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 |
Andrew Vasquez | 07e264b | 2011-03-30 11:46:23 -0700 | [diff] [blame] | 3 | * Copyright (c) 2003-2011 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_init_rings(scsi_qla_host_t *); |
| 29 | static int qla2x00_fw_ready(scsi_qla_host_t *); |
| 30 | static int qla2x00_configure_hba(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | static int qla2x00_configure_loop(scsi_qla_host_t *); |
| 32 | static int qla2x00_configure_local_loop(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | static int qla2x00_configure_fabric(scsi_qla_host_t *); |
| 34 | 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] | 35 | static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *, |
| 36 | uint16_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | static int qla2x00_restart_isp(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 40 | static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *); |
| 41 | static int qla84xx_init_chip(scsi_qla_host_t *); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 42 | static int qla25xx_init_queues(struct qla_hw_data *); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 43 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 44 | /* SRB Extensions ---------------------------------------------------------- */ |
| 45 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 46 | void |
| 47 | qla2x00_sp_timeout(unsigned long __data) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 48 | { |
| 49 | srb_t *sp = (srb_t *)__data; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 50 | struct srb_iocb *iocb; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 51 | fc_port_t *fcport = sp->fcport; |
| 52 | struct qla_hw_data *ha = fcport->vha->hw; |
| 53 | struct req_que *req; |
| 54 | unsigned long flags; |
| 55 | |
| 56 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 57 | req = ha->req_q_map[0]; |
| 58 | req->outstanding_cmds[sp->handle] = NULL; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 59 | iocb = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 60 | iocb->timeout(sp); |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 61 | sp->free(fcport->vha, sp); |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 62 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 65 | void |
| 66 | qla2x00_sp_free(void *data, void *ptr) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 67 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 68 | srb_t *sp = (srb_t *)ptr; |
| 69 | struct srb_iocb *iocb = &sp->u.iocb_cmd; |
| 70 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 71 | |
Chad Dupuis | 4d97cc5 | 2010-10-15 11:27:41 -0700 | [diff] [blame] | 72 | del_timer(&iocb->timer); |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 73 | mempool_free(sp, vha->hw->srb_mempool); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 74 | |
| 75 | QLA_VHA_MARK_NOT_BUSY(vha); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 78 | /* Asynchronous Login/Logout Routines -------------------------------------- */ |
| 79 | |
Saurav Kashyap | a9b6f72 | 2012-08-22 14:21:01 -0400 | [diff] [blame] | 80 | unsigned long |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 81 | qla2x00_get_async_timeout(struct scsi_qla_host *vha) |
| 82 | { |
| 83 | unsigned long tmo; |
| 84 | struct qla_hw_data *ha = vha->hw; |
| 85 | |
| 86 | /* Firmware should use switch negotiated r_a_tov for timeout. */ |
| 87 | tmo = ha->r_a_tov / 10 * 2; |
| 88 | if (!IS_FWI2_CAPABLE(ha)) { |
| 89 | /* |
| 90 | * Except for earlier ISPs where the timeout is seeded from the |
| 91 | * initialization control block. |
| 92 | */ |
| 93 | tmo = ha->login_timeout; |
| 94 | } |
| 95 | return tmo; |
| 96 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 97 | |
| 98 | static void |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 99 | qla2x00_async_iocb_timeout(void *data) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 100 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 101 | srb_t *sp = (srb_t *)data; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 102 | fc_port_t *fcport = sp->fcport; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 103 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 104 | ql_dbg(ql_dbg_disc, fcport->vha, 0x2071, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 105 | "Async-%s timeout - hdl=%x portid=%02x%02x%02x.\n", |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 106 | 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] | 107 | fcport->d_id.b.al_pa); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 108 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 109 | fcport->flags &= ~FCF_ASYNC_SENT; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 110 | if (sp->type == SRB_LOGIN_CMD) { |
| 111 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 112 | qla2x00_post_async_logout_work(fcport->vha, fcport, NULL); |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 113 | /* Retry as needed. */ |
| 114 | lio->u.logio.data[0] = MBS_COMMAND_ERROR; |
| 115 | lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ? |
| 116 | QLA_LOGIO_LOGIN_RETRIED : 0; |
| 117 | qla2x00_post_async_login_done_work(fcport->vha, fcport, |
| 118 | lio->u.logio.data); |
| 119 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 122 | static void |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 123 | qla2x00_async_login_sp_done(void *data, void *ptr, int res) |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 124 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 125 | srb_t *sp = (srb_t *)ptr; |
| 126 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
| 127 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 128 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 129 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
| 130 | qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport, |
| 131 | lio->u.logio.data); |
| 132 | sp->free(sp->fcport->vha, sp); |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 135 | int |
| 136 | qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 137 | uint16_t *data) |
| 138 | { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 139 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 140 | struct srb_iocb *lio; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 141 | int rval; |
| 142 | |
| 143 | rval = QLA_FUNCTION_FAILED; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 144 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 145 | if (!sp) |
| 146 | goto done; |
| 147 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 148 | sp->type = SRB_LOGIN_CMD; |
| 149 | sp->name = "login"; |
| 150 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 151 | |
| 152 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 153 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 154 | sp->done = qla2x00_async_login_sp_done; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 155 | lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 156 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 157 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 158 | rval = qla2x00_start_sp(sp); |
| 159 | if (rval != QLA_SUCCESS) |
| 160 | goto done_free_sp; |
| 161 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 162 | ql_dbg(ql_dbg_disc, vha, 0x2072, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 163 | "Async-login - hdl=%x, loopid=%x portid=%02x%02x%02x " |
| 164 | "retries=%d.\n", sp->handle, fcport->loop_id, |
| 165 | fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 166 | fcport->login_retry); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 167 | return rval; |
| 168 | |
| 169 | done_free_sp: |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 170 | sp->free(fcport->vha, sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 171 | done: |
| 172 | return rval; |
| 173 | } |
| 174 | |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 175 | static void |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 176 | qla2x00_async_logout_sp_done(void *data, void *ptr, int res) |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 177 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 178 | srb_t *sp = (srb_t *)ptr; |
| 179 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
| 180 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 181 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 182 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
| 183 | qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport, |
| 184 | lio->u.logio.data); |
| 185 | sp->free(sp->fcport->vha, sp); |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 188 | int |
| 189 | qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 190 | { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 191 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 192 | struct srb_iocb *lio; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 193 | int rval; |
| 194 | |
| 195 | rval = QLA_FUNCTION_FAILED; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 196 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 197 | if (!sp) |
| 198 | goto done; |
| 199 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 200 | sp->type = SRB_LOGOUT_CMD; |
| 201 | sp->name = "logout"; |
| 202 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 203 | |
| 204 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 205 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 206 | sp->done = qla2x00_async_logout_sp_done; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 207 | rval = qla2x00_start_sp(sp); |
| 208 | if (rval != QLA_SUCCESS) |
| 209 | goto done_free_sp; |
| 210 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 211 | ql_dbg(ql_dbg_disc, vha, 0x2070, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 212 | "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x.\n", |
| 213 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
| 214 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 215 | return rval; |
| 216 | |
| 217 | done_free_sp: |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 218 | sp->free(fcport->vha, sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 219 | done: |
| 220 | return rval; |
| 221 | } |
| 222 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 223 | static void |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 224 | qla2x00_async_adisc_sp_done(void *data, void *ptr, int res) |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 225 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 226 | srb_t *sp = (srb_t *)ptr; |
| 227 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
| 228 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 229 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 230 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
| 231 | qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport, |
| 232 | lio->u.logio.data); |
| 233 | sp->free(sp->fcport->vha, sp); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | int |
| 237 | qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 238 | uint16_t *data) |
| 239 | { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 240 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 241 | struct srb_iocb *lio; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 242 | int rval; |
| 243 | |
| 244 | rval = QLA_FUNCTION_FAILED; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 245 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 246 | if (!sp) |
| 247 | goto done; |
| 248 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 249 | sp->type = SRB_ADISC_CMD; |
| 250 | sp->name = "adisc"; |
| 251 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 252 | |
| 253 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 254 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 255 | sp->done = qla2x00_async_adisc_sp_done; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 256 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 257 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 258 | rval = qla2x00_start_sp(sp); |
| 259 | if (rval != QLA_SUCCESS) |
| 260 | goto done_free_sp; |
| 261 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 262 | ql_dbg(ql_dbg_disc, vha, 0x206f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 263 | "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n", |
| 264 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
| 265 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 266 | return rval; |
| 267 | |
| 268 | done_free_sp: |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 269 | sp->free(fcport->vha, sp); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 270 | done: |
| 271 | return rval; |
| 272 | } |
| 273 | |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 274 | static void |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 275 | qla2x00_async_tm_cmd_done(void *data, void *ptr, int res) |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 276 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 277 | srb_t *sp = (srb_t *)ptr; |
| 278 | struct srb_iocb *iocb = &sp->u.iocb_cmd; |
| 279 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; |
| 280 | uint32_t flags; |
| 281 | uint16_t lun; |
| 282 | int rval; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 283 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 284 | if (!test_bit(UNLOADING, &vha->dpc_flags)) { |
| 285 | flags = iocb->u.tmf.flags; |
| 286 | lun = (uint16_t)iocb->u.tmf.lun; |
| 287 | |
| 288 | /* Issue Marker IOCB */ |
| 289 | rval = qla2x00_marker(vha, vha->hw->req_q_map[0], |
| 290 | vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun, |
| 291 | flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID); |
| 292 | |
| 293 | if ((rval != QLA_SUCCESS) || iocb->u.tmf.data) { |
| 294 | ql_dbg(ql_dbg_taskm, vha, 0x8030, |
| 295 | "TM IOCB failed (%x).\n", rval); |
| 296 | } |
| 297 | } |
| 298 | sp->free(sp->fcport->vha, sp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | int |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 302 | 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] | 303 | uint32_t tag) |
| 304 | { |
| 305 | struct scsi_qla_host *vha = fcport->vha; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 306 | srb_t *sp; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 307 | struct srb_iocb *tcf; |
| 308 | int rval; |
| 309 | |
| 310 | rval = QLA_FUNCTION_FAILED; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 311 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 312 | if (!sp) |
| 313 | goto done; |
| 314 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 315 | sp->type = SRB_TM_CMD; |
| 316 | sp->name = "tmf"; |
| 317 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 318 | |
| 319 | tcf = &sp->u.iocb_cmd; |
| 320 | tcf->u.tmf.flags = tm_flags; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 321 | tcf->u.tmf.lun = lun; |
| 322 | tcf->u.tmf.data = tag; |
| 323 | tcf->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 324 | sp->done = qla2x00_async_tm_cmd_done; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 325 | |
| 326 | rval = qla2x00_start_sp(sp); |
| 327 | if (rval != QLA_SUCCESS) |
| 328 | goto done_free_sp; |
| 329 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 330 | ql_dbg(ql_dbg_taskm, vha, 0x802f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 331 | "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n", |
| 332 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
| 333 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 334 | return rval; |
| 335 | |
| 336 | done_free_sp: |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 337 | sp->free(fcport->vha, sp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 338 | done: |
| 339 | return rval; |
| 340 | } |
| 341 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 342 | void |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 343 | qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 344 | uint16_t *data) |
| 345 | { |
| 346 | int rval; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 347 | |
| 348 | switch (data[0]) { |
| 349 | case MBS_COMMAND_COMPLETE: |
Andrew Vasquez | a4f92a3 | 2011-03-30 11:46:31 -0700 | [diff] [blame] | 350 | /* |
| 351 | * Driver must validate login state - If PRLI not complete, |
| 352 | * force a relogin attempt via implicit LOGO, PLOGI, and PRLI |
| 353 | * requests. |
| 354 | */ |
| 355 | rval = qla2x00_get_port_database(vha, fcport, 0); |
Arun Easi | 0eba25d | 2012-02-09 11:15:58 -0800 | [diff] [blame] | 356 | if (rval == QLA_NOT_LOGGED_IN) { |
| 357 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 358 | fcport->flags |= FCF_LOGIN_NEEDED; |
| 359 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 360 | break; |
| 361 | } |
| 362 | |
Andrew Vasquez | a4f92a3 | 2011-03-30 11:46:31 -0700 | [diff] [blame] | 363 | if (rval != QLA_SUCCESS) { |
| 364 | qla2x00_post_async_logout_work(vha, fcport, NULL); |
| 365 | qla2x00_post_async_login_work(vha, fcport, NULL); |
| 366 | break; |
| 367 | } |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 368 | if (fcport->flags & FCF_FCP2_DEVICE) { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 369 | qla2x00_post_async_adisc_work(vha, fcport, data); |
| 370 | break; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 371 | } |
| 372 | qla2x00_update_fcport(vha, fcport); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 373 | break; |
| 374 | case MBS_COMMAND_ERROR: |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 375 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 376 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
| 377 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 378 | else |
Andrew Vasquez | 80d7944 | 2011-03-30 11:46:17 -0700 | [diff] [blame] | 379 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 380 | break; |
| 381 | case MBS_PORT_ID_USED: |
| 382 | fcport->loop_id = data[1]; |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 383 | qla2x00_post_async_logout_work(vha, fcport, NULL); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 384 | qla2x00_post_async_login_work(vha, fcport, NULL); |
| 385 | break; |
| 386 | case MBS_LOOP_ID_USED: |
| 387 | fcport->loop_id++; |
| 388 | rval = qla2x00_find_new_loop_id(vha, fcport); |
| 389 | if (rval != QLA_SUCCESS) { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 390 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | 80d7944 | 2011-03-30 11:46:17 -0700 | [diff] [blame] | 391 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 392 | break; |
| 393 | } |
| 394 | qla2x00_post_async_login_work(vha, fcport, NULL); |
| 395 | break; |
| 396 | } |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 397 | return; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 400 | void |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 401 | qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 402 | uint16_t *data) |
| 403 | { |
| 404 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 405 | return; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 406 | } |
| 407 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 408 | void |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 409 | qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 410 | uint16_t *data) |
| 411 | { |
| 412 | if (data[0] == MBS_COMMAND_COMPLETE) { |
| 413 | qla2x00_update_fcport(vha, fcport); |
| 414 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 415 | return; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | /* Retry login. */ |
| 419 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 420 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
| 421 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 422 | else |
Andrew Vasquez | 80d7944 | 2011-03-30 11:46:17 -0700 | [diff] [blame] | 423 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 424 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 425 | return; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | /****************************************************************************/ |
| 429 | /* QLogic ISP2x00 Hardware Support Functions. */ |
| 430 | /****************************************************************************/ |
| 431 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame^] | 432 | int |
| 433 | qla83xx_nic_core_fw_load(scsi_qla_host_t *vha) |
| 434 | { |
| 435 | int rval = QLA_SUCCESS; |
| 436 | struct qla_hw_data *ha = vha->hw; |
| 437 | uint32_t idc_major_ver, idc_minor_ver; |
| 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 | |
| 489 | rval = qla83xx_idc_state_handler(vha); |
| 490 | |
| 491 | exit: |
| 492 | qla83xx_idc_unlock(vha, 0); |
| 493 | |
| 494 | return rval; |
| 495 | } |
| 496 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | /* |
| 498 | * qla2x00_initialize_adapter |
| 499 | * Initialize board. |
| 500 | * |
| 501 | * Input: |
| 502 | * ha = adapter block pointer. |
| 503 | * |
| 504 | * Returns: |
| 505 | * 0 = success |
| 506 | */ |
| 507 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 508 | qla2x00_initialize_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | { |
| 510 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 511 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 512 | struct req_que *req = ha->req_q_map[0]; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 513 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | /* Clear adapter flags. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 515 | vha->flags.online = 0; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 516 | ha->flags.chip_reset_done = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 517 | vha->flags.reset_active = 0; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 518 | ha->flags.pci_channel_io_perm_failure = 0; |
| 519 | ha->flags.eeh_busy = 0; |
Andrew Vasquez | 794a569 | 2010-12-21 16:00:21 -0800 | [diff] [blame] | 520 | ha->flags.thermal_supported = 1; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 521 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 522 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 523 | vha->device_flags = DFLG_NO_CABLE; |
| 524 | vha->dpc_flags = 0; |
| 525 | vha->flags.management_server_logged_in = 0; |
| 526 | vha->marker_needed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | ha->isp_abort_cnt = 0; |
| 528 | ha->beacon_blink_led = 0; |
| 529 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 530 | set_bit(0, ha->req_qid_map); |
| 531 | set_bit(0, ha->rsp_qid_map); |
| 532 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 533 | ql_dbg(ql_dbg_init, vha, 0x0040, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 534 | "Configuring PCI space...\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 535 | rval = ha->isp_ops->pci_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 537 | ql_log(ql_log_warn, vha, 0x0044, |
| 538 | "Unable to configure PCI space.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | return (rval); |
| 540 | } |
| 541 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 542 | ha->isp_ops->reset_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 544 | rval = qla2xxx_get_flash_info(vha); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 545 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 546 | ql_log(ql_log_fatal, vha, 0x004f, |
| 547 | "Unable to validate FLASH data.\n"); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 548 | return (rval); |
| 549 | } |
| 550 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 551 | ha->isp_ops->get_flash_version(vha, req->ring); |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 552 | ql_dbg(ql_dbg_init, vha, 0x0061, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 553 | "Configure NVRAM parameters...\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 554 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 555 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 557 | if (ha->flags.disable_serdes) { |
| 558 | /* Mask HBA via NVRAM settings? */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 559 | ql_log(ql_log_info, vha, 0x0077, |
| 560 | "Masking HBA WWPN " |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 561 | "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 562 | vha->port_name[0], vha->port_name[1], |
| 563 | vha->port_name[2], vha->port_name[3], |
| 564 | vha->port_name[4], vha->port_name[5], |
| 565 | vha->port_name[6], vha->port_name[7]); |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 566 | return QLA_FUNCTION_FAILED; |
| 567 | } |
| 568 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 569 | ql_dbg(ql_dbg_init, vha, 0x0078, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 570 | "Verifying loaded RISC code...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 572 | if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) { |
| 573 | rval = ha->isp_ops->chip_diag(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 574 | if (rval) |
| 575 | return (rval); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 576 | rval = qla2x00_setup_chip(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 577 | if (rval) |
| 578 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 580 | |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 581 | if (IS_QLA84XX(ha)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 582 | ha->cs84xx = qla84xx_get_chip(vha); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 583 | if (!ha->cs84xx) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 584 | ql_log(ql_log_warn, vha, 0x00d0, |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 585 | "Unable to configure ISP84XX.\n"); |
| 586 | return QLA_FUNCTION_FAILED; |
| 587 | } |
| 588 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 589 | |
| 590 | if (qla_ini_mode_enabled(vha)) |
| 591 | rval = qla2x00_init_rings(vha); |
| 592 | |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 593 | ha->flags.chip_reset_done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 595 | if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) { |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 596 | /* Issue verify 84xx FW IOCB to complete 84xx initialization */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 597 | rval = qla84xx_init_chip(vha); |
| 598 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 599 | ql_log(ql_log_warn, vha, 0x00d4, |
| 600 | "Unable to initialize ISP84XX.\n"); |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 601 | qla84xx_put_chip(vha); |
| 602 | } |
| 603 | } |
| 604 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame^] | 605 | /* Load the NIC Core f/w if we are the first protocol driver. */ |
| 606 | if (IS_QLA8031(ha)) { |
| 607 | rval = qla83xx_nic_core_fw_load(vha); |
| 608 | if (rval) |
| 609 | ql_log(ql_log_warn, vha, 0x0124, |
| 610 | "Error in initializing NIC Core f/w.\n"); |
| 611 | } |
| 612 | |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 613 | if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)) |
| 614 | qla24xx_read_fcp_prio_cfg(vha); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 615 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | return (rval); |
| 617 | } |
| 618 | |
| 619 | /** |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 620 | * qla2100_pci_config() - Setup ISP21xx PCI configuration registers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | * @ha: HA context |
| 622 | * |
| 623 | * Returns 0 on success. |
| 624 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 625 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 626 | qla2100_pci_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 628 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 629 | unsigned long flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 630 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 631 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 634 | pci_try_set_mwi(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 637 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 639 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 640 | pci_disable_rom(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 642 | /* Get PCI bus information. */ |
| 643 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 644 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 645 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 646 | |
| 647 | return QLA_SUCCESS; |
| 648 | } |
| 649 | |
| 650 | /** |
| 651 | * qla2300_pci_config() - Setup ISP23xx PCI configuration registers. |
| 652 | * @ha: HA context |
| 653 | * |
| 654 | * Returns 0 on success. |
| 655 | */ |
| 656 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 657 | qla2300_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 658 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 659 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 660 | unsigned long flags = 0; |
| 661 | uint32_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 662 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 663 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 664 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 665 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 666 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 667 | |
| 668 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 669 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 670 | |
| 671 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 672 | w &= ~PCI_COMMAND_INTX_DISABLE; |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 673 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 674 | |
| 675 | /* |
| 676 | * If this is a 2300 card and not 2312, reset the |
| 677 | * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately, |
| 678 | * the 2310 also reports itself as a 2300 so we need to get the |
| 679 | * fb revision level -- a 6 indicates it really is a 2300 and |
| 680 | * not a 2310. |
| 681 | */ |
| 682 | if (IS_QLA2300(ha)) { |
| 683 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 684 | |
| 685 | /* Pause RISC. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 686 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 687 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 688 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 689 | break; |
| 690 | |
| 691 | udelay(10); |
| 692 | } |
| 693 | |
| 694 | /* Select FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 695 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 696 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 697 | |
| 698 | /* Get the fb rev level */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 699 | ha->fb_rev = RD_FB_CMD_REG(ha, reg); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 700 | |
| 701 | if (ha->fb_rev == FPM_2300) |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 702 | pci_clear_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 703 | |
| 704 | /* Deselect FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 705 | WRT_REG_WORD(®->ctrl_status, 0x0); |
| 706 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 707 | |
| 708 | /* Release RISC module. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 709 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 710 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 711 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 712 | break; |
| 713 | |
| 714 | udelay(10); |
| 715 | } |
| 716 | |
| 717 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 718 | } |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 719 | |
| 720 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 721 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 722 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 723 | |
| 724 | /* Get PCI bus information. */ |
| 725 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 726 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 727 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 728 | |
| 729 | return QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 733 | * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers. |
| 734 | * @ha: HA context |
| 735 | * |
| 736 | * Returns 0 on success. |
| 737 | */ |
| 738 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 739 | qla24xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 740 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 741 | uint16_t w; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 742 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 743 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 744 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 745 | |
| 746 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 747 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 748 | |
| 749 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 750 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 751 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 752 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 753 | |
| 754 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 755 | |
| 756 | /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */ |
Andrew Vasquez | f85ec18 | 2007-07-19 15:06:01 -0700 | [diff] [blame] | 757 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX)) |
| 758 | pcix_set_mmrbc(ha->pdev, 2048); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 759 | |
| 760 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Jon Mason | e67f132 | 2012-07-10 14:57:56 -0700 | [diff] [blame] | 761 | if (pci_is_pcie(ha->pdev)) |
Andrew Vasquez | f85ec18 | 2007-07-19 15:06:01 -0700 | [diff] [blame] | 762 | pcie_set_readrq(ha->pdev, 2048); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 763 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 764 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 765 | |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 766 | ha->chip_revision = ha->pdev->revision; |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 767 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 768 | /* Get PCI bus information. */ |
| 769 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 770 | ha->pci_attr = RD_REG_DWORD(®->ctrl_status); |
| 771 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 772 | |
| 773 | return QLA_SUCCESS; |
| 774 | } |
| 775 | |
| 776 | /** |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 777 | * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers. |
| 778 | * @ha: HA context |
| 779 | * |
| 780 | * Returns 0 on success. |
| 781 | */ |
| 782 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 783 | qla25xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 784 | { |
| 785 | uint16_t w; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 786 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 787 | |
| 788 | pci_set_master(ha->pdev); |
| 789 | pci_try_set_mwi(ha->pdev); |
| 790 | |
| 791 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
| 792 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
| 793 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 794 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 795 | |
| 796 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Jon Mason | e67f132 | 2012-07-10 14:57:56 -0700 | [diff] [blame] | 797 | if (pci_is_pcie(ha->pdev)) |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 798 | pcie_set_readrq(ha->pdev, 2048); |
| 799 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 800 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 801 | |
| 802 | ha->chip_revision = ha->pdev->revision; |
| 803 | |
| 804 | return QLA_SUCCESS; |
| 805 | } |
| 806 | |
| 807 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | * qla2x00_isp_firmware() - Choose firmware image. |
| 809 | * @ha: HA context |
| 810 | * |
| 811 | * Returns 0 on success. |
| 812 | */ |
| 813 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 814 | qla2x00_isp_firmware(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | { |
| 816 | int rval; |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 817 | uint16_t loop_id, topo, sw_cap; |
| 818 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 819 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | |
| 821 | /* Assume loading risc code */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 822 | rval = QLA_FUNCTION_FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | |
| 824 | if (ha->flags.disable_risc_code_load) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 825 | ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | |
| 827 | /* Verify checksum of loaded RISC code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 828 | rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address); |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 829 | if (rval == QLA_SUCCESS) { |
| 830 | /* And, verify we are not in ROM code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 831 | rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa, |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 832 | &area, &domain, &topo, &sw_cap); |
| 833 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | } |
| 835 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 836 | if (rval) |
| 837 | ql_dbg(ql_dbg_init, vha, 0x007a, |
| 838 | "**** Load RISC code ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | |
| 840 | return (rval); |
| 841 | } |
| 842 | |
| 843 | /** |
| 844 | * qla2x00_reset_chip() - Reset ISP chip. |
| 845 | * @ha: HA context |
| 846 | * |
| 847 | * Returns 0 on success. |
| 848 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 849 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 850 | qla2x00_reset_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | { |
| 852 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 853 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 854 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | uint32_t cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | uint16_t cmd; |
| 857 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 858 | if (unlikely(pci_channel_offline(ha->pdev))) |
| 859 | return; |
| 860 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 861 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | |
| 863 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 864 | |
| 865 | /* Turn off master enable */ |
| 866 | cmd = 0; |
| 867 | pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd); |
| 868 | cmd &= ~PCI_COMMAND_MASTER; |
| 869 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 870 | |
| 871 | if (!IS_QLA2100(ha)) { |
| 872 | /* Pause RISC. */ |
| 873 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
| 874 | if (IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 875 | for (cnt = 0; cnt < 30000; cnt++) { |
| 876 | if ((RD_REG_WORD(®->hccr) & |
| 877 | HCCR_RISC_PAUSE) != 0) |
| 878 | break; |
| 879 | udelay(100); |
| 880 | } |
| 881 | } else { |
| 882 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 883 | udelay(10); |
| 884 | } |
| 885 | |
| 886 | /* Select FPM registers. */ |
| 887 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 888 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 889 | |
| 890 | /* FPM Soft Reset. */ |
| 891 | WRT_REG_WORD(®->fpm_diag_config, 0x100); |
| 892 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 893 | |
| 894 | /* Toggle Fpm Reset. */ |
| 895 | if (!IS_QLA2200(ha)) { |
| 896 | WRT_REG_WORD(®->fpm_diag_config, 0x0); |
| 897 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 898 | } |
| 899 | |
| 900 | /* Select frame buffer registers. */ |
| 901 | WRT_REG_WORD(®->ctrl_status, 0x10); |
| 902 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 903 | |
| 904 | /* Reset frame buffer FIFOs. */ |
| 905 | if (IS_QLA2200(ha)) { |
| 906 | WRT_FB_CMD_REG(ha, reg, 0xa000); |
| 907 | RD_FB_CMD_REG(ha, reg); /* PCI Posting. */ |
| 908 | } else { |
| 909 | WRT_FB_CMD_REG(ha, reg, 0x00fc); |
| 910 | |
| 911 | /* Read back fb_cmd until zero or 3 seconds max */ |
| 912 | for (cnt = 0; cnt < 3000; cnt++) { |
| 913 | if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0) |
| 914 | break; |
| 915 | udelay(100); |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | /* Select RISC module registers. */ |
| 920 | WRT_REG_WORD(®->ctrl_status, 0); |
| 921 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 922 | |
| 923 | /* Reset RISC processor. */ |
| 924 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 925 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 926 | |
| 927 | /* Release RISC processor. */ |
| 928 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 929 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 930 | } |
| 931 | |
| 932 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); |
| 933 | WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT); |
| 934 | |
| 935 | /* Reset ISP chip. */ |
| 936 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 937 | |
| 938 | /* Wait for RISC to recover from reset. */ |
| 939 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 940 | /* |
| 941 | * It is necessary to for a delay here since the card doesn't |
| 942 | * respond to PCI reads during a reset. On some architectures |
| 943 | * this will result in an MCA. |
| 944 | */ |
| 945 | udelay(20); |
| 946 | for (cnt = 30000; cnt; cnt--) { |
| 947 | if ((RD_REG_WORD(®->ctrl_status) & |
| 948 | CSR_ISP_SOFT_RESET) == 0) |
| 949 | break; |
| 950 | udelay(100); |
| 951 | } |
| 952 | } else |
| 953 | udelay(10); |
| 954 | |
| 955 | /* Reset RISC processor. */ |
| 956 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 957 | |
| 958 | WRT_REG_WORD(®->semaphore, 0); |
| 959 | |
| 960 | /* Release RISC processor. */ |
| 961 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 962 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 963 | |
| 964 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 965 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | ffb39f0 | 2006-05-17 15:09:06 -0700 | [diff] [blame] | 966 | if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | |
| 969 | udelay(100); |
| 970 | } |
| 971 | } else |
| 972 | udelay(100); |
| 973 | |
| 974 | /* Turn on master enable */ |
| 975 | cmd |= PCI_COMMAND_MASTER; |
| 976 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 977 | |
| 978 | /* Disable RISC pause on FPM parity error. */ |
| 979 | if (!IS_QLA2100(ha)) { |
| 980 | WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE); |
| 981 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 982 | } |
| 983 | |
| 984 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 985 | } |
| 986 | |
| 987 | /** |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 988 | * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC. |
| 989 | * |
| 990 | * Returns 0 on success. |
| 991 | */ |
| 992 | int |
| 993 | qla81xx_reset_mpi(scsi_qla_host_t *vha) |
| 994 | { |
| 995 | uint16_t mb[4] = {0x1010, 0, 1, 0}; |
| 996 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 997 | if (!IS_QLA81XX(vha->hw)) |
| 998 | return QLA_SUCCESS; |
| 999 | |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 1000 | return qla81xx_write_mpi_register(vha, mb); |
| 1001 | } |
| 1002 | |
| 1003 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1004 | * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC. |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1005 | * @ha: HA context |
| 1006 | * |
| 1007 | * Returns 0 on success. |
| 1008 | */ |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1009 | static inline void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1010 | qla24xx_reset_risc(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1011 | { |
| 1012 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1013 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1014 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 1015 | uint32_t cnt, d2; |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 1016 | uint16_t wd; |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 1017 | static int abts_cnt; /* ISP abort retry counts */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1018 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1019 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1020 | |
| 1021 | /* Reset RISC. */ |
| 1022 | WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
| 1023 | for (cnt = 0; cnt < 30000; cnt++) { |
| 1024 | if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0) |
| 1025 | break; |
| 1026 | |
| 1027 | udelay(10); |
| 1028 | } |
| 1029 | |
| 1030 | WRT_REG_DWORD(®->ctrl_status, |
| 1031 | CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 1032 | pci_read_config_word(ha->pdev, PCI_COMMAND, &wd); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1033 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 1034 | udelay(100); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1035 | /* Wait for firmware to complete NVRAM accesses. */ |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1036 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 1037 | for (cnt = 10000 ; cnt && d2; cnt--) { |
| 1038 | udelay(5); |
| 1039 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 1040 | barrier(); |
| 1041 | } |
| 1042 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 1043 | /* Wait for soft-reset to complete. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1044 | d2 = RD_REG_DWORD(®->ctrl_status); |
| 1045 | for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) { |
| 1046 | udelay(5); |
| 1047 | d2 = RD_REG_DWORD(®->ctrl_status); |
| 1048 | barrier(); |
| 1049 | } |
| 1050 | |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 1051 | /* If required, do an MPI FW reset now */ |
| 1052 | if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) { |
| 1053 | if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) { |
| 1054 | if (++abts_cnt < 5) { |
| 1055 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 1056 | set_bit(MPI_RESET_NEEDED, &vha->dpc_flags); |
| 1057 | } else { |
| 1058 | /* |
| 1059 | * We exhausted the ISP abort retries. We have to |
| 1060 | * set the board offline. |
| 1061 | */ |
| 1062 | abts_cnt = 0; |
| 1063 | vha->flags.online = 0; |
| 1064 | } |
| 1065 | } |
| 1066 | } |
| 1067 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1068 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 1069 | RD_REG_DWORD(®->hccr); |
| 1070 | |
| 1071 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 1072 | RD_REG_DWORD(®->hccr); |
| 1073 | |
| 1074 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET); |
| 1075 | RD_REG_DWORD(®->hccr); |
| 1076 | |
| 1077 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 1078 | for (cnt = 6000000 ; cnt && d2; cnt--) { |
| 1079 | udelay(5); |
| 1080 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 1081 | barrier(); |
| 1082 | } |
| 1083 | |
| 1084 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 124f85e | 2009-01-05 11:18:06 -0800 | [diff] [blame] | 1085 | |
| 1086 | if (IS_NOPOLLING_TYPE(ha)) |
| 1087 | ha->isp_ops->enable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1091 | * qla24xx_reset_chip() - Reset ISP24xx chip. |
| 1092 | * @ha: HA context |
| 1093 | * |
| 1094 | * Returns 0 on success. |
| 1095 | */ |
| 1096 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1097 | qla24xx_reset_chip(scsi_qla_host_t *vha) |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1098 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1099 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 1100 | |
| 1101 | if (pci_channel_offline(ha->pdev) && |
| 1102 | ha->flags.pci_channel_io_perm_failure) { |
| 1103 | return; |
| 1104 | } |
| 1105 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1106 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1107 | |
| 1108 | /* Perform RISC reset. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1109 | qla24xx_reset_risc(vha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | * qla2x00_chip_diag() - Test chip for proper operation. |
| 1114 | * @ha: HA context |
| 1115 | * |
| 1116 | * Returns 0 on success. |
| 1117 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1118 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1119 | qla2x00_chip_diag(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | { |
| 1121 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1122 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1123 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | unsigned long flags = 0; |
| 1125 | uint16_t data; |
| 1126 | uint32_t cnt; |
| 1127 | uint16_t mb[5]; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1128 | struct req_que *req = ha->req_q_map[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | |
| 1130 | /* Assume a failed state */ |
| 1131 | rval = QLA_FUNCTION_FAILED; |
| 1132 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1133 | ql_dbg(ql_dbg_init, vha, 0x007b, |
| 1134 | "Testing device at %lx.\n", (u_long)®->flash_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | |
| 1136 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1137 | |
| 1138 | /* Reset ISP chip. */ |
| 1139 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 1140 | |
| 1141 | /* |
| 1142 | * We need to have a delay here since the card will not respond while |
| 1143 | * in reset causing an MCA on some architectures. |
| 1144 | */ |
| 1145 | udelay(20); |
| 1146 | data = qla2x00_debounce_register(®->ctrl_status); |
| 1147 | for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) { |
| 1148 | udelay(5); |
| 1149 | data = RD_REG_WORD(®->ctrl_status); |
| 1150 | barrier(); |
| 1151 | } |
| 1152 | |
| 1153 | if (!cnt) |
| 1154 | goto chip_diag_failed; |
| 1155 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1156 | ql_dbg(ql_dbg_init, vha, 0x007c, |
| 1157 | "Reset register cleared by chip reset.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | |
| 1159 | /* Reset RISC processor. */ |
| 1160 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 1161 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 1162 | |
| 1163 | /* Workaround for QLA2312 PCI parity error */ |
| 1164 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 1165 | data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0)); |
| 1166 | for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) { |
| 1167 | udelay(5); |
| 1168 | data = RD_MAILBOX_REG(ha, reg, 0); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1169 | barrier(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | } |
| 1171 | } else |
| 1172 | udelay(10); |
| 1173 | |
| 1174 | if (!cnt) |
| 1175 | goto chip_diag_failed; |
| 1176 | |
| 1177 | /* Check product ID of chip */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1178 | 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] | 1179 | |
| 1180 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); |
| 1181 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); |
| 1182 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); |
| 1183 | mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4)); |
| 1184 | if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) || |
| 1185 | mb[3] != PROD_ID_3) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1186 | ql_log(ql_log_warn, vha, 0x0062, |
| 1187 | "Wrong product ID = 0x%x,0x%x,0x%x.\n", |
| 1188 | mb[1], mb[2], mb[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | |
| 1190 | goto chip_diag_failed; |
| 1191 | } |
| 1192 | ha->product_id[0] = mb[1]; |
| 1193 | ha->product_id[1] = mb[2]; |
| 1194 | ha->product_id[2] = mb[3]; |
| 1195 | ha->product_id[3] = mb[4]; |
| 1196 | |
| 1197 | /* Adjust fw RISC transfer size */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1198 | if (req->length > 1024) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024; |
| 1200 | else |
| 1201 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1202 | req->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | |
| 1204 | if (IS_QLA2200(ha) && |
| 1205 | RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) { |
| 1206 | /* Limit firmware transfer size with a 2200A */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1207 | ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1209 | ha->device_type |= DT_ISP2200A; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | ha->fw_transfer_size = 128; |
| 1211 | } |
| 1212 | |
| 1213 | /* Wrap Incoming Mailboxes Test. */ |
| 1214 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1215 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1216 | ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1217 | rval = qla2x00_mbx_reg_test(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1218 | if (rval) |
| 1219 | ql_log(ql_log_warn, vha, 0x0080, |
| 1220 | "Failed mailbox send register test.\n"); |
| 1221 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | /* Flag a successful rval */ |
| 1223 | rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1225 | |
| 1226 | chip_diag_failed: |
| 1227 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1228 | ql_log(ql_log_info, vha, 0x0081, |
| 1229 | "Chip diagnostics **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | |
| 1231 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1232 | |
| 1233 | return (rval); |
| 1234 | } |
| 1235 | |
| 1236 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1237 | * qla24xx_chip_diag() - Test ISP24xx for proper operation. |
| 1238 | * @ha: HA context |
| 1239 | * |
| 1240 | * Returns 0 on success. |
| 1241 | */ |
| 1242 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1243 | qla24xx_chip_diag(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1244 | { |
| 1245 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1246 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1247 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1248 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1249 | if (IS_QLA82XX(ha)) |
| 1250 | return QLA_SUCCESS; |
| 1251 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1252 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1253 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1254 | rval = qla2x00_mbx_reg_test(vha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1255 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1256 | ql_log(ql_log_warn, vha, 0x0082, |
| 1257 | "Failed mailbox send register test.\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1258 | } else { |
| 1259 | /* Flag a successful rval */ |
| 1260 | rval = QLA_SUCCESS; |
| 1261 | } |
| 1262 | |
| 1263 | return rval; |
| 1264 | } |
| 1265 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1266 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1267 | qla2x00_alloc_fw_dump(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1268 | { |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1269 | int rval; |
| 1270 | 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] | 1271 | eft_size, fce_size, mq_size; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1272 | dma_addr_t tc_dma; |
| 1273 | void *tc; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1274 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1275 | struct req_que *req = ha->req_q_map[0]; |
| 1276 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 1277 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1278 | if (ha->fw_dump) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1279 | ql_dbg(ql_dbg_init, vha, 0x00bd, |
| 1280 | "Firmware dump already allocated.\n"); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1281 | return; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 1282 | } |
| 1283 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1284 | ha->fw_dumped = 0; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1285 | fixed_size = mem_size = eft_size = fce_size = mq_size = 0; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1286 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 1287 | fixed_size = sizeof(struct qla2100_fw_dump); |
| 1288 | } else if (IS_QLA23XX(ha)) { |
| 1289 | fixed_size = offsetof(struct qla2300_fw_dump, data_ram); |
| 1290 | mem_size = (ha->fw_memory_size - 0x11000 + 1) * |
| 1291 | sizeof(uint16_t); |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 1292 | } else if (IS_FWI2_CAPABLE(ha)) { |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1293 | if (IS_QLA83XX(ha)) |
| 1294 | fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem); |
| 1295 | else if (IS_QLA81XX(ha)) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1296 | fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem); |
| 1297 | else if (IS_QLA25XX(ha)) |
| 1298 | fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem); |
| 1299 | else |
| 1300 | fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1301 | mem_size = (ha->fw_memory_size - 0x100000 + 1) * |
| 1302 | sizeof(uint32_t); |
Giridhar Malavali | 050c9bb | 2012-02-09 11:15:33 -0800 | [diff] [blame] | 1303 | if (ha->mqenable) { |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1304 | if (!IS_QLA83XX(ha)) |
| 1305 | mq_size = sizeof(struct qla2xxx_mq_chain); |
Giridhar Malavali | 050c9bb | 2012-02-09 11:15:33 -0800 | [diff] [blame] | 1306 | /* |
| 1307 | * Allocate maximum buffer size for all queues. |
| 1308 | * Resizing must be done at end-of-dump processing. |
| 1309 | */ |
| 1310 | mq_size += ha->max_req_queues * |
| 1311 | (req->length * sizeof(request_t)); |
| 1312 | mq_size += ha->max_rsp_queues * |
| 1313 | (rsp->length * sizeof(response_t)); |
| 1314 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1315 | if (ha->tgt.atio_q_length) |
| 1316 | mq_size += ha->tgt.atio_q_length * sizeof(request_t); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1317 | /* Allocate memory for Fibre Channel Event Buffer. */ |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1318 | if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha)) |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1319 | goto try_eft; |
| 1320 | |
| 1321 | tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma, |
| 1322 | GFP_KERNEL); |
| 1323 | if (!tc) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1324 | ql_log(ql_log_warn, vha, 0x00be, |
| 1325 | "Unable to allocate (%d KB) for FCE.\n", |
| 1326 | FCE_SIZE / 1024); |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 1327 | goto try_eft; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | memset(tc, 0, FCE_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1331 | rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1332 | ha->fce_mb, &ha->fce_bufs); |
| 1333 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1334 | ql_log(ql_log_warn, vha, 0x00bf, |
| 1335 | "Unable to initialize FCE (%d).\n", rval); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1336 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, |
| 1337 | tc_dma); |
| 1338 | ha->flags.fce_enabled = 0; |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 1339 | goto try_eft; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1340 | } |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1341 | ql_dbg(ql_dbg_init, vha, 0x00c0, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1342 | "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1343 | |
Giridhar Malavali | 7d9dade | 2009-03-24 09:07:58 -0700 | [diff] [blame] | 1344 | fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1345 | ha->flags.fce_enabled = 1; |
| 1346 | ha->fce_dma = tc_dma; |
| 1347 | ha->fce = tc; |
| 1348 | try_eft: |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1349 | /* Allocate memory for Extended Trace Buffer. */ |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1350 | tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma, |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1351 | GFP_KERNEL); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1352 | if (!tc) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1353 | ql_log(ql_log_warn, vha, 0x00c1, |
| 1354 | "Unable to allocate (%d KB) for EFT.\n", |
| 1355 | EFT_SIZE / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1356 | goto cont_alloc; |
| 1357 | } |
| 1358 | |
Andrew Vasquez | fc44765 | 2008-01-17 09:02:18 -0800 | [diff] [blame] | 1359 | memset(tc, 0, EFT_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1360 | rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1361 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1362 | ql_log(ql_log_warn, vha, 0x00c2, |
| 1363 | "Unable to initialize EFT (%d).\n", rval); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1364 | dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, |
| 1365 | tc_dma); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1366 | goto cont_alloc; |
| 1367 | } |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1368 | ql_dbg(ql_dbg_init, vha, 0x00c3, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1369 | "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1370 | |
| 1371 | eft_size = EFT_SIZE; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1372 | ha->eft_dma = tc_dma; |
| 1373 | ha->eft = tc; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1374 | } |
| 1375 | cont_alloc: |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1376 | req_q_size = req->length * sizeof(request_t); |
| 1377 | rsp_q_size = rsp->length * sizeof(response_t); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1378 | |
| 1379 | dump_size = offsetof(struct qla2xxx_fw_dump, isp); |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1380 | 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] | 1381 | ha->chain_offset = dump_size; |
| 1382 | dump_size += mq_size + fce_size; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1383 | |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 1384 | ha->fw_dump = vmalloc(dump_size); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1385 | if (!ha->fw_dump) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1386 | ql_log(ql_log_warn, vha, 0x00c4, |
| 1387 | "Unable to allocate (%d KB) for firmware dump.\n", |
| 1388 | dump_size / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1389 | |
Madhuranath Iyengar | e30d175 | 2010-10-15 11:27:46 -0700 | [diff] [blame] | 1390 | if (ha->fce) { |
| 1391 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce, |
| 1392 | ha->fce_dma); |
| 1393 | ha->fce = NULL; |
| 1394 | ha->fce_dma = 0; |
| 1395 | } |
| 1396 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1397 | if (ha->eft) { |
| 1398 | dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft, |
| 1399 | ha->eft_dma); |
| 1400 | ha->eft = NULL; |
| 1401 | ha->eft_dma = 0; |
| 1402 | } |
| 1403 | return; |
| 1404 | } |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1405 | ql_dbg(ql_dbg_init, vha, 0x00c5, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1406 | "Allocated (%d KB) for firmware dump.\n", dump_size / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1407 | |
| 1408 | ha->fw_dump_len = dump_size; |
| 1409 | ha->fw_dump->signature[0] = 'Q'; |
| 1410 | ha->fw_dump->signature[1] = 'L'; |
| 1411 | ha->fw_dump->signature[2] = 'G'; |
| 1412 | ha->fw_dump->signature[3] = 'C'; |
| 1413 | ha->fw_dump->version = __constant_htonl(1); |
| 1414 | |
| 1415 | ha->fw_dump->fixed_size = htonl(fixed_size); |
| 1416 | ha->fw_dump->mem_size = htonl(mem_size); |
| 1417 | ha->fw_dump->req_q_size = htonl(req_q_size); |
| 1418 | ha->fw_dump->rsp_q_size = htonl(rsp_q_size); |
| 1419 | |
| 1420 | ha->fw_dump->eft_size = htonl(eft_size); |
| 1421 | ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma)); |
| 1422 | ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma)); |
| 1423 | |
| 1424 | ha->fw_dump->header_size = |
| 1425 | htonl(offsetof(struct qla2xxx_fw_dump, isp)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1426 | } |
| 1427 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1428 | static int |
| 1429 | qla81xx_mpi_sync(scsi_qla_host_t *vha) |
| 1430 | { |
| 1431 | #define MPS_MASK 0xe0 |
| 1432 | int rval; |
| 1433 | uint16_t dc; |
| 1434 | uint32_t dw; |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1435 | |
| 1436 | if (!IS_QLA81XX(vha->hw)) |
| 1437 | return QLA_SUCCESS; |
| 1438 | |
| 1439 | rval = qla2x00_write_ram_word(vha, 0x7c00, 1); |
| 1440 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1441 | ql_log(ql_log_warn, vha, 0x0105, |
| 1442 | "Unable to acquire semaphore.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1443 | goto done; |
| 1444 | } |
| 1445 | |
| 1446 | pci_read_config_word(vha->hw->pdev, 0x54, &dc); |
| 1447 | rval = qla2x00_read_ram_word(vha, 0x7a15, &dw); |
| 1448 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1449 | ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1450 | goto done_release; |
| 1451 | } |
| 1452 | |
| 1453 | dc &= MPS_MASK; |
| 1454 | if (dc == (dw & MPS_MASK)) |
| 1455 | goto done_release; |
| 1456 | |
| 1457 | dw &= ~MPS_MASK; |
| 1458 | dw |= dc; |
| 1459 | rval = qla2x00_write_ram_word(vha, 0x7a15, dw); |
| 1460 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1461 | ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | done_release: |
| 1465 | rval = qla2x00_write_ram_word(vha, 0x7c00, 0); |
| 1466 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1467 | ql_log(ql_log_warn, vha, 0x006d, |
| 1468 | "Unable to release semaphore.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1469 | } |
| 1470 | |
| 1471 | done: |
| 1472 | return rval; |
| 1473 | } |
| 1474 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1475 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | * qla2x00_setup_chip() - Load and start RISC firmware. |
| 1477 | * @ha: HA context |
| 1478 | * |
| 1479 | * Returns 0 on success. |
| 1480 | */ |
| 1481 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1482 | qla2x00_setup_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1484 | int rval; |
| 1485 | uint32_t srisc_address = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1486 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1487 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 1488 | unsigned long flags; |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 1489 | uint16_t fw_major_version; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1490 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1491 | if (IS_QLA82XX(ha)) { |
| 1492 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 1493 | if (rval == QLA_SUCCESS) { |
| 1494 | qla2x00_stop_firmware(vha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1495 | goto enable_82xx_npiv; |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 1496 | } else |
Giridhar Malavali | b963752 | 2010-05-28 15:08:15 -0700 | [diff] [blame] | 1497 | goto failed; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1498 | } |
| 1499 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1500 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 1501 | /* Disable SRAM, Instruction RAM and GP RAM parity. */ |
| 1502 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1503 | WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0)); |
| 1504 | RD_REG_WORD(®->hccr); |
| 1505 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1506 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1508 | qla81xx_mpi_sync(vha); |
| 1509 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | /* Load firmware sequences */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1511 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1512 | if (rval == QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1513 | ql_dbg(ql_dbg_init, vha, 0x00c9, |
| 1514 | "Verifying Checksum of loaded RISC code.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1516 | rval = qla2x00_verify_checksum(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | if (rval == QLA_SUCCESS) { |
| 1518 | /* Start firmware execution. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1519 | ql_dbg(ql_dbg_init, vha, 0x00ca, |
| 1520 | "Starting firmware.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1522 | rval = qla2x00_execute_fw(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | /* Retrieve firmware information. */ |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 1524 | if (rval == QLA_SUCCESS) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1525 | enable_82xx_npiv: |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 1526 | fw_major_version = ha->fw_major_version; |
Giridhar Malavali | 3173167 | 2011-08-16 11:31:54 -0700 | [diff] [blame] | 1527 | if (IS_QLA82XX(ha)) |
| 1528 | qla82xx_check_md_needed(vha); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1529 | else |
| 1530 | rval = qla2x00_get_fw_version(vha); |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 1531 | if (rval != QLA_SUCCESS) |
| 1532 | goto failed; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1533 | ha->flags.npiv_supported = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1534 | if (IS_QLA2XXX_MIDTYPE(ha) && |
Mike Hernandez | 946fb89 | 2008-08-13 21:36:59 -0700 | [diff] [blame] | 1535 | (ha->fw_attributes & BIT_2)) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1536 | ha->flags.npiv_supported = 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 1537 | if ((!ha->max_npiv_vports) || |
| 1538 | ((ha->max_npiv_vports + 1) % |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 1539 | MIN_MULTI_ID_FABRIC)) |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 1540 | ha->max_npiv_vports = |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 1541 | MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 1542 | } |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 1543 | qla2x00_get_resource_cnts(vha, NULL, |
| 1544 | &ha->fw_xcb_count, NULL, NULL, |
Andrew Vasquez | f3a0a77 | 2009-10-13 15:16:49 -0700 | [diff] [blame] | 1545 | &ha->max_npiv_vports, NULL); |
Andrew Vasquez | d743de6 | 2009-03-24 09:08:15 -0700 | [diff] [blame] | 1546 | |
Saurav Kashyap | be5ea3c | 2011-11-18 09:02:11 -0800 | [diff] [blame] | 1547 | if (!fw_major_version && ql2xallocfwdump |
| 1548 | && !IS_QLA82XX(ha)) |
Giridhar Malavali | 08de284 | 2011-08-16 11:31:44 -0700 | [diff] [blame] | 1549 | qla2x00_alloc_fw_dump(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | } |
| 1551 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1552 | ql_log(ql_log_fatal, vha, 0x00cd, |
| 1553 | "ISP Firmware failed checksum.\n"); |
| 1554 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1555 | } |
| 1556 | } |
| 1557 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1558 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 1559 | /* Enable proper parity. */ |
| 1560 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1561 | if (IS_QLA2300(ha)) |
| 1562 | /* SRAM parity */ |
| 1563 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1); |
| 1564 | else |
| 1565 | /* SRAM, Instruction RAM and GP RAM parity */ |
| 1566 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7); |
| 1567 | RD_REG_WORD(®->hccr); |
| 1568 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1569 | } |
| 1570 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1571 | if (IS_QLA83XX(ha)) |
| 1572 | goto skip_fac_check; |
| 1573 | |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1574 | if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) { |
| 1575 | uint32_t size; |
| 1576 | |
| 1577 | rval = qla81xx_fac_get_sector_size(vha, &size); |
| 1578 | if (rval == QLA_SUCCESS) { |
| 1579 | ha->flags.fac_supported = 1; |
| 1580 | ha->fdt_block_size = size << 2; |
| 1581 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1582 | ql_log(ql_log_warn, vha, 0x00ce, |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1583 | "Unsupported FAC firmware (%d.%02d.%02d).\n", |
| 1584 | ha->fw_major_version, ha->fw_minor_version, |
| 1585 | ha->fw_subminor_version); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1586 | skip_fac_check: |
| 1587 | if (IS_QLA83XX(ha)) { |
| 1588 | ha->flags.fac_supported = 0; |
| 1589 | rval = QLA_SUCCESS; |
| 1590 | } |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1591 | } |
| 1592 | } |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 1593 | failed: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1595 | ql_log(ql_log_fatal, vha, 0x00cf, |
| 1596 | "Setup chip ****FAILED****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | return (rval); |
| 1600 | } |
| 1601 | |
| 1602 | /** |
| 1603 | * qla2x00_init_response_q_entries() - Initializes response queue entries. |
| 1604 | * @ha: HA context |
| 1605 | * |
| 1606 | * Beginning of request ring has initialization control block already built |
| 1607 | * by nvram config routine. |
| 1608 | * |
| 1609 | * Returns 0 on success. |
| 1610 | */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1611 | void |
| 1612 | qla2x00_init_response_q_entries(struct rsp_que *rsp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | { |
| 1614 | uint16_t cnt; |
| 1615 | response_t *pkt; |
| 1616 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1617 | rsp->ring_ptr = rsp->ring; |
| 1618 | rsp->ring_index = 0; |
| 1619 | rsp->status_srb = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1620 | pkt = rsp->ring_ptr; |
| 1621 | for (cnt = 0; cnt < rsp->length; cnt++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | pkt->signature = RESPONSE_PROCESSED; |
| 1623 | pkt++; |
| 1624 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 | } |
| 1626 | |
| 1627 | /** |
| 1628 | * qla2x00_update_fw_options() - Read and process firmware options. |
| 1629 | * @ha: HA context |
| 1630 | * |
| 1631 | * Returns 0 on success. |
| 1632 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1633 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1634 | qla2x00_update_fw_options(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | { |
| 1636 | uint16_t swing, emphasis, tx_sens, rx_sens; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1637 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | |
| 1639 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1640 | qla2x00_get_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | |
| 1642 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
| 1643 | return; |
| 1644 | |
| 1645 | /* Serial Link options. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1646 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115, |
| 1647 | "Serial link options.\n"); |
| 1648 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109, |
| 1649 | (uint8_t *)&ha->fw_seriallink_options, |
| 1650 | sizeof(ha->fw_seriallink_options)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | |
| 1652 | ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING; |
| 1653 | if (ha->fw_seriallink_options[3] & BIT_2) { |
| 1654 | ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING; |
| 1655 | |
| 1656 | /* 1G settings */ |
| 1657 | swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0); |
| 1658 | emphasis = (ha->fw_seriallink_options[2] & |
| 1659 | (BIT_4 | BIT_3)) >> 3; |
| 1660 | tx_sens = ha->fw_seriallink_options[0] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1661 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | rx_sens = (ha->fw_seriallink_options[0] & |
| 1663 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 1664 | ha->fw_options[10] = (emphasis << 14) | (swing << 8); |
| 1665 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 1666 | if (rx_sens == 0x0) |
| 1667 | rx_sens = 0x3; |
| 1668 | ha->fw_options[10] |= (tx_sens << 4) | rx_sens; |
| 1669 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 1670 | ha->fw_options[10] |= BIT_5 | |
| 1671 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 1672 | (tx_sens & (BIT_1 | BIT_0)); |
| 1673 | |
| 1674 | /* 2G settings */ |
| 1675 | swing = (ha->fw_seriallink_options[2] & |
| 1676 | (BIT_7 | BIT_6 | BIT_5)) >> 5; |
| 1677 | emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0); |
| 1678 | tx_sens = ha->fw_seriallink_options[1] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1679 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | rx_sens = (ha->fw_seriallink_options[1] & |
| 1681 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 1682 | ha->fw_options[11] = (emphasis << 14) | (swing << 8); |
| 1683 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 1684 | if (rx_sens == 0x0) |
| 1685 | rx_sens = 0x3; |
| 1686 | ha->fw_options[11] |= (tx_sens << 4) | rx_sens; |
| 1687 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 1688 | ha->fw_options[11] |= BIT_5 | |
| 1689 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 1690 | (tx_sens & (BIT_1 | BIT_0)); |
| 1691 | } |
| 1692 | |
| 1693 | /* FCP2 options. */ |
| 1694 | /* Return command IOCBs without waiting for an ABTS to complete. */ |
| 1695 | ha->fw_options[3] |= BIT_13; |
| 1696 | |
| 1697 | /* LED scheme. */ |
| 1698 | if (ha->flags.enable_led_scheme) |
| 1699 | ha->fw_options[2] |= BIT_12; |
| 1700 | |
andrew.vasquez@qlogic.com | 48c02fd | 2006-03-09 14:27:18 -0800 | [diff] [blame] | 1701 | /* Detect ISP6312. */ |
| 1702 | if (IS_QLA6312(ha)) |
| 1703 | ha->fw_options[2] |= BIT_13; |
| 1704 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 | /* Update firmware options. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1706 | qla2x00_set_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | } |
| 1708 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1709 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1710 | qla24xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1711 | { |
| 1712 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1713 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1714 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1715 | if (IS_QLA82XX(ha)) |
| 1716 | return; |
| 1717 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1718 | /* Update Serial Link options. */ |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 1719 | if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1720 | return; |
| 1721 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1722 | rval = qla2x00_set_serdes_params(vha, |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 1723 | le16_to_cpu(ha->fw_seriallink_options24[1]), |
| 1724 | le16_to_cpu(ha->fw_seriallink_options24[2]), |
| 1725 | le16_to_cpu(ha->fw_seriallink_options24[3])); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1726 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1727 | ql_log(ql_log_warn, vha, 0x0104, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1728 | "Unable to update Serial Link options (%x).\n", rval); |
| 1729 | } |
| 1730 | } |
| 1731 | |
| 1732 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1733 | qla2x00_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1734 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1735 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1736 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1737 | struct req_que *req = ha->req_q_map[0]; |
| 1738 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1739 | |
| 1740 | /* Setup ring parameters in initialization control block. */ |
| 1741 | ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0); |
| 1742 | ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1743 | ha->init_cb->request_q_length = cpu_to_le16(req->length); |
| 1744 | ha->init_cb->response_q_length = cpu_to_le16(rsp->length); |
| 1745 | ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 1746 | ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 1747 | ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 1748 | 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] | 1749 | |
| 1750 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0); |
| 1751 | WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0); |
| 1752 | WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0); |
| 1753 | WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0); |
| 1754 | RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */ |
| 1755 | } |
| 1756 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1757 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1758 | qla24xx_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1759 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1760 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1761 | device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0); |
| 1762 | struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp; |
| 1763 | struct qla_msix_entry *msix; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1764 | struct init_cb_24xx *icb; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1765 | uint16_t rid = 0; |
| 1766 | struct req_que *req = ha->req_q_map[0]; |
| 1767 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1768 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1769 | /* Setup ring parameters in initialization control block. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1770 | icb = (struct init_cb_24xx *)ha->init_cb; |
| 1771 | icb->request_q_outpointer = __constant_cpu_to_le16(0); |
| 1772 | icb->response_q_inpointer = __constant_cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1773 | icb->request_q_length = cpu_to_le16(req->length); |
| 1774 | icb->response_q_length = cpu_to_le16(rsp->length); |
| 1775 | icb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 1776 | icb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 1777 | icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 1778 | icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1779 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1780 | /* Setup ATIO queue dma pointers for target mode */ |
| 1781 | icb->atio_q_inpointer = __constant_cpu_to_le16(0); |
| 1782 | icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length); |
| 1783 | icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma)); |
| 1784 | icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma)); |
| 1785 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1786 | if (ha->mqenable || IS_QLA83XX(ha)) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1787 | icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS); |
| 1788 | icb->rid = __constant_cpu_to_le16(rid); |
| 1789 | if (ha->flags.msix_enabled) { |
| 1790 | msix = &ha->msix_entries[1]; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1791 | ql_dbg(ql_dbg_init, vha, 0x00fd, |
| 1792 | "Registering vector 0x%x for base que.\n", |
| 1793 | msix->entry); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1794 | icb->msix = cpu_to_le16(msix->entry); |
| 1795 | } |
| 1796 | /* Use alternate PCI bus number */ |
| 1797 | if (MSB(rid)) |
| 1798 | icb->firmware_options_2 |= |
| 1799 | __constant_cpu_to_le32(BIT_19); |
| 1800 | /* Use alternate PCI devfn */ |
| 1801 | if (LSB(rid)) |
| 1802 | icb->firmware_options_2 |= |
| 1803 | __constant_cpu_to_le32(BIT_18); |
| 1804 | |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 1805 | /* Use Disable MSIX Handshake mode for capable adapters */ |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1806 | if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) && |
| 1807 | (ha->flags.msix_enabled)) { |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 1808 | icb->firmware_options_2 &= |
| 1809 | __constant_cpu_to_le32(~BIT_22); |
| 1810 | ha->flags.disable_msix_handshake = 1; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1811 | ql_dbg(ql_dbg_init, vha, 0x00fe, |
| 1812 | "MSIX Handshake Disable Mode turned on.\n"); |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 1813 | } else { |
| 1814 | icb->firmware_options_2 |= |
| 1815 | __constant_cpu_to_le32(BIT_22); |
| 1816 | } |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1817 | icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1818 | |
| 1819 | WRT_REG_DWORD(®->isp25mq.req_q_in, 0); |
| 1820 | WRT_REG_DWORD(®->isp25mq.req_q_out, 0); |
| 1821 | WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0); |
| 1822 | WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0); |
| 1823 | } else { |
| 1824 | WRT_REG_DWORD(®->isp24.req_q_in, 0); |
| 1825 | WRT_REG_DWORD(®->isp24.req_q_out, 0); |
| 1826 | WRT_REG_DWORD(®->isp24.rsp_q_in, 0); |
| 1827 | WRT_REG_DWORD(®->isp24.rsp_q_out, 0); |
| 1828 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1829 | qlt_24xx_config_rings(vha, reg); |
| 1830 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1831 | /* PCI posting */ |
| 1832 | RD_REG_DWORD(&ioreg->hccr); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1833 | } |
| 1834 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | /** |
| 1836 | * qla2x00_init_rings() - Initializes firmware. |
| 1837 | * @ha: HA context |
| 1838 | * |
| 1839 | * Beginning of request ring has initialization control block already built |
| 1840 | * by nvram config routine. |
| 1841 | * |
| 1842 | * Returns 0 on success. |
| 1843 | */ |
| 1844 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1845 | qla2x00_init_rings(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | { |
| 1847 | int rval; |
| 1848 | unsigned long flags = 0; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1849 | int cnt, que; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1850 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1851 | struct req_que *req; |
| 1852 | struct rsp_que *rsp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1853 | struct mid_init_cb_24xx *mid_init_cb = |
| 1854 | (struct mid_init_cb_24xx *) ha->init_cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | |
| 1856 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1857 | |
| 1858 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1859 | for (que = 0; que < ha->max_req_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1860 | req = ha->req_q_map[que]; |
| 1861 | if (!req) |
| 1862 | continue; |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1863 | for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1864 | req->outstanding_cmds[cnt] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1866 | req->current_outstanding_cmd = 1; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1867 | |
| 1868 | /* Initialize firmware. */ |
| 1869 | req->ring_ptr = req->ring; |
| 1870 | req->ring_index = 0; |
| 1871 | req->cnt = req->length; |
| 1872 | } |
| 1873 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1874 | for (que = 0; que < ha->max_rsp_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1875 | rsp = ha->rsp_q_map[que]; |
| 1876 | if (!rsp) |
| 1877 | continue; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1878 | /* Initialize response queue entries */ |
| 1879 | qla2x00_init_response_q_entries(rsp); |
| 1880 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | |
Dan Carpenter | 542bce1 | 2010-10-15 11:27:38 -0700 | [diff] [blame] | 1882 | spin_lock(&ha->vport_slock); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 1883 | |
Dan Carpenter | 542bce1 | 2010-10-15 11:27:38 -0700 | [diff] [blame] | 1884 | spin_unlock(&ha->vport_slock); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 1885 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1886 | ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; |
| 1887 | ha->tgt.atio_ring_index = 0; |
| 1888 | /* Initialize ATIO queue entries */ |
| 1889 | qlt_init_atio_q_entries(vha); |
| 1890 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1891 | ha->isp_ops->config_rings(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1892 | |
| 1893 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1894 | |
| 1895 | /* Update any ISP specific firmware options before initialization. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1896 | ha->isp_ops->update_fw_options(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1898 | ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n"); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1899 | |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 1900 | if (ha->flags.npiv_supported) { |
| 1901 | if (ha->operating_mode == LOOP) |
| 1902 | ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | c48339d | 2008-01-17 09:02:19 -0800 | [diff] [blame] | 1903 | mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports); |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 1904 | } |
| 1905 | |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 1906 | if (IS_FWI2_CAPABLE(ha)) { |
| 1907 | mid_init_cb->options = __constant_cpu_to_le16(BIT_1); |
| 1908 | mid_init_cb->init_cb.execution_throttle = |
| 1909 | cpu_to_le16(ha->fw_xcb_count); |
| 1910 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1911 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1912 | rval = qla2x00_init_firmware(vha, ha->init_cb_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1914 | ql_log(ql_log_fatal, vha, 0x00d2, |
| 1915 | "Init Firmware **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1917 | ql_dbg(ql_dbg_init, vha, 0x00d3, |
| 1918 | "Init Firmware -- success.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | } |
| 1920 | |
| 1921 | return (rval); |
| 1922 | } |
| 1923 | |
| 1924 | /** |
| 1925 | * qla2x00_fw_ready() - Waits for firmware ready. |
| 1926 | * @ha: HA context |
| 1927 | * |
| 1928 | * Returns 0 on success. |
| 1929 | */ |
| 1930 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1931 | qla2x00_fw_ready(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | { |
| 1933 | int rval; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1934 | unsigned long wtime, mtime, cs84xx_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1935 | uint16_t min_wait; /* Minimum wait time if loop is down */ |
| 1936 | uint16_t wait_time; /* Wait time if loop is coming ready */ |
Andrew Vasquez | 656e891 | 2009-06-03 09:55:29 -0700 | [diff] [blame] | 1937 | uint16_t state[5]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1938 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | |
| 1940 | rval = QLA_SUCCESS; |
| 1941 | |
| 1942 | /* 20 seconds for loop down. */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1943 | min_wait = 20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | |
| 1945 | /* |
| 1946 | * Firmware should take at most one RATOV to login, plus 5 seconds for |
| 1947 | * our own processing. |
| 1948 | */ |
| 1949 | if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) { |
| 1950 | wait_time = min_wait; |
| 1951 | } |
| 1952 | |
| 1953 | /* Min wait time if loop down */ |
| 1954 | mtime = jiffies + (min_wait * HZ); |
| 1955 | |
| 1956 | /* wait time before firmware ready */ |
| 1957 | wtime = jiffies + (wait_time * HZ); |
| 1958 | |
| 1959 | /* Wait for ISP to finish LIP */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1960 | if (!vha->flags.init_done) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1961 | ql_log(ql_log_info, vha, 0x801e, |
| 1962 | "Waiting for LIP to complete.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | |
| 1964 | do { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1965 | rval = qla2x00_get_firmware_state(vha, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | if (rval == QLA_SUCCESS) { |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1967 | if (state[0] < FSTATE_LOSS_OF_SYNC) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1968 | vha->device_flags &= ~DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1970 | if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1971 | ql_dbg(ql_dbg_taskm, vha, 0x801f, |
| 1972 | "fw_state=%x 84xx=%x.\n", state[0], |
| 1973 | state[2]); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1974 | if ((state[2] & FSTATE_LOGGED_IN) && |
| 1975 | (state[2] & FSTATE_WAITING_FOR_VERIFY)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1976 | ql_dbg(ql_dbg_taskm, vha, 0x8028, |
| 1977 | "Sending verify iocb.\n"); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1978 | |
| 1979 | cs84xx_time = jiffies; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1980 | rval = qla84xx_init_chip(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1981 | if (rval != QLA_SUCCESS) { |
| 1982 | ql_log(ql_log_warn, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1983 | vha, 0x8007, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1984 | "Init chip failed.\n"); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1985 | break; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1986 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1987 | |
| 1988 | /* Add time taken to initialize. */ |
| 1989 | cs84xx_time = jiffies - cs84xx_time; |
| 1990 | wtime += cs84xx_time; |
| 1991 | mtime += cs84xx_time; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1992 | ql_dbg(ql_dbg_taskm, vha, 0x8008, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1993 | "Increasing wait time by %ld. " |
| 1994 | "New time %ld.\n", cs84xx_time, |
| 1995 | wtime); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1996 | } |
| 1997 | } else if (state[0] == FSTATE_READY) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1998 | ql_dbg(ql_dbg_taskm, vha, 0x8037, |
| 1999 | "F/W Ready - OK.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2001 | qla2x00_get_retry_cnt(vha, &ha->retry_count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | &ha->login_timeout, &ha->r_a_tov); |
| 2003 | |
| 2004 | rval = QLA_SUCCESS; |
| 2005 | break; |
| 2006 | } |
| 2007 | |
| 2008 | rval = QLA_FUNCTION_FAILED; |
| 2009 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2010 | if (atomic_read(&vha->loop_down_timer) && |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2011 | state[0] != FSTATE_READY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | /* Loop down. Timeout on min_wait for states |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2013 | * other than Wait for Login. |
| 2014 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | if (time_after_eq(jiffies, mtime)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2016 | ql_log(ql_log_info, vha, 0x8038, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | "Cable is unplugged...\n"); |
| 2018 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2019 | vha->device_flags |= DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2020 | break; |
| 2021 | } |
| 2022 | } |
| 2023 | } else { |
| 2024 | /* Mailbox cmd failed. Timeout on min_wait. */ |
Santosh Vernekar | cdbb0a4f | 2010-05-28 15:08:25 -0700 | [diff] [blame] | 2025 | if (time_after_eq(jiffies, mtime) || |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 2026 | ha->flags.isp82xx_fw_hung) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | break; |
| 2028 | } |
| 2029 | |
| 2030 | if (time_after_eq(jiffies, wtime)) |
| 2031 | break; |
| 2032 | |
| 2033 | /* Delay for a while */ |
| 2034 | msleep(500); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | } while (1); |
| 2036 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2037 | ql_dbg(ql_dbg_taskm, vha, 0x803a, |
| 2038 | "fw_state=%x (%x, %x, %x, %x) " "curr time=%lx.\n", state[0], |
| 2039 | state[1], state[2], state[3], state[4], jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2041 | if (rval && !(vha->device_flags & DFLG_NO_CABLE)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2042 | ql_log(ql_log_warn, vha, 0x803b, |
| 2043 | "Firmware ready **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | } |
| 2045 | |
| 2046 | return (rval); |
| 2047 | } |
| 2048 | |
| 2049 | /* |
| 2050 | * qla2x00_configure_hba |
| 2051 | * Setup adapter context. |
| 2052 | * |
| 2053 | * Input: |
| 2054 | * ha = adapter state pointer. |
| 2055 | * |
| 2056 | * Returns: |
| 2057 | * 0 = success |
| 2058 | * |
| 2059 | * Context: |
| 2060 | * Kernel context. |
| 2061 | */ |
| 2062 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2063 | qla2x00_configure_hba(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | { |
| 2065 | int rval; |
| 2066 | uint16_t loop_id; |
| 2067 | uint16_t topo; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2068 | uint16_t sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | uint8_t al_pa; |
| 2070 | uint8_t area; |
| 2071 | uint8_t domain; |
| 2072 | char connect_type[22]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2073 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | |
| 2075 | /* Get host addresses. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2076 | rval = qla2x00_get_adapter_id(vha, |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2077 | &loop_id, &al_pa, &area, &domain, &topo, &sw_cap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2078 | if (rval != QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2079 | if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) || |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2080 | IS_CNA_CAPABLE(ha) || |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 2081 | (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2082 | ql_dbg(ql_dbg_disc, vha, 0x2008, |
| 2083 | "Loop is in a transition state.\n"); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 2084 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2085 | ql_log(ql_log_warn, vha, 0x2009, |
| 2086 | "Unable to get host loop ID.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2087 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 2088 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | return (rval); |
| 2090 | } |
| 2091 | |
| 2092 | if (topo == 4) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2093 | ql_log(ql_log_info, vha, 0x200a, |
| 2094 | "Cannot get topology - retrying.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | return (QLA_FUNCTION_FAILED); |
| 2096 | } |
| 2097 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2098 | vha->loop_id = loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | |
| 2100 | /* initialize */ |
| 2101 | ha->min_external_loopid = SNS_FIRST_LOOP_ID; |
| 2102 | ha->operating_mode = LOOP; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2103 | ha->switch_cap = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | |
| 2105 | switch (topo) { |
| 2106 | case 0: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2107 | ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2108 | ha->current_topology = ISP_CFG_NL; |
| 2109 | strcpy(connect_type, "(Loop)"); |
| 2110 | break; |
| 2111 | |
| 2112 | case 1: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2113 | ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n"); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2114 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | ha->current_topology = ISP_CFG_FL; |
| 2116 | strcpy(connect_type, "(FL_Port)"); |
| 2117 | break; |
| 2118 | |
| 2119 | case 2: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2120 | 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] | 2121 | ha->operating_mode = P2P; |
| 2122 | ha->current_topology = ISP_CFG_N; |
| 2123 | strcpy(connect_type, "(N_Port-to-N_Port)"); |
| 2124 | break; |
| 2125 | |
| 2126 | case 3: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2127 | 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] | 2128 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | ha->operating_mode = P2P; |
| 2130 | ha->current_topology = ISP_CFG_F; |
| 2131 | strcpy(connect_type, "(F_Port)"); |
| 2132 | break; |
| 2133 | |
| 2134 | default: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2135 | ql_dbg(ql_dbg_disc, vha, 0x200f, |
| 2136 | "HBA in unknown topology %x, using NL.\n", topo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | ha->current_topology = ISP_CFG_NL; |
| 2138 | strcpy(connect_type, "(Loop)"); |
| 2139 | break; |
| 2140 | } |
| 2141 | |
| 2142 | /* Save Host port and loop ID. */ |
| 2143 | /* byte order - Big Endian */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2144 | vha->d_id.b.domain = domain; |
| 2145 | vha->d_id.b.area = area; |
| 2146 | vha->d_id.b.al_pa = al_pa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2148 | spin_lock(&ha->vport_slock); |
| 2149 | qlt_update_vp_map(vha, SET_AL_PA); |
| 2150 | spin_unlock(&ha->vport_slock); |
| 2151 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2152 | if (!vha->flags.init_done) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2153 | ql_log(ql_log_info, vha, 0x2010, |
| 2154 | "Topology - %s, Host Loop address 0x%x.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2155 | connect_type, vha->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | |
| 2157 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2158 | ql_log(ql_log_warn, vha, 0x2011, |
| 2159 | "%s FAILED\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2161 | ql_dbg(ql_dbg_disc, vha, 0x2012, |
| 2162 | "%s success\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | } |
| 2164 | |
| 2165 | return(rval); |
| 2166 | } |
| 2167 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2168 | inline void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2169 | qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len, |
| 2170 | char *def) |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2171 | { |
| 2172 | char *st, *en; |
| 2173 | uint16_t index; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2174 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | ab67114 | 2009-08-25 11:36:17 -0700 | [diff] [blame] | 2175 | int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) && |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2176 | !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2177 | |
| 2178 | if (memcmp(model, BINZERO, len) != 0) { |
| 2179 | strncpy(ha->model_number, model, len); |
| 2180 | st = en = ha->model_number; |
| 2181 | en += len - 1; |
| 2182 | while (en > st) { |
| 2183 | if (*en != 0x20 && *en != 0x00) |
| 2184 | break; |
| 2185 | *en-- = '\0'; |
| 2186 | } |
| 2187 | |
| 2188 | index = (ha->pdev->subsystem_device & 0xff); |
Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 2189 | if (use_tbl && |
| 2190 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2191 | index < QLA_MODEL_NAMES) |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2192 | strncpy(ha->model_desc, |
| 2193 | qla2x00_model_name[index * 2 + 1], |
| 2194 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2195 | } else { |
| 2196 | index = (ha->pdev->subsystem_device & 0xff); |
Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 2197 | if (use_tbl && |
| 2198 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2199 | index < QLA_MODEL_NAMES) { |
| 2200 | strcpy(ha->model_number, |
| 2201 | qla2x00_model_name[index * 2]); |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2202 | strncpy(ha->model_desc, |
| 2203 | qla2x00_model_name[index * 2 + 1], |
| 2204 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2205 | } else { |
| 2206 | strcpy(ha->model_number, def); |
| 2207 | } |
| 2208 | } |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2209 | if (IS_FWI2_CAPABLE(ha)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2210 | qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc, |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2211 | sizeof(ha->model_desc)); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2212 | } |
| 2213 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2214 | /* On sparc systems, obtain port and node WWN from firmware |
| 2215 | * properties. |
| 2216 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2217 | 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] | 2218 | { |
| 2219 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2220 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2221 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 2222 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 2223 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2224 | int len; |
| 2225 | |
| 2226 | val = of_get_property(dp, "port-wwn", &len); |
| 2227 | if (val && len >= WWN_SIZE) |
| 2228 | memcpy(nv->port_name, val, WWN_SIZE); |
| 2229 | |
| 2230 | val = of_get_property(dp, "node-wwn", &len); |
| 2231 | if (val && len >= WWN_SIZE) |
| 2232 | memcpy(nv->node_name, val, WWN_SIZE); |
| 2233 | #endif |
| 2234 | } |
| 2235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | /* |
| 2237 | * NVRAM configuration for ISP 2xxx |
| 2238 | * |
| 2239 | * Input: |
| 2240 | * ha = adapter block pointer. |
| 2241 | * |
| 2242 | * Output: |
| 2243 | * initialization control block in response_ring |
| 2244 | * host adapters parameters in host adapter block |
| 2245 | * |
| 2246 | * Returns: |
| 2247 | * 0 = success. |
| 2248 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2249 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2250 | qla2x00_nvram_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2252 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2253 | uint8_t chksum = 0; |
| 2254 | uint16_t cnt; |
| 2255 | uint8_t *dptr1, *dptr2; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2256 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2257 | init_cb_t *icb = ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 2258 | nvram_t *nv = ha->nvram; |
| 2259 | uint8_t *ptr = ha->nvram; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2260 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2261 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2262 | rval = QLA_SUCCESS; |
| 2263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2264 | /* Determine NVRAM starting address. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2265 | ha->nvram_size = sizeof(nvram_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | ha->nvram_base = 0; |
| 2267 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) |
| 2268 | if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1) |
| 2269 | ha->nvram_base = 0x80; |
| 2270 | |
| 2271 | /* Get NVRAM data and calculate checksum. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2272 | 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] | 2273 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++) |
| 2274 | chksum += *ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2275 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2276 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f, |
| 2277 | "Contents of NVRAM.\n"); |
| 2278 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110, |
| 2279 | (uint8_t *)nv, ha->nvram_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | |
| 2281 | /* Bad NVRAM data, set defaults parameters. */ |
| 2282 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || |
| 2283 | nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) { |
| 2284 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2285 | ql_log(ql_log_warn, vha, 0x0064, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 2286 | "Inconsistent NVRAM " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2287 | "detected: checksum=0x%x id=%c version=0x%x.\n", |
| 2288 | chksum, nv->id[0], nv->nvram_version); |
| 2289 | ql_log(ql_log_warn, vha, 0x0065, |
| 2290 | "Falling back to " |
| 2291 | "functioning (yet invalid -- WWPN) defaults.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2292 | |
| 2293 | /* |
| 2294 | * Set default initialization control block. |
| 2295 | */ |
| 2296 | memset(nv, 0, ha->nvram_size); |
| 2297 | nv->parameter_block_version = ICB_VERSION; |
| 2298 | |
| 2299 | if (IS_QLA23XX(ha)) { |
| 2300 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 2301 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 2302 | nv->add_firmware_options[0] = BIT_5; |
| 2303 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
| 2304 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 2305 | nv->special_options[1] = BIT_7; |
| 2306 | } else if (IS_QLA2200(ha)) { |
| 2307 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 2308 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 2309 | nv->add_firmware_options[0] = BIT_5; |
| 2310 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
| 2311 | nv->frame_payload_size = __constant_cpu_to_le16(1024); |
| 2312 | } else if (IS_QLA2100(ha)) { |
| 2313 | nv->firmware_options[0] = BIT_3 | BIT_1; |
| 2314 | nv->firmware_options[1] = BIT_5; |
| 2315 | nv->frame_payload_size = __constant_cpu_to_le16(1024); |
| 2316 | } |
| 2317 | |
| 2318 | nv->max_iocb_allocation = __constant_cpu_to_le16(256); |
| 2319 | nv->execution_throttle = __constant_cpu_to_le16(16); |
| 2320 | nv->retry_count = 8; |
| 2321 | nv->retry_delay = 1; |
| 2322 | |
| 2323 | nv->port_name[0] = 33; |
| 2324 | nv->port_name[3] = 224; |
| 2325 | nv->port_name[4] = 139; |
| 2326 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2327 | qla2xxx_nvram_wwn_from_ofw(vha, nv); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2328 | |
| 2329 | nv->login_timeout = 4; |
| 2330 | |
| 2331 | /* |
| 2332 | * Set default host adapter parameters |
| 2333 | */ |
| 2334 | nv->host_p[1] = BIT_2; |
| 2335 | nv->reset_delay = 5; |
| 2336 | nv->port_down_retry_count = 8; |
| 2337 | nv->max_luns_per_target = __constant_cpu_to_le16(8); |
| 2338 | nv->link_down_timeout = 60; |
| 2339 | |
| 2340 | rval = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2341 | } |
| 2342 | |
| 2343 | #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2) |
| 2344 | /* |
| 2345 | * The SN2 does not provide BIOS emulation which means you can't change |
| 2346 | * potentially bogus BIOS settings. Force the use of default settings |
| 2347 | * for link rate and frame size. Hope that the rest of the settings |
| 2348 | * are valid. |
| 2349 | */ |
| 2350 | if (ia64_platform_is("sn2")) { |
| 2351 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 2352 | if (IS_QLA23XX(ha)) |
| 2353 | nv->special_options[1] = BIT_7; |
| 2354 | } |
| 2355 | #endif |
| 2356 | |
| 2357 | /* Reset Initialization control block */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2358 | memset(icb, 0, ha->init_cb_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2359 | |
| 2360 | /* |
| 2361 | * Setup driver NVRAM options. |
| 2362 | */ |
| 2363 | nv->firmware_options[0] |= (BIT_6 | BIT_1); |
| 2364 | nv->firmware_options[0] &= ~(BIT_5 | BIT_4); |
| 2365 | nv->firmware_options[1] |= (BIT_5 | BIT_0); |
| 2366 | nv->firmware_options[1] &= ~BIT_4; |
| 2367 | |
| 2368 | if (IS_QLA23XX(ha)) { |
| 2369 | nv->firmware_options[0] |= BIT_2; |
| 2370 | nv->firmware_options[0] &= ~BIT_3; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2371 | nv->special_options[0] &= ~BIT_6; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2372 | nv->add_firmware_options[1] |= BIT_5 | BIT_4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2373 | |
| 2374 | if (IS_QLA2300(ha)) { |
| 2375 | if (ha->fb_rev == FPM_2310) { |
| 2376 | strcpy(ha->model_number, "QLA2310"); |
| 2377 | } else { |
| 2378 | strcpy(ha->model_number, "QLA2300"); |
| 2379 | } |
| 2380 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2381 | qla2x00_set_model_info(vha, nv->model_number, |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2382 | sizeof(nv->model_number), "QLA23xx"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | } |
| 2384 | } else if (IS_QLA2200(ha)) { |
| 2385 | nv->firmware_options[0] |= BIT_2; |
| 2386 | /* |
| 2387 | * 'Point-to-point preferred, else loop' is not a safe |
| 2388 | * connection mode setting. |
| 2389 | */ |
| 2390 | if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) == |
| 2391 | (BIT_5 | BIT_4)) { |
| 2392 | /* Force 'loop preferred, else point-to-point'. */ |
| 2393 | nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4); |
| 2394 | nv->add_firmware_options[0] |= BIT_5; |
| 2395 | } |
| 2396 | strcpy(ha->model_number, "QLA22xx"); |
| 2397 | } else /*if (IS_QLA2100(ha))*/ { |
| 2398 | strcpy(ha->model_number, "QLA2100"); |
| 2399 | } |
| 2400 | |
| 2401 | /* |
| 2402 | * Copy over NVRAM RISC parameter block to initialization control block. |
| 2403 | */ |
| 2404 | dptr1 = (uint8_t *)icb; |
| 2405 | dptr2 = (uint8_t *)&nv->parameter_block_version; |
| 2406 | cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version; |
| 2407 | while (cnt--) |
| 2408 | *dptr1++ = *dptr2++; |
| 2409 | |
| 2410 | /* Copy 2nd half. */ |
| 2411 | dptr1 = (uint8_t *)icb->add_firmware_options; |
| 2412 | cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options; |
| 2413 | while (cnt--) |
| 2414 | *dptr1++ = *dptr2++; |
| 2415 | |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 2416 | /* Use alternate WWN? */ |
| 2417 | if (nv->host_p[1] & BIT_7) { |
| 2418 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 2419 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 2420 | } |
| 2421 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2422 | /* Prepare nodename */ |
| 2423 | if ((icb->firmware_options[1] & BIT_6) == 0) { |
| 2424 | /* |
| 2425 | * Firmware will apply the following mask if the nodename was |
| 2426 | * not provided. |
| 2427 | */ |
| 2428 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 2429 | icb->node_name[0] &= 0xF0; |
| 2430 | } |
| 2431 | |
| 2432 | /* |
| 2433 | * Set host adapter parameters. |
| 2434 | */ |
Saurav Kashyap | 3ce8866 | 2011-07-14 12:00:12 -0700 | [diff] [blame] | 2435 | |
| 2436 | /* |
| 2437 | * BIT_7 in the host-parameters section allows for modification to |
| 2438 | * internal driver logging. |
| 2439 | */ |
Andrew Vasquez | 0181944 | 2006-06-23 16:11:10 -0700 | [diff] [blame] | 2440 | if (nv->host_p[0] & BIT_7) |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2441 | ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0); |
| 2443 | /* Always load RISC code on non ISP2[12]00 chips. */ |
| 2444 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) |
| 2445 | ha->flags.disable_risc_code_load = 0; |
| 2446 | ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0); |
| 2447 | ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0); |
| 2448 | 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] | 2449 | 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] | 2450 | ha->flags.disable_serdes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | |
| 2452 | ha->operating_mode = |
| 2453 | (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 2454 | |
| 2455 | memcpy(ha->fw_seriallink_options, nv->seriallink_options, |
| 2456 | sizeof(ha->fw_seriallink_options)); |
| 2457 | |
| 2458 | /* save HBA serial number */ |
| 2459 | ha->serial0 = icb->port_name[5]; |
| 2460 | ha->serial1 = icb->port_name[6]; |
| 2461 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2462 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 2463 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2464 | |
| 2465 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 2466 | |
| 2467 | ha->retry_count = nv->retry_count; |
| 2468 | |
| 2469 | /* Set minimum login_timeout to 4 seconds. */ |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 2470 | if (nv->login_timeout != ql2xlogintimeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2471 | nv->login_timeout = ql2xlogintimeout; |
| 2472 | if (nv->login_timeout < 4) |
| 2473 | nv->login_timeout = 4; |
| 2474 | ha->login_timeout = nv->login_timeout; |
| 2475 | icb->login_timeout = nv->login_timeout; |
| 2476 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 2477 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 2478 | ha->r_a_tov = 100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2479 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | ha->loop_reset_delay = nv->reset_delay; |
| 2481 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2482 | /* Link Down Timeout = 0: |
| 2483 | * |
| 2484 | * When Port Down timer expires we will start returning |
| 2485 | * I/O's to OS with "DID_NO_CONNECT". |
| 2486 | * |
| 2487 | * Link Down Timeout != 0: |
| 2488 | * |
| 2489 | * The driver waits for the link to come up after link down |
| 2490 | * before returning I/Os to OS with "DID_NO_CONNECT". |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2491 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2492 | if (nv->link_down_timeout == 0) { |
| 2493 | ha->loop_down_abort_time = |
Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 2494 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2495 | } else { |
| 2496 | ha->link_down_timeout = nv->link_down_timeout; |
| 2497 | ha->loop_down_abort_time = |
| 2498 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2499 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2500 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | /* |
| 2502 | * Need enough time to try and get the port back. |
| 2503 | */ |
| 2504 | ha->port_down_retry_count = nv->port_down_retry_count; |
| 2505 | if (qlport_down_retry) |
| 2506 | ha->port_down_retry_count = qlport_down_retry; |
| 2507 | /* Set login_retry_count */ |
| 2508 | ha->login_retry_count = nv->retry_count; |
| 2509 | if (ha->port_down_retry_count == nv->port_down_retry_count && |
| 2510 | ha->port_down_retry_count > 3) |
| 2511 | ha->login_retry_count = ha->port_down_retry_count; |
| 2512 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 2513 | ha->login_retry_count = ha->port_down_retry_count; |
| 2514 | if (ql2xloginretrycount) |
| 2515 | ha->login_retry_count = ql2xloginretrycount; |
| 2516 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | icb->lun_enables = __constant_cpu_to_le16(0); |
| 2518 | icb->command_resource_count = 0; |
| 2519 | icb->immediate_notify_resource_count = 0; |
| 2520 | icb->timeout = __constant_cpu_to_le16(0); |
| 2521 | |
| 2522 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 2523 | /* Enable RIO */ |
| 2524 | icb->firmware_options[0] &= ~BIT_3; |
| 2525 | icb->add_firmware_options[0] &= |
| 2526 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 2527 | icb->add_firmware_options[0] |= BIT_2; |
| 2528 | icb->response_accumulation_timer = 3; |
| 2529 | icb->interrupt_delay_timer = 5; |
| 2530 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2531 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2532 | } else { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2533 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2534 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2535 | ha->zio_mode = icb->add_firmware_options[0] & |
| 2536 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 2537 | ha->zio_timer = icb->interrupt_delay_timer ? |
| 2538 | icb->interrupt_delay_timer: 2; |
| 2539 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2540 | icb->add_firmware_options[0] &= |
| 2541 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2542 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2543 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 2544 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 2545 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2546 | ql_log(ql_log_info, vha, 0x0068, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2547 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 2548 | ha->zio_mode, ha->zio_timer * 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2549 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2550 | icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode; |
| 2551 | icb->interrupt_delay_timer = (uint8_t)ha->zio_timer; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2552 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2553 | } |
| 2554 | } |
| 2555 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2556 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2557 | ql_log(ql_log_warn, vha, 0x0069, |
| 2558 | "NVRAM configuration failed.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2559 | } |
| 2560 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2561 | } |
| 2562 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2563 | static void |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2564 | qla2x00_rport_del(void *data) |
| 2565 | { |
| 2566 | fc_port_t *fcport = data; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2567 | struct fc_rport *rport; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2568 | scsi_qla_host_t *vha = fcport->vha; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2569 | unsigned long flags; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2570 | |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2571 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2572 | rport = fcport->drport ? fcport->drport: fcport->rport; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2573 | fcport->drport = NULL; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2574 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2575 | if (rport) { |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2576 | fc_remote_port_delete(rport); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2577 | /* |
| 2578 | * Release the target mode FC NEXUS in qla_target.c code |
| 2579 | * if target mod is enabled. |
| 2580 | */ |
| 2581 | qlt_fc_port_deleted(vha, fcport); |
| 2582 | } |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2583 | } |
| 2584 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2585 | /** |
| 2586 | * qla2x00_alloc_fcport() - Allocate a generic fcport. |
| 2587 | * @ha: HA context |
| 2588 | * @flags: allocation flags |
| 2589 | * |
| 2590 | * Returns a pointer to the allocated fcport, or NULL, if none available. |
| 2591 | */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2592 | fc_port_t * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2593 | qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2594 | { |
| 2595 | fc_port_t *fcport; |
| 2596 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2597 | fcport = kzalloc(sizeof(fc_port_t), flags); |
| 2598 | if (!fcport) |
| 2599 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 | |
| 2601 | /* Setup fcport template structure. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2602 | fcport->vha = vha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2603 | fcport->port_type = FCT_UNKNOWN; |
| 2604 | fcport->loop_id = FC_NO_LOOP_ID; |
Chad Dupuis | ec426e1 | 2011-03-30 11:46:32 -0700 | [diff] [blame] | 2605 | qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED); |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 2606 | fcport->supported_classes = FC_COS_UNSPECIFIED; |
Joe Carnuccio | c0822b6 | 2012-05-15 14:34:21 -0400 | [diff] [blame] | 2607 | fcport->scan_state = QLA_FCPORT_SCAN_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2608 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2609 | return fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2610 | } |
| 2611 | |
| 2612 | /* |
| 2613 | * qla2x00_configure_loop |
| 2614 | * Updates Fibre Channel Device Database with what is actually on loop. |
| 2615 | * |
| 2616 | * Input: |
| 2617 | * ha = adapter block pointer. |
| 2618 | * |
| 2619 | * Returns: |
| 2620 | * 0 = success. |
| 2621 | * 1 = error. |
| 2622 | * 2 = database was full and device was not configured. |
| 2623 | */ |
| 2624 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2625 | qla2x00_configure_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2626 | { |
| 2627 | int rval; |
| 2628 | unsigned long flags, save_flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2629 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2630 | rval = QLA_SUCCESS; |
| 2631 | |
| 2632 | /* Get Initiator ID */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2633 | if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) { |
| 2634 | rval = qla2x00_configure_hba(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2635 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2636 | ql_dbg(ql_dbg_disc, vha, 0x2013, |
| 2637 | "Unable to configure HBA.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2638 | return (rval); |
| 2639 | } |
| 2640 | } |
| 2641 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2642 | save_flags = flags = vha->dpc_flags; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2643 | ql_dbg(ql_dbg_disc, vha, 0x2014, |
| 2644 | "Configure loop -- dpc flags = 0x%lx.\n", flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2645 | |
| 2646 | /* |
| 2647 | * If we have both an RSCN and PORT UPDATE pending then handle them |
| 2648 | * both at the same time. |
| 2649 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2650 | clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 2651 | clear_bit(RSCN_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2652 | |
Michael Hernandez | 3064ff3 | 2009-12-15 21:29:44 -0800 | [diff] [blame] | 2653 | qla2x00_get_data_rate(vha); |
| 2654 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2655 | /* Determine what we need to do */ |
| 2656 | if (ha->current_topology == ISP_CFG_FL && |
| 2657 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 2658 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | set_bit(RSCN_UPDATE, &flags); |
| 2660 | |
| 2661 | } else if (ha->current_topology == ISP_CFG_F && |
| 2662 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 2663 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | set_bit(RSCN_UPDATE, &flags); |
| 2665 | clear_bit(LOCAL_LOOP_UPDATE, &flags); |
| 2666 | |
Andrew Vasquez | 21333b4 | 2006-05-17 15:09:56 -0700 | [diff] [blame] | 2667 | } else if (ha->current_topology == ISP_CFG_N) { |
| 2668 | clear_bit(RSCN_UPDATE, &flags); |
| 2669 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2670 | } else if (!vha->flags.online || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2671 | (test_bit(ABORT_ISP_ACTIVE, &flags))) { |
| 2672 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2673 | set_bit(RSCN_UPDATE, &flags); |
| 2674 | set_bit(LOCAL_LOOP_UPDATE, &flags); |
| 2675 | } |
| 2676 | |
| 2677 | if (test_bit(LOCAL_LOOP_UPDATE, &flags)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2678 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
| 2679 | ql_dbg(ql_dbg_disc, vha, 0x2015, |
| 2680 | "Loop resync needed, failing.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2681 | rval = QLA_FUNCTION_FAILED; |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 2682 | } else |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2683 | rval = qla2x00_configure_local_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2684 | } |
| 2685 | |
| 2686 | if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2687 | if (LOOP_TRANSITION(vha)) { |
| 2688 | ql_dbg(ql_dbg_disc, vha, 0x201e, |
| 2689 | "Needs RSCN update and loop transition.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2690 | rval = QLA_FUNCTION_FAILED; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2691 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2692 | else |
| 2693 | rval = qla2x00_configure_fabric(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2694 | } |
| 2695 | |
| 2696 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2697 | if (atomic_read(&vha->loop_down_timer) || |
| 2698 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2699 | rval = QLA_FUNCTION_FAILED; |
| 2700 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2701 | atomic_set(&vha->loop_state, LOOP_READY); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2702 | ql_dbg(ql_dbg_disc, vha, 0x2069, |
| 2703 | "LOOP READY.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | } |
| 2705 | } |
| 2706 | |
| 2707 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2708 | ql_dbg(ql_dbg_disc, vha, 0x206a, |
| 2709 | "%s *** FAILED ***.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2710 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2711 | ql_dbg(ql_dbg_disc, vha, 0x206b, |
| 2712 | "%s: exiting normally.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2713 | } |
| 2714 | |
Bjorn Helgaas | cc3ef7b | 2008-09-11 21:22:51 -0700 | [diff] [blame] | 2715 | /* Restore state if a resync event occurred during processing */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2716 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2717 | if (test_bit(LOCAL_LOOP_UPDATE, &save_flags)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2718 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 2719 | if (test_bit(RSCN_UPDATE, &save_flags)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2720 | set_bit(RSCN_UPDATE, &vha->dpc_flags); |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 2721 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 | } |
| 2723 | |
| 2724 | return (rval); |
| 2725 | } |
| 2726 | |
| 2727 | |
| 2728 | |
| 2729 | /* |
| 2730 | * qla2x00_configure_local_loop |
| 2731 | * Updates Fibre Channel Device Database with local loop devices. |
| 2732 | * |
| 2733 | * Input: |
| 2734 | * ha = adapter block pointer. |
| 2735 | * |
| 2736 | * Returns: |
| 2737 | * 0 = success. |
| 2738 | */ |
| 2739 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2740 | qla2x00_configure_local_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2741 | { |
| 2742 | int rval, rval2; |
| 2743 | int found_devs; |
| 2744 | int found; |
| 2745 | fc_port_t *fcport, *new_fcport; |
| 2746 | |
| 2747 | uint16_t index; |
| 2748 | uint16_t entries; |
| 2749 | char *id_iter; |
| 2750 | uint16_t loop_id; |
| 2751 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2752 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2753 | |
| 2754 | found_devs = 0; |
| 2755 | new_fcport = NULL; |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 2756 | entries = MAX_FIBRE_DEVICES_LOOP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2757 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2758 | ql_dbg(ql_dbg_disc, vha, 0x2016, |
| 2759 | "Getting FCAL position map.\n"); |
| 2760 | if (ql2xextended_error_logging & ql_dbg_disc) |
| 2761 | qla2x00_get_fcal_position_map(vha, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2762 | |
| 2763 | /* Get list of logged in devices. */ |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 2764 | memset(ha->gid_list, 0, qla2x00_gid_list_size(ha)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2765 | 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] | 2766 | &entries); |
| 2767 | if (rval != QLA_SUCCESS) |
| 2768 | goto cleanup_allocation; |
| 2769 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2770 | ql_dbg(ql_dbg_disc, vha, 0x2017, |
| 2771 | "Entries in ID list (%d).\n", entries); |
| 2772 | ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075, |
| 2773 | (uint8_t *)ha->gid_list, |
| 2774 | entries * sizeof(struct gid_list_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2775 | |
| 2776 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2777 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2778 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2779 | ql_log(ql_log_warn, vha, 0x2018, |
| 2780 | "Memory allocation failed for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2781 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 2782 | goto cleanup_allocation; |
| 2783 | } |
| 2784 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 2785 | |
| 2786 | /* |
| 2787 | * Mark local devices that were present with FCF_DEVICE_LOST for now. |
| 2788 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2789 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2790 | if (atomic_read(&fcport->state) == FCS_ONLINE && |
| 2791 | fcport->port_type != FCT_BROADCAST && |
| 2792 | (fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 2793 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2794 | ql_dbg(ql_dbg_disc, vha, 0x2019, |
| 2795 | "Marking port lost loop_id=0x%04x.\n", |
| 2796 | fcport->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2797 | |
Chad Dupuis | ec426e1 | 2011-03-30 11:46:32 -0700 | [diff] [blame] | 2798 | qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | } |
| 2800 | } |
| 2801 | |
| 2802 | /* Add devices to port list. */ |
| 2803 | id_iter = (char *)ha->gid_list; |
| 2804 | for (index = 0; index < entries; index++) { |
| 2805 | domain = ((struct gid_list_info *)id_iter)->domain; |
| 2806 | area = ((struct gid_list_info *)id_iter)->area; |
| 2807 | al_pa = ((struct gid_list_info *)id_iter)->al_pa; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2808 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2809 | loop_id = (uint16_t) |
| 2810 | ((struct gid_list_info *)id_iter)->loop_id_2100; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2811 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | loop_id = le16_to_cpu( |
| 2813 | ((struct gid_list_info *)id_iter)->loop_id); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2814 | id_iter += ha->gid_list_info_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2815 | |
| 2816 | /* Bypass reserved domain fields. */ |
| 2817 | if ((domain & 0xf0) == 0xf0) |
| 2818 | continue; |
| 2819 | |
| 2820 | /* Bypass if not same domain and area of adapter. */ |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 2821 | if (area && domain && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2822 | (area != vha->d_id.b.area || domain != vha->d_id.b.domain)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2823 | continue; |
| 2824 | |
| 2825 | /* Bypass invalid local loop ID. */ |
| 2826 | if (loop_id > LAST_LOCAL_LOOP_ID) |
| 2827 | continue; |
| 2828 | |
| 2829 | /* Fill in member data. */ |
| 2830 | new_fcport->d_id.b.domain = domain; |
| 2831 | new_fcport->d_id.b.area = area; |
| 2832 | new_fcport->d_id.b.al_pa = al_pa; |
| 2833 | new_fcport->loop_id = loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2834 | rval2 = qla2x00_get_port_database(vha, new_fcport, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | if (rval2 != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2836 | ql_dbg(ql_dbg_disc, vha, 0x201a, |
| 2837 | "Failed to retrieve fcport information " |
| 2838 | "-- get_port_database=%x, loop_id=0x%04x.\n", |
| 2839 | rval2, new_fcport->loop_id); |
| 2840 | ql_dbg(ql_dbg_disc, vha, 0x201b, |
| 2841 | "Scheduling resync.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2842 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2843 | continue; |
| 2844 | } |
| 2845 | |
| 2846 | /* Check for matching device in port list. */ |
| 2847 | found = 0; |
| 2848 | fcport = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2849 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2850 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 2851 | WWN_SIZE)) |
| 2852 | continue; |
| 2853 | |
Shyam Sundar | ddb9b12 | 2009-03-24 09:08:10 -0700 | [diff] [blame] | 2854 | fcport->flags &= ~FCF_FABRIC_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2855 | fcport->loop_id = new_fcport->loop_id; |
| 2856 | fcport->port_type = new_fcport->port_type; |
| 2857 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 2858 | memcpy(fcport->node_name, new_fcport->node_name, |
| 2859 | WWN_SIZE); |
| 2860 | |
| 2861 | found++; |
| 2862 | break; |
| 2863 | } |
| 2864 | |
| 2865 | if (!found) { |
| 2866 | /* New device, add to fcports list. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2867 | list_add_tail(&new_fcport->list, &vha->vp_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2868 | |
| 2869 | /* Allocate a new replacement fcport. */ |
| 2870 | fcport = new_fcport; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2871 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2873 | ql_log(ql_log_warn, vha, 0x201c, |
| 2874 | "Failed to allocate memory for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2875 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 2876 | goto cleanup_allocation; |
| 2877 | } |
| 2878 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 2879 | } |
| 2880 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2881 | /* Base iIDMA settings on HBA port speed. */ |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 2882 | fcport->fp_speed = ha->link_data_rate; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2883 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2884 | qla2x00_update_fcport(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2885 | |
| 2886 | found_devs++; |
| 2887 | } |
| 2888 | |
| 2889 | cleanup_allocation: |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2890 | kfree(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2891 | |
| 2892 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2893 | ql_dbg(ql_dbg_disc, vha, 0x201d, |
| 2894 | "Configure local loop error exit: rval=%x.\n", rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2895 | } |
| 2896 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2897 | return (rval); |
| 2898 | } |
| 2899 | |
| 2900 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2901 | qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2902 | { |
Andrew Vasquez | 9f8fdde | 2009-06-03 09:55:22 -0700 | [diff] [blame] | 2903 | char *link_speed; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2904 | int rval; |
Harish Zunjarrao | 1bb3954 | 2009-06-17 10:30:29 -0700 | [diff] [blame] | 2905 | uint16_t mb[4]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2906 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2907 | |
Andrew Vasquez | c76f2c0 | 2007-07-19 15:05:57 -0700 | [diff] [blame] | 2908 | if (!IS_IIDMA_CAPABLE(ha)) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2909 | return; |
| 2910 | |
Giridhar Malavali | c9afb9a | 2010-09-03 15:20:48 -0700 | [diff] [blame] | 2911 | if (atomic_read(&fcport->state) != FCS_ONLINE) |
| 2912 | return; |
| 2913 | |
Andrew Vasquez | 39bd962 | 2007-09-20 14:07:34 -0700 | [diff] [blame] | 2914 | if (fcport->fp_speed == PORT_SPEED_UNKNOWN || |
| 2915 | fcport->fp_speed > ha->link_data_rate) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2916 | return; |
| 2917 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2918 | rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed, |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 2919 | mb); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2920 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2921 | ql_dbg(ql_dbg_disc, vha, 0x2004, |
| 2922 | "Unable to adjust iIDMA " |
| 2923 | "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x " |
| 2924 | "%04x.\n", fcport->port_name[0], fcport->port_name[1], |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2925 | fcport->port_name[2], fcport->port_name[3], |
| 2926 | fcport->port_name[4], fcport->port_name[5], |
| 2927 | fcport->port_name[6], fcport->port_name[7], rval, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2928 | fcport->fp_speed, mb[0], mb[1]); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2929 | } else { |
Chad Dupuis | daae62a | 2012-05-15 14:34:23 -0400 | [diff] [blame] | 2930 | link_speed = qla2x00_get_link_speed_str(ha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2931 | ql_dbg(ql_dbg_disc, vha, 0x2005, |
| 2932 | "iIDMA adjusted to %s GB/s " |
| 2933 | "on %02x%02x%02x%02x%02x%02x%02x%02x.\n", link_speed, |
| 2934 | fcport->port_name[0], fcport->port_name[1], |
| 2935 | fcport->port_name[2], fcport->port_name[3], |
| 2936 | fcport->port_name[4], fcport->port_name[5], |
| 2937 | fcport->port_name[6], fcport->port_name[7]); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2938 | } |
| 2939 | } |
| 2940 | |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2941 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2942 | qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2943 | { |
| 2944 | struct fc_rport_identifiers rport_ids; |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 2945 | struct fc_rport *rport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2946 | unsigned long flags; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2947 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2948 | qla2x00_rport_del(fcport); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2949 | |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 2950 | rport_ids.node_name = wwn_to_u64(fcport->node_name); |
| 2951 | rport_ids.port_name = wwn_to_u64(fcport->port_name); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2952 | rport_ids.port_id = fcport->d_id.b.domain << 16 | |
| 2953 | fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa; |
| 2954 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2955 | fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 2956 | if (!rport) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2957 | ql_log(ql_log_warn, vha, 0x2006, |
| 2958 | "Unable to allocate fc remote port.\n"); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 2959 | return; |
| 2960 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2961 | /* |
| 2962 | * Create target mode FC NEXUS in qla_target.c if target mode is |
| 2963 | * enabled.. |
| 2964 | */ |
| 2965 | qlt_fc_port_added(vha, fcport); |
| 2966 | |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2967 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2968 | *((fc_port_t **)rport->dd_data) = fcport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2969 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2970 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 2971 | rport->supported_classes = fcport->supported_classes; |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 2972 | |
| 2973 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2974 | if (fcport->port_type == FCT_INITIATOR) |
| 2975 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 2976 | if (fcport->port_type == FCT_TARGET) |
| 2977 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 2978 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2979 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2980 | |
| 2981 | /* |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2982 | * qla2x00_update_fcport |
| 2983 | * Updates device on list. |
| 2984 | * |
| 2985 | * Input: |
| 2986 | * ha = adapter block pointer. |
| 2987 | * fcport = port structure pointer. |
| 2988 | * |
| 2989 | * Return: |
| 2990 | * 0 - Success |
| 2991 | * BIT_0 - error |
| 2992 | * |
| 2993 | * Context: |
| 2994 | * Kernel context. |
| 2995 | */ |
| 2996 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2997 | qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2998 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2999 | fcport->vha = vha; |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 3000 | fcport->login_retry = 0; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 3001 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 3002 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3003 | qla2x00_iidma_fcport(vha, fcport); |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 3004 | qla24xx_update_fcport_fcp_prio(vha, fcport); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3005 | qla2x00_reg_remote_port(vha, fcport); |
Chad Dupuis | ec426e1 | 2011-03-30 11:46:32 -0700 | [diff] [blame] | 3006 | qla2x00_set_fcport_state(fcport, FCS_ONLINE); |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 3007 | } |
| 3008 | |
| 3009 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3010 | * qla2x00_configure_fabric |
| 3011 | * Setup SNS devices with loop ID's. |
| 3012 | * |
| 3013 | * Input: |
| 3014 | * ha = adapter block pointer. |
| 3015 | * |
| 3016 | * Returns: |
| 3017 | * 0 = success. |
| 3018 | * BIT_0 = error |
| 3019 | */ |
| 3020 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3021 | qla2x00_configure_fabric(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | { |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 3023 | int rval; |
Joe Carnuccio | 4dc77c3 | 2012-05-15 14:34:24 -0400 | [diff] [blame] | 3024 | fc_port_t *fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3025 | uint16_t next_loopid; |
| 3026 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3027 | uint16_t loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3028 | LIST_HEAD(new_fcports); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3029 | struct qla_hw_data *ha = vha->hw; |
| 3030 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3031 | |
| 3032 | /* If FL port exists, then SNS is present */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 3033 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3034 | loop_id = NPH_F_PORT; |
| 3035 | else |
| 3036 | loop_id = SNS_FL_PORT; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3037 | 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] | 3038 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3039 | ql_dbg(ql_dbg_disc, vha, 0x201f, |
| 3040 | "MBX_GET_PORT_NAME failed, No FL Port.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3041 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3042 | vha->device_flags &= ~SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3043 | return (QLA_SUCCESS); |
| 3044 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3045 | vha->device_flags |= SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3046 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3047 | do { |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 3048 | /* FDMI support. */ |
| 3049 | if (ql2xfdmienable && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3050 | test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags)) |
| 3051 | qla2x00_fdmi_register(vha); |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 3052 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3053 | /* Ensure we are logged into the SNS. */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 3054 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3055 | loop_id = NPH_SNS; |
| 3056 | else |
| 3057 | loop_id = SIMPLE_NAME_SERVER; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 3058 | rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff, |
| 3059 | 0xfc, mb, BIT_1|BIT_0); |
| 3060 | if (rval != QLA_SUCCESS) { |
| 3061 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Joe Carnuccio | 4dc77c3 | 2012-05-15 14:34:24 -0400 | [diff] [blame] | 3062 | break; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 3063 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3064 | if (mb[0] != MBS_COMMAND_COMPLETE) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3065 | ql_dbg(ql_dbg_disc, vha, 0x2042, |
| 3066 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x " |
| 3067 | "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1], |
| 3068 | mb[2], mb[6], mb[7]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3069 | return (QLA_SUCCESS); |
| 3070 | } |
| 3071 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3072 | if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) { |
| 3073 | if (qla2x00_rft_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3074 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3075 | ql_dbg(ql_dbg_disc, vha, 0x2045, |
| 3076 | "Register FC-4 TYPE failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3077 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3078 | if (qla2x00_rff_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3079 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3080 | ql_dbg(ql_dbg_disc, vha, 0x2049, |
| 3081 | "Register FC-4 Features failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3082 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3083 | if (qla2x00_rnn_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3084 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3085 | ql_dbg(ql_dbg_disc, vha, 0x204f, |
| 3086 | "Register Node Name failed.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3087 | } else if (qla2x00_rsnn_nn(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3088 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3089 | ql_dbg(ql_dbg_disc, vha, 0x2053, |
| 3090 | "Register Symobilic Node Name failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3091 | } |
| 3092 | } |
| 3093 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3094 | rval = qla2x00_find_all_fabric_devs(vha, &new_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3095 | if (rval != QLA_SUCCESS) |
| 3096 | break; |
| 3097 | |
Joe Carnuccio | 4dc77c3 | 2012-05-15 14:34:24 -0400 | [diff] [blame] | 3098 | /* Add new ports to existing port list */ |
| 3099 | list_splice_tail_init(&new_fcports, &vha->vp_fcports); |
| 3100 | |
| 3101 | /* Starting free loop ID. */ |
| 3102 | next_loopid = ha->min_external_loopid; |
| 3103 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3104 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 3105 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | break; |
| 3107 | |
| 3108 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) |
| 3109 | continue; |
| 3110 | |
Joe Carnuccio | 4dc77c3 | 2012-05-15 14:34:24 -0400 | [diff] [blame] | 3111 | /* Logout lost/gone fabric devices (non-FCP2) */ |
Joe Carnuccio | c0822b6 | 2012-05-15 14:34:21 -0400 | [diff] [blame] | 3112 | if (fcport->scan_state != QLA_FCPORT_SCAN_FOUND && |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 3113 | atomic_read(&fcport->state) == FCS_ONLINE) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3114 | qla2x00_mark_device_lost(vha, fcport, |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3115 | ql2xplogiabsentdevice, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3116 | if (fcport->loop_id != FC_NO_LOOP_ID && |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3117 | (fcport->flags & FCF_FCP2_DEVICE) == 0 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3118 | fcport->port_type != FCT_INITIATOR && |
| 3119 | fcport->port_type != FCT_BROADCAST) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3120 | ha->isp_ops->fabric_logout(vha, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3121 | fcport->loop_id, |
| 3122 | fcport->d_id.b.domain, |
| 3123 | fcport->d_id.b.area, |
| 3124 | fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3125 | } |
Joe Carnuccio | c0822b6 | 2012-05-15 14:34:21 -0400 | [diff] [blame] | 3126 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3127 | } |
Joe Carnuccio | c0822b6 | 2012-05-15 14:34:21 -0400 | [diff] [blame] | 3128 | fcport->scan_state = QLA_FCPORT_SCAN_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3129 | |
Joe Carnuccio | 4dc77c3 | 2012-05-15 14:34:24 -0400 | [diff] [blame] | 3130 | /* Login fabric devices that need a login */ |
| 3131 | if ((fcport->flags & FCF_LOGIN_NEEDED) != 0 && |
| 3132 | atomic_read(&vha->loop_down_timer) == 0) { |
| 3133 | if (fcport->loop_id == FC_NO_LOOP_ID) { |
| 3134 | fcport->loop_id = next_loopid; |
| 3135 | rval = qla2x00_find_new_loop_id( |
| 3136 | base_vha, fcport); |
| 3137 | if (rval != QLA_SUCCESS) { |
| 3138 | /* Ran out of IDs to use */ |
| 3139 | continue; |
| 3140 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3141 | } |
| 3142 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3143 | |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 3144 | /* Login and update database */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3145 | qla2x00_fabric_dev_login(vha, fcport, &next_loopid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3146 | } |
| 3147 | } while (0); |
| 3148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3149 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3150 | ql_dbg(ql_dbg_disc, vha, 0x2068, |
| 3151 | "Configure fabric error exit rval=%d.\n", rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3152 | } |
| 3153 | |
| 3154 | return (rval); |
| 3155 | } |
| 3156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | /* |
| 3158 | * qla2x00_find_all_fabric_devs |
| 3159 | * |
| 3160 | * Input: |
| 3161 | * ha = adapter block pointer. |
| 3162 | * dev = database device entry pointer. |
| 3163 | * |
| 3164 | * Returns: |
| 3165 | * 0 = success. |
| 3166 | * |
| 3167 | * Context: |
| 3168 | * Kernel context. |
| 3169 | */ |
| 3170 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3171 | qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha, |
| 3172 | struct list_head *new_fcports) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3173 | { |
| 3174 | int rval; |
| 3175 | uint16_t loop_id; |
| 3176 | fc_port_t *fcport, *new_fcport, *fcptemp; |
| 3177 | int found; |
| 3178 | |
| 3179 | sw_info_t *swl; |
| 3180 | int swl_idx; |
| 3181 | int first_dev, last_dev; |
Mike Waychison | 1516ef4 | 2010-05-04 15:01:31 -0700 | [diff] [blame] | 3182 | port_id_t wrap = {}, nxt_d_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3183 | struct qla_hw_data *ha = vha->hw; |
| 3184 | struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev); |
Anirban Chakraborty | ee546b6 | 2009-03-05 11:07:02 -0800 | [diff] [blame] | 3185 | struct scsi_qla_host *tvp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3186 | |
| 3187 | rval = QLA_SUCCESS; |
| 3188 | |
| 3189 | /* Try GID_PT to get device list, else GAN. */ |
Andrew Vasquez | 7a67735 | 2012-02-09 11:15:56 -0800 | [diff] [blame] | 3190 | if (!ha->swl) |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 3191 | ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t), |
Andrew Vasquez | 7a67735 | 2012-02-09 11:15:56 -0800 | [diff] [blame] | 3192 | GFP_KERNEL); |
| 3193 | swl = ha->swl; |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 3194 | if (!swl) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | /*EMPTY*/ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3196 | ql_dbg(ql_dbg_disc, vha, 0x2054, |
| 3197 | "GID_PT allocations failed, fallback on GA_NXT.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | } else { |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 3199 | memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3200 | if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3201 | swl = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3202 | } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3203 | swl = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3204 | } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3205 | swl = NULL; |
Andrew Vasquez | e5896bd | 2008-07-10 16:55:52 -0700 | [diff] [blame] | 3206 | } else if (ql2xiidmaenable && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3207 | qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) { |
| 3208 | qla2x00_gpsc(vha, swl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | } |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3210 | |
| 3211 | /* If other queries succeeded probe for FC-4 type */ |
| 3212 | if (swl) |
| 3213 | qla2x00_gff_id(vha, swl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3214 | } |
| 3215 | swl_idx = 0; |
| 3216 | |
| 3217 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3218 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3220 | ql_log(ql_log_warn, vha, 0x205e, |
| 3221 | "Failed to allocate memory for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3222 | return (QLA_MEMORY_ALLOC_FAILED); |
| 3223 | } |
| 3224 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | /* Set start port ID scan at adapter ID. */ |
| 3226 | first_dev = 1; |
| 3227 | last_dev = 0; |
| 3228 | |
| 3229 | /* Starting free loop ID. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3230 | loop_id = ha->min_external_loopid; |
| 3231 | for (; loop_id <= ha->max_loop_id; loop_id++) { |
| 3232 | if (qla2x00_is_reserved_id(vha, loop_id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3233 | continue; |
| 3234 | |
Giridhar Malavali | 3a6478d | 2010-05-28 15:08:20 -0700 | [diff] [blame] | 3235 | if (ha->current_topology == ISP_CFG_FL && |
| 3236 | (atomic_read(&vha->loop_down_timer) || |
| 3237 | LOOP_TRANSITION(vha))) { |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 3238 | atomic_set(&vha->loop_down_timer, 0); |
| 3239 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 3240 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3241 | break; |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 3242 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3243 | |
| 3244 | if (swl != NULL) { |
| 3245 | if (last_dev) { |
| 3246 | wrap.b24 = new_fcport->d_id.b24; |
| 3247 | } else { |
| 3248 | new_fcport->d_id.b24 = swl[swl_idx].d_id.b24; |
| 3249 | memcpy(new_fcport->node_name, |
| 3250 | swl[swl_idx].node_name, WWN_SIZE); |
| 3251 | memcpy(new_fcport->port_name, |
| 3252 | swl[swl_idx].port_name, WWN_SIZE); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3253 | memcpy(new_fcport->fabric_port_name, |
| 3254 | swl[swl_idx].fabric_port_name, WWN_SIZE); |
| 3255 | new_fcport->fp_speed = swl[swl_idx].fp_speed; |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3256 | new_fcport->fc4_type = swl[swl_idx].fc4_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3257 | |
| 3258 | if (swl[swl_idx].d_id.b.rsvd_1 != 0) { |
| 3259 | last_dev = 1; |
| 3260 | } |
| 3261 | swl_idx++; |
| 3262 | } |
| 3263 | } else { |
| 3264 | /* Send GA_NXT to the switch */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3265 | rval = qla2x00_ga_nxt(vha, new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3266 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3267 | ql_log(ql_log_warn, vha, 0x2064, |
| 3268 | "SNS scan failed -- assuming " |
| 3269 | "zero-entry result.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | list_for_each_entry_safe(fcport, fcptemp, |
| 3271 | new_fcports, list) { |
| 3272 | list_del(&fcport->list); |
| 3273 | kfree(fcport); |
| 3274 | } |
| 3275 | rval = QLA_SUCCESS; |
| 3276 | break; |
| 3277 | } |
| 3278 | } |
| 3279 | |
| 3280 | /* If wrap on switch device list, exit. */ |
| 3281 | if (first_dev) { |
| 3282 | wrap.b24 = new_fcport->d_id.b24; |
| 3283 | first_dev = 0; |
| 3284 | } else if (new_fcport->d_id.b24 == wrap.b24) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3285 | ql_dbg(ql_dbg_disc, vha, 0x2065, |
| 3286 | "Device wrap (%02x%02x%02x).\n", |
| 3287 | new_fcport->d_id.b.domain, |
| 3288 | new_fcport->d_id.b.area, |
| 3289 | new_fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3290 | break; |
| 3291 | } |
| 3292 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3293 | /* Bypass if same physical adapter. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3294 | if (new_fcport->d_id.b24 == base_vha->d_id.b24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3295 | continue; |
| 3296 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3297 | /* Bypass virtual ports of the same host. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3298 | found = 0; |
| 3299 | if (ha->num_vhosts) { |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3300 | unsigned long flags; |
| 3301 | |
| 3302 | spin_lock_irqsave(&ha->vport_slock, flags); |
Anirban Chakraborty | ee546b6 | 2009-03-05 11:07:02 -0800 | [diff] [blame] | 3303 | list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3304 | if (new_fcport->d_id.b24 == vp->d_id.b24) { |
| 3305 | found = 1; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3306 | break; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3307 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3308 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3309 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 3310 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3311 | if (found) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3312 | continue; |
| 3313 | } |
| 3314 | |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 3315 | /* Bypass if same domain and area of adapter. */ |
| 3316 | if (((new_fcport->d_id.b24 & 0xffff00) == |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3317 | (vha->d_id.b24 & 0xffff00)) && ha->current_topology == |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 3318 | ISP_CFG_FL) |
| 3319 | continue; |
| 3320 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3321 | /* Bypass reserved domain fields. */ |
| 3322 | if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0) |
| 3323 | continue; |
| 3324 | |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3325 | /* Bypass ports whose FCP-4 type is not FCP_SCSI */ |
Chad Dupuis | 4da26e1 | 2010-10-15 11:27:40 -0700 | [diff] [blame] | 3326 | if (ql2xgffidenable && |
| 3327 | (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI && |
| 3328 | new_fcport->fc4_type != FC4_TYPE_UNKNOWN)) |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3329 | continue; |
| 3330 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3331 | /* Locate matching device in database. */ |
| 3332 | found = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3333 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3334 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 3335 | WWN_SIZE)) |
| 3336 | continue; |
| 3337 | |
Joe Carnuccio | c0822b6 | 2012-05-15 14:34:21 -0400 | [diff] [blame] | 3338 | fcport->scan_state = QLA_FCPORT_SCAN_FOUND; |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 3339 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3340 | found++; |
| 3341 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3342 | /* Update port state. */ |
| 3343 | memcpy(fcport->fabric_port_name, |
| 3344 | new_fcport->fabric_port_name, WWN_SIZE); |
| 3345 | fcport->fp_speed = new_fcport->fp_speed; |
| 3346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3347 | /* |
| 3348 | * If address the same and state FCS_ONLINE, nothing |
| 3349 | * changed. |
| 3350 | */ |
| 3351 | if (fcport->d_id.b24 == new_fcport->d_id.b24 && |
| 3352 | atomic_read(&fcport->state) == FCS_ONLINE) { |
| 3353 | break; |
| 3354 | } |
| 3355 | |
| 3356 | /* |
| 3357 | * If device was not a fabric device before. |
| 3358 | */ |
| 3359 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 3360 | fcport->d_id.b24 = new_fcport->d_id.b24; |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3361 | qla2x00_clear_loop_id(fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3362 | fcport->flags |= (FCF_FABRIC_DEVICE | |
| 3363 | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3364 | break; |
| 3365 | } |
| 3366 | |
| 3367 | /* |
| 3368 | * Port ID changed or device was marked to be updated; |
| 3369 | * Log it out if still logged in and mark it for |
| 3370 | * relogin later. |
| 3371 | */ |
| 3372 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 3373 | fcport->flags |= FCF_LOGIN_NEEDED; |
| 3374 | if (fcport->loop_id != FC_NO_LOOP_ID && |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3375 | (fcport->flags & FCF_FCP2_DEVICE) == 0 && |
Arun Easi | 0eba25d | 2012-02-09 11:15:58 -0800 | [diff] [blame] | 3376 | (fcport->flags & FCF_ASYNC_SENT) == 0 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3377 | fcport->port_type != FCT_INITIATOR && |
| 3378 | fcport->port_type != FCT_BROADCAST) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3379 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3380 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3381 | fcport->d_id.b.al_pa); |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3382 | qla2x00_clear_loop_id(fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3383 | } |
| 3384 | |
| 3385 | break; |
| 3386 | } |
| 3387 | |
| 3388 | if (found) |
| 3389 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3390 | /* If device was not in our fcports list, then add it. */ |
| 3391 | list_add_tail(&new_fcport->list, new_fcports); |
| 3392 | |
| 3393 | /* Allocate a new replacement fcport. */ |
| 3394 | nxt_d_id.b24 = new_fcport->d_id.b24; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3395 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3396 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3397 | ql_log(ql_log_warn, vha, 0x2066, |
| 3398 | "Memory allocation failed for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3399 | return (QLA_MEMORY_ALLOC_FAILED); |
| 3400 | } |
| 3401 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
| 3402 | new_fcport->d_id.b24 = nxt_d_id.b24; |
| 3403 | } |
| 3404 | |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 3405 | kfree(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3406 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3407 | return (rval); |
| 3408 | } |
| 3409 | |
| 3410 | /* |
| 3411 | * qla2x00_find_new_loop_id |
| 3412 | * Scan through our port list and find a new usable loop ID. |
| 3413 | * |
| 3414 | * Input: |
| 3415 | * ha: adapter state pointer. |
| 3416 | * dev: port structure pointer. |
| 3417 | * |
| 3418 | * Returns: |
| 3419 | * qla2x00 local function return status code. |
| 3420 | * |
| 3421 | * Context: |
| 3422 | * Kernel context. |
| 3423 | */ |
Joe Carnuccio | 03bcfb5 | 2011-03-30 11:46:27 -0700 | [diff] [blame] | 3424 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3425 | 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] | 3426 | { |
| 3427 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3428 | struct qla_hw_data *ha = vha->hw; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3429 | unsigned long flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3430 | |
| 3431 | rval = QLA_SUCCESS; |
| 3432 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3433 | spin_lock_irqsave(&ha->vport_slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3434 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3435 | dev->loop_id = find_first_zero_bit(ha->loop_id_map, |
| 3436 | LOOPID_MAP_SIZE); |
| 3437 | if (dev->loop_id >= LOOPID_MAP_SIZE || |
| 3438 | qla2x00_is_reserved_id(vha, dev->loop_id)) { |
| 3439 | dev->loop_id = FC_NO_LOOP_ID; |
| 3440 | rval = QLA_FUNCTION_FAILED; |
| 3441 | } else |
| 3442 | set_bit(dev->loop_id, ha->loop_id_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3443 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3444 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3445 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3446 | if (rval == QLA_SUCCESS) |
| 3447 | ql_dbg(ql_dbg_disc, dev->vha, 0x2086, |
| 3448 | "Assigning new loopid=%x, portid=%x.\n", |
| 3449 | dev->loop_id, dev->d_id.b24); |
| 3450 | else |
| 3451 | ql_log(ql_log_warn, dev->vha, 0x2087, |
| 3452 | "No loop_id's available, portid=%x.\n", |
| 3453 | dev->d_id.b24); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3454 | |
| 3455 | return (rval); |
| 3456 | } |
| 3457 | |
| 3458 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3459 | * qla2x00_fabric_dev_login |
| 3460 | * Login fabric target device and update FC port database. |
| 3461 | * |
| 3462 | * Input: |
| 3463 | * ha: adapter state pointer. |
| 3464 | * fcport: port structure list pointer. |
| 3465 | * next_loopid: contains value of a new loop ID that can be used |
| 3466 | * by the next login attempt. |
| 3467 | * |
| 3468 | * Returns: |
| 3469 | * qla2x00 local function return status code. |
| 3470 | * |
| 3471 | * Context: |
| 3472 | * Kernel context. |
| 3473 | */ |
| 3474 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3475 | 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] | 3476 | uint16_t *next_loopid) |
| 3477 | { |
| 3478 | int rval; |
| 3479 | int retry; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3480 | uint8_t opts; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3481 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3482 | |
| 3483 | rval = QLA_SUCCESS; |
| 3484 | retry = 0; |
| 3485 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3486 | if (IS_ALOGIO_CAPABLE(ha)) { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 3487 | if (fcport->flags & FCF_ASYNC_SENT) |
| 3488 | return rval; |
| 3489 | fcport->flags |= FCF_ASYNC_SENT; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3490 | rval = qla2x00_post_async_login_work(vha, fcport, NULL); |
| 3491 | if (!rval) |
| 3492 | return rval; |
| 3493 | } |
| 3494 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 3495 | fcport->flags &= ~FCF_ASYNC_SENT; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3496 | rval = qla2x00_fabric_login(vha, fcport, next_loopid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3497 | if (rval == QLA_SUCCESS) { |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3498 | /* Send an ADISC to FCP2 devices.*/ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3499 | opts = 0; |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3500 | if (fcport->flags & FCF_FCP2_DEVICE) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3501 | opts |= BIT_1; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3502 | rval = qla2x00_get_port_database(vha, fcport, opts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3503 | if (rval != QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3504 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3505 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3506 | fcport->d_id.b.al_pa); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3507 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3508 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3509 | qla2x00_update_fcport(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3510 | } |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 3511 | } else { |
| 3512 | /* Retry Login. */ |
| 3513 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3514 | } |
| 3515 | |
| 3516 | return (rval); |
| 3517 | } |
| 3518 | |
| 3519 | /* |
| 3520 | * qla2x00_fabric_login |
| 3521 | * Issue fabric login command. |
| 3522 | * |
| 3523 | * Input: |
| 3524 | * ha = adapter block pointer. |
| 3525 | * device = pointer to FC device type structure. |
| 3526 | * |
| 3527 | * Returns: |
| 3528 | * 0 - Login successfully |
| 3529 | * 1 - Login failed |
| 3530 | * 2 - Initiator device |
| 3531 | * 3 - Fatal error |
| 3532 | */ |
| 3533 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3534 | qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3535 | uint16_t *next_loopid) |
| 3536 | { |
| 3537 | int rval; |
| 3538 | int retry; |
| 3539 | uint16_t tmp_loopid; |
| 3540 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3541 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3542 | |
| 3543 | retry = 0; |
| 3544 | tmp_loopid = 0; |
| 3545 | |
| 3546 | for (;;) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3547 | ql_dbg(ql_dbg_disc, vha, 0x2000, |
| 3548 | "Trying Fabric Login w/loop id 0x%04x for port " |
| 3549 | "%02x%02x%02x.\n", |
| 3550 | fcport->loop_id, fcport->d_id.b.domain, |
| 3551 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3552 | |
| 3553 | /* Login fcport on switch. */ |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 3554 | rval = ha->isp_ops->fabric_login(vha, fcport->loop_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3555 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3556 | fcport->d_id.b.al_pa, mb, BIT_0); |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 3557 | if (rval != QLA_SUCCESS) { |
| 3558 | return rval; |
| 3559 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3560 | if (mb[0] == MBS_PORT_ID_USED) { |
| 3561 | /* |
| 3562 | * Device has another loop ID. The firmware team |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3563 | * recommends the driver perform an implicit login with |
| 3564 | * the specified ID again. The ID we just used is save |
| 3565 | * here so we return with an ID that can be tried by |
| 3566 | * the next login. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3567 | */ |
| 3568 | retry++; |
| 3569 | tmp_loopid = fcport->loop_id; |
| 3570 | fcport->loop_id = mb[1]; |
| 3571 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3572 | ql_dbg(ql_dbg_disc, vha, 0x2001, |
| 3573 | "Fabric Login: port in use - next loop " |
| 3574 | "id=0x%04x, port id= %02x%02x%02x.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3575 | fcport->loop_id, fcport->d_id.b.domain, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3576 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3577 | |
| 3578 | } else if (mb[0] == MBS_COMMAND_COMPLETE) { |
| 3579 | /* |
| 3580 | * Login succeeded. |
| 3581 | */ |
| 3582 | if (retry) { |
| 3583 | /* A retry occurred before. */ |
| 3584 | *next_loopid = tmp_loopid; |
| 3585 | } else { |
| 3586 | /* |
| 3587 | * No retry occurred before. Just increment the |
| 3588 | * ID value for next login. |
| 3589 | */ |
| 3590 | *next_loopid = (fcport->loop_id + 1); |
| 3591 | } |
| 3592 | |
| 3593 | if (mb[1] & BIT_0) { |
| 3594 | fcport->port_type = FCT_INITIATOR; |
| 3595 | } else { |
| 3596 | fcport->port_type = FCT_TARGET; |
| 3597 | if (mb[1] & BIT_1) { |
Santosh Vernekar | 8474f3a | 2009-08-25 11:36:16 -0700 | [diff] [blame] | 3598 | fcport->flags |= FCF_FCP2_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3599 | } |
| 3600 | } |
| 3601 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 3602 | if (mb[10] & BIT_0) |
| 3603 | fcport->supported_classes |= FC_COS_CLASS2; |
| 3604 | if (mb[10] & BIT_1) |
| 3605 | fcport->supported_classes |= FC_COS_CLASS3; |
| 3606 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3607 | if (IS_FWI2_CAPABLE(ha)) { |
| 3608 | if (mb[10] & BIT_7) |
| 3609 | fcport->flags |= |
| 3610 | FCF_CONF_COMP_SUPPORTED; |
| 3611 | } |
| 3612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3613 | rval = QLA_SUCCESS; |
| 3614 | break; |
| 3615 | } else if (mb[0] == MBS_LOOP_ID_USED) { |
| 3616 | /* |
| 3617 | * Loop ID already used, try next loop ID. |
| 3618 | */ |
| 3619 | fcport->loop_id++; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3620 | rval = qla2x00_find_new_loop_id(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3621 | if (rval != QLA_SUCCESS) { |
| 3622 | /* Ran out of loop IDs to use */ |
| 3623 | break; |
| 3624 | } |
| 3625 | } else if (mb[0] == MBS_COMMAND_ERROR) { |
| 3626 | /* |
| 3627 | * Firmware possibly timed out during login. If NO |
| 3628 | * retries are left to do then the device is declared |
| 3629 | * dead. |
| 3630 | */ |
| 3631 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3632 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3633 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3634 | fcport->d_id.b.al_pa); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3635 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3636 | |
| 3637 | rval = 1; |
| 3638 | break; |
| 3639 | } else { |
| 3640 | /* |
| 3641 | * unrecoverable / not handled error |
| 3642 | */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3643 | ql_dbg(ql_dbg_disc, vha, 0x2002, |
| 3644 | "Failed=%x port_id=%02x%02x%02x loop_id=%x " |
| 3645 | "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain, |
| 3646 | fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 3647 | fcport->loop_id, jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3648 | |
| 3649 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3650 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3651 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3652 | fcport->d_id.b.al_pa); |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3653 | qla2x00_clear_loop_id(fcport); |
Andrew Vasquez | 0eedfcf | 2005-10-27 11:09:38 -0700 | [diff] [blame] | 3654 | fcport->login_retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3655 | |
| 3656 | rval = 3; |
| 3657 | break; |
| 3658 | } |
| 3659 | } |
| 3660 | |
| 3661 | return (rval); |
| 3662 | } |
| 3663 | |
| 3664 | /* |
| 3665 | * qla2x00_local_device_login |
| 3666 | * Issue local device login command. |
| 3667 | * |
| 3668 | * Input: |
| 3669 | * ha = adapter block pointer. |
| 3670 | * loop_id = loop id of device to login to. |
| 3671 | * |
| 3672 | * Returns (Where's the #define!!!!): |
| 3673 | * 0 - Login successfully |
| 3674 | * 1 - Login failed |
| 3675 | * 3 - Fatal error |
| 3676 | */ |
| 3677 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3678 | 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] | 3679 | { |
| 3680 | int rval; |
| 3681 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
| 3682 | |
| 3683 | memset(mb, 0, sizeof(mb)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3684 | rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3685 | if (rval == QLA_SUCCESS) { |
| 3686 | /* Interrogate mailbox registers for any errors */ |
| 3687 | if (mb[0] == MBS_COMMAND_ERROR) |
| 3688 | rval = 1; |
| 3689 | else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR) |
| 3690 | /* device not in PCB table */ |
| 3691 | rval = 3; |
| 3692 | } |
| 3693 | |
| 3694 | return (rval); |
| 3695 | } |
| 3696 | |
| 3697 | /* |
| 3698 | * qla2x00_loop_resync |
| 3699 | * Resync with fibre channel devices. |
| 3700 | * |
| 3701 | * Input: |
| 3702 | * ha = adapter block pointer. |
| 3703 | * |
| 3704 | * Returns: |
| 3705 | * 0 = success |
| 3706 | */ |
| 3707 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3708 | qla2x00_loop_resync(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3709 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3710 | int rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3711 | uint32_t wait_time; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 3712 | struct req_que *req; |
| 3713 | struct rsp_que *rsp; |
| 3714 | |
Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 3715 | if (vha->hw->flags.cpu_affinity_enabled) |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 3716 | req = vha->hw->req_q_map[0]; |
| 3717 | else |
| 3718 | req = vha->req; |
| 3719 | rsp = req->rsp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3720 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3721 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 3722 | if (vha->flags.online) { |
| 3723 | if (!(rval = qla2x00_fw_ready(vha))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3724 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 3725 | wait_time = 256; |
| 3726 | do { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3727 | /* Issue a marker after FW becomes ready. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3728 | qla2x00_marker(vha, req, rsp, 0, 0, |
| 3729 | MK_SYNC_ALL); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3730 | vha->marker_needed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3731 | |
| 3732 | /* Remap devices on Loop. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3733 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3734 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3735 | qla2x00_configure_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3736 | wait_time--; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3737 | } while (!atomic_read(&vha->loop_down_timer) && |
| 3738 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
| 3739 | && wait_time && (test_bit(LOOP_RESYNC_NEEDED, |
| 3740 | &vha->dpc_flags))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3741 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3742 | } |
| 3743 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3744 | if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3745 | return (QLA_FUNCTION_FAILED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3746 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3747 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3748 | ql_dbg(ql_dbg_disc, vha, 0x206c, |
| 3749 | "%s *** FAILED ***.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3750 | |
| 3751 | return (rval); |
| 3752 | } |
| 3753 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 3754 | /* |
| 3755 | * qla2x00_perform_loop_resync |
| 3756 | * Description: This function will set the appropriate flags and call |
| 3757 | * qla2x00_loop_resync. If successful loop will be resynced |
| 3758 | * Arguments : scsi_qla_host_t pointer |
| 3759 | * returm : Success or Failure |
| 3760 | */ |
| 3761 | |
| 3762 | int qla2x00_perform_loop_resync(scsi_qla_host_t *ha) |
| 3763 | { |
| 3764 | int32_t rval = 0; |
| 3765 | |
| 3766 | if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) { |
| 3767 | /*Configure the flags so that resync happens properly*/ |
| 3768 | atomic_set(&ha->loop_down_timer, 0); |
| 3769 | if (!(ha->device_flags & DFLG_NO_CABLE)) { |
| 3770 | atomic_set(&ha->loop_state, LOOP_UP); |
| 3771 | set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); |
| 3772 | set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags); |
| 3773 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
| 3774 | |
| 3775 | rval = qla2x00_loop_resync(ha); |
| 3776 | } else |
| 3777 | atomic_set(&ha->loop_state, LOOP_DEAD); |
| 3778 | |
| 3779 | clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags); |
| 3780 | } |
| 3781 | |
| 3782 | return rval; |
| 3783 | } |
| 3784 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3785 | void |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 3786 | qla2x00_update_fcports(scsi_qla_host_t *base_vha) |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3787 | { |
| 3788 | fc_port_t *fcport; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3789 | struct scsi_qla_host *vha; |
| 3790 | struct qla_hw_data *ha = base_vha->hw; |
| 3791 | unsigned long flags; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3792 | |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3793 | spin_lock_irqsave(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3794 | /* Go with deferred removal of rport references. */ |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3795 | list_for_each_entry(vha, &base_vha->hw->vp_list, list) { |
| 3796 | atomic_inc(&vha->vref_count); |
| 3797 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Dan Carpenter | 8ae598d | 2010-12-21 16:00:15 -0800 | [diff] [blame] | 3798 | if (fcport->drport && |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3799 | atomic_read(&fcport->state) != FCS_UNCONFIGURED) { |
| 3800 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 3801 | |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 3802 | qla2x00_rport_del(fcport); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3803 | |
| 3804 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 3805 | } |
| 3806 | } |
| 3807 | atomic_dec(&vha->vref_count); |
| 3808 | } |
| 3809 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3810 | } |
| 3811 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame^] | 3812 | /* Assumes idc_lock always held on entry */ |
| 3813 | void |
| 3814 | qla83xx_reset_ownership(scsi_qla_host_t *vha) |
| 3815 | { |
| 3816 | struct qla_hw_data *ha = vha->hw; |
| 3817 | uint32_t drv_presence, drv_presence_mask; |
| 3818 | uint32_t dev_part_info1, dev_part_info2, class_type; |
| 3819 | uint32_t class_type_mask = 0x3; |
| 3820 | uint16_t fcoe_other_function = 0xffff, i; |
| 3821 | |
| 3822 | qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); |
| 3823 | |
| 3824 | qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1); |
| 3825 | qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2); |
| 3826 | for (i = 0; i < 8; i++) { |
| 3827 | class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask); |
| 3828 | if ((class_type == QLA83XX_CLASS_TYPE_FCOE) && |
| 3829 | (i != ha->portnum)) { |
| 3830 | fcoe_other_function = i; |
| 3831 | break; |
| 3832 | } |
| 3833 | } |
| 3834 | if (fcoe_other_function == 0xffff) { |
| 3835 | for (i = 0; i < 8; i++) { |
| 3836 | class_type = ((dev_part_info2 >> (i * 4)) & |
| 3837 | class_type_mask); |
| 3838 | if ((class_type == QLA83XX_CLASS_TYPE_FCOE) && |
| 3839 | ((i + 8) != ha->portnum)) { |
| 3840 | fcoe_other_function = i + 8; |
| 3841 | break; |
| 3842 | } |
| 3843 | } |
| 3844 | } |
| 3845 | /* |
| 3846 | * Prepare drv-presence mask based on fcoe functions present. |
| 3847 | * However consider only valid physical fcoe function numbers (0-15). |
| 3848 | */ |
| 3849 | drv_presence_mask = ~((1 << (ha->portnum)) | |
| 3850 | ((fcoe_other_function == 0xffff) ? |
| 3851 | 0 : (1 << (fcoe_other_function)))); |
| 3852 | |
| 3853 | /* We are the reset owner iff: |
| 3854 | * - No other protocol drivers present. |
| 3855 | * - This is the lowest among fcoe functions. */ |
| 3856 | if (!(drv_presence & drv_presence_mask) && |
| 3857 | (ha->portnum < fcoe_other_function)) { |
| 3858 | ql_dbg(ql_dbg_p3p, vha, 0xb07f, |
| 3859 | "This host is Reset owner.\n"); |
| 3860 | ha->flags.nic_core_reset_owner = 1; |
| 3861 | } |
| 3862 | } |
| 3863 | |
| 3864 | int |
| 3865 | __qla83xx_set_drv_ack(scsi_qla_host_t *vha) |
| 3866 | { |
| 3867 | int rval = QLA_SUCCESS; |
| 3868 | struct qla_hw_data *ha = vha->hw; |
| 3869 | uint32_t drv_ack; |
| 3870 | |
| 3871 | rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack); |
| 3872 | if (rval == QLA_SUCCESS) { |
| 3873 | drv_ack |= (1 << ha->portnum); |
| 3874 | rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack); |
| 3875 | } |
| 3876 | |
| 3877 | return rval; |
| 3878 | } |
| 3879 | |
| 3880 | int |
| 3881 | qla83xx_set_drv_ack(scsi_qla_host_t *vha) |
| 3882 | { |
| 3883 | int rval = QLA_SUCCESS; |
| 3884 | |
| 3885 | qla83xx_idc_lock(vha, 0); |
| 3886 | rval = __qla83xx_set_drv_ack(vha); |
| 3887 | qla83xx_idc_unlock(vha, 0); |
| 3888 | |
| 3889 | return rval; |
| 3890 | } |
| 3891 | |
| 3892 | int |
| 3893 | __qla83xx_clear_drv_ack(scsi_qla_host_t *vha) |
| 3894 | { |
| 3895 | int rval = QLA_SUCCESS; |
| 3896 | struct qla_hw_data *ha = vha->hw; |
| 3897 | uint32_t drv_ack; |
| 3898 | |
| 3899 | rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack); |
| 3900 | if (rval == QLA_SUCCESS) { |
| 3901 | drv_ack &= ~(1 << ha->portnum); |
| 3902 | rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack); |
| 3903 | } |
| 3904 | |
| 3905 | return rval; |
| 3906 | } |
| 3907 | |
| 3908 | int |
| 3909 | qla83xx_clear_drv_ack(scsi_qla_host_t *vha) |
| 3910 | { |
| 3911 | int rval = QLA_SUCCESS; |
| 3912 | |
| 3913 | qla83xx_idc_lock(vha, 0); |
| 3914 | rval = __qla83xx_clear_drv_ack(vha); |
| 3915 | qla83xx_idc_unlock(vha, 0); |
| 3916 | |
| 3917 | return rval; |
| 3918 | } |
| 3919 | |
| 3920 | const char * |
| 3921 | qla83xx_dev_state_to_string(uint32_t dev_state) |
| 3922 | { |
| 3923 | switch (dev_state) { |
| 3924 | case QLA8XXX_DEV_COLD: |
| 3925 | return "COLD/RE-INIT"; |
| 3926 | case QLA8XXX_DEV_INITIALIZING: |
| 3927 | return "INITIALIZING"; |
| 3928 | case QLA8XXX_DEV_READY: |
| 3929 | return "READY"; |
| 3930 | case QLA8XXX_DEV_NEED_RESET: |
| 3931 | return "NEED RESET"; |
| 3932 | case QLA8XXX_DEV_NEED_QUIESCENT: |
| 3933 | return "NEED QUIESCENT"; |
| 3934 | case QLA8XXX_DEV_FAILED: |
| 3935 | return "FAILED"; |
| 3936 | case QLA8XXX_DEV_QUIESCENT: |
| 3937 | return "QUIESCENT"; |
| 3938 | default: |
| 3939 | return "Unknown"; |
| 3940 | } |
| 3941 | } |
| 3942 | |
| 3943 | /* Assumes idc-lock always held on entry */ |
| 3944 | void |
| 3945 | qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type) |
| 3946 | { |
| 3947 | struct qla_hw_data *ha = vha->hw; |
| 3948 | uint32_t idc_audit_reg = 0, duration_secs = 0; |
| 3949 | |
| 3950 | switch (audit_type) { |
| 3951 | case IDC_AUDIT_TIMESTAMP: |
| 3952 | ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000); |
| 3953 | idc_audit_reg = (ha->portnum) | |
| 3954 | (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8); |
| 3955 | qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg); |
| 3956 | break; |
| 3957 | |
| 3958 | case IDC_AUDIT_COMPLETION: |
| 3959 | duration_secs = ((jiffies_to_msecs(jiffies) - |
| 3960 | jiffies_to_msecs(ha->idc_audit_ts)) / 1000); |
| 3961 | idc_audit_reg = (ha->portnum) | |
| 3962 | (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8); |
| 3963 | qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg); |
| 3964 | break; |
| 3965 | |
| 3966 | default: |
| 3967 | ql_log(ql_log_warn, vha, 0xb078, |
| 3968 | "Invalid audit type specified.\n"); |
| 3969 | break; |
| 3970 | } |
| 3971 | } |
| 3972 | |
| 3973 | /* Assumes idc_lock always held on entry */ |
| 3974 | int |
| 3975 | qla83xx_initiating_reset(scsi_qla_host_t *vha) |
| 3976 | { |
| 3977 | struct qla_hw_data *ha = vha->hw; |
| 3978 | uint32_t idc_control, dev_state; |
| 3979 | |
| 3980 | __qla83xx_get_idc_control(vha, &idc_control); |
| 3981 | if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) { |
| 3982 | ql_log(ql_log_info, vha, 0xb080, |
| 3983 | "NIC Core reset has been disabled. idc-control=0x%x\n", |
| 3984 | idc_control); |
| 3985 | return QLA_FUNCTION_FAILED; |
| 3986 | } |
| 3987 | |
| 3988 | /* Set NEED-RESET iff in READY state and we are the reset-owner */ |
| 3989 | qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state); |
| 3990 | if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) { |
| 3991 | qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, |
| 3992 | QLA8XXX_DEV_NEED_RESET); |
| 3993 | ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n"); |
| 3994 | qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP); |
| 3995 | } else { |
| 3996 | const char *state = qla83xx_dev_state_to_string(dev_state); |
| 3997 | ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state); |
| 3998 | |
| 3999 | /* SV: XXX: Is timeout required here? */ |
| 4000 | /* Wait for IDC state change READY -> NEED_RESET */ |
| 4001 | while (dev_state == QLA8XXX_DEV_READY) { |
| 4002 | qla83xx_idc_unlock(vha, 0); |
| 4003 | msleep(200); |
| 4004 | qla83xx_idc_lock(vha, 0); |
| 4005 | qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state); |
| 4006 | } |
| 4007 | } |
| 4008 | |
| 4009 | /* Send IDC ack by writing to drv-ack register */ |
| 4010 | __qla83xx_set_drv_ack(vha); |
| 4011 | |
| 4012 | return QLA_SUCCESS; |
| 4013 | } |
| 4014 | |
| 4015 | int |
| 4016 | __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control) |
| 4017 | { |
| 4018 | return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control); |
| 4019 | } |
| 4020 | |
| 4021 | int |
| 4022 | qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control) |
| 4023 | { |
| 4024 | int rval = QLA_SUCCESS; |
| 4025 | |
| 4026 | qla83xx_idc_lock(vha, 0); |
| 4027 | rval = __qla83xx_set_idc_control(vha, idc_control); |
| 4028 | qla83xx_idc_unlock(vha, 0); |
| 4029 | |
| 4030 | return rval; |
| 4031 | } |
| 4032 | |
| 4033 | int |
| 4034 | __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control) |
| 4035 | { |
| 4036 | return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control); |
| 4037 | } |
| 4038 | |
| 4039 | int |
| 4040 | qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control) |
| 4041 | { |
| 4042 | int rval = QLA_SUCCESS; |
| 4043 | |
| 4044 | qla83xx_idc_lock(vha, 0); |
| 4045 | rval = __qla83xx_get_idc_control(vha, idc_control); |
| 4046 | qla83xx_idc_unlock(vha, 0); |
| 4047 | |
| 4048 | return rval; |
| 4049 | } |
| 4050 | |
| 4051 | int |
| 4052 | qla83xx_check_driver_presence(scsi_qla_host_t *vha) |
| 4053 | { |
| 4054 | uint32_t drv_presence = 0; |
| 4055 | struct qla_hw_data *ha = vha->hw; |
| 4056 | |
| 4057 | qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); |
| 4058 | if (drv_presence & (1 << ha->portnum)) |
| 4059 | return QLA_SUCCESS; |
| 4060 | else |
| 4061 | return QLA_TEST_FAILED; |
| 4062 | } |
| 4063 | |
| 4064 | int |
| 4065 | qla83xx_nic_core_reset(scsi_qla_host_t *vha) |
| 4066 | { |
| 4067 | int rval = QLA_SUCCESS; |
| 4068 | struct qla_hw_data *ha = vha->hw; |
| 4069 | |
| 4070 | ql_dbg(ql_dbg_p3p, vha, 0xb058, |
| 4071 | "Entered %s().\n", __func__); |
| 4072 | |
| 4073 | if (vha->device_flags & DFLG_DEV_FAILED) { |
| 4074 | ql_log(ql_log_warn, vha, 0xb059, |
| 4075 | "Device in unrecoverable FAILED state.\n"); |
| 4076 | return QLA_FUNCTION_FAILED; |
| 4077 | } |
| 4078 | |
| 4079 | qla83xx_idc_lock(vha, 0); |
| 4080 | |
| 4081 | if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) { |
| 4082 | ql_log(ql_log_warn, vha, 0xb05a, |
| 4083 | "Function=0x%x has been removed from IDC participation.\n", |
| 4084 | ha->portnum); |
| 4085 | rval = QLA_FUNCTION_FAILED; |
| 4086 | goto exit; |
| 4087 | } |
| 4088 | |
| 4089 | qla83xx_reset_ownership(vha); |
| 4090 | |
| 4091 | rval = qla83xx_initiating_reset(vha); |
| 4092 | |
| 4093 | /* |
| 4094 | * Perform reset if we are the reset-owner, |
| 4095 | * else wait till IDC state changes to READY/FAILED. |
| 4096 | */ |
| 4097 | if (rval == QLA_SUCCESS) { |
| 4098 | rval = qla83xx_idc_state_handler(vha); |
| 4099 | |
| 4100 | if (rval == QLA_SUCCESS) |
| 4101 | ha->flags.nic_core_hung = 0; |
| 4102 | __qla83xx_clear_drv_ack(vha); |
| 4103 | } |
| 4104 | |
| 4105 | exit: |
| 4106 | qla83xx_idc_unlock(vha, 0); |
| 4107 | |
| 4108 | ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__); |
| 4109 | |
| 4110 | return rval; |
| 4111 | } |
| 4112 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4113 | /* |
| 4114 | * qla82xx_quiescent_state_cleanup |
| 4115 | * Description: This function will block the new I/Os |
| 4116 | * Its not aborting any I/Os as context |
| 4117 | * is not destroyed during quiescence |
| 4118 | * Arguments: scsi_qla_host_t |
| 4119 | * return : void |
| 4120 | */ |
| 4121 | void |
| 4122 | qla82xx_quiescent_state_cleanup(scsi_qla_host_t *vha) |
| 4123 | { |
| 4124 | struct qla_hw_data *ha = vha->hw; |
| 4125 | struct scsi_qla_host *vp; |
| 4126 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4127 | ql_dbg(ql_dbg_p3p, vha, 0xb002, |
| 4128 | "Performing ISP error recovery - ha=%p.\n", ha); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4129 | |
| 4130 | atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); |
| 4131 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 4132 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 4133 | qla2x00_mark_all_devices_lost(vha, 0); |
| 4134 | list_for_each_entry(vp, &ha->vp_list, list) |
| 4135 | qla2x00_mark_all_devices_lost(vha, 0); |
| 4136 | } else { |
| 4137 | if (!atomic_read(&vha->loop_down_timer)) |
| 4138 | atomic_set(&vha->loop_down_timer, |
| 4139 | LOOP_DOWN_TIME); |
| 4140 | } |
| 4141 | /* Wait for pending cmds to complete */ |
| 4142 | qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST); |
| 4143 | } |
| 4144 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4145 | void |
| 4146 | qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha) |
| 4147 | { |
| 4148 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4149 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4150 | unsigned long flags; |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 4151 | fc_port_t *fcport; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4152 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 4153 | /* For ISP82XX, driver waits for completion of the commands. |
| 4154 | * online flag should be set. |
| 4155 | */ |
| 4156 | if (!IS_QLA82XX(ha)) |
| 4157 | vha->flags.online = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4158 | ha->flags.chip_reset_done = 0; |
| 4159 | clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Saurav Kashyap | 2be21fa | 2012-05-15 14:34:16 -0400 | [diff] [blame] | 4160 | vha->qla_stats.total_isp_aborts++; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4161 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4162 | ql_log(ql_log_info, vha, 0x00af, |
| 4163 | "Performing ISP error recovery - ha=%p.\n", ha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4164 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 4165 | /* For ISP82XX, reset_chip is just disabling interrupts. |
| 4166 | * Driver waits for the completion of the commands. |
| 4167 | * the interrupts need to be enabled. |
| 4168 | */ |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4169 | if (!IS_QLA82XX(ha)) |
| 4170 | ha->isp_ops->reset_chip(vha); |
| 4171 | |
| 4172 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 4173 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 4174 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 4175 | qla2x00_mark_all_devices_lost(vha, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4176 | |
| 4177 | spin_lock_irqsave(&ha->vport_slock, flags); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4178 | list_for_each_entry(vp, &ha->vp_list, list) { |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4179 | atomic_inc(&vp->vref_count); |
| 4180 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4181 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4182 | qla2x00_mark_all_devices_lost(vp, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4183 | |
| 4184 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4185 | atomic_dec(&vp->vref_count); |
| 4186 | } |
| 4187 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4188 | } else { |
| 4189 | if (!atomic_read(&vha->loop_down_timer)) |
| 4190 | atomic_set(&vha->loop_down_timer, |
| 4191 | LOOP_DOWN_TIME); |
| 4192 | } |
| 4193 | |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 4194 | /* Clear all async request states across all VPs. */ |
| 4195 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 4196 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 4197 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4198 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 4199 | atomic_inc(&vp->vref_count); |
| 4200 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4201 | |
| 4202 | list_for_each_entry(fcport, &vp->vp_fcports, list) |
| 4203 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 4204 | |
| 4205 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4206 | atomic_dec(&vp->vref_count); |
| 4207 | } |
| 4208 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4209 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 4210 | if (!ha->flags.eeh_busy) { |
| 4211 | /* Make sure for ISP 82XX IO DMA is complete */ |
| 4212 | if (IS_QLA82XX(ha)) { |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 4213 | qla82xx_chip_reset_cleanup(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4214 | ql_log(ql_log_info, vha, 0x00b4, |
| 4215 | "Done chip reset cleanup.\n"); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4216 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 4217 | /* Done waiting for pending commands. |
| 4218 | * Reset the online flag. |
| 4219 | */ |
| 4220 | vha->flags.online = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4221 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4222 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 4223 | /* Requeue all commands in outstanding command list. */ |
| 4224 | qla2x00_abort_all_cmds(vha, DID_RESET << 16); |
| 4225 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4226 | } |
| 4227 | |
| 4228 | /* |
| 4229 | * qla2x00_abort_isp |
| 4230 | * Resets ISP and aborts all outstanding commands. |
| 4231 | * |
| 4232 | * Input: |
| 4233 | * ha = adapter block pointer. |
| 4234 | * |
| 4235 | * Returns: |
| 4236 | * 0 = success |
| 4237 | */ |
| 4238 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4239 | qla2x00_abort_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4240 | { |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 4241 | int rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4242 | uint8_t status = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4243 | struct qla_hw_data *ha = vha->hw; |
| 4244 | struct scsi_qla_host *vp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4245 | struct req_que *req = ha->req_q_map[0]; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4246 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4247 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame^] | 4248 | if (IS_QLA8031(ha)) { |
| 4249 | ql_dbg(ql_dbg_p3p, vha, 0xb05c, |
| 4250 | "Clearing fcoe driver presence.\n"); |
| 4251 | if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS) |
| 4252 | ql_dbg(ql_dbg_p3p, vha, 0xb073, |
| 4253 | "Erro while clearing DRV-Presence.\n"); |
| 4254 | } |
| 4255 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4256 | if (vha->flags.online) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4257 | qla2x00_abort_isp_cleanup(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4258 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 4259 | if (unlikely(pci_channel_offline(ha->pdev) && |
| 4260 | ha->flags.pci_channel_io_perm_failure)) { |
| 4261 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 4262 | status = 0; |
| 4263 | return status; |
| 4264 | } |
| 4265 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4266 | ha->isp_ops->get_flash_version(vha, req->ring); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 4267 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4268 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4269 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4270 | if (!qla2x00_restart_isp(vha)) { |
| 4271 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4272 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4273 | if (!atomic_read(&vha->loop_down_timer)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4274 | /* |
| 4275 | * Issue marker command only when we are going |
| 4276 | * to start the I/O . |
| 4277 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4278 | vha->marker_needed = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4279 | } |
| 4280 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4281 | vha->flags.online = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4282 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 4283 | ha->isp_ops->enable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4284 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4285 | ha->isp_abort_cnt = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4286 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 4287 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 4288 | if (IS_QLA81XX(ha) || IS_QLA8031(ha)) |
| 4289 | qla2x00_get_fw_version(vha); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 4290 | if (ha->fce) { |
| 4291 | ha->flags.fce_enabled = 1; |
| 4292 | memset(ha->fce, 0, |
| 4293 | fce_calc_size(ha->fce_bufs)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4294 | rval = qla2x00_enable_fce_trace(vha, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 4295 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 4296 | &ha->fce_bufs); |
| 4297 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4298 | ql_log(ql_log_warn, vha, 0x8033, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 4299 | "Unable to reinitialize FCE " |
| 4300 | "(%d).\n", rval); |
| 4301 | ha->flags.fce_enabled = 0; |
| 4302 | } |
| 4303 | } |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 4304 | |
| 4305 | if (ha->eft) { |
| 4306 | memset(ha->eft, 0, EFT_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4307 | rval = qla2x00_enable_eft_trace(vha, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 4308 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 4309 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4310 | ql_log(ql_log_warn, vha, 0x8034, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 4311 | "Unable to reinitialize EFT " |
| 4312 | "(%d).\n", rval); |
| 4313 | } |
| 4314 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4315 | } else { /* failed the ISP abort */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4316 | vha->flags.online = 1; |
| 4317 | if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4318 | if (ha->isp_abort_cnt == 0) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4319 | ql_log(ql_log_fatal, vha, 0x8035, |
| 4320 | "ISP error recover failed - " |
| 4321 | "board disabled.\n"); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4322 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4323 | * The next call disables the board |
| 4324 | * completely. |
| 4325 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4326 | ha->isp_ops->reset_adapter(vha); |
| 4327 | vha->flags.online = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4328 | clear_bit(ISP_ABORT_RETRY, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4329 | &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4330 | status = 0; |
| 4331 | } else { /* schedule another ISP abort */ |
| 4332 | ha->isp_abort_cnt--; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4333 | ql_dbg(ql_dbg_taskm, vha, 0x8020, |
| 4334 | "ISP abort - retry remaining %d.\n", |
| 4335 | ha->isp_abort_cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4336 | status = 1; |
| 4337 | } |
| 4338 | } else { |
| 4339 | ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4340 | ql_dbg(ql_dbg_taskm, vha, 0x8021, |
| 4341 | "ISP error recovery - retrying (%d) " |
| 4342 | "more times.\n", ha->isp_abort_cnt); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4343 | set_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4344 | status = 1; |
| 4345 | } |
| 4346 | } |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4348 | } |
| 4349 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4350 | if (!status) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4351 | ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4352 | |
| 4353 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4354 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 4355 | if (vp->vp_idx) { |
| 4356 | atomic_inc(&vp->vref_count); |
| 4357 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4358 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4359 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4360 | |
| 4361 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4362 | atomic_dec(&vp->vref_count); |
| 4363 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4364 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4365 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4366 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame^] | 4367 | if (IS_QLA8031(ha)) { |
| 4368 | ql_dbg(ql_dbg_p3p, vha, 0xb05d, |
| 4369 | "Setting back fcoe driver presence.\n"); |
| 4370 | if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS) |
| 4371 | ql_dbg(ql_dbg_p3p, vha, 0xb074, |
| 4372 | "Error while setting DRV-Presence.\n"); |
| 4373 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4374 | } else { |
Joe Perches | d8424f6 | 2011-11-18 09:03:06 -0800 | [diff] [blame] | 4375 | ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n", |
| 4376 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4377 | } |
| 4378 | |
| 4379 | return(status); |
| 4380 | } |
| 4381 | |
| 4382 | /* |
| 4383 | * qla2x00_restart_isp |
| 4384 | * restarts the ISP after a reset |
| 4385 | * |
| 4386 | * Input: |
| 4387 | * ha = adapter block pointer. |
| 4388 | * |
| 4389 | * Returns: |
| 4390 | * 0 = success |
| 4391 | */ |
| 4392 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4393 | qla2x00_restart_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4394 | { |
Andrew Vasquez | c6b2fca | 2009-03-05 11:07:03 -0800 | [diff] [blame] | 4395 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4396 | uint32_t wait_time; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4397 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4398 | struct req_que *req = ha->req_q_map[0]; |
| 4399 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4400 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4401 | |
| 4402 | /* If firmware needs to be loaded */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4403 | if (qla2x00_isp_firmware(vha)) { |
| 4404 | vha->flags.online = 0; |
| 4405 | status = ha->isp_ops->chip_diag(vha); |
| 4406 | if (!status) |
| 4407 | status = qla2x00_setup_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4408 | } |
| 4409 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4410 | if (!status && !(status = qla2x00_init_rings(vha))) { |
| 4411 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 4412 | ha->flags.chip_reset_done = 1; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4413 | /* Initialize the queues in use */ |
| 4414 | qla25xx_init_queues(ha); |
| 4415 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4416 | status = qla2x00_fw_ready(vha); |
| 4417 | if (!status) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4418 | ql_dbg(ql_dbg_taskm, vha, 0x8031, |
| 4419 | "Start configure loop status = %d.\n", status); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4420 | |
| 4421 | /* Issue a marker after FW becomes ready. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4422 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4423 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4424 | vha->flags.online = 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4425 | |
| 4426 | /* |
| 4427 | * Process any ATIO queue entries that came in |
| 4428 | * while we weren't online. |
| 4429 | */ |
| 4430 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4431 | if (qla_tgt_mode_enabled(vha)) |
| 4432 | qlt_24xx_process_atio_queue(vha); |
| 4433 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4434 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4435 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 4436 | wait_time = 256; |
| 4437 | do { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4438 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 4439 | qla2x00_configure_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4440 | wait_time--; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4441 | } while (!atomic_read(&vha->loop_down_timer) && |
| 4442 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
| 4443 | && wait_time && (test_bit(LOOP_RESYNC_NEEDED, |
| 4444 | &vha->dpc_flags))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4445 | } |
| 4446 | |
| 4447 | /* if no cable then assume it's good */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4448 | if ((vha->device_flags & DFLG_NO_CABLE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4449 | status = 0; |
| 4450 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4451 | ql_dbg(ql_dbg_taskm, vha, 0x8032, |
| 4452 | "Configure loop done, status = 0x%x.\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4453 | } |
| 4454 | return (status); |
| 4455 | } |
| 4456 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4457 | static int |
| 4458 | qla25xx_init_queues(struct qla_hw_data *ha) |
| 4459 | { |
| 4460 | struct rsp_que *rsp = NULL; |
| 4461 | struct req_que *req = NULL; |
| 4462 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
| 4463 | int ret = -1; |
| 4464 | int i; |
| 4465 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 4466 | for (i = 1; i < ha->max_rsp_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4467 | rsp = ha->rsp_q_map[i]; |
| 4468 | if (rsp) { |
| 4469 | rsp->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 4470 | ret = qla25xx_init_rsp_que(base_vha, rsp); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4471 | if (ret != QLA_SUCCESS) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4472 | ql_dbg(ql_dbg_init, base_vha, 0x00ff, |
| 4473 | "%s Rsp que: %d init failed.\n", |
| 4474 | __func__, rsp->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4475 | else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4476 | ql_dbg(ql_dbg_init, base_vha, 0x0100, |
| 4477 | "%s Rsp que: %d inited.\n", |
| 4478 | __func__, rsp->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4479 | } |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 4480 | } |
| 4481 | for (i = 1; i < ha->max_req_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4482 | req = ha->req_q_map[i]; |
| 4483 | if (req) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 4484 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4485 | req->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 4486 | ret = qla25xx_init_req_que(base_vha, req); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4487 | if (ret != QLA_SUCCESS) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4488 | ql_dbg(ql_dbg_init, base_vha, 0x0101, |
| 4489 | "%s Req que: %d init failed.\n", |
| 4490 | __func__, req->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4491 | else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4492 | ql_dbg(ql_dbg_init, base_vha, 0x0102, |
| 4493 | "%s Req que: %d inited.\n", |
| 4494 | __func__, req->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4495 | } |
| 4496 | } |
| 4497 | return ret; |
| 4498 | } |
| 4499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4500 | /* |
| 4501 | * qla2x00_reset_adapter |
| 4502 | * Reset adapter. |
| 4503 | * |
| 4504 | * Input: |
| 4505 | * ha = adapter block pointer. |
| 4506 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4507 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4508 | qla2x00_reset_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4509 | { |
| 4510 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4511 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 4512 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4513 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4514 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 4515 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4516 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4517 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4518 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 4519 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 4520 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 4521 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 4522 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4523 | } |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4524 | |
| 4525 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4526 | qla24xx_reset_adapter(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4527 | { |
| 4528 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4529 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4530 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 4531 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4532 | if (IS_QLA82XX(ha)) |
| 4533 | return; |
| 4534 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4535 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 4536 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4537 | |
| 4538 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4539 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 4540 | RD_REG_DWORD(®->hccr); |
| 4541 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 4542 | RD_REG_DWORD(®->hccr); |
| 4543 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 09ff36d | 2009-01-22 09:45:30 -0800 | [diff] [blame] | 4544 | |
| 4545 | if (IS_NOPOLLING_TYPE(ha)) |
| 4546 | ha->isp_ops->enable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4547 | } |
| 4548 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4549 | /* On sparc systems, obtain port and node WWN from firmware |
| 4550 | * properties. |
| 4551 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4552 | static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, |
| 4553 | struct nvram_24xx *nv) |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4554 | { |
| 4555 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4556 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4557 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 4558 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 4559 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4560 | int len; |
| 4561 | |
| 4562 | val = of_get_property(dp, "port-wwn", &len); |
| 4563 | if (val && len >= WWN_SIZE) |
| 4564 | memcpy(nv->port_name, val, WWN_SIZE); |
| 4565 | |
| 4566 | val = of_get_property(dp, "node-wwn", &len); |
| 4567 | if (val && len >= WWN_SIZE) |
| 4568 | memcpy(nv->node_name, val, WWN_SIZE); |
| 4569 | #endif |
| 4570 | } |
| 4571 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4572 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4573 | qla24xx_nvram_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4574 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4575 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4576 | struct init_cb_24xx *icb; |
| 4577 | struct nvram_24xx *nv; |
| 4578 | uint32_t *dptr; |
| 4579 | uint8_t *dptr1, *dptr2; |
| 4580 | uint32_t chksum; |
| 4581 | uint16_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4582 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4583 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4584 | rval = QLA_SUCCESS; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4585 | icb = (struct init_cb_24xx *)ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 4586 | nv = ha->nvram; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4587 | |
| 4588 | /* Determine NVRAM starting address. */ |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 4589 | if (ha->flags.port0) { |
| 4590 | ha->nvram_base = FA_NVRAM_FUNC0_ADDR; |
| 4591 | ha->vpd_base = FA_NVRAM_VPD0_ADDR; |
| 4592 | } else { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4593 | ha->nvram_base = FA_NVRAM_FUNC1_ADDR; |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 4594 | ha->vpd_base = FA_NVRAM_VPD1_ADDR; |
| 4595 | } |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 4596 | ha->nvram_size = sizeof(struct nvram_24xx); |
| 4597 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4598 | if (IS_QLA82XX(ha)) |
| 4599 | ha->vpd_size = FA_VPD_SIZE_82XX; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4600 | |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 4601 | /* Get VPD data into cache */ |
| 4602 | ha->vpd = ha->nvram + VPD_OFFSET; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4603 | ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 4604 | ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4); |
| 4605 | |
| 4606 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4607 | dptr = (uint32_t *)nv; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4608 | ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4609 | ha->nvram_size); |
| 4610 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++) |
| 4611 | chksum += le32_to_cpu(*dptr++); |
| 4612 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4613 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a, |
| 4614 | "Contents of NVRAM\n"); |
| 4615 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d, |
| 4616 | (uint8_t *)nv, ha->nvram_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4617 | |
| 4618 | /* Bad NVRAM data, set defaults parameters. */ |
| 4619 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 4620 | || nv->id[3] != ' ' || |
| 4621 | nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) { |
| 4622 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4623 | ql_log(ql_log_warn, vha, 0x006b, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 4624 | "Inconsistent NVRAM detected: checksum=0x%x id=%c " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4625 | "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version); |
| 4626 | ql_log(ql_log_warn, vha, 0x006c, |
| 4627 | "Falling back to functioning (yet invalid -- WWPN) " |
| 4628 | "defaults.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4629 | |
| 4630 | /* |
| 4631 | * Set default initialization control block. |
| 4632 | */ |
| 4633 | memset(nv, 0, ha->nvram_size); |
| 4634 | nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION); |
| 4635 | nv->version = __constant_cpu_to_le16(ICB_VERSION); |
| 4636 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 4637 | nv->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 4638 | nv->exchange_count = __constant_cpu_to_le16(0); |
| 4639 | nv->hard_address = __constant_cpu_to_le16(124); |
| 4640 | nv->port_name[0] = 0x21; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 4641 | nv->port_name[1] = 0x00 + ha->port_no; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4642 | nv->port_name[2] = 0x00; |
| 4643 | nv->port_name[3] = 0xe0; |
| 4644 | nv->port_name[4] = 0x8b; |
| 4645 | nv->port_name[5] = 0x1c; |
| 4646 | nv->port_name[6] = 0x55; |
| 4647 | nv->port_name[7] = 0x86; |
| 4648 | nv->node_name[0] = 0x20; |
| 4649 | nv->node_name[1] = 0x00; |
| 4650 | nv->node_name[2] = 0x00; |
| 4651 | nv->node_name[3] = 0xe0; |
| 4652 | nv->node_name[4] = 0x8b; |
| 4653 | nv->node_name[5] = 0x1c; |
| 4654 | nv->node_name[6] = 0x55; |
| 4655 | nv->node_name[7] = 0x86; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4656 | qla24xx_nvram_wwn_from_ofw(vha, nv); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4657 | nv->login_retry_count = __constant_cpu_to_le16(8); |
| 4658 | nv->interrupt_delay_timer = __constant_cpu_to_le16(0); |
| 4659 | nv->login_timeout = __constant_cpu_to_le16(0); |
| 4660 | nv->firmware_options_1 = |
| 4661 | __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 4662 | nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4); |
| 4663 | nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12); |
| 4664 | nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13); |
| 4665 | nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10); |
| 4666 | nv->efi_parameters = __constant_cpu_to_le32(0); |
| 4667 | nv->reset_delay = 5; |
| 4668 | nv->max_luns_per_target = __constant_cpu_to_le16(128); |
| 4669 | nv->port_down_retry_count = __constant_cpu_to_le16(30); |
| 4670 | nv->link_down_timeout = __constant_cpu_to_le16(30); |
| 4671 | |
| 4672 | rval = 1; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4673 | } |
| 4674 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4675 | if (!qla_ini_mode_enabled(vha)) { |
| 4676 | /* Don't enable full login after initial LIP */ |
| 4677 | nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_13); |
| 4678 | /* Don't enable LIP full login for initiator */ |
| 4679 | nv->host_p &= __constant_cpu_to_le32(~BIT_10); |
| 4680 | } |
| 4681 | |
| 4682 | qlt_24xx_config_nvram_stage1(vha, nv); |
| 4683 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4684 | /* Reset Initialization control block */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4685 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4686 | |
| 4687 | /* Copy 1st segment. */ |
| 4688 | dptr1 = (uint8_t *)icb; |
| 4689 | dptr2 = (uint8_t *)&nv->version; |
| 4690 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 4691 | while (cnt--) |
| 4692 | *dptr1++ = *dptr2++; |
| 4693 | |
| 4694 | icb->login_retry_count = nv->login_retry_count; |
Andrew Vasquez | 3ea66e2 | 2006-06-23 16:11:27 -0700 | [diff] [blame] | 4695 | icb->link_down_on_nos = nv->link_down_on_nos; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4696 | |
| 4697 | /* Copy 2nd segment. */ |
| 4698 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 4699 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 4700 | cnt = (uint8_t *)&icb->reserved_3 - |
| 4701 | (uint8_t *)&icb->interrupt_delay_timer; |
| 4702 | while (cnt--) |
| 4703 | *dptr1++ = *dptr2++; |
| 4704 | |
| 4705 | /* |
| 4706 | * Setup driver NVRAM options. |
| 4707 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4708 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 4709 | "QLA2462"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4710 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4711 | qlt_24xx_config_nvram_stage2(vha, icb); |
| 4712 | |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 4713 | if (nv->host_p & __constant_cpu_to_le32(BIT_15)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4714 | /* Use alternate WWN? */ |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 4715 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 4716 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 4717 | } |
| 4718 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4719 | /* Prepare nodename */ |
Andrew Vasquez | fd0e7e4 | 2006-05-17 15:09:11 -0700 | [diff] [blame] | 4720 | if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4721 | /* |
| 4722 | * Firmware will apply the following mask if the nodename was |
| 4723 | * not provided. |
| 4724 | */ |
| 4725 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 4726 | icb->node_name[0] &= 0xF0; |
| 4727 | } |
| 4728 | |
| 4729 | /* Set host adapter parameters. */ |
| 4730 | ha->flags.disable_risc_code_load = 0; |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 4731 | ha->flags.enable_lip_reset = 0; |
| 4732 | ha->flags.enable_lip_full_login = |
| 4733 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 4734 | ha->flags.enable_target_reset = |
| 4735 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4736 | ha->flags.enable_led_scheme = 0; |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 4737 | 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] | 4738 | |
Andrew Vasquez | fd0e7e4 | 2006-05-17 15:09:11 -0700 | [diff] [blame] | 4739 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 4740 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4741 | |
| 4742 | memcpy(ha->fw_seriallink_options24, nv->seriallink_options, |
| 4743 | sizeof(ha->fw_seriallink_options24)); |
| 4744 | |
| 4745 | /* save HBA serial number */ |
| 4746 | ha->serial0 = icb->port_name[5]; |
| 4747 | ha->serial1 = icb->port_name[6]; |
| 4748 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4749 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 4750 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4751 | |
andrew.vasquez@qlogic.com | bc8fb3c | 2006-01-13 17:05:42 -0800 | [diff] [blame] | 4752 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 4753 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4754 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 4755 | |
| 4756 | /* Set minimum login_timeout to 4 seconds. */ |
| 4757 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 4758 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 4759 | if (le16_to_cpu(nv->login_timeout) < 4) |
| 4760 | nv->login_timeout = __constant_cpu_to_le16(4); |
| 4761 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
Seokmann Ju | c6852c4 | 2008-04-24 15:21:29 -0700 | [diff] [blame] | 4762 | icb->login_timeout = nv->login_timeout; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4763 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 4764 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 4765 | ha->r_a_tov = 100; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4766 | |
| 4767 | ha->loop_reset_delay = nv->reset_delay; |
| 4768 | |
| 4769 | /* Link Down Timeout = 0: |
| 4770 | * |
| 4771 | * When Port Down timer expires we will start returning |
| 4772 | * I/O's to OS with "DID_NO_CONNECT". |
| 4773 | * |
| 4774 | * Link Down Timeout != 0: |
| 4775 | * |
| 4776 | * The driver waits for the link to come up after link down |
| 4777 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 4778 | */ |
| 4779 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 4780 | ha->loop_down_abort_time = |
| 4781 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 4782 | } else { |
| 4783 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 4784 | ha->loop_down_abort_time = |
| 4785 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 4786 | } |
| 4787 | |
| 4788 | /* Need enough time to try and get the port back. */ |
| 4789 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 4790 | if (qlport_down_retry) |
| 4791 | ha->port_down_retry_count = qlport_down_retry; |
| 4792 | |
| 4793 | /* Set login_retry_count */ |
| 4794 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 4795 | if (ha->port_down_retry_count == |
| 4796 | le16_to_cpu(nv->port_down_retry_count) && |
| 4797 | ha->port_down_retry_count > 3) |
| 4798 | ha->login_retry_count = ha->port_down_retry_count; |
| 4799 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 4800 | ha->login_retry_count = ha->port_down_retry_count; |
| 4801 | if (ql2xloginretrycount) |
| 4802 | ha->login_retry_count = ql2xloginretrycount; |
| 4803 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4804 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4805 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4806 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 4807 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 4808 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 4809 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 4810 | } |
| 4811 | icb->firmware_options_2 &= __constant_cpu_to_le32( |
| 4812 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4813 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4814 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 4815 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 4816 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4817 | ql_log(ql_log_info, vha, 0x006f, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4818 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 4819 | ha->zio_mode, ha->zio_timer * 100); |
| 4820 | |
| 4821 | icb->firmware_options_2 |= cpu_to_le32( |
| 4822 | (uint32_t)ha->zio_mode); |
| 4823 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4824 | vha->flags.process_response_queue = 1; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4825 | } |
| 4826 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4827 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4828 | ql_log(ql_log_warn, vha, 0x0070, |
| 4829 | "NVRAM configuration failed.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4830 | } |
| 4831 | return (rval); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4832 | } |
| 4833 | |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 4834 | static int |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4835 | qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr, |
| 4836 | uint32_t faddr) |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4837 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4838 | int rval = QLA_SUCCESS; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4839 | int segments, fragment; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4840 | uint32_t *dcode, dlen; |
| 4841 | uint32_t risc_addr; |
| 4842 | uint32_t risc_size; |
| 4843 | uint32_t i; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4844 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4845 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4846 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4847 | ql_dbg(ql_dbg_init, vha, 0x008b, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 4848 | "FW: Loading firmware from flash (%x).\n", faddr); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4849 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4850 | rval = QLA_SUCCESS; |
| 4851 | |
| 4852 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4853 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4854 | *srisc_addr = 0; |
| 4855 | |
| 4856 | /* Validate firmware image by checking version. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4857 | qla24xx_read_flash_data(vha, dcode, faddr + 4, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4858 | for (i = 0; i < 4; i++) |
| 4859 | dcode[i] = be32_to_cpu(dcode[i]); |
| 4860 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 4861 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 4862 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 4863 | dcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4864 | ql_log(ql_log_fatal, vha, 0x008c, |
| 4865 | "Unable to verify the integrity of flash firmware " |
| 4866 | "image.\n"); |
| 4867 | ql_log(ql_log_fatal, vha, 0x008d, |
| 4868 | "Firmware data: %08x %08x %08x %08x.\n", |
| 4869 | dcode[0], dcode[1], dcode[2], dcode[3]); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4870 | |
| 4871 | return QLA_FUNCTION_FAILED; |
| 4872 | } |
| 4873 | |
| 4874 | while (segments && rval == QLA_SUCCESS) { |
| 4875 | /* Read segment's load information. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4876 | qla24xx_read_flash_data(vha, dcode, faddr, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4877 | |
| 4878 | risc_addr = be32_to_cpu(dcode[2]); |
| 4879 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 4880 | risc_size = be32_to_cpu(dcode[3]); |
| 4881 | |
| 4882 | fragment = 0; |
| 4883 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 4884 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 4885 | if (dlen > risc_size) |
| 4886 | dlen = risc_size; |
| 4887 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4888 | ql_dbg(ql_dbg_init, vha, 0x008e, |
| 4889 | "Loading risc segment@ risc addr %x " |
| 4890 | "number of dwords 0x%x offset 0x%x.\n", |
| 4891 | risc_addr, dlen, faddr); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4892 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4893 | qla24xx_read_flash_data(vha, dcode, faddr, dlen); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4894 | for (i = 0; i < dlen; i++) |
| 4895 | dcode[i] = swab32(dcode[i]); |
| 4896 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4897 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4898 | dlen); |
| 4899 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4900 | ql_log(ql_log_fatal, vha, 0x008f, |
| 4901 | "Failed to load segment %d of firmware.\n", |
| 4902 | fragment); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4903 | break; |
| 4904 | } |
| 4905 | |
| 4906 | faddr += dlen; |
| 4907 | risc_addr += dlen; |
| 4908 | risc_size -= dlen; |
| 4909 | fragment++; |
| 4910 | } |
| 4911 | |
| 4912 | /* Next segment. */ |
| 4913 | segments--; |
| 4914 | } |
| 4915 | |
| 4916 | return rval; |
| 4917 | } |
| 4918 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4919 | #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/" |
| 4920 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4921 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4922 | qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4923 | { |
| 4924 | int rval; |
| 4925 | int i, fragment; |
| 4926 | uint16_t *wcode, *fwcode; |
| 4927 | uint32_t risc_addr, risc_size, fwclen, wlen, *seg; |
| 4928 | struct fw_blob *blob; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4929 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4930 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4931 | |
| 4932 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4933 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4934 | if (!blob) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4935 | ql_log(ql_log_info, vha, 0x0083, |
| 4936 | "Fimware image unavailable.\n"); |
| 4937 | ql_log(ql_log_info, vha, 0x0084, |
| 4938 | "Firmware images can be retrieved from: "QLA_FW_URL ".\n"); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4939 | return QLA_FUNCTION_FAILED; |
| 4940 | } |
| 4941 | |
| 4942 | rval = QLA_SUCCESS; |
| 4943 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4944 | wcode = (uint16_t *)req->ring; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4945 | *srisc_addr = 0; |
| 4946 | fwcode = (uint16_t *)blob->fw->data; |
| 4947 | fwclen = 0; |
| 4948 | |
| 4949 | /* Validate firmware image by checking version. */ |
| 4950 | if (blob->fw->size < 8 * sizeof(uint16_t)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4951 | ql_log(ql_log_fatal, vha, 0x0085, |
| 4952 | "Unable to verify integrity of firmware image (%Zd).\n", |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4953 | blob->fw->size); |
| 4954 | goto fail_fw_integrity; |
| 4955 | } |
| 4956 | for (i = 0; i < 4; i++) |
| 4957 | wcode[i] = be16_to_cpu(fwcode[i + 4]); |
| 4958 | if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff && |
| 4959 | wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 && |
| 4960 | wcode[2] == 0 && wcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4961 | ql_log(ql_log_fatal, vha, 0x0086, |
| 4962 | "Unable to verify integrity of firmware image.\n"); |
| 4963 | ql_log(ql_log_fatal, vha, 0x0087, |
| 4964 | "Firmware data: %04x %04x %04x %04x.\n", |
| 4965 | wcode[0], wcode[1], wcode[2], wcode[3]); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4966 | goto fail_fw_integrity; |
| 4967 | } |
| 4968 | |
| 4969 | seg = blob->segs; |
| 4970 | while (*seg && rval == QLA_SUCCESS) { |
| 4971 | risc_addr = *seg; |
| 4972 | *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr; |
| 4973 | risc_size = be16_to_cpu(fwcode[3]); |
| 4974 | |
| 4975 | /* Validate firmware image size. */ |
| 4976 | fwclen += risc_size * sizeof(uint16_t); |
| 4977 | if (blob->fw->size < fwclen) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4978 | ql_log(ql_log_fatal, vha, 0x0088, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4979 | "Unable to verify integrity of firmware image " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4980 | "(%Zd).\n", blob->fw->size); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4981 | goto fail_fw_integrity; |
| 4982 | } |
| 4983 | |
| 4984 | fragment = 0; |
| 4985 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 4986 | wlen = (uint16_t)(ha->fw_transfer_size >> 1); |
| 4987 | if (wlen > risc_size) |
| 4988 | wlen = risc_size; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4989 | ql_dbg(ql_dbg_init, vha, 0x0089, |
| 4990 | "Loading risc segment@ risc addr %x number of " |
| 4991 | "words 0x%x.\n", risc_addr, wlen); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4992 | |
| 4993 | for (i = 0; i < wlen; i++) |
| 4994 | wcode[i] = swab16(fwcode[i]); |
| 4995 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4996 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4997 | wlen); |
| 4998 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4999 | ql_log(ql_log_fatal, vha, 0x008a, |
| 5000 | "Failed to load segment %d of firmware.\n", |
| 5001 | fragment); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5002 | break; |
| 5003 | } |
| 5004 | |
| 5005 | fwcode += wlen; |
| 5006 | risc_addr += wlen; |
| 5007 | risc_size -= wlen; |
| 5008 | fragment++; |
| 5009 | } |
| 5010 | |
| 5011 | /* Next segment. */ |
| 5012 | seg++; |
| 5013 | } |
| 5014 | return rval; |
| 5015 | |
| 5016 | fail_fw_integrity: |
| 5017 | return QLA_FUNCTION_FAILED; |
| 5018 | } |
| 5019 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5020 | static int |
| 5021 | 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] | 5022 | { |
| 5023 | int rval; |
| 5024 | int segments, fragment; |
| 5025 | uint32_t *dcode, dlen; |
| 5026 | uint32_t risc_addr; |
| 5027 | uint32_t risc_size; |
| 5028 | uint32_t i; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5029 | struct fw_blob *blob; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5030 | uint32_t *fwcode, fwclen; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5031 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5032 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5033 | |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5034 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5035 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5036 | if (!blob) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5037 | ql_log(ql_log_warn, vha, 0x0090, |
| 5038 | "Fimware image unavailable.\n"); |
| 5039 | ql_log(ql_log_warn, vha, 0x0091, |
| 5040 | "Firmware images can be retrieved from: " |
| 5041 | QLA_FW_URL ".\n"); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5042 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5043 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5044 | } |
| 5045 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5046 | ql_dbg(ql_dbg_init, vha, 0x0092, |
| 5047 | "FW: Loading via request-firmware.\n"); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5048 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5049 | rval = QLA_SUCCESS; |
| 5050 | |
| 5051 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5052 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5053 | *srisc_addr = 0; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5054 | fwcode = (uint32_t *)blob->fw->data; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5055 | fwclen = 0; |
| 5056 | |
| 5057 | /* Validate firmware image by checking version. */ |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5058 | if (blob->fw->size < 8 * sizeof(uint32_t)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5059 | ql_log(ql_log_fatal, vha, 0x0093, |
| 5060 | "Unable to verify integrity of firmware image (%Zd).\n", |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5061 | blob->fw->size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5062 | goto fail_fw_integrity; |
| 5063 | } |
| 5064 | for (i = 0; i < 4; i++) |
| 5065 | dcode[i] = be32_to_cpu(fwcode[i + 4]); |
| 5066 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 5067 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 5068 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 5069 | dcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5070 | ql_log(ql_log_fatal, vha, 0x0094, |
| 5071 | "Unable to verify integrity of firmware image (%Zd).\n", |
| 5072 | blob->fw->size); |
| 5073 | ql_log(ql_log_fatal, vha, 0x0095, |
| 5074 | "Firmware data: %08x %08x %08x %08x.\n", |
| 5075 | dcode[0], dcode[1], dcode[2], dcode[3]); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5076 | goto fail_fw_integrity; |
| 5077 | } |
| 5078 | |
| 5079 | while (segments && rval == QLA_SUCCESS) { |
| 5080 | risc_addr = be32_to_cpu(fwcode[2]); |
| 5081 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 5082 | risc_size = be32_to_cpu(fwcode[3]); |
| 5083 | |
| 5084 | /* Validate firmware image size. */ |
| 5085 | fwclen += risc_size * sizeof(uint32_t); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5086 | if (blob->fw->size < fwclen) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5087 | ql_log(ql_log_fatal, vha, 0x0096, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5088 | "Unable to verify integrity of firmware image " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5089 | "(%Zd).\n", blob->fw->size); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5090 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5091 | goto fail_fw_integrity; |
| 5092 | } |
| 5093 | |
| 5094 | fragment = 0; |
| 5095 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 5096 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 5097 | if (dlen > risc_size) |
| 5098 | dlen = risc_size; |
| 5099 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5100 | ql_dbg(ql_dbg_init, vha, 0x0097, |
| 5101 | "Loading risc segment@ risc addr %x " |
| 5102 | "number of dwords 0x%x.\n", risc_addr, dlen); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5103 | |
| 5104 | for (i = 0; i < dlen; i++) |
| 5105 | dcode[i] = swab32(fwcode[i]); |
| 5106 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5107 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
andrew.vasquez@qlogic.com | 590f98e | 2006-01-13 17:05:37 -0800 | [diff] [blame] | 5108 | dlen); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5109 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5110 | ql_log(ql_log_fatal, vha, 0x0098, |
| 5111 | "Failed to load segment %d of firmware.\n", |
| 5112 | fragment); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5113 | break; |
| 5114 | } |
| 5115 | |
| 5116 | fwcode += dlen; |
| 5117 | risc_addr += dlen; |
| 5118 | risc_size -= dlen; |
| 5119 | fragment++; |
| 5120 | } |
| 5121 | |
| 5122 | /* Next segment. */ |
| 5123 | segments--; |
| 5124 | } |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5125 | return rval; |
| 5126 | |
| 5127 | fail_fw_integrity: |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5128 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5129 | } |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5130 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5131 | int |
| 5132 | qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 5133 | { |
| 5134 | int rval; |
| 5135 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 5136 | if (ql2xfwloadbin == 1) |
| 5137 | return qla81xx_load_risc(vha, srisc_addr); |
| 5138 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5139 | /* |
| 5140 | * FW Load priority: |
| 5141 | * 1) Firmware via request-firmware interface (.bin file). |
| 5142 | * 2) Firmware residing in flash. |
| 5143 | */ |
| 5144 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 5145 | if (rval == QLA_SUCCESS) |
| 5146 | return rval; |
| 5147 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5148 | return qla24xx_load_risc_flash(vha, srisc_addr, |
| 5149 | vha->hw->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5150 | } |
| 5151 | |
| 5152 | int |
| 5153 | qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 5154 | { |
| 5155 | int rval; |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5156 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5157 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 5158 | if (ql2xfwloadbin == 2) |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5159 | goto try_blob_fw; |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 5160 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5161 | /* |
| 5162 | * FW Load priority: |
| 5163 | * 1) Firmware residing in flash. |
| 5164 | * 2) Firmware via request-firmware interface (.bin file). |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5165 | * 3) Golden-Firmware residing in flash -- limited operation. |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5166 | */ |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5167 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5168 | if (rval == QLA_SUCCESS) |
| 5169 | return rval; |
| 5170 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5171 | try_blob_fw: |
| 5172 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 5173 | if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw) |
| 5174 | return rval; |
| 5175 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5176 | ql_log(ql_log_info, vha, 0x0099, |
| 5177 | "Attempting to fallback to golden firmware.\n"); |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5178 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw); |
| 5179 | if (rval != QLA_SUCCESS) |
| 5180 | return rval; |
| 5181 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5182 | ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n"); |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5183 | ha->flags.running_gold_fw = 1; |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5184 | return rval; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5185 | } |
| 5186 | |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5187 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5188 | qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5189 | { |
| 5190 | int ret, retries; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5191 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5192 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 5193 | if (ha->flags.pci_channel_io_perm_failure) |
| 5194 | return; |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 5195 | if (!IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5196 | return; |
Andrew Vasquez | 75edf81 | 2007-05-07 07:43:00 -0700 | [diff] [blame] | 5197 | if (!ha->fw_major_version) |
| 5198 | return; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5199 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5200 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 7c7f1f2 | 2008-02-28 14:06:09 -0800 | [diff] [blame] | 5201 | for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT && |
Andrew Vasquez | b469a7c | 2009-04-06 22:33:48 -0700 | [diff] [blame] | 5202 | ret != QLA_INVALID_COMMAND && retries ; retries--) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5203 | ha->isp_ops->reset_chip(vha); |
| 5204 | if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5205 | continue; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5206 | if (qla2x00_setup_chip(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5207 | continue; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5208 | ql_log(ql_log_info, vha, 0x8015, |
| 5209 | "Attempting retry of stop-firmware command.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5210 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5211 | } |
| 5212 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5213 | |
| 5214 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5215 | qla24xx_configure_vhba(scsi_qla_host_t *vha) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5216 | { |
| 5217 | int rval = QLA_SUCCESS; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 5218 | int rval2; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5219 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5220 | struct qla_hw_data *ha = vha->hw; |
| 5221 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 5222 | struct req_que *req; |
| 5223 | struct rsp_que *rsp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5224 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5225 | if (!vha->vp_idx) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5226 | return -EINVAL; |
| 5227 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5228 | rval = qla2x00_fw_ready(base_vha); |
Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 5229 | if (ha->flags.cpu_affinity_enabled) |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 5230 | req = ha->req_q_map[0]; |
| 5231 | else |
| 5232 | req = vha->req; |
| 5233 | rsp = req->rsp; |
| 5234 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5235 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5236 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5237 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5238 | } |
| 5239 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5240 | vha->flags.management_server_logged_in = 0; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5241 | |
| 5242 | /* Login to SNS first */ |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 5243 | rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, |
| 5244 | BIT_1); |
| 5245 | if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) { |
| 5246 | if (rval2 == QLA_MEMORY_ALLOC_FAILED) |
| 5247 | ql_dbg(ql_dbg_init, vha, 0x0120, |
| 5248 | "Failed SNS login: loop_id=%x, rval2=%d\n", |
| 5249 | NPH_SNS, rval2); |
| 5250 | else |
| 5251 | ql_dbg(ql_dbg_init, vha, 0x0103, |
| 5252 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x " |
| 5253 | "mb[2]=%x mb[6]=%x mb[7]=%x.\n", |
| 5254 | NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5255 | return (QLA_FUNCTION_FAILED); |
| 5256 | } |
| 5257 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5258 | atomic_set(&vha->loop_down_timer, 0); |
| 5259 | atomic_set(&vha->loop_state, LOOP_UP); |
| 5260 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 5261 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 5262 | rval = qla2x00_loop_resync(base_vha); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5263 | |
| 5264 | return rval; |
| 5265 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5266 | |
| 5267 | /* 84XX Support **************************************************************/ |
| 5268 | |
| 5269 | static LIST_HEAD(qla_cs84xx_list); |
| 5270 | static DEFINE_MUTEX(qla_cs84xx_mutex); |
| 5271 | |
| 5272 | static struct qla_chip_state_84xx * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5273 | qla84xx_get_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5274 | { |
| 5275 | struct qla_chip_state_84xx *cs84xx; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5276 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5277 | |
| 5278 | mutex_lock(&qla_cs84xx_mutex); |
| 5279 | |
| 5280 | /* Find any shared 84xx chip. */ |
| 5281 | list_for_each_entry(cs84xx, &qla_cs84xx_list, list) { |
| 5282 | if (cs84xx->bus == ha->pdev->bus) { |
| 5283 | kref_get(&cs84xx->kref); |
| 5284 | goto done; |
| 5285 | } |
| 5286 | } |
| 5287 | |
| 5288 | cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL); |
| 5289 | if (!cs84xx) |
| 5290 | goto done; |
| 5291 | |
| 5292 | kref_init(&cs84xx->kref); |
| 5293 | spin_lock_init(&cs84xx->access_lock); |
| 5294 | mutex_init(&cs84xx->fw_update_mutex); |
| 5295 | cs84xx->bus = ha->pdev->bus; |
| 5296 | |
| 5297 | list_add_tail(&cs84xx->list, &qla_cs84xx_list); |
| 5298 | done: |
| 5299 | mutex_unlock(&qla_cs84xx_mutex); |
| 5300 | return cs84xx; |
| 5301 | } |
| 5302 | |
| 5303 | static void |
| 5304 | __qla84xx_chip_release(struct kref *kref) |
| 5305 | { |
| 5306 | struct qla_chip_state_84xx *cs84xx = |
| 5307 | container_of(kref, struct qla_chip_state_84xx, kref); |
| 5308 | |
| 5309 | mutex_lock(&qla_cs84xx_mutex); |
| 5310 | list_del(&cs84xx->list); |
| 5311 | mutex_unlock(&qla_cs84xx_mutex); |
| 5312 | kfree(cs84xx); |
| 5313 | } |
| 5314 | |
| 5315 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5316 | qla84xx_put_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5317 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5318 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5319 | if (ha->cs84xx) |
| 5320 | kref_put(&ha->cs84xx->kref, __qla84xx_chip_release); |
| 5321 | } |
| 5322 | |
| 5323 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5324 | qla84xx_init_chip(scsi_qla_host_t *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5325 | { |
| 5326 | int rval; |
| 5327 | uint16_t status[2]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5328 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5329 | |
| 5330 | mutex_lock(&ha->cs84xx->fw_update_mutex); |
| 5331 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5332 | rval = qla84xx_verify_chip(vha, status); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5333 | |
| 5334 | mutex_unlock(&ha->cs84xx->fw_update_mutex); |
| 5335 | |
| 5336 | return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED: |
| 5337 | QLA_SUCCESS; |
| 5338 | } |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5339 | |
| 5340 | /* 81XX Support **************************************************************/ |
| 5341 | |
| 5342 | int |
| 5343 | qla81xx_nvram_config(scsi_qla_host_t *vha) |
| 5344 | { |
| 5345 | int rval; |
| 5346 | struct init_cb_81xx *icb; |
| 5347 | struct nvram_81xx *nv; |
| 5348 | uint32_t *dptr; |
| 5349 | uint8_t *dptr1, *dptr2; |
| 5350 | uint32_t chksum; |
| 5351 | uint16_t cnt; |
| 5352 | struct qla_hw_data *ha = vha->hw; |
| 5353 | |
| 5354 | rval = QLA_SUCCESS; |
| 5355 | icb = (struct init_cb_81xx *)ha->init_cb; |
| 5356 | nv = ha->nvram; |
| 5357 | |
| 5358 | /* Determine NVRAM starting address. */ |
| 5359 | ha->nvram_size = sizeof(struct nvram_81xx); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5360 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5361 | |
| 5362 | /* Get VPD data into cache */ |
| 5363 | ha->vpd = ha->nvram + VPD_OFFSET; |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 5364 | ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2, |
| 5365 | ha->vpd_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5366 | |
| 5367 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 5368 | 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] | 5369 | ha->nvram_size); |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 5370 | dptr = (uint32_t *)nv; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5371 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++) |
| 5372 | chksum += le32_to_cpu(*dptr++); |
| 5373 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5374 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111, |
| 5375 | "Contents of NVRAM:\n"); |
| 5376 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112, |
| 5377 | (uint8_t *)nv, ha->nvram_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5378 | |
| 5379 | /* Bad NVRAM data, set defaults parameters. */ |
| 5380 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 5381 | || nv->id[3] != ' ' || |
| 5382 | nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) { |
| 5383 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5384 | ql_log(ql_log_info, vha, 0x0073, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 5385 | "Inconsistent NVRAM detected: checksum=0x%x id=%c " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5386 | "version=0x%x.\n", chksum, nv->id[0], |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5387 | le16_to_cpu(nv->nvram_version)); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5388 | ql_log(ql_log_info, vha, 0x0074, |
| 5389 | "Falling back to functioning (yet invalid -- WWPN) " |
| 5390 | "defaults.\n"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5391 | |
| 5392 | /* |
| 5393 | * Set default initialization control block. |
| 5394 | */ |
| 5395 | memset(nv, 0, ha->nvram_size); |
| 5396 | nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION); |
| 5397 | nv->version = __constant_cpu_to_le16(ICB_VERSION); |
| 5398 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 5399 | nv->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 5400 | nv->exchange_count = __constant_cpu_to_le16(0); |
| 5401 | nv->port_name[0] = 0x21; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5402 | nv->port_name[1] = 0x00 + ha->port_no; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5403 | nv->port_name[2] = 0x00; |
| 5404 | nv->port_name[3] = 0xe0; |
| 5405 | nv->port_name[4] = 0x8b; |
| 5406 | nv->port_name[5] = 0x1c; |
| 5407 | nv->port_name[6] = 0x55; |
| 5408 | nv->port_name[7] = 0x86; |
| 5409 | nv->node_name[0] = 0x20; |
| 5410 | nv->node_name[1] = 0x00; |
| 5411 | nv->node_name[2] = 0x00; |
| 5412 | nv->node_name[3] = 0xe0; |
| 5413 | nv->node_name[4] = 0x8b; |
| 5414 | nv->node_name[5] = 0x1c; |
| 5415 | nv->node_name[6] = 0x55; |
| 5416 | nv->node_name[7] = 0x86; |
| 5417 | nv->login_retry_count = __constant_cpu_to_le16(8); |
| 5418 | nv->interrupt_delay_timer = __constant_cpu_to_le16(0); |
| 5419 | nv->login_timeout = __constant_cpu_to_le16(0); |
| 5420 | nv->firmware_options_1 = |
| 5421 | __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 5422 | nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4); |
| 5423 | nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12); |
| 5424 | nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13); |
| 5425 | nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10); |
| 5426 | nv->efi_parameters = __constant_cpu_to_le32(0); |
| 5427 | nv->reset_delay = 5; |
| 5428 | nv->max_luns_per_target = __constant_cpu_to_le16(128); |
| 5429 | nv->port_down_retry_count = __constant_cpu_to_le16(30); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 5430 | nv->link_down_timeout = __constant_cpu_to_le16(180); |
Andrew Vasquez | eeebcc9 | 2009-06-03 09:55:24 -0700 | [diff] [blame] | 5431 | nv->enode_mac[0] = 0x00; |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 5432 | nv->enode_mac[1] = 0xC0; |
| 5433 | nv->enode_mac[2] = 0xDD; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5434 | nv->enode_mac[3] = 0x04; |
| 5435 | nv->enode_mac[4] = 0x05; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5436 | nv->enode_mac[5] = 0x06 + ha->port_no; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5437 | |
| 5438 | rval = 1; |
| 5439 | } |
| 5440 | |
| 5441 | /* Reset Initialization control block */ |
Andrew Vasquez | 773120e | 2011-05-10 11:30:14 -0700 | [diff] [blame] | 5442 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5443 | |
| 5444 | /* Copy 1st segment. */ |
| 5445 | dptr1 = (uint8_t *)icb; |
| 5446 | dptr2 = (uint8_t *)&nv->version; |
| 5447 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 5448 | while (cnt--) |
| 5449 | *dptr1++ = *dptr2++; |
| 5450 | |
| 5451 | icb->login_retry_count = nv->login_retry_count; |
| 5452 | |
| 5453 | /* Copy 2nd segment. */ |
| 5454 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 5455 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 5456 | cnt = (uint8_t *)&icb->reserved_5 - |
| 5457 | (uint8_t *)&icb->interrupt_delay_timer; |
| 5458 | while (cnt--) |
| 5459 | *dptr1++ = *dptr2++; |
| 5460 | |
| 5461 | memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac)); |
| 5462 | /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */ |
| 5463 | 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] | 5464 | icb->enode_mac[0] = 0x00; |
| 5465 | icb->enode_mac[1] = 0xC0; |
| 5466 | icb->enode_mac[2] = 0xDD; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5467 | icb->enode_mac[3] = 0x04; |
| 5468 | icb->enode_mac[4] = 0x05; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5469 | icb->enode_mac[5] = 0x06 + ha->port_no; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5470 | } |
| 5471 | |
Andrew Vasquez | b64b0e8 | 2009-03-24 09:08:01 -0700 | [diff] [blame] | 5472 | /* Use extended-initialization control block. */ |
| 5473 | memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb)); |
| 5474 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5475 | /* |
| 5476 | * Setup driver NVRAM options. |
| 5477 | */ |
| 5478 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5479 | "QLE8XXX"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5480 | |
| 5481 | /* Use alternate WWN? */ |
| 5482 | if (nv->host_p & __constant_cpu_to_le32(BIT_15)) { |
| 5483 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 5484 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 5485 | } |
| 5486 | |
| 5487 | /* Prepare nodename */ |
| 5488 | if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) { |
| 5489 | /* |
| 5490 | * Firmware will apply the following mask if the nodename was |
| 5491 | * not provided. |
| 5492 | */ |
| 5493 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 5494 | icb->node_name[0] &= 0xF0; |
| 5495 | } |
| 5496 | |
| 5497 | /* Set host adapter parameters. */ |
| 5498 | ha->flags.disable_risc_code_load = 0; |
| 5499 | ha->flags.enable_lip_reset = 0; |
| 5500 | ha->flags.enable_lip_full_login = |
| 5501 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 5502 | ha->flags.enable_target_reset = |
| 5503 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
| 5504 | ha->flags.enable_led_scheme = 0; |
| 5505 | ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0; |
| 5506 | |
| 5507 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 5508 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 5509 | |
| 5510 | /* save HBA serial number */ |
| 5511 | ha->serial0 = icb->port_name[5]; |
| 5512 | ha->serial1 = icb->port_name[6]; |
| 5513 | ha->serial2 = icb->port_name[7]; |
| 5514 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 5515 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
| 5516 | |
| 5517 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 5518 | |
| 5519 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 5520 | |
| 5521 | /* Set minimum login_timeout to 4 seconds. */ |
| 5522 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 5523 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 5524 | if (le16_to_cpu(nv->login_timeout) < 4) |
| 5525 | nv->login_timeout = __constant_cpu_to_le16(4); |
| 5526 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
| 5527 | icb->login_timeout = nv->login_timeout; |
| 5528 | |
| 5529 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 5530 | ha->r_a_tov = 100; |
| 5531 | |
| 5532 | ha->loop_reset_delay = nv->reset_delay; |
| 5533 | |
| 5534 | /* Link Down Timeout = 0: |
| 5535 | * |
| 5536 | * When Port Down timer expires we will start returning |
| 5537 | * I/O's to OS with "DID_NO_CONNECT". |
| 5538 | * |
| 5539 | * Link Down Timeout != 0: |
| 5540 | * |
| 5541 | * The driver waits for the link to come up after link down |
| 5542 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 5543 | */ |
| 5544 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 5545 | ha->loop_down_abort_time = |
| 5546 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 5547 | } else { |
| 5548 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 5549 | ha->loop_down_abort_time = |
| 5550 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 5551 | } |
| 5552 | |
| 5553 | /* Need enough time to try and get the port back. */ |
| 5554 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 5555 | if (qlport_down_retry) |
| 5556 | ha->port_down_retry_count = qlport_down_retry; |
| 5557 | |
| 5558 | /* Set login_retry_count */ |
| 5559 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 5560 | if (ha->port_down_retry_count == |
| 5561 | le16_to_cpu(nv->port_down_retry_count) && |
| 5562 | ha->port_down_retry_count > 3) |
| 5563 | ha->login_retry_count = ha->port_down_retry_count; |
| 5564 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 5565 | ha->login_retry_count = ha->port_down_retry_count; |
| 5566 | if (ql2xloginretrycount) |
| 5567 | ha->login_retry_count = ql2xloginretrycount; |
| 5568 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 5569 | /* if not running MSI-X we need handshaking on interrupts */ |
| 5570 | if (!vha->hw->flags.msix_enabled && IS_QLA83XX(ha)) |
| 5571 | icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22); |
| 5572 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5573 | /* Enable ZIO. */ |
| 5574 | if (!vha->flags.init_done) { |
| 5575 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 5576 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 5577 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 5578 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 5579 | } |
| 5580 | icb->firmware_options_2 &= __constant_cpu_to_le32( |
| 5581 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
| 5582 | vha->flags.process_response_queue = 0; |
| 5583 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
| 5584 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 5585 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5586 | ql_log(ql_log_info, vha, 0x0075, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5587 | "ZIO mode %d enabled; timer delay (%d us).\n", |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5588 | ha->zio_mode, |
| 5589 | ha->zio_timer * 100); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5590 | |
| 5591 | icb->firmware_options_2 |= cpu_to_le32( |
| 5592 | (uint32_t)ha->zio_mode); |
| 5593 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
| 5594 | vha->flags.process_response_queue = 1; |
| 5595 | } |
| 5596 | |
| 5597 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5598 | ql_log(ql_log_warn, vha, 0x0076, |
| 5599 | "NVRAM configuration failed.\n"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5600 | } |
| 5601 | return (rval); |
| 5602 | } |
| 5603 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5604 | int |
| 5605 | qla82xx_restart_isp(scsi_qla_host_t *vha) |
| 5606 | { |
| 5607 | int status, rval; |
| 5608 | uint32_t wait_time; |
| 5609 | struct qla_hw_data *ha = vha->hw; |
| 5610 | struct req_que *req = ha->req_q_map[0]; |
| 5611 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
| 5612 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5613 | unsigned long flags; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5614 | |
| 5615 | status = qla2x00_init_rings(vha); |
| 5616 | if (!status) { |
| 5617 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 5618 | ha->flags.chip_reset_done = 1; |
| 5619 | |
| 5620 | status = qla2x00_fw_ready(vha); |
| 5621 | if (!status) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5622 | ql_log(ql_log_info, vha, 0x803c, |
| 5623 | "Start configure loop, status =%d.\n", status); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5624 | |
| 5625 | /* Issue a marker after FW becomes ready. */ |
| 5626 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
| 5627 | |
| 5628 | vha->flags.online = 1; |
| 5629 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 5630 | wait_time = 256; |
| 5631 | do { |
| 5632 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 5633 | qla2x00_configure_loop(vha); |
| 5634 | wait_time--; |
| 5635 | } while (!atomic_read(&vha->loop_down_timer) && |
| 5636 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) && |
| 5637 | wait_time && |
| 5638 | (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))); |
| 5639 | } |
| 5640 | |
| 5641 | /* if no cable then assume it's good */ |
| 5642 | if ((vha->device_flags & DFLG_NO_CABLE)) |
| 5643 | status = 0; |
| 5644 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5645 | ql_log(ql_log_info, vha, 0x8000, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5646 | "Configure loop done, status = 0x%x.\n", status); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5647 | } |
| 5648 | |
| 5649 | if (!status) { |
| 5650 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 5651 | |
| 5652 | if (!atomic_read(&vha->loop_down_timer)) { |
| 5653 | /* |
| 5654 | * Issue marker command only when we are going |
| 5655 | * to start the I/O . |
| 5656 | */ |
| 5657 | vha->marker_needed = 1; |
| 5658 | } |
| 5659 | |
| 5660 | vha->flags.online = 1; |
| 5661 | |
| 5662 | ha->isp_ops->enable_intrs(ha); |
| 5663 | |
| 5664 | ha->isp_abort_cnt = 0; |
| 5665 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 5666 | |
Saurav Kashyap | 5329678 | 2011-05-10 11:30:06 -0700 | [diff] [blame] | 5667 | /* Update the firmware version */ |
Giridhar Malavali | 3173167 | 2011-08-16 11:31:54 -0700 | [diff] [blame] | 5668 | status = qla82xx_check_md_needed(vha); |
Saurav Kashyap | 5329678 | 2011-05-10 11:30:06 -0700 | [diff] [blame] | 5669 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5670 | if (ha->fce) { |
| 5671 | ha->flags.fce_enabled = 1; |
| 5672 | memset(ha->fce, 0, |
| 5673 | fce_calc_size(ha->fce_bufs)); |
| 5674 | rval = qla2x00_enable_fce_trace(vha, |
| 5675 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 5676 | &ha->fce_bufs); |
| 5677 | if (rval) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5678 | ql_log(ql_log_warn, vha, 0x8001, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5679 | "Unable to reinitialize FCE (%d).\n", |
| 5680 | rval); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5681 | ha->flags.fce_enabled = 0; |
| 5682 | } |
| 5683 | } |
| 5684 | |
| 5685 | if (ha->eft) { |
| 5686 | memset(ha->eft, 0, EFT_SIZE); |
| 5687 | rval = qla2x00_enable_eft_trace(vha, |
| 5688 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 5689 | if (rval) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5690 | ql_log(ql_log_warn, vha, 0x8010, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5691 | "Unable to reinitialize EFT (%d).\n", |
| 5692 | rval); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5693 | } |
| 5694 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5695 | } |
| 5696 | |
| 5697 | if (!status) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5698 | ql_dbg(ql_dbg_taskm, vha, 0x8011, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5699 | "qla82xx_restart_isp succeeded.\n"); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5700 | |
| 5701 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5702 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 5703 | if (vp->vp_idx) { |
| 5704 | atomic_inc(&vp->vref_count); |
| 5705 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5706 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5707 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5708 | |
| 5709 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5710 | atomic_dec(&vp->vref_count); |
| 5711 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5712 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5713 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5714 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5715 | } else { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5716 | ql_log(ql_log_warn, vha, 0x8016, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5717 | "qla82xx_restart_isp **** FAILED ****.\n"); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5718 | } |
| 5719 | |
| 5720 | return status; |
| 5721 | } |
| 5722 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5723 | void |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 5724 | qla81xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5725 | { |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 5726 | struct qla_hw_data *ha = vha->hw; |
| 5727 | |
| 5728 | if (!ql2xetsenable) |
| 5729 | return; |
| 5730 | |
| 5731 | /* Enable ETS Burst. */ |
| 5732 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
| 5733 | ha->fw_options[2] |= BIT_9; |
| 5734 | qla2x00_set_fw_options(vha, ha->fw_options); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5735 | } |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5736 | |
| 5737 | /* |
| 5738 | * qla24xx_get_fcp_prio |
| 5739 | * Gets the fcp cmd priority value for the logged in port. |
| 5740 | * Looks for a match of the port descriptors within |
| 5741 | * each of the fcp prio config entries. If a match is found, |
| 5742 | * the tag (priority) value is returned. |
| 5743 | * |
| 5744 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5745 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5746 | * fcport = port structure pointer. |
| 5747 | * |
| 5748 | * Return: |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 5749 | * non-zero (if found) |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5750 | * -1 (if not found) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5751 | * |
| 5752 | * Context: |
| 5753 | * Kernel context |
| 5754 | */ |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5755 | static int |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5756 | qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 5757 | { |
| 5758 | int i, entries; |
| 5759 | uint8_t pid_match, wwn_match; |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5760 | int priority; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5761 | uint32_t pid1, pid2; |
| 5762 | uint64_t wwn1, wwn2; |
| 5763 | struct qla_fcp_prio_entry *pri_entry; |
| 5764 | struct qla_hw_data *ha = vha->hw; |
| 5765 | |
| 5766 | if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled) |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5767 | return -1; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5768 | |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5769 | priority = -1; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5770 | entries = ha->fcp_prio_cfg->num_entries; |
| 5771 | pri_entry = &ha->fcp_prio_cfg->entry[0]; |
| 5772 | |
| 5773 | for (i = 0; i < entries; i++) { |
| 5774 | pid_match = wwn_match = 0; |
| 5775 | |
| 5776 | if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) { |
| 5777 | pri_entry++; |
| 5778 | continue; |
| 5779 | } |
| 5780 | |
| 5781 | /* check source pid for a match */ |
| 5782 | if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) { |
| 5783 | pid1 = pri_entry->src_pid & INVALID_PORT_ID; |
| 5784 | pid2 = vha->d_id.b24 & INVALID_PORT_ID; |
| 5785 | if (pid1 == INVALID_PORT_ID) |
| 5786 | pid_match++; |
| 5787 | else if (pid1 == pid2) |
| 5788 | pid_match++; |
| 5789 | } |
| 5790 | |
| 5791 | /* check destination pid for a match */ |
| 5792 | if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) { |
| 5793 | pid1 = pri_entry->dst_pid & INVALID_PORT_ID; |
| 5794 | pid2 = fcport->d_id.b24 & INVALID_PORT_ID; |
| 5795 | if (pid1 == INVALID_PORT_ID) |
| 5796 | pid_match++; |
| 5797 | else if (pid1 == pid2) |
| 5798 | pid_match++; |
| 5799 | } |
| 5800 | |
| 5801 | /* check source WWN for a match */ |
| 5802 | if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) { |
| 5803 | wwn1 = wwn_to_u64(vha->port_name); |
| 5804 | wwn2 = wwn_to_u64(pri_entry->src_wwpn); |
| 5805 | if (wwn2 == (uint64_t)-1) |
| 5806 | wwn_match++; |
| 5807 | else if (wwn1 == wwn2) |
| 5808 | wwn_match++; |
| 5809 | } |
| 5810 | |
| 5811 | /* check destination WWN for a match */ |
| 5812 | if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) { |
| 5813 | wwn1 = wwn_to_u64(fcport->port_name); |
| 5814 | wwn2 = wwn_to_u64(pri_entry->dst_wwpn); |
| 5815 | if (wwn2 == (uint64_t)-1) |
| 5816 | wwn_match++; |
| 5817 | else if (wwn1 == wwn2) |
| 5818 | wwn_match++; |
| 5819 | } |
| 5820 | |
| 5821 | if (pid_match == 2 || wwn_match == 2) { |
| 5822 | /* Found a matching entry */ |
| 5823 | if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID) |
| 5824 | priority = pri_entry->tag; |
| 5825 | break; |
| 5826 | } |
| 5827 | |
| 5828 | pri_entry++; |
| 5829 | } |
| 5830 | |
| 5831 | return priority; |
| 5832 | } |
| 5833 | |
| 5834 | /* |
| 5835 | * qla24xx_update_fcport_fcp_prio |
| 5836 | * Activates fcp priority for the logged in fc port |
| 5837 | * |
| 5838 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5839 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5840 | * fcp = port structure pointer. |
| 5841 | * |
| 5842 | * Return: |
| 5843 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 5844 | * |
| 5845 | * Context: |
| 5846 | * Kernel context. |
| 5847 | */ |
| 5848 | int |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5849 | 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] | 5850 | { |
| 5851 | int ret; |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5852 | int priority; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5853 | uint16_t mb[5]; |
| 5854 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5855 | if (fcport->port_type != FCT_TARGET || |
| 5856 | fcport->loop_id == FC_NO_LOOP_ID) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5857 | return QLA_FUNCTION_FAILED; |
| 5858 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5859 | priority = qla24xx_get_fcp_prio(vha, fcport); |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5860 | if (priority < 0) |
| 5861 | return QLA_FUNCTION_FAILED; |
| 5862 | |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 5863 | if (IS_QLA82XX(vha->hw)) { |
| 5864 | fcport->fcp_prio = priority & 0xf; |
| 5865 | return QLA_SUCCESS; |
| 5866 | } |
| 5867 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5868 | ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb); |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5869 | if (ret == QLA_SUCCESS) { |
| 5870 | if (fcport->fcp_prio != priority) |
| 5871 | ql_dbg(ql_dbg_user, vha, 0x709e, |
| 5872 | "Updated FCP_CMND priority - value=%d loop_id=%d " |
| 5873 | "port_id=%02x%02x%02x.\n", priority, |
| 5874 | fcport->loop_id, fcport->d_id.b.domain, |
| 5875 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 5876 | fcport->fcp_prio = priority & 0xf; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5877 | } else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5878 | ql_dbg(ql_dbg_user, vha, 0x704f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5879 | "Unable to update FCP_CMND priority - ret=0x%x for " |
| 5880 | "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id, |
| 5881 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 5882 | fcport->d_id.b.al_pa); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5883 | return ret; |
| 5884 | } |
| 5885 | |
| 5886 | /* |
| 5887 | * qla24xx_update_all_fcp_prio |
| 5888 | * Activates fcp priority for all the logged in ports |
| 5889 | * |
| 5890 | * Input: |
| 5891 | * ha = adapter block pointer. |
| 5892 | * |
| 5893 | * Return: |
| 5894 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 5895 | * |
| 5896 | * Context: |
| 5897 | * Kernel context. |
| 5898 | */ |
| 5899 | int |
| 5900 | qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha) |
| 5901 | { |
| 5902 | int ret; |
| 5903 | fc_port_t *fcport; |
| 5904 | |
| 5905 | ret = QLA_FUNCTION_FAILED; |
| 5906 | /* We need to set priority for all logged in ports */ |
| 5907 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 5908 | ret = qla24xx_update_fcport_fcp_prio(vha, fcport); |
| 5909 | |
| 5910 | return ret; |
| 5911 | } |