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); |
Chad Dupuis | b00ee7d | 2013-02-08 01:57:50 -0500 | [diff] [blame^] | 73 | qla2x00_rel_sp(vha, sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 76 | /* Asynchronous Login/Logout Routines -------------------------------------- */ |
| 77 | |
Saurav Kashyap | a9b6f72 | 2012-08-22 14:21:01 -0400 | [diff] [blame] | 78 | unsigned long |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 79 | qla2x00_get_async_timeout(struct scsi_qla_host *vha) |
| 80 | { |
| 81 | unsigned long tmo; |
| 82 | struct qla_hw_data *ha = vha->hw; |
| 83 | |
| 84 | /* Firmware should use switch negotiated r_a_tov for timeout. */ |
| 85 | tmo = ha->r_a_tov / 10 * 2; |
| 86 | if (!IS_FWI2_CAPABLE(ha)) { |
| 87 | /* |
| 88 | * Except for earlier ISPs where the timeout is seeded from the |
| 89 | * initialization control block. |
| 90 | */ |
| 91 | tmo = ha->login_timeout; |
| 92 | } |
| 93 | return tmo; |
| 94 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 95 | |
| 96 | static void |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 97 | qla2x00_async_iocb_timeout(void *data) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 98 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 99 | srb_t *sp = (srb_t *)data; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 100 | fc_port_t *fcport = sp->fcport; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 101 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 102 | ql_dbg(ql_dbg_disc, fcport->vha, 0x2071, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 103 | "Async-%s timeout - hdl=%x portid=%02x%02x%02x.\n", |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 104 | 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] | 105 | fcport->d_id.b.al_pa); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 106 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 107 | fcport->flags &= ~FCF_ASYNC_SENT; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 108 | if (sp->type == SRB_LOGIN_CMD) { |
| 109 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 110 | qla2x00_post_async_logout_work(fcport->vha, fcport, NULL); |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 111 | /* Retry as needed. */ |
| 112 | lio->u.logio.data[0] = MBS_COMMAND_ERROR; |
| 113 | lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ? |
| 114 | QLA_LOGIO_LOGIN_RETRIED : 0; |
| 115 | qla2x00_post_async_login_done_work(fcport->vha, fcport, |
| 116 | lio->u.logio.data); |
| 117 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 120 | static void |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 121 | qla2x00_async_login_sp_done(void *data, void *ptr, int res) |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 122 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 123 | srb_t *sp = (srb_t *)ptr; |
| 124 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
| 125 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 126 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 127 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
| 128 | qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport, |
| 129 | lio->u.logio.data); |
| 130 | sp->free(sp->fcport->vha, sp); |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 133 | int |
| 134 | qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 135 | uint16_t *data) |
| 136 | { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 137 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 138 | struct srb_iocb *lio; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 139 | int rval; |
| 140 | |
| 141 | rval = QLA_FUNCTION_FAILED; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 142 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 143 | if (!sp) |
| 144 | goto done; |
| 145 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 146 | sp->type = SRB_LOGIN_CMD; |
| 147 | sp->name = "login"; |
| 148 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 149 | |
| 150 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 151 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 152 | sp->done = qla2x00_async_login_sp_done; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 153 | lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 154 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 155 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 156 | rval = qla2x00_start_sp(sp); |
| 157 | if (rval != QLA_SUCCESS) |
| 158 | goto done_free_sp; |
| 159 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 160 | ql_dbg(ql_dbg_disc, vha, 0x2072, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 161 | "Async-login - hdl=%x, loopid=%x portid=%02x%02x%02x " |
| 162 | "retries=%d.\n", sp->handle, fcport->loop_id, |
| 163 | fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 164 | fcport->login_retry); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 165 | return rval; |
| 166 | |
| 167 | done_free_sp: |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 168 | sp->free(fcport->vha, sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 169 | done: |
| 170 | return rval; |
| 171 | } |
| 172 | |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 173 | static void |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 174 | qla2x00_async_logout_sp_done(void *data, void *ptr, int res) |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 175 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 176 | srb_t *sp = (srb_t *)ptr; |
| 177 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
| 178 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 179 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 180 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
| 181 | qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport, |
| 182 | lio->u.logio.data); |
| 183 | sp->free(sp->fcport->vha, sp); |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 186 | int |
| 187 | qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 188 | { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 189 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 190 | struct srb_iocb *lio; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 191 | int rval; |
| 192 | |
| 193 | rval = QLA_FUNCTION_FAILED; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 194 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 195 | if (!sp) |
| 196 | goto done; |
| 197 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 198 | sp->type = SRB_LOGOUT_CMD; |
| 199 | sp->name = "logout"; |
| 200 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 201 | |
| 202 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 203 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 204 | sp->done = qla2x00_async_logout_sp_done; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 205 | rval = qla2x00_start_sp(sp); |
| 206 | if (rval != QLA_SUCCESS) |
| 207 | goto done_free_sp; |
| 208 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 209 | ql_dbg(ql_dbg_disc, vha, 0x2070, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 210 | "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x.\n", |
| 211 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
| 212 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 213 | return rval; |
| 214 | |
| 215 | done_free_sp: |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 216 | sp->free(fcport->vha, sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 217 | done: |
| 218 | return rval; |
| 219 | } |
| 220 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 221 | static void |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 222 | qla2x00_async_adisc_sp_done(void *data, void *ptr, int res) |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 223 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 224 | srb_t *sp = (srb_t *)ptr; |
| 225 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
| 226 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 227 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 228 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
| 229 | qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport, |
| 230 | lio->u.logio.data); |
| 231 | sp->free(sp->fcport->vha, sp); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | int |
| 235 | qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 236 | uint16_t *data) |
| 237 | { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 238 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 239 | struct srb_iocb *lio; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 240 | int rval; |
| 241 | |
| 242 | rval = QLA_FUNCTION_FAILED; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 243 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 244 | if (!sp) |
| 245 | goto done; |
| 246 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 247 | sp->type = SRB_ADISC_CMD; |
| 248 | sp->name = "adisc"; |
| 249 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 250 | |
| 251 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 252 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 253 | sp->done = qla2x00_async_adisc_sp_done; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 254 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 255 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 256 | rval = qla2x00_start_sp(sp); |
| 257 | if (rval != QLA_SUCCESS) |
| 258 | goto done_free_sp; |
| 259 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 260 | ql_dbg(ql_dbg_disc, vha, 0x206f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 261 | "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n", |
| 262 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
| 263 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 264 | return rval; |
| 265 | |
| 266 | done_free_sp: |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 267 | sp->free(fcport->vha, sp); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 268 | done: |
| 269 | return rval; |
| 270 | } |
| 271 | |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 272 | static void |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 273 | qla2x00_async_tm_cmd_done(void *data, void *ptr, int res) |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 274 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 275 | srb_t *sp = (srb_t *)ptr; |
| 276 | struct srb_iocb *iocb = &sp->u.iocb_cmd; |
| 277 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; |
| 278 | uint32_t flags; |
| 279 | uint16_t lun; |
| 280 | int rval; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 281 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 282 | if (!test_bit(UNLOADING, &vha->dpc_flags)) { |
| 283 | flags = iocb->u.tmf.flags; |
| 284 | lun = (uint16_t)iocb->u.tmf.lun; |
| 285 | |
| 286 | /* Issue Marker IOCB */ |
| 287 | rval = qla2x00_marker(vha, vha->hw->req_q_map[0], |
| 288 | vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun, |
| 289 | flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID); |
| 290 | |
| 291 | if ((rval != QLA_SUCCESS) || iocb->u.tmf.data) { |
| 292 | ql_dbg(ql_dbg_taskm, vha, 0x8030, |
| 293 | "TM IOCB failed (%x).\n", rval); |
| 294 | } |
| 295 | } |
| 296 | sp->free(sp->fcport->vha, sp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | int |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 300 | 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] | 301 | uint32_t tag) |
| 302 | { |
| 303 | struct scsi_qla_host *vha = fcport->vha; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 304 | srb_t *sp; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 305 | struct srb_iocb *tcf; |
| 306 | int rval; |
| 307 | |
| 308 | rval = QLA_FUNCTION_FAILED; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 309 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 310 | if (!sp) |
| 311 | goto done; |
| 312 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 313 | sp->type = SRB_TM_CMD; |
| 314 | sp->name = "tmf"; |
| 315 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 316 | |
| 317 | tcf = &sp->u.iocb_cmd; |
| 318 | tcf->u.tmf.flags = tm_flags; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 319 | tcf->u.tmf.lun = lun; |
| 320 | tcf->u.tmf.data = tag; |
| 321 | tcf->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 322 | sp->done = qla2x00_async_tm_cmd_done; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 323 | |
| 324 | rval = qla2x00_start_sp(sp); |
| 325 | if (rval != QLA_SUCCESS) |
| 326 | goto done_free_sp; |
| 327 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 328 | ql_dbg(ql_dbg_taskm, vha, 0x802f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 329 | "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n", |
| 330 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
| 331 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 332 | return rval; |
| 333 | |
| 334 | done_free_sp: |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 335 | sp->free(fcport->vha, sp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 336 | done: |
| 337 | return rval; |
| 338 | } |
| 339 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 340 | void |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 341 | qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 342 | uint16_t *data) |
| 343 | { |
| 344 | int rval; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 345 | |
| 346 | switch (data[0]) { |
| 347 | case MBS_COMMAND_COMPLETE: |
Andrew Vasquez | a4f92a3 | 2011-03-30 11:46:31 -0700 | [diff] [blame] | 348 | /* |
| 349 | * Driver must validate login state - If PRLI not complete, |
| 350 | * force a relogin attempt via implicit LOGO, PLOGI, and PRLI |
| 351 | * requests. |
| 352 | */ |
| 353 | rval = qla2x00_get_port_database(vha, fcport, 0); |
Arun Easi | 0eba25d | 2012-02-09 11:15:58 -0800 | [diff] [blame] | 354 | if (rval == QLA_NOT_LOGGED_IN) { |
| 355 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 356 | fcport->flags |= FCF_LOGIN_NEEDED; |
| 357 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 358 | break; |
| 359 | } |
| 360 | |
Andrew Vasquez | a4f92a3 | 2011-03-30 11:46:31 -0700 | [diff] [blame] | 361 | if (rval != QLA_SUCCESS) { |
| 362 | qla2x00_post_async_logout_work(vha, fcport, NULL); |
| 363 | qla2x00_post_async_login_work(vha, fcport, NULL); |
| 364 | break; |
| 365 | } |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 366 | if (fcport->flags & FCF_FCP2_DEVICE) { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 367 | qla2x00_post_async_adisc_work(vha, fcport, data); |
| 368 | break; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 369 | } |
| 370 | qla2x00_update_fcport(vha, fcport); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 371 | break; |
| 372 | case MBS_COMMAND_ERROR: |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 373 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 374 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
| 375 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 376 | else |
Andrew Vasquez | 80d7944 | 2011-03-30 11:46:17 -0700 | [diff] [blame] | 377 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 378 | break; |
| 379 | case MBS_PORT_ID_USED: |
| 380 | fcport->loop_id = data[1]; |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 381 | qla2x00_post_async_logout_work(vha, fcport, NULL); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 382 | qla2x00_post_async_login_work(vha, fcport, NULL); |
| 383 | break; |
| 384 | case MBS_LOOP_ID_USED: |
| 385 | fcport->loop_id++; |
| 386 | rval = qla2x00_find_new_loop_id(vha, fcport); |
| 387 | if (rval != QLA_SUCCESS) { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 388 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | 80d7944 | 2011-03-30 11:46:17 -0700 | [diff] [blame] | 389 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 390 | break; |
| 391 | } |
| 392 | qla2x00_post_async_login_work(vha, fcport, NULL); |
| 393 | break; |
| 394 | } |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 395 | return; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 396 | } |
| 397 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 398 | void |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 399 | qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 400 | uint16_t *data) |
| 401 | { |
| 402 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 403 | return; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 406 | void |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 407 | qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 408 | uint16_t *data) |
| 409 | { |
| 410 | if (data[0] == MBS_COMMAND_COMPLETE) { |
| 411 | qla2x00_update_fcport(vha, fcport); |
| 412 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 413 | return; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | /* Retry login. */ |
| 417 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 418 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
| 419 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 420 | else |
Andrew Vasquez | 80d7944 | 2011-03-30 11:46:17 -0700 | [diff] [blame] | 421 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 422 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 423 | return; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 424 | } |
| 425 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | /****************************************************************************/ |
| 427 | /* QLogic ISP2x00 Hardware Support Functions. */ |
| 428 | /****************************************************************************/ |
| 429 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 430 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 431 | qla83xx_nic_core_fw_load(scsi_qla_host_t *vha) |
| 432 | { |
| 433 | int rval = QLA_SUCCESS; |
| 434 | struct qla_hw_data *ha = vha->hw; |
| 435 | uint32_t idc_major_ver, idc_minor_ver; |
Saurav Kashyap | 711aa7f | 2012-08-22 14:21:15 -0400 | [diff] [blame] | 436 | uint16_t config[4]; |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 437 | |
| 438 | qla83xx_idc_lock(vha, 0); |
| 439 | |
| 440 | /* SV: TODO: Assign initialization timeout from |
| 441 | * flash-info / other param |
| 442 | */ |
| 443 | ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT; |
| 444 | ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT; |
| 445 | |
| 446 | /* Set our fcoe function presence */ |
| 447 | if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) { |
| 448 | ql_dbg(ql_dbg_p3p, vha, 0xb077, |
| 449 | "Error while setting DRV-Presence.\n"); |
| 450 | rval = QLA_FUNCTION_FAILED; |
| 451 | goto exit; |
| 452 | } |
| 453 | |
| 454 | /* Decide the reset ownership */ |
| 455 | qla83xx_reset_ownership(vha); |
| 456 | |
| 457 | /* |
| 458 | * On first protocol driver load: |
| 459 | * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery |
| 460 | * register. |
| 461 | * Others: Check compatibility with current IDC Major version. |
| 462 | */ |
| 463 | qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver); |
| 464 | if (ha->flags.nic_core_reset_owner) { |
| 465 | /* Set IDC Major version */ |
| 466 | idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION; |
| 467 | qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver); |
| 468 | |
| 469 | /* Clearing IDC-Lock-Recovery register */ |
| 470 | qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0); |
| 471 | } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) { |
| 472 | /* |
| 473 | * Clear further IDC participation if we are not compatible with |
| 474 | * the current IDC Major Version. |
| 475 | */ |
| 476 | ql_log(ql_log_warn, vha, 0xb07d, |
| 477 | "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n", |
| 478 | idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION); |
| 479 | __qla83xx_clear_drv_presence(vha); |
| 480 | rval = QLA_FUNCTION_FAILED; |
| 481 | goto exit; |
| 482 | } |
| 483 | /* Each function sets its supported Minor version. */ |
| 484 | qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver); |
| 485 | idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2)); |
| 486 | qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver); |
| 487 | |
Saurav Kashyap | 711aa7f | 2012-08-22 14:21:15 -0400 | [diff] [blame] | 488 | if (ha->flags.nic_core_reset_owner) { |
| 489 | memset(config, 0, sizeof(config)); |
| 490 | if (!qla81xx_get_port_config(vha, config)) |
| 491 | qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, |
| 492 | QLA8XXX_DEV_READY); |
| 493 | } |
| 494 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 495 | rval = qla83xx_idc_state_handler(vha); |
| 496 | |
| 497 | exit: |
| 498 | qla83xx_idc_unlock(vha, 0); |
| 499 | |
| 500 | return rval; |
| 501 | } |
| 502 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | /* |
| 504 | * qla2x00_initialize_adapter |
| 505 | * Initialize board. |
| 506 | * |
| 507 | * Input: |
| 508 | * ha = adapter block pointer. |
| 509 | * |
| 510 | * Returns: |
| 511 | * 0 = success |
| 512 | */ |
| 513 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 514 | qla2x00_initialize_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | { |
| 516 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 517 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 518 | struct req_que *req = ha->req_q_map[0]; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 519 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | /* Clear adapter flags. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 521 | vha->flags.online = 0; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 522 | ha->flags.chip_reset_done = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 523 | vha->flags.reset_active = 0; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 524 | ha->flags.pci_channel_io_perm_failure = 0; |
| 525 | ha->flags.eeh_busy = 0; |
Andrew Vasquez | 794a569 | 2010-12-21 16:00:21 -0800 | [diff] [blame] | 526 | ha->flags.thermal_supported = 1; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 527 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 528 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 529 | vha->device_flags = DFLG_NO_CABLE; |
| 530 | vha->dpc_flags = 0; |
| 531 | vha->flags.management_server_logged_in = 0; |
| 532 | vha->marker_needed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | ha->isp_abort_cnt = 0; |
| 534 | ha->beacon_blink_led = 0; |
| 535 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 536 | set_bit(0, ha->req_qid_map); |
| 537 | set_bit(0, ha->rsp_qid_map); |
| 538 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 539 | ql_dbg(ql_dbg_init, vha, 0x0040, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 540 | "Configuring PCI space...\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 541 | rval = ha->isp_ops->pci_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 543 | ql_log(ql_log_warn, vha, 0x0044, |
| 544 | "Unable to configure PCI space.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | return (rval); |
| 546 | } |
| 547 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 548 | ha->isp_ops->reset_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 550 | rval = qla2xxx_get_flash_info(vha); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 551 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 552 | ql_log(ql_log_fatal, vha, 0x004f, |
| 553 | "Unable to validate FLASH data.\n"); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 554 | return (rval); |
| 555 | } |
| 556 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 557 | ha->isp_ops->get_flash_version(vha, req->ring); |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 558 | ql_dbg(ql_dbg_init, vha, 0x0061, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 559 | "Configure NVRAM parameters...\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 560 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 561 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 563 | if (ha->flags.disable_serdes) { |
| 564 | /* Mask HBA via NVRAM settings? */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 565 | ql_log(ql_log_info, vha, 0x0077, |
| 566 | "Masking HBA WWPN " |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 567 | "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 568 | vha->port_name[0], vha->port_name[1], |
| 569 | vha->port_name[2], vha->port_name[3], |
| 570 | vha->port_name[4], vha->port_name[5], |
| 571 | vha->port_name[6], vha->port_name[7]); |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 572 | return QLA_FUNCTION_FAILED; |
| 573 | } |
| 574 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 575 | ql_dbg(ql_dbg_init, vha, 0x0078, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 576 | "Verifying loaded RISC code...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 578 | if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) { |
| 579 | rval = ha->isp_ops->chip_diag(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 580 | if (rval) |
| 581 | return (rval); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 582 | rval = qla2x00_setup_chip(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 583 | if (rval) |
| 584 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 586 | |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 587 | if (IS_QLA84XX(ha)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 588 | ha->cs84xx = qla84xx_get_chip(vha); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 589 | if (!ha->cs84xx) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 590 | ql_log(ql_log_warn, vha, 0x00d0, |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 591 | "Unable to configure ISP84XX.\n"); |
| 592 | return QLA_FUNCTION_FAILED; |
| 593 | } |
| 594 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 595 | |
| 596 | if (qla_ini_mode_enabled(vha)) |
| 597 | rval = qla2x00_init_rings(vha); |
| 598 | |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 599 | ha->flags.chip_reset_done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 601 | if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) { |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 602 | /* Issue verify 84xx FW IOCB to complete 84xx initialization */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 603 | rval = qla84xx_init_chip(vha); |
| 604 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 605 | ql_log(ql_log_warn, vha, 0x00d4, |
| 606 | "Unable to initialize ISP84XX.\n"); |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 607 | qla84xx_put_chip(vha); |
| 608 | } |
| 609 | } |
| 610 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 611 | /* Load the NIC Core f/w if we are the first protocol driver. */ |
| 612 | if (IS_QLA8031(ha)) { |
| 613 | rval = qla83xx_nic_core_fw_load(vha); |
| 614 | if (rval) |
| 615 | ql_log(ql_log_warn, vha, 0x0124, |
| 616 | "Error in initializing NIC Core f/w.\n"); |
| 617 | } |
| 618 | |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 619 | if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)) |
| 620 | qla24xx_read_fcp_prio_cfg(vha); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 621 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | return (rval); |
| 623 | } |
| 624 | |
| 625 | /** |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 626 | * qla2100_pci_config() - Setup ISP21xx PCI configuration registers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | * @ha: HA context |
| 628 | * |
| 629 | * Returns 0 on success. |
| 630 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 631 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 632 | qla2100_pci_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 634 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 635 | unsigned long flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 636 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 637 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 640 | pci_try_set_mwi(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 643 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 645 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 646 | pci_disable_rom(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 648 | /* Get PCI bus information. */ |
| 649 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 650 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 651 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 652 | |
| 653 | return QLA_SUCCESS; |
| 654 | } |
| 655 | |
| 656 | /** |
| 657 | * qla2300_pci_config() - Setup ISP23xx PCI configuration registers. |
| 658 | * @ha: HA context |
| 659 | * |
| 660 | * Returns 0 on success. |
| 661 | */ |
| 662 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 663 | qla2300_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 664 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 665 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 666 | unsigned long flags = 0; |
| 667 | uint32_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 668 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 669 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 670 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 671 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 672 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 673 | |
| 674 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 675 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 676 | |
| 677 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 678 | w &= ~PCI_COMMAND_INTX_DISABLE; |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 679 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 680 | |
| 681 | /* |
| 682 | * If this is a 2300 card and not 2312, reset the |
| 683 | * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately, |
| 684 | * the 2310 also reports itself as a 2300 so we need to get the |
| 685 | * fb revision level -- a 6 indicates it really is a 2300 and |
| 686 | * not a 2310. |
| 687 | */ |
| 688 | if (IS_QLA2300(ha)) { |
| 689 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 690 | |
| 691 | /* Pause RISC. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 692 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 693 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 694 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 695 | break; |
| 696 | |
| 697 | udelay(10); |
| 698 | } |
| 699 | |
| 700 | /* Select FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 701 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 702 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 703 | |
| 704 | /* Get the fb rev level */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 705 | ha->fb_rev = RD_FB_CMD_REG(ha, reg); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 706 | |
| 707 | if (ha->fb_rev == FPM_2300) |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 708 | pci_clear_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 709 | |
| 710 | /* Deselect FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 711 | WRT_REG_WORD(®->ctrl_status, 0x0); |
| 712 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 713 | |
| 714 | /* Release RISC module. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 715 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 716 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 717 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 718 | break; |
| 719 | |
| 720 | udelay(10); |
| 721 | } |
| 722 | |
| 723 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 724 | } |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 725 | |
| 726 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 727 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 728 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 729 | |
| 730 | /* Get PCI bus information. */ |
| 731 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 732 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 733 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 734 | |
| 735 | return QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 739 | * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers. |
| 740 | * @ha: HA context |
| 741 | * |
| 742 | * Returns 0 on success. |
| 743 | */ |
| 744 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 745 | qla24xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 746 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 747 | uint16_t w; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 748 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 749 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 750 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 751 | |
| 752 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 753 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 754 | |
| 755 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 756 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 757 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 758 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 759 | |
| 760 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 761 | |
| 762 | /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */ |
Andrew Vasquez | f85ec18 | 2007-07-19 15:06:01 -0700 | [diff] [blame] | 763 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX)) |
| 764 | pcix_set_mmrbc(ha->pdev, 2048); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 765 | |
| 766 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Jon Mason | e67f132 | 2012-07-10 14:57:56 -0700 | [diff] [blame] | 767 | if (pci_is_pcie(ha->pdev)) |
Chad Dupuis | 5ffd3a5 | 2012-08-22 14:21:26 -0400 | [diff] [blame] | 768 | pcie_set_readrq(ha->pdev, 4096); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 769 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 770 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 771 | |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 772 | ha->chip_revision = ha->pdev->revision; |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 773 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 774 | /* Get PCI bus information. */ |
| 775 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 776 | ha->pci_attr = RD_REG_DWORD(®->ctrl_status); |
| 777 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 778 | |
| 779 | return QLA_SUCCESS; |
| 780 | } |
| 781 | |
| 782 | /** |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 783 | * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers. |
| 784 | * @ha: HA context |
| 785 | * |
| 786 | * Returns 0 on success. |
| 787 | */ |
| 788 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 789 | qla25xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 790 | { |
| 791 | uint16_t w; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 792 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 793 | |
| 794 | pci_set_master(ha->pdev); |
| 795 | pci_try_set_mwi(ha->pdev); |
| 796 | |
| 797 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
| 798 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
| 799 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 800 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 801 | |
| 802 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Jon Mason | e67f132 | 2012-07-10 14:57:56 -0700 | [diff] [blame] | 803 | if (pci_is_pcie(ha->pdev)) |
Chad Dupuis | 5ffd3a5 | 2012-08-22 14:21:26 -0400 | [diff] [blame] | 804 | pcie_set_readrq(ha->pdev, 4096); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 805 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 806 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 807 | |
| 808 | ha->chip_revision = ha->pdev->revision; |
| 809 | |
| 810 | return QLA_SUCCESS; |
| 811 | } |
| 812 | |
| 813 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | * qla2x00_isp_firmware() - Choose firmware image. |
| 815 | * @ha: HA context |
| 816 | * |
| 817 | * Returns 0 on success. |
| 818 | */ |
| 819 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 820 | qla2x00_isp_firmware(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | { |
| 822 | int rval; |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 823 | uint16_t loop_id, topo, sw_cap; |
| 824 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 825 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | |
| 827 | /* Assume loading risc code */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 828 | rval = QLA_FUNCTION_FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | |
| 830 | if (ha->flags.disable_risc_code_load) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 831 | ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | |
| 833 | /* Verify checksum of loaded RISC code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 834 | rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address); |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 835 | if (rval == QLA_SUCCESS) { |
| 836 | /* And, verify we are not in ROM code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 837 | rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa, |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 838 | &area, &domain, &topo, &sw_cap); |
| 839 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | } |
| 841 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 842 | if (rval) |
| 843 | ql_dbg(ql_dbg_init, vha, 0x007a, |
| 844 | "**** Load RISC code ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | |
| 846 | return (rval); |
| 847 | } |
| 848 | |
| 849 | /** |
| 850 | * qla2x00_reset_chip() - Reset ISP chip. |
| 851 | * @ha: HA context |
| 852 | * |
| 853 | * Returns 0 on success. |
| 854 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 855 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 856 | qla2x00_reset_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | { |
| 858 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 859 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 860 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | uint32_t cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | uint16_t cmd; |
| 863 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 864 | if (unlikely(pci_channel_offline(ha->pdev))) |
| 865 | return; |
| 866 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 867 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | |
| 869 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 870 | |
| 871 | /* Turn off master enable */ |
| 872 | cmd = 0; |
| 873 | pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd); |
| 874 | cmd &= ~PCI_COMMAND_MASTER; |
| 875 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 876 | |
| 877 | if (!IS_QLA2100(ha)) { |
| 878 | /* Pause RISC. */ |
| 879 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
| 880 | if (IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 881 | for (cnt = 0; cnt < 30000; cnt++) { |
| 882 | if ((RD_REG_WORD(®->hccr) & |
| 883 | HCCR_RISC_PAUSE) != 0) |
| 884 | break; |
| 885 | udelay(100); |
| 886 | } |
| 887 | } else { |
| 888 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 889 | udelay(10); |
| 890 | } |
| 891 | |
| 892 | /* Select FPM registers. */ |
| 893 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 894 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 895 | |
| 896 | /* FPM Soft Reset. */ |
| 897 | WRT_REG_WORD(®->fpm_diag_config, 0x100); |
| 898 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 899 | |
| 900 | /* Toggle Fpm Reset. */ |
| 901 | if (!IS_QLA2200(ha)) { |
| 902 | WRT_REG_WORD(®->fpm_diag_config, 0x0); |
| 903 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 904 | } |
| 905 | |
| 906 | /* Select frame buffer registers. */ |
| 907 | WRT_REG_WORD(®->ctrl_status, 0x10); |
| 908 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 909 | |
| 910 | /* Reset frame buffer FIFOs. */ |
| 911 | if (IS_QLA2200(ha)) { |
| 912 | WRT_FB_CMD_REG(ha, reg, 0xa000); |
| 913 | RD_FB_CMD_REG(ha, reg); /* PCI Posting. */ |
| 914 | } else { |
| 915 | WRT_FB_CMD_REG(ha, reg, 0x00fc); |
| 916 | |
| 917 | /* Read back fb_cmd until zero or 3 seconds max */ |
| 918 | for (cnt = 0; cnt < 3000; cnt++) { |
| 919 | if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0) |
| 920 | break; |
| 921 | udelay(100); |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | /* Select RISC module registers. */ |
| 926 | WRT_REG_WORD(®->ctrl_status, 0); |
| 927 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 928 | |
| 929 | /* Reset RISC processor. */ |
| 930 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 931 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 932 | |
| 933 | /* Release RISC processor. */ |
| 934 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 935 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 936 | } |
| 937 | |
| 938 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); |
| 939 | WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT); |
| 940 | |
| 941 | /* Reset ISP chip. */ |
| 942 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 943 | |
| 944 | /* Wait for RISC to recover from reset. */ |
| 945 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 946 | /* |
| 947 | * It is necessary to for a delay here since the card doesn't |
| 948 | * respond to PCI reads during a reset. On some architectures |
| 949 | * this will result in an MCA. |
| 950 | */ |
| 951 | udelay(20); |
| 952 | for (cnt = 30000; cnt; cnt--) { |
| 953 | if ((RD_REG_WORD(®->ctrl_status) & |
| 954 | CSR_ISP_SOFT_RESET) == 0) |
| 955 | break; |
| 956 | udelay(100); |
| 957 | } |
| 958 | } else |
| 959 | udelay(10); |
| 960 | |
| 961 | /* Reset RISC processor. */ |
| 962 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 963 | |
| 964 | WRT_REG_WORD(®->semaphore, 0); |
| 965 | |
| 966 | /* Release RISC processor. */ |
| 967 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 968 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 969 | |
| 970 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 971 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | ffb39f0 | 2006-05-17 15:09:06 -0700 | [diff] [blame] | 972 | if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | |
| 975 | udelay(100); |
| 976 | } |
| 977 | } else |
| 978 | udelay(100); |
| 979 | |
| 980 | /* Turn on master enable */ |
| 981 | cmd |= PCI_COMMAND_MASTER; |
| 982 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 983 | |
| 984 | /* Disable RISC pause on FPM parity error. */ |
| 985 | if (!IS_QLA2100(ha)) { |
| 986 | WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE); |
| 987 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 988 | } |
| 989 | |
| 990 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 991 | } |
| 992 | |
| 993 | /** |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 994 | * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC. |
| 995 | * |
| 996 | * Returns 0 on success. |
| 997 | */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 998 | static int |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 999 | qla81xx_reset_mpi(scsi_qla_host_t *vha) |
| 1000 | { |
| 1001 | uint16_t mb[4] = {0x1010, 0, 1, 0}; |
| 1002 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1003 | if (!IS_QLA81XX(vha->hw)) |
| 1004 | return QLA_SUCCESS; |
| 1005 | |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 1006 | return qla81xx_write_mpi_register(vha, mb); |
| 1007 | } |
| 1008 | |
| 1009 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1010 | * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC. |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1011 | * @ha: HA context |
| 1012 | * |
| 1013 | * Returns 0 on success. |
| 1014 | */ |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1015 | static inline void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1016 | qla24xx_reset_risc(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1017 | { |
| 1018 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1019 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1020 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 1021 | uint32_t cnt, d2; |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 1022 | uint16_t wd; |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 1023 | static int abts_cnt; /* ISP abort retry counts */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1024 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1025 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1026 | |
| 1027 | /* Reset RISC. */ |
| 1028 | WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
| 1029 | for (cnt = 0; cnt < 30000; cnt++) { |
| 1030 | if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0) |
| 1031 | break; |
| 1032 | |
| 1033 | udelay(10); |
| 1034 | } |
| 1035 | |
| 1036 | WRT_REG_DWORD(®->ctrl_status, |
| 1037 | CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 1038 | pci_read_config_word(ha->pdev, PCI_COMMAND, &wd); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1039 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 1040 | udelay(100); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1041 | /* Wait for firmware to complete NVRAM accesses. */ |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1042 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 1043 | for (cnt = 10000 ; cnt && d2; cnt--) { |
| 1044 | udelay(5); |
| 1045 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 1046 | barrier(); |
| 1047 | } |
| 1048 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 1049 | /* Wait for soft-reset to complete. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1050 | d2 = RD_REG_DWORD(®->ctrl_status); |
| 1051 | for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) { |
| 1052 | udelay(5); |
| 1053 | d2 = RD_REG_DWORD(®->ctrl_status); |
| 1054 | barrier(); |
| 1055 | } |
| 1056 | |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 1057 | /* If required, do an MPI FW reset now */ |
| 1058 | if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) { |
| 1059 | if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) { |
| 1060 | if (++abts_cnt < 5) { |
| 1061 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 1062 | set_bit(MPI_RESET_NEEDED, &vha->dpc_flags); |
| 1063 | } else { |
| 1064 | /* |
| 1065 | * We exhausted the ISP abort retries. We have to |
| 1066 | * set the board offline. |
| 1067 | */ |
| 1068 | abts_cnt = 0; |
| 1069 | vha->flags.online = 0; |
| 1070 | } |
| 1071 | } |
| 1072 | } |
| 1073 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1074 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 1075 | RD_REG_DWORD(®->hccr); |
| 1076 | |
| 1077 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 1078 | RD_REG_DWORD(®->hccr); |
| 1079 | |
| 1080 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET); |
| 1081 | RD_REG_DWORD(®->hccr); |
| 1082 | |
| 1083 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 1084 | for (cnt = 6000000 ; cnt && d2; cnt--) { |
| 1085 | udelay(5); |
| 1086 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 1087 | barrier(); |
| 1088 | } |
| 1089 | |
| 1090 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 124f85e | 2009-01-05 11:18:06 -0800 | [diff] [blame] | 1091 | |
| 1092 | if (IS_NOPOLLING_TYPE(ha)) |
| 1093 | ha->isp_ops->enable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1094 | } |
| 1095 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 1096 | static void |
| 1097 | qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data) |
| 1098 | { |
| 1099 | struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24; |
| 1100 | |
| 1101 | WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET); |
| 1102 | *data = RD_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET); |
| 1103 | |
| 1104 | } |
| 1105 | |
| 1106 | static void |
| 1107 | qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data) |
| 1108 | { |
| 1109 | struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24; |
| 1110 | |
| 1111 | WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET); |
| 1112 | WRT_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET, data); |
| 1113 | } |
| 1114 | |
| 1115 | static void |
| 1116 | qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha) |
| 1117 | { |
| 1118 | struct qla_hw_data *ha = vha->hw; |
| 1119 | uint32_t wd32 = 0; |
| 1120 | uint delta_msec = 100; |
| 1121 | uint elapsed_msec = 0; |
| 1122 | uint timeout_msec; |
| 1123 | ulong n; |
| 1124 | |
| 1125 | if (!IS_QLA25XX(ha) && !IS_QLA2031(ha)) |
| 1126 | return; |
| 1127 | |
| 1128 | attempt: |
| 1129 | timeout_msec = TIMEOUT_SEMAPHORE; |
| 1130 | n = timeout_msec / delta_msec; |
| 1131 | while (n--) { |
| 1132 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET); |
| 1133 | qla25xx_read_risc_sema_reg(vha, &wd32); |
| 1134 | if (wd32 & RISC_SEMAPHORE) |
| 1135 | break; |
| 1136 | msleep(delta_msec); |
| 1137 | elapsed_msec += delta_msec; |
| 1138 | if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED) |
| 1139 | goto force; |
| 1140 | } |
| 1141 | |
| 1142 | if (!(wd32 & RISC_SEMAPHORE)) |
| 1143 | goto force; |
| 1144 | |
| 1145 | if (!(wd32 & RISC_SEMAPHORE_FORCE)) |
| 1146 | goto acquired; |
| 1147 | |
| 1148 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR); |
| 1149 | timeout_msec = TIMEOUT_SEMAPHORE_FORCE; |
| 1150 | n = timeout_msec / delta_msec; |
| 1151 | while (n--) { |
| 1152 | qla25xx_read_risc_sema_reg(vha, &wd32); |
| 1153 | if (!(wd32 & RISC_SEMAPHORE_FORCE)) |
| 1154 | break; |
| 1155 | msleep(delta_msec); |
| 1156 | elapsed_msec += delta_msec; |
| 1157 | if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED) |
| 1158 | goto force; |
| 1159 | } |
| 1160 | |
| 1161 | if (wd32 & RISC_SEMAPHORE_FORCE) |
| 1162 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR); |
| 1163 | |
| 1164 | goto attempt; |
| 1165 | |
| 1166 | force: |
| 1167 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET); |
| 1168 | |
| 1169 | acquired: |
| 1170 | return; |
| 1171 | } |
| 1172 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1173 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1174 | * qla24xx_reset_chip() - Reset ISP24xx chip. |
| 1175 | * @ha: HA context |
| 1176 | * |
| 1177 | * Returns 0 on success. |
| 1178 | */ |
| 1179 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1180 | qla24xx_reset_chip(scsi_qla_host_t *vha) |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1181 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1182 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 1183 | |
| 1184 | if (pci_channel_offline(ha->pdev) && |
| 1185 | ha->flags.pci_channel_io_perm_failure) { |
| 1186 | return; |
| 1187 | } |
| 1188 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1189 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1190 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 1191 | qla25xx_manipulate_risc_semaphore(vha); |
| 1192 | |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1193 | /* Perform RISC reset. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1194 | qla24xx_reset_risc(vha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | * qla2x00_chip_diag() - Test chip for proper operation. |
| 1199 | * @ha: HA context |
| 1200 | * |
| 1201 | * Returns 0 on success. |
| 1202 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1203 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1204 | qla2x00_chip_diag(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | { |
| 1206 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1207 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1208 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | unsigned long flags = 0; |
| 1210 | uint16_t data; |
| 1211 | uint32_t cnt; |
| 1212 | uint16_t mb[5]; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1213 | struct req_que *req = ha->req_q_map[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | |
| 1215 | /* Assume a failed state */ |
| 1216 | rval = QLA_FUNCTION_FAILED; |
| 1217 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1218 | ql_dbg(ql_dbg_init, vha, 0x007b, |
| 1219 | "Testing device at %lx.\n", (u_long)®->flash_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | |
| 1221 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1222 | |
| 1223 | /* Reset ISP chip. */ |
| 1224 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 1225 | |
| 1226 | /* |
| 1227 | * We need to have a delay here since the card will not respond while |
| 1228 | * in reset causing an MCA on some architectures. |
| 1229 | */ |
| 1230 | udelay(20); |
| 1231 | data = qla2x00_debounce_register(®->ctrl_status); |
| 1232 | for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) { |
| 1233 | udelay(5); |
| 1234 | data = RD_REG_WORD(®->ctrl_status); |
| 1235 | barrier(); |
| 1236 | } |
| 1237 | |
| 1238 | if (!cnt) |
| 1239 | goto chip_diag_failed; |
| 1240 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1241 | ql_dbg(ql_dbg_init, vha, 0x007c, |
| 1242 | "Reset register cleared by chip reset.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | |
| 1244 | /* Reset RISC processor. */ |
| 1245 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 1246 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 1247 | |
| 1248 | /* Workaround for QLA2312 PCI parity error */ |
| 1249 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 1250 | data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0)); |
| 1251 | for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) { |
| 1252 | udelay(5); |
| 1253 | data = RD_MAILBOX_REG(ha, reg, 0); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1254 | barrier(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | } |
| 1256 | } else |
| 1257 | udelay(10); |
| 1258 | |
| 1259 | if (!cnt) |
| 1260 | goto chip_diag_failed; |
| 1261 | |
| 1262 | /* Check product ID of chip */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1263 | 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] | 1264 | |
| 1265 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); |
| 1266 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); |
| 1267 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); |
| 1268 | mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4)); |
| 1269 | if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) || |
| 1270 | mb[3] != PROD_ID_3) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1271 | ql_log(ql_log_warn, vha, 0x0062, |
| 1272 | "Wrong product ID = 0x%x,0x%x,0x%x.\n", |
| 1273 | mb[1], mb[2], mb[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | |
| 1275 | goto chip_diag_failed; |
| 1276 | } |
| 1277 | ha->product_id[0] = mb[1]; |
| 1278 | ha->product_id[1] = mb[2]; |
| 1279 | ha->product_id[2] = mb[3]; |
| 1280 | ha->product_id[3] = mb[4]; |
| 1281 | |
| 1282 | /* Adjust fw RISC transfer size */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1283 | if (req->length > 1024) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024; |
| 1285 | else |
| 1286 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1287 | req->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | |
| 1289 | if (IS_QLA2200(ha) && |
| 1290 | RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) { |
| 1291 | /* Limit firmware transfer size with a 2200A */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1292 | ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1294 | ha->device_type |= DT_ISP2200A; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | ha->fw_transfer_size = 128; |
| 1296 | } |
| 1297 | |
| 1298 | /* Wrap Incoming Mailboxes Test. */ |
| 1299 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1300 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1301 | ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1302 | rval = qla2x00_mbx_reg_test(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1303 | if (rval) |
| 1304 | ql_log(ql_log_warn, vha, 0x0080, |
| 1305 | "Failed mailbox send register test.\n"); |
| 1306 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | /* Flag a successful rval */ |
| 1308 | rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1310 | |
| 1311 | chip_diag_failed: |
| 1312 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1313 | ql_log(ql_log_info, vha, 0x0081, |
| 1314 | "Chip diagnostics **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | |
| 1316 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1317 | |
| 1318 | return (rval); |
| 1319 | } |
| 1320 | |
| 1321 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1322 | * qla24xx_chip_diag() - Test ISP24xx for proper operation. |
| 1323 | * @ha: HA context |
| 1324 | * |
| 1325 | * Returns 0 on success. |
| 1326 | */ |
| 1327 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1328 | qla24xx_chip_diag(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1329 | { |
| 1330 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1331 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1332 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1333 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1334 | if (IS_QLA82XX(ha)) |
| 1335 | return QLA_SUCCESS; |
| 1336 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1337 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1338 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1339 | rval = qla2x00_mbx_reg_test(vha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1340 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1341 | ql_log(ql_log_warn, vha, 0x0082, |
| 1342 | "Failed mailbox send register test.\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1343 | } else { |
| 1344 | /* Flag a successful rval */ |
| 1345 | rval = QLA_SUCCESS; |
| 1346 | } |
| 1347 | |
| 1348 | return rval; |
| 1349 | } |
| 1350 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1351 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1352 | qla2x00_alloc_fw_dump(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1353 | { |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1354 | int rval; |
| 1355 | 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] | 1356 | eft_size, fce_size, mq_size; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1357 | dma_addr_t tc_dma; |
| 1358 | void *tc; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1359 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1360 | struct req_que *req = ha->req_q_map[0]; |
| 1361 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 1362 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1363 | if (ha->fw_dump) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1364 | ql_dbg(ql_dbg_init, vha, 0x00bd, |
| 1365 | "Firmware dump already allocated.\n"); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1366 | return; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 1367 | } |
| 1368 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1369 | ha->fw_dumped = 0; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1370 | fixed_size = mem_size = eft_size = fce_size = mq_size = 0; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1371 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 1372 | fixed_size = sizeof(struct qla2100_fw_dump); |
| 1373 | } else if (IS_QLA23XX(ha)) { |
| 1374 | fixed_size = offsetof(struct qla2300_fw_dump, data_ram); |
| 1375 | mem_size = (ha->fw_memory_size - 0x11000 + 1) * |
| 1376 | sizeof(uint16_t); |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 1377 | } else if (IS_FWI2_CAPABLE(ha)) { |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1378 | if (IS_QLA83XX(ha)) |
| 1379 | fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem); |
| 1380 | else if (IS_QLA81XX(ha)) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1381 | fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem); |
| 1382 | else if (IS_QLA25XX(ha)) |
| 1383 | fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem); |
| 1384 | else |
| 1385 | fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1386 | mem_size = (ha->fw_memory_size - 0x100000 + 1) * |
| 1387 | sizeof(uint32_t); |
Giridhar Malavali | 050c9bb | 2012-02-09 11:15:33 -0800 | [diff] [blame] | 1388 | if (ha->mqenable) { |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1389 | if (!IS_QLA83XX(ha)) |
| 1390 | mq_size = sizeof(struct qla2xxx_mq_chain); |
Giridhar Malavali | 050c9bb | 2012-02-09 11:15:33 -0800 | [diff] [blame] | 1391 | /* |
| 1392 | * Allocate maximum buffer size for all queues. |
| 1393 | * Resizing must be done at end-of-dump processing. |
| 1394 | */ |
| 1395 | mq_size += ha->max_req_queues * |
| 1396 | (req->length * sizeof(request_t)); |
| 1397 | mq_size += ha->max_rsp_queues * |
| 1398 | (rsp->length * sizeof(response_t)); |
| 1399 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1400 | if (ha->tgt.atio_q_length) |
| 1401 | mq_size += ha->tgt.atio_q_length * sizeof(request_t); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1402 | /* Allocate memory for Fibre Channel Event Buffer. */ |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1403 | if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha)) |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1404 | goto try_eft; |
| 1405 | |
| 1406 | tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma, |
| 1407 | GFP_KERNEL); |
| 1408 | if (!tc) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1409 | ql_log(ql_log_warn, vha, 0x00be, |
| 1410 | "Unable to allocate (%d KB) for FCE.\n", |
| 1411 | FCE_SIZE / 1024); |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 1412 | goto try_eft; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | memset(tc, 0, FCE_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1416 | rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1417 | ha->fce_mb, &ha->fce_bufs); |
| 1418 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1419 | ql_log(ql_log_warn, vha, 0x00bf, |
| 1420 | "Unable to initialize FCE (%d).\n", rval); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1421 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, |
| 1422 | tc_dma); |
| 1423 | ha->flags.fce_enabled = 0; |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 1424 | goto try_eft; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1425 | } |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1426 | ql_dbg(ql_dbg_init, vha, 0x00c0, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1427 | "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1428 | |
Giridhar Malavali | 7d9dade | 2009-03-24 09:07:58 -0700 | [diff] [blame] | 1429 | fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1430 | ha->flags.fce_enabled = 1; |
| 1431 | ha->fce_dma = tc_dma; |
| 1432 | ha->fce = tc; |
| 1433 | try_eft: |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1434 | /* Allocate memory for Extended Trace Buffer. */ |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1435 | tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma, |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1436 | GFP_KERNEL); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1437 | if (!tc) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1438 | ql_log(ql_log_warn, vha, 0x00c1, |
| 1439 | "Unable to allocate (%d KB) for EFT.\n", |
| 1440 | EFT_SIZE / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1441 | goto cont_alloc; |
| 1442 | } |
| 1443 | |
Andrew Vasquez | fc44765 | 2008-01-17 09:02:18 -0800 | [diff] [blame] | 1444 | memset(tc, 0, EFT_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1445 | rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1446 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1447 | ql_log(ql_log_warn, vha, 0x00c2, |
| 1448 | "Unable to initialize EFT (%d).\n", rval); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1449 | dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, |
| 1450 | tc_dma); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1451 | goto cont_alloc; |
| 1452 | } |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1453 | ql_dbg(ql_dbg_init, vha, 0x00c3, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1454 | "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1455 | |
| 1456 | eft_size = EFT_SIZE; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1457 | ha->eft_dma = tc_dma; |
| 1458 | ha->eft = tc; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1459 | } |
| 1460 | cont_alloc: |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1461 | req_q_size = req->length * sizeof(request_t); |
| 1462 | rsp_q_size = rsp->length * sizeof(response_t); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1463 | |
| 1464 | dump_size = offsetof(struct qla2xxx_fw_dump, isp); |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1465 | 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] | 1466 | ha->chain_offset = dump_size; |
| 1467 | dump_size += mq_size + fce_size; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1468 | |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 1469 | ha->fw_dump = vmalloc(dump_size); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1470 | if (!ha->fw_dump) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1471 | ql_log(ql_log_warn, vha, 0x00c4, |
| 1472 | "Unable to allocate (%d KB) for firmware dump.\n", |
| 1473 | dump_size / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1474 | |
Madhuranath Iyengar | e30d175 | 2010-10-15 11:27:46 -0700 | [diff] [blame] | 1475 | if (ha->fce) { |
| 1476 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce, |
| 1477 | ha->fce_dma); |
| 1478 | ha->fce = NULL; |
| 1479 | ha->fce_dma = 0; |
| 1480 | } |
| 1481 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1482 | if (ha->eft) { |
| 1483 | dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft, |
| 1484 | ha->eft_dma); |
| 1485 | ha->eft = NULL; |
| 1486 | ha->eft_dma = 0; |
| 1487 | } |
| 1488 | return; |
| 1489 | } |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1490 | ql_dbg(ql_dbg_init, vha, 0x00c5, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1491 | "Allocated (%d KB) for firmware dump.\n", dump_size / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1492 | |
| 1493 | ha->fw_dump_len = dump_size; |
| 1494 | ha->fw_dump->signature[0] = 'Q'; |
| 1495 | ha->fw_dump->signature[1] = 'L'; |
| 1496 | ha->fw_dump->signature[2] = 'G'; |
| 1497 | ha->fw_dump->signature[3] = 'C'; |
| 1498 | ha->fw_dump->version = __constant_htonl(1); |
| 1499 | |
| 1500 | ha->fw_dump->fixed_size = htonl(fixed_size); |
| 1501 | ha->fw_dump->mem_size = htonl(mem_size); |
| 1502 | ha->fw_dump->req_q_size = htonl(req_q_size); |
| 1503 | ha->fw_dump->rsp_q_size = htonl(rsp_q_size); |
| 1504 | |
| 1505 | ha->fw_dump->eft_size = htonl(eft_size); |
| 1506 | ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma)); |
| 1507 | ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma)); |
| 1508 | |
| 1509 | ha->fw_dump->header_size = |
| 1510 | htonl(offsetof(struct qla2xxx_fw_dump, isp)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1511 | } |
| 1512 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1513 | static int |
| 1514 | qla81xx_mpi_sync(scsi_qla_host_t *vha) |
| 1515 | { |
| 1516 | #define MPS_MASK 0xe0 |
| 1517 | int rval; |
| 1518 | uint16_t dc; |
| 1519 | uint32_t dw; |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1520 | |
| 1521 | if (!IS_QLA81XX(vha->hw)) |
| 1522 | return QLA_SUCCESS; |
| 1523 | |
| 1524 | rval = qla2x00_write_ram_word(vha, 0x7c00, 1); |
| 1525 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1526 | ql_log(ql_log_warn, vha, 0x0105, |
| 1527 | "Unable to acquire semaphore.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1528 | goto done; |
| 1529 | } |
| 1530 | |
| 1531 | pci_read_config_word(vha->hw->pdev, 0x54, &dc); |
| 1532 | rval = qla2x00_read_ram_word(vha, 0x7a15, &dw); |
| 1533 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1534 | ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1535 | goto done_release; |
| 1536 | } |
| 1537 | |
| 1538 | dc &= MPS_MASK; |
| 1539 | if (dc == (dw & MPS_MASK)) |
| 1540 | goto done_release; |
| 1541 | |
| 1542 | dw &= ~MPS_MASK; |
| 1543 | dw |= dc; |
| 1544 | rval = qla2x00_write_ram_word(vha, 0x7a15, dw); |
| 1545 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1546 | ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1547 | } |
| 1548 | |
| 1549 | done_release: |
| 1550 | rval = qla2x00_write_ram_word(vha, 0x7c00, 0); |
| 1551 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1552 | ql_log(ql_log_warn, vha, 0x006d, |
| 1553 | "Unable to release semaphore.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | done: |
| 1557 | return rval; |
| 1558 | } |
| 1559 | |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 1560 | int |
| 1561 | qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req) |
| 1562 | { |
| 1563 | /* Don't try to reallocate the array */ |
| 1564 | if (req->outstanding_cmds) |
| 1565 | return QLA_SUCCESS; |
| 1566 | |
| 1567 | if (!IS_FWI2_CAPABLE(ha) || (ha->mqiobase && |
| 1568 | (ql2xmultique_tag || ql2xmaxqueues > 1))) |
| 1569 | req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS; |
| 1570 | else { |
| 1571 | if (ha->fw_xcb_count <= ha->fw_iocb_count) |
| 1572 | req->num_outstanding_cmds = ha->fw_xcb_count; |
| 1573 | else |
| 1574 | req->num_outstanding_cmds = ha->fw_iocb_count; |
| 1575 | } |
| 1576 | |
| 1577 | req->outstanding_cmds = kzalloc(sizeof(srb_t *) * |
| 1578 | req->num_outstanding_cmds, GFP_KERNEL); |
| 1579 | |
| 1580 | if (!req->outstanding_cmds) { |
| 1581 | /* |
| 1582 | * Try to allocate a minimal size just so we can get through |
| 1583 | * initialization. |
| 1584 | */ |
| 1585 | req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS; |
| 1586 | req->outstanding_cmds = kzalloc(sizeof(srb_t *) * |
| 1587 | req->num_outstanding_cmds, GFP_KERNEL); |
| 1588 | |
| 1589 | if (!req->outstanding_cmds) { |
| 1590 | ql_log(ql_log_fatal, NULL, 0x0126, |
| 1591 | "Failed to allocate memory for " |
| 1592 | "outstanding_cmds for req_que %p.\n", req); |
| 1593 | req->num_outstanding_cmds = 0; |
| 1594 | return QLA_FUNCTION_FAILED; |
| 1595 | } |
| 1596 | } |
| 1597 | |
| 1598 | return QLA_SUCCESS; |
| 1599 | } |
| 1600 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1601 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | * qla2x00_setup_chip() - Load and start RISC firmware. |
| 1603 | * @ha: HA context |
| 1604 | * |
| 1605 | * Returns 0 on success. |
| 1606 | */ |
| 1607 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1608 | qla2x00_setup_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1610 | int rval; |
| 1611 | uint32_t srisc_address = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1612 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1613 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 1614 | unsigned long flags; |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 1615 | uint16_t fw_major_version; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1616 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1617 | if (IS_QLA82XX(ha)) { |
| 1618 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 1619 | if (rval == QLA_SUCCESS) { |
| 1620 | qla2x00_stop_firmware(vha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1621 | goto enable_82xx_npiv; |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 1622 | } else |
Giridhar Malavali | b963752 | 2010-05-28 15:08:15 -0700 | [diff] [blame] | 1623 | goto failed; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1624 | } |
| 1625 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1626 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 1627 | /* Disable SRAM, Instruction RAM and GP RAM parity. */ |
| 1628 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1629 | WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0)); |
| 1630 | RD_REG_WORD(®->hccr); |
| 1631 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1632 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1634 | qla81xx_mpi_sync(vha); |
| 1635 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | /* Load firmware sequences */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1637 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1638 | if (rval == QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1639 | ql_dbg(ql_dbg_init, vha, 0x00c9, |
| 1640 | "Verifying Checksum of loaded RISC code.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1642 | rval = qla2x00_verify_checksum(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1643 | if (rval == QLA_SUCCESS) { |
| 1644 | /* Start firmware execution. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1645 | ql_dbg(ql_dbg_init, vha, 0x00ca, |
| 1646 | "Starting firmware.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1648 | rval = qla2x00_execute_fw(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | /* Retrieve firmware information. */ |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 1650 | if (rval == QLA_SUCCESS) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1651 | enable_82xx_npiv: |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 1652 | fw_major_version = ha->fw_major_version; |
Giridhar Malavali | 3173167 | 2011-08-16 11:31:54 -0700 | [diff] [blame] | 1653 | if (IS_QLA82XX(ha)) |
| 1654 | qla82xx_check_md_needed(vha); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1655 | else |
| 1656 | rval = qla2x00_get_fw_version(vha); |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 1657 | if (rval != QLA_SUCCESS) |
| 1658 | goto failed; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1659 | ha->flags.npiv_supported = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1660 | if (IS_QLA2XXX_MIDTYPE(ha) && |
Mike Hernandez | 946fb89 | 2008-08-13 21:36:59 -0700 | [diff] [blame] | 1661 | (ha->fw_attributes & BIT_2)) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1662 | ha->flags.npiv_supported = 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 1663 | if ((!ha->max_npiv_vports) || |
| 1664 | ((ha->max_npiv_vports + 1) % |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 1665 | MIN_MULTI_ID_FABRIC)) |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 1666 | ha->max_npiv_vports = |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 1667 | MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 1668 | } |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 1669 | qla2x00_get_resource_cnts(vha, NULL, |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 1670 | &ha->fw_xcb_count, NULL, &ha->fw_iocb_count, |
Andrew Vasquez | f3a0a77 | 2009-10-13 15:16:49 -0700 | [diff] [blame] | 1671 | &ha->max_npiv_vports, NULL); |
Andrew Vasquez | d743de6 | 2009-03-24 09:08:15 -0700 | [diff] [blame] | 1672 | |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 1673 | /* |
| 1674 | * Allocate the array of outstanding commands |
| 1675 | * now that we know the firmware resources. |
| 1676 | */ |
| 1677 | rval = qla2x00_alloc_outstanding_cmds(ha, |
| 1678 | vha->req); |
| 1679 | if (rval != QLA_SUCCESS) |
| 1680 | goto failed; |
| 1681 | |
Saurav Kashyap | be5ea3c | 2011-11-18 09:02:11 -0800 | [diff] [blame] | 1682 | if (!fw_major_version && ql2xallocfwdump |
| 1683 | && !IS_QLA82XX(ha)) |
Giridhar Malavali | 08de284 | 2011-08-16 11:31:44 -0700 | [diff] [blame] | 1684 | qla2x00_alloc_fw_dump(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | } |
| 1686 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1687 | ql_log(ql_log_fatal, vha, 0x00cd, |
| 1688 | "ISP Firmware failed checksum.\n"); |
| 1689 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | } |
Andrew Vasquez | c74d88a | 2012-08-22 14:21:19 -0400 | [diff] [blame] | 1691 | } else |
| 1692 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1694 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 1695 | /* Enable proper parity. */ |
| 1696 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1697 | if (IS_QLA2300(ha)) |
| 1698 | /* SRAM parity */ |
| 1699 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1); |
| 1700 | else |
| 1701 | /* SRAM, Instruction RAM and GP RAM parity */ |
| 1702 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7); |
| 1703 | RD_REG_WORD(®->hccr); |
| 1704 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1705 | } |
| 1706 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1707 | if (IS_QLA83XX(ha)) |
| 1708 | goto skip_fac_check; |
| 1709 | |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1710 | if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) { |
| 1711 | uint32_t size; |
| 1712 | |
| 1713 | rval = qla81xx_fac_get_sector_size(vha, &size); |
| 1714 | if (rval == QLA_SUCCESS) { |
| 1715 | ha->flags.fac_supported = 1; |
| 1716 | ha->fdt_block_size = size << 2; |
| 1717 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1718 | ql_log(ql_log_warn, vha, 0x00ce, |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1719 | "Unsupported FAC firmware (%d.%02d.%02d).\n", |
| 1720 | ha->fw_major_version, ha->fw_minor_version, |
| 1721 | ha->fw_subminor_version); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1722 | skip_fac_check: |
| 1723 | if (IS_QLA83XX(ha)) { |
| 1724 | ha->flags.fac_supported = 0; |
| 1725 | rval = QLA_SUCCESS; |
| 1726 | } |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1727 | } |
| 1728 | } |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 1729 | failed: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1731 | ql_log(ql_log_fatal, vha, 0x00cf, |
| 1732 | "Setup chip ****FAILED****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | return (rval); |
| 1736 | } |
| 1737 | |
| 1738 | /** |
| 1739 | * qla2x00_init_response_q_entries() - Initializes response queue entries. |
| 1740 | * @ha: HA context |
| 1741 | * |
| 1742 | * Beginning of request ring has initialization control block already built |
| 1743 | * by nvram config routine. |
| 1744 | * |
| 1745 | * Returns 0 on success. |
| 1746 | */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1747 | void |
| 1748 | qla2x00_init_response_q_entries(struct rsp_que *rsp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | { |
| 1750 | uint16_t cnt; |
| 1751 | response_t *pkt; |
| 1752 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1753 | rsp->ring_ptr = rsp->ring; |
| 1754 | rsp->ring_index = 0; |
| 1755 | rsp->status_srb = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1756 | pkt = rsp->ring_ptr; |
| 1757 | for (cnt = 0; cnt < rsp->length; cnt++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1758 | pkt->signature = RESPONSE_PROCESSED; |
| 1759 | pkt++; |
| 1760 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | } |
| 1762 | |
| 1763 | /** |
| 1764 | * qla2x00_update_fw_options() - Read and process firmware options. |
| 1765 | * @ha: HA context |
| 1766 | * |
| 1767 | * Returns 0 on success. |
| 1768 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1769 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1770 | qla2x00_update_fw_options(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1771 | { |
| 1772 | uint16_t swing, emphasis, tx_sens, rx_sens; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1773 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1774 | |
| 1775 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1776 | qla2x00_get_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1777 | |
| 1778 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
| 1779 | return; |
| 1780 | |
| 1781 | /* Serial Link options. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1782 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115, |
| 1783 | "Serial link options.\n"); |
| 1784 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109, |
| 1785 | (uint8_t *)&ha->fw_seriallink_options, |
| 1786 | sizeof(ha->fw_seriallink_options)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | |
| 1788 | ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING; |
| 1789 | if (ha->fw_seriallink_options[3] & BIT_2) { |
| 1790 | ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING; |
| 1791 | |
| 1792 | /* 1G settings */ |
| 1793 | swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0); |
| 1794 | emphasis = (ha->fw_seriallink_options[2] & |
| 1795 | (BIT_4 | BIT_3)) >> 3; |
| 1796 | tx_sens = ha->fw_seriallink_options[0] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1797 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | rx_sens = (ha->fw_seriallink_options[0] & |
| 1799 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 1800 | ha->fw_options[10] = (emphasis << 14) | (swing << 8); |
| 1801 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 1802 | if (rx_sens == 0x0) |
| 1803 | rx_sens = 0x3; |
| 1804 | ha->fw_options[10] |= (tx_sens << 4) | rx_sens; |
| 1805 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 1806 | ha->fw_options[10] |= BIT_5 | |
| 1807 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 1808 | (tx_sens & (BIT_1 | BIT_0)); |
| 1809 | |
| 1810 | /* 2G settings */ |
| 1811 | swing = (ha->fw_seriallink_options[2] & |
| 1812 | (BIT_7 | BIT_6 | BIT_5)) >> 5; |
| 1813 | emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0); |
| 1814 | tx_sens = ha->fw_seriallink_options[1] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1815 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | rx_sens = (ha->fw_seriallink_options[1] & |
| 1817 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 1818 | ha->fw_options[11] = (emphasis << 14) | (swing << 8); |
| 1819 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 1820 | if (rx_sens == 0x0) |
| 1821 | rx_sens = 0x3; |
| 1822 | ha->fw_options[11] |= (tx_sens << 4) | rx_sens; |
| 1823 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 1824 | ha->fw_options[11] |= BIT_5 | |
| 1825 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 1826 | (tx_sens & (BIT_1 | BIT_0)); |
| 1827 | } |
| 1828 | |
| 1829 | /* FCP2 options. */ |
| 1830 | /* Return command IOCBs without waiting for an ABTS to complete. */ |
| 1831 | ha->fw_options[3] |= BIT_13; |
| 1832 | |
| 1833 | /* LED scheme. */ |
| 1834 | if (ha->flags.enable_led_scheme) |
| 1835 | ha->fw_options[2] |= BIT_12; |
| 1836 | |
andrew.vasquez@qlogic.com | 48c02fd | 2006-03-09 14:27:18 -0800 | [diff] [blame] | 1837 | /* Detect ISP6312. */ |
| 1838 | if (IS_QLA6312(ha)) |
| 1839 | ha->fw_options[2] |= BIT_13; |
| 1840 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1841 | /* Update firmware options. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1842 | qla2x00_set_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | } |
| 1844 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1845 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1846 | qla24xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1847 | { |
| 1848 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1849 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1850 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1851 | if (IS_QLA82XX(ha)) |
| 1852 | return; |
| 1853 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1854 | /* Update Serial Link options. */ |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 1855 | if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1856 | return; |
| 1857 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1858 | rval = qla2x00_set_serdes_params(vha, |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 1859 | le16_to_cpu(ha->fw_seriallink_options24[1]), |
| 1860 | le16_to_cpu(ha->fw_seriallink_options24[2]), |
| 1861 | le16_to_cpu(ha->fw_seriallink_options24[3])); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1862 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1863 | ql_log(ql_log_warn, vha, 0x0104, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1864 | "Unable to update Serial Link options (%x).\n", rval); |
| 1865 | } |
| 1866 | } |
| 1867 | |
| 1868 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1869 | qla2x00_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1870 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1871 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1872 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1873 | struct req_que *req = ha->req_q_map[0]; |
| 1874 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1875 | |
| 1876 | /* Setup ring parameters in initialization control block. */ |
| 1877 | ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0); |
| 1878 | ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1879 | ha->init_cb->request_q_length = cpu_to_le16(req->length); |
| 1880 | ha->init_cb->response_q_length = cpu_to_le16(rsp->length); |
| 1881 | ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 1882 | ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 1883 | ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 1884 | 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] | 1885 | |
| 1886 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0); |
| 1887 | WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0); |
| 1888 | WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0); |
| 1889 | WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0); |
| 1890 | RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */ |
| 1891 | } |
| 1892 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1893 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1894 | qla24xx_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1895 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1896 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1897 | device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0); |
| 1898 | struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp; |
| 1899 | struct qla_msix_entry *msix; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1900 | struct init_cb_24xx *icb; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1901 | uint16_t rid = 0; |
| 1902 | struct req_que *req = ha->req_q_map[0]; |
| 1903 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1904 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1905 | /* Setup ring parameters in initialization control block. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1906 | icb = (struct init_cb_24xx *)ha->init_cb; |
| 1907 | icb->request_q_outpointer = __constant_cpu_to_le16(0); |
| 1908 | icb->response_q_inpointer = __constant_cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1909 | icb->request_q_length = cpu_to_le16(req->length); |
| 1910 | icb->response_q_length = cpu_to_le16(rsp->length); |
| 1911 | icb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 1912 | icb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 1913 | icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 1914 | icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1915 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1916 | /* Setup ATIO queue dma pointers for target mode */ |
| 1917 | icb->atio_q_inpointer = __constant_cpu_to_le16(0); |
| 1918 | icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length); |
| 1919 | icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma)); |
| 1920 | icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma)); |
| 1921 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1922 | if (ha->mqenable || IS_QLA83XX(ha)) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1923 | icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS); |
| 1924 | icb->rid = __constant_cpu_to_le16(rid); |
| 1925 | if (ha->flags.msix_enabled) { |
| 1926 | msix = &ha->msix_entries[1]; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1927 | ql_dbg(ql_dbg_init, vha, 0x00fd, |
| 1928 | "Registering vector 0x%x for base que.\n", |
| 1929 | msix->entry); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1930 | icb->msix = cpu_to_le16(msix->entry); |
| 1931 | } |
| 1932 | /* Use alternate PCI bus number */ |
| 1933 | if (MSB(rid)) |
| 1934 | icb->firmware_options_2 |= |
| 1935 | __constant_cpu_to_le32(BIT_19); |
| 1936 | /* Use alternate PCI devfn */ |
| 1937 | if (LSB(rid)) |
| 1938 | icb->firmware_options_2 |= |
| 1939 | __constant_cpu_to_le32(BIT_18); |
| 1940 | |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 1941 | /* Use Disable MSIX Handshake mode for capable adapters */ |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1942 | if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) && |
| 1943 | (ha->flags.msix_enabled)) { |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 1944 | icb->firmware_options_2 &= |
| 1945 | __constant_cpu_to_le32(~BIT_22); |
| 1946 | ha->flags.disable_msix_handshake = 1; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1947 | ql_dbg(ql_dbg_init, vha, 0x00fe, |
| 1948 | "MSIX Handshake Disable Mode turned on.\n"); |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 1949 | } else { |
| 1950 | icb->firmware_options_2 |= |
| 1951 | __constant_cpu_to_le32(BIT_22); |
| 1952 | } |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1953 | icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1954 | |
| 1955 | WRT_REG_DWORD(®->isp25mq.req_q_in, 0); |
| 1956 | WRT_REG_DWORD(®->isp25mq.req_q_out, 0); |
| 1957 | WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0); |
| 1958 | WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0); |
| 1959 | } else { |
| 1960 | WRT_REG_DWORD(®->isp24.req_q_in, 0); |
| 1961 | WRT_REG_DWORD(®->isp24.req_q_out, 0); |
| 1962 | WRT_REG_DWORD(®->isp24.rsp_q_in, 0); |
| 1963 | WRT_REG_DWORD(®->isp24.rsp_q_out, 0); |
| 1964 | } |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 1965 | qlt_24xx_config_rings(vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1966 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1967 | /* PCI posting */ |
| 1968 | RD_REG_DWORD(&ioreg->hccr); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1969 | } |
| 1970 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | /** |
| 1972 | * qla2x00_init_rings() - Initializes firmware. |
| 1973 | * @ha: HA context |
| 1974 | * |
| 1975 | * Beginning of request ring has initialization control block already built |
| 1976 | * by nvram config routine. |
| 1977 | * |
| 1978 | * Returns 0 on success. |
| 1979 | */ |
| 1980 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1981 | qla2x00_init_rings(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | { |
| 1983 | int rval; |
| 1984 | unsigned long flags = 0; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1985 | int cnt, que; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1986 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1987 | struct req_que *req; |
| 1988 | struct rsp_que *rsp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1989 | struct mid_init_cb_24xx *mid_init_cb = |
| 1990 | (struct mid_init_cb_24xx *) ha->init_cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | |
| 1992 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1993 | |
| 1994 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1995 | for (que = 0; que < ha->max_req_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1996 | req = ha->req_q_map[que]; |
| 1997 | if (!req) |
| 1998 | continue; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 1999 | for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 2000 | req->outstanding_cmds[cnt] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 2002 | req->current_outstanding_cmd = 1; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 2003 | |
| 2004 | /* Initialize firmware. */ |
| 2005 | req->ring_ptr = req->ring; |
| 2006 | req->ring_index = 0; |
| 2007 | req->cnt = req->length; |
| 2008 | } |
| 2009 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 2010 | for (que = 0; que < ha->max_rsp_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 2011 | rsp = ha->rsp_q_map[que]; |
| 2012 | if (!rsp) |
| 2013 | continue; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 2014 | /* Initialize response queue entries */ |
| 2015 | qla2x00_init_response_q_entries(rsp); |
| 2016 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2018 | ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; |
| 2019 | ha->tgt.atio_ring_index = 0; |
| 2020 | /* Initialize ATIO queue entries */ |
| 2021 | qlt_init_atio_q_entries(vha); |
| 2022 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2023 | ha->isp_ops->config_rings(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | |
| 2025 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2026 | |
| 2027 | /* Update any ISP specific firmware options before initialization. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2028 | ha->isp_ops->update_fw_options(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2030 | ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n"); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2031 | |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 2032 | if (ha->flags.npiv_supported) { |
Saurav Kashyap | 45980cc | 2012-08-22 14:21:21 -0400 | [diff] [blame] | 2033 | if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha)) |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 2034 | ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | c48339d | 2008-01-17 09:02:19 -0800 | [diff] [blame] | 2035 | mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports); |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 2036 | } |
| 2037 | |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 2038 | if (IS_FWI2_CAPABLE(ha)) { |
| 2039 | mid_init_cb->options = __constant_cpu_to_le16(BIT_1); |
| 2040 | mid_init_cb->init_cb.execution_throttle = |
| 2041 | cpu_to_le16(ha->fw_xcb_count); |
| 2042 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2043 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2044 | rval = qla2x00_init_firmware(vha, ha->init_cb_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2046 | ql_log(ql_log_fatal, vha, 0x00d2, |
| 2047 | "Init Firmware **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2048 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2049 | ql_dbg(ql_dbg_init, vha, 0x00d3, |
| 2050 | "Init Firmware -- success.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | } |
| 2052 | |
| 2053 | return (rval); |
| 2054 | } |
| 2055 | |
| 2056 | /** |
| 2057 | * qla2x00_fw_ready() - Waits for firmware ready. |
| 2058 | * @ha: HA context |
| 2059 | * |
| 2060 | * Returns 0 on success. |
| 2061 | */ |
| 2062 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2063 | qla2x00_fw_ready(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | { |
| 2065 | int rval; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2066 | unsigned long wtime, mtime, cs84xx_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | uint16_t min_wait; /* Minimum wait time if loop is down */ |
| 2068 | uint16_t wait_time; /* Wait time if loop is coming ready */ |
Andrew Vasquez | 656e891 | 2009-06-03 09:55:29 -0700 | [diff] [blame] | 2069 | uint16_t state[5]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2070 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | |
| 2072 | rval = QLA_SUCCESS; |
| 2073 | |
| 2074 | /* 20 seconds for loop down. */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2075 | min_wait = 20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | |
| 2077 | /* |
| 2078 | * Firmware should take at most one RATOV to login, plus 5 seconds for |
| 2079 | * our own processing. |
| 2080 | */ |
| 2081 | if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) { |
| 2082 | wait_time = min_wait; |
| 2083 | } |
| 2084 | |
| 2085 | /* Min wait time if loop down */ |
| 2086 | mtime = jiffies + (min_wait * HZ); |
| 2087 | |
| 2088 | /* wait time before firmware ready */ |
| 2089 | wtime = jiffies + (wait_time * HZ); |
| 2090 | |
| 2091 | /* Wait for ISP to finish LIP */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2092 | if (!vha->flags.init_done) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2093 | ql_log(ql_log_info, vha, 0x801e, |
| 2094 | "Waiting for LIP to complete.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | |
| 2096 | do { |
Andrew Vasquez | 5b93903 | 2012-11-21 02:40:26 -0500 | [diff] [blame] | 2097 | memset(state, -1, sizeof(state)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2098 | rval = qla2x00_get_firmware_state(vha, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | if (rval == QLA_SUCCESS) { |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2100 | if (state[0] < FSTATE_LOSS_OF_SYNC) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2101 | vha->device_flags &= ~DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2103 | if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2104 | ql_dbg(ql_dbg_taskm, vha, 0x801f, |
| 2105 | "fw_state=%x 84xx=%x.\n", state[0], |
| 2106 | state[2]); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2107 | if ((state[2] & FSTATE_LOGGED_IN) && |
| 2108 | (state[2] & FSTATE_WAITING_FOR_VERIFY)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2109 | ql_dbg(ql_dbg_taskm, vha, 0x8028, |
| 2110 | "Sending verify iocb.\n"); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2111 | |
| 2112 | cs84xx_time = jiffies; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2113 | rval = qla84xx_init_chip(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2114 | if (rval != QLA_SUCCESS) { |
| 2115 | ql_log(ql_log_warn, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2116 | vha, 0x8007, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2117 | "Init chip failed.\n"); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2118 | break; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2119 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2120 | |
| 2121 | /* Add time taken to initialize. */ |
| 2122 | cs84xx_time = jiffies - cs84xx_time; |
| 2123 | wtime += cs84xx_time; |
| 2124 | mtime += cs84xx_time; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2125 | ql_dbg(ql_dbg_taskm, vha, 0x8008, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2126 | "Increasing wait time by %ld. " |
| 2127 | "New time %ld.\n", cs84xx_time, |
| 2128 | wtime); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2129 | } |
| 2130 | } else if (state[0] == FSTATE_READY) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2131 | ql_dbg(ql_dbg_taskm, vha, 0x8037, |
| 2132 | "F/W Ready - OK.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2134 | qla2x00_get_retry_cnt(vha, &ha->retry_count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | &ha->login_timeout, &ha->r_a_tov); |
| 2136 | |
| 2137 | rval = QLA_SUCCESS; |
| 2138 | break; |
| 2139 | } |
| 2140 | |
| 2141 | rval = QLA_FUNCTION_FAILED; |
| 2142 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2143 | if (atomic_read(&vha->loop_down_timer) && |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 2144 | state[0] != FSTATE_READY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2145 | /* Loop down. Timeout on min_wait for states |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2146 | * other than Wait for Login. |
| 2147 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | if (time_after_eq(jiffies, mtime)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2149 | ql_log(ql_log_info, vha, 0x8038, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2150 | "Cable is unplugged...\n"); |
| 2151 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2152 | vha->device_flags |= DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2153 | break; |
| 2154 | } |
| 2155 | } |
| 2156 | } else { |
| 2157 | /* Mailbox cmd failed. Timeout on min_wait. */ |
Santosh Vernekar | cdbb0a4f | 2010-05-28 15:08:25 -0700 | [diff] [blame] | 2158 | if (time_after_eq(jiffies, mtime) || |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 2159 | ha->flags.isp82xx_fw_hung) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | break; |
| 2161 | } |
| 2162 | |
| 2163 | if (time_after_eq(jiffies, wtime)) |
| 2164 | break; |
| 2165 | |
| 2166 | /* Delay for a while */ |
| 2167 | msleep(500); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | } while (1); |
| 2169 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2170 | ql_dbg(ql_dbg_taskm, vha, 0x803a, |
| 2171 | "fw_state=%x (%x, %x, %x, %x) " "curr time=%lx.\n", state[0], |
| 2172 | state[1], state[2], state[3], state[4], jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2173 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2174 | if (rval && !(vha->device_flags & DFLG_NO_CABLE)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2175 | ql_log(ql_log_warn, vha, 0x803b, |
| 2176 | "Firmware ready **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | } |
| 2178 | |
| 2179 | return (rval); |
| 2180 | } |
| 2181 | |
| 2182 | /* |
| 2183 | * qla2x00_configure_hba |
| 2184 | * Setup adapter context. |
| 2185 | * |
| 2186 | * Input: |
| 2187 | * ha = adapter state pointer. |
| 2188 | * |
| 2189 | * Returns: |
| 2190 | * 0 = success |
| 2191 | * |
| 2192 | * Context: |
| 2193 | * Kernel context. |
| 2194 | */ |
| 2195 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2196 | qla2x00_configure_hba(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | { |
| 2198 | int rval; |
| 2199 | uint16_t loop_id; |
| 2200 | uint16_t topo; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2201 | uint16_t sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2202 | uint8_t al_pa; |
| 2203 | uint8_t area; |
| 2204 | uint8_t domain; |
| 2205 | char connect_type[22]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2206 | struct qla_hw_data *ha = vha->hw; |
Jiri Kosina | f24b5cb | 2012-10-08 09:23:54 +0200 | [diff] [blame] | 2207 | unsigned long flags; |
Joe Carnuccio | 61e1b26 | 2013-02-08 01:57:48 -0500 | [diff] [blame] | 2208 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | |
| 2210 | /* Get host addresses. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2211 | rval = qla2x00_get_adapter_id(vha, |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2212 | &loop_id, &al_pa, &area, &domain, &topo, &sw_cap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2213 | if (rval != QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2214 | if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) || |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2215 | IS_CNA_CAPABLE(ha) || |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 2216 | (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2217 | ql_dbg(ql_dbg_disc, vha, 0x2008, |
| 2218 | "Loop is in a transition state.\n"); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 2219 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2220 | ql_log(ql_log_warn, vha, 0x2009, |
| 2221 | "Unable to get host loop ID.\n"); |
Joe Carnuccio | 61e1b26 | 2013-02-08 01:57:48 -0500 | [diff] [blame] | 2222 | if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) && |
| 2223 | (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) { |
| 2224 | ql_log(ql_log_warn, vha, 0x1151, |
| 2225 | "Doing link init.\n"); |
| 2226 | if (qla24xx_link_initialize(vha) == QLA_SUCCESS) |
| 2227 | return rval; |
| 2228 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2229 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 2230 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2231 | return (rval); |
| 2232 | } |
| 2233 | |
| 2234 | if (topo == 4) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2235 | ql_log(ql_log_info, vha, 0x200a, |
| 2236 | "Cannot get topology - retrying.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2237 | return (QLA_FUNCTION_FAILED); |
| 2238 | } |
| 2239 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2240 | vha->loop_id = loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2241 | |
| 2242 | /* initialize */ |
| 2243 | ha->min_external_loopid = SNS_FIRST_LOOP_ID; |
| 2244 | ha->operating_mode = LOOP; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2245 | ha->switch_cap = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2246 | |
| 2247 | switch (topo) { |
| 2248 | case 0: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2249 | ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2250 | ha->current_topology = ISP_CFG_NL; |
| 2251 | strcpy(connect_type, "(Loop)"); |
| 2252 | break; |
| 2253 | |
| 2254 | case 1: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2255 | ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n"); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2256 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2257 | ha->current_topology = ISP_CFG_FL; |
| 2258 | strcpy(connect_type, "(FL_Port)"); |
| 2259 | break; |
| 2260 | |
| 2261 | case 2: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2262 | 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] | 2263 | ha->operating_mode = P2P; |
| 2264 | ha->current_topology = ISP_CFG_N; |
| 2265 | strcpy(connect_type, "(N_Port-to-N_Port)"); |
| 2266 | break; |
| 2267 | |
| 2268 | case 3: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2269 | 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] | 2270 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | ha->operating_mode = P2P; |
| 2272 | ha->current_topology = ISP_CFG_F; |
| 2273 | strcpy(connect_type, "(F_Port)"); |
| 2274 | break; |
| 2275 | |
| 2276 | default: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2277 | ql_dbg(ql_dbg_disc, vha, 0x200f, |
| 2278 | "HBA in unknown topology %x, using NL.\n", topo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | ha->current_topology = ISP_CFG_NL; |
| 2280 | strcpy(connect_type, "(Loop)"); |
| 2281 | break; |
| 2282 | } |
| 2283 | |
| 2284 | /* Save Host port and loop ID. */ |
| 2285 | /* byte order - Big Endian */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2286 | vha->d_id.b.domain = domain; |
| 2287 | vha->d_id.b.area = area; |
| 2288 | vha->d_id.b.al_pa = al_pa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2289 | |
Jiri Kosina | f24b5cb | 2012-10-08 09:23:54 +0200 | [diff] [blame] | 2290 | spin_lock_irqsave(&ha->vport_slock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2291 | qlt_update_vp_map(vha, SET_AL_PA); |
Jiri Kosina | f24b5cb | 2012-10-08 09:23:54 +0200 | [diff] [blame] | 2292 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2293 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2294 | if (!vha->flags.init_done) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2295 | ql_log(ql_log_info, vha, 0x2010, |
| 2296 | "Topology - %s, Host Loop address 0x%x.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2297 | connect_type, vha->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | |
| 2299 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2300 | ql_log(ql_log_warn, vha, 0x2011, |
| 2301 | "%s FAILED\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2302 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2303 | ql_dbg(ql_dbg_disc, vha, 0x2012, |
| 2304 | "%s success\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2305 | } |
| 2306 | |
| 2307 | return(rval); |
| 2308 | } |
| 2309 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2310 | inline void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2311 | qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len, |
| 2312 | char *def) |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2313 | { |
| 2314 | char *st, *en; |
| 2315 | uint16_t index; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2316 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | ab67114 | 2009-08-25 11:36:17 -0700 | [diff] [blame] | 2317 | int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) && |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2318 | !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2319 | |
| 2320 | if (memcmp(model, BINZERO, len) != 0) { |
| 2321 | strncpy(ha->model_number, model, len); |
| 2322 | st = en = ha->model_number; |
| 2323 | en += len - 1; |
| 2324 | while (en > st) { |
| 2325 | if (*en != 0x20 && *en != 0x00) |
| 2326 | break; |
| 2327 | *en-- = '\0'; |
| 2328 | } |
| 2329 | |
| 2330 | index = (ha->pdev->subsystem_device & 0xff); |
Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 2331 | if (use_tbl && |
| 2332 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2333 | index < QLA_MODEL_NAMES) |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2334 | strncpy(ha->model_desc, |
| 2335 | qla2x00_model_name[index * 2 + 1], |
| 2336 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2337 | } else { |
| 2338 | index = (ha->pdev->subsystem_device & 0xff); |
Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 2339 | if (use_tbl && |
| 2340 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2341 | index < QLA_MODEL_NAMES) { |
| 2342 | strcpy(ha->model_number, |
| 2343 | qla2x00_model_name[index * 2]); |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2344 | strncpy(ha->model_desc, |
| 2345 | qla2x00_model_name[index * 2 + 1], |
| 2346 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2347 | } else { |
| 2348 | strcpy(ha->model_number, def); |
| 2349 | } |
| 2350 | } |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2351 | if (IS_FWI2_CAPABLE(ha)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2352 | qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc, |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2353 | sizeof(ha->model_desc)); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2354 | } |
| 2355 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2356 | /* On sparc systems, obtain port and node WWN from firmware |
| 2357 | * properties. |
| 2358 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2359 | 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] | 2360 | { |
| 2361 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2362 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2363 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 2364 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 2365 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2366 | int len; |
| 2367 | |
| 2368 | val = of_get_property(dp, "port-wwn", &len); |
| 2369 | if (val && len >= WWN_SIZE) |
| 2370 | memcpy(nv->port_name, val, WWN_SIZE); |
| 2371 | |
| 2372 | val = of_get_property(dp, "node-wwn", &len); |
| 2373 | if (val && len >= WWN_SIZE) |
| 2374 | memcpy(nv->node_name, val, WWN_SIZE); |
| 2375 | #endif |
| 2376 | } |
| 2377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2378 | /* |
| 2379 | * NVRAM configuration for ISP 2xxx |
| 2380 | * |
| 2381 | * Input: |
| 2382 | * ha = adapter block pointer. |
| 2383 | * |
| 2384 | * Output: |
| 2385 | * initialization control block in response_ring |
| 2386 | * host adapters parameters in host adapter block |
| 2387 | * |
| 2388 | * Returns: |
| 2389 | * 0 = success. |
| 2390 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2391 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2392 | qla2x00_nvram_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2393 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2394 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2395 | uint8_t chksum = 0; |
| 2396 | uint16_t cnt; |
| 2397 | uint8_t *dptr1, *dptr2; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2398 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2399 | init_cb_t *icb = ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 2400 | nvram_t *nv = ha->nvram; |
| 2401 | uint8_t *ptr = ha->nvram; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2402 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2403 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2404 | rval = QLA_SUCCESS; |
| 2405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | /* Determine NVRAM starting address. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2407 | ha->nvram_size = sizeof(nvram_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2408 | ha->nvram_base = 0; |
| 2409 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) |
| 2410 | if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1) |
| 2411 | ha->nvram_base = 0x80; |
| 2412 | |
| 2413 | /* Get NVRAM data and calculate checksum. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2414 | 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] | 2415 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++) |
| 2416 | chksum += *ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2418 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f, |
| 2419 | "Contents of NVRAM.\n"); |
| 2420 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110, |
| 2421 | (uint8_t *)nv, ha->nvram_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2422 | |
| 2423 | /* Bad NVRAM data, set defaults parameters. */ |
| 2424 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || |
| 2425 | nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) { |
| 2426 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2427 | ql_log(ql_log_warn, vha, 0x0064, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 2428 | "Inconsistent NVRAM " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2429 | "detected: checksum=0x%x id=%c version=0x%x.\n", |
| 2430 | chksum, nv->id[0], nv->nvram_version); |
| 2431 | ql_log(ql_log_warn, vha, 0x0065, |
| 2432 | "Falling back to " |
| 2433 | "functioning (yet invalid -- WWPN) defaults.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2434 | |
| 2435 | /* |
| 2436 | * Set default initialization control block. |
| 2437 | */ |
| 2438 | memset(nv, 0, ha->nvram_size); |
| 2439 | nv->parameter_block_version = ICB_VERSION; |
| 2440 | |
| 2441 | if (IS_QLA23XX(ha)) { |
| 2442 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 2443 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 2444 | nv->add_firmware_options[0] = BIT_5; |
| 2445 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
| 2446 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 2447 | nv->special_options[1] = BIT_7; |
| 2448 | } else if (IS_QLA2200(ha)) { |
| 2449 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 2450 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 2451 | nv->add_firmware_options[0] = BIT_5; |
| 2452 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
| 2453 | nv->frame_payload_size = __constant_cpu_to_le16(1024); |
| 2454 | } else if (IS_QLA2100(ha)) { |
| 2455 | nv->firmware_options[0] = BIT_3 | BIT_1; |
| 2456 | nv->firmware_options[1] = BIT_5; |
| 2457 | nv->frame_payload_size = __constant_cpu_to_le16(1024); |
| 2458 | } |
| 2459 | |
| 2460 | nv->max_iocb_allocation = __constant_cpu_to_le16(256); |
| 2461 | nv->execution_throttle = __constant_cpu_to_le16(16); |
| 2462 | nv->retry_count = 8; |
| 2463 | nv->retry_delay = 1; |
| 2464 | |
| 2465 | nv->port_name[0] = 33; |
| 2466 | nv->port_name[3] = 224; |
| 2467 | nv->port_name[4] = 139; |
| 2468 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2469 | qla2xxx_nvram_wwn_from_ofw(vha, nv); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2470 | |
| 2471 | nv->login_timeout = 4; |
| 2472 | |
| 2473 | /* |
| 2474 | * Set default host adapter parameters |
| 2475 | */ |
| 2476 | nv->host_p[1] = BIT_2; |
| 2477 | nv->reset_delay = 5; |
| 2478 | nv->port_down_retry_count = 8; |
| 2479 | nv->max_luns_per_target = __constant_cpu_to_le16(8); |
| 2480 | nv->link_down_timeout = 60; |
| 2481 | |
| 2482 | rval = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2483 | } |
| 2484 | |
| 2485 | #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2) |
| 2486 | /* |
| 2487 | * The SN2 does not provide BIOS emulation which means you can't change |
| 2488 | * potentially bogus BIOS settings. Force the use of default settings |
| 2489 | * for link rate and frame size. Hope that the rest of the settings |
| 2490 | * are valid. |
| 2491 | */ |
| 2492 | if (ia64_platform_is("sn2")) { |
| 2493 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 2494 | if (IS_QLA23XX(ha)) |
| 2495 | nv->special_options[1] = BIT_7; |
| 2496 | } |
| 2497 | #endif |
| 2498 | |
| 2499 | /* Reset Initialization control block */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2500 | memset(icb, 0, ha->init_cb_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | |
| 2502 | /* |
| 2503 | * Setup driver NVRAM options. |
| 2504 | */ |
| 2505 | nv->firmware_options[0] |= (BIT_6 | BIT_1); |
| 2506 | nv->firmware_options[0] &= ~(BIT_5 | BIT_4); |
| 2507 | nv->firmware_options[1] |= (BIT_5 | BIT_0); |
| 2508 | nv->firmware_options[1] &= ~BIT_4; |
| 2509 | |
| 2510 | if (IS_QLA23XX(ha)) { |
| 2511 | nv->firmware_options[0] |= BIT_2; |
| 2512 | nv->firmware_options[0] &= ~BIT_3; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2513 | nv->special_options[0] &= ~BIT_6; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2514 | nv->add_firmware_options[1] |= BIT_5 | BIT_4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2515 | |
| 2516 | if (IS_QLA2300(ha)) { |
| 2517 | if (ha->fb_rev == FPM_2310) { |
| 2518 | strcpy(ha->model_number, "QLA2310"); |
| 2519 | } else { |
| 2520 | strcpy(ha->model_number, "QLA2300"); |
| 2521 | } |
| 2522 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2523 | qla2x00_set_model_info(vha, nv->model_number, |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2524 | sizeof(nv->model_number), "QLA23xx"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2525 | } |
| 2526 | } else if (IS_QLA2200(ha)) { |
| 2527 | nv->firmware_options[0] |= BIT_2; |
| 2528 | /* |
| 2529 | * 'Point-to-point preferred, else loop' is not a safe |
| 2530 | * connection mode setting. |
| 2531 | */ |
| 2532 | if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) == |
| 2533 | (BIT_5 | BIT_4)) { |
| 2534 | /* Force 'loop preferred, else point-to-point'. */ |
| 2535 | nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4); |
| 2536 | nv->add_firmware_options[0] |= BIT_5; |
| 2537 | } |
| 2538 | strcpy(ha->model_number, "QLA22xx"); |
| 2539 | } else /*if (IS_QLA2100(ha))*/ { |
| 2540 | strcpy(ha->model_number, "QLA2100"); |
| 2541 | } |
| 2542 | |
| 2543 | /* |
| 2544 | * Copy over NVRAM RISC parameter block to initialization control block. |
| 2545 | */ |
| 2546 | dptr1 = (uint8_t *)icb; |
| 2547 | dptr2 = (uint8_t *)&nv->parameter_block_version; |
| 2548 | cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version; |
| 2549 | while (cnt--) |
| 2550 | *dptr1++ = *dptr2++; |
| 2551 | |
| 2552 | /* Copy 2nd half. */ |
| 2553 | dptr1 = (uint8_t *)icb->add_firmware_options; |
| 2554 | cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options; |
| 2555 | while (cnt--) |
| 2556 | *dptr1++ = *dptr2++; |
| 2557 | |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 2558 | /* Use alternate WWN? */ |
| 2559 | if (nv->host_p[1] & BIT_7) { |
| 2560 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 2561 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 2562 | } |
| 2563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2564 | /* Prepare nodename */ |
| 2565 | if ((icb->firmware_options[1] & BIT_6) == 0) { |
| 2566 | /* |
| 2567 | * Firmware will apply the following mask if the nodename was |
| 2568 | * not provided. |
| 2569 | */ |
| 2570 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 2571 | icb->node_name[0] &= 0xF0; |
| 2572 | } |
| 2573 | |
| 2574 | /* |
| 2575 | * Set host adapter parameters. |
| 2576 | */ |
Saurav Kashyap | 3ce8866 | 2011-07-14 12:00:12 -0700 | [diff] [blame] | 2577 | |
| 2578 | /* |
| 2579 | * BIT_7 in the host-parameters section allows for modification to |
| 2580 | * internal driver logging. |
| 2581 | */ |
Andrew Vasquez | 0181944 | 2006-06-23 16:11:10 -0700 | [diff] [blame] | 2582 | if (nv->host_p[0] & BIT_7) |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2583 | ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2584 | ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0); |
| 2585 | /* Always load RISC code on non ISP2[12]00 chips. */ |
| 2586 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) |
| 2587 | ha->flags.disable_risc_code_load = 0; |
| 2588 | ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0); |
| 2589 | ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0); |
| 2590 | 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] | 2591 | 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] | 2592 | ha->flags.disable_serdes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 | |
| 2594 | ha->operating_mode = |
| 2595 | (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 2596 | |
| 2597 | memcpy(ha->fw_seriallink_options, nv->seriallink_options, |
| 2598 | sizeof(ha->fw_seriallink_options)); |
| 2599 | |
| 2600 | /* save HBA serial number */ |
| 2601 | ha->serial0 = icb->port_name[5]; |
| 2602 | ha->serial1 = icb->port_name[6]; |
| 2603 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2604 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 2605 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2606 | |
| 2607 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 2608 | |
| 2609 | ha->retry_count = nv->retry_count; |
| 2610 | |
| 2611 | /* Set minimum login_timeout to 4 seconds. */ |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 2612 | if (nv->login_timeout != ql2xlogintimeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2613 | nv->login_timeout = ql2xlogintimeout; |
| 2614 | if (nv->login_timeout < 4) |
| 2615 | nv->login_timeout = 4; |
| 2616 | ha->login_timeout = nv->login_timeout; |
| 2617 | icb->login_timeout = nv->login_timeout; |
| 2618 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 2619 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 2620 | ha->r_a_tov = 100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2621 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2622 | ha->loop_reset_delay = nv->reset_delay; |
| 2623 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2624 | /* Link Down Timeout = 0: |
| 2625 | * |
| 2626 | * When Port Down timer expires we will start returning |
| 2627 | * I/O's to OS with "DID_NO_CONNECT". |
| 2628 | * |
| 2629 | * Link Down Timeout != 0: |
| 2630 | * |
| 2631 | * The driver waits for the link to come up after link down |
| 2632 | * before returning I/Os to OS with "DID_NO_CONNECT". |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2633 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2634 | if (nv->link_down_timeout == 0) { |
| 2635 | ha->loop_down_abort_time = |
Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 2636 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | } else { |
| 2638 | ha->link_down_timeout = nv->link_down_timeout; |
| 2639 | ha->loop_down_abort_time = |
| 2640 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2641 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2642 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2643 | /* |
| 2644 | * Need enough time to try and get the port back. |
| 2645 | */ |
| 2646 | ha->port_down_retry_count = nv->port_down_retry_count; |
| 2647 | if (qlport_down_retry) |
| 2648 | ha->port_down_retry_count = qlport_down_retry; |
| 2649 | /* Set login_retry_count */ |
| 2650 | ha->login_retry_count = nv->retry_count; |
| 2651 | if (ha->port_down_retry_count == nv->port_down_retry_count && |
| 2652 | ha->port_down_retry_count > 3) |
| 2653 | ha->login_retry_count = ha->port_down_retry_count; |
| 2654 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 2655 | ha->login_retry_count = ha->port_down_retry_count; |
| 2656 | if (ql2xloginretrycount) |
| 2657 | ha->login_retry_count = ql2xloginretrycount; |
| 2658 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | icb->lun_enables = __constant_cpu_to_le16(0); |
| 2660 | icb->command_resource_count = 0; |
| 2661 | icb->immediate_notify_resource_count = 0; |
| 2662 | icb->timeout = __constant_cpu_to_le16(0); |
| 2663 | |
| 2664 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 2665 | /* Enable RIO */ |
| 2666 | icb->firmware_options[0] &= ~BIT_3; |
| 2667 | icb->add_firmware_options[0] &= |
| 2668 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 2669 | icb->add_firmware_options[0] |= BIT_2; |
| 2670 | icb->response_accumulation_timer = 3; |
| 2671 | icb->interrupt_delay_timer = 5; |
| 2672 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2673 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2674 | } else { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2675 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2676 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2677 | ha->zio_mode = icb->add_firmware_options[0] & |
| 2678 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 2679 | ha->zio_timer = icb->interrupt_delay_timer ? |
| 2680 | icb->interrupt_delay_timer: 2; |
| 2681 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2682 | icb->add_firmware_options[0] &= |
| 2683 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2684 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2685 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 2686 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 2687 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2688 | ql_log(ql_log_info, vha, 0x0068, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2689 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 2690 | ha->zio_mode, ha->zio_timer * 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2691 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2692 | icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode; |
| 2693 | icb->interrupt_delay_timer = (uint8_t)ha->zio_timer; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2694 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | } |
| 2696 | } |
| 2697 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2698 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2699 | ql_log(ql_log_warn, vha, 0x0069, |
| 2700 | "NVRAM configuration failed.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2701 | } |
| 2702 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2703 | } |
| 2704 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2705 | static void |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2706 | qla2x00_rport_del(void *data) |
| 2707 | { |
| 2708 | fc_port_t *fcport = data; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2709 | struct fc_rport *rport; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2710 | scsi_qla_host_t *vha = fcport->vha; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2711 | unsigned long flags; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2712 | |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2713 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2714 | rport = fcport->drport ? fcport->drport: fcport->rport; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2715 | fcport->drport = NULL; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2716 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2717 | if (rport) { |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2718 | fc_remote_port_delete(rport); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2719 | /* |
| 2720 | * Release the target mode FC NEXUS in qla_target.c code |
| 2721 | * if target mod is enabled. |
| 2722 | */ |
| 2723 | qlt_fc_port_deleted(vha, fcport); |
| 2724 | } |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2725 | } |
| 2726 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2727 | /** |
| 2728 | * qla2x00_alloc_fcport() - Allocate a generic fcport. |
| 2729 | * @ha: HA context |
| 2730 | * @flags: allocation flags |
| 2731 | * |
| 2732 | * Returns a pointer to the allocated fcport, or NULL, if none available. |
| 2733 | */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2734 | fc_port_t * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2735 | qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2736 | { |
| 2737 | fc_port_t *fcport; |
| 2738 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2739 | fcport = kzalloc(sizeof(fc_port_t), flags); |
| 2740 | if (!fcport) |
| 2741 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2742 | |
| 2743 | /* Setup fcport template structure. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2744 | fcport->vha = vha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | fcport->port_type = FCT_UNKNOWN; |
| 2746 | fcport->loop_id = FC_NO_LOOP_ID; |
Chad Dupuis | ec426e1 | 2011-03-30 11:46:32 -0700 | [diff] [blame] | 2747 | qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED); |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 2748 | fcport->supported_classes = FC_COS_UNSPECIFIED; |
Joe Carnuccio | c0822b6 | 2012-05-15 14:34:21 -0400 | [diff] [blame] | 2749 | fcport->scan_state = QLA_FCPORT_SCAN_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2751 | return fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2752 | } |
| 2753 | |
| 2754 | /* |
| 2755 | * qla2x00_configure_loop |
| 2756 | * Updates Fibre Channel Device Database with what is actually on loop. |
| 2757 | * |
| 2758 | * Input: |
| 2759 | * ha = adapter block pointer. |
| 2760 | * |
| 2761 | * Returns: |
| 2762 | * 0 = success. |
| 2763 | * 1 = error. |
| 2764 | * 2 = database was full and device was not configured. |
| 2765 | */ |
| 2766 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2767 | qla2x00_configure_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2768 | { |
| 2769 | int rval; |
| 2770 | unsigned long flags, save_flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2771 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2772 | rval = QLA_SUCCESS; |
| 2773 | |
| 2774 | /* Get Initiator ID */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2775 | if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) { |
| 2776 | rval = qla2x00_configure_hba(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2777 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2778 | ql_dbg(ql_dbg_disc, vha, 0x2013, |
| 2779 | "Unable to configure HBA.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | return (rval); |
| 2781 | } |
| 2782 | } |
| 2783 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2784 | save_flags = flags = vha->dpc_flags; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2785 | ql_dbg(ql_dbg_disc, vha, 0x2014, |
| 2786 | "Configure loop -- dpc flags = 0x%lx.\n", flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | |
| 2788 | /* |
| 2789 | * If we have both an RSCN and PORT UPDATE pending then handle them |
| 2790 | * both at the same time. |
| 2791 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2792 | clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 2793 | clear_bit(RSCN_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2794 | |
Michael Hernandez | 3064ff3 | 2009-12-15 21:29:44 -0800 | [diff] [blame] | 2795 | qla2x00_get_data_rate(vha); |
| 2796 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2797 | /* Determine what we need to do */ |
| 2798 | if (ha->current_topology == ISP_CFG_FL && |
| 2799 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 2800 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2801 | set_bit(RSCN_UPDATE, &flags); |
| 2802 | |
| 2803 | } else if (ha->current_topology == ISP_CFG_F && |
| 2804 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 2805 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2806 | set_bit(RSCN_UPDATE, &flags); |
| 2807 | clear_bit(LOCAL_LOOP_UPDATE, &flags); |
| 2808 | |
Andrew Vasquez | 21333b4 | 2006-05-17 15:09:56 -0700 | [diff] [blame] | 2809 | } else if (ha->current_topology == ISP_CFG_N) { |
| 2810 | clear_bit(RSCN_UPDATE, &flags); |
| 2811 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2812 | } else if (!vha->flags.online || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2813 | (test_bit(ABORT_ISP_ACTIVE, &flags))) { |
| 2814 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2815 | set_bit(RSCN_UPDATE, &flags); |
| 2816 | set_bit(LOCAL_LOOP_UPDATE, &flags); |
| 2817 | } |
| 2818 | |
| 2819 | if (test_bit(LOCAL_LOOP_UPDATE, &flags)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2820 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
| 2821 | ql_dbg(ql_dbg_disc, vha, 0x2015, |
| 2822 | "Loop resync needed, failing.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2823 | rval = QLA_FUNCTION_FAILED; |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 2824 | } else |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2825 | rval = qla2x00_configure_local_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2826 | } |
| 2827 | |
| 2828 | if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2829 | if (LOOP_TRANSITION(vha)) { |
| 2830 | ql_dbg(ql_dbg_disc, vha, 0x201e, |
| 2831 | "Needs RSCN update and loop transition.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2832 | rval = QLA_FUNCTION_FAILED; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2833 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2834 | else |
| 2835 | rval = qla2x00_configure_fabric(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2836 | } |
| 2837 | |
| 2838 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2839 | if (atomic_read(&vha->loop_down_timer) || |
| 2840 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2841 | rval = QLA_FUNCTION_FAILED; |
| 2842 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2843 | atomic_set(&vha->loop_state, LOOP_READY); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2844 | ql_dbg(ql_dbg_disc, vha, 0x2069, |
| 2845 | "LOOP READY.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | } |
| 2847 | } |
| 2848 | |
| 2849 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2850 | ql_dbg(ql_dbg_disc, vha, 0x206a, |
| 2851 | "%s *** FAILED ***.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2852 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2853 | ql_dbg(ql_dbg_disc, vha, 0x206b, |
| 2854 | "%s: exiting normally.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2855 | } |
| 2856 | |
Bjorn Helgaas | cc3ef7b | 2008-09-11 21:22:51 -0700 | [diff] [blame] | 2857 | /* Restore state if a resync event occurred during processing */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2858 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2859 | if (test_bit(LOCAL_LOOP_UPDATE, &save_flags)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2860 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 2861 | if (test_bit(RSCN_UPDATE, &save_flags)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2862 | set_bit(RSCN_UPDATE, &vha->dpc_flags); |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 2863 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2864 | } |
| 2865 | |
| 2866 | return (rval); |
| 2867 | } |
| 2868 | |
| 2869 | |
| 2870 | |
| 2871 | /* |
| 2872 | * qla2x00_configure_local_loop |
| 2873 | * Updates Fibre Channel Device Database with local loop devices. |
| 2874 | * |
| 2875 | * Input: |
| 2876 | * ha = adapter block pointer. |
| 2877 | * |
| 2878 | * Returns: |
| 2879 | * 0 = success. |
| 2880 | */ |
| 2881 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2882 | qla2x00_configure_local_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2883 | { |
| 2884 | int rval, rval2; |
| 2885 | int found_devs; |
| 2886 | int found; |
| 2887 | fc_port_t *fcport, *new_fcport; |
| 2888 | |
| 2889 | uint16_t index; |
| 2890 | uint16_t entries; |
| 2891 | char *id_iter; |
| 2892 | uint16_t loop_id; |
| 2893 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2894 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2895 | |
| 2896 | found_devs = 0; |
| 2897 | new_fcport = NULL; |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 2898 | entries = MAX_FIBRE_DEVICES_LOOP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2899 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | /* Get list of logged in devices. */ |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 2901 | memset(ha->gid_list, 0, qla2x00_gid_list_size(ha)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2902 | 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] | 2903 | &entries); |
| 2904 | if (rval != QLA_SUCCESS) |
| 2905 | goto cleanup_allocation; |
| 2906 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2907 | ql_dbg(ql_dbg_disc, vha, 0x2017, |
| 2908 | "Entries in ID list (%d).\n", entries); |
| 2909 | ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075, |
| 2910 | (uint8_t *)ha->gid_list, |
| 2911 | entries * sizeof(struct gid_list_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2912 | |
| 2913 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2914 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2915 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2916 | ql_log(ql_log_warn, vha, 0x2018, |
| 2917 | "Memory allocation failed for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2918 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 2919 | goto cleanup_allocation; |
| 2920 | } |
| 2921 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 2922 | |
| 2923 | /* |
| 2924 | * Mark local devices that were present with FCF_DEVICE_LOST for now. |
| 2925 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2926 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2927 | if (atomic_read(&fcport->state) == FCS_ONLINE && |
| 2928 | fcport->port_type != FCT_BROADCAST && |
| 2929 | (fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 2930 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2931 | ql_dbg(ql_dbg_disc, vha, 0x2019, |
| 2932 | "Marking port lost loop_id=0x%04x.\n", |
| 2933 | fcport->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2934 | |
Chad Dupuis | ec426e1 | 2011-03-30 11:46:32 -0700 | [diff] [blame] | 2935 | qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2936 | } |
| 2937 | } |
| 2938 | |
| 2939 | /* Add devices to port list. */ |
| 2940 | id_iter = (char *)ha->gid_list; |
| 2941 | for (index = 0; index < entries; index++) { |
| 2942 | domain = ((struct gid_list_info *)id_iter)->domain; |
| 2943 | area = ((struct gid_list_info *)id_iter)->area; |
| 2944 | al_pa = ((struct gid_list_info *)id_iter)->al_pa; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2945 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2946 | loop_id = (uint16_t) |
| 2947 | ((struct gid_list_info *)id_iter)->loop_id_2100; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2948 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2949 | loop_id = le16_to_cpu( |
| 2950 | ((struct gid_list_info *)id_iter)->loop_id); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2951 | id_iter += ha->gid_list_info_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2952 | |
| 2953 | /* Bypass reserved domain fields. */ |
| 2954 | if ((domain & 0xf0) == 0xf0) |
| 2955 | continue; |
| 2956 | |
| 2957 | /* Bypass if not same domain and area of adapter. */ |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 2958 | if (area && domain && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2959 | (area != vha->d_id.b.area || domain != vha->d_id.b.domain)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2960 | continue; |
| 2961 | |
| 2962 | /* Bypass invalid local loop ID. */ |
| 2963 | if (loop_id > LAST_LOCAL_LOOP_ID) |
| 2964 | continue; |
| 2965 | |
Arun Easi | 370d550 | 2012-08-22 14:21:10 -0400 | [diff] [blame] | 2966 | memset(new_fcport, 0, sizeof(fc_port_t)); |
| 2967 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | /* Fill in member data. */ |
| 2969 | new_fcport->d_id.b.domain = domain; |
| 2970 | new_fcport->d_id.b.area = area; |
| 2971 | new_fcport->d_id.b.al_pa = al_pa; |
| 2972 | new_fcport->loop_id = loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2973 | rval2 = qla2x00_get_port_database(vha, new_fcport, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2974 | if (rval2 != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2975 | ql_dbg(ql_dbg_disc, vha, 0x201a, |
| 2976 | "Failed to retrieve fcport information " |
| 2977 | "-- get_port_database=%x, loop_id=0x%04x.\n", |
| 2978 | rval2, new_fcport->loop_id); |
| 2979 | ql_dbg(ql_dbg_disc, vha, 0x201b, |
| 2980 | "Scheduling resync.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2981 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2982 | continue; |
| 2983 | } |
| 2984 | |
| 2985 | /* Check for matching device in port list. */ |
| 2986 | found = 0; |
| 2987 | fcport = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2988 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2989 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 2990 | WWN_SIZE)) |
| 2991 | continue; |
| 2992 | |
Shyam Sundar | ddb9b12 | 2009-03-24 09:08:10 -0700 | [diff] [blame] | 2993 | fcport->flags &= ~FCF_FABRIC_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2994 | fcport->loop_id = new_fcport->loop_id; |
| 2995 | fcport->port_type = new_fcport->port_type; |
| 2996 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 2997 | memcpy(fcport->node_name, new_fcport->node_name, |
| 2998 | WWN_SIZE); |
| 2999 | |
| 3000 | found++; |
| 3001 | break; |
| 3002 | } |
| 3003 | |
| 3004 | if (!found) { |
| 3005 | /* New device, add to fcports list. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3006 | list_add_tail(&new_fcport->list, &vha->vp_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3007 | |
| 3008 | /* Allocate a new replacement fcport. */ |
| 3009 | fcport = new_fcport; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3010 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3012 | ql_log(ql_log_warn, vha, 0x201c, |
| 3013 | "Failed to allocate memory for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3014 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 3015 | goto cleanup_allocation; |
| 3016 | } |
| 3017 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 3018 | } |
| 3019 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3020 | /* Base iIDMA settings on HBA port speed. */ |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 3021 | fcport->fp_speed = ha->link_data_rate; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3022 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3023 | qla2x00_update_fcport(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3024 | |
| 3025 | found_devs++; |
| 3026 | } |
| 3027 | |
| 3028 | cleanup_allocation: |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 3029 | kfree(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | |
| 3031 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3032 | ql_dbg(ql_dbg_disc, vha, 0x201d, |
| 3033 | "Configure local loop error exit: rval=%x.\n", rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3034 | } |
| 3035 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | return (rval); |
| 3037 | } |
| 3038 | |
| 3039 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3040 | qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3041 | { |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3042 | int rval; |
Harish Zunjarrao | 1bb3954 | 2009-06-17 10:30:29 -0700 | [diff] [blame] | 3043 | uint16_t mb[4]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3044 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3045 | |
Andrew Vasquez | c76f2c0 | 2007-07-19 15:05:57 -0700 | [diff] [blame] | 3046 | if (!IS_IIDMA_CAPABLE(ha)) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3047 | return; |
| 3048 | |
Giridhar Malavali | c9afb9a | 2010-09-03 15:20:48 -0700 | [diff] [blame] | 3049 | if (atomic_read(&fcport->state) != FCS_ONLINE) |
| 3050 | return; |
| 3051 | |
Andrew Vasquez | 39bd962 | 2007-09-20 14:07:34 -0700 | [diff] [blame] | 3052 | if (fcport->fp_speed == PORT_SPEED_UNKNOWN || |
| 3053 | fcport->fp_speed > ha->link_data_rate) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3054 | return; |
| 3055 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3056 | rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed, |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 3057 | mb); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3058 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3059 | ql_dbg(ql_dbg_disc, vha, 0x2004, |
| 3060 | "Unable to adjust iIDMA " |
| 3061 | "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x " |
| 3062 | "%04x.\n", fcport->port_name[0], fcport->port_name[1], |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3063 | fcport->port_name[2], fcport->port_name[3], |
| 3064 | fcport->port_name[4], fcport->port_name[5], |
| 3065 | fcport->port_name[6], fcport->port_name[7], rval, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3066 | fcport->fp_speed, mb[0], mb[1]); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3067 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3068 | ql_dbg(ql_dbg_disc, vha, 0x2005, |
| 3069 | "iIDMA adjusted to %s GB/s " |
Joe Carnuccio | d0297c9 | 2012-11-21 02:40:40 -0500 | [diff] [blame] | 3070 | "on %02x%02x%02x%02x%02x%02x%02x%02x.\n", |
| 3071 | qla2x00_get_link_speed_str(ha, fcport->fp_speed), |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3072 | fcport->port_name[0], fcport->port_name[1], |
| 3073 | fcport->port_name[2], fcport->port_name[3], |
| 3074 | fcport->port_name[4], fcport->port_name[5], |
| 3075 | fcport->port_name[6], fcport->port_name[7]); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3076 | } |
| 3077 | } |
| 3078 | |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 3079 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3080 | qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 3081 | { |
| 3082 | struct fc_rport_identifiers rport_ids; |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 3083 | struct fc_rport *rport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 3084 | unsigned long flags; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 3085 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3086 | qla2x00_rport_del(fcport); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 3087 | |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 3088 | rport_ids.node_name = wwn_to_u64(fcport->node_name); |
| 3089 | rport_ids.port_name = wwn_to_u64(fcport->port_name); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 3090 | rport_ids.port_id = fcport->d_id.b.domain << 16 | |
| 3091 | fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa; |
| 3092 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3093 | fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 3094 | if (!rport) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3095 | ql_log(ql_log_warn, vha, 0x2006, |
| 3096 | "Unable to allocate fc remote port.\n"); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 3097 | return; |
| 3098 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3099 | /* |
| 3100 | * Create target mode FC NEXUS in qla_target.c if target mode is |
| 3101 | * enabled.. |
| 3102 | */ |
| 3103 | qlt_fc_port_added(vha, fcport); |
| 3104 | |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 3105 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 3106 | *((fc_port_t **)rport->dd_data) = fcport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 3107 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3108 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 3109 | rport->supported_classes = fcport->supported_classes; |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 3110 | |
| 3111 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 3112 | if (fcport->port_type == FCT_INITIATOR) |
| 3113 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 3114 | if (fcport->port_type == FCT_TARGET) |
| 3115 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 3116 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 3117 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3118 | |
| 3119 | /* |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 3120 | * qla2x00_update_fcport |
| 3121 | * Updates device on list. |
| 3122 | * |
| 3123 | * Input: |
| 3124 | * ha = adapter block pointer. |
| 3125 | * fcport = port structure pointer. |
| 3126 | * |
| 3127 | * Return: |
| 3128 | * 0 - Success |
| 3129 | * BIT_0 - error |
| 3130 | * |
| 3131 | * Context: |
| 3132 | * Kernel context. |
| 3133 | */ |
| 3134 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3135 | qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 3136 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3137 | fcport->vha = vha; |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 3138 | fcport->login_retry = 0; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 3139 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 3140 | |
Joe Carnuccio | 1f93da52 | 2012-11-21 02:40:38 -0500 | [diff] [blame] | 3141 | qla2x00_set_fcport_state(fcport, FCS_ONLINE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3142 | qla2x00_iidma_fcport(vha, fcport); |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 3143 | qla24xx_update_fcport_fcp_prio(vha, fcport); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3144 | qla2x00_reg_remote_port(vha, fcport); |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 3145 | } |
| 3146 | |
| 3147 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3148 | * qla2x00_configure_fabric |
| 3149 | * Setup SNS devices with loop ID's. |
| 3150 | * |
| 3151 | * Input: |
| 3152 | * ha = adapter block pointer. |
| 3153 | * |
| 3154 | * Returns: |
| 3155 | * 0 = success. |
| 3156 | * BIT_0 = error |
| 3157 | */ |
| 3158 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3159 | qla2x00_configure_fabric(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3160 | { |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 3161 | int rval; |
Joe Carnuccio | 4dc77c3 | 2012-05-15 14:34:24 -0400 | [diff] [blame] | 3162 | fc_port_t *fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3163 | uint16_t next_loopid; |
| 3164 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3165 | uint16_t loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3166 | LIST_HEAD(new_fcports); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3167 | struct qla_hw_data *ha = vha->hw; |
| 3168 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3169 | |
| 3170 | /* If FL port exists, then SNS is present */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 3171 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3172 | loop_id = NPH_F_PORT; |
| 3173 | else |
| 3174 | loop_id = SNS_FL_PORT; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3175 | 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] | 3176 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3177 | ql_dbg(ql_dbg_disc, vha, 0x201f, |
| 3178 | "MBX_GET_PORT_NAME failed, No FL Port.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3179 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3180 | vha->device_flags &= ~SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3181 | return (QLA_SUCCESS); |
| 3182 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3183 | vha->device_flags |= SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3185 | do { |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 3186 | /* FDMI support. */ |
| 3187 | if (ql2xfdmienable && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3188 | test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags)) |
| 3189 | qla2x00_fdmi_register(vha); |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 3190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3191 | /* Ensure we are logged into the SNS. */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 3192 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3193 | loop_id = NPH_SNS; |
| 3194 | else |
| 3195 | loop_id = SIMPLE_NAME_SERVER; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 3196 | rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff, |
| 3197 | 0xfc, mb, BIT_1|BIT_0); |
| 3198 | if (rval != QLA_SUCCESS) { |
| 3199 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Joe Carnuccio | 4dc77c3 | 2012-05-15 14:34:24 -0400 | [diff] [blame] | 3200 | break; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 3201 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3202 | if (mb[0] != MBS_COMMAND_COMPLETE) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3203 | ql_dbg(ql_dbg_disc, vha, 0x2042, |
| 3204 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x " |
| 3205 | "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1], |
| 3206 | mb[2], mb[6], mb[7]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3207 | return (QLA_SUCCESS); |
| 3208 | } |
| 3209 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3210 | if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) { |
| 3211 | if (qla2x00_rft_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3213 | ql_dbg(ql_dbg_disc, vha, 0x2045, |
| 3214 | "Register FC-4 TYPE failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3215 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3216 | if (qla2x00_rff_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3217 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3218 | ql_dbg(ql_dbg_disc, vha, 0x2049, |
| 3219 | "Register FC-4 Features failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3221 | if (qla2x00_rnn_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3222 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3223 | ql_dbg(ql_dbg_disc, vha, 0x204f, |
| 3224 | "Register Node Name failed.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3225 | } else if (qla2x00_rsnn_nn(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | /* EMPTY */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3227 | ql_dbg(ql_dbg_disc, vha, 0x2053, |
| 3228 | "Register Symobilic Node Name failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | } |
| 3230 | } |
| 3231 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3232 | rval = qla2x00_find_all_fabric_devs(vha, &new_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3233 | if (rval != QLA_SUCCESS) |
| 3234 | break; |
| 3235 | |
Joe Carnuccio | 4dc77c3 | 2012-05-15 14:34:24 -0400 | [diff] [blame] | 3236 | /* Add new ports to existing port list */ |
| 3237 | list_splice_tail_init(&new_fcports, &vha->vp_fcports); |
| 3238 | |
| 3239 | /* Starting free loop ID. */ |
| 3240 | next_loopid = ha->min_external_loopid; |
| 3241 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3242 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 3243 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3244 | break; |
| 3245 | |
| 3246 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) |
| 3247 | continue; |
| 3248 | |
Joe Carnuccio | 4dc77c3 | 2012-05-15 14:34:24 -0400 | [diff] [blame] | 3249 | /* Logout lost/gone fabric devices (non-FCP2) */ |
Joe Carnuccio | c0822b6 | 2012-05-15 14:34:21 -0400 | [diff] [blame] | 3250 | if (fcport->scan_state != QLA_FCPORT_SCAN_FOUND && |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 3251 | atomic_read(&fcport->state) == FCS_ONLINE) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3252 | qla2x00_mark_device_lost(vha, fcport, |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3253 | ql2xplogiabsentdevice, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | if (fcport->loop_id != FC_NO_LOOP_ID && |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3255 | (fcport->flags & FCF_FCP2_DEVICE) == 0 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3256 | fcport->port_type != FCT_INITIATOR && |
| 3257 | fcport->port_type != FCT_BROADCAST) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3258 | ha->isp_ops->fabric_logout(vha, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3259 | fcport->loop_id, |
| 3260 | fcport->d_id.b.domain, |
| 3261 | fcport->d_id.b.area, |
| 3262 | fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3263 | } |
Joe Carnuccio | c0822b6 | 2012-05-15 14:34:21 -0400 | [diff] [blame] | 3264 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3265 | } |
Joe Carnuccio | c0822b6 | 2012-05-15 14:34:21 -0400 | [diff] [blame] | 3266 | fcport->scan_state = QLA_FCPORT_SCAN_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3267 | |
Joe Carnuccio | 4dc77c3 | 2012-05-15 14:34:24 -0400 | [diff] [blame] | 3268 | /* Login fabric devices that need a login */ |
| 3269 | if ((fcport->flags & FCF_LOGIN_NEEDED) != 0 && |
| 3270 | atomic_read(&vha->loop_down_timer) == 0) { |
| 3271 | if (fcport->loop_id == FC_NO_LOOP_ID) { |
| 3272 | fcport->loop_id = next_loopid; |
| 3273 | rval = qla2x00_find_new_loop_id( |
| 3274 | base_vha, fcport); |
| 3275 | if (rval != QLA_SUCCESS) { |
| 3276 | /* Ran out of IDs to use */ |
| 3277 | continue; |
| 3278 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3279 | } |
| 3280 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3281 | |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 3282 | /* Login and update database */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3283 | qla2x00_fabric_dev_login(vha, fcport, &next_loopid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3284 | } |
| 3285 | } while (0); |
| 3286 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3287 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3288 | ql_dbg(ql_dbg_disc, vha, 0x2068, |
| 3289 | "Configure fabric error exit rval=%d.\n", rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3290 | } |
| 3291 | |
| 3292 | return (rval); |
| 3293 | } |
| 3294 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3295 | /* |
| 3296 | * qla2x00_find_all_fabric_devs |
| 3297 | * |
| 3298 | * Input: |
| 3299 | * ha = adapter block pointer. |
| 3300 | * dev = database device entry pointer. |
| 3301 | * |
| 3302 | * Returns: |
| 3303 | * 0 = success. |
| 3304 | * |
| 3305 | * Context: |
| 3306 | * Kernel context. |
| 3307 | */ |
| 3308 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3309 | qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha, |
| 3310 | struct list_head *new_fcports) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3311 | { |
| 3312 | int rval; |
| 3313 | uint16_t loop_id; |
| 3314 | fc_port_t *fcport, *new_fcport, *fcptemp; |
| 3315 | int found; |
| 3316 | |
| 3317 | sw_info_t *swl; |
| 3318 | int swl_idx; |
| 3319 | int first_dev, last_dev; |
Mike Waychison | 1516ef4 | 2010-05-04 15:01:31 -0700 | [diff] [blame] | 3320 | port_id_t wrap = {}, nxt_d_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3321 | struct qla_hw_data *ha = vha->hw; |
| 3322 | struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev); |
Anirban Chakraborty | ee546b6 | 2009-03-05 11:07:02 -0800 | [diff] [blame] | 3323 | struct scsi_qla_host *tvp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3324 | |
| 3325 | rval = QLA_SUCCESS; |
| 3326 | |
| 3327 | /* Try GID_PT to get device list, else GAN. */ |
Andrew Vasquez | 7a67735 | 2012-02-09 11:15:56 -0800 | [diff] [blame] | 3328 | if (!ha->swl) |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 3329 | ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t), |
Andrew Vasquez | 7a67735 | 2012-02-09 11:15:56 -0800 | [diff] [blame] | 3330 | GFP_KERNEL); |
| 3331 | swl = ha->swl; |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 3332 | if (!swl) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3333 | /*EMPTY*/ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3334 | ql_dbg(ql_dbg_disc, vha, 0x2054, |
| 3335 | "GID_PT allocations failed, fallback on GA_NXT.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3336 | } else { |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 3337 | memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3338 | if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3339 | swl = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3340 | } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3341 | swl = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3342 | } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3343 | swl = NULL; |
Andrew Vasquez | e5896bd | 2008-07-10 16:55:52 -0700 | [diff] [blame] | 3344 | } else if (ql2xiidmaenable && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3345 | qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) { |
| 3346 | qla2x00_gpsc(vha, swl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3347 | } |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3348 | |
| 3349 | /* If other queries succeeded probe for FC-4 type */ |
| 3350 | if (swl) |
| 3351 | qla2x00_gff_id(vha, swl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3352 | } |
| 3353 | swl_idx = 0; |
| 3354 | |
| 3355 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3356 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3357 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3358 | ql_log(ql_log_warn, vha, 0x205e, |
| 3359 | "Failed to allocate memory for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3360 | return (QLA_MEMORY_ALLOC_FAILED); |
| 3361 | } |
| 3362 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3363 | /* Set start port ID scan at adapter ID. */ |
| 3364 | first_dev = 1; |
| 3365 | last_dev = 0; |
| 3366 | |
| 3367 | /* Starting free loop ID. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3368 | loop_id = ha->min_external_loopid; |
| 3369 | for (; loop_id <= ha->max_loop_id; loop_id++) { |
| 3370 | if (qla2x00_is_reserved_id(vha, loop_id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3371 | continue; |
| 3372 | |
Giridhar Malavali | 3a6478d | 2010-05-28 15:08:20 -0700 | [diff] [blame] | 3373 | if (ha->current_topology == ISP_CFG_FL && |
| 3374 | (atomic_read(&vha->loop_down_timer) || |
| 3375 | LOOP_TRANSITION(vha))) { |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 3376 | atomic_set(&vha->loop_down_timer, 0); |
| 3377 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 3378 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | break; |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 3380 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3381 | |
| 3382 | if (swl != NULL) { |
| 3383 | if (last_dev) { |
| 3384 | wrap.b24 = new_fcport->d_id.b24; |
| 3385 | } else { |
| 3386 | new_fcport->d_id.b24 = swl[swl_idx].d_id.b24; |
| 3387 | memcpy(new_fcport->node_name, |
| 3388 | swl[swl_idx].node_name, WWN_SIZE); |
| 3389 | memcpy(new_fcport->port_name, |
| 3390 | swl[swl_idx].port_name, WWN_SIZE); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3391 | memcpy(new_fcport->fabric_port_name, |
| 3392 | swl[swl_idx].fabric_port_name, WWN_SIZE); |
| 3393 | new_fcport->fp_speed = swl[swl_idx].fp_speed; |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3394 | new_fcport->fc4_type = swl[swl_idx].fc4_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3395 | |
| 3396 | if (swl[swl_idx].d_id.b.rsvd_1 != 0) { |
| 3397 | last_dev = 1; |
| 3398 | } |
| 3399 | swl_idx++; |
| 3400 | } |
| 3401 | } else { |
| 3402 | /* Send GA_NXT to the switch */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3403 | rval = qla2x00_ga_nxt(vha, new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3404 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3405 | ql_log(ql_log_warn, vha, 0x2064, |
| 3406 | "SNS scan failed -- assuming " |
| 3407 | "zero-entry result.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3408 | list_for_each_entry_safe(fcport, fcptemp, |
| 3409 | new_fcports, list) { |
| 3410 | list_del(&fcport->list); |
| 3411 | kfree(fcport); |
| 3412 | } |
| 3413 | rval = QLA_SUCCESS; |
| 3414 | break; |
| 3415 | } |
| 3416 | } |
| 3417 | |
| 3418 | /* If wrap on switch device list, exit. */ |
| 3419 | if (first_dev) { |
| 3420 | wrap.b24 = new_fcport->d_id.b24; |
| 3421 | first_dev = 0; |
| 3422 | } else if (new_fcport->d_id.b24 == wrap.b24) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3423 | ql_dbg(ql_dbg_disc, vha, 0x2065, |
| 3424 | "Device wrap (%02x%02x%02x).\n", |
| 3425 | new_fcport->d_id.b.domain, |
| 3426 | new_fcport->d_id.b.area, |
| 3427 | new_fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3428 | break; |
| 3429 | } |
| 3430 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3431 | /* Bypass if same physical adapter. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3432 | if (new_fcport->d_id.b24 == base_vha->d_id.b24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3433 | continue; |
| 3434 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3435 | /* Bypass virtual ports of the same host. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3436 | found = 0; |
| 3437 | if (ha->num_vhosts) { |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3438 | unsigned long flags; |
| 3439 | |
| 3440 | spin_lock_irqsave(&ha->vport_slock, flags); |
Anirban Chakraborty | ee546b6 | 2009-03-05 11:07:02 -0800 | [diff] [blame] | 3441 | list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3442 | if (new_fcport->d_id.b24 == vp->d_id.b24) { |
| 3443 | found = 1; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3444 | break; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3445 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3446 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3447 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 3448 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3449 | if (found) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3450 | continue; |
| 3451 | } |
| 3452 | |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 3453 | /* Bypass if same domain and area of adapter. */ |
| 3454 | if (((new_fcport->d_id.b24 & 0xffff00) == |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3455 | (vha->d_id.b24 & 0xffff00)) && ha->current_topology == |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 3456 | ISP_CFG_FL) |
| 3457 | continue; |
| 3458 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3459 | /* Bypass reserved domain fields. */ |
| 3460 | if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0) |
| 3461 | continue; |
| 3462 | |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3463 | /* Bypass ports whose FCP-4 type is not FCP_SCSI */ |
Chad Dupuis | 4da26e1 | 2010-10-15 11:27:40 -0700 | [diff] [blame] | 3464 | if (ql2xgffidenable && |
| 3465 | (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI && |
| 3466 | new_fcport->fc4_type != FC4_TYPE_UNKNOWN)) |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3467 | continue; |
| 3468 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3469 | /* Locate matching device in database. */ |
| 3470 | found = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3471 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3472 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 3473 | WWN_SIZE)) |
| 3474 | continue; |
| 3475 | |
Joe Carnuccio | c0822b6 | 2012-05-15 14:34:21 -0400 | [diff] [blame] | 3476 | fcport->scan_state = QLA_FCPORT_SCAN_FOUND; |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 3477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | found++; |
| 3479 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3480 | /* Update port state. */ |
| 3481 | memcpy(fcport->fabric_port_name, |
| 3482 | new_fcport->fabric_port_name, WWN_SIZE); |
| 3483 | fcport->fp_speed = new_fcport->fp_speed; |
| 3484 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3485 | /* |
| 3486 | * If address the same and state FCS_ONLINE, nothing |
| 3487 | * changed. |
| 3488 | */ |
| 3489 | if (fcport->d_id.b24 == new_fcport->d_id.b24 && |
| 3490 | atomic_read(&fcport->state) == FCS_ONLINE) { |
| 3491 | break; |
| 3492 | } |
| 3493 | |
| 3494 | /* |
| 3495 | * If device was not a fabric device before. |
| 3496 | */ |
| 3497 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 3498 | fcport->d_id.b24 = new_fcport->d_id.b24; |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3499 | qla2x00_clear_loop_id(fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3500 | fcport->flags |= (FCF_FABRIC_DEVICE | |
| 3501 | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3502 | break; |
| 3503 | } |
| 3504 | |
| 3505 | /* |
| 3506 | * Port ID changed or device was marked to be updated; |
| 3507 | * Log it out if still logged in and mark it for |
| 3508 | * relogin later. |
| 3509 | */ |
| 3510 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 3511 | fcport->flags |= FCF_LOGIN_NEEDED; |
| 3512 | if (fcport->loop_id != FC_NO_LOOP_ID && |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3513 | (fcport->flags & FCF_FCP2_DEVICE) == 0 && |
Arun Easi | 0eba25d | 2012-02-09 11:15:58 -0800 | [diff] [blame] | 3514 | (fcport->flags & FCF_ASYNC_SENT) == 0 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3515 | fcport->port_type != FCT_INITIATOR && |
| 3516 | fcport->port_type != FCT_BROADCAST) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3517 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3518 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3519 | fcport->d_id.b.al_pa); |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3520 | qla2x00_clear_loop_id(fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3521 | } |
| 3522 | |
| 3523 | break; |
| 3524 | } |
| 3525 | |
| 3526 | if (found) |
| 3527 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3528 | /* If device was not in our fcports list, then add it. */ |
| 3529 | list_add_tail(&new_fcport->list, new_fcports); |
| 3530 | |
| 3531 | /* Allocate a new replacement fcport. */ |
| 3532 | nxt_d_id.b24 = new_fcport->d_id.b24; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3533 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3534 | if (new_fcport == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3535 | ql_log(ql_log_warn, vha, 0x2066, |
| 3536 | "Memory allocation failed for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3537 | return (QLA_MEMORY_ALLOC_FAILED); |
| 3538 | } |
| 3539 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
| 3540 | new_fcport->d_id.b24 = nxt_d_id.b24; |
| 3541 | } |
| 3542 | |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 3543 | kfree(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3544 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3545 | return (rval); |
| 3546 | } |
| 3547 | |
| 3548 | /* |
| 3549 | * qla2x00_find_new_loop_id |
| 3550 | * Scan through our port list and find a new usable loop ID. |
| 3551 | * |
| 3552 | * Input: |
| 3553 | * ha: adapter state pointer. |
| 3554 | * dev: port structure pointer. |
| 3555 | * |
| 3556 | * Returns: |
| 3557 | * qla2x00 local function return status code. |
| 3558 | * |
| 3559 | * Context: |
| 3560 | * Kernel context. |
| 3561 | */ |
Joe Carnuccio | 03bcfb5 | 2011-03-30 11:46:27 -0700 | [diff] [blame] | 3562 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3563 | 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] | 3564 | { |
| 3565 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3566 | struct qla_hw_data *ha = vha->hw; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3567 | unsigned long flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3568 | |
| 3569 | rval = QLA_SUCCESS; |
| 3570 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3571 | spin_lock_irqsave(&ha->vport_slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3572 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3573 | dev->loop_id = find_first_zero_bit(ha->loop_id_map, |
| 3574 | LOOPID_MAP_SIZE); |
| 3575 | if (dev->loop_id >= LOOPID_MAP_SIZE || |
| 3576 | qla2x00_is_reserved_id(vha, dev->loop_id)) { |
| 3577 | dev->loop_id = FC_NO_LOOP_ID; |
| 3578 | rval = QLA_FUNCTION_FAILED; |
| 3579 | } else |
| 3580 | set_bit(dev->loop_id, ha->loop_id_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3581 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3582 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3583 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3584 | if (rval == QLA_SUCCESS) |
| 3585 | ql_dbg(ql_dbg_disc, dev->vha, 0x2086, |
| 3586 | "Assigning new loopid=%x, portid=%x.\n", |
| 3587 | dev->loop_id, dev->d_id.b24); |
| 3588 | else |
| 3589 | ql_log(ql_log_warn, dev->vha, 0x2087, |
| 3590 | "No loop_id's available, portid=%x.\n", |
| 3591 | dev->d_id.b24); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3592 | |
| 3593 | return (rval); |
| 3594 | } |
| 3595 | |
| 3596 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3597 | * qla2x00_fabric_dev_login |
| 3598 | * Login fabric target device and update FC port database. |
| 3599 | * |
| 3600 | * Input: |
| 3601 | * ha: adapter state pointer. |
| 3602 | * fcport: port structure list pointer. |
| 3603 | * next_loopid: contains value of a new loop ID that can be used |
| 3604 | * by the next login attempt. |
| 3605 | * |
| 3606 | * Returns: |
| 3607 | * qla2x00 local function return status code. |
| 3608 | * |
| 3609 | * Context: |
| 3610 | * Kernel context. |
| 3611 | */ |
| 3612 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3613 | 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] | 3614 | uint16_t *next_loopid) |
| 3615 | { |
| 3616 | int rval; |
| 3617 | int retry; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3618 | uint8_t opts; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3619 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3620 | |
| 3621 | rval = QLA_SUCCESS; |
| 3622 | retry = 0; |
| 3623 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3624 | if (IS_ALOGIO_CAPABLE(ha)) { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 3625 | if (fcport->flags & FCF_ASYNC_SENT) |
| 3626 | return rval; |
| 3627 | fcport->flags |= FCF_ASYNC_SENT; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3628 | rval = qla2x00_post_async_login_work(vha, fcport, NULL); |
| 3629 | if (!rval) |
| 3630 | return rval; |
| 3631 | } |
| 3632 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 3633 | fcport->flags &= ~FCF_ASYNC_SENT; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3634 | rval = qla2x00_fabric_login(vha, fcport, next_loopid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3635 | if (rval == QLA_SUCCESS) { |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3636 | /* Send an ADISC to FCP2 devices.*/ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3637 | opts = 0; |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3638 | if (fcport->flags & FCF_FCP2_DEVICE) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3639 | opts |= BIT_1; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3640 | rval = qla2x00_get_port_database(vha, fcport, opts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3641 | if (rval != QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3642 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3643 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3644 | fcport->d_id.b.al_pa); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3645 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3646 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3647 | qla2x00_update_fcport(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3648 | } |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 3649 | } else { |
| 3650 | /* Retry Login. */ |
| 3651 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3652 | } |
| 3653 | |
| 3654 | return (rval); |
| 3655 | } |
| 3656 | |
| 3657 | /* |
| 3658 | * qla2x00_fabric_login |
| 3659 | * Issue fabric login command. |
| 3660 | * |
| 3661 | * Input: |
| 3662 | * ha = adapter block pointer. |
| 3663 | * device = pointer to FC device type structure. |
| 3664 | * |
| 3665 | * Returns: |
| 3666 | * 0 - Login successfully |
| 3667 | * 1 - Login failed |
| 3668 | * 2 - Initiator device |
| 3669 | * 3 - Fatal error |
| 3670 | */ |
| 3671 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3672 | qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3673 | uint16_t *next_loopid) |
| 3674 | { |
| 3675 | int rval; |
| 3676 | int retry; |
| 3677 | uint16_t tmp_loopid; |
| 3678 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3679 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3680 | |
| 3681 | retry = 0; |
| 3682 | tmp_loopid = 0; |
| 3683 | |
| 3684 | for (;;) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3685 | ql_dbg(ql_dbg_disc, vha, 0x2000, |
| 3686 | "Trying Fabric Login w/loop id 0x%04x for port " |
| 3687 | "%02x%02x%02x.\n", |
| 3688 | fcport->loop_id, fcport->d_id.b.domain, |
| 3689 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3690 | |
| 3691 | /* Login fcport on switch. */ |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 3692 | rval = ha->isp_ops->fabric_login(vha, fcport->loop_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3693 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3694 | fcport->d_id.b.al_pa, mb, BIT_0); |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 3695 | if (rval != QLA_SUCCESS) { |
| 3696 | return rval; |
| 3697 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3698 | if (mb[0] == MBS_PORT_ID_USED) { |
| 3699 | /* |
| 3700 | * Device has another loop ID. The firmware team |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3701 | * recommends the driver perform an implicit login with |
| 3702 | * the specified ID again. The ID we just used is save |
| 3703 | * here so we return with an ID that can be tried by |
| 3704 | * the next login. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3705 | */ |
| 3706 | retry++; |
| 3707 | tmp_loopid = fcport->loop_id; |
| 3708 | fcport->loop_id = mb[1]; |
| 3709 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3710 | ql_dbg(ql_dbg_disc, vha, 0x2001, |
| 3711 | "Fabric Login: port in use - next loop " |
| 3712 | "id=0x%04x, port id= %02x%02x%02x.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3713 | fcport->loop_id, fcport->d_id.b.domain, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3714 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3715 | |
| 3716 | } else if (mb[0] == MBS_COMMAND_COMPLETE) { |
| 3717 | /* |
| 3718 | * Login succeeded. |
| 3719 | */ |
| 3720 | if (retry) { |
| 3721 | /* A retry occurred before. */ |
| 3722 | *next_loopid = tmp_loopid; |
| 3723 | } else { |
| 3724 | /* |
| 3725 | * No retry occurred before. Just increment the |
| 3726 | * ID value for next login. |
| 3727 | */ |
| 3728 | *next_loopid = (fcport->loop_id + 1); |
| 3729 | } |
| 3730 | |
| 3731 | if (mb[1] & BIT_0) { |
| 3732 | fcport->port_type = FCT_INITIATOR; |
| 3733 | } else { |
| 3734 | fcport->port_type = FCT_TARGET; |
| 3735 | if (mb[1] & BIT_1) { |
Santosh Vernekar | 8474f3a | 2009-08-25 11:36:16 -0700 | [diff] [blame] | 3736 | fcport->flags |= FCF_FCP2_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3737 | } |
| 3738 | } |
| 3739 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 3740 | if (mb[10] & BIT_0) |
| 3741 | fcport->supported_classes |= FC_COS_CLASS2; |
| 3742 | if (mb[10] & BIT_1) |
| 3743 | fcport->supported_classes |= FC_COS_CLASS3; |
| 3744 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3745 | if (IS_FWI2_CAPABLE(ha)) { |
| 3746 | if (mb[10] & BIT_7) |
| 3747 | fcport->flags |= |
| 3748 | FCF_CONF_COMP_SUPPORTED; |
| 3749 | } |
| 3750 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3751 | rval = QLA_SUCCESS; |
| 3752 | break; |
| 3753 | } else if (mb[0] == MBS_LOOP_ID_USED) { |
| 3754 | /* |
| 3755 | * Loop ID already used, try next loop ID. |
| 3756 | */ |
| 3757 | fcport->loop_id++; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3758 | rval = qla2x00_find_new_loop_id(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3759 | if (rval != QLA_SUCCESS) { |
| 3760 | /* Ran out of loop IDs to use */ |
| 3761 | break; |
| 3762 | } |
| 3763 | } else if (mb[0] == MBS_COMMAND_ERROR) { |
| 3764 | /* |
| 3765 | * Firmware possibly timed out during login. If NO |
| 3766 | * retries are left to do then the device is declared |
| 3767 | * dead. |
| 3768 | */ |
| 3769 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3770 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3771 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3772 | fcport->d_id.b.al_pa); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3773 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3774 | |
| 3775 | rval = 1; |
| 3776 | break; |
| 3777 | } else { |
| 3778 | /* |
| 3779 | * unrecoverable / not handled error |
| 3780 | */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3781 | ql_dbg(ql_dbg_disc, vha, 0x2002, |
| 3782 | "Failed=%x port_id=%02x%02x%02x loop_id=%x " |
| 3783 | "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain, |
| 3784 | fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 3785 | fcport->loop_id, jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3786 | |
| 3787 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3788 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3789 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3790 | fcport->d_id.b.al_pa); |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 3791 | qla2x00_clear_loop_id(fcport); |
Andrew Vasquez | 0eedfcf | 2005-10-27 11:09:38 -0700 | [diff] [blame] | 3792 | fcport->login_retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3793 | |
| 3794 | rval = 3; |
| 3795 | break; |
| 3796 | } |
| 3797 | } |
| 3798 | |
| 3799 | return (rval); |
| 3800 | } |
| 3801 | |
| 3802 | /* |
| 3803 | * qla2x00_local_device_login |
| 3804 | * Issue local device login command. |
| 3805 | * |
| 3806 | * Input: |
| 3807 | * ha = adapter block pointer. |
| 3808 | * loop_id = loop id of device to login to. |
| 3809 | * |
| 3810 | * Returns (Where's the #define!!!!): |
| 3811 | * 0 - Login successfully |
| 3812 | * 1 - Login failed |
| 3813 | * 3 - Fatal error |
| 3814 | */ |
| 3815 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3816 | 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] | 3817 | { |
| 3818 | int rval; |
| 3819 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
| 3820 | |
| 3821 | memset(mb, 0, sizeof(mb)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3822 | rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3823 | if (rval == QLA_SUCCESS) { |
| 3824 | /* Interrogate mailbox registers for any errors */ |
| 3825 | if (mb[0] == MBS_COMMAND_ERROR) |
| 3826 | rval = 1; |
| 3827 | else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR) |
| 3828 | /* device not in PCB table */ |
| 3829 | rval = 3; |
| 3830 | } |
| 3831 | |
| 3832 | return (rval); |
| 3833 | } |
| 3834 | |
| 3835 | /* |
| 3836 | * qla2x00_loop_resync |
| 3837 | * Resync with fibre channel devices. |
| 3838 | * |
| 3839 | * Input: |
| 3840 | * ha = adapter block pointer. |
| 3841 | * |
| 3842 | * Returns: |
| 3843 | * 0 = success |
| 3844 | */ |
| 3845 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3846 | qla2x00_loop_resync(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3847 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3848 | int rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3849 | uint32_t wait_time; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 3850 | struct req_que *req; |
| 3851 | struct rsp_que *rsp; |
| 3852 | |
Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 3853 | if (vha->hw->flags.cpu_affinity_enabled) |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 3854 | req = vha->hw->req_q_map[0]; |
| 3855 | else |
| 3856 | req = vha->req; |
| 3857 | rsp = req->rsp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3858 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3859 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 3860 | if (vha->flags.online) { |
| 3861 | if (!(rval = qla2x00_fw_ready(vha))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3862 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 3863 | wait_time = 256; |
| 3864 | do { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3865 | /* Issue a marker after FW becomes ready. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3866 | qla2x00_marker(vha, req, rsp, 0, 0, |
| 3867 | MK_SYNC_ALL); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3868 | vha->marker_needed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3869 | |
| 3870 | /* Remap devices on Loop. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3871 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3872 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3873 | qla2x00_configure_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3874 | wait_time--; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3875 | } while (!atomic_read(&vha->loop_down_timer) && |
| 3876 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
| 3877 | && wait_time && (test_bit(LOOP_RESYNC_NEEDED, |
| 3878 | &vha->dpc_flags))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3879 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3880 | } |
| 3881 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3882 | if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3883 | return (QLA_FUNCTION_FAILED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3884 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3885 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3886 | ql_dbg(ql_dbg_disc, vha, 0x206c, |
| 3887 | "%s *** FAILED ***.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3888 | |
| 3889 | return (rval); |
| 3890 | } |
| 3891 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 3892 | /* |
| 3893 | * qla2x00_perform_loop_resync |
| 3894 | * Description: This function will set the appropriate flags and call |
| 3895 | * qla2x00_loop_resync. If successful loop will be resynced |
| 3896 | * Arguments : scsi_qla_host_t pointer |
| 3897 | * returm : Success or Failure |
| 3898 | */ |
| 3899 | |
| 3900 | int qla2x00_perform_loop_resync(scsi_qla_host_t *ha) |
| 3901 | { |
| 3902 | int32_t rval = 0; |
| 3903 | |
| 3904 | if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) { |
| 3905 | /*Configure the flags so that resync happens properly*/ |
| 3906 | atomic_set(&ha->loop_down_timer, 0); |
| 3907 | if (!(ha->device_flags & DFLG_NO_CABLE)) { |
| 3908 | atomic_set(&ha->loop_state, LOOP_UP); |
| 3909 | set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); |
| 3910 | set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags); |
| 3911 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
| 3912 | |
| 3913 | rval = qla2x00_loop_resync(ha); |
| 3914 | } else |
| 3915 | atomic_set(&ha->loop_state, LOOP_DEAD); |
| 3916 | |
| 3917 | clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags); |
| 3918 | } |
| 3919 | |
| 3920 | return rval; |
| 3921 | } |
| 3922 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3923 | void |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 3924 | qla2x00_update_fcports(scsi_qla_host_t *base_vha) |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3925 | { |
| 3926 | fc_port_t *fcport; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3927 | struct scsi_qla_host *vha; |
| 3928 | struct qla_hw_data *ha = base_vha->hw; |
| 3929 | unsigned long flags; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3930 | |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3931 | spin_lock_irqsave(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3932 | /* Go with deferred removal of rport references. */ |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3933 | list_for_each_entry(vha, &base_vha->hw->vp_list, list) { |
| 3934 | atomic_inc(&vha->vref_count); |
| 3935 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Dan Carpenter | 8ae598d | 2010-12-21 16:00:15 -0800 | [diff] [blame] | 3936 | if (fcport->drport && |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3937 | atomic_read(&fcport->state) != FCS_UNCONFIGURED) { |
| 3938 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 3939 | |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 3940 | qla2x00_rport_del(fcport); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3941 | |
| 3942 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 3943 | } |
| 3944 | } |
| 3945 | atomic_dec(&vha->vref_count); |
| 3946 | } |
| 3947 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3948 | } |
| 3949 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 3950 | /* Assumes idc_lock always held on entry */ |
| 3951 | void |
| 3952 | qla83xx_reset_ownership(scsi_qla_host_t *vha) |
| 3953 | { |
| 3954 | struct qla_hw_data *ha = vha->hw; |
| 3955 | uint32_t drv_presence, drv_presence_mask; |
| 3956 | uint32_t dev_part_info1, dev_part_info2, class_type; |
| 3957 | uint32_t class_type_mask = 0x3; |
| 3958 | uint16_t fcoe_other_function = 0xffff, i; |
| 3959 | |
| 3960 | qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); |
| 3961 | |
| 3962 | qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1); |
| 3963 | qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2); |
| 3964 | for (i = 0; i < 8; i++) { |
| 3965 | class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask); |
| 3966 | if ((class_type == QLA83XX_CLASS_TYPE_FCOE) && |
| 3967 | (i != ha->portnum)) { |
| 3968 | fcoe_other_function = i; |
| 3969 | break; |
| 3970 | } |
| 3971 | } |
| 3972 | if (fcoe_other_function == 0xffff) { |
| 3973 | for (i = 0; i < 8; i++) { |
| 3974 | class_type = ((dev_part_info2 >> (i * 4)) & |
| 3975 | class_type_mask); |
| 3976 | if ((class_type == QLA83XX_CLASS_TYPE_FCOE) && |
| 3977 | ((i + 8) != ha->portnum)) { |
| 3978 | fcoe_other_function = i + 8; |
| 3979 | break; |
| 3980 | } |
| 3981 | } |
| 3982 | } |
| 3983 | /* |
| 3984 | * Prepare drv-presence mask based on fcoe functions present. |
| 3985 | * However consider only valid physical fcoe function numbers (0-15). |
| 3986 | */ |
| 3987 | drv_presence_mask = ~((1 << (ha->portnum)) | |
| 3988 | ((fcoe_other_function == 0xffff) ? |
| 3989 | 0 : (1 << (fcoe_other_function)))); |
| 3990 | |
| 3991 | /* We are the reset owner iff: |
| 3992 | * - No other protocol drivers present. |
| 3993 | * - This is the lowest among fcoe functions. */ |
| 3994 | if (!(drv_presence & drv_presence_mask) && |
| 3995 | (ha->portnum < fcoe_other_function)) { |
| 3996 | ql_dbg(ql_dbg_p3p, vha, 0xb07f, |
| 3997 | "This host is Reset owner.\n"); |
| 3998 | ha->flags.nic_core_reset_owner = 1; |
| 3999 | } |
| 4000 | } |
| 4001 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 4002 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 4003 | __qla83xx_set_drv_ack(scsi_qla_host_t *vha) |
| 4004 | { |
| 4005 | int rval = QLA_SUCCESS; |
| 4006 | struct qla_hw_data *ha = vha->hw; |
| 4007 | uint32_t drv_ack; |
| 4008 | |
| 4009 | rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack); |
| 4010 | if (rval == QLA_SUCCESS) { |
| 4011 | drv_ack |= (1 << ha->portnum); |
| 4012 | rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack); |
| 4013 | } |
| 4014 | |
| 4015 | return rval; |
| 4016 | } |
| 4017 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 4018 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 4019 | __qla83xx_clear_drv_ack(scsi_qla_host_t *vha) |
| 4020 | { |
| 4021 | int rval = QLA_SUCCESS; |
| 4022 | struct qla_hw_data *ha = vha->hw; |
| 4023 | uint32_t drv_ack; |
| 4024 | |
| 4025 | rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack); |
| 4026 | if (rval == QLA_SUCCESS) { |
| 4027 | drv_ack &= ~(1 << ha->portnum); |
| 4028 | rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack); |
| 4029 | } |
| 4030 | |
| 4031 | return rval; |
| 4032 | } |
| 4033 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 4034 | static const char * |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 4035 | qla83xx_dev_state_to_string(uint32_t dev_state) |
| 4036 | { |
| 4037 | switch (dev_state) { |
| 4038 | case QLA8XXX_DEV_COLD: |
| 4039 | return "COLD/RE-INIT"; |
| 4040 | case QLA8XXX_DEV_INITIALIZING: |
| 4041 | return "INITIALIZING"; |
| 4042 | case QLA8XXX_DEV_READY: |
| 4043 | return "READY"; |
| 4044 | case QLA8XXX_DEV_NEED_RESET: |
| 4045 | return "NEED RESET"; |
| 4046 | case QLA8XXX_DEV_NEED_QUIESCENT: |
| 4047 | return "NEED QUIESCENT"; |
| 4048 | case QLA8XXX_DEV_FAILED: |
| 4049 | return "FAILED"; |
| 4050 | case QLA8XXX_DEV_QUIESCENT: |
| 4051 | return "QUIESCENT"; |
| 4052 | default: |
| 4053 | return "Unknown"; |
| 4054 | } |
| 4055 | } |
| 4056 | |
| 4057 | /* Assumes idc-lock always held on entry */ |
| 4058 | void |
| 4059 | qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type) |
| 4060 | { |
| 4061 | struct qla_hw_data *ha = vha->hw; |
| 4062 | uint32_t idc_audit_reg = 0, duration_secs = 0; |
| 4063 | |
| 4064 | switch (audit_type) { |
| 4065 | case IDC_AUDIT_TIMESTAMP: |
| 4066 | ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000); |
| 4067 | idc_audit_reg = (ha->portnum) | |
| 4068 | (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8); |
| 4069 | qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg); |
| 4070 | break; |
| 4071 | |
| 4072 | case IDC_AUDIT_COMPLETION: |
| 4073 | duration_secs = ((jiffies_to_msecs(jiffies) - |
| 4074 | jiffies_to_msecs(ha->idc_audit_ts)) / 1000); |
| 4075 | idc_audit_reg = (ha->portnum) | |
| 4076 | (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8); |
| 4077 | qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg); |
| 4078 | break; |
| 4079 | |
| 4080 | default: |
| 4081 | ql_log(ql_log_warn, vha, 0xb078, |
| 4082 | "Invalid audit type specified.\n"); |
| 4083 | break; |
| 4084 | } |
| 4085 | } |
| 4086 | |
| 4087 | /* Assumes idc_lock always held on entry */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 4088 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 4089 | qla83xx_initiating_reset(scsi_qla_host_t *vha) |
| 4090 | { |
| 4091 | struct qla_hw_data *ha = vha->hw; |
| 4092 | uint32_t idc_control, dev_state; |
| 4093 | |
| 4094 | __qla83xx_get_idc_control(vha, &idc_control); |
| 4095 | if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) { |
| 4096 | ql_log(ql_log_info, vha, 0xb080, |
| 4097 | "NIC Core reset has been disabled. idc-control=0x%x\n", |
| 4098 | idc_control); |
| 4099 | return QLA_FUNCTION_FAILED; |
| 4100 | } |
| 4101 | |
| 4102 | /* Set NEED-RESET iff in READY state and we are the reset-owner */ |
| 4103 | qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state); |
| 4104 | if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) { |
| 4105 | qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, |
| 4106 | QLA8XXX_DEV_NEED_RESET); |
| 4107 | ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n"); |
| 4108 | qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP); |
| 4109 | } else { |
| 4110 | const char *state = qla83xx_dev_state_to_string(dev_state); |
| 4111 | ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state); |
| 4112 | |
| 4113 | /* SV: XXX: Is timeout required here? */ |
| 4114 | /* Wait for IDC state change READY -> NEED_RESET */ |
| 4115 | while (dev_state == QLA8XXX_DEV_READY) { |
| 4116 | qla83xx_idc_unlock(vha, 0); |
| 4117 | msleep(200); |
| 4118 | qla83xx_idc_lock(vha, 0); |
| 4119 | qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state); |
| 4120 | } |
| 4121 | } |
| 4122 | |
| 4123 | /* Send IDC ack by writing to drv-ack register */ |
| 4124 | __qla83xx_set_drv_ack(vha); |
| 4125 | |
| 4126 | return QLA_SUCCESS; |
| 4127 | } |
| 4128 | |
| 4129 | int |
| 4130 | __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control) |
| 4131 | { |
| 4132 | return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control); |
| 4133 | } |
| 4134 | |
| 4135 | int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 4136 | __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control) |
| 4137 | { |
| 4138 | return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control); |
| 4139 | } |
| 4140 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 4141 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 4142 | qla83xx_check_driver_presence(scsi_qla_host_t *vha) |
| 4143 | { |
| 4144 | uint32_t drv_presence = 0; |
| 4145 | struct qla_hw_data *ha = vha->hw; |
| 4146 | |
| 4147 | qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); |
| 4148 | if (drv_presence & (1 << ha->portnum)) |
| 4149 | return QLA_SUCCESS; |
| 4150 | else |
| 4151 | return QLA_TEST_FAILED; |
| 4152 | } |
| 4153 | |
| 4154 | int |
| 4155 | qla83xx_nic_core_reset(scsi_qla_host_t *vha) |
| 4156 | { |
| 4157 | int rval = QLA_SUCCESS; |
| 4158 | struct qla_hw_data *ha = vha->hw; |
| 4159 | |
| 4160 | ql_dbg(ql_dbg_p3p, vha, 0xb058, |
| 4161 | "Entered %s().\n", __func__); |
| 4162 | |
| 4163 | if (vha->device_flags & DFLG_DEV_FAILED) { |
| 4164 | ql_log(ql_log_warn, vha, 0xb059, |
| 4165 | "Device in unrecoverable FAILED state.\n"); |
| 4166 | return QLA_FUNCTION_FAILED; |
| 4167 | } |
| 4168 | |
| 4169 | qla83xx_idc_lock(vha, 0); |
| 4170 | |
| 4171 | if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) { |
| 4172 | ql_log(ql_log_warn, vha, 0xb05a, |
| 4173 | "Function=0x%x has been removed from IDC participation.\n", |
| 4174 | ha->portnum); |
| 4175 | rval = QLA_FUNCTION_FAILED; |
| 4176 | goto exit; |
| 4177 | } |
| 4178 | |
| 4179 | qla83xx_reset_ownership(vha); |
| 4180 | |
| 4181 | rval = qla83xx_initiating_reset(vha); |
| 4182 | |
| 4183 | /* |
| 4184 | * Perform reset if we are the reset-owner, |
| 4185 | * else wait till IDC state changes to READY/FAILED. |
| 4186 | */ |
| 4187 | if (rval == QLA_SUCCESS) { |
| 4188 | rval = qla83xx_idc_state_handler(vha); |
| 4189 | |
| 4190 | if (rval == QLA_SUCCESS) |
| 4191 | ha->flags.nic_core_hung = 0; |
| 4192 | __qla83xx_clear_drv_ack(vha); |
| 4193 | } |
| 4194 | |
| 4195 | exit: |
| 4196 | qla83xx_idc_unlock(vha, 0); |
| 4197 | |
| 4198 | ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__); |
| 4199 | |
| 4200 | return rval; |
| 4201 | } |
| 4202 | |
Saurav Kashyap | 8117877 | 2012-08-22 14:21:04 -0400 | [diff] [blame] | 4203 | int |
| 4204 | qla2xxx_mctp_dump(scsi_qla_host_t *vha) |
| 4205 | { |
| 4206 | struct qla_hw_data *ha = vha->hw; |
| 4207 | int rval = QLA_FUNCTION_FAILED; |
| 4208 | |
| 4209 | if (!IS_MCTP_CAPABLE(ha)) { |
| 4210 | /* This message can be removed from the final version */ |
| 4211 | ql_log(ql_log_info, vha, 0x506d, |
| 4212 | "This board is not MCTP capable\n"); |
| 4213 | return rval; |
| 4214 | } |
| 4215 | |
| 4216 | if (!ha->mctp_dump) { |
| 4217 | ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev, |
| 4218 | MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL); |
| 4219 | |
| 4220 | if (!ha->mctp_dump) { |
| 4221 | ql_log(ql_log_warn, vha, 0x506e, |
| 4222 | "Failed to allocate memory for mctp dump\n"); |
| 4223 | return rval; |
| 4224 | } |
| 4225 | } |
| 4226 | |
| 4227 | #define MCTP_DUMP_STR_ADDR 0x00000000 |
| 4228 | rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma, |
| 4229 | MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4); |
| 4230 | if (rval != QLA_SUCCESS) { |
| 4231 | ql_log(ql_log_warn, vha, 0x506f, |
| 4232 | "Failed to capture mctp dump\n"); |
| 4233 | } else { |
| 4234 | ql_log(ql_log_info, vha, 0x5070, |
| 4235 | "Mctp dump capture for host (%ld/%p).\n", |
| 4236 | vha->host_no, ha->mctp_dump); |
| 4237 | ha->mctp_dumped = 1; |
| 4238 | } |
| 4239 | |
Saurav Kashyap | 409ee0f | 2012-08-22 14:21:29 -0400 | [diff] [blame] | 4240 | if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) { |
Saurav Kashyap | 8117877 | 2012-08-22 14:21:04 -0400 | [diff] [blame] | 4241 | ha->flags.nic_core_reset_hdlr_active = 1; |
| 4242 | rval = qla83xx_restart_nic_firmware(vha); |
| 4243 | if (rval) |
| 4244 | /* NIC Core reset failed. */ |
| 4245 | ql_log(ql_log_warn, vha, 0x5071, |
| 4246 | "Failed to restart nic firmware\n"); |
| 4247 | else |
| 4248 | ql_dbg(ql_dbg_p3p, vha, 0xb084, |
| 4249 | "Restarted NIC firmware successfully.\n"); |
| 4250 | ha->flags.nic_core_reset_hdlr_active = 0; |
| 4251 | } |
| 4252 | |
| 4253 | return rval; |
| 4254 | |
| 4255 | } |
| 4256 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4257 | /* |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 4258 | * qla2x00_quiesce_io |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4259 | * Description: This function will block the new I/Os |
| 4260 | * Its not aborting any I/Os as context |
| 4261 | * is not destroyed during quiescence |
| 4262 | * Arguments: scsi_qla_host_t |
| 4263 | * return : void |
| 4264 | */ |
| 4265 | void |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 4266 | qla2x00_quiesce_io(scsi_qla_host_t *vha) |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4267 | { |
| 4268 | struct qla_hw_data *ha = vha->hw; |
| 4269 | struct scsi_qla_host *vp; |
| 4270 | |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 4271 | ql_dbg(ql_dbg_dpc, vha, 0x401d, |
| 4272 | "Quiescing I/O - ha=%p.\n", ha); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4273 | |
| 4274 | atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); |
| 4275 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 4276 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 4277 | qla2x00_mark_all_devices_lost(vha, 0); |
| 4278 | list_for_each_entry(vp, &ha->vp_list, list) |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 4279 | qla2x00_mark_all_devices_lost(vp, 0); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4280 | } else { |
| 4281 | if (!atomic_read(&vha->loop_down_timer)) |
| 4282 | atomic_set(&vha->loop_down_timer, |
| 4283 | LOOP_DOWN_TIME); |
| 4284 | } |
| 4285 | /* Wait for pending cmds to complete */ |
| 4286 | qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST); |
| 4287 | } |
| 4288 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4289 | void |
| 4290 | qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha) |
| 4291 | { |
| 4292 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4293 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4294 | unsigned long flags; |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 4295 | fc_port_t *fcport; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4296 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 4297 | /* For ISP82XX, driver waits for completion of the commands. |
| 4298 | * online flag should be set. |
| 4299 | */ |
| 4300 | if (!IS_QLA82XX(ha)) |
| 4301 | vha->flags.online = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4302 | ha->flags.chip_reset_done = 0; |
| 4303 | clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Saurav Kashyap | 2be21fa | 2012-05-15 14:34:16 -0400 | [diff] [blame] | 4304 | vha->qla_stats.total_isp_aborts++; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4305 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4306 | ql_log(ql_log_info, vha, 0x00af, |
| 4307 | "Performing ISP error recovery - ha=%p.\n", ha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4308 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 4309 | /* For ISP82XX, reset_chip is just disabling interrupts. |
| 4310 | * Driver waits for the completion of the commands. |
| 4311 | * the interrupts need to be enabled. |
| 4312 | */ |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4313 | if (!IS_QLA82XX(ha)) |
| 4314 | ha->isp_ops->reset_chip(vha); |
| 4315 | |
| 4316 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 4317 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 4318 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 4319 | qla2x00_mark_all_devices_lost(vha, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4320 | |
| 4321 | spin_lock_irqsave(&ha->vport_slock, flags); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 4322 | list_for_each_entry(vp, &ha->vp_list, list) { |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4323 | atomic_inc(&vp->vref_count); |
| 4324 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4325 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4326 | qla2x00_mark_all_devices_lost(vp, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4327 | |
| 4328 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4329 | atomic_dec(&vp->vref_count); |
| 4330 | } |
| 4331 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4332 | } else { |
| 4333 | if (!atomic_read(&vha->loop_down_timer)) |
| 4334 | atomic_set(&vha->loop_down_timer, |
| 4335 | LOOP_DOWN_TIME); |
| 4336 | } |
| 4337 | |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 4338 | /* Clear all async request states across all VPs. */ |
| 4339 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 4340 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 4341 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4342 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 4343 | atomic_inc(&vp->vref_count); |
| 4344 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4345 | |
| 4346 | list_for_each_entry(fcport, &vp->vp_fcports, list) |
| 4347 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 4348 | |
| 4349 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4350 | atomic_dec(&vp->vref_count); |
| 4351 | } |
| 4352 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4353 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 4354 | if (!ha->flags.eeh_busy) { |
| 4355 | /* Make sure for ISP 82XX IO DMA is complete */ |
| 4356 | if (IS_QLA82XX(ha)) { |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 4357 | qla82xx_chip_reset_cleanup(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4358 | ql_log(ql_log_info, vha, 0x00b4, |
| 4359 | "Done chip reset cleanup.\n"); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4360 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 4361 | /* Done waiting for pending commands. |
| 4362 | * Reset the online flag. |
| 4363 | */ |
| 4364 | vha->flags.online = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4365 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4366 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 4367 | /* Requeue all commands in outstanding command list. */ |
| 4368 | qla2x00_abort_all_cmds(vha, DID_RESET << 16); |
| 4369 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4370 | } |
| 4371 | |
| 4372 | /* |
| 4373 | * qla2x00_abort_isp |
| 4374 | * Resets ISP and aborts all outstanding commands. |
| 4375 | * |
| 4376 | * Input: |
| 4377 | * ha = adapter block pointer. |
| 4378 | * |
| 4379 | * Returns: |
| 4380 | * 0 = success |
| 4381 | */ |
| 4382 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4383 | qla2x00_abort_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4384 | { |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 4385 | int rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4386 | uint8_t status = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4387 | struct qla_hw_data *ha = vha->hw; |
| 4388 | struct scsi_qla_host *vp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4389 | struct req_que *req = ha->req_q_map[0]; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4390 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4391 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4392 | if (vha->flags.online) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4393 | qla2x00_abort_isp_cleanup(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4394 | |
Santosh Vernekar | a6171297 | 2012-08-22 14:21:13 -0400 | [diff] [blame] | 4395 | if (IS_QLA8031(ha)) { |
| 4396 | ql_dbg(ql_dbg_p3p, vha, 0xb05c, |
| 4397 | "Clearing fcoe driver presence.\n"); |
| 4398 | if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS) |
| 4399 | ql_dbg(ql_dbg_p3p, vha, 0xb073, |
| 4400 | "Error while clearing DRV-Presence.\n"); |
| 4401 | } |
| 4402 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 4403 | if (unlikely(pci_channel_offline(ha->pdev) && |
| 4404 | ha->flags.pci_channel_io_perm_failure)) { |
| 4405 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 4406 | status = 0; |
| 4407 | return status; |
| 4408 | } |
| 4409 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4410 | ha->isp_ops->get_flash_version(vha, req->ring); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 4411 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4412 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4413 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4414 | if (!qla2x00_restart_isp(vha)) { |
| 4415 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4416 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4417 | if (!atomic_read(&vha->loop_down_timer)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4418 | /* |
| 4419 | * Issue marker command only when we are going |
| 4420 | * to start the I/O . |
| 4421 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4422 | vha->marker_needed = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4423 | } |
| 4424 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4425 | vha->flags.online = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4426 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 4427 | ha->isp_ops->enable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4429 | ha->isp_abort_cnt = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4430 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 4431 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 4432 | if (IS_QLA81XX(ha) || IS_QLA8031(ha)) |
| 4433 | qla2x00_get_fw_version(vha); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 4434 | if (ha->fce) { |
| 4435 | ha->flags.fce_enabled = 1; |
| 4436 | memset(ha->fce, 0, |
| 4437 | fce_calc_size(ha->fce_bufs)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4438 | rval = qla2x00_enable_fce_trace(vha, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 4439 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 4440 | &ha->fce_bufs); |
| 4441 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4442 | ql_log(ql_log_warn, vha, 0x8033, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 4443 | "Unable to reinitialize FCE " |
| 4444 | "(%d).\n", rval); |
| 4445 | ha->flags.fce_enabled = 0; |
| 4446 | } |
| 4447 | } |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 4448 | |
| 4449 | if (ha->eft) { |
| 4450 | memset(ha->eft, 0, EFT_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4451 | rval = qla2x00_enable_eft_trace(vha, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 4452 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 4453 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4454 | ql_log(ql_log_warn, vha, 0x8034, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 4455 | "Unable to reinitialize EFT " |
| 4456 | "(%d).\n", rval); |
| 4457 | } |
| 4458 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4459 | } else { /* failed the ISP abort */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4460 | vha->flags.online = 1; |
| 4461 | if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4462 | if (ha->isp_abort_cnt == 0) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4463 | ql_log(ql_log_fatal, vha, 0x8035, |
| 4464 | "ISP error recover failed - " |
| 4465 | "board disabled.\n"); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4466 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4467 | * The next call disables the board |
| 4468 | * completely. |
| 4469 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4470 | ha->isp_ops->reset_adapter(vha); |
| 4471 | vha->flags.online = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4472 | clear_bit(ISP_ABORT_RETRY, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4473 | &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4474 | status = 0; |
| 4475 | } else { /* schedule another ISP abort */ |
| 4476 | ha->isp_abort_cnt--; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4477 | ql_dbg(ql_dbg_taskm, vha, 0x8020, |
| 4478 | "ISP abort - retry remaining %d.\n", |
| 4479 | ha->isp_abort_cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4480 | status = 1; |
| 4481 | } |
| 4482 | } else { |
| 4483 | ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4484 | ql_dbg(ql_dbg_taskm, vha, 0x8021, |
| 4485 | "ISP error recovery - retrying (%d) " |
| 4486 | "more times.\n", ha->isp_abort_cnt); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4487 | set_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4488 | status = 1; |
| 4489 | } |
| 4490 | } |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4491 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4492 | } |
| 4493 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4494 | if (!status) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4495 | ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4496 | |
| 4497 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4498 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 4499 | if (vp->vp_idx) { |
| 4500 | atomic_inc(&vp->vref_count); |
| 4501 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4502 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4503 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4504 | |
| 4505 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4506 | atomic_dec(&vp->vref_count); |
| 4507 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4508 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4509 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4510 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 4511 | if (IS_QLA8031(ha)) { |
| 4512 | ql_dbg(ql_dbg_p3p, vha, 0xb05d, |
| 4513 | "Setting back fcoe driver presence.\n"); |
| 4514 | if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS) |
| 4515 | ql_dbg(ql_dbg_p3p, vha, 0xb074, |
| 4516 | "Error while setting DRV-Presence.\n"); |
| 4517 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4518 | } else { |
Joe Perches | d8424f6 | 2011-11-18 09:03:06 -0800 | [diff] [blame] | 4519 | ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n", |
| 4520 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4521 | } |
| 4522 | |
| 4523 | return(status); |
| 4524 | } |
| 4525 | |
| 4526 | /* |
| 4527 | * qla2x00_restart_isp |
| 4528 | * restarts the ISP after a reset |
| 4529 | * |
| 4530 | * Input: |
| 4531 | * ha = adapter block pointer. |
| 4532 | * |
| 4533 | * Returns: |
| 4534 | * 0 = success |
| 4535 | */ |
| 4536 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4537 | qla2x00_restart_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4538 | { |
Andrew Vasquez | c6b2fca | 2009-03-05 11:07:03 -0800 | [diff] [blame] | 4539 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4540 | uint32_t wait_time; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4541 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4542 | struct req_que *req = ha->req_q_map[0]; |
| 4543 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4544 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4545 | |
| 4546 | /* If firmware needs to be loaded */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4547 | if (qla2x00_isp_firmware(vha)) { |
| 4548 | vha->flags.online = 0; |
| 4549 | status = ha->isp_ops->chip_diag(vha); |
| 4550 | if (!status) |
| 4551 | status = qla2x00_setup_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4552 | } |
| 4553 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4554 | if (!status && !(status = qla2x00_init_rings(vha))) { |
| 4555 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 4556 | ha->flags.chip_reset_done = 1; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4557 | /* Initialize the queues in use */ |
| 4558 | qla25xx_init_queues(ha); |
| 4559 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4560 | status = qla2x00_fw_ready(vha); |
| 4561 | if (!status) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4562 | ql_dbg(ql_dbg_taskm, vha, 0x8031, |
| 4563 | "Start configure loop status = %d.\n", status); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4564 | |
| 4565 | /* Issue a marker after FW becomes ready. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4566 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4567 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4568 | vha->flags.online = 1; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4569 | |
| 4570 | /* |
| 4571 | * Process any ATIO queue entries that came in |
| 4572 | * while we weren't online. |
| 4573 | */ |
| 4574 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4575 | if (qla_tgt_mode_enabled(vha)) |
| 4576 | qlt_24xx_process_atio_queue(vha); |
| 4577 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4578 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4579 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 4580 | wait_time = 256; |
| 4581 | do { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4582 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 4583 | qla2x00_configure_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4584 | wait_time--; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4585 | } while (!atomic_read(&vha->loop_down_timer) && |
| 4586 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
| 4587 | && wait_time && (test_bit(LOOP_RESYNC_NEEDED, |
| 4588 | &vha->dpc_flags))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4589 | } |
| 4590 | |
| 4591 | /* if no cable then assume it's good */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4592 | if ((vha->device_flags & DFLG_NO_CABLE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4593 | status = 0; |
| 4594 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4595 | ql_dbg(ql_dbg_taskm, vha, 0x8032, |
| 4596 | "Configure loop done, status = 0x%x.\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4597 | } |
| 4598 | return (status); |
| 4599 | } |
| 4600 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4601 | static int |
| 4602 | qla25xx_init_queues(struct qla_hw_data *ha) |
| 4603 | { |
| 4604 | struct rsp_que *rsp = NULL; |
| 4605 | struct req_que *req = NULL; |
| 4606 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
| 4607 | int ret = -1; |
| 4608 | int i; |
| 4609 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 4610 | for (i = 1; i < ha->max_rsp_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4611 | rsp = ha->rsp_q_map[i]; |
| 4612 | if (rsp) { |
| 4613 | rsp->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 4614 | ret = qla25xx_init_rsp_que(base_vha, rsp); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4615 | if (ret != QLA_SUCCESS) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4616 | ql_dbg(ql_dbg_init, base_vha, 0x00ff, |
| 4617 | "%s Rsp que: %d init failed.\n", |
| 4618 | __func__, rsp->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4619 | else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4620 | ql_dbg(ql_dbg_init, base_vha, 0x0100, |
| 4621 | "%s Rsp que: %d inited.\n", |
| 4622 | __func__, rsp->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4623 | } |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 4624 | } |
| 4625 | for (i = 1; i < ha->max_req_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4626 | req = ha->req_q_map[i]; |
| 4627 | if (req) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 4628 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4629 | req->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 4630 | ret = qla25xx_init_req_que(base_vha, req); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4631 | if (ret != QLA_SUCCESS) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4632 | ql_dbg(ql_dbg_init, base_vha, 0x0101, |
| 4633 | "%s Req que: %d init failed.\n", |
| 4634 | __func__, req->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4635 | else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4636 | ql_dbg(ql_dbg_init, base_vha, 0x0102, |
| 4637 | "%s Req que: %d inited.\n", |
| 4638 | __func__, req->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4639 | } |
| 4640 | } |
| 4641 | return ret; |
| 4642 | } |
| 4643 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4644 | /* |
| 4645 | * qla2x00_reset_adapter |
| 4646 | * Reset adapter. |
| 4647 | * |
| 4648 | * Input: |
| 4649 | * ha = adapter block pointer. |
| 4650 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4651 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4652 | qla2x00_reset_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4653 | { |
| 4654 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4655 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 4656 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4657 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4658 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 4659 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4660 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4661 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4662 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 4663 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 4664 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 4665 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 4666 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4667 | } |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4668 | |
| 4669 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4670 | qla24xx_reset_adapter(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4671 | { |
| 4672 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4673 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4674 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 4675 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4676 | if (IS_QLA82XX(ha)) |
| 4677 | return; |
| 4678 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4679 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 4680 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4681 | |
| 4682 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4683 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 4684 | RD_REG_DWORD(®->hccr); |
| 4685 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 4686 | RD_REG_DWORD(®->hccr); |
| 4687 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 09ff36d | 2009-01-22 09:45:30 -0800 | [diff] [blame] | 4688 | |
| 4689 | if (IS_NOPOLLING_TYPE(ha)) |
| 4690 | ha->isp_ops->enable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4691 | } |
| 4692 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4693 | /* On sparc systems, obtain port and node WWN from firmware |
| 4694 | * properties. |
| 4695 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4696 | static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, |
| 4697 | struct nvram_24xx *nv) |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4698 | { |
| 4699 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4700 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4701 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 4702 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 4703 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4704 | int len; |
| 4705 | |
| 4706 | val = of_get_property(dp, "port-wwn", &len); |
| 4707 | if (val && len >= WWN_SIZE) |
| 4708 | memcpy(nv->port_name, val, WWN_SIZE); |
| 4709 | |
| 4710 | val = of_get_property(dp, "node-wwn", &len); |
| 4711 | if (val && len >= WWN_SIZE) |
| 4712 | memcpy(nv->node_name, val, WWN_SIZE); |
| 4713 | #endif |
| 4714 | } |
| 4715 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4716 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4717 | qla24xx_nvram_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4718 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4719 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4720 | struct init_cb_24xx *icb; |
| 4721 | struct nvram_24xx *nv; |
| 4722 | uint32_t *dptr; |
| 4723 | uint8_t *dptr1, *dptr2; |
| 4724 | uint32_t chksum; |
| 4725 | uint16_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4726 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4727 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4728 | rval = QLA_SUCCESS; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4729 | icb = (struct init_cb_24xx *)ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 4730 | nv = ha->nvram; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4731 | |
| 4732 | /* Determine NVRAM starting address. */ |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 4733 | if (ha->flags.port0) { |
| 4734 | ha->nvram_base = FA_NVRAM_FUNC0_ADDR; |
| 4735 | ha->vpd_base = FA_NVRAM_VPD0_ADDR; |
| 4736 | } else { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4737 | ha->nvram_base = FA_NVRAM_FUNC1_ADDR; |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 4738 | ha->vpd_base = FA_NVRAM_VPD1_ADDR; |
| 4739 | } |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 4740 | ha->nvram_size = sizeof(struct nvram_24xx); |
| 4741 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4742 | if (IS_QLA82XX(ha)) |
| 4743 | ha->vpd_size = FA_VPD_SIZE_82XX; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4744 | |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 4745 | /* Get VPD data into cache */ |
| 4746 | ha->vpd = ha->nvram + VPD_OFFSET; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4747 | ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 4748 | ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4); |
| 4749 | |
| 4750 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4751 | dptr = (uint32_t *)nv; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4752 | ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4753 | ha->nvram_size); |
| 4754 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++) |
| 4755 | chksum += le32_to_cpu(*dptr++); |
| 4756 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4757 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a, |
| 4758 | "Contents of NVRAM\n"); |
| 4759 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d, |
| 4760 | (uint8_t *)nv, ha->nvram_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4761 | |
| 4762 | /* Bad NVRAM data, set defaults parameters. */ |
| 4763 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 4764 | || nv->id[3] != ' ' || |
| 4765 | nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) { |
| 4766 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4767 | ql_log(ql_log_warn, vha, 0x006b, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 4768 | "Inconsistent NVRAM detected: checksum=0x%x id=%c " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4769 | "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version); |
| 4770 | ql_log(ql_log_warn, vha, 0x006c, |
| 4771 | "Falling back to functioning (yet invalid -- WWPN) " |
| 4772 | "defaults.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4773 | |
| 4774 | /* |
| 4775 | * Set default initialization control block. |
| 4776 | */ |
| 4777 | memset(nv, 0, ha->nvram_size); |
| 4778 | nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION); |
| 4779 | nv->version = __constant_cpu_to_le16(ICB_VERSION); |
| 4780 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 4781 | nv->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 4782 | nv->exchange_count = __constant_cpu_to_le16(0); |
| 4783 | nv->hard_address = __constant_cpu_to_le16(124); |
| 4784 | nv->port_name[0] = 0x21; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 4785 | nv->port_name[1] = 0x00 + ha->port_no; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4786 | nv->port_name[2] = 0x00; |
| 4787 | nv->port_name[3] = 0xe0; |
| 4788 | nv->port_name[4] = 0x8b; |
| 4789 | nv->port_name[5] = 0x1c; |
| 4790 | nv->port_name[6] = 0x55; |
| 4791 | nv->port_name[7] = 0x86; |
| 4792 | nv->node_name[0] = 0x20; |
| 4793 | nv->node_name[1] = 0x00; |
| 4794 | nv->node_name[2] = 0x00; |
| 4795 | nv->node_name[3] = 0xe0; |
| 4796 | nv->node_name[4] = 0x8b; |
| 4797 | nv->node_name[5] = 0x1c; |
| 4798 | nv->node_name[6] = 0x55; |
| 4799 | nv->node_name[7] = 0x86; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4800 | qla24xx_nvram_wwn_from_ofw(vha, nv); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4801 | nv->login_retry_count = __constant_cpu_to_le16(8); |
| 4802 | nv->interrupt_delay_timer = __constant_cpu_to_le16(0); |
| 4803 | nv->login_timeout = __constant_cpu_to_le16(0); |
| 4804 | nv->firmware_options_1 = |
| 4805 | __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 4806 | nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4); |
| 4807 | nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12); |
| 4808 | nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13); |
| 4809 | nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10); |
| 4810 | nv->efi_parameters = __constant_cpu_to_le32(0); |
| 4811 | nv->reset_delay = 5; |
| 4812 | nv->max_luns_per_target = __constant_cpu_to_le16(128); |
| 4813 | nv->port_down_retry_count = __constant_cpu_to_le16(30); |
| 4814 | nv->link_down_timeout = __constant_cpu_to_le16(30); |
| 4815 | |
| 4816 | rval = 1; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4817 | } |
| 4818 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4819 | if (!qla_ini_mode_enabled(vha)) { |
| 4820 | /* Don't enable full login after initial LIP */ |
| 4821 | nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_13); |
| 4822 | /* Don't enable LIP full login for initiator */ |
| 4823 | nv->host_p &= __constant_cpu_to_le32(~BIT_10); |
| 4824 | } |
| 4825 | |
| 4826 | qlt_24xx_config_nvram_stage1(vha, nv); |
| 4827 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4828 | /* Reset Initialization control block */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4829 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4830 | |
| 4831 | /* Copy 1st segment. */ |
| 4832 | dptr1 = (uint8_t *)icb; |
| 4833 | dptr2 = (uint8_t *)&nv->version; |
| 4834 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 4835 | while (cnt--) |
| 4836 | *dptr1++ = *dptr2++; |
| 4837 | |
| 4838 | icb->login_retry_count = nv->login_retry_count; |
Andrew Vasquez | 3ea66e2 | 2006-06-23 16:11:27 -0700 | [diff] [blame] | 4839 | icb->link_down_on_nos = nv->link_down_on_nos; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4840 | |
| 4841 | /* Copy 2nd segment. */ |
| 4842 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 4843 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 4844 | cnt = (uint8_t *)&icb->reserved_3 - |
| 4845 | (uint8_t *)&icb->interrupt_delay_timer; |
| 4846 | while (cnt--) |
| 4847 | *dptr1++ = *dptr2++; |
| 4848 | |
| 4849 | /* |
| 4850 | * Setup driver NVRAM options. |
| 4851 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4852 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 4853 | "QLA2462"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4854 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4855 | qlt_24xx_config_nvram_stage2(vha, icb); |
| 4856 | |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 4857 | if (nv->host_p & __constant_cpu_to_le32(BIT_15)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4858 | /* Use alternate WWN? */ |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 4859 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 4860 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 4861 | } |
| 4862 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4863 | /* Prepare nodename */ |
Andrew Vasquez | fd0e7e4 | 2006-05-17 15:09:11 -0700 | [diff] [blame] | 4864 | if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4865 | /* |
| 4866 | * Firmware will apply the following mask if the nodename was |
| 4867 | * not provided. |
| 4868 | */ |
| 4869 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 4870 | icb->node_name[0] &= 0xF0; |
| 4871 | } |
| 4872 | |
| 4873 | /* Set host adapter parameters. */ |
| 4874 | ha->flags.disable_risc_code_load = 0; |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 4875 | ha->flags.enable_lip_reset = 0; |
| 4876 | ha->flags.enable_lip_full_login = |
| 4877 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 4878 | ha->flags.enable_target_reset = |
| 4879 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4880 | ha->flags.enable_led_scheme = 0; |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 4881 | 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] | 4882 | |
Andrew Vasquez | fd0e7e4 | 2006-05-17 15:09:11 -0700 | [diff] [blame] | 4883 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 4884 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4885 | |
| 4886 | memcpy(ha->fw_seriallink_options24, nv->seriallink_options, |
| 4887 | sizeof(ha->fw_seriallink_options24)); |
| 4888 | |
| 4889 | /* save HBA serial number */ |
| 4890 | ha->serial0 = icb->port_name[5]; |
| 4891 | ha->serial1 = icb->port_name[6]; |
| 4892 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4893 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 4894 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4895 | |
andrew.vasquez@qlogic.com | bc8fb3c | 2006-01-13 17:05:42 -0800 | [diff] [blame] | 4896 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 4897 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4898 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 4899 | |
| 4900 | /* Set minimum login_timeout to 4 seconds. */ |
| 4901 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 4902 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 4903 | if (le16_to_cpu(nv->login_timeout) < 4) |
| 4904 | nv->login_timeout = __constant_cpu_to_le16(4); |
| 4905 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
Seokmann Ju | c6852c4 | 2008-04-24 15:21:29 -0700 | [diff] [blame] | 4906 | icb->login_timeout = nv->login_timeout; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4907 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 4908 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 4909 | ha->r_a_tov = 100; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4910 | |
| 4911 | ha->loop_reset_delay = nv->reset_delay; |
| 4912 | |
| 4913 | /* Link Down Timeout = 0: |
| 4914 | * |
| 4915 | * When Port Down timer expires we will start returning |
| 4916 | * I/O's to OS with "DID_NO_CONNECT". |
| 4917 | * |
| 4918 | * Link Down Timeout != 0: |
| 4919 | * |
| 4920 | * The driver waits for the link to come up after link down |
| 4921 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 4922 | */ |
| 4923 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 4924 | ha->loop_down_abort_time = |
| 4925 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 4926 | } else { |
| 4927 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 4928 | ha->loop_down_abort_time = |
| 4929 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 4930 | } |
| 4931 | |
| 4932 | /* Need enough time to try and get the port back. */ |
| 4933 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 4934 | if (qlport_down_retry) |
| 4935 | ha->port_down_retry_count = qlport_down_retry; |
| 4936 | |
| 4937 | /* Set login_retry_count */ |
| 4938 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 4939 | if (ha->port_down_retry_count == |
| 4940 | le16_to_cpu(nv->port_down_retry_count) && |
| 4941 | ha->port_down_retry_count > 3) |
| 4942 | ha->login_retry_count = ha->port_down_retry_count; |
| 4943 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 4944 | ha->login_retry_count = ha->port_down_retry_count; |
| 4945 | if (ql2xloginretrycount) |
| 4946 | ha->login_retry_count = ql2xloginretrycount; |
| 4947 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4948 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4949 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4950 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 4951 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 4952 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 4953 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 4954 | } |
| 4955 | icb->firmware_options_2 &= __constant_cpu_to_le32( |
| 4956 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4957 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4958 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 4959 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 4960 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4961 | ql_log(ql_log_info, vha, 0x006f, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4962 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 4963 | ha->zio_mode, ha->zio_timer * 100); |
| 4964 | |
| 4965 | icb->firmware_options_2 |= cpu_to_le32( |
| 4966 | (uint32_t)ha->zio_mode); |
| 4967 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4968 | vha->flags.process_response_queue = 1; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4969 | } |
| 4970 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4971 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4972 | ql_log(ql_log_warn, vha, 0x0070, |
| 4973 | "NVRAM configuration failed.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4974 | } |
| 4975 | return (rval); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4976 | } |
| 4977 | |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 4978 | static int |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4979 | qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr, |
| 4980 | uint32_t faddr) |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4981 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4982 | int rval = QLA_SUCCESS; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4983 | int segments, fragment; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4984 | uint32_t *dcode, dlen; |
| 4985 | uint32_t risc_addr; |
| 4986 | uint32_t risc_size; |
| 4987 | uint32_t i; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4988 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4989 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4990 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4991 | ql_dbg(ql_dbg_init, vha, 0x008b, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 4992 | "FW: Loading firmware from flash (%x).\n", faddr); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4993 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4994 | rval = QLA_SUCCESS; |
| 4995 | |
| 4996 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4997 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4998 | *srisc_addr = 0; |
| 4999 | |
| 5000 | /* Validate firmware image by checking version. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5001 | qla24xx_read_flash_data(vha, dcode, faddr + 4, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5002 | for (i = 0; i < 4; i++) |
| 5003 | dcode[i] = be32_to_cpu(dcode[i]); |
| 5004 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 5005 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 5006 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 5007 | dcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5008 | ql_log(ql_log_fatal, vha, 0x008c, |
| 5009 | "Unable to verify the integrity of flash firmware " |
| 5010 | "image.\n"); |
| 5011 | ql_log(ql_log_fatal, vha, 0x008d, |
| 5012 | "Firmware data: %08x %08x %08x %08x.\n", |
| 5013 | dcode[0], dcode[1], dcode[2], dcode[3]); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5014 | |
| 5015 | return QLA_FUNCTION_FAILED; |
| 5016 | } |
| 5017 | |
| 5018 | while (segments && rval == QLA_SUCCESS) { |
| 5019 | /* Read segment's load information. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5020 | qla24xx_read_flash_data(vha, dcode, faddr, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5021 | |
| 5022 | risc_addr = be32_to_cpu(dcode[2]); |
| 5023 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 5024 | risc_size = be32_to_cpu(dcode[3]); |
| 5025 | |
| 5026 | fragment = 0; |
| 5027 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 5028 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 5029 | if (dlen > risc_size) |
| 5030 | dlen = risc_size; |
| 5031 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5032 | ql_dbg(ql_dbg_init, vha, 0x008e, |
| 5033 | "Loading risc segment@ risc addr %x " |
| 5034 | "number of dwords 0x%x offset 0x%x.\n", |
| 5035 | risc_addr, dlen, faddr); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5036 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5037 | qla24xx_read_flash_data(vha, dcode, faddr, dlen); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5038 | for (i = 0; i < dlen; i++) |
| 5039 | dcode[i] = swab32(dcode[i]); |
| 5040 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5041 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5042 | dlen); |
| 5043 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5044 | ql_log(ql_log_fatal, vha, 0x008f, |
| 5045 | "Failed to load segment %d of firmware.\n", |
| 5046 | fragment); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5047 | break; |
| 5048 | } |
| 5049 | |
| 5050 | faddr += dlen; |
| 5051 | risc_addr += dlen; |
| 5052 | risc_size -= dlen; |
| 5053 | fragment++; |
| 5054 | } |
| 5055 | |
| 5056 | /* Next segment. */ |
| 5057 | segments--; |
| 5058 | } |
| 5059 | |
| 5060 | return rval; |
| 5061 | } |
| 5062 | |
Giridhar Malavali | e9454a8 | 2013-02-08 01:57:47 -0500 | [diff] [blame] | 5063 | #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/" |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5064 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5065 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5066 | qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5067 | { |
| 5068 | int rval; |
| 5069 | int i, fragment; |
| 5070 | uint16_t *wcode, *fwcode; |
| 5071 | uint32_t risc_addr, risc_size, fwclen, wlen, *seg; |
| 5072 | struct fw_blob *blob; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5073 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5074 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5075 | |
| 5076 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5077 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5078 | if (!blob) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5079 | ql_log(ql_log_info, vha, 0x0083, |
| 5080 | "Fimware image unavailable.\n"); |
| 5081 | ql_log(ql_log_info, vha, 0x0084, |
| 5082 | "Firmware images can be retrieved from: "QLA_FW_URL ".\n"); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5083 | return QLA_FUNCTION_FAILED; |
| 5084 | } |
| 5085 | |
| 5086 | rval = QLA_SUCCESS; |
| 5087 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5088 | wcode = (uint16_t *)req->ring; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5089 | *srisc_addr = 0; |
| 5090 | fwcode = (uint16_t *)blob->fw->data; |
| 5091 | fwclen = 0; |
| 5092 | |
| 5093 | /* Validate firmware image by checking version. */ |
| 5094 | if (blob->fw->size < 8 * sizeof(uint16_t)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5095 | ql_log(ql_log_fatal, vha, 0x0085, |
| 5096 | "Unable to verify integrity of firmware image (%Zd).\n", |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5097 | blob->fw->size); |
| 5098 | goto fail_fw_integrity; |
| 5099 | } |
| 5100 | for (i = 0; i < 4; i++) |
| 5101 | wcode[i] = be16_to_cpu(fwcode[i + 4]); |
| 5102 | if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff && |
| 5103 | wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 && |
| 5104 | wcode[2] == 0 && wcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5105 | ql_log(ql_log_fatal, vha, 0x0086, |
| 5106 | "Unable to verify integrity of firmware image.\n"); |
| 5107 | ql_log(ql_log_fatal, vha, 0x0087, |
| 5108 | "Firmware data: %04x %04x %04x %04x.\n", |
| 5109 | wcode[0], wcode[1], wcode[2], wcode[3]); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5110 | goto fail_fw_integrity; |
| 5111 | } |
| 5112 | |
| 5113 | seg = blob->segs; |
| 5114 | while (*seg && rval == QLA_SUCCESS) { |
| 5115 | risc_addr = *seg; |
| 5116 | *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr; |
| 5117 | risc_size = be16_to_cpu(fwcode[3]); |
| 5118 | |
| 5119 | /* Validate firmware image size. */ |
| 5120 | fwclen += risc_size * sizeof(uint16_t); |
| 5121 | if (blob->fw->size < fwclen) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5122 | ql_log(ql_log_fatal, vha, 0x0088, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5123 | "Unable to verify integrity of firmware image " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5124 | "(%Zd).\n", blob->fw->size); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5125 | goto fail_fw_integrity; |
| 5126 | } |
| 5127 | |
| 5128 | fragment = 0; |
| 5129 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 5130 | wlen = (uint16_t)(ha->fw_transfer_size >> 1); |
| 5131 | if (wlen > risc_size) |
| 5132 | wlen = risc_size; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5133 | ql_dbg(ql_dbg_init, vha, 0x0089, |
| 5134 | "Loading risc segment@ risc addr %x number of " |
| 5135 | "words 0x%x.\n", risc_addr, wlen); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5136 | |
| 5137 | for (i = 0; i < wlen; i++) |
| 5138 | wcode[i] = swab16(fwcode[i]); |
| 5139 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5140 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5141 | wlen); |
| 5142 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5143 | ql_log(ql_log_fatal, vha, 0x008a, |
| 5144 | "Failed to load segment %d of firmware.\n", |
| 5145 | fragment); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5146 | break; |
| 5147 | } |
| 5148 | |
| 5149 | fwcode += wlen; |
| 5150 | risc_addr += wlen; |
| 5151 | risc_size -= wlen; |
| 5152 | fragment++; |
| 5153 | } |
| 5154 | |
| 5155 | /* Next segment. */ |
| 5156 | seg++; |
| 5157 | } |
| 5158 | return rval; |
| 5159 | |
| 5160 | fail_fw_integrity: |
| 5161 | return QLA_FUNCTION_FAILED; |
| 5162 | } |
| 5163 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5164 | static int |
| 5165 | 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] | 5166 | { |
| 5167 | int rval; |
| 5168 | int segments, fragment; |
| 5169 | uint32_t *dcode, dlen; |
| 5170 | uint32_t risc_addr; |
| 5171 | uint32_t risc_size; |
| 5172 | uint32_t i; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5173 | struct fw_blob *blob; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5174 | uint32_t *fwcode, fwclen; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5175 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5176 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5177 | |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5178 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5179 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5180 | if (!blob) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5181 | ql_log(ql_log_warn, vha, 0x0090, |
| 5182 | "Fimware image unavailable.\n"); |
| 5183 | ql_log(ql_log_warn, vha, 0x0091, |
| 5184 | "Firmware images can be retrieved from: " |
| 5185 | QLA_FW_URL ".\n"); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 5186 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5187 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5188 | } |
| 5189 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5190 | ql_dbg(ql_dbg_init, vha, 0x0092, |
| 5191 | "FW: Loading via request-firmware.\n"); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5192 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5193 | rval = QLA_SUCCESS; |
| 5194 | |
| 5195 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5196 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5197 | *srisc_addr = 0; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5198 | fwcode = (uint32_t *)blob->fw->data; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5199 | fwclen = 0; |
| 5200 | |
| 5201 | /* Validate firmware image by checking version. */ |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5202 | if (blob->fw->size < 8 * sizeof(uint32_t)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5203 | ql_log(ql_log_fatal, vha, 0x0093, |
| 5204 | "Unable to verify integrity of firmware image (%Zd).\n", |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5205 | blob->fw->size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5206 | goto fail_fw_integrity; |
| 5207 | } |
| 5208 | for (i = 0; i < 4; i++) |
| 5209 | dcode[i] = be32_to_cpu(fwcode[i + 4]); |
| 5210 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 5211 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 5212 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 5213 | dcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5214 | ql_log(ql_log_fatal, vha, 0x0094, |
| 5215 | "Unable to verify integrity of firmware image (%Zd).\n", |
| 5216 | blob->fw->size); |
| 5217 | ql_log(ql_log_fatal, vha, 0x0095, |
| 5218 | "Firmware data: %08x %08x %08x %08x.\n", |
| 5219 | dcode[0], dcode[1], dcode[2], dcode[3]); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5220 | goto fail_fw_integrity; |
| 5221 | } |
| 5222 | |
| 5223 | while (segments && rval == QLA_SUCCESS) { |
| 5224 | risc_addr = be32_to_cpu(fwcode[2]); |
| 5225 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 5226 | risc_size = be32_to_cpu(fwcode[3]); |
| 5227 | |
| 5228 | /* Validate firmware image size. */ |
| 5229 | fwclen += risc_size * sizeof(uint32_t); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5230 | if (blob->fw->size < fwclen) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5231 | ql_log(ql_log_fatal, vha, 0x0096, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5232 | "Unable to verify integrity of firmware image " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5233 | "(%Zd).\n", blob->fw->size); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 5234 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5235 | goto fail_fw_integrity; |
| 5236 | } |
| 5237 | |
| 5238 | fragment = 0; |
| 5239 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 5240 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 5241 | if (dlen > risc_size) |
| 5242 | dlen = risc_size; |
| 5243 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5244 | ql_dbg(ql_dbg_init, vha, 0x0097, |
| 5245 | "Loading risc segment@ risc addr %x " |
| 5246 | "number of dwords 0x%x.\n", risc_addr, dlen); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5247 | |
| 5248 | for (i = 0; i < dlen; i++) |
| 5249 | dcode[i] = swab32(fwcode[i]); |
| 5250 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5251 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
andrew.vasquez@qlogic.com | 590f98e | 2006-01-13 17:05:37 -0800 | [diff] [blame] | 5252 | dlen); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5253 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5254 | ql_log(ql_log_fatal, vha, 0x0098, |
| 5255 | "Failed to load segment %d of firmware.\n", |
| 5256 | fragment); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5257 | break; |
| 5258 | } |
| 5259 | |
| 5260 | fwcode += dlen; |
| 5261 | risc_addr += dlen; |
| 5262 | risc_size -= dlen; |
| 5263 | fragment++; |
| 5264 | } |
| 5265 | |
| 5266 | /* Next segment. */ |
| 5267 | segments--; |
| 5268 | } |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5269 | return rval; |
| 5270 | |
| 5271 | fail_fw_integrity: |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5272 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5273 | } |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5274 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5275 | int |
| 5276 | qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 5277 | { |
| 5278 | int rval; |
| 5279 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 5280 | if (ql2xfwloadbin == 1) |
| 5281 | return qla81xx_load_risc(vha, srisc_addr); |
| 5282 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5283 | /* |
| 5284 | * FW Load priority: |
| 5285 | * 1) Firmware via request-firmware interface (.bin file). |
| 5286 | * 2) Firmware residing in flash. |
| 5287 | */ |
| 5288 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 5289 | if (rval == QLA_SUCCESS) |
| 5290 | return rval; |
| 5291 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5292 | return qla24xx_load_risc_flash(vha, srisc_addr, |
| 5293 | vha->hw->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5294 | } |
| 5295 | |
| 5296 | int |
| 5297 | qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 5298 | { |
| 5299 | int rval; |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5300 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5301 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 5302 | if (ql2xfwloadbin == 2) |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5303 | goto try_blob_fw; |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 5304 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5305 | /* |
| 5306 | * FW Load priority: |
| 5307 | * 1) Firmware residing in flash. |
| 5308 | * 2) Firmware via request-firmware interface (.bin file). |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5309 | * 3) Golden-Firmware residing in flash -- limited operation. |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5310 | */ |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5311 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5312 | if (rval == QLA_SUCCESS) |
| 5313 | return rval; |
| 5314 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5315 | try_blob_fw: |
| 5316 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 5317 | if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw) |
| 5318 | return rval; |
| 5319 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5320 | ql_log(ql_log_info, vha, 0x0099, |
| 5321 | "Attempting to fallback to golden firmware.\n"); |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5322 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw); |
| 5323 | if (rval != QLA_SUCCESS) |
| 5324 | return rval; |
| 5325 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5326 | ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n"); |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5327 | ha->flags.running_gold_fw = 1; |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 5328 | return rval; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 5329 | } |
| 5330 | |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5331 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5332 | qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5333 | { |
| 5334 | int ret, retries; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5335 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5336 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 5337 | if (ha->flags.pci_channel_io_perm_failure) |
| 5338 | return; |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 5339 | if (!IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5340 | return; |
Andrew Vasquez | 75edf81 | 2007-05-07 07:43:00 -0700 | [diff] [blame] | 5341 | if (!ha->fw_major_version) |
| 5342 | return; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5343 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5344 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 7c7f1f2 | 2008-02-28 14:06:09 -0800 | [diff] [blame] | 5345 | for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT && |
Andrew Vasquez | b469a7c | 2009-04-06 22:33:48 -0700 | [diff] [blame] | 5346 | ret != QLA_INVALID_COMMAND && retries ; retries--) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5347 | ha->isp_ops->reset_chip(vha); |
| 5348 | if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5349 | continue; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5350 | if (qla2x00_setup_chip(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5351 | continue; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5352 | ql_log(ql_log_info, vha, 0x8015, |
| 5353 | "Attempting retry of stop-firmware command.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5354 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 5355 | } |
| 5356 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5357 | |
| 5358 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5359 | qla24xx_configure_vhba(scsi_qla_host_t *vha) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5360 | { |
| 5361 | int rval = QLA_SUCCESS; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 5362 | int rval2; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5363 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5364 | struct qla_hw_data *ha = vha->hw; |
| 5365 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 5366 | struct req_que *req; |
| 5367 | struct rsp_que *rsp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5368 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5369 | if (!vha->vp_idx) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5370 | return -EINVAL; |
| 5371 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5372 | rval = qla2x00_fw_ready(base_vha); |
Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 5373 | if (ha->flags.cpu_affinity_enabled) |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 5374 | req = ha->req_q_map[0]; |
| 5375 | else |
| 5376 | req = vha->req; |
| 5377 | rsp = req->rsp; |
| 5378 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5379 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5380 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5381 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5382 | } |
| 5383 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5384 | vha->flags.management_server_logged_in = 0; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5385 | |
| 5386 | /* Login to SNS first */ |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 5387 | rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, |
| 5388 | BIT_1); |
| 5389 | if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) { |
| 5390 | if (rval2 == QLA_MEMORY_ALLOC_FAILED) |
| 5391 | ql_dbg(ql_dbg_init, vha, 0x0120, |
| 5392 | "Failed SNS login: loop_id=%x, rval2=%d\n", |
| 5393 | NPH_SNS, rval2); |
| 5394 | else |
| 5395 | ql_dbg(ql_dbg_init, vha, 0x0103, |
| 5396 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x " |
| 5397 | "mb[2]=%x mb[6]=%x mb[7]=%x.\n", |
| 5398 | NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5399 | return (QLA_FUNCTION_FAILED); |
| 5400 | } |
| 5401 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5402 | atomic_set(&vha->loop_down_timer, 0); |
| 5403 | atomic_set(&vha->loop_state, LOOP_UP); |
| 5404 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 5405 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 5406 | rval = qla2x00_loop_resync(base_vha); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5407 | |
| 5408 | return rval; |
| 5409 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5410 | |
| 5411 | /* 84XX Support **************************************************************/ |
| 5412 | |
| 5413 | static LIST_HEAD(qla_cs84xx_list); |
| 5414 | static DEFINE_MUTEX(qla_cs84xx_mutex); |
| 5415 | |
| 5416 | static struct qla_chip_state_84xx * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5417 | qla84xx_get_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5418 | { |
| 5419 | struct qla_chip_state_84xx *cs84xx; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5420 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5421 | |
| 5422 | mutex_lock(&qla_cs84xx_mutex); |
| 5423 | |
| 5424 | /* Find any shared 84xx chip. */ |
| 5425 | list_for_each_entry(cs84xx, &qla_cs84xx_list, list) { |
| 5426 | if (cs84xx->bus == ha->pdev->bus) { |
| 5427 | kref_get(&cs84xx->kref); |
| 5428 | goto done; |
| 5429 | } |
| 5430 | } |
| 5431 | |
| 5432 | cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL); |
| 5433 | if (!cs84xx) |
| 5434 | goto done; |
| 5435 | |
| 5436 | kref_init(&cs84xx->kref); |
| 5437 | spin_lock_init(&cs84xx->access_lock); |
| 5438 | mutex_init(&cs84xx->fw_update_mutex); |
| 5439 | cs84xx->bus = ha->pdev->bus; |
| 5440 | |
| 5441 | list_add_tail(&cs84xx->list, &qla_cs84xx_list); |
| 5442 | done: |
| 5443 | mutex_unlock(&qla_cs84xx_mutex); |
| 5444 | return cs84xx; |
| 5445 | } |
| 5446 | |
| 5447 | static void |
| 5448 | __qla84xx_chip_release(struct kref *kref) |
| 5449 | { |
| 5450 | struct qla_chip_state_84xx *cs84xx = |
| 5451 | container_of(kref, struct qla_chip_state_84xx, kref); |
| 5452 | |
| 5453 | mutex_lock(&qla_cs84xx_mutex); |
| 5454 | list_del(&cs84xx->list); |
| 5455 | mutex_unlock(&qla_cs84xx_mutex); |
| 5456 | kfree(cs84xx); |
| 5457 | } |
| 5458 | |
| 5459 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5460 | qla84xx_put_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5461 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5462 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5463 | if (ha->cs84xx) |
| 5464 | kref_put(&ha->cs84xx->kref, __qla84xx_chip_release); |
| 5465 | } |
| 5466 | |
| 5467 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5468 | qla84xx_init_chip(scsi_qla_host_t *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5469 | { |
| 5470 | int rval; |
| 5471 | uint16_t status[2]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5472 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5473 | |
| 5474 | mutex_lock(&ha->cs84xx->fw_update_mutex); |
| 5475 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5476 | rval = qla84xx_verify_chip(vha, status); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5477 | |
| 5478 | mutex_unlock(&ha->cs84xx->fw_update_mutex); |
| 5479 | |
| 5480 | return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED: |
| 5481 | QLA_SUCCESS; |
| 5482 | } |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5483 | |
| 5484 | /* 81XX Support **************************************************************/ |
| 5485 | |
| 5486 | int |
| 5487 | qla81xx_nvram_config(scsi_qla_host_t *vha) |
| 5488 | { |
| 5489 | int rval; |
| 5490 | struct init_cb_81xx *icb; |
| 5491 | struct nvram_81xx *nv; |
| 5492 | uint32_t *dptr; |
| 5493 | uint8_t *dptr1, *dptr2; |
| 5494 | uint32_t chksum; |
| 5495 | uint16_t cnt; |
| 5496 | struct qla_hw_data *ha = vha->hw; |
| 5497 | |
| 5498 | rval = QLA_SUCCESS; |
| 5499 | icb = (struct init_cb_81xx *)ha->init_cb; |
| 5500 | nv = ha->nvram; |
| 5501 | |
| 5502 | /* Determine NVRAM starting address. */ |
| 5503 | ha->nvram_size = sizeof(struct nvram_81xx); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5504 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5505 | |
| 5506 | /* Get VPD data into cache */ |
| 5507 | ha->vpd = ha->nvram + VPD_OFFSET; |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 5508 | ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2, |
| 5509 | ha->vpd_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5510 | |
| 5511 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 5512 | 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] | 5513 | ha->nvram_size); |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 5514 | dptr = (uint32_t *)nv; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5515 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++) |
| 5516 | chksum += le32_to_cpu(*dptr++); |
| 5517 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5518 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111, |
| 5519 | "Contents of NVRAM:\n"); |
| 5520 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112, |
| 5521 | (uint8_t *)nv, ha->nvram_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5522 | |
| 5523 | /* Bad NVRAM data, set defaults parameters. */ |
| 5524 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 5525 | || nv->id[3] != ' ' || |
| 5526 | nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) { |
| 5527 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5528 | ql_log(ql_log_info, vha, 0x0073, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 5529 | "Inconsistent NVRAM detected: checksum=0x%x id=%c " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5530 | "version=0x%x.\n", chksum, nv->id[0], |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5531 | le16_to_cpu(nv->nvram_version)); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5532 | ql_log(ql_log_info, vha, 0x0074, |
| 5533 | "Falling back to functioning (yet invalid -- WWPN) " |
| 5534 | "defaults.\n"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5535 | |
| 5536 | /* |
| 5537 | * Set default initialization control block. |
| 5538 | */ |
| 5539 | memset(nv, 0, ha->nvram_size); |
| 5540 | nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION); |
| 5541 | nv->version = __constant_cpu_to_le16(ICB_VERSION); |
| 5542 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 5543 | nv->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 5544 | nv->exchange_count = __constant_cpu_to_le16(0); |
| 5545 | nv->port_name[0] = 0x21; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5546 | nv->port_name[1] = 0x00 + ha->port_no; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5547 | nv->port_name[2] = 0x00; |
| 5548 | nv->port_name[3] = 0xe0; |
| 5549 | nv->port_name[4] = 0x8b; |
| 5550 | nv->port_name[5] = 0x1c; |
| 5551 | nv->port_name[6] = 0x55; |
| 5552 | nv->port_name[7] = 0x86; |
| 5553 | nv->node_name[0] = 0x20; |
| 5554 | nv->node_name[1] = 0x00; |
| 5555 | nv->node_name[2] = 0x00; |
| 5556 | nv->node_name[3] = 0xe0; |
| 5557 | nv->node_name[4] = 0x8b; |
| 5558 | nv->node_name[5] = 0x1c; |
| 5559 | nv->node_name[6] = 0x55; |
| 5560 | nv->node_name[7] = 0x86; |
| 5561 | nv->login_retry_count = __constant_cpu_to_le16(8); |
| 5562 | nv->interrupt_delay_timer = __constant_cpu_to_le16(0); |
| 5563 | nv->login_timeout = __constant_cpu_to_le16(0); |
| 5564 | nv->firmware_options_1 = |
| 5565 | __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 5566 | nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4); |
| 5567 | nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12); |
| 5568 | nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13); |
| 5569 | nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10); |
| 5570 | nv->efi_parameters = __constant_cpu_to_le32(0); |
| 5571 | nv->reset_delay = 5; |
| 5572 | nv->max_luns_per_target = __constant_cpu_to_le16(128); |
| 5573 | nv->port_down_retry_count = __constant_cpu_to_le16(30); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 5574 | nv->link_down_timeout = __constant_cpu_to_le16(180); |
Andrew Vasquez | eeebcc9 | 2009-06-03 09:55:24 -0700 | [diff] [blame] | 5575 | nv->enode_mac[0] = 0x00; |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 5576 | nv->enode_mac[1] = 0xC0; |
| 5577 | nv->enode_mac[2] = 0xDD; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5578 | nv->enode_mac[3] = 0x04; |
| 5579 | nv->enode_mac[4] = 0x05; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5580 | nv->enode_mac[5] = 0x06 + ha->port_no; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5581 | |
| 5582 | rval = 1; |
| 5583 | } |
| 5584 | |
Arun Easi | 9e522cd | 2012-08-22 14:21:31 -0400 | [diff] [blame] | 5585 | if (IS_T10_PI_CAPABLE(ha)) |
| 5586 | nv->frame_payload_size &= ~7; |
| 5587 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 5588 | qlt_81xx_config_nvram_stage1(vha, nv); |
| 5589 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5590 | /* Reset Initialization control block */ |
Andrew Vasquez | 773120e | 2011-05-10 11:30:14 -0700 | [diff] [blame] | 5591 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5592 | |
| 5593 | /* Copy 1st segment. */ |
| 5594 | dptr1 = (uint8_t *)icb; |
| 5595 | dptr2 = (uint8_t *)&nv->version; |
| 5596 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 5597 | while (cnt--) |
| 5598 | *dptr1++ = *dptr2++; |
| 5599 | |
| 5600 | icb->login_retry_count = nv->login_retry_count; |
| 5601 | |
| 5602 | /* Copy 2nd segment. */ |
| 5603 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 5604 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 5605 | cnt = (uint8_t *)&icb->reserved_5 - |
| 5606 | (uint8_t *)&icb->interrupt_delay_timer; |
| 5607 | while (cnt--) |
| 5608 | *dptr1++ = *dptr2++; |
| 5609 | |
| 5610 | memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac)); |
| 5611 | /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */ |
| 5612 | 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] | 5613 | icb->enode_mac[0] = 0x00; |
| 5614 | icb->enode_mac[1] = 0xC0; |
| 5615 | icb->enode_mac[2] = 0xDD; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5616 | icb->enode_mac[3] = 0x04; |
| 5617 | icb->enode_mac[4] = 0x05; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5618 | icb->enode_mac[5] = 0x06 + ha->port_no; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5619 | } |
| 5620 | |
Andrew Vasquez | b64b0e8 | 2009-03-24 09:08:01 -0700 | [diff] [blame] | 5621 | /* Use extended-initialization control block. */ |
| 5622 | memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb)); |
| 5623 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5624 | /* |
| 5625 | * Setup driver NVRAM options. |
| 5626 | */ |
| 5627 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5628 | "QLE8XXX"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5629 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 5630 | qlt_81xx_config_nvram_stage2(vha, icb); |
| 5631 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5632 | /* Use alternate WWN? */ |
| 5633 | if (nv->host_p & __constant_cpu_to_le32(BIT_15)) { |
| 5634 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 5635 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 5636 | } |
| 5637 | |
| 5638 | /* Prepare nodename */ |
| 5639 | if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) { |
| 5640 | /* |
| 5641 | * Firmware will apply the following mask if the nodename was |
| 5642 | * not provided. |
| 5643 | */ |
| 5644 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 5645 | icb->node_name[0] &= 0xF0; |
| 5646 | } |
| 5647 | |
| 5648 | /* Set host adapter parameters. */ |
| 5649 | ha->flags.disable_risc_code_load = 0; |
| 5650 | ha->flags.enable_lip_reset = 0; |
| 5651 | ha->flags.enable_lip_full_login = |
| 5652 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 5653 | ha->flags.enable_target_reset = |
| 5654 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
| 5655 | ha->flags.enable_led_scheme = 0; |
| 5656 | ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0; |
| 5657 | |
| 5658 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 5659 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 5660 | |
| 5661 | /* save HBA serial number */ |
| 5662 | ha->serial0 = icb->port_name[5]; |
| 5663 | ha->serial1 = icb->port_name[6]; |
| 5664 | ha->serial2 = icb->port_name[7]; |
| 5665 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 5666 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
| 5667 | |
| 5668 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 5669 | |
| 5670 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 5671 | |
| 5672 | /* Set minimum login_timeout to 4 seconds. */ |
| 5673 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 5674 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 5675 | if (le16_to_cpu(nv->login_timeout) < 4) |
| 5676 | nv->login_timeout = __constant_cpu_to_le16(4); |
| 5677 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
| 5678 | icb->login_timeout = nv->login_timeout; |
| 5679 | |
| 5680 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 5681 | ha->r_a_tov = 100; |
| 5682 | |
| 5683 | ha->loop_reset_delay = nv->reset_delay; |
| 5684 | |
| 5685 | /* Link Down Timeout = 0: |
| 5686 | * |
| 5687 | * When Port Down timer expires we will start returning |
| 5688 | * I/O's to OS with "DID_NO_CONNECT". |
| 5689 | * |
| 5690 | * Link Down Timeout != 0: |
| 5691 | * |
| 5692 | * The driver waits for the link to come up after link down |
| 5693 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 5694 | */ |
| 5695 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 5696 | ha->loop_down_abort_time = |
| 5697 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 5698 | } else { |
| 5699 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 5700 | ha->loop_down_abort_time = |
| 5701 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 5702 | } |
| 5703 | |
| 5704 | /* Need enough time to try and get the port back. */ |
| 5705 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 5706 | if (qlport_down_retry) |
| 5707 | ha->port_down_retry_count = qlport_down_retry; |
| 5708 | |
| 5709 | /* Set login_retry_count */ |
| 5710 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 5711 | if (ha->port_down_retry_count == |
| 5712 | le16_to_cpu(nv->port_down_retry_count) && |
| 5713 | ha->port_down_retry_count > 3) |
| 5714 | ha->login_retry_count = ha->port_down_retry_count; |
| 5715 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 5716 | ha->login_retry_count = ha->port_down_retry_count; |
| 5717 | if (ql2xloginretrycount) |
| 5718 | ha->login_retry_count = ql2xloginretrycount; |
| 5719 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 5720 | /* if not running MSI-X we need handshaking on interrupts */ |
| 5721 | if (!vha->hw->flags.msix_enabled && IS_QLA83XX(ha)) |
| 5722 | icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22); |
| 5723 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5724 | /* Enable ZIO. */ |
| 5725 | if (!vha->flags.init_done) { |
| 5726 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 5727 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 5728 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 5729 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 5730 | } |
| 5731 | icb->firmware_options_2 &= __constant_cpu_to_le32( |
| 5732 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
| 5733 | vha->flags.process_response_queue = 0; |
| 5734 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
| 5735 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 5736 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5737 | ql_log(ql_log_info, vha, 0x0075, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5738 | "ZIO mode %d enabled; timer delay (%d us).\n", |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5739 | ha->zio_mode, |
| 5740 | ha->zio_timer * 100); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5741 | |
| 5742 | icb->firmware_options_2 |= cpu_to_le32( |
| 5743 | (uint32_t)ha->zio_mode); |
| 5744 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
| 5745 | vha->flags.process_response_queue = 1; |
| 5746 | } |
| 5747 | |
| 5748 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5749 | ql_log(ql_log_warn, vha, 0x0076, |
| 5750 | "NVRAM configuration failed.\n"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5751 | } |
| 5752 | return (rval); |
| 5753 | } |
| 5754 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5755 | int |
| 5756 | qla82xx_restart_isp(scsi_qla_host_t *vha) |
| 5757 | { |
| 5758 | int status, rval; |
| 5759 | uint32_t wait_time; |
| 5760 | struct qla_hw_data *ha = vha->hw; |
| 5761 | struct req_que *req = ha->req_q_map[0]; |
| 5762 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
| 5763 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5764 | unsigned long flags; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5765 | |
| 5766 | status = qla2x00_init_rings(vha); |
| 5767 | if (!status) { |
| 5768 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 5769 | ha->flags.chip_reset_done = 1; |
| 5770 | |
| 5771 | status = qla2x00_fw_ready(vha); |
| 5772 | if (!status) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5773 | ql_log(ql_log_info, vha, 0x803c, |
| 5774 | "Start configure loop, status =%d.\n", status); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5775 | |
| 5776 | /* Issue a marker after FW becomes ready. */ |
| 5777 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
| 5778 | |
| 5779 | vha->flags.online = 1; |
| 5780 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 5781 | wait_time = 256; |
| 5782 | do { |
| 5783 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 5784 | qla2x00_configure_loop(vha); |
| 5785 | wait_time--; |
| 5786 | } while (!atomic_read(&vha->loop_down_timer) && |
| 5787 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) && |
| 5788 | wait_time && |
| 5789 | (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))); |
| 5790 | } |
| 5791 | |
| 5792 | /* if no cable then assume it's good */ |
| 5793 | if ((vha->device_flags & DFLG_NO_CABLE)) |
| 5794 | status = 0; |
| 5795 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5796 | ql_log(ql_log_info, vha, 0x8000, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5797 | "Configure loop done, status = 0x%x.\n", status); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5798 | } |
| 5799 | |
| 5800 | if (!status) { |
| 5801 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 5802 | |
| 5803 | if (!atomic_read(&vha->loop_down_timer)) { |
| 5804 | /* |
| 5805 | * Issue marker command only when we are going |
| 5806 | * to start the I/O . |
| 5807 | */ |
| 5808 | vha->marker_needed = 1; |
| 5809 | } |
| 5810 | |
| 5811 | vha->flags.online = 1; |
| 5812 | |
| 5813 | ha->isp_ops->enable_intrs(ha); |
| 5814 | |
| 5815 | ha->isp_abort_cnt = 0; |
| 5816 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 5817 | |
Saurav Kashyap | 5329678 | 2011-05-10 11:30:06 -0700 | [diff] [blame] | 5818 | /* Update the firmware version */ |
Giridhar Malavali | 3173167 | 2011-08-16 11:31:54 -0700 | [diff] [blame] | 5819 | status = qla82xx_check_md_needed(vha); |
Saurav Kashyap | 5329678 | 2011-05-10 11:30:06 -0700 | [diff] [blame] | 5820 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5821 | if (ha->fce) { |
| 5822 | ha->flags.fce_enabled = 1; |
| 5823 | memset(ha->fce, 0, |
| 5824 | fce_calc_size(ha->fce_bufs)); |
| 5825 | rval = qla2x00_enable_fce_trace(vha, |
| 5826 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 5827 | &ha->fce_bufs); |
| 5828 | if (rval) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5829 | ql_log(ql_log_warn, vha, 0x8001, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5830 | "Unable to reinitialize FCE (%d).\n", |
| 5831 | rval); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5832 | ha->flags.fce_enabled = 0; |
| 5833 | } |
| 5834 | } |
| 5835 | |
| 5836 | if (ha->eft) { |
| 5837 | memset(ha->eft, 0, EFT_SIZE); |
| 5838 | rval = qla2x00_enable_eft_trace(vha, |
| 5839 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 5840 | if (rval) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5841 | ql_log(ql_log_warn, vha, 0x8010, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5842 | "Unable to reinitialize EFT (%d).\n", |
| 5843 | rval); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5844 | } |
| 5845 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5846 | } |
| 5847 | |
| 5848 | if (!status) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5849 | ql_dbg(ql_dbg_taskm, vha, 0x8011, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5850 | "qla82xx_restart_isp succeeded.\n"); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5851 | |
| 5852 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5853 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 5854 | if (vp->vp_idx) { |
| 5855 | atomic_inc(&vp->vref_count); |
| 5856 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5857 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5858 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5859 | |
| 5860 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5861 | atomic_dec(&vp->vref_count); |
| 5862 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5863 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5864 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5865 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5866 | } else { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5867 | ql_log(ql_log_warn, vha, 0x8016, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5868 | "qla82xx_restart_isp **** FAILED ****.\n"); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5869 | } |
| 5870 | |
| 5871 | return status; |
| 5872 | } |
| 5873 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5874 | void |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 5875 | qla81xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5876 | { |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 5877 | struct qla_hw_data *ha = vha->hw; |
| 5878 | |
| 5879 | if (!ql2xetsenable) |
| 5880 | return; |
| 5881 | |
| 5882 | /* Enable ETS Burst. */ |
| 5883 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
| 5884 | ha->fw_options[2] |= BIT_9; |
| 5885 | qla2x00_set_fw_options(vha, ha->fw_options); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5886 | } |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5887 | |
| 5888 | /* |
| 5889 | * qla24xx_get_fcp_prio |
| 5890 | * Gets the fcp cmd priority value for the logged in port. |
| 5891 | * Looks for a match of the port descriptors within |
| 5892 | * each of the fcp prio config entries. If a match is found, |
| 5893 | * the tag (priority) value is returned. |
| 5894 | * |
| 5895 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5896 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5897 | * fcport = port structure pointer. |
| 5898 | * |
| 5899 | * Return: |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 5900 | * non-zero (if found) |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5901 | * -1 (if not found) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5902 | * |
| 5903 | * Context: |
| 5904 | * Kernel context |
| 5905 | */ |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5906 | static int |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5907 | qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 5908 | { |
| 5909 | int i, entries; |
| 5910 | uint8_t pid_match, wwn_match; |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5911 | int priority; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5912 | uint32_t pid1, pid2; |
| 5913 | uint64_t wwn1, wwn2; |
| 5914 | struct qla_fcp_prio_entry *pri_entry; |
| 5915 | struct qla_hw_data *ha = vha->hw; |
| 5916 | |
| 5917 | if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled) |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5918 | return -1; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5919 | |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5920 | priority = -1; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5921 | entries = ha->fcp_prio_cfg->num_entries; |
| 5922 | pri_entry = &ha->fcp_prio_cfg->entry[0]; |
| 5923 | |
| 5924 | for (i = 0; i < entries; i++) { |
| 5925 | pid_match = wwn_match = 0; |
| 5926 | |
| 5927 | if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) { |
| 5928 | pri_entry++; |
| 5929 | continue; |
| 5930 | } |
| 5931 | |
| 5932 | /* check source pid for a match */ |
| 5933 | if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) { |
| 5934 | pid1 = pri_entry->src_pid & INVALID_PORT_ID; |
| 5935 | pid2 = vha->d_id.b24 & INVALID_PORT_ID; |
| 5936 | if (pid1 == INVALID_PORT_ID) |
| 5937 | pid_match++; |
| 5938 | else if (pid1 == pid2) |
| 5939 | pid_match++; |
| 5940 | } |
| 5941 | |
| 5942 | /* check destination pid for a match */ |
| 5943 | if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) { |
| 5944 | pid1 = pri_entry->dst_pid & INVALID_PORT_ID; |
| 5945 | pid2 = fcport->d_id.b24 & INVALID_PORT_ID; |
| 5946 | if (pid1 == INVALID_PORT_ID) |
| 5947 | pid_match++; |
| 5948 | else if (pid1 == pid2) |
| 5949 | pid_match++; |
| 5950 | } |
| 5951 | |
| 5952 | /* check source WWN for a match */ |
| 5953 | if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) { |
| 5954 | wwn1 = wwn_to_u64(vha->port_name); |
| 5955 | wwn2 = wwn_to_u64(pri_entry->src_wwpn); |
| 5956 | if (wwn2 == (uint64_t)-1) |
| 5957 | wwn_match++; |
| 5958 | else if (wwn1 == wwn2) |
| 5959 | wwn_match++; |
| 5960 | } |
| 5961 | |
| 5962 | /* check destination WWN for a match */ |
| 5963 | if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) { |
| 5964 | wwn1 = wwn_to_u64(fcport->port_name); |
| 5965 | wwn2 = wwn_to_u64(pri_entry->dst_wwpn); |
| 5966 | if (wwn2 == (uint64_t)-1) |
| 5967 | wwn_match++; |
| 5968 | else if (wwn1 == wwn2) |
| 5969 | wwn_match++; |
| 5970 | } |
| 5971 | |
| 5972 | if (pid_match == 2 || wwn_match == 2) { |
| 5973 | /* Found a matching entry */ |
| 5974 | if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID) |
| 5975 | priority = pri_entry->tag; |
| 5976 | break; |
| 5977 | } |
| 5978 | |
| 5979 | pri_entry++; |
| 5980 | } |
| 5981 | |
| 5982 | return priority; |
| 5983 | } |
| 5984 | |
| 5985 | /* |
| 5986 | * qla24xx_update_fcport_fcp_prio |
| 5987 | * Activates fcp priority for the logged in fc port |
| 5988 | * |
| 5989 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5990 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5991 | * fcp = port structure pointer. |
| 5992 | * |
| 5993 | * Return: |
| 5994 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 5995 | * |
| 5996 | * Context: |
| 5997 | * Kernel context. |
| 5998 | */ |
| 5999 | int |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 6000 | 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] | 6001 | { |
| 6002 | int ret; |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 6003 | int priority; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 6004 | uint16_t mb[5]; |
| 6005 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 6006 | if (fcport->port_type != FCT_TARGET || |
| 6007 | fcport->loop_id == FC_NO_LOOP_ID) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 6008 | return QLA_FUNCTION_FAILED; |
| 6009 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 6010 | priority = qla24xx_get_fcp_prio(vha, fcport); |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 6011 | if (priority < 0) |
| 6012 | return QLA_FUNCTION_FAILED; |
| 6013 | |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 6014 | if (IS_QLA82XX(vha->hw)) { |
| 6015 | fcport->fcp_prio = priority & 0xf; |
| 6016 | return QLA_SUCCESS; |
| 6017 | } |
| 6018 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 6019 | ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb); |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 6020 | if (ret == QLA_SUCCESS) { |
| 6021 | if (fcport->fcp_prio != priority) |
| 6022 | ql_dbg(ql_dbg_user, vha, 0x709e, |
| 6023 | "Updated FCP_CMND priority - value=%d loop_id=%d " |
| 6024 | "port_id=%02x%02x%02x.\n", priority, |
| 6025 | fcport->loop_id, fcport->d_id.b.domain, |
| 6026 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 6027 | fcport->fcp_prio = priority & 0xf; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 6028 | } else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6029 | ql_dbg(ql_dbg_user, vha, 0x704f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 6030 | "Unable to update FCP_CMND priority - ret=0x%x for " |
| 6031 | "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id, |
| 6032 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 6033 | fcport->d_id.b.al_pa); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 6034 | return ret; |
| 6035 | } |
| 6036 | |
| 6037 | /* |
| 6038 | * qla24xx_update_all_fcp_prio |
| 6039 | * Activates fcp priority for all the logged in ports |
| 6040 | * |
| 6041 | * Input: |
| 6042 | * ha = adapter block pointer. |
| 6043 | * |
| 6044 | * Return: |
| 6045 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 6046 | * |
| 6047 | * Context: |
| 6048 | * Kernel context. |
| 6049 | */ |
| 6050 | int |
| 6051 | qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha) |
| 6052 | { |
| 6053 | int ret; |
| 6054 | fc_port_t *fcport; |
| 6055 | |
| 6056 | ret = QLA_FUNCTION_FAILED; |
| 6057 | /* We need to set priority for all logged in ports */ |
| 6058 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 6059 | ret = qla24xx_update_fcport_fcp_prio(vha, fcport); |
| 6060 | |
| 6061 | return ret; |
| 6062 | } |