blob: 33a23eb1cf51bf1b315b70c8881c1f0f07f0c25b [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 *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
33 uint16_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35static int qla2x00_restart_isp(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Harihara Kadayam4d4df192008-04-03 13:13:26 -070037static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
38static int qla84xx_init_chip(scsi_qla_host_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080039static int qla25xx_init_queues(struct qla_hw_data *);
Harihara Kadayam4d4df192008-04-03 13:13:26 -070040
Andrew Vasquezac280b62009-08-20 11:06:05 -070041/* SRB Extensions ---------------------------------------------------------- */
42
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080043void
44qla2x00_sp_timeout(unsigned long __data)
Andrew Vasquezac280b62009-08-20 11:06:05 -070045{
46 srb_t *sp = (srb_t *)__data;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070047 struct srb_iocb *iocb;
Andrew Vasquezac280b62009-08-20 11:06:05 -070048 fc_port_t *fcport = sp->fcport;
49 struct qla_hw_data *ha = fcport->vha->hw;
50 struct req_que *req;
51 unsigned long flags;
52
53 spin_lock_irqsave(&ha->hardware_lock, flags);
54 req = ha->req_q_map[0];
55 req->outstanding_cmds[sp->handle] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080056 iocb = &sp->u.iocb_cmd;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070057 iocb->timeout(sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080058 sp->free(fcport->vha, sp);
Andrew Vasquez6ac52602010-05-28 15:08:19 -070059 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -070060}
61
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080062void
63qla2x00_sp_free(void *data, void *ptr)
Andrew Vasquezac280b62009-08-20 11:06:05 -070064{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080065 srb_t *sp = (srb_t *)ptr;
66 struct srb_iocb *iocb = &sp->u.iocb_cmd;
67 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquezac280b62009-08-20 11:06:05 -070068
Chad Dupuis4d97cc52010-10-15 11:27:41 -070069 del_timer(&iocb->timer);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080070 mempool_free(sp, vha->hw->srb_mempool);
Arun Easifeafb7b2010-09-03 14:57:00 -070071
72 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquezac280b62009-08-20 11:06:05 -070073}
74
Andrew Vasquezac280b62009-08-20 11:06:05 -070075/* Asynchronous Login/Logout Routines -------------------------------------- */
76
Andrew Vasquez5b914902010-05-28 15:08:30 -070077static inline unsigned long
78qla2x00_get_async_timeout(struct scsi_qla_host *vha)
79{
80 unsigned long tmo;
81 struct qla_hw_data *ha = vha->hw;
82
83 /* Firmware should use switch negotiated r_a_tov for timeout. */
84 tmo = ha->r_a_tov / 10 * 2;
85 if (!IS_FWI2_CAPABLE(ha)) {
86 /*
87 * Except for earlier ISPs where the timeout is seeded from the
88 * initialization control block.
89 */
90 tmo = ha->login_timeout;
91 }
92 return tmo;
93}
Andrew Vasquezac280b62009-08-20 11:06:05 -070094
95static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080096qla2x00_async_iocb_timeout(void *data)
Andrew Vasquezac280b62009-08-20 11:06:05 -070097{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080098 srb_t *sp = (srb_t *)data;
Andrew Vasquezac280b62009-08-20 11:06:05 -070099 fc_port_t *fcport = sp->fcport;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700100
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700101 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800102 "Async-%s timeout - hdl=%x portid=%02x%02x%02x.\n",
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800103 sp->name, sp->handle, fcport->d_id.b.domain, fcport->d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700104 fcport->d_id.b.al_pa);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700105
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700106 fcport->flags &= ~FCF_ASYNC_SENT;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800107 if (sp->type == SRB_LOGIN_CMD) {
108 struct srb_iocb *lio = &sp->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700109 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700110 /* Retry as needed. */
111 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
112 lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
113 QLA_LOGIO_LOGIN_RETRIED : 0;
114 qla2x00_post_async_login_done_work(fcport->vha, fcport,
115 lio->u.logio.data);
116 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700117}
118
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700119static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800120qla2x00_async_login_sp_done(void *data, void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700121{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800122 srb_t *sp = (srb_t *)ptr;
123 struct srb_iocb *lio = &sp->u.iocb_cmd;
124 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700125
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800126 if (!test_bit(UNLOADING, &vha->dpc_flags))
127 qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
128 lio->u.logio.data);
129 sp->free(sp->fcport->vha, sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700130}
131
Andrew Vasquezac280b62009-08-20 11:06:05 -0700132int
133qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
134 uint16_t *data)
135{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700136 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700137 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700138 int rval;
139
140 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800141 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700142 if (!sp)
143 goto done;
144
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800145 sp->type = SRB_LOGIN_CMD;
146 sp->name = "login";
147 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
148
149 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700150 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800151 sp->done = qla2x00_async_login_sp_done;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700152 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700153 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700154 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700155 rval = qla2x00_start_sp(sp);
156 if (rval != QLA_SUCCESS)
157 goto done_free_sp;
158
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700159 ql_dbg(ql_dbg_disc, vha, 0x2072,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800160 "Async-login - hdl=%x, loopid=%x portid=%02x%02x%02x "
161 "retries=%d.\n", sp->handle, fcport->loop_id,
162 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
163 fcport->login_retry);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700164 return rval;
165
166done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800167 sp->free(fcport->vha, sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700168done:
169 return rval;
170}
171
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700172static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800173qla2x00_async_logout_sp_done(void *data, void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700174{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800175 srb_t *sp = (srb_t *)ptr;
176 struct srb_iocb *lio = &sp->u.iocb_cmd;
177 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700178
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800179 if (!test_bit(UNLOADING, &vha->dpc_flags))
180 qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
181 lio->u.logio.data);
182 sp->free(sp->fcport->vha, sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700183}
184
Andrew Vasquezac280b62009-08-20 11:06:05 -0700185int
186qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
187{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700188 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700189 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700190 int rval;
191
192 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800193 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700194 if (!sp)
195 goto done;
196
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800197 sp->type = SRB_LOGOUT_CMD;
198 sp->name = "logout";
199 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
200
201 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700202 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800203 sp->done = qla2x00_async_logout_sp_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700204 rval = qla2x00_start_sp(sp);
205 if (rval != QLA_SUCCESS)
206 goto done_free_sp;
207
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700208 ql_dbg(ql_dbg_disc, vha, 0x2070,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800209 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
210 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
211 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700212 return rval;
213
214done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800215 sp->free(fcport->vha, sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700216done:
217 return rval;
218}
219
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700220static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800221qla2x00_async_adisc_sp_done(void *data, void *ptr, int res)
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700222{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800223 srb_t *sp = (srb_t *)ptr;
224 struct srb_iocb *lio = &sp->u.iocb_cmd;
225 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700226
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800227 if (!test_bit(UNLOADING, &vha->dpc_flags))
228 qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
229 lio->u.logio.data);
230 sp->free(sp->fcport->vha, sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700231}
232
233int
234qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
235 uint16_t *data)
236{
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700237 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700238 struct srb_iocb *lio;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700239 int rval;
240
241 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800242 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700243 if (!sp)
244 goto done;
245
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800246 sp->type = SRB_ADISC_CMD;
247 sp->name = "adisc";
248 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
249
250 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700251 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800252 sp->done = qla2x00_async_adisc_sp_done;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700253 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700254 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700255 rval = qla2x00_start_sp(sp);
256 if (rval != QLA_SUCCESS)
257 goto done_free_sp;
258
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700259 ql_dbg(ql_dbg_disc, vha, 0x206f,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800260 "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n",
261 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
262 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700263 return rval;
264
265done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800266 sp->free(fcport->vha, sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700267done:
268 return rval;
269}
270
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700271static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800272qla2x00_async_tm_cmd_done(void *data, void *ptr, int res)
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700273{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800274 srb_t *sp = (srb_t *)ptr;
275 struct srb_iocb *iocb = &sp->u.iocb_cmd;
276 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
277 uint32_t flags;
278 uint16_t lun;
279 int rval;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700280
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800281 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
282 flags = iocb->u.tmf.flags;
283 lun = (uint16_t)iocb->u.tmf.lun;
284
285 /* Issue Marker IOCB */
286 rval = qla2x00_marker(vha, vha->hw->req_q_map[0],
287 vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
288 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
289
290 if ((rval != QLA_SUCCESS) || iocb->u.tmf.data) {
291 ql_dbg(ql_dbg_taskm, vha, 0x8030,
292 "TM IOCB failed (%x).\n", rval);
293 }
294 }
295 sp->free(sp->fcport->vha, sp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700296}
297
298int
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800299qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t tm_flags, uint32_t lun,
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700300 uint32_t tag)
301{
302 struct scsi_qla_host *vha = fcport->vha;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700303 srb_t *sp;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700304 struct srb_iocb *tcf;
305 int rval;
306
307 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800308 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700309 if (!sp)
310 goto done;
311
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800312 sp->type = SRB_TM_CMD;
313 sp->name = "tmf";
314 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
315
316 tcf = &sp->u.iocb_cmd;
317 tcf->u.tmf.flags = tm_flags;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700318 tcf->u.tmf.lun = lun;
319 tcf->u.tmf.data = tag;
320 tcf->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800321 sp->done = qla2x00_async_tm_cmd_done;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700322
323 rval = qla2x00_start_sp(sp);
324 if (rval != QLA_SUCCESS)
325 goto done_free_sp;
326
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700327 ql_dbg(ql_dbg_taskm, vha, 0x802f,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800328 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
329 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
330 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700331 return rval;
332
333done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800334 sp->free(fcport->vha, sp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700335done:
336 return rval;
337}
338
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700339void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700340qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
341 uint16_t *data)
342{
343 int rval;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700344
345 switch (data[0]) {
346 case MBS_COMMAND_COMPLETE:
Andrew Vasqueza4f92a32011-03-30 11:46:31 -0700347 /*
348 * Driver must validate login state - If PRLI not complete,
349 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
350 * requests.
351 */
352 rval = qla2x00_get_port_database(vha, fcport, 0);
Arun Easi0eba25d2012-02-09 11:15:58 -0800353 if (rval == QLA_NOT_LOGGED_IN) {
354 fcport->flags &= ~FCF_ASYNC_SENT;
355 fcport->flags |= FCF_LOGIN_NEEDED;
356 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
357 break;
358 }
359
Andrew Vasqueza4f92a32011-03-30 11:46:31 -0700360 if (rval != QLA_SUCCESS) {
361 qla2x00_post_async_logout_work(vha, fcport, NULL);
362 qla2x00_post_async_login_work(vha, fcport, NULL);
363 break;
364 }
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700365 if (fcport->flags & FCF_FCP2_DEVICE) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700366 qla2x00_post_async_adisc_work(vha, fcport, data);
367 break;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700368 }
369 qla2x00_update_fcport(vha, fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700370 break;
371 case MBS_COMMAND_ERROR:
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700372 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700373 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
374 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
375 else
Andrew Vasquez80d79442011-03-30 11:46:17 -0700376 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700377 break;
378 case MBS_PORT_ID_USED:
379 fcport->loop_id = data[1];
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700380 qla2x00_post_async_logout_work(vha, fcport, NULL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700381 qla2x00_post_async_login_work(vha, fcport, NULL);
382 break;
383 case MBS_LOOP_ID_USED:
384 fcport->loop_id++;
385 rval = qla2x00_find_new_loop_id(vha, fcport);
386 if (rval != QLA_SUCCESS) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700387 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquez80d79442011-03-30 11:46:17 -0700388 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700389 break;
390 }
391 qla2x00_post_async_login_work(vha, fcport, NULL);
392 break;
393 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700394 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700395}
396
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700397void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700398qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
399 uint16_t *data)
400{
401 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700402 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700403}
404
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700405void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700406qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
407 uint16_t *data)
408{
409 if (data[0] == MBS_COMMAND_COMPLETE) {
410 qla2x00_update_fcport(vha, fcport);
411
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700412 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700413 }
414
415 /* Retry login. */
416 fcport->flags &= ~FCF_ASYNC_SENT;
417 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
418 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
419 else
Andrew Vasquez80d79442011-03-30 11:46:17 -0700420 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700421
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700422 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700423}
424
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425/****************************************************************************/
426/* QLogic ISP2x00 Hardware Support Functions. */
427/****************************************************************************/
428
429/*
430* qla2x00_initialize_adapter
431* Initialize board.
432*
433* Input:
434* ha = adapter block pointer.
435*
436* Returns:
437* 0 = success
438*/
439int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800440qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441{
442 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800443 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800444 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700445
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800447 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700448 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800449 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -0800450 ha->flags.pci_channel_io_perm_failure = 0;
451 ha->flags.eeh_busy = 0;
Andrew Vasquez794a5692010-12-21 16:00:21 -0800452 ha->flags.thermal_supported = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800453 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
454 atomic_set(&vha->loop_state, LOOP_DOWN);
455 vha->device_flags = DFLG_NO_CABLE;
456 vha->dpc_flags = 0;
457 vha->flags.management_server_logged_in = 0;
458 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 ha->isp_abort_cnt = 0;
460 ha->beacon_blink_led = 0;
461
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800462 set_bit(0, ha->req_qid_map);
463 set_bit(0, ha->rsp_qid_map);
464
Chad Dupuiscfb09192011-11-18 09:03:07 -0800465 ql_dbg(ql_dbg_init, vha, 0x0040,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700466 "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800467 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700469 ql_log(ql_log_warn, vha, 0x0044,
470 "Unable to configure PCI space.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 return (rval);
472 }
473
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800474 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800476 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700477 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700478 ql_log(ql_log_fatal, vha, 0x004f,
479 "Unable to validate FLASH data.\n");
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700480 return (rval);
481 }
482
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800483 ha->isp_ops->get_flash_version(vha, req->ring);
Chad Dupuiscfb09192011-11-18 09:03:07 -0800484 ql_dbg(ql_dbg_init, vha, 0x0061,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700485 "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700486
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800487 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700489 if (ha->flags.disable_serdes) {
490 /* Mask HBA via NVRAM settings? */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700491 ql_log(ql_log_info, vha, 0x0077,
492 "Masking HBA WWPN "
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700493 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800494 vha->port_name[0], vha->port_name[1],
495 vha->port_name[2], vha->port_name[3],
496 vha->port_name[4], vha->port_name[5],
497 vha->port_name[6], vha->port_name[7]);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700498 return QLA_FUNCTION_FAILED;
499 }
500
Chad Dupuiscfb09192011-11-18 09:03:07 -0800501 ql_dbg(ql_dbg_init, vha, 0x0078,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700502 "Verifying loaded RISC code...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800504 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
505 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800506 if (rval)
507 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800508 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800509 if (rval)
510 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700512
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700513 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800514 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700515 if (!ha->cs84xx) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700516 ql_log(ql_log_warn, vha, 0x00d0,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700517 "Unable to configure ISP84XX.\n");
518 return QLA_FUNCTION_FAILED;
519 }
520 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800521 rval = qla2x00_init_rings(vha);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700522 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800524 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700525 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800526 rval = qla84xx_init_chip(vha);
527 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700528 ql_log(ql_log_warn, vha, 0x00d4,
529 "Unable to initialize ISP84XX.\n");
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800530 qla84xx_put_chip(vha);
531 }
532 }
533
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +0500534 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
535 qla24xx_read_fcp_prio_cfg(vha);
Sarang Radke09ff7012010-03-19 17:03:59 -0700536
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 return (rval);
538}
539
540/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700541 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 * @ha: HA context
543 *
544 * Returns 0 on success.
545 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700546int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800547qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700549 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700550 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800551 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700552 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700555 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700558 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
560
Andrew Vasquez737faec2008-10-24 15:13:45 -0700561 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700563 /* Get PCI bus information. */
564 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700565 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700566 spin_unlock_irqrestore(&ha->hardware_lock, flags);
567
568 return QLA_SUCCESS;
569}
570
571/**
572 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
573 * @ha: HA context
574 *
575 * Returns 0 on success.
576 */
577int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800578qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700579{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700580 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700581 unsigned long flags = 0;
582 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800583 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700584 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700585
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700586 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700587 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700588
589 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700590 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700591
592 if (IS_QLA2322(ha) || IS_QLA6322(ha))
593 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700594 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700595
596 /*
597 * If this is a 2300 card and not 2312, reset the
598 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
599 * the 2310 also reports itself as a 2300 so we need to get the
600 * fb revision level -- a 6 indicates it really is a 2300 and
601 * not a 2310.
602 */
603 if (IS_QLA2300(ha)) {
604 spin_lock_irqsave(&ha->hardware_lock, flags);
605
606 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700607 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700608 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700609 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700610 break;
611
612 udelay(10);
613 }
614
615 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700616 WRT_REG_WORD(&reg->ctrl_status, 0x20);
617 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700618
619 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700620 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700621
622 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700623 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700624
625 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700626 WRT_REG_WORD(&reg->ctrl_status, 0x0);
627 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700628
629 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700630 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700631 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700632 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700633 break;
634
635 udelay(10);
636 }
637
638 spin_unlock_irqrestore(&ha->hardware_lock, flags);
639 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700640
641 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
642
Andrew Vasquez737faec2008-10-24 15:13:45 -0700643 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700644
645 /* Get PCI bus information. */
646 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700647 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700648 spin_unlock_irqrestore(&ha->hardware_lock, flags);
649
650 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651}
652
653/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700654 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
655 * @ha: HA context
656 *
657 * Returns 0 on success.
658 */
659int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800660qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700661{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700662 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700663 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800664 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700665 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700666
667 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700668 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700669
670 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700671 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700672 w &= ~PCI_COMMAND_INTX_DISABLE;
673 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
674
675 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
676
677 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700678 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
679 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700680
681 /* PCIe -- adjust Maximum Read Request Size (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700682 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
683 pcie_set_readrq(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700684
Andrew Vasquez737faec2008-10-24 15:13:45 -0700685 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700686
Auke Kok44c10132007-06-08 15:46:36 -0700687 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800688
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700689 /* Get PCI bus information. */
690 spin_lock_irqsave(&ha->hardware_lock, flags);
691 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
692 spin_unlock_irqrestore(&ha->hardware_lock, flags);
693
694 return QLA_SUCCESS;
695}
696
697/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700698 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
699 * @ha: HA context
700 *
701 * Returns 0 on success.
702 */
703int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800704qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700705{
706 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800707 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700708
709 pci_set_master(ha->pdev);
710 pci_try_set_mwi(ha->pdev);
711
712 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
713 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
714 w &= ~PCI_COMMAND_INTX_DISABLE;
715 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
716
717 /* PCIe -- adjust Maximum Read Request Size (2048). */
718 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
719 pcie_set_readrq(ha->pdev, 2048);
720
Andrew Vasquez737faec2008-10-24 15:13:45 -0700721 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700722
723 ha->chip_revision = ha->pdev->revision;
724
725 return QLA_SUCCESS;
726}
727
728/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 * qla2x00_isp_firmware() - Choose firmware image.
730 * @ha: HA context
731 *
732 * Returns 0 on success.
733 */
734static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800735qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736{
737 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700738 uint16_t loop_id, topo, sw_cap;
739 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800740 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
742 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700743 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
745 if (ha->flags.disable_risc_code_load) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700746 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
748 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800749 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700750 if (rval == QLA_SUCCESS) {
751 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800752 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700753 &area, &domain, &topo, &sw_cap);
754 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 }
756
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700757 if (rval)
758 ql_dbg(ql_dbg_init, vha, 0x007a,
759 "**** Load RISC code ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
761 return (rval);
762}
763
764/**
765 * qla2x00_reset_chip() - Reset ISP chip.
766 * @ha: HA context
767 *
768 * Returns 0 on success.
769 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700770void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800771qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772{
773 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800774 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700775 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 uint16_t cmd;
778
Andrew Vasquez85880802009-12-15 21:29:46 -0800779 if (unlikely(pci_channel_offline(ha->pdev)))
780 return;
781
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700782 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783
784 spin_lock_irqsave(&ha->hardware_lock, flags);
785
786 /* Turn off master enable */
787 cmd = 0;
788 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
789 cmd &= ~PCI_COMMAND_MASTER;
790 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
791
792 if (!IS_QLA2100(ha)) {
793 /* Pause RISC. */
794 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
795 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
796 for (cnt = 0; cnt < 30000; cnt++) {
797 if ((RD_REG_WORD(&reg->hccr) &
798 HCCR_RISC_PAUSE) != 0)
799 break;
800 udelay(100);
801 }
802 } else {
803 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
804 udelay(10);
805 }
806
807 /* Select FPM registers. */
808 WRT_REG_WORD(&reg->ctrl_status, 0x20);
809 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
810
811 /* FPM Soft Reset. */
812 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
813 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
814
815 /* Toggle Fpm Reset. */
816 if (!IS_QLA2200(ha)) {
817 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
818 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
819 }
820
821 /* Select frame buffer registers. */
822 WRT_REG_WORD(&reg->ctrl_status, 0x10);
823 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
824
825 /* Reset frame buffer FIFOs. */
826 if (IS_QLA2200(ha)) {
827 WRT_FB_CMD_REG(ha, reg, 0xa000);
828 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
829 } else {
830 WRT_FB_CMD_REG(ha, reg, 0x00fc);
831
832 /* Read back fb_cmd until zero or 3 seconds max */
833 for (cnt = 0; cnt < 3000; cnt++) {
834 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
835 break;
836 udelay(100);
837 }
838 }
839
840 /* Select RISC module registers. */
841 WRT_REG_WORD(&reg->ctrl_status, 0);
842 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
843
844 /* Reset RISC processor. */
845 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
846 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
847
848 /* Release RISC processor. */
849 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
850 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
851 }
852
853 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
854 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
855
856 /* Reset ISP chip. */
857 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
858
859 /* Wait for RISC to recover from reset. */
860 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
861 /*
862 * It is necessary to for a delay here since the card doesn't
863 * respond to PCI reads during a reset. On some architectures
864 * this will result in an MCA.
865 */
866 udelay(20);
867 for (cnt = 30000; cnt; cnt--) {
868 if ((RD_REG_WORD(&reg->ctrl_status) &
869 CSR_ISP_SOFT_RESET) == 0)
870 break;
871 udelay(100);
872 }
873 } else
874 udelay(10);
875
876 /* Reset RISC processor. */
877 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
878
879 WRT_REG_WORD(&reg->semaphore, 0);
880
881 /* Release RISC processor. */
882 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
883 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
884
885 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
886 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700887 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
890 udelay(100);
891 }
892 } else
893 udelay(100);
894
895 /* Turn on master enable */
896 cmd |= PCI_COMMAND_MASTER;
897 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
898
899 /* Disable RISC pause on FPM parity error. */
900 if (!IS_QLA2100(ha)) {
901 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
902 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
903 }
904
905 spin_unlock_irqrestore(&ha->hardware_lock, flags);
906}
907
908/**
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -0700909 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
910 *
911 * Returns 0 on success.
912 */
913int
914qla81xx_reset_mpi(scsi_qla_host_t *vha)
915{
916 uint16_t mb[4] = {0x1010, 0, 1, 0};
917
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800918 if (!IS_QLA81XX(vha->hw))
919 return QLA_SUCCESS;
920
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -0700921 return qla81xx_write_mpi_register(vha, mb);
922}
923
924/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700925 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700926 * @ha: HA context
927 *
928 * Returns 0 on success.
929 */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700930static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800931qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700932{
933 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800934 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700935 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
936 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800937 uint16_t wd;
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -0700938 static int abts_cnt; /* ISP abort retry counts */
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700939
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700940 spin_lock_irqsave(&ha->hardware_lock, flags);
941
942 /* Reset RISC. */
943 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
944 for (cnt = 0; cnt < 30000; cnt++) {
945 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
946 break;
947
948 udelay(10);
949 }
950
951 WRT_REG_DWORD(&reg->ctrl_status,
952 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800953 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700954
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800955 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700956 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700957 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
958 for (cnt = 10000 ; cnt && d2; cnt--) {
959 udelay(5);
960 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
961 barrier();
962 }
963
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800964 /* Wait for soft-reset to complete. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700965 d2 = RD_REG_DWORD(&reg->ctrl_status);
966 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
967 udelay(5);
968 d2 = RD_REG_DWORD(&reg->ctrl_status);
969 barrier();
970 }
971
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -0700972 /* If required, do an MPI FW reset now */
973 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
974 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
975 if (++abts_cnt < 5) {
976 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
977 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
978 } else {
979 /*
980 * We exhausted the ISP abort retries. We have to
981 * set the board offline.
982 */
983 abts_cnt = 0;
984 vha->flags.online = 0;
985 }
986 }
987 }
988
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700989 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
990 RD_REG_DWORD(&reg->hccr);
991
992 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
993 RD_REG_DWORD(&reg->hccr);
994
995 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
996 RD_REG_DWORD(&reg->hccr);
997
998 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
999 for (cnt = 6000000 ; cnt && d2; cnt--) {
1000 udelay(5);
1001 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1002 barrier();
1003 }
1004
1005 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001006
1007 if (IS_NOPOLLING_TYPE(ha))
1008 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001009}
1010
1011/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001012 * qla24xx_reset_chip() - Reset ISP24xx chip.
1013 * @ha: HA context
1014 *
1015 * Returns 0 on success.
1016 */
1017void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001018qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07001019{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001020 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08001021
1022 if (pci_channel_offline(ha->pdev) &&
1023 ha->flags.pci_channel_io_perm_failure) {
1024 return;
1025 }
1026
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001027 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001028
1029 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001030 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001031}
1032
1033/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 * qla2x00_chip_diag() - Test chip for proper operation.
1035 * @ha: HA context
1036 *
1037 * Returns 0 on success.
1038 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001039int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001040qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041{
1042 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001043 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001044 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 unsigned long flags = 0;
1046 uint16_t data;
1047 uint32_t cnt;
1048 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001049 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050
1051 /* Assume a failed state */
1052 rval = QLA_FUNCTION_FAILED;
1053
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001054 ql_dbg(ql_dbg_init, vha, 0x007b,
1055 "Testing device at %lx.\n", (u_long)&reg->flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056
1057 spin_lock_irqsave(&ha->hardware_lock, flags);
1058
1059 /* Reset ISP chip. */
1060 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1061
1062 /*
1063 * We need to have a delay here since the card will not respond while
1064 * in reset causing an MCA on some architectures.
1065 */
1066 udelay(20);
1067 data = qla2x00_debounce_register(&reg->ctrl_status);
1068 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
1069 udelay(5);
1070 data = RD_REG_WORD(&reg->ctrl_status);
1071 barrier();
1072 }
1073
1074 if (!cnt)
1075 goto chip_diag_failed;
1076
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001077 ql_dbg(ql_dbg_init, vha, 0x007c,
1078 "Reset register cleared by chip reset.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
1080 /* Reset RISC processor. */
1081 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1082 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1083
1084 /* Workaround for QLA2312 PCI parity error */
1085 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1086 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
1087 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
1088 udelay(5);
1089 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001090 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 }
1092 } else
1093 udelay(10);
1094
1095 if (!cnt)
1096 goto chip_diag_failed;
1097
1098 /* Check product ID of chip */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001099 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product Id of chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
1101 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1102 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1103 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1104 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1105 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1106 mb[3] != PROD_ID_3) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001107 ql_log(ql_log_warn, vha, 0x0062,
1108 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
1109 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110
1111 goto chip_diag_failed;
1112 }
1113 ha->product_id[0] = mb[1];
1114 ha->product_id[1] = mb[2];
1115 ha->product_id[2] = mb[3];
1116 ha->product_id[3] = mb[4];
1117
1118 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001119 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1121 else
1122 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001123 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
1125 if (IS_QLA2200(ha) &&
1126 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1127 /* Limit firmware transfer size with a 2200A */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001128 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001130 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 ha->fw_transfer_size = 128;
1132 }
1133
1134 /* Wrap Incoming Mailboxes Test. */
1135 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1136
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001137 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001138 rval = qla2x00_mbx_reg_test(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001139 if (rval)
1140 ql_log(ql_log_warn, vha, 0x0080,
1141 "Failed mailbox send register test.\n");
1142 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 /* Flag a successful rval */
1144 rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 spin_lock_irqsave(&ha->hardware_lock, flags);
1146
1147chip_diag_failed:
1148 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001149 ql_log(ql_log_info, vha, 0x0081,
1150 "Chip diagnostics **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
1152 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1153
1154 return (rval);
1155}
1156
1157/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001158 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1159 * @ha: HA context
1160 *
1161 * Returns 0 on success.
1162 */
1163int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001164qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001165{
1166 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001167 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001168 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001169
Giridhar Malavalia9083012010-04-12 17:59:55 -07001170 if (IS_QLA82XX(ha))
1171 return QLA_SUCCESS;
1172
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001173 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001174
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001175 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001176 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001177 ql_log(ql_log_warn, vha, 0x0082,
1178 "Failed mailbox send register test.\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001179 } else {
1180 /* Flag a successful rval */
1181 rval = QLA_SUCCESS;
1182 }
1183
1184 return rval;
1185}
1186
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001187void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001188qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001189{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001190 int rval;
1191 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001192 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001193 dma_addr_t tc_dma;
1194 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001195 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001196 struct req_que *req = ha->req_q_map[0];
1197 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001198
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001199 if (ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001200 ql_dbg(ql_dbg_init, vha, 0x00bd,
1201 "Firmware dump already allocated.\n");
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001202 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001203 }
1204
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001205 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001206 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001207 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1208 fixed_size = sizeof(struct qla2100_fw_dump);
1209 } else if (IS_QLA23XX(ha)) {
1210 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1211 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1212 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001213 } else if (IS_FWI2_CAPABLE(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001214 if (IS_QLA83XX(ha))
1215 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
1216 else if (IS_QLA81XX(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001217 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1218 else if (IS_QLA25XX(ha))
1219 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1220 else
1221 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001222 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1223 sizeof(uint32_t);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001224 if (ha->mqenable) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001225 if (!IS_QLA83XX(ha))
1226 mq_size = sizeof(struct qla2xxx_mq_chain);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001227 /*
1228 * Allocate maximum buffer size for all queues.
1229 * Resizing must be done at end-of-dump processing.
1230 */
1231 mq_size += ha->max_req_queues *
1232 (req->length * sizeof(request_t));
1233 mq_size += ha->max_rsp_queues *
1234 (rsp->length * sizeof(response_t));
1235 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001236 /* Allocate memory for Fibre Channel Event Buffer. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001237 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001238 goto try_eft;
1239
1240 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1241 GFP_KERNEL);
1242 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001243 ql_log(ql_log_warn, vha, 0x00be,
1244 "Unable to allocate (%d KB) for FCE.\n",
1245 FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001246 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001247 }
1248
1249 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001250 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001251 ha->fce_mb, &ha->fce_bufs);
1252 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001253 ql_log(ql_log_warn, vha, 0x00bf,
1254 "Unable to initialize FCE (%d).\n", rval);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001255 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1256 tc_dma);
1257 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001258 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001259 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001260 ql_dbg(ql_dbg_init, vha, 0x00c0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001261 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001262
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001263 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001264 ha->flags.fce_enabled = 1;
1265 ha->fce_dma = tc_dma;
1266 ha->fce = tc;
1267try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001268 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001269 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001270 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001271 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001272 ql_log(ql_log_warn, vha, 0x00c1,
1273 "Unable to allocate (%d KB) for EFT.\n",
1274 EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001275 goto cont_alloc;
1276 }
1277
Andrew Vasquezfc447652008-01-17 09:02:18 -08001278 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001279 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001280 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001281 ql_log(ql_log_warn, vha, 0x00c2,
1282 "Unable to initialize EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001283 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1284 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001285 goto cont_alloc;
1286 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001287 ql_dbg(ql_dbg_init, vha, 0x00c3,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001288 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001289
1290 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001291 ha->eft_dma = tc_dma;
1292 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001293 }
1294cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001295 req_q_size = req->length * sizeof(request_t);
1296 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001297
1298 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001299 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001300 ha->chain_offset = dump_size;
1301 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001302
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001303 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001304 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001305 ql_log(ql_log_warn, vha, 0x00c4,
1306 "Unable to allocate (%d KB) for firmware dump.\n",
1307 dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001308
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07001309 if (ha->fce) {
1310 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
1311 ha->fce_dma);
1312 ha->fce = NULL;
1313 ha->fce_dma = 0;
1314 }
1315
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001316 if (ha->eft) {
1317 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1318 ha->eft_dma);
1319 ha->eft = NULL;
1320 ha->eft_dma = 0;
1321 }
1322 return;
1323 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001324 ql_dbg(ql_dbg_init, vha, 0x00c5,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001325 "Allocated (%d KB) for firmware dump.\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001326
1327 ha->fw_dump_len = dump_size;
1328 ha->fw_dump->signature[0] = 'Q';
1329 ha->fw_dump->signature[1] = 'L';
1330 ha->fw_dump->signature[2] = 'G';
1331 ha->fw_dump->signature[3] = 'C';
1332 ha->fw_dump->version = __constant_htonl(1);
1333
1334 ha->fw_dump->fixed_size = htonl(fixed_size);
1335 ha->fw_dump->mem_size = htonl(mem_size);
1336 ha->fw_dump->req_q_size = htonl(req_q_size);
1337 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1338
1339 ha->fw_dump->eft_size = htonl(eft_size);
1340 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1341 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1342
1343 ha->fw_dump->header_size =
1344 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001345}
1346
Andrew Vasquez18e75552009-06-03 09:55:30 -07001347static int
1348qla81xx_mpi_sync(scsi_qla_host_t *vha)
1349{
1350#define MPS_MASK 0xe0
1351 int rval;
1352 uint16_t dc;
1353 uint32_t dw;
Andrew Vasquez18e75552009-06-03 09:55:30 -07001354
1355 if (!IS_QLA81XX(vha->hw))
1356 return QLA_SUCCESS;
1357
1358 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1359 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001360 ql_log(ql_log_warn, vha, 0x0105,
1361 "Unable to acquire semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001362 goto done;
1363 }
1364
1365 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1366 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1367 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001368 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001369 goto done_release;
1370 }
1371
1372 dc &= MPS_MASK;
1373 if (dc == (dw & MPS_MASK))
1374 goto done_release;
1375
1376 dw &= ~MPS_MASK;
1377 dw |= dc;
1378 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1379 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001380 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001381 }
1382
1383done_release:
1384 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1385 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001386 ql_log(ql_log_warn, vha, 0x006d,
1387 "Unable to release semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001388 }
1389
1390done:
1391 return rval;
1392}
1393
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001394/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 * qla2x00_setup_chip() - Load and start RISC firmware.
1396 * @ha: HA context
1397 *
1398 * Returns 0 on success.
1399 */
1400static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001401qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001403 int rval;
1404 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001405 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001406 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1407 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001408 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001409
Giridhar Malavalia9083012010-04-12 17:59:55 -07001410 if (IS_QLA82XX(ha)) {
1411 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001412 if (rval == QLA_SUCCESS) {
1413 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001414 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001415 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07001416 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001417 }
1418
Andrew Vasquez3db06522008-01-31 12:33:49 -08001419 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1420 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1421 spin_lock_irqsave(&ha->hardware_lock, flags);
1422 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1423 RD_REG_WORD(&reg->hccr);
1424 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1425 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426
Andrew Vasquez18e75552009-06-03 09:55:30 -07001427 qla81xx_mpi_sync(vha);
1428
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001430 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001431 if (rval == QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001432 ql_dbg(ql_dbg_init, vha, 0x00c9,
1433 "Verifying Checksum of loaded RISC code.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001435 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 if (rval == QLA_SUCCESS) {
1437 /* Start firmware execution. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001438 ql_dbg(ql_dbg_init, vha, 0x00ca,
1439 "Starting firmware.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001441 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001443 if (rval == QLA_SUCCESS) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001444enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001445 fw_major_version = ha->fw_major_version;
Giridhar Malavali31731672011-08-16 11:31:54 -07001446 if (IS_QLA82XX(ha))
1447 qla82xx_check_md_needed(vha);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001448 else
1449 rval = qla2x00_get_fw_version(vha);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001450 if (rval != QLA_SUCCESS)
1451 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001452 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001453 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001454 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001455 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001456 if ((!ha->max_npiv_vports) ||
1457 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001458 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001459 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001460 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001461 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001462 qla2x00_get_resource_cnts(vha, NULL,
1463 &ha->fw_xcb_count, NULL, NULL,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001464 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001465
Saurav Kashyapbe5ea3c2011-11-18 09:02:11 -08001466 if (!fw_major_version && ql2xallocfwdump
1467 && !IS_QLA82XX(ha))
Giridhar Malavali08de2842011-08-16 11:31:44 -07001468 qla2x00_alloc_fw_dump(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 }
1470 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001471 ql_log(ql_log_fatal, vha, 0x00cd,
1472 "ISP Firmware failed checksum.\n");
1473 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 }
1475 }
1476
Andrew Vasquez3db06522008-01-31 12:33:49 -08001477 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1478 /* Enable proper parity. */
1479 spin_lock_irqsave(&ha->hardware_lock, flags);
1480 if (IS_QLA2300(ha))
1481 /* SRAM parity */
1482 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1483 else
1484 /* SRAM, Instruction RAM and GP RAM parity */
1485 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1486 RD_REG_WORD(&reg->hccr);
1487 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1488 }
1489
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001490 if (IS_QLA83XX(ha))
1491 goto skip_fac_check;
1492
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001493 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1494 uint32_t size;
1495
1496 rval = qla81xx_fac_get_sector_size(vha, &size);
1497 if (rval == QLA_SUCCESS) {
1498 ha->flags.fac_supported = 1;
1499 ha->fdt_block_size = size << 2;
1500 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001501 ql_log(ql_log_warn, vha, 0x00ce,
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001502 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1503 ha->fw_major_version, ha->fw_minor_version,
1504 ha->fw_subminor_version);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001505skip_fac_check:
1506 if (IS_QLA83XX(ha)) {
1507 ha->flags.fac_supported = 0;
1508 rval = QLA_SUCCESS;
1509 }
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001510 }
1511 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001512failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001514 ql_log(ql_log_fatal, vha, 0x00cf,
1515 "Setup chip ****FAILED****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 }
1517
1518 return (rval);
1519}
1520
1521/**
1522 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1523 * @ha: HA context
1524 *
1525 * Beginning of request ring has initialization control block already built
1526 * by nvram config routine.
1527 *
1528 * Returns 0 on success.
1529 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001530void
1531qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532{
1533 uint16_t cnt;
1534 response_t *pkt;
1535
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001536 rsp->ring_ptr = rsp->ring;
1537 rsp->ring_index = 0;
1538 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001539 pkt = rsp->ring_ptr;
1540 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 pkt->signature = RESPONSE_PROCESSED;
1542 pkt++;
1543 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544}
1545
1546/**
1547 * qla2x00_update_fw_options() - Read and process firmware options.
1548 * @ha: HA context
1549 *
1550 * Returns 0 on success.
1551 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001552void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001553qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554{
1555 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001556 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557
1558 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001559 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560
1561 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1562 return;
1563
1564 /* Serial Link options. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001565 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
1566 "Serial link options.\n");
1567 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
1568 (uint8_t *)&ha->fw_seriallink_options,
1569 sizeof(ha->fw_seriallink_options));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570
1571 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1572 if (ha->fw_seriallink_options[3] & BIT_2) {
1573 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1574
1575 /* 1G settings */
1576 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1577 emphasis = (ha->fw_seriallink_options[2] &
1578 (BIT_4 | BIT_3)) >> 3;
1579 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001580 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 rx_sens = (ha->fw_seriallink_options[0] &
1582 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1583 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1584 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1585 if (rx_sens == 0x0)
1586 rx_sens = 0x3;
1587 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1588 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1589 ha->fw_options[10] |= BIT_5 |
1590 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1591 (tx_sens & (BIT_1 | BIT_0));
1592
1593 /* 2G settings */
1594 swing = (ha->fw_seriallink_options[2] &
1595 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1596 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1597 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001598 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 rx_sens = (ha->fw_seriallink_options[1] &
1600 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1601 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1602 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1603 if (rx_sens == 0x0)
1604 rx_sens = 0x3;
1605 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1606 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1607 ha->fw_options[11] |= BIT_5 |
1608 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1609 (tx_sens & (BIT_1 | BIT_0));
1610 }
1611
1612 /* FCP2 options. */
1613 /* Return command IOCBs without waiting for an ABTS to complete. */
1614 ha->fw_options[3] |= BIT_13;
1615
1616 /* LED scheme. */
1617 if (ha->flags.enable_led_scheme)
1618 ha->fw_options[2] |= BIT_12;
1619
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001620 /* Detect ISP6312. */
1621 if (IS_QLA6312(ha))
1622 ha->fw_options[2] |= BIT_13;
1623
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001625 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626}
1627
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001628void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001629qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001630{
1631 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001632 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001633
Giridhar Malavalia9083012010-04-12 17:59:55 -07001634 if (IS_QLA82XX(ha))
1635 return;
1636
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001637 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001638 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001639 return;
1640
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001641 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001642 le16_to_cpu(ha->fw_seriallink_options24[1]),
1643 le16_to_cpu(ha->fw_seriallink_options24[2]),
1644 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001645 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001646 ql_log(ql_log_warn, vha, 0x0104,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001647 "Unable to update Serial Link options (%x).\n", rval);
1648 }
1649}
1650
1651void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001652qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001653{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001654 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001655 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001656 struct req_que *req = ha->req_q_map[0];
1657 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001658
1659 /* Setup ring parameters in initialization control block. */
1660 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1661 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001662 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1663 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1664 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1665 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1666 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1667 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001668
1669 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1670 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1671 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1672 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1673 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1674}
1675
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001676void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001677qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001678{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001679 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001680 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1681 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1682 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001683 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001684 uint16_t rid = 0;
1685 struct req_que *req = ha->req_q_map[0];
1686 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001687
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001688 /* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001689 icb = (struct init_cb_24xx *)ha->init_cb;
1690 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1691 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001692 icb->request_q_length = cpu_to_le16(req->length);
1693 icb->response_q_length = cpu_to_le16(rsp->length);
1694 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1695 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1696 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1697 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001698
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001699 if (ha->mqenable || IS_QLA83XX(ha)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001700 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1701 icb->rid = __constant_cpu_to_le16(rid);
1702 if (ha->flags.msix_enabled) {
1703 msix = &ha->msix_entries[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001704 ql_dbg(ql_dbg_init, vha, 0x00fd,
1705 "Registering vector 0x%x for base que.\n",
1706 msix->entry);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001707 icb->msix = cpu_to_le16(msix->entry);
1708 }
1709 /* Use alternate PCI bus number */
1710 if (MSB(rid))
1711 icb->firmware_options_2 |=
1712 __constant_cpu_to_le32(BIT_19);
1713 /* Use alternate PCI devfn */
1714 if (LSB(rid))
1715 icb->firmware_options_2 |=
1716 __constant_cpu_to_le32(BIT_18);
1717
Anirban Chakraborty31557542009-12-02 10:36:55 -08001718 /* Use Disable MSIX Handshake mode for capable adapters */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001719 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
1720 (ha->flags.msix_enabled)) {
Anirban Chakraborty31557542009-12-02 10:36:55 -08001721 icb->firmware_options_2 &=
1722 __constant_cpu_to_le32(~BIT_22);
1723 ha->flags.disable_msix_handshake = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001724 ql_dbg(ql_dbg_init, vha, 0x00fe,
1725 "MSIX Handshake Disable Mode turned on.\n");
Anirban Chakraborty31557542009-12-02 10:36:55 -08001726 } else {
1727 icb->firmware_options_2 |=
1728 __constant_cpu_to_le32(BIT_22);
1729 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001730 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001731
1732 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1733 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1734 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1735 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1736 } else {
1737 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1738 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1739 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1740 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1741 }
1742 /* PCI posting */
1743 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001744}
1745
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746/**
1747 * qla2x00_init_rings() - Initializes firmware.
1748 * @ha: HA context
1749 *
1750 * Beginning of request ring has initialization control block already built
1751 * by nvram config routine.
1752 *
1753 * Returns 0 on success.
1754 */
1755static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001756qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757{
1758 int rval;
1759 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001760 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001761 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001762 struct req_que *req;
1763 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001764 struct mid_init_cb_24xx *mid_init_cb =
1765 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766
1767 spin_lock_irqsave(&ha->hardware_lock, flags);
1768
1769 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001770 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001771 req = ha->req_q_map[que];
1772 if (!req)
1773 continue;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001774 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001775 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001777 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001778
1779 /* Initialize firmware. */
1780 req->ring_ptr = req->ring;
1781 req->ring_index = 0;
1782 req->cnt = req->length;
1783 }
1784
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001785 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001786 rsp = ha->rsp_q_map[que];
1787 if (!rsp)
1788 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001789 /* Initialize response queue entries */
1790 qla2x00_init_response_q_entries(rsp);
1791 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792
Dan Carpenter542bce12010-10-15 11:27:38 -07001793 spin_lock(&ha->vport_slock);
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,
Raul Porcel9e336522012-05-15 14:34:08 -04002188 "Inconsistent NVRAM "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002189 "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;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 fcport->port_type = FCT_UNKNOWN;
2499 fcport->loop_id = FC_NO_LOOP_ID;
Chad Dupuisec426e12011-03-30 11:46:32 -07002500 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002501 fcport->supported_classes = FC_COS_UNSPECIFIED;
Joe Carnuccioc0822b62012-05-15 14:34:21 -04002502 fcport->scan_state = QLA_FCPORT_SCAN_NONE;
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
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 set_bit(RSCN_UPDATE, &flags);
2555
2556 } else if (ha->current_topology == ISP_CFG_F &&
2557 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2558
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559 set_bit(RSCN_UPDATE, &flags);
2560 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2561
Andrew Vasquez21333b42006-05-17 15:09:56 -07002562 } else if (ha->current_topology == ISP_CFG_N) {
2563 clear_bit(RSCN_UPDATE, &flags);
2564
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002565 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2567
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 set_bit(RSCN_UPDATE, &flags);
2569 set_bit(LOCAL_LOOP_UPDATE, &flags);
2570 }
2571
2572 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002573 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2574 ql_dbg(ql_dbg_disc, vha, 0x2015,
2575 "Loop resync needed, failing.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 rval = QLA_FUNCTION_FAILED;
Chad Dupuis642ef982012-02-09 11:15:57 -08002577 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002578 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579 }
2580
2581 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002582 if (LOOP_TRANSITION(vha)) {
2583 ql_dbg(ql_dbg_disc, vha, 0x201e,
2584 "Needs RSCN update and loop transition.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 rval = QLA_FUNCTION_FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002586 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002587 else
2588 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 }
2590
2591 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002592 if (atomic_read(&vha->loop_down_timer) ||
2593 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 rval = QLA_FUNCTION_FAILED;
2595 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002596 atomic_set(&vha->loop_state, LOOP_READY);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002597 ql_dbg(ql_dbg_disc, vha, 0x2069,
2598 "LOOP READY.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 }
2600 }
2601
2602 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002603 ql_dbg(ql_dbg_disc, vha, 0x206a,
2604 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002606 ql_dbg(ql_dbg_disc, vha, 0x206b,
2607 "%s: exiting normally.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 }
2609
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002610 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002611 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002613 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002614 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002615 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002616 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 }
2618
2619 return (rval);
2620}
2621
2622
2623
2624/*
2625 * qla2x00_configure_local_loop
2626 * Updates Fibre Channel Device Database with local loop devices.
2627 *
2628 * Input:
2629 * ha = adapter block pointer.
2630 *
2631 * Returns:
2632 * 0 = success.
2633 */
2634static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002635qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636{
2637 int rval, rval2;
2638 int found_devs;
2639 int found;
2640 fc_port_t *fcport, *new_fcport;
2641
2642 uint16_t index;
2643 uint16_t entries;
2644 char *id_iter;
2645 uint16_t loop_id;
2646 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002647 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648
2649 found_devs = 0;
2650 new_fcport = NULL;
Chad Dupuis642ef982012-02-09 11:15:57 -08002651 entries = MAX_FIBRE_DEVICES_LOOP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002653 ql_dbg(ql_dbg_disc, vha, 0x2016,
2654 "Getting FCAL position map.\n");
2655 if (ql2xextended_error_logging & ql_dbg_disc)
2656 qla2x00_get_fcal_position_map(vha, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657
2658 /* Get list of logged in devices. */
Chad Dupuis642ef982012-02-09 11:15:57 -08002659 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002660 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 &entries);
2662 if (rval != QLA_SUCCESS)
2663 goto cleanup_allocation;
2664
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002665 ql_dbg(ql_dbg_disc, vha, 0x2017,
2666 "Entries in ID list (%d).\n", entries);
2667 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
2668 (uint8_t *)ha->gid_list,
2669 entries * sizeof(struct gid_list_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670
2671 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002672 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002674 ql_log(ql_log_warn, vha, 0x2018,
2675 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676 rval = QLA_MEMORY_ALLOC_FAILED;
2677 goto cleanup_allocation;
2678 }
2679 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2680
2681 /*
2682 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2683 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002684 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2686 fcport->port_type != FCT_BROADCAST &&
2687 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2688
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002689 ql_dbg(ql_dbg_disc, vha, 0x2019,
2690 "Marking port lost loop_id=0x%04x.\n",
2691 fcport->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692
Chad Dupuisec426e12011-03-30 11:46:32 -07002693 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 }
2695 }
2696
2697 /* Add devices to port list. */
2698 id_iter = (char *)ha->gid_list;
2699 for (index = 0; index < entries; index++) {
2700 domain = ((struct gid_list_info *)id_iter)->domain;
2701 area = ((struct gid_list_info *)id_iter)->area;
2702 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002703 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 loop_id = (uint16_t)
2705 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002706 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 loop_id = le16_to_cpu(
2708 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002709 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710
2711 /* Bypass reserved domain fields. */
2712 if ((domain & 0xf0) == 0xf0)
2713 continue;
2714
2715 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002716 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002717 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 continue;
2719
2720 /* Bypass invalid local loop ID. */
2721 if (loop_id > LAST_LOCAL_LOOP_ID)
2722 continue;
2723
2724 /* Fill in member data. */
2725 new_fcport->d_id.b.domain = domain;
2726 new_fcport->d_id.b.area = area;
2727 new_fcport->d_id.b.al_pa = al_pa;
2728 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002729 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002731 ql_dbg(ql_dbg_disc, vha, 0x201a,
2732 "Failed to retrieve fcport information "
2733 "-- get_port_database=%x, loop_id=0x%04x.\n",
2734 rval2, new_fcport->loop_id);
2735 ql_dbg(ql_dbg_disc, vha, 0x201b,
2736 "Scheduling resync.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002737 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 continue;
2739 }
2740
2741 /* Check for matching device in port list. */
2742 found = 0;
2743 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002744 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 if (memcmp(new_fcport->port_name, fcport->port_name,
2746 WWN_SIZE))
2747 continue;
2748
Shyam Sundarddb9b122009-03-24 09:08:10 -07002749 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 fcport->loop_id = new_fcport->loop_id;
2751 fcport->port_type = new_fcport->port_type;
2752 fcport->d_id.b24 = new_fcport->d_id.b24;
2753 memcpy(fcport->node_name, new_fcport->node_name,
2754 WWN_SIZE);
2755
2756 found++;
2757 break;
2758 }
2759
2760 if (!found) {
2761 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002762 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763
2764 /* Allocate a new replacement fcport. */
2765 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002766 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002768 ql_log(ql_log_warn, vha, 0x201c,
2769 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 rval = QLA_MEMORY_ALLOC_FAILED;
2771 goto cleanup_allocation;
2772 }
2773 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2774 }
2775
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002776 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002777 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002778
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002779 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780
2781 found_devs++;
2782 }
2783
2784cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002785 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786
2787 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002788 ql_dbg(ql_dbg_disc, vha, 0x201d,
2789 "Configure local loop error exit: rval=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790 }
2791
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 return (rval);
2793}
2794
2795static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002796qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002797{
2798#define LS_UNKNOWN 2
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002799 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2800 char *link_speed;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002801 int rval;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07002802 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002803 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002804
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002805 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002806 return;
2807
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07002808 if (atomic_read(&fcport->state) != FCS_ONLINE)
2809 return;
2810
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002811 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2812 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002813 return;
2814
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002815 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002816 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002817 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002818 ql_dbg(ql_dbg_disc, vha, 0x2004,
2819 "Unable to adjust iIDMA "
2820 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x "
2821 "%04x.\n", fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002822 fcport->port_name[2], fcport->port_name[3],
2823 fcport->port_name[4], fcport->port_name[5],
2824 fcport->port_name[6], fcport->port_name[7], rval,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002825 fcport->fp_speed, mb[0], mb[1]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002826 } else {
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002827 link_speed = link_speeds[LS_UNKNOWN];
2828 if (fcport->fp_speed < 5)
2829 link_speed = link_speeds[fcport->fp_speed];
2830 else if (fcport->fp_speed == 0x13)
2831 link_speed = link_speeds[5];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002832 ql_dbg(ql_dbg_disc, vha, 0x2005,
2833 "iIDMA adjusted to %s GB/s "
2834 "on %02x%02x%02x%02x%02x%02x%02x%02x.\n", link_speed,
2835 fcport->port_name[0], fcport->port_name[1],
2836 fcport->port_name[2], fcport->port_name[3],
2837 fcport->port_name[4], fcport->port_name[5],
2838 fcport->port_name[6], fcport->port_name[7]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002839 }
2840}
2841
Adrian Bunk23be3312006-11-24 02:46:01 +01002842static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002843qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002844{
2845 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002846 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002847 unsigned long flags;
8482e1182005-04-17 15:04:54 -05002848
Andrew Vasquezac280b62009-08-20 11:06:05 -07002849 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002850
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002851 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2852 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002853 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2854 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2855 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002856 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002857 if (!rport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002858 ql_log(ql_log_warn, vha, 0x2006,
2859 "Unable to allocate fc remote port.\n");
Andrew Vasquez77d74142005-07-08 18:00:36 -07002860 return;
2861 }
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002862 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002863 *((fc_port_t **)rport->dd_data) = fcport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002864 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002865
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002866 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002867
2868 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002869 if (fcport->port_type == FCT_INITIATOR)
2870 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2871 if (fcport->port_type == FCT_TARGET)
2872 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002873 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002874}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875
2876/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002877 * qla2x00_update_fcport
2878 * Updates device on list.
2879 *
2880 * Input:
2881 * ha = adapter block pointer.
2882 * fcport = port structure pointer.
2883 *
2884 * Return:
2885 * 0 - Success
2886 * BIT_0 - error
2887 *
2888 * Context:
2889 * Kernel context.
2890 */
2891void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002892qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002893{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002894 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002895 fcport->login_retry = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002896 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Adrian Bunk23be3312006-11-24 02:46:01 +01002897
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002898 qla2x00_iidma_fcport(vha, fcport);
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08002899 qla24xx_update_fcport_fcp_prio(vha, fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002900 qla2x00_reg_remote_port(vha, fcport);
Chad Dupuisec426e12011-03-30 11:46:32 -07002901 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Adrian Bunk23be3312006-11-24 02:46:01 +01002902}
2903
2904/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 * qla2x00_configure_fabric
2906 * Setup SNS devices with loop ID's.
2907 *
2908 * Input:
2909 * ha = adapter block pointer.
2910 *
2911 * Returns:
2912 * 0 = success.
2913 * BIT_0 = error
2914 */
2915static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002916qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917{
Arun Easib3b02e62012-02-09 11:15:39 -08002918 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 fc_port_t *fcport, *fcptemp;
2920 uint16_t next_loopid;
2921 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002922 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002924 struct qla_hw_data *ha = vha->hw;
2925 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926
2927 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002928 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002929 loop_id = NPH_F_PORT;
2930 else
2931 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002932 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002934 ql_dbg(ql_dbg_disc, vha, 0x201f,
2935 "MBX_GET_PORT_NAME failed, No FL Port.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002937 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 return (QLA_SUCCESS);
2939 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002940 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002943 /* FDMI support. */
2944 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002945 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2946 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002947
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002949 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002950 loop_id = NPH_SNS;
2951 else
2952 loop_id = SIMPLE_NAME_SERVER;
Chad Dupuis0b91d112012-02-09 11:15:42 -08002953 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
2954 0xfc, mb, BIT_1|BIT_0);
2955 if (rval != QLA_SUCCESS) {
2956 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2957 return rval;
2958 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959 if (mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002960 ql_dbg(ql_dbg_disc, vha, 0x2042,
2961 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
2962 "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1],
2963 mb[2], mb[6], mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964 return (QLA_SUCCESS);
2965 }
2966
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002967 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2968 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002970 ql_dbg(ql_dbg_disc, vha, 0x2045,
2971 "Register FC-4 TYPE failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002973 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002975 ql_dbg(ql_dbg_disc, vha, 0x2049,
2976 "Register FC-4 Features failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002978 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002980 ql_dbg(ql_dbg_disc, vha, 0x204f,
2981 "Register Node Name failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002982 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002984 ql_dbg(ql_dbg_disc, vha, 0x2053,
2985 "Register Symobilic Node Name failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986 }
2987 }
2988
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002989 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 if (rval != QLA_SUCCESS)
2991 break;
2992
2993 /*
2994 * Logout all previous fabric devices marked lost, except
Andrew Vasquezf08b7252010-01-12 12:59:48 -08002995 * FCP2 devices.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002997 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2998 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 break;
3000
3001 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3002 continue;
3003
Joe Carnuccioc0822b62012-05-15 14:34:21 -04003004 if (fcport->scan_state != QLA_FCPORT_SCAN_FOUND &&
Arun Easib3b02e62012-02-09 11:15:39 -08003005 atomic_read(&fcport->state) == FCS_ONLINE) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003006 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003007 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003009 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 fcport->port_type != FCT_INITIATOR &&
3011 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003012 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003013 fcport->loop_id,
3014 fcport->d_id.b.domain,
3015 fcport->d_id.b.area,
3016 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017 fcport->loop_id = FC_NO_LOOP_ID;
3018 }
Joe Carnuccioc0822b62012-05-15 14:34:21 -04003019 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 }
Joe Carnuccioc0822b62012-05-15 14:34:21 -04003021 fcport->scan_state = QLA_FCPORT_SCAN_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 }
3023
3024 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003025 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026
3027 /*
3028 * Scan through our port list and login entries that need to be
3029 * logged in.
3030 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003031 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3032 if (atomic_read(&vha->loop_down_timer) ||
3033 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034 break;
3035
3036 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3037 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
3038 continue;
3039
3040 if (fcport->loop_id == FC_NO_LOOP_ID) {
3041 fcport->loop_id = next_loopid;
Seokmann Jud4486fd2008-04-03 13:13:28 -07003042 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003043 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 if (rval != QLA_SUCCESS) {
3045 /* Ran out of IDs to use */
3046 break;
3047 }
3048 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003050 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 }
3052
3053 /* Exit if out of loop IDs. */
3054 if (rval != QLA_SUCCESS) {
3055 break;
3056 }
3057
3058 /*
3059 * Login and add the new devices to our port list.
3060 */
3061 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003062 if (atomic_read(&vha->loop_down_timer) ||
3063 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064 break;
3065
3066 /* Find a new loop ID to use. */
3067 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003068 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069 if (rval != QLA_SUCCESS) {
3070 /* Ran out of IDs to use */
3071 break;
3072 }
3073
bdf79622005-04-17 15:06:53 -05003074 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003075 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003076
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003077 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078 }
3079 } while (0);
3080
3081 /* Free all new device structures not processed. */
3082 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3083 list_del(&fcport->list);
3084 kfree(fcport);
3085 }
3086
3087 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003088 ql_dbg(ql_dbg_disc, vha, 0x2068,
3089 "Configure fabric error exit rval=%d.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 }
3091
3092 return (rval);
3093}
3094
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095/*
3096 * qla2x00_find_all_fabric_devs
3097 *
3098 * Input:
3099 * ha = adapter block pointer.
3100 * dev = database device entry pointer.
3101 *
3102 * Returns:
3103 * 0 = success.
3104 *
3105 * Context:
3106 * Kernel context.
3107 */
3108static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003109qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3110 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111{
3112 int rval;
3113 uint16_t loop_id;
3114 fc_port_t *fcport, *new_fcport, *fcptemp;
3115 int found;
3116
3117 sw_info_t *swl;
3118 int swl_idx;
3119 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07003120 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003121 struct qla_hw_data *ha = vha->hw;
3122 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003123 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124
3125 rval = QLA_SUCCESS;
3126
3127 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez7a677352012-02-09 11:15:56 -08003128 if (!ha->swl)
Chad Dupuis642ef982012-02-09 11:15:57 -08003129 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
Andrew Vasquez7a677352012-02-09 11:15:56 -08003130 GFP_KERNEL);
3131 swl = ha->swl;
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003132 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003134 ql_dbg(ql_dbg_disc, vha, 0x2054,
3135 "GID_PT allocations failed, fallback on GA_NXT.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 } else {
Chad Dupuis642ef982012-02-09 11:15:57 -08003137 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003138 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003140 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003142 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07003144 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003145 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3146 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003148
3149 /* If other queries succeeded probe for FC-4 type */
3150 if (swl)
3151 qla2x00_gff_id(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 }
3153 swl_idx = 0;
3154
3155 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003156 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003158 ql_log(ql_log_warn, vha, 0x205e,
3159 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160 return (QLA_MEMORY_ALLOC_FAILED);
3161 }
3162 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163 /* Set start port ID scan at adapter ID. */
3164 first_dev = 1;
3165 last_dev = 0;
3166
3167 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003168 loop_id = ha->min_external_loopid;
3169 for (; loop_id <= ha->max_loop_id; loop_id++) {
3170 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 continue;
3172
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07003173 if (ha->current_topology == ISP_CFG_FL &&
3174 (atomic_read(&vha->loop_down_timer) ||
3175 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003176 atomic_set(&vha->loop_down_timer, 0);
3177 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3178 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003180 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181
3182 if (swl != NULL) {
3183 if (last_dev) {
3184 wrap.b24 = new_fcport->d_id.b24;
3185 } else {
3186 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3187 memcpy(new_fcport->node_name,
3188 swl[swl_idx].node_name, WWN_SIZE);
3189 memcpy(new_fcport->port_name,
3190 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003191 memcpy(new_fcport->fabric_port_name,
3192 swl[swl_idx].fabric_port_name, WWN_SIZE);
3193 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003194 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195
3196 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3197 last_dev = 1;
3198 }
3199 swl_idx++;
3200 }
3201 } else {
3202 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003203 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003205 ql_log(ql_log_warn, vha, 0x2064,
3206 "SNS scan failed -- assuming "
3207 "zero-entry result.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208 list_for_each_entry_safe(fcport, fcptemp,
3209 new_fcports, list) {
3210 list_del(&fcport->list);
3211 kfree(fcport);
3212 }
3213 rval = QLA_SUCCESS;
3214 break;
3215 }
3216 }
3217
3218 /* If wrap on switch device list, exit. */
3219 if (first_dev) {
3220 wrap.b24 = new_fcport->d_id.b24;
3221 first_dev = 0;
3222 } else if (new_fcport->d_id.b24 == wrap.b24) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003223 ql_dbg(ql_dbg_disc, vha, 0x2065,
3224 "Device wrap (%02x%02x%02x).\n",
3225 new_fcport->d_id.b.domain,
3226 new_fcport->d_id.b.area,
3227 new_fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228 break;
3229 }
3230
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003231 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003232 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233 continue;
3234
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003235 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003236 found = 0;
3237 if (ha->num_vhosts) {
Arun Easifeafb7b2010-09-03 14:57:00 -07003238 unsigned long flags;
3239
3240 spin_lock_irqsave(&ha->vport_slock, flags);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003241 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003242 if (new_fcport->d_id.b24 == vp->d_id.b24) {
3243 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003244 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003245 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003246 }
Arun Easifeafb7b2010-09-03 14:57:00 -07003247 spin_unlock_irqrestore(&ha->vport_slock, flags);
3248
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003249 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003250 continue;
3251 }
3252
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003253 /* Bypass if same domain and area of adapter. */
3254 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003255 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003256 ISP_CFG_FL)
3257 continue;
3258
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 /* Bypass reserved domain fields. */
3260 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3261 continue;
3262
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003263 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07003264 if (ql2xgffidenable &&
3265 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
3266 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003267 continue;
3268
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 /* Locate matching device in database. */
3270 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003271 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272 if (memcmp(new_fcport->port_name, fcport->port_name,
3273 WWN_SIZE))
3274 continue;
3275
Joe Carnuccioc0822b62012-05-15 14:34:21 -04003276 fcport->scan_state = QLA_FCPORT_SCAN_FOUND;
Arun Easib3b02e62012-02-09 11:15:39 -08003277
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278 found++;
3279
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003280 /* Update port state. */
3281 memcpy(fcport->fabric_port_name,
3282 new_fcport->fabric_port_name, WWN_SIZE);
3283 fcport->fp_speed = new_fcport->fp_speed;
3284
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285 /*
3286 * If address the same and state FCS_ONLINE, nothing
3287 * changed.
3288 */
3289 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3290 atomic_read(&fcport->state) == FCS_ONLINE) {
3291 break;
3292 }
3293
3294 /*
3295 * If device was not a fabric device before.
3296 */
3297 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3298 fcport->d_id.b24 = new_fcport->d_id.b24;
3299 fcport->loop_id = FC_NO_LOOP_ID;
3300 fcport->flags |= (FCF_FABRIC_DEVICE |
3301 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302 break;
3303 }
3304
3305 /*
3306 * Port ID changed or device was marked to be updated;
3307 * Log it out if still logged in and mark it for
3308 * relogin later.
3309 */
3310 fcport->d_id.b24 = new_fcport->d_id.b24;
3311 fcport->flags |= FCF_LOGIN_NEEDED;
3312 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003313 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Arun Easi0eba25d2012-02-09 11:15:58 -08003314 (fcport->flags & FCF_ASYNC_SENT) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315 fcport->port_type != FCT_INITIATOR &&
3316 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003317 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003318 fcport->d_id.b.domain, fcport->d_id.b.area,
3319 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320 fcport->loop_id = FC_NO_LOOP_ID;
3321 }
3322
3323 break;
3324 }
3325
3326 if (found)
3327 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328 /* If device was not in our fcports list, then add it. */
3329 list_add_tail(&new_fcport->list, new_fcports);
3330
3331 /* Allocate a new replacement fcport. */
3332 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003333 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003335 ql_log(ql_log_warn, vha, 0x2066,
3336 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337 return (QLA_MEMORY_ALLOC_FAILED);
3338 }
3339 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3340 new_fcport->d_id.b24 = nxt_d_id.b24;
3341 }
3342
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003343 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345 return (rval);
3346}
3347
3348/*
3349 * qla2x00_find_new_loop_id
3350 * Scan through our port list and find a new usable loop ID.
3351 *
3352 * Input:
3353 * ha: adapter state pointer.
3354 * dev: port structure pointer.
3355 *
3356 * Returns:
3357 * qla2x00 local function return status code.
3358 *
3359 * Context:
3360 * Kernel context.
3361 */
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07003362int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003363qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364{
3365 int rval;
3366 int found;
3367 fc_port_t *fcport;
3368 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003369 struct qla_hw_data *ha = vha->hw;
3370 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003371 struct scsi_qla_host *tvp;
Arun Easifeafb7b2010-09-03 14:57:00 -07003372 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373
3374 rval = QLA_SUCCESS;
3375
3376 /* Save starting loop ID. */
3377 first_loop_id = dev->loop_id;
3378
3379 for (;;) {
3380 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003381 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383
3384 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003385 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387
3388 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003389 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390 /* first loop ID. */
3391 dev->loop_id = ha->min_external_loopid;
3392 }
3393
3394 /* Check for loop ID being already in use. */
3395 found = 0;
3396 fcport = NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003397
3398 spin_lock_irqsave(&ha->vport_slock, flags);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003399 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003400 list_for_each_entry(fcport, &vp->vp_fcports, list) {
3401 if (fcport->loop_id == dev->loop_id &&
3402 fcport != dev) {
3403 /* ID possibly in use */
3404 found++;
3405 break;
3406 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003408 if (found)
3409 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 }
Arun Easifeafb7b2010-09-03 14:57:00 -07003411 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412
3413 /* If not in use then it is free to use. */
3414 if (!found) {
Arun Easi557cf782012-02-09 11:15:50 -08003415 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
3416 "Assigning new loopid=%x, portid=%x.\n",
3417 dev->loop_id, dev->d_id.b24);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418 break;
3419 }
3420
3421 /* ID in use. Try next value. */
3422 dev->loop_id++;
3423
3424 /* If wrap around. No free ID to use. */
3425 if (dev->loop_id == first_loop_id) {
3426 dev->loop_id = FC_NO_LOOP_ID;
3427 rval = QLA_FUNCTION_FAILED;
3428 break;
3429 }
3430 }
3431
3432 return (rval);
3433}
3434
3435/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436 * qla2x00_fabric_dev_login
3437 * Login fabric target device and update FC port database.
3438 *
3439 * Input:
3440 * ha: adapter state pointer.
3441 * fcport: port structure list pointer.
3442 * next_loopid: contains value of a new loop ID that can be used
3443 * by the next login attempt.
3444 *
3445 * Returns:
3446 * qla2x00 local function return status code.
3447 *
3448 * Context:
3449 * Kernel context.
3450 */
3451static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003452qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453 uint16_t *next_loopid)
3454{
3455 int rval;
3456 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003457 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003458 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459
3460 rval = QLA_SUCCESS;
3461 retry = 0;
3462
Andrew Vasquezac280b62009-08-20 11:06:05 -07003463 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003464 if (fcport->flags & FCF_ASYNC_SENT)
3465 return rval;
3466 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003467 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3468 if (!rval)
3469 return rval;
3470 }
3471
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003472 fcport->flags &= ~FCF_ASYNC_SENT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003473 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003474 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003475 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003476 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003477 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003478 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003479 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003481 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003482 fcport->d_id.b.domain, fcport->d_id.b.area,
3483 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003484 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003486 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003487 }
Chad Dupuis0b91d112012-02-09 11:15:42 -08003488 } else {
3489 /* Retry Login. */
3490 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003491 }
3492
3493 return (rval);
3494}
3495
3496/*
3497 * qla2x00_fabric_login
3498 * Issue fabric login command.
3499 *
3500 * Input:
3501 * ha = adapter block pointer.
3502 * device = pointer to FC device type structure.
3503 *
3504 * Returns:
3505 * 0 - Login successfully
3506 * 1 - Login failed
3507 * 2 - Initiator device
3508 * 3 - Fatal error
3509 */
3510int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003511qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512 uint16_t *next_loopid)
3513{
3514 int rval;
3515 int retry;
3516 uint16_t tmp_loopid;
3517 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003518 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519
3520 retry = 0;
3521 tmp_loopid = 0;
3522
3523 for (;;) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003524 ql_dbg(ql_dbg_disc, vha, 0x2000,
3525 "Trying Fabric Login w/loop id 0x%04x for port "
3526 "%02x%02x%02x.\n",
3527 fcport->loop_id, fcport->d_id.b.domain,
3528 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529
3530 /* Login fcport on switch. */
Chad Dupuis0b91d112012-02-09 11:15:42 -08003531 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532 fcport->d_id.b.domain, fcport->d_id.b.area,
3533 fcport->d_id.b.al_pa, mb, BIT_0);
Chad Dupuis0b91d112012-02-09 11:15:42 -08003534 if (rval != QLA_SUCCESS) {
3535 return rval;
3536 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537 if (mb[0] == MBS_PORT_ID_USED) {
3538 /*
3539 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003540 * recommends the driver perform an implicit login with
3541 * the specified ID again. The ID we just used is save
3542 * here so we return with an ID that can be tried by
3543 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544 */
3545 retry++;
3546 tmp_loopid = fcport->loop_id;
3547 fcport->loop_id = mb[1];
3548
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003549 ql_dbg(ql_dbg_disc, vha, 0x2001,
3550 "Fabric Login: port in use - next loop "
3551 "id=0x%04x, port id= %02x%02x%02x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552 fcport->loop_id, fcport->d_id.b.domain,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003553 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554
3555 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3556 /*
3557 * Login succeeded.
3558 */
3559 if (retry) {
3560 /* A retry occurred before. */
3561 *next_loopid = tmp_loopid;
3562 } else {
3563 /*
3564 * No retry occurred before. Just increment the
3565 * ID value for next login.
3566 */
3567 *next_loopid = (fcport->loop_id + 1);
3568 }
3569
3570 if (mb[1] & BIT_0) {
3571 fcport->port_type = FCT_INITIATOR;
3572 } else {
3573 fcport->port_type = FCT_TARGET;
3574 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07003575 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576 }
3577 }
3578
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003579 if (mb[10] & BIT_0)
3580 fcport->supported_classes |= FC_COS_CLASS2;
3581 if (mb[10] & BIT_1)
3582 fcport->supported_classes |= FC_COS_CLASS3;
3583
Linus Torvalds1da177e2005-04-16 15:20:36 -07003584 rval = QLA_SUCCESS;
3585 break;
3586 } else if (mb[0] == MBS_LOOP_ID_USED) {
3587 /*
3588 * Loop ID already used, try next loop ID.
3589 */
3590 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003591 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003592 if (rval != QLA_SUCCESS) {
3593 /* Ran out of loop IDs to use */
3594 break;
3595 }
3596 } else if (mb[0] == MBS_COMMAND_ERROR) {
3597 /*
3598 * Firmware possibly timed out during login. If NO
3599 * retries are left to do then the device is declared
3600 * dead.
3601 */
3602 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003603 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003604 fcport->d_id.b.domain, fcport->d_id.b.area,
3605 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003606 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003607
3608 rval = 1;
3609 break;
3610 } else {
3611 /*
3612 * unrecoverable / not handled error
3613 */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003614 ql_dbg(ql_dbg_disc, vha, 0x2002,
3615 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
3616 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
3617 fcport->d_id.b.area, fcport->d_id.b.al_pa,
3618 fcport->loop_id, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003619
3620 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003621 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003622 fcport->d_id.b.domain, fcport->d_id.b.area,
3623 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003624 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003625 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626
3627 rval = 3;
3628 break;
3629 }
3630 }
3631
3632 return (rval);
3633}
3634
3635/*
3636 * qla2x00_local_device_login
3637 * Issue local device login command.
3638 *
3639 * Input:
3640 * ha = adapter block pointer.
3641 * loop_id = loop id of device to login to.
3642 *
3643 * Returns (Where's the #define!!!!):
3644 * 0 - Login successfully
3645 * 1 - Login failed
3646 * 3 - Fatal error
3647 */
3648int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003649qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003650{
3651 int rval;
3652 uint16_t mb[MAILBOX_REGISTER_COUNT];
3653
3654 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003655 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003656 if (rval == QLA_SUCCESS) {
3657 /* Interrogate mailbox registers for any errors */
3658 if (mb[0] == MBS_COMMAND_ERROR)
3659 rval = 1;
3660 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3661 /* device not in PCB table */
3662 rval = 3;
3663 }
3664
3665 return (rval);
3666}
3667
3668/*
3669 * qla2x00_loop_resync
3670 * Resync with fibre channel devices.
3671 *
3672 * Input:
3673 * ha = adapter block pointer.
3674 *
3675 * Returns:
3676 * 0 = success
3677 */
3678int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003679qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003680{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003681 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003682 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003683 struct req_que *req;
3684 struct rsp_que *rsp;
3685
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07003686 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003687 req = vha->hw->req_q_map[0];
3688 else
3689 req = vha->req;
3690 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003692 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3693 if (vha->flags.online) {
3694 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3696 wait_time = 256;
3697 do {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003698 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003699 qla2x00_marker(vha, req, rsp, 0, 0,
3700 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003701 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003702
3703 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003704 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003706 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003708 } while (!atomic_read(&vha->loop_down_timer) &&
3709 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3710 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3711 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003713 }
3714
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003715 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003717
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003718 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003719 ql_dbg(ql_dbg_disc, vha, 0x206c,
3720 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721
3722 return (rval);
3723}
3724
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003725/*
3726* qla2x00_perform_loop_resync
3727* Description: This function will set the appropriate flags and call
3728* qla2x00_loop_resync. If successful loop will be resynced
3729* Arguments : scsi_qla_host_t pointer
3730* returm : Success or Failure
3731*/
3732
3733int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
3734{
3735 int32_t rval = 0;
3736
3737 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
3738 /*Configure the flags so that resync happens properly*/
3739 atomic_set(&ha->loop_down_timer, 0);
3740 if (!(ha->device_flags & DFLG_NO_CABLE)) {
3741 atomic_set(&ha->loop_state, LOOP_UP);
3742 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
3743 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
3744 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3745
3746 rval = qla2x00_loop_resync(ha);
3747 } else
3748 atomic_set(&ha->loop_state, LOOP_DEAD);
3749
3750 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
3751 }
3752
3753 return rval;
3754}
3755
Linus Torvalds1da177e2005-04-16 15:20:36 -07003756void
Andrew Vasquez67becc02009-08-25 11:36:20 -07003757qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003758{
3759 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07003760 struct scsi_qla_host *vha;
3761 struct qla_hw_data *ha = base_vha->hw;
3762 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003763
Arun Easifeafb7b2010-09-03 14:57:00 -07003764 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003765 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07003766 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
3767 atomic_inc(&vha->vref_count);
3768 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Dan Carpenter8ae598d2010-12-21 16:00:15 -08003769 if (fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07003770 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
3771 spin_unlock_irqrestore(&ha->vport_slock, flags);
3772
Andrew Vasquez67becc02009-08-25 11:36:20 -07003773 qla2x00_rport_del(fcport);
Arun Easifeafb7b2010-09-03 14:57:00 -07003774
3775 spin_lock_irqsave(&ha->vport_slock, flags);
3776 }
3777 }
3778 atomic_dec(&vha->vref_count);
3779 }
3780 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003781}
3782
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003783/*
3784* qla82xx_quiescent_state_cleanup
3785* Description: This function will block the new I/Os
3786* Its not aborting any I/Os as context
3787* is not destroyed during quiescence
3788* Arguments: scsi_qla_host_t
3789* return : void
3790*/
3791void
3792qla82xx_quiescent_state_cleanup(scsi_qla_host_t *vha)
3793{
3794 struct qla_hw_data *ha = vha->hw;
3795 struct scsi_qla_host *vp;
3796
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003797 ql_dbg(ql_dbg_p3p, vha, 0xb002,
3798 "Performing ISP error recovery - ha=%p.\n", ha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003799
3800 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3801 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3802 atomic_set(&vha->loop_state, LOOP_DOWN);
3803 qla2x00_mark_all_devices_lost(vha, 0);
3804 list_for_each_entry(vp, &ha->vp_list, list)
3805 qla2x00_mark_all_devices_lost(vha, 0);
3806 } else {
3807 if (!atomic_read(&vha->loop_down_timer))
3808 atomic_set(&vha->loop_down_timer,
3809 LOOP_DOWN_TIME);
3810 }
3811 /* Wait for pending cmds to complete */
3812 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
3813}
3814
Giridhar Malavalia9083012010-04-12 17:59:55 -07003815void
3816qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
3817{
3818 struct qla_hw_data *ha = vha->hw;
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003819 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07003820 unsigned long flags;
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08003821 fc_port_t *fcport;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003822
Saurav Kashyape46ef002011-02-23 15:27:16 -08003823 /* For ISP82XX, driver waits for completion of the commands.
3824 * online flag should be set.
3825 */
3826 if (!IS_QLA82XX(ha))
3827 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003828 ha->flags.chip_reset_done = 0;
3829 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04003830 vha->qla_stats.total_isp_aborts++;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003831
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003832 ql_log(ql_log_info, vha, 0x00af,
3833 "Performing ISP error recovery - ha=%p.\n", ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003834
Saurav Kashyape46ef002011-02-23 15:27:16 -08003835 /* For ISP82XX, reset_chip is just disabling interrupts.
3836 * Driver waits for the completion of the commands.
3837 * the interrupts need to be enabled.
3838 */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003839 if (!IS_QLA82XX(ha))
3840 ha->isp_ops->reset_chip(vha);
3841
3842 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3843 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3844 atomic_set(&vha->loop_state, LOOP_DOWN);
3845 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07003846
3847 spin_lock_irqsave(&ha->vport_slock, flags);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003848 list_for_each_entry(vp, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -07003849 atomic_inc(&vp->vref_count);
3850 spin_unlock_irqrestore(&ha->vport_slock, flags);
3851
Giridhar Malavalia9083012010-04-12 17:59:55 -07003852 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07003853
3854 spin_lock_irqsave(&ha->vport_slock, flags);
3855 atomic_dec(&vp->vref_count);
3856 }
3857 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003858 } else {
3859 if (!atomic_read(&vha->loop_down_timer))
3860 atomic_set(&vha->loop_down_timer,
3861 LOOP_DOWN_TIME);
3862 }
3863
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08003864 /* Clear all async request states across all VPs. */
3865 list_for_each_entry(fcport, &vha->vp_fcports, list)
3866 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
3867 spin_lock_irqsave(&ha->vport_slock, flags);
3868 list_for_each_entry(vp, &ha->vp_list, list) {
3869 atomic_inc(&vp->vref_count);
3870 spin_unlock_irqrestore(&ha->vport_slock, flags);
3871
3872 list_for_each_entry(fcport, &vp->vp_fcports, list)
3873 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
3874
3875 spin_lock_irqsave(&ha->vport_slock, flags);
3876 atomic_dec(&vp->vref_count);
3877 }
3878 spin_unlock_irqrestore(&ha->vport_slock, flags);
3879
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07003880 if (!ha->flags.eeh_busy) {
3881 /* Make sure for ISP 82XX IO DMA is complete */
3882 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08003883 qla82xx_chip_reset_cleanup(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003884 ql_log(ql_log_info, vha, 0x00b4,
3885 "Done chip reset cleanup.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003886
Saurav Kashyape46ef002011-02-23 15:27:16 -08003887 /* Done waiting for pending commands.
3888 * Reset the online flag.
3889 */
3890 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003891 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07003893 /* Requeue all commands in outstanding command list. */
3894 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
3895 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896}
3897
3898/*
3899* qla2x00_abort_isp
3900* Resets ISP and aborts all outstanding commands.
3901*
3902* Input:
3903* ha = adapter block pointer.
3904*
3905* Returns:
3906* 0 = success
3907*/
3908int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003909qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003910{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003911 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003913 struct qla_hw_data *ha = vha->hw;
3914 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003915 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07003916 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003917
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003918 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003919 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003920
Andrew Vasquez85880802009-12-15 21:29:46 -08003921 if (unlikely(pci_channel_offline(ha->pdev) &&
3922 ha->flags.pci_channel_io_perm_failure)) {
3923 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3924 status = 0;
3925 return status;
3926 }
3927
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003928 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003929
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003930 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003931
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003932 if (!qla2x00_restart_isp(vha)) {
3933 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003935 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003936 /*
3937 * Issue marker command only when we are going
3938 * to start the I/O .
3939 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003940 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003941 }
3942
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003943 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003944
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003945 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003946
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003947 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003948 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003949
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003950 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
3951 qla2x00_get_fw_version(vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003952 if (ha->fce) {
3953 ha->flags.fce_enabled = 1;
3954 memset(ha->fce, 0,
3955 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003956 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003957 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3958 &ha->fce_bufs);
3959 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003960 ql_log(ql_log_warn, vha, 0x8033,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003961 "Unable to reinitialize FCE "
3962 "(%d).\n", rval);
3963 ha->flags.fce_enabled = 0;
3964 }
3965 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003966
3967 if (ha->eft) {
3968 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003969 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003970 ha->eft_dma, EFT_NUM_BUFFERS);
3971 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003972 ql_log(ql_log_warn, vha, 0x8034,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003973 "Unable to reinitialize EFT "
3974 "(%d).\n", rval);
3975 }
3976 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003978 vha->flags.online = 1;
3979 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980 if (ha->isp_abort_cnt == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003981 ql_log(ql_log_fatal, vha, 0x8035,
3982 "ISP error recover failed - "
3983 "board disabled.\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003984 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003985 * The next call disables the board
3986 * completely.
3987 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003988 ha->isp_ops->reset_adapter(vha);
3989 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003990 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003991 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003992 status = 0;
3993 } else { /* schedule another ISP abort */
3994 ha->isp_abort_cnt--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003995 ql_dbg(ql_dbg_taskm, vha, 0x8020,
3996 "ISP abort - retry remaining %d.\n",
3997 ha->isp_abort_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003998 status = 1;
3999 }
4000 } else {
4001 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004002 ql_dbg(ql_dbg_taskm, vha, 0x8021,
4003 "ISP error recovery - retrying (%d) "
4004 "more times.\n", ha->isp_abort_cnt);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004005 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004006 status = 1;
4007 }
4008 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004009
Linus Torvalds1da177e2005-04-16 15:20:36 -07004010 }
4011
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004012 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004013 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
Arun Easifeafb7b2010-09-03 14:57:00 -07004014
4015 spin_lock_irqsave(&ha->vport_slock, flags);
4016 list_for_each_entry(vp, &ha->vp_list, list) {
4017 if (vp->vp_idx) {
4018 atomic_inc(&vp->vref_count);
4019 spin_unlock_irqrestore(&ha->vport_slock, flags);
4020
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004021 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07004022
4023 spin_lock_irqsave(&ha->vport_slock, flags);
4024 atomic_dec(&vp->vref_count);
4025 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004026 }
Arun Easifeafb7b2010-09-03 14:57:00 -07004027 spin_unlock_irqrestore(&ha->vport_slock, flags);
4028
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004029 } else {
Joe Perchesd8424f62011-11-18 09:03:06 -08004030 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
4031 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004032 }
4033
4034 return(status);
4035}
4036
4037/*
4038* qla2x00_restart_isp
4039* restarts the ISP after a reset
4040*
4041* Input:
4042* ha = adapter block pointer.
4043*
4044* Returns:
4045* 0 = success
4046*/
4047static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004048qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004049{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004050 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004051 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004052 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004053 struct req_que *req = ha->req_q_map[0];
4054 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004055
4056 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004057 if (qla2x00_isp_firmware(vha)) {
4058 vha->flags.online = 0;
4059 status = ha->isp_ops->chip_diag(vha);
4060 if (!status)
4061 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062 }
4063
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004064 if (!status && !(status = qla2x00_init_rings(vha))) {
4065 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07004066 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004067 /* Initialize the queues in use */
4068 qla25xx_init_queues(ha);
4069
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004070 status = qla2x00_fw_ready(vha);
4071 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004072 ql_dbg(ql_dbg_taskm, vha, 0x8031,
4073 "Start configure loop status = %d.\n", status);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004074
4075 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004076 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004077
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004078 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004079 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4080 wait_time = 256;
4081 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004082 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4083 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004085 } while (!atomic_read(&vha->loop_down_timer) &&
4086 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4087 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4088 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004089 }
4090
4091 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004092 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004093 status = 0;
4094
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004095 ql_dbg(ql_dbg_taskm, vha, 0x8032,
4096 "Configure loop done, status = 0x%x.\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004097 }
4098 return (status);
4099}
4100
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004101static int
4102qla25xx_init_queues(struct qla_hw_data *ha)
4103{
4104 struct rsp_que *rsp = NULL;
4105 struct req_que *req = NULL;
4106 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4107 int ret = -1;
4108 int i;
4109
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004110 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004111 rsp = ha->rsp_q_map[i];
4112 if (rsp) {
4113 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004114 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004115 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004116 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
4117 "%s Rsp que: %d init failed.\n",
4118 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004119 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004120 ql_dbg(ql_dbg_init, base_vha, 0x0100,
4121 "%s Rsp que: %d inited.\n",
4122 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004123 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004124 }
4125 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004126 req = ha->req_q_map[i];
4127 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004128 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004129 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004130 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004131 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004132 ql_dbg(ql_dbg_init, base_vha, 0x0101,
4133 "%s Req que: %d init failed.\n",
4134 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004135 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004136 ql_dbg(ql_dbg_init, base_vha, 0x0102,
4137 "%s Req que: %d inited.\n",
4138 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004139 }
4140 }
4141 return ret;
4142}
4143
Linus Torvalds1da177e2005-04-16 15:20:36 -07004144/*
4145* qla2x00_reset_adapter
4146* Reset adapter.
4147*
4148* Input:
4149* ha = adapter block pointer.
4150*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004151void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004152qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004153{
4154 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004155 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07004156 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004158 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004159 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160
Linus Torvalds1da177e2005-04-16 15:20:36 -07004161 spin_lock_irqsave(&ha->hardware_lock, flags);
4162 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
4163 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4164 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
4165 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4166 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4167}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004168
4169void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004170qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004171{
4172 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004173 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004174 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4175
Giridhar Malavalia9083012010-04-12 17:59:55 -07004176 if (IS_QLA82XX(ha))
4177 return;
4178
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004179 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004180 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004181
4182 spin_lock_irqsave(&ha->hardware_lock, flags);
4183 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
4184 RD_REG_DWORD(&reg->hccr);
4185 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
4186 RD_REG_DWORD(&reg->hccr);
4187 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08004188
4189 if (IS_NOPOLLING_TYPE(ha))
4190 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004191}
4192
David Miller4e08df32007-04-16 12:37:43 -07004193/* On sparc systems, obtain port and node WWN from firmware
4194 * properties.
4195 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004196static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
4197 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07004198{
4199#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004200 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07004201 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07004202 struct device_node *dp = pci_device_to_OF_node(pdev);
4203 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07004204 int len;
4205
4206 val = of_get_property(dp, "port-wwn", &len);
4207 if (val && len >= WWN_SIZE)
4208 memcpy(nv->port_name, val, WWN_SIZE);
4209
4210 val = of_get_property(dp, "node-wwn", &len);
4211 if (val && len >= WWN_SIZE)
4212 memcpy(nv->node_name, val, WWN_SIZE);
4213#endif
4214}
4215
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004216int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004217qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004218{
David Miller4e08df32007-04-16 12:37:43 -07004219 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004220 struct init_cb_24xx *icb;
4221 struct nvram_24xx *nv;
4222 uint32_t *dptr;
4223 uint8_t *dptr1, *dptr2;
4224 uint32_t chksum;
4225 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004226 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004227
David Miller4e08df32007-04-16 12:37:43 -07004228 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004229 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07004230 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004231
4232 /* Determine NVRAM starting address. */
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004233 if (ha->flags.port0) {
4234 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4235 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4236 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004237 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08004238 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4239 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004240 ha->nvram_size = sizeof(struct nvram_24xx);
4241 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004242 if (IS_QLA82XX(ha))
4243 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004244
Seokmann Ju281afe12007-07-26 13:43:34 -07004245 /* Get VPD data into cache */
4246 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004247 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07004248 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4249
4250 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004251 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004252 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004253 ha->nvram_size);
4254 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4255 chksum += le32_to_cpu(*dptr++);
4256
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004257 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
4258 "Contents of NVRAM\n");
4259 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
4260 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004261
4262 /* Bad NVRAM data, set defaults parameters. */
4263 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4264 || nv->id[3] != ' ' ||
4265 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4266 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004267 ql_log(ql_log_warn, vha, 0x006b,
Raul Porcel9e336522012-05-15 14:34:08 -04004268 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004269 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
4270 ql_log(ql_log_warn, vha, 0x006c,
4271 "Falling back to functioning (yet invalid -- WWPN) "
4272 "defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07004273
4274 /*
4275 * Set default initialization control block.
4276 */
4277 memset(nv, 0, ha->nvram_size);
4278 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4279 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4280 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4281 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4282 nv->exchange_count = __constant_cpu_to_le16(0);
4283 nv->hard_address = __constant_cpu_to_le16(124);
4284 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004285 nv->port_name[1] = 0x00 + ha->port_no;
David Miller4e08df32007-04-16 12:37:43 -07004286 nv->port_name[2] = 0x00;
4287 nv->port_name[3] = 0xe0;
4288 nv->port_name[4] = 0x8b;
4289 nv->port_name[5] = 0x1c;
4290 nv->port_name[6] = 0x55;
4291 nv->port_name[7] = 0x86;
4292 nv->node_name[0] = 0x20;
4293 nv->node_name[1] = 0x00;
4294 nv->node_name[2] = 0x00;
4295 nv->node_name[3] = 0xe0;
4296 nv->node_name[4] = 0x8b;
4297 nv->node_name[5] = 0x1c;
4298 nv->node_name[6] = 0x55;
4299 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004300 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07004301 nv->login_retry_count = __constant_cpu_to_le16(8);
4302 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4303 nv->login_timeout = __constant_cpu_to_le16(0);
4304 nv->firmware_options_1 =
4305 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4306 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4307 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4308 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4309 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4310 nv->efi_parameters = __constant_cpu_to_le32(0);
4311 nv->reset_delay = 5;
4312 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4313 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4314 nv->link_down_timeout = __constant_cpu_to_le16(30);
4315
4316 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004317 }
4318
4319 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004320 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004321
4322 /* Copy 1st segment. */
4323 dptr1 = (uint8_t *)icb;
4324 dptr2 = (uint8_t *)&nv->version;
4325 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4326 while (cnt--)
4327 *dptr1++ = *dptr2++;
4328
4329 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07004330 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004331
4332 /* Copy 2nd segment. */
4333 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4334 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4335 cnt = (uint8_t *)&icb->reserved_3 -
4336 (uint8_t *)&icb->interrupt_delay_timer;
4337 while (cnt--)
4338 *dptr1++ = *dptr2++;
4339
4340 /*
4341 * Setup driver NVRAM options.
4342 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004343 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004344 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004345
Andrew Vasquez5341e862006-05-17 15:09:16 -07004346 /* Use alternate WWN? */
4347 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4348 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4349 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4350 }
4351
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004352 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004353 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004354 /*
4355 * Firmware will apply the following mask if the nodename was
4356 * not provided.
4357 */
4358 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4359 icb->node_name[0] &= 0xF0;
4360 }
4361
4362 /* Set host adapter parameters. */
4363 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08004364 ha->flags.enable_lip_reset = 0;
4365 ha->flags.enable_lip_full_login =
4366 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4367 ha->flags.enable_target_reset =
4368 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004369 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004370 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004371
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004372 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4373 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004374
4375 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4376 sizeof(ha->fw_seriallink_options24));
4377
4378 /* save HBA serial number */
4379 ha->serial0 = icb->port_name[5];
4380 ha->serial1 = icb->port_name[6];
4381 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004382 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4383 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004384
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08004385 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4386
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004387 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4388
4389 /* Set minimum login_timeout to 4 seconds. */
4390 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4391 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4392 if (le16_to_cpu(nv->login_timeout) < 4)
4393 nv->login_timeout = __constant_cpu_to_le16(4);
4394 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07004395 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004396
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004397 /* Set minimum RATOV to 100 tenths of a second. */
4398 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004399
4400 ha->loop_reset_delay = nv->reset_delay;
4401
4402 /* Link Down Timeout = 0:
4403 *
4404 * When Port Down timer expires we will start returning
4405 * I/O's to OS with "DID_NO_CONNECT".
4406 *
4407 * Link Down Timeout != 0:
4408 *
4409 * The driver waits for the link to come up after link down
4410 * before returning I/Os to OS with "DID_NO_CONNECT".
4411 */
4412 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4413 ha->loop_down_abort_time =
4414 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4415 } else {
4416 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4417 ha->loop_down_abort_time =
4418 (LOOP_DOWN_TIME - ha->link_down_timeout);
4419 }
4420
4421 /* Need enough time to try and get the port back. */
4422 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4423 if (qlport_down_retry)
4424 ha->port_down_retry_count = qlport_down_retry;
4425
4426 /* Set login_retry_count */
4427 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4428 if (ha->port_down_retry_count ==
4429 le16_to_cpu(nv->port_down_retry_count) &&
4430 ha->port_down_retry_count > 3)
4431 ha->login_retry_count = ha->port_down_retry_count;
4432 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4433 ha->login_retry_count = ha->port_down_retry_count;
4434 if (ql2xloginretrycount)
4435 ha->login_retry_count = ql2xloginretrycount;
4436
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004437 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004438 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004439 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4440 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4441 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4442 le16_to_cpu(icb->interrupt_delay_timer): 2;
4443 }
4444 icb->firmware_options_2 &= __constant_cpu_to_le32(
4445 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004446 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004447 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004448 ha->zio_mode = QLA_ZIO_MODE_6;
4449
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004450 ql_log(ql_log_info, vha, 0x006f,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004451 "ZIO mode %d enabled; timer delay (%d us).\n",
4452 ha->zio_mode, ha->zio_timer * 100);
4453
4454 icb->firmware_options_2 |= cpu_to_le32(
4455 (uint32_t)ha->zio_mode);
4456 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004457 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004458 }
4459
David Miller4e08df32007-04-16 12:37:43 -07004460 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004461 ql_log(ql_log_warn, vha, 0x0070,
4462 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07004463 }
4464 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004465}
4466
Adrian Bunk413975a2006-06-30 02:33:06 -07004467static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004468qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4469 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004470{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004471 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004472 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004473 uint32_t *dcode, dlen;
4474 uint32_t risc_addr;
4475 uint32_t risc_size;
4476 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004477 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004478 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004479
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004480 ql_dbg(ql_dbg_init, vha, 0x008b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08004481 "FW: Loading firmware from flash (%x).\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004482
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004483 rval = QLA_SUCCESS;
4484
4485 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004486 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004487 *srisc_addr = 0;
4488
4489 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004490 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004491 for (i = 0; i < 4; i++)
4492 dcode[i] = be32_to_cpu(dcode[i]);
4493 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4494 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4495 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4496 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004497 ql_log(ql_log_fatal, vha, 0x008c,
4498 "Unable to verify the integrity of flash firmware "
4499 "image.\n");
4500 ql_log(ql_log_fatal, vha, 0x008d,
4501 "Firmware data: %08x %08x %08x %08x.\n",
4502 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004503
4504 return QLA_FUNCTION_FAILED;
4505 }
4506
4507 while (segments && rval == QLA_SUCCESS) {
4508 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004509 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004510
4511 risc_addr = be32_to_cpu(dcode[2]);
4512 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4513 risc_size = be32_to_cpu(dcode[3]);
4514
4515 fragment = 0;
4516 while (risc_size > 0 && rval == QLA_SUCCESS) {
4517 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4518 if (dlen > risc_size)
4519 dlen = risc_size;
4520
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004521 ql_dbg(ql_dbg_init, vha, 0x008e,
4522 "Loading risc segment@ risc addr %x "
4523 "number of dwords 0x%x offset 0x%x.\n",
4524 risc_addr, dlen, faddr);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004525
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004526 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004527 for (i = 0; i < dlen; i++)
4528 dcode[i] = swab32(dcode[i]);
4529
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004530 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004531 dlen);
4532 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004533 ql_log(ql_log_fatal, vha, 0x008f,
4534 "Failed to load segment %d of firmware.\n",
4535 fragment);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004536 break;
4537 }
4538
4539 faddr += dlen;
4540 risc_addr += dlen;
4541 risc_size -= dlen;
4542 fragment++;
4543 }
4544
4545 /* Next segment. */
4546 segments--;
4547 }
4548
4549 return rval;
4550}
4551
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004552#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4553
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004554int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004555qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08004556{
4557 int rval;
4558 int i, fragment;
4559 uint16_t *wcode, *fwcode;
4560 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4561 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004562 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004563 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08004564
4565 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004566 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004567 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004568 ql_log(ql_log_info, vha, 0x0083,
4569 "Fimware image unavailable.\n");
4570 ql_log(ql_log_info, vha, 0x0084,
4571 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08004572 return QLA_FUNCTION_FAILED;
4573 }
4574
4575 rval = QLA_SUCCESS;
4576
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004577 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08004578 *srisc_addr = 0;
4579 fwcode = (uint16_t *)blob->fw->data;
4580 fwclen = 0;
4581
4582 /* Validate firmware image by checking version. */
4583 if (blob->fw->size < 8 * sizeof(uint16_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004584 ql_log(ql_log_fatal, vha, 0x0085,
4585 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08004586 blob->fw->size);
4587 goto fail_fw_integrity;
4588 }
4589 for (i = 0; i < 4; i++)
4590 wcode[i] = be16_to_cpu(fwcode[i + 4]);
4591 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
4592 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
4593 wcode[2] == 0 && wcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004594 ql_log(ql_log_fatal, vha, 0x0086,
4595 "Unable to verify integrity of firmware image.\n");
4596 ql_log(ql_log_fatal, vha, 0x0087,
4597 "Firmware data: %04x %04x %04x %04x.\n",
4598 wcode[0], wcode[1], wcode[2], wcode[3]);
Andrew Vasquez54333832005-11-09 15:49:04 -08004599 goto fail_fw_integrity;
4600 }
4601
4602 seg = blob->segs;
4603 while (*seg && rval == QLA_SUCCESS) {
4604 risc_addr = *seg;
4605 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4606 risc_size = be16_to_cpu(fwcode[3]);
4607
4608 /* Validate firmware image size. */
4609 fwclen += risc_size * sizeof(uint16_t);
4610 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004611 ql_log(ql_log_fatal, vha, 0x0088,
Andrew Vasquez54333832005-11-09 15:49:04 -08004612 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004613 "(%Zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08004614 goto fail_fw_integrity;
4615 }
4616
4617 fragment = 0;
4618 while (risc_size > 0 && rval == QLA_SUCCESS) {
4619 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4620 if (wlen > risc_size)
4621 wlen = risc_size;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004622 ql_dbg(ql_dbg_init, vha, 0x0089,
4623 "Loading risc segment@ risc addr %x number of "
4624 "words 0x%x.\n", risc_addr, wlen);
Andrew Vasquez54333832005-11-09 15:49:04 -08004625
4626 for (i = 0; i < wlen; i++)
4627 wcode[i] = swab16(fwcode[i]);
4628
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004629 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08004630 wlen);
4631 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004632 ql_log(ql_log_fatal, vha, 0x008a,
4633 "Failed to load segment %d of firmware.\n",
4634 fragment);
Andrew Vasquez54333832005-11-09 15:49:04 -08004635 break;
4636 }
4637
4638 fwcode += wlen;
4639 risc_addr += wlen;
4640 risc_size -= wlen;
4641 fragment++;
4642 }
4643
4644 /* Next segment. */
4645 seg++;
4646 }
4647 return rval;
4648
4649fail_fw_integrity:
4650 return QLA_FUNCTION_FAILED;
4651}
4652
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004653static int
4654qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004655{
4656 int rval;
4657 int segments, fragment;
4658 uint32_t *dcode, dlen;
4659 uint32_t risc_addr;
4660 uint32_t risc_size;
4661 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004662 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004663 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004664 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004665 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004666
Andrew Vasquez54333832005-11-09 15:49:04 -08004667 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004668 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004669 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004670 ql_log(ql_log_warn, vha, 0x0090,
4671 "Fimware image unavailable.\n");
4672 ql_log(ql_log_warn, vha, 0x0091,
4673 "Firmware images can be retrieved from: "
4674 QLA_FW_URL ".\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004675
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004676 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004677 }
4678
Chad Dupuiscfb09192011-11-18 09:03:07 -08004679 ql_dbg(ql_dbg_init, vha, 0x0092,
4680 "FW: Loading via request-firmware.\n");
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004681
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004682 rval = QLA_SUCCESS;
4683
4684 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004685 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004686 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004687 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004688 fwclen = 0;
4689
4690 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004691 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004692 ql_log(ql_log_fatal, vha, 0x0093,
4693 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08004694 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004695 goto fail_fw_integrity;
4696 }
4697 for (i = 0; i < 4; i++)
4698 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4699 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4700 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4701 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4702 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004703 ql_log(ql_log_fatal, vha, 0x0094,
4704 "Unable to verify integrity of firmware image (%Zd).\n",
4705 blob->fw->size);
4706 ql_log(ql_log_fatal, vha, 0x0095,
4707 "Firmware data: %08x %08x %08x %08x.\n",
4708 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004709 goto fail_fw_integrity;
4710 }
4711
4712 while (segments && rval == QLA_SUCCESS) {
4713 risc_addr = be32_to_cpu(fwcode[2]);
4714 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4715 risc_size = be32_to_cpu(fwcode[3]);
4716
4717 /* Validate firmware image size. */
4718 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004719 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004720 ql_log(ql_log_fatal, vha, 0x0096,
Andrew Vasquez54333832005-11-09 15:49:04 -08004721 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004722 "(%Zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08004723
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004724 goto fail_fw_integrity;
4725 }
4726
4727 fragment = 0;
4728 while (risc_size > 0 && rval == QLA_SUCCESS) {
4729 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4730 if (dlen > risc_size)
4731 dlen = risc_size;
4732
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004733 ql_dbg(ql_dbg_init, vha, 0x0097,
4734 "Loading risc segment@ risc addr %x "
4735 "number of dwords 0x%x.\n", risc_addr, dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004736
4737 for (i = 0; i < dlen; i++)
4738 dcode[i] = swab32(fwcode[i]);
4739
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004740 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004741 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004742 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004743 ql_log(ql_log_fatal, vha, 0x0098,
4744 "Failed to load segment %d of firmware.\n",
4745 fragment);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004746 break;
4747 }
4748
4749 fwcode += dlen;
4750 risc_addr += dlen;
4751 risc_size -= dlen;
4752 fragment++;
4753 }
4754
4755 /* Next segment. */
4756 segments--;
4757 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004758 return rval;
4759
4760fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004761 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004762}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004763
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004764int
4765qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4766{
4767 int rval;
4768
Andrew Vasqueze337d902009-04-06 22:33:49 -07004769 if (ql2xfwloadbin == 1)
4770 return qla81xx_load_risc(vha, srisc_addr);
4771
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004772 /*
4773 * FW Load priority:
4774 * 1) Firmware via request-firmware interface (.bin file).
4775 * 2) Firmware residing in flash.
4776 */
4777 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4778 if (rval == QLA_SUCCESS)
4779 return rval;
4780
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004781 return qla24xx_load_risc_flash(vha, srisc_addr,
4782 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004783}
4784
4785int
4786qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4787{
4788 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004789 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004790
Andrew Vasqueze337d902009-04-06 22:33:49 -07004791 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004792 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07004793
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004794 /*
4795 * FW Load priority:
4796 * 1) Firmware residing in flash.
4797 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004798 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004799 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004800 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004801 if (rval == QLA_SUCCESS)
4802 return rval;
4803
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004804try_blob_fw:
4805 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4806 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4807 return rval;
4808
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004809 ql_log(ql_log_info, vha, 0x0099,
4810 "Attempting to fallback to golden firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004811 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4812 if (rval != QLA_SUCCESS)
4813 return rval;
4814
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004815 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004816 ha->flags.running_gold_fw = 1;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004817 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004818}
4819
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004820void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004821qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004822{
4823 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004824 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004825
Andrew Vasquez85880802009-12-15 21:29:46 -08004826 if (ha->flags.pci_channel_io_perm_failure)
4827 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07004828 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004829 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004830 if (!ha->fw_major_version)
4831 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004832
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004833 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004834 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07004835 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004836 ha->isp_ops->reset_chip(vha);
4837 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004838 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004839 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004840 continue;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004841 ql_log(ql_log_info, vha, 0x8015,
4842 "Attempting retry of stop-firmware command.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004843 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004844 }
4845}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004846
4847int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004848qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004849{
4850 int rval = QLA_SUCCESS;
Chad Dupuis0b91d112012-02-09 11:15:42 -08004851 int rval2;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004852 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004853 struct qla_hw_data *ha = vha->hw;
4854 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004855 struct req_que *req;
4856 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004857
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004858 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004859 return -EINVAL;
4860
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004861 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07004862 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004863 req = ha->req_q_map[0];
4864 else
4865 req = vha->req;
4866 rsp = req->rsp;
4867
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004868 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004869 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004870 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004871 }
4872
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004873 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004874
4875 /* Login to SNS first */
Chad Dupuis0b91d112012-02-09 11:15:42 -08004876 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
4877 BIT_1);
4878 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
4879 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
4880 ql_dbg(ql_dbg_init, vha, 0x0120,
4881 "Failed SNS login: loop_id=%x, rval2=%d\n",
4882 NPH_SNS, rval2);
4883 else
4884 ql_dbg(ql_dbg_init, vha, 0x0103,
4885 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4886 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
4887 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004888 return (QLA_FUNCTION_FAILED);
4889 }
4890
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004891 atomic_set(&vha->loop_down_timer, 0);
4892 atomic_set(&vha->loop_state, LOOP_UP);
4893 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4894 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4895 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004896
4897 return rval;
4898}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004899
4900/* 84XX Support **************************************************************/
4901
4902static LIST_HEAD(qla_cs84xx_list);
4903static DEFINE_MUTEX(qla_cs84xx_mutex);
4904
4905static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004906qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004907{
4908 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004909 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004910
4911 mutex_lock(&qla_cs84xx_mutex);
4912
4913 /* Find any shared 84xx chip. */
4914 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4915 if (cs84xx->bus == ha->pdev->bus) {
4916 kref_get(&cs84xx->kref);
4917 goto done;
4918 }
4919 }
4920
4921 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4922 if (!cs84xx)
4923 goto done;
4924
4925 kref_init(&cs84xx->kref);
4926 spin_lock_init(&cs84xx->access_lock);
4927 mutex_init(&cs84xx->fw_update_mutex);
4928 cs84xx->bus = ha->pdev->bus;
4929
4930 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4931done:
4932 mutex_unlock(&qla_cs84xx_mutex);
4933 return cs84xx;
4934}
4935
4936static void
4937__qla84xx_chip_release(struct kref *kref)
4938{
4939 struct qla_chip_state_84xx *cs84xx =
4940 container_of(kref, struct qla_chip_state_84xx, kref);
4941
4942 mutex_lock(&qla_cs84xx_mutex);
4943 list_del(&cs84xx->list);
4944 mutex_unlock(&qla_cs84xx_mutex);
4945 kfree(cs84xx);
4946}
4947
4948void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004949qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004950{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004951 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004952 if (ha->cs84xx)
4953 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4954}
4955
4956static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004957qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004958{
4959 int rval;
4960 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004961 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004962
4963 mutex_lock(&ha->cs84xx->fw_update_mutex);
4964
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004965 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004966
4967 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4968
4969 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4970 QLA_SUCCESS;
4971}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004972
4973/* 81XX Support **************************************************************/
4974
4975int
4976qla81xx_nvram_config(scsi_qla_host_t *vha)
4977{
4978 int rval;
4979 struct init_cb_81xx *icb;
4980 struct nvram_81xx *nv;
4981 uint32_t *dptr;
4982 uint8_t *dptr1, *dptr2;
4983 uint32_t chksum;
4984 uint16_t cnt;
4985 struct qla_hw_data *ha = vha->hw;
4986
4987 rval = QLA_SUCCESS;
4988 icb = (struct init_cb_81xx *)ha->init_cb;
4989 nv = ha->nvram;
4990
4991 /* Determine NVRAM starting address. */
4992 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004993 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004994
4995 /* Get VPD data into cache */
4996 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004997 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
4998 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004999
5000 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005001 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005002 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005003 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005004 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
5005 chksum += le32_to_cpu(*dptr++);
5006
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005007 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
5008 "Contents of NVRAM:\n");
5009 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
5010 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005011
5012 /* Bad NVRAM data, set defaults parameters. */
5013 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5014 || nv->id[3] != ' ' ||
5015 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
5016 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005017 ql_log(ql_log_info, vha, 0x0073,
Raul Porcel9e336522012-05-15 14:34:08 -04005018 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005019 "version=0x%x.\n", chksum, nv->id[0],
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005020 le16_to_cpu(nv->nvram_version));
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005021 ql_log(ql_log_info, vha, 0x0074,
5022 "Falling back to functioning (yet invalid -- WWPN) "
5023 "defaults.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005024
5025 /*
5026 * Set default initialization control block.
5027 */
5028 memset(nv, 0, ha->nvram_size);
5029 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
5030 nv->version = __constant_cpu_to_le16(ICB_VERSION);
5031 nv->frame_payload_size = __constant_cpu_to_le16(2048);
5032 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5033 nv->exchange_count = __constant_cpu_to_le16(0);
5034 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005035 nv->port_name[1] = 0x00 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005036 nv->port_name[2] = 0x00;
5037 nv->port_name[3] = 0xe0;
5038 nv->port_name[4] = 0x8b;
5039 nv->port_name[5] = 0x1c;
5040 nv->port_name[6] = 0x55;
5041 nv->port_name[7] = 0x86;
5042 nv->node_name[0] = 0x20;
5043 nv->node_name[1] = 0x00;
5044 nv->node_name[2] = 0x00;
5045 nv->node_name[3] = 0xe0;
5046 nv->node_name[4] = 0x8b;
5047 nv->node_name[5] = 0x1c;
5048 nv->node_name[6] = 0x55;
5049 nv->node_name[7] = 0x86;
5050 nv->login_retry_count = __constant_cpu_to_le16(8);
5051 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
5052 nv->login_timeout = __constant_cpu_to_le16(0);
5053 nv->firmware_options_1 =
5054 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5055 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
5056 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
5057 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
5058 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
5059 nv->efi_parameters = __constant_cpu_to_le32(0);
5060 nv->reset_delay = 5;
5061 nv->max_luns_per_target = __constant_cpu_to_le16(128);
5062 nv->port_down_retry_count = __constant_cpu_to_le16(30);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005063 nv->link_down_timeout = __constant_cpu_to_le16(180);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07005064 nv->enode_mac[0] = 0x00;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005065 nv->enode_mac[1] = 0xC0;
5066 nv->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005067 nv->enode_mac[3] = 0x04;
5068 nv->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005069 nv->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005070
5071 rval = 1;
5072 }
5073
5074 /* Reset Initialization control block */
Andrew Vasquez773120e2011-05-10 11:30:14 -07005075 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005076
5077 /* Copy 1st segment. */
5078 dptr1 = (uint8_t *)icb;
5079 dptr2 = (uint8_t *)&nv->version;
5080 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5081 while (cnt--)
5082 *dptr1++ = *dptr2++;
5083
5084 icb->login_retry_count = nv->login_retry_count;
5085
5086 /* Copy 2nd segment. */
5087 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5088 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5089 cnt = (uint8_t *)&icb->reserved_5 -
5090 (uint8_t *)&icb->interrupt_delay_timer;
5091 while (cnt--)
5092 *dptr1++ = *dptr2++;
5093
5094 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
5095 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5096 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
Andrew Vasquez69e5f1e2012-02-09 11:15:35 -08005097 icb->enode_mac[0] = 0x00;
5098 icb->enode_mac[1] = 0xC0;
5099 icb->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005100 icb->enode_mac[3] = 0x04;
5101 icb->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005102 icb->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005103 }
5104
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07005105 /* Use extended-initialization control block. */
5106 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
5107
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005108 /*
5109 * Setup driver NVRAM options.
5110 */
5111 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07005112 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005113
5114 /* Use alternate WWN? */
5115 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
5116 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5117 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5118 }
5119
5120 /* Prepare nodename */
5121 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
5122 /*
5123 * Firmware will apply the following mask if the nodename was
5124 * not provided.
5125 */
5126 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5127 icb->node_name[0] &= 0xF0;
5128 }
5129
5130 /* Set host adapter parameters. */
5131 ha->flags.disable_risc_code_load = 0;
5132 ha->flags.enable_lip_reset = 0;
5133 ha->flags.enable_lip_full_login =
5134 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5135 ha->flags.enable_target_reset =
5136 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
5137 ha->flags.enable_led_scheme = 0;
5138 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
5139
5140 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5141 (BIT_6 | BIT_5 | BIT_4)) >> 4;
5142
5143 /* save HBA serial number */
5144 ha->serial0 = icb->port_name[5];
5145 ha->serial1 = icb->port_name[6];
5146 ha->serial2 = icb->port_name[7];
5147 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5148 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5149
5150 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5151
5152 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5153
5154 /* Set minimum login_timeout to 4 seconds. */
5155 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5156 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5157 if (le16_to_cpu(nv->login_timeout) < 4)
5158 nv->login_timeout = __constant_cpu_to_le16(4);
5159 ha->login_timeout = le16_to_cpu(nv->login_timeout);
5160 icb->login_timeout = nv->login_timeout;
5161
5162 /* Set minimum RATOV to 100 tenths of a second. */
5163 ha->r_a_tov = 100;
5164
5165 ha->loop_reset_delay = nv->reset_delay;
5166
5167 /* Link Down Timeout = 0:
5168 *
5169 * When Port Down timer expires we will start returning
5170 * I/O's to OS with "DID_NO_CONNECT".
5171 *
5172 * Link Down Timeout != 0:
5173 *
5174 * The driver waits for the link to come up after link down
5175 * before returning I/Os to OS with "DID_NO_CONNECT".
5176 */
5177 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5178 ha->loop_down_abort_time =
5179 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5180 } else {
5181 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5182 ha->loop_down_abort_time =
5183 (LOOP_DOWN_TIME - ha->link_down_timeout);
5184 }
5185
5186 /* Need enough time to try and get the port back. */
5187 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5188 if (qlport_down_retry)
5189 ha->port_down_retry_count = qlport_down_retry;
5190
5191 /* Set login_retry_count */
5192 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5193 if (ha->port_down_retry_count ==
5194 le16_to_cpu(nv->port_down_retry_count) &&
5195 ha->port_down_retry_count > 3)
5196 ha->login_retry_count = ha->port_down_retry_count;
5197 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5198 ha->login_retry_count = ha->port_down_retry_count;
5199 if (ql2xloginretrycount)
5200 ha->login_retry_count = ql2xloginretrycount;
5201
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005202 /* if not running MSI-X we need handshaking on interrupts */
5203 if (!vha->hw->flags.msix_enabled && IS_QLA83XX(ha))
5204 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22);
5205
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005206 /* Enable ZIO. */
5207 if (!vha->flags.init_done) {
5208 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5209 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5210 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5211 le16_to_cpu(icb->interrupt_delay_timer): 2;
5212 }
5213 icb->firmware_options_2 &= __constant_cpu_to_le32(
5214 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
5215 vha->flags.process_response_queue = 0;
5216 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5217 ha->zio_mode = QLA_ZIO_MODE_6;
5218
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005219 ql_log(ql_log_info, vha, 0x0075,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005220 "ZIO mode %d enabled; timer delay (%d us).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005221 ha->zio_mode,
5222 ha->zio_timer * 100);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005223
5224 icb->firmware_options_2 |= cpu_to_le32(
5225 (uint32_t)ha->zio_mode);
5226 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
5227 vha->flags.process_response_queue = 1;
5228 }
5229
5230 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005231 ql_log(ql_log_warn, vha, 0x0076,
5232 "NVRAM configuration failed.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005233 }
5234 return (rval);
5235}
5236
Giridhar Malavalia9083012010-04-12 17:59:55 -07005237int
5238qla82xx_restart_isp(scsi_qla_host_t *vha)
5239{
5240 int status, rval;
5241 uint32_t wait_time;
5242 struct qla_hw_data *ha = vha->hw;
5243 struct req_que *req = ha->req_q_map[0];
5244 struct rsp_que *rsp = ha->rsp_q_map[0];
5245 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07005246 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005247
5248 status = qla2x00_init_rings(vha);
5249 if (!status) {
5250 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5251 ha->flags.chip_reset_done = 1;
5252
5253 status = qla2x00_fw_ready(vha);
5254 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005255 ql_log(ql_log_info, vha, 0x803c,
5256 "Start configure loop, status =%d.\n", status);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005257
5258 /* Issue a marker after FW becomes ready. */
5259 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
5260
5261 vha->flags.online = 1;
5262 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5263 wait_time = 256;
5264 do {
5265 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5266 qla2x00_configure_loop(vha);
5267 wait_time--;
5268 } while (!atomic_read(&vha->loop_down_timer) &&
5269 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
5270 wait_time &&
5271 (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
5272 }
5273
5274 /* if no cable then assume it's good */
5275 if ((vha->device_flags & DFLG_NO_CABLE))
5276 status = 0;
5277
Chad Dupuiscfb09192011-11-18 09:03:07 -08005278 ql_log(ql_log_info, vha, 0x8000,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005279 "Configure loop done, status = 0x%x.\n", status);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005280 }
5281
5282 if (!status) {
5283 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5284
5285 if (!atomic_read(&vha->loop_down_timer)) {
5286 /*
5287 * Issue marker command only when we are going
5288 * to start the I/O .
5289 */
5290 vha->marker_needed = 1;
5291 }
5292
5293 vha->flags.online = 1;
5294
5295 ha->isp_ops->enable_intrs(ha);
5296
5297 ha->isp_abort_cnt = 0;
5298 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5299
Saurav Kashyap53296782011-05-10 11:30:06 -07005300 /* Update the firmware version */
Giridhar Malavali31731672011-08-16 11:31:54 -07005301 status = qla82xx_check_md_needed(vha);
Saurav Kashyap53296782011-05-10 11:30:06 -07005302
Giridhar Malavalia9083012010-04-12 17:59:55 -07005303 if (ha->fce) {
5304 ha->flags.fce_enabled = 1;
5305 memset(ha->fce, 0,
5306 fce_calc_size(ha->fce_bufs));
5307 rval = qla2x00_enable_fce_trace(vha,
5308 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5309 &ha->fce_bufs);
5310 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08005311 ql_log(ql_log_warn, vha, 0x8001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005312 "Unable to reinitialize FCE (%d).\n",
5313 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005314 ha->flags.fce_enabled = 0;
5315 }
5316 }
5317
5318 if (ha->eft) {
5319 memset(ha->eft, 0, EFT_SIZE);
5320 rval = qla2x00_enable_eft_trace(vha,
5321 ha->eft_dma, EFT_NUM_BUFFERS);
5322 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08005323 ql_log(ql_log_warn, vha, 0x8010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005324 "Unable to reinitialize EFT (%d).\n",
5325 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005326 }
5327 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005328 }
5329
5330 if (!status) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08005331 ql_dbg(ql_dbg_taskm, vha, 0x8011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005332 "qla82xx_restart_isp succeeded.\n");
Arun Easifeafb7b2010-09-03 14:57:00 -07005333
5334 spin_lock_irqsave(&ha->vport_slock, flags);
5335 list_for_each_entry(vp, &ha->vp_list, list) {
5336 if (vp->vp_idx) {
5337 atomic_inc(&vp->vref_count);
5338 spin_unlock_irqrestore(&ha->vport_slock, flags);
5339
Giridhar Malavalia9083012010-04-12 17:59:55 -07005340 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07005341
5342 spin_lock_irqsave(&ha->vport_slock, flags);
5343 atomic_dec(&vp->vref_count);
5344 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005345 }
Arun Easifeafb7b2010-09-03 14:57:00 -07005346 spin_unlock_irqrestore(&ha->vport_slock, flags);
5347
Giridhar Malavalia9083012010-04-12 17:59:55 -07005348 } else {
Chad Dupuiscfb09192011-11-18 09:03:07 -08005349 ql_log(ql_log_warn, vha, 0x8016,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005350 "qla82xx_restart_isp **** FAILED ****.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005351 }
5352
5353 return status;
5354}
5355
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005356void
Andrew Vasquezae97c912010-02-18 10:07:28 -08005357qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005358{
Andrew Vasquezae97c912010-02-18 10:07:28 -08005359 struct qla_hw_data *ha = vha->hw;
5360
5361 if (!ql2xetsenable)
5362 return;
5363
5364 /* Enable ETS Burst. */
5365 memset(ha->fw_options, 0, sizeof(ha->fw_options));
5366 ha->fw_options[2] |= BIT_9;
5367 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005368}
Sarang Radke09ff7012010-03-19 17:03:59 -07005369
5370/*
5371 * qla24xx_get_fcp_prio
5372 * Gets the fcp cmd priority value for the logged in port.
5373 * Looks for a match of the port descriptors within
5374 * each of the fcp prio config entries. If a match is found,
5375 * the tag (priority) value is returned.
5376 *
5377 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005378 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07005379 * fcport = port structure pointer.
5380 *
5381 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07005382 * non-zero (if found)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005383 * -1 (if not found)
Sarang Radke09ff7012010-03-19 17:03:59 -07005384 *
5385 * Context:
5386 * Kernel context
5387 */
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005388static int
Sarang Radke09ff7012010-03-19 17:03:59 -07005389qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
5390{
5391 int i, entries;
5392 uint8_t pid_match, wwn_match;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005393 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07005394 uint32_t pid1, pid2;
5395 uint64_t wwn1, wwn2;
5396 struct qla_fcp_prio_entry *pri_entry;
5397 struct qla_hw_data *ha = vha->hw;
5398
5399 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005400 return -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07005401
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005402 priority = -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07005403 entries = ha->fcp_prio_cfg->num_entries;
5404 pri_entry = &ha->fcp_prio_cfg->entry[0];
5405
5406 for (i = 0; i < entries; i++) {
5407 pid_match = wwn_match = 0;
5408
5409 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
5410 pri_entry++;
5411 continue;
5412 }
5413
5414 /* check source pid for a match */
5415 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
5416 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
5417 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
5418 if (pid1 == INVALID_PORT_ID)
5419 pid_match++;
5420 else if (pid1 == pid2)
5421 pid_match++;
5422 }
5423
5424 /* check destination pid for a match */
5425 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
5426 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
5427 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
5428 if (pid1 == INVALID_PORT_ID)
5429 pid_match++;
5430 else if (pid1 == pid2)
5431 pid_match++;
5432 }
5433
5434 /* check source WWN for a match */
5435 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
5436 wwn1 = wwn_to_u64(vha->port_name);
5437 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
5438 if (wwn2 == (uint64_t)-1)
5439 wwn_match++;
5440 else if (wwn1 == wwn2)
5441 wwn_match++;
5442 }
5443
5444 /* check destination WWN for a match */
5445 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
5446 wwn1 = wwn_to_u64(fcport->port_name);
5447 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
5448 if (wwn2 == (uint64_t)-1)
5449 wwn_match++;
5450 else if (wwn1 == wwn2)
5451 wwn_match++;
5452 }
5453
5454 if (pid_match == 2 || wwn_match == 2) {
5455 /* Found a matching entry */
5456 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
5457 priority = pri_entry->tag;
5458 break;
5459 }
5460
5461 pri_entry++;
5462 }
5463
5464 return priority;
5465}
5466
5467/*
5468 * qla24xx_update_fcport_fcp_prio
5469 * Activates fcp priority for the logged in fc port
5470 *
5471 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005472 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07005473 * fcp = port structure pointer.
5474 *
5475 * Return:
5476 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5477 *
5478 * Context:
5479 * Kernel context.
5480 */
5481int
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005482qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
Sarang Radke09ff7012010-03-19 17:03:59 -07005483{
5484 int ret;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005485 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07005486 uint16_t mb[5];
5487
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005488 if (fcport->port_type != FCT_TARGET ||
5489 fcport->loop_id == FC_NO_LOOP_ID)
Sarang Radke09ff7012010-03-19 17:03:59 -07005490 return QLA_FUNCTION_FAILED;
5491
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005492 priority = qla24xx_get_fcp_prio(vha, fcport);
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005493 if (priority < 0)
5494 return QLA_FUNCTION_FAILED;
5495
Saurav Kashyapa00f6292011-11-18 09:03:19 -08005496 if (IS_QLA82XX(vha->hw)) {
5497 fcport->fcp_prio = priority & 0xf;
5498 return QLA_SUCCESS;
5499 }
5500
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005501 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
Chad Dupuiscfb09192011-11-18 09:03:07 -08005502 if (ret == QLA_SUCCESS) {
5503 if (fcport->fcp_prio != priority)
5504 ql_dbg(ql_dbg_user, vha, 0x709e,
5505 "Updated FCP_CMND priority - value=%d loop_id=%d "
5506 "port_id=%02x%02x%02x.\n", priority,
5507 fcport->loop_id, fcport->d_id.b.domain,
5508 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Saurav Kashyapa00f6292011-11-18 09:03:19 -08005509 fcport->fcp_prio = priority & 0xf;
Chad Dupuiscfb09192011-11-18 09:03:07 -08005510 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005511 ql_dbg(ql_dbg_user, vha, 0x704f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08005512 "Unable to update FCP_CMND priority - ret=0x%x for "
5513 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
5514 fcport->d_id.b.domain, fcport->d_id.b.area,
5515 fcport->d_id.b.al_pa);
Sarang Radke09ff7012010-03-19 17:03:59 -07005516 return ret;
5517}
5518
5519/*
5520 * qla24xx_update_all_fcp_prio
5521 * Activates fcp priority for all the logged in ports
5522 *
5523 * Input:
5524 * ha = adapter block pointer.
5525 *
5526 * Return:
5527 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5528 *
5529 * Context:
5530 * Kernel context.
5531 */
5532int
5533qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
5534{
5535 int ret;
5536 fc_port_t *fcport;
5537
5538 ret = QLA_FUNCTION_FAILED;
5539 /* We need to set priority for all logged in ports */
5540 list_for_each_entry(fcport, &vha->vp_fcports, list)
5541 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
5542
5543 return ret;
5544}