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 |
Saurav Kashyap | 1e63395 | 2013-02-08 01:57:54 -0500 | [diff] [blame] | 3 | * Copyright (c) 2003-2013 QLogic Corporation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | #include "qla_def.h" |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 8 | #include "qla_gbl.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
| 10 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 11 | #include <linux/slab.h> |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 12 | #include <linux/vmalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
| 14 | #include "qla_devtbl.h" |
| 15 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 16 | #ifdef CONFIG_SPARC |
| 17 | #include <asm/prom.h> |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 18 | #endif |
| 19 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 20 | #include <target/target_core_base.h> |
| 21 | #include "qla_target.h" |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | /* |
| 24 | * QLogic ISP2x00 Hardware Support Function Prototypes. |
| 25 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | static int qla2x00_isp_firmware(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | static int qla2x00_setup_chip(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | static int qla2x00_fw_ready(scsi_qla_host_t *); |
| 29 | static int qla2x00_configure_hba(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | static int qla2x00_configure_loop(scsi_qla_host_t *); |
| 31 | static int qla2x00_configure_local_loop(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | static int qla2x00_configure_fabric(scsi_qla_host_t *); |
| 33 | static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *, |
| 35 | uint16_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | static int qla2x00_restart_isp(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 39 | static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *); |
| 40 | static int qla84xx_init_chip(scsi_qla_host_t *); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 41 | static int qla25xx_init_queues(struct qla_hw_data *); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 42 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 43 | /* SRB Extensions ---------------------------------------------------------- */ |
| 44 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 45 | void |
| 46 | qla2x00_sp_timeout(unsigned long __data) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 47 | { |
| 48 | srb_t *sp = (srb_t *)__data; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 49 | struct srb_iocb *iocb; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 50 | fc_port_t *fcport = sp->fcport; |
| 51 | struct qla_hw_data *ha = fcport->vha->hw; |
| 52 | struct req_que *req; |
| 53 | unsigned long flags; |
| 54 | |
| 55 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 56 | req = ha->req_q_map[0]; |
| 57 | req->outstanding_cmds[sp->handle] = NULL; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 58 | iocb = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 59 | iocb->timeout(sp); |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 60 | sp->free(fcport->vha, sp); |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 61 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 64 | void |
| 65 | qla2x00_sp_free(void *data, void *ptr) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 66 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 67 | srb_t *sp = (srb_t *)ptr; |
| 68 | struct srb_iocb *iocb = &sp->u.iocb_cmd; |
| 69 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 70 | |
Chad Dupuis | 4d97cc5 | 2010-10-15 11:27:41 -0700 | [diff] [blame] | 71 | del_timer(&iocb->timer); |
Chad Dupuis | b00ee7d | 2013-02-08 01:57:50 -0500 | [diff] [blame] | 72 | qla2x00_rel_sp(vha, sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 75 | /* Asynchronous Login/Logout Routines -------------------------------------- */ |
| 76 | |
Saurav Kashyap | a9b6f72 | 2012-08-22 14:21:01 -0400 | [diff] [blame] | 77 | unsigned long |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 78 | qla2x00_get_async_timeout(struct scsi_qla_host *vha) |
| 79 | { |
| 80 | unsigned long tmo; |
| 81 | struct qla_hw_data *ha = vha->hw; |
| 82 | |
| 83 | /* Firmware should use switch negotiated r_a_tov for timeout. */ |
| 84 | tmo = ha->r_a_tov / 10 * 2; |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 85 | if (IS_QLAFX00(ha)) { |
| 86 | tmo = FX00_DEF_RATOV * 2; |
| 87 | } else if (!IS_FWI2_CAPABLE(ha)) { |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 88 | /* |
| 89 | * Except for earlier ISPs where the timeout is seeded from the |
| 90 | * initialization control block. |
| 91 | */ |
| 92 | tmo = ha->login_timeout; |
| 93 | } |
| 94 | return tmo; |
| 95 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 96 | |
| 97 | static void |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 98 | qla2x00_async_iocb_timeout(void *data) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 99 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 100 | srb_t *sp = (srb_t *)data; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 101 | fc_port_t *fcport = sp->fcport; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 102 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 103 | ql_dbg(ql_dbg_disc, fcport->vha, 0x2071, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 104 | "Async-%s timeout - hdl=%x portid=%02x%02x%02x.\n", |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 105 | sp->name, sp->handle, fcport->d_id.b.domain, fcport->d_id.b.area, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 106 | fcport->d_id.b.al_pa); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 107 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 108 | fcport->flags &= ~FCF_ASYNC_SENT; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 109 | if (sp->type == SRB_LOGIN_CMD) { |
| 110 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 111 | qla2x00_post_async_logout_work(fcport->vha, fcport, NULL); |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 112 | /* Retry as needed. */ |
| 113 | lio->u.logio.data[0] = MBS_COMMAND_ERROR; |
| 114 | lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ? |
| 115 | QLA_LOGIO_LOGIN_RETRIED : 0; |
| 116 | qla2x00_post_async_login_done_work(fcport->vha, fcport, |
| 117 | lio->u.logio.data); |
| 118 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 121 | static void |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 122 | qla2x00_async_login_sp_done(void *data, void *ptr, int res) |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 123 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 124 | srb_t *sp = (srb_t *)ptr; |
| 125 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
| 126 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 127 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 128 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
| 129 | qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport, |
| 130 | lio->u.logio.data); |
| 131 | sp->free(sp->fcport->vha, sp); |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 134 | int |
| 135 | qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 136 | uint16_t *data) |
| 137 | { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 138 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 139 | struct srb_iocb *lio; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 140 | int rval; |
| 141 | |
| 142 | rval = QLA_FUNCTION_FAILED; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 143 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 144 | if (!sp) |
| 145 | goto done; |
| 146 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 147 | sp->type = SRB_LOGIN_CMD; |
| 148 | sp->name = "login"; |
| 149 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 150 | |
| 151 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 152 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 153 | sp->done = qla2x00_async_login_sp_done; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 154 | lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 155 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 156 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 157 | rval = qla2x00_start_sp(sp); |
| 158 | if (rval != QLA_SUCCESS) |
| 159 | goto done_free_sp; |
| 160 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 161 | ql_dbg(ql_dbg_disc, vha, 0x2072, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 162 | "Async-login - hdl=%x, loopid=%x portid=%02x%02x%02x " |
| 163 | "retries=%d.\n", sp->handle, fcport->loop_id, |
| 164 | fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 165 | fcport->login_retry); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 166 | return rval; |
| 167 | |
| 168 | done_free_sp: |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 169 | sp->free(fcport->vha, sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 170 | done: |
| 171 | return rval; |
| 172 | } |
| 173 | |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 174 | static void |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 175 | qla2x00_async_logout_sp_done(void *data, void *ptr, int res) |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 176 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 177 | srb_t *sp = (srb_t *)ptr; |
| 178 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
| 179 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 180 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 181 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
| 182 | qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport, |
| 183 | lio->u.logio.data); |
| 184 | sp->free(sp->fcport->vha, sp); |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 187 | int |
| 188 | qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 189 | { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 190 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 191 | struct srb_iocb *lio; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 192 | int rval; |
| 193 | |
| 194 | rval = QLA_FUNCTION_FAILED; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 195 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 196 | if (!sp) |
| 197 | goto done; |
| 198 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 199 | sp->type = SRB_LOGOUT_CMD; |
| 200 | sp->name = "logout"; |
| 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_logout_sp_done; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 206 | rval = qla2x00_start_sp(sp); |
| 207 | if (rval != QLA_SUCCESS) |
| 208 | goto done_free_sp; |
| 209 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 210 | ql_dbg(ql_dbg_disc, vha, 0x2070, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 211 | "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x.\n", |
| 212 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
| 213 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 214 | return rval; |
| 215 | |
| 216 | done_free_sp: |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 217 | sp->free(fcport->vha, sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 218 | done: |
| 219 | return rval; |
| 220 | } |
| 221 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 222 | static void |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 223 | qla2x00_async_adisc_sp_done(void *data, void *ptr, int res) |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 224 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 225 | srb_t *sp = (srb_t *)ptr; |
| 226 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
| 227 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 228 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 229 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
| 230 | qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport, |
| 231 | lio->u.logio.data); |
| 232 | sp->free(sp->fcport->vha, sp); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | int |
| 236 | qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 237 | uint16_t *data) |
| 238 | { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 239 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 240 | struct srb_iocb *lio; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 241 | int rval; |
| 242 | |
| 243 | rval = QLA_FUNCTION_FAILED; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 244 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 245 | if (!sp) |
| 246 | goto done; |
| 247 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 248 | sp->type = SRB_ADISC_CMD; |
| 249 | sp->name = "adisc"; |
| 250 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 251 | |
| 252 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 253 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 254 | sp->done = qla2x00_async_adisc_sp_done; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 255 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 256 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 257 | rval = qla2x00_start_sp(sp); |
| 258 | if (rval != QLA_SUCCESS) |
| 259 | goto done_free_sp; |
| 260 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 261 | ql_dbg(ql_dbg_disc, vha, 0x206f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 262 | "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n", |
| 263 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
| 264 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 265 | return rval; |
| 266 | |
| 267 | done_free_sp: |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 268 | sp->free(fcport->vha, sp); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 269 | done: |
| 270 | return rval; |
| 271 | } |
| 272 | |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 273 | static void |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 274 | qla2x00_async_tm_cmd_done(void *data, void *ptr, int res) |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 275 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 276 | srb_t *sp = (srb_t *)ptr; |
| 277 | struct srb_iocb *iocb = &sp->u.iocb_cmd; |
| 278 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; |
| 279 | uint32_t flags; |
| 280 | uint16_t lun; |
| 281 | int rval; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 282 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 283 | if (!test_bit(UNLOADING, &vha->dpc_flags)) { |
| 284 | flags = iocb->u.tmf.flags; |
| 285 | lun = (uint16_t)iocb->u.tmf.lun; |
| 286 | |
| 287 | /* Issue Marker IOCB */ |
| 288 | rval = qla2x00_marker(vha, vha->hw->req_q_map[0], |
| 289 | vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun, |
| 290 | flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID); |
| 291 | |
| 292 | if ((rval != QLA_SUCCESS) || iocb->u.tmf.data) { |
| 293 | ql_dbg(ql_dbg_taskm, vha, 0x8030, |
| 294 | "TM IOCB failed (%x).\n", rval); |
| 295 | } |
| 296 | } |
| 297 | sp->free(sp->fcport->vha, sp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | int |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 301 | qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t tm_flags, uint32_t lun, |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 302 | uint32_t tag) |
| 303 | { |
| 304 | struct scsi_qla_host *vha = fcport->vha; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 305 | srb_t *sp; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 306 | struct srb_iocb *tcf; |
| 307 | int rval; |
| 308 | |
| 309 | rval = QLA_FUNCTION_FAILED; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 310 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 311 | if (!sp) |
| 312 | goto done; |
| 313 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 314 | sp->type = SRB_TM_CMD; |
| 315 | sp->name = "tmf"; |
| 316 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 317 | |
| 318 | tcf = &sp->u.iocb_cmd; |
| 319 | tcf->u.tmf.flags = tm_flags; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 320 | tcf->u.tmf.lun = lun; |
| 321 | tcf->u.tmf.data = tag; |
| 322 | tcf->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 323 | sp->done = qla2x00_async_tm_cmd_done; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 324 | |
| 325 | rval = qla2x00_start_sp(sp); |
| 326 | if (rval != QLA_SUCCESS) |
| 327 | goto done_free_sp; |
| 328 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 329 | ql_dbg(ql_dbg_taskm, vha, 0x802f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 330 | "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n", |
| 331 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
| 332 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 333 | return rval; |
| 334 | |
| 335 | done_free_sp: |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 336 | sp->free(fcport->vha, sp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 337 | done: |
| 338 | return rval; |
| 339 | } |
| 340 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 341 | void |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 342 | qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 343 | uint16_t *data) |
| 344 | { |
| 345 | int rval; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 346 | |
| 347 | switch (data[0]) { |
| 348 | case MBS_COMMAND_COMPLETE: |
Andrew Vasquez | a4f92a3 | 2011-03-30 11:46:31 -0700 | [diff] [blame] | 349 | /* |
| 350 | * Driver must validate login state - If PRLI not complete, |
| 351 | * force a relogin attempt via implicit LOGO, PLOGI, and PRLI |
| 352 | * requests. |
| 353 | */ |
| 354 | rval = qla2x00_get_port_database(vha, fcport, 0); |
Arun Easi | 0eba25d | 2012-02-09 11:15:58 -0800 | [diff] [blame] | 355 | if (rval == QLA_NOT_LOGGED_IN) { |
| 356 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 357 | fcport->flags |= FCF_LOGIN_NEEDED; |
| 358 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 359 | break; |
| 360 | } |
| 361 | |
Andrew Vasquez | a4f92a3 | 2011-03-30 11:46:31 -0700 | [diff] [blame] | 362 | if (rval != QLA_SUCCESS) { |
| 363 | qla2x00_post_async_logout_work(vha, fcport, NULL); |
| 364 | qla2x00_post_async_login_work(vha, fcport, NULL); |
| 365 | break; |
| 366 | } |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 367 | if (fcport->flags & FCF_FCP2_DEVICE) { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 368 | qla2x00_post_async_adisc_work(vha, fcport, data); |
| 369 | break; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 370 | } |
| 371 | qla2x00_update_fcport(vha, fcport); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 372 | break; |
| 373 | case MBS_COMMAND_ERROR: |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 374 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 375 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
| 376 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 377 | else |
Andrew Vasquez | 80d7944 | 2011-03-30 11:46:17 -0700 | [diff] [blame] | 378 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 379 | break; |
| 380 | case MBS_PORT_ID_USED: |
| 381 | fcport->loop_id = data[1]; |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 382 | qla2x00_post_async_logout_work(vha, fcport, NULL); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 383 | qla2x00_post_async_login_work(vha, fcport, NULL); |
| 384 | break; |
| 385 | case MBS_LOOP_ID_USED: |
| 386 | fcport->loop_id++; |
| 387 | rval = qla2x00_find_new_loop_id(vha, fcport); |
| 388 | if (rval != QLA_SUCCESS) { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 389 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | 80d7944 | 2011-03-30 11:46:17 -0700 | [diff] [blame] | 390 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 391 | break; |
| 392 | } |
| 393 | qla2x00_post_async_login_work(vha, fcport, NULL); |
| 394 | break; |
| 395 | } |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 396 | return; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 399 | void |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 400 | qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 401 | uint16_t *data) |
| 402 | { |
| 403 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 404 | return; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 405 | } |
| 406 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 407 | void |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 408 | qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 409 | uint16_t *data) |
| 410 | { |
| 411 | if (data[0] == MBS_COMMAND_COMPLETE) { |
| 412 | qla2x00_update_fcport(vha, fcport); |
| 413 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 414 | return; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | /* Retry login. */ |
| 418 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 419 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
| 420 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 421 | else |
Andrew Vasquez | 80d7944 | 2011-03-30 11:46:17 -0700 | [diff] [blame] | 422 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 423 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 424 | return; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 425 | } |
| 426 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | /****************************************************************************/ |
| 428 | /* QLogic ISP2x00 Hardware Support Functions. */ |
| 429 | /****************************************************************************/ |
| 430 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 431 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 432 | qla83xx_nic_core_fw_load(scsi_qla_host_t *vha) |
| 433 | { |
| 434 | int rval = QLA_SUCCESS; |
| 435 | struct qla_hw_data *ha = vha->hw; |
| 436 | uint32_t idc_major_ver, idc_minor_ver; |
Saurav Kashyap | 711aa7f | 2012-08-22 14:21:15 -0400 | [diff] [blame] | 437 | uint16_t config[4]; |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 438 | |
| 439 | qla83xx_idc_lock(vha, 0); |
| 440 | |
| 441 | /* SV: TODO: Assign initialization timeout from |
| 442 | * flash-info / other param |
| 443 | */ |
| 444 | ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT; |
| 445 | ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT; |
| 446 | |
| 447 | /* Set our fcoe function presence */ |
| 448 | if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) { |
| 449 | ql_dbg(ql_dbg_p3p, vha, 0xb077, |
| 450 | "Error while setting DRV-Presence.\n"); |
| 451 | rval = QLA_FUNCTION_FAILED; |
| 452 | goto exit; |
| 453 | } |
| 454 | |
| 455 | /* Decide the reset ownership */ |
| 456 | qla83xx_reset_ownership(vha); |
| 457 | |
| 458 | /* |
| 459 | * On first protocol driver load: |
| 460 | * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery |
| 461 | * register. |
| 462 | * Others: Check compatibility with current IDC Major version. |
| 463 | */ |
| 464 | qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver); |
| 465 | if (ha->flags.nic_core_reset_owner) { |
| 466 | /* Set IDC Major version */ |
| 467 | idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION; |
| 468 | qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver); |
| 469 | |
| 470 | /* Clearing IDC-Lock-Recovery register */ |
| 471 | qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0); |
| 472 | } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) { |
| 473 | /* |
| 474 | * Clear further IDC participation if we are not compatible with |
| 475 | * the current IDC Major Version. |
| 476 | */ |
| 477 | ql_log(ql_log_warn, vha, 0xb07d, |
| 478 | "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n", |
| 479 | idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION); |
| 480 | __qla83xx_clear_drv_presence(vha); |
| 481 | rval = QLA_FUNCTION_FAILED; |
| 482 | goto exit; |
| 483 | } |
| 484 | /* Each function sets its supported Minor version. */ |
| 485 | qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver); |
| 486 | idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2)); |
| 487 | qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver); |
| 488 | |
Saurav Kashyap | 711aa7f | 2012-08-22 14:21:15 -0400 | [diff] [blame] | 489 | if (ha->flags.nic_core_reset_owner) { |
| 490 | memset(config, 0, sizeof(config)); |
| 491 | if (!qla81xx_get_port_config(vha, config)) |
| 492 | qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, |
| 493 | QLA8XXX_DEV_READY); |
| 494 | } |
| 495 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 496 | rval = qla83xx_idc_state_handler(vha); |
| 497 | |
| 498 | exit: |
| 499 | qla83xx_idc_unlock(vha, 0); |
| 500 | |
| 501 | return rval; |
| 502 | } |
| 503 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | /* |
| 505 | * qla2x00_initialize_adapter |
| 506 | * Initialize board. |
| 507 | * |
| 508 | * Input: |
| 509 | * ha = adapter block pointer. |
| 510 | * |
| 511 | * Returns: |
| 512 | * 0 = success |
| 513 | */ |
| 514 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 515 | qla2x00_initialize_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | { |
| 517 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 518 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 519 | struct req_que *req = ha->req_q_map[0]; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 520 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | /* Clear adapter flags. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 522 | vha->flags.online = 0; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 523 | ha->flags.chip_reset_done = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 524 | vha->flags.reset_active = 0; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 525 | ha->flags.pci_channel_io_perm_failure = 0; |
| 526 | ha->flags.eeh_busy = 0; |
Joe Carnuccio | fe52f6e | 2013-02-08 01:58:03 -0500 | [diff] [blame] | 527 | ha->thermal_support = THERMAL_SUPPORT_I2C|THERMAL_SUPPORT_ISP; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 528 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 529 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 530 | vha->device_flags = DFLG_NO_CABLE; |
| 531 | vha->dpc_flags = 0; |
| 532 | vha->flags.management_server_logged_in = 0; |
| 533 | vha->marker_needed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | ha->isp_abort_cnt = 0; |
| 535 | ha->beacon_blink_led = 0; |
| 536 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 537 | set_bit(0, ha->req_qid_map); |
| 538 | set_bit(0, ha->rsp_qid_map); |
| 539 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 540 | ql_dbg(ql_dbg_init, vha, 0x0040, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 541 | "Configuring PCI space...\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 542 | rval = ha->isp_ops->pci_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 544 | ql_log(ql_log_warn, vha, 0x0044, |
| 545 | "Unable to configure PCI space.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | return (rval); |
| 547 | } |
| 548 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 549 | ha->isp_ops->reset_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 551 | rval = qla2xxx_get_flash_info(vha); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 552 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 553 | ql_log(ql_log_fatal, vha, 0x004f, |
| 554 | "Unable to validate FLASH data.\n"); |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame^] | 555 | return rval; |
| 556 | } |
| 557 | |
| 558 | if (IS_QLA8044(ha)) { |
| 559 | qla8044_read_reset_template(vha); |
| 560 | |
| 561 | /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0. |
| 562 | * If DONRESET_BIT0 is set, drivers should not set dev_state |
| 563 | * to NEED_RESET. But if NEED_RESET is set, drivers should |
| 564 | * should honor the reset. */ |
| 565 | if (ql2xdontresethba == 1) |
| 566 | qla8044_set_idc_dontreset(vha); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 567 | } |
| 568 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 569 | ha->isp_ops->get_flash_version(vha, req->ring); |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 570 | ql_dbg(ql_dbg_init, vha, 0x0061, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 571 | "Configure NVRAM parameters...\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 572 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 573 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 575 | if (ha->flags.disable_serdes) { |
| 576 | /* Mask HBA via NVRAM settings? */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 577 | ql_log(ql_log_info, vha, 0x0077, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 578 | "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name); |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 579 | return QLA_FUNCTION_FAILED; |
| 580 | } |
| 581 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 582 | ql_dbg(ql_dbg_init, vha, 0x0078, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 583 | "Verifying loaded RISC code...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 585 | if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) { |
| 586 | rval = ha->isp_ops->chip_diag(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 587 | if (rval) |
| 588 | return (rval); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 589 | rval = qla2x00_setup_chip(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 590 | if (rval) |
| 591 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 593 | |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 594 | if (IS_QLA84XX(ha)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 595 | ha->cs84xx = qla84xx_get_chip(vha); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 596 | if (!ha->cs84xx) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 597 | ql_log(ql_log_warn, vha, 0x00d0, |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 598 | "Unable to configure ISP84XX.\n"); |
| 599 | return QLA_FUNCTION_FAILED; |
| 600 | } |
| 601 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 602 | |
| 603 | if (qla_ini_mode_enabled(vha)) |
| 604 | rval = qla2x00_init_rings(vha); |
| 605 | |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 606 | ha->flags.chip_reset_done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 608 | if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) { |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 609 | /* Issue verify 84xx FW IOCB to complete 84xx initialization */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 610 | rval = qla84xx_init_chip(vha); |
| 611 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 612 | ql_log(ql_log_warn, vha, 0x00d4, |
| 613 | "Unable to initialize ISP84XX.\n"); |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 614 | qla84xx_put_chip(vha); |
| 615 | } |
| 616 | } |
| 617 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 618 | /* Load the NIC Core f/w if we are the first protocol driver. */ |
| 619 | if (IS_QLA8031(ha)) { |
| 620 | rval = qla83xx_nic_core_fw_load(vha); |
| 621 | if (rval) |
| 622 | ql_log(ql_log_warn, vha, 0x0124, |
| 623 | "Error in initializing NIC Core f/w.\n"); |
| 624 | } |
| 625 | |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 626 | if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)) |
| 627 | qla24xx_read_fcp_prio_cfg(vha); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 628 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | return (rval); |
| 630 | } |
| 631 | |
| 632 | /** |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 633 | * qla2100_pci_config() - Setup ISP21xx PCI configuration registers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | * @ha: HA context |
| 635 | * |
| 636 | * Returns 0 on success. |
| 637 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 638 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 639 | qla2100_pci_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 641 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 642 | unsigned long flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 643 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 644 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 647 | pci_try_set_mwi(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 650 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 652 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 653 | pci_disable_rom(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 655 | /* Get PCI bus information. */ |
| 656 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 657 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 658 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 659 | |
| 660 | return QLA_SUCCESS; |
| 661 | } |
| 662 | |
| 663 | /** |
| 664 | * qla2300_pci_config() - Setup ISP23xx PCI configuration registers. |
| 665 | * @ha: HA context |
| 666 | * |
| 667 | * Returns 0 on success. |
| 668 | */ |
| 669 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 670 | qla2300_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 671 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 672 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 673 | unsigned long flags = 0; |
| 674 | uint32_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 675 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 676 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 677 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 678 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 679 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 680 | |
| 681 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 682 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 683 | |
| 684 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 685 | w &= ~PCI_COMMAND_INTX_DISABLE; |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 686 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 687 | |
| 688 | /* |
| 689 | * If this is a 2300 card and not 2312, reset the |
| 690 | * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately, |
| 691 | * the 2310 also reports itself as a 2300 so we need to get the |
| 692 | * fb revision level -- a 6 indicates it really is a 2300 and |
| 693 | * not a 2310. |
| 694 | */ |
| 695 | if (IS_QLA2300(ha)) { |
| 696 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 697 | |
| 698 | /* Pause RISC. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 699 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 700 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 701 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 702 | break; |
| 703 | |
| 704 | udelay(10); |
| 705 | } |
| 706 | |
| 707 | /* Select FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 708 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 709 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 710 | |
| 711 | /* Get the fb rev level */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 712 | ha->fb_rev = RD_FB_CMD_REG(ha, reg); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 713 | |
| 714 | if (ha->fb_rev == FPM_2300) |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 715 | pci_clear_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 716 | |
| 717 | /* Deselect FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 718 | WRT_REG_WORD(®->ctrl_status, 0x0); |
| 719 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 720 | |
| 721 | /* Release RISC module. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 722 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 723 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 724 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 725 | break; |
| 726 | |
| 727 | udelay(10); |
| 728 | } |
| 729 | |
| 730 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 731 | } |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 732 | |
| 733 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 734 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 735 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 736 | |
| 737 | /* Get PCI bus information. */ |
| 738 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 739 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 740 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 741 | |
| 742 | return QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 746 | * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers. |
| 747 | * @ha: HA context |
| 748 | * |
| 749 | * Returns 0 on success. |
| 750 | */ |
| 751 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 752 | qla24xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 753 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 754 | uint16_t w; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 755 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 756 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 757 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 758 | |
| 759 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 760 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 761 | |
| 762 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 763 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 764 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 765 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 766 | |
| 767 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 768 | |
| 769 | /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */ |
Andrew Vasquez | f85ec18 | 2007-07-19 15:06:01 -0700 | [diff] [blame] | 770 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX)) |
| 771 | pcix_set_mmrbc(ha->pdev, 2048); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 772 | |
| 773 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Jon Mason | e67f132 | 2012-07-10 14:57:56 -0700 | [diff] [blame] | 774 | if (pci_is_pcie(ha->pdev)) |
Chad Dupuis | 5ffd3a5 | 2012-08-22 14:21:26 -0400 | [diff] [blame] | 775 | pcie_set_readrq(ha->pdev, 4096); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 776 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 777 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 778 | |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 779 | ha->chip_revision = ha->pdev->revision; |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 780 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 781 | /* Get PCI bus information. */ |
| 782 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 783 | ha->pci_attr = RD_REG_DWORD(®->ctrl_status); |
| 784 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 785 | |
| 786 | return QLA_SUCCESS; |
| 787 | } |
| 788 | |
| 789 | /** |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 790 | * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers. |
| 791 | * @ha: HA context |
| 792 | * |
| 793 | * Returns 0 on success. |
| 794 | */ |
| 795 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 796 | qla25xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 797 | { |
| 798 | uint16_t w; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 799 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 800 | |
| 801 | pci_set_master(ha->pdev); |
| 802 | pci_try_set_mwi(ha->pdev); |
| 803 | |
| 804 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
| 805 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
| 806 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 807 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 808 | |
| 809 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Jon Mason | e67f132 | 2012-07-10 14:57:56 -0700 | [diff] [blame] | 810 | if (pci_is_pcie(ha->pdev)) |
Chad Dupuis | 5ffd3a5 | 2012-08-22 14:21:26 -0400 | [diff] [blame] | 811 | pcie_set_readrq(ha->pdev, 4096); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 812 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 813 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 814 | |
| 815 | ha->chip_revision = ha->pdev->revision; |
| 816 | |
| 817 | return QLA_SUCCESS; |
| 818 | } |
| 819 | |
| 820 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | * qla2x00_isp_firmware() - Choose firmware image. |
| 822 | * @ha: HA context |
| 823 | * |
| 824 | * Returns 0 on success. |
| 825 | */ |
| 826 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 827 | qla2x00_isp_firmware(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | { |
| 829 | int rval; |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 830 | uint16_t loop_id, topo, sw_cap; |
| 831 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 832 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | |
| 834 | /* Assume loading risc code */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 835 | rval = QLA_FUNCTION_FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | |
| 837 | if (ha->flags.disable_risc_code_load) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 838 | ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | |
| 840 | /* Verify checksum of loaded RISC code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 841 | rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address); |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 842 | if (rval == QLA_SUCCESS) { |
| 843 | /* And, verify we are not in ROM code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 844 | rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa, |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 845 | &area, &domain, &topo, &sw_cap); |
| 846 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | } |
| 848 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 849 | if (rval) |
| 850 | ql_dbg(ql_dbg_init, vha, 0x007a, |
| 851 | "**** Load RISC code ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | |
| 853 | return (rval); |
| 854 | } |
| 855 | |
| 856 | /** |
| 857 | * qla2x00_reset_chip() - Reset ISP chip. |
| 858 | * @ha: HA context |
| 859 | * |
| 860 | * Returns 0 on success. |
| 861 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 862 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 863 | qla2x00_reset_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | { |
| 865 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 866 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 867 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | uint32_t cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | uint16_t cmd; |
| 870 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 871 | if (unlikely(pci_channel_offline(ha->pdev))) |
| 872 | return; |
| 873 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 874 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | |
| 876 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 877 | |
| 878 | /* Turn off master enable */ |
| 879 | cmd = 0; |
| 880 | pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd); |
| 881 | cmd &= ~PCI_COMMAND_MASTER; |
| 882 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 883 | |
| 884 | if (!IS_QLA2100(ha)) { |
| 885 | /* Pause RISC. */ |
| 886 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
| 887 | if (IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 888 | for (cnt = 0; cnt < 30000; cnt++) { |
| 889 | if ((RD_REG_WORD(®->hccr) & |
| 890 | HCCR_RISC_PAUSE) != 0) |
| 891 | break; |
| 892 | udelay(100); |
| 893 | } |
| 894 | } else { |
| 895 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 896 | udelay(10); |
| 897 | } |
| 898 | |
| 899 | /* Select FPM registers. */ |
| 900 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 901 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 902 | |
| 903 | /* FPM Soft Reset. */ |
| 904 | WRT_REG_WORD(®->fpm_diag_config, 0x100); |
| 905 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 906 | |
| 907 | /* Toggle Fpm Reset. */ |
| 908 | if (!IS_QLA2200(ha)) { |
| 909 | WRT_REG_WORD(®->fpm_diag_config, 0x0); |
| 910 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 911 | } |
| 912 | |
| 913 | /* Select frame buffer registers. */ |
| 914 | WRT_REG_WORD(®->ctrl_status, 0x10); |
| 915 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 916 | |
| 917 | /* Reset frame buffer FIFOs. */ |
| 918 | if (IS_QLA2200(ha)) { |
| 919 | WRT_FB_CMD_REG(ha, reg, 0xa000); |
| 920 | RD_FB_CMD_REG(ha, reg); /* PCI Posting. */ |
| 921 | } else { |
| 922 | WRT_FB_CMD_REG(ha, reg, 0x00fc); |
| 923 | |
| 924 | /* Read back fb_cmd until zero or 3 seconds max */ |
| 925 | for (cnt = 0; cnt < 3000; cnt++) { |
| 926 | if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0) |
| 927 | break; |
| 928 | udelay(100); |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | /* Select RISC module registers. */ |
| 933 | WRT_REG_WORD(®->ctrl_status, 0); |
| 934 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 935 | |
| 936 | /* Reset RISC processor. */ |
| 937 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 938 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 939 | |
| 940 | /* Release RISC processor. */ |
| 941 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 942 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 943 | } |
| 944 | |
| 945 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); |
| 946 | WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT); |
| 947 | |
| 948 | /* Reset ISP chip. */ |
| 949 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 950 | |
| 951 | /* Wait for RISC to recover from reset. */ |
| 952 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 953 | /* |
| 954 | * It is necessary to for a delay here since the card doesn't |
| 955 | * respond to PCI reads during a reset. On some architectures |
| 956 | * this will result in an MCA. |
| 957 | */ |
| 958 | udelay(20); |
| 959 | for (cnt = 30000; cnt; cnt--) { |
| 960 | if ((RD_REG_WORD(®->ctrl_status) & |
| 961 | CSR_ISP_SOFT_RESET) == 0) |
| 962 | break; |
| 963 | udelay(100); |
| 964 | } |
| 965 | } else |
| 966 | udelay(10); |
| 967 | |
| 968 | /* Reset RISC processor. */ |
| 969 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 970 | |
| 971 | WRT_REG_WORD(®->semaphore, 0); |
| 972 | |
| 973 | /* Release RISC processor. */ |
| 974 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 975 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 976 | |
| 977 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 978 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | ffb39f0 | 2006-05-17 15:09:06 -0700 | [diff] [blame] | 979 | if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | |
| 982 | udelay(100); |
| 983 | } |
| 984 | } else |
| 985 | udelay(100); |
| 986 | |
| 987 | /* Turn on master enable */ |
| 988 | cmd |= PCI_COMMAND_MASTER; |
| 989 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 990 | |
| 991 | /* Disable RISC pause on FPM parity error. */ |
| 992 | if (!IS_QLA2100(ha)) { |
| 993 | WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE); |
| 994 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 995 | } |
| 996 | |
| 997 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 998 | } |
| 999 | |
| 1000 | /** |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 1001 | * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC. |
| 1002 | * |
| 1003 | * Returns 0 on success. |
| 1004 | */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 1005 | static int |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 1006 | qla81xx_reset_mpi(scsi_qla_host_t *vha) |
| 1007 | { |
| 1008 | uint16_t mb[4] = {0x1010, 0, 1, 0}; |
| 1009 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1010 | if (!IS_QLA81XX(vha->hw)) |
| 1011 | return QLA_SUCCESS; |
| 1012 | |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 1013 | return qla81xx_write_mpi_register(vha, mb); |
| 1014 | } |
| 1015 | |
| 1016 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1017 | * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC. |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1018 | * @ha: HA context |
| 1019 | * |
| 1020 | * Returns 0 on success. |
| 1021 | */ |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1022 | static inline void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1023 | qla24xx_reset_risc(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1024 | { |
| 1025 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1026 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1027 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 1028 | uint32_t cnt, d2; |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 1029 | uint16_t wd; |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 1030 | static int abts_cnt; /* ISP abort retry counts */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1031 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1032 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1033 | |
| 1034 | /* Reset RISC. */ |
| 1035 | WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
| 1036 | for (cnt = 0; cnt < 30000; cnt++) { |
| 1037 | if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0) |
| 1038 | break; |
| 1039 | |
| 1040 | udelay(10); |
| 1041 | } |
| 1042 | |
| 1043 | WRT_REG_DWORD(®->ctrl_status, |
| 1044 | CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 1045 | pci_read_config_word(ha->pdev, PCI_COMMAND, &wd); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1046 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 1047 | udelay(100); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1048 | /* Wait for firmware to complete NVRAM accesses. */ |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1049 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 1050 | for (cnt = 10000 ; cnt && d2; cnt--) { |
| 1051 | udelay(5); |
| 1052 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 1053 | barrier(); |
| 1054 | } |
| 1055 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 1056 | /* Wait for soft-reset to complete. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1057 | d2 = RD_REG_DWORD(®->ctrl_status); |
| 1058 | for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) { |
| 1059 | udelay(5); |
| 1060 | d2 = RD_REG_DWORD(®->ctrl_status); |
| 1061 | barrier(); |
| 1062 | } |
| 1063 | |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 1064 | /* If required, do an MPI FW reset now */ |
| 1065 | if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) { |
| 1066 | if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) { |
| 1067 | if (++abts_cnt < 5) { |
| 1068 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 1069 | set_bit(MPI_RESET_NEEDED, &vha->dpc_flags); |
| 1070 | } else { |
| 1071 | /* |
| 1072 | * We exhausted the ISP abort retries. We have to |
| 1073 | * set the board offline. |
| 1074 | */ |
| 1075 | abts_cnt = 0; |
| 1076 | vha->flags.online = 0; |
| 1077 | } |
| 1078 | } |
| 1079 | } |
| 1080 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1081 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 1082 | RD_REG_DWORD(®->hccr); |
| 1083 | |
| 1084 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 1085 | RD_REG_DWORD(®->hccr); |
| 1086 | |
| 1087 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET); |
| 1088 | RD_REG_DWORD(®->hccr); |
| 1089 | |
| 1090 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 1091 | for (cnt = 6000000 ; cnt && d2; cnt--) { |
| 1092 | udelay(5); |
| 1093 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 1094 | barrier(); |
| 1095 | } |
| 1096 | |
| 1097 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 124f85e | 2009-01-05 11:18:06 -0800 | [diff] [blame] | 1098 | |
| 1099 | if (IS_NOPOLLING_TYPE(ha)) |
| 1100 | ha->isp_ops->enable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1101 | } |
| 1102 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 1103 | static void |
| 1104 | qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data) |
| 1105 | { |
| 1106 | struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24; |
| 1107 | |
| 1108 | WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET); |
| 1109 | *data = RD_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET); |
| 1110 | |
| 1111 | } |
| 1112 | |
| 1113 | static void |
| 1114 | qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data) |
| 1115 | { |
| 1116 | struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24; |
| 1117 | |
| 1118 | WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET); |
| 1119 | WRT_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET, data); |
| 1120 | } |
| 1121 | |
| 1122 | static void |
| 1123 | qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha) |
| 1124 | { |
| 1125 | struct qla_hw_data *ha = vha->hw; |
| 1126 | uint32_t wd32 = 0; |
| 1127 | uint delta_msec = 100; |
| 1128 | uint elapsed_msec = 0; |
| 1129 | uint timeout_msec; |
| 1130 | ulong n; |
| 1131 | |
| 1132 | if (!IS_QLA25XX(ha) && !IS_QLA2031(ha)) |
| 1133 | return; |
| 1134 | |
| 1135 | attempt: |
| 1136 | timeout_msec = TIMEOUT_SEMAPHORE; |
| 1137 | n = timeout_msec / delta_msec; |
| 1138 | while (n--) { |
| 1139 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET); |
| 1140 | qla25xx_read_risc_sema_reg(vha, &wd32); |
| 1141 | if (wd32 & RISC_SEMAPHORE) |
| 1142 | break; |
| 1143 | msleep(delta_msec); |
| 1144 | elapsed_msec += delta_msec; |
| 1145 | if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED) |
| 1146 | goto force; |
| 1147 | } |
| 1148 | |
| 1149 | if (!(wd32 & RISC_SEMAPHORE)) |
| 1150 | goto force; |
| 1151 | |
| 1152 | if (!(wd32 & RISC_SEMAPHORE_FORCE)) |
| 1153 | goto acquired; |
| 1154 | |
| 1155 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR); |
| 1156 | timeout_msec = TIMEOUT_SEMAPHORE_FORCE; |
| 1157 | n = timeout_msec / delta_msec; |
| 1158 | while (n--) { |
| 1159 | qla25xx_read_risc_sema_reg(vha, &wd32); |
| 1160 | if (!(wd32 & RISC_SEMAPHORE_FORCE)) |
| 1161 | break; |
| 1162 | msleep(delta_msec); |
| 1163 | elapsed_msec += delta_msec; |
| 1164 | if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED) |
| 1165 | goto force; |
| 1166 | } |
| 1167 | |
| 1168 | if (wd32 & RISC_SEMAPHORE_FORCE) |
| 1169 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR); |
| 1170 | |
| 1171 | goto attempt; |
| 1172 | |
| 1173 | force: |
| 1174 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET); |
| 1175 | |
| 1176 | acquired: |
| 1177 | return; |
| 1178 | } |
| 1179 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1180 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1181 | * qla24xx_reset_chip() - Reset ISP24xx chip. |
| 1182 | * @ha: HA context |
| 1183 | * |
| 1184 | * Returns 0 on success. |
| 1185 | */ |
| 1186 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1187 | qla24xx_reset_chip(scsi_qla_host_t *vha) |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1188 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1189 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 1190 | |
| 1191 | if (pci_channel_offline(ha->pdev) && |
| 1192 | ha->flags.pci_channel_io_perm_failure) { |
| 1193 | return; |
| 1194 | } |
| 1195 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1196 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1197 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 1198 | qla25xx_manipulate_risc_semaphore(vha); |
| 1199 | |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1200 | /* Perform RISC reset. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1201 | qla24xx_reset_risc(vha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | * qla2x00_chip_diag() - Test chip for proper operation. |
| 1206 | * @ha: HA context |
| 1207 | * |
| 1208 | * Returns 0 on success. |
| 1209 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1210 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1211 | qla2x00_chip_diag(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | { |
| 1213 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1214 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1215 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | unsigned long flags = 0; |
| 1217 | uint16_t data; |
| 1218 | uint32_t cnt; |
| 1219 | uint16_t mb[5]; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1220 | struct req_que *req = ha->req_q_map[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | |
| 1222 | /* Assume a failed state */ |
| 1223 | rval = QLA_FUNCTION_FAILED; |
| 1224 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1225 | ql_dbg(ql_dbg_init, vha, 0x007b, |
| 1226 | "Testing device at %lx.\n", (u_long)®->flash_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | |
| 1228 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1229 | |
| 1230 | /* Reset ISP chip. */ |
| 1231 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 1232 | |
| 1233 | /* |
| 1234 | * We need to have a delay here since the card will not respond while |
| 1235 | * in reset causing an MCA on some architectures. |
| 1236 | */ |
| 1237 | udelay(20); |
| 1238 | data = qla2x00_debounce_register(®->ctrl_status); |
| 1239 | for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) { |
| 1240 | udelay(5); |
| 1241 | data = RD_REG_WORD(®->ctrl_status); |
| 1242 | barrier(); |
| 1243 | } |
| 1244 | |
| 1245 | if (!cnt) |
| 1246 | goto chip_diag_failed; |
| 1247 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1248 | ql_dbg(ql_dbg_init, vha, 0x007c, |
| 1249 | "Reset register cleared by chip reset.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | |
| 1251 | /* Reset RISC processor. */ |
| 1252 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 1253 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 1254 | |
| 1255 | /* Workaround for QLA2312 PCI parity error */ |
| 1256 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 1257 | data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0)); |
| 1258 | for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) { |
| 1259 | udelay(5); |
| 1260 | data = RD_MAILBOX_REG(ha, reg, 0); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1261 | barrier(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | } |
| 1263 | } else |
| 1264 | udelay(10); |
| 1265 | |
| 1266 | if (!cnt) |
| 1267 | goto chip_diag_failed; |
| 1268 | |
| 1269 | /* Check product ID of chip */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1270 | 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] | 1271 | |
| 1272 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); |
| 1273 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); |
| 1274 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); |
| 1275 | mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4)); |
| 1276 | if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) || |
| 1277 | mb[3] != PROD_ID_3) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1278 | ql_log(ql_log_warn, vha, 0x0062, |
| 1279 | "Wrong product ID = 0x%x,0x%x,0x%x.\n", |
| 1280 | mb[1], mb[2], mb[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | |
| 1282 | goto chip_diag_failed; |
| 1283 | } |
| 1284 | ha->product_id[0] = mb[1]; |
| 1285 | ha->product_id[1] = mb[2]; |
| 1286 | ha->product_id[2] = mb[3]; |
| 1287 | ha->product_id[3] = mb[4]; |
| 1288 | |
| 1289 | /* Adjust fw RISC transfer size */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1290 | if (req->length > 1024) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024; |
| 1292 | else |
| 1293 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1294 | req->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | |
| 1296 | if (IS_QLA2200(ha) && |
| 1297 | RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) { |
| 1298 | /* Limit firmware transfer size with a 2200A */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1299 | ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1301 | ha->device_type |= DT_ISP2200A; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | ha->fw_transfer_size = 128; |
| 1303 | } |
| 1304 | |
| 1305 | /* Wrap Incoming Mailboxes Test. */ |
| 1306 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1307 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1308 | ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1309 | rval = qla2x00_mbx_reg_test(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1310 | if (rval) |
| 1311 | ql_log(ql_log_warn, vha, 0x0080, |
| 1312 | "Failed mailbox send register test.\n"); |
| 1313 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | /* Flag a successful rval */ |
| 1315 | rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1317 | |
| 1318 | chip_diag_failed: |
| 1319 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1320 | ql_log(ql_log_info, vha, 0x0081, |
| 1321 | "Chip diagnostics **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | |
| 1323 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1324 | |
| 1325 | return (rval); |
| 1326 | } |
| 1327 | |
| 1328 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1329 | * qla24xx_chip_diag() - Test ISP24xx for proper operation. |
| 1330 | * @ha: HA context |
| 1331 | * |
| 1332 | * Returns 0 on success. |
| 1333 | */ |
| 1334 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1335 | qla24xx_chip_diag(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1336 | { |
| 1337 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1338 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1339 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1340 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame^] | 1341 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1342 | return QLA_SUCCESS; |
| 1343 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1344 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1345 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1346 | rval = qla2x00_mbx_reg_test(vha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1347 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1348 | ql_log(ql_log_warn, vha, 0x0082, |
| 1349 | "Failed mailbox send register test.\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1350 | } else { |
| 1351 | /* Flag a successful rval */ |
| 1352 | rval = QLA_SUCCESS; |
| 1353 | } |
| 1354 | |
| 1355 | return rval; |
| 1356 | } |
| 1357 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1358 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1359 | qla2x00_alloc_fw_dump(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1360 | { |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1361 | int rval; |
| 1362 | uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size, |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1363 | eft_size, fce_size, mq_size; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1364 | dma_addr_t tc_dma; |
| 1365 | void *tc; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1366 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1367 | struct req_que *req = ha->req_q_map[0]; |
| 1368 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 1369 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1370 | if (ha->fw_dump) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1371 | ql_dbg(ql_dbg_init, vha, 0x00bd, |
| 1372 | "Firmware dump already allocated.\n"); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1373 | return; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 1374 | } |
| 1375 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1376 | ha->fw_dumped = 0; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1377 | fixed_size = mem_size = eft_size = fce_size = mq_size = 0; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1378 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 1379 | fixed_size = sizeof(struct qla2100_fw_dump); |
| 1380 | } else if (IS_QLA23XX(ha)) { |
| 1381 | fixed_size = offsetof(struct qla2300_fw_dump, data_ram); |
| 1382 | mem_size = (ha->fw_memory_size - 0x11000 + 1) * |
| 1383 | sizeof(uint16_t); |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 1384 | } else if (IS_FWI2_CAPABLE(ha)) { |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1385 | if (IS_QLA83XX(ha)) |
| 1386 | fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem); |
| 1387 | else if (IS_QLA81XX(ha)) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1388 | fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem); |
| 1389 | else if (IS_QLA25XX(ha)) |
| 1390 | fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem); |
| 1391 | else |
| 1392 | fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1393 | mem_size = (ha->fw_memory_size - 0x100000 + 1) * |
| 1394 | sizeof(uint32_t); |
Giridhar Malavali | 050c9bb | 2012-02-09 11:15:33 -0800 | [diff] [blame] | 1395 | if (ha->mqenable) { |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1396 | if (!IS_QLA83XX(ha)) |
| 1397 | mq_size = sizeof(struct qla2xxx_mq_chain); |
Giridhar Malavali | 050c9bb | 2012-02-09 11:15:33 -0800 | [diff] [blame] | 1398 | /* |
| 1399 | * Allocate maximum buffer size for all queues. |
| 1400 | * Resizing must be done at end-of-dump processing. |
| 1401 | */ |
| 1402 | mq_size += ha->max_req_queues * |
| 1403 | (req->length * sizeof(request_t)); |
| 1404 | mq_size += ha->max_rsp_queues * |
| 1405 | (rsp->length * sizeof(response_t)); |
| 1406 | } |
Arun Easi | 00876ae | 2013-03-25 02:21:37 -0400 | [diff] [blame] | 1407 | if (ha->tgt.atio_ring) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1408 | mq_size += ha->tgt.atio_q_length * sizeof(request_t); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1409 | /* Allocate memory for Fibre Channel Event Buffer. */ |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1410 | if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha)) |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1411 | goto try_eft; |
| 1412 | |
| 1413 | tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma, |
| 1414 | GFP_KERNEL); |
| 1415 | if (!tc) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1416 | ql_log(ql_log_warn, vha, 0x00be, |
| 1417 | "Unable to allocate (%d KB) for FCE.\n", |
| 1418 | FCE_SIZE / 1024); |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 1419 | goto try_eft; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | memset(tc, 0, FCE_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1423 | rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1424 | ha->fce_mb, &ha->fce_bufs); |
| 1425 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1426 | ql_log(ql_log_warn, vha, 0x00bf, |
| 1427 | "Unable to initialize FCE (%d).\n", rval); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1428 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, |
| 1429 | tc_dma); |
| 1430 | ha->flags.fce_enabled = 0; |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 1431 | goto try_eft; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1432 | } |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1433 | ql_dbg(ql_dbg_init, vha, 0x00c0, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1434 | "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1435 | |
Giridhar Malavali | 7d9dade | 2009-03-24 09:07:58 -0700 | [diff] [blame] | 1436 | fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1437 | ha->flags.fce_enabled = 1; |
| 1438 | ha->fce_dma = tc_dma; |
| 1439 | ha->fce = tc; |
| 1440 | try_eft: |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1441 | /* Allocate memory for Extended Trace Buffer. */ |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1442 | tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma, |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1443 | GFP_KERNEL); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1444 | if (!tc) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1445 | ql_log(ql_log_warn, vha, 0x00c1, |
| 1446 | "Unable to allocate (%d KB) for EFT.\n", |
| 1447 | EFT_SIZE / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1448 | goto cont_alloc; |
| 1449 | } |
| 1450 | |
Andrew Vasquez | fc44765 | 2008-01-17 09:02:18 -0800 | [diff] [blame] | 1451 | memset(tc, 0, EFT_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1452 | rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1453 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1454 | ql_log(ql_log_warn, vha, 0x00c2, |
| 1455 | "Unable to initialize EFT (%d).\n", rval); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1456 | dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, |
| 1457 | tc_dma); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1458 | goto cont_alloc; |
| 1459 | } |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1460 | ql_dbg(ql_dbg_init, vha, 0x00c3, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1461 | "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1462 | |
| 1463 | eft_size = EFT_SIZE; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1464 | ha->eft_dma = tc_dma; |
| 1465 | ha->eft = tc; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1466 | } |
| 1467 | cont_alloc: |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1468 | req_q_size = req->length * sizeof(request_t); |
| 1469 | rsp_q_size = rsp->length * sizeof(response_t); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1470 | |
| 1471 | dump_size = offsetof(struct qla2xxx_fw_dump, isp); |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1472 | 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] | 1473 | ha->chain_offset = dump_size; |
| 1474 | dump_size += mq_size + fce_size; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1475 | |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 1476 | ha->fw_dump = vmalloc(dump_size); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1477 | if (!ha->fw_dump) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1478 | ql_log(ql_log_warn, vha, 0x00c4, |
| 1479 | "Unable to allocate (%d KB) for firmware dump.\n", |
| 1480 | dump_size / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1481 | |
Madhuranath Iyengar | e30d175 | 2010-10-15 11:27:46 -0700 | [diff] [blame] | 1482 | if (ha->fce) { |
| 1483 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce, |
| 1484 | ha->fce_dma); |
| 1485 | ha->fce = NULL; |
| 1486 | ha->fce_dma = 0; |
| 1487 | } |
| 1488 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1489 | if (ha->eft) { |
| 1490 | dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft, |
| 1491 | ha->eft_dma); |
| 1492 | ha->eft = NULL; |
| 1493 | ha->eft_dma = 0; |
| 1494 | } |
| 1495 | return; |
| 1496 | } |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1497 | ql_dbg(ql_dbg_init, vha, 0x00c5, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1498 | "Allocated (%d KB) for firmware dump.\n", dump_size / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1499 | |
| 1500 | ha->fw_dump_len = dump_size; |
| 1501 | ha->fw_dump->signature[0] = 'Q'; |
| 1502 | ha->fw_dump->signature[1] = 'L'; |
| 1503 | ha->fw_dump->signature[2] = 'G'; |
| 1504 | ha->fw_dump->signature[3] = 'C'; |
| 1505 | ha->fw_dump->version = __constant_htonl(1); |
| 1506 | |
| 1507 | ha->fw_dump->fixed_size = htonl(fixed_size); |
| 1508 | ha->fw_dump->mem_size = htonl(mem_size); |
| 1509 | ha->fw_dump->req_q_size = htonl(req_q_size); |
| 1510 | ha->fw_dump->rsp_q_size = htonl(rsp_q_size); |
| 1511 | |
| 1512 | ha->fw_dump->eft_size = htonl(eft_size); |
| 1513 | ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma)); |
| 1514 | ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma)); |
| 1515 | |
| 1516 | ha->fw_dump->header_size = |
| 1517 | htonl(offsetof(struct qla2xxx_fw_dump, isp)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1518 | } |
| 1519 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1520 | static int |
| 1521 | qla81xx_mpi_sync(scsi_qla_host_t *vha) |
| 1522 | { |
| 1523 | #define MPS_MASK 0xe0 |
| 1524 | int rval; |
| 1525 | uint16_t dc; |
| 1526 | uint32_t dw; |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1527 | |
| 1528 | if (!IS_QLA81XX(vha->hw)) |
| 1529 | return QLA_SUCCESS; |
| 1530 | |
| 1531 | rval = qla2x00_write_ram_word(vha, 0x7c00, 1); |
| 1532 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1533 | ql_log(ql_log_warn, vha, 0x0105, |
| 1534 | "Unable to acquire semaphore.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1535 | goto done; |
| 1536 | } |
| 1537 | |
| 1538 | pci_read_config_word(vha->hw->pdev, 0x54, &dc); |
| 1539 | rval = qla2x00_read_ram_word(vha, 0x7a15, &dw); |
| 1540 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1541 | ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1542 | goto done_release; |
| 1543 | } |
| 1544 | |
| 1545 | dc &= MPS_MASK; |
| 1546 | if (dc == (dw & MPS_MASK)) |
| 1547 | goto done_release; |
| 1548 | |
| 1549 | dw &= ~MPS_MASK; |
| 1550 | dw |= dc; |
| 1551 | rval = qla2x00_write_ram_word(vha, 0x7a15, dw); |
| 1552 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1553 | ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | done_release: |
| 1557 | rval = qla2x00_write_ram_word(vha, 0x7c00, 0); |
| 1558 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1559 | ql_log(ql_log_warn, vha, 0x006d, |
| 1560 | "Unable to release semaphore.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1561 | } |
| 1562 | |
| 1563 | done: |
| 1564 | return rval; |
| 1565 | } |
| 1566 | |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 1567 | int |
| 1568 | qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req) |
| 1569 | { |
| 1570 | /* Don't try to reallocate the array */ |
| 1571 | if (req->outstanding_cmds) |
| 1572 | return QLA_SUCCESS; |
| 1573 | |
| 1574 | if (!IS_FWI2_CAPABLE(ha) || (ha->mqiobase && |
| 1575 | (ql2xmultique_tag || ql2xmaxqueues > 1))) |
| 1576 | req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS; |
| 1577 | else { |
| 1578 | if (ha->fw_xcb_count <= ha->fw_iocb_count) |
| 1579 | req->num_outstanding_cmds = ha->fw_xcb_count; |
| 1580 | else |
| 1581 | req->num_outstanding_cmds = ha->fw_iocb_count; |
| 1582 | } |
| 1583 | |
| 1584 | req->outstanding_cmds = kzalloc(sizeof(srb_t *) * |
| 1585 | req->num_outstanding_cmds, GFP_KERNEL); |
| 1586 | |
| 1587 | if (!req->outstanding_cmds) { |
| 1588 | /* |
| 1589 | * Try to allocate a minimal size just so we can get through |
| 1590 | * initialization. |
| 1591 | */ |
| 1592 | req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS; |
| 1593 | req->outstanding_cmds = kzalloc(sizeof(srb_t *) * |
| 1594 | req->num_outstanding_cmds, GFP_KERNEL); |
| 1595 | |
| 1596 | if (!req->outstanding_cmds) { |
| 1597 | ql_log(ql_log_fatal, NULL, 0x0126, |
| 1598 | "Failed to allocate memory for " |
| 1599 | "outstanding_cmds for req_que %p.\n", req); |
| 1600 | req->num_outstanding_cmds = 0; |
| 1601 | return QLA_FUNCTION_FAILED; |
| 1602 | } |
| 1603 | } |
| 1604 | |
| 1605 | return QLA_SUCCESS; |
| 1606 | } |
| 1607 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1608 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | * qla2x00_setup_chip() - Load and start RISC firmware. |
| 1610 | * @ha: HA context |
| 1611 | * |
| 1612 | * Returns 0 on success. |
| 1613 | */ |
| 1614 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1615 | qla2x00_setup_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1617 | int rval; |
| 1618 | uint32_t srisc_address = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1619 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1620 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 1621 | unsigned long flags; |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 1622 | uint16_t fw_major_version; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1623 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame^] | 1624 | if (IS_P3P_TYPE(ha)) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1625 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 1626 | if (rval == QLA_SUCCESS) { |
| 1627 | qla2x00_stop_firmware(vha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1628 | goto enable_82xx_npiv; |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 1629 | } else |
Giridhar Malavali | b963752 | 2010-05-28 15:08:15 -0700 | [diff] [blame] | 1630 | goto failed; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1631 | } |
| 1632 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1633 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 1634 | /* Disable SRAM, Instruction RAM and GP RAM parity. */ |
| 1635 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1636 | WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0)); |
| 1637 | RD_REG_WORD(®->hccr); |
| 1638 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1639 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1641 | qla81xx_mpi_sync(vha); |
| 1642 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1643 | /* Load firmware sequences */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1644 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1645 | if (rval == QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1646 | ql_dbg(ql_dbg_init, vha, 0x00c9, |
| 1647 | "Verifying Checksum of loaded RISC code.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1649 | rval = qla2x00_verify_checksum(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | if (rval == QLA_SUCCESS) { |
| 1651 | /* Start firmware execution. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1652 | ql_dbg(ql_dbg_init, vha, 0x00ca, |
| 1653 | "Starting firmware.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1655 | rval = qla2x00_execute_fw(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | /* Retrieve firmware information. */ |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 1657 | if (rval == QLA_SUCCESS) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1658 | enable_82xx_npiv: |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 1659 | fw_major_version = ha->fw_major_version; |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame^] | 1660 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | 3173167 | 2011-08-16 11:31:54 -0700 | [diff] [blame] | 1661 | qla82xx_check_md_needed(vha); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1662 | else |
| 1663 | rval = qla2x00_get_fw_version(vha); |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 1664 | if (rval != QLA_SUCCESS) |
| 1665 | goto failed; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1666 | ha->flags.npiv_supported = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1667 | if (IS_QLA2XXX_MIDTYPE(ha) && |
Mike Hernandez | 946fb89 | 2008-08-13 21:36:59 -0700 | [diff] [blame] | 1668 | (ha->fw_attributes & BIT_2)) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1669 | ha->flags.npiv_supported = 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 1670 | if ((!ha->max_npiv_vports) || |
| 1671 | ((ha->max_npiv_vports + 1) % |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 1672 | MIN_MULTI_ID_FABRIC)) |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 1673 | ha->max_npiv_vports = |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 1674 | MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 1675 | } |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 1676 | qla2x00_get_resource_cnts(vha, NULL, |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 1677 | &ha->fw_xcb_count, NULL, &ha->fw_iocb_count, |
Andrew Vasquez | f3a0a77 | 2009-10-13 15:16:49 -0700 | [diff] [blame] | 1678 | &ha->max_npiv_vports, NULL); |
Andrew Vasquez | d743de6 | 2009-03-24 09:08:15 -0700 | [diff] [blame] | 1679 | |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 1680 | /* |
| 1681 | * Allocate the array of outstanding commands |
| 1682 | * now that we know the firmware resources. |
| 1683 | */ |
| 1684 | rval = qla2x00_alloc_outstanding_cmds(ha, |
| 1685 | vha->req); |
| 1686 | if (rval != QLA_SUCCESS) |
| 1687 | goto failed; |
| 1688 | |
Saurav Kashyap | be5ea3c | 2011-11-18 09:02:11 -0800 | [diff] [blame] | 1689 | if (!fw_major_version && ql2xallocfwdump |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame^] | 1690 | && !(IS_P3P_TYPE(ha))) |
Giridhar Malavali | 08de284 | 2011-08-16 11:31:44 -0700 | [diff] [blame] | 1691 | qla2x00_alloc_fw_dump(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | } |
| 1693 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1694 | ql_log(ql_log_fatal, vha, 0x00cd, |
| 1695 | "ISP Firmware failed checksum.\n"); |
| 1696 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | } |
Andrew Vasquez | c74d88a | 2012-08-22 14:21:19 -0400 | [diff] [blame] | 1698 | } else |
| 1699 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1701 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 1702 | /* Enable proper parity. */ |
| 1703 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1704 | if (IS_QLA2300(ha)) |
| 1705 | /* SRAM parity */ |
| 1706 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1); |
| 1707 | else |
| 1708 | /* SRAM, Instruction RAM and GP RAM parity */ |
| 1709 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7); |
| 1710 | RD_REG_WORD(®->hccr); |
| 1711 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1712 | } |
| 1713 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1714 | if (IS_QLA83XX(ha)) |
| 1715 | goto skip_fac_check; |
| 1716 | |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1717 | if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) { |
| 1718 | uint32_t size; |
| 1719 | |
| 1720 | rval = qla81xx_fac_get_sector_size(vha, &size); |
| 1721 | if (rval == QLA_SUCCESS) { |
| 1722 | ha->flags.fac_supported = 1; |
| 1723 | ha->fdt_block_size = size << 2; |
| 1724 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1725 | ql_log(ql_log_warn, vha, 0x00ce, |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1726 | "Unsupported FAC firmware (%d.%02d.%02d).\n", |
| 1727 | ha->fw_major_version, ha->fw_minor_version, |
| 1728 | ha->fw_subminor_version); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1729 | skip_fac_check: |
| 1730 | if (IS_QLA83XX(ha)) { |
| 1731 | ha->flags.fac_supported = 0; |
| 1732 | rval = QLA_SUCCESS; |
| 1733 | } |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1734 | } |
| 1735 | } |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 1736 | failed: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1737 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1738 | ql_log(ql_log_fatal, vha, 0x00cf, |
| 1739 | "Setup chip ****FAILED****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1740 | } |
| 1741 | |
| 1742 | return (rval); |
| 1743 | } |
| 1744 | |
| 1745 | /** |
| 1746 | * qla2x00_init_response_q_entries() - Initializes response queue entries. |
| 1747 | * @ha: HA context |
| 1748 | * |
| 1749 | * Beginning of request ring has initialization control block already built |
| 1750 | * by nvram config routine. |
| 1751 | * |
| 1752 | * Returns 0 on success. |
| 1753 | */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1754 | void |
| 1755 | qla2x00_init_response_q_entries(struct rsp_que *rsp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | { |
| 1757 | uint16_t cnt; |
| 1758 | response_t *pkt; |
| 1759 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1760 | rsp->ring_ptr = rsp->ring; |
| 1761 | rsp->ring_index = 0; |
| 1762 | rsp->status_srb = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1763 | pkt = rsp->ring_ptr; |
| 1764 | for (cnt = 0; cnt < rsp->length; cnt++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1765 | pkt->signature = RESPONSE_PROCESSED; |
| 1766 | pkt++; |
| 1767 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1768 | } |
| 1769 | |
| 1770 | /** |
| 1771 | * qla2x00_update_fw_options() - Read and process firmware options. |
| 1772 | * @ha: HA context |
| 1773 | * |
| 1774 | * Returns 0 on success. |
| 1775 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1776 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1777 | qla2x00_update_fw_options(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | { |
| 1779 | uint16_t swing, emphasis, tx_sens, rx_sens; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1780 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | |
| 1782 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1783 | qla2x00_get_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | |
| 1785 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
| 1786 | return; |
| 1787 | |
| 1788 | /* Serial Link options. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1789 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115, |
| 1790 | "Serial link options.\n"); |
| 1791 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109, |
| 1792 | (uint8_t *)&ha->fw_seriallink_options, |
| 1793 | sizeof(ha->fw_seriallink_options)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1794 | |
| 1795 | ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING; |
| 1796 | if (ha->fw_seriallink_options[3] & BIT_2) { |
| 1797 | ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING; |
| 1798 | |
| 1799 | /* 1G settings */ |
| 1800 | swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0); |
| 1801 | emphasis = (ha->fw_seriallink_options[2] & |
| 1802 | (BIT_4 | BIT_3)) >> 3; |
| 1803 | tx_sens = ha->fw_seriallink_options[0] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1804 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | rx_sens = (ha->fw_seriallink_options[0] & |
| 1806 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 1807 | ha->fw_options[10] = (emphasis << 14) | (swing << 8); |
| 1808 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 1809 | if (rx_sens == 0x0) |
| 1810 | rx_sens = 0x3; |
| 1811 | ha->fw_options[10] |= (tx_sens << 4) | rx_sens; |
| 1812 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 1813 | ha->fw_options[10] |= BIT_5 | |
| 1814 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 1815 | (tx_sens & (BIT_1 | BIT_0)); |
| 1816 | |
| 1817 | /* 2G settings */ |
| 1818 | swing = (ha->fw_seriallink_options[2] & |
| 1819 | (BIT_7 | BIT_6 | BIT_5)) >> 5; |
| 1820 | emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0); |
| 1821 | tx_sens = ha->fw_seriallink_options[1] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1822 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | rx_sens = (ha->fw_seriallink_options[1] & |
| 1824 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 1825 | ha->fw_options[11] = (emphasis << 14) | (swing << 8); |
| 1826 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 1827 | if (rx_sens == 0x0) |
| 1828 | rx_sens = 0x3; |
| 1829 | ha->fw_options[11] |= (tx_sens << 4) | rx_sens; |
| 1830 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 1831 | ha->fw_options[11] |= BIT_5 | |
| 1832 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 1833 | (tx_sens & (BIT_1 | BIT_0)); |
| 1834 | } |
| 1835 | |
| 1836 | /* FCP2 options. */ |
| 1837 | /* Return command IOCBs without waiting for an ABTS to complete. */ |
| 1838 | ha->fw_options[3] |= BIT_13; |
| 1839 | |
| 1840 | /* LED scheme. */ |
| 1841 | if (ha->flags.enable_led_scheme) |
| 1842 | ha->fw_options[2] |= BIT_12; |
| 1843 | |
andrew.vasquez@qlogic.com | 48c02fd | 2006-03-09 14:27:18 -0800 | [diff] [blame] | 1844 | /* Detect ISP6312. */ |
| 1845 | if (IS_QLA6312(ha)) |
| 1846 | ha->fw_options[2] |= BIT_13; |
| 1847 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | /* Update firmware options. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1849 | qla2x00_set_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | } |
| 1851 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1852 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1853 | qla24xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1854 | { |
| 1855 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1856 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1857 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame^] | 1858 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1859 | return; |
| 1860 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1861 | /* Update Serial Link options. */ |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 1862 | if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1863 | return; |
| 1864 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1865 | rval = qla2x00_set_serdes_params(vha, |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 1866 | le16_to_cpu(ha->fw_seriallink_options24[1]), |
| 1867 | le16_to_cpu(ha->fw_seriallink_options24[2]), |
| 1868 | le16_to_cpu(ha->fw_seriallink_options24[3])); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1869 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1870 | ql_log(ql_log_warn, vha, 0x0104, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1871 | "Unable to update Serial Link options (%x).\n", rval); |
| 1872 | } |
| 1873 | } |
| 1874 | |
| 1875 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1876 | qla2x00_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1877 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1878 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1879 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1880 | struct req_que *req = ha->req_q_map[0]; |
| 1881 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1882 | |
| 1883 | /* Setup ring parameters in initialization control block. */ |
| 1884 | ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0); |
| 1885 | ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1886 | ha->init_cb->request_q_length = cpu_to_le16(req->length); |
| 1887 | ha->init_cb->response_q_length = cpu_to_le16(rsp->length); |
| 1888 | ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 1889 | ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 1890 | ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 1891 | 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] | 1892 | |
| 1893 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0); |
| 1894 | WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0); |
| 1895 | WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0); |
| 1896 | WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0); |
| 1897 | RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */ |
| 1898 | } |
| 1899 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1900 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1901 | qla24xx_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1902 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1903 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1904 | device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0); |
| 1905 | struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp; |
| 1906 | struct qla_msix_entry *msix; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1907 | struct init_cb_24xx *icb; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1908 | uint16_t rid = 0; |
| 1909 | struct req_que *req = ha->req_q_map[0]; |
| 1910 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1911 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1912 | /* Setup ring parameters in initialization control block. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1913 | icb = (struct init_cb_24xx *)ha->init_cb; |
| 1914 | icb->request_q_outpointer = __constant_cpu_to_le16(0); |
| 1915 | icb->response_q_inpointer = __constant_cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1916 | icb->request_q_length = cpu_to_le16(req->length); |
| 1917 | icb->response_q_length = cpu_to_le16(rsp->length); |
| 1918 | icb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 1919 | icb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 1920 | icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 1921 | icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1922 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1923 | /* Setup ATIO queue dma pointers for target mode */ |
| 1924 | icb->atio_q_inpointer = __constant_cpu_to_le16(0); |
| 1925 | icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length); |
| 1926 | icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma)); |
| 1927 | icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma)); |
| 1928 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1929 | if (ha->mqenable || IS_QLA83XX(ha)) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1930 | icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS); |
| 1931 | icb->rid = __constant_cpu_to_le16(rid); |
| 1932 | if (ha->flags.msix_enabled) { |
| 1933 | msix = &ha->msix_entries[1]; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1934 | ql_dbg(ql_dbg_init, vha, 0x00fd, |
| 1935 | "Registering vector 0x%x for base que.\n", |
| 1936 | msix->entry); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1937 | icb->msix = cpu_to_le16(msix->entry); |
| 1938 | } |
| 1939 | /* Use alternate PCI bus number */ |
| 1940 | if (MSB(rid)) |
| 1941 | icb->firmware_options_2 |= |
| 1942 | __constant_cpu_to_le32(BIT_19); |
| 1943 | /* Use alternate PCI devfn */ |
| 1944 | if (LSB(rid)) |
| 1945 | icb->firmware_options_2 |= |
| 1946 | __constant_cpu_to_le32(BIT_18); |
| 1947 | |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 1948 | /* Use Disable MSIX Handshake mode for capable adapters */ |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1949 | if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) && |
| 1950 | (ha->flags.msix_enabled)) { |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 1951 | icb->firmware_options_2 &= |
| 1952 | __constant_cpu_to_le32(~BIT_22); |
| 1953 | ha->flags.disable_msix_handshake = 1; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1954 | ql_dbg(ql_dbg_init, vha, 0x00fe, |
| 1955 | "MSIX Handshake Disable Mode turned on.\n"); |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 1956 | } else { |
| 1957 | icb->firmware_options_2 |= |
| 1958 | __constant_cpu_to_le32(BIT_22); |
| 1959 | } |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1960 | icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1961 | |
| 1962 | WRT_REG_DWORD(®->isp25mq.req_q_in, 0); |
| 1963 | WRT_REG_DWORD(®->isp25mq.req_q_out, 0); |
| 1964 | WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0); |
| 1965 | WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0); |
| 1966 | } else { |
| 1967 | WRT_REG_DWORD(®->isp24.req_q_in, 0); |
| 1968 | WRT_REG_DWORD(®->isp24.req_q_out, 0); |
| 1969 | WRT_REG_DWORD(®->isp24.rsp_q_in, 0); |
| 1970 | WRT_REG_DWORD(®->isp24.rsp_q_out, 0); |
| 1971 | } |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 1972 | qlt_24xx_config_rings(vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1973 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1974 | /* PCI posting */ |
| 1975 | RD_REG_DWORD(&ioreg->hccr); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1976 | } |
| 1977 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1978 | /** |
| 1979 | * qla2x00_init_rings() - Initializes firmware. |
| 1980 | * @ha: HA context |
| 1981 | * |
| 1982 | * Beginning of request ring has initialization control block already built |
| 1983 | * by nvram config routine. |
| 1984 | * |
| 1985 | * Returns 0 on success. |
| 1986 | */ |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 1987 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1988 | qla2x00_init_rings(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1989 | { |
| 1990 | int rval; |
| 1991 | unsigned long flags = 0; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1992 | int cnt, que; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1993 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1994 | struct req_que *req; |
| 1995 | struct rsp_que *rsp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1996 | struct mid_init_cb_24xx *mid_init_cb = |
| 1997 | (struct mid_init_cb_24xx *) ha->init_cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | |
| 1999 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2000 | |
| 2001 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 2002 | for (que = 0; que < ha->max_req_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 2003 | req = ha->req_q_map[que]; |
| 2004 | if (!req) |
| 2005 | continue; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2006 | for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 2007 | req->outstanding_cmds[cnt] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2008 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 2009 | req->current_outstanding_cmd = 1; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 2010 | |
| 2011 | /* Initialize firmware. */ |
| 2012 | req->ring_ptr = req->ring; |
| 2013 | req->ring_index = 0; |
| 2014 | req->cnt = req->length; |
| 2015 | } |
| 2016 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 2017 | for (que = 0; que < ha->max_rsp_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 2018 | rsp = ha->rsp_q_map[que]; |
| 2019 | if (!rsp) |
| 2020 | continue; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 2021 | /* Initialize response queue entries */ |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 2022 | if (IS_QLAFX00(ha)) |
| 2023 | qlafx00_init_response_q_entries(rsp); |
| 2024 | else |
| 2025 | qla2x00_init_response_q_entries(rsp); |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 2026 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2028 | ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; |
| 2029 | ha->tgt.atio_ring_index = 0; |
| 2030 | /* Initialize ATIO queue entries */ |
| 2031 | qlt_init_atio_q_entries(vha); |
| 2032 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2033 | ha->isp_ops->config_rings(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | |
| 2035 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2036 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 2037 | ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n"); |
| 2038 | |
| 2039 | if (IS_QLAFX00(ha)) { |
| 2040 | rval = qlafx00_init_firmware(vha, ha->init_cb_size); |
| 2041 | goto next_check; |
| 2042 | } |
| 2043 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | /* Update any ISP specific firmware options before initialization. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2045 | ha->isp_ops->update_fw_options(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 2047 | if (ha->flags.npiv_supported) { |
Saurav Kashyap | 45980cc | 2012-08-22 14:21:21 -0400 | [diff] [blame] | 2048 | if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha)) |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 2049 | ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | c48339d | 2008-01-17 09:02:19 -0800 | [diff] [blame] | 2050 | mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports); |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 2051 | } |
| 2052 | |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 2053 | if (IS_FWI2_CAPABLE(ha)) { |
| 2054 | mid_init_cb->options = __constant_cpu_to_le16(BIT_1); |
| 2055 | mid_init_cb->init_cb.execution_throttle = |
| 2056 | cpu_to_le16(ha->fw_xcb_count); |
| 2057 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2058 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2059 | rval = qla2x00_init_firmware(vha, ha->init_cb_size); |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 2060 | next_check: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2061 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2062 | ql_log(ql_log_fatal, vha, 0x00d2, |
| 2063 | "Init Firmware **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2065 | ql_dbg(ql_dbg_init, vha, 0x00d3, |
| 2066 | "Init Firmware -- success.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | } |
| 2068 | |
| 2069 | return (rval); |
| 2070 | } |
| 2071 | |
| 2072 | /** |
| 2073 | * qla2x00_fw_ready() - Waits for firmware ready. |
| 2074 | * @ha: HA context |
| 2075 | * |
| 2076 | * Returns 0 on success. |
| 2077 | */ |
| 2078 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2079 | qla2x00_fw_ready(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | { |
| 2081 | int rval; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2082 | unsigned long wtime, mtime, cs84xx_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | uint16_t min_wait; /* Minimum wait time if loop is down */ |
| 2084 | uint16_t wait_time; /* Wait time if loop is coming ready */ |
Andrew Vasquez | 656e891 | 2009-06-03 09:55:29 -0700 | [diff] [blame] | 2085 | uint16_t state[5]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2086 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 2088 | if (IS_QLAFX00(vha->hw)) |
| 2089 | return qlafx00_fw_ready(vha); |
| 2090 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2091 | rval = QLA_SUCCESS; |
| 2092 | |
| 2093 | /* 20 seconds for loop down. */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2094 | min_wait = 20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | |
| 2096 | /* |
| 2097 | * Firmware should take at most one RATOV to login, plus 5 seconds for |
| 2098 | * our own processing. |
| 2099 | */ |
| 2100 | if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) { |
| 2101 | wait_time = min_wait; |
| 2102 | } |
| 2103 | |
| 2104 | /* Min wait time if loop down */ |
| 2105 | mtime = jiffies + (min_wait * HZ); |
| 2106 | |
| 2107 | /* wait time before firmware ready */ |
| 2108 | wtime = jiffies + (wait_time * HZ); |
| 2109 | |
| 2110 | /* Wait for ISP to finish LIP */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2111 | if (!vha->flags.init_done) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2112 | ql_log(ql_log_info, vha, 0x801e, |
| 2113 | "Waiting for LIP to complete.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2114 | |
| 2115 | do { |
Andrew Vasquez | 5b93903 | 2012-11-21 02:40:26 -0500 | [diff] [blame] | 2116 | memset(state, -1, sizeof(state)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2117 | rval = qla2x00_get_firmware_state(vha, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | if (rval == QLA_SUCCESS) { |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2119 | if (state[0] < FSTATE_LOSS_OF_SYNC) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2120 | vha->device_flags &= ~DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2122 | if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2123 | ql_dbg(ql_dbg_taskm, vha, 0x801f, |
| 2124 | "fw_state=%x 84xx=%x.\n", state[0], |
| 2125 | state[2]); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2126 | if ((state[2] & FSTATE_LOGGED_IN) && |
| 2127 | (state[2] & FSTATE_WAITING_FOR_VERIFY)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2128 | ql_dbg(ql_dbg_taskm, vha, 0x8028, |
| 2129 | "Sending verify iocb.\n"); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2130 | |
| 2131 | cs84xx_time = jiffies; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2132 | rval = qla84xx_init_chip(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2133 | if (rval != QLA_SUCCESS) { |
| 2134 | ql_log(ql_log_warn, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2135 | vha, 0x8007, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2136 | "Init chip failed.\n"); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2137 | break; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2138 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2139 | |
| 2140 | /* Add time taken to initialize. */ |
| 2141 | cs84xx_time = jiffies - cs84xx_time; |
| 2142 | wtime += cs84xx_time; |
| 2143 | mtime += cs84xx_time; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2144 | ql_dbg(ql_dbg_taskm, vha, 0x8008, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2145 | "Increasing wait time by %ld. " |
| 2146 | "New time %ld.\n", cs84xx_time, |
| 2147 | wtime); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2148 | } |
| 2149 | } else if (state[0] == FSTATE_READY) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2150 | ql_dbg(ql_dbg_taskm, vha, 0x8037, |
| 2151 | "F/W Ready - OK.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2152 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2153 | qla2x00_get_retry_cnt(vha, &ha->retry_count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2154 | &ha->login_timeout, &ha->r_a_tov); |
| 2155 | |
| 2156 | rval = QLA_SUCCESS; |
| 2157 | break; |
| 2158 | } |
| 2159 | |
| 2160 | rval = QLA_FUNCTION_FAILED; |
| 2161 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2162 | if (atomic_read(&vha->loop_down_timer) && |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2163 | state[0] != FSTATE_READY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | /* Loop down. Timeout on min_wait for states |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2165 | * other than Wait for Login. |
| 2166 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2167 | if (time_after_eq(jiffies, mtime)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2168 | ql_log(ql_log_info, vha, 0x8038, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | "Cable is unplugged...\n"); |
| 2170 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2171 | vha->device_flags |= DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | break; |
| 2173 | } |
| 2174 | } |
| 2175 | } else { |
| 2176 | /* Mailbox cmd failed. Timeout on min_wait. */ |
Santosh Vernekar | cdbb0a4f | 2010-05-28 15:08:25 -0700 | [diff] [blame] | 2177 | if (time_after_eq(jiffies, mtime) || |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 2178 | ha->flags.isp82xx_fw_hung) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2179 | break; |
| 2180 | } |
| 2181 | |
| 2182 | if (time_after_eq(jiffies, wtime)) |
| 2183 | break; |
| 2184 | |
| 2185 | /* Delay for a while */ |
| 2186 | msleep(500); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2187 | } while (1); |
| 2188 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2189 | ql_dbg(ql_dbg_taskm, vha, 0x803a, |
| 2190 | "fw_state=%x (%x, %x, %x, %x) " "curr time=%lx.\n", state[0], |
| 2191 | state[1], state[2], state[3], state[4], jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2192 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2193 | if (rval && !(vha->device_flags & DFLG_NO_CABLE)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2194 | ql_log(ql_log_warn, vha, 0x803b, |
| 2195 | "Firmware ready **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2196 | } |
| 2197 | |
| 2198 | return (rval); |
| 2199 | } |
| 2200 | |
| 2201 | /* |
| 2202 | * qla2x00_configure_hba |
| 2203 | * Setup adapter context. |
| 2204 | * |
| 2205 | * Input: |
| 2206 | * ha = adapter state pointer. |
| 2207 | * |
| 2208 | * Returns: |
| 2209 | * 0 = success |
| 2210 | * |
| 2211 | * Context: |
| 2212 | * Kernel context. |
| 2213 | */ |
| 2214 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2215 | qla2x00_configure_hba(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2216 | { |
| 2217 | int rval; |
| 2218 | uint16_t loop_id; |
| 2219 | uint16_t topo; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2220 | uint16_t sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2221 | uint8_t al_pa; |
| 2222 | uint8_t area; |
| 2223 | uint8_t domain; |
| 2224 | char connect_type[22]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2225 | struct qla_hw_data *ha = vha->hw; |
Jiri Kosina | f24b5cb | 2012-10-08 09:23:54 +0200 | [diff] [blame] | 2226 | unsigned long flags; |
Joe Carnuccio | 61e1b26 | 2013-02-08 01:57:48 -0500 | [diff] [blame] | 2227 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2228 | |
| 2229 | /* Get host addresses. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2230 | rval = qla2x00_get_adapter_id(vha, |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2231 | &loop_id, &al_pa, &area, &domain, &topo, &sw_cap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2232 | if (rval != QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2233 | if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) || |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2234 | IS_CNA_CAPABLE(ha) || |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 2235 | (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2236 | ql_dbg(ql_dbg_disc, vha, 0x2008, |
| 2237 | "Loop is in a transition state.\n"); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 2238 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2239 | ql_log(ql_log_warn, vha, 0x2009, |
| 2240 | "Unable to get host loop ID.\n"); |
Joe Carnuccio | 61e1b26 | 2013-02-08 01:57:48 -0500 | [diff] [blame] | 2241 | if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) && |
| 2242 | (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) { |
| 2243 | ql_log(ql_log_warn, vha, 0x1151, |
| 2244 | "Doing link init.\n"); |
| 2245 | if (qla24xx_link_initialize(vha) == QLA_SUCCESS) |
| 2246 | return rval; |
| 2247 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2248 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 2249 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2250 | return (rval); |
| 2251 | } |
| 2252 | |
| 2253 | if (topo == 4) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2254 | ql_log(ql_log_info, vha, 0x200a, |
| 2255 | "Cannot get topology - retrying.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2256 | return (QLA_FUNCTION_FAILED); |
| 2257 | } |
| 2258 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2259 | vha->loop_id = loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2260 | |
| 2261 | /* initialize */ |
| 2262 | ha->min_external_loopid = SNS_FIRST_LOOP_ID; |
| 2263 | ha->operating_mode = LOOP; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2264 | ha->switch_cap = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2265 | |
| 2266 | switch (topo) { |
| 2267 | case 0: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2268 | ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2269 | ha->current_topology = ISP_CFG_NL; |
| 2270 | strcpy(connect_type, "(Loop)"); |
| 2271 | break; |
| 2272 | |
| 2273 | case 1: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2274 | ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n"); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2275 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2276 | ha->current_topology = ISP_CFG_FL; |
| 2277 | strcpy(connect_type, "(FL_Port)"); |
| 2278 | break; |
| 2279 | |
| 2280 | case 2: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2281 | 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] | 2282 | ha->operating_mode = P2P; |
| 2283 | ha->current_topology = ISP_CFG_N; |
| 2284 | strcpy(connect_type, "(N_Port-to-N_Port)"); |
| 2285 | break; |
| 2286 | |
| 2287 | case 3: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2288 | 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] | 2289 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2290 | ha->operating_mode = P2P; |
| 2291 | ha->current_topology = ISP_CFG_F; |
| 2292 | strcpy(connect_type, "(F_Port)"); |
| 2293 | break; |
| 2294 | |
| 2295 | default: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2296 | ql_dbg(ql_dbg_disc, vha, 0x200f, |
| 2297 | "HBA in unknown topology %x, using NL.\n", topo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | ha->current_topology = ISP_CFG_NL; |
| 2299 | strcpy(connect_type, "(Loop)"); |
| 2300 | break; |
| 2301 | } |
| 2302 | |
| 2303 | /* Save Host port and loop ID. */ |
| 2304 | /* byte order - Big Endian */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2305 | vha->d_id.b.domain = domain; |
| 2306 | vha->d_id.b.area = area; |
| 2307 | vha->d_id.b.al_pa = al_pa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | |
Jiri Kosina | f24b5cb | 2012-10-08 09:23:54 +0200 | [diff] [blame] | 2309 | spin_lock_irqsave(&ha->vport_slock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2310 | qlt_update_vp_map(vha, SET_AL_PA); |
Jiri Kosina | f24b5cb | 2012-10-08 09:23:54 +0200 | [diff] [blame] | 2311 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2312 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2313 | if (!vha->flags.init_done) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2314 | ql_log(ql_log_info, vha, 0x2010, |
| 2315 | "Topology - %s, Host Loop address 0x%x.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2316 | connect_type, vha->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | return(rval); |
| 2319 | } |
| 2320 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2321 | inline void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2322 | qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len, |
| 2323 | char *def) |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2324 | { |
| 2325 | char *st, *en; |
| 2326 | uint16_t index; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2327 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | ab67114 | 2009-08-25 11:36:17 -0700 | [diff] [blame] | 2328 | int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) && |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2329 | !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2330 | |
| 2331 | if (memcmp(model, BINZERO, len) != 0) { |
| 2332 | strncpy(ha->model_number, model, len); |
| 2333 | st = en = ha->model_number; |
| 2334 | en += len - 1; |
| 2335 | while (en > st) { |
| 2336 | if (*en != 0x20 && *en != 0x00) |
| 2337 | break; |
| 2338 | *en-- = '\0'; |
| 2339 | } |
| 2340 | |
| 2341 | index = (ha->pdev->subsystem_device & 0xff); |
Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 2342 | if (use_tbl && |
| 2343 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2344 | index < QLA_MODEL_NAMES) |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2345 | strncpy(ha->model_desc, |
| 2346 | qla2x00_model_name[index * 2 + 1], |
| 2347 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2348 | } else { |
| 2349 | index = (ha->pdev->subsystem_device & 0xff); |
Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 2350 | if (use_tbl && |
| 2351 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2352 | index < QLA_MODEL_NAMES) { |
| 2353 | strcpy(ha->model_number, |
| 2354 | qla2x00_model_name[index * 2]); |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2355 | strncpy(ha->model_desc, |
| 2356 | qla2x00_model_name[index * 2 + 1], |
| 2357 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2358 | } else { |
| 2359 | strcpy(ha->model_number, def); |
| 2360 | } |
| 2361 | } |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2362 | if (IS_FWI2_CAPABLE(ha)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2363 | qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc, |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2364 | sizeof(ha->model_desc)); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2365 | } |
| 2366 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2367 | /* On sparc systems, obtain port and node WWN from firmware |
| 2368 | * properties. |
| 2369 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2370 | 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] | 2371 | { |
| 2372 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2373 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2374 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 2375 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 2376 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2377 | int len; |
| 2378 | |
| 2379 | val = of_get_property(dp, "port-wwn", &len); |
| 2380 | if (val && len >= WWN_SIZE) |
| 2381 | memcpy(nv->port_name, val, WWN_SIZE); |
| 2382 | |
| 2383 | val = of_get_property(dp, "node-wwn", &len); |
| 2384 | if (val && len >= WWN_SIZE) |
| 2385 | memcpy(nv->node_name, val, WWN_SIZE); |
| 2386 | #endif |
| 2387 | } |
| 2388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2389 | /* |
| 2390 | * NVRAM configuration for ISP 2xxx |
| 2391 | * |
| 2392 | * Input: |
| 2393 | * ha = adapter block pointer. |
| 2394 | * |
| 2395 | * Output: |
| 2396 | * initialization control block in response_ring |
| 2397 | * host adapters parameters in host adapter block |
| 2398 | * |
| 2399 | * Returns: |
| 2400 | * 0 = success. |
| 2401 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2402 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2403 | qla2x00_nvram_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2405 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2406 | uint8_t chksum = 0; |
| 2407 | uint16_t cnt; |
| 2408 | uint8_t *dptr1, *dptr2; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2409 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2410 | init_cb_t *icb = ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 2411 | nvram_t *nv = ha->nvram; |
| 2412 | uint8_t *ptr = ha->nvram; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2413 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2415 | rval = QLA_SUCCESS; |
| 2416 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | /* Determine NVRAM starting address. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2418 | ha->nvram_size = sizeof(nvram_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | ha->nvram_base = 0; |
| 2420 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) |
| 2421 | if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1) |
| 2422 | ha->nvram_base = 0x80; |
| 2423 | |
| 2424 | /* Get NVRAM data and calculate checksum. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2425 | 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] | 2426 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++) |
| 2427 | chksum += *ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2428 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2429 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f, |
| 2430 | "Contents of NVRAM.\n"); |
| 2431 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110, |
| 2432 | (uint8_t *)nv, ha->nvram_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2433 | |
| 2434 | /* Bad NVRAM data, set defaults parameters. */ |
| 2435 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || |
| 2436 | nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) { |
| 2437 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2438 | ql_log(ql_log_warn, vha, 0x0064, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 2439 | "Inconsistent NVRAM " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2440 | "detected: checksum=0x%x id=%c version=0x%x.\n", |
| 2441 | chksum, nv->id[0], nv->nvram_version); |
| 2442 | ql_log(ql_log_warn, vha, 0x0065, |
| 2443 | "Falling back to " |
| 2444 | "functioning (yet invalid -- WWPN) defaults.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2445 | |
| 2446 | /* |
| 2447 | * Set default initialization control block. |
| 2448 | */ |
| 2449 | memset(nv, 0, ha->nvram_size); |
| 2450 | nv->parameter_block_version = ICB_VERSION; |
| 2451 | |
| 2452 | if (IS_QLA23XX(ha)) { |
| 2453 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 2454 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 2455 | nv->add_firmware_options[0] = BIT_5; |
| 2456 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
| 2457 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 2458 | nv->special_options[1] = BIT_7; |
| 2459 | } else if (IS_QLA2200(ha)) { |
| 2460 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 2461 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 2462 | nv->add_firmware_options[0] = BIT_5; |
| 2463 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
| 2464 | nv->frame_payload_size = __constant_cpu_to_le16(1024); |
| 2465 | } else if (IS_QLA2100(ha)) { |
| 2466 | nv->firmware_options[0] = BIT_3 | BIT_1; |
| 2467 | nv->firmware_options[1] = BIT_5; |
| 2468 | nv->frame_payload_size = __constant_cpu_to_le16(1024); |
| 2469 | } |
| 2470 | |
| 2471 | nv->max_iocb_allocation = __constant_cpu_to_le16(256); |
| 2472 | nv->execution_throttle = __constant_cpu_to_le16(16); |
| 2473 | nv->retry_count = 8; |
| 2474 | nv->retry_delay = 1; |
| 2475 | |
| 2476 | nv->port_name[0] = 33; |
| 2477 | nv->port_name[3] = 224; |
| 2478 | nv->port_name[4] = 139; |
| 2479 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2480 | qla2xxx_nvram_wwn_from_ofw(vha, nv); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2481 | |
| 2482 | nv->login_timeout = 4; |
| 2483 | |
| 2484 | /* |
| 2485 | * Set default host adapter parameters |
| 2486 | */ |
| 2487 | nv->host_p[1] = BIT_2; |
| 2488 | nv->reset_delay = 5; |
| 2489 | nv->port_down_retry_count = 8; |
| 2490 | nv->max_luns_per_target = __constant_cpu_to_le16(8); |
| 2491 | nv->link_down_timeout = 60; |
| 2492 | |
| 2493 | rval = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2494 | } |
| 2495 | |
| 2496 | #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2) |
| 2497 | /* |
| 2498 | * The SN2 does not provide BIOS emulation which means you can't change |
| 2499 | * potentially bogus BIOS settings. Force the use of default settings |
| 2500 | * for link rate and frame size. Hope that the rest of the settings |
| 2501 | * are valid. |
| 2502 | */ |
| 2503 | if (ia64_platform_is("sn2")) { |
| 2504 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 2505 | if (IS_QLA23XX(ha)) |
| 2506 | nv->special_options[1] = BIT_7; |
| 2507 | } |
| 2508 | #endif |
| 2509 | |
| 2510 | /* Reset Initialization control block */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2511 | memset(icb, 0, ha->init_cb_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2512 | |
| 2513 | /* |
| 2514 | * Setup driver NVRAM options. |
| 2515 | */ |
| 2516 | nv->firmware_options[0] |= (BIT_6 | BIT_1); |
| 2517 | nv->firmware_options[0] &= ~(BIT_5 | BIT_4); |
| 2518 | nv->firmware_options[1] |= (BIT_5 | BIT_0); |
| 2519 | nv->firmware_options[1] &= ~BIT_4; |
| 2520 | |
| 2521 | if (IS_QLA23XX(ha)) { |
| 2522 | nv->firmware_options[0] |= BIT_2; |
| 2523 | nv->firmware_options[0] &= ~BIT_3; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2524 | nv->special_options[0] &= ~BIT_6; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2525 | nv->add_firmware_options[1] |= BIT_5 | BIT_4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2526 | |
| 2527 | if (IS_QLA2300(ha)) { |
| 2528 | if (ha->fb_rev == FPM_2310) { |
| 2529 | strcpy(ha->model_number, "QLA2310"); |
| 2530 | } else { |
| 2531 | strcpy(ha->model_number, "QLA2300"); |
| 2532 | } |
| 2533 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2534 | qla2x00_set_model_info(vha, nv->model_number, |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2535 | sizeof(nv->model_number), "QLA23xx"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2536 | } |
| 2537 | } else if (IS_QLA2200(ha)) { |
| 2538 | nv->firmware_options[0] |= BIT_2; |
| 2539 | /* |
| 2540 | * 'Point-to-point preferred, else loop' is not a safe |
| 2541 | * connection mode setting. |
| 2542 | */ |
| 2543 | if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) == |
| 2544 | (BIT_5 | BIT_4)) { |
| 2545 | /* Force 'loop preferred, else point-to-point'. */ |
| 2546 | nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4); |
| 2547 | nv->add_firmware_options[0] |= BIT_5; |
| 2548 | } |
| 2549 | strcpy(ha->model_number, "QLA22xx"); |
| 2550 | } else /*if (IS_QLA2100(ha))*/ { |
| 2551 | strcpy(ha->model_number, "QLA2100"); |
| 2552 | } |
| 2553 | |
| 2554 | /* |
| 2555 | * Copy over NVRAM RISC parameter block to initialization control block. |
| 2556 | */ |
| 2557 | dptr1 = (uint8_t *)icb; |
| 2558 | dptr2 = (uint8_t *)&nv->parameter_block_version; |
| 2559 | cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version; |
| 2560 | while (cnt--) |
| 2561 | *dptr1++ = *dptr2++; |
| 2562 | |
| 2563 | /* Copy 2nd half. */ |
| 2564 | dptr1 = (uint8_t *)icb->add_firmware_options; |
| 2565 | cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options; |
| 2566 | while (cnt--) |
| 2567 | *dptr1++ = *dptr2++; |
| 2568 | |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 2569 | /* Use alternate WWN? */ |
| 2570 | if (nv->host_p[1] & BIT_7) { |
| 2571 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 2572 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 2573 | } |
| 2574 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2575 | /* Prepare nodename */ |
| 2576 | if ((icb->firmware_options[1] & BIT_6) == 0) { |
| 2577 | /* |
| 2578 | * Firmware will apply the following mask if the nodename was |
| 2579 | * not provided. |
| 2580 | */ |
| 2581 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 2582 | icb->node_name[0] &= 0xF0; |
| 2583 | } |
| 2584 | |
| 2585 | /* |
| 2586 | * Set host adapter parameters. |
| 2587 | */ |
Saurav Kashyap | 3ce8866 | 2011-07-14 12:00:12 -0700 | [diff] [blame] | 2588 | |
| 2589 | /* |
| 2590 | * BIT_7 in the host-parameters section allows for modification to |
| 2591 | * internal driver logging. |
| 2592 | */ |
Andrew Vasquez | 0181944 | 2006-06-23 16:11:10 -0700 | [diff] [blame] | 2593 | if (nv->host_p[0] & BIT_7) |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2594 | ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2595 | ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0); |
| 2596 | /* Always load RISC code on non ISP2[12]00 chips. */ |
| 2597 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) |
| 2598 | ha->flags.disable_risc_code_load = 0; |
| 2599 | ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0); |
| 2600 | ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0); |
| 2601 | 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] | 2602 | 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] | 2603 | ha->flags.disable_serdes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2604 | |
| 2605 | ha->operating_mode = |
| 2606 | (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 2607 | |
| 2608 | memcpy(ha->fw_seriallink_options, nv->seriallink_options, |
| 2609 | sizeof(ha->fw_seriallink_options)); |
| 2610 | |
| 2611 | /* save HBA serial number */ |
| 2612 | ha->serial0 = icb->port_name[5]; |
| 2613 | ha->serial1 = icb->port_name[6]; |
| 2614 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2615 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 2616 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2617 | |
| 2618 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 2619 | |
| 2620 | ha->retry_count = nv->retry_count; |
| 2621 | |
| 2622 | /* Set minimum login_timeout to 4 seconds. */ |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 2623 | if (nv->login_timeout != ql2xlogintimeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2624 | nv->login_timeout = ql2xlogintimeout; |
| 2625 | if (nv->login_timeout < 4) |
| 2626 | nv->login_timeout = 4; |
| 2627 | ha->login_timeout = nv->login_timeout; |
| 2628 | icb->login_timeout = nv->login_timeout; |
| 2629 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 2630 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 2631 | ha->r_a_tov = 100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2632 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2633 | ha->loop_reset_delay = nv->reset_delay; |
| 2634 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2635 | /* Link Down Timeout = 0: |
| 2636 | * |
| 2637 | * When Port Down timer expires we will start returning |
| 2638 | * I/O's to OS with "DID_NO_CONNECT". |
| 2639 | * |
| 2640 | * Link Down Timeout != 0: |
| 2641 | * |
| 2642 | * The driver waits for the link to come up after link down |
| 2643 | * before returning I/Os to OS with "DID_NO_CONNECT". |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2644 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2645 | if (nv->link_down_timeout == 0) { |
| 2646 | ha->loop_down_abort_time = |
Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 2647 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2648 | } else { |
| 2649 | ha->link_down_timeout = nv->link_down_timeout; |
| 2650 | ha->loop_down_abort_time = |
| 2651 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2652 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2654 | /* |
| 2655 | * Need enough time to try and get the port back. |
| 2656 | */ |
| 2657 | ha->port_down_retry_count = nv->port_down_retry_count; |
| 2658 | if (qlport_down_retry) |
| 2659 | ha->port_down_retry_count = qlport_down_retry; |
| 2660 | /* Set login_retry_count */ |
| 2661 | ha->login_retry_count = nv->retry_count; |
| 2662 | if (ha->port_down_retry_count == nv->port_down_retry_count && |
| 2663 | ha->port_down_retry_count > 3) |
| 2664 | ha->login_retry_count = ha->port_down_retry_count; |
| 2665 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 2666 | ha->login_retry_count = ha->port_down_retry_count; |
| 2667 | if (ql2xloginretrycount) |
| 2668 | ha->login_retry_count = ql2xloginretrycount; |
| 2669 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2670 | icb->lun_enables = __constant_cpu_to_le16(0); |
| 2671 | icb->command_resource_count = 0; |
| 2672 | icb->immediate_notify_resource_count = 0; |
| 2673 | icb->timeout = __constant_cpu_to_le16(0); |
| 2674 | |
| 2675 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 2676 | /* Enable RIO */ |
| 2677 | icb->firmware_options[0] &= ~BIT_3; |
| 2678 | icb->add_firmware_options[0] &= |
| 2679 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 2680 | icb->add_firmware_options[0] |= BIT_2; |
| 2681 | icb->response_accumulation_timer = 3; |
| 2682 | icb->interrupt_delay_timer = 5; |
| 2683 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2684 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2685 | } else { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2686 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2687 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2688 | ha->zio_mode = icb->add_firmware_options[0] & |
| 2689 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 2690 | ha->zio_timer = icb->interrupt_delay_timer ? |
| 2691 | icb->interrupt_delay_timer: 2; |
| 2692 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2693 | icb->add_firmware_options[0] &= |
| 2694 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2695 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2696 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 2697 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 2698 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2699 | ql_log(ql_log_info, vha, 0x0068, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2700 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 2701 | ha->zio_mode, ha->zio_timer * 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2702 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2703 | icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode; |
| 2704 | icb->interrupt_delay_timer = (uint8_t)ha->zio_timer; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2705 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | } |
| 2707 | } |
| 2708 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2709 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2710 | ql_log(ql_log_warn, vha, 0x0069, |
| 2711 | "NVRAM configuration failed.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2712 | } |
| 2713 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | } |
| 2715 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2716 | static void |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2717 | qla2x00_rport_del(void *data) |
| 2718 | { |
| 2719 | fc_port_t *fcport = data; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2720 | struct fc_rport *rport; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2721 | scsi_qla_host_t *vha = fcport->vha; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2722 | unsigned long flags; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2723 | |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2724 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2725 | rport = fcport->drport ? fcport->drport: fcport->rport; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2726 | fcport->drport = NULL; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2727 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2728 | if (rport) { |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2729 | fc_remote_port_delete(rport); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2730 | /* |
| 2731 | * Release the target mode FC NEXUS in qla_target.c code |
| 2732 | * if target mod is enabled. |
| 2733 | */ |
| 2734 | qlt_fc_port_deleted(vha, fcport); |
| 2735 | } |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2736 | } |
| 2737 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2738 | /** |
| 2739 | * qla2x00_alloc_fcport() - Allocate a generic fcport. |
| 2740 | * @ha: HA context |
| 2741 | * @flags: allocation flags |
| 2742 | * |
| 2743 | * Returns a pointer to the allocated fcport, or NULL, if none available. |
| 2744 | */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2745 | fc_port_t * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2746 | qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2747 | { |
| 2748 | fc_port_t *fcport; |
| 2749 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2750 | fcport = kzalloc(sizeof(fc_port_t), flags); |
| 2751 | if (!fcport) |
| 2752 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2753 | |
| 2754 | /* Setup fcport template structure. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2755 | fcport->vha = vha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2756 | fcport->port_type = FCT_UNKNOWN; |
| 2757 | fcport->loop_id = FC_NO_LOOP_ID; |
Chad Dupuis | ec426e1 | 2011-03-30 11:46:32 -0700 | [diff] [blame] | 2758 | qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED); |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 2759 | fcport->supported_classes = FC_COS_UNSPECIFIED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2760 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2761 | return fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2762 | } |
| 2763 | |
| 2764 | /* |
| 2765 | * qla2x00_configure_loop |
| 2766 | * Updates Fibre Channel Device Database with what is actually on loop. |
| 2767 | * |
| 2768 | * Input: |
| 2769 | * ha = adapter block pointer. |
| 2770 | * |
| 2771 | * Returns: |
| 2772 | * 0 = success. |
| 2773 | * 1 = error. |
| 2774 | * 2 = database was full and device was not configured. |
| 2775 | */ |
| 2776 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2777 | qla2x00_configure_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2778 | { |
| 2779 | int rval; |
| 2780 | unsigned long flags, save_flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2781 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2782 | rval = QLA_SUCCESS; |
| 2783 | |
| 2784 | /* Get Initiator ID */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2785 | if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) { |
| 2786 | rval = qla2x00_configure_hba(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2788 | ql_dbg(ql_dbg_disc, vha, 0x2013, |
| 2789 | "Unable to configure HBA.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2790 | return (rval); |
| 2791 | } |
| 2792 | } |
| 2793 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2794 | save_flags = flags = vha->dpc_flags; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2795 | ql_dbg(ql_dbg_disc, vha, 0x2014, |
| 2796 | "Configure loop -- dpc flags = 0x%lx.\n", flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2797 | |
| 2798 | /* |
| 2799 | * If we have both an RSCN and PORT UPDATE pending then handle them |
| 2800 | * both at the same time. |
| 2801 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2802 | clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 2803 | clear_bit(RSCN_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | |
Michael Hernandez | 3064ff3 | 2009-12-15 21:29:44 -0800 | [diff] [blame] | 2805 | qla2x00_get_data_rate(vha); |
| 2806 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2807 | /* Determine what we need to do */ |
| 2808 | if (ha->current_topology == ISP_CFG_FL && |
| 2809 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 2810 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2811 | set_bit(RSCN_UPDATE, &flags); |
| 2812 | |
| 2813 | } else if (ha->current_topology == ISP_CFG_F && |
| 2814 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 2815 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2816 | set_bit(RSCN_UPDATE, &flags); |
| 2817 | clear_bit(LOCAL_LOOP_UPDATE, &flags); |
| 2818 | |
Andrew Vasquez | 21333b4 | 2006-05-17 15:09:56 -0700 | [diff] [blame] | 2819 | } else if (ha->current_topology == ISP_CFG_N) { |
| 2820 | clear_bit(RSCN_UPDATE, &flags); |
| 2821 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2822 | } else if (!vha->flags.online || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2823 | (test_bit(ABORT_ISP_ACTIVE, &flags))) { |
| 2824 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2825 | set_bit(RSCN_UPDATE, &flags); |
| 2826 | set_bit(LOCAL_LOOP_UPDATE, &flags); |
| 2827 | } |
| 2828 | |
| 2829 | if (test_bit(LOCAL_LOOP_UPDATE, &flags)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2830 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
| 2831 | ql_dbg(ql_dbg_disc, vha, 0x2015, |
| 2832 | "Loop resync needed, failing.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2833 | rval = QLA_FUNCTION_FAILED; |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 2834 | } else |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2835 | rval = qla2x00_configure_local_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2836 | } |
| 2837 | |
| 2838 | if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2839 | if (LOOP_TRANSITION(vha)) { |
| 2840 | ql_dbg(ql_dbg_disc, vha, 0x201e, |
| 2841 | "Needs RSCN update and loop transition.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2842 | rval = QLA_FUNCTION_FAILED; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2843 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2844 | else |
| 2845 | rval = qla2x00_configure_fabric(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | } |
| 2847 | |
| 2848 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2849 | if (atomic_read(&vha->loop_down_timer) || |
| 2850 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2851 | rval = QLA_FUNCTION_FAILED; |
| 2852 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2853 | atomic_set(&vha->loop_state, LOOP_READY); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2854 | ql_dbg(ql_dbg_disc, vha, 0x2069, |
| 2855 | "LOOP READY.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2856 | } |
| 2857 | } |
| 2858 | |
| 2859 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2860 | ql_dbg(ql_dbg_disc, vha, 0x206a, |
| 2861 | "%s *** FAILED ***.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2862 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2863 | ql_dbg(ql_dbg_disc, vha, 0x206b, |
| 2864 | "%s: exiting normally.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2865 | } |
| 2866 | |
Bjorn Helgaas | cc3ef7b | 2008-09-11 21:22:51 -0700 | [diff] [blame] | 2867 | /* Restore state if a resync event occurred during processing */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2868 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2869 | if (test_bit(LOCAL_LOOP_UPDATE, &save_flags)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2870 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 2871 | if (test_bit(RSCN_UPDATE, &save_flags)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2872 | set_bit(RSCN_UPDATE, &vha->dpc_flags); |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 2873 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2874 | } |
| 2875 | |
| 2876 | return (rval); |
| 2877 | } |
| 2878 | |
| 2879 | |
| 2880 | |
| 2881 | /* |
| 2882 | * qla2x00_configure_local_loop |
| 2883 | * Updates Fibre Channel Device Database with local loop devices. |
| 2884 | * |
| 2885 | * Input: |
| 2886 | * ha = adapter block pointer. |
| 2887 | * |
| 2888 | * Returns: |
| 2889 | * 0 = success. |
| 2890 | */ |
| 2891 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2892 | qla2x00_configure_local_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2893 | { |
| 2894 | int rval, rval2; |
| 2895 | int found_devs; |
| 2896 | int found; |
| 2897 | fc_port_t *fcport, *new_fcport; |
| 2898 | |
| 2899 | uint16_t index; |
| 2900 | uint16_t entries; |
| 2901 | char *id_iter; |
| 2902 | uint16_t loop_id; |
| 2903 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2904 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2905 | |
| 2906 | found_devs = 0; |
| 2907 | new_fcport = NULL; |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 2908 | entries = MAX_FIBRE_DEVICES_LOOP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2909 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2910 | /* Get list of logged in devices. */ |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 2911 | memset(ha->gid_list, 0, qla2x00_gid_list_size(ha)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2912 | 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] | 2913 | &entries); |
| 2914 | if (rval != QLA_SUCCESS) |
| 2915 | goto cleanup_allocation; |
| 2916 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2917 | ql_dbg(ql_dbg_disc, vha, 0x2017, |
| 2918 | "Entries in ID list (%d).\n", entries); |
| 2919 | ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075, |
| 2920 | (uint8_t *)ha->gid_list, |
| 2921 | entries * sizeof(struct gid_list_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2922 | |
| 2923 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2924 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2925 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2926 | ql_log(ql_log_warn, vha, 0x2018, |
| 2927 | "Memory allocation failed for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 2929 | goto cleanup_allocation; |
| 2930 | } |
| 2931 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 2932 | |
| 2933 | /* |
| 2934 | * Mark local devices that were present with FCF_DEVICE_LOST for now. |
| 2935 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2936 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2937 | if (atomic_read(&fcport->state) == FCS_ONLINE && |
| 2938 | fcport->port_type != FCT_BROADCAST && |
| 2939 | (fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 2940 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2941 | ql_dbg(ql_dbg_disc, vha, 0x2019, |
| 2942 | "Marking port lost loop_id=0x%04x.\n", |
| 2943 | fcport->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2944 | |
Chad Dupuis | ec426e1 | 2011-03-30 11:46:32 -0700 | [diff] [blame] | 2945 | qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2946 | } |
| 2947 | } |
| 2948 | |
| 2949 | /* Add devices to port list. */ |
| 2950 | id_iter = (char *)ha->gid_list; |
| 2951 | for (index = 0; index < entries; index++) { |
| 2952 | domain = ((struct gid_list_info *)id_iter)->domain; |
| 2953 | area = ((struct gid_list_info *)id_iter)->area; |
| 2954 | al_pa = ((struct gid_list_info *)id_iter)->al_pa; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2955 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2956 | loop_id = (uint16_t) |
| 2957 | ((struct gid_list_info *)id_iter)->loop_id_2100; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2958 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2959 | loop_id = le16_to_cpu( |
| 2960 | ((struct gid_list_info *)id_iter)->loop_id); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2961 | id_iter += ha->gid_list_info_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2962 | |
| 2963 | /* Bypass reserved domain fields. */ |
| 2964 | if ((domain & 0xf0) == 0xf0) |
| 2965 | continue; |
| 2966 | |
| 2967 | /* Bypass if not same domain and area of adapter. */ |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 2968 | if (area && domain && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2969 | (area != vha->d_id.b.area || domain != vha->d_id.b.domain)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | continue; |
| 2971 | |
| 2972 | /* Bypass invalid local loop ID. */ |
| 2973 | if (loop_id > LAST_LOCAL_LOOP_ID) |
| 2974 | continue; |
| 2975 | |
Arun Easi | 370d550 | 2012-08-22 14:21:10 -0400 | [diff] [blame] | 2976 | memset(new_fcport, 0, sizeof(fc_port_t)); |
| 2977 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | /* Fill in member data. */ |
| 2979 | new_fcport->d_id.b.domain = domain; |
| 2980 | new_fcport->d_id.b.area = area; |
| 2981 | new_fcport->d_id.b.al_pa = al_pa; |
| 2982 | new_fcport->loop_id = loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2983 | rval2 = qla2x00_get_port_database(vha, new_fcport, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2984 | if (rval2 != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2985 | ql_dbg(ql_dbg_disc, vha, 0x201a, |
| 2986 | "Failed to retrieve fcport information " |
| 2987 | "-- get_port_database=%x, loop_id=0x%04x.\n", |
| 2988 | rval2, new_fcport->loop_id); |
| 2989 | ql_dbg(ql_dbg_disc, vha, 0x201b, |
| 2990 | "Scheduling resync.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2991 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2992 | continue; |
| 2993 | } |
| 2994 | |
| 2995 | /* Check for matching device in port list. */ |
| 2996 | found = 0; |
| 2997 | fcport = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2998 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2999 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 3000 | WWN_SIZE)) |
| 3001 | continue; |
| 3002 | |
Shyam Sundar | ddb9b12 | 2009-03-24 09:08:10 -0700 | [diff] [blame] | 3003 | fcport->flags &= ~FCF_FABRIC_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3004 | fcport->loop_id = new_fcport->loop_id; |
| 3005 | fcport->port_type = new_fcport->port_type; |
| 3006 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 3007 | memcpy(fcport->node_name, new_fcport->node_name, |
| 3008 | WWN_SIZE); |
| 3009 | |
| 3010 | found++; |
| 3011 | break; |
| 3012 | } |
| 3013 | |
| 3014 | if (!found) { |
| 3015 | /* New device, add to fcports list. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3016 | list_add_tail(&new_fcport->list, &vha->vp_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3017 | |
| 3018 | /* Allocate a new replacement fcport. */ |
| 3019 | fcport = new_fcport; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3020 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3021 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3022 | ql_log(ql_log_warn, vha, 0x201c, |
| 3023 | "Failed to allocate memory for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3024 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 3025 | goto cleanup_allocation; |
| 3026 | } |
| 3027 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 3028 | } |
| 3029 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3030 | /* Base iIDMA settings on HBA port speed. */ |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 3031 | fcport->fp_speed = ha->link_data_rate; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3032 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3033 | qla2x00_update_fcport(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3034 | |
| 3035 | found_devs++; |
| 3036 | } |
| 3037 | |
| 3038 | cleanup_allocation: |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 3039 | kfree(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | |
| 3041 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3042 | ql_dbg(ql_dbg_disc, vha, 0x201d, |
| 3043 | "Configure local loop error exit: rval=%x.\n", rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3044 | } |
| 3045 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3046 | return (rval); |
| 3047 | } |
| 3048 | |
| 3049 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3050 | qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3051 | { |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3052 | int rval; |
Harish Zunjarrao | 1bb3954 | 2009-06-17 10:30:29 -0700 | [diff] [blame] | 3053 | uint16_t mb[4]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3054 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3055 | |
Andrew Vasquez | c76f2c0 | 2007-07-19 15:05:57 -0700 | [diff] [blame] | 3056 | if (!IS_IIDMA_CAPABLE(ha)) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3057 | return; |
| 3058 | |
Giridhar Malavali | c9afb9a | 2010-09-03 15:20:48 -0700 | [diff] [blame] | 3059 | if (atomic_read(&fcport->state) != FCS_ONLINE) |
| 3060 | return; |
| 3061 | |
Andrew Vasquez | 39bd962 | 2007-09-20 14:07:34 -0700 | [diff] [blame] | 3062 | if (fcport->fp_speed == PORT_SPEED_UNKNOWN || |
| 3063 | fcport->fp_speed > ha->link_data_rate) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3064 | return; |
| 3065 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3066 | rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed, |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 3067 | mb); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3068 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3069 | ql_dbg(ql_dbg_disc, vha, 0x2004, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 3070 | "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n", |
| 3071 | fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3072 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3073 | ql_dbg(ql_dbg_disc, vha, 0x2005, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 3074 | "iIDMA adjusted to %s GB/s on %8phN.\n", |
Joe Carnuccio | d0297c9 | 2012-11-21 02:40:40 -0500 | [diff] [blame] | 3075 | qla2x00_get_link_speed_str(ha, fcport->fp_speed), |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 3076 | fcport->port_name); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3077 | } |
| 3078 | } |
| 3079 | |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 3080 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3081 | qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 3082 | { |
| 3083 | struct fc_rport_identifiers rport_ids; |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 3084 | struct fc_rport *rport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 3085 | unsigned long flags; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 3086 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3087 | qla2x00_rport_del(fcport); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 3088 | |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 3089 | rport_ids.node_name = wwn_to_u64(fcport->node_name); |
| 3090 | rport_ids.port_name = wwn_to_u64(fcport->port_name); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 3091 | rport_ids.port_id = fcport->d_id.b.domain << 16 | |
| 3092 | fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa; |
| 3093 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3094 | fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 3095 | if (!rport) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3096 | ql_log(ql_log_warn, vha, 0x2006, |
| 3097 | "Unable to allocate fc remote port.\n"); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 3098 | return; |
| 3099 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3100 | /* |
| 3101 | * Create target mode FC NEXUS in qla_target.c if target mode is |
| 3102 | * enabled.. |
| 3103 | */ |
| 3104 | qlt_fc_port_added(vha, fcport); |
| 3105 | |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 3106 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3107 | *((fc_port_t **)rport->dd_data) = fcport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 3108 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3109 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 3110 | rport->supported_classes = fcport->supported_classes; |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 3111 | |
| 3112 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 3113 | if (fcport->port_type == FCT_INITIATOR) |
| 3114 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 3115 | if (fcport->port_type == FCT_TARGET) |
| 3116 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 3117 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 3118 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3119 | |
| 3120 | /* |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 3121 | * qla2x00_update_fcport |
| 3122 | * Updates device on list. |
| 3123 | * |
| 3124 | * Input: |
| 3125 | * ha = adapter block pointer. |
| 3126 | * fcport = port structure pointer. |
| 3127 | * |
| 3128 | * Return: |
| 3129 | * 0 - Success |
| 3130 | * BIT_0 - error |
| 3131 | * |
| 3132 | * Context: |
| 3133 | * Kernel context. |
| 3134 | */ |
| 3135 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3136 | qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 3137 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3138 | fcport->vha = vha; |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3139 | |
| 3140 | if (IS_QLAFX00(vha->hw)) { |
| 3141 | qla2x00_set_fcport_state(fcport, FCS_ONLINE); |
| 3142 | qla2x00_reg_remote_port(vha, fcport); |
| 3143 | return; |
| 3144 | } |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 3145 | fcport->login_retry = 0; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 3146 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 3147 | |
Joe Carnuccio | 1f93da52 | 2012-11-21 02:40:38 -0500 | [diff] [blame] | 3148 | qla2x00_set_fcport_state(fcport, FCS_ONLINE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3149 | qla2x00_iidma_fcport(vha, fcport); |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 3150 | qla24xx_update_fcport_fcp_prio(vha, fcport); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3151 | qla2x00_reg_remote_port(vha, fcport); |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 3152 | } |
| 3153 | |
| 3154 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3155 | * qla2x00_configure_fabric |
| 3156 | * Setup SNS devices with loop ID's. |
| 3157 | * |
| 3158 | * Input: |
| 3159 | * ha = adapter block pointer. |
| 3160 | * |
| 3161 | * Returns: |
| 3162 | * 0 = success. |
| 3163 | * BIT_0 = error |
| 3164 | */ |
| 3165 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3166 | qla2x00_configure_fabric(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3167 | { |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 3168 | int rval; |
Joe Carnuccio | e452ceb | 2013-02-08 01:57:56 -0500 | [diff] [blame] | 3169 | fc_port_t *fcport, *fcptemp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3170 | uint16_t next_loopid; |
| 3171 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3172 | uint16_t loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3173 | LIST_HEAD(new_fcports); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3174 | struct qla_hw_data *ha = vha->hw; |
| 3175 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3176 | |
| 3177 | /* If FL port exists, then SNS is present */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 3178 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3179 | loop_id = NPH_F_PORT; |
| 3180 | else |
| 3181 | loop_id = SNS_FL_PORT; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3182 | 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] | 3183 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3184 | ql_dbg(ql_dbg_disc, vha, 0x201f, |
| 3185 | "MBX_GET_PORT_NAME failed, No FL Port.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3186 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3187 | vha->device_flags &= ~SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3188 | return (QLA_SUCCESS); |
| 3189 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3190 | vha->device_flags |= SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3192 | do { |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 3193 | /* FDMI support. */ |
| 3194 | if (ql2xfdmienable && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3195 | test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags)) |
| 3196 | qla2x00_fdmi_register(vha); |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 3197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | /* Ensure we are logged into the SNS. */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 3199 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3200 | loop_id = NPH_SNS; |
| 3201 | else |
| 3202 | loop_id = SIMPLE_NAME_SERVER; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 3203 | rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff, |
| 3204 | 0xfc, mb, BIT_1|BIT_0); |
| 3205 | if (rval != QLA_SUCCESS) { |
| 3206 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Joe Carnuccio | e452ceb | 2013-02-08 01:57:56 -0500 | [diff] [blame] | 3207 | return rval; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 3208 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | if (mb[0] != MBS_COMMAND_COMPLETE) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3210 | ql_dbg(ql_dbg_disc, vha, 0x2042, |
| 3211 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x " |
| 3212 | "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1], |
| 3213 | mb[2], mb[6], mb[7]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3214 | return (QLA_SUCCESS); |
| 3215 | } |
| 3216 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3217 | if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) { |
| 3218 | if (qla2x00_rft_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3220 | ql_dbg(ql_dbg_disc, vha, 0x2045, |
| 3221 | "Register FC-4 TYPE failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3222 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3223 | if (qla2x00_rff_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3224 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3225 | ql_dbg(ql_dbg_disc, vha, 0x2049, |
| 3226 | "Register FC-4 Features failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3227 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3228 | if (qla2x00_rnn_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3230 | ql_dbg(ql_dbg_disc, vha, 0x204f, |
| 3231 | "Register Node Name failed.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3232 | } else if (qla2x00_rsnn_nn(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3233 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3234 | ql_dbg(ql_dbg_disc, vha, 0x2053, |
| 3235 | "Register Symobilic Node Name failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3236 | } |
| 3237 | } |
| 3238 | |
Joe Carnuccio | 827210b | 2013-02-08 01:57:57 -0500 | [diff] [blame] | 3239 | #define QLA_FCPORT_SCAN 1 |
| 3240 | #define QLA_FCPORT_FOUND 2 |
| 3241 | |
| 3242 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 3243 | fcport->scan_state = QLA_FCPORT_SCAN; |
| 3244 | } |
| 3245 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3246 | rval = qla2x00_find_all_fabric_devs(vha, &new_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | if (rval != QLA_SUCCESS) |
| 3248 | break; |
| 3249 | |
Joe Carnuccio | e452ceb | 2013-02-08 01:57:56 -0500 | [diff] [blame] | 3250 | /* |
| 3251 | * Logout all previous fabric devices marked lost, except |
| 3252 | * FCP2 devices. |
| 3253 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3254 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 3255 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3256 | break; |
| 3257 | |
| 3258 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) |
| 3259 | continue; |
| 3260 | |
Joe Carnuccio | 827210b | 2013-02-08 01:57:57 -0500 | [diff] [blame] | 3261 | if (fcport->scan_state == QLA_FCPORT_SCAN && |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 3262 | atomic_read(&fcport->state) == FCS_ONLINE) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3263 | qla2x00_mark_device_lost(vha, fcport, |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3264 | ql2xplogiabsentdevice, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3265 | if (fcport->loop_id != FC_NO_LOOP_ID && |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3266 | (fcport->flags & FCF_FCP2_DEVICE) == 0 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3267 | fcport->port_type != FCT_INITIATOR && |
| 3268 | fcport->port_type != FCT_BROADCAST) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3269 | ha->isp_ops->fabric_logout(vha, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3270 | fcport->loop_id, |
| 3271 | fcport->d_id.b.domain, |
| 3272 | fcport->d_id.b.area, |
| 3273 | fcport->d_id.b.al_pa); |
Joe Carnuccio | e452ceb | 2013-02-08 01:57:56 -0500 | [diff] [blame] | 3274 | fcport->loop_id = FC_NO_LOOP_ID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3275 | } |
| 3276 | } |
Joe Carnuccio | e452ceb | 2013-02-08 01:57:56 -0500 | [diff] [blame] | 3277 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3278 | |
Joe Carnuccio | e452ceb | 2013-02-08 01:57:56 -0500 | [diff] [blame] | 3279 | /* Starting free loop ID. */ |
| 3280 | next_loopid = ha->min_external_loopid; |
| 3281 | |
| 3282 | /* |
| 3283 | * Scan through our port list and login entries that need to be |
| 3284 | * logged in. |
| 3285 | */ |
| 3286 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 3287 | if (atomic_read(&vha->loop_down_timer) || |
| 3288 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 3289 | break; |
| 3290 | |
| 3291 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 || |
| 3292 | (fcport->flags & FCF_LOGIN_NEEDED) == 0) |
| 3293 | continue; |
| 3294 | |
| 3295 | if (fcport->loop_id == FC_NO_LOOP_ID) { |
| 3296 | fcport->loop_id = next_loopid; |
| 3297 | rval = qla2x00_find_new_loop_id( |
| 3298 | base_vha, fcport); |
| 3299 | if (rval != QLA_SUCCESS) { |
| 3300 | /* Ran out of IDs to use */ |
| 3301 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3302 | } |
| 3303 | } |
Joe Carnuccio | e452ceb | 2013-02-08 01:57:56 -0500 | [diff] [blame] | 3304 | /* Login and update database */ |
| 3305 | qla2x00_fabric_dev_login(vha, fcport, &next_loopid); |
| 3306 | } |
| 3307 | |
| 3308 | /* Exit if out of loop IDs. */ |
| 3309 | if (rval != QLA_SUCCESS) { |
| 3310 | break; |
| 3311 | } |
| 3312 | |
| 3313 | /* |
| 3314 | * Login and add the new devices to our port list. |
| 3315 | */ |
| 3316 | list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) { |
| 3317 | if (atomic_read(&vha->loop_down_timer) || |
| 3318 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 3319 | break; |
| 3320 | |
| 3321 | /* Find a new loop ID to use. */ |
| 3322 | fcport->loop_id = next_loopid; |
| 3323 | rval = qla2x00_find_new_loop_id(base_vha, fcport); |
| 3324 | if (rval != QLA_SUCCESS) { |
| 3325 | /* Ran out of IDs to use */ |
| 3326 | break; |
| 3327 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3328 | |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 3329 | /* Login and update database */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3330 | qla2x00_fabric_dev_login(vha, fcport, &next_loopid); |
Joe Carnuccio | e452ceb | 2013-02-08 01:57:56 -0500 | [diff] [blame] | 3331 | |
| 3332 | list_move_tail(&fcport->list, &vha->vp_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3333 | } |
| 3334 | } while (0); |
| 3335 | |
Joe Carnuccio | e452ceb | 2013-02-08 01:57:56 -0500 | [diff] [blame] | 3336 | /* Free all new device structures not processed. */ |
| 3337 | list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) { |
| 3338 | list_del(&fcport->list); |
| 3339 | kfree(fcport); |
| 3340 | } |
| 3341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3342 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3343 | ql_dbg(ql_dbg_disc, vha, 0x2068, |
| 3344 | "Configure fabric error exit rval=%d.\n", rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3345 | } |
| 3346 | |
| 3347 | return (rval); |
| 3348 | } |
| 3349 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | /* |
| 3351 | * qla2x00_find_all_fabric_devs |
| 3352 | * |
| 3353 | * Input: |
| 3354 | * ha = adapter block pointer. |
| 3355 | * dev = database device entry pointer. |
| 3356 | * |
| 3357 | * Returns: |
| 3358 | * 0 = success. |
| 3359 | * |
| 3360 | * Context: |
| 3361 | * Kernel context. |
| 3362 | */ |
| 3363 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3364 | qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha, |
| 3365 | struct list_head *new_fcports) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3366 | { |
| 3367 | int rval; |
| 3368 | uint16_t loop_id; |
| 3369 | fc_port_t *fcport, *new_fcport, *fcptemp; |
| 3370 | int found; |
| 3371 | |
| 3372 | sw_info_t *swl; |
| 3373 | int swl_idx; |
| 3374 | int first_dev, last_dev; |
Mike Waychison | 1516ef4 | 2010-05-04 15:01:31 -0700 | [diff] [blame] | 3375 | port_id_t wrap = {}, nxt_d_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3376 | struct qla_hw_data *ha = vha->hw; |
Chad Dupuis | bb4cf5b | 2013-02-08 01:58:01 -0500 | [diff] [blame] | 3377 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3378 | |
| 3379 | rval = QLA_SUCCESS; |
| 3380 | |
| 3381 | /* Try GID_PT to get device list, else GAN. */ |
Andrew Vasquez | 7a67735 | 2012-02-09 11:15:56 -0800 | [diff] [blame] | 3382 | if (!ha->swl) |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 3383 | ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t), |
Andrew Vasquez | 7a67735 | 2012-02-09 11:15:56 -0800 | [diff] [blame] | 3384 | GFP_KERNEL); |
| 3385 | swl = ha->swl; |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 3386 | if (!swl) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3387 | /*EMPTY*/ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3388 | ql_dbg(ql_dbg_disc, vha, 0x2054, |
| 3389 | "GID_PT allocations failed, fallback on GA_NXT.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3390 | } else { |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 3391 | memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3392 | if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3393 | swl = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3394 | } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3395 | swl = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3396 | } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3397 | swl = NULL; |
Andrew Vasquez | e5896bd | 2008-07-10 16:55:52 -0700 | [diff] [blame] | 3398 | } else if (ql2xiidmaenable && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3399 | qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) { |
| 3400 | qla2x00_gpsc(vha, swl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3401 | } |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3402 | |
| 3403 | /* If other queries succeeded probe for FC-4 type */ |
| 3404 | if (swl) |
| 3405 | qla2x00_gff_id(vha, swl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3406 | } |
| 3407 | swl_idx = 0; |
| 3408 | |
| 3409 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3410 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3411 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3412 | ql_log(ql_log_warn, vha, 0x205e, |
| 3413 | "Failed to allocate memory for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3414 | return (QLA_MEMORY_ALLOC_FAILED); |
| 3415 | } |
| 3416 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3417 | /* Set start port ID scan at adapter ID. */ |
| 3418 | first_dev = 1; |
| 3419 | last_dev = 0; |
| 3420 | |
| 3421 | /* Starting free loop ID. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3422 | loop_id = ha->min_external_loopid; |
| 3423 | for (; loop_id <= ha->max_loop_id; loop_id++) { |
| 3424 | if (qla2x00_is_reserved_id(vha, loop_id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3425 | continue; |
| 3426 | |
Giridhar Malavali | 3a6478d | 2010-05-28 15:08:20 -0700 | [diff] [blame] | 3427 | if (ha->current_topology == ISP_CFG_FL && |
| 3428 | (atomic_read(&vha->loop_down_timer) || |
| 3429 | LOOP_TRANSITION(vha))) { |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 3430 | atomic_set(&vha->loop_down_timer, 0); |
| 3431 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 3432 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3433 | break; |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 3434 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3435 | |
| 3436 | if (swl != NULL) { |
| 3437 | if (last_dev) { |
| 3438 | wrap.b24 = new_fcport->d_id.b24; |
| 3439 | } else { |
| 3440 | new_fcport->d_id.b24 = swl[swl_idx].d_id.b24; |
| 3441 | memcpy(new_fcport->node_name, |
| 3442 | swl[swl_idx].node_name, WWN_SIZE); |
| 3443 | memcpy(new_fcport->port_name, |
| 3444 | swl[swl_idx].port_name, WWN_SIZE); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3445 | memcpy(new_fcport->fabric_port_name, |
| 3446 | swl[swl_idx].fabric_port_name, WWN_SIZE); |
| 3447 | new_fcport->fp_speed = swl[swl_idx].fp_speed; |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3448 | new_fcport->fc4_type = swl[swl_idx].fc4_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3449 | |
| 3450 | if (swl[swl_idx].d_id.b.rsvd_1 != 0) { |
| 3451 | last_dev = 1; |
| 3452 | } |
| 3453 | swl_idx++; |
| 3454 | } |
| 3455 | } else { |
| 3456 | /* Send GA_NXT to the switch */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3457 | rval = qla2x00_ga_nxt(vha, new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3458 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3459 | ql_log(ql_log_warn, vha, 0x2064, |
| 3460 | "SNS scan failed -- assuming " |
| 3461 | "zero-entry result.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3462 | list_for_each_entry_safe(fcport, fcptemp, |
| 3463 | new_fcports, list) { |
| 3464 | list_del(&fcport->list); |
| 3465 | kfree(fcport); |
| 3466 | } |
| 3467 | rval = QLA_SUCCESS; |
| 3468 | break; |
| 3469 | } |
| 3470 | } |
| 3471 | |
| 3472 | /* If wrap on switch device list, exit. */ |
| 3473 | if (first_dev) { |
| 3474 | wrap.b24 = new_fcport->d_id.b24; |
| 3475 | first_dev = 0; |
| 3476 | } else if (new_fcport->d_id.b24 == wrap.b24) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3477 | ql_dbg(ql_dbg_disc, vha, 0x2065, |
| 3478 | "Device wrap (%02x%02x%02x).\n", |
| 3479 | new_fcport->d_id.b.domain, |
| 3480 | new_fcport->d_id.b.area, |
| 3481 | new_fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3482 | break; |
| 3483 | } |
| 3484 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3485 | /* Bypass if same physical adapter. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3486 | if (new_fcport->d_id.b24 == base_vha->d_id.b24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3487 | continue; |
| 3488 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3489 | /* Bypass virtual ports of the same host. */ |
Chad Dupuis | bb4cf5b | 2013-02-08 01:58:01 -0500 | [diff] [blame] | 3490 | if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24)) |
| 3491 | continue; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3492 | |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 3493 | /* Bypass if same domain and area of adapter. */ |
| 3494 | if (((new_fcport->d_id.b24 & 0xffff00) == |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3495 | (vha->d_id.b24 & 0xffff00)) && ha->current_topology == |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 3496 | ISP_CFG_FL) |
| 3497 | continue; |
| 3498 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3499 | /* Bypass reserved domain fields. */ |
| 3500 | if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0) |
| 3501 | continue; |
| 3502 | |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3503 | /* Bypass ports whose FCP-4 type is not FCP_SCSI */ |
Chad Dupuis | 4da26e1 | 2010-10-15 11:27:40 -0700 | [diff] [blame] | 3504 | if (ql2xgffidenable && |
| 3505 | (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI && |
| 3506 | new_fcport->fc4_type != FC4_TYPE_UNKNOWN)) |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3507 | continue; |
| 3508 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3509 | /* Locate matching device in database. */ |
| 3510 | found = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3511 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3512 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 3513 | WWN_SIZE)) |
| 3514 | continue; |
| 3515 | |
Joe Carnuccio | 827210b | 2013-02-08 01:57:57 -0500 | [diff] [blame] | 3516 | fcport->scan_state = QLA_FCPORT_FOUND; |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 3517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3518 | found++; |
| 3519 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3520 | /* Update port state. */ |
| 3521 | memcpy(fcport->fabric_port_name, |
| 3522 | new_fcport->fabric_port_name, WWN_SIZE); |
| 3523 | fcport->fp_speed = new_fcport->fp_speed; |
| 3524 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3525 | /* |
| 3526 | * If address the same and state FCS_ONLINE, nothing |
| 3527 | * changed. |
| 3528 | */ |
| 3529 | if (fcport->d_id.b24 == new_fcport->d_id.b24 && |
| 3530 | atomic_read(&fcport->state) == FCS_ONLINE) { |
| 3531 | break; |
| 3532 | } |
| 3533 | |
| 3534 | /* |
| 3535 | * If device was not a fabric device before. |
| 3536 | */ |
| 3537 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 3538 | fcport->d_id.b24 = new_fcport->d_id.b24; |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3539 | qla2x00_clear_loop_id(fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3540 | fcport->flags |= (FCF_FABRIC_DEVICE | |
| 3541 | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3542 | break; |
| 3543 | } |
| 3544 | |
| 3545 | /* |
| 3546 | * Port ID changed or device was marked to be updated; |
| 3547 | * Log it out if still logged in and mark it for |
| 3548 | * relogin later. |
| 3549 | */ |
| 3550 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 3551 | fcport->flags |= FCF_LOGIN_NEEDED; |
| 3552 | if (fcport->loop_id != FC_NO_LOOP_ID && |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3553 | (fcport->flags & FCF_FCP2_DEVICE) == 0 && |
Arun Easi | 0eba25d | 2012-02-09 11:15:58 -0800 | [diff] [blame] | 3554 | (fcport->flags & FCF_ASYNC_SENT) == 0 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3555 | fcport->port_type != FCT_INITIATOR && |
| 3556 | fcport->port_type != FCT_BROADCAST) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3557 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3558 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3559 | fcport->d_id.b.al_pa); |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3560 | qla2x00_clear_loop_id(fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3561 | } |
| 3562 | |
| 3563 | break; |
| 3564 | } |
| 3565 | |
| 3566 | if (found) |
| 3567 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3568 | /* If device was not in our fcports list, then add it. */ |
| 3569 | list_add_tail(&new_fcport->list, new_fcports); |
| 3570 | |
| 3571 | /* Allocate a new replacement fcport. */ |
| 3572 | nxt_d_id.b24 = new_fcport->d_id.b24; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3573 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3574 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3575 | ql_log(ql_log_warn, vha, 0x2066, |
| 3576 | "Memory allocation failed for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3577 | return (QLA_MEMORY_ALLOC_FAILED); |
| 3578 | } |
| 3579 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
| 3580 | new_fcport->d_id.b24 = nxt_d_id.b24; |
| 3581 | } |
| 3582 | |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 3583 | kfree(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3584 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | return (rval); |
| 3586 | } |
| 3587 | |
| 3588 | /* |
| 3589 | * qla2x00_find_new_loop_id |
| 3590 | * Scan through our port list and find a new usable loop ID. |
| 3591 | * |
| 3592 | * Input: |
| 3593 | * ha: adapter state pointer. |
| 3594 | * dev: port structure pointer. |
| 3595 | * |
| 3596 | * Returns: |
| 3597 | * qla2x00 local function return status code. |
| 3598 | * |
| 3599 | * Context: |
| 3600 | * Kernel context. |
| 3601 | */ |
Joe Carnuccio | 03bcfb5 | 2011-03-30 11:46:27 -0700 | [diff] [blame] | 3602 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3603 | 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] | 3604 | { |
| 3605 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3606 | struct qla_hw_data *ha = vha->hw; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3607 | unsigned long flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3608 | |
| 3609 | rval = QLA_SUCCESS; |
| 3610 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3611 | spin_lock_irqsave(&ha->vport_slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3612 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3613 | dev->loop_id = find_first_zero_bit(ha->loop_id_map, |
| 3614 | LOOPID_MAP_SIZE); |
| 3615 | if (dev->loop_id >= LOOPID_MAP_SIZE || |
| 3616 | qla2x00_is_reserved_id(vha, dev->loop_id)) { |
| 3617 | dev->loop_id = FC_NO_LOOP_ID; |
| 3618 | rval = QLA_FUNCTION_FAILED; |
| 3619 | } else |
| 3620 | set_bit(dev->loop_id, ha->loop_id_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3621 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3622 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3623 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3624 | if (rval == QLA_SUCCESS) |
| 3625 | ql_dbg(ql_dbg_disc, dev->vha, 0x2086, |
| 3626 | "Assigning new loopid=%x, portid=%x.\n", |
| 3627 | dev->loop_id, dev->d_id.b24); |
| 3628 | else |
| 3629 | ql_log(ql_log_warn, dev->vha, 0x2087, |
| 3630 | "No loop_id's available, portid=%x.\n", |
| 3631 | dev->d_id.b24); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3632 | |
| 3633 | return (rval); |
| 3634 | } |
| 3635 | |
| 3636 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3637 | * qla2x00_fabric_dev_login |
| 3638 | * Login fabric target device and update FC port database. |
| 3639 | * |
| 3640 | * Input: |
| 3641 | * ha: adapter state pointer. |
| 3642 | * fcport: port structure list pointer. |
| 3643 | * next_loopid: contains value of a new loop ID that can be used |
| 3644 | * by the next login attempt. |
| 3645 | * |
| 3646 | * Returns: |
| 3647 | * qla2x00 local function return status code. |
| 3648 | * |
| 3649 | * Context: |
| 3650 | * Kernel context. |
| 3651 | */ |
| 3652 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3653 | qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3654 | uint16_t *next_loopid) |
| 3655 | { |
| 3656 | int rval; |
| 3657 | int retry; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3658 | uint8_t opts; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3659 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3660 | |
| 3661 | rval = QLA_SUCCESS; |
| 3662 | retry = 0; |
| 3663 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3664 | if (IS_ALOGIO_CAPABLE(ha)) { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 3665 | if (fcport->flags & FCF_ASYNC_SENT) |
| 3666 | return rval; |
| 3667 | fcport->flags |= FCF_ASYNC_SENT; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3668 | rval = qla2x00_post_async_login_work(vha, fcport, NULL); |
| 3669 | if (!rval) |
| 3670 | return rval; |
| 3671 | } |
| 3672 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 3673 | fcport->flags &= ~FCF_ASYNC_SENT; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3674 | rval = qla2x00_fabric_login(vha, fcport, next_loopid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3675 | if (rval == QLA_SUCCESS) { |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3676 | /* Send an ADISC to FCP2 devices.*/ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3677 | opts = 0; |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3678 | if (fcport->flags & FCF_FCP2_DEVICE) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3679 | opts |= BIT_1; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3680 | rval = qla2x00_get_port_database(vha, fcport, opts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3681 | if (rval != QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3682 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3683 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3684 | fcport->d_id.b.al_pa); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3685 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3686 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3687 | qla2x00_update_fcport(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3688 | } |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 3689 | } else { |
| 3690 | /* Retry Login. */ |
| 3691 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3692 | } |
| 3693 | |
| 3694 | return (rval); |
| 3695 | } |
| 3696 | |
| 3697 | /* |
| 3698 | * qla2x00_fabric_login |
| 3699 | * Issue fabric login command. |
| 3700 | * |
| 3701 | * Input: |
| 3702 | * ha = adapter block pointer. |
| 3703 | * device = pointer to FC device type structure. |
| 3704 | * |
| 3705 | * Returns: |
| 3706 | * 0 - Login successfully |
| 3707 | * 1 - Login failed |
| 3708 | * 2 - Initiator device |
| 3709 | * 3 - Fatal error |
| 3710 | */ |
| 3711 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3712 | qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3713 | uint16_t *next_loopid) |
| 3714 | { |
| 3715 | int rval; |
| 3716 | int retry; |
| 3717 | uint16_t tmp_loopid; |
| 3718 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3719 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3720 | |
| 3721 | retry = 0; |
| 3722 | tmp_loopid = 0; |
| 3723 | |
| 3724 | for (;;) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3725 | ql_dbg(ql_dbg_disc, vha, 0x2000, |
| 3726 | "Trying Fabric Login w/loop id 0x%04x for port " |
| 3727 | "%02x%02x%02x.\n", |
| 3728 | fcport->loop_id, fcport->d_id.b.domain, |
| 3729 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3730 | |
| 3731 | /* Login fcport on switch. */ |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 3732 | rval = ha->isp_ops->fabric_login(vha, fcport->loop_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3733 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3734 | fcport->d_id.b.al_pa, mb, BIT_0); |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 3735 | if (rval != QLA_SUCCESS) { |
| 3736 | return rval; |
| 3737 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3738 | if (mb[0] == MBS_PORT_ID_USED) { |
| 3739 | /* |
| 3740 | * Device has another loop ID. The firmware team |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3741 | * recommends the driver perform an implicit login with |
| 3742 | * the specified ID again. The ID we just used is save |
| 3743 | * here so we return with an ID that can be tried by |
| 3744 | * the next login. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3745 | */ |
| 3746 | retry++; |
| 3747 | tmp_loopid = fcport->loop_id; |
| 3748 | fcport->loop_id = mb[1]; |
| 3749 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3750 | ql_dbg(ql_dbg_disc, vha, 0x2001, |
| 3751 | "Fabric Login: port in use - next loop " |
| 3752 | "id=0x%04x, port id= %02x%02x%02x.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3753 | fcport->loop_id, fcport->d_id.b.domain, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3754 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3755 | |
| 3756 | } else if (mb[0] == MBS_COMMAND_COMPLETE) { |
| 3757 | /* |
| 3758 | * Login succeeded. |
| 3759 | */ |
| 3760 | if (retry) { |
| 3761 | /* A retry occurred before. */ |
| 3762 | *next_loopid = tmp_loopid; |
| 3763 | } else { |
| 3764 | /* |
| 3765 | * No retry occurred before. Just increment the |
| 3766 | * ID value for next login. |
| 3767 | */ |
| 3768 | *next_loopid = (fcport->loop_id + 1); |
| 3769 | } |
| 3770 | |
| 3771 | if (mb[1] & BIT_0) { |
| 3772 | fcport->port_type = FCT_INITIATOR; |
| 3773 | } else { |
| 3774 | fcport->port_type = FCT_TARGET; |
| 3775 | if (mb[1] & BIT_1) { |
Santosh Vernekar | 8474f3a | 2009-08-25 11:36:16 -0700 | [diff] [blame] | 3776 | fcport->flags |= FCF_FCP2_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3777 | } |
| 3778 | } |
| 3779 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 3780 | if (mb[10] & BIT_0) |
| 3781 | fcport->supported_classes |= FC_COS_CLASS2; |
| 3782 | if (mb[10] & BIT_1) |
| 3783 | fcport->supported_classes |= FC_COS_CLASS3; |
| 3784 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3785 | if (IS_FWI2_CAPABLE(ha)) { |
| 3786 | if (mb[10] & BIT_7) |
| 3787 | fcport->flags |= |
| 3788 | FCF_CONF_COMP_SUPPORTED; |
| 3789 | } |
| 3790 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3791 | rval = QLA_SUCCESS; |
| 3792 | break; |
| 3793 | } else if (mb[0] == MBS_LOOP_ID_USED) { |
| 3794 | /* |
| 3795 | * Loop ID already used, try next loop ID. |
| 3796 | */ |
| 3797 | fcport->loop_id++; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3798 | rval = qla2x00_find_new_loop_id(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3799 | if (rval != QLA_SUCCESS) { |
| 3800 | /* Ran out of loop IDs to use */ |
| 3801 | break; |
| 3802 | } |
| 3803 | } else if (mb[0] == MBS_COMMAND_ERROR) { |
| 3804 | /* |
| 3805 | * Firmware possibly timed out during login. If NO |
| 3806 | * retries are left to do then the device is declared |
| 3807 | * dead. |
| 3808 | */ |
| 3809 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3810 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3811 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3812 | fcport->d_id.b.al_pa); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3813 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3814 | |
| 3815 | rval = 1; |
| 3816 | break; |
| 3817 | } else { |
| 3818 | /* |
| 3819 | * unrecoverable / not handled error |
| 3820 | */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3821 | ql_dbg(ql_dbg_disc, vha, 0x2002, |
| 3822 | "Failed=%x port_id=%02x%02x%02x loop_id=%x " |
| 3823 | "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain, |
| 3824 | fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 3825 | fcport->loop_id, jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3826 | |
| 3827 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3828 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3829 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3830 | fcport->d_id.b.al_pa); |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3831 | qla2x00_clear_loop_id(fcport); |
Andrew Vasquez | 0eedfcf | 2005-10-27 11:09:38 -0700 | [diff] [blame] | 3832 | fcport->login_retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3833 | |
| 3834 | rval = 3; |
| 3835 | break; |
| 3836 | } |
| 3837 | } |
| 3838 | |
| 3839 | return (rval); |
| 3840 | } |
| 3841 | |
| 3842 | /* |
| 3843 | * qla2x00_local_device_login |
| 3844 | * Issue local device login command. |
| 3845 | * |
| 3846 | * Input: |
| 3847 | * ha = adapter block pointer. |
| 3848 | * loop_id = loop id of device to login to. |
| 3849 | * |
| 3850 | * Returns (Where's the #define!!!!): |
| 3851 | * 0 - Login successfully |
| 3852 | * 1 - Login failed |
| 3853 | * 3 - Fatal error |
| 3854 | */ |
| 3855 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3856 | 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] | 3857 | { |
| 3858 | int rval; |
| 3859 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
| 3860 | |
| 3861 | memset(mb, 0, sizeof(mb)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3862 | rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3863 | if (rval == QLA_SUCCESS) { |
| 3864 | /* Interrogate mailbox registers for any errors */ |
| 3865 | if (mb[0] == MBS_COMMAND_ERROR) |
| 3866 | rval = 1; |
| 3867 | else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR) |
| 3868 | /* device not in PCB table */ |
| 3869 | rval = 3; |
| 3870 | } |
| 3871 | |
| 3872 | return (rval); |
| 3873 | } |
| 3874 | |
| 3875 | /* |
| 3876 | * qla2x00_loop_resync |
| 3877 | * Resync with fibre channel devices. |
| 3878 | * |
| 3879 | * Input: |
| 3880 | * ha = adapter block pointer. |
| 3881 | * |
| 3882 | * Returns: |
| 3883 | * 0 = success |
| 3884 | */ |
| 3885 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3886 | qla2x00_loop_resync(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3887 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3888 | int rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3889 | uint32_t wait_time; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 3890 | struct req_que *req; |
| 3891 | struct rsp_que *rsp; |
| 3892 | |
Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 3893 | if (vha->hw->flags.cpu_affinity_enabled) |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 3894 | req = vha->hw->req_q_map[0]; |
| 3895 | else |
| 3896 | req = vha->req; |
| 3897 | rsp = req->rsp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3898 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3899 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 3900 | if (vha->flags.online) { |
| 3901 | if (!(rval = qla2x00_fw_ready(vha))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3902 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 3903 | wait_time = 256; |
| 3904 | do { |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3905 | if (!IS_QLAFX00(vha->hw)) { |
| 3906 | /* |
| 3907 | * Issue a marker after FW becomes |
| 3908 | * ready. |
| 3909 | */ |
| 3910 | qla2x00_marker(vha, req, rsp, 0, 0, |
| 3911 | MK_SYNC_ALL); |
| 3912 | vha->marker_needed = 0; |
| 3913 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3914 | |
| 3915 | /* Remap devices on Loop. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3916 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3917 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3918 | if (IS_QLAFX00(vha->hw)) |
| 3919 | qlafx00_configure_devices(vha); |
| 3920 | else |
| 3921 | qla2x00_configure_loop(vha); |
| 3922 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3923 | wait_time--; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3924 | } while (!atomic_read(&vha->loop_down_timer) && |
| 3925 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
| 3926 | && wait_time && (test_bit(LOOP_RESYNC_NEEDED, |
| 3927 | &vha->dpc_flags))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3928 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3929 | } |
| 3930 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3931 | if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3932 | return (QLA_FUNCTION_FAILED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3933 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3934 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3935 | ql_dbg(ql_dbg_disc, vha, 0x206c, |
| 3936 | "%s *** FAILED ***.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3937 | |
| 3938 | return (rval); |
| 3939 | } |
| 3940 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 3941 | /* |
| 3942 | * qla2x00_perform_loop_resync |
| 3943 | * Description: This function will set the appropriate flags and call |
| 3944 | * qla2x00_loop_resync. If successful loop will be resynced |
| 3945 | * Arguments : scsi_qla_host_t pointer |
| 3946 | * returm : Success or Failure |
| 3947 | */ |
| 3948 | |
| 3949 | int qla2x00_perform_loop_resync(scsi_qla_host_t *ha) |
| 3950 | { |
| 3951 | int32_t rval = 0; |
| 3952 | |
| 3953 | if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) { |
| 3954 | /*Configure the flags so that resync happens properly*/ |
| 3955 | atomic_set(&ha->loop_down_timer, 0); |
| 3956 | if (!(ha->device_flags & DFLG_NO_CABLE)) { |
| 3957 | atomic_set(&ha->loop_state, LOOP_UP); |
| 3958 | set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); |
| 3959 | set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags); |
| 3960 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
| 3961 | |
| 3962 | rval = qla2x00_loop_resync(ha); |
| 3963 | } else |
| 3964 | atomic_set(&ha->loop_state, LOOP_DEAD); |
| 3965 | |
| 3966 | clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags); |
| 3967 | } |
| 3968 | |
| 3969 | return rval; |
| 3970 | } |
| 3971 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3972 | void |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 3973 | qla2x00_update_fcports(scsi_qla_host_t *base_vha) |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3974 | { |
| 3975 | fc_port_t *fcport; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3976 | struct scsi_qla_host *vha; |
| 3977 | struct qla_hw_data *ha = base_vha->hw; |
| 3978 | unsigned long flags; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3979 | |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3980 | spin_lock_irqsave(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3981 | /* Go with deferred removal of rport references. */ |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3982 | list_for_each_entry(vha, &base_vha->hw->vp_list, list) { |
| 3983 | atomic_inc(&vha->vref_count); |
| 3984 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Dan Carpenter | 8ae598d | 2010-12-21 16:00:15 -0800 | [diff] [blame] | 3985 | if (fcport->drport && |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3986 | atomic_read(&fcport->state) != FCS_UNCONFIGURED) { |
| 3987 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 3988 | qla2x00_rport_del(fcport); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3989 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 3990 | } |
| 3991 | } |
| 3992 | atomic_dec(&vha->vref_count); |
| 3993 | } |
| 3994 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3995 | } |
| 3996 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 3997 | /* Assumes idc_lock always held on entry */ |
| 3998 | void |
| 3999 | qla83xx_reset_ownership(scsi_qla_host_t *vha) |
| 4000 | { |
| 4001 | struct qla_hw_data *ha = vha->hw; |
| 4002 | uint32_t drv_presence, drv_presence_mask; |
| 4003 | uint32_t dev_part_info1, dev_part_info2, class_type; |
| 4004 | uint32_t class_type_mask = 0x3; |
| 4005 | uint16_t fcoe_other_function = 0xffff, i; |
| 4006 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame^] | 4007 | if (IS_QLA8044(ha)) { |
| 4008 | drv_presence = qla8044_rd_direct(vha, |
| 4009 | QLA8044_CRB_DRV_ACTIVE_INDEX); |
| 4010 | dev_part_info1 = qla8044_rd_direct(vha, |
| 4011 | QLA8044_CRB_DEV_PART_INFO_INDEX); |
| 4012 | dev_part_info2 = qla8044_rd_direct(vha, |
| 4013 | QLA8044_CRB_DEV_PART_INFO2); |
| 4014 | } else { |
| 4015 | qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); |
| 4016 | qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1); |
| 4017 | qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2); |
| 4018 | } |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 4019 | for (i = 0; i < 8; i++) { |
| 4020 | class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask); |
| 4021 | if ((class_type == QLA83XX_CLASS_TYPE_FCOE) && |
| 4022 | (i != ha->portnum)) { |
| 4023 | fcoe_other_function = i; |
| 4024 | break; |
| 4025 | } |
| 4026 | } |
| 4027 | if (fcoe_other_function == 0xffff) { |
| 4028 | for (i = 0; i < 8; i++) { |
| 4029 | class_type = ((dev_part_info2 >> (i * 4)) & |
| 4030 | class_type_mask); |
| 4031 | if ((class_type == QLA83XX_CLASS_TYPE_FCOE) && |
| 4032 | ((i + 8) != ha->portnum)) { |
| 4033 | fcoe_other_function = i + 8; |
| 4034 | break; |
| 4035 | } |
| 4036 | } |
| 4037 | } |
| 4038 | /* |
| 4039 | * Prepare drv-presence mask based on fcoe functions present. |
| 4040 | * However consider only valid physical fcoe function numbers (0-15). |
| 4041 | */ |
| 4042 | drv_presence_mask = ~((1 << (ha->portnum)) | |
| 4043 | ((fcoe_other_function == 0xffff) ? |
| 4044 | 0 : (1 << (fcoe_other_function)))); |
| 4045 | |
| 4046 | /* We are the reset owner iff: |
| 4047 | * - No other protocol drivers present. |
| 4048 | * - This is the lowest among fcoe functions. */ |
| 4049 | if (!(drv_presence & drv_presence_mask) && |
| 4050 | (ha->portnum < fcoe_other_function)) { |
| 4051 | ql_dbg(ql_dbg_p3p, vha, 0xb07f, |
| 4052 | "This host is Reset owner.\n"); |
| 4053 | ha->flags.nic_core_reset_owner = 1; |
| 4054 | } |
| 4055 | } |
| 4056 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 4057 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 4058 | __qla83xx_set_drv_ack(scsi_qla_host_t *vha) |
| 4059 | { |
| 4060 | int rval = QLA_SUCCESS; |
| 4061 | struct qla_hw_data *ha = vha->hw; |
| 4062 | uint32_t drv_ack; |
| 4063 | |
| 4064 | rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack); |
| 4065 | if (rval == QLA_SUCCESS) { |
| 4066 | drv_ack |= (1 << ha->portnum); |
| 4067 | rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack); |
| 4068 | } |
| 4069 | |
| 4070 | return rval; |
| 4071 | } |
| 4072 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 4073 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 4074 | __qla83xx_clear_drv_ack(scsi_qla_host_t *vha) |
| 4075 | { |
| 4076 | int rval = QLA_SUCCESS; |
| 4077 | struct qla_hw_data *ha = vha->hw; |
| 4078 | uint32_t drv_ack; |
| 4079 | |
| 4080 | rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack); |
| 4081 | if (rval == QLA_SUCCESS) { |
| 4082 | drv_ack &= ~(1 << ha->portnum); |
| 4083 | rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack); |
| 4084 | } |
| 4085 | |
| 4086 | return rval; |
| 4087 | } |
| 4088 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 4089 | static const char * |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 4090 | qla83xx_dev_state_to_string(uint32_t dev_state) |
| 4091 | { |
| 4092 | switch (dev_state) { |
| 4093 | case QLA8XXX_DEV_COLD: |
| 4094 | return "COLD/RE-INIT"; |
| 4095 | case QLA8XXX_DEV_INITIALIZING: |
| 4096 | return "INITIALIZING"; |
| 4097 | case QLA8XXX_DEV_READY: |
| 4098 | return "READY"; |
| 4099 | case QLA8XXX_DEV_NEED_RESET: |
| 4100 | return "NEED RESET"; |
| 4101 | case QLA8XXX_DEV_NEED_QUIESCENT: |
| 4102 | return "NEED QUIESCENT"; |
| 4103 | case QLA8XXX_DEV_FAILED: |
| 4104 | return "FAILED"; |
| 4105 | case QLA8XXX_DEV_QUIESCENT: |
| 4106 | return "QUIESCENT"; |
| 4107 | default: |
| 4108 | return "Unknown"; |
| 4109 | } |
| 4110 | } |
| 4111 | |
| 4112 | /* Assumes idc-lock always held on entry */ |
| 4113 | void |
| 4114 | qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type) |
| 4115 | { |
| 4116 | struct qla_hw_data *ha = vha->hw; |
| 4117 | uint32_t idc_audit_reg = 0, duration_secs = 0; |
| 4118 | |
| 4119 | switch (audit_type) { |
| 4120 | case IDC_AUDIT_TIMESTAMP: |
| 4121 | ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000); |
| 4122 | idc_audit_reg = (ha->portnum) | |
| 4123 | (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8); |
| 4124 | qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg); |
| 4125 | break; |
| 4126 | |
| 4127 | case IDC_AUDIT_COMPLETION: |
| 4128 | duration_secs = ((jiffies_to_msecs(jiffies) - |
| 4129 | jiffies_to_msecs(ha->idc_audit_ts)) / 1000); |
| 4130 | idc_audit_reg = (ha->portnum) | |
| 4131 | (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8); |
| 4132 | qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg); |
| 4133 | break; |
| 4134 | |
| 4135 | default: |
| 4136 | ql_log(ql_log_warn, vha, 0xb078, |
| 4137 | "Invalid audit type specified.\n"); |
| 4138 | break; |
| 4139 | } |
| 4140 | } |
| 4141 | |
| 4142 | /* Assumes idc_lock always held on entry */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 4143 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 4144 | qla83xx_initiating_reset(scsi_qla_host_t *vha) |
| 4145 | { |
| 4146 | struct qla_hw_data *ha = vha->hw; |
| 4147 | uint32_t idc_control, dev_state; |
| 4148 | |
| 4149 | __qla83xx_get_idc_control(vha, &idc_control); |
| 4150 | if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) { |
| 4151 | ql_log(ql_log_info, vha, 0xb080, |
| 4152 | "NIC Core reset has been disabled. idc-control=0x%x\n", |
| 4153 | idc_control); |
| 4154 | return QLA_FUNCTION_FAILED; |
| 4155 | } |
| 4156 | |
| 4157 | /* Set NEED-RESET iff in READY state and we are the reset-owner */ |
| 4158 | qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state); |
| 4159 | if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) { |
| 4160 | qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, |
| 4161 | QLA8XXX_DEV_NEED_RESET); |
| 4162 | ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n"); |
| 4163 | qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP); |
| 4164 | } else { |
| 4165 | const char *state = qla83xx_dev_state_to_string(dev_state); |
| 4166 | ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state); |
| 4167 | |
| 4168 | /* SV: XXX: Is timeout required here? */ |
| 4169 | /* Wait for IDC state change READY -> NEED_RESET */ |
| 4170 | while (dev_state == QLA8XXX_DEV_READY) { |
| 4171 | qla83xx_idc_unlock(vha, 0); |
| 4172 | msleep(200); |
| 4173 | qla83xx_idc_lock(vha, 0); |
| 4174 | qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state); |
| 4175 | } |
| 4176 | } |
| 4177 | |
| 4178 | /* Send IDC ack by writing to drv-ack register */ |
| 4179 | __qla83xx_set_drv_ack(vha); |
| 4180 | |
| 4181 | return QLA_SUCCESS; |
| 4182 | } |
| 4183 | |
| 4184 | int |
| 4185 | __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control) |
| 4186 | { |
| 4187 | return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control); |
| 4188 | } |
| 4189 | |
| 4190 | int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 4191 | __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control) |
| 4192 | { |
| 4193 | return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control); |
| 4194 | } |
| 4195 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 4196 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 4197 | qla83xx_check_driver_presence(scsi_qla_host_t *vha) |
| 4198 | { |
| 4199 | uint32_t drv_presence = 0; |
| 4200 | struct qla_hw_data *ha = vha->hw; |
| 4201 | |
| 4202 | qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); |
| 4203 | if (drv_presence & (1 << ha->portnum)) |
| 4204 | return QLA_SUCCESS; |
| 4205 | else |
| 4206 | return QLA_TEST_FAILED; |
| 4207 | } |
| 4208 | |
| 4209 | int |
| 4210 | qla83xx_nic_core_reset(scsi_qla_host_t *vha) |
| 4211 | { |
| 4212 | int rval = QLA_SUCCESS; |
| 4213 | struct qla_hw_data *ha = vha->hw; |
| 4214 | |
| 4215 | ql_dbg(ql_dbg_p3p, vha, 0xb058, |
| 4216 | "Entered %s().\n", __func__); |
| 4217 | |
| 4218 | if (vha->device_flags & DFLG_DEV_FAILED) { |
| 4219 | ql_log(ql_log_warn, vha, 0xb059, |
| 4220 | "Device in unrecoverable FAILED state.\n"); |
| 4221 | return QLA_FUNCTION_FAILED; |
| 4222 | } |
| 4223 | |
| 4224 | qla83xx_idc_lock(vha, 0); |
| 4225 | |
| 4226 | if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) { |
| 4227 | ql_log(ql_log_warn, vha, 0xb05a, |
| 4228 | "Function=0x%x has been removed from IDC participation.\n", |
| 4229 | ha->portnum); |
| 4230 | rval = QLA_FUNCTION_FAILED; |
| 4231 | goto exit; |
| 4232 | } |
| 4233 | |
| 4234 | qla83xx_reset_ownership(vha); |
| 4235 | |
| 4236 | rval = qla83xx_initiating_reset(vha); |
| 4237 | |
| 4238 | /* |
| 4239 | * Perform reset if we are the reset-owner, |
| 4240 | * else wait till IDC state changes to READY/FAILED. |
| 4241 | */ |
| 4242 | if (rval == QLA_SUCCESS) { |
| 4243 | rval = qla83xx_idc_state_handler(vha); |
| 4244 | |
| 4245 | if (rval == QLA_SUCCESS) |
| 4246 | ha->flags.nic_core_hung = 0; |
| 4247 | __qla83xx_clear_drv_ack(vha); |
| 4248 | } |
| 4249 | |
| 4250 | exit: |
| 4251 | qla83xx_idc_unlock(vha, 0); |
| 4252 | |
| 4253 | ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__); |
| 4254 | |
| 4255 | return rval; |
| 4256 | } |
| 4257 | |
Saurav Kashyap | 8117877 | 2012-08-22 14:21:04 -0400 | [diff] [blame] | 4258 | int |
| 4259 | qla2xxx_mctp_dump(scsi_qla_host_t *vha) |
| 4260 | { |
| 4261 | struct qla_hw_data *ha = vha->hw; |
| 4262 | int rval = QLA_FUNCTION_FAILED; |
| 4263 | |
| 4264 | if (!IS_MCTP_CAPABLE(ha)) { |
| 4265 | /* This message can be removed from the final version */ |
| 4266 | ql_log(ql_log_info, vha, 0x506d, |
| 4267 | "This board is not MCTP capable\n"); |
| 4268 | return rval; |
| 4269 | } |
| 4270 | |
| 4271 | if (!ha->mctp_dump) { |
| 4272 | ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev, |
| 4273 | MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL); |
| 4274 | |
| 4275 | if (!ha->mctp_dump) { |
| 4276 | ql_log(ql_log_warn, vha, 0x506e, |
| 4277 | "Failed to allocate memory for mctp dump\n"); |
| 4278 | return rval; |
| 4279 | } |
| 4280 | } |
| 4281 | |
| 4282 | #define MCTP_DUMP_STR_ADDR 0x00000000 |
| 4283 | rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma, |
| 4284 | MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4); |
| 4285 | if (rval != QLA_SUCCESS) { |
| 4286 | ql_log(ql_log_warn, vha, 0x506f, |
| 4287 | "Failed to capture mctp dump\n"); |
| 4288 | } else { |
| 4289 | ql_log(ql_log_info, vha, 0x5070, |
| 4290 | "Mctp dump capture for host (%ld/%p).\n", |
| 4291 | vha->host_no, ha->mctp_dump); |
| 4292 | ha->mctp_dumped = 1; |
| 4293 | } |
| 4294 | |
Saurav Kashyap | 409ee0f | 2012-08-22 14:21:29 -0400 | [diff] [blame] | 4295 | if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) { |
Saurav Kashyap | 8117877 | 2012-08-22 14:21:04 -0400 | [diff] [blame] | 4296 | ha->flags.nic_core_reset_hdlr_active = 1; |
| 4297 | rval = qla83xx_restart_nic_firmware(vha); |
| 4298 | if (rval) |
| 4299 | /* NIC Core reset failed. */ |
| 4300 | ql_log(ql_log_warn, vha, 0x5071, |
| 4301 | "Failed to restart nic firmware\n"); |
| 4302 | else |
| 4303 | ql_dbg(ql_dbg_p3p, vha, 0xb084, |
| 4304 | "Restarted NIC firmware successfully.\n"); |
| 4305 | ha->flags.nic_core_reset_hdlr_active = 0; |
| 4306 | } |
| 4307 | |
| 4308 | return rval; |
| 4309 | |
| 4310 | } |
| 4311 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4312 | /* |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 4313 | * qla2x00_quiesce_io |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4314 | * Description: This function will block the new I/Os |
| 4315 | * Its not aborting any I/Os as context |
| 4316 | * is not destroyed during quiescence |
| 4317 | * Arguments: scsi_qla_host_t |
| 4318 | * return : void |
| 4319 | */ |
| 4320 | void |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 4321 | qla2x00_quiesce_io(scsi_qla_host_t *vha) |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4322 | { |
| 4323 | struct qla_hw_data *ha = vha->hw; |
| 4324 | struct scsi_qla_host *vp; |
| 4325 | |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 4326 | ql_dbg(ql_dbg_dpc, vha, 0x401d, |
| 4327 | "Quiescing I/O - ha=%p.\n", ha); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4328 | |
| 4329 | atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); |
| 4330 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 4331 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 4332 | qla2x00_mark_all_devices_lost(vha, 0); |
| 4333 | list_for_each_entry(vp, &ha->vp_list, list) |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 4334 | qla2x00_mark_all_devices_lost(vp, 0); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4335 | } else { |
| 4336 | if (!atomic_read(&vha->loop_down_timer)) |
| 4337 | atomic_set(&vha->loop_down_timer, |
| 4338 | LOOP_DOWN_TIME); |
| 4339 | } |
| 4340 | /* Wait for pending cmds to complete */ |
| 4341 | qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST); |
| 4342 | } |
| 4343 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4344 | void |
| 4345 | qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha) |
| 4346 | { |
| 4347 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4348 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4349 | unsigned long flags; |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 4350 | fc_port_t *fcport; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4351 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 4352 | /* For ISP82XX, driver waits for completion of the commands. |
| 4353 | * online flag should be set. |
| 4354 | */ |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame^] | 4355 | if (!(IS_P3P_TYPE(ha))) |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 4356 | vha->flags.online = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4357 | ha->flags.chip_reset_done = 0; |
| 4358 | clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Saurav Kashyap | 2be21fa | 2012-05-15 14:34:16 -0400 | [diff] [blame] | 4359 | vha->qla_stats.total_isp_aborts++; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4360 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4361 | ql_log(ql_log_info, vha, 0x00af, |
| 4362 | "Performing ISP error recovery - ha=%p.\n", ha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4363 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 4364 | /* For ISP82XX, reset_chip is just disabling interrupts. |
| 4365 | * Driver waits for the completion of the commands. |
| 4366 | * the interrupts need to be enabled. |
| 4367 | */ |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame^] | 4368 | if (!(IS_P3P_TYPE(ha))) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4369 | ha->isp_ops->reset_chip(vha); |
| 4370 | |
| 4371 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 4372 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 4373 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 4374 | qla2x00_mark_all_devices_lost(vha, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4375 | |
| 4376 | spin_lock_irqsave(&ha->vport_slock, flags); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4377 | list_for_each_entry(vp, &ha->vp_list, list) { |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4378 | atomic_inc(&vp->vref_count); |
| 4379 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4380 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4381 | qla2x00_mark_all_devices_lost(vp, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4382 | |
| 4383 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4384 | atomic_dec(&vp->vref_count); |
| 4385 | } |
| 4386 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4387 | } else { |
| 4388 | if (!atomic_read(&vha->loop_down_timer)) |
| 4389 | atomic_set(&vha->loop_down_timer, |
| 4390 | LOOP_DOWN_TIME); |
| 4391 | } |
| 4392 | |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 4393 | /* Clear all async request states across all VPs. */ |
| 4394 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 4395 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 4396 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4397 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 4398 | atomic_inc(&vp->vref_count); |
| 4399 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4400 | |
| 4401 | list_for_each_entry(fcport, &vp->vp_fcports, list) |
| 4402 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 4403 | |
| 4404 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4405 | atomic_dec(&vp->vref_count); |
| 4406 | } |
| 4407 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4408 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 4409 | if (!ha->flags.eeh_busy) { |
| 4410 | /* Make sure for ISP 82XX IO DMA is complete */ |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame^] | 4411 | if (IS_P3P_TYPE(ha)) { |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 4412 | qla82xx_chip_reset_cleanup(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4413 | ql_log(ql_log_info, vha, 0x00b4, |
| 4414 | "Done chip reset cleanup.\n"); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4415 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 4416 | /* Done waiting for pending commands. |
| 4417 | * Reset the online flag. |
| 4418 | */ |
| 4419 | vha->flags.online = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4420 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4421 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 4422 | /* Requeue all commands in outstanding command list. */ |
| 4423 | qla2x00_abort_all_cmds(vha, DID_RESET << 16); |
| 4424 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4425 | } |
| 4426 | |
| 4427 | /* |
| 4428 | * qla2x00_abort_isp |
| 4429 | * Resets ISP and aborts all outstanding commands. |
| 4430 | * |
| 4431 | * Input: |
| 4432 | * ha = adapter block pointer. |
| 4433 | * |
| 4434 | * Returns: |
| 4435 | * 0 = success |
| 4436 | */ |
| 4437 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4438 | qla2x00_abort_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4439 | { |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 4440 | int rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4441 | uint8_t status = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4442 | struct qla_hw_data *ha = vha->hw; |
| 4443 | struct scsi_qla_host *vp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4444 | struct req_que *req = ha->req_q_map[0]; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4445 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4446 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4447 | if (vha->flags.online) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4448 | qla2x00_abort_isp_cleanup(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4449 | |
Santosh Vernekar | a6171297 | 2012-08-22 14:21:13 -0400 | [diff] [blame] | 4450 | if (IS_QLA8031(ha)) { |
| 4451 | ql_dbg(ql_dbg_p3p, vha, 0xb05c, |
| 4452 | "Clearing fcoe driver presence.\n"); |
| 4453 | if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS) |
| 4454 | ql_dbg(ql_dbg_p3p, vha, 0xb073, |
| 4455 | "Error while clearing DRV-Presence.\n"); |
| 4456 | } |
| 4457 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 4458 | if (unlikely(pci_channel_offline(ha->pdev) && |
| 4459 | ha->flags.pci_channel_io_perm_failure)) { |
| 4460 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 4461 | status = 0; |
| 4462 | return status; |
| 4463 | } |
| 4464 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4465 | ha->isp_ops->get_flash_version(vha, req->ring); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 4466 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4467 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4468 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4469 | if (!qla2x00_restart_isp(vha)) { |
| 4470 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4471 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4472 | if (!atomic_read(&vha->loop_down_timer)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4473 | /* |
| 4474 | * Issue marker command only when we are going |
| 4475 | * to start the I/O . |
| 4476 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4477 | vha->marker_needed = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4478 | } |
| 4479 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4480 | vha->flags.online = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4481 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 4482 | ha->isp_ops->enable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4483 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4484 | ha->isp_abort_cnt = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4485 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 4486 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 4487 | if (IS_QLA81XX(ha) || IS_QLA8031(ha)) |
| 4488 | qla2x00_get_fw_version(vha); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 4489 | if (ha->fce) { |
| 4490 | ha->flags.fce_enabled = 1; |
| 4491 | memset(ha->fce, 0, |
| 4492 | fce_calc_size(ha->fce_bufs)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4493 | rval = qla2x00_enable_fce_trace(vha, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 4494 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 4495 | &ha->fce_bufs); |
| 4496 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4497 | ql_log(ql_log_warn, vha, 0x8033, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 4498 | "Unable to reinitialize FCE " |
| 4499 | "(%d).\n", rval); |
| 4500 | ha->flags.fce_enabled = 0; |
| 4501 | } |
| 4502 | } |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 4503 | |
| 4504 | if (ha->eft) { |
| 4505 | memset(ha->eft, 0, EFT_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4506 | rval = qla2x00_enable_eft_trace(vha, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 4507 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 4508 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4509 | ql_log(ql_log_warn, vha, 0x8034, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 4510 | "Unable to reinitialize EFT " |
| 4511 | "(%d).\n", rval); |
| 4512 | } |
| 4513 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4514 | } else { /* failed the ISP abort */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4515 | vha->flags.online = 1; |
| 4516 | if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4517 | if (ha->isp_abort_cnt == 0) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4518 | ql_log(ql_log_fatal, vha, 0x8035, |
| 4519 | "ISP error recover failed - " |
| 4520 | "board disabled.\n"); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4521 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4522 | * The next call disables the board |
| 4523 | * completely. |
| 4524 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4525 | ha->isp_ops->reset_adapter(vha); |
| 4526 | vha->flags.online = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4527 | clear_bit(ISP_ABORT_RETRY, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4528 | &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4529 | status = 0; |
| 4530 | } else { /* schedule another ISP abort */ |
| 4531 | ha->isp_abort_cnt--; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4532 | ql_dbg(ql_dbg_taskm, vha, 0x8020, |
| 4533 | "ISP abort - retry remaining %d.\n", |
| 4534 | ha->isp_abort_cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4535 | status = 1; |
| 4536 | } |
| 4537 | } else { |
| 4538 | ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4539 | ql_dbg(ql_dbg_taskm, vha, 0x8021, |
| 4540 | "ISP error recovery - retrying (%d) " |
| 4541 | "more times.\n", ha->isp_abort_cnt); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4542 | set_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4543 | status = 1; |
| 4544 | } |
| 4545 | } |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4546 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4547 | } |
| 4548 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4549 | if (!status) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4550 | ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4551 | |
| 4552 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4553 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 4554 | if (vp->vp_idx) { |
| 4555 | atomic_inc(&vp->vref_count); |
| 4556 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4557 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4558 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4559 | |
| 4560 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4561 | atomic_dec(&vp->vref_count); |
| 4562 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4563 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4564 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4565 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 4566 | if (IS_QLA8031(ha)) { |
| 4567 | ql_dbg(ql_dbg_p3p, vha, 0xb05d, |
| 4568 | "Setting back fcoe driver presence.\n"); |
| 4569 | if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS) |
| 4570 | ql_dbg(ql_dbg_p3p, vha, 0xb074, |
| 4571 | "Error while setting DRV-Presence.\n"); |
| 4572 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4573 | } else { |
Joe Perches | d8424f6 | 2011-11-18 09:03:06 -0800 | [diff] [blame] | 4574 | ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n", |
| 4575 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4576 | } |
| 4577 | |
| 4578 | return(status); |
| 4579 | } |
| 4580 | |
| 4581 | /* |
| 4582 | * qla2x00_restart_isp |
| 4583 | * restarts the ISP after a reset |
| 4584 | * |
| 4585 | * Input: |
| 4586 | * ha = adapter block pointer. |
| 4587 | * |
| 4588 | * Returns: |
| 4589 | * 0 = success |
| 4590 | */ |
| 4591 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4592 | qla2x00_restart_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4593 | { |
Andrew Vasquez | c6b2fca | 2009-03-05 11:07:03 -0800 | [diff] [blame] | 4594 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4595 | uint32_t wait_time; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4596 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4597 | struct req_que *req = ha->req_q_map[0]; |
| 4598 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4599 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4600 | |
| 4601 | /* If firmware needs to be loaded */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4602 | if (qla2x00_isp_firmware(vha)) { |
| 4603 | vha->flags.online = 0; |
| 4604 | status = ha->isp_ops->chip_diag(vha); |
| 4605 | if (!status) |
| 4606 | status = qla2x00_setup_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4607 | } |
| 4608 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4609 | if (!status && !(status = qla2x00_init_rings(vha))) { |
| 4610 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 4611 | ha->flags.chip_reset_done = 1; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4612 | /* Initialize the queues in use */ |
| 4613 | qla25xx_init_queues(ha); |
| 4614 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4615 | status = qla2x00_fw_ready(vha); |
| 4616 | if (!status) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4617 | ql_dbg(ql_dbg_taskm, vha, 0x8031, |
| 4618 | "Start configure loop status = %d.\n", status); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4619 | |
| 4620 | /* Issue a marker after FW becomes ready. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4621 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4622 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4623 | vha->flags.online = 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4624 | |
| 4625 | /* |
| 4626 | * Process any ATIO queue entries that came in |
| 4627 | * while we weren't online. |
| 4628 | */ |
| 4629 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4630 | if (qla_tgt_mode_enabled(vha)) |
| 4631 | qlt_24xx_process_atio_queue(vha); |
| 4632 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4633 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4634 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 4635 | wait_time = 256; |
| 4636 | do { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4637 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 4638 | qla2x00_configure_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4639 | wait_time--; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4640 | } while (!atomic_read(&vha->loop_down_timer) && |
| 4641 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
| 4642 | && wait_time && (test_bit(LOOP_RESYNC_NEEDED, |
| 4643 | &vha->dpc_flags))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4644 | } |
| 4645 | |
| 4646 | /* if no cable then assume it's good */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4647 | if ((vha->device_flags & DFLG_NO_CABLE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4648 | status = 0; |
| 4649 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4650 | ql_dbg(ql_dbg_taskm, vha, 0x8032, |
| 4651 | "Configure loop done, status = 0x%x.\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4652 | } |
| 4653 | return (status); |
| 4654 | } |
| 4655 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4656 | static int |
| 4657 | qla25xx_init_queues(struct qla_hw_data *ha) |
| 4658 | { |
| 4659 | struct rsp_que *rsp = NULL; |
| 4660 | struct req_que *req = NULL; |
| 4661 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
| 4662 | int ret = -1; |
| 4663 | int i; |
| 4664 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 4665 | for (i = 1; i < ha->max_rsp_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4666 | rsp = ha->rsp_q_map[i]; |
| 4667 | if (rsp) { |
| 4668 | rsp->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 4669 | ret = qla25xx_init_rsp_que(base_vha, rsp); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4670 | if (ret != QLA_SUCCESS) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4671 | ql_dbg(ql_dbg_init, base_vha, 0x00ff, |
| 4672 | "%s Rsp que: %d init failed.\n", |
| 4673 | __func__, rsp->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4674 | else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4675 | ql_dbg(ql_dbg_init, base_vha, 0x0100, |
| 4676 | "%s Rsp que: %d inited.\n", |
| 4677 | __func__, rsp->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4678 | } |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 4679 | } |
| 4680 | for (i = 1; i < ha->max_req_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4681 | req = ha->req_q_map[i]; |
| 4682 | if (req) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 4683 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4684 | req->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 4685 | ret = qla25xx_init_req_que(base_vha, req); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4686 | if (ret != QLA_SUCCESS) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4687 | ql_dbg(ql_dbg_init, base_vha, 0x0101, |
| 4688 | "%s Req que: %d init failed.\n", |
| 4689 | __func__, req->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4690 | else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4691 | ql_dbg(ql_dbg_init, base_vha, 0x0102, |
| 4692 | "%s Req que: %d inited.\n", |
| 4693 | __func__, req->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4694 | } |
| 4695 | } |
| 4696 | return ret; |
| 4697 | } |
| 4698 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4699 | /* |
| 4700 | * qla2x00_reset_adapter |
| 4701 | * Reset adapter. |
| 4702 | * |
| 4703 | * Input: |
| 4704 | * ha = adapter block pointer. |
| 4705 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4706 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4707 | qla2x00_reset_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4708 | { |
| 4709 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4710 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 4711 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4712 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4713 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 4714 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4715 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4716 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4717 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 4718 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 4719 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 4720 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 4721 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4722 | } |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4723 | |
| 4724 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4725 | qla24xx_reset_adapter(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4726 | { |
| 4727 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4728 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4729 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 4730 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame^] | 4731 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4732 | return; |
| 4733 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4734 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 4735 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4736 | |
| 4737 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4738 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 4739 | RD_REG_DWORD(®->hccr); |
| 4740 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 4741 | RD_REG_DWORD(®->hccr); |
| 4742 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 09ff36d | 2009-01-22 09:45:30 -0800 | [diff] [blame] | 4743 | |
| 4744 | if (IS_NOPOLLING_TYPE(ha)) |
| 4745 | ha->isp_ops->enable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4746 | } |
| 4747 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4748 | /* On sparc systems, obtain port and node WWN from firmware |
| 4749 | * properties. |
| 4750 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4751 | static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, |
| 4752 | struct nvram_24xx *nv) |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4753 | { |
| 4754 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4755 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4756 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 4757 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 4758 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4759 | int len; |
| 4760 | |
| 4761 | val = of_get_property(dp, "port-wwn", &len); |
| 4762 | if (val && len >= WWN_SIZE) |
| 4763 | memcpy(nv->port_name, val, WWN_SIZE); |
| 4764 | |
| 4765 | val = of_get_property(dp, "node-wwn", &len); |
| 4766 | if (val && len >= WWN_SIZE) |
| 4767 | memcpy(nv->node_name, val, WWN_SIZE); |
| 4768 | #endif |
| 4769 | } |
| 4770 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4771 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4772 | qla24xx_nvram_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4773 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4774 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4775 | struct init_cb_24xx *icb; |
| 4776 | struct nvram_24xx *nv; |
| 4777 | uint32_t *dptr; |
| 4778 | uint8_t *dptr1, *dptr2; |
| 4779 | uint32_t chksum; |
| 4780 | uint16_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4781 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4782 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4783 | rval = QLA_SUCCESS; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4784 | icb = (struct init_cb_24xx *)ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 4785 | nv = ha->nvram; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4786 | |
| 4787 | /* Determine NVRAM starting address. */ |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 4788 | if (ha->flags.port0) { |
| 4789 | ha->nvram_base = FA_NVRAM_FUNC0_ADDR; |
| 4790 | ha->vpd_base = FA_NVRAM_VPD0_ADDR; |
| 4791 | } else { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4792 | ha->nvram_base = FA_NVRAM_FUNC1_ADDR; |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 4793 | ha->vpd_base = FA_NVRAM_VPD1_ADDR; |
| 4794 | } |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 4795 | ha->nvram_size = sizeof(struct nvram_24xx); |
| 4796 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4797 | |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 4798 | /* Get VPD data into cache */ |
| 4799 | ha->vpd = ha->nvram + VPD_OFFSET; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4800 | ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 4801 | ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4); |
| 4802 | |
| 4803 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4804 | dptr = (uint32_t *)nv; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4805 | ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4806 | ha->nvram_size); |
| 4807 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++) |
| 4808 | chksum += le32_to_cpu(*dptr++); |
| 4809 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4810 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a, |
| 4811 | "Contents of NVRAM\n"); |
| 4812 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d, |
| 4813 | (uint8_t *)nv, ha->nvram_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4814 | |
| 4815 | /* Bad NVRAM data, set defaults parameters. */ |
| 4816 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 4817 | || nv->id[3] != ' ' || |
| 4818 | nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) { |
| 4819 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4820 | ql_log(ql_log_warn, vha, 0x006b, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 4821 | "Inconsistent NVRAM detected: checksum=0x%x id=%c " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4822 | "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version); |
| 4823 | ql_log(ql_log_warn, vha, 0x006c, |
| 4824 | "Falling back to functioning (yet invalid -- WWPN) " |
| 4825 | "defaults.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4826 | |
| 4827 | /* |
| 4828 | * Set default initialization control block. |
| 4829 | */ |
| 4830 | memset(nv, 0, ha->nvram_size); |
| 4831 | nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION); |
| 4832 | nv->version = __constant_cpu_to_le16(ICB_VERSION); |
| 4833 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 4834 | nv->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 4835 | nv->exchange_count = __constant_cpu_to_le16(0); |
| 4836 | nv->hard_address = __constant_cpu_to_le16(124); |
| 4837 | nv->port_name[0] = 0x21; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 4838 | nv->port_name[1] = 0x00 + ha->port_no; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4839 | nv->port_name[2] = 0x00; |
| 4840 | nv->port_name[3] = 0xe0; |
| 4841 | nv->port_name[4] = 0x8b; |
| 4842 | nv->port_name[5] = 0x1c; |
| 4843 | nv->port_name[6] = 0x55; |
| 4844 | nv->port_name[7] = 0x86; |
| 4845 | nv->node_name[0] = 0x20; |
| 4846 | nv->node_name[1] = 0x00; |
| 4847 | nv->node_name[2] = 0x00; |
| 4848 | nv->node_name[3] = 0xe0; |
| 4849 | nv->node_name[4] = 0x8b; |
| 4850 | nv->node_name[5] = 0x1c; |
| 4851 | nv->node_name[6] = 0x55; |
| 4852 | nv->node_name[7] = 0x86; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4853 | qla24xx_nvram_wwn_from_ofw(vha, nv); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4854 | nv->login_retry_count = __constant_cpu_to_le16(8); |
| 4855 | nv->interrupt_delay_timer = __constant_cpu_to_le16(0); |
| 4856 | nv->login_timeout = __constant_cpu_to_le16(0); |
| 4857 | nv->firmware_options_1 = |
| 4858 | __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 4859 | nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4); |
| 4860 | nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12); |
| 4861 | nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13); |
| 4862 | nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10); |
| 4863 | nv->efi_parameters = __constant_cpu_to_le32(0); |
| 4864 | nv->reset_delay = 5; |
| 4865 | nv->max_luns_per_target = __constant_cpu_to_le16(128); |
| 4866 | nv->port_down_retry_count = __constant_cpu_to_le16(30); |
| 4867 | nv->link_down_timeout = __constant_cpu_to_le16(30); |
| 4868 | |
| 4869 | rval = 1; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4870 | } |
| 4871 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4872 | if (!qla_ini_mode_enabled(vha)) { |
| 4873 | /* Don't enable full login after initial LIP */ |
| 4874 | nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_13); |
| 4875 | /* Don't enable LIP full login for initiator */ |
| 4876 | nv->host_p &= __constant_cpu_to_le32(~BIT_10); |
| 4877 | } |
| 4878 | |
| 4879 | qlt_24xx_config_nvram_stage1(vha, nv); |
| 4880 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4881 | /* Reset Initialization control block */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4882 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4883 | |
| 4884 | /* Copy 1st segment. */ |
| 4885 | dptr1 = (uint8_t *)icb; |
| 4886 | dptr2 = (uint8_t *)&nv->version; |
| 4887 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 4888 | while (cnt--) |
| 4889 | *dptr1++ = *dptr2++; |
| 4890 | |
| 4891 | icb->login_retry_count = nv->login_retry_count; |
Andrew Vasquez | 3ea66e2 | 2006-06-23 16:11:27 -0700 | [diff] [blame] | 4892 | icb->link_down_on_nos = nv->link_down_on_nos; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4893 | |
| 4894 | /* Copy 2nd segment. */ |
| 4895 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 4896 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 4897 | cnt = (uint8_t *)&icb->reserved_3 - |
| 4898 | (uint8_t *)&icb->interrupt_delay_timer; |
| 4899 | while (cnt--) |
| 4900 | *dptr1++ = *dptr2++; |
| 4901 | |
| 4902 | /* |
| 4903 | * Setup driver NVRAM options. |
| 4904 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4905 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 4906 | "QLA2462"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4907 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4908 | qlt_24xx_config_nvram_stage2(vha, icb); |
| 4909 | |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 4910 | if (nv->host_p & __constant_cpu_to_le32(BIT_15)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4911 | /* Use alternate WWN? */ |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 4912 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 4913 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 4914 | } |
| 4915 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4916 | /* Prepare nodename */ |
Andrew Vasquez | fd0e7e4 | 2006-05-17 15:09:11 -0700 | [diff] [blame] | 4917 | if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4918 | /* |
| 4919 | * Firmware will apply the following mask if the nodename was |
| 4920 | * not provided. |
| 4921 | */ |
| 4922 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 4923 | icb->node_name[0] &= 0xF0; |
| 4924 | } |
| 4925 | |
| 4926 | /* Set host adapter parameters. */ |
| 4927 | ha->flags.disable_risc_code_load = 0; |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 4928 | ha->flags.enable_lip_reset = 0; |
| 4929 | ha->flags.enable_lip_full_login = |
| 4930 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 4931 | ha->flags.enable_target_reset = |
| 4932 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4933 | ha->flags.enable_led_scheme = 0; |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 4934 | 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] | 4935 | |
Andrew Vasquez | fd0e7e4 | 2006-05-17 15:09:11 -0700 | [diff] [blame] | 4936 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 4937 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4938 | |
| 4939 | memcpy(ha->fw_seriallink_options24, nv->seriallink_options, |
| 4940 | sizeof(ha->fw_seriallink_options24)); |
| 4941 | |
| 4942 | /* save HBA serial number */ |
| 4943 | ha->serial0 = icb->port_name[5]; |
| 4944 | ha->serial1 = icb->port_name[6]; |
| 4945 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4946 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 4947 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4948 | |
andrew.vasquez@qlogic.com | bc8fb3c | 2006-01-13 17:05:42 -0800 | [diff] [blame] | 4949 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 4950 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4951 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 4952 | |
| 4953 | /* Set minimum login_timeout to 4 seconds. */ |
| 4954 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 4955 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 4956 | if (le16_to_cpu(nv->login_timeout) < 4) |
| 4957 | nv->login_timeout = __constant_cpu_to_le16(4); |
| 4958 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
Seokmann Ju | c6852c4 | 2008-04-24 15:21:29 -0700 | [diff] [blame] | 4959 | icb->login_timeout = nv->login_timeout; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4960 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 4961 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 4962 | ha->r_a_tov = 100; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4963 | |
| 4964 | ha->loop_reset_delay = nv->reset_delay; |
| 4965 | |
| 4966 | /* Link Down Timeout = 0: |
| 4967 | * |
| 4968 | * When Port Down timer expires we will start returning |
| 4969 | * I/O's to OS with "DID_NO_CONNECT". |
| 4970 | * |
| 4971 | * Link Down Timeout != 0: |
| 4972 | * |
| 4973 | * The driver waits for the link to come up after link down |
| 4974 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 4975 | */ |
| 4976 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 4977 | ha->loop_down_abort_time = |
| 4978 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 4979 | } else { |
| 4980 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 4981 | ha->loop_down_abort_time = |
| 4982 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 4983 | } |
| 4984 | |
| 4985 | /* Need enough time to try and get the port back. */ |
| 4986 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 4987 | if (qlport_down_retry) |
| 4988 | ha->port_down_retry_count = qlport_down_retry; |
| 4989 | |
| 4990 | /* Set login_retry_count */ |
| 4991 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 4992 | if (ha->port_down_retry_count == |
| 4993 | le16_to_cpu(nv->port_down_retry_count) && |
| 4994 | ha->port_down_retry_count > 3) |
| 4995 | ha->login_retry_count = ha->port_down_retry_count; |
| 4996 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 4997 | ha->login_retry_count = ha->port_down_retry_count; |
| 4998 | if (ql2xloginretrycount) |
| 4999 | ha->login_retry_count = ql2xloginretrycount; |
| 5000 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 5001 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5002 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 5003 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 5004 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 5005 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 5006 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 5007 | } |
| 5008 | icb->firmware_options_2 &= __constant_cpu_to_le32( |
| 5009 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5010 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 5011 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 5012 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 5013 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5014 | ql_log(ql_log_info, vha, 0x006f, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 5015 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 5016 | ha->zio_mode, ha->zio_timer * 100); |
| 5017 | |
| 5018 | icb->firmware_options_2 |= cpu_to_le32( |
| 5019 | (uint32_t)ha->zio_mode); |
| 5020 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5021 | vha->flags.process_response_queue = 1; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 5022 | } |
| 5023 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5024 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5025 | ql_log(ql_log_warn, vha, 0x0070, |
| 5026 | "NVRAM configuration failed.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 5027 | } |
| 5028 | return (rval); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5029 | } |
| 5030 | |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 5031 | static int |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5032 | qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr, |
| 5033 | uint32_t faddr) |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5034 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5035 | int rval = QLA_SUCCESS; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5036 | int segments, fragment; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5037 | uint32_t *dcode, dlen; |
| 5038 | uint32_t risc_addr; |
| 5039 | uint32_t risc_size; |
| 5040 | uint32_t i; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5041 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5042 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5043 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5044 | ql_dbg(ql_dbg_init, vha, 0x008b, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5045 | "FW: Loading firmware from flash (%x).\n", faddr); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5046 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5047 | rval = QLA_SUCCESS; |
| 5048 | |
| 5049 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5050 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5051 | *srisc_addr = 0; |
| 5052 | |
| 5053 | /* Validate firmware image by checking version. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5054 | qla24xx_read_flash_data(vha, dcode, faddr + 4, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5055 | for (i = 0; i < 4; i++) |
| 5056 | dcode[i] = be32_to_cpu(dcode[i]); |
| 5057 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 5058 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 5059 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 5060 | dcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5061 | ql_log(ql_log_fatal, vha, 0x008c, |
| 5062 | "Unable to verify the integrity of flash firmware " |
| 5063 | "image.\n"); |
| 5064 | ql_log(ql_log_fatal, vha, 0x008d, |
| 5065 | "Firmware data: %08x %08x %08x %08x.\n", |
| 5066 | dcode[0], dcode[1], dcode[2], dcode[3]); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5067 | |
| 5068 | return QLA_FUNCTION_FAILED; |
| 5069 | } |
| 5070 | |
| 5071 | while (segments && rval == QLA_SUCCESS) { |
| 5072 | /* Read segment's load information. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5073 | qla24xx_read_flash_data(vha, dcode, faddr, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5074 | |
| 5075 | risc_addr = be32_to_cpu(dcode[2]); |
| 5076 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 5077 | risc_size = be32_to_cpu(dcode[3]); |
| 5078 | |
| 5079 | fragment = 0; |
| 5080 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 5081 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 5082 | if (dlen > risc_size) |
| 5083 | dlen = risc_size; |
| 5084 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5085 | ql_dbg(ql_dbg_init, vha, 0x008e, |
| 5086 | "Loading risc segment@ risc addr %x " |
| 5087 | "number of dwords 0x%x offset 0x%x.\n", |
| 5088 | risc_addr, dlen, faddr); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5089 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5090 | qla24xx_read_flash_data(vha, dcode, faddr, dlen); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5091 | for (i = 0; i < dlen; i++) |
| 5092 | dcode[i] = swab32(dcode[i]); |
| 5093 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5094 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5095 | dlen); |
| 5096 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5097 | ql_log(ql_log_fatal, vha, 0x008f, |
| 5098 | "Failed to load segment %d of firmware.\n", |
| 5099 | fragment); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5100 | break; |
| 5101 | } |
| 5102 | |
| 5103 | faddr += dlen; |
| 5104 | risc_addr += dlen; |
| 5105 | risc_size -= dlen; |
| 5106 | fragment++; |
| 5107 | } |
| 5108 | |
| 5109 | /* Next segment. */ |
| 5110 | segments--; |
| 5111 | } |
| 5112 | |
| 5113 | return rval; |
| 5114 | } |
| 5115 | |
Giridhar Malavali | e9454a8 | 2013-02-08 01:57:47 -0500 | [diff] [blame] | 5116 | #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/" |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5117 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5118 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5119 | qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5120 | { |
| 5121 | int rval; |
| 5122 | int i, fragment; |
| 5123 | uint16_t *wcode, *fwcode; |
| 5124 | uint32_t risc_addr, risc_size, fwclen, wlen, *seg; |
| 5125 | struct fw_blob *blob; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5126 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5127 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5128 | |
| 5129 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5130 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5131 | if (!blob) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5132 | ql_log(ql_log_info, vha, 0x0083, |
| 5133 | "Fimware image unavailable.\n"); |
| 5134 | ql_log(ql_log_info, vha, 0x0084, |
| 5135 | "Firmware images can be retrieved from: "QLA_FW_URL ".\n"); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5136 | return QLA_FUNCTION_FAILED; |
| 5137 | } |
| 5138 | |
| 5139 | rval = QLA_SUCCESS; |
| 5140 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5141 | wcode = (uint16_t *)req->ring; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5142 | *srisc_addr = 0; |
| 5143 | fwcode = (uint16_t *)blob->fw->data; |
| 5144 | fwclen = 0; |
| 5145 | |
| 5146 | /* Validate firmware image by checking version. */ |
| 5147 | if (blob->fw->size < 8 * sizeof(uint16_t)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5148 | ql_log(ql_log_fatal, vha, 0x0085, |
| 5149 | "Unable to verify integrity of firmware image (%Zd).\n", |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5150 | blob->fw->size); |
| 5151 | goto fail_fw_integrity; |
| 5152 | } |
| 5153 | for (i = 0; i < 4; i++) |
| 5154 | wcode[i] = be16_to_cpu(fwcode[i + 4]); |
| 5155 | if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff && |
| 5156 | wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 && |
| 5157 | wcode[2] == 0 && wcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5158 | ql_log(ql_log_fatal, vha, 0x0086, |
| 5159 | "Unable to verify integrity of firmware image.\n"); |
| 5160 | ql_log(ql_log_fatal, vha, 0x0087, |
| 5161 | "Firmware data: %04x %04x %04x %04x.\n", |
| 5162 | wcode[0], wcode[1], wcode[2], wcode[3]); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5163 | goto fail_fw_integrity; |
| 5164 | } |
| 5165 | |
| 5166 | seg = blob->segs; |
| 5167 | while (*seg && rval == QLA_SUCCESS) { |
| 5168 | risc_addr = *seg; |
| 5169 | *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr; |
| 5170 | risc_size = be16_to_cpu(fwcode[3]); |
| 5171 | |
| 5172 | /* Validate firmware image size. */ |
| 5173 | fwclen += risc_size * sizeof(uint16_t); |
| 5174 | if (blob->fw->size < fwclen) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5175 | ql_log(ql_log_fatal, vha, 0x0088, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5176 | "Unable to verify integrity of firmware image " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5177 | "(%Zd).\n", blob->fw->size); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5178 | goto fail_fw_integrity; |
| 5179 | } |
| 5180 | |
| 5181 | fragment = 0; |
| 5182 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 5183 | wlen = (uint16_t)(ha->fw_transfer_size >> 1); |
| 5184 | if (wlen > risc_size) |
| 5185 | wlen = risc_size; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5186 | ql_dbg(ql_dbg_init, vha, 0x0089, |
| 5187 | "Loading risc segment@ risc addr %x number of " |
| 5188 | "words 0x%x.\n", risc_addr, wlen); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5189 | |
| 5190 | for (i = 0; i < wlen; i++) |
| 5191 | wcode[i] = swab16(fwcode[i]); |
| 5192 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5193 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5194 | wlen); |
| 5195 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5196 | ql_log(ql_log_fatal, vha, 0x008a, |
| 5197 | "Failed to load segment %d of firmware.\n", |
| 5198 | fragment); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5199 | break; |
| 5200 | } |
| 5201 | |
| 5202 | fwcode += wlen; |
| 5203 | risc_addr += wlen; |
| 5204 | risc_size -= wlen; |
| 5205 | fragment++; |
| 5206 | } |
| 5207 | |
| 5208 | /* Next segment. */ |
| 5209 | seg++; |
| 5210 | } |
| 5211 | return rval; |
| 5212 | |
| 5213 | fail_fw_integrity: |
| 5214 | return QLA_FUNCTION_FAILED; |
| 5215 | } |
| 5216 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5217 | static int |
| 5218 | 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] | 5219 | { |
| 5220 | int rval; |
| 5221 | int segments, fragment; |
| 5222 | uint32_t *dcode, dlen; |
| 5223 | uint32_t risc_addr; |
| 5224 | uint32_t risc_size; |
| 5225 | uint32_t i; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5226 | struct fw_blob *blob; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5227 | uint32_t *fwcode, fwclen; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5228 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5229 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5230 | |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5231 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5232 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5233 | if (!blob) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5234 | ql_log(ql_log_warn, vha, 0x0090, |
| 5235 | "Fimware image unavailable.\n"); |
| 5236 | ql_log(ql_log_warn, vha, 0x0091, |
| 5237 | "Firmware images can be retrieved from: " |
| 5238 | QLA_FW_URL ".\n"); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5239 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5240 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5241 | } |
| 5242 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5243 | ql_dbg(ql_dbg_init, vha, 0x0092, |
| 5244 | "FW: Loading via request-firmware.\n"); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5245 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5246 | rval = QLA_SUCCESS; |
| 5247 | |
| 5248 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5249 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5250 | *srisc_addr = 0; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5251 | fwcode = (uint32_t *)blob->fw->data; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5252 | fwclen = 0; |
| 5253 | |
| 5254 | /* Validate firmware image by checking version. */ |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5255 | if (blob->fw->size < 8 * sizeof(uint32_t)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5256 | ql_log(ql_log_fatal, vha, 0x0093, |
| 5257 | "Unable to verify integrity of firmware image (%Zd).\n", |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5258 | blob->fw->size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5259 | goto fail_fw_integrity; |
| 5260 | } |
| 5261 | for (i = 0; i < 4; i++) |
| 5262 | dcode[i] = be32_to_cpu(fwcode[i + 4]); |
| 5263 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 5264 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 5265 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 5266 | dcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5267 | ql_log(ql_log_fatal, vha, 0x0094, |
| 5268 | "Unable to verify integrity of firmware image (%Zd).\n", |
| 5269 | blob->fw->size); |
| 5270 | ql_log(ql_log_fatal, vha, 0x0095, |
| 5271 | "Firmware data: %08x %08x %08x %08x.\n", |
| 5272 | dcode[0], dcode[1], dcode[2], dcode[3]); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5273 | goto fail_fw_integrity; |
| 5274 | } |
| 5275 | |
| 5276 | while (segments && rval == QLA_SUCCESS) { |
| 5277 | risc_addr = be32_to_cpu(fwcode[2]); |
| 5278 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 5279 | risc_size = be32_to_cpu(fwcode[3]); |
| 5280 | |
| 5281 | /* Validate firmware image size. */ |
| 5282 | fwclen += risc_size * sizeof(uint32_t); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5283 | if (blob->fw->size < fwclen) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5284 | ql_log(ql_log_fatal, vha, 0x0096, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5285 | "Unable to verify integrity of firmware image " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5286 | "(%Zd).\n", blob->fw->size); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5287 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5288 | goto fail_fw_integrity; |
| 5289 | } |
| 5290 | |
| 5291 | fragment = 0; |
| 5292 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 5293 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 5294 | if (dlen > risc_size) |
| 5295 | dlen = risc_size; |
| 5296 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5297 | ql_dbg(ql_dbg_init, vha, 0x0097, |
| 5298 | "Loading risc segment@ risc addr %x " |
| 5299 | "number of dwords 0x%x.\n", risc_addr, dlen); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5300 | |
| 5301 | for (i = 0; i < dlen; i++) |
| 5302 | dcode[i] = swab32(fwcode[i]); |
| 5303 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5304 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
andrew.vasquez@qlogic.com | 590f98e | 2006-01-13 17:05:37 -0800 | [diff] [blame] | 5305 | dlen); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5306 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5307 | ql_log(ql_log_fatal, vha, 0x0098, |
| 5308 | "Failed to load segment %d of firmware.\n", |
| 5309 | fragment); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5310 | break; |
| 5311 | } |
| 5312 | |
| 5313 | fwcode += dlen; |
| 5314 | risc_addr += dlen; |
| 5315 | risc_size -= dlen; |
| 5316 | fragment++; |
| 5317 | } |
| 5318 | |
| 5319 | /* Next segment. */ |
| 5320 | segments--; |
| 5321 | } |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5322 | return rval; |
| 5323 | |
| 5324 | fail_fw_integrity: |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5325 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5326 | } |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5327 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5328 | int |
| 5329 | qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 5330 | { |
| 5331 | int rval; |
| 5332 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 5333 | if (ql2xfwloadbin == 1) |
| 5334 | return qla81xx_load_risc(vha, srisc_addr); |
| 5335 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5336 | /* |
| 5337 | * FW Load priority: |
| 5338 | * 1) Firmware via request-firmware interface (.bin file). |
| 5339 | * 2) Firmware residing in flash. |
| 5340 | */ |
| 5341 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 5342 | if (rval == QLA_SUCCESS) |
| 5343 | return rval; |
| 5344 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5345 | return qla24xx_load_risc_flash(vha, srisc_addr, |
| 5346 | vha->hw->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5347 | } |
| 5348 | |
| 5349 | int |
| 5350 | qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 5351 | { |
| 5352 | int rval; |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5353 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5354 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 5355 | if (ql2xfwloadbin == 2) |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5356 | goto try_blob_fw; |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 5357 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5358 | /* |
| 5359 | * FW Load priority: |
| 5360 | * 1) Firmware residing in flash. |
| 5361 | * 2) Firmware via request-firmware interface (.bin file). |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5362 | * 3) Golden-Firmware residing in flash -- limited operation. |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5363 | */ |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5364 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5365 | if (rval == QLA_SUCCESS) |
| 5366 | return rval; |
| 5367 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5368 | try_blob_fw: |
| 5369 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 5370 | if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw) |
| 5371 | return rval; |
| 5372 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5373 | ql_log(ql_log_info, vha, 0x0099, |
| 5374 | "Attempting to fallback to golden firmware.\n"); |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5375 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw); |
| 5376 | if (rval != QLA_SUCCESS) |
| 5377 | return rval; |
| 5378 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5379 | ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n"); |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5380 | ha->flags.running_gold_fw = 1; |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5381 | return rval; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5382 | } |
| 5383 | |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5384 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5385 | qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5386 | { |
| 5387 | int ret, retries; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5388 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5389 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 5390 | if (ha->flags.pci_channel_io_perm_failure) |
| 5391 | return; |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 5392 | if (!IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5393 | return; |
Andrew Vasquez | 75edf81 | 2007-05-07 07:43:00 -0700 | [diff] [blame] | 5394 | if (!ha->fw_major_version) |
| 5395 | return; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5396 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5397 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 7c7f1f2 | 2008-02-28 14:06:09 -0800 | [diff] [blame] | 5398 | for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT && |
Andrew Vasquez | b469a7c | 2009-04-06 22:33:48 -0700 | [diff] [blame] | 5399 | ret != QLA_INVALID_COMMAND && retries ; retries--) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5400 | ha->isp_ops->reset_chip(vha); |
| 5401 | if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5402 | continue; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5403 | if (qla2x00_setup_chip(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5404 | continue; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5405 | ql_log(ql_log_info, vha, 0x8015, |
| 5406 | "Attempting retry of stop-firmware command.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5407 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5408 | } |
| 5409 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5410 | |
| 5411 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5412 | qla24xx_configure_vhba(scsi_qla_host_t *vha) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5413 | { |
| 5414 | int rval = QLA_SUCCESS; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 5415 | int rval2; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5416 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5417 | struct qla_hw_data *ha = vha->hw; |
| 5418 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 5419 | struct req_que *req; |
| 5420 | struct rsp_que *rsp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5421 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5422 | if (!vha->vp_idx) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5423 | return -EINVAL; |
| 5424 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5425 | rval = qla2x00_fw_ready(base_vha); |
Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 5426 | if (ha->flags.cpu_affinity_enabled) |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 5427 | req = ha->req_q_map[0]; |
| 5428 | else |
| 5429 | req = vha->req; |
| 5430 | rsp = req->rsp; |
| 5431 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5432 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5433 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5434 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5435 | } |
| 5436 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5437 | vha->flags.management_server_logged_in = 0; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5438 | |
| 5439 | /* Login to SNS first */ |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 5440 | rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, |
| 5441 | BIT_1); |
| 5442 | if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) { |
| 5443 | if (rval2 == QLA_MEMORY_ALLOC_FAILED) |
| 5444 | ql_dbg(ql_dbg_init, vha, 0x0120, |
| 5445 | "Failed SNS login: loop_id=%x, rval2=%d\n", |
| 5446 | NPH_SNS, rval2); |
| 5447 | else |
| 5448 | ql_dbg(ql_dbg_init, vha, 0x0103, |
| 5449 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x " |
| 5450 | "mb[2]=%x mb[6]=%x mb[7]=%x.\n", |
| 5451 | NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5452 | return (QLA_FUNCTION_FAILED); |
| 5453 | } |
| 5454 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5455 | atomic_set(&vha->loop_down_timer, 0); |
| 5456 | atomic_set(&vha->loop_state, LOOP_UP); |
| 5457 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 5458 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 5459 | rval = qla2x00_loop_resync(base_vha); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5460 | |
| 5461 | return rval; |
| 5462 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5463 | |
| 5464 | /* 84XX Support **************************************************************/ |
| 5465 | |
| 5466 | static LIST_HEAD(qla_cs84xx_list); |
| 5467 | static DEFINE_MUTEX(qla_cs84xx_mutex); |
| 5468 | |
| 5469 | static struct qla_chip_state_84xx * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5470 | qla84xx_get_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5471 | { |
| 5472 | struct qla_chip_state_84xx *cs84xx; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5473 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5474 | |
| 5475 | mutex_lock(&qla_cs84xx_mutex); |
| 5476 | |
| 5477 | /* Find any shared 84xx chip. */ |
| 5478 | list_for_each_entry(cs84xx, &qla_cs84xx_list, list) { |
| 5479 | if (cs84xx->bus == ha->pdev->bus) { |
| 5480 | kref_get(&cs84xx->kref); |
| 5481 | goto done; |
| 5482 | } |
| 5483 | } |
| 5484 | |
| 5485 | cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL); |
| 5486 | if (!cs84xx) |
| 5487 | goto done; |
| 5488 | |
| 5489 | kref_init(&cs84xx->kref); |
| 5490 | spin_lock_init(&cs84xx->access_lock); |
| 5491 | mutex_init(&cs84xx->fw_update_mutex); |
| 5492 | cs84xx->bus = ha->pdev->bus; |
| 5493 | |
| 5494 | list_add_tail(&cs84xx->list, &qla_cs84xx_list); |
| 5495 | done: |
| 5496 | mutex_unlock(&qla_cs84xx_mutex); |
| 5497 | return cs84xx; |
| 5498 | } |
| 5499 | |
| 5500 | static void |
| 5501 | __qla84xx_chip_release(struct kref *kref) |
| 5502 | { |
| 5503 | struct qla_chip_state_84xx *cs84xx = |
| 5504 | container_of(kref, struct qla_chip_state_84xx, kref); |
| 5505 | |
| 5506 | mutex_lock(&qla_cs84xx_mutex); |
| 5507 | list_del(&cs84xx->list); |
| 5508 | mutex_unlock(&qla_cs84xx_mutex); |
| 5509 | kfree(cs84xx); |
| 5510 | } |
| 5511 | |
| 5512 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5513 | qla84xx_put_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5514 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5515 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5516 | if (ha->cs84xx) |
| 5517 | kref_put(&ha->cs84xx->kref, __qla84xx_chip_release); |
| 5518 | } |
| 5519 | |
| 5520 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5521 | qla84xx_init_chip(scsi_qla_host_t *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5522 | { |
| 5523 | int rval; |
| 5524 | uint16_t status[2]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5525 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5526 | |
| 5527 | mutex_lock(&ha->cs84xx->fw_update_mutex); |
| 5528 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5529 | rval = qla84xx_verify_chip(vha, status); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5530 | |
| 5531 | mutex_unlock(&ha->cs84xx->fw_update_mutex); |
| 5532 | |
| 5533 | return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED: |
| 5534 | QLA_SUCCESS; |
| 5535 | } |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5536 | |
| 5537 | /* 81XX Support **************************************************************/ |
| 5538 | |
| 5539 | int |
| 5540 | qla81xx_nvram_config(scsi_qla_host_t *vha) |
| 5541 | { |
| 5542 | int rval; |
| 5543 | struct init_cb_81xx *icb; |
| 5544 | struct nvram_81xx *nv; |
| 5545 | uint32_t *dptr; |
| 5546 | uint8_t *dptr1, *dptr2; |
| 5547 | uint32_t chksum; |
| 5548 | uint16_t cnt; |
| 5549 | struct qla_hw_data *ha = vha->hw; |
| 5550 | |
| 5551 | rval = QLA_SUCCESS; |
| 5552 | icb = (struct init_cb_81xx *)ha->init_cb; |
| 5553 | nv = ha->nvram; |
| 5554 | |
| 5555 | /* Determine NVRAM starting address. */ |
| 5556 | ha->nvram_size = sizeof(struct nvram_81xx); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5557 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame^] | 5558 | if (IS_P3P_TYPE(ha) || IS_QLA8031(ha)) |
| 5559 | ha->vpd_size = FA_VPD_SIZE_82XX; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5560 | |
| 5561 | /* Get VPD data into cache */ |
| 5562 | ha->vpd = ha->nvram + VPD_OFFSET; |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 5563 | ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2, |
| 5564 | ha->vpd_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5565 | |
| 5566 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 5567 | 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] | 5568 | ha->nvram_size); |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 5569 | dptr = (uint32_t *)nv; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5570 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++) |
| 5571 | chksum += le32_to_cpu(*dptr++); |
| 5572 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5573 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111, |
| 5574 | "Contents of NVRAM:\n"); |
| 5575 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112, |
| 5576 | (uint8_t *)nv, ha->nvram_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5577 | |
| 5578 | /* Bad NVRAM data, set defaults parameters. */ |
| 5579 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 5580 | || nv->id[3] != ' ' || |
| 5581 | nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) { |
| 5582 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5583 | ql_log(ql_log_info, vha, 0x0073, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 5584 | "Inconsistent NVRAM detected: checksum=0x%x id=%c " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5585 | "version=0x%x.\n", chksum, nv->id[0], |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5586 | le16_to_cpu(nv->nvram_version)); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5587 | ql_log(ql_log_info, vha, 0x0074, |
| 5588 | "Falling back to functioning (yet invalid -- WWPN) " |
| 5589 | "defaults.\n"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5590 | |
| 5591 | /* |
| 5592 | * Set default initialization control block. |
| 5593 | */ |
| 5594 | memset(nv, 0, ha->nvram_size); |
| 5595 | nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION); |
| 5596 | nv->version = __constant_cpu_to_le16(ICB_VERSION); |
| 5597 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 5598 | nv->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 5599 | nv->exchange_count = __constant_cpu_to_le16(0); |
| 5600 | nv->port_name[0] = 0x21; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5601 | nv->port_name[1] = 0x00 + ha->port_no; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5602 | nv->port_name[2] = 0x00; |
| 5603 | nv->port_name[3] = 0xe0; |
| 5604 | nv->port_name[4] = 0x8b; |
| 5605 | nv->port_name[5] = 0x1c; |
| 5606 | nv->port_name[6] = 0x55; |
| 5607 | nv->port_name[7] = 0x86; |
| 5608 | nv->node_name[0] = 0x20; |
| 5609 | nv->node_name[1] = 0x00; |
| 5610 | nv->node_name[2] = 0x00; |
| 5611 | nv->node_name[3] = 0xe0; |
| 5612 | nv->node_name[4] = 0x8b; |
| 5613 | nv->node_name[5] = 0x1c; |
| 5614 | nv->node_name[6] = 0x55; |
| 5615 | nv->node_name[7] = 0x86; |
| 5616 | nv->login_retry_count = __constant_cpu_to_le16(8); |
| 5617 | nv->interrupt_delay_timer = __constant_cpu_to_le16(0); |
| 5618 | nv->login_timeout = __constant_cpu_to_le16(0); |
| 5619 | nv->firmware_options_1 = |
| 5620 | __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 5621 | nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4); |
| 5622 | nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12); |
| 5623 | nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13); |
| 5624 | nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10); |
| 5625 | nv->efi_parameters = __constant_cpu_to_le32(0); |
| 5626 | nv->reset_delay = 5; |
| 5627 | nv->max_luns_per_target = __constant_cpu_to_le16(128); |
| 5628 | nv->port_down_retry_count = __constant_cpu_to_le16(30); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 5629 | nv->link_down_timeout = __constant_cpu_to_le16(180); |
Andrew Vasquez | eeebcc9 | 2009-06-03 09:55:24 -0700 | [diff] [blame] | 5630 | nv->enode_mac[0] = 0x00; |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 5631 | nv->enode_mac[1] = 0xC0; |
| 5632 | nv->enode_mac[2] = 0xDD; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5633 | nv->enode_mac[3] = 0x04; |
| 5634 | nv->enode_mac[4] = 0x05; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5635 | nv->enode_mac[5] = 0x06 + ha->port_no; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5636 | |
| 5637 | rval = 1; |
| 5638 | } |
| 5639 | |
Arun Easi | 9e522cd | 2012-08-22 14:21:31 -0400 | [diff] [blame] | 5640 | if (IS_T10_PI_CAPABLE(ha)) |
| 5641 | nv->frame_payload_size &= ~7; |
| 5642 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 5643 | qlt_81xx_config_nvram_stage1(vha, nv); |
| 5644 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5645 | /* Reset Initialization control block */ |
Andrew Vasquez | 773120e | 2011-05-10 11:30:14 -0700 | [diff] [blame] | 5646 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5647 | |
| 5648 | /* Copy 1st segment. */ |
| 5649 | dptr1 = (uint8_t *)icb; |
| 5650 | dptr2 = (uint8_t *)&nv->version; |
| 5651 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 5652 | while (cnt--) |
| 5653 | *dptr1++ = *dptr2++; |
| 5654 | |
| 5655 | icb->login_retry_count = nv->login_retry_count; |
| 5656 | |
| 5657 | /* Copy 2nd segment. */ |
| 5658 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 5659 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 5660 | cnt = (uint8_t *)&icb->reserved_5 - |
| 5661 | (uint8_t *)&icb->interrupt_delay_timer; |
| 5662 | while (cnt--) |
| 5663 | *dptr1++ = *dptr2++; |
| 5664 | |
| 5665 | memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac)); |
| 5666 | /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */ |
| 5667 | 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] | 5668 | icb->enode_mac[0] = 0x00; |
| 5669 | icb->enode_mac[1] = 0xC0; |
| 5670 | icb->enode_mac[2] = 0xDD; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5671 | icb->enode_mac[3] = 0x04; |
| 5672 | icb->enode_mac[4] = 0x05; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5673 | icb->enode_mac[5] = 0x06 + ha->port_no; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5674 | } |
| 5675 | |
Andrew Vasquez | b64b0e8 | 2009-03-24 09:08:01 -0700 | [diff] [blame] | 5676 | /* Use extended-initialization control block. */ |
| 5677 | memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb)); |
| 5678 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5679 | /* |
| 5680 | * Setup driver NVRAM options. |
| 5681 | */ |
| 5682 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5683 | "QLE8XXX"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5684 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 5685 | qlt_81xx_config_nvram_stage2(vha, icb); |
| 5686 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5687 | /* Use alternate WWN? */ |
| 5688 | if (nv->host_p & __constant_cpu_to_le32(BIT_15)) { |
| 5689 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 5690 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 5691 | } |
| 5692 | |
| 5693 | /* Prepare nodename */ |
| 5694 | if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) { |
| 5695 | /* |
| 5696 | * Firmware will apply the following mask if the nodename was |
| 5697 | * not provided. |
| 5698 | */ |
| 5699 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 5700 | icb->node_name[0] &= 0xF0; |
| 5701 | } |
| 5702 | |
| 5703 | /* Set host adapter parameters. */ |
| 5704 | ha->flags.disable_risc_code_load = 0; |
| 5705 | ha->flags.enable_lip_reset = 0; |
| 5706 | ha->flags.enable_lip_full_login = |
| 5707 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 5708 | ha->flags.enable_target_reset = |
| 5709 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
| 5710 | ha->flags.enable_led_scheme = 0; |
| 5711 | ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0; |
| 5712 | |
| 5713 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 5714 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 5715 | |
| 5716 | /* save HBA serial number */ |
| 5717 | ha->serial0 = icb->port_name[5]; |
| 5718 | ha->serial1 = icb->port_name[6]; |
| 5719 | ha->serial2 = icb->port_name[7]; |
| 5720 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 5721 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
| 5722 | |
| 5723 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 5724 | |
| 5725 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 5726 | |
| 5727 | /* Set minimum login_timeout to 4 seconds. */ |
| 5728 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 5729 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 5730 | if (le16_to_cpu(nv->login_timeout) < 4) |
| 5731 | nv->login_timeout = __constant_cpu_to_le16(4); |
| 5732 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
| 5733 | icb->login_timeout = nv->login_timeout; |
| 5734 | |
| 5735 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 5736 | ha->r_a_tov = 100; |
| 5737 | |
| 5738 | ha->loop_reset_delay = nv->reset_delay; |
| 5739 | |
| 5740 | /* Link Down Timeout = 0: |
| 5741 | * |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame^] | 5742 | * When Port Down timer expires we will start returning |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5743 | * I/O's to OS with "DID_NO_CONNECT". |
| 5744 | * |
| 5745 | * Link Down Timeout != 0: |
| 5746 | * |
| 5747 | * The driver waits for the link to come up after link down |
| 5748 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 5749 | */ |
| 5750 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 5751 | ha->loop_down_abort_time = |
| 5752 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 5753 | } else { |
| 5754 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 5755 | ha->loop_down_abort_time = |
| 5756 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 5757 | } |
| 5758 | |
| 5759 | /* Need enough time to try and get the port back. */ |
| 5760 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 5761 | if (qlport_down_retry) |
| 5762 | ha->port_down_retry_count = qlport_down_retry; |
| 5763 | |
| 5764 | /* Set login_retry_count */ |
| 5765 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 5766 | if (ha->port_down_retry_count == |
| 5767 | le16_to_cpu(nv->port_down_retry_count) && |
| 5768 | ha->port_down_retry_count > 3) |
| 5769 | ha->login_retry_count = ha->port_down_retry_count; |
| 5770 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 5771 | ha->login_retry_count = ha->port_down_retry_count; |
| 5772 | if (ql2xloginretrycount) |
| 5773 | ha->login_retry_count = ql2xloginretrycount; |
| 5774 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 5775 | /* if not running MSI-X we need handshaking on interrupts */ |
| 5776 | if (!vha->hw->flags.msix_enabled && IS_QLA83XX(ha)) |
| 5777 | icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22); |
| 5778 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5779 | /* Enable ZIO. */ |
| 5780 | if (!vha->flags.init_done) { |
| 5781 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 5782 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 5783 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 5784 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 5785 | } |
| 5786 | icb->firmware_options_2 &= __constant_cpu_to_le32( |
| 5787 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
| 5788 | vha->flags.process_response_queue = 0; |
| 5789 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
| 5790 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 5791 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5792 | ql_log(ql_log_info, vha, 0x0075, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5793 | "ZIO mode %d enabled; timer delay (%d us).\n", |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5794 | ha->zio_mode, |
| 5795 | ha->zio_timer * 100); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5796 | |
| 5797 | icb->firmware_options_2 |= cpu_to_le32( |
| 5798 | (uint32_t)ha->zio_mode); |
| 5799 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
| 5800 | vha->flags.process_response_queue = 1; |
| 5801 | } |
| 5802 | |
| 5803 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5804 | ql_log(ql_log_warn, vha, 0x0076, |
| 5805 | "NVRAM configuration failed.\n"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5806 | } |
| 5807 | return (rval); |
| 5808 | } |
| 5809 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5810 | int |
| 5811 | qla82xx_restart_isp(scsi_qla_host_t *vha) |
| 5812 | { |
| 5813 | int status, rval; |
| 5814 | uint32_t wait_time; |
| 5815 | struct qla_hw_data *ha = vha->hw; |
| 5816 | struct req_que *req = ha->req_q_map[0]; |
| 5817 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
| 5818 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5819 | unsigned long flags; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5820 | |
| 5821 | status = qla2x00_init_rings(vha); |
| 5822 | if (!status) { |
| 5823 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 5824 | ha->flags.chip_reset_done = 1; |
| 5825 | |
| 5826 | status = qla2x00_fw_ready(vha); |
| 5827 | if (!status) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5828 | ql_log(ql_log_info, vha, 0x803c, |
| 5829 | "Start configure loop, status =%d.\n", status); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5830 | |
| 5831 | /* Issue a marker after FW becomes ready. */ |
| 5832 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
| 5833 | |
| 5834 | vha->flags.online = 1; |
| 5835 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 5836 | wait_time = 256; |
| 5837 | do { |
| 5838 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 5839 | qla2x00_configure_loop(vha); |
| 5840 | wait_time--; |
| 5841 | } while (!atomic_read(&vha->loop_down_timer) && |
| 5842 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) && |
| 5843 | wait_time && |
| 5844 | (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))); |
| 5845 | } |
| 5846 | |
| 5847 | /* if no cable then assume it's good */ |
| 5848 | if ((vha->device_flags & DFLG_NO_CABLE)) |
| 5849 | status = 0; |
| 5850 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5851 | ql_log(ql_log_info, vha, 0x8000, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5852 | "Configure loop done, status = 0x%x.\n", status); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5853 | } |
| 5854 | |
| 5855 | if (!status) { |
| 5856 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 5857 | |
| 5858 | if (!atomic_read(&vha->loop_down_timer)) { |
| 5859 | /* |
| 5860 | * Issue marker command only when we are going |
| 5861 | * to start the I/O . |
| 5862 | */ |
| 5863 | vha->marker_needed = 1; |
| 5864 | } |
| 5865 | |
| 5866 | vha->flags.online = 1; |
| 5867 | |
| 5868 | ha->isp_ops->enable_intrs(ha); |
| 5869 | |
| 5870 | ha->isp_abort_cnt = 0; |
| 5871 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 5872 | |
Saurav Kashyap | 5329678 | 2011-05-10 11:30:06 -0700 | [diff] [blame] | 5873 | /* Update the firmware version */ |
Giridhar Malavali | 3173167 | 2011-08-16 11:31:54 -0700 | [diff] [blame] | 5874 | status = qla82xx_check_md_needed(vha); |
Saurav Kashyap | 5329678 | 2011-05-10 11:30:06 -0700 | [diff] [blame] | 5875 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5876 | if (ha->fce) { |
| 5877 | ha->flags.fce_enabled = 1; |
| 5878 | memset(ha->fce, 0, |
| 5879 | fce_calc_size(ha->fce_bufs)); |
| 5880 | rval = qla2x00_enable_fce_trace(vha, |
| 5881 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 5882 | &ha->fce_bufs); |
| 5883 | if (rval) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5884 | ql_log(ql_log_warn, vha, 0x8001, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5885 | "Unable to reinitialize FCE (%d).\n", |
| 5886 | rval); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5887 | ha->flags.fce_enabled = 0; |
| 5888 | } |
| 5889 | } |
| 5890 | |
| 5891 | if (ha->eft) { |
| 5892 | memset(ha->eft, 0, EFT_SIZE); |
| 5893 | rval = qla2x00_enable_eft_trace(vha, |
| 5894 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 5895 | if (rval) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5896 | ql_log(ql_log_warn, vha, 0x8010, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5897 | "Unable to reinitialize EFT (%d).\n", |
| 5898 | rval); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5899 | } |
| 5900 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5901 | } |
| 5902 | |
| 5903 | if (!status) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5904 | ql_dbg(ql_dbg_taskm, vha, 0x8011, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5905 | "qla82xx_restart_isp succeeded.\n"); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5906 | |
| 5907 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5908 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 5909 | if (vp->vp_idx) { |
| 5910 | atomic_inc(&vp->vref_count); |
| 5911 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5912 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5913 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5914 | |
| 5915 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5916 | atomic_dec(&vp->vref_count); |
| 5917 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5918 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5919 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5920 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5921 | } else { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5922 | ql_log(ql_log_warn, vha, 0x8016, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5923 | "qla82xx_restart_isp **** FAILED ****.\n"); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5924 | } |
| 5925 | |
| 5926 | return status; |
| 5927 | } |
| 5928 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5929 | void |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 5930 | qla81xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5931 | { |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 5932 | struct qla_hw_data *ha = vha->hw; |
| 5933 | |
| 5934 | if (!ql2xetsenable) |
| 5935 | return; |
| 5936 | |
| 5937 | /* Enable ETS Burst. */ |
| 5938 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
| 5939 | ha->fw_options[2] |= BIT_9; |
| 5940 | qla2x00_set_fw_options(vha, ha->fw_options); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5941 | } |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5942 | |
| 5943 | /* |
| 5944 | * qla24xx_get_fcp_prio |
| 5945 | * Gets the fcp cmd priority value for the logged in port. |
| 5946 | * Looks for a match of the port descriptors within |
| 5947 | * each of the fcp prio config entries. If a match is found, |
| 5948 | * the tag (priority) value is returned. |
| 5949 | * |
| 5950 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5951 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5952 | * fcport = port structure pointer. |
| 5953 | * |
| 5954 | * Return: |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 5955 | * non-zero (if found) |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5956 | * -1 (if not found) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5957 | * |
| 5958 | * Context: |
| 5959 | * Kernel context |
| 5960 | */ |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5961 | static int |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5962 | qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 5963 | { |
| 5964 | int i, entries; |
| 5965 | uint8_t pid_match, wwn_match; |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5966 | int priority; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5967 | uint32_t pid1, pid2; |
| 5968 | uint64_t wwn1, wwn2; |
| 5969 | struct qla_fcp_prio_entry *pri_entry; |
| 5970 | struct qla_hw_data *ha = vha->hw; |
| 5971 | |
| 5972 | if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled) |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5973 | return -1; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5974 | |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5975 | priority = -1; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5976 | entries = ha->fcp_prio_cfg->num_entries; |
| 5977 | pri_entry = &ha->fcp_prio_cfg->entry[0]; |
| 5978 | |
| 5979 | for (i = 0; i < entries; i++) { |
| 5980 | pid_match = wwn_match = 0; |
| 5981 | |
| 5982 | if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) { |
| 5983 | pri_entry++; |
| 5984 | continue; |
| 5985 | } |
| 5986 | |
| 5987 | /* check source pid for a match */ |
| 5988 | if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) { |
| 5989 | pid1 = pri_entry->src_pid & INVALID_PORT_ID; |
| 5990 | pid2 = vha->d_id.b24 & INVALID_PORT_ID; |
| 5991 | if (pid1 == INVALID_PORT_ID) |
| 5992 | pid_match++; |
| 5993 | else if (pid1 == pid2) |
| 5994 | pid_match++; |
| 5995 | } |
| 5996 | |
| 5997 | /* check destination pid for a match */ |
| 5998 | if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) { |
| 5999 | pid1 = pri_entry->dst_pid & INVALID_PORT_ID; |
| 6000 | pid2 = fcport->d_id.b24 & INVALID_PORT_ID; |
| 6001 | if (pid1 == INVALID_PORT_ID) |
| 6002 | pid_match++; |
| 6003 | else if (pid1 == pid2) |
| 6004 | pid_match++; |
| 6005 | } |
| 6006 | |
| 6007 | /* check source WWN for a match */ |
| 6008 | if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) { |
| 6009 | wwn1 = wwn_to_u64(vha->port_name); |
| 6010 | wwn2 = wwn_to_u64(pri_entry->src_wwpn); |
| 6011 | if (wwn2 == (uint64_t)-1) |
| 6012 | wwn_match++; |
| 6013 | else if (wwn1 == wwn2) |
| 6014 | wwn_match++; |
| 6015 | } |
| 6016 | |
| 6017 | /* check destination WWN for a match */ |
| 6018 | if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) { |
| 6019 | wwn1 = wwn_to_u64(fcport->port_name); |
| 6020 | wwn2 = wwn_to_u64(pri_entry->dst_wwpn); |
| 6021 | if (wwn2 == (uint64_t)-1) |
| 6022 | wwn_match++; |
| 6023 | else if (wwn1 == wwn2) |
| 6024 | wwn_match++; |
| 6025 | } |
| 6026 | |
| 6027 | if (pid_match == 2 || wwn_match == 2) { |
| 6028 | /* Found a matching entry */ |
| 6029 | if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID) |
| 6030 | priority = pri_entry->tag; |
| 6031 | break; |
| 6032 | } |
| 6033 | |
| 6034 | pri_entry++; |
| 6035 | } |
| 6036 | |
| 6037 | return priority; |
| 6038 | } |
| 6039 | |
| 6040 | /* |
| 6041 | * qla24xx_update_fcport_fcp_prio |
| 6042 | * Activates fcp priority for the logged in fc port |
| 6043 | * |
| 6044 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 6045 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 6046 | * fcp = port structure pointer. |
| 6047 | * |
| 6048 | * Return: |
| 6049 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 6050 | * |
| 6051 | * Context: |
| 6052 | * Kernel context. |
| 6053 | */ |
| 6054 | int |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 6055 | 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] | 6056 | { |
| 6057 | int ret; |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 6058 | int priority; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 6059 | uint16_t mb[5]; |
| 6060 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 6061 | if (fcport->port_type != FCT_TARGET || |
| 6062 | fcport->loop_id == FC_NO_LOOP_ID) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 6063 | return QLA_FUNCTION_FAILED; |
| 6064 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 6065 | priority = qla24xx_get_fcp_prio(vha, fcport); |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 6066 | if (priority < 0) |
| 6067 | return QLA_FUNCTION_FAILED; |
| 6068 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame^] | 6069 | if (IS_P3P_TYPE(vha->hw)) { |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 6070 | fcport->fcp_prio = priority & 0xf; |
| 6071 | return QLA_SUCCESS; |
| 6072 | } |
| 6073 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 6074 | ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb); |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 6075 | if (ret == QLA_SUCCESS) { |
| 6076 | if (fcport->fcp_prio != priority) |
| 6077 | ql_dbg(ql_dbg_user, vha, 0x709e, |
| 6078 | "Updated FCP_CMND priority - value=%d loop_id=%d " |
| 6079 | "port_id=%02x%02x%02x.\n", priority, |
| 6080 | fcport->loop_id, fcport->d_id.b.domain, |
| 6081 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 6082 | fcport->fcp_prio = priority & 0xf; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 6083 | } else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6084 | ql_dbg(ql_dbg_user, vha, 0x704f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 6085 | "Unable to update FCP_CMND priority - ret=0x%x for " |
| 6086 | "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id, |
| 6087 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 6088 | fcport->d_id.b.al_pa); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 6089 | return ret; |
| 6090 | } |
| 6091 | |
| 6092 | /* |
| 6093 | * qla24xx_update_all_fcp_prio |
| 6094 | * Activates fcp priority for all the logged in ports |
| 6095 | * |
| 6096 | * Input: |
| 6097 | * ha = adapter block pointer. |
| 6098 | * |
| 6099 | * Return: |
| 6100 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 6101 | * |
| 6102 | * Context: |
| 6103 | * Kernel context. |
| 6104 | */ |
| 6105 | int |
| 6106 | qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha) |
| 6107 | { |
| 6108 | int ret; |
| 6109 | fc_port_t *fcport; |
| 6110 | |
| 6111 | ret = QLA_FUNCTION_FAILED; |
| 6112 | /* We need to set priority for all logged in ports */ |
| 6113 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 6114 | ret = qla24xx_update_fcport_fcp_prio(vha, fcport); |
| 6115 | |
| 6116 | return ret; |
| 6117 | } |