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; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 50 | scsi_qla_host_t *vha = (scsi_qla_host_t *)sp->vha; |
| 51 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 52 | struct req_que *req; |
| 53 | unsigned long flags; |
| 54 | |
| 55 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 56 | req = ha->req_q_map[0]; |
| 57 | req->outstanding_cmds[sp->handle] = NULL; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 58 | iocb = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 59 | iocb->timeout(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 60 | sp->free(vha, sp); |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 61 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 64 | void |
| 65 | qla2x00_sp_free(void *data, void *ptr) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 66 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 67 | srb_t *sp = (srb_t *)ptr; |
| 68 | struct srb_iocb *iocb = &sp->u.iocb_cmd; |
| 69 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 70 | |
Chad Dupuis | 4d97cc5 | 2010-10-15 11:27:41 -0700 | [diff] [blame] | 71 | del_timer(&iocb->timer); |
Chad Dupuis | b00ee7d | 2013-02-08 01:57:50 -0500 | [diff] [blame] | 72 | qla2x00_rel_sp(vha, sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 75 | /* Asynchronous Login/Logout Routines -------------------------------------- */ |
| 76 | |
Saurav Kashyap | a9b6f72 | 2012-08-22 14:21:01 -0400 | [diff] [blame] | 77 | unsigned long |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 78 | qla2x00_get_async_timeout(struct scsi_qla_host *vha) |
| 79 | { |
| 80 | unsigned long tmo; |
| 81 | struct qla_hw_data *ha = vha->hw; |
| 82 | |
| 83 | /* Firmware should use switch negotiated r_a_tov for timeout. */ |
| 84 | tmo = ha->r_a_tov / 10 * 2; |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 85 | if (IS_QLAFX00(ha)) { |
| 86 | tmo = FX00_DEF_RATOV * 2; |
| 87 | } else if (!IS_FWI2_CAPABLE(ha)) { |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 88 | /* |
| 89 | * Except for earlier ISPs where the timeout is seeded from the |
| 90 | * initialization control block. |
| 91 | */ |
| 92 | tmo = ha->login_timeout; |
| 93 | } |
| 94 | return tmo; |
| 95 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 96 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 97 | void |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 98 | qla2x00_async_iocb_timeout(void *data) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 99 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 100 | srb_t *sp = (srb_t *)data; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 101 | fc_port_t *fcport = sp->fcport; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 102 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
| 103 | struct event_arg ea; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 104 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 105 | ql_dbg(ql_dbg_disc, fcport->vha, 0x2071, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 106 | "Async-%s timeout - hdl=%x portid=%06x %8phC.\n", |
| 107 | sp->name, sp->handle, fcport->d_id.b24, fcport->port_name); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 108 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 109 | fcport->flags &= ~FCF_ASYNC_SENT; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 110 | |
| 111 | switch (sp->type) { |
| 112 | case SRB_LOGIN_CMD: |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 113 | /* Retry as needed. */ |
| 114 | lio->u.logio.data[0] = MBS_COMMAND_ERROR; |
| 115 | lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ? |
| 116 | QLA_LOGIO_LOGIN_RETRIED : 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 117 | memset(&ea, 0, sizeof(ea)); |
| 118 | ea.event = FCME_PLOGI_DONE; |
| 119 | ea.fcport = sp->fcport; |
| 120 | ea.data[0] = lio->u.logio.data[0]; |
| 121 | ea.data[1] = lio->u.logio.data[1]; |
| 122 | ea.sp = sp; |
| 123 | qla24xx_handle_plogi_done_event(fcport->vha, &ea); |
| 124 | break; |
| 125 | case SRB_LOGOUT_CMD: |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 126 | qlt_logo_completion_handler(fcport, QLA_FUNCTION_TIMEOUT); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 127 | break; |
| 128 | case SRB_CT_PTHRU_CMD: |
| 129 | case SRB_MB_IOCB: |
| 130 | case SRB_NACK_PLOGI: |
| 131 | case SRB_NACK_PRLI: |
| 132 | case SRB_NACK_LOGO: |
| 133 | sp->done(sp->vha, sp, QLA_FUNCTION_TIMEOUT); |
| 134 | break; |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 135 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 138 | static void |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 139 | qla2x00_async_login_sp_done(void *data, void *ptr, int res) |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 140 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 141 | srb_t *sp = (srb_t *)ptr; |
| 142 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
| 143 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 144 | struct event_arg ea; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 145 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 146 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 147 | "%s %8phC res %d \n", |
| 148 | __func__, sp->fcport->port_name, res); |
| 149 | |
| 150 | sp->fcport->flags &= ~FCF_ASYNC_SENT; |
| 151 | if (!test_bit(UNLOADING, &vha->dpc_flags)) { |
| 152 | memset(&ea, 0, sizeof(ea)); |
| 153 | ea.event = FCME_PLOGI_DONE; |
| 154 | ea.fcport = sp->fcport; |
| 155 | ea.data[0] = lio->u.logio.data[0]; |
| 156 | ea.data[1] = lio->u.logio.data[1]; |
| 157 | ea.iop[0] = lio->u.logio.iop[0]; |
| 158 | ea.iop[1] = lio->u.logio.iop[1]; |
| 159 | ea.sp = sp; |
| 160 | qla2x00_fcport_event_handler(vha, &ea); |
| 161 | } |
| 162 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 163 | sp->free(sp->fcport->vha, sp); |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 166 | int |
| 167 | qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 168 | uint16_t *data) |
| 169 | { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 170 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 171 | struct srb_iocb *lio; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 172 | int rval = QLA_FUNCTION_FAILED; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 173 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 174 | if (!vha->flags.online) |
| 175 | goto done; |
| 176 | |
| 177 | if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) || |
| 178 | (fcport->fw_login_state == DSC_LS_PLOGI_COMP) || |
| 179 | (fcport->fw_login_state == DSC_LS_PRLI_PEND)) |
| 180 | goto done; |
| 181 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 182 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 183 | if (!sp) |
| 184 | goto done; |
| 185 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 186 | fcport->flags |= FCF_ASYNC_SENT; |
| 187 | fcport->logout_completed = 0; |
| 188 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 189 | sp->type = SRB_LOGIN_CMD; |
| 190 | sp->name = "login"; |
| 191 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 192 | |
| 193 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 194 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 195 | sp->done = qla2x00_async_login_sp_done; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 196 | lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 197 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 198 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 199 | rval = qla2x00_start_sp(sp); |
Chad Dupuis | 080c951 | 2016-01-27 12:03:37 -0500 | [diff] [blame] | 200 | if (rval != QLA_SUCCESS) { |
| 201 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 202 | fcport->flags |= FCF_LOGIN_NEEDED; |
| 203 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 204 | goto done_free_sp; |
Chad Dupuis | 080c951 | 2016-01-27 12:03:37 -0500 | [diff] [blame] | 205 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 206 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 207 | ql_dbg(ql_dbg_disc, vha, 0x2072, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 208 | "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x " |
| 209 | "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 210 | fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 211 | fcport->login_retry); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 212 | return rval; |
| 213 | |
| 214 | done_free_sp: |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 215 | sp->free(fcport->vha, sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 216 | done: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 217 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 218 | return rval; |
| 219 | } |
| 220 | |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 221 | static void |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 222 | qla2x00_async_logout_sp_done(void *data, void *ptr, int res) |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 223 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 224 | srb_t *sp = (srb_t *)ptr; |
| 225 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
| 226 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 227 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 228 | sp->fcport->flags &= ~FCF_ASYNC_SENT; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 229 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
| 230 | qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport, |
| 231 | lio->u.logio.data); |
| 232 | sp->free(sp->fcport->vha, sp); |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 235 | int |
| 236 | qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 237 | { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 238 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 239 | struct srb_iocb *lio; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 240 | int rval; |
| 241 | |
| 242 | rval = QLA_FUNCTION_FAILED; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 243 | fcport->flags |= FCF_ASYNC_SENT; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 244 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 245 | if (!sp) |
| 246 | goto done; |
| 247 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 248 | sp->type = SRB_LOGOUT_CMD; |
| 249 | sp->name = "logout"; |
| 250 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 251 | |
| 252 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 253 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 254 | sp->done = qla2x00_async_logout_sp_done; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 255 | rval = qla2x00_start_sp(sp); |
| 256 | if (rval != QLA_SUCCESS) |
| 257 | goto done_free_sp; |
| 258 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 259 | ql_dbg(ql_dbg_disc, vha, 0x2070, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 260 | "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] | 261 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 262 | fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 263 | fcport->port_name); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 264 | return rval; |
| 265 | |
| 266 | done_free_sp: |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 267 | sp->free(fcport->vha, sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 268 | done: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 269 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 270 | return rval; |
| 271 | } |
| 272 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 273 | static void |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 274 | qla2x00_async_adisc_sp_done(void *data, void *ptr, int res) |
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 | srb_t *sp = (srb_t *)ptr; |
| 277 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
| 278 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 279 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 280 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
| 281 | qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport, |
| 282 | lio->u.logio.data); |
| 283 | sp->free(sp->fcport->vha, sp); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | int |
| 287 | qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 288 | uint16_t *data) |
| 289 | { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 290 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 291 | struct srb_iocb *lio; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 292 | int rval; |
| 293 | |
| 294 | rval = QLA_FUNCTION_FAILED; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 295 | fcport->flags |= FCF_ASYNC_SENT; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 296 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 297 | if (!sp) |
| 298 | goto done; |
| 299 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 300 | sp->type = SRB_ADISC_CMD; |
| 301 | sp->name = "adisc"; |
| 302 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 303 | |
| 304 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 305 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 306 | sp->done = qla2x00_async_adisc_sp_done; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 307 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 308 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 309 | rval = qla2x00_start_sp(sp); |
| 310 | if (rval != QLA_SUCCESS) |
| 311 | goto done_free_sp; |
| 312 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 313 | ql_dbg(ql_dbg_disc, vha, 0x206f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 314 | "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n", |
| 315 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
| 316 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 317 | return rval; |
| 318 | |
| 319 | done_free_sp: |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 320 | sp->free(fcport->vha, sp); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 321 | done: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 322 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 323 | return rval; |
| 324 | } |
| 325 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 326 | static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha, |
| 327 | struct event_arg *ea) |
| 328 | { |
| 329 | fc_port_t *fcport, *conflict_fcport; |
| 330 | struct get_name_list_extended *e; |
| 331 | u16 i, n, found = 0, loop_id; |
| 332 | port_id_t id; |
| 333 | u64 wwn; |
| 334 | u8 opt = 0; |
| 335 | |
| 336 | fcport = ea->fcport; |
| 337 | |
| 338 | if (ea->rc) { /* rval */ |
| 339 | if (fcport->login_retry == 0) { |
| 340 | fcport->login_retry = vha->hw->login_retry_count; |
| 341 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 342 | "GNL failed Port login retry %8phN, retry cnt=%d.\n", |
| 343 | fcport->port_name, fcport->login_retry); |
| 344 | } |
| 345 | return; |
| 346 | } |
| 347 | |
| 348 | if (fcport->last_rscn_gen != fcport->rscn_gen) { |
| 349 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 350 | "%s %8phC rscn gen changed rscn %d|%d \n", |
| 351 | __func__, fcport->port_name, |
| 352 | fcport->last_rscn_gen, fcport->rscn_gen); |
| 353 | qla24xx_post_gidpn_work(vha, fcport); |
| 354 | return; |
| 355 | } else if (fcport->last_login_gen != fcport->login_gen) { |
| 356 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 357 | "%s %8phC login gen changed login %d|%d \n", |
| 358 | __func__, fcport->port_name, |
| 359 | fcport->last_login_gen, fcport->login_gen); |
| 360 | return; |
| 361 | } |
| 362 | |
| 363 | n = ea->data[0] / sizeof(struct get_name_list_extended); |
| 364 | |
| 365 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 366 | "%s %d %8phC n %d %02x%02x%02x lid %d \n", |
| 367 | __func__, __LINE__, fcport->port_name, n, |
| 368 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 369 | fcport->d_id.b.al_pa, fcport->loop_id); |
| 370 | |
| 371 | for (i = 0; i < n; i++) { |
| 372 | e = &vha->gnl.l[i]; |
| 373 | wwn = wwn_to_u64(e->port_name); |
| 374 | |
| 375 | if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE)) |
| 376 | continue; |
| 377 | |
| 378 | found = 1; |
| 379 | id.b.domain = e->port_id[2]; |
| 380 | id.b.area = e->port_id[1]; |
| 381 | id.b.al_pa = e->port_id[0]; |
| 382 | id.b.rsvd_1 = 0; |
| 383 | |
| 384 | loop_id = le16_to_cpu(e->nport_handle); |
| 385 | loop_id = (loop_id & 0x7fff); |
| 386 | |
| 387 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 388 | "%s found %8phC CLS [%d|%d] ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n", |
| 389 | __func__, fcport->port_name, |
| 390 | e->current_login_state, fcport->fw_login_state, |
| 391 | id.b.domain, id.b.area, id.b.al_pa, |
| 392 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 393 | fcport->d_id.b.al_pa, loop_id, fcport->loop_id); |
| 394 | |
| 395 | if ((id.b24 != fcport->d_id.b24) || |
| 396 | ((fcport->loop_id != FC_NO_LOOP_ID) && |
| 397 | (fcport->loop_id != loop_id))) { |
| 398 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 399 | "%s %d %8phC post del sess\n", |
| 400 | __func__, __LINE__, fcport->port_name); |
| 401 | qlt_schedule_sess_for_deletion(fcport, 1); |
| 402 | return; |
| 403 | } |
| 404 | |
| 405 | fcport->loop_id = loop_id; |
| 406 | |
| 407 | wwn = wwn_to_u64(fcport->port_name); |
| 408 | qlt_find_sess_invalidate_other(vha, wwn, |
| 409 | id, loop_id, &conflict_fcport); |
| 410 | |
| 411 | if (conflict_fcport) { |
| 412 | /* |
| 413 | * Another share fcport share the same loop_id & |
| 414 | * nport id. Conflict fcport needs to finish |
| 415 | * cleanup before this fcport can proceed to login. |
| 416 | */ |
| 417 | conflict_fcport->conflict = fcport; |
| 418 | fcport->login_pause = 1; |
| 419 | } |
| 420 | |
| 421 | switch (e->current_login_state) { |
| 422 | case DSC_LS_PRLI_COMP: |
| 423 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 424 | "%s %d %8phC post gpdb\n", |
| 425 | __func__, __LINE__, fcport->port_name); |
| 426 | opt = PDO_FORCE_ADISC; |
| 427 | qla24xx_post_gpdb_work(vha, fcport, opt); |
| 428 | break; |
| 429 | |
| 430 | case DSC_LS_PORT_UNAVAIL: |
| 431 | default: |
| 432 | if (fcport->loop_id == FC_NO_LOOP_ID) { |
| 433 | qla2x00_find_new_loop_id(vha, fcport); |
| 434 | fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 435 | } |
| 436 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 437 | "%s %d %8phC \n", |
| 438 | __func__, __LINE__, fcport->port_name); |
| 439 | qla24xx_fcport_handle_login(vha, fcport); |
| 440 | break; |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | if (!found) { |
| 445 | /* fw has no record of this port */ |
| 446 | if (fcport->loop_id == FC_NO_LOOP_ID) { |
| 447 | qla2x00_find_new_loop_id(vha, fcport); |
| 448 | fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 449 | } else { |
| 450 | for (i = 0; i < n; i++) { |
| 451 | e = &vha->gnl.l[i]; |
| 452 | id.b.domain = e->port_id[0]; |
| 453 | id.b.area = e->port_id[1]; |
| 454 | id.b.al_pa = e->port_id[2]; |
| 455 | id.b.rsvd_1 = 0; |
| 456 | loop_id = le16_to_cpu(e->nport_handle); |
| 457 | |
| 458 | if (fcport->d_id.b24 == id.b24) { |
| 459 | conflict_fcport = |
| 460 | qla2x00_find_fcport_by_wwpn(vha, |
| 461 | e->port_name, 0); |
| 462 | |
| 463 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 464 | "%s %d %8phC post del sess\n", |
| 465 | __func__, __LINE__, |
| 466 | conflict_fcport->port_name); |
| 467 | qlt_schedule_sess_for_deletion |
| 468 | (conflict_fcport, 1); |
| 469 | } |
| 470 | |
| 471 | if (fcport->loop_id == loop_id) { |
| 472 | /* FW already picked this loop id for another fcport */ |
| 473 | qla2x00_find_new_loop_id(vha, fcport); |
| 474 | } |
| 475 | } |
| 476 | } |
| 477 | qla24xx_fcport_handle_login(vha, fcport); |
| 478 | } |
| 479 | } /* gnl_event */ |
| 480 | |
| 481 | static void |
| 482 | qla24xx_async_gnl_sp_done(void *v, void *s, int res) |
| 483 | { |
| 484 | struct scsi_qla_host *vha = (struct scsi_qla_host *)v; |
| 485 | struct srb *sp = (struct srb *)s; |
| 486 | unsigned long flags; |
| 487 | struct fc_port *fcport = NULL, *tf; |
| 488 | u16 i, n = 0, loop_id; |
| 489 | struct event_arg ea; |
| 490 | struct get_name_list_extended *e; |
| 491 | u64 wwn; |
| 492 | struct list_head h; |
| 493 | |
| 494 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 495 | "Async done-%s res %x mb[1]=%x mb[2]=%x \n", |
| 496 | sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1], |
| 497 | sp->u.iocb_cmd.u.mbx.in_mb[2]); |
| 498 | |
| 499 | memset(&ea, 0, sizeof(ea)); |
| 500 | ea.sp = sp; |
| 501 | ea.rc = res; |
| 502 | ea.event = FCME_GNL_DONE; |
| 503 | |
| 504 | if (sp->u.iocb_cmd.u.mbx.in_mb[1] >= |
| 505 | sizeof(struct get_name_list_extended)) { |
| 506 | n = sp->u.iocb_cmd.u.mbx.in_mb[1] / |
| 507 | sizeof(struct get_name_list_extended); |
| 508 | ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */ |
| 509 | } |
| 510 | |
| 511 | for (i = 0; i < n; i++) { |
| 512 | e = &vha->gnl.l[i]; |
| 513 | loop_id = le16_to_cpu(e->nport_handle); |
| 514 | /* mask out reserve bit */ |
| 515 | loop_id = (loop_id & 0x7fff); |
| 516 | set_bit(loop_id, vha->hw->loop_id_map); |
| 517 | wwn = wwn_to_u64(e->port_name); |
| 518 | |
| 519 | ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0xffff, |
| 520 | "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n", |
| 521 | __func__, (void *)&wwn, e->port_id[2], e->port_id[1], |
| 522 | e->port_id[0], e->current_login_state, e->last_login_state, |
| 523 | (loop_id & 0x7fff)); |
| 524 | } |
| 525 | |
| 526 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 527 | vha->gnl.sent = 0; |
| 528 | |
| 529 | INIT_LIST_HEAD(&h); |
| 530 | fcport = tf = NULL; |
| 531 | if (!list_empty(&vha->gnl.fcports)) |
| 532 | list_splice_init(&vha->gnl.fcports, &h); |
| 533 | |
| 534 | list_for_each_entry_safe(fcport, tf, &h, gnl_entry) { |
| 535 | list_del_init(&fcport->gnl_entry); |
| 536 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 537 | ea.fcport = fcport; |
| 538 | |
| 539 | qla2x00_fcport_event_handler(vha, &ea); |
| 540 | } |
| 541 | |
| 542 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 543 | |
| 544 | sp->free(vha, sp); |
| 545 | } |
| 546 | |
| 547 | int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 548 | { |
| 549 | srb_t *sp; |
| 550 | struct srb_iocb *mbx; |
| 551 | int rval = QLA_FUNCTION_FAILED; |
| 552 | unsigned long flags; |
| 553 | u16 *mb; |
| 554 | |
| 555 | if (!vha->flags.online) |
| 556 | goto done; |
| 557 | |
| 558 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 559 | "Async-gnlist WWPN %8phC \n", fcport->port_name); |
| 560 | |
| 561 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 562 | fcport->flags |= FCF_ASYNC_SENT; |
| 563 | fcport->disc_state = DSC_GNL; |
| 564 | fcport->last_rscn_gen = fcport->rscn_gen; |
| 565 | fcport->last_login_gen = fcport->login_gen; |
| 566 | |
| 567 | list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports); |
| 568 | if (vha->gnl.sent) { |
| 569 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 570 | rval = QLA_SUCCESS; |
| 571 | goto done; |
| 572 | } |
| 573 | vha->gnl.sent = 1; |
| 574 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 575 | |
| 576 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 577 | if (!sp) |
| 578 | goto done; |
| 579 | sp->type = SRB_MB_IOCB; |
| 580 | sp->name = "gnlist"; |
| 581 | sp->gen1 = fcport->rscn_gen; |
| 582 | sp->gen2 = fcport->login_gen; |
| 583 | |
| 584 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2); |
| 585 | |
| 586 | mb = sp->u.iocb_cmd.u.mbx.out_mb; |
| 587 | mb[0] = MBC_PORT_NODE_NAME_LIST; |
| 588 | mb[1] = BIT_2 | BIT_3; |
| 589 | mb[2] = MSW(vha->gnl.ldma); |
| 590 | mb[3] = LSW(vha->gnl.ldma); |
| 591 | mb[6] = MSW(MSD(vha->gnl.ldma)); |
| 592 | mb[7] = LSW(MSD(vha->gnl.ldma)); |
| 593 | mb[8] = vha->gnl.size; |
| 594 | mb[9] = vha->vp_idx; |
| 595 | |
| 596 | mbx = &sp->u.iocb_cmd; |
| 597 | mbx->timeout = qla2x00_async_iocb_timeout; |
| 598 | |
| 599 | sp->done = qla24xx_async_gnl_sp_done; |
| 600 | |
| 601 | rval = qla2x00_start_sp(sp); |
| 602 | if (rval != QLA_SUCCESS) |
| 603 | goto done_free_sp; |
| 604 | |
| 605 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 606 | "Async-%s - OUT WWPN %8phC hndl %x\n", |
| 607 | sp->name, fcport->port_name, sp->handle); |
| 608 | |
| 609 | return rval; |
| 610 | |
| 611 | done_free_sp: |
| 612 | sp->free(fcport->vha, sp); |
| 613 | done: |
| 614 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 615 | return rval; |
| 616 | } |
| 617 | |
| 618 | int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 619 | { |
| 620 | struct qla_work_evt *e; |
| 621 | |
| 622 | e = qla2x00_alloc_work(vha, QLA_EVT_GNL); |
| 623 | if (!e) |
| 624 | return QLA_FUNCTION_FAILED; |
| 625 | |
| 626 | e->u.fcport.fcport = fcport; |
| 627 | return qla2x00_post_work(vha, e); |
| 628 | } |
| 629 | |
| 630 | static |
| 631 | void qla24xx_async_gpdb_sp_done(void *v, void *s, int res) |
| 632 | { |
| 633 | struct scsi_qla_host *vha = (struct scsi_qla_host *)v; |
| 634 | struct srb *sp = (struct srb *)s; |
| 635 | struct qla_hw_data *ha = vha->hw; |
| 636 | uint64_t zero = 0; |
| 637 | struct port_database_24xx *pd; |
| 638 | fc_port_t *fcport = sp->fcport; |
| 639 | u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb; |
| 640 | int rval = QLA_SUCCESS; |
| 641 | struct event_arg ea; |
| 642 | |
| 643 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 644 | "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n", |
| 645 | sp->name, res, fcport->port_name, mb[1], mb[2]); |
| 646 | |
| 647 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 648 | |
| 649 | if (res) { |
| 650 | rval = res; |
| 651 | goto gpd_error_out; |
| 652 | } |
| 653 | |
| 654 | pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in; |
| 655 | |
| 656 | /* Check for logged in state. */ |
| 657 | if (pd->current_login_state != PDS_PRLI_COMPLETE && |
| 658 | pd->last_login_state != PDS_PRLI_COMPLETE) { |
| 659 | ql_dbg(ql_dbg_mbx, vha, 0xffff, |
| 660 | "Unable to verify login-state (%x/%x) for " |
| 661 | "loop_id %x.\n", pd->current_login_state, |
| 662 | pd->last_login_state, fcport->loop_id); |
| 663 | rval = QLA_FUNCTION_FAILED; |
| 664 | goto gpd_error_out; |
| 665 | } |
| 666 | |
| 667 | if (fcport->loop_id == FC_NO_LOOP_ID || |
| 668 | (memcmp(fcport->port_name, (uint8_t *)&zero, 8) && |
| 669 | memcmp(fcport->port_name, pd->port_name, 8))) { |
| 670 | /* We lost the device mid way. */ |
| 671 | rval = QLA_NOT_LOGGED_IN; |
| 672 | goto gpd_error_out; |
| 673 | } |
| 674 | |
| 675 | /* Names are little-endian. */ |
| 676 | memcpy(fcport->node_name, pd->node_name, WWN_SIZE); |
| 677 | |
| 678 | /* Get port_id of device. */ |
| 679 | fcport->d_id.b.domain = pd->port_id[0]; |
| 680 | fcport->d_id.b.area = pd->port_id[1]; |
| 681 | fcport->d_id.b.al_pa = pd->port_id[2]; |
| 682 | fcport->d_id.b.rsvd_1 = 0; |
| 683 | |
| 684 | /* If not target must be initiator or unknown type. */ |
| 685 | if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0) |
| 686 | fcport->port_type = FCT_INITIATOR; |
| 687 | else |
| 688 | fcport->port_type = FCT_TARGET; |
| 689 | |
| 690 | /* Passback COS information. */ |
| 691 | fcport->supported_classes = (pd->flags & PDF_CLASS_2) ? |
| 692 | FC_COS_CLASS2 : FC_COS_CLASS3; |
| 693 | |
| 694 | if (pd->prli_svc_param_word_3[0] & BIT_7) { |
| 695 | fcport->flags |= FCF_CONF_COMP_SUPPORTED; |
| 696 | fcport->conf_compl_supported = 1; |
| 697 | } |
| 698 | |
| 699 | gpd_error_out: |
| 700 | memset(&ea, 0, sizeof(ea)); |
| 701 | ea.event = FCME_GPDB_DONE; |
| 702 | ea.rc = rval; |
| 703 | ea.fcport = fcport; |
| 704 | ea.sp = sp; |
| 705 | |
| 706 | qla2x00_fcport_event_handler(vha, &ea); |
| 707 | |
| 708 | dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in, |
| 709 | sp->u.iocb_cmd.u.mbx.in_dma); |
| 710 | |
| 711 | sp->free(vha, sp); |
| 712 | } |
| 713 | |
| 714 | static int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 715 | u8 opt) |
| 716 | { |
| 717 | struct qla_work_evt *e; |
| 718 | |
| 719 | e = qla2x00_alloc_work(vha, QLA_EVT_GPDB); |
| 720 | if (!e) |
| 721 | return QLA_FUNCTION_FAILED; |
| 722 | |
| 723 | e->u.fcport.fcport = fcport; |
| 724 | e->u.fcport.opt = opt; |
| 725 | return qla2x00_post_work(vha, e); |
| 726 | } |
| 727 | |
| 728 | int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt) |
| 729 | { |
| 730 | srb_t *sp; |
| 731 | struct srb_iocb *mbx; |
| 732 | int rval = QLA_FUNCTION_FAILED; |
| 733 | u16 *mb; |
| 734 | dma_addr_t pd_dma; |
| 735 | struct port_database_24xx *pd; |
| 736 | struct qla_hw_data *ha = vha->hw; |
| 737 | |
| 738 | if (!vha->flags.online) |
| 739 | goto done; |
| 740 | |
| 741 | fcport->flags |= FCF_ASYNC_SENT; |
| 742 | fcport->disc_state = DSC_GPDB; |
| 743 | |
| 744 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 745 | if (!sp) |
| 746 | goto done; |
| 747 | |
| 748 | pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma); |
| 749 | if (pd == NULL) { |
| 750 | ql_log(ql_log_warn, vha, 0xffff, |
| 751 | "Failed to allocate port database structure.\n"); |
| 752 | goto done_free_sp; |
| 753 | } |
| 754 | memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE)); |
| 755 | |
| 756 | sp->type = SRB_MB_IOCB; |
| 757 | sp->name = "gpdb"; |
| 758 | sp->gen1 = fcport->rscn_gen; |
| 759 | sp->gen2 = fcport->login_gen; |
| 760 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 761 | |
| 762 | mb = sp->u.iocb_cmd.u.mbx.out_mb; |
| 763 | mb[0] = MBC_GET_PORT_DATABASE; |
| 764 | mb[1] = fcport->loop_id; |
| 765 | mb[2] = MSW(pd_dma); |
| 766 | mb[3] = LSW(pd_dma); |
| 767 | mb[6] = MSW(MSD(pd_dma)); |
| 768 | mb[7] = LSW(MSD(pd_dma)); |
| 769 | mb[9] = vha->vp_idx; |
| 770 | mb[10] = opt; |
| 771 | |
| 772 | mbx = &sp->u.iocb_cmd; |
| 773 | mbx->timeout = qla2x00_async_iocb_timeout; |
| 774 | mbx->u.mbx.in = (void *)pd; |
| 775 | mbx->u.mbx.in_dma = pd_dma; |
| 776 | |
| 777 | sp->done = qla24xx_async_gpdb_sp_done; |
| 778 | |
| 779 | rval = qla2x00_start_sp(sp); |
| 780 | if (rval != QLA_SUCCESS) |
| 781 | goto done_free_sp; |
| 782 | |
| 783 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 784 | "Async-%s %8phC hndl %x opt %x\n", |
| 785 | sp->name, fcport->port_name, sp->handle, opt); |
| 786 | |
| 787 | return rval; |
| 788 | |
| 789 | done_free_sp: |
| 790 | if (pd) |
| 791 | dma_pool_free(ha->s_dma_pool, pd, pd_dma); |
| 792 | |
| 793 | sp->free(vha, sp); |
| 794 | done: |
| 795 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 796 | qla24xx_post_gpdb_work(vha, fcport, opt); |
| 797 | return rval; |
| 798 | } |
| 799 | |
| 800 | static |
| 801 | void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea) |
| 802 | { |
| 803 | int rval = ea->rc; |
| 804 | fc_port_t *fcport = ea->fcport; |
| 805 | unsigned long flags; |
| 806 | |
| 807 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 808 | |
| 809 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 810 | "%s %8phC DS %d LS %d rval %d\n", __func__, fcport->port_name, |
| 811 | fcport->disc_state, fcport->fw_login_state, rval); |
| 812 | |
| 813 | if (ea->sp->gen2 != fcport->login_gen) { |
| 814 | /* target side must have changed it. */ |
| 815 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 816 | "%s %8phC generation changed rscn %d|%d login %d|%d \n", |
| 817 | __func__, fcport->port_name, fcport->last_rscn_gen, |
| 818 | fcport->rscn_gen, fcport->last_login_gen, |
| 819 | fcport->login_gen); |
| 820 | return; |
| 821 | } else if (ea->sp->gen1 != fcport->rscn_gen) { |
| 822 | ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC post gidpn\n", |
| 823 | __func__, __LINE__, fcport->port_name); |
| 824 | qla24xx_post_gidpn_work(vha, fcport); |
| 825 | return; |
| 826 | } |
| 827 | |
| 828 | if (rval != QLA_SUCCESS) { |
| 829 | ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC post del sess\n", |
| 830 | __func__, __LINE__, fcport->port_name); |
| 831 | qlt_schedule_sess_for_deletion_lock(fcport); |
| 832 | return; |
| 833 | } |
| 834 | |
| 835 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 836 | ea->fcport->login_gen++; |
| 837 | ea->fcport->deleted = 0; |
| 838 | ea->fcport->logout_on_delete = 1; |
| 839 | |
| 840 | if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) { |
| 841 | vha->fcport_count++; |
| 842 | ea->fcport->login_succ = 1; |
| 843 | |
| 844 | if (!IS_IIDMA_CAPABLE(vha->hw) || |
| 845 | !vha->hw->flags.gpsc_supported) { |
| 846 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 847 | "%s %d %8phC post upd_fcport fcp_cnt %d\n", |
| 848 | __func__, __LINE__, fcport->port_name, |
| 849 | vha->fcport_count); |
| 850 | |
| 851 | qla24xx_post_upd_fcport_work(vha, fcport); |
| 852 | } else { |
| 853 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 854 | "%s %d %8phC post gpsc fcp_cnt %d\n", |
| 855 | __func__, __LINE__, fcport->port_name, |
| 856 | vha->fcport_count); |
| 857 | |
| 858 | qla24xx_post_gpsc_work(vha, fcport); |
| 859 | } |
| 860 | } |
| 861 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 862 | } /* gpdb event */ |
| 863 | |
| 864 | int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 865 | { |
| 866 | if (fcport->login_retry == 0) |
| 867 | return 0; |
| 868 | |
| 869 | if (fcport->scan_state != QLA_FCPORT_FOUND) |
| 870 | return 0; |
| 871 | |
| 872 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 873 | "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d|%d retry %d lid %d\n", |
| 874 | __func__, fcport->port_name, fcport->disc_state, |
| 875 | fcport->fw_login_state, fcport->login_pause, fcport->flags, |
| 876 | fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen, |
| 877 | fcport->last_login_gen, fcport->login_gen, fcport->login_retry, |
| 878 | fcport->loop_id); |
| 879 | |
| 880 | fcport->login_retry--; |
| 881 | |
| 882 | if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) || |
| 883 | (fcport->fw_login_state == DSC_LS_PLOGI_COMP) || |
| 884 | (fcport->fw_login_state == DSC_LS_PRLI_PEND)) |
| 885 | return 0; |
| 886 | |
| 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) || |
| 1048 | (fcport->fw_login_state == DSC_LS_PLOGI_COMP) || |
| 1049 | (fcport->fw_login_state == DSC_LS_PRLI_PEND)) |
| 1050 | return; |
| 1051 | |
| 1052 | if (fcport->flags & FCF_ASYNC_SENT) { |
| 1053 | fcport->login_retry++; |
| 1054 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1055 | return; |
| 1056 | } |
| 1057 | |
| 1058 | if (fcport->disc_state == DSC_DELETE_PEND) { |
| 1059 | fcport->login_retry++; |
| 1060 | return; |
| 1061 | } |
| 1062 | |
| 1063 | if (fcport->last_rscn_gen != fcport->rscn_gen) { |
| 1064 | ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC post gidpn\n", |
| 1065 | __func__, __LINE__, fcport->port_name); |
| 1066 | |
| 1067 | qla24xx_async_gidpn(vha, fcport); |
| 1068 | return; |
| 1069 | } |
| 1070 | |
| 1071 | qla24xx_fcport_handle_login(vha, fcport); |
| 1072 | } |
| 1073 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame^] | 1074 | 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] | 1075 | { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame^] | 1076 | fc_port_t *fcport, *f, *tf; |
| 1077 | uint32_t id = 0, mask, rid; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1078 | int rc; |
| 1079 | |
| 1080 | switch (ea->event) { |
| 1081 | case FCME_RELOGIN: |
| 1082 | if (test_bit(UNLOADING, &vha->dpc_flags)) |
| 1083 | return; |
| 1084 | |
| 1085 | qla24xx_handle_relogin_event(vha, ea); |
| 1086 | break; |
| 1087 | case FCME_RSCN: |
| 1088 | if (test_bit(UNLOADING, &vha->dpc_flags)) |
| 1089 | return; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame^] | 1090 | switch (ea->id.b.rsvd_1) { |
| 1091 | case RSCN_PORT_ADDR: |
| 1092 | fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1); |
| 1093 | if (!fcport) { |
| 1094 | /* cable moved */ |
| 1095 | rc = qla24xx_post_gpnid_work(vha, &ea->id); |
| 1096 | if (rc) { |
| 1097 | ql_log(ql_log_warn, vha, 0xffff, |
| 1098 | "RSCN GPNID work failed %02x%02x%02x\n", |
| 1099 | ea->id.b.domain, ea->id.b.area, |
| 1100 | ea->id.b.al_pa); |
| 1101 | } |
| 1102 | } else { |
| 1103 | ea->fcport = fcport; |
| 1104 | qla24xx_handle_rscn_event(fcport, ea); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1105 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame^] | 1106 | break; |
| 1107 | case RSCN_AREA_ADDR: |
| 1108 | case RSCN_DOM_ADDR: |
| 1109 | if (ea->id.b.rsvd_1 == RSCN_AREA_ADDR) { |
| 1110 | mask = 0xffff00; |
| 1111 | ql_log(ql_dbg_async, vha, 0xffff, |
| 1112 | "RSCN: Area 0x%06x was affected\n", |
| 1113 | ea->id.b24); |
| 1114 | } else { |
| 1115 | mask = 0xff0000; |
| 1116 | ql_log(ql_dbg_async, vha, 0xffff, |
| 1117 | "RSCN: Domain 0x%06x was affected\n", |
| 1118 | ea->id.b24); |
| 1119 | } |
| 1120 | |
| 1121 | rid = ea->id.b24 & mask; |
| 1122 | list_for_each_entry_safe(f, tf, &vha->vp_fcports, |
| 1123 | list) { |
| 1124 | id = f->d_id.b24 & mask; |
| 1125 | if (rid == id) { |
| 1126 | ea->fcport = f; |
| 1127 | qla24xx_handle_rscn_event(f, ea); |
| 1128 | } |
| 1129 | } |
| 1130 | break; |
| 1131 | case RSCN_FAB_ADDR: |
| 1132 | default: |
| 1133 | ql_log(ql_log_warn, vha, 0xffff, |
| 1134 | "RSCN: Fabric was affected. Addr format %d\n", |
| 1135 | ea->id.b.rsvd_1); |
| 1136 | qla2x00_mark_all_devices_lost(vha, 1); |
| 1137 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 1138 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1139 | } |
| 1140 | break; |
| 1141 | case FCME_GIDPN_DONE: |
| 1142 | qla24xx_handle_gidpn_event(vha, ea); |
| 1143 | break; |
| 1144 | case FCME_GNL_DONE: |
| 1145 | qla24xx_handle_gnl_done_event(vha, ea); |
| 1146 | break; |
| 1147 | case FCME_GPSC_DONE: |
| 1148 | qla24xx_post_upd_fcport_work(vha, ea->fcport); |
| 1149 | break; |
| 1150 | case FCME_PLOGI_DONE: /* Initiator side sent LLIOCB */ |
| 1151 | qla24xx_handle_plogi_done_event(vha, ea); |
| 1152 | break; |
| 1153 | case FCME_GPDB_DONE: |
| 1154 | qla24xx_handle_gpdb_event(vha, ea); |
| 1155 | break; |
| 1156 | case FCME_GPNID_DONE: |
| 1157 | qla24xx_handle_gpnid_event(vha, ea); |
| 1158 | break; |
| 1159 | case FCME_DELETE_DONE: |
| 1160 | qla24xx_handle_delete_done_event(vha, ea); |
| 1161 | break; |
| 1162 | default: |
| 1163 | BUG_ON(1); |
| 1164 | break; |
| 1165 | } |
| 1166 | } |
| 1167 | |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1168 | static void |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1169 | qla2x00_tmf_iocb_timeout(void *data) |
| 1170 | { |
| 1171 | srb_t *sp = (srb_t *)data; |
| 1172 | struct srb_iocb *tmf = &sp->u.iocb_cmd; |
| 1173 | |
| 1174 | tmf->u.tmf.comp_status = CS_TIMEOUT; |
| 1175 | complete(&tmf->u.tmf.comp); |
| 1176 | } |
| 1177 | |
| 1178 | static void |
| 1179 | qla2x00_tmf_sp_done(void *data, void *ptr, int res) |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1180 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1181 | srb_t *sp = (srb_t *)ptr; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1182 | struct srb_iocb *tmf = &sp->u.iocb_cmd; |
| 1183 | complete(&tmf->u.tmf.comp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | int |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1187 | 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] | 1188 | uint32_t tag) |
| 1189 | { |
| 1190 | struct scsi_qla_host *vha = fcport->vha; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1191 | struct srb_iocb *tm_iocb; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1192 | srb_t *sp; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1193 | int rval = QLA_FUNCTION_FAILED; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1194 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1195 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1196 | if (!sp) |
| 1197 | goto done; |
| 1198 | |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1199 | tm_iocb = &sp->u.iocb_cmd; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1200 | sp->type = SRB_TM_CMD; |
| 1201 | sp->name = "tmf"; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1202 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)); |
| 1203 | tm_iocb->u.tmf.flags = flags; |
| 1204 | tm_iocb->u.tmf.lun = lun; |
| 1205 | tm_iocb->u.tmf.data = tag; |
| 1206 | sp->done = qla2x00_tmf_sp_done; |
| 1207 | tm_iocb->timeout = qla2x00_tmf_iocb_timeout; |
| 1208 | init_completion(&tm_iocb->u.tmf.comp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1209 | |
| 1210 | rval = qla2x00_start_sp(sp); |
| 1211 | if (rval != QLA_SUCCESS) |
| 1212 | goto done_free_sp; |
| 1213 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1214 | ql_dbg(ql_dbg_taskm, vha, 0x802f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1215 | "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n", |
| 1216 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
| 1217 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1218 | |
| 1219 | wait_for_completion(&tm_iocb->u.tmf.comp); |
| 1220 | |
| 1221 | rval = tm_iocb->u.tmf.comp_status == CS_COMPLETE ? |
| 1222 | QLA_SUCCESS : QLA_FUNCTION_FAILED; |
| 1223 | |
| 1224 | if ((rval != QLA_SUCCESS) || tm_iocb->u.tmf.data) { |
| 1225 | ql_dbg(ql_dbg_taskm, vha, 0x8030, |
| 1226 | "TM IOCB failed (%x).\n", rval); |
| 1227 | } |
| 1228 | |
| 1229 | if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) { |
| 1230 | flags = tm_iocb->u.tmf.flags; |
| 1231 | lun = (uint16_t)tm_iocb->u.tmf.lun; |
| 1232 | |
| 1233 | /* Issue Marker IOCB */ |
| 1234 | qla2x00_marker(vha, vha->hw->req_q_map[0], |
| 1235 | vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun, |
| 1236 | flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID); |
| 1237 | } |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1238 | |
| 1239 | done_free_sp: |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1240 | sp->free(vha, sp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1241 | done: |
| 1242 | return rval; |
| 1243 | } |
| 1244 | |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1245 | static void |
| 1246 | qla24xx_abort_iocb_timeout(void *data) |
| 1247 | { |
| 1248 | srb_t *sp = (srb_t *)data; |
| 1249 | struct srb_iocb *abt = &sp->u.iocb_cmd; |
| 1250 | |
| 1251 | abt->u.abt.comp_status = CS_TIMEOUT; |
| 1252 | complete(&abt->u.abt.comp); |
| 1253 | } |
| 1254 | |
| 1255 | static void |
| 1256 | qla24xx_abort_sp_done(void *data, void *ptr, int res) |
| 1257 | { |
| 1258 | srb_t *sp = (srb_t *)ptr; |
| 1259 | struct srb_iocb *abt = &sp->u.iocb_cmd; |
| 1260 | |
| 1261 | complete(&abt->u.abt.comp); |
| 1262 | } |
| 1263 | |
| 1264 | static int |
| 1265 | qla24xx_async_abort_cmd(srb_t *cmd_sp) |
| 1266 | { |
| 1267 | scsi_qla_host_t *vha = cmd_sp->fcport->vha; |
| 1268 | fc_port_t *fcport = cmd_sp->fcport; |
| 1269 | struct srb_iocb *abt_iocb; |
| 1270 | srb_t *sp; |
| 1271 | int rval = QLA_FUNCTION_FAILED; |
| 1272 | |
| 1273 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 1274 | if (!sp) |
| 1275 | goto done; |
| 1276 | |
| 1277 | abt_iocb = &sp->u.iocb_cmd; |
| 1278 | sp->type = SRB_ABT_CMD; |
| 1279 | sp->name = "abort"; |
| 1280 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)); |
| 1281 | abt_iocb->u.abt.cmd_hndl = cmd_sp->handle; |
| 1282 | sp->done = qla24xx_abort_sp_done; |
| 1283 | abt_iocb->timeout = qla24xx_abort_iocb_timeout; |
| 1284 | init_completion(&abt_iocb->u.abt.comp); |
| 1285 | |
| 1286 | rval = qla2x00_start_sp(sp); |
| 1287 | if (rval != QLA_SUCCESS) |
| 1288 | goto done_free_sp; |
| 1289 | |
| 1290 | ql_dbg(ql_dbg_async, vha, 0x507c, |
| 1291 | "Abort command issued - hdl=%x, target_id=%x\n", |
| 1292 | cmd_sp->handle, fcport->tgt_id); |
| 1293 | |
| 1294 | wait_for_completion(&abt_iocb->u.abt.comp); |
| 1295 | |
| 1296 | rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ? |
| 1297 | QLA_SUCCESS : QLA_FUNCTION_FAILED; |
| 1298 | |
| 1299 | done_free_sp: |
| 1300 | sp->free(vha, sp); |
| 1301 | done: |
| 1302 | return rval; |
| 1303 | } |
| 1304 | |
| 1305 | int |
| 1306 | qla24xx_async_abort_command(srb_t *sp) |
| 1307 | { |
| 1308 | unsigned long flags = 0; |
| 1309 | |
| 1310 | uint32_t handle; |
| 1311 | fc_port_t *fcport = sp->fcport; |
| 1312 | struct scsi_qla_host *vha = fcport->vha; |
| 1313 | struct qla_hw_data *ha = vha->hw; |
| 1314 | struct req_que *req = vha->req; |
| 1315 | |
| 1316 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1317 | for (handle = 1; handle < req->num_outstanding_cmds; handle++) { |
| 1318 | if (req->outstanding_cmds[handle] == sp) |
| 1319 | break; |
| 1320 | } |
| 1321 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1322 | if (handle == req->num_outstanding_cmds) { |
| 1323 | /* Command not found. */ |
| 1324 | return QLA_FUNCTION_FAILED; |
| 1325 | } |
| 1326 | if (sp->type == SRB_FXIOCB_DCMD) |
| 1327 | return qlafx00_fx_disc(vha, &vha->hw->mr.fcport, |
| 1328 | FXDISC_ABORT_IOCTL); |
| 1329 | |
| 1330 | return qla24xx_async_abort_cmd(sp); |
| 1331 | } |
| 1332 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1333 | static void |
| 1334 | 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] | 1335 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1336 | port_id_t cid; /* conflict Nport id */ |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1337 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1338 | switch (ea->data[0]) { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1339 | case MBS_COMMAND_COMPLETE: |
Andrew Vasquez | a4f92a3 | 2011-03-30 11:46:31 -0700 | [diff] [blame] | 1340 | /* |
| 1341 | * Driver must validate login state - If PRLI not complete, |
| 1342 | * force a relogin attempt via implicit LOGO, PLOGI, and PRLI |
| 1343 | * requests. |
| 1344 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1345 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 1346 | "%s %d %8phC post gpdb\n", |
| 1347 | __func__, __LINE__, ea->fcport->port_name); |
| 1348 | ea->fcport->chip_reset = vha->hw->chip_reset; |
| 1349 | ea->fcport->logout_on_delete = 1; |
| 1350 | qla24xx_post_gpdb_work(vha, ea->fcport, 0); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1351 | break; |
| 1352 | case MBS_COMMAND_ERROR: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1353 | ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC cmd error %x\n", |
| 1354 | __func__, __LINE__, ea->fcport->port_name, ea->data[1]); |
| 1355 | |
| 1356 | ea->fcport->flags &= ~FCF_ASYNC_SENT; |
| 1357 | ea->fcport->disc_state = DSC_LOGIN_FAILED; |
| 1358 | if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1359 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1360 | else |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1361 | qla2x00_mark_device_lost(vha, ea->fcport, 1, 0); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1362 | break; |
| 1363 | case MBS_LOOP_ID_USED: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1364 | /* data[1] = IO PARAM 1 = nport ID */ |
| 1365 | cid.b.domain = (ea->iop[1] >> 16) & 0xff; |
| 1366 | cid.b.area = (ea->iop[1] >> 8) & 0xff; |
| 1367 | cid.b.al_pa = ea->iop[1] & 0xff; |
| 1368 | cid.b.rsvd_1 = 0; |
| 1369 | |
| 1370 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 1371 | "%s %d %8phC LoopID 0x%x in use post gnl\n", |
| 1372 | __func__, __LINE__, ea->fcport->port_name, |
| 1373 | ea->fcport->loop_id); |
| 1374 | |
| 1375 | if (IS_SW_RESV_ADDR(cid)) { |
| 1376 | set_bit(ea->fcport->loop_id, vha->hw->loop_id_map); |
| 1377 | ea->fcport->loop_id = FC_NO_LOOP_ID; |
| 1378 | } else { |
| 1379 | qla2x00_clear_loop_id(ea->fcport); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1380 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1381 | qla24xx_post_gnl_work(vha, ea->fcport); |
| 1382 | break; |
| 1383 | case MBS_PORT_ID_USED: |
| 1384 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 1385 | "%s %d %8phC NPortId %02x%02x%02x inuse post gidpn\n", |
| 1386 | __func__, __LINE__, ea->fcport->port_name, |
| 1387 | ea->fcport->d_id.b.domain, ea->fcport->d_id.b.area, |
| 1388 | ea->fcport->d_id.b.al_pa); |
| 1389 | |
| 1390 | qla2x00_clear_loop_id(ea->fcport); |
| 1391 | qla24xx_post_gidpn_work(vha, ea->fcport); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1392 | break; |
| 1393 | } |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1394 | return; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1395 | } |
| 1396 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1397 | void |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1398 | qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 1399 | uint16_t *data) |
| 1400 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1401 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1402 | qlt_logo_completion_handler(fcport, data[0]); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1403 | fcport->login_gen++; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1404 | return; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1405 | } |
| 1406 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1407 | void |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1408 | qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 1409 | uint16_t *data) |
| 1410 | { |
| 1411 | if (data[0] == MBS_COMMAND_COMPLETE) { |
| 1412 | qla2x00_update_fcport(vha, fcport); |
| 1413 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1414 | return; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | /* Retry login. */ |
| 1418 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 1419 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
| 1420 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1421 | else |
Andrew Vasquez | 80d7944 | 2011-03-30 11:46:17 -0700 | [diff] [blame] | 1422 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1423 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1424 | return; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1425 | } |
| 1426 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | /****************************************************************************/ |
| 1428 | /* QLogic ISP2x00 Hardware Support Functions. */ |
| 1429 | /****************************************************************************/ |
| 1430 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 1431 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1432 | qla83xx_nic_core_fw_load(scsi_qla_host_t *vha) |
| 1433 | { |
| 1434 | int rval = QLA_SUCCESS; |
| 1435 | struct qla_hw_data *ha = vha->hw; |
| 1436 | uint32_t idc_major_ver, idc_minor_ver; |
Saurav Kashyap | 711aa7f | 2012-08-22 14:21:15 -0400 | [diff] [blame] | 1437 | uint16_t config[4]; |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1438 | |
| 1439 | qla83xx_idc_lock(vha, 0); |
| 1440 | |
| 1441 | /* SV: TODO: Assign initialization timeout from |
| 1442 | * flash-info / other param |
| 1443 | */ |
| 1444 | ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT; |
| 1445 | ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT; |
| 1446 | |
| 1447 | /* Set our fcoe function presence */ |
| 1448 | if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) { |
| 1449 | ql_dbg(ql_dbg_p3p, vha, 0xb077, |
| 1450 | "Error while setting DRV-Presence.\n"); |
| 1451 | rval = QLA_FUNCTION_FAILED; |
| 1452 | goto exit; |
| 1453 | } |
| 1454 | |
| 1455 | /* Decide the reset ownership */ |
| 1456 | qla83xx_reset_ownership(vha); |
| 1457 | |
| 1458 | /* |
| 1459 | * On first protocol driver load: |
| 1460 | * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery |
| 1461 | * register. |
| 1462 | * Others: Check compatibility with current IDC Major version. |
| 1463 | */ |
| 1464 | qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver); |
| 1465 | if (ha->flags.nic_core_reset_owner) { |
| 1466 | /* Set IDC Major version */ |
| 1467 | idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION; |
| 1468 | qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver); |
| 1469 | |
| 1470 | /* Clearing IDC-Lock-Recovery register */ |
| 1471 | qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0); |
| 1472 | } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) { |
| 1473 | /* |
| 1474 | * Clear further IDC participation if we are not compatible with |
| 1475 | * the current IDC Major Version. |
| 1476 | */ |
| 1477 | ql_log(ql_log_warn, vha, 0xb07d, |
| 1478 | "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n", |
| 1479 | idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION); |
| 1480 | __qla83xx_clear_drv_presence(vha); |
| 1481 | rval = QLA_FUNCTION_FAILED; |
| 1482 | goto exit; |
| 1483 | } |
| 1484 | /* Each function sets its supported Minor version. */ |
| 1485 | qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver); |
| 1486 | idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2)); |
| 1487 | qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver); |
| 1488 | |
Saurav Kashyap | 711aa7f | 2012-08-22 14:21:15 -0400 | [diff] [blame] | 1489 | if (ha->flags.nic_core_reset_owner) { |
| 1490 | memset(config, 0, sizeof(config)); |
| 1491 | if (!qla81xx_get_port_config(vha, config)) |
| 1492 | qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, |
| 1493 | QLA8XXX_DEV_READY); |
| 1494 | } |
| 1495 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1496 | rval = qla83xx_idc_state_handler(vha); |
| 1497 | |
| 1498 | exit: |
| 1499 | qla83xx_idc_unlock(vha, 0); |
| 1500 | |
| 1501 | return rval; |
| 1502 | } |
| 1503 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | /* |
| 1505 | * qla2x00_initialize_adapter |
| 1506 | * Initialize board. |
| 1507 | * |
| 1508 | * Input: |
| 1509 | * ha = adapter block pointer. |
| 1510 | * |
| 1511 | * Returns: |
| 1512 | * 0 = success |
| 1513 | */ |
| 1514 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1515 | qla2x00_initialize_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | { |
| 1517 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1518 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1519 | struct req_que *req = ha->req_q_map[0]; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 1520 | |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 1521 | memset(&vha->qla_stats, 0, sizeof(vha->qla_stats)); |
| 1522 | memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat)); |
| 1523 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | /* Clear adapter flags. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1525 | vha->flags.online = 0; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 1526 | ha->flags.chip_reset_done = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1527 | vha->flags.reset_active = 0; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 1528 | ha->flags.pci_channel_io_perm_failure = 0; |
| 1529 | ha->flags.eeh_busy = 0; |
Joe Carnuccio | fabbb8d | 2013-08-27 01:37:40 -0400 | [diff] [blame] | 1530 | vha->qla_stats.jiffies_at_last_reset = get_jiffies_64(); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1531 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 1532 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 1533 | vha->device_flags = DFLG_NO_CABLE; |
| 1534 | vha->dpc_flags = 0; |
| 1535 | vha->flags.management_server_logged_in = 0; |
| 1536 | vha->marker_needed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | ha->isp_abort_cnt = 0; |
| 1538 | ha->beacon_blink_led = 0; |
| 1539 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1540 | set_bit(0, ha->req_qid_map); |
| 1541 | set_bit(0, ha->rsp_qid_map); |
| 1542 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1543 | ql_dbg(ql_dbg_init, vha, 0x0040, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1544 | "Configuring PCI space...\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1545 | rval = ha->isp_ops->pci_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1546 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1547 | ql_log(ql_log_warn, vha, 0x0044, |
| 1548 | "Unable to configure PCI space.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | return (rval); |
| 1550 | } |
| 1551 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1552 | ha->isp_ops->reset_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1553 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1554 | rval = qla2xxx_get_flash_info(vha); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 1555 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1556 | ql_log(ql_log_fatal, vha, 0x004f, |
| 1557 | "Unable to validate FLASH data.\n"); |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 1558 | return rval; |
| 1559 | } |
| 1560 | |
| 1561 | if (IS_QLA8044(ha)) { |
| 1562 | qla8044_read_reset_template(vha); |
| 1563 | |
| 1564 | /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0. |
| 1565 | * If DONRESET_BIT0 is set, drivers should not set dev_state |
| 1566 | * to NEED_RESET. But if NEED_RESET is set, drivers should |
| 1567 | * should honor the reset. */ |
| 1568 | if (ql2xdontresethba == 1) |
| 1569 | qla8044_set_idc_dontreset(vha); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 1570 | } |
| 1571 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1572 | ha->isp_ops->get_flash_version(vha, req->ring); |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1573 | ql_dbg(ql_dbg_init, vha, 0x0061, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1574 | "Configure NVRAM parameters...\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1575 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1576 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 1578 | if (ha->flags.disable_serdes) { |
| 1579 | /* Mask HBA via NVRAM settings? */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1580 | ql_log(ql_log_info, vha, 0x0077, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1581 | "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name); |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 1582 | return QLA_FUNCTION_FAILED; |
| 1583 | } |
| 1584 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1585 | ql_dbg(ql_dbg_init, vha, 0x0078, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1586 | "Verifying loaded RISC code...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1588 | if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) { |
| 1589 | rval = ha->isp_ops->chip_diag(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 1590 | if (rval) |
| 1591 | return (rval); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1592 | rval = qla2x00_setup_chip(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 1593 | if (rval) |
| 1594 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1596 | |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1597 | if (IS_QLA84XX(ha)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1598 | ha->cs84xx = qla84xx_get_chip(vha); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1599 | if (!ha->cs84xx) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1600 | ql_log(ql_log_warn, vha, 0x00d0, |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1601 | "Unable to configure ISP84XX.\n"); |
| 1602 | return QLA_FUNCTION_FAILED; |
| 1603 | } |
| 1604 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1605 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 1606 | if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1607 | rval = qla2x00_init_rings(vha); |
| 1608 | |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 1609 | ha->flags.chip_reset_done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 1611 | if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) { |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 1612 | /* Issue verify 84xx FW IOCB to complete 84xx initialization */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 1613 | rval = qla84xx_init_chip(vha); |
| 1614 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1615 | ql_log(ql_log_warn, vha, 0x00d4, |
| 1616 | "Unable to initialize ISP84XX.\n"); |
Bart Van Assche | 8d2b21d | 2015-06-04 15:58:09 -0700 | [diff] [blame] | 1617 | qla84xx_put_chip(vha); |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 1618 | } |
| 1619 | } |
| 1620 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1621 | /* Load the NIC Core f/w if we are the first protocol driver. */ |
| 1622 | if (IS_QLA8031(ha)) { |
| 1623 | rval = qla83xx_nic_core_fw_load(vha); |
| 1624 | if (rval) |
| 1625 | ql_log(ql_log_warn, vha, 0x0124, |
| 1626 | "Error in initializing NIC Core f/w.\n"); |
| 1627 | } |
| 1628 | |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 1629 | if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)) |
| 1630 | qla24xx_read_fcp_prio_cfg(vha); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 1631 | |
Joe Carnuccio | c46e65c | 2013-08-27 01:37:35 -0400 | [diff] [blame] | 1632 | if (IS_P3P_TYPE(ha)) |
| 1633 | qla82xx_set_driver_version(vha, QLA2XXX_VERSION); |
| 1634 | else |
| 1635 | qla25xx_set_driver_version(vha, QLA2XXX_VERSION); |
| 1636 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1637 | return (rval); |
| 1638 | } |
| 1639 | |
| 1640 | /** |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1641 | * qla2100_pci_config() - Setup ISP21xx PCI configuration registers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1642 | * @ha: HA context |
| 1643 | * |
| 1644 | * Returns 0 on success. |
| 1645 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1646 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1647 | qla2100_pci_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1649 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1650 | unsigned long flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1651 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1652 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 1655 | pci_try_set_mwi(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1658 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 1660 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 1661 | pci_disable_rom(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1663 | /* Get PCI bus information. */ |
| 1664 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1665 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1666 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1667 | |
| 1668 | return QLA_SUCCESS; |
| 1669 | } |
| 1670 | |
| 1671 | /** |
| 1672 | * qla2300_pci_config() - Setup ISP23xx PCI configuration registers. |
| 1673 | * @ha: HA context |
| 1674 | * |
| 1675 | * Returns 0 on success. |
| 1676 | */ |
| 1677 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1678 | qla2300_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1679 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1680 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1681 | unsigned long flags = 0; |
| 1682 | uint32_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1683 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1684 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1685 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1686 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 1687 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1688 | |
| 1689 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1690 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1691 | |
| 1692 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 1693 | w &= ~PCI_COMMAND_INTX_DISABLE; |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1694 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1695 | |
| 1696 | /* |
| 1697 | * If this is a 2300 card and not 2312, reset the |
| 1698 | * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately, |
| 1699 | * the 2310 also reports itself as a 2300 so we need to get the |
| 1700 | * fb revision level -- a 6 indicates it really is a 2300 and |
| 1701 | * not a 2310. |
| 1702 | */ |
| 1703 | if (IS_QLA2300(ha)) { |
| 1704 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1705 | |
| 1706 | /* Pause RISC. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1707 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1708 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1709 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1710 | break; |
| 1711 | |
| 1712 | udelay(10); |
| 1713 | } |
| 1714 | |
| 1715 | /* Select FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1716 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 1717 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1718 | |
| 1719 | /* Get the fb rev level */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1720 | ha->fb_rev = RD_FB_CMD_REG(ha, reg); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1721 | |
| 1722 | if (ha->fb_rev == FPM_2300) |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1723 | pci_clear_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1724 | |
| 1725 | /* Deselect FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1726 | WRT_REG_WORD(®->ctrl_status, 0x0); |
| 1727 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1728 | |
| 1729 | /* Release RISC module. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1730 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1731 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1732 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1733 | break; |
| 1734 | |
| 1735 | udelay(10); |
| 1736 | } |
| 1737 | |
| 1738 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1739 | } |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1740 | |
| 1741 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 1742 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 1743 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1744 | |
| 1745 | /* Get PCI bus information. */ |
| 1746 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1747 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1748 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1749 | |
| 1750 | return QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1754 | * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers. |
| 1755 | * @ha: HA context |
| 1756 | * |
| 1757 | * Returns 0 on success. |
| 1758 | */ |
| 1759 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1760 | qla24xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1761 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1762 | uint16_t w; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1763 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1764 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1765 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1766 | |
| 1767 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 1768 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1769 | |
| 1770 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1771 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1772 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 1773 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 1774 | |
| 1775 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 1776 | |
| 1777 | /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */ |
Andrew Vasquez | f85ec18 | 2007-07-19 15:06:01 -0700 | [diff] [blame] | 1778 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX)) |
| 1779 | pcix_set_mmrbc(ha->pdev, 2048); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1780 | |
| 1781 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Jon Mason | e67f132 | 2012-07-10 14:57:56 -0700 | [diff] [blame] | 1782 | if (pci_is_pcie(ha->pdev)) |
Chad Dupuis | 5ffd3a5 | 2012-08-22 14:21:26 -0400 | [diff] [blame] | 1783 | pcie_set_readrq(ha->pdev, 4096); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1784 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 1785 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1786 | |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 1787 | ha->chip_revision = ha->pdev->revision; |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1788 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1789 | /* Get PCI bus information. */ |
| 1790 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1791 | ha->pci_attr = RD_REG_DWORD(®->ctrl_status); |
| 1792 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1793 | |
| 1794 | return QLA_SUCCESS; |
| 1795 | } |
| 1796 | |
| 1797 | /** |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1798 | * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers. |
| 1799 | * @ha: HA context |
| 1800 | * |
| 1801 | * Returns 0 on success. |
| 1802 | */ |
| 1803 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1804 | qla25xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1805 | { |
| 1806 | uint16_t w; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1807 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1808 | |
| 1809 | pci_set_master(ha->pdev); |
| 1810 | pci_try_set_mwi(ha->pdev); |
| 1811 | |
| 1812 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
| 1813 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
| 1814 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 1815 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 1816 | |
| 1817 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Jon Mason | e67f132 | 2012-07-10 14:57:56 -0700 | [diff] [blame] | 1818 | if (pci_is_pcie(ha->pdev)) |
Chad Dupuis | 5ffd3a5 | 2012-08-22 14:21:26 -0400 | [diff] [blame] | 1819 | pcie_set_readrq(ha->pdev, 4096); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1820 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 1821 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1822 | |
| 1823 | ha->chip_revision = ha->pdev->revision; |
| 1824 | |
| 1825 | return QLA_SUCCESS; |
| 1826 | } |
| 1827 | |
| 1828 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | * qla2x00_isp_firmware() - Choose firmware image. |
| 1830 | * @ha: HA context |
| 1831 | * |
| 1832 | * Returns 0 on success. |
| 1833 | */ |
| 1834 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1835 | qla2x00_isp_firmware(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | { |
| 1837 | int rval; |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 1838 | uint16_t loop_id, topo, sw_cap; |
| 1839 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1840 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1841 | |
| 1842 | /* Assume loading risc code */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1843 | rval = QLA_FUNCTION_FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | |
| 1845 | if (ha->flags.disable_risc_code_load) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1846 | ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | |
| 1848 | /* Verify checksum of loaded RISC code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1849 | rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address); |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 1850 | if (rval == QLA_SUCCESS) { |
| 1851 | /* And, verify we are not in ROM code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1852 | rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa, |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 1853 | &area, &domain, &topo, &sw_cap); |
| 1854 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | } |
| 1856 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1857 | if (rval) |
| 1858 | ql_dbg(ql_dbg_init, vha, 0x007a, |
| 1859 | "**** Load RISC code ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | |
| 1861 | return (rval); |
| 1862 | } |
| 1863 | |
| 1864 | /** |
| 1865 | * qla2x00_reset_chip() - Reset ISP chip. |
| 1866 | * @ha: HA context |
| 1867 | * |
| 1868 | * Returns 0 on success. |
| 1869 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1870 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1871 | qla2x00_reset_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | { |
| 1873 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1874 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1875 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | uint32_t cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | uint16_t cmd; |
| 1878 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 1879 | if (unlikely(pci_channel_offline(ha->pdev))) |
| 1880 | return; |
| 1881 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1882 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | |
| 1884 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1885 | |
| 1886 | /* Turn off master enable */ |
| 1887 | cmd = 0; |
| 1888 | pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd); |
| 1889 | cmd &= ~PCI_COMMAND_MASTER; |
| 1890 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 1891 | |
| 1892 | if (!IS_QLA2100(ha)) { |
| 1893 | /* Pause RISC. */ |
| 1894 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
| 1895 | if (IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 1896 | for (cnt = 0; cnt < 30000; cnt++) { |
| 1897 | if ((RD_REG_WORD(®->hccr) & |
| 1898 | HCCR_RISC_PAUSE) != 0) |
| 1899 | break; |
| 1900 | udelay(100); |
| 1901 | } |
| 1902 | } else { |
| 1903 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 1904 | udelay(10); |
| 1905 | } |
| 1906 | |
| 1907 | /* Select FPM registers. */ |
| 1908 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 1909 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 1910 | |
| 1911 | /* FPM Soft Reset. */ |
| 1912 | WRT_REG_WORD(®->fpm_diag_config, 0x100); |
| 1913 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 1914 | |
| 1915 | /* Toggle Fpm Reset. */ |
| 1916 | if (!IS_QLA2200(ha)) { |
| 1917 | WRT_REG_WORD(®->fpm_diag_config, 0x0); |
| 1918 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 1919 | } |
| 1920 | |
| 1921 | /* Select frame buffer registers. */ |
| 1922 | WRT_REG_WORD(®->ctrl_status, 0x10); |
| 1923 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 1924 | |
| 1925 | /* Reset frame buffer FIFOs. */ |
| 1926 | if (IS_QLA2200(ha)) { |
| 1927 | WRT_FB_CMD_REG(ha, reg, 0xa000); |
| 1928 | RD_FB_CMD_REG(ha, reg); /* PCI Posting. */ |
| 1929 | } else { |
| 1930 | WRT_FB_CMD_REG(ha, reg, 0x00fc); |
| 1931 | |
| 1932 | /* Read back fb_cmd until zero or 3 seconds max */ |
| 1933 | for (cnt = 0; cnt < 3000; cnt++) { |
| 1934 | if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0) |
| 1935 | break; |
| 1936 | udelay(100); |
| 1937 | } |
| 1938 | } |
| 1939 | |
| 1940 | /* Select RISC module registers. */ |
| 1941 | WRT_REG_WORD(®->ctrl_status, 0); |
| 1942 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 1943 | |
| 1944 | /* Reset RISC processor. */ |
| 1945 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 1946 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 1947 | |
| 1948 | /* Release RISC processor. */ |
| 1949 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 1950 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 1951 | } |
| 1952 | |
| 1953 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); |
| 1954 | WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT); |
| 1955 | |
| 1956 | /* Reset ISP chip. */ |
| 1957 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 1958 | |
| 1959 | /* Wait for RISC to recover from reset. */ |
| 1960 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 1961 | /* |
| 1962 | * It is necessary to for a delay here since the card doesn't |
| 1963 | * respond to PCI reads during a reset. On some architectures |
| 1964 | * this will result in an MCA. |
| 1965 | */ |
| 1966 | udelay(20); |
| 1967 | for (cnt = 30000; cnt; cnt--) { |
| 1968 | if ((RD_REG_WORD(®->ctrl_status) & |
| 1969 | CSR_ISP_SOFT_RESET) == 0) |
| 1970 | break; |
| 1971 | udelay(100); |
| 1972 | } |
| 1973 | } else |
| 1974 | udelay(10); |
| 1975 | |
| 1976 | /* Reset RISC processor. */ |
| 1977 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 1978 | |
| 1979 | WRT_REG_WORD(®->semaphore, 0); |
| 1980 | |
| 1981 | /* Release RISC processor. */ |
| 1982 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 1983 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 1984 | |
| 1985 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 1986 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | ffb39f0 | 2006-05-17 15:09:06 -0700 | [diff] [blame] | 1987 | if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1989 | |
| 1990 | udelay(100); |
| 1991 | } |
| 1992 | } else |
| 1993 | udelay(100); |
| 1994 | |
| 1995 | /* Turn on master enable */ |
| 1996 | cmd |= PCI_COMMAND_MASTER; |
| 1997 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 1998 | |
| 1999 | /* Disable RISC pause on FPM parity error. */ |
| 2000 | if (!IS_QLA2100(ha)) { |
| 2001 | WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE); |
| 2002 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 2003 | } |
| 2004 | |
| 2005 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2006 | } |
| 2007 | |
| 2008 | /** |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2009 | * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC. |
| 2010 | * |
| 2011 | * Returns 0 on success. |
| 2012 | */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 2013 | static int |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2014 | qla81xx_reset_mpi(scsi_qla_host_t *vha) |
| 2015 | { |
| 2016 | uint16_t mb[4] = {0x1010, 0, 1, 0}; |
| 2017 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2018 | if (!IS_QLA81XX(vha->hw)) |
| 2019 | return QLA_SUCCESS; |
| 2020 | |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2021 | return qla81xx_write_mpi_register(vha, mb); |
| 2022 | } |
| 2023 | |
| 2024 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2025 | * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC. |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2026 | * @ha: HA context |
| 2027 | * |
| 2028 | * Returns 0 on success. |
| 2029 | */ |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2030 | static inline int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2031 | qla24xx_reset_risc(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2032 | { |
| 2033 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2034 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2035 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2036 | uint32_t cnt; |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2037 | uint16_t wd; |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2038 | static int abts_cnt; /* ISP abort retry counts */ |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2039 | int rval = QLA_SUCCESS; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2040 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2041 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2042 | |
| 2043 | /* Reset RISC. */ |
| 2044 | WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
| 2045 | for (cnt = 0; cnt < 30000; cnt++) { |
| 2046 | if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0) |
| 2047 | break; |
| 2048 | |
| 2049 | udelay(10); |
| 2050 | } |
| 2051 | |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2052 | if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE)) |
| 2053 | set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags); |
| 2054 | |
| 2055 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e, |
| 2056 | "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n", |
| 2057 | RD_REG_DWORD(®->hccr), |
| 2058 | RD_REG_DWORD(®->ctrl_status), |
| 2059 | (RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE)); |
| 2060 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2061 | WRT_REG_DWORD(®->ctrl_status, |
| 2062 | CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2063 | pci_read_config_word(ha->pdev, PCI_COMMAND, &wd); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2064 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2065 | udelay(100); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2066 | |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2067 | /* Wait for firmware to complete NVRAM accesses. */ |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2068 | RD_REG_WORD(®->mailbox0); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2069 | for (cnt = 10000; RD_REG_WORD(®->mailbox0) != 0 && |
| 2070 | rval == QLA_SUCCESS; cnt--) { |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2071 | barrier(); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2072 | if (cnt) |
| 2073 | udelay(5); |
| 2074 | else |
| 2075 | rval = QLA_FUNCTION_TIMEOUT; |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2076 | } |
| 2077 | |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2078 | if (rval == QLA_SUCCESS) |
| 2079 | set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags); |
| 2080 | |
| 2081 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f, |
| 2082 | "HCCR: 0x%x, MailBox0 Status 0x%x\n", |
| 2083 | RD_REG_DWORD(®->hccr), |
| 2084 | RD_REG_DWORD(®->mailbox0)); |
| 2085 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2086 | /* Wait for soft-reset to complete. */ |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2087 | RD_REG_DWORD(®->ctrl_status); |
Quinn Tran | 200ffb1 | 2016-12-23 18:06:12 -0800 | [diff] [blame] | 2088 | for (cnt = 0; cnt < 60; cnt++) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2089 | barrier(); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2090 | if ((RD_REG_DWORD(®->ctrl_status) & |
| 2091 | CSRX_ISP_SOFT_RESET) == 0) |
| 2092 | break; |
| 2093 | |
| 2094 | udelay(5); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2095 | } |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2096 | if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_ISP_SOFT_RESET)) |
| 2097 | set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags); |
| 2098 | |
| 2099 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d, |
| 2100 | "HCCR: 0x%x, Soft Reset status: 0x%x\n", |
| 2101 | RD_REG_DWORD(®->hccr), |
| 2102 | RD_REG_DWORD(®->ctrl_status)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2103 | |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2104 | /* If required, do an MPI FW reset now */ |
| 2105 | if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) { |
| 2106 | if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) { |
| 2107 | if (++abts_cnt < 5) { |
| 2108 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 2109 | set_bit(MPI_RESET_NEEDED, &vha->dpc_flags); |
| 2110 | } else { |
| 2111 | /* |
| 2112 | * We exhausted the ISP abort retries. We have to |
| 2113 | * set the board offline. |
| 2114 | */ |
| 2115 | abts_cnt = 0; |
| 2116 | vha->flags.online = 0; |
| 2117 | } |
| 2118 | } |
| 2119 | } |
| 2120 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2121 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 2122 | RD_REG_DWORD(®->hccr); |
| 2123 | |
| 2124 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 2125 | RD_REG_DWORD(®->hccr); |
| 2126 | |
| 2127 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET); |
| 2128 | RD_REG_DWORD(®->hccr); |
| 2129 | |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2130 | RD_REG_WORD(®->mailbox0); |
Quinn Tran | 200ffb1 | 2016-12-23 18:06:12 -0800 | [diff] [blame] | 2131 | for (cnt = 60; RD_REG_WORD(®->mailbox0) != 0 && |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2132 | rval == QLA_SUCCESS; cnt--) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2133 | barrier(); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2134 | if (cnt) |
| 2135 | udelay(5); |
| 2136 | else |
| 2137 | rval = QLA_FUNCTION_TIMEOUT; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2138 | } |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2139 | if (rval == QLA_SUCCESS) |
| 2140 | set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags); |
| 2141 | |
| 2142 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e, |
| 2143 | "Host Risc 0x%x, mailbox0 0x%x\n", |
| 2144 | RD_REG_DWORD(®->hccr), |
| 2145 | RD_REG_WORD(®->mailbox0)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2146 | |
| 2147 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 124f85e | 2009-01-05 11:18:06 -0800 | [diff] [blame] | 2148 | |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2149 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f, |
| 2150 | "Driver in %s mode\n", |
| 2151 | IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling"); |
| 2152 | |
Andrew Vasquez | 124f85e | 2009-01-05 11:18:06 -0800 | [diff] [blame] | 2153 | if (IS_NOPOLLING_TYPE(ha)) |
| 2154 | ha->isp_ops->enable_intrs(ha); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2155 | |
| 2156 | return rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2157 | } |
| 2158 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2159 | static void |
| 2160 | qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data) |
| 2161 | { |
| 2162 | struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24; |
| 2163 | |
| 2164 | WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET); |
| 2165 | *data = RD_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET); |
| 2166 | |
| 2167 | } |
| 2168 | |
| 2169 | static void |
| 2170 | qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data) |
| 2171 | { |
| 2172 | struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24; |
| 2173 | |
| 2174 | WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET); |
| 2175 | WRT_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET, data); |
| 2176 | } |
| 2177 | |
| 2178 | static void |
| 2179 | qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha) |
| 2180 | { |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2181 | uint32_t wd32 = 0; |
| 2182 | uint delta_msec = 100; |
| 2183 | uint elapsed_msec = 0; |
| 2184 | uint timeout_msec; |
| 2185 | ulong n; |
| 2186 | |
Joe Carnuccio | cc79076 | 2015-08-04 13:37:53 -0400 | [diff] [blame] | 2187 | if (vha->hw->pdev->subsystem_device != 0x0175 && |
| 2188 | vha->hw->pdev->subsystem_device != 0x0240) |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2189 | return; |
| 2190 | |
Joe Carnuccio | 8dd7e3a | 2015-08-04 13:37:54 -0400 | [diff] [blame] | 2191 | WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE); |
| 2192 | udelay(100); |
| 2193 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2194 | attempt: |
| 2195 | timeout_msec = TIMEOUT_SEMAPHORE; |
| 2196 | n = timeout_msec / delta_msec; |
| 2197 | while (n--) { |
| 2198 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET); |
| 2199 | qla25xx_read_risc_sema_reg(vha, &wd32); |
| 2200 | if (wd32 & RISC_SEMAPHORE) |
| 2201 | break; |
| 2202 | msleep(delta_msec); |
| 2203 | elapsed_msec += delta_msec; |
| 2204 | if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED) |
| 2205 | goto force; |
| 2206 | } |
| 2207 | |
| 2208 | if (!(wd32 & RISC_SEMAPHORE)) |
| 2209 | goto force; |
| 2210 | |
| 2211 | if (!(wd32 & RISC_SEMAPHORE_FORCE)) |
| 2212 | goto acquired; |
| 2213 | |
| 2214 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR); |
| 2215 | timeout_msec = TIMEOUT_SEMAPHORE_FORCE; |
| 2216 | n = timeout_msec / delta_msec; |
| 2217 | while (n--) { |
| 2218 | qla25xx_read_risc_sema_reg(vha, &wd32); |
| 2219 | if (!(wd32 & RISC_SEMAPHORE_FORCE)) |
| 2220 | break; |
| 2221 | msleep(delta_msec); |
| 2222 | elapsed_msec += delta_msec; |
| 2223 | if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED) |
| 2224 | goto force; |
| 2225 | } |
| 2226 | |
| 2227 | if (wd32 & RISC_SEMAPHORE_FORCE) |
| 2228 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR); |
| 2229 | |
| 2230 | goto attempt; |
| 2231 | |
| 2232 | force: |
| 2233 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET); |
| 2234 | |
| 2235 | acquired: |
| 2236 | return; |
| 2237 | } |
| 2238 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2239 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2240 | * qla24xx_reset_chip() - Reset ISP24xx chip. |
| 2241 | * @ha: HA context |
| 2242 | * |
| 2243 | * Returns 0 on success. |
| 2244 | */ |
| 2245 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2246 | qla24xx_reset_chip(scsi_qla_host_t *vha) |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2247 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2248 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 2249 | |
| 2250 | if (pci_channel_offline(ha->pdev) && |
| 2251 | ha->flags.pci_channel_io_perm_failure) { |
| 2252 | return; |
| 2253 | } |
| 2254 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 2255 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2256 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2257 | qla25xx_manipulate_risc_semaphore(vha); |
| 2258 | |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2259 | /* Perform RISC reset. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2260 | qla24xx_reset_risc(vha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2261 | } |
| 2262 | |
| 2263 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2264 | * qla2x00_chip_diag() - Test chip for proper operation. |
| 2265 | * @ha: HA context |
| 2266 | * |
| 2267 | * Returns 0 on success. |
| 2268 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2269 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2270 | qla2x00_chip_diag(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | { |
| 2272 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2273 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2274 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2275 | unsigned long flags = 0; |
| 2276 | uint16_t data; |
| 2277 | uint32_t cnt; |
| 2278 | uint16_t mb[5]; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2279 | struct req_que *req = ha->req_q_map[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | |
| 2281 | /* Assume a failed state */ |
| 2282 | rval = QLA_FUNCTION_FAILED; |
| 2283 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2284 | ql_dbg(ql_dbg_init, vha, 0x007b, |
| 2285 | "Testing device at %lx.\n", (u_long)®->flash_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | |
| 2287 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2288 | |
| 2289 | /* Reset ISP chip. */ |
| 2290 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 2291 | |
| 2292 | /* |
| 2293 | * We need to have a delay here since the card will not respond while |
| 2294 | * in reset causing an MCA on some architectures. |
| 2295 | */ |
| 2296 | udelay(20); |
| 2297 | data = qla2x00_debounce_register(®->ctrl_status); |
| 2298 | for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) { |
| 2299 | udelay(5); |
| 2300 | data = RD_REG_WORD(®->ctrl_status); |
| 2301 | barrier(); |
| 2302 | } |
| 2303 | |
| 2304 | if (!cnt) |
| 2305 | goto chip_diag_failed; |
| 2306 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2307 | ql_dbg(ql_dbg_init, vha, 0x007c, |
| 2308 | "Reset register cleared by chip reset.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2309 | |
| 2310 | /* Reset RISC processor. */ |
| 2311 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 2312 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 2313 | |
| 2314 | /* Workaround for QLA2312 PCI parity error */ |
| 2315 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 2316 | data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0)); |
| 2317 | for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) { |
| 2318 | udelay(5); |
| 2319 | data = RD_MAILBOX_REG(ha, reg, 0); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2320 | barrier(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2321 | } |
| 2322 | } else |
| 2323 | udelay(10); |
| 2324 | |
| 2325 | if (!cnt) |
| 2326 | goto chip_diag_failed; |
| 2327 | |
| 2328 | /* Check product ID of chip */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2329 | 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] | 2330 | |
| 2331 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); |
| 2332 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); |
| 2333 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); |
| 2334 | mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4)); |
| 2335 | if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) || |
| 2336 | mb[3] != PROD_ID_3) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2337 | ql_log(ql_log_warn, vha, 0x0062, |
| 2338 | "Wrong product ID = 0x%x,0x%x,0x%x.\n", |
| 2339 | mb[1], mb[2], mb[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2340 | |
| 2341 | goto chip_diag_failed; |
| 2342 | } |
| 2343 | ha->product_id[0] = mb[1]; |
| 2344 | ha->product_id[1] = mb[2]; |
| 2345 | ha->product_id[2] = mb[3]; |
| 2346 | ha->product_id[3] = mb[4]; |
| 2347 | |
| 2348 | /* Adjust fw RISC transfer size */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2349 | if (req->length > 1024) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024; |
| 2351 | else |
| 2352 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2353 | req->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2354 | |
| 2355 | if (IS_QLA2200(ha) && |
| 2356 | RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) { |
| 2357 | /* Limit firmware transfer size with a 2200A */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2358 | ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2359 | |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 2360 | ha->device_type |= DT_ISP2200A; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2361 | ha->fw_transfer_size = 128; |
| 2362 | } |
| 2363 | |
| 2364 | /* Wrap Incoming Mailboxes Test. */ |
| 2365 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2366 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2367 | ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2368 | rval = qla2x00_mbx_reg_test(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2369 | if (rval) |
| 2370 | ql_log(ql_log_warn, vha, 0x0080, |
| 2371 | "Failed mailbox send register test.\n"); |
| 2372 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2373 | /* Flag a successful rval */ |
| 2374 | rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2375 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2376 | |
| 2377 | chip_diag_failed: |
| 2378 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2379 | ql_log(ql_log_info, vha, 0x0081, |
| 2380 | "Chip diagnostics **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2381 | |
| 2382 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2383 | |
| 2384 | return (rval); |
| 2385 | } |
| 2386 | |
| 2387 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2388 | * qla24xx_chip_diag() - Test ISP24xx for proper operation. |
| 2389 | * @ha: HA context |
| 2390 | * |
| 2391 | * Returns 0 on success. |
| 2392 | */ |
| 2393 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2394 | qla24xx_chip_diag(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2395 | { |
| 2396 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2397 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2398 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2399 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 2400 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2401 | return QLA_SUCCESS; |
| 2402 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2403 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2404 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2405 | rval = qla2x00_mbx_reg_test(vha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2406 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2407 | ql_log(ql_log_warn, vha, 0x0082, |
| 2408 | "Failed mailbox send register test.\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2409 | } else { |
| 2410 | /* Flag a successful rval */ |
| 2411 | rval = QLA_SUCCESS; |
| 2412 | } |
| 2413 | |
| 2414 | return rval; |
| 2415 | } |
| 2416 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2417 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2418 | qla2x00_alloc_fw_dump(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2419 | { |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2420 | int rval; |
| 2421 | 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] | 2422 | eft_size, fce_size, mq_size; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2423 | dma_addr_t tc_dma; |
| 2424 | void *tc; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2425 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2426 | struct req_que *req = ha->req_q_map[0]; |
| 2427 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 2428 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2429 | if (ha->fw_dump) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2430 | ql_dbg(ql_dbg_init, vha, 0x00bd, |
| 2431 | "Firmware dump already allocated.\n"); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2432 | return; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 2433 | } |
| 2434 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2435 | ha->fw_dumped = 0; |
Hiral Patel | 61f098d | 2014-04-11 16:54:21 -0400 | [diff] [blame] | 2436 | ha->fw_dump_cap_flags = 0; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2437 | dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0; |
| 2438 | req_q_size = rsp_q_size = 0; |
| 2439 | |
| 2440 | if (IS_QLA27XX(ha)) |
| 2441 | goto try_fce; |
| 2442 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2443 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 2444 | fixed_size = sizeof(struct qla2100_fw_dump); |
| 2445 | } else if (IS_QLA23XX(ha)) { |
| 2446 | fixed_size = offsetof(struct qla2300_fw_dump, data_ram); |
| 2447 | mem_size = (ha->fw_memory_size - 0x11000 + 1) * |
| 2448 | sizeof(uint16_t); |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 2449 | } else if (IS_FWI2_CAPABLE(ha)) { |
Himanshu Madhani | b20f02e | 2015-06-10 11:05:18 -0400 | [diff] [blame] | 2450 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2451 | fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem); |
| 2452 | else if (IS_QLA81XX(ha)) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 2453 | fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem); |
| 2454 | else if (IS_QLA25XX(ha)) |
| 2455 | fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem); |
| 2456 | else |
| 2457 | fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2458 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2459 | mem_size = (ha->fw_memory_size - 0x100000 + 1) * |
| 2460 | sizeof(uint32_t); |
Giridhar Malavali | 050c9bb | 2012-02-09 11:15:33 -0800 | [diff] [blame] | 2461 | if (ha->mqenable) { |
Himanshu Madhani | b20f02e | 2015-06-10 11:05:18 -0400 | [diff] [blame] | 2462 | if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha)) |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2463 | mq_size = sizeof(struct qla2xxx_mq_chain); |
Giridhar Malavali | 050c9bb | 2012-02-09 11:15:33 -0800 | [diff] [blame] | 2464 | /* |
| 2465 | * Allocate maximum buffer size for all queues. |
| 2466 | * Resizing must be done at end-of-dump processing. |
| 2467 | */ |
| 2468 | mq_size += ha->max_req_queues * |
| 2469 | (req->length * sizeof(request_t)); |
| 2470 | mq_size += ha->max_rsp_queues * |
| 2471 | (rsp->length * sizeof(response_t)); |
| 2472 | } |
Arun Easi | 00876ae | 2013-03-25 02:21:37 -0400 | [diff] [blame] | 2473 | if (ha->tgt.atio_ring) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2474 | mq_size += ha->tgt.atio_q_length * sizeof(request_t); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2475 | /* Allocate memory for Fibre Channel Event Buffer. */ |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2476 | if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) && |
| 2477 | !IS_QLA27XX(ha)) |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2478 | goto try_eft; |
| 2479 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2480 | try_fce: |
| 2481 | if (ha->fce) |
| 2482 | dma_free_coherent(&ha->pdev->dev, |
| 2483 | FCE_SIZE, ha->fce, ha->fce_dma); |
| 2484 | |
| 2485 | /* Allocate memory for Fibre Channel Event Buffer. */ |
Joe Perches | 0ea85b5 | 2014-06-15 13:37:51 -0700 | [diff] [blame] | 2486 | tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma, |
| 2487 | GFP_KERNEL); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2488 | if (!tc) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2489 | ql_log(ql_log_warn, vha, 0x00be, |
| 2490 | "Unable to allocate (%d KB) for FCE.\n", |
| 2491 | FCE_SIZE / 1024); |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 2492 | goto try_eft; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2493 | } |
| 2494 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2495 | rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2496 | ha->fce_mb, &ha->fce_bufs); |
| 2497 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2498 | ql_log(ql_log_warn, vha, 0x00bf, |
| 2499 | "Unable to initialize FCE (%d).\n", rval); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2500 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, |
| 2501 | tc_dma); |
| 2502 | ha->flags.fce_enabled = 0; |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 2503 | goto try_eft; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2504 | } |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2505 | ql_dbg(ql_dbg_init, vha, 0x00c0, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2506 | "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2507 | |
Giridhar Malavali | 7d9dade | 2009-03-24 09:07:58 -0700 | [diff] [blame] | 2508 | fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2509 | ha->flags.fce_enabled = 1; |
| 2510 | ha->fce_dma = tc_dma; |
| 2511 | ha->fce = tc; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2512 | |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2513 | try_eft: |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2514 | if (ha->eft) |
| 2515 | dma_free_coherent(&ha->pdev->dev, |
| 2516 | EFT_SIZE, ha->eft, ha->eft_dma); |
| 2517 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2518 | /* Allocate memory for Extended Trace Buffer. */ |
Joe Perches | 0ea85b5 | 2014-06-15 13:37:51 -0700 | [diff] [blame] | 2519 | tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma, |
| 2520 | GFP_KERNEL); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2521 | if (!tc) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2522 | ql_log(ql_log_warn, vha, 0x00c1, |
| 2523 | "Unable to allocate (%d KB) for EFT.\n", |
| 2524 | EFT_SIZE / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2525 | goto cont_alloc; |
| 2526 | } |
| 2527 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2528 | rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2529 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2530 | ql_log(ql_log_warn, vha, 0x00c2, |
| 2531 | "Unable to initialize EFT (%d).\n", rval); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2532 | dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, |
| 2533 | tc_dma); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2534 | goto cont_alloc; |
| 2535 | } |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2536 | ql_dbg(ql_dbg_init, vha, 0x00c3, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2537 | "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2538 | |
| 2539 | eft_size = EFT_SIZE; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2540 | ha->eft_dma = tc_dma; |
| 2541 | ha->eft = tc; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2542 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2543 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2544 | cont_alloc: |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2545 | if (IS_QLA27XX(ha)) { |
| 2546 | if (!ha->fw_dump_template) { |
| 2547 | ql_log(ql_log_warn, vha, 0x00ba, |
| 2548 | "Failed missing fwdump template\n"); |
| 2549 | return; |
| 2550 | } |
| 2551 | dump_size = qla27xx_fwdt_calculate_dump_size(vha); |
| 2552 | ql_dbg(ql_dbg_init, vha, 0x00fa, |
| 2553 | "-> allocating fwdump (%x bytes)...\n", dump_size); |
| 2554 | goto allocate; |
| 2555 | } |
| 2556 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2557 | req_q_size = req->length * sizeof(request_t); |
| 2558 | rsp_q_size = rsp->length * sizeof(response_t); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2559 | dump_size = offsetof(struct qla2xxx_fw_dump, isp); |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 2560 | 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] | 2561 | ha->chain_offset = dump_size; |
| 2562 | dump_size += mq_size + fce_size; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2563 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2564 | allocate: |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 2565 | ha->fw_dump = vmalloc(dump_size); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2566 | if (!ha->fw_dump) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2567 | ql_log(ql_log_warn, vha, 0x00c4, |
| 2568 | "Unable to allocate (%d KB) for firmware dump.\n", |
| 2569 | dump_size / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2570 | |
Madhuranath Iyengar | e30d175 | 2010-10-15 11:27:46 -0700 | [diff] [blame] | 2571 | if (ha->fce) { |
| 2572 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce, |
| 2573 | ha->fce_dma); |
| 2574 | ha->fce = NULL; |
| 2575 | ha->fce_dma = 0; |
| 2576 | } |
| 2577 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2578 | if (ha->eft) { |
| 2579 | dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft, |
| 2580 | ha->eft_dma); |
| 2581 | ha->eft = NULL; |
| 2582 | ha->eft_dma = 0; |
| 2583 | } |
| 2584 | return; |
| 2585 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2586 | ha->fw_dump_len = dump_size; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2587 | ql_dbg(ql_dbg_init, vha, 0x00c5, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2588 | "Allocated (%d KB) for firmware dump.\n", dump_size / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2589 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2590 | if (IS_QLA27XX(ha)) |
| 2591 | return; |
| 2592 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2593 | ha->fw_dump->signature[0] = 'Q'; |
| 2594 | ha->fw_dump->signature[1] = 'L'; |
| 2595 | ha->fw_dump->signature[2] = 'G'; |
| 2596 | ha->fw_dump->signature[3] = 'C'; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2597 | ha->fw_dump->version = htonl(1); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2598 | |
| 2599 | ha->fw_dump->fixed_size = htonl(fixed_size); |
| 2600 | ha->fw_dump->mem_size = htonl(mem_size); |
| 2601 | ha->fw_dump->req_q_size = htonl(req_q_size); |
| 2602 | ha->fw_dump->rsp_q_size = htonl(rsp_q_size); |
| 2603 | |
| 2604 | ha->fw_dump->eft_size = htonl(eft_size); |
| 2605 | ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma)); |
| 2606 | ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma)); |
| 2607 | |
| 2608 | ha->fw_dump->header_size = |
| 2609 | htonl(offsetof(struct qla2xxx_fw_dump, isp)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2610 | } |
| 2611 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2612 | static int |
| 2613 | qla81xx_mpi_sync(scsi_qla_host_t *vha) |
| 2614 | { |
| 2615 | #define MPS_MASK 0xe0 |
| 2616 | int rval; |
| 2617 | uint16_t dc; |
| 2618 | uint32_t dw; |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2619 | |
| 2620 | if (!IS_QLA81XX(vha->hw)) |
| 2621 | return QLA_SUCCESS; |
| 2622 | |
| 2623 | rval = qla2x00_write_ram_word(vha, 0x7c00, 1); |
| 2624 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2625 | ql_log(ql_log_warn, vha, 0x0105, |
| 2626 | "Unable to acquire semaphore.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2627 | goto done; |
| 2628 | } |
| 2629 | |
| 2630 | pci_read_config_word(vha->hw->pdev, 0x54, &dc); |
| 2631 | rval = qla2x00_read_ram_word(vha, 0x7a15, &dw); |
| 2632 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2633 | ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2634 | goto done_release; |
| 2635 | } |
| 2636 | |
| 2637 | dc &= MPS_MASK; |
| 2638 | if (dc == (dw & MPS_MASK)) |
| 2639 | goto done_release; |
| 2640 | |
| 2641 | dw &= ~MPS_MASK; |
| 2642 | dw |= dc; |
| 2643 | rval = qla2x00_write_ram_word(vha, 0x7a15, dw); |
| 2644 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2645 | ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2646 | } |
| 2647 | |
| 2648 | done_release: |
| 2649 | rval = qla2x00_write_ram_word(vha, 0x7c00, 0); |
| 2650 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2651 | ql_log(ql_log_warn, vha, 0x006d, |
| 2652 | "Unable to release semaphore.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2653 | } |
| 2654 | |
| 2655 | done: |
| 2656 | return rval; |
| 2657 | } |
| 2658 | |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2659 | int |
| 2660 | qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req) |
| 2661 | { |
| 2662 | /* Don't try to reallocate the array */ |
| 2663 | if (req->outstanding_cmds) |
| 2664 | return QLA_SUCCESS; |
| 2665 | |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 2666 | if (!IS_FWI2_CAPABLE(ha)) |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2667 | req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS; |
| 2668 | else { |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 2669 | if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count) |
| 2670 | req->num_outstanding_cmds = ha->cur_fw_xcb_count; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2671 | else |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 2672 | req->num_outstanding_cmds = ha->cur_fw_iocb_count; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2673 | } |
| 2674 | |
| 2675 | req->outstanding_cmds = kzalloc(sizeof(srb_t *) * |
| 2676 | req->num_outstanding_cmds, GFP_KERNEL); |
| 2677 | |
| 2678 | if (!req->outstanding_cmds) { |
| 2679 | /* |
| 2680 | * Try to allocate a minimal size just so we can get through |
| 2681 | * initialization. |
| 2682 | */ |
| 2683 | req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS; |
| 2684 | req->outstanding_cmds = kzalloc(sizeof(srb_t *) * |
| 2685 | req->num_outstanding_cmds, GFP_KERNEL); |
| 2686 | |
| 2687 | if (!req->outstanding_cmds) { |
| 2688 | ql_log(ql_log_fatal, NULL, 0x0126, |
| 2689 | "Failed to allocate memory for " |
| 2690 | "outstanding_cmds for req_que %p.\n", req); |
| 2691 | req->num_outstanding_cmds = 0; |
| 2692 | return QLA_FUNCTION_FAILED; |
| 2693 | } |
| 2694 | } |
| 2695 | |
| 2696 | return QLA_SUCCESS; |
| 2697 | } |
| 2698 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2699 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2700 | * qla2x00_setup_chip() - Load and start RISC firmware. |
| 2701 | * @ha: HA context |
| 2702 | * |
| 2703 | * Returns 0 on success. |
| 2704 | */ |
| 2705 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2706 | qla2x00_setup_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2708 | int rval; |
| 2709 | uint32_t srisc_address = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2710 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 2711 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 2712 | unsigned long flags; |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 2713 | uint16_t fw_major_version; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 2714 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 2715 | if (IS_P3P_TYPE(ha)) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2716 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 2717 | if (rval == QLA_SUCCESS) { |
| 2718 | qla2x00_stop_firmware(vha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2719 | goto enable_82xx_npiv; |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 2720 | } else |
Giridhar Malavali | b963752 | 2010-05-28 15:08:15 -0700 | [diff] [blame] | 2721 | goto failed; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2722 | } |
| 2723 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 2724 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 2725 | /* Disable SRAM, Instruction RAM and GP RAM parity. */ |
| 2726 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2727 | WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0)); |
| 2728 | RD_REG_WORD(®->hccr); |
| 2729 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2730 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2731 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2732 | qla81xx_mpi_sync(vha); |
| 2733 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2734 | /* Load firmware sequences */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2735 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2736 | if (rval == QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2737 | ql_dbg(ql_dbg_init, vha, 0x00c9, |
| 2738 | "Verifying Checksum of loaded RISC code.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2739 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2740 | rval = qla2x00_verify_checksum(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2741 | if (rval == QLA_SUCCESS) { |
| 2742 | /* Start firmware execution. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2743 | ql_dbg(ql_dbg_init, vha, 0x00ca, |
| 2744 | "Starting firmware.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | |
Himanshu Madhani | b0d6cab | 2015-12-17 14:56:56 -0500 | [diff] [blame] | 2746 | if (ql2xexlogins) |
| 2747 | ha->flags.exlogins_enabled = 1; |
| 2748 | |
Himanshu Madhani | 2f56a7f | 2015-12-17 14:56:57 -0500 | [diff] [blame] | 2749 | if (ql2xexchoffld) |
| 2750 | ha->flags.exchoffld_enabled = 1; |
| 2751 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2752 | rval = qla2x00_execute_fw(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2753 | /* Retrieve firmware information. */ |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 2754 | if (rval == QLA_SUCCESS) { |
Himanshu Madhani | b0d6cab | 2015-12-17 14:56:56 -0500 | [diff] [blame] | 2755 | rval = qla2x00_set_exlogins_buffer(vha); |
| 2756 | if (rval != QLA_SUCCESS) |
| 2757 | goto failed; |
| 2758 | |
Himanshu Madhani | 2f56a7f | 2015-12-17 14:56:57 -0500 | [diff] [blame] | 2759 | rval = qla2x00_set_exchoffld_buffer(vha); |
| 2760 | if (rval != QLA_SUCCESS) |
| 2761 | goto failed; |
| 2762 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2763 | enable_82xx_npiv: |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 2764 | fw_major_version = ha->fw_major_version; |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 2765 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | 3173167 | 2011-08-16 11:31:54 -0700 | [diff] [blame] | 2766 | qla82xx_check_md_needed(vha); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2767 | else |
| 2768 | rval = qla2x00_get_fw_version(vha); |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 2769 | if (rval != QLA_SUCCESS) |
| 2770 | goto failed; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2771 | ha->flags.npiv_supported = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2772 | if (IS_QLA2XXX_MIDTYPE(ha) && |
Mike Hernandez | 946fb89 | 2008-08-13 21:36:59 -0700 | [diff] [blame] | 2773 | (ha->fw_attributes & BIT_2)) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2774 | ha->flags.npiv_supported = 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 2775 | if ((!ha->max_npiv_vports) || |
| 2776 | ((ha->max_npiv_vports + 1) % |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 2777 | MIN_MULTI_ID_FABRIC)) |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 2778 | ha->max_npiv_vports = |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 2779 | MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 2780 | } |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 2781 | qla2x00_get_resource_cnts(vha); |
Andrew Vasquez | d743de6 | 2009-03-24 09:08:15 -0700 | [diff] [blame] | 2782 | |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2783 | /* |
| 2784 | * Allocate the array of outstanding commands |
| 2785 | * now that we know the firmware resources. |
| 2786 | */ |
| 2787 | rval = qla2x00_alloc_outstanding_cmds(ha, |
| 2788 | vha->req); |
| 2789 | if (rval != QLA_SUCCESS) |
| 2790 | goto failed; |
| 2791 | |
Saurav Kashyap | be5ea3c | 2011-11-18 09:02:11 -0800 | [diff] [blame] | 2792 | if (!fw_major_version && ql2xallocfwdump |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 2793 | && !(IS_P3P_TYPE(ha))) |
Giridhar Malavali | 08de284 | 2011-08-16 11:31:44 -0700 | [diff] [blame] | 2794 | qla2x00_alloc_fw_dump(vha); |
Chad Dupuis | 3b6e5b9 | 2013-10-30 03:38:09 -0400 | [diff] [blame] | 2795 | } else { |
| 2796 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2797 | } |
| 2798 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2799 | ql_log(ql_log_fatal, vha, 0x00cd, |
| 2800 | "ISP Firmware failed checksum.\n"); |
| 2801 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2802 | } |
Andrew Vasquez | c74d88a | 2012-08-22 14:21:19 -0400 | [diff] [blame] | 2803 | } else |
| 2804 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2805 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 2806 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 2807 | /* Enable proper parity. */ |
| 2808 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2809 | if (IS_QLA2300(ha)) |
| 2810 | /* SRAM parity */ |
| 2811 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1); |
| 2812 | else |
| 2813 | /* SRAM, Instruction RAM and GP RAM parity */ |
| 2814 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7); |
| 2815 | RD_REG_WORD(®->hccr); |
| 2816 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2817 | } |
| 2818 | |
Chad Dupuis | f3982d8 | 2014-09-25 05:16:57 -0400 | [diff] [blame] | 2819 | if (IS_QLA27XX(ha)) |
| 2820 | ha->flags.fac_supported = 1; |
| 2821 | else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) { |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 2822 | uint32_t size; |
| 2823 | |
| 2824 | rval = qla81xx_fac_get_sector_size(vha, &size); |
| 2825 | if (rval == QLA_SUCCESS) { |
| 2826 | ha->flags.fac_supported = 1; |
| 2827 | ha->fdt_block_size = size << 2; |
| 2828 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2829 | ql_log(ql_log_warn, vha, 0x00ce, |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 2830 | "Unsupported FAC firmware (%d.%02d.%02d).\n", |
| 2831 | ha->fw_major_version, ha->fw_minor_version, |
| 2832 | ha->fw_subminor_version); |
Joe Carnuccio | 1ca60e3 | 2014-02-26 04:15:02 -0500 | [diff] [blame] | 2833 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2834 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2835 | ha->flags.fac_supported = 0; |
| 2836 | rval = QLA_SUCCESS; |
| 2837 | } |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 2838 | } |
| 2839 | } |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 2840 | failed: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2841 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2842 | ql_log(ql_log_fatal, vha, 0x00cf, |
| 2843 | "Setup chip ****FAILED****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | } |
| 2845 | |
| 2846 | return (rval); |
| 2847 | } |
| 2848 | |
| 2849 | /** |
| 2850 | * qla2x00_init_response_q_entries() - Initializes response queue entries. |
| 2851 | * @ha: HA context |
| 2852 | * |
| 2853 | * Beginning of request ring has initialization control block already built |
| 2854 | * by nvram config routine. |
| 2855 | * |
| 2856 | * Returns 0 on success. |
| 2857 | */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2858 | void |
| 2859 | qla2x00_init_response_q_entries(struct rsp_que *rsp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2860 | { |
| 2861 | uint16_t cnt; |
| 2862 | response_t *pkt; |
| 2863 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 2864 | rsp->ring_ptr = rsp->ring; |
| 2865 | rsp->ring_index = 0; |
| 2866 | rsp->status_srb = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2867 | pkt = rsp->ring_ptr; |
| 2868 | for (cnt = 0; cnt < rsp->length; cnt++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2869 | pkt->signature = RESPONSE_PROCESSED; |
| 2870 | pkt++; |
| 2871 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | } |
| 2873 | |
| 2874 | /** |
| 2875 | * qla2x00_update_fw_options() - Read and process firmware options. |
| 2876 | * @ha: HA context |
| 2877 | * |
| 2878 | * Returns 0 on success. |
| 2879 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2880 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2881 | qla2x00_update_fw_options(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2882 | { |
| 2883 | uint16_t swing, emphasis, tx_sens, rx_sens; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2884 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2885 | |
| 2886 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2887 | qla2x00_get_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2888 | |
| 2889 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
| 2890 | return; |
| 2891 | |
| 2892 | /* Serial Link options. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2893 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115, |
| 2894 | "Serial link options.\n"); |
| 2895 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109, |
| 2896 | (uint8_t *)&ha->fw_seriallink_options, |
| 2897 | sizeof(ha->fw_seriallink_options)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | |
| 2899 | ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING; |
| 2900 | if (ha->fw_seriallink_options[3] & BIT_2) { |
| 2901 | ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING; |
| 2902 | |
| 2903 | /* 1G settings */ |
| 2904 | swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0); |
| 2905 | emphasis = (ha->fw_seriallink_options[2] & |
| 2906 | (BIT_4 | BIT_3)) >> 3; |
| 2907 | tx_sens = ha->fw_seriallink_options[0] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2908 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2909 | rx_sens = (ha->fw_seriallink_options[0] & |
| 2910 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 2911 | ha->fw_options[10] = (emphasis << 14) | (swing << 8); |
| 2912 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 2913 | if (rx_sens == 0x0) |
| 2914 | rx_sens = 0x3; |
| 2915 | ha->fw_options[10] |= (tx_sens << 4) | rx_sens; |
| 2916 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 2917 | ha->fw_options[10] |= BIT_5 | |
| 2918 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 2919 | (tx_sens & (BIT_1 | BIT_0)); |
| 2920 | |
| 2921 | /* 2G settings */ |
| 2922 | swing = (ha->fw_seriallink_options[2] & |
| 2923 | (BIT_7 | BIT_6 | BIT_5)) >> 5; |
| 2924 | emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0); |
| 2925 | tx_sens = ha->fw_seriallink_options[1] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2926 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2927 | rx_sens = (ha->fw_seriallink_options[1] & |
| 2928 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 2929 | ha->fw_options[11] = (emphasis << 14) | (swing << 8); |
| 2930 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 2931 | if (rx_sens == 0x0) |
| 2932 | rx_sens = 0x3; |
| 2933 | ha->fw_options[11] |= (tx_sens << 4) | rx_sens; |
| 2934 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 2935 | ha->fw_options[11] |= BIT_5 | |
| 2936 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 2937 | (tx_sens & (BIT_1 | BIT_0)); |
| 2938 | } |
| 2939 | |
| 2940 | /* FCP2 options. */ |
| 2941 | /* Return command IOCBs without waiting for an ABTS to complete. */ |
| 2942 | ha->fw_options[3] |= BIT_13; |
| 2943 | |
| 2944 | /* LED scheme. */ |
| 2945 | if (ha->flags.enable_led_scheme) |
| 2946 | ha->fw_options[2] |= BIT_12; |
| 2947 | |
andrew.vasquez@qlogic.com | 48c02fd | 2006-03-09 14:27:18 -0800 | [diff] [blame] | 2948 | /* Detect ISP6312. */ |
| 2949 | if (IS_QLA6312(ha)) |
| 2950 | ha->fw_options[2] |= BIT_13; |
| 2951 | |
Giridhar Malavali | 088d09d | 2016-07-06 11:14:20 -0400 | [diff] [blame] | 2952 | /* Set Retry FLOGI in case of P2P connection */ |
| 2953 | if (ha->operating_mode == P2P) { |
| 2954 | ha->fw_options[2] |= BIT_3; |
| 2955 | ql_dbg(ql_dbg_disc, vha, 0x2100, |
| 2956 | "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n", |
| 2957 | __func__, ha->fw_options[2]); |
| 2958 | } |
| 2959 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2960 | /* Update firmware options. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2961 | qla2x00_set_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2962 | } |
| 2963 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2964 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2965 | qla24xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2966 | { |
| 2967 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2968 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2969 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 2970 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2971 | return; |
| 2972 | |
Himanshu Madhani | f198caf | 2016-01-27 12:03:30 -0500 | [diff] [blame] | 2973 | /* Hold status IOCBs until ABTS response received. */ |
| 2974 | if (ql2xfwholdabts) |
| 2975 | ha->fw_options[3] |= BIT_12; |
| 2976 | |
Giridhar Malavali | 088d09d | 2016-07-06 11:14:20 -0400 | [diff] [blame] | 2977 | /* Set Retry FLOGI in case of P2P connection */ |
| 2978 | if (ha->operating_mode == P2P) { |
| 2979 | ha->fw_options[2] |= BIT_3; |
| 2980 | ql_dbg(ql_dbg_disc, vha, 0x2101, |
| 2981 | "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n", |
| 2982 | __func__, ha->fw_options[2]); |
| 2983 | } |
| 2984 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame^] | 2985 | /* Move PUREX, ABTS RX & RIDA to ATIOQ */ |
| 2986 | if (ql2xmvasynctoatio) { |
| 2987 | if (qla_tgt_mode_enabled(vha) || |
| 2988 | qla_dual_mode_enabled(vha)) |
| 2989 | ha->fw_options[2] |= BIT_11; |
| 2990 | else |
| 2991 | ha->fw_options[2] &= ~BIT_11; |
| 2992 | } |
| 2993 | |
| 2994 | ql_dbg(ql_dbg_init, vha, 0xffff, |
| 2995 | "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n", |
| 2996 | __func__, ha->fw_options[1], ha->fw_options[2], |
| 2997 | ha->fw_options[3], vha->host->active_mode); |
| 2998 | qla2x00_set_fw_options(vha, ha->fw_options); |
| 2999 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3000 | /* Update Serial Link options. */ |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 3001 | if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3002 | return; |
| 3003 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3004 | rval = qla2x00_set_serdes_params(vha, |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 3005 | le16_to_cpu(ha->fw_seriallink_options24[1]), |
| 3006 | le16_to_cpu(ha->fw_seriallink_options24[2]), |
| 3007 | le16_to_cpu(ha->fw_seriallink_options24[3])); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3008 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3009 | ql_log(ql_log_warn, vha, 0x0104, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3010 | "Unable to update Serial Link options (%x).\n", rval); |
| 3011 | } |
| 3012 | } |
| 3013 | |
| 3014 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3015 | qla2x00_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3016 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3017 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 3018 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3019 | struct req_que *req = ha->req_q_map[0]; |
| 3020 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3021 | |
| 3022 | /* Setup ring parameters in initialization control block. */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3023 | ha->init_cb->request_q_outpointer = cpu_to_le16(0); |
| 3024 | ha->init_cb->response_q_inpointer = cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3025 | ha->init_cb->request_q_length = cpu_to_le16(req->length); |
| 3026 | ha->init_cb->response_q_length = cpu_to_le16(rsp->length); |
| 3027 | ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 3028 | ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 3029 | ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 3030 | 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] | 3031 | |
| 3032 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0); |
| 3033 | WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0); |
| 3034 | WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0); |
| 3035 | WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0); |
| 3036 | RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */ |
| 3037 | } |
| 3038 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3039 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3040 | qla24xx_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3041 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3042 | struct qla_hw_data *ha = vha->hw; |
Bart Van Assche | 118e2ef | 2015-07-09 07:24:27 -0700 | [diff] [blame] | 3043 | device_reg_t *reg = ISP_QUE_REG(ha, 0); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3044 | struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp; |
| 3045 | struct qla_msix_entry *msix; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3046 | struct init_cb_24xx *icb; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3047 | uint16_t rid = 0; |
| 3048 | struct req_que *req = ha->req_q_map[0]; |
| 3049 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3050 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3051 | /* Setup ring parameters in initialization control block. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3052 | icb = (struct init_cb_24xx *)ha->init_cb; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3053 | icb->request_q_outpointer = cpu_to_le16(0); |
| 3054 | icb->response_q_inpointer = cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3055 | icb->request_q_length = cpu_to_le16(req->length); |
| 3056 | icb->response_q_length = cpu_to_le16(rsp->length); |
| 3057 | icb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 3058 | icb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 3059 | icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 3060 | icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3061 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3062 | /* Setup ATIO queue dma pointers for target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3063 | icb->atio_q_inpointer = cpu_to_le16(0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3064 | icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length); |
| 3065 | icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma)); |
| 3066 | icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma)); |
| 3067 | |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3068 | if (IS_SHADOW_REG_CAPABLE(ha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3069 | icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29); |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3070 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 3071 | if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3072 | icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS); |
| 3073 | icb->rid = cpu_to_le16(rid); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3074 | if (ha->flags.msix_enabled) { |
| 3075 | msix = &ha->msix_entries[1]; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3076 | ql_dbg(ql_dbg_init, vha, 0x00fd, |
| 3077 | "Registering vector 0x%x for base que.\n", |
| 3078 | msix->entry); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3079 | icb->msix = cpu_to_le16(msix->entry); |
| 3080 | } |
| 3081 | /* Use alternate PCI bus number */ |
| 3082 | if (MSB(rid)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3083 | icb->firmware_options_2 |= cpu_to_le32(BIT_19); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3084 | /* Use alternate PCI devfn */ |
| 3085 | if (LSB(rid)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3086 | icb->firmware_options_2 |= cpu_to_le32(BIT_18); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3087 | |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 3088 | /* Use Disable MSIX Handshake mode for capable adapters */ |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3089 | if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) && |
| 3090 | (ha->flags.msix_enabled)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3091 | icb->firmware_options_2 &= cpu_to_le32(~BIT_22); |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 3092 | ha->flags.disable_msix_handshake = 1; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3093 | ql_dbg(ql_dbg_init, vha, 0x00fe, |
| 3094 | "MSIX Handshake Disable Mode turned on.\n"); |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 3095 | } else { |
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 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3098 | icb->firmware_options_2 |= cpu_to_le32(BIT_23); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3099 | |
| 3100 | WRT_REG_DWORD(®->isp25mq.req_q_in, 0); |
| 3101 | WRT_REG_DWORD(®->isp25mq.req_q_out, 0); |
| 3102 | WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0); |
| 3103 | WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0); |
| 3104 | } else { |
| 3105 | WRT_REG_DWORD(®->isp24.req_q_in, 0); |
| 3106 | WRT_REG_DWORD(®->isp24.req_q_out, 0); |
| 3107 | WRT_REG_DWORD(®->isp24.rsp_q_in, 0); |
| 3108 | WRT_REG_DWORD(®->isp24.rsp_q_out, 0); |
| 3109 | } |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 3110 | qlt_24xx_config_rings(vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3111 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3112 | /* PCI posting */ |
| 3113 | RD_REG_DWORD(&ioreg->hccr); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3114 | } |
| 3115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3116 | /** |
| 3117 | * qla2x00_init_rings() - Initializes firmware. |
| 3118 | * @ha: HA context |
| 3119 | * |
| 3120 | * Beginning of request ring has initialization control block already built |
| 3121 | * by nvram config routine. |
| 3122 | * |
| 3123 | * Returns 0 on success. |
| 3124 | */ |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3125 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3126 | qla2x00_init_rings(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3127 | { |
| 3128 | int rval; |
| 3129 | unsigned long flags = 0; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3130 | int cnt, que; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3131 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3132 | struct req_que *req; |
| 3133 | struct rsp_que *rsp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3134 | struct mid_init_cb_24xx *mid_init_cb = |
| 3135 | (struct mid_init_cb_24xx *) ha->init_cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3136 | |
| 3137 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3138 | |
| 3139 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 3140 | for (que = 0; que < ha->max_req_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3141 | req = ha->req_q_map[que]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 3142 | if (!req || !test_bit(que, ha->req_qid_map)) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3143 | continue; |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3144 | req->out_ptr = (void *)(req->ring + req->length); |
| 3145 | *req->out_ptr = 0; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 3146 | for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3147 | req->outstanding_cmds[cnt] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3148 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 3149 | req->current_outstanding_cmd = 1; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3150 | |
| 3151 | /* Initialize firmware. */ |
| 3152 | req->ring_ptr = req->ring; |
| 3153 | req->ring_index = 0; |
| 3154 | req->cnt = req->length; |
| 3155 | } |
| 3156 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 3157 | for (que = 0; que < ha->max_rsp_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3158 | rsp = ha->rsp_q_map[que]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 3159 | if (!rsp || !test_bit(que, ha->rsp_qid_map)) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3160 | continue; |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3161 | rsp->in_ptr = (void *)(rsp->ring + rsp->length); |
| 3162 | *rsp->in_ptr = 0; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3163 | /* Initialize response queue entries */ |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3164 | if (IS_QLAFX00(ha)) |
| 3165 | qlafx00_init_response_q_entries(rsp); |
| 3166 | else |
| 3167 | qla2x00_init_response_q_entries(rsp); |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3168 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3169 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3170 | ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; |
| 3171 | ha->tgt.atio_ring_index = 0; |
| 3172 | /* Initialize ATIO queue entries */ |
| 3173 | qlt_init_atio_q_entries(vha); |
| 3174 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3175 | ha->isp_ops->config_rings(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3176 | |
| 3177 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3178 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3179 | ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n"); |
| 3180 | |
| 3181 | if (IS_QLAFX00(ha)) { |
| 3182 | rval = qlafx00_init_firmware(vha, ha->init_cb_size); |
| 3183 | goto next_check; |
| 3184 | } |
| 3185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3186 | /* Update any ISP specific firmware options before initialization. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3187 | ha->isp_ops->update_fw_options(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3188 | |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 3189 | if (ha->flags.npiv_supported) { |
Saurav Kashyap | 45980cc | 2012-08-22 14:21:21 -0400 | [diff] [blame] | 3190 | if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha)) |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 3191 | ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | c48339d | 2008-01-17 09:02:19 -0800 | [diff] [blame] | 3192 | mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports); |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 3193 | } |
| 3194 | |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 3195 | if (IS_FWI2_CAPABLE(ha)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3196 | mid_init_cb->options = cpu_to_le16(BIT_1); |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 3197 | mid_init_cb->init_cb.execution_throttle = |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3198 | cpu_to_le16(ha->cur_fw_xcb_count); |
Joe Carnuccio | 40f3862 | 2016-07-06 11:14:28 -0400 | [diff] [blame] | 3199 | ha->flags.dport_enabled = |
| 3200 | (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0; |
| 3201 | ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n", |
| 3202 | (ha->flags.dport_enabled) ? "enabled" : "disabled"); |
| 3203 | /* FA-WWPN Status */ |
Himanshu Madhani | 2486c62 | 2014-09-25 05:17:00 -0400 | [diff] [blame] | 3204 | ha->flags.fawwpn_enabled = |
Joe Carnuccio | 40f3862 | 2016-07-06 11:14:28 -0400 | [diff] [blame] | 3205 | (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0; |
Himanshu Madhani | 2486c62 | 2014-09-25 05:17:00 -0400 | [diff] [blame] | 3206 | ql_dbg(ql_dbg_init, vha, 0x0141, "FA-WWPN Support: %s.\n", |
| 3207 | (ha->flags.fawwpn_enabled) ? "enabled" : "disabled"); |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 3208 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3209 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3210 | rval = qla2x00_init_firmware(vha, ha->init_cb_size); |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3211 | next_check: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3213 | ql_log(ql_log_fatal, vha, 0x00d2, |
| 3214 | "Init Firmware **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3215 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3216 | ql_dbg(ql_dbg_init, vha, 0x00d3, |
| 3217 | "Init Firmware -- success.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3218 | } |
| 3219 | |
| 3220 | return (rval); |
| 3221 | } |
| 3222 | |
| 3223 | /** |
| 3224 | * qla2x00_fw_ready() - Waits for firmware ready. |
| 3225 | * @ha: HA context |
| 3226 | * |
| 3227 | * Returns 0 on success. |
| 3228 | */ |
| 3229 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3230 | qla2x00_fw_ready(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3231 | { |
| 3232 | int rval; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3233 | unsigned long wtime, mtime, cs84xx_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3234 | uint16_t min_wait; /* Minimum wait time if loop is down */ |
| 3235 | uint16_t wait_time; /* Wait time if loop is coming ready */ |
Joe Carnuccio | b5a340d | 2014-09-25 05:16:48 -0400 | [diff] [blame] | 3236 | uint16_t state[6]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3237 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3238 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3239 | if (IS_QLAFX00(vha->hw)) |
| 3240 | return qlafx00_fw_ready(vha); |
| 3241 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3242 | rval = QLA_SUCCESS; |
| 3243 | |
Chad Dupuis | 33461491 | 2015-04-09 14:59:57 -0400 | [diff] [blame] | 3244 | /* Time to wait for loop down */ |
| 3245 | if (IS_P3P_TYPE(ha)) |
| 3246 | min_wait = 30; |
| 3247 | else |
| 3248 | min_wait = 20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3249 | |
| 3250 | /* |
| 3251 | * Firmware should take at most one RATOV to login, plus 5 seconds for |
| 3252 | * our own processing. |
| 3253 | */ |
| 3254 | if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) { |
| 3255 | wait_time = min_wait; |
| 3256 | } |
| 3257 | |
| 3258 | /* Min wait time if loop down */ |
| 3259 | mtime = jiffies + (min_wait * HZ); |
| 3260 | |
| 3261 | /* wait time before firmware ready */ |
| 3262 | wtime = jiffies + (wait_time * HZ); |
| 3263 | |
| 3264 | /* Wait for ISP to finish LIP */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3265 | if (!vha->flags.init_done) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3266 | ql_log(ql_log_info, vha, 0x801e, |
| 3267 | "Waiting for LIP to complete.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3268 | |
| 3269 | do { |
Andrew Vasquez | 5b93903 | 2012-11-21 02:40:26 -0500 | [diff] [blame] | 3270 | memset(state, -1, sizeof(state)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3271 | rval = qla2x00_get_firmware_state(vha, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3272 | if (rval == QLA_SUCCESS) { |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3273 | if (state[0] < FSTATE_LOSS_OF_SYNC) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3274 | vha->device_flags &= ~DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3275 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3276 | if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3277 | ql_dbg(ql_dbg_taskm, vha, 0x801f, |
| 3278 | "fw_state=%x 84xx=%x.\n", state[0], |
| 3279 | state[2]); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3280 | if ((state[2] & FSTATE_LOGGED_IN) && |
| 3281 | (state[2] & FSTATE_WAITING_FOR_VERIFY)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3282 | ql_dbg(ql_dbg_taskm, vha, 0x8028, |
| 3283 | "Sending verify iocb.\n"); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3284 | |
| 3285 | cs84xx_time = jiffies; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3286 | rval = qla84xx_init_chip(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3287 | if (rval != QLA_SUCCESS) { |
| 3288 | ql_log(ql_log_warn, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 3289 | vha, 0x8007, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3290 | "Init chip failed.\n"); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3291 | break; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3292 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3293 | |
| 3294 | /* Add time taken to initialize. */ |
| 3295 | cs84xx_time = jiffies - cs84xx_time; |
| 3296 | wtime += cs84xx_time; |
| 3297 | mtime += cs84xx_time; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 3298 | ql_dbg(ql_dbg_taskm, vha, 0x8008, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3299 | "Increasing wait time by %ld. " |
| 3300 | "New time %ld.\n", cs84xx_time, |
| 3301 | wtime); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3302 | } |
| 3303 | } else if (state[0] == FSTATE_READY) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3304 | ql_dbg(ql_dbg_taskm, vha, 0x8037, |
| 3305 | "F/W Ready - OK.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3306 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3307 | qla2x00_get_retry_cnt(vha, &ha->retry_count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3308 | &ha->login_timeout, &ha->r_a_tov); |
| 3309 | |
| 3310 | rval = QLA_SUCCESS; |
| 3311 | break; |
| 3312 | } |
| 3313 | |
| 3314 | rval = QLA_FUNCTION_FAILED; |
| 3315 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3316 | if (atomic_read(&vha->loop_down_timer) && |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3317 | state[0] != FSTATE_READY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3318 | /* Loop down. Timeout on min_wait for states |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3319 | * other than Wait for Login. |
| 3320 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3321 | if (time_after_eq(jiffies, mtime)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3322 | ql_log(ql_log_info, vha, 0x8038, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3323 | "Cable is unplugged...\n"); |
| 3324 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3325 | vha->device_flags |= DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3326 | break; |
| 3327 | } |
| 3328 | } |
| 3329 | } else { |
| 3330 | /* Mailbox cmd failed. Timeout on min_wait. */ |
Santosh Vernekar | cdbb0a4f | 2010-05-28 15:08:25 -0700 | [diff] [blame] | 3331 | if (time_after_eq(jiffies, mtime) || |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 3332 | ha->flags.isp82xx_fw_hung) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3333 | break; |
| 3334 | } |
| 3335 | |
| 3336 | if (time_after_eq(jiffies, wtime)) |
| 3337 | break; |
| 3338 | |
| 3339 | /* Delay for a while */ |
| 3340 | msleep(500); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3341 | } while (1); |
| 3342 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3343 | ql_dbg(ql_dbg_taskm, vha, 0x803a, |
Joe Carnuccio | b5a340d | 2014-09-25 05:16:48 -0400 | [diff] [blame] | 3344 | "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0], |
| 3345 | state[1], state[2], state[3], state[4], state[5], jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3346 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 3347 | if (rval && !(vha->device_flags & DFLG_NO_CABLE)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3348 | ql_log(ql_log_warn, vha, 0x803b, |
| 3349 | "Firmware ready **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | } |
| 3351 | |
| 3352 | return (rval); |
| 3353 | } |
| 3354 | |
| 3355 | /* |
| 3356 | * qla2x00_configure_hba |
| 3357 | * Setup adapter context. |
| 3358 | * |
| 3359 | * Input: |
| 3360 | * ha = adapter state pointer. |
| 3361 | * |
| 3362 | * Returns: |
| 3363 | * 0 = success |
| 3364 | * |
| 3365 | * Context: |
| 3366 | * Kernel context. |
| 3367 | */ |
| 3368 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3369 | qla2x00_configure_hba(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3370 | { |
| 3371 | int rval; |
| 3372 | uint16_t loop_id; |
| 3373 | uint16_t topo; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3374 | uint16_t sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | uint8_t al_pa; |
| 3376 | uint8_t area; |
| 3377 | uint8_t domain; |
| 3378 | char connect_type[22]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3379 | struct qla_hw_data *ha = vha->hw; |
Jiri Kosina | f24b5cb | 2012-10-08 09:23:54 +0200 | [diff] [blame] | 3380 | unsigned long flags; |
Joe Carnuccio | 61e1b26 | 2013-02-08 01:57:48 -0500 | [diff] [blame] | 3381 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3382 | |
| 3383 | /* Get host addresses. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3384 | rval = qla2x00_get_adapter_id(vha, |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3385 | &loop_id, &al_pa, &area, &domain, &topo, &sw_cap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3386 | if (rval != QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3387 | if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) || |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3388 | IS_CNA_CAPABLE(ha) || |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 3389 | (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3390 | ql_dbg(ql_dbg_disc, vha, 0x2008, |
| 3391 | "Loop is in a transition state.\n"); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 3392 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3393 | ql_log(ql_log_warn, vha, 0x2009, |
| 3394 | "Unable to get host loop ID.\n"); |
Joe Carnuccio | 61e1b26 | 2013-02-08 01:57:48 -0500 | [diff] [blame] | 3395 | if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) && |
| 3396 | (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) { |
| 3397 | ql_log(ql_log_warn, vha, 0x1151, |
| 3398 | "Doing link init.\n"); |
| 3399 | if (qla24xx_link_initialize(vha) == QLA_SUCCESS) |
| 3400 | return rval; |
| 3401 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3402 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 3403 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3404 | return (rval); |
| 3405 | } |
| 3406 | |
| 3407 | if (topo == 4) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3408 | ql_log(ql_log_info, vha, 0x200a, |
| 3409 | "Cannot get topology - retrying.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3410 | return (QLA_FUNCTION_FAILED); |
| 3411 | } |
| 3412 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3413 | vha->loop_id = loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3414 | |
| 3415 | /* initialize */ |
| 3416 | ha->min_external_loopid = SNS_FIRST_LOOP_ID; |
| 3417 | ha->operating_mode = LOOP; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3418 | ha->switch_cap = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3419 | |
| 3420 | switch (topo) { |
| 3421 | case 0: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3422 | ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3423 | ha->current_topology = ISP_CFG_NL; |
| 3424 | strcpy(connect_type, "(Loop)"); |
| 3425 | break; |
| 3426 | |
| 3427 | case 1: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3428 | ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n"); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3429 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3430 | ha->current_topology = ISP_CFG_FL; |
| 3431 | strcpy(connect_type, "(FL_Port)"); |
| 3432 | break; |
| 3433 | |
| 3434 | case 2: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3435 | 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] | 3436 | ha->operating_mode = P2P; |
| 3437 | ha->current_topology = ISP_CFG_N; |
| 3438 | strcpy(connect_type, "(N_Port-to-N_Port)"); |
| 3439 | break; |
| 3440 | |
| 3441 | case 3: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3442 | 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] | 3443 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3444 | ha->operating_mode = P2P; |
| 3445 | ha->current_topology = ISP_CFG_F; |
| 3446 | strcpy(connect_type, "(F_Port)"); |
| 3447 | break; |
| 3448 | |
| 3449 | default: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3450 | ql_dbg(ql_dbg_disc, vha, 0x200f, |
| 3451 | "HBA in unknown topology %x, using NL.\n", topo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3452 | ha->current_topology = ISP_CFG_NL; |
| 3453 | strcpy(connect_type, "(Loop)"); |
| 3454 | break; |
| 3455 | } |
| 3456 | |
| 3457 | /* Save Host port and loop ID. */ |
| 3458 | /* byte order - Big Endian */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3459 | vha->d_id.b.domain = domain; |
| 3460 | vha->d_id.b.area = area; |
| 3461 | vha->d_id.b.al_pa = al_pa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3462 | |
Jiri Kosina | f24b5cb | 2012-10-08 09:23:54 +0200 | [diff] [blame] | 3463 | spin_lock_irqsave(&ha->vport_slock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3464 | qlt_update_vp_map(vha, SET_AL_PA); |
Jiri Kosina | f24b5cb | 2012-10-08 09:23:54 +0200 | [diff] [blame] | 3465 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3466 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3467 | if (!vha->flags.init_done) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3468 | ql_log(ql_log_info, vha, 0x2010, |
| 3469 | "Topology - %s, Host Loop address 0x%x.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3470 | connect_type, vha->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3471 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3472 | return(rval); |
| 3473 | } |
| 3474 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3475 | inline void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3476 | qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len, |
| 3477 | char *def) |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3478 | { |
| 3479 | char *st, *en; |
| 3480 | uint16_t index; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3481 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | ab67114 | 2009-08-25 11:36:17 -0700 | [diff] [blame] | 3482 | int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) && |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3483 | !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3484 | |
| 3485 | if (memcmp(model, BINZERO, len) != 0) { |
| 3486 | strncpy(ha->model_number, model, len); |
| 3487 | st = en = ha->model_number; |
| 3488 | en += len - 1; |
| 3489 | while (en > st) { |
| 3490 | if (*en != 0x20 && *en != 0x00) |
| 3491 | break; |
| 3492 | *en-- = '\0'; |
| 3493 | } |
| 3494 | |
| 3495 | index = (ha->pdev->subsystem_device & 0xff); |
Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 3496 | if (use_tbl && |
| 3497 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3498 | index < QLA_MODEL_NAMES) |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 3499 | strncpy(ha->model_desc, |
| 3500 | qla2x00_model_name[index * 2 + 1], |
| 3501 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3502 | } else { |
| 3503 | index = (ha->pdev->subsystem_device & 0xff); |
Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 3504 | if (use_tbl && |
| 3505 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3506 | index < QLA_MODEL_NAMES) { |
| 3507 | strcpy(ha->model_number, |
| 3508 | qla2x00_model_name[index * 2]); |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 3509 | strncpy(ha->model_desc, |
| 3510 | qla2x00_model_name[index * 2 + 1], |
| 3511 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3512 | } else { |
| 3513 | strcpy(ha->model_number, def); |
| 3514 | } |
| 3515 | } |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 3516 | if (IS_FWI2_CAPABLE(ha)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3517 | qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc, |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 3518 | sizeof(ha->model_desc)); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3519 | } |
| 3520 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3521 | /* On sparc systems, obtain port and node WWN from firmware |
| 3522 | * properties. |
| 3523 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3524 | 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] | 3525 | { |
| 3526 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3527 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3528 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 3529 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 3530 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3531 | int len; |
| 3532 | |
| 3533 | val = of_get_property(dp, "port-wwn", &len); |
| 3534 | if (val && len >= WWN_SIZE) |
| 3535 | memcpy(nv->port_name, val, WWN_SIZE); |
| 3536 | |
| 3537 | val = of_get_property(dp, "node-wwn", &len); |
| 3538 | if (val && len >= WWN_SIZE) |
| 3539 | memcpy(nv->node_name, val, WWN_SIZE); |
| 3540 | #endif |
| 3541 | } |
| 3542 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3543 | /* |
| 3544 | * NVRAM configuration for ISP 2xxx |
| 3545 | * |
| 3546 | * Input: |
| 3547 | * ha = adapter block pointer. |
| 3548 | * |
| 3549 | * Output: |
| 3550 | * initialization control block in response_ring |
| 3551 | * host adapters parameters in host adapter block |
| 3552 | * |
| 3553 | * Returns: |
| 3554 | * 0 = success. |
| 3555 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3556 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3557 | qla2x00_nvram_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3558 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3559 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3560 | uint8_t chksum = 0; |
| 3561 | uint16_t cnt; |
| 3562 | uint8_t *dptr1, *dptr2; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3563 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3564 | init_cb_t *icb = ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 3565 | nvram_t *nv = ha->nvram; |
| 3566 | uint8_t *ptr = ha->nvram; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 3567 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3568 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3569 | rval = QLA_SUCCESS; |
| 3570 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3571 | /* Determine NVRAM starting address. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3572 | ha->nvram_size = sizeof(nvram_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3573 | ha->nvram_base = 0; |
| 3574 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) |
| 3575 | if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1) |
| 3576 | ha->nvram_base = 0x80; |
| 3577 | |
| 3578 | /* Get NVRAM data and calculate checksum. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3579 | 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] | 3580 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++) |
| 3581 | chksum += *ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3582 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3583 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f, |
| 3584 | "Contents of NVRAM.\n"); |
| 3585 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110, |
| 3586 | (uint8_t *)nv, ha->nvram_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3587 | |
| 3588 | /* Bad NVRAM data, set defaults parameters. */ |
| 3589 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || |
| 3590 | nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) { |
| 3591 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3592 | ql_log(ql_log_warn, vha, 0x0064, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 3593 | "Inconsistent NVRAM " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3594 | "detected: checksum=0x%x id=%c version=0x%x.\n", |
| 3595 | chksum, nv->id[0], nv->nvram_version); |
| 3596 | ql_log(ql_log_warn, vha, 0x0065, |
| 3597 | "Falling back to " |
| 3598 | "functioning (yet invalid -- WWPN) defaults.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3599 | |
| 3600 | /* |
| 3601 | * Set default initialization control block. |
| 3602 | */ |
| 3603 | memset(nv, 0, ha->nvram_size); |
| 3604 | nv->parameter_block_version = ICB_VERSION; |
| 3605 | |
| 3606 | if (IS_QLA23XX(ha)) { |
| 3607 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 3608 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 3609 | nv->add_firmware_options[0] = BIT_5; |
| 3610 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 3611 | nv->frame_payload_size = 2048; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3612 | nv->special_options[1] = BIT_7; |
| 3613 | } else if (IS_QLA2200(ha)) { |
| 3614 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 3615 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 3616 | nv->add_firmware_options[0] = BIT_5; |
| 3617 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 3618 | nv->frame_payload_size = 1024; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3619 | } else if (IS_QLA2100(ha)) { |
| 3620 | nv->firmware_options[0] = BIT_3 | BIT_1; |
| 3621 | nv->firmware_options[1] = BIT_5; |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 3622 | nv->frame_payload_size = 1024; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3623 | } |
| 3624 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3625 | nv->max_iocb_allocation = cpu_to_le16(256); |
| 3626 | nv->execution_throttle = cpu_to_le16(16); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3627 | nv->retry_count = 8; |
| 3628 | nv->retry_delay = 1; |
| 3629 | |
| 3630 | nv->port_name[0] = 33; |
| 3631 | nv->port_name[3] = 224; |
| 3632 | nv->port_name[4] = 139; |
| 3633 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3634 | qla2xxx_nvram_wwn_from_ofw(vha, nv); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3635 | |
| 3636 | nv->login_timeout = 4; |
| 3637 | |
| 3638 | /* |
| 3639 | * Set default host adapter parameters |
| 3640 | */ |
| 3641 | nv->host_p[1] = BIT_2; |
| 3642 | nv->reset_delay = 5; |
| 3643 | nv->port_down_retry_count = 8; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3644 | nv->max_luns_per_target = cpu_to_le16(8); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3645 | nv->link_down_timeout = 60; |
| 3646 | |
| 3647 | rval = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3648 | } |
| 3649 | |
| 3650 | #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2) |
| 3651 | /* |
| 3652 | * The SN2 does not provide BIOS emulation which means you can't change |
| 3653 | * potentially bogus BIOS settings. Force the use of default settings |
| 3654 | * for link rate and frame size. Hope that the rest of the settings |
| 3655 | * are valid. |
| 3656 | */ |
| 3657 | if (ia64_platform_is("sn2")) { |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 3658 | nv->frame_payload_size = 2048; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3659 | if (IS_QLA23XX(ha)) |
| 3660 | nv->special_options[1] = BIT_7; |
| 3661 | } |
| 3662 | #endif |
| 3663 | |
| 3664 | /* Reset Initialization control block */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3665 | memset(icb, 0, ha->init_cb_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3666 | |
| 3667 | /* |
| 3668 | * Setup driver NVRAM options. |
| 3669 | */ |
| 3670 | nv->firmware_options[0] |= (BIT_6 | BIT_1); |
| 3671 | nv->firmware_options[0] &= ~(BIT_5 | BIT_4); |
| 3672 | nv->firmware_options[1] |= (BIT_5 | BIT_0); |
| 3673 | nv->firmware_options[1] &= ~BIT_4; |
| 3674 | |
| 3675 | if (IS_QLA23XX(ha)) { |
| 3676 | nv->firmware_options[0] |= BIT_2; |
| 3677 | nv->firmware_options[0] &= ~BIT_3; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3678 | nv->special_options[0] &= ~BIT_6; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3679 | nv->add_firmware_options[1] |= BIT_5 | BIT_4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3680 | |
| 3681 | if (IS_QLA2300(ha)) { |
| 3682 | if (ha->fb_rev == FPM_2310) { |
| 3683 | strcpy(ha->model_number, "QLA2310"); |
| 3684 | } else { |
| 3685 | strcpy(ha->model_number, "QLA2300"); |
| 3686 | } |
| 3687 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3688 | qla2x00_set_model_info(vha, nv->model_number, |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3689 | sizeof(nv->model_number), "QLA23xx"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3690 | } |
| 3691 | } else if (IS_QLA2200(ha)) { |
| 3692 | nv->firmware_options[0] |= BIT_2; |
| 3693 | /* |
| 3694 | * 'Point-to-point preferred, else loop' is not a safe |
| 3695 | * connection mode setting. |
| 3696 | */ |
| 3697 | if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) == |
| 3698 | (BIT_5 | BIT_4)) { |
| 3699 | /* Force 'loop preferred, else point-to-point'. */ |
| 3700 | nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4); |
| 3701 | nv->add_firmware_options[0] |= BIT_5; |
| 3702 | } |
| 3703 | strcpy(ha->model_number, "QLA22xx"); |
| 3704 | } else /*if (IS_QLA2100(ha))*/ { |
| 3705 | strcpy(ha->model_number, "QLA2100"); |
| 3706 | } |
| 3707 | |
| 3708 | /* |
| 3709 | * Copy over NVRAM RISC parameter block to initialization control block. |
| 3710 | */ |
| 3711 | dptr1 = (uint8_t *)icb; |
| 3712 | dptr2 = (uint8_t *)&nv->parameter_block_version; |
| 3713 | cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version; |
| 3714 | while (cnt--) |
| 3715 | *dptr1++ = *dptr2++; |
| 3716 | |
| 3717 | /* Copy 2nd half. */ |
| 3718 | dptr1 = (uint8_t *)icb->add_firmware_options; |
| 3719 | cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options; |
| 3720 | while (cnt--) |
| 3721 | *dptr1++ = *dptr2++; |
| 3722 | |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 3723 | /* Use alternate WWN? */ |
| 3724 | if (nv->host_p[1] & BIT_7) { |
| 3725 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 3726 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 3727 | } |
| 3728 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3729 | /* Prepare nodename */ |
| 3730 | if ((icb->firmware_options[1] & BIT_6) == 0) { |
| 3731 | /* |
| 3732 | * Firmware will apply the following mask if the nodename was |
| 3733 | * not provided. |
| 3734 | */ |
| 3735 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 3736 | icb->node_name[0] &= 0xF0; |
| 3737 | } |
| 3738 | |
| 3739 | /* |
| 3740 | * Set host adapter parameters. |
| 3741 | */ |
Saurav Kashyap | 3ce8866 | 2011-07-14 12:00:12 -0700 | [diff] [blame] | 3742 | |
| 3743 | /* |
| 3744 | * BIT_7 in the host-parameters section allows for modification to |
| 3745 | * internal driver logging. |
| 3746 | */ |
Andrew Vasquez | 0181944 | 2006-06-23 16:11:10 -0700 | [diff] [blame] | 3747 | if (nv->host_p[0] & BIT_7) |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 3748 | ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3749 | ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0); |
| 3750 | /* Always load RISC code on non ISP2[12]00 chips. */ |
| 3751 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) |
| 3752 | ha->flags.disable_risc_code_load = 0; |
| 3753 | ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0); |
| 3754 | ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0); |
| 3755 | 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] | 3756 | 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] | 3757 | ha->flags.disable_serdes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3758 | |
| 3759 | ha->operating_mode = |
| 3760 | (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 3761 | |
| 3762 | memcpy(ha->fw_seriallink_options, nv->seriallink_options, |
| 3763 | sizeof(ha->fw_seriallink_options)); |
| 3764 | |
| 3765 | /* save HBA serial number */ |
| 3766 | ha->serial0 = icb->port_name[5]; |
| 3767 | ha->serial1 = icb->port_name[6]; |
| 3768 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3769 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 3770 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3771 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3772 | icb->execution_throttle = cpu_to_le16(0xFFFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3773 | |
| 3774 | ha->retry_count = nv->retry_count; |
| 3775 | |
| 3776 | /* Set minimum login_timeout to 4 seconds. */ |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 3777 | if (nv->login_timeout != ql2xlogintimeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3778 | nv->login_timeout = ql2xlogintimeout; |
| 3779 | if (nv->login_timeout < 4) |
| 3780 | nv->login_timeout = 4; |
| 3781 | ha->login_timeout = nv->login_timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3782 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 3783 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 3784 | ha->r_a_tov = 100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3785 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3786 | ha->loop_reset_delay = nv->reset_delay; |
| 3787 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3788 | /* Link Down Timeout = 0: |
| 3789 | * |
| 3790 | * When Port Down timer expires we will start returning |
| 3791 | * I/O's to OS with "DID_NO_CONNECT". |
| 3792 | * |
| 3793 | * Link Down Timeout != 0: |
| 3794 | * |
| 3795 | * The driver waits for the link to come up after link down |
| 3796 | * before returning I/Os to OS with "DID_NO_CONNECT". |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3797 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3798 | if (nv->link_down_timeout == 0) { |
| 3799 | ha->loop_down_abort_time = |
Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 3800 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3801 | } else { |
| 3802 | ha->link_down_timeout = nv->link_down_timeout; |
| 3803 | ha->loop_down_abort_time = |
| 3804 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3805 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3807 | /* |
| 3808 | * Need enough time to try and get the port back. |
| 3809 | */ |
| 3810 | ha->port_down_retry_count = nv->port_down_retry_count; |
| 3811 | if (qlport_down_retry) |
| 3812 | ha->port_down_retry_count = qlport_down_retry; |
| 3813 | /* Set login_retry_count */ |
| 3814 | ha->login_retry_count = nv->retry_count; |
| 3815 | if (ha->port_down_retry_count == nv->port_down_retry_count && |
| 3816 | ha->port_down_retry_count > 3) |
| 3817 | ha->login_retry_count = ha->port_down_retry_count; |
| 3818 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 3819 | ha->login_retry_count = ha->port_down_retry_count; |
| 3820 | if (ql2xloginretrycount) |
| 3821 | ha->login_retry_count = ql2xloginretrycount; |
| 3822 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3823 | icb->lun_enables = cpu_to_le16(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3824 | icb->command_resource_count = 0; |
| 3825 | icb->immediate_notify_resource_count = 0; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3826 | icb->timeout = cpu_to_le16(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3827 | |
| 3828 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 3829 | /* Enable RIO */ |
| 3830 | icb->firmware_options[0] &= ~BIT_3; |
| 3831 | icb->add_firmware_options[0] &= |
| 3832 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 3833 | icb->add_firmware_options[0] |= BIT_2; |
| 3834 | icb->response_accumulation_timer = 3; |
| 3835 | icb->interrupt_delay_timer = 5; |
| 3836 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3837 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3838 | } else { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 3839 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3840 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 3841 | ha->zio_mode = icb->add_firmware_options[0] & |
| 3842 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 3843 | ha->zio_timer = icb->interrupt_delay_timer ? |
| 3844 | icb->interrupt_delay_timer: 2; |
| 3845 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3846 | icb->add_firmware_options[0] &= |
| 3847 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3848 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 3849 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 3850 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 3851 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3852 | ql_log(ql_log_info, vha, 0x0068, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 3853 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 3854 | ha->zio_mode, ha->zio_timer * 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3855 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 3856 | icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode; |
| 3857 | icb->interrupt_delay_timer = (uint8_t)ha->zio_timer; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3858 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3859 | } |
| 3860 | } |
| 3861 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3862 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3863 | ql_log(ql_log_warn, vha, 0x0069, |
| 3864 | "NVRAM configuration failed.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3865 | } |
| 3866 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3867 | } |
| 3868 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3869 | static void |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3870 | qla2x00_rport_del(void *data) |
| 3871 | { |
| 3872 | fc_port_t *fcport = data; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3873 | struct fc_rport *rport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 3874 | unsigned long flags; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3875 | |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 3876 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3877 | rport = fcport->drport ? fcport->drport: fcport->rport; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3878 | fcport->drport = NULL; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 3879 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3880 | if (rport) { |
| 3881 | ql_dbg(ql_dbg_disc, fcport->vha, 0xffff, |
| 3882 | "%s %8phN. rport %p roles %x \n", |
| 3883 | __func__, fcport->port_name, rport, |
| 3884 | rport->roles); |
| 3885 | |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3886 | fc_remote_port_delete(rport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3887 | } |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3888 | } |
| 3889 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3890 | /** |
| 3891 | * qla2x00_alloc_fcport() - Allocate a generic fcport. |
| 3892 | * @ha: HA context |
| 3893 | * @flags: allocation flags |
| 3894 | * |
| 3895 | * Returns a pointer to the allocated fcport, or NULL, if none available. |
| 3896 | */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 3897 | fc_port_t * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3898 | qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3899 | { |
| 3900 | fc_port_t *fcport; |
| 3901 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 3902 | fcport = kzalloc(sizeof(fc_port_t), flags); |
| 3903 | if (!fcport) |
| 3904 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3905 | |
| 3906 | /* Setup fcport template structure. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3907 | fcport->vha = vha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3908 | fcport->port_type = FCT_UNKNOWN; |
| 3909 | fcport->loop_id = FC_NO_LOOP_ID; |
Chad Dupuis | ec426e1 | 2011-03-30 11:46:32 -0700 | [diff] [blame] | 3910 | qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED); |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 3911 | fcport->supported_classes = FC_COS_UNSPECIFIED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3912 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3913 | fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev, |
| 3914 | sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma, |
| 3915 | GFP_ATOMIC); |
| 3916 | fcport->disc_state = DSC_DELETED; |
| 3917 | fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 3918 | fcport->deleted = QLA_SESS_DELETED; |
| 3919 | fcport->login_retry = vha->hw->login_retry_count; |
| 3920 | fcport->login_retry = 5; |
| 3921 | fcport->logout_on_delete = 1; |
| 3922 | |
| 3923 | if (!fcport->ct_desc.ct_sns) { |
| 3924 | ql_log(ql_log_warn, vha, 0xffff, |
| 3925 | "Failed to allocate ct_sns request.\n"); |
| 3926 | kfree(fcport); |
| 3927 | fcport = NULL; |
| 3928 | } |
| 3929 | INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn); |
| 3930 | INIT_LIST_HEAD(&fcport->gnl_entry); |
| 3931 | INIT_LIST_HEAD(&fcport->list); |
| 3932 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 3933 | return fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3934 | } |
| 3935 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3936 | void |
| 3937 | qla2x00_free_fcport(fc_port_t *fcport) |
| 3938 | { |
| 3939 | if (fcport->ct_desc.ct_sns) { |
| 3940 | dma_free_coherent(&fcport->vha->hw->pdev->dev, |
| 3941 | sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns, |
| 3942 | fcport->ct_desc.ct_sns_dma); |
| 3943 | |
| 3944 | fcport->ct_desc.ct_sns = NULL; |
| 3945 | } |
| 3946 | kfree(fcport); |
| 3947 | } |
| 3948 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3949 | /* |
| 3950 | * qla2x00_configure_loop |
| 3951 | * Updates Fibre Channel Device Database with what is actually on loop. |
| 3952 | * |
| 3953 | * Input: |
| 3954 | * ha = adapter block pointer. |
| 3955 | * |
| 3956 | * Returns: |
| 3957 | * 0 = success. |
| 3958 | * 1 = error. |
| 3959 | * 2 = database was full and device was not configured. |
| 3960 | */ |
| 3961 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3962 | qla2x00_configure_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3963 | { |
| 3964 | int rval; |
| 3965 | unsigned long flags, save_flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3966 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3967 | rval = QLA_SUCCESS; |
| 3968 | |
| 3969 | /* Get Initiator ID */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3970 | if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) { |
| 3971 | rval = qla2x00_configure_hba(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3972 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3973 | ql_dbg(ql_dbg_disc, vha, 0x2013, |
| 3974 | "Unable to configure HBA.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3975 | return (rval); |
| 3976 | } |
| 3977 | } |
| 3978 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3979 | save_flags = flags = vha->dpc_flags; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3980 | ql_dbg(ql_dbg_disc, vha, 0x2014, |
| 3981 | "Configure loop -- dpc flags = 0x%lx.\n", flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3982 | |
| 3983 | /* |
| 3984 | * If we have both an RSCN and PORT UPDATE pending then handle them |
| 3985 | * both at the same time. |
| 3986 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3987 | clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 3988 | clear_bit(RSCN_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3989 | |
Michael Hernandez | 3064ff3 | 2009-12-15 21:29:44 -0800 | [diff] [blame] | 3990 | qla2x00_get_data_rate(vha); |
| 3991 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3992 | /* Determine what we need to do */ |
| 3993 | if (ha->current_topology == ISP_CFG_FL && |
| 3994 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 3995 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3996 | set_bit(RSCN_UPDATE, &flags); |
| 3997 | |
| 3998 | } else if (ha->current_topology == ISP_CFG_F && |
| 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 | clear_bit(LOCAL_LOOP_UPDATE, &flags); |
| 4003 | |
Andrew Vasquez | 21333b4 | 2006-05-17 15:09:56 -0700 | [diff] [blame] | 4004 | } else if (ha->current_topology == ISP_CFG_N) { |
| 4005 | clear_bit(RSCN_UPDATE, &flags); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame^] | 4006 | } else if (ha->current_topology == ISP_CFG_NL) { |
| 4007 | clear_bit(RSCN_UPDATE, &flags); |
| 4008 | set_bit(LOCAL_LOOP_UPDATE, &flags); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4009 | } else if (!vha->flags.online || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4010 | (test_bit(ABORT_ISP_ACTIVE, &flags))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4011 | set_bit(RSCN_UPDATE, &flags); |
| 4012 | set_bit(LOCAL_LOOP_UPDATE, &flags); |
| 4013 | } |
| 4014 | |
| 4015 | if (test_bit(LOCAL_LOOP_UPDATE, &flags)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4016 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
| 4017 | ql_dbg(ql_dbg_disc, vha, 0x2015, |
| 4018 | "Loop resync needed, failing.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4019 | rval = QLA_FUNCTION_FAILED; |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4020 | } else |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4021 | rval = qla2x00_configure_local_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4022 | } |
| 4023 | |
| 4024 | if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4025 | if (LOOP_TRANSITION(vha)) { |
| 4026 | ql_dbg(ql_dbg_disc, vha, 0x201e, |
| 4027 | "Needs RSCN update and loop transition.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4028 | rval = QLA_FUNCTION_FAILED; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4029 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4030 | else |
| 4031 | rval = qla2x00_configure_fabric(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4032 | } |
| 4033 | |
| 4034 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4035 | if (atomic_read(&vha->loop_down_timer) || |
| 4036 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4037 | rval = QLA_FUNCTION_FAILED; |
| 4038 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4039 | atomic_set(&vha->loop_state, LOOP_READY); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4040 | ql_dbg(ql_dbg_disc, vha, 0x2069, |
| 4041 | "LOOP READY.\n"); |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 4042 | |
| 4043 | /* |
| 4044 | * Process any ATIO queue entries that came in |
| 4045 | * while we weren't online. |
| 4046 | */ |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 4047 | if (qla_tgt_mode_enabled(vha) || |
| 4048 | qla_dual_mode_enabled(vha)) { |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 4049 | if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) { |
| 4050 | spin_lock_irqsave(&ha->tgt.atio_lock, |
| 4051 | flags); |
| 4052 | qlt_24xx_process_atio_queue(vha, 0); |
| 4053 | spin_unlock_irqrestore( |
| 4054 | &ha->tgt.atio_lock, flags); |
| 4055 | } else { |
| 4056 | spin_lock_irqsave(&ha->hardware_lock, |
| 4057 | flags); |
| 4058 | qlt_24xx_process_atio_queue(vha, 1); |
| 4059 | spin_unlock_irqrestore( |
| 4060 | &ha->hardware_lock, flags); |
| 4061 | } |
| 4062 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4063 | } |
| 4064 | } |
| 4065 | |
| 4066 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4067 | ql_dbg(ql_dbg_disc, vha, 0x206a, |
| 4068 | "%s *** FAILED ***.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4069 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4070 | ql_dbg(ql_dbg_disc, vha, 0x206b, |
| 4071 | "%s: exiting normally.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4072 | } |
| 4073 | |
Bjorn Helgaas | cc3ef7b | 2008-09-11 21:22:51 -0700 | [diff] [blame] | 4074 | /* Restore state if a resync event occurred during processing */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4075 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4076 | if (test_bit(LOCAL_LOOP_UPDATE, &save_flags)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4077 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 4078 | if (test_bit(RSCN_UPDATE, &save_flags)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4079 | set_bit(RSCN_UPDATE, &vha->dpc_flags); |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 4080 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4081 | } |
| 4082 | |
| 4083 | return (rval); |
| 4084 | } |
| 4085 | |
| 4086 | |
| 4087 | |
| 4088 | /* |
| 4089 | * qla2x00_configure_local_loop |
| 4090 | * Updates Fibre Channel Device Database with local loop devices. |
| 4091 | * |
| 4092 | * Input: |
| 4093 | * ha = adapter block pointer. |
| 4094 | * |
| 4095 | * Returns: |
| 4096 | * 0 = success. |
| 4097 | */ |
| 4098 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4099 | qla2x00_configure_local_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4100 | { |
| 4101 | int rval, rval2; |
| 4102 | int found_devs; |
| 4103 | int found; |
| 4104 | fc_port_t *fcport, *new_fcport; |
| 4105 | |
| 4106 | uint16_t index; |
| 4107 | uint16_t entries; |
| 4108 | char *id_iter; |
| 4109 | uint16_t loop_id; |
| 4110 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4111 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame^] | 4112 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4113 | |
| 4114 | found_devs = 0; |
| 4115 | new_fcport = NULL; |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4116 | entries = MAX_FIBRE_DEVICES_LOOP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4118 | /* Get list of logged in devices. */ |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4119 | memset(ha->gid_list, 0, qla2x00_gid_list_size(ha)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4120 | 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] | 4121 | &entries); |
| 4122 | if (rval != QLA_SUCCESS) |
| 4123 | goto cleanup_allocation; |
| 4124 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4125 | ql_dbg(ql_dbg_disc, vha, 0x2017, |
| 4126 | "Entries in ID list (%d).\n", entries); |
| 4127 | ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075, |
| 4128 | (uint8_t *)ha->gid_list, |
| 4129 | entries * sizeof(struct gid_list_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4130 | |
| 4131 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4132 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4133 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4134 | ql_log(ql_log_warn, vha, 0x2018, |
| 4135 | "Memory allocation failed for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4136 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 4137 | goto cleanup_allocation; |
| 4138 | } |
| 4139 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 4140 | |
| 4141 | /* |
| 4142 | * Mark local devices that were present with FCF_DEVICE_LOST for now. |
| 4143 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4144 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4145 | if (atomic_read(&fcport->state) == FCS_ONLINE && |
| 4146 | fcport->port_type != FCT_BROADCAST && |
| 4147 | (fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 4148 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4149 | ql_dbg(ql_dbg_disc, vha, 0x2019, |
| 4150 | "Marking port lost loop_id=0x%04x.\n", |
| 4151 | fcport->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4152 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame^] | 4153 | qla2x00_mark_device_lost(vha, fcport, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4154 | } |
| 4155 | } |
| 4156 | |
| 4157 | /* Add devices to port list. */ |
| 4158 | id_iter = (char *)ha->gid_list; |
| 4159 | for (index = 0; index < entries; index++) { |
| 4160 | domain = ((struct gid_list_info *)id_iter)->domain; |
| 4161 | area = ((struct gid_list_info *)id_iter)->area; |
| 4162 | al_pa = ((struct gid_list_info *)id_iter)->al_pa; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4163 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4164 | loop_id = (uint16_t) |
| 4165 | ((struct gid_list_info *)id_iter)->loop_id_2100; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4166 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4167 | loop_id = le16_to_cpu( |
| 4168 | ((struct gid_list_info *)id_iter)->loop_id); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4169 | id_iter += ha->gid_list_info_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4170 | |
| 4171 | /* Bypass reserved domain fields. */ |
| 4172 | if ((domain & 0xf0) == 0xf0) |
| 4173 | continue; |
| 4174 | |
| 4175 | /* Bypass if not same domain and area of adapter. */ |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 4176 | if (area && domain && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4177 | (area != vha->d_id.b.area || domain != vha->d_id.b.domain)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4178 | continue; |
| 4179 | |
| 4180 | /* Bypass invalid local loop ID. */ |
| 4181 | if (loop_id > LAST_LOCAL_LOOP_ID) |
| 4182 | continue; |
| 4183 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame^] | 4184 | memset(new_fcport->port_name, 0, WWN_SIZE); |
Arun Easi | 370d550 | 2012-08-22 14:21:10 -0400 | [diff] [blame] | 4185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4186 | /* Fill in member data. */ |
| 4187 | new_fcport->d_id.b.domain = domain; |
| 4188 | new_fcport->d_id.b.area = area; |
| 4189 | new_fcport->d_id.b.al_pa = al_pa; |
| 4190 | new_fcport->loop_id = loop_id; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame^] | 4191 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4192 | rval2 = qla2x00_get_port_database(vha, new_fcport, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4193 | if (rval2 != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4194 | ql_dbg(ql_dbg_disc, vha, 0x201a, |
| 4195 | "Failed to retrieve fcport information " |
| 4196 | "-- get_port_database=%x, loop_id=0x%04x.\n", |
| 4197 | rval2, new_fcport->loop_id); |
| 4198 | ql_dbg(ql_dbg_disc, vha, 0x201b, |
| 4199 | "Scheduling resync.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4200 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4201 | continue; |
| 4202 | } |
| 4203 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame^] | 4204 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4205 | /* Check for matching device in port list. */ |
| 4206 | found = 0; |
| 4207 | fcport = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4208 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4209 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 4210 | WWN_SIZE)) |
| 4211 | continue; |
| 4212 | |
Shyam Sundar | ddb9b12 | 2009-03-24 09:08:10 -0700 | [diff] [blame] | 4213 | fcport->flags &= ~FCF_FABRIC_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4214 | fcport->loop_id = new_fcport->loop_id; |
| 4215 | fcport->port_type = new_fcport->port_type; |
| 4216 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 4217 | memcpy(fcport->node_name, new_fcport->node_name, |
| 4218 | WWN_SIZE); |
| 4219 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame^] | 4220 | if (!fcport->login_succ) { |
| 4221 | vha->fcport_count++; |
| 4222 | fcport->login_succ = 1; |
| 4223 | fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 4224 | } |
| 4225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4226 | found++; |
| 4227 | break; |
| 4228 | } |
| 4229 | |
| 4230 | if (!found) { |
| 4231 | /* New device, add to fcports list. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4232 | list_add_tail(&new_fcport->list, &vha->vp_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4233 | |
| 4234 | /* Allocate a new replacement fcport. */ |
| 4235 | fcport = new_fcport; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame^] | 4236 | if (!fcport->login_succ) { |
| 4237 | vha->fcport_count++; |
| 4238 | fcport->login_succ = 1; |
| 4239 | fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 4240 | } |
| 4241 | |
| 4242 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 4243 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4244 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame^] | 4245 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4246 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4247 | ql_log(ql_log_warn, vha, 0x201c, |
| 4248 | "Failed to allocate memory for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4249 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 4250 | goto cleanup_allocation; |
| 4251 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame^] | 4252 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4253 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 4254 | } |
| 4255 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame^] | 4256 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 4257 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4258 | /* Base iIDMA settings on HBA port speed. */ |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 4259 | fcport->fp_speed = ha->link_data_rate; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4260 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4261 | qla2x00_update_fcport(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4262 | |
| 4263 | found_devs++; |
| 4264 | } |
| 4265 | |
| 4266 | cleanup_allocation: |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 4267 | kfree(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4268 | |
| 4269 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4270 | ql_dbg(ql_dbg_disc, vha, 0x201d, |
| 4271 | "Configure local loop error exit: rval=%x.\n", rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4272 | } |
| 4273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4274 | return (rval); |
| 4275 | } |
| 4276 | |
| 4277 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4278 | qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4279 | { |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4280 | int rval; |
Quinn Tran | 93f2bd6 | 2014-09-25 05:16:53 -0400 | [diff] [blame] | 4281 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4282 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4283 | |
Andrew Vasquez | c76f2c0 | 2007-07-19 15:05:57 -0700 | [diff] [blame] | 4284 | if (!IS_IIDMA_CAPABLE(ha)) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4285 | return; |
| 4286 | |
Giridhar Malavali | c9afb9a | 2010-09-03 15:20:48 -0700 | [diff] [blame] | 4287 | if (atomic_read(&fcport->state) != FCS_ONLINE) |
| 4288 | return; |
| 4289 | |
Andrew Vasquez | 39bd962 | 2007-09-20 14:07:34 -0700 | [diff] [blame] | 4290 | if (fcport->fp_speed == PORT_SPEED_UNKNOWN || |
| 4291 | fcport->fp_speed > ha->link_data_rate) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4292 | return; |
| 4293 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4294 | rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed, |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 4295 | mb); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4296 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4297 | ql_dbg(ql_dbg_disc, vha, 0x2004, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 4298 | "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n", |
| 4299 | fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4300 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4301 | ql_dbg(ql_dbg_disc, vha, 0x2005, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 4302 | "iIDMA adjusted to %s GB/s on %8phN.\n", |
Joe Carnuccio | d0297c9 | 2012-11-21 02:40:40 -0500 | [diff] [blame] | 4303 | qla2x00_get_link_speed_str(ha, fcport->fp_speed), |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 4304 | fcport->port_name); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4305 | } |
| 4306 | } |
| 4307 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4308 | /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/ |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4309 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4310 | qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 4311 | { |
| 4312 | struct fc_rport_identifiers rport_ids; |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 4313 | struct fc_rport *rport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 4314 | unsigned long flags; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 4315 | |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 4316 | rport_ids.node_name = wwn_to_u64(fcport->node_name); |
| 4317 | rport_ids.port_name = wwn_to_u64(fcport->port_name); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 4318 | rport_ids.port_id = fcport->d_id.b.domain << 16 | |
| 4319 | fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa; |
| 4320 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4321 | fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 4322 | if (!rport) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4323 | ql_log(ql_log_warn, vha, 0x2006, |
| 4324 | "Unable to allocate fc remote port.\n"); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 4325 | return; |
| 4326 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4327 | |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 4328 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4329 | *((fc_port_t **)rport->dd_data) = fcport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 4330 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 4331 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 4332 | rport->supported_classes = fcport->supported_classes; |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 4333 | |
| 4334 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 4335 | if (fcport->port_type == FCT_INITIATOR) |
| 4336 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 4337 | if (fcport->port_type == FCT_TARGET) |
| 4338 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4339 | |
| 4340 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4341 | "%s %8phN. rport %p is %s mode \n", |
| 4342 | __func__, fcport->port_name, rport, |
| 4343 | (fcport->port_type == FCT_TARGET) ? "tgt" : "ini"); |
| 4344 | |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 4345 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 4346 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4347 | |
| 4348 | /* |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4349 | * qla2x00_update_fcport |
| 4350 | * Updates device on list. |
| 4351 | * |
| 4352 | * Input: |
| 4353 | * ha = adapter block pointer. |
| 4354 | * fcport = port structure pointer. |
| 4355 | * |
| 4356 | * Return: |
| 4357 | * 0 - Success |
| 4358 | * BIT_0 - error |
| 4359 | * |
| 4360 | * Context: |
| 4361 | * Kernel context. |
| 4362 | */ |
| 4363 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4364 | qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4365 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4366 | fcport->vha = vha; |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 4367 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4368 | if (IS_SW_RESV_ADDR(fcport->d_id)) |
| 4369 | return; |
| 4370 | |
| 4371 | ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %8phC \n", |
| 4372 | __func__, fcport->port_name); |
| 4373 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 4374 | if (IS_QLAFX00(vha->hw)) { |
| 4375 | qla2x00_set_fcport_state(fcport, FCS_ONLINE); |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 4376 | goto reg_port; |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 4377 | } |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4378 | fcport->login_retry = 0; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 4379 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4380 | fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 4381 | fcport->deleted = 0; |
| 4382 | fcport->logout_on_delete = 1; |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4383 | |
Joe Carnuccio | 1f93da52 | 2012-11-21 02:40:38 -0500 | [diff] [blame] | 4384 | qla2x00_set_fcport_state(fcport, FCS_ONLINE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4385 | qla2x00_iidma_fcport(vha, fcport); |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 4386 | qla24xx_update_fcport_fcp_prio(vha, fcport); |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 4387 | |
| 4388 | reg_port: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4389 | switch (vha->host->active_mode) { |
| 4390 | case MODE_INITIATOR: |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 4391 | qla2x00_reg_remote_port(vha, fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4392 | break; |
| 4393 | case MODE_TARGET: |
| 4394 | if (!vha->vha_tgt.qla_tgt->tgt_stop && |
| 4395 | !vha->vha_tgt.qla_tgt->tgt_stopped) |
| 4396 | qlt_fc_port_added(vha, fcport); |
| 4397 | break; |
| 4398 | case MODE_DUAL: |
| 4399 | qla2x00_reg_remote_port(vha, fcport); |
| 4400 | if (!vha->vha_tgt.qla_tgt->tgt_stop && |
| 4401 | !vha->vha_tgt.qla_tgt->tgt_stopped) |
| 4402 | qlt_fc_port_added(vha, fcport); |
| 4403 | break; |
| 4404 | default: |
| 4405 | break; |
| 4406 | } |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4407 | } |
| 4408 | |
| 4409 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4410 | * qla2x00_configure_fabric |
| 4411 | * Setup SNS devices with loop ID's. |
| 4412 | * |
| 4413 | * Input: |
| 4414 | * ha = adapter block pointer. |
| 4415 | * |
| 4416 | * Returns: |
| 4417 | * 0 = success. |
| 4418 | * BIT_0 = error |
| 4419 | */ |
| 4420 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4421 | qla2x00_configure_fabric(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4422 | { |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 4423 | int rval; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4424 | fc_port_t *fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4425 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4426 | uint16_t loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4427 | LIST_HEAD(new_fcports); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4428 | struct qla_hw_data *ha = vha->hw; |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4429 | int discovery_gen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4430 | |
| 4431 | /* If FL port exists, then SNS is present */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 4432 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4433 | loop_id = NPH_F_PORT; |
| 4434 | else |
| 4435 | loop_id = SNS_FL_PORT; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4436 | 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] | 4437 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4438 | ql_dbg(ql_dbg_disc, vha, 0x201f, |
| 4439 | "MBX_GET_PORT_NAME failed, No FL Port.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4440 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4441 | vha->device_flags &= ~SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4442 | return (QLA_SUCCESS); |
| 4443 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4444 | vha->device_flags |= SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4445 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame^] | 4446 | |
| 4447 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { |
| 4448 | rval = qla2x00_send_change_request(vha, 0x3, 0); |
| 4449 | if (rval != QLA_SUCCESS) |
| 4450 | ql_log(ql_log_warn, vha, 0x121, |
| 4451 | "Failed to enable receiving of RSCN requests: 0x%x.\n", |
| 4452 | rval); |
| 4453 | } |
| 4454 | |
| 4455 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4456 | do { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4457 | qla2x00_mgmt_svr_login(vha); |
| 4458 | |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 4459 | /* FDMI support. */ |
| 4460 | if (ql2xfdmienable && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4461 | test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags)) |
| 4462 | qla2x00_fdmi_register(vha); |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 4463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4464 | /* Ensure we are logged into the SNS. */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 4465 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4466 | loop_id = NPH_SNS; |
| 4467 | else |
| 4468 | loop_id = SIMPLE_NAME_SERVER; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 4469 | rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff, |
| 4470 | 0xfc, mb, BIT_1|BIT_0); |
| 4471 | if (rval != QLA_SUCCESS) { |
| 4472 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Joe Carnuccio | e452ceb | 2013-02-08 01:57:56 -0500 | [diff] [blame] | 4473 | return rval; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 4474 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4475 | if (mb[0] != MBS_COMMAND_COMPLETE) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4476 | ql_dbg(ql_dbg_disc, vha, 0x2042, |
| 4477 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x " |
| 4478 | "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1], |
| 4479 | mb[2], mb[6], mb[7]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4480 | return (QLA_SUCCESS); |
| 4481 | } |
| 4482 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4483 | if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) { |
| 4484 | if (qla2x00_rft_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4485 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4486 | ql_dbg(ql_dbg_disc, vha, 0x2045, |
| 4487 | "Register FC-4 TYPE failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4488 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4489 | if (qla2x00_rff_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, 0x2049, |
| 4492 | "Register FC-4 Features 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_rnn_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, 0x204f, |
| 4497 | "Register Node Name failed.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4498 | } else if (qla2x00_rsnn_nn(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4499 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4500 | ql_dbg(ql_dbg_disc, vha, 0x2053, |
| 4501 | "Register Symobilic Node Name failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4502 | } |
| 4503 | } |
| 4504 | |
Joe Carnuccio | 827210b | 2013-02-08 01:57:57 -0500 | [diff] [blame] | 4505 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 4506 | fcport->scan_state = QLA_FCPORT_SCAN; |
| 4507 | } |
| 4508 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4509 | /* Mark the time right before querying FW for connected ports. |
| 4510 | * This process is long, asynchronous and by the time it's done, |
| 4511 | * collected information might not be accurate anymore. E.g. |
| 4512 | * disconnected port might have re-connected and a brand new |
| 4513 | * session has been created. In this case session's generation |
| 4514 | * will be newer than discovery_gen. */ |
| 4515 | qlt_do_generation_tick(vha, &discovery_gen); |
| 4516 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4517 | rval = qla2x00_find_all_fabric_devs(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4518 | if (rval != QLA_SUCCESS) |
| 4519 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4520 | } while (0); |
| 4521 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4522 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4523 | ql_dbg(ql_dbg_disc, vha, 0x2068, |
| 4524 | "Configure fabric error exit rval=%d.\n", rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4525 | |
| 4526 | return (rval); |
| 4527 | } |
| 4528 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4529 | /* |
| 4530 | * qla2x00_find_all_fabric_devs |
| 4531 | * |
| 4532 | * Input: |
| 4533 | * ha = adapter block pointer. |
| 4534 | * dev = database device entry pointer. |
| 4535 | * |
| 4536 | * Returns: |
| 4537 | * 0 = success. |
| 4538 | * |
| 4539 | * Context: |
| 4540 | * Kernel context. |
| 4541 | */ |
| 4542 | static int |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4543 | qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4544 | { |
| 4545 | int rval; |
| 4546 | uint16_t loop_id; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4547 | fc_port_t *fcport, *new_fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4548 | int found; |
| 4549 | |
| 4550 | sw_info_t *swl; |
| 4551 | int swl_idx; |
| 4552 | int first_dev, last_dev; |
Mike Waychison | 1516ef4 | 2010-05-04 15:01:31 -0700 | [diff] [blame] | 4553 | port_id_t wrap = {}, nxt_d_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4554 | struct qla_hw_data *ha = vha->hw; |
Chad Dupuis | bb4cf5b | 2013-02-08 01:58:01 -0500 | [diff] [blame] | 4555 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4556 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4557 | |
| 4558 | rval = QLA_SUCCESS; |
| 4559 | |
| 4560 | /* Try GID_PT to get device list, else GAN. */ |
Andrew Vasquez | 7a67735 | 2012-02-09 11:15:56 -0800 | [diff] [blame] | 4561 | if (!ha->swl) |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4562 | ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t), |
Andrew Vasquez | 7a67735 | 2012-02-09 11:15:56 -0800 | [diff] [blame] | 4563 | GFP_KERNEL); |
| 4564 | swl = ha->swl; |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 4565 | if (!swl) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4566 | /*EMPTY*/ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4567 | ql_dbg(ql_dbg_disc, vha, 0x2054, |
| 4568 | "GID_PT allocations failed, fallback on GA_NXT.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4569 | } else { |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4570 | memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4571 | if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4572 | swl = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4573 | } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4574 | swl = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4575 | } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4576 | swl = NULL; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4577 | } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) { |
| 4578 | swl = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4579 | } |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 4580 | |
| 4581 | /* If other queries succeeded probe for FC-4 type */ |
| 4582 | if (swl) |
| 4583 | qla2x00_gff_id(vha, swl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4584 | } |
| 4585 | swl_idx = 0; |
| 4586 | |
| 4587 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4588 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4589 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4590 | ql_log(ql_log_warn, vha, 0x205e, |
| 4591 | "Failed to allocate memory for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4592 | return (QLA_MEMORY_ALLOC_FAILED); |
| 4593 | } |
| 4594 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4595 | /* Set start port ID scan at adapter ID. */ |
| 4596 | first_dev = 1; |
| 4597 | last_dev = 0; |
| 4598 | |
| 4599 | /* Starting free loop ID. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4600 | loop_id = ha->min_external_loopid; |
| 4601 | for (; loop_id <= ha->max_loop_id; loop_id++) { |
| 4602 | if (qla2x00_is_reserved_id(vha, loop_id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4603 | continue; |
| 4604 | |
Giridhar Malavali | 3a6478d | 2010-05-28 15:08:20 -0700 | [diff] [blame] | 4605 | if (ha->current_topology == ISP_CFG_FL && |
| 4606 | (atomic_read(&vha->loop_down_timer) || |
| 4607 | LOOP_TRANSITION(vha))) { |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 4608 | atomic_set(&vha->loop_down_timer, 0); |
| 4609 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 4610 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4611 | break; |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 4612 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4613 | |
| 4614 | if (swl != NULL) { |
| 4615 | if (last_dev) { |
| 4616 | wrap.b24 = new_fcport->d_id.b24; |
| 4617 | } else { |
| 4618 | new_fcport->d_id.b24 = swl[swl_idx].d_id.b24; |
| 4619 | memcpy(new_fcport->node_name, |
| 4620 | swl[swl_idx].node_name, WWN_SIZE); |
| 4621 | memcpy(new_fcport->port_name, |
| 4622 | swl[swl_idx].port_name, WWN_SIZE); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4623 | memcpy(new_fcport->fabric_port_name, |
| 4624 | swl[swl_idx].fabric_port_name, WWN_SIZE); |
| 4625 | new_fcport->fp_speed = swl[swl_idx].fp_speed; |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 4626 | new_fcport->fc4_type = swl[swl_idx].fc4_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4627 | |
| 4628 | if (swl[swl_idx].d_id.b.rsvd_1 != 0) { |
| 4629 | last_dev = 1; |
| 4630 | } |
| 4631 | swl_idx++; |
| 4632 | } |
| 4633 | } else { |
| 4634 | /* Send GA_NXT to the switch */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4635 | rval = qla2x00_ga_nxt(vha, new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4636 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4637 | ql_log(ql_log_warn, vha, 0x2064, |
| 4638 | "SNS scan failed -- assuming " |
| 4639 | "zero-entry result.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4640 | rval = QLA_SUCCESS; |
| 4641 | break; |
| 4642 | } |
| 4643 | } |
| 4644 | |
| 4645 | /* If wrap on switch device list, exit. */ |
| 4646 | if (first_dev) { |
| 4647 | wrap.b24 = new_fcport->d_id.b24; |
| 4648 | first_dev = 0; |
| 4649 | } else if (new_fcport->d_id.b24 == wrap.b24) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4650 | ql_dbg(ql_dbg_disc, vha, 0x2065, |
| 4651 | "Device wrap (%02x%02x%02x).\n", |
| 4652 | new_fcport->d_id.b.domain, |
| 4653 | new_fcport->d_id.b.area, |
| 4654 | new_fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4655 | break; |
| 4656 | } |
| 4657 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4658 | /* Bypass if same physical adapter. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4659 | if (new_fcport->d_id.b24 == base_vha->d_id.b24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4660 | continue; |
| 4661 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4662 | /* Bypass virtual ports of the same host. */ |
Chad Dupuis | bb4cf5b | 2013-02-08 01:58:01 -0500 | [diff] [blame] | 4663 | if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24)) |
| 4664 | continue; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4665 | |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 4666 | /* Bypass if same domain and area of adapter. */ |
| 4667 | if (((new_fcport->d_id.b24 & 0xffff00) == |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4668 | (vha->d_id.b24 & 0xffff00)) && ha->current_topology == |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 4669 | ISP_CFG_FL) |
| 4670 | continue; |
| 4671 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4672 | /* Bypass reserved domain fields. */ |
| 4673 | if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0) |
| 4674 | continue; |
| 4675 | |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 4676 | /* Bypass ports whose FCP-4 type is not FCP_SCSI */ |
Chad Dupuis | 4da26e1 | 2010-10-15 11:27:40 -0700 | [diff] [blame] | 4677 | if (ql2xgffidenable && |
| 4678 | (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI && |
| 4679 | new_fcport->fc4_type != FC4_TYPE_UNKNOWN)) |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 4680 | continue; |
| 4681 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4682 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 4683 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4684 | /* Locate matching device in database. */ |
| 4685 | found = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4686 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4687 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 4688 | WWN_SIZE)) |
| 4689 | continue; |
| 4690 | |
Joe Carnuccio | 827210b | 2013-02-08 01:57:57 -0500 | [diff] [blame] | 4691 | fcport->scan_state = QLA_FCPORT_FOUND; |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 4692 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4693 | found++; |
| 4694 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4695 | /* Update port state. */ |
| 4696 | memcpy(fcport->fabric_port_name, |
| 4697 | new_fcport->fabric_port_name, WWN_SIZE); |
| 4698 | fcport->fp_speed = new_fcport->fp_speed; |
| 4699 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4700 | /* |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 4701 | * If address the same and state FCS_ONLINE |
| 4702 | * (or in target mode), nothing changed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4703 | */ |
| 4704 | if (fcport->d_id.b24 == new_fcport->d_id.b24 && |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 4705 | (atomic_read(&fcport->state) == FCS_ONLINE || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4706 | (vha->host->active_mode == MODE_TARGET))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4707 | break; |
| 4708 | } |
| 4709 | |
| 4710 | /* |
| 4711 | * If device was not a fabric device before. |
| 4712 | */ |
| 4713 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 4714 | fcport->d_id.b24 = new_fcport->d_id.b24; |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 4715 | qla2x00_clear_loop_id(fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4716 | fcport->flags |= (FCF_FABRIC_DEVICE | |
| 4717 | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4718 | break; |
| 4719 | } |
| 4720 | |
| 4721 | /* |
| 4722 | * Port ID changed or device was marked to be updated; |
| 4723 | * Log it out if still logged in and mark it for |
| 4724 | * relogin later. |
| 4725 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4726 | if (qla_tgt_mode_enabled(base_vha)) { |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 4727 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080, |
| 4728 | "port changed FC ID, %8phC" |
| 4729 | " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n", |
| 4730 | fcport->port_name, |
| 4731 | fcport->d_id.b.domain, |
| 4732 | fcport->d_id.b.area, |
| 4733 | fcport->d_id.b.al_pa, |
| 4734 | fcport->loop_id, |
| 4735 | new_fcport->d_id.b.domain, |
| 4736 | new_fcport->d_id.b.area, |
| 4737 | new_fcport->d_id.b.al_pa); |
| 4738 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 4739 | break; |
| 4740 | } |
| 4741 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4742 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 4743 | fcport->flags |= FCF_LOGIN_NEEDED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4744 | break; |
| 4745 | } |
| 4746 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4747 | if (found) { |
| 4748 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4749 | continue; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4750 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4751 | /* If device was not in our fcports list, then add it. */ |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 4752 | new_fcport->scan_state = QLA_FCPORT_FOUND; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4753 | list_add_tail(&new_fcport->list, &vha->vp_fcports); |
| 4754 | |
| 4755 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 4756 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4757 | |
| 4758 | /* Allocate a new replacement fcport. */ |
| 4759 | nxt_d_id.b24 = new_fcport->d_id.b24; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4760 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4761 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4762 | ql_log(ql_log_warn, vha, 0x2066, |
| 4763 | "Memory allocation failed for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4764 | return (QLA_MEMORY_ALLOC_FAILED); |
| 4765 | } |
| 4766 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
| 4767 | new_fcport->d_id.b24 = nxt_d_id.b24; |
| 4768 | } |
| 4769 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4770 | qla2x00_free_fcport(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4771 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4772 | /* |
| 4773 | * Logout all previous fabric dev marked lost, except FCP2 devices. |
| 4774 | */ |
| 4775 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 4776 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 4777 | break; |
| 4778 | |
| 4779 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 || |
| 4780 | (fcport->flags & FCF_LOGIN_NEEDED) == 0) |
| 4781 | continue; |
| 4782 | |
| 4783 | if (fcport->scan_state == QLA_FCPORT_SCAN) { |
| 4784 | if ((qla_dual_mode_enabled(vha) || |
| 4785 | qla_ini_mode_enabled(vha)) && |
| 4786 | atomic_read(&fcport->state) == FCS_ONLINE) { |
| 4787 | qla2x00_mark_device_lost(vha, fcport, |
| 4788 | ql2xplogiabsentdevice, 0); |
| 4789 | if (fcport->loop_id != FC_NO_LOOP_ID && |
| 4790 | (fcport->flags & FCF_FCP2_DEVICE) == 0 && |
| 4791 | fcport->port_type != FCT_INITIATOR && |
| 4792 | fcport->port_type != FCT_BROADCAST) { |
| 4793 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 4794 | "%s %d %8phC post del sess\n", |
| 4795 | __func__, __LINE__, |
| 4796 | fcport->port_name); |
| 4797 | |
| 4798 | qlt_schedule_sess_for_deletion_lock |
| 4799 | (fcport); |
| 4800 | continue; |
| 4801 | } |
| 4802 | } |
| 4803 | } |
| 4804 | |
| 4805 | if (fcport->scan_state == QLA_FCPORT_FOUND) |
| 4806 | qla24xx_fcport_handle_login(vha, fcport); |
| 4807 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4808 | return (rval); |
| 4809 | } |
| 4810 | |
| 4811 | /* |
| 4812 | * qla2x00_find_new_loop_id |
| 4813 | * Scan through our port list and find a new usable loop ID. |
| 4814 | * |
| 4815 | * Input: |
| 4816 | * ha: adapter state pointer. |
| 4817 | * dev: port structure pointer. |
| 4818 | * |
| 4819 | * Returns: |
| 4820 | * qla2x00 local function return status code. |
| 4821 | * |
| 4822 | * Context: |
| 4823 | * Kernel context. |
| 4824 | */ |
Joe Carnuccio | 03bcfb5 | 2011-03-30 11:46:27 -0700 | [diff] [blame] | 4825 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4826 | 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] | 4827 | { |
| 4828 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4829 | struct qla_hw_data *ha = vha->hw; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4830 | unsigned long flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4831 | |
| 4832 | rval = QLA_SUCCESS; |
| 4833 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 4834 | spin_lock_irqsave(&ha->vport_slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4835 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 4836 | dev->loop_id = find_first_zero_bit(ha->loop_id_map, |
| 4837 | LOOPID_MAP_SIZE); |
| 4838 | if (dev->loop_id >= LOOPID_MAP_SIZE || |
| 4839 | qla2x00_is_reserved_id(vha, dev->loop_id)) { |
| 4840 | dev->loop_id = FC_NO_LOOP_ID; |
| 4841 | rval = QLA_FUNCTION_FAILED; |
| 4842 | } else |
| 4843 | set_bit(dev->loop_id, ha->loop_id_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4844 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 4845 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4846 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 4847 | if (rval == QLA_SUCCESS) |
| 4848 | ql_dbg(ql_dbg_disc, dev->vha, 0x2086, |
| 4849 | "Assigning new loopid=%x, portid=%x.\n", |
| 4850 | dev->loop_id, dev->d_id.b24); |
| 4851 | else |
| 4852 | ql_log(ql_log_warn, dev->vha, 0x2087, |
| 4853 | "No loop_id's available, portid=%x.\n", |
| 4854 | dev->d_id.b24); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4855 | |
| 4856 | return (rval); |
| 4857 | } |
| 4858 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4859 | |
| 4860 | /* |
| 4861 | * qla2x00_fabric_login |
| 4862 | * Issue fabric login command. |
| 4863 | * |
| 4864 | * Input: |
| 4865 | * ha = adapter block pointer. |
| 4866 | * device = pointer to FC device type structure. |
| 4867 | * |
| 4868 | * Returns: |
| 4869 | * 0 - Login successfully |
| 4870 | * 1 - Login failed |
| 4871 | * 2 - Initiator device |
| 4872 | * 3 - Fatal error |
| 4873 | */ |
| 4874 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4875 | qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4876 | uint16_t *next_loopid) |
| 4877 | { |
| 4878 | int rval; |
| 4879 | int retry; |
| 4880 | uint16_t tmp_loopid; |
| 4881 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4882 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4883 | |
| 4884 | retry = 0; |
| 4885 | tmp_loopid = 0; |
| 4886 | |
| 4887 | for (;;) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4888 | ql_dbg(ql_dbg_disc, vha, 0x2000, |
| 4889 | "Trying Fabric Login w/loop id 0x%04x for port " |
| 4890 | "%02x%02x%02x.\n", |
| 4891 | fcport->loop_id, fcport->d_id.b.domain, |
| 4892 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4893 | |
| 4894 | /* Login fcport on switch. */ |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 4895 | rval = ha->isp_ops->fabric_login(vha, fcport->loop_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4896 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 4897 | fcport->d_id.b.al_pa, mb, BIT_0); |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 4898 | if (rval != QLA_SUCCESS) { |
| 4899 | return rval; |
| 4900 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4901 | if (mb[0] == MBS_PORT_ID_USED) { |
| 4902 | /* |
| 4903 | * Device has another loop ID. The firmware team |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4904 | * recommends the driver perform an implicit login with |
| 4905 | * the specified ID again. The ID we just used is save |
| 4906 | * here so we return with an ID that can be tried by |
| 4907 | * the next login. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4908 | */ |
| 4909 | retry++; |
| 4910 | tmp_loopid = fcport->loop_id; |
| 4911 | fcport->loop_id = mb[1]; |
| 4912 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4913 | ql_dbg(ql_dbg_disc, vha, 0x2001, |
| 4914 | "Fabric Login: port in use - next loop " |
| 4915 | "id=0x%04x, port id= %02x%02x%02x.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4916 | fcport->loop_id, fcport->d_id.b.domain, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4917 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4918 | |
| 4919 | } else if (mb[0] == MBS_COMMAND_COMPLETE) { |
| 4920 | /* |
| 4921 | * Login succeeded. |
| 4922 | */ |
| 4923 | if (retry) { |
| 4924 | /* A retry occurred before. */ |
| 4925 | *next_loopid = tmp_loopid; |
| 4926 | } else { |
| 4927 | /* |
| 4928 | * No retry occurred before. Just increment the |
| 4929 | * ID value for next login. |
| 4930 | */ |
| 4931 | *next_loopid = (fcport->loop_id + 1); |
| 4932 | } |
| 4933 | |
| 4934 | if (mb[1] & BIT_0) { |
| 4935 | fcport->port_type = FCT_INITIATOR; |
| 4936 | } else { |
| 4937 | fcport->port_type = FCT_TARGET; |
| 4938 | if (mb[1] & BIT_1) { |
Santosh Vernekar | 8474f3a | 2009-08-25 11:36:16 -0700 | [diff] [blame] | 4939 | fcport->flags |= FCF_FCP2_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4940 | } |
| 4941 | } |
| 4942 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 4943 | if (mb[10] & BIT_0) |
| 4944 | fcport->supported_classes |= FC_COS_CLASS2; |
| 4945 | if (mb[10] & BIT_1) |
| 4946 | fcport->supported_classes |= FC_COS_CLASS3; |
| 4947 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4948 | if (IS_FWI2_CAPABLE(ha)) { |
| 4949 | if (mb[10] & BIT_7) |
| 4950 | fcport->flags |= |
| 4951 | FCF_CONF_COMP_SUPPORTED; |
| 4952 | } |
| 4953 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4954 | rval = QLA_SUCCESS; |
| 4955 | break; |
| 4956 | } else if (mb[0] == MBS_LOOP_ID_USED) { |
| 4957 | /* |
| 4958 | * Loop ID already used, try next loop ID. |
| 4959 | */ |
| 4960 | fcport->loop_id++; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4961 | rval = qla2x00_find_new_loop_id(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4962 | if (rval != QLA_SUCCESS) { |
| 4963 | /* Ran out of loop IDs to use */ |
| 4964 | break; |
| 4965 | } |
| 4966 | } else if (mb[0] == MBS_COMMAND_ERROR) { |
| 4967 | /* |
| 4968 | * Firmware possibly timed out during login. If NO |
| 4969 | * retries are left to do then the device is declared |
| 4970 | * dead. |
| 4971 | */ |
| 4972 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4973 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 4974 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 4975 | fcport->d_id.b.al_pa); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4976 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4977 | |
| 4978 | rval = 1; |
| 4979 | break; |
| 4980 | } else { |
| 4981 | /* |
| 4982 | * unrecoverable / not handled error |
| 4983 | */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4984 | ql_dbg(ql_dbg_disc, vha, 0x2002, |
| 4985 | "Failed=%x port_id=%02x%02x%02x loop_id=%x " |
| 4986 | "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain, |
| 4987 | fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 4988 | fcport->loop_id, jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4989 | |
| 4990 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4991 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 4992 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 4993 | fcport->d_id.b.al_pa); |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 4994 | qla2x00_clear_loop_id(fcport); |
Andrew Vasquez | 0eedfcf | 2005-10-27 11:09:38 -0700 | [diff] [blame] | 4995 | fcport->login_retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4996 | |
| 4997 | rval = 3; |
| 4998 | break; |
| 4999 | } |
| 5000 | } |
| 5001 | |
| 5002 | return (rval); |
| 5003 | } |
| 5004 | |
| 5005 | /* |
| 5006 | * qla2x00_local_device_login |
| 5007 | * Issue local device login command. |
| 5008 | * |
| 5009 | * Input: |
| 5010 | * ha = adapter block pointer. |
| 5011 | * loop_id = loop id of device to login to. |
| 5012 | * |
| 5013 | * Returns (Where's the #define!!!!): |
| 5014 | * 0 - Login successfully |
| 5015 | * 1 - Login failed |
| 5016 | * 3 - Fatal error |
| 5017 | */ |
| 5018 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5019 | 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] | 5020 | { |
| 5021 | int rval; |
| 5022 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
| 5023 | |
| 5024 | memset(mb, 0, sizeof(mb)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5025 | rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5026 | if (rval == QLA_SUCCESS) { |
| 5027 | /* Interrogate mailbox registers for any errors */ |
| 5028 | if (mb[0] == MBS_COMMAND_ERROR) |
| 5029 | rval = 1; |
| 5030 | else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR) |
| 5031 | /* device not in PCB table */ |
| 5032 | rval = 3; |
| 5033 | } |
| 5034 | |
| 5035 | return (rval); |
| 5036 | } |
| 5037 | |
| 5038 | /* |
| 5039 | * qla2x00_loop_resync |
| 5040 | * Resync with fibre channel devices. |
| 5041 | * |
| 5042 | * Input: |
| 5043 | * ha = adapter block pointer. |
| 5044 | * |
| 5045 | * Returns: |
| 5046 | * 0 = success |
| 5047 | */ |
| 5048 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5049 | qla2x00_loop_resync(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5050 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5051 | int rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5052 | uint32_t wait_time; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 5053 | struct req_que *req; |
| 5054 | struct rsp_que *rsp; |
| 5055 | |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 5056 | req = vha->req; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 5057 | rsp = req->rsp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5058 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5059 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 5060 | if (vha->flags.online) { |
| 5061 | if (!(rval = qla2x00_fw_ready(vha))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5062 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 5063 | wait_time = 256; |
| 5064 | do { |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 5065 | if (!IS_QLAFX00(vha->hw)) { |
| 5066 | /* |
| 5067 | * Issue a marker after FW becomes |
| 5068 | * ready. |
| 5069 | */ |
| 5070 | qla2x00_marker(vha, req, rsp, 0, 0, |
| 5071 | MK_SYNC_ALL); |
| 5072 | vha->marker_needed = 0; |
| 5073 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5074 | |
| 5075 | /* Remap devices on Loop. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5076 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5077 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 5078 | if (IS_QLAFX00(vha->hw)) |
| 5079 | qlafx00_configure_devices(vha); |
| 5080 | else |
| 5081 | qla2x00_configure_loop(vha); |
| 5082 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5083 | wait_time--; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5084 | } while (!atomic_read(&vha->loop_down_timer) && |
| 5085 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
| 5086 | && wait_time && (test_bit(LOOP_RESYNC_NEEDED, |
| 5087 | &vha->dpc_flags))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5088 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5089 | } |
| 5090 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5091 | if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5092 | return (QLA_FUNCTION_FAILED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5093 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5094 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5095 | ql_dbg(ql_dbg_disc, vha, 0x206c, |
| 5096 | "%s *** FAILED ***.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5097 | |
| 5098 | return (rval); |
| 5099 | } |
| 5100 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5101 | /* |
| 5102 | * qla2x00_perform_loop_resync |
| 5103 | * Description: This function will set the appropriate flags and call |
| 5104 | * qla2x00_loop_resync. If successful loop will be resynced |
| 5105 | * Arguments : scsi_qla_host_t pointer |
| 5106 | * returm : Success or Failure |
| 5107 | */ |
| 5108 | |
| 5109 | int qla2x00_perform_loop_resync(scsi_qla_host_t *ha) |
| 5110 | { |
| 5111 | int32_t rval = 0; |
| 5112 | |
| 5113 | if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) { |
| 5114 | /*Configure the flags so that resync happens properly*/ |
| 5115 | atomic_set(&ha->loop_down_timer, 0); |
| 5116 | if (!(ha->device_flags & DFLG_NO_CABLE)) { |
| 5117 | atomic_set(&ha->loop_state, LOOP_UP); |
| 5118 | set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); |
| 5119 | set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags); |
| 5120 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
| 5121 | |
| 5122 | rval = qla2x00_loop_resync(ha); |
| 5123 | } else |
| 5124 | atomic_set(&ha->loop_state, LOOP_DEAD); |
| 5125 | |
| 5126 | clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags); |
| 5127 | } |
| 5128 | |
| 5129 | return rval; |
| 5130 | } |
| 5131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5132 | void |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 5133 | qla2x00_update_fcports(scsi_qla_host_t *base_vha) |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5134 | { |
| 5135 | fc_port_t *fcport; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5136 | struct scsi_qla_host *vha; |
| 5137 | struct qla_hw_data *ha = base_vha->hw; |
| 5138 | unsigned long flags; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5139 | |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5140 | spin_lock_irqsave(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5141 | /* Go with deferred removal of rport references. */ |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5142 | list_for_each_entry(vha, &base_vha->hw->vp_list, list) { |
| 5143 | atomic_inc(&vha->vref_count); |
| 5144 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Dan Carpenter | 8ae598d | 2010-12-21 16:00:15 -0800 | [diff] [blame] | 5145 | if (fcport->drport && |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5146 | atomic_read(&fcport->state) != FCS_UNCONFIGURED) { |
| 5147 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 5148 | qla2x00_rport_del(fcport); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 5149 | |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5150 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5151 | } |
| 5152 | } |
| 5153 | atomic_dec(&vha->vref_count); |
| 5154 | } |
| 5155 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5156 | } |
| 5157 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5158 | /* Assumes idc_lock always held on entry */ |
| 5159 | void |
| 5160 | qla83xx_reset_ownership(scsi_qla_host_t *vha) |
| 5161 | { |
| 5162 | struct qla_hw_data *ha = vha->hw; |
| 5163 | uint32_t drv_presence, drv_presence_mask; |
| 5164 | uint32_t dev_part_info1, dev_part_info2, class_type; |
| 5165 | uint32_t class_type_mask = 0x3; |
| 5166 | uint16_t fcoe_other_function = 0xffff, i; |
| 5167 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 5168 | if (IS_QLA8044(ha)) { |
| 5169 | drv_presence = qla8044_rd_direct(vha, |
| 5170 | QLA8044_CRB_DRV_ACTIVE_INDEX); |
| 5171 | dev_part_info1 = qla8044_rd_direct(vha, |
| 5172 | QLA8044_CRB_DEV_PART_INFO_INDEX); |
| 5173 | dev_part_info2 = qla8044_rd_direct(vha, |
| 5174 | QLA8044_CRB_DEV_PART_INFO2); |
| 5175 | } else { |
| 5176 | qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); |
| 5177 | qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1); |
| 5178 | qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2); |
| 5179 | } |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5180 | for (i = 0; i < 8; i++) { |
| 5181 | class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask); |
| 5182 | if ((class_type == QLA83XX_CLASS_TYPE_FCOE) && |
| 5183 | (i != ha->portnum)) { |
| 5184 | fcoe_other_function = i; |
| 5185 | break; |
| 5186 | } |
| 5187 | } |
| 5188 | if (fcoe_other_function == 0xffff) { |
| 5189 | for (i = 0; i < 8; i++) { |
| 5190 | class_type = ((dev_part_info2 >> (i * 4)) & |
| 5191 | class_type_mask); |
| 5192 | if ((class_type == QLA83XX_CLASS_TYPE_FCOE) && |
| 5193 | ((i + 8) != ha->portnum)) { |
| 5194 | fcoe_other_function = i + 8; |
| 5195 | break; |
| 5196 | } |
| 5197 | } |
| 5198 | } |
| 5199 | /* |
| 5200 | * Prepare drv-presence mask based on fcoe functions present. |
| 5201 | * However consider only valid physical fcoe function numbers (0-15). |
| 5202 | */ |
| 5203 | drv_presence_mask = ~((1 << (ha->portnum)) | |
| 5204 | ((fcoe_other_function == 0xffff) ? |
| 5205 | 0 : (1 << (fcoe_other_function)))); |
| 5206 | |
| 5207 | /* We are the reset owner iff: |
| 5208 | * - No other protocol drivers present. |
| 5209 | * - This is the lowest among fcoe functions. */ |
| 5210 | if (!(drv_presence & drv_presence_mask) && |
| 5211 | (ha->portnum < fcoe_other_function)) { |
| 5212 | ql_dbg(ql_dbg_p3p, vha, 0xb07f, |
| 5213 | "This host is Reset owner.\n"); |
| 5214 | ha->flags.nic_core_reset_owner = 1; |
| 5215 | } |
| 5216 | } |
| 5217 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5218 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5219 | __qla83xx_set_drv_ack(scsi_qla_host_t *vha) |
| 5220 | { |
| 5221 | int rval = QLA_SUCCESS; |
| 5222 | struct qla_hw_data *ha = vha->hw; |
| 5223 | uint32_t drv_ack; |
| 5224 | |
| 5225 | rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack); |
| 5226 | if (rval == QLA_SUCCESS) { |
| 5227 | drv_ack |= (1 << ha->portnum); |
| 5228 | rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack); |
| 5229 | } |
| 5230 | |
| 5231 | return rval; |
| 5232 | } |
| 5233 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5234 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5235 | __qla83xx_clear_drv_ack(scsi_qla_host_t *vha) |
| 5236 | { |
| 5237 | int rval = QLA_SUCCESS; |
| 5238 | struct qla_hw_data *ha = vha->hw; |
| 5239 | uint32_t drv_ack; |
| 5240 | |
| 5241 | rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack); |
| 5242 | if (rval == QLA_SUCCESS) { |
| 5243 | drv_ack &= ~(1 << ha->portnum); |
| 5244 | rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack); |
| 5245 | } |
| 5246 | |
| 5247 | return rval; |
| 5248 | } |
| 5249 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5250 | static const char * |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5251 | qla83xx_dev_state_to_string(uint32_t dev_state) |
| 5252 | { |
| 5253 | switch (dev_state) { |
| 5254 | case QLA8XXX_DEV_COLD: |
| 5255 | return "COLD/RE-INIT"; |
| 5256 | case QLA8XXX_DEV_INITIALIZING: |
| 5257 | return "INITIALIZING"; |
| 5258 | case QLA8XXX_DEV_READY: |
| 5259 | return "READY"; |
| 5260 | case QLA8XXX_DEV_NEED_RESET: |
| 5261 | return "NEED RESET"; |
| 5262 | case QLA8XXX_DEV_NEED_QUIESCENT: |
| 5263 | return "NEED QUIESCENT"; |
| 5264 | case QLA8XXX_DEV_FAILED: |
| 5265 | return "FAILED"; |
| 5266 | case QLA8XXX_DEV_QUIESCENT: |
| 5267 | return "QUIESCENT"; |
| 5268 | default: |
| 5269 | return "Unknown"; |
| 5270 | } |
| 5271 | } |
| 5272 | |
| 5273 | /* Assumes idc-lock always held on entry */ |
| 5274 | void |
| 5275 | qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type) |
| 5276 | { |
| 5277 | struct qla_hw_data *ha = vha->hw; |
| 5278 | uint32_t idc_audit_reg = 0, duration_secs = 0; |
| 5279 | |
| 5280 | switch (audit_type) { |
| 5281 | case IDC_AUDIT_TIMESTAMP: |
| 5282 | ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000); |
| 5283 | idc_audit_reg = (ha->portnum) | |
| 5284 | (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8); |
| 5285 | qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg); |
| 5286 | break; |
| 5287 | |
| 5288 | case IDC_AUDIT_COMPLETION: |
| 5289 | duration_secs = ((jiffies_to_msecs(jiffies) - |
| 5290 | jiffies_to_msecs(ha->idc_audit_ts)) / 1000); |
| 5291 | idc_audit_reg = (ha->portnum) | |
| 5292 | (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8); |
| 5293 | qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg); |
| 5294 | break; |
| 5295 | |
| 5296 | default: |
| 5297 | ql_log(ql_log_warn, vha, 0xb078, |
| 5298 | "Invalid audit type specified.\n"); |
| 5299 | break; |
| 5300 | } |
| 5301 | } |
| 5302 | |
| 5303 | /* Assumes idc_lock always held on entry */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5304 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5305 | qla83xx_initiating_reset(scsi_qla_host_t *vha) |
| 5306 | { |
| 5307 | struct qla_hw_data *ha = vha->hw; |
| 5308 | uint32_t idc_control, dev_state; |
| 5309 | |
| 5310 | __qla83xx_get_idc_control(vha, &idc_control); |
| 5311 | if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) { |
| 5312 | ql_log(ql_log_info, vha, 0xb080, |
| 5313 | "NIC Core reset has been disabled. idc-control=0x%x\n", |
| 5314 | idc_control); |
| 5315 | return QLA_FUNCTION_FAILED; |
| 5316 | } |
| 5317 | |
| 5318 | /* Set NEED-RESET iff in READY state and we are the reset-owner */ |
| 5319 | qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state); |
| 5320 | if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) { |
| 5321 | qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, |
| 5322 | QLA8XXX_DEV_NEED_RESET); |
| 5323 | ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n"); |
| 5324 | qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP); |
| 5325 | } else { |
| 5326 | const char *state = qla83xx_dev_state_to_string(dev_state); |
| 5327 | ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state); |
| 5328 | |
| 5329 | /* SV: XXX: Is timeout required here? */ |
| 5330 | /* Wait for IDC state change READY -> NEED_RESET */ |
| 5331 | while (dev_state == QLA8XXX_DEV_READY) { |
| 5332 | qla83xx_idc_unlock(vha, 0); |
| 5333 | msleep(200); |
| 5334 | qla83xx_idc_lock(vha, 0); |
| 5335 | qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state); |
| 5336 | } |
| 5337 | } |
| 5338 | |
| 5339 | /* Send IDC ack by writing to drv-ack register */ |
| 5340 | __qla83xx_set_drv_ack(vha); |
| 5341 | |
| 5342 | return QLA_SUCCESS; |
| 5343 | } |
| 5344 | |
| 5345 | int |
| 5346 | __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control) |
| 5347 | { |
| 5348 | return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control); |
| 5349 | } |
| 5350 | |
| 5351 | int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5352 | __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control) |
| 5353 | { |
| 5354 | return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control); |
| 5355 | } |
| 5356 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5357 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5358 | qla83xx_check_driver_presence(scsi_qla_host_t *vha) |
| 5359 | { |
| 5360 | uint32_t drv_presence = 0; |
| 5361 | struct qla_hw_data *ha = vha->hw; |
| 5362 | |
| 5363 | qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); |
| 5364 | if (drv_presence & (1 << ha->portnum)) |
| 5365 | return QLA_SUCCESS; |
| 5366 | else |
| 5367 | return QLA_TEST_FAILED; |
| 5368 | } |
| 5369 | |
| 5370 | int |
| 5371 | qla83xx_nic_core_reset(scsi_qla_host_t *vha) |
| 5372 | { |
| 5373 | int rval = QLA_SUCCESS; |
| 5374 | struct qla_hw_data *ha = vha->hw; |
| 5375 | |
| 5376 | ql_dbg(ql_dbg_p3p, vha, 0xb058, |
| 5377 | "Entered %s().\n", __func__); |
| 5378 | |
| 5379 | if (vha->device_flags & DFLG_DEV_FAILED) { |
| 5380 | ql_log(ql_log_warn, vha, 0xb059, |
| 5381 | "Device in unrecoverable FAILED state.\n"); |
| 5382 | return QLA_FUNCTION_FAILED; |
| 5383 | } |
| 5384 | |
| 5385 | qla83xx_idc_lock(vha, 0); |
| 5386 | |
| 5387 | if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) { |
| 5388 | ql_log(ql_log_warn, vha, 0xb05a, |
| 5389 | "Function=0x%x has been removed from IDC participation.\n", |
| 5390 | ha->portnum); |
| 5391 | rval = QLA_FUNCTION_FAILED; |
| 5392 | goto exit; |
| 5393 | } |
| 5394 | |
| 5395 | qla83xx_reset_ownership(vha); |
| 5396 | |
| 5397 | rval = qla83xx_initiating_reset(vha); |
| 5398 | |
| 5399 | /* |
| 5400 | * Perform reset if we are the reset-owner, |
| 5401 | * else wait till IDC state changes to READY/FAILED. |
| 5402 | */ |
| 5403 | if (rval == QLA_SUCCESS) { |
| 5404 | rval = qla83xx_idc_state_handler(vha); |
| 5405 | |
| 5406 | if (rval == QLA_SUCCESS) |
| 5407 | ha->flags.nic_core_hung = 0; |
| 5408 | __qla83xx_clear_drv_ack(vha); |
| 5409 | } |
| 5410 | |
| 5411 | exit: |
| 5412 | qla83xx_idc_unlock(vha, 0); |
| 5413 | |
| 5414 | ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__); |
| 5415 | |
| 5416 | return rval; |
| 5417 | } |
| 5418 | |
Saurav Kashyap | 8117877 | 2012-08-22 14:21:04 -0400 | [diff] [blame] | 5419 | int |
| 5420 | qla2xxx_mctp_dump(scsi_qla_host_t *vha) |
| 5421 | { |
| 5422 | struct qla_hw_data *ha = vha->hw; |
| 5423 | int rval = QLA_FUNCTION_FAILED; |
| 5424 | |
| 5425 | if (!IS_MCTP_CAPABLE(ha)) { |
| 5426 | /* This message can be removed from the final version */ |
| 5427 | ql_log(ql_log_info, vha, 0x506d, |
| 5428 | "This board is not MCTP capable\n"); |
| 5429 | return rval; |
| 5430 | } |
| 5431 | |
| 5432 | if (!ha->mctp_dump) { |
| 5433 | ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev, |
| 5434 | MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL); |
| 5435 | |
| 5436 | if (!ha->mctp_dump) { |
| 5437 | ql_log(ql_log_warn, vha, 0x506e, |
| 5438 | "Failed to allocate memory for mctp dump\n"); |
| 5439 | return rval; |
| 5440 | } |
| 5441 | } |
| 5442 | |
| 5443 | #define MCTP_DUMP_STR_ADDR 0x00000000 |
| 5444 | rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma, |
| 5445 | MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4); |
| 5446 | if (rval != QLA_SUCCESS) { |
| 5447 | ql_log(ql_log_warn, vha, 0x506f, |
| 5448 | "Failed to capture mctp dump\n"); |
| 5449 | } else { |
| 5450 | ql_log(ql_log_info, vha, 0x5070, |
| 5451 | "Mctp dump capture for host (%ld/%p).\n", |
| 5452 | vha->host_no, ha->mctp_dump); |
| 5453 | ha->mctp_dumped = 1; |
| 5454 | } |
| 5455 | |
Saurav Kashyap | 409ee0f | 2012-08-22 14:21:29 -0400 | [diff] [blame] | 5456 | if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) { |
Saurav Kashyap | 8117877 | 2012-08-22 14:21:04 -0400 | [diff] [blame] | 5457 | ha->flags.nic_core_reset_hdlr_active = 1; |
| 5458 | rval = qla83xx_restart_nic_firmware(vha); |
| 5459 | if (rval) |
| 5460 | /* NIC Core reset failed. */ |
| 5461 | ql_log(ql_log_warn, vha, 0x5071, |
| 5462 | "Failed to restart nic firmware\n"); |
| 5463 | else |
| 5464 | ql_dbg(ql_dbg_p3p, vha, 0xb084, |
| 5465 | "Restarted NIC firmware successfully.\n"); |
| 5466 | ha->flags.nic_core_reset_hdlr_active = 0; |
| 5467 | } |
| 5468 | |
| 5469 | return rval; |
| 5470 | |
| 5471 | } |
| 5472 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5473 | /* |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 5474 | * qla2x00_quiesce_io |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5475 | * Description: This function will block the new I/Os |
| 5476 | * Its not aborting any I/Os as context |
| 5477 | * is not destroyed during quiescence |
| 5478 | * Arguments: scsi_qla_host_t |
| 5479 | * return : void |
| 5480 | */ |
| 5481 | void |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 5482 | qla2x00_quiesce_io(scsi_qla_host_t *vha) |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5483 | { |
| 5484 | struct qla_hw_data *ha = vha->hw; |
| 5485 | struct scsi_qla_host *vp; |
| 5486 | |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 5487 | ql_dbg(ql_dbg_dpc, vha, 0x401d, |
| 5488 | "Quiescing I/O - ha=%p.\n", ha); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5489 | |
| 5490 | atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); |
| 5491 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 5492 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 5493 | qla2x00_mark_all_devices_lost(vha, 0); |
| 5494 | list_for_each_entry(vp, &ha->vp_list, list) |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 5495 | qla2x00_mark_all_devices_lost(vp, 0); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5496 | } else { |
| 5497 | if (!atomic_read(&vha->loop_down_timer)) |
| 5498 | atomic_set(&vha->loop_down_timer, |
| 5499 | LOOP_DOWN_TIME); |
| 5500 | } |
| 5501 | /* Wait for pending cmds to complete */ |
| 5502 | qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST); |
| 5503 | } |
| 5504 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5505 | void |
| 5506 | qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha) |
| 5507 | { |
| 5508 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5509 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5510 | unsigned long flags; |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 5511 | fc_port_t *fcport; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5512 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 5513 | /* For ISP82XX, driver waits for completion of the commands. |
| 5514 | * online flag should be set. |
| 5515 | */ |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 5516 | if (!(IS_P3P_TYPE(ha))) |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 5517 | vha->flags.online = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5518 | ha->flags.chip_reset_done = 0; |
| 5519 | clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Saurav Kashyap | 2be21fa | 2012-05-15 14:34:16 -0400 | [diff] [blame] | 5520 | vha->qla_stats.total_isp_aborts++; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5521 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5522 | ql_log(ql_log_info, vha, 0x00af, |
| 5523 | "Performing ISP error recovery - ha=%p.\n", ha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5524 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 5525 | /* For ISP82XX, reset_chip is just disabling interrupts. |
| 5526 | * Driver waits for the completion of the commands. |
| 5527 | * the interrupts need to be enabled. |
| 5528 | */ |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 5529 | if (!(IS_P3P_TYPE(ha))) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5530 | ha->isp_ops->reset_chip(vha); |
| 5531 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5532 | ha->chip_reset++; |
| 5533 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5534 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 5535 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 5536 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 5537 | qla2x00_mark_all_devices_lost(vha, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5538 | |
| 5539 | spin_lock_irqsave(&ha->vport_slock, flags); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5540 | list_for_each_entry(vp, &ha->vp_list, list) { |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5541 | atomic_inc(&vp->vref_count); |
| 5542 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5543 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5544 | qla2x00_mark_all_devices_lost(vp, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5545 | |
| 5546 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5547 | atomic_dec(&vp->vref_count); |
| 5548 | } |
| 5549 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5550 | } else { |
| 5551 | if (!atomic_read(&vha->loop_down_timer)) |
| 5552 | atomic_set(&vha->loop_down_timer, |
| 5553 | LOOP_DOWN_TIME); |
| 5554 | } |
| 5555 | |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 5556 | /* Clear all async request states across all VPs. */ |
| 5557 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 5558 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 5559 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5560 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 5561 | atomic_inc(&vp->vref_count); |
| 5562 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5563 | |
| 5564 | list_for_each_entry(fcport, &vp->vp_fcports, list) |
| 5565 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 5566 | |
| 5567 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5568 | atomic_dec(&vp->vref_count); |
| 5569 | } |
| 5570 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5571 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 5572 | if (!ha->flags.eeh_busy) { |
| 5573 | /* Make sure for ISP 82XX IO DMA is complete */ |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 5574 | if (IS_P3P_TYPE(ha)) { |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 5575 | qla82xx_chip_reset_cleanup(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5576 | ql_log(ql_log_info, vha, 0x00b4, |
| 5577 | "Done chip reset cleanup.\n"); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5578 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 5579 | /* Done waiting for pending commands. |
| 5580 | * Reset the online flag. |
| 5581 | */ |
| 5582 | vha->flags.online = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5583 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5584 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 5585 | /* Requeue all commands in outstanding command list. */ |
| 5586 | qla2x00_abort_all_cmds(vha, DID_RESET << 16); |
| 5587 | } |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 5588 | /* memory barrier */ |
| 5589 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5590 | } |
| 5591 | |
| 5592 | /* |
| 5593 | * qla2x00_abort_isp |
| 5594 | * Resets ISP and aborts all outstanding commands. |
| 5595 | * |
| 5596 | * Input: |
| 5597 | * ha = adapter block pointer. |
| 5598 | * |
| 5599 | * Returns: |
| 5600 | * 0 = success |
| 5601 | */ |
| 5602 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5603 | qla2x00_abort_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5604 | { |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 5605 | int rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5606 | uint8_t status = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5607 | struct qla_hw_data *ha = vha->hw; |
| 5608 | struct scsi_qla_host *vp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5609 | struct req_que *req = ha->req_q_map[0]; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5610 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5611 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5612 | if (vha->flags.online) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5613 | qla2x00_abort_isp_cleanup(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5614 | |
Santosh Vernekar | a6171297 | 2012-08-22 14:21:13 -0400 | [diff] [blame] | 5615 | if (IS_QLA8031(ha)) { |
| 5616 | ql_dbg(ql_dbg_p3p, vha, 0xb05c, |
| 5617 | "Clearing fcoe driver presence.\n"); |
| 5618 | if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS) |
| 5619 | ql_dbg(ql_dbg_p3p, vha, 0xb073, |
| 5620 | "Error while clearing DRV-Presence.\n"); |
| 5621 | } |
| 5622 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 5623 | if (unlikely(pci_channel_offline(ha->pdev) && |
| 5624 | ha->flags.pci_channel_io_perm_failure)) { |
| 5625 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 5626 | status = 0; |
| 5627 | return status; |
| 5628 | } |
| 5629 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5630 | ha->isp_ops->get_flash_version(vha, req->ring); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 5631 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5632 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5633 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5634 | if (!qla2x00_restart_isp(vha)) { |
| 5635 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5636 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5637 | if (!atomic_read(&vha->loop_down_timer)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5638 | /* |
| 5639 | * Issue marker command only when we are going |
| 5640 | * to start the I/O . |
| 5641 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5642 | vha->marker_needed = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5643 | } |
| 5644 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5645 | vha->flags.online = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5646 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 5647 | ha->isp_ops->enable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5648 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 5649 | ha->isp_abort_cnt = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5650 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 5651 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 5652 | if (IS_QLA81XX(ha) || IS_QLA8031(ha)) |
| 5653 | qla2x00_get_fw_version(vha); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 5654 | if (ha->fce) { |
| 5655 | ha->flags.fce_enabled = 1; |
| 5656 | memset(ha->fce, 0, |
| 5657 | fce_calc_size(ha->fce_bufs)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5658 | rval = qla2x00_enable_fce_trace(vha, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 5659 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 5660 | &ha->fce_bufs); |
| 5661 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5662 | ql_log(ql_log_warn, vha, 0x8033, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 5663 | "Unable to reinitialize FCE " |
| 5664 | "(%d).\n", rval); |
| 5665 | ha->flags.fce_enabled = 0; |
| 5666 | } |
| 5667 | } |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 5668 | |
| 5669 | if (ha->eft) { |
| 5670 | memset(ha->eft, 0, EFT_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5671 | rval = qla2x00_enable_eft_trace(vha, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 5672 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 5673 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5674 | ql_log(ql_log_warn, vha, 0x8034, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 5675 | "Unable to reinitialize EFT " |
| 5676 | "(%d).\n", rval); |
| 5677 | } |
| 5678 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5679 | } else { /* failed the ISP abort */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5680 | vha->flags.online = 1; |
| 5681 | if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5682 | if (ha->isp_abort_cnt == 0) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5683 | ql_log(ql_log_fatal, vha, 0x8035, |
| 5684 | "ISP error recover failed - " |
| 5685 | "board disabled.\n"); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 5686 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5687 | * The next call disables the board |
| 5688 | * completely. |
| 5689 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5690 | ha->isp_ops->reset_adapter(vha); |
| 5691 | vha->flags.online = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5692 | clear_bit(ISP_ABORT_RETRY, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5693 | &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5694 | status = 0; |
| 5695 | } else { /* schedule another ISP abort */ |
| 5696 | ha->isp_abort_cnt--; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5697 | ql_dbg(ql_dbg_taskm, vha, 0x8020, |
| 5698 | "ISP abort - retry remaining %d.\n", |
| 5699 | ha->isp_abort_cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5700 | status = 1; |
| 5701 | } |
| 5702 | } else { |
| 5703 | ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5704 | ql_dbg(ql_dbg_taskm, vha, 0x8021, |
| 5705 | "ISP error recovery - retrying (%d) " |
| 5706 | "more times.\n", ha->isp_abort_cnt); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5707 | set_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5708 | status = 1; |
| 5709 | } |
| 5710 | } |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 5711 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5712 | } |
| 5713 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5714 | if (!status) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5715 | ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5716 | |
| 5717 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5718 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 5719 | if (vp->vp_idx) { |
| 5720 | atomic_inc(&vp->vref_count); |
| 5721 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5722 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5723 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5724 | |
| 5725 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5726 | atomic_dec(&vp->vref_count); |
| 5727 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5728 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5729 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5730 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5731 | if (IS_QLA8031(ha)) { |
| 5732 | ql_dbg(ql_dbg_p3p, vha, 0xb05d, |
| 5733 | "Setting back fcoe driver presence.\n"); |
| 5734 | if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS) |
| 5735 | ql_dbg(ql_dbg_p3p, vha, 0xb074, |
| 5736 | "Error while setting DRV-Presence.\n"); |
| 5737 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5738 | } else { |
Joe Perches | d8424f6 | 2011-11-18 09:03:06 -0800 | [diff] [blame] | 5739 | ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n", |
| 5740 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5741 | } |
| 5742 | |
| 5743 | return(status); |
| 5744 | } |
| 5745 | |
| 5746 | /* |
| 5747 | * qla2x00_restart_isp |
| 5748 | * restarts the ISP after a reset |
| 5749 | * |
| 5750 | * Input: |
| 5751 | * ha = adapter block pointer. |
| 5752 | * |
| 5753 | * Returns: |
| 5754 | * 0 = success |
| 5755 | */ |
| 5756 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5757 | qla2x00_restart_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5758 | { |
Andrew Vasquez | c6b2fca | 2009-03-05 11:07:03 -0800 | [diff] [blame] | 5759 | int status = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5760 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5761 | struct req_que *req = ha->req_q_map[0]; |
| 5762 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5763 | |
| 5764 | /* If firmware needs to be loaded */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5765 | if (qla2x00_isp_firmware(vha)) { |
| 5766 | vha->flags.online = 0; |
| 5767 | status = ha->isp_ops->chip_diag(vha); |
| 5768 | if (!status) |
| 5769 | status = qla2x00_setup_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5770 | } |
| 5771 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5772 | if (!status && !(status = qla2x00_init_rings(vha))) { |
| 5773 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 5774 | ha->flags.chip_reset_done = 1; |
Chad Dupuis | 7108b76 | 2014-04-11 16:54:45 -0400 | [diff] [blame] | 5775 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5776 | /* Initialize the queues in use */ |
| 5777 | qla25xx_init_queues(ha); |
| 5778 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5779 | status = qla2x00_fw_ready(vha); |
| 5780 | if (!status) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5781 | /* Issue a marker after FW becomes ready. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5782 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Chad Dupuis | 7108b76 | 2014-04-11 16:54:45 -0400 | [diff] [blame] | 5783 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5784 | } |
| 5785 | |
| 5786 | /* if no cable then assume it's good */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5787 | if ((vha->device_flags & DFLG_NO_CABLE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5788 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5789 | } |
| 5790 | return (status); |
| 5791 | } |
| 5792 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5793 | static int |
| 5794 | qla25xx_init_queues(struct qla_hw_data *ha) |
| 5795 | { |
| 5796 | struct rsp_que *rsp = NULL; |
| 5797 | struct req_que *req = NULL; |
| 5798 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
| 5799 | int ret = -1; |
| 5800 | int i; |
| 5801 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 5802 | for (i = 1; i < ha->max_rsp_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5803 | rsp = ha->rsp_q_map[i]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 5804 | if (rsp && test_bit(i, ha->rsp_qid_map)) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5805 | rsp->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 5806 | ret = qla25xx_init_rsp_que(base_vha, rsp); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5807 | if (ret != QLA_SUCCESS) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5808 | ql_dbg(ql_dbg_init, base_vha, 0x00ff, |
| 5809 | "%s Rsp que: %d init failed.\n", |
| 5810 | __func__, rsp->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5811 | else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5812 | ql_dbg(ql_dbg_init, base_vha, 0x0100, |
| 5813 | "%s Rsp que: %d inited.\n", |
| 5814 | __func__, rsp->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5815 | } |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 5816 | } |
| 5817 | for (i = 1; i < ha->max_req_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5818 | req = ha->req_q_map[i]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 5819 | if (req && test_bit(i, ha->req_qid_map)) { |
| 5820 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5821 | req->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 5822 | ret = qla25xx_init_req_que(base_vha, req); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5823 | if (ret != QLA_SUCCESS) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5824 | ql_dbg(ql_dbg_init, base_vha, 0x0101, |
| 5825 | "%s Req que: %d init failed.\n", |
| 5826 | __func__, req->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5827 | else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5828 | ql_dbg(ql_dbg_init, base_vha, 0x0102, |
| 5829 | "%s Req que: %d inited.\n", |
| 5830 | __func__, req->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5831 | } |
| 5832 | } |
| 5833 | return ret; |
| 5834 | } |
| 5835 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5836 | /* |
| 5837 | * qla2x00_reset_adapter |
| 5838 | * Reset adapter. |
| 5839 | * |
| 5840 | * Input: |
| 5841 | * ha = adapter block pointer. |
| 5842 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 5843 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5844 | qla2x00_reset_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5845 | { |
| 5846 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5847 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 5848 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5849 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5850 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 5851 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5852 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5853 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 5854 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 5855 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 5856 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 5857 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 5858 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 5859 | } |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5860 | |
| 5861 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5862 | qla24xx_reset_adapter(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5863 | { |
| 5864 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5865 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5866 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 5867 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 5868 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5869 | return; |
| 5870 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5871 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 5872 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5873 | |
| 5874 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 5875 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 5876 | RD_REG_DWORD(®->hccr); |
| 5877 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 5878 | RD_REG_DWORD(®->hccr); |
| 5879 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 09ff36d | 2009-01-22 09:45:30 -0800 | [diff] [blame] | 5880 | |
| 5881 | if (IS_NOPOLLING_TYPE(ha)) |
| 5882 | ha->isp_ops->enable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5883 | } |
| 5884 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5885 | /* On sparc systems, obtain port and node WWN from firmware |
| 5886 | * properties. |
| 5887 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5888 | static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, |
| 5889 | struct nvram_24xx *nv) |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5890 | { |
| 5891 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5892 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5893 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 5894 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 5895 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5896 | int len; |
| 5897 | |
| 5898 | val = of_get_property(dp, "port-wwn", &len); |
| 5899 | if (val && len >= WWN_SIZE) |
| 5900 | memcpy(nv->port_name, val, WWN_SIZE); |
| 5901 | |
| 5902 | val = of_get_property(dp, "node-wwn", &len); |
| 5903 | if (val && len >= WWN_SIZE) |
| 5904 | memcpy(nv->node_name, val, WWN_SIZE); |
| 5905 | #endif |
| 5906 | } |
| 5907 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5908 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5909 | qla24xx_nvram_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5910 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5911 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5912 | struct init_cb_24xx *icb; |
| 5913 | struct nvram_24xx *nv; |
| 5914 | uint32_t *dptr; |
| 5915 | uint8_t *dptr1, *dptr2; |
| 5916 | uint32_t chksum; |
| 5917 | uint16_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5918 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5919 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5920 | rval = QLA_SUCCESS; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5921 | icb = (struct init_cb_24xx *)ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 5922 | nv = ha->nvram; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5923 | |
| 5924 | /* Determine NVRAM starting address. */ |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 5925 | if (ha->port_no == 0) { |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5926 | ha->nvram_base = FA_NVRAM_FUNC0_ADDR; |
| 5927 | ha->vpd_base = FA_NVRAM_VPD0_ADDR; |
| 5928 | } else { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5929 | ha->nvram_base = FA_NVRAM_FUNC1_ADDR; |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 5930 | ha->vpd_base = FA_NVRAM_VPD1_ADDR; |
| 5931 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 5932 | |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5933 | ha->nvram_size = sizeof(struct nvram_24xx); |
| 5934 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5935 | |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 5936 | /* Get VPD data into cache */ |
| 5937 | ha->vpd = ha->nvram + VPD_OFFSET; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5938 | ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 5939 | ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4); |
| 5940 | |
| 5941 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5942 | dptr = (uint32_t *)nv; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5943 | ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5944 | ha->nvram_size); |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 5945 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++) |
| 5946 | chksum += le32_to_cpu(*dptr); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5947 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5948 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a, |
| 5949 | "Contents of NVRAM\n"); |
| 5950 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d, |
| 5951 | (uint8_t *)nv, ha->nvram_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5952 | |
| 5953 | /* Bad NVRAM data, set defaults parameters. */ |
| 5954 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 5955 | || nv->id[3] != ' ' || |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5956 | nv->nvram_version < cpu_to_le16(ICB_VERSION)) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5957 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5958 | ql_log(ql_log_warn, vha, 0x006b, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 5959 | "Inconsistent NVRAM detected: checksum=0x%x id=%c " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5960 | "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version); |
| 5961 | ql_log(ql_log_warn, vha, 0x006c, |
| 5962 | "Falling back to functioning (yet invalid -- WWPN) " |
| 5963 | "defaults.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5964 | |
| 5965 | /* |
| 5966 | * Set default initialization control block. |
| 5967 | */ |
| 5968 | memset(nv, 0, ha->nvram_size); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5969 | nv->nvram_version = cpu_to_le16(ICB_VERSION); |
| 5970 | nv->version = cpu_to_le16(ICB_VERSION); |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 5971 | nv->frame_payload_size = 2048; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5972 | nv->execution_throttle = cpu_to_le16(0xFFFF); |
| 5973 | nv->exchange_count = cpu_to_le16(0); |
| 5974 | nv->hard_address = cpu_to_le16(124); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5975 | nv->port_name[0] = 0x21; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 5976 | nv->port_name[1] = 0x00 + ha->port_no + 1; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5977 | nv->port_name[2] = 0x00; |
| 5978 | nv->port_name[3] = 0xe0; |
| 5979 | nv->port_name[4] = 0x8b; |
| 5980 | nv->port_name[5] = 0x1c; |
| 5981 | nv->port_name[6] = 0x55; |
| 5982 | nv->port_name[7] = 0x86; |
| 5983 | nv->node_name[0] = 0x20; |
| 5984 | nv->node_name[1] = 0x00; |
| 5985 | nv->node_name[2] = 0x00; |
| 5986 | nv->node_name[3] = 0xe0; |
| 5987 | nv->node_name[4] = 0x8b; |
| 5988 | nv->node_name[5] = 0x1c; |
| 5989 | nv->node_name[6] = 0x55; |
| 5990 | nv->node_name[7] = 0x86; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5991 | qla24xx_nvram_wwn_from_ofw(vha, nv); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5992 | nv->login_retry_count = cpu_to_le16(8); |
| 5993 | nv->interrupt_delay_timer = cpu_to_le16(0); |
| 5994 | nv->login_timeout = cpu_to_le16(0); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5995 | nv->firmware_options_1 = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 5996 | cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 5997 | nv->firmware_options_2 = cpu_to_le32(2 << 4); |
| 5998 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 5999 | nv->firmware_options_3 = cpu_to_le32(2 << 13); |
| 6000 | nv->host_p = cpu_to_le32(BIT_11|BIT_10); |
| 6001 | nv->efi_parameters = cpu_to_le32(0); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6002 | nv->reset_delay = 5; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6003 | nv->max_luns_per_target = cpu_to_le16(128); |
| 6004 | nv->port_down_retry_count = cpu_to_le16(30); |
| 6005 | nv->link_down_timeout = cpu_to_le16(30); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6006 | |
| 6007 | rval = 1; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6008 | } |
| 6009 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6010 | if (qla_tgt_mode_enabled(vha)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6011 | /* Don't enable full login after initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6012 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6013 | /* Don't enable LIP full login for initiator */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6014 | nv->host_p &= cpu_to_le32(~BIT_10); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6015 | } |
| 6016 | |
| 6017 | qlt_24xx_config_nvram_stage1(vha, nv); |
| 6018 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6019 | /* Reset Initialization control block */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6020 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6021 | |
| 6022 | /* Copy 1st segment. */ |
| 6023 | dptr1 = (uint8_t *)icb; |
| 6024 | dptr2 = (uint8_t *)&nv->version; |
| 6025 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 6026 | while (cnt--) |
| 6027 | *dptr1++ = *dptr2++; |
| 6028 | |
| 6029 | icb->login_retry_count = nv->login_retry_count; |
Andrew Vasquez | 3ea66e2 | 2006-06-23 16:11:27 -0700 | [diff] [blame] | 6030 | icb->link_down_on_nos = nv->link_down_on_nos; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6031 | |
| 6032 | /* Copy 2nd segment. */ |
| 6033 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 6034 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 6035 | cnt = (uint8_t *)&icb->reserved_3 - |
| 6036 | (uint8_t *)&icb->interrupt_delay_timer; |
| 6037 | while (cnt--) |
| 6038 | *dptr1++ = *dptr2++; |
| 6039 | |
| 6040 | /* |
| 6041 | * Setup driver NVRAM options. |
| 6042 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6043 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 6044 | "QLA2462"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6045 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6046 | qlt_24xx_config_nvram_stage2(vha, icb); |
| 6047 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6048 | if (nv->host_p & cpu_to_le32(BIT_15)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6049 | /* Use alternate WWN? */ |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 6050 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 6051 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 6052 | } |
| 6053 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6054 | /* Prepare nodename */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6055 | if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6056 | /* |
| 6057 | * Firmware will apply the following mask if the nodename was |
| 6058 | * not provided. |
| 6059 | */ |
| 6060 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 6061 | icb->node_name[0] &= 0xF0; |
| 6062 | } |
| 6063 | |
| 6064 | /* Set host adapter parameters. */ |
| 6065 | ha->flags.disable_risc_code_load = 0; |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 6066 | ha->flags.enable_lip_reset = 0; |
| 6067 | ha->flags.enable_lip_full_login = |
| 6068 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 6069 | ha->flags.enable_target_reset = |
| 6070 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6071 | ha->flags.enable_led_scheme = 0; |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 6072 | 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] | 6073 | |
Andrew Vasquez | fd0e7e4 | 2006-05-17 15:09:11 -0700 | [diff] [blame] | 6074 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 6075 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6076 | |
| 6077 | memcpy(ha->fw_seriallink_options24, nv->seriallink_options, |
| 6078 | sizeof(ha->fw_seriallink_options24)); |
| 6079 | |
| 6080 | /* save HBA serial number */ |
| 6081 | ha->serial0 = icb->port_name[5]; |
| 6082 | ha->serial1 = icb->port_name[6]; |
| 6083 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6084 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 6085 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6086 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6087 | icb->execution_throttle = cpu_to_le16(0xFFFF); |
andrew.vasquez@qlogic.com | bc8fb3c | 2006-01-13 17:05:42 -0800 | [diff] [blame] | 6088 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6089 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 6090 | |
| 6091 | /* Set minimum login_timeout to 4 seconds. */ |
| 6092 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 6093 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 6094 | if (le16_to_cpu(nv->login_timeout) < 4) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6095 | nv->login_timeout = cpu_to_le16(4); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6096 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6097 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 6098 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 6099 | ha->r_a_tov = 100; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6100 | |
| 6101 | ha->loop_reset_delay = nv->reset_delay; |
| 6102 | |
| 6103 | /* Link Down Timeout = 0: |
| 6104 | * |
| 6105 | * When Port Down timer expires we will start returning |
| 6106 | * I/O's to OS with "DID_NO_CONNECT". |
| 6107 | * |
| 6108 | * Link Down Timeout != 0: |
| 6109 | * |
| 6110 | * The driver waits for the link to come up after link down |
| 6111 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 6112 | */ |
| 6113 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 6114 | ha->loop_down_abort_time = |
| 6115 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 6116 | } else { |
| 6117 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 6118 | ha->loop_down_abort_time = |
| 6119 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 6120 | } |
| 6121 | |
| 6122 | /* Need enough time to try and get the port back. */ |
| 6123 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 6124 | if (qlport_down_retry) |
| 6125 | ha->port_down_retry_count = qlport_down_retry; |
| 6126 | |
| 6127 | /* Set login_retry_count */ |
| 6128 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 6129 | if (ha->port_down_retry_count == |
| 6130 | le16_to_cpu(nv->port_down_retry_count) && |
| 6131 | ha->port_down_retry_count > 3) |
| 6132 | ha->login_retry_count = ha->port_down_retry_count; |
| 6133 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 6134 | ha->login_retry_count = ha->port_down_retry_count; |
| 6135 | if (ql2xloginretrycount) |
| 6136 | ha->login_retry_count = ql2xloginretrycount; |
| 6137 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6138 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6139 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6140 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 6141 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 6142 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 6143 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 6144 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6145 | icb->firmware_options_2 &= cpu_to_le32( |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6146 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6147 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6148 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 6149 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 6150 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6151 | ql_log(ql_log_info, vha, 0x006f, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6152 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 6153 | ha->zio_mode, ha->zio_timer * 100); |
| 6154 | |
| 6155 | icb->firmware_options_2 |= cpu_to_le32( |
| 6156 | (uint32_t)ha->zio_mode); |
| 6157 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6158 | vha->flags.process_response_queue = 1; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6159 | } |
| 6160 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6161 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6162 | ql_log(ql_log_warn, vha, 0x0070, |
| 6163 | "NVRAM configuration failed.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6164 | } |
| 6165 | return (rval); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6166 | } |
| 6167 | |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 6168 | uint8_t qla27xx_find_valid_image(struct scsi_qla_host *vha) |
| 6169 | { |
| 6170 | struct qla27xx_image_status pri_image_status, sec_image_status; |
| 6171 | uint8_t valid_pri_image, valid_sec_image; |
| 6172 | uint32_t *wptr; |
| 6173 | uint32_t cnt, chksum, size; |
| 6174 | struct qla_hw_data *ha = vha->hw; |
| 6175 | |
| 6176 | valid_pri_image = valid_sec_image = 1; |
| 6177 | ha->active_image = 0; |
| 6178 | size = sizeof(struct qla27xx_image_status) / sizeof(uint32_t); |
| 6179 | |
| 6180 | if (!ha->flt_region_img_status_pri) { |
| 6181 | valid_pri_image = 0; |
| 6182 | goto check_sec_image; |
| 6183 | } |
| 6184 | |
| 6185 | qla24xx_read_flash_data(vha, (uint32_t *)(&pri_image_status), |
| 6186 | ha->flt_region_img_status_pri, size); |
| 6187 | |
| 6188 | if (pri_image_status.signature != QLA27XX_IMG_STATUS_SIGN) { |
| 6189 | ql_dbg(ql_dbg_init, vha, 0x018b, |
| 6190 | "Primary image signature (0x%x) not valid\n", |
| 6191 | pri_image_status.signature); |
| 6192 | valid_pri_image = 0; |
| 6193 | goto check_sec_image; |
| 6194 | } |
| 6195 | |
| 6196 | wptr = (uint32_t *)(&pri_image_status); |
| 6197 | cnt = size; |
| 6198 | |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 6199 | for (chksum = 0; cnt--; wptr++) |
| 6200 | chksum += le32_to_cpu(*wptr); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame^] | 6201 | |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 6202 | if (chksum) { |
| 6203 | ql_dbg(ql_dbg_init, vha, 0x018c, |
| 6204 | "Checksum validation failed for primary image (0x%x)\n", |
| 6205 | chksum); |
| 6206 | valid_pri_image = 0; |
| 6207 | } |
| 6208 | |
| 6209 | check_sec_image: |
| 6210 | if (!ha->flt_region_img_status_sec) { |
| 6211 | valid_sec_image = 0; |
| 6212 | goto check_valid_image; |
| 6213 | } |
| 6214 | |
| 6215 | qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status), |
| 6216 | ha->flt_region_img_status_sec, size); |
| 6217 | |
| 6218 | if (sec_image_status.signature != QLA27XX_IMG_STATUS_SIGN) { |
| 6219 | ql_dbg(ql_dbg_init, vha, 0x018d, |
| 6220 | "Secondary image signature(0x%x) not valid\n", |
| 6221 | sec_image_status.signature); |
| 6222 | valid_sec_image = 0; |
| 6223 | goto check_valid_image; |
| 6224 | } |
| 6225 | |
| 6226 | wptr = (uint32_t *)(&sec_image_status); |
| 6227 | cnt = size; |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 6228 | for (chksum = 0; cnt--; wptr++) |
| 6229 | chksum += le32_to_cpu(*wptr); |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 6230 | if (chksum) { |
| 6231 | ql_dbg(ql_dbg_init, vha, 0x018e, |
| 6232 | "Checksum validation failed for secondary image (0x%x)\n", |
| 6233 | chksum); |
| 6234 | valid_sec_image = 0; |
| 6235 | } |
| 6236 | |
| 6237 | check_valid_image: |
| 6238 | if (valid_pri_image && (pri_image_status.image_status_mask & 0x1)) |
| 6239 | ha->active_image = QLA27XX_PRIMARY_IMAGE; |
| 6240 | if (valid_sec_image && (sec_image_status.image_status_mask & 0x1)) { |
| 6241 | if (!ha->active_image || |
| 6242 | pri_image_status.generation_number < |
| 6243 | sec_image_status.generation_number) |
| 6244 | ha->active_image = QLA27XX_SECONDARY_IMAGE; |
| 6245 | } |
| 6246 | |
| 6247 | ql_dbg(ql_dbg_init, vha, 0x018f, "%s image\n", |
| 6248 | ha->active_image == 0 ? "default bootld and fw" : |
| 6249 | ha->active_image == 1 ? "primary" : |
| 6250 | ha->active_image == 2 ? "secondary" : |
| 6251 | "Invalid"); |
| 6252 | |
| 6253 | return ha->active_image; |
| 6254 | } |
| 6255 | |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 6256 | static int |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6257 | qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr, |
| 6258 | uint32_t faddr) |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6259 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6260 | int rval = QLA_SUCCESS; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6261 | int segments, fragment; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6262 | uint32_t *dcode, dlen; |
| 6263 | uint32_t risc_addr; |
| 6264 | uint32_t risc_size; |
| 6265 | uint32_t i; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6266 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6267 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6268 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6269 | ql_dbg(ql_dbg_init, vha, 0x008b, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 6270 | "FW: Loading firmware from flash (%x).\n", faddr); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6271 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6272 | rval = QLA_SUCCESS; |
| 6273 | |
| 6274 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6275 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6276 | *srisc_addr = 0; |
| 6277 | |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 6278 | if (IS_QLA27XX(ha) && |
| 6279 | qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE) |
| 6280 | faddr = ha->flt_region_fw_sec; |
| 6281 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6282 | /* Validate firmware image by checking version. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6283 | qla24xx_read_flash_data(vha, dcode, faddr + 4, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6284 | for (i = 0; i < 4; i++) |
| 6285 | dcode[i] = be32_to_cpu(dcode[i]); |
| 6286 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 6287 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 6288 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 6289 | dcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6290 | ql_log(ql_log_fatal, vha, 0x008c, |
| 6291 | "Unable to verify the integrity of flash firmware " |
| 6292 | "image.\n"); |
| 6293 | ql_log(ql_log_fatal, vha, 0x008d, |
| 6294 | "Firmware data: %08x %08x %08x %08x.\n", |
| 6295 | dcode[0], dcode[1], dcode[2], dcode[3]); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6296 | |
| 6297 | return QLA_FUNCTION_FAILED; |
| 6298 | } |
| 6299 | |
| 6300 | while (segments && rval == QLA_SUCCESS) { |
| 6301 | /* Read segment's load information. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6302 | qla24xx_read_flash_data(vha, dcode, faddr, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6303 | |
| 6304 | risc_addr = be32_to_cpu(dcode[2]); |
| 6305 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 6306 | risc_size = be32_to_cpu(dcode[3]); |
| 6307 | |
| 6308 | fragment = 0; |
| 6309 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 6310 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 6311 | if (dlen > risc_size) |
| 6312 | dlen = risc_size; |
| 6313 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6314 | ql_dbg(ql_dbg_init, vha, 0x008e, |
| 6315 | "Loading risc segment@ risc addr %x " |
| 6316 | "number of dwords 0x%x offset 0x%x.\n", |
| 6317 | risc_addr, dlen, faddr); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6318 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6319 | qla24xx_read_flash_data(vha, dcode, faddr, dlen); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6320 | for (i = 0; i < dlen; i++) |
| 6321 | dcode[i] = swab32(dcode[i]); |
| 6322 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6323 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6324 | dlen); |
| 6325 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6326 | ql_log(ql_log_fatal, vha, 0x008f, |
| 6327 | "Failed to load segment %d of firmware.\n", |
| 6328 | fragment); |
Chad Dupuis | f261f7a | 2014-09-25 05:17:03 -0400 | [diff] [blame] | 6329 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6330 | } |
| 6331 | |
| 6332 | faddr += dlen; |
| 6333 | risc_addr += dlen; |
| 6334 | risc_size -= dlen; |
| 6335 | fragment++; |
| 6336 | } |
| 6337 | |
| 6338 | /* Next segment. */ |
| 6339 | segments--; |
| 6340 | } |
| 6341 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6342 | if (!IS_QLA27XX(ha)) |
| 6343 | return rval; |
| 6344 | |
| 6345 | if (ha->fw_dump_template) |
| 6346 | vfree(ha->fw_dump_template); |
| 6347 | ha->fw_dump_template = NULL; |
| 6348 | ha->fw_dump_template_len = 0; |
| 6349 | |
| 6350 | ql_dbg(ql_dbg_init, vha, 0x0161, |
| 6351 | "Loading fwdump template from %x\n", faddr); |
| 6352 | qla24xx_read_flash_data(vha, dcode, faddr, 7); |
| 6353 | risc_size = be32_to_cpu(dcode[2]); |
| 6354 | ql_dbg(ql_dbg_init, vha, 0x0162, |
| 6355 | "-> array size %x dwords\n", risc_size); |
| 6356 | if (risc_size == 0 || risc_size == ~0) |
| 6357 | goto default_template; |
| 6358 | |
| 6359 | dlen = (risc_size - 8) * sizeof(*dcode); |
| 6360 | ql_dbg(ql_dbg_init, vha, 0x0163, |
| 6361 | "-> template allocating %x bytes...\n", dlen); |
| 6362 | ha->fw_dump_template = vmalloc(dlen); |
| 6363 | if (!ha->fw_dump_template) { |
| 6364 | ql_log(ql_log_warn, vha, 0x0164, |
| 6365 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 6366 | goto default_template; |
| 6367 | } |
| 6368 | |
| 6369 | faddr += 7; |
| 6370 | risc_size -= 8; |
| 6371 | dcode = ha->fw_dump_template; |
| 6372 | qla24xx_read_flash_data(vha, dcode, faddr, risc_size); |
| 6373 | for (i = 0; i < risc_size; i++) |
| 6374 | dcode[i] = le32_to_cpu(dcode[i]); |
| 6375 | |
| 6376 | if (!qla27xx_fwdt_template_valid(dcode)) { |
| 6377 | ql_log(ql_log_warn, vha, 0x0165, |
| 6378 | "Failed fwdump template validate\n"); |
| 6379 | goto default_template; |
| 6380 | } |
| 6381 | |
| 6382 | dlen = qla27xx_fwdt_template_size(dcode); |
| 6383 | ql_dbg(ql_dbg_init, vha, 0x0166, |
| 6384 | "-> template size %x bytes\n", dlen); |
| 6385 | if (dlen > risc_size * sizeof(*dcode)) { |
| 6386 | ql_log(ql_log_warn, vha, 0x0167, |
Chad Dupuis | 97ea702 | 2014-03-13 14:16:40 -0400 | [diff] [blame] | 6387 | "Failed fwdump template exceeds array by %x bytes\n", |
| 6388 | (uint32_t)(dlen - risc_size * sizeof(*dcode))); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6389 | goto default_template; |
| 6390 | } |
| 6391 | ha->fw_dump_template_len = dlen; |
| 6392 | return rval; |
| 6393 | |
| 6394 | default_template: |
| 6395 | ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n"); |
| 6396 | if (ha->fw_dump_template) |
| 6397 | vfree(ha->fw_dump_template); |
| 6398 | ha->fw_dump_template = NULL; |
| 6399 | ha->fw_dump_template_len = 0; |
| 6400 | |
| 6401 | dlen = qla27xx_fwdt_template_default_size(); |
| 6402 | ql_dbg(ql_dbg_init, vha, 0x0169, |
| 6403 | "-> template allocating %x bytes...\n", dlen); |
| 6404 | ha->fw_dump_template = vmalloc(dlen); |
| 6405 | if (!ha->fw_dump_template) { |
| 6406 | ql_log(ql_log_warn, vha, 0x016a, |
| 6407 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 6408 | goto failed_template; |
| 6409 | } |
| 6410 | |
| 6411 | dcode = ha->fw_dump_template; |
| 6412 | risc_size = dlen / sizeof(*dcode); |
| 6413 | memcpy(dcode, qla27xx_fwdt_template_default(), dlen); |
| 6414 | for (i = 0; i < risc_size; i++) |
| 6415 | dcode[i] = be32_to_cpu(dcode[i]); |
| 6416 | |
| 6417 | if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) { |
| 6418 | ql_log(ql_log_warn, vha, 0x016b, |
| 6419 | "Failed fwdump template validate\n"); |
| 6420 | goto failed_template; |
| 6421 | } |
| 6422 | |
| 6423 | dlen = qla27xx_fwdt_template_size(ha->fw_dump_template); |
| 6424 | ql_dbg(ql_dbg_init, vha, 0x016c, |
| 6425 | "-> template size %x bytes\n", dlen); |
| 6426 | ha->fw_dump_template_len = dlen; |
| 6427 | return rval; |
| 6428 | |
| 6429 | failed_template: |
| 6430 | ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n"); |
| 6431 | if (ha->fw_dump_template) |
| 6432 | vfree(ha->fw_dump_template); |
| 6433 | ha->fw_dump_template = NULL; |
| 6434 | ha->fw_dump_template_len = 0; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6435 | return rval; |
| 6436 | } |
| 6437 | |
Giridhar Malavali | e9454a8 | 2013-02-08 01:57:47 -0500 | [diff] [blame] | 6438 | #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/" |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6439 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6440 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6441 | qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6442 | { |
| 6443 | int rval; |
| 6444 | int i, fragment; |
| 6445 | uint16_t *wcode, *fwcode; |
| 6446 | uint32_t risc_addr, risc_size, fwclen, wlen, *seg; |
| 6447 | struct fw_blob *blob; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6448 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6449 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6450 | |
| 6451 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6452 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6453 | if (!blob) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6454 | ql_log(ql_log_info, vha, 0x0083, |
Yannick Guerrini | 94bcf83 | 2015-02-26 22:49:34 +0100 | [diff] [blame] | 6455 | "Firmware image unavailable.\n"); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6456 | ql_log(ql_log_info, vha, 0x0084, |
| 6457 | "Firmware images can be retrieved from: "QLA_FW_URL ".\n"); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6458 | return QLA_FUNCTION_FAILED; |
| 6459 | } |
| 6460 | |
| 6461 | rval = QLA_SUCCESS; |
| 6462 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6463 | wcode = (uint16_t *)req->ring; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6464 | *srisc_addr = 0; |
| 6465 | fwcode = (uint16_t *)blob->fw->data; |
| 6466 | fwclen = 0; |
| 6467 | |
| 6468 | /* Validate firmware image by checking version. */ |
| 6469 | if (blob->fw->size < 8 * sizeof(uint16_t)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6470 | ql_log(ql_log_fatal, vha, 0x0085, |
| 6471 | "Unable to verify integrity of firmware image (%Zd).\n", |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6472 | blob->fw->size); |
| 6473 | goto fail_fw_integrity; |
| 6474 | } |
| 6475 | for (i = 0; i < 4; i++) |
| 6476 | wcode[i] = be16_to_cpu(fwcode[i + 4]); |
| 6477 | if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff && |
| 6478 | wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 && |
| 6479 | wcode[2] == 0 && wcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6480 | ql_log(ql_log_fatal, vha, 0x0086, |
| 6481 | "Unable to verify integrity of firmware image.\n"); |
| 6482 | ql_log(ql_log_fatal, vha, 0x0087, |
| 6483 | "Firmware data: %04x %04x %04x %04x.\n", |
| 6484 | wcode[0], wcode[1], wcode[2], wcode[3]); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6485 | goto fail_fw_integrity; |
| 6486 | } |
| 6487 | |
| 6488 | seg = blob->segs; |
| 6489 | while (*seg && rval == QLA_SUCCESS) { |
| 6490 | risc_addr = *seg; |
| 6491 | *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr; |
| 6492 | risc_size = be16_to_cpu(fwcode[3]); |
| 6493 | |
| 6494 | /* Validate firmware image size. */ |
| 6495 | fwclen += risc_size * sizeof(uint16_t); |
| 6496 | if (blob->fw->size < fwclen) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6497 | ql_log(ql_log_fatal, vha, 0x0088, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6498 | "Unable to verify integrity of firmware image " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6499 | "(%Zd).\n", blob->fw->size); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6500 | goto fail_fw_integrity; |
| 6501 | } |
| 6502 | |
| 6503 | fragment = 0; |
| 6504 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 6505 | wlen = (uint16_t)(ha->fw_transfer_size >> 1); |
| 6506 | if (wlen > risc_size) |
| 6507 | wlen = risc_size; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6508 | ql_dbg(ql_dbg_init, vha, 0x0089, |
| 6509 | "Loading risc segment@ risc addr %x number of " |
| 6510 | "words 0x%x.\n", risc_addr, wlen); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6511 | |
| 6512 | for (i = 0; i < wlen; i++) |
| 6513 | wcode[i] = swab16(fwcode[i]); |
| 6514 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6515 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6516 | wlen); |
| 6517 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6518 | ql_log(ql_log_fatal, vha, 0x008a, |
| 6519 | "Failed to load segment %d of firmware.\n", |
| 6520 | fragment); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6521 | break; |
| 6522 | } |
| 6523 | |
| 6524 | fwcode += wlen; |
| 6525 | risc_addr += wlen; |
| 6526 | risc_size -= wlen; |
| 6527 | fragment++; |
| 6528 | } |
| 6529 | |
| 6530 | /* Next segment. */ |
| 6531 | seg++; |
| 6532 | } |
| 6533 | return rval; |
| 6534 | |
| 6535 | fail_fw_integrity: |
| 6536 | return QLA_FUNCTION_FAILED; |
| 6537 | } |
| 6538 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6539 | static int |
| 6540 | 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] | 6541 | { |
| 6542 | int rval; |
| 6543 | int segments, fragment; |
| 6544 | uint32_t *dcode, dlen; |
| 6545 | uint32_t risc_addr; |
| 6546 | uint32_t risc_size; |
| 6547 | uint32_t i; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6548 | struct fw_blob *blob; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6549 | const uint32_t *fwcode; |
| 6550 | uint32_t fwclen; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6551 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6552 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6553 | |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6554 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6555 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6556 | if (!blob) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6557 | ql_log(ql_log_warn, vha, 0x0090, |
Yannick Guerrini | 94bcf83 | 2015-02-26 22:49:34 +0100 | [diff] [blame] | 6558 | "Firmware image unavailable.\n"); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6559 | ql_log(ql_log_warn, vha, 0x0091, |
| 6560 | "Firmware images can be retrieved from: " |
| 6561 | QLA_FW_URL ".\n"); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6562 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6563 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6564 | } |
| 6565 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 6566 | ql_dbg(ql_dbg_init, vha, 0x0092, |
| 6567 | "FW: Loading via request-firmware.\n"); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6568 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6569 | rval = QLA_SUCCESS; |
| 6570 | |
| 6571 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6572 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6573 | *srisc_addr = 0; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6574 | fwcode = (uint32_t *)blob->fw->data; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6575 | fwclen = 0; |
| 6576 | |
| 6577 | /* Validate firmware image by checking version. */ |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6578 | if (blob->fw->size < 8 * sizeof(uint32_t)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6579 | ql_log(ql_log_fatal, vha, 0x0093, |
| 6580 | "Unable to verify integrity of firmware image (%Zd).\n", |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6581 | blob->fw->size); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6582 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6583 | } |
| 6584 | for (i = 0; i < 4; i++) |
| 6585 | dcode[i] = be32_to_cpu(fwcode[i + 4]); |
| 6586 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 6587 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 6588 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 6589 | dcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6590 | ql_log(ql_log_fatal, vha, 0x0094, |
| 6591 | "Unable to verify integrity of firmware image (%Zd).\n", |
| 6592 | blob->fw->size); |
| 6593 | ql_log(ql_log_fatal, vha, 0x0095, |
| 6594 | "Firmware data: %08x %08x %08x %08x.\n", |
| 6595 | dcode[0], dcode[1], dcode[2], dcode[3]); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6596 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6597 | } |
| 6598 | |
| 6599 | while (segments && rval == QLA_SUCCESS) { |
| 6600 | risc_addr = be32_to_cpu(fwcode[2]); |
| 6601 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 6602 | risc_size = be32_to_cpu(fwcode[3]); |
| 6603 | |
| 6604 | /* Validate firmware image size. */ |
| 6605 | fwclen += risc_size * sizeof(uint32_t); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6606 | if (blob->fw->size < fwclen) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6607 | ql_log(ql_log_fatal, vha, 0x0096, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6608 | "Unable to verify integrity of firmware image " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6609 | "(%Zd).\n", blob->fw->size); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6610 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6611 | } |
| 6612 | |
| 6613 | fragment = 0; |
| 6614 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 6615 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 6616 | if (dlen > risc_size) |
| 6617 | dlen = risc_size; |
| 6618 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6619 | ql_dbg(ql_dbg_init, vha, 0x0097, |
| 6620 | "Loading risc segment@ risc addr %x " |
| 6621 | "number of dwords 0x%x.\n", risc_addr, dlen); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6622 | |
| 6623 | for (i = 0; i < dlen; i++) |
| 6624 | dcode[i] = swab32(fwcode[i]); |
| 6625 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6626 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
andrew.vasquez@qlogic.com | 590f98e | 2006-01-13 17:05:37 -0800 | [diff] [blame] | 6627 | dlen); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6628 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6629 | ql_log(ql_log_fatal, vha, 0x0098, |
| 6630 | "Failed to load segment %d of firmware.\n", |
| 6631 | fragment); |
Chad Dupuis | f261f7a | 2014-09-25 05:17:03 -0400 | [diff] [blame] | 6632 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6633 | } |
| 6634 | |
| 6635 | fwcode += dlen; |
| 6636 | risc_addr += dlen; |
| 6637 | risc_size -= dlen; |
| 6638 | fragment++; |
| 6639 | } |
| 6640 | |
| 6641 | /* Next segment. */ |
| 6642 | segments--; |
| 6643 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6644 | |
| 6645 | if (!IS_QLA27XX(ha)) |
| 6646 | return rval; |
| 6647 | |
| 6648 | if (ha->fw_dump_template) |
| 6649 | vfree(ha->fw_dump_template); |
| 6650 | ha->fw_dump_template = NULL; |
| 6651 | ha->fw_dump_template_len = 0; |
| 6652 | |
| 6653 | ql_dbg(ql_dbg_init, vha, 0x171, |
Chad Dupuis | 97ea702 | 2014-03-13 14:16:40 -0400 | [diff] [blame] | 6654 | "Loading fwdump template from %x\n", |
| 6655 | (uint32_t)((void *)fwcode - (void *)blob->fw->data)); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6656 | risc_size = be32_to_cpu(fwcode[2]); |
| 6657 | ql_dbg(ql_dbg_init, vha, 0x172, |
| 6658 | "-> array size %x dwords\n", risc_size); |
| 6659 | if (risc_size == 0 || risc_size == ~0) |
| 6660 | goto default_template; |
| 6661 | |
| 6662 | dlen = (risc_size - 8) * sizeof(*fwcode); |
| 6663 | ql_dbg(ql_dbg_init, vha, 0x0173, |
| 6664 | "-> template allocating %x bytes...\n", dlen); |
| 6665 | ha->fw_dump_template = vmalloc(dlen); |
| 6666 | if (!ha->fw_dump_template) { |
| 6667 | ql_log(ql_log_warn, vha, 0x0174, |
| 6668 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 6669 | goto default_template; |
| 6670 | } |
| 6671 | |
| 6672 | fwcode += 7; |
| 6673 | risc_size -= 8; |
| 6674 | dcode = ha->fw_dump_template; |
| 6675 | for (i = 0; i < risc_size; i++) |
| 6676 | dcode[i] = le32_to_cpu(fwcode[i]); |
| 6677 | |
| 6678 | if (!qla27xx_fwdt_template_valid(dcode)) { |
| 6679 | ql_log(ql_log_warn, vha, 0x0175, |
| 6680 | "Failed fwdump template validate\n"); |
| 6681 | goto default_template; |
| 6682 | } |
| 6683 | |
| 6684 | dlen = qla27xx_fwdt_template_size(dcode); |
| 6685 | ql_dbg(ql_dbg_init, vha, 0x0176, |
| 6686 | "-> template size %x bytes\n", dlen); |
| 6687 | if (dlen > risc_size * sizeof(*fwcode)) { |
| 6688 | ql_log(ql_log_warn, vha, 0x0177, |
Chad Dupuis | 97ea702 | 2014-03-13 14:16:40 -0400 | [diff] [blame] | 6689 | "Failed fwdump template exceeds array by %x bytes\n", |
| 6690 | (uint32_t)(dlen - risc_size * sizeof(*fwcode))); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6691 | goto default_template; |
| 6692 | } |
| 6693 | ha->fw_dump_template_len = dlen; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6694 | return rval; |
| 6695 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6696 | default_template: |
| 6697 | ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n"); |
| 6698 | if (ha->fw_dump_template) |
| 6699 | vfree(ha->fw_dump_template); |
| 6700 | ha->fw_dump_template = NULL; |
| 6701 | ha->fw_dump_template_len = 0; |
| 6702 | |
| 6703 | dlen = qla27xx_fwdt_template_default_size(); |
| 6704 | ql_dbg(ql_dbg_init, vha, 0x0179, |
| 6705 | "-> template allocating %x bytes...\n", dlen); |
| 6706 | ha->fw_dump_template = vmalloc(dlen); |
| 6707 | if (!ha->fw_dump_template) { |
| 6708 | ql_log(ql_log_warn, vha, 0x017a, |
| 6709 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 6710 | goto failed_template; |
| 6711 | } |
| 6712 | |
| 6713 | dcode = ha->fw_dump_template; |
| 6714 | risc_size = dlen / sizeof(*fwcode); |
| 6715 | fwcode = qla27xx_fwdt_template_default(); |
| 6716 | for (i = 0; i < risc_size; i++) |
| 6717 | dcode[i] = be32_to_cpu(fwcode[i]); |
| 6718 | |
| 6719 | if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) { |
| 6720 | ql_log(ql_log_warn, vha, 0x017b, |
| 6721 | "Failed fwdump template validate\n"); |
| 6722 | goto failed_template; |
| 6723 | } |
| 6724 | |
| 6725 | dlen = qla27xx_fwdt_template_size(ha->fw_dump_template); |
| 6726 | ql_dbg(ql_dbg_init, vha, 0x017c, |
| 6727 | "-> template size %x bytes\n", dlen); |
| 6728 | ha->fw_dump_template_len = dlen; |
| 6729 | return rval; |
| 6730 | |
| 6731 | failed_template: |
| 6732 | ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n"); |
| 6733 | if (ha->fw_dump_template) |
| 6734 | vfree(ha->fw_dump_template); |
| 6735 | ha->fw_dump_template = NULL; |
| 6736 | ha->fw_dump_template_len = 0; |
| 6737 | return rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6738 | } |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6739 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6740 | int |
| 6741 | qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 6742 | { |
| 6743 | int rval; |
| 6744 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 6745 | if (ql2xfwloadbin == 1) |
| 6746 | return qla81xx_load_risc(vha, srisc_addr); |
| 6747 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6748 | /* |
| 6749 | * FW Load priority: |
| 6750 | * 1) Firmware via request-firmware interface (.bin file). |
| 6751 | * 2) Firmware residing in flash. |
| 6752 | */ |
| 6753 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 6754 | if (rval == QLA_SUCCESS) |
| 6755 | return rval; |
| 6756 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6757 | return qla24xx_load_risc_flash(vha, srisc_addr, |
| 6758 | vha->hw->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6759 | } |
| 6760 | |
| 6761 | int |
| 6762 | qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 6763 | { |
| 6764 | int rval; |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6765 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6766 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 6767 | if (ql2xfwloadbin == 2) |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6768 | goto try_blob_fw; |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 6769 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6770 | /* |
| 6771 | * FW Load priority: |
| 6772 | * 1) Firmware residing in flash. |
| 6773 | * 2) Firmware via request-firmware interface (.bin file). |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6774 | * 3) Golden-Firmware residing in flash -- limited operation. |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6775 | */ |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6776 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6777 | if (rval == QLA_SUCCESS) |
| 6778 | return rval; |
| 6779 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6780 | try_blob_fw: |
| 6781 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 6782 | if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw) |
| 6783 | return rval; |
| 6784 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6785 | ql_log(ql_log_info, vha, 0x0099, |
| 6786 | "Attempting to fallback to golden firmware.\n"); |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6787 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw); |
| 6788 | if (rval != QLA_SUCCESS) |
| 6789 | return rval; |
| 6790 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6791 | ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n"); |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6792 | ha->flags.running_gold_fw = 1; |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6793 | return rval; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6794 | } |
| 6795 | |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6796 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6797 | qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6798 | { |
| 6799 | int ret, retries; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6800 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6801 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 6802 | if (ha->flags.pci_channel_io_perm_failure) |
| 6803 | return; |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 6804 | if (!IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6805 | return; |
Andrew Vasquez | 75edf81 | 2007-05-07 07:43:00 -0700 | [diff] [blame] | 6806 | if (!ha->fw_major_version) |
| 6807 | return; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6808 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6809 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 7c7f1f2 | 2008-02-28 14:06:09 -0800 | [diff] [blame] | 6810 | for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT && |
Andrew Vasquez | b469a7c | 2009-04-06 22:33:48 -0700 | [diff] [blame] | 6811 | ret != QLA_INVALID_COMMAND && retries ; retries--) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6812 | ha->isp_ops->reset_chip(vha); |
| 6813 | if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6814 | continue; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6815 | if (qla2x00_setup_chip(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6816 | continue; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6817 | ql_log(ql_log_info, vha, 0x8015, |
| 6818 | "Attempting retry of stop-firmware command.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6819 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 6820 | } |
| 6821 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6822 | |
| 6823 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6824 | qla24xx_configure_vhba(scsi_qla_host_t *vha) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6825 | { |
| 6826 | int rval = QLA_SUCCESS; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 6827 | int rval2; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6828 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6829 | struct qla_hw_data *ha = vha->hw; |
| 6830 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 6831 | struct req_que *req; |
| 6832 | struct rsp_que *rsp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6833 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6834 | if (!vha->vp_idx) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6835 | return -EINVAL; |
| 6836 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6837 | rval = qla2x00_fw_ready(base_vha); |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 6838 | if (vha->qpair) |
| 6839 | req = vha->qpair->req; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 6840 | else |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 6841 | req = ha->req_q_map[0]; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 6842 | rsp = req->rsp; |
| 6843 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6844 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6845 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6846 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6847 | } |
| 6848 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6849 | vha->flags.management_server_logged_in = 0; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6850 | |
| 6851 | /* Login to SNS first */ |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 6852 | rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, |
| 6853 | BIT_1); |
| 6854 | if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) { |
| 6855 | if (rval2 == QLA_MEMORY_ALLOC_FAILED) |
| 6856 | ql_dbg(ql_dbg_init, vha, 0x0120, |
| 6857 | "Failed SNS login: loop_id=%x, rval2=%d\n", |
| 6858 | NPH_SNS, rval2); |
| 6859 | else |
| 6860 | ql_dbg(ql_dbg_init, vha, 0x0103, |
| 6861 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x " |
| 6862 | "mb[2]=%x mb[6]=%x mb[7]=%x.\n", |
| 6863 | NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6864 | return (QLA_FUNCTION_FAILED); |
| 6865 | } |
| 6866 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6867 | atomic_set(&vha->loop_down_timer, 0); |
| 6868 | atomic_set(&vha->loop_state, LOOP_UP); |
| 6869 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 6870 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 6871 | rval = qla2x00_loop_resync(base_vha); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6872 | |
| 6873 | return rval; |
| 6874 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6875 | |
| 6876 | /* 84XX Support **************************************************************/ |
| 6877 | |
| 6878 | static LIST_HEAD(qla_cs84xx_list); |
| 6879 | static DEFINE_MUTEX(qla_cs84xx_mutex); |
| 6880 | |
| 6881 | static struct qla_chip_state_84xx * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6882 | qla84xx_get_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6883 | { |
| 6884 | struct qla_chip_state_84xx *cs84xx; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6885 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6886 | |
| 6887 | mutex_lock(&qla_cs84xx_mutex); |
| 6888 | |
| 6889 | /* Find any shared 84xx chip. */ |
| 6890 | list_for_each_entry(cs84xx, &qla_cs84xx_list, list) { |
| 6891 | if (cs84xx->bus == ha->pdev->bus) { |
| 6892 | kref_get(&cs84xx->kref); |
| 6893 | goto done; |
| 6894 | } |
| 6895 | } |
| 6896 | |
| 6897 | cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL); |
| 6898 | if (!cs84xx) |
| 6899 | goto done; |
| 6900 | |
| 6901 | kref_init(&cs84xx->kref); |
| 6902 | spin_lock_init(&cs84xx->access_lock); |
| 6903 | mutex_init(&cs84xx->fw_update_mutex); |
| 6904 | cs84xx->bus = ha->pdev->bus; |
| 6905 | |
| 6906 | list_add_tail(&cs84xx->list, &qla_cs84xx_list); |
| 6907 | done: |
| 6908 | mutex_unlock(&qla_cs84xx_mutex); |
| 6909 | return cs84xx; |
| 6910 | } |
| 6911 | |
| 6912 | static void |
| 6913 | __qla84xx_chip_release(struct kref *kref) |
| 6914 | { |
| 6915 | struct qla_chip_state_84xx *cs84xx = |
| 6916 | container_of(kref, struct qla_chip_state_84xx, kref); |
| 6917 | |
| 6918 | mutex_lock(&qla_cs84xx_mutex); |
| 6919 | list_del(&cs84xx->list); |
| 6920 | mutex_unlock(&qla_cs84xx_mutex); |
| 6921 | kfree(cs84xx); |
| 6922 | } |
| 6923 | |
| 6924 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6925 | qla84xx_put_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6926 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6927 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6928 | if (ha->cs84xx) |
| 6929 | kref_put(&ha->cs84xx->kref, __qla84xx_chip_release); |
| 6930 | } |
| 6931 | |
| 6932 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6933 | qla84xx_init_chip(scsi_qla_host_t *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6934 | { |
| 6935 | int rval; |
| 6936 | uint16_t status[2]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6937 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6938 | |
| 6939 | mutex_lock(&ha->cs84xx->fw_update_mutex); |
| 6940 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6941 | rval = qla84xx_verify_chip(vha, status); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 6942 | |
| 6943 | mutex_unlock(&ha->cs84xx->fw_update_mutex); |
| 6944 | |
| 6945 | return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED: |
| 6946 | QLA_SUCCESS; |
| 6947 | } |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6948 | |
| 6949 | /* 81XX Support **************************************************************/ |
| 6950 | |
| 6951 | int |
| 6952 | qla81xx_nvram_config(scsi_qla_host_t *vha) |
| 6953 | { |
| 6954 | int rval; |
| 6955 | struct init_cb_81xx *icb; |
| 6956 | struct nvram_81xx *nv; |
| 6957 | uint32_t *dptr; |
| 6958 | uint8_t *dptr1, *dptr2; |
| 6959 | uint32_t chksum; |
| 6960 | uint16_t cnt; |
| 6961 | struct qla_hw_data *ha = vha->hw; |
| 6962 | |
| 6963 | rval = QLA_SUCCESS; |
| 6964 | icb = (struct init_cb_81xx *)ha->init_cb; |
| 6965 | nv = ha->nvram; |
| 6966 | |
| 6967 | /* Determine NVRAM starting address. */ |
| 6968 | ha->nvram_size = sizeof(struct nvram_81xx); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6969 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 6970 | if (IS_P3P_TYPE(ha) || IS_QLA8031(ha)) |
| 6971 | ha->vpd_size = FA_VPD_SIZE_82XX; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6972 | |
| 6973 | /* Get VPD data into cache */ |
| 6974 | ha->vpd = ha->nvram + VPD_OFFSET; |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 6975 | ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2, |
| 6976 | ha->vpd_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6977 | |
| 6978 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 6979 | 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] | 6980 | ha->nvram_size); |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 6981 | dptr = (uint32_t *)nv; |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 6982 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++) |
| 6983 | chksum += le32_to_cpu(*dptr); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6984 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6985 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111, |
| 6986 | "Contents of NVRAM:\n"); |
| 6987 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112, |
| 6988 | (uint8_t *)nv, ha->nvram_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6989 | |
| 6990 | /* Bad NVRAM data, set defaults parameters. */ |
| 6991 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 6992 | || nv->id[3] != ' ' || |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6993 | nv->nvram_version < cpu_to_le16(ICB_VERSION)) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6994 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6995 | ql_log(ql_log_info, vha, 0x0073, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 6996 | "Inconsistent NVRAM detected: checksum=0x%x id=%c " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6997 | "version=0x%x.\n", chksum, nv->id[0], |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 6998 | le16_to_cpu(nv->nvram_version)); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6999 | ql_log(ql_log_info, vha, 0x0074, |
| 7000 | "Falling back to functioning (yet invalid -- WWPN) " |
| 7001 | "defaults.\n"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7002 | |
| 7003 | /* |
| 7004 | * Set default initialization control block. |
| 7005 | */ |
| 7006 | memset(nv, 0, ha->nvram_size); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7007 | nv->nvram_version = cpu_to_le16(ICB_VERSION); |
| 7008 | nv->version = cpu_to_le16(ICB_VERSION); |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 7009 | nv->frame_payload_size = 2048; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7010 | nv->execution_throttle = cpu_to_le16(0xFFFF); |
| 7011 | nv->exchange_count = cpu_to_le16(0); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7012 | nv->port_name[0] = 0x21; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7013 | nv->port_name[1] = 0x00 + ha->port_no + 1; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7014 | nv->port_name[2] = 0x00; |
| 7015 | nv->port_name[3] = 0xe0; |
| 7016 | nv->port_name[4] = 0x8b; |
| 7017 | nv->port_name[5] = 0x1c; |
| 7018 | nv->port_name[6] = 0x55; |
| 7019 | nv->port_name[7] = 0x86; |
| 7020 | nv->node_name[0] = 0x20; |
| 7021 | nv->node_name[1] = 0x00; |
| 7022 | nv->node_name[2] = 0x00; |
| 7023 | nv->node_name[3] = 0xe0; |
| 7024 | nv->node_name[4] = 0x8b; |
| 7025 | nv->node_name[5] = 0x1c; |
| 7026 | nv->node_name[6] = 0x55; |
| 7027 | nv->node_name[7] = 0x86; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7028 | nv->login_retry_count = cpu_to_le16(8); |
| 7029 | nv->interrupt_delay_timer = cpu_to_le16(0); |
| 7030 | nv->login_timeout = cpu_to_le16(0); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7031 | nv->firmware_options_1 = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7032 | cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 7033 | nv->firmware_options_2 = cpu_to_le32(2 << 4); |
| 7034 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 7035 | nv->firmware_options_3 = cpu_to_le32(2 << 13); |
| 7036 | nv->host_p = cpu_to_le32(BIT_11|BIT_10); |
| 7037 | nv->efi_parameters = cpu_to_le32(0); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7038 | nv->reset_delay = 5; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7039 | nv->max_luns_per_target = cpu_to_le16(128); |
| 7040 | nv->port_down_retry_count = cpu_to_le16(30); |
| 7041 | nv->link_down_timeout = cpu_to_le16(180); |
Andrew Vasquez | eeebcc9 | 2009-06-03 09:55:24 -0700 | [diff] [blame] | 7042 | nv->enode_mac[0] = 0x00; |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 7043 | nv->enode_mac[1] = 0xC0; |
| 7044 | nv->enode_mac[2] = 0xDD; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7045 | nv->enode_mac[3] = 0x04; |
| 7046 | nv->enode_mac[4] = 0x05; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7047 | nv->enode_mac[5] = 0x06 + ha->port_no + 1; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7048 | |
| 7049 | rval = 1; |
| 7050 | } |
| 7051 | |
Arun Easi | 9e522cd | 2012-08-22 14:21:31 -0400 | [diff] [blame] | 7052 | if (IS_T10_PI_CAPABLE(ha)) |
| 7053 | nv->frame_payload_size &= ~7; |
| 7054 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7055 | qlt_81xx_config_nvram_stage1(vha, nv); |
| 7056 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7057 | /* Reset Initialization control block */ |
Andrew Vasquez | 773120e | 2011-05-10 11:30:14 -0700 | [diff] [blame] | 7058 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7059 | |
| 7060 | /* Copy 1st segment. */ |
| 7061 | dptr1 = (uint8_t *)icb; |
| 7062 | dptr2 = (uint8_t *)&nv->version; |
| 7063 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 7064 | while (cnt--) |
| 7065 | *dptr1++ = *dptr2++; |
| 7066 | |
| 7067 | icb->login_retry_count = nv->login_retry_count; |
| 7068 | |
| 7069 | /* Copy 2nd segment. */ |
| 7070 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 7071 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 7072 | cnt = (uint8_t *)&icb->reserved_5 - |
| 7073 | (uint8_t *)&icb->interrupt_delay_timer; |
| 7074 | while (cnt--) |
| 7075 | *dptr1++ = *dptr2++; |
| 7076 | |
| 7077 | memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac)); |
| 7078 | /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */ |
| 7079 | 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] | 7080 | icb->enode_mac[0] = 0x00; |
| 7081 | icb->enode_mac[1] = 0xC0; |
| 7082 | icb->enode_mac[2] = 0xDD; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7083 | icb->enode_mac[3] = 0x04; |
| 7084 | icb->enode_mac[4] = 0x05; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7085 | icb->enode_mac[5] = 0x06 + ha->port_no + 1; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7086 | } |
| 7087 | |
Andrew Vasquez | b64b0e8 | 2009-03-24 09:08:01 -0700 | [diff] [blame] | 7088 | /* Use extended-initialization control block. */ |
| 7089 | memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb)); |
| 7090 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7091 | /* |
| 7092 | * Setup driver NVRAM options. |
| 7093 | */ |
| 7094 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7095 | "QLE8XXX"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7096 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7097 | qlt_81xx_config_nvram_stage2(vha, icb); |
| 7098 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7099 | /* Use alternate WWN? */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7100 | if (nv->host_p & cpu_to_le32(BIT_15)) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7101 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 7102 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 7103 | } |
| 7104 | |
| 7105 | /* Prepare nodename */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7106 | if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7107 | /* |
| 7108 | * Firmware will apply the following mask if the nodename was |
| 7109 | * not provided. |
| 7110 | */ |
| 7111 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 7112 | icb->node_name[0] &= 0xF0; |
| 7113 | } |
| 7114 | |
| 7115 | /* Set host adapter parameters. */ |
| 7116 | ha->flags.disable_risc_code_load = 0; |
| 7117 | ha->flags.enable_lip_reset = 0; |
| 7118 | ha->flags.enable_lip_full_login = |
| 7119 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 7120 | ha->flags.enable_target_reset = |
| 7121 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
| 7122 | ha->flags.enable_led_scheme = 0; |
| 7123 | ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0; |
| 7124 | |
| 7125 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 7126 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 7127 | |
| 7128 | /* save HBA serial number */ |
| 7129 | ha->serial0 = icb->port_name[5]; |
| 7130 | ha->serial1 = icb->port_name[6]; |
| 7131 | ha->serial2 = icb->port_name[7]; |
| 7132 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 7133 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
| 7134 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7135 | icb->execution_throttle = cpu_to_le16(0xFFFF); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7136 | |
| 7137 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 7138 | |
| 7139 | /* Set minimum login_timeout to 4 seconds. */ |
| 7140 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 7141 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 7142 | if (le16_to_cpu(nv->login_timeout) < 4) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7143 | nv->login_timeout = cpu_to_le16(4); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7144 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7145 | |
| 7146 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 7147 | ha->r_a_tov = 100; |
| 7148 | |
| 7149 | ha->loop_reset_delay = nv->reset_delay; |
| 7150 | |
| 7151 | /* Link Down Timeout = 0: |
| 7152 | * |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 7153 | * When Port Down timer expires we will start returning |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7154 | * I/O's to OS with "DID_NO_CONNECT". |
| 7155 | * |
| 7156 | * Link Down Timeout != 0: |
| 7157 | * |
| 7158 | * The driver waits for the link to come up after link down |
| 7159 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 7160 | */ |
| 7161 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 7162 | ha->loop_down_abort_time = |
| 7163 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 7164 | } else { |
| 7165 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 7166 | ha->loop_down_abort_time = |
| 7167 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 7168 | } |
| 7169 | |
| 7170 | /* Need enough time to try and get the port back. */ |
| 7171 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 7172 | if (qlport_down_retry) |
| 7173 | ha->port_down_retry_count = qlport_down_retry; |
| 7174 | |
| 7175 | /* Set login_retry_count */ |
| 7176 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 7177 | if (ha->port_down_retry_count == |
| 7178 | le16_to_cpu(nv->port_down_retry_count) && |
| 7179 | ha->port_down_retry_count > 3) |
| 7180 | ha->login_retry_count = ha->port_down_retry_count; |
| 7181 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 7182 | ha->login_retry_count = ha->port_down_retry_count; |
| 7183 | if (ql2xloginretrycount) |
| 7184 | ha->login_retry_count = ql2xloginretrycount; |
| 7185 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 7186 | /* if not running MSI-X we need handshaking on interrupts */ |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7187 | 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] | 7188 | icb->firmware_options_2 |= cpu_to_le32(BIT_22); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 7189 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7190 | /* Enable ZIO. */ |
| 7191 | if (!vha->flags.init_done) { |
| 7192 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 7193 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 7194 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 7195 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 7196 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7197 | icb->firmware_options_2 &= cpu_to_le32( |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7198 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
| 7199 | vha->flags.process_response_queue = 0; |
| 7200 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
| 7201 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 7202 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7203 | ql_log(ql_log_info, vha, 0x0075, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7204 | "ZIO mode %d enabled; timer delay (%d us).\n", |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7205 | ha->zio_mode, |
| 7206 | ha->zio_timer * 100); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7207 | |
| 7208 | icb->firmware_options_2 |= cpu_to_le32( |
| 7209 | (uint32_t)ha->zio_mode); |
| 7210 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
| 7211 | vha->flags.process_response_queue = 1; |
| 7212 | } |
| 7213 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame^] | 7214 | /* enable RIDA Format2 */ |
| 7215 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) |
| 7216 | icb->firmware_options_3 |= BIT_0; |
| 7217 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7218 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7219 | ql_log(ql_log_warn, vha, 0x0076, |
| 7220 | "NVRAM configuration failed.\n"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7221 | } |
| 7222 | return (rval); |
| 7223 | } |
| 7224 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7225 | int |
| 7226 | qla82xx_restart_isp(scsi_qla_host_t *vha) |
| 7227 | { |
| 7228 | int status, rval; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7229 | struct qla_hw_data *ha = vha->hw; |
| 7230 | struct req_que *req = ha->req_q_map[0]; |
| 7231 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
| 7232 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 7233 | unsigned long flags; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7234 | |
| 7235 | status = qla2x00_init_rings(vha); |
| 7236 | if (!status) { |
| 7237 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 7238 | ha->flags.chip_reset_done = 1; |
| 7239 | |
| 7240 | status = qla2x00_fw_ready(vha); |
| 7241 | if (!status) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7242 | /* Issue a marker after FW becomes ready. */ |
| 7243 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7244 | vha->flags.online = 1; |
Chad Dupuis | 7108b76 | 2014-04-11 16:54:45 -0400 | [diff] [blame] | 7245 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7246 | } |
| 7247 | |
| 7248 | /* if no cable then assume it's good */ |
| 7249 | if ((vha->device_flags & DFLG_NO_CABLE)) |
| 7250 | status = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7251 | } |
| 7252 | |
| 7253 | if (!status) { |
| 7254 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 7255 | |
| 7256 | if (!atomic_read(&vha->loop_down_timer)) { |
| 7257 | /* |
| 7258 | * Issue marker command only when we are going |
| 7259 | * to start the I/O . |
| 7260 | */ |
| 7261 | vha->marker_needed = 1; |
| 7262 | } |
| 7263 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7264 | ha->isp_ops->enable_intrs(ha); |
| 7265 | |
| 7266 | ha->isp_abort_cnt = 0; |
| 7267 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 7268 | |
Saurav Kashyap | 5329678 | 2011-05-10 11:30:06 -0700 | [diff] [blame] | 7269 | /* Update the firmware version */ |
Giridhar Malavali | 3173167 | 2011-08-16 11:31:54 -0700 | [diff] [blame] | 7270 | status = qla82xx_check_md_needed(vha); |
Saurav Kashyap | 5329678 | 2011-05-10 11:30:06 -0700 | [diff] [blame] | 7271 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7272 | if (ha->fce) { |
| 7273 | ha->flags.fce_enabled = 1; |
| 7274 | memset(ha->fce, 0, |
| 7275 | fce_calc_size(ha->fce_bufs)); |
| 7276 | rval = qla2x00_enable_fce_trace(vha, |
| 7277 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 7278 | &ha->fce_bufs); |
| 7279 | if (rval) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7280 | ql_log(ql_log_warn, vha, 0x8001, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7281 | "Unable to reinitialize FCE (%d).\n", |
| 7282 | rval); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7283 | ha->flags.fce_enabled = 0; |
| 7284 | } |
| 7285 | } |
| 7286 | |
| 7287 | if (ha->eft) { |
| 7288 | memset(ha->eft, 0, EFT_SIZE); |
| 7289 | rval = qla2x00_enable_eft_trace(vha, |
| 7290 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 7291 | if (rval) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7292 | ql_log(ql_log_warn, vha, 0x8010, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7293 | "Unable to reinitialize EFT (%d).\n", |
| 7294 | rval); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7295 | } |
| 7296 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7297 | } |
| 7298 | |
| 7299 | if (!status) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7300 | ql_dbg(ql_dbg_taskm, vha, 0x8011, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7301 | "qla82xx_restart_isp succeeded.\n"); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 7302 | |
| 7303 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 7304 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 7305 | if (vp->vp_idx) { |
| 7306 | atomic_inc(&vp->vref_count); |
| 7307 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 7308 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7309 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 7310 | |
| 7311 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 7312 | atomic_dec(&vp->vref_count); |
| 7313 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7314 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 7315 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 7316 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7317 | } else { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7318 | ql_log(ql_log_warn, vha, 0x8016, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7319 | "qla82xx_restart_isp **** FAILED ****.\n"); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7320 | } |
| 7321 | |
| 7322 | return status; |
| 7323 | } |
| 7324 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7325 | void |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 7326 | qla81xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7327 | { |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 7328 | struct qla_hw_data *ha = vha->hw; |
| 7329 | |
Himanshu Madhani | f198caf | 2016-01-27 12:03:30 -0500 | [diff] [blame] | 7330 | /* Hold status IOCBs until ABTS response received. */ |
| 7331 | if (ql2xfwholdabts) |
| 7332 | ha->fw_options[3] |= BIT_12; |
| 7333 | |
Giridhar Malavali | 088d09d | 2016-07-06 11:14:20 -0400 | [diff] [blame] | 7334 | /* Set Retry FLOGI in case of P2P connection */ |
| 7335 | if (ha->operating_mode == P2P) { |
| 7336 | ha->fw_options[2] |= BIT_3; |
| 7337 | ql_dbg(ql_dbg_disc, vha, 0x2103, |
| 7338 | "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n", |
| 7339 | __func__, ha->fw_options[2]); |
| 7340 | } |
| 7341 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame^] | 7342 | /* Move PUREX, ABTS RX & RIDA to ATIOQ */ |
| 7343 | if (ql2xmvasynctoatio) { |
| 7344 | if (qla_tgt_mode_enabled(vha) || |
| 7345 | qla_dual_mode_enabled(vha)) |
| 7346 | ha->fw_options[2] |= BIT_11; |
| 7347 | else |
| 7348 | ha->fw_options[2] &= ~BIT_11; |
| 7349 | } |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 7350 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame^] | 7351 | if (ql2xetsenable) { |
| 7352 | /* Enable ETS Burst. */ |
| 7353 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
| 7354 | ha->fw_options[2] |= BIT_9; |
| 7355 | } |
| 7356 | |
| 7357 | ql_dbg(ql_dbg_init, vha, 0xffff, |
| 7358 | "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n", |
| 7359 | __func__, ha->fw_options[1], ha->fw_options[2], |
| 7360 | ha->fw_options[3], vha->host->active_mode); |
| 7361 | |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 7362 | qla2x00_set_fw_options(vha, ha->fw_options); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7363 | } |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7364 | |
| 7365 | /* |
| 7366 | * qla24xx_get_fcp_prio |
| 7367 | * Gets the fcp cmd priority value for the logged in port. |
| 7368 | * Looks for a match of the port descriptors within |
| 7369 | * each of the fcp prio config entries. If a match is found, |
| 7370 | * the tag (priority) value is returned. |
| 7371 | * |
| 7372 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 7373 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7374 | * fcport = port structure pointer. |
| 7375 | * |
| 7376 | * Return: |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 7377 | * non-zero (if found) |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7378 | * -1 (if not found) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7379 | * |
| 7380 | * Context: |
| 7381 | * Kernel context |
| 7382 | */ |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7383 | static int |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7384 | qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 7385 | { |
| 7386 | int i, entries; |
| 7387 | uint8_t pid_match, wwn_match; |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7388 | int priority; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7389 | uint32_t pid1, pid2; |
| 7390 | uint64_t wwn1, wwn2; |
| 7391 | struct qla_fcp_prio_entry *pri_entry; |
| 7392 | struct qla_hw_data *ha = vha->hw; |
| 7393 | |
| 7394 | if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled) |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7395 | return -1; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7396 | |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7397 | priority = -1; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7398 | entries = ha->fcp_prio_cfg->num_entries; |
| 7399 | pri_entry = &ha->fcp_prio_cfg->entry[0]; |
| 7400 | |
| 7401 | for (i = 0; i < entries; i++) { |
| 7402 | pid_match = wwn_match = 0; |
| 7403 | |
| 7404 | if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) { |
| 7405 | pri_entry++; |
| 7406 | continue; |
| 7407 | } |
| 7408 | |
| 7409 | /* check source pid for a match */ |
| 7410 | if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) { |
| 7411 | pid1 = pri_entry->src_pid & INVALID_PORT_ID; |
| 7412 | pid2 = vha->d_id.b24 & INVALID_PORT_ID; |
| 7413 | if (pid1 == INVALID_PORT_ID) |
| 7414 | pid_match++; |
| 7415 | else if (pid1 == pid2) |
| 7416 | pid_match++; |
| 7417 | } |
| 7418 | |
| 7419 | /* check destination pid for a match */ |
| 7420 | if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) { |
| 7421 | pid1 = pri_entry->dst_pid & INVALID_PORT_ID; |
| 7422 | pid2 = fcport->d_id.b24 & INVALID_PORT_ID; |
| 7423 | if (pid1 == INVALID_PORT_ID) |
| 7424 | pid_match++; |
| 7425 | else if (pid1 == pid2) |
| 7426 | pid_match++; |
| 7427 | } |
| 7428 | |
| 7429 | /* check source WWN for a match */ |
| 7430 | if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) { |
| 7431 | wwn1 = wwn_to_u64(vha->port_name); |
| 7432 | wwn2 = wwn_to_u64(pri_entry->src_wwpn); |
| 7433 | if (wwn2 == (uint64_t)-1) |
| 7434 | wwn_match++; |
| 7435 | else if (wwn1 == wwn2) |
| 7436 | wwn_match++; |
| 7437 | } |
| 7438 | |
| 7439 | /* check destination WWN for a match */ |
| 7440 | if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) { |
| 7441 | wwn1 = wwn_to_u64(fcport->port_name); |
| 7442 | wwn2 = wwn_to_u64(pri_entry->dst_wwpn); |
| 7443 | if (wwn2 == (uint64_t)-1) |
| 7444 | wwn_match++; |
| 7445 | else if (wwn1 == wwn2) |
| 7446 | wwn_match++; |
| 7447 | } |
| 7448 | |
| 7449 | if (pid_match == 2 || wwn_match == 2) { |
| 7450 | /* Found a matching entry */ |
| 7451 | if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID) |
| 7452 | priority = pri_entry->tag; |
| 7453 | break; |
| 7454 | } |
| 7455 | |
| 7456 | pri_entry++; |
| 7457 | } |
| 7458 | |
| 7459 | return priority; |
| 7460 | } |
| 7461 | |
| 7462 | /* |
| 7463 | * qla24xx_update_fcport_fcp_prio |
| 7464 | * Activates fcp priority for the logged in fc port |
| 7465 | * |
| 7466 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 7467 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7468 | * fcp = port structure pointer. |
| 7469 | * |
| 7470 | * Return: |
| 7471 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 7472 | * |
| 7473 | * Context: |
| 7474 | * Kernel context. |
| 7475 | */ |
| 7476 | int |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 7477 | 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] | 7478 | { |
| 7479 | int ret; |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7480 | int priority; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7481 | uint16_t mb[5]; |
| 7482 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 7483 | if (fcport->port_type != FCT_TARGET || |
| 7484 | fcport->loop_id == FC_NO_LOOP_ID) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7485 | return QLA_FUNCTION_FAILED; |
| 7486 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 7487 | priority = qla24xx_get_fcp_prio(vha, fcport); |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7488 | if (priority < 0) |
| 7489 | return QLA_FUNCTION_FAILED; |
| 7490 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 7491 | if (IS_P3P_TYPE(vha->hw)) { |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 7492 | fcport->fcp_prio = priority & 0xf; |
| 7493 | return QLA_SUCCESS; |
| 7494 | } |
| 7495 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 7496 | ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb); |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7497 | if (ret == QLA_SUCCESS) { |
| 7498 | if (fcport->fcp_prio != priority) |
| 7499 | ql_dbg(ql_dbg_user, vha, 0x709e, |
| 7500 | "Updated FCP_CMND priority - value=%d loop_id=%d " |
| 7501 | "port_id=%02x%02x%02x.\n", priority, |
| 7502 | fcport->loop_id, fcport->d_id.b.domain, |
| 7503 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 7504 | fcport->fcp_prio = priority & 0xf; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7505 | } else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7506 | ql_dbg(ql_dbg_user, vha, 0x704f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7507 | "Unable to update FCP_CMND priority - ret=0x%x for " |
| 7508 | "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id, |
| 7509 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 7510 | fcport->d_id.b.al_pa); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7511 | return ret; |
| 7512 | } |
| 7513 | |
| 7514 | /* |
| 7515 | * qla24xx_update_all_fcp_prio |
| 7516 | * Activates fcp priority for all the logged in ports |
| 7517 | * |
| 7518 | * Input: |
| 7519 | * ha = adapter block pointer. |
| 7520 | * |
| 7521 | * Return: |
| 7522 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 7523 | * |
| 7524 | * Context: |
| 7525 | * Kernel context. |
| 7526 | */ |
| 7527 | int |
| 7528 | qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha) |
| 7529 | { |
| 7530 | int ret; |
| 7531 | fc_port_t *fcport; |
| 7532 | |
| 7533 | ret = QLA_FUNCTION_FAILED; |
| 7534 | /* We need to set priority for all logged in ports */ |
| 7535 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 7536 | ret = qla24xx_update_fcport_fcp_prio(vha, fcport); |
| 7537 | |
| 7538 | return ret; |
| 7539 | } |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7540 | |
| 7541 | struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos, int vp_idx) |
| 7542 | { |
| 7543 | int rsp_id = 0; |
| 7544 | int req_id = 0; |
| 7545 | int i; |
| 7546 | struct qla_hw_data *ha = vha->hw; |
| 7547 | uint16_t qpair_id = 0; |
| 7548 | struct qla_qpair *qpair = NULL; |
| 7549 | struct qla_msix_entry *msix; |
| 7550 | |
| 7551 | if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) { |
| 7552 | ql_log(ql_log_warn, vha, 0x00181, |
| 7553 | "FW/Driver is not multi-queue capable.\n"); |
| 7554 | return NULL; |
| 7555 | } |
| 7556 | |
| 7557 | if (ql2xmqsupport) { |
| 7558 | qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL); |
| 7559 | if (qpair == NULL) { |
| 7560 | ql_log(ql_log_warn, vha, 0x0182, |
| 7561 | "Failed to allocate memory for queue pair.\n"); |
| 7562 | return NULL; |
| 7563 | } |
| 7564 | memset(qpair, 0, sizeof(struct qla_qpair)); |
| 7565 | |
| 7566 | qpair->hw = vha->hw; |
| 7567 | |
| 7568 | /* Assign available que pair id */ |
| 7569 | mutex_lock(&ha->mq_lock); |
| 7570 | qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs); |
| 7571 | if (qpair_id >= ha->max_qpairs) { |
| 7572 | mutex_unlock(&ha->mq_lock); |
| 7573 | ql_log(ql_log_warn, vha, 0x0183, |
| 7574 | "No resources to create additional q pair.\n"); |
| 7575 | goto fail_qid_map; |
| 7576 | } |
| 7577 | set_bit(qpair_id, ha->qpair_qid_map); |
| 7578 | ha->queue_pair_map[qpair_id] = qpair; |
| 7579 | qpair->id = qpair_id; |
| 7580 | qpair->vp_idx = vp_idx; |
| 7581 | |
| 7582 | for (i = 0; i < ha->msix_count; i++) { |
Quinn Tran | 093df73 | 2016-12-12 14:40:09 -0800 | [diff] [blame] | 7583 | msix = &ha->msix_entries[i]; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7584 | if (msix->in_use) |
| 7585 | continue; |
| 7586 | qpair->msix = msix; |
| 7587 | ql_log(ql_dbg_multiq, vha, 0xc00f, |
| 7588 | "Vector %x selected for qpair\n", msix->vector); |
| 7589 | break; |
| 7590 | } |
| 7591 | if (!qpair->msix) { |
| 7592 | ql_log(ql_log_warn, vha, 0x0184, |
| 7593 | "Out of MSI-X vectors!.\n"); |
| 7594 | goto fail_msix; |
| 7595 | } |
| 7596 | |
| 7597 | qpair->msix->in_use = 1; |
| 7598 | list_add_tail(&qpair->qp_list_elem, &vha->qp_list); |
| 7599 | |
| 7600 | mutex_unlock(&ha->mq_lock); |
| 7601 | |
| 7602 | /* Create response queue first */ |
| 7603 | rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair); |
| 7604 | if (!rsp_id) { |
| 7605 | ql_log(ql_log_warn, vha, 0x0185, |
| 7606 | "Failed to create response queue.\n"); |
| 7607 | goto fail_rsp; |
| 7608 | } |
| 7609 | |
| 7610 | qpair->rsp = ha->rsp_q_map[rsp_id]; |
| 7611 | |
| 7612 | /* Create request queue */ |
| 7613 | req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos); |
| 7614 | if (!req_id) { |
| 7615 | ql_log(ql_log_warn, vha, 0x0186, |
| 7616 | "Failed to create request queue.\n"); |
| 7617 | goto fail_req; |
| 7618 | } |
| 7619 | |
| 7620 | qpair->req = ha->req_q_map[req_id]; |
| 7621 | qpair->rsp->req = qpair->req; |
| 7622 | |
| 7623 | if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) { |
| 7624 | if (ha->fw_attributes & BIT_4) |
| 7625 | qpair->difdix_supported = 1; |
| 7626 | } |
| 7627 | |
| 7628 | qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep); |
| 7629 | if (!qpair->srb_mempool) { |
| 7630 | ql_log(ql_log_warn, vha, 0x0191, |
| 7631 | "Failed to create srb mempool for qpair %d\n", |
| 7632 | qpair->id); |
| 7633 | goto fail_mempool; |
| 7634 | } |
| 7635 | |
| 7636 | /* Mark as online */ |
| 7637 | qpair->online = 1; |
| 7638 | |
| 7639 | if (!vha->flags.qpairs_available) |
| 7640 | vha->flags.qpairs_available = 1; |
| 7641 | |
| 7642 | ql_dbg(ql_dbg_multiq, vha, 0xc00d, |
| 7643 | "Request/Response queue pair created, id %d\n", |
| 7644 | qpair->id); |
| 7645 | ql_dbg(ql_dbg_init, vha, 0x0187, |
| 7646 | "Request/Response queue pair created, id %d\n", |
| 7647 | qpair->id); |
| 7648 | } |
| 7649 | return qpair; |
| 7650 | |
| 7651 | fail_mempool: |
| 7652 | fail_req: |
| 7653 | qla25xx_delete_rsp_que(vha, qpair->rsp); |
| 7654 | fail_rsp: |
| 7655 | mutex_lock(&ha->mq_lock); |
| 7656 | qpair->msix->in_use = 0; |
| 7657 | list_del(&qpair->qp_list_elem); |
| 7658 | if (list_empty(&vha->qp_list)) |
| 7659 | vha->flags.qpairs_available = 0; |
| 7660 | fail_msix: |
| 7661 | ha->queue_pair_map[qpair_id] = NULL; |
| 7662 | clear_bit(qpair_id, ha->qpair_qid_map); |
| 7663 | mutex_unlock(&ha->mq_lock); |
| 7664 | fail_qid_map: |
| 7665 | kfree(qpair); |
| 7666 | return NULL; |
| 7667 | } |
| 7668 | |
| 7669 | int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair) |
| 7670 | { |
| 7671 | int ret; |
| 7672 | struct qla_hw_data *ha = qpair->hw; |
| 7673 | |
| 7674 | qpair->delete_in_progress = 1; |
| 7675 | while (atomic_read(&qpair->ref_count)) |
| 7676 | msleep(500); |
| 7677 | |
| 7678 | ret = qla25xx_delete_req_que(vha, qpair->req); |
| 7679 | if (ret != QLA_SUCCESS) |
| 7680 | goto fail; |
| 7681 | ret = qla25xx_delete_rsp_que(vha, qpair->rsp); |
| 7682 | if (ret != QLA_SUCCESS) |
| 7683 | goto fail; |
| 7684 | |
| 7685 | mutex_lock(&ha->mq_lock); |
| 7686 | ha->queue_pair_map[qpair->id] = NULL; |
| 7687 | clear_bit(qpair->id, ha->qpair_qid_map); |
| 7688 | list_del(&qpair->qp_list_elem); |
| 7689 | if (list_empty(&vha->qp_list)) |
| 7690 | vha->flags.qpairs_available = 0; |
| 7691 | mempool_destroy(qpair->srb_mempool); |
| 7692 | kfree(qpair); |
| 7693 | mutex_unlock(&ha->mq_lock); |
| 7694 | |
| 7695 | return QLA_SUCCESS; |
| 7696 | fail: |
| 7697 | return ret; |
| 7698 | } |