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 *); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 33 | static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | static int qla2x00_restart_isp(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 36 | static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *); |
| 37 | static int qla84xx_init_chip(scsi_qla_host_t *); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 38 | static int qla25xx_init_queues(struct qla_hw_data *); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 39 | static int qla24xx_post_gpdb_work(struct scsi_qla_host *, fc_port_t *, u8); |
| 40 | static void qla24xx_handle_plogi_done_event(struct scsi_qla_host *, |
| 41 | struct event_arg *); |
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; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 50 | scsi_qla_host_t *vha = sp->vha; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 51 | struct req_que *req; |
| 52 | unsigned long flags; |
| 53 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 54 | spin_lock_irqsave(&vha->hw->hardware_lock, flags); |
| 55 | req = vha->hw->req_q_map[0]; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 56 | req->outstanding_cmds[sp->handle] = NULL; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 57 | iocb = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 58 | iocb->timeout(sp); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 59 | sp->free(sp); |
| 60 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 63 | void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 64 | qla2x00_sp_free(void *ptr) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 65 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 66 | srb_t *sp = ptr; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 67 | struct srb_iocb *iocb = &sp->u.iocb_cmd; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 68 | |
Chad Dupuis | 4d97cc5 | 2010-10-15 11:27:41 -0700 | [diff] [blame] | 69 | del_timer(&iocb->timer); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 70 | qla2x00_rel_sp(sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 73 | /* Asynchronous Login/Logout Routines -------------------------------------- */ |
| 74 | |
Saurav Kashyap | a9b6f72 | 2012-08-22 14:21:01 -0400 | [diff] [blame] | 75 | unsigned long |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 76 | qla2x00_get_async_timeout(struct scsi_qla_host *vha) |
| 77 | { |
| 78 | unsigned long tmo; |
| 79 | struct qla_hw_data *ha = vha->hw; |
| 80 | |
| 81 | /* Firmware should use switch negotiated r_a_tov for timeout. */ |
| 82 | tmo = ha->r_a_tov / 10 * 2; |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 83 | if (IS_QLAFX00(ha)) { |
| 84 | tmo = FX00_DEF_RATOV * 2; |
| 85 | } else if (!IS_FWI2_CAPABLE(ha)) { |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 86 | /* |
| 87 | * Except for earlier ISPs where the timeout is seeded from the |
| 88 | * initialization control block. |
| 89 | */ |
| 90 | tmo = ha->login_timeout; |
| 91 | } |
| 92 | return tmo; |
| 93 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 94 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 95 | void |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 96 | qla2x00_async_iocb_timeout(void *data) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 97 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 98 | srb_t *sp = data; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 99 | fc_port_t *fcport = sp->fcport; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 100 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
| 101 | struct event_arg ea; |
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, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 104 | "Async-%s timeout - hdl=%x portid=%06x %8phC.\n", |
| 105 | sp->name, sp->handle, fcport->d_id.b24, fcport->port_name); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 106 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 107 | fcport->flags &= ~FCF_ASYNC_SENT; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 108 | |
| 109 | switch (sp->type) { |
| 110 | case SRB_LOGIN_CMD: |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 111 | /* Retry as needed. */ |
| 112 | lio->u.logio.data[0] = MBS_COMMAND_ERROR; |
| 113 | lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ? |
| 114 | QLA_LOGIO_LOGIN_RETRIED : 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 115 | memset(&ea, 0, sizeof(ea)); |
| 116 | ea.event = FCME_PLOGI_DONE; |
| 117 | ea.fcport = sp->fcport; |
| 118 | ea.data[0] = lio->u.logio.data[0]; |
| 119 | ea.data[1] = lio->u.logio.data[1]; |
| 120 | ea.sp = sp; |
| 121 | qla24xx_handle_plogi_done_event(fcport->vha, &ea); |
| 122 | break; |
| 123 | case SRB_LOGOUT_CMD: |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 124 | qlt_logo_completion_handler(fcport, QLA_FUNCTION_TIMEOUT); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 125 | break; |
| 126 | case SRB_CT_PTHRU_CMD: |
| 127 | case SRB_MB_IOCB: |
| 128 | case SRB_NACK_PLOGI: |
| 129 | case SRB_NACK_PRLI: |
| 130 | case SRB_NACK_LOGO: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 131 | sp->done(sp, QLA_FUNCTION_TIMEOUT); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 132 | break; |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 133 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 136 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 137 | qla2x00_async_login_sp_done(void *ptr, int res) |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 138 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 139 | srb_t *sp = ptr; |
| 140 | struct scsi_qla_host *vha = sp->vha; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 141 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 142 | struct event_arg ea; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 143 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 144 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 145 | "%s %8phC res %d \n", __func__, sp->fcport->port_name, res); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 146 | |
| 147 | sp->fcport->flags &= ~FCF_ASYNC_SENT; |
| 148 | if (!test_bit(UNLOADING, &vha->dpc_flags)) { |
| 149 | memset(&ea, 0, sizeof(ea)); |
| 150 | ea.event = FCME_PLOGI_DONE; |
| 151 | ea.fcport = sp->fcport; |
| 152 | ea.data[0] = lio->u.logio.data[0]; |
| 153 | ea.data[1] = lio->u.logio.data[1]; |
| 154 | ea.iop[0] = lio->u.logio.iop[0]; |
| 155 | ea.iop[1] = lio->u.logio.iop[1]; |
| 156 | ea.sp = sp; |
| 157 | qla2x00_fcport_event_handler(vha, &ea); |
| 158 | } |
| 159 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 160 | sp->free(sp); |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 163 | int |
| 164 | qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 165 | uint16_t *data) |
| 166 | { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 167 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 168 | struct srb_iocb *lio; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 169 | int rval = QLA_FUNCTION_FAILED; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 170 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 171 | if (!vha->flags.online) |
| 172 | goto done; |
| 173 | |
| 174 | if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) || |
| 175 | (fcport->fw_login_state == DSC_LS_PLOGI_COMP) || |
| 176 | (fcport->fw_login_state == DSC_LS_PRLI_PEND)) |
| 177 | goto done; |
| 178 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 179 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 180 | if (!sp) |
| 181 | goto done; |
| 182 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 183 | fcport->flags |= FCF_ASYNC_SENT; |
| 184 | fcport->logout_completed = 0; |
| 185 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 186 | sp->type = SRB_LOGIN_CMD; |
| 187 | sp->name = "login"; |
| 188 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 189 | |
| 190 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 191 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 192 | sp->done = qla2x00_async_login_sp_done; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 193 | lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 194 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 195 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 196 | rval = qla2x00_start_sp(sp); |
Chad Dupuis | 080c951 | 2016-01-27 12:03:37 -0500 | [diff] [blame] | 197 | if (rval != QLA_SUCCESS) { |
| 198 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 199 | fcport->flags |= FCF_LOGIN_NEEDED; |
| 200 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 201 | goto done_free_sp; |
Chad Dupuis | 080c951 | 2016-01-27 12:03:37 -0500 | [diff] [blame] | 202 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 203 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 204 | ql_dbg(ql_dbg_disc, vha, 0x2072, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 205 | "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x " |
| 206 | "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 207 | fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 208 | fcport->login_retry); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 209 | return rval; |
| 210 | |
| 211 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 212 | sp->free(sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 213 | done: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 214 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 215 | return rval; |
| 216 | } |
| 217 | |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 218 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 219 | qla2x00_async_logout_sp_done(void *ptr, int res) |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 220 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 221 | srb_t *sp = ptr; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 222 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 223 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 224 | sp->fcport->flags &= ~FCF_ASYNC_SENT; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 225 | if (!test_bit(UNLOADING, &sp->vha->dpc_flags)) |
| 226 | qla2x00_post_async_logout_done_work(sp->vha, sp->fcport, |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 227 | lio->u.logio.data); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 228 | sp->free(sp); |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 231 | int |
| 232 | qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 233 | { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 234 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 235 | struct srb_iocb *lio; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 236 | int rval; |
| 237 | |
| 238 | rval = QLA_FUNCTION_FAILED; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 239 | fcport->flags |= FCF_ASYNC_SENT; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 240 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 241 | if (!sp) |
| 242 | goto done; |
| 243 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 244 | sp->type = SRB_LOGOUT_CMD; |
| 245 | sp->name = "logout"; |
| 246 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 247 | |
| 248 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 249 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 250 | sp->done = qla2x00_async_logout_sp_done; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 251 | rval = qla2x00_start_sp(sp); |
| 252 | if (rval != QLA_SUCCESS) |
| 253 | goto done_free_sp; |
| 254 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 255 | ql_dbg(ql_dbg_disc, vha, 0x2070, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 256 | "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n", |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 257 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 258 | fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 259 | fcport->port_name); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 260 | return rval; |
| 261 | |
| 262 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 263 | sp->free(sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 264 | done: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 265 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 266 | return rval; |
| 267 | } |
| 268 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 269 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 270 | qla2x00_async_adisc_sp_done(void *ptr, int res) |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 271 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 272 | srb_t *sp = ptr; |
| 273 | struct scsi_qla_host *vha = sp->vha; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 274 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 275 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 276 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 277 | qla2x00_post_async_adisc_done_work(sp->vha, sp->fcport, |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 278 | lio->u.logio.data); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 279 | sp->free(sp); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | int |
| 283 | qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 284 | uint16_t *data) |
| 285 | { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 286 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 287 | struct srb_iocb *lio; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 288 | int rval; |
| 289 | |
| 290 | rval = QLA_FUNCTION_FAILED; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 291 | fcport->flags |= FCF_ASYNC_SENT; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 292 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 293 | if (!sp) |
| 294 | goto done; |
| 295 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 296 | sp->type = SRB_ADISC_CMD; |
| 297 | sp->name = "adisc"; |
| 298 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 299 | |
| 300 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 301 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 302 | sp->done = qla2x00_async_adisc_sp_done; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 303 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 304 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 305 | rval = qla2x00_start_sp(sp); |
| 306 | if (rval != QLA_SUCCESS) |
| 307 | goto done_free_sp; |
| 308 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 309 | ql_dbg(ql_dbg_disc, vha, 0x206f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 310 | "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n", |
| 311 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
| 312 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 313 | return rval; |
| 314 | |
| 315 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 316 | sp->free(sp); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 317 | done: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 318 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 319 | return rval; |
| 320 | } |
| 321 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 322 | static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha, |
| 323 | struct event_arg *ea) |
| 324 | { |
| 325 | fc_port_t *fcport, *conflict_fcport; |
| 326 | struct get_name_list_extended *e; |
| 327 | u16 i, n, found = 0, loop_id; |
| 328 | port_id_t id; |
| 329 | u64 wwn; |
| 330 | u8 opt = 0; |
| 331 | |
| 332 | fcport = ea->fcport; |
| 333 | |
| 334 | if (ea->rc) { /* rval */ |
| 335 | if (fcport->login_retry == 0) { |
| 336 | fcport->login_retry = vha->hw->login_retry_count; |
| 337 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 338 | "GNL failed Port login retry %8phN, retry cnt=%d.\n", |
| 339 | fcport->port_name, fcport->login_retry); |
| 340 | } |
| 341 | return; |
| 342 | } |
| 343 | |
| 344 | if (fcport->last_rscn_gen != fcport->rscn_gen) { |
| 345 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 346 | "%s %8phC rscn gen changed rscn %d|%d \n", |
| 347 | __func__, fcport->port_name, |
| 348 | fcport->last_rscn_gen, fcport->rscn_gen); |
| 349 | qla24xx_post_gidpn_work(vha, fcport); |
| 350 | return; |
| 351 | } else if (fcport->last_login_gen != fcport->login_gen) { |
| 352 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 353 | "%s %8phC login gen changed login %d|%d \n", |
| 354 | __func__, fcport->port_name, |
| 355 | fcport->last_login_gen, fcport->login_gen); |
| 356 | return; |
| 357 | } |
| 358 | |
| 359 | n = ea->data[0] / sizeof(struct get_name_list_extended); |
| 360 | |
| 361 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 362 | "%s %d %8phC n %d %02x%02x%02x lid %d \n", |
| 363 | __func__, __LINE__, fcport->port_name, n, |
| 364 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 365 | fcport->d_id.b.al_pa, fcport->loop_id); |
| 366 | |
| 367 | for (i = 0; i < n; i++) { |
| 368 | e = &vha->gnl.l[i]; |
| 369 | wwn = wwn_to_u64(e->port_name); |
| 370 | |
| 371 | if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE)) |
| 372 | continue; |
| 373 | |
| 374 | found = 1; |
| 375 | id.b.domain = e->port_id[2]; |
| 376 | id.b.area = e->port_id[1]; |
| 377 | id.b.al_pa = e->port_id[0]; |
| 378 | id.b.rsvd_1 = 0; |
| 379 | |
| 380 | loop_id = le16_to_cpu(e->nport_handle); |
| 381 | loop_id = (loop_id & 0x7fff); |
| 382 | |
| 383 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 384 | "%s found %8phC CLS [%d|%d] ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n", |
| 385 | __func__, fcport->port_name, |
| 386 | e->current_login_state, fcport->fw_login_state, |
| 387 | id.b.domain, id.b.area, id.b.al_pa, |
| 388 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 389 | fcport->d_id.b.al_pa, loop_id, fcport->loop_id); |
| 390 | |
| 391 | if ((id.b24 != fcport->d_id.b24) || |
| 392 | ((fcport->loop_id != FC_NO_LOOP_ID) && |
| 393 | (fcport->loop_id != loop_id))) { |
| 394 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 395 | "%s %d %8phC post del sess\n", |
| 396 | __func__, __LINE__, fcport->port_name); |
| 397 | qlt_schedule_sess_for_deletion(fcport, 1); |
| 398 | return; |
| 399 | } |
| 400 | |
| 401 | fcport->loop_id = loop_id; |
| 402 | |
| 403 | wwn = wwn_to_u64(fcport->port_name); |
| 404 | qlt_find_sess_invalidate_other(vha, wwn, |
| 405 | id, loop_id, &conflict_fcport); |
| 406 | |
| 407 | if (conflict_fcport) { |
| 408 | /* |
| 409 | * Another share fcport share the same loop_id & |
| 410 | * nport id. Conflict fcport needs to finish |
| 411 | * cleanup before this fcport can proceed to login. |
| 412 | */ |
| 413 | conflict_fcport->conflict = fcport; |
| 414 | fcport->login_pause = 1; |
| 415 | } |
| 416 | |
| 417 | switch (e->current_login_state) { |
| 418 | case DSC_LS_PRLI_COMP: |
| 419 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 420 | "%s %d %8phC post gpdb\n", |
| 421 | __func__, __LINE__, fcport->port_name); |
| 422 | opt = PDO_FORCE_ADISC; |
| 423 | qla24xx_post_gpdb_work(vha, fcport, opt); |
| 424 | break; |
| 425 | |
| 426 | case DSC_LS_PORT_UNAVAIL: |
| 427 | default: |
| 428 | if (fcport->loop_id == FC_NO_LOOP_ID) { |
| 429 | qla2x00_find_new_loop_id(vha, fcport); |
| 430 | fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 431 | } |
| 432 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 433 | "%s %d %8phC \n", |
| 434 | __func__, __LINE__, fcport->port_name); |
| 435 | qla24xx_fcport_handle_login(vha, fcport); |
| 436 | break; |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | if (!found) { |
| 441 | /* fw has no record of this port */ |
| 442 | if (fcport->loop_id == FC_NO_LOOP_ID) { |
| 443 | qla2x00_find_new_loop_id(vha, fcport); |
| 444 | fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 445 | } else { |
| 446 | for (i = 0; i < n; i++) { |
| 447 | e = &vha->gnl.l[i]; |
| 448 | id.b.domain = e->port_id[0]; |
| 449 | id.b.area = e->port_id[1]; |
| 450 | id.b.al_pa = e->port_id[2]; |
| 451 | id.b.rsvd_1 = 0; |
| 452 | loop_id = le16_to_cpu(e->nport_handle); |
| 453 | |
| 454 | if (fcport->d_id.b24 == id.b24) { |
| 455 | conflict_fcport = |
| 456 | qla2x00_find_fcport_by_wwpn(vha, |
| 457 | e->port_name, 0); |
| 458 | |
| 459 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 460 | "%s %d %8phC post del sess\n", |
| 461 | __func__, __LINE__, |
| 462 | conflict_fcport->port_name); |
| 463 | qlt_schedule_sess_for_deletion |
| 464 | (conflict_fcport, 1); |
| 465 | } |
| 466 | |
| 467 | if (fcport->loop_id == loop_id) { |
| 468 | /* FW already picked this loop id for another fcport */ |
| 469 | qla2x00_find_new_loop_id(vha, fcport); |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | qla24xx_fcport_handle_login(vha, fcport); |
| 474 | } |
| 475 | } /* gnl_event */ |
| 476 | |
| 477 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 478 | qla24xx_async_gnl_sp_done(void *s, int res) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 479 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 480 | struct srb *sp = s; |
| 481 | struct scsi_qla_host *vha = sp->vha; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 482 | unsigned long flags; |
| 483 | struct fc_port *fcport = NULL, *tf; |
| 484 | u16 i, n = 0, loop_id; |
| 485 | struct event_arg ea; |
| 486 | struct get_name_list_extended *e; |
| 487 | u64 wwn; |
| 488 | struct list_head h; |
| 489 | |
| 490 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 491 | "Async done-%s res %x mb[1]=%x mb[2]=%x \n", |
| 492 | sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1], |
| 493 | sp->u.iocb_cmd.u.mbx.in_mb[2]); |
| 494 | |
| 495 | memset(&ea, 0, sizeof(ea)); |
| 496 | ea.sp = sp; |
| 497 | ea.rc = res; |
| 498 | ea.event = FCME_GNL_DONE; |
| 499 | |
| 500 | if (sp->u.iocb_cmd.u.mbx.in_mb[1] >= |
| 501 | sizeof(struct get_name_list_extended)) { |
| 502 | n = sp->u.iocb_cmd.u.mbx.in_mb[1] / |
| 503 | sizeof(struct get_name_list_extended); |
| 504 | ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */ |
| 505 | } |
| 506 | |
| 507 | for (i = 0; i < n; i++) { |
| 508 | e = &vha->gnl.l[i]; |
| 509 | loop_id = le16_to_cpu(e->nport_handle); |
| 510 | /* mask out reserve bit */ |
| 511 | loop_id = (loop_id & 0x7fff); |
| 512 | set_bit(loop_id, vha->hw->loop_id_map); |
| 513 | wwn = wwn_to_u64(e->port_name); |
| 514 | |
| 515 | ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0xffff, |
| 516 | "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n", |
| 517 | __func__, (void *)&wwn, e->port_id[2], e->port_id[1], |
| 518 | e->port_id[0], e->current_login_state, e->last_login_state, |
| 519 | (loop_id & 0x7fff)); |
| 520 | } |
| 521 | |
| 522 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 523 | vha->gnl.sent = 0; |
| 524 | |
| 525 | INIT_LIST_HEAD(&h); |
| 526 | fcport = tf = NULL; |
| 527 | if (!list_empty(&vha->gnl.fcports)) |
| 528 | list_splice_init(&vha->gnl.fcports, &h); |
| 529 | |
| 530 | list_for_each_entry_safe(fcport, tf, &h, gnl_entry) { |
| 531 | list_del_init(&fcport->gnl_entry); |
| 532 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 533 | ea.fcport = fcport; |
| 534 | |
| 535 | qla2x00_fcport_event_handler(vha, &ea); |
| 536 | } |
| 537 | |
| 538 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 539 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 540 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 544 | { |
| 545 | srb_t *sp; |
| 546 | struct srb_iocb *mbx; |
| 547 | int rval = QLA_FUNCTION_FAILED; |
| 548 | unsigned long flags; |
| 549 | u16 *mb; |
| 550 | |
| 551 | if (!vha->flags.online) |
| 552 | goto done; |
| 553 | |
| 554 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 555 | "Async-gnlist WWPN %8phC \n", fcport->port_name); |
| 556 | |
| 557 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 558 | fcport->flags |= FCF_ASYNC_SENT; |
| 559 | fcport->disc_state = DSC_GNL; |
| 560 | fcport->last_rscn_gen = fcport->rscn_gen; |
| 561 | fcport->last_login_gen = fcport->login_gen; |
| 562 | |
| 563 | list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports); |
| 564 | if (vha->gnl.sent) { |
| 565 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 566 | rval = QLA_SUCCESS; |
| 567 | goto done; |
| 568 | } |
| 569 | vha->gnl.sent = 1; |
| 570 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 571 | |
| 572 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 573 | if (!sp) |
| 574 | goto done; |
| 575 | sp->type = SRB_MB_IOCB; |
| 576 | sp->name = "gnlist"; |
| 577 | sp->gen1 = fcport->rscn_gen; |
| 578 | sp->gen2 = fcport->login_gen; |
| 579 | |
| 580 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2); |
| 581 | |
| 582 | mb = sp->u.iocb_cmd.u.mbx.out_mb; |
| 583 | mb[0] = MBC_PORT_NODE_NAME_LIST; |
| 584 | mb[1] = BIT_2 | BIT_3; |
| 585 | mb[2] = MSW(vha->gnl.ldma); |
| 586 | mb[3] = LSW(vha->gnl.ldma); |
| 587 | mb[6] = MSW(MSD(vha->gnl.ldma)); |
| 588 | mb[7] = LSW(MSD(vha->gnl.ldma)); |
| 589 | mb[8] = vha->gnl.size; |
| 590 | mb[9] = vha->vp_idx; |
| 591 | |
| 592 | mbx = &sp->u.iocb_cmd; |
| 593 | mbx->timeout = qla2x00_async_iocb_timeout; |
| 594 | |
| 595 | sp->done = qla24xx_async_gnl_sp_done; |
| 596 | |
| 597 | rval = qla2x00_start_sp(sp); |
| 598 | if (rval != QLA_SUCCESS) |
| 599 | goto done_free_sp; |
| 600 | |
| 601 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 602 | "Async-%s - OUT WWPN %8phC hndl %x\n", |
| 603 | sp->name, fcport->port_name, sp->handle); |
| 604 | |
| 605 | return rval; |
| 606 | |
| 607 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 608 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 609 | done: |
| 610 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 611 | return rval; |
| 612 | } |
| 613 | |
| 614 | int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 615 | { |
| 616 | struct qla_work_evt *e; |
| 617 | |
| 618 | e = qla2x00_alloc_work(vha, QLA_EVT_GNL); |
| 619 | if (!e) |
| 620 | return QLA_FUNCTION_FAILED; |
| 621 | |
| 622 | e->u.fcport.fcport = fcport; |
| 623 | return qla2x00_post_work(vha, e); |
| 624 | } |
| 625 | |
| 626 | static |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 627 | void qla24xx_async_gpdb_sp_done(void *s, int res) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 628 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 629 | struct srb *sp = s; |
| 630 | struct scsi_qla_host *vha = sp->vha; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 631 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 632 | struct port_database_24xx *pd; |
| 633 | fc_port_t *fcport = sp->fcport; |
| 634 | u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb; |
| 635 | int rval = QLA_SUCCESS; |
| 636 | struct event_arg ea; |
| 637 | |
| 638 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 639 | "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n", |
| 640 | sp->name, res, fcport->port_name, mb[1], mb[2]); |
| 641 | |
| 642 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 643 | |
| 644 | if (res) { |
| 645 | rval = res; |
| 646 | goto gpd_error_out; |
| 647 | } |
| 648 | |
| 649 | pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in; |
| 650 | |
Quinn Tran | 15f30a5 | 2017-03-15 09:48:52 -0700 | [diff] [blame] | 651 | rval = __qla24xx_parse_gpdb(vha, fcport, pd); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 652 | |
| 653 | gpd_error_out: |
| 654 | memset(&ea, 0, sizeof(ea)); |
| 655 | ea.event = FCME_GPDB_DONE; |
| 656 | ea.rc = rval; |
| 657 | ea.fcport = fcport; |
| 658 | ea.sp = sp; |
| 659 | |
| 660 | qla2x00_fcport_event_handler(vha, &ea); |
| 661 | |
| 662 | dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in, |
| 663 | sp->u.iocb_cmd.u.mbx.in_dma); |
| 664 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 665 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | static int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 669 | u8 opt) |
| 670 | { |
| 671 | struct qla_work_evt *e; |
| 672 | |
| 673 | e = qla2x00_alloc_work(vha, QLA_EVT_GPDB); |
| 674 | if (!e) |
| 675 | return QLA_FUNCTION_FAILED; |
| 676 | |
| 677 | e->u.fcport.fcport = fcport; |
| 678 | e->u.fcport.opt = opt; |
| 679 | return qla2x00_post_work(vha, e); |
| 680 | } |
| 681 | |
| 682 | int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt) |
| 683 | { |
| 684 | srb_t *sp; |
| 685 | struct srb_iocb *mbx; |
| 686 | int rval = QLA_FUNCTION_FAILED; |
| 687 | u16 *mb; |
| 688 | dma_addr_t pd_dma; |
| 689 | struct port_database_24xx *pd; |
| 690 | struct qla_hw_data *ha = vha->hw; |
| 691 | |
| 692 | if (!vha->flags.online) |
| 693 | goto done; |
| 694 | |
| 695 | fcport->flags |= FCF_ASYNC_SENT; |
| 696 | fcport->disc_state = DSC_GPDB; |
| 697 | |
| 698 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 699 | if (!sp) |
| 700 | goto done; |
| 701 | |
| 702 | pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma); |
| 703 | if (pd == NULL) { |
| 704 | ql_log(ql_log_warn, vha, 0xffff, |
| 705 | "Failed to allocate port database structure.\n"); |
| 706 | goto done_free_sp; |
| 707 | } |
| 708 | memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE)); |
| 709 | |
| 710 | sp->type = SRB_MB_IOCB; |
| 711 | sp->name = "gpdb"; |
| 712 | sp->gen1 = fcport->rscn_gen; |
| 713 | sp->gen2 = fcport->login_gen; |
| 714 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 715 | |
| 716 | mb = sp->u.iocb_cmd.u.mbx.out_mb; |
| 717 | mb[0] = MBC_GET_PORT_DATABASE; |
| 718 | mb[1] = fcport->loop_id; |
| 719 | mb[2] = MSW(pd_dma); |
| 720 | mb[3] = LSW(pd_dma); |
| 721 | mb[6] = MSW(MSD(pd_dma)); |
| 722 | mb[7] = LSW(MSD(pd_dma)); |
| 723 | mb[9] = vha->vp_idx; |
| 724 | mb[10] = opt; |
| 725 | |
| 726 | mbx = &sp->u.iocb_cmd; |
| 727 | mbx->timeout = qla2x00_async_iocb_timeout; |
| 728 | mbx->u.mbx.in = (void *)pd; |
| 729 | mbx->u.mbx.in_dma = pd_dma; |
| 730 | |
| 731 | sp->done = qla24xx_async_gpdb_sp_done; |
| 732 | |
| 733 | rval = qla2x00_start_sp(sp); |
| 734 | if (rval != QLA_SUCCESS) |
| 735 | goto done_free_sp; |
| 736 | |
| 737 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 738 | "Async-%s %8phC hndl %x opt %x\n", |
| 739 | sp->name, fcport->port_name, sp->handle, opt); |
| 740 | |
| 741 | return rval; |
| 742 | |
| 743 | done_free_sp: |
| 744 | if (pd) |
| 745 | dma_pool_free(ha->s_dma_pool, pd, pd_dma); |
| 746 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 747 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 748 | done: |
| 749 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 750 | qla24xx_post_gpdb_work(vha, fcport, opt); |
| 751 | return rval; |
| 752 | } |
| 753 | |
| 754 | static |
| 755 | void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea) |
| 756 | { |
| 757 | int rval = ea->rc; |
| 758 | fc_port_t *fcport = ea->fcport; |
| 759 | unsigned long flags; |
| 760 | |
| 761 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 762 | |
| 763 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 764 | "%s %8phC DS %d LS %d rval %d\n", __func__, fcport->port_name, |
| 765 | fcport->disc_state, fcport->fw_login_state, rval); |
| 766 | |
| 767 | if (ea->sp->gen2 != fcport->login_gen) { |
| 768 | /* target side must have changed it. */ |
| 769 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 770 | "%s %8phC generation changed rscn %d|%d login %d|%d \n", |
| 771 | __func__, fcport->port_name, fcport->last_rscn_gen, |
| 772 | fcport->rscn_gen, fcport->last_login_gen, |
| 773 | fcport->login_gen); |
| 774 | return; |
| 775 | } else if (ea->sp->gen1 != fcport->rscn_gen) { |
| 776 | ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC post gidpn\n", |
| 777 | __func__, __LINE__, fcport->port_name); |
| 778 | qla24xx_post_gidpn_work(vha, fcport); |
| 779 | return; |
| 780 | } |
| 781 | |
| 782 | if (rval != QLA_SUCCESS) { |
| 783 | ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC post del sess\n", |
| 784 | __func__, __LINE__, fcport->port_name); |
| 785 | qlt_schedule_sess_for_deletion_lock(fcport); |
| 786 | return; |
| 787 | } |
| 788 | |
| 789 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 790 | ea->fcport->login_gen++; |
| 791 | ea->fcport->deleted = 0; |
| 792 | ea->fcport->logout_on_delete = 1; |
| 793 | |
| 794 | if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) { |
| 795 | vha->fcport_count++; |
| 796 | ea->fcport->login_succ = 1; |
| 797 | |
| 798 | if (!IS_IIDMA_CAPABLE(vha->hw) || |
| 799 | !vha->hw->flags.gpsc_supported) { |
| 800 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 801 | "%s %d %8phC post upd_fcport fcp_cnt %d\n", |
| 802 | __func__, __LINE__, fcport->port_name, |
| 803 | vha->fcport_count); |
| 804 | |
| 805 | qla24xx_post_upd_fcport_work(vha, fcport); |
| 806 | } else { |
| 807 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 808 | "%s %d %8phC post gpsc fcp_cnt %d\n", |
| 809 | __func__, __LINE__, fcport->port_name, |
| 810 | vha->fcport_count); |
| 811 | |
| 812 | qla24xx_post_gpsc_work(vha, fcport); |
| 813 | } |
| 814 | } |
| 815 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 816 | } /* gpdb event */ |
| 817 | |
| 818 | int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 819 | { |
| 820 | if (fcport->login_retry == 0) |
| 821 | return 0; |
| 822 | |
| 823 | if (fcport->scan_state != QLA_FCPORT_FOUND) |
| 824 | return 0; |
| 825 | |
| 826 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 827 | "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d|%d retry %d lid %d\n", |
| 828 | __func__, fcport->port_name, fcport->disc_state, |
| 829 | fcport->fw_login_state, fcport->login_pause, fcport->flags, |
| 830 | fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen, |
| 831 | fcport->last_login_gen, fcport->login_gen, fcport->login_retry, |
| 832 | fcport->loop_id); |
| 833 | |
| 834 | fcport->login_retry--; |
| 835 | |
| 836 | if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 837 | (fcport->fw_login_state == DSC_LS_PRLI_PEND)) |
| 838 | return 0; |
| 839 | |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame] | 840 | if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) { |
| 841 | if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) |
| 842 | return 0; |
| 843 | } |
| 844 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 845 | /* for pure Target Mode. Login will not be initiated */ |
| 846 | if (vha->host->active_mode == MODE_TARGET) |
| 847 | return 0; |
| 848 | |
| 849 | if (fcport->flags & FCF_ASYNC_SENT) { |
| 850 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 851 | return 0; |
| 852 | } |
| 853 | |
| 854 | switch (fcport->disc_state) { |
| 855 | case DSC_DELETED: |
| 856 | if (fcport->loop_id == FC_NO_LOOP_ID) { |
| 857 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 858 | "%s %d %8phC post gnl\n", |
| 859 | __func__, __LINE__, fcport->port_name); |
| 860 | qla24xx_async_gnl(vha, fcport); |
| 861 | } else { |
| 862 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 863 | "%s %d %8phC post login\n", |
| 864 | __func__, __LINE__, fcport->port_name); |
| 865 | fcport->disc_state = DSC_LOGIN_PEND; |
| 866 | qla2x00_post_async_login_work(vha, fcport, NULL); |
| 867 | } |
| 868 | break; |
| 869 | |
| 870 | case DSC_GNL: |
| 871 | if (fcport->login_pause) { |
| 872 | fcport->last_rscn_gen = fcport->rscn_gen; |
| 873 | fcport->last_login_gen = fcport->login_gen; |
| 874 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 875 | break; |
| 876 | } |
| 877 | |
| 878 | if (fcport->flags & FCF_FCP2_DEVICE) { |
| 879 | u8 opt = PDO_FORCE_ADISC; |
| 880 | |
| 881 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 882 | "%s %d %8phC post gpdb\n", |
| 883 | __func__, __LINE__, fcport->port_name); |
| 884 | |
| 885 | fcport->disc_state = DSC_GPDB; |
| 886 | qla24xx_post_gpdb_work(vha, fcport, opt); |
| 887 | } else { |
| 888 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 889 | "%s %d %8phC post login \n", |
| 890 | __func__, __LINE__, fcport->port_name); |
| 891 | fcport->disc_state = DSC_LOGIN_PEND; |
| 892 | qla2x00_post_async_login_work(vha, fcport, NULL); |
| 893 | } |
| 894 | |
| 895 | break; |
| 896 | |
| 897 | case DSC_LOGIN_FAILED: |
| 898 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 899 | "%s %d %8phC post gidpn \n", |
| 900 | __func__, __LINE__, fcport->port_name); |
| 901 | |
| 902 | qla24xx_post_gidpn_work(vha, fcport); |
| 903 | break; |
| 904 | |
| 905 | case DSC_LOGIN_COMPLETE: |
| 906 | /* recheck login state */ |
| 907 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 908 | "%s %d %8phC post gpdb \n", |
| 909 | __func__, __LINE__, fcport->port_name); |
| 910 | |
| 911 | qla24xx_post_gpdb_work(vha, fcport, PDO_FORCE_ADISC); |
| 912 | break; |
| 913 | |
| 914 | default: |
| 915 | break; |
| 916 | } |
| 917 | |
| 918 | return 0; |
| 919 | } |
| 920 | |
| 921 | static |
| 922 | void qla24xx_handle_rscn_event(fc_port_t *fcport, struct event_arg *ea) |
| 923 | { |
| 924 | fcport->rscn_gen++; |
| 925 | |
| 926 | ql_dbg(ql_dbg_disc, fcport->vha, 0xffff, |
| 927 | "%s %8phC DS %d LS %d\n", |
| 928 | __func__, fcport->port_name, fcport->disc_state, |
| 929 | fcport->fw_login_state); |
| 930 | |
| 931 | if (fcport->flags & FCF_ASYNC_SENT) |
| 932 | return; |
| 933 | |
| 934 | switch (fcport->disc_state) { |
| 935 | case DSC_DELETED: |
| 936 | case DSC_LOGIN_COMPLETE: |
| 937 | qla24xx_post_gidpn_work(fcport->vha, fcport); |
| 938 | break; |
| 939 | |
| 940 | default: |
| 941 | break; |
| 942 | } |
| 943 | } |
| 944 | |
| 945 | int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id, |
| 946 | u8 *port_name, void *pla) |
| 947 | { |
| 948 | struct qla_work_evt *e; |
| 949 | e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS); |
| 950 | if (!e) |
| 951 | return QLA_FUNCTION_FAILED; |
| 952 | |
| 953 | e->u.new_sess.id = *id; |
| 954 | e->u.new_sess.pla = pla; |
| 955 | memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE); |
| 956 | |
| 957 | return qla2x00_post_work(vha, e); |
| 958 | } |
| 959 | |
| 960 | static |
| 961 | int qla24xx_handle_delete_done_event(scsi_qla_host_t *vha, |
| 962 | struct event_arg *ea) |
| 963 | { |
| 964 | fc_port_t *fcport = ea->fcport; |
| 965 | |
| 966 | if (test_bit(UNLOADING, &vha->dpc_flags)) |
| 967 | return 0; |
| 968 | |
| 969 | switch (vha->host->active_mode) { |
| 970 | case MODE_INITIATOR: |
| 971 | case MODE_DUAL: |
| 972 | if (fcport->scan_state == QLA_FCPORT_FOUND) |
| 973 | qla24xx_fcport_handle_login(vha, fcport); |
| 974 | break; |
| 975 | |
| 976 | case MODE_TARGET: |
| 977 | default: |
| 978 | /* no-op */ |
| 979 | break; |
| 980 | } |
| 981 | |
| 982 | return 0; |
| 983 | } |
| 984 | |
| 985 | static |
| 986 | void qla24xx_handle_relogin_event(scsi_qla_host_t *vha, |
| 987 | struct event_arg *ea) |
| 988 | { |
| 989 | fc_port_t *fcport = ea->fcport; |
| 990 | |
| 991 | if (fcport->scan_state != QLA_FCPORT_FOUND) { |
| 992 | fcport->login_retry++; |
| 993 | return; |
| 994 | } |
| 995 | |
| 996 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 997 | "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n", |
| 998 | __func__, fcport->port_name, fcport->disc_state, |
| 999 | fcport->fw_login_state, fcport->login_pause, |
| 1000 | fcport->deleted, fcport->conflict, |
| 1001 | fcport->last_rscn_gen, fcport->rscn_gen, |
| 1002 | fcport->last_login_gen, fcport->login_gen, |
| 1003 | fcport->flags); |
| 1004 | |
| 1005 | if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1006 | (fcport->fw_login_state == DSC_LS_PRLI_PEND)) |
| 1007 | return; |
| 1008 | |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame] | 1009 | if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) { |
| 1010 | if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) |
| 1011 | return; |
| 1012 | } |
| 1013 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1014 | if (fcport->flags & FCF_ASYNC_SENT) { |
| 1015 | fcport->login_retry++; |
| 1016 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1017 | return; |
| 1018 | } |
| 1019 | |
| 1020 | if (fcport->disc_state == DSC_DELETE_PEND) { |
| 1021 | fcport->login_retry++; |
| 1022 | return; |
| 1023 | } |
| 1024 | |
| 1025 | if (fcport->last_rscn_gen != fcport->rscn_gen) { |
| 1026 | ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC post gidpn\n", |
| 1027 | __func__, __LINE__, fcport->port_name); |
| 1028 | |
| 1029 | qla24xx_async_gidpn(vha, fcport); |
| 1030 | return; |
| 1031 | } |
| 1032 | |
| 1033 | qla24xx_fcport_handle_login(vha, fcport); |
| 1034 | } |
| 1035 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1036 | void qla2x00_fcport_event_handler(scsi_qla_host_t *vha, struct event_arg *ea) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1037 | { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1038 | fc_port_t *fcport, *f, *tf; |
| 1039 | uint32_t id = 0, mask, rid; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1040 | int rc; |
| 1041 | |
| 1042 | switch (ea->event) { |
| 1043 | case FCME_RELOGIN: |
| 1044 | if (test_bit(UNLOADING, &vha->dpc_flags)) |
| 1045 | return; |
| 1046 | |
| 1047 | qla24xx_handle_relogin_event(vha, ea); |
| 1048 | break; |
| 1049 | case FCME_RSCN: |
| 1050 | if (test_bit(UNLOADING, &vha->dpc_flags)) |
| 1051 | return; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1052 | switch (ea->id.b.rsvd_1) { |
| 1053 | case RSCN_PORT_ADDR: |
| 1054 | fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1); |
| 1055 | if (!fcport) { |
| 1056 | /* cable moved */ |
| 1057 | rc = qla24xx_post_gpnid_work(vha, &ea->id); |
| 1058 | if (rc) { |
| 1059 | ql_log(ql_log_warn, vha, 0xffff, |
| 1060 | "RSCN GPNID work failed %02x%02x%02x\n", |
| 1061 | ea->id.b.domain, ea->id.b.area, |
| 1062 | ea->id.b.al_pa); |
| 1063 | } |
| 1064 | } else { |
| 1065 | ea->fcport = fcport; |
| 1066 | qla24xx_handle_rscn_event(fcport, ea); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1067 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1068 | break; |
| 1069 | case RSCN_AREA_ADDR: |
| 1070 | case RSCN_DOM_ADDR: |
| 1071 | if (ea->id.b.rsvd_1 == RSCN_AREA_ADDR) { |
| 1072 | mask = 0xffff00; |
| 1073 | ql_log(ql_dbg_async, vha, 0xffff, |
| 1074 | "RSCN: Area 0x%06x was affected\n", |
| 1075 | ea->id.b24); |
| 1076 | } else { |
| 1077 | mask = 0xff0000; |
| 1078 | ql_log(ql_dbg_async, vha, 0xffff, |
| 1079 | "RSCN: Domain 0x%06x was affected\n", |
| 1080 | ea->id.b24); |
| 1081 | } |
| 1082 | |
| 1083 | rid = ea->id.b24 & mask; |
| 1084 | list_for_each_entry_safe(f, tf, &vha->vp_fcports, |
| 1085 | list) { |
| 1086 | id = f->d_id.b24 & mask; |
| 1087 | if (rid == id) { |
| 1088 | ea->fcport = f; |
| 1089 | qla24xx_handle_rscn_event(f, ea); |
| 1090 | } |
| 1091 | } |
| 1092 | break; |
| 1093 | case RSCN_FAB_ADDR: |
| 1094 | default: |
| 1095 | ql_log(ql_log_warn, vha, 0xffff, |
| 1096 | "RSCN: Fabric was affected. Addr format %d\n", |
| 1097 | ea->id.b.rsvd_1); |
| 1098 | qla2x00_mark_all_devices_lost(vha, 1); |
| 1099 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 1100 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1101 | } |
| 1102 | break; |
| 1103 | case FCME_GIDPN_DONE: |
| 1104 | qla24xx_handle_gidpn_event(vha, ea); |
| 1105 | break; |
| 1106 | case FCME_GNL_DONE: |
| 1107 | qla24xx_handle_gnl_done_event(vha, ea); |
| 1108 | break; |
| 1109 | case FCME_GPSC_DONE: |
| 1110 | qla24xx_post_upd_fcport_work(vha, ea->fcport); |
| 1111 | break; |
| 1112 | case FCME_PLOGI_DONE: /* Initiator side sent LLIOCB */ |
| 1113 | qla24xx_handle_plogi_done_event(vha, ea); |
| 1114 | break; |
| 1115 | case FCME_GPDB_DONE: |
| 1116 | qla24xx_handle_gpdb_event(vha, ea); |
| 1117 | break; |
| 1118 | case FCME_GPNID_DONE: |
| 1119 | qla24xx_handle_gpnid_event(vha, ea); |
| 1120 | break; |
| 1121 | case FCME_DELETE_DONE: |
| 1122 | qla24xx_handle_delete_done_event(vha, ea); |
| 1123 | break; |
| 1124 | default: |
| 1125 | BUG_ON(1); |
| 1126 | break; |
| 1127 | } |
| 1128 | } |
| 1129 | |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1130 | static void |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1131 | qla2x00_tmf_iocb_timeout(void *data) |
| 1132 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1133 | srb_t *sp = data; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1134 | struct srb_iocb *tmf = &sp->u.iocb_cmd; |
| 1135 | |
| 1136 | tmf->u.tmf.comp_status = CS_TIMEOUT; |
| 1137 | complete(&tmf->u.tmf.comp); |
| 1138 | } |
| 1139 | |
| 1140 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1141 | qla2x00_tmf_sp_done(void *ptr, int res) |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1142 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1143 | srb_t *sp = ptr; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1144 | struct srb_iocb *tmf = &sp->u.iocb_cmd; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1145 | |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1146 | complete(&tmf->u.tmf.comp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | int |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1150 | 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] | 1151 | uint32_t tag) |
| 1152 | { |
| 1153 | struct scsi_qla_host *vha = fcport->vha; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1154 | struct srb_iocb *tm_iocb; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1155 | srb_t *sp; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1156 | int rval = QLA_FUNCTION_FAILED; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1157 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1158 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1159 | if (!sp) |
| 1160 | goto done; |
| 1161 | |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1162 | tm_iocb = &sp->u.iocb_cmd; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1163 | sp->type = SRB_TM_CMD; |
| 1164 | sp->name = "tmf"; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1165 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)); |
| 1166 | tm_iocb->u.tmf.flags = flags; |
| 1167 | tm_iocb->u.tmf.lun = lun; |
| 1168 | tm_iocb->u.tmf.data = tag; |
| 1169 | sp->done = qla2x00_tmf_sp_done; |
| 1170 | tm_iocb->timeout = qla2x00_tmf_iocb_timeout; |
| 1171 | init_completion(&tm_iocb->u.tmf.comp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1172 | |
| 1173 | rval = qla2x00_start_sp(sp); |
| 1174 | if (rval != QLA_SUCCESS) |
| 1175 | goto done_free_sp; |
| 1176 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1177 | ql_dbg(ql_dbg_taskm, vha, 0x802f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1178 | "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n", |
| 1179 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
| 1180 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1181 | |
| 1182 | wait_for_completion(&tm_iocb->u.tmf.comp); |
| 1183 | |
| 1184 | rval = tm_iocb->u.tmf.comp_status == CS_COMPLETE ? |
| 1185 | QLA_SUCCESS : QLA_FUNCTION_FAILED; |
| 1186 | |
| 1187 | if ((rval != QLA_SUCCESS) || tm_iocb->u.tmf.data) { |
| 1188 | ql_dbg(ql_dbg_taskm, vha, 0x8030, |
| 1189 | "TM IOCB failed (%x).\n", rval); |
| 1190 | } |
| 1191 | |
| 1192 | if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) { |
| 1193 | flags = tm_iocb->u.tmf.flags; |
| 1194 | lun = (uint16_t)tm_iocb->u.tmf.lun; |
| 1195 | |
| 1196 | /* Issue Marker IOCB */ |
| 1197 | qla2x00_marker(vha, vha->hw->req_q_map[0], |
| 1198 | vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun, |
| 1199 | flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID); |
| 1200 | } |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1201 | |
| 1202 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1203 | sp->free(sp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1204 | done: |
| 1205 | return rval; |
| 1206 | } |
| 1207 | |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1208 | static void |
| 1209 | qla24xx_abort_iocb_timeout(void *data) |
| 1210 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1211 | srb_t *sp = data; |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1212 | struct srb_iocb *abt = &sp->u.iocb_cmd; |
| 1213 | |
| 1214 | abt->u.abt.comp_status = CS_TIMEOUT; |
| 1215 | complete(&abt->u.abt.comp); |
| 1216 | } |
| 1217 | |
| 1218 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1219 | qla24xx_abort_sp_done(void *ptr, int res) |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1220 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1221 | srb_t *sp = ptr; |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1222 | struct srb_iocb *abt = &sp->u.iocb_cmd; |
| 1223 | |
| 1224 | complete(&abt->u.abt.comp); |
| 1225 | } |
| 1226 | |
Quinn Tran | 15f30a5 | 2017-03-15 09:48:52 -0700 | [diff] [blame] | 1227 | int |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1228 | qla24xx_async_abort_cmd(srb_t *cmd_sp) |
| 1229 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1230 | scsi_qla_host_t *vha = cmd_sp->vha; |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1231 | fc_port_t *fcport = cmd_sp->fcport; |
| 1232 | struct srb_iocb *abt_iocb; |
| 1233 | srb_t *sp; |
| 1234 | int rval = QLA_FUNCTION_FAILED; |
| 1235 | |
| 1236 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 1237 | if (!sp) |
| 1238 | goto done; |
| 1239 | |
| 1240 | abt_iocb = &sp->u.iocb_cmd; |
| 1241 | sp->type = SRB_ABT_CMD; |
| 1242 | sp->name = "abort"; |
| 1243 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)); |
| 1244 | abt_iocb->u.abt.cmd_hndl = cmd_sp->handle; |
| 1245 | sp->done = qla24xx_abort_sp_done; |
| 1246 | abt_iocb->timeout = qla24xx_abort_iocb_timeout; |
| 1247 | init_completion(&abt_iocb->u.abt.comp); |
| 1248 | |
| 1249 | rval = qla2x00_start_sp(sp); |
| 1250 | if (rval != QLA_SUCCESS) |
| 1251 | goto done_free_sp; |
| 1252 | |
| 1253 | ql_dbg(ql_dbg_async, vha, 0x507c, |
| 1254 | "Abort command issued - hdl=%x, target_id=%x\n", |
| 1255 | cmd_sp->handle, fcport->tgt_id); |
| 1256 | |
| 1257 | wait_for_completion(&abt_iocb->u.abt.comp); |
| 1258 | |
| 1259 | rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ? |
| 1260 | QLA_SUCCESS : QLA_FUNCTION_FAILED; |
| 1261 | |
| 1262 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1263 | sp->free(sp); |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1264 | done: |
| 1265 | return rval; |
| 1266 | } |
| 1267 | |
| 1268 | int |
| 1269 | qla24xx_async_abort_command(srb_t *sp) |
| 1270 | { |
| 1271 | unsigned long flags = 0; |
| 1272 | |
| 1273 | uint32_t handle; |
| 1274 | fc_port_t *fcport = sp->fcport; |
| 1275 | struct scsi_qla_host *vha = fcport->vha; |
| 1276 | struct qla_hw_data *ha = vha->hw; |
| 1277 | struct req_que *req = vha->req; |
| 1278 | |
| 1279 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1280 | for (handle = 1; handle < req->num_outstanding_cmds; handle++) { |
| 1281 | if (req->outstanding_cmds[handle] == sp) |
| 1282 | break; |
| 1283 | } |
| 1284 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1285 | if (handle == req->num_outstanding_cmds) { |
| 1286 | /* Command not found. */ |
| 1287 | return QLA_FUNCTION_FAILED; |
| 1288 | } |
| 1289 | if (sp->type == SRB_FXIOCB_DCMD) |
| 1290 | return qlafx00_fx_disc(vha, &vha->hw->mr.fcport, |
| 1291 | FXDISC_ABORT_IOCTL); |
| 1292 | |
| 1293 | return qla24xx_async_abort_cmd(sp); |
| 1294 | } |
| 1295 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1296 | static void |
| 1297 | qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1298 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1299 | port_id_t cid; /* conflict Nport id */ |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1300 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1301 | switch (ea->data[0]) { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1302 | case MBS_COMMAND_COMPLETE: |
Andrew Vasquez | a4f92a3 | 2011-03-30 11:46:31 -0700 | [diff] [blame] | 1303 | /* |
| 1304 | * Driver must validate login state - If PRLI not complete, |
| 1305 | * force a relogin attempt via implicit LOGO, PLOGI, and PRLI |
| 1306 | * requests. |
| 1307 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1308 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 1309 | "%s %d %8phC post gpdb\n", |
| 1310 | __func__, __LINE__, ea->fcport->port_name); |
| 1311 | ea->fcport->chip_reset = vha->hw->chip_reset; |
| 1312 | ea->fcport->logout_on_delete = 1; |
| 1313 | qla24xx_post_gpdb_work(vha, ea->fcport, 0); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1314 | break; |
| 1315 | case MBS_COMMAND_ERROR: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1316 | ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC cmd error %x\n", |
| 1317 | __func__, __LINE__, ea->fcport->port_name, ea->data[1]); |
| 1318 | |
| 1319 | ea->fcport->flags &= ~FCF_ASYNC_SENT; |
| 1320 | ea->fcport->disc_state = DSC_LOGIN_FAILED; |
| 1321 | if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1322 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1323 | else |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1324 | qla2x00_mark_device_lost(vha, ea->fcport, 1, 0); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1325 | break; |
| 1326 | case MBS_LOOP_ID_USED: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1327 | /* data[1] = IO PARAM 1 = nport ID */ |
| 1328 | cid.b.domain = (ea->iop[1] >> 16) & 0xff; |
| 1329 | cid.b.area = (ea->iop[1] >> 8) & 0xff; |
| 1330 | cid.b.al_pa = ea->iop[1] & 0xff; |
| 1331 | cid.b.rsvd_1 = 0; |
| 1332 | |
| 1333 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 1334 | "%s %d %8phC LoopID 0x%x in use post gnl\n", |
| 1335 | __func__, __LINE__, ea->fcport->port_name, |
| 1336 | ea->fcport->loop_id); |
| 1337 | |
| 1338 | if (IS_SW_RESV_ADDR(cid)) { |
| 1339 | set_bit(ea->fcport->loop_id, vha->hw->loop_id_map); |
| 1340 | ea->fcport->loop_id = FC_NO_LOOP_ID; |
| 1341 | } else { |
| 1342 | qla2x00_clear_loop_id(ea->fcport); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1343 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1344 | qla24xx_post_gnl_work(vha, ea->fcport); |
| 1345 | break; |
| 1346 | case MBS_PORT_ID_USED: |
| 1347 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 1348 | "%s %d %8phC NPortId %02x%02x%02x inuse post gidpn\n", |
| 1349 | __func__, __LINE__, ea->fcport->port_name, |
| 1350 | ea->fcport->d_id.b.domain, ea->fcport->d_id.b.area, |
| 1351 | ea->fcport->d_id.b.al_pa); |
| 1352 | |
| 1353 | qla2x00_clear_loop_id(ea->fcport); |
| 1354 | qla24xx_post_gidpn_work(vha, ea->fcport); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1355 | break; |
| 1356 | } |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1357 | return; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1358 | } |
| 1359 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1360 | void |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1361 | qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 1362 | uint16_t *data) |
| 1363 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1364 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1365 | qlt_logo_completion_handler(fcport, data[0]); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1366 | fcport->login_gen++; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1367 | return; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1368 | } |
| 1369 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1370 | void |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1371 | qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 1372 | uint16_t *data) |
| 1373 | { |
| 1374 | if (data[0] == MBS_COMMAND_COMPLETE) { |
| 1375 | qla2x00_update_fcport(vha, fcport); |
| 1376 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1377 | return; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1378 | } |
| 1379 | |
| 1380 | /* Retry login. */ |
| 1381 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 1382 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
| 1383 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1384 | else |
Andrew Vasquez | 80d7944 | 2011-03-30 11:46:17 -0700 | [diff] [blame] | 1385 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1386 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1387 | return; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1388 | } |
| 1389 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | /****************************************************************************/ |
| 1391 | /* QLogic ISP2x00 Hardware Support Functions. */ |
| 1392 | /****************************************************************************/ |
| 1393 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 1394 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1395 | qla83xx_nic_core_fw_load(scsi_qla_host_t *vha) |
| 1396 | { |
| 1397 | int rval = QLA_SUCCESS; |
| 1398 | struct qla_hw_data *ha = vha->hw; |
| 1399 | uint32_t idc_major_ver, idc_minor_ver; |
Saurav Kashyap | 711aa7f | 2012-08-22 14:21:15 -0400 | [diff] [blame] | 1400 | uint16_t config[4]; |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1401 | |
| 1402 | qla83xx_idc_lock(vha, 0); |
| 1403 | |
| 1404 | /* SV: TODO: Assign initialization timeout from |
| 1405 | * flash-info / other param |
| 1406 | */ |
| 1407 | ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT; |
| 1408 | ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT; |
| 1409 | |
| 1410 | /* Set our fcoe function presence */ |
| 1411 | if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) { |
| 1412 | ql_dbg(ql_dbg_p3p, vha, 0xb077, |
| 1413 | "Error while setting DRV-Presence.\n"); |
| 1414 | rval = QLA_FUNCTION_FAILED; |
| 1415 | goto exit; |
| 1416 | } |
| 1417 | |
| 1418 | /* Decide the reset ownership */ |
| 1419 | qla83xx_reset_ownership(vha); |
| 1420 | |
| 1421 | /* |
| 1422 | * On first protocol driver load: |
| 1423 | * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery |
| 1424 | * register. |
| 1425 | * Others: Check compatibility with current IDC Major version. |
| 1426 | */ |
| 1427 | qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver); |
| 1428 | if (ha->flags.nic_core_reset_owner) { |
| 1429 | /* Set IDC Major version */ |
| 1430 | idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION; |
| 1431 | qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver); |
| 1432 | |
| 1433 | /* Clearing IDC-Lock-Recovery register */ |
| 1434 | qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0); |
| 1435 | } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) { |
| 1436 | /* |
| 1437 | * Clear further IDC participation if we are not compatible with |
| 1438 | * the current IDC Major Version. |
| 1439 | */ |
| 1440 | ql_log(ql_log_warn, vha, 0xb07d, |
| 1441 | "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n", |
| 1442 | idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION); |
| 1443 | __qla83xx_clear_drv_presence(vha); |
| 1444 | rval = QLA_FUNCTION_FAILED; |
| 1445 | goto exit; |
| 1446 | } |
| 1447 | /* Each function sets its supported Minor version. */ |
| 1448 | qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver); |
| 1449 | idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2)); |
| 1450 | qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver); |
| 1451 | |
Saurav Kashyap | 711aa7f | 2012-08-22 14:21:15 -0400 | [diff] [blame] | 1452 | if (ha->flags.nic_core_reset_owner) { |
| 1453 | memset(config, 0, sizeof(config)); |
| 1454 | if (!qla81xx_get_port_config(vha, config)) |
| 1455 | qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, |
| 1456 | QLA8XXX_DEV_READY); |
| 1457 | } |
| 1458 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1459 | rval = qla83xx_idc_state_handler(vha); |
| 1460 | |
| 1461 | exit: |
| 1462 | qla83xx_idc_unlock(vha, 0); |
| 1463 | |
| 1464 | return rval; |
| 1465 | } |
| 1466 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | /* |
| 1468 | * qla2x00_initialize_adapter |
| 1469 | * Initialize board. |
| 1470 | * |
| 1471 | * Input: |
| 1472 | * ha = adapter block pointer. |
| 1473 | * |
| 1474 | * Returns: |
| 1475 | * 0 = success |
| 1476 | */ |
| 1477 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1478 | qla2x00_initialize_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | { |
| 1480 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1481 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1482 | struct req_que *req = ha->req_q_map[0]; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 1483 | |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 1484 | memset(&vha->qla_stats, 0, sizeof(vha->qla_stats)); |
| 1485 | memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat)); |
| 1486 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | /* Clear adapter flags. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1488 | vha->flags.online = 0; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 1489 | ha->flags.chip_reset_done = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1490 | vha->flags.reset_active = 0; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 1491 | ha->flags.pci_channel_io_perm_failure = 0; |
| 1492 | ha->flags.eeh_busy = 0; |
Joe Carnuccio | fabbb8d | 2013-08-27 01:37:40 -0400 | [diff] [blame] | 1493 | vha->qla_stats.jiffies_at_last_reset = get_jiffies_64(); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1494 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 1495 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 1496 | vha->device_flags = DFLG_NO_CABLE; |
| 1497 | vha->dpc_flags = 0; |
| 1498 | vha->flags.management_server_logged_in = 0; |
| 1499 | vha->marker_needed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | ha->isp_abort_cnt = 0; |
| 1501 | ha->beacon_blink_led = 0; |
| 1502 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1503 | set_bit(0, ha->req_qid_map); |
| 1504 | set_bit(0, ha->rsp_qid_map); |
| 1505 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1506 | ql_dbg(ql_dbg_init, vha, 0x0040, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1507 | "Configuring PCI space...\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1508 | rval = ha->isp_ops->pci_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -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, 0x0044, |
| 1511 | "Unable to configure PCI space.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 | return (rval); |
| 1513 | } |
| 1514 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1515 | ha->isp_ops->reset_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1517 | rval = qla2xxx_get_flash_info(vha); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 1518 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1519 | ql_log(ql_log_fatal, vha, 0x004f, |
| 1520 | "Unable to validate FLASH data.\n"); |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 1521 | return rval; |
| 1522 | } |
| 1523 | |
| 1524 | if (IS_QLA8044(ha)) { |
| 1525 | qla8044_read_reset_template(vha); |
| 1526 | |
| 1527 | /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0. |
| 1528 | * If DONRESET_BIT0 is set, drivers should not set dev_state |
| 1529 | * to NEED_RESET. But if NEED_RESET is set, drivers should |
| 1530 | * should honor the reset. */ |
| 1531 | if (ql2xdontresethba == 1) |
| 1532 | qla8044_set_idc_dontreset(vha); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 1533 | } |
| 1534 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1535 | ha->isp_ops->get_flash_version(vha, req->ring); |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1536 | ql_dbg(ql_dbg_init, vha, 0x0061, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1537 | "Configure NVRAM parameters...\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1538 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1539 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 1541 | if (ha->flags.disable_serdes) { |
| 1542 | /* Mask HBA via NVRAM settings? */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1543 | ql_log(ql_log_info, vha, 0x0077, |
Oleksandr Khoshaba | 7b83355 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1544 | "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name); |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 1545 | return QLA_FUNCTION_FAILED; |
| 1546 | } |
| 1547 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1548 | ql_dbg(ql_dbg_init, vha, 0x0078, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1549 | "Verifying loaded RISC code...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1551 | if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) { |
| 1552 | rval = ha->isp_ops->chip_diag(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 1553 | if (rval) |
| 1554 | return (rval); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1555 | rval = qla2x00_setup_chip(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 1556 | if (rval) |
| 1557 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1559 | |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1560 | if (IS_QLA84XX(ha)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1561 | ha->cs84xx = qla84xx_get_chip(vha); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1562 | if (!ha->cs84xx) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1563 | ql_log(ql_log_warn, vha, 0x00d0, |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1564 | "Unable to configure ISP84XX.\n"); |
| 1565 | return QLA_FUNCTION_FAILED; |
| 1566 | } |
| 1567 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1568 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 1569 | if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1570 | rval = qla2x00_init_rings(vha); |
| 1571 | |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 1572 | ha->flags.chip_reset_done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 1574 | if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) { |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 1575 | /* Issue verify 84xx FW IOCB to complete 84xx initialization */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 1576 | rval = qla84xx_init_chip(vha); |
| 1577 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1578 | ql_log(ql_log_warn, vha, 0x00d4, |
| 1579 | "Unable to initialize ISP84XX.\n"); |
Bart Van Assche | 8d2b21d | 2015-06-04 15:58:09 -0700 | [diff] [blame] | 1580 | qla84xx_put_chip(vha); |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 1581 | } |
| 1582 | } |
| 1583 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1584 | /* Load the NIC Core f/w if we are the first protocol driver. */ |
| 1585 | if (IS_QLA8031(ha)) { |
| 1586 | rval = qla83xx_nic_core_fw_load(vha); |
| 1587 | if (rval) |
| 1588 | ql_log(ql_log_warn, vha, 0x0124, |
| 1589 | "Error in initializing NIC Core f/w.\n"); |
| 1590 | } |
| 1591 | |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 1592 | if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)) |
| 1593 | qla24xx_read_fcp_prio_cfg(vha); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 1594 | |
Joe Carnuccio | c46e65c | 2013-08-27 01:37:35 -0400 | [diff] [blame] | 1595 | if (IS_P3P_TYPE(ha)) |
| 1596 | qla82xx_set_driver_version(vha, QLA2XXX_VERSION); |
| 1597 | else |
| 1598 | qla25xx_set_driver_version(vha, QLA2XXX_VERSION); |
| 1599 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | return (rval); |
| 1601 | } |
| 1602 | |
| 1603 | /** |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1604 | * qla2100_pci_config() - Setup ISP21xx PCI configuration registers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | * @ha: HA context |
| 1606 | * |
| 1607 | * Returns 0 on success. |
| 1608 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1609 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1610 | qla2100_pci_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1612 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1613 | unsigned long flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1614 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1615 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 1618 | pci_try_set_mwi(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1619 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1621 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 1623 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 1624 | pci_disable_rom(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1626 | /* Get PCI bus information. */ |
| 1627 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1628 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1629 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1630 | |
| 1631 | return QLA_SUCCESS; |
| 1632 | } |
| 1633 | |
| 1634 | /** |
| 1635 | * qla2300_pci_config() - Setup ISP23xx PCI configuration registers. |
| 1636 | * @ha: HA context |
| 1637 | * |
| 1638 | * Returns 0 on success. |
| 1639 | */ |
| 1640 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1641 | qla2300_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1642 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1643 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1644 | unsigned long flags = 0; |
| 1645 | uint32_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1646 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1647 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1648 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1649 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 1650 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1651 | |
| 1652 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1653 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1654 | |
| 1655 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 1656 | w &= ~PCI_COMMAND_INTX_DISABLE; |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1657 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1658 | |
| 1659 | /* |
| 1660 | * If this is a 2300 card and not 2312, reset the |
| 1661 | * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately, |
| 1662 | * the 2310 also reports itself as a 2300 so we need to get the |
| 1663 | * fb revision level -- a 6 indicates it really is a 2300 and |
| 1664 | * not a 2310. |
| 1665 | */ |
| 1666 | if (IS_QLA2300(ha)) { |
| 1667 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1668 | |
| 1669 | /* Pause RISC. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1670 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1671 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1672 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1673 | break; |
| 1674 | |
| 1675 | udelay(10); |
| 1676 | } |
| 1677 | |
| 1678 | /* Select FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1679 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 1680 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1681 | |
| 1682 | /* Get the fb rev level */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1683 | ha->fb_rev = RD_FB_CMD_REG(ha, reg); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1684 | |
| 1685 | if (ha->fb_rev == FPM_2300) |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1686 | pci_clear_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1687 | |
| 1688 | /* Deselect FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1689 | WRT_REG_WORD(®->ctrl_status, 0x0); |
| 1690 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1691 | |
| 1692 | /* Release RISC module. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1693 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1694 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1695 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1696 | break; |
| 1697 | |
| 1698 | udelay(10); |
| 1699 | } |
| 1700 | |
| 1701 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1702 | } |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1703 | |
| 1704 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 1705 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 1706 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1707 | |
| 1708 | /* Get PCI bus information. */ |
| 1709 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1710 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1711 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1712 | |
| 1713 | return QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1717 | * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers. |
| 1718 | * @ha: HA context |
| 1719 | * |
| 1720 | * Returns 0 on success. |
| 1721 | */ |
| 1722 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1723 | qla24xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1724 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1725 | uint16_t w; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1726 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1727 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1728 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1729 | |
| 1730 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 1731 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1732 | |
| 1733 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1734 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1735 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 1736 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 1737 | |
| 1738 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 1739 | |
| 1740 | /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */ |
Andrew Vasquez | f85ec18 | 2007-07-19 15:06:01 -0700 | [diff] [blame] | 1741 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX)) |
| 1742 | pcix_set_mmrbc(ha->pdev, 2048); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1743 | |
| 1744 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Jon Mason | e67f132 | 2012-07-10 14:57:56 -0700 | [diff] [blame] | 1745 | if (pci_is_pcie(ha->pdev)) |
Chad Dupuis | 5ffd3a5 | 2012-08-22 14:21:26 -0400 | [diff] [blame] | 1746 | pcie_set_readrq(ha->pdev, 4096); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1747 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 1748 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1749 | |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 1750 | ha->chip_revision = ha->pdev->revision; |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1751 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1752 | /* Get PCI bus information. */ |
| 1753 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1754 | ha->pci_attr = RD_REG_DWORD(®->ctrl_status); |
| 1755 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1756 | |
| 1757 | return QLA_SUCCESS; |
| 1758 | } |
| 1759 | |
| 1760 | /** |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1761 | * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers. |
| 1762 | * @ha: HA context |
| 1763 | * |
| 1764 | * Returns 0 on success. |
| 1765 | */ |
| 1766 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1767 | qla25xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1768 | { |
| 1769 | uint16_t w; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1770 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1771 | |
| 1772 | pci_set_master(ha->pdev); |
| 1773 | pci_try_set_mwi(ha->pdev); |
| 1774 | |
| 1775 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
| 1776 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
| 1777 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 1778 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 1779 | |
| 1780 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Jon Mason | e67f132 | 2012-07-10 14:57:56 -0700 | [diff] [blame] | 1781 | if (pci_is_pcie(ha->pdev)) |
Chad Dupuis | 5ffd3a5 | 2012-08-22 14:21:26 -0400 | [diff] [blame] | 1782 | pcie_set_readrq(ha->pdev, 4096); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1783 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 1784 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1785 | |
| 1786 | ha->chip_revision = ha->pdev->revision; |
| 1787 | |
| 1788 | return QLA_SUCCESS; |
| 1789 | } |
| 1790 | |
| 1791 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | * qla2x00_isp_firmware() - Choose firmware image. |
| 1793 | * @ha: HA context |
| 1794 | * |
| 1795 | * Returns 0 on success. |
| 1796 | */ |
| 1797 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1798 | qla2x00_isp_firmware(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | { |
| 1800 | int rval; |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 1801 | uint16_t loop_id, topo, sw_cap; |
| 1802 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1803 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | |
| 1805 | /* Assume loading risc code */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1806 | rval = QLA_FUNCTION_FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | |
| 1808 | if (ha->flags.disable_risc_code_load) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1809 | ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | |
| 1811 | /* Verify checksum of loaded RISC code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1812 | rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address); |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 1813 | if (rval == QLA_SUCCESS) { |
| 1814 | /* And, verify we are not in ROM code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1815 | rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa, |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 1816 | &area, &domain, &topo, &sw_cap); |
| 1817 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1818 | } |
| 1819 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1820 | if (rval) |
| 1821 | ql_dbg(ql_dbg_init, vha, 0x007a, |
| 1822 | "**** Load RISC code ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | |
| 1824 | return (rval); |
| 1825 | } |
| 1826 | |
| 1827 | /** |
| 1828 | * qla2x00_reset_chip() - Reset ISP chip. |
| 1829 | * @ha: HA context |
| 1830 | * |
| 1831 | * Returns 0 on success. |
| 1832 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1833 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1834 | qla2x00_reset_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | { |
| 1836 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1837 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1838 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1839 | uint32_t cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | uint16_t cmd; |
| 1841 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 1842 | if (unlikely(pci_channel_offline(ha->pdev))) |
| 1843 | return; |
| 1844 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1845 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | |
| 1847 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1848 | |
| 1849 | /* Turn off master enable */ |
| 1850 | cmd = 0; |
| 1851 | pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd); |
| 1852 | cmd &= ~PCI_COMMAND_MASTER; |
| 1853 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 1854 | |
| 1855 | if (!IS_QLA2100(ha)) { |
| 1856 | /* Pause RISC. */ |
| 1857 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
| 1858 | if (IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 1859 | for (cnt = 0; cnt < 30000; cnt++) { |
| 1860 | if ((RD_REG_WORD(®->hccr) & |
| 1861 | HCCR_RISC_PAUSE) != 0) |
| 1862 | break; |
| 1863 | udelay(100); |
| 1864 | } |
| 1865 | } else { |
| 1866 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 1867 | udelay(10); |
| 1868 | } |
| 1869 | |
| 1870 | /* Select FPM registers. */ |
| 1871 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 1872 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 1873 | |
| 1874 | /* FPM Soft Reset. */ |
| 1875 | WRT_REG_WORD(®->fpm_diag_config, 0x100); |
| 1876 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 1877 | |
| 1878 | /* Toggle Fpm Reset. */ |
| 1879 | if (!IS_QLA2200(ha)) { |
| 1880 | WRT_REG_WORD(®->fpm_diag_config, 0x0); |
| 1881 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 1882 | } |
| 1883 | |
| 1884 | /* Select frame buffer registers. */ |
| 1885 | WRT_REG_WORD(®->ctrl_status, 0x10); |
| 1886 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 1887 | |
| 1888 | /* Reset frame buffer FIFOs. */ |
| 1889 | if (IS_QLA2200(ha)) { |
| 1890 | WRT_FB_CMD_REG(ha, reg, 0xa000); |
| 1891 | RD_FB_CMD_REG(ha, reg); /* PCI Posting. */ |
| 1892 | } else { |
| 1893 | WRT_FB_CMD_REG(ha, reg, 0x00fc); |
| 1894 | |
| 1895 | /* Read back fb_cmd until zero or 3 seconds max */ |
| 1896 | for (cnt = 0; cnt < 3000; cnt++) { |
| 1897 | if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0) |
| 1898 | break; |
| 1899 | udelay(100); |
| 1900 | } |
| 1901 | } |
| 1902 | |
| 1903 | /* Select RISC module registers. */ |
| 1904 | WRT_REG_WORD(®->ctrl_status, 0); |
| 1905 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 1906 | |
| 1907 | /* Reset RISC processor. */ |
| 1908 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 1909 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 1910 | |
| 1911 | /* Release RISC processor. */ |
| 1912 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 1913 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 1914 | } |
| 1915 | |
| 1916 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); |
| 1917 | WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT); |
| 1918 | |
| 1919 | /* Reset ISP chip. */ |
| 1920 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 1921 | |
| 1922 | /* Wait for RISC to recover from reset. */ |
| 1923 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 1924 | /* |
| 1925 | * It is necessary to for a delay here since the card doesn't |
| 1926 | * respond to PCI reads during a reset. On some architectures |
| 1927 | * this will result in an MCA. |
| 1928 | */ |
| 1929 | udelay(20); |
| 1930 | for (cnt = 30000; cnt; cnt--) { |
| 1931 | if ((RD_REG_WORD(®->ctrl_status) & |
| 1932 | CSR_ISP_SOFT_RESET) == 0) |
| 1933 | break; |
| 1934 | udelay(100); |
| 1935 | } |
| 1936 | } else |
| 1937 | udelay(10); |
| 1938 | |
| 1939 | /* Reset RISC processor. */ |
| 1940 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 1941 | |
| 1942 | WRT_REG_WORD(®->semaphore, 0); |
| 1943 | |
| 1944 | /* Release RISC processor. */ |
| 1945 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 1946 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 1947 | |
| 1948 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 1949 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | ffb39f0 | 2006-05-17 15:09:06 -0700 | [diff] [blame] | 1950 | if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | |
| 1953 | udelay(100); |
| 1954 | } |
| 1955 | } else |
| 1956 | udelay(100); |
| 1957 | |
| 1958 | /* Turn on master enable */ |
| 1959 | cmd |= PCI_COMMAND_MASTER; |
| 1960 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 1961 | |
| 1962 | /* Disable RISC pause on FPM parity error. */ |
| 1963 | if (!IS_QLA2100(ha)) { |
| 1964 | WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE); |
| 1965 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 1966 | } |
| 1967 | |
| 1968 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1969 | } |
| 1970 | |
| 1971 | /** |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 1972 | * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC. |
| 1973 | * |
| 1974 | * Returns 0 on success. |
| 1975 | */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 1976 | static int |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 1977 | qla81xx_reset_mpi(scsi_qla_host_t *vha) |
| 1978 | { |
| 1979 | uint16_t mb[4] = {0x1010, 0, 1, 0}; |
| 1980 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1981 | if (!IS_QLA81XX(vha->hw)) |
| 1982 | return QLA_SUCCESS; |
| 1983 | |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 1984 | return qla81xx_write_mpi_register(vha, mb); |
| 1985 | } |
| 1986 | |
| 1987 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1988 | * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC. |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1989 | * @ha: HA context |
| 1990 | * |
| 1991 | * Returns 0 on success. |
| 1992 | */ |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 1993 | static inline int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1994 | qla24xx_reset_risc(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1995 | { |
| 1996 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1997 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1998 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 1999 | uint32_t cnt; |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2000 | uint16_t wd; |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2001 | static int abts_cnt; /* ISP abort retry counts */ |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2002 | int rval = QLA_SUCCESS; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2003 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2004 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2005 | |
| 2006 | /* Reset RISC. */ |
| 2007 | WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
| 2008 | for (cnt = 0; cnt < 30000; cnt++) { |
| 2009 | if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0) |
| 2010 | break; |
| 2011 | |
| 2012 | udelay(10); |
| 2013 | } |
| 2014 | |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2015 | if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE)) |
| 2016 | set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags); |
| 2017 | |
| 2018 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e, |
| 2019 | "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n", |
| 2020 | RD_REG_DWORD(®->hccr), |
| 2021 | RD_REG_DWORD(®->ctrl_status), |
| 2022 | (RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE)); |
| 2023 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2024 | WRT_REG_DWORD(®->ctrl_status, |
| 2025 | CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2026 | pci_read_config_word(ha->pdev, PCI_COMMAND, &wd); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2027 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2028 | udelay(100); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2029 | |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2030 | /* Wait for firmware to complete NVRAM accesses. */ |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2031 | RD_REG_WORD(®->mailbox0); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2032 | for (cnt = 10000; RD_REG_WORD(®->mailbox0) != 0 && |
| 2033 | rval == QLA_SUCCESS; cnt--) { |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2034 | barrier(); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2035 | if (cnt) |
| 2036 | udelay(5); |
| 2037 | else |
| 2038 | rval = QLA_FUNCTION_TIMEOUT; |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2039 | } |
| 2040 | |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2041 | if (rval == QLA_SUCCESS) |
| 2042 | set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags); |
| 2043 | |
| 2044 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f, |
| 2045 | "HCCR: 0x%x, MailBox0 Status 0x%x\n", |
| 2046 | RD_REG_DWORD(®->hccr), |
| 2047 | RD_REG_DWORD(®->mailbox0)); |
| 2048 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2049 | /* Wait for soft-reset to complete. */ |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2050 | RD_REG_DWORD(®->ctrl_status); |
Quinn Tran | 200ffb1 | 2016-12-23 18:06:12 -0800 | [diff] [blame] | 2051 | for (cnt = 0; cnt < 60; cnt++) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2052 | barrier(); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2053 | if ((RD_REG_DWORD(®->ctrl_status) & |
| 2054 | CSRX_ISP_SOFT_RESET) == 0) |
| 2055 | break; |
| 2056 | |
| 2057 | udelay(5); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2058 | } |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2059 | if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_ISP_SOFT_RESET)) |
| 2060 | set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags); |
| 2061 | |
| 2062 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d, |
| 2063 | "HCCR: 0x%x, Soft Reset status: 0x%x\n", |
| 2064 | RD_REG_DWORD(®->hccr), |
| 2065 | RD_REG_DWORD(®->ctrl_status)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2066 | |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2067 | /* If required, do an MPI FW reset now */ |
| 2068 | if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) { |
| 2069 | if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) { |
| 2070 | if (++abts_cnt < 5) { |
| 2071 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 2072 | set_bit(MPI_RESET_NEEDED, &vha->dpc_flags); |
| 2073 | } else { |
| 2074 | /* |
| 2075 | * We exhausted the ISP abort retries. We have to |
| 2076 | * set the board offline. |
| 2077 | */ |
| 2078 | abts_cnt = 0; |
| 2079 | vha->flags.online = 0; |
| 2080 | } |
| 2081 | } |
| 2082 | } |
| 2083 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2084 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 2085 | RD_REG_DWORD(®->hccr); |
| 2086 | |
| 2087 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 2088 | RD_REG_DWORD(®->hccr); |
| 2089 | |
| 2090 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET); |
| 2091 | RD_REG_DWORD(®->hccr); |
| 2092 | |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2093 | RD_REG_WORD(®->mailbox0); |
Quinn Tran | 200ffb1 | 2016-12-23 18:06:12 -0800 | [diff] [blame] | 2094 | for (cnt = 60; RD_REG_WORD(®->mailbox0) != 0 && |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2095 | rval == QLA_SUCCESS; cnt--) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2096 | barrier(); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2097 | if (cnt) |
| 2098 | udelay(5); |
| 2099 | else |
| 2100 | rval = QLA_FUNCTION_TIMEOUT; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2101 | } |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2102 | if (rval == QLA_SUCCESS) |
| 2103 | set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags); |
| 2104 | |
| 2105 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e, |
| 2106 | "Host Risc 0x%x, mailbox0 0x%x\n", |
| 2107 | RD_REG_DWORD(®->hccr), |
| 2108 | RD_REG_WORD(®->mailbox0)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2109 | |
| 2110 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 124f85e | 2009-01-05 11:18:06 -0800 | [diff] [blame] | 2111 | |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2112 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f, |
| 2113 | "Driver in %s mode\n", |
| 2114 | IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling"); |
| 2115 | |
Andrew Vasquez | 124f85e | 2009-01-05 11:18:06 -0800 | [diff] [blame] | 2116 | if (IS_NOPOLLING_TYPE(ha)) |
| 2117 | ha->isp_ops->enable_intrs(ha); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2118 | |
| 2119 | return rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2120 | } |
| 2121 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2122 | static void |
| 2123 | qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data) |
| 2124 | { |
| 2125 | struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24; |
| 2126 | |
| 2127 | WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET); |
| 2128 | *data = RD_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET); |
| 2129 | |
| 2130 | } |
| 2131 | |
| 2132 | static void |
| 2133 | qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data) |
| 2134 | { |
| 2135 | struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24; |
| 2136 | |
| 2137 | WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET); |
| 2138 | WRT_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET, data); |
| 2139 | } |
| 2140 | |
| 2141 | static void |
| 2142 | qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha) |
| 2143 | { |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2144 | uint32_t wd32 = 0; |
| 2145 | uint delta_msec = 100; |
| 2146 | uint elapsed_msec = 0; |
| 2147 | uint timeout_msec; |
| 2148 | ulong n; |
| 2149 | |
Joe Carnuccio | cc79076 | 2015-08-04 13:37:53 -0400 | [diff] [blame] | 2150 | if (vha->hw->pdev->subsystem_device != 0x0175 && |
| 2151 | vha->hw->pdev->subsystem_device != 0x0240) |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2152 | return; |
| 2153 | |
Joe Carnuccio | 8dd7e3a | 2015-08-04 13:37:54 -0400 | [diff] [blame] | 2154 | WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE); |
| 2155 | udelay(100); |
| 2156 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2157 | attempt: |
| 2158 | timeout_msec = TIMEOUT_SEMAPHORE; |
| 2159 | n = timeout_msec / delta_msec; |
| 2160 | while (n--) { |
| 2161 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET); |
| 2162 | qla25xx_read_risc_sema_reg(vha, &wd32); |
| 2163 | if (wd32 & RISC_SEMAPHORE) |
| 2164 | break; |
| 2165 | msleep(delta_msec); |
| 2166 | elapsed_msec += delta_msec; |
| 2167 | if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED) |
| 2168 | goto force; |
| 2169 | } |
| 2170 | |
| 2171 | if (!(wd32 & RISC_SEMAPHORE)) |
| 2172 | goto force; |
| 2173 | |
| 2174 | if (!(wd32 & RISC_SEMAPHORE_FORCE)) |
| 2175 | goto acquired; |
| 2176 | |
| 2177 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR); |
| 2178 | timeout_msec = TIMEOUT_SEMAPHORE_FORCE; |
| 2179 | n = timeout_msec / delta_msec; |
| 2180 | while (n--) { |
| 2181 | qla25xx_read_risc_sema_reg(vha, &wd32); |
| 2182 | if (!(wd32 & RISC_SEMAPHORE_FORCE)) |
| 2183 | break; |
| 2184 | msleep(delta_msec); |
| 2185 | elapsed_msec += delta_msec; |
| 2186 | if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED) |
| 2187 | goto force; |
| 2188 | } |
| 2189 | |
| 2190 | if (wd32 & RISC_SEMAPHORE_FORCE) |
| 2191 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR); |
| 2192 | |
| 2193 | goto attempt; |
| 2194 | |
| 2195 | force: |
| 2196 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET); |
| 2197 | |
| 2198 | acquired: |
| 2199 | return; |
| 2200 | } |
| 2201 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2202 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2203 | * qla24xx_reset_chip() - Reset ISP24xx chip. |
| 2204 | * @ha: HA context |
| 2205 | * |
| 2206 | * Returns 0 on success. |
| 2207 | */ |
| 2208 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2209 | qla24xx_reset_chip(scsi_qla_host_t *vha) |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2210 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2211 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 2212 | |
| 2213 | if (pci_channel_offline(ha->pdev) && |
| 2214 | ha->flags.pci_channel_io_perm_failure) { |
| 2215 | return; |
| 2216 | } |
| 2217 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 2218 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2219 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2220 | qla25xx_manipulate_risc_semaphore(vha); |
| 2221 | |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2222 | /* Perform RISC reset. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2223 | qla24xx_reset_risc(vha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2224 | } |
| 2225 | |
| 2226 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | * qla2x00_chip_diag() - Test chip for proper operation. |
| 2228 | * @ha: HA context |
| 2229 | * |
| 2230 | * Returns 0 on success. |
| 2231 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2232 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2233 | qla2x00_chip_diag(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | { |
| 2235 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2236 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2237 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2238 | unsigned long flags = 0; |
| 2239 | uint16_t data; |
| 2240 | uint32_t cnt; |
| 2241 | uint16_t mb[5]; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2242 | struct req_que *req = ha->req_q_map[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | |
| 2244 | /* Assume a failed state */ |
| 2245 | rval = QLA_FUNCTION_FAILED; |
| 2246 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2247 | ql_dbg(ql_dbg_init, vha, 0x007b, |
| 2248 | "Testing device at %lx.\n", (u_long)®->flash_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2249 | |
| 2250 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2251 | |
| 2252 | /* Reset ISP chip. */ |
| 2253 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 2254 | |
| 2255 | /* |
| 2256 | * We need to have a delay here since the card will not respond while |
| 2257 | * in reset causing an MCA on some architectures. |
| 2258 | */ |
| 2259 | udelay(20); |
| 2260 | data = qla2x00_debounce_register(®->ctrl_status); |
| 2261 | for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) { |
| 2262 | udelay(5); |
| 2263 | data = RD_REG_WORD(®->ctrl_status); |
| 2264 | barrier(); |
| 2265 | } |
| 2266 | |
| 2267 | if (!cnt) |
| 2268 | goto chip_diag_failed; |
| 2269 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2270 | ql_dbg(ql_dbg_init, vha, 0x007c, |
| 2271 | "Reset register cleared by chip reset.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | |
| 2273 | /* Reset RISC processor. */ |
| 2274 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 2275 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 2276 | |
| 2277 | /* Workaround for QLA2312 PCI parity error */ |
| 2278 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 2279 | data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0)); |
| 2280 | for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) { |
| 2281 | udelay(5); |
| 2282 | data = RD_MAILBOX_REG(ha, reg, 0); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2283 | barrier(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2284 | } |
| 2285 | } else |
| 2286 | udelay(10); |
| 2287 | |
| 2288 | if (!cnt) |
| 2289 | goto chip_diag_failed; |
| 2290 | |
| 2291 | /* Check product ID of chip */ |
Milan P Gandhi | 5a68a1c | 2017-03-31 14:37:04 -0700 | [diff] [blame] | 2292 | 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] | 2293 | |
| 2294 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); |
| 2295 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); |
| 2296 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); |
| 2297 | mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4)); |
| 2298 | if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) || |
| 2299 | mb[3] != PROD_ID_3) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2300 | ql_log(ql_log_warn, vha, 0x0062, |
| 2301 | "Wrong product ID = 0x%x,0x%x,0x%x.\n", |
| 2302 | mb[1], mb[2], mb[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2303 | |
| 2304 | goto chip_diag_failed; |
| 2305 | } |
| 2306 | ha->product_id[0] = mb[1]; |
| 2307 | ha->product_id[1] = mb[2]; |
| 2308 | ha->product_id[2] = mb[3]; |
| 2309 | ha->product_id[3] = mb[4]; |
| 2310 | |
| 2311 | /* Adjust fw RISC transfer size */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2312 | if (req->length > 1024) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024; |
| 2314 | else |
| 2315 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2316 | req->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | |
| 2318 | if (IS_QLA2200(ha) && |
| 2319 | RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) { |
| 2320 | /* Limit firmware transfer size with a 2200A */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2321 | ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2322 | |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 2323 | ha->device_type |= DT_ISP2200A; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2324 | ha->fw_transfer_size = 128; |
| 2325 | } |
| 2326 | |
| 2327 | /* Wrap Incoming Mailboxes Test. */ |
| 2328 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2329 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2330 | ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2331 | rval = qla2x00_mbx_reg_test(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2332 | if (rval) |
| 2333 | ql_log(ql_log_warn, vha, 0x0080, |
| 2334 | "Failed mailbox send register test.\n"); |
| 2335 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | /* Flag a successful rval */ |
| 2337 | rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2338 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2339 | |
| 2340 | chip_diag_failed: |
| 2341 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2342 | ql_log(ql_log_info, vha, 0x0081, |
| 2343 | "Chip diagnostics **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2344 | |
| 2345 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2346 | |
| 2347 | return (rval); |
| 2348 | } |
| 2349 | |
| 2350 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2351 | * qla24xx_chip_diag() - Test ISP24xx for proper operation. |
| 2352 | * @ha: HA context |
| 2353 | * |
| 2354 | * Returns 0 on success. |
| 2355 | */ |
| 2356 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2357 | qla24xx_chip_diag(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2358 | { |
| 2359 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2360 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2361 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2362 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 2363 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2364 | return QLA_SUCCESS; |
| 2365 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2366 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2367 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2368 | rval = qla2x00_mbx_reg_test(vha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2369 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2370 | ql_log(ql_log_warn, vha, 0x0082, |
| 2371 | "Failed mailbox send register test.\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2372 | } else { |
| 2373 | /* Flag a successful rval */ |
| 2374 | rval = QLA_SUCCESS; |
| 2375 | } |
| 2376 | |
| 2377 | return rval; |
| 2378 | } |
| 2379 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2380 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2381 | qla2x00_alloc_fw_dump(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2382 | { |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2383 | int rval; |
| 2384 | 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] | 2385 | eft_size, fce_size, mq_size; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2386 | dma_addr_t tc_dma; |
| 2387 | void *tc; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2388 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2389 | struct req_que *req = ha->req_q_map[0]; |
| 2390 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 2391 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2392 | if (ha->fw_dump) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2393 | ql_dbg(ql_dbg_init, vha, 0x00bd, |
| 2394 | "Firmware dump already allocated.\n"); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2395 | return; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 2396 | } |
| 2397 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2398 | ha->fw_dumped = 0; |
Hiral Patel | 61f098d | 2014-04-11 16:54:21 -0400 | [diff] [blame] | 2399 | ha->fw_dump_cap_flags = 0; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2400 | dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0; |
| 2401 | req_q_size = rsp_q_size = 0; |
| 2402 | |
| 2403 | if (IS_QLA27XX(ha)) |
| 2404 | goto try_fce; |
| 2405 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2406 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 2407 | fixed_size = sizeof(struct qla2100_fw_dump); |
| 2408 | } else if (IS_QLA23XX(ha)) { |
| 2409 | fixed_size = offsetof(struct qla2300_fw_dump, data_ram); |
| 2410 | mem_size = (ha->fw_memory_size - 0x11000 + 1) * |
| 2411 | sizeof(uint16_t); |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 2412 | } else if (IS_FWI2_CAPABLE(ha)) { |
Himanshu Madhani | b20f02e | 2015-06-10 11:05:18 -0400 | [diff] [blame] | 2413 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2414 | fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem); |
| 2415 | else if (IS_QLA81XX(ha)) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 2416 | fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem); |
| 2417 | else if (IS_QLA25XX(ha)) |
| 2418 | fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem); |
| 2419 | else |
| 2420 | fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2421 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2422 | mem_size = (ha->fw_memory_size - 0x100000 + 1) * |
| 2423 | sizeof(uint32_t); |
Giridhar Malavali | 050c9bb | 2012-02-09 11:15:33 -0800 | [diff] [blame] | 2424 | if (ha->mqenable) { |
Himanshu Madhani | b20f02e | 2015-06-10 11:05:18 -0400 | [diff] [blame] | 2425 | if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha)) |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2426 | mq_size = sizeof(struct qla2xxx_mq_chain); |
Giridhar Malavali | 050c9bb | 2012-02-09 11:15:33 -0800 | [diff] [blame] | 2427 | /* |
| 2428 | * Allocate maximum buffer size for all queues. |
| 2429 | * Resizing must be done at end-of-dump processing. |
| 2430 | */ |
| 2431 | mq_size += ha->max_req_queues * |
| 2432 | (req->length * sizeof(request_t)); |
| 2433 | mq_size += ha->max_rsp_queues * |
| 2434 | (rsp->length * sizeof(response_t)); |
| 2435 | } |
Arun Easi | 00876ae | 2013-03-25 02:21:37 -0400 | [diff] [blame] | 2436 | if (ha->tgt.atio_ring) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2437 | mq_size += ha->tgt.atio_q_length * sizeof(request_t); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2438 | /* Allocate memory for Fibre Channel Event Buffer. */ |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2439 | if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) && |
| 2440 | !IS_QLA27XX(ha)) |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2441 | goto try_eft; |
| 2442 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2443 | try_fce: |
| 2444 | if (ha->fce) |
| 2445 | dma_free_coherent(&ha->pdev->dev, |
| 2446 | FCE_SIZE, ha->fce, ha->fce_dma); |
| 2447 | |
| 2448 | /* Allocate memory for Fibre Channel Event Buffer. */ |
Joe Perches | 0ea85b5 | 2014-06-15 13:37:51 -0700 | [diff] [blame] | 2449 | tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma, |
| 2450 | GFP_KERNEL); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2451 | if (!tc) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2452 | ql_log(ql_log_warn, vha, 0x00be, |
| 2453 | "Unable to allocate (%d KB) for FCE.\n", |
| 2454 | FCE_SIZE / 1024); |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 2455 | goto try_eft; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2456 | } |
| 2457 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2458 | rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2459 | ha->fce_mb, &ha->fce_bufs); |
| 2460 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2461 | ql_log(ql_log_warn, vha, 0x00bf, |
| 2462 | "Unable to initialize FCE (%d).\n", rval); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2463 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, |
| 2464 | tc_dma); |
| 2465 | ha->flags.fce_enabled = 0; |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 2466 | goto try_eft; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2467 | } |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2468 | ql_dbg(ql_dbg_init, vha, 0x00c0, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2469 | "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2470 | |
Giridhar Malavali | 7d9dade | 2009-03-24 09:07:58 -0700 | [diff] [blame] | 2471 | fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2472 | ha->flags.fce_enabled = 1; |
| 2473 | ha->fce_dma = tc_dma; |
| 2474 | ha->fce = tc; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2475 | |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2476 | try_eft: |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2477 | if (ha->eft) |
| 2478 | dma_free_coherent(&ha->pdev->dev, |
| 2479 | EFT_SIZE, ha->eft, ha->eft_dma); |
| 2480 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2481 | /* Allocate memory for Extended Trace Buffer. */ |
Joe Perches | 0ea85b5 | 2014-06-15 13:37:51 -0700 | [diff] [blame] | 2482 | tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma, |
| 2483 | GFP_KERNEL); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2484 | if (!tc) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2485 | ql_log(ql_log_warn, vha, 0x00c1, |
| 2486 | "Unable to allocate (%d KB) for EFT.\n", |
| 2487 | EFT_SIZE / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2488 | goto cont_alloc; |
| 2489 | } |
| 2490 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2491 | rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2492 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2493 | ql_log(ql_log_warn, vha, 0x00c2, |
| 2494 | "Unable to initialize EFT (%d).\n", rval); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2495 | dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, |
| 2496 | tc_dma); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2497 | goto cont_alloc; |
| 2498 | } |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2499 | ql_dbg(ql_dbg_init, vha, 0x00c3, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2500 | "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2501 | |
| 2502 | eft_size = EFT_SIZE; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2503 | ha->eft_dma = tc_dma; |
| 2504 | ha->eft = tc; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2505 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2506 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2507 | cont_alloc: |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2508 | if (IS_QLA27XX(ha)) { |
| 2509 | if (!ha->fw_dump_template) { |
| 2510 | ql_log(ql_log_warn, vha, 0x00ba, |
| 2511 | "Failed missing fwdump template\n"); |
| 2512 | return; |
| 2513 | } |
| 2514 | dump_size = qla27xx_fwdt_calculate_dump_size(vha); |
| 2515 | ql_dbg(ql_dbg_init, vha, 0x00fa, |
| 2516 | "-> allocating fwdump (%x bytes)...\n", dump_size); |
| 2517 | goto allocate; |
| 2518 | } |
| 2519 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2520 | req_q_size = req->length * sizeof(request_t); |
| 2521 | rsp_q_size = rsp->length * sizeof(response_t); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2522 | dump_size = offsetof(struct qla2xxx_fw_dump, isp); |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 2523 | 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] | 2524 | ha->chain_offset = dump_size; |
| 2525 | dump_size += mq_size + fce_size; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2526 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2527 | allocate: |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 2528 | ha->fw_dump = vmalloc(dump_size); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2529 | if (!ha->fw_dump) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2530 | ql_log(ql_log_warn, vha, 0x00c4, |
| 2531 | "Unable to allocate (%d KB) for firmware dump.\n", |
| 2532 | dump_size / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2533 | |
Madhuranath Iyengar | e30d175 | 2010-10-15 11:27:46 -0700 | [diff] [blame] | 2534 | if (ha->fce) { |
| 2535 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce, |
| 2536 | ha->fce_dma); |
| 2537 | ha->fce = NULL; |
| 2538 | ha->fce_dma = 0; |
| 2539 | } |
| 2540 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2541 | if (ha->eft) { |
| 2542 | dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft, |
| 2543 | ha->eft_dma); |
| 2544 | ha->eft = NULL; |
| 2545 | ha->eft_dma = 0; |
| 2546 | } |
| 2547 | return; |
| 2548 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2549 | ha->fw_dump_len = dump_size; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2550 | ql_dbg(ql_dbg_init, vha, 0x00c5, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2551 | "Allocated (%d KB) for firmware dump.\n", dump_size / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2552 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2553 | if (IS_QLA27XX(ha)) |
| 2554 | return; |
| 2555 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2556 | ha->fw_dump->signature[0] = 'Q'; |
| 2557 | ha->fw_dump->signature[1] = 'L'; |
| 2558 | ha->fw_dump->signature[2] = 'G'; |
| 2559 | ha->fw_dump->signature[3] = 'C'; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2560 | ha->fw_dump->version = htonl(1); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2561 | |
| 2562 | ha->fw_dump->fixed_size = htonl(fixed_size); |
| 2563 | ha->fw_dump->mem_size = htonl(mem_size); |
| 2564 | ha->fw_dump->req_q_size = htonl(req_q_size); |
| 2565 | ha->fw_dump->rsp_q_size = htonl(rsp_q_size); |
| 2566 | |
| 2567 | ha->fw_dump->eft_size = htonl(eft_size); |
| 2568 | ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma)); |
| 2569 | ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma)); |
| 2570 | |
| 2571 | ha->fw_dump->header_size = |
| 2572 | htonl(offsetof(struct qla2xxx_fw_dump, isp)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2573 | } |
| 2574 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2575 | static int |
| 2576 | qla81xx_mpi_sync(scsi_qla_host_t *vha) |
| 2577 | { |
| 2578 | #define MPS_MASK 0xe0 |
| 2579 | int rval; |
| 2580 | uint16_t dc; |
| 2581 | uint32_t dw; |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2582 | |
| 2583 | if (!IS_QLA81XX(vha->hw)) |
| 2584 | return QLA_SUCCESS; |
| 2585 | |
| 2586 | rval = qla2x00_write_ram_word(vha, 0x7c00, 1); |
| 2587 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2588 | ql_log(ql_log_warn, vha, 0x0105, |
| 2589 | "Unable to acquire semaphore.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2590 | goto done; |
| 2591 | } |
| 2592 | |
| 2593 | pci_read_config_word(vha->hw->pdev, 0x54, &dc); |
| 2594 | rval = qla2x00_read_ram_word(vha, 0x7a15, &dw); |
| 2595 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2596 | ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2597 | goto done_release; |
| 2598 | } |
| 2599 | |
| 2600 | dc &= MPS_MASK; |
| 2601 | if (dc == (dw & MPS_MASK)) |
| 2602 | goto done_release; |
| 2603 | |
| 2604 | dw &= ~MPS_MASK; |
| 2605 | dw |= dc; |
| 2606 | rval = qla2x00_write_ram_word(vha, 0x7a15, dw); |
| 2607 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2608 | ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2609 | } |
| 2610 | |
| 2611 | done_release: |
| 2612 | rval = qla2x00_write_ram_word(vha, 0x7c00, 0); |
| 2613 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2614 | ql_log(ql_log_warn, vha, 0x006d, |
| 2615 | "Unable to release semaphore.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2616 | } |
| 2617 | |
| 2618 | done: |
| 2619 | return rval; |
| 2620 | } |
| 2621 | |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2622 | int |
| 2623 | qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req) |
| 2624 | { |
| 2625 | /* Don't try to reallocate the array */ |
| 2626 | if (req->outstanding_cmds) |
| 2627 | return QLA_SUCCESS; |
| 2628 | |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 2629 | if (!IS_FWI2_CAPABLE(ha)) |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2630 | req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS; |
| 2631 | else { |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 2632 | if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count) |
| 2633 | req->num_outstanding_cmds = ha->cur_fw_xcb_count; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2634 | else |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 2635 | req->num_outstanding_cmds = ha->cur_fw_iocb_count; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2636 | } |
| 2637 | |
| 2638 | req->outstanding_cmds = kzalloc(sizeof(srb_t *) * |
| 2639 | req->num_outstanding_cmds, GFP_KERNEL); |
| 2640 | |
| 2641 | if (!req->outstanding_cmds) { |
| 2642 | /* |
| 2643 | * Try to allocate a minimal size just so we can get through |
| 2644 | * initialization. |
| 2645 | */ |
| 2646 | req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS; |
| 2647 | req->outstanding_cmds = kzalloc(sizeof(srb_t *) * |
| 2648 | req->num_outstanding_cmds, GFP_KERNEL); |
| 2649 | |
| 2650 | if (!req->outstanding_cmds) { |
| 2651 | ql_log(ql_log_fatal, NULL, 0x0126, |
| 2652 | "Failed to allocate memory for " |
| 2653 | "outstanding_cmds for req_que %p.\n", req); |
| 2654 | req->num_outstanding_cmds = 0; |
| 2655 | return QLA_FUNCTION_FAILED; |
| 2656 | } |
| 2657 | } |
| 2658 | |
| 2659 | return QLA_SUCCESS; |
| 2660 | } |
| 2661 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2662 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2663 | * qla2x00_setup_chip() - Load and start RISC firmware. |
| 2664 | * @ha: HA context |
| 2665 | * |
| 2666 | * Returns 0 on success. |
| 2667 | */ |
| 2668 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2669 | qla2x00_setup_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2670 | { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2671 | int rval; |
| 2672 | uint32_t srisc_address = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2673 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 2674 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 2675 | unsigned long flags; |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 2676 | uint16_t fw_major_version; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 2677 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 2678 | if (IS_P3P_TYPE(ha)) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2679 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 2680 | if (rval == QLA_SUCCESS) { |
| 2681 | qla2x00_stop_firmware(vha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2682 | goto enable_82xx_npiv; |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 2683 | } else |
Giridhar Malavali | b963752 | 2010-05-28 15:08:15 -0700 | [diff] [blame] | 2684 | goto failed; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2685 | } |
| 2686 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 2687 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 2688 | /* Disable SRAM, Instruction RAM and GP RAM parity. */ |
| 2689 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2690 | WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0)); |
| 2691 | RD_REG_WORD(®->hccr); |
| 2692 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2693 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2694 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2695 | qla81xx_mpi_sync(vha); |
| 2696 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2697 | /* Load firmware sequences */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2698 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2699 | if (rval == QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2700 | ql_dbg(ql_dbg_init, vha, 0x00c9, |
| 2701 | "Verifying Checksum of loaded RISC code.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2702 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2703 | rval = qla2x00_verify_checksum(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | if (rval == QLA_SUCCESS) { |
| 2705 | /* Start firmware execution. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2706 | ql_dbg(ql_dbg_init, vha, 0x00ca, |
| 2707 | "Starting firmware.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2708 | |
Himanshu Madhani | b0d6cab | 2015-12-17 14:56:56 -0500 | [diff] [blame] | 2709 | if (ql2xexlogins) |
| 2710 | ha->flags.exlogins_enabled = 1; |
| 2711 | |
Himanshu Madhani | 2f56a7f | 2015-12-17 14:56:57 -0500 | [diff] [blame] | 2712 | if (ql2xexchoffld) |
| 2713 | ha->flags.exchoffld_enabled = 1; |
| 2714 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2715 | rval = qla2x00_execute_fw(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2716 | /* Retrieve firmware information. */ |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 2717 | if (rval == QLA_SUCCESS) { |
Himanshu Madhani | b0d6cab | 2015-12-17 14:56:56 -0500 | [diff] [blame] | 2718 | rval = qla2x00_set_exlogins_buffer(vha); |
| 2719 | if (rval != QLA_SUCCESS) |
| 2720 | goto failed; |
| 2721 | |
Himanshu Madhani | 2f56a7f | 2015-12-17 14:56:57 -0500 | [diff] [blame] | 2722 | rval = qla2x00_set_exchoffld_buffer(vha); |
| 2723 | if (rval != QLA_SUCCESS) |
| 2724 | goto failed; |
| 2725 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2726 | enable_82xx_npiv: |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 2727 | fw_major_version = ha->fw_major_version; |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 2728 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | 3173167 | 2011-08-16 11:31:54 -0700 | [diff] [blame] | 2729 | qla82xx_check_md_needed(vha); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2730 | else |
| 2731 | rval = qla2x00_get_fw_version(vha); |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 2732 | if (rval != QLA_SUCCESS) |
| 2733 | goto failed; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2734 | ha->flags.npiv_supported = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2735 | if (IS_QLA2XXX_MIDTYPE(ha) && |
Mike Hernandez | 946fb89 | 2008-08-13 21:36:59 -0700 | [diff] [blame] | 2736 | (ha->fw_attributes & BIT_2)) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2737 | ha->flags.npiv_supported = 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 2738 | if ((!ha->max_npiv_vports) || |
| 2739 | ((ha->max_npiv_vports + 1) % |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 2740 | MIN_MULTI_ID_FABRIC)) |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 2741 | ha->max_npiv_vports = |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 2742 | MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 2743 | } |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 2744 | qla2x00_get_resource_cnts(vha); |
Andrew Vasquez | d743de6 | 2009-03-24 09:08:15 -0700 | [diff] [blame] | 2745 | |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2746 | /* |
| 2747 | * Allocate the array of outstanding commands |
| 2748 | * now that we know the firmware resources. |
| 2749 | */ |
| 2750 | rval = qla2x00_alloc_outstanding_cmds(ha, |
| 2751 | vha->req); |
| 2752 | if (rval != QLA_SUCCESS) |
| 2753 | goto failed; |
| 2754 | |
Saurav Kashyap | be5ea3c | 2011-11-18 09:02:11 -0800 | [diff] [blame] | 2755 | if (!fw_major_version && ql2xallocfwdump |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 2756 | && !(IS_P3P_TYPE(ha))) |
Giridhar Malavali | 08de284 | 2011-08-16 11:31:44 -0700 | [diff] [blame] | 2757 | qla2x00_alloc_fw_dump(vha); |
Chad Dupuis | 3b6e5b9 | 2013-10-30 03:38:09 -0400 | [diff] [blame] | 2758 | } else { |
| 2759 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2760 | } |
| 2761 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2762 | ql_log(ql_log_fatal, vha, 0x00cd, |
| 2763 | "ISP Firmware failed checksum.\n"); |
| 2764 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2765 | } |
Andrew Vasquez | c74d88a | 2012-08-22 14:21:19 -0400 | [diff] [blame] | 2766 | } else |
| 2767 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2768 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 2769 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 2770 | /* Enable proper parity. */ |
| 2771 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2772 | if (IS_QLA2300(ha)) |
| 2773 | /* SRAM parity */ |
| 2774 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1); |
| 2775 | else |
| 2776 | /* SRAM, Instruction RAM and GP RAM parity */ |
| 2777 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7); |
| 2778 | RD_REG_WORD(®->hccr); |
| 2779 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2780 | } |
| 2781 | |
Chad Dupuis | f3982d8 | 2014-09-25 05:16:57 -0400 | [diff] [blame] | 2782 | if (IS_QLA27XX(ha)) |
| 2783 | ha->flags.fac_supported = 1; |
| 2784 | else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) { |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 2785 | uint32_t size; |
| 2786 | |
| 2787 | rval = qla81xx_fac_get_sector_size(vha, &size); |
| 2788 | if (rval == QLA_SUCCESS) { |
| 2789 | ha->flags.fac_supported = 1; |
| 2790 | ha->fdt_block_size = size << 2; |
| 2791 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2792 | ql_log(ql_log_warn, vha, 0x00ce, |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 2793 | "Unsupported FAC firmware (%d.%02d.%02d).\n", |
| 2794 | ha->fw_major_version, ha->fw_minor_version, |
| 2795 | ha->fw_subminor_version); |
Joe Carnuccio | 1ca60e3 | 2014-02-26 04:15:02 -0500 | [diff] [blame] | 2796 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2797 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2798 | ha->flags.fac_supported = 0; |
| 2799 | rval = QLA_SUCCESS; |
| 2800 | } |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 2801 | } |
| 2802 | } |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 2803 | failed: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2805 | ql_log(ql_log_fatal, vha, 0x00cf, |
| 2806 | "Setup chip ****FAILED****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2807 | } |
| 2808 | |
| 2809 | return (rval); |
| 2810 | } |
| 2811 | |
| 2812 | /** |
| 2813 | * qla2x00_init_response_q_entries() - Initializes response queue entries. |
| 2814 | * @ha: HA context |
| 2815 | * |
| 2816 | * Beginning of request ring has initialization control block already built |
| 2817 | * by nvram config routine. |
| 2818 | * |
| 2819 | * Returns 0 on success. |
| 2820 | */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2821 | void |
| 2822 | qla2x00_init_response_q_entries(struct rsp_que *rsp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2823 | { |
| 2824 | uint16_t cnt; |
| 2825 | response_t *pkt; |
| 2826 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 2827 | rsp->ring_ptr = rsp->ring; |
| 2828 | rsp->ring_index = 0; |
| 2829 | rsp->status_srb = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2830 | pkt = rsp->ring_ptr; |
| 2831 | for (cnt = 0; cnt < rsp->length; cnt++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 | pkt->signature = RESPONSE_PROCESSED; |
| 2833 | pkt++; |
| 2834 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | } |
| 2836 | |
| 2837 | /** |
| 2838 | * qla2x00_update_fw_options() - Read and process firmware options. |
| 2839 | * @ha: HA context |
| 2840 | * |
| 2841 | * Returns 0 on success. |
| 2842 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2843 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2844 | qla2x00_update_fw_options(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2845 | { |
| 2846 | uint16_t swing, emphasis, tx_sens, rx_sens; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2847 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | |
| 2849 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2850 | qla2x00_get_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2851 | |
| 2852 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
| 2853 | return; |
| 2854 | |
| 2855 | /* Serial Link options. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2856 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115, |
| 2857 | "Serial link options.\n"); |
| 2858 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109, |
| 2859 | (uint8_t *)&ha->fw_seriallink_options, |
| 2860 | sizeof(ha->fw_seriallink_options)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2861 | |
| 2862 | ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING; |
| 2863 | if (ha->fw_seriallink_options[3] & BIT_2) { |
| 2864 | ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING; |
| 2865 | |
| 2866 | /* 1G settings */ |
| 2867 | swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0); |
| 2868 | emphasis = (ha->fw_seriallink_options[2] & |
| 2869 | (BIT_4 | BIT_3)) >> 3; |
| 2870 | tx_sens = ha->fw_seriallink_options[0] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2871 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | rx_sens = (ha->fw_seriallink_options[0] & |
| 2873 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 2874 | ha->fw_options[10] = (emphasis << 14) | (swing << 8); |
| 2875 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 2876 | if (rx_sens == 0x0) |
| 2877 | rx_sens = 0x3; |
| 2878 | ha->fw_options[10] |= (tx_sens << 4) | rx_sens; |
| 2879 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 2880 | ha->fw_options[10] |= BIT_5 | |
| 2881 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 2882 | (tx_sens & (BIT_1 | BIT_0)); |
| 2883 | |
| 2884 | /* 2G settings */ |
| 2885 | swing = (ha->fw_seriallink_options[2] & |
| 2886 | (BIT_7 | BIT_6 | BIT_5)) >> 5; |
| 2887 | emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0); |
| 2888 | tx_sens = ha->fw_seriallink_options[1] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2889 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2890 | rx_sens = (ha->fw_seriallink_options[1] & |
| 2891 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 2892 | ha->fw_options[11] = (emphasis << 14) | (swing << 8); |
| 2893 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 2894 | if (rx_sens == 0x0) |
| 2895 | rx_sens = 0x3; |
| 2896 | ha->fw_options[11] |= (tx_sens << 4) | rx_sens; |
| 2897 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 2898 | ha->fw_options[11] |= BIT_5 | |
| 2899 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 2900 | (tx_sens & (BIT_1 | BIT_0)); |
| 2901 | } |
| 2902 | |
| 2903 | /* FCP2 options. */ |
| 2904 | /* Return command IOCBs without waiting for an ABTS to complete. */ |
| 2905 | ha->fw_options[3] |= BIT_13; |
| 2906 | |
| 2907 | /* LED scheme. */ |
| 2908 | if (ha->flags.enable_led_scheme) |
| 2909 | ha->fw_options[2] |= BIT_12; |
| 2910 | |
andrew.vasquez@qlogic.com | 48c02fd | 2006-03-09 14:27:18 -0800 | [diff] [blame] | 2911 | /* Detect ISP6312. */ |
| 2912 | if (IS_QLA6312(ha)) |
| 2913 | ha->fw_options[2] |= BIT_13; |
| 2914 | |
Giridhar Malavali | 088d09d | 2016-07-06 11:14:20 -0400 | [diff] [blame] | 2915 | /* Set Retry FLOGI in case of P2P connection */ |
| 2916 | if (ha->operating_mode == P2P) { |
| 2917 | ha->fw_options[2] |= BIT_3; |
| 2918 | ql_dbg(ql_dbg_disc, vha, 0x2100, |
| 2919 | "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n", |
| 2920 | __func__, ha->fw_options[2]); |
| 2921 | } |
| 2922 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2923 | /* Update firmware options. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2924 | qla2x00_set_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2925 | } |
| 2926 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2927 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2928 | qla24xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2929 | { |
| 2930 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2931 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2932 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 2933 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2934 | return; |
| 2935 | |
Himanshu Madhani | f198caf | 2016-01-27 12:03:30 -0500 | [diff] [blame] | 2936 | /* Hold status IOCBs until ABTS response received. */ |
| 2937 | if (ql2xfwholdabts) |
| 2938 | ha->fw_options[3] |= BIT_12; |
| 2939 | |
Giridhar Malavali | 088d09d | 2016-07-06 11:14:20 -0400 | [diff] [blame] | 2940 | /* Set Retry FLOGI in case of P2P connection */ |
| 2941 | if (ha->operating_mode == P2P) { |
| 2942 | ha->fw_options[2] |= BIT_3; |
| 2943 | ql_dbg(ql_dbg_disc, vha, 0x2101, |
| 2944 | "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n", |
| 2945 | __func__, ha->fw_options[2]); |
| 2946 | } |
| 2947 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 2948 | /* Move PUREX, ABTS RX & RIDA to ATIOQ */ |
| 2949 | if (ql2xmvasynctoatio) { |
| 2950 | if (qla_tgt_mode_enabled(vha) || |
| 2951 | qla_dual_mode_enabled(vha)) |
| 2952 | ha->fw_options[2] |= BIT_11; |
| 2953 | else |
| 2954 | ha->fw_options[2] &= ~BIT_11; |
| 2955 | } |
| 2956 | |
| 2957 | ql_dbg(ql_dbg_init, vha, 0xffff, |
| 2958 | "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n", |
| 2959 | __func__, ha->fw_options[1], ha->fw_options[2], |
| 2960 | ha->fw_options[3], vha->host->active_mode); |
| 2961 | qla2x00_set_fw_options(vha, ha->fw_options); |
| 2962 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2963 | /* Update Serial Link options. */ |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 2964 | if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2965 | return; |
| 2966 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2967 | rval = qla2x00_set_serdes_params(vha, |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 2968 | le16_to_cpu(ha->fw_seriallink_options24[1]), |
| 2969 | le16_to_cpu(ha->fw_seriallink_options24[2]), |
| 2970 | le16_to_cpu(ha->fw_seriallink_options24[3])); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2971 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2972 | ql_log(ql_log_warn, vha, 0x0104, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2973 | "Unable to update Serial Link options (%x).\n", rval); |
| 2974 | } |
| 2975 | } |
| 2976 | |
| 2977 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2978 | qla2x00_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2979 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2980 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2981 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2982 | struct req_que *req = ha->req_q_map[0]; |
| 2983 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2984 | |
| 2985 | /* Setup ring parameters in initialization control block. */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2986 | ha->init_cb->request_q_outpointer = cpu_to_le16(0); |
| 2987 | ha->init_cb->response_q_inpointer = cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2988 | ha->init_cb->request_q_length = cpu_to_le16(req->length); |
| 2989 | ha->init_cb->response_q_length = cpu_to_le16(rsp->length); |
| 2990 | ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 2991 | ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 2992 | ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 2993 | 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] | 2994 | |
| 2995 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0); |
| 2996 | WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0); |
| 2997 | WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0); |
| 2998 | WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0); |
| 2999 | RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */ |
| 3000 | } |
| 3001 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3002 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3003 | qla24xx_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3004 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3005 | struct qla_hw_data *ha = vha->hw; |
Bart Van Assche | 118e2ef | 2015-07-09 07:24:27 -0700 | [diff] [blame] | 3006 | device_reg_t *reg = ISP_QUE_REG(ha, 0); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3007 | struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp; |
| 3008 | struct qla_msix_entry *msix; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3009 | struct init_cb_24xx *icb; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3010 | uint16_t rid = 0; |
| 3011 | struct req_que *req = ha->req_q_map[0]; |
| 3012 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3013 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3014 | /* Setup ring parameters in initialization control block. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3015 | icb = (struct init_cb_24xx *)ha->init_cb; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3016 | icb->request_q_outpointer = cpu_to_le16(0); |
| 3017 | icb->response_q_inpointer = cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3018 | icb->request_q_length = cpu_to_le16(req->length); |
| 3019 | icb->response_q_length = cpu_to_le16(rsp->length); |
| 3020 | icb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 3021 | icb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 3022 | icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 3023 | icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3024 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3025 | /* Setup ATIO queue dma pointers for target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3026 | icb->atio_q_inpointer = cpu_to_le16(0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3027 | icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length); |
| 3028 | icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma)); |
| 3029 | icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma)); |
| 3030 | |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3031 | if (IS_SHADOW_REG_CAPABLE(ha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3032 | icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29); |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3033 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 3034 | if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3035 | icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS); |
| 3036 | icb->rid = cpu_to_le16(rid); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3037 | if (ha->flags.msix_enabled) { |
| 3038 | msix = &ha->msix_entries[1]; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3039 | ql_dbg(ql_dbg_init, vha, 0x00fd, |
| 3040 | "Registering vector 0x%x for base que.\n", |
| 3041 | msix->entry); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3042 | icb->msix = cpu_to_le16(msix->entry); |
| 3043 | } |
| 3044 | /* Use alternate PCI bus number */ |
| 3045 | if (MSB(rid)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3046 | icb->firmware_options_2 |= cpu_to_le32(BIT_19); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3047 | /* Use alternate PCI devfn */ |
| 3048 | if (LSB(rid)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3049 | icb->firmware_options_2 |= cpu_to_le32(BIT_18); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3050 | |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 3051 | /* Use Disable MSIX Handshake mode for capable adapters */ |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3052 | if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) && |
| 3053 | (ha->flags.msix_enabled)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3054 | icb->firmware_options_2 &= cpu_to_le32(~BIT_22); |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 3055 | ha->flags.disable_msix_handshake = 1; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3056 | ql_dbg(ql_dbg_init, vha, 0x00fe, |
| 3057 | "MSIX Handshake Disable Mode turned on.\n"); |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 3058 | } else { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3059 | icb->firmware_options_2 |= cpu_to_le32(BIT_22); |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 3060 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3061 | icb->firmware_options_2 |= cpu_to_le32(BIT_23); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3062 | |
| 3063 | WRT_REG_DWORD(®->isp25mq.req_q_in, 0); |
| 3064 | WRT_REG_DWORD(®->isp25mq.req_q_out, 0); |
| 3065 | WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0); |
| 3066 | WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0); |
| 3067 | } else { |
| 3068 | WRT_REG_DWORD(®->isp24.req_q_in, 0); |
| 3069 | WRT_REG_DWORD(®->isp24.req_q_out, 0); |
| 3070 | WRT_REG_DWORD(®->isp24.rsp_q_in, 0); |
| 3071 | WRT_REG_DWORD(®->isp24.rsp_q_out, 0); |
| 3072 | } |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 3073 | qlt_24xx_config_rings(vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3074 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3075 | /* PCI posting */ |
| 3076 | RD_REG_DWORD(&ioreg->hccr); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3077 | } |
| 3078 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3079 | /** |
| 3080 | * qla2x00_init_rings() - Initializes firmware. |
| 3081 | * @ha: HA context |
| 3082 | * |
| 3083 | * Beginning of request ring has initialization control block already built |
| 3084 | * by nvram config routine. |
| 3085 | * |
| 3086 | * Returns 0 on success. |
| 3087 | */ |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3088 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3089 | qla2x00_init_rings(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3090 | { |
| 3091 | int rval; |
| 3092 | unsigned long flags = 0; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3093 | int cnt, que; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3094 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3095 | struct req_que *req; |
| 3096 | struct rsp_que *rsp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3097 | struct mid_init_cb_24xx *mid_init_cb = |
| 3098 | (struct mid_init_cb_24xx *) ha->init_cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3099 | |
| 3100 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3101 | |
| 3102 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 3103 | for (que = 0; que < ha->max_req_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3104 | req = ha->req_q_map[que]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 3105 | if (!req || !test_bit(que, ha->req_qid_map)) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3106 | continue; |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3107 | req->out_ptr = (void *)(req->ring + req->length); |
| 3108 | *req->out_ptr = 0; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 3109 | for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3110 | req->outstanding_cmds[cnt] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3111 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 3112 | req->current_outstanding_cmd = 1; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3113 | |
| 3114 | /* Initialize firmware. */ |
| 3115 | req->ring_ptr = req->ring; |
| 3116 | req->ring_index = 0; |
| 3117 | req->cnt = req->length; |
| 3118 | } |
| 3119 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 3120 | for (que = 0; que < ha->max_rsp_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3121 | rsp = ha->rsp_q_map[que]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 3122 | if (!rsp || !test_bit(que, ha->rsp_qid_map)) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3123 | continue; |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3124 | rsp->in_ptr = (void *)(rsp->ring + rsp->length); |
| 3125 | *rsp->in_ptr = 0; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3126 | /* Initialize response queue entries */ |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3127 | if (IS_QLAFX00(ha)) |
| 3128 | qlafx00_init_response_q_entries(rsp); |
| 3129 | else |
| 3130 | qla2x00_init_response_q_entries(rsp); |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3131 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3132 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3133 | ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; |
| 3134 | ha->tgt.atio_ring_index = 0; |
| 3135 | /* Initialize ATIO queue entries */ |
| 3136 | qlt_init_atio_q_entries(vha); |
| 3137 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3138 | ha->isp_ops->config_rings(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3139 | |
| 3140 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3141 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3142 | ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n"); |
| 3143 | |
| 3144 | if (IS_QLAFX00(ha)) { |
| 3145 | rval = qlafx00_init_firmware(vha, ha->init_cb_size); |
| 3146 | goto next_check; |
| 3147 | } |
| 3148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3149 | /* Update any ISP specific firmware options before initialization. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3150 | ha->isp_ops->update_fw_options(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 3152 | if (ha->flags.npiv_supported) { |
Saurav Kashyap | 45980cc | 2012-08-22 14:21:21 -0400 | [diff] [blame] | 3153 | if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha)) |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 3154 | ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | c48339d | 2008-01-17 09:02:19 -0800 | [diff] [blame] | 3155 | mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports); |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 3156 | } |
| 3157 | |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 3158 | if (IS_FWI2_CAPABLE(ha)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3159 | mid_init_cb->options = cpu_to_le16(BIT_1); |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 3160 | mid_init_cb->init_cb.execution_throttle = |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3161 | cpu_to_le16(ha->cur_fw_xcb_count); |
Joe Carnuccio | 40f3862 | 2016-07-06 11:14:28 -0400 | [diff] [blame] | 3162 | ha->flags.dport_enabled = |
| 3163 | (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0; |
| 3164 | ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n", |
| 3165 | (ha->flags.dport_enabled) ? "enabled" : "disabled"); |
| 3166 | /* FA-WWPN Status */ |
Himanshu Madhani | 2486c62 | 2014-09-25 05:17:00 -0400 | [diff] [blame] | 3167 | ha->flags.fawwpn_enabled = |
Joe Carnuccio | 40f3862 | 2016-07-06 11:14:28 -0400 | [diff] [blame] | 3168 | (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0; |
Himanshu Madhani | 2486c62 | 2014-09-25 05:17:00 -0400 | [diff] [blame] | 3169 | ql_dbg(ql_dbg_init, vha, 0x0141, "FA-WWPN Support: %s.\n", |
| 3170 | (ha->flags.fawwpn_enabled) ? "enabled" : "disabled"); |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 3171 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3172 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3173 | rval = qla2x00_init_firmware(vha, ha->init_cb_size); |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3174 | next_check: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3175 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3176 | ql_log(ql_log_fatal, vha, 0x00d2, |
| 3177 | "Init Firmware **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3178 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3179 | ql_dbg(ql_dbg_init, vha, 0x00d3, |
| 3180 | "Init Firmware -- success.\n"); |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 3181 | ha->flags.fw_started = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | } |
| 3183 | |
| 3184 | return (rval); |
| 3185 | } |
| 3186 | |
| 3187 | /** |
| 3188 | * qla2x00_fw_ready() - Waits for firmware ready. |
| 3189 | * @ha: HA context |
| 3190 | * |
| 3191 | * Returns 0 on success. |
| 3192 | */ |
| 3193 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3194 | qla2x00_fw_ready(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | { |
| 3196 | int rval; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3197 | unsigned long wtime, mtime, cs84xx_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | uint16_t min_wait; /* Minimum wait time if loop is down */ |
| 3199 | uint16_t wait_time; /* Wait time if loop is coming ready */ |
Joe Carnuccio | b5a340d | 2014-09-25 05:16:48 -0400 | [diff] [blame] | 3200 | uint16_t state[6]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3201 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3202 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3203 | if (IS_QLAFX00(vha->hw)) |
| 3204 | return qlafx00_fw_ready(vha); |
| 3205 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | rval = QLA_SUCCESS; |
| 3207 | |
Chad Dupuis | 3346149 | 2015-04-09 14:59:57 -0400 | [diff] [blame] | 3208 | /* Time to wait for loop down */ |
| 3209 | if (IS_P3P_TYPE(ha)) |
| 3210 | min_wait = 30; |
| 3211 | else |
| 3212 | min_wait = 20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | |
| 3214 | /* |
| 3215 | * Firmware should take at most one RATOV to login, plus 5 seconds for |
| 3216 | * our own processing. |
| 3217 | */ |
| 3218 | if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) { |
| 3219 | wait_time = min_wait; |
| 3220 | } |
| 3221 | |
| 3222 | /* Min wait time if loop down */ |
| 3223 | mtime = jiffies + (min_wait * HZ); |
| 3224 | |
| 3225 | /* wait time before firmware ready */ |
| 3226 | wtime = jiffies + (wait_time * HZ); |
| 3227 | |
| 3228 | /* Wait for ISP to finish LIP */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3229 | if (!vha->flags.init_done) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3230 | ql_log(ql_log_info, vha, 0x801e, |
| 3231 | "Waiting for LIP to complete.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3232 | |
| 3233 | do { |
Andrew Vasquez | 5b93903 | 2012-11-21 02:40:26 -0500 | [diff] [blame] | 3234 | memset(state, -1, sizeof(state)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3235 | rval = qla2x00_get_firmware_state(vha, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3236 | if (rval == QLA_SUCCESS) { |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3237 | if (state[0] < FSTATE_LOSS_OF_SYNC) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3238 | vha->device_flags &= ~DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3239 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3240 | if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3241 | ql_dbg(ql_dbg_taskm, vha, 0x801f, |
| 3242 | "fw_state=%x 84xx=%x.\n", state[0], |
| 3243 | state[2]); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3244 | if ((state[2] & FSTATE_LOGGED_IN) && |
| 3245 | (state[2] & FSTATE_WAITING_FOR_VERIFY)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3246 | ql_dbg(ql_dbg_taskm, vha, 0x8028, |
| 3247 | "Sending verify iocb.\n"); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3248 | |
| 3249 | cs84xx_time = jiffies; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3250 | rval = qla84xx_init_chip(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3251 | if (rval != QLA_SUCCESS) { |
| 3252 | ql_log(ql_log_warn, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 3253 | vha, 0x8007, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3254 | "Init chip failed.\n"); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3255 | break; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3256 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3257 | |
| 3258 | /* Add time taken to initialize. */ |
| 3259 | cs84xx_time = jiffies - cs84xx_time; |
| 3260 | wtime += cs84xx_time; |
| 3261 | mtime += cs84xx_time; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 3262 | ql_dbg(ql_dbg_taskm, vha, 0x8008, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3263 | "Increasing wait time by %ld. " |
| 3264 | "New time %ld.\n", cs84xx_time, |
| 3265 | wtime); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3266 | } |
| 3267 | } else if (state[0] == FSTATE_READY) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3268 | ql_dbg(ql_dbg_taskm, vha, 0x8037, |
| 3269 | "F/W Ready - OK.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3271 | qla2x00_get_retry_cnt(vha, &ha->retry_count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3272 | &ha->login_timeout, &ha->r_a_tov); |
| 3273 | |
| 3274 | rval = QLA_SUCCESS; |
| 3275 | break; |
| 3276 | } |
| 3277 | |
| 3278 | rval = QLA_FUNCTION_FAILED; |
| 3279 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3280 | if (atomic_read(&vha->loop_down_timer) && |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3281 | state[0] != FSTATE_READY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3282 | /* Loop down. Timeout on min_wait for states |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3283 | * other than Wait for Login. |
| 3284 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3285 | if (time_after_eq(jiffies, mtime)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3286 | ql_log(ql_log_info, vha, 0x8038, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3287 | "Cable is unplugged...\n"); |
| 3288 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3289 | vha->device_flags |= DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3290 | break; |
| 3291 | } |
| 3292 | } |
| 3293 | } else { |
| 3294 | /* Mailbox cmd failed. Timeout on min_wait. */ |
Santosh Vernekar | cdbb0a4f | 2010-05-28 15:08:25 -0700 | [diff] [blame] | 3295 | if (time_after_eq(jiffies, mtime) || |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 3296 | ha->flags.isp82xx_fw_hung) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3297 | break; |
| 3298 | } |
| 3299 | |
| 3300 | if (time_after_eq(jiffies, wtime)) |
| 3301 | break; |
| 3302 | |
| 3303 | /* Delay for a while */ |
| 3304 | msleep(500); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3305 | } while (1); |
| 3306 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3307 | ql_dbg(ql_dbg_taskm, vha, 0x803a, |
Joe Carnuccio | b5a340d | 2014-09-25 05:16:48 -0400 | [diff] [blame] | 3308 | "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0], |
| 3309 | state[1], state[2], state[3], state[4], state[5], jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3310 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 3311 | if (rval && !(vha->device_flags & DFLG_NO_CABLE)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3312 | ql_log(ql_log_warn, vha, 0x803b, |
| 3313 | "Firmware ready **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3314 | } |
| 3315 | |
| 3316 | return (rval); |
| 3317 | } |
| 3318 | |
| 3319 | /* |
| 3320 | * qla2x00_configure_hba |
| 3321 | * Setup adapter context. |
| 3322 | * |
| 3323 | * Input: |
| 3324 | * ha = adapter state pointer. |
| 3325 | * |
| 3326 | * Returns: |
| 3327 | * 0 = success |
| 3328 | * |
| 3329 | * Context: |
| 3330 | * Kernel context. |
| 3331 | */ |
| 3332 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3333 | qla2x00_configure_hba(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3334 | { |
| 3335 | int rval; |
| 3336 | uint16_t loop_id; |
| 3337 | uint16_t topo; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3338 | uint16_t sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3339 | uint8_t al_pa; |
| 3340 | uint8_t area; |
| 3341 | uint8_t domain; |
| 3342 | char connect_type[22]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3343 | struct qla_hw_data *ha = vha->hw; |
Joe Carnuccio | 61e1b26 | 2013-02-08 01:57:48 -0500 | [diff] [blame] | 3344 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 3345 | port_id_t id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3346 | |
| 3347 | /* Get host addresses. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3348 | rval = qla2x00_get_adapter_id(vha, |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3349 | &loop_id, &al_pa, &area, &domain, &topo, &sw_cap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | if (rval != QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3351 | if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) || |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3352 | IS_CNA_CAPABLE(ha) || |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 3353 | (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3354 | ql_dbg(ql_dbg_disc, vha, 0x2008, |
| 3355 | "Loop is in a transition state.\n"); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 3356 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3357 | ql_log(ql_log_warn, vha, 0x2009, |
| 3358 | "Unable to get host loop ID.\n"); |
Joe Carnuccio | 61e1b26 | 2013-02-08 01:57:48 -0500 | [diff] [blame] | 3359 | if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) && |
| 3360 | (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) { |
| 3361 | ql_log(ql_log_warn, vha, 0x1151, |
| 3362 | "Doing link init.\n"); |
| 3363 | if (qla24xx_link_initialize(vha) == QLA_SUCCESS) |
| 3364 | return rval; |
| 3365 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3366 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 3367 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3368 | return (rval); |
| 3369 | } |
| 3370 | |
| 3371 | if (topo == 4) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3372 | ql_log(ql_log_info, vha, 0x200a, |
| 3373 | "Cannot get topology - retrying.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3374 | return (QLA_FUNCTION_FAILED); |
| 3375 | } |
| 3376 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3377 | vha->loop_id = loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3378 | |
| 3379 | /* initialize */ |
| 3380 | ha->min_external_loopid = SNS_FIRST_LOOP_ID; |
| 3381 | ha->operating_mode = LOOP; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3382 | ha->switch_cap = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3383 | |
| 3384 | switch (topo) { |
| 3385 | case 0: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3386 | ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3387 | ha->current_topology = ISP_CFG_NL; |
| 3388 | strcpy(connect_type, "(Loop)"); |
| 3389 | break; |
| 3390 | |
| 3391 | case 1: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3392 | ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n"); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3393 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3394 | ha->current_topology = ISP_CFG_FL; |
| 3395 | strcpy(connect_type, "(FL_Port)"); |
| 3396 | break; |
| 3397 | |
| 3398 | case 2: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3399 | 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] | 3400 | ha->operating_mode = P2P; |
| 3401 | ha->current_topology = ISP_CFG_N; |
| 3402 | strcpy(connect_type, "(N_Port-to-N_Port)"); |
| 3403 | break; |
| 3404 | |
| 3405 | case 3: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3406 | 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] | 3407 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3408 | ha->operating_mode = P2P; |
| 3409 | ha->current_topology = ISP_CFG_F; |
| 3410 | strcpy(connect_type, "(F_Port)"); |
| 3411 | break; |
| 3412 | |
| 3413 | default: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3414 | ql_dbg(ql_dbg_disc, vha, 0x200f, |
| 3415 | "HBA in unknown topology %x, using NL.\n", topo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3416 | ha->current_topology = ISP_CFG_NL; |
| 3417 | strcpy(connect_type, "(Loop)"); |
| 3418 | break; |
| 3419 | } |
| 3420 | |
| 3421 | /* Save Host port and loop ID. */ |
| 3422 | /* byte order - Big Endian */ |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 3423 | id.b.domain = domain; |
| 3424 | id.b.area = area; |
| 3425 | id.b.al_pa = al_pa; |
| 3426 | id.b.rsvd_1 = 0; |
| 3427 | qlt_update_host_map(vha, id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3428 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3429 | if (!vha->flags.init_done) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3430 | ql_log(ql_log_info, vha, 0x2010, |
| 3431 | "Topology - %s, Host Loop address 0x%x.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3432 | connect_type, vha->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3433 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3434 | return(rval); |
| 3435 | } |
| 3436 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3437 | inline void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3438 | qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len, |
| 3439 | char *def) |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3440 | { |
| 3441 | char *st, *en; |
| 3442 | uint16_t index; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3443 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | ab67114 | 2009-08-25 11:36:17 -0700 | [diff] [blame] | 3444 | int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) && |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3445 | !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3446 | |
| 3447 | if (memcmp(model, BINZERO, len) != 0) { |
| 3448 | strncpy(ha->model_number, model, len); |
| 3449 | st = en = ha->model_number; |
| 3450 | en += len - 1; |
| 3451 | while (en > st) { |
| 3452 | if (*en != 0x20 && *en != 0x00) |
| 3453 | break; |
| 3454 | *en-- = '\0'; |
| 3455 | } |
| 3456 | |
| 3457 | index = (ha->pdev->subsystem_device & 0xff); |
Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 3458 | if (use_tbl && |
| 3459 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3460 | index < QLA_MODEL_NAMES) |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 3461 | strncpy(ha->model_desc, |
| 3462 | qla2x00_model_name[index * 2 + 1], |
| 3463 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3464 | } else { |
| 3465 | index = (ha->pdev->subsystem_device & 0xff); |
Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 3466 | if (use_tbl && |
| 3467 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3468 | index < QLA_MODEL_NAMES) { |
| 3469 | strcpy(ha->model_number, |
| 3470 | qla2x00_model_name[index * 2]); |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 3471 | strncpy(ha->model_desc, |
| 3472 | qla2x00_model_name[index * 2 + 1], |
| 3473 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3474 | } else { |
| 3475 | strcpy(ha->model_number, def); |
| 3476 | } |
| 3477 | } |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 3478 | if (IS_FWI2_CAPABLE(ha)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3479 | qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc, |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 3480 | sizeof(ha->model_desc)); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3481 | } |
| 3482 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3483 | /* On sparc systems, obtain port and node WWN from firmware |
| 3484 | * properties. |
| 3485 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3486 | 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] | 3487 | { |
| 3488 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3489 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3490 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 3491 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 3492 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3493 | int len; |
| 3494 | |
| 3495 | val = of_get_property(dp, "port-wwn", &len); |
| 3496 | if (val && len >= WWN_SIZE) |
| 3497 | memcpy(nv->port_name, val, WWN_SIZE); |
| 3498 | |
| 3499 | val = of_get_property(dp, "node-wwn", &len); |
| 3500 | if (val && len >= WWN_SIZE) |
| 3501 | memcpy(nv->node_name, val, WWN_SIZE); |
| 3502 | #endif |
| 3503 | } |
| 3504 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3505 | /* |
| 3506 | * NVRAM configuration for ISP 2xxx |
| 3507 | * |
| 3508 | * Input: |
| 3509 | * ha = adapter block pointer. |
| 3510 | * |
| 3511 | * Output: |
| 3512 | * initialization control block in response_ring |
| 3513 | * host adapters parameters in host adapter block |
| 3514 | * |
| 3515 | * Returns: |
| 3516 | * 0 = success. |
| 3517 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3518 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3519 | qla2x00_nvram_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3520 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3521 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3522 | uint8_t chksum = 0; |
| 3523 | uint16_t cnt; |
| 3524 | uint8_t *dptr1, *dptr2; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3525 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3526 | init_cb_t *icb = ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 3527 | nvram_t *nv = ha->nvram; |
| 3528 | uint8_t *ptr = ha->nvram; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 3529 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3530 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3531 | rval = QLA_SUCCESS; |
| 3532 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3533 | /* Determine NVRAM starting address. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3534 | ha->nvram_size = sizeof(nvram_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3535 | ha->nvram_base = 0; |
| 3536 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) |
| 3537 | if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1) |
| 3538 | ha->nvram_base = 0x80; |
| 3539 | |
| 3540 | /* Get NVRAM data and calculate checksum. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3541 | 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] | 3542 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++) |
| 3543 | chksum += *ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3544 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3545 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f, |
| 3546 | "Contents of NVRAM.\n"); |
| 3547 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110, |
| 3548 | (uint8_t *)nv, ha->nvram_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3549 | |
| 3550 | /* Bad NVRAM data, set defaults parameters. */ |
| 3551 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || |
| 3552 | nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) { |
| 3553 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3554 | ql_log(ql_log_warn, vha, 0x0064, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 3555 | "Inconsistent NVRAM " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3556 | "detected: checksum=0x%x id=%c version=0x%x.\n", |
| 3557 | chksum, nv->id[0], nv->nvram_version); |
| 3558 | ql_log(ql_log_warn, vha, 0x0065, |
| 3559 | "Falling back to " |
| 3560 | "functioning (yet invalid -- WWPN) defaults.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3561 | |
| 3562 | /* |
| 3563 | * Set default initialization control block. |
| 3564 | */ |
| 3565 | memset(nv, 0, ha->nvram_size); |
| 3566 | nv->parameter_block_version = ICB_VERSION; |
| 3567 | |
| 3568 | if (IS_QLA23XX(ha)) { |
| 3569 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 3570 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 3571 | nv->add_firmware_options[0] = BIT_5; |
| 3572 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 3573 | nv->frame_payload_size = 2048; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3574 | nv->special_options[1] = BIT_7; |
| 3575 | } else if (IS_QLA2200(ha)) { |
| 3576 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 3577 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 3578 | nv->add_firmware_options[0] = BIT_5; |
| 3579 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 3580 | nv->frame_payload_size = 1024; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3581 | } else if (IS_QLA2100(ha)) { |
| 3582 | nv->firmware_options[0] = BIT_3 | BIT_1; |
| 3583 | nv->firmware_options[1] = BIT_5; |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 3584 | nv->frame_payload_size = 1024; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3585 | } |
| 3586 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3587 | nv->max_iocb_allocation = cpu_to_le16(256); |
| 3588 | nv->execution_throttle = cpu_to_le16(16); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3589 | nv->retry_count = 8; |
| 3590 | nv->retry_delay = 1; |
| 3591 | |
| 3592 | nv->port_name[0] = 33; |
| 3593 | nv->port_name[3] = 224; |
| 3594 | nv->port_name[4] = 139; |
| 3595 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3596 | qla2xxx_nvram_wwn_from_ofw(vha, nv); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3597 | |
| 3598 | nv->login_timeout = 4; |
| 3599 | |
| 3600 | /* |
| 3601 | * Set default host adapter parameters |
| 3602 | */ |
| 3603 | nv->host_p[1] = BIT_2; |
| 3604 | nv->reset_delay = 5; |
| 3605 | nv->port_down_retry_count = 8; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3606 | nv->max_luns_per_target = cpu_to_le16(8); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3607 | nv->link_down_timeout = 60; |
| 3608 | |
| 3609 | rval = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3610 | } |
| 3611 | |
| 3612 | #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2) |
| 3613 | /* |
| 3614 | * The SN2 does not provide BIOS emulation which means you can't change |
| 3615 | * potentially bogus BIOS settings. Force the use of default settings |
| 3616 | * for link rate and frame size. Hope that the rest of the settings |
| 3617 | * are valid. |
| 3618 | */ |
| 3619 | if (ia64_platform_is("sn2")) { |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 3620 | nv->frame_payload_size = 2048; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3621 | if (IS_QLA23XX(ha)) |
| 3622 | nv->special_options[1] = BIT_7; |
| 3623 | } |
| 3624 | #endif |
| 3625 | |
| 3626 | /* Reset Initialization control block */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3627 | memset(icb, 0, ha->init_cb_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3628 | |
| 3629 | /* |
| 3630 | * Setup driver NVRAM options. |
| 3631 | */ |
| 3632 | nv->firmware_options[0] |= (BIT_6 | BIT_1); |
| 3633 | nv->firmware_options[0] &= ~(BIT_5 | BIT_4); |
| 3634 | nv->firmware_options[1] |= (BIT_5 | BIT_0); |
| 3635 | nv->firmware_options[1] &= ~BIT_4; |
| 3636 | |
| 3637 | if (IS_QLA23XX(ha)) { |
| 3638 | nv->firmware_options[0] |= BIT_2; |
| 3639 | nv->firmware_options[0] &= ~BIT_3; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3640 | nv->special_options[0] &= ~BIT_6; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3641 | nv->add_firmware_options[1] |= BIT_5 | BIT_4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3642 | |
| 3643 | if (IS_QLA2300(ha)) { |
| 3644 | if (ha->fb_rev == FPM_2310) { |
| 3645 | strcpy(ha->model_number, "QLA2310"); |
| 3646 | } else { |
| 3647 | strcpy(ha->model_number, "QLA2300"); |
| 3648 | } |
| 3649 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3650 | qla2x00_set_model_info(vha, nv->model_number, |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3651 | sizeof(nv->model_number), "QLA23xx"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3652 | } |
| 3653 | } else if (IS_QLA2200(ha)) { |
| 3654 | nv->firmware_options[0] |= BIT_2; |
| 3655 | /* |
| 3656 | * 'Point-to-point preferred, else loop' is not a safe |
| 3657 | * connection mode setting. |
| 3658 | */ |
| 3659 | if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) == |
| 3660 | (BIT_5 | BIT_4)) { |
| 3661 | /* Force 'loop preferred, else point-to-point'. */ |
| 3662 | nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4); |
| 3663 | nv->add_firmware_options[0] |= BIT_5; |
| 3664 | } |
| 3665 | strcpy(ha->model_number, "QLA22xx"); |
| 3666 | } else /*if (IS_QLA2100(ha))*/ { |
| 3667 | strcpy(ha->model_number, "QLA2100"); |
| 3668 | } |
| 3669 | |
| 3670 | /* |
| 3671 | * Copy over NVRAM RISC parameter block to initialization control block. |
| 3672 | */ |
| 3673 | dptr1 = (uint8_t *)icb; |
| 3674 | dptr2 = (uint8_t *)&nv->parameter_block_version; |
| 3675 | cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version; |
| 3676 | while (cnt--) |
| 3677 | *dptr1++ = *dptr2++; |
| 3678 | |
| 3679 | /* Copy 2nd half. */ |
| 3680 | dptr1 = (uint8_t *)icb->add_firmware_options; |
| 3681 | cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options; |
| 3682 | while (cnt--) |
| 3683 | *dptr1++ = *dptr2++; |
| 3684 | |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 3685 | /* Use alternate WWN? */ |
| 3686 | if (nv->host_p[1] & BIT_7) { |
| 3687 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 3688 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 3689 | } |
| 3690 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3691 | /* Prepare nodename */ |
| 3692 | if ((icb->firmware_options[1] & BIT_6) == 0) { |
| 3693 | /* |
| 3694 | * Firmware will apply the following mask if the nodename was |
| 3695 | * not provided. |
| 3696 | */ |
| 3697 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 3698 | icb->node_name[0] &= 0xF0; |
| 3699 | } |
| 3700 | |
| 3701 | /* |
| 3702 | * Set host adapter parameters. |
| 3703 | */ |
Saurav Kashyap | 3ce8866 | 2011-07-14 12:00:12 -0700 | [diff] [blame] | 3704 | |
| 3705 | /* |
| 3706 | * BIT_7 in the host-parameters section allows for modification to |
| 3707 | * internal driver logging. |
| 3708 | */ |
Andrew Vasquez | 0181944 | 2006-06-23 16:11:10 -0700 | [diff] [blame] | 3709 | if (nv->host_p[0] & BIT_7) |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 3710 | ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3711 | ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0); |
| 3712 | /* Always load RISC code on non ISP2[12]00 chips. */ |
| 3713 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) |
| 3714 | ha->flags.disable_risc_code_load = 0; |
| 3715 | ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0); |
| 3716 | ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0); |
| 3717 | 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] | 3718 | 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] | 3719 | ha->flags.disable_serdes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3720 | |
| 3721 | ha->operating_mode = |
| 3722 | (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 3723 | |
| 3724 | memcpy(ha->fw_seriallink_options, nv->seriallink_options, |
| 3725 | sizeof(ha->fw_seriallink_options)); |
| 3726 | |
| 3727 | /* save HBA serial number */ |
| 3728 | ha->serial0 = icb->port_name[5]; |
| 3729 | ha->serial1 = icb->port_name[6]; |
| 3730 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3731 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 3732 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3733 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3734 | icb->execution_throttle = cpu_to_le16(0xFFFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3735 | |
| 3736 | ha->retry_count = nv->retry_count; |
| 3737 | |
| 3738 | /* Set minimum login_timeout to 4 seconds. */ |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 3739 | if (nv->login_timeout != ql2xlogintimeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3740 | nv->login_timeout = ql2xlogintimeout; |
| 3741 | if (nv->login_timeout < 4) |
| 3742 | nv->login_timeout = 4; |
| 3743 | ha->login_timeout = nv->login_timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3744 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 3745 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 3746 | ha->r_a_tov = 100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3747 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3748 | ha->loop_reset_delay = nv->reset_delay; |
| 3749 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3750 | /* Link Down Timeout = 0: |
| 3751 | * |
| 3752 | * When Port Down timer expires we will start returning |
| 3753 | * I/O's to OS with "DID_NO_CONNECT". |
| 3754 | * |
| 3755 | * Link Down Timeout != 0: |
| 3756 | * |
| 3757 | * The driver waits for the link to come up after link down |
| 3758 | * before returning I/Os to OS with "DID_NO_CONNECT". |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3759 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3760 | if (nv->link_down_timeout == 0) { |
| 3761 | ha->loop_down_abort_time = |
Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 3762 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3763 | } else { |
| 3764 | ha->link_down_timeout = nv->link_down_timeout; |
| 3765 | ha->loop_down_abort_time = |
| 3766 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3767 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3768 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3769 | /* |
| 3770 | * Need enough time to try and get the port back. |
| 3771 | */ |
| 3772 | ha->port_down_retry_count = nv->port_down_retry_count; |
| 3773 | if (qlport_down_retry) |
| 3774 | ha->port_down_retry_count = qlport_down_retry; |
| 3775 | /* Set login_retry_count */ |
| 3776 | ha->login_retry_count = nv->retry_count; |
| 3777 | if (ha->port_down_retry_count == nv->port_down_retry_count && |
| 3778 | ha->port_down_retry_count > 3) |
| 3779 | ha->login_retry_count = ha->port_down_retry_count; |
| 3780 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 3781 | ha->login_retry_count = ha->port_down_retry_count; |
| 3782 | if (ql2xloginretrycount) |
| 3783 | ha->login_retry_count = ql2xloginretrycount; |
| 3784 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3785 | icb->lun_enables = cpu_to_le16(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3786 | icb->command_resource_count = 0; |
| 3787 | icb->immediate_notify_resource_count = 0; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3788 | icb->timeout = cpu_to_le16(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3789 | |
| 3790 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 3791 | /* Enable RIO */ |
| 3792 | icb->firmware_options[0] &= ~BIT_3; |
| 3793 | icb->add_firmware_options[0] &= |
| 3794 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 3795 | icb->add_firmware_options[0] |= BIT_2; |
| 3796 | icb->response_accumulation_timer = 3; |
| 3797 | icb->interrupt_delay_timer = 5; |
| 3798 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3799 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3800 | } else { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 3801 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3802 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 3803 | ha->zio_mode = icb->add_firmware_options[0] & |
| 3804 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 3805 | ha->zio_timer = icb->interrupt_delay_timer ? |
| 3806 | icb->interrupt_delay_timer: 2; |
| 3807 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3808 | icb->add_firmware_options[0] &= |
| 3809 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3810 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 3811 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 3812 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 3813 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3814 | ql_log(ql_log_info, vha, 0x0068, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 3815 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 3816 | ha->zio_mode, ha->zio_timer * 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3817 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 3818 | icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode; |
| 3819 | icb->interrupt_delay_timer = (uint8_t)ha->zio_timer; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3820 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3821 | } |
| 3822 | } |
| 3823 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3824 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3825 | ql_log(ql_log_warn, vha, 0x0069, |
| 3826 | "NVRAM configuration failed.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3827 | } |
| 3828 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3829 | } |
| 3830 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3831 | static void |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3832 | qla2x00_rport_del(void *data) |
| 3833 | { |
| 3834 | fc_port_t *fcport = data; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3835 | struct fc_rport *rport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 3836 | unsigned long flags; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3837 | |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 3838 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3839 | rport = fcport->drport ? fcport->drport: fcport->rport; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3840 | fcport->drport = NULL; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 3841 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3842 | if (rport) { |
| 3843 | ql_dbg(ql_dbg_disc, fcport->vha, 0xffff, |
| 3844 | "%s %8phN. rport %p roles %x \n", |
| 3845 | __func__, fcport->port_name, rport, |
| 3846 | rport->roles); |
| 3847 | |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3848 | fc_remote_port_delete(rport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3849 | } |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3850 | } |
| 3851 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3852 | /** |
| 3853 | * qla2x00_alloc_fcport() - Allocate a generic fcport. |
| 3854 | * @ha: HA context |
| 3855 | * @flags: allocation flags |
| 3856 | * |
| 3857 | * Returns a pointer to the allocated fcport, or NULL, if none available. |
| 3858 | */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 3859 | fc_port_t * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3860 | qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3861 | { |
| 3862 | fc_port_t *fcport; |
| 3863 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 3864 | fcport = kzalloc(sizeof(fc_port_t), flags); |
| 3865 | if (!fcport) |
| 3866 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3867 | |
| 3868 | /* Setup fcport template structure. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3869 | fcport->vha = vha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3870 | fcport->port_type = FCT_UNKNOWN; |
| 3871 | fcport->loop_id = FC_NO_LOOP_ID; |
Chad Dupuis | ec426e1 | 2011-03-30 11:46:32 -0700 | [diff] [blame] | 3872 | qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED); |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 3873 | fcport->supported_classes = FC_COS_UNSPECIFIED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3874 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3875 | fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev, |
| 3876 | sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma, |
Quinn Tran | 6cb3216 | 2017-02-13 12:18:29 -0800 | [diff] [blame] | 3877 | flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3878 | fcport->disc_state = DSC_DELETED; |
| 3879 | fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 3880 | fcport->deleted = QLA_SESS_DELETED; |
| 3881 | fcport->login_retry = vha->hw->login_retry_count; |
| 3882 | fcport->login_retry = 5; |
| 3883 | fcport->logout_on_delete = 1; |
| 3884 | |
| 3885 | if (!fcport->ct_desc.ct_sns) { |
| 3886 | ql_log(ql_log_warn, vha, 0xffff, |
| 3887 | "Failed to allocate ct_sns request.\n"); |
| 3888 | kfree(fcport); |
| 3889 | fcport = NULL; |
| 3890 | } |
| 3891 | INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn); |
| 3892 | INIT_LIST_HEAD(&fcport->gnl_entry); |
| 3893 | INIT_LIST_HEAD(&fcport->list); |
| 3894 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 3895 | return fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3896 | } |
| 3897 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3898 | void |
| 3899 | qla2x00_free_fcport(fc_port_t *fcport) |
| 3900 | { |
| 3901 | if (fcport->ct_desc.ct_sns) { |
| 3902 | dma_free_coherent(&fcport->vha->hw->pdev->dev, |
| 3903 | sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns, |
| 3904 | fcport->ct_desc.ct_sns_dma); |
| 3905 | |
| 3906 | fcport->ct_desc.ct_sns = NULL; |
| 3907 | } |
| 3908 | kfree(fcport); |
| 3909 | } |
| 3910 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3911 | /* |
| 3912 | * qla2x00_configure_loop |
| 3913 | * Updates Fibre Channel Device Database with what is actually on loop. |
| 3914 | * |
| 3915 | * Input: |
| 3916 | * ha = adapter block pointer. |
| 3917 | * |
| 3918 | * Returns: |
| 3919 | * 0 = success. |
| 3920 | * 1 = error. |
| 3921 | * 2 = database was full and device was not configured. |
| 3922 | */ |
| 3923 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3924 | qla2x00_configure_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3925 | { |
| 3926 | int rval; |
| 3927 | unsigned long flags, save_flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3928 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3929 | rval = QLA_SUCCESS; |
| 3930 | |
| 3931 | /* Get Initiator ID */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3932 | if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) { |
| 3933 | rval = qla2x00_configure_hba(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3934 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3935 | ql_dbg(ql_dbg_disc, vha, 0x2013, |
| 3936 | "Unable to configure HBA.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3937 | return (rval); |
| 3938 | } |
| 3939 | } |
| 3940 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3941 | save_flags = flags = vha->dpc_flags; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3942 | ql_dbg(ql_dbg_disc, vha, 0x2014, |
| 3943 | "Configure loop -- dpc flags = 0x%lx.\n", flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3944 | |
| 3945 | /* |
| 3946 | * If we have both an RSCN and PORT UPDATE pending then handle them |
| 3947 | * both at the same time. |
| 3948 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3949 | clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 3950 | clear_bit(RSCN_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3951 | |
Michael Hernandez | 3064ff3 | 2009-12-15 21:29:44 -0800 | [diff] [blame] | 3952 | qla2x00_get_data_rate(vha); |
| 3953 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3954 | /* Determine what we need to do */ |
| 3955 | if (ha->current_topology == ISP_CFG_FL && |
| 3956 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 3957 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3958 | set_bit(RSCN_UPDATE, &flags); |
| 3959 | |
| 3960 | } else if (ha->current_topology == ISP_CFG_F && |
| 3961 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 3962 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3963 | set_bit(RSCN_UPDATE, &flags); |
| 3964 | clear_bit(LOCAL_LOOP_UPDATE, &flags); |
| 3965 | |
Andrew Vasquez | 21333b4 | 2006-05-17 15:09:56 -0700 | [diff] [blame] | 3966 | } else if (ha->current_topology == ISP_CFG_N) { |
| 3967 | clear_bit(RSCN_UPDATE, &flags); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 3968 | } else if (ha->current_topology == ISP_CFG_NL) { |
| 3969 | clear_bit(RSCN_UPDATE, &flags); |
| 3970 | set_bit(LOCAL_LOOP_UPDATE, &flags); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3971 | } else if (!vha->flags.online || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3972 | (test_bit(ABORT_ISP_ACTIVE, &flags))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3973 | set_bit(RSCN_UPDATE, &flags); |
| 3974 | set_bit(LOCAL_LOOP_UPDATE, &flags); |
| 3975 | } |
| 3976 | |
| 3977 | if (test_bit(LOCAL_LOOP_UPDATE, &flags)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3978 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
| 3979 | ql_dbg(ql_dbg_disc, vha, 0x2015, |
| 3980 | "Loop resync needed, failing.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3981 | rval = QLA_FUNCTION_FAILED; |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 3982 | } else |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3983 | rval = qla2x00_configure_local_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3984 | } |
| 3985 | |
| 3986 | if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3987 | if (LOOP_TRANSITION(vha)) { |
| 3988 | ql_dbg(ql_dbg_disc, vha, 0x201e, |
| 3989 | "Needs RSCN update and loop transition.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3990 | rval = QLA_FUNCTION_FAILED; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3991 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3992 | else |
| 3993 | rval = qla2x00_configure_fabric(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3994 | } |
| 3995 | |
| 3996 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3997 | if (atomic_read(&vha->loop_down_timer) || |
| 3998 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3999 | rval = QLA_FUNCTION_FAILED; |
| 4000 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4001 | atomic_set(&vha->loop_state, LOOP_READY); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4002 | ql_dbg(ql_dbg_disc, vha, 0x2069, |
| 4003 | "LOOP READY.\n"); |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 4004 | ha->flags.fw_init_done = 1; |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 4005 | |
| 4006 | /* |
| 4007 | * Process any ATIO queue entries that came in |
| 4008 | * while we weren't online. |
| 4009 | */ |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 4010 | if (qla_tgt_mode_enabled(vha) || |
| 4011 | qla_dual_mode_enabled(vha)) { |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 4012 | if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) { |
| 4013 | spin_lock_irqsave(&ha->tgt.atio_lock, |
| 4014 | flags); |
| 4015 | qlt_24xx_process_atio_queue(vha, 0); |
| 4016 | spin_unlock_irqrestore( |
| 4017 | &ha->tgt.atio_lock, flags); |
| 4018 | } else { |
| 4019 | spin_lock_irqsave(&ha->hardware_lock, |
| 4020 | flags); |
| 4021 | qlt_24xx_process_atio_queue(vha, 1); |
| 4022 | spin_unlock_irqrestore( |
| 4023 | &ha->hardware_lock, flags); |
| 4024 | } |
| 4025 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4026 | } |
| 4027 | } |
| 4028 | |
| 4029 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4030 | ql_dbg(ql_dbg_disc, vha, 0x206a, |
| 4031 | "%s *** FAILED ***.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4032 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4033 | ql_dbg(ql_dbg_disc, vha, 0x206b, |
| 4034 | "%s: exiting normally.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4035 | } |
| 4036 | |
Bjorn Helgaas | cc3ef7b | 2008-09-11 21:22:51 -0700 | [diff] [blame] | 4037 | /* Restore state if a resync event occurred during processing */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4038 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4039 | if (test_bit(LOCAL_LOOP_UPDATE, &save_flags)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4040 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 4041 | if (test_bit(RSCN_UPDATE, &save_flags)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4042 | set_bit(RSCN_UPDATE, &vha->dpc_flags); |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 4043 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4044 | } |
| 4045 | |
| 4046 | return (rval); |
| 4047 | } |
| 4048 | |
| 4049 | |
| 4050 | |
| 4051 | /* |
| 4052 | * qla2x00_configure_local_loop |
| 4053 | * Updates Fibre Channel Device Database with local loop devices. |
| 4054 | * |
| 4055 | * Input: |
| 4056 | * ha = adapter block pointer. |
| 4057 | * |
| 4058 | * Returns: |
| 4059 | * 0 = success. |
| 4060 | */ |
| 4061 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4062 | qla2x00_configure_local_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4063 | { |
| 4064 | int rval, rval2; |
| 4065 | int found_devs; |
| 4066 | int found; |
| 4067 | fc_port_t *fcport, *new_fcport; |
| 4068 | |
| 4069 | uint16_t index; |
| 4070 | uint16_t entries; |
| 4071 | char *id_iter; |
| 4072 | uint16_t loop_id; |
| 4073 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4074 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4075 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4076 | |
| 4077 | found_devs = 0; |
| 4078 | new_fcport = NULL; |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4079 | entries = MAX_FIBRE_DEVICES_LOOP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4080 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4081 | /* Get list of logged in devices. */ |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4082 | memset(ha->gid_list, 0, qla2x00_gid_list_size(ha)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4083 | 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] | 4084 | &entries); |
| 4085 | if (rval != QLA_SUCCESS) |
| 4086 | goto cleanup_allocation; |
| 4087 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4088 | ql_dbg(ql_dbg_disc, vha, 0x2017, |
| 4089 | "Entries in ID list (%d).\n", entries); |
| 4090 | ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075, |
| 4091 | (uint8_t *)ha->gid_list, |
| 4092 | entries * sizeof(struct gid_list_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4093 | |
| 4094 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4095 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4096 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4097 | ql_log(ql_log_warn, vha, 0x2018, |
| 4098 | "Memory allocation failed for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4099 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 4100 | goto cleanup_allocation; |
| 4101 | } |
| 4102 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 4103 | |
| 4104 | /* |
| 4105 | * Mark local devices that were present with FCF_DEVICE_LOST for now. |
| 4106 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4107 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4108 | if (atomic_read(&fcport->state) == FCS_ONLINE && |
| 4109 | fcport->port_type != FCT_BROADCAST && |
| 4110 | (fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 4111 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4112 | ql_dbg(ql_dbg_disc, vha, 0x2019, |
| 4113 | "Marking port lost loop_id=0x%04x.\n", |
| 4114 | fcport->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4115 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4116 | qla2x00_mark_device_lost(vha, fcport, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4117 | } |
| 4118 | } |
| 4119 | |
| 4120 | /* Add devices to port list. */ |
| 4121 | id_iter = (char *)ha->gid_list; |
| 4122 | for (index = 0; index < entries; index++) { |
| 4123 | domain = ((struct gid_list_info *)id_iter)->domain; |
| 4124 | area = ((struct gid_list_info *)id_iter)->area; |
| 4125 | al_pa = ((struct gid_list_info *)id_iter)->al_pa; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4126 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4127 | loop_id = (uint16_t) |
| 4128 | ((struct gid_list_info *)id_iter)->loop_id_2100; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4129 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4130 | loop_id = le16_to_cpu( |
| 4131 | ((struct gid_list_info *)id_iter)->loop_id); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4132 | id_iter += ha->gid_list_info_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4133 | |
| 4134 | /* Bypass reserved domain fields. */ |
| 4135 | if ((domain & 0xf0) == 0xf0) |
| 4136 | continue; |
| 4137 | |
| 4138 | /* Bypass if not same domain and area of adapter. */ |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 4139 | if (area && domain && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4140 | (area != vha->d_id.b.area || domain != vha->d_id.b.domain)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4141 | continue; |
| 4142 | |
| 4143 | /* Bypass invalid local loop ID. */ |
| 4144 | if (loop_id > LAST_LOCAL_LOOP_ID) |
| 4145 | continue; |
| 4146 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4147 | memset(new_fcport->port_name, 0, WWN_SIZE); |
Arun Easi | 370d550 | 2012-08-22 14:21:10 -0400 | [diff] [blame] | 4148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4149 | /* Fill in member data. */ |
| 4150 | new_fcport->d_id.b.domain = domain; |
| 4151 | new_fcport->d_id.b.area = area; |
| 4152 | new_fcport->d_id.b.al_pa = al_pa; |
| 4153 | new_fcport->loop_id = loop_id; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4154 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4155 | rval2 = qla2x00_get_port_database(vha, new_fcport, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4156 | if (rval2 != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4157 | ql_dbg(ql_dbg_disc, vha, 0x201a, |
| 4158 | "Failed to retrieve fcport information " |
| 4159 | "-- get_port_database=%x, loop_id=0x%04x.\n", |
| 4160 | rval2, new_fcport->loop_id); |
| 4161 | ql_dbg(ql_dbg_disc, vha, 0x201b, |
| 4162 | "Scheduling resync.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4163 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4164 | continue; |
| 4165 | } |
| 4166 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4167 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4168 | /* Check for matching device in port list. */ |
| 4169 | found = 0; |
| 4170 | fcport = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4171 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4172 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 4173 | WWN_SIZE)) |
| 4174 | continue; |
| 4175 | |
Shyam Sundar | ddb9b12 | 2009-03-24 09:08:10 -0700 | [diff] [blame] | 4176 | fcport->flags &= ~FCF_FABRIC_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4177 | fcport->loop_id = new_fcport->loop_id; |
| 4178 | fcport->port_type = new_fcport->port_type; |
| 4179 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 4180 | memcpy(fcport->node_name, new_fcport->node_name, |
| 4181 | WWN_SIZE); |
| 4182 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4183 | if (!fcport->login_succ) { |
| 4184 | vha->fcport_count++; |
| 4185 | fcport->login_succ = 1; |
| 4186 | fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 4187 | } |
| 4188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4189 | found++; |
| 4190 | break; |
| 4191 | } |
| 4192 | |
| 4193 | if (!found) { |
| 4194 | /* New device, add to fcports list. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4195 | list_add_tail(&new_fcport->list, &vha->vp_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4196 | |
| 4197 | /* Allocate a new replacement fcport. */ |
| 4198 | fcport = new_fcport; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4199 | if (!fcport->login_succ) { |
| 4200 | vha->fcport_count++; |
| 4201 | fcport->login_succ = 1; |
| 4202 | fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 4203 | } |
| 4204 | |
| 4205 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 4206 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4207 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4209 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4210 | ql_log(ql_log_warn, vha, 0x201c, |
| 4211 | "Failed to allocate memory for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4212 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 4213 | goto cleanup_allocation; |
| 4214 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4215 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4216 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 4217 | } |
| 4218 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4219 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 4220 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4221 | /* Base iIDMA settings on HBA port speed. */ |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 4222 | fcport->fp_speed = ha->link_data_rate; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4223 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4224 | qla2x00_update_fcport(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4225 | |
| 4226 | found_devs++; |
| 4227 | } |
| 4228 | |
| 4229 | cleanup_allocation: |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 4230 | kfree(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4231 | |
| 4232 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4233 | ql_dbg(ql_dbg_disc, vha, 0x201d, |
| 4234 | "Configure local loop error exit: rval=%x.\n", rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4235 | } |
| 4236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4237 | return (rval); |
| 4238 | } |
| 4239 | |
| 4240 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4241 | qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4242 | { |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4243 | int rval; |
Quinn Tran | 93f2bd6 | 2014-09-25 05:16:53 -0400 | [diff] [blame] | 4244 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4245 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4246 | |
Andrew Vasquez | c76f2c0 | 2007-07-19 15:05:57 -0700 | [diff] [blame] | 4247 | if (!IS_IIDMA_CAPABLE(ha)) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4248 | return; |
| 4249 | |
Giridhar Malavali | c9afb9a | 2010-09-03 15:20:48 -0700 | [diff] [blame] | 4250 | if (atomic_read(&fcport->state) != FCS_ONLINE) |
| 4251 | return; |
| 4252 | |
Andrew Vasquez | 39bd962 | 2007-09-20 14:07:34 -0700 | [diff] [blame] | 4253 | if (fcport->fp_speed == PORT_SPEED_UNKNOWN || |
| 4254 | fcport->fp_speed > ha->link_data_rate) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4255 | return; |
| 4256 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4257 | rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed, |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 4258 | mb); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4259 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4260 | ql_dbg(ql_dbg_disc, vha, 0x2004, |
Oleksandr Khoshaba | 7b83355 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 4261 | "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n", |
| 4262 | fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4263 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4264 | ql_dbg(ql_dbg_disc, vha, 0x2005, |
Oleksandr Khoshaba | 7b83355 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 4265 | "iIDMA adjusted to %s GB/s on %8phN.\n", |
Joe Carnuccio | d0297c9 | 2012-11-21 02:40:40 -0500 | [diff] [blame] | 4266 | qla2x00_get_link_speed_str(ha, fcport->fp_speed), |
Oleksandr Khoshaba | 7b83355 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 4267 | fcport->port_name); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4268 | } |
| 4269 | } |
| 4270 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4271 | /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/ |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4272 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4273 | qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 4274 | { |
| 4275 | struct fc_rport_identifiers rport_ids; |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 4276 | struct fc_rport *rport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 4277 | unsigned long flags; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 4278 | |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 4279 | rport_ids.node_name = wwn_to_u64(fcport->node_name); |
| 4280 | rport_ids.port_name = wwn_to_u64(fcport->port_name); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 4281 | rport_ids.port_id = fcport->d_id.b.domain << 16 | |
| 4282 | fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa; |
| 4283 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4284 | fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 4285 | if (!rport) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4286 | ql_log(ql_log_warn, vha, 0x2006, |
| 4287 | "Unable to allocate fc remote port.\n"); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 4288 | return; |
| 4289 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4290 | |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 4291 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4292 | *((fc_port_t **)rport->dd_data) = fcport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 4293 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 4294 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 4295 | rport->supported_classes = fcport->supported_classes; |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 4296 | |
| 4297 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 4298 | if (fcport->port_type == FCT_INITIATOR) |
| 4299 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 4300 | if (fcport->port_type == FCT_TARGET) |
| 4301 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4302 | |
| 4303 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4304 | "%s %8phN. rport %p is %s mode \n", |
| 4305 | __func__, fcport->port_name, rport, |
| 4306 | (fcport->port_type == FCT_TARGET) ? "tgt" : "ini"); |
| 4307 | |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 4308 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 4309 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4310 | |
| 4311 | /* |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4312 | * qla2x00_update_fcport |
| 4313 | * Updates device on list. |
| 4314 | * |
| 4315 | * Input: |
| 4316 | * ha = adapter block pointer. |
| 4317 | * fcport = port structure pointer. |
| 4318 | * |
| 4319 | * Return: |
| 4320 | * 0 - Success |
| 4321 | * BIT_0 - error |
| 4322 | * |
| 4323 | * Context: |
| 4324 | * Kernel context. |
| 4325 | */ |
| 4326 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4327 | qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4328 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4329 | fcport->vha = vha; |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 4330 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4331 | if (IS_SW_RESV_ADDR(fcport->d_id)) |
| 4332 | return; |
| 4333 | |
| 4334 | ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %8phC \n", |
| 4335 | __func__, fcport->port_name); |
| 4336 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 4337 | if (IS_QLAFX00(vha->hw)) { |
| 4338 | qla2x00_set_fcport_state(fcport, FCS_ONLINE); |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 4339 | goto reg_port; |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 4340 | } |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4341 | fcport->login_retry = 0; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 4342 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4343 | fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 4344 | fcport->deleted = 0; |
| 4345 | fcport->logout_on_delete = 1; |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4346 | |
Joe Carnuccio | 1f93da52 | 2012-11-21 02:40:38 -0500 | [diff] [blame] | 4347 | qla2x00_set_fcport_state(fcport, FCS_ONLINE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4348 | qla2x00_iidma_fcport(vha, fcport); |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 4349 | qla24xx_update_fcport_fcp_prio(vha, fcport); |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 4350 | |
| 4351 | reg_port: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4352 | switch (vha->host->active_mode) { |
| 4353 | case MODE_INITIATOR: |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 4354 | qla2x00_reg_remote_port(vha, fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4355 | break; |
| 4356 | case MODE_TARGET: |
| 4357 | if (!vha->vha_tgt.qla_tgt->tgt_stop && |
| 4358 | !vha->vha_tgt.qla_tgt->tgt_stopped) |
| 4359 | qlt_fc_port_added(vha, fcport); |
| 4360 | break; |
| 4361 | case MODE_DUAL: |
| 4362 | qla2x00_reg_remote_port(vha, fcport); |
| 4363 | if (!vha->vha_tgt.qla_tgt->tgt_stop && |
| 4364 | !vha->vha_tgt.qla_tgt->tgt_stopped) |
| 4365 | qlt_fc_port_added(vha, fcport); |
| 4366 | break; |
| 4367 | default: |
| 4368 | break; |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 4369 | } |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4370 | } |
| 4371 | |
| 4372 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4373 | * qla2x00_configure_fabric |
| 4374 | * Setup SNS devices with loop ID's. |
| 4375 | * |
| 4376 | * Input: |
| 4377 | * ha = adapter block pointer. |
| 4378 | * |
| 4379 | * Returns: |
| 4380 | * 0 = success. |
| 4381 | * BIT_0 = error |
| 4382 | */ |
| 4383 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4384 | qla2x00_configure_fabric(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4385 | { |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 4386 | int rval; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4387 | fc_port_t *fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4388 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4389 | uint16_t loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4390 | LIST_HEAD(new_fcports); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4391 | struct qla_hw_data *ha = vha->hw; |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4392 | int discovery_gen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4393 | |
| 4394 | /* If FL port exists, then SNS is present */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 4395 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4396 | loop_id = NPH_F_PORT; |
| 4397 | else |
| 4398 | loop_id = SNS_FL_PORT; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4399 | 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] | 4400 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4401 | ql_dbg(ql_dbg_disc, vha, 0x201f, |
| 4402 | "MBX_GET_PORT_NAME failed, No FL Port.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4403 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4404 | vha->device_flags &= ~SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4405 | return (QLA_SUCCESS); |
| 4406 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4407 | vha->device_flags |= SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4408 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4409 | |
| 4410 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { |
| 4411 | rval = qla2x00_send_change_request(vha, 0x3, 0); |
| 4412 | if (rval != QLA_SUCCESS) |
| 4413 | ql_log(ql_log_warn, vha, 0x121, |
| 4414 | "Failed to enable receiving of RSCN requests: 0x%x.\n", |
| 4415 | rval); |
| 4416 | } |
| 4417 | |
| 4418 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4419 | do { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4420 | qla2x00_mgmt_svr_login(vha); |
| 4421 | |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 4422 | /* FDMI support. */ |
| 4423 | if (ql2xfdmienable && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4424 | test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags)) |
| 4425 | qla2x00_fdmi_register(vha); |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 4426 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4427 | /* Ensure we are logged into the SNS. */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 4428 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4429 | loop_id = NPH_SNS; |
| 4430 | else |
| 4431 | loop_id = SIMPLE_NAME_SERVER; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 4432 | rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff, |
| 4433 | 0xfc, mb, BIT_1|BIT_0); |
| 4434 | if (rval != QLA_SUCCESS) { |
| 4435 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Joe Carnuccio | e452ceb | 2013-02-08 01:57:56 -0500 | [diff] [blame] | 4436 | return rval; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 4437 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4438 | if (mb[0] != MBS_COMMAND_COMPLETE) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4439 | ql_dbg(ql_dbg_disc, vha, 0x2042, |
| 4440 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x " |
| 4441 | "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1], |
| 4442 | mb[2], mb[6], mb[7]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4443 | return (QLA_SUCCESS); |
| 4444 | } |
| 4445 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4446 | if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) { |
| 4447 | if (qla2x00_rft_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4448 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4449 | ql_dbg(ql_dbg_disc, vha, 0x2045, |
| 4450 | "Register FC-4 TYPE failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4451 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4452 | if (qla2x00_rff_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4453 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4454 | ql_dbg(ql_dbg_disc, vha, 0x2049, |
| 4455 | "Register FC-4 Features failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4456 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4457 | if (qla2x00_rnn_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4458 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4459 | ql_dbg(ql_dbg_disc, vha, 0x204f, |
| 4460 | "Register Node Name failed.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4461 | } else if (qla2x00_rsnn_nn(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4462 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4463 | ql_dbg(ql_dbg_disc, vha, 0x2053, |
| 4464 | "Register Symobilic Node Name failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4465 | } |
| 4466 | } |
| 4467 | |
Joe Carnuccio | 827210b | 2013-02-08 01:57:57 -0500 | [diff] [blame] | 4468 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 4469 | fcport->scan_state = QLA_FCPORT_SCAN; |
| 4470 | } |
| 4471 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4472 | /* Mark the time right before querying FW for connected ports. |
| 4473 | * This process is long, asynchronous and by the time it's done, |
| 4474 | * collected information might not be accurate anymore. E.g. |
| 4475 | * disconnected port might have re-connected and a brand new |
| 4476 | * session has been created. In this case session's generation |
| 4477 | * will be newer than discovery_gen. */ |
| 4478 | qlt_do_generation_tick(vha, &discovery_gen); |
| 4479 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4480 | rval = qla2x00_find_all_fabric_devs(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4481 | if (rval != QLA_SUCCESS) |
| 4482 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4483 | } while (0); |
| 4484 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4485 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4486 | ql_dbg(ql_dbg_disc, vha, 0x2068, |
| 4487 | "Configure fabric error exit rval=%d.\n", rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4488 | |
| 4489 | return (rval); |
| 4490 | } |
| 4491 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4492 | /* |
| 4493 | * qla2x00_find_all_fabric_devs |
| 4494 | * |
| 4495 | * Input: |
| 4496 | * ha = adapter block pointer. |
| 4497 | * dev = database device entry pointer. |
| 4498 | * |
| 4499 | * Returns: |
| 4500 | * 0 = success. |
| 4501 | * |
| 4502 | * Context: |
| 4503 | * Kernel context. |
| 4504 | */ |
| 4505 | static int |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4506 | qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4507 | { |
| 4508 | int rval; |
| 4509 | uint16_t loop_id; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4510 | fc_port_t *fcport, *new_fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4511 | int found; |
| 4512 | |
| 4513 | sw_info_t *swl; |
| 4514 | int swl_idx; |
| 4515 | int first_dev, last_dev; |
Mike Waychison | 1516ef4 | 2010-05-04 15:01:31 -0700 | [diff] [blame] | 4516 | port_id_t wrap = {}, nxt_d_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4517 | struct qla_hw_data *ha = vha->hw; |
Chad Dupuis | bb4cf5b | 2013-02-08 01:58:01 -0500 | [diff] [blame] | 4518 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4519 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4520 | |
| 4521 | rval = QLA_SUCCESS; |
| 4522 | |
| 4523 | /* Try GID_PT to get device list, else GAN. */ |
Andrew Vasquez | 7a67735 | 2012-02-09 11:15:56 -0800 | [diff] [blame] | 4524 | if (!ha->swl) |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4525 | ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t), |
Andrew Vasquez | 7a67735 | 2012-02-09 11:15:56 -0800 | [diff] [blame] | 4526 | GFP_KERNEL); |
| 4527 | swl = ha->swl; |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 4528 | if (!swl) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4529 | /*EMPTY*/ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4530 | ql_dbg(ql_dbg_disc, vha, 0x2054, |
| 4531 | "GID_PT allocations failed, fallback on GA_NXT.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4532 | } else { |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4533 | memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4534 | if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4535 | swl = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4536 | } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4537 | swl = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4538 | } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4539 | swl = NULL; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4540 | } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) { |
| 4541 | swl = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4542 | } |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 4543 | |
| 4544 | /* If other queries succeeded probe for FC-4 type */ |
| 4545 | if (swl) |
| 4546 | qla2x00_gff_id(vha, swl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4547 | } |
| 4548 | swl_idx = 0; |
| 4549 | |
| 4550 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4551 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4552 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4553 | ql_log(ql_log_warn, vha, 0x205e, |
| 4554 | "Failed to allocate memory for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4555 | return (QLA_MEMORY_ALLOC_FAILED); |
| 4556 | } |
| 4557 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4558 | /* Set start port ID scan at adapter ID. */ |
| 4559 | first_dev = 1; |
| 4560 | last_dev = 0; |
| 4561 | |
| 4562 | /* Starting free loop ID. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4563 | loop_id = ha->min_external_loopid; |
| 4564 | for (; loop_id <= ha->max_loop_id; loop_id++) { |
| 4565 | if (qla2x00_is_reserved_id(vha, loop_id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4566 | continue; |
| 4567 | |
Giridhar Malavali | 3a6478d | 2010-05-28 15:08:20 -0700 | [diff] [blame] | 4568 | if (ha->current_topology == ISP_CFG_FL && |
| 4569 | (atomic_read(&vha->loop_down_timer) || |
| 4570 | LOOP_TRANSITION(vha))) { |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 4571 | atomic_set(&vha->loop_down_timer, 0); |
| 4572 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 4573 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4574 | break; |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 4575 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4576 | |
| 4577 | if (swl != NULL) { |
| 4578 | if (last_dev) { |
| 4579 | wrap.b24 = new_fcport->d_id.b24; |
| 4580 | } else { |
| 4581 | new_fcport->d_id.b24 = swl[swl_idx].d_id.b24; |
| 4582 | memcpy(new_fcport->node_name, |
| 4583 | swl[swl_idx].node_name, WWN_SIZE); |
| 4584 | memcpy(new_fcport->port_name, |
| 4585 | swl[swl_idx].port_name, WWN_SIZE); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4586 | memcpy(new_fcport->fabric_port_name, |
| 4587 | swl[swl_idx].fabric_port_name, WWN_SIZE); |
| 4588 | new_fcport->fp_speed = swl[swl_idx].fp_speed; |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 4589 | new_fcport->fc4_type = swl[swl_idx].fc4_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4590 | |
| 4591 | if (swl[swl_idx].d_id.b.rsvd_1 != 0) { |
| 4592 | last_dev = 1; |
| 4593 | } |
| 4594 | swl_idx++; |
| 4595 | } |
| 4596 | } else { |
| 4597 | /* Send GA_NXT to the switch */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4598 | rval = qla2x00_ga_nxt(vha, new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4599 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4600 | ql_log(ql_log_warn, vha, 0x2064, |
| 4601 | "SNS scan failed -- assuming " |
| 4602 | "zero-entry result.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4603 | rval = QLA_SUCCESS; |
| 4604 | break; |
| 4605 | } |
| 4606 | } |
| 4607 | |
| 4608 | /* If wrap on switch device list, exit. */ |
| 4609 | if (first_dev) { |
| 4610 | wrap.b24 = new_fcport->d_id.b24; |
| 4611 | first_dev = 0; |
| 4612 | } else if (new_fcport->d_id.b24 == wrap.b24) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4613 | ql_dbg(ql_dbg_disc, vha, 0x2065, |
| 4614 | "Device wrap (%02x%02x%02x).\n", |
| 4615 | new_fcport->d_id.b.domain, |
| 4616 | new_fcport->d_id.b.area, |
| 4617 | new_fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4618 | break; |
| 4619 | } |
| 4620 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4621 | /* Bypass if same physical adapter. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4622 | if (new_fcport->d_id.b24 == base_vha->d_id.b24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4623 | continue; |
| 4624 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4625 | /* Bypass virtual ports of the same host. */ |
Chad Dupuis | bb4cf5b | 2013-02-08 01:58:01 -0500 | [diff] [blame] | 4626 | if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24)) |
| 4627 | continue; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4628 | |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 4629 | /* Bypass if same domain and area of adapter. */ |
| 4630 | if (((new_fcport->d_id.b24 & 0xffff00) == |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4631 | (vha->d_id.b24 & 0xffff00)) && ha->current_topology == |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 4632 | ISP_CFG_FL) |
| 4633 | continue; |
| 4634 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4635 | /* Bypass reserved domain fields. */ |
| 4636 | if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0) |
| 4637 | continue; |
| 4638 | |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 4639 | /* Bypass ports whose FCP-4 type is not FCP_SCSI */ |
Chad Dupuis | 4da26e1 | 2010-10-15 11:27:40 -0700 | [diff] [blame] | 4640 | if (ql2xgffidenable && |
| 4641 | (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI && |
| 4642 | new_fcport->fc4_type != FC4_TYPE_UNKNOWN)) |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 4643 | continue; |
| 4644 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4645 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 4646 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4647 | /* Locate matching device in database. */ |
| 4648 | found = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4649 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4650 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 4651 | WWN_SIZE)) |
| 4652 | continue; |
| 4653 | |
Joe Carnuccio | 827210b | 2013-02-08 01:57:57 -0500 | [diff] [blame] | 4654 | fcport->scan_state = QLA_FCPORT_FOUND; |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 4655 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4656 | found++; |
| 4657 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4658 | /* Update port state. */ |
| 4659 | memcpy(fcport->fabric_port_name, |
| 4660 | new_fcport->fabric_port_name, WWN_SIZE); |
| 4661 | fcport->fp_speed = new_fcport->fp_speed; |
| 4662 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4663 | /* |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 4664 | * If address the same and state FCS_ONLINE |
| 4665 | * (or in target mode), nothing changed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4666 | */ |
| 4667 | if (fcport->d_id.b24 == new_fcport->d_id.b24 && |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 4668 | (atomic_read(&fcport->state) == FCS_ONLINE || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4669 | (vha->host->active_mode == MODE_TARGET))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4670 | break; |
| 4671 | } |
| 4672 | |
| 4673 | /* |
| 4674 | * If device was not a fabric device before. |
| 4675 | */ |
| 4676 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 4677 | fcport->d_id.b24 = new_fcport->d_id.b24; |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 4678 | qla2x00_clear_loop_id(fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4679 | fcport->flags |= (FCF_FABRIC_DEVICE | |
| 4680 | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4681 | break; |
| 4682 | } |
| 4683 | |
| 4684 | /* |
| 4685 | * Port ID changed or device was marked to be updated; |
| 4686 | * Log it out if still logged in and mark it for |
| 4687 | * relogin later. |
| 4688 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4689 | if (qla_tgt_mode_enabled(base_vha)) { |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 4690 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080, |
| 4691 | "port changed FC ID, %8phC" |
| 4692 | " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n", |
| 4693 | fcport->port_name, |
| 4694 | fcport->d_id.b.domain, |
| 4695 | fcport->d_id.b.area, |
| 4696 | fcport->d_id.b.al_pa, |
| 4697 | fcport->loop_id, |
| 4698 | new_fcport->d_id.b.domain, |
| 4699 | new_fcport->d_id.b.area, |
| 4700 | new_fcport->d_id.b.al_pa); |
| 4701 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 4702 | break; |
| 4703 | } |
| 4704 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4705 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 4706 | fcport->flags |= FCF_LOGIN_NEEDED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4707 | break; |
| 4708 | } |
| 4709 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4710 | if (found) { |
| 4711 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4712 | continue; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4713 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4714 | /* If device was not in our fcports list, then add it. */ |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 4715 | new_fcport->scan_state = QLA_FCPORT_FOUND; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4716 | list_add_tail(&new_fcport->list, &vha->vp_fcports); |
| 4717 | |
| 4718 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 4719 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4720 | |
| 4721 | /* Allocate a new replacement fcport. */ |
| 4722 | nxt_d_id.b24 = new_fcport->d_id.b24; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4723 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4724 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4725 | ql_log(ql_log_warn, vha, 0x2066, |
| 4726 | "Memory allocation failed for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4727 | return (QLA_MEMORY_ALLOC_FAILED); |
| 4728 | } |
| 4729 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
| 4730 | new_fcport->d_id.b24 = nxt_d_id.b24; |
| 4731 | } |
| 4732 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4733 | qla2x00_free_fcport(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4734 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4735 | /* |
| 4736 | * Logout all previous fabric dev marked lost, except FCP2 devices. |
| 4737 | */ |
| 4738 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 4739 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 4740 | break; |
| 4741 | |
| 4742 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 || |
| 4743 | (fcport->flags & FCF_LOGIN_NEEDED) == 0) |
| 4744 | continue; |
| 4745 | |
| 4746 | if (fcport->scan_state == QLA_FCPORT_SCAN) { |
| 4747 | if ((qla_dual_mode_enabled(vha) || |
| 4748 | qla_ini_mode_enabled(vha)) && |
| 4749 | atomic_read(&fcport->state) == FCS_ONLINE) { |
| 4750 | qla2x00_mark_device_lost(vha, fcport, |
| 4751 | ql2xplogiabsentdevice, 0); |
| 4752 | if (fcport->loop_id != FC_NO_LOOP_ID && |
| 4753 | (fcport->flags & FCF_FCP2_DEVICE) == 0 && |
| 4754 | fcport->port_type != FCT_INITIATOR && |
| 4755 | fcport->port_type != FCT_BROADCAST) { |
| 4756 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4757 | "%s %d %8phC post del sess\n", |
| 4758 | __func__, __LINE__, |
| 4759 | fcport->port_name); |
| 4760 | |
| 4761 | qlt_schedule_sess_for_deletion_lock |
| 4762 | (fcport); |
| 4763 | continue; |
| 4764 | } |
| 4765 | } |
| 4766 | } |
| 4767 | |
| 4768 | if (fcport->scan_state == QLA_FCPORT_FOUND) |
| 4769 | qla24xx_fcport_handle_login(vha, fcport); |
| 4770 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4771 | return (rval); |
| 4772 | } |
| 4773 | |
| 4774 | /* |
| 4775 | * qla2x00_find_new_loop_id |
| 4776 | * Scan through our port list and find a new usable loop ID. |
| 4777 | * |
| 4778 | * Input: |
| 4779 | * ha: adapter state pointer. |
| 4780 | * dev: port structure pointer. |
| 4781 | * |
| 4782 | * Returns: |
| 4783 | * qla2x00 local function return status code. |
| 4784 | * |
| 4785 | * Context: |
| 4786 | * Kernel context. |
| 4787 | */ |
Joe Carnuccio | 03bcfb5 | 2011-03-30 11:46:27 -0700 | [diff] [blame] | 4788 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4789 | 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] | 4790 | { |
| 4791 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4792 | struct qla_hw_data *ha = vha->hw; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4793 | unsigned long flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4794 | |
| 4795 | rval = QLA_SUCCESS; |
| 4796 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 4797 | spin_lock_irqsave(&ha->vport_slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4798 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 4799 | dev->loop_id = find_first_zero_bit(ha->loop_id_map, |
| 4800 | LOOPID_MAP_SIZE); |
| 4801 | if (dev->loop_id >= LOOPID_MAP_SIZE || |
| 4802 | qla2x00_is_reserved_id(vha, dev->loop_id)) { |
| 4803 | dev->loop_id = FC_NO_LOOP_ID; |
| 4804 | rval = QLA_FUNCTION_FAILED; |
| 4805 | } else |
| 4806 | set_bit(dev->loop_id, ha->loop_id_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4807 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 4808 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4809 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 4810 | if (rval == QLA_SUCCESS) |
| 4811 | ql_dbg(ql_dbg_disc, dev->vha, 0x2086, |
| 4812 | "Assigning new loopid=%x, portid=%x.\n", |
| 4813 | dev->loop_id, dev->d_id.b24); |
| 4814 | else |
| 4815 | ql_log(ql_log_warn, dev->vha, 0x2087, |
| 4816 | "No loop_id's available, portid=%x.\n", |
| 4817 | dev->d_id.b24); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4818 | |
| 4819 | return (rval); |
| 4820 | } |
| 4821 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4822 | |
| 4823 | /* |
| 4824 | * qla2x00_fabric_login |
| 4825 | * Issue fabric login command. |
| 4826 | * |
| 4827 | * Input: |
| 4828 | * ha = adapter block pointer. |
| 4829 | * device = pointer to FC device type structure. |
| 4830 | * |
| 4831 | * Returns: |
| 4832 | * 0 - Login successfully |
| 4833 | * 1 - Login failed |
| 4834 | * 2 - Initiator device |
| 4835 | * 3 - Fatal error |
| 4836 | */ |
| 4837 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4838 | qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4839 | uint16_t *next_loopid) |
| 4840 | { |
| 4841 | int rval; |
| 4842 | int retry; |
| 4843 | uint16_t tmp_loopid; |
| 4844 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4845 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4846 | |
| 4847 | retry = 0; |
| 4848 | tmp_loopid = 0; |
| 4849 | |
| 4850 | for (;;) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4851 | ql_dbg(ql_dbg_disc, vha, 0x2000, |
| 4852 | "Trying Fabric Login w/loop id 0x%04x for port " |
| 4853 | "%02x%02x%02x.\n", |
| 4854 | fcport->loop_id, fcport->d_id.b.domain, |
| 4855 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4856 | |
| 4857 | /* Login fcport on switch. */ |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 4858 | rval = ha->isp_ops->fabric_login(vha, fcport->loop_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4859 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 4860 | fcport->d_id.b.al_pa, mb, BIT_0); |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 4861 | if (rval != QLA_SUCCESS) { |
| 4862 | return rval; |
| 4863 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4864 | if (mb[0] == MBS_PORT_ID_USED) { |
| 4865 | /* |
| 4866 | * Device has another loop ID. The firmware team |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4867 | * recommends the driver perform an implicit login with |
| 4868 | * the specified ID again. The ID we just used is save |
| 4869 | * here so we return with an ID that can be tried by |
| 4870 | * the next login. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4871 | */ |
| 4872 | retry++; |
| 4873 | tmp_loopid = fcport->loop_id; |
| 4874 | fcport->loop_id = mb[1]; |
| 4875 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4876 | ql_dbg(ql_dbg_disc, vha, 0x2001, |
| 4877 | "Fabric Login: port in use - next loop " |
| 4878 | "id=0x%04x, port id= %02x%02x%02x.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4879 | fcport->loop_id, fcport->d_id.b.domain, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4880 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4881 | |
| 4882 | } else if (mb[0] == MBS_COMMAND_COMPLETE) { |
| 4883 | /* |
| 4884 | * Login succeeded. |
| 4885 | */ |
| 4886 | if (retry) { |
| 4887 | /* A retry occurred before. */ |
| 4888 | *next_loopid = tmp_loopid; |
| 4889 | } else { |
| 4890 | /* |
| 4891 | * No retry occurred before. Just increment the |
| 4892 | * ID value for next login. |
| 4893 | */ |
| 4894 | *next_loopid = (fcport->loop_id + 1); |
| 4895 | } |
| 4896 | |
| 4897 | if (mb[1] & BIT_0) { |
| 4898 | fcport->port_type = FCT_INITIATOR; |
| 4899 | } else { |
| 4900 | fcport->port_type = FCT_TARGET; |
| 4901 | if (mb[1] & BIT_1) { |
Santosh Vernekar | 8474f3a | 2009-08-25 11:36:16 -0700 | [diff] [blame] | 4902 | fcport->flags |= FCF_FCP2_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4903 | } |
| 4904 | } |
| 4905 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 4906 | if (mb[10] & BIT_0) |
| 4907 | fcport->supported_classes |= FC_COS_CLASS2; |
| 4908 | if (mb[10] & BIT_1) |
| 4909 | fcport->supported_classes |= FC_COS_CLASS3; |
| 4910 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4911 | if (IS_FWI2_CAPABLE(ha)) { |
| 4912 | if (mb[10] & BIT_7) |
| 4913 | fcport->flags |= |
| 4914 | FCF_CONF_COMP_SUPPORTED; |
| 4915 | } |
| 4916 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4917 | rval = QLA_SUCCESS; |
| 4918 | break; |
| 4919 | } else if (mb[0] == MBS_LOOP_ID_USED) { |
| 4920 | /* |
| 4921 | * Loop ID already used, try next loop ID. |
| 4922 | */ |
| 4923 | fcport->loop_id++; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4924 | rval = qla2x00_find_new_loop_id(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4925 | if (rval != QLA_SUCCESS) { |
| 4926 | /* Ran out of loop IDs to use */ |
| 4927 | break; |
| 4928 | } |
| 4929 | } else if (mb[0] == MBS_COMMAND_ERROR) { |
| 4930 | /* |
| 4931 | * Firmware possibly timed out during login. If NO |
| 4932 | * retries are left to do then the device is declared |
| 4933 | * dead. |
| 4934 | */ |
| 4935 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4936 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 4937 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 4938 | fcport->d_id.b.al_pa); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4939 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4940 | |
| 4941 | rval = 1; |
| 4942 | break; |
| 4943 | } else { |
| 4944 | /* |
| 4945 | * unrecoverable / not handled error |
| 4946 | */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4947 | ql_dbg(ql_dbg_disc, vha, 0x2002, |
| 4948 | "Failed=%x port_id=%02x%02x%02x loop_id=%x " |
| 4949 | "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain, |
| 4950 | fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 4951 | fcport->loop_id, jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4952 | |
| 4953 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4954 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 4955 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 4956 | fcport->d_id.b.al_pa); |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 4957 | qla2x00_clear_loop_id(fcport); |
Andrew Vasquez | 0eedfcf | 2005-10-27 11:09:38 -0700 | [diff] [blame] | 4958 | fcport->login_retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4959 | |
| 4960 | rval = 3; |
| 4961 | break; |
| 4962 | } |
| 4963 | } |
| 4964 | |
| 4965 | return (rval); |
| 4966 | } |
| 4967 | |
| 4968 | /* |
| 4969 | * qla2x00_local_device_login |
| 4970 | * Issue local device login command. |
| 4971 | * |
| 4972 | * Input: |
| 4973 | * ha = adapter block pointer. |
| 4974 | * loop_id = loop id of device to login to. |
| 4975 | * |
| 4976 | * Returns (Where's the #define!!!!): |
| 4977 | * 0 - Login successfully |
| 4978 | * 1 - Login failed |
| 4979 | * 3 - Fatal error |
| 4980 | */ |
| 4981 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4982 | 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] | 4983 | { |
| 4984 | int rval; |
| 4985 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
| 4986 | |
| 4987 | memset(mb, 0, sizeof(mb)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4988 | rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4989 | if (rval == QLA_SUCCESS) { |
| 4990 | /* Interrogate mailbox registers for any errors */ |
| 4991 | if (mb[0] == MBS_COMMAND_ERROR) |
| 4992 | rval = 1; |
| 4993 | else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR) |
| 4994 | /* device not in PCB table */ |
| 4995 | rval = 3; |
| 4996 | } |
| 4997 | |
| 4998 | return (rval); |
| 4999 | } |
| 5000 | |
| 5001 | /* |
| 5002 | * qla2x00_loop_resync |
| 5003 | * Resync with fibre channel devices. |
| 5004 | * |
| 5005 | * Input: |
| 5006 | * ha = adapter block pointer. |
| 5007 | * |
| 5008 | * Returns: |
| 5009 | * 0 = success |
| 5010 | */ |
| 5011 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5012 | qla2x00_loop_resync(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5013 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5014 | int rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5015 | uint32_t wait_time; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 5016 | struct req_que *req; |
| 5017 | struct rsp_que *rsp; |
| 5018 | |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 5019 | req = vha->req; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 5020 | rsp = req->rsp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5021 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5022 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 5023 | if (vha->flags.online) { |
| 5024 | if (!(rval = qla2x00_fw_ready(vha))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5025 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 5026 | wait_time = 256; |
| 5027 | do { |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 5028 | if (!IS_QLAFX00(vha->hw)) { |
| 5029 | /* |
| 5030 | * Issue a marker after FW becomes |
| 5031 | * ready. |
| 5032 | */ |
| 5033 | qla2x00_marker(vha, req, rsp, 0, 0, |
| 5034 | MK_SYNC_ALL); |
| 5035 | vha->marker_needed = 0; |
| 5036 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5037 | |
| 5038 | /* Remap devices on Loop. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5039 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5040 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 5041 | if (IS_QLAFX00(vha->hw)) |
| 5042 | qlafx00_configure_devices(vha); |
| 5043 | else |
| 5044 | qla2x00_configure_loop(vha); |
| 5045 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5046 | wait_time--; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5047 | } while (!atomic_read(&vha->loop_down_timer) && |
| 5048 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
| 5049 | && wait_time && (test_bit(LOOP_RESYNC_NEEDED, |
| 5050 | &vha->dpc_flags))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5051 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5052 | } |
| 5053 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5054 | if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5055 | return (QLA_FUNCTION_FAILED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5056 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5057 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5058 | ql_dbg(ql_dbg_disc, vha, 0x206c, |
| 5059 | "%s *** FAILED ***.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5060 | |
| 5061 | return (rval); |
| 5062 | } |
| 5063 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5064 | /* |
| 5065 | * qla2x00_perform_loop_resync |
| 5066 | * Description: This function will set the appropriate flags and call |
| 5067 | * qla2x00_loop_resync. If successful loop will be resynced |
| 5068 | * Arguments : scsi_qla_host_t pointer |
| 5069 | * returm : Success or Failure |
| 5070 | */ |
| 5071 | |
| 5072 | int qla2x00_perform_loop_resync(scsi_qla_host_t *ha) |
| 5073 | { |
| 5074 | int32_t rval = 0; |
| 5075 | |
| 5076 | if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) { |
| 5077 | /*Configure the flags so that resync happens properly*/ |
| 5078 | atomic_set(&ha->loop_down_timer, 0); |
| 5079 | if (!(ha->device_flags & DFLG_NO_CABLE)) { |
| 5080 | atomic_set(&ha->loop_state, LOOP_UP); |
| 5081 | set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); |
| 5082 | set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags); |
| 5083 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
| 5084 | |
| 5085 | rval = qla2x00_loop_resync(ha); |
| 5086 | } else |
| 5087 | atomic_set(&ha->loop_state, LOOP_DEAD); |
| 5088 | |
| 5089 | clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags); |
| 5090 | } |
| 5091 | |
| 5092 | return rval; |
| 5093 | } |
| 5094 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5095 | void |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 5096 | qla2x00_update_fcports(scsi_qla_host_t *base_vha) |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5097 | { |
| 5098 | fc_port_t *fcport; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5099 | struct scsi_qla_host *vha; |
| 5100 | struct qla_hw_data *ha = base_vha->hw; |
| 5101 | unsigned long flags; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5102 | |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5103 | spin_lock_irqsave(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5104 | /* Go with deferred removal of rport references. */ |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5105 | list_for_each_entry(vha, &base_vha->hw->vp_list, list) { |
| 5106 | atomic_inc(&vha->vref_count); |
| 5107 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Dan Carpenter | 8ae598d | 2010-12-21 16:00:15 -0800 | [diff] [blame] | 5108 | if (fcport->drport && |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5109 | atomic_read(&fcport->state) != FCS_UNCONFIGURED) { |
| 5110 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 5111 | qla2x00_rport_del(fcport); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 5112 | |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5113 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5114 | } |
| 5115 | } |
| 5116 | atomic_dec(&vha->vref_count); |
Joe Carnuccio | c4a9b53 | 2017-03-15 09:48:43 -0700 | [diff] [blame] | 5117 | wake_up(&vha->vref_waitq); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5118 | } |
| 5119 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5120 | } |
| 5121 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5122 | /* Assumes idc_lock always held on entry */ |
| 5123 | void |
| 5124 | qla83xx_reset_ownership(scsi_qla_host_t *vha) |
| 5125 | { |
| 5126 | struct qla_hw_data *ha = vha->hw; |
| 5127 | uint32_t drv_presence, drv_presence_mask; |
| 5128 | uint32_t dev_part_info1, dev_part_info2, class_type; |
| 5129 | uint32_t class_type_mask = 0x3; |
| 5130 | uint16_t fcoe_other_function = 0xffff, i; |
| 5131 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 5132 | if (IS_QLA8044(ha)) { |
| 5133 | drv_presence = qla8044_rd_direct(vha, |
| 5134 | QLA8044_CRB_DRV_ACTIVE_INDEX); |
| 5135 | dev_part_info1 = qla8044_rd_direct(vha, |
| 5136 | QLA8044_CRB_DEV_PART_INFO_INDEX); |
| 5137 | dev_part_info2 = qla8044_rd_direct(vha, |
| 5138 | QLA8044_CRB_DEV_PART_INFO2); |
| 5139 | } else { |
| 5140 | qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); |
| 5141 | qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1); |
| 5142 | qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2); |
| 5143 | } |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5144 | for (i = 0; i < 8; i++) { |
| 5145 | class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask); |
| 5146 | if ((class_type == QLA83XX_CLASS_TYPE_FCOE) && |
| 5147 | (i != ha->portnum)) { |
| 5148 | fcoe_other_function = i; |
| 5149 | break; |
| 5150 | } |
| 5151 | } |
| 5152 | if (fcoe_other_function == 0xffff) { |
| 5153 | for (i = 0; i < 8; i++) { |
| 5154 | class_type = ((dev_part_info2 >> (i * 4)) & |
| 5155 | class_type_mask); |
| 5156 | if ((class_type == QLA83XX_CLASS_TYPE_FCOE) && |
| 5157 | ((i + 8) != ha->portnum)) { |
| 5158 | fcoe_other_function = i + 8; |
| 5159 | break; |
| 5160 | } |
| 5161 | } |
| 5162 | } |
| 5163 | /* |
| 5164 | * Prepare drv-presence mask based on fcoe functions present. |
| 5165 | * However consider only valid physical fcoe function numbers (0-15). |
| 5166 | */ |
| 5167 | drv_presence_mask = ~((1 << (ha->portnum)) | |
| 5168 | ((fcoe_other_function == 0xffff) ? |
| 5169 | 0 : (1 << (fcoe_other_function)))); |
| 5170 | |
| 5171 | /* We are the reset owner iff: |
| 5172 | * - No other protocol drivers present. |
| 5173 | * - This is the lowest among fcoe functions. */ |
| 5174 | if (!(drv_presence & drv_presence_mask) && |
| 5175 | (ha->portnum < fcoe_other_function)) { |
| 5176 | ql_dbg(ql_dbg_p3p, vha, 0xb07f, |
| 5177 | "This host is Reset owner.\n"); |
| 5178 | ha->flags.nic_core_reset_owner = 1; |
| 5179 | } |
| 5180 | } |
| 5181 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5182 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5183 | __qla83xx_set_drv_ack(scsi_qla_host_t *vha) |
| 5184 | { |
| 5185 | int rval = QLA_SUCCESS; |
| 5186 | struct qla_hw_data *ha = vha->hw; |
| 5187 | uint32_t drv_ack; |
| 5188 | |
| 5189 | rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack); |
| 5190 | if (rval == QLA_SUCCESS) { |
| 5191 | drv_ack |= (1 << ha->portnum); |
| 5192 | rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack); |
| 5193 | } |
| 5194 | |
| 5195 | return rval; |
| 5196 | } |
| 5197 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5198 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5199 | __qla83xx_clear_drv_ack(scsi_qla_host_t *vha) |
| 5200 | { |
| 5201 | int rval = QLA_SUCCESS; |
| 5202 | struct qla_hw_data *ha = vha->hw; |
| 5203 | uint32_t drv_ack; |
| 5204 | |
| 5205 | rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack); |
| 5206 | if (rval == QLA_SUCCESS) { |
| 5207 | drv_ack &= ~(1 << ha->portnum); |
| 5208 | rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack); |
| 5209 | } |
| 5210 | |
| 5211 | return rval; |
| 5212 | } |
| 5213 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5214 | static const char * |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5215 | qla83xx_dev_state_to_string(uint32_t dev_state) |
| 5216 | { |
| 5217 | switch (dev_state) { |
| 5218 | case QLA8XXX_DEV_COLD: |
| 5219 | return "COLD/RE-INIT"; |
| 5220 | case QLA8XXX_DEV_INITIALIZING: |
| 5221 | return "INITIALIZING"; |
| 5222 | case QLA8XXX_DEV_READY: |
| 5223 | return "READY"; |
| 5224 | case QLA8XXX_DEV_NEED_RESET: |
| 5225 | return "NEED RESET"; |
| 5226 | case QLA8XXX_DEV_NEED_QUIESCENT: |
| 5227 | return "NEED QUIESCENT"; |
| 5228 | case QLA8XXX_DEV_FAILED: |
| 5229 | return "FAILED"; |
| 5230 | case QLA8XXX_DEV_QUIESCENT: |
| 5231 | return "QUIESCENT"; |
| 5232 | default: |
| 5233 | return "Unknown"; |
| 5234 | } |
| 5235 | } |
| 5236 | |
| 5237 | /* Assumes idc-lock always held on entry */ |
| 5238 | void |
| 5239 | qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type) |
| 5240 | { |
| 5241 | struct qla_hw_data *ha = vha->hw; |
| 5242 | uint32_t idc_audit_reg = 0, duration_secs = 0; |
| 5243 | |
| 5244 | switch (audit_type) { |
| 5245 | case IDC_AUDIT_TIMESTAMP: |
| 5246 | ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000); |
| 5247 | idc_audit_reg = (ha->portnum) | |
| 5248 | (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8); |
| 5249 | qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg); |
| 5250 | break; |
| 5251 | |
| 5252 | case IDC_AUDIT_COMPLETION: |
| 5253 | duration_secs = ((jiffies_to_msecs(jiffies) - |
| 5254 | jiffies_to_msecs(ha->idc_audit_ts)) / 1000); |
| 5255 | idc_audit_reg = (ha->portnum) | |
| 5256 | (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8); |
| 5257 | qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg); |
| 5258 | break; |
| 5259 | |
| 5260 | default: |
| 5261 | ql_log(ql_log_warn, vha, 0xb078, |
| 5262 | "Invalid audit type specified.\n"); |
| 5263 | break; |
| 5264 | } |
| 5265 | } |
| 5266 | |
| 5267 | /* Assumes idc_lock always held on entry */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5268 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5269 | qla83xx_initiating_reset(scsi_qla_host_t *vha) |
| 5270 | { |
| 5271 | struct qla_hw_data *ha = vha->hw; |
| 5272 | uint32_t idc_control, dev_state; |
| 5273 | |
| 5274 | __qla83xx_get_idc_control(vha, &idc_control); |
| 5275 | if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) { |
| 5276 | ql_log(ql_log_info, vha, 0xb080, |
| 5277 | "NIC Core reset has been disabled. idc-control=0x%x\n", |
| 5278 | idc_control); |
| 5279 | return QLA_FUNCTION_FAILED; |
| 5280 | } |
| 5281 | |
| 5282 | /* Set NEED-RESET iff in READY state and we are the reset-owner */ |
| 5283 | qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state); |
| 5284 | if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) { |
| 5285 | qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, |
| 5286 | QLA8XXX_DEV_NEED_RESET); |
| 5287 | ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n"); |
| 5288 | qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP); |
| 5289 | } else { |
| 5290 | const char *state = qla83xx_dev_state_to_string(dev_state); |
| 5291 | ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state); |
| 5292 | |
| 5293 | /* SV: XXX: Is timeout required here? */ |
| 5294 | /* Wait for IDC state change READY -> NEED_RESET */ |
| 5295 | while (dev_state == QLA8XXX_DEV_READY) { |
| 5296 | qla83xx_idc_unlock(vha, 0); |
| 5297 | msleep(200); |
| 5298 | qla83xx_idc_lock(vha, 0); |
| 5299 | qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state); |
| 5300 | } |
| 5301 | } |
| 5302 | |
| 5303 | /* Send IDC ack by writing to drv-ack register */ |
| 5304 | __qla83xx_set_drv_ack(vha); |
| 5305 | |
| 5306 | return QLA_SUCCESS; |
| 5307 | } |
| 5308 | |
| 5309 | int |
| 5310 | __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control) |
| 5311 | { |
| 5312 | return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control); |
| 5313 | } |
| 5314 | |
| 5315 | int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5316 | __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control) |
| 5317 | { |
| 5318 | return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control); |
| 5319 | } |
| 5320 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5321 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5322 | qla83xx_check_driver_presence(scsi_qla_host_t *vha) |
| 5323 | { |
| 5324 | uint32_t drv_presence = 0; |
| 5325 | struct qla_hw_data *ha = vha->hw; |
| 5326 | |
| 5327 | qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); |
| 5328 | if (drv_presence & (1 << ha->portnum)) |
| 5329 | return QLA_SUCCESS; |
| 5330 | else |
| 5331 | return QLA_TEST_FAILED; |
| 5332 | } |
| 5333 | |
| 5334 | int |
| 5335 | qla83xx_nic_core_reset(scsi_qla_host_t *vha) |
| 5336 | { |
| 5337 | int rval = QLA_SUCCESS; |
| 5338 | struct qla_hw_data *ha = vha->hw; |
| 5339 | |
| 5340 | ql_dbg(ql_dbg_p3p, vha, 0xb058, |
| 5341 | "Entered %s().\n", __func__); |
| 5342 | |
| 5343 | if (vha->device_flags & DFLG_DEV_FAILED) { |
| 5344 | ql_log(ql_log_warn, vha, 0xb059, |
| 5345 | "Device in unrecoverable FAILED state.\n"); |
| 5346 | return QLA_FUNCTION_FAILED; |
| 5347 | } |
| 5348 | |
| 5349 | qla83xx_idc_lock(vha, 0); |
| 5350 | |
| 5351 | if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) { |
| 5352 | ql_log(ql_log_warn, vha, 0xb05a, |
| 5353 | "Function=0x%x has been removed from IDC participation.\n", |
| 5354 | ha->portnum); |
| 5355 | rval = QLA_FUNCTION_FAILED; |
| 5356 | goto exit; |
| 5357 | } |
| 5358 | |
| 5359 | qla83xx_reset_ownership(vha); |
| 5360 | |
| 5361 | rval = qla83xx_initiating_reset(vha); |
| 5362 | |
| 5363 | /* |
| 5364 | * Perform reset if we are the reset-owner, |
| 5365 | * else wait till IDC state changes to READY/FAILED. |
| 5366 | */ |
| 5367 | if (rval == QLA_SUCCESS) { |
| 5368 | rval = qla83xx_idc_state_handler(vha); |
| 5369 | |
| 5370 | if (rval == QLA_SUCCESS) |
| 5371 | ha->flags.nic_core_hung = 0; |
| 5372 | __qla83xx_clear_drv_ack(vha); |
| 5373 | } |
| 5374 | |
| 5375 | exit: |
| 5376 | qla83xx_idc_unlock(vha, 0); |
| 5377 | |
| 5378 | ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__); |
| 5379 | |
| 5380 | return rval; |
| 5381 | } |
| 5382 | |
Saurav Kashyap | 8117877 | 2012-08-22 14:21:04 -0400 | [diff] [blame] | 5383 | int |
| 5384 | qla2xxx_mctp_dump(scsi_qla_host_t *vha) |
| 5385 | { |
| 5386 | struct qla_hw_data *ha = vha->hw; |
| 5387 | int rval = QLA_FUNCTION_FAILED; |
| 5388 | |
| 5389 | if (!IS_MCTP_CAPABLE(ha)) { |
| 5390 | /* This message can be removed from the final version */ |
| 5391 | ql_log(ql_log_info, vha, 0x506d, |
| 5392 | "This board is not MCTP capable\n"); |
| 5393 | return rval; |
| 5394 | } |
| 5395 | |
| 5396 | if (!ha->mctp_dump) { |
| 5397 | ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev, |
| 5398 | MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL); |
| 5399 | |
| 5400 | if (!ha->mctp_dump) { |
| 5401 | ql_log(ql_log_warn, vha, 0x506e, |
| 5402 | "Failed to allocate memory for mctp dump\n"); |
| 5403 | return rval; |
| 5404 | } |
| 5405 | } |
| 5406 | |
| 5407 | #define MCTP_DUMP_STR_ADDR 0x00000000 |
| 5408 | rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma, |
| 5409 | MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4); |
| 5410 | if (rval != QLA_SUCCESS) { |
| 5411 | ql_log(ql_log_warn, vha, 0x506f, |
| 5412 | "Failed to capture mctp dump\n"); |
| 5413 | } else { |
| 5414 | ql_log(ql_log_info, vha, 0x5070, |
| 5415 | "Mctp dump capture for host (%ld/%p).\n", |
| 5416 | vha->host_no, ha->mctp_dump); |
| 5417 | ha->mctp_dumped = 1; |
| 5418 | } |
| 5419 | |
Saurav Kashyap | 409ee0f | 2012-08-22 14:21:29 -0400 | [diff] [blame] | 5420 | if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) { |
Saurav Kashyap | 8117877 | 2012-08-22 14:21:04 -0400 | [diff] [blame] | 5421 | ha->flags.nic_core_reset_hdlr_active = 1; |
| 5422 | rval = qla83xx_restart_nic_firmware(vha); |
| 5423 | if (rval) |
| 5424 | /* NIC Core reset failed. */ |
| 5425 | ql_log(ql_log_warn, vha, 0x5071, |
| 5426 | "Failed to restart nic firmware\n"); |
| 5427 | else |
| 5428 | ql_dbg(ql_dbg_p3p, vha, 0xb084, |
| 5429 | "Restarted NIC firmware successfully.\n"); |
| 5430 | ha->flags.nic_core_reset_hdlr_active = 0; |
| 5431 | } |
| 5432 | |
| 5433 | return rval; |
| 5434 | |
| 5435 | } |
| 5436 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5437 | /* |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 5438 | * qla2x00_quiesce_io |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5439 | * Description: This function will block the new I/Os |
| 5440 | * Its not aborting any I/Os as context |
| 5441 | * is not destroyed during quiescence |
| 5442 | * Arguments: scsi_qla_host_t |
| 5443 | * return : void |
| 5444 | */ |
| 5445 | void |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 5446 | qla2x00_quiesce_io(scsi_qla_host_t *vha) |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5447 | { |
| 5448 | struct qla_hw_data *ha = vha->hw; |
| 5449 | struct scsi_qla_host *vp; |
| 5450 | |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 5451 | ql_dbg(ql_dbg_dpc, vha, 0x401d, |
| 5452 | "Quiescing I/O - ha=%p.\n", ha); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5453 | |
| 5454 | atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); |
| 5455 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 5456 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 5457 | qla2x00_mark_all_devices_lost(vha, 0); |
| 5458 | list_for_each_entry(vp, &ha->vp_list, list) |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 5459 | qla2x00_mark_all_devices_lost(vp, 0); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5460 | } else { |
| 5461 | if (!atomic_read(&vha->loop_down_timer)) |
| 5462 | atomic_set(&vha->loop_down_timer, |
| 5463 | LOOP_DOWN_TIME); |
| 5464 | } |
| 5465 | /* Wait for pending cmds to complete */ |
| 5466 | qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST); |
| 5467 | } |
| 5468 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5469 | void |
| 5470 | qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha) |
| 5471 | { |
| 5472 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5473 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5474 | unsigned long flags; |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 5475 | fc_port_t *fcport; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5476 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 5477 | /* For ISP82XX, driver waits for completion of the commands. |
| 5478 | * online flag should be set. |
| 5479 | */ |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 5480 | if (!(IS_P3P_TYPE(ha))) |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 5481 | vha->flags.online = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5482 | ha->flags.chip_reset_done = 0; |
| 5483 | clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Saurav Kashyap | 2be21fa | 2012-05-15 14:34:16 -0400 | [diff] [blame] | 5484 | vha->qla_stats.total_isp_aborts++; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5485 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5486 | ql_log(ql_log_info, vha, 0x00af, |
| 5487 | "Performing ISP error recovery - ha=%p.\n", ha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5488 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 5489 | /* For ISP82XX, reset_chip is just disabling interrupts. |
| 5490 | * Driver waits for the completion of the commands. |
| 5491 | * the interrupts need to be enabled. |
| 5492 | */ |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 5493 | if (!(IS_P3P_TYPE(ha))) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5494 | ha->isp_ops->reset_chip(vha); |
| 5495 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 5496 | ha->flags.n2n_ae = 0; |
| 5497 | ha->flags.lip_ae = 0; |
| 5498 | ha->current_topology = 0; |
| 5499 | ha->flags.fw_started = 0; |
| 5500 | ha->flags.fw_init_done = 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5501 | ha->chip_reset++; |
| 5502 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5503 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 5504 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 5505 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 5506 | qla2x00_mark_all_devices_lost(vha, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5507 | |
| 5508 | spin_lock_irqsave(&ha->vport_slock, flags); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5509 | list_for_each_entry(vp, &ha->vp_list, list) { |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5510 | atomic_inc(&vp->vref_count); |
| 5511 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5512 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5513 | qla2x00_mark_all_devices_lost(vp, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5514 | |
| 5515 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5516 | atomic_dec(&vp->vref_count); |
| 5517 | } |
| 5518 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5519 | } else { |
| 5520 | if (!atomic_read(&vha->loop_down_timer)) |
| 5521 | atomic_set(&vha->loop_down_timer, |
| 5522 | LOOP_DOWN_TIME); |
| 5523 | } |
| 5524 | |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 5525 | /* Clear all async request states across all VPs. */ |
| 5526 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 5527 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 5528 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5529 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 5530 | atomic_inc(&vp->vref_count); |
| 5531 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5532 | |
| 5533 | list_for_each_entry(fcport, &vp->vp_fcports, list) |
| 5534 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 5535 | |
| 5536 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5537 | atomic_dec(&vp->vref_count); |
| 5538 | } |
| 5539 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5540 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 5541 | if (!ha->flags.eeh_busy) { |
| 5542 | /* Make sure for ISP 82XX IO DMA is complete */ |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 5543 | if (IS_P3P_TYPE(ha)) { |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 5544 | qla82xx_chip_reset_cleanup(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5545 | ql_log(ql_log_info, vha, 0x00b4, |
| 5546 | "Done chip reset cleanup.\n"); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5547 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 5548 | /* Done waiting for pending commands. |
| 5549 | * Reset the online flag. |
| 5550 | */ |
| 5551 | vha->flags.online = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5552 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5553 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 5554 | /* Requeue all commands in outstanding command list. */ |
| 5555 | qla2x00_abort_all_cmds(vha, DID_RESET << 16); |
| 5556 | } |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 5557 | /* memory barrier */ |
| 5558 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5559 | } |
| 5560 | |
| 5561 | /* |
| 5562 | * qla2x00_abort_isp |
| 5563 | * Resets ISP and aborts all outstanding commands. |
| 5564 | * |
| 5565 | * Input: |
| 5566 | * ha = adapter block pointer. |
| 5567 | * |
| 5568 | * Returns: |
| 5569 | * 0 = success |
| 5570 | */ |
| 5571 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5572 | qla2x00_abort_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5573 | { |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 5574 | int rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5575 | uint8_t status = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5576 | struct qla_hw_data *ha = vha->hw; |
| 5577 | struct scsi_qla_host *vp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5578 | struct req_que *req = ha->req_q_map[0]; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5579 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5580 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5581 | if (vha->flags.online) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5582 | qla2x00_abort_isp_cleanup(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5583 | |
Santosh Vernekar | a6171297 | 2012-08-22 14:21:13 -0400 | [diff] [blame] | 5584 | if (IS_QLA8031(ha)) { |
| 5585 | ql_dbg(ql_dbg_p3p, vha, 0xb05c, |
| 5586 | "Clearing fcoe driver presence.\n"); |
| 5587 | if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS) |
| 5588 | ql_dbg(ql_dbg_p3p, vha, 0xb073, |
| 5589 | "Error while clearing DRV-Presence.\n"); |
| 5590 | } |
| 5591 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 5592 | if (unlikely(pci_channel_offline(ha->pdev) && |
| 5593 | ha->flags.pci_channel_io_perm_failure)) { |
| 5594 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 5595 | status = 0; |
| 5596 | return status; |
| 5597 | } |
| 5598 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5599 | ha->isp_ops->get_flash_version(vha, req->ring); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 5600 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5601 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5602 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5603 | if (!qla2x00_restart_isp(vha)) { |
| 5604 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5605 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5606 | if (!atomic_read(&vha->loop_down_timer)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5607 | /* |
| 5608 | * Issue marker command only when we are going |
| 5609 | * to start the I/O . |
| 5610 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5611 | vha->marker_needed = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5612 | } |
| 5613 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5614 | vha->flags.online = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5615 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 5616 | ha->isp_ops->enable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5617 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 5618 | ha->isp_abort_cnt = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5619 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 5620 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 5621 | if (IS_QLA81XX(ha) || IS_QLA8031(ha)) |
| 5622 | qla2x00_get_fw_version(vha); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 5623 | if (ha->fce) { |
| 5624 | ha->flags.fce_enabled = 1; |
| 5625 | memset(ha->fce, 0, |
| 5626 | fce_calc_size(ha->fce_bufs)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5627 | rval = qla2x00_enable_fce_trace(vha, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 5628 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 5629 | &ha->fce_bufs); |
| 5630 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5631 | ql_log(ql_log_warn, vha, 0x8033, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 5632 | "Unable to reinitialize FCE " |
| 5633 | "(%d).\n", rval); |
| 5634 | ha->flags.fce_enabled = 0; |
| 5635 | } |
| 5636 | } |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 5637 | |
| 5638 | if (ha->eft) { |
| 5639 | memset(ha->eft, 0, EFT_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5640 | rval = qla2x00_enable_eft_trace(vha, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 5641 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 5642 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5643 | ql_log(ql_log_warn, vha, 0x8034, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 5644 | "Unable to reinitialize EFT " |
| 5645 | "(%d).\n", rval); |
| 5646 | } |
| 5647 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5648 | } else { /* failed the ISP abort */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5649 | vha->flags.online = 1; |
| 5650 | if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5651 | if (ha->isp_abort_cnt == 0) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5652 | ql_log(ql_log_fatal, vha, 0x8035, |
| 5653 | "ISP error recover failed - " |
| 5654 | "board disabled.\n"); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 5655 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5656 | * The next call disables the board |
| 5657 | * completely. |
| 5658 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5659 | ha->isp_ops->reset_adapter(vha); |
| 5660 | vha->flags.online = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5661 | clear_bit(ISP_ABORT_RETRY, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5662 | &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5663 | status = 0; |
| 5664 | } else { /* schedule another ISP abort */ |
| 5665 | ha->isp_abort_cnt--; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5666 | ql_dbg(ql_dbg_taskm, vha, 0x8020, |
| 5667 | "ISP abort - retry remaining %d.\n", |
| 5668 | ha->isp_abort_cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5669 | status = 1; |
| 5670 | } |
| 5671 | } else { |
| 5672 | ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5673 | ql_dbg(ql_dbg_taskm, vha, 0x8021, |
| 5674 | "ISP error recovery - retrying (%d) " |
| 5675 | "more times.\n", ha->isp_abort_cnt); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5676 | set_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5677 | status = 1; |
| 5678 | } |
| 5679 | } |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 5680 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5681 | } |
| 5682 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5683 | if (!status) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5684 | ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5685 | |
| 5686 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5687 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 5688 | if (vp->vp_idx) { |
| 5689 | atomic_inc(&vp->vref_count); |
| 5690 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5691 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5692 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5693 | |
| 5694 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5695 | atomic_dec(&vp->vref_count); |
| 5696 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5697 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5698 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5699 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5700 | if (IS_QLA8031(ha)) { |
| 5701 | ql_dbg(ql_dbg_p3p, vha, 0xb05d, |
| 5702 | "Setting back fcoe driver presence.\n"); |
| 5703 | if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS) |
| 5704 | ql_dbg(ql_dbg_p3p, vha, 0xb074, |
| 5705 | "Error while setting DRV-Presence.\n"); |
| 5706 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5707 | } else { |
Joe Perches | d8424f6 | 2011-11-18 09:03:06 -0800 | [diff] [blame] | 5708 | ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n", |
| 5709 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5710 | } |
| 5711 | |
| 5712 | return(status); |
| 5713 | } |
| 5714 | |
| 5715 | /* |
| 5716 | * qla2x00_restart_isp |
| 5717 | * restarts the ISP after a reset |
| 5718 | * |
| 5719 | * Input: |
| 5720 | * ha = adapter block pointer. |
| 5721 | * |
| 5722 | * Returns: |
| 5723 | * 0 = success |
| 5724 | */ |
| 5725 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5726 | qla2x00_restart_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5727 | { |
Andrew Vasquez | c6b2fca | 2009-03-05 11:07:03 -0800 | [diff] [blame] | 5728 | int status = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5729 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5730 | struct req_que *req = ha->req_q_map[0]; |
| 5731 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5732 | |
| 5733 | /* If firmware needs to be loaded */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5734 | if (qla2x00_isp_firmware(vha)) { |
| 5735 | vha->flags.online = 0; |
| 5736 | status = ha->isp_ops->chip_diag(vha); |
| 5737 | if (!status) |
| 5738 | status = qla2x00_setup_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5739 | } |
| 5740 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5741 | if (!status && !(status = qla2x00_init_rings(vha))) { |
| 5742 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 5743 | ha->flags.chip_reset_done = 1; |
Chad Dupuis | 7108b76 | 2014-04-11 16:54:45 -0400 | [diff] [blame] | 5744 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5745 | /* Initialize the queues in use */ |
| 5746 | qla25xx_init_queues(ha); |
| 5747 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5748 | status = qla2x00_fw_ready(vha); |
| 5749 | if (!status) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5750 | /* Issue a marker after FW becomes ready. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5751 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Chad Dupuis | 7108b76 | 2014-04-11 16:54:45 -0400 | [diff] [blame] | 5752 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5753 | } |
| 5754 | |
| 5755 | /* if no cable then assume it's good */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5756 | if ((vha->device_flags & DFLG_NO_CABLE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5757 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5758 | } |
| 5759 | return (status); |
| 5760 | } |
| 5761 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5762 | static int |
| 5763 | qla25xx_init_queues(struct qla_hw_data *ha) |
| 5764 | { |
| 5765 | struct rsp_que *rsp = NULL; |
| 5766 | struct req_que *req = NULL; |
| 5767 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
| 5768 | int ret = -1; |
| 5769 | int i; |
| 5770 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 5771 | for (i = 1; i < ha->max_rsp_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5772 | rsp = ha->rsp_q_map[i]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 5773 | if (rsp && test_bit(i, ha->rsp_qid_map)) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5774 | rsp->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 5775 | ret = qla25xx_init_rsp_que(base_vha, rsp); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5776 | if (ret != QLA_SUCCESS) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5777 | ql_dbg(ql_dbg_init, base_vha, 0x00ff, |
| 5778 | "%s Rsp que: %d init failed.\n", |
| 5779 | __func__, rsp->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5780 | else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5781 | ql_dbg(ql_dbg_init, base_vha, 0x0100, |
| 5782 | "%s Rsp que: %d inited.\n", |
| 5783 | __func__, rsp->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5784 | } |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 5785 | } |
| 5786 | for (i = 1; i < ha->max_req_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5787 | req = ha->req_q_map[i]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 5788 | if (req && test_bit(i, ha->req_qid_map)) { |
| 5789 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5790 | req->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 5791 | ret = qla25xx_init_req_que(base_vha, req); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5792 | if (ret != QLA_SUCCESS) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5793 | ql_dbg(ql_dbg_init, base_vha, 0x0101, |
| 5794 | "%s Req que: %d init failed.\n", |
| 5795 | __func__, req->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5796 | else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5797 | ql_dbg(ql_dbg_init, base_vha, 0x0102, |
| 5798 | "%s Req que: %d inited.\n", |
| 5799 | __func__, req->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5800 | } |
| 5801 | } |
| 5802 | return ret; |
| 5803 | } |
| 5804 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5805 | /* |
| 5806 | * qla2x00_reset_adapter |
| 5807 | * Reset adapter. |
| 5808 | * |
| 5809 | * Input: |
| 5810 | * ha = adapter block pointer. |
| 5811 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 5812 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5813 | qla2x00_reset_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5814 | { |
| 5815 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5816 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 5817 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5818 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5819 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 5820 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5821 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5822 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 5823 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 5824 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 5825 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 5826 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 5827 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 5828 | } |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5829 | |
| 5830 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5831 | qla24xx_reset_adapter(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5832 | { |
| 5833 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5834 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5835 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 5836 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 5837 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5838 | return; |
| 5839 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5840 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 5841 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5842 | |
| 5843 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 5844 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 5845 | RD_REG_DWORD(®->hccr); |
| 5846 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 5847 | RD_REG_DWORD(®->hccr); |
| 5848 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 09ff36d | 2009-01-22 09:45:30 -0800 | [diff] [blame] | 5849 | |
| 5850 | if (IS_NOPOLLING_TYPE(ha)) |
| 5851 | ha->isp_ops->enable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5852 | } |
| 5853 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5854 | /* On sparc systems, obtain port and node WWN from firmware |
| 5855 | * properties. |
| 5856 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5857 | static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, |
| 5858 | struct nvram_24xx *nv) |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5859 | { |
| 5860 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5861 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5862 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 5863 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 5864 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5865 | int len; |
| 5866 | |
| 5867 | val = of_get_property(dp, "port-wwn", &len); |
| 5868 | if (val && len >= WWN_SIZE) |
| 5869 | memcpy(nv->port_name, val, WWN_SIZE); |
| 5870 | |
| 5871 | val = of_get_property(dp, "node-wwn", &len); |
| 5872 | if (val && len >= WWN_SIZE) |
| 5873 | memcpy(nv->node_name, val, WWN_SIZE); |
| 5874 | #endif |
| 5875 | } |
| 5876 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5877 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5878 | qla24xx_nvram_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5879 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5880 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5881 | struct init_cb_24xx *icb; |
| 5882 | struct nvram_24xx *nv; |
| 5883 | uint32_t *dptr; |
| 5884 | uint8_t *dptr1, *dptr2; |
| 5885 | uint32_t chksum; |
| 5886 | uint16_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5887 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5888 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5889 | rval = QLA_SUCCESS; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5890 | icb = (struct init_cb_24xx *)ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 5891 | nv = ha->nvram; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5892 | |
| 5893 | /* Determine NVRAM starting address. */ |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 5894 | if (ha->port_no == 0) { |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5895 | ha->nvram_base = FA_NVRAM_FUNC0_ADDR; |
| 5896 | ha->vpd_base = FA_NVRAM_VPD0_ADDR; |
| 5897 | } else { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5898 | ha->nvram_base = FA_NVRAM_FUNC1_ADDR; |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 5899 | ha->vpd_base = FA_NVRAM_VPD1_ADDR; |
| 5900 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 5901 | |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5902 | ha->nvram_size = sizeof(struct nvram_24xx); |
| 5903 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5904 | |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 5905 | /* Get VPD data into cache */ |
| 5906 | ha->vpd = ha->nvram + VPD_OFFSET; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5907 | ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 5908 | ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4); |
| 5909 | |
| 5910 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5911 | dptr = (uint32_t *)nv; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5912 | ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5913 | ha->nvram_size); |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 5914 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++) |
| 5915 | chksum += le32_to_cpu(*dptr); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5916 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5917 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a, |
| 5918 | "Contents of NVRAM\n"); |
| 5919 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d, |
| 5920 | (uint8_t *)nv, ha->nvram_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5921 | |
| 5922 | /* Bad NVRAM data, set defaults parameters. */ |
| 5923 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 5924 | || nv->id[3] != ' ' || |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5925 | nv->nvram_version < cpu_to_le16(ICB_VERSION)) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5926 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5927 | ql_log(ql_log_warn, vha, 0x006b, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 5928 | "Inconsistent NVRAM detected: checksum=0x%x id=%c " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5929 | "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version); |
| 5930 | ql_log(ql_log_warn, vha, 0x006c, |
| 5931 | "Falling back to functioning (yet invalid -- WWPN) " |
| 5932 | "defaults.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5933 | |
| 5934 | /* |
| 5935 | * Set default initialization control block. |
| 5936 | */ |
| 5937 | memset(nv, 0, ha->nvram_size); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5938 | nv->nvram_version = cpu_to_le16(ICB_VERSION); |
| 5939 | nv->version = cpu_to_le16(ICB_VERSION); |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 5940 | nv->frame_payload_size = 2048; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5941 | nv->execution_throttle = cpu_to_le16(0xFFFF); |
| 5942 | nv->exchange_count = cpu_to_le16(0); |
| 5943 | nv->hard_address = cpu_to_le16(124); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5944 | nv->port_name[0] = 0x21; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 5945 | nv->port_name[1] = 0x00 + ha->port_no + 1; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5946 | nv->port_name[2] = 0x00; |
| 5947 | nv->port_name[3] = 0xe0; |
| 5948 | nv->port_name[4] = 0x8b; |
| 5949 | nv->port_name[5] = 0x1c; |
| 5950 | nv->port_name[6] = 0x55; |
| 5951 | nv->port_name[7] = 0x86; |
| 5952 | nv->node_name[0] = 0x20; |
| 5953 | nv->node_name[1] = 0x00; |
| 5954 | nv->node_name[2] = 0x00; |
| 5955 | nv->node_name[3] = 0xe0; |
| 5956 | nv->node_name[4] = 0x8b; |
| 5957 | nv->node_name[5] = 0x1c; |
| 5958 | nv->node_name[6] = 0x55; |
| 5959 | nv->node_name[7] = 0x86; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5960 | qla24xx_nvram_wwn_from_ofw(vha, nv); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5961 | nv->login_retry_count = cpu_to_le16(8); |
| 5962 | nv->interrupt_delay_timer = cpu_to_le16(0); |
| 5963 | nv->login_timeout = cpu_to_le16(0); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5964 | nv->firmware_options_1 = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5965 | cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 5966 | nv->firmware_options_2 = cpu_to_le32(2 << 4); |
| 5967 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 5968 | nv->firmware_options_3 = cpu_to_le32(2 << 13); |
| 5969 | nv->host_p = cpu_to_le32(BIT_11|BIT_10); |
| 5970 | nv->efi_parameters = cpu_to_le32(0); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5971 | nv->reset_delay = 5; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5972 | nv->max_luns_per_target = cpu_to_le16(128); |
| 5973 | nv->port_down_retry_count = cpu_to_le16(30); |
| 5974 | nv->link_down_timeout = cpu_to_le16(30); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5975 | |
| 5976 | rval = 1; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5977 | } |
| 5978 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5979 | if (qla_tgt_mode_enabled(vha)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5980 | /* Don't enable full login after initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5981 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5982 | /* Don't enable LIP full login for initiator */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5983 | nv->host_p &= cpu_to_le32(~BIT_10); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5984 | } |
| 5985 | |
| 5986 | qlt_24xx_config_nvram_stage1(vha, nv); |
| 5987 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5988 | /* Reset Initialization control block */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5989 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5990 | |
| 5991 | /* Copy 1st segment. */ |
| 5992 | dptr1 = (uint8_t *)icb; |
| 5993 | dptr2 = (uint8_t *)&nv->version; |
| 5994 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 5995 | while (cnt--) |
| 5996 | *dptr1++ = *dptr2++; |
| 5997 | |
| 5998 | icb->login_retry_count = nv->login_retry_count; |
Andrew Vasquez | 3ea66e2 | 2006-06-23 16:11:27 -0700 | [diff] [blame] | 5999 | icb->link_down_on_nos = nv->link_down_on_nos; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6000 | |
| 6001 | /* Copy 2nd segment. */ |
| 6002 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 6003 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 6004 | cnt = (uint8_t *)&icb->reserved_3 - |
| 6005 | (uint8_t *)&icb->interrupt_delay_timer; |
| 6006 | while (cnt--) |
| 6007 | *dptr1++ = *dptr2++; |
| 6008 | |
| 6009 | /* |
| 6010 | * Setup driver NVRAM options. |
| 6011 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6012 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 6013 | "QLA2462"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6014 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6015 | qlt_24xx_config_nvram_stage2(vha, icb); |
| 6016 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6017 | if (nv->host_p & cpu_to_le32(BIT_15)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6018 | /* Use alternate WWN? */ |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 6019 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 6020 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 6021 | } |
| 6022 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6023 | /* Prepare nodename */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6024 | if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6025 | /* |
| 6026 | * Firmware will apply the following mask if the nodename was |
| 6027 | * not provided. |
| 6028 | */ |
| 6029 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 6030 | icb->node_name[0] &= 0xF0; |
| 6031 | } |
| 6032 | |
| 6033 | /* Set host adapter parameters. */ |
| 6034 | ha->flags.disable_risc_code_load = 0; |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 6035 | ha->flags.enable_lip_reset = 0; |
| 6036 | ha->flags.enable_lip_full_login = |
| 6037 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 6038 | ha->flags.enable_target_reset = |
| 6039 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6040 | ha->flags.enable_led_scheme = 0; |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 6041 | 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] | 6042 | |
Andrew Vasquez | fd0e7e4 | 2006-05-17 15:09:11 -0700 | [diff] [blame] | 6043 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 6044 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6045 | |
| 6046 | memcpy(ha->fw_seriallink_options24, nv->seriallink_options, |
| 6047 | sizeof(ha->fw_seriallink_options24)); |
| 6048 | |
| 6049 | /* save HBA serial number */ |
| 6050 | ha->serial0 = icb->port_name[5]; |
| 6051 | ha->serial1 = icb->port_name[6]; |
| 6052 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6053 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 6054 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6055 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6056 | icb->execution_throttle = cpu_to_le16(0xFFFF); |
andrew.vasquez@qlogic.com | bc8fb3c | 2006-01-13 17:05:42 -0800 | [diff] [blame] | 6057 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6058 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 6059 | |
| 6060 | /* Set minimum login_timeout to 4 seconds. */ |
| 6061 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 6062 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 6063 | if (le16_to_cpu(nv->login_timeout) < 4) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6064 | nv->login_timeout = cpu_to_le16(4); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6065 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6066 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 6067 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 6068 | ha->r_a_tov = 100; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6069 | |
| 6070 | ha->loop_reset_delay = nv->reset_delay; |
| 6071 | |
| 6072 | /* Link Down Timeout = 0: |
| 6073 | * |
| 6074 | * When Port Down timer expires we will start returning |
| 6075 | * I/O's to OS with "DID_NO_CONNECT". |
| 6076 | * |
| 6077 | * Link Down Timeout != 0: |
| 6078 | * |
| 6079 | * The driver waits for the link to come up after link down |
| 6080 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 6081 | */ |
| 6082 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 6083 | ha->loop_down_abort_time = |
| 6084 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 6085 | } else { |
| 6086 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 6087 | ha->loop_down_abort_time = |
| 6088 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 6089 | } |
| 6090 | |
| 6091 | /* Need enough time to try and get the port back. */ |
| 6092 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 6093 | if (qlport_down_retry) |
| 6094 | ha->port_down_retry_count = qlport_down_retry; |
| 6095 | |
| 6096 | /* Set login_retry_count */ |
| 6097 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 6098 | if (ha->port_down_retry_count == |
| 6099 | le16_to_cpu(nv->port_down_retry_count) && |
| 6100 | ha->port_down_retry_count > 3) |
| 6101 | ha->login_retry_count = ha->port_down_retry_count; |
| 6102 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 6103 | ha->login_retry_count = ha->port_down_retry_count; |
| 6104 | if (ql2xloginretrycount) |
| 6105 | ha->login_retry_count = ql2xloginretrycount; |
| 6106 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6107 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6108 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6109 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 6110 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 6111 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 6112 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 6113 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6114 | icb->firmware_options_2 &= cpu_to_le32( |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6115 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6116 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6117 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 6118 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 6119 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6120 | ql_log(ql_log_info, vha, 0x006f, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6121 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 6122 | ha->zio_mode, ha->zio_timer * 100); |
| 6123 | |
| 6124 | icb->firmware_options_2 |= cpu_to_le32( |
| 6125 | (uint32_t)ha->zio_mode); |
| 6126 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6127 | vha->flags.process_response_queue = 1; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6128 | } |
| 6129 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6130 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6131 | ql_log(ql_log_warn, vha, 0x0070, |
| 6132 | "NVRAM configuration failed.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6133 | } |
| 6134 | return (rval); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6135 | } |
| 6136 | |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 6137 | uint8_t qla27xx_find_valid_image(struct scsi_qla_host *vha) |
| 6138 | { |
| 6139 | struct qla27xx_image_status pri_image_status, sec_image_status; |
| 6140 | uint8_t valid_pri_image, valid_sec_image; |
| 6141 | uint32_t *wptr; |
| 6142 | uint32_t cnt, chksum, size; |
| 6143 | struct qla_hw_data *ha = vha->hw; |
| 6144 | |
| 6145 | valid_pri_image = valid_sec_image = 1; |
| 6146 | ha->active_image = 0; |
| 6147 | size = sizeof(struct qla27xx_image_status) / sizeof(uint32_t); |
| 6148 | |
| 6149 | if (!ha->flt_region_img_status_pri) { |
| 6150 | valid_pri_image = 0; |
| 6151 | goto check_sec_image; |
| 6152 | } |
| 6153 | |
| 6154 | qla24xx_read_flash_data(vha, (uint32_t *)(&pri_image_status), |
| 6155 | ha->flt_region_img_status_pri, size); |
| 6156 | |
| 6157 | if (pri_image_status.signature != QLA27XX_IMG_STATUS_SIGN) { |
| 6158 | ql_dbg(ql_dbg_init, vha, 0x018b, |
| 6159 | "Primary image signature (0x%x) not valid\n", |
| 6160 | pri_image_status.signature); |
| 6161 | valid_pri_image = 0; |
| 6162 | goto check_sec_image; |
| 6163 | } |
| 6164 | |
| 6165 | wptr = (uint32_t *)(&pri_image_status); |
| 6166 | cnt = size; |
| 6167 | |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 6168 | for (chksum = 0; cnt--; wptr++) |
| 6169 | chksum += le32_to_cpu(*wptr); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 6170 | |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 6171 | if (chksum) { |
| 6172 | ql_dbg(ql_dbg_init, vha, 0x018c, |
| 6173 | "Checksum validation failed for primary image (0x%x)\n", |
| 6174 | chksum); |
| 6175 | valid_pri_image = 0; |
| 6176 | } |
| 6177 | |
| 6178 | check_sec_image: |
| 6179 | if (!ha->flt_region_img_status_sec) { |
| 6180 | valid_sec_image = 0; |
| 6181 | goto check_valid_image; |
| 6182 | } |
| 6183 | |
| 6184 | qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status), |
| 6185 | ha->flt_region_img_status_sec, size); |
| 6186 | |
| 6187 | if (sec_image_status.signature != QLA27XX_IMG_STATUS_SIGN) { |
| 6188 | ql_dbg(ql_dbg_init, vha, 0x018d, |
| 6189 | "Secondary image signature(0x%x) not valid\n", |
| 6190 | sec_image_status.signature); |
| 6191 | valid_sec_image = 0; |
| 6192 | goto check_valid_image; |
| 6193 | } |
| 6194 | |
| 6195 | wptr = (uint32_t *)(&sec_image_status); |
| 6196 | cnt = size; |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 6197 | for (chksum = 0; cnt--; wptr++) |
| 6198 | chksum += le32_to_cpu(*wptr); |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 6199 | if (chksum) { |
| 6200 | ql_dbg(ql_dbg_init, vha, 0x018e, |
| 6201 | "Checksum validation failed for secondary image (0x%x)\n", |
| 6202 | chksum); |
| 6203 | valid_sec_image = 0; |
| 6204 | } |
| 6205 | |
| 6206 | check_valid_image: |
| 6207 | if (valid_pri_image && (pri_image_status.image_status_mask & 0x1)) |
| 6208 | ha->active_image = QLA27XX_PRIMARY_IMAGE; |
| 6209 | if (valid_sec_image && (sec_image_status.image_status_mask & 0x1)) { |
| 6210 | if (!ha->active_image || |
| 6211 | pri_image_status.generation_number < |
| 6212 | sec_image_status.generation_number) |
| 6213 | ha->active_image = QLA27XX_SECONDARY_IMAGE; |
| 6214 | } |
| 6215 | |
| 6216 | ql_dbg(ql_dbg_init, vha, 0x018f, "%s image\n", |
| 6217 | ha->active_image == 0 ? "default bootld and fw" : |
| 6218 | ha->active_image == 1 ? "primary" : |
| 6219 | ha->active_image == 2 ? "secondary" : |
| 6220 | "Invalid"); |
| 6221 | |
| 6222 | return ha->active_image; |
| 6223 | } |
| 6224 | |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 6225 | static int |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6226 | qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr, |
| 6227 | uint32_t faddr) |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6228 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6229 | int rval = QLA_SUCCESS; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6230 | int segments, fragment; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6231 | uint32_t *dcode, dlen; |
| 6232 | uint32_t risc_addr; |
| 6233 | uint32_t risc_size; |
| 6234 | uint32_t i; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6235 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6236 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6237 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6238 | ql_dbg(ql_dbg_init, vha, 0x008b, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 6239 | "FW: Loading firmware from flash (%x).\n", faddr); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6240 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6241 | rval = QLA_SUCCESS; |
| 6242 | |
| 6243 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6244 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6245 | *srisc_addr = 0; |
| 6246 | |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 6247 | if (IS_QLA27XX(ha) && |
| 6248 | qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE) |
| 6249 | faddr = ha->flt_region_fw_sec; |
| 6250 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6251 | /* Validate firmware image by checking version. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6252 | qla24xx_read_flash_data(vha, dcode, faddr + 4, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6253 | for (i = 0; i < 4; i++) |
| 6254 | dcode[i] = be32_to_cpu(dcode[i]); |
| 6255 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 6256 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 6257 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 6258 | dcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6259 | ql_log(ql_log_fatal, vha, 0x008c, |
| 6260 | "Unable to verify the integrity of flash firmware " |
| 6261 | "image.\n"); |
| 6262 | ql_log(ql_log_fatal, vha, 0x008d, |
| 6263 | "Firmware data: %08x %08x %08x %08x.\n", |
| 6264 | dcode[0], dcode[1], dcode[2], dcode[3]); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6265 | |
| 6266 | return QLA_FUNCTION_FAILED; |
| 6267 | } |
| 6268 | |
| 6269 | while (segments && rval == QLA_SUCCESS) { |
| 6270 | /* Read segment's load information. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6271 | qla24xx_read_flash_data(vha, dcode, faddr, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6272 | |
| 6273 | risc_addr = be32_to_cpu(dcode[2]); |
| 6274 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 6275 | risc_size = be32_to_cpu(dcode[3]); |
| 6276 | |
| 6277 | fragment = 0; |
| 6278 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 6279 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 6280 | if (dlen > risc_size) |
| 6281 | dlen = risc_size; |
| 6282 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6283 | ql_dbg(ql_dbg_init, vha, 0x008e, |
| 6284 | "Loading risc segment@ risc addr %x " |
| 6285 | "number of dwords 0x%x offset 0x%x.\n", |
| 6286 | risc_addr, dlen, faddr); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6287 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6288 | qla24xx_read_flash_data(vha, dcode, faddr, dlen); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6289 | for (i = 0; i < dlen; i++) |
| 6290 | dcode[i] = swab32(dcode[i]); |
| 6291 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6292 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6293 | dlen); |
| 6294 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6295 | ql_log(ql_log_fatal, vha, 0x008f, |
| 6296 | "Failed to load segment %d of firmware.\n", |
| 6297 | fragment); |
Chad Dupuis | f261f7a | 2014-09-25 05:17:03 -0400 | [diff] [blame] | 6298 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6299 | } |
| 6300 | |
| 6301 | faddr += dlen; |
| 6302 | risc_addr += dlen; |
| 6303 | risc_size -= dlen; |
| 6304 | fragment++; |
| 6305 | } |
| 6306 | |
| 6307 | /* Next segment. */ |
| 6308 | segments--; |
| 6309 | } |
| 6310 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6311 | if (!IS_QLA27XX(ha)) |
| 6312 | return rval; |
| 6313 | |
| 6314 | if (ha->fw_dump_template) |
| 6315 | vfree(ha->fw_dump_template); |
| 6316 | ha->fw_dump_template = NULL; |
| 6317 | ha->fw_dump_template_len = 0; |
| 6318 | |
| 6319 | ql_dbg(ql_dbg_init, vha, 0x0161, |
| 6320 | "Loading fwdump template from %x\n", faddr); |
| 6321 | qla24xx_read_flash_data(vha, dcode, faddr, 7); |
| 6322 | risc_size = be32_to_cpu(dcode[2]); |
| 6323 | ql_dbg(ql_dbg_init, vha, 0x0162, |
| 6324 | "-> array size %x dwords\n", risc_size); |
| 6325 | if (risc_size == 0 || risc_size == ~0) |
| 6326 | goto default_template; |
| 6327 | |
| 6328 | dlen = (risc_size - 8) * sizeof(*dcode); |
| 6329 | ql_dbg(ql_dbg_init, vha, 0x0163, |
| 6330 | "-> template allocating %x bytes...\n", dlen); |
| 6331 | ha->fw_dump_template = vmalloc(dlen); |
| 6332 | if (!ha->fw_dump_template) { |
| 6333 | ql_log(ql_log_warn, vha, 0x0164, |
| 6334 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 6335 | goto default_template; |
| 6336 | } |
| 6337 | |
| 6338 | faddr += 7; |
| 6339 | risc_size -= 8; |
| 6340 | dcode = ha->fw_dump_template; |
| 6341 | qla24xx_read_flash_data(vha, dcode, faddr, risc_size); |
| 6342 | for (i = 0; i < risc_size; i++) |
| 6343 | dcode[i] = le32_to_cpu(dcode[i]); |
| 6344 | |
| 6345 | if (!qla27xx_fwdt_template_valid(dcode)) { |
| 6346 | ql_log(ql_log_warn, vha, 0x0165, |
| 6347 | "Failed fwdump template validate\n"); |
| 6348 | goto default_template; |
| 6349 | } |
| 6350 | |
| 6351 | dlen = qla27xx_fwdt_template_size(dcode); |
| 6352 | ql_dbg(ql_dbg_init, vha, 0x0166, |
| 6353 | "-> template size %x bytes\n", dlen); |
| 6354 | if (dlen > risc_size * sizeof(*dcode)) { |
| 6355 | ql_log(ql_log_warn, vha, 0x0167, |
Chad Dupuis | 97ea702 | 2014-03-13 14:16:40 -0400 | [diff] [blame] | 6356 | "Failed fwdump template exceeds array by %x bytes\n", |
| 6357 | (uint32_t)(dlen - risc_size * sizeof(*dcode))); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6358 | goto default_template; |
| 6359 | } |
| 6360 | ha->fw_dump_template_len = dlen; |
| 6361 | return rval; |
| 6362 | |
| 6363 | default_template: |
| 6364 | ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n"); |
| 6365 | if (ha->fw_dump_template) |
| 6366 | vfree(ha->fw_dump_template); |
| 6367 | ha->fw_dump_template = NULL; |
| 6368 | ha->fw_dump_template_len = 0; |
| 6369 | |
| 6370 | dlen = qla27xx_fwdt_template_default_size(); |
| 6371 | ql_dbg(ql_dbg_init, vha, 0x0169, |
| 6372 | "-> template allocating %x bytes...\n", dlen); |
| 6373 | ha->fw_dump_template = vmalloc(dlen); |
| 6374 | if (!ha->fw_dump_template) { |
| 6375 | ql_log(ql_log_warn, vha, 0x016a, |
| 6376 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 6377 | goto failed_template; |
| 6378 | } |
| 6379 | |
| 6380 | dcode = ha->fw_dump_template; |
| 6381 | risc_size = dlen / sizeof(*dcode); |
| 6382 | memcpy(dcode, qla27xx_fwdt_template_default(), dlen); |
| 6383 | for (i = 0; i < risc_size; i++) |
| 6384 | dcode[i] = be32_to_cpu(dcode[i]); |
| 6385 | |
| 6386 | if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) { |
| 6387 | ql_log(ql_log_warn, vha, 0x016b, |
| 6388 | "Failed fwdump template validate\n"); |
| 6389 | goto failed_template; |
| 6390 | } |
| 6391 | |
| 6392 | dlen = qla27xx_fwdt_template_size(ha->fw_dump_template); |
| 6393 | ql_dbg(ql_dbg_init, vha, 0x016c, |
| 6394 | "-> template size %x bytes\n", dlen); |
| 6395 | ha->fw_dump_template_len = dlen; |
| 6396 | return rval; |
| 6397 | |
| 6398 | failed_template: |
| 6399 | ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n"); |
| 6400 | if (ha->fw_dump_template) |
| 6401 | vfree(ha->fw_dump_template); |
| 6402 | ha->fw_dump_template = NULL; |
| 6403 | ha->fw_dump_template_len = 0; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6404 | return rval; |
| 6405 | } |
| 6406 | |
Giridhar Malavali | e9454a8 | 2013-02-08 01:57:47 -0500 | [diff] [blame] | 6407 | #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/" |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6408 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6409 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6410 | qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6411 | { |
| 6412 | int rval; |
| 6413 | int i, fragment; |
| 6414 | uint16_t *wcode, *fwcode; |
| 6415 | uint32_t risc_addr, risc_size, fwclen, wlen, *seg; |
| 6416 | struct fw_blob *blob; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6417 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6418 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6419 | |
| 6420 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6421 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6422 | if (!blob) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6423 | ql_log(ql_log_info, vha, 0x0083, |
Yannick Guerrini | 94bcf83 | 2015-02-26 22:49:34 +0100 | [diff] [blame] | 6424 | "Firmware image unavailable.\n"); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6425 | ql_log(ql_log_info, vha, 0x0084, |
| 6426 | "Firmware images can be retrieved from: "QLA_FW_URL ".\n"); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6427 | return QLA_FUNCTION_FAILED; |
| 6428 | } |
| 6429 | |
| 6430 | rval = QLA_SUCCESS; |
| 6431 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6432 | wcode = (uint16_t *)req->ring; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6433 | *srisc_addr = 0; |
| 6434 | fwcode = (uint16_t *)blob->fw->data; |
| 6435 | fwclen = 0; |
| 6436 | |
| 6437 | /* Validate firmware image by checking version. */ |
| 6438 | if (blob->fw->size < 8 * sizeof(uint16_t)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6439 | ql_log(ql_log_fatal, vha, 0x0085, |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 6440 | "Unable to verify integrity of firmware image (%zd).\n", |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6441 | blob->fw->size); |
| 6442 | goto fail_fw_integrity; |
| 6443 | } |
| 6444 | for (i = 0; i < 4; i++) |
| 6445 | wcode[i] = be16_to_cpu(fwcode[i + 4]); |
| 6446 | if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff && |
| 6447 | wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 && |
| 6448 | wcode[2] == 0 && wcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6449 | ql_log(ql_log_fatal, vha, 0x0086, |
| 6450 | "Unable to verify integrity of firmware image.\n"); |
| 6451 | ql_log(ql_log_fatal, vha, 0x0087, |
| 6452 | "Firmware data: %04x %04x %04x %04x.\n", |
| 6453 | wcode[0], wcode[1], wcode[2], wcode[3]); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6454 | goto fail_fw_integrity; |
| 6455 | } |
| 6456 | |
| 6457 | seg = blob->segs; |
| 6458 | while (*seg && rval == QLA_SUCCESS) { |
| 6459 | risc_addr = *seg; |
| 6460 | *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr; |
| 6461 | risc_size = be16_to_cpu(fwcode[3]); |
| 6462 | |
| 6463 | /* Validate firmware image size. */ |
| 6464 | fwclen += risc_size * sizeof(uint16_t); |
| 6465 | if (blob->fw->size < fwclen) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6466 | ql_log(ql_log_fatal, vha, 0x0088, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6467 | "Unable to verify integrity of firmware image " |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 6468 | "(%zd).\n", blob->fw->size); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6469 | goto fail_fw_integrity; |
| 6470 | } |
| 6471 | |
| 6472 | fragment = 0; |
| 6473 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 6474 | wlen = (uint16_t)(ha->fw_transfer_size >> 1); |
| 6475 | if (wlen > risc_size) |
| 6476 | wlen = risc_size; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6477 | ql_dbg(ql_dbg_init, vha, 0x0089, |
| 6478 | "Loading risc segment@ risc addr %x number of " |
| 6479 | "words 0x%x.\n", risc_addr, wlen); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6480 | |
| 6481 | for (i = 0; i < wlen; i++) |
| 6482 | wcode[i] = swab16(fwcode[i]); |
| 6483 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6484 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6485 | wlen); |
| 6486 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6487 | ql_log(ql_log_fatal, vha, 0x008a, |
| 6488 | "Failed to load segment %d of firmware.\n", |
| 6489 | fragment); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6490 | break; |
| 6491 | } |
| 6492 | |
| 6493 | fwcode += wlen; |
| 6494 | risc_addr += wlen; |
| 6495 | risc_size -= wlen; |
| 6496 | fragment++; |
| 6497 | } |
| 6498 | |
| 6499 | /* Next segment. */ |
| 6500 | seg++; |
| 6501 | } |
| 6502 | return rval; |
| 6503 | |
| 6504 | fail_fw_integrity: |
| 6505 | return QLA_FUNCTION_FAILED; |
| 6506 | } |
| 6507 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6508 | static int |
| 6509 | 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] | 6510 | { |
| 6511 | int rval; |
| 6512 | int segments, fragment; |
| 6513 | uint32_t *dcode, dlen; |
| 6514 | uint32_t risc_addr; |
| 6515 | uint32_t risc_size; |
| 6516 | uint32_t i; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6517 | struct fw_blob *blob; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6518 | const uint32_t *fwcode; |
| 6519 | uint32_t fwclen; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6520 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6521 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6522 | |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6523 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6524 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6525 | if (!blob) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6526 | ql_log(ql_log_warn, vha, 0x0090, |
Yannick Guerrini | 94bcf83 | 2015-02-26 22:49:34 +0100 | [diff] [blame] | 6527 | "Firmware image unavailable.\n"); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6528 | ql_log(ql_log_warn, vha, 0x0091, |
| 6529 | "Firmware images can be retrieved from: " |
| 6530 | QLA_FW_URL ".\n"); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6531 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6532 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6533 | } |
| 6534 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 6535 | ql_dbg(ql_dbg_init, vha, 0x0092, |
| 6536 | "FW: Loading via request-firmware.\n"); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6537 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6538 | rval = QLA_SUCCESS; |
| 6539 | |
| 6540 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6541 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6542 | *srisc_addr = 0; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6543 | fwcode = (uint32_t *)blob->fw->data; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6544 | fwclen = 0; |
| 6545 | |
| 6546 | /* Validate firmware image by checking version. */ |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6547 | if (blob->fw->size < 8 * sizeof(uint32_t)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6548 | ql_log(ql_log_fatal, vha, 0x0093, |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 6549 | "Unable to verify integrity of firmware image (%zd).\n", |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6550 | blob->fw->size); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6551 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6552 | } |
| 6553 | for (i = 0; i < 4; i++) |
| 6554 | dcode[i] = be32_to_cpu(fwcode[i + 4]); |
| 6555 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 6556 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 6557 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 6558 | dcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6559 | ql_log(ql_log_fatal, vha, 0x0094, |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 6560 | "Unable to verify integrity of firmware image (%zd).\n", |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6561 | blob->fw->size); |
| 6562 | ql_log(ql_log_fatal, vha, 0x0095, |
| 6563 | "Firmware data: %08x %08x %08x %08x.\n", |
| 6564 | dcode[0], dcode[1], dcode[2], dcode[3]); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6565 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6566 | } |
| 6567 | |
| 6568 | while (segments && rval == QLA_SUCCESS) { |
| 6569 | risc_addr = be32_to_cpu(fwcode[2]); |
| 6570 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 6571 | risc_size = be32_to_cpu(fwcode[3]); |
| 6572 | |
| 6573 | /* Validate firmware image size. */ |
| 6574 | fwclen += risc_size * sizeof(uint32_t); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6575 | if (blob->fw->size < fwclen) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6576 | ql_log(ql_log_fatal, vha, 0x0096, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6577 | "Unable to verify integrity of firmware image " |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 6578 | "(%zd).\n", blob->fw->size); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6579 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6580 | } |
| 6581 | |
| 6582 | fragment = 0; |
| 6583 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 6584 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 6585 | if (dlen > risc_size) |
| 6586 | dlen = risc_size; |
| 6587 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6588 | ql_dbg(ql_dbg_init, vha, 0x0097, |
| 6589 | "Loading risc segment@ risc addr %x " |
| 6590 | "number of dwords 0x%x.\n", risc_addr, dlen); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6591 | |
| 6592 | for (i = 0; i < dlen; i++) |
| 6593 | dcode[i] = swab32(fwcode[i]); |
| 6594 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6595 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
andrew.vasquez@qlogic.com | 590f98e | 2006-01-13 17:05:37 -0800 | [diff] [blame] | 6596 | dlen); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6597 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6598 | ql_log(ql_log_fatal, vha, 0x0098, |
| 6599 | "Failed to load segment %d of firmware.\n", |
| 6600 | fragment); |
Chad Dupuis | f261f7a | 2014-09-25 05:17:03 -0400 | [diff] [blame] | 6601 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6602 | } |
| 6603 | |
| 6604 | fwcode += dlen; |
| 6605 | risc_addr += dlen; |
| 6606 | risc_size -= dlen; |
| 6607 | fragment++; |
| 6608 | } |
| 6609 | |
| 6610 | /* Next segment. */ |
| 6611 | segments--; |
| 6612 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6613 | |
| 6614 | if (!IS_QLA27XX(ha)) |
| 6615 | return rval; |
| 6616 | |
| 6617 | if (ha->fw_dump_template) |
| 6618 | vfree(ha->fw_dump_template); |
| 6619 | ha->fw_dump_template = NULL; |
| 6620 | ha->fw_dump_template_len = 0; |
| 6621 | |
| 6622 | ql_dbg(ql_dbg_init, vha, 0x171, |
Chad Dupuis | 97ea702 | 2014-03-13 14:16:40 -0400 | [diff] [blame] | 6623 | "Loading fwdump template from %x\n", |
| 6624 | (uint32_t)((void *)fwcode - (void *)blob->fw->data)); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6625 | risc_size = be32_to_cpu(fwcode[2]); |
| 6626 | ql_dbg(ql_dbg_init, vha, 0x172, |
| 6627 | "-> array size %x dwords\n", risc_size); |
| 6628 | if (risc_size == 0 || risc_size == ~0) |
| 6629 | goto default_template; |
| 6630 | |
| 6631 | dlen = (risc_size - 8) * sizeof(*fwcode); |
| 6632 | ql_dbg(ql_dbg_init, vha, 0x0173, |
| 6633 | "-> template allocating %x bytes...\n", dlen); |
| 6634 | ha->fw_dump_template = vmalloc(dlen); |
| 6635 | if (!ha->fw_dump_template) { |
| 6636 | ql_log(ql_log_warn, vha, 0x0174, |
| 6637 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 6638 | goto default_template; |
| 6639 | } |
| 6640 | |
| 6641 | fwcode += 7; |
| 6642 | risc_size -= 8; |
| 6643 | dcode = ha->fw_dump_template; |
| 6644 | for (i = 0; i < risc_size; i++) |
| 6645 | dcode[i] = le32_to_cpu(fwcode[i]); |
| 6646 | |
| 6647 | if (!qla27xx_fwdt_template_valid(dcode)) { |
| 6648 | ql_log(ql_log_warn, vha, 0x0175, |
| 6649 | "Failed fwdump template validate\n"); |
| 6650 | goto default_template; |
| 6651 | } |
| 6652 | |
| 6653 | dlen = qla27xx_fwdt_template_size(dcode); |
| 6654 | ql_dbg(ql_dbg_init, vha, 0x0176, |
| 6655 | "-> template size %x bytes\n", dlen); |
| 6656 | if (dlen > risc_size * sizeof(*fwcode)) { |
| 6657 | ql_log(ql_log_warn, vha, 0x0177, |
Chad Dupuis | 97ea702 | 2014-03-13 14:16:40 -0400 | [diff] [blame] | 6658 | "Failed fwdump template exceeds array by %x bytes\n", |
| 6659 | (uint32_t)(dlen - risc_size * sizeof(*fwcode))); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6660 | goto default_template; |
| 6661 | } |
| 6662 | ha->fw_dump_template_len = dlen; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6663 | return rval; |
| 6664 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6665 | default_template: |
| 6666 | ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n"); |
| 6667 | if (ha->fw_dump_template) |
| 6668 | vfree(ha->fw_dump_template); |
| 6669 | ha->fw_dump_template = NULL; |
| 6670 | ha->fw_dump_template_len = 0; |
| 6671 | |
| 6672 | dlen = qla27xx_fwdt_template_default_size(); |
| 6673 | ql_dbg(ql_dbg_init, vha, 0x0179, |
| 6674 | "-> template allocating %x bytes...\n", dlen); |
| 6675 | ha->fw_dump_template = vmalloc(dlen); |
| 6676 | if (!ha->fw_dump_template) { |
| 6677 | ql_log(ql_log_warn, vha, 0x017a, |
| 6678 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 6679 | goto failed_template; |
| 6680 | } |
| 6681 | |
| 6682 | dcode = ha->fw_dump_template; |
| 6683 | risc_size = dlen / sizeof(*fwcode); |
| 6684 | fwcode = qla27xx_fwdt_template_default(); |
| 6685 | for (i = 0; i < risc_size; i++) |
| 6686 | dcode[i] = be32_to_cpu(fwcode[i]); |
| 6687 | |
| 6688 | if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) { |
| 6689 | ql_log(ql_log_warn, vha, 0x017b, |
| 6690 | "Failed fwdump template validate\n"); |
| 6691 | goto failed_template; |
| 6692 | } |
| 6693 | |
| 6694 | dlen = qla27xx_fwdt_template_size(ha->fw_dump_template); |
| 6695 | ql_dbg(ql_dbg_init, vha, 0x017c, |
| 6696 | "-> template size %x bytes\n", dlen); |
| 6697 | ha->fw_dump_template_len = dlen; |
| 6698 | return rval; |
| 6699 | |
| 6700 | failed_template: |
| 6701 | ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n"); |
| 6702 | if (ha->fw_dump_template) |
| 6703 | vfree(ha->fw_dump_template); |
| 6704 | ha->fw_dump_template = NULL; |
| 6705 | ha->fw_dump_template_len = 0; |
| 6706 | return rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6707 | } |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6708 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6709 | int |
| 6710 | qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 6711 | { |
| 6712 | int rval; |
| 6713 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 6714 | if (ql2xfwloadbin == 1) |
| 6715 | return qla81xx_load_risc(vha, srisc_addr); |
| 6716 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6717 | /* |
| 6718 | * FW Load priority: |
| 6719 | * 1) Firmware via request-firmware interface (.bin file). |
| 6720 | * 2) Firmware residing in flash. |
| 6721 | */ |
| 6722 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 6723 | if (rval == QLA_SUCCESS) |
| 6724 | return rval; |
| 6725 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6726 | return qla24xx_load_risc_flash(vha, srisc_addr, |
| 6727 | vha->hw->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6728 | } |
| 6729 | |
| 6730 | int |
| 6731 | qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 6732 | { |
| 6733 | int rval; |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6734 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6735 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 6736 | if (ql2xfwloadbin == 2) |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6737 | goto try_blob_fw; |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 6738 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6739 | /* |
| 6740 | * FW Load priority: |
| 6741 | * 1) Firmware residing in flash. |
| 6742 | * 2) Firmware via request-firmware interface (.bin file). |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6743 | * 3) Golden-Firmware residing in flash -- limited operation. |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6744 | */ |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6745 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6746 | if (rval == QLA_SUCCESS) |
| 6747 | return rval; |
| 6748 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6749 | try_blob_fw: |
| 6750 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 6751 | if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw) |
| 6752 | return rval; |
| 6753 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6754 | ql_log(ql_log_info, vha, 0x0099, |
| 6755 | "Attempting to fallback to golden firmware.\n"); |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6756 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw); |
| 6757 | if (rval != QLA_SUCCESS) |
| 6758 | return rval; |
| 6759 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6760 | ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n"); |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6761 | ha->flags.running_gold_fw = 1; |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6762 | return rval; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6763 | } |
| 6764 | |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6765 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6766 | qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6767 | { |
| 6768 | int ret, retries; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6769 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6770 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 6771 | if (ha->flags.pci_channel_io_perm_failure) |
| 6772 | return; |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 6773 | if (!IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6774 | return; |
Andrew Vasquez | 75edf81 | 2007-05-07 07:43:00 -0700 | [diff] [blame] | 6775 | if (!ha->fw_major_version) |
| 6776 | return; |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 6777 | if (!ha->flags.fw_started) |
| 6778 | return; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6779 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6780 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 7c7f1f2 | 2008-02-28 14:06:09 -0800 | [diff] [blame] | 6781 | for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT && |
Andrew Vasquez | b469a7c | 2009-04-06 22:33:48 -0700 | [diff] [blame] | 6782 | ret != QLA_INVALID_COMMAND && retries ; retries--) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6783 | ha->isp_ops->reset_chip(vha); |
| 6784 | if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6785 | continue; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6786 | if (qla2x00_setup_chip(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6787 | continue; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6788 | ql_log(ql_log_info, vha, 0x8015, |
| 6789 | "Attempting retry of stop-firmware command.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6790 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6791 | } |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 6792 | |
| 6793 | ha->flags.fw_started = 0; |
| 6794 | ha->flags.fw_init_done = 0; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6795 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6796 | |
| 6797 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6798 | qla24xx_configure_vhba(scsi_qla_host_t *vha) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6799 | { |
| 6800 | int rval = QLA_SUCCESS; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 6801 | int rval2; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6802 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6803 | struct qla_hw_data *ha = vha->hw; |
| 6804 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 6805 | struct req_que *req; |
| 6806 | struct rsp_que *rsp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6807 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6808 | if (!vha->vp_idx) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6809 | return -EINVAL; |
| 6810 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6811 | rval = qla2x00_fw_ready(base_vha); |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 6812 | if (vha->qpair) |
| 6813 | req = vha->qpair->req; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 6814 | else |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 6815 | req = ha->req_q_map[0]; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 6816 | rsp = req->rsp; |
| 6817 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6818 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6819 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6820 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6821 | } |
| 6822 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6823 | vha->flags.management_server_logged_in = 0; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6824 | |
| 6825 | /* Login to SNS first */ |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 6826 | rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, |
| 6827 | BIT_1); |
| 6828 | if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) { |
| 6829 | if (rval2 == QLA_MEMORY_ALLOC_FAILED) |
| 6830 | ql_dbg(ql_dbg_init, vha, 0x0120, |
| 6831 | "Failed SNS login: loop_id=%x, rval2=%d\n", |
| 6832 | NPH_SNS, rval2); |
| 6833 | else |
| 6834 | ql_dbg(ql_dbg_init, vha, 0x0103, |
| 6835 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x " |
| 6836 | "mb[2]=%x mb[6]=%x mb[7]=%x.\n", |
| 6837 | NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6838 | return (QLA_FUNCTION_FAILED); |
| 6839 | } |
| 6840 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6841 | atomic_set(&vha->loop_down_timer, 0); |
| 6842 | atomic_set(&vha->loop_state, LOOP_UP); |
| 6843 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 6844 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 6845 | rval = qla2x00_loop_resync(base_vha); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6846 | |
| 6847 | return rval; |
| 6848 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6849 | |
| 6850 | /* 84XX Support **************************************************************/ |
| 6851 | |
| 6852 | static LIST_HEAD(qla_cs84xx_list); |
| 6853 | static DEFINE_MUTEX(qla_cs84xx_mutex); |
| 6854 | |
| 6855 | static struct qla_chip_state_84xx * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6856 | qla84xx_get_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6857 | { |
| 6858 | struct qla_chip_state_84xx *cs84xx; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6859 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6860 | |
| 6861 | mutex_lock(&qla_cs84xx_mutex); |
| 6862 | |
| 6863 | /* Find any shared 84xx chip. */ |
| 6864 | list_for_each_entry(cs84xx, &qla_cs84xx_list, list) { |
| 6865 | if (cs84xx->bus == ha->pdev->bus) { |
| 6866 | kref_get(&cs84xx->kref); |
| 6867 | goto done; |
| 6868 | } |
| 6869 | } |
| 6870 | |
| 6871 | cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL); |
| 6872 | if (!cs84xx) |
| 6873 | goto done; |
| 6874 | |
| 6875 | kref_init(&cs84xx->kref); |
| 6876 | spin_lock_init(&cs84xx->access_lock); |
| 6877 | mutex_init(&cs84xx->fw_update_mutex); |
| 6878 | cs84xx->bus = ha->pdev->bus; |
| 6879 | |
| 6880 | list_add_tail(&cs84xx->list, &qla_cs84xx_list); |
| 6881 | done: |
| 6882 | mutex_unlock(&qla_cs84xx_mutex); |
| 6883 | return cs84xx; |
| 6884 | } |
| 6885 | |
| 6886 | static void |
| 6887 | __qla84xx_chip_release(struct kref *kref) |
| 6888 | { |
| 6889 | struct qla_chip_state_84xx *cs84xx = |
| 6890 | container_of(kref, struct qla_chip_state_84xx, kref); |
| 6891 | |
| 6892 | mutex_lock(&qla_cs84xx_mutex); |
| 6893 | list_del(&cs84xx->list); |
| 6894 | mutex_unlock(&qla_cs84xx_mutex); |
| 6895 | kfree(cs84xx); |
| 6896 | } |
| 6897 | |
| 6898 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6899 | qla84xx_put_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6900 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6901 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6902 | if (ha->cs84xx) |
| 6903 | kref_put(&ha->cs84xx->kref, __qla84xx_chip_release); |
| 6904 | } |
| 6905 | |
| 6906 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6907 | qla84xx_init_chip(scsi_qla_host_t *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6908 | { |
| 6909 | int rval; |
| 6910 | uint16_t status[2]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6911 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6912 | |
| 6913 | mutex_lock(&ha->cs84xx->fw_update_mutex); |
| 6914 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6915 | rval = qla84xx_verify_chip(vha, status); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6916 | |
| 6917 | mutex_unlock(&ha->cs84xx->fw_update_mutex); |
| 6918 | |
| 6919 | return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED: |
| 6920 | QLA_SUCCESS; |
| 6921 | } |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6922 | |
| 6923 | /* 81XX Support **************************************************************/ |
| 6924 | |
| 6925 | int |
| 6926 | qla81xx_nvram_config(scsi_qla_host_t *vha) |
| 6927 | { |
| 6928 | int rval; |
| 6929 | struct init_cb_81xx *icb; |
| 6930 | struct nvram_81xx *nv; |
| 6931 | uint32_t *dptr; |
| 6932 | uint8_t *dptr1, *dptr2; |
| 6933 | uint32_t chksum; |
| 6934 | uint16_t cnt; |
| 6935 | struct qla_hw_data *ha = vha->hw; |
| 6936 | |
| 6937 | rval = QLA_SUCCESS; |
| 6938 | icb = (struct init_cb_81xx *)ha->init_cb; |
| 6939 | nv = ha->nvram; |
| 6940 | |
| 6941 | /* Determine NVRAM starting address. */ |
| 6942 | ha->nvram_size = sizeof(struct nvram_81xx); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6943 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 6944 | if (IS_P3P_TYPE(ha) || IS_QLA8031(ha)) |
| 6945 | ha->vpd_size = FA_VPD_SIZE_82XX; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6946 | |
| 6947 | /* Get VPD data into cache */ |
| 6948 | ha->vpd = ha->nvram + VPD_OFFSET; |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 6949 | ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2, |
| 6950 | ha->vpd_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6951 | |
| 6952 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 6953 | 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] | 6954 | ha->nvram_size); |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 6955 | dptr = (uint32_t *)nv; |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 6956 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++) |
| 6957 | chksum += le32_to_cpu(*dptr); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6958 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6959 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111, |
| 6960 | "Contents of NVRAM:\n"); |
| 6961 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112, |
| 6962 | (uint8_t *)nv, ha->nvram_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6963 | |
| 6964 | /* Bad NVRAM data, set defaults parameters. */ |
| 6965 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 6966 | || nv->id[3] != ' ' || |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6967 | nv->nvram_version < cpu_to_le16(ICB_VERSION)) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6968 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6969 | ql_log(ql_log_info, vha, 0x0073, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 6970 | "Inconsistent NVRAM detected: checksum=0x%x id=%c " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6971 | "version=0x%x.\n", chksum, nv->id[0], |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6972 | le16_to_cpu(nv->nvram_version)); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6973 | ql_log(ql_log_info, vha, 0x0074, |
| 6974 | "Falling back to functioning (yet invalid -- WWPN) " |
| 6975 | "defaults.\n"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6976 | |
| 6977 | /* |
| 6978 | * Set default initialization control block. |
| 6979 | */ |
| 6980 | memset(nv, 0, ha->nvram_size); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6981 | nv->nvram_version = cpu_to_le16(ICB_VERSION); |
| 6982 | nv->version = cpu_to_le16(ICB_VERSION); |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 6983 | nv->frame_payload_size = 2048; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6984 | nv->execution_throttle = cpu_to_le16(0xFFFF); |
| 6985 | nv->exchange_count = cpu_to_le16(0); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6986 | nv->port_name[0] = 0x21; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6987 | nv->port_name[1] = 0x00 + ha->port_no + 1; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6988 | nv->port_name[2] = 0x00; |
| 6989 | nv->port_name[3] = 0xe0; |
| 6990 | nv->port_name[4] = 0x8b; |
| 6991 | nv->port_name[5] = 0x1c; |
| 6992 | nv->port_name[6] = 0x55; |
| 6993 | nv->port_name[7] = 0x86; |
| 6994 | nv->node_name[0] = 0x20; |
| 6995 | nv->node_name[1] = 0x00; |
| 6996 | nv->node_name[2] = 0x00; |
| 6997 | nv->node_name[3] = 0xe0; |
| 6998 | nv->node_name[4] = 0x8b; |
| 6999 | nv->node_name[5] = 0x1c; |
| 7000 | nv->node_name[6] = 0x55; |
| 7001 | nv->node_name[7] = 0x86; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7002 | nv->login_retry_count = cpu_to_le16(8); |
| 7003 | nv->interrupt_delay_timer = cpu_to_le16(0); |
| 7004 | nv->login_timeout = cpu_to_le16(0); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7005 | nv->firmware_options_1 = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7006 | cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 7007 | nv->firmware_options_2 = cpu_to_le32(2 << 4); |
| 7008 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 7009 | nv->firmware_options_3 = cpu_to_le32(2 << 13); |
| 7010 | nv->host_p = cpu_to_le32(BIT_11|BIT_10); |
| 7011 | nv->efi_parameters = cpu_to_le32(0); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7012 | nv->reset_delay = 5; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7013 | nv->max_luns_per_target = cpu_to_le16(128); |
| 7014 | nv->port_down_retry_count = cpu_to_le16(30); |
| 7015 | nv->link_down_timeout = cpu_to_le16(180); |
Andrew Vasquez | eeebcc9 | 2009-06-03 09:55:24 -0700 | [diff] [blame] | 7016 | nv->enode_mac[0] = 0x00; |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 7017 | nv->enode_mac[1] = 0xC0; |
| 7018 | nv->enode_mac[2] = 0xDD; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7019 | nv->enode_mac[3] = 0x04; |
| 7020 | nv->enode_mac[4] = 0x05; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7021 | nv->enode_mac[5] = 0x06 + ha->port_no + 1; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7022 | |
| 7023 | rval = 1; |
| 7024 | } |
| 7025 | |
Arun Easi | 9e522cd | 2012-08-22 14:21:31 -0400 | [diff] [blame] | 7026 | if (IS_T10_PI_CAPABLE(ha)) |
| 7027 | nv->frame_payload_size &= ~7; |
| 7028 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7029 | qlt_81xx_config_nvram_stage1(vha, nv); |
| 7030 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7031 | /* Reset Initialization control block */ |
Andrew Vasquez | 773120e | 2011-05-10 11:30:14 -0700 | [diff] [blame] | 7032 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7033 | |
| 7034 | /* Copy 1st segment. */ |
| 7035 | dptr1 = (uint8_t *)icb; |
| 7036 | dptr2 = (uint8_t *)&nv->version; |
| 7037 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 7038 | while (cnt--) |
| 7039 | *dptr1++ = *dptr2++; |
| 7040 | |
| 7041 | icb->login_retry_count = nv->login_retry_count; |
| 7042 | |
| 7043 | /* Copy 2nd segment. */ |
| 7044 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 7045 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 7046 | cnt = (uint8_t *)&icb->reserved_5 - |
| 7047 | (uint8_t *)&icb->interrupt_delay_timer; |
| 7048 | while (cnt--) |
| 7049 | *dptr1++ = *dptr2++; |
| 7050 | |
| 7051 | memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac)); |
| 7052 | /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */ |
| 7053 | 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] | 7054 | icb->enode_mac[0] = 0x00; |
| 7055 | icb->enode_mac[1] = 0xC0; |
| 7056 | icb->enode_mac[2] = 0xDD; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7057 | icb->enode_mac[3] = 0x04; |
| 7058 | icb->enode_mac[4] = 0x05; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7059 | icb->enode_mac[5] = 0x06 + ha->port_no + 1; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7060 | } |
| 7061 | |
Andrew Vasquez | b64b0e8 | 2009-03-24 09:08:01 -0700 | [diff] [blame] | 7062 | /* Use extended-initialization control block. */ |
| 7063 | memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb)); |
| 7064 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7065 | /* |
| 7066 | * Setup driver NVRAM options. |
| 7067 | */ |
| 7068 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7069 | "QLE8XXX"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7070 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7071 | qlt_81xx_config_nvram_stage2(vha, icb); |
| 7072 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7073 | /* Use alternate WWN? */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7074 | if (nv->host_p & cpu_to_le32(BIT_15)) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7075 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 7076 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 7077 | } |
| 7078 | |
| 7079 | /* Prepare nodename */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7080 | if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7081 | /* |
| 7082 | * Firmware will apply the following mask if the nodename was |
| 7083 | * not provided. |
| 7084 | */ |
| 7085 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 7086 | icb->node_name[0] &= 0xF0; |
| 7087 | } |
| 7088 | |
| 7089 | /* Set host adapter parameters. */ |
| 7090 | ha->flags.disable_risc_code_load = 0; |
| 7091 | ha->flags.enable_lip_reset = 0; |
| 7092 | ha->flags.enable_lip_full_login = |
| 7093 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 7094 | ha->flags.enable_target_reset = |
| 7095 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
| 7096 | ha->flags.enable_led_scheme = 0; |
| 7097 | ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0; |
| 7098 | |
| 7099 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 7100 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 7101 | |
| 7102 | /* save HBA serial number */ |
| 7103 | ha->serial0 = icb->port_name[5]; |
| 7104 | ha->serial1 = icb->port_name[6]; |
| 7105 | ha->serial2 = icb->port_name[7]; |
| 7106 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 7107 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
| 7108 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7109 | icb->execution_throttle = cpu_to_le16(0xFFFF); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7110 | |
| 7111 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 7112 | |
| 7113 | /* Set minimum login_timeout to 4 seconds. */ |
| 7114 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 7115 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 7116 | if (le16_to_cpu(nv->login_timeout) < 4) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7117 | nv->login_timeout = cpu_to_le16(4); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7118 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7119 | |
| 7120 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 7121 | ha->r_a_tov = 100; |
| 7122 | |
| 7123 | ha->loop_reset_delay = nv->reset_delay; |
| 7124 | |
| 7125 | /* Link Down Timeout = 0: |
| 7126 | * |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 7127 | * When Port Down timer expires we will start returning |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7128 | * I/O's to OS with "DID_NO_CONNECT". |
| 7129 | * |
| 7130 | * Link Down Timeout != 0: |
| 7131 | * |
| 7132 | * The driver waits for the link to come up after link down |
| 7133 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 7134 | */ |
| 7135 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 7136 | ha->loop_down_abort_time = |
| 7137 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 7138 | } else { |
| 7139 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 7140 | ha->loop_down_abort_time = |
| 7141 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 7142 | } |
| 7143 | |
| 7144 | /* Need enough time to try and get the port back. */ |
| 7145 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 7146 | if (qlport_down_retry) |
| 7147 | ha->port_down_retry_count = qlport_down_retry; |
| 7148 | |
| 7149 | /* Set login_retry_count */ |
| 7150 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 7151 | if (ha->port_down_retry_count == |
| 7152 | le16_to_cpu(nv->port_down_retry_count) && |
| 7153 | ha->port_down_retry_count > 3) |
| 7154 | ha->login_retry_count = ha->port_down_retry_count; |
| 7155 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 7156 | ha->login_retry_count = ha->port_down_retry_count; |
| 7157 | if (ql2xloginretrycount) |
| 7158 | ha->login_retry_count = ql2xloginretrycount; |
| 7159 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 7160 | /* if not running MSI-X we need handshaking on interrupts */ |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7161 | 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] | 7162 | icb->firmware_options_2 |= cpu_to_le32(BIT_22); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 7163 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7164 | /* Enable ZIO. */ |
| 7165 | if (!vha->flags.init_done) { |
| 7166 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 7167 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 7168 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 7169 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 7170 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7171 | icb->firmware_options_2 &= cpu_to_le32( |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7172 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
| 7173 | vha->flags.process_response_queue = 0; |
| 7174 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
| 7175 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 7176 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7177 | ql_log(ql_log_info, vha, 0x0075, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7178 | "ZIO mode %d enabled; timer delay (%d us).\n", |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7179 | ha->zio_mode, |
| 7180 | ha->zio_timer * 100); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7181 | |
| 7182 | icb->firmware_options_2 |= cpu_to_le32( |
| 7183 | (uint32_t)ha->zio_mode); |
| 7184 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
| 7185 | vha->flags.process_response_queue = 1; |
| 7186 | } |
| 7187 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 7188 | /* enable RIDA Format2 */ |
| 7189 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) |
| 7190 | icb->firmware_options_3 |= BIT_0; |
| 7191 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7192 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7193 | ql_log(ql_log_warn, vha, 0x0076, |
| 7194 | "NVRAM configuration failed.\n"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7195 | } |
| 7196 | return (rval); |
| 7197 | } |
| 7198 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7199 | int |
| 7200 | qla82xx_restart_isp(scsi_qla_host_t *vha) |
| 7201 | { |
| 7202 | int status, rval; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7203 | struct qla_hw_data *ha = vha->hw; |
| 7204 | struct req_que *req = ha->req_q_map[0]; |
| 7205 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
| 7206 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 7207 | unsigned long flags; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7208 | |
| 7209 | status = qla2x00_init_rings(vha); |
| 7210 | if (!status) { |
| 7211 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 7212 | ha->flags.chip_reset_done = 1; |
| 7213 | |
| 7214 | status = qla2x00_fw_ready(vha); |
| 7215 | if (!status) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7216 | /* Issue a marker after FW becomes ready. */ |
| 7217 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7218 | vha->flags.online = 1; |
Chad Dupuis | 7108b76 | 2014-04-11 16:54:45 -0400 | [diff] [blame] | 7219 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7220 | } |
| 7221 | |
| 7222 | /* if no cable then assume it's good */ |
| 7223 | if ((vha->device_flags & DFLG_NO_CABLE)) |
| 7224 | status = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7225 | } |
| 7226 | |
| 7227 | if (!status) { |
| 7228 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 7229 | |
| 7230 | if (!atomic_read(&vha->loop_down_timer)) { |
| 7231 | /* |
| 7232 | * Issue marker command only when we are going |
| 7233 | * to start the I/O . |
| 7234 | */ |
| 7235 | vha->marker_needed = 1; |
| 7236 | } |
| 7237 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7238 | ha->isp_ops->enable_intrs(ha); |
| 7239 | |
| 7240 | ha->isp_abort_cnt = 0; |
| 7241 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 7242 | |
Saurav Kashyap | 5329678 | 2011-05-10 11:30:06 -0700 | [diff] [blame] | 7243 | /* Update the firmware version */ |
Giridhar Malavali | 3173167 | 2011-08-16 11:31:54 -0700 | [diff] [blame] | 7244 | status = qla82xx_check_md_needed(vha); |
Saurav Kashyap | 5329678 | 2011-05-10 11:30:06 -0700 | [diff] [blame] | 7245 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7246 | if (ha->fce) { |
| 7247 | ha->flags.fce_enabled = 1; |
| 7248 | memset(ha->fce, 0, |
| 7249 | fce_calc_size(ha->fce_bufs)); |
| 7250 | rval = qla2x00_enable_fce_trace(vha, |
| 7251 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 7252 | &ha->fce_bufs); |
| 7253 | if (rval) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7254 | ql_log(ql_log_warn, vha, 0x8001, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7255 | "Unable to reinitialize FCE (%d).\n", |
| 7256 | rval); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7257 | ha->flags.fce_enabled = 0; |
| 7258 | } |
| 7259 | } |
| 7260 | |
| 7261 | if (ha->eft) { |
| 7262 | memset(ha->eft, 0, EFT_SIZE); |
| 7263 | rval = qla2x00_enable_eft_trace(vha, |
| 7264 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 7265 | if (rval) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7266 | ql_log(ql_log_warn, vha, 0x8010, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7267 | "Unable to reinitialize EFT (%d).\n", |
| 7268 | rval); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7269 | } |
| 7270 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7271 | } |
| 7272 | |
| 7273 | if (!status) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7274 | ql_dbg(ql_dbg_taskm, vha, 0x8011, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7275 | "qla82xx_restart_isp succeeded.\n"); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 7276 | |
| 7277 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 7278 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 7279 | if (vp->vp_idx) { |
| 7280 | atomic_inc(&vp->vref_count); |
| 7281 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 7282 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7283 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 7284 | |
| 7285 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 7286 | atomic_dec(&vp->vref_count); |
| 7287 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7288 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 7289 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 7290 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7291 | } else { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7292 | ql_log(ql_log_warn, vha, 0x8016, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7293 | "qla82xx_restart_isp **** FAILED ****.\n"); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7294 | } |
| 7295 | |
| 7296 | return status; |
| 7297 | } |
| 7298 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7299 | void |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 7300 | qla81xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7301 | { |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 7302 | struct qla_hw_data *ha = vha->hw; |
| 7303 | |
Himanshu Madhani | f198caf | 2016-01-27 12:03:30 -0500 | [diff] [blame] | 7304 | /* Hold status IOCBs until ABTS response received. */ |
| 7305 | if (ql2xfwholdabts) |
| 7306 | ha->fw_options[3] |= BIT_12; |
| 7307 | |
Giridhar Malavali | 088d09d | 2016-07-06 11:14:20 -0400 | [diff] [blame] | 7308 | /* Set Retry FLOGI in case of P2P connection */ |
| 7309 | if (ha->operating_mode == P2P) { |
| 7310 | ha->fw_options[2] |= BIT_3; |
| 7311 | ql_dbg(ql_dbg_disc, vha, 0x2103, |
| 7312 | "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n", |
| 7313 | __func__, ha->fw_options[2]); |
| 7314 | } |
| 7315 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 7316 | /* Move PUREX, ABTS RX & RIDA to ATIOQ */ |
| 7317 | if (ql2xmvasynctoatio) { |
| 7318 | if (qla_tgt_mode_enabled(vha) || |
| 7319 | qla_dual_mode_enabled(vha)) |
| 7320 | ha->fw_options[2] |= BIT_11; |
| 7321 | else |
| 7322 | ha->fw_options[2] &= ~BIT_11; |
| 7323 | } |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 7324 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 7325 | if (ql2xetsenable) { |
| 7326 | /* Enable ETS Burst. */ |
| 7327 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
| 7328 | ha->fw_options[2] |= BIT_9; |
| 7329 | } |
| 7330 | |
| 7331 | ql_dbg(ql_dbg_init, vha, 0xffff, |
| 7332 | "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n", |
| 7333 | __func__, ha->fw_options[1], ha->fw_options[2], |
| 7334 | ha->fw_options[3], vha->host->active_mode); |
| 7335 | |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 7336 | qla2x00_set_fw_options(vha, ha->fw_options); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7337 | } |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7338 | |
| 7339 | /* |
| 7340 | * qla24xx_get_fcp_prio |
| 7341 | * Gets the fcp cmd priority value for the logged in port. |
| 7342 | * Looks for a match of the port descriptors within |
| 7343 | * each of the fcp prio config entries. If a match is found, |
| 7344 | * the tag (priority) value is returned. |
| 7345 | * |
| 7346 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 7347 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7348 | * fcport = port structure pointer. |
| 7349 | * |
| 7350 | * Return: |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 7351 | * non-zero (if found) |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7352 | * -1 (if not found) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7353 | * |
| 7354 | * Context: |
| 7355 | * Kernel context |
| 7356 | */ |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7357 | static int |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7358 | qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 7359 | { |
| 7360 | int i, entries; |
| 7361 | uint8_t pid_match, wwn_match; |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7362 | int priority; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7363 | uint32_t pid1, pid2; |
| 7364 | uint64_t wwn1, wwn2; |
| 7365 | struct qla_fcp_prio_entry *pri_entry; |
| 7366 | struct qla_hw_data *ha = vha->hw; |
| 7367 | |
| 7368 | if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled) |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7369 | return -1; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7370 | |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7371 | priority = -1; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7372 | entries = ha->fcp_prio_cfg->num_entries; |
| 7373 | pri_entry = &ha->fcp_prio_cfg->entry[0]; |
| 7374 | |
| 7375 | for (i = 0; i < entries; i++) { |
| 7376 | pid_match = wwn_match = 0; |
| 7377 | |
| 7378 | if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) { |
| 7379 | pri_entry++; |
| 7380 | continue; |
| 7381 | } |
| 7382 | |
| 7383 | /* check source pid for a match */ |
| 7384 | if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) { |
| 7385 | pid1 = pri_entry->src_pid & INVALID_PORT_ID; |
| 7386 | pid2 = vha->d_id.b24 & INVALID_PORT_ID; |
| 7387 | if (pid1 == INVALID_PORT_ID) |
| 7388 | pid_match++; |
| 7389 | else if (pid1 == pid2) |
| 7390 | pid_match++; |
| 7391 | } |
| 7392 | |
| 7393 | /* check destination pid for a match */ |
| 7394 | if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) { |
| 7395 | pid1 = pri_entry->dst_pid & INVALID_PORT_ID; |
| 7396 | pid2 = fcport->d_id.b24 & INVALID_PORT_ID; |
| 7397 | if (pid1 == INVALID_PORT_ID) |
| 7398 | pid_match++; |
| 7399 | else if (pid1 == pid2) |
| 7400 | pid_match++; |
| 7401 | } |
| 7402 | |
| 7403 | /* check source WWN for a match */ |
| 7404 | if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) { |
| 7405 | wwn1 = wwn_to_u64(vha->port_name); |
| 7406 | wwn2 = wwn_to_u64(pri_entry->src_wwpn); |
| 7407 | if (wwn2 == (uint64_t)-1) |
| 7408 | wwn_match++; |
| 7409 | else if (wwn1 == wwn2) |
| 7410 | wwn_match++; |
| 7411 | } |
| 7412 | |
| 7413 | /* check destination WWN for a match */ |
| 7414 | if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) { |
| 7415 | wwn1 = wwn_to_u64(fcport->port_name); |
| 7416 | wwn2 = wwn_to_u64(pri_entry->dst_wwpn); |
| 7417 | if (wwn2 == (uint64_t)-1) |
| 7418 | wwn_match++; |
| 7419 | else if (wwn1 == wwn2) |
| 7420 | wwn_match++; |
| 7421 | } |
| 7422 | |
| 7423 | if (pid_match == 2 || wwn_match == 2) { |
| 7424 | /* Found a matching entry */ |
| 7425 | if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID) |
| 7426 | priority = pri_entry->tag; |
| 7427 | break; |
| 7428 | } |
| 7429 | |
| 7430 | pri_entry++; |
| 7431 | } |
| 7432 | |
| 7433 | return priority; |
| 7434 | } |
| 7435 | |
| 7436 | /* |
| 7437 | * qla24xx_update_fcport_fcp_prio |
| 7438 | * Activates fcp priority for the logged in fc port |
| 7439 | * |
| 7440 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 7441 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7442 | * fcp = port structure pointer. |
| 7443 | * |
| 7444 | * Return: |
| 7445 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 7446 | * |
| 7447 | * Context: |
| 7448 | * Kernel context. |
| 7449 | */ |
| 7450 | int |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 7451 | 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] | 7452 | { |
| 7453 | int ret; |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7454 | int priority; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7455 | uint16_t mb[5]; |
| 7456 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 7457 | if (fcport->port_type != FCT_TARGET || |
| 7458 | fcport->loop_id == FC_NO_LOOP_ID) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7459 | return QLA_FUNCTION_FAILED; |
| 7460 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 7461 | priority = qla24xx_get_fcp_prio(vha, fcport); |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7462 | if (priority < 0) |
| 7463 | return QLA_FUNCTION_FAILED; |
| 7464 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 7465 | if (IS_P3P_TYPE(vha->hw)) { |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 7466 | fcport->fcp_prio = priority & 0xf; |
| 7467 | return QLA_SUCCESS; |
| 7468 | } |
| 7469 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 7470 | ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb); |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7471 | if (ret == QLA_SUCCESS) { |
| 7472 | if (fcport->fcp_prio != priority) |
| 7473 | ql_dbg(ql_dbg_user, vha, 0x709e, |
| 7474 | "Updated FCP_CMND priority - value=%d loop_id=%d " |
| 7475 | "port_id=%02x%02x%02x.\n", priority, |
| 7476 | fcport->loop_id, fcport->d_id.b.domain, |
| 7477 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 7478 | fcport->fcp_prio = priority & 0xf; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7479 | } else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7480 | ql_dbg(ql_dbg_user, vha, 0x704f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7481 | "Unable to update FCP_CMND priority - ret=0x%x for " |
| 7482 | "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id, |
| 7483 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 7484 | fcport->d_id.b.al_pa); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7485 | return ret; |
| 7486 | } |
| 7487 | |
| 7488 | /* |
| 7489 | * qla24xx_update_all_fcp_prio |
| 7490 | * Activates fcp priority for all the logged in ports |
| 7491 | * |
| 7492 | * Input: |
| 7493 | * ha = adapter block pointer. |
| 7494 | * |
| 7495 | * Return: |
| 7496 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 7497 | * |
| 7498 | * Context: |
| 7499 | * Kernel context. |
| 7500 | */ |
| 7501 | int |
| 7502 | qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha) |
| 7503 | { |
| 7504 | int ret; |
| 7505 | fc_port_t *fcport; |
| 7506 | |
| 7507 | ret = QLA_FUNCTION_FAILED; |
| 7508 | /* We need to set priority for all logged in ports */ |
| 7509 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 7510 | ret = qla24xx_update_fcport_fcp_prio(vha, fcport); |
| 7511 | |
| 7512 | return ret; |
| 7513 | } |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7514 | |
| 7515 | struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos, int vp_idx) |
| 7516 | { |
| 7517 | int rsp_id = 0; |
| 7518 | int req_id = 0; |
| 7519 | int i; |
| 7520 | struct qla_hw_data *ha = vha->hw; |
| 7521 | uint16_t qpair_id = 0; |
| 7522 | struct qla_qpair *qpair = NULL; |
| 7523 | struct qla_msix_entry *msix; |
| 7524 | |
| 7525 | if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) { |
| 7526 | ql_log(ql_log_warn, vha, 0x00181, |
| 7527 | "FW/Driver is not multi-queue capable.\n"); |
| 7528 | return NULL; |
| 7529 | } |
| 7530 | |
| 7531 | if (ql2xmqsupport) { |
| 7532 | qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL); |
| 7533 | if (qpair == NULL) { |
| 7534 | ql_log(ql_log_warn, vha, 0x0182, |
| 7535 | "Failed to allocate memory for queue pair.\n"); |
| 7536 | return NULL; |
| 7537 | } |
| 7538 | memset(qpair, 0, sizeof(struct qla_qpair)); |
| 7539 | |
| 7540 | qpair->hw = vha->hw; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 7541 | qpair->vha = vha; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7542 | |
| 7543 | /* Assign available que pair id */ |
| 7544 | mutex_lock(&ha->mq_lock); |
| 7545 | qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs); |
Sawan Chandak | b95b945 | 2017-05-24 18:06:20 -0700 | [diff] [blame^] | 7546 | if (ha->num_qpairs >= ha->max_qpairs) { |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7547 | mutex_unlock(&ha->mq_lock); |
| 7548 | ql_log(ql_log_warn, vha, 0x0183, |
| 7549 | "No resources to create additional q pair.\n"); |
| 7550 | goto fail_qid_map; |
| 7551 | } |
Sawan Chandak | b95b945 | 2017-05-24 18:06:20 -0700 | [diff] [blame^] | 7552 | ha->num_qpairs++; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7553 | set_bit(qpair_id, ha->qpair_qid_map); |
| 7554 | ha->queue_pair_map[qpair_id] = qpair; |
| 7555 | qpair->id = qpair_id; |
| 7556 | qpair->vp_idx = vp_idx; |
| 7557 | |
| 7558 | for (i = 0; i < ha->msix_count; i++) { |
Quinn Tran | 093df73 | 2016-12-12 14:40:09 -0800 | [diff] [blame] | 7559 | msix = &ha->msix_entries[i]; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7560 | if (msix->in_use) |
| 7561 | continue; |
| 7562 | qpair->msix = msix; |
| 7563 | ql_log(ql_dbg_multiq, vha, 0xc00f, |
| 7564 | "Vector %x selected for qpair\n", msix->vector); |
| 7565 | break; |
| 7566 | } |
| 7567 | if (!qpair->msix) { |
| 7568 | ql_log(ql_log_warn, vha, 0x0184, |
| 7569 | "Out of MSI-X vectors!.\n"); |
| 7570 | goto fail_msix; |
| 7571 | } |
| 7572 | |
| 7573 | qpair->msix->in_use = 1; |
| 7574 | list_add_tail(&qpair->qp_list_elem, &vha->qp_list); |
| 7575 | |
| 7576 | mutex_unlock(&ha->mq_lock); |
| 7577 | |
| 7578 | /* Create response queue first */ |
| 7579 | rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair); |
| 7580 | if (!rsp_id) { |
| 7581 | ql_log(ql_log_warn, vha, 0x0185, |
| 7582 | "Failed to create response queue.\n"); |
| 7583 | goto fail_rsp; |
| 7584 | } |
| 7585 | |
| 7586 | qpair->rsp = ha->rsp_q_map[rsp_id]; |
| 7587 | |
| 7588 | /* Create request queue */ |
| 7589 | req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos); |
| 7590 | if (!req_id) { |
| 7591 | ql_log(ql_log_warn, vha, 0x0186, |
| 7592 | "Failed to create request queue.\n"); |
| 7593 | goto fail_req; |
| 7594 | } |
| 7595 | |
| 7596 | qpair->req = ha->req_q_map[req_id]; |
| 7597 | qpair->rsp->req = qpair->req; |
| 7598 | |
| 7599 | if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) { |
| 7600 | if (ha->fw_attributes & BIT_4) |
| 7601 | qpair->difdix_supported = 1; |
| 7602 | } |
| 7603 | |
| 7604 | qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep); |
| 7605 | if (!qpair->srb_mempool) { |
| 7606 | ql_log(ql_log_warn, vha, 0x0191, |
| 7607 | "Failed to create srb mempool for qpair %d\n", |
| 7608 | qpair->id); |
| 7609 | goto fail_mempool; |
| 7610 | } |
| 7611 | |
| 7612 | /* Mark as online */ |
| 7613 | qpair->online = 1; |
| 7614 | |
| 7615 | if (!vha->flags.qpairs_available) |
| 7616 | vha->flags.qpairs_available = 1; |
| 7617 | |
| 7618 | ql_dbg(ql_dbg_multiq, vha, 0xc00d, |
| 7619 | "Request/Response queue pair created, id %d\n", |
| 7620 | qpair->id); |
| 7621 | ql_dbg(ql_dbg_init, vha, 0x0187, |
| 7622 | "Request/Response queue pair created, id %d\n", |
| 7623 | qpair->id); |
| 7624 | } |
| 7625 | return qpair; |
| 7626 | |
| 7627 | fail_mempool: |
| 7628 | fail_req: |
| 7629 | qla25xx_delete_rsp_que(vha, qpair->rsp); |
| 7630 | fail_rsp: |
| 7631 | mutex_lock(&ha->mq_lock); |
| 7632 | qpair->msix->in_use = 0; |
| 7633 | list_del(&qpair->qp_list_elem); |
| 7634 | if (list_empty(&vha->qp_list)) |
| 7635 | vha->flags.qpairs_available = 0; |
| 7636 | fail_msix: |
| 7637 | ha->queue_pair_map[qpair_id] = NULL; |
| 7638 | clear_bit(qpair_id, ha->qpair_qid_map); |
Sawan Chandak | b95b945 | 2017-05-24 18:06:20 -0700 | [diff] [blame^] | 7639 | ha->num_qpairs--; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7640 | mutex_unlock(&ha->mq_lock); |
| 7641 | fail_qid_map: |
| 7642 | kfree(qpair); |
| 7643 | return NULL; |
| 7644 | } |
| 7645 | |
| 7646 | int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair) |
| 7647 | { |
| 7648 | int ret; |
| 7649 | struct qla_hw_data *ha = qpair->hw; |
| 7650 | |
| 7651 | qpair->delete_in_progress = 1; |
| 7652 | while (atomic_read(&qpair->ref_count)) |
| 7653 | msleep(500); |
| 7654 | |
| 7655 | ret = qla25xx_delete_req_que(vha, qpair->req); |
| 7656 | if (ret != QLA_SUCCESS) |
| 7657 | goto fail; |
| 7658 | ret = qla25xx_delete_rsp_que(vha, qpair->rsp); |
| 7659 | if (ret != QLA_SUCCESS) |
| 7660 | goto fail; |
| 7661 | |
| 7662 | mutex_lock(&ha->mq_lock); |
| 7663 | ha->queue_pair_map[qpair->id] = NULL; |
| 7664 | clear_bit(qpair->id, ha->qpair_qid_map); |
Sawan Chandak | b95b945 | 2017-05-24 18:06:20 -0700 | [diff] [blame^] | 7665 | ha->num_qpairs--; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7666 | list_del(&qpair->qp_list_elem); |
| 7667 | if (list_empty(&vha->qp_list)) |
| 7668 | vha->flags.qpairs_available = 0; |
| 7669 | mempool_destroy(qpair->srb_mempool); |
| 7670 | kfree(qpair); |
| 7671 | mutex_unlock(&ha->mq_lock); |
| 7672 | |
| 7673 | return QLA_SUCCESS; |
| 7674 | fail: |
| 7675 | return ret; |
| 7676 | } |