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; |
| 632 | uint64_t zero = 0; |
| 633 | struct port_database_24xx *pd; |
| 634 | fc_port_t *fcport = sp->fcport; |
| 635 | u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb; |
| 636 | int rval = QLA_SUCCESS; |
| 637 | struct event_arg ea; |
| 638 | |
| 639 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 640 | "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n", |
| 641 | sp->name, res, fcport->port_name, mb[1], mb[2]); |
| 642 | |
| 643 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 644 | |
| 645 | if (res) { |
| 646 | rval = res; |
| 647 | goto gpd_error_out; |
| 648 | } |
| 649 | |
| 650 | pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in; |
| 651 | |
| 652 | /* Check for logged in state. */ |
| 653 | if (pd->current_login_state != PDS_PRLI_COMPLETE && |
| 654 | pd->last_login_state != PDS_PRLI_COMPLETE) { |
| 655 | ql_dbg(ql_dbg_mbx, vha, 0xffff, |
| 656 | "Unable to verify login-state (%x/%x) for " |
| 657 | "loop_id %x.\n", pd->current_login_state, |
| 658 | pd->last_login_state, fcport->loop_id); |
| 659 | rval = QLA_FUNCTION_FAILED; |
| 660 | goto gpd_error_out; |
| 661 | } |
| 662 | |
| 663 | if (fcport->loop_id == FC_NO_LOOP_ID || |
| 664 | (memcmp(fcport->port_name, (uint8_t *)&zero, 8) && |
| 665 | memcmp(fcport->port_name, pd->port_name, 8))) { |
| 666 | /* We lost the device mid way. */ |
| 667 | rval = QLA_NOT_LOGGED_IN; |
| 668 | goto gpd_error_out; |
| 669 | } |
| 670 | |
| 671 | /* Names are little-endian. */ |
| 672 | memcpy(fcport->node_name, pd->node_name, WWN_SIZE); |
| 673 | |
| 674 | /* Get port_id of device. */ |
| 675 | fcport->d_id.b.domain = pd->port_id[0]; |
| 676 | fcport->d_id.b.area = pd->port_id[1]; |
| 677 | fcport->d_id.b.al_pa = pd->port_id[2]; |
| 678 | fcport->d_id.b.rsvd_1 = 0; |
| 679 | |
| 680 | /* If not target must be initiator or unknown type. */ |
| 681 | if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0) |
| 682 | fcport->port_type = FCT_INITIATOR; |
| 683 | else |
| 684 | fcport->port_type = FCT_TARGET; |
| 685 | |
| 686 | /* Passback COS information. */ |
| 687 | fcport->supported_classes = (pd->flags & PDF_CLASS_2) ? |
| 688 | FC_COS_CLASS2 : FC_COS_CLASS3; |
| 689 | |
| 690 | if (pd->prli_svc_param_word_3[0] & BIT_7) { |
| 691 | fcport->flags |= FCF_CONF_COMP_SUPPORTED; |
| 692 | fcport->conf_compl_supported = 1; |
| 693 | } |
| 694 | |
| 695 | gpd_error_out: |
| 696 | memset(&ea, 0, sizeof(ea)); |
| 697 | ea.event = FCME_GPDB_DONE; |
| 698 | ea.rc = rval; |
| 699 | ea.fcport = fcport; |
| 700 | ea.sp = sp; |
| 701 | |
| 702 | qla2x00_fcport_event_handler(vha, &ea); |
| 703 | |
| 704 | dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in, |
| 705 | sp->u.iocb_cmd.u.mbx.in_dma); |
| 706 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 707 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | static int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 711 | u8 opt) |
| 712 | { |
| 713 | struct qla_work_evt *e; |
| 714 | |
| 715 | e = qla2x00_alloc_work(vha, QLA_EVT_GPDB); |
| 716 | if (!e) |
| 717 | return QLA_FUNCTION_FAILED; |
| 718 | |
| 719 | e->u.fcport.fcport = fcport; |
| 720 | e->u.fcport.opt = opt; |
| 721 | return qla2x00_post_work(vha, e); |
| 722 | } |
| 723 | |
| 724 | int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt) |
| 725 | { |
| 726 | srb_t *sp; |
| 727 | struct srb_iocb *mbx; |
| 728 | int rval = QLA_FUNCTION_FAILED; |
| 729 | u16 *mb; |
| 730 | dma_addr_t pd_dma; |
| 731 | struct port_database_24xx *pd; |
| 732 | struct qla_hw_data *ha = vha->hw; |
| 733 | |
| 734 | if (!vha->flags.online) |
| 735 | goto done; |
| 736 | |
| 737 | fcport->flags |= FCF_ASYNC_SENT; |
| 738 | fcport->disc_state = DSC_GPDB; |
| 739 | |
| 740 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 741 | if (!sp) |
| 742 | goto done; |
| 743 | |
| 744 | pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma); |
| 745 | if (pd == NULL) { |
| 746 | ql_log(ql_log_warn, vha, 0xffff, |
| 747 | "Failed to allocate port database structure.\n"); |
| 748 | goto done_free_sp; |
| 749 | } |
| 750 | memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE)); |
| 751 | |
| 752 | sp->type = SRB_MB_IOCB; |
| 753 | sp->name = "gpdb"; |
| 754 | sp->gen1 = fcport->rscn_gen; |
| 755 | sp->gen2 = fcport->login_gen; |
| 756 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 757 | |
| 758 | mb = sp->u.iocb_cmd.u.mbx.out_mb; |
| 759 | mb[0] = MBC_GET_PORT_DATABASE; |
| 760 | mb[1] = fcport->loop_id; |
| 761 | mb[2] = MSW(pd_dma); |
| 762 | mb[3] = LSW(pd_dma); |
| 763 | mb[6] = MSW(MSD(pd_dma)); |
| 764 | mb[7] = LSW(MSD(pd_dma)); |
| 765 | mb[9] = vha->vp_idx; |
| 766 | mb[10] = opt; |
| 767 | |
| 768 | mbx = &sp->u.iocb_cmd; |
| 769 | mbx->timeout = qla2x00_async_iocb_timeout; |
| 770 | mbx->u.mbx.in = (void *)pd; |
| 771 | mbx->u.mbx.in_dma = pd_dma; |
| 772 | |
| 773 | sp->done = qla24xx_async_gpdb_sp_done; |
| 774 | |
| 775 | rval = qla2x00_start_sp(sp); |
| 776 | if (rval != QLA_SUCCESS) |
| 777 | goto done_free_sp; |
| 778 | |
| 779 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 780 | "Async-%s %8phC hndl %x opt %x\n", |
| 781 | sp->name, fcport->port_name, sp->handle, opt); |
| 782 | |
| 783 | return rval; |
| 784 | |
| 785 | done_free_sp: |
| 786 | if (pd) |
| 787 | dma_pool_free(ha->s_dma_pool, pd, pd_dma); |
| 788 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 789 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 790 | done: |
| 791 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 792 | qla24xx_post_gpdb_work(vha, fcport, opt); |
| 793 | return rval; |
| 794 | } |
| 795 | |
| 796 | static |
| 797 | void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea) |
| 798 | { |
| 799 | int rval = ea->rc; |
| 800 | fc_port_t *fcport = ea->fcport; |
| 801 | unsigned long flags; |
| 802 | |
| 803 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 804 | |
| 805 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 806 | "%s %8phC DS %d LS %d rval %d\n", __func__, fcport->port_name, |
| 807 | fcport->disc_state, fcport->fw_login_state, rval); |
| 808 | |
| 809 | if (ea->sp->gen2 != fcport->login_gen) { |
| 810 | /* target side must have changed it. */ |
| 811 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 812 | "%s %8phC generation changed rscn %d|%d login %d|%d \n", |
| 813 | __func__, fcport->port_name, fcport->last_rscn_gen, |
| 814 | fcport->rscn_gen, fcport->last_login_gen, |
| 815 | fcport->login_gen); |
| 816 | return; |
| 817 | } else if (ea->sp->gen1 != fcport->rscn_gen) { |
| 818 | ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC post gidpn\n", |
| 819 | __func__, __LINE__, fcport->port_name); |
| 820 | qla24xx_post_gidpn_work(vha, fcport); |
| 821 | return; |
| 822 | } |
| 823 | |
| 824 | if (rval != QLA_SUCCESS) { |
| 825 | ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC post del sess\n", |
| 826 | __func__, __LINE__, fcport->port_name); |
| 827 | qlt_schedule_sess_for_deletion_lock(fcport); |
| 828 | return; |
| 829 | } |
| 830 | |
| 831 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 832 | ea->fcport->login_gen++; |
| 833 | ea->fcport->deleted = 0; |
| 834 | ea->fcport->logout_on_delete = 1; |
| 835 | |
| 836 | if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) { |
| 837 | vha->fcport_count++; |
| 838 | ea->fcport->login_succ = 1; |
| 839 | |
| 840 | if (!IS_IIDMA_CAPABLE(vha->hw) || |
| 841 | !vha->hw->flags.gpsc_supported) { |
| 842 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 843 | "%s %d %8phC post upd_fcport fcp_cnt %d\n", |
| 844 | __func__, __LINE__, fcport->port_name, |
| 845 | vha->fcport_count); |
| 846 | |
| 847 | qla24xx_post_upd_fcport_work(vha, fcport); |
| 848 | } else { |
| 849 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 850 | "%s %d %8phC post gpsc fcp_cnt %d\n", |
| 851 | __func__, __LINE__, fcport->port_name, |
| 852 | vha->fcport_count); |
| 853 | |
| 854 | qla24xx_post_gpsc_work(vha, fcport); |
| 855 | } |
| 856 | } |
| 857 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 858 | } /* gpdb event */ |
| 859 | |
| 860 | int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 861 | { |
| 862 | if (fcport->login_retry == 0) |
| 863 | return 0; |
| 864 | |
| 865 | if (fcport->scan_state != QLA_FCPORT_FOUND) |
| 866 | return 0; |
| 867 | |
| 868 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 869 | "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d|%d retry %d lid %d\n", |
| 870 | __func__, fcport->port_name, fcport->disc_state, |
| 871 | fcport->fw_login_state, fcport->login_pause, fcport->flags, |
| 872 | fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen, |
| 873 | fcport->last_login_gen, fcport->login_gen, fcport->login_retry, |
| 874 | fcport->loop_id); |
| 875 | |
| 876 | fcport->login_retry--; |
| 877 | |
| 878 | if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 879 | (fcport->fw_login_state == DSC_LS_PRLI_PEND)) |
| 880 | return 0; |
| 881 | |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame^] | 882 | if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) { |
| 883 | if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) |
| 884 | return 0; |
| 885 | } |
| 886 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 887 | /* for pure Target Mode. Login will not be initiated */ |
| 888 | if (vha->host->active_mode == MODE_TARGET) |
| 889 | return 0; |
| 890 | |
| 891 | if (fcport->flags & FCF_ASYNC_SENT) { |
| 892 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 893 | return 0; |
| 894 | } |
| 895 | |
| 896 | switch (fcport->disc_state) { |
| 897 | case DSC_DELETED: |
| 898 | if (fcport->loop_id == FC_NO_LOOP_ID) { |
| 899 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 900 | "%s %d %8phC post gnl\n", |
| 901 | __func__, __LINE__, fcport->port_name); |
| 902 | qla24xx_async_gnl(vha, fcport); |
| 903 | } else { |
| 904 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 905 | "%s %d %8phC post login\n", |
| 906 | __func__, __LINE__, fcport->port_name); |
| 907 | fcport->disc_state = DSC_LOGIN_PEND; |
| 908 | qla2x00_post_async_login_work(vha, fcport, NULL); |
| 909 | } |
| 910 | break; |
| 911 | |
| 912 | case DSC_GNL: |
| 913 | if (fcport->login_pause) { |
| 914 | fcport->last_rscn_gen = fcport->rscn_gen; |
| 915 | fcport->last_login_gen = fcport->login_gen; |
| 916 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 917 | break; |
| 918 | } |
| 919 | |
| 920 | if (fcport->flags & FCF_FCP2_DEVICE) { |
| 921 | u8 opt = PDO_FORCE_ADISC; |
| 922 | |
| 923 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 924 | "%s %d %8phC post gpdb\n", |
| 925 | __func__, __LINE__, fcport->port_name); |
| 926 | |
| 927 | fcport->disc_state = DSC_GPDB; |
| 928 | qla24xx_post_gpdb_work(vha, fcport, opt); |
| 929 | } else { |
| 930 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 931 | "%s %d %8phC post login \n", |
| 932 | __func__, __LINE__, fcport->port_name); |
| 933 | fcport->disc_state = DSC_LOGIN_PEND; |
| 934 | qla2x00_post_async_login_work(vha, fcport, NULL); |
| 935 | } |
| 936 | |
| 937 | break; |
| 938 | |
| 939 | case DSC_LOGIN_FAILED: |
| 940 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 941 | "%s %d %8phC post gidpn \n", |
| 942 | __func__, __LINE__, fcport->port_name); |
| 943 | |
| 944 | qla24xx_post_gidpn_work(vha, fcport); |
| 945 | break; |
| 946 | |
| 947 | case DSC_LOGIN_COMPLETE: |
| 948 | /* recheck login state */ |
| 949 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 950 | "%s %d %8phC post gpdb \n", |
| 951 | __func__, __LINE__, fcport->port_name); |
| 952 | |
| 953 | qla24xx_post_gpdb_work(vha, fcport, PDO_FORCE_ADISC); |
| 954 | break; |
| 955 | |
| 956 | default: |
| 957 | break; |
| 958 | } |
| 959 | |
| 960 | return 0; |
| 961 | } |
| 962 | |
| 963 | static |
| 964 | void qla24xx_handle_rscn_event(fc_port_t *fcport, struct event_arg *ea) |
| 965 | { |
| 966 | fcport->rscn_gen++; |
| 967 | |
| 968 | ql_dbg(ql_dbg_disc, fcport->vha, 0xffff, |
| 969 | "%s %8phC DS %d LS %d\n", |
| 970 | __func__, fcport->port_name, fcport->disc_state, |
| 971 | fcport->fw_login_state); |
| 972 | |
| 973 | if (fcport->flags & FCF_ASYNC_SENT) |
| 974 | return; |
| 975 | |
| 976 | switch (fcport->disc_state) { |
| 977 | case DSC_DELETED: |
| 978 | case DSC_LOGIN_COMPLETE: |
| 979 | qla24xx_post_gidpn_work(fcport->vha, fcport); |
| 980 | break; |
| 981 | |
| 982 | default: |
| 983 | break; |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id, |
| 988 | u8 *port_name, void *pla) |
| 989 | { |
| 990 | struct qla_work_evt *e; |
| 991 | e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS); |
| 992 | if (!e) |
| 993 | return QLA_FUNCTION_FAILED; |
| 994 | |
| 995 | e->u.new_sess.id = *id; |
| 996 | e->u.new_sess.pla = pla; |
| 997 | memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE); |
| 998 | |
| 999 | return qla2x00_post_work(vha, e); |
| 1000 | } |
| 1001 | |
| 1002 | static |
| 1003 | int qla24xx_handle_delete_done_event(scsi_qla_host_t *vha, |
| 1004 | struct event_arg *ea) |
| 1005 | { |
| 1006 | fc_port_t *fcport = ea->fcport; |
| 1007 | |
| 1008 | if (test_bit(UNLOADING, &vha->dpc_flags)) |
| 1009 | return 0; |
| 1010 | |
| 1011 | switch (vha->host->active_mode) { |
| 1012 | case MODE_INITIATOR: |
| 1013 | case MODE_DUAL: |
| 1014 | if (fcport->scan_state == QLA_FCPORT_FOUND) |
| 1015 | qla24xx_fcport_handle_login(vha, fcport); |
| 1016 | break; |
| 1017 | |
| 1018 | case MODE_TARGET: |
| 1019 | default: |
| 1020 | /* no-op */ |
| 1021 | break; |
| 1022 | } |
| 1023 | |
| 1024 | return 0; |
| 1025 | } |
| 1026 | |
| 1027 | static |
| 1028 | void qla24xx_handle_relogin_event(scsi_qla_host_t *vha, |
| 1029 | struct event_arg *ea) |
| 1030 | { |
| 1031 | fc_port_t *fcport = ea->fcport; |
| 1032 | |
| 1033 | if (fcport->scan_state != QLA_FCPORT_FOUND) { |
| 1034 | fcport->login_retry++; |
| 1035 | return; |
| 1036 | } |
| 1037 | |
| 1038 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 1039 | "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n", |
| 1040 | __func__, fcport->port_name, fcport->disc_state, |
| 1041 | fcport->fw_login_state, fcport->login_pause, |
| 1042 | fcport->deleted, fcport->conflict, |
| 1043 | fcport->last_rscn_gen, fcport->rscn_gen, |
| 1044 | fcport->last_login_gen, fcport->login_gen, |
| 1045 | fcport->flags); |
| 1046 | |
| 1047 | if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1048 | (fcport->fw_login_state == DSC_LS_PRLI_PEND)) |
| 1049 | return; |
| 1050 | |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame^] | 1051 | if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) { |
| 1052 | if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) |
| 1053 | return; |
| 1054 | } |
| 1055 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1056 | if (fcport->flags & FCF_ASYNC_SENT) { |
| 1057 | fcport->login_retry++; |
| 1058 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1059 | return; |
| 1060 | } |
| 1061 | |
| 1062 | if (fcport->disc_state == DSC_DELETE_PEND) { |
| 1063 | fcport->login_retry++; |
| 1064 | return; |
| 1065 | } |
| 1066 | |
| 1067 | if (fcport->last_rscn_gen != fcport->rscn_gen) { |
| 1068 | ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC post gidpn\n", |
| 1069 | __func__, __LINE__, fcport->port_name); |
| 1070 | |
| 1071 | qla24xx_async_gidpn(vha, fcport); |
| 1072 | return; |
| 1073 | } |
| 1074 | |
| 1075 | qla24xx_fcport_handle_login(vha, fcport); |
| 1076 | } |
| 1077 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1078 | 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] | 1079 | { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1080 | fc_port_t *fcport, *f, *tf; |
| 1081 | uint32_t id = 0, mask, rid; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1082 | int rc; |
| 1083 | |
| 1084 | switch (ea->event) { |
| 1085 | case FCME_RELOGIN: |
| 1086 | if (test_bit(UNLOADING, &vha->dpc_flags)) |
| 1087 | return; |
| 1088 | |
| 1089 | qla24xx_handle_relogin_event(vha, ea); |
| 1090 | break; |
| 1091 | case FCME_RSCN: |
| 1092 | if (test_bit(UNLOADING, &vha->dpc_flags)) |
| 1093 | return; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1094 | switch (ea->id.b.rsvd_1) { |
| 1095 | case RSCN_PORT_ADDR: |
| 1096 | fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1); |
| 1097 | if (!fcport) { |
| 1098 | /* cable moved */ |
| 1099 | rc = qla24xx_post_gpnid_work(vha, &ea->id); |
| 1100 | if (rc) { |
| 1101 | ql_log(ql_log_warn, vha, 0xffff, |
| 1102 | "RSCN GPNID work failed %02x%02x%02x\n", |
| 1103 | ea->id.b.domain, ea->id.b.area, |
| 1104 | ea->id.b.al_pa); |
| 1105 | } |
| 1106 | } else { |
| 1107 | ea->fcport = fcport; |
| 1108 | qla24xx_handle_rscn_event(fcport, ea); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1109 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1110 | break; |
| 1111 | case RSCN_AREA_ADDR: |
| 1112 | case RSCN_DOM_ADDR: |
| 1113 | if (ea->id.b.rsvd_1 == RSCN_AREA_ADDR) { |
| 1114 | mask = 0xffff00; |
| 1115 | ql_log(ql_dbg_async, vha, 0xffff, |
| 1116 | "RSCN: Area 0x%06x was affected\n", |
| 1117 | ea->id.b24); |
| 1118 | } else { |
| 1119 | mask = 0xff0000; |
| 1120 | ql_log(ql_dbg_async, vha, 0xffff, |
| 1121 | "RSCN: Domain 0x%06x was affected\n", |
| 1122 | ea->id.b24); |
| 1123 | } |
| 1124 | |
| 1125 | rid = ea->id.b24 & mask; |
| 1126 | list_for_each_entry_safe(f, tf, &vha->vp_fcports, |
| 1127 | list) { |
| 1128 | id = f->d_id.b24 & mask; |
| 1129 | if (rid == id) { |
| 1130 | ea->fcport = f; |
| 1131 | qla24xx_handle_rscn_event(f, ea); |
| 1132 | } |
| 1133 | } |
| 1134 | break; |
| 1135 | case RSCN_FAB_ADDR: |
| 1136 | default: |
| 1137 | ql_log(ql_log_warn, vha, 0xffff, |
| 1138 | "RSCN: Fabric was affected. Addr format %d\n", |
| 1139 | ea->id.b.rsvd_1); |
| 1140 | qla2x00_mark_all_devices_lost(vha, 1); |
| 1141 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 1142 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1143 | } |
| 1144 | break; |
| 1145 | case FCME_GIDPN_DONE: |
| 1146 | qla24xx_handle_gidpn_event(vha, ea); |
| 1147 | break; |
| 1148 | case FCME_GNL_DONE: |
| 1149 | qla24xx_handle_gnl_done_event(vha, ea); |
| 1150 | break; |
| 1151 | case FCME_GPSC_DONE: |
| 1152 | qla24xx_post_upd_fcport_work(vha, ea->fcport); |
| 1153 | break; |
| 1154 | case FCME_PLOGI_DONE: /* Initiator side sent LLIOCB */ |
| 1155 | qla24xx_handle_plogi_done_event(vha, ea); |
| 1156 | break; |
| 1157 | case FCME_GPDB_DONE: |
| 1158 | qla24xx_handle_gpdb_event(vha, ea); |
| 1159 | break; |
| 1160 | case FCME_GPNID_DONE: |
| 1161 | qla24xx_handle_gpnid_event(vha, ea); |
| 1162 | break; |
| 1163 | case FCME_DELETE_DONE: |
| 1164 | qla24xx_handle_delete_done_event(vha, ea); |
| 1165 | break; |
| 1166 | default: |
| 1167 | BUG_ON(1); |
| 1168 | break; |
| 1169 | } |
| 1170 | } |
| 1171 | |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1172 | static void |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1173 | qla2x00_tmf_iocb_timeout(void *data) |
| 1174 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1175 | srb_t *sp = data; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1176 | struct srb_iocb *tmf = &sp->u.iocb_cmd; |
| 1177 | |
| 1178 | tmf->u.tmf.comp_status = CS_TIMEOUT; |
| 1179 | complete(&tmf->u.tmf.comp); |
| 1180 | } |
| 1181 | |
| 1182 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1183 | qla2x00_tmf_sp_done(void *ptr, int res) |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1184 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1185 | srb_t *sp = ptr; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1186 | struct srb_iocb *tmf = &sp->u.iocb_cmd; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1187 | |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1188 | complete(&tmf->u.tmf.comp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1189 | } |
| 1190 | |
| 1191 | int |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1192 | 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] | 1193 | uint32_t tag) |
| 1194 | { |
| 1195 | struct scsi_qla_host *vha = fcport->vha; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1196 | struct srb_iocb *tm_iocb; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1197 | srb_t *sp; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1198 | int rval = QLA_FUNCTION_FAILED; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1199 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1200 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1201 | if (!sp) |
| 1202 | goto done; |
| 1203 | |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1204 | tm_iocb = &sp->u.iocb_cmd; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1205 | sp->type = SRB_TM_CMD; |
| 1206 | sp->name = "tmf"; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1207 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)); |
| 1208 | tm_iocb->u.tmf.flags = flags; |
| 1209 | tm_iocb->u.tmf.lun = lun; |
| 1210 | tm_iocb->u.tmf.data = tag; |
| 1211 | sp->done = qla2x00_tmf_sp_done; |
| 1212 | tm_iocb->timeout = qla2x00_tmf_iocb_timeout; |
| 1213 | init_completion(&tm_iocb->u.tmf.comp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1214 | |
| 1215 | rval = qla2x00_start_sp(sp); |
| 1216 | if (rval != QLA_SUCCESS) |
| 1217 | goto done_free_sp; |
| 1218 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1219 | ql_dbg(ql_dbg_taskm, vha, 0x802f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1220 | "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n", |
| 1221 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
| 1222 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1223 | |
| 1224 | wait_for_completion(&tm_iocb->u.tmf.comp); |
| 1225 | |
| 1226 | rval = tm_iocb->u.tmf.comp_status == CS_COMPLETE ? |
| 1227 | QLA_SUCCESS : QLA_FUNCTION_FAILED; |
| 1228 | |
| 1229 | if ((rval != QLA_SUCCESS) || tm_iocb->u.tmf.data) { |
| 1230 | ql_dbg(ql_dbg_taskm, vha, 0x8030, |
| 1231 | "TM IOCB failed (%x).\n", rval); |
| 1232 | } |
| 1233 | |
| 1234 | if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) { |
| 1235 | flags = tm_iocb->u.tmf.flags; |
| 1236 | lun = (uint16_t)tm_iocb->u.tmf.lun; |
| 1237 | |
| 1238 | /* Issue Marker IOCB */ |
| 1239 | qla2x00_marker(vha, vha->hw->req_q_map[0], |
| 1240 | vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun, |
| 1241 | flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID); |
| 1242 | } |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1243 | |
| 1244 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1245 | sp->free(sp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1246 | done: |
| 1247 | return rval; |
| 1248 | } |
| 1249 | |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1250 | static void |
| 1251 | qla24xx_abort_iocb_timeout(void *data) |
| 1252 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1253 | srb_t *sp = data; |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1254 | struct srb_iocb *abt = &sp->u.iocb_cmd; |
| 1255 | |
| 1256 | abt->u.abt.comp_status = CS_TIMEOUT; |
| 1257 | complete(&abt->u.abt.comp); |
| 1258 | } |
| 1259 | |
| 1260 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1261 | qla24xx_abort_sp_done(void *ptr, int res) |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1262 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1263 | srb_t *sp = ptr; |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1264 | struct srb_iocb *abt = &sp->u.iocb_cmd; |
| 1265 | |
| 1266 | complete(&abt->u.abt.comp); |
| 1267 | } |
| 1268 | |
| 1269 | static int |
| 1270 | qla24xx_async_abort_cmd(srb_t *cmd_sp) |
| 1271 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1272 | scsi_qla_host_t *vha = cmd_sp->vha; |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1273 | fc_port_t *fcport = cmd_sp->fcport; |
| 1274 | struct srb_iocb *abt_iocb; |
| 1275 | srb_t *sp; |
| 1276 | int rval = QLA_FUNCTION_FAILED; |
| 1277 | |
| 1278 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 1279 | if (!sp) |
| 1280 | goto done; |
| 1281 | |
| 1282 | abt_iocb = &sp->u.iocb_cmd; |
| 1283 | sp->type = SRB_ABT_CMD; |
| 1284 | sp->name = "abort"; |
| 1285 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)); |
| 1286 | abt_iocb->u.abt.cmd_hndl = cmd_sp->handle; |
| 1287 | sp->done = qla24xx_abort_sp_done; |
| 1288 | abt_iocb->timeout = qla24xx_abort_iocb_timeout; |
| 1289 | init_completion(&abt_iocb->u.abt.comp); |
| 1290 | |
| 1291 | rval = qla2x00_start_sp(sp); |
| 1292 | if (rval != QLA_SUCCESS) |
| 1293 | goto done_free_sp; |
| 1294 | |
| 1295 | ql_dbg(ql_dbg_async, vha, 0x507c, |
| 1296 | "Abort command issued - hdl=%x, target_id=%x\n", |
| 1297 | cmd_sp->handle, fcport->tgt_id); |
| 1298 | |
| 1299 | wait_for_completion(&abt_iocb->u.abt.comp); |
| 1300 | |
| 1301 | rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ? |
| 1302 | QLA_SUCCESS : QLA_FUNCTION_FAILED; |
| 1303 | |
| 1304 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1305 | sp->free(sp); |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1306 | done: |
| 1307 | return rval; |
| 1308 | } |
| 1309 | |
| 1310 | int |
| 1311 | qla24xx_async_abort_command(srb_t *sp) |
| 1312 | { |
| 1313 | unsigned long flags = 0; |
| 1314 | |
| 1315 | uint32_t handle; |
| 1316 | fc_port_t *fcport = sp->fcport; |
| 1317 | struct scsi_qla_host *vha = fcport->vha; |
| 1318 | struct qla_hw_data *ha = vha->hw; |
| 1319 | struct req_que *req = vha->req; |
| 1320 | |
| 1321 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1322 | for (handle = 1; handle < req->num_outstanding_cmds; handle++) { |
| 1323 | if (req->outstanding_cmds[handle] == sp) |
| 1324 | break; |
| 1325 | } |
| 1326 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1327 | if (handle == req->num_outstanding_cmds) { |
| 1328 | /* Command not found. */ |
| 1329 | return QLA_FUNCTION_FAILED; |
| 1330 | } |
| 1331 | if (sp->type == SRB_FXIOCB_DCMD) |
| 1332 | return qlafx00_fx_disc(vha, &vha->hw->mr.fcport, |
| 1333 | FXDISC_ABORT_IOCTL); |
| 1334 | |
| 1335 | return qla24xx_async_abort_cmd(sp); |
| 1336 | } |
| 1337 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1338 | static void |
| 1339 | 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] | 1340 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1341 | port_id_t cid; /* conflict Nport id */ |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1342 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1343 | switch (ea->data[0]) { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1344 | case MBS_COMMAND_COMPLETE: |
Andrew Vasquez | a4f92a3 | 2011-03-30 11:46:31 -0700 | [diff] [blame] | 1345 | /* |
| 1346 | * Driver must validate login state - If PRLI not complete, |
| 1347 | * force a relogin attempt via implicit LOGO, PLOGI, and PRLI |
| 1348 | * requests. |
| 1349 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1350 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 1351 | "%s %d %8phC post gpdb\n", |
| 1352 | __func__, __LINE__, ea->fcport->port_name); |
| 1353 | ea->fcport->chip_reset = vha->hw->chip_reset; |
| 1354 | ea->fcport->logout_on_delete = 1; |
| 1355 | qla24xx_post_gpdb_work(vha, ea->fcport, 0); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1356 | break; |
| 1357 | case MBS_COMMAND_ERROR: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1358 | ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC cmd error %x\n", |
| 1359 | __func__, __LINE__, ea->fcport->port_name, ea->data[1]); |
| 1360 | |
| 1361 | ea->fcport->flags &= ~FCF_ASYNC_SENT; |
| 1362 | ea->fcport->disc_state = DSC_LOGIN_FAILED; |
| 1363 | if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1364 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1365 | else |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1366 | qla2x00_mark_device_lost(vha, ea->fcport, 1, 0); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1367 | break; |
| 1368 | case MBS_LOOP_ID_USED: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1369 | /* data[1] = IO PARAM 1 = nport ID */ |
| 1370 | cid.b.domain = (ea->iop[1] >> 16) & 0xff; |
| 1371 | cid.b.area = (ea->iop[1] >> 8) & 0xff; |
| 1372 | cid.b.al_pa = ea->iop[1] & 0xff; |
| 1373 | cid.b.rsvd_1 = 0; |
| 1374 | |
| 1375 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 1376 | "%s %d %8phC LoopID 0x%x in use post gnl\n", |
| 1377 | __func__, __LINE__, ea->fcport->port_name, |
| 1378 | ea->fcport->loop_id); |
| 1379 | |
| 1380 | if (IS_SW_RESV_ADDR(cid)) { |
| 1381 | set_bit(ea->fcport->loop_id, vha->hw->loop_id_map); |
| 1382 | ea->fcport->loop_id = FC_NO_LOOP_ID; |
| 1383 | } else { |
| 1384 | qla2x00_clear_loop_id(ea->fcport); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1385 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1386 | qla24xx_post_gnl_work(vha, ea->fcport); |
| 1387 | break; |
| 1388 | case MBS_PORT_ID_USED: |
| 1389 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 1390 | "%s %d %8phC NPortId %02x%02x%02x inuse post gidpn\n", |
| 1391 | __func__, __LINE__, ea->fcport->port_name, |
| 1392 | ea->fcport->d_id.b.domain, ea->fcport->d_id.b.area, |
| 1393 | ea->fcport->d_id.b.al_pa); |
| 1394 | |
| 1395 | qla2x00_clear_loop_id(ea->fcport); |
| 1396 | qla24xx_post_gidpn_work(vha, ea->fcport); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1397 | break; |
| 1398 | } |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1399 | return; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1400 | } |
| 1401 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1402 | void |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1403 | qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 1404 | uint16_t *data) |
| 1405 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1406 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1407 | qlt_logo_completion_handler(fcport, data[0]); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1408 | fcport->login_gen++; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1409 | return; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1410 | } |
| 1411 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1412 | void |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1413 | qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 1414 | uint16_t *data) |
| 1415 | { |
| 1416 | if (data[0] == MBS_COMMAND_COMPLETE) { |
| 1417 | qla2x00_update_fcport(vha, fcport); |
| 1418 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1419 | return; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | /* Retry login. */ |
| 1423 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 1424 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
| 1425 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1426 | else |
Andrew Vasquez | 80d7944 | 2011-03-30 11:46:17 -0700 | [diff] [blame] | 1427 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1428 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1429 | return; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1430 | } |
| 1431 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | /****************************************************************************/ |
| 1433 | /* QLogic ISP2x00 Hardware Support Functions. */ |
| 1434 | /****************************************************************************/ |
| 1435 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 1436 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1437 | qla83xx_nic_core_fw_load(scsi_qla_host_t *vha) |
| 1438 | { |
| 1439 | int rval = QLA_SUCCESS; |
| 1440 | struct qla_hw_data *ha = vha->hw; |
| 1441 | uint32_t idc_major_ver, idc_minor_ver; |
Saurav Kashyap | 711aa7f | 2012-08-22 14:21:15 -0400 | [diff] [blame] | 1442 | uint16_t config[4]; |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1443 | |
| 1444 | qla83xx_idc_lock(vha, 0); |
| 1445 | |
| 1446 | /* SV: TODO: Assign initialization timeout from |
| 1447 | * flash-info / other param |
| 1448 | */ |
| 1449 | ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT; |
| 1450 | ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT; |
| 1451 | |
| 1452 | /* Set our fcoe function presence */ |
| 1453 | if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) { |
| 1454 | ql_dbg(ql_dbg_p3p, vha, 0xb077, |
| 1455 | "Error while setting DRV-Presence.\n"); |
| 1456 | rval = QLA_FUNCTION_FAILED; |
| 1457 | goto exit; |
| 1458 | } |
| 1459 | |
| 1460 | /* Decide the reset ownership */ |
| 1461 | qla83xx_reset_ownership(vha); |
| 1462 | |
| 1463 | /* |
| 1464 | * On first protocol driver load: |
| 1465 | * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery |
| 1466 | * register. |
| 1467 | * Others: Check compatibility with current IDC Major version. |
| 1468 | */ |
| 1469 | qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver); |
| 1470 | if (ha->flags.nic_core_reset_owner) { |
| 1471 | /* Set IDC Major version */ |
| 1472 | idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION; |
| 1473 | qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver); |
| 1474 | |
| 1475 | /* Clearing IDC-Lock-Recovery register */ |
| 1476 | qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0); |
| 1477 | } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) { |
| 1478 | /* |
| 1479 | * Clear further IDC participation if we are not compatible with |
| 1480 | * the current IDC Major Version. |
| 1481 | */ |
| 1482 | ql_log(ql_log_warn, vha, 0xb07d, |
| 1483 | "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n", |
| 1484 | idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION); |
| 1485 | __qla83xx_clear_drv_presence(vha); |
| 1486 | rval = QLA_FUNCTION_FAILED; |
| 1487 | goto exit; |
| 1488 | } |
| 1489 | /* Each function sets its supported Minor version. */ |
| 1490 | qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver); |
| 1491 | idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2)); |
| 1492 | qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver); |
| 1493 | |
Saurav Kashyap | 711aa7f | 2012-08-22 14:21:15 -0400 | [diff] [blame] | 1494 | if (ha->flags.nic_core_reset_owner) { |
| 1495 | memset(config, 0, sizeof(config)); |
| 1496 | if (!qla81xx_get_port_config(vha, config)) |
| 1497 | qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, |
| 1498 | QLA8XXX_DEV_READY); |
| 1499 | } |
| 1500 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1501 | rval = qla83xx_idc_state_handler(vha); |
| 1502 | |
| 1503 | exit: |
| 1504 | qla83xx_idc_unlock(vha, 0); |
| 1505 | |
| 1506 | return rval; |
| 1507 | } |
| 1508 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | /* |
| 1510 | * qla2x00_initialize_adapter |
| 1511 | * Initialize board. |
| 1512 | * |
| 1513 | * Input: |
| 1514 | * ha = adapter block pointer. |
| 1515 | * |
| 1516 | * Returns: |
| 1517 | * 0 = success |
| 1518 | */ |
| 1519 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1520 | qla2x00_initialize_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | { |
| 1522 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1523 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1524 | struct req_que *req = ha->req_q_map[0]; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 1525 | |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 1526 | memset(&vha->qla_stats, 0, sizeof(vha->qla_stats)); |
| 1527 | memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat)); |
| 1528 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 | /* Clear adapter flags. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1530 | vha->flags.online = 0; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 1531 | ha->flags.chip_reset_done = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1532 | vha->flags.reset_active = 0; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 1533 | ha->flags.pci_channel_io_perm_failure = 0; |
| 1534 | ha->flags.eeh_busy = 0; |
Joe Carnuccio | fabbb8d | 2013-08-27 01:37:40 -0400 | [diff] [blame] | 1535 | vha->qla_stats.jiffies_at_last_reset = get_jiffies_64(); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1536 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 1537 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 1538 | vha->device_flags = DFLG_NO_CABLE; |
| 1539 | vha->dpc_flags = 0; |
| 1540 | vha->flags.management_server_logged_in = 0; |
| 1541 | vha->marker_needed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | ha->isp_abort_cnt = 0; |
| 1543 | ha->beacon_blink_led = 0; |
| 1544 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1545 | set_bit(0, ha->req_qid_map); |
| 1546 | set_bit(0, ha->rsp_qid_map); |
| 1547 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1548 | ql_dbg(ql_dbg_init, vha, 0x0040, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1549 | "Configuring PCI space...\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1550 | rval = ha->isp_ops->pci_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1552 | ql_log(ql_log_warn, vha, 0x0044, |
| 1553 | "Unable to configure PCI space.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | return (rval); |
| 1555 | } |
| 1556 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1557 | ha->isp_ops->reset_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1559 | rval = qla2xxx_get_flash_info(vha); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 1560 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1561 | ql_log(ql_log_fatal, vha, 0x004f, |
| 1562 | "Unable to validate FLASH data.\n"); |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 1563 | return rval; |
| 1564 | } |
| 1565 | |
| 1566 | if (IS_QLA8044(ha)) { |
| 1567 | qla8044_read_reset_template(vha); |
| 1568 | |
| 1569 | /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0. |
| 1570 | * If DONRESET_BIT0 is set, drivers should not set dev_state |
| 1571 | * to NEED_RESET. But if NEED_RESET is set, drivers should |
| 1572 | * should honor the reset. */ |
| 1573 | if (ql2xdontresethba == 1) |
| 1574 | qla8044_set_idc_dontreset(vha); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 1575 | } |
| 1576 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1577 | ha->isp_ops->get_flash_version(vha, req->ring); |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1578 | ql_dbg(ql_dbg_init, vha, 0x0061, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1579 | "Configure NVRAM parameters...\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1580 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1581 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 1583 | if (ha->flags.disable_serdes) { |
| 1584 | /* Mask HBA via NVRAM settings? */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1585 | ql_log(ql_log_info, vha, 0x0077, |
Oleksandr Khoshaba | 7b83355 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1586 | "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name); |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 1587 | return QLA_FUNCTION_FAILED; |
| 1588 | } |
| 1589 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1590 | ql_dbg(ql_dbg_init, vha, 0x0078, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1591 | "Verifying loaded RISC code...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1593 | if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) { |
| 1594 | rval = ha->isp_ops->chip_diag(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 1595 | if (rval) |
| 1596 | return (rval); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1597 | rval = qla2x00_setup_chip(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 1598 | if (rval) |
| 1599 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1601 | |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1602 | if (IS_QLA84XX(ha)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1603 | ha->cs84xx = qla84xx_get_chip(vha); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1604 | if (!ha->cs84xx) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1605 | ql_log(ql_log_warn, vha, 0x00d0, |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1606 | "Unable to configure ISP84XX.\n"); |
| 1607 | return QLA_FUNCTION_FAILED; |
| 1608 | } |
| 1609 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1610 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 1611 | if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1612 | rval = qla2x00_init_rings(vha); |
| 1613 | |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 1614 | ha->flags.chip_reset_done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1615 | |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 1616 | if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) { |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 1617 | /* Issue verify 84xx FW IOCB to complete 84xx initialization */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 1618 | rval = qla84xx_init_chip(vha); |
| 1619 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1620 | ql_log(ql_log_warn, vha, 0x00d4, |
| 1621 | "Unable to initialize ISP84XX.\n"); |
Bart Van Assche | 8d2b21d | 2015-06-04 15:58:09 -0700 | [diff] [blame] | 1622 | qla84xx_put_chip(vha); |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 1623 | } |
| 1624 | } |
| 1625 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1626 | /* Load the NIC Core f/w if we are the first protocol driver. */ |
| 1627 | if (IS_QLA8031(ha)) { |
| 1628 | rval = qla83xx_nic_core_fw_load(vha); |
| 1629 | if (rval) |
| 1630 | ql_log(ql_log_warn, vha, 0x0124, |
| 1631 | "Error in initializing NIC Core f/w.\n"); |
| 1632 | } |
| 1633 | |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 1634 | if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)) |
| 1635 | qla24xx_read_fcp_prio_cfg(vha); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 1636 | |
Joe Carnuccio | c46e65c | 2013-08-27 01:37:35 -0400 | [diff] [blame] | 1637 | if (IS_P3P_TYPE(ha)) |
| 1638 | qla82xx_set_driver_version(vha, QLA2XXX_VERSION); |
| 1639 | else |
| 1640 | qla25xx_set_driver_version(vha, QLA2XXX_VERSION); |
| 1641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1642 | return (rval); |
| 1643 | } |
| 1644 | |
| 1645 | /** |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1646 | * qla2100_pci_config() - Setup ISP21xx PCI configuration registers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | * @ha: HA context |
| 1648 | * |
| 1649 | * Returns 0 on success. |
| 1650 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1651 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1652 | qla2100_pci_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1654 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1655 | unsigned long flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1656 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1657 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 1660 | pci_try_set_mwi(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1661 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1663 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1664 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 1665 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 1666 | pci_disable_rom(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1667 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1668 | /* Get PCI bus information. */ |
| 1669 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1670 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1671 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1672 | |
| 1673 | return QLA_SUCCESS; |
| 1674 | } |
| 1675 | |
| 1676 | /** |
| 1677 | * qla2300_pci_config() - Setup ISP23xx PCI configuration registers. |
| 1678 | * @ha: HA context |
| 1679 | * |
| 1680 | * Returns 0 on success. |
| 1681 | */ |
| 1682 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1683 | qla2300_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1684 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1685 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1686 | unsigned long flags = 0; |
| 1687 | uint32_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1688 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1689 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1690 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1691 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 1692 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1693 | |
| 1694 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1695 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1696 | |
| 1697 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 1698 | w &= ~PCI_COMMAND_INTX_DISABLE; |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1699 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1700 | |
| 1701 | /* |
| 1702 | * If this is a 2300 card and not 2312, reset the |
| 1703 | * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately, |
| 1704 | * the 2310 also reports itself as a 2300 so we need to get the |
| 1705 | * fb revision level -- a 6 indicates it really is a 2300 and |
| 1706 | * not a 2310. |
| 1707 | */ |
| 1708 | if (IS_QLA2300(ha)) { |
| 1709 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1710 | |
| 1711 | /* Pause RISC. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1712 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1713 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1714 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1715 | break; |
| 1716 | |
| 1717 | udelay(10); |
| 1718 | } |
| 1719 | |
| 1720 | /* Select FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1721 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 1722 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1723 | |
| 1724 | /* Get the fb rev level */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1725 | ha->fb_rev = RD_FB_CMD_REG(ha, reg); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1726 | |
| 1727 | if (ha->fb_rev == FPM_2300) |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1728 | pci_clear_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1729 | |
| 1730 | /* Deselect FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1731 | WRT_REG_WORD(®->ctrl_status, 0x0); |
| 1732 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1733 | |
| 1734 | /* Release RISC module. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1735 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1736 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1737 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1738 | break; |
| 1739 | |
| 1740 | udelay(10); |
| 1741 | } |
| 1742 | |
| 1743 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1744 | } |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1745 | |
| 1746 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 1747 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 1748 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1749 | |
| 1750 | /* Get PCI bus information. */ |
| 1751 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1752 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1753 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1754 | |
| 1755 | return QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1759 | * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers. |
| 1760 | * @ha: HA context |
| 1761 | * |
| 1762 | * Returns 0 on success. |
| 1763 | */ |
| 1764 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1765 | qla24xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1766 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1767 | uint16_t w; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1768 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1769 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1770 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1771 | |
| 1772 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 1773 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1774 | |
| 1775 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1776 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1777 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 1778 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 1779 | |
| 1780 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 1781 | |
| 1782 | /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */ |
Andrew Vasquez | f85ec18 | 2007-07-19 15:06:01 -0700 | [diff] [blame] | 1783 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX)) |
| 1784 | pcix_set_mmrbc(ha->pdev, 2048); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1785 | |
| 1786 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Jon Mason | e67f132 | 2012-07-10 14:57:56 -0700 | [diff] [blame] | 1787 | if (pci_is_pcie(ha->pdev)) |
Chad Dupuis | 5ffd3a5 | 2012-08-22 14:21:26 -0400 | [diff] [blame] | 1788 | pcie_set_readrq(ha->pdev, 4096); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1789 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 1790 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1791 | |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 1792 | ha->chip_revision = ha->pdev->revision; |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1793 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1794 | /* Get PCI bus information. */ |
| 1795 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1796 | ha->pci_attr = RD_REG_DWORD(®->ctrl_status); |
| 1797 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1798 | |
| 1799 | return QLA_SUCCESS; |
| 1800 | } |
| 1801 | |
| 1802 | /** |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1803 | * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers. |
| 1804 | * @ha: HA context |
| 1805 | * |
| 1806 | * Returns 0 on success. |
| 1807 | */ |
| 1808 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1809 | qla25xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1810 | { |
| 1811 | uint16_t w; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1812 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1813 | |
| 1814 | pci_set_master(ha->pdev); |
| 1815 | pci_try_set_mwi(ha->pdev); |
| 1816 | |
| 1817 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
| 1818 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
| 1819 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 1820 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 1821 | |
| 1822 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Jon Mason | e67f132 | 2012-07-10 14:57:56 -0700 | [diff] [blame] | 1823 | if (pci_is_pcie(ha->pdev)) |
Chad Dupuis | 5ffd3a5 | 2012-08-22 14:21:26 -0400 | [diff] [blame] | 1824 | pcie_set_readrq(ha->pdev, 4096); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1825 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 1826 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1827 | |
| 1828 | ha->chip_revision = ha->pdev->revision; |
| 1829 | |
| 1830 | return QLA_SUCCESS; |
| 1831 | } |
| 1832 | |
| 1833 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | * qla2x00_isp_firmware() - Choose firmware image. |
| 1835 | * @ha: HA context |
| 1836 | * |
| 1837 | * Returns 0 on success. |
| 1838 | */ |
| 1839 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1840 | qla2x00_isp_firmware(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1841 | { |
| 1842 | int rval; |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 1843 | uint16_t loop_id, topo, sw_cap; |
| 1844 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1845 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | |
| 1847 | /* Assume loading risc code */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1848 | rval = QLA_FUNCTION_FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | |
| 1850 | if (ha->flags.disable_risc_code_load) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1851 | ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | |
| 1853 | /* Verify checksum of loaded RISC code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1854 | rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address); |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 1855 | if (rval == QLA_SUCCESS) { |
| 1856 | /* And, verify we are not in ROM code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1857 | rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa, |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 1858 | &area, &domain, &topo, &sw_cap); |
| 1859 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | } |
| 1861 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1862 | if (rval) |
| 1863 | ql_dbg(ql_dbg_init, vha, 0x007a, |
| 1864 | "**** Load RISC code ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | |
| 1866 | return (rval); |
| 1867 | } |
| 1868 | |
| 1869 | /** |
| 1870 | * qla2x00_reset_chip() - Reset ISP chip. |
| 1871 | * @ha: HA context |
| 1872 | * |
| 1873 | * Returns 0 on success. |
| 1874 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1875 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1876 | qla2x00_reset_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | { |
| 1878 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1879 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1880 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | uint32_t cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | uint16_t cmd; |
| 1883 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 1884 | if (unlikely(pci_channel_offline(ha->pdev))) |
| 1885 | return; |
| 1886 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1887 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | |
| 1889 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1890 | |
| 1891 | /* Turn off master enable */ |
| 1892 | cmd = 0; |
| 1893 | pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd); |
| 1894 | cmd &= ~PCI_COMMAND_MASTER; |
| 1895 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 1896 | |
| 1897 | if (!IS_QLA2100(ha)) { |
| 1898 | /* Pause RISC. */ |
| 1899 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
| 1900 | if (IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 1901 | for (cnt = 0; cnt < 30000; cnt++) { |
| 1902 | if ((RD_REG_WORD(®->hccr) & |
| 1903 | HCCR_RISC_PAUSE) != 0) |
| 1904 | break; |
| 1905 | udelay(100); |
| 1906 | } |
| 1907 | } else { |
| 1908 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 1909 | udelay(10); |
| 1910 | } |
| 1911 | |
| 1912 | /* Select FPM registers. */ |
| 1913 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 1914 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 1915 | |
| 1916 | /* FPM Soft Reset. */ |
| 1917 | WRT_REG_WORD(®->fpm_diag_config, 0x100); |
| 1918 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 1919 | |
| 1920 | /* Toggle Fpm Reset. */ |
| 1921 | if (!IS_QLA2200(ha)) { |
| 1922 | WRT_REG_WORD(®->fpm_diag_config, 0x0); |
| 1923 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 1924 | } |
| 1925 | |
| 1926 | /* Select frame buffer registers. */ |
| 1927 | WRT_REG_WORD(®->ctrl_status, 0x10); |
| 1928 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 1929 | |
| 1930 | /* Reset frame buffer FIFOs. */ |
| 1931 | if (IS_QLA2200(ha)) { |
| 1932 | WRT_FB_CMD_REG(ha, reg, 0xa000); |
| 1933 | RD_FB_CMD_REG(ha, reg); /* PCI Posting. */ |
| 1934 | } else { |
| 1935 | WRT_FB_CMD_REG(ha, reg, 0x00fc); |
| 1936 | |
| 1937 | /* Read back fb_cmd until zero or 3 seconds max */ |
| 1938 | for (cnt = 0; cnt < 3000; cnt++) { |
| 1939 | if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0) |
| 1940 | break; |
| 1941 | udelay(100); |
| 1942 | } |
| 1943 | } |
| 1944 | |
| 1945 | /* Select RISC module registers. */ |
| 1946 | WRT_REG_WORD(®->ctrl_status, 0); |
| 1947 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 1948 | |
| 1949 | /* Reset RISC processor. */ |
| 1950 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 1951 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 1952 | |
| 1953 | /* Release RISC processor. */ |
| 1954 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 1955 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 1956 | } |
| 1957 | |
| 1958 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); |
| 1959 | WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT); |
| 1960 | |
| 1961 | /* Reset ISP chip. */ |
| 1962 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 1963 | |
| 1964 | /* Wait for RISC to recover from reset. */ |
| 1965 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 1966 | /* |
| 1967 | * It is necessary to for a delay here since the card doesn't |
| 1968 | * respond to PCI reads during a reset. On some architectures |
| 1969 | * this will result in an MCA. |
| 1970 | */ |
| 1971 | udelay(20); |
| 1972 | for (cnt = 30000; cnt; cnt--) { |
| 1973 | if ((RD_REG_WORD(®->ctrl_status) & |
| 1974 | CSR_ISP_SOFT_RESET) == 0) |
| 1975 | break; |
| 1976 | udelay(100); |
| 1977 | } |
| 1978 | } else |
| 1979 | udelay(10); |
| 1980 | |
| 1981 | /* Reset RISC processor. */ |
| 1982 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 1983 | |
| 1984 | WRT_REG_WORD(®->semaphore, 0); |
| 1985 | |
| 1986 | /* Release RISC processor. */ |
| 1987 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 1988 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 1989 | |
| 1990 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 1991 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | ffb39f0 | 2006-05-17 15:09:06 -0700 | [diff] [blame] | 1992 | if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | |
| 1995 | udelay(100); |
| 1996 | } |
| 1997 | } else |
| 1998 | udelay(100); |
| 1999 | |
| 2000 | /* Turn on master enable */ |
| 2001 | cmd |= PCI_COMMAND_MASTER; |
| 2002 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 2003 | |
| 2004 | /* Disable RISC pause on FPM parity error. */ |
| 2005 | if (!IS_QLA2100(ha)) { |
| 2006 | WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE); |
| 2007 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 2008 | } |
| 2009 | |
| 2010 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2011 | } |
| 2012 | |
| 2013 | /** |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2014 | * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC. |
| 2015 | * |
| 2016 | * Returns 0 on success. |
| 2017 | */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 2018 | static int |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2019 | qla81xx_reset_mpi(scsi_qla_host_t *vha) |
| 2020 | { |
| 2021 | uint16_t mb[4] = {0x1010, 0, 1, 0}; |
| 2022 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2023 | if (!IS_QLA81XX(vha->hw)) |
| 2024 | return QLA_SUCCESS; |
| 2025 | |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2026 | return qla81xx_write_mpi_register(vha, mb); |
| 2027 | } |
| 2028 | |
| 2029 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2030 | * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC. |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2031 | * @ha: HA context |
| 2032 | * |
| 2033 | * Returns 0 on success. |
| 2034 | */ |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2035 | static inline int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2036 | qla24xx_reset_risc(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2037 | { |
| 2038 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2039 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2040 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2041 | uint32_t cnt; |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2042 | uint16_t wd; |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2043 | static int abts_cnt; /* ISP abort retry counts */ |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2044 | int rval = QLA_SUCCESS; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2045 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2046 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2047 | |
| 2048 | /* Reset RISC. */ |
| 2049 | WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
| 2050 | for (cnt = 0; cnt < 30000; cnt++) { |
| 2051 | if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0) |
| 2052 | break; |
| 2053 | |
| 2054 | udelay(10); |
| 2055 | } |
| 2056 | |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2057 | if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE)) |
| 2058 | set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags); |
| 2059 | |
| 2060 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e, |
| 2061 | "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n", |
| 2062 | RD_REG_DWORD(®->hccr), |
| 2063 | RD_REG_DWORD(®->ctrl_status), |
| 2064 | (RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE)); |
| 2065 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2066 | WRT_REG_DWORD(®->ctrl_status, |
| 2067 | CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2068 | pci_read_config_word(ha->pdev, PCI_COMMAND, &wd); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2069 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2070 | udelay(100); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2071 | |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2072 | /* Wait for firmware to complete NVRAM accesses. */ |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2073 | RD_REG_WORD(®->mailbox0); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2074 | for (cnt = 10000; RD_REG_WORD(®->mailbox0) != 0 && |
| 2075 | rval == QLA_SUCCESS; cnt--) { |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2076 | barrier(); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2077 | if (cnt) |
| 2078 | udelay(5); |
| 2079 | else |
| 2080 | rval = QLA_FUNCTION_TIMEOUT; |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2081 | } |
| 2082 | |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2083 | if (rval == QLA_SUCCESS) |
| 2084 | set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags); |
| 2085 | |
| 2086 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f, |
| 2087 | "HCCR: 0x%x, MailBox0 Status 0x%x\n", |
| 2088 | RD_REG_DWORD(®->hccr), |
| 2089 | RD_REG_DWORD(®->mailbox0)); |
| 2090 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2091 | /* Wait for soft-reset to complete. */ |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2092 | RD_REG_DWORD(®->ctrl_status); |
Quinn Tran | 200ffb1 | 2016-12-23 18:06:12 -0800 | [diff] [blame] | 2093 | for (cnt = 0; cnt < 60; cnt++) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2094 | barrier(); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2095 | if ((RD_REG_DWORD(®->ctrl_status) & |
| 2096 | CSRX_ISP_SOFT_RESET) == 0) |
| 2097 | break; |
| 2098 | |
| 2099 | udelay(5); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2100 | } |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2101 | if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_ISP_SOFT_RESET)) |
| 2102 | set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags); |
| 2103 | |
| 2104 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d, |
| 2105 | "HCCR: 0x%x, Soft Reset status: 0x%x\n", |
| 2106 | RD_REG_DWORD(®->hccr), |
| 2107 | RD_REG_DWORD(®->ctrl_status)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2108 | |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2109 | /* If required, do an MPI FW reset now */ |
| 2110 | if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) { |
| 2111 | if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) { |
| 2112 | if (++abts_cnt < 5) { |
| 2113 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 2114 | set_bit(MPI_RESET_NEEDED, &vha->dpc_flags); |
| 2115 | } else { |
| 2116 | /* |
| 2117 | * We exhausted the ISP abort retries. We have to |
| 2118 | * set the board offline. |
| 2119 | */ |
| 2120 | abts_cnt = 0; |
| 2121 | vha->flags.online = 0; |
| 2122 | } |
| 2123 | } |
| 2124 | } |
| 2125 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2126 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 2127 | RD_REG_DWORD(®->hccr); |
| 2128 | |
| 2129 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 2130 | RD_REG_DWORD(®->hccr); |
| 2131 | |
| 2132 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET); |
| 2133 | RD_REG_DWORD(®->hccr); |
| 2134 | |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2135 | RD_REG_WORD(®->mailbox0); |
Quinn Tran | 200ffb1 | 2016-12-23 18:06:12 -0800 | [diff] [blame] | 2136 | for (cnt = 60; RD_REG_WORD(®->mailbox0) != 0 && |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2137 | rval == QLA_SUCCESS; cnt--) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2138 | barrier(); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2139 | if (cnt) |
| 2140 | udelay(5); |
| 2141 | else |
| 2142 | rval = QLA_FUNCTION_TIMEOUT; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2143 | } |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2144 | if (rval == QLA_SUCCESS) |
| 2145 | set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags); |
| 2146 | |
| 2147 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e, |
| 2148 | "Host Risc 0x%x, mailbox0 0x%x\n", |
| 2149 | RD_REG_DWORD(®->hccr), |
| 2150 | RD_REG_WORD(®->mailbox0)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2151 | |
| 2152 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 124f85e | 2009-01-05 11:18:06 -0800 | [diff] [blame] | 2153 | |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2154 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f, |
| 2155 | "Driver in %s mode\n", |
| 2156 | IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling"); |
| 2157 | |
Andrew Vasquez | 124f85e | 2009-01-05 11:18:06 -0800 | [diff] [blame] | 2158 | if (IS_NOPOLLING_TYPE(ha)) |
| 2159 | ha->isp_ops->enable_intrs(ha); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2160 | |
| 2161 | return rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2162 | } |
| 2163 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2164 | static void |
| 2165 | qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data) |
| 2166 | { |
| 2167 | struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24; |
| 2168 | |
| 2169 | WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET); |
| 2170 | *data = RD_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET); |
| 2171 | |
| 2172 | } |
| 2173 | |
| 2174 | static void |
| 2175 | qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data) |
| 2176 | { |
| 2177 | struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24; |
| 2178 | |
| 2179 | WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET); |
| 2180 | WRT_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET, data); |
| 2181 | } |
| 2182 | |
| 2183 | static void |
| 2184 | qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha) |
| 2185 | { |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2186 | uint32_t wd32 = 0; |
| 2187 | uint delta_msec = 100; |
| 2188 | uint elapsed_msec = 0; |
| 2189 | uint timeout_msec; |
| 2190 | ulong n; |
| 2191 | |
Joe Carnuccio | cc79076 | 2015-08-04 13:37:53 -0400 | [diff] [blame] | 2192 | if (vha->hw->pdev->subsystem_device != 0x0175 && |
| 2193 | vha->hw->pdev->subsystem_device != 0x0240) |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2194 | return; |
| 2195 | |
Joe Carnuccio | 8dd7e3a | 2015-08-04 13:37:54 -0400 | [diff] [blame] | 2196 | WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE); |
| 2197 | udelay(100); |
| 2198 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2199 | attempt: |
| 2200 | timeout_msec = TIMEOUT_SEMAPHORE; |
| 2201 | n = timeout_msec / delta_msec; |
| 2202 | while (n--) { |
| 2203 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET); |
| 2204 | qla25xx_read_risc_sema_reg(vha, &wd32); |
| 2205 | if (wd32 & RISC_SEMAPHORE) |
| 2206 | break; |
| 2207 | msleep(delta_msec); |
| 2208 | elapsed_msec += delta_msec; |
| 2209 | if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED) |
| 2210 | goto force; |
| 2211 | } |
| 2212 | |
| 2213 | if (!(wd32 & RISC_SEMAPHORE)) |
| 2214 | goto force; |
| 2215 | |
| 2216 | if (!(wd32 & RISC_SEMAPHORE_FORCE)) |
| 2217 | goto acquired; |
| 2218 | |
| 2219 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR); |
| 2220 | timeout_msec = TIMEOUT_SEMAPHORE_FORCE; |
| 2221 | n = timeout_msec / delta_msec; |
| 2222 | while (n--) { |
| 2223 | qla25xx_read_risc_sema_reg(vha, &wd32); |
| 2224 | if (!(wd32 & RISC_SEMAPHORE_FORCE)) |
| 2225 | break; |
| 2226 | msleep(delta_msec); |
| 2227 | elapsed_msec += delta_msec; |
| 2228 | if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED) |
| 2229 | goto force; |
| 2230 | } |
| 2231 | |
| 2232 | if (wd32 & RISC_SEMAPHORE_FORCE) |
| 2233 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR); |
| 2234 | |
| 2235 | goto attempt; |
| 2236 | |
| 2237 | force: |
| 2238 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET); |
| 2239 | |
| 2240 | acquired: |
| 2241 | return; |
| 2242 | } |
| 2243 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2244 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2245 | * qla24xx_reset_chip() - Reset ISP24xx chip. |
| 2246 | * @ha: HA context |
| 2247 | * |
| 2248 | * Returns 0 on success. |
| 2249 | */ |
| 2250 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2251 | qla24xx_reset_chip(scsi_qla_host_t *vha) |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2252 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2253 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 2254 | |
| 2255 | if (pci_channel_offline(ha->pdev) && |
| 2256 | ha->flags.pci_channel_io_perm_failure) { |
| 2257 | return; |
| 2258 | } |
| 2259 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 2260 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2261 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2262 | qla25xx_manipulate_risc_semaphore(vha); |
| 2263 | |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2264 | /* Perform RISC reset. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2265 | qla24xx_reset_risc(vha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2266 | } |
| 2267 | |
| 2268 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2269 | * qla2x00_chip_diag() - Test chip for proper operation. |
| 2270 | * @ha: HA context |
| 2271 | * |
| 2272 | * Returns 0 on success. |
| 2273 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2274 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2275 | qla2x00_chip_diag(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2276 | { |
| 2277 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2278 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2279 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | unsigned long flags = 0; |
| 2281 | uint16_t data; |
| 2282 | uint32_t cnt; |
| 2283 | uint16_t mb[5]; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2284 | struct req_que *req = ha->req_q_map[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2285 | |
| 2286 | /* Assume a failed state */ |
| 2287 | rval = QLA_FUNCTION_FAILED; |
| 2288 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2289 | ql_dbg(ql_dbg_init, vha, 0x007b, |
| 2290 | "Testing device at %lx.\n", (u_long)®->flash_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2291 | |
| 2292 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2293 | |
| 2294 | /* Reset ISP chip. */ |
| 2295 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 2296 | |
| 2297 | /* |
| 2298 | * We need to have a delay here since the card will not respond while |
| 2299 | * in reset causing an MCA on some architectures. |
| 2300 | */ |
| 2301 | udelay(20); |
| 2302 | data = qla2x00_debounce_register(®->ctrl_status); |
| 2303 | for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) { |
| 2304 | udelay(5); |
| 2305 | data = RD_REG_WORD(®->ctrl_status); |
| 2306 | barrier(); |
| 2307 | } |
| 2308 | |
| 2309 | if (!cnt) |
| 2310 | goto chip_diag_failed; |
| 2311 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2312 | ql_dbg(ql_dbg_init, vha, 0x007c, |
| 2313 | "Reset register cleared by chip reset.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2314 | |
| 2315 | /* Reset RISC processor. */ |
| 2316 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 2317 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 2318 | |
| 2319 | /* Workaround for QLA2312 PCI parity error */ |
| 2320 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 2321 | data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0)); |
| 2322 | for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) { |
| 2323 | udelay(5); |
| 2324 | data = RD_MAILBOX_REG(ha, reg, 0); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2325 | barrier(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | } |
| 2327 | } else |
| 2328 | udelay(10); |
| 2329 | |
| 2330 | if (!cnt) |
| 2331 | goto chip_diag_failed; |
| 2332 | |
| 2333 | /* Check product ID of chip */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2334 | 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] | 2335 | |
| 2336 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); |
| 2337 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); |
| 2338 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); |
| 2339 | mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4)); |
| 2340 | if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) || |
| 2341 | mb[3] != PROD_ID_3) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2342 | ql_log(ql_log_warn, vha, 0x0062, |
| 2343 | "Wrong product ID = 0x%x,0x%x,0x%x.\n", |
| 2344 | mb[1], mb[2], mb[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2345 | |
| 2346 | goto chip_diag_failed; |
| 2347 | } |
| 2348 | ha->product_id[0] = mb[1]; |
| 2349 | ha->product_id[1] = mb[2]; |
| 2350 | ha->product_id[2] = mb[3]; |
| 2351 | ha->product_id[3] = mb[4]; |
| 2352 | |
| 2353 | /* Adjust fw RISC transfer size */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2354 | if (req->length > 1024) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024; |
| 2356 | else |
| 2357 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2358 | req->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2359 | |
| 2360 | if (IS_QLA2200(ha) && |
| 2361 | RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) { |
| 2362 | /* Limit firmware transfer size with a 2200A */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2363 | ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 2365 | ha->device_type |= DT_ISP2200A; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2366 | ha->fw_transfer_size = 128; |
| 2367 | } |
| 2368 | |
| 2369 | /* Wrap Incoming Mailboxes Test. */ |
| 2370 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2371 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2372 | ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2373 | rval = qla2x00_mbx_reg_test(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2374 | if (rval) |
| 2375 | ql_log(ql_log_warn, vha, 0x0080, |
| 2376 | "Failed mailbox send register test.\n"); |
| 2377 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2378 | /* Flag a successful rval */ |
| 2379 | rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2380 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2381 | |
| 2382 | chip_diag_failed: |
| 2383 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2384 | ql_log(ql_log_info, vha, 0x0081, |
| 2385 | "Chip diagnostics **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2386 | |
| 2387 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2388 | |
| 2389 | return (rval); |
| 2390 | } |
| 2391 | |
| 2392 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2393 | * qla24xx_chip_diag() - Test ISP24xx for proper operation. |
| 2394 | * @ha: HA context |
| 2395 | * |
| 2396 | * Returns 0 on success. |
| 2397 | */ |
| 2398 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2399 | qla24xx_chip_diag(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2400 | { |
| 2401 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2402 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2403 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2404 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 2405 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2406 | return QLA_SUCCESS; |
| 2407 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2408 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2409 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2410 | rval = qla2x00_mbx_reg_test(vha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2411 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2412 | ql_log(ql_log_warn, vha, 0x0082, |
| 2413 | "Failed mailbox send register test.\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2414 | } else { |
| 2415 | /* Flag a successful rval */ |
| 2416 | rval = QLA_SUCCESS; |
| 2417 | } |
| 2418 | |
| 2419 | return rval; |
| 2420 | } |
| 2421 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2422 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2423 | qla2x00_alloc_fw_dump(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2424 | { |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2425 | int rval; |
| 2426 | 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] | 2427 | eft_size, fce_size, mq_size; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2428 | dma_addr_t tc_dma; |
| 2429 | void *tc; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2430 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2431 | struct req_que *req = ha->req_q_map[0]; |
| 2432 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 2433 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2434 | if (ha->fw_dump) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2435 | ql_dbg(ql_dbg_init, vha, 0x00bd, |
| 2436 | "Firmware dump already allocated.\n"); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2437 | return; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 2438 | } |
| 2439 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2440 | ha->fw_dumped = 0; |
Hiral Patel | 61f098d | 2014-04-11 16:54:21 -0400 | [diff] [blame] | 2441 | ha->fw_dump_cap_flags = 0; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2442 | dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0; |
| 2443 | req_q_size = rsp_q_size = 0; |
| 2444 | |
| 2445 | if (IS_QLA27XX(ha)) |
| 2446 | goto try_fce; |
| 2447 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2448 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 2449 | fixed_size = sizeof(struct qla2100_fw_dump); |
| 2450 | } else if (IS_QLA23XX(ha)) { |
| 2451 | fixed_size = offsetof(struct qla2300_fw_dump, data_ram); |
| 2452 | mem_size = (ha->fw_memory_size - 0x11000 + 1) * |
| 2453 | sizeof(uint16_t); |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 2454 | } else if (IS_FWI2_CAPABLE(ha)) { |
Himanshu Madhani | b20f02e | 2015-06-10 11:05:18 -0400 | [diff] [blame] | 2455 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2456 | fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem); |
| 2457 | else if (IS_QLA81XX(ha)) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 2458 | fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem); |
| 2459 | else if (IS_QLA25XX(ha)) |
| 2460 | fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem); |
| 2461 | else |
| 2462 | fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2463 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2464 | mem_size = (ha->fw_memory_size - 0x100000 + 1) * |
| 2465 | sizeof(uint32_t); |
Giridhar Malavali | 050c9bb | 2012-02-09 11:15:33 -0800 | [diff] [blame] | 2466 | if (ha->mqenable) { |
Himanshu Madhani | b20f02e | 2015-06-10 11:05:18 -0400 | [diff] [blame] | 2467 | if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha)) |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2468 | mq_size = sizeof(struct qla2xxx_mq_chain); |
Giridhar Malavali | 050c9bb | 2012-02-09 11:15:33 -0800 | [diff] [blame] | 2469 | /* |
| 2470 | * Allocate maximum buffer size for all queues. |
| 2471 | * Resizing must be done at end-of-dump processing. |
| 2472 | */ |
| 2473 | mq_size += ha->max_req_queues * |
| 2474 | (req->length * sizeof(request_t)); |
| 2475 | mq_size += ha->max_rsp_queues * |
| 2476 | (rsp->length * sizeof(response_t)); |
| 2477 | } |
Arun Easi | 00876ae | 2013-03-25 02:21:37 -0400 | [diff] [blame] | 2478 | if (ha->tgt.atio_ring) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2479 | mq_size += ha->tgt.atio_q_length * sizeof(request_t); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2480 | /* Allocate memory for Fibre Channel Event Buffer. */ |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2481 | if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) && |
| 2482 | !IS_QLA27XX(ha)) |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2483 | goto try_eft; |
| 2484 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2485 | try_fce: |
| 2486 | if (ha->fce) |
| 2487 | dma_free_coherent(&ha->pdev->dev, |
| 2488 | FCE_SIZE, ha->fce, ha->fce_dma); |
| 2489 | |
| 2490 | /* Allocate memory for Fibre Channel Event Buffer. */ |
Joe Perches | 0ea85b5 | 2014-06-15 13:37:51 -0700 | [diff] [blame] | 2491 | tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma, |
| 2492 | GFP_KERNEL); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2493 | if (!tc) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2494 | ql_log(ql_log_warn, vha, 0x00be, |
| 2495 | "Unable to allocate (%d KB) for FCE.\n", |
| 2496 | FCE_SIZE / 1024); |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 2497 | goto try_eft; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2498 | } |
| 2499 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2500 | rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2501 | ha->fce_mb, &ha->fce_bufs); |
| 2502 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2503 | ql_log(ql_log_warn, vha, 0x00bf, |
| 2504 | "Unable to initialize FCE (%d).\n", rval); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2505 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, |
| 2506 | tc_dma); |
| 2507 | ha->flags.fce_enabled = 0; |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 2508 | goto try_eft; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2509 | } |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2510 | ql_dbg(ql_dbg_init, vha, 0x00c0, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2511 | "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2512 | |
Giridhar Malavali | 7d9dade | 2009-03-24 09:07:58 -0700 | [diff] [blame] | 2513 | fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2514 | ha->flags.fce_enabled = 1; |
| 2515 | ha->fce_dma = tc_dma; |
| 2516 | ha->fce = tc; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2517 | |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2518 | try_eft: |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2519 | if (ha->eft) |
| 2520 | dma_free_coherent(&ha->pdev->dev, |
| 2521 | EFT_SIZE, ha->eft, ha->eft_dma); |
| 2522 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2523 | /* Allocate memory for Extended Trace Buffer. */ |
Joe Perches | 0ea85b5 | 2014-06-15 13:37:51 -0700 | [diff] [blame] | 2524 | tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma, |
| 2525 | GFP_KERNEL); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2526 | if (!tc) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2527 | ql_log(ql_log_warn, vha, 0x00c1, |
| 2528 | "Unable to allocate (%d KB) for EFT.\n", |
| 2529 | EFT_SIZE / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2530 | goto cont_alloc; |
| 2531 | } |
| 2532 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2533 | rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2534 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2535 | ql_log(ql_log_warn, vha, 0x00c2, |
| 2536 | "Unable to initialize EFT (%d).\n", rval); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2537 | dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, |
| 2538 | tc_dma); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2539 | goto cont_alloc; |
| 2540 | } |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2541 | ql_dbg(ql_dbg_init, vha, 0x00c3, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2542 | "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2543 | |
| 2544 | eft_size = EFT_SIZE; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2545 | ha->eft_dma = tc_dma; |
| 2546 | ha->eft = tc; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2547 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2548 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2549 | cont_alloc: |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2550 | if (IS_QLA27XX(ha)) { |
| 2551 | if (!ha->fw_dump_template) { |
| 2552 | ql_log(ql_log_warn, vha, 0x00ba, |
| 2553 | "Failed missing fwdump template\n"); |
| 2554 | return; |
| 2555 | } |
| 2556 | dump_size = qla27xx_fwdt_calculate_dump_size(vha); |
| 2557 | ql_dbg(ql_dbg_init, vha, 0x00fa, |
| 2558 | "-> allocating fwdump (%x bytes)...\n", dump_size); |
| 2559 | goto allocate; |
| 2560 | } |
| 2561 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2562 | req_q_size = req->length * sizeof(request_t); |
| 2563 | rsp_q_size = rsp->length * sizeof(response_t); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2564 | dump_size = offsetof(struct qla2xxx_fw_dump, isp); |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 2565 | 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] | 2566 | ha->chain_offset = dump_size; |
| 2567 | dump_size += mq_size + fce_size; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2568 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2569 | allocate: |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 2570 | ha->fw_dump = vmalloc(dump_size); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2571 | if (!ha->fw_dump) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2572 | ql_log(ql_log_warn, vha, 0x00c4, |
| 2573 | "Unable to allocate (%d KB) for firmware dump.\n", |
| 2574 | dump_size / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2575 | |
Madhuranath Iyengar | e30d175 | 2010-10-15 11:27:46 -0700 | [diff] [blame] | 2576 | if (ha->fce) { |
| 2577 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce, |
| 2578 | ha->fce_dma); |
| 2579 | ha->fce = NULL; |
| 2580 | ha->fce_dma = 0; |
| 2581 | } |
| 2582 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2583 | if (ha->eft) { |
| 2584 | dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft, |
| 2585 | ha->eft_dma); |
| 2586 | ha->eft = NULL; |
| 2587 | ha->eft_dma = 0; |
| 2588 | } |
| 2589 | return; |
| 2590 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2591 | ha->fw_dump_len = dump_size; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2592 | ql_dbg(ql_dbg_init, vha, 0x00c5, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2593 | "Allocated (%d KB) for firmware dump.\n", dump_size / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2594 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2595 | if (IS_QLA27XX(ha)) |
| 2596 | return; |
| 2597 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2598 | ha->fw_dump->signature[0] = 'Q'; |
| 2599 | ha->fw_dump->signature[1] = 'L'; |
| 2600 | ha->fw_dump->signature[2] = 'G'; |
| 2601 | ha->fw_dump->signature[3] = 'C'; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2602 | ha->fw_dump->version = htonl(1); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2603 | |
| 2604 | ha->fw_dump->fixed_size = htonl(fixed_size); |
| 2605 | ha->fw_dump->mem_size = htonl(mem_size); |
| 2606 | ha->fw_dump->req_q_size = htonl(req_q_size); |
| 2607 | ha->fw_dump->rsp_q_size = htonl(rsp_q_size); |
| 2608 | |
| 2609 | ha->fw_dump->eft_size = htonl(eft_size); |
| 2610 | ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma)); |
| 2611 | ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma)); |
| 2612 | |
| 2613 | ha->fw_dump->header_size = |
| 2614 | htonl(offsetof(struct qla2xxx_fw_dump, isp)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2615 | } |
| 2616 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2617 | static int |
| 2618 | qla81xx_mpi_sync(scsi_qla_host_t *vha) |
| 2619 | { |
| 2620 | #define MPS_MASK 0xe0 |
| 2621 | int rval; |
| 2622 | uint16_t dc; |
| 2623 | uint32_t dw; |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2624 | |
| 2625 | if (!IS_QLA81XX(vha->hw)) |
| 2626 | return QLA_SUCCESS; |
| 2627 | |
| 2628 | rval = qla2x00_write_ram_word(vha, 0x7c00, 1); |
| 2629 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2630 | ql_log(ql_log_warn, vha, 0x0105, |
| 2631 | "Unable to acquire semaphore.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2632 | goto done; |
| 2633 | } |
| 2634 | |
| 2635 | pci_read_config_word(vha->hw->pdev, 0x54, &dc); |
| 2636 | rval = qla2x00_read_ram_word(vha, 0x7a15, &dw); |
| 2637 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2638 | ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2639 | goto done_release; |
| 2640 | } |
| 2641 | |
| 2642 | dc &= MPS_MASK; |
| 2643 | if (dc == (dw & MPS_MASK)) |
| 2644 | goto done_release; |
| 2645 | |
| 2646 | dw &= ~MPS_MASK; |
| 2647 | dw |= dc; |
| 2648 | rval = qla2x00_write_ram_word(vha, 0x7a15, dw); |
| 2649 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2650 | ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2651 | } |
| 2652 | |
| 2653 | done_release: |
| 2654 | rval = qla2x00_write_ram_word(vha, 0x7c00, 0); |
| 2655 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2656 | ql_log(ql_log_warn, vha, 0x006d, |
| 2657 | "Unable to release semaphore.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2658 | } |
| 2659 | |
| 2660 | done: |
| 2661 | return rval; |
| 2662 | } |
| 2663 | |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2664 | int |
| 2665 | qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req) |
| 2666 | { |
| 2667 | /* Don't try to reallocate the array */ |
| 2668 | if (req->outstanding_cmds) |
| 2669 | return QLA_SUCCESS; |
| 2670 | |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 2671 | if (!IS_FWI2_CAPABLE(ha)) |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2672 | req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS; |
| 2673 | else { |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 2674 | if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count) |
| 2675 | req->num_outstanding_cmds = ha->cur_fw_xcb_count; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2676 | else |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 2677 | req->num_outstanding_cmds = ha->cur_fw_iocb_count; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2678 | } |
| 2679 | |
| 2680 | req->outstanding_cmds = kzalloc(sizeof(srb_t *) * |
| 2681 | req->num_outstanding_cmds, GFP_KERNEL); |
| 2682 | |
| 2683 | if (!req->outstanding_cmds) { |
| 2684 | /* |
| 2685 | * Try to allocate a minimal size just so we can get through |
| 2686 | * initialization. |
| 2687 | */ |
| 2688 | req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS; |
| 2689 | req->outstanding_cmds = kzalloc(sizeof(srb_t *) * |
| 2690 | req->num_outstanding_cmds, GFP_KERNEL); |
| 2691 | |
| 2692 | if (!req->outstanding_cmds) { |
| 2693 | ql_log(ql_log_fatal, NULL, 0x0126, |
| 2694 | "Failed to allocate memory for " |
| 2695 | "outstanding_cmds for req_que %p.\n", req); |
| 2696 | req->num_outstanding_cmds = 0; |
| 2697 | return QLA_FUNCTION_FAILED; |
| 2698 | } |
| 2699 | } |
| 2700 | |
| 2701 | return QLA_SUCCESS; |
| 2702 | } |
| 2703 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2704 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2705 | * qla2x00_setup_chip() - Load and start RISC firmware. |
| 2706 | * @ha: HA context |
| 2707 | * |
| 2708 | * Returns 0 on success. |
| 2709 | */ |
| 2710 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2711 | qla2x00_setup_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2712 | { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2713 | int rval; |
| 2714 | uint32_t srisc_address = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2715 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 2716 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 2717 | unsigned long flags; |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 2718 | uint16_t fw_major_version; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 2719 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 2720 | if (IS_P3P_TYPE(ha)) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2721 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 2722 | if (rval == QLA_SUCCESS) { |
| 2723 | qla2x00_stop_firmware(vha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2724 | goto enable_82xx_npiv; |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 2725 | } else |
Giridhar Malavali | b963752 | 2010-05-28 15:08:15 -0700 | [diff] [blame] | 2726 | goto failed; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2727 | } |
| 2728 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 2729 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 2730 | /* Disable SRAM, Instruction RAM and GP RAM parity. */ |
| 2731 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2732 | WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0)); |
| 2733 | RD_REG_WORD(®->hccr); |
| 2734 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2735 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2736 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2737 | qla81xx_mpi_sync(vha); |
| 2738 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2739 | /* Load firmware sequences */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2740 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2741 | if (rval == QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2742 | ql_dbg(ql_dbg_init, vha, 0x00c9, |
| 2743 | "Verifying Checksum of loaded RISC code.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2744 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2745 | rval = qla2x00_verify_checksum(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2746 | if (rval == QLA_SUCCESS) { |
| 2747 | /* Start firmware execution. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2748 | ql_dbg(ql_dbg_init, vha, 0x00ca, |
| 2749 | "Starting firmware.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | |
Himanshu Madhani | b0d6cab | 2015-12-17 14:56:56 -0500 | [diff] [blame] | 2751 | if (ql2xexlogins) |
| 2752 | ha->flags.exlogins_enabled = 1; |
| 2753 | |
Himanshu Madhani | 2f56a7f | 2015-12-17 14:56:57 -0500 | [diff] [blame] | 2754 | if (ql2xexchoffld) |
| 2755 | ha->flags.exchoffld_enabled = 1; |
| 2756 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2757 | rval = qla2x00_execute_fw(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2758 | /* Retrieve firmware information. */ |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 2759 | if (rval == QLA_SUCCESS) { |
Himanshu Madhani | b0d6cab | 2015-12-17 14:56:56 -0500 | [diff] [blame] | 2760 | rval = qla2x00_set_exlogins_buffer(vha); |
| 2761 | if (rval != QLA_SUCCESS) |
| 2762 | goto failed; |
| 2763 | |
Himanshu Madhani | 2f56a7f | 2015-12-17 14:56:57 -0500 | [diff] [blame] | 2764 | rval = qla2x00_set_exchoffld_buffer(vha); |
| 2765 | if (rval != QLA_SUCCESS) |
| 2766 | goto failed; |
| 2767 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2768 | enable_82xx_npiv: |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 2769 | fw_major_version = ha->fw_major_version; |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 2770 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | 3173167 | 2011-08-16 11:31:54 -0700 | [diff] [blame] | 2771 | qla82xx_check_md_needed(vha); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2772 | else |
| 2773 | rval = qla2x00_get_fw_version(vha); |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 2774 | if (rval != QLA_SUCCESS) |
| 2775 | goto failed; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2776 | ha->flags.npiv_supported = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2777 | if (IS_QLA2XXX_MIDTYPE(ha) && |
Mike Hernandez | 946fb89 | 2008-08-13 21:36:59 -0700 | [diff] [blame] | 2778 | (ha->fw_attributes & BIT_2)) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2779 | ha->flags.npiv_supported = 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 2780 | if ((!ha->max_npiv_vports) || |
| 2781 | ((ha->max_npiv_vports + 1) % |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 2782 | MIN_MULTI_ID_FABRIC)) |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 2783 | ha->max_npiv_vports = |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 2784 | MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 2785 | } |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 2786 | qla2x00_get_resource_cnts(vha); |
Andrew Vasquez | d743de6 | 2009-03-24 09:08:15 -0700 | [diff] [blame] | 2787 | |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2788 | /* |
| 2789 | * Allocate the array of outstanding commands |
| 2790 | * now that we know the firmware resources. |
| 2791 | */ |
| 2792 | rval = qla2x00_alloc_outstanding_cmds(ha, |
| 2793 | vha->req); |
| 2794 | if (rval != QLA_SUCCESS) |
| 2795 | goto failed; |
| 2796 | |
Saurav Kashyap | be5ea3c | 2011-11-18 09:02:11 -0800 | [diff] [blame] | 2797 | if (!fw_major_version && ql2xallocfwdump |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 2798 | && !(IS_P3P_TYPE(ha))) |
Giridhar Malavali | 08de284 | 2011-08-16 11:31:44 -0700 | [diff] [blame] | 2799 | qla2x00_alloc_fw_dump(vha); |
Chad Dupuis | 3b6e5b9 | 2013-10-30 03:38:09 -0400 | [diff] [blame] | 2800 | } else { |
| 2801 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2802 | } |
| 2803 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2804 | ql_log(ql_log_fatal, vha, 0x00cd, |
| 2805 | "ISP Firmware failed checksum.\n"); |
| 2806 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2807 | } |
Andrew Vasquez | c74d88a | 2012-08-22 14:21:19 -0400 | [diff] [blame] | 2808 | } else |
| 2809 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2810 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 2811 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 2812 | /* Enable proper parity. */ |
| 2813 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2814 | if (IS_QLA2300(ha)) |
| 2815 | /* SRAM parity */ |
| 2816 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1); |
| 2817 | else |
| 2818 | /* SRAM, Instruction RAM and GP RAM parity */ |
| 2819 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7); |
| 2820 | RD_REG_WORD(®->hccr); |
| 2821 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2822 | } |
| 2823 | |
Chad Dupuis | f3982d8 | 2014-09-25 05:16:57 -0400 | [diff] [blame] | 2824 | if (IS_QLA27XX(ha)) |
| 2825 | ha->flags.fac_supported = 1; |
| 2826 | else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) { |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 2827 | uint32_t size; |
| 2828 | |
| 2829 | rval = qla81xx_fac_get_sector_size(vha, &size); |
| 2830 | if (rval == QLA_SUCCESS) { |
| 2831 | ha->flags.fac_supported = 1; |
| 2832 | ha->fdt_block_size = size << 2; |
| 2833 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2834 | ql_log(ql_log_warn, vha, 0x00ce, |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 2835 | "Unsupported FAC firmware (%d.%02d.%02d).\n", |
| 2836 | ha->fw_major_version, ha->fw_minor_version, |
| 2837 | ha->fw_subminor_version); |
Joe Carnuccio | 1ca60e3 | 2014-02-26 04:15:02 -0500 | [diff] [blame] | 2838 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2839 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2840 | ha->flags.fac_supported = 0; |
| 2841 | rval = QLA_SUCCESS; |
| 2842 | } |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 2843 | } |
| 2844 | } |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 2845 | failed: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2847 | ql_log(ql_log_fatal, vha, 0x00cf, |
| 2848 | "Setup chip ****FAILED****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2849 | } |
| 2850 | |
| 2851 | return (rval); |
| 2852 | } |
| 2853 | |
| 2854 | /** |
| 2855 | * qla2x00_init_response_q_entries() - Initializes response queue entries. |
| 2856 | * @ha: HA context |
| 2857 | * |
| 2858 | * Beginning of request ring has initialization control block already built |
| 2859 | * by nvram config routine. |
| 2860 | * |
| 2861 | * Returns 0 on success. |
| 2862 | */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2863 | void |
| 2864 | qla2x00_init_response_q_entries(struct rsp_que *rsp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2865 | { |
| 2866 | uint16_t cnt; |
| 2867 | response_t *pkt; |
| 2868 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 2869 | rsp->ring_ptr = rsp->ring; |
| 2870 | rsp->ring_index = 0; |
| 2871 | rsp->status_srb = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2872 | pkt = rsp->ring_ptr; |
| 2873 | for (cnt = 0; cnt < rsp->length; cnt++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2874 | pkt->signature = RESPONSE_PROCESSED; |
| 2875 | pkt++; |
| 2876 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2877 | } |
| 2878 | |
| 2879 | /** |
| 2880 | * qla2x00_update_fw_options() - Read and process firmware options. |
| 2881 | * @ha: HA context |
| 2882 | * |
| 2883 | * Returns 0 on success. |
| 2884 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2885 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2886 | qla2x00_update_fw_options(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 | { |
| 2888 | uint16_t swing, emphasis, tx_sens, rx_sens; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2889 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2890 | |
| 2891 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2892 | qla2x00_get_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2893 | |
| 2894 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
| 2895 | return; |
| 2896 | |
| 2897 | /* Serial Link options. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2898 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115, |
| 2899 | "Serial link options.\n"); |
| 2900 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109, |
| 2901 | (uint8_t *)&ha->fw_seriallink_options, |
| 2902 | sizeof(ha->fw_seriallink_options)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2903 | |
| 2904 | ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING; |
| 2905 | if (ha->fw_seriallink_options[3] & BIT_2) { |
| 2906 | ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING; |
| 2907 | |
| 2908 | /* 1G settings */ |
| 2909 | swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0); |
| 2910 | emphasis = (ha->fw_seriallink_options[2] & |
| 2911 | (BIT_4 | BIT_3)) >> 3; |
| 2912 | tx_sens = ha->fw_seriallink_options[0] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2913 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2914 | rx_sens = (ha->fw_seriallink_options[0] & |
| 2915 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 2916 | ha->fw_options[10] = (emphasis << 14) | (swing << 8); |
| 2917 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 2918 | if (rx_sens == 0x0) |
| 2919 | rx_sens = 0x3; |
| 2920 | ha->fw_options[10] |= (tx_sens << 4) | rx_sens; |
| 2921 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 2922 | ha->fw_options[10] |= BIT_5 | |
| 2923 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 2924 | (tx_sens & (BIT_1 | BIT_0)); |
| 2925 | |
| 2926 | /* 2G settings */ |
| 2927 | swing = (ha->fw_seriallink_options[2] & |
| 2928 | (BIT_7 | BIT_6 | BIT_5)) >> 5; |
| 2929 | emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0); |
| 2930 | tx_sens = ha->fw_seriallink_options[1] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2931 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2932 | rx_sens = (ha->fw_seriallink_options[1] & |
| 2933 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 2934 | ha->fw_options[11] = (emphasis << 14) | (swing << 8); |
| 2935 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 2936 | if (rx_sens == 0x0) |
| 2937 | rx_sens = 0x3; |
| 2938 | ha->fw_options[11] |= (tx_sens << 4) | rx_sens; |
| 2939 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 2940 | ha->fw_options[11] |= BIT_5 | |
| 2941 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 2942 | (tx_sens & (BIT_1 | BIT_0)); |
| 2943 | } |
| 2944 | |
| 2945 | /* FCP2 options. */ |
| 2946 | /* Return command IOCBs without waiting for an ABTS to complete. */ |
| 2947 | ha->fw_options[3] |= BIT_13; |
| 2948 | |
| 2949 | /* LED scheme. */ |
| 2950 | if (ha->flags.enable_led_scheme) |
| 2951 | ha->fw_options[2] |= BIT_12; |
| 2952 | |
andrew.vasquez@qlogic.com | 48c02fd | 2006-03-09 14:27:18 -0800 | [diff] [blame] | 2953 | /* Detect ISP6312. */ |
| 2954 | if (IS_QLA6312(ha)) |
| 2955 | ha->fw_options[2] |= BIT_13; |
| 2956 | |
Giridhar Malavali | 088d09d | 2016-07-06 11:14:20 -0400 | [diff] [blame] | 2957 | /* Set Retry FLOGI in case of P2P connection */ |
| 2958 | if (ha->operating_mode == P2P) { |
| 2959 | ha->fw_options[2] |= BIT_3; |
| 2960 | ql_dbg(ql_dbg_disc, vha, 0x2100, |
| 2961 | "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n", |
| 2962 | __func__, ha->fw_options[2]); |
| 2963 | } |
| 2964 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | /* Update firmware options. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2966 | qla2x00_set_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2967 | } |
| 2968 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2969 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2970 | qla24xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2971 | { |
| 2972 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2973 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2974 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 2975 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2976 | return; |
| 2977 | |
Himanshu Madhani | f198caf | 2016-01-27 12:03:30 -0500 | [diff] [blame] | 2978 | /* Hold status IOCBs until ABTS response received. */ |
| 2979 | if (ql2xfwholdabts) |
| 2980 | ha->fw_options[3] |= BIT_12; |
| 2981 | |
Giridhar Malavali | 088d09d | 2016-07-06 11:14:20 -0400 | [diff] [blame] | 2982 | /* Set Retry FLOGI in case of P2P connection */ |
| 2983 | if (ha->operating_mode == P2P) { |
| 2984 | ha->fw_options[2] |= BIT_3; |
| 2985 | ql_dbg(ql_dbg_disc, vha, 0x2101, |
| 2986 | "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n", |
| 2987 | __func__, ha->fw_options[2]); |
| 2988 | } |
| 2989 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 2990 | /* Move PUREX, ABTS RX & RIDA to ATIOQ */ |
| 2991 | if (ql2xmvasynctoatio) { |
| 2992 | if (qla_tgt_mode_enabled(vha) || |
| 2993 | qla_dual_mode_enabled(vha)) |
| 2994 | ha->fw_options[2] |= BIT_11; |
| 2995 | else |
| 2996 | ha->fw_options[2] &= ~BIT_11; |
| 2997 | } |
| 2998 | |
| 2999 | ql_dbg(ql_dbg_init, vha, 0xffff, |
| 3000 | "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n", |
| 3001 | __func__, ha->fw_options[1], ha->fw_options[2], |
| 3002 | ha->fw_options[3], vha->host->active_mode); |
| 3003 | qla2x00_set_fw_options(vha, ha->fw_options); |
| 3004 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3005 | /* Update Serial Link options. */ |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 3006 | if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3007 | return; |
| 3008 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3009 | rval = qla2x00_set_serdes_params(vha, |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 3010 | le16_to_cpu(ha->fw_seriallink_options24[1]), |
| 3011 | le16_to_cpu(ha->fw_seriallink_options24[2]), |
| 3012 | le16_to_cpu(ha->fw_seriallink_options24[3])); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3013 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3014 | ql_log(ql_log_warn, vha, 0x0104, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3015 | "Unable to update Serial Link options (%x).\n", rval); |
| 3016 | } |
| 3017 | } |
| 3018 | |
| 3019 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3020 | qla2x00_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3021 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3022 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 3023 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3024 | struct req_que *req = ha->req_q_map[0]; |
| 3025 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3026 | |
| 3027 | /* Setup ring parameters in initialization control block. */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3028 | ha->init_cb->request_q_outpointer = cpu_to_le16(0); |
| 3029 | ha->init_cb->response_q_inpointer = cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3030 | ha->init_cb->request_q_length = cpu_to_le16(req->length); |
| 3031 | ha->init_cb->response_q_length = cpu_to_le16(rsp->length); |
| 3032 | ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 3033 | ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 3034 | ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 3035 | 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] | 3036 | |
| 3037 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0); |
| 3038 | WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0); |
| 3039 | WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0); |
| 3040 | WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0); |
| 3041 | RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */ |
| 3042 | } |
| 3043 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3044 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3045 | qla24xx_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3046 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3047 | struct qla_hw_data *ha = vha->hw; |
Bart Van Assche | 118e2ef | 2015-07-09 07:24:27 -0700 | [diff] [blame] | 3048 | device_reg_t *reg = ISP_QUE_REG(ha, 0); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3049 | struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp; |
| 3050 | struct qla_msix_entry *msix; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3051 | struct init_cb_24xx *icb; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3052 | uint16_t rid = 0; |
| 3053 | struct req_que *req = ha->req_q_map[0]; |
| 3054 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3055 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3056 | /* Setup ring parameters in initialization control block. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3057 | icb = (struct init_cb_24xx *)ha->init_cb; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3058 | icb->request_q_outpointer = cpu_to_le16(0); |
| 3059 | icb->response_q_inpointer = cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3060 | icb->request_q_length = cpu_to_le16(req->length); |
| 3061 | icb->response_q_length = cpu_to_le16(rsp->length); |
| 3062 | icb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 3063 | icb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 3064 | icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 3065 | icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3066 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3067 | /* Setup ATIO queue dma pointers for target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3068 | icb->atio_q_inpointer = cpu_to_le16(0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3069 | icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length); |
| 3070 | icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma)); |
| 3071 | icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma)); |
| 3072 | |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3073 | if (IS_SHADOW_REG_CAPABLE(ha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3074 | icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29); |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3075 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 3076 | if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3077 | icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS); |
| 3078 | icb->rid = cpu_to_le16(rid); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3079 | if (ha->flags.msix_enabled) { |
| 3080 | msix = &ha->msix_entries[1]; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3081 | ql_dbg(ql_dbg_init, vha, 0x00fd, |
| 3082 | "Registering vector 0x%x for base que.\n", |
| 3083 | msix->entry); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3084 | icb->msix = cpu_to_le16(msix->entry); |
| 3085 | } |
| 3086 | /* Use alternate PCI bus number */ |
| 3087 | if (MSB(rid)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3088 | icb->firmware_options_2 |= cpu_to_le32(BIT_19); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3089 | /* Use alternate PCI devfn */ |
| 3090 | if (LSB(rid)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3091 | icb->firmware_options_2 |= cpu_to_le32(BIT_18); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3092 | |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 3093 | /* Use Disable MSIX Handshake mode for capable adapters */ |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3094 | if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) && |
| 3095 | (ha->flags.msix_enabled)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3096 | icb->firmware_options_2 &= cpu_to_le32(~BIT_22); |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 3097 | ha->flags.disable_msix_handshake = 1; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3098 | ql_dbg(ql_dbg_init, vha, 0x00fe, |
| 3099 | "MSIX Handshake Disable Mode turned on.\n"); |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 3100 | } else { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3101 | icb->firmware_options_2 |= cpu_to_le32(BIT_22); |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 3102 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3103 | icb->firmware_options_2 |= cpu_to_le32(BIT_23); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3104 | |
| 3105 | WRT_REG_DWORD(®->isp25mq.req_q_in, 0); |
| 3106 | WRT_REG_DWORD(®->isp25mq.req_q_out, 0); |
| 3107 | WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0); |
| 3108 | WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0); |
| 3109 | } else { |
| 3110 | WRT_REG_DWORD(®->isp24.req_q_in, 0); |
| 3111 | WRT_REG_DWORD(®->isp24.req_q_out, 0); |
| 3112 | WRT_REG_DWORD(®->isp24.rsp_q_in, 0); |
| 3113 | WRT_REG_DWORD(®->isp24.rsp_q_out, 0); |
| 3114 | } |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 3115 | qlt_24xx_config_rings(vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3116 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3117 | /* PCI posting */ |
| 3118 | RD_REG_DWORD(&ioreg->hccr); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3119 | } |
| 3120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3121 | /** |
| 3122 | * qla2x00_init_rings() - Initializes firmware. |
| 3123 | * @ha: HA context |
| 3124 | * |
| 3125 | * Beginning of request ring has initialization control block already built |
| 3126 | * by nvram config routine. |
| 3127 | * |
| 3128 | * Returns 0 on success. |
| 3129 | */ |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3130 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3131 | qla2x00_init_rings(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3132 | { |
| 3133 | int rval; |
| 3134 | unsigned long flags = 0; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3135 | int cnt, que; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3136 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3137 | struct req_que *req; |
| 3138 | struct rsp_que *rsp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3139 | struct mid_init_cb_24xx *mid_init_cb = |
| 3140 | (struct mid_init_cb_24xx *) ha->init_cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3141 | |
| 3142 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3143 | |
| 3144 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 3145 | for (que = 0; que < ha->max_req_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3146 | req = ha->req_q_map[que]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 3147 | if (!req || !test_bit(que, ha->req_qid_map)) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3148 | continue; |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3149 | req->out_ptr = (void *)(req->ring + req->length); |
| 3150 | *req->out_ptr = 0; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 3151 | for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3152 | req->outstanding_cmds[cnt] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3153 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 3154 | req->current_outstanding_cmd = 1; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3155 | |
| 3156 | /* Initialize firmware. */ |
| 3157 | req->ring_ptr = req->ring; |
| 3158 | req->ring_index = 0; |
| 3159 | req->cnt = req->length; |
| 3160 | } |
| 3161 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 3162 | for (que = 0; que < ha->max_rsp_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3163 | rsp = ha->rsp_q_map[que]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 3164 | if (!rsp || !test_bit(que, ha->rsp_qid_map)) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3165 | continue; |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3166 | rsp->in_ptr = (void *)(rsp->ring + rsp->length); |
| 3167 | *rsp->in_ptr = 0; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3168 | /* Initialize response queue entries */ |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3169 | if (IS_QLAFX00(ha)) |
| 3170 | qlafx00_init_response_q_entries(rsp); |
| 3171 | else |
| 3172 | qla2x00_init_response_q_entries(rsp); |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3173 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3174 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3175 | ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; |
| 3176 | ha->tgt.atio_ring_index = 0; |
| 3177 | /* Initialize ATIO queue entries */ |
| 3178 | qlt_init_atio_q_entries(vha); |
| 3179 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3180 | ha->isp_ops->config_rings(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3181 | |
| 3182 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3183 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3184 | ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n"); |
| 3185 | |
| 3186 | if (IS_QLAFX00(ha)) { |
| 3187 | rval = qlafx00_init_firmware(vha, ha->init_cb_size); |
| 3188 | goto next_check; |
| 3189 | } |
| 3190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3191 | /* Update any ISP specific firmware options before initialization. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3192 | ha->isp_ops->update_fw_options(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3193 | |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 3194 | if (ha->flags.npiv_supported) { |
Saurav Kashyap | 45980cc | 2012-08-22 14:21:21 -0400 | [diff] [blame] | 3195 | if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha)) |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 3196 | ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | c48339d | 2008-01-17 09:02:19 -0800 | [diff] [blame] | 3197 | mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports); |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 3198 | } |
| 3199 | |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 3200 | if (IS_FWI2_CAPABLE(ha)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3201 | mid_init_cb->options = cpu_to_le16(BIT_1); |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 3202 | mid_init_cb->init_cb.execution_throttle = |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3203 | cpu_to_le16(ha->cur_fw_xcb_count); |
Joe Carnuccio | 40f3862 | 2016-07-06 11:14:28 -0400 | [diff] [blame] | 3204 | ha->flags.dport_enabled = |
| 3205 | (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0; |
| 3206 | ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n", |
| 3207 | (ha->flags.dport_enabled) ? "enabled" : "disabled"); |
| 3208 | /* FA-WWPN Status */ |
Himanshu Madhani | 2486c62 | 2014-09-25 05:17:00 -0400 | [diff] [blame] | 3209 | ha->flags.fawwpn_enabled = |
Joe Carnuccio | 40f3862 | 2016-07-06 11:14:28 -0400 | [diff] [blame] | 3210 | (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0; |
Himanshu Madhani | 2486c62 | 2014-09-25 05:17:00 -0400 | [diff] [blame] | 3211 | ql_dbg(ql_dbg_init, vha, 0x0141, "FA-WWPN Support: %s.\n", |
| 3212 | (ha->flags.fawwpn_enabled) ? "enabled" : "disabled"); |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 3213 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3214 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3215 | rval = qla2x00_init_firmware(vha, ha->init_cb_size); |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3216 | next_check: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3217 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3218 | ql_log(ql_log_fatal, vha, 0x00d2, |
| 3219 | "Init Firmware **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3221 | ql_dbg(ql_dbg_init, vha, 0x00d3, |
| 3222 | "Init Firmware -- success.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3223 | } |
| 3224 | |
| 3225 | return (rval); |
| 3226 | } |
| 3227 | |
| 3228 | /** |
| 3229 | * qla2x00_fw_ready() - Waits for firmware ready. |
| 3230 | * @ha: HA context |
| 3231 | * |
| 3232 | * Returns 0 on success. |
| 3233 | */ |
| 3234 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3235 | qla2x00_fw_ready(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3236 | { |
| 3237 | int rval; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3238 | unsigned long wtime, mtime, cs84xx_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3239 | uint16_t min_wait; /* Minimum wait time if loop is down */ |
| 3240 | uint16_t wait_time; /* Wait time if loop is coming ready */ |
Joe Carnuccio | b5a340d | 2014-09-25 05:16:48 -0400 | [diff] [blame] | 3241 | uint16_t state[6]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3242 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3243 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3244 | if (IS_QLAFX00(vha->hw)) |
| 3245 | return qlafx00_fw_ready(vha); |
| 3246 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | rval = QLA_SUCCESS; |
| 3248 | |
Chad Dupuis | 3346149 | 2015-04-09 14:59:57 -0400 | [diff] [blame] | 3249 | /* Time to wait for loop down */ |
| 3250 | if (IS_P3P_TYPE(ha)) |
| 3251 | min_wait = 30; |
| 3252 | else |
| 3253 | min_wait = 20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | |
| 3255 | /* |
| 3256 | * Firmware should take at most one RATOV to login, plus 5 seconds for |
| 3257 | * our own processing. |
| 3258 | */ |
| 3259 | if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) { |
| 3260 | wait_time = min_wait; |
| 3261 | } |
| 3262 | |
| 3263 | /* Min wait time if loop down */ |
| 3264 | mtime = jiffies + (min_wait * HZ); |
| 3265 | |
| 3266 | /* wait time before firmware ready */ |
| 3267 | wtime = jiffies + (wait_time * HZ); |
| 3268 | |
| 3269 | /* Wait for ISP to finish LIP */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3270 | if (!vha->flags.init_done) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3271 | ql_log(ql_log_info, vha, 0x801e, |
| 3272 | "Waiting for LIP to complete.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3273 | |
| 3274 | do { |
Andrew Vasquez | 5b93903 | 2012-11-21 02:40:26 -0500 | [diff] [blame] | 3275 | memset(state, -1, sizeof(state)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3276 | rval = qla2x00_get_firmware_state(vha, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3277 | if (rval == QLA_SUCCESS) { |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3278 | if (state[0] < FSTATE_LOSS_OF_SYNC) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3279 | vha->device_flags &= ~DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3280 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3281 | if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3282 | ql_dbg(ql_dbg_taskm, vha, 0x801f, |
| 3283 | "fw_state=%x 84xx=%x.\n", state[0], |
| 3284 | state[2]); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3285 | if ((state[2] & FSTATE_LOGGED_IN) && |
| 3286 | (state[2] & FSTATE_WAITING_FOR_VERIFY)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3287 | ql_dbg(ql_dbg_taskm, vha, 0x8028, |
| 3288 | "Sending verify iocb.\n"); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3289 | |
| 3290 | cs84xx_time = jiffies; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3291 | rval = qla84xx_init_chip(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3292 | if (rval != QLA_SUCCESS) { |
| 3293 | ql_log(ql_log_warn, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 3294 | vha, 0x8007, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3295 | "Init chip failed.\n"); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3296 | break; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3297 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3298 | |
| 3299 | /* Add time taken to initialize. */ |
| 3300 | cs84xx_time = jiffies - cs84xx_time; |
| 3301 | wtime += cs84xx_time; |
| 3302 | mtime += cs84xx_time; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 3303 | ql_dbg(ql_dbg_taskm, vha, 0x8008, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3304 | "Increasing wait time by %ld. " |
| 3305 | "New time %ld.\n", cs84xx_time, |
| 3306 | wtime); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3307 | } |
| 3308 | } else if (state[0] == FSTATE_READY) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3309 | ql_dbg(ql_dbg_taskm, vha, 0x8037, |
| 3310 | "F/W Ready - OK.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3311 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3312 | qla2x00_get_retry_cnt(vha, &ha->retry_count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3313 | &ha->login_timeout, &ha->r_a_tov); |
| 3314 | |
| 3315 | rval = QLA_SUCCESS; |
| 3316 | break; |
| 3317 | } |
| 3318 | |
| 3319 | rval = QLA_FUNCTION_FAILED; |
| 3320 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3321 | if (atomic_read(&vha->loop_down_timer) && |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3322 | state[0] != FSTATE_READY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3323 | /* Loop down. Timeout on min_wait for states |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3324 | * other than Wait for Login. |
| 3325 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3326 | if (time_after_eq(jiffies, mtime)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3327 | ql_log(ql_log_info, vha, 0x8038, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3328 | "Cable is unplugged...\n"); |
| 3329 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3330 | vha->device_flags |= DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3331 | break; |
| 3332 | } |
| 3333 | } |
| 3334 | } else { |
| 3335 | /* Mailbox cmd failed. Timeout on min_wait. */ |
Santosh Vernekar | cdbb0a4f | 2010-05-28 15:08:25 -0700 | [diff] [blame] | 3336 | if (time_after_eq(jiffies, mtime) || |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 3337 | ha->flags.isp82xx_fw_hung) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3338 | break; |
| 3339 | } |
| 3340 | |
| 3341 | if (time_after_eq(jiffies, wtime)) |
| 3342 | break; |
| 3343 | |
| 3344 | /* Delay for a while */ |
| 3345 | msleep(500); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3346 | } while (1); |
| 3347 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3348 | ql_dbg(ql_dbg_taskm, vha, 0x803a, |
Joe Carnuccio | b5a340d | 2014-09-25 05:16:48 -0400 | [diff] [blame] | 3349 | "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0], |
| 3350 | state[1], state[2], state[3], state[4], state[5], jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3351 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 3352 | if (rval && !(vha->device_flags & DFLG_NO_CABLE)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3353 | ql_log(ql_log_warn, vha, 0x803b, |
| 3354 | "Firmware ready **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3355 | } |
| 3356 | |
| 3357 | return (rval); |
| 3358 | } |
| 3359 | |
| 3360 | /* |
| 3361 | * qla2x00_configure_hba |
| 3362 | * Setup adapter context. |
| 3363 | * |
| 3364 | * Input: |
| 3365 | * ha = adapter state pointer. |
| 3366 | * |
| 3367 | * Returns: |
| 3368 | * 0 = success |
| 3369 | * |
| 3370 | * Context: |
| 3371 | * Kernel context. |
| 3372 | */ |
| 3373 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3374 | qla2x00_configure_hba(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | { |
| 3376 | int rval; |
| 3377 | uint16_t loop_id; |
| 3378 | uint16_t topo; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3379 | uint16_t sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3380 | uint8_t al_pa; |
| 3381 | uint8_t area; |
| 3382 | uint8_t domain; |
| 3383 | char connect_type[22]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3384 | struct qla_hw_data *ha = vha->hw; |
Jiri Kosina | f24b5cb | 2012-10-08 09:23:54 +0200 | [diff] [blame] | 3385 | unsigned long flags; |
Joe Carnuccio | 61e1b26 | 2013-02-08 01:57:48 -0500 | [diff] [blame] | 3386 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3387 | |
| 3388 | /* Get host addresses. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3389 | rval = qla2x00_get_adapter_id(vha, |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3390 | &loop_id, &al_pa, &area, &domain, &topo, &sw_cap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3391 | if (rval != QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3392 | if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) || |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3393 | IS_CNA_CAPABLE(ha) || |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 3394 | (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3395 | ql_dbg(ql_dbg_disc, vha, 0x2008, |
| 3396 | "Loop is in a transition state.\n"); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 3397 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3398 | ql_log(ql_log_warn, vha, 0x2009, |
| 3399 | "Unable to get host loop ID.\n"); |
Joe Carnuccio | 61e1b26 | 2013-02-08 01:57:48 -0500 | [diff] [blame] | 3400 | if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) && |
| 3401 | (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) { |
| 3402 | ql_log(ql_log_warn, vha, 0x1151, |
| 3403 | "Doing link init.\n"); |
| 3404 | if (qla24xx_link_initialize(vha) == QLA_SUCCESS) |
| 3405 | return rval; |
| 3406 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3407 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 3408 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3409 | return (rval); |
| 3410 | } |
| 3411 | |
| 3412 | if (topo == 4) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3413 | ql_log(ql_log_info, vha, 0x200a, |
| 3414 | "Cannot get topology - retrying.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3415 | return (QLA_FUNCTION_FAILED); |
| 3416 | } |
| 3417 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3418 | vha->loop_id = loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3419 | |
| 3420 | /* initialize */ |
| 3421 | ha->min_external_loopid = SNS_FIRST_LOOP_ID; |
| 3422 | ha->operating_mode = LOOP; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3423 | ha->switch_cap = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3424 | |
| 3425 | switch (topo) { |
| 3426 | case 0: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3427 | ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3428 | ha->current_topology = ISP_CFG_NL; |
| 3429 | strcpy(connect_type, "(Loop)"); |
| 3430 | break; |
| 3431 | |
| 3432 | case 1: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3433 | ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n"); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3434 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3435 | ha->current_topology = ISP_CFG_FL; |
| 3436 | strcpy(connect_type, "(FL_Port)"); |
| 3437 | break; |
| 3438 | |
| 3439 | case 2: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3440 | 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] | 3441 | ha->operating_mode = P2P; |
| 3442 | ha->current_topology = ISP_CFG_N; |
| 3443 | strcpy(connect_type, "(N_Port-to-N_Port)"); |
| 3444 | break; |
| 3445 | |
| 3446 | case 3: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3447 | 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] | 3448 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3449 | ha->operating_mode = P2P; |
| 3450 | ha->current_topology = ISP_CFG_F; |
| 3451 | strcpy(connect_type, "(F_Port)"); |
| 3452 | break; |
| 3453 | |
| 3454 | default: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3455 | ql_dbg(ql_dbg_disc, vha, 0x200f, |
| 3456 | "HBA in unknown topology %x, using NL.\n", topo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3457 | ha->current_topology = ISP_CFG_NL; |
| 3458 | strcpy(connect_type, "(Loop)"); |
| 3459 | break; |
| 3460 | } |
| 3461 | |
| 3462 | /* Save Host port and loop ID. */ |
| 3463 | /* byte order - Big Endian */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3464 | vha->d_id.b.domain = domain; |
| 3465 | vha->d_id.b.area = area; |
| 3466 | vha->d_id.b.al_pa = al_pa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3467 | |
Jiri Kosina | f24b5cb | 2012-10-08 09:23:54 +0200 | [diff] [blame] | 3468 | spin_lock_irqsave(&ha->vport_slock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3469 | qlt_update_vp_map(vha, SET_AL_PA); |
Jiri Kosina | f24b5cb | 2012-10-08 09:23:54 +0200 | [diff] [blame] | 3470 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3471 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3472 | if (!vha->flags.init_done) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3473 | ql_log(ql_log_info, vha, 0x2010, |
| 3474 | "Topology - %s, Host Loop address 0x%x.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3475 | connect_type, vha->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3476 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3477 | return(rval); |
| 3478 | } |
| 3479 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3480 | inline void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3481 | qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len, |
| 3482 | char *def) |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3483 | { |
| 3484 | char *st, *en; |
| 3485 | uint16_t index; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3486 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | ab67114 | 2009-08-25 11:36:17 -0700 | [diff] [blame] | 3487 | int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) && |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3488 | !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3489 | |
| 3490 | if (memcmp(model, BINZERO, len) != 0) { |
| 3491 | strncpy(ha->model_number, model, len); |
| 3492 | st = en = ha->model_number; |
| 3493 | en += len - 1; |
| 3494 | while (en > st) { |
| 3495 | if (*en != 0x20 && *en != 0x00) |
| 3496 | break; |
| 3497 | *en-- = '\0'; |
| 3498 | } |
| 3499 | |
| 3500 | index = (ha->pdev->subsystem_device & 0xff); |
Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 3501 | if (use_tbl && |
| 3502 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3503 | index < QLA_MODEL_NAMES) |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 3504 | strncpy(ha->model_desc, |
| 3505 | qla2x00_model_name[index * 2 + 1], |
| 3506 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3507 | } else { |
| 3508 | index = (ha->pdev->subsystem_device & 0xff); |
Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 3509 | if (use_tbl && |
| 3510 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3511 | index < QLA_MODEL_NAMES) { |
| 3512 | strcpy(ha->model_number, |
| 3513 | qla2x00_model_name[index * 2]); |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 3514 | strncpy(ha->model_desc, |
| 3515 | qla2x00_model_name[index * 2 + 1], |
| 3516 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3517 | } else { |
| 3518 | strcpy(ha->model_number, def); |
| 3519 | } |
| 3520 | } |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 3521 | if (IS_FWI2_CAPABLE(ha)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3522 | qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc, |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 3523 | sizeof(ha->model_desc)); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3524 | } |
| 3525 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3526 | /* On sparc systems, obtain port and node WWN from firmware |
| 3527 | * properties. |
| 3528 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3529 | 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] | 3530 | { |
| 3531 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3532 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3533 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 3534 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 3535 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3536 | int len; |
| 3537 | |
| 3538 | val = of_get_property(dp, "port-wwn", &len); |
| 3539 | if (val && len >= WWN_SIZE) |
| 3540 | memcpy(nv->port_name, val, WWN_SIZE); |
| 3541 | |
| 3542 | val = of_get_property(dp, "node-wwn", &len); |
| 3543 | if (val && len >= WWN_SIZE) |
| 3544 | memcpy(nv->node_name, val, WWN_SIZE); |
| 3545 | #endif |
| 3546 | } |
| 3547 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3548 | /* |
| 3549 | * NVRAM configuration for ISP 2xxx |
| 3550 | * |
| 3551 | * Input: |
| 3552 | * ha = adapter block pointer. |
| 3553 | * |
| 3554 | * Output: |
| 3555 | * initialization control block in response_ring |
| 3556 | * host adapters parameters in host adapter block |
| 3557 | * |
| 3558 | * Returns: |
| 3559 | * 0 = success. |
| 3560 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3561 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3562 | qla2x00_nvram_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3563 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3564 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3565 | uint8_t chksum = 0; |
| 3566 | uint16_t cnt; |
| 3567 | uint8_t *dptr1, *dptr2; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3568 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3569 | init_cb_t *icb = ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 3570 | nvram_t *nv = ha->nvram; |
| 3571 | uint8_t *ptr = ha->nvram; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 3572 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3573 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3574 | rval = QLA_SUCCESS; |
| 3575 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3576 | /* Determine NVRAM starting address. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3577 | ha->nvram_size = sizeof(nvram_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3578 | ha->nvram_base = 0; |
| 3579 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) |
| 3580 | if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1) |
| 3581 | ha->nvram_base = 0x80; |
| 3582 | |
| 3583 | /* Get NVRAM data and calculate checksum. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3584 | 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] | 3585 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++) |
| 3586 | chksum += *ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3587 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3588 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f, |
| 3589 | "Contents of NVRAM.\n"); |
| 3590 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110, |
| 3591 | (uint8_t *)nv, ha->nvram_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3592 | |
| 3593 | /* Bad NVRAM data, set defaults parameters. */ |
| 3594 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || |
| 3595 | nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) { |
| 3596 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3597 | ql_log(ql_log_warn, vha, 0x0064, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 3598 | "Inconsistent NVRAM " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3599 | "detected: checksum=0x%x id=%c version=0x%x.\n", |
| 3600 | chksum, nv->id[0], nv->nvram_version); |
| 3601 | ql_log(ql_log_warn, vha, 0x0065, |
| 3602 | "Falling back to " |
| 3603 | "functioning (yet invalid -- WWPN) defaults.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3604 | |
| 3605 | /* |
| 3606 | * Set default initialization control block. |
| 3607 | */ |
| 3608 | memset(nv, 0, ha->nvram_size); |
| 3609 | nv->parameter_block_version = ICB_VERSION; |
| 3610 | |
| 3611 | if (IS_QLA23XX(ha)) { |
| 3612 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 3613 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 3614 | nv->add_firmware_options[0] = BIT_5; |
| 3615 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 3616 | nv->frame_payload_size = 2048; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3617 | nv->special_options[1] = BIT_7; |
| 3618 | } else if (IS_QLA2200(ha)) { |
| 3619 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 3620 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 3621 | nv->add_firmware_options[0] = BIT_5; |
| 3622 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 3623 | nv->frame_payload_size = 1024; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3624 | } else if (IS_QLA2100(ha)) { |
| 3625 | nv->firmware_options[0] = BIT_3 | BIT_1; |
| 3626 | nv->firmware_options[1] = BIT_5; |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 3627 | nv->frame_payload_size = 1024; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3628 | } |
| 3629 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3630 | nv->max_iocb_allocation = cpu_to_le16(256); |
| 3631 | nv->execution_throttle = cpu_to_le16(16); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3632 | nv->retry_count = 8; |
| 3633 | nv->retry_delay = 1; |
| 3634 | |
| 3635 | nv->port_name[0] = 33; |
| 3636 | nv->port_name[3] = 224; |
| 3637 | nv->port_name[4] = 139; |
| 3638 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3639 | qla2xxx_nvram_wwn_from_ofw(vha, nv); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3640 | |
| 3641 | nv->login_timeout = 4; |
| 3642 | |
| 3643 | /* |
| 3644 | * Set default host adapter parameters |
| 3645 | */ |
| 3646 | nv->host_p[1] = BIT_2; |
| 3647 | nv->reset_delay = 5; |
| 3648 | nv->port_down_retry_count = 8; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3649 | nv->max_luns_per_target = cpu_to_le16(8); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3650 | nv->link_down_timeout = 60; |
| 3651 | |
| 3652 | rval = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3653 | } |
| 3654 | |
| 3655 | #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2) |
| 3656 | /* |
| 3657 | * The SN2 does not provide BIOS emulation which means you can't change |
| 3658 | * potentially bogus BIOS settings. Force the use of default settings |
| 3659 | * for link rate and frame size. Hope that the rest of the settings |
| 3660 | * are valid. |
| 3661 | */ |
| 3662 | if (ia64_platform_is("sn2")) { |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 3663 | nv->frame_payload_size = 2048; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3664 | if (IS_QLA23XX(ha)) |
| 3665 | nv->special_options[1] = BIT_7; |
| 3666 | } |
| 3667 | #endif |
| 3668 | |
| 3669 | /* Reset Initialization control block */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3670 | memset(icb, 0, ha->init_cb_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3671 | |
| 3672 | /* |
| 3673 | * Setup driver NVRAM options. |
| 3674 | */ |
| 3675 | nv->firmware_options[0] |= (BIT_6 | BIT_1); |
| 3676 | nv->firmware_options[0] &= ~(BIT_5 | BIT_4); |
| 3677 | nv->firmware_options[1] |= (BIT_5 | BIT_0); |
| 3678 | nv->firmware_options[1] &= ~BIT_4; |
| 3679 | |
| 3680 | if (IS_QLA23XX(ha)) { |
| 3681 | nv->firmware_options[0] |= BIT_2; |
| 3682 | nv->firmware_options[0] &= ~BIT_3; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3683 | nv->special_options[0] &= ~BIT_6; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3684 | nv->add_firmware_options[1] |= BIT_5 | BIT_4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3685 | |
| 3686 | if (IS_QLA2300(ha)) { |
| 3687 | if (ha->fb_rev == FPM_2310) { |
| 3688 | strcpy(ha->model_number, "QLA2310"); |
| 3689 | } else { |
| 3690 | strcpy(ha->model_number, "QLA2300"); |
| 3691 | } |
| 3692 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3693 | qla2x00_set_model_info(vha, nv->model_number, |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3694 | sizeof(nv->model_number), "QLA23xx"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3695 | } |
| 3696 | } else if (IS_QLA2200(ha)) { |
| 3697 | nv->firmware_options[0] |= BIT_2; |
| 3698 | /* |
| 3699 | * 'Point-to-point preferred, else loop' is not a safe |
| 3700 | * connection mode setting. |
| 3701 | */ |
| 3702 | if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) == |
| 3703 | (BIT_5 | BIT_4)) { |
| 3704 | /* Force 'loop preferred, else point-to-point'. */ |
| 3705 | nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4); |
| 3706 | nv->add_firmware_options[0] |= BIT_5; |
| 3707 | } |
| 3708 | strcpy(ha->model_number, "QLA22xx"); |
| 3709 | } else /*if (IS_QLA2100(ha))*/ { |
| 3710 | strcpy(ha->model_number, "QLA2100"); |
| 3711 | } |
| 3712 | |
| 3713 | /* |
| 3714 | * Copy over NVRAM RISC parameter block to initialization control block. |
| 3715 | */ |
| 3716 | dptr1 = (uint8_t *)icb; |
| 3717 | dptr2 = (uint8_t *)&nv->parameter_block_version; |
| 3718 | cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version; |
| 3719 | while (cnt--) |
| 3720 | *dptr1++ = *dptr2++; |
| 3721 | |
| 3722 | /* Copy 2nd half. */ |
| 3723 | dptr1 = (uint8_t *)icb->add_firmware_options; |
| 3724 | cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options; |
| 3725 | while (cnt--) |
| 3726 | *dptr1++ = *dptr2++; |
| 3727 | |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 3728 | /* Use alternate WWN? */ |
| 3729 | if (nv->host_p[1] & BIT_7) { |
| 3730 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 3731 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 3732 | } |
| 3733 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3734 | /* Prepare nodename */ |
| 3735 | if ((icb->firmware_options[1] & BIT_6) == 0) { |
| 3736 | /* |
| 3737 | * Firmware will apply the following mask if the nodename was |
| 3738 | * not provided. |
| 3739 | */ |
| 3740 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 3741 | icb->node_name[0] &= 0xF0; |
| 3742 | } |
| 3743 | |
| 3744 | /* |
| 3745 | * Set host adapter parameters. |
| 3746 | */ |
Saurav Kashyap | 3ce8866 | 2011-07-14 12:00:12 -0700 | [diff] [blame] | 3747 | |
| 3748 | /* |
| 3749 | * BIT_7 in the host-parameters section allows for modification to |
| 3750 | * internal driver logging. |
| 3751 | */ |
Andrew Vasquez | 0181944 | 2006-06-23 16:11:10 -0700 | [diff] [blame] | 3752 | if (nv->host_p[0] & BIT_7) |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 3753 | ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3754 | ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0); |
| 3755 | /* Always load RISC code on non ISP2[12]00 chips. */ |
| 3756 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) |
| 3757 | ha->flags.disable_risc_code_load = 0; |
| 3758 | ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0); |
| 3759 | ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0); |
| 3760 | 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] | 3761 | 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] | 3762 | ha->flags.disable_serdes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3763 | |
| 3764 | ha->operating_mode = |
| 3765 | (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 3766 | |
| 3767 | memcpy(ha->fw_seriallink_options, nv->seriallink_options, |
| 3768 | sizeof(ha->fw_seriallink_options)); |
| 3769 | |
| 3770 | /* save HBA serial number */ |
| 3771 | ha->serial0 = icb->port_name[5]; |
| 3772 | ha->serial1 = icb->port_name[6]; |
| 3773 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3774 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 3775 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3776 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3777 | icb->execution_throttle = cpu_to_le16(0xFFFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3778 | |
| 3779 | ha->retry_count = nv->retry_count; |
| 3780 | |
| 3781 | /* Set minimum login_timeout to 4 seconds. */ |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 3782 | if (nv->login_timeout != ql2xlogintimeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3783 | nv->login_timeout = ql2xlogintimeout; |
| 3784 | if (nv->login_timeout < 4) |
| 3785 | nv->login_timeout = 4; |
| 3786 | ha->login_timeout = nv->login_timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3787 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 3788 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 3789 | ha->r_a_tov = 100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3790 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3791 | ha->loop_reset_delay = nv->reset_delay; |
| 3792 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3793 | /* Link Down Timeout = 0: |
| 3794 | * |
| 3795 | * When Port Down timer expires we will start returning |
| 3796 | * I/O's to OS with "DID_NO_CONNECT". |
| 3797 | * |
| 3798 | * Link Down Timeout != 0: |
| 3799 | * |
| 3800 | * The driver waits for the link to come up after link down |
| 3801 | * before returning I/Os to OS with "DID_NO_CONNECT". |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3802 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3803 | if (nv->link_down_timeout == 0) { |
| 3804 | ha->loop_down_abort_time = |
Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 3805 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | } else { |
| 3807 | ha->link_down_timeout = nv->link_down_timeout; |
| 3808 | ha->loop_down_abort_time = |
| 3809 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3810 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3811 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3812 | /* |
| 3813 | * Need enough time to try and get the port back. |
| 3814 | */ |
| 3815 | ha->port_down_retry_count = nv->port_down_retry_count; |
| 3816 | if (qlport_down_retry) |
| 3817 | ha->port_down_retry_count = qlport_down_retry; |
| 3818 | /* Set login_retry_count */ |
| 3819 | ha->login_retry_count = nv->retry_count; |
| 3820 | if (ha->port_down_retry_count == nv->port_down_retry_count && |
| 3821 | ha->port_down_retry_count > 3) |
| 3822 | ha->login_retry_count = ha->port_down_retry_count; |
| 3823 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 3824 | ha->login_retry_count = ha->port_down_retry_count; |
| 3825 | if (ql2xloginretrycount) |
| 3826 | ha->login_retry_count = ql2xloginretrycount; |
| 3827 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3828 | icb->lun_enables = cpu_to_le16(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3829 | icb->command_resource_count = 0; |
| 3830 | icb->immediate_notify_resource_count = 0; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3831 | icb->timeout = cpu_to_le16(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3832 | |
| 3833 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 3834 | /* Enable RIO */ |
| 3835 | icb->firmware_options[0] &= ~BIT_3; |
| 3836 | icb->add_firmware_options[0] &= |
| 3837 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 3838 | icb->add_firmware_options[0] |= BIT_2; |
| 3839 | icb->response_accumulation_timer = 3; |
| 3840 | icb->interrupt_delay_timer = 5; |
| 3841 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3842 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3843 | } else { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 3844 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3845 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 3846 | ha->zio_mode = icb->add_firmware_options[0] & |
| 3847 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 3848 | ha->zio_timer = icb->interrupt_delay_timer ? |
| 3849 | icb->interrupt_delay_timer: 2; |
| 3850 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3851 | icb->add_firmware_options[0] &= |
| 3852 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3853 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 3854 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 3855 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 3856 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3857 | ql_log(ql_log_info, vha, 0x0068, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 3858 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 3859 | ha->zio_mode, ha->zio_timer * 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3860 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 3861 | icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode; |
| 3862 | icb->interrupt_delay_timer = (uint8_t)ha->zio_timer; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3863 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3864 | } |
| 3865 | } |
| 3866 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3867 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3868 | ql_log(ql_log_warn, vha, 0x0069, |
| 3869 | "NVRAM configuration failed.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3870 | } |
| 3871 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3872 | } |
| 3873 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3874 | static void |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3875 | qla2x00_rport_del(void *data) |
| 3876 | { |
| 3877 | fc_port_t *fcport = data; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3878 | struct fc_rport *rport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 3879 | unsigned long flags; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3880 | |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 3881 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3882 | rport = fcport->drport ? fcport->drport: fcport->rport; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3883 | fcport->drport = NULL; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 3884 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3885 | if (rport) { |
| 3886 | ql_dbg(ql_dbg_disc, fcport->vha, 0xffff, |
| 3887 | "%s %8phN. rport %p roles %x \n", |
| 3888 | __func__, fcport->port_name, rport, |
| 3889 | rport->roles); |
| 3890 | |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3891 | fc_remote_port_delete(rport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3892 | } |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3893 | } |
| 3894 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3895 | /** |
| 3896 | * qla2x00_alloc_fcport() - Allocate a generic fcport. |
| 3897 | * @ha: HA context |
| 3898 | * @flags: allocation flags |
| 3899 | * |
| 3900 | * Returns a pointer to the allocated fcport, or NULL, if none available. |
| 3901 | */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 3902 | fc_port_t * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3903 | qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3904 | { |
| 3905 | fc_port_t *fcport; |
| 3906 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 3907 | fcport = kzalloc(sizeof(fc_port_t), flags); |
| 3908 | if (!fcport) |
| 3909 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3910 | |
| 3911 | /* Setup fcport template structure. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3912 | fcport->vha = vha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3913 | fcport->port_type = FCT_UNKNOWN; |
| 3914 | fcport->loop_id = FC_NO_LOOP_ID; |
Chad Dupuis | ec426e1 | 2011-03-30 11:46:32 -0700 | [diff] [blame] | 3915 | qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED); |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 3916 | fcport->supported_classes = FC_COS_UNSPECIFIED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3917 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3918 | fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev, |
| 3919 | sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma, |
Quinn Tran | 6cb3216 | 2017-02-13 12:18:29 -0800 | [diff] [blame] | 3920 | flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3921 | fcport->disc_state = DSC_DELETED; |
| 3922 | fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 3923 | fcport->deleted = QLA_SESS_DELETED; |
| 3924 | fcport->login_retry = vha->hw->login_retry_count; |
| 3925 | fcport->login_retry = 5; |
| 3926 | fcport->logout_on_delete = 1; |
| 3927 | |
| 3928 | if (!fcport->ct_desc.ct_sns) { |
| 3929 | ql_log(ql_log_warn, vha, 0xffff, |
| 3930 | "Failed to allocate ct_sns request.\n"); |
| 3931 | kfree(fcport); |
| 3932 | fcport = NULL; |
| 3933 | } |
| 3934 | INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn); |
| 3935 | INIT_LIST_HEAD(&fcport->gnl_entry); |
| 3936 | INIT_LIST_HEAD(&fcport->list); |
| 3937 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 3938 | return fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3939 | } |
| 3940 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3941 | void |
| 3942 | qla2x00_free_fcport(fc_port_t *fcport) |
| 3943 | { |
| 3944 | if (fcport->ct_desc.ct_sns) { |
| 3945 | dma_free_coherent(&fcport->vha->hw->pdev->dev, |
| 3946 | sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns, |
| 3947 | fcport->ct_desc.ct_sns_dma); |
| 3948 | |
| 3949 | fcport->ct_desc.ct_sns = NULL; |
| 3950 | } |
| 3951 | kfree(fcport); |
| 3952 | } |
| 3953 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3954 | /* |
| 3955 | * qla2x00_configure_loop |
| 3956 | * Updates Fibre Channel Device Database with what is actually on loop. |
| 3957 | * |
| 3958 | * Input: |
| 3959 | * ha = adapter block pointer. |
| 3960 | * |
| 3961 | * Returns: |
| 3962 | * 0 = success. |
| 3963 | * 1 = error. |
| 3964 | * 2 = database was full and device was not configured. |
| 3965 | */ |
| 3966 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3967 | qla2x00_configure_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3968 | { |
| 3969 | int rval; |
| 3970 | unsigned long flags, save_flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3971 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3972 | rval = QLA_SUCCESS; |
| 3973 | |
| 3974 | /* Get Initiator ID */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3975 | if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) { |
| 3976 | rval = qla2x00_configure_hba(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3977 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3978 | ql_dbg(ql_dbg_disc, vha, 0x2013, |
| 3979 | "Unable to configure HBA.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3980 | return (rval); |
| 3981 | } |
| 3982 | } |
| 3983 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3984 | save_flags = flags = vha->dpc_flags; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3985 | ql_dbg(ql_dbg_disc, vha, 0x2014, |
| 3986 | "Configure loop -- dpc flags = 0x%lx.\n", flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3987 | |
| 3988 | /* |
| 3989 | * If we have both an RSCN and PORT UPDATE pending then handle them |
| 3990 | * both at the same time. |
| 3991 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3992 | clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 3993 | clear_bit(RSCN_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3994 | |
Michael Hernandez | 3064ff3 | 2009-12-15 21:29:44 -0800 | [diff] [blame] | 3995 | qla2x00_get_data_rate(vha); |
| 3996 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3997 | /* Determine what we need to do */ |
| 3998 | if (ha->current_topology == ISP_CFG_FL && |
| 3999 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 4000 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4001 | set_bit(RSCN_UPDATE, &flags); |
| 4002 | |
| 4003 | } else if (ha->current_topology == ISP_CFG_F && |
| 4004 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 4005 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4006 | set_bit(RSCN_UPDATE, &flags); |
| 4007 | clear_bit(LOCAL_LOOP_UPDATE, &flags); |
| 4008 | |
Andrew Vasquez | 21333b4 | 2006-05-17 15:09:56 -0700 | [diff] [blame] | 4009 | } else if (ha->current_topology == ISP_CFG_N) { |
| 4010 | clear_bit(RSCN_UPDATE, &flags); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4011 | } else if (ha->current_topology == ISP_CFG_NL) { |
| 4012 | clear_bit(RSCN_UPDATE, &flags); |
| 4013 | set_bit(LOCAL_LOOP_UPDATE, &flags); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4014 | } else if (!vha->flags.online || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4015 | (test_bit(ABORT_ISP_ACTIVE, &flags))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4016 | set_bit(RSCN_UPDATE, &flags); |
| 4017 | set_bit(LOCAL_LOOP_UPDATE, &flags); |
| 4018 | } |
| 4019 | |
| 4020 | if (test_bit(LOCAL_LOOP_UPDATE, &flags)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4021 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
| 4022 | ql_dbg(ql_dbg_disc, vha, 0x2015, |
| 4023 | "Loop resync needed, failing.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4024 | rval = QLA_FUNCTION_FAILED; |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4025 | } else |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4026 | rval = qla2x00_configure_local_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4027 | } |
| 4028 | |
| 4029 | if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4030 | if (LOOP_TRANSITION(vha)) { |
| 4031 | ql_dbg(ql_dbg_disc, vha, 0x201e, |
| 4032 | "Needs RSCN update and loop transition.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4033 | rval = QLA_FUNCTION_FAILED; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4034 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4035 | else |
| 4036 | rval = qla2x00_configure_fabric(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4037 | } |
| 4038 | |
| 4039 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4040 | if (atomic_read(&vha->loop_down_timer) || |
| 4041 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4042 | rval = QLA_FUNCTION_FAILED; |
| 4043 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4044 | atomic_set(&vha->loop_state, LOOP_READY); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4045 | ql_dbg(ql_dbg_disc, vha, 0x2069, |
| 4046 | "LOOP READY.\n"); |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 4047 | |
| 4048 | /* |
| 4049 | * Process any ATIO queue entries that came in |
| 4050 | * while we weren't online. |
| 4051 | */ |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 4052 | if (qla_tgt_mode_enabled(vha) || |
| 4053 | qla_dual_mode_enabled(vha)) { |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 4054 | if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) { |
| 4055 | spin_lock_irqsave(&ha->tgt.atio_lock, |
| 4056 | flags); |
| 4057 | qlt_24xx_process_atio_queue(vha, 0); |
| 4058 | spin_unlock_irqrestore( |
| 4059 | &ha->tgt.atio_lock, flags); |
| 4060 | } else { |
| 4061 | spin_lock_irqsave(&ha->hardware_lock, |
| 4062 | flags); |
| 4063 | qlt_24xx_process_atio_queue(vha, 1); |
| 4064 | spin_unlock_irqrestore( |
| 4065 | &ha->hardware_lock, flags); |
| 4066 | } |
| 4067 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4068 | } |
| 4069 | } |
| 4070 | |
| 4071 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4072 | ql_dbg(ql_dbg_disc, vha, 0x206a, |
| 4073 | "%s *** FAILED ***.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4074 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4075 | ql_dbg(ql_dbg_disc, vha, 0x206b, |
| 4076 | "%s: exiting normally.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4077 | } |
| 4078 | |
Bjorn Helgaas | cc3ef7b | 2008-09-11 21:22:51 -0700 | [diff] [blame] | 4079 | /* Restore state if a resync event occurred during processing */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4080 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4081 | if (test_bit(LOCAL_LOOP_UPDATE, &save_flags)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4082 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 4083 | if (test_bit(RSCN_UPDATE, &save_flags)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4084 | set_bit(RSCN_UPDATE, &vha->dpc_flags); |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 4085 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4086 | } |
| 4087 | |
| 4088 | return (rval); |
| 4089 | } |
| 4090 | |
| 4091 | |
| 4092 | |
| 4093 | /* |
| 4094 | * qla2x00_configure_local_loop |
| 4095 | * Updates Fibre Channel Device Database with local loop devices. |
| 4096 | * |
| 4097 | * Input: |
| 4098 | * ha = adapter block pointer. |
| 4099 | * |
| 4100 | * Returns: |
| 4101 | * 0 = success. |
| 4102 | */ |
| 4103 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4104 | qla2x00_configure_local_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4105 | { |
| 4106 | int rval, rval2; |
| 4107 | int found_devs; |
| 4108 | int found; |
| 4109 | fc_port_t *fcport, *new_fcport; |
| 4110 | |
| 4111 | uint16_t index; |
| 4112 | uint16_t entries; |
| 4113 | char *id_iter; |
| 4114 | uint16_t loop_id; |
| 4115 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4116 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4117 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4118 | |
| 4119 | found_devs = 0; |
| 4120 | new_fcport = NULL; |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4121 | entries = MAX_FIBRE_DEVICES_LOOP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4123 | /* Get list of logged in devices. */ |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4124 | memset(ha->gid_list, 0, qla2x00_gid_list_size(ha)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4125 | 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] | 4126 | &entries); |
| 4127 | if (rval != QLA_SUCCESS) |
| 4128 | goto cleanup_allocation; |
| 4129 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4130 | ql_dbg(ql_dbg_disc, vha, 0x2017, |
| 4131 | "Entries in ID list (%d).\n", entries); |
| 4132 | ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075, |
| 4133 | (uint8_t *)ha->gid_list, |
| 4134 | entries * sizeof(struct gid_list_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4135 | |
| 4136 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4137 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4138 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4139 | ql_log(ql_log_warn, vha, 0x2018, |
| 4140 | "Memory allocation failed for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4141 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 4142 | goto cleanup_allocation; |
| 4143 | } |
| 4144 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 4145 | |
| 4146 | /* |
| 4147 | * Mark local devices that were present with FCF_DEVICE_LOST for now. |
| 4148 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4149 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4150 | if (atomic_read(&fcport->state) == FCS_ONLINE && |
| 4151 | fcport->port_type != FCT_BROADCAST && |
| 4152 | (fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 4153 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4154 | ql_dbg(ql_dbg_disc, vha, 0x2019, |
| 4155 | "Marking port lost loop_id=0x%04x.\n", |
| 4156 | fcport->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4157 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4158 | qla2x00_mark_device_lost(vha, fcport, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4159 | } |
| 4160 | } |
| 4161 | |
| 4162 | /* Add devices to port list. */ |
| 4163 | id_iter = (char *)ha->gid_list; |
| 4164 | for (index = 0; index < entries; index++) { |
| 4165 | domain = ((struct gid_list_info *)id_iter)->domain; |
| 4166 | area = ((struct gid_list_info *)id_iter)->area; |
| 4167 | al_pa = ((struct gid_list_info *)id_iter)->al_pa; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4168 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4169 | loop_id = (uint16_t) |
| 4170 | ((struct gid_list_info *)id_iter)->loop_id_2100; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4171 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4172 | loop_id = le16_to_cpu( |
| 4173 | ((struct gid_list_info *)id_iter)->loop_id); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4174 | id_iter += ha->gid_list_info_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4175 | |
| 4176 | /* Bypass reserved domain fields. */ |
| 4177 | if ((domain & 0xf0) == 0xf0) |
| 4178 | continue; |
| 4179 | |
| 4180 | /* Bypass if not same domain and area of adapter. */ |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 4181 | if (area && domain && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4182 | (area != vha->d_id.b.area || domain != vha->d_id.b.domain)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4183 | continue; |
| 4184 | |
| 4185 | /* Bypass invalid local loop ID. */ |
| 4186 | if (loop_id > LAST_LOCAL_LOOP_ID) |
| 4187 | continue; |
| 4188 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4189 | memset(new_fcport->port_name, 0, WWN_SIZE); |
Arun Easi | 370d550 | 2012-08-22 14:21:10 -0400 | [diff] [blame] | 4190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4191 | /* Fill in member data. */ |
| 4192 | new_fcport->d_id.b.domain = domain; |
| 4193 | new_fcport->d_id.b.area = area; |
| 4194 | new_fcport->d_id.b.al_pa = al_pa; |
| 4195 | new_fcport->loop_id = loop_id; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4196 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4197 | rval2 = qla2x00_get_port_database(vha, new_fcport, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4198 | if (rval2 != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4199 | ql_dbg(ql_dbg_disc, vha, 0x201a, |
| 4200 | "Failed to retrieve fcport information " |
| 4201 | "-- get_port_database=%x, loop_id=0x%04x.\n", |
| 4202 | rval2, new_fcport->loop_id); |
| 4203 | ql_dbg(ql_dbg_disc, vha, 0x201b, |
| 4204 | "Scheduling resync.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4205 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4206 | continue; |
| 4207 | } |
| 4208 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4209 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4210 | /* Check for matching device in port list. */ |
| 4211 | found = 0; |
| 4212 | fcport = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4213 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4214 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 4215 | WWN_SIZE)) |
| 4216 | continue; |
| 4217 | |
Shyam Sundar | ddb9b12 | 2009-03-24 09:08:10 -0700 | [diff] [blame] | 4218 | fcport->flags &= ~FCF_FABRIC_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4219 | fcport->loop_id = new_fcport->loop_id; |
| 4220 | fcport->port_type = new_fcport->port_type; |
| 4221 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 4222 | memcpy(fcport->node_name, new_fcport->node_name, |
| 4223 | WWN_SIZE); |
| 4224 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4225 | if (!fcport->login_succ) { |
| 4226 | vha->fcport_count++; |
| 4227 | fcport->login_succ = 1; |
| 4228 | fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 4229 | } |
| 4230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4231 | found++; |
| 4232 | break; |
| 4233 | } |
| 4234 | |
| 4235 | if (!found) { |
| 4236 | /* New device, add to fcports list. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4237 | list_add_tail(&new_fcport->list, &vha->vp_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4238 | |
| 4239 | /* Allocate a new replacement fcport. */ |
| 4240 | fcport = new_fcport; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4241 | if (!fcport->login_succ) { |
| 4242 | vha->fcport_count++; |
| 4243 | fcport->login_succ = 1; |
| 4244 | fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 4245 | } |
| 4246 | |
| 4247 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 4248 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4249 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4250 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4251 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4252 | ql_log(ql_log_warn, vha, 0x201c, |
| 4253 | "Failed to allocate memory for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4254 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 4255 | goto cleanup_allocation; |
| 4256 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4257 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4258 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 4259 | } |
| 4260 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4261 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 4262 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4263 | /* Base iIDMA settings on HBA port speed. */ |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 4264 | fcport->fp_speed = ha->link_data_rate; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4265 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4266 | qla2x00_update_fcport(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4267 | |
| 4268 | found_devs++; |
| 4269 | } |
| 4270 | |
| 4271 | cleanup_allocation: |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 4272 | kfree(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4273 | |
| 4274 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4275 | ql_dbg(ql_dbg_disc, vha, 0x201d, |
| 4276 | "Configure local loop error exit: rval=%x.\n", rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4277 | } |
| 4278 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4279 | return (rval); |
| 4280 | } |
| 4281 | |
| 4282 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4283 | qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4284 | { |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4285 | int rval; |
Quinn Tran | 93f2bd6 | 2014-09-25 05:16:53 -0400 | [diff] [blame] | 4286 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4287 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4288 | |
Andrew Vasquez | c76f2c0 | 2007-07-19 15:05:57 -0700 | [diff] [blame] | 4289 | if (!IS_IIDMA_CAPABLE(ha)) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4290 | return; |
| 4291 | |
Giridhar Malavali | c9afb9a | 2010-09-03 15:20:48 -0700 | [diff] [blame] | 4292 | if (atomic_read(&fcport->state) != FCS_ONLINE) |
| 4293 | return; |
| 4294 | |
Andrew Vasquez | 39bd962 | 2007-09-20 14:07:34 -0700 | [diff] [blame] | 4295 | if (fcport->fp_speed == PORT_SPEED_UNKNOWN || |
| 4296 | fcport->fp_speed > ha->link_data_rate) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4297 | return; |
| 4298 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4299 | rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed, |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 4300 | mb); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4301 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4302 | ql_dbg(ql_dbg_disc, vha, 0x2004, |
Oleksandr Khoshaba | 7b83355 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 4303 | "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n", |
| 4304 | fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4305 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4306 | ql_dbg(ql_dbg_disc, vha, 0x2005, |
Oleksandr Khoshaba | 7b83355 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 4307 | "iIDMA adjusted to %s GB/s on %8phN.\n", |
Joe Carnuccio | d0297c9 | 2012-11-21 02:40:40 -0500 | [diff] [blame] | 4308 | qla2x00_get_link_speed_str(ha, fcport->fp_speed), |
Oleksandr Khoshaba | 7b83355 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 4309 | fcport->port_name); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4310 | } |
| 4311 | } |
| 4312 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4313 | /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/ |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4314 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4315 | qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 4316 | { |
| 4317 | struct fc_rport_identifiers rport_ids; |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 4318 | struct fc_rport *rport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 4319 | unsigned long flags; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 4320 | |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 4321 | rport_ids.node_name = wwn_to_u64(fcport->node_name); |
| 4322 | rport_ids.port_name = wwn_to_u64(fcport->port_name); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 4323 | rport_ids.port_id = fcport->d_id.b.domain << 16 | |
| 4324 | fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa; |
| 4325 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4326 | fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 4327 | if (!rport) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4328 | ql_log(ql_log_warn, vha, 0x2006, |
| 4329 | "Unable to allocate fc remote port.\n"); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 4330 | return; |
| 4331 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4332 | |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 4333 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4334 | *((fc_port_t **)rport->dd_data) = fcport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 4335 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 4336 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 4337 | rport->supported_classes = fcport->supported_classes; |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 4338 | |
| 4339 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 4340 | if (fcport->port_type == FCT_INITIATOR) |
| 4341 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 4342 | if (fcport->port_type == FCT_TARGET) |
| 4343 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4344 | |
| 4345 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4346 | "%s %8phN. rport %p is %s mode \n", |
| 4347 | __func__, fcport->port_name, rport, |
| 4348 | (fcport->port_type == FCT_TARGET) ? "tgt" : "ini"); |
| 4349 | |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 4350 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 4351 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4352 | |
| 4353 | /* |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4354 | * qla2x00_update_fcport |
| 4355 | * Updates device on list. |
| 4356 | * |
| 4357 | * Input: |
| 4358 | * ha = adapter block pointer. |
| 4359 | * fcport = port structure pointer. |
| 4360 | * |
| 4361 | * Return: |
| 4362 | * 0 - Success |
| 4363 | * BIT_0 - error |
| 4364 | * |
| 4365 | * Context: |
| 4366 | * Kernel context. |
| 4367 | */ |
| 4368 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4369 | qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4370 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4371 | fcport->vha = vha; |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 4372 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4373 | if (IS_SW_RESV_ADDR(fcport->d_id)) |
| 4374 | return; |
| 4375 | |
| 4376 | ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %8phC \n", |
| 4377 | __func__, fcport->port_name); |
| 4378 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 4379 | if (IS_QLAFX00(vha->hw)) { |
| 4380 | qla2x00_set_fcport_state(fcport, FCS_ONLINE); |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 4381 | goto reg_port; |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 4382 | } |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4383 | fcport->login_retry = 0; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 4384 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4385 | fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 4386 | fcport->deleted = 0; |
| 4387 | fcport->logout_on_delete = 1; |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4388 | |
Joe Carnuccio | 1f93da52 | 2012-11-21 02:40:38 -0500 | [diff] [blame] | 4389 | qla2x00_set_fcport_state(fcport, FCS_ONLINE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4390 | qla2x00_iidma_fcport(vha, fcport); |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 4391 | qla24xx_update_fcport_fcp_prio(vha, fcport); |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 4392 | |
| 4393 | reg_port: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4394 | switch (vha->host->active_mode) { |
| 4395 | case MODE_INITIATOR: |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 4396 | qla2x00_reg_remote_port(vha, fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4397 | break; |
| 4398 | case MODE_TARGET: |
| 4399 | if (!vha->vha_tgt.qla_tgt->tgt_stop && |
| 4400 | !vha->vha_tgt.qla_tgt->tgt_stopped) |
| 4401 | qlt_fc_port_added(vha, fcport); |
| 4402 | break; |
| 4403 | case MODE_DUAL: |
| 4404 | qla2x00_reg_remote_port(vha, fcport); |
| 4405 | if (!vha->vha_tgt.qla_tgt->tgt_stop && |
| 4406 | !vha->vha_tgt.qla_tgt->tgt_stopped) |
| 4407 | qlt_fc_port_added(vha, fcport); |
| 4408 | break; |
| 4409 | default: |
| 4410 | break; |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 4411 | } |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4412 | } |
| 4413 | |
| 4414 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4415 | * qla2x00_configure_fabric |
| 4416 | * Setup SNS devices with loop ID's. |
| 4417 | * |
| 4418 | * Input: |
| 4419 | * ha = adapter block pointer. |
| 4420 | * |
| 4421 | * Returns: |
| 4422 | * 0 = success. |
| 4423 | * BIT_0 = error |
| 4424 | */ |
| 4425 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4426 | qla2x00_configure_fabric(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4427 | { |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 4428 | int rval; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4429 | fc_port_t *fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4430 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4431 | uint16_t loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4432 | LIST_HEAD(new_fcports); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4433 | struct qla_hw_data *ha = vha->hw; |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4434 | int discovery_gen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4435 | |
| 4436 | /* If FL port exists, then SNS is present */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 4437 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4438 | loop_id = NPH_F_PORT; |
| 4439 | else |
| 4440 | loop_id = SNS_FL_PORT; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4441 | 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] | 4442 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4443 | ql_dbg(ql_dbg_disc, vha, 0x201f, |
| 4444 | "MBX_GET_PORT_NAME failed, No FL Port.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4445 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4446 | vha->device_flags &= ~SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4447 | return (QLA_SUCCESS); |
| 4448 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4449 | vha->device_flags |= SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4450 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4451 | |
| 4452 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { |
| 4453 | rval = qla2x00_send_change_request(vha, 0x3, 0); |
| 4454 | if (rval != QLA_SUCCESS) |
| 4455 | ql_log(ql_log_warn, vha, 0x121, |
| 4456 | "Failed to enable receiving of RSCN requests: 0x%x.\n", |
| 4457 | rval); |
| 4458 | } |
| 4459 | |
| 4460 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4461 | do { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4462 | qla2x00_mgmt_svr_login(vha); |
| 4463 | |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 4464 | /* FDMI support. */ |
| 4465 | if (ql2xfdmienable && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4466 | test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags)) |
| 4467 | qla2x00_fdmi_register(vha); |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 4468 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4469 | /* Ensure we are logged into the SNS. */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 4470 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4471 | loop_id = NPH_SNS; |
| 4472 | else |
| 4473 | loop_id = SIMPLE_NAME_SERVER; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 4474 | rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff, |
| 4475 | 0xfc, mb, BIT_1|BIT_0); |
| 4476 | if (rval != QLA_SUCCESS) { |
| 4477 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Joe Carnuccio | e452ceb | 2013-02-08 01:57:56 -0500 | [diff] [blame] | 4478 | return rval; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 4479 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4480 | if (mb[0] != MBS_COMMAND_COMPLETE) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4481 | ql_dbg(ql_dbg_disc, vha, 0x2042, |
| 4482 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x " |
| 4483 | "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1], |
| 4484 | mb[2], mb[6], mb[7]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4485 | return (QLA_SUCCESS); |
| 4486 | } |
| 4487 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4488 | if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) { |
| 4489 | if (qla2x00_rft_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4490 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4491 | ql_dbg(ql_dbg_disc, vha, 0x2045, |
| 4492 | "Register FC-4 TYPE failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4493 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4494 | if (qla2x00_rff_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4495 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4496 | ql_dbg(ql_dbg_disc, vha, 0x2049, |
| 4497 | "Register FC-4 Features failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4498 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4499 | if (qla2x00_rnn_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4500 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4501 | ql_dbg(ql_dbg_disc, vha, 0x204f, |
| 4502 | "Register Node Name failed.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4503 | } else if (qla2x00_rsnn_nn(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4504 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4505 | ql_dbg(ql_dbg_disc, vha, 0x2053, |
| 4506 | "Register Symobilic Node Name failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4507 | } |
| 4508 | } |
| 4509 | |
Joe Carnuccio | 827210b | 2013-02-08 01:57:57 -0500 | [diff] [blame] | 4510 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 4511 | fcport->scan_state = QLA_FCPORT_SCAN; |
| 4512 | } |
| 4513 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4514 | /* Mark the time right before querying FW for connected ports. |
| 4515 | * This process is long, asynchronous and by the time it's done, |
| 4516 | * collected information might not be accurate anymore. E.g. |
| 4517 | * disconnected port might have re-connected and a brand new |
| 4518 | * session has been created. In this case session's generation |
| 4519 | * will be newer than discovery_gen. */ |
| 4520 | qlt_do_generation_tick(vha, &discovery_gen); |
| 4521 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4522 | rval = qla2x00_find_all_fabric_devs(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4523 | if (rval != QLA_SUCCESS) |
| 4524 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4525 | } while (0); |
| 4526 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4527 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4528 | ql_dbg(ql_dbg_disc, vha, 0x2068, |
| 4529 | "Configure fabric error exit rval=%d.\n", rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4530 | |
| 4531 | return (rval); |
| 4532 | } |
| 4533 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4534 | /* |
| 4535 | * qla2x00_find_all_fabric_devs |
| 4536 | * |
| 4537 | * Input: |
| 4538 | * ha = adapter block pointer. |
| 4539 | * dev = database device entry pointer. |
| 4540 | * |
| 4541 | * Returns: |
| 4542 | * 0 = success. |
| 4543 | * |
| 4544 | * Context: |
| 4545 | * Kernel context. |
| 4546 | */ |
| 4547 | static int |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4548 | qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4549 | { |
| 4550 | int rval; |
| 4551 | uint16_t loop_id; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4552 | fc_port_t *fcport, *new_fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4553 | int found; |
| 4554 | |
| 4555 | sw_info_t *swl; |
| 4556 | int swl_idx; |
| 4557 | int first_dev, last_dev; |
Mike Waychison | 1516ef4 | 2010-05-04 15:01:31 -0700 | [diff] [blame] | 4558 | port_id_t wrap = {}, nxt_d_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4559 | struct qla_hw_data *ha = vha->hw; |
Chad Dupuis | bb4cf5b | 2013-02-08 01:58:01 -0500 | [diff] [blame] | 4560 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4561 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4562 | |
| 4563 | rval = QLA_SUCCESS; |
| 4564 | |
| 4565 | /* Try GID_PT to get device list, else GAN. */ |
Andrew Vasquez | 7a67735 | 2012-02-09 11:15:56 -0800 | [diff] [blame] | 4566 | if (!ha->swl) |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4567 | ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t), |
Andrew Vasquez | 7a67735 | 2012-02-09 11:15:56 -0800 | [diff] [blame] | 4568 | GFP_KERNEL); |
| 4569 | swl = ha->swl; |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 4570 | if (!swl) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4571 | /*EMPTY*/ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4572 | ql_dbg(ql_dbg_disc, vha, 0x2054, |
| 4573 | "GID_PT allocations failed, fallback on GA_NXT.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4574 | } else { |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4575 | memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4576 | if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4577 | swl = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4578 | } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4579 | swl = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4580 | } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4581 | swl = NULL; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4582 | } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) { |
| 4583 | swl = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4584 | } |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 4585 | |
| 4586 | /* If other queries succeeded probe for FC-4 type */ |
| 4587 | if (swl) |
| 4588 | qla2x00_gff_id(vha, swl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4589 | } |
| 4590 | swl_idx = 0; |
| 4591 | |
| 4592 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4593 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4594 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4595 | ql_log(ql_log_warn, vha, 0x205e, |
| 4596 | "Failed to allocate memory for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4597 | return (QLA_MEMORY_ALLOC_FAILED); |
| 4598 | } |
| 4599 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4600 | /* Set start port ID scan at adapter ID. */ |
| 4601 | first_dev = 1; |
| 4602 | last_dev = 0; |
| 4603 | |
| 4604 | /* Starting free loop ID. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4605 | loop_id = ha->min_external_loopid; |
| 4606 | for (; loop_id <= ha->max_loop_id; loop_id++) { |
| 4607 | if (qla2x00_is_reserved_id(vha, loop_id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4608 | continue; |
| 4609 | |
Giridhar Malavali | 3a6478d | 2010-05-28 15:08:20 -0700 | [diff] [blame] | 4610 | if (ha->current_topology == ISP_CFG_FL && |
| 4611 | (atomic_read(&vha->loop_down_timer) || |
| 4612 | LOOP_TRANSITION(vha))) { |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 4613 | atomic_set(&vha->loop_down_timer, 0); |
| 4614 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 4615 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4616 | break; |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 4617 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4618 | |
| 4619 | if (swl != NULL) { |
| 4620 | if (last_dev) { |
| 4621 | wrap.b24 = new_fcport->d_id.b24; |
| 4622 | } else { |
| 4623 | new_fcport->d_id.b24 = swl[swl_idx].d_id.b24; |
| 4624 | memcpy(new_fcport->node_name, |
| 4625 | swl[swl_idx].node_name, WWN_SIZE); |
| 4626 | memcpy(new_fcport->port_name, |
| 4627 | swl[swl_idx].port_name, WWN_SIZE); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4628 | memcpy(new_fcport->fabric_port_name, |
| 4629 | swl[swl_idx].fabric_port_name, WWN_SIZE); |
| 4630 | new_fcport->fp_speed = swl[swl_idx].fp_speed; |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 4631 | new_fcport->fc4_type = swl[swl_idx].fc4_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4632 | |
| 4633 | if (swl[swl_idx].d_id.b.rsvd_1 != 0) { |
| 4634 | last_dev = 1; |
| 4635 | } |
| 4636 | swl_idx++; |
| 4637 | } |
| 4638 | } else { |
| 4639 | /* Send GA_NXT to the switch */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4640 | rval = qla2x00_ga_nxt(vha, new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4641 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4642 | ql_log(ql_log_warn, vha, 0x2064, |
| 4643 | "SNS scan failed -- assuming " |
| 4644 | "zero-entry result.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4645 | rval = QLA_SUCCESS; |
| 4646 | break; |
| 4647 | } |
| 4648 | } |
| 4649 | |
| 4650 | /* If wrap on switch device list, exit. */ |
| 4651 | if (first_dev) { |
| 4652 | wrap.b24 = new_fcport->d_id.b24; |
| 4653 | first_dev = 0; |
| 4654 | } else if (new_fcport->d_id.b24 == wrap.b24) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4655 | ql_dbg(ql_dbg_disc, vha, 0x2065, |
| 4656 | "Device wrap (%02x%02x%02x).\n", |
| 4657 | new_fcport->d_id.b.domain, |
| 4658 | new_fcport->d_id.b.area, |
| 4659 | new_fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4660 | break; |
| 4661 | } |
| 4662 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4663 | /* Bypass if same physical adapter. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4664 | if (new_fcport->d_id.b24 == base_vha->d_id.b24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4665 | continue; |
| 4666 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4667 | /* Bypass virtual ports of the same host. */ |
Chad Dupuis | bb4cf5b | 2013-02-08 01:58:01 -0500 | [diff] [blame] | 4668 | if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24)) |
| 4669 | continue; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4670 | |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 4671 | /* Bypass if same domain and area of adapter. */ |
| 4672 | if (((new_fcport->d_id.b24 & 0xffff00) == |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4673 | (vha->d_id.b24 & 0xffff00)) && ha->current_topology == |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 4674 | ISP_CFG_FL) |
| 4675 | continue; |
| 4676 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4677 | /* Bypass reserved domain fields. */ |
| 4678 | if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0) |
| 4679 | continue; |
| 4680 | |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 4681 | /* Bypass ports whose FCP-4 type is not FCP_SCSI */ |
Chad Dupuis | 4da26e1 | 2010-10-15 11:27:40 -0700 | [diff] [blame] | 4682 | if (ql2xgffidenable && |
| 4683 | (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI && |
| 4684 | new_fcport->fc4_type != FC4_TYPE_UNKNOWN)) |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 4685 | continue; |
| 4686 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4687 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 4688 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4689 | /* Locate matching device in database. */ |
| 4690 | found = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4691 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4692 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 4693 | WWN_SIZE)) |
| 4694 | continue; |
| 4695 | |
Joe Carnuccio | 827210b | 2013-02-08 01:57:57 -0500 | [diff] [blame] | 4696 | fcport->scan_state = QLA_FCPORT_FOUND; |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 4697 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4698 | found++; |
| 4699 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4700 | /* Update port state. */ |
| 4701 | memcpy(fcport->fabric_port_name, |
| 4702 | new_fcport->fabric_port_name, WWN_SIZE); |
| 4703 | fcport->fp_speed = new_fcport->fp_speed; |
| 4704 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4705 | /* |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 4706 | * If address the same and state FCS_ONLINE |
| 4707 | * (or in target mode), nothing changed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4708 | */ |
| 4709 | if (fcport->d_id.b24 == new_fcport->d_id.b24 && |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 4710 | (atomic_read(&fcport->state) == FCS_ONLINE || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4711 | (vha->host->active_mode == MODE_TARGET))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4712 | break; |
| 4713 | } |
| 4714 | |
| 4715 | /* |
| 4716 | * If device was not a fabric device before. |
| 4717 | */ |
| 4718 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 4719 | fcport->d_id.b24 = new_fcport->d_id.b24; |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 4720 | qla2x00_clear_loop_id(fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4721 | fcport->flags |= (FCF_FABRIC_DEVICE | |
| 4722 | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4723 | break; |
| 4724 | } |
| 4725 | |
| 4726 | /* |
| 4727 | * Port ID changed or device was marked to be updated; |
| 4728 | * Log it out if still logged in and mark it for |
| 4729 | * relogin later. |
| 4730 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4731 | if (qla_tgt_mode_enabled(base_vha)) { |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 4732 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080, |
| 4733 | "port changed FC ID, %8phC" |
| 4734 | " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n", |
| 4735 | fcport->port_name, |
| 4736 | fcport->d_id.b.domain, |
| 4737 | fcport->d_id.b.area, |
| 4738 | fcport->d_id.b.al_pa, |
| 4739 | fcport->loop_id, |
| 4740 | new_fcport->d_id.b.domain, |
| 4741 | new_fcport->d_id.b.area, |
| 4742 | new_fcport->d_id.b.al_pa); |
| 4743 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 4744 | break; |
| 4745 | } |
| 4746 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4747 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 4748 | fcport->flags |= FCF_LOGIN_NEEDED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4749 | break; |
| 4750 | } |
| 4751 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4752 | if (found) { |
| 4753 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4754 | continue; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4755 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4756 | /* If device was not in our fcports list, then add it. */ |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 4757 | new_fcport->scan_state = QLA_FCPORT_FOUND; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4758 | list_add_tail(&new_fcport->list, &vha->vp_fcports); |
| 4759 | |
| 4760 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 4761 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4762 | |
| 4763 | /* Allocate a new replacement fcport. */ |
| 4764 | nxt_d_id.b24 = new_fcport->d_id.b24; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4765 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4766 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4767 | ql_log(ql_log_warn, vha, 0x2066, |
| 4768 | "Memory allocation failed for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4769 | return (QLA_MEMORY_ALLOC_FAILED); |
| 4770 | } |
| 4771 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
| 4772 | new_fcport->d_id.b24 = nxt_d_id.b24; |
| 4773 | } |
| 4774 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4775 | qla2x00_free_fcport(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4776 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4777 | /* |
| 4778 | * Logout all previous fabric dev marked lost, except FCP2 devices. |
| 4779 | */ |
| 4780 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 4781 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 4782 | break; |
| 4783 | |
| 4784 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 || |
| 4785 | (fcport->flags & FCF_LOGIN_NEEDED) == 0) |
| 4786 | continue; |
| 4787 | |
| 4788 | if (fcport->scan_state == QLA_FCPORT_SCAN) { |
| 4789 | if ((qla_dual_mode_enabled(vha) || |
| 4790 | qla_ini_mode_enabled(vha)) && |
| 4791 | atomic_read(&fcport->state) == FCS_ONLINE) { |
| 4792 | qla2x00_mark_device_lost(vha, fcport, |
| 4793 | ql2xplogiabsentdevice, 0); |
| 4794 | if (fcport->loop_id != FC_NO_LOOP_ID && |
| 4795 | (fcport->flags & FCF_FCP2_DEVICE) == 0 && |
| 4796 | fcport->port_type != FCT_INITIATOR && |
| 4797 | fcport->port_type != FCT_BROADCAST) { |
| 4798 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4799 | "%s %d %8phC post del sess\n", |
| 4800 | __func__, __LINE__, |
| 4801 | fcport->port_name); |
| 4802 | |
| 4803 | qlt_schedule_sess_for_deletion_lock |
| 4804 | (fcport); |
| 4805 | continue; |
| 4806 | } |
| 4807 | } |
| 4808 | } |
| 4809 | |
| 4810 | if (fcport->scan_state == QLA_FCPORT_FOUND) |
| 4811 | qla24xx_fcport_handle_login(vha, fcport); |
| 4812 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4813 | return (rval); |
| 4814 | } |
| 4815 | |
| 4816 | /* |
| 4817 | * qla2x00_find_new_loop_id |
| 4818 | * Scan through our port list and find a new usable loop ID. |
| 4819 | * |
| 4820 | * Input: |
| 4821 | * ha: adapter state pointer. |
| 4822 | * dev: port structure pointer. |
| 4823 | * |
| 4824 | * Returns: |
| 4825 | * qla2x00 local function return status code. |
| 4826 | * |
| 4827 | * Context: |
| 4828 | * Kernel context. |
| 4829 | */ |
Joe Carnuccio | 03bcfb5 | 2011-03-30 11:46:27 -0700 | [diff] [blame] | 4830 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4831 | 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] | 4832 | { |
| 4833 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4834 | struct qla_hw_data *ha = vha->hw; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4835 | unsigned long flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4836 | |
| 4837 | rval = QLA_SUCCESS; |
| 4838 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 4839 | spin_lock_irqsave(&ha->vport_slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4840 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 4841 | dev->loop_id = find_first_zero_bit(ha->loop_id_map, |
| 4842 | LOOPID_MAP_SIZE); |
| 4843 | if (dev->loop_id >= LOOPID_MAP_SIZE || |
| 4844 | qla2x00_is_reserved_id(vha, dev->loop_id)) { |
| 4845 | dev->loop_id = FC_NO_LOOP_ID; |
| 4846 | rval = QLA_FUNCTION_FAILED; |
| 4847 | } else |
| 4848 | set_bit(dev->loop_id, ha->loop_id_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4849 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 4850 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4851 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 4852 | if (rval == QLA_SUCCESS) |
| 4853 | ql_dbg(ql_dbg_disc, dev->vha, 0x2086, |
| 4854 | "Assigning new loopid=%x, portid=%x.\n", |
| 4855 | dev->loop_id, dev->d_id.b24); |
| 4856 | else |
| 4857 | ql_log(ql_log_warn, dev->vha, 0x2087, |
| 4858 | "No loop_id's available, portid=%x.\n", |
| 4859 | dev->d_id.b24); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4860 | |
| 4861 | return (rval); |
| 4862 | } |
| 4863 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4864 | |
| 4865 | /* |
| 4866 | * qla2x00_fabric_login |
| 4867 | * Issue fabric login command. |
| 4868 | * |
| 4869 | * Input: |
| 4870 | * ha = adapter block pointer. |
| 4871 | * device = pointer to FC device type structure. |
| 4872 | * |
| 4873 | * Returns: |
| 4874 | * 0 - Login successfully |
| 4875 | * 1 - Login failed |
| 4876 | * 2 - Initiator device |
| 4877 | * 3 - Fatal error |
| 4878 | */ |
| 4879 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4880 | qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4881 | uint16_t *next_loopid) |
| 4882 | { |
| 4883 | int rval; |
| 4884 | int retry; |
| 4885 | uint16_t tmp_loopid; |
| 4886 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4887 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4888 | |
| 4889 | retry = 0; |
| 4890 | tmp_loopid = 0; |
| 4891 | |
| 4892 | for (;;) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4893 | ql_dbg(ql_dbg_disc, vha, 0x2000, |
| 4894 | "Trying Fabric Login w/loop id 0x%04x for port " |
| 4895 | "%02x%02x%02x.\n", |
| 4896 | fcport->loop_id, fcport->d_id.b.domain, |
| 4897 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4898 | |
| 4899 | /* Login fcport on switch. */ |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 4900 | rval = ha->isp_ops->fabric_login(vha, fcport->loop_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4901 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 4902 | fcport->d_id.b.al_pa, mb, BIT_0); |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 4903 | if (rval != QLA_SUCCESS) { |
| 4904 | return rval; |
| 4905 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4906 | if (mb[0] == MBS_PORT_ID_USED) { |
| 4907 | /* |
| 4908 | * Device has another loop ID. The firmware team |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4909 | * recommends the driver perform an implicit login with |
| 4910 | * the specified ID again. The ID we just used is save |
| 4911 | * here so we return with an ID that can be tried by |
| 4912 | * the next login. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4913 | */ |
| 4914 | retry++; |
| 4915 | tmp_loopid = fcport->loop_id; |
| 4916 | fcport->loop_id = mb[1]; |
| 4917 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4918 | ql_dbg(ql_dbg_disc, vha, 0x2001, |
| 4919 | "Fabric Login: port in use - next loop " |
| 4920 | "id=0x%04x, port id= %02x%02x%02x.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4921 | fcport->loop_id, fcport->d_id.b.domain, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4922 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4923 | |
| 4924 | } else if (mb[0] == MBS_COMMAND_COMPLETE) { |
| 4925 | /* |
| 4926 | * Login succeeded. |
| 4927 | */ |
| 4928 | if (retry) { |
| 4929 | /* A retry occurred before. */ |
| 4930 | *next_loopid = tmp_loopid; |
| 4931 | } else { |
| 4932 | /* |
| 4933 | * No retry occurred before. Just increment the |
| 4934 | * ID value for next login. |
| 4935 | */ |
| 4936 | *next_loopid = (fcport->loop_id + 1); |
| 4937 | } |
| 4938 | |
| 4939 | if (mb[1] & BIT_0) { |
| 4940 | fcport->port_type = FCT_INITIATOR; |
| 4941 | } else { |
| 4942 | fcport->port_type = FCT_TARGET; |
| 4943 | if (mb[1] & BIT_1) { |
Santosh Vernekar | 8474f3a | 2009-08-25 11:36:16 -0700 | [diff] [blame] | 4944 | fcport->flags |= FCF_FCP2_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4945 | } |
| 4946 | } |
| 4947 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 4948 | if (mb[10] & BIT_0) |
| 4949 | fcport->supported_classes |= FC_COS_CLASS2; |
| 4950 | if (mb[10] & BIT_1) |
| 4951 | fcport->supported_classes |= FC_COS_CLASS3; |
| 4952 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4953 | if (IS_FWI2_CAPABLE(ha)) { |
| 4954 | if (mb[10] & BIT_7) |
| 4955 | fcport->flags |= |
| 4956 | FCF_CONF_COMP_SUPPORTED; |
| 4957 | } |
| 4958 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4959 | rval = QLA_SUCCESS; |
| 4960 | break; |
| 4961 | } else if (mb[0] == MBS_LOOP_ID_USED) { |
| 4962 | /* |
| 4963 | * Loop ID already used, try next loop ID. |
| 4964 | */ |
| 4965 | fcport->loop_id++; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4966 | rval = qla2x00_find_new_loop_id(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4967 | if (rval != QLA_SUCCESS) { |
| 4968 | /* Ran out of loop IDs to use */ |
| 4969 | break; |
| 4970 | } |
| 4971 | } else if (mb[0] == MBS_COMMAND_ERROR) { |
| 4972 | /* |
| 4973 | * Firmware possibly timed out during login. If NO |
| 4974 | * retries are left to do then the device is declared |
| 4975 | * dead. |
| 4976 | */ |
| 4977 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4978 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 4979 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 4980 | fcport->d_id.b.al_pa); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4981 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4982 | |
| 4983 | rval = 1; |
| 4984 | break; |
| 4985 | } else { |
| 4986 | /* |
| 4987 | * unrecoverable / not handled error |
| 4988 | */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4989 | ql_dbg(ql_dbg_disc, vha, 0x2002, |
| 4990 | "Failed=%x port_id=%02x%02x%02x loop_id=%x " |
| 4991 | "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain, |
| 4992 | fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 4993 | fcport->loop_id, jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4994 | |
| 4995 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4996 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 4997 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 4998 | fcport->d_id.b.al_pa); |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 4999 | qla2x00_clear_loop_id(fcport); |
Andrew Vasquez | 0eedfcf | 2005-10-27 11:09:38 -0700 | [diff] [blame] | 5000 | fcport->login_retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5001 | |
| 5002 | rval = 3; |
| 5003 | break; |
| 5004 | } |
| 5005 | } |
| 5006 | |
| 5007 | return (rval); |
| 5008 | } |
| 5009 | |
| 5010 | /* |
| 5011 | * qla2x00_local_device_login |
| 5012 | * Issue local device login command. |
| 5013 | * |
| 5014 | * Input: |
| 5015 | * ha = adapter block pointer. |
| 5016 | * loop_id = loop id of device to login to. |
| 5017 | * |
| 5018 | * Returns (Where's the #define!!!!): |
| 5019 | * 0 - Login successfully |
| 5020 | * 1 - Login failed |
| 5021 | * 3 - Fatal error |
| 5022 | */ |
| 5023 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5024 | 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] | 5025 | { |
| 5026 | int rval; |
| 5027 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
| 5028 | |
| 5029 | memset(mb, 0, sizeof(mb)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5030 | rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5031 | if (rval == QLA_SUCCESS) { |
| 5032 | /* Interrogate mailbox registers for any errors */ |
| 5033 | if (mb[0] == MBS_COMMAND_ERROR) |
| 5034 | rval = 1; |
| 5035 | else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR) |
| 5036 | /* device not in PCB table */ |
| 5037 | rval = 3; |
| 5038 | } |
| 5039 | |
| 5040 | return (rval); |
| 5041 | } |
| 5042 | |
| 5043 | /* |
| 5044 | * qla2x00_loop_resync |
| 5045 | * Resync with fibre channel devices. |
| 5046 | * |
| 5047 | * Input: |
| 5048 | * ha = adapter block pointer. |
| 5049 | * |
| 5050 | * Returns: |
| 5051 | * 0 = success |
| 5052 | */ |
| 5053 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5054 | qla2x00_loop_resync(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5055 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5056 | int rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5057 | uint32_t wait_time; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 5058 | struct req_que *req; |
| 5059 | struct rsp_que *rsp; |
| 5060 | |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 5061 | req = vha->req; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 5062 | rsp = req->rsp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5063 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5064 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 5065 | if (vha->flags.online) { |
| 5066 | if (!(rval = qla2x00_fw_ready(vha))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5067 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 5068 | wait_time = 256; |
| 5069 | do { |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 5070 | if (!IS_QLAFX00(vha->hw)) { |
| 5071 | /* |
| 5072 | * Issue a marker after FW becomes |
| 5073 | * ready. |
| 5074 | */ |
| 5075 | qla2x00_marker(vha, req, rsp, 0, 0, |
| 5076 | MK_SYNC_ALL); |
| 5077 | vha->marker_needed = 0; |
| 5078 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5079 | |
| 5080 | /* Remap devices on Loop. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5081 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5082 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 5083 | if (IS_QLAFX00(vha->hw)) |
| 5084 | qlafx00_configure_devices(vha); |
| 5085 | else |
| 5086 | qla2x00_configure_loop(vha); |
| 5087 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5088 | wait_time--; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5089 | } while (!atomic_read(&vha->loop_down_timer) && |
| 5090 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
| 5091 | && wait_time && (test_bit(LOOP_RESYNC_NEEDED, |
| 5092 | &vha->dpc_flags))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5093 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5094 | } |
| 5095 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5096 | if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5097 | return (QLA_FUNCTION_FAILED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5098 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5099 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5100 | ql_dbg(ql_dbg_disc, vha, 0x206c, |
| 5101 | "%s *** FAILED ***.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5102 | |
| 5103 | return (rval); |
| 5104 | } |
| 5105 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5106 | /* |
| 5107 | * qla2x00_perform_loop_resync |
| 5108 | * Description: This function will set the appropriate flags and call |
| 5109 | * qla2x00_loop_resync. If successful loop will be resynced |
| 5110 | * Arguments : scsi_qla_host_t pointer |
| 5111 | * returm : Success or Failure |
| 5112 | */ |
| 5113 | |
| 5114 | int qla2x00_perform_loop_resync(scsi_qla_host_t *ha) |
| 5115 | { |
| 5116 | int32_t rval = 0; |
| 5117 | |
| 5118 | if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) { |
| 5119 | /*Configure the flags so that resync happens properly*/ |
| 5120 | atomic_set(&ha->loop_down_timer, 0); |
| 5121 | if (!(ha->device_flags & DFLG_NO_CABLE)) { |
| 5122 | atomic_set(&ha->loop_state, LOOP_UP); |
| 5123 | set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); |
| 5124 | set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags); |
| 5125 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
| 5126 | |
| 5127 | rval = qla2x00_loop_resync(ha); |
| 5128 | } else |
| 5129 | atomic_set(&ha->loop_state, LOOP_DEAD); |
| 5130 | |
| 5131 | clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags); |
| 5132 | } |
| 5133 | |
| 5134 | return rval; |
| 5135 | } |
| 5136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5137 | void |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 5138 | qla2x00_update_fcports(scsi_qla_host_t *base_vha) |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5139 | { |
| 5140 | fc_port_t *fcport; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5141 | struct scsi_qla_host *vha; |
| 5142 | struct qla_hw_data *ha = base_vha->hw; |
| 5143 | unsigned long flags; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5144 | |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5145 | spin_lock_irqsave(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5146 | /* Go with deferred removal of rport references. */ |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5147 | list_for_each_entry(vha, &base_vha->hw->vp_list, list) { |
| 5148 | atomic_inc(&vha->vref_count); |
| 5149 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Dan Carpenter | 8ae598d | 2010-12-21 16:00:15 -0800 | [diff] [blame] | 5150 | if (fcport->drport && |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5151 | atomic_read(&fcport->state) != FCS_UNCONFIGURED) { |
| 5152 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 5153 | qla2x00_rport_del(fcport); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 5154 | |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5155 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5156 | } |
| 5157 | } |
| 5158 | atomic_dec(&vha->vref_count); |
Joe Carnuccio | c4a9b53 | 2017-03-15 09:48:43 -0700 | [diff] [blame] | 5159 | wake_up(&vha->vref_waitq); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5160 | } |
| 5161 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5162 | } |
| 5163 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5164 | /* Assumes idc_lock always held on entry */ |
| 5165 | void |
| 5166 | qla83xx_reset_ownership(scsi_qla_host_t *vha) |
| 5167 | { |
| 5168 | struct qla_hw_data *ha = vha->hw; |
| 5169 | uint32_t drv_presence, drv_presence_mask; |
| 5170 | uint32_t dev_part_info1, dev_part_info2, class_type; |
| 5171 | uint32_t class_type_mask = 0x3; |
| 5172 | uint16_t fcoe_other_function = 0xffff, i; |
| 5173 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 5174 | if (IS_QLA8044(ha)) { |
| 5175 | drv_presence = qla8044_rd_direct(vha, |
| 5176 | QLA8044_CRB_DRV_ACTIVE_INDEX); |
| 5177 | dev_part_info1 = qla8044_rd_direct(vha, |
| 5178 | QLA8044_CRB_DEV_PART_INFO_INDEX); |
| 5179 | dev_part_info2 = qla8044_rd_direct(vha, |
| 5180 | QLA8044_CRB_DEV_PART_INFO2); |
| 5181 | } else { |
| 5182 | qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); |
| 5183 | qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1); |
| 5184 | qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2); |
| 5185 | } |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5186 | for (i = 0; i < 8; i++) { |
| 5187 | class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask); |
| 5188 | if ((class_type == QLA83XX_CLASS_TYPE_FCOE) && |
| 5189 | (i != ha->portnum)) { |
| 5190 | fcoe_other_function = i; |
| 5191 | break; |
| 5192 | } |
| 5193 | } |
| 5194 | if (fcoe_other_function == 0xffff) { |
| 5195 | for (i = 0; i < 8; i++) { |
| 5196 | class_type = ((dev_part_info2 >> (i * 4)) & |
| 5197 | class_type_mask); |
| 5198 | if ((class_type == QLA83XX_CLASS_TYPE_FCOE) && |
| 5199 | ((i + 8) != ha->portnum)) { |
| 5200 | fcoe_other_function = i + 8; |
| 5201 | break; |
| 5202 | } |
| 5203 | } |
| 5204 | } |
| 5205 | /* |
| 5206 | * Prepare drv-presence mask based on fcoe functions present. |
| 5207 | * However consider only valid physical fcoe function numbers (0-15). |
| 5208 | */ |
| 5209 | drv_presence_mask = ~((1 << (ha->portnum)) | |
| 5210 | ((fcoe_other_function == 0xffff) ? |
| 5211 | 0 : (1 << (fcoe_other_function)))); |
| 5212 | |
| 5213 | /* We are the reset owner iff: |
| 5214 | * - No other protocol drivers present. |
| 5215 | * - This is the lowest among fcoe functions. */ |
| 5216 | if (!(drv_presence & drv_presence_mask) && |
| 5217 | (ha->portnum < fcoe_other_function)) { |
| 5218 | ql_dbg(ql_dbg_p3p, vha, 0xb07f, |
| 5219 | "This host is Reset owner.\n"); |
| 5220 | ha->flags.nic_core_reset_owner = 1; |
| 5221 | } |
| 5222 | } |
| 5223 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5224 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5225 | __qla83xx_set_drv_ack(scsi_qla_host_t *vha) |
| 5226 | { |
| 5227 | int rval = QLA_SUCCESS; |
| 5228 | struct qla_hw_data *ha = vha->hw; |
| 5229 | uint32_t drv_ack; |
| 5230 | |
| 5231 | rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack); |
| 5232 | if (rval == QLA_SUCCESS) { |
| 5233 | drv_ack |= (1 << ha->portnum); |
| 5234 | rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack); |
| 5235 | } |
| 5236 | |
| 5237 | return rval; |
| 5238 | } |
| 5239 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5240 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5241 | __qla83xx_clear_drv_ack(scsi_qla_host_t *vha) |
| 5242 | { |
| 5243 | int rval = QLA_SUCCESS; |
| 5244 | struct qla_hw_data *ha = vha->hw; |
| 5245 | uint32_t drv_ack; |
| 5246 | |
| 5247 | rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack); |
| 5248 | if (rval == QLA_SUCCESS) { |
| 5249 | drv_ack &= ~(1 << ha->portnum); |
| 5250 | rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack); |
| 5251 | } |
| 5252 | |
| 5253 | return rval; |
| 5254 | } |
| 5255 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5256 | static const char * |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5257 | qla83xx_dev_state_to_string(uint32_t dev_state) |
| 5258 | { |
| 5259 | switch (dev_state) { |
| 5260 | case QLA8XXX_DEV_COLD: |
| 5261 | return "COLD/RE-INIT"; |
| 5262 | case QLA8XXX_DEV_INITIALIZING: |
| 5263 | return "INITIALIZING"; |
| 5264 | case QLA8XXX_DEV_READY: |
| 5265 | return "READY"; |
| 5266 | case QLA8XXX_DEV_NEED_RESET: |
| 5267 | return "NEED RESET"; |
| 5268 | case QLA8XXX_DEV_NEED_QUIESCENT: |
| 5269 | return "NEED QUIESCENT"; |
| 5270 | case QLA8XXX_DEV_FAILED: |
| 5271 | return "FAILED"; |
| 5272 | case QLA8XXX_DEV_QUIESCENT: |
| 5273 | return "QUIESCENT"; |
| 5274 | default: |
| 5275 | return "Unknown"; |
| 5276 | } |
| 5277 | } |
| 5278 | |
| 5279 | /* Assumes idc-lock always held on entry */ |
| 5280 | void |
| 5281 | qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type) |
| 5282 | { |
| 5283 | struct qla_hw_data *ha = vha->hw; |
| 5284 | uint32_t idc_audit_reg = 0, duration_secs = 0; |
| 5285 | |
| 5286 | switch (audit_type) { |
| 5287 | case IDC_AUDIT_TIMESTAMP: |
| 5288 | ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000); |
| 5289 | idc_audit_reg = (ha->portnum) | |
| 5290 | (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8); |
| 5291 | qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg); |
| 5292 | break; |
| 5293 | |
| 5294 | case IDC_AUDIT_COMPLETION: |
| 5295 | duration_secs = ((jiffies_to_msecs(jiffies) - |
| 5296 | jiffies_to_msecs(ha->idc_audit_ts)) / 1000); |
| 5297 | idc_audit_reg = (ha->portnum) | |
| 5298 | (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8); |
| 5299 | qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg); |
| 5300 | break; |
| 5301 | |
| 5302 | default: |
| 5303 | ql_log(ql_log_warn, vha, 0xb078, |
| 5304 | "Invalid audit type specified.\n"); |
| 5305 | break; |
| 5306 | } |
| 5307 | } |
| 5308 | |
| 5309 | /* Assumes idc_lock always held on entry */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5310 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5311 | qla83xx_initiating_reset(scsi_qla_host_t *vha) |
| 5312 | { |
| 5313 | struct qla_hw_data *ha = vha->hw; |
| 5314 | uint32_t idc_control, dev_state; |
| 5315 | |
| 5316 | __qla83xx_get_idc_control(vha, &idc_control); |
| 5317 | if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) { |
| 5318 | ql_log(ql_log_info, vha, 0xb080, |
| 5319 | "NIC Core reset has been disabled. idc-control=0x%x\n", |
| 5320 | idc_control); |
| 5321 | return QLA_FUNCTION_FAILED; |
| 5322 | } |
| 5323 | |
| 5324 | /* Set NEED-RESET iff in READY state and we are the reset-owner */ |
| 5325 | qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state); |
| 5326 | if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) { |
| 5327 | qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, |
| 5328 | QLA8XXX_DEV_NEED_RESET); |
| 5329 | ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n"); |
| 5330 | qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP); |
| 5331 | } else { |
| 5332 | const char *state = qla83xx_dev_state_to_string(dev_state); |
| 5333 | ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state); |
| 5334 | |
| 5335 | /* SV: XXX: Is timeout required here? */ |
| 5336 | /* Wait for IDC state change READY -> NEED_RESET */ |
| 5337 | while (dev_state == QLA8XXX_DEV_READY) { |
| 5338 | qla83xx_idc_unlock(vha, 0); |
| 5339 | msleep(200); |
| 5340 | qla83xx_idc_lock(vha, 0); |
| 5341 | qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state); |
| 5342 | } |
| 5343 | } |
| 5344 | |
| 5345 | /* Send IDC ack by writing to drv-ack register */ |
| 5346 | __qla83xx_set_drv_ack(vha); |
| 5347 | |
| 5348 | return QLA_SUCCESS; |
| 5349 | } |
| 5350 | |
| 5351 | int |
| 5352 | __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control) |
| 5353 | { |
| 5354 | return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control); |
| 5355 | } |
| 5356 | |
| 5357 | int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5358 | __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control) |
| 5359 | { |
| 5360 | return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control); |
| 5361 | } |
| 5362 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5363 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5364 | qla83xx_check_driver_presence(scsi_qla_host_t *vha) |
| 5365 | { |
| 5366 | uint32_t drv_presence = 0; |
| 5367 | struct qla_hw_data *ha = vha->hw; |
| 5368 | |
| 5369 | qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); |
| 5370 | if (drv_presence & (1 << ha->portnum)) |
| 5371 | return QLA_SUCCESS; |
| 5372 | else |
| 5373 | return QLA_TEST_FAILED; |
| 5374 | } |
| 5375 | |
| 5376 | int |
| 5377 | qla83xx_nic_core_reset(scsi_qla_host_t *vha) |
| 5378 | { |
| 5379 | int rval = QLA_SUCCESS; |
| 5380 | struct qla_hw_data *ha = vha->hw; |
| 5381 | |
| 5382 | ql_dbg(ql_dbg_p3p, vha, 0xb058, |
| 5383 | "Entered %s().\n", __func__); |
| 5384 | |
| 5385 | if (vha->device_flags & DFLG_DEV_FAILED) { |
| 5386 | ql_log(ql_log_warn, vha, 0xb059, |
| 5387 | "Device in unrecoverable FAILED state.\n"); |
| 5388 | return QLA_FUNCTION_FAILED; |
| 5389 | } |
| 5390 | |
| 5391 | qla83xx_idc_lock(vha, 0); |
| 5392 | |
| 5393 | if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) { |
| 5394 | ql_log(ql_log_warn, vha, 0xb05a, |
| 5395 | "Function=0x%x has been removed from IDC participation.\n", |
| 5396 | ha->portnum); |
| 5397 | rval = QLA_FUNCTION_FAILED; |
| 5398 | goto exit; |
| 5399 | } |
| 5400 | |
| 5401 | qla83xx_reset_ownership(vha); |
| 5402 | |
| 5403 | rval = qla83xx_initiating_reset(vha); |
| 5404 | |
| 5405 | /* |
| 5406 | * Perform reset if we are the reset-owner, |
| 5407 | * else wait till IDC state changes to READY/FAILED. |
| 5408 | */ |
| 5409 | if (rval == QLA_SUCCESS) { |
| 5410 | rval = qla83xx_idc_state_handler(vha); |
| 5411 | |
| 5412 | if (rval == QLA_SUCCESS) |
| 5413 | ha->flags.nic_core_hung = 0; |
| 5414 | __qla83xx_clear_drv_ack(vha); |
| 5415 | } |
| 5416 | |
| 5417 | exit: |
| 5418 | qla83xx_idc_unlock(vha, 0); |
| 5419 | |
| 5420 | ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__); |
| 5421 | |
| 5422 | return rval; |
| 5423 | } |
| 5424 | |
Saurav Kashyap | 8117877 | 2012-08-22 14:21:04 -0400 | [diff] [blame] | 5425 | int |
| 5426 | qla2xxx_mctp_dump(scsi_qla_host_t *vha) |
| 5427 | { |
| 5428 | struct qla_hw_data *ha = vha->hw; |
| 5429 | int rval = QLA_FUNCTION_FAILED; |
| 5430 | |
| 5431 | if (!IS_MCTP_CAPABLE(ha)) { |
| 5432 | /* This message can be removed from the final version */ |
| 5433 | ql_log(ql_log_info, vha, 0x506d, |
| 5434 | "This board is not MCTP capable\n"); |
| 5435 | return rval; |
| 5436 | } |
| 5437 | |
| 5438 | if (!ha->mctp_dump) { |
| 5439 | ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev, |
| 5440 | MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL); |
| 5441 | |
| 5442 | if (!ha->mctp_dump) { |
| 5443 | ql_log(ql_log_warn, vha, 0x506e, |
| 5444 | "Failed to allocate memory for mctp dump\n"); |
| 5445 | return rval; |
| 5446 | } |
| 5447 | } |
| 5448 | |
| 5449 | #define MCTP_DUMP_STR_ADDR 0x00000000 |
| 5450 | rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma, |
| 5451 | MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4); |
| 5452 | if (rval != QLA_SUCCESS) { |
| 5453 | ql_log(ql_log_warn, vha, 0x506f, |
| 5454 | "Failed to capture mctp dump\n"); |
| 5455 | } else { |
| 5456 | ql_log(ql_log_info, vha, 0x5070, |
| 5457 | "Mctp dump capture for host (%ld/%p).\n", |
| 5458 | vha->host_no, ha->mctp_dump); |
| 5459 | ha->mctp_dumped = 1; |
| 5460 | } |
| 5461 | |
Saurav Kashyap | 409ee0f | 2012-08-22 14:21:29 -0400 | [diff] [blame] | 5462 | if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) { |
Saurav Kashyap | 8117877 | 2012-08-22 14:21:04 -0400 | [diff] [blame] | 5463 | ha->flags.nic_core_reset_hdlr_active = 1; |
| 5464 | rval = qla83xx_restart_nic_firmware(vha); |
| 5465 | if (rval) |
| 5466 | /* NIC Core reset failed. */ |
| 5467 | ql_log(ql_log_warn, vha, 0x5071, |
| 5468 | "Failed to restart nic firmware\n"); |
| 5469 | else |
| 5470 | ql_dbg(ql_dbg_p3p, vha, 0xb084, |
| 5471 | "Restarted NIC firmware successfully.\n"); |
| 5472 | ha->flags.nic_core_reset_hdlr_active = 0; |
| 5473 | } |
| 5474 | |
| 5475 | return rval; |
| 5476 | |
| 5477 | } |
| 5478 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5479 | /* |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 5480 | * qla2x00_quiesce_io |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5481 | * Description: This function will block the new I/Os |
| 5482 | * Its not aborting any I/Os as context |
| 5483 | * is not destroyed during quiescence |
| 5484 | * Arguments: scsi_qla_host_t |
| 5485 | * return : void |
| 5486 | */ |
| 5487 | void |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 5488 | qla2x00_quiesce_io(scsi_qla_host_t *vha) |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5489 | { |
| 5490 | struct qla_hw_data *ha = vha->hw; |
| 5491 | struct scsi_qla_host *vp; |
| 5492 | |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 5493 | ql_dbg(ql_dbg_dpc, vha, 0x401d, |
| 5494 | "Quiescing I/O - ha=%p.\n", ha); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5495 | |
| 5496 | atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); |
| 5497 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 5498 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 5499 | qla2x00_mark_all_devices_lost(vha, 0); |
| 5500 | list_for_each_entry(vp, &ha->vp_list, list) |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 5501 | qla2x00_mark_all_devices_lost(vp, 0); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5502 | } else { |
| 5503 | if (!atomic_read(&vha->loop_down_timer)) |
| 5504 | atomic_set(&vha->loop_down_timer, |
| 5505 | LOOP_DOWN_TIME); |
| 5506 | } |
| 5507 | /* Wait for pending cmds to complete */ |
| 5508 | qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST); |
| 5509 | } |
| 5510 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5511 | void |
| 5512 | qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha) |
| 5513 | { |
| 5514 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5515 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5516 | unsigned long flags; |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 5517 | fc_port_t *fcport; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5518 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 5519 | /* For ISP82XX, driver waits for completion of the commands. |
| 5520 | * online flag should be set. |
| 5521 | */ |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 5522 | if (!(IS_P3P_TYPE(ha))) |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 5523 | vha->flags.online = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5524 | ha->flags.chip_reset_done = 0; |
| 5525 | clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Saurav Kashyap | 2be21fa | 2012-05-15 14:34:16 -0400 | [diff] [blame] | 5526 | vha->qla_stats.total_isp_aborts++; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5527 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5528 | ql_log(ql_log_info, vha, 0x00af, |
| 5529 | "Performing ISP error recovery - ha=%p.\n", ha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5530 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 5531 | /* For ISP82XX, reset_chip is just disabling interrupts. |
| 5532 | * Driver waits for the completion of the commands. |
| 5533 | * the interrupts need to be enabled. |
| 5534 | */ |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 5535 | if (!(IS_P3P_TYPE(ha))) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5536 | ha->isp_ops->reset_chip(vha); |
| 5537 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5538 | ha->chip_reset++; |
| 5539 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5540 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 5541 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 5542 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 5543 | qla2x00_mark_all_devices_lost(vha, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5544 | |
| 5545 | spin_lock_irqsave(&ha->vport_slock, flags); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5546 | list_for_each_entry(vp, &ha->vp_list, list) { |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5547 | atomic_inc(&vp->vref_count); |
| 5548 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5549 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5550 | qla2x00_mark_all_devices_lost(vp, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5551 | |
| 5552 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5553 | atomic_dec(&vp->vref_count); |
| 5554 | } |
| 5555 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5556 | } else { |
| 5557 | if (!atomic_read(&vha->loop_down_timer)) |
| 5558 | atomic_set(&vha->loop_down_timer, |
| 5559 | LOOP_DOWN_TIME); |
| 5560 | } |
| 5561 | |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 5562 | /* Clear all async request states across all VPs. */ |
| 5563 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 5564 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 5565 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5566 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 5567 | atomic_inc(&vp->vref_count); |
| 5568 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5569 | |
| 5570 | list_for_each_entry(fcport, &vp->vp_fcports, list) |
| 5571 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 5572 | |
| 5573 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5574 | atomic_dec(&vp->vref_count); |
| 5575 | } |
| 5576 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5577 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 5578 | if (!ha->flags.eeh_busy) { |
| 5579 | /* Make sure for ISP 82XX IO DMA is complete */ |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 5580 | if (IS_P3P_TYPE(ha)) { |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 5581 | qla82xx_chip_reset_cleanup(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5582 | ql_log(ql_log_info, vha, 0x00b4, |
| 5583 | "Done chip reset cleanup.\n"); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5584 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 5585 | /* Done waiting for pending commands. |
| 5586 | * Reset the online flag. |
| 5587 | */ |
| 5588 | vha->flags.online = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5589 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5590 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 5591 | /* Requeue all commands in outstanding command list. */ |
| 5592 | qla2x00_abort_all_cmds(vha, DID_RESET << 16); |
| 5593 | } |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 5594 | /* memory barrier */ |
| 5595 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5596 | } |
| 5597 | |
| 5598 | /* |
| 5599 | * qla2x00_abort_isp |
| 5600 | * Resets ISP and aborts all outstanding commands. |
| 5601 | * |
| 5602 | * Input: |
| 5603 | * ha = adapter block pointer. |
| 5604 | * |
| 5605 | * Returns: |
| 5606 | * 0 = success |
| 5607 | */ |
| 5608 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5609 | qla2x00_abort_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5610 | { |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 5611 | int rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5612 | uint8_t status = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5613 | struct qla_hw_data *ha = vha->hw; |
| 5614 | struct scsi_qla_host *vp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5615 | struct req_que *req = ha->req_q_map[0]; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5616 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5617 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5618 | if (vha->flags.online) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5619 | qla2x00_abort_isp_cleanup(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5620 | |
Santosh Vernekar | a6171297 | 2012-08-22 14:21:13 -0400 | [diff] [blame] | 5621 | if (IS_QLA8031(ha)) { |
| 5622 | ql_dbg(ql_dbg_p3p, vha, 0xb05c, |
| 5623 | "Clearing fcoe driver presence.\n"); |
| 5624 | if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS) |
| 5625 | ql_dbg(ql_dbg_p3p, vha, 0xb073, |
| 5626 | "Error while clearing DRV-Presence.\n"); |
| 5627 | } |
| 5628 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 5629 | if (unlikely(pci_channel_offline(ha->pdev) && |
| 5630 | ha->flags.pci_channel_io_perm_failure)) { |
| 5631 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 5632 | status = 0; |
| 5633 | return status; |
| 5634 | } |
| 5635 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5636 | ha->isp_ops->get_flash_version(vha, req->ring); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 5637 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5638 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5639 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5640 | if (!qla2x00_restart_isp(vha)) { |
| 5641 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5642 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5643 | if (!atomic_read(&vha->loop_down_timer)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5644 | /* |
| 5645 | * Issue marker command only when we are going |
| 5646 | * to start the I/O . |
| 5647 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5648 | vha->marker_needed = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5649 | } |
| 5650 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5651 | vha->flags.online = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5652 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 5653 | ha->isp_ops->enable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5654 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 5655 | ha->isp_abort_cnt = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5656 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 5657 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 5658 | if (IS_QLA81XX(ha) || IS_QLA8031(ha)) |
| 5659 | qla2x00_get_fw_version(vha); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 5660 | if (ha->fce) { |
| 5661 | ha->flags.fce_enabled = 1; |
| 5662 | memset(ha->fce, 0, |
| 5663 | fce_calc_size(ha->fce_bufs)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5664 | rval = qla2x00_enable_fce_trace(vha, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 5665 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 5666 | &ha->fce_bufs); |
| 5667 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5668 | ql_log(ql_log_warn, vha, 0x8033, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 5669 | "Unable to reinitialize FCE " |
| 5670 | "(%d).\n", rval); |
| 5671 | ha->flags.fce_enabled = 0; |
| 5672 | } |
| 5673 | } |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 5674 | |
| 5675 | if (ha->eft) { |
| 5676 | memset(ha->eft, 0, EFT_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5677 | rval = qla2x00_enable_eft_trace(vha, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 5678 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 5679 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5680 | ql_log(ql_log_warn, vha, 0x8034, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 5681 | "Unable to reinitialize EFT " |
| 5682 | "(%d).\n", rval); |
| 5683 | } |
| 5684 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5685 | } else { /* failed the ISP abort */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5686 | vha->flags.online = 1; |
| 5687 | if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5688 | if (ha->isp_abort_cnt == 0) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5689 | ql_log(ql_log_fatal, vha, 0x8035, |
| 5690 | "ISP error recover failed - " |
| 5691 | "board disabled.\n"); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 5692 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5693 | * The next call disables the board |
| 5694 | * completely. |
| 5695 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5696 | ha->isp_ops->reset_adapter(vha); |
| 5697 | vha->flags.online = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5698 | clear_bit(ISP_ABORT_RETRY, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5699 | &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5700 | status = 0; |
| 5701 | } else { /* schedule another ISP abort */ |
| 5702 | ha->isp_abort_cnt--; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5703 | ql_dbg(ql_dbg_taskm, vha, 0x8020, |
| 5704 | "ISP abort - retry remaining %d.\n", |
| 5705 | ha->isp_abort_cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5706 | status = 1; |
| 5707 | } |
| 5708 | } else { |
| 5709 | ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5710 | ql_dbg(ql_dbg_taskm, vha, 0x8021, |
| 5711 | "ISP error recovery - retrying (%d) " |
| 5712 | "more times.\n", ha->isp_abort_cnt); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5713 | set_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5714 | status = 1; |
| 5715 | } |
| 5716 | } |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 5717 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5718 | } |
| 5719 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5720 | if (!status) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5721 | ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5722 | |
| 5723 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5724 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 5725 | if (vp->vp_idx) { |
| 5726 | atomic_inc(&vp->vref_count); |
| 5727 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5728 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5729 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5730 | |
| 5731 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5732 | atomic_dec(&vp->vref_count); |
| 5733 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5734 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5735 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5736 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5737 | if (IS_QLA8031(ha)) { |
| 5738 | ql_dbg(ql_dbg_p3p, vha, 0xb05d, |
| 5739 | "Setting back fcoe driver presence.\n"); |
| 5740 | if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS) |
| 5741 | ql_dbg(ql_dbg_p3p, vha, 0xb074, |
| 5742 | "Error while setting DRV-Presence.\n"); |
| 5743 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5744 | } else { |
Joe Perches | d8424f6 | 2011-11-18 09:03:06 -0800 | [diff] [blame] | 5745 | ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n", |
| 5746 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5747 | } |
| 5748 | |
| 5749 | return(status); |
| 5750 | } |
| 5751 | |
| 5752 | /* |
| 5753 | * qla2x00_restart_isp |
| 5754 | * restarts the ISP after a reset |
| 5755 | * |
| 5756 | * Input: |
| 5757 | * ha = adapter block pointer. |
| 5758 | * |
| 5759 | * Returns: |
| 5760 | * 0 = success |
| 5761 | */ |
| 5762 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5763 | qla2x00_restart_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5764 | { |
Andrew Vasquez | c6b2fca | 2009-03-05 11:07:03 -0800 | [diff] [blame] | 5765 | int status = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5766 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5767 | struct req_que *req = ha->req_q_map[0]; |
| 5768 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5769 | |
| 5770 | /* If firmware needs to be loaded */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5771 | if (qla2x00_isp_firmware(vha)) { |
| 5772 | vha->flags.online = 0; |
| 5773 | status = ha->isp_ops->chip_diag(vha); |
| 5774 | if (!status) |
| 5775 | status = qla2x00_setup_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5776 | } |
| 5777 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5778 | if (!status && !(status = qla2x00_init_rings(vha))) { |
| 5779 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 5780 | ha->flags.chip_reset_done = 1; |
Chad Dupuis | 7108b76 | 2014-04-11 16:54:45 -0400 | [diff] [blame] | 5781 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5782 | /* Initialize the queues in use */ |
| 5783 | qla25xx_init_queues(ha); |
| 5784 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5785 | status = qla2x00_fw_ready(vha); |
| 5786 | if (!status) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5787 | /* Issue a marker after FW becomes ready. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5788 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Chad Dupuis | 7108b76 | 2014-04-11 16:54:45 -0400 | [diff] [blame] | 5789 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5790 | } |
| 5791 | |
| 5792 | /* if no cable then assume it's good */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5793 | if ((vha->device_flags & DFLG_NO_CABLE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5794 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5795 | } |
| 5796 | return (status); |
| 5797 | } |
| 5798 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5799 | static int |
| 5800 | qla25xx_init_queues(struct qla_hw_data *ha) |
| 5801 | { |
| 5802 | struct rsp_que *rsp = NULL; |
| 5803 | struct req_que *req = NULL; |
| 5804 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
| 5805 | int ret = -1; |
| 5806 | int i; |
| 5807 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 5808 | for (i = 1; i < ha->max_rsp_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5809 | rsp = ha->rsp_q_map[i]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 5810 | if (rsp && test_bit(i, ha->rsp_qid_map)) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5811 | rsp->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 5812 | ret = qla25xx_init_rsp_que(base_vha, rsp); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5813 | if (ret != QLA_SUCCESS) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5814 | ql_dbg(ql_dbg_init, base_vha, 0x00ff, |
| 5815 | "%s Rsp que: %d init failed.\n", |
| 5816 | __func__, rsp->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5817 | else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5818 | ql_dbg(ql_dbg_init, base_vha, 0x0100, |
| 5819 | "%s Rsp que: %d inited.\n", |
| 5820 | __func__, rsp->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5821 | } |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 5822 | } |
| 5823 | for (i = 1; i < ha->max_req_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5824 | req = ha->req_q_map[i]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 5825 | if (req && test_bit(i, ha->req_qid_map)) { |
| 5826 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5827 | req->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 5828 | ret = qla25xx_init_req_que(base_vha, req); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5829 | if (ret != QLA_SUCCESS) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5830 | ql_dbg(ql_dbg_init, base_vha, 0x0101, |
| 5831 | "%s Req que: %d init failed.\n", |
| 5832 | __func__, req->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5833 | else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5834 | ql_dbg(ql_dbg_init, base_vha, 0x0102, |
| 5835 | "%s Req que: %d inited.\n", |
| 5836 | __func__, req->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5837 | } |
| 5838 | } |
| 5839 | return ret; |
| 5840 | } |
| 5841 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5842 | /* |
| 5843 | * qla2x00_reset_adapter |
| 5844 | * Reset adapter. |
| 5845 | * |
| 5846 | * Input: |
| 5847 | * ha = adapter block pointer. |
| 5848 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 5849 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5850 | qla2x00_reset_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5851 | { |
| 5852 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5853 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 5854 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5855 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5856 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 5857 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5858 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5859 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 5860 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 5861 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 5862 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 5863 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 5864 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 5865 | } |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5866 | |
| 5867 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5868 | qla24xx_reset_adapter(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5869 | { |
| 5870 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5871 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5872 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 5873 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 5874 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5875 | return; |
| 5876 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5877 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 5878 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5879 | |
| 5880 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 5881 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 5882 | RD_REG_DWORD(®->hccr); |
| 5883 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 5884 | RD_REG_DWORD(®->hccr); |
| 5885 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 09ff36d | 2009-01-22 09:45:30 -0800 | [diff] [blame] | 5886 | |
| 5887 | if (IS_NOPOLLING_TYPE(ha)) |
| 5888 | ha->isp_ops->enable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5889 | } |
| 5890 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5891 | /* On sparc systems, obtain port and node WWN from firmware |
| 5892 | * properties. |
| 5893 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5894 | static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, |
| 5895 | struct nvram_24xx *nv) |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5896 | { |
| 5897 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5898 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5899 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 5900 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 5901 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5902 | int len; |
| 5903 | |
| 5904 | val = of_get_property(dp, "port-wwn", &len); |
| 5905 | if (val && len >= WWN_SIZE) |
| 5906 | memcpy(nv->port_name, val, WWN_SIZE); |
| 5907 | |
| 5908 | val = of_get_property(dp, "node-wwn", &len); |
| 5909 | if (val && len >= WWN_SIZE) |
| 5910 | memcpy(nv->node_name, val, WWN_SIZE); |
| 5911 | #endif |
| 5912 | } |
| 5913 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5914 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5915 | qla24xx_nvram_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5916 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5917 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5918 | struct init_cb_24xx *icb; |
| 5919 | struct nvram_24xx *nv; |
| 5920 | uint32_t *dptr; |
| 5921 | uint8_t *dptr1, *dptr2; |
| 5922 | uint32_t chksum; |
| 5923 | uint16_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5924 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5925 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5926 | rval = QLA_SUCCESS; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5927 | icb = (struct init_cb_24xx *)ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 5928 | nv = ha->nvram; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5929 | |
| 5930 | /* Determine NVRAM starting address. */ |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 5931 | if (ha->port_no == 0) { |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5932 | ha->nvram_base = FA_NVRAM_FUNC0_ADDR; |
| 5933 | ha->vpd_base = FA_NVRAM_VPD0_ADDR; |
| 5934 | } else { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5935 | ha->nvram_base = FA_NVRAM_FUNC1_ADDR; |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 5936 | ha->vpd_base = FA_NVRAM_VPD1_ADDR; |
| 5937 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 5938 | |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5939 | ha->nvram_size = sizeof(struct nvram_24xx); |
| 5940 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5941 | |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 5942 | /* Get VPD data into cache */ |
| 5943 | ha->vpd = ha->nvram + VPD_OFFSET; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5944 | ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 5945 | ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4); |
| 5946 | |
| 5947 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5948 | dptr = (uint32_t *)nv; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5949 | ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5950 | ha->nvram_size); |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 5951 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++) |
| 5952 | chksum += le32_to_cpu(*dptr); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5953 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5954 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a, |
| 5955 | "Contents of NVRAM\n"); |
| 5956 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d, |
| 5957 | (uint8_t *)nv, ha->nvram_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5958 | |
| 5959 | /* Bad NVRAM data, set defaults parameters. */ |
| 5960 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 5961 | || nv->id[3] != ' ' || |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5962 | nv->nvram_version < cpu_to_le16(ICB_VERSION)) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5963 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5964 | ql_log(ql_log_warn, vha, 0x006b, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 5965 | "Inconsistent NVRAM detected: checksum=0x%x id=%c " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5966 | "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version); |
| 5967 | ql_log(ql_log_warn, vha, 0x006c, |
| 5968 | "Falling back to functioning (yet invalid -- WWPN) " |
| 5969 | "defaults.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5970 | |
| 5971 | /* |
| 5972 | * Set default initialization control block. |
| 5973 | */ |
| 5974 | memset(nv, 0, ha->nvram_size); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5975 | nv->nvram_version = cpu_to_le16(ICB_VERSION); |
| 5976 | nv->version = cpu_to_le16(ICB_VERSION); |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 5977 | nv->frame_payload_size = 2048; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5978 | nv->execution_throttle = cpu_to_le16(0xFFFF); |
| 5979 | nv->exchange_count = cpu_to_le16(0); |
| 5980 | nv->hard_address = cpu_to_le16(124); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5981 | nv->port_name[0] = 0x21; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 5982 | nv->port_name[1] = 0x00 + ha->port_no + 1; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5983 | nv->port_name[2] = 0x00; |
| 5984 | nv->port_name[3] = 0xe0; |
| 5985 | nv->port_name[4] = 0x8b; |
| 5986 | nv->port_name[5] = 0x1c; |
| 5987 | nv->port_name[6] = 0x55; |
| 5988 | nv->port_name[7] = 0x86; |
| 5989 | nv->node_name[0] = 0x20; |
| 5990 | nv->node_name[1] = 0x00; |
| 5991 | nv->node_name[2] = 0x00; |
| 5992 | nv->node_name[3] = 0xe0; |
| 5993 | nv->node_name[4] = 0x8b; |
| 5994 | nv->node_name[5] = 0x1c; |
| 5995 | nv->node_name[6] = 0x55; |
| 5996 | nv->node_name[7] = 0x86; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5997 | qla24xx_nvram_wwn_from_ofw(vha, nv); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5998 | nv->login_retry_count = cpu_to_le16(8); |
| 5999 | nv->interrupt_delay_timer = cpu_to_le16(0); |
| 6000 | nv->login_timeout = cpu_to_le16(0); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6001 | nv->firmware_options_1 = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6002 | cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 6003 | nv->firmware_options_2 = cpu_to_le32(2 << 4); |
| 6004 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 6005 | nv->firmware_options_3 = cpu_to_le32(2 << 13); |
| 6006 | nv->host_p = cpu_to_le32(BIT_11|BIT_10); |
| 6007 | nv->efi_parameters = cpu_to_le32(0); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6008 | nv->reset_delay = 5; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6009 | nv->max_luns_per_target = cpu_to_le16(128); |
| 6010 | nv->port_down_retry_count = cpu_to_le16(30); |
| 6011 | nv->link_down_timeout = cpu_to_le16(30); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6012 | |
| 6013 | rval = 1; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6014 | } |
| 6015 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6016 | if (qla_tgt_mode_enabled(vha)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6017 | /* Don't enable full login after initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6018 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6019 | /* Don't enable LIP full login for initiator */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6020 | nv->host_p &= cpu_to_le32(~BIT_10); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6021 | } |
| 6022 | |
| 6023 | qlt_24xx_config_nvram_stage1(vha, nv); |
| 6024 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6025 | /* Reset Initialization control block */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6026 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6027 | |
| 6028 | /* Copy 1st segment. */ |
| 6029 | dptr1 = (uint8_t *)icb; |
| 6030 | dptr2 = (uint8_t *)&nv->version; |
| 6031 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 6032 | while (cnt--) |
| 6033 | *dptr1++ = *dptr2++; |
| 6034 | |
| 6035 | icb->login_retry_count = nv->login_retry_count; |
Andrew Vasquez | 3ea66e2 | 2006-06-23 16:11:27 -0700 | [diff] [blame] | 6036 | icb->link_down_on_nos = nv->link_down_on_nos; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6037 | |
| 6038 | /* Copy 2nd segment. */ |
| 6039 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 6040 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 6041 | cnt = (uint8_t *)&icb->reserved_3 - |
| 6042 | (uint8_t *)&icb->interrupt_delay_timer; |
| 6043 | while (cnt--) |
| 6044 | *dptr1++ = *dptr2++; |
| 6045 | |
| 6046 | /* |
| 6047 | * Setup driver NVRAM options. |
| 6048 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6049 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 6050 | "QLA2462"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6051 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6052 | qlt_24xx_config_nvram_stage2(vha, icb); |
| 6053 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6054 | if (nv->host_p & cpu_to_le32(BIT_15)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6055 | /* Use alternate WWN? */ |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 6056 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 6057 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 6058 | } |
| 6059 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6060 | /* Prepare nodename */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6061 | if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6062 | /* |
| 6063 | * Firmware will apply the following mask if the nodename was |
| 6064 | * not provided. |
| 6065 | */ |
| 6066 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 6067 | icb->node_name[0] &= 0xF0; |
| 6068 | } |
| 6069 | |
| 6070 | /* Set host adapter parameters. */ |
| 6071 | ha->flags.disable_risc_code_load = 0; |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 6072 | ha->flags.enable_lip_reset = 0; |
| 6073 | ha->flags.enable_lip_full_login = |
| 6074 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 6075 | ha->flags.enable_target_reset = |
| 6076 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6077 | ha->flags.enable_led_scheme = 0; |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 6078 | 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] | 6079 | |
Andrew Vasquez | fd0e7e4 | 2006-05-17 15:09:11 -0700 | [diff] [blame] | 6080 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 6081 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6082 | |
| 6083 | memcpy(ha->fw_seriallink_options24, nv->seriallink_options, |
| 6084 | sizeof(ha->fw_seriallink_options24)); |
| 6085 | |
| 6086 | /* save HBA serial number */ |
| 6087 | ha->serial0 = icb->port_name[5]; |
| 6088 | ha->serial1 = icb->port_name[6]; |
| 6089 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6090 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 6091 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6092 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6093 | icb->execution_throttle = cpu_to_le16(0xFFFF); |
andrew.vasquez@qlogic.com | bc8fb3c | 2006-01-13 17:05:42 -0800 | [diff] [blame] | 6094 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6095 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 6096 | |
| 6097 | /* Set minimum login_timeout to 4 seconds. */ |
| 6098 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 6099 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 6100 | if (le16_to_cpu(nv->login_timeout) < 4) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6101 | nv->login_timeout = cpu_to_le16(4); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6102 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6103 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 6104 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 6105 | ha->r_a_tov = 100; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6106 | |
| 6107 | ha->loop_reset_delay = nv->reset_delay; |
| 6108 | |
| 6109 | /* Link Down Timeout = 0: |
| 6110 | * |
| 6111 | * When Port Down timer expires we will start returning |
| 6112 | * I/O's to OS with "DID_NO_CONNECT". |
| 6113 | * |
| 6114 | * Link Down Timeout != 0: |
| 6115 | * |
| 6116 | * The driver waits for the link to come up after link down |
| 6117 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 6118 | */ |
| 6119 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 6120 | ha->loop_down_abort_time = |
| 6121 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 6122 | } else { |
| 6123 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 6124 | ha->loop_down_abort_time = |
| 6125 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 6126 | } |
| 6127 | |
| 6128 | /* Need enough time to try and get the port back. */ |
| 6129 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 6130 | if (qlport_down_retry) |
| 6131 | ha->port_down_retry_count = qlport_down_retry; |
| 6132 | |
| 6133 | /* Set login_retry_count */ |
| 6134 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 6135 | if (ha->port_down_retry_count == |
| 6136 | le16_to_cpu(nv->port_down_retry_count) && |
| 6137 | ha->port_down_retry_count > 3) |
| 6138 | ha->login_retry_count = ha->port_down_retry_count; |
| 6139 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 6140 | ha->login_retry_count = ha->port_down_retry_count; |
| 6141 | if (ql2xloginretrycount) |
| 6142 | ha->login_retry_count = ql2xloginretrycount; |
| 6143 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6144 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6145 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6146 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 6147 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 6148 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 6149 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 6150 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6151 | icb->firmware_options_2 &= cpu_to_le32( |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6152 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6153 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6154 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 6155 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 6156 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6157 | ql_log(ql_log_info, vha, 0x006f, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6158 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 6159 | ha->zio_mode, ha->zio_timer * 100); |
| 6160 | |
| 6161 | icb->firmware_options_2 |= cpu_to_le32( |
| 6162 | (uint32_t)ha->zio_mode); |
| 6163 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6164 | vha->flags.process_response_queue = 1; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6165 | } |
| 6166 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6167 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6168 | ql_log(ql_log_warn, vha, 0x0070, |
| 6169 | "NVRAM configuration failed.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6170 | } |
| 6171 | return (rval); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6172 | } |
| 6173 | |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 6174 | uint8_t qla27xx_find_valid_image(struct scsi_qla_host *vha) |
| 6175 | { |
| 6176 | struct qla27xx_image_status pri_image_status, sec_image_status; |
| 6177 | uint8_t valid_pri_image, valid_sec_image; |
| 6178 | uint32_t *wptr; |
| 6179 | uint32_t cnt, chksum, size; |
| 6180 | struct qla_hw_data *ha = vha->hw; |
| 6181 | |
| 6182 | valid_pri_image = valid_sec_image = 1; |
| 6183 | ha->active_image = 0; |
| 6184 | size = sizeof(struct qla27xx_image_status) / sizeof(uint32_t); |
| 6185 | |
| 6186 | if (!ha->flt_region_img_status_pri) { |
| 6187 | valid_pri_image = 0; |
| 6188 | goto check_sec_image; |
| 6189 | } |
| 6190 | |
| 6191 | qla24xx_read_flash_data(vha, (uint32_t *)(&pri_image_status), |
| 6192 | ha->flt_region_img_status_pri, size); |
| 6193 | |
| 6194 | if (pri_image_status.signature != QLA27XX_IMG_STATUS_SIGN) { |
| 6195 | ql_dbg(ql_dbg_init, vha, 0x018b, |
| 6196 | "Primary image signature (0x%x) not valid\n", |
| 6197 | pri_image_status.signature); |
| 6198 | valid_pri_image = 0; |
| 6199 | goto check_sec_image; |
| 6200 | } |
| 6201 | |
| 6202 | wptr = (uint32_t *)(&pri_image_status); |
| 6203 | cnt = size; |
| 6204 | |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 6205 | for (chksum = 0; cnt--; wptr++) |
| 6206 | chksum += le32_to_cpu(*wptr); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 6207 | |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 6208 | if (chksum) { |
| 6209 | ql_dbg(ql_dbg_init, vha, 0x018c, |
| 6210 | "Checksum validation failed for primary image (0x%x)\n", |
| 6211 | chksum); |
| 6212 | valid_pri_image = 0; |
| 6213 | } |
| 6214 | |
| 6215 | check_sec_image: |
| 6216 | if (!ha->flt_region_img_status_sec) { |
| 6217 | valid_sec_image = 0; |
| 6218 | goto check_valid_image; |
| 6219 | } |
| 6220 | |
| 6221 | qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status), |
| 6222 | ha->flt_region_img_status_sec, size); |
| 6223 | |
| 6224 | if (sec_image_status.signature != QLA27XX_IMG_STATUS_SIGN) { |
| 6225 | ql_dbg(ql_dbg_init, vha, 0x018d, |
| 6226 | "Secondary image signature(0x%x) not valid\n", |
| 6227 | sec_image_status.signature); |
| 6228 | valid_sec_image = 0; |
| 6229 | goto check_valid_image; |
| 6230 | } |
| 6231 | |
| 6232 | wptr = (uint32_t *)(&sec_image_status); |
| 6233 | cnt = size; |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 6234 | for (chksum = 0; cnt--; wptr++) |
| 6235 | chksum += le32_to_cpu(*wptr); |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 6236 | if (chksum) { |
| 6237 | ql_dbg(ql_dbg_init, vha, 0x018e, |
| 6238 | "Checksum validation failed for secondary image (0x%x)\n", |
| 6239 | chksum); |
| 6240 | valid_sec_image = 0; |
| 6241 | } |
| 6242 | |
| 6243 | check_valid_image: |
| 6244 | if (valid_pri_image && (pri_image_status.image_status_mask & 0x1)) |
| 6245 | ha->active_image = QLA27XX_PRIMARY_IMAGE; |
| 6246 | if (valid_sec_image && (sec_image_status.image_status_mask & 0x1)) { |
| 6247 | if (!ha->active_image || |
| 6248 | pri_image_status.generation_number < |
| 6249 | sec_image_status.generation_number) |
| 6250 | ha->active_image = QLA27XX_SECONDARY_IMAGE; |
| 6251 | } |
| 6252 | |
| 6253 | ql_dbg(ql_dbg_init, vha, 0x018f, "%s image\n", |
| 6254 | ha->active_image == 0 ? "default bootld and fw" : |
| 6255 | ha->active_image == 1 ? "primary" : |
| 6256 | ha->active_image == 2 ? "secondary" : |
| 6257 | "Invalid"); |
| 6258 | |
| 6259 | return ha->active_image; |
| 6260 | } |
| 6261 | |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 6262 | static int |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6263 | qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr, |
| 6264 | uint32_t faddr) |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6265 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6266 | int rval = QLA_SUCCESS; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6267 | int segments, fragment; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6268 | uint32_t *dcode, dlen; |
| 6269 | uint32_t risc_addr; |
| 6270 | uint32_t risc_size; |
| 6271 | uint32_t i; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6272 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6273 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6274 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6275 | ql_dbg(ql_dbg_init, vha, 0x008b, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 6276 | "FW: Loading firmware from flash (%x).\n", faddr); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6277 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6278 | rval = QLA_SUCCESS; |
| 6279 | |
| 6280 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6281 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6282 | *srisc_addr = 0; |
| 6283 | |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 6284 | if (IS_QLA27XX(ha) && |
| 6285 | qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE) |
| 6286 | faddr = ha->flt_region_fw_sec; |
| 6287 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6288 | /* Validate firmware image by checking version. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6289 | qla24xx_read_flash_data(vha, dcode, faddr + 4, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6290 | for (i = 0; i < 4; i++) |
| 6291 | dcode[i] = be32_to_cpu(dcode[i]); |
| 6292 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 6293 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 6294 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 6295 | dcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6296 | ql_log(ql_log_fatal, vha, 0x008c, |
| 6297 | "Unable to verify the integrity of flash firmware " |
| 6298 | "image.\n"); |
| 6299 | ql_log(ql_log_fatal, vha, 0x008d, |
| 6300 | "Firmware data: %08x %08x %08x %08x.\n", |
| 6301 | dcode[0], dcode[1], dcode[2], dcode[3]); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6302 | |
| 6303 | return QLA_FUNCTION_FAILED; |
| 6304 | } |
| 6305 | |
| 6306 | while (segments && rval == QLA_SUCCESS) { |
| 6307 | /* Read segment's load information. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6308 | qla24xx_read_flash_data(vha, dcode, faddr, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6309 | |
| 6310 | risc_addr = be32_to_cpu(dcode[2]); |
| 6311 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 6312 | risc_size = be32_to_cpu(dcode[3]); |
| 6313 | |
| 6314 | fragment = 0; |
| 6315 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 6316 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 6317 | if (dlen > risc_size) |
| 6318 | dlen = risc_size; |
| 6319 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6320 | ql_dbg(ql_dbg_init, vha, 0x008e, |
| 6321 | "Loading risc segment@ risc addr %x " |
| 6322 | "number of dwords 0x%x offset 0x%x.\n", |
| 6323 | risc_addr, dlen, faddr); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6324 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6325 | qla24xx_read_flash_data(vha, dcode, faddr, dlen); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6326 | for (i = 0; i < dlen; i++) |
| 6327 | dcode[i] = swab32(dcode[i]); |
| 6328 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6329 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6330 | dlen); |
| 6331 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6332 | ql_log(ql_log_fatal, vha, 0x008f, |
| 6333 | "Failed to load segment %d of firmware.\n", |
| 6334 | fragment); |
Chad Dupuis | f261f7a | 2014-09-25 05:17:03 -0400 | [diff] [blame] | 6335 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6336 | } |
| 6337 | |
| 6338 | faddr += dlen; |
| 6339 | risc_addr += dlen; |
| 6340 | risc_size -= dlen; |
| 6341 | fragment++; |
| 6342 | } |
| 6343 | |
| 6344 | /* Next segment. */ |
| 6345 | segments--; |
| 6346 | } |
| 6347 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6348 | if (!IS_QLA27XX(ha)) |
| 6349 | return rval; |
| 6350 | |
| 6351 | if (ha->fw_dump_template) |
| 6352 | vfree(ha->fw_dump_template); |
| 6353 | ha->fw_dump_template = NULL; |
| 6354 | ha->fw_dump_template_len = 0; |
| 6355 | |
| 6356 | ql_dbg(ql_dbg_init, vha, 0x0161, |
| 6357 | "Loading fwdump template from %x\n", faddr); |
| 6358 | qla24xx_read_flash_data(vha, dcode, faddr, 7); |
| 6359 | risc_size = be32_to_cpu(dcode[2]); |
| 6360 | ql_dbg(ql_dbg_init, vha, 0x0162, |
| 6361 | "-> array size %x dwords\n", risc_size); |
| 6362 | if (risc_size == 0 || risc_size == ~0) |
| 6363 | goto default_template; |
| 6364 | |
| 6365 | dlen = (risc_size - 8) * sizeof(*dcode); |
| 6366 | ql_dbg(ql_dbg_init, vha, 0x0163, |
| 6367 | "-> template allocating %x bytes...\n", dlen); |
| 6368 | ha->fw_dump_template = vmalloc(dlen); |
| 6369 | if (!ha->fw_dump_template) { |
| 6370 | ql_log(ql_log_warn, vha, 0x0164, |
| 6371 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 6372 | goto default_template; |
| 6373 | } |
| 6374 | |
| 6375 | faddr += 7; |
| 6376 | risc_size -= 8; |
| 6377 | dcode = ha->fw_dump_template; |
| 6378 | qla24xx_read_flash_data(vha, dcode, faddr, risc_size); |
| 6379 | for (i = 0; i < risc_size; i++) |
| 6380 | dcode[i] = le32_to_cpu(dcode[i]); |
| 6381 | |
| 6382 | if (!qla27xx_fwdt_template_valid(dcode)) { |
| 6383 | ql_log(ql_log_warn, vha, 0x0165, |
| 6384 | "Failed fwdump template validate\n"); |
| 6385 | goto default_template; |
| 6386 | } |
| 6387 | |
| 6388 | dlen = qla27xx_fwdt_template_size(dcode); |
| 6389 | ql_dbg(ql_dbg_init, vha, 0x0166, |
| 6390 | "-> template size %x bytes\n", dlen); |
| 6391 | if (dlen > risc_size * sizeof(*dcode)) { |
| 6392 | ql_log(ql_log_warn, vha, 0x0167, |
Chad Dupuis | 97ea702 | 2014-03-13 14:16:40 -0400 | [diff] [blame] | 6393 | "Failed fwdump template exceeds array by %x bytes\n", |
| 6394 | (uint32_t)(dlen - risc_size * sizeof(*dcode))); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6395 | goto default_template; |
| 6396 | } |
| 6397 | ha->fw_dump_template_len = dlen; |
| 6398 | return rval; |
| 6399 | |
| 6400 | default_template: |
| 6401 | ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n"); |
| 6402 | if (ha->fw_dump_template) |
| 6403 | vfree(ha->fw_dump_template); |
| 6404 | ha->fw_dump_template = NULL; |
| 6405 | ha->fw_dump_template_len = 0; |
| 6406 | |
| 6407 | dlen = qla27xx_fwdt_template_default_size(); |
| 6408 | ql_dbg(ql_dbg_init, vha, 0x0169, |
| 6409 | "-> template allocating %x bytes...\n", dlen); |
| 6410 | ha->fw_dump_template = vmalloc(dlen); |
| 6411 | if (!ha->fw_dump_template) { |
| 6412 | ql_log(ql_log_warn, vha, 0x016a, |
| 6413 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 6414 | goto failed_template; |
| 6415 | } |
| 6416 | |
| 6417 | dcode = ha->fw_dump_template; |
| 6418 | risc_size = dlen / sizeof(*dcode); |
| 6419 | memcpy(dcode, qla27xx_fwdt_template_default(), dlen); |
| 6420 | for (i = 0; i < risc_size; i++) |
| 6421 | dcode[i] = be32_to_cpu(dcode[i]); |
| 6422 | |
| 6423 | if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) { |
| 6424 | ql_log(ql_log_warn, vha, 0x016b, |
| 6425 | "Failed fwdump template validate\n"); |
| 6426 | goto failed_template; |
| 6427 | } |
| 6428 | |
| 6429 | dlen = qla27xx_fwdt_template_size(ha->fw_dump_template); |
| 6430 | ql_dbg(ql_dbg_init, vha, 0x016c, |
| 6431 | "-> template size %x bytes\n", dlen); |
| 6432 | ha->fw_dump_template_len = dlen; |
| 6433 | return rval; |
| 6434 | |
| 6435 | failed_template: |
| 6436 | ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n"); |
| 6437 | if (ha->fw_dump_template) |
| 6438 | vfree(ha->fw_dump_template); |
| 6439 | ha->fw_dump_template = NULL; |
| 6440 | ha->fw_dump_template_len = 0; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6441 | return rval; |
| 6442 | } |
| 6443 | |
Giridhar Malavali | e9454a8 | 2013-02-08 01:57:47 -0500 | [diff] [blame] | 6444 | #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/" |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6445 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6446 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6447 | qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6448 | { |
| 6449 | int rval; |
| 6450 | int i, fragment; |
| 6451 | uint16_t *wcode, *fwcode; |
| 6452 | uint32_t risc_addr, risc_size, fwclen, wlen, *seg; |
| 6453 | struct fw_blob *blob; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6454 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6455 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6456 | |
| 6457 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6458 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6459 | if (!blob) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6460 | ql_log(ql_log_info, vha, 0x0083, |
Yannick Guerrini | 94bcf83 | 2015-02-26 22:49:34 +0100 | [diff] [blame] | 6461 | "Firmware image unavailable.\n"); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6462 | ql_log(ql_log_info, vha, 0x0084, |
| 6463 | "Firmware images can be retrieved from: "QLA_FW_URL ".\n"); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6464 | return QLA_FUNCTION_FAILED; |
| 6465 | } |
| 6466 | |
| 6467 | rval = QLA_SUCCESS; |
| 6468 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6469 | wcode = (uint16_t *)req->ring; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6470 | *srisc_addr = 0; |
| 6471 | fwcode = (uint16_t *)blob->fw->data; |
| 6472 | fwclen = 0; |
| 6473 | |
| 6474 | /* Validate firmware image by checking version. */ |
| 6475 | if (blob->fw->size < 8 * sizeof(uint16_t)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6476 | ql_log(ql_log_fatal, vha, 0x0085, |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 6477 | "Unable to verify integrity of firmware image (%zd).\n", |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6478 | blob->fw->size); |
| 6479 | goto fail_fw_integrity; |
| 6480 | } |
| 6481 | for (i = 0; i < 4; i++) |
| 6482 | wcode[i] = be16_to_cpu(fwcode[i + 4]); |
| 6483 | if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff && |
| 6484 | wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 && |
| 6485 | wcode[2] == 0 && wcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6486 | ql_log(ql_log_fatal, vha, 0x0086, |
| 6487 | "Unable to verify integrity of firmware image.\n"); |
| 6488 | ql_log(ql_log_fatal, vha, 0x0087, |
| 6489 | "Firmware data: %04x %04x %04x %04x.\n", |
| 6490 | wcode[0], wcode[1], wcode[2], wcode[3]); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6491 | goto fail_fw_integrity; |
| 6492 | } |
| 6493 | |
| 6494 | seg = blob->segs; |
| 6495 | while (*seg && rval == QLA_SUCCESS) { |
| 6496 | risc_addr = *seg; |
| 6497 | *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr; |
| 6498 | risc_size = be16_to_cpu(fwcode[3]); |
| 6499 | |
| 6500 | /* Validate firmware image size. */ |
| 6501 | fwclen += risc_size * sizeof(uint16_t); |
| 6502 | if (blob->fw->size < fwclen) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6503 | ql_log(ql_log_fatal, vha, 0x0088, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6504 | "Unable to verify integrity of firmware image " |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 6505 | "(%zd).\n", blob->fw->size); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6506 | goto fail_fw_integrity; |
| 6507 | } |
| 6508 | |
| 6509 | fragment = 0; |
| 6510 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 6511 | wlen = (uint16_t)(ha->fw_transfer_size >> 1); |
| 6512 | if (wlen > risc_size) |
| 6513 | wlen = risc_size; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6514 | ql_dbg(ql_dbg_init, vha, 0x0089, |
| 6515 | "Loading risc segment@ risc addr %x number of " |
| 6516 | "words 0x%x.\n", risc_addr, wlen); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6517 | |
| 6518 | for (i = 0; i < wlen; i++) |
| 6519 | wcode[i] = swab16(fwcode[i]); |
| 6520 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6521 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6522 | wlen); |
| 6523 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6524 | ql_log(ql_log_fatal, vha, 0x008a, |
| 6525 | "Failed to load segment %d of firmware.\n", |
| 6526 | fragment); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6527 | break; |
| 6528 | } |
| 6529 | |
| 6530 | fwcode += wlen; |
| 6531 | risc_addr += wlen; |
| 6532 | risc_size -= wlen; |
| 6533 | fragment++; |
| 6534 | } |
| 6535 | |
| 6536 | /* Next segment. */ |
| 6537 | seg++; |
| 6538 | } |
| 6539 | return rval; |
| 6540 | |
| 6541 | fail_fw_integrity: |
| 6542 | return QLA_FUNCTION_FAILED; |
| 6543 | } |
| 6544 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6545 | static int |
| 6546 | 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] | 6547 | { |
| 6548 | int rval; |
| 6549 | int segments, fragment; |
| 6550 | uint32_t *dcode, dlen; |
| 6551 | uint32_t risc_addr; |
| 6552 | uint32_t risc_size; |
| 6553 | uint32_t i; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6554 | struct fw_blob *blob; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6555 | const uint32_t *fwcode; |
| 6556 | uint32_t fwclen; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6557 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6558 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6559 | |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6560 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6561 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6562 | if (!blob) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6563 | ql_log(ql_log_warn, vha, 0x0090, |
Yannick Guerrini | 94bcf83 | 2015-02-26 22:49:34 +0100 | [diff] [blame] | 6564 | "Firmware image unavailable.\n"); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6565 | ql_log(ql_log_warn, vha, 0x0091, |
| 6566 | "Firmware images can be retrieved from: " |
| 6567 | QLA_FW_URL ".\n"); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6568 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6569 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6570 | } |
| 6571 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 6572 | ql_dbg(ql_dbg_init, vha, 0x0092, |
| 6573 | "FW: Loading via request-firmware.\n"); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6574 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6575 | rval = QLA_SUCCESS; |
| 6576 | |
| 6577 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6578 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6579 | *srisc_addr = 0; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6580 | fwcode = (uint32_t *)blob->fw->data; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6581 | fwclen = 0; |
| 6582 | |
| 6583 | /* Validate firmware image by checking version. */ |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6584 | if (blob->fw->size < 8 * sizeof(uint32_t)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6585 | ql_log(ql_log_fatal, vha, 0x0093, |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 6586 | "Unable to verify integrity of firmware image (%zd).\n", |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6587 | blob->fw->size); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6588 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6589 | } |
| 6590 | for (i = 0; i < 4; i++) |
| 6591 | dcode[i] = be32_to_cpu(fwcode[i + 4]); |
| 6592 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 6593 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 6594 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 6595 | dcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6596 | ql_log(ql_log_fatal, vha, 0x0094, |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 6597 | "Unable to verify integrity of firmware image (%zd).\n", |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6598 | blob->fw->size); |
| 6599 | ql_log(ql_log_fatal, vha, 0x0095, |
| 6600 | "Firmware data: %08x %08x %08x %08x.\n", |
| 6601 | dcode[0], dcode[1], dcode[2], dcode[3]); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6602 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6603 | } |
| 6604 | |
| 6605 | while (segments && rval == QLA_SUCCESS) { |
| 6606 | risc_addr = be32_to_cpu(fwcode[2]); |
| 6607 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 6608 | risc_size = be32_to_cpu(fwcode[3]); |
| 6609 | |
| 6610 | /* Validate firmware image size. */ |
| 6611 | fwclen += risc_size * sizeof(uint32_t); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6612 | if (blob->fw->size < fwclen) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6613 | ql_log(ql_log_fatal, vha, 0x0096, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6614 | "Unable to verify integrity of firmware image " |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 6615 | "(%zd).\n", blob->fw->size); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6616 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6617 | } |
| 6618 | |
| 6619 | fragment = 0; |
| 6620 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 6621 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 6622 | if (dlen > risc_size) |
| 6623 | dlen = risc_size; |
| 6624 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6625 | ql_dbg(ql_dbg_init, vha, 0x0097, |
| 6626 | "Loading risc segment@ risc addr %x " |
| 6627 | "number of dwords 0x%x.\n", risc_addr, dlen); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6628 | |
| 6629 | for (i = 0; i < dlen; i++) |
| 6630 | dcode[i] = swab32(fwcode[i]); |
| 6631 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6632 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
andrew.vasquez@qlogic.com | 590f98e | 2006-01-13 17:05:37 -0800 | [diff] [blame] | 6633 | dlen); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6634 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6635 | ql_log(ql_log_fatal, vha, 0x0098, |
| 6636 | "Failed to load segment %d of firmware.\n", |
| 6637 | fragment); |
Chad Dupuis | f261f7a | 2014-09-25 05:17:03 -0400 | [diff] [blame] | 6638 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6639 | } |
| 6640 | |
| 6641 | fwcode += dlen; |
| 6642 | risc_addr += dlen; |
| 6643 | risc_size -= dlen; |
| 6644 | fragment++; |
| 6645 | } |
| 6646 | |
| 6647 | /* Next segment. */ |
| 6648 | segments--; |
| 6649 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6650 | |
| 6651 | if (!IS_QLA27XX(ha)) |
| 6652 | return rval; |
| 6653 | |
| 6654 | if (ha->fw_dump_template) |
| 6655 | vfree(ha->fw_dump_template); |
| 6656 | ha->fw_dump_template = NULL; |
| 6657 | ha->fw_dump_template_len = 0; |
| 6658 | |
| 6659 | ql_dbg(ql_dbg_init, vha, 0x171, |
Chad Dupuis | 97ea702 | 2014-03-13 14:16:40 -0400 | [diff] [blame] | 6660 | "Loading fwdump template from %x\n", |
| 6661 | (uint32_t)((void *)fwcode - (void *)blob->fw->data)); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6662 | risc_size = be32_to_cpu(fwcode[2]); |
| 6663 | ql_dbg(ql_dbg_init, vha, 0x172, |
| 6664 | "-> array size %x dwords\n", risc_size); |
| 6665 | if (risc_size == 0 || risc_size == ~0) |
| 6666 | goto default_template; |
| 6667 | |
| 6668 | dlen = (risc_size - 8) * sizeof(*fwcode); |
| 6669 | ql_dbg(ql_dbg_init, vha, 0x0173, |
| 6670 | "-> template allocating %x bytes...\n", dlen); |
| 6671 | ha->fw_dump_template = vmalloc(dlen); |
| 6672 | if (!ha->fw_dump_template) { |
| 6673 | ql_log(ql_log_warn, vha, 0x0174, |
| 6674 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 6675 | goto default_template; |
| 6676 | } |
| 6677 | |
| 6678 | fwcode += 7; |
| 6679 | risc_size -= 8; |
| 6680 | dcode = ha->fw_dump_template; |
| 6681 | for (i = 0; i < risc_size; i++) |
| 6682 | dcode[i] = le32_to_cpu(fwcode[i]); |
| 6683 | |
| 6684 | if (!qla27xx_fwdt_template_valid(dcode)) { |
| 6685 | ql_log(ql_log_warn, vha, 0x0175, |
| 6686 | "Failed fwdump template validate\n"); |
| 6687 | goto default_template; |
| 6688 | } |
| 6689 | |
| 6690 | dlen = qla27xx_fwdt_template_size(dcode); |
| 6691 | ql_dbg(ql_dbg_init, vha, 0x0176, |
| 6692 | "-> template size %x bytes\n", dlen); |
| 6693 | if (dlen > risc_size * sizeof(*fwcode)) { |
| 6694 | ql_log(ql_log_warn, vha, 0x0177, |
Chad Dupuis | 97ea702 | 2014-03-13 14:16:40 -0400 | [diff] [blame] | 6695 | "Failed fwdump template exceeds array by %x bytes\n", |
| 6696 | (uint32_t)(dlen - risc_size * sizeof(*fwcode))); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6697 | goto default_template; |
| 6698 | } |
| 6699 | ha->fw_dump_template_len = dlen; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6700 | return rval; |
| 6701 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6702 | default_template: |
| 6703 | ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n"); |
| 6704 | if (ha->fw_dump_template) |
| 6705 | vfree(ha->fw_dump_template); |
| 6706 | ha->fw_dump_template = NULL; |
| 6707 | ha->fw_dump_template_len = 0; |
| 6708 | |
| 6709 | dlen = qla27xx_fwdt_template_default_size(); |
| 6710 | ql_dbg(ql_dbg_init, vha, 0x0179, |
| 6711 | "-> template allocating %x bytes...\n", dlen); |
| 6712 | ha->fw_dump_template = vmalloc(dlen); |
| 6713 | if (!ha->fw_dump_template) { |
| 6714 | ql_log(ql_log_warn, vha, 0x017a, |
| 6715 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 6716 | goto failed_template; |
| 6717 | } |
| 6718 | |
| 6719 | dcode = ha->fw_dump_template; |
| 6720 | risc_size = dlen / sizeof(*fwcode); |
| 6721 | fwcode = qla27xx_fwdt_template_default(); |
| 6722 | for (i = 0; i < risc_size; i++) |
| 6723 | dcode[i] = be32_to_cpu(fwcode[i]); |
| 6724 | |
| 6725 | if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) { |
| 6726 | ql_log(ql_log_warn, vha, 0x017b, |
| 6727 | "Failed fwdump template validate\n"); |
| 6728 | goto failed_template; |
| 6729 | } |
| 6730 | |
| 6731 | dlen = qla27xx_fwdt_template_size(ha->fw_dump_template); |
| 6732 | ql_dbg(ql_dbg_init, vha, 0x017c, |
| 6733 | "-> template size %x bytes\n", dlen); |
| 6734 | ha->fw_dump_template_len = dlen; |
| 6735 | return rval; |
| 6736 | |
| 6737 | failed_template: |
| 6738 | ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n"); |
| 6739 | if (ha->fw_dump_template) |
| 6740 | vfree(ha->fw_dump_template); |
| 6741 | ha->fw_dump_template = NULL; |
| 6742 | ha->fw_dump_template_len = 0; |
| 6743 | return rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6744 | } |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6745 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6746 | int |
| 6747 | qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 6748 | { |
| 6749 | int rval; |
| 6750 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 6751 | if (ql2xfwloadbin == 1) |
| 6752 | return qla81xx_load_risc(vha, srisc_addr); |
| 6753 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6754 | /* |
| 6755 | * FW Load priority: |
| 6756 | * 1) Firmware via request-firmware interface (.bin file). |
| 6757 | * 2) Firmware residing in flash. |
| 6758 | */ |
| 6759 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 6760 | if (rval == QLA_SUCCESS) |
| 6761 | return rval; |
| 6762 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6763 | return qla24xx_load_risc_flash(vha, srisc_addr, |
| 6764 | vha->hw->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6765 | } |
| 6766 | |
| 6767 | int |
| 6768 | qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 6769 | { |
| 6770 | int rval; |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6771 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6772 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 6773 | if (ql2xfwloadbin == 2) |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6774 | goto try_blob_fw; |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 6775 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6776 | /* |
| 6777 | * FW Load priority: |
| 6778 | * 1) Firmware residing in flash. |
| 6779 | * 2) Firmware via request-firmware interface (.bin file). |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6780 | * 3) Golden-Firmware residing in flash -- limited operation. |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6781 | */ |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6782 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6783 | if (rval == QLA_SUCCESS) |
| 6784 | return rval; |
| 6785 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6786 | try_blob_fw: |
| 6787 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 6788 | if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw) |
| 6789 | return rval; |
| 6790 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6791 | ql_log(ql_log_info, vha, 0x0099, |
| 6792 | "Attempting to fallback to golden firmware.\n"); |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6793 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw); |
| 6794 | if (rval != QLA_SUCCESS) |
| 6795 | return rval; |
| 6796 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6797 | ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n"); |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6798 | ha->flags.running_gold_fw = 1; |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6799 | return rval; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6800 | } |
| 6801 | |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6802 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6803 | qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6804 | { |
| 6805 | int ret, retries; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6806 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6807 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 6808 | if (ha->flags.pci_channel_io_perm_failure) |
| 6809 | return; |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 6810 | if (!IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6811 | return; |
Andrew Vasquez | 75edf81 | 2007-05-07 07:43:00 -0700 | [diff] [blame] | 6812 | if (!ha->fw_major_version) |
| 6813 | return; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6814 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6815 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 7c7f1f2 | 2008-02-28 14:06:09 -0800 | [diff] [blame] | 6816 | for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT && |
Andrew Vasquez | b469a7c | 2009-04-06 22:33:48 -0700 | [diff] [blame] | 6817 | ret != QLA_INVALID_COMMAND && retries ; retries--) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6818 | ha->isp_ops->reset_chip(vha); |
| 6819 | if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6820 | continue; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6821 | if (qla2x00_setup_chip(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6822 | continue; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6823 | ql_log(ql_log_info, vha, 0x8015, |
| 6824 | "Attempting retry of stop-firmware command.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6825 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6826 | } |
| 6827 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6828 | |
| 6829 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6830 | qla24xx_configure_vhba(scsi_qla_host_t *vha) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6831 | { |
| 6832 | int rval = QLA_SUCCESS; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 6833 | int rval2; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6834 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6835 | struct qla_hw_data *ha = vha->hw; |
| 6836 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 6837 | struct req_que *req; |
| 6838 | struct rsp_que *rsp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6839 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6840 | if (!vha->vp_idx) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6841 | return -EINVAL; |
| 6842 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6843 | rval = qla2x00_fw_ready(base_vha); |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 6844 | if (vha->qpair) |
| 6845 | req = vha->qpair->req; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 6846 | else |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 6847 | req = ha->req_q_map[0]; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 6848 | rsp = req->rsp; |
| 6849 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6850 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6851 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6852 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6853 | } |
| 6854 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6855 | vha->flags.management_server_logged_in = 0; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6856 | |
| 6857 | /* Login to SNS first */ |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 6858 | rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, |
| 6859 | BIT_1); |
| 6860 | if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) { |
| 6861 | if (rval2 == QLA_MEMORY_ALLOC_FAILED) |
| 6862 | ql_dbg(ql_dbg_init, vha, 0x0120, |
| 6863 | "Failed SNS login: loop_id=%x, rval2=%d\n", |
| 6864 | NPH_SNS, rval2); |
| 6865 | else |
| 6866 | ql_dbg(ql_dbg_init, vha, 0x0103, |
| 6867 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x " |
| 6868 | "mb[2]=%x mb[6]=%x mb[7]=%x.\n", |
| 6869 | NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6870 | return (QLA_FUNCTION_FAILED); |
| 6871 | } |
| 6872 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6873 | atomic_set(&vha->loop_down_timer, 0); |
| 6874 | atomic_set(&vha->loop_state, LOOP_UP); |
| 6875 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 6876 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 6877 | rval = qla2x00_loop_resync(base_vha); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6878 | |
| 6879 | return rval; |
| 6880 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6881 | |
| 6882 | /* 84XX Support **************************************************************/ |
| 6883 | |
| 6884 | static LIST_HEAD(qla_cs84xx_list); |
| 6885 | static DEFINE_MUTEX(qla_cs84xx_mutex); |
| 6886 | |
| 6887 | static struct qla_chip_state_84xx * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6888 | qla84xx_get_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6889 | { |
| 6890 | struct qla_chip_state_84xx *cs84xx; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6891 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6892 | |
| 6893 | mutex_lock(&qla_cs84xx_mutex); |
| 6894 | |
| 6895 | /* Find any shared 84xx chip. */ |
| 6896 | list_for_each_entry(cs84xx, &qla_cs84xx_list, list) { |
| 6897 | if (cs84xx->bus == ha->pdev->bus) { |
| 6898 | kref_get(&cs84xx->kref); |
| 6899 | goto done; |
| 6900 | } |
| 6901 | } |
| 6902 | |
| 6903 | cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL); |
| 6904 | if (!cs84xx) |
| 6905 | goto done; |
| 6906 | |
| 6907 | kref_init(&cs84xx->kref); |
| 6908 | spin_lock_init(&cs84xx->access_lock); |
| 6909 | mutex_init(&cs84xx->fw_update_mutex); |
| 6910 | cs84xx->bus = ha->pdev->bus; |
| 6911 | |
| 6912 | list_add_tail(&cs84xx->list, &qla_cs84xx_list); |
| 6913 | done: |
| 6914 | mutex_unlock(&qla_cs84xx_mutex); |
| 6915 | return cs84xx; |
| 6916 | } |
| 6917 | |
| 6918 | static void |
| 6919 | __qla84xx_chip_release(struct kref *kref) |
| 6920 | { |
| 6921 | struct qla_chip_state_84xx *cs84xx = |
| 6922 | container_of(kref, struct qla_chip_state_84xx, kref); |
| 6923 | |
| 6924 | mutex_lock(&qla_cs84xx_mutex); |
| 6925 | list_del(&cs84xx->list); |
| 6926 | mutex_unlock(&qla_cs84xx_mutex); |
| 6927 | kfree(cs84xx); |
| 6928 | } |
| 6929 | |
| 6930 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6931 | qla84xx_put_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6932 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6933 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6934 | if (ha->cs84xx) |
| 6935 | kref_put(&ha->cs84xx->kref, __qla84xx_chip_release); |
| 6936 | } |
| 6937 | |
| 6938 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6939 | qla84xx_init_chip(scsi_qla_host_t *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6940 | { |
| 6941 | int rval; |
| 6942 | uint16_t status[2]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6943 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6944 | |
| 6945 | mutex_lock(&ha->cs84xx->fw_update_mutex); |
| 6946 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6947 | rval = qla84xx_verify_chip(vha, status); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6948 | |
| 6949 | mutex_unlock(&ha->cs84xx->fw_update_mutex); |
| 6950 | |
| 6951 | return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED: |
| 6952 | QLA_SUCCESS; |
| 6953 | } |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6954 | |
| 6955 | /* 81XX Support **************************************************************/ |
| 6956 | |
| 6957 | int |
| 6958 | qla81xx_nvram_config(scsi_qla_host_t *vha) |
| 6959 | { |
| 6960 | int rval; |
| 6961 | struct init_cb_81xx *icb; |
| 6962 | struct nvram_81xx *nv; |
| 6963 | uint32_t *dptr; |
| 6964 | uint8_t *dptr1, *dptr2; |
| 6965 | uint32_t chksum; |
| 6966 | uint16_t cnt; |
| 6967 | struct qla_hw_data *ha = vha->hw; |
| 6968 | |
| 6969 | rval = QLA_SUCCESS; |
| 6970 | icb = (struct init_cb_81xx *)ha->init_cb; |
| 6971 | nv = ha->nvram; |
| 6972 | |
| 6973 | /* Determine NVRAM starting address. */ |
| 6974 | ha->nvram_size = sizeof(struct nvram_81xx); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6975 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 6976 | if (IS_P3P_TYPE(ha) || IS_QLA8031(ha)) |
| 6977 | ha->vpd_size = FA_VPD_SIZE_82XX; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6978 | |
| 6979 | /* Get VPD data into cache */ |
| 6980 | ha->vpd = ha->nvram + VPD_OFFSET; |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 6981 | ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2, |
| 6982 | ha->vpd_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6983 | |
| 6984 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 6985 | 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] | 6986 | ha->nvram_size); |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 6987 | dptr = (uint32_t *)nv; |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 6988 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++) |
| 6989 | chksum += le32_to_cpu(*dptr); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6990 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6991 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111, |
| 6992 | "Contents of NVRAM:\n"); |
| 6993 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112, |
| 6994 | (uint8_t *)nv, ha->nvram_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6995 | |
| 6996 | /* Bad NVRAM data, set defaults parameters. */ |
| 6997 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 6998 | || nv->id[3] != ' ' || |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6999 | nv->nvram_version < cpu_to_le16(ICB_VERSION)) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7000 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7001 | ql_log(ql_log_info, vha, 0x0073, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 7002 | "Inconsistent NVRAM detected: checksum=0x%x id=%c " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7003 | "version=0x%x.\n", chksum, nv->id[0], |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7004 | le16_to_cpu(nv->nvram_version)); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7005 | ql_log(ql_log_info, vha, 0x0074, |
| 7006 | "Falling back to functioning (yet invalid -- WWPN) " |
| 7007 | "defaults.\n"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7008 | |
| 7009 | /* |
| 7010 | * Set default initialization control block. |
| 7011 | */ |
| 7012 | memset(nv, 0, ha->nvram_size); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7013 | nv->nvram_version = cpu_to_le16(ICB_VERSION); |
| 7014 | nv->version = cpu_to_le16(ICB_VERSION); |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 7015 | nv->frame_payload_size = 2048; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7016 | nv->execution_throttle = cpu_to_le16(0xFFFF); |
| 7017 | nv->exchange_count = cpu_to_le16(0); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7018 | nv->port_name[0] = 0x21; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7019 | nv->port_name[1] = 0x00 + ha->port_no + 1; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7020 | nv->port_name[2] = 0x00; |
| 7021 | nv->port_name[3] = 0xe0; |
| 7022 | nv->port_name[4] = 0x8b; |
| 7023 | nv->port_name[5] = 0x1c; |
| 7024 | nv->port_name[6] = 0x55; |
| 7025 | nv->port_name[7] = 0x86; |
| 7026 | nv->node_name[0] = 0x20; |
| 7027 | nv->node_name[1] = 0x00; |
| 7028 | nv->node_name[2] = 0x00; |
| 7029 | nv->node_name[3] = 0xe0; |
| 7030 | nv->node_name[4] = 0x8b; |
| 7031 | nv->node_name[5] = 0x1c; |
| 7032 | nv->node_name[6] = 0x55; |
| 7033 | nv->node_name[7] = 0x86; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7034 | nv->login_retry_count = cpu_to_le16(8); |
| 7035 | nv->interrupt_delay_timer = cpu_to_le16(0); |
| 7036 | nv->login_timeout = cpu_to_le16(0); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7037 | nv->firmware_options_1 = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7038 | cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 7039 | nv->firmware_options_2 = cpu_to_le32(2 << 4); |
| 7040 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 7041 | nv->firmware_options_3 = cpu_to_le32(2 << 13); |
| 7042 | nv->host_p = cpu_to_le32(BIT_11|BIT_10); |
| 7043 | nv->efi_parameters = cpu_to_le32(0); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7044 | nv->reset_delay = 5; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7045 | nv->max_luns_per_target = cpu_to_le16(128); |
| 7046 | nv->port_down_retry_count = cpu_to_le16(30); |
| 7047 | nv->link_down_timeout = cpu_to_le16(180); |
Andrew Vasquez | eeebcc9 | 2009-06-03 09:55:24 -0700 | [diff] [blame] | 7048 | nv->enode_mac[0] = 0x00; |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 7049 | nv->enode_mac[1] = 0xC0; |
| 7050 | nv->enode_mac[2] = 0xDD; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7051 | nv->enode_mac[3] = 0x04; |
| 7052 | nv->enode_mac[4] = 0x05; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7053 | nv->enode_mac[5] = 0x06 + ha->port_no + 1; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7054 | |
| 7055 | rval = 1; |
| 7056 | } |
| 7057 | |
Arun Easi | 9e522cd | 2012-08-22 14:21:31 -0400 | [diff] [blame] | 7058 | if (IS_T10_PI_CAPABLE(ha)) |
| 7059 | nv->frame_payload_size &= ~7; |
| 7060 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7061 | qlt_81xx_config_nvram_stage1(vha, nv); |
| 7062 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7063 | /* Reset Initialization control block */ |
Andrew Vasquez | 773120e | 2011-05-10 11:30:14 -0700 | [diff] [blame] | 7064 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7065 | |
| 7066 | /* Copy 1st segment. */ |
| 7067 | dptr1 = (uint8_t *)icb; |
| 7068 | dptr2 = (uint8_t *)&nv->version; |
| 7069 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 7070 | while (cnt--) |
| 7071 | *dptr1++ = *dptr2++; |
| 7072 | |
| 7073 | icb->login_retry_count = nv->login_retry_count; |
| 7074 | |
| 7075 | /* Copy 2nd segment. */ |
| 7076 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 7077 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 7078 | cnt = (uint8_t *)&icb->reserved_5 - |
| 7079 | (uint8_t *)&icb->interrupt_delay_timer; |
| 7080 | while (cnt--) |
| 7081 | *dptr1++ = *dptr2++; |
| 7082 | |
| 7083 | memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac)); |
| 7084 | /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */ |
| 7085 | 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] | 7086 | icb->enode_mac[0] = 0x00; |
| 7087 | icb->enode_mac[1] = 0xC0; |
| 7088 | icb->enode_mac[2] = 0xDD; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7089 | icb->enode_mac[3] = 0x04; |
| 7090 | icb->enode_mac[4] = 0x05; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7091 | icb->enode_mac[5] = 0x06 + ha->port_no + 1; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7092 | } |
| 7093 | |
Andrew Vasquez | b64b0e8 | 2009-03-24 09:08:01 -0700 | [diff] [blame] | 7094 | /* Use extended-initialization control block. */ |
| 7095 | memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb)); |
| 7096 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7097 | /* |
| 7098 | * Setup driver NVRAM options. |
| 7099 | */ |
| 7100 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7101 | "QLE8XXX"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7102 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7103 | qlt_81xx_config_nvram_stage2(vha, icb); |
| 7104 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7105 | /* Use alternate WWN? */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7106 | if (nv->host_p & cpu_to_le32(BIT_15)) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7107 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 7108 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 7109 | } |
| 7110 | |
| 7111 | /* Prepare nodename */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7112 | if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7113 | /* |
| 7114 | * Firmware will apply the following mask if the nodename was |
| 7115 | * not provided. |
| 7116 | */ |
| 7117 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 7118 | icb->node_name[0] &= 0xF0; |
| 7119 | } |
| 7120 | |
| 7121 | /* Set host adapter parameters. */ |
| 7122 | ha->flags.disable_risc_code_load = 0; |
| 7123 | ha->flags.enable_lip_reset = 0; |
| 7124 | ha->flags.enable_lip_full_login = |
| 7125 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 7126 | ha->flags.enable_target_reset = |
| 7127 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
| 7128 | ha->flags.enable_led_scheme = 0; |
| 7129 | ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0; |
| 7130 | |
| 7131 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 7132 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 7133 | |
| 7134 | /* save HBA serial number */ |
| 7135 | ha->serial0 = icb->port_name[5]; |
| 7136 | ha->serial1 = icb->port_name[6]; |
| 7137 | ha->serial2 = icb->port_name[7]; |
| 7138 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 7139 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
| 7140 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7141 | icb->execution_throttle = cpu_to_le16(0xFFFF); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7142 | |
| 7143 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 7144 | |
| 7145 | /* Set minimum login_timeout to 4 seconds. */ |
| 7146 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 7147 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 7148 | if (le16_to_cpu(nv->login_timeout) < 4) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7149 | nv->login_timeout = cpu_to_le16(4); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7150 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7151 | |
| 7152 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 7153 | ha->r_a_tov = 100; |
| 7154 | |
| 7155 | ha->loop_reset_delay = nv->reset_delay; |
| 7156 | |
| 7157 | /* Link Down Timeout = 0: |
| 7158 | * |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 7159 | * When Port Down timer expires we will start returning |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7160 | * I/O's to OS with "DID_NO_CONNECT". |
| 7161 | * |
| 7162 | * Link Down Timeout != 0: |
| 7163 | * |
| 7164 | * The driver waits for the link to come up after link down |
| 7165 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 7166 | */ |
| 7167 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 7168 | ha->loop_down_abort_time = |
| 7169 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 7170 | } else { |
| 7171 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 7172 | ha->loop_down_abort_time = |
| 7173 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 7174 | } |
| 7175 | |
| 7176 | /* Need enough time to try and get the port back. */ |
| 7177 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 7178 | if (qlport_down_retry) |
| 7179 | ha->port_down_retry_count = qlport_down_retry; |
| 7180 | |
| 7181 | /* Set login_retry_count */ |
| 7182 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 7183 | if (ha->port_down_retry_count == |
| 7184 | le16_to_cpu(nv->port_down_retry_count) && |
| 7185 | ha->port_down_retry_count > 3) |
| 7186 | ha->login_retry_count = ha->port_down_retry_count; |
| 7187 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 7188 | ha->login_retry_count = ha->port_down_retry_count; |
| 7189 | if (ql2xloginretrycount) |
| 7190 | ha->login_retry_count = ql2xloginretrycount; |
| 7191 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 7192 | /* if not running MSI-X we need handshaking on interrupts */ |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7193 | 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] | 7194 | icb->firmware_options_2 |= cpu_to_le32(BIT_22); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 7195 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7196 | /* Enable ZIO. */ |
| 7197 | if (!vha->flags.init_done) { |
| 7198 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 7199 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 7200 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 7201 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 7202 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7203 | icb->firmware_options_2 &= cpu_to_le32( |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7204 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
| 7205 | vha->flags.process_response_queue = 0; |
| 7206 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
| 7207 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 7208 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7209 | ql_log(ql_log_info, vha, 0x0075, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7210 | "ZIO mode %d enabled; timer delay (%d us).\n", |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7211 | ha->zio_mode, |
| 7212 | ha->zio_timer * 100); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7213 | |
| 7214 | icb->firmware_options_2 |= cpu_to_le32( |
| 7215 | (uint32_t)ha->zio_mode); |
| 7216 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
| 7217 | vha->flags.process_response_queue = 1; |
| 7218 | } |
| 7219 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 7220 | /* enable RIDA Format2 */ |
| 7221 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) |
| 7222 | icb->firmware_options_3 |= BIT_0; |
| 7223 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7224 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7225 | ql_log(ql_log_warn, vha, 0x0076, |
| 7226 | "NVRAM configuration failed.\n"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7227 | } |
| 7228 | return (rval); |
| 7229 | } |
| 7230 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7231 | int |
| 7232 | qla82xx_restart_isp(scsi_qla_host_t *vha) |
| 7233 | { |
| 7234 | int status, rval; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7235 | struct qla_hw_data *ha = vha->hw; |
| 7236 | struct req_que *req = ha->req_q_map[0]; |
| 7237 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
| 7238 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 7239 | unsigned long flags; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7240 | |
| 7241 | status = qla2x00_init_rings(vha); |
| 7242 | if (!status) { |
| 7243 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 7244 | ha->flags.chip_reset_done = 1; |
| 7245 | |
| 7246 | status = qla2x00_fw_ready(vha); |
| 7247 | if (!status) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7248 | /* Issue a marker after FW becomes ready. */ |
| 7249 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7250 | vha->flags.online = 1; |
Chad Dupuis | 7108b76 | 2014-04-11 16:54:45 -0400 | [diff] [blame] | 7251 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7252 | } |
| 7253 | |
| 7254 | /* if no cable then assume it's good */ |
| 7255 | if ((vha->device_flags & DFLG_NO_CABLE)) |
| 7256 | status = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7257 | } |
| 7258 | |
| 7259 | if (!status) { |
| 7260 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 7261 | |
| 7262 | if (!atomic_read(&vha->loop_down_timer)) { |
| 7263 | /* |
| 7264 | * Issue marker command only when we are going |
| 7265 | * to start the I/O . |
| 7266 | */ |
| 7267 | vha->marker_needed = 1; |
| 7268 | } |
| 7269 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7270 | ha->isp_ops->enable_intrs(ha); |
| 7271 | |
| 7272 | ha->isp_abort_cnt = 0; |
| 7273 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 7274 | |
Saurav Kashyap | 5329678 | 2011-05-10 11:30:06 -0700 | [diff] [blame] | 7275 | /* Update the firmware version */ |
Giridhar Malavali | 3173167 | 2011-08-16 11:31:54 -0700 | [diff] [blame] | 7276 | status = qla82xx_check_md_needed(vha); |
Saurav Kashyap | 5329678 | 2011-05-10 11:30:06 -0700 | [diff] [blame] | 7277 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7278 | if (ha->fce) { |
| 7279 | ha->flags.fce_enabled = 1; |
| 7280 | memset(ha->fce, 0, |
| 7281 | fce_calc_size(ha->fce_bufs)); |
| 7282 | rval = qla2x00_enable_fce_trace(vha, |
| 7283 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 7284 | &ha->fce_bufs); |
| 7285 | if (rval) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7286 | ql_log(ql_log_warn, vha, 0x8001, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7287 | "Unable to reinitialize FCE (%d).\n", |
| 7288 | rval); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7289 | ha->flags.fce_enabled = 0; |
| 7290 | } |
| 7291 | } |
| 7292 | |
| 7293 | if (ha->eft) { |
| 7294 | memset(ha->eft, 0, EFT_SIZE); |
| 7295 | rval = qla2x00_enable_eft_trace(vha, |
| 7296 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 7297 | if (rval) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7298 | ql_log(ql_log_warn, vha, 0x8010, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7299 | "Unable to reinitialize EFT (%d).\n", |
| 7300 | rval); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7301 | } |
| 7302 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7303 | } |
| 7304 | |
| 7305 | if (!status) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7306 | ql_dbg(ql_dbg_taskm, vha, 0x8011, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7307 | "qla82xx_restart_isp succeeded.\n"); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 7308 | |
| 7309 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 7310 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 7311 | if (vp->vp_idx) { |
| 7312 | atomic_inc(&vp->vref_count); |
| 7313 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 7314 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7315 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 7316 | |
| 7317 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 7318 | atomic_dec(&vp->vref_count); |
| 7319 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7320 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 7321 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 7322 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7323 | } else { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7324 | ql_log(ql_log_warn, vha, 0x8016, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7325 | "qla82xx_restart_isp **** FAILED ****.\n"); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7326 | } |
| 7327 | |
| 7328 | return status; |
| 7329 | } |
| 7330 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7331 | void |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 7332 | qla81xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7333 | { |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 7334 | struct qla_hw_data *ha = vha->hw; |
| 7335 | |
Himanshu Madhani | f198caf | 2016-01-27 12:03:30 -0500 | [diff] [blame] | 7336 | /* Hold status IOCBs until ABTS response received. */ |
| 7337 | if (ql2xfwholdabts) |
| 7338 | ha->fw_options[3] |= BIT_12; |
| 7339 | |
Giridhar Malavali | 088d09d | 2016-07-06 11:14:20 -0400 | [diff] [blame] | 7340 | /* Set Retry FLOGI in case of P2P connection */ |
| 7341 | if (ha->operating_mode == P2P) { |
| 7342 | ha->fw_options[2] |= BIT_3; |
| 7343 | ql_dbg(ql_dbg_disc, vha, 0x2103, |
| 7344 | "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n", |
| 7345 | __func__, ha->fw_options[2]); |
| 7346 | } |
| 7347 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 7348 | /* Move PUREX, ABTS RX & RIDA to ATIOQ */ |
| 7349 | if (ql2xmvasynctoatio) { |
| 7350 | if (qla_tgt_mode_enabled(vha) || |
| 7351 | qla_dual_mode_enabled(vha)) |
| 7352 | ha->fw_options[2] |= BIT_11; |
| 7353 | else |
| 7354 | ha->fw_options[2] &= ~BIT_11; |
| 7355 | } |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 7356 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 7357 | if (ql2xetsenable) { |
| 7358 | /* Enable ETS Burst. */ |
| 7359 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
| 7360 | ha->fw_options[2] |= BIT_9; |
| 7361 | } |
| 7362 | |
| 7363 | ql_dbg(ql_dbg_init, vha, 0xffff, |
| 7364 | "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n", |
| 7365 | __func__, ha->fw_options[1], ha->fw_options[2], |
| 7366 | ha->fw_options[3], vha->host->active_mode); |
| 7367 | |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 7368 | qla2x00_set_fw_options(vha, ha->fw_options); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7369 | } |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7370 | |
| 7371 | /* |
| 7372 | * qla24xx_get_fcp_prio |
| 7373 | * Gets the fcp cmd priority value for the logged in port. |
| 7374 | * Looks for a match of the port descriptors within |
| 7375 | * each of the fcp prio config entries. If a match is found, |
| 7376 | * the tag (priority) value is returned. |
| 7377 | * |
| 7378 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 7379 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7380 | * fcport = port structure pointer. |
| 7381 | * |
| 7382 | * Return: |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 7383 | * non-zero (if found) |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7384 | * -1 (if not found) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7385 | * |
| 7386 | * Context: |
| 7387 | * Kernel context |
| 7388 | */ |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7389 | static int |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7390 | qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 7391 | { |
| 7392 | int i, entries; |
| 7393 | uint8_t pid_match, wwn_match; |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7394 | int priority; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7395 | uint32_t pid1, pid2; |
| 7396 | uint64_t wwn1, wwn2; |
| 7397 | struct qla_fcp_prio_entry *pri_entry; |
| 7398 | struct qla_hw_data *ha = vha->hw; |
| 7399 | |
| 7400 | if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled) |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7401 | return -1; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7402 | |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7403 | priority = -1; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7404 | entries = ha->fcp_prio_cfg->num_entries; |
| 7405 | pri_entry = &ha->fcp_prio_cfg->entry[0]; |
| 7406 | |
| 7407 | for (i = 0; i < entries; i++) { |
| 7408 | pid_match = wwn_match = 0; |
| 7409 | |
| 7410 | if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) { |
| 7411 | pri_entry++; |
| 7412 | continue; |
| 7413 | } |
| 7414 | |
| 7415 | /* check source pid for a match */ |
| 7416 | if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) { |
| 7417 | pid1 = pri_entry->src_pid & INVALID_PORT_ID; |
| 7418 | pid2 = vha->d_id.b24 & INVALID_PORT_ID; |
| 7419 | if (pid1 == INVALID_PORT_ID) |
| 7420 | pid_match++; |
| 7421 | else if (pid1 == pid2) |
| 7422 | pid_match++; |
| 7423 | } |
| 7424 | |
| 7425 | /* check destination pid for a match */ |
| 7426 | if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) { |
| 7427 | pid1 = pri_entry->dst_pid & INVALID_PORT_ID; |
| 7428 | pid2 = fcport->d_id.b24 & INVALID_PORT_ID; |
| 7429 | if (pid1 == INVALID_PORT_ID) |
| 7430 | pid_match++; |
| 7431 | else if (pid1 == pid2) |
| 7432 | pid_match++; |
| 7433 | } |
| 7434 | |
| 7435 | /* check source WWN for a match */ |
| 7436 | if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) { |
| 7437 | wwn1 = wwn_to_u64(vha->port_name); |
| 7438 | wwn2 = wwn_to_u64(pri_entry->src_wwpn); |
| 7439 | if (wwn2 == (uint64_t)-1) |
| 7440 | wwn_match++; |
| 7441 | else if (wwn1 == wwn2) |
| 7442 | wwn_match++; |
| 7443 | } |
| 7444 | |
| 7445 | /* check destination WWN for a match */ |
| 7446 | if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) { |
| 7447 | wwn1 = wwn_to_u64(fcport->port_name); |
| 7448 | wwn2 = wwn_to_u64(pri_entry->dst_wwpn); |
| 7449 | if (wwn2 == (uint64_t)-1) |
| 7450 | wwn_match++; |
| 7451 | else if (wwn1 == wwn2) |
| 7452 | wwn_match++; |
| 7453 | } |
| 7454 | |
| 7455 | if (pid_match == 2 || wwn_match == 2) { |
| 7456 | /* Found a matching entry */ |
| 7457 | if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID) |
| 7458 | priority = pri_entry->tag; |
| 7459 | break; |
| 7460 | } |
| 7461 | |
| 7462 | pri_entry++; |
| 7463 | } |
| 7464 | |
| 7465 | return priority; |
| 7466 | } |
| 7467 | |
| 7468 | /* |
| 7469 | * qla24xx_update_fcport_fcp_prio |
| 7470 | * Activates fcp priority for the logged in fc port |
| 7471 | * |
| 7472 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 7473 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7474 | * fcp = port structure pointer. |
| 7475 | * |
| 7476 | * Return: |
| 7477 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 7478 | * |
| 7479 | * Context: |
| 7480 | * Kernel context. |
| 7481 | */ |
| 7482 | int |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 7483 | 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] | 7484 | { |
| 7485 | int ret; |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7486 | int priority; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7487 | uint16_t mb[5]; |
| 7488 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 7489 | if (fcport->port_type != FCT_TARGET || |
| 7490 | fcport->loop_id == FC_NO_LOOP_ID) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7491 | return QLA_FUNCTION_FAILED; |
| 7492 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 7493 | priority = qla24xx_get_fcp_prio(vha, fcport); |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7494 | if (priority < 0) |
| 7495 | return QLA_FUNCTION_FAILED; |
| 7496 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 7497 | if (IS_P3P_TYPE(vha->hw)) { |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 7498 | fcport->fcp_prio = priority & 0xf; |
| 7499 | return QLA_SUCCESS; |
| 7500 | } |
| 7501 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 7502 | ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb); |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7503 | if (ret == QLA_SUCCESS) { |
| 7504 | if (fcport->fcp_prio != priority) |
| 7505 | ql_dbg(ql_dbg_user, vha, 0x709e, |
| 7506 | "Updated FCP_CMND priority - value=%d loop_id=%d " |
| 7507 | "port_id=%02x%02x%02x.\n", priority, |
| 7508 | fcport->loop_id, fcport->d_id.b.domain, |
| 7509 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 7510 | fcport->fcp_prio = priority & 0xf; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7511 | } else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7512 | ql_dbg(ql_dbg_user, vha, 0x704f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7513 | "Unable to update FCP_CMND priority - ret=0x%x for " |
| 7514 | "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id, |
| 7515 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 7516 | fcport->d_id.b.al_pa); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7517 | return ret; |
| 7518 | } |
| 7519 | |
| 7520 | /* |
| 7521 | * qla24xx_update_all_fcp_prio |
| 7522 | * Activates fcp priority for all the logged in ports |
| 7523 | * |
| 7524 | * Input: |
| 7525 | * ha = adapter block pointer. |
| 7526 | * |
| 7527 | * Return: |
| 7528 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 7529 | * |
| 7530 | * Context: |
| 7531 | * Kernel context. |
| 7532 | */ |
| 7533 | int |
| 7534 | qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha) |
| 7535 | { |
| 7536 | int ret; |
| 7537 | fc_port_t *fcport; |
| 7538 | |
| 7539 | ret = QLA_FUNCTION_FAILED; |
| 7540 | /* We need to set priority for all logged in ports */ |
| 7541 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 7542 | ret = qla24xx_update_fcport_fcp_prio(vha, fcport); |
| 7543 | |
| 7544 | return ret; |
| 7545 | } |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7546 | |
| 7547 | struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos, int vp_idx) |
| 7548 | { |
| 7549 | int rsp_id = 0; |
| 7550 | int req_id = 0; |
| 7551 | int i; |
| 7552 | struct qla_hw_data *ha = vha->hw; |
| 7553 | uint16_t qpair_id = 0; |
| 7554 | struct qla_qpair *qpair = NULL; |
| 7555 | struct qla_msix_entry *msix; |
| 7556 | |
| 7557 | if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) { |
| 7558 | ql_log(ql_log_warn, vha, 0x00181, |
| 7559 | "FW/Driver is not multi-queue capable.\n"); |
| 7560 | return NULL; |
| 7561 | } |
| 7562 | |
| 7563 | if (ql2xmqsupport) { |
| 7564 | qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL); |
| 7565 | if (qpair == NULL) { |
| 7566 | ql_log(ql_log_warn, vha, 0x0182, |
| 7567 | "Failed to allocate memory for queue pair.\n"); |
| 7568 | return NULL; |
| 7569 | } |
| 7570 | memset(qpair, 0, sizeof(struct qla_qpair)); |
| 7571 | |
| 7572 | qpair->hw = vha->hw; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 7573 | qpair->vha = vha; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7574 | |
| 7575 | /* Assign available que pair id */ |
| 7576 | mutex_lock(&ha->mq_lock); |
| 7577 | qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs); |
| 7578 | if (qpair_id >= ha->max_qpairs) { |
| 7579 | mutex_unlock(&ha->mq_lock); |
| 7580 | ql_log(ql_log_warn, vha, 0x0183, |
| 7581 | "No resources to create additional q pair.\n"); |
| 7582 | goto fail_qid_map; |
| 7583 | } |
| 7584 | set_bit(qpair_id, ha->qpair_qid_map); |
| 7585 | ha->queue_pair_map[qpair_id] = qpair; |
| 7586 | qpair->id = qpair_id; |
| 7587 | qpair->vp_idx = vp_idx; |
| 7588 | |
| 7589 | for (i = 0; i < ha->msix_count; i++) { |
Quinn Tran | 093df73 | 2016-12-12 14:40:09 -0800 | [diff] [blame] | 7590 | msix = &ha->msix_entries[i]; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7591 | if (msix->in_use) |
| 7592 | continue; |
| 7593 | qpair->msix = msix; |
| 7594 | ql_log(ql_dbg_multiq, vha, 0xc00f, |
| 7595 | "Vector %x selected for qpair\n", msix->vector); |
| 7596 | break; |
| 7597 | } |
| 7598 | if (!qpair->msix) { |
| 7599 | ql_log(ql_log_warn, vha, 0x0184, |
| 7600 | "Out of MSI-X vectors!.\n"); |
| 7601 | goto fail_msix; |
| 7602 | } |
| 7603 | |
| 7604 | qpair->msix->in_use = 1; |
| 7605 | list_add_tail(&qpair->qp_list_elem, &vha->qp_list); |
| 7606 | |
| 7607 | mutex_unlock(&ha->mq_lock); |
| 7608 | |
| 7609 | /* Create response queue first */ |
| 7610 | rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair); |
| 7611 | if (!rsp_id) { |
| 7612 | ql_log(ql_log_warn, vha, 0x0185, |
| 7613 | "Failed to create response queue.\n"); |
| 7614 | goto fail_rsp; |
| 7615 | } |
| 7616 | |
| 7617 | qpair->rsp = ha->rsp_q_map[rsp_id]; |
| 7618 | |
| 7619 | /* Create request queue */ |
| 7620 | req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos); |
| 7621 | if (!req_id) { |
| 7622 | ql_log(ql_log_warn, vha, 0x0186, |
| 7623 | "Failed to create request queue.\n"); |
| 7624 | goto fail_req; |
| 7625 | } |
| 7626 | |
| 7627 | qpair->req = ha->req_q_map[req_id]; |
| 7628 | qpair->rsp->req = qpair->req; |
| 7629 | |
| 7630 | if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) { |
| 7631 | if (ha->fw_attributes & BIT_4) |
| 7632 | qpair->difdix_supported = 1; |
| 7633 | } |
| 7634 | |
| 7635 | qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep); |
| 7636 | if (!qpair->srb_mempool) { |
| 7637 | ql_log(ql_log_warn, vha, 0x0191, |
| 7638 | "Failed to create srb mempool for qpair %d\n", |
| 7639 | qpair->id); |
| 7640 | goto fail_mempool; |
| 7641 | } |
| 7642 | |
| 7643 | /* Mark as online */ |
| 7644 | qpair->online = 1; |
| 7645 | |
| 7646 | if (!vha->flags.qpairs_available) |
| 7647 | vha->flags.qpairs_available = 1; |
| 7648 | |
| 7649 | ql_dbg(ql_dbg_multiq, vha, 0xc00d, |
| 7650 | "Request/Response queue pair created, id %d\n", |
| 7651 | qpair->id); |
| 7652 | ql_dbg(ql_dbg_init, vha, 0x0187, |
| 7653 | "Request/Response queue pair created, id %d\n", |
| 7654 | qpair->id); |
| 7655 | } |
| 7656 | return qpair; |
| 7657 | |
| 7658 | fail_mempool: |
| 7659 | fail_req: |
| 7660 | qla25xx_delete_rsp_que(vha, qpair->rsp); |
| 7661 | fail_rsp: |
| 7662 | mutex_lock(&ha->mq_lock); |
| 7663 | qpair->msix->in_use = 0; |
| 7664 | list_del(&qpair->qp_list_elem); |
| 7665 | if (list_empty(&vha->qp_list)) |
| 7666 | vha->flags.qpairs_available = 0; |
| 7667 | fail_msix: |
| 7668 | ha->queue_pair_map[qpair_id] = NULL; |
| 7669 | clear_bit(qpair_id, ha->qpair_qid_map); |
| 7670 | mutex_unlock(&ha->mq_lock); |
| 7671 | fail_qid_map: |
| 7672 | kfree(qpair); |
| 7673 | return NULL; |
| 7674 | } |
| 7675 | |
| 7676 | int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair) |
| 7677 | { |
| 7678 | int ret; |
| 7679 | struct qla_hw_data *ha = qpair->hw; |
| 7680 | |
| 7681 | qpair->delete_in_progress = 1; |
| 7682 | while (atomic_read(&qpair->ref_count)) |
| 7683 | msleep(500); |
| 7684 | |
| 7685 | ret = qla25xx_delete_req_que(vha, qpair->req); |
| 7686 | if (ret != QLA_SUCCESS) |
| 7687 | goto fail; |
| 7688 | ret = qla25xx_delete_rsp_que(vha, qpair->rsp); |
| 7689 | if (ret != QLA_SUCCESS) |
| 7690 | goto fail; |
| 7691 | |
| 7692 | mutex_lock(&ha->mq_lock); |
| 7693 | ha->queue_pair_map[qpair->id] = NULL; |
| 7694 | clear_bit(qpair->id, ha->qpair_qid_map); |
| 7695 | list_del(&qpair->qp_list_elem); |
| 7696 | if (list_empty(&vha->qp_list)) |
| 7697 | vha->flags.qpairs_available = 0; |
| 7698 | mempool_destroy(qpair->srb_mempool); |
| 7699 | kfree(qpair); |
| 7700 | mutex_unlock(&ha->mq_lock); |
| 7701 | |
| 7702 | return QLA_SUCCESS; |
| 7703 | fail: |
| 7704 | return ret; |
| 7705 | } |