Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 2 | * QLogic Fibre Channel HBA Driver |
Armen Baloyan | bd21eaf | 2014-04-11 16:54:24 -0400 | [diff] [blame] | 3 | * Copyright (c) 2003-2014 QLogic Corporation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | #include "qla_def.h" |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 8 | #include "qla_gbl.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
| 10 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 11 | #include <linux/slab.h> |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 12 | #include <linux/vmalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
| 14 | #include "qla_devtbl.h" |
| 15 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 16 | #ifdef CONFIG_SPARC |
| 17 | #include <asm/prom.h> |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 18 | #endif |
| 19 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 20 | #include <target/target_core_base.h> |
| 21 | #include "qla_target.h" |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | /* |
| 24 | * QLogic ISP2x00 Hardware Support Function Prototypes. |
| 25 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | static int qla2x00_isp_firmware(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | static int qla2x00_setup_chip(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | static int qla2x00_fw_ready(scsi_qla_host_t *); |
| 29 | static int qla2x00_configure_hba(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | static int qla2x00_configure_loop(scsi_qla_host_t *); |
| 31 | static int qla2x00_configure_local_loop(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | static int qla2x00_configure_fabric(scsi_qla_host_t *); |
| 33 | static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *, |
| 35 | uint16_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | static int qla2x00_restart_isp(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 39 | static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *); |
| 40 | static int qla84xx_init_chip(scsi_qla_host_t *); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 41 | static int qla25xx_init_queues(struct qla_hw_data *); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 42 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 43 | /* SRB Extensions ---------------------------------------------------------- */ |
| 44 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 45 | void |
| 46 | qla2x00_sp_timeout(unsigned long __data) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 47 | { |
| 48 | srb_t *sp = (srb_t *)__data; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 49 | struct srb_iocb *iocb; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 50 | fc_port_t *fcport = sp->fcport; |
| 51 | struct qla_hw_data *ha = fcport->vha->hw; |
| 52 | struct req_que *req; |
| 53 | unsigned long flags; |
| 54 | |
| 55 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 56 | req = ha->req_q_map[0]; |
| 57 | req->outstanding_cmds[sp->handle] = NULL; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 58 | iocb = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 59 | iocb->timeout(sp); |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 60 | sp->free(fcport->vha, sp); |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 61 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 64 | void |
| 65 | qla2x00_sp_free(void *data, void *ptr) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 66 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 67 | srb_t *sp = (srb_t *)ptr; |
| 68 | struct srb_iocb *iocb = &sp->u.iocb_cmd; |
| 69 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 70 | |
Chad Dupuis | 4d97cc5 | 2010-10-15 11:27:41 -0700 | [diff] [blame] | 71 | del_timer(&iocb->timer); |
Chad Dupuis | b00ee7d | 2013-02-08 01:57:50 -0500 | [diff] [blame] | 72 | qla2x00_rel_sp(vha, sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 75 | /* Asynchronous Login/Logout Routines -------------------------------------- */ |
| 76 | |
Saurav Kashyap | a9b6f72 | 2012-08-22 14:21:01 -0400 | [diff] [blame] | 77 | unsigned long |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 78 | qla2x00_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; |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 85 | if (IS_QLAFX00(ha)) { |
| 86 | tmo = FX00_DEF_RATOV * 2; |
| 87 | } else if (!IS_FWI2_CAPABLE(ha)) { |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 88 | /* |
| 89 | * Except for earlier ISPs where the timeout is seeded from the |
| 90 | * initialization control block. |
| 91 | */ |
| 92 | tmo = ha->login_timeout; |
| 93 | } |
| 94 | return tmo; |
| 95 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 96 | |
| 97 | static void |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 98 | qla2x00_async_iocb_timeout(void *data) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 99 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 100 | srb_t *sp = (srb_t *)data; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 101 | fc_port_t *fcport = sp->fcport; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 102 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 103 | ql_dbg(ql_dbg_disc, fcport->vha, 0x2071, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 104 | "Async-%s timeout - hdl=%x portid=%02x%02x%02x.\n", |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 105 | sp->name, sp->handle, fcport->d_id.b.domain, fcport->d_id.b.area, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 106 | fcport->d_id.b.al_pa); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 107 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 108 | fcport->flags &= ~FCF_ASYNC_SENT; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 109 | if (sp->type == SRB_LOGIN_CMD) { |
| 110 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 111 | qla2x00_post_async_logout_work(fcport->vha, fcport, NULL); |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 112 | /* Retry as needed. */ |
| 113 | lio->u.logio.data[0] = MBS_COMMAND_ERROR; |
| 114 | lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ? |
| 115 | QLA_LOGIO_LOGIN_RETRIED : 0; |
| 116 | qla2x00_post_async_login_done_work(fcport->vha, fcport, |
| 117 | lio->u.logio.data); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 118 | } else if (sp->type == SRB_LOGOUT_CMD) { |
| 119 | qlt_logo_completion_handler(fcport, QLA_FUNCTION_TIMEOUT); |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 120 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 123 | static void |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 124 | qla2x00_async_login_sp_done(void *data, void *ptr, int res) |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 125 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 126 | srb_t *sp = (srb_t *)ptr; |
| 127 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
| 128 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 129 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 130 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
| 131 | qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport, |
| 132 | lio->u.logio.data); |
| 133 | sp->free(sp->fcport->vha, sp); |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 136 | int |
| 137 | qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 138 | uint16_t *data) |
| 139 | { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 140 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 141 | struct srb_iocb *lio; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 142 | int rval; |
| 143 | |
| 144 | rval = QLA_FUNCTION_FAILED; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 145 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 146 | if (!sp) |
| 147 | goto done; |
| 148 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 149 | sp->type = SRB_LOGIN_CMD; |
| 150 | sp->name = "login"; |
| 151 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 152 | |
| 153 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 154 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 155 | sp->done = qla2x00_async_login_sp_done; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 156 | lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 157 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 158 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 159 | rval = qla2x00_start_sp(sp); |
Chad Dupuis | 080c951 | 2016-01-27 12:03:37 -0500 | [diff] [blame^] | 160 | if (rval != QLA_SUCCESS) { |
| 161 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 162 | fcport->flags |= FCF_LOGIN_NEEDED; |
| 163 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 164 | goto done_free_sp; |
Chad Dupuis | 080c951 | 2016-01-27 12:03:37 -0500 | [diff] [blame^] | 165 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 166 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 167 | ql_dbg(ql_dbg_disc, vha, 0x2072, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 168 | "Async-login - hdl=%x, loopid=%x portid=%02x%02x%02x " |
| 169 | "retries=%d.\n", sp->handle, fcport->loop_id, |
| 170 | fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 171 | fcport->login_retry); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 172 | return rval; |
| 173 | |
| 174 | done_free_sp: |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 175 | sp->free(fcport->vha, sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 176 | done: |
| 177 | return rval; |
| 178 | } |
| 179 | |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 180 | static void |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 181 | qla2x00_async_logout_sp_done(void *data, void *ptr, int res) |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 182 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 183 | srb_t *sp = (srb_t *)ptr; |
| 184 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
| 185 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 186 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 187 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
| 188 | qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport, |
| 189 | lio->u.logio.data); |
| 190 | sp->free(sp->fcport->vha, sp); |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 193 | int |
| 194 | qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 195 | { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 196 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 197 | struct srb_iocb *lio; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 198 | int rval; |
| 199 | |
| 200 | rval = QLA_FUNCTION_FAILED; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 201 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 202 | if (!sp) |
| 203 | goto done; |
| 204 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 205 | sp->type = SRB_LOGOUT_CMD; |
| 206 | sp->name = "logout"; |
| 207 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 208 | |
| 209 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 210 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 211 | sp->done = qla2x00_async_logout_sp_done; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 212 | rval = qla2x00_start_sp(sp); |
| 213 | if (rval != QLA_SUCCESS) |
| 214 | goto done_free_sp; |
| 215 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 216 | ql_dbg(ql_dbg_disc, vha, 0x2070, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 217 | "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x.\n", |
| 218 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
| 219 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 220 | return rval; |
| 221 | |
| 222 | done_free_sp: |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 223 | sp->free(fcport->vha, sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 224 | done: |
| 225 | return rval; |
| 226 | } |
| 227 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 228 | static void |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 229 | qla2x00_async_adisc_sp_done(void *data, void *ptr, int res) |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 230 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 231 | srb_t *sp = (srb_t *)ptr; |
| 232 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
| 233 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 234 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 235 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
| 236 | qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport, |
| 237 | lio->u.logio.data); |
| 238 | sp->free(sp->fcport->vha, sp); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | int |
| 242 | qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 243 | uint16_t *data) |
| 244 | { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 245 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 246 | struct srb_iocb *lio; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 247 | int rval; |
| 248 | |
| 249 | rval = QLA_FUNCTION_FAILED; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 250 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 251 | if (!sp) |
| 252 | goto done; |
| 253 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 254 | sp->type = SRB_ADISC_CMD; |
| 255 | sp->name = "adisc"; |
| 256 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 257 | |
| 258 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 259 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 260 | sp->done = qla2x00_async_adisc_sp_done; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 261 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 262 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 263 | rval = qla2x00_start_sp(sp); |
| 264 | if (rval != QLA_SUCCESS) |
| 265 | goto done_free_sp; |
| 266 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 267 | ql_dbg(ql_dbg_disc, vha, 0x206f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 268 | "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n", |
| 269 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
| 270 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 271 | return rval; |
| 272 | |
| 273 | done_free_sp: |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 274 | sp->free(fcport->vha, sp); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 275 | done: |
| 276 | return rval; |
| 277 | } |
| 278 | |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 279 | static void |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 280 | qla2x00_tmf_iocb_timeout(void *data) |
| 281 | { |
| 282 | srb_t *sp = (srb_t *)data; |
| 283 | struct srb_iocb *tmf = &sp->u.iocb_cmd; |
| 284 | |
| 285 | tmf->u.tmf.comp_status = CS_TIMEOUT; |
| 286 | complete(&tmf->u.tmf.comp); |
| 287 | } |
| 288 | |
| 289 | static void |
| 290 | qla2x00_tmf_sp_done(void *data, void *ptr, int res) |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 291 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 292 | srb_t *sp = (srb_t *)ptr; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 293 | struct srb_iocb *tmf = &sp->u.iocb_cmd; |
| 294 | complete(&tmf->u.tmf.comp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | int |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 298 | qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun, |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 299 | uint32_t tag) |
| 300 | { |
| 301 | struct scsi_qla_host *vha = fcport->vha; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 302 | struct srb_iocb *tm_iocb; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 303 | srb_t *sp; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 304 | int rval = QLA_FUNCTION_FAILED; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 305 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 306 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 307 | if (!sp) |
| 308 | goto done; |
| 309 | |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 310 | tm_iocb = &sp->u.iocb_cmd; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 311 | sp->type = SRB_TM_CMD; |
| 312 | sp->name = "tmf"; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 313 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)); |
| 314 | tm_iocb->u.tmf.flags = flags; |
| 315 | tm_iocb->u.tmf.lun = lun; |
| 316 | tm_iocb->u.tmf.data = tag; |
| 317 | sp->done = qla2x00_tmf_sp_done; |
| 318 | tm_iocb->timeout = qla2x00_tmf_iocb_timeout; |
| 319 | init_completion(&tm_iocb->u.tmf.comp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 320 | |
| 321 | rval = qla2x00_start_sp(sp); |
| 322 | if (rval != QLA_SUCCESS) |
| 323 | goto done_free_sp; |
| 324 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 325 | ql_dbg(ql_dbg_taskm, vha, 0x802f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 326 | "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n", |
| 327 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
| 328 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 329 | |
| 330 | wait_for_completion(&tm_iocb->u.tmf.comp); |
| 331 | |
| 332 | rval = tm_iocb->u.tmf.comp_status == CS_COMPLETE ? |
| 333 | QLA_SUCCESS : QLA_FUNCTION_FAILED; |
| 334 | |
| 335 | if ((rval != QLA_SUCCESS) || tm_iocb->u.tmf.data) { |
| 336 | ql_dbg(ql_dbg_taskm, vha, 0x8030, |
| 337 | "TM IOCB failed (%x).\n", rval); |
| 338 | } |
| 339 | |
| 340 | if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) { |
| 341 | flags = tm_iocb->u.tmf.flags; |
| 342 | lun = (uint16_t)tm_iocb->u.tmf.lun; |
| 343 | |
| 344 | /* Issue Marker IOCB */ |
| 345 | qla2x00_marker(vha, vha->hw->req_q_map[0], |
| 346 | vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun, |
| 347 | flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID); |
| 348 | } |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 349 | |
| 350 | done_free_sp: |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 351 | sp->free(vha, sp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 352 | done: |
| 353 | return rval; |
| 354 | } |
| 355 | |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 356 | static void |
| 357 | qla24xx_abort_iocb_timeout(void *data) |
| 358 | { |
| 359 | srb_t *sp = (srb_t *)data; |
| 360 | struct srb_iocb *abt = &sp->u.iocb_cmd; |
| 361 | |
| 362 | abt->u.abt.comp_status = CS_TIMEOUT; |
| 363 | complete(&abt->u.abt.comp); |
| 364 | } |
| 365 | |
| 366 | static void |
| 367 | qla24xx_abort_sp_done(void *data, void *ptr, int res) |
| 368 | { |
| 369 | srb_t *sp = (srb_t *)ptr; |
| 370 | struct srb_iocb *abt = &sp->u.iocb_cmd; |
| 371 | |
| 372 | complete(&abt->u.abt.comp); |
| 373 | } |
| 374 | |
| 375 | static int |
| 376 | qla24xx_async_abort_cmd(srb_t *cmd_sp) |
| 377 | { |
| 378 | scsi_qla_host_t *vha = cmd_sp->fcport->vha; |
| 379 | fc_port_t *fcport = cmd_sp->fcport; |
| 380 | struct srb_iocb *abt_iocb; |
| 381 | srb_t *sp; |
| 382 | int rval = QLA_FUNCTION_FAILED; |
| 383 | |
| 384 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 385 | if (!sp) |
| 386 | goto done; |
| 387 | |
| 388 | abt_iocb = &sp->u.iocb_cmd; |
| 389 | sp->type = SRB_ABT_CMD; |
| 390 | sp->name = "abort"; |
| 391 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)); |
| 392 | abt_iocb->u.abt.cmd_hndl = cmd_sp->handle; |
| 393 | sp->done = qla24xx_abort_sp_done; |
| 394 | abt_iocb->timeout = qla24xx_abort_iocb_timeout; |
| 395 | init_completion(&abt_iocb->u.abt.comp); |
| 396 | |
| 397 | rval = qla2x00_start_sp(sp); |
| 398 | if (rval != QLA_SUCCESS) |
| 399 | goto done_free_sp; |
| 400 | |
| 401 | ql_dbg(ql_dbg_async, vha, 0x507c, |
| 402 | "Abort command issued - hdl=%x, target_id=%x\n", |
| 403 | cmd_sp->handle, fcport->tgt_id); |
| 404 | |
| 405 | wait_for_completion(&abt_iocb->u.abt.comp); |
| 406 | |
| 407 | rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ? |
| 408 | QLA_SUCCESS : QLA_FUNCTION_FAILED; |
| 409 | |
| 410 | done_free_sp: |
| 411 | sp->free(vha, sp); |
| 412 | done: |
| 413 | return rval; |
| 414 | } |
| 415 | |
| 416 | int |
| 417 | qla24xx_async_abort_command(srb_t *sp) |
| 418 | { |
| 419 | unsigned long flags = 0; |
| 420 | |
| 421 | uint32_t handle; |
| 422 | fc_port_t *fcport = sp->fcport; |
| 423 | struct scsi_qla_host *vha = fcport->vha; |
| 424 | struct qla_hw_data *ha = vha->hw; |
| 425 | struct req_que *req = vha->req; |
| 426 | |
| 427 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 428 | for (handle = 1; handle < req->num_outstanding_cmds; handle++) { |
| 429 | if (req->outstanding_cmds[handle] == sp) |
| 430 | break; |
| 431 | } |
| 432 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 433 | if (handle == req->num_outstanding_cmds) { |
| 434 | /* Command not found. */ |
| 435 | return QLA_FUNCTION_FAILED; |
| 436 | } |
| 437 | if (sp->type == SRB_FXIOCB_DCMD) |
| 438 | return qlafx00_fx_disc(vha, &vha->hw->mr.fcport, |
| 439 | FXDISC_ABORT_IOCTL); |
| 440 | |
| 441 | return qla24xx_async_abort_cmd(sp); |
| 442 | } |
| 443 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 444 | void |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 445 | qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 446 | uint16_t *data) |
| 447 | { |
| 448 | int rval; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 449 | |
| 450 | switch (data[0]) { |
| 451 | case MBS_COMMAND_COMPLETE: |
Andrew Vasquez | a4f92a3 | 2011-03-30 11:46:31 -0700 | [diff] [blame] | 452 | /* |
| 453 | * Driver must validate login state - If PRLI not complete, |
| 454 | * force a relogin attempt via implicit LOGO, PLOGI, and PRLI |
| 455 | * requests. |
| 456 | */ |
| 457 | rval = qla2x00_get_port_database(vha, fcport, 0); |
Arun Easi | 0eba25d | 2012-02-09 11:15:58 -0800 | [diff] [blame] | 458 | if (rval == QLA_NOT_LOGGED_IN) { |
| 459 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 460 | fcport->flags |= FCF_LOGIN_NEEDED; |
| 461 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 462 | break; |
| 463 | } |
| 464 | |
Andrew Vasquez | a4f92a3 | 2011-03-30 11:46:31 -0700 | [diff] [blame] | 465 | if (rval != QLA_SUCCESS) { |
| 466 | qla2x00_post_async_logout_work(vha, fcport, NULL); |
| 467 | qla2x00_post_async_login_work(vha, fcport, NULL); |
| 468 | break; |
| 469 | } |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 470 | if (fcport->flags & FCF_FCP2_DEVICE) { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 471 | qla2x00_post_async_adisc_work(vha, fcport, data); |
| 472 | break; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 473 | } |
| 474 | qla2x00_update_fcport(vha, fcport); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 475 | break; |
| 476 | case MBS_COMMAND_ERROR: |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 477 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 478 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
| 479 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 480 | else |
Andrew Vasquez | 80d7944 | 2011-03-30 11:46:17 -0700 | [diff] [blame] | 481 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 482 | break; |
| 483 | case MBS_PORT_ID_USED: |
| 484 | fcport->loop_id = data[1]; |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 485 | qla2x00_post_async_logout_work(vha, fcport, NULL); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 486 | qla2x00_post_async_login_work(vha, fcport, NULL); |
| 487 | break; |
| 488 | case MBS_LOOP_ID_USED: |
| 489 | fcport->loop_id++; |
| 490 | rval = qla2x00_find_new_loop_id(vha, fcport); |
| 491 | if (rval != QLA_SUCCESS) { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 492 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | 80d7944 | 2011-03-30 11:46:17 -0700 | [diff] [blame] | 493 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 494 | break; |
| 495 | } |
| 496 | qla2x00_post_async_login_work(vha, fcport, NULL); |
| 497 | break; |
| 498 | } |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 499 | return; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 500 | } |
| 501 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 502 | void |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 503 | qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 504 | uint16_t *data) |
| 505 | { |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 506 | /* Don't re-login in target mode */ |
| 507 | if (!fcport->tgt_session) |
| 508 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
| 509 | qlt_logo_completion_handler(fcport, data[0]); |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 510 | return; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 511 | } |
| 512 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 513 | void |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 514 | qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 515 | uint16_t *data) |
| 516 | { |
| 517 | if (data[0] == MBS_COMMAND_COMPLETE) { |
| 518 | qla2x00_update_fcport(vha, fcport); |
| 519 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 520 | return; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | /* Retry login. */ |
| 524 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 525 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
| 526 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 527 | else |
Andrew Vasquez | 80d7944 | 2011-03-30 11:46:17 -0700 | [diff] [blame] | 528 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 529 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 530 | return; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | /****************************************************************************/ |
| 534 | /* QLogic ISP2x00 Hardware Support Functions. */ |
| 535 | /****************************************************************************/ |
| 536 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 537 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 538 | qla83xx_nic_core_fw_load(scsi_qla_host_t *vha) |
| 539 | { |
| 540 | int rval = QLA_SUCCESS; |
| 541 | struct qla_hw_data *ha = vha->hw; |
| 542 | uint32_t idc_major_ver, idc_minor_ver; |
Saurav Kashyap | 711aa7f | 2012-08-22 14:21:15 -0400 | [diff] [blame] | 543 | uint16_t config[4]; |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 544 | |
| 545 | qla83xx_idc_lock(vha, 0); |
| 546 | |
| 547 | /* SV: TODO: Assign initialization timeout from |
| 548 | * flash-info / other param |
| 549 | */ |
| 550 | ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT; |
| 551 | ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT; |
| 552 | |
| 553 | /* Set our fcoe function presence */ |
| 554 | if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) { |
| 555 | ql_dbg(ql_dbg_p3p, vha, 0xb077, |
| 556 | "Error while setting DRV-Presence.\n"); |
| 557 | rval = QLA_FUNCTION_FAILED; |
| 558 | goto exit; |
| 559 | } |
| 560 | |
| 561 | /* Decide the reset ownership */ |
| 562 | qla83xx_reset_ownership(vha); |
| 563 | |
| 564 | /* |
| 565 | * On first protocol driver load: |
| 566 | * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery |
| 567 | * register. |
| 568 | * Others: Check compatibility with current IDC Major version. |
| 569 | */ |
| 570 | qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver); |
| 571 | if (ha->flags.nic_core_reset_owner) { |
| 572 | /* Set IDC Major version */ |
| 573 | idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION; |
| 574 | qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver); |
| 575 | |
| 576 | /* Clearing IDC-Lock-Recovery register */ |
| 577 | qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0); |
| 578 | } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) { |
| 579 | /* |
| 580 | * Clear further IDC participation if we are not compatible with |
| 581 | * the current IDC Major Version. |
| 582 | */ |
| 583 | ql_log(ql_log_warn, vha, 0xb07d, |
| 584 | "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n", |
| 585 | idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION); |
| 586 | __qla83xx_clear_drv_presence(vha); |
| 587 | rval = QLA_FUNCTION_FAILED; |
| 588 | goto exit; |
| 589 | } |
| 590 | /* Each function sets its supported Minor version. */ |
| 591 | qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver); |
| 592 | idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2)); |
| 593 | qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver); |
| 594 | |
Saurav Kashyap | 711aa7f | 2012-08-22 14:21:15 -0400 | [diff] [blame] | 595 | if (ha->flags.nic_core_reset_owner) { |
| 596 | memset(config, 0, sizeof(config)); |
| 597 | if (!qla81xx_get_port_config(vha, config)) |
| 598 | qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, |
| 599 | QLA8XXX_DEV_READY); |
| 600 | } |
| 601 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 602 | rval = qla83xx_idc_state_handler(vha); |
| 603 | |
| 604 | exit: |
| 605 | qla83xx_idc_unlock(vha, 0); |
| 606 | |
| 607 | return rval; |
| 608 | } |
| 609 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | /* |
| 611 | * qla2x00_initialize_adapter |
| 612 | * Initialize board. |
| 613 | * |
| 614 | * Input: |
| 615 | * ha = adapter block pointer. |
| 616 | * |
| 617 | * Returns: |
| 618 | * 0 = success |
| 619 | */ |
| 620 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 621 | qla2x00_initialize_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | { |
| 623 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 624 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 625 | struct req_que *req = ha->req_q_map[0]; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 626 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | /* Clear adapter flags. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 628 | vha->flags.online = 0; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 629 | ha->flags.chip_reset_done = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 630 | vha->flags.reset_active = 0; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 631 | ha->flags.pci_channel_io_perm_failure = 0; |
| 632 | ha->flags.eeh_busy = 0; |
Joe Carnuccio | fabbb8d | 2013-08-27 01:37:40 -0400 | [diff] [blame] | 633 | vha->qla_stats.jiffies_at_last_reset = get_jiffies_64(); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 634 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 635 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 636 | vha->device_flags = DFLG_NO_CABLE; |
| 637 | vha->dpc_flags = 0; |
| 638 | vha->flags.management_server_logged_in = 0; |
| 639 | vha->marker_needed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | ha->isp_abort_cnt = 0; |
| 641 | ha->beacon_blink_led = 0; |
| 642 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 643 | set_bit(0, ha->req_qid_map); |
| 644 | set_bit(0, ha->rsp_qid_map); |
| 645 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 646 | ql_dbg(ql_dbg_init, vha, 0x0040, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 647 | "Configuring PCI space...\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 648 | rval = ha->isp_ops->pci_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 650 | ql_log(ql_log_warn, vha, 0x0044, |
| 651 | "Unable to configure PCI space.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | return (rval); |
| 653 | } |
| 654 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 655 | ha->isp_ops->reset_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 657 | rval = qla2xxx_get_flash_info(vha); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 658 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 659 | ql_log(ql_log_fatal, vha, 0x004f, |
| 660 | "Unable to validate FLASH data.\n"); |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 661 | return rval; |
| 662 | } |
| 663 | |
| 664 | if (IS_QLA8044(ha)) { |
| 665 | qla8044_read_reset_template(vha); |
| 666 | |
| 667 | /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0. |
| 668 | * If DONRESET_BIT0 is set, drivers should not set dev_state |
| 669 | * to NEED_RESET. But if NEED_RESET is set, drivers should |
| 670 | * should honor the reset. */ |
| 671 | if (ql2xdontresethba == 1) |
| 672 | qla8044_set_idc_dontreset(vha); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 673 | } |
| 674 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 675 | ha->isp_ops->get_flash_version(vha, req->ring); |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 676 | ql_dbg(ql_dbg_init, vha, 0x0061, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 677 | "Configure NVRAM parameters...\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 678 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 679 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 681 | if (ha->flags.disable_serdes) { |
| 682 | /* Mask HBA via NVRAM settings? */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 683 | ql_log(ql_log_info, vha, 0x0077, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 684 | "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name); |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 685 | return QLA_FUNCTION_FAILED; |
| 686 | } |
| 687 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 688 | ql_dbg(ql_dbg_init, vha, 0x0078, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 689 | "Verifying loaded RISC code...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 691 | if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) { |
| 692 | rval = ha->isp_ops->chip_diag(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 693 | if (rval) |
| 694 | return (rval); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 695 | rval = qla2x00_setup_chip(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 696 | if (rval) |
| 697 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 699 | |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 700 | if (IS_QLA84XX(ha)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 701 | ha->cs84xx = qla84xx_get_chip(vha); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 702 | if (!ha->cs84xx) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 703 | ql_log(ql_log_warn, vha, 0x00d0, |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 704 | "Unable to configure ISP84XX.\n"); |
| 705 | return QLA_FUNCTION_FAILED; |
| 706 | } |
| 707 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 708 | |
| 709 | if (qla_ini_mode_enabled(vha)) |
| 710 | rval = qla2x00_init_rings(vha); |
| 711 | |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 712 | ha->flags.chip_reset_done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 714 | if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) { |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 715 | /* Issue verify 84xx FW IOCB to complete 84xx initialization */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 716 | rval = qla84xx_init_chip(vha); |
| 717 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 718 | ql_log(ql_log_warn, vha, 0x00d4, |
| 719 | "Unable to initialize ISP84XX.\n"); |
Bart Van Assche | 8d2b21d | 2015-06-04 15:58:09 -0700 | [diff] [blame] | 720 | qla84xx_put_chip(vha); |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 721 | } |
| 722 | } |
| 723 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 724 | /* Load the NIC Core f/w if we are the first protocol driver. */ |
| 725 | if (IS_QLA8031(ha)) { |
| 726 | rval = qla83xx_nic_core_fw_load(vha); |
| 727 | if (rval) |
| 728 | ql_log(ql_log_warn, vha, 0x0124, |
| 729 | "Error in initializing NIC Core f/w.\n"); |
| 730 | } |
| 731 | |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 732 | if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)) |
| 733 | qla24xx_read_fcp_prio_cfg(vha); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 734 | |
Joe Carnuccio | c46e65c | 2013-08-27 01:37:35 -0400 | [diff] [blame] | 735 | if (IS_P3P_TYPE(ha)) |
| 736 | qla82xx_set_driver_version(vha, QLA2XXX_VERSION); |
| 737 | else |
| 738 | qla25xx_set_driver_version(vha, QLA2XXX_VERSION); |
| 739 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | return (rval); |
| 741 | } |
| 742 | |
| 743 | /** |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 744 | * qla2100_pci_config() - Setup ISP21xx PCI configuration registers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | * @ha: HA context |
| 746 | * |
| 747 | * Returns 0 on success. |
| 748 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 749 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 750 | qla2100_pci_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 752 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 753 | unsigned long flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 754 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 755 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 758 | pci_try_set_mwi(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 761 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 763 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 764 | pci_disable_rom(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 766 | /* Get PCI bus information. */ |
| 767 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 768 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 769 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 770 | |
| 771 | return QLA_SUCCESS; |
| 772 | } |
| 773 | |
| 774 | /** |
| 775 | * qla2300_pci_config() - Setup ISP23xx PCI configuration registers. |
| 776 | * @ha: HA context |
| 777 | * |
| 778 | * Returns 0 on success. |
| 779 | */ |
| 780 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 781 | qla2300_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 782 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 783 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 784 | unsigned long flags = 0; |
| 785 | uint32_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 786 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 787 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 788 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 789 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 790 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 791 | |
| 792 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 793 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 794 | |
| 795 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 796 | w &= ~PCI_COMMAND_INTX_DISABLE; |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 797 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 798 | |
| 799 | /* |
| 800 | * If this is a 2300 card and not 2312, reset the |
| 801 | * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately, |
| 802 | * the 2310 also reports itself as a 2300 so we need to get the |
| 803 | * fb revision level -- a 6 indicates it really is a 2300 and |
| 804 | * not a 2310. |
| 805 | */ |
| 806 | if (IS_QLA2300(ha)) { |
| 807 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 808 | |
| 809 | /* Pause RISC. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 810 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 811 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 812 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 813 | break; |
| 814 | |
| 815 | udelay(10); |
| 816 | } |
| 817 | |
| 818 | /* Select FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 819 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 820 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 821 | |
| 822 | /* Get the fb rev level */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 823 | ha->fb_rev = RD_FB_CMD_REG(ha, reg); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 824 | |
| 825 | if (ha->fb_rev == FPM_2300) |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 826 | pci_clear_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 827 | |
| 828 | /* Deselect FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 829 | WRT_REG_WORD(®->ctrl_status, 0x0); |
| 830 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 831 | |
| 832 | /* Release RISC module. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 833 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 834 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 835 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 836 | break; |
| 837 | |
| 838 | udelay(10); |
| 839 | } |
| 840 | |
| 841 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 842 | } |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 843 | |
| 844 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 845 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 846 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 847 | |
| 848 | /* Get PCI bus information. */ |
| 849 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 850 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 851 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 852 | |
| 853 | return QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 857 | * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers. |
| 858 | * @ha: HA context |
| 859 | * |
| 860 | * Returns 0 on success. |
| 861 | */ |
| 862 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 863 | qla24xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 864 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 865 | uint16_t w; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 866 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 867 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 868 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 869 | |
| 870 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 871 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 872 | |
| 873 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 874 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 875 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 876 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 877 | |
| 878 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 879 | |
| 880 | /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */ |
Andrew Vasquez | f85ec18 | 2007-07-19 15:06:01 -0700 | [diff] [blame] | 881 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX)) |
| 882 | pcix_set_mmrbc(ha->pdev, 2048); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 883 | |
| 884 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Jon Mason | e67f132 | 2012-07-10 14:57:56 -0700 | [diff] [blame] | 885 | if (pci_is_pcie(ha->pdev)) |
Chad Dupuis | 5ffd3a5 | 2012-08-22 14:21:26 -0400 | [diff] [blame] | 886 | pcie_set_readrq(ha->pdev, 4096); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 887 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 888 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 889 | |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 890 | ha->chip_revision = ha->pdev->revision; |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 891 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 892 | /* Get PCI bus information. */ |
| 893 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 894 | ha->pci_attr = RD_REG_DWORD(®->ctrl_status); |
| 895 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 896 | |
| 897 | return QLA_SUCCESS; |
| 898 | } |
| 899 | |
| 900 | /** |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 901 | * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers. |
| 902 | * @ha: HA context |
| 903 | * |
| 904 | * Returns 0 on success. |
| 905 | */ |
| 906 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 907 | qla25xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 908 | { |
| 909 | uint16_t w; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 910 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 911 | |
| 912 | pci_set_master(ha->pdev); |
| 913 | pci_try_set_mwi(ha->pdev); |
| 914 | |
| 915 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
| 916 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
| 917 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 918 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 919 | |
| 920 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Jon Mason | e67f132 | 2012-07-10 14:57:56 -0700 | [diff] [blame] | 921 | if (pci_is_pcie(ha->pdev)) |
Chad Dupuis | 5ffd3a5 | 2012-08-22 14:21:26 -0400 | [diff] [blame] | 922 | pcie_set_readrq(ha->pdev, 4096); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 923 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 924 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 925 | |
| 926 | ha->chip_revision = ha->pdev->revision; |
| 927 | |
| 928 | return QLA_SUCCESS; |
| 929 | } |
| 930 | |
| 931 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | * qla2x00_isp_firmware() - Choose firmware image. |
| 933 | * @ha: HA context |
| 934 | * |
| 935 | * Returns 0 on success. |
| 936 | */ |
| 937 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 938 | qla2x00_isp_firmware(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | { |
| 940 | int rval; |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 941 | uint16_t loop_id, topo, sw_cap; |
| 942 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 943 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | |
| 945 | /* Assume loading risc code */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 946 | rval = QLA_FUNCTION_FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | |
| 948 | if (ha->flags.disable_risc_code_load) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 949 | ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | |
| 951 | /* Verify checksum of loaded RISC code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 952 | rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address); |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 953 | if (rval == QLA_SUCCESS) { |
| 954 | /* And, verify we are not in ROM code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 955 | rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa, |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 956 | &area, &domain, &topo, &sw_cap); |
| 957 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | } |
| 959 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 960 | if (rval) |
| 961 | ql_dbg(ql_dbg_init, vha, 0x007a, |
| 962 | "**** Load RISC code ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | |
| 964 | return (rval); |
| 965 | } |
| 966 | |
| 967 | /** |
| 968 | * qla2x00_reset_chip() - Reset ISP chip. |
| 969 | * @ha: HA context |
| 970 | * |
| 971 | * Returns 0 on success. |
| 972 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 973 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 974 | qla2x00_reset_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | { |
| 976 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 977 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 978 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | uint32_t cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | uint16_t cmd; |
| 981 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 982 | if (unlikely(pci_channel_offline(ha->pdev))) |
| 983 | return; |
| 984 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 985 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | |
| 987 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 988 | |
| 989 | /* Turn off master enable */ |
| 990 | cmd = 0; |
| 991 | pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd); |
| 992 | cmd &= ~PCI_COMMAND_MASTER; |
| 993 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 994 | |
| 995 | if (!IS_QLA2100(ha)) { |
| 996 | /* Pause RISC. */ |
| 997 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
| 998 | if (IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 999 | for (cnt = 0; cnt < 30000; cnt++) { |
| 1000 | if ((RD_REG_WORD(®->hccr) & |
| 1001 | HCCR_RISC_PAUSE) != 0) |
| 1002 | break; |
| 1003 | udelay(100); |
| 1004 | } |
| 1005 | } else { |
| 1006 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 1007 | udelay(10); |
| 1008 | } |
| 1009 | |
| 1010 | /* Select FPM registers. */ |
| 1011 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 1012 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 1013 | |
| 1014 | /* FPM Soft Reset. */ |
| 1015 | WRT_REG_WORD(®->fpm_diag_config, 0x100); |
| 1016 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 1017 | |
| 1018 | /* Toggle Fpm Reset. */ |
| 1019 | if (!IS_QLA2200(ha)) { |
| 1020 | WRT_REG_WORD(®->fpm_diag_config, 0x0); |
| 1021 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 1022 | } |
| 1023 | |
| 1024 | /* Select frame buffer registers. */ |
| 1025 | WRT_REG_WORD(®->ctrl_status, 0x10); |
| 1026 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 1027 | |
| 1028 | /* Reset frame buffer FIFOs. */ |
| 1029 | if (IS_QLA2200(ha)) { |
| 1030 | WRT_FB_CMD_REG(ha, reg, 0xa000); |
| 1031 | RD_FB_CMD_REG(ha, reg); /* PCI Posting. */ |
| 1032 | } else { |
| 1033 | WRT_FB_CMD_REG(ha, reg, 0x00fc); |
| 1034 | |
| 1035 | /* Read back fb_cmd until zero or 3 seconds max */ |
| 1036 | for (cnt = 0; cnt < 3000; cnt++) { |
| 1037 | if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0) |
| 1038 | break; |
| 1039 | udelay(100); |
| 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | /* Select RISC module registers. */ |
| 1044 | WRT_REG_WORD(®->ctrl_status, 0); |
| 1045 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 1046 | |
| 1047 | /* Reset RISC processor. */ |
| 1048 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 1049 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 1050 | |
| 1051 | /* Release RISC processor. */ |
| 1052 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 1053 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 1054 | } |
| 1055 | |
| 1056 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); |
| 1057 | WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT); |
| 1058 | |
| 1059 | /* Reset ISP chip. */ |
| 1060 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 1061 | |
| 1062 | /* Wait for RISC to recover from reset. */ |
| 1063 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 1064 | /* |
| 1065 | * It is necessary to for a delay here since the card doesn't |
| 1066 | * respond to PCI reads during a reset. On some architectures |
| 1067 | * this will result in an MCA. |
| 1068 | */ |
| 1069 | udelay(20); |
| 1070 | for (cnt = 30000; cnt; cnt--) { |
| 1071 | if ((RD_REG_WORD(®->ctrl_status) & |
| 1072 | CSR_ISP_SOFT_RESET) == 0) |
| 1073 | break; |
| 1074 | udelay(100); |
| 1075 | } |
| 1076 | } else |
| 1077 | udelay(10); |
| 1078 | |
| 1079 | /* Reset RISC processor. */ |
| 1080 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 1081 | |
| 1082 | WRT_REG_WORD(®->semaphore, 0); |
| 1083 | |
| 1084 | /* Release RISC processor. */ |
| 1085 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 1086 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 1087 | |
| 1088 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 1089 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | ffb39f0 | 2006-05-17 15:09:06 -0700 | [diff] [blame] | 1090 | if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | |
| 1093 | udelay(100); |
| 1094 | } |
| 1095 | } else |
| 1096 | udelay(100); |
| 1097 | |
| 1098 | /* Turn on master enable */ |
| 1099 | cmd |= PCI_COMMAND_MASTER; |
| 1100 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 1101 | |
| 1102 | /* Disable RISC pause on FPM parity error. */ |
| 1103 | if (!IS_QLA2100(ha)) { |
| 1104 | WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE); |
| 1105 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 1106 | } |
| 1107 | |
| 1108 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1109 | } |
| 1110 | |
| 1111 | /** |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 1112 | * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC. |
| 1113 | * |
| 1114 | * Returns 0 on success. |
| 1115 | */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 1116 | static int |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 1117 | qla81xx_reset_mpi(scsi_qla_host_t *vha) |
| 1118 | { |
| 1119 | uint16_t mb[4] = {0x1010, 0, 1, 0}; |
| 1120 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1121 | if (!IS_QLA81XX(vha->hw)) |
| 1122 | return QLA_SUCCESS; |
| 1123 | |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 1124 | return qla81xx_write_mpi_register(vha, mb); |
| 1125 | } |
| 1126 | |
| 1127 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1128 | * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC. |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1129 | * @ha: HA context |
| 1130 | * |
| 1131 | * Returns 0 on success. |
| 1132 | */ |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 1133 | static inline int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1134 | qla24xx_reset_risc(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1135 | { |
| 1136 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1137 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1138 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 1139 | uint32_t cnt; |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 1140 | uint16_t wd; |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 1141 | static int abts_cnt; /* ISP abort retry counts */ |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 1142 | int rval = QLA_SUCCESS; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1143 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1144 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1145 | |
| 1146 | /* Reset RISC. */ |
| 1147 | WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
| 1148 | for (cnt = 0; cnt < 30000; cnt++) { |
| 1149 | if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0) |
| 1150 | break; |
| 1151 | |
| 1152 | udelay(10); |
| 1153 | } |
| 1154 | |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 1155 | if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE)) |
| 1156 | set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags); |
| 1157 | |
| 1158 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e, |
| 1159 | "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n", |
| 1160 | RD_REG_DWORD(®->hccr), |
| 1161 | RD_REG_DWORD(®->ctrl_status), |
| 1162 | (RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE)); |
| 1163 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1164 | WRT_REG_DWORD(®->ctrl_status, |
| 1165 | CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 1166 | pci_read_config_word(ha->pdev, PCI_COMMAND, &wd); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1167 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 1168 | udelay(100); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 1169 | |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1170 | /* Wait for firmware to complete NVRAM accesses. */ |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 1171 | RD_REG_WORD(®->mailbox0); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 1172 | for (cnt = 10000; RD_REG_WORD(®->mailbox0) != 0 && |
| 1173 | rval == QLA_SUCCESS; cnt--) { |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1174 | barrier(); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 1175 | if (cnt) |
| 1176 | udelay(5); |
| 1177 | else |
| 1178 | rval = QLA_FUNCTION_TIMEOUT; |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1179 | } |
| 1180 | |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 1181 | if (rval == QLA_SUCCESS) |
| 1182 | set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags); |
| 1183 | |
| 1184 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f, |
| 1185 | "HCCR: 0x%x, MailBox0 Status 0x%x\n", |
| 1186 | RD_REG_DWORD(®->hccr), |
| 1187 | RD_REG_DWORD(®->mailbox0)); |
| 1188 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 1189 | /* Wait for soft-reset to complete. */ |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 1190 | RD_REG_DWORD(®->ctrl_status); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 1191 | for (cnt = 0; cnt < 6000000; cnt++) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1192 | barrier(); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 1193 | if ((RD_REG_DWORD(®->ctrl_status) & |
| 1194 | CSRX_ISP_SOFT_RESET) == 0) |
| 1195 | break; |
| 1196 | |
| 1197 | udelay(5); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1198 | } |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 1199 | if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_ISP_SOFT_RESET)) |
| 1200 | set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags); |
| 1201 | |
| 1202 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d, |
| 1203 | "HCCR: 0x%x, Soft Reset status: 0x%x\n", |
| 1204 | RD_REG_DWORD(®->hccr), |
| 1205 | RD_REG_DWORD(®->ctrl_status)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1206 | |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 1207 | /* If required, do an MPI FW reset now */ |
| 1208 | if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) { |
| 1209 | if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) { |
| 1210 | if (++abts_cnt < 5) { |
| 1211 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 1212 | set_bit(MPI_RESET_NEEDED, &vha->dpc_flags); |
| 1213 | } else { |
| 1214 | /* |
| 1215 | * We exhausted the ISP abort retries. We have to |
| 1216 | * set the board offline. |
| 1217 | */ |
| 1218 | abts_cnt = 0; |
| 1219 | vha->flags.online = 0; |
| 1220 | } |
| 1221 | } |
| 1222 | } |
| 1223 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1224 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 1225 | RD_REG_DWORD(®->hccr); |
| 1226 | |
| 1227 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 1228 | RD_REG_DWORD(®->hccr); |
| 1229 | |
| 1230 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET); |
| 1231 | RD_REG_DWORD(®->hccr); |
| 1232 | |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 1233 | RD_REG_WORD(®->mailbox0); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 1234 | for (cnt = 6000000; RD_REG_WORD(®->mailbox0) != 0 && |
| 1235 | rval == QLA_SUCCESS; cnt--) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1236 | barrier(); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 1237 | if (cnt) |
| 1238 | udelay(5); |
| 1239 | else |
| 1240 | rval = QLA_FUNCTION_TIMEOUT; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1241 | } |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 1242 | if (rval == QLA_SUCCESS) |
| 1243 | set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags); |
| 1244 | |
| 1245 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e, |
| 1246 | "Host Risc 0x%x, mailbox0 0x%x\n", |
| 1247 | RD_REG_DWORD(®->hccr), |
| 1248 | RD_REG_WORD(®->mailbox0)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1249 | |
| 1250 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 124f85e | 2009-01-05 11:18:06 -0800 | [diff] [blame] | 1251 | |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 1252 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f, |
| 1253 | "Driver in %s mode\n", |
| 1254 | IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling"); |
| 1255 | |
Andrew Vasquez | 124f85e | 2009-01-05 11:18:06 -0800 | [diff] [blame] | 1256 | if (IS_NOPOLLING_TYPE(ha)) |
| 1257 | ha->isp_ops->enable_intrs(ha); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 1258 | |
| 1259 | return rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1260 | } |
| 1261 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 1262 | static void |
| 1263 | qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data) |
| 1264 | { |
| 1265 | struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24; |
| 1266 | |
| 1267 | WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET); |
| 1268 | *data = RD_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET); |
| 1269 | |
| 1270 | } |
| 1271 | |
| 1272 | static void |
| 1273 | qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data) |
| 1274 | { |
| 1275 | struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24; |
| 1276 | |
| 1277 | WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET); |
| 1278 | WRT_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET, data); |
| 1279 | } |
| 1280 | |
| 1281 | static void |
| 1282 | qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha) |
| 1283 | { |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 1284 | uint32_t wd32 = 0; |
| 1285 | uint delta_msec = 100; |
| 1286 | uint elapsed_msec = 0; |
| 1287 | uint timeout_msec; |
| 1288 | ulong n; |
| 1289 | |
Joe Carnuccio | cc79076 | 2015-08-04 13:37:53 -0400 | [diff] [blame] | 1290 | if (vha->hw->pdev->subsystem_device != 0x0175 && |
| 1291 | vha->hw->pdev->subsystem_device != 0x0240) |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 1292 | return; |
| 1293 | |
Joe Carnuccio | 8dd7e3a | 2015-08-04 13:37:54 -0400 | [diff] [blame] | 1294 | WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE); |
| 1295 | udelay(100); |
| 1296 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 1297 | attempt: |
| 1298 | timeout_msec = TIMEOUT_SEMAPHORE; |
| 1299 | n = timeout_msec / delta_msec; |
| 1300 | while (n--) { |
| 1301 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET); |
| 1302 | qla25xx_read_risc_sema_reg(vha, &wd32); |
| 1303 | if (wd32 & RISC_SEMAPHORE) |
| 1304 | break; |
| 1305 | msleep(delta_msec); |
| 1306 | elapsed_msec += delta_msec; |
| 1307 | if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED) |
| 1308 | goto force; |
| 1309 | } |
| 1310 | |
| 1311 | if (!(wd32 & RISC_SEMAPHORE)) |
| 1312 | goto force; |
| 1313 | |
| 1314 | if (!(wd32 & RISC_SEMAPHORE_FORCE)) |
| 1315 | goto acquired; |
| 1316 | |
| 1317 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR); |
| 1318 | timeout_msec = TIMEOUT_SEMAPHORE_FORCE; |
| 1319 | n = timeout_msec / delta_msec; |
| 1320 | while (n--) { |
| 1321 | qla25xx_read_risc_sema_reg(vha, &wd32); |
| 1322 | if (!(wd32 & RISC_SEMAPHORE_FORCE)) |
| 1323 | break; |
| 1324 | msleep(delta_msec); |
| 1325 | elapsed_msec += delta_msec; |
| 1326 | if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED) |
| 1327 | goto force; |
| 1328 | } |
| 1329 | |
| 1330 | if (wd32 & RISC_SEMAPHORE_FORCE) |
| 1331 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR); |
| 1332 | |
| 1333 | goto attempt; |
| 1334 | |
| 1335 | force: |
| 1336 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET); |
| 1337 | |
| 1338 | acquired: |
| 1339 | return; |
| 1340 | } |
| 1341 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1342 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1343 | * qla24xx_reset_chip() - Reset ISP24xx chip. |
| 1344 | * @ha: HA context |
| 1345 | * |
| 1346 | * Returns 0 on success. |
| 1347 | */ |
| 1348 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1349 | qla24xx_reset_chip(scsi_qla_host_t *vha) |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1350 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1351 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 1352 | |
| 1353 | if (pci_channel_offline(ha->pdev) && |
| 1354 | ha->flags.pci_channel_io_perm_failure) { |
| 1355 | return; |
| 1356 | } |
| 1357 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1358 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1359 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 1360 | qla25xx_manipulate_risc_semaphore(vha); |
| 1361 | |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1362 | /* Perform RISC reset. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1363 | qla24xx_reset_risc(vha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | * qla2x00_chip_diag() - Test chip for proper operation. |
| 1368 | * @ha: HA context |
| 1369 | * |
| 1370 | * Returns 0 on success. |
| 1371 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1372 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1373 | qla2x00_chip_diag(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | { |
| 1375 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1376 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1377 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | unsigned long flags = 0; |
| 1379 | uint16_t data; |
| 1380 | uint32_t cnt; |
| 1381 | uint16_t mb[5]; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1382 | struct req_que *req = ha->req_q_map[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | |
| 1384 | /* Assume a failed state */ |
| 1385 | rval = QLA_FUNCTION_FAILED; |
| 1386 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1387 | ql_dbg(ql_dbg_init, vha, 0x007b, |
| 1388 | "Testing device at %lx.\n", (u_long)®->flash_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | |
| 1390 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1391 | |
| 1392 | /* Reset ISP chip. */ |
| 1393 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 1394 | |
| 1395 | /* |
| 1396 | * We need to have a delay here since the card will not respond while |
| 1397 | * in reset causing an MCA on some architectures. |
| 1398 | */ |
| 1399 | udelay(20); |
| 1400 | data = qla2x00_debounce_register(®->ctrl_status); |
| 1401 | for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) { |
| 1402 | udelay(5); |
| 1403 | data = RD_REG_WORD(®->ctrl_status); |
| 1404 | barrier(); |
| 1405 | } |
| 1406 | |
| 1407 | if (!cnt) |
| 1408 | goto chip_diag_failed; |
| 1409 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1410 | ql_dbg(ql_dbg_init, vha, 0x007c, |
| 1411 | "Reset register cleared by chip reset.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | |
| 1413 | /* Reset RISC processor. */ |
| 1414 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 1415 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 1416 | |
| 1417 | /* Workaround for QLA2312 PCI parity error */ |
| 1418 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 1419 | data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0)); |
| 1420 | for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) { |
| 1421 | udelay(5); |
| 1422 | data = RD_MAILBOX_REG(ha, reg, 0); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1423 | barrier(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | } |
| 1425 | } else |
| 1426 | udelay(10); |
| 1427 | |
| 1428 | if (!cnt) |
| 1429 | goto chip_diag_failed; |
| 1430 | |
| 1431 | /* Check product ID of chip */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1432 | ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product Id of chip.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | |
| 1434 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); |
| 1435 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); |
| 1436 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); |
| 1437 | mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4)); |
| 1438 | if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) || |
| 1439 | mb[3] != PROD_ID_3) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1440 | ql_log(ql_log_warn, vha, 0x0062, |
| 1441 | "Wrong product ID = 0x%x,0x%x,0x%x.\n", |
| 1442 | mb[1], mb[2], mb[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | |
| 1444 | goto chip_diag_failed; |
| 1445 | } |
| 1446 | ha->product_id[0] = mb[1]; |
| 1447 | ha->product_id[1] = mb[2]; |
| 1448 | ha->product_id[2] = mb[3]; |
| 1449 | ha->product_id[3] = mb[4]; |
| 1450 | |
| 1451 | /* Adjust fw RISC transfer size */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1452 | if (req->length > 1024) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024; |
| 1454 | else |
| 1455 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1456 | req->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | |
| 1458 | if (IS_QLA2200(ha) && |
| 1459 | RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) { |
| 1460 | /* Limit firmware transfer size with a 2200A */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1461 | ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1463 | ha->device_type |= DT_ISP2200A; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | ha->fw_transfer_size = 128; |
| 1465 | } |
| 1466 | |
| 1467 | /* Wrap Incoming Mailboxes Test. */ |
| 1468 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1469 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1470 | ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1471 | rval = qla2x00_mbx_reg_test(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1472 | if (rval) |
| 1473 | ql_log(ql_log_warn, vha, 0x0080, |
| 1474 | "Failed mailbox send register test.\n"); |
| 1475 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | /* Flag a successful rval */ |
| 1477 | rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1479 | |
| 1480 | chip_diag_failed: |
| 1481 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1482 | ql_log(ql_log_info, vha, 0x0081, |
| 1483 | "Chip diagnostics **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | |
| 1485 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1486 | |
| 1487 | return (rval); |
| 1488 | } |
| 1489 | |
| 1490 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1491 | * qla24xx_chip_diag() - Test ISP24xx for proper operation. |
| 1492 | * @ha: HA context |
| 1493 | * |
| 1494 | * Returns 0 on success. |
| 1495 | */ |
| 1496 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1497 | qla24xx_chip_diag(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1498 | { |
| 1499 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1500 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1501 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1502 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 1503 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1504 | return QLA_SUCCESS; |
| 1505 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1506 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1507 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1508 | rval = qla2x00_mbx_reg_test(vha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1509 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1510 | ql_log(ql_log_warn, vha, 0x0082, |
| 1511 | "Failed mailbox send register test.\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1512 | } else { |
| 1513 | /* Flag a successful rval */ |
| 1514 | rval = QLA_SUCCESS; |
| 1515 | } |
| 1516 | |
| 1517 | return rval; |
| 1518 | } |
| 1519 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1520 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1521 | qla2x00_alloc_fw_dump(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1522 | { |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1523 | int rval; |
| 1524 | uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size, |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1525 | eft_size, fce_size, mq_size; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1526 | dma_addr_t tc_dma; |
| 1527 | void *tc; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1528 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1529 | struct req_que *req = ha->req_q_map[0]; |
| 1530 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 1531 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1532 | if (ha->fw_dump) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1533 | ql_dbg(ql_dbg_init, vha, 0x00bd, |
| 1534 | "Firmware dump already allocated.\n"); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1535 | return; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 1536 | } |
| 1537 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1538 | ha->fw_dumped = 0; |
Hiral Patel | 61f098d | 2014-04-11 16:54:21 -0400 | [diff] [blame] | 1539 | ha->fw_dump_cap_flags = 0; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 1540 | dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0; |
| 1541 | req_q_size = rsp_q_size = 0; |
| 1542 | |
| 1543 | if (IS_QLA27XX(ha)) |
| 1544 | goto try_fce; |
| 1545 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1546 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 1547 | fixed_size = sizeof(struct qla2100_fw_dump); |
| 1548 | } else if (IS_QLA23XX(ha)) { |
| 1549 | fixed_size = offsetof(struct qla2300_fw_dump, data_ram); |
| 1550 | mem_size = (ha->fw_memory_size - 0x11000 + 1) * |
| 1551 | sizeof(uint16_t); |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 1552 | } else if (IS_FWI2_CAPABLE(ha)) { |
Himanshu Madhani | b20f02e | 2015-06-10 11:05:18 -0400 | [diff] [blame] | 1553 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1554 | fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem); |
| 1555 | else if (IS_QLA81XX(ha)) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1556 | fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem); |
| 1557 | else if (IS_QLA25XX(ha)) |
| 1558 | fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem); |
| 1559 | else |
| 1560 | fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 1561 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1562 | mem_size = (ha->fw_memory_size - 0x100000 + 1) * |
| 1563 | sizeof(uint32_t); |
Giridhar Malavali | 050c9bb | 2012-02-09 11:15:33 -0800 | [diff] [blame] | 1564 | if (ha->mqenable) { |
Himanshu Madhani | b20f02e | 2015-06-10 11:05:18 -0400 | [diff] [blame] | 1565 | if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha)) |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1566 | mq_size = sizeof(struct qla2xxx_mq_chain); |
Giridhar Malavali | 050c9bb | 2012-02-09 11:15:33 -0800 | [diff] [blame] | 1567 | /* |
| 1568 | * Allocate maximum buffer size for all queues. |
| 1569 | * Resizing must be done at end-of-dump processing. |
| 1570 | */ |
| 1571 | mq_size += ha->max_req_queues * |
| 1572 | (req->length * sizeof(request_t)); |
| 1573 | mq_size += ha->max_rsp_queues * |
| 1574 | (rsp->length * sizeof(response_t)); |
| 1575 | } |
Arun Easi | 00876ae | 2013-03-25 02:21:37 -0400 | [diff] [blame] | 1576 | if (ha->tgt.atio_ring) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1577 | mq_size += ha->tgt.atio_q_length * sizeof(request_t); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1578 | /* Allocate memory for Fibre Channel Event Buffer. */ |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 1579 | if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) && |
| 1580 | !IS_QLA27XX(ha)) |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1581 | goto try_eft; |
| 1582 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 1583 | try_fce: |
| 1584 | if (ha->fce) |
| 1585 | dma_free_coherent(&ha->pdev->dev, |
| 1586 | FCE_SIZE, ha->fce, ha->fce_dma); |
| 1587 | |
| 1588 | /* Allocate memory for Fibre Channel Event Buffer. */ |
Joe Perches | 0ea85b5 | 2014-06-15 13:37:51 -0700 | [diff] [blame] | 1589 | tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma, |
| 1590 | GFP_KERNEL); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1591 | if (!tc) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1592 | ql_log(ql_log_warn, vha, 0x00be, |
| 1593 | "Unable to allocate (%d KB) for FCE.\n", |
| 1594 | FCE_SIZE / 1024); |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 1595 | goto try_eft; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1596 | } |
| 1597 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1598 | rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1599 | ha->fce_mb, &ha->fce_bufs); |
| 1600 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1601 | ql_log(ql_log_warn, vha, 0x00bf, |
| 1602 | "Unable to initialize FCE (%d).\n", rval); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1603 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, |
| 1604 | tc_dma); |
| 1605 | ha->flags.fce_enabled = 0; |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 1606 | goto try_eft; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1607 | } |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1608 | ql_dbg(ql_dbg_init, vha, 0x00c0, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1609 | "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1610 | |
Giridhar Malavali | 7d9dade | 2009-03-24 09:07:58 -0700 | [diff] [blame] | 1611 | fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1612 | ha->flags.fce_enabled = 1; |
| 1613 | ha->fce_dma = tc_dma; |
| 1614 | ha->fce = tc; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 1615 | |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1616 | try_eft: |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 1617 | if (ha->eft) |
| 1618 | dma_free_coherent(&ha->pdev->dev, |
| 1619 | EFT_SIZE, ha->eft, ha->eft_dma); |
| 1620 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1621 | /* Allocate memory for Extended Trace Buffer. */ |
Joe Perches | 0ea85b5 | 2014-06-15 13:37:51 -0700 | [diff] [blame] | 1622 | tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma, |
| 1623 | GFP_KERNEL); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1624 | if (!tc) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1625 | ql_log(ql_log_warn, vha, 0x00c1, |
| 1626 | "Unable to allocate (%d KB) for EFT.\n", |
| 1627 | EFT_SIZE / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1628 | goto cont_alloc; |
| 1629 | } |
| 1630 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1631 | rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1632 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1633 | ql_log(ql_log_warn, vha, 0x00c2, |
| 1634 | "Unable to initialize EFT (%d).\n", rval); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1635 | dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, |
| 1636 | tc_dma); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1637 | goto cont_alloc; |
| 1638 | } |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1639 | ql_dbg(ql_dbg_init, vha, 0x00c3, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1640 | "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1641 | |
| 1642 | eft_size = EFT_SIZE; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1643 | ha->eft_dma = tc_dma; |
| 1644 | ha->eft = tc; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1645 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 1646 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1647 | cont_alloc: |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 1648 | if (IS_QLA27XX(ha)) { |
| 1649 | if (!ha->fw_dump_template) { |
| 1650 | ql_log(ql_log_warn, vha, 0x00ba, |
| 1651 | "Failed missing fwdump template\n"); |
| 1652 | return; |
| 1653 | } |
| 1654 | dump_size = qla27xx_fwdt_calculate_dump_size(vha); |
| 1655 | ql_dbg(ql_dbg_init, vha, 0x00fa, |
| 1656 | "-> allocating fwdump (%x bytes)...\n", dump_size); |
| 1657 | goto allocate; |
| 1658 | } |
| 1659 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1660 | req_q_size = req->length * sizeof(request_t); |
| 1661 | rsp_q_size = rsp->length * sizeof(response_t); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1662 | dump_size = offsetof(struct qla2xxx_fw_dump, isp); |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1663 | dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size; |
Andrew Vasquez | bb99de6 | 2009-01-05 11:18:08 -0800 | [diff] [blame] | 1664 | ha->chain_offset = dump_size; |
| 1665 | dump_size += mq_size + fce_size; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1666 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 1667 | allocate: |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 1668 | ha->fw_dump = vmalloc(dump_size); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1669 | if (!ha->fw_dump) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1670 | ql_log(ql_log_warn, vha, 0x00c4, |
| 1671 | "Unable to allocate (%d KB) for firmware dump.\n", |
| 1672 | dump_size / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1673 | |
Madhuranath Iyengar | e30d175 | 2010-10-15 11:27:46 -0700 | [diff] [blame] | 1674 | if (ha->fce) { |
| 1675 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce, |
| 1676 | ha->fce_dma); |
| 1677 | ha->fce = NULL; |
| 1678 | ha->fce_dma = 0; |
| 1679 | } |
| 1680 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1681 | if (ha->eft) { |
| 1682 | dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft, |
| 1683 | ha->eft_dma); |
| 1684 | ha->eft = NULL; |
| 1685 | ha->eft_dma = 0; |
| 1686 | } |
| 1687 | return; |
| 1688 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 1689 | ha->fw_dump_len = dump_size; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1690 | ql_dbg(ql_dbg_init, vha, 0x00c5, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1691 | "Allocated (%d KB) for firmware dump.\n", dump_size / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1692 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 1693 | if (IS_QLA27XX(ha)) |
| 1694 | return; |
| 1695 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1696 | ha->fw_dump->signature[0] = 'Q'; |
| 1697 | ha->fw_dump->signature[1] = 'L'; |
| 1698 | ha->fw_dump->signature[2] = 'G'; |
| 1699 | ha->fw_dump->signature[3] = 'C'; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1700 | ha->fw_dump->version = htonl(1); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1701 | |
| 1702 | ha->fw_dump->fixed_size = htonl(fixed_size); |
| 1703 | ha->fw_dump->mem_size = htonl(mem_size); |
| 1704 | ha->fw_dump->req_q_size = htonl(req_q_size); |
| 1705 | ha->fw_dump->rsp_q_size = htonl(rsp_q_size); |
| 1706 | |
| 1707 | ha->fw_dump->eft_size = htonl(eft_size); |
| 1708 | ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma)); |
| 1709 | ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma)); |
| 1710 | |
| 1711 | ha->fw_dump->header_size = |
| 1712 | htonl(offsetof(struct qla2xxx_fw_dump, isp)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1713 | } |
| 1714 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1715 | static int |
| 1716 | qla81xx_mpi_sync(scsi_qla_host_t *vha) |
| 1717 | { |
| 1718 | #define MPS_MASK 0xe0 |
| 1719 | int rval; |
| 1720 | uint16_t dc; |
| 1721 | uint32_t dw; |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1722 | |
| 1723 | if (!IS_QLA81XX(vha->hw)) |
| 1724 | return QLA_SUCCESS; |
| 1725 | |
| 1726 | rval = qla2x00_write_ram_word(vha, 0x7c00, 1); |
| 1727 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1728 | ql_log(ql_log_warn, vha, 0x0105, |
| 1729 | "Unable to acquire semaphore.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1730 | goto done; |
| 1731 | } |
| 1732 | |
| 1733 | pci_read_config_word(vha->hw->pdev, 0x54, &dc); |
| 1734 | rval = qla2x00_read_ram_word(vha, 0x7a15, &dw); |
| 1735 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1736 | ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1737 | goto done_release; |
| 1738 | } |
| 1739 | |
| 1740 | dc &= MPS_MASK; |
| 1741 | if (dc == (dw & MPS_MASK)) |
| 1742 | goto done_release; |
| 1743 | |
| 1744 | dw &= ~MPS_MASK; |
| 1745 | dw |= dc; |
| 1746 | rval = qla2x00_write_ram_word(vha, 0x7a15, dw); |
| 1747 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1748 | ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | done_release: |
| 1752 | rval = qla2x00_write_ram_word(vha, 0x7c00, 0); |
| 1753 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1754 | ql_log(ql_log_warn, vha, 0x006d, |
| 1755 | "Unable to release semaphore.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | done: |
| 1759 | return rval; |
| 1760 | } |
| 1761 | |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 1762 | int |
| 1763 | qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req) |
| 1764 | { |
| 1765 | /* Don't try to reallocate the array */ |
| 1766 | if (req->outstanding_cmds) |
| 1767 | return QLA_SUCCESS; |
| 1768 | |
| 1769 | if (!IS_FWI2_CAPABLE(ha) || (ha->mqiobase && |
| 1770 | (ql2xmultique_tag || ql2xmaxqueues > 1))) |
| 1771 | req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS; |
| 1772 | else { |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 1773 | if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count) |
| 1774 | req->num_outstanding_cmds = ha->cur_fw_xcb_count; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 1775 | else |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 1776 | req->num_outstanding_cmds = ha->cur_fw_iocb_count; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | req->outstanding_cmds = kzalloc(sizeof(srb_t *) * |
| 1780 | req->num_outstanding_cmds, GFP_KERNEL); |
| 1781 | |
| 1782 | if (!req->outstanding_cmds) { |
| 1783 | /* |
| 1784 | * Try to allocate a minimal size just so we can get through |
| 1785 | * initialization. |
| 1786 | */ |
| 1787 | req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS; |
| 1788 | req->outstanding_cmds = kzalloc(sizeof(srb_t *) * |
| 1789 | req->num_outstanding_cmds, GFP_KERNEL); |
| 1790 | |
| 1791 | if (!req->outstanding_cmds) { |
| 1792 | ql_log(ql_log_fatal, NULL, 0x0126, |
| 1793 | "Failed to allocate memory for " |
| 1794 | "outstanding_cmds for req_que %p.\n", req); |
| 1795 | req->num_outstanding_cmds = 0; |
| 1796 | return QLA_FUNCTION_FAILED; |
| 1797 | } |
| 1798 | } |
| 1799 | |
| 1800 | return QLA_SUCCESS; |
| 1801 | } |
| 1802 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1803 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | * qla2x00_setup_chip() - Load and start RISC firmware. |
| 1805 | * @ha: HA context |
| 1806 | * |
| 1807 | * Returns 0 on success. |
| 1808 | */ |
| 1809 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1810 | qla2x00_setup_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1812 | int rval; |
| 1813 | uint32_t srisc_address = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1814 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1815 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 1816 | unsigned long flags; |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 1817 | uint16_t fw_major_version; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1818 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 1819 | if (IS_P3P_TYPE(ha)) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1820 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 1821 | if (rval == QLA_SUCCESS) { |
| 1822 | qla2x00_stop_firmware(vha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1823 | goto enable_82xx_npiv; |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 1824 | } else |
Giridhar Malavali | b963752 | 2010-05-28 15:08:15 -0700 | [diff] [blame] | 1825 | goto failed; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1826 | } |
| 1827 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1828 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 1829 | /* Disable SRAM, Instruction RAM and GP RAM parity. */ |
| 1830 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1831 | WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0)); |
| 1832 | RD_REG_WORD(®->hccr); |
| 1833 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1834 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1836 | qla81xx_mpi_sync(vha); |
| 1837 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | /* Load firmware sequences */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1839 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1840 | if (rval == QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1841 | ql_dbg(ql_dbg_init, vha, 0x00c9, |
| 1842 | "Verifying Checksum of loaded RISC code.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1844 | rval = qla2x00_verify_checksum(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | if (rval == QLA_SUCCESS) { |
| 1846 | /* Start firmware execution. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1847 | ql_dbg(ql_dbg_init, vha, 0x00ca, |
| 1848 | "Starting firmware.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | |
Himanshu Madhani | b0d6cab | 2015-12-17 14:56:56 -0500 | [diff] [blame] | 1850 | if (ql2xexlogins) |
| 1851 | ha->flags.exlogins_enabled = 1; |
| 1852 | |
Himanshu Madhani | 2f56a7f | 2015-12-17 14:56:57 -0500 | [diff] [blame] | 1853 | if (ql2xexchoffld) |
| 1854 | ha->flags.exchoffld_enabled = 1; |
| 1855 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1856 | rval = qla2x00_execute_fw(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1857 | /* Retrieve firmware information. */ |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 1858 | if (rval == QLA_SUCCESS) { |
Himanshu Madhani | b0d6cab | 2015-12-17 14:56:56 -0500 | [diff] [blame] | 1859 | rval = qla2x00_set_exlogins_buffer(vha); |
| 1860 | if (rval != QLA_SUCCESS) |
| 1861 | goto failed; |
| 1862 | |
Himanshu Madhani | 2f56a7f | 2015-12-17 14:56:57 -0500 | [diff] [blame] | 1863 | rval = qla2x00_set_exchoffld_buffer(vha); |
| 1864 | if (rval != QLA_SUCCESS) |
| 1865 | goto failed; |
| 1866 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1867 | enable_82xx_npiv: |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 1868 | fw_major_version = ha->fw_major_version; |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 1869 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | 3173167 | 2011-08-16 11:31:54 -0700 | [diff] [blame] | 1870 | qla82xx_check_md_needed(vha); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1871 | else |
| 1872 | rval = qla2x00_get_fw_version(vha); |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 1873 | if (rval != QLA_SUCCESS) |
| 1874 | goto failed; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1875 | ha->flags.npiv_supported = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1876 | if (IS_QLA2XXX_MIDTYPE(ha) && |
Mike Hernandez | 946fb89 | 2008-08-13 21:36:59 -0700 | [diff] [blame] | 1877 | (ha->fw_attributes & BIT_2)) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1878 | ha->flags.npiv_supported = 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 1879 | if ((!ha->max_npiv_vports) || |
| 1880 | ((ha->max_npiv_vports + 1) % |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 1881 | MIN_MULTI_ID_FABRIC)) |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 1882 | ha->max_npiv_vports = |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 1883 | MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 1884 | } |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 1885 | qla2x00_get_resource_cnts(vha); |
Andrew Vasquez | d743de6 | 2009-03-24 09:08:15 -0700 | [diff] [blame] | 1886 | |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 1887 | /* |
| 1888 | * Allocate the array of outstanding commands |
| 1889 | * now that we know the firmware resources. |
| 1890 | */ |
| 1891 | rval = qla2x00_alloc_outstanding_cmds(ha, |
| 1892 | vha->req); |
| 1893 | if (rval != QLA_SUCCESS) |
| 1894 | goto failed; |
| 1895 | |
Saurav Kashyap | be5ea3c | 2011-11-18 09:02:11 -0800 | [diff] [blame] | 1896 | if (!fw_major_version && ql2xallocfwdump |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 1897 | && !(IS_P3P_TYPE(ha))) |
Giridhar Malavali | 08de284 | 2011-08-16 11:31:44 -0700 | [diff] [blame] | 1898 | qla2x00_alloc_fw_dump(vha); |
Chad Dupuis | 3b6e5b9 | 2013-10-30 03:38:09 -0400 | [diff] [blame] | 1899 | } else { |
| 1900 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | } |
| 1902 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1903 | ql_log(ql_log_fatal, vha, 0x00cd, |
| 1904 | "ISP Firmware failed checksum.\n"); |
| 1905 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | } |
Andrew Vasquez | c74d88a | 2012-08-22 14:21:19 -0400 | [diff] [blame] | 1907 | } else |
| 1908 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1910 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 1911 | /* Enable proper parity. */ |
| 1912 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1913 | if (IS_QLA2300(ha)) |
| 1914 | /* SRAM parity */ |
| 1915 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1); |
| 1916 | else |
| 1917 | /* SRAM, Instruction RAM and GP RAM parity */ |
| 1918 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7); |
| 1919 | RD_REG_WORD(®->hccr); |
| 1920 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1921 | } |
| 1922 | |
Chad Dupuis | f3982d8 | 2014-09-25 05:16:57 -0400 | [diff] [blame] | 1923 | if (IS_QLA27XX(ha)) |
| 1924 | ha->flags.fac_supported = 1; |
| 1925 | else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) { |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1926 | uint32_t size; |
| 1927 | |
| 1928 | rval = qla81xx_fac_get_sector_size(vha, &size); |
| 1929 | if (rval == QLA_SUCCESS) { |
| 1930 | ha->flags.fac_supported = 1; |
| 1931 | ha->fdt_block_size = size << 2; |
| 1932 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1933 | ql_log(ql_log_warn, vha, 0x00ce, |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1934 | "Unsupported FAC firmware (%d.%02d.%02d).\n", |
| 1935 | ha->fw_major_version, ha->fw_minor_version, |
| 1936 | ha->fw_subminor_version); |
Joe Carnuccio | 1ca60e3 | 2014-02-26 04:15:02 -0500 | [diff] [blame] | 1937 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 1938 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1939 | ha->flags.fac_supported = 0; |
| 1940 | rval = QLA_SUCCESS; |
| 1941 | } |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1942 | } |
| 1943 | } |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 1944 | failed: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1946 | ql_log(ql_log_fatal, vha, 0x00cf, |
| 1947 | "Setup chip ****FAILED****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | } |
| 1949 | |
| 1950 | return (rval); |
| 1951 | } |
| 1952 | |
| 1953 | /** |
| 1954 | * qla2x00_init_response_q_entries() - Initializes response queue entries. |
| 1955 | * @ha: HA context |
| 1956 | * |
| 1957 | * Beginning of request ring has initialization control block already built |
| 1958 | * by nvram config routine. |
| 1959 | * |
| 1960 | * Returns 0 on success. |
| 1961 | */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1962 | void |
| 1963 | qla2x00_init_response_q_entries(struct rsp_que *rsp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | { |
| 1965 | uint16_t cnt; |
| 1966 | response_t *pkt; |
| 1967 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1968 | rsp->ring_ptr = rsp->ring; |
| 1969 | rsp->ring_index = 0; |
| 1970 | rsp->status_srb = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1971 | pkt = rsp->ring_ptr; |
| 1972 | for (cnt = 0; cnt < rsp->length; cnt++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | pkt->signature = RESPONSE_PROCESSED; |
| 1974 | pkt++; |
| 1975 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | } |
| 1977 | |
| 1978 | /** |
| 1979 | * qla2x00_update_fw_options() - Read and process firmware options. |
| 1980 | * @ha: HA context |
| 1981 | * |
| 1982 | * Returns 0 on success. |
| 1983 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1984 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1985 | qla2x00_update_fw_options(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 | { |
| 1987 | uint16_t swing, emphasis, tx_sens, rx_sens; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1988 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1989 | |
| 1990 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1991 | qla2x00_get_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | |
| 1993 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
| 1994 | return; |
| 1995 | |
| 1996 | /* Serial Link options. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1997 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115, |
| 1998 | "Serial link options.\n"); |
| 1999 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109, |
| 2000 | (uint8_t *)&ha->fw_seriallink_options, |
| 2001 | sizeof(ha->fw_seriallink_options)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | |
| 2003 | ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING; |
| 2004 | if (ha->fw_seriallink_options[3] & BIT_2) { |
| 2005 | ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING; |
| 2006 | |
| 2007 | /* 1G settings */ |
| 2008 | swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0); |
| 2009 | emphasis = (ha->fw_seriallink_options[2] & |
| 2010 | (BIT_4 | BIT_3)) >> 3; |
| 2011 | tx_sens = ha->fw_seriallink_options[0] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2012 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | rx_sens = (ha->fw_seriallink_options[0] & |
| 2014 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 2015 | ha->fw_options[10] = (emphasis << 14) | (swing << 8); |
| 2016 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 2017 | if (rx_sens == 0x0) |
| 2018 | rx_sens = 0x3; |
| 2019 | ha->fw_options[10] |= (tx_sens << 4) | rx_sens; |
| 2020 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 2021 | ha->fw_options[10] |= BIT_5 | |
| 2022 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 2023 | (tx_sens & (BIT_1 | BIT_0)); |
| 2024 | |
| 2025 | /* 2G settings */ |
| 2026 | swing = (ha->fw_seriallink_options[2] & |
| 2027 | (BIT_7 | BIT_6 | BIT_5)) >> 5; |
| 2028 | emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0); |
| 2029 | tx_sens = ha->fw_seriallink_options[1] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2030 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 | rx_sens = (ha->fw_seriallink_options[1] & |
| 2032 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 2033 | ha->fw_options[11] = (emphasis << 14) | (swing << 8); |
| 2034 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 2035 | if (rx_sens == 0x0) |
| 2036 | rx_sens = 0x3; |
| 2037 | ha->fw_options[11] |= (tx_sens << 4) | rx_sens; |
| 2038 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 2039 | ha->fw_options[11] |= BIT_5 | |
| 2040 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 2041 | (tx_sens & (BIT_1 | BIT_0)); |
| 2042 | } |
| 2043 | |
| 2044 | /* FCP2 options. */ |
| 2045 | /* Return command IOCBs without waiting for an ABTS to complete. */ |
| 2046 | ha->fw_options[3] |= BIT_13; |
| 2047 | |
| 2048 | /* LED scheme. */ |
| 2049 | if (ha->flags.enable_led_scheme) |
| 2050 | ha->fw_options[2] |= BIT_12; |
| 2051 | |
andrew.vasquez@qlogic.com | 48c02fd | 2006-03-09 14:27:18 -0800 | [diff] [blame] | 2052 | /* Detect ISP6312. */ |
| 2053 | if (IS_QLA6312(ha)) |
| 2054 | ha->fw_options[2] |= BIT_13; |
| 2055 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | /* Update firmware options. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2057 | qla2x00_set_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2058 | } |
| 2059 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2060 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2061 | qla24xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2062 | { |
| 2063 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2064 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2065 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 2066 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2067 | return; |
| 2068 | |
Himanshu Madhani | f198caf | 2016-01-27 12:03:30 -0500 | [diff] [blame] | 2069 | /* Hold status IOCBs until ABTS response received. */ |
| 2070 | if (ql2xfwholdabts) |
| 2071 | ha->fw_options[3] |= BIT_12; |
| 2072 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2073 | /* Update Serial Link options. */ |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 2074 | if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2075 | return; |
| 2076 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2077 | rval = qla2x00_set_serdes_params(vha, |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 2078 | le16_to_cpu(ha->fw_seriallink_options24[1]), |
| 2079 | le16_to_cpu(ha->fw_seriallink_options24[2]), |
| 2080 | le16_to_cpu(ha->fw_seriallink_options24[3])); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2081 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2082 | ql_log(ql_log_warn, vha, 0x0104, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2083 | "Unable to update Serial Link options (%x).\n", rval); |
| 2084 | } |
| 2085 | } |
| 2086 | |
| 2087 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2088 | qla2x00_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2089 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2090 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2091 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2092 | struct req_que *req = ha->req_q_map[0]; |
| 2093 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2094 | |
| 2095 | /* Setup ring parameters in initialization control block. */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2096 | ha->init_cb->request_q_outpointer = cpu_to_le16(0); |
| 2097 | ha->init_cb->response_q_inpointer = cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2098 | ha->init_cb->request_q_length = cpu_to_le16(req->length); |
| 2099 | ha->init_cb->response_q_length = cpu_to_le16(rsp->length); |
| 2100 | ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 2101 | ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 2102 | ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 2103 | ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma)); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2104 | |
| 2105 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0); |
| 2106 | WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0); |
| 2107 | WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0); |
| 2108 | WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0); |
| 2109 | RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */ |
| 2110 | } |
| 2111 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2112 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2113 | qla24xx_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2114 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2115 | struct qla_hw_data *ha = vha->hw; |
Bart Van Assche | 118e2ef | 2015-07-09 07:24:27 -0700 | [diff] [blame] | 2116 | device_reg_t *reg = ISP_QUE_REG(ha, 0); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2117 | struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp; |
| 2118 | struct qla_msix_entry *msix; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2119 | struct init_cb_24xx *icb; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2120 | uint16_t rid = 0; |
| 2121 | struct req_que *req = ha->req_q_map[0]; |
| 2122 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2123 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2124 | /* Setup ring parameters in initialization control block. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2125 | icb = (struct init_cb_24xx *)ha->init_cb; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2126 | icb->request_q_outpointer = cpu_to_le16(0); |
| 2127 | icb->response_q_inpointer = cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2128 | icb->request_q_length = cpu_to_le16(req->length); |
| 2129 | icb->response_q_length = cpu_to_le16(rsp->length); |
| 2130 | icb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 2131 | icb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 2132 | icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 2133 | icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2134 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2135 | /* Setup ATIO queue dma pointers for target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2136 | icb->atio_q_inpointer = cpu_to_le16(0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2137 | icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length); |
| 2138 | icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma)); |
| 2139 | icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma)); |
| 2140 | |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 2141 | if (IS_SHADOW_REG_CAPABLE(ha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2142 | icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29); |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 2143 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2144 | if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2145 | icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS); |
| 2146 | icb->rid = cpu_to_le16(rid); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2147 | if (ha->flags.msix_enabled) { |
| 2148 | msix = &ha->msix_entries[1]; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2149 | ql_dbg(ql_dbg_init, vha, 0x00fd, |
| 2150 | "Registering vector 0x%x for base que.\n", |
| 2151 | msix->entry); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2152 | icb->msix = cpu_to_le16(msix->entry); |
| 2153 | } |
| 2154 | /* Use alternate PCI bus number */ |
| 2155 | if (MSB(rid)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2156 | icb->firmware_options_2 |= cpu_to_le32(BIT_19); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2157 | /* Use alternate PCI devfn */ |
| 2158 | if (LSB(rid)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2159 | icb->firmware_options_2 |= cpu_to_le32(BIT_18); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2160 | |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 2161 | /* Use Disable MSIX Handshake mode for capable adapters */ |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2162 | if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) && |
| 2163 | (ha->flags.msix_enabled)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2164 | icb->firmware_options_2 &= cpu_to_le32(~BIT_22); |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 2165 | ha->flags.disable_msix_handshake = 1; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2166 | ql_dbg(ql_dbg_init, vha, 0x00fe, |
| 2167 | "MSIX Handshake Disable Mode turned on.\n"); |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 2168 | } else { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2169 | icb->firmware_options_2 |= cpu_to_le32(BIT_22); |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 2170 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2171 | icb->firmware_options_2 |= cpu_to_le32(BIT_23); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2172 | |
| 2173 | WRT_REG_DWORD(®->isp25mq.req_q_in, 0); |
| 2174 | WRT_REG_DWORD(®->isp25mq.req_q_out, 0); |
| 2175 | WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0); |
| 2176 | WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0); |
| 2177 | } else { |
| 2178 | WRT_REG_DWORD(®->isp24.req_q_in, 0); |
| 2179 | WRT_REG_DWORD(®->isp24.req_q_out, 0); |
| 2180 | WRT_REG_DWORD(®->isp24.rsp_q_in, 0); |
| 2181 | WRT_REG_DWORD(®->isp24.rsp_q_out, 0); |
| 2182 | } |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 2183 | qlt_24xx_config_rings(vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2184 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2185 | /* PCI posting */ |
| 2186 | RD_REG_DWORD(&ioreg->hccr); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2187 | } |
| 2188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | /** |
| 2190 | * qla2x00_init_rings() - Initializes firmware. |
| 2191 | * @ha: HA context |
| 2192 | * |
| 2193 | * Beginning of request ring has initialization control block already built |
| 2194 | * by nvram config routine. |
| 2195 | * |
| 2196 | * Returns 0 on success. |
| 2197 | */ |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 2198 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2199 | qla2x00_init_rings(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | { |
| 2201 | int rval; |
| 2202 | unsigned long flags = 0; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 2203 | int cnt, que; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2204 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 2205 | struct req_que *req; |
| 2206 | struct rsp_que *rsp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2207 | struct mid_init_cb_24xx *mid_init_cb = |
| 2208 | (struct mid_init_cb_24xx *) ha->init_cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | |
| 2210 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2211 | |
| 2212 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 2213 | for (que = 0; que < ha->max_req_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 2214 | req = ha->req_q_map[que]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 2215 | if (!req || !test_bit(que, ha->req_qid_map)) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 2216 | continue; |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 2217 | req->out_ptr = (void *)(req->ring + req->length); |
| 2218 | *req->out_ptr = 0; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2219 | for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 2220 | req->outstanding_cmds[cnt] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2221 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 2222 | req->current_outstanding_cmd = 1; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 2223 | |
| 2224 | /* Initialize firmware. */ |
| 2225 | req->ring_ptr = req->ring; |
| 2226 | req->ring_index = 0; |
| 2227 | req->cnt = req->length; |
| 2228 | } |
| 2229 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 2230 | for (que = 0; que < ha->max_rsp_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 2231 | rsp = ha->rsp_q_map[que]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 2232 | if (!rsp || !test_bit(que, ha->rsp_qid_map)) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 2233 | continue; |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 2234 | rsp->in_ptr = (void *)(rsp->ring + rsp->length); |
| 2235 | *rsp->in_ptr = 0; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 2236 | /* Initialize response queue entries */ |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 2237 | if (IS_QLAFX00(ha)) |
| 2238 | qlafx00_init_response_q_entries(rsp); |
| 2239 | else |
| 2240 | qla2x00_init_response_q_entries(rsp); |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 2241 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2243 | ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; |
| 2244 | ha->tgt.atio_ring_index = 0; |
| 2245 | /* Initialize ATIO queue entries */ |
| 2246 | qlt_init_atio_q_entries(vha); |
| 2247 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2248 | ha->isp_ops->config_rings(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2249 | |
| 2250 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2251 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 2252 | ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n"); |
| 2253 | |
| 2254 | if (IS_QLAFX00(ha)) { |
| 2255 | rval = qlafx00_init_firmware(vha, ha->init_cb_size); |
| 2256 | goto next_check; |
| 2257 | } |
| 2258 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2259 | /* Update any ISP specific firmware options before initialization. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2260 | ha->isp_ops->update_fw_options(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2261 | |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 2262 | if (ha->flags.npiv_supported) { |
Saurav Kashyap | 45980cc | 2012-08-22 14:21:21 -0400 | [diff] [blame] | 2263 | if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha)) |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 2264 | ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | c48339d | 2008-01-17 09:02:19 -0800 | [diff] [blame] | 2265 | mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports); |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 2266 | } |
| 2267 | |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 2268 | if (IS_FWI2_CAPABLE(ha)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2269 | mid_init_cb->options = cpu_to_le16(BIT_1); |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 2270 | mid_init_cb->init_cb.execution_throttle = |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 2271 | cpu_to_le16(ha->cur_fw_xcb_count); |
Himanshu Madhani | 25232cc | 2014-09-25 05:16:54 -0400 | [diff] [blame] | 2272 | /* D-Port Status */ |
| 2273 | if (IS_DPORT_CAPABLE(ha)) |
| 2274 | mid_init_cb->init_cb.firmware_options_1 |= |
| 2275 | cpu_to_le16(BIT_7); |
Himanshu Madhani | 2486c62 | 2014-09-25 05:17:00 -0400 | [diff] [blame] | 2276 | /* Enable FA-WWPN */ |
| 2277 | ha->flags.fawwpn_enabled = |
| 2278 | (mid_init_cb->init_cb.firmware_options_1 & BIT_6) ? 1 : 0; |
| 2279 | ql_dbg(ql_dbg_init, vha, 0x0141, "FA-WWPN Support: %s.\n", |
| 2280 | (ha->flags.fawwpn_enabled) ? "enabled" : "disabled"); |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 2281 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2282 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2283 | rval = qla2x00_init_firmware(vha, ha->init_cb_size); |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 2284 | next_check: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2285 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2286 | ql_log(ql_log_fatal, vha, 0x00d2, |
| 2287 | "Init Firmware **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2288 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2289 | ql_dbg(ql_dbg_init, vha, 0x00d3, |
| 2290 | "Init Firmware -- success.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2291 | } |
| 2292 | |
| 2293 | return (rval); |
| 2294 | } |
| 2295 | |
| 2296 | /** |
| 2297 | * qla2x00_fw_ready() - Waits for firmware ready. |
| 2298 | * @ha: HA context |
| 2299 | * |
| 2300 | * Returns 0 on success. |
| 2301 | */ |
| 2302 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2303 | qla2x00_fw_ready(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2304 | { |
| 2305 | int rval; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2306 | unsigned long wtime, mtime, cs84xx_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2307 | uint16_t min_wait; /* Minimum wait time if loop is down */ |
| 2308 | uint16_t wait_time; /* Wait time if loop is coming ready */ |
Joe Carnuccio | b5a340d | 2014-09-25 05:16:48 -0400 | [diff] [blame] | 2309 | uint16_t state[6]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2310 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2311 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 2312 | if (IS_QLAFX00(vha->hw)) |
| 2313 | return qlafx00_fw_ready(vha); |
| 2314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | rval = QLA_SUCCESS; |
| 2316 | |
Chad Dupuis | 33461491 | 2015-04-09 14:59:57 -0400 | [diff] [blame] | 2317 | /* Time to wait for loop down */ |
| 2318 | if (IS_P3P_TYPE(ha)) |
| 2319 | min_wait = 30; |
| 2320 | else |
| 2321 | min_wait = 20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2322 | |
| 2323 | /* |
| 2324 | * Firmware should take at most one RATOV to login, plus 5 seconds for |
| 2325 | * our own processing. |
| 2326 | */ |
| 2327 | if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) { |
| 2328 | wait_time = min_wait; |
| 2329 | } |
| 2330 | |
| 2331 | /* Min wait time if loop down */ |
| 2332 | mtime = jiffies + (min_wait * HZ); |
| 2333 | |
| 2334 | /* wait time before firmware ready */ |
| 2335 | wtime = jiffies + (wait_time * HZ); |
| 2336 | |
| 2337 | /* Wait for ISP to finish LIP */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2338 | if (!vha->flags.init_done) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2339 | ql_log(ql_log_info, vha, 0x801e, |
| 2340 | "Waiting for LIP to complete.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2341 | |
| 2342 | do { |
Andrew Vasquez | 5b93903 | 2012-11-21 02:40:26 -0500 | [diff] [blame] | 2343 | memset(state, -1, sizeof(state)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2344 | rval = qla2x00_get_firmware_state(vha, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2345 | if (rval == QLA_SUCCESS) { |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2346 | if (state[0] < FSTATE_LOSS_OF_SYNC) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2347 | vha->device_flags &= ~DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2348 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2349 | if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2350 | ql_dbg(ql_dbg_taskm, vha, 0x801f, |
| 2351 | "fw_state=%x 84xx=%x.\n", state[0], |
| 2352 | state[2]); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2353 | if ((state[2] & FSTATE_LOGGED_IN) && |
| 2354 | (state[2] & FSTATE_WAITING_FOR_VERIFY)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2355 | ql_dbg(ql_dbg_taskm, vha, 0x8028, |
| 2356 | "Sending verify iocb.\n"); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2357 | |
| 2358 | cs84xx_time = jiffies; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2359 | rval = qla84xx_init_chip(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2360 | if (rval != QLA_SUCCESS) { |
| 2361 | ql_log(ql_log_warn, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2362 | vha, 0x8007, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2363 | "Init chip failed.\n"); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2364 | break; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2365 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2366 | |
| 2367 | /* Add time taken to initialize. */ |
| 2368 | cs84xx_time = jiffies - cs84xx_time; |
| 2369 | wtime += cs84xx_time; |
| 2370 | mtime += cs84xx_time; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2371 | ql_dbg(ql_dbg_taskm, vha, 0x8008, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2372 | "Increasing wait time by %ld. " |
| 2373 | "New time %ld.\n", cs84xx_time, |
| 2374 | wtime); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2375 | } |
| 2376 | } else if (state[0] == FSTATE_READY) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2377 | ql_dbg(ql_dbg_taskm, vha, 0x8037, |
| 2378 | "F/W Ready - OK.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2380 | qla2x00_get_retry_cnt(vha, &ha->retry_count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2381 | &ha->login_timeout, &ha->r_a_tov); |
| 2382 | |
| 2383 | rval = QLA_SUCCESS; |
| 2384 | break; |
| 2385 | } |
| 2386 | |
| 2387 | rval = QLA_FUNCTION_FAILED; |
| 2388 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2389 | if (atomic_read(&vha->loop_down_timer) && |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2390 | state[0] != FSTATE_READY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | /* Loop down. Timeout on min_wait for states |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2392 | * other than Wait for Login. |
| 2393 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2394 | if (time_after_eq(jiffies, mtime)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2395 | ql_log(ql_log_info, vha, 0x8038, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2396 | "Cable is unplugged...\n"); |
| 2397 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2398 | vha->device_flags |= DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2399 | break; |
| 2400 | } |
| 2401 | } |
| 2402 | } else { |
| 2403 | /* Mailbox cmd failed. Timeout on min_wait. */ |
Santosh Vernekar | cdbb0a4f | 2010-05-28 15:08:25 -0700 | [diff] [blame] | 2404 | if (time_after_eq(jiffies, mtime) || |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 2405 | ha->flags.isp82xx_fw_hung) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | break; |
| 2407 | } |
| 2408 | |
| 2409 | if (time_after_eq(jiffies, wtime)) |
| 2410 | break; |
| 2411 | |
| 2412 | /* Delay for a while */ |
| 2413 | msleep(500); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | } while (1); |
| 2415 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2416 | ql_dbg(ql_dbg_taskm, vha, 0x803a, |
Joe Carnuccio | b5a340d | 2014-09-25 05:16:48 -0400 | [diff] [blame] | 2417 | "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0], |
| 2418 | state[1], state[2], state[3], state[4], state[5], jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2420 | if (rval && !(vha->device_flags & DFLG_NO_CABLE)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2421 | ql_log(ql_log_warn, vha, 0x803b, |
| 2422 | "Firmware ready **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | return (rval); |
| 2426 | } |
| 2427 | |
| 2428 | /* |
| 2429 | * qla2x00_configure_hba |
| 2430 | * Setup adapter context. |
| 2431 | * |
| 2432 | * Input: |
| 2433 | * ha = adapter state pointer. |
| 2434 | * |
| 2435 | * Returns: |
| 2436 | * 0 = success |
| 2437 | * |
| 2438 | * Context: |
| 2439 | * Kernel context. |
| 2440 | */ |
| 2441 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2442 | qla2x00_configure_hba(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2443 | { |
| 2444 | int rval; |
| 2445 | uint16_t loop_id; |
| 2446 | uint16_t topo; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2447 | uint16_t sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2448 | uint8_t al_pa; |
| 2449 | uint8_t area; |
| 2450 | uint8_t domain; |
| 2451 | char connect_type[22]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2452 | struct qla_hw_data *ha = vha->hw; |
Jiri Kosina | f24b5cb | 2012-10-08 09:23:54 +0200 | [diff] [blame] | 2453 | unsigned long flags; |
Joe Carnuccio | 61e1b26 | 2013-02-08 01:57:48 -0500 | [diff] [blame] | 2454 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2455 | |
| 2456 | /* Get host addresses. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2457 | rval = qla2x00_get_adapter_id(vha, |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2458 | &loop_id, &al_pa, &area, &domain, &topo, &sw_cap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2459 | if (rval != QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2460 | if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) || |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2461 | IS_CNA_CAPABLE(ha) || |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 2462 | (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2463 | ql_dbg(ql_dbg_disc, vha, 0x2008, |
| 2464 | "Loop is in a transition state.\n"); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 2465 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2466 | ql_log(ql_log_warn, vha, 0x2009, |
| 2467 | "Unable to get host loop ID.\n"); |
Joe Carnuccio | 61e1b26 | 2013-02-08 01:57:48 -0500 | [diff] [blame] | 2468 | if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) && |
| 2469 | (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) { |
| 2470 | ql_log(ql_log_warn, vha, 0x1151, |
| 2471 | "Doing link init.\n"); |
| 2472 | if (qla24xx_link_initialize(vha) == QLA_SUCCESS) |
| 2473 | return rval; |
| 2474 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2475 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 2476 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2477 | return (rval); |
| 2478 | } |
| 2479 | |
| 2480 | if (topo == 4) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2481 | ql_log(ql_log_info, vha, 0x200a, |
| 2482 | "Cannot get topology - retrying.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2483 | return (QLA_FUNCTION_FAILED); |
| 2484 | } |
| 2485 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2486 | vha->loop_id = loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2487 | |
| 2488 | /* initialize */ |
| 2489 | ha->min_external_loopid = SNS_FIRST_LOOP_ID; |
| 2490 | ha->operating_mode = LOOP; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2491 | ha->switch_cap = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2492 | |
| 2493 | switch (topo) { |
| 2494 | case 0: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2495 | ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2496 | ha->current_topology = ISP_CFG_NL; |
| 2497 | strcpy(connect_type, "(Loop)"); |
| 2498 | break; |
| 2499 | |
| 2500 | case 1: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2501 | ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n"); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2502 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2503 | ha->current_topology = ISP_CFG_FL; |
| 2504 | strcpy(connect_type, "(FL_Port)"); |
| 2505 | break; |
| 2506 | |
| 2507 | case 2: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2508 | ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2509 | ha->operating_mode = P2P; |
| 2510 | ha->current_topology = ISP_CFG_N; |
| 2511 | strcpy(connect_type, "(N_Port-to-N_Port)"); |
| 2512 | break; |
| 2513 | |
| 2514 | case 3: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2515 | ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n"); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2516 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | ha->operating_mode = P2P; |
| 2518 | ha->current_topology = ISP_CFG_F; |
| 2519 | strcpy(connect_type, "(F_Port)"); |
| 2520 | break; |
| 2521 | |
| 2522 | default: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2523 | ql_dbg(ql_dbg_disc, vha, 0x200f, |
| 2524 | "HBA in unknown topology %x, using NL.\n", topo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2525 | ha->current_topology = ISP_CFG_NL; |
| 2526 | strcpy(connect_type, "(Loop)"); |
| 2527 | break; |
| 2528 | } |
| 2529 | |
| 2530 | /* Save Host port and loop ID. */ |
| 2531 | /* byte order - Big Endian */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2532 | vha->d_id.b.domain = domain; |
| 2533 | vha->d_id.b.area = area; |
| 2534 | vha->d_id.b.al_pa = al_pa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2535 | |
Jiri Kosina | f24b5cb | 2012-10-08 09:23:54 +0200 | [diff] [blame] | 2536 | spin_lock_irqsave(&ha->vport_slock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2537 | qlt_update_vp_map(vha, SET_AL_PA); |
Jiri Kosina | f24b5cb | 2012-10-08 09:23:54 +0200 | [diff] [blame] | 2538 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2539 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2540 | if (!vha->flags.init_done) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2541 | ql_log(ql_log_info, vha, 0x2010, |
| 2542 | "Topology - %s, Host Loop address 0x%x.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2543 | connect_type, vha->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2544 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | return(rval); |
| 2546 | } |
| 2547 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2548 | inline void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2549 | qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len, |
| 2550 | char *def) |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2551 | { |
| 2552 | char *st, *en; |
| 2553 | uint16_t index; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2554 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | ab67114 | 2009-08-25 11:36:17 -0700 | [diff] [blame] | 2555 | int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) && |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2556 | !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2557 | |
| 2558 | if (memcmp(model, BINZERO, len) != 0) { |
| 2559 | strncpy(ha->model_number, model, len); |
| 2560 | st = en = ha->model_number; |
| 2561 | en += len - 1; |
| 2562 | while (en > st) { |
| 2563 | if (*en != 0x20 && *en != 0x00) |
| 2564 | break; |
| 2565 | *en-- = '\0'; |
| 2566 | } |
| 2567 | |
| 2568 | index = (ha->pdev->subsystem_device & 0xff); |
Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 2569 | if (use_tbl && |
| 2570 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2571 | index < QLA_MODEL_NAMES) |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2572 | strncpy(ha->model_desc, |
| 2573 | qla2x00_model_name[index * 2 + 1], |
| 2574 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2575 | } else { |
| 2576 | index = (ha->pdev->subsystem_device & 0xff); |
Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 2577 | if (use_tbl && |
| 2578 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2579 | index < QLA_MODEL_NAMES) { |
| 2580 | strcpy(ha->model_number, |
| 2581 | qla2x00_model_name[index * 2]); |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2582 | strncpy(ha->model_desc, |
| 2583 | qla2x00_model_name[index * 2 + 1], |
| 2584 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2585 | } else { |
| 2586 | strcpy(ha->model_number, def); |
| 2587 | } |
| 2588 | } |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2589 | if (IS_FWI2_CAPABLE(ha)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2590 | qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc, |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2591 | sizeof(ha->model_desc)); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2592 | } |
| 2593 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2594 | /* On sparc systems, obtain port and node WWN from firmware |
| 2595 | * properties. |
| 2596 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2597 | static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv) |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2598 | { |
| 2599 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2600 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2601 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 2602 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 2603 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2604 | int len; |
| 2605 | |
| 2606 | val = of_get_property(dp, "port-wwn", &len); |
| 2607 | if (val && len >= WWN_SIZE) |
| 2608 | memcpy(nv->port_name, val, WWN_SIZE); |
| 2609 | |
| 2610 | val = of_get_property(dp, "node-wwn", &len); |
| 2611 | if (val && len >= WWN_SIZE) |
| 2612 | memcpy(nv->node_name, val, WWN_SIZE); |
| 2613 | #endif |
| 2614 | } |
| 2615 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2616 | /* |
| 2617 | * NVRAM configuration for ISP 2xxx |
| 2618 | * |
| 2619 | * Input: |
| 2620 | * ha = adapter block pointer. |
| 2621 | * |
| 2622 | * Output: |
| 2623 | * initialization control block in response_ring |
| 2624 | * host adapters parameters in host adapter block |
| 2625 | * |
| 2626 | * Returns: |
| 2627 | * 0 = success. |
| 2628 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2629 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2630 | qla2x00_nvram_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2631 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2632 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2633 | uint8_t chksum = 0; |
| 2634 | uint16_t cnt; |
| 2635 | uint8_t *dptr1, *dptr2; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2636 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2637 | init_cb_t *icb = ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 2638 | nvram_t *nv = ha->nvram; |
| 2639 | uint8_t *ptr = ha->nvram; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2640 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2641 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2642 | rval = QLA_SUCCESS; |
| 2643 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | /* Determine NVRAM starting address. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2645 | ha->nvram_size = sizeof(nvram_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2646 | ha->nvram_base = 0; |
| 2647 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) |
| 2648 | if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1) |
| 2649 | ha->nvram_base = 0x80; |
| 2650 | |
| 2651 | /* Get NVRAM data and calculate checksum. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2652 | ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2653 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++) |
| 2654 | chksum += *ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2655 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2656 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f, |
| 2657 | "Contents of NVRAM.\n"); |
| 2658 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110, |
| 2659 | (uint8_t *)nv, ha->nvram_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2660 | |
| 2661 | /* Bad NVRAM data, set defaults parameters. */ |
| 2662 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || |
| 2663 | nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) { |
| 2664 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2665 | ql_log(ql_log_warn, vha, 0x0064, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 2666 | "Inconsistent NVRAM " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2667 | "detected: checksum=0x%x id=%c version=0x%x.\n", |
| 2668 | chksum, nv->id[0], nv->nvram_version); |
| 2669 | ql_log(ql_log_warn, vha, 0x0065, |
| 2670 | "Falling back to " |
| 2671 | "functioning (yet invalid -- WWPN) defaults.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2672 | |
| 2673 | /* |
| 2674 | * Set default initialization control block. |
| 2675 | */ |
| 2676 | memset(nv, 0, ha->nvram_size); |
| 2677 | nv->parameter_block_version = ICB_VERSION; |
| 2678 | |
| 2679 | if (IS_QLA23XX(ha)) { |
| 2680 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 2681 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 2682 | nv->add_firmware_options[0] = BIT_5; |
| 2683 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 2684 | nv->frame_payload_size = 2048; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2685 | nv->special_options[1] = BIT_7; |
| 2686 | } else if (IS_QLA2200(ha)) { |
| 2687 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 2688 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 2689 | nv->add_firmware_options[0] = BIT_5; |
| 2690 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 2691 | nv->frame_payload_size = 1024; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2692 | } else if (IS_QLA2100(ha)) { |
| 2693 | nv->firmware_options[0] = BIT_3 | BIT_1; |
| 2694 | nv->firmware_options[1] = BIT_5; |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 2695 | nv->frame_payload_size = 1024; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2696 | } |
| 2697 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2698 | nv->max_iocb_allocation = cpu_to_le16(256); |
| 2699 | nv->execution_throttle = cpu_to_le16(16); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2700 | nv->retry_count = 8; |
| 2701 | nv->retry_delay = 1; |
| 2702 | |
| 2703 | nv->port_name[0] = 33; |
| 2704 | nv->port_name[3] = 224; |
| 2705 | nv->port_name[4] = 139; |
| 2706 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2707 | qla2xxx_nvram_wwn_from_ofw(vha, nv); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2708 | |
| 2709 | nv->login_timeout = 4; |
| 2710 | |
| 2711 | /* |
| 2712 | * Set default host adapter parameters |
| 2713 | */ |
| 2714 | nv->host_p[1] = BIT_2; |
| 2715 | nv->reset_delay = 5; |
| 2716 | nv->port_down_retry_count = 8; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2717 | nv->max_luns_per_target = cpu_to_le16(8); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2718 | nv->link_down_timeout = 60; |
| 2719 | |
| 2720 | rval = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2721 | } |
| 2722 | |
| 2723 | #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2) |
| 2724 | /* |
| 2725 | * The SN2 does not provide BIOS emulation which means you can't change |
| 2726 | * potentially bogus BIOS settings. Force the use of default settings |
| 2727 | * for link rate and frame size. Hope that the rest of the settings |
| 2728 | * are valid. |
| 2729 | */ |
| 2730 | if (ia64_platform_is("sn2")) { |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 2731 | nv->frame_payload_size = 2048; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2732 | if (IS_QLA23XX(ha)) |
| 2733 | nv->special_options[1] = BIT_7; |
| 2734 | } |
| 2735 | #endif |
| 2736 | |
| 2737 | /* Reset Initialization control block */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2738 | memset(icb, 0, ha->init_cb_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2739 | |
| 2740 | /* |
| 2741 | * Setup driver NVRAM options. |
| 2742 | */ |
| 2743 | nv->firmware_options[0] |= (BIT_6 | BIT_1); |
| 2744 | nv->firmware_options[0] &= ~(BIT_5 | BIT_4); |
| 2745 | nv->firmware_options[1] |= (BIT_5 | BIT_0); |
| 2746 | nv->firmware_options[1] &= ~BIT_4; |
| 2747 | |
| 2748 | if (IS_QLA23XX(ha)) { |
| 2749 | nv->firmware_options[0] |= BIT_2; |
| 2750 | nv->firmware_options[0] &= ~BIT_3; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2751 | nv->special_options[0] &= ~BIT_6; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2752 | nv->add_firmware_options[1] |= BIT_5 | BIT_4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2753 | |
| 2754 | if (IS_QLA2300(ha)) { |
| 2755 | if (ha->fb_rev == FPM_2310) { |
| 2756 | strcpy(ha->model_number, "QLA2310"); |
| 2757 | } else { |
| 2758 | strcpy(ha->model_number, "QLA2300"); |
| 2759 | } |
| 2760 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2761 | qla2x00_set_model_info(vha, nv->model_number, |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2762 | sizeof(nv->model_number), "QLA23xx"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2763 | } |
| 2764 | } else if (IS_QLA2200(ha)) { |
| 2765 | nv->firmware_options[0] |= BIT_2; |
| 2766 | /* |
| 2767 | * 'Point-to-point preferred, else loop' is not a safe |
| 2768 | * connection mode setting. |
| 2769 | */ |
| 2770 | if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) == |
| 2771 | (BIT_5 | BIT_4)) { |
| 2772 | /* Force 'loop preferred, else point-to-point'. */ |
| 2773 | nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4); |
| 2774 | nv->add_firmware_options[0] |= BIT_5; |
| 2775 | } |
| 2776 | strcpy(ha->model_number, "QLA22xx"); |
| 2777 | } else /*if (IS_QLA2100(ha))*/ { |
| 2778 | strcpy(ha->model_number, "QLA2100"); |
| 2779 | } |
| 2780 | |
| 2781 | /* |
| 2782 | * Copy over NVRAM RISC parameter block to initialization control block. |
| 2783 | */ |
| 2784 | dptr1 = (uint8_t *)icb; |
| 2785 | dptr2 = (uint8_t *)&nv->parameter_block_version; |
| 2786 | cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version; |
| 2787 | while (cnt--) |
| 2788 | *dptr1++ = *dptr2++; |
| 2789 | |
| 2790 | /* Copy 2nd half. */ |
| 2791 | dptr1 = (uint8_t *)icb->add_firmware_options; |
| 2792 | cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options; |
| 2793 | while (cnt--) |
| 2794 | *dptr1++ = *dptr2++; |
| 2795 | |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 2796 | /* Use alternate WWN? */ |
| 2797 | if (nv->host_p[1] & BIT_7) { |
| 2798 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 2799 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 2800 | } |
| 2801 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2802 | /* Prepare nodename */ |
| 2803 | if ((icb->firmware_options[1] & BIT_6) == 0) { |
| 2804 | /* |
| 2805 | * Firmware will apply the following mask if the nodename was |
| 2806 | * not provided. |
| 2807 | */ |
| 2808 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 2809 | icb->node_name[0] &= 0xF0; |
| 2810 | } |
| 2811 | |
| 2812 | /* |
| 2813 | * Set host adapter parameters. |
| 2814 | */ |
Saurav Kashyap | 3ce8866 | 2011-07-14 12:00:12 -0700 | [diff] [blame] | 2815 | |
| 2816 | /* |
| 2817 | * BIT_7 in the host-parameters section allows for modification to |
| 2818 | * internal driver logging. |
| 2819 | */ |
Andrew Vasquez | 0181944 | 2006-06-23 16:11:10 -0700 | [diff] [blame] | 2820 | if (nv->host_p[0] & BIT_7) |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2821 | ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2822 | ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0); |
| 2823 | /* Always load RISC code on non ISP2[12]00 chips. */ |
| 2824 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) |
| 2825 | ha->flags.disable_risc_code_load = 0; |
| 2826 | ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0); |
| 2827 | ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0); |
| 2828 | ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0); |
Andrew Vasquez | 06c22bd | 2005-08-26 19:09:00 -0700 | [diff] [blame] | 2829 | ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0; |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 2830 | ha->flags.disable_serdes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2831 | |
| 2832 | ha->operating_mode = |
| 2833 | (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 2834 | |
| 2835 | memcpy(ha->fw_seriallink_options, nv->seriallink_options, |
| 2836 | sizeof(ha->fw_seriallink_options)); |
| 2837 | |
| 2838 | /* save HBA serial number */ |
| 2839 | ha->serial0 = icb->port_name[5]; |
| 2840 | ha->serial1 = icb->port_name[6]; |
| 2841 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2842 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 2843 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2845 | icb->execution_throttle = cpu_to_le16(0xFFFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | |
| 2847 | ha->retry_count = nv->retry_count; |
| 2848 | |
| 2849 | /* Set minimum login_timeout to 4 seconds. */ |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 2850 | if (nv->login_timeout != ql2xlogintimeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2851 | nv->login_timeout = ql2xlogintimeout; |
| 2852 | if (nv->login_timeout < 4) |
| 2853 | nv->login_timeout = 4; |
| 2854 | ha->login_timeout = nv->login_timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2855 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 2856 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 2857 | ha->r_a_tov = 100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2858 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2859 | ha->loop_reset_delay = nv->reset_delay; |
| 2860 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2861 | /* Link Down Timeout = 0: |
| 2862 | * |
| 2863 | * When Port Down timer expires we will start returning |
| 2864 | * I/O's to OS with "DID_NO_CONNECT". |
| 2865 | * |
| 2866 | * Link Down Timeout != 0: |
| 2867 | * |
| 2868 | * The driver waits for the link to come up after link down |
| 2869 | * before returning I/Os to OS with "DID_NO_CONNECT". |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2870 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2871 | if (nv->link_down_timeout == 0) { |
| 2872 | ha->loop_down_abort_time = |
Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 2873 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2874 | } else { |
| 2875 | ha->link_down_timeout = nv->link_down_timeout; |
| 2876 | ha->loop_down_abort_time = |
| 2877 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2878 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2879 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2880 | /* |
| 2881 | * Need enough time to try and get the port back. |
| 2882 | */ |
| 2883 | ha->port_down_retry_count = nv->port_down_retry_count; |
| 2884 | if (qlport_down_retry) |
| 2885 | ha->port_down_retry_count = qlport_down_retry; |
| 2886 | /* Set login_retry_count */ |
| 2887 | ha->login_retry_count = nv->retry_count; |
| 2888 | if (ha->port_down_retry_count == nv->port_down_retry_count && |
| 2889 | ha->port_down_retry_count > 3) |
| 2890 | ha->login_retry_count = ha->port_down_retry_count; |
| 2891 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 2892 | ha->login_retry_count = ha->port_down_retry_count; |
| 2893 | if (ql2xloginretrycount) |
| 2894 | ha->login_retry_count = ql2xloginretrycount; |
| 2895 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2896 | icb->lun_enables = cpu_to_le16(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2897 | icb->command_resource_count = 0; |
| 2898 | icb->immediate_notify_resource_count = 0; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2899 | icb->timeout = cpu_to_le16(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | |
| 2901 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 2902 | /* Enable RIO */ |
| 2903 | icb->firmware_options[0] &= ~BIT_3; |
| 2904 | icb->add_firmware_options[0] &= |
| 2905 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 2906 | icb->add_firmware_options[0] |= BIT_2; |
| 2907 | icb->response_accumulation_timer = 3; |
| 2908 | icb->interrupt_delay_timer = 5; |
| 2909 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2910 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2911 | } else { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2912 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2913 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2914 | ha->zio_mode = icb->add_firmware_options[0] & |
| 2915 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 2916 | ha->zio_timer = icb->interrupt_delay_timer ? |
| 2917 | icb->interrupt_delay_timer: 2; |
| 2918 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2919 | icb->add_firmware_options[0] &= |
| 2920 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2921 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2922 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 2923 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 2924 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2925 | ql_log(ql_log_info, vha, 0x0068, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2926 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 2927 | ha->zio_mode, ha->zio_timer * 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2929 | icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode; |
| 2930 | icb->interrupt_delay_timer = (uint8_t)ha->zio_timer; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2931 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2932 | } |
| 2933 | } |
| 2934 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2935 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2936 | ql_log(ql_log_warn, vha, 0x0069, |
| 2937 | "NVRAM configuration failed.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2938 | } |
| 2939 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2940 | } |
| 2941 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2942 | static void |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2943 | qla2x00_rport_del(void *data) |
| 2944 | { |
| 2945 | fc_port_t *fcport = data; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2946 | struct fc_rport *rport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2947 | unsigned long flags; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2948 | |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2949 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2950 | rport = fcport->drport ? fcport->drport: fcport->rport; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2951 | fcport->drport = NULL; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2952 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 2953 | if (rport) |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2954 | fc_remote_port_delete(rport); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2955 | } |
| 2956 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2957 | /** |
| 2958 | * qla2x00_alloc_fcport() - Allocate a generic fcport. |
| 2959 | * @ha: HA context |
| 2960 | * @flags: allocation flags |
| 2961 | * |
| 2962 | * Returns a pointer to the allocated fcport, or NULL, if none available. |
| 2963 | */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2964 | fc_port_t * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2965 | qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2966 | { |
| 2967 | fc_port_t *fcport; |
| 2968 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2969 | fcport = kzalloc(sizeof(fc_port_t), flags); |
| 2970 | if (!fcport) |
| 2971 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2972 | |
| 2973 | /* Setup fcport template structure. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2974 | fcport->vha = vha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | fcport->port_type = FCT_UNKNOWN; |
| 2976 | fcport->loop_id = FC_NO_LOOP_ID; |
Chad Dupuis | ec426e1 | 2011-03-30 11:46:32 -0700 | [diff] [blame] | 2977 | qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED); |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 2978 | fcport->supported_classes = FC_COS_UNSPECIFIED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2979 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2980 | return fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2981 | } |
| 2982 | |
| 2983 | /* |
| 2984 | * qla2x00_configure_loop |
| 2985 | * Updates Fibre Channel Device Database with what is actually on loop. |
| 2986 | * |
| 2987 | * Input: |
| 2988 | * ha = adapter block pointer. |
| 2989 | * |
| 2990 | * Returns: |
| 2991 | * 0 = success. |
| 2992 | * 1 = error. |
| 2993 | * 2 = database was full and device was not configured. |
| 2994 | */ |
| 2995 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2996 | qla2x00_configure_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2997 | { |
| 2998 | int rval; |
| 2999 | unsigned long flags, save_flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3000 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | rval = QLA_SUCCESS; |
| 3002 | |
| 3003 | /* Get Initiator ID */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3004 | if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) { |
| 3005 | rval = qla2x00_configure_hba(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3006 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3007 | ql_dbg(ql_dbg_disc, vha, 0x2013, |
| 3008 | "Unable to configure HBA.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3009 | return (rval); |
| 3010 | } |
| 3011 | } |
| 3012 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3013 | save_flags = flags = vha->dpc_flags; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3014 | ql_dbg(ql_dbg_disc, vha, 0x2014, |
| 3015 | "Configure loop -- dpc flags = 0x%lx.\n", flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | |
| 3017 | /* |
| 3018 | * If we have both an RSCN and PORT UPDATE pending then handle them |
| 3019 | * both at the same time. |
| 3020 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3021 | clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 3022 | clear_bit(RSCN_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3023 | |
Michael Hernandez | 3064ff3 | 2009-12-15 21:29:44 -0800 | [diff] [blame] | 3024 | qla2x00_get_data_rate(vha); |
| 3025 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3026 | /* Determine what we need to do */ |
| 3027 | if (ha->current_topology == ISP_CFG_FL && |
| 3028 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 3029 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | set_bit(RSCN_UPDATE, &flags); |
| 3031 | |
| 3032 | } else if (ha->current_topology == ISP_CFG_F && |
| 3033 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 3034 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3035 | set_bit(RSCN_UPDATE, &flags); |
| 3036 | clear_bit(LOCAL_LOOP_UPDATE, &flags); |
| 3037 | |
Andrew Vasquez | 21333b4 | 2006-05-17 15:09:56 -0700 | [diff] [blame] | 3038 | } else if (ha->current_topology == ISP_CFG_N) { |
| 3039 | clear_bit(RSCN_UPDATE, &flags); |
| 3040 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3041 | } else if (!vha->flags.online || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | (test_bit(ABORT_ISP_ACTIVE, &flags))) { |
| 3043 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3044 | set_bit(RSCN_UPDATE, &flags); |
| 3045 | set_bit(LOCAL_LOOP_UPDATE, &flags); |
| 3046 | } |
| 3047 | |
| 3048 | if (test_bit(LOCAL_LOOP_UPDATE, &flags)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3049 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
| 3050 | ql_dbg(ql_dbg_disc, vha, 0x2015, |
| 3051 | "Loop resync needed, failing.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3052 | rval = QLA_FUNCTION_FAILED; |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 3053 | } else |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3054 | rval = qla2x00_configure_local_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | } |
| 3056 | |
| 3057 | if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3058 | if (LOOP_TRANSITION(vha)) { |
| 3059 | ql_dbg(ql_dbg_disc, vha, 0x201e, |
| 3060 | "Needs RSCN update and loop transition.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | rval = QLA_FUNCTION_FAILED; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3062 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3063 | else |
| 3064 | rval = qla2x00_configure_fabric(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3065 | } |
| 3066 | |
| 3067 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3068 | if (atomic_read(&vha->loop_down_timer) || |
| 3069 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | rval = QLA_FUNCTION_FAILED; |
| 3071 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3072 | atomic_set(&vha->loop_state, LOOP_READY); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3073 | ql_dbg(ql_dbg_disc, vha, 0x2069, |
| 3074 | "LOOP READY.\n"); |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 3075 | |
| 3076 | /* |
| 3077 | * Process any ATIO queue entries that came in |
| 3078 | * while we weren't online. |
| 3079 | */ |
| 3080 | if (qla_tgt_mode_enabled(vha)) { |
| 3081 | if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) { |
| 3082 | spin_lock_irqsave(&ha->tgt.atio_lock, |
| 3083 | flags); |
| 3084 | qlt_24xx_process_atio_queue(vha, 0); |
| 3085 | spin_unlock_irqrestore( |
| 3086 | &ha->tgt.atio_lock, flags); |
| 3087 | } else { |
| 3088 | spin_lock_irqsave(&ha->hardware_lock, |
| 3089 | flags); |
| 3090 | qlt_24xx_process_atio_queue(vha, 1); |
| 3091 | spin_unlock_irqrestore( |
| 3092 | &ha->hardware_lock, flags); |
| 3093 | } |
| 3094 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3095 | } |
| 3096 | } |
| 3097 | |
| 3098 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3099 | ql_dbg(ql_dbg_disc, vha, 0x206a, |
| 3100 | "%s *** FAILED ***.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3101 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3102 | ql_dbg(ql_dbg_disc, vha, 0x206b, |
| 3103 | "%s: exiting normally.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3104 | } |
| 3105 | |
Bjorn Helgaas | cc3ef7b | 2008-09-11 21:22:51 -0700 | [diff] [blame] | 3106 | /* Restore state if a resync event occurred during processing */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3107 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3108 | if (test_bit(LOCAL_LOOP_UPDATE, &save_flags)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3109 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 3110 | if (test_bit(RSCN_UPDATE, &save_flags)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3111 | set_bit(RSCN_UPDATE, &vha->dpc_flags); |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 3112 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3113 | } |
| 3114 | |
| 3115 | return (rval); |
| 3116 | } |
| 3117 | |
| 3118 | |
| 3119 | |
| 3120 | /* |
| 3121 | * qla2x00_configure_local_loop |
| 3122 | * Updates Fibre Channel Device Database with local loop devices. |
| 3123 | * |
| 3124 | * Input: |
| 3125 | * ha = adapter block pointer. |
| 3126 | * |
| 3127 | * Returns: |
| 3128 | * 0 = success. |
| 3129 | */ |
| 3130 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3131 | qla2x00_configure_local_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3132 | { |
| 3133 | int rval, rval2; |
| 3134 | int found_devs; |
| 3135 | int found; |
| 3136 | fc_port_t *fcport, *new_fcport; |
| 3137 | |
| 3138 | uint16_t index; |
| 3139 | uint16_t entries; |
| 3140 | char *id_iter; |
| 3141 | uint16_t loop_id; |
| 3142 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3143 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3144 | |
| 3145 | found_devs = 0; |
| 3146 | new_fcport = NULL; |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 3147 | entries = MAX_FIBRE_DEVICES_LOOP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3149 | /* Get list of logged in devices. */ |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 3150 | memset(ha->gid_list, 0, qla2x00_gid_list_size(ha)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3151 | rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3152 | &entries); |
| 3153 | if (rval != QLA_SUCCESS) |
| 3154 | goto cleanup_allocation; |
| 3155 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3156 | ql_dbg(ql_dbg_disc, vha, 0x2017, |
| 3157 | "Entries in ID list (%d).\n", entries); |
| 3158 | ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075, |
| 3159 | (uint8_t *)ha->gid_list, |
| 3160 | entries * sizeof(struct gid_list_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | |
| 3162 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3163 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3164 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3165 | ql_log(ql_log_warn, vha, 0x2018, |
| 3166 | "Memory allocation failed for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3167 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 3168 | goto cleanup_allocation; |
| 3169 | } |
| 3170 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 3171 | |
| 3172 | /* |
| 3173 | * Mark local devices that were present with FCF_DEVICE_LOST for now. |
| 3174 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3175 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3176 | if (atomic_read(&fcport->state) == FCS_ONLINE && |
| 3177 | fcport->port_type != FCT_BROADCAST && |
| 3178 | (fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 3179 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3180 | ql_dbg(ql_dbg_disc, vha, 0x2019, |
| 3181 | "Marking port lost loop_id=0x%04x.\n", |
| 3182 | fcport->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3183 | |
Chad Dupuis | ec426e1 | 2011-03-30 11:46:32 -0700 | [diff] [blame] | 3184 | qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3185 | } |
| 3186 | } |
| 3187 | |
| 3188 | /* Add devices to port list. */ |
| 3189 | id_iter = (char *)ha->gid_list; |
| 3190 | for (index = 0; index < entries; index++) { |
| 3191 | domain = ((struct gid_list_info *)id_iter)->domain; |
| 3192 | area = ((struct gid_list_info *)id_iter)->area; |
| 3193 | al_pa = ((struct gid_list_info *)id_iter)->al_pa; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3194 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | loop_id = (uint16_t) |
| 3196 | ((struct gid_list_info *)id_iter)->loop_id_2100; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3197 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | loop_id = le16_to_cpu( |
| 3199 | ((struct gid_list_info *)id_iter)->loop_id); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3200 | id_iter += ha->gid_list_info_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3201 | |
| 3202 | /* Bypass reserved domain fields. */ |
| 3203 | if ((domain & 0xf0) == 0xf0) |
| 3204 | continue; |
| 3205 | |
| 3206 | /* Bypass if not same domain and area of adapter. */ |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 3207 | if (area && domain && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3208 | (area != vha->d_id.b.area || domain != vha->d_id.b.domain)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | continue; |
| 3210 | |
| 3211 | /* Bypass invalid local loop ID. */ |
| 3212 | if (loop_id > LAST_LOCAL_LOOP_ID) |
| 3213 | continue; |
| 3214 | |
Arun Easi | 370d550 | 2012-08-22 14:21:10 -0400 | [diff] [blame] | 3215 | memset(new_fcport, 0, sizeof(fc_port_t)); |
| 3216 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3217 | /* Fill in member data. */ |
| 3218 | new_fcport->d_id.b.domain = domain; |
| 3219 | new_fcport->d_id.b.area = area; |
| 3220 | new_fcport->d_id.b.al_pa = al_pa; |
| 3221 | new_fcport->loop_id = loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3222 | rval2 = qla2x00_get_port_database(vha, new_fcport, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3223 | if (rval2 != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3224 | ql_dbg(ql_dbg_disc, vha, 0x201a, |
| 3225 | "Failed to retrieve fcport information " |
| 3226 | "-- get_port_database=%x, loop_id=0x%04x.\n", |
| 3227 | rval2, new_fcport->loop_id); |
| 3228 | ql_dbg(ql_dbg_disc, vha, 0x201b, |
| 3229 | "Scheduling resync.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3230 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3231 | continue; |
| 3232 | } |
| 3233 | |
| 3234 | /* Check for matching device in port list. */ |
| 3235 | found = 0; |
| 3236 | fcport = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3237 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3238 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 3239 | WWN_SIZE)) |
| 3240 | continue; |
| 3241 | |
Shyam Sundar | ddb9b12 | 2009-03-24 09:08:10 -0700 | [diff] [blame] | 3242 | fcport->flags &= ~FCF_FABRIC_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3243 | fcport->loop_id = new_fcport->loop_id; |
| 3244 | fcport->port_type = new_fcport->port_type; |
| 3245 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 3246 | memcpy(fcport->node_name, new_fcport->node_name, |
| 3247 | WWN_SIZE); |
| 3248 | |
| 3249 | found++; |
| 3250 | break; |
| 3251 | } |
| 3252 | |
| 3253 | if (!found) { |
| 3254 | /* New device, add to fcports list. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3255 | list_add_tail(&new_fcport->list, &vha->vp_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3256 | |
| 3257 | /* Allocate a new replacement fcport. */ |
| 3258 | fcport = new_fcport; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3259 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3260 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3261 | ql_log(ql_log_warn, vha, 0x201c, |
| 3262 | "Failed to allocate memory for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3263 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 3264 | goto cleanup_allocation; |
| 3265 | } |
| 3266 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 3267 | } |
| 3268 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3269 | /* Base iIDMA settings on HBA port speed. */ |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 3270 | fcport->fp_speed = ha->link_data_rate; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3271 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3272 | qla2x00_update_fcport(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3273 | |
| 3274 | found_devs++; |
| 3275 | } |
| 3276 | |
| 3277 | cleanup_allocation: |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 3278 | kfree(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3279 | |
| 3280 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3281 | ql_dbg(ql_dbg_disc, vha, 0x201d, |
| 3282 | "Configure local loop error exit: rval=%x.\n", rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3283 | } |
| 3284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3285 | return (rval); |
| 3286 | } |
| 3287 | |
| 3288 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3289 | qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3290 | { |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3291 | int rval; |
Quinn Tran | 93f2bd6 | 2014-09-25 05:16:53 -0400 | [diff] [blame] | 3292 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3293 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3294 | |
Andrew Vasquez | c76f2c0 | 2007-07-19 15:05:57 -0700 | [diff] [blame] | 3295 | if (!IS_IIDMA_CAPABLE(ha)) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3296 | return; |
| 3297 | |
Giridhar Malavali | c9afb9a | 2010-09-03 15:20:48 -0700 | [diff] [blame] | 3298 | if (atomic_read(&fcport->state) != FCS_ONLINE) |
| 3299 | return; |
| 3300 | |
Andrew Vasquez | 39bd962 | 2007-09-20 14:07:34 -0700 | [diff] [blame] | 3301 | if (fcport->fp_speed == PORT_SPEED_UNKNOWN || |
| 3302 | fcport->fp_speed > ha->link_data_rate) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3303 | return; |
| 3304 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3305 | rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed, |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 3306 | mb); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3307 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3308 | ql_dbg(ql_dbg_disc, vha, 0x2004, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 3309 | "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n", |
| 3310 | fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3311 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3312 | ql_dbg(ql_dbg_disc, vha, 0x2005, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 3313 | "iIDMA adjusted to %s GB/s on %8phN.\n", |
Joe Carnuccio | d0297c9 | 2012-11-21 02:40:40 -0500 | [diff] [blame] | 3314 | qla2x00_get_link_speed_str(ha, fcport->fp_speed), |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 3315 | fcport->port_name); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3316 | } |
| 3317 | } |
| 3318 | |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 3319 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3320 | qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 3321 | { |
| 3322 | struct fc_rport_identifiers rport_ids; |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 3323 | struct fc_rport *rport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 3324 | unsigned long flags; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 3325 | |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 3326 | rport_ids.node_name = wwn_to_u64(fcport->node_name); |
| 3327 | rport_ids.port_name = wwn_to_u64(fcport->port_name); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 3328 | rport_ids.port_id = fcport->d_id.b.domain << 16 | |
| 3329 | fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa; |
| 3330 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3331 | fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 3332 | if (!rport) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3333 | ql_log(ql_log_warn, vha, 0x2006, |
| 3334 | "Unable to allocate fc remote port.\n"); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 3335 | return; |
| 3336 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3337 | /* |
| 3338 | * Create target mode FC NEXUS in qla_target.c if target mode is |
| 3339 | * enabled.. |
| 3340 | */ |
Saurav Kashyap | ba9f6f6 | 2015-06-10 11:05:17 -0400 | [diff] [blame] | 3341 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3342 | qlt_fc_port_added(vha, fcport); |
| 3343 | |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 3344 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3345 | *((fc_port_t **)rport->dd_data) = fcport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 3346 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3347 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 3348 | rport->supported_classes = fcport->supported_classes; |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 3349 | |
| 3350 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 3351 | if (fcport->port_type == FCT_INITIATOR) |
| 3352 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 3353 | if (fcport->port_type == FCT_TARGET) |
| 3354 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 3355 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 3356 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3357 | |
| 3358 | /* |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 3359 | * qla2x00_update_fcport |
| 3360 | * Updates device on list. |
| 3361 | * |
| 3362 | * Input: |
| 3363 | * ha = adapter block pointer. |
| 3364 | * fcport = port structure pointer. |
| 3365 | * |
| 3366 | * Return: |
| 3367 | * 0 - Success |
| 3368 | * BIT_0 - error |
| 3369 | * |
| 3370 | * Context: |
| 3371 | * Kernel context. |
| 3372 | */ |
| 3373 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3374 | qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 3375 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3376 | fcport->vha = vha; |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3377 | |
| 3378 | if (IS_QLAFX00(vha->hw)) { |
| 3379 | qla2x00_set_fcport_state(fcport, FCS_ONLINE); |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 3380 | goto reg_port; |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3381 | } |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 3382 | fcport->login_retry = 0; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 3383 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 3384 | |
Joe Carnuccio | 1f93da52 | 2012-11-21 02:40:38 -0500 | [diff] [blame] | 3385 | qla2x00_set_fcport_state(fcport, FCS_ONLINE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3386 | qla2x00_iidma_fcport(vha, fcport); |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 3387 | qla24xx_update_fcport_fcp_prio(vha, fcport); |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 3388 | |
| 3389 | reg_port: |
| 3390 | if (qla_ini_mode_enabled(vha)) |
| 3391 | qla2x00_reg_remote_port(vha, fcport); |
| 3392 | else { |
| 3393 | /* |
| 3394 | * Create target mode FC NEXUS in qla_target.c |
| 3395 | */ |
| 3396 | qlt_fc_port_added(vha, fcport); |
| 3397 | } |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 3398 | } |
| 3399 | |
| 3400 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3401 | * qla2x00_configure_fabric |
| 3402 | * Setup SNS devices with loop ID's. |
| 3403 | * |
| 3404 | * Input: |
| 3405 | * ha = adapter block pointer. |
| 3406 | * |
| 3407 | * Returns: |
| 3408 | * 0 = success. |
| 3409 | * BIT_0 = error |
| 3410 | */ |
| 3411 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3412 | qla2x00_configure_fabric(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3413 | { |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 3414 | int rval; |
Joe Carnuccio | e452ceb | 2013-02-08 01:57:56 -0500 | [diff] [blame] | 3415 | fc_port_t *fcport, *fcptemp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3416 | uint16_t next_loopid; |
| 3417 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3418 | uint16_t loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3419 | LIST_HEAD(new_fcports); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3420 | struct qla_hw_data *ha = vha->hw; |
| 3421 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 3422 | int discovery_gen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3423 | |
| 3424 | /* If FL port exists, then SNS is present */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 3425 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3426 | loop_id = NPH_F_PORT; |
| 3427 | else |
| 3428 | loop_id = SNS_FL_PORT; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3429 | rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3430 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3431 | ql_dbg(ql_dbg_disc, vha, 0x201f, |
| 3432 | "MBX_GET_PORT_NAME failed, No FL Port.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3433 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3434 | vha->device_flags &= ~SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3435 | return (QLA_SUCCESS); |
| 3436 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3437 | vha->device_flags |= SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3438 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3439 | do { |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 3440 | /* FDMI support. */ |
| 3441 | if (ql2xfdmienable && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3442 | test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags)) |
| 3443 | qla2x00_fdmi_register(vha); |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 3444 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3445 | /* Ensure we are logged into the SNS. */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 3446 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3447 | loop_id = NPH_SNS; |
| 3448 | else |
| 3449 | loop_id = SIMPLE_NAME_SERVER; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 3450 | rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff, |
| 3451 | 0xfc, mb, BIT_1|BIT_0); |
| 3452 | if (rval != QLA_SUCCESS) { |
| 3453 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Joe Carnuccio | e452ceb | 2013-02-08 01:57:56 -0500 | [diff] [blame] | 3454 | return rval; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 3455 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3456 | if (mb[0] != MBS_COMMAND_COMPLETE) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3457 | ql_dbg(ql_dbg_disc, vha, 0x2042, |
| 3458 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x " |
| 3459 | "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1], |
| 3460 | mb[2], mb[6], mb[7]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3461 | return (QLA_SUCCESS); |
| 3462 | } |
| 3463 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3464 | if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) { |
| 3465 | if (qla2x00_rft_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3466 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3467 | ql_dbg(ql_dbg_disc, vha, 0x2045, |
| 3468 | "Register FC-4 TYPE failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3469 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3470 | if (qla2x00_rff_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3471 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3472 | ql_dbg(ql_dbg_disc, vha, 0x2049, |
| 3473 | "Register FC-4 Features failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3474 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3475 | if (qla2x00_rnn_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3476 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3477 | ql_dbg(ql_dbg_disc, vha, 0x204f, |
| 3478 | "Register Node Name failed.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3479 | } else if (qla2x00_rsnn_nn(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3480 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3481 | ql_dbg(ql_dbg_disc, vha, 0x2053, |
| 3482 | "Register Symobilic Node Name failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3483 | } |
| 3484 | } |
| 3485 | |
Joe Carnuccio | 827210b | 2013-02-08 01:57:57 -0500 | [diff] [blame] | 3486 | #define QLA_FCPORT_SCAN 1 |
| 3487 | #define QLA_FCPORT_FOUND 2 |
| 3488 | |
| 3489 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 3490 | fcport->scan_state = QLA_FCPORT_SCAN; |
| 3491 | } |
| 3492 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 3493 | /* Mark the time right before querying FW for connected ports. |
| 3494 | * This process is long, asynchronous and by the time it's done, |
| 3495 | * collected information might not be accurate anymore. E.g. |
| 3496 | * disconnected port might have re-connected and a brand new |
| 3497 | * session has been created. In this case session's generation |
| 3498 | * will be newer than discovery_gen. */ |
| 3499 | qlt_do_generation_tick(vha, &discovery_gen); |
| 3500 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3501 | rval = qla2x00_find_all_fabric_devs(vha, &new_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3502 | if (rval != QLA_SUCCESS) |
| 3503 | break; |
| 3504 | |
Joe Carnuccio | e452ceb | 2013-02-08 01:57:56 -0500 | [diff] [blame] | 3505 | /* |
| 3506 | * Logout all previous fabric devices marked lost, except |
| 3507 | * FCP2 devices. |
| 3508 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3509 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 3510 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3511 | break; |
| 3512 | |
| 3513 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) |
| 3514 | continue; |
| 3515 | |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 3516 | if (fcport->scan_state == QLA_FCPORT_SCAN) { |
| 3517 | if (qla_ini_mode_enabled(base_vha) && |
| 3518 | atomic_read(&fcport->state) == FCS_ONLINE) { |
| 3519 | qla2x00_mark_device_lost(vha, fcport, |
| 3520 | ql2xplogiabsentdevice, 0); |
| 3521 | if (fcport->loop_id != FC_NO_LOOP_ID && |
| 3522 | (fcport->flags & FCF_FCP2_DEVICE) == 0 && |
| 3523 | fcport->port_type != FCT_INITIATOR && |
| 3524 | fcport->port_type != FCT_BROADCAST) { |
| 3525 | ha->isp_ops->fabric_logout(vha, |
| 3526 | fcport->loop_id, |
| 3527 | fcport->d_id.b.domain, |
| 3528 | fcport->d_id.b.area, |
| 3529 | fcport->d_id.b.al_pa); |
| 3530 | qla2x00_clear_loop_id(fcport); |
| 3531 | } |
| 3532 | } else if (!qla_ini_mode_enabled(base_vha)) { |
| 3533 | /* |
| 3534 | * In target mode, explicitly kill |
| 3535 | * sessions and log out of devices |
| 3536 | * that are gone, so that we don't |
| 3537 | * end up with an initiator using the |
| 3538 | * wrong ACL (if the fabric recycles |
| 3539 | * an FC address and we have a stale |
| 3540 | * session around) and so that we don't |
| 3541 | * report initiators that are no longer |
| 3542 | * on the fabric. |
| 3543 | */ |
| 3544 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf077, |
| 3545 | "port gone, logging out/killing session: " |
| 3546 | "%8phC state 0x%x flags 0x%x fc4_type 0x%x " |
| 3547 | "scan_state %d\n", |
| 3548 | fcport->port_name, |
| 3549 | atomic_read(&fcport->state), |
| 3550 | fcport->flags, fcport->fc4_type, |
| 3551 | fcport->scan_state); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 3552 | qlt_fc_port_deleted(vha, fcport, |
| 3553 | discovery_gen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3554 | } |
| 3555 | } |
Joe Carnuccio | e452ceb | 2013-02-08 01:57:56 -0500 | [diff] [blame] | 3556 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3557 | |
Joe Carnuccio | e452ceb | 2013-02-08 01:57:56 -0500 | [diff] [blame] | 3558 | /* Starting free loop ID. */ |
| 3559 | next_loopid = ha->min_external_loopid; |
| 3560 | |
| 3561 | /* |
| 3562 | * Scan through our port list and login entries that need to be |
| 3563 | * logged in. |
| 3564 | */ |
| 3565 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 3566 | if (atomic_read(&vha->loop_down_timer) || |
| 3567 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 3568 | break; |
| 3569 | |
| 3570 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 || |
| 3571 | (fcport->flags & FCF_LOGIN_NEEDED) == 0) |
| 3572 | continue; |
| 3573 | |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 3574 | /* |
| 3575 | * If we're not an initiator, skip looking for devices |
| 3576 | * and logging in. There's no reason for us to do it, |
| 3577 | * and it seems to actively cause problems in target |
| 3578 | * mode if we race with the initiator logging into us |
| 3579 | * (we might get the "port ID used" status back from |
| 3580 | * our login command and log out the initiator, which |
| 3581 | * seems to cause havoc). |
| 3582 | */ |
| 3583 | if (!qla_ini_mode_enabled(base_vha)) { |
| 3584 | if (fcport->scan_state == QLA_FCPORT_FOUND) { |
| 3585 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf078, |
| 3586 | "port %8phC state 0x%x flags 0x%x fc4_type 0x%x " |
| 3587 | "scan_state %d (initiator mode disabled; skipping " |
| 3588 | "login)\n", fcport->port_name, |
| 3589 | atomic_read(&fcport->state), |
| 3590 | fcport->flags, fcport->fc4_type, |
| 3591 | fcport->scan_state); |
| 3592 | } |
| 3593 | continue; |
| 3594 | } |
| 3595 | |
Joe Carnuccio | e452ceb | 2013-02-08 01:57:56 -0500 | [diff] [blame] | 3596 | if (fcport->loop_id == FC_NO_LOOP_ID) { |
| 3597 | fcport->loop_id = next_loopid; |
| 3598 | rval = qla2x00_find_new_loop_id( |
| 3599 | base_vha, fcport); |
| 3600 | if (rval != QLA_SUCCESS) { |
| 3601 | /* Ran out of IDs to use */ |
| 3602 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3603 | } |
| 3604 | } |
Joe Carnuccio | e452ceb | 2013-02-08 01:57:56 -0500 | [diff] [blame] | 3605 | /* Login and update database */ |
| 3606 | qla2x00_fabric_dev_login(vha, fcport, &next_loopid); |
| 3607 | } |
| 3608 | |
| 3609 | /* Exit if out of loop IDs. */ |
| 3610 | if (rval != QLA_SUCCESS) { |
| 3611 | break; |
| 3612 | } |
| 3613 | |
| 3614 | /* |
| 3615 | * Login and add the new devices to our port list. |
| 3616 | */ |
| 3617 | list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) { |
| 3618 | if (atomic_read(&vha->loop_down_timer) || |
| 3619 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 3620 | break; |
| 3621 | |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 3622 | /* |
| 3623 | * If we're not an initiator, skip looking for devices |
| 3624 | * and logging in. There's no reason for us to do it, |
| 3625 | * and it seems to actively cause problems in target |
| 3626 | * mode if we race with the initiator logging into us |
| 3627 | * (we might get the "port ID used" status back from |
| 3628 | * our login command and log out the initiator, which |
| 3629 | * seems to cause havoc). |
| 3630 | */ |
| 3631 | if (qla_ini_mode_enabled(base_vha)) { |
| 3632 | /* Find a new loop ID to use. */ |
| 3633 | fcport->loop_id = next_loopid; |
| 3634 | rval = qla2x00_find_new_loop_id(base_vha, |
| 3635 | fcport); |
| 3636 | if (rval != QLA_SUCCESS) { |
| 3637 | /* Ran out of IDs to use */ |
| 3638 | break; |
| 3639 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3640 | |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 3641 | /* Login and update database */ |
| 3642 | qla2x00_fabric_dev_login(vha, fcport, |
| 3643 | &next_loopid); |
| 3644 | } else { |
| 3645 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf079, |
| 3646 | "new port %8phC state 0x%x flags 0x%x fc4_type " |
| 3647 | "0x%x scan_state %d (initiator mode disabled; " |
| 3648 | "skipping login)\n", |
| 3649 | fcport->port_name, |
| 3650 | atomic_read(&fcport->state), |
| 3651 | fcport->flags, fcport->fc4_type, |
| 3652 | fcport->scan_state); |
| 3653 | } |
Joe Carnuccio | e452ceb | 2013-02-08 01:57:56 -0500 | [diff] [blame] | 3654 | |
| 3655 | list_move_tail(&fcport->list, &vha->vp_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3656 | } |
| 3657 | } while (0); |
| 3658 | |
Joe Carnuccio | e452ceb | 2013-02-08 01:57:56 -0500 | [diff] [blame] | 3659 | /* Free all new device structures not processed. */ |
| 3660 | list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) { |
| 3661 | list_del(&fcport->list); |
| 3662 | kfree(fcport); |
| 3663 | } |
| 3664 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3665 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3666 | ql_dbg(ql_dbg_disc, vha, 0x2068, |
| 3667 | "Configure fabric error exit rval=%d.\n", rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3668 | } |
| 3669 | |
| 3670 | return (rval); |
| 3671 | } |
| 3672 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3673 | /* |
| 3674 | * qla2x00_find_all_fabric_devs |
| 3675 | * |
| 3676 | * Input: |
| 3677 | * ha = adapter block pointer. |
| 3678 | * dev = database device entry pointer. |
| 3679 | * |
| 3680 | * Returns: |
| 3681 | * 0 = success. |
| 3682 | * |
| 3683 | * Context: |
| 3684 | * Kernel context. |
| 3685 | */ |
| 3686 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3687 | qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha, |
| 3688 | struct list_head *new_fcports) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3689 | { |
| 3690 | int rval; |
| 3691 | uint16_t loop_id; |
| 3692 | fc_port_t *fcport, *new_fcport, *fcptemp; |
| 3693 | int found; |
| 3694 | |
| 3695 | sw_info_t *swl; |
| 3696 | int swl_idx; |
| 3697 | int first_dev, last_dev; |
Mike Waychison | 1516ef4 | 2010-05-04 15:01:31 -0700 | [diff] [blame] | 3698 | port_id_t wrap = {}, nxt_d_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3699 | struct qla_hw_data *ha = vha->hw; |
Chad Dupuis | bb4cf5b | 2013-02-08 01:58:01 -0500 | [diff] [blame] | 3700 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3701 | |
| 3702 | rval = QLA_SUCCESS; |
| 3703 | |
| 3704 | /* Try GID_PT to get device list, else GAN. */ |
Andrew Vasquez | 7a67735 | 2012-02-09 11:15:56 -0800 | [diff] [blame] | 3705 | if (!ha->swl) |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 3706 | ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t), |
Andrew Vasquez | 7a67735 | 2012-02-09 11:15:56 -0800 | [diff] [blame] | 3707 | GFP_KERNEL); |
| 3708 | swl = ha->swl; |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 3709 | if (!swl) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3710 | /*EMPTY*/ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3711 | ql_dbg(ql_dbg_disc, vha, 0x2054, |
| 3712 | "GID_PT allocations failed, fallback on GA_NXT.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3713 | } else { |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 3714 | memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3715 | if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3716 | swl = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3717 | } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3718 | swl = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3719 | } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3720 | swl = NULL; |
Andrew Vasquez | e5896bd | 2008-07-10 16:55:52 -0700 | [diff] [blame] | 3721 | } else if (ql2xiidmaenable && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3722 | qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) { |
| 3723 | qla2x00_gpsc(vha, swl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3724 | } |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3725 | |
| 3726 | /* If other queries succeeded probe for FC-4 type */ |
| 3727 | if (swl) |
| 3728 | qla2x00_gff_id(vha, swl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3729 | } |
| 3730 | swl_idx = 0; |
| 3731 | |
| 3732 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3733 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3734 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3735 | ql_log(ql_log_warn, vha, 0x205e, |
| 3736 | "Failed to allocate memory for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3737 | return (QLA_MEMORY_ALLOC_FAILED); |
| 3738 | } |
| 3739 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3740 | /* Set start port ID scan at adapter ID. */ |
| 3741 | first_dev = 1; |
| 3742 | last_dev = 0; |
| 3743 | |
| 3744 | /* Starting free loop ID. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3745 | loop_id = ha->min_external_loopid; |
| 3746 | for (; loop_id <= ha->max_loop_id; loop_id++) { |
| 3747 | if (qla2x00_is_reserved_id(vha, loop_id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3748 | continue; |
| 3749 | |
Giridhar Malavali | 3a6478d | 2010-05-28 15:08:20 -0700 | [diff] [blame] | 3750 | if (ha->current_topology == ISP_CFG_FL && |
| 3751 | (atomic_read(&vha->loop_down_timer) || |
| 3752 | LOOP_TRANSITION(vha))) { |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 3753 | atomic_set(&vha->loop_down_timer, 0); |
| 3754 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 3755 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3756 | break; |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 3757 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3758 | |
| 3759 | if (swl != NULL) { |
| 3760 | if (last_dev) { |
| 3761 | wrap.b24 = new_fcport->d_id.b24; |
| 3762 | } else { |
| 3763 | new_fcport->d_id.b24 = swl[swl_idx].d_id.b24; |
| 3764 | memcpy(new_fcport->node_name, |
| 3765 | swl[swl_idx].node_name, WWN_SIZE); |
| 3766 | memcpy(new_fcport->port_name, |
| 3767 | swl[swl_idx].port_name, WWN_SIZE); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3768 | memcpy(new_fcport->fabric_port_name, |
| 3769 | swl[swl_idx].fabric_port_name, WWN_SIZE); |
| 3770 | new_fcport->fp_speed = swl[swl_idx].fp_speed; |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3771 | new_fcport->fc4_type = swl[swl_idx].fc4_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3772 | |
| 3773 | if (swl[swl_idx].d_id.b.rsvd_1 != 0) { |
| 3774 | last_dev = 1; |
| 3775 | } |
| 3776 | swl_idx++; |
| 3777 | } |
| 3778 | } else { |
| 3779 | /* Send GA_NXT to the switch */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3780 | rval = qla2x00_ga_nxt(vha, new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3781 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3782 | ql_log(ql_log_warn, vha, 0x2064, |
| 3783 | "SNS scan failed -- assuming " |
| 3784 | "zero-entry result.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3785 | list_for_each_entry_safe(fcport, fcptemp, |
| 3786 | new_fcports, list) { |
| 3787 | list_del(&fcport->list); |
| 3788 | kfree(fcport); |
| 3789 | } |
| 3790 | rval = QLA_SUCCESS; |
| 3791 | break; |
| 3792 | } |
| 3793 | } |
| 3794 | |
| 3795 | /* If wrap on switch device list, exit. */ |
| 3796 | if (first_dev) { |
| 3797 | wrap.b24 = new_fcport->d_id.b24; |
| 3798 | first_dev = 0; |
| 3799 | } else if (new_fcport->d_id.b24 == wrap.b24) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3800 | ql_dbg(ql_dbg_disc, vha, 0x2065, |
| 3801 | "Device wrap (%02x%02x%02x).\n", |
| 3802 | new_fcport->d_id.b.domain, |
| 3803 | new_fcport->d_id.b.area, |
| 3804 | new_fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3805 | break; |
| 3806 | } |
| 3807 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3808 | /* Bypass if same physical adapter. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3809 | if (new_fcport->d_id.b24 == base_vha->d_id.b24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3810 | continue; |
| 3811 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3812 | /* Bypass virtual ports of the same host. */ |
Chad Dupuis | bb4cf5b | 2013-02-08 01:58:01 -0500 | [diff] [blame] | 3813 | if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24)) |
| 3814 | continue; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3815 | |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 3816 | /* Bypass if same domain and area of adapter. */ |
| 3817 | if (((new_fcport->d_id.b24 & 0xffff00) == |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3818 | (vha->d_id.b24 & 0xffff00)) && ha->current_topology == |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 3819 | ISP_CFG_FL) |
| 3820 | continue; |
| 3821 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3822 | /* Bypass reserved domain fields. */ |
| 3823 | if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0) |
| 3824 | continue; |
| 3825 | |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3826 | /* Bypass ports whose FCP-4 type is not FCP_SCSI */ |
Chad Dupuis | 4da26e1 | 2010-10-15 11:27:40 -0700 | [diff] [blame] | 3827 | if (ql2xgffidenable && |
| 3828 | (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI && |
| 3829 | new_fcport->fc4_type != FC4_TYPE_UNKNOWN)) |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3830 | continue; |
| 3831 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3832 | /* Locate matching device in database. */ |
| 3833 | found = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3834 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3835 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 3836 | WWN_SIZE)) |
| 3837 | continue; |
| 3838 | |
Joe Carnuccio | 827210b | 2013-02-08 01:57:57 -0500 | [diff] [blame] | 3839 | fcport->scan_state = QLA_FCPORT_FOUND; |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 3840 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3841 | found++; |
| 3842 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3843 | /* Update port state. */ |
| 3844 | memcpy(fcport->fabric_port_name, |
| 3845 | new_fcport->fabric_port_name, WWN_SIZE); |
| 3846 | fcport->fp_speed = new_fcport->fp_speed; |
| 3847 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3848 | /* |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 3849 | * If address the same and state FCS_ONLINE |
| 3850 | * (or in target mode), nothing changed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3851 | */ |
| 3852 | if (fcport->d_id.b24 == new_fcport->d_id.b24 && |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 3853 | (atomic_read(&fcport->state) == FCS_ONLINE || |
| 3854 | !qla_ini_mode_enabled(base_vha))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3855 | break; |
| 3856 | } |
| 3857 | |
| 3858 | /* |
| 3859 | * If device was not a fabric device before. |
| 3860 | */ |
| 3861 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 3862 | fcport->d_id.b24 = new_fcport->d_id.b24; |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3863 | qla2x00_clear_loop_id(fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3864 | fcport->flags |= (FCF_FABRIC_DEVICE | |
| 3865 | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3866 | break; |
| 3867 | } |
| 3868 | |
| 3869 | /* |
| 3870 | * Port ID changed or device was marked to be updated; |
| 3871 | * Log it out if still logged in and mark it for |
| 3872 | * relogin later. |
| 3873 | */ |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 3874 | if (!qla_ini_mode_enabled(base_vha)) { |
| 3875 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080, |
| 3876 | "port changed FC ID, %8phC" |
| 3877 | " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n", |
| 3878 | fcport->port_name, |
| 3879 | fcport->d_id.b.domain, |
| 3880 | fcport->d_id.b.area, |
| 3881 | fcport->d_id.b.al_pa, |
| 3882 | fcport->loop_id, |
| 3883 | new_fcport->d_id.b.domain, |
| 3884 | new_fcport->d_id.b.area, |
| 3885 | new_fcport->d_id.b.al_pa); |
| 3886 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 3887 | break; |
| 3888 | } |
| 3889 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3890 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 3891 | fcport->flags |= FCF_LOGIN_NEEDED; |
| 3892 | if (fcport->loop_id != FC_NO_LOOP_ID && |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3893 | (fcport->flags & FCF_FCP2_DEVICE) == 0 && |
Arun Easi | 0eba25d | 2012-02-09 11:15:58 -0800 | [diff] [blame] | 3894 | (fcport->flags & FCF_ASYNC_SENT) == 0 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3895 | fcport->port_type != FCT_INITIATOR && |
| 3896 | fcport->port_type != FCT_BROADCAST) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3897 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3898 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3899 | fcport->d_id.b.al_pa); |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3900 | qla2x00_clear_loop_id(fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3901 | } |
| 3902 | |
| 3903 | break; |
| 3904 | } |
| 3905 | |
| 3906 | if (found) |
| 3907 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3908 | /* If device was not in our fcports list, then add it. */ |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 3909 | new_fcport->scan_state = QLA_FCPORT_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3910 | list_add_tail(&new_fcport->list, new_fcports); |
| 3911 | |
| 3912 | /* Allocate a new replacement fcport. */ |
| 3913 | nxt_d_id.b24 = new_fcport->d_id.b24; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3914 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3915 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3916 | ql_log(ql_log_warn, vha, 0x2066, |
| 3917 | "Memory allocation failed for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3918 | return (QLA_MEMORY_ALLOC_FAILED); |
| 3919 | } |
| 3920 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
| 3921 | new_fcport->d_id.b24 = nxt_d_id.b24; |
| 3922 | } |
| 3923 | |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 3924 | kfree(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3925 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3926 | return (rval); |
| 3927 | } |
| 3928 | |
| 3929 | /* |
| 3930 | * qla2x00_find_new_loop_id |
| 3931 | * Scan through our port list and find a new usable loop ID. |
| 3932 | * |
| 3933 | * Input: |
| 3934 | * ha: adapter state pointer. |
| 3935 | * dev: port structure pointer. |
| 3936 | * |
| 3937 | * Returns: |
| 3938 | * qla2x00 local function return status code. |
| 3939 | * |
| 3940 | * Context: |
| 3941 | * Kernel context. |
| 3942 | */ |
Joe Carnuccio | 03bcfb5 | 2011-03-30 11:46:27 -0700 | [diff] [blame] | 3943 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3944 | qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3945 | { |
| 3946 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3947 | struct qla_hw_data *ha = vha->hw; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3948 | unsigned long flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3949 | |
| 3950 | rval = QLA_SUCCESS; |
| 3951 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3952 | spin_lock_irqsave(&ha->vport_slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3953 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3954 | dev->loop_id = find_first_zero_bit(ha->loop_id_map, |
| 3955 | LOOPID_MAP_SIZE); |
| 3956 | if (dev->loop_id >= LOOPID_MAP_SIZE || |
| 3957 | qla2x00_is_reserved_id(vha, dev->loop_id)) { |
| 3958 | dev->loop_id = FC_NO_LOOP_ID; |
| 3959 | rval = QLA_FUNCTION_FAILED; |
| 3960 | } else |
| 3961 | set_bit(dev->loop_id, ha->loop_id_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3962 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3963 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3964 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3965 | if (rval == QLA_SUCCESS) |
| 3966 | ql_dbg(ql_dbg_disc, dev->vha, 0x2086, |
| 3967 | "Assigning new loopid=%x, portid=%x.\n", |
| 3968 | dev->loop_id, dev->d_id.b24); |
| 3969 | else |
| 3970 | ql_log(ql_log_warn, dev->vha, 0x2087, |
| 3971 | "No loop_id's available, portid=%x.\n", |
| 3972 | dev->d_id.b24); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3973 | |
| 3974 | return (rval); |
| 3975 | } |
| 3976 | |
| 3977 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3978 | * qla2x00_fabric_dev_login |
| 3979 | * Login fabric target device and update FC port database. |
| 3980 | * |
| 3981 | * Input: |
| 3982 | * ha: adapter state pointer. |
| 3983 | * fcport: port structure list pointer. |
| 3984 | * next_loopid: contains value of a new loop ID that can be used |
| 3985 | * by the next login attempt. |
| 3986 | * |
| 3987 | * Returns: |
| 3988 | * qla2x00 local function return status code. |
| 3989 | * |
| 3990 | * Context: |
| 3991 | * Kernel context. |
| 3992 | */ |
| 3993 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3994 | qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3995 | uint16_t *next_loopid) |
| 3996 | { |
| 3997 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3998 | uint8_t opts; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3999 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4000 | |
| 4001 | rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4002 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 4003 | if (IS_ALOGIO_CAPABLE(ha)) { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 4004 | if (fcport->flags & FCF_ASYNC_SENT) |
| 4005 | return rval; |
| 4006 | fcport->flags |= FCF_ASYNC_SENT; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 4007 | rval = qla2x00_post_async_login_work(vha, fcport, NULL); |
| 4008 | if (!rval) |
| 4009 | return rval; |
| 4010 | } |
| 4011 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 4012 | fcport->flags &= ~FCF_ASYNC_SENT; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4013 | rval = qla2x00_fabric_login(vha, fcport, next_loopid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4014 | if (rval == QLA_SUCCESS) { |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 4015 | /* Send an ADISC to FCP2 devices.*/ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4016 | opts = 0; |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 4017 | if (fcport->flags & FCF_FCP2_DEVICE) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4018 | opts |= BIT_1; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4019 | rval = qla2x00_get_port_database(vha, fcport, opts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4020 | if (rval != QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4021 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 4022 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 4023 | fcport->d_id.b.al_pa); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4024 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4025 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4026 | qla2x00_update_fcport(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4027 | } |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 4028 | } else { |
| 4029 | /* Retry Login. */ |
| 4030 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4031 | } |
| 4032 | |
| 4033 | return (rval); |
| 4034 | } |
| 4035 | |
| 4036 | /* |
| 4037 | * qla2x00_fabric_login |
| 4038 | * Issue fabric login command. |
| 4039 | * |
| 4040 | * Input: |
| 4041 | * ha = adapter block pointer. |
| 4042 | * device = pointer to FC device type structure. |
| 4043 | * |
| 4044 | * Returns: |
| 4045 | * 0 - Login successfully |
| 4046 | * 1 - Login failed |
| 4047 | * 2 - Initiator device |
| 4048 | * 3 - Fatal error |
| 4049 | */ |
| 4050 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4051 | qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4052 | uint16_t *next_loopid) |
| 4053 | { |
| 4054 | int rval; |
| 4055 | int retry; |
| 4056 | uint16_t tmp_loopid; |
| 4057 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4058 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4059 | |
| 4060 | retry = 0; |
| 4061 | tmp_loopid = 0; |
| 4062 | |
| 4063 | for (;;) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4064 | ql_dbg(ql_dbg_disc, vha, 0x2000, |
| 4065 | "Trying Fabric Login w/loop id 0x%04x for port " |
| 4066 | "%02x%02x%02x.\n", |
| 4067 | fcport->loop_id, fcport->d_id.b.domain, |
| 4068 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4069 | |
| 4070 | /* Login fcport on switch. */ |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 4071 | rval = ha->isp_ops->fabric_login(vha, fcport->loop_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4072 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 4073 | fcport->d_id.b.al_pa, mb, BIT_0); |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 4074 | if (rval != QLA_SUCCESS) { |
| 4075 | return rval; |
| 4076 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4077 | if (mb[0] == MBS_PORT_ID_USED) { |
| 4078 | /* |
| 4079 | * Device has another loop ID. The firmware team |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4080 | * recommends the driver perform an implicit login with |
| 4081 | * the specified ID again. The ID we just used is save |
| 4082 | * here so we return with an ID that can be tried by |
| 4083 | * the next login. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4084 | */ |
| 4085 | retry++; |
| 4086 | tmp_loopid = fcport->loop_id; |
| 4087 | fcport->loop_id = mb[1]; |
| 4088 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4089 | ql_dbg(ql_dbg_disc, vha, 0x2001, |
| 4090 | "Fabric Login: port in use - next loop " |
| 4091 | "id=0x%04x, port id= %02x%02x%02x.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4092 | fcport->loop_id, fcport->d_id.b.domain, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4093 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4094 | |
| 4095 | } else if (mb[0] == MBS_COMMAND_COMPLETE) { |
| 4096 | /* |
| 4097 | * Login succeeded. |
| 4098 | */ |
| 4099 | if (retry) { |
| 4100 | /* A retry occurred before. */ |
| 4101 | *next_loopid = tmp_loopid; |
| 4102 | } else { |
| 4103 | /* |
| 4104 | * No retry occurred before. Just increment the |
| 4105 | * ID value for next login. |
| 4106 | */ |
| 4107 | *next_loopid = (fcport->loop_id + 1); |
| 4108 | } |
| 4109 | |
| 4110 | if (mb[1] & BIT_0) { |
| 4111 | fcport->port_type = FCT_INITIATOR; |
| 4112 | } else { |
| 4113 | fcport->port_type = FCT_TARGET; |
| 4114 | if (mb[1] & BIT_1) { |
Santosh Vernekar | 8474f3a | 2009-08-25 11:36:16 -0700 | [diff] [blame] | 4115 | fcport->flags |= FCF_FCP2_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4116 | } |
| 4117 | } |
| 4118 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 4119 | if (mb[10] & BIT_0) |
| 4120 | fcport->supported_classes |= FC_COS_CLASS2; |
| 4121 | if (mb[10] & BIT_1) |
| 4122 | fcport->supported_classes |= FC_COS_CLASS3; |
| 4123 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4124 | if (IS_FWI2_CAPABLE(ha)) { |
| 4125 | if (mb[10] & BIT_7) |
| 4126 | fcport->flags |= |
| 4127 | FCF_CONF_COMP_SUPPORTED; |
| 4128 | } |
| 4129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4130 | rval = QLA_SUCCESS; |
| 4131 | break; |
| 4132 | } else if (mb[0] == MBS_LOOP_ID_USED) { |
| 4133 | /* |
| 4134 | * Loop ID already used, try next loop ID. |
| 4135 | */ |
| 4136 | fcport->loop_id++; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4137 | rval = qla2x00_find_new_loop_id(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4138 | if (rval != QLA_SUCCESS) { |
| 4139 | /* Ran out of loop IDs to use */ |
| 4140 | break; |
| 4141 | } |
| 4142 | } else if (mb[0] == MBS_COMMAND_ERROR) { |
| 4143 | /* |
| 4144 | * Firmware possibly timed out during login. If NO |
| 4145 | * retries are left to do then the device is declared |
| 4146 | * dead. |
| 4147 | */ |
| 4148 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4149 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 4150 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 4151 | fcport->d_id.b.al_pa); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4152 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4153 | |
| 4154 | rval = 1; |
| 4155 | break; |
| 4156 | } else { |
| 4157 | /* |
| 4158 | * unrecoverable / not handled error |
| 4159 | */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4160 | ql_dbg(ql_dbg_disc, vha, 0x2002, |
| 4161 | "Failed=%x port_id=%02x%02x%02x loop_id=%x " |
| 4162 | "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain, |
| 4163 | fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 4164 | fcport->loop_id, jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4165 | |
| 4166 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4167 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 4168 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 4169 | fcport->d_id.b.al_pa); |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 4170 | qla2x00_clear_loop_id(fcport); |
Andrew Vasquez | 0eedfcf | 2005-10-27 11:09:38 -0700 | [diff] [blame] | 4171 | fcport->login_retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4172 | |
| 4173 | rval = 3; |
| 4174 | break; |
| 4175 | } |
| 4176 | } |
| 4177 | |
| 4178 | return (rval); |
| 4179 | } |
| 4180 | |
| 4181 | /* |
| 4182 | * qla2x00_local_device_login |
| 4183 | * Issue local device login command. |
| 4184 | * |
| 4185 | * Input: |
| 4186 | * ha = adapter block pointer. |
| 4187 | * loop_id = loop id of device to login to. |
| 4188 | * |
| 4189 | * Returns (Where's the #define!!!!): |
| 4190 | * 0 - Login successfully |
| 4191 | * 1 - Login failed |
| 4192 | * 3 - Fatal error |
| 4193 | */ |
| 4194 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4195 | qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4196 | { |
| 4197 | int rval; |
| 4198 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
| 4199 | |
| 4200 | memset(mb, 0, sizeof(mb)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4201 | rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4202 | if (rval == QLA_SUCCESS) { |
| 4203 | /* Interrogate mailbox registers for any errors */ |
| 4204 | if (mb[0] == MBS_COMMAND_ERROR) |
| 4205 | rval = 1; |
| 4206 | else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR) |
| 4207 | /* device not in PCB table */ |
| 4208 | rval = 3; |
| 4209 | } |
| 4210 | |
| 4211 | return (rval); |
| 4212 | } |
| 4213 | |
| 4214 | /* |
| 4215 | * qla2x00_loop_resync |
| 4216 | * Resync with fibre channel devices. |
| 4217 | * |
| 4218 | * Input: |
| 4219 | * ha = adapter block pointer. |
| 4220 | * |
| 4221 | * Returns: |
| 4222 | * 0 = success |
| 4223 | */ |
| 4224 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4225 | qla2x00_loop_resync(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4226 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4227 | int rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4228 | uint32_t wait_time; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 4229 | struct req_que *req; |
| 4230 | struct rsp_que *rsp; |
| 4231 | |
Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 4232 | if (vha->hw->flags.cpu_affinity_enabled) |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 4233 | req = vha->hw->req_q_map[0]; |
| 4234 | else |
| 4235 | req = vha->req; |
| 4236 | rsp = req->rsp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4237 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4238 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 4239 | if (vha->flags.online) { |
| 4240 | if (!(rval = qla2x00_fw_ready(vha))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4241 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 4242 | wait_time = 256; |
| 4243 | do { |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 4244 | if (!IS_QLAFX00(vha->hw)) { |
| 4245 | /* |
| 4246 | * Issue a marker after FW becomes |
| 4247 | * ready. |
| 4248 | */ |
| 4249 | qla2x00_marker(vha, req, rsp, 0, 0, |
| 4250 | MK_SYNC_ALL); |
| 4251 | vha->marker_needed = 0; |
| 4252 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4253 | |
| 4254 | /* Remap devices on Loop. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4255 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4256 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 4257 | if (IS_QLAFX00(vha->hw)) |
| 4258 | qlafx00_configure_devices(vha); |
| 4259 | else |
| 4260 | qla2x00_configure_loop(vha); |
| 4261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4262 | wait_time--; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4263 | } while (!atomic_read(&vha->loop_down_timer) && |
| 4264 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
| 4265 | && wait_time && (test_bit(LOOP_RESYNC_NEEDED, |
| 4266 | &vha->dpc_flags))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4267 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4268 | } |
| 4269 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4270 | if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4271 | return (QLA_FUNCTION_FAILED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4272 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4273 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4274 | ql_dbg(ql_dbg_disc, vha, 0x206c, |
| 4275 | "%s *** FAILED ***.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | |
| 4277 | return (rval); |
| 4278 | } |
| 4279 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4280 | /* |
| 4281 | * qla2x00_perform_loop_resync |
| 4282 | * Description: This function will set the appropriate flags and call |
| 4283 | * qla2x00_loop_resync. If successful loop will be resynced |
| 4284 | * Arguments : scsi_qla_host_t pointer |
| 4285 | * returm : Success or Failure |
| 4286 | */ |
| 4287 | |
| 4288 | int qla2x00_perform_loop_resync(scsi_qla_host_t *ha) |
| 4289 | { |
| 4290 | int32_t rval = 0; |
| 4291 | |
| 4292 | if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) { |
| 4293 | /*Configure the flags so that resync happens properly*/ |
| 4294 | atomic_set(&ha->loop_down_timer, 0); |
| 4295 | if (!(ha->device_flags & DFLG_NO_CABLE)) { |
| 4296 | atomic_set(&ha->loop_state, LOOP_UP); |
| 4297 | set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); |
| 4298 | set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags); |
| 4299 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
| 4300 | |
| 4301 | rval = qla2x00_loop_resync(ha); |
| 4302 | } else |
| 4303 | atomic_set(&ha->loop_state, LOOP_DEAD); |
| 4304 | |
| 4305 | clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags); |
| 4306 | } |
| 4307 | |
| 4308 | return rval; |
| 4309 | } |
| 4310 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4311 | void |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 4312 | qla2x00_update_fcports(scsi_qla_host_t *base_vha) |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 4313 | { |
| 4314 | fc_port_t *fcport; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4315 | struct scsi_qla_host *vha; |
| 4316 | struct qla_hw_data *ha = base_vha->hw; |
| 4317 | unsigned long flags; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 4318 | |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4319 | spin_lock_irqsave(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 4320 | /* Go with deferred removal of rport references. */ |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4321 | list_for_each_entry(vha, &base_vha->hw->vp_list, list) { |
| 4322 | atomic_inc(&vha->vref_count); |
| 4323 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Dan Carpenter | 8ae598d | 2010-12-21 16:00:15 -0800 | [diff] [blame] | 4324 | if (fcport->drport && |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4325 | atomic_read(&fcport->state) != FCS_UNCONFIGURED) { |
| 4326 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 4327 | qla2x00_rport_del(fcport); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4328 | |
| 4329 | /* |
| 4330 | * Release the target mode FC NEXUS in |
| 4331 | * qla_target.c, if target mod is enabled. |
| 4332 | */ |
| 4333 | qlt_fc_port_deleted(vha, fcport, |
| 4334 | base_vha->total_fcport_update_gen); |
| 4335 | |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4336 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4337 | } |
| 4338 | } |
| 4339 | atomic_dec(&vha->vref_count); |
| 4340 | } |
| 4341 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 4342 | } |
| 4343 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 4344 | /* Assumes idc_lock always held on entry */ |
| 4345 | void |
| 4346 | qla83xx_reset_ownership(scsi_qla_host_t *vha) |
| 4347 | { |
| 4348 | struct qla_hw_data *ha = vha->hw; |
| 4349 | uint32_t drv_presence, drv_presence_mask; |
| 4350 | uint32_t dev_part_info1, dev_part_info2, class_type; |
| 4351 | uint32_t class_type_mask = 0x3; |
| 4352 | uint16_t fcoe_other_function = 0xffff, i; |
| 4353 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 4354 | if (IS_QLA8044(ha)) { |
| 4355 | drv_presence = qla8044_rd_direct(vha, |
| 4356 | QLA8044_CRB_DRV_ACTIVE_INDEX); |
| 4357 | dev_part_info1 = qla8044_rd_direct(vha, |
| 4358 | QLA8044_CRB_DEV_PART_INFO_INDEX); |
| 4359 | dev_part_info2 = qla8044_rd_direct(vha, |
| 4360 | QLA8044_CRB_DEV_PART_INFO2); |
| 4361 | } else { |
| 4362 | qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); |
| 4363 | qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1); |
| 4364 | qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2); |
| 4365 | } |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 4366 | for (i = 0; i < 8; i++) { |
| 4367 | class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask); |
| 4368 | if ((class_type == QLA83XX_CLASS_TYPE_FCOE) && |
| 4369 | (i != ha->portnum)) { |
| 4370 | fcoe_other_function = i; |
| 4371 | break; |
| 4372 | } |
| 4373 | } |
| 4374 | if (fcoe_other_function == 0xffff) { |
| 4375 | for (i = 0; i < 8; i++) { |
| 4376 | class_type = ((dev_part_info2 >> (i * 4)) & |
| 4377 | class_type_mask); |
| 4378 | if ((class_type == QLA83XX_CLASS_TYPE_FCOE) && |
| 4379 | ((i + 8) != ha->portnum)) { |
| 4380 | fcoe_other_function = i + 8; |
| 4381 | break; |
| 4382 | } |
| 4383 | } |
| 4384 | } |
| 4385 | /* |
| 4386 | * Prepare drv-presence mask based on fcoe functions present. |
| 4387 | * However consider only valid physical fcoe function numbers (0-15). |
| 4388 | */ |
| 4389 | drv_presence_mask = ~((1 << (ha->portnum)) | |
| 4390 | ((fcoe_other_function == 0xffff) ? |
| 4391 | 0 : (1 << (fcoe_other_function)))); |
| 4392 | |
| 4393 | /* We are the reset owner iff: |
| 4394 | * - No other protocol drivers present. |
| 4395 | * - This is the lowest among fcoe functions. */ |
| 4396 | if (!(drv_presence & drv_presence_mask) && |
| 4397 | (ha->portnum < fcoe_other_function)) { |
| 4398 | ql_dbg(ql_dbg_p3p, vha, 0xb07f, |
| 4399 | "This host is Reset owner.\n"); |
| 4400 | ha->flags.nic_core_reset_owner = 1; |
| 4401 | } |
| 4402 | } |
| 4403 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 4404 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 4405 | __qla83xx_set_drv_ack(scsi_qla_host_t *vha) |
| 4406 | { |
| 4407 | int rval = QLA_SUCCESS; |
| 4408 | struct qla_hw_data *ha = vha->hw; |
| 4409 | uint32_t drv_ack; |
| 4410 | |
| 4411 | rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack); |
| 4412 | if (rval == QLA_SUCCESS) { |
| 4413 | drv_ack |= (1 << ha->portnum); |
| 4414 | rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack); |
| 4415 | } |
| 4416 | |
| 4417 | return rval; |
| 4418 | } |
| 4419 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 4420 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 4421 | __qla83xx_clear_drv_ack(scsi_qla_host_t *vha) |
| 4422 | { |
| 4423 | int rval = QLA_SUCCESS; |
| 4424 | struct qla_hw_data *ha = vha->hw; |
| 4425 | uint32_t drv_ack; |
| 4426 | |
| 4427 | rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack); |
| 4428 | if (rval == QLA_SUCCESS) { |
| 4429 | drv_ack &= ~(1 << ha->portnum); |
| 4430 | rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack); |
| 4431 | } |
| 4432 | |
| 4433 | return rval; |
| 4434 | } |
| 4435 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 4436 | static const char * |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 4437 | qla83xx_dev_state_to_string(uint32_t dev_state) |
| 4438 | { |
| 4439 | switch (dev_state) { |
| 4440 | case QLA8XXX_DEV_COLD: |
| 4441 | return "COLD/RE-INIT"; |
| 4442 | case QLA8XXX_DEV_INITIALIZING: |
| 4443 | return "INITIALIZING"; |
| 4444 | case QLA8XXX_DEV_READY: |
| 4445 | return "READY"; |
| 4446 | case QLA8XXX_DEV_NEED_RESET: |
| 4447 | return "NEED RESET"; |
| 4448 | case QLA8XXX_DEV_NEED_QUIESCENT: |
| 4449 | return "NEED QUIESCENT"; |
| 4450 | case QLA8XXX_DEV_FAILED: |
| 4451 | return "FAILED"; |
| 4452 | case QLA8XXX_DEV_QUIESCENT: |
| 4453 | return "QUIESCENT"; |
| 4454 | default: |
| 4455 | return "Unknown"; |
| 4456 | } |
| 4457 | } |
| 4458 | |
| 4459 | /* Assumes idc-lock always held on entry */ |
| 4460 | void |
| 4461 | qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type) |
| 4462 | { |
| 4463 | struct qla_hw_data *ha = vha->hw; |
| 4464 | uint32_t idc_audit_reg = 0, duration_secs = 0; |
| 4465 | |
| 4466 | switch (audit_type) { |
| 4467 | case IDC_AUDIT_TIMESTAMP: |
| 4468 | ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000); |
| 4469 | idc_audit_reg = (ha->portnum) | |
| 4470 | (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8); |
| 4471 | qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg); |
| 4472 | break; |
| 4473 | |
| 4474 | case IDC_AUDIT_COMPLETION: |
| 4475 | duration_secs = ((jiffies_to_msecs(jiffies) - |
| 4476 | jiffies_to_msecs(ha->idc_audit_ts)) / 1000); |
| 4477 | idc_audit_reg = (ha->portnum) | |
| 4478 | (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8); |
| 4479 | qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg); |
| 4480 | break; |
| 4481 | |
| 4482 | default: |
| 4483 | ql_log(ql_log_warn, vha, 0xb078, |
| 4484 | "Invalid audit type specified.\n"); |
| 4485 | break; |
| 4486 | } |
| 4487 | } |
| 4488 | |
| 4489 | /* Assumes idc_lock always held on entry */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 4490 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 4491 | qla83xx_initiating_reset(scsi_qla_host_t *vha) |
| 4492 | { |
| 4493 | struct qla_hw_data *ha = vha->hw; |
| 4494 | uint32_t idc_control, dev_state; |
| 4495 | |
| 4496 | __qla83xx_get_idc_control(vha, &idc_control); |
| 4497 | if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) { |
| 4498 | ql_log(ql_log_info, vha, 0xb080, |
| 4499 | "NIC Core reset has been disabled. idc-control=0x%x\n", |
| 4500 | idc_control); |
| 4501 | return QLA_FUNCTION_FAILED; |
| 4502 | } |
| 4503 | |
| 4504 | /* Set NEED-RESET iff in READY state and we are the reset-owner */ |
| 4505 | qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state); |
| 4506 | if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) { |
| 4507 | qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, |
| 4508 | QLA8XXX_DEV_NEED_RESET); |
| 4509 | ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n"); |
| 4510 | qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP); |
| 4511 | } else { |
| 4512 | const char *state = qla83xx_dev_state_to_string(dev_state); |
| 4513 | ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state); |
| 4514 | |
| 4515 | /* SV: XXX: Is timeout required here? */ |
| 4516 | /* Wait for IDC state change READY -> NEED_RESET */ |
| 4517 | while (dev_state == QLA8XXX_DEV_READY) { |
| 4518 | qla83xx_idc_unlock(vha, 0); |
| 4519 | msleep(200); |
| 4520 | qla83xx_idc_lock(vha, 0); |
| 4521 | qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state); |
| 4522 | } |
| 4523 | } |
| 4524 | |
| 4525 | /* Send IDC ack by writing to drv-ack register */ |
| 4526 | __qla83xx_set_drv_ack(vha); |
| 4527 | |
| 4528 | return QLA_SUCCESS; |
| 4529 | } |
| 4530 | |
| 4531 | int |
| 4532 | __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control) |
| 4533 | { |
| 4534 | return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control); |
| 4535 | } |
| 4536 | |
| 4537 | int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 4538 | __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control) |
| 4539 | { |
| 4540 | return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control); |
| 4541 | } |
| 4542 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 4543 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 4544 | qla83xx_check_driver_presence(scsi_qla_host_t *vha) |
| 4545 | { |
| 4546 | uint32_t drv_presence = 0; |
| 4547 | struct qla_hw_data *ha = vha->hw; |
| 4548 | |
| 4549 | qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); |
| 4550 | if (drv_presence & (1 << ha->portnum)) |
| 4551 | return QLA_SUCCESS; |
| 4552 | else |
| 4553 | return QLA_TEST_FAILED; |
| 4554 | } |
| 4555 | |
| 4556 | int |
| 4557 | qla83xx_nic_core_reset(scsi_qla_host_t *vha) |
| 4558 | { |
| 4559 | int rval = QLA_SUCCESS; |
| 4560 | struct qla_hw_data *ha = vha->hw; |
| 4561 | |
| 4562 | ql_dbg(ql_dbg_p3p, vha, 0xb058, |
| 4563 | "Entered %s().\n", __func__); |
| 4564 | |
| 4565 | if (vha->device_flags & DFLG_DEV_FAILED) { |
| 4566 | ql_log(ql_log_warn, vha, 0xb059, |
| 4567 | "Device in unrecoverable FAILED state.\n"); |
| 4568 | return QLA_FUNCTION_FAILED; |
| 4569 | } |
| 4570 | |
| 4571 | qla83xx_idc_lock(vha, 0); |
| 4572 | |
| 4573 | if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) { |
| 4574 | ql_log(ql_log_warn, vha, 0xb05a, |
| 4575 | "Function=0x%x has been removed from IDC participation.\n", |
| 4576 | ha->portnum); |
| 4577 | rval = QLA_FUNCTION_FAILED; |
| 4578 | goto exit; |
| 4579 | } |
| 4580 | |
| 4581 | qla83xx_reset_ownership(vha); |
| 4582 | |
| 4583 | rval = qla83xx_initiating_reset(vha); |
| 4584 | |
| 4585 | /* |
| 4586 | * Perform reset if we are the reset-owner, |
| 4587 | * else wait till IDC state changes to READY/FAILED. |
| 4588 | */ |
| 4589 | if (rval == QLA_SUCCESS) { |
| 4590 | rval = qla83xx_idc_state_handler(vha); |
| 4591 | |
| 4592 | if (rval == QLA_SUCCESS) |
| 4593 | ha->flags.nic_core_hung = 0; |
| 4594 | __qla83xx_clear_drv_ack(vha); |
| 4595 | } |
| 4596 | |
| 4597 | exit: |
| 4598 | qla83xx_idc_unlock(vha, 0); |
| 4599 | |
| 4600 | ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__); |
| 4601 | |
| 4602 | return rval; |
| 4603 | } |
| 4604 | |
Saurav Kashyap | 8117877 | 2012-08-22 14:21:04 -0400 | [diff] [blame] | 4605 | int |
| 4606 | qla2xxx_mctp_dump(scsi_qla_host_t *vha) |
| 4607 | { |
| 4608 | struct qla_hw_data *ha = vha->hw; |
| 4609 | int rval = QLA_FUNCTION_FAILED; |
| 4610 | |
| 4611 | if (!IS_MCTP_CAPABLE(ha)) { |
| 4612 | /* This message can be removed from the final version */ |
| 4613 | ql_log(ql_log_info, vha, 0x506d, |
| 4614 | "This board is not MCTP capable\n"); |
| 4615 | return rval; |
| 4616 | } |
| 4617 | |
| 4618 | if (!ha->mctp_dump) { |
| 4619 | ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev, |
| 4620 | MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL); |
| 4621 | |
| 4622 | if (!ha->mctp_dump) { |
| 4623 | ql_log(ql_log_warn, vha, 0x506e, |
| 4624 | "Failed to allocate memory for mctp dump\n"); |
| 4625 | return rval; |
| 4626 | } |
| 4627 | } |
| 4628 | |
| 4629 | #define MCTP_DUMP_STR_ADDR 0x00000000 |
| 4630 | rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma, |
| 4631 | MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4); |
| 4632 | if (rval != QLA_SUCCESS) { |
| 4633 | ql_log(ql_log_warn, vha, 0x506f, |
| 4634 | "Failed to capture mctp dump\n"); |
| 4635 | } else { |
| 4636 | ql_log(ql_log_info, vha, 0x5070, |
| 4637 | "Mctp dump capture for host (%ld/%p).\n", |
| 4638 | vha->host_no, ha->mctp_dump); |
| 4639 | ha->mctp_dumped = 1; |
| 4640 | } |
| 4641 | |
Saurav Kashyap | 409ee0f | 2012-08-22 14:21:29 -0400 | [diff] [blame] | 4642 | if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) { |
Saurav Kashyap | 8117877 | 2012-08-22 14:21:04 -0400 | [diff] [blame] | 4643 | ha->flags.nic_core_reset_hdlr_active = 1; |
| 4644 | rval = qla83xx_restart_nic_firmware(vha); |
| 4645 | if (rval) |
| 4646 | /* NIC Core reset failed. */ |
| 4647 | ql_log(ql_log_warn, vha, 0x5071, |
| 4648 | "Failed to restart nic firmware\n"); |
| 4649 | else |
| 4650 | ql_dbg(ql_dbg_p3p, vha, 0xb084, |
| 4651 | "Restarted NIC firmware successfully.\n"); |
| 4652 | ha->flags.nic_core_reset_hdlr_active = 0; |
| 4653 | } |
| 4654 | |
| 4655 | return rval; |
| 4656 | |
| 4657 | } |
| 4658 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4659 | /* |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 4660 | * qla2x00_quiesce_io |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4661 | * Description: This function will block the new I/Os |
| 4662 | * Its not aborting any I/Os as context |
| 4663 | * is not destroyed during quiescence |
| 4664 | * Arguments: scsi_qla_host_t |
| 4665 | * return : void |
| 4666 | */ |
| 4667 | void |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 4668 | qla2x00_quiesce_io(scsi_qla_host_t *vha) |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4669 | { |
| 4670 | struct qla_hw_data *ha = vha->hw; |
| 4671 | struct scsi_qla_host *vp; |
| 4672 | |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 4673 | ql_dbg(ql_dbg_dpc, vha, 0x401d, |
| 4674 | "Quiescing I/O - ha=%p.\n", ha); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4675 | |
| 4676 | atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); |
| 4677 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 4678 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 4679 | qla2x00_mark_all_devices_lost(vha, 0); |
| 4680 | list_for_each_entry(vp, &ha->vp_list, list) |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 4681 | qla2x00_mark_all_devices_lost(vp, 0); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4682 | } else { |
| 4683 | if (!atomic_read(&vha->loop_down_timer)) |
| 4684 | atomic_set(&vha->loop_down_timer, |
| 4685 | LOOP_DOWN_TIME); |
| 4686 | } |
| 4687 | /* Wait for pending cmds to complete */ |
| 4688 | qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST); |
| 4689 | } |
| 4690 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4691 | void |
| 4692 | qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha) |
| 4693 | { |
| 4694 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4695 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4696 | unsigned long flags; |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 4697 | fc_port_t *fcport; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4698 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 4699 | /* For ISP82XX, driver waits for completion of the commands. |
| 4700 | * online flag should be set. |
| 4701 | */ |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 4702 | if (!(IS_P3P_TYPE(ha))) |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 4703 | vha->flags.online = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4704 | ha->flags.chip_reset_done = 0; |
| 4705 | clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Saurav Kashyap | 2be21fa | 2012-05-15 14:34:16 -0400 | [diff] [blame] | 4706 | vha->qla_stats.total_isp_aborts++; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4707 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4708 | ql_log(ql_log_info, vha, 0x00af, |
| 4709 | "Performing ISP error recovery - ha=%p.\n", ha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4710 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 4711 | /* For ISP82XX, reset_chip is just disabling interrupts. |
| 4712 | * Driver waits for the completion of the commands. |
| 4713 | * the interrupts need to be enabled. |
| 4714 | */ |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 4715 | if (!(IS_P3P_TYPE(ha))) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4716 | ha->isp_ops->reset_chip(vha); |
| 4717 | |
| 4718 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 4719 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 4720 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 4721 | qla2x00_mark_all_devices_lost(vha, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4722 | |
| 4723 | spin_lock_irqsave(&ha->vport_slock, flags); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4724 | list_for_each_entry(vp, &ha->vp_list, list) { |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4725 | atomic_inc(&vp->vref_count); |
| 4726 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4727 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4728 | qla2x00_mark_all_devices_lost(vp, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4729 | |
| 4730 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4731 | atomic_dec(&vp->vref_count); |
| 4732 | } |
| 4733 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4734 | } else { |
| 4735 | if (!atomic_read(&vha->loop_down_timer)) |
| 4736 | atomic_set(&vha->loop_down_timer, |
| 4737 | LOOP_DOWN_TIME); |
| 4738 | } |
| 4739 | |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 4740 | /* Clear all async request states across all VPs. */ |
| 4741 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 4742 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 4743 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4744 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 4745 | atomic_inc(&vp->vref_count); |
| 4746 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4747 | |
| 4748 | list_for_each_entry(fcport, &vp->vp_fcports, list) |
| 4749 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 4750 | |
| 4751 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4752 | atomic_dec(&vp->vref_count); |
| 4753 | } |
| 4754 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4755 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 4756 | if (!ha->flags.eeh_busy) { |
| 4757 | /* Make sure for ISP 82XX IO DMA is complete */ |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 4758 | if (IS_P3P_TYPE(ha)) { |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 4759 | qla82xx_chip_reset_cleanup(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4760 | ql_log(ql_log_info, vha, 0x00b4, |
| 4761 | "Done chip reset cleanup.\n"); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4762 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 4763 | /* Done waiting for pending commands. |
| 4764 | * Reset the online flag. |
| 4765 | */ |
| 4766 | vha->flags.online = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4767 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4768 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 4769 | /* Requeue all commands in outstanding command list. */ |
| 4770 | qla2x00_abort_all_cmds(vha, DID_RESET << 16); |
| 4771 | } |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 4772 | |
| 4773 | ha->chip_reset++; |
| 4774 | /* memory barrier */ |
| 4775 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4776 | } |
| 4777 | |
| 4778 | /* |
| 4779 | * qla2x00_abort_isp |
| 4780 | * Resets ISP and aborts all outstanding commands. |
| 4781 | * |
| 4782 | * Input: |
| 4783 | * ha = adapter block pointer. |
| 4784 | * |
| 4785 | * Returns: |
| 4786 | * 0 = success |
| 4787 | */ |
| 4788 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4789 | qla2x00_abort_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4790 | { |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 4791 | int rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4792 | uint8_t status = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4793 | struct qla_hw_data *ha = vha->hw; |
| 4794 | struct scsi_qla_host *vp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4795 | struct req_que *req = ha->req_q_map[0]; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4796 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4797 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4798 | if (vha->flags.online) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4799 | qla2x00_abort_isp_cleanup(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4800 | |
Santosh Vernekar | a6171297 | 2012-08-22 14:21:13 -0400 | [diff] [blame] | 4801 | if (IS_QLA8031(ha)) { |
| 4802 | ql_dbg(ql_dbg_p3p, vha, 0xb05c, |
| 4803 | "Clearing fcoe driver presence.\n"); |
| 4804 | if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS) |
| 4805 | ql_dbg(ql_dbg_p3p, vha, 0xb073, |
| 4806 | "Error while clearing DRV-Presence.\n"); |
| 4807 | } |
| 4808 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 4809 | if (unlikely(pci_channel_offline(ha->pdev) && |
| 4810 | ha->flags.pci_channel_io_perm_failure)) { |
| 4811 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 4812 | status = 0; |
| 4813 | return status; |
| 4814 | } |
| 4815 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4816 | ha->isp_ops->get_flash_version(vha, req->ring); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 4817 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4818 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4819 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4820 | if (!qla2x00_restart_isp(vha)) { |
| 4821 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4822 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4823 | if (!atomic_read(&vha->loop_down_timer)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4824 | /* |
| 4825 | * Issue marker command only when we are going |
| 4826 | * to start the I/O . |
| 4827 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4828 | vha->marker_needed = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4829 | } |
| 4830 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4831 | vha->flags.online = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4832 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 4833 | ha->isp_ops->enable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4834 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4835 | ha->isp_abort_cnt = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4836 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 4837 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 4838 | if (IS_QLA81XX(ha) || IS_QLA8031(ha)) |
| 4839 | qla2x00_get_fw_version(vha); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 4840 | if (ha->fce) { |
| 4841 | ha->flags.fce_enabled = 1; |
| 4842 | memset(ha->fce, 0, |
| 4843 | fce_calc_size(ha->fce_bufs)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4844 | rval = qla2x00_enable_fce_trace(vha, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 4845 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 4846 | &ha->fce_bufs); |
| 4847 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4848 | ql_log(ql_log_warn, vha, 0x8033, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 4849 | "Unable to reinitialize FCE " |
| 4850 | "(%d).\n", rval); |
| 4851 | ha->flags.fce_enabled = 0; |
| 4852 | } |
| 4853 | } |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 4854 | |
| 4855 | if (ha->eft) { |
| 4856 | memset(ha->eft, 0, EFT_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4857 | rval = qla2x00_enable_eft_trace(vha, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 4858 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 4859 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4860 | ql_log(ql_log_warn, vha, 0x8034, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 4861 | "Unable to reinitialize EFT " |
| 4862 | "(%d).\n", rval); |
| 4863 | } |
| 4864 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4865 | } else { /* failed the ISP abort */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4866 | vha->flags.online = 1; |
| 4867 | if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4868 | if (ha->isp_abort_cnt == 0) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4869 | ql_log(ql_log_fatal, vha, 0x8035, |
| 4870 | "ISP error recover failed - " |
| 4871 | "board disabled.\n"); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4872 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4873 | * The next call disables the board |
| 4874 | * completely. |
| 4875 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4876 | ha->isp_ops->reset_adapter(vha); |
| 4877 | vha->flags.online = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4878 | clear_bit(ISP_ABORT_RETRY, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4879 | &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4880 | status = 0; |
| 4881 | } else { /* schedule another ISP abort */ |
| 4882 | ha->isp_abort_cnt--; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4883 | ql_dbg(ql_dbg_taskm, vha, 0x8020, |
| 4884 | "ISP abort - retry remaining %d.\n", |
| 4885 | ha->isp_abort_cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4886 | status = 1; |
| 4887 | } |
| 4888 | } else { |
| 4889 | ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4890 | ql_dbg(ql_dbg_taskm, vha, 0x8021, |
| 4891 | "ISP error recovery - retrying (%d) " |
| 4892 | "more times.\n", ha->isp_abort_cnt); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4893 | set_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4894 | status = 1; |
| 4895 | } |
| 4896 | } |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4897 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4898 | } |
| 4899 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4900 | if (!status) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4901 | ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4902 | |
| 4903 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4904 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 4905 | if (vp->vp_idx) { |
| 4906 | atomic_inc(&vp->vref_count); |
| 4907 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4908 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4909 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4910 | |
| 4911 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4912 | atomic_dec(&vp->vref_count); |
| 4913 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4914 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4915 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4916 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 4917 | if (IS_QLA8031(ha)) { |
| 4918 | ql_dbg(ql_dbg_p3p, vha, 0xb05d, |
| 4919 | "Setting back fcoe driver presence.\n"); |
| 4920 | if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS) |
| 4921 | ql_dbg(ql_dbg_p3p, vha, 0xb074, |
| 4922 | "Error while setting DRV-Presence.\n"); |
| 4923 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4924 | } else { |
Joe Perches | d8424f6 | 2011-11-18 09:03:06 -0800 | [diff] [blame] | 4925 | ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n", |
| 4926 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4927 | } |
| 4928 | |
| 4929 | return(status); |
| 4930 | } |
| 4931 | |
| 4932 | /* |
| 4933 | * qla2x00_restart_isp |
| 4934 | * restarts the ISP after a reset |
| 4935 | * |
| 4936 | * Input: |
| 4937 | * ha = adapter block pointer. |
| 4938 | * |
| 4939 | * Returns: |
| 4940 | * 0 = success |
| 4941 | */ |
| 4942 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4943 | qla2x00_restart_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4944 | { |
Andrew Vasquez | c6b2fca | 2009-03-05 11:07:03 -0800 | [diff] [blame] | 4945 | int status = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4946 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4947 | struct req_que *req = ha->req_q_map[0]; |
| 4948 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4949 | |
| 4950 | /* If firmware needs to be loaded */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4951 | if (qla2x00_isp_firmware(vha)) { |
| 4952 | vha->flags.online = 0; |
| 4953 | status = ha->isp_ops->chip_diag(vha); |
| 4954 | if (!status) |
| 4955 | status = qla2x00_setup_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4956 | } |
| 4957 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4958 | if (!status && !(status = qla2x00_init_rings(vha))) { |
| 4959 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 4960 | ha->flags.chip_reset_done = 1; |
Chad Dupuis | 7108b76 | 2014-04-11 16:54:45 -0400 | [diff] [blame] | 4961 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4962 | /* Initialize the queues in use */ |
| 4963 | qla25xx_init_queues(ha); |
| 4964 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4965 | status = qla2x00_fw_ready(vha); |
| 4966 | if (!status) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4967 | /* Issue a marker after FW becomes ready. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4968 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4969 | |
Chad Dupuis | 7108b76 | 2014-04-11 16:54:45 -0400 | [diff] [blame] | 4970 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4971 | } |
| 4972 | |
| 4973 | /* if no cable then assume it's good */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4974 | if ((vha->device_flags & DFLG_NO_CABLE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4975 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4976 | } |
| 4977 | return (status); |
| 4978 | } |
| 4979 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4980 | static int |
| 4981 | qla25xx_init_queues(struct qla_hw_data *ha) |
| 4982 | { |
| 4983 | struct rsp_que *rsp = NULL; |
| 4984 | struct req_que *req = NULL; |
| 4985 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
| 4986 | int ret = -1; |
| 4987 | int i; |
| 4988 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 4989 | for (i = 1; i < ha->max_rsp_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4990 | rsp = ha->rsp_q_map[i]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 4991 | if (rsp && test_bit(i, ha->rsp_qid_map)) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4992 | rsp->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 4993 | ret = qla25xx_init_rsp_que(base_vha, rsp); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4994 | if (ret != QLA_SUCCESS) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4995 | ql_dbg(ql_dbg_init, base_vha, 0x00ff, |
| 4996 | "%s Rsp que: %d init failed.\n", |
| 4997 | __func__, rsp->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4998 | else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4999 | ql_dbg(ql_dbg_init, base_vha, 0x0100, |
| 5000 | "%s Rsp que: %d inited.\n", |
| 5001 | __func__, rsp->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5002 | } |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 5003 | } |
| 5004 | for (i = 1; i < ha->max_req_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5005 | req = ha->req_q_map[i]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 5006 | if (req && test_bit(i, ha->req_qid_map)) { |
| 5007 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5008 | req->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 5009 | ret = qla25xx_init_req_que(base_vha, req); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5010 | if (ret != QLA_SUCCESS) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5011 | ql_dbg(ql_dbg_init, base_vha, 0x0101, |
| 5012 | "%s Req que: %d init failed.\n", |
| 5013 | __func__, req->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5014 | else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5015 | ql_dbg(ql_dbg_init, base_vha, 0x0102, |
| 5016 | "%s Req que: %d inited.\n", |
| 5017 | __func__, req->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5018 | } |
| 5019 | } |
| 5020 | return ret; |
| 5021 | } |
| 5022 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5023 | /* |
| 5024 | * qla2x00_reset_adapter |
| 5025 | * Reset adapter. |
| 5026 | * |
| 5027 | * Input: |
| 5028 | * ha = adapter block pointer. |
| 5029 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 5030 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5031 | qla2x00_reset_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5032 | { |
| 5033 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5034 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 5035 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5036 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5037 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 5038 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5039 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5040 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 5041 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 5042 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 5043 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 5044 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 5045 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 5046 | } |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5047 | |
| 5048 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5049 | qla24xx_reset_adapter(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5050 | { |
| 5051 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5052 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5053 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 5054 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 5055 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5056 | return; |
| 5057 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5058 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 5059 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5060 | |
| 5061 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 5062 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 5063 | RD_REG_DWORD(®->hccr); |
| 5064 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 5065 | RD_REG_DWORD(®->hccr); |
| 5066 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 09ff36d | 2009-01-22 09:45:30 -0800 | [diff] [blame] | 5067 | |
| 5068 | if (IS_NOPOLLING_TYPE(ha)) |
| 5069 | ha->isp_ops->enable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5070 | } |
| 5071 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5072 | /* On sparc systems, obtain port and node WWN from firmware |
| 5073 | * properties. |
| 5074 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5075 | static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, |
| 5076 | struct nvram_24xx *nv) |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5077 | { |
| 5078 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5079 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5080 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 5081 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 5082 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5083 | int len; |
| 5084 | |
| 5085 | val = of_get_property(dp, "port-wwn", &len); |
| 5086 | if (val && len >= WWN_SIZE) |
| 5087 | memcpy(nv->port_name, val, WWN_SIZE); |
| 5088 | |
| 5089 | val = of_get_property(dp, "node-wwn", &len); |
| 5090 | if (val && len >= WWN_SIZE) |
| 5091 | memcpy(nv->node_name, val, WWN_SIZE); |
| 5092 | #endif |
| 5093 | } |
| 5094 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5095 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5096 | qla24xx_nvram_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5097 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5098 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5099 | struct init_cb_24xx *icb; |
| 5100 | struct nvram_24xx *nv; |
| 5101 | uint32_t *dptr; |
| 5102 | uint8_t *dptr1, *dptr2; |
| 5103 | uint32_t chksum; |
| 5104 | uint16_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5105 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5106 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5107 | rval = QLA_SUCCESS; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5108 | icb = (struct init_cb_24xx *)ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 5109 | nv = ha->nvram; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5110 | |
| 5111 | /* Determine NVRAM starting address. */ |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 5112 | if (ha->port_no == 0) { |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5113 | ha->nvram_base = FA_NVRAM_FUNC0_ADDR; |
| 5114 | ha->vpd_base = FA_NVRAM_VPD0_ADDR; |
| 5115 | } else { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5116 | ha->nvram_base = FA_NVRAM_FUNC1_ADDR; |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 5117 | ha->vpd_base = FA_NVRAM_VPD1_ADDR; |
| 5118 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 5119 | |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5120 | ha->nvram_size = sizeof(struct nvram_24xx); |
| 5121 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5122 | |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 5123 | /* Get VPD data into cache */ |
| 5124 | ha->vpd = ha->nvram + VPD_OFFSET; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5125 | ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 5126 | ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4); |
| 5127 | |
| 5128 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5129 | dptr = (uint32_t *)nv; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5130 | ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5131 | ha->nvram_size); |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 5132 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++) |
| 5133 | chksum += le32_to_cpu(*dptr); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5134 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5135 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a, |
| 5136 | "Contents of NVRAM\n"); |
| 5137 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d, |
| 5138 | (uint8_t *)nv, ha->nvram_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5139 | |
| 5140 | /* Bad NVRAM data, set defaults parameters. */ |
| 5141 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 5142 | || nv->id[3] != ' ' || |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5143 | nv->nvram_version < cpu_to_le16(ICB_VERSION)) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5144 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5145 | ql_log(ql_log_warn, vha, 0x006b, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 5146 | "Inconsistent NVRAM detected: checksum=0x%x id=%c " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5147 | "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version); |
| 5148 | ql_log(ql_log_warn, vha, 0x006c, |
| 5149 | "Falling back to functioning (yet invalid -- WWPN) " |
| 5150 | "defaults.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5151 | |
| 5152 | /* |
| 5153 | * Set default initialization control block. |
| 5154 | */ |
| 5155 | memset(nv, 0, ha->nvram_size); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5156 | nv->nvram_version = cpu_to_le16(ICB_VERSION); |
| 5157 | nv->version = cpu_to_le16(ICB_VERSION); |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 5158 | nv->frame_payload_size = 2048; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5159 | nv->execution_throttle = cpu_to_le16(0xFFFF); |
| 5160 | nv->exchange_count = cpu_to_le16(0); |
| 5161 | nv->hard_address = cpu_to_le16(124); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5162 | nv->port_name[0] = 0x21; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 5163 | nv->port_name[1] = 0x00 + ha->port_no + 1; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5164 | nv->port_name[2] = 0x00; |
| 5165 | nv->port_name[3] = 0xe0; |
| 5166 | nv->port_name[4] = 0x8b; |
| 5167 | nv->port_name[5] = 0x1c; |
| 5168 | nv->port_name[6] = 0x55; |
| 5169 | nv->port_name[7] = 0x86; |
| 5170 | nv->node_name[0] = 0x20; |
| 5171 | nv->node_name[1] = 0x00; |
| 5172 | nv->node_name[2] = 0x00; |
| 5173 | nv->node_name[3] = 0xe0; |
| 5174 | nv->node_name[4] = 0x8b; |
| 5175 | nv->node_name[5] = 0x1c; |
| 5176 | nv->node_name[6] = 0x55; |
| 5177 | nv->node_name[7] = 0x86; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5178 | qla24xx_nvram_wwn_from_ofw(vha, nv); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5179 | nv->login_retry_count = cpu_to_le16(8); |
| 5180 | nv->interrupt_delay_timer = cpu_to_le16(0); |
| 5181 | nv->login_timeout = cpu_to_le16(0); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5182 | nv->firmware_options_1 = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5183 | cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 5184 | nv->firmware_options_2 = cpu_to_le32(2 << 4); |
| 5185 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 5186 | nv->firmware_options_3 = cpu_to_le32(2 << 13); |
| 5187 | nv->host_p = cpu_to_le32(BIT_11|BIT_10); |
| 5188 | nv->efi_parameters = cpu_to_le32(0); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5189 | nv->reset_delay = 5; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5190 | nv->max_luns_per_target = cpu_to_le16(128); |
| 5191 | nv->port_down_retry_count = cpu_to_le16(30); |
| 5192 | nv->link_down_timeout = cpu_to_le16(30); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5193 | |
| 5194 | rval = 1; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5195 | } |
| 5196 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5197 | if (!qla_ini_mode_enabled(vha)) { |
| 5198 | /* Don't enable full login after initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5199 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5200 | /* Don't enable LIP full login for initiator */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5201 | nv->host_p &= cpu_to_le32(~BIT_10); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5202 | } |
| 5203 | |
| 5204 | qlt_24xx_config_nvram_stage1(vha, nv); |
| 5205 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5206 | /* Reset Initialization control block */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5207 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5208 | |
| 5209 | /* Copy 1st segment. */ |
| 5210 | dptr1 = (uint8_t *)icb; |
| 5211 | dptr2 = (uint8_t *)&nv->version; |
| 5212 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 5213 | while (cnt--) |
| 5214 | *dptr1++ = *dptr2++; |
| 5215 | |
| 5216 | icb->login_retry_count = nv->login_retry_count; |
Andrew Vasquez | 3ea66e2 | 2006-06-23 16:11:27 -0700 | [diff] [blame] | 5217 | icb->link_down_on_nos = nv->link_down_on_nos; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5218 | |
| 5219 | /* Copy 2nd segment. */ |
| 5220 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 5221 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 5222 | cnt = (uint8_t *)&icb->reserved_3 - |
| 5223 | (uint8_t *)&icb->interrupt_delay_timer; |
| 5224 | while (cnt--) |
| 5225 | *dptr1++ = *dptr2++; |
| 5226 | |
| 5227 | /* |
| 5228 | * Setup driver NVRAM options. |
| 5229 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5230 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 5231 | "QLA2462"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5232 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5233 | qlt_24xx_config_nvram_stage2(vha, icb); |
| 5234 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5235 | if (nv->host_p & cpu_to_le32(BIT_15)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5236 | /* Use alternate WWN? */ |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 5237 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 5238 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 5239 | } |
| 5240 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5241 | /* Prepare nodename */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5242 | if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5243 | /* |
| 5244 | * Firmware will apply the following mask if the nodename was |
| 5245 | * not provided. |
| 5246 | */ |
| 5247 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 5248 | icb->node_name[0] &= 0xF0; |
| 5249 | } |
| 5250 | |
| 5251 | /* Set host adapter parameters. */ |
| 5252 | ha->flags.disable_risc_code_load = 0; |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 5253 | ha->flags.enable_lip_reset = 0; |
| 5254 | ha->flags.enable_lip_full_login = |
| 5255 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 5256 | ha->flags.enable_target_reset = |
| 5257 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5258 | ha->flags.enable_led_scheme = 0; |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 5259 | ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5260 | |
Andrew Vasquez | fd0e7e4 | 2006-05-17 15:09:11 -0700 | [diff] [blame] | 5261 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 5262 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5263 | |
| 5264 | memcpy(ha->fw_seriallink_options24, nv->seriallink_options, |
| 5265 | sizeof(ha->fw_seriallink_options24)); |
| 5266 | |
| 5267 | /* save HBA serial number */ |
| 5268 | ha->serial0 = icb->port_name[5]; |
| 5269 | ha->serial1 = icb->port_name[6]; |
| 5270 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5271 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 5272 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5273 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5274 | icb->execution_throttle = cpu_to_le16(0xFFFF); |
andrew.vasquez@qlogic.com | bc8fb3c | 2006-01-13 17:05:42 -0800 | [diff] [blame] | 5275 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5276 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 5277 | |
| 5278 | /* Set minimum login_timeout to 4 seconds. */ |
| 5279 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 5280 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 5281 | if (le16_to_cpu(nv->login_timeout) < 4) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5282 | nv->login_timeout = cpu_to_le16(4); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5283 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5284 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 5285 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 5286 | ha->r_a_tov = 100; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5287 | |
| 5288 | ha->loop_reset_delay = nv->reset_delay; |
| 5289 | |
| 5290 | /* Link Down Timeout = 0: |
| 5291 | * |
| 5292 | * When Port Down timer expires we will start returning |
| 5293 | * I/O's to OS with "DID_NO_CONNECT". |
| 5294 | * |
| 5295 | * Link Down Timeout != 0: |
| 5296 | * |
| 5297 | * The driver waits for the link to come up after link down |
| 5298 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 5299 | */ |
| 5300 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 5301 | ha->loop_down_abort_time = |
| 5302 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 5303 | } else { |
| 5304 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 5305 | ha->loop_down_abort_time = |
| 5306 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 5307 | } |
| 5308 | |
| 5309 | /* Need enough time to try and get the port back. */ |
| 5310 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 5311 | if (qlport_down_retry) |
| 5312 | ha->port_down_retry_count = qlport_down_retry; |
| 5313 | |
| 5314 | /* Set login_retry_count */ |
| 5315 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 5316 | if (ha->port_down_retry_count == |
| 5317 | le16_to_cpu(nv->port_down_retry_count) && |
| 5318 | ha->port_down_retry_count > 3) |
| 5319 | ha->login_retry_count = ha->port_down_retry_count; |
| 5320 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 5321 | ha->login_retry_count = ha->port_down_retry_count; |
| 5322 | if (ql2xloginretrycount) |
| 5323 | ha->login_retry_count = ql2xloginretrycount; |
| 5324 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 5325 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5326 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 5327 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 5328 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 5329 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 5330 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 5331 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5332 | icb->firmware_options_2 &= cpu_to_le32( |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 5333 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5334 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 5335 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 5336 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 5337 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5338 | ql_log(ql_log_info, vha, 0x006f, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 5339 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 5340 | ha->zio_mode, ha->zio_timer * 100); |
| 5341 | |
| 5342 | icb->firmware_options_2 |= cpu_to_le32( |
| 5343 | (uint32_t)ha->zio_mode); |
| 5344 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5345 | vha->flags.process_response_queue = 1; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 5346 | } |
| 5347 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5348 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5349 | ql_log(ql_log_warn, vha, 0x0070, |
| 5350 | "NVRAM configuration failed.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5351 | } |
| 5352 | return (rval); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5353 | } |
| 5354 | |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 5355 | uint8_t qla27xx_find_valid_image(struct scsi_qla_host *vha) |
| 5356 | { |
| 5357 | struct qla27xx_image_status pri_image_status, sec_image_status; |
| 5358 | uint8_t valid_pri_image, valid_sec_image; |
| 5359 | uint32_t *wptr; |
| 5360 | uint32_t cnt, chksum, size; |
| 5361 | struct qla_hw_data *ha = vha->hw; |
| 5362 | |
| 5363 | valid_pri_image = valid_sec_image = 1; |
| 5364 | ha->active_image = 0; |
| 5365 | size = sizeof(struct qla27xx_image_status) / sizeof(uint32_t); |
| 5366 | |
| 5367 | if (!ha->flt_region_img_status_pri) { |
| 5368 | valid_pri_image = 0; |
| 5369 | goto check_sec_image; |
| 5370 | } |
| 5371 | |
| 5372 | qla24xx_read_flash_data(vha, (uint32_t *)(&pri_image_status), |
| 5373 | ha->flt_region_img_status_pri, size); |
| 5374 | |
| 5375 | if (pri_image_status.signature != QLA27XX_IMG_STATUS_SIGN) { |
| 5376 | ql_dbg(ql_dbg_init, vha, 0x018b, |
| 5377 | "Primary image signature (0x%x) not valid\n", |
| 5378 | pri_image_status.signature); |
| 5379 | valid_pri_image = 0; |
| 5380 | goto check_sec_image; |
| 5381 | } |
| 5382 | |
| 5383 | wptr = (uint32_t *)(&pri_image_status); |
| 5384 | cnt = size; |
| 5385 | |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 5386 | for (chksum = 0; cnt--; wptr++) |
| 5387 | chksum += le32_to_cpu(*wptr); |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 5388 | if (chksum) { |
| 5389 | ql_dbg(ql_dbg_init, vha, 0x018c, |
| 5390 | "Checksum validation failed for primary image (0x%x)\n", |
| 5391 | chksum); |
| 5392 | valid_pri_image = 0; |
| 5393 | } |
| 5394 | |
| 5395 | check_sec_image: |
| 5396 | if (!ha->flt_region_img_status_sec) { |
| 5397 | valid_sec_image = 0; |
| 5398 | goto check_valid_image; |
| 5399 | } |
| 5400 | |
| 5401 | qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status), |
| 5402 | ha->flt_region_img_status_sec, size); |
| 5403 | |
| 5404 | if (sec_image_status.signature != QLA27XX_IMG_STATUS_SIGN) { |
| 5405 | ql_dbg(ql_dbg_init, vha, 0x018d, |
| 5406 | "Secondary image signature(0x%x) not valid\n", |
| 5407 | sec_image_status.signature); |
| 5408 | valid_sec_image = 0; |
| 5409 | goto check_valid_image; |
| 5410 | } |
| 5411 | |
| 5412 | wptr = (uint32_t *)(&sec_image_status); |
| 5413 | cnt = size; |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 5414 | for (chksum = 0; cnt--; wptr++) |
| 5415 | chksum += le32_to_cpu(*wptr); |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 5416 | if (chksum) { |
| 5417 | ql_dbg(ql_dbg_init, vha, 0x018e, |
| 5418 | "Checksum validation failed for secondary image (0x%x)\n", |
| 5419 | chksum); |
| 5420 | valid_sec_image = 0; |
| 5421 | } |
| 5422 | |
| 5423 | check_valid_image: |
| 5424 | if (valid_pri_image && (pri_image_status.image_status_mask & 0x1)) |
| 5425 | ha->active_image = QLA27XX_PRIMARY_IMAGE; |
| 5426 | if (valid_sec_image && (sec_image_status.image_status_mask & 0x1)) { |
| 5427 | if (!ha->active_image || |
| 5428 | pri_image_status.generation_number < |
| 5429 | sec_image_status.generation_number) |
| 5430 | ha->active_image = QLA27XX_SECONDARY_IMAGE; |
| 5431 | } |
| 5432 | |
| 5433 | ql_dbg(ql_dbg_init, vha, 0x018f, "%s image\n", |
| 5434 | ha->active_image == 0 ? "default bootld and fw" : |
| 5435 | ha->active_image == 1 ? "primary" : |
| 5436 | ha->active_image == 2 ? "secondary" : |
| 5437 | "Invalid"); |
| 5438 | |
| 5439 | return ha->active_image; |
| 5440 | } |
| 5441 | |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 5442 | static int |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5443 | qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr, |
| 5444 | uint32_t faddr) |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5445 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5446 | int rval = QLA_SUCCESS; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5447 | int segments, fragment; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5448 | uint32_t *dcode, dlen; |
| 5449 | uint32_t risc_addr; |
| 5450 | uint32_t risc_size; |
| 5451 | uint32_t i; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5452 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5453 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5454 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5455 | ql_dbg(ql_dbg_init, vha, 0x008b, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5456 | "FW: Loading firmware from flash (%x).\n", faddr); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5457 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5458 | rval = QLA_SUCCESS; |
| 5459 | |
| 5460 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5461 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5462 | *srisc_addr = 0; |
| 5463 | |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 5464 | if (IS_QLA27XX(ha) && |
| 5465 | qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE) |
| 5466 | faddr = ha->flt_region_fw_sec; |
| 5467 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5468 | /* Validate firmware image by checking version. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5469 | qla24xx_read_flash_data(vha, dcode, faddr + 4, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5470 | for (i = 0; i < 4; i++) |
| 5471 | dcode[i] = be32_to_cpu(dcode[i]); |
| 5472 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 5473 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 5474 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 5475 | dcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5476 | ql_log(ql_log_fatal, vha, 0x008c, |
| 5477 | "Unable to verify the integrity of flash firmware " |
| 5478 | "image.\n"); |
| 5479 | ql_log(ql_log_fatal, vha, 0x008d, |
| 5480 | "Firmware data: %08x %08x %08x %08x.\n", |
| 5481 | dcode[0], dcode[1], dcode[2], dcode[3]); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5482 | |
| 5483 | return QLA_FUNCTION_FAILED; |
| 5484 | } |
| 5485 | |
| 5486 | while (segments && rval == QLA_SUCCESS) { |
| 5487 | /* Read segment's load information. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5488 | qla24xx_read_flash_data(vha, dcode, faddr, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5489 | |
| 5490 | risc_addr = be32_to_cpu(dcode[2]); |
| 5491 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 5492 | risc_size = be32_to_cpu(dcode[3]); |
| 5493 | |
| 5494 | fragment = 0; |
| 5495 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 5496 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 5497 | if (dlen > risc_size) |
| 5498 | dlen = risc_size; |
| 5499 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5500 | ql_dbg(ql_dbg_init, vha, 0x008e, |
| 5501 | "Loading risc segment@ risc addr %x " |
| 5502 | "number of dwords 0x%x offset 0x%x.\n", |
| 5503 | risc_addr, dlen, faddr); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5504 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5505 | qla24xx_read_flash_data(vha, dcode, faddr, dlen); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5506 | for (i = 0; i < dlen; i++) |
| 5507 | dcode[i] = swab32(dcode[i]); |
| 5508 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5509 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5510 | dlen); |
| 5511 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5512 | ql_log(ql_log_fatal, vha, 0x008f, |
| 5513 | "Failed to load segment %d of firmware.\n", |
| 5514 | fragment); |
Chad Dupuis | f261f7a | 2014-09-25 05:17:03 -0400 | [diff] [blame] | 5515 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5516 | } |
| 5517 | |
| 5518 | faddr += dlen; |
| 5519 | risc_addr += dlen; |
| 5520 | risc_size -= dlen; |
| 5521 | fragment++; |
| 5522 | } |
| 5523 | |
| 5524 | /* Next segment. */ |
| 5525 | segments--; |
| 5526 | } |
| 5527 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 5528 | if (!IS_QLA27XX(ha)) |
| 5529 | return rval; |
| 5530 | |
| 5531 | if (ha->fw_dump_template) |
| 5532 | vfree(ha->fw_dump_template); |
| 5533 | ha->fw_dump_template = NULL; |
| 5534 | ha->fw_dump_template_len = 0; |
| 5535 | |
| 5536 | ql_dbg(ql_dbg_init, vha, 0x0161, |
| 5537 | "Loading fwdump template from %x\n", faddr); |
| 5538 | qla24xx_read_flash_data(vha, dcode, faddr, 7); |
| 5539 | risc_size = be32_to_cpu(dcode[2]); |
| 5540 | ql_dbg(ql_dbg_init, vha, 0x0162, |
| 5541 | "-> array size %x dwords\n", risc_size); |
| 5542 | if (risc_size == 0 || risc_size == ~0) |
| 5543 | goto default_template; |
| 5544 | |
| 5545 | dlen = (risc_size - 8) * sizeof(*dcode); |
| 5546 | ql_dbg(ql_dbg_init, vha, 0x0163, |
| 5547 | "-> template allocating %x bytes...\n", dlen); |
| 5548 | ha->fw_dump_template = vmalloc(dlen); |
| 5549 | if (!ha->fw_dump_template) { |
| 5550 | ql_log(ql_log_warn, vha, 0x0164, |
| 5551 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 5552 | goto default_template; |
| 5553 | } |
| 5554 | |
| 5555 | faddr += 7; |
| 5556 | risc_size -= 8; |
| 5557 | dcode = ha->fw_dump_template; |
| 5558 | qla24xx_read_flash_data(vha, dcode, faddr, risc_size); |
| 5559 | for (i = 0; i < risc_size; i++) |
| 5560 | dcode[i] = le32_to_cpu(dcode[i]); |
| 5561 | |
| 5562 | if (!qla27xx_fwdt_template_valid(dcode)) { |
| 5563 | ql_log(ql_log_warn, vha, 0x0165, |
| 5564 | "Failed fwdump template validate\n"); |
| 5565 | goto default_template; |
| 5566 | } |
| 5567 | |
| 5568 | dlen = qla27xx_fwdt_template_size(dcode); |
| 5569 | ql_dbg(ql_dbg_init, vha, 0x0166, |
| 5570 | "-> template size %x bytes\n", dlen); |
| 5571 | if (dlen > risc_size * sizeof(*dcode)) { |
| 5572 | ql_log(ql_log_warn, vha, 0x0167, |
Chad Dupuis | 97ea702 | 2014-03-13 14:16:40 -0400 | [diff] [blame] | 5573 | "Failed fwdump template exceeds array by %x bytes\n", |
| 5574 | (uint32_t)(dlen - risc_size * sizeof(*dcode))); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 5575 | goto default_template; |
| 5576 | } |
| 5577 | ha->fw_dump_template_len = dlen; |
| 5578 | return rval; |
| 5579 | |
| 5580 | default_template: |
| 5581 | ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n"); |
| 5582 | if (ha->fw_dump_template) |
| 5583 | vfree(ha->fw_dump_template); |
| 5584 | ha->fw_dump_template = NULL; |
| 5585 | ha->fw_dump_template_len = 0; |
| 5586 | |
| 5587 | dlen = qla27xx_fwdt_template_default_size(); |
| 5588 | ql_dbg(ql_dbg_init, vha, 0x0169, |
| 5589 | "-> template allocating %x bytes...\n", dlen); |
| 5590 | ha->fw_dump_template = vmalloc(dlen); |
| 5591 | if (!ha->fw_dump_template) { |
| 5592 | ql_log(ql_log_warn, vha, 0x016a, |
| 5593 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 5594 | goto failed_template; |
| 5595 | } |
| 5596 | |
| 5597 | dcode = ha->fw_dump_template; |
| 5598 | risc_size = dlen / sizeof(*dcode); |
| 5599 | memcpy(dcode, qla27xx_fwdt_template_default(), dlen); |
| 5600 | for (i = 0; i < risc_size; i++) |
| 5601 | dcode[i] = be32_to_cpu(dcode[i]); |
| 5602 | |
| 5603 | if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) { |
| 5604 | ql_log(ql_log_warn, vha, 0x016b, |
| 5605 | "Failed fwdump template validate\n"); |
| 5606 | goto failed_template; |
| 5607 | } |
| 5608 | |
| 5609 | dlen = qla27xx_fwdt_template_size(ha->fw_dump_template); |
| 5610 | ql_dbg(ql_dbg_init, vha, 0x016c, |
| 5611 | "-> template size %x bytes\n", dlen); |
| 5612 | ha->fw_dump_template_len = dlen; |
| 5613 | return rval; |
| 5614 | |
| 5615 | failed_template: |
| 5616 | ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n"); |
| 5617 | if (ha->fw_dump_template) |
| 5618 | vfree(ha->fw_dump_template); |
| 5619 | ha->fw_dump_template = NULL; |
| 5620 | ha->fw_dump_template_len = 0; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5621 | return rval; |
| 5622 | } |
| 5623 | |
Giridhar Malavali | e9454a8 | 2013-02-08 01:57:47 -0500 | [diff] [blame] | 5624 | #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/" |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5625 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5626 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5627 | qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5628 | { |
| 5629 | int rval; |
| 5630 | int i, fragment; |
| 5631 | uint16_t *wcode, *fwcode; |
| 5632 | uint32_t risc_addr, risc_size, fwclen, wlen, *seg; |
| 5633 | struct fw_blob *blob; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5634 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5635 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5636 | |
| 5637 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5638 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5639 | if (!blob) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5640 | ql_log(ql_log_info, vha, 0x0083, |
Yannick Guerrini | 94bcf83 | 2015-02-26 22:49:34 +0100 | [diff] [blame] | 5641 | "Firmware image unavailable.\n"); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5642 | ql_log(ql_log_info, vha, 0x0084, |
| 5643 | "Firmware images can be retrieved from: "QLA_FW_URL ".\n"); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5644 | return QLA_FUNCTION_FAILED; |
| 5645 | } |
| 5646 | |
| 5647 | rval = QLA_SUCCESS; |
| 5648 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5649 | wcode = (uint16_t *)req->ring; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5650 | *srisc_addr = 0; |
| 5651 | fwcode = (uint16_t *)blob->fw->data; |
| 5652 | fwclen = 0; |
| 5653 | |
| 5654 | /* Validate firmware image by checking version. */ |
| 5655 | if (blob->fw->size < 8 * sizeof(uint16_t)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5656 | ql_log(ql_log_fatal, vha, 0x0085, |
| 5657 | "Unable to verify integrity of firmware image (%Zd).\n", |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5658 | blob->fw->size); |
| 5659 | goto fail_fw_integrity; |
| 5660 | } |
| 5661 | for (i = 0; i < 4; i++) |
| 5662 | wcode[i] = be16_to_cpu(fwcode[i + 4]); |
| 5663 | if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff && |
| 5664 | wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 && |
| 5665 | wcode[2] == 0 && wcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5666 | ql_log(ql_log_fatal, vha, 0x0086, |
| 5667 | "Unable to verify integrity of firmware image.\n"); |
| 5668 | ql_log(ql_log_fatal, vha, 0x0087, |
| 5669 | "Firmware data: %04x %04x %04x %04x.\n", |
| 5670 | wcode[0], wcode[1], wcode[2], wcode[3]); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5671 | goto fail_fw_integrity; |
| 5672 | } |
| 5673 | |
| 5674 | seg = blob->segs; |
| 5675 | while (*seg && rval == QLA_SUCCESS) { |
| 5676 | risc_addr = *seg; |
| 5677 | *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr; |
| 5678 | risc_size = be16_to_cpu(fwcode[3]); |
| 5679 | |
| 5680 | /* Validate firmware image size. */ |
| 5681 | fwclen += risc_size * sizeof(uint16_t); |
| 5682 | if (blob->fw->size < fwclen) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5683 | ql_log(ql_log_fatal, vha, 0x0088, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5684 | "Unable to verify integrity of firmware image " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5685 | "(%Zd).\n", blob->fw->size); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5686 | goto fail_fw_integrity; |
| 5687 | } |
| 5688 | |
| 5689 | fragment = 0; |
| 5690 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 5691 | wlen = (uint16_t)(ha->fw_transfer_size >> 1); |
| 5692 | if (wlen > risc_size) |
| 5693 | wlen = risc_size; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5694 | ql_dbg(ql_dbg_init, vha, 0x0089, |
| 5695 | "Loading risc segment@ risc addr %x number of " |
| 5696 | "words 0x%x.\n", risc_addr, wlen); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5697 | |
| 5698 | for (i = 0; i < wlen; i++) |
| 5699 | wcode[i] = swab16(fwcode[i]); |
| 5700 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5701 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5702 | wlen); |
| 5703 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5704 | ql_log(ql_log_fatal, vha, 0x008a, |
| 5705 | "Failed to load segment %d of firmware.\n", |
| 5706 | fragment); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5707 | break; |
| 5708 | } |
| 5709 | |
| 5710 | fwcode += wlen; |
| 5711 | risc_addr += wlen; |
| 5712 | risc_size -= wlen; |
| 5713 | fragment++; |
| 5714 | } |
| 5715 | |
| 5716 | /* Next segment. */ |
| 5717 | seg++; |
| 5718 | } |
| 5719 | return rval; |
| 5720 | |
| 5721 | fail_fw_integrity: |
| 5722 | return QLA_FUNCTION_FAILED; |
| 5723 | } |
| 5724 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5725 | static int |
| 5726 | qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5727 | { |
| 5728 | int rval; |
| 5729 | int segments, fragment; |
| 5730 | uint32_t *dcode, dlen; |
| 5731 | uint32_t risc_addr; |
| 5732 | uint32_t risc_size; |
| 5733 | uint32_t i; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5734 | struct fw_blob *blob; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 5735 | const uint32_t *fwcode; |
| 5736 | uint32_t fwclen; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5737 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5738 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5739 | |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5740 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5741 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5742 | if (!blob) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5743 | ql_log(ql_log_warn, vha, 0x0090, |
Yannick Guerrini | 94bcf83 | 2015-02-26 22:49:34 +0100 | [diff] [blame] | 5744 | "Firmware image unavailable.\n"); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5745 | ql_log(ql_log_warn, vha, 0x0091, |
| 5746 | "Firmware images can be retrieved from: " |
| 5747 | QLA_FW_URL ".\n"); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5748 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5749 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5750 | } |
| 5751 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5752 | ql_dbg(ql_dbg_init, vha, 0x0092, |
| 5753 | "FW: Loading via request-firmware.\n"); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5754 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5755 | rval = QLA_SUCCESS; |
| 5756 | |
| 5757 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5758 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5759 | *srisc_addr = 0; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5760 | fwcode = (uint32_t *)blob->fw->data; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5761 | fwclen = 0; |
| 5762 | |
| 5763 | /* Validate firmware image by checking version. */ |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5764 | if (blob->fw->size < 8 * sizeof(uint32_t)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5765 | ql_log(ql_log_fatal, vha, 0x0093, |
| 5766 | "Unable to verify integrity of firmware image (%Zd).\n", |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5767 | blob->fw->size); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 5768 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5769 | } |
| 5770 | for (i = 0; i < 4; i++) |
| 5771 | dcode[i] = be32_to_cpu(fwcode[i + 4]); |
| 5772 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 5773 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 5774 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 5775 | dcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5776 | ql_log(ql_log_fatal, vha, 0x0094, |
| 5777 | "Unable to verify integrity of firmware image (%Zd).\n", |
| 5778 | blob->fw->size); |
| 5779 | ql_log(ql_log_fatal, vha, 0x0095, |
| 5780 | "Firmware data: %08x %08x %08x %08x.\n", |
| 5781 | dcode[0], dcode[1], dcode[2], dcode[3]); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 5782 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5783 | } |
| 5784 | |
| 5785 | while (segments && rval == QLA_SUCCESS) { |
| 5786 | risc_addr = be32_to_cpu(fwcode[2]); |
| 5787 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 5788 | risc_size = be32_to_cpu(fwcode[3]); |
| 5789 | |
| 5790 | /* Validate firmware image size. */ |
| 5791 | fwclen += risc_size * sizeof(uint32_t); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5792 | if (blob->fw->size < fwclen) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5793 | ql_log(ql_log_fatal, vha, 0x0096, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5794 | "Unable to verify integrity of firmware image " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5795 | "(%Zd).\n", blob->fw->size); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 5796 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5797 | } |
| 5798 | |
| 5799 | fragment = 0; |
| 5800 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 5801 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 5802 | if (dlen > risc_size) |
| 5803 | dlen = risc_size; |
| 5804 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5805 | ql_dbg(ql_dbg_init, vha, 0x0097, |
| 5806 | "Loading risc segment@ risc addr %x " |
| 5807 | "number of dwords 0x%x.\n", risc_addr, dlen); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5808 | |
| 5809 | for (i = 0; i < dlen; i++) |
| 5810 | dcode[i] = swab32(fwcode[i]); |
| 5811 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5812 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
andrew.vasquez@qlogic.com | 590f98e | 2006-01-13 17:05:37 -0800 | [diff] [blame] | 5813 | dlen); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5814 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5815 | ql_log(ql_log_fatal, vha, 0x0098, |
| 5816 | "Failed to load segment %d of firmware.\n", |
| 5817 | fragment); |
Chad Dupuis | f261f7a | 2014-09-25 05:17:03 -0400 | [diff] [blame] | 5818 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5819 | } |
| 5820 | |
| 5821 | fwcode += dlen; |
| 5822 | risc_addr += dlen; |
| 5823 | risc_size -= dlen; |
| 5824 | fragment++; |
| 5825 | } |
| 5826 | |
| 5827 | /* Next segment. */ |
| 5828 | segments--; |
| 5829 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 5830 | |
| 5831 | if (!IS_QLA27XX(ha)) |
| 5832 | return rval; |
| 5833 | |
| 5834 | if (ha->fw_dump_template) |
| 5835 | vfree(ha->fw_dump_template); |
| 5836 | ha->fw_dump_template = NULL; |
| 5837 | ha->fw_dump_template_len = 0; |
| 5838 | |
| 5839 | ql_dbg(ql_dbg_init, vha, 0x171, |
Chad Dupuis | 97ea702 | 2014-03-13 14:16:40 -0400 | [diff] [blame] | 5840 | "Loading fwdump template from %x\n", |
| 5841 | (uint32_t)((void *)fwcode - (void *)blob->fw->data)); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 5842 | risc_size = be32_to_cpu(fwcode[2]); |
| 5843 | ql_dbg(ql_dbg_init, vha, 0x172, |
| 5844 | "-> array size %x dwords\n", risc_size); |
| 5845 | if (risc_size == 0 || risc_size == ~0) |
| 5846 | goto default_template; |
| 5847 | |
| 5848 | dlen = (risc_size - 8) * sizeof(*fwcode); |
| 5849 | ql_dbg(ql_dbg_init, vha, 0x0173, |
| 5850 | "-> template allocating %x bytes...\n", dlen); |
| 5851 | ha->fw_dump_template = vmalloc(dlen); |
| 5852 | if (!ha->fw_dump_template) { |
| 5853 | ql_log(ql_log_warn, vha, 0x0174, |
| 5854 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 5855 | goto default_template; |
| 5856 | } |
| 5857 | |
| 5858 | fwcode += 7; |
| 5859 | risc_size -= 8; |
| 5860 | dcode = ha->fw_dump_template; |
| 5861 | for (i = 0; i < risc_size; i++) |
| 5862 | dcode[i] = le32_to_cpu(fwcode[i]); |
| 5863 | |
| 5864 | if (!qla27xx_fwdt_template_valid(dcode)) { |
| 5865 | ql_log(ql_log_warn, vha, 0x0175, |
| 5866 | "Failed fwdump template validate\n"); |
| 5867 | goto default_template; |
| 5868 | } |
| 5869 | |
| 5870 | dlen = qla27xx_fwdt_template_size(dcode); |
| 5871 | ql_dbg(ql_dbg_init, vha, 0x0176, |
| 5872 | "-> template size %x bytes\n", dlen); |
| 5873 | if (dlen > risc_size * sizeof(*fwcode)) { |
| 5874 | ql_log(ql_log_warn, vha, 0x0177, |
Chad Dupuis | 97ea702 | 2014-03-13 14:16:40 -0400 | [diff] [blame] | 5875 | "Failed fwdump template exceeds array by %x bytes\n", |
| 5876 | (uint32_t)(dlen - risc_size * sizeof(*fwcode))); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 5877 | goto default_template; |
| 5878 | } |
| 5879 | ha->fw_dump_template_len = dlen; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5880 | return rval; |
| 5881 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 5882 | default_template: |
| 5883 | ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n"); |
| 5884 | if (ha->fw_dump_template) |
| 5885 | vfree(ha->fw_dump_template); |
| 5886 | ha->fw_dump_template = NULL; |
| 5887 | ha->fw_dump_template_len = 0; |
| 5888 | |
| 5889 | dlen = qla27xx_fwdt_template_default_size(); |
| 5890 | ql_dbg(ql_dbg_init, vha, 0x0179, |
| 5891 | "-> template allocating %x bytes...\n", dlen); |
| 5892 | ha->fw_dump_template = vmalloc(dlen); |
| 5893 | if (!ha->fw_dump_template) { |
| 5894 | ql_log(ql_log_warn, vha, 0x017a, |
| 5895 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 5896 | goto failed_template; |
| 5897 | } |
| 5898 | |
| 5899 | dcode = ha->fw_dump_template; |
| 5900 | risc_size = dlen / sizeof(*fwcode); |
| 5901 | fwcode = qla27xx_fwdt_template_default(); |
| 5902 | for (i = 0; i < risc_size; i++) |
| 5903 | dcode[i] = be32_to_cpu(fwcode[i]); |
| 5904 | |
| 5905 | if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) { |
| 5906 | ql_log(ql_log_warn, vha, 0x017b, |
| 5907 | "Failed fwdump template validate\n"); |
| 5908 | goto failed_template; |
| 5909 | } |
| 5910 | |
| 5911 | dlen = qla27xx_fwdt_template_size(ha->fw_dump_template); |
| 5912 | ql_dbg(ql_dbg_init, vha, 0x017c, |
| 5913 | "-> template size %x bytes\n", dlen); |
| 5914 | ha->fw_dump_template_len = dlen; |
| 5915 | return rval; |
| 5916 | |
| 5917 | failed_template: |
| 5918 | ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n"); |
| 5919 | if (ha->fw_dump_template) |
| 5920 | vfree(ha->fw_dump_template); |
| 5921 | ha->fw_dump_template = NULL; |
| 5922 | ha->fw_dump_template_len = 0; |
| 5923 | return rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5924 | } |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5925 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5926 | int |
| 5927 | qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 5928 | { |
| 5929 | int rval; |
| 5930 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 5931 | if (ql2xfwloadbin == 1) |
| 5932 | return qla81xx_load_risc(vha, srisc_addr); |
| 5933 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5934 | /* |
| 5935 | * FW Load priority: |
| 5936 | * 1) Firmware via request-firmware interface (.bin file). |
| 5937 | * 2) Firmware residing in flash. |
| 5938 | */ |
| 5939 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 5940 | if (rval == QLA_SUCCESS) |
| 5941 | return rval; |
| 5942 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5943 | return qla24xx_load_risc_flash(vha, srisc_addr, |
| 5944 | vha->hw->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5945 | } |
| 5946 | |
| 5947 | int |
| 5948 | qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 5949 | { |
| 5950 | int rval; |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5951 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5952 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 5953 | if (ql2xfwloadbin == 2) |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5954 | goto try_blob_fw; |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 5955 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5956 | /* |
| 5957 | * FW Load priority: |
| 5958 | * 1) Firmware residing in flash. |
| 5959 | * 2) Firmware via request-firmware interface (.bin file). |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5960 | * 3) Golden-Firmware residing in flash -- limited operation. |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5961 | */ |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5962 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5963 | if (rval == QLA_SUCCESS) |
| 5964 | return rval; |
| 5965 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5966 | try_blob_fw: |
| 5967 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 5968 | if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw) |
| 5969 | return rval; |
| 5970 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5971 | ql_log(ql_log_info, vha, 0x0099, |
| 5972 | "Attempting to fallback to golden firmware.\n"); |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5973 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw); |
| 5974 | if (rval != QLA_SUCCESS) |
| 5975 | return rval; |
| 5976 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5977 | ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n"); |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5978 | ha->flags.running_gold_fw = 1; |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5979 | return rval; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5980 | } |
| 5981 | |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5982 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5983 | qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5984 | { |
| 5985 | int ret, retries; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5986 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5987 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 5988 | if (ha->flags.pci_channel_io_perm_failure) |
| 5989 | return; |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 5990 | if (!IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5991 | return; |
Andrew Vasquez | 75edf81 | 2007-05-07 07:43:00 -0700 | [diff] [blame] | 5992 | if (!ha->fw_major_version) |
| 5993 | return; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5994 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5995 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 7c7f1f2 | 2008-02-28 14:06:09 -0800 | [diff] [blame] | 5996 | for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT && |
Andrew Vasquez | b469a7c | 2009-04-06 22:33:48 -0700 | [diff] [blame] | 5997 | ret != QLA_INVALID_COMMAND && retries ; retries--) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5998 | ha->isp_ops->reset_chip(vha); |
| 5999 | if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6000 | continue; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6001 | if (qla2x00_setup_chip(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6002 | continue; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6003 | ql_log(ql_log_info, vha, 0x8015, |
| 6004 | "Attempting retry of stop-firmware command.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6005 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6006 | } |
| 6007 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6008 | |
| 6009 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6010 | qla24xx_configure_vhba(scsi_qla_host_t *vha) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6011 | { |
| 6012 | int rval = QLA_SUCCESS; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 6013 | int rval2; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6014 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6015 | struct qla_hw_data *ha = vha->hw; |
| 6016 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 6017 | struct req_que *req; |
| 6018 | struct rsp_que *rsp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6019 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6020 | if (!vha->vp_idx) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6021 | return -EINVAL; |
| 6022 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6023 | rval = qla2x00_fw_ready(base_vha); |
Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 6024 | if (ha->flags.cpu_affinity_enabled) |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 6025 | req = ha->req_q_map[0]; |
| 6026 | else |
| 6027 | req = vha->req; |
| 6028 | rsp = req->rsp; |
| 6029 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6030 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6031 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6032 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6033 | } |
| 6034 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6035 | vha->flags.management_server_logged_in = 0; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6036 | |
| 6037 | /* Login to SNS first */ |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 6038 | rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, |
| 6039 | BIT_1); |
| 6040 | if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) { |
| 6041 | if (rval2 == QLA_MEMORY_ALLOC_FAILED) |
| 6042 | ql_dbg(ql_dbg_init, vha, 0x0120, |
| 6043 | "Failed SNS login: loop_id=%x, rval2=%d\n", |
| 6044 | NPH_SNS, rval2); |
| 6045 | else |
| 6046 | ql_dbg(ql_dbg_init, vha, 0x0103, |
| 6047 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x " |
| 6048 | "mb[2]=%x mb[6]=%x mb[7]=%x.\n", |
| 6049 | NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6050 | return (QLA_FUNCTION_FAILED); |
| 6051 | } |
| 6052 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6053 | atomic_set(&vha->loop_down_timer, 0); |
| 6054 | atomic_set(&vha->loop_state, LOOP_UP); |
| 6055 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 6056 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 6057 | rval = qla2x00_loop_resync(base_vha); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6058 | |
| 6059 | return rval; |
| 6060 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6061 | |
| 6062 | /* 84XX Support **************************************************************/ |
| 6063 | |
| 6064 | static LIST_HEAD(qla_cs84xx_list); |
| 6065 | static DEFINE_MUTEX(qla_cs84xx_mutex); |
| 6066 | |
| 6067 | static struct qla_chip_state_84xx * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6068 | qla84xx_get_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6069 | { |
| 6070 | struct qla_chip_state_84xx *cs84xx; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6071 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6072 | |
| 6073 | mutex_lock(&qla_cs84xx_mutex); |
| 6074 | |
| 6075 | /* Find any shared 84xx chip. */ |
| 6076 | list_for_each_entry(cs84xx, &qla_cs84xx_list, list) { |
| 6077 | if (cs84xx->bus == ha->pdev->bus) { |
| 6078 | kref_get(&cs84xx->kref); |
| 6079 | goto done; |
| 6080 | } |
| 6081 | } |
| 6082 | |
| 6083 | cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL); |
| 6084 | if (!cs84xx) |
| 6085 | goto done; |
| 6086 | |
| 6087 | kref_init(&cs84xx->kref); |
| 6088 | spin_lock_init(&cs84xx->access_lock); |
| 6089 | mutex_init(&cs84xx->fw_update_mutex); |
| 6090 | cs84xx->bus = ha->pdev->bus; |
| 6091 | |
| 6092 | list_add_tail(&cs84xx->list, &qla_cs84xx_list); |
| 6093 | done: |
| 6094 | mutex_unlock(&qla_cs84xx_mutex); |
| 6095 | return cs84xx; |
| 6096 | } |
| 6097 | |
| 6098 | static void |
| 6099 | __qla84xx_chip_release(struct kref *kref) |
| 6100 | { |
| 6101 | struct qla_chip_state_84xx *cs84xx = |
| 6102 | container_of(kref, struct qla_chip_state_84xx, kref); |
| 6103 | |
| 6104 | mutex_lock(&qla_cs84xx_mutex); |
| 6105 | list_del(&cs84xx->list); |
| 6106 | mutex_unlock(&qla_cs84xx_mutex); |
| 6107 | kfree(cs84xx); |
| 6108 | } |
| 6109 | |
| 6110 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6111 | qla84xx_put_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6112 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6113 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6114 | if (ha->cs84xx) |
| 6115 | kref_put(&ha->cs84xx->kref, __qla84xx_chip_release); |
| 6116 | } |
| 6117 | |
| 6118 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6119 | qla84xx_init_chip(scsi_qla_host_t *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6120 | { |
| 6121 | int rval; |
| 6122 | uint16_t status[2]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6123 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6124 | |
| 6125 | mutex_lock(&ha->cs84xx->fw_update_mutex); |
| 6126 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6127 | rval = qla84xx_verify_chip(vha, status); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6128 | |
| 6129 | mutex_unlock(&ha->cs84xx->fw_update_mutex); |
| 6130 | |
| 6131 | return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED: |
| 6132 | QLA_SUCCESS; |
| 6133 | } |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6134 | |
| 6135 | /* 81XX Support **************************************************************/ |
| 6136 | |
| 6137 | int |
| 6138 | qla81xx_nvram_config(scsi_qla_host_t *vha) |
| 6139 | { |
| 6140 | int rval; |
| 6141 | struct init_cb_81xx *icb; |
| 6142 | struct nvram_81xx *nv; |
| 6143 | uint32_t *dptr; |
| 6144 | uint8_t *dptr1, *dptr2; |
| 6145 | uint32_t chksum; |
| 6146 | uint16_t cnt; |
| 6147 | struct qla_hw_data *ha = vha->hw; |
| 6148 | |
| 6149 | rval = QLA_SUCCESS; |
| 6150 | icb = (struct init_cb_81xx *)ha->init_cb; |
| 6151 | nv = ha->nvram; |
| 6152 | |
| 6153 | /* Determine NVRAM starting address. */ |
| 6154 | ha->nvram_size = sizeof(struct nvram_81xx); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6155 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 6156 | if (IS_P3P_TYPE(ha) || IS_QLA8031(ha)) |
| 6157 | ha->vpd_size = FA_VPD_SIZE_82XX; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6158 | |
| 6159 | /* Get VPD data into cache */ |
| 6160 | ha->vpd = ha->nvram + VPD_OFFSET; |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 6161 | ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2, |
| 6162 | ha->vpd_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6163 | |
| 6164 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 6165 | ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6166 | ha->nvram_size); |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 6167 | dptr = (uint32_t *)nv; |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 6168 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++) |
| 6169 | chksum += le32_to_cpu(*dptr); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6170 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6171 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111, |
| 6172 | "Contents of NVRAM:\n"); |
| 6173 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112, |
| 6174 | (uint8_t *)nv, ha->nvram_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6175 | |
| 6176 | /* Bad NVRAM data, set defaults parameters. */ |
| 6177 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 6178 | || nv->id[3] != ' ' || |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6179 | nv->nvram_version < cpu_to_le16(ICB_VERSION)) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6180 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6181 | ql_log(ql_log_info, vha, 0x0073, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 6182 | "Inconsistent NVRAM detected: checksum=0x%x id=%c " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6183 | "version=0x%x.\n", chksum, nv->id[0], |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6184 | le16_to_cpu(nv->nvram_version)); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6185 | ql_log(ql_log_info, vha, 0x0074, |
| 6186 | "Falling back to functioning (yet invalid -- WWPN) " |
| 6187 | "defaults.\n"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6188 | |
| 6189 | /* |
| 6190 | * Set default initialization control block. |
| 6191 | */ |
| 6192 | memset(nv, 0, ha->nvram_size); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6193 | nv->nvram_version = cpu_to_le16(ICB_VERSION); |
| 6194 | nv->version = cpu_to_le16(ICB_VERSION); |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 6195 | nv->frame_payload_size = 2048; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6196 | nv->execution_throttle = cpu_to_le16(0xFFFF); |
| 6197 | nv->exchange_count = cpu_to_le16(0); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6198 | nv->port_name[0] = 0x21; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6199 | nv->port_name[1] = 0x00 + ha->port_no + 1; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6200 | nv->port_name[2] = 0x00; |
| 6201 | nv->port_name[3] = 0xe0; |
| 6202 | nv->port_name[4] = 0x8b; |
| 6203 | nv->port_name[5] = 0x1c; |
| 6204 | nv->port_name[6] = 0x55; |
| 6205 | nv->port_name[7] = 0x86; |
| 6206 | nv->node_name[0] = 0x20; |
| 6207 | nv->node_name[1] = 0x00; |
| 6208 | nv->node_name[2] = 0x00; |
| 6209 | nv->node_name[3] = 0xe0; |
| 6210 | nv->node_name[4] = 0x8b; |
| 6211 | nv->node_name[5] = 0x1c; |
| 6212 | nv->node_name[6] = 0x55; |
| 6213 | nv->node_name[7] = 0x86; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6214 | nv->login_retry_count = cpu_to_le16(8); |
| 6215 | nv->interrupt_delay_timer = cpu_to_le16(0); |
| 6216 | nv->login_timeout = cpu_to_le16(0); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6217 | nv->firmware_options_1 = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6218 | cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 6219 | nv->firmware_options_2 = cpu_to_le32(2 << 4); |
| 6220 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 6221 | nv->firmware_options_3 = cpu_to_le32(2 << 13); |
| 6222 | nv->host_p = cpu_to_le32(BIT_11|BIT_10); |
| 6223 | nv->efi_parameters = cpu_to_le32(0); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6224 | nv->reset_delay = 5; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6225 | nv->max_luns_per_target = cpu_to_le16(128); |
| 6226 | nv->port_down_retry_count = cpu_to_le16(30); |
| 6227 | nv->link_down_timeout = cpu_to_le16(180); |
Andrew Vasquez | eeebcc9 | 2009-06-03 09:55:24 -0700 | [diff] [blame] | 6228 | nv->enode_mac[0] = 0x00; |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 6229 | nv->enode_mac[1] = 0xC0; |
| 6230 | nv->enode_mac[2] = 0xDD; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6231 | nv->enode_mac[3] = 0x04; |
| 6232 | nv->enode_mac[4] = 0x05; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6233 | nv->enode_mac[5] = 0x06 + ha->port_no + 1; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6234 | |
| 6235 | rval = 1; |
| 6236 | } |
| 6237 | |
Arun Easi | 9e522cd | 2012-08-22 14:21:31 -0400 | [diff] [blame] | 6238 | if (IS_T10_PI_CAPABLE(ha)) |
| 6239 | nv->frame_payload_size &= ~7; |
| 6240 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6241 | qlt_81xx_config_nvram_stage1(vha, nv); |
| 6242 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6243 | /* Reset Initialization control block */ |
Andrew Vasquez | 773120e | 2011-05-10 11:30:14 -0700 | [diff] [blame] | 6244 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6245 | |
| 6246 | /* Copy 1st segment. */ |
| 6247 | dptr1 = (uint8_t *)icb; |
| 6248 | dptr2 = (uint8_t *)&nv->version; |
| 6249 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 6250 | while (cnt--) |
| 6251 | *dptr1++ = *dptr2++; |
| 6252 | |
| 6253 | icb->login_retry_count = nv->login_retry_count; |
| 6254 | |
| 6255 | /* Copy 2nd segment. */ |
| 6256 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 6257 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 6258 | cnt = (uint8_t *)&icb->reserved_5 - |
| 6259 | (uint8_t *)&icb->interrupt_delay_timer; |
| 6260 | while (cnt--) |
| 6261 | *dptr1++ = *dptr2++; |
| 6262 | |
| 6263 | memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac)); |
| 6264 | /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */ |
| 6265 | if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) { |
Andrew Vasquez | 69e5f1e | 2012-02-09 11:15:35 -0800 | [diff] [blame] | 6266 | icb->enode_mac[0] = 0x00; |
| 6267 | icb->enode_mac[1] = 0xC0; |
| 6268 | icb->enode_mac[2] = 0xDD; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6269 | icb->enode_mac[3] = 0x04; |
| 6270 | icb->enode_mac[4] = 0x05; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6271 | icb->enode_mac[5] = 0x06 + ha->port_no + 1; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6272 | } |
| 6273 | |
Andrew Vasquez | b64b0e8 | 2009-03-24 09:08:01 -0700 | [diff] [blame] | 6274 | /* Use extended-initialization control block. */ |
| 6275 | memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb)); |
| 6276 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6277 | /* |
| 6278 | * Setup driver NVRAM options. |
| 6279 | */ |
| 6280 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6281 | "QLE8XXX"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6282 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 6283 | qlt_81xx_config_nvram_stage2(vha, icb); |
| 6284 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6285 | /* Use alternate WWN? */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6286 | if (nv->host_p & cpu_to_le32(BIT_15)) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6287 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 6288 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 6289 | } |
| 6290 | |
| 6291 | /* Prepare nodename */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6292 | if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6293 | /* |
| 6294 | * Firmware will apply the following mask if the nodename was |
| 6295 | * not provided. |
| 6296 | */ |
| 6297 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 6298 | icb->node_name[0] &= 0xF0; |
| 6299 | } |
| 6300 | |
| 6301 | /* Set host adapter parameters. */ |
| 6302 | ha->flags.disable_risc_code_load = 0; |
| 6303 | ha->flags.enable_lip_reset = 0; |
| 6304 | ha->flags.enable_lip_full_login = |
| 6305 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 6306 | ha->flags.enable_target_reset = |
| 6307 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
| 6308 | ha->flags.enable_led_scheme = 0; |
| 6309 | ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0; |
| 6310 | |
| 6311 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 6312 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 6313 | |
| 6314 | /* save HBA serial number */ |
| 6315 | ha->serial0 = icb->port_name[5]; |
| 6316 | ha->serial1 = icb->port_name[6]; |
| 6317 | ha->serial2 = icb->port_name[7]; |
| 6318 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 6319 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
| 6320 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6321 | icb->execution_throttle = cpu_to_le16(0xFFFF); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6322 | |
| 6323 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 6324 | |
| 6325 | /* Set minimum login_timeout to 4 seconds. */ |
| 6326 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 6327 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 6328 | if (le16_to_cpu(nv->login_timeout) < 4) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6329 | nv->login_timeout = cpu_to_le16(4); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6330 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6331 | |
| 6332 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 6333 | ha->r_a_tov = 100; |
| 6334 | |
| 6335 | ha->loop_reset_delay = nv->reset_delay; |
| 6336 | |
| 6337 | /* Link Down Timeout = 0: |
| 6338 | * |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 6339 | * When Port Down timer expires we will start returning |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6340 | * I/O's to OS with "DID_NO_CONNECT". |
| 6341 | * |
| 6342 | * Link Down Timeout != 0: |
| 6343 | * |
| 6344 | * The driver waits for the link to come up after link down |
| 6345 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 6346 | */ |
| 6347 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 6348 | ha->loop_down_abort_time = |
| 6349 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 6350 | } else { |
| 6351 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 6352 | ha->loop_down_abort_time = |
| 6353 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 6354 | } |
| 6355 | |
| 6356 | /* Need enough time to try and get the port back. */ |
| 6357 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 6358 | if (qlport_down_retry) |
| 6359 | ha->port_down_retry_count = qlport_down_retry; |
| 6360 | |
| 6361 | /* Set login_retry_count */ |
| 6362 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 6363 | if (ha->port_down_retry_count == |
| 6364 | le16_to_cpu(nv->port_down_retry_count) && |
| 6365 | ha->port_down_retry_count > 3) |
| 6366 | ha->login_retry_count = ha->port_down_retry_count; |
| 6367 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 6368 | ha->login_retry_count = ha->port_down_retry_count; |
| 6369 | if (ql2xloginretrycount) |
| 6370 | ha->login_retry_count = ql2xloginretrycount; |
| 6371 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 6372 | /* if not running MSI-X we need handshaking on interrupts */ |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6373 | if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha))) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6374 | icb->firmware_options_2 |= cpu_to_le32(BIT_22); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 6375 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6376 | /* Enable ZIO. */ |
| 6377 | if (!vha->flags.init_done) { |
| 6378 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 6379 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 6380 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 6381 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 6382 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6383 | icb->firmware_options_2 &= cpu_to_le32( |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6384 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
| 6385 | vha->flags.process_response_queue = 0; |
| 6386 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
| 6387 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 6388 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6389 | ql_log(ql_log_info, vha, 0x0075, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6390 | "ZIO mode %d enabled; timer delay (%d us).\n", |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6391 | ha->zio_mode, |
| 6392 | ha->zio_timer * 100); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6393 | |
| 6394 | icb->firmware_options_2 |= cpu_to_le32( |
| 6395 | (uint32_t)ha->zio_mode); |
| 6396 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
| 6397 | vha->flags.process_response_queue = 1; |
| 6398 | } |
| 6399 | |
| 6400 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6401 | ql_log(ql_log_warn, vha, 0x0076, |
| 6402 | "NVRAM configuration failed.\n"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6403 | } |
| 6404 | return (rval); |
| 6405 | } |
| 6406 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6407 | int |
| 6408 | qla82xx_restart_isp(scsi_qla_host_t *vha) |
| 6409 | { |
| 6410 | int status, rval; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6411 | struct qla_hw_data *ha = vha->hw; |
| 6412 | struct req_que *req = ha->req_q_map[0]; |
| 6413 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
| 6414 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6415 | unsigned long flags; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6416 | |
| 6417 | status = qla2x00_init_rings(vha); |
| 6418 | if (!status) { |
| 6419 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 6420 | ha->flags.chip_reset_done = 1; |
| 6421 | |
| 6422 | status = qla2x00_fw_ready(vha); |
| 6423 | if (!status) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6424 | /* Issue a marker after FW becomes ready. */ |
| 6425 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6426 | vha->flags.online = 1; |
Chad Dupuis | 7108b76 | 2014-04-11 16:54:45 -0400 | [diff] [blame] | 6427 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6428 | } |
| 6429 | |
| 6430 | /* if no cable then assume it's good */ |
| 6431 | if ((vha->device_flags & DFLG_NO_CABLE)) |
| 6432 | status = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6433 | } |
| 6434 | |
| 6435 | if (!status) { |
| 6436 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 6437 | |
| 6438 | if (!atomic_read(&vha->loop_down_timer)) { |
| 6439 | /* |
| 6440 | * Issue marker command only when we are going |
| 6441 | * to start the I/O . |
| 6442 | */ |
| 6443 | vha->marker_needed = 1; |
| 6444 | } |
| 6445 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6446 | ha->isp_ops->enable_intrs(ha); |
| 6447 | |
| 6448 | ha->isp_abort_cnt = 0; |
| 6449 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 6450 | |
Saurav Kashyap | 5329678 | 2011-05-10 11:30:06 -0700 | [diff] [blame] | 6451 | /* Update the firmware version */ |
Giridhar Malavali | 3173167 | 2011-08-16 11:31:54 -0700 | [diff] [blame] | 6452 | status = qla82xx_check_md_needed(vha); |
Saurav Kashyap | 5329678 | 2011-05-10 11:30:06 -0700 | [diff] [blame] | 6453 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6454 | if (ha->fce) { |
| 6455 | ha->flags.fce_enabled = 1; |
| 6456 | memset(ha->fce, 0, |
| 6457 | fce_calc_size(ha->fce_bufs)); |
| 6458 | rval = qla2x00_enable_fce_trace(vha, |
| 6459 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 6460 | &ha->fce_bufs); |
| 6461 | if (rval) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 6462 | ql_log(ql_log_warn, vha, 0x8001, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6463 | "Unable to reinitialize FCE (%d).\n", |
| 6464 | rval); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6465 | ha->flags.fce_enabled = 0; |
| 6466 | } |
| 6467 | } |
| 6468 | |
| 6469 | if (ha->eft) { |
| 6470 | memset(ha->eft, 0, EFT_SIZE); |
| 6471 | rval = qla2x00_enable_eft_trace(vha, |
| 6472 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 6473 | if (rval) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 6474 | ql_log(ql_log_warn, vha, 0x8010, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6475 | "Unable to reinitialize EFT (%d).\n", |
| 6476 | rval); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6477 | } |
| 6478 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6479 | } |
| 6480 | |
| 6481 | if (!status) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 6482 | ql_dbg(ql_dbg_taskm, vha, 0x8011, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6483 | "qla82xx_restart_isp succeeded.\n"); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6484 | |
| 6485 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 6486 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 6487 | if (vp->vp_idx) { |
| 6488 | atomic_inc(&vp->vref_count); |
| 6489 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 6490 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6491 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6492 | |
| 6493 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 6494 | atomic_dec(&vp->vref_count); |
| 6495 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6496 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6497 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 6498 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6499 | } else { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 6500 | ql_log(ql_log_warn, vha, 0x8016, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6501 | "qla82xx_restart_isp **** FAILED ****.\n"); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6502 | } |
| 6503 | |
| 6504 | return status; |
| 6505 | } |
| 6506 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6507 | void |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 6508 | qla81xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6509 | { |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 6510 | struct qla_hw_data *ha = vha->hw; |
| 6511 | |
Himanshu Madhani | f198caf | 2016-01-27 12:03:30 -0500 | [diff] [blame] | 6512 | /* Hold status IOCBs until ABTS response received. */ |
| 6513 | if (ql2xfwholdabts) |
| 6514 | ha->fw_options[3] |= BIT_12; |
| 6515 | |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 6516 | if (!ql2xetsenable) |
Himanshu Madhani | f198caf | 2016-01-27 12:03:30 -0500 | [diff] [blame] | 6517 | goto out; |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 6518 | |
| 6519 | /* Enable ETS Burst. */ |
| 6520 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
| 6521 | ha->fw_options[2] |= BIT_9; |
Himanshu Madhani | f198caf | 2016-01-27 12:03:30 -0500 | [diff] [blame] | 6522 | out: |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 6523 | qla2x00_set_fw_options(vha, ha->fw_options); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6524 | } |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 6525 | |
| 6526 | /* |
| 6527 | * qla24xx_get_fcp_prio |
| 6528 | * Gets the fcp cmd priority value for the logged in port. |
| 6529 | * Looks for a match of the port descriptors within |
| 6530 | * each of the fcp prio config entries. If a match is found, |
| 6531 | * the tag (priority) value is returned. |
| 6532 | * |
| 6533 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 6534 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 6535 | * fcport = port structure pointer. |
| 6536 | * |
| 6537 | * Return: |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 6538 | * non-zero (if found) |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 6539 | * -1 (if not found) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 6540 | * |
| 6541 | * Context: |
| 6542 | * Kernel context |
| 6543 | */ |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 6544 | static int |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 6545 | qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 6546 | { |
| 6547 | int i, entries; |
| 6548 | uint8_t pid_match, wwn_match; |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 6549 | int priority; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 6550 | uint32_t pid1, pid2; |
| 6551 | uint64_t wwn1, wwn2; |
| 6552 | struct qla_fcp_prio_entry *pri_entry; |
| 6553 | struct qla_hw_data *ha = vha->hw; |
| 6554 | |
| 6555 | if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled) |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 6556 | return -1; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 6557 | |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 6558 | priority = -1; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 6559 | entries = ha->fcp_prio_cfg->num_entries; |
| 6560 | pri_entry = &ha->fcp_prio_cfg->entry[0]; |
| 6561 | |
| 6562 | for (i = 0; i < entries; i++) { |
| 6563 | pid_match = wwn_match = 0; |
| 6564 | |
| 6565 | if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) { |
| 6566 | pri_entry++; |
| 6567 | continue; |
| 6568 | } |
| 6569 | |
| 6570 | /* check source pid for a match */ |
| 6571 | if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) { |
| 6572 | pid1 = pri_entry->src_pid & INVALID_PORT_ID; |
| 6573 | pid2 = vha->d_id.b24 & INVALID_PORT_ID; |
| 6574 | if (pid1 == INVALID_PORT_ID) |
| 6575 | pid_match++; |
| 6576 | else if (pid1 == pid2) |
| 6577 | pid_match++; |
| 6578 | } |
| 6579 | |
| 6580 | /* check destination pid for a match */ |
| 6581 | if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) { |
| 6582 | pid1 = pri_entry->dst_pid & INVALID_PORT_ID; |
| 6583 | pid2 = fcport->d_id.b24 & INVALID_PORT_ID; |
| 6584 | if (pid1 == INVALID_PORT_ID) |
| 6585 | pid_match++; |
| 6586 | else if (pid1 == pid2) |
| 6587 | pid_match++; |
| 6588 | } |
| 6589 | |
| 6590 | /* check source WWN for a match */ |
| 6591 | if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) { |
| 6592 | wwn1 = wwn_to_u64(vha->port_name); |
| 6593 | wwn2 = wwn_to_u64(pri_entry->src_wwpn); |
| 6594 | if (wwn2 == (uint64_t)-1) |
| 6595 | wwn_match++; |
| 6596 | else if (wwn1 == wwn2) |
| 6597 | wwn_match++; |
| 6598 | } |
| 6599 | |
| 6600 | /* check destination WWN for a match */ |
| 6601 | if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) { |
| 6602 | wwn1 = wwn_to_u64(fcport->port_name); |
| 6603 | wwn2 = wwn_to_u64(pri_entry->dst_wwpn); |
| 6604 | if (wwn2 == (uint64_t)-1) |
| 6605 | wwn_match++; |
| 6606 | else if (wwn1 == wwn2) |
| 6607 | wwn_match++; |
| 6608 | } |
| 6609 | |
| 6610 | if (pid_match == 2 || wwn_match == 2) { |
| 6611 | /* Found a matching entry */ |
| 6612 | if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID) |
| 6613 | priority = pri_entry->tag; |
| 6614 | break; |
| 6615 | } |
| 6616 | |
| 6617 | pri_entry++; |
| 6618 | } |
| 6619 | |
| 6620 | return priority; |
| 6621 | } |
| 6622 | |
| 6623 | /* |
| 6624 | * qla24xx_update_fcport_fcp_prio |
| 6625 | * Activates fcp priority for the logged in fc port |
| 6626 | * |
| 6627 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 6628 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 6629 | * fcp = port structure pointer. |
| 6630 | * |
| 6631 | * Return: |
| 6632 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 6633 | * |
| 6634 | * Context: |
| 6635 | * Kernel context. |
| 6636 | */ |
| 6637 | int |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 6638 | qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 6639 | { |
| 6640 | int ret; |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 6641 | int priority; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 6642 | uint16_t mb[5]; |
| 6643 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 6644 | if (fcport->port_type != FCT_TARGET || |
| 6645 | fcport->loop_id == FC_NO_LOOP_ID) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 6646 | return QLA_FUNCTION_FAILED; |
| 6647 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 6648 | priority = qla24xx_get_fcp_prio(vha, fcport); |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 6649 | if (priority < 0) |
| 6650 | return QLA_FUNCTION_FAILED; |
| 6651 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 6652 | if (IS_P3P_TYPE(vha->hw)) { |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 6653 | fcport->fcp_prio = priority & 0xf; |
| 6654 | return QLA_SUCCESS; |
| 6655 | } |
| 6656 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 6657 | ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb); |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 6658 | if (ret == QLA_SUCCESS) { |
| 6659 | if (fcport->fcp_prio != priority) |
| 6660 | ql_dbg(ql_dbg_user, vha, 0x709e, |
| 6661 | "Updated FCP_CMND priority - value=%d loop_id=%d " |
| 6662 | "port_id=%02x%02x%02x.\n", priority, |
| 6663 | fcport->loop_id, fcport->d_id.b.domain, |
| 6664 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 6665 | fcport->fcp_prio = priority & 0xf; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 6666 | } else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6667 | ql_dbg(ql_dbg_user, vha, 0x704f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 6668 | "Unable to update FCP_CMND priority - ret=0x%x for " |
| 6669 | "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id, |
| 6670 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 6671 | fcport->d_id.b.al_pa); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 6672 | return ret; |
| 6673 | } |
| 6674 | |
| 6675 | /* |
| 6676 | * qla24xx_update_all_fcp_prio |
| 6677 | * Activates fcp priority for all the logged in ports |
| 6678 | * |
| 6679 | * Input: |
| 6680 | * ha = adapter block pointer. |
| 6681 | * |
| 6682 | * Return: |
| 6683 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 6684 | * |
| 6685 | * Context: |
| 6686 | * Kernel context. |
| 6687 | */ |
| 6688 | int |
| 6689 | qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha) |
| 6690 | { |
| 6691 | int ret; |
| 6692 | fc_port_t *fcport; |
| 6693 | |
| 6694 | ret = QLA_FUNCTION_FAILED; |
| 6695 | /* We need to set priority for all logged in ports */ |
| 6696 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 6697 | ret = qla24xx_update_fcport_fcp_prio(vha, fcport); |
| 6698 | |
| 6699 | return ret; |
| 6700 | } |