blob: 4837b5872cde614efbf4bf5ef1c9c2e41611b09d [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 Vasquez07e264b2011-03-30 11:46:23 -07003 * Copyright (c) 2003-2011 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
Harihara Kadayam4d4df192008-04-03 13:13:26 -070038static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
39static int qla84xx_init_chip(scsi_qla_host_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080040static int qla25xx_init_queues(struct qla_hw_data *);
Harihara Kadayam4d4df192008-04-03 13:13:26 -070041
Andrew Vasquezac280b62009-08-20 11:06:05 -070042/* SRB Extensions ---------------------------------------------------------- */
43
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080044void
45qla2x00_sp_timeout(unsigned long __data)
Andrew Vasquezac280b62009-08-20 11:06:05 -070046{
47 srb_t *sp = (srb_t *)__data;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070048 struct srb_iocb *iocb;
Andrew Vasquezac280b62009-08-20 11:06:05 -070049 fc_port_t *fcport = sp->fcport;
50 struct qla_hw_data *ha = fcport->vha->hw;
51 struct req_que *req;
52 unsigned long flags;
53
54 spin_lock_irqsave(&ha->hardware_lock, flags);
55 req = ha->req_q_map[0];
56 req->outstanding_cmds[sp->handle] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080057 iocb = &sp->u.iocb_cmd;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070058 iocb->timeout(sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080059 sp->free(fcport->vha, sp);
Andrew Vasquez6ac52602010-05-28 15:08:19 -070060 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -070061}
62
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080063void
64qla2x00_sp_free(void *data, void *ptr)
Andrew Vasquezac280b62009-08-20 11:06:05 -070065{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080066 srb_t *sp = (srb_t *)ptr;
67 struct srb_iocb *iocb = &sp->u.iocb_cmd;
68 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquezac280b62009-08-20 11:06:05 -070069
Chad Dupuis4d97cc52010-10-15 11:27:41 -070070 del_timer(&iocb->timer);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080071 mempool_free(sp, vha->hw->srb_mempool);
Arun Easifeafb7b2010-09-03 14:57:00 -070072
73 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquezac280b62009-08-20 11:06:05 -070074}
75
Andrew Vasquezac280b62009-08-20 11:06:05 -070076/* Asynchronous Login/Logout Routines -------------------------------------- */
77
Andrew Vasquez5b914902010-05-28 15:08:30 -070078static inline unsigned long
79qla2x00_get_async_timeout(struct scsi_qla_host *vha)
80{
81 unsigned long tmo;
82 struct qla_hw_data *ha = vha->hw;
83
84 /* Firmware should use switch negotiated r_a_tov for timeout. */
85 tmo = ha->r_a_tov / 10 * 2;
86 if (!IS_FWI2_CAPABLE(ha)) {
87 /*
88 * Except for earlier ISPs where the timeout is seeded from the
89 * initialization control block.
90 */
91 tmo = ha->login_timeout;
92 }
93 return tmo;
94}
Andrew Vasquezac280b62009-08-20 11:06:05 -070095
96static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080097qla2x00_async_iocb_timeout(void *data)
Andrew Vasquezac280b62009-08-20 11:06:05 -070098{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080099 srb_t *sp = (srb_t *)data;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700100 fc_port_t *fcport = sp->fcport;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700101
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700102 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800103 "Async-%s timeout - hdl=%x portid=%02x%02x%02x.\n",
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800104 sp->name, sp->handle, fcport->d_id.b.domain, fcport->d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700105 fcport->d_id.b.al_pa);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700106
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700107 fcport->flags &= ~FCF_ASYNC_SENT;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800108 if (sp->type == SRB_LOGIN_CMD) {
109 struct srb_iocb *lio = &sp->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700110 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700111 /* Retry as needed. */
112 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
113 lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
114 QLA_LOGIO_LOGIN_RETRIED : 0;
115 qla2x00_post_async_login_done_work(fcport->vha, fcport,
116 lio->u.logio.data);
117 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700118}
119
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700120static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800121qla2x00_async_login_sp_done(void *data, void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700122{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800123 srb_t *sp = (srb_t *)ptr;
124 struct srb_iocb *lio = &sp->u.iocb_cmd;
125 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700126
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800127 if (!test_bit(UNLOADING, &vha->dpc_flags))
128 qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
129 lio->u.logio.data);
130 sp->free(sp->fcport->vha, sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700131}
132
Andrew Vasquezac280b62009-08-20 11:06:05 -0700133int
134qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
135 uint16_t *data)
136{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700137 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700138 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700139 int rval;
140
141 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800142 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700143 if (!sp)
144 goto done;
145
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800146 sp->type = SRB_LOGIN_CMD;
147 sp->name = "login";
148 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
149
150 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700151 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800152 sp->done = qla2x00_async_login_sp_done;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700153 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700154 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700155 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700156 rval = qla2x00_start_sp(sp);
157 if (rval != QLA_SUCCESS)
158 goto done_free_sp;
159
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700160 ql_dbg(ql_dbg_disc, vha, 0x2072,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800161 "Async-login - hdl=%x, loopid=%x portid=%02x%02x%02x "
162 "retries=%d.\n", sp->handle, fcport->loop_id,
163 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
164 fcport->login_retry);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700165 return rval;
166
167done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800168 sp->free(fcport->vha, sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700169done:
170 return rval;
171}
172
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700173static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800174qla2x00_async_logout_sp_done(void *data, void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700175{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800176 srb_t *sp = (srb_t *)ptr;
177 struct srb_iocb *lio = &sp->u.iocb_cmd;
178 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700179
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800180 if (!test_bit(UNLOADING, &vha->dpc_flags))
181 qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
182 lio->u.logio.data);
183 sp->free(sp->fcport->vha, sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700184}
185
Andrew Vasquezac280b62009-08-20 11:06:05 -0700186int
187qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
188{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700189 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700190 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700191 int rval;
192
193 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800194 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700195 if (!sp)
196 goto done;
197
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800198 sp->type = SRB_LOGOUT_CMD;
199 sp->name = "logout";
200 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
201
202 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700203 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800204 sp->done = qla2x00_async_logout_sp_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700205 rval = qla2x00_start_sp(sp);
206 if (rval != QLA_SUCCESS)
207 goto done_free_sp;
208
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700209 ql_dbg(ql_dbg_disc, vha, 0x2070,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800210 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
211 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
212 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700213 return rval;
214
215done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800216 sp->free(fcport->vha, sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700217done:
218 return rval;
219}
220
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700221static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800222qla2x00_async_adisc_sp_done(void *data, void *ptr, int res)
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700223{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800224 srb_t *sp = (srb_t *)ptr;
225 struct srb_iocb *lio = &sp->u.iocb_cmd;
226 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700227
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800228 if (!test_bit(UNLOADING, &vha->dpc_flags))
229 qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
230 lio->u.logio.data);
231 sp->free(sp->fcport->vha, sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700232}
233
234int
235qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
236 uint16_t *data)
237{
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700238 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700239 struct srb_iocb *lio;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700240 int rval;
241
242 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800243 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700244 if (!sp)
245 goto done;
246
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800247 sp->type = SRB_ADISC_CMD;
248 sp->name = "adisc";
249 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
250
251 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700252 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800253 sp->done = qla2x00_async_adisc_sp_done;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700254 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700255 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700256 rval = qla2x00_start_sp(sp);
257 if (rval != QLA_SUCCESS)
258 goto done_free_sp;
259
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700260 ql_dbg(ql_dbg_disc, vha, 0x206f,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800261 "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n",
262 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
263 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700264 return rval;
265
266done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800267 sp->free(fcport->vha, sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700268done:
269 return rval;
270}
271
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700272static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800273qla2x00_async_tm_cmd_done(void *data, void *ptr, int res)
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700274{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800275 srb_t *sp = (srb_t *)ptr;
276 struct srb_iocb *iocb = &sp->u.iocb_cmd;
277 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
278 uint32_t flags;
279 uint16_t lun;
280 int rval;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700281
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800282 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
283 flags = iocb->u.tmf.flags;
284 lun = (uint16_t)iocb->u.tmf.lun;
285
286 /* Issue Marker IOCB */
287 rval = qla2x00_marker(vha, vha->hw->req_q_map[0],
288 vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
289 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
290
291 if ((rval != QLA_SUCCESS) || iocb->u.tmf.data) {
292 ql_dbg(ql_dbg_taskm, vha, 0x8030,
293 "TM IOCB failed (%x).\n", rval);
294 }
295 }
296 sp->free(sp->fcport->vha, sp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700297}
298
299int
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800300qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t tm_flags, uint32_t lun,
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700301 uint32_t tag)
302{
303 struct scsi_qla_host *vha = fcport->vha;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700304 srb_t *sp;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700305 struct srb_iocb *tcf;
306 int rval;
307
308 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800309 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700310 if (!sp)
311 goto done;
312
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800313 sp->type = SRB_TM_CMD;
314 sp->name = "tmf";
315 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
316
317 tcf = &sp->u.iocb_cmd;
318 tcf->u.tmf.flags = tm_flags;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700319 tcf->u.tmf.lun = lun;
320 tcf->u.tmf.data = tag;
321 tcf->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800322 sp->done = qla2x00_async_tm_cmd_done;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700323
324 rval = qla2x00_start_sp(sp);
325 if (rval != QLA_SUCCESS)
326 goto done_free_sp;
327
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700328 ql_dbg(ql_dbg_taskm, vha, 0x802f,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800329 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
330 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
331 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700332 return rval;
333
334done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800335 sp->free(fcport->vha, sp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700336done:
337 return rval;
338}
339
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700340void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700341qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
342 uint16_t *data)
343{
344 int rval;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700345
346 switch (data[0]) {
347 case MBS_COMMAND_COMPLETE:
Andrew Vasqueza4f92a32011-03-30 11:46:31 -0700348 /*
349 * Driver must validate login state - If PRLI not complete,
350 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
351 * requests.
352 */
353 rval = qla2x00_get_port_database(vha, fcport, 0);
354 if (rval != QLA_SUCCESS) {
355 qla2x00_post_async_logout_work(vha, fcport, NULL);
356 qla2x00_post_async_login_work(vha, fcport, NULL);
357 break;
358 }
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700359 if (fcport->flags & FCF_FCP2_DEVICE) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700360 qla2x00_post_async_adisc_work(vha, fcport, data);
361 break;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700362 }
363 qla2x00_update_fcport(vha, fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700364 break;
365 case MBS_COMMAND_ERROR:
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700366 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700367 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
368 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
369 else
Andrew Vasquez80d79442011-03-30 11:46:17 -0700370 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700371 break;
372 case MBS_PORT_ID_USED:
373 fcport->loop_id = data[1];
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700374 qla2x00_post_async_logout_work(vha, fcport, NULL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700375 qla2x00_post_async_login_work(vha, fcport, NULL);
376 break;
377 case MBS_LOOP_ID_USED:
378 fcport->loop_id++;
379 rval = qla2x00_find_new_loop_id(vha, fcport);
380 if (rval != QLA_SUCCESS) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700381 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquez80d79442011-03-30 11:46:17 -0700382 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700383 break;
384 }
385 qla2x00_post_async_login_work(vha, fcport, NULL);
386 break;
387 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700388 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700389}
390
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700391void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700392qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
393 uint16_t *data)
394{
395 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700396 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700397}
398
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700399void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700400qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
401 uint16_t *data)
402{
403 if (data[0] == MBS_COMMAND_COMPLETE) {
404 qla2x00_update_fcport(vha, fcport);
405
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700406 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700407 }
408
409 /* Retry login. */
410 fcport->flags &= ~FCF_ASYNC_SENT;
411 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
412 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
413 else
Andrew Vasquez80d79442011-03-30 11:46:17 -0700414 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700415
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700416 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700417}
418
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419/****************************************************************************/
420/* QLogic ISP2x00 Hardware Support Functions. */
421/****************************************************************************/
422
423/*
424* qla2x00_initialize_adapter
425* Initialize board.
426*
427* Input:
428* ha = adapter block pointer.
429*
430* Returns:
431* 0 = success
432*/
433int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800434qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435{
436 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800437 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800438 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800441 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700442 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800443 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -0800444 ha->flags.pci_channel_io_perm_failure = 0;
445 ha->flags.eeh_busy = 0;
Andrew Vasquez794a5692010-12-21 16:00:21 -0800446 ha->flags.thermal_supported = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800447 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
448 atomic_set(&vha->loop_state, LOOP_DOWN);
449 vha->device_flags = DFLG_NO_CABLE;
450 vha->dpc_flags = 0;
451 vha->flags.management_server_logged_in = 0;
452 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 ha->isp_abort_cnt = 0;
454 ha->beacon_blink_led = 0;
455
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800456 set_bit(0, ha->req_qid_map);
457 set_bit(0, ha->rsp_qid_map);
458
Chad Dupuiscfb09192011-11-18 09:03:07 -0800459 ql_dbg(ql_dbg_init, vha, 0x0040,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700460 "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800461 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700463 ql_log(ql_log_warn, vha, 0x0044,
464 "Unable to configure PCI space.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 return (rval);
466 }
467
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800468 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800470 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700471 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700472 ql_log(ql_log_fatal, vha, 0x004f,
473 "Unable to validate FLASH data.\n");
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700474 return (rval);
475 }
476
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800477 ha->isp_ops->get_flash_version(vha, req->ring);
Chad Dupuiscfb09192011-11-18 09:03:07 -0800478 ql_dbg(ql_dbg_init, vha, 0x0061,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700479 "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700480
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800481 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700483 if (ha->flags.disable_serdes) {
484 /* Mask HBA via NVRAM settings? */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700485 ql_log(ql_log_info, vha, 0x0077,
486 "Masking HBA WWPN "
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700487 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800488 vha->port_name[0], vha->port_name[1],
489 vha->port_name[2], vha->port_name[3],
490 vha->port_name[4], vha->port_name[5],
491 vha->port_name[6], vha->port_name[7]);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700492 return QLA_FUNCTION_FAILED;
493 }
494
Chad Dupuiscfb09192011-11-18 09:03:07 -0800495 ql_dbg(ql_dbg_init, vha, 0x0078,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700496 "Verifying loaded RISC code...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800498 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
499 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800500 if (rval)
501 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800502 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800503 if (rval)
504 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700506
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700507 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800508 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700509 if (!ha->cs84xx) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700510 ql_log(ql_log_warn, vha, 0x00d0,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700511 "Unable to configure ISP84XX.\n");
512 return QLA_FUNCTION_FAILED;
513 }
514 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800515 rval = qla2x00_init_rings(vha);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700516 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800518 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700519 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800520 rval = qla84xx_init_chip(vha);
521 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700522 ql_log(ql_log_warn, vha, 0x00d4,
523 "Unable to initialize ISP84XX.\n");
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800524 qla84xx_put_chip(vha);
525 }
526 }
527
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +0500528 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
529 qla24xx_read_fcp_prio_cfg(vha);
Sarang Radke09ff7012010-03-19 17:03:59 -0700530
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 return (rval);
532}
533
534/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700535 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 * @ha: HA context
537 *
538 * Returns 0 on success.
539 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700540int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800541qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700543 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700544 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800545 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700546 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700549 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700552 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
554
Andrew Vasquez737faec2008-10-24 15:13:45 -0700555 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700557 /* Get PCI bus information. */
558 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700559 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700560 spin_unlock_irqrestore(&ha->hardware_lock, flags);
561
562 return QLA_SUCCESS;
563}
564
565/**
566 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
567 * @ha: HA context
568 *
569 * Returns 0 on success.
570 */
571int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800572qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700573{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700574 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700575 unsigned long flags = 0;
576 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800577 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700578 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700579
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700580 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700581 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700582
583 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700584 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700585
586 if (IS_QLA2322(ha) || IS_QLA6322(ha))
587 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700588 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700589
590 /*
591 * If this is a 2300 card and not 2312, reset the
592 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
593 * the 2310 also reports itself as a 2300 so we need to get the
594 * fb revision level -- a 6 indicates it really is a 2300 and
595 * not a 2310.
596 */
597 if (IS_QLA2300(ha)) {
598 spin_lock_irqsave(&ha->hardware_lock, flags);
599
600 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700601 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700602 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700603 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700604 break;
605
606 udelay(10);
607 }
608
609 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700610 WRT_REG_WORD(&reg->ctrl_status, 0x20);
611 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700612
613 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700614 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700615
616 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700617 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700618
619 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700620 WRT_REG_WORD(&reg->ctrl_status, 0x0);
621 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700622
623 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700624 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700625 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700626 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700627 break;
628
629 udelay(10);
630 }
631
632 spin_unlock_irqrestore(&ha->hardware_lock, flags);
633 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700634
635 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
636
Andrew Vasquez737faec2008-10-24 15:13:45 -0700637 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700638
639 /* Get PCI bus information. */
640 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700641 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700642 spin_unlock_irqrestore(&ha->hardware_lock, flags);
643
644 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645}
646
647/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700648 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
649 * @ha: HA context
650 *
651 * Returns 0 on success.
652 */
653int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800654qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700655{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700656 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700657 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800658 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700659 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700660
661 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700662 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700663
664 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700665 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700666 w &= ~PCI_COMMAND_INTX_DISABLE;
667 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
668
669 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
670
671 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700672 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
673 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700674
675 /* PCIe -- adjust Maximum Read Request Size (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700676 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
677 pcie_set_readrq(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700678
Andrew Vasquez737faec2008-10-24 15:13:45 -0700679 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700680
Auke Kok44c10132007-06-08 15:46:36 -0700681 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800682
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700683 /* Get PCI bus information. */
684 spin_lock_irqsave(&ha->hardware_lock, flags);
685 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
686 spin_unlock_irqrestore(&ha->hardware_lock, flags);
687
688 return QLA_SUCCESS;
689}
690
691/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700692 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
693 * @ha: HA context
694 *
695 * Returns 0 on success.
696 */
697int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800698qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700699{
700 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800701 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700702
703 pci_set_master(ha->pdev);
704 pci_try_set_mwi(ha->pdev);
705
706 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
707 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
708 w &= ~PCI_COMMAND_INTX_DISABLE;
709 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
710
711 /* PCIe -- adjust Maximum Read Request Size (2048). */
712 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
713 pcie_set_readrq(ha->pdev, 2048);
714
Andrew Vasquez737faec2008-10-24 15:13:45 -0700715 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700716
717 ha->chip_revision = ha->pdev->revision;
718
719 return QLA_SUCCESS;
720}
721
722/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 * qla2x00_isp_firmware() - Choose firmware image.
724 * @ha: HA context
725 *
726 * Returns 0 on success.
727 */
728static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800729qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730{
731 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700732 uint16_t loop_id, topo, sw_cap;
733 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800734 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
736 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700737 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
739 if (ha->flags.disable_risc_code_load) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700740 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
742 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800743 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700744 if (rval == QLA_SUCCESS) {
745 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800746 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700747 &area, &domain, &topo, &sw_cap);
748 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 }
750
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700751 if (rval)
752 ql_dbg(ql_dbg_init, vha, 0x007a,
753 "**** Load RISC code ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
755 return (rval);
756}
757
758/**
759 * qla2x00_reset_chip() - Reset ISP chip.
760 * @ha: HA context
761 *
762 * Returns 0 on success.
763 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700764void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800765qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766{
767 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800768 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700769 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 uint16_t cmd;
772
Andrew Vasquez85880802009-12-15 21:29:46 -0800773 if (unlikely(pci_channel_offline(ha->pdev)))
774 return;
775
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700776 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
778 spin_lock_irqsave(&ha->hardware_lock, flags);
779
780 /* Turn off master enable */
781 cmd = 0;
782 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
783 cmd &= ~PCI_COMMAND_MASTER;
784 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
785
786 if (!IS_QLA2100(ha)) {
787 /* Pause RISC. */
788 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
789 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
790 for (cnt = 0; cnt < 30000; cnt++) {
791 if ((RD_REG_WORD(&reg->hccr) &
792 HCCR_RISC_PAUSE) != 0)
793 break;
794 udelay(100);
795 }
796 } else {
797 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
798 udelay(10);
799 }
800
801 /* Select FPM registers. */
802 WRT_REG_WORD(&reg->ctrl_status, 0x20);
803 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
804
805 /* FPM Soft Reset. */
806 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
807 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
808
809 /* Toggle Fpm Reset. */
810 if (!IS_QLA2200(ha)) {
811 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
812 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
813 }
814
815 /* Select frame buffer registers. */
816 WRT_REG_WORD(&reg->ctrl_status, 0x10);
817 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
818
819 /* Reset frame buffer FIFOs. */
820 if (IS_QLA2200(ha)) {
821 WRT_FB_CMD_REG(ha, reg, 0xa000);
822 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
823 } else {
824 WRT_FB_CMD_REG(ha, reg, 0x00fc);
825
826 /* Read back fb_cmd until zero or 3 seconds max */
827 for (cnt = 0; cnt < 3000; cnt++) {
828 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
829 break;
830 udelay(100);
831 }
832 }
833
834 /* Select RISC module registers. */
835 WRT_REG_WORD(&reg->ctrl_status, 0);
836 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
837
838 /* Reset RISC processor. */
839 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
840 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
841
842 /* Release RISC processor. */
843 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
844 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
845 }
846
847 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
848 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
849
850 /* Reset ISP chip. */
851 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
852
853 /* Wait for RISC to recover from reset. */
854 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
855 /*
856 * It is necessary to for a delay here since the card doesn't
857 * respond to PCI reads during a reset. On some architectures
858 * this will result in an MCA.
859 */
860 udelay(20);
861 for (cnt = 30000; cnt; cnt--) {
862 if ((RD_REG_WORD(&reg->ctrl_status) &
863 CSR_ISP_SOFT_RESET) == 0)
864 break;
865 udelay(100);
866 }
867 } else
868 udelay(10);
869
870 /* Reset RISC processor. */
871 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
872
873 WRT_REG_WORD(&reg->semaphore, 0);
874
875 /* Release RISC processor. */
876 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
877 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
878
879 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
880 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700881 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883
884 udelay(100);
885 }
886 } else
887 udelay(100);
888
889 /* Turn on master enable */
890 cmd |= PCI_COMMAND_MASTER;
891 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
892
893 /* Disable RISC pause on FPM parity error. */
894 if (!IS_QLA2100(ha)) {
895 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
896 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
897 }
898
899 spin_unlock_irqrestore(&ha->hardware_lock, flags);
900}
901
902/**
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700903 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
904 *
905 * Returns 0 on success.
906 */
907int
908qla81xx_reset_mpi(scsi_qla_host_t *vha)
909{
910 uint16_t mb[4] = {0x1010, 0, 1, 0};
911
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800912 if (!IS_QLA81XX(vha->hw))
913 return QLA_SUCCESS;
914
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700915 return qla81xx_write_mpi_register(vha, mb);
916}
917
918/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700919 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700920 * @ha: HA context
921 *
922 * Returns 0 on success.
923 */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700924static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800925qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700926{
927 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800928 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700929 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
930 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800931 uint16_t wd;
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700932 static int abts_cnt; /* ISP abort retry counts */
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700933
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700934 spin_lock_irqsave(&ha->hardware_lock, flags);
935
936 /* Reset RISC. */
937 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
938 for (cnt = 0; cnt < 30000; cnt++) {
939 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
940 break;
941
942 udelay(10);
943 }
944
945 WRT_REG_DWORD(&reg->ctrl_status,
946 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800947 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700948
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800949 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700950 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700951 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
952 for (cnt = 10000 ; cnt && d2; cnt--) {
953 udelay(5);
954 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
955 barrier();
956 }
957
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800958 /* Wait for soft-reset to complete. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700959 d2 = RD_REG_DWORD(&reg->ctrl_status);
960 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
961 udelay(5);
962 d2 = RD_REG_DWORD(&reg->ctrl_status);
963 barrier();
964 }
965
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700966 /* If required, do an MPI FW reset now */
967 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
968 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
969 if (++abts_cnt < 5) {
970 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
971 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
972 } else {
973 /*
974 * We exhausted the ISP abort retries. We have to
975 * set the board offline.
976 */
977 abts_cnt = 0;
978 vha->flags.online = 0;
979 }
980 }
981 }
982
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700983 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
984 RD_REG_DWORD(&reg->hccr);
985
986 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
987 RD_REG_DWORD(&reg->hccr);
988
989 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
990 RD_REG_DWORD(&reg->hccr);
991
992 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
993 for (cnt = 6000000 ; cnt && d2; cnt--) {
994 udelay(5);
995 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
996 barrier();
997 }
998
999 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001000
1001 if (IS_NOPOLLING_TYPE(ha))
1002 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001003}
1004
1005/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001006 * qla24xx_reset_chip() - Reset ISP24xx chip.
1007 * @ha: HA context
1008 *
1009 * Returns 0 on success.
1010 */
1011void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001012qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07001013{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001014 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08001015
1016 if (pci_channel_offline(ha->pdev) &&
1017 ha->flags.pci_channel_io_perm_failure) {
1018 return;
1019 }
1020
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001021 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001022
1023 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001024 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001025}
1026
1027/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 * qla2x00_chip_diag() - Test chip for proper operation.
1029 * @ha: HA context
1030 *
1031 * Returns 0 on success.
1032 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001033int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001034qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035{
1036 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001037 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001038 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 unsigned long flags = 0;
1040 uint16_t data;
1041 uint32_t cnt;
1042 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001043 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044
1045 /* Assume a failed state */
1046 rval = QLA_FUNCTION_FAILED;
1047
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001048 ql_dbg(ql_dbg_init, vha, 0x007b,
1049 "Testing device at %lx.\n", (u_long)&reg->flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050
1051 spin_lock_irqsave(&ha->hardware_lock, flags);
1052
1053 /* Reset ISP chip. */
1054 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1055
1056 /*
1057 * We need to have a delay here since the card will not respond while
1058 * in reset causing an MCA on some architectures.
1059 */
1060 udelay(20);
1061 data = qla2x00_debounce_register(&reg->ctrl_status);
1062 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
1063 udelay(5);
1064 data = RD_REG_WORD(&reg->ctrl_status);
1065 barrier();
1066 }
1067
1068 if (!cnt)
1069 goto chip_diag_failed;
1070
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001071 ql_dbg(ql_dbg_init, vha, 0x007c,
1072 "Reset register cleared by chip reset.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073
1074 /* Reset RISC processor. */
1075 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1076 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1077
1078 /* Workaround for QLA2312 PCI parity error */
1079 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1080 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
1081 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
1082 udelay(5);
1083 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001084 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 }
1086 } else
1087 udelay(10);
1088
1089 if (!cnt)
1090 goto chip_diag_failed;
1091
1092 /* Check product ID of chip */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001093 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product Id of chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094
1095 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1096 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1097 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1098 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1099 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1100 mb[3] != PROD_ID_3) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001101 ql_log(ql_log_warn, vha, 0x0062,
1102 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
1103 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
1105 goto chip_diag_failed;
1106 }
1107 ha->product_id[0] = mb[1];
1108 ha->product_id[1] = mb[2];
1109 ha->product_id[2] = mb[3];
1110 ha->product_id[3] = mb[4];
1111
1112 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001113 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1115 else
1116 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001117 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118
1119 if (IS_QLA2200(ha) &&
1120 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1121 /* Limit firmware transfer size with a 2200A */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001122 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001124 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 ha->fw_transfer_size = 128;
1126 }
1127
1128 /* Wrap Incoming Mailboxes Test. */
1129 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1130
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001131 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001132 rval = qla2x00_mbx_reg_test(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001133 if (rval)
1134 ql_log(ql_log_warn, vha, 0x0080,
1135 "Failed mailbox send register test.\n");
1136 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 /* Flag a successful rval */
1138 rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 spin_lock_irqsave(&ha->hardware_lock, flags);
1140
1141chip_diag_failed:
1142 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001143 ql_log(ql_log_info, vha, 0x0081,
1144 "Chip diagnostics **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
1146 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1147
1148 return (rval);
1149}
1150
1151/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001152 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1153 * @ha: HA context
1154 *
1155 * Returns 0 on success.
1156 */
1157int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001158qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001159{
1160 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001161 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001162 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001163
Giridhar Malavalia9083012010-04-12 17:59:55 -07001164 if (IS_QLA82XX(ha))
1165 return QLA_SUCCESS;
1166
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001167 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001168
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001169 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001170 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001171 ql_log(ql_log_warn, vha, 0x0082,
1172 "Failed mailbox send register test.\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001173 } else {
1174 /* Flag a successful rval */
1175 rval = QLA_SUCCESS;
1176 }
1177
1178 return rval;
1179}
1180
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001181void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001182qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001183{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001184 int rval;
1185 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001186 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001187 dma_addr_t tc_dma;
1188 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001189 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001190 struct req_que *req = ha->req_q_map[0];
1191 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001192
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001193 if (ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001194 ql_dbg(ql_dbg_init, vha, 0x00bd,
1195 "Firmware dump already allocated.\n");
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001196 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001197 }
1198
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001199 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001200 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001201 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1202 fixed_size = sizeof(struct qla2100_fw_dump);
1203 } else if (IS_QLA23XX(ha)) {
1204 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1205 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1206 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001207 } else if (IS_FWI2_CAPABLE(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001208 if (IS_QLA83XX(ha))
1209 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
1210 else if (IS_QLA81XX(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001211 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1212 else if (IS_QLA25XX(ha))
1213 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1214 else
1215 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001216 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1217 sizeof(uint32_t);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001218 if (ha->mqenable) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001219 if (!IS_QLA83XX(ha))
1220 mq_size = sizeof(struct qla2xxx_mq_chain);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001221 /*
1222 * Allocate maximum buffer size for all queues.
1223 * Resizing must be done at end-of-dump processing.
1224 */
1225 mq_size += ha->max_req_queues *
1226 (req->length * sizeof(request_t));
1227 mq_size += ha->max_rsp_queues *
1228 (rsp->length * sizeof(response_t));
1229 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001230 /* Allocate memory for Fibre Channel Event Buffer. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001231 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001232 goto try_eft;
1233
1234 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1235 GFP_KERNEL);
1236 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001237 ql_log(ql_log_warn, vha, 0x00be,
1238 "Unable to allocate (%d KB) for FCE.\n",
1239 FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001240 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001241 }
1242
1243 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001244 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001245 ha->fce_mb, &ha->fce_bufs);
1246 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001247 ql_log(ql_log_warn, vha, 0x00bf,
1248 "Unable to initialize FCE (%d).\n", rval);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001249 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1250 tc_dma);
1251 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001252 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001253 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001254 ql_dbg(ql_dbg_init, vha, 0x00c0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001255 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001256
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001257 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001258 ha->flags.fce_enabled = 1;
1259 ha->fce_dma = tc_dma;
1260 ha->fce = tc;
1261try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001262 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001263 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001264 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001265 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001266 ql_log(ql_log_warn, vha, 0x00c1,
1267 "Unable to allocate (%d KB) for EFT.\n",
1268 EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001269 goto cont_alloc;
1270 }
1271
Andrew Vasquezfc447652008-01-17 09:02:18 -08001272 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001273 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001274 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001275 ql_log(ql_log_warn, vha, 0x00c2,
1276 "Unable to initialize EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001277 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1278 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001279 goto cont_alloc;
1280 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001281 ql_dbg(ql_dbg_init, vha, 0x00c3,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001282 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001283
1284 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001285 ha->eft_dma = tc_dma;
1286 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001287 }
1288cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001289 req_q_size = req->length * sizeof(request_t);
1290 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001291
1292 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001293 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001294 ha->chain_offset = dump_size;
1295 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001296
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001297 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001298 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001299 ql_log(ql_log_warn, vha, 0x00c4,
1300 "Unable to allocate (%d KB) for firmware dump.\n",
1301 dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001302
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07001303 if (ha->fce) {
1304 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
1305 ha->fce_dma);
1306 ha->fce = NULL;
1307 ha->fce_dma = 0;
1308 }
1309
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001310 if (ha->eft) {
1311 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1312 ha->eft_dma);
1313 ha->eft = NULL;
1314 ha->eft_dma = 0;
1315 }
1316 return;
1317 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001318 ql_dbg(ql_dbg_init, vha, 0x00c5,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001319 "Allocated (%d KB) for firmware dump.\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001320
1321 ha->fw_dump_len = dump_size;
1322 ha->fw_dump->signature[0] = 'Q';
1323 ha->fw_dump->signature[1] = 'L';
1324 ha->fw_dump->signature[2] = 'G';
1325 ha->fw_dump->signature[3] = 'C';
1326 ha->fw_dump->version = __constant_htonl(1);
1327
1328 ha->fw_dump->fixed_size = htonl(fixed_size);
1329 ha->fw_dump->mem_size = htonl(mem_size);
1330 ha->fw_dump->req_q_size = htonl(req_q_size);
1331 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1332
1333 ha->fw_dump->eft_size = htonl(eft_size);
1334 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1335 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1336
1337 ha->fw_dump->header_size =
1338 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001339}
1340
Andrew Vasquez18e75552009-06-03 09:55:30 -07001341static int
1342qla81xx_mpi_sync(scsi_qla_host_t *vha)
1343{
1344#define MPS_MASK 0xe0
1345 int rval;
1346 uint16_t dc;
1347 uint32_t dw;
Andrew Vasquez18e75552009-06-03 09:55:30 -07001348
1349 if (!IS_QLA81XX(vha->hw))
1350 return QLA_SUCCESS;
1351
1352 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1353 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001354 ql_log(ql_log_warn, vha, 0x0105,
1355 "Unable to acquire semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001356 goto done;
1357 }
1358
1359 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1360 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1361 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001362 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001363 goto done_release;
1364 }
1365
1366 dc &= MPS_MASK;
1367 if (dc == (dw & MPS_MASK))
1368 goto done_release;
1369
1370 dw &= ~MPS_MASK;
1371 dw |= dc;
1372 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1373 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001374 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001375 }
1376
1377done_release:
1378 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1379 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001380 ql_log(ql_log_warn, vha, 0x006d,
1381 "Unable to release semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001382 }
1383
1384done:
1385 return rval;
1386}
1387
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001388/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 * qla2x00_setup_chip() - Load and start RISC firmware.
1390 * @ha: HA context
1391 *
1392 * Returns 0 on success.
1393 */
1394static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001395qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001397 int rval;
1398 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001399 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001400 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1401 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001402 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001403
Giridhar Malavalia9083012010-04-12 17:59:55 -07001404 if (IS_QLA82XX(ha)) {
1405 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001406 if (rval == QLA_SUCCESS) {
1407 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001408 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001409 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07001410 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001411 }
1412
Andrew Vasquez3db06522008-01-31 12:33:49 -08001413 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1414 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1415 spin_lock_irqsave(&ha->hardware_lock, flags);
1416 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1417 RD_REG_WORD(&reg->hccr);
1418 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1419 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420
Andrew Vasquez18e75552009-06-03 09:55:30 -07001421 qla81xx_mpi_sync(vha);
1422
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001424 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001425 if (rval == QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001426 ql_dbg(ql_dbg_init, vha, 0x00c9,
1427 "Verifying Checksum of loaded RISC code.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001429 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 if (rval == QLA_SUCCESS) {
1431 /* Start firmware execution. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001432 ql_dbg(ql_dbg_init, vha, 0x00ca,
1433 "Starting firmware.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001435 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001437 if (rval == QLA_SUCCESS) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001438enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001439 fw_major_version = ha->fw_major_version;
Giridhar Malavali31731672011-08-16 11:31:54 -07001440 if (IS_QLA82XX(ha))
1441 qla82xx_check_md_needed(vha);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001442 else
1443 rval = qla2x00_get_fw_version(vha);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001444 if (rval != QLA_SUCCESS)
1445 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001446 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001447 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001448 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001449 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001450 if ((!ha->max_npiv_vports) ||
1451 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001452 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001453 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001454 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001455 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001456 qla2x00_get_resource_cnts(vha, NULL,
1457 &ha->fw_xcb_count, NULL, NULL,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001458 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001459
Saurav Kashyapbe5ea3c2011-11-18 09:02:11 -08001460 if (!fw_major_version && ql2xallocfwdump
1461 && !IS_QLA82XX(ha))
Giridhar Malavali08de2842011-08-16 11:31:44 -07001462 qla2x00_alloc_fw_dump(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 }
1464 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001465 ql_log(ql_log_fatal, vha, 0x00cd,
1466 "ISP Firmware failed checksum.\n");
1467 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 }
1469 }
1470
Andrew Vasquez3db06522008-01-31 12:33:49 -08001471 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1472 /* Enable proper parity. */
1473 spin_lock_irqsave(&ha->hardware_lock, flags);
1474 if (IS_QLA2300(ha))
1475 /* SRAM parity */
1476 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1477 else
1478 /* SRAM, Instruction RAM and GP RAM parity */
1479 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1480 RD_REG_WORD(&reg->hccr);
1481 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1482 }
1483
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001484 if (IS_QLA83XX(ha))
1485 goto skip_fac_check;
1486
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001487 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1488 uint32_t size;
1489
1490 rval = qla81xx_fac_get_sector_size(vha, &size);
1491 if (rval == QLA_SUCCESS) {
1492 ha->flags.fac_supported = 1;
1493 ha->fdt_block_size = size << 2;
1494 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001495 ql_log(ql_log_warn, vha, 0x00ce,
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001496 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1497 ha->fw_major_version, ha->fw_minor_version,
1498 ha->fw_subminor_version);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001499skip_fac_check:
1500 if (IS_QLA83XX(ha)) {
1501 ha->flags.fac_supported = 0;
1502 rval = QLA_SUCCESS;
1503 }
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001504 }
1505 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001506failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001508 ql_log(ql_log_fatal, vha, 0x00cf,
1509 "Setup chip ****FAILED****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 }
1511
1512 return (rval);
1513}
1514
1515/**
1516 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1517 * @ha: HA context
1518 *
1519 * Beginning of request ring has initialization control block already built
1520 * by nvram config routine.
1521 *
1522 * Returns 0 on success.
1523 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001524void
1525qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526{
1527 uint16_t cnt;
1528 response_t *pkt;
1529
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001530 rsp->ring_ptr = rsp->ring;
1531 rsp->ring_index = 0;
1532 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001533 pkt = rsp->ring_ptr;
1534 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 pkt->signature = RESPONSE_PROCESSED;
1536 pkt++;
1537 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538}
1539
1540/**
1541 * qla2x00_update_fw_options() - Read and process firmware options.
1542 * @ha: HA context
1543 *
1544 * Returns 0 on success.
1545 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001546void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001547qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548{
1549 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001550 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551
1552 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001553 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
1555 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1556 return;
1557
1558 /* Serial Link options. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001559 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
1560 "Serial link options.\n");
1561 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
1562 (uint8_t *)&ha->fw_seriallink_options,
1563 sizeof(ha->fw_seriallink_options));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564
1565 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1566 if (ha->fw_seriallink_options[3] & BIT_2) {
1567 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1568
1569 /* 1G settings */
1570 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1571 emphasis = (ha->fw_seriallink_options[2] &
1572 (BIT_4 | BIT_3)) >> 3;
1573 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001574 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 rx_sens = (ha->fw_seriallink_options[0] &
1576 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1577 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1578 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1579 if (rx_sens == 0x0)
1580 rx_sens = 0x3;
1581 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1582 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1583 ha->fw_options[10] |= BIT_5 |
1584 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1585 (tx_sens & (BIT_1 | BIT_0));
1586
1587 /* 2G settings */
1588 swing = (ha->fw_seriallink_options[2] &
1589 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1590 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1591 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001592 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 rx_sens = (ha->fw_seriallink_options[1] &
1594 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1595 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1596 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1597 if (rx_sens == 0x0)
1598 rx_sens = 0x3;
1599 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1600 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1601 ha->fw_options[11] |= BIT_5 |
1602 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1603 (tx_sens & (BIT_1 | BIT_0));
1604 }
1605
1606 /* FCP2 options. */
1607 /* Return command IOCBs without waiting for an ABTS to complete. */
1608 ha->fw_options[3] |= BIT_13;
1609
1610 /* LED scheme. */
1611 if (ha->flags.enable_led_scheme)
1612 ha->fw_options[2] |= BIT_12;
1613
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001614 /* Detect ISP6312. */
1615 if (IS_QLA6312(ha))
1616 ha->fw_options[2] |= BIT_13;
1617
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001619 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620}
1621
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001622void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001623qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001624{
1625 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001626 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001627
Giridhar Malavalia9083012010-04-12 17:59:55 -07001628 if (IS_QLA82XX(ha))
1629 return;
1630
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001631 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001632 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001633 return;
1634
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001635 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001636 le16_to_cpu(ha->fw_seriallink_options24[1]),
1637 le16_to_cpu(ha->fw_seriallink_options24[2]),
1638 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001639 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001640 ql_log(ql_log_warn, vha, 0x0104,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001641 "Unable to update Serial Link options (%x).\n", rval);
1642 }
1643}
1644
1645void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001646qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001647{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001648 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001649 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001650 struct req_que *req = ha->req_q_map[0];
1651 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001652
1653 /* Setup ring parameters in initialization control block. */
1654 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1655 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001656 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1657 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1658 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1659 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1660 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1661 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001662
1663 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1664 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1665 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1666 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1667 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1668}
1669
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001670void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001671qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001672{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001673 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001674 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1675 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1676 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001677 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001678 uint16_t rid = 0;
1679 struct req_que *req = ha->req_q_map[0];
1680 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001681
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001682 /* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001683 icb = (struct init_cb_24xx *)ha->init_cb;
1684 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1685 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001686 icb->request_q_length = cpu_to_le16(req->length);
1687 icb->response_q_length = cpu_to_le16(rsp->length);
1688 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1689 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1690 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1691 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001692
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001693 if (ha->mqenable || IS_QLA83XX(ha)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001694 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1695 icb->rid = __constant_cpu_to_le16(rid);
1696 if (ha->flags.msix_enabled) {
1697 msix = &ha->msix_entries[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001698 ql_dbg(ql_dbg_init, vha, 0x00fd,
1699 "Registering vector 0x%x for base que.\n",
1700 msix->entry);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001701 icb->msix = cpu_to_le16(msix->entry);
1702 }
1703 /* Use alternate PCI bus number */
1704 if (MSB(rid))
1705 icb->firmware_options_2 |=
1706 __constant_cpu_to_le32(BIT_19);
1707 /* Use alternate PCI devfn */
1708 if (LSB(rid))
1709 icb->firmware_options_2 |=
1710 __constant_cpu_to_le32(BIT_18);
1711
Anirban Chakraborty31557542009-12-02 10:36:55 -08001712 /* Use Disable MSIX Handshake mode for capable adapters */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001713 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
1714 (ha->flags.msix_enabled)) {
Anirban Chakraborty31557542009-12-02 10:36:55 -08001715 icb->firmware_options_2 &=
1716 __constant_cpu_to_le32(~BIT_22);
1717 ha->flags.disable_msix_handshake = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001718 ql_dbg(ql_dbg_init, vha, 0x00fe,
1719 "MSIX Handshake Disable Mode turned on.\n");
Anirban Chakraborty31557542009-12-02 10:36:55 -08001720 } else {
1721 icb->firmware_options_2 |=
1722 __constant_cpu_to_le32(BIT_22);
1723 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001724 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001725
1726 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1727 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1728 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1729 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1730 } else {
1731 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1732 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1733 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1734 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1735 }
1736 /* PCI posting */
1737 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001738}
1739
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740/**
1741 * qla2x00_init_rings() - Initializes firmware.
1742 * @ha: HA context
1743 *
1744 * Beginning of request ring has initialization control block already built
1745 * by nvram config routine.
1746 *
1747 * Returns 0 on success.
1748 */
1749static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001750qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751{
1752 int rval;
1753 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001754 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001755 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001756 struct req_que *req;
1757 struct rsp_que *rsp;
1758 struct scsi_qla_host *vp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001759 struct mid_init_cb_24xx *mid_init_cb =
1760 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761
1762 spin_lock_irqsave(&ha->hardware_lock, flags);
1763
1764 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001765 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001766 req = ha->req_q_map[que];
1767 if (!req)
1768 continue;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001769 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001770 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001772 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001773
1774 /* Initialize firmware. */
1775 req->ring_ptr = req->ring;
1776 req->ring_index = 0;
1777 req->cnt = req->length;
1778 }
1779
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001780 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001781 rsp = ha->rsp_q_map[que];
1782 if (!rsp)
1783 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001784 /* Initialize response queue entries */
1785 qla2x00_init_response_q_entries(rsp);
1786 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787
Dan Carpenter542bce12010-10-15 11:27:38 -07001788 spin_lock(&ha->vport_slock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 /* Clear RSCN queue. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001790 list_for_each_entry(vp, &ha->vp_list, list) {
1791 vp->rscn_in_ptr = 0;
1792 vp->rscn_out_ptr = 0;
1793 }
Arun Easifeafb7b2010-09-03 14:57:00 -07001794
Dan Carpenter542bce12010-10-15 11:27:38 -07001795 spin_unlock(&ha->vport_slock);
Arun Easifeafb7b2010-09-03 14:57:00 -07001796
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001797 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798
1799 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1800
1801 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001802 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001804 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001805
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001806 if (ha->flags.npiv_supported) {
1807 if (ha->operating_mode == LOOP)
1808 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08001809 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001810 }
1811
Andrew Vasquez24a08132009-03-24 09:08:16 -07001812 if (IS_FWI2_CAPABLE(ha)) {
1813 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1814 mid_init_cb->init_cb.execution_throttle =
1815 cpu_to_le16(ha->fw_xcb_count);
1816 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001817
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001818 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001820 ql_log(ql_log_fatal, vha, 0x00d2,
1821 "Init Firmware **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001823 ql_dbg(ql_dbg_init, vha, 0x00d3,
1824 "Init Firmware -- success.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 }
1826
1827 return (rval);
1828}
1829
1830/**
1831 * qla2x00_fw_ready() - Waits for firmware ready.
1832 * @ha: HA context
1833 *
1834 * Returns 0 on success.
1835 */
1836static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001837qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838{
1839 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001840 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 uint16_t min_wait; /* Minimum wait time if loop is down */
1842 uint16_t wait_time; /* Wait time if loop is coming ready */
Andrew Vasquez656e8912009-06-03 09:55:29 -07001843 uint16_t state[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001844 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845
1846 rval = QLA_SUCCESS;
1847
1848 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001849 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850
1851 /*
1852 * Firmware should take at most one RATOV to login, plus 5 seconds for
1853 * our own processing.
1854 */
1855 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1856 wait_time = min_wait;
1857 }
1858
1859 /* Min wait time if loop down */
1860 mtime = jiffies + (min_wait * HZ);
1861
1862 /* wait time before firmware ready */
1863 wtime = jiffies + (wait_time * HZ);
1864
1865 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001866 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001867 ql_log(ql_log_info, vha, 0x801e,
1868 "Waiting for LIP to complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869
1870 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001871 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001873 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001874 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001876 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001877 ql_dbg(ql_dbg_taskm, vha, 0x801f,
1878 "fw_state=%x 84xx=%x.\n", state[0],
1879 state[2]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001880 if ((state[2] & FSTATE_LOGGED_IN) &&
1881 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001882 ql_dbg(ql_dbg_taskm, vha, 0x8028,
1883 "Sending verify iocb.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001884
1885 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001886 rval = qla84xx_init_chip(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001887 if (rval != QLA_SUCCESS) {
1888 ql_log(ql_log_warn,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001889 vha, 0x8007,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001890 "Init chip failed.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001891 break;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001892 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001893
1894 /* Add time taken to initialize. */
1895 cs84xx_time = jiffies - cs84xx_time;
1896 wtime += cs84xx_time;
1897 mtime += cs84xx_time;
Chad Dupuiscfb09192011-11-18 09:03:07 -08001898 ql_dbg(ql_dbg_taskm, vha, 0x8008,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001899 "Increasing wait time by %ld. "
1900 "New time %ld.\n", cs84xx_time,
1901 wtime);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001902 }
1903 } else if (state[0] == FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001904 ql_dbg(ql_dbg_taskm, vha, 0x8037,
1905 "F/W Ready - OK.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001907 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 &ha->login_timeout, &ha->r_a_tov);
1909
1910 rval = QLA_SUCCESS;
1911 break;
1912 }
1913
1914 rval = QLA_FUNCTION_FAILED;
1915
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001916 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001917 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001919 * other than Wait for Login.
1920 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 if (time_after_eq(jiffies, mtime)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001922 ql_log(ql_log_info, vha, 0x8038,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 "Cable is unplugged...\n");
1924
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001925 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 break;
1927 }
1928 }
1929 } else {
1930 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07001931 if (time_after_eq(jiffies, mtime) ||
Giridhar Malavali71905752011-02-23 15:27:10 -08001932 ha->flags.isp82xx_fw_hung)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 break;
1934 }
1935
1936 if (time_after_eq(jiffies, wtime))
1937 break;
1938
1939 /* Delay for a while */
1940 msleep(500);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 } while (1);
1942
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001943 ql_dbg(ql_dbg_taskm, vha, 0x803a,
1944 "fw_state=%x (%x, %x, %x, %x) " "curr time=%lx.\n", state[0],
1945 state[1], state[2], state[3], state[4], jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946
Chad Dupuiscfb09192011-11-18 09:03:07 -08001947 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001948 ql_log(ql_log_warn, vha, 0x803b,
1949 "Firmware ready **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 }
1951
1952 return (rval);
1953}
1954
1955/*
1956* qla2x00_configure_hba
1957* Setup adapter context.
1958*
1959* Input:
1960* ha = adapter state pointer.
1961*
1962* Returns:
1963* 0 = success
1964*
1965* Context:
1966* Kernel context.
1967*/
1968static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001969qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970{
1971 int rval;
1972 uint16_t loop_id;
1973 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001974 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975 uint8_t al_pa;
1976 uint8_t area;
1977 uint8_t domain;
1978 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001979 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980
1981 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001982 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001983 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001985 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001986 IS_CNA_CAPABLE(ha) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08001987 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001988 ql_dbg(ql_dbg_disc, vha, 0x2008,
1989 "Loop is in a transition state.\n");
Ravi Anand33135aa2005-11-08 14:37:20 -08001990 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001991 ql_log(ql_log_warn, vha, 0x2009,
1992 "Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001993 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08001994 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995 return (rval);
1996 }
1997
1998 if (topo == 4) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001999 ql_log(ql_log_info, vha, 0x200a,
2000 "Cannot get topology - retrying.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 return (QLA_FUNCTION_FAILED);
2002 }
2003
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002004 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005
2006 /* initialize */
2007 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
2008 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002009 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010
2011 switch (topo) {
2012 case 0:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002013 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 ha->current_topology = ISP_CFG_NL;
2015 strcpy(connect_type, "(Loop)");
2016 break;
2017
2018 case 1:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002019 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002020 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 ha->current_topology = ISP_CFG_FL;
2022 strcpy(connect_type, "(FL_Port)");
2023 break;
2024
2025 case 2:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002026 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 ha->operating_mode = P2P;
2028 ha->current_topology = ISP_CFG_N;
2029 strcpy(connect_type, "(N_Port-to-N_Port)");
2030 break;
2031
2032 case 3:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002033 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002034 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 ha->operating_mode = P2P;
2036 ha->current_topology = ISP_CFG_F;
2037 strcpy(connect_type, "(F_Port)");
2038 break;
2039
2040 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002041 ql_dbg(ql_dbg_disc, vha, 0x200f,
2042 "HBA in unknown topology %x, using NL.\n", topo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 ha->current_topology = ISP_CFG_NL;
2044 strcpy(connect_type, "(Loop)");
2045 break;
2046 }
2047
2048 /* Save Host port and loop ID. */
2049 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002050 vha->d_id.b.domain = domain;
2051 vha->d_id.b.area = area;
2052 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002054 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002055 ql_log(ql_log_info, vha, 0x2010,
2056 "Topology - %s, Host Loop address 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002057 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058
2059 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002060 ql_log(ql_log_warn, vha, 0x2011,
2061 "%s FAILED\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002063 ql_dbg(ql_dbg_disc, vha, 0x2012,
2064 "%s success\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 }
2066
2067 return(rval);
2068}
2069
Giridhar Malavalia9083012010-04-12 17:59:55 -07002070inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002071qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
2072 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002073{
2074 char *st, *en;
2075 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002076 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07002077 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002078 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002079
2080 if (memcmp(model, BINZERO, len) != 0) {
2081 strncpy(ha->model_number, model, len);
2082 st = en = ha->model_number;
2083 en += len - 1;
2084 while (en > st) {
2085 if (*en != 0x20 && *en != 0x00)
2086 break;
2087 *en-- = '\0';
2088 }
2089
2090 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002091 if (use_tbl &&
2092 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002093 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002094 strncpy(ha->model_desc,
2095 qla2x00_model_name[index * 2 + 1],
2096 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002097 } else {
2098 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002099 if (use_tbl &&
2100 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002101 index < QLA_MODEL_NAMES) {
2102 strcpy(ha->model_number,
2103 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002104 strncpy(ha->model_desc,
2105 qla2x00_model_name[index * 2 + 1],
2106 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002107 } else {
2108 strcpy(ha->model_number, def);
2109 }
2110 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002111 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002112 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002113 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002114}
2115
David Miller4e08df32007-04-16 12:37:43 -07002116/* On sparc systems, obtain port and node WWN from firmware
2117 * properties.
2118 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002119static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07002120{
2121#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002122 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07002123 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07002124 struct device_node *dp = pci_device_to_OF_node(pdev);
2125 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07002126 int len;
2127
2128 val = of_get_property(dp, "port-wwn", &len);
2129 if (val && len >= WWN_SIZE)
2130 memcpy(nv->port_name, val, WWN_SIZE);
2131
2132 val = of_get_property(dp, "node-wwn", &len);
2133 if (val && len >= WWN_SIZE)
2134 memcpy(nv->node_name, val, WWN_SIZE);
2135#endif
2136}
2137
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138/*
2139* NVRAM configuration for ISP 2xxx
2140*
2141* Input:
2142* ha = adapter block pointer.
2143*
2144* Output:
2145* initialization control block in response_ring
2146* host adapters parameters in host adapter block
2147*
2148* Returns:
2149* 0 = success.
2150*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002151int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002152qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153{
David Miller4e08df32007-04-16 12:37:43 -07002154 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002155 uint8_t chksum = 0;
2156 uint16_t cnt;
2157 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002158 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002159 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07002160 nvram_t *nv = ha->nvram;
2161 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002162 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163
David Miller4e08df32007-04-16 12:37:43 -07002164 rval = QLA_SUCCESS;
2165
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002167 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 ha->nvram_base = 0;
2169 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2170 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
2171 ha->nvram_base = 0x80;
2172
2173 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002174 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002175 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2176 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002178 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
2179 "Contents of NVRAM.\n");
2180 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
2181 (uint8_t *)nv, ha->nvram_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182
2183 /* Bad NVRAM data, set defaults parameters. */
2184 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2185 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2186 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002187 ql_log(ql_log_warn, vha, 0x0064,
2188 "Inconisistent NVRAM "
2189 "detected: checksum=0x%x id=%c version=0x%x.\n",
2190 chksum, nv->id[0], nv->nvram_version);
2191 ql_log(ql_log_warn, vha, 0x0065,
2192 "Falling back to "
2193 "functioning (yet invalid -- WWPN) defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07002194
2195 /*
2196 * Set default initialization control block.
2197 */
2198 memset(nv, 0, ha->nvram_size);
2199 nv->parameter_block_version = ICB_VERSION;
2200
2201 if (IS_QLA23XX(ha)) {
2202 nv->firmware_options[0] = BIT_2 | BIT_1;
2203 nv->firmware_options[1] = BIT_7 | BIT_5;
2204 nv->add_firmware_options[0] = BIT_5;
2205 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2206 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2207 nv->special_options[1] = BIT_7;
2208 } else if (IS_QLA2200(ha)) {
2209 nv->firmware_options[0] = BIT_2 | BIT_1;
2210 nv->firmware_options[1] = BIT_7 | BIT_5;
2211 nv->add_firmware_options[0] = BIT_5;
2212 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2213 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2214 } else if (IS_QLA2100(ha)) {
2215 nv->firmware_options[0] = BIT_3 | BIT_1;
2216 nv->firmware_options[1] = BIT_5;
2217 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2218 }
2219
2220 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
2221 nv->execution_throttle = __constant_cpu_to_le16(16);
2222 nv->retry_count = 8;
2223 nv->retry_delay = 1;
2224
2225 nv->port_name[0] = 33;
2226 nv->port_name[3] = 224;
2227 nv->port_name[4] = 139;
2228
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002229 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07002230
2231 nv->login_timeout = 4;
2232
2233 /*
2234 * Set default host adapter parameters
2235 */
2236 nv->host_p[1] = BIT_2;
2237 nv->reset_delay = 5;
2238 nv->port_down_retry_count = 8;
2239 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2240 nv->link_down_timeout = 60;
2241
2242 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 }
2244
2245#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2246 /*
2247 * The SN2 does not provide BIOS emulation which means you can't change
2248 * potentially bogus BIOS settings. Force the use of default settings
2249 * for link rate and frame size. Hope that the rest of the settings
2250 * are valid.
2251 */
2252 if (ia64_platform_is("sn2")) {
2253 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2254 if (IS_QLA23XX(ha))
2255 nv->special_options[1] = BIT_7;
2256 }
2257#endif
2258
2259 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002260 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261
2262 /*
2263 * Setup driver NVRAM options.
2264 */
2265 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2266 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2267 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2268 nv->firmware_options[1] &= ~BIT_4;
2269
2270 if (IS_QLA23XX(ha)) {
2271 nv->firmware_options[0] |= BIT_2;
2272 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002273 nv->firmware_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002274 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275
2276 if (IS_QLA2300(ha)) {
2277 if (ha->fb_rev == FPM_2310) {
2278 strcpy(ha->model_number, "QLA2310");
2279 } else {
2280 strcpy(ha->model_number, "QLA2300");
2281 }
2282 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002283 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002284 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 }
2286 } else if (IS_QLA2200(ha)) {
2287 nv->firmware_options[0] |= BIT_2;
2288 /*
2289 * 'Point-to-point preferred, else loop' is not a safe
2290 * connection mode setting.
2291 */
2292 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2293 (BIT_5 | BIT_4)) {
2294 /* Force 'loop preferred, else point-to-point'. */
2295 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2296 nv->add_firmware_options[0] |= BIT_5;
2297 }
2298 strcpy(ha->model_number, "QLA22xx");
2299 } else /*if (IS_QLA2100(ha))*/ {
2300 strcpy(ha->model_number, "QLA2100");
2301 }
2302
2303 /*
2304 * Copy over NVRAM RISC parameter block to initialization control block.
2305 */
2306 dptr1 = (uint8_t *)icb;
2307 dptr2 = (uint8_t *)&nv->parameter_block_version;
2308 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2309 while (cnt--)
2310 *dptr1++ = *dptr2++;
2311
2312 /* Copy 2nd half. */
2313 dptr1 = (uint8_t *)icb->add_firmware_options;
2314 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2315 while (cnt--)
2316 *dptr1++ = *dptr2++;
2317
Andrew Vasquez5341e862006-05-17 15:09:16 -07002318 /* Use alternate WWN? */
2319 if (nv->host_p[1] & BIT_7) {
2320 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2321 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2322 }
2323
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 /* Prepare nodename */
2325 if ((icb->firmware_options[1] & BIT_6) == 0) {
2326 /*
2327 * Firmware will apply the following mask if the nodename was
2328 * not provided.
2329 */
2330 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2331 icb->node_name[0] &= 0xF0;
2332 }
2333
2334 /*
2335 * Set host adapter parameters.
2336 */
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002337
2338 /*
2339 * BIT_7 in the host-parameters section allows for modification to
2340 * internal driver logging.
2341 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002342 if (nv->host_p[0] & BIT_7)
Chad Dupuiscfb09192011-11-18 09:03:07 -08002343 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2345 /* Always load RISC code on non ISP2[12]00 chips. */
2346 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2347 ha->flags.disable_risc_code_load = 0;
2348 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2349 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2350 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002351 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002352 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353
2354 ha->operating_mode =
2355 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2356
2357 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2358 sizeof(ha->fw_seriallink_options));
2359
2360 /* save HBA serial number */
2361 ha->serial0 = icb->port_name[5];
2362 ha->serial1 = icb->port_name[6];
2363 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002364 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2365 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366
2367 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2368
2369 ha->retry_count = nv->retry_count;
2370
2371 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07002372 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 nv->login_timeout = ql2xlogintimeout;
2374 if (nv->login_timeout < 4)
2375 nv->login_timeout = 4;
2376 ha->login_timeout = nv->login_timeout;
2377 icb->login_timeout = nv->login_timeout;
2378
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002379 /* Set minimum RATOV to 100 tenths of a second. */
2380 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 ha->loop_reset_delay = nv->reset_delay;
2383
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 /* Link Down Timeout = 0:
2385 *
2386 * When Port Down timer expires we will start returning
2387 * I/O's to OS with "DID_NO_CONNECT".
2388 *
2389 * Link Down Timeout != 0:
2390 *
2391 * The driver waits for the link to come up after link down
2392 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002393 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 if (nv->link_down_timeout == 0) {
2395 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002396 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 } else {
2398 ha->link_down_timeout = nv->link_down_timeout;
2399 ha->loop_down_abort_time =
2400 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002401 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 /*
2404 * Need enough time to try and get the port back.
2405 */
2406 ha->port_down_retry_count = nv->port_down_retry_count;
2407 if (qlport_down_retry)
2408 ha->port_down_retry_count = qlport_down_retry;
2409 /* Set login_retry_count */
2410 ha->login_retry_count = nv->retry_count;
2411 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2412 ha->port_down_retry_count > 3)
2413 ha->login_retry_count = ha->port_down_retry_count;
2414 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2415 ha->login_retry_count = ha->port_down_retry_count;
2416 if (ql2xloginretrycount)
2417 ha->login_retry_count = ql2xloginretrycount;
2418
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 icb->lun_enables = __constant_cpu_to_le16(0);
2420 icb->command_resource_count = 0;
2421 icb->immediate_notify_resource_count = 0;
2422 icb->timeout = __constant_cpu_to_le16(0);
2423
2424 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2425 /* Enable RIO */
2426 icb->firmware_options[0] &= ~BIT_3;
2427 icb->add_firmware_options[0] &=
2428 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2429 icb->add_firmware_options[0] |= BIT_2;
2430 icb->response_accumulation_timer = 3;
2431 icb->interrupt_delay_timer = 5;
2432
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002433 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002435 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002436 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002437 ha->zio_mode = icb->add_firmware_options[0] &
2438 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2439 ha->zio_timer = icb->interrupt_delay_timer ?
2440 icb->interrupt_delay_timer: 2;
2441 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 icb->add_firmware_options[0] &=
2443 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002444 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002445 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002446 ha->zio_mode = QLA_ZIO_MODE_6;
2447
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002448 ql_log(ql_log_info, vha, 0x0068,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002449 "ZIO mode %d enabled; timer delay (%d us).\n",
2450 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002452 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2453 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002454 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 }
2456 }
2457
David Miller4e08df32007-04-16 12:37:43 -07002458 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002459 ql_log(ql_log_warn, vha, 0x0069,
2460 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07002461 }
2462 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463}
2464
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002465static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002466qla2x00_rport_del(void *data)
2467{
2468 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002469 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002470 unsigned long flags;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002471
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002472 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002473 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002474 fcport->drport = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002475 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002476 if (rport)
2477 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002478}
2479
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480/**
2481 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2482 * @ha: HA context
2483 * @flags: allocation flags
2484 *
2485 * Returns a pointer to the allocated fcport, or NULL, if none available.
2486 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002487fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002488qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489{
2490 fc_port_t *fcport;
2491
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002492 fcport = kzalloc(sizeof(fc_port_t), flags);
2493 if (!fcport)
2494 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495
2496 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002497 fcport->vha = vha;
2498 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 fcport->port_type = FCT_UNKNOWN;
2500 fcport->loop_id = FC_NO_LOOP_ID;
Chad Dupuisec426e12011-03-30 11:46:32 -07002501 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002502 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002504 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505}
2506
2507/*
2508 * qla2x00_configure_loop
2509 * Updates Fibre Channel Device Database with what is actually on loop.
2510 *
2511 * Input:
2512 * ha = adapter block pointer.
2513 *
2514 * Returns:
2515 * 0 = success.
2516 * 1 = error.
2517 * 2 = database was full and device was not configured.
2518 */
2519static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002520qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521{
2522 int rval;
2523 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002524 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 rval = QLA_SUCCESS;
2526
2527 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002528 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2529 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002531 ql_dbg(ql_dbg_disc, vha, 0x2013,
2532 "Unable to configure HBA.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 return (rval);
2534 }
2535 }
2536
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002537 save_flags = flags = vha->dpc_flags;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002538 ql_dbg(ql_dbg_disc, vha, 0x2014,
2539 "Configure loop -- dpc flags = 0x%lx.\n", flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540
2541 /*
2542 * If we have both an RSCN and PORT UPDATE pending then handle them
2543 * both at the same time.
2544 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002545 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2546 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547
Michael Hernandez3064ff32009-12-15 21:29:44 -08002548 qla2x00_get_data_rate(vha);
2549
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 /* Determine what we need to do */
2551 if (ha->current_topology == ISP_CFG_FL &&
2552 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2553
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002554 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 set_bit(RSCN_UPDATE, &flags);
2556
2557 } else if (ha->current_topology == ISP_CFG_F &&
2558 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2559
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002560 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 set_bit(RSCN_UPDATE, &flags);
2562 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2563
Andrew Vasquez21333b42006-05-17 15:09:56 -07002564 } else if (ha->current_topology == ISP_CFG_N) {
2565 clear_bit(RSCN_UPDATE, &flags);
2566
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002567 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2569
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002570 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 set_bit(RSCN_UPDATE, &flags);
2572 set_bit(LOCAL_LOOP_UPDATE, &flags);
2573 }
2574
2575 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002576 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2577 ql_dbg(ql_dbg_disc, vha, 0x2015,
2578 "Loop resync needed, failing.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579 rval = QLA_FUNCTION_FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002580 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002581 else
2582 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 }
2584
2585 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002586 if (LOOP_TRANSITION(vha)) {
2587 ql_dbg(ql_dbg_disc, vha, 0x201e,
2588 "Needs RSCN update and loop transition.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 rval = QLA_FUNCTION_FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002590 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002591 else
2592 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 }
2594
2595 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002596 if (atomic_read(&vha->loop_down_timer) ||
2597 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 rval = QLA_FUNCTION_FAILED;
2599 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002600 atomic_set(&vha->loop_state, LOOP_READY);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002601 ql_dbg(ql_dbg_disc, vha, 0x2069,
2602 "LOOP READY.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 }
2604 }
2605
2606 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002607 ql_dbg(ql_dbg_disc, vha, 0x206a,
2608 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002610 ql_dbg(ql_dbg_disc, vha, 0x206b,
2611 "%s: exiting normally.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 }
2613
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002614 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002615 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002617 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002618 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002619 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07002620 if (!IS_ALOGIO_CAPABLE(ha))
2621 vha->flags.rscn_queue_overflow = 1;
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002622 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 }
2624
2625 return (rval);
2626}
2627
2628
2629
2630/*
2631 * qla2x00_configure_local_loop
2632 * Updates Fibre Channel Device Database with local loop devices.
2633 *
2634 * Input:
2635 * ha = adapter block pointer.
2636 *
2637 * Returns:
2638 * 0 = success.
2639 */
2640static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002641qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642{
2643 int rval, rval2;
2644 int found_devs;
2645 int found;
2646 fc_port_t *fcport, *new_fcport;
2647
2648 uint16_t index;
2649 uint16_t entries;
2650 char *id_iter;
2651 uint16_t loop_id;
2652 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002653 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654
2655 found_devs = 0;
2656 new_fcport = NULL;
2657 entries = MAX_FIBRE_DEVICES;
2658
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002659 ql_dbg(ql_dbg_disc, vha, 0x2016,
2660 "Getting FCAL position map.\n");
2661 if (ql2xextended_error_logging & ql_dbg_disc)
2662 qla2x00_get_fcal_position_map(vha, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663
2664 /* Get list of logged in devices. */
2665 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002666 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 &entries);
2668 if (rval != QLA_SUCCESS)
2669 goto cleanup_allocation;
2670
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002671 ql_dbg(ql_dbg_disc, vha, 0x2017,
2672 "Entries in ID list (%d).\n", entries);
2673 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
2674 (uint8_t *)ha->gid_list,
2675 entries * sizeof(struct gid_list_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676
2677 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002678 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002680 ql_log(ql_log_warn, vha, 0x2018,
2681 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 rval = QLA_MEMORY_ALLOC_FAILED;
2683 goto cleanup_allocation;
2684 }
2685 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2686
2687 /*
2688 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2689 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002690 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2692 fcport->port_type != FCT_BROADCAST &&
2693 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2694
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002695 ql_dbg(ql_dbg_disc, vha, 0x2019,
2696 "Marking port lost loop_id=0x%04x.\n",
2697 fcport->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698
Chad Dupuisec426e12011-03-30 11:46:32 -07002699 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 }
2701 }
2702
2703 /* Add devices to port list. */
2704 id_iter = (char *)ha->gid_list;
2705 for (index = 0; index < entries; index++) {
2706 domain = ((struct gid_list_info *)id_iter)->domain;
2707 area = ((struct gid_list_info *)id_iter)->area;
2708 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002709 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 loop_id = (uint16_t)
2711 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002712 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713 loop_id = le16_to_cpu(
2714 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002715 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716
2717 /* Bypass reserved domain fields. */
2718 if ((domain & 0xf0) == 0xf0)
2719 continue;
2720
2721 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002722 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002723 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 continue;
2725
2726 /* Bypass invalid local loop ID. */
2727 if (loop_id > LAST_LOCAL_LOOP_ID)
2728 continue;
2729
2730 /* Fill in member data. */
2731 new_fcport->d_id.b.domain = domain;
2732 new_fcport->d_id.b.area = area;
2733 new_fcport->d_id.b.al_pa = al_pa;
2734 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002735 new_fcport->vp_idx = vha->vp_idx;
2736 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002738 ql_dbg(ql_dbg_disc, vha, 0x201a,
2739 "Failed to retrieve fcport information "
2740 "-- get_port_database=%x, loop_id=0x%04x.\n",
2741 rval2, new_fcport->loop_id);
2742 ql_dbg(ql_dbg_disc, vha, 0x201b,
2743 "Scheduling resync.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002744 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 continue;
2746 }
2747
2748 /* Check for matching device in port list. */
2749 found = 0;
2750 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002751 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752 if (memcmp(new_fcport->port_name, fcport->port_name,
2753 WWN_SIZE))
2754 continue;
2755
Shyam Sundarddb9b122009-03-24 09:08:10 -07002756 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 fcport->loop_id = new_fcport->loop_id;
2758 fcport->port_type = new_fcport->port_type;
2759 fcport->d_id.b24 = new_fcport->d_id.b24;
2760 memcpy(fcport->node_name, new_fcport->node_name,
2761 WWN_SIZE);
2762
2763 found++;
2764 break;
2765 }
2766
2767 if (!found) {
2768 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002769 if (vha->vp_idx) {
2770 new_fcport->vha = vha;
2771 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002772 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002773 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774
2775 /* Allocate a new replacement fcport. */
2776 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002777 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002779 ql_log(ql_log_warn, vha, 0x201c,
2780 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781 rval = QLA_MEMORY_ALLOC_FAILED;
2782 goto cleanup_allocation;
2783 }
2784 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2785 }
2786
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002787 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002788 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002789
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002790 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791
2792 found_devs++;
2793 }
2794
2795cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002796 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797
2798 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002799 ql_dbg(ql_dbg_disc, vha, 0x201d,
2800 "Configure local loop error exit: rval=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 }
2802
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 return (rval);
2804}
2805
2806static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002807qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002808{
2809#define LS_UNKNOWN 2
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002810 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2811 char *link_speed;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002812 int rval;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07002813 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002814 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002815
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002816 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002817 return;
2818
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07002819 if (atomic_read(&fcport->state) != FCS_ONLINE)
2820 return;
2821
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002822 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2823 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002824 return;
2825
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002826 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002827 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002828 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002829 ql_dbg(ql_dbg_disc, vha, 0x2004,
2830 "Unable to adjust iIDMA "
2831 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x "
2832 "%04x.\n", fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002833 fcport->port_name[2], fcport->port_name[3],
2834 fcport->port_name[4], fcport->port_name[5],
2835 fcport->port_name[6], fcport->port_name[7], rval,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002836 fcport->fp_speed, mb[0], mb[1]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002837 } else {
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002838 link_speed = link_speeds[LS_UNKNOWN];
2839 if (fcport->fp_speed < 5)
2840 link_speed = link_speeds[fcport->fp_speed];
2841 else if (fcport->fp_speed == 0x13)
2842 link_speed = link_speeds[5];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002843 ql_dbg(ql_dbg_disc, vha, 0x2005,
2844 "iIDMA adjusted to %s GB/s "
2845 "on %02x%02x%02x%02x%02x%02x%02x%02x.\n", link_speed,
2846 fcport->port_name[0], fcport->port_name[1],
2847 fcport->port_name[2], fcport->port_name[3],
2848 fcport->port_name[4], fcport->port_name[5],
2849 fcport->port_name[6], fcport->port_name[7]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002850 }
2851}
2852
Adrian Bunk23be3312006-11-24 02:46:01 +01002853static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002854qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002855{
2856 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002857 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002858 unsigned long flags;
8482e1182005-04-17 15:04:54 -05002859
Andrew Vasquezac280b62009-08-20 11:06:05 -07002860 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002861
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002862 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2863 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002864 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2865 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2866 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002867 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002868 if (!rport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002869 ql_log(ql_log_warn, vha, 0x2006,
2870 "Unable to allocate fc remote port.\n");
Andrew Vasquez77d74142005-07-08 18:00:36 -07002871 return;
2872 }
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002873 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002874 *((fc_port_t **)rport->dd_data) = fcport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002875 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002876
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002877 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002878
2879 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002880 if (fcport->port_type == FCT_INITIATOR)
2881 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2882 if (fcport->port_type == FCT_TARGET)
2883 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002884 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002885}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886
2887/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002888 * qla2x00_update_fcport
2889 * Updates device on list.
2890 *
2891 * Input:
2892 * ha = adapter block pointer.
2893 * fcport = port structure pointer.
2894 *
2895 * Return:
2896 * 0 - Success
2897 * BIT_0 - error
2898 *
2899 * Context:
2900 * Kernel context.
2901 */
2902void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002903qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002904{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002905 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002906 fcport->login_retry = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002907 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Adrian Bunk23be3312006-11-24 02:46:01 +01002908
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002909 qla2x00_iidma_fcport(vha, fcport);
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08002910 qla24xx_update_fcport_fcp_prio(vha, fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002911 qla2x00_reg_remote_port(vha, fcport);
Chad Dupuisec426e12011-03-30 11:46:32 -07002912 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Adrian Bunk23be3312006-11-24 02:46:01 +01002913}
2914
2915/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 * qla2x00_configure_fabric
2917 * Setup SNS devices with loop ID's.
2918 *
2919 * Input:
2920 * ha = adapter block pointer.
2921 *
2922 * Returns:
2923 * 0 = success.
2924 * BIT_0 = error
2925 */
2926static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002927qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928{
2929 int rval, rval2;
2930 fc_port_t *fcport, *fcptemp;
2931 uint16_t next_loopid;
2932 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002933 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002935 struct qla_hw_data *ha = vha->hw;
2936 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937
2938 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002939 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002940 loop_id = NPH_F_PORT;
2941 else
2942 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002943 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002945 ql_dbg(ql_dbg_disc, vha, 0x201f,
2946 "MBX_GET_PORT_NAME failed, No FL Port.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002948 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949 return (QLA_SUCCESS);
2950 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002951 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952
2953 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002954 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955 if (rval2 == QLA_RSCNS_HANDLED) {
2956 /* No point doing the scan, just continue. */
2957 return (QLA_SUCCESS);
2958 }
2959 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002960 /* FDMI support. */
2961 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002962 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2963 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002964
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002966 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002967 loop_id = NPH_SNS;
2968 else
2969 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002970 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002971 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 if (mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002973 ql_dbg(ql_dbg_disc, vha, 0x2042,
2974 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
2975 "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1],
2976 mb[2], mb[6], mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 return (QLA_SUCCESS);
2978 }
2979
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002980 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2981 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002983 ql_dbg(ql_dbg_disc, vha, 0x2045,
2984 "Register FC-4 TYPE failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002986 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002988 ql_dbg(ql_dbg_disc, vha, 0x2049,
2989 "Register FC-4 Features failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002991 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002993 ql_dbg(ql_dbg_disc, vha, 0x204f,
2994 "Register Node Name failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002995 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002997 ql_dbg(ql_dbg_disc, vha, 0x2053,
2998 "Register Symobilic Node Name failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 }
3000 }
3001
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003002 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 if (rval != QLA_SUCCESS)
3004 break;
3005
3006 /*
3007 * Logout all previous fabric devices marked lost, except
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003008 * FCP2 devices.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003010 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3011 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012 break;
3013
3014 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3015 continue;
3016
3017 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003018 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003019 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003021 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 fcport->port_type != FCT_INITIATOR &&
3023 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003024 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003025 fcport->loop_id,
3026 fcport->d_id.b.domain,
3027 fcport->d_id.b.area,
3028 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 fcport->loop_id = FC_NO_LOOP_ID;
3030 }
3031 }
3032 }
3033
3034 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003035 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036
3037 /*
3038 * Scan through our port list and login entries that need to be
3039 * logged in.
3040 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003041 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3042 if (atomic_read(&vha->loop_down_timer) ||
3043 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 break;
3045
3046 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3047 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
3048 continue;
3049
3050 if (fcport->loop_id == FC_NO_LOOP_ID) {
3051 fcport->loop_id = next_loopid;
Seokmann Jud4486fd62008-04-03 13:13:28 -07003052 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003053 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054 if (rval != QLA_SUCCESS) {
3055 /* Ran out of IDs to use */
3056 break;
3057 }
3058 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003060 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 }
3062
3063 /* Exit if out of loop IDs. */
3064 if (rval != QLA_SUCCESS) {
3065 break;
3066 }
3067
3068 /*
3069 * Login and add the new devices to our port list.
3070 */
3071 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003072 if (atomic_read(&vha->loop_down_timer) ||
3073 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074 break;
3075
3076 /* Find a new loop ID to use. */
3077 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003078 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 if (rval != QLA_SUCCESS) {
3080 /* Ran out of IDs to use */
3081 break;
3082 }
3083
bdf79622005-04-17 15:06:53 -05003084 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003085 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003086
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003087 if (vha->vp_idx) {
3088 fcport->vha = vha;
3089 fcport->vp_idx = vha->vp_idx;
3090 }
3091 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092 }
3093 } while (0);
3094
3095 /* Free all new device structures not processed. */
3096 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3097 list_del(&fcport->list);
3098 kfree(fcport);
3099 }
3100
3101 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003102 ql_dbg(ql_dbg_disc, vha, 0x2068,
3103 "Configure fabric error exit rval=%d.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104 }
3105
3106 return (rval);
3107}
3108
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109/*
3110 * qla2x00_find_all_fabric_devs
3111 *
3112 * Input:
3113 * ha = adapter block pointer.
3114 * dev = database device entry pointer.
3115 *
3116 * Returns:
3117 * 0 = success.
3118 *
3119 * Context:
3120 * Kernel context.
3121 */
3122static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003123qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3124 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125{
3126 int rval;
3127 uint16_t loop_id;
3128 fc_port_t *fcport, *new_fcport, *fcptemp;
3129 int found;
3130
3131 sw_info_t *swl;
3132 int swl_idx;
3133 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07003134 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003135 struct qla_hw_data *ha = vha->hw;
3136 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003137 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138
3139 rval = QLA_SUCCESS;
3140
3141 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07003142 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003143 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003145 ql_dbg(ql_dbg_disc, vha, 0x2054,
3146 "GID_PT allocations failed, fallback on GA_NXT.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003148 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149 kfree(swl);
3150 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003151 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 kfree(swl);
3153 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003154 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155 kfree(swl);
3156 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07003157 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003158 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3159 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003161
3162 /* If other queries succeeded probe for FC-4 type */
3163 if (swl)
3164 qla2x00_gff_id(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 }
3166 swl_idx = 0;
3167
3168 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003169 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003171 ql_log(ql_log_warn, vha, 0x205e,
3172 "Failed to allocate memory for fcport.\n");
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003173 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174 return (QLA_MEMORY_ALLOC_FAILED);
3175 }
3176 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 /* Set start port ID scan at adapter ID. */
3178 first_dev = 1;
3179 last_dev = 0;
3180
3181 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003182 loop_id = ha->min_external_loopid;
3183 for (; loop_id <= ha->max_loop_id; loop_id++) {
3184 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 continue;
3186
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07003187 if (ha->current_topology == ISP_CFG_FL &&
3188 (atomic_read(&vha->loop_down_timer) ||
3189 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003190 atomic_set(&vha->loop_down_timer, 0);
3191 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3192 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003194 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195
3196 if (swl != NULL) {
3197 if (last_dev) {
3198 wrap.b24 = new_fcport->d_id.b24;
3199 } else {
3200 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3201 memcpy(new_fcport->node_name,
3202 swl[swl_idx].node_name, WWN_SIZE);
3203 memcpy(new_fcport->port_name,
3204 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003205 memcpy(new_fcport->fabric_port_name,
3206 swl[swl_idx].fabric_port_name, WWN_SIZE);
3207 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003208 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209
3210 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3211 last_dev = 1;
3212 }
3213 swl_idx++;
3214 }
3215 } else {
3216 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003217 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003219 ql_log(ql_log_warn, vha, 0x2064,
3220 "SNS scan failed -- assuming "
3221 "zero-entry result.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222 list_for_each_entry_safe(fcport, fcptemp,
3223 new_fcports, list) {
3224 list_del(&fcport->list);
3225 kfree(fcport);
3226 }
3227 rval = QLA_SUCCESS;
3228 break;
3229 }
3230 }
3231
3232 /* If wrap on switch device list, exit. */
3233 if (first_dev) {
3234 wrap.b24 = new_fcport->d_id.b24;
3235 first_dev = 0;
3236 } else if (new_fcport->d_id.b24 == wrap.b24) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003237 ql_dbg(ql_dbg_disc, vha, 0x2065,
3238 "Device wrap (%02x%02x%02x).\n",
3239 new_fcport->d_id.b.domain,
3240 new_fcport->d_id.b.area,
3241 new_fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242 break;
3243 }
3244
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003245 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003246 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 continue;
3248
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003249 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003250 found = 0;
3251 if (ha->num_vhosts) {
Arun Easifeafb7b2010-09-03 14:57:00 -07003252 unsigned long flags;
3253
3254 spin_lock_irqsave(&ha->vport_slock, flags);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003255 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003256 if (new_fcport->d_id.b24 == vp->d_id.b24) {
3257 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003258 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003259 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003260 }
Arun Easifeafb7b2010-09-03 14:57:00 -07003261 spin_unlock_irqrestore(&ha->vport_slock, flags);
3262
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003263 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003264 continue;
3265 }
3266
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003267 /* Bypass if same domain and area of adapter. */
3268 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003269 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003270 ISP_CFG_FL)
3271 continue;
3272
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273 /* Bypass reserved domain fields. */
3274 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3275 continue;
3276
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003277 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07003278 if (ql2xgffidenable &&
3279 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
3280 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003281 continue;
3282
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 /* Locate matching device in database. */
3284 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003285 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286 if (memcmp(new_fcport->port_name, fcport->port_name,
3287 WWN_SIZE))
3288 continue;
3289
3290 found++;
3291
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003292 /* Update port state. */
3293 memcpy(fcport->fabric_port_name,
3294 new_fcport->fabric_port_name, WWN_SIZE);
3295 fcport->fp_speed = new_fcport->fp_speed;
3296
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297 /*
3298 * If address the same and state FCS_ONLINE, nothing
3299 * changed.
3300 */
3301 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3302 atomic_read(&fcport->state) == FCS_ONLINE) {
3303 break;
3304 }
3305
3306 /*
3307 * If device was not a fabric device before.
3308 */
3309 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3310 fcport->d_id.b24 = new_fcport->d_id.b24;
3311 fcport->loop_id = FC_NO_LOOP_ID;
3312 fcport->flags |= (FCF_FABRIC_DEVICE |
3313 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314 break;
3315 }
3316
3317 /*
3318 * Port ID changed or device was marked to be updated;
3319 * Log it out if still logged in and mark it for
3320 * relogin later.
3321 */
3322 fcport->d_id.b24 = new_fcport->d_id.b24;
3323 fcport->flags |= FCF_LOGIN_NEEDED;
3324 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003325 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326 fcport->port_type != FCT_INITIATOR &&
3327 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003328 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003329 fcport->d_id.b.domain, fcport->d_id.b.area,
3330 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331 fcport->loop_id = FC_NO_LOOP_ID;
3332 }
3333
3334 break;
3335 }
3336
3337 if (found)
3338 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339 /* If device was not in our fcports list, then add it. */
3340 list_add_tail(&new_fcport->list, new_fcports);
3341
3342 /* Allocate a new replacement fcport. */
3343 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003344 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003346 ql_log(ql_log_warn, vha, 0x2066,
3347 "Memory allocation failed for fcport.\n");
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003348 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 return (QLA_MEMORY_ALLOC_FAILED);
3350 }
3351 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3352 new_fcport->d_id.b24 = nxt_d_id.b24;
3353 }
3354
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003355 kfree(swl);
3356 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358 return (rval);
3359}
3360
3361/*
3362 * qla2x00_find_new_loop_id
3363 * Scan through our port list and find a new usable loop ID.
3364 *
3365 * Input:
3366 * ha: adapter state pointer.
3367 * dev: port structure pointer.
3368 *
3369 * Returns:
3370 * qla2x00 local function return status code.
3371 *
3372 * Context:
3373 * Kernel context.
3374 */
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07003375int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003376qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377{
3378 int rval;
3379 int found;
3380 fc_port_t *fcport;
3381 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003382 struct qla_hw_data *ha = vha->hw;
3383 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003384 struct scsi_qla_host *tvp;
Arun Easifeafb7b2010-09-03 14:57:00 -07003385 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386
3387 rval = QLA_SUCCESS;
3388
3389 /* Save starting loop ID. */
3390 first_loop_id = dev->loop_id;
3391
3392 for (;;) {
3393 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003394 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003396
3397 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003398 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400
3401 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003402 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403 /* first loop ID. */
3404 dev->loop_id = ha->min_external_loopid;
3405 }
3406
3407 /* Check for loop ID being already in use. */
3408 found = 0;
3409 fcport = NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003410
3411 spin_lock_irqsave(&ha->vport_slock, flags);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003412 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003413 list_for_each_entry(fcport, &vp->vp_fcports, list) {
3414 if (fcport->loop_id == dev->loop_id &&
3415 fcport != dev) {
3416 /* ID possibly in use */
3417 found++;
3418 break;
3419 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003421 if (found)
3422 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003423 }
Arun Easifeafb7b2010-09-03 14:57:00 -07003424 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003425
3426 /* If not in use then it is free to use. */
3427 if (!found) {
3428 break;
3429 }
3430
3431 /* ID in use. Try next value. */
3432 dev->loop_id++;
3433
3434 /* If wrap around. No free ID to use. */
3435 if (dev->loop_id == first_loop_id) {
3436 dev->loop_id = FC_NO_LOOP_ID;
3437 rval = QLA_FUNCTION_FAILED;
3438 break;
3439 }
3440 }
3441
3442 return (rval);
3443}
3444
3445/*
3446 * qla2x00_device_resync
3447 * Marks devices in the database that needs resynchronization.
3448 *
3449 * Input:
3450 * ha = adapter block pointer.
3451 *
3452 * Context:
3453 * Kernel context.
3454 */
3455static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003456qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457{
3458 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459 uint32_t mask;
3460 fc_port_t *fcport;
3461 uint32_t rscn_entry;
3462 uint8_t rscn_out_iter;
3463 uint8_t format;
Mike Waychison1516ef42010-05-04 15:01:31 -07003464 port_id_t d_id = {};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003465
3466 rval = QLA_RSCNS_HANDLED;
3467
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003468 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
3469 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003471 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472 format = MSB(MSW(rscn_entry));
3473 d_id.b.domain = LSB(MSW(rscn_entry));
3474 d_id.b.area = MSB(LSW(rscn_entry));
3475 d_id.b.al_pa = LSB(LSW(rscn_entry));
3476
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003477 ql_dbg(ql_dbg_disc, vha, 0x2020,
3478 "RSCN queue entry[%d] = [%02x/%02x%02x%02x].\n",
3479 vha->rscn_out_ptr, format, d_id.b.domain, d_id.b.area,
3480 d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003481
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003482 vha->rscn_out_ptr++;
3483 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
3484 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485
3486 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003487 for (rscn_out_iter = vha->rscn_out_ptr;
3488 !vha->flags.rscn_queue_overflow &&
3489 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490 rscn_out_iter = (rscn_out_iter ==
3491 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
3492
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003493 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494 break;
3495
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003496 ql_dbg(ql_dbg_disc, vha, 0x2021,
3497 "Skipping duplicate RSCN queue entry found at "
3498 "[%d].\n", rscn_out_iter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003500 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501 }
3502
3503 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003504 if (vha->flags.rscn_queue_overflow) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003505 ql_dbg(ql_dbg_disc, vha, 0x2022,
3506 "device_resync: rscn overflow.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507
3508 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003509 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510 }
3511
3512 switch (format) {
3513 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003514 mask = 0xffffff;
3515 break;
3516 case 1:
3517 mask = 0xffff00;
3518 break;
3519 case 2:
3520 mask = 0xff0000;
3521 break;
3522 default:
3523 mask = 0x0;
3524 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003525 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 break;
3527 }
3528
3529 rval = QLA_SUCCESS;
3530
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003531 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3533 (fcport->d_id.b24 & mask) != d_id.b24 ||
3534 fcport->port_type == FCT_BROADCAST)
3535 continue;
3536
3537 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3538 if (format != 3 ||
3539 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003540 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003541 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542 }
3543 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544 }
3545 }
3546 return (rval);
3547}
3548
3549/*
3550 * qla2x00_fabric_dev_login
3551 * Login fabric target device and update FC port database.
3552 *
3553 * Input:
3554 * ha: adapter state pointer.
3555 * fcport: port structure list pointer.
3556 * next_loopid: contains value of a new loop ID that can be used
3557 * by the next login attempt.
3558 *
3559 * Returns:
3560 * qla2x00 local function return status code.
3561 *
3562 * Context:
3563 * Kernel context.
3564 */
3565static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003566qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003567 uint16_t *next_loopid)
3568{
3569 int rval;
3570 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003571 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003572 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573
3574 rval = QLA_SUCCESS;
3575 retry = 0;
3576
Andrew Vasquezac280b62009-08-20 11:06:05 -07003577 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003578 if (fcport->flags & FCF_ASYNC_SENT)
3579 return rval;
3580 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003581 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3582 if (!rval)
3583 return rval;
3584 }
3585
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003586 fcport->flags &= ~FCF_ASYNC_SENT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003587 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003588 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003589 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003590 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003591 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003592 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003593 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003594 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003595 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003596 fcport->d_id.b.domain, fcport->d_id.b.area,
3597 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003598 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003599 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003600 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601 }
3602 }
3603
3604 return (rval);
3605}
3606
3607/*
3608 * qla2x00_fabric_login
3609 * Issue fabric login command.
3610 *
3611 * Input:
3612 * ha = adapter block pointer.
3613 * device = pointer to FC device type structure.
3614 *
3615 * Returns:
3616 * 0 - Login successfully
3617 * 1 - Login failed
3618 * 2 - Initiator device
3619 * 3 - Fatal error
3620 */
3621int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003622qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003623 uint16_t *next_loopid)
3624{
3625 int rval;
3626 int retry;
3627 uint16_t tmp_loopid;
3628 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003629 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630
3631 retry = 0;
3632 tmp_loopid = 0;
3633
3634 for (;;) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003635 ql_dbg(ql_dbg_disc, vha, 0x2000,
3636 "Trying Fabric Login w/loop id 0x%04x for port "
3637 "%02x%02x%02x.\n",
3638 fcport->loop_id, fcport->d_id.b.domain,
3639 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003640
3641 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003642 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003643 fcport->d_id.b.domain, fcport->d_id.b.area,
3644 fcport->d_id.b.al_pa, mb, BIT_0);
3645 if (mb[0] == MBS_PORT_ID_USED) {
3646 /*
3647 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003648 * recommends the driver perform an implicit login with
3649 * the specified ID again. The ID we just used is save
3650 * here so we return with an ID that can be tried by
3651 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003652 */
3653 retry++;
3654 tmp_loopid = fcport->loop_id;
3655 fcport->loop_id = mb[1];
3656
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003657 ql_dbg(ql_dbg_disc, vha, 0x2001,
3658 "Fabric Login: port in use - next loop "
3659 "id=0x%04x, port id= %02x%02x%02x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003660 fcport->loop_id, fcport->d_id.b.domain,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003661 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662
3663 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3664 /*
3665 * Login succeeded.
3666 */
3667 if (retry) {
3668 /* A retry occurred before. */
3669 *next_loopid = tmp_loopid;
3670 } else {
3671 /*
3672 * No retry occurred before. Just increment the
3673 * ID value for next login.
3674 */
3675 *next_loopid = (fcport->loop_id + 1);
3676 }
3677
3678 if (mb[1] & BIT_0) {
3679 fcport->port_type = FCT_INITIATOR;
3680 } else {
3681 fcport->port_type = FCT_TARGET;
3682 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07003683 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003684 }
3685 }
3686
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003687 if (mb[10] & BIT_0)
3688 fcport->supported_classes |= FC_COS_CLASS2;
3689 if (mb[10] & BIT_1)
3690 fcport->supported_classes |= FC_COS_CLASS3;
3691
Linus Torvalds1da177e2005-04-16 15:20:36 -07003692 rval = QLA_SUCCESS;
3693 break;
3694 } else if (mb[0] == MBS_LOOP_ID_USED) {
3695 /*
3696 * Loop ID already used, try next loop ID.
3697 */
3698 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003699 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700 if (rval != QLA_SUCCESS) {
3701 /* Ran out of loop IDs to use */
3702 break;
3703 }
3704 } else if (mb[0] == MBS_COMMAND_ERROR) {
3705 /*
3706 * Firmware possibly timed out during login. If NO
3707 * retries are left to do then the device is declared
3708 * dead.
3709 */
3710 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003711 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003712 fcport->d_id.b.domain, fcport->d_id.b.area,
3713 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003714 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715
3716 rval = 1;
3717 break;
3718 } else {
3719 /*
3720 * unrecoverable / not handled error
3721 */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003722 ql_dbg(ql_dbg_disc, vha, 0x2002,
3723 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
3724 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
3725 fcport->d_id.b.area, fcport->d_id.b.al_pa,
3726 fcport->loop_id, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003727
3728 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003729 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003730 fcport->d_id.b.domain, fcport->d_id.b.area,
3731 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003732 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003733 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003734
3735 rval = 3;
3736 break;
3737 }
3738 }
3739
3740 return (rval);
3741}
3742
3743/*
3744 * qla2x00_local_device_login
3745 * Issue local device login command.
3746 *
3747 * Input:
3748 * ha = adapter block pointer.
3749 * loop_id = loop id of device to login to.
3750 *
3751 * Returns (Where's the #define!!!!):
3752 * 0 - Login successfully
3753 * 1 - Login failed
3754 * 3 - Fatal error
3755 */
3756int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003757qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003758{
3759 int rval;
3760 uint16_t mb[MAILBOX_REGISTER_COUNT];
3761
3762 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003763 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003764 if (rval == QLA_SUCCESS) {
3765 /* Interrogate mailbox registers for any errors */
3766 if (mb[0] == MBS_COMMAND_ERROR)
3767 rval = 1;
3768 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3769 /* device not in PCB table */
3770 rval = 3;
3771 }
3772
3773 return (rval);
3774}
3775
3776/*
3777 * qla2x00_loop_resync
3778 * Resync with fibre channel devices.
3779 *
3780 * Input:
3781 * ha = adapter block pointer.
3782 *
3783 * Returns:
3784 * 0 = success
3785 */
3786int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003787qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003789 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003791 struct req_que *req;
3792 struct rsp_que *rsp;
3793
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07003794 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003795 req = vha->hw->req_q_map[0];
3796 else
3797 req = vha->req;
3798 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003799
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003800 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3801 if (vha->flags.online) {
3802 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3804 wait_time = 256;
3805 do {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003806 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003807 qla2x00_marker(vha, req, rsp, 0, 0,
3808 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003809 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810
3811 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003812 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003814 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003816 } while (!atomic_read(&vha->loop_down_timer) &&
3817 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3818 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3819 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821 }
3822
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003823 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003826 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003827 ql_dbg(ql_dbg_disc, vha, 0x206c,
3828 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829
3830 return (rval);
3831}
3832
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003833/*
3834* qla2x00_perform_loop_resync
3835* Description: This function will set the appropriate flags and call
3836* qla2x00_loop_resync. If successful loop will be resynced
3837* Arguments : scsi_qla_host_t pointer
3838* returm : Success or Failure
3839*/
3840
3841int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
3842{
3843 int32_t rval = 0;
3844
3845 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
3846 /*Configure the flags so that resync happens properly*/
3847 atomic_set(&ha->loop_down_timer, 0);
3848 if (!(ha->device_flags & DFLG_NO_CABLE)) {
3849 atomic_set(&ha->loop_state, LOOP_UP);
3850 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
3851 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
3852 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3853
3854 rval = qla2x00_loop_resync(ha);
3855 } else
3856 atomic_set(&ha->loop_state, LOOP_DEAD);
3857
3858 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
3859 }
3860
3861 return rval;
3862}
3863
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864void
Andrew Vasquez67becc02009-08-25 11:36:20 -07003865qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003866{
3867 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07003868 struct scsi_qla_host *vha;
3869 struct qla_hw_data *ha = base_vha->hw;
3870 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003871
Arun Easifeafb7b2010-09-03 14:57:00 -07003872 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003873 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07003874 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
3875 atomic_inc(&vha->vref_count);
3876 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Dan Carpenter8ae598d2010-12-21 16:00:15 -08003877 if (fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07003878 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
3879 spin_unlock_irqrestore(&ha->vport_slock, flags);
3880
Andrew Vasquez67becc02009-08-25 11:36:20 -07003881 qla2x00_rport_del(fcport);
Arun Easifeafb7b2010-09-03 14:57:00 -07003882
3883 spin_lock_irqsave(&ha->vport_slock, flags);
3884 }
3885 }
3886 atomic_dec(&vha->vref_count);
3887 }
3888 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003889}
3890
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003891/*
3892* qla82xx_quiescent_state_cleanup
3893* Description: This function will block the new I/Os
3894* Its not aborting any I/Os as context
3895* is not destroyed during quiescence
3896* Arguments: scsi_qla_host_t
3897* return : void
3898*/
3899void
3900qla82xx_quiescent_state_cleanup(scsi_qla_host_t *vha)
3901{
3902 struct qla_hw_data *ha = vha->hw;
3903 struct scsi_qla_host *vp;
3904
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003905 ql_dbg(ql_dbg_p3p, vha, 0xb002,
3906 "Performing ISP error recovery - ha=%p.\n", ha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003907
3908 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3909 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3910 atomic_set(&vha->loop_state, LOOP_DOWN);
3911 qla2x00_mark_all_devices_lost(vha, 0);
3912 list_for_each_entry(vp, &ha->vp_list, list)
3913 qla2x00_mark_all_devices_lost(vha, 0);
3914 } else {
3915 if (!atomic_read(&vha->loop_down_timer))
3916 atomic_set(&vha->loop_down_timer,
3917 LOOP_DOWN_TIME);
3918 }
3919 /* Wait for pending cmds to complete */
3920 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
3921}
3922
Giridhar Malavalia9083012010-04-12 17:59:55 -07003923void
3924qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
3925{
3926 struct qla_hw_data *ha = vha->hw;
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003927 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07003928 unsigned long flags;
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08003929 fc_port_t *fcport;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003930
Saurav Kashyape46ef002011-02-23 15:27:16 -08003931 /* For ISP82XX, driver waits for completion of the commands.
3932 * online flag should be set.
3933 */
3934 if (!IS_QLA82XX(ha))
3935 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003936 ha->flags.chip_reset_done = 0;
3937 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3938 ha->qla_stats.total_isp_aborts++;
3939
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003940 ql_log(ql_log_info, vha, 0x00af,
3941 "Performing ISP error recovery - ha=%p.\n", ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003942
Saurav Kashyape46ef002011-02-23 15:27:16 -08003943 /* For ISP82XX, reset_chip is just disabling interrupts.
3944 * Driver waits for the completion of the commands.
3945 * the interrupts need to be enabled.
3946 */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003947 if (!IS_QLA82XX(ha))
3948 ha->isp_ops->reset_chip(vha);
3949
3950 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3951 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3952 atomic_set(&vha->loop_state, LOOP_DOWN);
3953 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07003954
3955 spin_lock_irqsave(&ha->vport_slock, flags);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003956 list_for_each_entry(vp, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -07003957 atomic_inc(&vp->vref_count);
3958 spin_unlock_irqrestore(&ha->vport_slock, flags);
3959
Giridhar Malavalia9083012010-04-12 17:59:55 -07003960 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07003961
3962 spin_lock_irqsave(&ha->vport_slock, flags);
3963 atomic_dec(&vp->vref_count);
3964 }
3965 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003966 } else {
3967 if (!atomic_read(&vha->loop_down_timer))
3968 atomic_set(&vha->loop_down_timer,
3969 LOOP_DOWN_TIME);
3970 }
3971
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08003972 /* Clear all async request states across all VPs. */
3973 list_for_each_entry(fcport, &vha->vp_fcports, list)
3974 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
3975 spin_lock_irqsave(&ha->vport_slock, flags);
3976 list_for_each_entry(vp, &ha->vp_list, list) {
3977 atomic_inc(&vp->vref_count);
3978 spin_unlock_irqrestore(&ha->vport_slock, flags);
3979
3980 list_for_each_entry(fcport, &vp->vp_fcports, list)
3981 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
3982
3983 spin_lock_irqsave(&ha->vport_slock, flags);
3984 atomic_dec(&vp->vref_count);
3985 }
3986 spin_unlock_irqrestore(&ha->vport_slock, flags);
3987
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07003988 if (!ha->flags.eeh_busy) {
3989 /* Make sure for ISP 82XX IO DMA is complete */
3990 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08003991 qla82xx_chip_reset_cleanup(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003992 ql_log(ql_log_info, vha, 0x00b4,
3993 "Done chip reset cleanup.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003994
Saurav Kashyape46ef002011-02-23 15:27:16 -08003995 /* Done waiting for pending commands.
3996 * Reset the online flag.
3997 */
3998 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003999 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004000
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004001 /* Requeue all commands in outstanding command list. */
4002 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
4003 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004004}
4005
4006/*
4007* qla2x00_abort_isp
4008* Resets ISP and aborts all outstanding commands.
4009*
4010* Input:
4011* ha = adapter block pointer.
4012*
4013* Returns:
4014* 0 = success
4015*/
4016int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004017qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004018{
Andrew Vasquez476e8972006-08-23 14:54:55 -07004019 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004020 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004021 struct qla_hw_data *ha = vha->hw;
4022 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004023 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07004024 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004025
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004026 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004027 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004028
Andrew Vasquez85880802009-12-15 21:29:46 -08004029 if (unlikely(pci_channel_offline(ha->pdev) &&
4030 ha->flags.pci_channel_io_perm_failure)) {
4031 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4032 status = 0;
4033 return status;
4034 }
4035
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004036 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08004037
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004038 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004039
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004040 if (!qla2x00_restart_isp(vha)) {
4041 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004043 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004044 /*
4045 * Issue marker command only when we are going
4046 * to start the I/O .
4047 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004048 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004049 }
4050
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004051 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004053 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004054
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004055 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004056 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07004057
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004058 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
4059 qla2x00_get_fw_version(vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004060 if (ha->fce) {
4061 ha->flags.fce_enabled = 1;
4062 memset(ha->fce, 0,
4063 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004064 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004065 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
4066 &ha->fce_bufs);
4067 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004068 ql_log(ql_log_warn, vha, 0x8033,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004069 "Unable to reinitialize FCE "
4070 "(%d).\n", rval);
4071 ha->flags.fce_enabled = 0;
4072 }
4073 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004074
4075 if (ha->eft) {
4076 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004077 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004078 ha->eft_dma, EFT_NUM_BUFFERS);
4079 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004080 ql_log(ql_log_warn, vha, 0x8034,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004081 "Unable to reinitialize EFT "
4082 "(%d).\n", rval);
4083 }
4084 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004085 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004086 vha->flags.online = 1;
4087 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004088 if (ha->isp_abort_cnt == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004089 ql_log(ql_log_fatal, vha, 0x8035,
4090 "ISP error recover failed - "
4091 "board disabled.\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004092 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004093 * The next call disables the board
4094 * completely.
4095 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004096 ha->isp_ops->reset_adapter(vha);
4097 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004099 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004100 status = 0;
4101 } else { /* schedule another ISP abort */
4102 ha->isp_abort_cnt--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004103 ql_dbg(ql_dbg_taskm, vha, 0x8020,
4104 "ISP abort - retry remaining %d.\n",
4105 ha->isp_abort_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106 status = 1;
4107 }
4108 } else {
4109 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004110 ql_dbg(ql_dbg_taskm, vha, 0x8021,
4111 "ISP error recovery - retrying (%d) "
4112 "more times.\n", ha->isp_abort_cnt);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004113 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004114 status = 1;
4115 }
4116 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004117
Linus Torvalds1da177e2005-04-16 15:20:36 -07004118 }
4119
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004120 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004121 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
Arun Easifeafb7b2010-09-03 14:57:00 -07004122
4123 spin_lock_irqsave(&ha->vport_slock, flags);
4124 list_for_each_entry(vp, &ha->vp_list, list) {
4125 if (vp->vp_idx) {
4126 atomic_inc(&vp->vref_count);
4127 spin_unlock_irqrestore(&ha->vport_slock, flags);
4128
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004129 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07004130
4131 spin_lock_irqsave(&ha->vport_slock, flags);
4132 atomic_dec(&vp->vref_count);
4133 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004134 }
Arun Easifeafb7b2010-09-03 14:57:00 -07004135 spin_unlock_irqrestore(&ha->vport_slock, flags);
4136
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004137 } else {
Joe Perchesd8424f62011-11-18 09:03:06 -08004138 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
4139 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004140 }
4141
4142 return(status);
4143}
4144
4145/*
4146* qla2x00_restart_isp
4147* restarts the ISP after a reset
4148*
4149* Input:
4150* ha = adapter block pointer.
4151*
4152* Returns:
4153* 0 = success
4154*/
4155static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004156qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004158 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004159 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004160 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004161 struct req_que *req = ha->req_q_map[0];
4162 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004163
4164 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004165 if (qla2x00_isp_firmware(vha)) {
4166 vha->flags.online = 0;
4167 status = ha->isp_ops->chip_diag(vha);
4168 if (!status)
4169 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170 }
4171
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004172 if (!status && !(status = qla2x00_init_rings(vha))) {
4173 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07004174 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004175 /* Initialize the queues in use */
4176 qla25xx_init_queues(ha);
4177
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004178 status = qla2x00_fw_ready(vha);
4179 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004180 ql_dbg(ql_dbg_taskm, vha, 0x8031,
4181 "Start configure loop status = %d.\n", status);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004182
4183 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004184 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004185
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004186 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004187 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4188 wait_time = 256;
4189 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004190 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4191 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004193 } while (!atomic_read(&vha->loop_down_timer) &&
4194 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4195 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4196 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004197 }
4198
4199 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004200 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004201 status = 0;
4202
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004203 ql_dbg(ql_dbg_taskm, vha, 0x8032,
4204 "Configure loop done, status = 0x%x.\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205 }
4206 return (status);
4207}
4208
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004209static int
4210qla25xx_init_queues(struct qla_hw_data *ha)
4211{
4212 struct rsp_que *rsp = NULL;
4213 struct req_que *req = NULL;
4214 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4215 int ret = -1;
4216 int i;
4217
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004218 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004219 rsp = ha->rsp_q_map[i];
4220 if (rsp) {
4221 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004222 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004223 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004224 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
4225 "%s Rsp que: %d init failed.\n",
4226 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004227 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004228 ql_dbg(ql_dbg_init, base_vha, 0x0100,
4229 "%s Rsp que: %d inited.\n",
4230 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004231 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004232 }
4233 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004234 req = ha->req_q_map[i];
4235 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004236 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004237 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004238 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004239 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004240 ql_dbg(ql_dbg_init, base_vha, 0x0101,
4241 "%s Req que: %d init failed.\n",
4242 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004243 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004244 ql_dbg(ql_dbg_init, base_vha, 0x0102,
4245 "%s Req que: %d inited.\n",
4246 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004247 }
4248 }
4249 return ret;
4250}
4251
Linus Torvalds1da177e2005-04-16 15:20:36 -07004252/*
4253* qla2x00_reset_adapter
4254* Reset adapter.
4255*
4256* Input:
4257* ha = adapter block pointer.
4258*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004259void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004260qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004261{
4262 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004263 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07004264 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004265
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004266 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004267 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268
Linus Torvalds1da177e2005-04-16 15:20:36 -07004269 spin_lock_irqsave(&ha->hardware_lock, flags);
4270 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
4271 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4272 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
4273 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4274 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4275}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004276
4277void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004278qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004279{
4280 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004281 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004282 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4283
Giridhar Malavalia9083012010-04-12 17:59:55 -07004284 if (IS_QLA82XX(ha))
4285 return;
4286
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004287 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004288 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004289
4290 spin_lock_irqsave(&ha->hardware_lock, flags);
4291 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
4292 RD_REG_DWORD(&reg->hccr);
4293 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
4294 RD_REG_DWORD(&reg->hccr);
4295 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08004296
4297 if (IS_NOPOLLING_TYPE(ha))
4298 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004299}
4300
David Miller4e08df32007-04-16 12:37:43 -07004301/* On sparc systems, obtain port and node WWN from firmware
4302 * properties.
4303 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004304static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
4305 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07004306{
4307#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004308 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07004309 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07004310 struct device_node *dp = pci_device_to_OF_node(pdev);
4311 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07004312 int len;
4313
4314 val = of_get_property(dp, "port-wwn", &len);
4315 if (val && len >= WWN_SIZE)
4316 memcpy(nv->port_name, val, WWN_SIZE);
4317
4318 val = of_get_property(dp, "node-wwn", &len);
4319 if (val && len >= WWN_SIZE)
4320 memcpy(nv->node_name, val, WWN_SIZE);
4321#endif
4322}
4323
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004324int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004325qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004326{
David Miller4e08df32007-04-16 12:37:43 -07004327 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004328 struct init_cb_24xx *icb;
4329 struct nvram_24xx *nv;
4330 uint32_t *dptr;
4331 uint8_t *dptr1, *dptr2;
4332 uint32_t chksum;
4333 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004334 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004335
David Miller4e08df32007-04-16 12:37:43 -07004336 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004337 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07004338 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004339
4340 /* Determine NVRAM starting address. */
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004341 if (ha->flags.port0) {
4342 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4343 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4344 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004345 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08004346 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4347 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004348 ha->nvram_size = sizeof(struct nvram_24xx);
4349 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004350 if (IS_QLA82XX(ha))
4351 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004352
Seokmann Ju281afe12007-07-26 13:43:34 -07004353 /* Get VPD data into cache */
4354 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004355 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07004356 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4357
4358 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004359 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004360 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004361 ha->nvram_size);
4362 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4363 chksum += le32_to_cpu(*dptr++);
4364
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004365 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
4366 "Contents of NVRAM\n");
4367 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
4368 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004369
4370 /* Bad NVRAM data, set defaults parameters. */
4371 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4372 || nv->id[3] != ' ' ||
4373 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4374 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004375 ql_log(ql_log_warn, vha, 0x006b,
4376 "Inconisistent NVRAM detected: checksum=0x%x id=%c "
4377 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
4378 ql_log(ql_log_warn, vha, 0x006c,
4379 "Falling back to functioning (yet invalid -- WWPN) "
4380 "defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07004381
4382 /*
4383 * Set default initialization control block.
4384 */
4385 memset(nv, 0, ha->nvram_size);
4386 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4387 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4388 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4389 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4390 nv->exchange_count = __constant_cpu_to_le16(0);
4391 nv->hard_address = __constant_cpu_to_le16(124);
4392 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004393 nv->port_name[1] = 0x00 + ha->port_no;
David Miller4e08df32007-04-16 12:37:43 -07004394 nv->port_name[2] = 0x00;
4395 nv->port_name[3] = 0xe0;
4396 nv->port_name[4] = 0x8b;
4397 nv->port_name[5] = 0x1c;
4398 nv->port_name[6] = 0x55;
4399 nv->port_name[7] = 0x86;
4400 nv->node_name[0] = 0x20;
4401 nv->node_name[1] = 0x00;
4402 nv->node_name[2] = 0x00;
4403 nv->node_name[3] = 0xe0;
4404 nv->node_name[4] = 0x8b;
4405 nv->node_name[5] = 0x1c;
4406 nv->node_name[6] = 0x55;
4407 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004408 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07004409 nv->login_retry_count = __constant_cpu_to_le16(8);
4410 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4411 nv->login_timeout = __constant_cpu_to_le16(0);
4412 nv->firmware_options_1 =
4413 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4414 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4415 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4416 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4417 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4418 nv->efi_parameters = __constant_cpu_to_le32(0);
4419 nv->reset_delay = 5;
4420 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4421 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4422 nv->link_down_timeout = __constant_cpu_to_le16(30);
4423
4424 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004425 }
4426
4427 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004428 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004429
4430 /* Copy 1st segment. */
4431 dptr1 = (uint8_t *)icb;
4432 dptr2 = (uint8_t *)&nv->version;
4433 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4434 while (cnt--)
4435 *dptr1++ = *dptr2++;
4436
4437 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07004438 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004439
4440 /* Copy 2nd segment. */
4441 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4442 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4443 cnt = (uint8_t *)&icb->reserved_3 -
4444 (uint8_t *)&icb->interrupt_delay_timer;
4445 while (cnt--)
4446 *dptr1++ = *dptr2++;
4447
4448 /*
4449 * Setup driver NVRAM options.
4450 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004451 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004452 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004453
Andrew Vasquez5341e862006-05-17 15:09:16 -07004454 /* Use alternate WWN? */
4455 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4456 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4457 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4458 }
4459
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004460 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004461 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004462 /*
4463 * Firmware will apply the following mask if the nodename was
4464 * not provided.
4465 */
4466 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4467 icb->node_name[0] &= 0xF0;
4468 }
4469
4470 /* Set host adapter parameters. */
4471 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08004472 ha->flags.enable_lip_reset = 0;
4473 ha->flags.enable_lip_full_login =
4474 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4475 ha->flags.enable_target_reset =
4476 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004477 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004478 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004479
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004480 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4481 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004482
4483 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4484 sizeof(ha->fw_seriallink_options24));
4485
4486 /* save HBA serial number */
4487 ha->serial0 = icb->port_name[5];
4488 ha->serial1 = icb->port_name[6];
4489 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004490 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4491 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004492
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08004493 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4494
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004495 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4496
4497 /* Set minimum login_timeout to 4 seconds. */
4498 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4499 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4500 if (le16_to_cpu(nv->login_timeout) < 4)
4501 nv->login_timeout = __constant_cpu_to_le16(4);
4502 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07004503 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004504
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004505 /* Set minimum RATOV to 100 tenths of a second. */
4506 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004507
4508 ha->loop_reset_delay = nv->reset_delay;
4509
4510 /* Link Down Timeout = 0:
4511 *
4512 * When Port Down timer expires we will start returning
4513 * I/O's to OS with "DID_NO_CONNECT".
4514 *
4515 * Link Down Timeout != 0:
4516 *
4517 * The driver waits for the link to come up after link down
4518 * before returning I/Os to OS with "DID_NO_CONNECT".
4519 */
4520 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4521 ha->loop_down_abort_time =
4522 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4523 } else {
4524 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4525 ha->loop_down_abort_time =
4526 (LOOP_DOWN_TIME - ha->link_down_timeout);
4527 }
4528
4529 /* Need enough time to try and get the port back. */
4530 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4531 if (qlport_down_retry)
4532 ha->port_down_retry_count = qlport_down_retry;
4533
4534 /* Set login_retry_count */
4535 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4536 if (ha->port_down_retry_count ==
4537 le16_to_cpu(nv->port_down_retry_count) &&
4538 ha->port_down_retry_count > 3)
4539 ha->login_retry_count = ha->port_down_retry_count;
4540 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4541 ha->login_retry_count = ha->port_down_retry_count;
4542 if (ql2xloginretrycount)
4543 ha->login_retry_count = ql2xloginretrycount;
4544
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004545 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004546 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004547 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4548 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4549 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4550 le16_to_cpu(icb->interrupt_delay_timer): 2;
4551 }
4552 icb->firmware_options_2 &= __constant_cpu_to_le32(
4553 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004554 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004555 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004556 ha->zio_mode = QLA_ZIO_MODE_6;
4557
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004558 ql_log(ql_log_info, vha, 0x006f,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004559 "ZIO mode %d enabled; timer delay (%d us).\n",
4560 ha->zio_mode, ha->zio_timer * 100);
4561
4562 icb->firmware_options_2 |= cpu_to_le32(
4563 (uint32_t)ha->zio_mode);
4564 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004565 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004566 }
4567
David Miller4e08df32007-04-16 12:37:43 -07004568 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004569 ql_log(ql_log_warn, vha, 0x0070,
4570 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07004571 }
4572 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004573}
4574
Adrian Bunk413975a2006-06-30 02:33:06 -07004575static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004576qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4577 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004578{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004579 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004580 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004581 uint32_t *dcode, dlen;
4582 uint32_t risc_addr;
4583 uint32_t risc_size;
4584 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004585 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004586 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004587
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004588 ql_dbg(ql_dbg_init, vha, 0x008b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08004589 "FW: Loading firmware from flash (%x).\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004590
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004591 rval = QLA_SUCCESS;
4592
4593 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004594 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004595 *srisc_addr = 0;
4596
4597 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004598 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004599 for (i = 0; i < 4; i++)
4600 dcode[i] = be32_to_cpu(dcode[i]);
4601 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4602 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4603 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4604 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004605 ql_log(ql_log_fatal, vha, 0x008c,
4606 "Unable to verify the integrity of flash firmware "
4607 "image.\n");
4608 ql_log(ql_log_fatal, vha, 0x008d,
4609 "Firmware data: %08x %08x %08x %08x.\n",
4610 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004611
4612 return QLA_FUNCTION_FAILED;
4613 }
4614
4615 while (segments && rval == QLA_SUCCESS) {
4616 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004617 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004618
4619 risc_addr = be32_to_cpu(dcode[2]);
4620 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4621 risc_size = be32_to_cpu(dcode[3]);
4622
4623 fragment = 0;
4624 while (risc_size > 0 && rval == QLA_SUCCESS) {
4625 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4626 if (dlen > risc_size)
4627 dlen = risc_size;
4628
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004629 ql_dbg(ql_dbg_init, vha, 0x008e,
4630 "Loading risc segment@ risc addr %x "
4631 "number of dwords 0x%x offset 0x%x.\n",
4632 risc_addr, dlen, faddr);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004633
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004634 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004635 for (i = 0; i < dlen; i++)
4636 dcode[i] = swab32(dcode[i]);
4637
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004638 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004639 dlen);
4640 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004641 ql_log(ql_log_fatal, vha, 0x008f,
4642 "Failed to load segment %d of firmware.\n",
4643 fragment);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004644 break;
4645 }
4646
4647 faddr += dlen;
4648 risc_addr += dlen;
4649 risc_size -= dlen;
4650 fragment++;
4651 }
4652
4653 /* Next segment. */
4654 segments--;
4655 }
4656
4657 return rval;
4658}
4659
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004660#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4661
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004662int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004663qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08004664{
4665 int rval;
4666 int i, fragment;
4667 uint16_t *wcode, *fwcode;
4668 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4669 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004670 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004671 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08004672
4673 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004674 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004675 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004676 ql_log(ql_log_info, vha, 0x0083,
4677 "Fimware image unavailable.\n");
4678 ql_log(ql_log_info, vha, 0x0084,
4679 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08004680 return QLA_FUNCTION_FAILED;
4681 }
4682
4683 rval = QLA_SUCCESS;
4684
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004685 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08004686 *srisc_addr = 0;
4687 fwcode = (uint16_t *)blob->fw->data;
4688 fwclen = 0;
4689
4690 /* Validate firmware image by checking version. */
4691 if (blob->fw->size < 8 * sizeof(uint16_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004692 ql_log(ql_log_fatal, vha, 0x0085,
4693 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08004694 blob->fw->size);
4695 goto fail_fw_integrity;
4696 }
4697 for (i = 0; i < 4; i++)
4698 wcode[i] = be16_to_cpu(fwcode[i + 4]);
4699 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
4700 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
4701 wcode[2] == 0 && wcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004702 ql_log(ql_log_fatal, vha, 0x0086,
4703 "Unable to verify integrity of firmware image.\n");
4704 ql_log(ql_log_fatal, vha, 0x0087,
4705 "Firmware data: %04x %04x %04x %04x.\n",
4706 wcode[0], wcode[1], wcode[2], wcode[3]);
Andrew Vasquez54333832005-11-09 15:49:04 -08004707 goto fail_fw_integrity;
4708 }
4709
4710 seg = blob->segs;
4711 while (*seg && rval == QLA_SUCCESS) {
4712 risc_addr = *seg;
4713 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4714 risc_size = be16_to_cpu(fwcode[3]);
4715
4716 /* Validate firmware image size. */
4717 fwclen += risc_size * sizeof(uint16_t);
4718 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004719 ql_log(ql_log_fatal, vha, 0x0088,
Andrew Vasquez54333832005-11-09 15:49:04 -08004720 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004721 "(%Zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08004722 goto fail_fw_integrity;
4723 }
4724
4725 fragment = 0;
4726 while (risc_size > 0 && rval == QLA_SUCCESS) {
4727 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4728 if (wlen > risc_size)
4729 wlen = risc_size;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004730 ql_dbg(ql_dbg_init, vha, 0x0089,
4731 "Loading risc segment@ risc addr %x number of "
4732 "words 0x%x.\n", risc_addr, wlen);
Andrew Vasquez54333832005-11-09 15:49:04 -08004733
4734 for (i = 0; i < wlen; i++)
4735 wcode[i] = swab16(fwcode[i]);
4736
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004737 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08004738 wlen);
4739 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004740 ql_log(ql_log_fatal, vha, 0x008a,
4741 "Failed to load segment %d of firmware.\n",
4742 fragment);
Andrew Vasquez54333832005-11-09 15:49:04 -08004743 break;
4744 }
4745
4746 fwcode += wlen;
4747 risc_addr += wlen;
4748 risc_size -= wlen;
4749 fragment++;
4750 }
4751
4752 /* Next segment. */
4753 seg++;
4754 }
4755 return rval;
4756
4757fail_fw_integrity:
4758 return QLA_FUNCTION_FAILED;
4759}
4760
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004761static int
4762qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004763{
4764 int rval;
4765 int segments, fragment;
4766 uint32_t *dcode, dlen;
4767 uint32_t risc_addr;
4768 uint32_t risc_size;
4769 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004770 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004771 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004772 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004773 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004774
Andrew Vasquez54333832005-11-09 15:49:04 -08004775 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004776 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004777 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004778 ql_log(ql_log_warn, vha, 0x0090,
4779 "Fimware image unavailable.\n");
4780 ql_log(ql_log_warn, vha, 0x0091,
4781 "Firmware images can be retrieved from: "
4782 QLA_FW_URL ".\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004783
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004784 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004785 }
4786
Chad Dupuiscfb09192011-11-18 09:03:07 -08004787 ql_dbg(ql_dbg_init, vha, 0x0092,
4788 "FW: Loading via request-firmware.\n");
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004789
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004790 rval = QLA_SUCCESS;
4791
4792 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004793 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004794 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004795 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004796 fwclen = 0;
4797
4798 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004799 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004800 ql_log(ql_log_fatal, vha, 0x0093,
4801 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08004802 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004803 goto fail_fw_integrity;
4804 }
4805 for (i = 0; i < 4; i++)
4806 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4807 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4808 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4809 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4810 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004811 ql_log(ql_log_fatal, vha, 0x0094,
4812 "Unable to verify integrity of firmware image (%Zd).\n",
4813 blob->fw->size);
4814 ql_log(ql_log_fatal, vha, 0x0095,
4815 "Firmware data: %08x %08x %08x %08x.\n",
4816 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004817 goto fail_fw_integrity;
4818 }
4819
4820 while (segments && rval == QLA_SUCCESS) {
4821 risc_addr = be32_to_cpu(fwcode[2]);
4822 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4823 risc_size = be32_to_cpu(fwcode[3]);
4824
4825 /* Validate firmware image size. */
4826 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004827 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004828 ql_log(ql_log_fatal, vha, 0x0096,
Andrew Vasquez54333832005-11-09 15:49:04 -08004829 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004830 "(%Zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08004831
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004832 goto fail_fw_integrity;
4833 }
4834
4835 fragment = 0;
4836 while (risc_size > 0 && rval == QLA_SUCCESS) {
4837 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4838 if (dlen > risc_size)
4839 dlen = risc_size;
4840
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004841 ql_dbg(ql_dbg_init, vha, 0x0097,
4842 "Loading risc segment@ risc addr %x "
4843 "number of dwords 0x%x.\n", risc_addr, dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004844
4845 for (i = 0; i < dlen; i++)
4846 dcode[i] = swab32(fwcode[i]);
4847
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004848 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004849 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004850 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004851 ql_log(ql_log_fatal, vha, 0x0098,
4852 "Failed to load segment %d of firmware.\n",
4853 fragment);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004854 break;
4855 }
4856
4857 fwcode += dlen;
4858 risc_addr += dlen;
4859 risc_size -= dlen;
4860 fragment++;
4861 }
4862
4863 /* Next segment. */
4864 segments--;
4865 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004866 return rval;
4867
4868fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004869 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004870}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004871
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004872int
4873qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4874{
4875 int rval;
4876
Andrew Vasqueze337d902009-04-06 22:33:49 -07004877 if (ql2xfwloadbin == 1)
4878 return qla81xx_load_risc(vha, srisc_addr);
4879
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004880 /*
4881 * FW Load priority:
4882 * 1) Firmware via request-firmware interface (.bin file).
4883 * 2) Firmware residing in flash.
4884 */
4885 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4886 if (rval == QLA_SUCCESS)
4887 return rval;
4888
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004889 return qla24xx_load_risc_flash(vha, srisc_addr,
4890 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004891}
4892
4893int
4894qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4895{
4896 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004897 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004898
Andrew Vasqueze337d902009-04-06 22:33:49 -07004899 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004900 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07004901
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004902 /*
4903 * FW Load priority:
4904 * 1) Firmware residing in flash.
4905 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004906 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004907 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004908 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004909 if (rval == QLA_SUCCESS)
4910 return rval;
4911
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004912try_blob_fw:
4913 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4914 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4915 return rval;
4916
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004917 ql_log(ql_log_info, vha, 0x0099,
4918 "Attempting to fallback to golden firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004919 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4920 if (rval != QLA_SUCCESS)
4921 return rval;
4922
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004923 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004924 ha->flags.running_gold_fw = 1;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004925 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004926}
4927
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004928void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004929qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004930{
4931 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004932 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004933
Andrew Vasquez85880802009-12-15 21:29:46 -08004934 if (ha->flags.pci_channel_io_perm_failure)
4935 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07004936 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004937 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004938 if (!ha->fw_major_version)
4939 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004940
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004941 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004942 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07004943 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004944 ha->isp_ops->reset_chip(vha);
4945 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004946 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004947 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004948 continue;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004949 ql_log(ql_log_info, vha, 0x8015,
4950 "Attempting retry of stop-firmware command.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004951 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004952 }
4953}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004954
4955int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004956qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004957{
4958 int rval = QLA_SUCCESS;
4959 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004960 struct qla_hw_data *ha = vha->hw;
4961 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004962 struct req_que *req;
4963 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004964
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004965 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004966 return -EINVAL;
4967
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004968 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07004969 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004970 req = ha->req_q_map[0];
4971 else
4972 req = vha->req;
4973 rsp = req->rsp;
4974
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004975 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004976 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004977 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004978 }
4979
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004980 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004981
4982 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004983 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004984 if (mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004985 ql_dbg(ql_dbg_init, vha, 0x0103,
4986 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
4987 "mb[6]=%x mb[7]=%x.\n",
4988 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004989 return (QLA_FUNCTION_FAILED);
4990 }
4991
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004992 atomic_set(&vha->loop_down_timer, 0);
4993 atomic_set(&vha->loop_state, LOOP_UP);
4994 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4995 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4996 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004997
4998 return rval;
4999}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005000
5001/* 84XX Support **************************************************************/
5002
5003static LIST_HEAD(qla_cs84xx_list);
5004static DEFINE_MUTEX(qla_cs84xx_mutex);
5005
5006static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005007qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005008{
5009 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005010 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005011
5012 mutex_lock(&qla_cs84xx_mutex);
5013
5014 /* Find any shared 84xx chip. */
5015 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
5016 if (cs84xx->bus == ha->pdev->bus) {
5017 kref_get(&cs84xx->kref);
5018 goto done;
5019 }
5020 }
5021
5022 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
5023 if (!cs84xx)
5024 goto done;
5025
5026 kref_init(&cs84xx->kref);
5027 spin_lock_init(&cs84xx->access_lock);
5028 mutex_init(&cs84xx->fw_update_mutex);
5029 cs84xx->bus = ha->pdev->bus;
5030
5031 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
5032done:
5033 mutex_unlock(&qla_cs84xx_mutex);
5034 return cs84xx;
5035}
5036
5037static void
5038__qla84xx_chip_release(struct kref *kref)
5039{
5040 struct qla_chip_state_84xx *cs84xx =
5041 container_of(kref, struct qla_chip_state_84xx, kref);
5042
5043 mutex_lock(&qla_cs84xx_mutex);
5044 list_del(&cs84xx->list);
5045 mutex_unlock(&qla_cs84xx_mutex);
5046 kfree(cs84xx);
5047}
5048
5049void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005050qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005051{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005052 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005053 if (ha->cs84xx)
5054 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
5055}
5056
5057static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005058qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005059{
5060 int rval;
5061 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005062 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005063
5064 mutex_lock(&ha->cs84xx->fw_update_mutex);
5065
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005066 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005067
5068 mutex_unlock(&ha->cs84xx->fw_update_mutex);
5069
5070 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
5071 QLA_SUCCESS;
5072}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005073
5074/* 81XX Support **************************************************************/
5075
5076int
5077qla81xx_nvram_config(scsi_qla_host_t *vha)
5078{
5079 int rval;
5080 struct init_cb_81xx *icb;
5081 struct nvram_81xx *nv;
5082 uint32_t *dptr;
5083 uint8_t *dptr1, *dptr2;
5084 uint32_t chksum;
5085 uint16_t cnt;
5086 struct qla_hw_data *ha = vha->hw;
5087
5088 rval = QLA_SUCCESS;
5089 icb = (struct init_cb_81xx *)ha->init_cb;
5090 nv = ha->nvram;
5091
5092 /* Determine NVRAM starting address. */
5093 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005094 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005095
5096 /* Get VPD data into cache */
5097 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005098 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
5099 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005100
5101 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005102 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005103 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005104 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005105 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
5106 chksum += le32_to_cpu(*dptr++);
5107
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005108 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
5109 "Contents of NVRAM:\n");
5110 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
5111 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005112
5113 /* Bad NVRAM data, set defaults parameters. */
5114 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5115 || nv->id[3] != ' ' ||
5116 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
5117 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005118 ql_log(ql_log_info, vha, 0x0073,
5119 "Inconisistent NVRAM detected: checksum=0x%x id=%c "
5120 "version=0x%x.\n", chksum, nv->id[0],
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005121 le16_to_cpu(nv->nvram_version));
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005122 ql_log(ql_log_info, vha, 0x0074,
5123 "Falling back to functioning (yet invalid -- WWPN) "
5124 "defaults.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005125
5126 /*
5127 * Set default initialization control block.
5128 */
5129 memset(nv, 0, ha->nvram_size);
5130 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
5131 nv->version = __constant_cpu_to_le16(ICB_VERSION);
5132 nv->frame_payload_size = __constant_cpu_to_le16(2048);
5133 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5134 nv->exchange_count = __constant_cpu_to_le16(0);
5135 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005136 nv->port_name[1] = 0x00 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005137 nv->port_name[2] = 0x00;
5138 nv->port_name[3] = 0xe0;
5139 nv->port_name[4] = 0x8b;
5140 nv->port_name[5] = 0x1c;
5141 nv->port_name[6] = 0x55;
5142 nv->port_name[7] = 0x86;
5143 nv->node_name[0] = 0x20;
5144 nv->node_name[1] = 0x00;
5145 nv->node_name[2] = 0x00;
5146 nv->node_name[3] = 0xe0;
5147 nv->node_name[4] = 0x8b;
5148 nv->node_name[5] = 0x1c;
5149 nv->node_name[6] = 0x55;
5150 nv->node_name[7] = 0x86;
5151 nv->login_retry_count = __constant_cpu_to_le16(8);
5152 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
5153 nv->login_timeout = __constant_cpu_to_le16(0);
5154 nv->firmware_options_1 =
5155 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5156 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
5157 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
5158 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
5159 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
5160 nv->efi_parameters = __constant_cpu_to_le32(0);
5161 nv->reset_delay = 5;
5162 nv->max_luns_per_target = __constant_cpu_to_le16(128);
5163 nv->port_down_retry_count = __constant_cpu_to_le16(30);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005164 nv->link_down_timeout = __constant_cpu_to_le16(180);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07005165 nv->enode_mac[0] = 0x00;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005166 nv->enode_mac[1] = 0xC0;
5167 nv->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005168 nv->enode_mac[3] = 0x04;
5169 nv->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005170 nv->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005171
5172 rval = 1;
5173 }
5174
5175 /* Reset Initialization control block */
Andrew Vasquez773120e2011-05-10 11:30:14 -07005176 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005177
5178 /* Copy 1st segment. */
5179 dptr1 = (uint8_t *)icb;
5180 dptr2 = (uint8_t *)&nv->version;
5181 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5182 while (cnt--)
5183 *dptr1++ = *dptr2++;
5184
5185 icb->login_retry_count = nv->login_retry_count;
5186
5187 /* Copy 2nd segment. */
5188 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5189 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5190 cnt = (uint8_t *)&icb->reserved_5 -
5191 (uint8_t *)&icb->interrupt_delay_timer;
5192 while (cnt--)
5193 *dptr1++ = *dptr2++;
5194
5195 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
5196 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5197 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
Andrew Vasquez69e5f1e2012-02-09 11:15:35 -08005198 icb->enode_mac[0] = 0x00;
5199 icb->enode_mac[1] = 0xC0;
5200 icb->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005201 icb->enode_mac[3] = 0x04;
5202 icb->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005203 icb->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005204 }
5205
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07005206 /* Use extended-initialization control block. */
5207 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
5208
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005209 /*
5210 * Setup driver NVRAM options.
5211 */
5212 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07005213 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005214
5215 /* Use alternate WWN? */
5216 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
5217 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5218 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5219 }
5220
5221 /* Prepare nodename */
5222 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
5223 /*
5224 * Firmware will apply the following mask if the nodename was
5225 * not provided.
5226 */
5227 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5228 icb->node_name[0] &= 0xF0;
5229 }
5230
5231 /* Set host adapter parameters. */
5232 ha->flags.disable_risc_code_load = 0;
5233 ha->flags.enable_lip_reset = 0;
5234 ha->flags.enable_lip_full_login =
5235 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5236 ha->flags.enable_target_reset =
5237 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
5238 ha->flags.enable_led_scheme = 0;
5239 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
5240
5241 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5242 (BIT_6 | BIT_5 | BIT_4)) >> 4;
5243
5244 /* save HBA serial number */
5245 ha->serial0 = icb->port_name[5];
5246 ha->serial1 = icb->port_name[6];
5247 ha->serial2 = icb->port_name[7];
5248 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5249 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5250
5251 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5252
5253 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5254
5255 /* Set minimum login_timeout to 4 seconds. */
5256 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5257 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5258 if (le16_to_cpu(nv->login_timeout) < 4)
5259 nv->login_timeout = __constant_cpu_to_le16(4);
5260 ha->login_timeout = le16_to_cpu(nv->login_timeout);
5261 icb->login_timeout = nv->login_timeout;
5262
5263 /* Set minimum RATOV to 100 tenths of a second. */
5264 ha->r_a_tov = 100;
5265
5266 ha->loop_reset_delay = nv->reset_delay;
5267
5268 /* Link Down Timeout = 0:
5269 *
5270 * When Port Down timer expires we will start returning
5271 * I/O's to OS with "DID_NO_CONNECT".
5272 *
5273 * Link Down Timeout != 0:
5274 *
5275 * The driver waits for the link to come up after link down
5276 * before returning I/Os to OS with "DID_NO_CONNECT".
5277 */
5278 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5279 ha->loop_down_abort_time =
5280 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5281 } else {
5282 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5283 ha->loop_down_abort_time =
5284 (LOOP_DOWN_TIME - ha->link_down_timeout);
5285 }
5286
5287 /* Need enough time to try and get the port back. */
5288 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5289 if (qlport_down_retry)
5290 ha->port_down_retry_count = qlport_down_retry;
5291
5292 /* Set login_retry_count */
5293 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5294 if (ha->port_down_retry_count ==
5295 le16_to_cpu(nv->port_down_retry_count) &&
5296 ha->port_down_retry_count > 3)
5297 ha->login_retry_count = ha->port_down_retry_count;
5298 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5299 ha->login_retry_count = ha->port_down_retry_count;
5300 if (ql2xloginretrycount)
5301 ha->login_retry_count = ql2xloginretrycount;
5302
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005303 /* if not running MSI-X we need handshaking on interrupts */
5304 if (!vha->hw->flags.msix_enabled && IS_QLA83XX(ha))
5305 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22);
5306
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005307 /* Enable ZIO. */
5308 if (!vha->flags.init_done) {
5309 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5310 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5311 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5312 le16_to_cpu(icb->interrupt_delay_timer): 2;
5313 }
5314 icb->firmware_options_2 &= __constant_cpu_to_le32(
5315 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
5316 vha->flags.process_response_queue = 0;
5317 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5318 ha->zio_mode = QLA_ZIO_MODE_6;
5319
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005320 ql_log(ql_log_info, vha, 0x0075,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005321 "ZIO mode %d enabled; timer delay (%d us).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005322 ha->zio_mode,
5323 ha->zio_timer * 100);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005324
5325 icb->firmware_options_2 |= cpu_to_le32(
5326 (uint32_t)ha->zio_mode);
5327 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
5328 vha->flags.process_response_queue = 1;
5329 }
5330
5331 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005332 ql_log(ql_log_warn, vha, 0x0076,
5333 "NVRAM configuration failed.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005334 }
5335 return (rval);
5336}
5337
Giridhar Malavalia9083012010-04-12 17:59:55 -07005338int
5339qla82xx_restart_isp(scsi_qla_host_t *vha)
5340{
5341 int status, rval;
5342 uint32_t wait_time;
5343 struct qla_hw_data *ha = vha->hw;
5344 struct req_que *req = ha->req_q_map[0];
5345 struct rsp_que *rsp = ha->rsp_q_map[0];
5346 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07005347 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005348
5349 status = qla2x00_init_rings(vha);
5350 if (!status) {
5351 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5352 ha->flags.chip_reset_done = 1;
5353
5354 status = qla2x00_fw_ready(vha);
5355 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005356 ql_log(ql_log_info, vha, 0x803c,
5357 "Start configure loop, status =%d.\n", status);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005358
5359 /* Issue a marker after FW becomes ready. */
5360 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
5361
5362 vha->flags.online = 1;
5363 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5364 wait_time = 256;
5365 do {
5366 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5367 qla2x00_configure_loop(vha);
5368 wait_time--;
5369 } while (!atomic_read(&vha->loop_down_timer) &&
5370 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
5371 wait_time &&
5372 (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
5373 }
5374
5375 /* if no cable then assume it's good */
5376 if ((vha->device_flags & DFLG_NO_CABLE))
5377 status = 0;
5378
Chad Dupuiscfb09192011-11-18 09:03:07 -08005379 ql_log(ql_log_info, vha, 0x8000,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005380 "Configure loop done, status = 0x%x.\n", status);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005381 }
5382
5383 if (!status) {
5384 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5385
5386 if (!atomic_read(&vha->loop_down_timer)) {
5387 /*
5388 * Issue marker command only when we are going
5389 * to start the I/O .
5390 */
5391 vha->marker_needed = 1;
5392 }
5393
5394 vha->flags.online = 1;
5395
5396 ha->isp_ops->enable_intrs(ha);
5397
5398 ha->isp_abort_cnt = 0;
5399 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5400
Saurav Kashyap53296782011-05-10 11:30:06 -07005401 /* Update the firmware version */
Giridhar Malavali31731672011-08-16 11:31:54 -07005402 status = qla82xx_check_md_needed(vha);
Saurav Kashyap53296782011-05-10 11:30:06 -07005403
Giridhar Malavalia9083012010-04-12 17:59:55 -07005404 if (ha->fce) {
5405 ha->flags.fce_enabled = 1;
5406 memset(ha->fce, 0,
5407 fce_calc_size(ha->fce_bufs));
5408 rval = qla2x00_enable_fce_trace(vha,
5409 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5410 &ha->fce_bufs);
5411 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08005412 ql_log(ql_log_warn, vha, 0x8001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005413 "Unable to reinitialize FCE (%d).\n",
5414 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005415 ha->flags.fce_enabled = 0;
5416 }
5417 }
5418
5419 if (ha->eft) {
5420 memset(ha->eft, 0, EFT_SIZE);
5421 rval = qla2x00_enable_eft_trace(vha,
5422 ha->eft_dma, EFT_NUM_BUFFERS);
5423 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08005424 ql_log(ql_log_warn, vha, 0x8010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005425 "Unable to reinitialize EFT (%d).\n",
5426 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005427 }
5428 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005429 }
5430
5431 if (!status) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08005432 ql_dbg(ql_dbg_taskm, vha, 0x8011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005433 "qla82xx_restart_isp succeeded.\n");
Arun Easifeafb7b2010-09-03 14:57:00 -07005434
5435 spin_lock_irqsave(&ha->vport_slock, flags);
5436 list_for_each_entry(vp, &ha->vp_list, list) {
5437 if (vp->vp_idx) {
5438 atomic_inc(&vp->vref_count);
5439 spin_unlock_irqrestore(&ha->vport_slock, flags);
5440
Giridhar Malavalia9083012010-04-12 17:59:55 -07005441 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07005442
5443 spin_lock_irqsave(&ha->vport_slock, flags);
5444 atomic_dec(&vp->vref_count);
5445 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005446 }
Arun Easifeafb7b2010-09-03 14:57:00 -07005447 spin_unlock_irqrestore(&ha->vport_slock, flags);
5448
Giridhar Malavalia9083012010-04-12 17:59:55 -07005449 } else {
Chad Dupuiscfb09192011-11-18 09:03:07 -08005450 ql_log(ql_log_warn, vha, 0x8016,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005451 "qla82xx_restart_isp **** FAILED ****.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005452 }
5453
5454 return status;
5455}
5456
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005457void
Andrew Vasquezae97c912010-02-18 10:07:28 -08005458qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005459{
Andrew Vasquezae97c912010-02-18 10:07:28 -08005460 struct qla_hw_data *ha = vha->hw;
5461
5462 if (!ql2xetsenable)
5463 return;
5464
5465 /* Enable ETS Burst. */
5466 memset(ha->fw_options, 0, sizeof(ha->fw_options));
5467 ha->fw_options[2] |= BIT_9;
5468 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005469}
Sarang Radke09ff7012010-03-19 17:03:59 -07005470
5471/*
5472 * qla24xx_get_fcp_prio
5473 * Gets the fcp cmd priority value for the logged in port.
5474 * Looks for a match of the port descriptors within
5475 * each of the fcp prio config entries. If a match is found,
5476 * the tag (priority) value is returned.
5477 *
5478 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005479 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07005480 * fcport = port structure pointer.
5481 *
5482 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07005483 * non-zero (if found)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005484 * -1 (if not found)
Sarang Radke09ff7012010-03-19 17:03:59 -07005485 *
5486 * Context:
5487 * Kernel context
5488 */
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005489static int
Sarang Radke09ff7012010-03-19 17:03:59 -07005490qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
5491{
5492 int i, entries;
5493 uint8_t pid_match, wwn_match;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005494 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07005495 uint32_t pid1, pid2;
5496 uint64_t wwn1, wwn2;
5497 struct qla_fcp_prio_entry *pri_entry;
5498 struct qla_hw_data *ha = vha->hw;
5499
5500 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005501 return -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07005502
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005503 priority = -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07005504 entries = ha->fcp_prio_cfg->num_entries;
5505 pri_entry = &ha->fcp_prio_cfg->entry[0];
5506
5507 for (i = 0; i < entries; i++) {
5508 pid_match = wwn_match = 0;
5509
5510 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
5511 pri_entry++;
5512 continue;
5513 }
5514
5515 /* check source pid for a match */
5516 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
5517 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
5518 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
5519 if (pid1 == INVALID_PORT_ID)
5520 pid_match++;
5521 else if (pid1 == pid2)
5522 pid_match++;
5523 }
5524
5525 /* check destination pid for a match */
5526 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
5527 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
5528 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
5529 if (pid1 == INVALID_PORT_ID)
5530 pid_match++;
5531 else if (pid1 == pid2)
5532 pid_match++;
5533 }
5534
5535 /* check source WWN for a match */
5536 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
5537 wwn1 = wwn_to_u64(vha->port_name);
5538 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
5539 if (wwn2 == (uint64_t)-1)
5540 wwn_match++;
5541 else if (wwn1 == wwn2)
5542 wwn_match++;
5543 }
5544
5545 /* check destination WWN for a match */
5546 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
5547 wwn1 = wwn_to_u64(fcport->port_name);
5548 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
5549 if (wwn2 == (uint64_t)-1)
5550 wwn_match++;
5551 else if (wwn1 == wwn2)
5552 wwn_match++;
5553 }
5554
5555 if (pid_match == 2 || wwn_match == 2) {
5556 /* Found a matching entry */
5557 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
5558 priority = pri_entry->tag;
5559 break;
5560 }
5561
5562 pri_entry++;
5563 }
5564
5565 return priority;
5566}
5567
5568/*
5569 * qla24xx_update_fcport_fcp_prio
5570 * Activates fcp priority for the logged in fc port
5571 *
5572 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005573 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07005574 * fcp = port structure pointer.
5575 *
5576 * Return:
5577 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5578 *
5579 * Context:
5580 * Kernel context.
5581 */
5582int
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005583qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
Sarang Radke09ff7012010-03-19 17:03:59 -07005584{
5585 int ret;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005586 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07005587 uint16_t mb[5];
5588
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005589 if (fcport->port_type != FCT_TARGET ||
5590 fcport->loop_id == FC_NO_LOOP_ID)
Sarang Radke09ff7012010-03-19 17:03:59 -07005591 return QLA_FUNCTION_FAILED;
5592
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005593 priority = qla24xx_get_fcp_prio(vha, fcport);
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005594 if (priority < 0)
5595 return QLA_FUNCTION_FAILED;
5596
Saurav Kashyapa00f6292011-11-18 09:03:19 -08005597 if (IS_QLA82XX(vha->hw)) {
5598 fcport->fcp_prio = priority & 0xf;
5599 return QLA_SUCCESS;
5600 }
5601
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005602 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
Chad Dupuiscfb09192011-11-18 09:03:07 -08005603 if (ret == QLA_SUCCESS) {
5604 if (fcport->fcp_prio != priority)
5605 ql_dbg(ql_dbg_user, vha, 0x709e,
5606 "Updated FCP_CMND priority - value=%d loop_id=%d "
5607 "port_id=%02x%02x%02x.\n", priority,
5608 fcport->loop_id, fcport->d_id.b.domain,
5609 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Saurav Kashyapa00f6292011-11-18 09:03:19 -08005610 fcport->fcp_prio = priority & 0xf;
Chad Dupuiscfb09192011-11-18 09:03:07 -08005611 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005612 ql_dbg(ql_dbg_user, vha, 0x704f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08005613 "Unable to update FCP_CMND priority - ret=0x%x for "
5614 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
5615 fcport->d_id.b.domain, fcport->d_id.b.area,
5616 fcport->d_id.b.al_pa);
Sarang Radke09ff7012010-03-19 17:03:59 -07005617 return ret;
5618}
5619
5620/*
5621 * qla24xx_update_all_fcp_prio
5622 * Activates fcp priority for all the logged in ports
5623 *
5624 * Input:
5625 * ha = adapter block pointer.
5626 *
5627 * Return:
5628 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5629 *
5630 * Context:
5631 * Kernel context.
5632 */
5633int
5634qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
5635{
5636 int ret;
5637 fc_port_t *fcport;
5638
5639 ret = QLA_FUNCTION_FAILED;
5640 /* We need to set priority for all logged in ports */
5641 list_for_each_entry(fcport, &vha->vp_fcports, list)
5642 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
5643
5644 return ret;
5645}