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 *); |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 39 | static int qla24xx_post_prli_work(struct scsi_qla_host*, fc_port_t *); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 40 | static void qla24xx_handle_plogi_done_event(struct scsi_qla_host *, |
| 41 | struct event_arg *); |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 42 | static void qla24xx_handle_prli_done_event(struct scsi_qla_host *, |
| 43 | struct event_arg *); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 44 | static void __qla24xx_handle_gpdb_event(scsi_qla_host_t *, struct event_arg *); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 45 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 46 | /* SRB Extensions ---------------------------------------------------------- */ |
| 47 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 48 | void |
Kees Cook | 8e5f4ba | 2017-09-03 13:23:32 -0700 | [diff] [blame] | 49 | qla2x00_sp_timeout(struct timer_list *t) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 50 | { |
Kees Cook | 8e5f4ba | 2017-09-03 13:23:32 -0700 | [diff] [blame] | 51 | srb_t *sp = from_timer(sp, t, u.iocb_cmd.timer); |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 52 | struct srb_iocb *iocb; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 53 | scsi_qla_host_t *vha = sp->vha; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 54 | struct req_que *req; |
| 55 | unsigned long flags; |
| 56 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 57 | spin_lock_irqsave(&vha->hw->hardware_lock, flags); |
| 58 | req = vha->hw->req_q_map[0]; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 59 | req->outstanding_cmds[sp->handle] = NULL; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 60 | iocb = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 61 | iocb->timeout(sp); |
Giridhar Malavali | 045d6ea | 2017-12-28 12:33:21 -0800 | [diff] [blame] | 62 | if (sp->type != SRB_ELS_DCMD) |
| 63 | sp->free(sp); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 64 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 67 | void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 68 | qla2x00_sp_free(void *ptr) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 69 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 70 | srb_t *sp = ptr; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 71 | struct srb_iocb *iocb = &sp->u.iocb_cmd; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 72 | |
Chad Dupuis | 4d97cc5 | 2010-10-15 11:27:41 -0700 | [diff] [blame] | 73 | del_timer(&iocb->timer); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 74 | qla2x00_rel_sp(sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 77 | /* Asynchronous Login/Logout Routines -------------------------------------- */ |
| 78 | |
Saurav Kashyap | a9b6f72 | 2012-08-22 14:21:01 -0400 | [diff] [blame] | 79 | unsigned long |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 80 | qla2x00_get_async_timeout(struct scsi_qla_host *vha) |
| 81 | { |
| 82 | unsigned long tmo; |
| 83 | struct qla_hw_data *ha = vha->hw; |
| 84 | |
| 85 | /* Firmware should use switch negotiated r_a_tov for timeout. */ |
| 86 | tmo = ha->r_a_tov / 10 * 2; |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 87 | if (IS_QLAFX00(ha)) { |
| 88 | tmo = FX00_DEF_RATOV * 2; |
| 89 | } else if (!IS_FWI2_CAPABLE(ha)) { |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 90 | /* |
| 91 | * Except for earlier ISPs where the timeout is seeded from the |
| 92 | * initialization control block. |
| 93 | */ |
| 94 | tmo = ha->login_timeout; |
| 95 | } |
| 96 | return tmo; |
| 97 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 98 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 99 | void |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 100 | qla2x00_async_iocb_timeout(void *data) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 101 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 102 | srb_t *sp = data; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 103 | fc_port_t *fcport = sp->fcport; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 104 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
| 105 | struct event_arg ea; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 106 | |
Quinn Tran | 5c25d45 | 2017-12-28 12:33:09 -0800 | [diff] [blame] | 107 | if (fcport) { |
| 108 | ql_dbg(ql_dbg_disc, fcport->vha, 0x2071, |
| 109 | "Async-%s timeout - hdl=%x portid=%06x %8phC.\n", |
| 110 | sp->name, sp->handle, fcport->d_id.b24, fcport->port_name); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 111 | |
Quinn Tran | 6d674927 | 2017-12-28 12:33:41 -0800 | [diff] [blame] | 112 | fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE); |
Quinn Tran | 5c25d45 | 2017-12-28 12:33:09 -0800 | [diff] [blame] | 113 | } else { |
| 114 | pr_info("Async-%s timeout - hdl=%x.\n", |
| 115 | sp->name, sp->handle); |
| 116 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 117 | |
| 118 | switch (sp->type) { |
| 119 | case SRB_LOGIN_CMD: |
himanshu.madhani@cavium.com | 7ac0c33 | 2018-01-15 20:46:48 -0800 | [diff] [blame] | 120 | if (!fcport) |
| 121 | break; |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 122 | /* Retry as needed. */ |
| 123 | lio->u.logio.data[0] = MBS_COMMAND_ERROR; |
| 124 | lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ? |
| 125 | QLA_LOGIO_LOGIN_RETRIED : 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 126 | memset(&ea, 0, sizeof(ea)); |
| 127 | ea.event = FCME_PLOGI_DONE; |
| 128 | ea.fcport = sp->fcport; |
| 129 | ea.data[0] = lio->u.logio.data[0]; |
| 130 | ea.data[1] = lio->u.logio.data[1]; |
| 131 | ea.sp = sp; |
| 132 | qla24xx_handle_plogi_done_event(fcport->vha, &ea); |
| 133 | break; |
| 134 | case SRB_LOGOUT_CMD: |
himanshu.madhani@cavium.com | 7ac0c33 | 2018-01-15 20:46:48 -0800 | [diff] [blame] | 135 | if (!fcport) |
| 136 | break; |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 137 | qlt_logo_completion_handler(fcport, QLA_FUNCTION_TIMEOUT); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 138 | break; |
| 139 | case SRB_CT_PTHRU_CMD: |
| 140 | case SRB_MB_IOCB: |
| 141 | case SRB_NACK_PLOGI: |
| 142 | case SRB_NACK_PRLI: |
| 143 | case SRB_NACK_LOGO: |
Quinn Tran | 2853192 | 2017-12-28 12:33:10 -0800 | [diff] [blame] | 144 | case SRB_CTRL_VP: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 145 | sp->done(sp, QLA_FUNCTION_TIMEOUT); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 146 | break; |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 147 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 150 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 151 | qla2x00_async_login_sp_done(void *ptr, int res) |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 152 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 153 | srb_t *sp = ptr; |
| 154 | struct scsi_qla_host *vha = sp->vha; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 155 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 156 | struct event_arg ea; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 157 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 158 | ql_dbg(ql_dbg_disc, vha, 0x20dd, |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 159 | "%s %8phC res %d \n", __func__, sp->fcport->port_name, res); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 160 | |
Quinn Tran | 6d674927 | 2017-12-28 12:33:41 -0800 | [diff] [blame] | 161 | sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE); |
| 162 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 163 | if (!test_bit(UNLOADING, &vha->dpc_flags)) { |
| 164 | memset(&ea, 0, sizeof(ea)); |
| 165 | ea.event = FCME_PLOGI_DONE; |
| 166 | ea.fcport = sp->fcport; |
| 167 | ea.data[0] = lio->u.logio.data[0]; |
| 168 | ea.data[1] = lio->u.logio.data[1]; |
| 169 | ea.iop[0] = lio->u.logio.iop[0]; |
| 170 | ea.iop[1] = lio->u.logio.iop[1]; |
| 171 | ea.sp = sp; |
| 172 | qla2x00_fcport_event_handler(vha, &ea); |
| 173 | } |
| 174 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 175 | sp->free(sp); |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 178 | int |
| 179 | qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 180 | uint16_t *data) |
| 181 | { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 182 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 183 | struct srb_iocb *lio; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 184 | int rval = QLA_FUNCTION_FAILED; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 185 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 186 | if (!vha->flags.online) |
| 187 | goto done; |
| 188 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 189 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 190 | if (!sp) |
| 191 | goto done; |
| 192 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 193 | fcport->flags |= FCF_ASYNC_SENT; |
| 194 | fcport->logout_completed = 0; |
| 195 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 196 | fcport->disc_state = DSC_LOGIN_PEND; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 197 | sp->type = SRB_LOGIN_CMD; |
| 198 | sp->name = "login"; |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 199 | sp->gen1 = fcport->rscn_gen; |
| 200 | sp->gen2 = fcport->login_gen; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 201 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 202 | |
| 203 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 204 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 205 | sp->done = qla2x00_async_login_sp_done; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 206 | lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI; |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 207 | |
| 208 | if (fcport->fc4f_nvme) |
| 209 | lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI; |
| 210 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 211 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 212 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 213 | rval = qla2x00_start_sp(sp); |
Chad Dupuis | 080c951 | 2016-01-27 12:03:37 -0500 | [diff] [blame] | 214 | if (rval != QLA_SUCCESS) { |
Chad Dupuis | 080c951 | 2016-01-27 12:03:37 -0500 | [diff] [blame] | 215 | fcport->flags |= FCF_LOGIN_NEEDED; |
| 216 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 217 | goto done_free_sp; |
Chad Dupuis | 080c951 | 2016-01-27 12:03:37 -0500 | [diff] [blame] | 218 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 219 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 220 | ql_dbg(ql_dbg_disc, vha, 0x2072, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 221 | "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x " |
| 222 | "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 223 | fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 224 | fcport->login_retry); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 225 | return rval; |
| 226 | |
| 227 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 228 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 229 | fcport->flags &= ~FCF_ASYNC_SENT; |
Quinn Tran | 3dbec59 | 2017-12-28 12:33:40 -0800 | [diff] [blame] | 230 | done: |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 231 | return rval; |
| 232 | } |
| 233 | |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 234 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 235 | qla2x00_async_logout_sp_done(void *ptr, int res) |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 236 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 237 | srb_t *sp = ptr; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 238 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 239 | |
Quinn Tran | 6d674927 | 2017-12-28 12:33:41 -0800 | [diff] [blame] | 240 | sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 241 | if (!test_bit(UNLOADING, &sp->vha->dpc_flags)) |
| 242 | qla2x00_post_async_logout_done_work(sp->vha, sp->fcport, |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 243 | lio->u.logio.data); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 244 | sp->free(sp); |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 247 | int |
| 248 | qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 249 | { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 250 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 251 | struct srb_iocb *lio; |
Quinn Tran | 3dbec59 | 2017-12-28 12:33:40 -0800 | [diff] [blame] | 252 | int rval = QLA_FUNCTION_FAILED; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 253 | |
Quinn Tran | 3dbec59 | 2017-12-28 12:33:40 -0800 | [diff] [blame] | 254 | if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT)) |
| 255 | return rval; |
| 256 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 257 | fcport->flags |= FCF_ASYNC_SENT; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 258 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 259 | if (!sp) |
| 260 | goto done; |
| 261 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 262 | sp->type = SRB_LOGOUT_CMD; |
| 263 | sp->name = "logout"; |
| 264 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 265 | |
| 266 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 267 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 268 | sp->done = qla2x00_async_logout_sp_done; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 269 | rval = qla2x00_start_sp(sp); |
| 270 | if (rval != QLA_SUCCESS) |
| 271 | goto done_free_sp; |
| 272 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 273 | ql_dbg(ql_dbg_disc, vha, 0x2070, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 274 | "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] | 275 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 276 | fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 277 | fcport->port_name); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 278 | return rval; |
| 279 | |
| 280 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 281 | sp->free(sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 282 | done: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 283 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 284 | return rval; |
| 285 | } |
Quinn Tran | 11aea16 | 2017-12-28 12:33:20 -0800 | [diff] [blame] | 286 | |
| 287 | void |
| 288 | qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 289 | uint16_t *data) |
| 290 | { |
| 291 | /* Don't re-login in target mode */ |
| 292 | if (!fcport->tgt_session) |
| 293 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
| 294 | qlt_logo_completion_handler(fcport, data[0]); |
| 295 | } |
| 296 | |
| 297 | static void |
| 298 | qla2x00_async_prlo_sp_done(void *s, int res) |
| 299 | { |
| 300 | srb_t *sp = (srb_t *)s; |
| 301 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
| 302 | struct scsi_qla_host *vha = sp->vha; |
| 303 | |
| 304 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
| 305 | qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport, |
| 306 | lio->u.logio.data); |
| 307 | sp->free(sp); |
| 308 | } |
| 309 | |
| 310 | int |
| 311 | qla2x00_async_prlo(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 312 | { |
| 313 | srb_t *sp; |
| 314 | struct srb_iocb *lio; |
| 315 | int rval; |
| 316 | |
| 317 | rval = QLA_FUNCTION_FAILED; |
| 318 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 319 | if (!sp) |
| 320 | goto done; |
| 321 | |
| 322 | sp->type = SRB_PRLO_CMD; |
| 323 | sp->name = "prlo"; |
| 324 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 325 | |
| 326 | lio = &sp->u.iocb_cmd; |
| 327 | lio->timeout = qla2x00_async_iocb_timeout; |
| 328 | sp->done = qla2x00_async_prlo_sp_done; |
| 329 | rval = qla2x00_start_sp(sp); |
| 330 | if (rval != QLA_SUCCESS) |
| 331 | goto done_free_sp; |
| 332 | |
| 333 | ql_dbg(ql_dbg_disc, vha, 0x2070, |
| 334 | "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n", |
| 335 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
| 336 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
| 337 | return rval; |
| 338 | |
| 339 | done_free_sp: |
| 340 | sp->free(sp); |
| 341 | done: |
| 342 | return rval; |
| 343 | } |
| 344 | |
Quinn Tran | f13515a | 2017-12-28 12:33:15 -0800 | [diff] [blame] | 345 | static |
| 346 | void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, struct event_arg *ea) |
| 347 | { |
Quinn Tran | 0616e96 | 2017-12-28 12:33:34 -0800 | [diff] [blame] | 348 | struct fc_port *fcport = ea->fcport; |
| 349 | |
| 350 | ql_dbg(ql_dbg_disc, vha, 0x20d2, |
| 351 | "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n", |
| 352 | __func__, fcport->port_name, fcport->disc_state, |
| 353 | fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2, |
| 354 | fcport->rscn_gen, ea->sp->gen1, fcport->loop_id); |
| 355 | |
| 356 | if (ea->data[0] != MBS_COMMAND_COMPLETE) { |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 357 | ql_dbg(ql_dbg_disc, vha, 0x2066, |
| 358 | "%s %8phC: adisc fail: post delete\n", |
| 359 | __func__, ea->fcport->port_name); |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 360 | qlt_schedule_sess_for_deletion(ea->fcport); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 361 | return; |
| 362 | } |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 363 | |
| 364 | if (ea->fcport->disc_state == DSC_DELETE_PEND) |
| 365 | return; |
| 366 | |
| 367 | if (ea->sp->gen2 != ea->fcport->login_gen) { |
| 368 | /* target side must have changed it. */ |
| 369 | ql_dbg(ql_dbg_disc, vha, 0x20d3, |
Quinn Tran | 0616e96 | 2017-12-28 12:33:34 -0800 | [diff] [blame] | 370 | "%s %8phC generation changed\n", |
| 371 | __func__, ea->fcport->port_name); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 372 | return; |
| 373 | } else if (ea->sp->gen1 != ea->fcport->rscn_gen) { |
| 374 | ql_dbg(ql_dbg_disc, vha, 0x20d4, "%s %d %8phC post gidpn\n", |
| 375 | __func__, __LINE__, ea->fcport->port_name); |
| 376 | qla24xx_post_gidpn_work(vha, ea->fcport); |
| 377 | return; |
| 378 | } |
| 379 | |
| 380 | __qla24xx_handle_gpdb_event(vha, ea); |
Quinn Tran | f13515a | 2017-12-28 12:33:15 -0800 | [diff] [blame] | 381 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 382 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 383 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 384 | qla2x00_async_adisc_sp_done(void *ptr, int res) |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 385 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 386 | srb_t *sp = ptr; |
| 387 | struct scsi_qla_host *vha = sp->vha; |
Quinn Tran | f13515a | 2017-12-28 12:33:15 -0800 | [diff] [blame] | 388 | struct event_arg ea; |
Quinn Tran | 0616e96 | 2017-12-28 12:33:34 -0800 | [diff] [blame] | 389 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 390 | |
Quinn Tran | f13515a | 2017-12-28 12:33:15 -0800 | [diff] [blame] | 391 | ql_dbg(ql_dbg_disc, vha, 0x2066, |
| 392 | "Async done-%s res %x %8phC\n", |
| 393 | sp->name, res, sp->fcport->port_name); |
| 394 | |
| 395 | memset(&ea, 0, sizeof(ea)); |
| 396 | ea.event = FCME_ADISC_DONE; |
| 397 | ea.rc = res; |
Quinn Tran | 0616e96 | 2017-12-28 12:33:34 -0800 | [diff] [blame] | 398 | ea.data[0] = lio->u.logio.data[0]; |
| 399 | ea.data[1] = lio->u.logio.data[1]; |
| 400 | ea.iop[0] = lio->u.logio.iop[0]; |
| 401 | ea.iop[1] = lio->u.logio.iop[1]; |
Quinn Tran | f13515a | 2017-12-28 12:33:15 -0800 | [diff] [blame] | 402 | ea.fcport = sp->fcport; |
| 403 | ea.sp = sp; |
| 404 | |
| 405 | qla2x00_fcport_event_handler(vha, &ea); |
| 406 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 407 | sp->free(sp); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | int |
| 411 | qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 412 | uint16_t *data) |
| 413 | { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 414 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 415 | struct srb_iocb *lio; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 416 | int rval; |
| 417 | |
| 418 | rval = QLA_FUNCTION_FAILED; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 419 | fcport->flags |= FCF_ASYNC_SENT; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 420 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 421 | if (!sp) |
| 422 | goto done; |
| 423 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 424 | sp->type = SRB_ADISC_CMD; |
| 425 | sp->name = "adisc"; |
| 426 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 427 | |
| 428 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 429 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 430 | sp->done = qla2x00_async_adisc_sp_done; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 431 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 432 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 433 | rval = qla2x00_start_sp(sp); |
| 434 | if (rval != QLA_SUCCESS) |
| 435 | goto done_free_sp; |
| 436 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 437 | ql_dbg(ql_dbg_disc, vha, 0x206f, |
Quinn Tran | f13515a | 2017-12-28 12:33:15 -0800 | [diff] [blame] | 438 | "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n", |
| 439 | sp->handle, fcport->loop_id, fcport->d_id.b24, fcport->port_name); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 440 | return rval; |
| 441 | |
| 442 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 443 | sp->free(sp); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 444 | done: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 445 | fcport->flags &= ~FCF_ASYNC_SENT; |
Quinn Tran | f13515a | 2017-12-28 12:33:15 -0800 | [diff] [blame] | 446 | qla2x00_post_async_adisc_work(vha, fcport, data); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 447 | return rval; |
| 448 | } |
| 449 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 450 | static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha, |
| 451 | struct event_arg *ea) |
| 452 | { |
| 453 | fc_port_t *fcport, *conflict_fcport; |
| 454 | struct get_name_list_extended *e; |
| 455 | u16 i, n, found = 0, loop_id; |
| 456 | port_id_t id; |
| 457 | u64 wwn; |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 458 | u16 data[2]; |
| 459 | u8 current_login_state; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 460 | |
| 461 | fcport = ea->fcport; |
Quinn Tran | f352eeb | 2017-12-28 12:33:35 -0800 | [diff] [blame] | 462 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 463 | "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d\n", |
| 464 | __func__, fcport->port_name, fcport->disc_state, |
| 465 | fcport->fw_login_state, ea->rc, |
| 466 | fcport->login_gen, fcport->last_login_gen, |
| 467 | fcport->rscn_gen, fcport->last_rscn_gen, vha->loop_id); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 468 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 469 | if (fcport->disc_state == DSC_DELETE_PEND) |
| 470 | return; |
| 471 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 472 | if (ea->rc) { /* rval */ |
| 473 | if (fcport->login_retry == 0) { |
| 474 | fcport->login_retry = vha->hw->login_retry_count; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 475 | ql_dbg(ql_dbg_disc, vha, 0x20de, |
| 476 | "GNL failed Port login retry %8phN, retry cnt=%d.\n", |
| 477 | fcport->port_name, fcport->login_retry); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 478 | } |
| 479 | return; |
| 480 | } |
| 481 | |
| 482 | if (fcport->last_rscn_gen != fcport->rscn_gen) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 483 | ql_dbg(ql_dbg_disc, vha, 0x20df, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 484 | "%s %8phC rscn gen changed rscn %d|%d \n", |
| 485 | __func__, fcport->port_name, |
| 486 | fcport->last_rscn_gen, fcport->rscn_gen); |
| 487 | qla24xx_post_gidpn_work(vha, fcport); |
| 488 | return; |
| 489 | } else if (fcport->last_login_gen != fcport->login_gen) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 490 | ql_dbg(ql_dbg_disc, vha, 0x20e0, |
Quinn Tran | f352eeb | 2017-12-28 12:33:35 -0800 | [diff] [blame] | 491 | "%s %8phC login gen changed\n", |
| 492 | __func__, fcport->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 493 | return; |
| 494 | } |
| 495 | |
| 496 | n = ea->data[0] / sizeof(struct get_name_list_extended); |
| 497 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 498 | ql_dbg(ql_dbg_disc, vha, 0x20e1, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 499 | "%s %d %8phC n %d %02x%02x%02x lid %d \n", |
| 500 | __func__, __LINE__, fcport->port_name, n, |
| 501 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 502 | fcport->d_id.b.al_pa, fcport->loop_id); |
| 503 | |
| 504 | for (i = 0; i < n; i++) { |
| 505 | e = &vha->gnl.l[i]; |
| 506 | wwn = wwn_to_u64(e->port_name); |
| 507 | |
| 508 | if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE)) |
| 509 | continue; |
| 510 | |
| 511 | found = 1; |
| 512 | id.b.domain = e->port_id[2]; |
| 513 | id.b.area = e->port_id[1]; |
| 514 | id.b.al_pa = e->port_id[0]; |
| 515 | id.b.rsvd_1 = 0; |
| 516 | |
| 517 | loop_id = le16_to_cpu(e->nport_handle); |
| 518 | loop_id = (loop_id & 0x7fff); |
| 519 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 520 | ql_dbg(ql_dbg_disc, vha, 0x20e2, |
| 521 | "%s found %8phC CLS [%d|%d] ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n", |
| 522 | __func__, fcport->port_name, |
| 523 | e->current_login_state, fcport->fw_login_state, |
| 524 | id.b.domain, id.b.area, id.b.al_pa, |
| 525 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 526 | fcport->d_id.b.al_pa, loop_id, fcport->loop_id); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 527 | |
| 528 | if ((id.b24 != fcport->d_id.b24) || |
| 529 | ((fcport->loop_id != FC_NO_LOOP_ID) && |
| 530 | (fcport->loop_id != loop_id))) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 531 | ql_dbg(ql_dbg_disc, vha, 0x20e3, |
| 532 | "%s %d %8phC post del sess\n", |
| 533 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 534 | qlt_schedule_sess_for_deletion(fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 535 | return; |
| 536 | } |
| 537 | |
| 538 | fcport->loop_id = loop_id; |
| 539 | |
| 540 | wwn = wwn_to_u64(fcport->port_name); |
| 541 | qlt_find_sess_invalidate_other(vha, wwn, |
| 542 | id, loop_id, &conflict_fcport); |
| 543 | |
| 544 | if (conflict_fcport) { |
| 545 | /* |
| 546 | * Another share fcport share the same loop_id & |
| 547 | * nport id. Conflict fcport needs to finish |
| 548 | * cleanup before this fcport can proceed to login. |
| 549 | */ |
| 550 | conflict_fcport->conflict = fcport; |
| 551 | fcport->login_pause = 1; |
| 552 | } |
| 553 | |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 554 | if (fcport->fc4f_nvme) |
| 555 | current_login_state = e->current_login_state >> 4; |
| 556 | else |
| 557 | current_login_state = e->current_login_state & 0xf; |
| 558 | |
| 559 | switch (current_login_state) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 560 | case DSC_LS_PRLI_COMP: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 561 | ql_dbg(ql_dbg_disc, vha, 0x20e4, |
| 562 | "%s %d %8phC post gpdb\n", |
| 563 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 564 | |
| 565 | if ((e->prli_svc_param_word_3[0] & BIT_4) == 0) |
| 566 | fcport->port_type = FCT_INITIATOR; |
| 567 | else |
| 568 | fcport->port_type = FCT_TARGET; |
| 569 | |
| 570 | data[0] = data[1] = 0; |
| 571 | qla2x00_post_async_adisc_work(vha, fcport, data); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 572 | break; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 573 | case DSC_LS_PORT_UNAVAIL: |
| 574 | default: |
| 575 | if (fcport->loop_id == FC_NO_LOOP_ID) { |
| 576 | qla2x00_find_new_loop_id(vha, fcport); |
| 577 | fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 578 | } |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 579 | ql_dbg(ql_dbg_disc, vha, 0x20e5, |
| 580 | "%s %d %8phC\n", |
| 581 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 582 | qla24xx_fcport_handle_login(vha, fcport); |
| 583 | break; |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | if (!found) { |
| 588 | /* fw has no record of this port */ |
Quinn Tran | 040036b | 2017-12-28 12:33:38 -0800 | [diff] [blame] | 589 | for (i = 0; i < n; i++) { |
| 590 | e = &vha->gnl.l[i]; |
| 591 | id.b.domain = e->port_id[0]; |
| 592 | id.b.area = e->port_id[1]; |
| 593 | id.b.al_pa = e->port_id[2]; |
| 594 | id.b.rsvd_1 = 0; |
| 595 | loop_id = le16_to_cpu(e->nport_handle); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 596 | |
Quinn Tran | 040036b | 2017-12-28 12:33:38 -0800 | [diff] [blame] | 597 | if (fcport->d_id.b24 == id.b24) { |
| 598 | conflict_fcport = |
| 599 | qla2x00_find_fcport_by_wwpn(vha, |
| 600 | e->port_name, 0); |
| 601 | ql_dbg(ql_dbg_disc, vha, 0x20e6, |
| 602 | "%s %d %8phC post del sess\n", |
| 603 | __func__, __LINE__, |
| 604 | conflict_fcport->port_name); |
| 605 | qlt_schedule_sess_for_deletion |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 606 | (conflict_fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 607 | } |
Quinn Tran | 040036b | 2017-12-28 12:33:38 -0800 | [diff] [blame] | 608 | |
| 609 | /* FW already picked this loop id for another fcport */ |
| 610 | if (fcport->loop_id == loop_id) |
| 611 | fcport->loop_id = FC_NO_LOOP_ID; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 612 | } |
| 613 | qla24xx_fcport_handle_login(vha, fcport); |
| 614 | } |
| 615 | } /* gnl_event */ |
| 616 | |
| 617 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 618 | qla24xx_async_gnl_sp_done(void *s, int res) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 619 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 620 | struct srb *sp = s; |
| 621 | struct scsi_qla_host *vha = sp->vha; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 622 | unsigned long flags; |
| 623 | struct fc_port *fcport = NULL, *tf; |
| 624 | u16 i, n = 0, loop_id; |
| 625 | struct event_arg ea; |
| 626 | struct get_name_list_extended *e; |
| 627 | u64 wwn; |
| 628 | struct list_head h; |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 629 | bool found = false; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 630 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 631 | ql_dbg(ql_dbg_disc, vha, 0x20e7, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 632 | "Async done-%s res %x mb[1]=%x mb[2]=%x \n", |
| 633 | sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1], |
| 634 | sp->u.iocb_cmd.u.mbx.in_mb[2]); |
| 635 | |
| 636 | memset(&ea, 0, sizeof(ea)); |
| 637 | ea.sp = sp; |
| 638 | ea.rc = res; |
| 639 | ea.event = FCME_GNL_DONE; |
| 640 | |
| 641 | if (sp->u.iocb_cmd.u.mbx.in_mb[1] >= |
| 642 | sizeof(struct get_name_list_extended)) { |
| 643 | n = sp->u.iocb_cmd.u.mbx.in_mb[1] / |
| 644 | sizeof(struct get_name_list_extended); |
| 645 | ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */ |
| 646 | } |
| 647 | |
| 648 | for (i = 0; i < n; i++) { |
| 649 | e = &vha->gnl.l[i]; |
| 650 | loop_id = le16_to_cpu(e->nport_handle); |
| 651 | /* mask out reserve bit */ |
| 652 | loop_id = (loop_id & 0x7fff); |
| 653 | set_bit(loop_id, vha->hw->loop_id_map); |
| 654 | wwn = wwn_to_u64(e->port_name); |
| 655 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 656 | ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20e8, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 657 | "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n", |
| 658 | __func__, (void *)&wwn, e->port_id[2], e->port_id[1], |
| 659 | e->port_id[0], e->current_login_state, e->last_login_state, |
| 660 | (loop_id & 0x7fff)); |
| 661 | } |
| 662 | |
| 663 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 664 | vha->gnl.sent = 0; |
| 665 | |
| 666 | INIT_LIST_HEAD(&h); |
| 667 | fcport = tf = NULL; |
| 668 | if (!list_empty(&vha->gnl.fcports)) |
| 669 | list_splice_init(&vha->gnl.fcports, &h); |
| 670 | |
| 671 | list_for_each_entry_safe(fcport, tf, &h, gnl_entry) { |
| 672 | list_del_init(&fcport->gnl_entry); |
Quinn Tran | 6d674927 | 2017-12-28 12:33:41 -0800 | [diff] [blame] | 673 | fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 674 | ea.fcport = fcport; |
| 675 | |
| 676 | qla2x00_fcport_event_handler(vha, &ea); |
| 677 | } |
| 678 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 679 | /* create new fcport if fw has knowledge of new sessions */ |
| 680 | for (i = 0; i < n; i++) { |
| 681 | port_id_t id; |
| 682 | u64 wwnn; |
| 683 | |
| 684 | e = &vha->gnl.l[i]; |
| 685 | wwn = wwn_to_u64(e->port_name); |
| 686 | |
| 687 | found = false; |
| 688 | list_for_each_entry_safe(fcport, tf, &vha->vp_fcports, list) { |
| 689 | if (!memcmp((u8 *)&wwn, fcport->port_name, |
| 690 | WWN_SIZE)) { |
| 691 | found = true; |
| 692 | break; |
| 693 | } |
| 694 | } |
| 695 | |
Quinn Tran | cf055fb | 2017-12-28 12:33:33 -0800 | [diff] [blame] | 696 | id.b.domain = e->port_id[2]; |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 697 | id.b.area = e->port_id[1]; |
Quinn Tran | cf055fb | 2017-12-28 12:33:33 -0800 | [diff] [blame] | 698 | id.b.al_pa = e->port_id[0]; |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 699 | id.b.rsvd_1 = 0; |
| 700 | |
| 701 | if (!found && wwn && !IS_SW_RESV_ADDR(id)) { |
| 702 | ql_dbg(ql_dbg_disc, vha, 0x2065, |
Quinn Tran | cf055fb | 2017-12-28 12:33:33 -0800 | [diff] [blame] | 703 | "%s %d %8phC %06x post new sess\n", |
| 704 | __func__, __LINE__, (u8 *)&wwn, id.b24); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 705 | wwnn = wwn_to_u64(e->node_name); |
| 706 | qla24xx_post_newsess_work(vha, &id, (u8 *)&wwn, |
| 707 | (u8 *)&wwnn, NULL, FC4_TYPE_UNKNOWN); |
| 708 | } |
| 709 | } |
| 710 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 711 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 712 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 713 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 717 | { |
| 718 | srb_t *sp; |
| 719 | struct srb_iocb *mbx; |
| 720 | int rval = QLA_FUNCTION_FAILED; |
| 721 | unsigned long flags; |
| 722 | u16 *mb; |
| 723 | |
Quinn Tran | 3dbec59 | 2017-12-28 12:33:40 -0800 | [diff] [blame] | 724 | if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT)) |
| 725 | return rval; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 726 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 727 | ql_dbg(ql_dbg_disc, vha, 0x20d9, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 728 | "Async-gnlist WWPN %8phC \n", fcport->port_name); |
| 729 | |
| 730 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 731 | fcport->disc_state = DSC_GNL; |
| 732 | fcport->last_rscn_gen = fcport->rscn_gen; |
| 733 | fcport->last_login_gen = fcport->login_gen; |
| 734 | |
| 735 | list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports); |
| 736 | if (vha->gnl.sent) { |
| 737 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Quinn Tran | 3dbec59 | 2017-12-28 12:33:40 -0800 | [diff] [blame] | 738 | return QLA_SUCCESS; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 739 | } |
| 740 | vha->gnl.sent = 1; |
| 741 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 742 | |
| 743 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 744 | if (!sp) |
| 745 | goto done; |
Quinn Tran | 3dbec59 | 2017-12-28 12:33:40 -0800 | [diff] [blame] | 746 | |
| 747 | fcport->flags |= FCF_ASYNC_SENT; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 748 | sp->type = SRB_MB_IOCB; |
| 749 | sp->name = "gnlist"; |
| 750 | sp->gen1 = fcport->rscn_gen; |
| 751 | sp->gen2 = fcport->login_gen; |
| 752 | |
| 753 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2); |
| 754 | |
| 755 | mb = sp->u.iocb_cmd.u.mbx.out_mb; |
| 756 | mb[0] = MBC_PORT_NODE_NAME_LIST; |
| 757 | mb[1] = BIT_2 | BIT_3; |
| 758 | mb[2] = MSW(vha->gnl.ldma); |
| 759 | mb[3] = LSW(vha->gnl.ldma); |
| 760 | mb[6] = MSW(MSD(vha->gnl.ldma)); |
| 761 | mb[7] = LSW(MSD(vha->gnl.ldma)); |
| 762 | mb[8] = vha->gnl.size; |
| 763 | mb[9] = vha->vp_idx; |
| 764 | |
| 765 | mbx = &sp->u.iocb_cmd; |
| 766 | mbx->timeout = qla2x00_async_iocb_timeout; |
| 767 | |
| 768 | sp->done = qla24xx_async_gnl_sp_done; |
| 769 | |
| 770 | rval = qla2x00_start_sp(sp); |
| 771 | if (rval != QLA_SUCCESS) |
| 772 | goto done_free_sp; |
| 773 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 774 | ql_dbg(ql_dbg_disc, vha, 0x20da, |
| 775 | "Async-%s - OUT WWPN %8phC hndl %x\n", |
| 776 | sp->name, fcport->port_name, sp->handle); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 777 | |
| 778 | return rval; |
| 779 | |
| 780 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 781 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 782 | fcport->flags &= ~FCF_ASYNC_SENT; |
Quinn Tran | 3dbec59 | 2017-12-28 12:33:40 -0800 | [diff] [blame] | 783 | done: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 784 | return rval; |
| 785 | } |
| 786 | |
| 787 | int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 788 | { |
| 789 | struct qla_work_evt *e; |
| 790 | |
| 791 | e = qla2x00_alloc_work(vha, QLA_EVT_GNL); |
| 792 | if (!e) |
| 793 | return QLA_FUNCTION_FAILED; |
| 794 | |
| 795 | e->u.fcport.fcport = fcport; |
Quinn Tran | 6d674927 | 2017-12-28 12:33:41 -0800 | [diff] [blame] | 796 | fcport->flags |= FCF_ASYNC_ACTIVE; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 797 | return qla2x00_post_work(vha, e); |
| 798 | } |
| 799 | |
| 800 | static |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 801 | void qla24xx_async_gpdb_sp_done(void *s, int res) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 802 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 803 | struct srb *sp = s; |
| 804 | struct scsi_qla_host *vha = sp->vha; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 805 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 806 | fc_port_t *fcport = sp->fcport; |
| 807 | u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 808 | struct event_arg ea; |
| 809 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 810 | ql_dbg(ql_dbg_disc, vha, 0x20db, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 811 | "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n", |
| 812 | sp->name, res, fcport->port_name, mb[1], mb[2]); |
| 813 | |
Quinn Tran | 6d674927 | 2017-12-28 12:33:41 -0800 | [diff] [blame] | 814 | fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 815 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 816 | memset(&ea, 0, sizeof(ea)); |
| 817 | ea.event = FCME_GPDB_DONE; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 818 | ea.fcport = fcport; |
| 819 | ea.sp = sp; |
| 820 | |
| 821 | qla2x00_fcport_event_handler(vha, &ea); |
| 822 | |
| 823 | dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in, |
| 824 | sp->u.iocb_cmd.u.mbx.in_dma); |
| 825 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 826 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 827 | } |
| 828 | |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 829 | static int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 830 | { |
| 831 | struct qla_work_evt *e; |
| 832 | |
| 833 | e = qla2x00_alloc_work(vha, QLA_EVT_PRLI); |
| 834 | if (!e) |
| 835 | return QLA_FUNCTION_FAILED; |
| 836 | |
| 837 | e->u.fcport.fcport = fcport; |
| 838 | |
| 839 | return qla2x00_post_work(vha, e); |
| 840 | } |
| 841 | |
| 842 | static void |
| 843 | qla2x00_async_prli_sp_done(void *ptr, int res) |
| 844 | { |
| 845 | srb_t *sp = ptr; |
| 846 | struct scsi_qla_host *vha = sp->vha; |
| 847 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
| 848 | struct event_arg ea; |
| 849 | |
| 850 | ql_dbg(ql_dbg_disc, vha, 0x2129, |
| 851 | "%s %8phC res %d \n", __func__, |
| 852 | sp->fcport->port_name, res); |
| 853 | |
| 854 | sp->fcport->flags &= ~FCF_ASYNC_SENT; |
| 855 | |
| 856 | if (!test_bit(UNLOADING, &vha->dpc_flags)) { |
| 857 | memset(&ea, 0, sizeof(ea)); |
| 858 | ea.event = FCME_PRLI_DONE; |
| 859 | ea.fcport = sp->fcport; |
| 860 | ea.data[0] = lio->u.logio.data[0]; |
| 861 | ea.data[1] = lio->u.logio.data[1]; |
| 862 | ea.iop[0] = lio->u.logio.iop[0]; |
| 863 | ea.iop[1] = lio->u.logio.iop[1]; |
| 864 | ea.sp = sp; |
| 865 | |
| 866 | qla2x00_fcport_event_handler(vha, &ea); |
| 867 | } |
| 868 | |
| 869 | sp->free(sp); |
| 870 | } |
| 871 | |
| 872 | int |
| 873 | qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 874 | { |
| 875 | srb_t *sp; |
| 876 | struct srb_iocb *lio; |
| 877 | int rval = QLA_FUNCTION_FAILED; |
| 878 | |
| 879 | if (!vha->flags.online) |
| 880 | return rval; |
| 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 rval; |
| 886 | |
| 887 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 888 | if (!sp) |
| 889 | return rval; |
| 890 | |
| 891 | fcport->flags |= FCF_ASYNC_SENT; |
| 892 | fcport->logout_completed = 0; |
| 893 | |
| 894 | sp->type = SRB_PRLI_CMD; |
| 895 | sp->name = "prli"; |
| 896 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 897 | |
| 898 | lio = &sp->u.iocb_cmd; |
| 899 | lio->timeout = qla2x00_async_iocb_timeout; |
| 900 | sp->done = qla2x00_async_prli_sp_done; |
| 901 | lio->u.logio.flags = 0; |
| 902 | |
| 903 | if (fcport->fc4f_nvme) |
| 904 | lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI; |
| 905 | |
| 906 | rval = qla2x00_start_sp(sp); |
| 907 | if (rval != QLA_SUCCESS) { |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 908 | fcport->flags |= FCF_LOGIN_NEEDED; |
| 909 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 910 | goto done_free_sp; |
| 911 | } |
| 912 | |
| 913 | ql_dbg(ql_dbg_disc, vha, 0x211b, |
| 914 | "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d.\n", |
| 915 | fcport->port_name, sp->handle, fcport->loop_id, |
| 916 | fcport->d_id.b24, fcport->login_retry); |
| 917 | |
| 918 | return rval; |
| 919 | |
| 920 | done_free_sp: |
| 921 | sp->free(sp); |
| 922 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 923 | return rval; |
| 924 | } |
| 925 | |
Quinn Tran | a07fc0a | 2017-08-23 15:05:21 -0700 | [diff] [blame] | 926 | int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 927 | { |
| 928 | struct qla_work_evt *e; |
| 929 | |
| 930 | e = qla2x00_alloc_work(vha, QLA_EVT_GPDB); |
| 931 | if (!e) |
| 932 | return QLA_FUNCTION_FAILED; |
| 933 | |
| 934 | e->u.fcport.fcport = fcport; |
| 935 | e->u.fcport.opt = opt; |
Quinn Tran | 6d674927 | 2017-12-28 12:33:41 -0800 | [diff] [blame] | 936 | fcport->flags |= FCF_ASYNC_ACTIVE; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 937 | return qla2x00_post_work(vha, e); |
| 938 | } |
| 939 | |
| 940 | int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt) |
| 941 | { |
| 942 | srb_t *sp; |
| 943 | struct srb_iocb *mbx; |
| 944 | int rval = QLA_FUNCTION_FAILED; |
| 945 | u16 *mb; |
| 946 | dma_addr_t pd_dma; |
| 947 | struct port_database_24xx *pd; |
| 948 | struct qla_hw_data *ha = vha->hw; |
| 949 | |
Quinn Tran | 3dbec59 | 2017-12-28 12:33:40 -0800 | [diff] [blame] | 950 | if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT)) |
| 951 | return rval; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 952 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 953 | fcport->disc_state = DSC_GPDB; |
| 954 | |
| 955 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 956 | if (!sp) |
| 957 | goto done; |
| 958 | |
Quinn Tran | 3dbec59 | 2017-12-28 12:33:40 -0800 | [diff] [blame] | 959 | fcport->flags |= FCF_ASYNC_SENT; |
Joe Carnuccio | e0824e6 | 2017-08-23 15:05:08 -0700 | [diff] [blame] | 960 | sp->type = SRB_MB_IOCB; |
| 961 | sp->name = "gpdb"; |
| 962 | sp->gen1 = fcport->rscn_gen; |
| 963 | sp->gen2 = fcport->login_gen; |
| 964 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 965 | |
Thomas Meyer | 08eb7f4 | 2017-09-21 08:15:26 +0200 | [diff] [blame] | 966 | pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 967 | if (pd == NULL) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 968 | ql_log(ql_log_warn, vha, 0xd043, |
| 969 | "Failed to allocate port database structure.\n"); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 970 | goto done_free_sp; |
| 971 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 972 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 973 | mb = sp->u.iocb_cmd.u.mbx.out_mb; |
| 974 | mb[0] = MBC_GET_PORT_DATABASE; |
| 975 | mb[1] = fcport->loop_id; |
| 976 | mb[2] = MSW(pd_dma); |
| 977 | mb[3] = LSW(pd_dma); |
| 978 | mb[6] = MSW(MSD(pd_dma)); |
| 979 | mb[7] = LSW(MSD(pd_dma)); |
| 980 | mb[9] = vha->vp_idx; |
| 981 | mb[10] = opt; |
| 982 | |
| 983 | mbx = &sp->u.iocb_cmd; |
| 984 | mbx->timeout = qla2x00_async_iocb_timeout; |
| 985 | mbx->u.mbx.in = (void *)pd; |
| 986 | mbx->u.mbx.in_dma = pd_dma; |
| 987 | |
| 988 | sp->done = qla24xx_async_gpdb_sp_done; |
| 989 | |
| 990 | rval = qla2x00_start_sp(sp); |
| 991 | if (rval != QLA_SUCCESS) |
| 992 | goto done_free_sp; |
| 993 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 994 | ql_dbg(ql_dbg_disc, vha, 0x20dc, |
| 995 | "Async-%s %8phC hndl %x opt %x\n", |
| 996 | sp->name, fcport->port_name, sp->handle, opt); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 997 | |
| 998 | return rval; |
| 999 | |
| 1000 | done_free_sp: |
| 1001 | if (pd) |
| 1002 | dma_pool_free(ha->s_dma_pool, pd, pd_dma); |
| 1003 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1004 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1005 | fcport->flags &= ~FCF_ASYNC_SENT; |
Quinn Tran | 3dbec59 | 2017-12-28 12:33:40 -0800 | [diff] [blame] | 1006 | done: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1007 | qla24xx_post_gpdb_work(vha, fcport, opt); |
| 1008 | return rval; |
| 1009 | } |
| 1010 | |
| 1011 | static |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1012 | void __qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1013 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1014 | unsigned long flags; |
| 1015 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1016 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Quinn Tran | f13515a | 2017-12-28 12:33:15 -0800 | [diff] [blame] | 1017 | ea->fcport->login_gen++; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1018 | ea->fcport->deleted = 0; |
| 1019 | ea->fcport->logout_on_delete = 1; |
| 1020 | |
| 1021 | if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) { |
| 1022 | vha->fcport_count++; |
| 1023 | ea->fcport->login_succ = 1; |
| 1024 | |
| 1025 | if (!IS_IIDMA_CAPABLE(vha->hw) || |
| 1026 | !vha->hw->flags.gpsc_supported) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1027 | ql_dbg(ql_dbg_disc, vha, 0x20d6, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1028 | "%s %d %8phC post upd_fcport fcp_cnt %d\n", |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1029 | __func__, __LINE__, ea->fcport->port_name, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1030 | vha->fcport_count); |
| 1031 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1032 | qla24xx_post_upd_fcport_work(vha, ea->fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1033 | } else { |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1034 | if (ea->fcport->id_changed) { |
| 1035 | ea->fcport->id_changed = 0; |
| 1036 | ql_dbg(ql_dbg_disc, vha, 0x20d7, |
| 1037 | "%s %d %8phC post gfpnid fcp_cnt %d\n", |
| 1038 | __func__, __LINE__, ea->fcport->port_name, |
| 1039 | vha->fcport_count); |
| 1040 | qla24xx_post_gfpnid_work(vha, ea->fcport); |
| 1041 | } else { |
| 1042 | ql_dbg(ql_dbg_disc, vha, 0x20d7, |
| 1043 | "%s %d %8phC post gpsc fcp_cnt %d\n", |
| 1044 | __func__, __LINE__, ea->fcport->port_name, |
| 1045 | vha->fcport_count); |
| 1046 | qla24xx_post_gpsc_work(vha, ea->fcport); |
| 1047 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1048 | } |
Quinn Tran | 414d9ff | 2017-12-04 14:45:03 -0800 | [diff] [blame] | 1049 | } else if (ea->fcport->login_succ) { |
| 1050 | /* |
| 1051 | * We have an existing session. A late RSCN delivery |
| 1052 | * must have triggered the session to be re-validate. |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1053 | * Session is still valid. |
Quinn Tran | 414d9ff | 2017-12-04 14:45:03 -0800 | [diff] [blame] | 1054 | */ |
Quinn Tran | 5ef696a | 2017-12-04 14:45:05 -0800 | [diff] [blame] | 1055 | ql_dbg(ql_dbg_disc, vha, 0x20d6, |
| 1056 | "%s %d %8phC session revalidate success\n", |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1057 | __func__, __LINE__, ea->fcport->port_name); |
himanshu.madhani@cavium.com | 8a7eac2 | 2018-01-15 20:46:50 -0800 | [diff] [blame] | 1058 | ea->fcport->disc_state = DSC_LOGIN_COMPLETE; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1059 | } |
| 1060 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1061 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1062 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1063 | static |
| 1064 | void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea) |
| 1065 | { |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1066 | fc_port_t *fcport = ea->fcport; |
| 1067 | struct port_database_24xx *pd; |
| 1068 | struct srb *sp = ea->sp; |
| 1069 | |
| 1070 | pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in; |
| 1071 | |
| 1072 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 1073 | |
| 1074 | ql_dbg(ql_dbg_disc, vha, 0x20d2, |
Quinn Tran | f352eeb | 2017-12-28 12:33:35 -0800 | [diff] [blame] | 1075 | "%s %8phC DS %d LS %d rc %d\n", __func__, fcport->port_name, |
| 1076 | fcport->disc_state, pd->current_login_state, ea->rc); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1077 | |
| 1078 | if (fcport->disc_state == DSC_DELETE_PEND) |
| 1079 | return; |
| 1080 | |
| 1081 | switch (pd->current_login_state) { |
| 1082 | case PDS_PRLI_COMPLETE: |
| 1083 | __qla24xx_parse_gpdb(vha, fcport, pd); |
| 1084 | break; |
| 1085 | case PDS_PLOGI_PENDING: |
| 1086 | case PDS_PLOGI_COMPLETE: |
| 1087 | case PDS_PRLI_PENDING: |
| 1088 | case PDS_PRLI2_PENDING: |
| 1089 | ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC relogin needed\n", |
| 1090 | __func__, __LINE__, fcport->port_name); |
| 1091 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1092 | return; |
| 1093 | case PDS_LOGO_PENDING: |
| 1094 | case PDS_PORT_UNAVAILABLE: |
| 1095 | default: |
| 1096 | ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n", |
| 1097 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 1098 | qlt_schedule_sess_for_deletion(fcport); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1099 | return; |
| 1100 | } |
| 1101 | __qla24xx_handle_gpdb_event(vha, ea); |
| 1102 | } /* gpdb event */ |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1103 | |
| 1104 | static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 1105 | { |
| 1106 | u8 login = 0; |
Quinn Tran | 040036b | 2017-12-28 12:33:38 -0800 | [diff] [blame] | 1107 | int rc; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1108 | |
| 1109 | if (qla_tgt_mode_enabled(vha)) |
| 1110 | return; |
| 1111 | |
| 1112 | if (qla_dual_mode_enabled(vha)) { |
| 1113 | if (N2N_TOPO(vha->hw)) { |
| 1114 | u64 mywwn, wwn; |
| 1115 | |
| 1116 | mywwn = wwn_to_u64(vha->port_name); |
| 1117 | wwn = wwn_to_u64(fcport->port_name); |
| 1118 | if (mywwn > wwn) |
| 1119 | login = 1; |
| 1120 | else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP) |
| 1121 | && time_after_eq(jiffies, |
| 1122 | fcport->plogi_nack_done_deadline)) |
| 1123 | login = 1; |
| 1124 | } else { |
| 1125 | login = 1; |
| 1126 | } |
| 1127 | } else { |
| 1128 | /* initiator mode */ |
| 1129 | login = 1; |
| 1130 | } |
| 1131 | |
| 1132 | if (login) { |
Quinn Tran | 040036b | 2017-12-28 12:33:38 -0800 | [diff] [blame] | 1133 | if (fcport->loop_id == FC_NO_LOOP_ID) { |
| 1134 | fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 1135 | rc = qla2x00_find_new_loop_id(vha, fcport); |
| 1136 | if (rc) { |
| 1137 | ql_dbg(ql_dbg_disc, vha, 0x20e6, |
| 1138 | "%s %d %8phC post del sess - out of loopid\n", |
| 1139 | __func__, __LINE__, fcport->port_name); |
| 1140 | fcport->scan_state = 0; |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 1141 | qlt_schedule_sess_for_deletion(fcport); |
Quinn Tran | 040036b | 2017-12-28 12:33:38 -0800 | [diff] [blame] | 1142 | return; |
| 1143 | } |
| 1144 | } |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1145 | ql_dbg(ql_dbg_disc, vha, 0x20bf, |
| 1146 | "%s %d %8phC post login\n", |
| 1147 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1148 | qla2x00_post_async_login_work(vha, fcport, NULL); |
| 1149 | } |
| 1150 | } |
| 1151 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1152 | int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 1153 | { |
Quinn Tran | f13515a | 2017-12-28 12:33:15 -0800 | [diff] [blame] | 1154 | u16 data[2]; |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1155 | u64 wwn; |
| 1156 | |
| 1157 | ql_dbg(ql_dbg_disc, vha, 0x20d8, |
Quinn Tran | f352eeb | 2017-12-28 12:33:35 -0800 | [diff] [blame] | 1158 | "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d retry %d lid %d scan %d\n", |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1159 | __func__, fcport->port_name, fcport->disc_state, |
| 1160 | fcport->fw_login_state, fcport->login_pause, fcport->flags, |
| 1161 | fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen, |
Quinn Tran | f352eeb | 2017-12-28 12:33:35 -0800 | [diff] [blame] | 1162 | fcport->login_gen, fcport->login_retry, |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1163 | fcport->loop_id, fcport->scan_state); |
| 1164 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1165 | if (fcport->login_retry == 0) |
| 1166 | return 0; |
| 1167 | |
| 1168 | if (fcport->scan_state != QLA_FCPORT_FOUND) |
| 1169 | return 0; |
| 1170 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1171 | if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1172 | (fcport->fw_login_state == DSC_LS_PRLI_PEND)) |
| 1173 | return 0; |
| 1174 | |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame] | 1175 | if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) { |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1176 | if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) { |
| 1177 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame] | 1178 | return 0; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1179 | } |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame] | 1180 | } |
| 1181 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1182 | /* for pure Target Mode. Login will not be initiated */ |
| 1183 | if (vha->host->active_mode == MODE_TARGET) |
| 1184 | return 0; |
| 1185 | |
| 1186 | if (fcport->flags & FCF_ASYNC_SENT) { |
| 1187 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1188 | return 0; |
| 1189 | } |
| 1190 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1191 | fcport->login_retry--; |
| 1192 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1193 | switch (fcport->disc_state) { |
| 1194 | case DSC_DELETED: |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1195 | wwn = wwn_to_u64(fcport->node_name); |
| 1196 | if (wwn == 0) { |
| 1197 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 1198 | "%s %d %8phC post GNNID\n", |
| 1199 | __func__, __LINE__, fcport->port_name); |
| 1200 | qla24xx_post_gnnid_work(vha, fcport); |
| 1201 | } else if (fcport->loop_id == FC_NO_LOOP_ID) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1202 | ql_dbg(ql_dbg_disc, vha, 0x20bd, |
| 1203 | "%s %d %8phC post gnl\n", |
| 1204 | __func__, __LINE__, fcport->port_name); |
Giridhar Malavali | 5d3300a | 2017-12-04 14:45:13 -0800 | [diff] [blame] | 1205 | qla24xx_post_gnl_work(vha, fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1206 | } else { |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1207 | qla_chk_n2n_b4_login(vha, fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1208 | } |
| 1209 | break; |
| 1210 | |
| 1211 | case DSC_GNL: |
| 1212 | if (fcport->login_pause) { |
| 1213 | fcport->last_rscn_gen = fcport->rscn_gen; |
| 1214 | fcport->last_login_gen = fcport->login_gen; |
| 1215 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1216 | break; |
| 1217 | } |
| 1218 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1219 | qla_chk_n2n_b4_login(vha, fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1220 | break; |
| 1221 | |
| 1222 | case DSC_LOGIN_FAILED: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1223 | ql_dbg(ql_dbg_disc, vha, 0x20d0, |
| 1224 | "%s %d %8phC post gidpn\n", |
| 1225 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1226 | if (N2N_TOPO(vha->hw)) |
| 1227 | qla_chk_n2n_b4_login(vha, fcport); |
| 1228 | else |
| 1229 | qla24xx_post_gidpn_work(vha, fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1230 | break; |
| 1231 | |
| 1232 | case DSC_LOGIN_COMPLETE: |
| 1233 | /* recheck login state */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1234 | ql_dbg(ql_dbg_disc, vha, 0x20d1, |
Quinn Tran | f13515a | 2017-12-28 12:33:15 -0800 | [diff] [blame] | 1235 | "%s %d %8phC post adisc\n", |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1236 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | f13515a | 2017-12-28 12:33:15 -0800 | [diff] [blame] | 1237 | data[0] = data[1] = 0; |
| 1238 | qla2x00_post_async_adisc_work(vha, fcport, data); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1239 | break; |
| 1240 | |
| 1241 | default: |
| 1242 | break; |
| 1243 | } |
| 1244 | |
| 1245 | return 0; |
| 1246 | } |
| 1247 | |
| 1248 | static |
| 1249 | void qla24xx_handle_rscn_event(fc_port_t *fcport, struct event_arg *ea) |
| 1250 | { |
| 1251 | fcport->rscn_gen++; |
| 1252 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1253 | ql_dbg(ql_dbg_disc, fcport->vha, 0x210c, |
| 1254 | "%s %8phC DS %d LS %d\n", |
| 1255 | __func__, fcport->port_name, fcport->disc_state, |
| 1256 | fcport->fw_login_state); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1257 | |
| 1258 | if (fcport->flags & FCF_ASYNC_SENT) |
| 1259 | return; |
| 1260 | |
| 1261 | switch (fcport->disc_state) { |
| 1262 | case DSC_DELETED: |
| 1263 | case DSC_LOGIN_COMPLETE: |
Quinn Tran | 5ef696a | 2017-12-04 14:45:05 -0800 | [diff] [blame] | 1264 | qla24xx_post_gpnid_work(fcport->vha, &ea->id); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1265 | break; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1266 | default: |
| 1267 | break; |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id, |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1272 | u8 *port_name, u8 *node_name, void *pla, u8 fc4_type) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1273 | { |
| 1274 | struct qla_work_evt *e; |
| 1275 | e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS); |
| 1276 | if (!e) |
| 1277 | return QLA_FUNCTION_FAILED; |
| 1278 | |
| 1279 | e->u.new_sess.id = *id; |
| 1280 | e->u.new_sess.pla = pla; |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1281 | e->u.new_sess.fc4_type = fc4_type; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1282 | memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1283 | if (node_name) |
| 1284 | memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1285 | |
| 1286 | return qla2x00_post_work(vha, e); |
| 1287 | } |
| 1288 | |
| 1289 | static |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1290 | void qla24xx_handle_relogin_event(scsi_qla_host_t *vha, |
| 1291 | struct event_arg *ea) |
| 1292 | { |
| 1293 | fc_port_t *fcport = ea->fcport; |
| 1294 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1295 | ql_dbg(ql_dbg_disc, vha, 0x2102, |
| 1296 | "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n", |
| 1297 | __func__, fcport->port_name, fcport->disc_state, |
| 1298 | fcport->fw_login_state, fcport->login_pause, |
| 1299 | fcport->deleted, fcport->conflict, |
| 1300 | fcport->last_rscn_gen, fcport->rscn_gen, |
| 1301 | fcport->last_login_gen, fcport->login_gen, |
| 1302 | fcport->flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1303 | |
| 1304 | if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1305 | (fcport->fw_login_state == DSC_LS_PRLI_PEND)) |
| 1306 | return; |
| 1307 | |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame] | 1308 | if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) { |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1309 | if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) { |
| 1310 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame] | 1311 | return; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 1312 | } |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame] | 1313 | } |
| 1314 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1315 | if (fcport->flags & FCF_ASYNC_SENT) { |
| 1316 | fcport->login_retry++; |
| 1317 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1318 | return; |
| 1319 | } |
| 1320 | |
| 1321 | if (fcport->disc_state == DSC_DELETE_PEND) { |
| 1322 | fcport->login_retry++; |
| 1323 | return; |
| 1324 | } |
| 1325 | |
| 1326 | if (fcport->last_rscn_gen != fcport->rscn_gen) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1327 | ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gidpn\n", |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1328 | __func__, __LINE__, fcport->port_name); |
| 1329 | |
Giridhar Malavali | 5d3300a | 2017-12-04 14:45:13 -0800 | [diff] [blame] | 1330 | qla24xx_post_gidpn_work(vha, fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1331 | return; |
| 1332 | } |
| 1333 | |
| 1334 | qla24xx_fcport_handle_login(vha, fcport); |
| 1335 | } |
| 1336 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1337 | 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] | 1338 | { |
Quinn Tran | f352eeb | 2017-12-28 12:33:35 -0800 | [diff] [blame] | 1339 | fc_port_t *f, *tf; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1340 | uint32_t id = 0, mask, rid; |
Quinn Tran | f352eeb | 2017-12-28 12:33:35 -0800 | [diff] [blame] | 1341 | unsigned long flags; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1342 | |
| 1343 | switch (ea->event) { |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 1344 | case FCME_RSCN: |
| 1345 | case FCME_GIDPN_DONE: |
| 1346 | case FCME_GPSC_DONE: |
| 1347 | case FCME_GPNID_DONE: |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1348 | case FCME_GNNID_DONE: |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 1349 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) || |
| 1350 | test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags)) |
| 1351 | return; |
| 1352 | break; |
| 1353 | default: |
| 1354 | break; |
| 1355 | } |
| 1356 | |
| 1357 | switch (ea->event) { |
| 1358 | case FCME_RELOGIN: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1359 | if (test_bit(UNLOADING, &vha->dpc_flags)) |
| 1360 | return; |
| 1361 | |
| 1362 | qla24xx_handle_relogin_event(vha, ea); |
| 1363 | break; |
| 1364 | case FCME_RSCN: |
| 1365 | if (test_bit(UNLOADING, &vha->dpc_flags)) |
| 1366 | return; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1367 | switch (ea->id.b.rsvd_1) { |
| 1368 | case RSCN_PORT_ADDR: |
Quinn Tran | f352eeb | 2017-12-28 12:33:35 -0800 | [diff] [blame] | 1369 | spin_lock_irqsave(&vha->work_lock, flags); |
| 1370 | if (vha->scan.scan_flags == 0) { |
| 1371 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 1372 | "%s: schedule\n", __func__); |
| 1373 | vha->scan.scan_flags |= SF_QUEUED; |
| 1374 | schedule_delayed_work(&vha->scan.scan_work, 5); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1375 | } |
Quinn Tran | f352eeb | 2017-12-28 12:33:35 -0800 | [diff] [blame] | 1376 | spin_unlock_irqrestore(&vha->work_lock, flags); |
| 1377 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1378 | break; |
| 1379 | case RSCN_AREA_ADDR: |
| 1380 | case RSCN_DOM_ADDR: |
| 1381 | if (ea->id.b.rsvd_1 == RSCN_AREA_ADDR) { |
| 1382 | mask = 0xffff00; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1383 | ql_dbg(ql_dbg_async, vha, 0x5044, |
| 1384 | "RSCN: Area 0x%06x was affected\n", |
| 1385 | ea->id.b24); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1386 | } else { |
| 1387 | mask = 0xff0000; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1388 | ql_dbg(ql_dbg_async, vha, 0x507a, |
| 1389 | "RSCN: Domain 0x%06x was affected\n", |
| 1390 | ea->id.b24); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1391 | } |
| 1392 | |
| 1393 | rid = ea->id.b24 & mask; |
| 1394 | list_for_each_entry_safe(f, tf, &vha->vp_fcports, |
| 1395 | list) { |
| 1396 | id = f->d_id.b24 & mask; |
| 1397 | if (rid == id) { |
| 1398 | ea->fcport = f; |
| 1399 | qla24xx_handle_rscn_event(f, ea); |
| 1400 | } |
| 1401 | } |
| 1402 | break; |
| 1403 | case RSCN_FAB_ADDR: |
| 1404 | default: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1405 | ql_log(ql_log_warn, vha, 0xd045, |
| 1406 | "RSCN: Fabric was affected. Addr format %d\n", |
| 1407 | ea->id.b.rsvd_1); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1408 | qla2x00_mark_all_devices_lost(vha, 1); |
| 1409 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 1410 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1411 | } |
| 1412 | break; |
| 1413 | case FCME_GIDPN_DONE: |
| 1414 | qla24xx_handle_gidpn_event(vha, ea); |
| 1415 | break; |
| 1416 | case FCME_GNL_DONE: |
| 1417 | qla24xx_handle_gnl_done_event(vha, ea); |
| 1418 | break; |
| 1419 | case FCME_GPSC_DONE: |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1420 | qla24xx_handle_gpsc_event(vha, ea); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1421 | break; |
| 1422 | case FCME_PLOGI_DONE: /* Initiator side sent LLIOCB */ |
| 1423 | qla24xx_handle_plogi_done_event(vha, ea); |
| 1424 | break; |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 1425 | case FCME_PRLI_DONE: |
| 1426 | qla24xx_handle_prli_done_event(vha, ea); |
| 1427 | break; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1428 | case FCME_GPDB_DONE: |
| 1429 | qla24xx_handle_gpdb_event(vha, ea); |
| 1430 | break; |
| 1431 | case FCME_GPNID_DONE: |
| 1432 | qla24xx_handle_gpnid_event(vha, ea); |
| 1433 | break; |
Duane Grigsby | d3bae93 | 2017-06-21 13:48:44 -0700 | [diff] [blame] | 1434 | case FCME_GFFID_DONE: |
| 1435 | qla24xx_handle_gffid_event(vha, ea); |
| 1436 | break; |
Quinn Tran | f13515a | 2017-12-28 12:33:15 -0800 | [diff] [blame] | 1437 | case FCME_ADISC_DONE: |
| 1438 | qla24xx_handle_adisc_event(vha, ea); |
| 1439 | break; |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1440 | case FCME_GNNID_DONE: |
| 1441 | qla24xx_handle_gnnid_event(vha, ea); |
| 1442 | break; |
| 1443 | case FCME_GFPNID_DONE: |
| 1444 | qla24xx_handle_gfpnid_event(vha, ea); |
| 1445 | break; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1446 | default: |
| 1447 | BUG_ON(1); |
| 1448 | break; |
| 1449 | } |
| 1450 | } |
| 1451 | |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1452 | static void |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1453 | qla2x00_tmf_iocb_timeout(void *data) |
| 1454 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1455 | srb_t *sp = data; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1456 | struct srb_iocb *tmf = &sp->u.iocb_cmd; |
| 1457 | |
| 1458 | tmf->u.tmf.comp_status = CS_TIMEOUT; |
| 1459 | complete(&tmf->u.tmf.comp); |
| 1460 | } |
| 1461 | |
| 1462 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1463 | qla2x00_tmf_sp_done(void *ptr, int res) |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1464 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1465 | srb_t *sp = ptr; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1466 | struct srb_iocb *tmf = &sp->u.iocb_cmd; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1467 | |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1468 | complete(&tmf->u.tmf.comp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1469 | } |
| 1470 | |
| 1471 | int |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1472 | 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] | 1473 | uint32_t tag) |
| 1474 | { |
| 1475 | struct scsi_qla_host *vha = fcport->vha; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1476 | struct srb_iocb *tm_iocb; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1477 | srb_t *sp; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1478 | int rval = QLA_FUNCTION_FAILED; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1479 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1480 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1481 | if (!sp) |
| 1482 | goto done; |
| 1483 | |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1484 | tm_iocb = &sp->u.iocb_cmd; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1485 | sp->type = SRB_TM_CMD; |
| 1486 | sp->name = "tmf"; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1487 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)); |
| 1488 | tm_iocb->u.tmf.flags = flags; |
| 1489 | tm_iocb->u.tmf.lun = lun; |
| 1490 | tm_iocb->u.tmf.data = tag; |
| 1491 | sp->done = qla2x00_tmf_sp_done; |
| 1492 | tm_iocb->timeout = qla2x00_tmf_iocb_timeout; |
| 1493 | init_completion(&tm_iocb->u.tmf.comp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1494 | |
| 1495 | rval = qla2x00_start_sp(sp); |
| 1496 | if (rval != QLA_SUCCESS) |
| 1497 | goto done_free_sp; |
| 1498 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1499 | ql_dbg(ql_dbg_taskm, vha, 0x802f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1500 | "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n", |
| 1501 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
| 1502 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1503 | |
| 1504 | wait_for_completion(&tm_iocb->u.tmf.comp); |
| 1505 | |
| 1506 | rval = tm_iocb->u.tmf.comp_status == CS_COMPLETE ? |
| 1507 | QLA_SUCCESS : QLA_FUNCTION_FAILED; |
| 1508 | |
| 1509 | if ((rval != QLA_SUCCESS) || tm_iocb->u.tmf.data) { |
| 1510 | ql_dbg(ql_dbg_taskm, vha, 0x8030, |
| 1511 | "TM IOCB failed (%x).\n", rval); |
| 1512 | } |
| 1513 | |
| 1514 | if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) { |
| 1515 | flags = tm_iocb->u.tmf.flags; |
| 1516 | lun = (uint16_t)tm_iocb->u.tmf.lun; |
| 1517 | |
| 1518 | /* Issue Marker IOCB */ |
| 1519 | qla2x00_marker(vha, vha->hw->req_q_map[0], |
| 1520 | vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun, |
| 1521 | flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID); |
| 1522 | } |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1523 | |
| 1524 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1525 | sp->free(sp); |
Quinn Tran | 6d674927 | 2017-12-28 12:33:41 -0800 | [diff] [blame] | 1526 | sp->fcport->flags &= ~FCF_ASYNC_SENT; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1527 | done: |
| 1528 | return rval; |
| 1529 | } |
| 1530 | |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1531 | static void |
| 1532 | qla24xx_abort_iocb_timeout(void *data) |
| 1533 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1534 | srb_t *sp = data; |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1535 | struct srb_iocb *abt = &sp->u.iocb_cmd; |
| 1536 | |
| 1537 | abt->u.abt.comp_status = CS_TIMEOUT; |
| 1538 | complete(&abt->u.abt.comp); |
| 1539 | } |
| 1540 | |
| 1541 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1542 | qla24xx_abort_sp_done(void *ptr, int res) |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1543 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1544 | srb_t *sp = ptr; |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1545 | struct srb_iocb *abt = &sp->u.iocb_cmd; |
| 1546 | |
| 1547 | complete(&abt->u.abt.comp); |
| 1548 | } |
| 1549 | |
Quinn Tran | 15f30a5 | 2017-03-15 09:48:52 -0700 | [diff] [blame] | 1550 | int |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1551 | qla24xx_async_abort_cmd(srb_t *cmd_sp) |
| 1552 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1553 | scsi_qla_host_t *vha = cmd_sp->vha; |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1554 | fc_port_t *fcport = cmd_sp->fcport; |
| 1555 | struct srb_iocb *abt_iocb; |
| 1556 | srb_t *sp; |
| 1557 | int rval = QLA_FUNCTION_FAILED; |
| 1558 | |
| 1559 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 1560 | if (!sp) |
| 1561 | goto done; |
| 1562 | |
| 1563 | abt_iocb = &sp->u.iocb_cmd; |
| 1564 | sp->type = SRB_ABT_CMD; |
| 1565 | sp->name = "abort"; |
| 1566 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)); |
| 1567 | abt_iocb->u.abt.cmd_hndl = cmd_sp->handle; |
Darren Trapp | b027a5a | 2018-01-15 20:46:51 -0800 | [diff] [blame] | 1568 | |
| 1569 | if (vha->flags.qpairs_available && cmd_sp->qpair) |
| 1570 | abt_iocb->u.abt.req_que_no = |
| 1571 | cpu_to_le16(cmd_sp->qpair->req->id); |
| 1572 | else |
| 1573 | abt_iocb->u.abt.req_que_no = cpu_to_le16(vha->req->id); |
| 1574 | |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1575 | sp->done = qla24xx_abort_sp_done; |
| 1576 | abt_iocb->timeout = qla24xx_abort_iocb_timeout; |
| 1577 | init_completion(&abt_iocb->u.abt.comp); |
| 1578 | |
| 1579 | rval = qla2x00_start_sp(sp); |
| 1580 | if (rval != QLA_SUCCESS) |
| 1581 | goto done_free_sp; |
| 1582 | |
| 1583 | ql_dbg(ql_dbg_async, vha, 0x507c, |
| 1584 | "Abort command issued - hdl=%x, target_id=%x\n", |
| 1585 | cmd_sp->handle, fcport->tgt_id); |
| 1586 | |
| 1587 | wait_for_completion(&abt_iocb->u.abt.comp); |
| 1588 | |
| 1589 | rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ? |
| 1590 | QLA_SUCCESS : QLA_FUNCTION_FAILED; |
| 1591 | |
| 1592 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1593 | sp->free(sp); |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1594 | done: |
| 1595 | return rval; |
| 1596 | } |
| 1597 | |
| 1598 | int |
| 1599 | qla24xx_async_abort_command(srb_t *sp) |
| 1600 | { |
| 1601 | unsigned long flags = 0; |
| 1602 | |
| 1603 | uint32_t handle; |
| 1604 | fc_port_t *fcport = sp->fcport; |
| 1605 | struct scsi_qla_host *vha = fcport->vha; |
| 1606 | struct qla_hw_data *ha = vha->hw; |
| 1607 | struct req_que *req = vha->req; |
| 1608 | |
Darren Trapp | b027a5a | 2018-01-15 20:46:51 -0800 | [diff] [blame] | 1609 | if (vha->flags.qpairs_available && sp->qpair) |
| 1610 | req = sp->qpair->req; |
| 1611 | |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1612 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1613 | for (handle = 1; handle < req->num_outstanding_cmds; handle++) { |
| 1614 | if (req->outstanding_cmds[handle] == sp) |
| 1615 | break; |
| 1616 | } |
| 1617 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1618 | if (handle == req->num_outstanding_cmds) { |
| 1619 | /* Command not found. */ |
| 1620 | return QLA_FUNCTION_FAILED; |
| 1621 | } |
| 1622 | if (sp->type == SRB_FXIOCB_DCMD) |
| 1623 | return qlafx00_fx_disc(vha, &vha->hw->mr.fcport, |
| 1624 | FXDISC_ABORT_IOCTL); |
| 1625 | |
| 1626 | return qla24xx_async_abort_cmd(sp); |
| 1627 | } |
| 1628 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1629 | static void |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 1630 | qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea) |
| 1631 | { |
| 1632 | switch (ea->data[0]) { |
| 1633 | case MBS_COMMAND_COMPLETE: |
| 1634 | ql_dbg(ql_dbg_disc, vha, 0x2118, |
| 1635 | "%s %d %8phC post gpdb\n", |
| 1636 | __func__, __LINE__, ea->fcport->port_name); |
| 1637 | |
| 1638 | ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset; |
| 1639 | ea->fcport->logout_on_delete = 1; |
| 1640 | qla24xx_post_gpdb_work(vha, ea->fcport, 0); |
| 1641 | break; |
| 1642 | default: |
Duane Grigsby | edd05de | 2017-10-13 09:34:06 -0700 | [diff] [blame] | 1643 | if (ea->fcport->n2n_flag) { |
| 1644 | ql_dbg(ql_dbg_disc, vha, 0x2118, |
| 1645 | "%s %d %8phC post fc4 prli\n", |
| 1646 | __func__, __LINE__, ea->fcport->port_name); |
| 1647 | ea->fcport->fc4f_nvme = 0; |
| 1648 | ea->fcport->n2n_flag = 0; |
| 1649 | qla24xx_post_prli_work(vha, ea->fcport); |
| 1650 | } |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 1651 | ql_dbg(ql_dbg_disc, vha, 0x2119, |
| 1652 | "%s %d %8phC unhandle event of %x\n", |
| 1653 | __func__, __LINE__, ea->fcport->port_name, ea->data[0]); |
| 1654 | break; |
| 1655 | } |
| 1656 | } |
| 1657 | |
| 1658 | static void |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1659 | 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] | 1660 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1661 | port_id_t cid; /* conflict Nport id */ |
Quinn Tran | a084fd6 | 2017-12-04 14:45:00 -0800 | [diff] [blame] | 1662 | u16 lid; |
| 1663 | struct fc_port *conflict_fcport; |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame] | 1664 | unsigned long flags; |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1665 | struct fc_port *fcport = ea->fcport; |
| 1666 | |
Quinn Tran | f352eeb | 2017-12-28 12:33:35 -0800 | [diff] [blame] | 1667 | ql_dbg(ql_dbg_disc, vha, 0xffff, |
| 1668 | "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n", |
| 1669 | __func__, fcport->port_name, fcport->disc_state, |
| 1670 | fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen, |
| 1671 | ea->sp->gen2, fcport->rscn_gen|ea->sp->gen1, |
| 1672 | ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]); |
| 1673 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1674 | if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) || |
| 1675 | (fcport->fw_login_state == DSC_LS_PRLI_PEND)) { |
| 1676 | ql_dbg(ql_dbg_disc, vha, 0x20ea, |
| 1677 | "%s %d %8phC Remote is trying to login\n", |
| 1678 | __func__, __LINE__, fcport->port_name); |
| 1679 | return; |
| 1680 | } |
| 1681 | |
| 1682 | if (fcport->disc_state == DSC_DELETE_PEND) |
| 1683 | return; |
| 1684 | |
| 1685 | if (ea->sp->gen2 != fcport->login_gen) { |
| 1686 | /* target side must have changed it. */ |
| 1687 | ql_dbg(ql_dbg_disc, vha, 0x20d3, |
Quinn Tran | f352eeb | 2017-12-28 12:33:35 -0800 | [diff] [blame] | 1688 | "%s %8phC generation changed\n", |
| 1689 | __func__, fcport->port_name); |
| 1690 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 1691 | return; |
| 1692 | } else if (ea->sp->gen1 != fcport->rscn_gen) { |
| 1693 | ql_dbg(ql_dbg_disc, vha, 0x20d4, "%s %d %8phC post gidpn\n", |
| 1694 | __func__, __LINE__, fcport->port_name); |
| 1695 | qla24xx_post_gidpn_work(vha, fcport); |
| 1696 | return; |
| 1697 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1698 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1699 | switch (ea->data[0]) { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1700 | case MBS_COMMAND_COMPLETE: |
Andrew Vasquez | a4f92a3 | 2011-03-30 11:46:31 -0700 | [diff] [blame] | 1701 | /* |
| 1702 | * Driver must validate login state - If PRLI not complete, |
| 1703 | * force a relogin attempt via implicit LOGO, PLOGI, and PRLI |
| 1704 | * requests. |
| 1705 | */ |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 1706 | if (ea->fcport->fc4f_nvme) { |
| 1707 | ql_dbg(ql_dbg_disc, vha, 0x2117, |
| 1708 | "%s %d %8phC post prli\n", |
| 1709 | __func__, __LINE__, ea->fcport->port_name); |
| 1710 | qla24xx_post_prli_work(vha, ea->fcport); |
| 1711 | } else { |
| 1712 | ql_dbg(ql_dbg_disc, vha, 0x20ea, |
Quinn Tran | a084fd6 | 2017-12-04 14:45:00 -0800 | [diff] [blame] | 1713 | "%s %d %8phC LoopID 0x%x in use with %06x. post gnl\n", |
| 1714 | __func__, __LINE__, ea->fcport->port_name, |
| 1715 | ea->fcport->loop_id, ea->fcport->d_id.b24); |
| 1716 | |
| 1717 | set_bit(ea->fcport->loop_id, vha->hw->loop_id_map); |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame] | 1718 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Quinn Tran | a084fd6 | 2017-12-04 14:45:00 -0800 | [diff] [blame] | 1719 | ea->fcport->loop_id = FC_NO_LOOP_ID; |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 1720 | ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset; |
| 1721 | ea->fcport->logout_on_delete = 1; |
Quinn Tran | 3515832 | 2017-08-30 10:16:50 -0700 | [diff] [blame] | 1722 | ea->fcport->send_els_logo = 0; |
Quinn Tran | 82abdca | 2017-12-28 12:33:22 -0800 | [diff] [blame] | 1723 | ea->fcport->fw_login_state = DSC_LS_PRLI_COMP; |
| 1724 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 1725 | |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 1726 | qla24xx_post_gpdb_work(vha, ea->fcport, 0); |
| 1727 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1728 | break; |
| 1729 | case MBS_COMMAND_ERROR: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1730 | ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n", |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1731 | __func__, __LINE__, ea->fcport->port_name, ea->data[1]); |
| 1732 | |
| 1733 | ea->fcport->flags &= ~FCF_ASYNC_SENT; |
| 1734 | ea->fcport->disc_state = DSC_LOGIN_FAILED; |
| 1735 | if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1736 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1737 | else |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1738 | qla2x00_mark_device_lost(vha, ea->fcport, 1, 0); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1739 | break; |
| 1740 | case MBS_LOOP_ID_USED: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1741 | /* data[1] = IO PARAM 1 = nport ID */ |
| 1742 | cid.b.domain = (ea->iop[1] >> 16) & 0xff; |
| 1743 | cid.b.area = (ea->iop[1] >> 8) & 0xff; |
| 1744 | cid.b.al_pa = ea->iop[1] & 0xff; |
| 1745 | cid.b.rsvd_1 = 0; |
| 1746 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1747 | ql_dbg(ql_dbg_disc, vha, 0x20ec, |
| 1748 | "%s %d %8phC LoopID 0x%x in use post gnl\n", |
| 1749 | __func__, __LINE__, ea->fcport->port_name, |
| 1750 | ea->fcport->loop_id); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1751 | |
| 1752 | if (IS_SW_RESV_ADDR(cid)) { |
| 1753 | set_bit(ea->fcport->loop_id, vha->hw->loop_id_map); |
| 1754 | ea->fcport->loop_id = FC_NO_LOOP_ID; |
| 1755 | } else { |
| 1756 | qla2x00_clear_loop_id(ea->fcport); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1757 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1758 | qla24xx_post_gnl_work(vha, ea->fcport); |
| 1759 | break; |
| 1760 | case MBS_PORT_ID_USED: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1761 | ql_dbg(ql_dbg_disc, vha, 0x20ed, |
| 1762 | "%s %d %8phC NPortId %02x%02x%02x inuse post gidpn\n", |
| 1763 | __func__, __LINE__, ea->fcport->port_name, |
| 1764 | ea->fcport->d_id.b.domain, ea->fcport->d_id.b.area, |
| 1765 | ea->fcport->d_id.b.al_pa); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1766 | |
Quinn Tran | a084fd6 | 2017-12-04 14:45:00 -0800 | [diff] [blame] | 1767 | lid = ea->iop[1] & 0xffff; |
| 1768 | qlt_find_sess_invalidate_other(vha, |
| 1769 | wwn_to_u64(ea->fcport->port_name), |
| 1770 | ea->fcport->d_id, lid, &conflict_fcport); |
| 1771 | |
| 1772 | if (conflict_fcport) { |
| 1773 | /* |
| 1774 | * Another fcport share the same loop_id/nport id. |
| 1775 | * Conflict fcport needs to finish cleanup before this |
| 1776 | * fcport can proceed to login. |
| 1777 | */ |
| 1778 | conflict_fcport->conflict = ea->fcport; |
| 1779 | ea->fcport->login_pause = 1; |
| 1780 | |
| 1781 | ql_dbg(ql_dbg_disc, vha, 0x20ed, |
| 1782 | "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n", |
| 1783 | __func__, __LINE__, ea->fcport->port_name, |
| 1784 | ea->fcport->d_id.b24, lid); |
| 1785 | qla2x00_clear_loop_id(ea->fcport); |
| 1786 | qla24xx_post_gidpn_work(vha, ea->fcport); |
| 1787 | } else { |
| 1788 | ql_dbg(ql_dbg_disc, vha, 0x20ed, |
| 1789 | "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n", |
| 1790 | __func__, __LINE__, ea->fcport->port_name, |
| 1791 | ea->fcport->d_id.b24, lid); |
| 1792 | |
| 1793 | qla2x00_clear_loop_id(ea->fcport); |
| 1794 | set_bit(lid, vha->hw->loop_id_map); |
| 1795 | ea->fcport->loop_id = lid; |
| 1796 | ea->fcport->keep_nport_handle = 0; |
Quinn Tran | 94cff6e | 2017-12-28 12:33:42 -0800 | [diff] [blame] | 1797 | qlt_schedule_sess_for_deletion(ea->fcport); |
Quinn Tran | a084fd6 | 2017-12-04 14:45:00 -0800 | [diff] [blame] | 1798 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1799 | break; |
| 1800 | } |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1801 | return; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1802 | } |
| 1803 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1804 | void |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1805 | qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 1806 | uint16_t *data) |
| 1807 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1808 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1809 | qlt_logo_completion_handler(fcport, data[0]); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1810 | fcport->login_gen++; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1811 | return; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1812 | } |
| 1813 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1814 | void |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1815 | qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 1816 | uint16_t *data) |
| 1817 | { |
| 1818 | if (data[0] == MBS_COMMAND_COMPLETE) { |
| 1819 | qla2x00_update_fcport(vha, fcport); |
| 1820 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1821 | return; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | /* Retry login. */ |
| 1825 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 1826 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
| 1827 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1828 | else |
Andrew Vasquez | 80d7944 | 2011-03-30 11:46:17 -0700 | [diff] [blame] | 1829 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1830 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1831 | return; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1832 | } |
| 1833 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | /****************************************************************************/ |
| 1835 | /* QLogic ISP2x00 Hardware Support Functions. */ |
| 1836 | /****************************************************************************/ |
| 1837 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 1838 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1839 | qla83xx_nic_core_fw_load(scsi_qla_host_t *vha) |
| 1840 | { |
| 1841 | int rval = QLA_SUCCESS; |
| 1842 | struct qla_hw_data *ha = vha->hw; |
| 1843 | uint32_t idc_major_ver, idc_minor_ver; |
Saurav Kashyap | 711aa7f | 2012-08-22 14:21:15 -0400 | [diff] [blame] | 1844 | uint16_t config[4]; |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1845 | |
| 1846 | qla83xx_idc_lock(vha, 0); |
| 1847 | |
| 1848 | /* SV: TODO: Assign initialization timeout from |
| 1849 | * flash-info / other param |
| 1850 | */ |
| 1851 | ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT; |
| 1852 | ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT; |
| 1853 | |
| 1854 | /* Set our fcoe function presence */ |
| 1855 | if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) { |
| 1856 | ql_dbg(ql_dbg_p3p, vha, 0xb077, |
| 1857 | "Error while setting DRV-Presence.\n"); |
| 1858 | rval = QLA_FUNCTION_FAILED; |
| 1859 | goto exit; |
| 1860 | } |
| 1861 | |
| 1862 | /* Decide the reset ownership */ |
| 1863 | qla83xx_reset_ownership(vha); |
| 1864 | |
| 1865 | /* |
| 1866 | * On first protocol driver load: |
| 1867 | * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery |
| 1868 | * register. |
| 1869 | * Others: Check compatibility with current IDC Major version. |
| 1870 | */ |
| 1871 | qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver); |
| 1872 | if (ha->flags.nic_core_reset_owner) { |
| 1873 | /* Set IDC Major version */ |
| 1874 | idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION; |
| 1875 | qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver); |
| 1876 | |
| 1877 | /* Clearing IDC-Lock-Recovery register */ |
| 1878 | qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0); |
| 1879 | } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) { |
| 1880 | /* |
| 1881 | * Clear further IDC participation if we are not compatible with |
| 1882 | * the current IDC Major Version. |
| 1883 | */ |
| 1884 | ql_log(ql_log_warn, vha, 0xb07d, |
| 1885 | "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n", |
| 1886 | idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION); |
| 1887 | __qla83xx_clear_drv_presence(vha); |
| 1888 | rval = QLA_FUNCTION_FAILED; |
| 1889 | goto exit; |
| 1890 | } |
| 1891 | /* Each function sets its supported Minor version. */ |
| 1892 | qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver); |
| 1893 | idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2)); |
| 1894 | qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver); |
| 1895 | |
Saurav Kashyap | 711aa7f | 2012-08-22 14:21:15 -0400 | [diff] [blame] | 1896 | if (ha->flags.nic_core_reset_owner) { |
| 1897 | memset(config, 0, sizeof(config)); |
| 1898 | if (!qla81xx_get_port_config(vha, config)) |
| 1899 | qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, |
| 1900 | QLA8XXX_DEV_READY); |
| 1901 | } |
| 1902 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1903 | rval = qla83xx_idc_state_handler(vha); |
| 1904 | |
| 1905 | exit: |
| 1906 | qla83xx_idc_unlock(vha, 0); |
| 1907 | |
| 1908 | return rval; |
| 1909 | } |
| 1910 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | /* |
| 1912 | * qla2x00_initialize_adapter |
| 1913 | * Initialize board. |
| 1914 | * |
| 1915 | * Input: |
| 1916 | * ha = adapter block pointer. |
| 1917 | * |
| 1918 | * Returns: |
| 1919 | * 0 = success |
| 1920 | */ |
| 1921 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1922 | qla2x00_initialize_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | { |
| 1924 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1925 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1926 | struct req_que *req = ha->req_q_map[0]; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 1927 | |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 1928 | memset(&vha->qla_stats, 0, sizeof(vha->qla_stats)); |
| 1929 | memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat)); |
| 1930 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | /* Clear adapter flags. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1932 | vha->flags.online = 0; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 1933 | ha->flags.chip_reset_done = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1934 | vha->flags.reset_active = 0; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 1935 | ha->flags.pci_channel_io_perm_failure = 0; |
| 1936 | ha->flags.eeh_busy = 0; |
Joe Carnuccio | fabbb8d | 2013-08-27 01:37:40 -0400 | [diff] [blame] | 1937 | vha->qla_stats.jiffies_at_last_reset = get_jiffies_64(); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1938 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 1939 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 1940 | vha->device_flags = DFLG_NO_CABLE; |
| 1941 | vha->dpc_flags = 0; |
| 1942 | vha->flags.management_server_logged_in = 0; |
| 1943 | vha->marker_needed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | ha->isp_abort_cnt = 0; |
| 1945 | ha->beacon_blink_led = 0; |
| 1946 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1947 | set_bit(0, ha->req_qid_map); |
| 1948 | set_bit(0, ha->rsp_qid_map); |
| 1949 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1950 | ql_dbg(ql_dbg_init, vha, 0x0040, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1951 | "Configuring PCI space...\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1952 | rval = ha->isp_ops->pci_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1953 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1954 | ql_log(ql_log_warn, vha, 0x0044, |
| 1955 | "Unable to configure PCI space.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | return (rval); |
| 1957 | } |
| 1958 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1959 | ha->isp_ops->reset_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1961 | rval = qla2xxx_get_flash_info(vha); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 1962 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1963 | ql_log(ql_log_fatal, vha, 0x004f, |
| 1964 | "Unable to validate FLASH data.\n"); |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 1965 | return rval; |
| 1966 | } |
| 1967 | |
| 1968 | if (IS_QLA8044(ha)) { |
| 1969 | qla8044_read_reset_template(vha); |
| 1970 | |
| 1971 | /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0. |
| 1972 | * If DONRESET_BIT0 is set, drivers should not set dev_state |
| 1973 | * to NEED_RESET. But if NEED_RESET is set, drivers should |
| 1974 | * should honor the reset. */ |
| 1975 | if (ql2xdontresethba == 1) |
| 1976 | qla8044_set_idc_dontreset(vha); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 1977 | } |
| 1978 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1979 | ha->isp_ops->get_flash_version(vha, req->ring); |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1980 | ql_dbg(ql_dbg_init, vha, 0x0061, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1981 | "Configure NVRAM parameters...\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1982 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1983 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 1985 | if (ha->flags.disable_serdes) { |
| 1986 | /* Mask HBA via NVRAM settings? */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1987 | ql_log(ql_log_info, vha, 0x0077, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1988 | "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name); |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 1989 | return QLA_FUNCTION_FAILED; |
| 1990 | } |
| 1991 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1992 | ql_dbg(ql_dbg_init, vha, 0x0078, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1993 | "Verifying loaded RISC code...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1995 | if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) { |
| 1996 | rval = ha->isp_ops->chip_diag(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 1997 | if (rval) |
| 1998 | return (rval); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1999 | rval = qla2x00_setup_chip(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 2000 | if (rval) |
| 2001 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2003 | |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2004 | if (IS_QLA84XX(ha)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2005 | ha->cs84xx = qla84xx_get_chip(vha); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2006 | if (!ha->cs84xx) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2007 | ql_log(ql_log_warn, vha, 0x00d0, |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2008 | "Unable to configure ISP84XX.\n"); |
| 2009 | return QLA_FUNCTION_FAILED; |
| 2010 | } |
| 2011 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2012 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 2013 | if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2014 | rval = qla2x00_init_rings(vha); |
| 2015 | |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 2016 | ha->flags.chip_reset_done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2018 | if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) { |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 2019 | /* Issue verify 84xx FW IOCB to complete 84xx initialization */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2020 | rval = qla84xx_init_chip(vha); |
| 2021 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2022 | ql_log(ql_log_warn, vha, 0x00d4, |
| 2023 | "Unable to initialize ISP84XX.\n"); |
Bart Van Assche | 8d2b21d | 2015-06-04 15:58:09 -0700 | [diff] [blame] | 2024 | qla84xx_put_chip(vha); |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2025 | } |
| 2026 | } |
| 2027 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 2028 | /* Load the NIC Core f/w if we are the first protocol driver. */ |
| 2029 | if (IS_QLA8031(ha)) { |
| 2030 | rval = qla83xx_nic_core_fw_load(vha); |
| 2031 | if (rval) |
| 2032 | ql_log(ql_log_warn, vha, 0x0124, |
| 2033 | "Error in initializing NIC Core f/w.\n"); |
| 2034 | } |
| 2035 | |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 2036 | if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)) |
| 2037 | qla24xx_read_fcp_prio_cfg(vha); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 2038 | |
Joe Carnuccio | c46e65c | 2013-08-27 01:37:35 -0400 | [diff] [blame] | 2039 | if (IS_P3P_TYPE(ha)) |
| 2040 | qla82xx_set_driver_version(vha, QLA2XXX_VERSION); |
| 2041 | else |
| 2042 | qla25xx_set_driver_version(vha, QLA2XXX_VERSION); |
| 2043 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | return (rval); |
| 2045 | } |
| 2046 | |
| 2047 | /** |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2048 | * qla2100_pci_config() - Setup ISP21xx PCI configuration registers. |
Bart Van Assche | 2db6228 | 2018-01-23 16:33:51 -0800 | [diff] [blame] | 2049 | * @vha: HA context |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | * |
| 2051 | * Returns 0 on success. |
| 2052 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2053 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2054 | qla2100_pci_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2055 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 2056 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2057 | unsigned long flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2058 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2059 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2061 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 2062 | pci_try_set_mwi(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 2065 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 2067 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 2068 | pci_disable_rom(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2070 | /* Get PCI bus information. */ |
| 2071 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2072 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2073 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2074 | |
| 2075 | return QLA_SUCCESS; |
| 2076 | } |
| 2077 | |
| 2078 | /** |
| 2079 | * qla2300_pci_config() - Setup ISP23xx PCI configuration registers. |
Bart Van Assche | 2db6228 | 2018-01-23 16:33:51 -0800 | [diff] [blame] | 2080 | * @vha: HA context |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2081 | * |
| 2082 | * Returns 0 on success. |
| 2083 | */ |
| 2084 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2085 | qla2300_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2086 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 2087 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2088 | unsigned long flags = 0; |
| 2089 | uint32_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2090 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2091 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2092 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2093 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 2094 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2095 | |
| 2096 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 2097 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2098 | |
| 2099 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 2100 | w &= ~PCI_COMMAND_INTX_DISABLE; |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 2101 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2102 | |
| 2103 | /* |
| 2104 | * If this is a 2300 card and not 2312, reset the |
| 2105 | * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately, |
| 2106 | * the 2310 also reports itself as a 2300 so we need to get the |
| 2107 | * fb revision level -- a 6 indicates it really is a 2300 and |
| 2108 | * not a 2310. |
| 2109 | */ |
| 2110 | if (IS_QLA2300(ha)) { |
| 2111 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2112 | |
| 2113 | /* Pause RISC. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2114 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2115 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2116 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2117 | break; |
| 2118 | |
| 2119 | udelay(10); |
| 2120 | } |
| 2121 | |
| 2122 | /* Select FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2123 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 2124 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2125 | |
| 2126 | /* Get the fb rev level */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2127 | ha->fb_rev = RD_FB_CMD_REG(ha, reg); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2128 | |
| 2129 | if (ha->fb_rev == FPM_2300) |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 2130 | pci_clear_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2131 | |
| 2132 | /* Deselect FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2133 | WRT_REG_WORD(®->ctrl_status, 0x0); |
| 2134 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2135 | |
| 2136 | /* Release RISC module. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2137 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2138 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2139 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2140 | break; |
| 2141 | |
| 2142 | udelay(10); |
| 2143 | } |
| 2144 | |
| 2145 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2146 | } |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2147 | |
| 2148 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 2149 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 2150 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2151 | |
| 2152 | /* Get PCI bus information. */ |
| 2153 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2154 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2155 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2156 | |
| 2157 | return QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2158 | } |
| 2159 | |
| 2160 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2161 | * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers. |
Bart Van Assche | 2db6228 | 2018-01-23 16:33:51 -0800 | [diff] [blame] | 2162 | * @vha: HA context |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2163 | * |
| 2164 | * Returns 0 on success. |
| 2165 | */ |
| 2166 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2167 | qla24xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2168 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 2169 | uint16_t w; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2170 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2171 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2172 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2173 | |
| 2174 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 2175 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2176 | |
| 2177 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 2178 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2179 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 2180 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 2181 | |
| 2182 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 2183 | |
| 2184 | /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */ |
Andrew Vasquez | f85ec18 | 2007-07-19 15:06:01 -0700 | [diff] [blame] | 2185 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX)) |
| 2186 | pcix_set_mmrbc(ha->pdev, 2048); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2187 | |
| 2188 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Jon Mason | e67f132 | 2012-07-10 14:57:56 -0700 | [diff] [blame] | 2189 | if (pci_is_pcie(ha->pdev)) |
Chad Dupuis | 5ffd3a5 | 2012-08-22 14:21:26 -0400 | [diff] [blame] | 2190 | pcie_set_readrq(ha->pdev, 4096); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2191 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 2192 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2193 | |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 2194 | ha->chip_revision = ha->pdev->revision; |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 2195 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2196 | /* Get PCI bus information. */ |
| 2197 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2198 | ha->pci_attr = RD_REG_DWORD(®->ctrl_status); |
| 2199 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2200 | |
| 2201 | return QLA_SUCCESS; |
| 2202 | } |
| 2203 | |
| 2204 | /** |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 2205 | * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers. |
Bart Van Assche | 2db6228 | 2018-01-23 16:33:51 -0800 | [diff] [blame] | 2206 | * @vha: HA context |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 2207 | * |
| 2208 | * Returns 0 on success. |
| 2209 | */ |
| 2210 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2211 | qla25xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 2212 | { |
| 2213 | uint16_t w; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2214 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 2215 | |
| 2216 | pci_set_master(ha->pdev); |
| 2217 | pci_try_set_mwi(ha->pdev); |
| 2218 | |
| 2219 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
| 2220 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
| 2221 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 2222 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 2223 | |
| 2224 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Jon Mason | e67f132 | 2012-07-10 14:57:56 -0700 | [diff] [blame] | 2225 | if (pci_is_pcie(ha->pdev)) |
Chad Dupuis | 5ffd3a5 | 2012-08-22 14:21:26 -0400 | [diff] [blame] | 2226 | pcie_set_readrq(ha->pdev, 4096); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 2227 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 2228 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 2229 | |
| 2230 | ha->chip_revision = ha->pdev->revision; |
| 2231 | |
| 2232 | return QLA_SUCCESS; |
| 2233 | } |
| 2234 | |
| 2235 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | * qla2x00_isp_firmware() - Choose firmware image. |
Bart Van Assche | 2db6228 | 2018-01-23 16:33:51 -0800 | [diff] [blame] | 2237 | * @vha: HA context |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2238 | * |
| 2239 | * Returns 0 on success. |
| 2240 | */ |
| 2241 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2242 | qla2x00_isp_firmware(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | { |
| 2244 | int rval; |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 2245 | uint16_t loop_id, topo, sw_cap; |
| 2246 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2247 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2248 | |
| 2249 | /* Assume loading risc code */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2250 | rval = QLA_FUNCTION_FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | |
| 2252 | if (ha->flags.disable_risc_code_load) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2253 | ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2254 | |
| 2255 | /* Verify checksum of loaded RISC code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2256 | rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address); |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 2257 | if (rval == QLA_SUCCESS) { |
| 2258 | /* And, verify we are not in ROM code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2259 | rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa, |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 2260 | &area, &domain, &topo, &sw_cap); |
| 2261 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2262 | } |
| 2263 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2264 | if (rval) |
| 2265 | ql_dbg(ql_dbg_init, vha, 0x007a, |
| 2266 | "**** Load RISC code ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2267 | |
| 2268 | return (rval); |
| 2269 | } |
| 2270 | |
| 2271 | /** |
| 2272 | * qla2x00_reset_chip() - Reset ISP chip. |
Bart Van Assche | 2db6228 | 2018-01-23 16:33:51 -0800 | [diff] [blame] | 2273 | * @vha: HA context |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2274 | * |
| 2275 | * Returns 0 on success. |
| 2276 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2277 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2278 | qla2x00_reset_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | { |
| 2280 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2281 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2282 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2283 | uint32_t cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2284 | uint16_t cmd; |
| 2285 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 2286 | if (unlikely(pci_channel_offline(ha->pdev))) |
| 2287 | return; |
| 2288 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 2289 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2290 | |
| 2291 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2292 | |
| 2293 | /* Turn off master enable */ |
| 2294 | cmd = 0; |
| 2295 | pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd); |
| 2296 | cmd &= ~PCI_COMMAND_MASTER; |
| 2297 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 2298 | |
| 2299 | if (!IS_QLA2100(ha)) { |
| 2300 | /* Pause RISC. */ |
| 2301 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
| 2302 | if (IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 2303 | for (cnt = 0; cnt < 30000; cnt++) { |
| 2304 | if ((RD_REG_WORD(®->hccr) & |
| 2305 | HCCR_RISC_PAUSE) != 0) |
| 2306 | break; |
| 2307 | udelay(100); |
| 2308 | } |
| 2309 | } else { |
| 2310 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 2311 | udelay(10); |
| 2312 | } |
| 2313 | |
| 2314 | /* Select FPM registers. */ |
| 2315 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 2316 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 2317 | |
| 2318 | /* FPM Soft Reset. */ |
| 2319 | WRT_REG_WORD(®->fpm_diag_config, 0x100); |
| 2320 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 2321 | |
| 2322 | /* Toggle Fpm Reset. */ |
| 2323 | if (!IS_QLA2200(ha)) { |
| 2324 | WRT_REG_WORD(®->fpm_diag_config, 0x0); |
| 2325 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 2326 | } |
| 2327 | |
| 2328 | /* Select frame buffer registers. */ |
| 2329 | WRT_REG_WORD(®->ctrl_status, 0x10); |
| 2330 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 2331 | |
| 2332 | /* Reset frame buffer FIFOs. */ |
| 2333 | if (IS_QLA2200(ha)) { |
| 2334 | WRT_FB_CMD_REG(ha, reg, 0xa000); |
| 2335 | RD_FB_CMD_REG(ha, reg); /* PCI Posting. */ |
| 2336 | } else { |
| 2337 | WRT_FB_CMD_REG(ha, reg, 0x00fc); |
| 2338 | |
| 2339 | /* Read back fb_cmd until zero or 3 seconds max */ |
| 2340 | for (cnt = 0; cnt < 3000; cnt++) { |
| 2341 | if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0) |
| 2342 | break; |
| 2343 | udelay(100); |
| 2344 | } |
| 2345 | } |
| 2346 | |
| 2347 | /* Select RISC module registers. */ |
| 2348 | WRT_REG_WORD(®->ctrl_status, 0); |
| 2349 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 2350 | |
| 2351 | /* Reset RISC processor. */ |
| 2352 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 2353 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 2354 | |
| 2355 | /* Release RISC processor. */ |
| 2356 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 2357 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 2358 | } |
| 2359 | |
| 2360 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); |
| 2361 | WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT); |
| 2362 | |
| 2363 | /* Reset ISP chip. */ |
| 2364 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 2365 | |
| 2366 | /* Wait for RISC to recover from reset. */ |
| 2367 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 2368 | /* |
| 2369 | * It is necessary to for a delay here since the card doesn't |
| 2370 | * respond to PCI reads during a reset. On some architectures |
| 2371 | * this will result in an MCA. |
| 2372 | */ |
| 2373 | udelay(20); |
| 2374 | for (cnt = 30000; cnt; cnt--) { |
| 2375 | if ((RD_REG_WORD(®->ctrl_status) & |
| 2376 | CSR_ISP_SOFT_RESET) == 0) |
| 2377 | break; |
| 2378 | udelay(100); |
| 2379 | } |
| 2380 | } else |
| 2381 | udelay(10); |
| 2382 | |
| 2383 | /* Reset RISC processor. */ |
| 2384 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 2385 | |
| 2386 | WRT_REG_WORD(®->semaphore, 0); |
| 2387 | |
| 2388 | /* Release RISC processor. */ |
| 2389 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 2390 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 2391 | |
| 2392 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 2393 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | ffb39f0 | 2006-05-17 15:09:06 -0700 | [diff] [blame] | 2394 | if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2395 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2396 | |
| 2397 | udelay(100); |
| 2398 | } |
| 2399 | } else |
| 2400 | udelay(100); |
| 2401 | |
| 2402 | /* Turn on master enable */ |
| 2403 | cmd |= PCI_COMMAND_MASTER; |
| 2404 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 2405 | |
| 2406 | /* Disable RISC pause on FPM parity error. */ |
| 2407 | if (!IS_QLA2100(ha)) { |
| 2408 | WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE); |
| 2409 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 2410 | } |
| 2411 | |
| 2412 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2413 | } |
| 2414 | |
| 2415 | /** |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2416 | * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC. |
Bart Van Assche | 2db6228 | 2018-01-23 16:33:51 -0800 | [diff] [blame] | 2417 | * @vha: HA context |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2418 | * |
| 2419 | * Returns 0 on success. |
| 2420 | */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 2421 | static int |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2422 | qla81xx_reset_mpi(scsi_qla_host_t *vha) |
| 2423 | { |
| 2424 | uint16_t mb[4] = {0x1010, 0, 1, 0}; |
| 2425 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2426 | if (!IS_QLA81XX(vha->hw)) |
| 2427 | return QLA_SUCCESS; |
| 2428 | |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2429 | return qla81xx_write_mpi_register(vha, mb); |
| 2430 | } |
| 2431 | |
| 2432 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2433 | * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC. |
Bart Van Assche | 2db6228 | 2018-01-23 16:33:51 -0800 | [diff] [blame] | 2434 | * @vha: HA context |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2435 | * |
| 2436 | * Returns 0 on success. |
| 2437 | */ |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2438 | static inline int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2439 | qla24xx_reset_risc(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2440 | { |
| 2441 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2442 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2443 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2444 | uint32_t cnt; |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2445 | uint16_t wd; |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2446 | static int abts_cnt; /* ISP abort retry counts */ |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2447 | int rval = QLA_SUCCESS; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2448 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2449 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2450 | |
| 2451 | /* Reset RISC. */ |
| 2452 | WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
| 2453 | for (cnt = 0; cnt < 30000; cnt++) { |
| 2454 | if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0) |
| 2455 | break; |
| 2456 | |
| 2457 | udelay(10); |
| 2458 | } |
| 2459 | |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2460 | if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE)) |
| 2461 | set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags); |
| 2462 | |
| 2463 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e, |
| 2464 | "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n", |
| 2465 | RD_REG_DWORD(®->hccr), |
| 2466 | RD_REG_DWORD(®->ctrl_status), |
| 2467 | (RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE)); |
| 2468 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2469 | WRT_REG_DWORD(®->ctrl_status, |
| 2470 | CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2471 | pci_read_config_word(ha->pdev, PCI_COMMAND, &wd); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2472 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2473 | udelay(100); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2474 | |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2475 | /* Wait for firmware to complete NVRAM accesses. */ |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2476 | RD_REG_WORD(®->mailbox0); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2477 | for (cnt = 10000; RD_REG_WORD(®->mailbox0) != 0 && |
| 2478 | rval == QLA_SUCCESS; cnt--) { |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2479 | barrier(); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2480 | if (cnt) |
| 2481 | udelay(5); |
| 2482 | else |
| 2483 | rval = QLA_FUNCTION_TIMEOUT; |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2484 | } |
| 2485 | |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2486 | if (rval == QLA_SUCCESS) |
| 2487 | set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags); |
| 2488 | |
| 2489 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f, |
| 2490 | "HCCR: 0x%x, MailBox0 Status 0x%x\n", |
| 2491 | RD_REG_DWORD(®->hccr), |
| 2492 | RD_REG_DWORD(®->mailbox0)); |
| 2493 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2494 | /* Wait for soft-reset to complete. */ |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2495 | RD_REG_DWORD(®->ctrl_status); |
Quinn Tran | 200ffb1 | 2016-12-23 18:06:12 -0800 | [diff] [blame] | 2496 | for (cnt = 0; cnt < 60; cnt++) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2497 | barrier(); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2498 | if ((RD_REG_DWORD(®->ctrl_status) & |
| 2499 | CSRX_ISP_SOFT_RESET) == 0) |
| 2500 | break; |
| 2501 | |
| 2502 | udelay(5); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2503 | } |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2504 | if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_ISP_SOFT_RESET)) |
| 2505 | set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags); |
| 2506 | |
| 2507 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d, |
| 2508 | "HCCR: 0x%x, Soft Reset status: 0x%x\n", |
| 2509 | RD_REG_DWORD(®->hccr), |
| 2510 | RD_REG_DWORD(®->ctrl_status)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2511 | |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2512 | /* If required, do an MPI FW reset now */ |
| 2513 | if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) { |
| 2514 | if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) { |
| 2515 | if (++abts_cnt < 5) { |
| 2516 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 2517 | set_bit(MPI_RESET_NEEDED, &vha->dpc_flags); |
| 2518 | } else { |
| 2519 | /* |
| 2520 | * We exhausted the ISP abort retries. We have to |
| 2521 | * set the board offline. |
| 2522 | */ |
| 2523 | abts_cnt = 0; |
| 2524 | vha->flags.online = 0; |
| 2525 | } |
| 2526 | } |
| 2527 | } |
| 2528 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2529 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 2530 | RD_REG_DWORD(®->hccr); |
| 2531 | |
| 2532 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 2533 | RD_REG_DWORD(®->hccr); |
| 2534 | |
| 2535 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET); |
| 2536 | RD_REG_DWORD(®->hccr); |
| 2537 | |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2538 | RD_REG_WORD(®->mailbox0); |
Quinn Tran | 200ffb1 | 2016-12-23 18:06:12 -0800 | [diff] [blame] | 2539 | for (cnt = 60; RD_REG_WORD(®->mailbox0) != 0 && |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2540 | rval == QLA_SUCCESS; cnt--) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2541 | barrier(); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2542 | if (cnt) |
| 2543 | udelay(5); |
| 2544 | else |
| 2545 | rval = QLA_FUNCTION_TIMEOUT; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2546 | } |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2547 | if (rval == QLA_SUCCESS) |
| 2548 | set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags); |
| 2549 | |
| 2550 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e, |
| 2551 | "Host Risc 0x%x, mailbox0 0x%x\n", |
| 2552 | RD_REG_DWORD(®->hccr), |
| 2553 | RD_REG_WORD(®->mailbox0)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2554 | |
| 2555 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 124f85e | 2009-01-05 11:18:06 -0800 | [diff] [blame] | 2556 | |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2557 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f, |
| 2558 | "Driver in %s mode\n", |
| 2559 | IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling"); |
| 2560 | |
Andrew Vasquez | 124f85e | 2009-01-05 11:18:06 -0800 | [diff] [blame] | 2561 | if (IS_NOPOLLING_TYPE(ha)) |
| 2562 | ha->isp_ops->enable_intrs(ha); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2563 | |
| 2564 | return rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2565 | } |
| 2566 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2567 | static void |
| 2568 | qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data) |
| 2569 | { |
| 2570 | struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24; |
| 2571 | |
| 2572 | WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET); |
| 2573 | *data = RD_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET); |
| 2574 | |
| 2575 | } |
| 2576 | |
| 2577 | static void |
| 2578 | qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data) |
| 2579 | { |
| 2580 | struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24; |
| 2581 | |
| 2582 | WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET); |
| 2583 | WRT_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET, data); |
| 2584 | } |
| 2585 | |
| 2586 | static void |
| 2587 | qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha) |
| 2588 | { |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2589 | uint32_t wd32 = 0; |
| 2590 | uint delta_msec = 100; |
| 2591 | uint elapsed_msec = 0; |
| 2592 | uint timeout_msec; |
| 2593 | ulong n; |
| 2594 | |
Joe Carnuccio | cc79076 | 2015-08-04 13:37:53 -0400 | [diff] [blame] | 2595 | if (vha->hw->pdev->subsystem_device != 0x0175 && |
| 2596 | vha->hw->pdev->subsystem_device != 0x0240) |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2597 | return; |
| 2598 | |
Joe Carnuccio | 8dd7e3a | 2015-08-04 13:37:54 -0400 | [diff] [blame] | 2599 | WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE); |
| 2600 | udelay(100); |
| 2601 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2602 | attempt: |
| 2603 | timeout_msec = TIMEOUT_SEMAPHORE; |
| 2604 | n = timeout_msec / delta_msec; |
| 2605 | while (n--) { |
| 2606 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET); |
| 2607 | qla25xx_read_risc_sema_reg(vha, &wd32); |
| 2608 | if (wd32 & RISC_SEMAPHORE) |
| 2609 | break; |
| 2610 | msleep(delta_msec); |
| 2611 | elapsed_msec += delta_msec; |
| 2612 | if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED) |
| 2613 | goto force; |
| 2614 | } |
| 2615 | |
| 2616 | if (!(wd32 & RISC_SEMAPHORE)) |
| 2617 | goto force; |
| 2618 | |
| 2619 | if (!(wd32 & RISC_SEMAPHORE_FORCE)) |
| 2620 | goto acquired; |
| 2621 | |
| 2622 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR); |
| 2623 | timeout_msec = TIMEOUT_SEMAPHORE_FORCE; |
| 2624 | n = timeout_msec / delta_msec; |
| 2625 | while (n--) { |
| 2626 | qla25xx_read_risc_sema_reg(vha, &wd32); |
| 2627 | if (!(wd32 & RISC_SEMAPHORE_FORCE)) |
| 2628 | break; |
| 2629 | msleep(delta_msec); |
| 2630 | elapsed_msec += delta_msec; |
| 2631 | if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED) |
| 2632 | goto force; |
| 2633 | } |
| 2634 | |
| 2635 | if (wd32 & RISC_SEMAPHORE_FORCE) |
| 2636 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR); |
| 2637 | |
| 2638 | goto attempt; |
| 2639 | |
| 2640 | force: |
| 2641 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET); |
| 2642 | |
| 2643 | acquired: |
| 2644 | return; |
| 2645 | } |
| 2646 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2647 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2648 | * qla24xx_reset_chip() - Reset ISP24xx chip. |
Bart Van Assche | 2db6228 | 2018-01-23 16:33:51 -0800 | [diff] [blame] | 2649 | * @vha: HA context |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2650 | * |
| 2651 | * Returns 0 on success. |
| 2652 | */ |
| 2653 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2654 | qla24xx_reset_chip(scsi_qla_host_t *vha) |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2655 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2656 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 2657 | |
| 2658 | if (pci_channel_offline(ha->pdev) && |
| 2659 | ha->flags.pci_channel_io_perm_failure) { |
| 2660 | return; |
| 2661 | } |
| 2662 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 2663 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2664 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2665 | qla25xx_manipulate_risc_semaphore(vha); |
| 2666 | |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2667 | /* Perform RISC reset. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2668 | qla24xx_reset_risc(vha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2669 | } |
| 2670 | |
| 2671 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | * qla2x00_chip_diag() - Test chip for proper operation. |
Bart Van Assche | 2db6228 | 2018-01-23 16:33:51 -0800 | [diff] [blame] | 2673 | * @vha: HA context |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2674 | * |
| 2675 | * Returns 0 on success. |
| 2676 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2677 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2678 | qla2x00_chip_diag(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2679 | { |
| 2680 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2681 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2682 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2683 | unsigned long flags = 0; |
| 2684 | uint16_t data; |
| 2685 | uint32_t cnt; |
| 2686 | uint16_t mb[5]; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2687 | struct req_que *req = ha->req_q_map[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2688 | |
| 2689 | /* Assume a failed state */ |
| 2690 | rval = QLA_FUNCTION_FAILED; |
| 2691 | |
Bart Van Assche | da4704d | 2018-01-23 16:33:47 -0800 | [diff] [blame] | 2692 | ql_dbg(ql_dbg_init, vha, 0x007b, "Testing device at %p.\n", |
| 2693 | ®->flash_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2694 | |
| 2695 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2696 | |
| 2697 | /* Reset ISP chip. */ |
| 2698 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 2699 | |
| 2700 | /* |
| 2701 | * We need to have a delay here since the card will not respond while |
| 2702 | * in reset causing an MCA on some architectures. |
| 2703 | */ |
| 2704 | udelay(20); |
| 2705 | data = qla2x00_debounce_register(®->ctrl_status); |
| 2706 | for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) { |
| 2707 | udelay(5); |
| 2708 | data = RD_REG_WORD(®->ctrl_status); |
| 2709 | barrier(); |
| 2710 | } |
| 2711 | |
| 2712 | if (!cnt) |
| 2713 | goto chip_diag_failed; |
| 2714 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2715 | ql_dbg(ql_dbg_init, vha, 0x007c, |
| 2716 | "Reset register cleared by chip reset.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2717 | |
| 2718 | /* Reset RISC processor. */ |
| 2719 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 2720 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 2721 | |
| 2722 | /* Workaround for QLA2312 PCI parity error */ |
| 2723 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 2724 | data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0)); |
| 2725 | for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) { |
| 2726 | udelay(5); |
| 2727 | data = RD_MAILBOX_REG(ha, reg, 0); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2728 | barrier(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2729 | } |
| 2730 | } else |
| 2731 | udelay(10); |
| 2732 | |
| 2733 | if (!cnt) |
| 2734 | goto chip_diag_failed; |
| 2735 | |
| 2736 | /* Check product ID of chip */ |
Milan P Gandhi | 5a68a1c | 2017-03-31 14:37:04 -0700 | [diff] [blame] | 2737 | 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] | 2738 | |
| 2739 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); |
| 2740 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); |
| 2741 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); |
| 2742 | mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4)); |
| 2743 | if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) || |
| 2744 | mb[3] != PROD_ID_3) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2745 | ql_log(ql_log_warn, vha, 0x0062, |
| 2746 | "Wrong product ID = 0x%x,0x%x,0x%x.\n", |
| 2747 | mb[1], mb[2], mb[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2748 | |
| 2749 | goto chip_diag_failed; |
| 2750 | } |
| 2751 | ha->product_id[0] = mb[1]; |
| 2752 | ha->product_id[1] = mb[2]; |
| 2753 | ha->product_id[2] = mb[3]; |
| 2754 | ha->product_id[3] = mb[4]; |
| 2755 | |
| 2756 | /* Adjust fw RISC transfer size */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2757 | if (req->length > 1024) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2758 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024; |
| 2759 | else |
| 2760 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2761 | req->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2762 | |
| 2763 | if (IS_QLA2200(ha) && |
| 2764 | RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) { |
| 2765 | /* Limit firmware transfer size with a 2200A */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2766 | ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2767 | |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 2768 | ha->device_type |= DT_ISP2200A; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | ha->fw_transfer_size = 128; |
| 2770 | } |
| 2771 | |
| 2772 | /* Wrap Incoming Mailboxes Test. */ |
| 2773 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2774 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2775 | ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2776 | rval = qla2x00_mbx_reg_test(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2777 | if (rval) |
| 2778 | ql_log(ql_log_warn, vha, 0x0080, |
| 2779 | "Failed mailbox send register test.\n"); |
| 2780 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2781 | /* Flag a successful rval */ |
| 2782 | rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2783 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2784 | |
| 2785 | chip_diag_failed: |
| 2786 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2787 | ql_log(ql_log_info, vha, 0x0081, |
| 2788 | "Chip diagnostics **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2789 | |
| 2790 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2791 | |
| 2792 | return (rval); |
| 2793 | } |
| 2794 | |
| 2795 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2796 | * qla24xx_chip_diag() - Test ISP24xx for proper operation. |
Bart Van Assche | 2db6228 | 2018-01-23 16:33:51 -0800 | [diff] [blame] | 2797 | * @vha: HA context |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2798 | * |
| 2799 | * Returns 0 on success. |
| 2800 | */ |
| 2801 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2802 | qla24xx_chip_diag(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2803 | { |
| 2804 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2805 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2806 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2807 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 2808 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2809 | return QLA_SUCCESS; |
| 2810 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2811 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2812 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2813 | rval = qla2x00_mbx_reg_test(vha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2814 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2815 | ql_log(ql_log_warn, vha, 0x0082, |
| 2816 | "Failed mailbox send register test.\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2817 | } else { |
| 2818 | /* Flag a successful rval */ |
| 2819 | rval = QLA_SUCCESS; |
| 2820 | } |
| 2821 | |
| 2822 | return rval; |
| 2823 | } |
| 2824 | |
Quinn Tran | ad0a0b0 | 2017-12-28 12:33:14 -0800 | [diff] [blame] | 2825 | static void |
| 2826 | qla2x00_alloc_offload_mem(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2827 | { |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2828 | int rval; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2829 | dma_addr_t tc_dma; |
| 2830 | void *tc; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2831 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 2832 | |
Quinn Tran | ad0a0b0 | 2017-12-28 12:33:14 -0800 | [diff] [blame] | 2833 | if (ha->eft) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2834 | ql_dbg(ql_dbg_init, vha, 0x00bd, |
Quinn Tran | ad0a0b0 | 2017-12-28 12:33:14 -0800 | [diff] [blame] | 2835 | "%s: Offload Mem is already allocated.\n", |
| 2836 | __func__); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2837 | return; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 2838 | } |
| 2839 | |
Quinn Tran | ad0a0b0 | 2017-12-28 12:33:14 -0800 | [diff] [blame] | 2840 | if (IS_FWI2_CAPABLE(ha)) { |
| 2841 | /* Allocate memory for Fibre Channel Event Buffer. */ |
| 2842 | if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) && |
| 2843 | !IS_QLA27XX(ha)) |
| 2844 | goto try_eft; |
| 2845 | |
| 2846 | if (ha->fce) |
| 2847 | dma_free_coherent(&ha->pdev->dev, |
| 2848 | FCE_SIZE, ha->fce, ha->fce_dma); |
| 2849 | |
| 2850 | /* Allocate memory for Fibre Channel Event Buffer. */ |
| 2851 | tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma, |
| 2852 | GFP_KERNEL); |
| 2853 | if (!tc) { |
| 2854 | ql_log(ql_log_warn, vha, 0x00be, |
| 2855 | "Unable to allocate (%d KB) for FCE.\n", |
| 2856 | FCE_SIZE / 1024); |
| 2857 | goto try_eft; |
| 2858 | } |
| 2859 | |
| 2860 | rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS, |
| 2861 | ha->fce_mb, &ha->fce_bufs); |
| 2862 | if (rval) { |
| 2863 | ql_log(ql_log_warn, vha, 0x00bf, |
| 2864 | "Unable to initialize FCE (%d).\n", rval); |
| 2865 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, |
| 2866 | tc_dma); |
| 2867 | ha->flags.fce_enabled = 0; |
| 2868 | goto try_eft; |
| 2869 | } |
| 2870 | ql_dbg(ql_dbg_init, vha, 0x00c0, |
| 2871 | "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024); |
| 2872 | |
| 2873 | ha->flags.fce_enabled = 1; |
| 2874 | ha->fce_dma = tc_dma; |
| 2875 | ha->fce = tc; |
| 2876 | |
| 2877 | try_eft: |
| 2878 | if (ha->eft) |
| 2879 | dma_free_coherent(&ha->pdev->dev, |
| 2880 | EFT_SIZE, ha->eft, ha->eft_dma); |
| 2881 | |
| 2882 | /* Allocate memory for Extended Trace Buffer. */ |
| 2883 | tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma, |
| 2884 | GFP_KERNEL); |
| 2885 | if (!tc) { |
| 2886 | ql_log(ql_log_warn, vha, 0x00c1, |
| 2887 | "Unable to allocate (%d KB) for EFT.\n", |
| 2888 | EFT_SIZE / 1024); |
| 2889 | goto eft_err; |
| 2890 | } |
| 2891 | |
| 2892 | rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS); |
| 2893 | if (rval) { |
| 2894 | ql_log(ql_log_warn, vha, 0x00c2, |
| 2895 | "Unable to initialize EFT (%d).\n", rval); |
| 2896 | dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, |
| 2897 | tc_dma); |
| 2898 | goto eft_err; |
| 2899 | } |
| 2900 | ql_dbg(ql_dbg_init, vha, 0x00c3, |
| 2901 | "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024); |
| 2902 | |
| 2903 | ha->eft_dma = tc_dma; |
| 2904 | ha->eft = tc; |
| 2905 | } |
| 2906 | |
| 2907 | eft_err: |
| 2908 | return; |
| 2909 | } |
| 2910 | |
| 2911 | void |
| 2912 | qla2x00_alloc_fw_dump(scsi_qla_host_t *vha) |
| 2913 | { |
| 2914 | uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size, |
| 2915 | eft_size, fce_size, mq_size; |
| 2916 | struct qla_hw_data *ha = vha->hw; |
| 2917 | struct req_que *req = ha->req_q_map[0]; |
| 2918 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
| 2919 | struct qla2xxx_fw_dump *fw_dump; |
| 2920 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2921 | dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0; |
| 2922 | req_q_size = rsp_q_size = 0; |
| 2923 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2924 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 2925 | fixed_size = sizeof(struct qla2100_fw_dump); |
| 2926 | } else if (IS_QLA23XX(ha)) { |
| 2927 | fixed_size = offsetof(struct qla2300_fw_dump, data_ram); |
| 2928 | mem_size = (ha->fw_memory_size - 0x11000 + 1) * |
| 2929 | sizeof(uint16_t); |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 2930 | } else if (IS_FWI2_CAPABLE(ha)) { |
Himanshu Madhani | b20f02e | 2015-06-10 11:05:18 -0400 | [diff] [blame] | 2931 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2932 | fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem); |
| 2933 | else if (IS_QLA81XX(ha)) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 2934 | fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem); |
| 2935 | else if (IS_QLA25XX(ha)) |
| 2936 | fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem); |
| 2937 | else |
| 2938 | fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2939 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2940 | mem_size = (ha->fw_memory_size - 0x100000 + 1) * |
| 2941 | sizeof(uint32_t); |
Giridhar Malavali | 050c9bb | 2012-02-09 11:15:33 -0800 | [diff] [blame] | 2942 | if (ha->mqenable) { |
Himanshu Madhani | b20f02e | 2015-06-10 11:05:18 -0400 | [diff] [blame] | 2943 | if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha)) |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2944 | mq_size = sizeof(struct qla2xxx_mq_chain); |
Giridhar Malavali | 050c9bb | 2012-02-09 11:15:33 -0800 | [diff] [blame] | 2945 | /* |
| 2946 | * Allocate maximum buffer size for all queues. |
| 2947 | * Resizing must be done at end-of-dump processing. |
| 2948 | */ |
| 2949 | mq_size += ha->max_req_queues * |
| 2950 | (req->length * sizeof(request_t)); |
| 2951 | mq_size += ha->max_rsp_queues * |
| 2952 | (rsp->length * sizeof(response_t)); |
| 2953 | } |
Arun Easi | 00876ae | 2013-03-25 02:21:37 -0400 | [diff] [blame] | 2954 | if (ha->tgt.atio_ring) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2955 | mq_size += ha->tgt.atio_q_length * sizeof(request_t); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2956 | /* Allocate memory for Fibre Channel Event Buffer. */ |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2957 | if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) && |
| 2958 | !IS_QLA27XX(ha)) |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2959 | goto try_eft; |
| 2960 | |
Giridhar Malavali | 7d9dade | 2009-03-24 09:07:58 -0700 | [diff] [blame] | 2961 | fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2962 | try_eft: |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2963 | ql_dbg(ql_dbg_init, vha, 0x00c3, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2964 | "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2965 | eft_size = EFT_SIZE; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2966 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2967 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2968 | if (IS_QLA27XX(ha)) { |
| 2969 | if (!ha->fw_dump_template) { |
| 2970 | ql_log(ql_log_warn, vha, 0x00ba, |
| 2971 | "Failed missing fwdump template\n"); |
| 2972 | return; |
| 2973 | } |
| 2974 | dump_size = qla27xx_fwdt_calculate_dump_size(vha); |
| 2975 | ql_dbg(ql_dbg_init, vha, 0x00fa, |
| 2976 | "-> allocating fwdump (%x bytes)...\n", dump_size); |
| 2977 | goto allocate; |
| 2978 | } |
| 2979 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2980 | req_q_size = req->length * sizeof(request_t); |
| 2981 | rsp_q_size = rsp->length * sizeof(response_t); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2982 | dump_size = offsetof(struct qla2xxx_fw_dump, isp); |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 2983 | 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] | 2984 | ha->chain_offset = dump_size; |
| 2985 | dump_size += mq_size + fce_size; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2986 | |
Quinn Tran | b945e77 | 2017-06-13 20:47:29 -0700 | [diff] [blame] | 2987 | if (ha->exchoffld_buf) |
| 2988 | dump_size += sizeof(struct qla2xxx_offld_chain) + |
| 2989 | ha->exchoffld_size; |
| 2990 | if (ha->exlogin_buf) |
| 2991 | dump_size += sizeof(struct qla2xxx_offld_chain) + |
| 2992 | ha->exlogin_size; |
| 2993 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2994 | allocate: |
Quinn Tran | ad0a0b0 | 2017-12-28 12:33:14 -0800 | [diff] [blame] | 2995 | if (!ha->fw_dump_len || dump_size != ha->fw_dump_len) { |
| 2996 | fw_dump = vmalloc(dump_size); |
| 2997 | if (!fw_dump) { |
| 2998 | ql_log(ql_log_warn, vha, 0x00c4, |
| 2999 | "Unable to allocate (%d KB) for firmware dump.\n", |
| 3000 | dump_size / 1024); |
| 3001 | } else { |
| 3002 | if (ha->fw_dump) |
| 3003 | vfree(ha->fw_dump); |
| 3004 | ha->fw_dump = fw_dump; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 3005 | |
Quinn Tran | ad0a0b0 | 2017-12-28 12:33:14 -0800 | [diff] [blame] | 3006 | ha->fw_dump_len = dump_size; |
| 3007 | ql_dbg(ql_dbg_init, vha, 0x00c5, |
| 3008 | "Allocated (%d KB) for firmware dump.\n", |
| 3009 | dump_size / 1024); |
Madhuranath Iyengar | e30d175 | 2010-10-15 11:27:46 -0700 | [diff] [blame] | 3010 | |
Quinn Tran | ad0a0b0 | 2017-12-28 12:33:14 -0800 | [diff] [blame] | 3011 | if (IS_QLA27XX(ha)) |
| 3012 | return; |
| 3013 | |
| 3014 | ha->fw_dump->signature[0] = 'Q'; |
| 3015 | ha->fw_dump->signature[1] = 'L'; |
| 3016 | ha->fw_dump->signature[2] = 'G'; |
| 3017 | ha->fw_dump->signature[3] = 'C'; |
| 3018 | ha->fw_dump->version = htonl(1); |
| 3019 | |
| 3020 | ha->fw_dump->fixed_size = htonl(fixed_size); |
| 3021 | ha->fw_dump->mem_size = htonl(mem_size); |
| 3022 | ha->fw_dump->req_q_size = htonl(req_q_size); |
| 3023 | ha->fw_dump->rsp_q_size = htonl(rsp_q_size); |
| 3024 | |
| 3025 | ha->fw_dump->eft_size = htonl(eft_size); |
| 3026 | ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma)); |
| 3027 | ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma)); |
| 3028 | |
| 3029 | ha->fw_dump->header_size = |
| 3030 | htonl(offsetof(struct qla2xxx_fw_dump, isp)); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 3031 | } |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 3032 | } |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3033 | } |
| 3034 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 3035 | static int |
| 3036 | qla81xx_mpi_sync(scsi_qla_host_t *vha) |
| 3037 | { |
| 3038 | #define MPS_MASK 0xe0 |
| 3039 | int rval; |
| 3040 | uint16_t dc; |
| 3041 | uint32_t dw; |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 3042 | |
| 3043 | if (!IS_QLA81XX(vha->hw)) |
| 3044 | return QLA_SUCCESS; |
| 3045 | |
| 3046 | rval = qla2x00_write_ram_word(vha, 0x7c00, 1); |
| 3047 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3048 | ql_log(ql_log_warn, vha, 0x0105, |
| 3049 | "Unable to acquire semaphore.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 3050 | goto done; |
| 3051 | } |
| 3052 | |
| 3053 | pci_read_config_word(vha->hw->pdev, 0x54, &dc); |
| 3054 | rval = qla2x00_read_ram_word(vha, 0x7a15, &dw); |
| 3055 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3056 | ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 3057 | goto done_release; |
| 3058 | } |
| 3059 | |
| 3060 | dc &= MPS_MASK; |
| 3061 | if (dc == (dw & MPS_MASK)) |
| 3062 | goto done_release; |
| 3063 | |
| 3064 | dw &= ~MPS_MASK; |
| 3065 | dw |= dc; |
| 3066 | rval = qla2x00_write_ram_word(vha, 0x7a15, dw); |
| 3067 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3068 | ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 3069 | } |
| 3070 | |
| 3071 | done_release: |
| 3072 | rval = qla2x00_write_ram_word(vha, 0x7c00, 0); |
| 3073 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3074 | ql_log(ql_log_warn, vha, 0x006d, |
| 3075 | "Unable to release semaphore.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 3076 | } |
| 3077 | |
| 3078 | done: |
| 3079 | return rval; |
| 3080 | } |
| 3081 | |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 3082 | int |
| 3083 | qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req) |
| 3084 | { |
| 3085 | /* Don't try to reallocate the array */ |
| 3086 | if (req->outstanding_cmds) |
| 3087 | return QLA_SUCCESS; |
| 3088 | |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 3089 | if (!IS_FWI2_CAPABLE(ha)) |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 3090 | req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS; |
| 3091 | else { |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3092 | if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count) |
| 3093 | req->num_outstanding_cmds = ha->cur_fw_xcb_count; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 3094 | else |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3095 | req->num_outstanding_cmds = ha->cur_fw_iocb_count; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 3096 | } |
| 3097 | |
| 3098 | req->outstanding_cmds = kzalloc(sizeof(srb_t *) * |
| 3099 | req->num_outstanding_cmds, GFP_KERNEL); |
| 3100 | |
| 3101 | if (!req->outstanding_cmds) { |
| 3102 | /* |
| 3103 | * Try to allocate a minimal size just so we can get through |
| 3104 | * initialization. |
| 3105 | */ |
| 3106 | req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS; |
| 3107 | req->outstanding_cmds = kzalloc(sizeof(srb_t *) * |
| 3108 | req->num_outstanding_cmds, GFP_KERNEL); |
| 3109 | |
| 3110 | if (!req->outstanding_cmds) { |
| 3111 | ql_log(ql_log_fatal, NULL, 0x0126, |
| 3112 | "Failed to allocate memory for " |
| 3113 | "outstanding_cmds for req_que %p.\n", req); |
| 3114 | req->num_outstanding_cmds = 0; |
| 3115 | return QLA_FUNCTION_FAILED; |
| 3116 | } |
| 3117 | } |
| 3118 | |
| 3119 | return QLA_SUCCESS; |
| 3120 | } |
| 3121 | |
Quinn Tran | e4e3a2c | 2017-08-23 15:05:07 -0700 | [diff] [blame] | 3122 | #define PRINT_FIELD(_field, _flag, _str) { \ |
| 3123 | if (a0->_field & _flag) {\ |
| 3124 | if (p) {\ |
| 3125 | strcat(ptr, "|");\ |
| 3126 | ptr++;\ |
| 3127 | leftover--;\ |
| 3128 | } \ |
| 3129 | len = snprintf(ptr, leftover, "%s", _str); \ |
| 3130 | p = 1;\ |
| 3131 | leftover -= len;\ |
| 3132 | ptr += len; \ |
| 3133 | } \ |
| 3134 | } |
| 3135 | |
| 3136 | static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha) |
| 3137 | { |
| 3138 | #define STR_LEN 64 |
| 3139 | struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data; |
| 3140 | u8 str[STR_LEN], *ptr, p; |
| 3141 | int leftover, len; |
| 3142 | |
| 3143 | memset(str, 0, STR_LEN); |
| 3144 | snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name); |
| 3145 | ql_dbg(ql_dbg_init, vha, 0x015a, |
| 3146 | "SFP MFG Name: %s\n", str); |
| 3147 | |
| 3148 | memset(str, 0, STR_LEN); |
| 3149 | snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn); |
| 3150 | ql_dbg(ql_dbg_init, vha, 0x015c, |
| 3151 | "SFP Part Name: %s\n", str); |
| 3152 | |
| 3153 | /* media */ |
| 3154 | memset(str, 0, STR_LEN); |
| 3155 | ptr = str; |
| 3156 | leftover = STR_LEN; |
| 3157 | p = len = 0; |
| 3158 | PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX"); |
| 3159 | PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair"); |
| 3160 | PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax"); |
| 3161 | PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax"); |
| 3162 | PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um"); |
| 3163 | PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um"); |
| 3164 | PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode"); |
| 3165 | ql_dbg(ql_dbg_init, vha, 0x0160, |
| 3166 | "SFP Media: %s\n", str); |
| 3167 | |
| 3168 | /* link length */ |
| 3169 | memset(str, 0, STR_LEN); |
| 3170 | ptr = str; |
| 3171 | leftover = STR_LEN; |
| 3172 | p = len = 0; |
| 3173 | PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long"); |
| 3174 | PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short"); |
| 3175 | PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate"); |
| 3176 | PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long"); |
| 3177 | PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium"); |
| 3178 | ql_dbg(ql_dbg_init, vha, 0x0196, |
| 3179 | "SFP Link Length: %s\n", str); |
| 3180 | |
| 3181 | memset(str, 0, STR_LEN); |
| 3182 | ptr = str; |
| 3183 | leftover = STR_LEN; |
| 3184 | p = len = 0; |
| 3185 | PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)"); |
| 3186 | PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)"); |
| 3187 | PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)"); |
| 3188 | PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)"); |
| 3189 | PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)"); |
| 3190 | ql_dbg(ql_dbg_init, vha, 0x016e, |
| 3191 | "SFP FC Link Tech: %s\n", str); |
| 3192 | |
| 3193 | if (a0->length_km) |
| 3194 | ql_dbg(ql_dbg_init, vha, 0x016f, |
| 3195 | "SFP Distant: %d km\n", a0->length_km); |
| 3196 | if (a0->length_100m) |
| 3197 | ql_dbg(ql_dbg_init, vha, 0x0170, |
| 3198 | "SFP Distant: %d m\n", a0->length_100m*100); |
| 3199 | if (a0->length_50um_10m) |
| 3200 | ql_dbg(ql_dbg_init, vha, 0x0189, |
| 3201 | "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10); |
| 3202 | if (a0->length_62um_10m) |
| 3203 | ql_dbg(ql_dbg_init, vha, 0x018a, |
| 3204 | "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10); |
| 3205 | if (a0->length_om4_10m) |
| 3206 | ql_dbg(ql_dbg_init, vha, 0x0194, |
| 3207 | "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10); |
| 3208 | if (a0->length_om3_10m) |
| 3209 | ql_dbg(ql_dbg_init, vha, 0x0195, |
| 3210 | "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10); |
| 3211 | } |
| 3212 | |
| 3213 | |
| 3214 | /* |
| 3215 | * Return Code: |
| 3216 | * QLA_SUCCESS: no action |
| 3217 | * QLA_INTERFACE_ERROR: SFP is not there. |
| 3218 | * QLA_FUNCTION_FAILED: detected New SFP |
| 3219 | */ |
| 3220 | int |
| 3221 | qla24xx_detect_sfp(scsi_qla_host_t *vha) |
| 3222 | { |
| 3223 | int rc = QLA_SUCCESS; |
| 3224 | struct sff_8247_a0 *a; |
| 3225 | struct qla_hw_data *ha = vha->hw; |
| 3226 | |
| 3227 | if (!AUTO_DETECT_SFP_SUPPORT(vha)) |
| 3228 | goto out; |
| 3229 | |
| 3230 | rc = qla2x00_read_sfp_dev(vha, NULL, 0); |
| 3231 | if (rc) |
| 3232 | goto out; |
| 3233 | |
| 3234 | a = (struct sff_8247_a0 *)vha->hw->sfp_data; |
| 3235 | qla2xxx_print_sfp_info(vha); |
| 3236 | |
| 3237 | if (a->fc_ll_cc7 & FC_LL_VL || a->fc_ll_cc7 & FC_LL_L) { |
| 3238 | /* long range */ |
| 3239 | ha->flags.detected_lr_sfp = 1; |
| 3240 | |
| 3241 | if (a->length_km > 5 || a->length_100m > 50) |
| 3242 | ha->long_range_distance = LR_DISTANCE_10K; |
| 3243 | else |
| 3244 | ha->long_range_distance = LR_DISTANCE_5K; |
| 3245 | |
| 3246 | if (ha->flags.detected_lr_sfp != ha->flags.using_lr_setting) |
| 3247 | ql_dbg(ql_dbg_async, vha, 0x507b, |
| 3248 | "Detected Long Range SFP.\n"); |
| 3249 | } else { |
| 3250 | /* short range */ |
| 3251 | ha->flags.detected_lr_sfp = 0; |
| 3252 | if (ha->flags.using_lr_setting) |
| 3253 | ql_dbg(ql_dbg_async, vha, 0x5084, |
| 3254 | "Detected Short Range SFP.\n"); |
| 3255 | } |
| 3256 | |
| 3257 | if (!vha->flags.init_done) |
| 3258 | rc = QLA_SUCCESS; |
| 3259 | out: |
| 3260 | return rc; |
| 3261 | } |
| 3262 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3263 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3264 | * qla2x00_setup_chip() - Load and start RISC firmware. |
Bart Van Assche | 2db6228 | 2018-01-23 16:33:51 -0800 | [diff] [blame] | 3265 | * @vha: HA context |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3266 | * |
| 3267 | * Returns 0 on success. |
| 3268 | */ |
| 3269 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3270 | qla2x00_setup_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3271 | { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3272 | int rval; |
| 3273 | uint32_t srisc_address = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3274 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 3275 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 3276 | unsigned long flags; |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 3277 | uint16_t fw_major_version; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 3278 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 3279 | if (IS_P3P_TYPE(ha)) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3280 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 3281 | if (rval == QLA_SUCCESS) { |
| 3282 | qla2x00_stop_firmware(vha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3283 | goto enable_82xx_npiv; |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 3284 | } else |
Giridhar Malavali | b963752 | 2010-05-28 15:08:15 -0700 | [diff] [blame] | 3285 | goto failed; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3286 | } |
| 3287 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 3288 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 3289 | /* Disable SRAM, Instruction RAM and GP RAM parity. */ |
| 3290 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3291 | WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0)); |
| 3292 | RD_REG_WORD(®->hccr); |
| 3293 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3294 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3295 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 3296 | qla81xx_mpi_sync(vha); |
| 3297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3298 | /* Load firmware sequences */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3299 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3300 | if (rval == QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3301 | ql_dbg(ql_dbg_init, vha, 0x00c9, |
| 3302 | "Verifying Checksum of loaded RISC code.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3303 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3304 | rval = qla2x00_verify_checksum(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3305 | if (rval == QLA_SUCCESS) { |
| 3306 | /* Start firmware execution. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3307 | ql_dbg(ql_dbg_init, vha, 0x00ca, |
| 3308 | "Starting firmware.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3309 | |
Himanshu Madhani | b0d6cab | 2015-12-17 14:56:56 -0500 | [diff] [blame] | 3310 | if (ql2xexlogins) |
| 3311 | ha->flags.exlogins_enabled = 1; |
| 3312 | |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 3313 | if (qla_is_exch_offld_enabled(vha)) |
Himanshu Madhani | 2f56a7f | 2015-12-17 14:56:57 -0500 | [diff] [blame] | 3314 | ha->flags.exchoffld_enabled = 1; |
| 3315 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3316 | rval = qla2x00_execute_fw(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3317 | /* Retrieve firmware information. */ |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 3318 | if (rval == QLA_SUCCESS) { |
Quinn Tran | e4e3a2c | 2017-08-23 15:05:07 -0700 | [diff] [blame] | 3319 | qla24xx_detect_sfp(vha); |
| 3320 | |
Himanshu Madhani | b0d6cab | 2015-12-17 14:56:56 -0500 | [diff] [blame] | 3321 | rval = qla2x00_set_exlogins_buffer(vha); |
| 3322 | if (rval != QLA_SUCCESS) |
| 3323 | goto failed; |
| 3324 | |
Himanshu Madhani | 2f56a7f | 2015-12-17 14:56:57 -0500 | [diff] [blame] | 3325 | rval = qla2x00_set_exchoffld_buffer(vha); |
| 3326 | if (rval != QLA_SUCCESS) |
| 3327 | goto failed; |
| 3328 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3329 | enable_82xx_npiv: |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 3330 | fw_major_version = ha->fw_major_version; |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 3331 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | 3173167 | 2011-08-16 11:31:54 -0700 | [diff] [blame] | 3332 | qla82xx_check_md_needed(vha); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3333 | else |
| 3334 | rval = qla2x00_get_fw_version(vha); |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 3335 | if (rval != QLA_SUCCESS) |
| 3336 | goto failed; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3337 | ha->flags.npiv_supported = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3338 | if (IS_QLA2XXX_MIDTYPE(ha) && |
Mike Hernandez | 946fb89 | 2008-08-13 21:36:59 -0700 | [diff] [blame] | 3339 | (ha->fw_attributes & BIT_2)) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3340 | ha->flags.npiv_supported = 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 3341 | if ((!ha->max_npiv_vports) || |
| 3342 | ((ha->max_npiv_vports + 1) % |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 3343 | MIN_MULTI_ID_FABRIC)) |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 3344 | ha->max_npiv_vports = |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 3345 | MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 3346 | } |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3347 | qla2x00_get_resource_cnts(vha); |
Andrew Vasquez | d743de6 | 2009-03-24 09:08:15 -0700 | [diff] [blame] | 3348 | |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 3349 | /* |
| 3350 | * Allocate the array of outstanding commands |
| 3351 | * now that we know the firmware resources. |
| 3352 | */ |
| 3353 | rval = qla2x00_alloc_outstanding_cmds(ha, |
| 3354 | vha->req); |
| 3355 | if (rval != QLA_SUCCESS) |
| 3356 | goto failed; |
| 3357 | |
Quinn Tran | ad0a0b0 | 2017-12-28 12:33:14 -0800 | [diff] [blame] | 3358 | if (!fw_major_version && !(IS_P3P_TYPE(ha))) |
| 3359 | qla2x00_alloc_offload_mem(vha); |
| 3360 | |
| 3361 | if (ql2xallocfwdump && !(IS_P3P_TYPE(ha))) |
Giridhar Malavali | 08de284 | 2011-08-16 11:31:44 -0700 | [diff] [blame] | 3362 | qla2x00_alloc_fw_dump(vha); |
Quinn Tran | ad0a0b0 | 2017-12-28 12:33:14 -0800 | [diff] [blame] | 3363 | |
Chad Dupuis | 3b6e5b9 | 2013-10-30 03:38:09 -0400 | [diff] [blame] | 3364 | } else { |
| 3365 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3366 | } |
| 3367 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3368 | ql_log(ql_log_fatal, vha, 0x00cd, |
| 3369 | "ISP Firmware failed checksum.\n"); |
| 3370 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3371 | } |
Andrew Vasquez | c74d88a | 2012-08-22 14:21:19 -0400 | [diff] [blame] | 3372 | } else |
| 3373 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3374 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 3375 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 3376 | /* Enable proper parity. */ |
| 3377 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3378 | if (IS_QLA2300(ha)) |
| 3379 | /* SRAM parity */ |
| 3380 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1); |
| 3381 | else |
| 3382 | /* SRAM, Instruction RAM and GP RAM parity */ |
| 3383 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7); |
| 3384 | RD_REG_WORD(®->hccr); |
| 3385 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3386 | } |
| 3387 | |
Chad Dupuis | f3982d8 | 2014-09-25 05:16:57 -0400 | [diff] [blame] | 3388 | if (IS_QLA27XX(ha)) |
| 3389 | ha->flags.fac_supported = 1; |
| 3390 | else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) { |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 3391 | uint32_t size; |
| 3392 | |
| 3393 | rval = qla81xx_fac_get_sector_size(vha, &size); |
| 3394 | if (rval == QLA_SUCCESS) { |
| 3395 | ha->flags.fac_supported = 1; |
| 3396 | ha->fdt_block_size = size << 2; |
| 3397 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3398 | ql_log(ql_log_warn, vha, 0x00ce, |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 3399 | "Unsupported FAC firmware (%d.%02d.%02d).\n", |
| 3400 | ha->fw_major_version, ha->fw_minor_version, |
| 3401 | ha->fw_subminor_version); |
Joe Carnuccio | 1ca60e3 | 2014-02-26 04:15:02 -0500 | [diff] [blame] | 3402 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 3403 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3404 | ha->flags.fac_supported = 0; |
| 3405 | rval = QLA_SUCCESS; |
| 3406 | } |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 3407 | } |
| 3408 | } |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 3409 | failed: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3410 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3411 | ql_log(ql_log_fatal, vha, 0x00cf, |
| 3412 | "Setup chip ****FAILED****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3413 | } |
| 3414 | |
| 3415 | return (rval); |
| 3416 | } |
| 3417 | |
| 3418 | /** |
| 3419 | * qla2x00_init_response_q_entries() - Initializes response queue entries. |
Bart Van Assche | 2db6228 | 2018-01-23 16:33:51 -0800 | [diff] [blame] | 3420 | * @rsp: response queue |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | * |
| 3422 | * Beginning of request ring has initialization control block already built |
| 3423 | * by nvram config routine. |
| 3424 | * |
| 3425 | * Returns 0 on success. |
| 3426 | */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3427 | void |
| 3428 | qla2x00_init_response_q_entries(struct rsp_que *rsp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3429 | { |
| 3430 | uint16_t cnt; |
| 3431 | response_t *pkt; |
| 3432 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 3433 | rsp->ring_ptr = rsp->ring; |
| 3434 | rsp->ring_index = 0; |
| 3435 | rsp->status_srb = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3436 | pkt = rsp->ring_ptr; |
| 3437 | for (cnt = 0; cnt < rsp->length; cnt++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3438 | pkt->signature = RESPONSE_PROCESSED; |
| 3439 | pkt++; |
| 3440 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3441 | } |
| 3442 | |
| 3443 | /** |
| 3444 | * qla2x00_update_fw_options() - Read and process firmware options. |
Bart Van Assche | 2db6228 | 2018-01-23 16:33:51 -0800 | [diff] [blame] | 3445 | * @vha: HA context |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3446 | * |
| 3447 | * Returns 0 on success. |
| 3448 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3449 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3450 | qla2x00_update_fw_options(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3451 | { |
| 3452 | uint16_t swing, emphasis, tx_sens, rx_sens; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3453 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3454 | |
| 3455 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3456 | qla2x00_get_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3457 | |
| 3458 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
| 3459 | return; |
| 3460 | |
| 3461 | /* Serial Link options. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3462 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115, |
| 3463 | "Serial link options.\n"); |
| 3464 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109, |
| 3465 | (uint8_t *)&ha->fw_seriallink_options, |
| 3466 | sizeof(ha->fw_seriallink_options)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3467 | |
| 3468 | ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING; |
| 3469 | if (ha->fw_seriallink_options[3] & BIT_2) { |
| 3470 | ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING; |
| 3471 | |
| 3472 | /* 1G settings */ |
| 3473 | swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0); |
| 3474 | emphasis = (ha->fw_seriallink_options[2] & |
| 3475 | (BIT_4 | BIT_3)) >> 3; |
| 3476 | tx_sens = ha->fw_seriallink_options[0] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3477 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | rx_sens = (ha->fw_seriallink_options[0] & |
| 3479 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 3480 | ha->fw_options[10] = (emphasis << 14) | (swing << 8); |
| 3481 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 3482 | if (rx_sens == 0x0) |
| 3483 | rx_sens = 0x3; |
| 3484 | ha->fw_options[10] |= (tx_sens << 4) | rx_sens; |
| 3485 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 3486 | ha->fw_options[10] |= BIT_5 | |
| 3487 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 3488 | (tx_sens & (BIT_1 | BIT_0)); |
| 3489 | |
| 3490 | /* 2G settings */ |
| 3491 | swing = (ha->fw_seriallink_options[2] & |
| 3492 | (BIT_7 | BIT_6 | BIT_5)) >> 5; |
| 3493 | emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0); |
| 3494 | tx_sens = ha->fw_seriallink_options[1] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3495 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3496 | rx_sens = (ha->fw_seriallink_options[1] & |
| 3497 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 3498 | ha->fw_options[11] = (emphasis << 14) | (swing << 8); |
| 3499 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 3500 | if (rx_sens == 0x0) |
| 3501 | rx_sens = 0x3; |
| 3502 | ha->fw_options[11] |= (tx_sens << 4) | rx_sens; |
| 3503 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 3504 | ha->fw_options[11] |= BIT_5 | |
| 3505 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 3506 | (tx_sens & (BIT_1 | BIT_0)); |
| 3507 | } |
| 3508 | |
| 3509 | /* FCP2 options. */ |
| 3510 | /* Return command IOCBs without waiting for an ABTS to complete. */ |
| 3511 | ha->fw_options[3] |= BIT_13; |
| 3512 | |
| 3513 | /* LED scheme. */ |
| 3514 | if (ha->flags.enable_led_scheme) |
| 3515 | ha->fw_options[2] |= BIT_12; |
| 3516 | |
andrew.vasquez@qlogic.com | 48c02fd | 2006-03-09 14:27:18 -0800 | [diff] [blame] | 3517 | /* Detect ISP6312. */ |
| 3518 | if (IS_QLA6312(ha)) |
| 3519 | ha->fw_options[2] |= BIT_13; |
| 3520 | |
Giridhar Malavali | 088d09d | 2016-07-06 11:14:20 -0400 | [diff] [blame] | 3521 | /* Set Retry FLOGI in case of P2P connection */ |
| 3522 | if (ha->operating_mode == P2P) { |
| 3523 | ha->fw_options[2] |= BIT_3; |
| 3524 | ql_dbg(ql_dbg_disc, vha, 0x2100, |
| 3525 | "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n", |
| 3526 | __func__, ha->fw_options[2]); |
| 3527 | } |
| 3528 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3529 | /* Update firmware options. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3530 | qla2x00_set_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3531 | } |
| 3532 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3533 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3534 | qla24xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3535 | { |
| 3536 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3537 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3538 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 3539 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3540 | return; |
| 3541 | |
Himanshu Madhani | f198caf | 2016-01-27 12:03:30 -0500 | [diff] [blame] | 3542 | /* Hold status IOCBs until ABTS response received. */ |
| 3543 | if (ql2xfwholdabts) |
| 3544 | ha->fw_options[3] |= BIT_12; |
| 3545 | |
Giridhar Malavali | 088d09d | 2016-07-06 11:14:20 -0400 | [diff] [blame] | 3546 | /* Set Retry FLOGI in case of P2P connection */ |
| 3547 | if (ha->operating_mode == P2P) { |
| 3548 | ha->fw_options[2] |= BIT_3; |
| 3549 | ql_dbg(ql_dbg_disc, vha, 0x2101, |
| 3550 | "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n", |
| 3551 | __func__, ha->fw_options[2]); |
| 3552 | } |
| 3553 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 3554 | /* Move PUREX, ABTS RX & RIDA to ATIOQ */ |
Quinn Tran | 3c4810f | 2017-06-02 09:11:53 -0700 | [diff] [blame] | 3555 | if (ql2xmvasynctoatio && |
| 3556 | (IS_QLA83XX(ha) || IS_QLA27XX(ha))) { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 3557 | if (qla_tgt_mode_enabled(vha) || |
| 3558 | qla_dual_mode_enabled(vha)) |
| 3559 | ha->fw_options[2] |= BIT_11; |
| 3560 | else |
| 3561 | ha->fw_options[2] &= ~BIT_11; |
| 3562 | } |
| 3563 | |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 3564 | if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
| 3565 | /* |
| 3566 | * Tell FW to track each exchange to prevent |
| 3567 | * driver from using stale exchange. |
| 3568 | */ |
| 3569 | if (qla_tgt_mode_enabled(vha) || |
| 3570 | qla_dual_mode_enabled(vha)) |
| 3571 | ha->fw_options[2] |= BIT_4; |
| 3572 | else |
| 3573 | ha->fw_options[2] &= ~BIT_4; |
Quinn Tran | 9ecf0b0 | 2017-12-28 12:33:19 -0800 | [diff] [blame] | 3574 | |
| 3575 | /* Reserve 1/2 of emergency exchanges for ELS.*/ |
| 3576 | if (qla2xuseresexchforels) |
| 3577 | ha->fw_options[2] |= BIT_8; |
| 3578 | else |
| 3579 | ha->fw_options[2] &= ~BIT_8; |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 3580 | } |
| 3581 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3582 | ql_dbg(ql_dbg_init, vha, 0x00e8, |
| 3583 | "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n", |
| 3584 | __func__, ha->fw_options[1], ha->fw_options[2], |
| 3585 | ha->fw_options[3], vha->host->active_mode); |
Quinn Tran | 3c4810f | 2017-06-02 09:11:53 -0700 | [diff] [blame] | 3586 | |
| 3587 | if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3]) |
| 3588 | qla2x00_set_fw_options(vha, ha->fw_options); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 3589 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3590 | /* Update Serial Link options. */ |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 3591 | if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3592 | return; |
| 3593 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3594 | rval = qla2x00_set_serdes_params(vha, |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 3595 | le16_to_cpu(ha->fw_seriallink_options24[1]), |
| 3596 | le16_to_cpu(ha->fw_seriallink_options24[2]), |
| 3597 | le16_to_cpu(ha->fw_seriallink_options24[3])); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3598 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3599 | ql_log(ql_log_warn, vha, 0x0104, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3600 | "Unable to update Serial Link options (%x).\n", rval); |
| 3601 | } |
| 3602 | } |
| 3603 | |
| 3604 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3605 | qla2x00_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3606 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3607 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 3608 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3609 | struct req_que *req = ha->req_q_map[0]; |
| 3610 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3611 | |
| 3612 | /* Setup ring parameters in initialization control block. */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3613 | ha->init_cb->request_q_outpointer = cpu_to_le16(0); |
| 3614 | ha->init_cb->response_q_inpointer = cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3615 | ha->init_cb->request_q_length = cpu_to_le16(req->length); |
| 3616 | ha->init_cb->response_q_length = cpu_to_le16(rsp->length); |
| 3617 | ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 3618 | ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 3619 | ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 3620 | 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] | 3621 | |
| 3622 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0); |
| 3623 | WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0); |
| 3624 | WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0); |
| 3625 | WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0); |
| 3626 | RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */ |
| 3627 | } |
| 3628 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3629 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3630 | qla24xx_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3631 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3632 | struct qla_hw_data *ha = vha->hw; |
Bart Van Assche | 118e2ef | 2015-07-09 07:24:27 -0700 | [diff] [blame] | 3633 | device_reg_t *reg = ISP_QUE_REG(ha, 0); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3634 | struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp; |
| 3635 | struct qla_msix_entry *msix; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3636 | struct init_cb_24xx *icb; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3637 | uint16_t rid = 0; |
| 3638 | struct req_que *req = ha->req_q_map[0]; |
| 3639 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3640 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3641 | /* Setup ring parameters in initialization control block. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3642 | icb = (struct init_cb_24xx *)ha->init_cb; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3643 | icb->request_q_outpointer = cpu_to_le16(0); |
| 3644 | icb->response_q_inpointer = cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3645 | icb->request_q_length = cpu_to_le16(req->length); |
| 3646 | icb->response_q_length = cpu_to_le16(rsp->length); |
| 3647 | icb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 3648 | icb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 3649 | icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 3650 | icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3651 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3652 | /* Setup ATIO queue dma pointers for target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3653 | icb->atio_q_inpointer = cpu_to_le16(0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3654 | icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length); |
| 3655 | icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma)); |
| 3656 | icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma)); |
| 3657 | |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3658 | if (IS_SHADOW_REG_CAPABLE(ha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3659 | icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29); |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3660 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 3661 | if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3662 | icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS); |
| 3663 | icb->rid = cpu_to_le16(rid); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3664 | if (ha->flags.msix_enabled) { |
| 3665 | msix = &ha->msix_entries[1]; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3666 | ql_dbg(ql_dbg_init, vha, 0x0019, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3667 | "Registering vector 0x%x for base que.\n", |
| 3668 | msix->entry); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3669 | icb->msix = cpu_to_le16(msix->entry); |
| 3670 | } |
| 3671 | /* Use alternate PCI bus number */ |
| 3672 | if (MSB(rid)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3673 | icb->firmware_options_2 |= cpu_to_le32(BIT_19); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3674 | /* Use alternate PCI devfn */ |
| 3675 | if (LSB(rid)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3676 | icb->firmware_options_2 |= cpu_to_le32(BIT_18); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3677 | |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 3678 | /* Use Disable MSIX Handshake mode for capable adapters */ |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3679 | if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) && |
| 3680 | (ha->flags.msix_enabled)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3681 | icb->firmware_options_2 &= cpu_to_le32(~BIT_22); |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 3682 | ha->flags.disable_msix_handshake = 1; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3683 | ql_dbg(ql_dbg_init, vha, 0x00fe, |
| 3684 | "MSIX Handshake Disable Mode turned on.\n"); |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 3685 | } else { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3686 | icb->firmware_options_2 |= cpu_to_le32(BIT_22); |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 3687 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3688 | icb->firmware_options_2 |= cpu_to_le32(BIT_23); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3689 | |
| 3690 | WRT_REG_DWORD(®->isp25mq.req_q_in, 0); |
| 3691 | WRT_REG_DWORD(®->isp25mq.req_q_out, 0); |
| 3692 | WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0); |
| 3693 | WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0); |
| 3694 | } else { |
| 3695 | WRT_REG_DWORD(®->isp24.req_q_in, 0); |
| 3696 | WRT_REG_DWORD(®->isp24.req_q_out, 0); |
| 3697 | WRT_REG_DWORD(®->isp24.rsp_q_in, 0); |
| 3698 | WRT_REG_DWORD(®->isp24.rsp_q_out, 0); |
| 3699 | } |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 3700 | qlt_24xx_config_rings(vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3701 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3702 | /* PCI posting */ |
| 3703 | RD_REG_DWORD(&ioreg->hccr); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3704 | } |
| 3705 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3706 | /** |
| 3707 | * qla2x00_init_rings() - Initializes firmware. |
Bart Van Assche | 2db6228 | 2018-01-23 16:33:51 -0800 | [diff] [blame] | 3708 | * @vha: HA context |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3709 | * |
| 3710 | * Beginning of request ring has initialization control block already built |
| 3711 | * by nvram config routine. |
| 3712 | * |
| 3713 | * Returns 0 on success. |
| 3714 | */ |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3715 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3716 | qla2x00_init_rings(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3717 | { |
| 3718 | int rval; |
| 3719 | unsigned long flags = 0; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3720 | int cnt, que; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3721 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3722 | struct req_que *req; |
| 3723 | struct rsp_que *rsp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3724 | struct mid_init_cb_24xx *mid_init_cb = |
| 3725 | (struct mid_init_cb_24xx *) ha->init_cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3726 | |
| 3727 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3728 | |
| 3729 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 3730 | for (que = 0; que < ha->max_req_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3731 | req = ha->req_q_map[que]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 3732 | if (!req || !test_bit(que, ha->req_qid_map)) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3733 | continue; |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3734 | req->out_ptr = (void *)(req->ring + req->length); |
| 3735 | *req->out_ptr = 0; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 3736 | for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3737 | req->outstanding_cmds[cnt] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3738 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 3739 | req->current_outstanding_cmd = 1; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3740 | |
| 3741 | /* Initialize firmware. */ |
| 3742 | req->ring_ptr = req->ring; |
| 3743 | req->ring_index = 0; |
| 3744 | req->cnt = req->length; |
| 3745 | } |
| 3746 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 3747 | for (que = 0; que < ha->max_rsp_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3748 | rsp = ha->rsp_q_map[que]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 3749 | if (!rsp || !test_bit(que, ha->rsp_qid_map)) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3750 | continue; |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3751 | rsp->in_ptr = (void *)(rsp->ring + rsp->length); |
| 3752 | *rsp->in_ptr = 0; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3753 | /* Initialize response queue entries */ |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3754 | if (IS_QLAFX00(ha)) |
| 3755 | qlafx00_init_response_q_entries(rsp); |
| 3756 | else |
| 3757 | qla2x00_init_response_q_entries(rsp); |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3758 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3759 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3760 | ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; |
| 3761 | ha->tgt.atio_ring_index = 0; |
| 3762 | /* Initialize ATIO queue entries */ |
| 3763 | qlt_init_atio_q_entries(vha); |
| 3764 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3765 | ha->isp_ops->config_rings(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3766 | |
| 3767 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3768 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3769 | ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n"); |
| 3770 | |
| 3771 | if (IS_QLAFX00(ha)) { |
| 3772 | rval = qlafx00_init_firmware(vha, ha->init_cb_size); |
| 3773 | goto next_check; |
| 3774 | } |
| 3775 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3776 | /* Update any ISP specific firmware options before initialization. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3777 | ha->isp_ops->update_fw_options(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3778 | |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 3779 | if (ha->flags.npiv_supported) { |
Saurav Kashyap | 45980cc | 2012-08-22 14:21:21 -0400 | [diff] [blame] | 3780 | if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha)) |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 3781 | ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | c48339d | 2008-01-17 09:02:19 -0800 | [diff] [blame] | 3782 | mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports); |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 3783 | } |
| 3784 | |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 3785 | if (IS_FWI2_CAPABLE(ha)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3786 | mid_init_cb->options = cpu_to_le16(BIT_1); |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 3787 | mid_init_cb->init_cb.execution_throttle = |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3788 | cpu_to_le16(ha->cur_fw_xcb_count); |
Joe Carnuccio | 40f3862 | 2016-07-06 11:14:28 -0400 | [diff] [blame] | 3789 | ha->flags.dport_enabled = |
| 3790 | (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0; |
| 3791 | ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n", |
| 3792 | (ha->flags.dport_enabled) ? "enabled" : "disabled"); |
| 3793 | /* FA-WWPN Status */ |
Himanshu Madhani | 2486c62 | 2014-09-25 05:17:00 -0400 | [diff] [blame] | 3794 | ha->flags.fawwpn_enabled = |
Joe Carnuccio | 40f3862 | 2016-07-06 11:14:28 -0400 | [diff] [blame] | 3795 | (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3796 | ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n", |
Himanshu Madhani | 2486c62 | 2014-09-25 05:17:00 -0400 | [diff] [blame] | 3797 | (ha->flags.fawwpn_enabled) ? "enabled" : "disabled"); |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 3798 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3799 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3800 | rval = qla2x00_init_firmware(vha, ha->init_cb_size); |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3801 | next_check: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3802 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3803 | ql_log(ql_log_fatal, vha, 0x00d2, |
| 3804 | "Init Firmware **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3805 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3806 | ql_dbg(ql_dbg_init, vha, 0x00d3, |
| 3807 | "Init Firmware -- success.\n"); |
Quinn Tran | 4b60c82 | 2017-06-13 20:47:21 -0700 | [diff] [blame] | 3808 | QLA_FW_STARTED(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3809 | } |
| 3810 | |
| 3811 | return (rval); |
| 3812 | } |
| 3813 | |
| 3814 | /** |
| 3815 | * qla2x00_fw_ready() - Waits for firmware ready. |
Bart Van Assche | 2db6228 | 2018-01-23 16:33:51 -0800 | [diff] [blame] | 3816 | * @vha: HA context |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3817 | * |
| 3818 | * Returns 0 on success. |
| 3819 | */ |
| 3820 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3821 | qla2x00_fw_ready(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3822 | { |
| 3823 | int rval; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3824 | unsigned long wtime, mtime, cs84xx_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3825 | uint16_t min_wait; /* Minimum wait time if loop is down */ |
| 3826 | uint16_t wait_time; /* Wait time if loop is coming ready */ |
Joe Carnuccio | b5a340d | 2014-09-25 05:16:48 -0400 | [diff] [blame] | 3827 | uint16_t state[6]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3828 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3829 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3830 | if (IS_QLAFX00(vha->hw)) |
| 3831 | return qlafx00_fw_ready(vha); |
| 3832 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3833 | rval = QLA_SUCCESS; |
| 3834 | |
Chad Dupuis | 33461491 | 2015-04-09 14:59:57 -0400 | [diff] [blame] | 3835 | /* Time to wait for loop down */ |
| 3836 | if (IS_P3P_TYPE(ha)) |
| 3837 | min_wait = 30; |
| 3838 | else |
| 3839 | min_wait = 20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3840 | |
| 3841 | /* |
| 3842 | * Firmware should take at most one RATOV to login, plus 5 seconds for |
| 3843 | * our own processing. |
| 3844 | */ |
| 3845 | if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) { |
| 3846 | wait_time = min_wait; |
| 3847 | } |
| 3848 | |
| 3849 | /* Min wait time if loop down */ |
| 3850 | mtime = jiffies + (min_wait * HZ); |
| 3851 | |
| 3852 | /* wait time before firmware ready */ |
| 3853 | wtime = jiffies + (wait_time * HZ); |
| 3854 | |
| 3855 | /* Wait for ISP to finish LIP */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3856 | if (!vha->flags.init_done) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3857 | ql_log(ql_log_info, vha, 0x801e, |
| 3858 | "Waiting for LIP to complete.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3859 | |
| 3860 | do { |
Andrew Vasquez | 5b93903 | 2012-11-21 02:40:26 -0500 | [diff] [blame] | 3861 | memset(state, -1, sizeof(state)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3862 | rval = qla2x00_get_firmware_state(vha, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3863 | if (rval == QLA_SUCCESS) { |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3864 | if (state[0] < FSTATE_LOSS_OF_SYNC) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3865 | vha->device_flags &= ~DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3866 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3867 | if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3868 | ql_dbg(ql_dbg_taskm, vha, 0x801f, |
| 3869 | "fw_state=%x 84xx=%x.\n", state[0], |
| 3870 | state[2]); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3871 | if ((state[2] & FSTATE_LOGGED_IN) && |
| 3872 | (state[2] & FSTATE_WAITING_FOR_VERIFY)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3873 | ql_dbg(ql_dbg_taskm, vha, 0x8028, |
| 3874 | "Sending verify iocb.\n"); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3875 | |
| 3876 | cs84xx_time = jiffies; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3877 | rval = qla84xx_init_chip(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3878 | if (rval != QLA_SUCCESS) { |
| 3879 | ql_log(ql_log_warn, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 3880 | vha, 0x8007, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3881 | "Init chip failed.\n"); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3882 | break; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3883 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3884 | |
| 3885 | /* Add time taken to initialize. */ |
| 3886 | cs84xx_time = jiffies - cs84xx_time; |
| 3887 | wtime += cs84xx_time; |
| 3888 | mtime += cs84xx_time; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 3889 | ql_dbg(ql_dbg_taskm, vha, 0x8008, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3890 | "Increasing wait time by %ld. " |
| 3891 | "New time %ld.\n", cs84xx_time, |
| 3892 | wtime); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3893 | } |
| 3894 | } else if (state[0] == FSTATE_READY) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3895 | ql_dbg(ql_dbg_taskm, vha, 0x8037, |
| 3896 | "F/W Ready - OK.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3897 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3898 | qla2x00_get_retry_cnt(vha, &ha->retry_count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3899 | &ha->login_timeout, &ha->r_a_tov); |
| 3900 | |
| 3901 | rval = QLA_SUCCESS; |
| 3902 | break; |
| 3903 | } |
| 3904 | |
| 3905 | rval = QLA_FUNCTION_FAILED; |
| 3906 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3907 | if (atomic_read(&vha->loop_down_timer) && |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3908 | state[0] != FSTATE_READY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3909 | /* Loop down. Timeout on min_wait for states |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3910 | * other than Wait for Login. |
| 3911 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3912 | if (time_after_eq(jiffies, mtime)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3913 | ql_log(ql_log_info, vha, 0x8038, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3914 | "Cable is unplugged...\n"); |
| 3915 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3916 | vha->device_flags |= DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3917 | break; |
| 3918 | } |
| 3919 | } |
| 3920 | } else { |
| 3921 | /* Mailbox cmd failed. Timeout on min_wait. */ |
Santosh Vernekar | cdbb0a4f | 2010-05-28 15:08:25 -0700 | [diff] [blame] | 3922 | if (time_after_eq(jiffies, mtime) || |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 3923 | ha->flags.isp82xx_fw_hung) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3924 | break; |
| 3925 | } |
| 3926 | |
| 3927 | if (time_after_eq(jiffies, wtime)) |
| 3928 | break; |
| 3929 | |
| 3930 | /* Delay for a while */ |
| 3931 | msleep(500); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3932 | } while (1); |
| 3933 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3934 | ql_dbg(ql_dbg_taskm, vha, 0x803a, |
Joe Carnuccio | b5a340d | 2014-09-25 05:16:48 -0400 | [diff] [blame] | 3935 | "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0], |
| 3936 | state[1], state[2], state[3], state[4], state[5], jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3937 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 3938 | if (rval && !(vha->device_flags & DFLG_NO_CABLE)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3939 | ql_log(ql_log_warn, vha, 0x803b, |
| 3940 | "Firmware ready **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3941 | } |
| 3942 | |
| 3943 | return (rval); |
| 3944 | } |
| 3945 | |
| 3946 | /* |
| 3947 | * qla2x00_configure_hba |
| 3948 | * Setup adapter context. |
| 3949 | * |
| 3950 | * Input: |
| 3951 | * ha = adapter state pointer. |
| 3952 | * |
| 3953 | * Returns: |
| 3954 | * 0 = success |
| 3955 | * |
| 3956 | * Context: |
| 3957 | * Kernel context. |
| 3958 | */ |
| 3959 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3960 | qla2x00_configure_hba(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3961 | { |
| 3962 | int rval; |
| 3963 | uint16_t loop_id; |
| 3964 | uint16_t topo; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3965 | uint16_t sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3966 | uint8_t al_pa; |
| 3967 | uint8_t area; |
| 3968 | uint8_t domain; |
| 3969 | char connect_type[22]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3970 | struct qla_hw_data *ha = vha->hw; |
Joe Carnuccio | 61e1b26 | 2013-02-08 01:57:48 -0500 | [diff] [blame] | 3971 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 3972 | port_id_t id; |
Quinn Tran | 9d1aa4e | 2017-12-28 12:33:27 -0800 | [diff] [blame] | 3973 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3974 | |
| 3975 | /* Get host addresses. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3976 | rval = qla2x00_get_adapter_id(vha, |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3977 | &loop_id, &al_pa, &area, &domain, &topo, &sw_cap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3978 | if (rval != QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3979 | if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) || |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3980 | IS_CNA_CAPABLE(ha) || |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 3981 | (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3982 | ql_dbg(ql_dbg_disc, vha, 0x2008, |
| 3983 | "Loop is in a transition state.\n"); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 3984 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3985 | ql_log(ql_log_warn, vha, 0x2009, |
| 3986 | "Unable to get host loop ID.\n"); |
Joe Carnuccio | 61e1b26 | 2013-02-08 01:57:48 -0500 | [diff] [blame] | 3987 | if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) && |
| 3988 | (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) { |
| 3989 | ql_log(ql_log_warn, vha, 0x1151, |
| 3990 | "Doing link init.\n"); |
| 3991 | if (qla24xx_link_initialize(vha) == QLA_SUCCESS) |
| 3992 | return rval; |
| 3993 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3994 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 3995 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3996 | return (rval); |
| 3997 | } |
| 3998 | |
| 3999 | if (topo == 4) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4000 | ql_log(ql_log_info, vha, 0x200a, |
| 4001 | "Cannot get topology - retrying.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4002 | return (QLA_FUNCTION_FAILED); |
| 4003 | } |
| 4004 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4005 | vha->loop_id = loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4006 | |
| 4007 | /* initialize */ |
| 4008 | ha->min_external_loopid = SNS_FIRST_LOOP_ID; |
| 4009 | ha->operating_mode = LOOP; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4010 | ha->switch_cap = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4011 | |
| 4012 | switch (topo) { |
| 4013 | case 0: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4014 | ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4015 | ha->current_topology = ISP_CFG_NL; |
| 4016 | strcpy(connect_type, "(Loop)"); |
| 4017 | break; |
| 4018 | |
| 4019 | case 1: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4020 | ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n"); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4021 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4022 | ha->current_topology = ISP_CFG_FL; |
| 4023 | strcpy(connect_type, "(FL_Port)"); |
| 4024 | break; |
| 4025 | |
| 4026 | case 2: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4027 | 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] | 4028 | ha->operating_mode = P2P; |
| 4029 | ha->current_topology = ISP_CFG_N; |
| 4030 | strcpy(connect_type, "(N_Port-to-N_Port)"); |
| 4031 | break; |
| 4032 | |
| 4033 | case 3: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4034 | 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] | 4035 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4036 | ha->operating_mode = P2P; |
| 4037 | ha->current_topology = ISP_CFG_F; |
| 4038 | strcpy(connect_type, "(F_Port)"); |
| 4039 | break; |
| 4040 | |
| 4041 | default: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4042 | ql_dbg(ql_dbg_disc, vha, 0x200f, |
| 4043 | "HBA in unknown topology %x, using NL.\n", topo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4044 | ha->current_topology = ISP_CFG_NL; |
| 4045 | strcpy(connect_type, "(Loop)"); |
| 4046 | break; |
| 4047 | } |
| 4048 | |
| 4049 | /* Save Host port and loop ID. */ |
| 4050 | /* byte order - Big Endian */ |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 4051 | id.b.domain = domain; |
| 4052 | id.b.area = area; |
| 4053 | id.b.al_pa = al_pa; |
| 4054 | id.b.rsvd_1 = 0; |
Quinn Tran | 9d1aa4e | 2017-12-28 12:33:27 -0800 | [diff] [blame] | 4055 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 4056 | qlt_update_host_map(vha, id); |
Quinn Tran | 9d1aa4e | 2017-12-28 12:33:27 -0800 | [diff] [blame] | 4057 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4058 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4059 | if (!vha->flags.init_done) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4060 | ql_log(ql_log_info, vha, 0x2010, |
| 4061 | "Topology - %s, Host Loop address 0x%x.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4062 | connect_type, vha->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4063 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4064 | return(rval); |
| 4065 | } |
| 4066 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4067 | inline void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4068 | qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len, |
| 4069 | char *def) |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 4070 | { |
| 4071 | char *st, *en; |
| 4072 | uint16_t index; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4073 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | ab67114 | 2009-08-25 11:36:17 -0700 | [diff] [blame] | 4074 | int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) && |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 4075 | !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 4076 | |
| 4077 | if (memcmp(model, BINZERO, len) != 0) { |
| 4078 | strncpy(ha->model_number, model, len); |
| 4079 | st = en = ha->model_number; |
| 4080 | en += len - 1; |
| 4081 | while (en > st) { |
| 4082 | if (*en != 0x20 && *en != 0x00) |
| 4083 | break; |
| 4084 | *en-- = '\0'; |
| 4085 | } |
| 4086 | |
| 4087 | index = (ha->pdev->subsystem_device & 0xff); |
Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 4088 | if (use_tbl && |
| 4089 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 4090 | index < QLA_MODEL_NAMES) |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 4091 | strncpy(ha->model_desc, |
| 4092 | qla2x00_model_name[index * 2 + 1], |
| 4093 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 4094 | } else { |
| 4095 | index = (ha->pdev->subsystem_device & 0xff); |
Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 4096 | if (use_tbl && |
| 4097 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 4098 | index < QLA_MODEL_NAMES) { |
| 4099 | strcpy(ha->model_number, |
| 4100 | qla2x00_model_name[index * 2]); |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 4101 | strncpy(ha->model_desc, |
| 4102 | qla2x00_model_name[index * 2 + 1], |
| 4103 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 4104 | } else { |
| 4105 | strcpy(ha->model_number, def); |
| 4106 | } |
| 4107 | } |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 4108 | if (IS_FWI2_CAPABLE(ha)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4109 | qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc, |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 4110 | sizeof(ha->model_desc)); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 4111 | } |
| 4112 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4113 | /* On sparc systems, obtain port and node WWN from firmware |
| 4114 | * properties. |
| 4115 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4116 | 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] | 4117 | { |
| 4118 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4119 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4120 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 4121 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 4122 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4123 | int len; |
| 4124 | |
| 4125 | val = of_get_property(dp, "port-wwn", &len); |
| 4126 | if (val && len >= WWN_SIZE) |
| 4127 | memcpy(nv->port_name, val, WWN_SIZE); |
| 4128 | |
| 4129 | val = of_get_property(dp, "node-wwn", &len); |
| 4130 | if (val && len >= WWN_SIZE) |
| 4131 | memcpy(nv->node_name, val, WWN_SIZE); |
| 4132 | #endif |
| 4133 | } |
| 4134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4135 | /* |
| 4136 | * NVRAM configuration for ISP 2xxx |
| 4137 | * |
| 4138 | * Input: |
| 4139 | * ha = adapter block pointer. |
| 4140 | * |
| 4141 | * Output: |
| 4142 | * initialization control block in response_ring |
| 4143 | * host adapters parameters in host adapter block |
| 4144 | * |
| 4145 | * Returns: |
| 4146 | * 0 = success. |
| 4147 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4148 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4149 | qla2x00_nvram_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4150 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4151 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4152 | uint8_t chksum = 0; |
| 4153 | uint16_t cnt; |
| 4154 | uint8_t *dptr1, *dptr2; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4155 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4156 | init_cb_t *icb = ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 4157 | nvram_t *nv = ha->nvram; |
| 4158 | uint8_t *ptr = ha->nvram; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 4159 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4160 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4161 | rval = QLA_SUCCESS; |
| 4162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4163 | /* Determine NVRAM starting address. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4164 | ha->nvram_size = sizeof(nvram_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4165 | ha->nvram_base = 0; |
| 4166 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) |
| 4167 | if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1) |
| 4168 | ha->nvram_base = 0x80; |
| 4169 | |
| 4170 | /* Get NVRAM data and calculate checksum. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4171 | 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] | 4172 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++) |
| 4173 | chksum += *ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4174 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4175 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f, |
| 4176 | "Contents of NVRAM.\n"); |
| 4177 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110, |
| 4178 | (uint8_t *)nv, ha->nvram_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4179 | |
| 4180 | /* Bad NVRAM data, set defaults parameters. */ |
| 4181 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || |
| 4182 | nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) { |
| 4183 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4184 | ql_log(ql_log_warn, vha, 0x0064, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 4185 | "Inconsistent NVRAM " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4186 | "detected: checksum=0x%x id=%c version=0x%x.\n", |
| 4187 | chksum, nv->id[0], nv->nvram_version); |
| 4188 | ql_log(ql_log_warn, vha, 0x0065, |
| 4189 | "Falling back to " |
| 4190 | "functioning (yet invalid -- WWPN) defaults.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4191 | |
| 4192 | /* |
| 4193 | * Set default initialization control block. |
| 4194 | */ |
| 4195 | memset(nv, 0, ha->nvram_size); |
| 4196 | nv->parameter_block_version = ICB_VERSION; |
| 4197 | |
| 4198 | if (IS_QLA23XX(ha)) { |
| 4199 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 4200 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 4201 | nv->add_firmware_options[0] = BIT_5; |
| 4202 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 4203 | nv->frame_payload_size = 2048; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4204 | nv->special_options[1] = BIT_7; |
| 4205 | } else if (IS_QLA2200(ha)) { |
| 4206 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 4207 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 4208 | nv->add_firmware_options[0] = BIT_5; |
| 4209 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 4210 | nv->frame_payload_size = 1024; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4211 | } else if (IS_QLA2100(ha)) { |
| 4212 | nv->firmware_options[0] = BIT_3 | BIT_1; |
| 4213 | nv->firmware_options[1] = BIT_5; |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 4214 | nv->frame_payload_size = 1024; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4215 | } |
| 4216 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 4217 | nv->max_iocb_allocation = cpu_to_le16(256); |
| 4218 | nv->execution_throttle = cpu_to_le16(16); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4219 | nv->retry_count = 8; |
| 4220 | nv->retry_delay = 1; |
| 4221 | |
| 4222 | nv->port_name[0] = 33; |
| 4223 | nv->port_name[3] = 224; |
| 4224 | nv->port_name[4] = 139; |
| 4225 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4226 | qla2xxx_nvram_wwn_from_ofw(vha, nv); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4227 | |
| 4228 | nv->login_timeout = 4; |
| 4229 | |
| 4230 | /* |
| 4231 | * Set default host adapter parameters |
| 4232 | */ |
| 4233 | nv->host_p[1] = BIT_2; |
| 4234 | nv->reset_delay = 5; |
| 4235 | nv->port_down_retry_count = 8; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 4236 | nv->max_luns_per_target = cpu_to_le16(8); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4237 | nv->link_down_timeout = 60; |
| 4238 | |
| 4239 | rval = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4240 | } |
| 4241 | |
| 4242 | #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2) |
| 4243 | /* |
| 4244 | * The SN2 does not provide BIOS emulation which means you can't change |
| 4245 | * potentially bogus BIOS settings. Force the use of default settings |
| 4246 | * for link rate and frame size. Hope that the rest of the settings |
| 4247 | * are valid. |
| 4248 | */ |
| 4249 | if (ia64_platform_is("sn2")) { |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 4250 | nv->frame_payload_size = 2048; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4251 | if (IS_QLA23XX(ha)) |
| 4252 | nv->special_options[1] = BIT_7; |
| 4253 | } |
| 4254 | #endif |
| 4255 | |
| 4256 | /* Reset Initialization control block */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4257 | memset(icb, 0, ha->init_cb_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4258 | |
| 4259 | /* |
| 4260 | * Setup driver NVRAM options. |
| 4261 | */ |
| 4262 | nv->firmware_options[0] |= (BIT_6 | BIT_1); |
| 4263 | nv->firmware_options[0] &= ~(BIT_5 | BIT_4); |
| 4264 | nv->firmware_options[1] |= (BIT_5 | BIT_0); |
| 4265 | nv->firmware_options[1] &= ~BIT_4; |
| 4266 | |
| 4267 | if (IS_QLA23XX(ha)) { |
| 4268 | nv->firmware_options[0] |= BIT_2; |
| 4269 | nv->firmware_options[0] &= ~BIT_3; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4270 | nv->special_options[0] &= ~BIT_6; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4271 | nv->add_firmware_options[1] |= BIT_5 | BIT_4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4272 | |
| 4273 | if (IS_QLA2300(ha)) { |
| 4274 | if (ha->fb_rev == FPM_2310) { |
| 4275 | strcpy(ha->model_number, "QLA2310"); |
| 4276 | } else { |
| 4277 | strcpy(ha->model_number, "QLA2300"); |
| 4278 | } |
| 4279 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4280 | qla2x00_set_model_info(vha, nv->model_number, |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 4281 | sizeof(nv->model_number), "QLA23xx"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4282 | } |
| 4283 | } else if (IS_QLA2200(ha)) { |
| 4284 | nv->firmware_options[0] |= BIT_2; |
| 4285 | /* |
| 4286 | * 'Point-to-point preferred, else loop' is not a safe |
| 4287 | * connection mode setting. |
| 4288 | */ |
| 4289 | if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) == |
| 4290 | (BIT_5 | BIT_4)) { |
| 4291 | /* Force 'loop preferred, else point-to-point'. */ |
| 4292 | nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4); |
| 4293 | nv->add_firmware_options[0] |= BIT_5; |
| 4294 | } |
| 4295 | strcpy(ha->model_number, "QLA22xx"); |
| 4296 | } else /*if (IS_QLA2100(ha))*/ { |
| 4297 | strcpy(ha->model_number, "QLA2100"); |
| 4298 | } |
| 4299 | |
| 4300 | /* |
| 4301 | * Copy over NVRAM RISC parameter block to initialization control block. |
| 4302 | */ |
| 4303 | dptr1 = (uint8_t *)icb; |
| 4304 | dptr2 = (uint8_t *)&nv->parameter_block_version; |
| 4305 | cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version; |
| 4306 | while (cnt--) |
| 4307 | *dptr1++ = *dptr2++; |
| 4308 | |
| 4309 | /* Copy 2nd half. */ |
| 4310 | dptr1 = (uint8_t *)icb->add_firmware_options; |
| 4311 | cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options; |
| 4312 | while (cnt--) |
| 4313 | *dptr1++ = *dptr2++; |
| 4314 | |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 4315 | /* Use alternate WWN? */ |
| 4316 | if (nv->host_p[1] & BIT_7) { |
| 4317 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 4318 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 4319 | } |
| 4320 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4321 | /* Prepare nodename */ |
| 4322 | if ((icb->firmware_options[1] & BIT_6) == 0) { |
| 4323 | /* |
| 4324 | * Firmware will apply the following mask if the nodename was |
| 4325 | * not provided. |
| 4326 | */ |
| 4327 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 4328 | icb->node_name[0] &= 0xF0; |
| 4329 | } |
| 4330 | |
| 4331 | /* |
| 4332 | * Set host adapter parameters. |
| 4333 | */ |
Saurav Kashyap | 3ce8866 | 2011-07-14 12:00:12 -0700 | [diff] [blame] | 4334 | |
| 4335 | /* |
| 4336 | * BIT_7 in the host-parameters section allows for modification to |
| 4337 | * internal driver logging. |
| 4338 | */ |
Andrew Vasquez | 0181944 | 2006-06-23 16:11:10 -0700 | [diff] [blame] | 4339 | if (nv->host_p[0] & BIT_7) |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 4340 | ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4341 | ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0); |
| 4342 | /* Always load RISC code on non ISP2[12]00 chips. */ |
| 4343 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) |
| 4344 | ha->flags.disable_risc_code_load = 0; |
| 4345 | ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0); |
| 4346 | ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0); |
| 4347 | 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] | 4348 | 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] | 4349 | ha->flags.disable_serdes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4350 | |
| 4351 | ha->operating_mode = |
| 4352 | (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 4353 | |
| 4354 | memcpy(ha->fw_seriallink_options, nv->seriallink_options, |
| 4355 | sizeof(ha->fw_seriallink_options)); |
| 4356 | |
| 4357 | /* save HBA serial number */ |
| 4358 | ha->serial0 = icb->port_name[5]; |
| 4359 | ha->serial1 = icb->port_name[6]; |
| 4360 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4361 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 4362 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4363 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 4364 | icb->execution_throttle = cpu_to_le16(0xFFFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4365 | |
| 4366 | ha->retry_count = nv->retry_count; |
| 4367 | |
| 4368 | /* Set minimum login_timeout to 4 seconds. */ |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 4369 | if (nv->login_timeout != ql2xlogintimeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4370 | nv->login_timeout = ql2xlogintimeout; |
| 4371 | if (nv->login_timeout < 4) |
| 4372 | nv->login_timeout = 4; |
| 4373 | ha->login_timeout = nv->login_timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4374 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 4375 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 4376 | ha->r_a_tov = 100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4378 | ha->loop_reset_delay = nv->reset_delay; |
| 4379 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4380 | /* Link Down Timeout = 0: |
| 4381 | * |
| 4382 | * When Port Down timer expires we will start returning |
| 4383 | * I/O's to OS with "DID_NO_CONNECT". |
| 4384 | * |
| 4385 | * Link Down Timeout != 0: |
| 4386 | * |
| 4387 | * The driver waits for the link to come up after link down |
| 4388 | * before returning I/Os to OS with "DID_NO_CONNECT". |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4389 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4390 | if (nv->link_down_timeout == 0) { |
| 4391 | ha->loop_down_abort_time = |
Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 4392 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4393 | } else { |
| 4394 | ha->link_down_timeout = nv->link_down_timeout; |
| 4395 | ha->loop_down_abort_time = |
| 4396 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4397 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4398 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4399 | /* |
| 4400 | * Need enough time to try and get the port back. |
| 4401 | */ |
| 4402 | ha->port_down_retry_count = nv->port_down_retry_count; |
| 4403 | if (qlport_down_retry) |
| 4404 | ha->port_down_retry_count = qlport_down_retry; |
| 4405 | /* Set login_retry_count */ |
| 4406 | ha->login_retry_count = nv->retry_count; |
| 4407 | if (ha->port_down_retry_count == nv->port_down_retry_count && |
| 4408 | ha->port_down_retry_count > 3) |
| 4409 | ha->login_retry_count = ha->port_down_retry_count; |
| 4410 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 4411 | ha->login_retry_count = ha->port_down_retry_count; |
| 4412 | if (ql2xloginretrycount) |
| 4413 | ha->login_retry_count = ql2xloginretrycount; |
| 4414 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 4415 | icb->lun_enables = cpu_to_le16(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4416 | icb->command_resource_count = 0; |
| 4417 | icb->immediate_notify_resource_count = 0; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 4418 | icb->timeout = cpu_to_le16(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4419 | |
| 4420 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 4421 | /* Enable RIO */ |
| 4422 | icb->firmware_options[0] &= ~BIT_3; |
| 4423 | icb->add_firmware_options[0] &= |
| 4424 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 4425 | icb->add_firmware_options[0] |= BIT_2; |
| 4426 | icb->response_accumulation_timer = 3; |
| 4427 | icb->interrupt_delay_timer = 5; |
| 4428 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4429 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4430 | } else { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4431 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4432 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4433 | ha->zio_mode = icb->add_firmware_options[0] & |
| 4434 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 4435 | ha->zio_timer = icb->interrupt_delay_timer ? |
| 4436 | icb->interrupt_delay_timer: 2; |
| 4437 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4438 | icb->add_firmware_options[0] &= |
| 4439 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4440 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4441 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 4442 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 4443 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4444 | ql_log(ql_log_info, vha, 0x0068, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4445 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 4446 | ha->zio_mode, ha->zio_timer * 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4447 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4448 | icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode; |
| 4449 | icb->interrupt_delay_timer = (uint8_t)ha->zio_timer; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4450 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4451 | } |
| 4452 | } |
| 4453 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4454 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4455 | ql_log(ql_log_warn, vha, 0x0069, |
| 4456 | "NVRAM configuration failed.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4457 | } |
| 4458 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4459 | } |
| 4460 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4461 | static void |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4462 | qla2x00_rport_del(void *data) |
| 4463 | { |
| 4464 | fc_port_t *fcport = data; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 4465 | struct fc_rport *rport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 4466 | unsigned long flags; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4467 | |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 4468 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 4469 | rport = fcport->drport ? fcport->drport: fcport->rport; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 4470 | fcport->drport = NULL; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 4471 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4472 | if (rport) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4473 | ql_dbg(ql_dbg_disc, fcport->vha, 0x210b, |
| 4474 | "%s %8phN. rport %p roles %x\n", |
| 4475 | __func__, fcport->port_name, rport, |
| 4476 | rport->roles); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4477 | |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 4478 | fc_remote_port_delete(rport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4479 | } |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4480 | } |
| 4481 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4482 | /** |
| 4483 | * qla2x00_alloc_fcport() - Allocate a generic fcport. |
Bart Van Assche | 2db6228 | 2018-01-23 16:33:51 -0800 | [diff] [blame] | 4484 | * @vha: HA context |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4485 | * @flags: allocation flags |
| 4486 | * |
| 4487 | * Returns a pointer to the allocated fcport, or NULL, if none available. |
| 4488 | */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 4489 | fc_port_t * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4490 | qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4491 | { |
| 4492 | fc_port_t *fcport; |
| 4493 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 4494 | fcport = kzalloc(sizeof(fc_port_t), flags); |
| 4495 | if (!fcport) |
| 4496 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4497 | |
| 4498 | /* Setup fcport template structure. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4499 | fcport->vha = vha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4500 | fcport->port_type = FCT_UNKNOWN; |
| 4501 | fcport->loop_id = FC_NO_LOOP_ID; |
Chad Dupuis | ec426e1 | 2011-03-30 11:46:32 -0700 | [diff] [blame] | 4502 | qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED); |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 4503 | fcport->supported_classes = FC_COS_UNSPECIFIED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4504 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4505 | fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev, |
| 4506 | sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma, |
Quinn Tran | 6cb3216 | 2017-02-13 12:18:29 -0800 | [diff] [blame] | 4507 | flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4508 | fcport->disc_state = DSC_DELETED; |
| 4509 | fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 4510 | fcport->deleted = QLA_SESS_DELETED; |
| 4511 | fcport->login_retry = vha->hw->login_retry_count; |
| 4512 | fcport->login_retry = 5; |
| 4513 | fcport->logout_on_delete = 1; |
| 4514 | |
| 4515 | if (!fcport->ct_desc.ct_sns) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4516 | ql_log(ql_log_warn, vha, 0xd049, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4517 | "Failed to allocate ct_sns request.\n"); |
| 4518 | kfree(fcport); |
| 4519 | fcport = NULL; |
| 4520 | } |
| 4521 | INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn); |
| 4522 | INIT_LIST_HEAD(&fcport->gnl_entry); |
| 4523 | INIT_LIST_HEAD(&fcport->list); |
| 4524 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 4525 | return fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4526 | } |
| 4527 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4528 | void |
| 4529 | qla2x00_free_fcport(fc_port_t *fcport) |
| 4530 | { |
| 4531 | if (fcport->ct_desc.ct_sns) { |
| 4532 | dma_free_coherent(&fcport->vha->hw->pdev->dev, |
| 4533 | sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns, |
| 4534 | fcport->ct_desc.ct_sns_dma); |
| 4535 | |
| 4536 | fcport->ct_desc.ct_sns = NULL; |
| 4537 | } |
| 4538 | kfree(fcport); |
| 4539 | } |
| 4540 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4541 | /* |
| 4542 | * qla2x00_configure_loop |
| 4543 | * Updates Fibre Channel Device Database with what is actually on loop. |
| 4544 | * |
| 4545 | * Input: |
| 4546 | * ha = adapter block pointer. |
| 4547 | * |
| 4548 | * Returns: |
| 4549 | * 0 = success. |
| 4550 | * 1 = error. |
| 4551 | * 2 = database was full and device was not configured. |
| 4552 | */ |
| 4553 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4554 | qla2x00_configure_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4555 | { |
| 4556 | int rval; |
| 4557 | unsigned long flags, save_flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4558 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4559 | rval = QLA_SUCCESS; |
| 4560 | |
| 4561 | /* Get Initiator ID */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4562 | if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) { |
| 4563 | rval = qla2x00_configure_hba(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4564 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4565 | ql_dbg(ql_dbg_disc, vha, 0x2013, |
| 4566 | "Unable to configure HBA.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4567 | return (rval); |
| 4568 | } |
| 4569 | } |
| 4570 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4571 | save_flags = flags = vha->dpc_flags; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4572 | ql_dbg(ql_dbg_disc, vha, 0x2014, |
| 4573 | "Configure loop -- dpc flags = 0x%lx.\n", flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4574 | |
| 4575 | /* |
| 4576 | * If we have both an RSCN and PORT UPDATE pending then handle them |
| 4577 | * both at the same time. |
| 4578 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4579 | clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 4580 | clear_bit(RSCN_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4581 | |
Michael Hernandez | 3064ff3 | 2009-12-15 21:29:44 -0800 | [diff] [blame] | 4582 | qla2x00_get_data_rate(vha); |
| 4583 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4584 | /* Determine what we need to do */ |
| 4585 | if (ha->current_topology == ISP_CFG_FL && |
| 4586 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 4587 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4588 | set_bit(RSCN_UPDATE, &flags); |
| 4589 | |
| 4590 | } else if (ha->current_topology == ISP_CFG_F && |
| 4591 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 4592 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4593 | set_bit(RSCN_UPDATE, &flags); |
| 4594 | clear_bit(LOCAL_LOOP_UPDATE, &flags); |
| 4595 | |
Andrew Vasquez | 21333b4 | 2006-05-17 15:09:56 -0700 | [diff] [blame] | 4596 | } else if (ha->current_topology == ISP_CFG_N) { |
| 4597 | clear_bit(RSCN_UPDATE, &flags); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4598 | if (ha->flags.rida_fmt2) { |
| 4599 | /* With Rida Format 2, the login is already triggered. |
| 4600 | * We know who is on the other side of the wire. |
| 4601 | * No need to login to do login to find out or drop into |
| 4602 | * qla2x00_configure_local_loop(). |
| 4603 | */ |
| 4604 | clear_bit(LOCAL_LOOP_UPDATE, &flags); |
| 4605 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 4606 | } else { |
| 4607 | if (qla_tgt_mode_enabled(vha)) { |
| 4608 | /* allow the other side to start the login */ |
| 4609 | clear_bit(LOCAL_LOOP_UPDATE, &flags); |
| 4610 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 4611 | } |
| 4612 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4613 | } else if (ha->current_topology == ISP_CFG_NL) { |
| 4614 | clear_bit(RSCN_UPDATE, &flags); |
| 4615 | set_bit(LOCAL_LOOP_UPDATE, &flags); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4616 | } else if (!vha->flags.online || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4617 | (test_bit(ABORT_ISP_ACTIVE, &flags))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4618 | set_bit(RSCN_UPDATE, &flags); |
| 4619 | set_bit(LOCAL_LOOP_UPDATE, &flags); |
| 4620 | } |
| 4621 | |
| 4622 | if (test_bit(LOCAL_LOOP_UPDATE, &flags)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4623 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
| 4624 | ql_dbg(ql_dbg_disc, vha, 0x2015, |
| 4625 | "Loop resync needed, failing.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4626 | rval = QLA_FUNCTION_FAILED; |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4627 | } else |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4628 | rval = qla2x00_configure_local_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4629 | } |
| 4630 | |
| 4631 | if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4632 | if (LOOP_TRANSITION(vha)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4633 | ql_dbg(ql_dbg_disc, vha, 0x2099, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4634 | "Needs RSCN update and loop transition.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4635 | rval = QLA_FUNCTION_FAILED; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4636 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4637 | else |
| 4638 | rval = qla2x00_configure_fabric(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4639 | } |
| 4640 | |
| 4641 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4642 | if (atomic_read(&vha->loop_down_timer) || |
| 4643 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4644 | rval = QLA_FUNCTION_FAILED; |
| 4645 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4646 | atomic_set(&vha->loop_state, LOOP_READY); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4647 | ql_dbg(ql_dbg_disc, vha, 0x2069, |
| 4648 | "LOOP READY.\n"); |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 4649 | ha->flags.fw_init_done = 1; |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 4650 | |
| 4651 | /* |
| 4652 | * Process any ATIO queue entries that came in |
| 4653 | * while we weren't online. |
| 4654 | */ |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 4655 | if (qla_tgt_mode_enabled(vha) || |
| 4656 | qla_dual_mode_enabled(vha)) { |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 4657 | if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) { |
| 4658 | spin_lock_irqsave(&ha->tgt.atio_lock, |
| 4659 | flags); |
| 4660 | qlt_24xx_process_atio_queue(vha, 0); |
| 4661 | spin_unlock_irqrestore( |
| 4662 | &ha->tgt.atio_lock, flags); |
| 4663 | } else { |
| 4664 | spin_lock_irqsave(&ha->hardware_lock, |
| 4665 | flags); |
| 4666 | qlt_24xx_process_atio_queue(vha, 1); |
| 4667 | spin_unlock_irqrestore( |
| 4668 | &ha->hardware_lock, flags); |
| 4669 | } |
| 4670 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4671 | } |
| 4672 | } |
| 4673 | |
| 4674 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4675 | ql_dbg(ql_dbg_disc, vha, 0x206a, |
| 4676 | "%s *** FAILED ***.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4677 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4678 | ql_dbg(ql_dbg_disc, vha, 0x206b, |
| 4679 | "%s: exiting normally.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4680 | } |
| 4681 | |
Bjorn Helgaas | cc3ef7b | 2008-09-11 21:22:51 -0700 | [diff] [blame] | 4682 | /* Restore state if a resync event occurred during processing */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4683 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4684 | if (test_bit(LOCAL_LOOP_UPDATE, &save_flags)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4685 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 4686 | if (test_bit(RSCN_UPDATE, &save_flags)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4687 | set_bit(RSCN_UPDATE, &vha->dpc_flags); |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 4688 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4689 | } |
| 4690 | |
| 4691 | return (rval); |
| 4692 | } |
| 4693 | |
Duane Grigsby | edd05de | 2017-10-13 09:34:06 -0700 | [diff] [blame] | 4694 | /* |
| 4695 | * N2N Login |
| 4696 | * Updates Fibre Channel Device Database with local loop devices. |
| 4697 | * |
| 4698 | * Input: |
| 4699 | * ha = adapter block pointer. |
| 4700 | * |
| 4701 | * Returns: |
| 4702 | */ |
| 4703 | static int qla24xx_n2n_handle_login(struct scsi_qla_host *vha, |
| 4704 | fc_port_t *fcport) |
| 4705 | { |
| 4706 | struct qla_hw_data *ha = vha->hw; |
| 4707 | int res = QLA_SUCCESS, rval; |
| 4708 | int greater_wwpn = 0; |
| 4709 | int logged_in = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4710 | |
Duane Grigsby | edd05de | 2017-10-13 09:34:06 -0700 | [diff] [blame] | 4711 | if (ha->current_topology != ISP_CFG_N) |
| 4712 | return res; |
| 4713 | |
| 4714 | if (wwn_to_u64(vha->port_name) > |
| 4715 | wwn_to_u64(vha->n2n_port_name)) { |
| 4716 | ql_dbg(ql_dbg_disc, vha, 0x2002, |
| 4717 | "HBA WWPN is greater %llx > target %llx\n", |
| 4718 | wwn_to_u64(vha->port_name), |
| 4719 | wwn_to_u64(vha->n2n_port_name)); |
| 4720 | greater_wwpn = 1; |
| 4721 | fcport->d_id.b24 = vha->n2n_id; |
| 4722 | } |
| 4723 | |
| 4724 | fcport->loop_id = vha->loop_id; |
| 4725 | fcport->fc4f_nvme = 0; |
| 4726 | fcport->query = 1; |
| 4727 | |
| 4728 | ql_dbg(ql_dbg_disc, vha, 0x4001, |
| 4729 | "Initiate N2N login handler: HBA port_id=%06x loopid=%d\n", |
| 4730 | fcport->d_id.b24, vha->loop_id); |
| 4731 | |
| 4732 | /* Fill in member data. */ |
| 4733 | if (!greater_wwpn) { |
| 4734 | rval = qla2x00_get_port_database(vha, fcport, 0); |
| 4735 | ql_dbg(ql_dbg_disc, vha, 0x1051, |
| 4736 | "Remote login-state (%x/%x) port_id=%06x loop_id=%x, rval=%d\n", |
| 4737 | fcport->current_login_state, fcport->last_login_state, |
| 4738 | fcport->d_id.b24, fcport->loop_id, rval); |
| 4739 | |
| 4740 | if (((fcport->current_login_state & 0xf) == 0x4) || |
| 4741 | ((fcport->current_login_state & 0xf) == 0x6)) |
| 4742 | logged_in = 1; |
| 4743 | } |
| 4744 | |
| 4745 | if (logged_in || greater_wwpn) { |
| 4746 | if (!vha->nvme_local_port && vha->flags.nvme_enabled) |
| 4747 | qla_nvme_register_hba(vha); |
| 4748 | |
| 4749 | /* Set connected N_Port d_id */ |
| 4750 | if (vha->flags.nvme_enabled) |
| 4751 | fcport->fc4f_nvme = 1; |
| 4752 | |
| 4753 | fcport->scan_state = QLA_FCPORT_FOUND; |
| 4754 | fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 4755 | fcport->disc_state = DSC_GNL; |
| 4756 | fcport->n2n_flag = 1; |
| 4757 | fcport->flags = 3; |
| 4758 | vha->hw->flags.gpsc_supported = 0; |
| 4759 | |
| 4760 | if (greater_wwpn) { |
| 4761 | ql_dbg(ql_dbg_disc, vha, 0x20e5, |
| 4762 | "%s %d PLOGI ELS %8phC\n", |
| 4763 | __func__, __LINE__, fcport->port_name); |
| 4764 | |
| 4765 | res = qla24xx_els_dcmd2_iocb(vha, ELS_DCMD_PLOGI, |
| 4766 | fcport, fcport->d_id); |
| 4767 | } |
| 4768 | |
| 4769 | if (res != QLA_SUCCESS) { |
| 4770 | ql_log(ql_log_info, vha, 0xd04d, |
| 4771 | "PLOGI Failed: portid=%06x - retrying\n", |
| 4772 | fcport->d_id.b24); |
| 4773 | res = QLA_SUCCESS; |
| 4774 | } else { |
| 4775 | /* State 0x6 means FCP PRLI complete */ |
| 4776 | if ((fcport->current_login_state & 0xf) == 0x6) { |
| 4777 | ql_dbg(ql_dbg_disc, vha, 0x2118, |
| 4778 | "%s %d %8phC post GPDB work\n", |
| 4779 | __func__, __LINE__, fcport->port_name); |
| 4780 | fcport->chip_reset = |
| 4781 | vha->hw->base_qpair->chip_reset; |
| 4782 | qla24xx_post_gpdb_work(vha, fcport, 0); |
| 4783 | } else { |
| 4784 | ql_dbg(ql_dbg_disc, vha, 0x2118, |
| 4785 | "%s %d %8phC post NVMe PRLI\n", |
| 4786 | __func__, __LINE__, fcport->port_name); |
| 4787 | qla24xx_post_prli_work(vha, fcport); |
| 4788 | } |
| 4789 | } |
| 4790 | } else { |
| 4791 | /* Wait for next database change */ |
| 4792 | set_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags); |
| 4793 | } |
| 4794 | |
| 4795 | return res; |
| 4796 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4797 | |
| 4798 | /* |
| 4799 | * qla2x00_configure_local_loop |
| 4800 | * Updates Fibre Channel Device Database with local loop devices. |
| 4801 | * |
| 4802 | * Input: |
| 4803 | * ha = adapter block pointer. |
| 4804 | * |
| 4805 | * Returns: |
| 4806 | * 0 = success. |
| 4807 | */ |
| 4808 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4809 | qla2x00_configure_local_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4810 | { |
| 4811 | int rval, rval2; |
| 4812 | int found_devs; |
| 4813 | int found; |
| 4814 | fc_port_t *fcport, *new_fcport; |
| 4815 | |
| 4816 | uint16_t index; |
| 4817 | uint16_t entries; |
| 4818 | char *id_iter; |
| 4819 | uint16_t loop_id; |
| 4820 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4821 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4822 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4823 | |
| 4824 | found_devs = 0; |
| 4825 | new_fcport = NULL; |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4826 | entries = MAX_FIBRE_DEVICES_LOOP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4827 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4828 | /* Get list of logged in devices. */ |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4829 | memset(ha->gid_list, 0, qla2x00_gid_list_size(ha)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4830 | 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] | 4831 | &entries); |
| 4832 | if (rval != QLA_SUCCESS) |
| 4833 | goto cleanup_allocation; |
| 4834 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4835 | ql_dbg(ql_dbg_disc, vha, 0x2011, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4836 | "Entries in ID list (%d).\n", entries); |
| 4837 | ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075, |
| 4838 | (uint8_t *)ha->gid_list, |
| 4839 | entries * sizeof(struct gid_list_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4840 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4841 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 4842 | fcport->scan_state = QLA_FCPORT_SCAN; |
| 4843 | } |
| 4844 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4845 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4846 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4847 | if (new_fcport == NULL) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4848 | ql_log(ql_log_warn, vha, 0x2012, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4849 | "Memory allocation failed for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4850 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 4851 | goto cleanup_allocation; |
| 4852 | } |
| 4853 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 4854 | |
Duane Grigsby | edd05de | 2017-10-13 09:34:06 -0700 | [diff] [blame] | 4855 | /* Inititae N2N login. */ |
| 4856 | if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags)) { |
| 4857 | rval = qla24xx_n2n_handle_login(vha, new_fcport); |
| 4858 | if (rval != QLA_SUCCESS) |
| 4859 | goto cleanup_allocation; |
| 4860 | return QLA_SUCCESS; |
| 4861 | } |
| 4862 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4863 | /* Add devices to port list. */ |
| 4864 | id_iter = (char *)ha->gid_list; |
| 4865 | for (index = 0; index < entries; index++) { |
| 4866 | domain = ((struct gid_list_info *)id_iter)->domain; |
| 4867 | area = ((struct gid_list_info *)id_iter)->area; |
| 4868 | al_pa = ((struct gid_list_info *)id_iter)->al_pa; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4869 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4870 | loop_id = (uint16_t) |
| 4871 | ((struct gid_list_info *)id_iter)->loop_id_2100; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4872 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4873 | loop_id = le16_to_cpu( |
| 4874 | ((struct gid_list_info *)id_iter)->loop_id); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4875 | id_iter += ha->gid_list_info_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4876 | |
| 4877 | /* Bypass reserved domain fields. */ |
| 4878 | if ((domain & 0xf0) == 0xf0) |
| 4879 | continue; |
| 4880 | |
| 4881 | /* Bypass if not same domain and area of adapter. */ |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 4882 | if (area && domain && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4883 | (area != vha->d_id.b.area || domain != vha->d_id.b.domain)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4884 | continue; |
| 4885 | |
| 4886 | /* Bypass invalid local loop ID. */ |
| 4887 | if (loop_id > LAST_LOCAL_LOOP_ID) |
| 4888 | continue; |
| 4889 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4890 | memset(new_fcport->port_name, 0, WWN_SIZE); |
Arun Easi | 370d550 | 2012-08-22 14:21:10 -0400 | [diff] [blame] | 4891 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4892 | /* Fill in member data. */ |
| 4893 | new_fcport->d_id.b.domain = domain; |
| 4894 | new_fcport->d_id.b.area = area; |
| 4895 | new_fcport->d_id.b.al_pa = al_pa; |
| 4896 | new_fcport->loop_id = loop_id; |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4897 | new_fcport->scan_state = QLA_FCPORT_FOUND; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4898 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4899 | rval2 = qla2x00_get_port_database(vha, new_fcport, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4900 | if (rval2 != QLA_SUCCESS) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4901 | ql_dbg(ql_dbg_disc, vha, 0x2097, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4902 | "Failed to retrieve fcport information " |
| 4903 | "-- get_port_database=%x, loop_id=0x%04x.\n", |
| 4904 | rval2, new_fcport->loop_id); |
Duane Grigsby | edd05de | 2017-10-13 09:34:06 -0700 | [diff] [blame] | 4905 | /* Skip retry if N2N */ |
| 4906 | if (ha->current_topology != ISP_CFG_N) { |
| 4907 | ql_dbg(ql_dbg_disc, vha, 0x2105, |
| 4908 | "Scheduling resync.\n"); |
| 4909 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 4910 | continue; |
| 4911 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4912 | } |
| 4913 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4914 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4915 | /* Check for matching device in port list. */ |
| 4916 | found = 0; |
| 4917 | fcport = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4918 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4919 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 4920 | WWN_SIZE)) |
| 4921 | continue; |
| 4922 | |
Shyam Sundar | ddb9b12 | 2009-03-24 09:08:10 -0700 | [diff] [blame] | 4923 | fcport->flags &= ~FCF_FABRIC_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4924 | fcport->loop_id = new_fcport->loop_id; |
| 4925 | fcport->port_type = new_fcport->port_type; |
| 4926 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 4927 | memcpy(fcport->node_name, new_fcport->node_name, |
| 4928 | WWN_SIZE); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4929 | fcport->scan_state = QLA_FCPORT_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4930 | found++; |
| 4931 | break; |
| 4932 | } |
| 4933 | |
| 4934 | if (!found) { |
| 4935 | /* New device, add to fcports list. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4936 | list_add_tail(&new_fcport->list, &vha->vp_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4937 | |
| 4938 | /* Allocate a new replacement fcport. */ |
| 4939 | fcport = new_fcport; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4940 | |
| 4941 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 4942 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4943 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4944 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4945 | if (new_fcport == NULL) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4946 | ql_log(ql_log_warn, vha, 0xd031, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4947 | "Failed to allocate memory for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4948 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 4949 | goto cleanup_allocation; |
| 4950 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4951 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4952 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 4953 | } |
| 4954 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4955 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 4956 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4957 | /* Base iIDMA settings on HBA port speed. */ |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 4958 | fcport->fp_speed = ha->link_data_rate; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4959 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4960 | found_devs++; |
| 4961 | } |
| 4962 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4963 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 4964 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 4965 | break; |
| 4966 | |
| 4967 | if (fcport->scan_state == QLA_FCPORT_SCAN) { |
| 4968 | if ((qla_dual_mode_enabled(vha) || |
| 4969 | qla_ini_mode_enabled(vha)) && |
| 4970 | atomic_read(&fcport->state) == FCS_ONLINE) { |
| 4971 | qla2x00_mark_device_lost(vha, fcport, |
| 4972 | ql2xplogiabsentdevice, 0); |
| 4973 | if (fcport->loop_id != FC_NO_LOOP_ID && |
| 4974 | (fcport->flags & FCF_FCP2_DEVICE) == 0 && |
| 4975 | fcport->port_type != FCT_INITIATOR && |
| 4976 | fcport->port_type != FCT_BROADCAST) { |
| 4977 | ql_dbg(ql_dbg_disc, vha, 0x20f0, |
| 4978 | "%s %d %8phC post del sess\n", |
| 4979 | __func__, __LINE__, |
| 4980 | fcport->port_name); |
| 4981 | |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 4982 | qlt_schedule_sess_for_deletion(fcport); |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 4983 | continue; |
| 4984 | } |
| 4985 | } |
| 4986 | } |
| 4987 | |
| 4988 | if (fcport->scan_state == QLA_FCPORT_FOUND) |
| 4989 | qla24xx_fcport_handle_login(vha, fcport); |
| 4990 | } |
| 4991 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4992 | cleanup_allocation: |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 4993 | kfree(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4994 | |
| 4995 | if (rval != QLA_SUCCESS) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4996 | ql_dbg(ql_dbg_disc, vha, 0x2098, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4997 | "Configure local loop error exit: rval=%x.\n", rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4998 | } |
| 4999 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5000 | return (rval); |
| 5001 | } |
| 5002 | |
| 5003 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5004 | qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 5005 | { |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 5006 | int rval; |
Quinn Tran | 93f2bd6 | 2014-09-25 05:16:53 -0400 | [diff] [blame] | 5007 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5008 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 5009 | |
Andrew Vasquez | c76f2c0 | 2007-07-19 15:05:57 -0700 | [diff] [blame] | 5010 | if (!IS_IIDMA_CAPABLE(ha)) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 5011 | return; |
| 5012 | |
Giridhar Malavali | c9afb9a | 2010-09-03 15:20:48 -0700 | [diff] [blame] | 5013 | if (atomic_read(&fcport->state) != FCS_ONLINE) |
| 5014 | return; |
| 5015 | |
Andrew Vasquez | 39bd962 | 2007-09-20 14:07:34 -0700 | [diff] [blame] | 5016 | if (fcport->fp_speed == PORT_SPEED_UNKNOWN || |
| 5017 | fcport->fp_speed > ha->link_data_rate) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 5018 | return; |
| 5019 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5020 | rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed, |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 5021 | mb); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 5022 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5023 | ql_dbg(ql_dbg_disc, vha, 0x2004, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 5024 | "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n", |
| 5025 | fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 5026 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5027 | ql_dbg(ql_dbg_disc, vha, 0x2005, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 5028 | "iIDMA adjusted to %s GB/s on %8phN.\n", |
Joe Carnuccio | d0297c9 | 2012-11-21 02:40:40 -0500 | [diff] [blame] | 5029 | qla2x00_get_link_speed_str(ha, fcport->fp_speed), |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 5030 | fcport->port_name); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 5031 | } |
| 5032 | } |
| 5033 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5034 | /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/ |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 5035 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5036 | qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 5037 | { |
| 5038 | struct fc_rport_identifiers rport_ids; |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 5039 | struct fc_rport *rport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 5040 | unsigned long flags; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 5041 | |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 5042 | rport_ids.node_name = wwn_to_u64(fcport->node_name); |
| 5043 | rport_ids.port_name = wwn_to_u64(fcport->port_name); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 5044 | rport_ids.port_id = fcport->d_id.b.domain << 16 | |
| 5045 | fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa; |
| 5046 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5047 | fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 5048 | if (!rport) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5049 | ql_log(ql_log_warn, vha, 0x2006, |
| 5050 | "Unable to allocate fc remote port.\n"); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 5051 | return; |
| 5052 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5053 | |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 5054 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 5055 | *((fc_port_t **)rport->dd_data) = fcport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 5056 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5057 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 5058 | rport->supported_classes = fcport->supported_classes; |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 5059 | |
| 5060 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 5061 | if (fcport->port_type == FCT_INITIATOR) |
| 5062 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 5063 | if (fcport->port_type == FCT_TARGET) |
| 5064 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5065 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5066 | ql_dbg(ql_dbg_disc, vha, 0x20ee, |
| 5067 | "%s %8phN. rport %p is %s mode\n", |
| 5068 | __func__, fcport->port_name, rport, |
| 5069 | (fcport->port_type == FCT_TARGET) ? "tgt" : "ini"); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5070 | |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 5071 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 5072 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5073 | |
| 5074 | /* |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 5075 | * qla2x00_update_fcport |
| 5076 | * Updates device on list. |
| 5077 | * |
| 5078 | * Input: |
| 5079 | * ha = adapter block pointer. |
| 5080 | * fcport = port structure pointer. |
| 5081 | * |
| 5082 | * Return: |
| 5083 | * 0 - Success |
| 5084 | * BIT_0 - error |
| 5085 | * |
| 5086 | * Context: |
| 5087 | * Kernel context. |
| 5088 | */ |
| 5089 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5090 | qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 5091 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5092 | fcport->vha = vha; |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 5093 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5094 | if (IS_SW_RESV_ADDR(fcport->d_id)) |
| 5095 | return; |
| 5096 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5097 | ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n", |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5098 | __func__, fcport->port_name); |
| 5099 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 5100 | if (IS_QLAFX00(vha->hw)) { |
| 5101 | qla2x00_set_fcport_state(fcport, FCS_ONLINE); |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 5102 | goto reg_port; |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 5103 | } |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 5104 | fcport->login_retry = 0; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 5105 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5106 | fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 5107 | fcport->deleted = 0; |
| 5108 | fcport->logout_on_delete = 1; |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 5109 | |
Darren Trapp | dbe1801 | 2018-03-20 23:09:31 -0700 | [diff] [blame] | 5110 | qla2x00_set_fcport_state(fcport, FCS_ONLINE); |
| 5111 | qla2x00_iidma_fcport(vha, fcport); |
| 5112 | |
Duane Grigsby | e84067d | 2017-06-21 13:48:43 -0700 | [diff] [blame] | 5113 | if (fcport->fc4f_nvme) { |
| 5114 | qla_nvme_register_remote(vha, fcport); |
| 5115 | return; |
| 5116 | } |
| 5117 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5118 | qla24xx_update_fcport_fcp_prio(vha, fcport); |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 5119 | |
| 5120 | reg_port: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5121 | switch (vha->host->active_mode) { |
| 5122 | case MODE_INITIATOR: |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 5123 | qla2x00_reg_remote_port(vha, fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5124 | break; |
| 5125 | case MODE_TARGET: |
| 5126 | if (!vha->vha_tgt.qla_tgt->tgt_stop && |
| 5127 | !vha->vha_tgt.qla_tgt->tgt_stopped) |
| 5128 | qlt_fc_port_added(vha, fcport); |
| 5129 | break; |
| 5130 | case MODE_DUAL: |
| 5131 | qla2x00_reg_remote_port(vha, fcport); |
| 5132 | if (!vha->vha_tgt.qla_tgt->tgt_stop && |
| 5133 | !vha->vha_tgt.qla_tgt->tgt_stopped) |
| 5134 | qlt_fc_port_added(vha, fcport); |
| 5135 | break; |
| 5136 | default: |
| 5137 | break; |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 5138 | } |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 5139 | } |
| 5140 | |
| 5141 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5142 | * qla2x00_configure_fabric |
| 5143 | * Setup SNS devices with loop ID's. |
| 5144 | * |
| 5145 | * Input: |
| 5146 | * ha = adapter block pointer. |
| 5147 | * |
| 5148 | * Returns: |
| 5149 | * 0 = success. |
| 5150 | * BIT_0 = error |
| 5151 | */ |
| 5152 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5153 | qla2x00_configure_fabric(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5154 | { |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 5155 | int rval; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5156 | fc_port_t *fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5157 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5158 | uint16_t loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5159 | LIST_HEAD(new_fcports); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5160 | struct qla_hw_data *ha = vha->hw; |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 5161 | int discovery_gen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5162 | |
| 5163 | /* If FL port exists, then SNS is present */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 5164 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5165 | loop_id = NPH_F_PORT; |
| 5166 | else |
| 5167 | loop_id = SNS_FL_PORT; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5168 | 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] | 5169 | if (rval != QLA_SUCCESS) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5170 | ql_dbg(ql_dbg_disc, vha, 0x20a0, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5171 | "MBX_GET_PORT_NAME failed, No FL Port.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5172 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5173 | vha->device_flags &= ~SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5174 | return (QLA_SUCCESS); |
| 5175 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5176 | vha->device_flags |= SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5177 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 5178 | |
| 5179 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { |
| 5180 | rval = qla2x00_send_change_request(vha, 0x3, 0); |
| 5181 | if (rval != QLA_SUCCESS) |
| 5182 | ql_log(ql_log_warn, vha, 0x121, |
| 5183 | "Failed to enable receiving of RSCN requests: 0x%x.\n", |
| 5184 | rval); |
| 5185 | } |
| 5186 | |
| 5187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5188 | do { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5189 | qla2x00_mgmt_svr_login(vha); |
| 5190 | |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 5191 | /* FDMI support. */ |
| 5192 | if (ql2xfdmienable && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5193 | test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags)) |
| 5194 | qla2x00_fdmi_register(vha); |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 5195 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5196 | /* Ensure we are logged into the SNS. */ |
Joe Carnuccio | a14c771 | 2017-08-23 15:05:12 -0700 | [diff] [blame] | 5197 | loop_id = NPH_SNS_LID(ha); |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 5198 | rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff, |
| 5199 | 0xfc, mb, BIT_1|BIT_0); |
Joe Carnuccio | a14c771 | 2017-08-23 15:05:12 -0700 | [diff] [blame] | 5200 | if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) { |
| 5201 | ql_dbg(ql_dbg_disc, vha, 0x20a1, |
| 5202 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n", |
| 5203 | loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval); |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 5204 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Joe Carnuccio | e452ceb | 2013-02-08 01:57:56 -0500 | [diff] [blame] | 5205 | return rval; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 5206 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5207 | if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) { |
| 5208 | if (qla2x00_rft_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5209 | /* EMPTY */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5210 | ql_dbg(ql_dbg_disc, vha, 0x20a2, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5211 | "Register FC-4 TYPE failed.\n"); |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 5212 | if (test_bit(LOOP_RESYNC_NEEDED, |
| 5213 | &vha->dpc_flags)) |
| 5214 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5215 | } |
Duane Grigsby | d3bae93 | 2017-06-21 13:48:44 -0700 | [diff] [blame] | 5216 | if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5217 | /* EMPTY */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5218 | ql_dbg(ql_dbg_disc, vha, 0x209a, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5219 | "Register FC-4 Features failed.\n"); |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 5220 | if (test_bit(LOOP_RESYNC_NEEDED, |
| 5221 | &vha->dpc_flags)) |
| 5222 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5223 | } |
Duane Grigsby | d3bae93 | 2017-06-21 13:48:44 -0700 | [diff] [blame] | 5224 | if (vha->flags.nvme_enabled) { |
| 5225 | if (qla2x00_rff_id(vha, FC_TYPE_NVME)) { |
| 5226 | ql_dbg(ql_dbg_disc, vha, 0x2049, |
| 5227 | "Register NVME FC Type Features failed.\n"); |
| 5228 | } |
| 5229 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5230 | if (qla2x00_rnn_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5231 | /* EMPTY */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5232 | ql_dbg(ql_dbg_disc, vha, 0x2104, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5233 | "Register Node Name failed.\n"); |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 5234 | if (test_bit(LOOP_RESYNC_NEEDED, |
| 5235 | &vha->dpc_flags)) |
| 5236 | break; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5237 | } else if (qla2x00_rsnn_nn(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5238 | /* EMPTY */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5239 | ql_dbg(ql_dbg_disc, vha, 0x209b, |
Colin Ian King | 0bf0efa | 2017-06-30 14:47:41 +0100 | [diff] [blame] | 5240 | "Register Symbolic Node Name failed.\n"); |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 5241 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 5242 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5243 | } |
| 5244 | } |
| 5245 | |
Joe Carnuccio | 827210b | 2013-02-08 01:57:57 -0500 | [diff] [blame] | 5246 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 5247 | /* Mark the time right before querying FW for connected ports. |
| 5248 | * This process is long, asynchronous and by the time it's done, |
| 5249 | * collected information might not be accurate anymore. E.g. |
| 5250 | * disconnected port might have re-connected and a brand new |
| 5251 | * session has been created. In this case session's generation |
| 5252 | * will be newer than discovery_gen. */ |
| 5253 | qlt_do_generation_tick(vha, &discovery_gen); |
| 5254 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 5255 | if (USE_ASYNC_SCAN(ha)) { |
| 5256 | rval = QLA_SUCCESS; |
| 5257 | rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI); |
| 5258 | if (rval) |
| 5259 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 5260 | } else { |
Quinn Tran | f352eeb | 2017-12-28 12:33:35 -0800 | [diff] [blame] | 5261 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 5262 | fcport->scan_state = QLA_FCPORT_SCAN; |
| 5263 | |
Quinn Tran | a423994 | 2017-12-28 12:33:26 -0800 | [diff] [blame] | 5264 | rval = qla2x00_find_all_fabric_devs(vha); |
| 5265 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5266 | if (rval != QLA_SUCCESS) |
| 5267 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5268 | } while (0); |
| 5269 | |
Duane Grigsby | e84067d | 2017-06-21 13:48:43 -0700 | [diff] [blame] | 5270 | if (!vha->nvme_local_port && vha->flags.nvme_enabled) |
| 5271 | qla_nvme_register_hba(vha); |
| 5272 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5273 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5274 | ql_dbg(ql_dbg_disc, vha, 0x2068, |
| 5275 | "Configure fabric error exit rval=%d.\n", rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5276 | |
| 5277 | return (rval); |
| 5278 | } |
| 5279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5280 | /* |
| 5281 | * qla2x00_find_all_fabric_devs |
| 5282 | * |
| 5283 | * Input: |
| 5284 | * ha = adapter block pointer. |
| 5285 | * dev = database device entry pointer. |
| 5286 | * |
| 5287 | * Returns: |
| 5288 | * 0 = success. |
| 5289 | * |
| 5290 | * Context: |
| 5291 | * Kernel context. |
| 5292 | */ |
| 5293 | static int |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5294 | qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5295 | { |
| 5296 | int rval; |
| 5297 | uint16_t loop_id; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5298 | fc_port_t *fcport, *new_fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5299 | int found; |
| 5300 | |
| 5301 | sw_info_t *swl; |
| 5302 | int swl_idx; |
| 5303 | int first_dev, last_dev; |
Mike Waychison | 1516ef4 | 2010-05-04 15:01:31 -0700 | [diff] [blame] | 5304 | port_id_t wrap = {}, nxt_d_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5305 | struct qla_hw_data *ha = vha->hw; |
Chad Dupuis | bb4cf5b | 2013-02-08 01:58:01 -0500 | [diff] [blame] | 5306 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5307 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5308 | |
| 5309 | rval = QLA_SUCCESS; |
| 5310 | |
| 5311 | /* Try GID_PT to get device list, else GAN. */ |
Andrew Vasquez | 7a67735 | 2012-02-09 11:15:56 -0800 | [diff] [blame] | 5312 | if (!ha->swl) |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 5313 | ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t), |
Andrew Vasquez | 7a67735 | 2012-02-09 11:15:56 -0800 | [diff] [blame] | 5314 | GFP_KERNEL); |
| 5315 | swl = ha->swl; |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 5316 | if (!swl) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5317 | /*EMPTY*/ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5318 | ql_dbg(ql_dbg_disc, vha, 0x209c, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5319 | "GID_PT allocations failed, fallback on GA_NXT.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5320 | } else { |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 5321 | memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5322 | if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5323 | swl = NULL; |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 5324 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 5325 | return rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5326 | } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5327 | swl = NULL; |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 5328 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 5329 | return rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5330 | } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5331 | swl = NULL; |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 5332 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 5333 | return rval; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5334 | } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) { |
| 5335 | swl = NULL; |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 5336 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 5337 | return rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5338 | } |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 5339 | |
| 5340 | /* If other queries succeeded probe for FC-4 type */ |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 5341 | if (swl) { |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 5342 | qla2x00_gff_id(vha, swl); |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 5343 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 5344 | return rval; |
| 5345 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5346 | } |
| 5347 | swl_idx = 0; |
| 5348 | |
| 5349 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5350 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5351 | if (new_fcport == NULL) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5352 | ql_log(ql_log_warn, vha, 0x209d, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5353 | "Failed to allocate memory for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5354 | return (QLA_MEMORY_ALLOC_FAILED); |
| 5355 | } |
| 5356 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5357 | /* Set start port ID scan at adapter ID. */ |
| 5358 | first_dev = 1; |
| 5359 | last_dev = 0; |
| 5360 | |
| 5361 | /* Starting free loop ID. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5362 | loop_id = ha->min_external_loopid; |
| 5363 | for (; loop_id <= ha->max_loop_id; loop_id++) { |
| 5364 | if (qla2x00_is_reserved_id(vha, loop_id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5365 | continue; |
| 5366 | |
Giridhar Malavali | 3a6478d | 2010-05-28 15:08:20 -0700 | [diff] [blame] | 5367 | if (ha->current_topology == ISP_CFG_FL && |
| 5368 | (atomic_read(&vha->loop_down_timer) || |
| 5369 | LOOP_TRANSITION(vha))) { |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 5370 | atomic_set(&vha->loop_down_timer, 0); |
| 5371 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 5372 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5373 | break; |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 5374 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5375 | |
| 5376 | if (swl != NULL) { |
| 5377 | if (last_dev) { |
| 5378 | wrap.b24 = new_fcport->d_id.b24; |
| 5379 | } else { |
| 5380 | new_fcport->d_id.b24 = swl[swl_idx].d_id.b24; |
| 5381 | memcpy(new_fcport->node_name, |
| 5382 | swl[swl_idx].node_name, WWN_SIZE); |
| 5383 | memcpy(new_fcport->port_name, |
| 5384 | swl[swl_idx].port_name, WWN_SIZE); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 5385 | memcpy(new_fcport->fabric_port_name, |
| 5386 | swl[swl_idx].fabric_port_name, WWN_SIZE); |
| 5387 | new_fcport->fp_speed = swl[swl_idx].fp_speed; |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 5388 | new_fcport->fc4_type = swl[swl_idx].fc4_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5389 | |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 5390 | new_fcport->nvme_flag = 0; |
Darren Trap | 1a28faa | 2017-08-30 10:16:48 -0700 | [diff] [blame] | 5391 | new_fcport->fc4f_nvme = 0; |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 5392 | if (vha->flags.nvme_enabled && |
| 5393 | swl[swl_idx].fc4f_nvme) { |
| 5394 | new_fcport->fc4f_nvme = |
| 5395 | swl[swl_idx].fc4f_nvme; |
| 5396 | ql_log(ql_log_info, vha, 0x2131, |
| 5397 | "FOUND: NVME port %8phC as FC Type 28h\n", |
| 5398 | new_fcport->port_name); |
| 5399 | } |
| 5400 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5401 | if (swl[swl_idx].d_id.b.rsvd_1 != 0) { |
| 5402 | last_dev = 1; |
| 5403 | } |
| 5404 | swl_idx++; |
| 5405 | } |
| 5406 | } else { |
| 5407 | /* Send GA_NXT to the switch */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5408 | rval = qla2x00_ga_nxt(vha, new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5409 | if (rval != QLA_SUCCESS) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5410 | ql_log(ql_log_warn, vha, 0x209e, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5411 | "SNS scan failed -- assuming " |
| 5412 | "zero-entry result.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5413 | rval = QLA_SUCCESS; |
| 5414 | break; |
| 5415 | } |
| 5416 | } |
| 5417 | |
| 5418 | /* If wrap on switch device list, exit. */ |
| 5419 | if (first_dev) { |
| 5420 | wrap.b24 = new_fcport->d_id.b24; |
| 5421 | first_dev = 0; |
| 5422 | } else if (new_fcport->d_id.b24 == wrap.b24) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5423 | ql_dbg(ql_dbg_disc, vha, 0x209f, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5424 | "Device wrap (%02x%02x%02x).\n", |
| 5425 | new_fcport->d_id.b.domain, |
| 5426 | new_fcport->d_id.b.area, |
| 5427 | new_fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5428 | break; |
| 5429 | } |
| 5430 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5431 | /* Bypass if same physical adapter. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5432 | if (new_fcport->d_id.b24 == base_vha->d_id.b24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5433 | continue; |
| 5434 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5435 | /* Bypass virtual ports of the same host. */ |
Chad Dupuis | bb4cf5b | 2013-02-08 01:58:01 -0500 | [diff] [blame] | 5436 | if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24)) |
| 5437 | continue; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5438 | |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 5439 | /* Bypass if same domain and area of adapter. */ |
| 5440 | if (((new_fcport->d_id.b24 & 0xffff00) == |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5441 | (vha->d_id.b24 & 0xffff00)) && ha->current_topology == |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 5442 | ISP_CFG_FL) |
| 5443 | continue; |
| 5444 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5445 | /* Bypass reserved domain fields. */ |
| 5446 | if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0) |
| 5447 | continue; |
| 5448 | |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 5449 | /* Bypass ports whose FCP-4 type is not FCP_SCSI */ |
Chad Dupuis | 4da26e1 | 2010-10-15 11:27:40 -0700 | [diff] [blame] | 5450 | if (ql2xgffidenable && |
| 5451 | (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI && |
| 5452 | new_fcport->fc4_type != FC4_TYPE_UNKNOWN)) |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 5453 | continue; |
| 5454 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5455 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 5456 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5457 | /* Locate matching device in database. */ |
| 5458 | found = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5459 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5460 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 5461 | WWN_SIZE)) |
| 5462 | continue; |
| 5463 | |
Joe Carnuccio | 827210b | 2013-02-08 01:57:57 -0500 | [diff] [blame] | 5464 | fcport->scan_state = QLA_FCPORT_FOUND; |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 5465 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5466 | found++; |
| 5467 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 5468 | /* Update port state. */ |
| 5469 | memcpy(fcport->fabric_port_name, |
| 5470 | new_fcport->fabric_port_name, WWN_SIZE); |
| 5471 | fcport->fp_speed = new_fcport->fp_speed; |
| 5472 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5473 | /* |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 5474 | * If address the same and state FCS_ONLINE |
| 5475 | * (or in target mode), nothing changed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5476 | */ |
| 5477 | if (fcport->d_id.b24 == new_fcport->d_id.b24 && |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 5478 | (atomic_read(&fcport->state) == FCS_ONLINE || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5479 | (vha->host->active_mode == MODE_TARGET))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5480 | break; |
| 5481 | } |
| 5482 | |
| 5483 | /* |
| 5484 | * If device was not a fabric device before. |
| 5485 | */ |
| 5486 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 5487 | fcport->d_id.b24 = new_fcport->d_id.b24; |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 5488 | qla2x00_clear_loop_id(fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5489 | fcport->flags |= (FCF_FABRIC_DEVICE | |
| 5490 | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5491 | break; |
| 5492 | } |
| 5493 | |
| 5494 | /* |
| 5495 | * Port ID changed or device was marked to be updated; |
| 5496 | * Log it out if still logged in and mark it for |
| 5497 | * relogin later. |
| 5498 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5499 | if (qla_tgt_mode_enabled(base_vha)) { |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 5500 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080, |
| 5501 | "port changed FC ID, %8phC" |
| 5502 | " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n", |
| 5503 | fcport->port_name, |
| 5504 | fcport->d_id.b.domain, |
| 5505 | fcport->d_id.b.area, |
| 5506 | fcport->d_id.b.al_pa, |
| 5507 | fcport->loop_id, |
| 5508 | new_fcport->d_id.b.domain, |
| 5509 | new_fcport->d_id.b.area, |
| 5510 | new_fcport->d_id.b.al_pa); |
| 5511 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 5512 | break; |
| 5513 | } |
| 5514 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5515 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 5516 | fcport->flags |= FCF_LOGIN_NEEDED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5517 | break; |
| 5518 | } |
| 5519 | |
Darren Trapp | 9dd9686 | 2018-03-20 23:09:32 -0700 | [diff] [blame^] | 5520 | if (fcport->fc4f_nvme) { |
| 5521 | if (fcport->disc_state == DSC_DELETE_PEND) { |
| 5522 | fcport->disc_state = DSC_GNL; |
| 5523 | vha->fcport_count--; |
| 5524 | fcport->login_succ = 0; |
| 5525 | } |
| 5526 | } |
| 5527 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5528 | if (found) { |
| 5529 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5530 | continue; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5531 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5532 | /* If device was not in our fcports list, then add it. */ |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 5533 | new_fcport->scan_state = QLA_FCPORT_FOUND; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5534 | list_add_tail(&new_fcport->list, &vha->vp_fcports); |
| 5535 | |
| 5536 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 5537 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5538 | |
| 5539 | /* Allocate a new replacement fcport. */ |
| 5540 | nxt_d_id.b24 = new_fcport->d_id.b24; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5541 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5542 | if (new_fcport == NULL) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5543 | ql_log(ql_log_warn, vha, 0xd032, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5544 | "Memory allocation failed for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5545 | return (QLA_MEMORY_ALLOC_FAILED); |
| 5546 | } |
| 5547 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
| 5548 | new_fcport->d_id.b24 = nxt_d_id.b24; |
| 5549 | } |
| 5550 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5551 | qla2x00_free_fcport(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5552 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5553 | /* |
| 5554 | * Logout all previous fabric dev marked lost, except FCP2 devices. |
| 5555 | */ |
| 5556 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 5557 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 5558 | break; |
| 5559 | |
| 5560 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 || |
| 5561 | (fcport->flags & FCF_LOGIN_NEEDED) == 0) |
| 5562 | continue; |
| 5563 | |
| 5564 | if (fcport->scan_state == QLA_FCPORT_SCAN) { |
| 5565 | if ((qla_dual_mode_enabled(vha) || |
| 5566 | qla_ini_mode_enabled(vha)) && |
| 5567 | atomic_read(&fcport->state) == FCS_ONLINE) { |
| 5568 | qla2x00_mark_device_lost(vha, fcport, |
| 5569 | ql2xplogiabsentdevice, 0); |
| 5570 | if (fcport->loop_id != FC_NO_LOOP_ID && |
| 5571 | (fcport->flags & FCF_FCP2_DEVICE) == 0 && |
| 5572 | fcport->port_type != FCT_INITIATOR && |
| 5573 | fcport->port_type != FCT_BROADCAST) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5574 | ql_dbg(ql_dbg_disc, vha, 0x20f0, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5575 | "%s %d %8phC post del sess\n", |
| 5576 | __func__, __LINE__, |
| 5577 | fcport->port_name); |
Quinn Tran | d8630bb | 2017-12-28 12:33:43 -0800 | [diff] [blame] | 5578 | qlt_schedule_sess_for_deletion(fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5579 | continue; |
| 5580 | } |
| 5581 | } |
| 5582 | } |
| 5583 | |
| 5584 | if (fcport->scan_state == QLA_FCPORT_FOUND) |
| 5585 | qla24xx_fcport_handle_login(vha, fcport); |
| 5586 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5587 | return (rval); |
| 5588 | } |
| 5589 | |
| 5590 | /* |
| 5591 | * qla2x00_find_new_loop_id |
| 5592 | * Scan through our port list and find a new usable loop ID. |
| 5593 | * |
| 5594 | * Input: |
| 5595 | * ha: adapter state pointer. |
| 5596 | * dev: port structure pointer. |
| 5597 | * |
| 5598 | * Returns: |
| 5599 | * qla2x00 local function return status code. |
| 5600 | * |
| 5601 | * Context: |
| 5602 | * Kernel context. |
| 5603 | */ |
Joe Carnuccio | 03bcfb5 | 2011-03-30 11:46:27 -0700 | [diff] [blame] | 5604 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5605 | 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] | 5606 | { |
| 5607 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5608 | struct qla_hw_data *ha = vha->hw; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5609 | unsigned long flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5610 | |
| 5611 | rval = QLA_SUCCESS; |
| 5612 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 5613 | spin_lock_irqsave(&ha->vport_slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5614 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 5615 | dev->loop_id = find_first_zero_bit(ha->loop_id_map, |
| 5616 | LOOPID_MAP_SIZE); |
| 5617 | if (dev->loop_id >= LOOPID_MAP_SIZE || |
| 5618 | qla2x00_is_reserved_id(vha, dev->loop_id)) { |
| 5619 | dev->loop_id = FC_NO_LOOP_ID; |
| 5620 | rval = QLA_FUNCTION_FAILED; |
| 5621 | } else |
| 5622 | set_bit(dev->loop_id, ha->loop_id_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5623 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 5624 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5625 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 5626 | if (rval == QLA_SUCCESS) |
| 5627 | ql_dbg(ql_dbg_disc, dev->vha, 0x2086, |
| 5628 | "Assigning new loopid=%x, portid=%x.\n", |
| 5629 | dev->loop_id, dev->d_id.b24); |
| 5630 | else |
| 5631 | ql_log(ql_log_warn, dev->vha, 0x2087, |
| 5632 | "No loop_id's available, portid=%x.\n", |
| 5633 | dev->d_id.b24); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5634 | |
| 5635 | return (rval); |
| 5636 | } |
| 5637 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5638 | |
| 5639 | /* |
| 5640 | * qla2x00_fabric_login |
| 5641 | * Issue fabric login command. |
| 5642 | * |
| 5643 | * Input: |
| 5644 | * ha = adapter block pointer. |
| 5645 | * device = pointer to FC device type structure. |
| 5646 | * |
| 5647 | * Returns: |
| 5648 | * 0 - Login successfully |
| 5649 | * 1 - Login failed |
| 5650 | * 2 - Initiator device |
| 5651 | * 3 - Fatal error |
| 5652 | */ |
| 5653 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5654 | qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5655 | uint16_t *next_loopid) |
| 5656 | { |
| 5657 | int rval; |
| 5658 | int retry; |
| 5659 | uint16_t tmp_loopid; |
| 5660 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5661 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5662 | |
| 5663 | retry = 0; |
| 5664 | tmp_loopid = 0; |
| 5665 | |
| 5666 | for (;;) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5667 | ql_dbg(ql_dbg_disc, vha, 0x2000, |
| 5668 | "Trying Fabric Login w/loop id 0x%04x for port " |
| 5669 | "%02x%02x%02x.\n", |
| 5670 | fcport->loop_id, fcport->d_id.b.domain, |
| 5671 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5672 | |
| 5673 | /* Login fcport on switch. */ |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 5674 | rval = ha->isp_ops->fabric_login(vha, fcport->loop_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5675 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 5676 | fcport->d_id.b.al_pa, mb, BIT_0); |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 5677 | if (rval != QLA_SUCCESS) { |
| 5678 | return rval; |
| 5679 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5680 | if (mb[0] == MBS_PORT_ID_USED) { |
| 5681 | /* |
| 5682 | * Device has another loop ID. The firmware team |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5683 | * recommends the driver perform an implicit login with |
| 5684 | * the specified ID again. The ID we just used is save |
| 5685 | * here so we return with an ID that can be tried by |
| 5686 | * the next login. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5687 | */ |
| 5688 | retry++; |
| 5689 | tmp_loopid = fcport->loop_id; |
| 5690 | fcport->loop_id = mb[1]; |
| 5691 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5692 | ql_dbg(ql_dbg_disc, vha, 0x2001, |
| 5693 | "Fabric Login: port in use - next loop " |
| 5694 | "id=0x%04x, port id= %02x%02x%02x.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5695 | fcport->loop_id, fcport->d_id.b.domain, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5696 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5697 | |
| 5698 | } else if (mb[0] == MBS_COMMAND_COMPLETE) { |
| 5699 | /* |
| 5700 | * Login succeeded. |
| 5701 | */ |
| 5702 | if (retry) { |
| 5703 | /* A retry occurred before. */ |
| 5704 | *next_loopid = tmp_loopid; |
| 5705 | } else { |
| 5706 | /* |
| 5707 | * No retry occurred before. Just increment the |
| 5708 | * ID value for next login. |
| 5709 | */ |
| 5710 | *next_loopid = (fcport->loop_id + 1); |
| 5711 | } |
| 5712 | |
| 5713 | if (mb[1] & BIT_0) { |
| 5714 | fcport->port_type = FCT_INITIATOR; |
| 5715 | } else { |
| 5716 | fcport->port_type = FCT_TARGET; |
| 5717 | if (mb[1] & BIT_1) { |
Santosh Vernekar | 8474f3a | 2009-08-25 11:36:16 -0700 | [diff] [blame] | 5718 | fcport->flags |= FCF_FCP2_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5719 | } |
| 5720 | } |
| 5721 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 5722 | if (mb[10] & BIT_0) |
| 5723 | fcport->supported_classes |= FC_COS_CLASS2; |
| 5724 | if (mb[10] & BIT_1) |
| 5725 | fcport->supported_classes |= FC_COS_CLASS3; |
| 5726 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5727 | if (IS_FWI2_CAPABLE(ha)) { |
| 5728 | if (mb[10] & BIT_7) |
| 5729 | fcport->flags |= |
| 5730 | FCF_CONF_COMP_SUPPORTED; |
| 5731 | } |
| 5732 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5733 | rval = QLA_SUCCESS; |
| 5734 | break; |
| 5735 | } else if (mb[0] == MBS_LOOP_ID_USED) { |
| 5736 | /* |
| 5737 | * Loop ID already used, try next loop ID. |
| 5738 | */ |
| 5739 | fcport->loop_id++; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5740 | rval = qla2x00_find_new_loop_id(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5741 | if (rval != QLA_SUCCESS) { |
| 5742 | /* Ran out of loop IDs to use */ |
| 5743 | break; |
| 5744 | } |
| 5745 | } else if (mb[0] == MBS_COMMAND_ERROR) { |
| 5746 | /* |
| 5747 | * Firmware possibly timed out during login. If NO |
| 5748 | * retries are left to do then the device is declared |
| 5749 | * dead. |
| 5750 | */ |
| 5751 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5752 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 5753 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 5754 | fcport->d_id.b.al_pa); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5755 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5756 | |
| 5757 | rval = 1; |
| 5758 | break; |
| 5759 | } else { |
| 5760 | /* |
| 5761 | * unrecoverable / not handled error |
| 5762 | */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5763 | ql_dbg(ql_dbg_disc, vha, 0x2002, |
| 5764 | "Failed=%x port_id=%02x%02x%02x loop_id=%x " |
| 5765 | "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain, |
| 5766 | fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 5767 | fcport->loop_id, jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5768 | |
| 5769 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5770 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 5771 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 5772 | fcport->d_id.b.al_pa); |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 5773 | qla2x00_clear_loop_id(fcport); |
Andrew Vasquez | 0eedfcf | 2005-10-27 11:09:38 -0700 | [diff] [blame] | 5774 | fcport->login_retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5775 | |
| 5776 | rval = 3; |
| 5777 | break; |
| 5778 | } |
| 5779 | } |
| 5780 | |
| 5781 | return (rval); |
| 5782 | } |
| 5783 | |
| 5784 | /* |
| 5785 | * qla2x00_local_device_login |
| 5786 | * Issue local device login command. |
| 5787 | * |
| 5788 | * Input: |
| 5789 | * ha = adapter block pointer. |
| 5790 | * loop_id = loop id of device to login to. |
| 5791 | * |
| 5792 | * Returns (Where's the #define!!!!): |
| 5793 | * 0 - Login successfully |
| 5794 | * 1 - Login failed |
| 5795 | * 3 - Fatal error |
| 5796 | */ |
| 5797 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5798 | 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] | 5799 | { |
| 5800 | int rval; |
| 5801 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
| 5802 | |
| 5803 | memset(mb, 0, sizeof(mb)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5804 | rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5805 | if (rval == QLA_SUCCESS) { |
| 5806 | /* Interrogate mailbox registers for any errors */ |
| 5807 | if (mb[0] == MBS_COMMAND_ERROR) |
| 5808 | rval = 1; |
| 5809 | else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR) |
| 5810 | /* device not in PCB table */ |
| 5811 | rval = 3; |
| 5812 | } |
| 5813 | |
| 5814 | return (rval); |
| 5815 | } |
| 5816 | |
| 5817 | /* |
| 5818 | * qla2x00_loop_resync |
| 5819 | * Resync with fibre channel devices. |
| 5820 | * |
| 5821 | * Input: |
| 5822 | * ha = adapter block pointer. |
| 5823 | * |
| 5824 | * Returns: |
| 5825 | * 0 = success |
| 5826 | */ |
| 5827 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5828 | qla2x00_loop_resync(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5829 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5830 | int rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5831 | uint32_t wait_time; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 5832 | struct req_que *req; |
| 5833 | struct rsp_que *rsp; |
| 5834 | |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 5835 | req = vha->req; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 5836 | rsp = req->rsp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5837 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5838 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 5839 | if (vha->flags.online) { |
| 5840 | if (!(rval = qla2x00_fw_ready(vha))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5841 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 5842 | wait_time = 256; |
| 5843 | do { |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 5844 | if (!IS_QLAFX00(vha->hw)) { |
| 5845 | /* |
| 5846 | * Issue a marker after FW becomes |
| 5847 | * ready. |
| 5848 | */ |
| 5849 | qla2x00_marker(vha, req, rsp, 0, 0, |
| 5850 | MK_SYNC_ALL); |
| 5851 | vha->marker_needed = 0; |
| 5852 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5853 | |
| 5854 | /* Remap devices on Loop. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5855 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5856 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 5857 | if (IS_QLAFX00(vha->hw)) |
| 5858 | qlafx00_configure_devices(vha); |
| 5859 | else |
| 5860 | qla2x00_configure_loop(vha); |
| 5861 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5862 | wait_time--; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5863 | } while (!atomic_read(&vha->loop_down_timer) && |
| 5864 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
| 5865 | && wait_time && (test_bit(LOOP_RESYNC_NEEDED, |
| 5866 | &vha->dpc_flags))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5867 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5868 | } |
| 5869 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5870 | if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5871 | return (QLA_FUNCTION_FAILED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5872 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5873 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5874 | ql_dbg(ql_dbg_disc, vha, 0x206c, |
| 5875 | "%s *** FAILED ***.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5876 | |
| 5877 | return (rval); |
| 5878 | } |
| 5879 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5880 | /* |
| 5881 | * qla2x00_perform_loop_resync |
| 5882 | * Description: This function will set the appropriate flags and call |
| 5883 | * qla2x00_loop_resync. If successful loop will be resynced |
| 5884 | * Arguments : scsi_qla_host_t pointer |
| 5885 | * returm : Success or Failure |
| 5886 | */ |
| 5887 | |
| 5888 | int qla2x00_perform_loop_resync(scsi_qla_host_t *ha) |
| 5889 | { |
| 5890 | int32_t rval = 0; |
| 5891 | |
| 5892 | if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) { |
| 5893 | /*Configure the flags so that resync happens properly*/ |
| 5894 | atomic_set(&ha->loop_down_timer, 0); |
| 5895 | if (!(ha->device_flags & DFLG_NO_CABLE)) { |
| 5896 | atomic_set(&ha->loop_state, LOOP_UP); |
| 5897 | set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); |
| 5898 | set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags); |
| 5899 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
| 5900 | |
| 5901 | rval = qla2x00_loop_resync(ha); |
| 5902 | } else |
| 5903 | atomic_set(&ha->loop_state, LOOP_DEAD); |
| 5904 | |
| 5905 | clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags); |
| 5906 | } |
| 5907 | |
| 5908 | return rval; |
| 5909 | } |
| 5910 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5911 | void |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 5912 | qla2x00_update_fcports(scsi_qla_host_t *base_vha) |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5913 | { |
| 5914 | fc_port_t *fcport; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5915 | struct scsi_qla_host *vha; |
| 5916 | struct qla_hw_data *ha = base_vha->hw; |
| 5917 | unsigned long flags; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5918 | |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5919 | spin_lock_irqsave(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5920 | /* Go with deferred removal of rport references. */ |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5921 | list_for_each_entry(vha, &base_vha->hw->vp_list, list) { |
| 5922 | atomic_inc(&vha->vref_count); |
| 5923 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Dan Carpenter | 8ae598d | 2010-12-21 16:00:15 -0800 | [diff] [blame] | 5924 | if (fcport->drport && |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5925 | atomic_read(&fcport->state) != FCS_UNCONFIGURED) { |
| 5926 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 5927 | qla2x00_rport_del(fcport); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 5928 | |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5929 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5930 | } |
| 5931 | } |
| 5932 | atomic_dec(&vha->vref_count); |
Joe Carnuccio | c4a9b53 | 2017-03-15 09:48:43 -0700 | [diff] [blame] | 5933 | wake_up(&vha->vref_waitq); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5934 | } |
| 5935 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5936 | } |
| 5937 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5938 | /* Assumes idc_lock always held on entry */ |
| 5939 | void |
| 5940 | qla83xx_reset_ownership(scsi_qla_host_t *vha) |
| 5941 | { |
| 5942 | struct qla_hw_data *ha = vha->hw; |
| 5943 | uint32_t drv_presence, drv_presence_mask; |
| 5944 | uint32_t dev_part_info1, dev_part_info2, class_type; |
| 5945 | uint32_t class_type_mask = 0x3; |
| 5946 | uint16_t fcoe_other_function = 0xffff, i; |
| 5947 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 5948 | if (IS_QLA8044(ha)) { |
| 5949 | drv_presence = qla8044_rd_direct(vha, |
| 5950 | QLA8044_CRB_DRV_ACTIVE_INDEX); |
| 5951 | dev_part_info1 = qla8044_rd_direct(vha, |
| 5952 | QLA8044_CRB_DEV_PART_INFO_INDEX); |
| 5953 | dev_part_info2 = qla8044_rd_direct(vha, |
| 5954 | QLA8044_CRB_DEV_PART_INFO2); |
| 5955 | } else { |
| 5956 | qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); |
| 5957 | qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1); |
| 5958 | qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2); |
| 5959 | } |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5960 | for (i = 0; i < 8; i++) { |
| 5961 | class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask); |
| 5962 | if ((class_type == QLA83XX_CLASS_TYPE_FCOE) && |
| 5963 | (i != ha->portnum)) { |
| 5964 | fcoe_other_function = i; |
| 5965 | break; |
| 5966 | } |
| 5967 | } |
| 5968 | if (fcoe_other_function == 0xffff) { |
| 5969 | for (i = 0; i < 8; i++) { |
| 5970 | class_type = ((dev_part_info2 >> (i * 4)) & |
| 5971 | class_type_mask); |
| 5972 | if ((class_type == QLA83XX_CLASS_TYPE_FCOE) && |
| 5973 | ((i + 8) != ha->portnum)) { |
| 5974 | fcoe_other_function = i + 8; |
| 5975 | break; |
| 5976 | } |
| 5977 | } |
| 5978 | } |
| 5979 | /* |
| 5980 | * Prepare drv-presence mask based on fcoe functions present. |
| 5981 | * However consider only valid physical fcoe function numbers (0-15). |
| 5982 | */ |
| 5983 | drv_presence_mask = ~((1 << (ha->portnum)) | |
| 5984 | ((fcoe_other_function == 0xffff) ? |
| 5985 | 0 : (1 << (fcoe_other_function)))); |
| 5986 | |
| 5987 | /* We are the reset owner iff: |
| 5988 | * - No other protocol drivers present. |
| 5989 | * - This is the lowest among fcoe functions. */ |
| 5990 | if (!(drv_presence & drv_presence_mask) && |
| 5991 | (ha->portnum < fcoe_other_function)) { |
| 5992 | ql_dbg(ql_dbg_p3p, vha, 0xb07f, |
| 5993 | "This host is Reset owner.\n"); |
| 5994 | ha->flags.nic_core_reset_owner = 1; |
| 5995 | } |
| 5996 | } |
| 5997 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5998 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5999 | __qla83xx_set_drv_ack(scsi_qla_host_t *vha) |
| 6000 | { |
| 6001 | int rval = QLA_SUCCESS; |
| 6002 | struct qla_hw_data *ha = vha->hw; |
| 6003 | uint32_t drv_ack; |
| 6004 | |
| 6005 | rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack); |
| 6006 | if (rval == QLA_SUCCESS) { |
| 6007 | drv_ack |= (1 << ha->portnum); |
| 6008 | rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack); |
| 6009 | } |
| 6010 | |
| 6011 | return rval; |
| 6012 | } |
| 6013 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 6014 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 6015 | __qla83xx_clear_drv_ack(scsi_qla_host_t *vha) |
| 6016 | { |
| 6017 | int rval = QLA_SUCCESS; |
| 6018 | struct qla_hw_data *ha = vha->hw; |
| 6019 | uint32_t drv_ack; |
| 6020 | |
| 6021 | rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack); |
| 6022 | if (rval == QLA_SUCCESS) { |
| 6023 | drv_ack &= ~(1 << ha->portnum); |
| 6024 | rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack); |
| 6025 | } |
| 6026 | |
| 6027 | return rval; |
| 6028 | } |
| 6029 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 6030 | static const char * |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 6031 | qla83xx_dev_state_to_string(uint32_t dev_state) |
| 6032 | { |
| 6033 | switch (dev_state) { |
| 6034 | case QLA8XXX_DEV_COLD: |
| 6035 | return "COLD/RE-INIT"; |
| 6036 | case QLA8XXX_DEV_INITIALIZING: |
| 6037 | return "INITIALIZING"; |
| 6038 | case QLA8XXX_DEV_READY: |
| 6039 | return "READY"; |
| 6040 | case QLA8XXX_DEV_NEED_RESET: |
| 6041 | return "NEED RESET"; |
| 6042 | case QLA8XXX_DEV_NEED_QUIESCENT: |
| 6043 | return "NEED QUIESCENT"; |
| 6044 | case QLA8XXX_DEV_FAILED: |
| 6045 | return "FAILED"; |
| 6046 | case QLA8XXX_DEV_QUIESCENT: |
| 6047 | return "QUIESCENT"; |
| 6048 | default: |
| 6049 | return "Unknown"; |
| 6050 | } |
| 6051 | } |
| 6052 | |
| 6053 | /* Assumes idc-lock always held on entry */ |
| 6054 | void |
| 6055 | qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type) |
| 6056 | { |
| 6057 | struct qla_hw_data *ha = vha->hw; |
| 6058 | uint32_t idc_audit_reg = 0, duration_secs = 0; |
| 6059 | |
| 6060 | switch (audit_type) { |
| 6061 | case IDC_AUDIT_TIMESTAMP: |
| 6062 | ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000); |
| 6063 | idc_audit_reg = (ha->portnum) | |
| 6064 | (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8); |
| 6065 | qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg); |
| 6066 | break; |
| 6067 | |
| 6068 | case IDC_AUDIT_COMPLETION: |
| 6069 | duration_secs = ((jiffies_to_msecs(jiffies) - |
| 6070 | jiffies_to_msecs(ha->idc_audit_ts)) / 1000); |
| 6071 | idc_audit_reg = (ha->portnum) | |
| 6072 | (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8); |
| 6073 | qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg); |
| 6074 | break; |
| 6075 | |
| 6076 | default: |
| 6077 | ql_log(ql_log_warn, vha, 0xb078, |
| 6078 | "Invalid audit type specified.\n"); |
| 6079 | break; |
| 6080 | } |
| 6081 | } |
| 6082 | |
| 6083 | /* Assumes idc_lock always held on entry */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 6084 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 6085 | qla83xx_initiating_reset(scsi_qla_host_t *vha) |
| 6086 | { |
| 6087 | struct qla_hw_data *ha = vha->hw; |
| 6088 | uint32_t idc_control, dev_state; |
| 6089 | |
| 6090 | __qla83xx_get_idc_control(vha, &idc_control); |
| 6091 | if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) { |
| 6092 | ql_log(ql_log_info, vha, 0xb080, |
| 6093 | "NIC Core reset has been disabled. idc-control=0x%x\n", |
| 6094 | idc_control); |
| 6095 | return QLA_FUNCTION_FAILED; |
| 6096 | } |
| 6097 | |
| 6098 | /* Set NEED-RESET iff in READY state and we are the reset-owner */ |
| 6099 | qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state); |
| 6100 | if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) { |
| 6101 | qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, |
| 6102 | QLA8XXX_DEV_NEED_RESET); |
| 6103 | ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n"); |
| 6104 | qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP); |
| 6105 | } else { |
| 6106 | const char *state = qla83xx_dev_state_to_string(dev_state); |
| 6107 | ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state); |
| 6108 | |
| 6109 | /* SV: XXX: Is timeout required here? */ |
| 6110 | /* Wait for IDC state change READY -> NEED_RESET */ |
| 6111 | while (dev_state == QLA8XXX_DEV_READY) { |
| 6112 | qla83xx_idc_unlock(vha, 0); |
| 6113 | msleep(200); |
| 6114 | qla83xx_idc_lock(vha, 0); |
| 6115 | qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state); |
| 6116 | } |
| 6117 | } |
| 6118 | |
| 6119 | /* Send IDC ack by writing to drv-ack register */ |
| 6120 | __qla83xx_set_drv_ack(vha); |
| 6121 | |
| 6122 | return QLA_SUCCESS; |
| 6123 | } |
| 6124 | |
| 6125 | int |
| 6126 | __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control) |
| 6127 | { |
| 6128 | return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control); |
| 6129 | } |
| 6130 | |
| 6131 | int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 6132 | __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control) |
| 6133 | { |
| 6134 | return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control); |
| 6135 | } |
| 6136 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 6137 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 6138 | qla83xx_check_driver_presence(scsi_qla_host_t *vha) |
| 6139 | { |
| 6140 | uint32_t drv_presence = 0; |
| 6141 | struct qla_hw_data *ha = vha->hw; |
| 6142 | |
| 6143 | qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); |
| 6144 | if (drv_presence & (1 << ha->portnum)) |
| 6145 | return QLA_SUCCESS; |
| 6146 | else |
| 6147 | return QLA_TEST_FAILED; |
| 6148 | } |
| 6149 | |
| 6150 | int |
| 6151 | qla83xx_nic_core_reset(scsi_qla_host_t *vha) |
| 6152 | { |
| 6153 | int rval = QLA_SUCCESS; |
| 6154 | struct qla_hw_data *ha = vha->hw; |
| 6155 | |
| 6156 | ql_dbg(ql_dbg_p3p, vha, 0xb058, |
| 6157 | "Entered %s().\n", __func__); |
| 6158 | |
| 6159 | if (vha->device_flags & DFLG_DEV_FAILED) { |
| 6160 | ql_log(ql_log_warn, vha, 0xb059, |
| 6161 | "Device in unrecoverable FAILED state.\n"); |
| 6162 | return QLA_FUNCTION_FAILED; |
| 6163 | } |
| 6164 | |
| 6165 | qla83xx_idc_lock(vha, 0); |
| 6166 | |
| 6167 | if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) { |
| 6168 | ql_log(ql_log_warn, vha, 0xb05a, |
| 6169 | "Function=0x%x has been removed from IDC participation.\n", |
| 6170 | ha->portnum); |
| 6171 | rval = QLA_FUNCTION_FAILED; |
| 6172 | goto exit; |
| 6173 | } |
| 6174 | |
| 6175 | qla83xx_reset_ownership(vha); |
| 6176 | |
| 6177 | rval = qla83xx_initiating_reset(vha); |
| 6178 | |
| 6179 | /* |
| 6180 | * Perform reset if we are the reset-owner, |
| 6181 | * else wait till IDC state changes to READY/FAILED. |
| 6182 | */ |
| 6183 | if (rval == QLA_SUCCESS) { |
| 6184 | rval = qla83xx_idc_state_handler(vha); |
| 6185 | |
| 6186 | if (rval == QLA_SUCCESS) |
| 6187 | ha->flags.nic_core_hung = 0; |
| 6188 | __qla83xx_clear_drv_ack(vha); |
| 6189 | } |
| 6190 | |
| 6191 | exit: |
| 6192 | qla83xx_idc_unlock(vha, 0); |
| 6193 | |
| 6194 | ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__); |
| 6195 | |
| 6196 | return rval; |
| 6197 | } |
| 6198 | |
Saurav Kashyap | 8117877 | 2012-08-22 14:21:04 -0400 | [diff] [blame] | 6199 | int |
| 6200 | qla2xxx_mctp_dump(scsi_qla_host_t *vha) |
| 6201 | { |
| 6202 | struct qla_hw_data *ha = vha->hw; |
| 6203 | int rval = QLA_FUNCTION_FAILED; |
| 6204 | |
| 6205 | if (!IS_MCTP_CAPABLE(ha)) { |
| 6206 | /* This message can be removed from the final version */ |
| 6207 | ql_log(ql_log_info, vha, 0x506d, |
| 6208 | "This board is not MCTP capable\n"); |
| 6209 | return rval; |
| 6210 | } |
| 6211 | |
| 6212 | if (!ha->mctp_dump) { |
| 6213 | ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev, |
| 6214 | MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL); |
| 6215 | |
| 6216 | if (!ha->mctp_dump) { |
| 6217 | ql_log(ql_log_warn, vha, 0x506e, |
| 6218 | "Failed to allocate memory for mctp dump\n"); |
| 6219 | return rval; |
| 6220 | } |
| 6221 | } |
| 6222 | |
| 6223 | #define MCTP_DUMP_STR_ADDR 0x00000000 |
| 6224 | rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma, |
| 6225 | MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4); |
| 6226 | if (rval != QLA_SUCCESS) { |
| 6227 | ql_log(ql_log_warn, vha, 0x506f, |
| 6228 | "Failed to capture mctp dump\n"); |
| 6229 | } else { |
| 6230 | ql_log(ql_log_info, vha, 0x5070, |
| 6231 | "Mctp dump capture for host (%ld/%p).\n", |
| 6232 | vha->host_no, ha->mctp_dump); |
| 6233 | ha->mctp_dumped = 1; |
| 6234 | } |
| 6235 | |
Saurav Kashyap | 409ee0f | 2012-08-22 14:21:29 -0400 | [diff] [blame] | 6236 | if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) { |
Saurav Kashyap | 8117877 | 2012-08-22 14:21:04 -0400 | [diff] [blame] | 6237 | ha->flags.nic_core_reset_hdlr_active = 1; |
| 6238 | rval = qla83xx_restart_nic_firmware(vha); |
| 6239 | if (rval) |
| 6240 | /* NIC Core reset failed. */ |
| 6241 | ql_log(ql_log_warn, vha, 0x5071, |
| 6242 | "Failed to restart nic firmware\n"); |
| 6243 | else |
| 6244 | ql_dbg(ql_dbg_p3p, vha, 0xb084, |
| 6245 | "Restarted NIC firmware successfully.\n"); |
| 6246 | ha->flags.nic_core_reset_hdlr_active = 0; |
| 6247 | } |
| 6248 | |
| 6249 | return rval; |
| 6250 | |
| 6251 | } |
| 6252 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 6253 | /* |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 6254 | * qla2x00_quiesce_io |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 6255 | * Description: This function will block the new I/Os |
| 6256 | * Its not aborting any I/Os as context |
| 6257 | * is not destroyed during quiescence |
| 6258 | * Arguments: scsi_qla_host_t |
| 6259 | * return : void |
| 6260 | */ |
| 6261 | void |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 6262 | qla2x00_quiesce_io(scsi_qla_host_t *vha) |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 6263 | { |
| 6264 | struct qla_hw_data *ha = vha->hw; |
| 6265 | struct scsi_qla_host *vp; |
| 6266 | |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 6267 | ql_dbg(ql_dbg_dpc, vha, 0x401d, |
| 6268 | "Quiescing I/O - ha=%p.\n", ha); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 6269 | |
| 6270 | atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); |
| 6271 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 6272 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 6273 | qla2x00_mark_all_devices_lost(vha, 0); |
| 6274 | list_for_each_entry(vp, &ha->vp_list, list) |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 6275 | qla2x00_mark_all_devices_lost(vp, 0); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 6276 | } else { |
| 6277 | if (!atomic_read(&vha->loop_down_timer)) |
| 6278 | atomic_set(&vha->loop_down_timer, |
| 6279 | LOOP_DOWN_TIME); |
| 6280 | } |
| 6281 | /* Wait for pending cmds to complete */ |
| 6282 | qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST); |
| 6283 | } |
| 6284 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6285 | void |
| 6286 | qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha) |
| 6287 | { |
| 6288 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 6289 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6290 | unsigned long flags; |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 6291 | fc_port_t *fcport; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 6292 | u16 i; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6293 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 6294 | /* For ISP82XX, driver waits for completion of the commands. |
| 6295 | * online flag should be set. |
| 6296 | */ |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 6297 | if (!(IS_P3P_TYPE(ha))) |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 6298 | vha->flags.online = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6299 | ha->flags.chip_reset_done = 0; |
| 6300 | clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Saurav Kashyap | 2be21fa | 2012-05-15 14:34:16 -0400 | [diff] [blame] | 6301 | vha->qla_stats.total_isp_aborts++; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6302 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6303 | ql_log(ql_log_info, vha, 0x00af, |
| 6304 | "Performing ISP error recovery - ha=%p.\n", ha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6305 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 6306 | /* For ISP82XX, reset_chip is just disabling interrupts. |
| 6307 | * Driver waits for the completion of the commands. |
| 6308 | * the interrupts need to be enabled. |
| 6309 | */ |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 6310 | if (!(IS_P3P_TYPE(ha))) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6311 | ha->isp_ops->reset_chip(vha); |
| 6312 | |
Quinn Tran | 9cd883f | 2017-12-28 12:33:24 -0800 | [diff] [blame] | 6313 | SAVE_TOPO(ha); |
| 6314 | ha->flags.rida_fmt2 = 0; |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 6315 | ha->flags.n2n_ae = 0; |
| 6316 | ha->flags.lip_ae = 0; |
| 6317 | ha->current_topology = 0; |
| 6318 | ha->flags.fw_started = 0; |
| 6319 | ha->flags.fw_init_done = 0; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 6320 | ha->base_qpair->chip_reset++; |
| 6321 | for (i = 0; i < ha->max_qpairs; i++) { |
| 6322 | if (ha->queue_pair_map[i]) |
| 6323 | ha->queue_pair_map[i]->chip_reset = |
| 6324 | ha->base_qpair->chip_reset; |
| 6325 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6326 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6327 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 6328 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 6329 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 6330 | qla2x00_mark_all_devices_lost(vha, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6331 | |
| 6332 | spin_lock_irqsave(&ha->vport_slock, flags); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 6333 | list_for_each_entry(vp, &ha->vp_list, list) { |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6334 | atomic_inc(&vp->vref_count); |
| 6335 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 6336 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6337 | qla2x00_mark_all_devices_lost(vp, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6338 | |
| 6339 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 6340 | atomic_dec(&vp->vref_count); |
| 6341 | } |
| 6342 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6343 | } else { |
| 6344 | if (!atomic_read(&vha->loop_down_timer)) |
| 6345 | atomic_set(&vha->loop_down_timer, |
| 6346 | LOOP_DOWN_TIME); |
| 6347 | } |
| 6348 | |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 6349 | /* Clear all async request states across all VPs. */ |
| 6350 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 6351 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 6352 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 6353 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 6354 | atomic_inc(&vp->vref_count); |
| 6355 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 6356 | |
| 6357 | list_for_each_entry(fcport, &vp->vp_fcports, list) |
| 6358 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 6359 | |
| 6360 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 6361 | atomic_dec(&vp->vref_count); |
| 6362 | } |
| 6363 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 6364 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 6365 | if (!ha->flags.eeh_busy) { |
| 6366 | /* Make sure for ISP 82XX IO DMA is complete */ |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 6367 | if (IS_P3P_TYPE(ha)) { |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 6368 | qla82xx_chip_reset_cleanup(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6369 | ql_log(ql_log_info, vha, 0x00b4, |
| 6370 | "Done chip reset cleanup.\n"); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6371 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 6372 | /* Done waiting for pending commands. |
| 6373 | * Reset the online flag. |
| 6374 | */ |
| 6375 | vha->flags.online = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6376 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6377 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 6378 | /* Requeue all commands in outstanding command list. */ |
| 6379 | qla2x00_abort_all_cmds(vha, DID_RESET << 16); |
| 6380 | } |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 6381 | /* memory barrier */ |
| 6382 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6383 | } |
| 6384 | |
| 6385 | /* |
| 6386 | * qla2x00_abort_isp |
| 6387 | * Resets ISP and aborts all outstanding commands. |
| 6388 | * |
| 6389 | * Input: |
| 6390 | * ha = adapter block pointer. |
| 6391 | * |
| 6392 | * Returns: |
| 6393 | * 0 = success |
| 6394 | */ |
| 6395 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6396 | qla2x00_abort_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6397 | { |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 6398 | int rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6399 | uint8_t status = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6400 | struct qla_hw_data *ha = vha->hw; |
| 6401 | struct scsi_qla_host *vp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6402 | struct req_que *req = ha->req_q_map[0]; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6403 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6404 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6405 | if (vha->flags.online) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6406 | qla2x00_abort_isp_cleanup(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6407 | |
Santosh Vernekar | a6171297 | 2012-08-22 14:21:13 -0400 | [diff] [blame] | 6408 | if (IS_QLA8031(ha)) { |
| 6409 | ql_dbg(ql_dbg_p3p, vha, 0xb05c, |
| 6410 | "Clearing fcoe driver presence.\n"); |
| 6411 | if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS) |
| 6412 | ql_dbg(ql_dbg_p3p, vha, 0xb073, |
| 6413 | "Error while clearing DRV-Presence.\n"); |
| 6414 | } |
| 6415 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 6416 | if (unlikely(pci_channel_offline(ha->pdev) && |
| 6417 | ha->flags.pci_channel_io_perm_failure)) { |
| 6418 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 6419 | status = 0; |
| 6420 | return status; |
| 6421 | } |
| 6422 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6423 | ha->isp_ops->get_flash_version(vha, req->ring); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 6424 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6425 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6426 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6427 | if (!qla2x00_restart_isp(vha)) { |
| 6428 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6429 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6430 | if (!atomic_read(&vha->loop_down_timer)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6431 | /* |
| 6432 | * Issue marker command only when we are going |
| 6433 | * to start the I/O . |
| 6434 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6435 | vha->marker_needed = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6436 | } |
| 6437 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6438 | vha->flags.online = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6439 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 6440 | ha->isp_ops->enable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6441 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 6442 | ha->isp_abort_cnt = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6443 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 6444 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 6445 | if (IS_QLA81XX(ha) || IS_QLA8031(ha)) |
| 6446 | qla2x00_get_fw_version(vha); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 6447 | if (ha->fce) { |
| 6448 | ha->flags.fce_enabled = 1; |
| 6449 | memset(ha->fce, 0, |
| 6450 | fce_calc_size(ha->fce_bufs)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6451 | rval = qla2x00_enable_fce_trace(vha, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 6452 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 6453 | &ha->fce_bufs); |
| 6454 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6455 | ql_log(ql_log_warn, vha, 0x8033, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 6456 | "Unable to reinitialize FCE " |
| 6457 | "(%d).\n", rval); |
| 6458 | ha->flags.fce_enabled = 0; |
| 6459 | } |
| 6460 | } |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 6461 | |
| 6462 | if (ha->eft) { |
| 6463 | memset(ha->eft, 0, EFT_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6464 | rval = qla2x00_enable_eft_trace(vha, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 6465 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 6466 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6467 | ql_log(ql_log_warn, vha, 0x8034, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 6468 | "Unable to reinitialize EFT " |
| 6469 | "(%d).\n", rval); |
| 6470 | } |
| 6471 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6472 | } else { /* failed the ISP abort */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6473 | vha->flags.online = 1; |
| 6474 | if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6475 | if (ha->isp_abort_cnt == 0) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6476 | ql_log(ql_log_fatal, vha, 0x8035, |
| 6477 | "ISP error recover failed - " |
| 6478 | "board disabled.\n"); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 6479 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6480 | * The next call disables the board |
| 6481 | * completely. |
| 6482 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6483 | ha->isp_ops->reset_adapter(vha); |
| 6484 | vha->flags.online = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6485 | clear_bit(ISP_ABORT_RETRY, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6486 | &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6487 | status = 0; |
| 6488 | } else { /* schedule another ISP abort */ |
| 6489 | ha->isp_abort_cnt--; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6490 | ql_dbg(ql_dbg_taskm, vha, 0x8020, |
| 6491 | "ISP abort - retry remaining %d.\n", |
| 6492 | ha->isp_abort_cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6493 | status = 1; |
| 6494 | } |
| 6495 | } else { |
| 6496 | ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6497 | ql_dbg(ql_dbg_taskm, vha, 0x8021, |
| 6498 | "ISP error recovery - retrying (%d) " |
| 6499 | "more times.\n", ha->isp_abort_cnt); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6500 | set_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6501 | status = 1; |
| 6502 | } |
| 6503 | } |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 6504 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6505 | } |
| 6506 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6507 | if (!status) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6508 | ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__); |
Quinn Tran | 1608cc4 | 2017-08-23 15:05:03 -0700 | [diff] [blame] | 6509 | qla2x00_configure_hba(vha); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6510 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 6511 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 6512 | if (vp->vp_idx) { |
| 6513 | atomic_inc(&vp->vref_count); |
| 6514 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 6515 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6516 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6517 | |
| 6518 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 6519 | atomic_dec(&vp->vref_count); |
| 6520 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6521 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6522 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 6523 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 6524 | if (IS_QLA8031(ha)) { |
| 6525 | ql_dbg(ql_dbg_p3p, vha, 0xb05d, |
| 6526 | "Setting back fcoe driver presence.\n"); |
| 6527 | if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS) |
| 6528 | ql_dbg(ql_dbg_p3p, vha, 0xb074, |
| 6529 | "Error while setting DRV-Presence.\n"); |
| 6530 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6531 | } else { |
Joe Perches | d8424f6 | 2011-11-18 09:03:06 -0800 | [diff] [blame] | 6532 | ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n", |
| 6533 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6534 | } |
| 6535 | |
| 6536 | return(status); |
| 6537 | } |
| 6538 | |
| 6539 | /* |
| 6540 | * qla2x00_restart_isp |
| 6541 | * restarts the ISP after a reset |
| 6542 | * |
| 6543 | * Input: |
| 6544 | * ha = adapter block pointer. |
| 6545 | * |
| 6546 | * Returns: |
| 6547 | * 0 = success |
| 6548 | */ |
| 6549 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6550 | qla2x00_restart_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6551 | { |
Andrew Vasquez | c6b2fca | 2009-03-05 11:07:03 -0800 | [diff] [blame] | 6552 | int status = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6553 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6554 | struct req_que *req = ha->req_q_map[0]; |
| 6555 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6556 | |
| 6557 | /* If firmware needs to be loaded */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6558 | if (qla2x00_isp_firmware(vha)) { |
| 6559 | vha->flags.online = 0; |
| 6560 | status = ha->isp_ops->chip_diag(vha); |
| 6561 | if (!status) |
| 6562 | status = qla2x00_setup_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6563 | } |
| 6564 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6565 | if (!status && !(status = qla2x00_init_rings(vha))) { |
| 6566 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 6567 | ha->flags.chip_reset_done = 1; |
Chad Dupuis | 7108b76 | 2014-04-11 16:54:45 -0400 | [diff] [blame] | 6568 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6569 | /* Initialize the queues in use */ |
| 6570 | qla25xx_init_queues(ha); |
| 6571 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6572 | status = qla2x00_fw_ready(vha); |
| 6573 | if (!status) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6574 | /* Issue a marker after FW becomes ready. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6575 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Chad Dupuis | 7108b76 | 2014-04-11 16:54:45 -0400 | [diff] [blame] | 6576 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6577 | } |
| 6578 | |
| 6579 | /* if no cable then assume it's good */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6580 | if ((vha->device_flags & DFLG_NO_CABLE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6581 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6582 | } |
| 6583 | return (status); |
| 6584 | } |
| 6585 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6586 | static int |
| 6587 | qla25xx_init_queues(struct qla_hw_data *ha) |
| 6588 | { |
| 6589 | struct rsp_que *rsp = NULL; |
| 6590 | struct req_que *req = NULL; |
| 6591 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
| 6592 | int ret = -1; |
| 6593 | int i; |
| 6594 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 6595 | for (i = 1; i < ha->max_rsp_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6596 | rsp = ha->rsp_q_map[i]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 6597 | if (rsp && test_bit(i, ha->rsp_qid_map)) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6598 | rsp->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 6599 | ret = qla25xx_init_rsp_que(base_vha, rsp); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6600 | if (ret != QLA_SUCCESS) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6601 | ql_dbg(ql_dbg_init, base_vha, 0x00ff, |
| 6602 | "%s Rsp que: %d init failed.\n", |
| 6603 | __func__, rsp->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6604 | else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6605 | ql_dbg(ql_dbg_init, base_vha, 0x0100, |
| 6606 | "%s Rsp que: %d inited.\n", |
| 6607 | __func__, rsp->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6608 | } |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 6609 | } |
| 6610 | for (i = 1; i < ha->max_req_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6611 | req = ha->req_q_map[i]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 6612 | if (req && test_bit(i, ha->req_qid_map)) { |
| 6613 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6614 | req->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 6615 | ret = qla25xx_init_req_que(base_vha, req); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6616 | if (ret != QLA_SUCCESS) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6617 | ql_dbg(ql_dbg_init, base_vha, 0x0101, |
| 6618 | "%s Req que: %d init failed.\n", |
| 6619 | __func__, req->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6620 | else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6621 | ql_dbg(ql_dbg_init, base_vha, 0x0102, |
| 6622 | "%s Req que: %d inited.\n", |
| 6623 | __func__, req->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6624 | } |
| 6625 | } |
| 6626 | return ret; |
| 6627 | } |
| 6628 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6629 | /* |
| 6630 | * qla2x00_reset_adapter |
| 6631 | * Reset adapter. |
| 6632 | * |
| 6633 | * Input: |
| 6634 | * ha = adapter block pointer. |
| 6635 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 6636 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6637 | qla2x00_reset_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6638 | { |
| 6639 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6640 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 6641 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6642 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6643 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 6644 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6645 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6646 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6647 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 6648 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 6649 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 6650 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 6651 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6652 | } |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6653 | |
| 6654 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6655 | qla24xx_reset_adapter(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6656 | { |
| 6657 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6658 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6659 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 6660 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 6661 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6662 | return; |
| 6663 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6664 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 6665 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6666 | |
| 6667 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6668 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 6669 | RD_REG_DWORD(®->hccr); |
| 6670 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 6671 | RD_REG_DWORD(®->hccr); |
| 6672 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 09ff36d | 2009-01-22 09:45:30 -0800 | [diff] [blame] | 6673 | |
| 6674 | if (IS_NOPOLLING_TYPE(ha)) |
| 6675 | ha->isp_ops->enable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6676 | } |
| 6677 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6678 | /* On sparc systems, obtain port and node WWN from firmware |
| 6679 | * properties. |
| 6680 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6681 | static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, |
| 6682 | struct nvram_24xx *nv) |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6683 | { |
| 6684 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6685 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6686 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 6687 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 6688 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6689 | int len; |
| 6690 | |
| 6691 | val = of_get_property(dp, "port-wwn", &len); |
| 6692 | if (val && len >= WWN_SIZE) |
| 6693 | memcpy(nv->port_name, val, WWN_SIZE); |
| 6694 | |
| 6695 | val = of_get_property(dp, "node-wwn", &len); |
| 6696 | if (val && len >= WWN_SIZE) |
| 6697 | memcpy(nv->node_name, val, WWN_SIZE); |
| 6698 | #endif |
| 6699 | } |
| 6700 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6701 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6702 | qla24xx_nvram_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6703 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6704 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6705 | struct init_cb_24xx *icb; |
| 6706 | struct nvram_24xx *nv; |
| 6707 | uint32_t *dptr; |
| 6708 | uint8_t *dptr1, *dptr2; |
| 6709 | uint32_t chksum; |
| 6710 | uint16_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6711 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6712 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6713 | rval = QLA_SUCCESS; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6714 | icb = (struct init_cb_24xx *)ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 6715 | nv = ha->nvram; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6716 | |
| 6717 | /* Determine NVRAM starting address. */ |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6718 | if (ha->port_no == 0) { |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 6719 | ha->nvram_base = FA_NVRAM_FUNC0_ADDR; |
| 6720 | ha->vpd_base = FA_NVRAM_VPD0_ADDR; |
| 6721 | } else { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6722 | ha->nvram_base = FA_NVRAM_FUNC1_ADDR; |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 6723 | ha->vpd_base = FA_NVRAM_VPD1_ADDR; |
| 6724 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6725 | |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 6726 | ha->nvram_size = sizeof(struct nvram_24xx); |
| 6727 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6728 | |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 6729 | /* Get VPD data into cache */ |
| 6730 | ha->vpd = ha->nvram + VPD_OFFSET; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6731 | ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 6732 | ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4); |
| 6733 | |
| 6734 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6735 | dptr = (uint32_t *)nv; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6736 | ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6737 | ha->nvram_size); |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 6738 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++) |
| 6739 | chksum += le32_to_cpu(*dptr); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6740 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6741 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a, |
| 6742 | "Contents of NVRAM\n"); |
| 6743 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d, |
| 6744 | (uint8_t *)nv, ha->nvram_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6745 | |
| 6746 | /* Bad NVRAM data, set defaults parameters. */ |
| 6747 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 6748 | || nv->id[3] != ' ' || |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6749 | nv->nvram_version < cpu_to_le16(ICB_VERSION)) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6750 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6751 | ql_log(ql_log_warn, vha, 0x006b, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 6752 | "Inconsistent NVRAM detected: checksum=0x%x id=%c " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6753 | "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version); |
| 6754 | ql_log(ql_log_warn, vha, 0x006c, |
| 6755 | "Falling back to functioning (yet invalid -- WWPN) " |
| 6756 | "defaults.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6757 | |
| 6758 | /* |
| 6759 | * Set default initialization control block. |
| 6760 | */ |
| 6761 | memset(nv, 0, ha->nvram_size); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6762 | nv->nvram_version = cpu_to_le16(ICB_VERSION); |
| 6763 | nv->version = cpu_to_le16(ICB_VERSION); |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 6764 | nv->frame_payload_size = 2048; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6765 | nv->execution_throttle = cpu_to_le16(0xFFFF); |
| 6766 | nv->exchange_count = cpu_to_le16(0); |
| 6767 | nv->hard_address = cpu_to_le16(124); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6768 | nv->port_name[0] = 0x21; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6769 | nv->port_name[1] = 0x00 + ha->port_no + 1; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6770 | nv->port_name[2] = 0x00; |
| 6771 | nv->port_name[3] = 0xe0; |
| 6772 | nv->port_name[4] = 0x8b; |
| 6773 | nv->port_name[5] = 0x1c; |
| 6774 | nv->port_name[6] = 0x55; |
| 6775 | nv->port_name[7] = 0x86; |
| 6776 | nv->node_name[0] = 0x20; |
| 6777 | nv->node_name[1] = 0x00; |
| 6778 | nv->node_name[2] = 0x00; |
| 6779 | nv->node_name[3] = 0xe0; |
| 6780 | nv->node_name[4] = 0x8b; |
| 6781 | nv->node_name[5] = 0x1c; |
| 6782 | nv->node_name[6] = 0x55; |
| 6783 | nv->node_name[7] = 0x86; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6784 | qla24xx_nvram_wwn_from_ofw(vha, nv); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6785 | nv->login_retry_count = cpu_to_le16(8); |
| 6786 | nv->interrupt_delay_timer = cpu_to_le16(0); |
| 6787 | nv->login_timeout = cpu_to_le16(0); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6788 | nv->firmware_options_1 = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6789 | cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 6790 | nv->firmware_options_2 = cpu_to_le32(2 << 4); |
| 6791 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 6792 | nv->firmware_options_3 = cpu_to_le32(2 << 13); |
| 6793 | nv->host_p = cpu_to_le32(BIT_11|BIT_10); |
| 6794 | nv->efi_parameters = cpu_to_le32(0); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6795 | nv->reset_delay = 5; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6796 | nv->max_luns_per_target = cpu_to_le16(128); |
| 6797 | nv->port_down_retry_count = cpu_to_le16(30); |
| 6798 | nv->link_down_timeout = cpu_to_le16(30); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6799 | |
| 6800 | rval = 1; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6801 | } |
| 6802 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6803 | if (qla_tgt_mode_enabled(vha)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6804 | /* Don't enable full login after initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6805 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6806 | /* Don't enable LIP full login for initiator */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6807 | nv->host_p &= cpu_to_le32(~BIT_10); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6808 | } |
| 6809 | |
| 6810 | qlt_24xx_config_nvram_stage1(vha, nv); |
| 6811 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6812 | /* Reset Initialization control block */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6813 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6814 | |
| 6815 | /* Copy 1st segment. */ |
| 6816 | dptr1 = (uint8_t *)icb; |
| 6817 | dptr2 = (uint8_t *)&nv->version; |
| 6818 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 6819 | while (cnt--) |
| 6820 | *dptr1++ = *dptr2++; |
| 6821 | |
| 6822 | icb->login_retry_count = nv->login_retry_count; |
Andrew Vasquez | 3ea66e2 | 2006-06-23 16:11:27 -0700 | [diff] [blame] | 6823 | icb->link_down_on_nos = nv->link_down_on_nos; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6824 | |
| 6825 | /* Copy 2nd segment. */ |
| 6826 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 6827 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 6828 | cnt = (uint8_t *)&icb->reserved_3 - |
| 6829 | (uint8_t *)&icb->interrupt_delay_timer; |
| 6830 | while (cnt--) |
| 6831 | *dptr1++ = *dptr2++; |
| 6832 | |
| 6833 | /* |
| 6834 | * Setup driver NVRAM options. |
| 6835 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6836 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 6837 | "QLA2462"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6838 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6839 | qlt_24xx_config_nvram_stage2(vha, icb); |
| 6840 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6841 | if (nv->host_p & cpu_to_le32(BIT_15)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6842 | /* Use alternate WWN? */ |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 6843 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 6844 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 6845 | } |
| 6846 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6847 | /* Prepare nodename */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6848 | if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6849 | /* |
| 6850 | * Firmware will apply the following mask if the nodename was |
| 6851 | * not provided. |
| 6852 | */ |
| 6853 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 6854 | icb->node_name[0] &= 0xF0; |
| 6855 | } |
| 6856 | |
| 6857 | /* Set host adapter parameters. */ |
| 6858 | ha->flags.disable_risc_code_load = 0; |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 6859 | ha->flags.enable_lip_reset = 0; |
| 6860 | ha->flags.enable_lip_full_login = |
| 6861 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 6862 | ha->flags.enable_target_reset = |
| 6863 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6864 | ha->flags.enable_led_scheme = 0; |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 6865 | 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] | 6866 | |
Andrew Vasquez | fd0e7e4 | 2006-05-17 15:09:11 -0700 | [diff] [blame] | 6867 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 6868 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6869 | |
| 6870 | memcpy(ha->fw_seriallink_options24, nv->seriallink_options, |
| 6871 | sizeof(ha->fw_seriallink_options24)); |
| 6872 | |
| 6873 | /* save HBA serial number */ |
| 6874 | ha->serial0 = icb->port_name[5]; |
| 6875 | ha->serial1 = icb->port_name[6]; |
| 6876 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6877 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 6878 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6879 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6880 | icb->execution_throttle = cpu_to_le16(0xFFFF); |
andrew.vasquez@qlogic.com | bc8fb3c | 2006-01-13 17:05:42 -0800 | [diff] [blame] | 6881 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6882 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 6883 | |
| 6884 | /* Set minimum login_timeout to 4 seconds. */ |
| 6885 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 6886 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 6887 | if (le16_to_cpu(nv->login_timeout) < 4) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6888 | nv->login_timeout = cpu_to_le16(4); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6889 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6890 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 6891 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 6892 | ha->r_a_tov = 100; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6893 | |
| 6894 | ha->loop_reset_delay = nv->reset_delay; |
| 6895 | |
| 6896 | /* Link Down Timeout = 0: |
| 6897 | * |
| 6898 | * When Port Down timer expires we will start returning |
| 6899 | * I/O's to OS with "DID_NO_CONNECT". |
| 6900 | * |
| 6901 | * Link Down Timeout != 0: |
| 6902 | * |
| 6903 | * The driver waits for the link to come up after link down |
| 6904 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 6905 | */ |
| 6906 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 6907 | ha->loop_down_abort_time = |
| 6908 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 6909 | } else { |
| 6910 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 6911 | ha->loop_down_abort_time = |
| 6912 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 6913 | } |
| 6914 | |
| 6915 | /* Need enough time to try and get the port back. */ |
| 6916 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 6917 | if (qlport_down_retry) |
| 6918 | ha->port_down_retry_count = qlport_down_retry; |
| 6919 | |
| 6920 | /* Set login_retry_count */ |
| 6921 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 6922 | if (ha->port_down_retry_count == |
| 6923 | le16_to_cpu(nv->port_down_retry_count) && |
| 6924 | ha->port_down_retry_count > 3) |
| 6925 | ha->login_retry_count = ha->port_down_retry_count; |
| 6926 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 6927 | ha->login_retry_count = ha->port_down_retry_count; |
| 6928 | if (ql2xloginretrycount) |
| 6929 | ha->login_retry_count = ql2xloginretrycount; |
| 6930 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6931 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6932 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6933 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 6934 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 6935 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 6936 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 6937 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6938 | icb->firmware_options_2 &= cpu_to_le32( |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6939 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6940 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6941 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 6942 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 6943 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6944 | ql_log(ql_log_info, vha, 0x006f, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6945 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 6946 | ha->zio_mode, ha->zio_timer * 100); |
| 6947 | |
| 6948 | icb->firmware_options_2 |= cpu_to_le32( |
| 6949 | (uint32_t)ha->zio_mode); |
| 6950 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6951 | vha->flags.process_response_queue = 1; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6952 | } |
| 6953 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6954 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6955 | ql_log(ql_log_warn, vha, 0x0070, |
| 6956 | "NVRAM configuration failed.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6957 | } |
| 6958 | return (rval); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6959 | } |
| 6960 | |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 6961 | uint8_t qla27xx_find_valid_image(struct scsi_qla_host *vha) |
| 6962 | { |
| 6963 | struct qla27xx_image_status pri_image_status, sec_image_status; |
| 6964 | uint8_t valid_pri_image, valid_sec_image; |
| 6965 | uint32_t *wptr; |
| 6966 | uint32_t cnt, chksum, size; |
| 6967 | struct qla_hw_data *ha = vha->hw; |
| 6968 | |
| 6969 | valid_pri_image = valid_sec_image = 1; |
| 6970 | ha->active_image = 0; |
| 6971 | size = sizeof(struct qla27xx_image_status) / sizeof(uint32_t); |
| 6972 | |
| 6973 | if (!ha->flt_region_img_status_pri) { |
| 6974 | valid_pri_image = 0; |
| 6975 | goto check_sec_image; |
| 6976 | } |
| 6977 | |
| 6978 | qla24xx_read_flash_data(vha, (uint32_t *)(&pri_image_status), |
| 6979 | ha->flt_region_img_status_pri, size); |
| 6980 | |
| 6981 | if (pri_image_status.signature != QLA27XX_IMG_STATUS_SIGN) { |
| 6982 | ql_dbg(ql_dbg_init, vha, 0x018b, |
| 6983 | "Primary image signature (0x%x) not valid\n", |
| 6984 | pri_image_status.signature); |
| 6985 | valid_pri_image = 0; |
| 6986 | goto check_sec_image; |
| 6987 | } |
| 6988 | |
| 6989 | wptr = (uint32_t *)(&pri_image_status); |
| 6990 | cnt = size; |
| 6991 | |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 6992 | for (chksum = 0; cnt--; wptr++) |
| 6993 | chksum += le32_to_cpu(*wptr); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 6994 | |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 6995 | if (chksum) { |
| 6996 | ql_dbg(ql_dbg_init, vha, 0x018c, |
| 6997 | "Checksum validation failed for primary image (0x%x)\n", |
| 6998 | chksum); |
| 6999 | valid_pri_image = 0; |
| 7000 | } |
| 7001 | |
| 7002 | check_sec_image: |
| 7003 | if (!ha->flt_region_img_status_sec) { |
| 7004 | valid_sec_image = 0; |
| 7005 | goto check_valid_image; |
| 7006 | } |
| 7007 | |
| 7008 | qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status), |
| 7009 | ha->flt_region_img_status_sec, size); |
| 7010 | |
| 7011 | if (sec_image_status.signature != QLA27XX_IMG_STATUS_SIGN) { |
| 7012 | ql_dbg(ql_dbg_init, vha, 0x018d, |
| 7013 | "Secondary image signature(0x%x) not valid\n", |
| 7014 | sec_image_status.signature); |
| 7015 | valid_sec_image = 0; |
| 7016 | goto check_valid_image; |
| 7017 | } |
| 7018 | |
| 7019 | wptr = (uint32_t *)(&sec_image_status); |
| 7020 | cnt = size; |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 7021 | for (chksum = 0; cnt--; wptr++) |
| 7022 | chksum += le32_to_cpu(*wptr); |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 7023 | if (chksum) { |
| 7024 | ql_dbg(ql_dbg_init, vha, 0x018e, |
| 7025 | "Checksum validation failed for secondary image (0x%x)\n", |
| 7026 | chksum); |
| 7027 | valid_sec_image = 0; |
| 7028 | } |
| 7029 | |
| 7030 | check_valid_image: |
| 7031 | if (valid_pri_image && (pri_image_status.image_status_mask & 0x1)) |
| 7032 | ha->active_image = QLA27XX_PRIMARY_IMAGE; |
| 7033 | if (valid_sec_image && (sec_image_status.image_status_mask & 0x1)) { |
| 7034 | if (!ha->active_image || |
| 7035 | pri_image_status.generation_number < |
| 7036 | sec_image_status.generation_number) |
| 7037 | ha->active_image = QLA27XX_SECONDARY_IMAGE; |
| 7038 | } |
| 7039 | |
| 7040 | ql_dbg(ql_dbg_init, vha, 0x018f, "%s image\n", |
| 7041 | ha->active_image == 0 ? "default bootld and fw" : |
| 7042 | ha->active_image == 1 ? "primary" : |
| 7043 | ha->active_image == 2 ? "secondary" : |
| 7044 | "Invalid"); |
| 7045 | |
| 7046 | return ha->active_image; |
| 7047 | } |
| 7048 | |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 7049 | static int |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7050 | qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr, |
| 7051 | uint32_t faddr) |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7052 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7053 | int rval = QLA_SUCCESS; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7054 | int segments, fragment; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7055 | uint32_t *dcode, dlen; |
| 7056 | uint32_t risc_addr; |
| 7057 | uint32_t risc_size; |
| 7058 | uint32_t i; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7059 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7060 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7061 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7062 | ql_dbg(ql_dbg_init, vha, 0x008b, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7063 | "FW: Loading firmware from flash (%x).\n", faddr); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7064 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7065 | rval = QLA_SUCCESS; |
| 7066 | |
| 7067 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7068 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7069 | *srisc_addr = 0; |
| 7070 | |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 7071 | if (IS_QLA27XX(ha) && |
| 7072 | qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE) |
| 7073 | faddr = ha->flt_region_fw_sec; |
| 7074 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7075 | /* Validate firmware image by checking version. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7076 | qla24xx_read_flash_data(vha, dcode, faddr + 4, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7077 | for (i = 0; i < 4; i++) |
| 7078 | dcode[i] = be32_to_cpu(dcode[i]); |
| 7079 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 7080 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 7081 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 7082 | dcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7083 | ql_log(ql_log_fatal, vha, 0x008c, |
| 7084 | "Unable to verify the integrity of flash firmware " |
| 7085 | "image.\n"); |
| 7086 | ql_log(ql_log_fatal, vha, 0x008d, |
| 7087 | "Firmware data: %08x %08x %08x %08x.\n", |
| 7088 | dcode[0], dcode[1], dcode[2], dcode[3]); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7089 | |
| 7090 | return QLA_FUNCTION_FAILED; |
| 7091 | } |
| 7092 | |
| 7093 | while (segments && rval == QLA_SUCCESS) { |
| 7094 | /* Read segment's load information. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7095 | qla24xx_read_flash_data(vha, dcode, faddr, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7096 | |
| 7097 | risc_addr = be32_to_cpu(dcode[2]); |
| 7098 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 7099 | risc_size = be32_to_cpu(dcode[3]); |
| 7100 | |
| 7101 | fragment = 0; |
| 7102 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 7103 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 7104 | if (dlen > risc_size) |
| 7105 | dlen = risc_size; |
| 7106 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7107 | ql_dbg(ql_dbg_init, vha, 0x008e, |
| 7108 | "Loading risc segment@ risc addr %x " |
| 7109 | "number of dwords 0x%x offset 0x%x.\n", |
| 7110 | risc_addr, dlen, faddr); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7111 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7112 | qla24xx_read_flash_data(vha, dcode, faddr, dlen); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7113 | for (i = 0; i < dlen; i++) |
| 7114 | dcode[i] = swab32(dcode[i]); |
| 7115 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7116 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7117 | dlen); |
| 7118 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7119 | ql_log(ql_log_fatal, vha, 0x008f, |
| 7120 | "Failed to load segment %d of firmware.\n", |
| 7121 | fragment); |
Chad Dupuis | f261f7a | 2014-09-25 05:17:03 -0400 | [diff] [blame] | 7122 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7123 | } |
| 7124 | |
| 7125 | faddr += dlen; |
| 7126 | risc_addr += dlen; |
| 7127 | risc_size -= dlen; |
| 7128 | fragment++; |
| 7129 | } |
| 7130 | |
| 7131 | /* Next segment. */ |
| 7132 | segments--; |
| 7133 | } |
| 7134 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7135 | if (!IS_QLA27XX(ha)) |
| 7136 | return rval; |
| 7137 | |
| 7138 | if (ha->fw_dump_template) |
| 7139 | vfree(ha->fw_dump_template); |
| 7140 | ha->fw_dump_template = NULL; |
| 7141 | ha->fw_dump_template_len = 0; |
| 7142 | |
| 7143 | ql_dbg(ql_dbg_init, vha, 0x0161, |
| 7144 | "Loading fwdump template from %x\n", faddr); |
| 7145 | qla24xx_read_flash_data(vha, dcode, faddr, 7); |
| 7146 | risc_size = be32_to_cpu(dcode[2]); |
| 7147 | ql_dbg(ql_dbg_init, vha, 0x0162, |
| 7148 | "-> array size %x dwords\n", risc_size); |
| 7149 | if (risc_size == 0 || risc_size == ~0) |
| 7150 | goto default_template; |
| 7151 | |
| 7152 | dlen = (risc_size - 8) * sizeof(*dcode); |
| 7153 | ql_dbg(ql_dbg_init, vha, 0x0163, |
| 7154 | "-> template allocating %x bytes...\n", dlen); |
| 7155 | ha->fw_dump_template = vmalloc(dlen); |
| 7156 | if (!ha->fw_dump_template) { |
| 7157 | ql_log(ql_log_warn, vha, 0x0164, |
| 7158 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 7159 | goto default_template; |
| 7160 | } |
| 7161 | |
| 7162 | faddr += 7; |
| 7163 | risc_size -= 8; |
| 7164 | dcode = ha->fw_dump_template; |
| 7165 | qla24xx_read_flash_data(vha, dcode, faddr, risc_size); |
| 7166 | for (i = 0; i < risc_size; i++) |
| 7167 | dcode[i] = le32_to_cpu(dcode[i]); |
| 7168 | |
| 7169 | if (!qla27xx_fwdt_template_valid(dcode)) { |
| 7170 | ql_log(ql_log_warn, vha, 0x0165, |
| 7171 | "Failed fwdump template validate\n"); |
| 7172 | goto default_template; |
| 7173 | } |
| 7174 | |
| 7175 | dlen = qla27xx_fwdt_template_size(dcode); |
| 7176 | ql_dbg(ql_dbg_init, vha, 0x0166, |
| 7177 | "-> template size %x bytes\n", dlen); |
| 7178 | if (dlen > risc_size * sizeof(*dcode)) { |
| 7179 | ql_log(ql_log_warn, vha, 0x0167, |
Himanshu Madhani | 4fae52b | 2017-06-06 13:55:23 -0700 | [diff] [blame] | 7180 | "Failed fwdump template exceeds array by %zx bytes\n", |
Joe Carnuccio | 383a298 | 2017-06-02 09:11:55 -0700 | [diff] [blame] | 7181 | (size_t)(dlen - risc_size * sizeof(*dcode))); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7182 | goto default_template; |
| 7183 | } |
| 7184 | ha->fw_dump_template_len = dlen; |
| 7185 | return rval; |
| 7186 | |
| 7187 | default_template: |
| 7188 | ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n"); |
| 7189 | if (ha->fw_dump_template) |
| 7190 | vfree(ha->fw_dump_template); |
| 7191 | ha->fw_dump_template = NULL; |
| 7192 | ha->fw_dump_template_len = 0; |
| 7193 | |
| 7194 | dlen = qla27xx_fwdt_template_default_size(); |
| 7195 | ql_dbg(ql_dbg_init, vha, 0x0169, |
| 7196 | "-> template allocating %x bytes...\n", dlen); |
| 7197 | ha->fw_dump_template = vmalloc(dlen); |
| 7198 | if (!ha->fw_dump_template) { |
| 7199 | ql_log(ql_log_warn, vha, 0x016a, |
| 7200 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 7201 | goto failed_template; |
| 7202 | } |
| 7203 | |
| 7204 | dcode = ha->fw_dump_template; |
| 7205 | risc_size = dlen / sizeof(*dcode); |
| 7206 | memcpy(dcode, qla27xx_fwdt_template_default(), dlen); |
| 7207 | for (i = 0; i < risc_size; i++) |
| 7208 | dcode[i] = be32_to_cpu(dcode[i]); |
| 7209 | |
| 7210 | if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) { |
| 7211 | ql_log(ql_log_warn, vha, 0x016b, |
| 7212 | "Failed fwdump template validate\n"); |
| 7213 | goto failed_template; |
| 7214 | } |
| 7215 | |
| 7216 | dlen = qla27xx_fwdt_template_size(ha->fw_dump_template); |
| 7217 | ql_dbg(ql_dbg_init, vha, 0x016c, |
| 7218 | "-> template size %x bytes\n", dlen); |
| 7219 | ha->fw_dump_template_len = dlen; |
| 7220 | return rval; |
| 7221 | |
| 7222 | failed_template: |
| 7223 | ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n"); |
| 7224 | if (ha->fw_dump_template) |
| 7225 | vfree(ha->fw_dump_template); |
| 7226 | ha->fw_dump_template = NULL; |
| 7227 | ha->fw_dump_template_len = 0; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7228 | return rval; |
| 7229 | } |
| 7230 | |
Giridhar Malavali | e9454a8 | 2013-02-08 01:57:47 -0500 | [diff] [blame] | 7231 | #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/" |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7232 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7233 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7234 | qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7235 | { |
| 7236 | int rval; |
| 7237 | int i, fragment; |
| 7238 | uint16_t *wcode, *fwcode; |
| 7239 | uint32_t risc_addr, risc_size, fwclen, wlen, *seg; |
| 7240 | struct fw_blob *blob; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7241 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7242 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7243 | |
| 7244 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7245 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7246 | if (!blob) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7247 | ql_log(ql_log_info, vha, 0x0083, |
Yannick Guerrini | 94bcf83 | 2015-02-26 22:49:34 +0100 | [diff] [blame] | 7248 | "Firmware image unavailable.\n"); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7249 | ql_log(ql_log_info, vha, 0x0084, |
| 7250 | "Firmware images can be retrieved from: "QLA_FW_URL ".\n"); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7251 | return QLA_FUNCTION_FAILED; |
| 7252 | } |
| 7253 | |
| 7254 | rval = QLA_SUCCESS; |
| 7255 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7256 | wcode = (uint16_t *)req->ring; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7257 | *srisc_addr = 0; |
| 7258 | fwcode = (uint16_t *)blob->fw->data; |
| 7259 | fwclen = 0; |
| 7260 | |
| 7261 | /* Validate firmware image by checking version. */ |
| 7262 | if (blob->fw->size < 8 * sizeof(uint16_t)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7263 | ql_log(ql_log_fatal, vha, 0x0085, |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 7264 | "Unable to verify integrity of firmware image (%zd).\n", |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7265 | blob->fw->size); |
| 7266 | goto fail_fw_integrity; |
| 7267 | } |
| 7268 | for (i = 0; i < 4; i++) |
| 7269 | wcode[i] = be16_to_cpu(fwcode[i + 4]); |
| 7270 | if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff && |
| 7271 | wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 && |
| 7272 | wcode[2] == 0 && wcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7273 | ql_log(ql_log_fatal, vha, 0x0086, |
| 7274 | "Unable to verify integrity of firmware image.\n"); |
| 7275 | ql_log(ql_log_fatal, vha, 0x0087, |
| 7276 | "Firmware data: %04x %04x %04x %04x.\n", |
| 7277 | wcode[0], wcode[1], wcode[2], wcode[3]); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7278 | goto fail_fw_integrity; |
| 7279 | } |
| 7280 | |
| 7281 | seg = blob->segs; |
| 7282 | while (*seg && rval == QLA_SUCCESS) { |
| 7283 | risc_addr = *seg; |
| 7284 | *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr; |
| 7285 | risc_size = be16_to_cpu(fwcode[3]); |
| 7286 | |
| 7287 | /* Validate firmware image size. */ |
| 7288 | fwclen += risc_size * sizeof(uint16_t); |
| 7289 | if (blob->fw->size < fwclen) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7290 | ql_log(ql_log_fatal, vha, 0x0088, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7291 | "Unable to verify integrity of firmware image " |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 7292 | "(%zd).\n", blob->fw->size); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7293 | goto fail_fw_integrity; |
| 7294 | } |
| 7295 | |
| 7296 | fragment = 0; |
| 7297 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 7298 | wlen = (uint16_t)(ha->fw_transfer_size >> 1); |
| 7299 | if (wlen > risc_size) |
| 7300 | wlen = risc_size; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7301 | ql_dbg(ql_dbg_init, vha, 0x0089, |
| 7302 | "Loading risc segment@ risc addr %x number of " |
| 7303 | "words 0x%x.\n", risc_addr, wlen); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7304 | |
| 7305 | for (i = 0; i < wlen; i++) |
| 7306 | wcode[i] = swab16(fwcode[i]); |
| 7307 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7308 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7309 | wlen); |
| 7310 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7311 | ql_log(ql_log_fatal, vha, 0x008a, |
| 7312 | "Failed to load segment %d of firmware.\n", |
| 7313 | fragment); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7314 | break; |
| 7315 | } |
| 7316 | |
| 7317 | fwcode += wlen; |
| 7318 | risc_addr += wlen; |
| 7319 | risc_size -= wlen; |
| 7320 | fragment++; |
| 7321 | } |
| 7322 | |
| 7323 | /* Next segment. */ |
| 7324 | seg++; |
| 7325 | } |
| 7326 | return rval; |
| 7327 | |
| 7328 | fail_fw_integrity: |
| 7329 | return QLA_FUNCTION_FAILED; |
| 7330 | } |
| 7331 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7332 | static int |
| 7333 | 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] | 7334 | { |
| 7335 | int rval; |
| 7336 | int segments, fragment; |
| 7337 | uint32_t *dcode, dlen; |
| 7338 | uint32_t risc_addr; |
| 7339 | uint32_t risc_size; |
| 7340 | uint32_t i; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7341 | struct fw_blob *blob; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7342 | const uint32_t *fwcode; |
| 7343 | uint32_t fwclen; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7344 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7345 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7346 | |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7347 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7348 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7349 | if (!blob) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7350 | ql_log(ql_log_warn, vha, 0x0090, |
Yannick Guerrini | 94bcf83 | 2015-02-26 22:49:34 +0100 | [diff] [blame] | 7351 | "Firmware image unavailable.\n"); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7352 | ql_log(ql_log_warn, vha, 0x0091, |
| 7353 | "Firmware images can be retrieved from: " |
| 7354 | QLA_FW_URL ".\n"); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 7355 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7356 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7357 | } |
| 7358 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7359 | ql_dbg(ql_dbg_init, vha, 0x0092, |
| 7360 | "FW: Loading via request-firmware.\n"); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7361 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7362 | rval = QLA_SUCCESS; |
| 7363 | |
| 7364 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7365 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7366 | *srisc_addr = 0; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7367 | fwcode = (uint32_t *)blob->fw->data; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7368 | fwclen = 0; |
| 7369 | |
| 7370 | /* Validate firmware image by checking version. */ |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7371 | if (blob->fw->size < 8 * sizeof(uint32_t)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7372 | ql_log(ql_log_fatal, vha, 0x0093, |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 7373 | "Unable to verify integrity of firmware image (%zd).\n", |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7374 | blob->fw->size); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7375 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7376 | } |
| 7377 | for (i = 0; i < 4; i++) |
| 7378 | dcode[i] = be32_to_cpu(fwcode[i + 4]); |
| 7379 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 7380 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 7381 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 7382 | dcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7383 | ql_log(ql_log_fatal, vha, 0x0094, |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 7384 | "Unable to verify integrity of firmware image (%zd).\n", |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7385 | blob->fw->size); |
| 7386 | ql_log(ql_log_fatal, vha, 0x0095, |
| 7387 | "Firmware data: %08x %08x %08x %08x.\n", |
| 7388 | dcode[0], dcode[1], dcode[2], dcode[3]); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7389 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7390 | } |
| 7391 | |
| 7392 | while (segments && rval == QLA_SUCCESS) { |
| 7393 | risc_addr = be32_to_cpu(fwcode[2]); |
| 7394 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 7395 | risc_size = be32_to_cpu(fwcode[3]); |
| 7396 | |
| 7397 | /* Validate firmware image size. */ |
| 7398 | fwclen += risc_size * sizeof(uint32_t); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7399 | if (blob->fw->size < fwclen) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7400 | ql_log(ql_log_fatal, vha, 0x0096, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 7401 | "Unable to verify integrity of firmware image " |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 7402 | "(%zd).\n", blob->fw->size); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7403 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7404 | } |
| 7405 | |
| 7406 | fragment = 0; |
| 7407 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 7408 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 7409 | if (dlen > risc_size) |
| 7410 | dlen = risc_size; |
| 7411 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7412 | ql_dbg(ql_dbg_init, vha, 0x0097, |
| 7413 | "Loading risc segment@ risc addr %x " |
| 7414 | "number of dwords 0x%x.\n", risc_addr, dlen); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7415 | |
| 7416 | for (i = 0; i < dlen; i++) |
| 7417 | dcode[i] = swab32(fwcode[i]); |
| 7418 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7419 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
andrew.vasquez@qlogic.com | 590f98e | 2006-01-13 17:05:37 -0800 | [diff] [blame] | 7420 | dlen); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7421 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7422 | ql_log(ql_log_fatal, vha, 0x0098, |
| 7423 | "Failed to load segment %d of firmware.\n", |
| 7424 | fragment); |
Chad Dupuis | f261f7a | 2014-09-25 05:17:03 -0400 | [diff] [blame] | 7425 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7426 | } |
| 7427 | |
| 7428 | fwcode += dlen; |
| 7429 | risc_addr += dlen; |
| 7430 | risc_size -= dlen; |
| 7431 | fragment++; |
| 7432 | } |
| 7433 | |
| 7434 | /* Next segment. */ |
| 7435 | segments--; |
| 7436 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7437 | |
| 7438 | if (!IS_QLA27XX(ha)) |
| 7439 | return rval; |
| 7440 | |
| 7441 | if (ha->fw_dump_template) |
| 7442 | vfree(ha->fw_dump_template); |
| 7443 | ha->fw_dump_template = NULL; |
| 7444 | ha->fw_dump_template_len = 0; |
| 7445 | |
| 7446 | ql_dbg(ql_dbg_init, vha, 0x171, |
Chad Dupuis | 97ea702 | 2014-03-13 14:16:40 -0400 | [diff] [blame] | 7447 | "Loading fwdump template from %x\n", |
| 7448 | (uint32_t)((void *)fwcode - (void *)blob->fw->data)); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7449 | risc_size = be32_to_cpu(fwcode[2]); |
| 7450 | ql_dbg(ql_dbg_init, vha, 0x172, |
| 7451 | "-> array size %x dwords\n", risc_size); |
| 7452 | if (risc_size == 0 || risc_size == ~0) |
| 7453 | goto default_template; |
| 7454 | |
| 7455 | dlen = (risc_size - 8) * sizeof(*fwcode); |
| 7456 | ql_dbg(ql_dbg_init, vha, 0x0173, |
| 7457 | "-> template allocating %x bytes...\n", dlen); |
| 7458 | ha->fw_dump_template = vmalloc(dlen); |
| 7459 | if (!ha->fw_dump_template) { |
| 7460 | ql_log(ql_log_warn, vha, 0x0174, |
| 7461 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 7462 | goto default_template; |
| 7463 | } |
| 7464 | |
| 7465 | fwcode += 7; |
| 7466 | risc_size -= 8; |
| 7467 | dcode = ha->fw_dump_template; |
| 7468 | for (i = 0; i < risc_size; i++) |
| 7469 | dcode[i] = le32_to_cpu(fwcode[i]); |
| 7470 | |
| 7471 | if (!qla27xx_fwdt_template_valid(dcode)) { |
| 7472 | ql_log(ql_log_warn, vha, 0x0175, |
| 7473 | "Failed fwdump template validate\n"); |
| 7474 | goto default_template; |
| 7475 | } |
| 7476 | |
| 7477 | dlen = qla27xx_fwdt_template_size(dcode); |
| 7478 | ql_dbg(ql_dbg_init, vha, 0x0176, |
| 7479 | "-> template size %x bytes\n", dlen); |
| 7480 | if (dlen > risc_size * sizeof(*fwcode)) { |
| 7481 | ql_log(ql_log_warn, vha, 0x0177, |
Himanshu Madhani | 4fae52b | 2017-06-06 13:55:23 -0700 | [diff] [blame] | 7482 | "Failed fwdump template exceeds array by %zx bytes\n", |
Joe Carnuccio | 383a298 | 2017-06-02 09:11:55 -0700 | [diff] [blame] | 7483 | (size_t)(dlen - risc_size * sizeof(*fwcode))); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7484 | goto default_template; |
| 7485 | } |
| 7486 | ha->fw_dump_template_len = dlen; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7487 | return rval; |
| 7488 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7489 | default_template: |
| 7490 | ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n"); |
| 7491 | if (ha->fw_dump_template) |
| 7492 | vfree(ha->fw_dump_template); |
| 7493 | ha->fw_dump_template = NULL; |
| 7494 | ha->fw_dump_template_len = 0; |
| 7495 | |
| 7496 | dlen = qla27xx_fwdt_template_default_size(); |
| 7497 | ql_dbg(ql_dbg_init, vha, 0x0179, |
| 7498 | "-> template allocating %x bytes...\n", dlen); |
| 7499 | ha->fw_dump_template = vmalloc(dlen); |
| 7500 | if (!ha->fw_dump_template) { |
| 7501 | ql_log(ql_log_warn, vha, 0x017a, |
| 7502 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 7503 | goto failed_template; |
| 7504 | } |
| 7505 | |
| 7506 | dcode = ha->fw_dump_template; |
| 7507 | risc_size = dlen / sizeof(*fwcode); |
| 7508 | fwcode = qla27xx_fwdt_template_default(); |
| 7509 | for (i = 0; i < risc_size; i++) |
| 7510 | dcode[i] = be32_to_cpu(fwcode[i]); |
| 7511 | |
| 7512 | if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) { |
| 7513 | ql_log(ql_log_warn, vha, 0x017b, |
| 7514 | "Failed fwdump template validate\n"); |
| 7515 | goto failed_template; |
| 7516 | } |
| 7517 | |
| 7518 | dlen = qla27xx_fwdt_template_size(ha->fw_dump_template); |
| 7519 | ql_dbg(ql_dbg_init, vha, 0x017c, |
| 7520 | "-> template size %x bytes\n", dlen); |
| 7521 | ha->fw_dump_template_len = dlen; |
| 7522 | return rval; |
| 7523 | |
| 7524 | failed_template: |
| 7525 | ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n"); |
| 7526 | if (ha->fw_dump_template) |
| 7527 | vfree(ha->fw_dump_template); |
| 7528 | ha->fw_dump_template = NULL; |
| 7529 | ha->fw_dump_template_len = 0; |
| 7530 | return rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7531 | } |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7532 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7533 | int |
| 7534 | qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 7535 | { |
| 7536 | int rval; |
| 7537 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 7538 | if (ql2xfwloadbin == 1) |
| 7539 | return qla81xx_load_risc(vha, srisc_addr); |
| 7540 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7541 | /* |
| 7542 | * FW Load priority: |
| 7543 | * 1) Firmware via request-firmware interface (.bin file). |
| 7544 | * 2) Firmware residing in flash. |
| 7545 | */ |
| 7546 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 7547 | if (rval == QLA_SUCCESS) |
| 7548 | return rval; |
| 7549 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7550 | return qla24xx_load_risc_flash(vha, srisc_addr, |
| 7551 | vha->hw->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7552 | } |
| 7553 | |
| 7554 | int |
| 7555 | qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 7556 | { |
| 7557 | int rval; |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7558 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7559 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 7560 | if (ql2xfwloadbin == 2) |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7561 | goto try_blob_fw; |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 7562 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7563 | /* |
| 7564 | * FW Load priority: |
| 7565 | * 1) Firmware residing in flash. |
| 7566 | * 2) Firmware via request-firmware interface (.bin file). |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7567 | * 3) Golden-Firmware residing in flash -- limited operation. |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7568 | */ |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7569 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7570 | if (rval == QLA_SUCCESS) |
| 7571 | return rval; |
| 7572 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7573 | try_blob_fw: |
| 7574 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 7575 | if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw) |
| 7576 | return rval; |
| 7577 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7578 | ql_log(ql_log_info, vha, 0x0099, |
| 7579 | "Attempting to fallback to golden firmware.\n"); |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7580 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw); |
| 7581 | if (rval != QLA_SUCCESS) |
| 7582 | return rval; |
| 7583 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7584 | ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n"); |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7585 | ha->flags.running_gold_fw = 1; |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7586 | return rval; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7587 | } |
| 7588 | |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7589 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7590 | qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7591 | { |
| 7592 | int ret, retries; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7593 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7594 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 7595 | if (ha->flags.pci_channel_io_perm_failure) |
| 7596 | return; |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 7597 | if (!IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7598 | return; |
Andrew Vasquez | 75edf81 | 2007-05-07 07:43:00 -0700 | [diff] [blame] | 7599 | if (!ha->fw_major_version) |
| 7600 | return; |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 7601 | if (!ha->flags.fw_started) |
| 7602 | return; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7603 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7604 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 7c7f1f2 | 2008-02-28 14:06:09 -0800 | [diff] [blame] | 7605 | for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT && |
Andrew Vasquez | b469a7c | 2009-04-06 22:33:48 -0700 | [diff] [blame] | 7606 | ret != QLA_INVALID_COMMAND && retries ; retries--) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7607 | ha->isp_ops->reset_chip(vha); |
| 7608 | if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7609 | continue; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7610 | if (qla2x00_setup_chip(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7611 | continue; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7612 | ql_log(ql_log_info, vha, 0x8015, |
| 7613 | "Attempting retry of stop-firmware command.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7614 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7615 | } |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 7616 | |
Quinn Tran | 4b60c82 | 2017-06-13 20:47:21 -0700 | [diff] [blame] | 7617 | QLA_FW_STOPPED(ha); |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 7618 | ha->flags.fw_init_done = 0; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7619 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7620 | |
| 7621 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7622 | qla24xx_configure_vhba(scsi_qla_host_t *vha) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7623 | { |
| 7624 | int rval = QLA_SUCCESS; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 7625 | int rval2; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7626 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7627 | struct qla_hw_data *ha = vha->hw; |
| 7628 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 7629 | struct req_que *req; |
| 7630 | struct rsp_que *rsp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7631 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7632 | if (!vha->vp_idx) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7633 | return -EINVAL; |
| 7634 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7635 | rval = qla2x00_fw_ready(base_vha); |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7636 | if (vha->qpair) |
| 7637 | req = vha->qpair->req; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 7638 | else |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7639 | req = ha->req_q_map[0]; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 7640 | rsp = req->rsp; |
| 7641 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7642 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7643 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7644 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7645 | } |
| 7646 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7647 | vha->flags.management_server_logged_in = 0; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7648 | |
| 7649 | /* Login to SNS first */ |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 7650 | rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, |
| 7651 | BIT_1); |
| 7652 | if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) { |
| 7653 | if (rval2 == QLA_MEMORY_ALLOC_FAILED) |
| 7654 | ql_dbg(ql_dbg_init, vha, 0x0120, |
| 7655 | "Failed SNS login: loop_id=%x, rval2=%d\n", |
| 7656 | NPH_SNS, rval2); |
| 7657 | else |
| 7658 | ql_dbg(ql_dbg_init, vha, 0x0103, |
| 7659 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x " |
| 7660 | "mb[2]=%x mb[6]=%x mb[7]=%x.\n", |
| 7661 | NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7662 | return (QLA_FUNCTION_FAILED); |
| 7663 | } |
| 7664 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7665 | atomic_set(&vha->loop_down_timer, 0); |
| 7666 | atomic_set(&vha->loop_state, LOOP_UP); |
| 7667 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 7668 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 7669 | rval = qla2x00_loop_resync(base_vha); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7670 | |
| 7671 | return rval; |
| 7672 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7673 | |
| 7674 | /* 84XX Support **************************************************************/ |
| 7675 | |
| 7676 | static LIST_HEAD(qla_cs84xx_list); |
| 7677 | static DEFINE_MUTEX(qla_cs84xx_mutex); |
| 7678 | |
| 7679 | static struct qla_chip_state_84xx * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7680 | qla84xx_get_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7681 | { |
| 7682 | struct qla_chip_state_84xx *cs84xx; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7683 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7684 | |
| 7685 | mutex_lock(&qla_cs84xx_mutex); |
| 7686 | |
| 7687 | /* Find any shared 84xx chip. */ |
| 7688 | list_for_each_entry(cs84xx, &qla_cs84xx_list, list) { |
| 7689 | if (cs84xx->bus == ha->pdev->bus) { |
| 7690 | kref_get(&cs84xx->kref); |
| 7691 | goto done; |
| 7692 | } |
| 7693 | } |
| 7694 | |
| 7695 | cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL); |
| 7696 | if (!cs84xx) |
| 7697 | goto done; |
| 7698 | |
| 7699 | kref_init(&cs84xx->kref); |
| 7700 | spin_lock_init(&cs84xx->access_lock); |
| 7701 | mutex_init(&cs84xx->fw_update_mutex); |
| 7702 | cs84xx->bus = ha->pdev->bus; |
| 7703 | |
| 7704 | list_add_tail(&cs84xx->list, &qla_cs84xx_list); |
| 7705 | done: |
| 7706 | mutex_unlock(&qla_cs84xx_mutex); |
| 7707 | return cs84xx; |
| 7708 | } |
| 7709 | |
| 7710 | static void |
| 7711 | __qla84xx_chip_release(struct kref *kref) |
| 7712 | { |
| 7713 | struct qla_chip_state_84xx *cs84xx = |
| 7714 | container_of(kref, struct qla_chip_state_84xx, kref); |
| 7715 | |
| 7716 | mutex_lock(&qla_cs84xx_mutex); |
| 7717 | list_del(&cs84xx->list); |
| 7718 | mutex_unlock(&qla_cs84xx_mutex); |
| 7719 | kfree(cs84xx); |
| 7720 | } |
| 7721 | |
| 7722 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7723 | qla84xx_put_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7724 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7725 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7726 | if (ha->cs84xx) |
| 7727 | kref_put(&ha->cs84xx->kref, __qla84xx_chip_release); |
| 7728 | } |
| 7729 | |
| 7730 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7731 | qla84xx_init_chip(scsi_qla_host_t *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7732 | { |
| 7733 | int rval; |
| 7734 | uint16_t status[2]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7735 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7736 | |
| 7737 | mutex_lock(&ha->cs84xx->fw_update_mutex); |
| 7738 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7739 | rval = qla84xx_verify_chip(vha, status); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7740 | |
| 7741 | mutex_unlock(&ha->cs84xx->fw_update_mutex); |
| 7742 | |
| 7743 | return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED: |
| 7744 | QLA_SUCCESS; |
| 7745 | } |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7746 | |
| 7747 | /* 81XX Support **************************************************************/ |
| 7748 | |
| 7749 | int |
| 7750 | qla81xx_nvram_config(scsi_qla_host_t *vha) |
| 7751 | { |
| 7752 | int rval; |
| 7753 | struct init_cb_81xx *icb; |
| 7754 | struct nvram_81xx *nv; |
| 7755 | uint32_t *dptr; |
| 7756 | uint8_t *dptr1, *dptr2; |
| 7757 | uint32_t chksum; |
| 7758 | uint16_t cnt; |
| 7759 | struct qla_hw_data *ha = vha->hw; |
| 7760 | |
| 7761 | rval = QLA_SUCCESS; |
| 7762 | icb = (struct init_cb_81xx *)ha->init_cb; |
| 7763 | nv = ha->nvram; |
| 7764 | |
| 7765 | /* Determine NVRAM starting address. */ |
| 7766 | ha->nvram_size = sizeof(struct nvram_81xx); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7767 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 7768 | if (IS_P3P_TYPE(ha) || IS_QLA8031(ha)) |
| 7769 | ha->vpd_size = FA_VPD_SIZE_82XX; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7770 | |
| 7771 | /* Get VPD data into cache */ |
| 7772 | ha->vpd = ha->nvram + VPD_OFFSET; |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 7773 | ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2, |
| 7774 | ha->vpd_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7775 | |
| 7776 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 7777 | 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] | 7778 | ha->nvram_size); |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 7779 | dptr = (uint32_t *)nv; |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 7780 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++) |
| 7781 | chksum += le32_to_cpu(*dptr); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7782 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7783 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111, |
| 7784 | "Contents of NVRAM:\n"); |
| 7785 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112, |
| 7786 | (uint8_t *)nv, ha->nvram_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7787 | |
| 7788 | /* Bad NVRAM data, set defaults parameters. */ |
| 7789 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 7790 | || nv->id[3] != ' ' || |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7791 | nv->nvram_version < cpu_to_le16(ICB_VERSION)) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7792 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7793 | ql_log(ql_log_info, vha, 0x0073, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 7794 | "Inconsistent NVRAM detected: checksum=0x%x id=%c " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7795 | "version=0x%x.\n", chksum, nv->id[0], |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7796 | le16_to_cpu(nv->nvram_version)); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7797 | ql_log(ql_log_info, vha, 0x0074, |
| 7798 | "Falling back to functioning (yet invalid -- WWPN) " |
| 7799 | "defaults.\n"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7800 | |
| 7801 | /* |
| 7802 | * Set default initialization control block. |
| 7803 | */ |
| 7804 | memset(nv, 0, ha->nvram_size); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7805 | nv->nvram_version = cpu_to_le16(ICB_VERSION); |
| 7806 | nv->version = cpu_to_le16(ICB_VERSION); |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 7807 | nv->frame_payload_size = 2048; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7808 | nv->execution_throttle = cpu_to_le16(0xFFFF); |
| 7809 | nv->exchange_count = cpu_to_le16(0); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7810 | nv->port_name[0] = 0x21; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7811 | nv->port_name[1] = 0x00 + ha->port_no + 1; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7812 | nv->port_name[2] = 0x00; |
| 7813 | nv->port_name[3] = 0xe0; |
| 7814 | nv->port_name[4] = 0x8b; |
| 7815 | nv->port_name[5] = 0x1c; |
| 7816 | nv->port_name[6] = 0x55; |
| 7817 | nv->port_name[7] = 0x86; |
| 7818 | nv->node_name[0] = 0x20; |
| 7819 | nv->node_name[1] = 0x00; |
| 7820 | nv->node_name[2] = 0x00; |
| 7821 | nv->node_name[3] = 0xe0; |
| 7822 | nv->node_name[4] = 0x8b; |
| 7823 | nv->node_name[5] = 0x1c; |
| 7824 | nv->node_name[6] = 0x55; |
| 7825 | nv->node_name[7] = 0x86; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7826 | nv->login_retry_count = cpu_to_le16(8); |
| 7827 | nv->interrupt_delay_timer = cpu_to_le16(0); |
| 7828 | nv->login_timeout = cpu_to_le16(0); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7829 | nv->firmware_options_1 = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7830 | cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 7831 | nv->firmware_options_2 = cpu_to_le32(2 << 4); |
| 7832 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 7833 | nv->firmware_options_3 = cpu_to_le32(2 << 13); |
| 7834 | nv->host_p = cpu_to_le32(BIT_11|BIT_10); |
| 7835 | nv->efi_parameters = cpu_to_le32(0); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7836 | nv->reset_delay = 5; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7837 | nv->max_luns_per_target = cpu_to_le16(128); |
| 7838 | nv->port_down_retry_count = cpu_to_le16(30); |
| 7839 | nv->link_down_timeout = cpu_to_le16(180); |
Andrew Vasquez | eeebcc9 | 2009-06-03 09:55:24 -0700 | [diff] [blame] | 7840 | nv->enode_mac[0] = 0x00; |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 7841 | nv->enode_mac[1] = 0xC0; |
| 7842 | nv->enode_mac[2] = 0xDD; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7843 | nv->enode_mac[3] = 0x04; |
| 7844 | nv->enode_mac[4] = 0x05; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7845 | nv->enode_mac[5] = 0x06 + ha->port_no + 1; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7846 | |
| 7847 | rval = 1; |
| 7848 | } |
| 7849 | |
Arun Easi | 9e522cd | 2012-08-22 14:21:31 -0400 | [diff] [blame] | 7850 | if (IS_T10_PI_CAPABLE(ha)) |
| 7851 | nv->frame_payload_size &= ~7; |
| 7852 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7853 | qlt_81xx_config_nvram_stage1(vha, nv); |
| 7854 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7855 | /* Reset Initialization control block */ |
Andrew Vasquez | 773120e | 2011-05-10 11:30:14 -0700 | [diff] [blame] | 7856 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7857 | |
| 7858 | /* Copy 1st segment. */ |
| 7859 | dptr1 = (uint8_t *)icb; |
| 7860 | dptr2 = (uint8_t *)&nv->version; |
| 7861 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 7862 | while (cnt--) |
| 7863 | *dptr1++ = *dptr2++; |
| 7864 | |
| 7865 | icb->login_retry_count = nv->login_retry_count; |
| 7866 | |
| 7867 | /* Copy 2nd segment. */ |
| 7868 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 7869 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 7870 | cnt = (uint8_t *)&icb->reserved_5 - |
| 7871 | (uint8_t *)&icb->interrupt_delay_timer; |
| 7872 | while (cnt--) |
| 7873 | *dptr1++ = *dptr2++; |
| 7874 | |
| 7875 | memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac)); |
| 7876 | /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */ |
| 7877 | 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] | 7878 | icb->enode_mac[0] = 0x00; |
| 7879 | icb->enode_mac[1] = 0xC0; |
| 7880 | icb->enode_mac[2] = 0xDD; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7881 | icb->enode_mac[3] = 0x04; |
| 7882 | icb->enode_mac[4] = 0x05; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7883 | icb->enode_mac[5] = 0x06 + ha->port_no + 1; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7884 | } |
| 7885 | |
Andrew Vasquez | b64b0e8 | 2009-03-24 09:08:01 -0700 | [diff] [blame] | 7886 | /* Use extended-initialization control block. */ |
| 7887 | memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb)); |
| 7888 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7889 | /* |
| 7890 | * Setup driver NVRAM options. |
| 7891 | */ |
| 7892 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7893 | "QLE8XXX"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7894 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7895 | qlt_81xx_config_nvram_stage2(vha, icb); |
| 7896 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7897 | /* Use alternate WWN? */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7898 | if (nv->host_p & cpu_to_le32(BIT_15)) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7899 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 7900 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 7901 | } |
| 7902 | |
| 7903 | /* Prepare nodename */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7904 | if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7905 | /* |
| 7906 | * Firmware will apply the following mask if the nodename was |
| 7907 | * not provided. |
| 7908 | */ |
| 7909 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 7910 | icb->node_name[0] &= 0xF0; |
| 7911 | } |
| 7912 | |
| 7913 | /* Set host adapter parameters. */ |
| 7914 | ha->flags.disable_risc_code_load = 0; |
| 7915 | ha->flags.enable_lip_reset = 0; |
| 7916 | ha->flags.enable_lip_full_login = |
| 7917 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 7918 | ha->flags.enable_target_reset = |
| 7919 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
| 7920 | ha->flags.enable_led_scheme = 0; |
| 7921 | ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0; |
| 7922 | |
| 7923 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 7924 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 7925 | |
| 7926 | /* save HBA serial number */ |
| 7927 | ha->serial0 = icb->port_name[5]; |
| 7928 | ha->serial1 = icb->port_name[6]; |
| 7929 | ha->serial2 = icb->port_name[7]; |
| 7930 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 7931 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
| 7932 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7933 | icb->execution_throttle = cpu_to_le16(0xFFFF); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7934 | |
| 7935 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 7936 | |
| 7937 | /* Set minimum login_timeout to 4 seconds. */ |
| 7938 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 7939 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 7940 | if (le16_to_cpu(nv->login_timeout) < 4) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7941 | nv->login_timeout = cpu_to_le16(4); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7942 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7943 | |
| 7944 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 7945 | ha->r_a_tov = 100; |
| 7946 | |
| 7947 | ha->loop_reset_delay = nv->reset_delay; |
| 7948 | |
| 7949 | /* Link Down Timeout = 0: |
| 7950 | * |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 7951 | * When Port Down timer expires we will start returning |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7952 | * I/O's to OS with "DID_NO_CONNECT". |
| 7953 | * |
| 7954 | * Link Down Timeout != 0: |
| 7955 | * |
| 7956 | * The driver waits for the link to come up after link down |
| 7957 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 7958 | */ |
| 7959 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 7960 | ha->loop_down_abort_time = |
| 7961 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 7962 | } else { |
| 7963 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 7964 | ha->loop_down_abort_time = |
| 7965 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 7966 | } |
| 7967 | |
| 7968 | /* Need enough time to try and get the port back. */ |
| 7969 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 7970 | if (qlport_down_retry) |
| 7971 | ha->port_down_retry_count = qlport_down_retry; |
| 7972 | |
| 7973 | /* Set login_retry_count */ |
| 7974 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 7975 | if (ha->port_down_retry_count == |
| 7976 | le16_to_cpu(nv->port_down_retry_count) && |
| 7977 | ha->port_down_retry_count > 3) |
| 7978 | ha->login_retry_count = ha->port_down_retry_count; |
| 7979 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 7980 | ha->login_retry_count = ha->port_down_retry_count; |
| 7981 | if (ql2xloginretrycount) |
| 7982 | ha->login_retry_count = ql2xloginretrycount; |
| 7983 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 7984 | /* if not running MSI-X we need handshaking on interrupts */ |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7985 | 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] | 7986 | icb->firmware_options_2 |= cpu_to_le32(BIT_22); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 7987 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7988 | /* Enable ZIO. */ |
| 7989 | if (!vha->flags.init_done) { |
| 7990 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 7991 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 7992 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 7993 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 7994 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7995 | icb->firmware_options_2 &= cpu_to_le32( |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7996 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
| 7997 | vha->flags.process_response_queue = 0; |
| 7998 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
| 7999 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 8000 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 8001 | ql_log(ql_log_info, vha, 0x0075, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 8002 | "ZIO mode %d enabled; timer delay (%d us).\n", |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 8003 | ha->zio_mode, |
| 8004 | ha->zio_timer * 100); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 8005 | |
| 8006 | icb->firmware_options_2 |= cpu_to_le32( |
| 8007 | (uint32_t)ha->zio_mode); |
| 8008 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
| 8009 | vha->flags.process_response_queue = 1; |
| 8010 | } |
| 8011 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 8012 | /* enable RIDA Format2 */ |
| 8013 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) |
| 8014 | icb->firmware_options_3 |= BIT_0; |
| 8015 | |
Duane Grigsby | edd05de | 2017-10-13 09:34:06 -0700 | [diff] [blame] | 8016 | if (IS_QLA27XX(ha)) { |
| 8017 | icb->firmware_options_3 |= BIT_8; |
| 8018 | ql_dbg(ql_log_info, vha, 0x0075, |
| 8019 | "Enabling direct connection.\n"); |
| 8020 | } |
| 8021 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 8022 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 8023 | ql_log(ql_log_warn, vha, 0x0076, |
| 8024 | "NVRAM configuration failed.\n"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 8025 | } |
| 8026 | return (rval); |
| 8027 | } |
| 8028 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8029 | int |
| 8030 | qla82xx_restart_isp(scsi_qla_host_t *vha) |
| 8031 | { |
| 8032 | int status, rval; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8033 | struct qla_hw_data *ha = vha->hw; |
| 8034 | struct req_que *req = ha->req_q_map[0]; |
| 8035 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
| 8036 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 8037 | unsigned long flags; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8038 | |
| 8039 | status = qla2x00_init_rings(vha); |
| 8040 | if (!status) { |
| 8041 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 8042 | ha->flags.chip_reset_done = 1; |
| 8043 | |
| 8044 | status = qla2x00_fw_ready(vha); |
| 8045 | if (!status) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8046 | /* Issue a marker after FW becomes ready. */ |
| 8047 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8048 | vha->flags.online = 1; |
Chad Dupuis | 7108b76 | 2014-04-11 16:54:45 -0400 | [diff] [blame] | 8049 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8050 | } |
| 8051 | |
| 8052 | /* if no cable then assume it's good */ |
| 8053 | if ((vha->device_flags & DFLG_NO_CABLE)) |
| 8054 | status = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8055 | } |
| 8056 | |
| 8057 | if (!status) { |
| 8058 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 8059 | |
| 8060 | if (!atomic_read(&vha->loop_down_timer)) { |
| 8061 | /* |
| 8062 | * Issue marker command only when we are going |
| 8063 | * to start the I/O . |
| 8064 | */ |
| 8065 | vha->marker_needed = 1; |
| 8066 | } |
| 8067 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8068 | ha->isp_ops->enable_intrs(ha); |
| 8069 | |
| 8070 | ha->isp_abort_cnt = 0; |
| 8071 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 8072 | |
Saurav Kashyap | 5329678 | 2011-05-10 11:30:06 -0700 | [diff] [blame] | 8073 | /* Update the firmware version */ |
Giridhar Malavali | 3173167 | 2011-08-16 11:31:54 -0700 | [diff] [blame] | 8074 | status = qla82xx_check_md_needed(vha); |
Saurav Kashyap | 5329678 | 2011-05-10 11:30:06 -0700 | [diff] [blame] | 8075 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8076 | if (ha->fce) { |
| 8077 | ha->flags.fce_enabled = 1; |
| 8078 | memset(ha->fce, 0, |
| 8079 | fce_calc_size(ha->fce_bufs)); |
| 8080 | rval = qla2x00_enable_fce_trace(vha, |
| 8081 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 8082 | &ha->fce_bufs); |
| 8083 | if (rval) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 8084 | ql_log(ql_log_warn, vha, 0x8001, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 8085 | "Unable to reinitialize FCE (%d).\n", |
| 8086 | rval); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8087 | ha->flags.fce_enabled = 0; |
| 8088 | } |
| 8089 | } |
| 8090 | |
| 8091 | if (ha->eft) { |
| 8092 | memset(ha->eft, 0, EFT_SIZE); |
| 8093 | rval = qla2x00_enable_eft_trace(vha, |
| 8094 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 8095 | if (rval) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 8096 | ql_log(ql_log_warn, vha, 0x8010, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 8097 | "Unable to reinitialize EFT (%d).\n", |
| 8098 | rval); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8099 | } |
| 8100 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8101 | } |
| 8102 | |
| 8103 | if (!status) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 8104 | ql_dbg(ql_dbg_taskm, vha, 0x8011, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 8105 | "qla82xx_restart_isp succeeded.\n"); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 8106 | |
| 8107 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 8108 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 8109 | if (vp->vp_idx) { |
| 8110 | atomic_inc(&vp->vref_count); |
| 8111 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 8112 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8113 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 8114 | |
| 8115 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 8116 | atomic_dec(&vp->vref_count); |
| 8117 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8118 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 8119 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 8120 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8121 | } else { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 8122 | ql_log(ql_log_warn, vha, 0x8016, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 8123 | "qla82xx_restart_isp **** FAILED ****.\n"); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 8124 | } |
| 8125 | |
| 8126 | return status; |
| 8127 | } |
| 8128 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 8129 | void |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 8130 | qla81xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 8131 | { |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 8132 | struct qla_hw_data *ha = vha->hw; |
| 8133 | |
Himanshu Madhani | f198caf | 2016-01-27 12:03:30 -0500 | [diff] [blame] | 8134 | /* Hold status IOCBs until ABTS response received. */ |
| 8135 | if (ql2xfwholdabts) |
| 8136 | ha->fw_options[3] |= BIT_12; |
| 8137 | |
Giridhar Malavali | 088d09d | 2016-07-06 11:14:20 -0400 | [diff] [blame] | 8138 | /* Set Retry FLOGI in case of P2P connection */ |
| 8139 | if (ha->operating_mode == P2P) { |
| 8140 | ha->fw_options[2] |= BIT_3; |
| 8141 | ql_dbg(ql_dbg_disc, vha, 0x2103, |
| 8142 | "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n", |
| 8143 | __func__, ha->fw_options[2]); |
| 8144 | } |
| 8145 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 8146 | /* Move PUREX, ABTS RX & RIDA to ATIOQ */ |
| 8147 | if (ql2xmvasynctoatio) { |
| 8148 | if (qla_tgt_mode_enabled(vha) || |
| 8149 | qla_dual_mode_enabled(vha)) |
| 8150 | ha->fw_options[2] |= BIT_11; |
| 8151 | else |
| 8152 | ha->fw_options[2] &= ~BIT_11; |
| 8153 | } |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 8154 | |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 8155 | if (qla_tgt_mode_enabled(vha) || |
Quinn Tran | 2da5273 | 2017-06-02 09:12:05 -0700 | [diff] [blame] | 8156 | qla_dual_mode_enabled(vha)) { |
| 8157 | /* FW auto send SCSI status during */ |
| 8158 | ha->fw_options[1] |= BIT_8; |
| 8159 | ha->fw_options[10] |= (u16)SAM_STAT_BUSY << 8; |
| 8160 | |
| 8161 | /* FW perform Exchange validation */ |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 8162 | ha->fw_options[2] |= BIT_4; |
Quinn Tran | 2da5273 | 2017-06-02 09:12:05 -0700 | [diff] [blame] | 8163 | } else { |
| 8164 | ha->fw_options[1] &= ~BIT_8; |
| 8165 | ha->fw_options[10] &= 0x00ff; |
| 8166 | |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 8167 | ha->fw_options[2] &= ~BIT_4; |
Quinn Tran | 2da5273 | 2017-06-02 09:12:05 -0700 | [diff] [blame] | 8168 | } |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 8169 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 8170 | if (ql2xetsenable) { |
| 8171 | /* Enable ETS Burst. */ |
| 8172 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
| 8173 | ha->fw_options[2] |= BIT_9; |
| 8174 | } |
| 8175 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 8176 | ql_dbg(ql_dbg_init, vha, 0x00e9, |
| 8177 | "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n", |
| 8178 | __func__, ha->fw_options[1], ha->fw_options[2], |
| 8179 | ha->fw_options[3], vha->host->active_mode); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 8180 | |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 8181 | qla2x00_set_fw_options(vha, ha->fw_options); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 8182 | } |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 8183 | |
| 8184 | /* |
| 8185 | * qla24xx_get_fcp_prio |
| 8186 | * Gets the fcp cmd priority value for the logged in port. |
| 8187 | * Looks for a match of the port descriptors within |
| 8188 | * each of the fcp prio config entries. If a match is found, |
| 8189 | * the tag (priority) value is returned. |
| 8190 | * |
| 8191 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 8192 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 8193 | * fcport = port structure pointer. |
| 8194 | * |
| 8195 | * Return: |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 8196 | * non-zero (if found) |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 8197 | * -1 (if not found) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 8198 | * |
| 8199 | * Context: |
| 8200 | * Kernel context |
| 8201 | */ |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 8202 | static int |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 8203 | qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 8204 | { |
| 8205 | int i, entries; |
| 8206 | uint8_t pid_match, wwn_match; |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 8207 | int priority; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 8208 | uint32_t pid1, pid2; |
| 8209 | uint64_t wwn1, wwn2; |
| 8210 | struct qla_fcp_prio_entry *pri_entry; |
| 8211 | struct qla_hw_data *ha = vha->hw; |
| 8212 | |
| 8213 | if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled) |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 8214 | return -1; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 8215 | |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 8216 | priority = -1; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 8217 | entries = ha->fcp_prio_cfg->num_entries; |
| 8218 | pri_entry = &ha->fcp_prio_cfg->entry[0]; |
| 8219 | |
| 8220 | for (i = 0; i < entries; i++) { |
| 8221 | pid_match = wwn_match = 0; |
| 8222 | |
| 8223 | if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) { |
| 8224 | pri_entry++; |
| 8225 | continue; |
| 8226 | } |
| 8227 | |
| 8228 | /* check source pid for a match */ |
| 8229 | if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) { |
| 8230 | pid1 = pri_entry->src_pid & INVALID_PORT_ID; |
| 8231 | pid2 = vha->d_id.b24 & INVALID_PORT_ID; |
| 8232 | if (pid1 == INVALID_PORT_ID) |
| 8233 | pid_match++; |
| 8234 | else if (pid1 == pid2) |
| 8235 | pid_match++; |
| 8236 | } |
| 8237 | |
| 8238 | /* check destination pid for a match */ |
| 8239 | if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) { |
| 8240 | pid1 = pri_entry->dst_pid & INVALID_PORT_ID; |
| 8241 | pid2 = fcport->d_id.b24 & INVALID_PORT_ID; |
| 8242 | if (pid1 == INVALID_PORT_ID) |
| 8243 | pid_match++; |
| 8244 | else if (pid1 == pid2) |
| 8245 | pid_match++; |
| 8246 | } |
| 8247 | |
| 8248 | /* check source WWN for a match */ |
| 8249 | if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) { |
| 8250 | wwn1 = wwn_to_u64(vha->port_name); |
| 8251 | wwn2 = wwn_to_u64(pri_entry->src_wwpn); |
| 8252 | if (wwn2 == (uint64_t)-1) |
| 8253 | wwn_match++; |
| 8254 | else if (wwn1 == wwn2) |
| 8255 | wwn_match++; |
| 8256 | } |
| 8257 | |
| 8258 | /* check destination WWN for a match */ |
| 8259 | if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) { |
| 8260 | wwn1 = wwn_to_u64(fcport->port_name); |
| 8261 | wwn2 = wwn_to_u64(pri_entry->dst_wwpn); |
| 8262 | if (wwn2 == (uint64_t)-1) |
| 8263 | wwn_match++; |
| 8264 | else if (wwn1 == wwn2) |
| 8265 | wwn_match++; |
| 8266 | } |
| 8267 | |
| 8268 | if (pid_match == 2 || wwn_match == 2) { |
| 8269 | /* Found a matching entry */ |
| 8270 | if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID) |
| 8271 | priority = pri_entry->tag; |
| 8272 | break; |
| 8273 | } |
| 8274 | |
| 8275 | pri_entry++; |
| 8276 | } |
| 8277 | |
| 8278 | return priority; |
| 8279 | } |
| 8280 | |
| 8281 | /* |
| 8282 | * qla24xx_update_fcport_fcp_prio |
| 8283 | * Activates fcp priority for the logged in fc port |
| 8284 | * |
| 8285 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 8286 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 8287 | * fcp = port structure pointer. |
| 8288 | * |
| 8289 | * Return: |
| 8290 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 8291 | * |
| 8292 | * Context: |
| 8293 | * Kernel context. |
| 8294 | */ |
| 8295 | int |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 8296 | 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] | 8297 | { |
| 8298 | int ret; |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 8299 | int priority; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 8300 | uint16_t mb[5]; |
| 8301 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 8302 | if (fcport->port_type != FCT_TARGET || |
| 8303 | fcport->loop_id == FC_NO_LOOP_ID) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 8304 | return QLA_FUNCTION_FAILED; |
| 8305 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 8306 | priority = qla24xx_get_fcp_prio(vha, fcport); |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 8307 | if (priority < 0) |
| 8308 | return QLA_FUNCTION_FAILED; |
| 8309 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 8310 | if (IS_P3P_TYPE(vha->hw)) { |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 8311 | fcport->fcp_prio = priority & 0xf; |
| 8312 | return QLA_SUCCESS; |
| 8313 | } |
| 8314 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 8315 | ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb); |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 8316 | if (ret == QLA_SUCCESS) { |
| 8317 | if (fcport->fcp_prio != priority) |
| 8318 | ql_dbg(ql_dbg_user, vha, 0x709e, |
| 8319 | "Updated FCP_CMND priority - value=%d loop_id=%d " |
| 8320 | "port_id=%02x%02x%02x.\n", priority, |
| 8321 | fcport->loop_id, fcport->d_id.b.domain, |
| 8322 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 8323 | fcport->fcp_prio = priority & 0xf; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 8324 | } else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 8325 | ql_dbg(ql_dbg_user, vha, 0x704f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 8326 | "Unable to update FCP_CMND priority - ret=0x%x for " |
| 8327 | "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id, |
| 8328 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 8329 | fcport->d_id.b.al_pa); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 8330 | return ret; |
| 8331 | } |
| 8332 | |
| 8333 | /* |
| 8334 | * qla24xx_update_all_fcp_prio |
| 8335 | * Activates fcp priority for all the logged in ports |
| 8336 | * |
| 8337 | * Input: |
| 8338 | * ha = adapter block pointer. |
| 8339 | * |
| 8340 | * Return: |
| 8341 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 8342 | * |
| 8343 | * Context: |
| 8344 | * Kernel context. |
| 8345 | */ |
| 8346 | int |
| 8347 | qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha) |
| 8348 | { |
| 8349 | int ret; |
| 8350 | fc_port_t *fcport; |
| 8351 | |
| 8352 | ret = QLA_FUNCTION_FAILED; |
| 8353 | /* We need to set priority for all logged in ports */ |
| 8354 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 8355 | ret = qla24xx_update_fcport_fcp_prio(vha, fcport); |
| 8356 | |
| 8357 | return ret; |
| 8358 | } |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8359 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 8360 | struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos, |
| 8361 | int vp_idx, bool startqp) |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8362 | { |
| 8363 | int rsp_id = 0; |
| 8364 | int req_id = 0; |
| 8365 | int i; |
| 8366 | struct qla_hw_data *ha = vha->hw; |
| 8367 | uint16_t qpair_id = 0; |
| 8368 | struct qla_qpair *qpair = NULL; |
| 8369 | struct qla_msix_entry *msix; |
| 8370 | |
| 8371 | if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) { |
| 8372 | ql_log(ql_log_warn, vha, 0x00181, |
| 8373 | "FW/Driver is not multi-queue capable.\n"); |
| 8374 | return NULL; |
| 8375 | } |
| 8376 | |
Himanshu Madhani | c38d1ba | 2017-10-13 15:43:22 -0700 | [diff] [blame] | 8377 | if (ql2xmqsupport || ql2xnvmeenable) { |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8378 | qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL); |
| 8379 | if (qpair == NULL) { |
| 8380 | ql_log(ql_log_warn, vha, 0x0182, |
| 8381 | "Failed to allocate memory for queue pair.\n"); |
| 8382 | return NULL; |
| 8383 | } |
| 8384 | memset(qpair, 0, sizeof(struct qla_qpair)); |
| 8385 | |
| 8386 | qpair->hw = vha->hw; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 8387 | qpair->vha = vha; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 8388 | qpair->qp_lock_ptr = &qpair->qp_lock; |
| 8389 | spin_lock_init(&qpair->qp_lock); |
Quinn Tran | af7bb38 | 2017-06-13 20:47:23 -0700 | [diff] [blame] | 8390 | qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8391 | |
| 8392 | /* Assign available que pair id */ |
| 8393 | mutex_lock(&ha->mq_lock); |
| 8394 | qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs); |
Sawan Chandak | b95b945 | 2017-05-24 18:06:20 -0700 | [diff] [blame] | 8395 | if (ha->num_qpairs >= ha->max_qpairs) { |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8396 | mutex_unlock(&ha->mq_lock); |
| 8397 | ql_log(ql_log_warn, vha, 0x0183, |
| 8398 | "No resources to create additional q pair.\n"); |
| 8399 | goto fail_qid_map; |
| 8400 | } |
Sawan Chandak | b95b945 | 2017-05-24 18:06:20 -0700 | [diff] [blame] | 8401 | ha->num_qpairs++; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8402 | set_bit(qpair_id, ha->qpair_qid_map); |
| 8403 | ha->queue_pair_map[qpair_id] = qpair; |
| 8404 | qpair->id = qpair_id; |
| 8405 | qpair->vp_idx = vp_idx; |
himanshu.madhani@cavium.com | e6373f33 | 2017-08-23 15:04:57 -0700 | [diff] [blame] | 8406 | qpair->fw_started = ha->flags.fw_started; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 8407 | INIT_LIST_HEAD(&qpair->hints_list); |
Duane Grigsby | cf19c45 | 2017-08-23 15:04:58 -0700 | [diff] [blame] | 8408 | INIT_LIST_HEAD(&qpair->nvme_done_list); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 8409 | qpair->chip_reset = ha->base_qpair->chip_reset; |
| 8410 | qpair->enable_class_2 = ha->base_qpair->enable_class_2; |
| 8411 | qpair->enable_explicit_conf = |
| 8412 | ha->base_qpair->enable_explicit_conf; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8413 | |
| 8414 | for (i = 0; i < ha->msix_count; i++) { |
Quinn Tran | 093df73 | 2016-12-12 14:40:09 -0800 | [diff] [blame] | 8415 | msix = &ha->msix_entries[i]; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8416 | if (msix->in_use) |
| 8417 | continue; |
| 8418 | qpair->msix = msix; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 8419 | ql_dbg(ql_dbg_multiq, vha, 0xc00f, |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8420 | "Vector %x selected for qpair\n", msix->vector); |
| 8421 | break; |
| 8422 | } |
| 8423 | if (!qpair->msix) { |
| 8424 | ql_log(ql_log_warn, vha, 0x0184, |
| 8425 | "Out of MSI-X vectors!.\n"); |
| 8426 | goto fail_msix; |
| 8427 | } |
| 8428 | |
| 8429 | qpair->msix->in_use = 1; |
| 8430 | list_add_tail(&qpair->qp_list_elem, &vha->qp_list); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 8431 | qpair->pdev = ha->pdev; |
| 8432 | if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) |
| 8433 | qpair->reqq_start_iocbs = qla_83xx_start_iocbs; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8434 | |
| 8435 | mutex_unlock(&ha->mq_lock); |
| 8436 | |
| 8437 | /* Create response queue first */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 8438 | rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp); |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8439 | if (!rsp_id) { |
| 8440 | ql_log(ql_log_warn, vha, 0x0185, |
| 8441 | "Failed to create response queue.\n"); |
| 8442 | goto fail_rsp; |
| 8443 | } |
| 8444 | |
| 8445 | qpair->rsp = ha->rsp_q_map[rsp_id]; |
| 8446 | |
| 8447 | /* Create request queue */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 8448 | req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos, |
| 8449 | startqp); |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8450 | if (!req_id) { |
| 8451 | ql_log(ql_log_warn, vha, 0x0186, |
| 8452 | "Failed to create request queue.\n"); |
| 8453 | goto fail_req; |
| 8454 | } |
| 8455 | |
| 8456 | qpair->req = ha->req_q_map[req_id]; |
| 8457 | qpair->rsp->req = qpair->req; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 8458 | qpair->rsp->qpair = qpair; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 8459 | /* init qpair to this cpu. Will adjust at run time. */ |
| 8460 | qla_cpu_update(qpair, smp_processor_id()); |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8461 | |
| 8462 | if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) { |
| 8463 | if (ha->fw_attributes & BIT_4) |
| 8464 | qpair->difdix_supported = 1; |
| 8465 | } |
| 8466 | |
| 8467 | qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep); |
| 8468 | if (!qpair->srb_mempool) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 8469 | ql_log(ql_log_warn, vha, 0xd036, |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8470 | "Failed to create srb mempool for qpair %d\n", |
| 8471 | qpair->id); |
| 8472 | goto fail_mempool; |
| 8473 | } |
| 8474 | |
| 8475 | /* Mark as online */ |
| 8476 | qpair->online = 1; |
| 8477 | |
| 8478 | if (!vha->flags.qpairs_available) |
| 8479 | vha->flags.qpairs_available = 1; |
| 8480 | |
| 8481 | ql_dbg(ql_dbg_multiq, vha, 0xc00d, |
| 8482 | "Request/Response queue pair created, id %d\n", |
| 8483 | qpair->id); |
| 8484 | ql_dbg(ql_dbg_init, vha, 0x0187, |
| 8485 | "Request/Response queue pair created, id %d\n", |
| 8486 | qpair->id); |
| 8487 | } |
| 8488 | return qpair; |
| 8489 | |
| 8490 | fail_mempool: |
| 8491 | fail_req: |
| 8492 | qla25xx_delete_rsp_que(vha, qpair->rsp); |
| 8493 | fail_rsp: |
| 8494 | mutex_lock(&ha->mq_lock); |
| 8495 | qpair->msix->in_use = 0; |
| 8496 | list_del(&qpair->qp_list_elem); |
| 8497 | if (list_empty(&vha->qp_list)) |
| 8498 | vha->flags.qpairs_available = 0; |
| 8499 | fail_msix: |
| 8500 | ha->queue_pair_map[qpair_id] = NULL; |
| 8501 | clear_bit(qpair_id, ha->qpair_qid_map); |
Sawan Chandak | b95b945 | 2017-05-24 18:06:20 -0700 | [diff] [blame] | 8502 | ha->num_qpairs--; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8503 | mutex_unlock(&ha->mq_lock); |
| 8504 | fail_qid_map: |
| 8505 | kfree(qpair); |
| 8506 | return NULL; |
| 8507 | } |
| 8508 | |
| 8509 | int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair) |
| 8510 | { |
Sawan Chandak | d65237c | 2017-06-13 20:47:19 -0700 | [diff] [blame] | 8511 | int ret = QLA_FUNCTION_FAILED; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8512 | struct qla_hw_data *ha = qpair->hw; |
| 8513 | |
| 8514 | qpair->delete_in_progress = 1; |
| 8515 | while (atomic_read(&qpair->ref_count)) |
| 8516 | msleep(500); |
| 8517 | |
| 8518 | ret = qla25xx_delete_req_que(vha, qpair->req); |
| 8519 | if (ret != QLA_SUCCESS) |
| 8520 | goto fail; |
himanshu.madhani@cavium.com | 7867b98 | 2017-12-04 14:45:16 -0800 | [diff] [blame] | 8521 | |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8522 | ret = qla25xx_delete_rsp_que(vha, qpair->rsp); |
| 8523 | if (ret != QLA_SUCCESS) |
| 8524 | goto fail; |
| 8525 | |
| 8526 | mutex_lock(&ha->mq_lock); |
| 8527 | ha->queue_pair_map[qpair->id] = NULL; |
| 8528 | clear_bit(qpair->id, ha->qpair_qid_map); |
Sawan Chandak | b95b945 | 2017-05-24 18:06:20 -0700 | [diff] [blame] | 8529 | ha->num_qpairs--; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8530 | list_del(&qpair->qp_list_elem); |
Sawan Chandak | d65237c | 2017-06-13 20:47:19 -0700 | [diff] [blame] | 8531 | if (list_empty(&vha->qp_list)) { |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8532 | vha->flags.qpairs_available = 0; |
Sawan Chandak | d65237c | 2017-06-13 20:47:19 -0700 | [diff] [blame] | 8533 | vha->flags.qpairs_req_created = 0; |
| 8534 | vha->flags.qpairs_rsp_created = 0; |
| 8535 | } |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8536 | mempool_destroy(qpair->srb_mempool); |
| 8537 | kfree(qpair); |
| 8538 | mutex_unlock(&ha->mq_lock); |
| 8539 | |
| 8540 | return QLA_SUCCESS; |
| 8541 | fail: |
| 8542 | return ret; |
| 8543 | } |