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 |
Chad Dupuis | 46152ce | 2012-08-22 14:21:08 -0400 | [diff] [blame] | 3 | * Copyright (c) 2003-2012 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; |
Saurav Kashyap | 711aa7f | 2012-08-22 14:21:15 -0400 | [diff] [blame] | 438 | uint16_t config[4]; |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 439 | |
| 440 | qla83xx_idc_lock(vha, 0); |
| 441 | |
| 442 | /* SV: TODO: Assign initialization timeout from |
| 443 | * flash-info / other param |
| 444 | */ |
| 445 | ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT; |
| 446 | ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT; |
| 447 | |
| 448 | /* Set our fcoe function presence */ |
| 449 | if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) { |
| 450 | ql_dbg(ql_dbg_p3p, vha, 0xb077, |
| 451 | "Error while setting DRV-Presence.\n"); |
| 452 | rval = QLA_FUNCTION_FAILED; |
| 453 | goto exit; |
| 454 | } |
| 455 | |
| 456 | /* Decide the reset ownership */ |
| 457 | qla83xx_reset_ownership(vha); |
| 458 | |
| 459 | /* |
| 460 | * On first protocol driver load: |
| 461 | * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery |
| 462 | * register. |
| 463 | * Others: Check compatibility with current IDC Major version. |
| 464 | */ |
| 465 | qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver); |
| 466 | if (ha->flags.nic_core_reset_owner) { |
| 467 | /* Set IDC Major version */ |
| 468 | idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION; |
| 469 | qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver); |
| 470 | |
| 471 | /* Clearing IDC-Lock-Recovery register */ |
| 472 | qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0); |
| 473 | } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) { |
| 474 | /* |
| 475 | * Clear further IDC participation if we are not compatible with |
| 476 | * the current IDC Major Version. |
| 477 | */ |
| 478 | ql_log(ql_log_warn, vha, 0xb07d, |
| 479 | "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n", |
| 480 | idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION); |
| 481 | __qla83xx_clear_drv_presence(vha); |
| 482 | rval = QLA_FUNCTION_FAILED; |
| 483 | goto exit; |
| 484 | } |
| 485 | /* Each function sets its supported Minor version. */ |
| 486 | qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver); |
| 487 | idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2)); |
| 488 | qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver); |
| 489 | |
Saurav Kashyap | 711aa7f | 2012-08-22 14:21:15 -0400 | [diff] [blame] | 490 | if (ha->flags.nic_core_reset_owner) { |
| 491 | memset(config, 0, sizeof(config)); |
| 492 | if (!qla81xx_get_port_config(vha, config)) |
| 493 | qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, |
| 494 | QLA8XXX_DEV_READY); |
| 495 | } |
| 496 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 497 | rval = qla83xx_idc_state_handler(vha); |
| 498 | |
| 499 | exit: |
| 500 | qla83xx_idc_unlock(vha, 0); |
| 501 | |
| 502 | return rval; |
| 503 | } |
| 504 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | /* |
| 506 | * qla2x00_initialize_adapter |
| 507 | * Initialize board. |
| 508 | * |
| 509 | * Input: |
| 510 | * ha = adapter block pointer. |
| 511 | * |
| 512 | * Returns: |
| 513 | * 0 = success |
| 514 | */ |
| 515 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 516 | qla2x00_initialize_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | { |
| 518 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 519 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 520 | struct req_que *req = ha->req_q_map[0]; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | /* Clear adapter flags. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 523 | vha->flags.online = 0; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 524 | ha->flags.chip_reset_done = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 525 | vha->flags.reset_active = 0; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 526 | ha->flags.pci_channel_io_perm_failure = 0; |
| 527 | ha->flags.eeh_busy = 0; |
Andrew Vasquez | 794a569 | 2010-12-21 16:00:21 -0800 | [diff] [blame] | 528 | ha->flags.thermal_supported = 1; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 529 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 530 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 531 | vha->device_flags = DFLG_NO_CABLE; |
| 532 | vha->dpc_flags = 0; |
| 533 | vha->flags.management_server_logged_in = 0; |
| 534 | vha->marker_needed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | ha->isp_abort_cnt = 0; |
| 536 | ha->beacon_blink_led = 0; |
| 537 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 538 | set_bit(0, ha->req_qid_map); |
| 539 | set_bit(0, ha->rsp_qid_map); |
| 540 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 541 | ql_dbg(ql_dbg_init, vha, 0x0040, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 542 | "Configuring PCI space...\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 543 | rval = ha->isp_ops->pci_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 545 | ql_log(ql_log_warn, vha, 0x0044, |
| 546 | "Unable to configure PCI space.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | return (rval); |
| 548 | } |
| 549 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 550 | ha->isp_ops->reset_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 552 | rval = qla2xxx_get_flash_info(vha); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 553 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 554 | ql_log(ql_log_fatal, vha, 0x004f, |
| 555 | "Unable to validate FLASH data.\n"); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 556 | return (rval); |
| 557 | } |
| 558 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 559 | ha->isp_ops->get_flash_version(vha, req->ring); |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 560 | ql_dbg(ql_dbg_init, vha, 0x0061, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 561 | "Configure NVRAM parameters...\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 562 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 563 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 565 | if (ha->flags.disable_serdes) { |
| 566 | /* Mask HBA via NVRAM settings? */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 567 | ql_log(ql_log_info, vha, 0x0077, |
| 568 | "Masking HBA WWPN " |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 569 | "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 570 | vha->port_name[0], vha->port_name[1], |
| 571 | vha->port_name[2], vha->port_name[3], |
| 572 | vha->port_name[4], vha->port_name[5], |
| 573 | vha->port_name[6], vha->port_name[7]); |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 574 | return QLA_FUNCTION_FAILED; |
| 575 | } |
| 576 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 577 | ql_dbg(ql_dbg_init, vha, 0x0078, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 578 | "Verifying loaded RISC code...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 580 | if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) { |
| 581 | rval = ha->isp_ops->chip_diag(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 582 | if (rval) |
| 583 | return (rval); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 584 | rval = qla2x00_setup_chip(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 585 | if (rval) |
| 586 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 588 | |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 589 | if (IS_QLA84XX(ha)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 590 | ha->cs84xx = qla84xx_get_chip(vha); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 591 | if (!ha->cs84xx) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 592 | ql_log(ql_log_warn, vha, 0x00d0, |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 593 | "Unable to configure ISP84XX.\n"); |
| 594 | return QLA_FUNCTION_FAILED; |
| 595 | } |
| 596 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 597 | |
| 598 | if (qla_ini_mode_enabled(vha)) |
| 599 | rval = qla2x00_init_rings(vha); |
| 600 | |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 601 | ha->flags.chip_reset_done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 603 | if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) { |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 604 | /* Issue verify 84xx FW IOCB to complete 84xx initialization */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 605 | rval = qla84xx_init_chip(vha); |
| 606 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 607 | ql_log(ql_log_warn, vha, 0x00d4, |
| 608 | "Unable to initialize ISP84XX.\n"); |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 609 | qla84xx_put_chip(vha); |
| 610 | } |
| 611 | } |
| 612 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 613 | /* Load the NIC Core f/w if we are the first protocol driver. */ |
| 614 | if (IS_QLA8031(ha)) { |
| 615 | rval = qla83xx_nic_core_fw_load(vha); |
| 616 | if (rval) |
| 617 | ql_log(ql_log_warn, vha, 0x0124, |
| 618 | "Error in initializing NIC Core f/w.\n"); |
| 619 | } |
| 620 | |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 621 | if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)) |
| 622 | qla24xx_read_fcp_prio_cfg(vha); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 623 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | return (rval); |
| 625 | } |
| 626 | |
| 627 | /** |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 628 | * qla2100_pci_config() - Setup ISP21xx PCI configuration registers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | * @ha: HA context |
| 630 | * |
| 631 | * Returns 0 on success. |
| 632 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 633 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 634 | qla2100_pci_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 636 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 637 | unsigned long flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 638 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 639 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 642 | pci_try_set_mwi(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 645 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 647 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 648 | pci_disable_rom(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 650 | /* Get PCI bus information. */ |
| 651 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 652 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 653 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 654 | |
| 655 | return QLA_SUCCESS; |
| 656 | } |
| 657 | |
| 658 | /** |
| 659 | * qla2300_pci_config() - Setup ISP23xx PCI configuration registers. |
| 660 | * @ha: HA context |
| 661 | * |
| 662 | * Returns 0 on success. |
| 663 | */ |
| 664 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 665 | qla2300_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 666 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 667 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 668 | unsigned long flags = 0; |
| 669 | uint32_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 670 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 671 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 672 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 673 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 674 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 675 | |
| 676 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 677 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 678 | |
| 679 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 680 | w &= ~PCI_COMMAND_INTX_DISABLE; |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 681 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 682 | |
| 683 | /* |
| 684 | * If this is a 2300 card and not 2312, reset the |
| 685 | * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately, |
| 686 | * the 2310 also reports itself as a 2300 so we need to get the |
| 687 | * fb revision level -- a 6 indicates it really is a 2300 and |
| 688 | * not a 2310. |
| 689 | */ |
| 690 | if (IS_QLA2300(ha)) { |
| 691 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 692 | |
| 693 | /* Pause RISC. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 694 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 695 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 696 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 697 | break; |
| 698 | |
| 699 | udelay(10); |
| 700 | } |
| 701 | |
| 702 | /* Select FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 703 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 704 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 705 | |
| 706 | /* Get the fb rev level */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 707 | ha->fb_rev = RD_FB_CMD_REG(ha, reg); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 708 | |
| 709 | if (ha->fb_rev == FPM_2300) |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 710 | pci_clear_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 711 | |
| 712 | /* Deselect FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 713 | WRT_REG_WORD(®->ctrl_status, 0x0); |
| 714 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 715 | |
| 716 | /* Release RISC module. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 717 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 718 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 719 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 720 | break; |
| 721 | |
| 722 | udelay(10); |
| 723 | } |
| 724 | |
| 725 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 726 | } |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 727 | |
| 728 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 729 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 730 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 731 | |
| 732 | /* Get PCI bus information. */ |
| 733 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 734 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 735 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 736 | |
| 737 | return QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 741 | * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers. |
| 742 | * @ha: HA context |
| 743 | * |
| 744 | * Returns 0 on success. |
| 745 | */ |
| 746 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 747 | qla24xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 748 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 749 | uint16_t w; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 750 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 751 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 752 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 753 | |
| 754 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 755 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 756 | |
| 757 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 758 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 759 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 760 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 761 | |
| 762 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 763 | |
| 764 | /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */ |
Andrew Vasquez | f85ec18 | 2007-07-19 15:06:01 -0700 | [diff] [blame] | 765 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX)) |
| 766 | pcix_set_mmrbc(ha->pdev, 2048); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 767 | |
| 768 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Jon Mason | e67f132 | 2012-07-10 14:57:56 -0700 | [diff] [blame] | 769 | if (pci_is_pcie(ha->pdev)) |
Chad Dupuis | 5ffd3a5 | 2012-08-22 14:21:26 -0400 | [diff] [blame] | 770 | pcie_set_readrq(ha->pdev, 4096); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 771 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 772 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 773 | |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 774 | ha->chip_revision = ha->pdev->revision; |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 775 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 776 | /* Get PCI bus information. */ |
| 777 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 778 | ha->pci_attr = RD_REG_DWORD(®->ctrl_status); |
| 779 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 780 | |
| 781 | return QLA_SUCCESS; |
| 782 | } |
| 783 | |
| 784 | /** |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 785 | * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers. |
| 786 | * @ha: HA context |
| 787 | * |
| 788 | * Returns 0 on success. |
| 789 | */ |
| 790 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 791 | qla25xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 792 | { |
| 793 | uint16_t w; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 794 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 795 | |
| 796 | pci_set_master(ha->pdev); |
| 797 | pci_try_set_mwi(ha->pdev); |
| 798 | |
| 799 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
| 800 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
| 801 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 802 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 803 | |
| 804 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Jon Mason | e67f132 | 2012-07-10 14:57:56 -0700 | [diff] [blame] | 805 | if (pci_is_pcie(ha->pdev)) |
Chad Dupuis | 5ffd3a5 | 2012-08-22 14:21:26 -0400 | [diff] [blame] | 806 | pcie_set_readrq(ha->pdev, 4096); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 807 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 808 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 809 | |
| 810 | ha->chip_revision = ha->pdev->revision; |
| 811 | |
| 812 | return QLA_SUCCESS; |
| 813 | } |
| 814 | |
| 815 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | * qla2x00_isp_firmware() - Choose firmware image. |
| 817 | * @ha: HA context |
| 818 | * |
| 819 | * Returns 0 on success. |
| 820 | */ |
| 821 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 822 | qla2x00_isp_firmware(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | { |
| 824 | int rval; |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 825 | uint16_t loop_id, topo, sw_cap; |
| 826 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 827 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | |
| 829 | /* Assume loading risc code */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 830 | rval = QLA_FUNCTION_FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | |
| 832 | if (ha->flags.disable_risc_code_load) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 833 | ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | |
| 835 | /* Verify checksum of loaded RISC code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 836 | rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address); |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 837 | if (rval == QLA_SUCCESS) { |
| 838 | /* And, verify we are not in ROM code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 839 | rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa, |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 840 | &area, &domain, &topo, &sw_cap); |
| 841 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | } |
| 843 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 844 | if (rval) |
| 845 | ql_dbg(ql_dbg_init, vha, 0x007a, |
| 846 | "**** Load RISC code ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | |
| 848 | return (rval); |
| 849 | } |
| 850 | |
| 851 | /** |
| 852 | * qla2x00_reset_chip() - Reset ISP chip. |
| 853 | * @ha: HA context |
| 854 | * |
| 855 | * Returns 0 on success. |
| 856 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 857 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 858 | qla2x00_reset_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | { |
| 860 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 861 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 862 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | uint32_t cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | uint16_t cmd; |
| 865 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 866 | if (unlikely(pci_channel_offline(ha->pdev))) |
| 867 | return; |
| 868 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 869 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | |
| 871 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 872 | |
| 873 | /* Turn off master enable */ |
| 874 | cmd = 0; |
| 875 | pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd); |
| 876 | cmd &= ~PCI_COMMAND_MASTER; |
| 877 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 878 | |
| 879 | if (!IS_QLA2100(ha)) { |
| 880 | /* Pause RISC. */ |
| 881 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
| 882 | if (IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 883 | for (cnt = 0; cnt < 30000; cnt++) { |
| 884 | if ((RD_REG_WORD(®->hccr) & |
| 885 | HCCR_RISC_PAUSE) != 0) |
| 886 | break; |
| 887 | udelay(100); |
| 888 | } |
| 889 | } else { |
| 890 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 891 | udelay(10); |
| 892 | } |
| 893 | |
| 894 | /* Select FPM registers. */ |
| 895 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 896 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 897 | |
| 898 | /* FPM Soft Reset. */ |
| 899 | WRT_REG_WORD(®->fpm_diag_config, 0x100); |
| 900 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 901 | |
| 902 | /* Toggle Fpm Reset. */ |
| 903 | if (!IS_QLA2200(ha)) { |
| 904 | WRT_REG_WORD(®->fpm_diag_config, 0x0); |
| 905 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 906 | } |
| 907 | |
| 908 | /* Select frame buffer registers. */ |
| 909 | WRT_REG_WORD(®->ctrl_status, 0x10); |
| 910 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 911 | |
| 912 | /* Reset frame buffer FIFOs. */ |
| 913 | if (IS_QLA2200(ha)) { |
| 914 | WRT_FB_CMD_REG(ha, reg, 0xa000); |
| 915 | RD_FB_CMD_REG(ha, reg); /* PCI Posting. */ |
| 916 | } else { |
| 917 | WRT_FB_CMD_REG(ha, reg, 0x00fc); |
| 918 | |
| 919 | /* Read back fb_cmd until zero or 3 seconds max */ |
| 920 | for (cnt = 0; cnt < 3000; cnt++) { |
| 921 | if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0) |
| 922 | break; |
| 923 | udelay(100); |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | /* Select RISC module registers. */ |
| 928 | WRT_REG_WORD(®->ctrl_status, 0); |
| 929 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 930 | |
| 931 | /* Reset RISC processor. */ |
| 932 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 933 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 934 | |
| 935 | /* Release RISC processor. */ |
| 936 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 937 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 938 | } |
| 939 | |
| 940 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); |
| 941 | WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT); |
| 942 | |
| 943 | /* Reset ISP chip. */ |
| 944 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 945 | |
| 946 | /* Wait for RISC to recover from reset. */ |
| 947 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 948 | /* |
| 949 | * It is necessary to for a delay here since the card doesn't |
| 950 | * respond to PCI reads during a reset. On some architectures |
| 951 | * this will result in an MCA. |
| 952 | */ |
| 953 | udelay(20); |
| 954 | for (cnt = 30000; cnt; cnt--) { |
| 955 | if ((RD_REG_WORD(®->ctrl_status) & |
| 956 | CSR_ISP_SOFT_RESET) == 0) |
| 957 | break; |
| 958 | udelay(100); |
| 959 | } |
| 960 | } else |
| 961 | udelay(10); |
| 962 | |
| 963 | /* Reset RISC processor. */ |
| 964 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 965 | |
| 966 | WRT_REG_WORD(®->semaphore, 0); |
| 967 | |
| 968 | /* Release RISC processor. */ |
| 969 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 970 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 971 | |
| 972 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 973 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | ffb39f0 | 2006-05-17 15:09:06 -0700 | [diff] [blame] | 974 | if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | |
| 977 | udelay(100); |
| 978 | } |
| 979 | } else |
| 980 | udelay(100); |
| 981 | |
| 982 | /* Turn on master enable */ |
| 983 | cmd |= PCI_COMMAND_MASTER; |
| 984 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 985 | |
| 986 | /* Disable RISC pause on FPM parity error. */ |
| 987 | if (!IS_QLA2100(ha)) { |
| 988 | WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE); |
| 989 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 990 | } |
| 991 | |
| 992 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 993 | } |
| 994 | |
| 995 | /** |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 996 | * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC. |
| 997 | * |
| 998 | * Returns 0 on success. |
| 999 | */ |
| 1000 | int |
| 1001 | qla81xx_reset_mpi(scsi_qla_host_t *vha) |
| 1002 | { |
| 1003 | uint16_t mb[4] = {0x1010, 0, 1, 0}; |
| 1004 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1005 | if (!IS_QLA81XX(vha->hw)) |
| 1006 | return QLA_SUCCESS; |
| 1007 | |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 1008 | return qla81xx_write_mpi_register(vha, mb); |
| 1009 | } |
| 1010 | |
| 1011 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1012 | * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC. |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1013 | * @ha: HA context |
| 1014 | * |
| 1015 | * Returns 0 on success. |
| 1016 | */ |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1017 | static inline void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1018 | qla24xx_reset_risc(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1019 | { |
| 1020 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1021 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1022 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 1023 | uint32_t cnt, d2; |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 1024 | uint16_t wd; |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 1025 | static int abts_cnt; /* ISP abort retry counts */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1026 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1027 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1028 | |
| 1029 | /* Reset RISC. */ |
| 1030 | WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
| 1031 | for (cnt = 0; cnt < 30000; cnt++) { |
| 1032 | if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0) |
| 1033 | break; |
| 1034 | |
| 1035 | udelay(10); |
| 1036 | } |
| 1037 | |
| 1038 | WRT_REG_DWORD(®->ctrl_status, |
| 1039 | CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 1040 | pci_read_config_word(ha->pdev, PCI_COMMAND, &wd); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1041 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 1042 | udelay(100); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1043 | /* Wait for firmware to complete NVRAM accesses. */ |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1044 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 1045 | for (cnt = 10000 ; cnt && d2; cnt--) { |
| 1046 | udelay(5); |
| 1047 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 1048 | barrier(); |
| 1049 | } |
| 1050 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 1051 | /* Wait for soft-reset to complete. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1052 | d2 = RD_REG_DWORD(®->ctrl_status); |
| 1053 | for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) { |
| 1054 | udelay(5); |
| 1055 | d2 = RD_REG_DWORD(®->ctrl_status); |
| 1056 | barrier(); |
| 1057 | } |
| 1058 | |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 1059 | /* If required, do an MPI FW reset now */ |
| 1060 | if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) { |
| 1061 | if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) { |
| 1062 | if (++abts_cnt < 5) { |
| 1063 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 1064 | set_bit(MPI_RESET_NEEDED, &vha->dpc_flags); |
| 1065 | } else { |
| 1066 | /* |
| 1067 | * We exhausted the ISP abort retries. We have to |
| 1068 | * set the board offline. |
| 1069 | */ |
| 1070 | abts_cnt = 0; |
| 1071 | vha->flags.online = 0; |
| 1072 | } |
| 1073 | } |
| 1074 | } |
| 1075 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1076 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 1077 | RD_REG_DWORD(®->hccr); |
| 1078 | |
| 1079 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 1080 | RD_REG_DWORD(®->hccr); |
| 1081 | |
| 1082 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET); |
| 1083 | RD_REG_DWORD(®->hccr); |
| 1084 | |
| 1085 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 1086 | for (cnt = 6000000 ; cnt && d2; cnt--) { |
| 1087 | udelay(5); |
| 1088 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 1089 | barrier(); |
| 1090 | } |
| 1091 | |
| 1092 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 124f85e | 2009-01-05 11:18:06 -0800 | [diff] [blame] | 1093 | |
| 1094 | if (IS_NOPOLLING_TYPE(ha)) |
| 1095 | ha->isp_ops->enable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1099 | * qla24xx_reset_chip() - Reset ISP24xx chip. |
| 1100 | * @ha: HA context |
| 1101 | * |
| 1102 | * Returns 0 on success. |
| 1103 | */ |
| 1104 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1105 | qla24xx_reset_chip(scsi_qla_host_t *vha) |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1106 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1107 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 1108 | |
| 1109 | if (pci_channel_offline(ha->pdev) && |
| 1110 | ha->flags.pci_channel_io_perm_failure) { |
| 1111 | return; |
| 1112 | } |
| 1113 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1114 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1115 | |
| 1116 | /* Perform RISC reset. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1117 | qla24xx_reset_risc(vha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | * qla2x00_chip_diag() - Test chip for proper operation. |
| 1122 | * @ha: HA context |
| 1123 | * |
| 1124 | * Returns 0 on success. |
| 1125 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1126 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1127 | qla2x00_chip_diag(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | { |
| 1129 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1130 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1131 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | unsigned long flags = 0; |
| 1133 | uint16_t data; |
| 1134 | uint32_t cnt; |
| 1135 | uint16_t mb[5]; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1136 | struct req_que *req = ha->req_q_map[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | |
| 1138 | /* Assume a failed state */ |
| 1139 | rval = QLA_FUNCTION_FAILED; |
| 1140 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1141 | ql_dbg(ql_dbg_init, vha, 0x007b, |
| 1142 | "Testing device at %lx.\n", (u_long)®->flash_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | |
| 1144 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1145 | |
| 1146 | /* Reset ISP chip. */ |
| 1147 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 1148 | |
| 1149 | /* |
| 1150 | * We need to have a delay here since the card will not respond while |
| 1151 | * in reset causing an MCA on some architectures. |
| 1152 | */ |
| 1153 | udelay(20); |
| 1154 | data = qla2x00_debounce_register(®->ctrl_status); |
| 1155 | for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) { |
| 1156 | udelay(5); |
| 1157 | data = RD_REG_WORD(®->ctrl_status); |
| 1158 | barrier(); |
| 1159 | } |
| 1160 | |
| 1161 | if (!cnt) |
| 1162 | goto chip_diag_failed; |
| 1163 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1164 | ql_dbg(ql_dbg_init, vha, 0x007c, |
| 1165 | "Reset register cleared by chip reset.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | |
| 1167 | /* Reset RISC processor. */ |
| 1168 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 1169 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 1170 | |
| 1171 | /* Workaround for QLA2312 PCI parity error */ |
| 1172 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 1173 | data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0)); |
| 1174 | for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) { |
| 1175 | udelay(5); |
| 1176 | data = RD_MAILBOX_REG(ha, reg, 0); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1177 | barrier(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | } |
| 1179 | } else |
| 1180 | udelay(10); |
| 1181 | |
| 1182 | if (!cnt) |
| 1183 | goto chip_diag_failed; |
| 1184 | |
| 1185 | /* Check product ID of chip */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1186 | 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] | 1187 | |
| 1188 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); |
| 1189 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); |
| 1190 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); |
| 1191 | mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4)); |
| 1192 | if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) || |
| 1193 | mb[3] != PROD_ID_3) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1194 | ql_log(ql_log_warn, vha, 0x0062, |
| 1195 | "Wrong product ID = 0x%x,0x%x,0x%x.\n", |
| 1196 | mb[1], mb[2], mb[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | |
| 1198 | goto chip_diag_failed; |
| 1199 | } |
| 1200 | ha->product_id[0] = mb[1]; |
| 1201 | ha->product_id[1] = mb[2]; |
| 1202 | ha->product_id[2] = mb[3]; |
| 1203 | ha->product_id[3] = mb[4]; |
| 1204 | |
| 1205 | /* Adjust fw RISC transfer size */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1206 | if (req->length > 1024) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024; |
| 1208 | else |
| 1209 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1210 | req->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | |
| 1212 | if (IS_QLA2200(ha) && |
| 1213 | RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) { |
| 1214 | /* Limit firmware transfer size with a 2200A */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1215 | ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1217 | ha->device_type |= DT_ISP2200A; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | ha->fw_transfer_size = 128; |
| 1219 | } |
| 1220 | |
| 1221 | /* Wrap Incoming Mailboxes Test. */ |
| 1222 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1223 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1224 | ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1225 | rval = qla2x00_mbx_reg_test(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1226 | if (rval) |
| 1227 | ql_log(ql_log_warn, vha, 0x0080, |
| 1228 | "Failed mailbox send register test.\n"); |
| 1229 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | /* Flag a successful rval */ |
| 1231 | rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1233 | |
| 1234 | chip_diag_failed: |
| 1235 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1236 | ql_log(ql_log_info, vha, 0x0081, |
| 1237 | "Chip diagnostics **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | |
| 1239 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1240 | |
| 1241 | return (rval); |
| 1242 | } |
| 1243 | |
| 1244 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1245 | * qla24xx_chip_diag() - Test ISP24xx for proper operation. |
| 1246 | * @ha: HA context |
| 1247 | * |
| 1248 | * Returns 0 on success. |
| 1249 | */ |
| 1250 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1251 | qla24xx_chip_diag(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1252 | { |
| 1253 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1254 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1255 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1256 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1257 | if (IS_QLA82XX(ha)) |
| 1258 | return QLA_SUCCESS; |
| 1259 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1260 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1261 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1262 | rval = qla2x00_mbx_reg_test(vha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1263 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1264 | ql_log(ql_log_warn, vha, 0x0082, |
| 1265 | "Failed mailbox send register test.\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1266 | } else { |
| 1267 | /* Flag a successful rval */ |
| 1268 | rval = QLA_SUCCESS; |
| 1269 | } |
| 1270 | |
| 1271 | return rval; |
| 1272 | } |
| 1273 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1274 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1275 | qla2x00_alloc_fw_dump(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1276 | { |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1277 | int rval; |
| 1278 | 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] | 1279 | eft_size, fce_size, mq_size; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1280 | dma_addr_t tc_dma; |
| 1281 | void *tc; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1282 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1283 | struct req_que *req = ha->req_q_map[0]; |
| 1284 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 1285 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1286 | if (ha->fw_dump) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1287 | ql_dbg(ql_dbg_init, vha, 0x00bd, |
| 1288 | "Firmware dump already allocated.\n"); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1289 | return; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 1290 | } |
| 1291 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1292 | ha->fw_dumped = 0; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1293 | fixed_size = mem_size = eft_size = fce_size = mq_size = 0; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1294 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 1295 | fixed_size = sizeof(struct qla2100_fw_dump); |
| 1296 | } else if (IS_QLA23XX(ha)) { |
| 1297 | fixed_size = offsetof(struct qla2300_fw_dump, data_ram); |
| 1298 | mem_size = (ha->fw_memory_size - 0x11000 + 1) * |
| 1299 | sizeof(uint16_t); |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 1300 | } else if (IS_FWI2_CAPABLE(ha)) { |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1301 | if (IS_QLA83XX(ha)) |
| 1302 | fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem); |
| 1303 | else if (IS_QLA81XX(ha)) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1304 | fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem); |
| 1305 | else if (IS_QLA25XX(ha)) |
| 1306 | fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem); |
| 1307 | else |
| 1308 | fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1309 | mem_size = (ha->fw_memory_size - 0x100000 + 1) * |
| 1310 | sizeof(uint32_t); |
Giridhar Malavali | 050c9bb | 2012-02-09 11:15:33 -0800 | [diff] [blame] | 1311 | if (ha->mqenable) { |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1312 | if (!IS_QLA83XX(ha)) |
| 1313 | mq_size = sizeof(struct qla2xxx_mq_chain); |
Giridhar Malavali | 050c9bb | 2012-02-09 11:15:33 -0800 | [diff] [blame] | 1314 | /* |
| 1315 | * Allocate maximum buffer size for all queues. |
| 1316 | * Resizing must be done at end-of-dump processing. |
| 1317 | */ |
| 1318 | mq_size += ha->max_req_queues * |
| 1319 | (req->length * sizeof(request_t)); |
| 1320 | mq_size += ha->max_rsp_queues * |
| 1321 | (rsp->length * sizeof(response_t)); |
| 1322 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1323 | if (ha->tgt.atio_q_length) |
| 1324 | mq_size += ha->tgt.atio_q_length * sizeof(request_t); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1325 | /* Allocate memory for Fibre Channel Event Buffer. */ |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1326 | if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha)) |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1327 | goto try_eft; |
| 1328 | |
| 1329 | tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma, |
| 1330 | GFP_KERNEL); |
| 1331 | if (!tc) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1332 | ql_log(ql_log_warn, vha, 0x00be, |
| 1333 | "Unable to allocate (%d KB) for FCE.\n", |
| 1334 | FCE_SIZE / 1024); |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 1335 | goto try_eft; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | memset(tc, 0, FCE_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1339 | rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1340 | ha->fce_mb, &ha->fce_bufs); |
| 1341 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1342 | ql_log(ql_log_warn, vha, 0x00bf, |
| 1343 | "Unable to initialize FCE (%d).\n", rval); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1344 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, |
| 1345 | tc_dma); |
| 1346 | ha->flags.fce_enabled = 0; |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 1347 | goto try_eft; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1348 | } |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1349 | ql_dbg(ql_dbg_init, vha, 0x00c0, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1350 | "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1351 | |
Giridhar Malavali | 7d9dade | 2009-03-24 09:07:58 -0700 | [diff] [blame] | 1352 | fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1353 | ha->flags.fce_enabled = 1; |
| 1354 | ha->fce_dma = tc_dma; |
| 1355 | ha->fce = tc; |
| 1356 | try_eft: |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1357 | /* Allocate memory for Extended Trace Buffer. */ |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1358 | tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma, |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1359 | GFP_KERNEL); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1360 | if (!tc) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1361 | ql_log(ql_log_warn, vha, 0x00c1, |
| 1362 | "Unable to allocate (%d KB) for EFT.\n", |
| 1363 | EFT_SIZE / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1364 | goto cont_alloc; |
| 1365 | } |
| 1366 | |
Andrew Vasquez | fc44765 | 2008-01-17 09:02:18 -0800 | [diff] [blame] | 1367 | memset(tc, 0, EFT_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1368 | rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1369 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1370 | ql_log(ql_log_warn, vha, 0x00c2, |
| 1371 | "Unable to initialize EFT (%d).\n", rval); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1372 | dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, |
| 1373 | tc_dma); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1374 | goto cont_alloc; |
| 1375 | } |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1376 | ql_dbg(ql_dbg_init, vha, 0x00c3, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1377 | "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1378 | |
| 1379 | eft_size = EFT_SIZE; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1380 | ha->eft_dma = tc_dma; |
| 1381 | ha->eft = tc; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1382 | } |
| 1383 | cont_alloc: |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1384 | req_q_size = req->length * sizeof(request_t); |
| 1385 | rsp_q_size = rsp->length * sizeof(response_t); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1386 | |
| 1387 | dump_size = offsetof(struct qla2xxx_fw_dump, isp); |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1388 | 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] | 1389 | ha->chain_offset = dump_size; |
| 1390 | dump_size += mq_size + fce_size; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1391 | |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 1392 | ha->fw_dump = vmalloc(dump_size); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1393 | if (!ha->fw_dump) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1394 | ql_log(ql_log_warn, vha, 0x00c4, |
| 1395 | "Unable to allocate (%d KB) for firmware dump.\n", |
| 1396 | dump_size / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1397 | |
Madhuranath Iyengar | e30d175 | 2010-10-15 11:27:46 -0700 | [diff] [blame] | 1398 | if (ha->fce) { |
| 1399 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce, |
| 1400 | ha->fce_dma); |
| 1401 | ha->fce = NULL; |
| 1402 | ha->fce_dma = 0; |
| 1403 | } |
| 1404 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1405 | if (ha->eft) { |
| 1406 | dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft, |
| 1407 | ha->eft_dma); |
| 1408 | ha->eft = NULL; |
| 1409 | ha->eft_dma = 0; |
| 1410 | } |
| 1411 | return; |
| 1412 | } |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1413 | ql_dbg(ql_dbg_init, vha, 0x00c5, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1414 | "Allocated (%d KB) for firmware dump.\n", dump_size / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1415 | |
| 1416 | ha->fw_dump_len = dump_size; |
| 1417 | ha->fw_dump->signature[0] = 'Q'; |
| 1418 | ha->fw_dump->signature[1] = 'L'; |
| 1419 | ha->fw_dump->signature[2] = 'G'; |
| 1420 | ha->fw_dump->signature[3] = 'C'; |
| 1421 | ha->fw_dump->version = __constant_htonl(1); |
| 1422 | |
| 1423 | ha->fw_dump->fixed_size = htonl(fixed_size); |
| 1424 | ha->fw_dump->mem_size = htonl(mem_size); |
| 1425 | ha->fw_dump->req_q_size = htonl(req_q_size); |
| 1426 | ha->fw_dump->rsp_q_size = htonl(rsp_q_size); |
| 1427 | |
| 1428 | ha->fw_dump->eft_size = htonl(eft_size); |
| 1429 | ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma)); |
| 1430 | ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma)); |
| 1431 | |
| 1432 | ha->fw_dump->header_size = |
| 1433 | htonl(offsetof(struct qla2xxx_fw_dump, isp)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1434 | } |
| 1435 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1436 | static int |
| 1437 | qla81xx_mpi_sync(scsi_qla_host_t *vha) |
| 1438 | { |
| 1439 | #define MPS_MASK 0xe0 |
| 1440 | int rval; |
| 1441 | uint16_t dc; |
| 1442 | uint32_t dw; |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1443 | |
| 1444 | if (!IS_QLA81XX(vha->hw)) |
| 1445 | return QLA_SUCCESS; |
| 1446 | |
| 1447 | rval = qla2x00_write_ram_word(vha, 0x7c00, 1); |
| 1448 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1449 | ql_log(ql_log_warn, vha, 0x0105, |
| 1450 | "Unable to acquire semaphore.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1451 | goto done; |
| 1452 | } |
| 1453 | |
| 1454 | pci_read_config_word(vha->hw->pdev, 0x54, &dc); |
| 1455 | rval = qla2x00_read_ram_word(vha, 0x7a15, &dw); |
| 1456 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1457 | ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1458 | goto done_release; |
| 1459 | } |
| 1460 | |
| 1461 | dc &= MPS_MASK; |
| 1462 | if (dc == (dw & MPS_MASK)) |
| 1463 | goto done_release; |
| 1464 | |
| 1465 | dw &= ~MPS_MASK; |
| 1466 | dw |= dc; |
| 1467 | rval = qla2x00_write_ram_word(vha, 0x7a15, dw); |
| 1468 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1469 | ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | done_release: |
| 1473 | rval = qla2x00_write_ram_word(vha, 0x7c00, 0); |
| 1474 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1475 | ql_log(ql_log_warn, vha, 0x006d, |
| 1476 | "Unable to release semaphore.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | done: |
| 1480 | return rval; |
| 1481 | } |
| 1482 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1483 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | * qla2x00_setup_chip() - Load and start RISC firmware. |
| 1485 | * @ha: HA context |
| 1486 | * |
| 1487 | * Returns 0 on success. |
| 1488 | */ |
| 1489 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1490 | qla2x00_setup_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1492 | int rval; |
| 1493 | uint32_t srisc_address = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1494 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1495 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 1496 | unsigned long flags; |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 1497 | uint16_t fw_major_version; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1498 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1499 | if (IS_QLA82XX(ha)) { |
| 1500 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 1501 | if (rval == QLA_SUCCESS) { |
| 1502 | qla2x00_stop_firmware(vha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1503 | goto enable_82xx_npiv; |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 1504 | } else |
Giridhar Malavali | b963752 | 2010-05-28 15:08:15 -0700 | [diff] [blame] | 1505 | goto failed; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1506 | } |
| 1507 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1508 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 1509 | /* Disable SRAM, Instruction RAM and GP RAM parity. */ |
| 1510 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1511 | WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0)); |
| 1512 | RD_REG_WORD(®->hccr); |
| 1513 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1514 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1516 | qla81xx_mpi_sync(vha); |
| 1517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | /* Load firmware sequences */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1519 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1520 | if (rval == QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1521 | ql_dbg(ql_dbg_init, vha, 0x00c9, |
| 1522 | "Verifying Checksum of loaded RISC code.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1524 | rval = qla2x00_verify_checksum(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | if (rval == QLA_SUCCESS) { |
| 1526 | /* Start firmware execution. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1527 | ql_dbg(ql_dbg_init, vha, 0x00ca, |
| 1528 | "Starting firmware.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1530 | rval = qla2x00_execute_fw(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1531 | /* Retrieve firmware information. */ |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 1532 | if (rval == QLA_SUCCESS) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1533 | enable_82xx_npiv: |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 1534 | fw_major_version = ha->fw_major_version; |
Giridhar Malavali | 3173167 | 2011-08-16 11:31:54 -0700 | [diff] [blame] | 1535 | if (IS_QLA82XX(ha)) |
| 1536 | qla82xx_check_md_needed(vha); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1537 | else |
| 1538 | rval = qla2x00_get_fw_version(vha); |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 1539 | if (rval != QLA_SUCCESS) |
| 1540 | goto failed; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1541 | ha->flags.npiv_supported = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1542 | if (IS_QLA2XXX_MIDTYPE(ha) && |
Mike Hernandez | 946fb89 | 2008-08-13 21:36:59 -0700 | [diff] [blame] | 1543 | (ha->fw_attributes & BIT_2)) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1544 | ha->flags.npiv_supported = 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 1545 | if ((!ha->max_npiv_vports) || |
| 1546 | ((ha->max_npiv_vports + 1) % |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 1547 | MIN_MULTI_ID_FABRIC)) |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 1548 | ha->max_npiv_vports = |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 1549 | MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 1550 | } |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 1551 | qla2x00_get_resource_cnts(vha, NULL, |
| 1552 | &ha->fw_xcb_count, NULL, NULL, |
Andrew Vasquez | f3a0a77 | 2009-10-13 15:16:49 -0700 | [diff] [blame] | 1553 | &ha->max_npiv_vports, NULL); |
Andrew Vasquez | d743de6 | 2009-03-24 09:08:15 -0700 | [diff] [blame] | 1554 | |
Saurav Kashyap | be5ea3c | 2011-11-18 09:02:11 -0800 | [diff] [blame] | 1555 | if (!fw_major_version && ql2xallocfwdump |
| 1556 | && !IS_QLA82XX(ha)) |
Giridhar Malavali | 08de284 | 2011-08-16 11:31:44 -0700 | [diff] [blame] | 1557 | qla2x00_alloc_fw_dump(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | } |
| 1559 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1560 | ql_log(ql_log_fatal, vha, 0x00cd, |
| 1561 | "ISP Firmware failed checksum.\n"); |
| 1562 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1563 | } |
Andrew Vasquez | c74d88a | 2012-08-22 14:21:19 -0400 | [diff] [blame] | 1564 | } else |
| 1565 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1567 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 1568 | /* Enable proper parity. */ |
| 1569 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1570 | if (IS_QLA2300(ha)) |
| 1571 | /* SRAM parity */ |
| 1572 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1); |
| 1573 | else |
| 1574 | /* SRAM, Instruction RAM and GP RAM parity */ |
| 1575 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7); |
| 1576 | RD_REG_WORD(®->hccr); |
| 1577 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1578 | } |
| 1579 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1580 | if (IS_QLA83XX(ha)) |
| 1581 | goto skip_fac_check; |
| 1582 | |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1583 | if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) { |
| 1584 | uint32_t size; |
| 1585 | |
| 1586 | rval = qla81xx_fac_get_sector_size(vha, &size); |
| 1587 | if (rval == QLA_SUCCESS) { |
| 1588 | ha->flags.fac_supported = 1; |
| 1589 | ha->fdt_block_size = size << 2; |
| 1590 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1591 | ql_log(ql_log_warn, vha, 0x00ce, |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1592 | "Unsupported FAC firmware (%d.%02d.%02d).\n", |
| 1593 | ha->fw_major_version, ha->fw_minor_version, |
| 1594 | ha->fw_subminor_version); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1595 | skip_fac_check: |
| 1596 | if (IS_QLA83XX(ha)) { |
| 1597 | ha->flags.fac_supported = 0; |
| 1598 | rval = QLA_SUCCESS; |
| 1599 | } |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1600 | } |
| 1601 | } |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 1602 | failed: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1604 | ql_log(ql_log_fatal, vha, 0x00cf, |
| 1605 | "Setup chip ****FAILED****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | return (rval); |
| 1609 | } |
| 1610 | |
| 1611 | /** |
| 1612 | * qla2x00_init_response_q_entries() - Initializes response queue entries. |
| 1613 | * @ha: HA context |
| 1614 | * |
| 1615 | * Beginning of request ring has initialization control block already built |
| 1616 | * by nvram config routine. |
| 1617 | * |
| 1618 | * Returns 0 on success. |
| 1619 | */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1620 | void |
| 1621 | qla2x00_init_response_q_entries(struct rsp_que *rsp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | { |
| 1623 | uint16_t cnt; |
| 1624 | response_t *pkt; |
| 1625 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1626 | rsp->ring_ptr = rsp->ring; |
| 1627 | rsp->ring_index = 0; |
| 1628 | rsp->status_srb = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1629 | pkt = rsp->ring_ptr; |
| 1630 | for (cnt = 0; cnt < rsp->length; cnt++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | pkt->signature = RESPONSE_PROCESSED; |
| 1632 | pkt++; |
| 1633 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | } |
| 1635 | |
| 1636 | /** |
| 1637 | * qla2x00_update_fw_options() - Read and process firmware options. |
| 1638 | * @ha: HA context |
| 1639 | * |
| 1640 | * Returns 0 on success. |
| 1641 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1642 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1643 | qla2x00_update_fw_options(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | { |
| 1645 | uint16_t swing, emphasis, tx_sens, rx_sens; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1646 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | |
| 1648 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1649 | qla2x00_get_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | |
| 1651 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
| 1652 | return; |
| 1653 | |
| 1654 | /* Serial Link options. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1655 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115, |
| 1656 | "Serial link options.\n"); |
| 1657 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109, |
| 1658 | (uint8_t *)&ha->fw_seriallink_options, |
| 1659 | sizeof(ha->fw_seriallink_options)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | |
| 1661 | ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING; |
| 1662 | if (ha->fw_seriallink_options[3] & BIT_2) { |
| 1663 | ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING; |
| 1664 | |
| 1665 | /* 1G settings */ |
| 1666 | swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0); |
| 1667 | emphasis = (ha->fw_seriallink_options[2] & |
| 1668 | (BIT_4 | BIT_3)) >> 3; |
| 1669 | tx_sens = ha->fw_seriallink_options[0] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1670 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | rx_sens = (ha->fw_seriallink_options[0] & |
| 1672 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 1673 | ha->fw_options[10] = (emphasis << 14) | (swing << 8); |
| 1674 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 1675 | if (rx_sens == 0x0) |
| 1676 | rx_sens = 0x3; |
| 1677 | ha->fw_options[10] |= (tx_sens << 4) | rx_sens; |
| 1678 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 1679 | ha->fw_options[10] |= BIT_5 | |
| 1680 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 1681 | (tx_sens & (BIT_1 | BIT_0)); |
| 1682 | |
| 1683 | /* 2G settings */ |
| 1684 | swing = (ha->fw_seriallink_options[2] & |
| 1685 | (BIT_7 | BIT_6 | BIT_5)) >> 5; |
| 1686 | emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0); |
| 1687 | tx_sens = ha->fw_seriallink_options[1] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1688 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | rx_sens = (ha->fw_seriallink_options[1] & |
| 1690 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 1691 | ha->fw_options[11] = (emphasis << 14) | (swing << 8); |
| 1692 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 1693 | if (rx_sens == 0x0) |
| 1694 | rx_sens = 0x3; |
| 1695 | ha->fw_options[11] |= (tx_sens << 4) | rx_sens; |
| 1696 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 1697 | ha->fw_options[11] |= BIT_5 | |
| 1698 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 1699 | (tx_sens & (BIT_1 | BIT_0)); |
| 1700 | } |
| 1701 | |
| 1702 | /* FCP2 options. */ |
| 1703 | /* Return command IOCBs without waiting for an ABTS to complete. */ |
| 1704 | ha->fw_options[3] |= BIT_13; |
| 1705 | |
| 1706 | /* LED scheme. */ |
| 1707 | if (ha->flags.enable_led_scheme) |
| 1708 | ha->fw_options[2] |= BIT_12; |
| 1709 | |
andrew.vasquez@qlogic.com | 48c02fd | 2006-03-09 14:27:18 -0800 | [diff] [blame] | 1710 | /* Detect ISP6312. */ |
| 1711 | if (IS_QLA6312(ha)) |
| 1712 | ha->fw_options[2] |= BIT_13; |
| 1713 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | /* Update firmware options. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1715 | qla2x00_set_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | } |
| 1717 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1718 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1719 | qla24xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1720 | { |
| 1721 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1722 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1723 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1724 | if (IS_QLA82XX(ha)) |
| 1725 | return; |
| 1726 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1727 | /* Update Serial Link options. */ |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 1728 | if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1729 | return; |
| 1730 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1731 | rval = qla2x00_set_serdes_params(vha, |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 1732 | le16_to_cpu(ha->fw_seriallink_options24[1]), |
| 1733 | le16_to_cpu(ha->fw_seriallink_options24[2]), |
| 1734 | le16_to_cpu(ha->fw_seriallink_options24[3])); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1735 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1736 | ql_log(ql_log_warn, vha, 0x0104, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1737 | "Unable to update Serial Link options (%x).\n", rval); |
| 1738 | } |
| 1739 | } |
| 1740 | |
| 1741 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1742 | qla2x00_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1743 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1744 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1745 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1746 | struct req_que *req = ha->req_q_map[0]; |
| 1747 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1748 | |
| 1749 | /* Setup ring parameters in initialization control block. */ |
| 1750 | ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0); |
| 1751 | ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1752 | ha->init_cb->request_q_length = cpu_to_le16(req->length); |
| 1753 | ha->init_cb->response_q_length = cpu_to_le16(rsp->length); |
| 1754 | ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 1755 | ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 1756 | ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 1757 | 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] | 1758 | |
| 1759 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0); |
| 1760 | WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0); |
| 1761 | WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0); |
| 1762 | WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0); |
| 1763 | RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */ |
| 1764 | } |
| 1765 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1766 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1767 | qla24xx_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1768 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1769 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1770 | device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0); |
| 1771 | struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp; |
| 1772 | struct qla_msix_entry *msix; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1773 | struct init_cb_24xx *icb; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1774 | uint16_t rid = 0; |
| 1775 | struct req_que *req = ha->req_q_map[0]; |
| 1776 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1777 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1778 | /* Setup ring parameters in initialization control block. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1779 | icb = (struct init_cb_24xx *)ha->init_cb; |
| 1780 | icb->request_q_outpointer = __constant_cpu_to_le16(0); |
| 1781 | icb->response_q_inpointer = __constant_cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1782 | icb->request_q_length = cpu_to_le16(req->length); |
| 1783 | icb->response_q_length = cpu_to_le16(rsp->length); |
| 1784 | icb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 1785 | icb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 1786 | icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 1787 | icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1788 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1789 | /* Setup ATIO queue dma pointers for target mode */ |
| 1790 | icb->atio_q_inpointer = __constant_cpu_to_le16(0); |
| 1791 | icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length); |
| 1792 | icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma)); |
| 1793 | icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma)); |
| 1794 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1795 | if (ha->mqenable || IS_QLA83XX(ha)) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1796 | icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS); |
| 1797 | icb->rid = __constant_cpu_to_le16(rid); |
| 1798 | if (ha->flags.msix_enabled) { |
| 1799 | msix = &ha->msix_entries[1]; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1800 | ql_dbg(ql_dbg_init, vha, 0x00fd, |
| 1801 | "Registering vector 0x%x for base que.\n", |
| 1802 | msix->entry); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1803 | icb->msix = cpu_to_le16(msix->entry); |
| 1804 | } |
| 1805 | /* Use alternate PCI bus number */ |
| 1806 | if (MSB(rid)) |
| 1807 | icb->firmware_options_2 |= |
| 1808 | __constant_cpu_to_le32(BIT_19); |
| 1809 | /* Use alternate PCI devfn */ |
| 1810 | if (LSB(rid)) |
| 1811 | icb->firmware_options_2 |= |
| 1812 | __constant_cpu_to_le32(BIT_18); |
| 1813 | |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 1814 | /* Use Disable MSIX Handshake mode for capable adapters */ |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1815 | if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) && |
| 1816 | (ha->flags.msix_enabled)) { |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 1817 | icb->firmware_options_2 &= |
| 1818 | __constant_cpu_to_le32(~BIT_22); |
| 1819 | ha->flags.disable_msix_handshake = 1; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1820 | ql_dbg(ql_dbg_init, vha, 0x00fe, |
| 1821 | "MSIX Handshake Disable Mode turned on.\n"); |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 1822 | } else { |
| 1823 | icb->firmware_options_2 |= |
| 1824 | __constant_cpu_to_le32(BIT_22); |
| 1825 | } |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1826 | icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1827 | |
| 1828 | WRT_REG_DWORD(®->isp25mq.req_q_in, 0); |
| 1829 | WRT_REG_DWORD(®->isp25mq.req_q_out, 0); |
| 1830 | WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0); |
| 1831 | WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0); |
| 1832 | } else { |
| 1833 | WRT_REG_DWORD(®->isp24.req_q_in, 0); |
| 1834 | WRT_REG_DWORD(®->isp24.req_q_out, 0); |
| 1835 | WRT_REG_DWORD(®->isp24.rsp_q_in, 0); |
| 1836 | WRT_REG_DWORD(®->isp24.rsp_q_out, 0); |
| 1837 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1838 | qlt_24xx_config_rings(vha, reg); |
| 1839 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1840 | /* PCI posting */ |
| 1841 | RD_REG_DWORD(&ioreg->hccr); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1842 | } |
| 1843 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | /** |
| 1845 | * qla2x00_init_rings() - Initializes firmware. |
| 1846 | * @ha: HA context |
| 1847 | * |
| 1848 | * Beginning of request ring has initialization control block already built |
| 1849 | * by nvram config routine. |
| 1850 | * |
| 1851 | * Returns 0 on success. |
| 1852 | */ |
| 1853 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1854 | qla2x00_init_rings(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | { |
| 1856 | int rval; |
| 1857 | unsigned long flags = 0; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1858 | int cnt, que; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1859 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1860 | struct req_que *req; |
| 1861 | struct rsp_que *rsp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1862 | struct mid_init_cb_24xx *mid_init_cb = |
| 1863 | (struct mid_init_cb_24xx *) ha->init_cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | |
| 1865 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1866 | |
| 1867 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1868 | for (que = 0; que < ha->max_req_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1869 | req = ha->req_q_map[que]; |
| 1870 | if (!req) |
| 1871 | continue; |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1872 | for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1873 | req->outstanding_cmds[cnt] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1875 | req->current_outstanding_cmd = 1; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1876 | |
| 1877 | /* Initialize firmware. */ |
| 1878 | req->ring_ptr = req->ring; |
| 1879 | req->ring_index = 0; |
| 1880 | req->cnt = req->length; |
| 1881 | } |
| 1882 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1883 | for (que = 0; que < ha->max_rsp_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1884 | rsp = ha->rsp_q_map[que]; |
| 1885 | if (!rsp) |
| 1886 | continue; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1887 | /* Initialize response queue entries */ |
| 1888 | qla2x00_init_response_q_entries(rsp); |
| 1889 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1891 | ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; |
| 1892 | ha->tgt.atio_ring_index = 0; |
| 1893 | /* Initialize ATIO queue entries */ |
| 1894 | qlt_init_atio_q_entries(vha); |
| 1895 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1896 | ha->isp_ops->config_rings(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | |
| 1898 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1899 | |
| 1900 | /* Update any ISP specific firmware options before initialization. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1901 | ha->isp_ops->update_fw_options(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1903 | ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n"); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1904 | |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 1905 | if (ha->flags.npiv_supported) { |
Saurav Kashyap | 45980cc | 2012-08-22 14:21:21 -0400 | [diff] [blame] | 1906 | if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha)) |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 1907 | ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | c48339d | 2008-01-17 09:02:19 -0800 | [diff] [blame] | 1908 | mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports); |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 1909 | } |
| 1910 | |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 1911 | if (IS_FWI2_CAPABLE(ha)) { |
| 1912 | mid_init_cb->options = __constant_cpu_to_le16(BIT_1); |
| 1913 | mid_init_cb->init_cb.execution_throttle = |
| 1914 | cpu_to_le16(ha->fw_xcb_count); |
| 1915 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1916 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1917 | rval = qla2x00_init_firmware(vha, ha->init_cb_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1919 | ql_log(ql_log_fatal, vha, 0x00d2, |
| 1920 | "Init Firmware **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1922 | ql_dbg(ql_dbg_init, vha, 0x00d3, |
| 1923 | "Init Firmware -- success.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1924 | } |
| 1925 | |
| 1926 | return (rval); |
| 1927 | } |
| 1928 | |
| 1929 | /** |
| 1930 | * qla2x00_fw_ready() - Waits for firmware ready. |
| 1931 | * @ha: HA context |
| 1932 | * |
| 1933 | * Returns 0 on success. |
| 1934 | */ |
| 1935 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1936 | qla2x00_fw_ready(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 | { |
| 1938 | int rval; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1939 | unsigned long wtime, mtime, cs84xx_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | uint16_t min_wait; /* Minimum wait time if loop is down */ |
| 1941 | uint16_t wait_time; /* Wait time if loop is coming ready */ |
Andrew Vasquez | 656e891 | 2009-06-03 09:55:29 -0700 | [diff] [blame] | 1942 | uint16_t state[5]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1943 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | |
| 1945 | rval = QLA_SUCCESS; |
| 1946 | |
| 1947 | /* 20 seconds for loop down. */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1948 | min_wait = 20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | |
| 1950 | /* |
| 1951 | * Firmware should take at most one RATOV to login, plus 5 seconds for |
| 1952 | * our own processing. |
| 1953 | */ |
| 1954 | if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) { |
| 1955 | wait_time = min_wait; |
| 1956 | } |
| 1957 | |
| 1958 | /* Min wait time if loop down */ |
| 1959 | mtime = jiffies + (min_wait * HZ); |
| 1960 | |
| 1961 | /* wait time before firmware ready */ |
| 1962 | wtime = jiffies + (wait_time * HZ); |
| 1963 | |
| 1964 | /* Wait for ISP to finish LIP */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1965 | if (!vha->flags.init_done) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1966 | ql_log(ql_log_info, vha, 0x801e, |
| 1967 | "Waiting for LIP to complete.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | |
| 1969 | do { |
Andrew Vasquez | 5b93903 | 2012-11-21 02:40:26 -0500 | [diff] [blame] | 1970 | memset(state, -1, sizeof(state)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1971 | rval = qla2x00_get_firmware_state(vha, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | if (rval == QLA_SUCCESS) { |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1973 | if (state[0] < FSTATE_LOSS_OF_SYNC) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1974 | vha->device_flags &= ~DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1975 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1976 | if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1977 | ql_dbg(ql_dbg_taskm, vha, 0x801f, |
| 1978 | "fw_state=%x 84xx=%x.\n", state[0], |
| 1979 | state[2]); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1980 | if ((state[2] & FSTATE_LOGGED_IN) && |
| 1981 | (state[2] & FSTATE_WAITING_FOR_VERIFY)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1982 | ql_dbg(ql_dbg_taskm, vha, 0x8028, |
| 1983 | "Sending verify iocb.\n"); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1984 | |
| 1985 | cs84xx_time = jiffies; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1986 | rval = qla84xx_init_chip(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1987 | if (rval != QLA_SUCCESS) { |
| 1988 | ql_log(ql_log_warn, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1989 | vha, 0x8007, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1990 | "Init chip failed.\n"); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1991 | break; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1992 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1993 | |
| 1994 | /* Add time taken to initialize. */ |
| 1995 | cs84xx_time = jiffies - cs84xx_time; |
| 1996 | wtime += cs84xx_time; |
| 1997 | mtime += cs84xx_time; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1998 | ql_dbg(ql_dbg_taskm, vha, 0x8008, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1999 | "Increasing wait time by %ld. " |
| 2000 | "New time %ld.\n", cs84xx_time, |
| 2001 | wtime); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2002 | } |
| 2003 | } else if (state[0] == FSTATE_READY) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2004 | ql_dbg(ql_dbg_taskm, vha, 0x8037, |
| 2005 | "F/W Ready - OK.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2007 | qla2x00_get_retry_cnt(vha, &ha->retry_count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2008 | &ha->login_timeout, &ha->r_a_tov); |
| 2009 | |
| 2010 | rval = QLA_SUCCESS; |
| 2011 | break; |
| 2012 | } |
| 2013 | |
| 2014 | rval = QLA_FUNCTION_FAILED; |
| 2015 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2016 | if (atomic_read(&vha->loop_down_timer) && |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2017 | state[0] != FSTATE_READY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | /* Loop down. Timeout on min_wait for states |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2019 | * other than Wait for Login. |
| 2020 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | if (time_after_eq(jiffies, mtime)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2022 | ql_log(ql_log_info, vha, 0x8038, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | "Cable is unplugged...\n"); |
| 2024 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2025 | vha->device_flags |= DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 | break; |
| 2027 | } |
| 2028 | } |
| 2029 | } else { |
| 2030 | /* Mailbox cmd failed. Timeout on min_wait. */ |
Santosh Vernekar | cdbb0a4f | 2010-05-28 15:08:25 -0700 | [diff] [blame] | 2031 | if (time_after_eq(jiffies, mtime) || |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 2032 | ha->flags.isp82xx_fw_hung) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | break; |
| 2034 | } |
| 2035 | |
| 2036 | if (time_after_eq(jiffies, wtime)) |
| 2037 | break; |
| 2038 | |
| 2039 | /* Delay for a while */ |
| 2040 | msleep(500); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | } while (1); |
| 2042 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2043 | ql_dbg(ql_dbg_taskm, vha, 0x803a, |
| 2044 | "fw_state=%x (%x, %x, %x, %x) " "curr time=%lx.\n", state[0], |
| 2045 | state[1], state[2], state[3], state[4], jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2047 | if (rval && !(vha->device_flags & DFLG_NO_CABLE)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2048 | ql_log(ql_log_warn, vha, 0x803b, |
| 2049 | "Firmware ready **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | } |
| 2051 | |
| 2052 | return (rval); |
| 2053 | } |
| 2054 | |
| 2055 | /* |
| 2056 | * qla2x00_configure_hba |
| 2057 | * Setup adapter context. |
| 2058 | * |
| 2059 | * Input: |
| 2060 | * ha = adapter state pointer. |
| 2061 | * |
| 2062 | * Returns: |
| 2063 | * 0 = success |
| 2064 | * |
| 2065 | * Context: |
| 2066 | * Kernel context. |
| 2067 | */ |
| 2068 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2069 | qla2x00_configure_hba(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | { |
| 2071 | int rval; |
| 2072 | uint16_t loop_id; |
| 2073 | uint16_t topo; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2074 | uint16_t sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | uint8_t al_pa; |
| 2076 | uint8_t area; |
| 2077 | uint8_t domain; |
| 2078 | char connect_type[22]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2079 | struct qla_hw_data *ha = vha->hw; |
Jiri Kosina | f24b5cb | 2012-10-08 09:23:54 +0200 | [diff] [blame] | 2080 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | |
| 2082 | /* Get host addresses. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2083 | rval = qla2x00_get_adapter_id(vha, |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2084 | &loop_id, &al_pa, &area, &domain, &topo, &sw_cap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | if (rval != QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2086 | if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) || |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2087 | IS_CNA_CAPABLE(ha) || |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 2088 | (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2089 | ql_dbg(ql_dbg_disc, vha, 0x2008, |
| 2090 | "Loop is in a transition state.\n"); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 2091 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2092 | ql_log(ql_log_warn, vha, 0x2009, |
| 2093 | "Unable to get host loop ID.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2094 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 2095 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | return (rval); |
| 2097 | } |
| 2098 | |
| 2099 | if (topo == 4) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2100 | ql_log(ql_log_info, vha, 0x200a, |
| 2101 | "Cannot get topology - retrying.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | return (QLA_FUNCTION_FAILED); |
| 2103 | } |
| 2104 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2105 | vha->loop_id = loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2106 | |
| 2107 | /* initialize */ |
| 2108 | ha->min_external_loopid = SNS_FIRST_LOOP_ID; |
| 2109 | ha->operating_mode = LOOP; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2110 | ha->switch_cap = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | |
| 2112 | switch (topo) { |
| 2113 | case 0: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2114 | ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | ha->current_topology = ISP_CFG_NL; |
| 2116 | strcpy(connect_type, "(Loop)"); |
| 2117 | break; |
| 2118 | |
| 2119 | case 1: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2120 | ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n"); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2121 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | ha->current_topology = ISP_CFG_FL; |
| 2123 | strcpy(connect_type, "(FL_Port)"); |
| 2124 | break; |
| 2125 | |
| 2126 | case 2: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2127 | 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] | 2128 | ha->operating_mode = P2P; |
| 2129 | ha->current_topology = ISP_CFG_N; |
| 2130 | strcpy(connect_type, "(N_Port-to-N_Port)"); |
| 2131 | break; |
| 2132 | |
| 2133 | case 3: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2134 | 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] | 2135 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2136 | ha->operating_mode = P2P; |
| 2137 | ha->current_topology = ISP_CFG_F; |
| 2138 | strcpy(connect_type, "(F_Port)"); |
| 2139 | break; |
| 2140 | |
| 2141 | default: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2142 | ql_dbg(ql_dbg_disc, vha, 0x200f, |
| 2143 | "HBA in unknown topology %x, using NL.\n", topo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2144 | ha->current_topology = ISP_CFG_NL; |
| 2145 | strcpy(connect_type, "(Loop)"); |
| 2146 | break; |
| 2147 | } |
| 2148 | |
| 2149 | /* Save Host port and loop ID. */ |
| 2150 | /* byte order - Big Endian */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2151 | vha->d_id.b.domain = domain; |
| 2152 | vha->d_id.b.area = area; |
| 2153 | vha->d_id.b.al_pa = al_pa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2154 | |
Jiri Kosina | f24b5cb | 2012-10-08 09:23:54 +0200 | [diff] [blame] | 2155 | spin_lock_irqsave(&ha->vport_slock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2156 | qlt_update_vp_map(vha, SET_AL_PA); |
Jiri Kosina | f24b5cb | 2012-10-08 09:23:54 +0200 | [diff] [blame] | 2157 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2158 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2159 | if (!vha->flags.init_done) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2160 | ql_log(ql_log_info, vha, 0x2010, |
| 2161 | "Topology - %s, Host Loop address 0x%x.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2162 | connect_type, vha->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | |
| 2164 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2165 | ql_log(ql_log_warn, vha, 0x2011, |
| 2166 | "%s FAILED\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2167 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2168 | ql_dbg(ql_dbg_disc, vha, 0x2012, |
| 2169 | "%s success\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2170 | } |
| 2171 | |
| 2172 | return(rval); |
| 2173 | } |
| 2174 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2175 | inline void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2176 | qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len, |
| 2177 | char *def) |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2178 | { |
| 2179 | char *st, *en; |
| 2180 | uint16_t index; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2181 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | ab67114 | 2009-08-25 11:36:17 -0700 | [diff] [blame] | 2182 | int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) && |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2183 | !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2184 | |
| 2185 | if (memcmp(model, BINZERO, len) != 0) { |
| 2186 | strncpy(ha->model_number, model, len); |
| 2187 | st = en = ha->model_number; |
| 2188 | en += len - 1; |
| 2189 | while (en > st) { |
| 2190 | if (*en != 0x20 && *en != 0x00) |
| 2191 | break; |
| 2192 | *en-- = '\0'; |
| 2193 | } |
| 2194 | |
| 2195 | index = (ha->pdev->subsystem_device & 0xff); |
Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 2196 | if (use_tbl && |
| 2197 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2198 | index < QLA_MODEL_NAMES) |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2199 | strncpy(ha->model_desc, |
| 2200 | qla2x00_model_name[index * 2 + 1], |
| 2201 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2202 | } else { |
| 2203 | index = (ha->pdev->subsystem_device & 0xff); |
Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 2204 | if (use_tbl && |
| 2205 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2206 | index < QLA_MODEL_NAMES) { |
| 2207 | strcpy(ha->model_number, |
| 2208 | qla2x00_model_name[index * 2]); |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2209 | strncpy(ha->model_desc, |
| 2210 | qla2x00_model_name[index * 2 + 1], |
| 2211 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2212 | } else { |
| 2213 | strcpy(ha->model_number, def); |
| 2214 | } |
| 2215 | } |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2216 | if (IS_FWI2_CAPABLE(ha)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2217 | qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc, |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2218 | sizeof(ha->model_desc)); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2219 | } |
| 2220 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2221 | /* On sparc systems, obtain port and node WWN from firmware |
| 2222 | * properties. |
| 2223 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2224 | 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] | 2225 | { |
| 2226 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2227 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2228 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 2229 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 2230 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2231 | int len; |
| 2232 | |
| 2233 | val = of_get_property(dp, "port-wwn", &len); |
| 2234 | if (val && len >= WWN_SIZE) |
| 2235 | memcpy(nv->port_name, val, WWN_SIZE); |
| 2236 | |
| 2237 | val = of_get_property(dp, "node-wwn", &len); |
| 2238 | if (val && len >= WWN_SIZE) |
| 2239 | memcpy(nv->node_name, val, WWN_SIZE); |
| 2240 | #endif |
| 2241 | } |
| 2242 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | /* |
| 2244 | * NVRAM configuration for ISP 2xxx |
| 2245 | * |
| 2246 | * Input: |
| 2247 | * ha = adapter block pointer. |
| 2248 | * |
| 2249 | * Output: |
| 2250 | * initialization control block in response_ring |
| 2251 | * host adapters parameters in host adapter block |
| 2252 | * |
| 2253 | * Returns: |
| 2254 | * 0 = success. |
| 2255 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2256 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2257 | qla2x00_nvram_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2259 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2260 | uint8_t chksum = 0; |
| 2261 | uint16_t cnt; |
| 2262 | uint8_t *dptr1, *dptr2; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2263 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2264 | init_cb_t *icb = ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 2265 | nvram_t *nv = ha->nvram; |
| 2266 | uint8_t *ptr = ha->nvram; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2267 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2269 | rval = QLA_SUCCESS; |
| 2270 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | /* Determine NVRAM starting address. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2272 | ha->nvram_size = sizeof(nvram_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2273 | ha->nvram_base = 0; |
| 2274 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) |
| 2275 | if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1) |
| 2276 | ha->nvram_base = 0x80; |
| 2277 | |
| 2278 | /* Get NVRAM data and calculate checksum. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2279 | 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] | 2280 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++) |
| 2281 | chksum += *ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2282 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2283 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f, |
| 2284 | "Contents of NVRAM.\n"); |
| 2285 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110, |
| 2286 | (uint8_t *)nv, ha->nvram_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2287 | |
| 2288 | /* Bad NVRAM data, set defaults parameters. */ |
| 2289 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || |
| 2290 | nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) { |
| 2291 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2292 | ql_log(ql_log_warn, vha, 0x0064, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 2293 | "Inconsistent NVRAM " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2294 | "detected: checksum=0x%x id=%c version=0x%x.\n", |
| 2295 | chksum, nv->id[0], nv->nvram_version); |
| 2296 | ql_log(ql_log_warn, vha, 0x0065, |
| 2297 | "Falling back to " |
| 2298 | "functioning (yet invalid -- WWPN) defaults.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2299 | |
| 2300 | /* |
| 2301 | * Set default initialization control block. |
| 2302 | */ |
| 2303 | memset(nv, 0, ha->nvram_size); |
| 2304 | nv->parameter_block_version = ICB_VERSION; |
| 2305 | |
| 2306 | if (IS_QLA23XX(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(2048); |
| 2312 | nv->special_options[1] = BIT_7; |
| 2313 | } else if (IS_QLA2200(ha)) { |
| 2314 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 2315 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 2316 | nv->add_firmware_options[0] = BIT_5; |
| 2317 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
| 2318 | nv->frame_payload_size = __constant_cpu_to_le16(1024); |
| 2319 | } else if (IS_QLA2100(ha)) { |
| 2320 | nv->firmware_options[0] = BIT_3 | BIT_1; |
| 2321 | nv->firmware_options[1] = BIT_5; |
| 2322 | nv->frame_payload_size = __constant_cpu_to_le16(1024); |
| 2323 | } |
| 2324 | |
| 2325 | nv->max_iocb_allocation = __constant_cpu_to_le16(256); |
| 2326 | nv->execution_throttle = __constant_cpu_to_le16(16); |
| 2327 | nv->retry_count = 8; |
| 2328 | nv->retry_delay = 1; |
| 2329 | |
| 2330 | nv->port_name[0] = 33; |
| 2331 | nv->port_name[3] = 224; |
| 2332 | nv->port_name[4] = 139; |
| 2333 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2334 | qla2xxx_nvram_wwn_from_ofw(vha, nv); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2335 | |
| 2336 | nv->login_timeout = 4; |
| 2337 | |
| 2338 | /* |
| 2339 | * Set default host adapter parameters |
| 2340 | */ |
| 2341 | nv->host_p[1] = BIT_2; |
| 2342 | nv->reset_delay = 5; |
| 2343 | nv->port_down_retry_count = 8; |
| 2344 | nv->max_luns_per_target = __constant_cpu_to_le16(8); |
| 2345 | nv->link_down_timeout = 60; |
| 2346 | |
| 2347 | rval = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2348 | } |
| 2349 | |
| 2350 | #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2) |
| 2351 | /* |
| 2352 | * The SN2 does not provide BIOS emulation which means you can't change |
| 2353 | * potentially bogus BIOS settings. Force the use of default settings |
| 2354 | * for link rate and frame size. Hope that the rest of the settings |
| 2355 | * are valid. |
| 2356 | */ |
| 2357 | if (ia64_platform_is("sn2")) { |
| 2358 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 2359 | if (IS_QLA23XX(ha)) |
| 2360 | nv->special_options[1] = BIT_7; |
| 2361 | } |
| 2362 | #endif |
| 2363 | |
| 2364 | /* Reset Initialization control block */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2365 | memset(icb, 0, ha->init_cb_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2366 | |
| 2367 | /* |
| 2368 | * Setup driver NVRAM options. |
| 2369 | */ |
| 2370 | nv->firmware_options[0] |= (BIT_6 | BIT_1); |
| 2371 | nv->firmware_options[0] &= ~(BIT_5 | BIT_4); |
| 2372 | nv->firmware_options[1] |= (BIT_5 | BIT_0); |
| 2373 | nv->firmware_options[1] &= ~BIT_4; |
| 2374 | |
| 2375 | if (IS_QLA23XX(ha)) { |
| 2376 | nv->firmware_options[0] |= BIT_2; |
| 2377 | nv->firmware_options[0] &= ~BIT_3; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2378 | nv->special_options[0] &= ~BIT_6; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2379 | nv->add_firmware_options[1] |= BIT_5 | BIT_4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2380 | |
| 2381 | if (IS_QLA2300(ha)) { |
| 2382 | if (ha->fb_rev == FPM_2310) { |
| 2383 | strcpy(ha->model_number, "QLA2310"); |
| 2384 | } else { |
| 2385 | strcpy(ha->model_number, "QLA2300"); |
| 2386 | } |
| 2387 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2388 | qla2x00_set_model_info(vha, nv->model_number, |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2389 | sizeof(nv->model_number), "QLA23xx"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | } |
| 2391 | } else if (IS_QLA2200(ha)) { |
| 2392 | nv->firmware_options[0] |= BIT_2; |
| 2393 | /* |
| 2394 | * 'Point-to-point preferred, else loop' is not a safe |
| 2395 | * connection mode setting. |
| 2396 | */ |
| 2397 | if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) == |
| 2398 | (BIT_5 | BIT_4)) { |
| 2399 | /* Force 'loop preferred, else point-to-point'. */ |
| 2400 | nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4); |
| 2401 | nv->add_firmware_options[0] |= BIT_5; |
| 2402 | } |
| 2403 | strcpy(ha->model_number, "QLA22xx"); |
| 2404 | } else /*if (IS_QLA2100(ha))*/ { |
| 2405 | strcpy(ha->model_number, "QLA2100"); |
| 2406 | } |
| 2407 | |
| 2408 | /* |
| 2409 | * Copy over NVRAM RISC parameter block to initialization control block. |
| 2410 | */ |
| 2411 | dptr1 = (uint8_t *)icb; |
| 2412 | dptr2 = (uint8_t *)&nv->parameter_block_version; |
| 2413 | cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version; |
| 2414 | while (cnt--) |
| 2415 | *dptr1++ = *dptr2++; |
| 2416 | |
| 2417 | /* Copy 2nd half. */ |
| 2418 | dptr1 = (uint8_t *)icb->add_firmware_options; |
| 2419 | cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options; |
| 2420 | while (cnt--) |
| 2421 | *dptr1++ = *dptr2++; |
| 2422 | |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 2423 | /* Use alternate WWN? */ |
| 2424 | if (nv->host_p[1] & BIT_7) { |
| 2425 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 2426 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 2427 | } |
| 2428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2429 | /* Prepare nodename */ |
| 2430 | if ((icb->firmware_options[1] & BIT_6) == 0) { |
| 2431 | /* |
| 2432 | * Firmware will apply the following mask if the nodename was |
| 2433 | * not provided. |
| 2434 | */ |
| 2435 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 2436 | icb->node_name[0] &= 0xF0; |
| 2437 | } |
| 2438 | |
| 2439 | /* |
| 2440 | * Set host adapter parameters. |
| 2441 | */ |
Saurav Kashyap | 3ce8866 | 2011-07-14 12:00:12 -0700 | [diff] [blame] | 2442 | |
| 2443 | /* |
| 2444 | * BIT_7 in the host-parameters section allows for modification to |
| 2445 | * internal driver logging. |
| 2446 | */ |
Andrew Vasquez | 0181944 | 2006-06-23 16:11:10 -0700 | [diff] [blame] | 2447 | if (nv->host_p[0] & BIT_7) |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2448 | ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2449 | ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0); |
| 2450 | /* Always load RISC code on non ISP2[12]00 chips. */ |
| 2451 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) |
| 2452 | ha->flags.disable_risc_code_load = 0; |
| 2453 | ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0); |
| 2454 | ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0); |
| 2455 | 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] | 2456 | 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] | 2457 | ha->flags.disable_serdes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2458 | |
| 2459 | ha->operating_mode = |
| 2460 | (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 2461 | |
| 2462 | memcpy(ha->fw_seriallink_options, nv->seriallink_options, |
| 2463 | sizeof(ha->fw_seriallink_options)); |
| 2464 | |
| 2465 | /* save HBA serial number */ |
| 2466 | ha->serial0 = icb->port_name[5]; |
| 2467 | ha->serial1 = icb->port_name[6]; |
| 2468 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2469 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 2470 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2471 | |
| 2472 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 2473 | |
| 2474 | ha->retry_count = nv->retry_count; |
| 2475 | |
| 2476 | /* Set minimum login_timeout to 4 seconds. */ |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 2477 | if (nv->login_timeout != ql2xlogintimeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 | nv->login_timeout = ql2xlogintimeout; |
| 2479 | if (nv->login_timeout < 4) |
| 2480 | nv->login_timeout = 4; |
| 2481 | ha->login_timeout = nv->login_timeout; |
| 2482 | icb->login_timeout = nv->login_timeout; |
| 2483 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 2484 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 2485 | ha->r_a_tov = 100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2486 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2487 | ha->loop_reset_delay = nv->reset_delay; |
| 2488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2489 | /* Link Down Timeout = 0: |
| 2490 | * |
| 2491 | * When Port Down timer expires we will start returning |
| 2492 | * I/O's to OS with "DID_NO_CONNECT". |
| 2493 | * |
| 2494 | * Link Down Timeout != 0: |
| 2495 | * |
| 2496 | * The driver waits for the link to come up after link down |
| 2497 | * before returning I/Os to OS with "DID_NO_CONNECT". |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2498 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2499 | if (nv->link_down_timeout == 0) { |
| 2500 | ha->loop_down_abort_time = |
Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 2501 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2502 | } else { |
| 2503 | ha->link_down_timeout = nv->link_down_timeout; |
| 2504 | ha->loop_down_abort_time = |
| 2505 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2506 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2507 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2508 | /* |
| 2509 | * Need enough time to try and get the port back. |
| 2510 | */ |
| 2511 | ha->port_down_retry_count = nv->port_down_retry_count; |
| 2512 | if (qlport_down_retry) |
| 2513 | ha->port_down_retry_count = qlport_down_retry; |
| 2514 | /* Set login_retry_count */ |
| 2515 | ha->login_retry_count = nv->retry_count; |
| 2516 | if (ha->port_down_retry_count == nv->port_down_retry_count && |
| 2517 | ha->port_down_retry_count > 3) |
| 2518 | ha->login_retry_count = ha->port_down_retry_count; |
| 2519 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 2520 | ha->login_retry_count = ha->port_down_retry_count; |
| 2521 | if (ql2xloginretrycount) |
| 2522 | ha->login_retry_count = ql2xloginretrycount; |
| 2523 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | icb->lun_enables = __constant_cpu_to_le16(0); |
| 2525 | icb->command_resource_count = 0; |
| 2526 | icb->immediate_notify_resource_count = 0; |
| 2527 | icb->timeout = __constant_cpu_to_le16(0); |
| 2528 | |
| 2529 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 2530 | /* Enable RIO */ |
| 2531 | icb->firmware_options[0] &= ~BIT_3; |
| 2532 | icb->add_firmware_options[0] &= |
| 2533 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 2534 | icb->add_firmware_options[0] |= BIT_2; |
| 2535 | icb->response_accumulation_timer = 3; |
| 2536 | icb->interrupt_delay_timer = 5; |
| 2537 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2538 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2539 | } else { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2540 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2541 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2542 | ha->zio_mode = icb->add_firmware_options[0] & |
| 2543 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 2544 | ha->zio_timer = icb->interrupt_delay_timer ? |
| 2545 | icb->interrupt_delay_timer: 2; |
| 2546 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2547 | icb->add_firmware_options[0] &= |
| 2548 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2549 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2550 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 2551 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 2552 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2553 | ql_log(ql_log_info, vha, 0x0068, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2554 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 2555 | ha->zio_mode, ha->zio_timer * 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2556 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2557 | icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode; |
| 2558 | icb->interrupt_delay_timer = (uint8_t)ha->zio_timer; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2559 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2560 | } |
| 2561 | } |
| 2562 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2563 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2564 | ql_log(ql_log_warn, vha, 0x0069, |
| 2565 | "NVRAM configuration failed.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2566 | } |
| 2567 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2568 | } |
| 2569 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2570 | static void |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2571 | qla2x00_rport_del(void *data) |
| 2572 | { |
| 2573 | fc_port_t *fcport = data; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2574 | struct fc_rport *rport; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2575 | scsi_qla_host_t *vha = fcport->vha; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2576 | unsigned long flags; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2577 | |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2578 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2579 | rport = fcport->drport ? fcport->drport: fcport->rport; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2580 | fcport->drport = NULL; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2581 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2582 | if (rport) { |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2583 | fc_remote_port_delete(rport); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2584 | /* |
| 2585 | * Release the target mode FC NEXUS in qla_target.c code |
| 2586 | * if target mod is enabled. |
| 2587 | */ |
| 2588 | qlt_fc_port_deleted(vha, fcport); |
| 2589 | } |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2590 | } |
| 2591 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2592 | /** |
| 2593 | * qla2x00_alloc_fcport() - Allocate a generic fcport. |
| 2594 | * @ha: HA context |
| 2595 | * @flags: allocation flags |
| 2596 | * |
| 2597 | * Returns a pointer to the allocated fcport, or NULL, if none available. |
| 2598 | */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2599 | fc_port_t * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2600 | qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2601 | { |
| 2602 | fc_port_t *fcport; |
| 2603 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2604 | fcport = kzalloc(sizeof(fc_port_t), flags); |
| 2605 | if (!fcport) |
| 2606 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2607 | |
| 2608 | /* Setup fcport template structure. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2609 | fcport->vha = vha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2610 | fcport->port_type = FCT_UNKNOWN; |
| 2611 | fcport->loop_id = FC_NO_LOOP_ID; |
Chad Dupuis | ec426e1 | 2011-03-30 11:46:32 -0700 | [diff] [blame] | 2612 | qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED); |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 2613 | fcport->supported_classes = FC_COS_UNSPECIFIED; |
Joe Carnuccio | c0822b6 | 2012-05-15 14:34:21 -0400 | [diff] [blame] | 2614 | fcport->scan_state = QLA_FCPORT_SCAN_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2615 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2616 | return fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | /* |
| 2620 | * qla2x00_configure_loop |
| 2621 | * Updates Fibre Channel Device Database with what is actually on loop. |
| 2622 | * |
| 2623 | * Input: |
| 2624 | * ha = adapter block pointer. |
| 2625 | * |
| 2626 | * Returns: |
| 2627 | * 0 = success. |
| 2628 | * 1 = error. |
| 2629 | * 2 = database was full and device was not configured. |
| 2630 | */ |
| 2631 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2632 | qla2x00_configure_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2633 | { |
| 2634 | int rval; |
| 2635 | unsigned long flags, save_flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2636 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | rval = QLA_SUCCESS; |
| 2638 | |
| 2639 | /* Get Initiator ID */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2640 | if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) { |
| 2641 | rval = qla2x00_configure_hba(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2642 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2643 | ql_dbg(ql_dbg_disc, vha, 0x2013, |
| 2644 | "Unable to configure HBA.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2645 | return (rval); |
| 2646 | } |
| 2647 | } |
| 2648 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2649 | save_flags = flags = vha->dpc_flags; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2650 | ql_dbg(ql_dbg_disc, vha, 0x2014, |
| 2651 | "Configure loop -- dpc flags = 0x%lx.\n", flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2652 | |
| 2653 | /* |
| 2654 | * If we have both an RSCN and PORT UPDATE pending then handle them |
| 2655 | * both at the same time. |
| 2656 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2657 | clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 2658 | clear_bit(RSCN_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | |
Michael Hernandez | 3064ff3 | 2009-12-15 21:29:44 -0800 | [diff] [blame] | 2660 | qla2x00_get_data_rate(vha); |
| 2661 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2662 | /* Determine what we need to do */ |
| 2663 | if (ha->current_topology == ISP_CFG_FL && |
| 2664 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 2665 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2666 | set_bit(RSCN_UPDATE, &flags); |
| 2667 | |
| 2668 | } else if (ha->current_topology == ISP_CFG_F && |
| 2669 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 2670 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2671 | set_bit(RSCN_UPDATE, &flags); |
| 2672 | clear_bit(LOCAL_LOOP_UPDATE, &flags); |
| 2673 | |
Andrew Vasquez | 21333b4 | 2006-05-17 15:09:56 -0700 | [diff] [blame] | 2674 | } else if (ha->current_topology == ISP_CFG_N) { |
| 2675 | clear_bit(RSCN_UPDATE, &flags); |
| 2676 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2677 | } else if (!vha->flags.online || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2678 | (test_bit(ABORT_ISP_ACTIVE, &flags))) { |
| 2679 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2680 | set_bit(RSCN_UPDATE, &flags); |
| 2681 | set_bit(LOCAL_LOOP_UPDATE, &flags); |
| 2682 | } |
| 2683 | |
| 2684 | if (test_bit(LOCAL_LOOP_UPDATE, &flags)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2685 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
| 2686 | ql_dbg(ql_dbg_disc, vha, 0x2015, |
| 2687 | "Loop resync needed, failing.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2688 | rval = QLA_FUNCTION_FAILED; |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 2689 | } else |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2690 | rval = qla2x00_configure_local_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2691 | } |
| 2692 | |
| 2693 | if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2694 | if (LOOP_TRANSITION(vha)) { |
| 2695 | ql_dbg(ql_dbg_disc, vha, 0x201e, |
| 2696 | "Needs RSCN update and loop transition.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2697 | rval = QLA_FUNCTION_FAILED; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2698 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2699 | else |
| 2700 | rval = qla2x00_configure_fabric(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2701 | } |
| 2702 | |
| 2703 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2704 | if (atomic_read(&vha->loop_down_timer) || |
| 2705 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | rval = QLA_FUNCTION_FAILED; |
| 2707 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2708 | atomic_set(&vha->loop_state, LOOP_READY); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2709 | ql_dbg(ql_dbg_disc, vha, 0x2069, |
| 2710 | "LOOP READY.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2711 | } |
| 2712 | } |
| 2713 | |
| 2714 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2715 | ql_dbg(ql_dbg_disc, vha, 0x206a, |
| 2716 | "%s *** FAILED ***.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2717 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2718 | ql_dbg(ql_dbg_disc, vha, 0x206b, |
| 2719 | "%s: exiting normally.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2720 | } |
| 2721 | |
Bjorn Helgaas | cc3ef7b | 2008-09-11 21:22:51 -0700 | [diff] [blame] | 2722 | /* Restore state if a resync event occurred during processing */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2723 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2724 | if (test_bit(LOCAL_LOOP_UPDATE, &save_flags)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2725 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 2726 | if (test_bit(RSCN_UPDATE, &save_flags)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2727 | set_bit(RSCN_UPDATE, &vha->dpc_flags); |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 2728 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2729 | } |
| 2730 | |
| 2731 | return (rval); |
| 2732 | } |
| 2733 | |
| 2734 | |
| 2735 | |
| 2736 | /* |
| 2737 | * qla2x00_configure_local_loop |
| 2738 | * Updates Fibre Channel Device Database with local loop devices. |
| 2739 | * |
| 2740 | * Input: |
| 2741 | * ha = adapter block pointer. |
| 2742 | * |
| 2743 | * Returns: |
| 2744 | * 0 = success. |
| 2745 | */ |
| 2746 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2747 | qla2x00_configure_local_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2748 | { |
| 2749 | int rval, rval2; |
| 2750 | int found_devs; |
| 2751 | int found; |
| 2752 | fc_port_t *fcport, *new_fcport; |
| 2753 | |
| 2754 | uint16_t index; |
| 2755 | uint16_t entries; |
| 2756 | char *id_iter; |
| 2757 | uint16_t loop_id; |
| 2758 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2759 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2760 | |
| 2761 | found_devs = 0; |
| 2762 | new_fcport = NULL; |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 2763 | entries = MAX_FIBRE_DEVICES_LOOP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2764 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2765 | /* Get list of logged in devices. */ |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 2766 | memset(ha->gid_list, 0, qla2x00_gid_list_size(ha)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2767 | 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] | 2768 | &entries); |
| 2769 | if (rval != QLA_SUCCESS) |
| 2770 | goto cleanup_allocation; |
| 2771 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2772 | ql_dbg(ql_dbg_disc, vha, 0x2017, |
| 2773 | "Entries in ID list (%d).\n", entries); |
| 2774 | ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075, |
| 2775 | (uint8_t *)ha->gid_list, |
| 2776 | entries * sizeof(struct gid_list_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2777 | |
| 2778 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2779 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2781 | ql_log(ql_log_warn, vha, 0x2018, |
| 2782 | "Memory allocation failed for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2783 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 2784 | goto cleanup_allocation; |
| 2785 | } |
| 2786 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 2787 | |
| 2788 | /* |
| 2789 | * Mark local devices that were present with FCF_DEVICE_LOST for now. |
| 2790 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2791 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | if (atomic_read(&fcport->state) == FCS_ONLINE && |
| 2793 | fcport->port_type != FCT_BROADCAST && |
| 2794 | (fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 2795 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2796 | ql_dbg(ql_dbg_disc, vha, 0x2019, |
| 2797 | "Marking port lost loop_id=0x%04x.\n", |
| 2798 | fcport->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | |
Chad Dupuis | ec426e1 | 2011-03-30 11:46:32 -0700 | [diff] [blame] | 2800 | qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2801 | } |
| 2802 | } |
| 2803 | |
| 2804 | /* Add devices to port list. */ |
| 2805 | id_iter = (char *)ha->gid_list; |
| 2806 | for (index = 0; index < entries; index++) { |
| 2807 | domain = ((struct gid_list_info *)id_iter)->domain; |
| 2808 | area = ((struct gid_list_info *)id_iter)->area; |
| 2809 | al_pa = ((struct gid_list_info *)id_iter)->al_pa; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2810 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2811 | loop_id = (uint16_t) |
| 2812 | ((struct gid_list_info *)id_iter)->loop_id_2100; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2813 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2814 | loop_id = le16_to_cpu( |
| 2815 | ((struct gid_list_info *)id_iter)->loop_id); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2816 | id_iter += ha->gid_list_info_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2817 | |
| 2818 | /* Bypass reserved domain fields. */ |
| 2819 | if ((domain & 0xf0) == 0xf0) |
| 2820 | continue; |
| 2821 | |
| 2822 | /* Bypass if not same domain and area of adapter. */ |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 2823 | if (area && domain && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2824 | (area != vha->d_id.b.area || domain != vha->d_id.b.domain)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2825 | continue; |
| 2826 | |
| 2827 | /* Bypass invalid local loop ID. */ |
| 2828 | if (loop_id > LAST_LOCAL_LOOP_ID) |
| 2829 | continue; |
| 2830 | |
Arun Easi | 370d550 | 2012-08-22 14:21:10 -0400 | [diff] [blame] | 2831 | memset(new_fcport, 0, sizeof(fc_port_t)); |
| 2832 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2833 | /* Fill in member data. */ |
| 2834 | new_fcport->d_id.b.domain = domain; |
| 2835 | new_fcport->d_id.b.area = area; |
| 2836 | new_fcport->d_id.b.al_pa = al_pa; |
| 2837 | new_fcport->loop_id = loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2838 | rval2 = qla2x00_get_port_database(vha, new_fcport, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2839 | if (rval2 != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2840 | ql_dbg(ql_dbg_disc, vha, 0x201a, |
| 2841 | "Failed to retrieve fcport information " |
| 2842 | "-- get_port_database=%x, loop_id=0x%04x.\n", |
| 2843 | rval2, new_fcport->loop_id); |
| 2844 | ql_dbg(ql_dbg_disc, vha, 0x201b, |
| 2845 | "Scheduling resync.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2846 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2847 | continue; |
| 2848 | } |
| 2849 | |
| 2850 | /* Check for matching device in port list. */ |
| 2851 | found = 0; |
| 2852 | fcport = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2853 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 2855 | WWN_SIZE)) |
| 2856 | continue; |
| 2857 | |
Shyam Sundar | ddb9b12 | 2009-03-24 09:08:10 -0700 | [diff] [blame] | 2858 | fcport->flags &= ~FCF_FABRIC_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2859 | fcport->loop_id = new_fcport->loop_id; |
| 2860 | fcport->port_type = new_fcport->port_type; |
| 2861 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 2862 | memcpy(fcport->node_name, new_fcport->node_name, |
| 2863 | WWN_SIZE); |
| 2864 | |
| 2865 | found++; |
| 2866 | break; |
| 2867 | } |
| 2868 | |
| 2869 | if (!found) { |
| 2870 | /* New device, add to fcports list. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2871 | list_add_tail(&new_fcport->list, &vha->vp_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | |
| 2873 | /* Allocate a new replacement fcport. */ |
| 2874 | fcport = new_fcport; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2875 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2876 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2877 | ql_log(ql_log_warn, vha, 0x201c, |
| 2878 | "Failed to allocate memory for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2879 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 2880 | goto cleanup_allocation; |
| 2881 | } |
| 2882 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 2883 | } |
| 2884 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2885 | /* Base iIDMA settings on HBA port speed. */ |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 2886 | fcport->fp_speed = ha->link_data_rate; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2887 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2888 | qla2x00_update_fcport(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | |
| 2890 | found_devs++; |
| 2891 | } |
| 2892 | |
| 2893 | cleanup_allocation: |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2894 | kfree(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2895 | |
| 2896 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2897 | ql_dbg(ql_dbg_disc, vha, 0x201d, |
| 2898 | "Configure local loop error exit: rval=%x.\n", rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2899 | } |
| 2900 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2901 | return (rval); |
| 2902 | } |
| 2903 | |
| 2904 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2905 | qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2906 | { |
Andrew Vasquez | 9f8fdde | 2009-06-03 09:55:22 -0700 | [diff] [blame] | 2907 | char *link_speed; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2908 | int rval; |
Harish Zunjarrao | 1bb3954 | 2009-06-17 10:30:29 -0700 | [diff] [blame] | 2909 | uint16_t mb[4]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2910 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2911 | |
Andrew Vasquez | c76f2c0 | 2007-07-19 15:05:57 -0700 | [diff] [blame] | 2912 | if (!IS_IIDMA_CAPABLE(ha)) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2913 | return; |
| 2914 | |
Giridhar Malavali | c9afb9a | 2010-09-03 15:20:48 -0700 | [diff] [blame] | 2915 | if (atomic_read(&fcport->state) != FCS_ONLINE) |
| 2916 | return; |
| 2917 | |
Andrew Vasquez | 39bd962 | 2007-09-20 14:07:34 -0700 | [diff] [blame] | 2918 | if (fcport->fp_speed == PORT_SPEED_UNKNOWN || |
| 2919 | fcport->fp_speed > ha->link_data_rate) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2920 | return; |
| 2921 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2922 | rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed, |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 2923 | mb); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2924 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2925 | ql_dbg(ql_dbg_disc, vha, 0x2004, |
| 2926 | "Unable to adjust iIDMA " |
| 2927 | "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x " |
| 2928 | "%04x.\n", fcport->port_name[0], fcport->port_name[1], |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2929 | fcport->port_name[2], fcport->port_name[3], |
| 2930 | fcport->port_name[4], fcport->port_name[5], |
| 2931 | fcport->port_name[6], fcport->port_name[7], rval, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2932 | fcport->fp_speed, mb[0], mb[1]); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2933 | } else { |
Chad Dupuis | daae62a | 2012-05-15 14:34:23 -0400 | [diff] [blame] | 2934 | link_speed = qla2x00_get_link_speed_str(ha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2935 | ql_dbg(ql_dbg_disc, vha, 0x2005, |
| 2936 | "iIDMA adjusted to %s GB/s " |
| 2937 | "on %02x%02x%02x%02x%02x%02x%02x%02x.\n", link_speed, |
| 2938 | fcport->port_name[0], fcport->port_name[1], |
| 2939 | fcport->port_name[2], fcport->port_name[3], |
| 2940 | fcport->port_name[4], fcport->port_name[5], |
| 2941 | fcport->port_name[6], fcport->port_name[7]); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2942 | } |
| 2943 | } |
| 2944 | |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2945 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2946 | qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2947 | { |
| 2948 | struct fc_rport_identifiers rport_ids; |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 2949 | struct fc_rport *rport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2950 | unsigned long flags; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2951 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2952 | qla2x00_rport_del(fcport); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2953 | |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 2954 | rport_ids.node_name = wwn_to_u64(fcport->node_name); |
| 2955 | rport_ids.port_name = wwn_to_u64(fcport->port_name); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2956 | rport_ids.port_id = fcport->d_id.b.domain << 16 | |
| 2957 | fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa; |
| 2958 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2959 | fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 2960 | if (!rport) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2961 | ql_log(ql_log_warn, vha, 0x2006, |
| 2962 | "Unable to allocate fc remote port.\n"); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 2963 | return; |
| 2964 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2965 | /* |
| 2966 | * Create target mode FC NEXUS in qla_target.c if target mode is |
| 2967 | * enabled.. |
| 2968 | */ |
| 2969 | qlt_fc_port_added(vha, fcport); |
| 2970 | |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2971 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2972 | *((fc_port_t **)rport->dd_data) = fcport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2973 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2974 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 2975 | rport->supported_classes = fcport->supported_classes; |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 2976 | |
| 2977 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2978 | if (fcport->port_type == FCT_INITIATOR) |
| 2979 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 2980 | if (fcport->port_type == FCT_TARGET) |
| 2981 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 2982 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2983 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2984 | |
| 2985 | /* |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2986 | * qla2x00_update_fcport |
| 2987 | * Updates device on list. |
| 2988 | * |
| 2989 | * Input: |
| 2990 | * ha = adapter block pointer. |
| 2991 | * fcport = port structure pointer. |
| 2992 | * |
| 2993 | * Return: |
| 2994 | * 0 - Success |
| 2995 | * BIT_0 - error |
| 2996 | * |
| 2997 | * Context: |
| 2998 | * Kernel context. |
| 2999 | */ |
| 3000 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3001 | qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
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 | fcport->vha = vha; |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 3004 | fcport->login_retry = 0; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 3005 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 3006 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3007 | qla2x00_iidma_fcport(vha, fcport); |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 3008 | qla24xx_update_fcport_fcp_prio(vha, fcport); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3009 | qla2x00_reg_remote_port(vha, fcport); |
Chad Dupuis | ec426e1 | 2011-03-30 11:46:32 -0700 | [diff] [blame] | 3010 | qla2x00_set_fcport_state(fcport, FCS_ONLINE); |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 3011 | } |
| 3012 | |
| 3013 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3014 | * qla2x00_configure_fabric |
| 3015 | * Setup SNS devices with loop ID's. |
| 3016 | * |
| 3017 | * Input: |
| 3018 | * ha = adapter block pointer. |
| 3019 | * |
| 3020 | * Returns: |
| 3021 | * 0 = success. |
| 3022 | * BIT_0 = error |
| 3023 | */ |
| 3024 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3025 | qla2x00_configure_fabric(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3026 | { |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 3027 | int rval; |
Joe Carnuccio | 4dc77c3 | 2012-05-15 14:34:24 -0400 | [diff] [blame] | 3028 | fc_port_t *fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3029 | uint16_t next_loopid; |
| 3030 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3031 | uint16_t loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | LIST_HEAD(new_fcports); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3033 | struct qla_hw_data *ha = vha->hw; |
| 3034 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3035 | |
| 3036 | /* If FL port exists, then SNS is present */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 3037 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3038 | loop_id = NPH_F_PORT; |
| 3039 | else |
| 3040 | loop_id = SNS_FL_PORT; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3041 | 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] | 3042 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3043 | ql_dbg(ql_dbg_disc, vha, 0x201f, |
| 3044 | "MBX_GET_PORT_NAME failed, No FL Port.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3045 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3046 | vha->device_flags &= ~SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3047 | return (QLA_SUCCESS); |
| 3048 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3049 | vha->device_flags |= SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3050 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3051 | do { |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 3052 | /* FDMI support. */ |
| 3053 | if (ql2xfdmienable && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3054 | test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags)) |
| 3055 | qla2x00_fdmi_register(vha); |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 3056 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3057 | /* Ensure we are logged into the SNS. */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 3058 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3059 | loop_id = NPH_SNS; |
| 3060 | else |
| 3061 | loop_id = SIMPLE_NAME_SERVER; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 3062 | rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff, |
| 3063 | 0xfc, mb, BIT_1|BIT_0); |
| 3064 | if (rval != QLA_SUCCESS) { |
| 3065 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Joe Carnuccio | 4dc77c3 | 2012-05-15 14:34:24 -0400 | [diff] [blame] | 3066 | break; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 3067 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3068 | if (mb[0] != MBS_COMMAND_COMPLETE) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3069 | ql_dbg(ql_dbg_disc, vha, 0x2042, |
| 3070 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x " |
| 3071 | "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1], |
| 3072 | mb[2], mb[6], mb[7]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3073 | return (QLA_SUCCESS); |
| 3074 | } |
| 3075 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3076 | if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) { |
| 3077 | if (qla2x00_rft_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3078 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3079 | ql_dbg(ql_dbg_disc, vha, 0x2045, |
| 3080 | "Register FC-4 TYPE failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3081 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3082 | if (qla2x00_rff_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3083 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3084 | ql_dbg(ql_dbg_disc, vha, 0x2049, |
| 3085 | "Register FC-4 Features failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3086 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3087 | if (qla2x00_rnn_id(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, 0x204f, |
| 3090 | "Register Node Name failed.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3091 | } else if (qla2x00_rsnn_nn(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3092 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3093 | ql_dbg(ql_dbg_disc, vha, 0x2053, |
| 3094 | "Register Symobilic Node Name failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3095 | } |
| 3096 | } |
| 3097 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3098 | rval = qla2x00_find_all_fabric_devs(vha, &new_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3099 | if (rval != QLA_SUCCESS) |
| 3100 | break; |
| 3101 | |
Joe Carnuccio | 4dc77c3 | 2012-05-15 14:34:24 -0400 | [diff] [blame] | 3102 | /* Add new ports to existing port list */ |
| 3103 | list_splice_tail_init(&new_fcports, &vha->vp_fcports); |
| 3104 | |
| 3105 | /* Starting free loop ID. */ |
| 3106 | next_loopid = ha->min_external_loopid; |
| 3107 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3108 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 3109 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | break; |
| 3111 | |
| 3112 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) |
| 3113 | continue; |
| 3114 | |
Joe Carnuccio | 4dc77c3 | 2012-05-15 14:34:24 -0400 | [diff] [blame] | 3115 | /* Logout lost/gone fabric devices (non-FCP2) */ |
Joe Carnuccio | c0822b6 | 2012-05-15 14:34:21 -0400 | [diff] [blame] | 3116 | if (fcport->scan_state != QLA_FCPORT_SCAN_FOUND && |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 3117 | atomic_read(&fcport->state) == FCS_ONLINE) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3118 | qla2x00_mark_device_lost(vha, fcport, |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3119 | ql2xplogiabsentdevice, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3120 | if (fcport->loop_id != FC_NO_LOOP_ID && |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3121 | (fcport->flags & FCF_FCP2_DEVICE) == 0 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3122 | fcport->port_type != FCT_INITIATOR && |
| 3123 | fcport->port_type != FCT_BROADCAST) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3124 | ha->isp_ops->fabric_logout(vha, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3125 | fcport->loop_id, |
| 3126 | fcport->d_id.b.domain, |
| 3127 | fcport->d_id.b.area, |
| 3128 | fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3129 | } |
Joe Carnuccio | c0822b6 | 2012-05-15 14:34:21 -0400 | [diff] [blame] | 3130 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3131 | } |
Joe Carnuccio | c0822b6 | 2012-05-15 14:34:21 -0400 | [diff] [blame] | 3132 | fcport->scan_state = QLA_FCPORT_SCAN_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3133 | |
Joe Carnuccio | 4dc77c3 | 2012-05-15 14:34:24 -0400 | [diff] [blame] | 3134 | /* Login fabric devices that need a login */ |
| 3135 | if ((fcport->flags & FCF_LOGIN_NEEDED) != 0 && |
| 3136 | atomic_read(&vha->loop_down_timer) == 0) { |
| 3137 | if (fcport->loop_id == FC_NO_LOOP_ID) { |
| 3138 | fcport->loop_id = next_loopid; |
| 3139 | rval = qla2x00_find_new_loop_id( |
| 3140 | base_vha, fcport); |
| 3141 | if (rval != QLA_SUCCESS) { |
| 3142 | /* Ran out of IDs to use */ |
| 3143 | continue; |
| 3144 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3145 | } |
| 3146 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3147 | |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 3148 | /* Login and update database */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3149 | qla2x00_fabric_dev_login(vha, fcport, &next_loopid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3150 | } |
| 3151 | } while (0); |
| 3152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3153 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3154 | ql_dbg(ql_dbg_disc, vha, 0x2068, |
| 3155 | "Configure fabric error exit rval=%d.\n", rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3156 | } |
| 3157 | |
| 3158 | return (rval); |
| 3159 | } |
| 3160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | /* |
| 3162 | * qla2x00_find_all_fabric_devs |
| 3163 | * |
| 3164 | * Input: |
| 3165 | * ha = adapter block pointer. |
| 3166 | * dev = database device entry pointer. |
| 3167 | * |
| 3168 | * Returns: |
| 3169 | * 0 = success. |
| 3170 | * |
| 3171 | * Context: |
| 3172 | * Kernel context. |
| 3173 | */ |
| 3174 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3175 | qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha, |
| 3176 | struct list_head *new_fcports) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3177 | { |
| 3178 | int rval; |
| 3179 | uint16_t loop_id; |
| 3180 | fc_port_t *fcport, *new_fcport, *fcptemp; |
| 3181 | int found; |
| 3182 | |
| 3183 | sw_info_t *swl; |
| 3184 | int swl_idx; |
| 3185 | int first_dev, last_dev; |
Mike Waychison | 1516ef4 | 2010-05-04 15:01:31 -0700 | [diff] [blame] | 3186 | port_id_t wrap = {}, nxt_d_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3187 | struct qla_hw_data *ha = vha->hw; |
| 3188 | struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev); |
Anirban Chakraborty | ee546b6 | 2009-03-05 11:07:02 -0800 | [diff] [blame] | 3189 | struct scsi_qla_host *tvp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3190 | |
| 3191 | rval = QLA_SUCCESS; |
| 3192 | |
| 3193 | /* Try GID_PT to get device list, else GAN. */ |
Andrew Vasquez | 7a67735 | 2012-02-09 11:15:56 -0800 | [diff] [blame] | 3194 | if (!ha->swl) |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 3195 | ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t), |
Andrew Vasquez | 7a67735 | 2012-02-09 11:15:56 -0800 | [diff] [blame] | 3196 | GFP_KERNEL); |
| 3197 | swl = ha->swl; |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 3198 | if (!swl) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3199 | /*EMPTY*/ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3200 | ql_dbg(ql_dbg_disc, vha, 0x2054, |
| 3201 | "GID_PT allocations failed, fallback on GA_NXT.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3202 | } else { |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 3203 | memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3204 | if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3205 | swl = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3206 | } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3207 | swl = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3208 | } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | swl = NULL; |
Andrew Vasquez | e5896bd | 2008-07-10 16:55:52 -0700 | [diff] [blame] | 3210 | } else if (ql2xiidmaenable && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3211 | qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) { |
| 3212 | qla2x00_gpsc(vha, swl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | } |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3214 | |
| 3215 | /* If other queries succeeded probe for FC-4 type */ |
| 3216 | if (swl) |
| 3217 | qla2x00_gff_id(vha, swl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3218 | } |
| 3219 | swl_idx = 0; |
| 3220 | |
| 3221 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3222 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3223 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3224 | ql_log(ql_log_warn, vha, 0x205e, |
| 3225 | "Failed to allocate memory for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | return (QLA_MEMORY_ALLOC_FAILED); |
| 3227 | } |
| 3228 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | /* Set start port ID scan at adapter ID. */ |
| 3230 | first_dev = 1; |
| 3231 | last_dev = 0; |
| 3232 | |
| 3233 | /* Starting free loop ID. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3234 | loop_id = ha->min_external_loopid; |
| 3235 | for (; loop_id <= ha->max_loop_id; loop_id++) { |
| 3236 | if (qla2x00_is_reserved_id(vha, loop_id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3237 | continue; |
| 3238 | |
Giridhar Malavali | 3a6478d | 2010-05-28 15:08:20 -0700 | [diff] [blame] | 3239 | if (ha->current_topology == ISP_CFG_FL && |
| 3240 | (atomic_read(&vha->loop_down_timer) || |
| 3241 | LOOP_TRANSITION(vha))) { |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 3242 | atomic_set(&vha->loop_down_timer, 0); |
| 3243 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 3244 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3245 | break; |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 3246 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | |
| 3248 | if (swl != NULL) { |
| 3249 | if (last_dev) { |
| 3250 | wrap.b24 = new_fcport->d_id.b24; |
| 3251 | } else { |
| 3252 | new_fcport->d_id.b24 = swl[swl_idx].d_id.b24; |
| 3253 | memcpy(new_fcport->node_name, |
| 3254 | swl[swl_idx].node_name, WWN_SIZE); |
| 3255 | memcpy(new_fcport->port_name, |
| 3256 | swl[swl_idx].port_name, WWN_SIZE); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3257 | memcpy(new_fcport->fabric_port_name, |
| 3258 | swl[swl_idx].fabric_port_name, WWN_SIZE); |
| 3259 | new_fcport->fp_speed = swl[swl_idx].fp_speed; |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3260 | new_fcport->fc4_type = swl[swl_idx].fc4_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3261 | |
| 3262 | if (swl[swl_idx].d_id.b.rsvd_1 != 0) { |
| 3263 | last_dev = 1; |
| 3264 | } |
| 3265 | swl_idx++; |
| 3266 | } |
| 3267 | } else { |
| 3268 | /* Send GA_NXT to the switch */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3269 | rval = qla2x00_ga_nxt(vha, new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3271 | ql_log(ql_log_warn, vha, 0x2064, |
| 3272 | "SNS scan failed -- assuming " |
| 3273 | "zero-entry result.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3274 | list_for_each_entry_safe(fcport, fcptemp, |
| 3275 | new_fcports, list) { |
| 3276 | list_del(&fcport->list); |
| 3277 | kfree(fcport); |
| 3278 | } |
| 3279 | rval = QLA_SUCCESS; |
| 3280 | break; |
| 3281 | } |
| 3282 | } |
| 3283 | |
| 3284 | /* If wrap on switch device list, exit. */ |
| 3285 | if (first_dev) { |
| 3286 | wrap.b24 = new_fcport->d_id.b24; |
| 3287 | first_dev = 0; |
| 3288 | } else if (new_fcport->d_id.b24 == wrap.b24) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3289 | ql_dbg(ql_dbg_disc, vha, 0x2065, |
| 3290 | "Device wrap (%02x%02x%02x).\n", |
| 3291 | new_fcport->d_id.b.domain, |
| 3292 | new_fcport->d_id.b.area, |
| 3293 | new_fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3294 | break; |
| 3295 | } |
| 3296 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3297 | /* Bypass if same physical adapter. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3298 | if (new_fcport->d_id.b24 == base_vha->d_id.b24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3299 | continue; |
| 3300 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3301 | /* Bypass virtual ports of the same host. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3302 | found = 0; |
| 3303 | if (ha->num_vhosts) { |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3304 | unsigned long flags; |
| 3305 | |
| 3306 | spin_lock_irqsave(&ha->vport_slock, flags); |
Anirban Chakraborty | ee546b6 | 2009-03-05 11:07:02 -0800 | [diff] [blame] | 3307 | list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3308 | if (new_fcport->d_id.b24 == vp->d_id.b24) { |
| 3309 | found = 1; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3310 | break; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3311 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3312 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3313 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 3314 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3315 | if (found) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3316 | continue; |
| 3317 | } |
| 3318 | |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 3319 | /* Bypass if same domain and area of adapter. */ |
| 3320 | if (((new_fcport->d_id.b24 & 0xffff00) == |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3321 | (vha->d_id.b24 & 0xffff00)) && ha->current_topology == |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 3322 | ISP_CFG_FL) |
| 3323 | continue; |
| 3324 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3325 | /* Bypass reserved domain fields. */ |
| 3326 | if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0) |
| 3327 | continue; |
| 3328 | |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3329 | /* Bypass ports whose FCP-4 type is not FCP_SCSI */ |
Chad Dupuis | 4da26e1 | 2010-10-15 11:27:40 -0700 | [diff] [blame] | 3330 | if (ql2xgffidenable && |
| 3331 | (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI && |
| 3332 | new_fcport->fc4_type != FC4_TYPE_UNKNOWN)) |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3333 | continue; |
| 3334 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3335 | /* Locate matching device in database. */ |
| 3336 | found = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3337 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3338 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 3339 | WWN_SIZE)) |
| 3340 | continue; |
| 3341 | |
Joe Carnuccio | c0822b6 | 2012-05-15 14:34:21 -0400 | [diff] [blame] | 3342 | fcport->scan_state = QLA_FCPORT_SCAN_FOUND; |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 3343 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3344 | found++; |
| 3345 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3346 | /* Update port state. */ |
| 3347 | memcpy(fcport->fabric_port_name, |
| 3348 | new_fcport->fabric_port_name, WWN_SIZE); |
| 3349 | fcport->fp_speed = new_fcport->fp_speed; |
| 3350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3351 | /* |
| 3352 | * If address the same and state FCS_ONLINE, nothing |
| 3353 | * changed. |
| 3354 | */ |
| 3355 | if (fcport->d_id.b24 == new_fcport->d_id.b24 && |
| 3356 | atomic_read(&fcport->state) == FCS_ONLINE) { |
| 3357 | break; |
| 3358 | } |
| 3359 | |
| 3360 | /* |
| 3361 | * If device was not a fabric device before. |
| 3362 | */ |
| 3363 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 3364 | fcport->d_id.b24 = new_fcport->d_id.b24; |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3365 | qla2x00_clear_loop_id(fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3366 | fcport->flags |= (FCF_FABRIC_DEVICE | |
| 3367 | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3368 | break; |
| 3369 | } |
| 3370 | |
| 3371 | /* |
| 3372 | * Port ID changed or device was marked to be updated; |
| 3373 | * Log it out if still logged in and mark it for |
| 3374 | * relogin later. |
| 3375 | */ |
| 3376 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 3377 | fcport->flags |= FCF_LOGIN_NEEDED; |
| 3378 | if (fcport->loop_id != FC_NO_LOOP_ID && |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3379 | (fcport->flags & FCF_FCP2_DEVICE) == 0 && |
Arun Easi | 0eba25d | 2012-02-09 11:15:58 -0800 | [diff] [blame] | 3380 | (fcport->flags & FCF_ASYNC_SENT) == 0 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3381 | fcport->port_type != FCT_INITIATOR && |
| 3382 | fcport->port_type != FCT_BROADCAST) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3383 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3384 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3385 | fcport->d_id.b.al_pa); |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3386 | qla2x00_clear_loop_id(fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3387 | } |
| 3388 | |
| 3389 | break; |
| 3390 | } |
| 3391 | |
| 3392 | if (found) |
| 3393 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3394 | /* If device was not in our fcports list, then add it. */ |
| 3395 | list_add_tail(&new_fcport->list, new_fcports); |
| 3396 | |
| 3397 | /* Allocate a new replacement fcport. */ |
| 3398 | nxt_d_id.b24 = new_fcport->d_id.b24; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3399 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3400 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3401 | ql_log(ql_log_warn, vha, 0x2066, |
| 3402 | "Memory allocation failed for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3403 | return (QLA_MEMORY_ALLOC_FAILED); |
| 3404 | } |
| 3405 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
| 3406 | new_fcport->d_id.b24 = nxt_d_id.b24; |
| 3407 | } |
| 3408 | |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 3409 | kfree(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3410 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3411 | return (rval); |
| 3412 | } |
| 3413 | |
| 3414 | /* |
| 3415 | * qla2x00_find_new_loop_id |
| 3416 | * Scan through our port list and find a new usable loop ID. |
| 3417 | * |
| 3418 | * Input: |
| 3419 | * ha: adapter state pointer. |
| 3420 | * dev: port structure pointer. |
| 3421 | * |
| 3422 | * Returns: |
| 3423 | * qla2x00 local function return status code. |
| 3424 | * |
| 3425 | * Context: |
| 3426 | * Kernel context. |
| 3427 | */ |
Joe Carnuccio | 03bcfb5 | 2011-03-30 11:46:27 -0700 | [diff] [blame] | 3428 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3429 | 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] | 3430 | { |
| 3431 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3432 | struct qla_hw_data *ha = vha->hw; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3433 | unsigned long flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3434 | |
| 3435 | rval = QLA_SUCCESS; |
| 3436 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3437 | spin_lock_irqsave(&ha->vport_slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3438 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3439 | dev->loop_id = find_first_zero_bit(ha->loop_id_map, |
| 3440 | LOOPID_MAP_SIZE); |
| 3441 | if (dev->loop_id >= LOOPID_MAP_SIZE || |
| 3442 | qla2x00_is_reserved_id(vha, dev->loop_id)) { |
| 3443 | dev->loop_id = FC_NO_LOOP_ID; |
| 3444 | rval = QLA_FUNCTION_FAILED; |
| 3445 | } else |
| 3446 | set_bit(dev->loop_id, ha->loop_id_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3447 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3448 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3449 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3450 | if (rval == QLA_SUCCESS) |
| 3451 | ql_dbg(ql_dbg_disc, dev->vha, 0x2086, |
| 3452 | "Assigning new loopid=%x, portid=%x.\n", |
| 3453 | dev->loop_id, dev->d_id.b24); |
| 3454 | else |
| 3455 | ql_log(ql_log_warn, dev->vha, 0x2087, |
| 3456 | "No loop_id's available, portid=%x.\n", |
| 3457 | dev->d_id.b24); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3458 | |
| 3459 | return (rval); |
| 3460 | } |
| 3461 | |
| 3462 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3463 | * qla2x00_fabric_dev_login |
| 3464 | * Login fabric target device and update FC port database. |
| 3465 | * |
| 3466 | * Input: |
| 3467 | * ha: adapter state pointer. |
| 3468 | * fcport: port structure list pointer. |
| 3469 | * next_loopid: contains value of a new loop ID that can be used |
| 3470 | * by the next login attempt. |
| 3471 | * |
| 3472 | * Returns: |
| 3473 | * qla2x00 local function return status code. |
| 3474 | * |
| 3475 | * Context: |
| 3476 | * Kernel context. |
| 3477 | */ |
| 3478 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3479 | 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] | 3480 | uint16_t *next_loopid) |
| 3481 | { |
| 3482 | int rval; |
| 3483 | int retry; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3484 | uint8_t opts; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3485 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3486 | |
| 3487 | rval = QLA_SUCCESS; |
| 3488 | retry = 0; |
| 3489 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3490 | if (IS_ALOGIO_CAPABLE(ha)) { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 3491 | if (fcport->flags & FCF_ASYNC_SENT) |
| 3492 | return rval; |
| 3493 | fcport->flags |= FCF_ASYNC_SENT; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3494 | rval = qla2x00_post_async_login_work(vha, fcport, NULL); |
| 3495 | if (!rval) |
| 3496 | return rval; |
| 3497 | } |
| 3498 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 3499 | fcport->flags &= ~FCF_ASYNC_SENT; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3500 | rval = qla2x00_fabric_login(vha, fcport, next_loopid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3501 | if (rval == QLA_SUCCESS) { |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3502 | /* Send an ADISC to FCP2 devices.*/ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3503 | opts = 0; |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3504 | if (fcport->flags & FCF_FCP2_DEVICE) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3505 | opts |= BIT_1; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3506 | rval = qla2x00_get_port_database(vha, fcport, opts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3507 | if (rval != QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3508 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3509 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3510 | fcport->d_id.b.al_pa); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3511 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3512 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3513 | qla2x00_update_fcport(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3514 | } |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 3515 | } else { |
| 3516 | /* Retry Login. */ |
| 3517 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3518 | } |
| 3519 | |
| 3520 | return (rval); |
| 3521 | } |
| 3522 | |
| 3523 | /* |
| 3524 | * qla2x00_fabric_login |
| 3525 | * Issue fabric login command. |
| 3526 | * |
| 3527 | * Input: |
| 3528 | * ha = adapter block pointer. |
| 3529 | * device = pointer to FC device type structure. |
| 3530 | * |
| 3531 | * Returns: |
| 3532 | * 0 - Login successfully |
| 3533 | * 1 - Login failed |
| 3534 | * 2 - Initiator device |
| 3535 | * 3 - Fatal error |
| 3536 | */ |
| 3537 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3538 | qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3539 | uint16_t *next_loopid) |
| 3540 | { |
| 3541 | int rval; |
| 3542 | int retry; |
| 3543 | uint16_t tmp_loopid; |
| 3544 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3545 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3546 | |
| 3547 | retry = 0; |
| 3548 | tmp_loopid = 0; |
| 3549 | |
| 3550 | for (;;) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3551 | ql_dbg(ql_dbg_disc, vha, 0x2000, |
| 3552 | "Trying Fabric Login w/loop id 0x%04x for port " |
| 3553 | "%02x%02x%02x.\n", |
| 3554 | fcport->loop_id, fcport->d_id.b.domain, |
| 3555 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3556 | |
| 3557 | /* Login fcport on switch. */ |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 3558 | rval = ha->isp_ops->fabric_login(vha, fcport->loop_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3559 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3560 | fcport->d_id.b.al_pa, mb, BIT_0); |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 3561 | if (rval != QLA_SUCCESS) { |
| 3562 | return rval; |
| 3563 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3564 | if (mb[0] == MBS_PORT_ID_USED) { |
| 3565 | /* |
| 3566 | * Device has another loop ID. The firmware team |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3567 | * recommends the driver perform an implicit login with |
| 3568 | * the specified ID again. The ID we just used is save |
| 3569 | * here so we return with an ID that can be tried by |
| 3570 | * the next login. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3571 | */ |
| 3572 | retry++; |
| 3573 | tmp_loopid = fcport->loop_id; |
| 3574 | fcport->loop_id = mb[1]; |
| 3575 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3576 | ql_dbg(ql_dbg_disc, vha, 0x2001, |
| 3577 | "Fabric Login: port in use - next loop " |
| 3578 | "id=0x%04x, port id= %02x%02x%02x.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3579 | fcport->loop_id, fcport->d_id.b.domain, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3580 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3581 | |
| 3582 | } else if (mb[0] == MBS_COMMAND_COMPLETE) { |
| 3583 | /* |
| 3584 | * Login succeeded. |
| 3585 | */ |
| 3586 | if (retry) { |
| 3587 | /* A retry occurred before. */ |
| 3588 | *next_loopid = tmp_loopid; |
| 3589 | } else { |
| 3590 | /* |
| 3591 | * No retry occurred before. Just increment the |
| 3592 | * ID value for next login. |
| 3593 | */ |
| 3594 | *next_loopid = (fcport->loop_id + 1); |
| 3595 | } |
| 3596 | |
| 3597 | if (mb[1] & BIT_0) { |
| 3598 | fcport->port_type = FCT_INITIATOR; |
| 3599 | } else { |
| 3600 | fcport->port_type = FCT_TARGET; |
| 3601 | if (mb[1] & BIT_1) { |
Santosh Vernekar | 8474f3a | 2009-08-25 11:36:16 -0700 | [diff] [blame] | 3602 | fcport->flags |= FCF_FCP2_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3603 | } |
| 3604 | } |
| 3605 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 3606 | if (mb[10] & BIT_0) |
| 3607 | fcport->supported_classes |= FC_COS_CLASS2; |
| 3608 | if (mb[10] & BIT_1) |
| 3609 | fcport->supported_classes |= FC_COS_CLASS3; |
| 3610 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3611 | if (IS_FWI2_CAPABLE(ha)) { |
| 3612 | if (mb[10] & BIT_7) |
| 3613 | fcport->flags |= |
| 3614 | FCF_CONF_COMP_SUPPORTED; |
| 3615 | } |
| 3616 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3617 | rval = QLA_SUCCESS; |
| 3618 | break; |
| 3619 | } else if (mb[0] == MBS_LOOP_ID_USED) { |
| 3620 | /* |
| 3621 | * Loop ID already used, try next loop ID. |
| 3622 | */ |
| 3623 | fcport->loop_id++; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3624 | rval = qla2x00_find_new_loop_id(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3625 | if (rval != QLA_SUCCESS) { |
| 3626 | /* Ran out of loop IDs to use */ |
| 3627 | break; |
| 3628 | } |
| 3629 | } else if (mb[0] == MBS_COMMAND_ERROR) { |
| 3630 | /* |
| 3631 | * Firmware possibly timed out during login. If NO |
| 3632 | * retries are left to do then the device is declared |
| 3633 | * dead. |
| 3634 | */ |
| 3635 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3636 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3637 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3638 | fcport->d_id.b.al_pa); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3639 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3640 | |
| 3641 | rval = 1; |
| 3642 | break; |
| 3643 | } else { |
| 3644 | /* |
| 3645 | * unrecoverable / not handled error |
| 3646 | */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3647 | ql_dbg(ql_dbg_disc, vha, 0x2002, |
| 3648 | "Failed=%x port_id=%02x%02x%02x loop_id=%x " |
| 3649 | "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain, |
| 3650 | fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 3651 | fcport->loop_id, jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3652 | |
| 3653 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3654 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3655 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3656 | fcport->d_id.b.al_pa); |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3657 | qla2x00_clear_loop_id(fcport); |
Andrew Vasquez | 0eedfcf | 2005-10-27 11:09:38 -0700 | [diff] [blame] | 3658 | fcport->login_retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3659 | |
| 3660 | rval = 3; |
| 3661 | break; |
| 3662 | } |
| 3663 | } |
| 3664 | |
| 3665 | return (rval); |
| 3666 | } |
| 3667 | |
| 3668 | /* |
| 3669 | * qla2x00_local_device_login |
| 3670 | * Issue local device login command. |
| 3671 | * |
| 3672 | * Input: |
| 3673 | * ha = adapter block pointer. |
| 3674 | * loop_id = loop id of device to login to. |
| 3675 | * |
| 3676 | * Returns (Where's the #define!!!!): |
| 3677 | * 0 - Login successfully |
| 3678 | * 1 - Login failed |
| 3679 | * 3 - Fatal error |
| 3680 | */ |
| 3681 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3682 | 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] | 3683 | { |
| 3684 | int rval; |
| 3685 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
| 3686 | |
| 3687 | memset(mb, 0, sizeof(mb)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3688 | rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3689 | if (rval == QLA_SUCCESS) { |
| 3690 | /* Interrogate mailbox registers for any errors */ |
| 3691 | if (mb[0] == MBS_COMMAND_ERROR) |
| 3692 | rval = 1; |
| 3693 | else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR) |
| 3694 | /* device not in PCB table */ |
| 3695 | rval = 3; |
| 3696 | } |
| 3697 | |
| 3698 | return (rval); |
| 3699 | } |
| 3700 | |
| 3701 | /* |
| 3702 | * qla2x00_loop_resync |
| 3703 | * Resync with fibre channel devices. |
| 3704 | * |
| 3705 | * Input: |
| 3706 | * ha = adapter block pointer. |
| 3707 | * |
| 3708 | * Returns: |
| 3709 | * 0 = success |
| 3710 | */ |
| 3711 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3712 | qla2x00_loop_resync(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3713 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3714 | int rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3715 | uint32_t wait_time; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 3716 | struct req_que *req; |
| 3717 | struct rsp_que *rsp; |
| 3718 | |
Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 3719 | if (vha->hw->flags.cpu_affinity_enabled) |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 3720 | req = vha->hw->req_q_map[0]; |
| 3721 | else |
| 3722 | req = vha->req; |
| 3723 | rsp = req->rsp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3724 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3725 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 3726 | if (vha->flags.online) { |
| 3727 | if (!(rval = qla2x00_fw_ready(vha))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3728 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 3729 | wait_time = 256; |
| 3730 | do { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3731 | /* Issue a marker after FW becomes ready. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3732 | qla2x00_marker(vha, req, rsp, 0, 0, |
| 3733 | MK_SYNC_ALL); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3734 | vha->marker_needed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3735 | |
| 3736 | /* Remap devices on Loop. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3737 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3738 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3739 | qla2x00_configure_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3740 | wait_time--; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3741 | } while (!atomic_read(&vha->loop_down_timer) && |
| 3742 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
| 3743 | && wait_time && (test_bit(LOOP_RESYNC_NEEDED, |
| 3744 | &vha->dpc_flags))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3745 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3746 | } |
| 3747 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3748 | if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3749 | return (QLA_FUNCTION_FAILED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3750 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3751 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3752 | ql_dbg(ql_dbg_disc, vha, 0x206c, |
| 3753 | "%s *** FAILED ***.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3754 | |
| 3755 | return (rval); |
| 3756 | } |
| 3757 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 3758 | /* |
| 3759 | * qla2x00_perform_loop_resync |
| 3760 | * Description: This function will set the appropriate flags and call |
| 3761 | * qla2x00_loop_resync. If successful loop will be resynced |
| 3762 | * Arguments : scsi_qla_host_t pointer |
| 3763 | * returm : Success or Failure |
| 3764 | */ |
| 3765 | |
| 3766 | int qla2x00_perform_loop_resync(scsi_qla_host_t *ha) |
| 3767 | { |
| 3768 | int32_t rval = 0; |
| 3769 | |
| 3770 | if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) { |
| 3771 | /*Configure the flags so that resync happens properly*/ |
| 3772 | atomic_set(&ha->loop_down_timer, 0); |
| 3773 | if (!(ha->device_flags & DFLG_NO_CABLE)) { |
| 3774 | atomic_set(&ha->loop_state, LOOP_UP); |
| 3775 | set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); |
| 3776 | set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags); |
| 3777 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
| 3778 | |
| 3779 | rval = qla2x00_loop_resync(ha); |
| 3780 | } else |
| 3781 | atomic_set(&ha->loop_state, LOOP_DEAD); |
| 3782 | |
| 3783 | clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags); |
| 3784 | } |
| 3785 | |
| 3786 | return rval; |
| 3787 | } |
| 3788 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3789 | void |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 3790 | qla2x00_update_fcports(scsi_qla_host_t *base_vha) |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3791 | { |
| 3792 | fc_port_t *fcport; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3793 | struct scsi_qla_host *vha; |
| 3794 | struct qla_hw_data *ha = base_vha->hw; |
| 3795 | unsigned long flags; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3796 | |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3797 | spin_lock_irqsave(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3798 | /* Go with deferred removal of rport references. */ |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3799 | list_for_each_entry(vha, &base_vha->hw->vp_list, list) { |
| 3800 | atomic_inc(&vha->vref_count); |
| 3801 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Dan Carpenter | 8ae598d | 2010-12-21 16:00:15 -0800 | [diff] [blame] | 3802 | if (fcport->drport && |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3803 | atomic_read(&fcport->state) != FCS_UNCONFIGURED) { |
| 3804 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 3805 | |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 3806 | qla2x00_rport_del(fcport); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3807 | |
| 3808 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 3809 | } |
| 3810 | } |
| 3811 | atomic_dec(&vha->vref_count); |
| 3812 | } |
| 3813 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3814 | } |
| 3815 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 3816 | /* Assumes idc_lock always held on entry */ |
| 3817 | void |
| 3818 | qla83xx_reset_ownership(scsi_qla_host_t *vha) |
| 3819 | { |
| 3820 | struct qla_hw_data *ha = vha->hw; |
| 3821 | uint32_t drv_presence, drv_presence_mask; |
| 3822 | uint32_t dev_part_info1, dev_part_info2, class_type; |
| 3823 | uint32_t class_type_mask = 0x3; |
| 3824 | uint16_t fcoe_other_function = 0xffff, i; |
| 3825 | |
| 3826 | qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); |
| 3827 | |
| 3828 | qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1); |
| 3829 | qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2); |
| 3830 | for (i = 0; i < 8; i++) { |
| 3831 | class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask); |
| 3832 | if ((class_type == QLA83XX_CLASS_TYPE_FCOE) && |
| 3833 | (i != ha->portnum)) { |
| 3834 | fcoe_other_function = i; |
| 3835 | break; |
| 3836 | } |
| 3837 | } |
| 3838 | if (fcoe_other_function == 0xffff) { |
| 3839 | for (i = 0; i < 8; i++) { |
| 3840 | class_type = ((dev_part_info2 >> (i * 4)) & |
| 3841 | class_type_mask); |
| 3842 | if ((class_type == QLA83XX_CLASS_TYPE_FCOE) && |
| 3843 | ((i + 8) != ha->portnum)) { |
| 3844 | fcoe_other_function = i + 8; |
| 3845 | break; |
| 3846 | } |
| 3847 | } |
| 3848 | } |
| 3849 | /* |
| 3850 | * Prepare drv-presence mask based on fcoe functions present. |
| 3851 | * However consider only valid physical fcoe function numbers (0-15). |
| 3852 | */ |
| 3853 | drv_presence_mask = ~((1 << (ha->portnum)) | |
| 3854 | ((fcoe_other_function == 0xffff) ? |
| 3855 | 0 : (1 << (fcoe_other_function)))); |
| 3856 | |
| 3857 | /* We are the reset owner iff: |
| 3858 | * - No other protocol drivers present. |
| 3859 | * - This is the lowest among fcoe functions. */ |
| 3860 | if (!(drv_presence & drv_presence_mask) && |
| 3861 | (ha->portnum < fcoe_other_function)) { |
| 3862 | ql_dbg(ql_dbg_p3p, vha, 0xb07f, |
| 3863 | "This host is Reset owner.\n"); |
| 3864 | ha->flags.nic_core_reset_owner = 1; |
| 3865 | } |
| 3866 | } |
| 3867 | |
| 3868 | int |
| 3869 | __qla83xx_set_drv_ack(scsi_qla_host_t *vha) |
| 3870 | { |
| 3871 | int rval = QLA_SUCCESS; |
| 3872 | struct qla_hw_data *ha = vha->hw; |
| 3873 | uint32_t drv_ack; |
| 3874 | |
| 3875 | rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack); |
| 3876 | if (rval == QLA_SUCCESS) { |
| 3877 | drv_ack |= (1 << ha->portnum); |
| 3878 | rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack); |
| 3879 | } |
| 3880 | |
| 3881 | return rval; |
| 3882 | } |
| 3883 | |
| 3884 | int |
| 3885 | qla83xx_set_drv_ack(scsi_qla_host_t *vha) |
| 3886 | { |
| 3887 | int rval = QLA_SUCCESS; |
| 3888 | |
| 3889 | qla83xx_idc_lock(vha, 0); |
| 3890 | rval = __qla83xx_set_drv_ack(vha); |
| 3891 | qla83xx_idc_unlock(vha, 0); |
| 3892 | |
| 3893 | return rval; |
| 3894 | } |
| 3895 | |
| 3896 | int |
| 3897 | __qla83xx_clear_drv_ack(scsi_qla_host_t *vha) |
| 3898 | { |
| 3899 | int rval = QLA_SUCCESS; |
| 3900 | struct qla_hw_data *ha = vha->hw; |
| 3901 | uint32_t drv_ack; |
| 3902 | |
| 3903 | rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack); |
| 3904 | if (rval == QLA_SUCCESS) { |
| 3905 | drv_ack &= ~(1 << ha->portnum); |
| 3906 | rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack); |
| 3907 | } |
| 3908 | |
| 3909 | return rval; |
| 3910 | } |
| 3911 | |
| 3912 | int |
| 3913 | qla83xx_clear_drv_ack(scsi_qla_host_t *vha) |
| 3914 | { |
| 3915 | int rval = QLA_SUCCESS; |
| 3916 | |
| 3917 | qla83xx_idc_lock(vha, 0); |
| 3918 | rval = __qla83xx_clear_drv_ack(vha); |
| 3919 | qla83xx_idc_unlock(vha, 0); |
| 3920 | |
| 3921 | return rval; |
| 3922 | } |
| 3923 | |
| 3924 | const char * |
| 3925 | qla83xx_dev_state_to_string(uint32_t dev_state) |
| 3926 | { |
| 3927 | switch (dev_state) { |
| 3928 | case QLA8XXX_DEV_COLD: |
| 3929 | return "COLD/RE-INIT"; |
| 3930 | case QLA8XXX_DEV_INITIALIZING: |
| 3931 | return "INITIALIZING"; |
| 3932 | case QLA8XXX_DEV_READY: |
| 3933 | return "READY"; |
| 3934 | case QLA8XXX_DEV_NEED_RESET: |
| 3935 | return "NEED RESET"; |
| 3936 | case QLA8XXX_DEV_NEED_QUIESCENT: |
| 3937 | return "NEED QUIESCENT"; |
| 3938 | case QLA8XXX_DEV_FAILED: |
| 3939 | return "FAILED"; |
| 3940 | case QLA8XXX_DEV_QUIESCENT: |
| 3941 | return "QUIESCENT"; |
| 3942 | default: |
| 3943 | return "Unknown"; |
| 3944 | } |
| 3945 | } |
| 3946 | |
| 3947 | /* Assumes idc-lock always held on entry */ |
| 3948 | void |
| 3949 | qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type) |
| 3950 | { |
| 3951 | struct qla_hw_data *ha = vha->hw; |
| 3952 | uint32_t idc_audit_reg = 0, duration_secs = 0; |
| 3953 | |
| 3954 | switch (audit_type) { |
| 3955 | case IDC_AUDIT_TIMESTAMP: |
| 3956 | ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000); |
| 3957 | idc_audit_reg = (ha->portnum) | |
| 3958 | (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8); |
| 3959 | qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg); |
| 3960 | break; |
| 3961 | |
| 3962 | case IDC_AUDIT_COMPLETION: |
| 3963 | duration_secs = ((jiffies_to_msecs(jiffies) - |
| 3964 | jiffies_to_msecs(ha->idc_audit_ts)) / 1000); |
| 3965 | idc_audit_reg = (ha->portnum) | |
| 3966 | (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8); |
| 3967 | qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg); |
| 3968 | break; |
| 3969 | |
| 3970 | default: |
| 3971 | ql_log(ql_log_warn, vha, 0xb078, |
| 3972 | "Invalid audit type specified.\n"); |
| 3973 | break; |
| 3974 | } |
| 3975 | } |
| 3976 | |
| 3977 | /* Assumes idc_lock always held on entry */ |
| 3978 | int |
| 3979 | qla83xx_initiating_reset(scsi_qla_host_t *vha) |
| 3980 | { |
| 3981 | struct qla_hw_data *ha = vha->hw; |
| 3982 | uint32_t idc_control, dev_state; |
| 3983 | |
| 3984 | __qla83xx_get_idc_control(vha, &idc_control); |
| 3985 | if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) { |
| 3986 | ql_log(ql_log_info, vha, 0xb080, |
| 3987 | "NIC Core reset has been disabled. idc-control=0x%x\n", |
| 3988 | idc_control); |
| 3989 | return QLA_FUNCTION_FAILED; |
| 3990 | } |
| 3991 | |
| 3992 | /* Set NEED-RESET iff in READY state and we are the reset-owner */ |
| 3993 | qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state); |
| 3994 | if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) { |
| 3995 | qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, |
| 3996 | QLA8XXX_DEV_NEED_RESET); |
| 3997 | ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n"); |
| 3998 | qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP); |
| 3999 | } else { |
| 4000 | const char *state = qla83xx_dev_state_to_string(dev_state); |
| 4001 | ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state); |
| 4002 | |
| 4003 | /* SV: XXX: Is timeout required here? */ |
| 4004 | /* Wait for IDC state change READY -> NEED_RESET */ |
| 4005 | while (dev_state == QLA8XXX_DEV_READY) { |
| 4006 | qla83xx_idc_unlock(vha, 0); |
| 4007 | msleep(200); |
| 4008 | qla83xx_idc_lock(vha, 0); |
| 4009 | qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state); |
| 4010 | } |
| 4011 | } |
| 4012 | |
| 4013 | /* Send IDC ack by writing to drv-ack register */ |
| 4014 | __qla83xx_set_drv_ack(vha); |
| 4015 | |
| 4016 | return QLA_SUCCESS; |
| 4017 | } |
| 4018 | |
| 4019 | int |
| 4020 | __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control) |
| 4021 | { |
| 4022 | return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control); |
| 4023 | } |
| 4024 | |
| 4025 | int |
| 4026 | qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control) |
| 4027 | { |
| 4028 | int rval = QLA_SUCCESS; |
| 4029 | |
| 4030 | qla83xx_idc_lock(vha, 0); |
| 4031 | rval = __qla83xx_set_idc_control(vha, idc_control); |
| 4032 | qla83xx_idc_unlock(vha, 0); |
| 4033 | |
| 4034 | return rval; |
| 4035 | } |
| 4036 | |
| 4037 | int |
| 4038 | __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control) |
| 4039 | { |
| 4040 | return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control); |
| 4041 | } |
| 4042 | |
| 4043 | int |
| 4044 | qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control) |
| 4045 | { |
| 4046 | int rval = QLA_SUCCESS; |
| 4047 | |
| 4048 | qla83xx_idc_lock(vha, 0); |
| 4049 | rval = __qla83xx_get_idc_control(vha, idc_control); |
| 4050 | qla83xx_idc_unlock(vha, 0); |
| 4051 | |
| 4052 | return rval; |
| 4053 | } |
| 4054 | |
| 4055 | int |
| 4056 | qla83xx_check_driver_presence(scsi_qla_host_t *vha) |
| 4057 | { |
| 4058 | uint32_t drv_presence = 0; |
| 4059 | struct qla_hw_data *ha = vha->hw; |
| 4060 | |
| 4061 | qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); |
| 4062 | if (drv_presence & (1 << ha->portnum)) |
| 4063 | return QLA_SUCCESS; |
| 4064 | else |
| 4065 | return QLA_TEST_FAILED; |
| 4066 | } |
| 4067 | |
| 4068 | int |
| 4069 | qla83xx_nic_core_reset(scsi_qla_host_t *vha) |
| 4070 | { |
| 4071 | int rval = QLA_SUCCESS; |
| 4072 | struct qla_hw_data *ha = vha->hw; |
| 4073 | |
| 4074 | ql_dbg(ql_dbg_p3p, vha, 0xb058, |
| 4075 | "Entered %s().\n", __func__); |
| 4076 | |
| 4077 | if (vha->device_flags & DFLG_DEV_FAILED) { |
| 4078 | ql_log(ql_log_warn, vha, 0xb059, |
| 4079 | "Device in unrecoverable FAILED state.\n"); |
| 4080 | return QLA_FUNCTION_FAILED; |
| 4081 | } |
| 4082 | |
| 4083 | qla83xx_idc_lock(vha, 0); |
| 4084 | |
| 4085 | if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) { |
| 4086 | ql_log(ql_log_warn, vha, 0xb05a, |
| 4087 | "Function=0x%x has been removed from IDC participation.\n", |
| 4088 | ha->portnum); |
| 4089 | rval = QLA_FUNCTION_FAILED; |
| 4090 | goto exit; |
| 4091 | } |
| 4092 | |
| 4093 | qla83xx_reset_ownership(vha); |
| 4094 | |
| 4095 | rval = qla83xx_initiating_reset(vha); |
| 4096 | |
| 4097 | /* |
| 4098 | * Perform reset if we are the reset-owner, |
| 4099 | * else wait till IDC state changes to READY/FAILED. |
| 4100 | */ |
| 4101 | if (rval == QLA_SUCCESS) { |
| 4102 | rval = qla83xx_idc_state_handler(vha); |
| 4103 | |
| 4104 | if (rval == QLA_SUCCESS) |
| 4105 | ha->flags.nic_core_hung = 0; |
| 4106 | __qla83xx_clear_drv_ack(vha); |
| 4107 | } |
| 4108 | |
| 4109 | exit: |
| 4110 | qla83xx_idc_unlock(vha, 0); |
| 4111 | |
| 4112 | ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__); |
| 4113 | |
| 4114 | return rval; |
| 4115 | } |
| 4116 | |
Saurav Kashyap | 8117877 | 2012-08-22 14:21:04 -0400 | [diff] [blame] | 4117 | int |
| 4118 | qla2xxx_mctp_dump(scsi_qla_host_t *vha) |
| 4119 | { |
| 4120 | struct qla_hw_data *ha = vha->hw; |
| 4121 | int rval = QLA_FUNCTION_FAILED; |
| 4122 | |
| 4123 | if (!IS_MCTP_CAPABLE(ha)) { |
| 4124 | /* This message can be removed from the final version */ |
| 4125 | ql_log(ql_log_info, vha, 0x506d, |
| 4126 | "This board is not MCTP capable\n"); |
| 4127 | return rval; |
| 4128 | } |
| 4129 | |
| 4130 | if (!ha->mctp_dump) { |
| 4131 | ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev, |
| 4132 | MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL); |
| 4133 | |
| 4134 | if (!ha->mctp_dump) { |
| 4135 | ql_log(ql_log_warn, vha, 0x506e, |
| 4136 | "Failed to allocate memory for mctp dump\n"); |
| 4137 | return rval; |
| 4138 | } |
| 4139 | } |
| 4140 | |
| 4141 | #define MCTP_DUMP_STR_ADDR 0x00000000 |
| 4142 | rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma, |
| 4143 | MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4); |
| 4144 | if (rval != QLA_SUCCESS) { |
| 4145 | ql_log(ql_log_warn, vha, 0x506f, |
| 4146 | "Failed to capture mctp dump\n"); |
| 4147 | } else { |
| 4148 | ql_log(ql_log_info, vha, 0x5070, |
| 4149 | "Mctp dump capture for host (%ld/%p).\n", |
| 4150 | vha->host_no, ha->mctp_dump); |
| 4151 | ha->mctp_dumped = 1; |
| 4152 | } |
| 4153 | |
Saurav Kashyap | 409ee0f | 2012-08-22 14:21:29 -0400 | [diff] [blame] | 4154 | if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) { |
Saurav Kashyap | 8117877 | 2012-08-22 14:21:04 -0400 | [diff] [blame] | 4155 | ha->flags.nic_core_reset_hdlr_active = 1; |
| 4156 | rval = qla83xx_restart_nic_firmware(vha); |
| 4157 | if (rval) |
| 4158 | /* NIC Core reset failed. */ |
| 4159 | ql_log(ql_log_warn, vha, 0x5071, |
| 4160 | "Failed to restart nic firmware\n"); |
| 4161 | else |
| 4162 | ql_dbg(ql_dbg_p3p, vha, 0xb084, |
| 4163 | "Restarted NIC firmware successfully.\n"); |
| 4164 | ha->flags.nic_core_reset_hdlr_active = 0; |
| 4165 | } |
| 4166 | |
| 4167 | return rval; |
| 4168 | |
| 4169 | } |
| 4170 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4171 | /* |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 4172 | * qla2x00_quiesce_io |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4173 | * Description: This function will block the new I/Os |
| 4174 | * Its not aborting any I/Os as context |
| 4175 | * is not destroyed during quiescence |
| 4176 | * Arguments: scsi_qla_host_t |
| 4177 | * return : void |
| 4178 | */ |
| 4179 | void |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 4180 | qla2x00_quiesce_io(scsi_qla_host_t *vha) |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4181 | { |
| 4182 | struct qla_hw_data *ha = vha->hw; |
| 4183 | struct scsi_qla_host *vp; |
| 4184 | |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 4185 | ql_dbg(ql_dbg_dpc, vha, 0x401d, |
| 4186 | "Quiescing I/O - ha=%p.\n", ha); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4187 | |
| 4188 | atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); |
| 4189 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 4190 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 4191 | qla2x00_mark_all_devices_lost(vha, 0); |
| 4192 | list_for_each_entry(vp, &ha->vp_list, list) |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 4193 | qla2x00_mark_all_devices_lost(vp, 0); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4194 | } else { |
| 4195 | if (!atomic_read(&vha->loop_down_timer)) |
| 4196 | atomic_set(&vha->loop_down_timer, |
| 4197 | LOOP_DOWN_TIME); |
| 4198 | } |
| 4199 | /* Wait for pending cmds to complete */ |
| 4200 | qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST); |
| 4201 | } |
| 4202 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4203 | void |
| 4204 | qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha) |
| 4205 | { |
| 4206 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4207 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4208 | unsigned long flags; |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 4209 | fc_port_t *fcport; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4210 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 4211 | /* For ISP82XX, driver waits for completion of the commands. |
| 4212 | * online flag should be set. |
| 4213 | */ |
| 4214 | if (!IS_QLA82XX(ha)) |
| 4215 | vha->flags.online = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4216 | ha->flags.chip_reset_done = 0; |
| 4217 | clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Saurav Kashyap | 2be21fa | 2012-05-15 14:34:16 -0400 | [diff] [blame] | 4218 | vha->qla_stats.total_isp_aborts++; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4219 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4220 | ql_log(ql_log_info, vha, 0x00af, |
| 4221 | "Performing ISP error recovery - ha=%p.\n", ha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4222 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 4223 | /* For ISP82XX, reset_chip is just disabling interrupts. |
| 4224 | * Driver waits for the completion of the commands. |
| 4225 | * the interrupts need to be enabled. |
| 4226 | */ |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4227 | if (!IS_QLA82XX(ha)) |
| 4228 | ha->isp_ops->reset_chip(vha); |
| 4229 | |
| 4230 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 4231 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 4232 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 4233 | qla2x00_mark_all_devices_lost(vha, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4234 | |
| 4235 | spin_lock_irqsave(&ha->vport_slock, flags); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4236 | list_for_each_entry(vp, &ha->vp_list, list) { |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4237 | atomic_inc(&vp->vref_count); |
| 4238 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4239 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4240 | qla2x00_mark_all_devices_lost(vp, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4241 | |
| 4242 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4243 | atomic_dec(&vp->vref_count); |
| 4244 | } |
| 4245 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4246 | } else { |
| 4247 | if (!atomic_read(&vha->loop_down_timer)) |
| 4248 | atomic_set(&vha->loop_down_timer, |
| 4249 | LOOP_DOWN_TIME); |
| 4250 | } |
| 4251 | |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 4252 | /* Clear all async request states across all VPs. */ |
| 4253 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 4254 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 4255 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4256 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 4257 | atomic_inc(&vp->vref_count); |
| 4258 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4259 | |
| 4260 | list_for_each_entry(fcport, &vp->vp_fcports, list) |
| 4261 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 4262 | |
| 4263 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4264 | atomic_dec(&vp->vref_count); |
| 4265 | } |
| 4266 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4267 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 4268 | if (!ha->flags.eeh_busy) { |
| 4269 | /* Make sure for ISP 82XX IO DMA is complete */ |
| 4270 | if (IS_QLA82XX(ha)) { |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 4271 | qla82xx_chip_reset_cleanup(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4272 | ql_log(ql_log_info, vha, 0x00b4, |
| 4273 | "Done chip reset cleanup.\n"); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4274 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 4275 | /* Done waiting for pending commands. |
| 4276 | * Reset the online flag. |
| 4277 | */ |
| 4278 | vha->flags.online = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4279 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4280 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 4281 | /* Requeue all commands in outstanding command list. */ |
| 4282 | qla2x00_abort_all_cmds(vha, DID_RESET << 16); |
| 4283 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4284 | } |
| 4285 | |
| 4286 | /* |
| 4287 | * qla2x00_abort_isp |
| 4288 | * Resets ISP and aborts all outstanding commands. |
| 4289 | * |
| 4290 | * Input: |
| 4291 | * ha = adapter block pointer. |
| 4292 | * |
| 4293 | * Returns: |
| 4294 | * 0 = success |
| 4295 | */ |
| 4296 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4297 | qla2x00_abort_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4298 | { |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 4299 | int rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4300 | uint8_t status = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4301 | struct qla_hw_data *ha = vha->hw; |
| 4302 | struct scsi_qla_host *vp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4303 | struct req_que *req = ha->req_q_map[0]; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4304 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4305 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4306 | if (vha->flags.online) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4307 | qla2x00_abort_isp_cleanup(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4308 | |
Santosh Vernekar | a6171297 | 2012-08-22 14:21:13 -0400 | [diff] [blame] | 4309 | if (IS_QLA8031(ha)) { |
| 4310 | ql_dbg(ql_dbg_p3p, vha, 0xb05c, |
| 4311 | "Clearing fcoe driver presence.\n"); |
| 4312 | if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS) |
| 4313 | ql_dbg(ql_dbg_p3p, vha, 0xb073, |
| 4314 | "Error while clearing DRV-Presence.\n"); |
| 4315 | } |
| 4316 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 4317 | if (unlikely(pci_channel_offline(ha->pdev) && |
| 4318 | ha->flags.pci_channel_io_perm_failure)) { |
| 4319 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 4320 | status = 0; |
| 4321 | return status; |
| 4322 | } |
| 4323 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4324 | ha->isp_ops->get_flash_version(vha, req->ring); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 4325 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4326 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4327 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4328 | if (!qla2x00_restart_isp(vha)) { |
| 4329 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4330 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4331 | if (!atomic_read(&vha->loop_down_timer)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4332 | /* |
| 4333 | * Issue marker command only when we are going |
| 4334 | * to start the I/O . |
| 4335 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4336 | vha->marker_needed = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4337 | } |
| 4338 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4339 | vha->flags.online = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4340 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 4341 | ha->isp_ops->enable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4342 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4343 | ha->isp_abort_cnt = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4344 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 4345 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 4346 | if (IS_QLA81XX(ha) || IS_QLA8031(ha)) |
| 4347 | qla2x00_get_fw_version(vha); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 4348 | if (ha->fce) { |
| 4349 | ha->flags.fce_enabled = 1; |
| 4350 | memset(ha->fce, 0, |
| 4351 | fce_calc_size(ha->fce_bufs)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4352 | rval = qla2x00_enable_fce_trace(vha, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 4353 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 4354 | &ha->fce_bufs); |
| 4355 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4356 | ql_log(ql_log_warn, vha, 0x8033, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 4357 | "Unable to reinitialize FCE " |
| 4358 | "(%d).\n", rval); |
| 4359 | ha->flags.fce_enabled = 0; |
| 4360 | } |
| 4361 | } |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 4362 | |
| 4363 | if (ha->eft) { |
| 4364 | memset(ha->eft, 0, EFT_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4365 | rval = qla2x00_enable_eft_trace(vha, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 4366 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 4367 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4368 | ql_log(ql_log_warn, vha, 0x8034, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 4369 | "Unable to reinitialize EFT " |
| 4370 | "(%d).\n", rval); |
| 4371 | } |
| 4372 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4373 | } else { /* failed the ISP abort */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4374 | vha->flags.online = 1; |
| 4375 | if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4376 | if (ha->isp_abort_cnt == 0) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4377 | ql_log(ql_log_fatal, vha, 0x8035, |
| 4378 | "ISP error recover failed - " |
| 4379 | "board disabled.\n"); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4380 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4381 | * The next call disables the board |
| 4382 | * completely. |
| 4383 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4384 | ha->isp_ops->reset_adapter(vha); |
| 4385 | vha->flags.online = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4386 | clear_bit(ISP_ABORT_RETRY, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4387 | &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4388 | status = 0; |
| 4389 | } else { /* schedule another ISP abort */ |
| 4390 | ha->isp_abort_cnt--; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4391 | ql_dbg(ql_dbg_taskm, vha, 0x8020, |
| 4392 | "ISP abort - retry remaining %d.\n", |
| 4393 | ha->isp_abort_cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4394 | status = 1; |
| 4395 | } |
| 4396 | } else { |
| 4397 | ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4398 | ql_dbg(ql_dbg_taskm, vha, 0x8021, |
| 4399 | "ISP error recovery - retrying (%d) " |
| 4400 | "more times.\n", ha->isp_abort_cnt); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4401 | set_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4402 | status = 1; |
| 4403 | } |
| 4404 | } |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4406 | } |
| 4407 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4408 | if (!status) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4409 | ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4410 | |
| 4411 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4412 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 4413 | if (vp->vp_idx) { |
| 4414 | atomic_inc(&vp->vref_count); |
| 4415 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4416 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4417 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4418 | |
| 4419 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4420 | atomic_dec(&vp->vref_count); |
| 4421 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4422 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4423 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4424 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 4425 | if (IS_QLA8031(ha)) { |
| 4426 | ql_dbg(ql_dbg_p3p, vha, 0xb05d, |
| 4427 | "Setting back fcoe driver presence.\n"); |
| 4428 | if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS) |
| 4429 | ql_dbg(ql_dbg_p3p, vha, 0xb074, |
| 4430 | "Error while setting DRV-Presence.\n"); |
| 4431 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4432 | } else { |
Joe Perches | d8424f6 | 2011-11-18 09:03:06 -0800 | [diff] [blame] | 4433 | ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n", |
| 4434 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4435 | } |
| 4436 | |
| 4437 | return(status); |
| 4438 | } |
| 4439 | |
| 4440 | /* |
| 4441 | * qla2x00_restart_isp |
| 4442 | * restarts the ISP after a reset |
| 4443 | * |
| 4444 | * Input: |
| 4445 | * ha = adapter block pointer. |
| 4446 | * |
| 4447 | * Returns: |
| 4448 | * 0 = success |
| 4449 | */ |
| 4450 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4451 | qla2x00_restart_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4452 | { |
Andrew Vasquez | c6b2fca | 2009-03-05 11:07:03 -0800 | [diff] [blame] | 4453 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4454 | uint32_t wait_time; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4455 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4456 | struct req_que *req = ha->req_q_map[0]; |
| 4457 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4458 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4459 | |
| 4460 | /* If firmware needs to be loaded */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4461 | if (qla2x00_isp_firmware(vha)) { |
| 4462 | vha->flags.online = 0; |
| 4463 | status = ha->isp_ops->chip_diag(vha); |
| 4464 | if (!status) |
| 4465 | status = qla2x00_setup_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4466 | } |
| 4467 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4468 | if (!status && !(status = qla2x00_init_rings(vha))) { |
| 4469 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 4470 | ha->flags.chip_reset_done = 1; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4471 | /* Initialize the queues in use */ |
| 4472 | qla25xx_init_queues(ha); |
| 4473 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4474 | status = qla2x00_fw_ready(vha); |
| 4475 | if (!status) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4476 | ql_dbg(ql_dbg_taskm, vha, 0x8031, |
| 4477 | "Start configure loop status = %d.\n", status); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4478 | |
| 4479 | /* Issue a marker after FW becomes ready. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4480 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4481 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4482 | vha->flags.online = 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4483 | |
| 4484 | /* |
| 4485 | * Process any ATIO queue entries that came in |
| 4486 | * while we weren't online. |
| 4487 | */ |
| 4488 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4489 | if (qla_tgt_mode_enabled(vha)) |
| 4490 | qlt_24xx_process_atio_queue(vha); |
| 4491 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4492 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4493 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 4494 | wait_time = 256; |
| 4495 | do { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4496 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 4497 | qla2x00_configure_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4498 | wait_time--; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4499 | } while (!atomic_read(&vha->loop_down_timer) && |
| 4500 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
| 4501 | && wait_time && (test_bit(LOOP_RESYNC_NEEDED, |
| 4502 | &vha->dpc_flags))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4503 | } |
| 4504 | |
| 4505 | /* if no cable then assume it's good */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4506 | if ((vha->device_flags & DFLG_NO_CABLE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4507 | status = 0; |
| 4508 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4509 | ql_dbg(ql_dbg_taskm, vha, 0x8032, |
| 4510 | "Configure loop done, status = 0x%x.\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4511 | } |
| 4512 | return (status); |
| 4513 | } |
| 4514 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4515 | static int |
| 4516 | qla25xx_init_queues(struct qla_hw_data *ha) |
| 4517 | { |
| 4518 | struct rsp_que *rsp = NULL; |
| 4519 | struct req_que *req = NULL; |
| 4520 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
| 4521 | int ret = -1; |
| 4522 | int i; |
| 4523 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 4524 | for (i = 1; i < ha->max_rsp_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4525 | rsp = ha->rsp_q_map[i]; |
| 4526 | if (rsp) { |
| 4527 | rsp->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 4528 | ret = qla25xx_init_rsp_que(base_vha, rsp); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4529 | if (ret != QLA_SUCCESS) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4530 | ql_dbg(ql_dbg_init, base_vha, 0x00ff, |
| 4531 | "%s Rsp que: %d init failed.\n", |
| 4532 | __func__, rsp->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4533 | else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4534 | ql_dbg(ql_dbg_init, base_vha, 0x0100, |
| 4535 | "%s Rsp que: %d inited.\n", |
| 4536 | __func__, rsp->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4537 | } |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 4538 | } |
| 4539 | for (i = 1; i < ha->max_req_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4540 | req = ha->req_q_map[i]; |
| 4541 | if (req) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 4542 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4543 | req->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 4544 | ret = qla25xx_init_req_que(base_vha, req); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4545 | if (ret != QLA_SUCCESS) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4546 | ql_dbg(ql_dbg_init, base_vha, 0x0101, |
| 4547 | "%s Req que: %d init failed.\n", |
| 4548 | __func__, req->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4549 | else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4550 | ql_dbg(ql_dbg_init, base_vha, 0x0102, |
| 4551 | "%s Req que: %d inited.\n", |
| 4552 | __func__, req->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4553 | } |
| 4554 | } |
| 4555 | return ret; |
| 4556 | } |
| 4557 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4558 | /* |
| 4559 | * qla2x00_reset_adapter |
| 4560 | * Reset adapter. |
| 4561 | * |
| 4562 | * Input: |
| 4563 | * ha = adapter block pointer. |
| 4564 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4565 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4566 | qla2x00_reset_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4567 | { |
| 4568 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4569 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 4570 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4571 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4572 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 4573 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4574 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4575 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4576 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 4577 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 4578 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 4579 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 4580 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4581 | } |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4582 | |
| 4583 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4584 | qla24xx_reset_adapter(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4585 | { |
| 4586 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4587 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4588 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 4589 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4590 | if (IS_QLA82XX(ha)) |
| 4591 | return; |
| 4592 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4593 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 4594 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4595 | |
| 4596 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4597 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 4598 | RD_REG_DWORD(®->hccr); |
| 4599 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 4600 | RD_REG_DWORD(®->hccr); |
| 4601 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 09ff36d | 2009-01-22 09:45:30 -0800 | [diff] [blame] | 4602 | |
| 4603 | if (IS_NOPOLLING_TYPE(ha)) |
| 4604 | ha->isp_ops->enable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4605 | } |
| 4606 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4607 | /* On sparc systems, obtain port and node WWN from firmware |
| 4608 | * properties. |
| 4609 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4610 | static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, |
| 4611 | struct nvram_24xx *nv) |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4612 | { |
| 4613 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4614 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4615 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 4616 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 4617 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4618 | int len; |
| 4619 | |
| 4620 | val = of_get_property(dp, "port-wwn", &len); |
| 4621 | if (val && len >= WWN_SIZE) |
| 4622 | memcpy(nv->port_name, val, WWN_SIZE); |
| 4623 | |
| 4624 | val = of_get_property(dp, "node-wwn", &len); |
| 4625 | if (val && len >= WWN_SIZE) |
| 4626 | memcpy(nv->node_name, val, WWN_SIZE); |
| 4627 | #endif |
| 4628 | } |
| 4629 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4630 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4631 | qla24xx_nvram_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4632 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4633 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4634 | struct init_cb_24xx *icb; |
| 4635 | struct nvram_24xx *nv; |
| 4636 | uint32_t *dptr; |
| 4637 | uint8_t *dptr1, *dptr2; |
| 4638 | uint32_t chksum; |
| 4639 | uint16_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4640 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4641 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4642 | rval = QLA_SUCCESS; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4643 | icb = (struct init_cb_24xx *)ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 4644 | nv = ha->nvram; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4645 | |
| 4646 | /* Determine NVRAM starting address. */ |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 4647 | if (ha->flags.port0) { |
| 4648 | ha->nvram_base = FA_NVRAM_FUNC0_ADDR; |
| 4649 | ha->vpd_base = FA_NVRAM_VPD0_ADDR; |
| 4650 | } else { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4651 | ha->nvram_base = FA_NVRAM_FUNC1_ADDR; |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 4652 | ha->vpd_base = FA_NVRAM_VPD1_ADDR; |
| 4653 | } |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 4654 | ha->nvram_size = sizeof(struct nvram_24xx); |
| 4655 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4656 | if (IS_QLA82XX(ha)) |
| 4657 | ha->vpd_size = FA_VPD_SIZE_82XX; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4658 | |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 4659 | /* Get VPD data into cache */ |
| 4660 | ha->vpd = ha->nvram + VPD_OFFSET; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4661 | ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 4662 | ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4); |
| 4663 | |
| 4664 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4665 | dptr = (uint32_t *)nv; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4666 | ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4667 | ha->nvram_size); |
| 4668 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++) |
| 4669 | chksum += le32_to_cpu(*dptr++); |
| 4670 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4671 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a, |
| 4672 | "Contents of NVRAM\n"); |
| 4673 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d, |
| 4674 | (uint8_t *)nv, ha->nvram_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4675 | |
| 4676 | /* Bad NVRAM data, set defaults parameters. */ |
| 4677 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 4678 | || nv->id[3] != ' ' || |
| 4679 | nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) { |
| 4680 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4681 | ql_log(ql_log_warn, vha, 0x006b, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 4682 | "Inconsistent NVRAM detected: checksum=0x%x id=%c " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4683 | "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version); |
| 4684 | ql_log(ql_log_warn, vha, 0x006c, |
| 4685 | "Falling back to functioning (yet invalid -- WWPN) " |
| 4686 | "defaults.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4687 | |
| 4688 | /* |
| 4689 | * Set default initialization control block. |
| 4690 | */ |
| 4691 | memset(nv, 0, ha->nvram_size); |
| 4692 | nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION); |
| 4693 | nv->version = __constant_cpu_to_le16(ICB_VERSION); |
| 4694 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 4695 | nv->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 4696 | nv->exchange_count = __constant_cpu_to_le16(0); |
| 4697 | nv->hard_address = __constant_cpu_to_le16(124); |
| 4698 | nv->port_name[0] = 0x21; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 4699 | nv->port_name[1] = 0x00 + ha->port_no; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4700 | nv->port_name[2] = 0x00; |
| 4701 | nv->port_name[3] = 0xe0; |
| 4702 | nv->port_name[4] = 0x8b; |
| 4703 | nv->port_name[5] = 0x1c; |
| 4704 | nv->port_name[6] = 0x55; |
| 4705 | nv->port_name[7] = 0x86; |
| 4706 | nv->node_name[0] = 0x20; |
| 4707 | nv->node_name[1] = 0x00; |
| 4708 | nv->node_name[2] = 0x00; |
| 4709 | nv->node_name[3] = 0xe0; |
| 4710 | nv->node_name[4] = 0x8b; |
| 4711 | nv->node_name[5] = 0x1c; |
| 4712 | nv->node_name[6] = 0x55; |
| 4713 | nv->node_name[7] = 0x86; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4714 | qla24xx_nvram_wwn_from_ofw(vha, nv); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4715 | nv->login_retry_count = __constant_cpu_to_le16(8); |
| 4716 | nv->interrupt_delay_timer = __constant_cpu_to_le16(0); |
| 4717 | nv->login_timeout = __constant_cpu_to_le16(0); |
| 4718 | nv->firmware_options_1 = |
| 4719 | __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 4720 | nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4); |
| 4721 | nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12); |
| 4722 | nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13); |
| 4723 | nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10); |
| 4724 | nv->efi_parameters = __constant_cpu_to_le32(0); |
| 4725 | nv->reset_delay = 5; |
| 4726 | nv->max_luns_per_target = __constant_cpu_to_le16(128); |
| 4727 | nv->port_down_retry_count = __constant_cpu_to_le16(30); |
| 4728 | nv->link_down_timeout = __constant_cpu_to_le16(30); |
| 4729 | |
| 4730 | rval = 1; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4731 | } |
| 4732 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4733 | if (!qla_ini_mode_enabled(vha)) { |
| 4734 | /* Don't enable full login after initial LIP */ |
| 4735 | nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_13); |
| 4736 | /* Don't enable LIP full login for initiator */ |
| 4737 | nv->host_p &= __constant_cpu_to_le32(~BIT_10); |
| 4738 | } |
| 4739 | |
| 4740 | qlt_24xx_config_nvram_stage1(vha, nv); |
| 4741 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4742 | /* Reset Initialization control block */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4743 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4744 | |
| 4745 | /* Copy 1st segment. */ |
| 4746 | dptr1 = (uint8_t *)icb; |
| 4747 | dptr2 = (uint8_t *)&nv->version; |
| 4748 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 4749 | while (cnt--) |
| 4750 | *dptr1++ = *dptr2++; |
| 4751 | |
| 4752 | icb->login_retry_count = nv->login_retry_count; |
Andrew Vasquez | 3ea66e2 | 2006-06-23 16:11:27 -0700 | [diff] [blame] | 4753 | icb->link_down_on_nos = nv->link_down_on_nos; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4754 | |
| 4755 | /* Copy 2nd segment. */ |
| 4756 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 4757 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 4758 | cnt = (uint8_t *)&icb->reserved_3 - |
| 4759 | (uint8_t *)&icb->interrupt_delay_timer; |
| 4760 | while (cnt--) |
| 4761 | *dptr1++ = *dptr2++; |
| 4762 | |
| 4763 | /* |
| 4764 | * Setup driver NVRAM options. |
| 4765 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4766 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 4767 | "QLA2462"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4768 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4769 | qlt_24xx_config_nvram_stage2(vha, icb); |
| 4770 | |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 4771 | if (nv->host_p & __constant_cpu_to_le32(BIT_15)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4772 | /* Use alternate WWN? */ |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 4773 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 4774 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 4775 | } |
| 4776 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4777 | /* Prepare nodename */ |
Andrew Vasquez | fd0e7e4 | 2006-05-17 15:09:11 -0700 | [diff] [blame] | 4778 | if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4779 | /* |
| 4780 | * Firmware will apply the following mask if the nodename was |
| 4781 | * not provided. |
| 4782 | */ |
| 4783 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 4784 | icb->node_name[0] &= 0xF0; |
| 4785 | } |
| 4786 | |
| 4787 | /* Set host adapter parameters. */ |
| 4788 | ha->flags.disable_risc_code_load = 0; |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 4789 | ha->flags.enable_lip_reset = 0; |
| 4790 | ha->flags.enable_lip_full_login = |
| 4791 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 4792 | ha->flags.enable_target_reset = |
| 4793 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4794 | ha->flags.enable_led_scheme = 0; |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 4795 | 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] | 4796 | |
Andrew Vasquez | fd0e7e4 | 2006-05-17 15:09:11 -0700 | [diff] [blame] | 4797 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 4798 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4799 | |
| 4800 | memcpy(ha->fw_seriallink_options24, nv->seriallink_options, |
| 4801 | sizeof(ha->fw_seriallink_options24)); |
| 4802 | |
| 4803 | /* save HBA serial number */ |
| 4804 | ha->serial0 = icb->port_name[5]; |
| 4805 | ha->serial1 = icb->port_name[6]; |
| 4806 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4807 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 4808 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4809 | |
andrew.vasquez@qlogic.com | bc8fb3c | 2006-01-13 17:05:42 -0800 | [diff] [blame] | 4810 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 4811 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4812 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 4813 | |
| 4814 | /* Set minimum login_timeout to 4 seconds. */ |
| 4815 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 4816 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 4817 | if (le16_to_cpu(nv->login_timeout) < 4) |
| 4818 | nv->login_timeout = __constant_cpu_to_le16(4); |
| 4819 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
Seokmann Ju | c6852c4 | 2008-04-24 15:21:29 -0700 | [diff] [blame] | 4820 | icb->login_timeout = nv->login_timeout; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4821 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 4822 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 4823 | ha->r_a_tov = 100; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4824 | |
| 4825 | ha->loop_reset_delay = nv->reset_delay; |
| 4826 | |
| 4827 | /* Link Down Timeout = 0: |
| 4828 | * |
| 4829 | * When Port Down timer expires we will start returning |
| 4830 | * I/O's to OS with "DID_NO_CONNECT". |
| 4831 | * |
| 4832 | * Link Down Timeout != 0: |
| 4833 | * |
| 4834 | * The driver waits for the link to come up after link down |
| 4835 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 4836 | */ |
| 4837 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 4838 | ha->loop_down_abort_time = |
| 4839 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 4840 | } else { |
| 4841 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 4842 | ha->loop_down_abort_time = |
| 4843 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 4844 | } |
| 4845 | |
| 4846 | /* Need enough time to try and get the port back. */ |
| 4847 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 4848 | if (qlport_down_retry) |
| 4849 | ha->port_down_retry_count = qlport_down_retry; |
| 4850 | |
| 4851 | /* Set login_retry_count */ |
| 4852 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 4853 | if (ha->port_down_retry_count == |
| 4854 | le16_to_cpu(nv->port_down_retry_count) && |
| 4855 | ha->port_down_retry_count > 3) |
| 4856 | ha->login_retry_count = ha->port_down_retry_count; |
| 4857 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 4858 | ha->login_retry_count = ha->port_down_retry_count; |
| 4859 | if (ql2xloginretrycount) |
| 4860 | ha->login_retry_count = ql2xloginretrycount; |
| 4861 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4862 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4863 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4864 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 4865 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 4866 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 4867 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 4868 | } |
| 4869 | icb->firmware_options_2 &= __constant_cpu_to_le32( |
| 4870 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4871 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4872 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 4873 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 4874 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4875 | ql_log(ql_log_info, vha, 0x006f, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4876 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 4877 | ha->zio_mode, ha->zio_timer * 100); |
| 4878 | |
| 4879 | icb->firmware_options_2 |= cpu_to_le32( |
| 4880 | (uint32_t)ha->zio_mode); |
| 4881 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4882 | vha->flags.process_response_queue = 1; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4883 | } |
| 4884 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4885 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4886 | ql_log(ql_log_warn, vha, 0x0070, |
| 4887 | "NVRAM configuration failed.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4888 | } |
| 4889 | return (rval); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4890 | } |
| 4891 | |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 4892 | static int |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4893 | qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr, |
| 4894 | uint32_t faddr) |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4895 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4896 | int rval = QLA_SUCCESS; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4897 | int segments, fragment; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4898 | uint32_t *dcode, dlen; |
| 4899 | uint32_t risc_addr; |
| 4900 | uint32_t risc_size; |
| 4901 | uint32_t i; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4902 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4903 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4904 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4905 | ql_dbg(ql_dbg_init, vha, 0x008b, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 4906 | "FW: Loading firmware from flash (%x).\n", faddr); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4907 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4908 | rval = QLA_SUCCESS; |
| 4909 | |
| 4910 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4911 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4912 | *srisc_addr = 0; |
| 4913 | |
| 4914 | /* Validate firmware image by checking version. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4915 | qla24xx_read_flash_data(vha, dcode, faddr + 4, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4916 | for (i = 0; i < 4; i++) |
| 4917 | dcode[i] = be32_to_cpu(dcode[i]); |
| 4918 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 4919 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 4920 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 4921 | dcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4922 | ql_log(ql_log_fatal, vha, 0x008c, |
| 4923 | "Unable to verify the integrity of flash firmware " |
| 4924 | "image.\n"); |
| 4925 | ql_log(ql_log_fatal, vha, 0x008d, |
| 4926 | "Firmware data: %08x %08x %08x %08x.\n", |
| 4927 | dcode[0], dcode[1], dcode[2], dcode[3]); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4928 | |
| 4929 | return QLA_FUNCTION_FAILED; |
| 4930 | } |
| 4931 | |
| 4932 | while (segments && rval == QLA_SUCCESS) { |
| 4933 | /* Read segment's load information. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4934 | qla24xx_read_flash_data(vha, dcode, faddr, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4935 | |
| 4936 | risc_addr = be32_to_cpu(dcode[2]); |
| 4937 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 4938 | risc_size = be32_to_cpu(dcode[3]); |
| 4939 | |
| 4940 | fragment = 0; |
| 4941 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 4942 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 4943 | if (dlen > risc_size) |
| 4944 | dlen = risc_size; |
| 4945 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4946 | ql_dbg(ql_dbg_init, vha, 0x008e, |
| 4947 | "Loading risc segment@ risc addr %x " |
| 4948 | "number of dwords 0x%x offset 0x%x.\n", |
| 4949 | risc_addr, dlen, faddr); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4950 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4951 | qla24xx_read_flash_data(vha, dcode, faddr, dlen); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4952 | for (i = 0; i < dlen; i++) |
| 4953 | dcode[i] = swab32(dcode[i]); |
| 4954 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4955 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4956 | dlen); |
| 4957 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4958 | ql_log(ql_log_fatal, vha, 0x008f, |
| 4959 | "Failed to load segment %d of firmware.\n", |
| 4960 | fragment); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4961 | break; |
| 4962 | } |
| 4963 | |
| 4964 | faddr += dlen; |
| 4965 | risc_addr += dlen; |
| 4966 | risc_size -= dlen; |
| 4967 | fragment++; |
| 4968 | } |
| 4969 | |
| 4970 | /* Next segment. */ |
| 4971 | segments--; |
| 4972 | } |
| 4973 | |
| 4974 | return rval; |
| 4975 | } |
| 4976 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4977 | #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/" |
| 4978 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4979 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4980 | qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4981 | { |
| 4982 | int rval; |
| 4983 | int i, fragment; |
| 4984 | uint16_t *wcode, *fwcode; |
| 4985 | uint32_t risc_addr, risc_size, fwclen, wlen, *seg; |
| 4986 | struct fw_blob *blob; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4987 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4988 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4989 | |
| 4990 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4991 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4992 | if (!blob) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4993 | ql_log(ql_log_info, vha, 0x0083, |
| 4994 | "Fimware image unavailable.\n"); |
| 4995 | ql_log(ql_log_info, vha, 0x0084, |
| 4996 | "Firmware images can be retrieved from: "QLA_FW_URL ".\n"); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4997 | return QLA_FUNCTION_FAILED; |
| 4998 | } |
| 4999 | |
| 5000 | rval = QLA_SUCCESS; |
| 5001 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5002 | wcode = (uint16_t *)req->ring; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5003 | *srisc_addr = 0; |
| 5004 | fwcode = (uint16_t *)blob->fw->data; |
| 5005 | fwclen = 0; |
| 5006 | |
| 5007 | /* Validate firmware image by checking version. */ |
| 5008 | if (blob->fw->size < 8 * sizeof(uint16_t)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5009 | ql_log(ql_log_fatal, vha, 0x0085, |
| 5010 | "Unable to verify integrity of firmware image (%Zd).\n", |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5011 | blob->fw->size); |
| 5012 | goto fail_fw_integrity; |
| 5013 | } |
| 5014 | for (i = 0; i < 4; i++) |
| 5015 | wcode[i] = be16_to_cpu(fwcode[i + 4]); |
| 5016 | if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff && |
| 5017 | wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 && |
| 5018 | wcode[2] == 0 && wcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5019 | ql_log(ql_log_fatal, vha, 0x0086, |
| 5020 | "Unable to verify integrity of firmware image.\n"); |
| 5021 | ql_log(ql_log_fatal, vha, 0x0087, |
| 5022 | "Firmware data: %04x %04x %04x %04x.\n", |
| 5023 | wcode[0], wcode[1], wcode[2], wcode[3]); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5024 | goto fail_fw_integrity; |
| 5025 | } |
| 5026 | |
| 5027 | seg = blob->segs; |
| 5028 | while (*seg && rval == QLA_SUCCESS) { |
| 5029 | risc_addr = *seg; |
| 5030 | *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr; |
| 5031 | risc_size = be16_to_cpu(fwcode[3]); |
| 5032 | |
| 5033 | /* Validate firmware image size. */ |
| 5034 | fwclen += risc_size * sizeof(uint16_t); |
| 5035 | if (blob->fw->size < fwclen) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5036 | ql_log(ql_log_fatal, vha, 0x0088, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5037 | "Unable to verify integrity of firmware image " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5038 | "(%Zd).\n", blob->fw->size); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5039 | goto fail_fw_integrity; |
| 5040 | } |
| 5041 | |
| 5042 | fragment = 0; |
| 5043 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 5044 | wlen = (uint16_t)(ha->fw_transfer_size >> 1); |
| 5045 | if (wlen > risc_size) |
| 5046 | wlen = risc_size; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5047 | ql_dbg(ql_dbg_init, vha, 0x0089, |
| 5048 | "Loading risc segment@ risc addr %x number of " |
| 5049 | "words 0x%x.\n", risc_addr, wlen); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5050 | |
| 5051 | for (i = 0; i < wlen; i++) |
| 5052 | wcode[i] = swab16(fwcode[i]); |
| 5053 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5054 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5055 | wlen); |
| 5056 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5057 | ql_log(ql_log_fatal, vha, 0x008a, |
| 5058 | "Failed to load segment %d of firmware.\n", |
| 5059 | fragment); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5060 | break; |
| 5061 | } |
| 5062 | |
| 5063 | fwcode += wlen; |
| 5064 | risc_addr += wlen; |
| 5065 | risc_size -= wlen; |
| 5066 | fragment++; |
| 5067 | } |
| 5068 | |
| 5069 | /* Next segment. */ |
| 5070 | seg++; |
| 5071 | } |
| 5072 | return rval; |
| 5073 | |
| 5074 | fail_fw_integrity: |
| 5075 | return QLA_FUNCTION_FAILED; |
| 5076 | } |
| 5077 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5078 | static int |
| 5079 | 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] | 5080 | { |
| 5081 | int rval; |
| 5082 | int segments, fragment; |
| 5083 | uint32_t *dcode, dlen; |
| 5084 | uint32_t risc_addr; |
| 5085 | uint32_t risc_size; |
| 5086 | uint32_t i; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5087 | struct fw_blob *blob; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5088 | uint32_t *fwcode, fwclen; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5089 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5090 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5091 | |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5092 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5093 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5094 | if (!blob) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5095 | ql_log(ql_log_warn, vha, 0x0090, |
| 5096 | "Fimware image unavailable.\n"); |
| 5097 | ql_log(ql_log_warn, vha, 0x0091, |
| 5098 | "Firmware images can be retrieved from: " |
| 5099 | QLA_FW_URL ".\n"); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5100 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5101 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5102 | } |
| 5103 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5104 | ql_dbg(ql_dbg_init, vha, 0x0092, |
| 5105 | "FW: Loading via request-firmware.\n"); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5106 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5107 | rval = QLA_SUCCESS; |
| 5108 | |
| 5109 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5110 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5111 | *srisc_addr = 0; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5112 | fwcode = (uint32_t *)blob->fw->data; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5113 | fwclen = 0; |
| 5114 | |
| 5115 | /* Validate firmware image by checking version. */ |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5116 | if (blob->fw->size < 8 * sizeof(uint32_t)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5117 | ql_log(ql_log_fatal, vha, 0x0093, |
| 5118 | "Unable to verify integrity of firmware image (%Zd).\n", |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5119 | blob->fw->size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5120 | goto fail_fw_integrity; |
| 5121 | } |
| 5122 | for (i = 0; i < 4; i++) |
| 5123 | dcode[i] = be32_to_cpu(fwcode[i + 4]); |
| 5124 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 5125 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 5126 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 5127 | dcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5128 | ql_log(ql_log_fatal, vha, 0x0094, |
| 5129 | "Unable to verify integrity of firmware image (%Zd).\n", |
| 5130 | blob->fw->size); |
| 5131 | ql_log(ql_log_fatal, vha, 0x0095, |
| 5132 | "Firmware data: %08x %08x %08x %08x.\n", |
| 5133 | dcode[0], dcode[1], dcode[2], dcode[3]); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5134 | goto fail_fw_integrity; |
| 5135 | } |
| 5136 | |
| 5137 | while (segments && rval == QLA_SUCCESS) { |
| 5138 | risc_addr = be32_to_cpu(fwcode[2]); |
| 5139 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 5140 | risc_size = be32_to_cpu(fwcode[3]); |
| 5141 | |
| 5142 | /* Validate firmware image size. */ |
| 5143 | fwclen += risc_size * sizeof(uint32_t); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5144 | if (blob->fw->size < fwclen) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5145 | ql_log(ql_log_fatal, vha, 0x0096, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5146 | "Unable to verify integrity of firmware image " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5147 | "(%Zd).\n", blob->fw->size); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5148 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5149 | goto fail_fw_integrity; |
| 5150 | } |
| 5151 | |
| 5152 | fragment = 0; |
| 5153 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 5154 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 5155 | if (dlen > risc_size) |
| 5156 | dlen = risc_size; |
| 5157 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5158 | ql_dbg(ql_dbg_init, vha, 0x0097, |
| 5159 | "Loading risc segment@ risc addr %x " |
| 5160 | "number of dwords 0x%x.\n", risc_addr, dlen); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5161 | |
| 5162 | for (i = 0; i < dlen; i++) |
| 5163 | dcode[i] = swab32(fwcode[i]); |
| 5164 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5165 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
andrew.vasquez@qlogic.com | 590f98e | 2006-01-13 17:05:37 -0800 | [diff] [blame] | 5166 | dlen); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5167 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5168 | ql_log(ql_log_fatal, vha, 0x0098, |
| 5169 | "Failed to load segment %d of firmware.\n", |
| 5170 | fragment); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5171 | break; |
| 5172 | } |
| 5173 | |
| 5174 | fwcode += dlen; |
| 5175 | risc_addr += dlen; |
| 5176 | risc_size -= dlen; |
| 5177 | fragment++; |
| 5178 | } |
| 5179 | |
| 5180 | /* Next segment. */ |
| 5181 | segments--; |
| 5182 | } |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5183 | return rval; |
| 5184 | |
| 5185 | fail_fw_integrity: |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5186 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5187 | } |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5188 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5189 | int |
| 5190 | qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 5191 | { |
| 5192 | int rval; |
| 5193 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 5194 | if (ql2xfwloadbin == 1) |
| 5195 | return qla81xx_load_risc(vha, srisc_addr); |
| 5196 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5197 | /* |
| 5198 | * FW Load priority: |
| 5199 | * 1) Firmware via request-firmware interface (.bin file). |
| 5200 | * 2) Firmware residing in flash. |
| 5201 | */ |
| 5202 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 5203 | if (rval == QLA_SUCCESS) |
| 5204 | return rval; |
| 5205 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5206 | return qla24xx_load_risc_flash(vha, srisc_addr, |
| 5207 | vha->hw->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5208 | } |
| 5209 | |
| 5210 | int |
| 5211 | qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 5212 | { |
| 5213 | int rval; |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5214 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5215 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 5216 | if (ql2xfwloadbin == 2) |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5217 | goto try_blob_fw; |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 5218 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5219 | /* |
| 5220 | * FW Load priority: |
| 5221 | * 1) Firmware residing in flash. |
| 5222 | * 2) Firmware via request-firmware interface (.bin file). |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5223 | * 3) Golden-Firmware residing in flash -- limited operation. |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5224 | */ |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5225 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5226 | if (rval == QLA_SUCCESS) |
| 5227 | return rval; |
| 5228 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5229 | try_blob_fw: |
| 5230 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 5231 | if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw) |
| 5232 | return rval; |
| 5233 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5234 | ql_log(ql_log_info, vha, 0x0099, |
| 5235 | "Attempting to fallback to golden firmware.\n"); |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5236 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw); |
| 5237 | if (rval != QLA_SUCCESS) |
| 5238 | return rval; |
| 5239 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5240 | ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n"); |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5241 | ha->flags.running_gold_fw = 1; |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5242 | return rval; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5243 | } |
| 5244 | |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5245 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5246 | qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5247 | { |
| 5248 | int ret, retries; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5249 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5250 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 5251 | if (ha->flags.pci_channel_io_perm_failure) |
| 5252 | return; |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 5253 | if (!IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5254 | return; |
Andrew Vasquez | 75edf81 | 2007-05-07 07:43:00 -0700 | [diff] [blame] | 5255 | if (!ha->fw_major_version) |
| 5256 | return; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5257 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5258 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 7c7f1f2 | 2008-02-28 14:06:09 -0800 | [diff] [blame] | 5259 | for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT && |
Andrew Vasquez | b469a7c | 2009-04-06 22:33:48 -0700 | [diff] [blame] | 5260 | ret != QLA_INVALID_COMMAND && retries ; retries--) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5261 | ha->isp_ops->reset_chip(vha); |
| 5262 | if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5263 | continue; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5264 | if (qla2x00_setup_chip(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5265 | continue; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5266 | ql_log(ql_log_info, vha, 0x8015, |
| 5267 | "Attempting retry of stop-firmware command.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5268 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5269 | } |
| 5270 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5271 | |
| 5272 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5273 | qla24xx_configure_vhba(scsi_qla_host_t *vha) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5274 | { |
| 5275 | int rval = QLA_SUCCESS; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 5276 | int rval2; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5277 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5278 | struct qla_hw_data *ha = vha->hw; |
| 5279 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 5280 | struct req_que *req; |
| 5281 | struct rsp_que *rsp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5282 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5283 | if (!vha->vp_idx) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5284 | return -EINVAL; |
| 5285 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5286 | rval = qla2x00_fw_ready(base_vha); |
Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 5287 | if (ha->flags.cpu_affinity_enabled) |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 5288 | req = ha->req_q_map[0]; |
| 5289 | else |
| 5290 | req = vha->req; |
| 5291 | rsp = req->rsp; |
| 5292 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5293 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5294 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5295 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5296 | } |
| 5297 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5298 | vha->flags.management_server_logged_in = 0; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5299 | |
| 5300 | /* Login to SNS first */ |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 5301 | rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, |
| 5302 | BIT_1); |
| 5303 | if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) { |
| 5304 | if (rval2 == QLA_MEMORY_ALLOC_FAILED) |
| 5305 | ql_dbg(ql_dbg_init, vha, 0x0120, |
| 5306 | "Failed SNS login: loop_id=%x, rval2=%d\n", |
| 5307 | NPH_SNS, rval2); |
| 5308 | else |
| 5309 | ql_dbg(ql_dbg_init, vha, 0x0103, |
| 5310 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x " |
| 5311 | "mb[2]=%x mb[6]=%x mb[7]=%x.\n", |
| 5312 | NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5313 | return (QLA_FUNCTION_FAILED); |
| 5314 | } |
| 5315 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5316 | atomic_set(&vha->loop_down_timer, 0); |
| 5317 | atomic_set(&vha->loop_state, LOOP_UP); |
| 5318 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 5319 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 5320 | rval = qla2x00_loop_resync(base_vha); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5321 | |
| 5322 | return rval; |
| 5323 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5324 | |
| 5325 | /* 84XX Support **************************************************************/ |
| 5326 | |
| 5327 | static LIST_HEAD(qla_cs84xx_list); |
| 5328 | static DEFINE_MUTEX(qla_cs84xx_mutex); |
| 5329 | |
| 5330 | static struct qla_chip_state_84xx * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5331 | qla84xx_get_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5332 | { |
| 5333 | struct qla_chip_state_84xx *cs84xx; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5334 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5335 | |
| 5336 | mutex_lock(&qla_cs84xx_mutex); |
| 5337 | |
| 5338 | /* Find any shared 84xx chip. */ |
| 5339 | list_for_each_entry(cs84xx, &qla_cs84xx_list, list) { |
| 5340 | if (cs84xx->bus == ha->pdev->bus) { |
| 5341 | kref_get(&cs84xx->kref); |
| 5342 | goto done; |
| 5343 | } |
| 5344 | } |
| 5345 | |
| 5346 | cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL); |
| 5347 | if (!cs84xx) |
| 5348 | goto done; |
| 5349 | |
| 5350 | kref_init(&cs84xx->kref); |
| 5351 | spin_lock_init(&cs84xx->access_lock); |
| 5352 | mutex_init(&cs84xx->fw_update_mutex); |
| 5353 | cs84xx->bus = ha->pdev->bus; |
| 5354 | |
| 5355 | list_add_tail(&cs84xx->list, &qla_cs84xx_list); |
| 5356 | done: |
| 5357 | mutex_unlock(&qla_cs84xx_mutex); |
| 5358 | return cs84xx; |
| 5359 | } |
| 5360 | |
| 5361 | static void |
| 5362 | __qla84xx_chip_release(struct kref *kref) |
| 5363 | { |
| 5364 | struct qla_chip_state_84xx *cs84xx = |
| 5365 | container_of(kref, struct qla_chip_state_84xx, kref); |
| 5366 | |
| 5367 | mutex_lock(&qla_cs84xx_mutex); |
| 5368 | list_del(&cs84xx->list); |
| 5369 | mutex_unlock(&qla_cs84xx_mutex); |
| 5370 | kfree(cs84xx); |
| 5371 | } |
| 5372 | |
| 5373 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5374 | qla84xx_put_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5375 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5376 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5377 | if (ha->cs84xx) |
| 5378 | kref_put(&ha->cs84xx->kref, __qla84xx_chip_release); |
| 5379 | } |
| 5380 | |
| 5381 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5382 | qla84xx_init_chip(scsi_qla_host_t *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5383 | { |
| 5384 | int rval; |
| 5385 | uint16_t status[2]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5386 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5387 | |
| 5388 | mutex_lock(&ha->cs84xx->fw_update_mutex); |
| 5389 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5390 | rval = qla84xx_verify_chip(vha, status); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5391 | |
| 5392 | mutex_unlock(&ha->cs84xx->fw_update_mutex); |
| 5393 | |
| 5394 | return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED: |
| 5395 | QLA_SUCCESS; |
| 5396 | } |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5397 | |
| 5398 | /* 81XX Support **************************************************************/ |
| 5399 | |
| 5400 | int |
| 5401 | qla81xx_nvram_config(scsi_qla_host_t *vha) |
| 5402 | { |
| 5403 | int rval; |
| 5404 | struct init_cb_81xx *icb; |
| 5405 | struct nvram_81xx *nv; |
| 5406 | uint32_t *dptr; |
| 5407 | uint8_t *dptr1, *dptr2; |
| 5408 | uint32_t chksum; |
| 5409 | uint16_t cnt; |
| 5410 | struct qla_hw_data *ha = vha->hw; |
| 5411 | |
| 5412 | rval = QLA_SUCCESS; |
| 5413 | icb = (struct init_cb_81xx *)ha->init_cb; |
| 5414 | nv = ha->nvram; |
| 5415 | |
| 5416 | /* Determine NVRAM starting address. */ |
| 5417 | ha->nvram_size = sizeof(struct nvram_81xx); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5418 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5419 | |
| 5420 | /* Get VPD data into cache */ |
| 5421 | ha->vpd = ha->nvram + VPD_OFFSET; |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 5422 | ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2, |
| 5423 | ha->vpd_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5424 | |
| 5425 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 5426 | 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] | 5427 | ha->nvram_size); |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 5428 | dptr = (uint32_t *)nv; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5429 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++) |
| 5430 | chksum += le32_to_cpu(*dptr++); |
| 5431 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5432 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111, |
| 5433 | "Contents of NVRAM:\n"); |
| 5434 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112, |
| 5435 | (uint8_t *)nv, ha->nvram_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5436 | |
| 5437 | /* Bad NVRAM data, set defaults parameters. */ |
| 5438 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 5439 | || nv->id[3] != ' ' || |
| 5440 | nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) { |
| 5441 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5442 | ql_log(ql_log_info, vha, 0x0073, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 5443 | "Inconsistent NVRAM detected: checksum=0x%x id=%c " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5444 | "version=0x%x.\n", chksum, nv->id[0], |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5445 | le16_to_cpu(nv->nvram_version)); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5446 | ql_log(ql_log_info, vha, 0x0074, |
| 5447 | "Falling back to functioning (yet invalid -- WWPN) " |
| 5448 | "defaults.\n"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5449 | |
| 5450 | /* |
| 5451 | * Set default initialization control block. |
| 5452 | */ |
| 5453 | memset(nv, 0, ha->nvram_size); |
| 5454 | nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION); |
| 5455 | nv->version = __constant_cpu_to_le16(ICB_VERSION); |
| 5456 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 5457 | nv->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 5458 | nv->exchange_count = __constant_cpu_to_le16(0); |
| 5459 | nv->port_name[0] = 0x21; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5460 | nv->port_name[1] = 0x00 + ha->port_no; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5461 | nv->port_name[2] = 0x00; |
| 5462 | nv->port_name[3] = 0xe0; |
| 5463 | nv->port_name[4] = 0x8b; |
| 5464 | nv->port_name[5] = 0x1c; |
| 5465 | nv->port_name[6] = 0x55; |
| 5466 | nv->port_name[7] = 0x86; |
| 5467 | nv->node_name[0] = 0x20; |
| 5468 | nv->node_name[1] = 0x00; |
| 5469 | nv->node_name[2] = 0x00; |
| 5470 | nv->node_name[3] = 0xe0; |
| 5471 | nv->node_name[4] = 0x8b; |
| 5472 | nv->node_name[5] = 0x1c; |
| 5473 | nv->node_name[6] = 0x55; |
| 5474 | nv->node_name[7] = 0x86; |
| 5475 | nv->login_retry_count = __constant_cpu_to_le16(8); |
| 5476 | nv->interrupt_delay_timer = __constant_cpu_to_le16(0); |
| 5477 | nv->login_timeout = __constant_cpu_to_le16(0); |
| 5478 | nv->firmware_options_1 = |
| 5479 | __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 5480 | nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4); |
| 5481 | nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12); |
| 5482 | nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13); |
| 5483 | nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10); |
| 5484 | nv->efi_parameters = __constant_cpu_to_le32(0); |
| 5485 | nv->reset_delay = 5; |
| 5486 | nv->max_luns_per_target = __constant_cpu_to_le16(128); |
| 5487 | nv->port_down_retry_count = __constant_cpu_to_le16(30); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 5488 | nv->link_down_timeout = __constant_cpu_to_le16(180); |
Andrew Vasquez | eeebcc9 | 2009-06-03 09:55:24 -0700 | [diff] [blame] | 5489 | nv->enode_mac[0] = 0x00; |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 5490 | nv->enode_mac[1] = 0xC0; |
| 5491 | nv->enode_mac[2] = 0xDD; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5492 | nv->enode_mac[3] = 0x04; |
| 5493 | nv->enode_mac[4] = 0x05; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5494 | nv->enode_mac[5] = 0x06 + ha->port_no; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5495 | |
| 5496 | rval = 1; |
| 5497 | } |
| 5498 | |
Arun Easi | 9e522cd | 2012-08-22 14:21:31 -0400 | [diff] [blame] | 5499 | if (IS_T10_PI_CAPABLE(ha)) |
| 5500 | nv->frame_payload_size &= ~7; |
| 5501 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5502 | /* Reset Initialization control block */ |
Andrew Vasquez | 773120e | 2011-05-10 11:30:14 -0700 | [diff] [blame] | 5503 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5504 | |
| 5505 | /* Copy 1st segment. */ |
| 5506 | dptr1 = (uint8_t *)icb; |
| 5507 | dptr2 = (uint8_t *)&nv->version; |
| 5508 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 5509 | while (cnt--) |
| 5510 | *dptr1++ = *dptr2++; |
| 5511 | |
| 5512 | icb->login_retry_count = nv->login_retry_count; |
| 5513 | |
| 5514 | /* Copy 2nd segment. */ |
| 5515 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 5516 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 5517 | cnt = (uint8_t *)&icb->reserved_5 - |
| 5518 | (uint8_t *)&icb->interrupt_delay_timer; |
| 5519 | while (cnt--) |
| 5520 | *dptr1++ = *dptr2++; |
| 5521 | |
| 5522 | memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac)); |
| 5523 | /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */ |
| 5524 | 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] | 5525 | icb->enode_mac[0] = 0x00; |
| 5526 | icb->enode_mac[1] = 0xC0; |
| 5527 | icb->enode_mac[2] = 0xDD; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5528 | icb->enode_mac[3] = 0x04; |
| 5529 | icb->enode_mac[4] = 0x05; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5530 | icb->enode_mac[5] = 0x06 + ha->port_no; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5531 | } |
| 5532 | |
Andrew Vasquez | b64b0e8 | 2009-03-24 09:08:01 -0700 | [diff] [blame] | 5533 | /* Use extended-initialization control block. */ |
| 5534 | memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb)); |
| 5535 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5536 | /* |
| 5537 | * Setup driver NVRAM options. |
| 5538 | */ |
| 5539 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5540 | "QLE8XXX"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5541 | |
| 5542 | /* Use alternate WWN? */ |
| 5543 | if (nv->host_p & __constant_cpu_to_le32(BIT_15)) { |
| 5544 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 5545 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 5546 | } |
| 5547 | |
| 5548 | /* Prepare nodename */ |
| 5549 | if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) { |
| 5550 | /* |
| 5551 | * Firmware will apply the following mask if the nodename was |
| 5552 | * not provided. |
| 5553 | */ |
| 5554 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 5555 | icb->node_name[0] &= 0xF0; |
| 5556 | } |
| 5557 | |
| 5558 | /* Set host adapter parameters. */ |
| 5559 | ha->flags.disable_risc_code_load = 0; |
| 5560 | ha->flags.enable_lip_reset = 0; |
| 5561 | ha->flags.enable_lip_full_login = |
| 5562 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 5563 | ha->flags.enable_target_reset = |
| 5564 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
| 5565 | ha->flags.enable_led_scheme = 0; |
| 5566 | ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0; |
| 5567 | |
| 5568 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 5569 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 5570 | |
| 5571 | /* save HBA serial number */ |
| 5572 | ha->serial0 = icb->port_name[5]; |
| 5573 | ha->serial1 = icb->port_name[6]; |
| 5574 | ha->serial2 = icb->port_name[7]; |
| 5575 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 5576 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
| 5577 | |
| 5578 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 5579 | |
| 5580 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 5581 | |
| 5582 | /* Set minimum login_timeout to 4 seconds. */ |
| 5583 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 5584 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 5585 | if (le16_to_cpu(nv->login_timeout) < 4) |
| 5586 | nv->login_timeout = __constant_cpu_to_le16(4); |
| 5587 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
| 5588 | icb->login_timeout = nv->login_timeout; |
| 5589 | |
| 5590 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 5591 | ha->r_a_tov = 100; |
| 5592 | |
| 5593 | ha->loop_reset_delay = nv->reset_delay; |
| 5594 | |
| 5595 | /* Link Down Timeout = 0: |
| 5596 | * |
| 5597 | * When Port Down timer expires we will start returning |
| 5598 | * I/O's to OS with "DID_NO_CONNECT". |
| 5599 | * |
| 5600 | * Link Down Timeout != 0: |
| 5601 | * |
| 5602 | * The driver waits for the link to come up after link down |
| 5603 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 5604 | */ |
| 5605 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 5606 | ha->loop_down_abort_time = |
| 5607 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 5608 | } else { |
| 5609 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 5610 | ha->loop_down_abort_time = |
| 5611 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 5612 | } |
| 5613 | |
| 5614 | /* Need enough time to try and get the port back. */ |
| 5615 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 5616 | if (qlport_down_retry) |
| 5617 | ha->port_down_retry_count = qlport_down_retry; |
| 5618 | |
| 5619 | /* Set login_retry_count */ |
| 5620 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 5621 | if (ha->port_down_retry_count == |
| 5622 | le16_to_cpu(nv->port_down_retry_count) && |
| 5623 | ha->port_down_retry_count > 3) |
| 5624 | ha->login_retry_count = ha->port_down_retry_count; |
| 5625 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 5626 | ha->login_retry_count = ha->port_down_retry_count; |
| 5627 | if (ql2xloginretrycount) |
| 5628 | ha->login_retry_count = ql2xloginretrycount; |
| 5629 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 5630 | /* if not running MSI-X we need handshaking on interrupts */ |
| 5631 | if (!vha->hw->flags.msix_enabled && IS_QLA83XX(ha)) |
| 5632 | icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22); |
| 5633 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5634 | /* Enable ZIO. */ |
| 5635 | if (!vha->flags.init_done) { |
| 5636 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 5637 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 5638 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 5639 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 5640 | } |
| 5641 | icb->firmware_options_2 &= __constant_cpu_to_le32( |
| 5642 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
| 5643 | vha->flags.process_response_queue = 0; |
| 5644 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
| 5645 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 5646 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5647 | ql_log(ql_log_info, vha, 0x0075, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5648 | "ZIO mode %d enabled; timer delay (%d us).\n", |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5649 | ha->zio_mode, |
| 5650 | ha->zio_timer * 100); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5651 | |
| 5652 | icb->firmware_options_2 |= cpu_to_le32( |
| 5653 | (uint32_t)ha->zio_mode); |
| 5654 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
| 5655 | vha->flags.process_response_queue = 1; |
| 5656 | } |
| 5657 | |
| 5658 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5659 | ql_log(ql_log_warn, vha, 0x0076, |
| 5660 | "NVRAM configuration failed.\n"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5661 | } |
| 5662 | return (rval); |
| 5663 | } |
| 5664 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5665 | int |
| 5666 | qla82xx_restart_isp(scsi_qla_host_t *vha) |
| 5667 | { |
| 5668 | int status, rval; |
| 5669 | uint32_t wait_time; |
| 5670 | struct qla_hw_data *ha = vha->hw; |
| 5671 | struct req_que *req = ha->req_q_map[0]; |
| 5672 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
| 5673 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5674 | unsigned long flags; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5675 | |
| 5676 | status = qla2x00_init_rings(vha); |
| 5677 | if (!status) { |
| 5678 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 5679 | ha->flags.chip_reset_done = 1; |
| 5680 | |
| 5681 | status = qla2x00_fw_ready(vha); |
| 5682 | if (!status) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5683 | ql_log(ql_log_info, vha, 0x803c, |
| 5684 | "Start configure loop, status =%d.\n", status); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5685 | |
| 5686 | /* Issue a marker after FW becomes ready. */ |
| 5687 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
| 5688 | |
| 5689 | vha->flags.online = 1; |
| 5690 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 5691 | wait_time = 256; |
| 5692 | do { |
| 5693 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 5694 | qla2x00_configure_loop(vha); |
| 5695 | wait_time--; |
| 5696 | } while (!atomic_read(&vha->loop_down_timer) && |
| 5697 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) && |
| 5698 | wait_time && |
| 5699 | (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))); |
| 5700 | } |
| 5701 | |
| 5702 | /* if no cable then assume it's good */ |
| 5703 | if ((vha->device_flags & DFLG_NO_CABLE)) |
| 5704 | status = 0; |
| 5705 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5706 | ql_log(ql_log_info, vha, 0x8000, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5707 | "Configure loop done, status = 0x%x.\n", status); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5708 | } |
| 5709 | |
| 5710 | if (!status) { |
| 5711 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 5712 | |
| 5713 | if (!atomic_read(&vha->loop_down_timer)) { |
| 5714 | /* |
| 5715 | * Issue marker command only when we are going |
| 5716 | * to start the I/O . |
| 5717 | */ |
| 5718 | vha->marker_needed = 1; |
| 5719 | } |
| 5720 | |
| 5721 | vha->flags.online = 1; |
| 5722 | |
| 5723 | ha->isp_ops->enable_intrs(ha); |
| 5724 | |
| 5725 | ha->isp_abort_cnt = 0; |
| 5726 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 5727 | |
Saurav Kashyap | 5329678 | 2011-05-10 11:30:06 -0700 | [diff] [blame] | 5728 | /* Update the firmware version */ |
Giridhar Malavali | 3173167 | 2011-08-16 11:31:54 -0700 | [diff] [blame] | 5729 | status = qla82xx_check_md_needed(vha); |
Saurav Kashyap | 5329678 | 2011-05-10 11:30:06 -0700 | [diff] [blame] | 5730 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5731 | if (ha->fce) { |
| 5732 | ha->flags.fce_enabled = 1; |
| 5733 | memset(ha->fce, 0, |
| 5734 | fce_calc_size(ha->fce_bufs)); |
| 5735 | rval = qla2x00_enable_fce_trace(vha, |
| 5736 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 5737 | &ha->fce_bufs); |
| 5738 | if (rval) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5739 | ql_log(ql_log_warn, vha, 0x8001, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5740 | "Unable to reinitialize FCE (%d).\n", |
| 5741 | rval); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5742 | ha->flags.fce_enabled = 0; |
| 5743 | } |
| 5744 | } |
| 5745 | |
| 5746 | if (ha->eft) { |
| 5747 | memset(ha->eft, 0, EFT_SIZE); |
| 5748 | rval = qla2x00_enable_eft_trace(vha, |
| 5749 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 5750 | if (rval) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5751 | ql_log(ql_log_warn, vha, 0x8010, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5752 | "Unable to reinitialize EFT (%d).\n", |
| 5753 | rval); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5754 | } |
| 5755 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5756 | } |
| 5757 | |
| 5758 | if (!status) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5759 | ql_dbg(ql_dbg_taskm, vha, 0x8011, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5760 | "qla82xx_restart_isp succeeded.\n"); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5761 | |
| 5762 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5763 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 5764 | if (vp->vp_idx) { |
| 5765 | atomic_inc(&vp->vref_count); |
| 5766 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5767 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5768 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5769 | |
| 5770 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5771 | atomic_dec(&vp->vref_count); |
| 5772 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5773 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5774 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5775 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5776 | } else { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5777 | ql_log(ql_log_warn, vha, 0x8016, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5778 | "qla82xx_restart_isp **** FAILED ****.\n"); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5779 | } |
| 5780 | |
| 5781 | return status; |
| 5782 | } |
| 5783 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5784 | void |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 5785 | qla81xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5786 | { |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 5787 | struct qla_hw_data *ha = vha->hw; |
| 5788 | |
| 5789 | if (!ql2xetsenable) |
| 5790 | return; |
| 5791 | |
| 5792 | /* Enable ETS Burst. */ |
| 5793 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
| 5794 | ha->fw_options[2] |= BIT_9; |
| 5795 | qla2x00_set_fw_options(vha, ha->fw_options); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5796 | } |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5797 | |
| 5798 | /* |
| 5799 | * qla24xx_get_fcp_prio |
| 5800 | * Gets the fcp cmd priority value for the logged in port. |
| 5801 | * Looks for a match of the port descriptors within |
| 5802 | * each of the fcp prio config entries. If a match is found, |
| 5803 | * the tag (priority) value is returned. |
| 5804 | * |
| 5805 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5806 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5807 | * fcport = port structure pointer. |
| 5808 | * |
| 5809 | * Return: |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 5810 | * non-zero (if found) |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5811 | * -1 (if not found) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5812 | * |
| 5813 | * Context: |
| 5814 | * Kernel context |
| 5815 | */ |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5816 | static int |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5817 | qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 5818 | { |
| 5819 | int i, entries; |
| 5820 | uint8_t pid_match, wwn_match; |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5821 | int priority; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5822 | uint32_t pid1, pid2; |
| 5823 | uint64_t wwn1, wwn2; |
| 5824 | struct qla_fcp_prio_entry *pri_entry; |
| 5825 | struct qla_hw_data *ha = vha->hw; |
| 5826 | |
| 5827 | if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled) |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5828 | return -1; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5829 | |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5830 | priority = -1; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5831 | entries = ha->fcp_prio_cfg->num_entries; |
| 5832 | pri_entry = &ha->fcp_prio_cfg->entry[0]; |
| 5833 | |
| 5834 | for (i = 0; i < entries; i++) { |
| 5835 | pid_match = wwn_match = 0; |
| 5836 | |
| 5837 | if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) { |
| 5838 | pri_entry++; |
| 5839 | continue; |
| 5840 | } |
| 5841 | |
| 5842 | /* check source pid for a match */ |
| 5843 | if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) { |
| 5844 | pid1 = pri_entry->src_pid & INVALID_PORT_ID; |
| 5845 | pid2 = vha->d_id.b24 & INVALID_PORT_ID; |
| 5846 | if (pid1 == INVALID_PORT_ID) |
| 5847 | pid_match++; |
| 5848 | else if (pid1 == pid2) |
| 5849 | pid_match++; |
| 5850 | } |
| 5851 | |
| 5852 | /* check destination pid for a match */ |
| 5853 | if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) { |
| 5854 | pid1 = pri_entry->dst_pid & INVALID_PORT_ID; |
| 5855 | pid2 = fcport->d_id.b24 & INVALID_PORT_ID; |
| 5856 | if (pid1 == INVALID_PORT_ID) |
| 5857 | pid_match++; |
| 5858 | else if (pid1 == pid2) |
| 5859 | pid_match++; |
| 5860 | } |
| 5861 | |
| 5862 | /* check source WWN for a match */ |
| 5863 | if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) { |
| 5864 | wwn1 = wwn_to_u64(vha->port_name); |
| 5865 | wwn2 = wwn_to_u64(pri_entry->src_wwpn); |
| 5866 | if (wwn2 == (uint64_t)-1) |
| 5867 | wwn_match++; |
| 5868 | else if (wwn1 == wwn2) |
| 5869 | wwn_match++; |
| 5870 | } |
| 5871 | |
| 5872 | /* check destination WWN for a match */ |
| 5873 | if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) { |
| 5874 | wwn1 = wwn_to_u64(fcport->port_name); |
| 5875 | wwn2 = wwn_to_u64(pri_entry->dst_wwpn); |
| 5876 | if (wwn2 == (uint64_t)-1) |
| 5877 | wwn_match++; |
| 5878 | else if (wwn1 == wwn2) |
| 5879 | wwn_match++; |
| 5880 | } |
| 5881 | |
| 5882 | if (pid_match == 2 || wwn_match == 2) { |
| 5883 | /* Found a matching entry */ |
| 5884 | if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID) |
| 5885 | priority = pri_entry->tag; |
| 5886 | break; |
| 5887 | } |
| 5888 | |
| 5889 | pri_entry++; |
| 5890 | } |
| 5891 | |
| 5892 | return priority; |
| 5893 | } |
| 5894 | |
| 5895 | /* |
| 5896 | * qla24xx_update_fcport_fcp_prio |
| 5897 | * Activates fcp priority for the logged in fc port |
| 5898 | * |
| 5899 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5900 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5901 | * fcp = port structure pointer. |
| 5902 | * |
| 5903 | * Return: |
| 5904 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 5905 | * |
| 5906 | * Context: |
| 5907 | * Kernel context. |
| 5908 | */ |
| 5909 | int |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5910 | 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] | 5911 | { |
| 5912 | int ret; |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5913 | int priority; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5914 | uint16_t mb[5]; |
| 5915 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5916 | if (fcport->port_type != FCT_TARGET || |
| 5917 | fcport->loop_id == FC_NO_LOOP_ID) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5918 | return QLA_FUNCTION_FAILED; |
| 5919 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5920 | priority = qla24xx_get_fcp_prio(vha, fcport); |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5921 | if (priority < 0) |
| 5922 | return QLA_FUNCTION_FAILED; |
| 5923 | |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 5924 | if (IS_QLA82XX(vha->hw)) { |
| 5925 | fcport->fcp_prio = priority & 0xf; |
| 5926 | return QLA_SUCCESS; |
| 5927 | } |
| 5928 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5929 | ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb); |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5930 | if (ret == QLA_SUCCESS) { |
| 5931 | if (fcport->fcp_prio != priority) |
| 5932 | ql_dbg(ql_dbg_user, vha, 0x709e, |
| 5933 | "Updated FCP_CMND priority - value=%d loop_id=%d " |
| 5934 | "port_id=%02x%02x%02x.\n", priority, |
| 5935 | fcport->loop_id, fcport->d_id.b.domain, |
| 5936 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 5937 | fcport->fcp_prio = priority & 0xf; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5938 | } else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5939 | ql_dbg(ql_dbg_user, vha, 0x704f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5940 | "Unable to update FCP_CMND priority - ret=0x%x for " |
| 5941 | "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id, |
| 5942 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 5943 | fcport->d_id.b.al_pa); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5944 | return ret; |
| 5945 | } |
| 5946 | |
| 5947 | /* |
| 5948 | * qla24xx_update_all_fcp_prio |
| 5949 | * Activates fcp priority for all the logged in ports |
| 5950 | * |
| 5951 | * Input: |
| 5952 | * ha = adapter block pointer. |
| 5953 | * |
| 5954 | * Return: |
| 5955 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 5956 | * |
| 5957 | * Context: |
| 5958 | * Kernel context. |
| 5959 | */ |
| 5960 | int |
| 5961 | qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha) |
| 5962 | { |
| 5963 | int ret; |
| 5964 | fc_port_t *fcport; |
| 5965 | |
| 5966 | ret = QLA_FUNCTION_FAILED; |
| 5967 | /* We need to set priority for all logged in ports */ |
| 5968 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 5969 | ret = qla24xx_update_fcport_fcp_prio(vha, fcport); |
| 5970 | |
| 5971 | return ret; |
| 5972 | } |