| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
| Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 2 | * QLogic Fibre Channel HBA Driver | 
| Andrew Vasquez | 07e264b | 2011-03-30 11:46:23 -0700 | [diff] [blame] | 3 | * Copyright (c)  2003-2011 QLogic Corporation | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * | 
| Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 5 | * See LICENSE.qla2xxx for copyright and licensing details. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ | 
|  | 7 | #include "qla_def.h" | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 8 | #include "qla_gbl.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 |  | 
|  | 10 | #include <linux/delay.h> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 11 | #include <linux/slab.h> | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 12 | #include <linux/vmalloc.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 |  | 
|  | 14 | #include "qla_devtbl.h" | 
|  | 15 |  | 
| David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 16 | #ifdef CONFIG_SPARC | 
|  | 17 | #include <asm/prom.h> | 
| David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 18 | #endif | 
|  | 19 |  | 
| Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 20 | #include <target/target_core_base.h> | 
|  | 21 | #include "qla_target.h" | 
|  | 22 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | /* | 
|  | 24 | *  QLogic ISP2x00 Hardware Support Function Prototypes. | 
|  | 25 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | static int qla2x00_isp_firmware(scsi_qla_host_t *); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | static int qla2x00_setup_chip(scsi_qla_host_t *); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | static int qla2x00_init_rings(scsi_qla_host_t *); | 
|  | 29 | static int qla2x00_fw_ready(scsi_qla_host_t *); | 
|  | 30 | static int qla2x00_configure_hba(scsi_qla_host_t *); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | static int qla2x00_configure_loop(scsi_qla_host_t *); | 
|  | 32 | static int qla2x00_configure_local_loop(scsi_qla_host_t *); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | static int qla2x00_configure_fabric(scsi_qla_host_t *); | 
|  | 34 | static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *, | 
|  | 36 | uint16_t *); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 |  | 
|  | 38 | static int qla2x00_restart_isp(scsi_qla_host_t *); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 |  | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 40 | static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *); | 
|  | 41 | static int qla84xx_init_chip(scsi_qla_host_t *); | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 42 | static int qla25xx_init_queues(struct qla_hw_data *); | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 43 |  | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 44 | /* SRB Extensions ---------------------------------------------------------- */ | 
|  | 45 |  | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 46 | void | 
|  | 47 | qla2x00_sp_timeout(unsigned long __data) | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 48 | { | 
|  | 49 | srb_t *sp = (srb_t *)__data; | 
| Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 50 | struct srb_iocb *iocb; | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 51 | fc_port_t *fcport = sp->fcport; | 
|  | 52 | struct qla_hw_data *ha = fcport->vha->hw; | 
|  | 53 | struct req_que *req; | 
|  | 54 | unsigned long flags; | 
|  | 55 |  | 
|  | 56 | spin_lock_irqsave(&ha->hardware_lock, flags); | 
|  | 57 | req = ha->req_q_map[0]; | 
|  | 58 | req->outstanding_cmds[sp->handle] = NULL; | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 59 | iocb = &sp->u.iocb_cmd; | 
| Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 60 | iocb->timeout(sp); | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 61 | sp->free(fcport->vha, sp); | 
| Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 62 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 63 | } | 
|  | 64 |  | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 65 | void | 
|  | 66 | qla2x00_sp_free(void *data, void *ptr) | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 67 | { | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 68 | srb_t *sp = (srb_t *)ptr; | 
|  | 69 | struct srb_iocb *iocb = &sp->u.iocb_cmd; | 
|  | 70 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 71 |  | 
| Chad Dupuis | 4d97cc5 | 2010-10-15 11:27:41 -0700 | [diff] [blame] | 72 | del_timer(&iocb->timer); | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 73 | mempool_free(sp, vha->hw->srb_mempool); | 
| Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 74 |  | 
|  | 75 | QLA_VHA_MARK_NOT_BUSY(vha); | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 76 | } | 
|  | 77 |  | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 78 | /* Asynchronous Login/Logout Routines -------------------------------------- */ | 
|  | 79 |  | 
| Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 80 | static inline unsigned long | 
|  | 81 | qla2x00_get_async_timeout(struct scsi_qla_host *vha) | 
|  | 82 | { | 
|  | 83 | unsigned long tmo; | 
|  | 84 | struct qla_hw_data *ha = vha->hw; | 
|  | 85 |  | 
|  | 86 | /* Firmware should use switch negotiated r_a_tov for timeout. */ | 
|  | 87 | tmo = ha->r_a_tov / 10 * 2; | 
|  | 88 | if (!IS_FWI2_CAPABLE(ha)) { | 
|  | 89 | /* | 
|  | 90 | * Except for earlier ISPs where the timeout is seeded from the | 
|  | 91 | * initialization control block. | 
|  | 92 | */ | 
|  | 93 | tmo = ha->login_timeout; | 
|  | 94 | } | 
|  | 95 | return tmo; | 
|  | 96 | } | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 97 |  | 
|  | 98 | static void | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 99 | qla2x00_async_iocb_timeout(void *data) | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 100 | { | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 101 | srb_t *sp = (srb_t *)data; | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 102 | fc_port_t *fcport = sp->fcport; | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 103 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 104 | ql_dbg(ql_dbg_disc, fcport->vha, 0x2071, | 
| Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 105 | "Async-%s timeout - hdl=%x portid=%02x%02x%02x.\n", | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 106 | sp->name, sp->handle, fcport->d_id.b.domain, fcport->d_id.b.area, | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 107 | fcport->d_id.b.al_pa); | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 108 |  | 
| Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 109 | fcport->flags &= ~FCF_ASYNC_SENT; | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 110 | if (sp->type == SRB_LOGIN_CMD) { | 
|  | 111 | struct srb_iocb *lio = &sp->u.iocb_cmd; | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 112 | qla2x00_post_async_logout_work(fcport->vha, fcport, NULL); | 
| Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 113 | /* Retry as needed. */ | 
|  | 114 | lio->u.logio.data[0] = MBS_COMMAND_ERROR; | 
|  | 115 | lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ? | 
|  | 116 | QLA_LOGIO_LOGIN_RETRIED : 0; | 
|  | 117 | qla2x00_post_async_login_done_work(fcport->vha, fcport, | 
|  | 118 | lio->u.logio.data); | 
|  | 119 | } | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 120 | } | 
|  | 121 |  | 
| Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 122 | static void | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 123 | qla2x00_async_login_sp_done(void *data, void *ptr, int res) | 
| Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 124 | { | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 125 | srb_t *sp = (srb_t *)ptr; | 
|  | 126 | struct srb_iocb *lio = &sp->u.iocb_cmd; | 
|  | 127 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; | 
| Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 128 |  | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 129 | if (!test_bit(UNLOADING, &vha->dpc_flags)) | 
|  | 130 | qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport, | 
|  | 131 | lio->u.logio.data); | 
|  | 132 | sp->free(sp->fcport->vha, sp); | 
| Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 133 | } | 
|  | 134 |  | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 135 | int | 
|  | 136 | qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport, | 
|  | 137 | uint16_t *data) | 
|  | 138 | { | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 139 | srb_t *sp; | 
| Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 140 | struct srb_iocb *lio; | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 141 | int rval; | 
|  | 142 |  | 
|  | 143 | rval = QLA_FUNCTION_FAILED; | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 144 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 145 | if (!sp) | 
|  | 146 | goto done; | 
|  | 147 |  | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 148 | sp->type = SRB_LOGIN_CMD; | 
|  | 149 | sp->name = "login"; | 
|  | 150 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); | 
|  | 151 |  | 
|  | 152 | lio = &sp->u.iocb_cmd; | 
| Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 153 | lio->timeout = qla2x00_async_iocb_timeout; | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 154 | sp->done = qla2x00_async_login_sp_done; | 
| Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 155 | lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI; | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 156 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) | 
| Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 157 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 158 | rval = qla2x00_start_sp(sp); | 
|  | 159 | if (rval != QLA_SUCCESS) | 
|  | 160 | goto done_free_sp; | 
|  | 161 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 162 | ql_dbg(ql_dbg_disc, vha, 0x2072, | 
| Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 163 | "Async-login - hdl=%x, loopid=%x portid=%02x%02x%02x " | 
|  | 164 | "retries=%d.\n", sp->handle, fcport->loop_id, | 
|  | 165 | fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa, | 
|  | 166 | fcport->login_retry); | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 167 | return rval; | 
|  | 168 |  | 
|  | 169 | done_free_sp: | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 170 | sp->free(fcport->vha, sp); | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 171 | done: | 
|  | 172 | return rval; | 
|  | 173 | } | 
|  | 174 |  | 
| Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 175 | static void | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 176 | qla2x00_async_logout_sp_done(void *data, void *ptr, int res) | 
| Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 177 | { | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 178 | srb_t *sp = (srb_t *)ptr; | 
|  | 179 | struct srb_iocb *lio = &sp->u.iocb_cmd; | 
|  | 180 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; | 
| Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 181 |  | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 182 | if (!test_bit(UNLOADING, &vha->dpc_flags)) | 
|  | 183 | qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport, | 
|  | 184 | lio->u.logio.data); | 
|  | 185 | sp->free(sp->fcport->vha, sp); | 
| Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 186 | } | 
|  | 187 |  | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 188 | int | 
|  | 189 | qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport) | 
|  | 190 | { | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 191 | srb_t *sp; | 
| Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 192 | struct srb_iocb *lio; | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 193 | int rval; | 
|  | 194 |  | 
|  | 195 | rval = QLA_FUNCTION_FAILED; | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 196 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 197 | if (!sp) | 
|  | 198 | goto done; | 
|  | 199 |  | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 200 | sp->type = SRB_LOGOUT_CMD; | 
|  | 201 | sp->name = "logout"; | 
|  | 202 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); | 
|  | 203 |  | 
|  | 204 | lio = &sp->u.iocb_cmd; | 
| Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 205 | lio->timeout = qla2x00_async_iocb_timeout; | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 206 | sp->done = qla2x00_async_logout_sp_done; | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 207 | rval = qla2x00_start_sp(sp); | 
|  | 208 | if (rval != QLA_SUCCESS) | 
|  | 209 | goto done_free_sp; | 
|  | 210 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 211 | ql_dbg(ql_dbg_disc, vha, 0x2070, | 
| Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 212 | "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x.\n", | 
|  | 213 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, | 
|  | 214 | fcport->d_id.b.area, fcport->d_id.b.al_pa); | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 215 | return rval; | 
|  | 216 |  | 
|  | 217 | done_free_sp: | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 218 | sp->free(fcport->vha, sp); | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 219 | done: | 
|  | 220 | return rval; | 
|  | 221 | } | 
|  | 222 |  | 
| Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 223 | static void | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 224 | qla2x00_async_adisc_sp_done(void *data, void *ptr, int res) | 
| Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 225 | { | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 226 | srb_t *sp = (srb_t *)ptr; | 
|  | 227 | struct srb_iocb *lio = &sp->u.iocb_cmd; | 
|  | 228 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; | 
| Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 229 |  | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 230 | if (!test_bit(UNLOADING, &vha->dpc_flags)) | 
|  | 231 | qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport, | 
|  | 232 | lio->u.logio.data); | 
|  | 233 | sp->free(sp->fcport->vha, sp); | 
| Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 234 | } | 
|  | 235 |  | 
|  | 236 | int | 
|  | 237 | qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport, | 
|  | 238 | uint16_t *data) | 
|  | 239 | { | 
| Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 240 | srb_t *sp; | 
| Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 241 | struct srb_iocb *lio; | 
| Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 242 | int rval; | 
|  | 243 |  | 
|  | 244 | rval = QLA_FUNCTION_FAILED; | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 245 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); | 
| Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 246 | if (!sp) | 
|  | 247 | goto done; | 
|  | 248 |  | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 249 | sp->type = SRB_ADISC_CMD; | 
|  | 250 | sp->name = "adisc"; | 
|  | 251 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); | 
|  | 252 |  | 
|  | 253 | lio = &sp->u.iocb_cmd; | 
| Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 254 | lio->timeout = qla2x00_async_iocb_timeout; | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 255 | sp->done = qla2x00_async_adisc_sp_done; | 
| Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 256 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) | 
| Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 257 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; | 
| Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 258 | rval = qla2x00_start_sp(sp); | 
|  | 259 | if (rval != QLA_SUCCESS) | 
|  | 260 | goto done_free_sp; | 
|  | 261 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 262 | ql_dbg(ql_dbg_disc, vha, 0x206f, | 
| Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 263 | "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n", | 
|  | 264 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, | 
|  | 265 | fcport->d_id.b.area, fcport->d_id.b.al_pa); | 
| Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 266 | return rval; | 
|  | 267 |  | 
|  | 268 | done_free_sp: | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 269 | sp->free(fcport->vha, sp); | 
| Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 270 | done: | 
|  | 271 | return rval; | 
|  | 272 | } | 
|  | 273 |  | 
| Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 274 | static void | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 275 | qla2x00_async_tm_cmd_done(void *data, void *ptr, int res) | 
| Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 276 | { | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 277 | srb_t *sp = (srb_t *)ptr; | 
|  | 278 | struct srb_iocb *iocb = &sp->u.iocb_cmd; | 
|  | 279 | struct scsi_qla_host *vha = (scsi_qla_host_t *)data; | 
|  | 280 | uint32_t flags; | 
|  | 281 | uint16_t lun; | 
|  | 282 | int rval; | 
| Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 283 |  | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 284 | if (!test_bit(UNLOADING, &vha->dpc_flags)) { | 
|  | 285 | flags = iocb->u.tmf.flags; | 
|  | 286 | lun = (uint16_t)iocb->u.tmf.lun; | 
|  | 287 |  | 
|  | 288 | /* Issue Marker IOCB */ | 
|  | 289 | rval = qla2x00_marker(vha, vha->hw->req_q_map[0], | 
|  | 290 | vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun, | 
|  | 291 | flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID); | 
|  | 292 |  | 
|  | 293 | if ((rval != QLA_SUCCESS) || iocb->u.tmf.data) { | 
|  | 294 | ql_dbg(ql_dbg_taskm, vha, 0x8030, | 
|  | 295 | "TM IOCB failed (%x).\n", rval); | 
|  | 296 | } | 
|  | 297 | } | 
|  | 298 | sp->free(sp->fcport->vha, sp); | 
| Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 299 | } | 
|  | 300 |  | 
|  | 301 | int | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 302 | qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t tm_flags, uint32_t lun, | 
| Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 303 | uint32_t tag) | 
|  | 304 | { | 
|  | 305 | struct scsi_qla_host *vha = fcport->vha; | 
| Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 306 | srb_t *sp; | 
| Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 307 | struct srb_iocb *tcf; | 
|  | 308 | int rval; | 
|  | 309 |  | 
|  | 310 | rval = QLA_FUNCTION_FAILED; | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 311 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); | 
| Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 312 | if (!sp) | 
|  | 313 | goto done; | 
|  | 314 |  | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 315 | sp->type = SRB_TM_CMD; | 
|  | 316 | sp->name = "tmf"; | 
|  | 317 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); | 
|  | 318 |  | 
|  | 319 | tcf = &sp->u.iocb_cmd; | 
|  | 320 | tcf->u.tmf.flags = tm_flags; | 
| Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 321 | tcf->u.tmf.lun = lun; | 
|  | 322 | tcf->u.tmf.data = tag; | 
|  | 323 | tcf->timeout = qla2x00_async_iocb_timeout; | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 324 | sp->done = qla2x00_async_tm_cmd_done; | 
| Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 325 |  | 
|  | 326 | rval = qla2x00_start_sp(sp); | 
|  | 327 | if (rval != QLA_SUCCESS) | 
|  | 328 | goto done_free_sp; | 
|  | 329 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 330 | ql_dbg(ql_dbg_taskm, vha, 0x802f, | 
| Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 331 | "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n", | 
|  | 332 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, | 
|  | 333 | fcport->d_id.b.area, fcport->d_id.b.al_pa); | 
| Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 334 | return rval; | 
|  | 335 |  | 
|  | 336 | done_free_sp: | 
| Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 337 | sp->free(fcport->vha, sp); | 
| Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 338 | done: | 
|  | 339 | return rval; | 
|  | 340 | } | 
|  | 341 |  | 
| Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 342 | void | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 343 | qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport, | 
|  | 344 | uint16_t *data) | 
|  | 345 | { | 
|  | 346 | int rval; | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 347 |  | 
|  | 348 | switch (data[0]) { | 
|  | 349 | case MBS_COMMAND_COMPLETE: | 
| Andrew Vasquez | a4f92a3 | 2011-03-30 11:46:31 -0700 | [diff] [blame] | 350 | /* | 
|  | 351 | * Driver must validate login state - If PRLI not complete, | 
|  | 352 | * force a relogin attempt via implicit LOGO, PLOGI, and PRLI | 
|  | 353 | * requests. | 
|  | 354 | */ | 
|  | 355 | rval = qla2x00_get_port_database(vha, fcport, 0); | 
| Arun Easi | 0eba25d | 2012-02-09 11:15:58 -0800 | [diff] [blame] | 356 | if (rval == QLA_NOT_LOGGED_IN) { | 
|  | 357 | fcport->flags &= ~FCF_ASYNC_SENT; | 
|  | 358 | fcport->flags |= FCF_LOGIN_NEEDED; | 
|  | 359 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); | 
|  | 360 | break; | 
|  | 361 | } | 
|  | 362 |  | 
| Andrew Vasquez | a4f92a3 | 2011-03-30 11:46:31 -0700 | [diff] [blame] | 363 | if (rval != QLA_SUCCESS) { | 
|  | 364 | qla2x00_post_async_logout_work(vha, fcport, NULL); | 
|  | 365 | qla2x00_post_async_login_work(vha, fcport, NULL); | 
|  | 366 | break; | 
|  | 367 | } | 
| Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 368 | if (fcport->flags & FCF_FCP2_DEVICE) { | 
| Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 369 | qla2x00_post_async_adisc_work(vha, fcport, data); | 
|  | 370 | break; | 
| Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 371 | } | 
|  | 372 | qla2x00_update_fcport(vha, fcport); | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 373 | break; | 
|  | 374 | case MBS_COMMAND_ERROR: | 
| Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 375 | fcport->flags &= ~FCF_ASYNC_SENT; | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 376 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) | 
|  | 377 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); | 
|  | 378 | else | 
| Andrew Vasquez | 80d7944 | 2011-03-30 11:46:17 -0700 | [diff] [blame] | 379 | qla2x00_mark_device_lost(vha, fcport, 1, 0); | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 380 | break; | 
|  | 381 | case MBS_PORT_ID_USED: | 
|  | 382 | fcport->loop_id = data[1]; | 
| Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 383 | qla2x00_post_async_logout_work(vha, fcport, NULL); | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 384 | qla2x00_post_async_login_work(vha, fcport, NULL); | 
|  | 385 | break; | 
|  | 386 | case MBS_LOOP_ID_USED: | 
|  | 387 | fcport->loop_id++; | 
|  | 388 | rval = qla2x00_find_new_loop_id(vha, fcport); | 
|  | 389 | if (rval != QLA_SUCCESS) { | 
| Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 390 | fcport->flags &= ~FCF_ASYNC_SENT; | 
| Andrew Vasquez | 80d7944 | 2011-03-30 11:46:17 -0700 | [diff] [blame] | 391 | qla2x00_mark_device_lost(vha, fcport, 1, 0); | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 392 | break; | 
|  | 393 | } | 
|  | 394 | qla2x00_post_async_login_work(vha, fcport, NULL); | 
|  | 395 | break; | 
|  | 396 | } | 
| Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 397 | return; | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 398 | } | 
|  | 399 |  | 
| Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 400 | void | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 401 | qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport, | 
|  | 402 | uint16_t *data) | 
|  | 403 | { | 
|  | 404 | qla2x00_mark_device_lost(vha, fcport, 1, 0); | 
| Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 405 | return; | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 406 | } | 
|  | 407 |  | 
| Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 408 | void | 
| Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 409 | qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport, | 
|  | 410 | uint16_t *data) | 
|  | 411 | { | 
|  | 412 | if (data[0] == MBS_COMMAND_COMPLETE) { | 
|  | 413 | qla2x00_update_fcport(vha, fcport); | 
|  | 414 |  | 
| Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 415 | return; | 
| Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 416 | } | 
|  | 417 |  | 
|  | 418 | /* Retry login. */ | 
|  | 419 | fcport->flags &= ~FCF_ASYNC_SENT; | 
|  | 420 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) | 
|  | 421 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); | 
|  | 422 | else | 
| Andrew Vasquez | 80d7944 | 2011-03-30 11:46:17 -0700 | [diff] [blame] | 423 | qla2x00_mark_device_lost(vha, fcport, 1, 0); | 
| Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 424 |  | 
| Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 425 | return; | 
| Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 426 | } | 
|  | 427 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | /****************************************************************************/ | 
|  | 429 | /*                QLogic ISP2x00 Hardware Support Functions.                */ | 
|  | 430 | /****************************************************************************/ | 
|  | 431 |  | 
|  | 432 | /* | 
|  | 433 | * qla2x00_initialize_adapter | 
|  | 434 | *      Initialize board. | 
|  | 435 | * | 
|  | 436 | * Input: | 
|  | 437 | *      ha = adapter block pointer. | 
|  | 438 | * | 
|  | 439 | * Returns: | 
|  | 440 | *      0 = success | 
|  | 441 | */ | 
|  | 442 | int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 443 | qla2x00_initialize_adapter(scsi_qla_host_t *vha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | { | 
|  | 445 | int	rval; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 446 | struct qla_hw_data *ha = vha->hw; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 447 | struct req_que *req = ha->req_q_map[0]; | 
| Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 448 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | /* Clear adapter flags. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 450 | vha->flags.online = 0; | 
| Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 451 | ha->flags.chip_reset_done = 0; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 452 | vha->flags.reset_active = 0; | 
| Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 453 | ha->flags.pci_channel_io_perm_failure = 0; | 
|  | 454 | ha->flags.eeh_busy = 0; | 
| Andrew Vasquez | 794a569 | 2010-12-21 16:00:21 -0800 | [diff] [blame] | 455 | ha->flags.thermal_supported = 1; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 456 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); | 
|  | 457 | atomic_set(&vha->loop_state, LOOP_DOWN); | 
|  | 458 | vha->device_flags = DFLG_NO_CABLE; | 
|  | 459 | vha->dpc_flags = 0; | 
|  | 460 | vha->flags.management_server_logged_in = 0; | 
|  | 461 | vha->marker_needed = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | ha->isp_abort_cnt = 0; | 
|  | 463 | ha->beacon_blink_led = 0; | 
|  | 464 |  | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 465 | set_bit(0, ha->req_qid_map); | 
|  | 466 | set_bit(0, ha->rsp_qid_map); | 
|  | 467 |  | 
| Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 468 | ql_dbg(ql_dbg_init, vha, 0x0040, | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 469 | "Configuring PCI space...\n"); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 470 | rval = ha->isp_ops->pci_config(vha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | if (rval) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 472 | ql_log(ql_log_warn, vha, 0x0044, | 
|  | 473 | "Unable to configure PCI space.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | return (rval); | 
|  | 475 | } | 
|  | 476 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 477 | ha->isp_ops->reset_chip(vha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 479 | rval = qla2xxx_get_flash_info(vha); | 
| Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 480 | if (rval) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 481 | ql_log(ql_log_fatal, vha, 0x004f, | 
|  | 482 | "Unable to validate FLASH data.\n"); | 
| Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 483 | return (rval); | 
|  | 484 | } | 
|  | 485 |  | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 486 | ha->isp_ops->get_flash_version(vha, req->ring); | 
| Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 487 | ql_dbg(ql_dbg_init, vha, 0x0061, | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 488 | "Configure NVRAM parameters...\n"); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 489 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 490 | ha->isp_ops->nvram_config(vha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 |  | 
| Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 492 | if (ha->flags.disable_serdes) { | 
|  | 493 | /* Mask HBA via NVRAM settings? */ | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 494 | ql_log(ql_log_info, vha, 0x0077, | 
|  | 495 | "Masking HBA WWPN " | 
| Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 496 | "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n", | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 497 | vha->port_name[0], vha->port_name[1], | 
|  | 498 | vha->port_name[2], vha->port_name[3], | 
|  | 499 | vha->port_name[4], vha->port_name[5], | 
|  | 500 | vha->port_name[6], vha->port_name[7]); | 
| Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 501 | return QLA_FUNCTION_FAILED; | 
|  | 502 | } | 
|  | 503 |  | 
| Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 504 | ql_dbg(ql_dbg_init, vha, 0x0078, | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 505 | "Verifying loaded RISC code...\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 507 | if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) { | 
|  | 508 | rval = ha->isp_ops->chip_diag(vha); | 
| Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 509 | if (rval) | 
|  | 510 | return (rval); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 511 | rval = qla2x00_setup_chip(vha); | 
| Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 512 | if (rval) | 
|  | 513 | return (rval); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | } | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 515 |  | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 516 | if (IS_QLA84XX(ha)) { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 517 | ha->cs84xx = qla84xx_get_chip(vha); | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 518 | if (!ha->cs84xx) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 519 | ql_log(ql_log_warn, vha, 0x00d0, | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 520 | "Unable to configure ISP84XX.\n"); | 
|  | 521 | return QLA_FUNCTION_FAILED; | 
|  | 522 | } | 
|  | 523 | } | 
| Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 524 |  | 
|  | 525 | if (qla_ini_mode_enabled(vha)) | 
|  | 526 | rval = qla2x00_init_rings(vha); | 
|  | 527 |  | 
| Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 528 | ha->flags.chip_reset_done = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 |  | 
| Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 530 | if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) { | 
| Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 531 | /* Issue verify 84xx FW IOCB to complete 84xx initialization */ | 
| Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 532 | rval = qla84xx_init_chip(vha); | 
|  | 533 | if (rval != QLA_SUCCESS) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 534 | ql_log(ql_log_warn, vha, 0x00d4, | 
|  | 535 | "Unable to initialize ISP84XX.\n"); | 
| Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 536 | qla84xx_put_chip(vha); | 
|  | 537 | } | 
|  | 538 | } | 
|  | 539 |  | 
| Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 540 | if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)) | 
|  | 541 | qla24xx_read_fcp_prio_cfg(vha); | 
| Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 542 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | return (rval); | 
|  | 544 | } | 
|  | 545 |  | 
|  | 546 | /** | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 547 | * qla2100_pci_config() - Setup ISP21xx PCI configuration registers. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | * @ha: HA context | 
|  | 549 | * | 
|  | 550 | * Returns 0 on success. | 
|  | 551 | */ | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 552 | int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 553 | qla2100_pci_config(scsi_qla_host_t *vha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | { | 
| Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 555 | uint16_t w; | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 556 | unsigned long flags; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 557 | struct qla_hw_data *ha = vha->hw; | 
| Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 558 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | pci_set_master(ha->pdev); | 
| Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 561 | pci_try_set_mwi(ha->pdev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); | 
| Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 564 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); | 
|  | 566 |  | 
| Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 567 | pci_disable_rom(ha->pdev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 |  | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 569 | /* Get PCI bus information. */ | 
|  | 570 | spin_lock_irqsave(&ha->hardware_lock, flags); | 
| Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 571 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 572 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
|  | 573 |  | 
|  | 574 | return QLA_SUCCESS; | 
|  | 575 | } | 
|  | 576 |  | 
|  | 577 | /** | 
|  | 578 | * qla2300_pci_config() - Setup ISP23xx PCI configuration registers. | 
|  | 579 | * @ha: HA context | 
|  | 580 | * | 
|  | 581 | * Returns 0 on success. | 
|  | 582 | */ | 
|  | 583 | int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 584 | qla2300_pci_config(scsi_qla_host_t *vha) | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 585 | { | 
| Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 586 | uint16_t	w; | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 587 | unsigned long   flags = 0; | 
|  | 588 | uint32_t	cnt; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 589 | struct qla_hw_data *ha = vha->hw; | 
| Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 590 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 591 |  | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 592 | pci_set_master(ha->pdev); | 
| Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 593 | pci_try_set_mwi(ha->pdev); | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 594 |  | 
|  | 595 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); | 
| Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 596 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 597 |  | 
|  | 598 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) | 
|  | 599 | w &= ~PCI_COMMAND_INTX_DISABLE; | 
| Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 600 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 601 |  | 
|  | 602 | /* | 
|  | 603 | * If this is a 2300 card and not 2312, reset the | 
|  | 604 | * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately, | 
|  | 605 | * the 2310 also reports itself as a 2300 so we need to get the | 
|  | 606 | * fb revision level -- a 6 indicates it really is a 2300 and | 
|  | 607 | * not a 2310. | 
|  | 608 | */ | 
|  | 609 | if (IS_QLA2300(ha)) { | 
|  | 610 | spin_lock_irqsave(&ha->hardware_lock, flags); | 
|  | 611 |  | 
|  | 612 | /* Pause RISC. */ | 
| Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 613 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 614 | for (cnt = 0; cnt < 30000; cnt++) { | 
| Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 615 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0) | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 616 | break; | 
|  | 617 |  | 
|  | 618 | udelay(10); | 
|  | 619 | } | 
|  | 620 |  | 
|  | 621 | /* Select FPM registers. */ | 
| Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 622 | WRT_REG_WORD(®->ctrl_status, 0x20); | 
|  | 623 | RD_REG_WORD(®->ctrl_status); | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 624 |  | 
|  | 625 | /* Get the fb rev level */ | 
| Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 626 | ha->fb_rev = RD_FB_CMD_REG(ha, reg); | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 627 |  | 
|  | 628 | if (ha->fb_rev == FPM_2300) | 
| Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 629 | pci_clear_mwi(ha->pdev); | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 630 |  | 
|  | 631 | /* Deselect FPM registers. */ | 
| Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 632 | WRT_REG_WORD(®->ctrl_status, 0x0); | 
|  | 633 | RD_REG_WORD(®->ctrl_status); | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 634 |  | 
|  | 635 | /* Release RISC module. */ | 
| Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 636 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 637 | for (cnt = 0; cnt < 30000; cnt++) { | 
| Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 638 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0) | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 639 | break; | 
|  | 640 |  | 
|  | 641 | udelay(10); | 
|  | 642 | } | 
|  | 643 |  | 
|  | 644 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
|  | 645 | } | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 646 |  | 
|  | 647 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); | 
|  | 648 |  | 
| Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 649 | pci_disable_rom(ha->pdev); | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 650 |  | 
|  | 651 | /* Get PCI bus information. */ | 
|  | 652 | spin_lock_irqsave(&ha->hardware_lock, flags); | 
| Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 653 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 654 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
|  | 655 |  | 
|  | 656 | return QLA_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | } | 
|  | 658 |  | 
|  | 659 | /** | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 660 | * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers. | 
|  | 661 | * @ha: HA context | 
|  | 662 | * | 
|  | 663 | * Returns 0 on success. | 
|  | 664 | */ | 
|  | 665 | int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 666 | qla24xx_pci_config(scsi_qla_host_t *vha) | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 667 | { | 
| Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 668 | uint16_t w; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 669 | unsigned long flags = 0; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 670 | struct qla_hw_data *ha = vha->hw; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 671 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 672 |  | 
|  | 673 | pci_set_master(ha->pdev); | 
| Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 674 | pci_try_set_mwi(ha->pdev); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 675 |  | 
|  | 676 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); | 
| Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 677 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 678 | w &= ~PCI_COMMAND_INTX_DISABLE; | 
|  | 679 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); | 
|  | 680 |  | 
|  | 681 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); | 
|  | 682 |  | 
|  | 683 | /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */ | 
| Andrew Vasquez | f85ec18 | 2007-07-19 15:06:01 -0700 | [diff] [blame] | 684 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX)) | 
|  | 685 | pcix_set_mmrbc(ha->pdev, 2048); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 686 |  | 
|  | 687 | /* PCIe -- adjust Maximum Read Request Size (2048). */ | 
| Andrew Vasquez | f85ec18 | 2007-07-19 15:06:01 -0700 | [diff] [blame] | 688 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP)) | 
|  | 689 | pcie_set_readrq(ha->pdev, 2048); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 690 |  | 
| Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 691 | pci_disable_rom(ha->pdev); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 692 |  | 
| Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 693 | ha->chip_revision = ha->pdev->revision; | 
| Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 694 |  | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 695 | /* Get PCI bus information. */ | 
|  | 696 | spin_lock_irqsave(&ha->hardware_lock, flags); | 
|  | 697 | ha->pci_attr = RD_REG_DWORD(®->ctrl_status); | 
|  | 698 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
|  | 699 |  | 
|  | 700 | return QLA_SUCCESS; | 
|  | 701 | } | 
|  | 702 |  | 
|  | 703 | /** | 
| Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 704 | * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers. | 
|  | 705 | * @ha: HA context | 
|  | 706 | * | 
|  | 707 | * Returns 0 on success. | 
|  | 708 | */ | 
|  | 709 | int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 710 | qla25xx_pci_config(scsi_qla_host_t *vha) | 
| Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 711 | { | 
|  | 712 | uint16_t w; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 713 | struct qla_hw_data *ha = vha->hw; | 
| Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 714 |  | 
|  | 715 | pci_set_master(ha->pdev); | 
|  | 716 | pci_try_set_mwi(ha->pdev); | 
|  | 717 |  | 
|  | 718 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); | 
|  | 719 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); | 
|  | 720 | w &= ~PCI_COMMAND_INTX_DISABLE; | 
|  | 721 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); | 
|  | 722 |  | 
|  | 723 | /* PCIe -- adjust Maximum Read Request Size (2048). */ | 
|  | 724 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP)) | 
|  | 725 | pcie_set_readrq(ha->pdev, 2048); | 
|  | 726 |  | 
| Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 727 | pci_disable_rom(ha->pdev); | 
| Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 728 |  | 
|  | 729 | ha->chip_revision = ha->pdev->revision; | 
|  | 730 |  | 
|  | 731 | return QLA_SUCCESS; | 
|  | 732 | } | 
|  | 733 |  | 
|  | 734 | /** | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | * qla2x00_isp_firmware() - Choose firmware image. | 
|  | 736 | * @ha: HA context | 
|  | 737 | * | 
|  | 738 | * Returns 0 on success. | 
|  | 739 | */ | 
|  | 740 | static int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 741 | qla2x00_isp_firmware(scsi_qla_host_t *vha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | { | 
|  | 743 | int  rval; | 
| Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 744 | uint16_t loop_id, topo, sw_cap; | 
|  | 745 | uint8_t domain, area, al_pa; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 746 | struct qla_hw_data *ha = vha->hw; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 |  | 
|  | 748 | /* Assume loading risc code */ | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 749 | rval = QLA_FUNCTION_FAILED; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 |  | 
|  | 751 | if (ha->flags.disable_risc_code_load) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 752 | ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 |  | 
|  | 754 | /* Verify checksum of loaded RISC code. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 755 | rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address); | 
| Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 756 | if (rval == QLA_SUCCESS) { | 
|  | 757 | /* And, verify we are not in ROM code. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 758 | rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa, | 
| Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 759 | &area, &domain, &topo, &sw_cap); | 
|  | 760 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | } | 
|  | 762 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 763 | if (rval) | 
|  | 764 | ql_dbg(ql_dbg_init, vha, 0x007a, | 
|  | 765 | "**** Load RISC code ****.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 |  | 
|  | 767 | return (rval); | 
|  | 768 | } | 
|  | 769 |  | 
|  | 770 | /** | 
|  | 771 | * qla2x00_reset_chip() - Reset ISP chip. | 
|  | 772 | * @ha: HA context | 
|  | 773 | * | 
|  | 774 | * Returns 0 on success. | 
|  | 775 | */ | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 776 | void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 777 | qla2x00_reset_chip(scsi_qla_host_t *vha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | { | 
|  | 779 | unsigned long   flags = 0; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 780 | struct qla_hw_data *ha = vha->hw; | 
| Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 781 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | uint32_t	cnt; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | uint16_t	cmd; | 
|  | 784 |  | 
| Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 785 | if (unlikely(pci_channel_offline(ha->pdev))) | 
|  | 786 | return; | 
|  | 787 |  | 
| Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 788 | ha->isp_ops->disable_intrs(ha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 |  | 
|  | 790 | spin_lock_irqsave(&ha->hardware_lock, flags); | 
|  | 791 |  | 
|  | 792 | /* Turn off master enable */ | 
|  | 793 | cmd = 0; | 
|  | 794 | pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd); | 
|  | 795 | cmd &= ~PCI_COMMAND_MASTER; | 
|  | 796 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); | 
|  | 797 |  | 
|  | 798 | if (!IS_QLA2100(ha)) { | 
|  | 799 | /* Pause RISC. */ | 
|  | 800 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); | 
|  | 801 | if (IS_QLA2200(ha) || IS_QLA2300(ha)) { | 
|  | 802 | for (cnt = 0; cnt < 30000; cnt++) { | 
|  | 803 | if ((RD_REG_WORD(®->hccr) & | 
|  | 804 | HCCR_RISC_PAUSE) != 0) | 
|  | 805 | break; | 
|  | 806 | udelay(100); | 
|  | 807 | } | 
|  | 808 | } else { | 
|  | 809 | RD_REG_WORD(®->hccr);	/* PCI Posting. */ | 
|  | 810 | udelay(10); | 
|  | 811 | } | 
|  | 812 |  | 
|  | 813 | /* Select FPM registers. */ | 
|  | 814 | WRT_REG_WORD(®->ctrl_status, 0x20); | 
|  | 815 | RD_REG_WORD(®->ctrl_status);		/* PCI Posting. */ | 
|  | 816 |  | 
|  | 817 | /* FPM Soft Reset. */ | 
|  | 818 | WRT_REG_WORD(®->fpm_diag_config, 0x100); | 
|  | 819 | RD_REG_WORD(®->fpm_diag_config);	/* PCI Posting. */ | 
|  | 820 |  | 
|  | 821 | /* Toggle Fpm Reset. */ | 
|  | 822 | if (!IS_QLA2200(ha)) { | 
|  | 823 | WRT_REG_WORD(®->fpm_diag_config, 0x0); | 
|  | 824 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ | 
|  | 825 | } | 
|  | 826 |  | 
|  | 827 | /* Select frame buffer registers. */ | 
|  | 828 | WRT_REG_WORD(®->ctrl_status, 0x10); | 
|  | 829 | RD_REG_WORD(®->ctrl_status);		/* PCI Posting. */ | 
|  | 830 |  | 
|  | 831 | /* Reset frame buffer FIFOs. */ | 
|  | 832 | if (IS_QLA2200(ha)) { | 
|  | 833 | WRT_FB_CMD_REG(ha, reg, 0xa000); | 
|  | 834 | RD_FB_CMD_REG(ha, reg);		/* PCI Posting. */ | 
|  | 835 | } else { | 
|  | 836 | WRT_FB_CMD_REG(ha, reg, 0x00fc); | 
|  | 837 |  | 
|  | 838 | /* Read back fb_cmd until zero or 3 seconds max */ | 
|  | 839 | for (cnt = 0; cnt < 3000; cnt++) { | 
|  | 840 | if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0) | 
|  | 841 | break; | 
|  | 842 | udelay(100); | 
|  | 843 | } | 
|  | 844 | } | 
|  | 845 |  | 
|  | 846 | /* Select RISC module registers. */ | 
|  | 847 | WRT_REG_WORD(®->ctrl_status, 0); | 
|  | 848 | RD_REG_WORD(®->ctrl_status);		/* PCI Posting. */ | 
|  | 849 |  | 
|  | 850 | /* Reset RISC processor. */ | 
|  | 851 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); | 
|  | 852 | RD_REG_WORD(®->hccr);		/* PCI Posting. */ | 
|  | 853 |  | 
|  | 854 | /* Release RISC processor. */ | 
|  | 855 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); | 
|  | 856 | RD_REG_WORD(®->hccr);		/* PCI Posting. */ | 
|  | 857 | } | 
|  | 858 |  | 
|  | 859 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); | 
|  | 860 | WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT); | 
|  | 861 |  | 
|  | 862 | /* Reset ISP chip. */ | 
|  | 863 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); | 
|  | 864 |  | 
|  | 865 | /* Wait for RISC to recover from reset. */ | 
|  | 866 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { | 
|  | 867 | /* | 
|  | 868 | * It is necessary to for a delay here since the card doesn't | 
|  | 869 | * respond to PCI reads during a reset. On some architectures | 
|  | 870 | * this will result in an MCA. | 
|  | 871 | */ | 
|  | 872 | udelay(20); | 
|  | 873 | for (cnt = 30000; cnt; cnt--) { | 
|  | 874 | if ((RD_REG_WORD(®->ctrl_status) & | 
|  | 875 | CSR_ISP_SOFT_RESET) == 0) | 
|  | 876 | break; | 
|  | 877 | udelay(100); | 
|  | 878 | } | 
|  | 879 | } else | 
|  | 880 | udelay(10); | 
|  | 881 |  | 
|  | 882 | /* Reset RISC processor. */ | 
|  | 883 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); | 
|  | 884 |  | 
|  | 885 | WRT_REG_WORD(®->semaphore, 0); | 
|  | 886 |  | 
|  | 887 | /* Release RISC processor. */ | 
|  | 888 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); | 
|  | 889 | RD_REG_WORD(®->hccr);			/* PCI Posting. */ | 
|  | 890 |  | 
|  | 891 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { | 
|  | 892 | for (cnt = 0; cnt < 30000; cnt++) { | 
| Andrew Vasquez | ffb39f0 | 2006-05-17 15:09:06 -0700 | [diff] [blame] | 893 | if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 |  | 
|  | 896 | udelay(100); | 
|  | 897 | } | 
|  | 898 | } else | 
|  | 899 | udelay(100); | 
|  | 900 |  | 
|  | 901 | /* Turn on master enable */ | 
|  | 902 | cmd |= PCI_COMMAND_MASTER; | 
|  | 903 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); | 
|  | 904 |  | 
|  | 905 | /* Disable RISC pause on FPM parity error. */ | 
|  | 906 | if (!IS_QLA2100(ha)) { | 
|  | 907 | WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE); | 
|  | 908 | RD_REG_WORD(®->hccr);		/* PCI Posting. */ | 
|  | 909 | } | 
|  | 910 |  | 
|  | 911 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
|  | 912 | } | 
|  | 913 |  | 
|  | 914 | /** | 
| Madhuranath Iyengar | b1d4698 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 915 | * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC. | 
|  | 916 | * | 
|  | 917 | * Returns 0 on success. | 
|  | 918 | */ | 
|  | 919 | int | 
|  | 920 | qla81xx_reset_mpi(scsi_qla_host_t *vha) | 
|  | 921 | { | 
|  | 922 | uint16_t mb[4] = {0x1010, 0, 1, 0}; | 
|  | 923 |  | 
| Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 924 | if (!IS_QLA81XX(vha->hw)) | 
|  | 925 | return QLA_SUCCESS; | 
|  | 926 |  | 
| Madhuranath Iyengar | b1d4698 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 927 | return qla81xx_write_mpi_register(vha, mb); | 
|  | 928 | } | 
|  | 929 |  | 
|  | 930 | /** | 
| Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 931 | * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC. | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 932 | * @ha: HA context | 
|  | 933 | * | 
|  | 934 | * Returns 0 on success. | 
|  | 935 | */ | 
| Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 936 | static inline void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 937 | qla24xx_reset_risc(scsi_qla_host_t *vha) | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 938 | { | 
|  | 939 | unsigned long flags = 0; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 940 | struct qla_hw_data *ha = vha->hw; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 941 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; | 
|  | 942 | uint32_t cnt, d2; | 
| Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 943 | uint16_t wd; | 
| Madhuranath Iyengar | b1d4698 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 944 | static int abts_cnt; /* ISP abort retry counts */ | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 945 |  | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 946 | spin_lock_irqsave(&ha->hardware_lock, flags); | 
|  | 947 |  | 
|  | 948 | /* Reset RISC. */ | 
|  | 949 | WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); | 
|  | 950 | for (cnt = 0; cnt < 30000; cnt++) { | 
|  | 951 | if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0) | 
|  | 952 | break; | 
|  | 953 |  | 
|  | 954 | udelay(10); | 
|  | 955 | } | 
|  | 956 |  | 
|  | 957 | WRT_REG_DWORD(®->ctrl_status, | 
|  | 958 | CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); | 
| Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 959 | pci_read_config_word(ha->pdev, PCI_COMMAND, &wd); | 
| Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 960 |  | 
| Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 961 | udelay(100); | 
| Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 962 | /* Wait for firmware to complete NVRAM accesses. */ | 
| Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 963 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); | 
|  | 964 | for (cnt = 10000 ; cnt && d2; cnt--) { | 
|  | 965 | udelay(5); | 
|  | 966 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); | 
|  | 967 | barrier(); | 
|  | 968 | } | 
|  | 969 |  | 
| Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 970 | /* Wait for soft-reset to complete. */ | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 971 | d2 = RD_REG_DWORD(®->ctrl_status); | 
|  | 972 | for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) { | 
|  | 973 | udelay(5); | 
|  | 974 | d2 = RD_REG_DWORD(®->ctrl_status); | 
|  | 975 | barrier(); | 
|  | 976 | } | 
|  | 977 |  | 
| Madhuranath Iyengar | b1d4698 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 978 | /* If required, do an MPI FW reset now */ | 
|  | 979 | if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) { | 
|  | 980 | if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) { | 
|  | 981 | if (++abts_cnt < 5) { | 
|  | 982 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | 
|  | 983 | set_bit(MPI_RESET_NEEDED, &vha->dpc_flags); | 
|  | 984 | } else { | 
|  | 985 | /* | 
|  | 986 | * We exhausted the ISP abort retries. We have to | 
|  | 987 | * set the board offline. | 
|  | 988 | */ | 
|  | 989 | abts_cnt = 0; | 
|  | 990 | vha->flags.online = 0; | 
|  | 991 | } | 
|  | 992 | } | 
|  | 993 | } | 
|  | 994 |  | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 995 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); | 
|  | 996 | RD_REG_DWORD(®->hccr); | 
|  | 997 |  | 
|  | 998 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); | 
|  | 999 | RD_REG_DWORD(®->hccr); | 
|  | 1000 |  | 
|  | 1001 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET); | 
|  | 1002 | RD_REG_DWORD(®->hccr); | 
|  | 1003 |  | 
|  | 1004 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); | 
|  | 1005 | for (cnt = 6000000 ; cnt && d2; cnt--) { | 
|  | 1006 | udelay(5); | 
|  | 1007 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); | 
|  | 1008 | barrier(); | 
|  | 1009 | } | 
|  | 1010 |  | 
|  | 1011 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
| Andrew Vasquez | 124f85e | 2009-01-05 11:18:06 -0800 | [diff] [blame] | 1012 |  | 
|  | 1013 | if (IS_NOPOLLING_TYPE(ha)) | 
|  | 1014 | ha->isp_ops->enable_intrs(ha); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1015 | } | 
|  | 1016 |  | 
|  | 1017 | /** | 
| Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1018 | * qla24xx_reset_chip() - Reset ISP24xx chip. | 
|  | 1019 | * @ha: HA context | 
|  | 1020 | * | 
|  | 1021 | * Returns 0 on success. | 
|  | 1022 | */ | 
|  | 1023 | void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1024 | qla24xx_reset_chip(scsi_qla_host_t *vha) | 
| Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1025 | { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1026 | struct qla_hw_data *ha = vha->hw; | 
| Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 1027 |  | 
|  | 1028 | if (pci_channel_offline(ha->pdev) && | 
|  | 1029 | ha->flags.pci_channel_io_perm_failure) { | 
|  | 1030 | return; | 
|  | 1031 | } | 
|  | 1032 |  | 
| Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1033 | ha->isp_ops->disable_intrs(ha); | 
| Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1034 |  | 
|  | 1035 | /* Perform RISC reset. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1036 | qla24xx_reset_risc(vha); | 
| Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1037 | } | 
|  | 1038 |  | 
|  | 1039 | /** | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | * qla2x00_chip_diag() - Test chip for proper operation. | 
|  | 1041 | * @ha: HA context | 
|  | 1042 | * | 
|  | 1043 | * Returns 0 on success. | 
|  | 1044 | */ | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1045 | int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1046 | qla2x00_chip_diag(scsi_qla_host_t *vha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | { | 
|  | 1048 | int		rval; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1049 | struct qla_hw_data *ha = vha->hw; | 
| Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1050 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | unsigned long	flags = 0; | 
|  | 1052 | uint16_t	data; | 
|  | 1053 | uint32_t	cnt; | 
|  | 1054 | uint16_t	mb[5]; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1055 | struct req_que *req = ha->req_q_map[0]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 |  | 
|  | 1057 | /* Assume a failed state */ | 
|  | 1058 | rval = QLA_FUNCTION_FAILED; | 
|  | 1059 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1060 | ql_dbg(ql_dbg_init, vha, 0x007b, | 
|  | 1061 | "Testing device at %lx.\n", (u_long)®->flash_address); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 |  | 
|  | 1063 | spin_lock_irqsave(&ha->hardware_lock, flags); | 
|  | 1064 |  | 
|  | 1065 | /* Reset ISP chip. */ | 
|  | 1066 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); | 
|  | 1067 |  | 
|  | 1068 | /* | 
|  | 1069 | * We need to have a delay here since the card will not respond while | 
|  | 1070 | * in reset causing an MCA on some architectures. | 
|  | 1071 | */ | 
|  | 1072 | udelay(20); | 
|  | 1073 | data = qla2x00_debounce_register(®->ctrl_status); | 
|  | 1074 | for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) { | 
|  | 1075 | udelay(5); | 
|  | 1076 | data = RD_REG_WORD(®->ctrl_status); | 
|  | 1077 | barrier(); | 
|  | 1078 | } | 
|  | 1079 |  | 
|  | 1080 | if (!cnt) | 
|  | 1081 | goto chip_diag_failed; | 
|  | 1082 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1083 | ql_dbg(ql_dbg_init, vha, 0x007c, | 
|  | 1084 | "Reset register cleared by chip reset.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 |  | 
|  | 1086 | /* Reset RISC processor. */ | 
|  | 1087 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); | 
|  | 1088 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); | 
|  | 1089 |  | 
|  | 1090 | /* Workaround for QLA2312 PCI parity error */ | 
|  | 1091 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { | 
|  | 1092 | data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0)); | 
|  | 1093 | for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) { | 
|  | 1094 | udelay(5); | 
|  | 1095 | data = RD_MAILBOX_REG(ha, reg, 0); | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1096 | barrier(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | } | 
|  | 1098 | } else | 
|  | 1099 | udelay(10); | 
|  | 1100 |  | 
|  | 1101 | if (!cnt) | 
|  | 1102 | goto chip_diag_failed; | 
|  | 1103 |  | 
|  | 1104 | /* Check product ID of chip */ | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1105 | 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] | 1106 |  | 
|  | 1107 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); | 
|  | 1108 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); | 
|  | 1109 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); | 
|  | 1110 | mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4)); | 
|  | 1111 | if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) || | 
|  | 1112 | mb[3] != PROD_ID_3) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1113 | ql_log(ql_log_warn, vha, 0x0062, | 
|  | 1114 | "Wrong product ID = 0x%x,0x%x,0x%x.\n", | 
|  | 1115 | mb[1], mb[2], mb[3]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 |  | 
|  | 1117 | goto chip_diag_failed; | 
|  | 1118 | } | 
|  | 1119 | ha->product_id[0] = mb[1]; | 
|  | 1120 | ha->product_id[1] = mb[2]; | 
|  | 1121 | ha->product_id[2] = mb[3]; | 
|  | 1122 | ha->product_id[3] = mb[4]; | 
|  | 1123 |  | 
|  | 1124 | /* Adjust fw RISC transfer size */ | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1125 | if (req->length > 1024) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024; | 
|  | 1127 | else | 
|  | 1128 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1129 | req->length; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 |  | 
|  | 1131 | if (IS_QLA2200(ha) && | 
|  | 1132 | RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) { | 
|  | 1133 | /* Limit firmware transfer size with a 2200A */ | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1134 | ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 |  | 
| andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1136 | ha->device_type |= DT_ISP2200A; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | ha->fw_transfer_size = 128; | 
|  | 1138 | } | 
|  | 1139 |  | 
|  | 1140 | /* Wrap Incoming Mailboxes Test. */ | 
|  | 1141 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
|  | 1142 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1143 | ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n"); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1144 | rval = qla2x00_mbx_reg_test(vha); | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1145 | if (rval) | 
|  | 1146 | ql_log(ql_log_warn, vha, 0x0080, | 
|  | 1147 | "Failed mailbox send register test.\n"); | 
|  | 1148 | else | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | /* Flag a successful rval */ | 
|  | 1150 | rval = QLA_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | spin_lock_irqsave(&ha->hardware_lock, flags); | 
|  | 1152 |  | 
|  | 1153 | chip_diag_failed: | 
|  | 1154 | if (rval) | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1155 | ql_log(ql_log_info, vha, 0x0081, | 
|  | 1156 | "Chip diagnostics **** FAILED ****.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 |  | 
|  | 1158 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
|  | 1159 |  | 
|  | 1160 | return (rval); | 
|  | 1161 | } | 
|  | 1162 |  | 
|  | 1163 | /** | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1164 | * qla24xx_chip_diag() - Test ISP24xx for proper operation. | 
|  | 1165 | * @ha: HA context | 
|  | 1166 | * | 
|  | 1167 | * Returns 0 on success. | 
|  | 1168 | */ | 
|  | 1169 | int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1170 | qla24xx_chip_diag(scsi_qla_host_t *vha) | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1171 | { | 
|  | 1172 | int rval; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1173 | struct qla_hw_data *ha = vha->hw; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1174 | struct req_que *req = ha->req_q_map[0]; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1175 |  | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1176 | if (IS_QLA82XX(ha)) | 
|  | 1177 | return QLA_SUCCESS; | 
|  | 1178 |  | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1179 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1180 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1181 | rval = qla2x00_mbx_reg_test(vha); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1182 | if (rval) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1183 | ql_log(ql_log_warn, vha, 0x0082, | 
|  | 1184 | "Failed mailbox send register test.\n"); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1185 | } else { | 
|  | 1186 | /* Flag a successful rval */ | 
|  | 1187 | rval = QLA_SUCCESS; | 
|  | 1188 | } | 
|  | 1189 |  | 
|  | 1190 | return rval; | 
|  | 1191 | } | 
|  | 1192 |  | 
| Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1193 | void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1194 | qla2x00_alloc_fw_dump(scsi_qla_host_t *vha) | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1195 | { | 
| Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1196 | int rval; | 
|  | 1197 | 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] | 1198 | eft_size, fce_size, mq_size; | 
| Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1199 | dma_addr_t tc_dma; | 
|  | 1200 | void *tc; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1201 | struct qla_hw_data *ha = vha->hw; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1202 | struct req_que *req = ha->req_q_map[0]; | 
|  | 1203 | struct rsp_que *rsp = ha->rsp_q_map[0]; | 
| Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 1204 |  | 
| Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1205 | if (ha->fw_dump) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1206 | ql_dbg(ql_dbg_init, vha, 0x00bd, | 
|  | 1207 | "Firmware dump already allocated.\n"); | 
| Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1208 | return; | 
| Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 1209 | } | 
|  | 1210 |  | 
| Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1211 | ha->fw_dumped = 0; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1212 | fixed_size = mem_size = eft_size = fce_size = mq_size = 0; | 
| Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1213 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { | 
|  | 1214 | fixed_size = sizeof(struct qla2100_fw_dump); | 
|  | 1215 | } else if (IS_QLA23XX(ha)) { | 
|  | 1216 | fixed_size = offsetof(struct qla2300_fw_dump, data_ram); | 
|  | 1217 | mem_size = (ha->fw_memory_size - 0x11000 + 1) * | 
|  | 1218 | sizeof(uint16_t); | 
| Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 1219 | } else if (IS_FWI2_CAPABLE(ha)) { | 
| Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1220 | if (IS_QLA83XX(ha)) | 
|  | 1221 | fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem); | 
|  | 1222 | else if (IS_QLA81XX(ha)) | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1223 | fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem); | 
|  | 1224 | else if (IS_QLA25XX(ha)) | 
|  | 1225 | fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem); | 
|  | 1226 | else | 
|  | 1227 | fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem); | 
| Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1228 | mem_size = (ha->fw_memory_size - 0x100000 + 1) * | 
|  | 1229 | sizeof(uint32_t); | 
| Giridhar Malavali | 050c9bb | 2012-02-09 11:15:33 -0800 | [diff] [blame] | 1230 | if (ha->mqenable) { | 
| Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1231 | if (!IS_QLA83XX(ha)) | 
|  | 1232 | mq_size = sizeof(struct qla2xxx_mq_chain); | 
| Giridhar Malavali | 050c9bb | 2012-02-09 11:15:33 -0800 | [diff] [blame] | 1233 | /* | 
|  | 1234 | * Allocate maximum buffer size for all queues. | 
|  | 1235 | * Resizing must be done at end-of-dump processing. | 
|  | 1236 | */ | 
|  | 1237 | mq_size += ha->max_req_queues * | 
|  | 1238 | (req->length * sizeof(request_t)); | 
|  | 1239 | mq_size += ha->max_rsp_queues * | 
|  | 1240 | (rsp->length * sizeof(response_t)); | 
|  | 1241 | } | 
| Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1242 | if (ha->tgt.atio_q_length) | 
|  | 1243 | mq_size += ha->tgt.atio_q_length * sizeof(request_t); | 
| Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1244 | /* Allocate memory for Fibre Channel Event Buffer. */ | 
| Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1245 | if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha)) | 
| Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1246 | goto try_eft; | 
|  | 1247 |  | 
|  | 1248 | tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma, | 
|  | 1249 | GFP_KERNEL); | 
|  | 1250 | if (!tc) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1251 | ql_log(ql_log_warn, vha, 0x00be, | 
|  | 1252 | "Unable to allocate (%d KB) for FCE.\n", | 
|  | 1253 | FCE_SIZE / 1024); | 
| Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 1254 | goto try_eft; | 
| Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1255 | } | 
|  | 1256 |  | 
|  | 1257 | memset(tc, 0, FCE_SIZE); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1258 | rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS, | 
| Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1259 | ha->fce_mb, &ha->fce_bufs); | 
|  | 1260 | if (rval) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1261 | ql_log(ql_log_warn, vha, 0x00bf, | 
|  | 1262 | "Unable to initialize FCE (%d).\n", rval); | 
| Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1263 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, | 
|  | 1264 | tc_dma); | 
|  | 1265 | ha->flags.fce_enabled = 0; | 
| Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 1266 | goto try_eft; | 
| Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1267 | } | 
| Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1268 | ql_dbg(ql_dbg_init, vha, 0x00c0, | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1269 | "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024); | 
| Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1270 |  | 
| Giridhar Malavali | 7d9dade | 2009-03-24 09:07:58 -0700 | [diff] [blame] | 1271 | fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE; | 
| Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1272 | ha->flags.fce_enabled = 1; | 
|  | 1273 | ha->fce_dma = tc_dma; | 
|  | 1274 | ha->fce = tc; | 
|  | 1275 | try_eft: | 
| Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1276 | /* Allocate memory for Extended Trace Buffer. */ | 
| Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1277 | tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma, | 
| Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1278 | GFP_KERNEL); | 
| Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1279 | if (!tc) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1280 | ql_log(ql_log_warn, vha, 0x00c1, | 
|  | 1281 | "Unable to allocate (%d KB) for EFT.\n", | 
|  | 1282 | EFT_SIZE / 1024); | 
| Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1283 | goto cont_alloc; | 
|  | 1284 | } | 
|  | 1285 |  | 
| Andrew Vasquez | fc44765 | 2008-01-17 09:02:18 -0800 | [diff] [blame] | 1286 | memset(tc, 0, EFT_SIZE); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1287 | rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS); | 
| Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1288 | if (rval) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1289 | ql_log(ql_log_warn, vha, 0x00c2, | 
|  | 1290 | "Unable to initialize EFT (%d).\n", rval); | 
| Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1291 | dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, | 
|  | 1292 | tc_dma); | 
| Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1293 | goto cont_alloc; | 
|  | 1294 | } | 
| Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1295 | ql_dbg(ql_dbg_init, vha, 0x00c3, | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1296 | "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024); | 
| Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1297 |  | 
|  | 1298 | eft_size = EFT_SIZE; | 
| Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1299 | ha->eft_dma = tc_dma; | 
|  | 1300 | ha->eft = tc; | 
| Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1301 | } | 
|  | 1302 | cont_alloc: | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1303 | req_q_size = req->length * sizeof(request_t); | 
|  | 1304 | rsp_q_size = rsp->length * sizeof(response_t); | 
| Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1305 |  | 
|  | 1306 | dump_size = offsetof(struct qla2xxx_fw_dump, isp); | 
| Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1307 | 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] | 1308 | ha->chain_offset = dump_size; | 
|  | 1309 | dump_size += mq_size + fce_size; | 
| Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1310 |  | 
| Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 1311 | ha->fw_dump = vmalloc(dump_size); | 
| Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1312 | if (!ha->fw_dump) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1313 | ql_log(ql_log_warn, vha, 0x00c4, | 
|  | 1314 | "Unable to allocate (%d KB) for firmware dump.\n", | 
|  | 1315 | dump_size / 1024); | 
| Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1316 |  | 
| Madhuranath Iyengar | e30d175 | 2010-10-15 11:27:46 -0700 | [diff] [blame] | 1317 | if (ha->fce) { | 
|  | 1318 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce, | 
|  | 1319 | ha->fce_dma); | 
|  | 1320 | ha->fce = NULL; | 
|  | 1321 | ha->fce_dma = 0; | 
|  | 1322 | } | 
|  | 1323 |  | 
| Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1324 | if (ha->eft) { | 
|  | 1325 | dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft, | 
|  | 1326 | ha->eft_dma); | 
|  | 1327 | ha->eft = NULL; | 
|  | 1328 | ha->eft_dma = 0; | 
|  | 1329 | } | 
|  | 1330 | return; | 
|  | 1331 | } | 
| Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1332 | ql_dbg(ql_dbg_init, vha, 0x00c5, | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1333 | "Allocated (%d KB) for firmware dump.\n", dump_size / 1024); | 
| Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1334 |  | 
|  | 1335 | ha->fw_dump_len = dump_size; | 
|  | 1336 | ha->fw_dump->signature[0] = 'Q'; | 
|  | 1337 | ha->fw_dump->signature[1] = 'L'; | 
|  | 1338 | ha->fw_dump->signature[2] = 'G'; | 
|  | 1339 | ha->fw_dump->signature[3] = 'C'; | 
|  | 1340 | ha->fw_dump->version = __constant_htonl(1); | 
|  | 1341 |  | 
|  | 1342 | ha->fw_dump->fixed_size = htonl(fixed_size); | 
|  | 1343 | ha->fw_dump->mem_size = htonl(mem_size); | 
|  | 1344 | ha->fw_dump->req_q_size = htonl(req_q_size); | 
|  | 1345 | ha->fw_dump->rsp_q_size = htonl(rsp_q_size); | 
|  | 1346 |  | 
|  | 1347 | ha->fw_dump->eft_size = htonl(eft_size); | 
|  | 1348 | ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma)); | 
|  | 1349 | ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma)); | 
|  | 1350 |  | 
|  | 1351 | ha->fw_dump->header_size = | 
|  | 1352 | htonl(offsetof(struct qla2xxx_fw_dump, isp)); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1353 | } | 
|  | 1354 |  | 
| Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1355 | static int | 
|  | 1356 | qla81xx_mpi_sync(scsi_qla_host_t *vha) | 
|  | 1357 | { | 
|  | 1358 | #define MPS_MASK	0xe0 | 
|  | 1359 | int rval; | 
|  | 1360 | uint16_t dc; | 
|  | 1361 | uint32_t dw; | 
| Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1362 |  | 
|  | 1363 | if (!IS_QLA81XX(vha->hw)) | 
|  | 1364 | return QLA_SUCCESS; | 
|  | 1365 |  | 
|  | 1366 | rval = qla2x00_write_ram_word(vha, 0x7c00, 1); | 
|  | 1367 | if (rval != QLA_SUCCESS) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1368 | ql_log(ql_log_warn, vha, 0x0105, | 
|  | 1369 | "Unable to acquire semaphore.\n"); | 
| Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1370 | goto done; | 
|  | 1371 | } | 
|  | 1372 |  | 
|  | 1373 | pci_read_config_word(vha->hw->pdev, 0x54, &dc); | 
|  | 1374 | rval = qla2x00_read_ram_word(vha, 0x7a15, &dw); | 
|  | 1375 | if (rval != QLA_SUCCESS) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1376 | ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n"); | 
| Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1377 | goto done_release; | 
|  | 1378 | } | 
|  | 1379 |  | 
|  | 1380 | dc &= MPS_MASK; | 
|  | 1381 | if (dc == (dw & MPS_MASK)) | 
|  | 1382 | goto done_release; | 
|  | 1383 |  | 
|  | 1384 | dw &= ~MPS_MASK; | 
|  | 1385 | dw |= dc; | 
|  | 1386 | rval = qla2x00_write_ram_word(vha, 0x7a15, dw); | 
|  | 1387 | if (rval != QLA_SUCCESS) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1388 | ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n"); | 
| Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1389 | } | 
|  | 1390 |  | 
|  | 1391 | done_release: | 
|  | 1392 | rval = qla2x00_write_ram_word(vha, 0x7c00, 0); | 
|  | 1393 | if (rval != QLA_SUCCESS) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1394 | ql_log(ql_log_warn, vha, 0x006d, | 
|  | 1395 | "Unable to release semaphore.\n"); | 
| Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1396 | } | 
|  | 1397 |  | 
|  | 1398 | done: | 
|  | 1399 | return rval; | 
|  | 1400 | } | 
|  | 1401 |  | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1402 | /** | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | * qla2x00_setup_chip() - Load and start RISC firmware. | 
|  | 1404 | * @ha: HA context | 
|  | 1405 | * | 
|  | 1406 | * Returns 0 on success. | 
|  | 1407 | */ | 
|  | 1408 | static int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1409 | qla2x00_setup_chip(scsi_qla_host_t *vha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | { | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1411 | int rval; | 
|  | 1412 | uint32_t srisc_address = 0; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1413 | struct qla_hw_data *ha = vha->hw; | 
| Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1414 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; | 
|  | 1415 | unsigned long flags; | 
| Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 1416 | uint16_t fw_major_version; | 
| Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1417 |  | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1418 | if (IS_QLA82XX(ha)) { | 
|  | 1419 | rval = ha->isp_ops->load_risc(vha, &srisc_address); | 
| Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 1420 | if (rval == QLA_SUCCESS) { | 
|  | 1421 | qla2x00_stop_firmware(vha); | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1422 | goto enable_82xx_npiv; | 
| Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 1423 | } else | 
| Giridhar Malavali | b963752 | 2010-05-28 15:08:15 -0700 | [diff] [blame] | 1424 | goto failed; | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1425 | } | 
|  | 1426 |  | 
| Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1427 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { | 
|  | 1428 | /* Disable SRAM, Instruction RAM and GP RAM parity.  */ | 
|  | 1429 | spin_lock_irqsave(&ha->hardware_lock, flags); | 
|  | 1430 | WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0)); | 
|  | 1431 | RD_REG_WORD(®->hccr); | 
|  | 1432 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
|  | 1433 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 |  | 
| Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1435 | qla81xx_mpi_sync(vha); | 
|  | 1436 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | /* Load firmware sequences */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1438 | rval = ha->isp_ops->load_risc(vha, &srisc_address); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1439 | if (rval == QLA_SUCCESS) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1440 | ql_dbg(ql_dbg_init, vha, 0x00c9, | 
|  | 1441 | "Verifying Checksum of loaded RISC code.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1443 | rval = qla2x00_verify_checksum(vha, srisc_address); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | if (rval == QLA_SUCCESS) { | 
|  | 1445 | /* Start firmware execution. */ | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1446 | ql_dbg(ql_dbg_init, vha, 0x00ca, | 
|  | 1447 | "Starting firmware.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1449 | rval = qla2x00_execute_fw(vha, srisc_address); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | /* Retrieve firmware information. */ | 
| Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 1451 | if (rval == QLA_SUCCESS) { | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1452 | enable_82xx_npiv: | 
| Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 1453 | fw_major_version = ha->fw_major_version; | 
| Giridhar Malavali | 3173167 | 2011-08-16 11:31:54 -0700 | [diff] [blame] | 1454 | if (IS_QLA82XX(ha)) | 
|  | 1455 | qla82xx_check_md_needed(vha); | 
| Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1456 | else | 
|  | 1457 | rval = qla2x00_get_fw_version(vha); | 
| Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 1458 | if (rval != QLA_SUCCESS) | 
|  | 1459 | goto failed; | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1460 | ha->flags.npiv_supported = 0; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1461 | if (IS_QLA2XXX_MIDTYPE(ha) && | 
| Mike Hernandez | 946fb89 | 2008-08-13 21:36:59 -0700 | [diff] [blame] | 1462 | (ha->fw_attributes & BIT_2)) { | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1463 | ha->flags.npiv_supported = 1; | 
| Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 1464 | if ((!ha->max_npiv_vports) || | 
|  | 1465 | ((ha->max_npiv_vports + 1) % | 
| Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 1466 | MIN_MULTI_ID_FABRIC)) | 
| Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 1467 | ha->max_npiv_vports = | 
| Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 1468 | MIN_MULTI_ID_FABRIC - 1; | 
| Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 1469 | } | 
| Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 1470 | qla2x00_get_resource_cnts(vha, NULL, | 
|  | 1471 | &ha->fw_xcb_count, NULL, NULL, | 
| Andrew Vasquez | f3a0a77 | 2009-10-13 15:16:49 -0700 | [diff] [blame] | 1472 | &ha->max_npiv_vports, NULL); | 
| Andrew Vasquez | d743de6 | 2009-03-24 09:08:15 -0700 | [diff] [blame] | 1473 |  | 
| Saurav Kashyap | be5ea3c | 2011-11-18 09:02:11 -0800 | [diff] [blame] | 1474 | if (!fw_major_version && ql2xallocfwdump | 
|  | 1475 | && !IS_QLA82XX(ha)) | 
| Giridhar Malavali | 08de284 | 2011-08-16 11:31:44 -0700 | [diff] [blame] | 1476 | qla2x00_alloc_fw_dump(vha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | } | 
|  | 1478 | } else { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1479 | ql_log(ql_log_fatal, vha, 0x00cd, | 
|  | 1480 | "ISP Firmware failed checksum.\n"); | 
|  | 1481 | goto failed; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | } | 
|  | 1483 | } | 
|  | 1484 |  | 
| Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1485 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { | 
|  | 1486 | /* Enable proper parity. */ | 
|  | 1487 | spin_lock_irqsave(&ha->hardware_lock, flags); | 
|  | 1488 | if (IS_QLA2300(ha)) | 
|  | 1489 | /* SRAM parity */ | 
|  | 1490 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1); | 
|  | 1491 | else | 
|  | 1492 | /* SRAM, Instruction RAM and GP RAM parity */ | 
|  | 1493 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7); | 
|  | 1494 | RD_REG_WORD(®->hccr); | 
|  | 1495 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
|  | 1496 | } | 
|  | 1497 |  | 
| Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1498 | if (IS_QLA83XX(ha)) | 
|  | 1499 | goto skip_fac_check; | 
|  | 1500 |  | 
| Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1501 | if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) { | 
|  | 1502 | uint32_t size; | 
|  | 1503 |  | 
|  | 1504 | rval = qla81xx_fac_get_sector_size(vha, &size); | 
|  | 1505 | if (rval == QLA_SUCCESS) { | 
|  | 1506 | ha->flags.fac_supported = 1; | 
|  | 1507 | ha->fdt_block_size = size << 2; | 
|  | 1508 | } else { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1509 | ql_log(ql_log_warn, vha, 0x00ce, | 
| Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1510 | "Unsupported FAC firmware (%d.%02d.%02d).\n", | 
|  | 1511 | ha->fw_major_version, ha->fw_minor_version, | 
|  | 1512 | ha->fw_subminor_version); | 
| Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1513 | skip_fac_check: | 
|  | 1514 | if (IS_QLA83XX(ha)) { | 
|  | 1515 | ha->flags.fac_supported = 0; | 
|  | 1516 | rval = QLA_SUCCESS; | 
|  | 1517 | } | 
| Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1518 | } | 
|  | 1519 | } | 
| Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 1520 | failed: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | if (rval) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1522 | ql_log(ql_log_fatal, vha, 0x00cf, | 
|  | 1523 | "Setup chip ****FAILED****.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | } | 
|  | 1525 |  | 
|  | 1526 | return (rval); | 
|  | 1527 | } | 
|  | 1528 |  | 
|  | 1529 | /** | 
|  | 1530 | * qla2x00_init_response_q_entries() - Initializes response queue entries. | 
|  | 1531 | * @ha: HA context | 
|  | 1532 | * | 
|  | 1533 | * Beginning of request ring has initialization control block already built | 
|  | 1534 | * by nvram config routine. | 
|  | 1535 | * | 
|  | 1536 | * Returns 0 on success. | 
|  | 1537 | */ | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1538 | void | 
|  | 1539 | qla2x00_init_response_q_entries(struct rsp_que *rsp) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | { | 
|  | 1541 | uint16_t cnt; | 
|  | 1542 | response_t *pkt; | 
|  | 1543 |  | 
| Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1544 | rsp->ring_ptr = rsp->ring; | 
|  | 1545 | rsp->ring_index    = 0; | 
|  | 1546 | rsp->status_srb = NULL; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1547 | pkt = rsp->ring_ptr; | 
|  | 1548 | for (cnt = 0; cnt < rsp->length; cnt++) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | pkt->signature = RESPONSE_PROCESSED; | 
|  | 1550 | pkt++; | 
|  | 1551 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | } | 
|  | 1553 |  | 
|  | 1554 | /** | 
|  | 1555 | * qla2x00_update_fw_options() - Read and process firmware options. | 
|  | 1556 | * @ha: HA context | 
|  | 1557 | * | 
|  | 1558 | * Returns 0 on success. | 
|  | 1559 | */ | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1560 | void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1561 | qla2x00_update_fw_options(scsi_qla_host_t *vha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1562 | { | 
|  | 1563 | uint16_t swing, emphasis, tx_sens, rx_sens; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1564 | struct qla_hw_data *ha = vha->hw; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 |  | 
|  | 1566 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1567 | qla2x00_get_fw_options(vha, ha->fw_options); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 |  | 
|  | 1569 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) | 
|  | 1570 | return; | 
|  | 1571 |  | 
|  | 1572 | /* Serial Link options. */ | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1573 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115, | 
|  | 1574 | "Serial link options.\n"); | 
|  | 1575 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109, | 
|  | 1576 | (uint8_t *)&ha->fw_seriallink_options, | 
|  | 1577 | sizeof(ha->fw_seriallink_options)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 |  | 
|  | 1579 | ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING; | 
|  | 1580 | if (ha->fw_seriallink_options[3] & BIT_2) { | 
|  | 1581 | ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING; | 
|  | 1582 |  | 
|  | 1583 | /*  1G settings */ | 
|  | 1584 | swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0); | 
|  | 1585 | emphasis = (ha->fw_seriallink_options[2] & | 
|  | 1586 | (BIT_4 | BIT_3)) >> 3; | 
|  | 1587 | tx_sens = ha->fw_seriallink_options[0] & | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1588 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | rx_sens = (ha->fw_seriallink_options[0] & | 
|  | 1590 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; | 
|  | 1591 | ha->fw_options[10] = (emphasis << 14) | (swing << 8); | 
|  | 1592 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { | 
|  | 1593 | if (rx_sens == 0x0) | 
|  | 1594 | rx_sens = 0x3; | 
|  | 1595 | ha->fw_options[10] |= (tx_sens << 4) | rx_sens; | 
|  | 1596 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) | 
|  | 1597 | ha->fw_options[10] |= BIT_5 | | 
|  | 1598 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | | 
|  | 1599 | (tx_sens & (BIT_1 | BIT_0)); | 
|  | 1600 |  | 
|  | 1601 | /*  2G settings */ | 
|  | 1602 | swing = (ha->fw_seriallink_options[2] & | 
|  | 1603 | (BIT_7 | BIT_6 | BIT_5)) >> 5; | 
|  | 1604 | emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0); | 
|  | 1605 | tx_sens = ha->fw_seriallink_options[1] & | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1606 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1607 | rx_sens = (ha->fw_seriallink_options[1] & | 
|  | 1608 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; | 
|  | 1609 | ha->fw_options[11] = (emphasis << 14) | (swing << 8); | 
|  | 1610 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { | 
|  | 1611 | if (rx_sens == 0x0) | 
|  | 1612 | rx_sens = 0x3; | 
|  | 1613 | ha->fw_options[11] |= (tx_sens << 4) | rx_sens; | 
|  | 1614 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) | 
|  | 1615 | ha->fw_options[11] |= BIT_5 | | 
|  | 1616 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | | 
|  | 1617 | (tx_sens & (BIT_1 | BIT_0)); | 
|  | 1618 | } | 
|  | 1619 |  | 
|  | 1620 | /* FCP2 options. */ | 
|  | 1621 | /*  Return command IOCBs without waiting for an ABTS to complete. */ | 
|  | 1622 | ha->fw_options[3] |= BIT_13; | 
|  | 1623 |  | 
|  | 1624 | /* LED scheme. */ | 
|  | 1625 | if (ha->flags.enable_led_scheme) | 
|  | 1626 | ha->fw_options[2] |= BIT_12; | 
|  | 1627 |  | 
| andrew.vasquez@qlogic.com | 48c02fd | 2006-03-09 14:27:18 -0800 | [diff] [blame] | 1628 | /* Detect ISP6312. */ | 
|  | 1629 | if (IS_QLA6312(ha)) | 
|  | 1630 | ha->fw_options[2] |= BIT_13; | 
|  | 1631 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | /* Update firmware options. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1633 | qla2x00_set_fw_options(vha, ha->fw_options); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | } | 
|  | 1635 |  | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1636 | void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1637 | qla24xx_update_fw_options(scsi_qla_host_t *vha) | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1638 | { | 
|  | 1639 | int rval; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1640 | struct qla_hw_data *ha = vha->hw; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1641 |  | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1642 | if (IS_QLA82XX(ha)) | 
|  | 1643 | return; | 
|  | 1644 |  | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1645 | /* Update Serial Link options. */ | 
| andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 1646 | if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0) | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1647 | return; | 
|  | 1648 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1649 | rval = qla2x00_set_serdes_params(vha, | 
| andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 1650 | le16_to_cpu(ha->fw_seriallink_options24[1]), | 
|  | 1651 | le16_to_cpu(ha->fw_seriallink_options24[2]), | 
|  | 1652 | le16_to_cpu(ha->fw_seriallink_options24[3])); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1653 | if (rval != QLA_SUCCESS) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1654 | ql_log(ql_log_warn, vha, 0x0104, | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1655 | "Unable to update Serial Link options (%x).\n", rval); | 
|  | 1656 | } | 
|  | 1657 | } | 
|  | 1658 |  | 
|  | 1659 | void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1660 | qla2x00_config_rings(struct scsi_qla_host *vha) | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1661 | { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1662 | struct qla_hw_data *ha = vha->hw; | 
| Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1663 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1664 | struct req_que *req = ha->req_q_map[0]; | 
|  | 1665 | struct rsp_que *rsp = ha->rsp_q_map[0]; | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1666 |  | 
|  | 1667 | /* Setup ring parameters in initialization control block. */ | 
|  | 1668 | ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0); | 
|  | 1669 | ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1670 | ha->init_cb->request_q_length = cpu_to_le16(req->length); | 
|  | 1671 | ha->init_cb->response_q_length = cpu_to_le16(rsp->length); | 
|  | 1672 | ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); | 
|  | 1673 | ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); | 
|  | 1674 | ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); | 
|  | 1675 | 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] | 1676 |  | 
|  | 1677 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0); | 
|  | 1678 | WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0); | 
|  | 1679 | WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0); | 
|  | 1680 | WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0); | 
|  | 1681 | RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg));		/* PCI Posting. */ | 
|  | 1682 | } | 
|  | 1683 |  | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1684 | void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1685 | qla24xx_config_rings(struct scsi_qla_host *vha) | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1686 | { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1687 | struct qla_hw_data *ha = vha->hw; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1688 | device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0); | 
|  | 1689 | struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp; | 
|  | 1690 | struct qla_msix_entry *msix; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1691 | struct init_cb_24xx *icb; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1692 | uint16_t rid = 0; | 
|  | 1693 | struct req_que *req = ha->req_q_map[0]; | 
|  | 1694 | struct rsp_que *rsp = ha->rsp_q_map[0]; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1695 |  | 
| Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1696 | /* Setup ring parameters in initialization control block. */ | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1697 | icb = (struct init_cb_24xx *)ha->init_cb; | 
|  | 1698 | icb->request_q_outpointer = __constant_cpu_to_le16(0); | 
|  | 1699 | icb->response_q_inpointer = __constant_cpu_to_le16(0); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1700 | icb->request_q_length = cpu_to_le16(req->length); | 
|  | 1701 | icb->response_q_length = cpu_to_le16(rsp->length); | 
|  | 1702 | icb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); | 
|  | 1703 | icb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); | 
|  | 1704 | icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); | 
|  | 1705 | icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma)); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1706 |  | 
| Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1707 | /* Setup ATIO queue dma pointers for target mode */ | 
|  | 1708 | icb->atio_q_inpointer = __constant_cpu_to_le16(0); | 
|  | 1709 | icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length); | 
|  | 1710 | icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma)); | 
|  | 1711 | icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma)); | 
|  | 1712 |  | 
| Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1713 | if (ha->mqenable || IS_QLA83XX(ha)) { | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1714 | icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS); | 
|  | 1715 | icb->rid = __constant_cpu_to_le16(rid); | 
|  | 1716 | if (ha->flags.msix_enabled) { | 
|  | 1717 | msix = &ha->msix_entries[1]; | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1718 | ql_dbg(ql_dbg_init, vha, 0x00fd, | 
|  | 1719 | "Registering vector 0x%x for base que.\n", | 
|  | 1720 | msix->entry); | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1721 | icb->msix = cpu_to_le16(msix->entry); | 
|  | 1722 | } | 
|  | 1723 | /* Use alternate PCI bus number */ | 
|  | 1724 | if (MSB(rid)) | 
|  | 1725 | icb->firmware_options_2 |= | 
|  | 1726 | __constant_cpu_to_le32(BIT_19); | 
|  | 1727 | /* Use alternate PCI devfn */ | 
|  | 1728 | if (LSB(rid)) | 
|  | 1729 | icb->firmware_options_2 |= | 
|  | 1730 | __constant_cpu_to_le32(BIT_18); | 
|  | 1731 |  | 
| Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 1732 | /* Use Disable MSIX Handshake mode for capable adapters */ | 
| Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1733 | if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) && | 
|  | 1734 | (ha->flags.msix_enabled)) { | 
| Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 1735 | icb->firmware_options_2 &= | 
|  | 1736 | __constant_cpu_to_le32(~BIT_22); | 
|  | 1737 | ha->flags.disable_msix_handshake = 1; | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1738 | ql_dbg(ql_dbg_init, vha, 0x00fe, | 
|  | 1739 | "MSIX Handshake Disable Mode turned on.\n"); | 
| Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 1740 | } else { | 
|  | 1741 | icb->firmware_options_2 |= | 
|  | 1742 | __constant_cpu_to_le32(BIT_22); | 
|  | 1743 | } | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1744 | icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23); | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1745 |  | 
|  | 1746 | WRT_REG_DWORD(®->isp25mq.req_q_in, 0); | 
|  | 1747 | WRT_REG_DWORD(®->isp25mq.req_q_out, 0); | 
|  | 1748 | WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0); | 
|  | 1749 | WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0); | 
|  | 1750 | } else { | 
|  | 1751 | WRT_REG_DWORD(®->isp24.req_q_in, 0); | 
|  | 1752 | WRT_REG_DWORD(®->isp24.req_q_out, 0); | 
|  | 1753 | WRT_REG_DWORD(®->isp24.rsp_q_in, 0); | 
|  | 1754 | WRT_REG_DWORD(®->isp24.rsp_q_out, 0); | 
|  | 1755 | } | 
| Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1756 | qlt_24xx_config_rings(vha, reg); | 
|  | 1757 |  | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1758 | /* PCI posting */ | 
|  | 1759 | RD_REG_DWORD(&ioreg->hccr); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1760 | } | 
|  | 1761 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 | /** | 
|  | 1763 | * qla2x00_init_rings() - Initializes firmware. | 
|  | 1764 | * @ha: HA context | 
|  | 1765 | * | 
|  | 1766 | * Beginning of request ring has initialization control block already built | 
|  | 1767 | * by nvram config routine. | 
|  | 1768 | * | 
|  | 1769 | * Returns 0 on success. | 
|  | 1770 | */ | 
|  | 1771 | static int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1772 | qla2x00_init_rings(scsi_qla_host_t *vha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | { | 
|  | 1774 | int	rval; | 
|  | 1775 | unsigned long flags = 0; | 
| Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1776 | int cnt, que; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1777 | struct qla_hw_data *ha = vha->hw; | 
| Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1778 | struct req_que *req; | 
|  | 1779 | struct rsp_que *rsp; | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1780 | struct mid_init_cb_24xx *mid_init_cb = | 
|  | 1781 | (struct mid_init_cb_24xx *) ha->init_cb; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1782 |  | 
|  | 1783 | spin_lock_irqsave(&ha->hardware_lock, flags); | 
|  | 1784 |  | 
|  | 1785 | /* Clear outstanding commands array. */ | 
| Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1786 | for (que = 0; que < ha->max_req_queues; que++) { | 
| Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1787 | req = ha->req_q_map[que]; | 
|  | 1788 | if (!req) | 
|  | 1789 | continue; | 
| Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1790 | for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) | 
| Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1791 | req->outstanding_cmds[cnt] = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 |  | 
| Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1793 | req->current_outstanding_cmd = 1; | 
| Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1794 |  | 
|  | 1795 | /* Initialize firmware. */ | 
|  | 1796 | req->ring_ptr  = req->ring; | 
|  | 1797 | req->ring_index    = 0; | 
|  | 1798 | req->cnt      = req->length; | 
|  | 1799 | } | 
|  | 1800 |  | 
| Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1801 | for (que = 0; que < ha->max_rsp_queues; que++) { | 
| Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1802 | rsp = ha->rsp_q_map[que]; | 
|  | 1803 | if (!rsp) | 
|  | 1804 | continue; | 
| Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1805 | /* Initialize response queue entries */ | 
|  | 1806 | qla2x00_init_response_q_entries(rsp); | 
|  | 1807 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 |  | 
| Dan Carpenter | 542bce1 | 2010-10-15 11:27:38 -0700 | [diff] [blame] | 1809 | spin_lock(&ha->vport_slock); | 
| Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 1810 |  | 
| Dan Carpenter | 542bce1 | 2010-10-15 11:27:38 -0700 | [diff] [blame] | 1811 | spin_unlock(&ha->vport_slock); | 
| Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 1812 |  | 
| Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1813 | ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; | 
|  | 1814 | ha->tgt.atio_ring_index = 0; | 
|  | 1815 | /* Initialize ATIO queue entries */ | 
|  | 1816 | qlt_init_atio_q_entries(vha); | 
|  | 1817 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1818 | ha->isp_ops->config_rings(vha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 |  | 
|  | 1820 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
|  | 1821 |  | 
|  | 1822 | /* Update any ISP specific firmware options before initialization. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1823 | ha->isp_ops->update_fw_options(vha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1825 | ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n"); | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1826 |  | 
| Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 1827 | if (ha->flags.npiv_supported) { | 
|  | 1828 | if (ha->operating_mode == LOOP) | 
|  | 1829 | ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1; | 
| Seokmann Ju | c48339d | 2008-01-17 09:02:19 -0800 | [diff] [blame] | 1830 | mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports); | 
| Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 1831 | } | 
|  | 1832 |  | 
| Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 1833 | if (IS_FWI2_CAPABLE(ha)) { | 
|  | 1834 | mid_init_cb->options = __constant_cpu_to_le16(BIT_1); | 
|  | 1835 | mid_init_cb->init_cb.execution_throttle = | 
|  | 1836 | cpu_to_le16(ha->fw_xcb_count); | 
|  | 1837 | } | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1838 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1839 | rval = qla2x00_init_firmware(vha, ha->init_cb_size); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | if (rval) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1841 | ql_log(ql_log_fatal, vha, 0x00d2, | 
|  | 1842 | "Init Firmware **** FAILED ****.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | } else { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1844 | ql_dbg(ql_dbg_init, vha, 0x00d3, | 
|  | 1845 | "Init Firmware -- success.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | } | 
|  | 1847 |  | 
|  | 1848 | return (rval); | 
|  | 1849 | } | 
|  | 1850 |  | 
|  | 1851 | /** | 
|  | 1852 | * qla2x00_fw_ready() - Waits for firmware ready. | 
|  | 1853 | * @ha: HA context | 
|  | 1854 | * | 
|  | 1855 | * Returns 0 on success. | 
|  | 1856 | */ | 
|  | 1857 | static int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1858 | qla2x00_fw_ready(scsi_qla_host_t *vha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | { | 
|  | 1860 | int		rval; | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1861 | unsigned long	wtime, mtime, cs84xx_time; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | uint16_t	min_wait;	/* Minimum wait time if loop is down */ | 
|  | 1863 | uint16_t	wait_time;	/* Wait time if loop is coming ready */ | 
| Andrew Vasquez | 656e891 | 2009-06-03 09:55:29 -0700 | [diff] [blame] | 1864 | uint16_t	state[5]; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1865 | struct qla_hw_data *ha = vha->hw; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 |  | 
|  | 1867 | rval = QLA_SUCCESS; | 
|  | 1868 |  | 
|  | 1869 | /* 20 seconds for loop down. */ | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1870 | min_wait = 20; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1871 |  | 
|  | 1872 | /* | 
|  | 1873 | * Firmware should take at most one RATOV to login, plus 5 seconds for | 
|  | 1874 | * our own processing. | 
|  | 1875 | */ | 
|  | 1876 | if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) { | 
|  | 1877 | wait_time = min_wait; | 
|  | 1878 | } | 
|  | 1879 |  | 
|  | 1880 | /* Min wait time if loop down */ | 
|  | 1881 | mtime = jiffies + (min_wait * HZ); | 
|  | 1882 |  | 
|  | 1883 | /* wait time before firmware ready */ | 
|  | 1884 | wtime = jiffies + (wait_time * HZ); | 
|  | 1885 |  | 
|  | 1886 | /* Wait for ISP to finish LIP */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1887 | if (!vha->flags.init_done) | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1888 | ql_log(ql_log_info, vha, 0x801e, | 
|  | 1889 | "Waiting for LIP to complete.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 |  | 
|  | 1891 | do { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1892 | rval = qla2x00_get_firmware_state(vha, state); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | if (rval == QLA_SUCCESS) { | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1894 | if (state[0] < FSTATE_LOSS_OF_SYNC) { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1895 | vha->device_flags &= ~DFLG_NO_CABLE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1896 | } | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1897 | if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1898 | ql_dbg(ql_dbg_taskm, vha, 0x801f, | 
|  | 1899 | "fw_state=%x 84xx=%x.\n", state[0], | 
|  | 1900 | state[2]); | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1901 | if ((state[2] & FSTATE_LOGGED_IN) && | 
|  | 1902 | (state[2] & FSTATE_WAITING_FOR_VERIFY)) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1903 | ql_dbg(ql_dbg_taskm, vha, 0x8028, | 
|  | 1904 | "Sending verify iocb.\n"); | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1905 |  | 
|  | 1906 | cs84xx_time = jiffies; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1907 | rval = qla84xx_init_chip(vha); | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1908 | if (rval != QLA_SUCCESS) { | 
|  | 1909 | ql_log(ql_log_warn, | 
| Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1910 | vha, 0x8007, | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1911 | "Init chip failed.\n"); | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1912 | break; | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1913 | } | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1914 |  | 
|  | 1915 | /* Add time taken to initialize. */ | 
|  | 1916 | cs84xx_time = jiffies - cs84xx_time; | 
|  | 1917 | wtime += cs84xx_time; | 
|  | 1918 | mtime += cs84xx_time; | 
| Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1919 | ql_dbg(ql_dbg_taskm, vha, 0x8008, | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1920 | "Increasing wait time by %ld. " | 
|  | 1921 | "New time %ld.\n", cs84xx_time, | 
|  | 1922 | wtime); | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1923 | } | 
|  | 1924 | } else if (state[0] == FSTATE_READY) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1925 | ql_dbg(ql_dbg_taskm, vha, 0x8037, | 
|  | 1926 | "F/W Ready - OK.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1928 | qla2x00_get_retry_cnt(vha, &ha->retry_count, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | &ha->login_timeout, &ha->r_a_tov); | 
|  | 1930 |  | 
|  | 1931 | rval = QLA_SUCCESS; | 
|  | 1932 | break; | 
|  | 1933 | } | 
|  | 1934 |  | 
|  | 1935 | rval = QLA_FUNCTION_FAILED; | 
|  | 1936 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1937 | if (atomic_read(&vha->loop_down_timer) && | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1938 | state[0] != FSTATE_READY) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | /* Loop down. Timeout on min_wait for states | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1940 | * other than Wait for Login. | 
|  | 1941 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | if (time_after_eq(jiffies, mtime)) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1943 | ql_log(ql_log_info, vha, 0x8038, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | "Cable is unplugged...\n"); | 
|  | 1945 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1946 | vha->device_flags |= DFLG_NO_CABLE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | break; | 
|  | 1948 | } | 
|  | 1949 | } | 
|  | 1950 | } else { | 
|  | 1951 | /* Mailbox cmd failed. Timeout on min_wait. */ | 
| Santosh Vernekar | cdbb0a4f | 2010-05-28 15:08:25 -0700 | [diff] [blame] | 1952 | if (time_after_eq(jiffies, mtime) || | 
| Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 1953 | ha->flags.isp82xx_fw_hung) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1954 | break; | 
|  | 1955 | } | 
|  | 1956 |  | 
|  | 1957 | if (time_after_eq(jiffies, wtime)) | 
|  | 1958 | break; | 
|  | 1959 |  | 
|  | 1960 | /* Delay for a while */ | 
|  | 1961 | msleep(500); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | } while (1); | 
|  | 1963 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1964 | ql_dbg(ql_dbg_taskm, vha, 0x803a, | 
|  | 1965 | "fw_state=%x (%x, %x, %x, %x) " "curr time=%lx.\n", state[0], | 
|  | 1966 | state[1], state[2], state[3], state[4], jiffies); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 |  | 
| Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1968 | if (rval && !(vha->device_flags & DFLG_NO_CABLE)) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1969 | ql_log(ql_log_warn, vha, 0x803b, | 
|  | 1970 | "Firmware ready **** FAILED ****.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | } | 
|  | 1972 |  | 
|  | 1973 | return (rval); | 
|  | 1974 | } | 
|  | 1975 |  | 
|  | 1976 | /* | 
|  | 1977 | *  qla2x00_configure_hba | 
|  | 1978 | *      Setup adapter context. | 
|  | 1979 | * | 
|  | 1980 | * Input: | 
|  | 1981 | *      ha = adapter state pointer. | 
|  | 1982 | * | 
|  | 1983 | * Returns: | 
|  | 1984 | *      0 = success | 
|  | 1985 | * | 
|  | 1986 | * Context: | 
|  | 1987 | *      Kernel context. | 
|  | 1988 | */ | 
|  | 1989 | static int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1990 | qla2x00_configure_hba(scsi_qla_host_t *vha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | { | 
|  | 1992 | int       rval; | 
|  | 1993 | uint16_t      loop_id; | 
|  | 1994 | uint16_t      topo; | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1995 | uint16_t      sw_cap; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | uint8_t       al_pa; | 
|  | 1997 | uint8_t       area; | 
|  | 1998 | uint8_t       domain; | 
|  | 1999 | char		connect_type[22]; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2000 | struct qla_hw_data *ha = vha->hw; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 |  | 
|  | 2002 | /* Get host addresses. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2003 | rval = qla2x00_get_adapter_id(vha, | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2004 | &loop_id, &al_pa, &area, &domain, &topo, &sw_cap); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | if (rval != QLA_SUCCESS) { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2006 | if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) || | 
| Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2007 | IS_CNA_CAPABLE(ha) || | 
| Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 2008 | (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2009 | ql_dbg(ql_dbg_disc, vha, 0x2008, | 
|  | 2010 | "Loop is in a transition state.\n"); | 
| Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 2011 | } else { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2012 | ql_log(ql_log_warn, vha, 0x2009, | 
|  | 2013 | "Unable to get host loop ID.\n"); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2014 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | 
| Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 2015 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | return (rval); | 
|  | 2017 | } | 
|  | 2018 |  | 
|  | 2019 | if (topo == 4) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2020 | ql_log(ql_log_info, vha, 0x200a, | 
|  | 2021 | "Cannot get topology - retrying.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2022 | return (QLA_FUNCTION_FAILED); | 
|  | 2023 | } | 
|  | 2024 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2025 | vha->loop_id = loop_id; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 |  | 
|  | 2027 | /* initialize */ | 
|  | 2028 | ha->min_external_loopid = SNS_FIRST_LOOP_ID; | 
|  | 2029 | ha->operating_mode = LOOP; | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2030 | ha->switch_cap = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 |  | 
|  | 2032 | switch (topo) { | 
|  | 2033 | case 0: | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2034 | ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | ha->current_topology = ISP_CFG_NL; | 
|  | 2036 | strcpy(connect_type, "(Loop)"); | 
|  | 2037 | break; | 
|  | 2038 |  | 
|  | 2039 | case 1: | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2040 | ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n"); | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2041 | ha->switch_cap = sw_cap; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | ha->current_topology = ISP_CFG_FL; | 
|  | 2043 | strcpy(connect_type, "(FL_Port)"); | 
|  | 2044 | break; | 
|  | 2045 |  | 
|  | 2046 | case 2: | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2047 | 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] | 2048 | ha->operating_mode = P2P; | 
|  | 2049 | ha->current_topology = ISP_CFG_N; | 
|  | 2050 | strcpy(connect_type, "(N_Port-to-N_Port)"); | 
|  | 2051 | break; | 
|  | 2052 |  | 
|  | 2053 | case 3: | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2054 | 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] | 2055 | ha->switch_cap = sw_cap; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | ha->operating_mode = P2P; | 
|  | 2057 | ha->current_topology = ISP_CFG_F; | 
|  | 2058 | strcpy(connect_type, "(F_Port)"); | 
|  | 2059 | break; | 
|  | 2060 |  | 
|  | 2061 | default: | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2062 | ql_dbg(ql_dbg_disc, vha, 0x200f, | 
|  | 2063 | "HBA in unknown topology %x, using NL.\n", topo); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | ha->current_topology = ISP_CFG_NL; | 
|  | 2065 | strcpy(connect_type, "(Loop)"); | 
|  | 2066 | break; | 
|  | 2067 | } | 
|  | 2068 |  | 
|  | 2069 | /* Save Host port and loop ID. */ | 
|  | 2070 | /* byte order - Big Endian */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2071 | vha->d_id.b.domain = domain; | 
|  | 2072 | vha->d_id.b.area = area; | 
|  | 2073 | vha->d_id.b.al_pa = al_pa; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 |  | 
| Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2075 | spin_lock(&ha->vport_slock); | 
|  | 2076 | qlt_update_vp_map(vha, SET_AL_PA); | 
|  | 2077 | spin_unlock(&ha->vport_slock); | 
|  | 2078 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2079 | if (!vha->flags.init_done) | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2080 | ql_log(ql_log_info, vha, 0x2010, | 
|  | 2081 | "Topology - %s, Host Loop address 0x%x.\n", | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2082 | connect_type, vha->loop_id); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 |  | 
|  | 2084 | if (rval) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2085 | ql_log(ql_log_warn, vha, 0x2011, | 
|  | 2086 | "%s FAILED\n", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | } else { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2088 | ql_dbg(ql_dbg_disc, vha, 0x2012, | 
|  | 2089 | "%s success\n", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2090 | } | 
|  | 2091 |  | 
|  | 2092 | return(rval); | 
|  | 2093 | } | 
|  | 2094 |  | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2095 | inline void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2096 | qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len, | 
|  | 2097 | char *def) | 
| Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2098 | { | 
|  | 2099 | char *st, *en; | 
|  | 2100 | uint16_t index; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2101 | struct qla_hw_data *ha = vha->hw; | 
| Andrew Vasquez | ab67114 | 2009-08-25 11:36:17 -0700 | [diff] [blame] | 2102 | int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) && | 
| Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2103 | !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha); | 
| Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2104 |  | 
|  | 2105 | if (memcmp(model, BINZERO, len) != 0) { | 
|  | 2106 | strncpy(ha->model_number, model, len); | 
|  | 2107 | st = en = ha->model_number; | 
|  | 2108 | en += len - 1; | 
|  | 2109 | while (en > st) { | 
|  | 2110 | if (*en != 0x20 && *en != 0x00) | 
|  | 2111 | break; | 
|  | 2112 | *en-- = '\0'; | 
|  | 2113 | } | 
|  | 2114 |  | 
|  | 2115 | index = (ha->pdev->subsystem_device & 0xff); | 
| Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 2116 | if (use_tbl && | 
|  | 2117 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && | 
| Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2118 | index < QLA_MODEL_NAMES) | 
| Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2119 | strncpy(ha->model_desc, | 
|  | 2120 | qla2x00_model_name[index * 2 + 1], | 
|  | 2121 | sizeof(ha->model_desc) - 1); | 
| Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2122 | } else { | 
|  | 2123 | index = (ha->pdev->subsystem_device & 0xff); | 
| Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 2124 | if (use_tbl && | 
|  | 2125 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && | 
| Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2126 | index < QLA_MODEL_NAMES) { | 
|  | 2127 | strcpy(ha->model_number, | 
|  | 2128 | qla2x00_model_name[index * 2]); | 
| Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2129 | strncpy(ha->model_desc, | 
|  | 2130 | qla2x00_model_name[index * 2 + 1], | 
|  | 2131 | sizeof(ha->model_desc) - 1); | 
| Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2132 | } else { | 
|  | 2133 | strcpy(ha->model_number, def); | 
|  | 2134 | } | 
|  | 2135 | } | 
| Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2136 | if (IS_FWI2_CAPABLE(ha)) | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2137 | qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc, | 
| Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2138 | sizeof(ha->model_desc)); | 
| Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2139 | } | 
|  | 2140 |  | 
| David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2141 | /* On sparc systems, obtain port and node WWN from firmware | 
|  | 2142 | * properties. | 
|  | 2143 | */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2144 | 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] | 2145 | { | 
|  | 2146 | #ifdef CONFIG_SPARC | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2147 | struct qla_hw_data *ha = vha->hw; | 
| David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2148 | struct pci_dev *pdev = ha->pdev; | 
| David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 2149 | struct device_node *dp = pci_device_to_OF_node(pdev); | 
|  | 2150 | const u8 *val; | 
| David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2151 | int len; | 
|  | 2152 |  | 
|  | 2153 | val = of_get_property(dp, "port-wwn", &len); | 
|  | 2154 | if (val && len >= WWN_SIZE) | 
|  | 2155 | memcpy(nv->port_name, val, WWN_SIZE); | 
|  | 2156 |  | 
|  | 2157 | val = of_get_property(dp, "node-wwn", &len); | 
|  | 2158 | if (val && len >= WWN_SIZE) | 
|  | 2159 | memcpy(nv->node_name, val, WWN_SIZE); | 
|  | 2160 | #endif | 
|  | 2161 | } | 
|  | 2162 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | /* | 
|  | 2164 | * NVRAM configuration for ISP 2xxx | 
|  | 2165 | * | 
|  | 2166 | * Input: | 
|  | 2167 | *      ha                = adapter block pointer. | 
|  | 2168 | * | 
|  | 2169 | * Output: | 
|  | 2170 | *      initialization control block in response_ring | 
|  | 2171 | *      host adapters parameters in host adapter block | 
|  | 2172 | * | 
|  | 2173 | * Returns: | 
|  | 2174 | *      0 = success. | 
|  | 2175 | */ | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2176 | int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2177 | qla2x00_nvram_config(scsi_qla_host_t *vha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2178 | { | 
| David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2179 | int             rval; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2180 | uint8_t         chksum = 0; | 
|  | 2181 | uint16_t        cnt; | 
|  | 2182 | uint8_t         *dptr1, *dptr2; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2183 | struct qla_hw_data *ha = vha->hw; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2184 | init_cb_t       *icb = ha->init_cb; | 
| Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 2185 | nvram_t         *nv = ha->nvram; | 
|  | 2186 | uint8_t         *ptr = ha->nvram; | 
| Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2187 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2188 |  | 
| David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2189 | rval = QLA_SUCCESS; | 
|  | 2190 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | /* Determine NVRAM starting address. */ | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2192 | ha->nvram_size = sizeof(nvram_t); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2193 | ha->nvram_base = 0; | 
|  | 2194 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) | 
|  | 2195 | if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1) | 
|  | 2196 | ha->nvram_base = 0x80; | 
|  | 2197 |  | 
|  | 2198 | /* Get NVRAM data and calculate checksum. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2199 | 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] | 2200 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++) | 
|  | 2201 | chksum += *ptr++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2202 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2203 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f, | 
|  | 2204 | "Contents of NVRAM.\n"); | 
|  | 2205 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110, | 
|  | 2206 | (uint8_t *)nv, ha->nvram_size); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2207 |  | 
|  | 2208 | /* Bad NVRAM data, set defaults parameters. */ | 
|  | 2209 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || | 
|  | 2210 | nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) { | 
|  | 2211 | /* Reset NVRAM data. */ | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2212 | ql_log(ql_log_warn, vha, 0x0064, | 
| Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 2213 | "Inconsistent NVRAM " | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2214 | "detected: checksum=0x%x id=%c version=0x%x.\n", | 
|  | 2215 | chksum, nv->id[0], nv->nvram_version); | 
|  | 2216 | ql_log(ql_log_warn, vha, 0x0065, | 
|  | 2217 | "Falling back to " | 
|  | 2218 | "functioning (yet invalid -- WWPN) defaults.\n"); | 
| David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2219 |  | 
|  | 2220 | /* | 
|  | 2221 | * Set default initialization control block. | 
|  | 2222 | */ | 
|  | 2223 | memset(nv, 0, ha->nvram_size); | 
|  | 2224 | nv->parameter_block_version = ICB_VERSION; | 
|  | 2225 |  | 
|  | 2226 | if (IS_QLA23XX(ha)) { | 
|  | 2227 | nv->firmware_options[0] = BIT_2 | BIT_1; | 
|  | 2228 | nv->firmware_options[1] = BIT_7 | BIT_5; | 
|  | 2229 | nv->add_firmware_options[0] = BIT_5; | 
|  | 2230 | nv->add_firmware_options[1] = BIT_5 | BIT_4; | 
|  | 2231 | nv->frame_payload_size = __constant_cpu_to_le16(2048); | 
|  | 2232 | nv->special_options[1] = BIT_7; | 
|  | 2233 | } else if (IS_QLA2200(ha)) { | 
|  | 2234 | nv->firmware_options[0] = BIT_2 | BIT_1; | 
|  | 2235 | nv->firmware_options[1] = BIT_7 | BIT_5; | 
|  | 2236 | nv->add_firmware_options[0] = BIT_5; | 
|  | 2237 | nv->add_firmware_options[1] = BIT_5 | BIT_4; | 
|  | 2238 | nv->frame_payload_size = __constant_cpu_to_le16(1024); | 
|  | 2239 | } else if (IS_QLA2100(ha)) { | 
|  | 2240 | nv->firmware_options[0] = BIT_3 | BIT_1; | 
|  | 2241 | nv->firmware_options[1] = BIT_5; | 
|  | 2242 | nv->frame_payload_size = __constant_cpu_to_le16(1024); | 
|  | 2243 | } | 
|  | 2244 |  | 
|  | 2245 | nv->max_iocb_allocation = __constant_cpu_to_le16(256); | 
|  | 2246 | nv->execution_throttle = __constant_cpu_to_le16(16); | 
|  | 2247 | nv->retry_count = 8; | 
|  | 2248 | nv->retry_delay = 1; | 
|  | 2249 |  | 
|  | 2250 | nv->port_name[0] = 33; | 
|  | 2251 | nv->port_name[3] = 224; | 
|  | 2252 | nv->port_name[4] = 139; | 
|  | 2253 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2254 | qla2xxx_nvram_wwn_from_ofw(vha, nv); | 
| David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2255 |  | 
|  | 2256 | nv->login_timeout = 4; | 
|  | 2257 |  | 
|  | 2258 | /* | 
|  | 2259 | * Set default host adapter parameters | 
|  | 2260 | */ | 
|  | 2261 | nv->host_p[1] = BIT_2; | 
|  | 2262 | nv->reset_delay = 5; | 
|  | 2263 | nv->port_down_retry_count = 8; | 
|  | 2264 | nv->max_luns_per_target = __constant_cpu_to_le16(8); | 
|  | 2265 | nv->link_down_timeout = 60; | 
|  | 2266 |  | 
|  | 2267 | rval = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | } | 
|  | 2269 |  | 
|  | 2270 | #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2) | 
|  | 2271 | /* | 
|  | 2272 | * The SN2 does not provide BIOS emulation which means you can't change | 
|  | 2273 | * potentially bogus BIOS settings. Force the use of default settings | 
|  | 2274 | * for link rate and frame size.  Hope that the rest of the settings | 
|  | 2275 | * are valid. | 
|  | 2276 | */ | 
|  | 2277 | if (ia64_platform_is("sn2")) { | 
|  | 2278 | nv->frame_payload_size = __constant_cpu_to_le16(2048); | 
|  | 2279 | if (IS_QLA23XX(ha)) | 
|  | 2280 | nv->special_options[1] = BIT_7; | 
|  | 2281 | } | 
|  | 2282 | #endif | 
|  | 2283 |  | 
|  | 2284 | /* Reset Initialization control block */ | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2285 | memset(icb, 0, ha->init_cb_size); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 |  | 
|  | 2287 | /* | 
|  | 2288 | * Setup driver NVRAM options. | 
|  | 2289 | */ | 
|  | 2290 | nv->firmware_options[0] |= (BIT_6 | BIT_1); | 
|  | 2291 | nv->firmware_options[0] &= ~(BIT_5 | BIT_4); | 
|  | 2292 | nv->firmware_options[1] |= (BIT_5 | BIT_0); | 
|  | 2293 | nv->firmware_options[1] &= ~BIT_4; | 
|  | 2294 |  | 
|  | 2295 | if (IS_QLA23XX(ha)) { | 
|  | 2296 | nv->firmware_options[0] |= BIT_2; | 
|  | 2297 | nv->firmware_options[0] &= ~BIT_3; | 
| Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2298 | nv->special_options[0] &= ~BIT_6; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2299 | nv->add_firmware_options[1] |= BIT_5 | BIT_4; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2300 |  | 
|  | 2301 | if (IS_QLA2300(ha)) { | 
|  | 2302 | if (ha->fb_rev == FPM_2310) { | 
|  | 2303 | strcpy(ha->model_number, "QLA2310"); | 
|  | 2304 | } else { | 
|  | 2305 | strcpy(ha->model_number, "QLA2300"); | 
|  | 2306 | } | 
|  | 2307 | } else { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2308 | qla2x00_set_model_info(vha, nv->model_number, | 
| Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2309 | sizeof(nv->model_number), "QLA23xx"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2310 | } | 
|  | 2311 | } else if (IS_QLA2200(ha)) { | 
|  | 2312 | nv->firmware_options[0] |= BIT_2; | 
|  | 2313 | /* | 
|  | 2314 | * 'Point-to-point preferred, else loop' is not a safe | 
|  | 2315 | * connection mode setting. | 
|  | 2316 | */ | 
|  | 2317 | if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) == | 
|  | 2318 | (BIT_5 | BIT_4)) { | 
|  | 2319 | /* Force 'loop preferred, else point-to-point'. */ | 
|  | 2320 | nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4); | 
|  | 2321 | nv->add_firmware_options[0] |= BIT_5; | 
|  | 2322 | } | 
|  | 2323 | strcpy(ha->model_number, "QLA22xx"); | 
|  | 2324 | } else /*if (IS_QLA2100(ha))*/ { | 
|  | 2325 | strcpy(ha->model_number, "QLA2100"); | 
|  | 2326 | } | 
|  | 2327 |  | 
|  | 2328 | /* | 
|  | 2329 | * Copy over NVRAM RISC parameter block to initialization control block. | 
|  | 2330 | */ | 
|  | 2331 | dptr1 = (uint8_t *)icb; | 
|  | 2332 | dptr2 = (uint8_t *)&nv->parameter_block_version; | 
|  | 2333 | cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version; | 
|  | 2334 | while (cnt--) | 
|  | 2335 | *dptr1++ = *dptr2++; | 
|  | 2336 |  | 
|  | 2337 | /* Copy 2nd half. */ | 
|  | 2338 | dptr1 = (uint8_t *)icb->add_firmware_options; | 
|  | 2339 | cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options; | 
|  | 2340 | while (cnt--) | 
|  | 2341 | *dptr1++ = *dptr2++; | 
|  | 2342 |  | 
| Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 2343 | /* Use alternate WWN? */ | 
|  | 2344 | if (nv->host_p[1] & BIT_7) { | 
|  | 2345 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); | 
|  | 2346 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); | 
|  | 2347 | } | 
|  | 2348 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2349 | /* Prepare nodename */ | 
|  | 2350 | if ((icb->firmware_options[1] & BIT_6) == 0) { | 
|  | 2351 | /* | 
|  | 2352 | * Firmware will apply the following mask if the nodename was | 
|  | 2353 | * not provided. | 
|  | 2354 | */ | 
|  | 2355 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); | 
|  | 2356 | icb->node_name[0] &= 0xF0; | 
|  | 2357 | } | 
|  | 2358 |  | 
|  | 2359 | /* | 
|  | 2360 | * Set host adapter parameters. | 
|  | 2361 | */ | 
| Saurav Kashyap | 3ce8866 | 2011-07-14 12:00:12 -0700 | [diff] [blame] | 2362 |  | 
|  | 2363 | /* | 
|  | 2364 | * BIT_7 in the host-parameters section allows for modification to | 
|  | 2365 | * internal driver logging. | 
|  | 2366 | */ | 
| Andrew Vasquez | 0181944 | 2006-06-23 16:11:10 -0700 | [diff] [blame] | 2367 | if (nv->host_p[0] & BIT_7) | 
| Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2368 | ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2369 | ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0); | 
|  | 2370 | /* Always load RISC code on non ISP2[12]00 chips. */ | 
|  | 2371 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) | 
|  | 2372 | ha->flags.disable_risc_code_load = 0; | 
|  | 2373 | ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0); | 
|  | 2374 | ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0); | 
|  | 2375 | 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] | 2376 | 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] | 2377 | ha->flags.disable_serdes = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2378 |  | 
|  | 2379 | ha->operating_mode = | 
|  | 2380 | (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4; | 
|  | 2381 |  | 
|  | 2382 | memcpy(ha->fw_seriallink_options, nv->seriallink_options, | 
|  | 2383 | sizeof(ha->fw_seriallink_options)); | 
|  | 2384 |  | 
|  | 2385 | /* save HBA serial number */ | 
|  | 2386 | ha->serial0 = icb->port_name[5]; | 
|  | 2387 | ha->serial1 = icb->port_name[6]; | 
|  | 2388 | ha->serial2 = icb->port_name[7]; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2389 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); | 
|  | 2390 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 |  | 
|  | 2392 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); | 
|  | 2393 |  | 
|  | 2394 | ha->retry_count = nv->retry_count; | 
|  | 2395 |  | 
|  | 2396 | /* Set minimum login_timeout to 4 seconds. */ | 
| Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 2397 | if (nv->login_timeout != ql2xlogintimeout) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2398 | nv->login_timeout = ql2xlogintimeout; | 
|  | 2399 | if (nv->login_timeout < 4) | 
|  | 2400 | nv->login_timeout = 4; | 
|  | 2401 | ha->login_timeout = nv->login_timeout; | 
|  | 2402 | icb->login_timeout = nv->login_timeout; | 
|  | 2403 |  | 
| Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 2404 | /* Set minimum RATOV to 100 tenths of a second. */ | 
|  | 2405 | ha->r_a_tov = 100; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2407 | ha->loop_reset_delay = nv->reset_delay; | 
|  | 2408 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2409 | /* Link Down Timeout = 0: | 
|  | 2410 | * | 
|  | 2411 | * 	When Port Down timer expires we will start returning | 
|  | 2412 | *	I/O's to OS with "DID_NO_CONNECT". | 
|  | 2413 | * | 
|  | 2414 | * Link Down Timeout != 0: | 
|  | 2415 | * | 
|  | 2416 | *	 The driver waits for the link to come up after link down | 
|  | 2417 | *	 before returning I/Os to OS with "DID_NO_CONNECT". | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2418 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | if (nv->link_down_timeout == 0) { | 
|  | 2420 | ha->loop_down_abort_time = | 
| Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 2421 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2422 | } else { | 
|  | 2423 | ha->link_down_timeout =	 nv->link_down_timeout; | 
|  | 2424 | ha->loop_down_abort_time = | 
|  | 2425 | (LOOP_DOWN_TIME - ha->link_down_timeout); | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2426 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2427 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2428 | /* | 
|  | 2429 | * Need enough time to try and get the port back. | 
|  | 2430 | */ | 
|  | 2431 | ha->port_down_retry_count = nv->port_down_retry_count; | 
|  | 2432 | if (qlport_down_retry) | 
|  | 2433 | ha->port_down_retry_count = qlport_down_retry; | 
|  | 2434 | /* Set login_retry_count */ | 
|  | 2435 | ha->login_retry_count  = nv->retry_count; | 
|  | 2436 | if (ha->port_down_retry_count == nv->port_down_retry_count && | 
|  | 2437 | ha->port_down_retry_count > 3) | 
|  | 2438 | ha->login_retry_count = ha->port_down_retry_count; | 
|  | 2439 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) | 
|  | 2440 | ha->login_retry_count = ha->port_down_retry_count; | 
|  | 2441 | if (ql2xloginretrycount) | 
|  | 2442 | ha->login_retry_count = ql2xloginretrycount; | 
|  | 2443 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2444 | icb->lun_enables = __constant_cpu_to_le16(0); | 
|  | 2445 | icb->command_resource_count = 0; | 
|  | 2446 | icb->immediate_notify_resource_count = 0; | 
|  | 2447 | icb->timeout = __constant_cpu_to_le16(0); | 
|  | 2448 |  | 
|  | 2449 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { | 
|  | 2450 | /* Enable RIO */ | 
|  | 2451 | icb->firmware_options[0] &= ~BIT_3; | 
|  | 2452 | icb->add_firmware_options[0] &= | 
|  | 2453 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); | 
|  | 2454 | icb->add_firmware_options[0] |= BIT_2; | 
|  | 2455 | icb->response_accumulation_timer = 3; | 
|  | 2456 | icb->interrupt_delay_timer = 5; | 
|  | 2457 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2458 | vha->flags.process_response_queue = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2459 | } else { | 
| Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2460 | /* Enable ZIO. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2461 | if (!vha->flags.init_done) { | 
| Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2462 | ha->zio_mode = icb->add_firmware_options[0] & | 
|  | 2463 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); | 
|  | 2464 | ha->zio_timer = icb->interrupt_delay_timer ? | 
|  | 2465 | icb->interrupt_delay_timer: 2; | 
|  | 2466 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2467 | icb->add_firmware_options[0] &= | 
|  | 2468 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2469 | vha->flags.process_response_queue = 0; | 
| Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2470 | if (ha->zio_mode != QLA_ZIO_DISABLED) { | 
| andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 2471 | ha->zio_mode = QLA_ZIO_MODE_6; | 
|  | 2472 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2473 | ql_log(ql_log_info, vha, 0x0068, | 
| Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2474 | "ZIO mode %d enabled; timer delay (%d us).\n", | 
|  | 2475 | ha->zio_mode, ha->zio_timer * 100); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2476 |  | 
| Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2477 | icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode; | 
|  | 2478 | icb->interrupt_delay_timer = (uint8_t)ha->zio_timer; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2479 | vha->flags.process_response_queue = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | } | 
|  | 2481 | } | 
|  | 2482 |  | 
| David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2483 | if (rval) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2484 | ql_log(ql_log_warn, vha, 0x0069, | 
|  | 2485 | "NVRAM configuration failed.\n"); | 
| David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2486 | } | 
|  | 2487 | return (rval); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | } | 
|  | 2489 |  | 
| James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2490 | static void | 
| James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2491 | qla2x00_rport_del(void *data) | 
|  | 2492 | { | 
|  | 2493 | fc_port_t *fcport = data; | 
| andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2494 | struct fc_rport *rport; | 
| Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2495 | scsi_qla_host_t *vha = fcport->vha; | 
| Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2496 | unsigned long flags; | 
| James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2497 |  | 
| Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2498 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2499 | rport = fcport->drport ? fcport->drport: fcport->rport; | 
| andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2500 | fcport->drport = NULL; | 
| Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2501 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); | 
| Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2502 | if (rport) { | 
| andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2503 | fc_remote_port_delete(rport); | 
| Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2504 | /* | 
|  | 2505 | * Release the target mode FC NEXUS in qla_target.c code | 
|  | 2506 | * if target mod is enabled. | 
|  | 2507 | */ | 
|  | 2508 | qlt_fc_port_deleted(vha, fcport); | 
|  | 2509 | } | 
| James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2510 | } | 
|  | 2511 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2512 | /** | 
|  | 2513 | * qla2x00_alloc_fcport() - Allocate a generic fcport. | 
|  | 2514 | * @ha: HA context | 
|  | 2515 | * @flags: allocation flags | 
|  | 2516 | * | 
|  | 2517 | * Returns a pointer to the allocated fcport, or NULL, if none available. | 
|  | 2518 | */ | 
| Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2519 | fc_port_t * | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2520 | qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2521 | { | 
|  | 2522 | fc_port_t *fcport; | 
|  | 2523 |  | 
| Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2524 | fcport = kzalloc(sizeof(fc_port_t), flags); | 
|  | 2525 | if (!fcport) | 
|  | 2526 | return NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2527 |  | 
|  | 2528 | /* Setup fcport template structure. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2529 | fcport->vha = vha; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2530 | fcport->port_type = FCT_UNKNOWN; | 
|  | 2531 | fcport->loop_id = FC_NO_LOOP_ID; | 
| Chad Dupuis | ec426e1 | 2011-03-30 11:46:32 -0700 | [diff] [blame] | 2532 | qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED); | 
| Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 2533 | fcport->supported_classes = FC_COS_UNSPECIFIED; | 
| Joe Carnuccio | c0822b6 | 2012-05-15 14:34:21 -0400 | [diff] [blame] | 2534 | fcport->scan_state = QLA_FCPORT_SCAN_NONE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2535 |  | 
| Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2536 | return fcport; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 | } | 
|  | 2538 |  | 
|  | 2539 | /* | 
|  | 2540 | * qla2x00_configure_loop | 
|  | 2541 | *      Updates Fibre Channel Device Database with what is actually on loop. | 
|  | 2542 | * | 
|  | 2543 | * Input: | 
|  | 2544 | *      ha                = adapter block pointer. | 
|  | 2545 | * | 
|  | 2546 | * Returns: | 
|  | 2547 | *      0 = success. | 
|  | 2548 | *      1 = error. | 
|  | 2549 | *      2 = database was full and device was not configured. | 
|  | 2550 | */ | 
|  | 2551 | static int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2552 | qla2x00_configure_loop(scsi_qla_host_t *vha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2553 | { | 
|  | 2554 | int  rval; | 
|  | 2555 | unsigned long flags, save_flags; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2556 | struct qla_hw_data *ha = vha->hw; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2557 | rval = QLA_SUCCESS; | 
|  | 2558 |  | 
|  | 2559 | /* Get Initiator ID */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2560 | if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) { | 
|  | 2561 | rval = qla2x00_configure_hba(vha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2562 | if (rval != QLA_SUCCESS) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2563 | ql_dbg(ql_dbg_disc, vha, 0x2013, | 
|  | 2564 | "Unable to configure HBA.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2565 | return (rval); | 
|  | 2566 | } | 
|  | 2567 | } | 
|  | 2568 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2569 | save_flags = flags = vha->dpc_flags; | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2570 | ql_dbg(ql_dbg_disc, vha, 0x2014, | 
|  | 2571 | "Configure loop -- dpc flags = 0x%lx.\n", flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2572 |  | 
|  | 2573 | /* | 
|  | 2574 | * If we have both an RSCN and PORT UPDATE pending then handle them | 
|  | 2575 | * both at the same time. | 
|  | 2576 | */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2577 | clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); | 
|  | 2578 | clear_bit(RSCN_UPDATE, &vha->dpc_flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 |  | 
| Michael Hernandez | 3064ff3 | 2009-12-15 21:29:44 -0800 | [diff] [blame] | 2580 | qla2x00_get_data_rate(vha); | 
|  | 2581 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2582 | /* Determine what we need to do */ | 
|  | 2583 | if (ha->current_topology == ISP_CFG_FL && | 
|  | 2584 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { | 
|  | 2585 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2586 | set_bit(RSCN_UPDATE, &flags); | 
|  | 2587 |  | 
|  | 2588 | } else if (ha->current_topology == ISP_CFG_F && | 
|  | 2589 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { | 
|  | 2590 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 | set_bit(RSCN_UPDATE, &flags); | 
|  | 2592 | clear_bit(LOCAL_LOOP_UPDATE, &flags); | 
|  | 2593 |  | 
| Andrew Vasquez | 21333b4 | 2006-05-17 15:09:56 -0700 | [diff] [blame] | 2594 | } else if (ha->current_topology == ISP_CFG_N) { | 
|  | 2595 | clear_bit(RSCN_UPDATE, &flags); | 
|  | 2596 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2597 | } else if (!vha->flags.online || | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2598 | (test_bit(ABORT_ISP_ACTIVE, &flags))) { | 
|  | 2599 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 | set_bit(RSCN_UPDATE, &flags); | 
|  | 2601 | set_bit(LOCAL_LOOP_UPDATE, &flags); | 
|  | 2602 | } | 
|  | 2603 |  | 
|  | 2604 | if (test_bit(LOCAL_LOOP_UPDATE, &flags)) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2605 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { | 
|  | 2606 | ql_dbg(ql_dbg_disc, vha, 0x2015, | 
|  | 2607 | "Loop resync needed, failing.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2608 | rval = QLA_FUNCTION_FAILED; | 
| Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 2609 | } else | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2610 | rval = qla2x00_configure_local_loop(vha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2611 | } | 
|  | 2612 |  | 
|  | 2613 | if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2614 | if (LOOP_TRANSITION(vha)) { | 
|  | 2615 | ql_dbg(ql_dbg_disc, vha, 0x201e, | 
|  | 2616 | "Needs RSCN update and loop transition.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2617 | rval = QLA_FUNCTION_FAILED; | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2618 | } | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2619 | else | 
|  | 2620 | rval = qla2x00_configure_fabric(vha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2621 | } | 
|  | 2622 |  | 
|  | 2623 | if (rval == QLA_SUCCESS) { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2624 | if (atomic_read(&vha->loop_down_timer) || | 
|  | 2625 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2626 | rval = QLA_FUNCTION_FAILED; | 
|  | 2627 | } else { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2628 | atomic_set(&vha->loop_state, LOOP_READY); | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2629 | ql_dbg(ql_dbg_disc, vha, 0x2069, | 
|  | 2630 | "LOOP READY.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2631 | } | 
|  | 2632 | } | 
|  | 2633 |  | 
|  | 2634 | if (rval) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2635 | ql_dbg(ql_dbg_disc, vha, 0x206a, | 
|  | 2636 | "%s *** FAILED ***.\n", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | } else { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2638 | ql_dbg(ql_dbg_disc, vha, 0x206b, | 
|  | 2639 | "%s: exiting normally.\n", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2640 | } | 
|  | 2641 |  | 
| Bjorn Helgaas | cc3ef7b | 2008-09-11 21:22:51 -0700 | [diff] [blame] | 2642 | /* Restore state if a resync event occurred during processing */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2643 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | if (test_bit(LOCAL_LOOP_UPDATE, &save_flags)) | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2645 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); | 
| Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 2646 | if (test_bit(RSCN_UPDATE, &save_flags)) { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2647 | set_bit(RSCN_UPDATE, &vha->dpc_flags); | 
| Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 2648 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2649 | } | 
|  | 2650 |  | 
|  | 2651 | return (rval); | 
|  | 2652 | } | 
|  | 2653 |  | 
|  | 2654 |  | 
|  | 2655 |  | 
|  | 2656 | /* | 
|  | 2657 | * qla2x00_configure_local_loop | 
|  | 2658 | *	Updates Fibre Channel Device Database with local loop devices. | 
|  | 2659 | * | 
|  | 2660 | * Input: | 
|  | 2661 | *	ha = adapter block pointer. | 
|  | 2662 | * | 
|  | 2663 | * Returns: | 
|  | 2664 | *	0 = success. | 
|  | 2665 | */ | 
|  | 2666 | static int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2667 | qla2x00_configure_local_loop(scsi_qla_host_t *vha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2668 | { | 
|  | 2669 | int		rval, rval2; | 
|  | 2670 | int		found_devs; | 
|  | 2671 | int		found; | 
|  | 2672 | fc_port_t	*fcport, *new_fcport; | 
|  | 2673 |  | 
|  | 2674 | uint16_t	index; | 
|  | 2675 | uint16_t	entries; | 
|  | 2676 | char		*id_iter; | 
|  | 2677 | uint16_t	loop_id; | 
|  | 2678 | uint8_t		domain, area, al_pa; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2679 | struct qla_hw_data *ha = vha->hw; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2680 |  | 
|  | 2681 | found_devs = 0; | 
|  | 2682 | new_fcport = NULL; | 
| Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 2683 | entries = MAX_FIBRE_DEVICES_LOOP; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2684 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2685 | ql_dbg(ql_dbg_disc, vha, 0x2016, | 
|  | 2686 | "Getting FCAL position map.\n"); | 
|  | 2687 | if (ql2xextended_error_logging & ql_dbg_disc) | 
|  | 2688 | qla2x00_get_fcal_position_map(vha, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2689 |  | 
|  | 2690 | /* Get list of logged in devices. */ | 
| Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 2691 | memset(ha->gid_list, 0, qla2x00_gid_list_size(ha)); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2692 | 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] | 2693 | &entries); | 
|  | 2694 | if (rval != QLA_SUCCESS) | 
|  | 2695 | goto cleanup_allocation; | 
|  | 2696 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2697 | ql_dbg(ql_dbg_disc, vha, 0x2017, | 
|  | 2698 | "Entries in ID list (%d).\n", entries); | 
|  | 2699 | ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075, | 
|  | 2700 | (uint8_t *)ha->gid_list, | 
|  | 2701 | entries * sizeof(struct gid_list_info)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2702 |  | 
|  | 2703 | /* Allocate temporary fcport for any new fcports discovered. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2704 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2705 | if (new_fcport == NULL) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2706 | ql_log(ql_log_warn, vha, 0x2018, | 
|  | 2707 | "Memory allocation failed for fcport.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2708 | rval = QLA_MEMORY_ALLOC_FAILED; | 
|  | 2709 | goto cleanup_allocation; | 
|  | 2710 | } | 
|  | 2711 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; | 
|  | 2712 |  | 
|  | 2713 | /* | 
|  | 2714 | * Mark local devices that were present with FCF_DEVICE_LOST for now. | 
|  | 2715 | */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2716 | list_for_each_entry(fcport, &vha->vp_fcports, list) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2717 | if (atomic_read(&fcport->state) == FCS_ONLINE && | 
|  | 2718 | fcport->port_type != FCT_BROADCAST && | 
|  | 2719 | (fcport->flags & FCF_FABRIC_DEVICE) == 0) { | 
|  | 2720 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2721 | ql_dbg(ql_dbg_disc, vha, 0x2019, | 
|  | 2722 | "Marking port lost loop_id=0x%04x.\n", | 
|  | 2723 | fcport->loop_id); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2724 |  | 
| Chad Dupuis | ec426e1 | 2011-03-30 11:46:32 -0700 | [diff] [blame] | 2725 | qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2726 | } | 
|  | 2727 | } | 
|  | 2728 |  | 
|  | 2729 | /* Add devices to port list. */ | 
|  | 2730 | id_iter = (char *)ha->gid_list; | 
|  | 2731 | for (index = 0; index < entries; index++) { | 
|  | 2732 | domain = ((struct gid_list_info *)id_iter)->domain; | 
|  | 2733 | area = ((struct gid_list_info *)id_iter)->area; | 
|  | 2734 | al_pa = ((struct gid_list_info *)id_iter)->al_pa; | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2735 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2736 | loop_id = (uint16_t) | 
|  | 2737 | ((struct gid_list_info *)id_iter)->loop_id_2100; | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2738 | else | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2739 | loop_id = le16_to_cpu( | 
|  | 2740 | ((struct gid_list_info *)id_iter)->loop_id); | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2741 | id_iter += ha->gid_list_info_size; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2742 |  | 
|  | 2743 | /* Bypass reserved domain fields. */ | 
|  | 2744 | if ((domain & 0xf0) == 0xf0) | 
|  | 2745 | continue; | 
|  | 2746 |  | 
|  | 2747 | /* Bypass if not same domain and area of adapter. */ | 
| Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 2748 | if (area && domain && | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2749 | (area != vha->d_id.b.area || domain != vha->d_id.b.domain)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | continue; | 
|  | 2751 |  | 
|  | 2752 | /* Bypass invalid local loop ID. */ | 
|  | 2753 | if (loop_id > LAST_LOCAL_LOOP_ID) | 
|  | 2754 | continue; | 
|  | 2755 |  | 
|  | 2756 | /* Fill in member data. */ | 
|  | 2757 | new_fcport->d_id.b.domain = domain; | 
|  | 2758 | new_fcport->d_id.b.area = area; | 
|  | 2759 | new_fcport->d_id.b.al_pa = al_pa; | 
|  | 2760 | new_fcport->loop_id = loop_id; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2761 | rval2 = qla2x00_get_port_database(vha, new_fcport, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2762 | if (rval2 != QLA_SUCCESS) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2763 | ql_dbg(ql_dbg_disc, vha, 0x201a, | 
|  | 2764 | "Failed to retrieve fcport information " | 
|  | 2765 | "-- get_port_database=%x, loop_id=0x%04x.\n", | 
|  | 2766 | rval2, new_fcport->loop_id); | 
|  | 2767 | ql_dbg(ql_dbg_disc, vha, 0x201b, | 
|  | 2768 | "Scheduling resync.\n"); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2769 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2770 | continue; | 
|  | 2771 | } | 
|  | 2772 |  | 
|  | 2773 | /* Check for matching device in port list. */ | 
|  | 2774 | found = 0; | 
|  | 2775 | fcport = NULL; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2776 | list_for_each_entry(fcport, &vha->vp_fcports, list) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2777 | if (memcmp(new_fcport->port_name, fcport->port_name, | 
|  | 2778 | WWN_SIZE)) | 
|  | 2779 | continue; | 
|  | 2780 |  | 
| Shyam Sundar | ddb9b12 | 2009-03-24 09:08:10 -0700 | [diff] [blame] | 2781 | fcport->flags &= ~FCF_FABRIC_DEVICE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2782 | fcport->loop_id = new_fcport->loop_id; | 
|  | 2783 | fcport->port_type = new_fcport->port_type; | 
|  | 2784 | fcport->d_id.b24 = new_fcport->d_id.b24; | 
|  | 2785 | memcpy(fcport->node_name, new_fcport->node_name, | 
|  | 2786 | WWN_SIZE); | 
|  | 2787 |  | 
|  | 2788 | found++; | 
|  | 2789 | break; | 
|  | 2790 | } | 
|  | 2791 |  | 
|  | 2792 | if (!found) { | 
|  | 2793 | /* New device, add to fcports list. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2794 | list_add_tail(&new_fcport->list, &vha->vp_fcports); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2795 |  | 
|  | 2796 | /* Allocate a new replacement fcport. */ | 
|  | 2797 | fcport = new_fcport; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2798 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | if (new_fcport == NULL) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2800 | ql_log(ql_log_warn, vha, 0x201c, | 
|  | 2801 | "Failed to allocate memory for fcport.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2802 | rval = QLA_MEMORY_ALLOC_FAILED; | 
|  | 2803 | goto cleanup_allocation; | 
|  | 2804 | } | 
|  | 2805 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; | 
|  | 2806 | } | 
|  | 2807 |  | 
| Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2808 | /* Base iIDMA settings on HBA port speed. */ | 
| Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 2809 | fcport->fp_speed = ha->link_data_rate; | 
| Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2810 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2811 | qla2x00_update_fcport(vha, fcport); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 |  | 
|  | 2813 | found_devs++; | 
|  | 2814 | } | 
|  | 2815 |  | 
|  | 2816 | cleanup_allocation: | 
| Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2817 | kfree(new_fcport); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2818 |  | 
|  | 2819 | if (rval != QLA_SUCCESS) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2820 | ql_dbg(ql_dbg_disc, vha, 0x201d, | 
|  | 2821 | "Configure local loop error exit: rval=%x.\n", rval); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2822 | } | 
|  | 2823 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2824 | return (rval); | 
|  | 2825 | } | 
|  | 2826 |  | 
|  | 2827 | static void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2828 | qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) | 
| Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2829 | { | 
| Andrew Vasquez | 9f8fdde | 2009-06-03 09:55:22 -0700 | [diff] [blame] | 2830 | char *link_speed; | 
| Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2831 | int rval; | 
| Harish Zunjarrao | 1bb3954 | 2009-06-17 10:30:29 -0700 | [diff] [blame] | 2832 | uint16_t mb[4]; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2833 | struct qla_hw_data *ha = vha->hw; | 
| Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2834 |  | 
| Andrew Vasquez | c76f2c0 | 2007-07-19 15:05:57 -0700 | [diff] [blame] | 2835 | if (!IS_IIDMA_CAPABLE(ha)) | 
| Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2836 | return; | 
|  | 2837 |  | 
| Giridhar Malavali | c9afb9a | 2010-09-03 15:20:48 -0700 | [diff] [blame] | 2838 | if (atomic_read(&fcport->state) != FCS_ONLINE) | 
|  | 2839 | return; | 
|  | 2840 |  | 
| Andrew Vasquez | 39bd962 | 2007-09-20 14:07:34 -0700 | [diff] [blame] | 2841 | if (fcport->fp_speed == PORT_SPEED_UNKNOWN || | 
|  | 2842 | fcport->fp_speed > ha->link_data_rate) | 
| Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2843 | return; | 
|  | 2844 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2845 | rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed, | 
| Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 2846 | mb); | 
| Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2847 | if (rval != QLA_SUCCESS) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2848 | ql_dbg(ql_dbg_disc, vha, 0x2004, | 
|  | 2849 | "Unable to adjust iIDMA " | 
|  | 2850 | "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x " | 
|  | 2851 | "%04x.\n", fcport->port_name[0], fcport->port_name[1], | 
| Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2852 | fcport->port_name[2], fcport->port_name[3], | 
|  | 2853 | fcport->port_name[4], fcport->port_name[5], | 
|  | 2854 | fcport->port_name[6], fcport->port_name[7], rval, | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2855 | fcport->fp_speed, mb[0], mb[1]); | 
| Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2856 | } else { | 
| Chad Dupuis | daae62a | 2012-05-15 14:34:23 -0400 | [diff] [blame] | 2857 | link_speed = qla2x00_get_link_speed_str(ha); | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2858 | ql_dbg(ql_dbg_disc, vha, 0x2005, | 
|  | 2859 | "iIDMA adjusted to %s GB/s " | 
|  | 2860 | "on %02x%02x%02x%02x%02x%02x%02x%02x.\n", link_speed, | 
|  | 2861 | fcport->port_name[0], fcport->port_name[1], | 
|  | 2862 | fcport->port_name[2], fcport->port_name[3], | 
|  | 2863 | fcport->port_name[4], fcport->port_name[5], | 
|  | 2864 | fcport->port_name[6], fcport->port_name[7]); | 
| Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2865 | } | 
|  | 2866 | } | 
|  | 2867 |  | 
| Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2868 | static void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2869 | qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport) | 
|  | 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2870 | { | 
|  | 2871 | struct fc_rport_identifiers rport_ids; | 
|  | bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 2872 | struct fc_rport *rport; | 
| Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2873 | unsigned long flags; | 
|  | 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2874 |  | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2875 | qla2x00_rport_del(fcport); | 
|  | 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2876 |  | 
| Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 2877 | rport_ids.node_name = wwn_to_u64(fcport->node_name); | 
|  | 2878 | rport_ids.port_name = wwn_to_u64(fcport->port_name); | 
|  | 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2879 | rport_ids.port_id = fcport->d_id.b.domain << 16 | | 
|  | 2880 | fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa; | 
|  | 2881 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2882 | fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids); | 
| Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 2883 | if (!rport) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2884 | ql_log(ql_log_warn, vha, 0x2006, | 
|  | 2885 | "Unable to allocate fc remote port.\n"); | 
| Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 2886 | return; | 
|  | 2887 | } | 
| Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2888 | /* | 
|  | 2889 | * Create target mode FC NEXUS in qla_target.c if target mode is | 
|  | 2890 | * enabled.. | 
|  | 2891 | */ | 
|  | 2892 | qlt_fc_port_added(vha, fcport); | 
|  | 2893 |  | 
| Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2894 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); | 
| James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2895 | *((fc_port_t **)rport->dd_data) = fcport; | 
| Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2896 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); | 
| andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2897 |  | 
| Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 2898 | rport->supported_classes = fcport->supported_classes; | 
| Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 2899 |  | 
|  | 2900 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; | 
|  | 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2901 | if (fcport->port_type == FCT_INITIATOR) | 
|  | 2902 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; | 
|  | 2903 | if (fcport->port_type == FCT_TARGET) | 
|  | 2904 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; | 
| Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 2905 | fc_remote_port_rolechg(rport, rport_ids.roles); | 
|  | 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2906 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2907 |  | 
|  | 2908 | /* | 
| Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2909 | * qla2x00_update_fcport | 
|  | 2910 | *	Updates device on list. | 
|  | 2911 | * | 
|  | 2912 | * Input: | 
|  | 2913 | *	ha = adapter block pointer. | 
|  | 2914 | *	fcport = port structure pointer. | 
|  | 2915 | * | 
|  | 2916 | * Return: | 
|  | 2917 | *	0  - Success | 
|  | 2918 | *  BIT_0 - error | 
|  | 2919 | * | 
|  | 2920 | * Context: | 
|  | 2921 | *	Kernel context. | 
|  | 2922 | */ | 
|  | 2923 | void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2924 | qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) | 
| Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2925 | { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2926 | fcport->vha = vha; | 
| Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2927 | fcport->login_retry = 0; | 
| Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 2928 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); | 
| Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2929 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2930 | qla2x00_iidma_fcport(vha, fcport); | 
| Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 2931 | qla24xx_update_fcport_fcp_prio(vha, fcport); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2932 | qla2x00_reg_remote_port(vha, fcport); | 
| Chad Dupuis | ec426e1 | 2011-03-30 11:46:32 -0700 | [diff] [blame] | 2933 | qla2x00_set_fcport_state(fcport, FCS_ONLINE); | 
| Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2934 | } | 
|  | 2935 |  | 
|  | 2936 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2937 | * qla2x00_configure_fabric | 
|  | 2938 | *      Setup SNS devices with loop ID's. | 
|  | 2939 | * | 
|  | 2940 | * Input: | 
|  | 2941 | *      ha = adapter block pointer. | 
|  | 2942 | * | 
|  | 2943 | * Returns: | 
|  | 2944 | *      0 = success. | 
|  | 2945 | *      BIT_0 = error | 
|  | 2946 | */ | 
|  | 2947 | static int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2948 | qla2x00_configure_fabric(scsi_qla_host_t *vha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2949 | { | 
| Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 2950 | int	rval; | 
| Joe Carnuccio | 4dc77c3 | 2012-05-15 14:34:24 -0400 | [diff] [blame] | 2951 | fc_port_t	*fcport; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2952 | uint16_t	next_loopid; | 
|  | 2953 | uint16_t	mb[MAILBOX_REGISTER_COUNT]; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2954 | uint16_t	loop_id; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | LIST_HEAD(new_fcports); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2956 | struct qla_hw_data *ha = vha->hw; | 
|  | 2957 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2958 |  | 
|  | 2959 | /* If FL port exists, then SNS is present */ | 
| Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 2960 | if (IS_FWI2_CAPABLE(ha)) | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2961 | loop_id = NPH_F_PORT; | 
|  | 2962 | else | 
|  | 2963 | loop_id = SNS_FL_PORT; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2964 | 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] | 2965 | if (rval != QLA_SUCCESS) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2966 | ql_dbg(ql_dbg_disc, vha, 0x201f, | 
|  | 2967 | "MBX_GET_PORT_NAME failed, No FL Port.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2969 | vha->device_flags &= ~SWITCH_FOUND; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | return (QLA_SUCCESS); | 
|  | 2971 | } | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2972 | vha->device_flags |= SWITCH_FOUND; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2974 | do { | 
| Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 2975 | /* FDMI support. */ | 
|  | 2976 | if (ql2xfdmienable && | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2977 | test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags)) | 
|  | 2978 | qla2x00_fdmi_register(vha); | 
| Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 2979 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2980 | /* Ensure we are logged into the SNS. */ | 
| Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 2981 | if (IS_FWI2_CAPABLE(ha)) | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2982 | loop_id = NPH_SNS; | 
|  | 2983 | else | 
|  | 2984 | loop_id = SIMPLE_NAME_SERVER; | 
| Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 2985 | rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff, | 
|  | 2986 | 0xfc, mb, BIT_1|BIT_0); | 
|  | 2987 | if (rval != QLA_SUCCESS) { | 
|  | 2988 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); | 
| Joe Carnuccio | 4dc77c3 | 2012-05-15 14:34:24 -0400 | [diff] [blame] | 2989 | break; | 
| Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 2990 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2991 | if (mb[0] != MBS_COMMAND_COMPLETE) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2992 | ql_dbg(ql_dbg_disc, vha, 0x2042, | 
|  | 2993 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x " | 
|  | 2994 | "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1], | 
|  | 2995 | mb[2], mb[6], mb[7]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2996 | return (QLA_SUCCESS); | 
|  | 2997 | } | 
|  | 2998 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2999 | if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) { | 
|  | 3000 | if (qla2x00_rft_id(vha)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | /* EMPTY */ | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3002 | ql_dbg(ql_dbg_disc, vha, 0x2045, | 
|  | 3003 | "Register FC-4 TYPE failed.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3004 | } | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3005 | if (qla2x00_rff_id(vha)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3006 | /* EMPTY */ | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3007 | ql_dbg(ql_dbg_disc, vha, 0x2049, | 
|  | 3008 | "Register FC-4 Features failed.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3009 | } | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3010 | if (qla2x00_rnn_id(vha)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | /* EMPTY */ | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3012 | ql_dbg(ql_dbg_disc, vha, 0x204f, | 
|  | 3013 | "Register Node Name failed.\n"); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3014 | } else if (qla2x00_rsnn_nn(vha)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3015 | /* EMPTY */ | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3016 | ql_dbg(ql_dbg_disc, vha, 0x2053, | 
|  | 3017 | "Register Symobilic Node Name failed.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3018 | } | 
|  | 3019 | } | 
|  | 3020 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3021 | rval = qla2x00_find_all_fabric_devs(vha, &new_fcports); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | if (rval != QLA_SUCCESS) | 
|  | 3023 | break; | 
|  | 3024 |  | 
| Joe Carnuccio | 4dc77c3 | 2012-05-15 14:34:24 -0400 | [diff] [blame] | 3025 | /* Add new ports to existing port list */ | 
|  | 3026 | list_splice_tail_init(&new_fcports, &vha->vp_fcports); | 
|  | 3027 |  | 
|  | 3028 | /* Starting free loop ID. */ | 
|  | 3029 | next_loopid = ha->min_external_loopid; | 
|  | 3030 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3031 | list_for_each_entry(fcport, &vha->vp_fcports, list) { | 
|  | 3032 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3033 | break; | 
|  | 3034 |  | 
|  | 3035 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) | 
|  | 3036 | continue; | 
|  | 3037 |  | 
| Joe Carnuccio | 4dc77c3 | 2012-05-15 14:34:24 -0400 | [diff] [blame] | 3038 | /* Logout lost/gone fabric devices (non-FCP2) */ | 
| Joe Carnuccio | c0822b6 | 2012-05-15 14:34:21 -0400 | [diff] [blame] | 3039 | if (fcport->scan_state != QLA_FCPORT_SCAN_FOUND && | 
| Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 3040 | atomic_read(&fcport->state) == FCS_ONLINE) { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3041 | qla2x00_mark_device_lost(vha, fcport, | 
| andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3042 | ql2xplogiabsentdevice, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3043 | if (fcport->loop_id != FC_NO_LOOP_ID && | 
| Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3044 | (fcport->flags & FCF_FCP2_DEVICE) == 0 && | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3045 | fcport->port_type != FCT_INITIATOR && | 
|  | 3046 | fcport->port_type != FCT_BROADCAST) { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3047 | ha->isp_ops->fabric_logout(vha, | 
| Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3048 | fcport->loop_id, | 
|  | 3049 | fcport->d_id.b.domain, | 
|  | 3050 | fcport->d_id.b.area, | 
|  | 3051 | fcport->d_id.b.al_pa); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3052 | } | 
| Joe Carnuccio | c0822b6 | 2012-05-15 14:34:21 -0400 | [diff] [blame] | 3053 | continue; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3054 | } | 
| Joe Carnuccio | c0822b6 | 2012-05-15 14:34:21 -0400 | [diff] [blame] | 3055 | fcport->scan_state = QLA_FCPORT_SCAN_NONE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3056 |  | 
| Joe Carnuccio | 4dc77c3 | 2012-05-15 14:34:24 -0400 | [diff] [blame] | 3057 | /* Login fabric devices that need a login */ | 
|  | 3058 | if ((fcport->flags & FCF_LOGIN_NEEDED) != 0 && | 
|  | 3059 | atomic_read(&vha->loop_down_timer) == 0) { | 
|  | 3060 | if (fcport->loop_id == FC_NO_LOOP_ID) { | 
|  | 3061 | fcport->loop_id = next_loopid; | 
|  | 3062 | rval = qla2x00_find_new_loop_id( | 
|  | 3063 | base_vha, fcport); | 
|  | 3064 | if (rval != QLA_SUCCESS) { | 
|  | 3065 | /* Ran out of IDs to use */ | 
|  | 3066 | continue; | 
|  | 3067 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3068 | } | 
|  | 3069 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 |  | 
|  | bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 3071 | /* Login and update database */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3072 | qla2x00_fabric_dev_login(vha, fcport, &next_loopid); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3073 | } | 
|  | 3074 | } while (0); | 
|  | 3075 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | if (rval) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3077 | ql_dbg(ql_dbg_disc, vha, 0x2068, | 
|  | 3078 | "Configure fabric error exit rval=%d.\n", rval); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3079 | } | 
|  | 3080 |  | 
|  | 3081 | return (rval); | 
|  | 3082 | } | 
|  | 3083 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3084 | /* | 
|  | 3085 | * qla2x00_find_all_fabric_devs | 
|  | 3086 | * | 
|  | 3087 | * Input: | 
|  | 3088 | *	ha = adapter block pointer. | 
|  | 3089 | *	dev = database device entry pointer. | 
|  | 3090 | * | 
|  | 3091 | * Returns: | 
|  | 3092 | *	0 = success. | 
|  | 3093 | * | 
|  | 3094 | * Context: | 
|  | 3095 | *	Kernel context. | 
|  | 3096 | */ | 
|  | 3097 | static int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3098 | qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha, | 
|  | 3099 | struct list_head *new_fcports) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3100 | { | 
|  | 3101 | int		rval; | 
|  | 3102 | uint16_t	loop_id; | 
|  | 3103 | fc_port_t	*fcport, *new_fcport, *fcptemp; | 
|  | 3104 | int		found; | 
|  | 3105 |  | 
|  | 3106 | sw_info_t	*swl; | 
|  | 3107 | int		swl_idx; | 
|  | 3108 | int		first_dev, last_dev; | 
| Mike Waychison | 1516ef4 | 2010-05-04 15:01:31 -0700 | [diff] [blame] | 3109 | port_id_t	wrap = {}, nxt_d_id; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3110 | struct qla_hw_data *ha = vha->hw; | 
|  | 3111 | struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev); | 
| Anirban Chakraborty | ee546b6 | 2009-03-05 11:07:02 -0800 | [diff] [blame] | 3112 | struct scsi_qla_host *tvp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3113 |  | 
|  | 3114 | rval = QLA_SUCCESS; | 
|  | 3115 |  | 
|  | 3116 | /* Try GID_PT to get device list, else GAN. */ | 
| Andrew Vasquez | 7a67735 | 2012-02-09 11:15:56 -0800 | [diff] [blame] | 3117 | if (!ha->swl) | 
| Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 3118 | ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t), | 
| Andrew Vasquez | 7a67735 | 2012-02-09 11:15:56 -0800 | [diff] [blame] | 3119 | GFP_KERNEL); | 
|  | 3120 | swl = ha->swl; | 
| Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 3121 | if (!swl) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3122 | /*EMPTY*/ | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3123 | ql_dbg(ql_dbg_disc, vha, 0x2054, | 
|  | 3124 | "GID_PT allocations failed, fallback on GA_NXT.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3125 | } else { | 
| Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 3126 | memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t)); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3127 | if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3128 | swl = NULL; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3129 | } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3130 | swl = NULL; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3131 | } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3132 | swl = NULL; | 
| Andrew Vasquez | e5896bd | 2008-07-10 16:55:52 -0700 | [diff] [blame] | 3133 | } else if (ql2xiidmaenable && | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3134 | qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) { | 
|  | 3135 | qla2x00_gpsc(vha, swl); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3136 | } | 
| Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3137 |  | 
|  | 3138 | /* If other queries succeeded probe for FC-4 type */ | 
|  | 3139 | if (swl) | 
|  | 3140 | qla2x00_gff_id(vha, swl); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3141 | } | 
|  | 3142 | swl_idx = 0; | 
|  | 3143 |  | 
|  | 3144 | /* Allocate temporary fcport for any new fcports discovered. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3145 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3146 | if (new_fcport == NULL) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3147 | ql_log(ql_log_warn, vha, 0x205e, | 
|  | 3148 | "Failed to allocate memory for fcport.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3149 | return (QLA_MEMORY_ALLOC_FAILED); | 
|  | 3150 | } | 
|  | 3151 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3152 | /* Set start port ID scan at adapter ID. */ | 
|  | 3153 | first_dev = 1; | 
|  | 3154 | last_dev = 0; | 
|  | 3155 |  | 
|  | 3156 | /* Starting free loop ID. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3157 | loop_id = ha->min_external_loopid; | 
|  | 3158 | for (; loop_id <= ha->max_loop_id; loop_id++) { | 
|  | 3159 | if (qla2x00_is_reserved_id(vha, loop_id)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3160 | continue; | 
|  | 3161 |  | 
| Giridhar Malavali | 3a6478d | 2010-05-28 15:08:20 -0700 | [diff] [blame] | 3162 | if (ha->current_topology == ISP_CFG_FL && | 
|  | 3163 | (atomic_read(&vha->loop_down_timer) || | 
|  | 3164 | LOOP_TRANSITION(vha))) { | 
| Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 3165 | atomic_set(&vha->loop_down_timer, 0); | 
|  | 3166 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); | 
|  | 3167 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3168 | break; | 
| Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 3169 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3170 |  | 
|  | 3171 | if (swl != NULL) { | 
|  | 3172 | if (last_dev) { | 
|  | 3173 | wrap.b24 = new_fcport->d_id.b24; | 
|  | 3174 | } else { | 
|  | 3175 | new_fcport->d_id.b24 = swl[swl_idx].d_id.b24; | 
|  | 3176 | memcpy(new_fcport->node_name, | 
|  | 3177 | swl[swl_idx].node_name, WWN_SIZE); | 
|  | 3178 | memcpy(new_fcport->port_name, | 
|  | 3179 | swl[swl_idx].port_name, WWN_SIZE); | 
| Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3180 | memcpy(new_fcport->fabric_port_name, | 
|  | 3181 | swl[swl_idx].fabric_port_name, WWN_SIZE); | 
|  | 3182 | new_fcport->fp_speed = swl[swl_idx].fp_speed; | 
| Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3183 | new_fcport->fc4_type = swl[swl_idx].fc4_type; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3184 |  | 
|  | 3185 | if (swl[swl_idx].d_id.b.rsvd_1 != 0) { | 
|  | 3186 | last_dev = 1; | 
|  | 3187 | } | 
|  | 3188 | swl_idx++; | 
|  | 3189 | } | 
|  | 3190 | } else { | 
|  | 3191 | /* Send GA_NXT to the switch */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3192 | rval = qla2x00_ga_nxt(vha, new_fcport); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3193 | if (rval != QLA_SUCCESS) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3194 | ql_log(ql_log_warn, vha, 0x2064, | 
|  | 3195 | "SNS scan failed -- assuming " | 
|  | 3196 | "zero-entry result.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3197 | list_for_each_entry_safe(fcport, fcptemp, | 
|  | 3198 | new_fcports, list) { | 
|  | 3199 | list_del(&fcport->list); | 
|  | 3200 | kfree(fcport); | 
|  | 3201 | } | 
|  | 3202 | rval = QLA_SUCCESS; | 
|  | 3203 | break; | 
|  | 3204 | } | 
|  | 3205 | } | 
|  | 3206 |  | 
|  | 3207 | /* If wrap on switch device list, exit. */ | 
|  | 3208 | if (first_dev) { | 
|  | 3209 | wrap.b24 = new_fcport->d_id.b24; | 
|  | 3210 | first_dev = 0; | 
|  | 3211 | } else if (new_fcport->d_id.b24 == wrap.b24) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3212 | ql_dbg(ql_dbg_disc, vha, 0x2065, | 
|  | 3213 | "Device wrap (%02x%02x%02x).\n", | 
|  | 3214 | new_fcport->d_id.b.domain, | 
|  | 3215 | new_fcport->d_id.b.area, | 
|  | 3216 | new_fcport->d_id.b.al_pa); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3217 | break; | 
|  | 3218 | } | 
|  | 3219 |  | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3220 | /* Bypass if same physical adapter. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3221 | if (new_fcport->d_id.b24 == base_vha->d_id.b24) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3222 | continue; | 
|  | 3223 |  | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3224 | /* Bypass virtual ports of the same host. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3225 | found = 0; | 
|  | 3226 | if (ha->num_vhosts) { | 
| Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3227 | unsigned long flags; | 
|  | 3228 |  | 
|  | 3229 | spin_lock_irqsave(&ha->vport_slock, flags); | 
| Anirban Chakraborty | ee546b6 | 2009-03-05 11:07:02 -0800 | [diff] [blame] | 3230 | list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3231 | if (new_fcport->d_id.b24 == vp->d_id.b24) { | 
|  | 3232 | found = 1; | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3233 | break; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3234 | } | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3235 | } | 
| Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3236 | spin_unlock_irqrestore(&ha->vport_slock, flags); | 
|  | 3237 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3238 | if (found) | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3239 | continue; | 
|  | 3240 | } | 
|  | 3241 |  | 
| Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 3242 | /* Bypass if same domain and area of adapter. */ | 
|  | 3243 | if (((new_fcport->d_id.b24 & 0xffff00) == | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3244 | (vha->d_id.b24 & 0xffff00)) && ha->current_topology == | 
| Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 3245 | ISP_CFG_FL) | 
|  | 3246 | continue; | 
|  | 3247 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3248 | /* Bypass reserved domain fields. */ | 
|  | 3249 | if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0) | 
|  | 3250 | continue; | 
|  | 3251 |  | 
| Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3252 | /* Bypass ports whose FCP-4 type is not FCP_SCSI */ | 
| Chad Dupuis | 4da26e1 | 2010-10-15 11:27:40 -0700 | [diff] [blame] | 3253 | if (ql2xgffidenable && | 
|  | 3254 | (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI && | 
|  | 3255 | new_fcport->fc4_type != FC4_TYPE_UNKNOWN)) | 
| Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3256 | continue; | 
|  | 3257 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3258 | /* Locate matching device in database. */ | 
|  | 3259 | found = 0; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3260 | list_for_each_entry(fcport, &vha->vp_fcports, list) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3261 | if (memcmp(new_fcport->port_name, fcport->port_name, | 
|  | 3262 | WWN_SIZE)) | 
|  | 3263 | continue; | 
|  | 3264 |  | 
| Joe Carnuccio | c0822b6 | 2012-05-15 14:34:21 -0400 | [diff] [blame] | 3265 | fcport->scan_state = QLA_FCPORT_SCAN_FOUND; | 
| Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 3266 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3267 | found++; | 
|  | 3268 |  | 
| Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3269 | /* Update port state. */ | 
|  | 3270 | memcpy(fcport->fabric_port_name, | 
|  | 3271 | new_fcport->fabric_port_name, WWN_SIZE); | 
|  | 3272 | fcport->fp_speed = new_fcport->fp_speed; | 
|  | 3273 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3274 | /* | 
|  | 3275 | * If address the same and state FCS_ONLINE, nothing | 
|  | 3276 | * changed. | 
|  | 3277 | */ | 
|  | 3278 | if (fcport->d_id.b24 == new_fcport->d_id.b24 && | 
|  | 3279 | atomic_read(&fcport->state) == FCS_ONLINE) { | 
|  | 3280 | break; | 
|  | 3281 | } | 
|  | 3282 |  | 
|  | 3283 | /* | 
|  | 3284 | * If device was not a fabric device before. | 
|  | 3285 | */ | 
|  | 3286 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) { | 
|  | 3287 | fcport->d_id.b24 = new_fcport->d_id.b24; | 
|  | 3288 | fcport->loop_id = FC_NO_LOOP_ID; | 
|  | 3289 | fcport->flags |= (FCF_FABRIC_DEVICE | | 
|  | 3290 | FCF_LOGIN_NEEDED); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3291 | break; | 
|  | 3292 | } | 
|  | 3293 |  | 
|  | 3294 | /* | 
|  | 3295 | * Port ID changed or device was marked to be updated; | 
|  | 3296 | * Log it out if still logged in and mark it for | 
|  | 3297 | * relogin later. | 
|  | 3298 | */ | 
|  | 3299 | fcport->d_id.b24 = new_fcport->d_id.b24; | 
|  | 3300 | fcport->flags |= FCF_LOGIN_NEEDED; | 
|  | 3301 | if (fcport->loop_id != FC_NO_LOOP_ID && | 
| Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3302 | (fcport->flags & FCF_FCP2_DEVICE) == 0 && | 
| Arun Easi | 0eba25d | 2012-02-09 11:15:58 -0800 | [diff] [blame] | 3303 | (fcport->flags & FCF_ASYNC_SENT) == 0 && | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3304 | fcport->port_type != FCT_INITIATOR && | 
|  | 3305 | fcport->port_type != FCT_BROADCAST) { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3306 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, | 
| Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3307 | fcport->d_id.b.domain, fcport->d_id.b.area, | 
|  | 3308 | fcport->d_id.b.al_pa); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3309 | fcport->loop_id = FC_NO_LOOP_ID; | 
|  | 3310 | } | 
|  | 3311 |  | 
|  | 3312 | break; | 
|  | 3313 | } | 
|  | 3314 |  | 
|  | 3315 | if (found) | 
|  | 3316 | continue; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3317 | /* If device was not in our fcports list, then add it. */ | 
|  | 3318 | list_add_tail(&new_fcport->list, new_fcports); | 
|  | 3319 |  | 
|  | 3320 | /* Allocate a new replacement fcport. */ | 
|  | 3321 | nxt_d_id.b24 = new_fcport->d_id.b24; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3322 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3323 | if (new_fcport == NULL) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3324 | ql_log(ql_log_warn, vha, 0x2066, | 
|  | 3325 | "Memory allocation failed for fcport.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3326 | return (QLA_MEMORY_ALLOC_FAILED); | 
|  | 3327 | } | 
|  | 3328 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); | 
|  | 3329 | new_fcport->d_id.b24 = nxt_d_id.b24; | 
|  | 3330 | } | 
|  | 3331 |  | 
| Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 3332 | kfree(new_fcport); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3333 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3334 | return (rval); | 
|  | 3335 | } | 
|  | 3336 |  | 
|  | 3337 | /* | 
|  | 3338 | * qla2x00_find_new_loop_id | 
|  | 3339 | *	Scan through our port list and find a new usable loop ID. | 
|  | 3340 | * | 
|  | 3341 | * Input: | 
|  | 3342 | *	ha:	adapter state pointer. | 
|  | 3343 | *	dev:	port structure pointer. | 
|  | 3344 | * | 
|  | 3345 | * Returns: | 
|  | 3346 | *	qla2x00 local function return status code. | 
|  | 3347 | * | 
|  | 3348 | * Context: | 
|  | 3349 | *	Kernel context. | 
|  | 3350 | */ | 
| Joe Carnuccio | 03bcfb5 | 2011-03-30 11:46:27 -0700 | [diff] [blame] | 3351 | int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3352 | 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] | 3353 | { | 
|  | 3354 | int	rval; | 
|  | 3355 | int	found; | 
|  | 3356 | fc_port_t *fcport; | 
|  | 3357 | uint16_t first_loop_id; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3358 | struct qla_hw_data *ha = vha->hw; | 
|  | 3359 | struct scsi_qla_host *vp; | 
| Anirban Chakraborty | ee546b6 | 2009-03-05 11:07:02 -0800 | [diff] [blame] | 3360 | struct scsi_qla_host *tvp; | 
| Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3361 | unsigned long flags = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3362 |  | 
|  | 3363 | rval = QLA_SUCCESS; | 
|  | 3364 |  | 
|  | 3365 | /* Save starting loop ID. */ | 
|  | 3366 | first_loop_id = dev->loop_id; | 
|  | 3367 |  | 
|  | 3368 | for (;;) { | 
|  | 3369 | /* Skip loop ID if already used by adapter. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3370 | if (dev->loop_id == vha->loop_id) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3371 | dev->loop_id++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3372 |  | 
|  | 3373 | /* Skip reserved loop IDs. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3374 | while (qla2x00_is_reserved_id(vha, dev->loop_id)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | dev->loop_id++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3376 |  | 
|  | 3377 | /* Reset loop ID if passed the end. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3378 | if (dev->loop_id > ha->max_loop_id) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | /* first loop ID. */ | 
|  | 3380 | dev->loop_id = ha->min_external_loopid; | 
|  | 3381 | } | 
|  | 3382 |  | 
|  | 3383 | /* Check for loop ID being already in use. */ | 
|  | 3384 | found = 0; | 
|  | 3385 | fcport = NULL; | 
| Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3386 |  | 
|  | 3387 | spin_lock_irqsave(&ha->vport_slock, flags); | 
| Anirban Chakraborty | ee546b6 | 2009-03-05 11:07:02 -0800 | [diff] [blame] | 3388 | list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3389 | list_for_each_entry(fcport, &vp->vp_fcports, list) { | 
|  | 3390 | if (fcport->loop_id == dev->loop_id && | 
|  | 3391 | fcport != dev) { | 
|  | 3392 | /* ID possibly in use */ | 
|  | 3393 | found++; | 
|  | 3394 | break; | 
|  | 3395 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3396 | } | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3397 | if (found) | 
|  | 3398 | break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3399 | } | 
| Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3400 | spin_unlock_irqrestore(&ha->vport_slock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3401 |  | 
|  | 3402 | /* If not in use then it is free to use. */ | 
|  | 3403 | if (!found) { | 
| Arun Easi | 557cf78 | 2012-02-09 11:15:50 -0800 | [diff] [blame] | 3404 | ql_dbg(ql_dbg_disc, dev->vha, 0x2086, | 
|  | 3405 | "Assigning new loopid=%x, portid=%x.\n", | 
|  | 3406 | dev->loop_id, dev->d_id.b24); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3407 | break; | 
|  | 3408 | } | 
|  | 3409 |  | 
|  | 3410 | /* ID in use. Try next value. */ | 
|  | 3411 | dev->loop_id++; | 
|  | 3412 |  | 
|  | 3413 | /* If wrap around. No free ID to use. */ | 
|  | 3414 | if (dev->loop_id == first_loop_id) { | 
|  | 3415 | dev->loop_id = FC_NO_LOOP_ID; | 
|  | 3416 | rval = QLA_FUNCTION_FAILED; | 
|  | 3417 | break; | 
|  | 3418 | } | 
|  | 3419 | } | 
|  | 3420 |  | 
|  | 3421 | return (rval); | 
|  | 3422 | } | 
|  | 3423 |  | 
|  | 3424 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3425 | * qla2x00_fabric_dev_login | 
|  | 3426 | *	Login fabric target device and update FC port database. | 
|  | 3427 | * | 
|  | 3428 | * Input: | 
|  | 3429 | *	ha:		adapter state pointer. | 
|  | 3430 | *	fcport:		port structure list pointer. | 
|  | 3431 | *	next_loopid:	contains value of a new loop ID that can be used | 
|  | 3432 | *			by the next login attempt. | 
|  | 3433 | * | 
|  | 3434 | * Returns: | 
|  | 3435 | *	qla2x00 local function return status code. | 
|  | 3436 | * | 
|  | 3437 | * Context: | 
|  | 3438 | *	Kernel context. | 
|  | 3439 | */ | 
|  | 3440 | static int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3441 | 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] | 3442 | uint16_t *next_loopid) | 
|  | 3443 | { | 
|  | 3444 | int	rval; | 
|  | 3445 | int	retry; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3446 | uint8_t opts; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3447 | struct qla_hw_data *ha = vha->hw; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3448 |  | 
|  | 3449 | rval = QLA_SUCCESS; | 
|  | 3450 | retry = 0; | 
|  | 3451 |  | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3452 | if (IS_ALOGIO_CAPABLE(ha)) { | 
| Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 3453 | if (fcport->flags & FCF_ASYNC_SENT) | 
|  | 3454 | return rval; | 
|  | 3455 | fcport->flags |= FCF_ASYNC_SENT; | 
| Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3456 | rval = qla2x00_post_async_login_work(vha, fcport, NULL); | 
|  | 3457 | if (!rval) | 
|  | 3458 | return rval; | 
|  | 3459 | } | 
|  | 3460 |  | 
| Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 3461 | fcport->flags &= ~FCF_ASYNC_SENT; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3462 | rval = qla2x00_fabric_login(vha, fcport, next_loopid); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3463 | if (rval == QLA_SUCCESS) { | 
| Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3464 | /* Send an ADISC to FCP2 devices.*/ | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3465 | opts = 0; | 
| Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3466 | if (fcport->flags & FCF_FCP2_DEVICE) | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3467 | opts |= BIT_1; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3468 | rval = qla2x00_get_port_database(vha, fcport, opts); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3469 | if (rval != QLA_SUCCESS) { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3470 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, | 
| Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3471 | fcport->d_id.b.domain, fcport->d_id.b.area, | 
|  | 3472 | fcport->d_id.b.al_pa); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3473 | qla2x00_mark_device_lost(vha, fcport, 1, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3474 | } else { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3475 | qla2x00_update_fcport(vha, fcport); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3476 | } | 
| Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 3477 | } else { | 
|  | 3478 | /* Retry Login. */ | 
|  | 3479 | qla2x00_mark_device_lost(vha, fcport, 1, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3480 | } | 
|  | 3481 |  | 
|  | 3482 | return (rval); | 
|  | 3483 | } | 
|  | 3484 |  | 
|  | 3485 | /* | 
|  | 3486 | * qla2x00_fabric_login | 
|  | 3487 | *	Issue fabric login command. | 
|  | 3488 | * | 
|  | 3489 | * Input: | 
|  | 3490 | *	ha = adapter block pointer. | 
|  | 3491 | *	device = pointer to FC device type structure. | 
|  | 3492 | * | 
|  | 3493 | * Returns: | 
|  | 3494 | *      0 - Login successfully | 
|  | 3495 | *      1 - Login failed | 
|  | 3496 | *      2 - Initiator device | 
|  | 3497 | *      3 - Fatal error | 
|  | 3498 | */ | 
|  | 3499 | int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3500 | qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3501 | uint16_t *next_loopid) | 
|  | 3502 | { | 
|  | 3503 | int	rval; | 
|  | 3504 | int	retry; | 
|  | 3505 | uint16_t tmp_loopid; | 
|  | 3506 | uint16_t mb[MAILBOX_REGISTER_COUNT]; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3507 | struct qla_hw_data *ha = vha->hw; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3508 |  | 
|  | 3509 | retry = 0; | 
|  | 3510 | tmp_loopid = 0; | 
|  | 3511 |  | 
|  | 3512 | for (;;) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3513 | ql_dbg(ql_dbg_disc, vha, 0x2000, | 
|  | 3514 | "Trying Fabric Login w/loop id 0x%04x for port " | 
|  | 3515 | "%02x%02x%02x.\n", | 
|  | 3516 | fcport->loop_id, fcport->d_id.b.domain, | 
|  | 3517 | fcport->d_id.b.area, fcport->d_id.b.al_pa); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3518 |  | 
|  | 3519 | /* Login fcport on switch. */ | 
| Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 3520 | rval = ha->isp_ops->fabric_login(vha, fcport->loop_id, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3521 | fcport->d_id.b.domain, fcport->d_id.b.area, | 
|  | 3522 | fcport->d_id.b.al_pa, mb, BIT_0); | 
| Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 3523 | if (rval != QLA_SUCCESS) { | 
|  | 3524 | return rval; | 
|  | 3525 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3526 | if (mb[0] == MBS_PORT_ID_USED) { | 
|  | 3527 | /* | 
|  | 3528 | * Device has another loop ID.  The firmware team | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3529 | * recommends the driver perform an implicit login with | 
|  | 3530 | * the specified ID again. The ID we just used is save | 
|  | 3531 | * here so we return with an ID that can be tried by | 
|  | 3532 | * the next login. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3533 | */ | 
|  | 3534 | retry++; | 
|  | 3535 | tmp_loopid = fcport->loop_id; | 
|  | 3536 | fcport->loop_id = mb[1]; | 
|  | 3537 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3538 | ql_dbg(ql_dbg_disc, vha, 0x2001, | 
|  | 3539 | "Fabric Login: port in use - next loop " | 
|  | 3540 | "id=0x%04x, port id= %02x%02x%02x.\n", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | fcport->loop_id, fcport->d_id.b.domain, | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3542 | fcport->d_id.b.area, fcport->d_id.b.al_pa); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3543 |  | 
|  | 3544 | } else if (mb[0] == MBS_COMMAND_COMPLETE) { | 
|  | 3545 | /* | 
|  | 3546 | * Login succeeded. | 
|  | 3547 | */ | 
|  | 3548 | if (retry) { | 
|  | 3549 | /* A retry occurred before. */ | 
|  | 3550 | *next_loopid = tmp_loopid; | 
|  | 3551 | } else { | 
|  | 3552 | /* | 
|  | 3553 | * No retry occurred before. Just increment the | 
|  | 3554 | * ID value for next login. | 
|  | 3555 | */ | 
|  | 3556 | *next_loopid = (fcport->loop_id + 1); | 
|  | 3557 | } | 
|  | 3558 |  | 
|  | 3559 | if (mb[1] & BIT_0) { | 
|  | 3560 | fcport->port_type = FCT_INITIATOR; | 
|  | 3561 | } else { | 
|  | 3562 | fcport->port_type = FCT_TARGET; | 
|  | 3563 | if (mb[1] & BIT_1) { | 
| Santosh Vernekar | 8474f3a | 2009-08-25 11:36:16 -0700 | [diff] [blame] | 3564 | fcport->flags |= FCF_FCP2_DEVICE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3565 | } | 
|  | 3566 | } | 
|  | 3567 |  | 
| Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 3568 | if (mb[10] & BIT_0) | 
|  | 3569 | fcport->supported_classes |= FC_COS_CLASS2; | 
|  | 3570 | if (mb[10] & BIT_1) | 
|  | 3571 | fcport->supported_classes |= FC_COS_CLASS3; | 
|  | 3572 |  | 
| Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3573 | if (IS_FWI2_CAPABLE(ha)) { | 
|  | 3574 | if (mb[10] & BIT_7) | 
|  | 3575 | fcport->flags |= | 
|  | 3576 | FCF_CONF_COMP_SUPPORTED; | 
|  | 3577 | } | 
|  | 3578 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3579 | rval = QLA_SUCCESS; | 
|  | 3580 | break; | 
|  | 3581 | } else if (mb[0] == MBS_LOOP_ID_USED) { | 
|  | 3582 | /* | 
|  | 3583 | * Loop ID already used, try next loop ID. | 
|  | 3584 | */ | 
|  | 3585 | fcport->loop_id++; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3586 | rval = qla2x00_find_new_loop_id(vha, fcport); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3587 | if (rval != QLA_SUCCESS) { | 
|  | 3588 | /* Ran out of loop IDs to use */ | 
|  | 3589 | break; | 
|  | 3590 | } | 
|  | 3591 | } else if (mb[0] == MBS_COMMAND_ERROR) { | 
|  | 3592 | /* | 
|  | 3593 | * Firmware possibly timed out during login. If NO | 
|  | 3594 | * retries are left to do then the device is declared | 
|  | 3595 | * dead. | 
|  | 3596 | */ | 
|  | 3597 | *next_loopid = fcport->loop_id; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3598 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, | 
| Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3599 | fcport->d_id.b.domain, fcport->d_id.b.area, | 
|  | 3600 | fcport->d_id.b.al_pa); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3601 | qla2x00_mark_device_lost(vha, fcport, 1, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3602 |  | 
|  | 3603 | rval = 1; | 
|  | 3604 | break; | 
|  | 3605 | } else { | 
|  | 3606 | /* | 
|  | 3607 | * unrecoverable / not handled error | 
|  | 3608 | */ | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3609 | ql_dbg(ql_dbg_disc, vha, 0x2002, | 
|  | 3610 | "Failed=%x port_id=%02x%02x%02x loop_id=%x " | 
|  | 3611 | "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain, | 
|  | 3612 | fcport->d_id.b.area, fcport->d_id.b.al_pa, | 
|  | 3613 | fcport->loop_id, jiffies); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3614 |  | 
|  | 3615 | *next_loopid = fcport->loop_id; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3616 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, | 
| Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3617 | fcport->d_id.b.domain, fcport->d_id.b.area, | 
|  | 3618 | fcport->d_id.b.al_pa); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | fcport->loop_id = FC_NO_LOOP_ID; | 
| Andrew Vasquez | 0eedfcf | 2005-10-27 11:09:38 -0700 | [diff] [blame] | 3620 | fcport->login_retry = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3621 |  | 
|  | 3622 | rval = 3; | 
|  | 3623 | break; | 
|  | 3624 | } | 
|  | 3625 | } | 
|  | 3626 |  | 
|  | 3627 | return (rval); | 
|  | 3628 | } | 
|  | 3629 |  | 
|  | 3630 | /* | 
|  | 3631 | * qla2x00_local_device_login | 
|  | 3632 | *	Issue local device login command. | 
|  | 3633 | * | 
|  | 3634 | * Input: | 
|  | 3635 | *	ha = adapter block pointer. | 
|  | 3636 | *	loop_id = loop id of device to login to. | 
|  | 3637 | * | 
|  | 3638 | * Returns (Where's the #define!!!!): | 
|  | 3639 | *      0 - Login successfully | 
|  | 3640 | *      1 - Login failed | 
|  | 3641 | *      3 - Fatal error | 
|  | 3642 | */ | 
|  | 3643 | int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3644 | 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] | 3645 | { | 
|  | 3646 | int		rval; | 
|  | 3647 | uint16_t	mb[MAILBOX_REGISTER_COUNT]; | 
|  | 3648 |  | 
|  | 3649 | memset(mb, 0, sizeof(mb)); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3650 | rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3651 | if (rval == QLA_SUCCESS) { | 
|  | 3652 | /* Interrogate mailbox registers for any errors */ | 
|  | 3653 | if (mb[0] == MBS_COMMAND_ERROR) | 
|  | 3654 | rval = 1; | 
|  | 3655 | else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR) | 
|  | 3656 | /* device not in PCB table */ | 
|  | 3657 | rval = 3; | 
|  | 3658 | } | 
|  | 3659 |  | 
|  | 3660 | return (rval); | 
|  | 3661 | } | 
|  | 3662 |  | 
|  | 3663 | /* | 
|  | 3664 | *  qla2x00_loop_resync | 
|  | 3665 | *      Resync with fibre channel devices. | 
|  | 3666 | * | 
|  | 3667 | * Input: | 
|  | 3668 | *      ha = adapter block pointer. | 
|  | 3669 | * | 
|  | 3670 | * Returns: | 
|  | 3671 | *      0 = success | 
|  | 3672 | */ | 
|  | 3673 | int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3674 | qla2x00_loop_resync(scsi_qla_host_t *vha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3675 | { | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3676 | int rval = QLA_SUCCESS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3677 | uint32_t wait_time; | 
| Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 3678 | struct req_que *req; | 
|  | 3679 | struct rsp_que *rsp; | 
|  | 3680 |  | 
| Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 3681 | if (vha->hw->flags.cpu_affinity_enabled) | 
| Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 3682 | req = vha->hw->req_q_map[0]; | 
|  | 3683 | else | 
|  | 3684 | req = vha->req; | 
|  | 3685 | rsp = req->rsp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3686 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3687 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); | 
|  | 3688 | if (vha->flags.online) { | 
|  | 3689 | if (!(rval = qla2x00_fw_ready(vha))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3690 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ | 
|  | 3691 | wait_time = 256; | 
|  | 3692 | do { | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3693 | /* Issue a marker after FW becomes ready. */ | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3694 | qla2x00_marker(vha, req, rsp, 0, 0, | 
|  | 3695 | MK_SYNC_ALL); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3696 | vha->marker_needed = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3697 |  | 
|  | 3698 | /* Remap devices on Loop. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3699 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3700 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3701 | qla2x00_configure_loop(vha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3702 | wait_time--; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3703 | } while (!atomic_read(&vha->loop_down_timer) && | 
|  | 3704 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) | 
|  | 3705 | && wait_time && (test_bit(LOOP_RESYNC_NEEDED, | 
|  | 3706 | &vha->dpc_flags))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3707 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3708 | } | 
|  | 3709 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3710 | if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3711 | return (QLA_FUNCTION_FAILED); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3712 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3713 | if (rval) | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3714 | ql_dbg(ql_dbg_disc, vha, 0x206c, | 
|  | 3715 | "%s *** FAILED ***.\n", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3716 |  | 
|  | 3717 | return (rval); | 
|  | 3718 | } | 
|  | 3719 |  | 
| Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 3720 | /* | 
|  | 3721 | * qla2x00_perform_loop_resync | 
|  | 3722 | * Description: This function will set the appropriate flags and call | 
|  | 3723 | *              qla2x00_loop_resync. If successful loop will be resynced | 
|  | 3724 | * Arguments : scsi_qla_host_t pointer | 
|  | 3725 | * returm    : Success or Failure | 
|  | 3726 | */ | 
|  | 3727 |  | 
|  | 3728 | int qla2x00_perform_loop_resync(scsi_qla_host_t *ha) | 
|  | 3729 | { | 
|  | 3730 | int32_t rval = 0; | 
|  | 3731 |  | 
|  | 3732 | if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) { | 
|  | 3733 | /*Configure the flags so that resync happens properly*/ | 
|  | 3734 | atomic_set(&ha->loop_down_timer, 0); | 
|  | 3735 | if (!(ha->device_flags & DFLG_NO_CABLE)) { | 
|  | 3736 | atomic_set(&ha->loop_state, LOOP_UP); | 
|  | 3737 | set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); | 
|  | 3738 | set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags); | 
|  | 3739 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); | 
|  | 3740 |  | 
|  | 3741 | rval = qla2x00_loop_resync(ha); | 
|  | 3742 | } else | 
|  | 3743 | atomic_set(&ha->loop_state, LOOP_DEAD); | 
|  | 3744 |  | 
|  | 3745 | clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags); | 
|  | 3746 | } | 
|  | 3747 |  | 
|  | 3748 | return rval; | 
|  | 3749 | } | 
|  | 3750 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3751 | void | 
| Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 3752 | qla2x00_update_fcports(scsi_qla_host_t *base_vha) | 
| andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3753 | { | 
|  | 3754 | fc_port_t *fcport; | 
| Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3755 | struct scsi_qla_host *vha; | 
|  | 3756 | struct qla_hw_data *ha = base_vha->hw; | 
|  | 3757 | unsigned long flags; | 
| andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3758 |  | 
| Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3759 | spin_lock_irqsave(&ha->vport_slock, flags); | 
| andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3760 | /* Go with deferred removal of rport references. */ | 
| Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3761 | list_for_each_entry(vha, &base_vha->hw->vp_list, list) { | 
|  | 3762 | atomic_inc(&vha->vref_count); | 
|  | 3763 | list_for_each_entry(fcport, &vha->vp_fcports, list) { | 
| Dan Carpenter | 8ae598d | 2010-12-21 16:00:15 -0800 | [diff] [blame] | 3764 | if (fcport->drport && | 
| Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3765 | atomic_read(&fcport->state) != FCS_UNCONFIGURED) { | 
|  | 3766 | spin_unlock_irqrestore(&ha->vport_slock, flags); | 
|  | 3767 |  | 
| Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 3768 | qla2x00_rport_del(fcport); | 
| Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3769 |  | 
|  | 3770 | spin_lock_irqsave(&ha->vport_slock, flags); | 
|  | 3771 | } | 
|  | 3772 | } | 
|  | 3773 | atomic_dec(&vha->vref_count); | 
|  | 3774 | } | 
|  | 3775 | spin_unlock_irqrestore(&ha->vport_slock, flags); | 
| andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3776 | } | 
|  | 3777 |  | 
| Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 3778 | /* | 
|  | 3779 | * qla82xx_quiescent_state_cleanup | 
|  | 3780 | * Description: This function will block the new I/Os | 
|  | 3781 | *              Its not aborting any I/Os as context | 
|  | 3782 | *              is not destroyed during quiescence | 
|  | 3783 | * Arguments: scsi_qla_host_t | 
|  | 3784 | * return   : void | 
|  | 3785 | */ | 
|  | 3786 | void | 
|  | 3787 | qla82xx_quiescent_state_cleanup(scsi_qla_host_t *vha) | 
|  | 3788 | { | 
|  | 3789 | struct qla_hw_data *ha = vha->hw; | 
|  | 3790 | struct scsi_qla_host *vp; | 
|  | 3791 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3792 | ql_dbg(ql_dbg_p3p, vha, 0xb002, | 
|  | 3793 | "Performing ISP error recovery - ha=%p.\n", ha); | 
| Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 3794 |  | 
|  | 3795 | atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); | 
|  | 3796 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { | 
|  | 3797 | atomic_set(&vha->loop_state, LOOP_DOWN); | 
|  | 3798 | qla2x00_mark_all_devices_lost(vha, 0); | 
|  | 3799 | list_for_each_entry(vp, &ha->vp_list, list) | 
|  | 3800 | qla2x00_mark_all_devices_lost(vha, 0); | 
|  | 3801 | } else { | 
|  | 3802 | if (!atomic_read(&vha->loop_down_timer)) | 
|  | 3803 | atomic_set(&vha->loop_down_timer, | 
|  | 3804 | LOOP_DOWN_TIME); | 
|  | 3805 | } | 
|  | 3806 | /* Wait for pending cmds to complete */ | 
|  | 3807 | qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST); | 
|  | 3808 | } | 
|  | 3809 |  | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3810 | void | 
|  | 3811 | qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha) | 
|  | 3812 | { | 
|  | 3813 | struct qla_hw_data *ha = vha->hw; | 
| Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 3814 | struct scsi_qla_host *vp; | 
| Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3815 | unsigned long flags; | 
| Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 3816 | fc_port_t *fcport; | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3817 |  | 
| Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 3818 | /* For ISP82XX, driver waits for completion of the commands. | 
|  | 3819 | * online flag should be set. | 
|  | 3820 | */ | 
|  | 3821 | if (!IS_QLA82XX(ha)) | 
|  | 3822 | vha->flags.online = 0; | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3823 | ha->flags.chip_reset_done = 0; | 
|  | 3824 | clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); | 
| Saurav Kashyap | 2be21fa | 2012-05-15 14:34:16 -0400 | [diff] [blame] | 3825 | vha->qla_stats.total_isp_aborts++; | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3826 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3827 | ql_log(ql_log_info, vha, 0x00af, | 
|  | 3828 | "Performing ISP error recovery - ha=%p.\n", ha); | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3829 |  | 
| Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 3830 | /* For ISP82XX, reset_chip is just disabling interrupts. | 
|  | 3831 | * Driver waits for the completion of the commands. | 
|  | 3832 | * the interrupts need to be enabled. | 
|  | 3833 | */ | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3834 | if (!IS_QLA82XX(ha)) | 
|  | 3835 | ha->isp_ops->reset_chip(vha); | 
|  | 3836 |  | 
|  | 3837 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); | 
|  | 3838 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { | 
|  | 3839 | atomic_set(&vha->loop_state, LOOP_DOWN); | 
|  | 3840 | qla2x00_mark_all_devices_lost(vha, 0); | 
| Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3841 |  | 
|  | 3842 | spin_lock_irqsave(&ha->vport_slock, flags); | 
| Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 3843 | list_for_each_entry(vp, &ha->vp_list, list) { | 
| Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3844 | atomic_inc(&vp->vref_count); | 
|  | 3845 | spin_unlock_irqrestore(&ha->vport_slock, flags); | 
|  | 3846 |  | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3847 | qla2x00_mark_all_devices_lost(vp, 0); | 
| Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3848 |  | 
|  | 3849 | spin_lock_irqsave(&ha->vport_slock, flags); | 
|  | 3850 | atomic_dec(&vp->vref_count); | 
|  | 3851 | } | 
|  | 3852 | spin_unlock_irqrestore(&ha->vport_slock, flags); | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3853 | } else { | 
|  | 3854 | if (!atomic_read(&vha->loop_down_timer)) | 
|  | 3855 | atomic_set(&vha->loop_down_timer, | 
|  | 3856 | LOOP_DOWN_TIME); | 
|  | 3857 | } | 
|  | 3858 |  | 
| Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 3859 | /* Clear all async request states across all VPs. */ | 
|  | 3860 | list_for_each_entry(fcport, &vha->vp_fcports, list) | 
|  | 3861 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); | 
|  | 3862 | spin_lock_irqsave(&ha->vport_slock, flags); | 
|  | 3863 | list_for_each_entry(vp, &ha->vp_list, list) { | 
|  | 3864 | atomic_inc(&vp->vref_count); | 
|  | 3865 | spin_unlock_irqrestore(&ha->vport_slock, flags); | 
|  | 3866 |  | 
|  | 3867 | list_for_each_entry(fcport, &vp->vp_fcports, list) | 
|  | 3868 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); | 
|  | 3869 |  | 
|  | 3870 | spin_lock_irqsave(&ha->vport_slock, flags); | 
|  | 3871 | atomic_dec(&vp->vref_count); | 
|  | 3872 | } | 
|  | 3873 | spin_unlock_irqrestore(&ha->vport_slock, flags); | 
|  | 3874 |  | 
| Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 3875 | if (!ha->flags.eeh_busy) { | 
|  | 3876 | /* Make sure for ISP 82XX IO DMA is complete */ | 
|  | 3877 | if (IS_QLA82XX(ha)) { | 
| Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 3878 | qla82xx_chip_reset_cleanup(vha); | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3879 | ql_log(ql_log_info, vha, 0x00b4, | 
|  | 3880 | "Done chip reset cleanup.\n"); | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3881 |  | 
| Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 3882 | /* Done waiting for pending commands. | 
|  | 3883 | * Reset the online flag. | 
|  | 3884 | */ | 
|  | 3885 | vha->flags.online = 0; | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3886 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3887 |  | 
| Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 3888 | /* Requeue all commands in outstanding command list. */ | 
|  | 3889 | qla2x00_abort_all_cmds(vha, DID_RESET << 16); | 
|  | 3890 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3891 | } | 
|  | 3892 |  | 
|  | 3893 | /* | 
|  | 3894 | *  qla2x00_abort_isp | 
|  | 3895 | *      Resets ISP and aborts all outstanding commands. | 
|  | 3896 | * | 
|  | 3897 | * Input: | 
|  | 3898 | *      ha           = adapter block pointer. | 
|  | 3899 | * | 
|  | 3900 | * Returns: | 
|  | 3901 | *      0 = success | 
|  | 3902 | */ | 
|  | 3903 | int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3904 | qla2x00_abort_isp(scsi_qla_host_t *vha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3905 | { | 
| Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 3906 | int rval; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3907 | uint8_t        status = 0; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3908 | struct qla_hw_data *ha = vha->hw; | 
|  | 3909 | struct scsi_qla_host *vp; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3910 | struct req_que *req = ha->req_q_map[0]; | 
| Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3911 | unsigned long flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3912 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3913 | if (vha->flags.online) { | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3914 | qla2x00_abort_isp_cleanup(vha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3915 |  | 
| Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 3916 | if (unlikely(pci_channel_offline(ha->pdev) && | 
|  | 3917 | ha->flags.pci_channel_io_perm_failure)) { | 
|  | 3918 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); | 
|  | 3919 | status = 0; | 
|  | 3920 | return status; | 
|  | 3921 | } | 
|  | 3922 |  | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3923 | ha->isp_ops->get_flash_version(vha, req->ring); | 
| Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 3924 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3925 | ha->isp_ops->nvram_config(vha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3926 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3927 | if (!qla2x00_restart_isp(vha)) { | 
|  | 3928 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3929 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3930 | if (!atomic_read(&vha->loop_down_timer)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3931 | /* | 
|  | 3932 | * Issue marker command only when we are going | 
|  | 3933 | * to start the I/O . | 
|  | 3934 | */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3935 | vha->marker_needed = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3936 | } | 
|  | 3937 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3938 | vha->flags.online = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3939 |  | 
| Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 3940 | ha->isp_ops->enable_intrs(ha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3941 |  | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3942 | ha->isp_abort_cnt = 0; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3943 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); | 
| Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 3944 |  | 
| Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3945 | if (IS_QLA81XX(ha) || IS_QLA8031(ha)) | 
|  | 3946 | qla2x00_get_fw_version(vha); | 
| Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 3947 | if (ha->fce) { | 
|  | 3948 | ha->flags.fce_enabled = 1; | 
|  | 3949 | memset(ha->fce, 0, | 
|  | 3950 | fce_calc_size(ha->fce_bufs)); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3951 | rval = qla2x00_enable_fce_trace(vha, | 
| Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 3952 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, | 
|  | 3953 | &ha->fce_bufs); | 
|  | 3954 | if (rval) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3955 | ql_log(ql_log_warn, vha, 0x8033, | 
| Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 3956 | "Unable to reinitialize FCE " | 
|  | 3957 | "(%d).\n", rval); | 
|  | 3958 | ha->flags.fce_enabled = 0; | 
|  | 3959 | } | 
|  | 3960 | } | 
| Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 3961 |  | 
|  | 3962 | if (ha->eft) { | 
|  | 3963 | memset(ha->eft, 0, EFT_SIZE); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3964 | rval = qla2x00_enable_eft_trace(vha, | 
| Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 3965 | ha->eft_dma, EFT_NUM_BUFFERS); | 
|  | 3966 | if (rval) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3967 | ql_log(ql_log_warn, vha, 0x8034, | 
| Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 3968 | "Unable to reinitialize EFT " | 
|  | 3969 | "(%d).\n", rval); | 
|  | 3970 | } | 
|  | 3971 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3972 | } else {	/* failed the ISP abort */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3973 | vha->flags.online = 1; | 
|  | 3974 | if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3975 | if (ha->isp_abort_cnt == 0) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3976 | ql_log(ql_log_fatal, vha, 0x8035, | 
|  | 3977 | "ISP error recover failed - " | 
|  | 3978 | "board disabled.\n"); | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3979 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3980 | * The next call disables the board | 
|  | 3981 | * completely. | 
|  | 3982 | */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3983 | ha->isp_ops->reset_adapter(vha); | 
|  | 3984 | vha->flags.online = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3985 | clear_bit(ISP_ABORT_RETRY, | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3986 | &vha->dpc_flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3987 | status = 0; | 
|  | 3988 | } else { /* schedule another ISP abort */ | 
|  | 3989 | ha->isp_abort_cnt--; | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3990 | ql_dbg(ql_dbg_taskm, vha, 0x8020, | 
|  | 3991 | "ISP abort - retry remaining %d.\n", | 
|  | 3992 | ha->isp_abort_cnt); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3993 | status = 1; | 
|  | 3994 | } | 
|  | 3995 | } else { | 
|  | 3996 | ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT; | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3997 | ql_dbg(ql_dbg_taskm, vha, 0x8021, | 
|  | 3998 | "ISP error recovery - retrying (%d) " | 
|  | 3999 | "more times.\n", ha->isp_abort_cnt); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4000 | set_bit(ISP_ABORT_RETRY, &vha->dpc_flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4001 | status = 1; | 
|  | 4002 | } | 
|  | 4003 | } | 
| Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4004 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4005 | } | 
|  | 4006 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4007 | if (!status) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4008 | ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__); | 
| Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4009 |  | 
|  | 4010 | spin_lock_irqsave(&ha->vport_slock, flags); | 
|  | 4011 | list_for_each_entry(vp, &ha->vp_list, list) { | 
|  | 4012 | if (vp->vp_idx) { | 
|  | 4013 | atomic_inc(&vp->vref_count); | 
|  | 4014 | spin_unlock_irqrestore(&ha->vport_slock, flags); | 
|  | 4015 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4016 | qla2x00_vp_abort_isp(vp); | 
| Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4017 |  | 
|  | 4018 | spin_lock_irqsave(&ha->vport_slock, flags); | 
|  | 4019 | atomic_dec(&vp->vref_count); | 
|  | 4020 | } | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4021 | } | 
| Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4022 | spin_unlock_irqrestore(&ha->vport_slock, flags); | 
|  | 4023 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4024 | } else { | 
| Joe Perches | d8424f6 | 2011-11-18 09:03:06 -0800 | [diff] [blame] | 4025 | ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n", | 
|  | 4026 | __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4027 | } | 
|  | 4028 |  | 
|  | 4029 | return(status); | 
|  | 4030 | } | 
|  | 4031 |  | 
|  | 4032 | /* | 
|  | 4033 | *  qla2x00_restart_isp | 
|  | 4034 | *      restarts the ISP after a reset | 
|  | 4035 | * | 
|  | 4036 | * Input: | 
|  | 4037 | *      ha = adapter block pointer. | 
|  | 4038 | * | 
|  | 4039 | * Returns: | 
|  | 4040 | *      0 = success | 
|  | 4041 | */ | 
|  | 4042 | static int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4043 | qla2x00_restart_isp(scsi_qla_host_t *vha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4044 | { | 
| Andrew Vasquez | c6b2fca | 2009-03-05 11:07:03 -0800 | [diff] [blame] | 4045 | int status = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4046 | uint32_t wait_time; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4047 | struct qla_hw_data *ha = vha->hw; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4048 | struct req_que *req = ha->req_q_map[0]; | 
|  | 4049 | struct rsp_que *rsp = ha->rsp_q_map[0]; | 
| Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4050 | unsigned long flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4051 |  | 
|  | 4052 | /* If firmware needs to be loaded */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4053 | if (qla2x00_isp_firmware(vha)) { | 
|  | 4054 | vha->flags.online = 0; | 
|  | 4055 | status = ha->isp_ops->chip_diag(vha); | 
|  | 4056 | if (!status) | 
|  | 4057 | status = qla2x00_setup_chip(vha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4058 | } | 
|  | 4059 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4060 | if (!status && !(status = qla2x00_init_rings(vha))) { | 
|  | 4061 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); | 
| Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 4062 | ha->flags.chip_reset_done = 1; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4063 | /* Initialize the queues in use */ | 
|  | 4064 | qla25xx_init_queues(ha); | 
|  | 4065 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4066 | status = qla2x00_fw_ready(vha); | 
|  | 4067 | if (!status) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4068 | ql_dbg(ql_dbg_taskm, vha, 0x8031, | 
|  | 4069 | "Start configure loop status = %d.\n", status); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4070 |  | 
|  | 4071 | /* Issue a marker after FW becomes ready. */ | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4072 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4073 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4074 | vha->flags.online = 1; | 
| Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4075 |  | 
|  | 4076 | /* | 
|  | 4077 | * Process any ATIO queue entries that came in | 
|  | 4078 | * while we weren't online. | 
|  | 4079 | */ | 
|  | 4080 | spin_lock_irqsave(&ha->hardware_lock, flags); | 
|  | 4081 | if (qla_tgt_mode_enabled(vha)) | 
|  | 4082 | qlt_24xx_process_atio_queue(vha); | 
|  | 4083 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
|  | 4084 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4085 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ | 
|  | 4086 | wait_time = 256; | 
|  | 4087 | do { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4088 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); | 
|  | 4089 | qla2x00_configure_loop(vha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4090 | wait_time--; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4091 | } while (!atomic_read(&vha->loop_down_timer) && | 
|  | 4092 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) | 
|  | 4093 | && wait_time && (test_bit(LOOP_RESYNC_NEEDED, | 
|  | 4094 | &vha->dpc_flags))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4095 | } | 
|  | 4096 |  | 
|  | 4097 | /* if no cable then assume it's good */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4098 | if ((vha->device_flags & DFLG_NO_CABLE)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4099 | status = 0; | 
|  | 4100 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4101 | ql_dbg(ql_dbg_taskm, vha, 0x8032, | 
|  | 4102 | "Configure loop done, status = 0x%x.\n", status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4103 | } | 
|  | 4104 | return (status); | 
|  | 4105 | } | 
|  | 4106 |  | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4107 | static int | 
|  | 4108 | qla25xx_init_queues(struct qla_hw_data *ha) | 
|  | 4109 | { | 
|  | 4110 | struct rsp_que *rsp = NULL; | 
|  | 4111 | struct req_que *req = NULL; | 
|  | 4112 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); | 
|  | 4113 | int ret = -1; | 
|  | 4114 | int i; | 
|  | 4115 |  | 
| Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 4116 | for (i = 1; i < ha->max_rsp_queues; i++) { | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4117 | rsp = ha->rsp_q_map[i]; | 
|  | 4118 | if (rsp) { | 
|  | 4119 | rsp->options &= ~BIT_0; | 
| Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 4120 | ret = qla25xx_init_rsp_que(base_vha, rsp); | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4121 | if (ret != QLA_SUCCESS) | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4122 | ql_dbg(ql_dbg_init, base_vha, 0x00ff, | 
|  | 4123 | "%s Rsp que: %d init failed.\n", | 
|  | 4124 | __func__, rsp->id); | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4125 | else | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4126 | ql_dbg(ql_dbg_init, base_vha, 0x0100, | 
|  | 4127 | "%s Rsp que: %d inited.\n", | 
|  | 4128 | __func__, rsp->id); | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4129 | } | 
| Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 4130 | } | 
|  | 4131 | for (i = 1; i < ha->max_req_queues; i++) { | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4132 | req = ha->req_q_map[i]; | 
|  | 4133 | if (req) { | 
| Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 4134 | /* Clear outstanding commands array. */ | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4135 | req->options &= ~BIT_0; | 
| Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 4136 | ret = qla25xx_init_req_que(base_vha, req); | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4137 | if (ret != QLA_SUCCESS) | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4138 | ql_dbg(ql_dbg_init, base_vha, 0x0101, | 
|  | 4139 | "%s Req que: %d init failed.\n", | 
|  | 4140 | __func__, req->id); | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4141 | else | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4142 | ql_dbg(ql_dbg_init, base_vha, 0x0102, | 
|  | 4143 | "%s Req que: %d inited.\n", | 
|  | 4144 | __func__, req->id); | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4145 | } | 
|  | 4146 | } | 
|  | 4147 | return ret; | 
|  | 4148 | } | 
|  | 4149 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4150 | /* | 
|  | 4151 | * qla2x00_reset_adapter | 
|  | 4152 | *      Reset adapter. | 
|  | 4153 | * | 
|  | 4154 | * Input: | 
|  | 4155 | *      ha = adapter block pointer. | 
|  | 4156 | */ | 
| Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4157 | void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4158 | qla2x00_reset_adapter(scsi_qla_host_t *vha) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4159 | { | 
|  | 4160 | unsigned long flags = 0; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4161 | struct qla_hw_data *ha = vha->hw; | 
| Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 4162 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4163 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4164 | vha->flags.online = 0; | 
| Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 4165 | ha->isp_ops->disable_intrs(ha); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4166 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4167 | spin_lock_irqsave(&ha->hardware_lock, flags); | 
|  | 4168 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); | 
|  | 4169 | RD_REG_WORD(®->hccr);			/* PCI Posting. */ | 
|  | 4170 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); | 
|  | 4171 | RD_REG_WORD(®->hccr);			/* PCI Posting. */ | 
|  | 4172 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
|  | 4173 | } | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4174 |  | 
|  | 4175 | void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4176 | qla24xx_reset_adapter(scsi_qla_host_t *vha) | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4177 | { | 
|  | 4178 | unsigned long flags = 0; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4179 | struct qla_hw_data *ha = vha->hw; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4180 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; | 
|  | 4181 |  | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4182 | if (IS_QLA82XX(ha)) | 
|  | 4183 | return; | 
|  | 4184 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4185 | vha->flags.online = 0; | 
| Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 4186 | ha->isp_ops->disable_intrs(ha); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4187 |  | 
|  | 4188 | spin_lock_irqsave(&ha->hardware_lock, flags); | 
|  | 4189 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); | 
|  | 4190 | RD_REG_DWORD(®->hccr); | 
|  | 4191 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); | 
|  | 4192 | RD_REG_DWORD(®->hccr); | 
|  | 4193 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | 
| Andrew Vasquez | 09ff36d | 2009-01-22 09:45:30 -0800 | [diff] [blame] | 4194 |  | 
|  | 4195 | if (IS_NOPOLLING_TYPE(ha)) | 
|  | 4196 | ha->isp_ops->enable_intrs(ha); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4197 | } | 
|  | 4198 |  | 
| David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4199 | /* On sparc systems, obtain port and node WWN from firmware | 
|  | 4200 | * properties. | 
|  | 4201 | */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4202 | static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, | 
|  | 4203 | struct nvram_24xx *nv) | 
| David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4204 | { | 
|  | 4205 | #ifdef CONFIG_SPARC | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4206 | struct qla_hw_data *ha = vha->hw; | 
| David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4207 | struct pci_dev *pdev = ha->pdev; | 
| David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 4208 | struct device_node *dp = pci_device_to_OF_node(pdev); | 
|  | 4209 | const u8 *val; | 
| David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4210 | int len; | 
|  | 4211 |  | 
|  | 4212 | val = of_get_property(dp, "port-wwn", &len); | 
|  | 4213 | if (val && len >= WWN_SIZE) | 
|  | 4214 | memcpy(nv->port_name, val, WWN_SIZE); | 
|  | 4215 |  | 
|  | 4216 | val = of_get_property(dp, "node-wwn", &len); | 
|  | 4217 | if (val && len >= WWN_SIZE) | 
|  | 4218 | memcpy(nv->node_name, val, WWN_SIZE); | 
|  | 4219 | #endif | 
|  | 4220 | } | 
|  | 4221 |  | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4222 | int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4223 | qla24xx_nvram_config(scsi_qla_host_t *vha) | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4224 | { | 
| David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4225 | int   rval; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4226 | struct init_cb_24xx *icb; | 
|  | 4227 | struct nvram_24xx *nv; | 
|  | 4228 | uint32_t *dptr; | 
|  | 4229 | uint8_t  *dptr1, *dptr2; | 
|  | 4230 | uint32_t chksum; | 
|  | 4231 | uint16_t cnt; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4232 | struct qla_hw_data *ha = vha->hw; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4233 |  | 
| David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4234 | rval = QLA_SUCCESS; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4235 | icb = (struct init_cb_24xx *)ha->init_cb; | 
| Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 4236 | nv = ha->nvram; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4237 |  | 
|  | 4238 | /* Determine NVRAM starting address. */ | 
| Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 4239 | if (ha->flags.port0) { | 
|  | 4240 | ha->nvram_base = FA_NVRAM_FUNC0_ADDR; | 
|  | 4241 | ha->vpd_base = FA_NVRAM_VPD0_ADDR; | 
|  | 4242 | } else { | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4243 | ha->nvram_base = FA_NVRAM_FUNC1_ADDR; | 
| andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 4244 | ha->vpd_base = FA_NVRAM_VPD1_ADDR; | 
|  | 4245 | } | 
| Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 4246 | ha->nvram_size = sizeof(struct nvram_24xx); | 
|  | 4247 | ha->vpd_size = FA_NVRAM_VPD_SIZE; | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4248 | if (IS_QLA82XX(ha)) | 
|  | 4249 | ha->vpd_size = FA_VPD_SIZE_82XX; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4250 |  | 
| Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 4251 | /* Get VPD data into cache */ | 
|  | 4252 | ha->vpd = ha->nvram + VPD_OFFSET; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4253 | ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, | 
| Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 4254 | ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4); | 
|  | 4255 |  | 
|  | 4256 | /* Get NVRAM data into cache and calculate checksum. */ | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4257 | dptr = (uint32_t *)nv; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4258 | ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base, | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4259 | ha->nvram_size); | 
|  | 4260 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++) | 
|  | 4261 | chksum += le32_to_cpu(*dptr++); | 
|  | 4262 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4263 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a, | 
|  | 4264 | "Contents of NVRAM\n"); | 
|  | 4265 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d, | 
|  | 4266 | (uint8_t *)nv, ha->nvram_size); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4267 |  | 
|  | 4268 | /* Bad NVRAM data, set defaults parameters. */ | 
|  | 4269 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' | 
|  | 4270 | || nv->id[3] != ' ' || | 
|  | 4271 | nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) { | 
|  | 4272 | /* Reset NVRAM data. */ | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4273 | ql_log(ql_log_warn, vha, 0x006b, | 
| Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 4274 | "Inconsistent NVRAM detected: checksum=0x%x id=%c " | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4275 | "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version); | 
|  | 4276 | ql_log(ql_log_warn, vha, 0x006c, | 
|  | 4277 | "Falling back to functioning (yet invalid -- WWPN) " | 
|  | 4278 | "defaults.\n"); | 
| David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4279 |  | 
|  | 4280 | /* | 
|  | 4281 | * Set default initialization control block. | 
|  | 4282 | */ | 
|  | 4283 | memset(nv, 0, ha->nvram_size); | 
|  | 4284 | nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION); | 
|  | 4285 | nv->version = __constant_cpu_to_le16(ICB_VERSION); | 
|  | 4286 | nv->frame_payload_size = __constant_cpu_to_le16(2048); | 
|  | 4287 | nv->execution_throttle = __constant_cpu_to_le16(0xFFFF); | 
|  | 4288 | nv->exchange_count = __constant_cpu_to_le16(0); | 
|  | 4289 | nv->hard_address = __constant_cpu_to_le16(124); | 
|  | 4290 | nv->port_name[0] = 0x21; | 
| Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 4291 | nv->port_name[1] = 0x00 + ha->port_no; | 
| David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4292 | nv->port_name[2] = 0x00; | 
|  | 4293 | nv->port_name[3] = 0xe0; | 
|  | 4294 | nv->port_name[4] = 0x8b; | 
|  | 4295 | nv->port_name[5] = 0x1c; | 
|  | 4296 | nv->port_name[6] = 0x55; | 
|  | 4297 | nv->port_name[7] = 0x86; | 
|  | 4298 | nv->node_name[0] = 0x20; | 
|  | 4299 | nv->node_name[1] = 0x00; | 
|  | 4300 | nv->node_name[2] = 0x00; | 
|  | 4301 | nv->node_name[3] = 0xe0; | 
|  | 4302 | nv->node_name[4] = 0x8b; | 
|  | 4303 | nv->node_name[5] = 0x1c; | 
|  | 4304 | nv->node_name[6] = 0x55; | 
|  | 4305 | nv->node_name[7] = 0x86; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4306 | qla24xx_nvram_wwn_from_ofw(vha, nv); | 
| David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4307 | nv->login_retry_count = __constant_cpu_to_le16(8); | 
|  | 4308 | nv->interrupt_delay_timer = __constant_cpu_to_le16(0); | 
|  | 4309 | nv->login_timeout = __constant_cpu_to_le16(0); | 
|  | 4310 | nv->firmware_options_1 = | 
|  | 4311 | __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); | 
|  | 4312 | nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4); | 
|  | 4313 | nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12); | 
|  | 4314 | nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13); | 
|  | 4315 | nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10); | 
|  | 4316 | nv->efi_parameters = __constant_cpu_to_le32(0); | 
|  | 4317 | nv->reset_delay = 5; | 
|  | 4318 | nv->max_luns_per_target = __constant_cpu_to_le16(128); | 
|  | 4319 | nv->port_down_retry_count = __constant_cpu_to_le16(30); | 
|  | 4320 | nv->link_down_timeout = __constant_cpu_to_le16(30); | 
|  | 4321 |  | 
|  | 4322 | rval = 1; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4323 | } | 
|  | 4324 |  | 
| Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4325 | if (!qla_ini_mode_enabled(vha)) { | 
|  | 4326 | /* Don't enable full login after initial LIP */ | 
|  | 4327 | nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_13); | 
|  | 4328 | /* Don't enable LIP full login for initiator */ | 
|  | 4329 | nv->host_p &= __constant_cpu_to_le32(~BIT_10); | 
|  | 4330 | } | 
|  | 4331 |  | 
|  | 4332 | qlt_24xx_config_nvram_stage1(vha, nv); | 
|  | 4333 |  | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4334 | /* Reset Initialization control block */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4335 | memset(icb, 0, ha->init_cb_size); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4336 |  | 
|  | 4337 | /* Copy 1st segment. */ | 
|  | 4338 | dptr1 = (uint8_t *)icb; | 
|  | 4339 | dptr2 = (uint8_t *)&nv->version; | 
|  | 4340 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; | 
|  | 4341 | while (cnt--) | 
|  | 4342 | *dptr1++ = *dptr2++; | 
|  | 4343 |  | 
|  | 4344 | icb->login_retry_count = nv->login_retry_count; | 
| Andrew Vasquez | 3ea66e2 | 2006-06-23 16:11:27 -0700 | [diff] [blame] | 4345 | icb->link_down_on_nos = nv->link_down_on_nos; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4346 |  | 
|  | 4347 | /* Copy 2nd segment. */ | 
|  | 4348 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; | 
|  | 4349 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; | 
|  | 4350 | cnt = (uint8_t *)&icb->reserved_3 - | 
|  | 4351 | (uint8_t *)&icb->interrupt_delay_timer; | 
|  | 4352 | while (cnt--) | 
|  | 4353 | *dptr1++ = *dptr2++; | 
|  | 4354 |  | 
|  | 4355 | /* | 
|  | 4356 | * Setup driver NVRAM options. | 
|  | 4357 | */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4358 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), | 
| Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 4359 | "QLA2462"); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4360 |  | 
| Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4361 | qlt_24xx_config_nvram_stage2(vha, icb); | 
|  | 4362 |  | 
| Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 4363 | if (nv->host_p & __constant_cpu_to_le32(BIT_15)) { | 
| Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4364 | /* Use alternate WWN? */ | 
| Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 4365 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); | 
|  | 4366 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); | 
|  | 4367 | } | 
|  | 4368 |  | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4369 | /* Prepare nodename */ | 
| Andrew Vasquez | fd0e7e4 | 2006-05-17 15:09:11 -0700 | [diff] [blame] | 4370 | if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) { | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4371 | /* | 
|  | 4372 | * Firmware will apply the following mask if the nodename was | 
|  | 4373 | * not provided. | 
|  | 4374 | */ | 
|  | 4375 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); | 
|  | 4376 | icb->node_name[0] &= 0xF0; | 
|  | 4377 | } | 
|  | 4378 |  | 
|  | 4379 | /* Set host adapter parameters. */ | 
|  | 4380 | ha->flags.disable_risc_code_load = 0; | 
| Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 4381 | ha->flags.enable_lip_reset = 0; | 
|  | 4382 | ha->flags.enable_lip_full_login = | 
|  | 4383 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; | 
|  | 4384 | ha->flags.enable_target_reset = | 
|  | 4385 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4386 | ha->flags.enable_led_scheme = 0; | 
| Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 4387 | 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] | 4388 |  | 
| Andrew Vasquez | fd0e7e4 | 2006-05-17 15:09:11 -0700 | [diff] [blame] | 4389 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & | 
|  | 4390 | (BIT_6 | BIT_5 | BIT_4)) >> 4; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4391 |  | 
|  | 4392 | memcpy(ha->fw_seriallink_options24, nv->seriallink_options, | 
|  | 4393 | sizeof(ha->fw_seriallink_options24)); | 
|  | 4394 |  | 
|  | 4395 | /* save HBA serial number */ | 
|  | 4396 | ha->serial0 = icb->port_name[5]; | 
|  | 4397 | ha->serial1 = icb->port_name[6]; | 
|  | 4398 | ha->serial2 = icb->port_name[7]; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4399 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); | 
|  | 4400 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4401 |  | 
| andrew.vasquez@qlogic.com | bc8fb3c | 2006-01-13 17:05:42 -0800 | [diff] [blame] | 4402 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); | 
|  | 4403 |  | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4404 | ha->retry_count = le16_to_cpu(nv->login_retry_count); | 
|  | 4405 |  | 
|  | 4406 | /* Set minimum login_timeout to 4 seconds. */ | 
|  | 4407 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) | 
|  | 4408 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); | 
|  | 4409 | if (le16_to_cpu(nv->login_timeout) < 4) | 
|  | 4410 | nv->login_timeout = __constant_cpu_to_le16(4); | 
|  | 4411 | ha->login_timeout = le16_to_cpu(nv->login_timeout); | 
| Seokmann Ju | c6852c4 | 2008-04-24 15:21:29 -0700 | [diff] [blame] | 4412 | icb->login_timeout = nv->login_timeout; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4413 |  | 
| Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 4414 | /* Set minimum RATOV to 100 tenths of a second. */ | 
|  | 4415 | ha->r_a_tov = 100; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4416 |  | 
|  | 4417 | ha->loop_reset_delay = nv->reset_delay; | 
|  | 4418 |  | 
|  | 4419 | /* Link Down Timeout = 0: | 
|  | 4420 | * | 
|  | 4421 | * 	When Port Down timer expires we will start returning | 
|  | 4422 | *	I/O's to OS with "DID_NO_CONNECT". | 
|  | 4423 | * | 
|  | 4424 | * Link Down Timeout != 0: | 
|  | 4425 | * | 
|  | 4426 | *	 The driver waits for the link to come up after link down | 
|  | 4427 | *	 before returning I/Os to OS with "DID_NO_CONNECT". | 
|  | 4428 | */ | 
|  | 4429 | if (le16_to_cpu(nv->link_down_timeout) == 0) { | 
|  | 4430 | ha->loop_down_abort_time = | 
|  | 4431 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); | 
|  | 4432 | } else { | 
|  | 4433 | ha->link_down_timeout =	le16_to_cpu(nv->link_down_timeout); | 
|  | 4434 | ha->loop_down_abort_time = | 
|  | 4435 | (LOOP_DOWN_TIME - ha->link_down_timeout); | 
|  | 4436 | } | 
|  | 4437 |  | 
|  | 4438 | /* Need enough time to try and get the port back. */ | 
|  | 4439 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); | 
|  | 4440 | if (qlport_down_retry) | 
|  | 4441 | ha->port_down_retry_count = qlport_down_retry; | 
|  | 4442 |  | 
|  | 4443 | /* Set login_retry_count */ | 
|  | 4444 | ha->login_retry_count  = le16_to_cpu(nv->login_retry_count); | 
|  | 4445 | if (ha->port_down_retry_count == | 
|  | 4446 | le16_to_cpu(nv->port_down_retry_count) && | 
|  | 4447 | ha->port_down_retry_count > 3) | 
|  | 4448 | ha->login_retry_count = ha->port_down_retry_count; | 
|  | 4449 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) | 
|  | 4450 | ha->login_retry_count = ha->port_down_retry_count; | 
|  | 4451 | if (ql2xloginretrycount) | 
|  | 4452 | ha->login_retry_count = ql2xloginretrycount; | 
|  | 4453 |  | 
| Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4454 | /* Enable ZIO. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4455 | if (!vha->flags.init_done) { | 
| Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4456 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & | 
|  | 4457 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); | 
|  | 4458 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? | 
|  | 4459 | le16_to_cpu(icb->interrupt_delay_timer): 2; | 
|  | 4460 | } | 
|  | 4461 | icb->firmware_options_2 &= __constant_cpu_to_le32( | 
|  | 4462 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4463 | vha->flags.process_response_queue = 0; | 
| Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4464 | if (ha->zio_mode != QLA_ZIO_DISABLED) { | 
| andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 4465 | ha->zio_mode = QLA_ZIO_MODE_6; | 
|  | 4466 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4467 | ql_log(ql_log_info, vha, 0x006f, | 
| Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4468 | "ZIO mode %d enabled; timer delay (%d us).\n", | 
|  | 4469 | ha->zio_mode, ha->zio_timer * 100); | 
|  | 4470 |  | 
|  | 4471 | icb->firmware_options_2 |= cpu_to_le32( | 
|  | 4472 | (uint32_t)ha->zio_mode); | 
|  | 4473 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4474 | vha->flags.process_response_queue = 1; | 
| Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4475 | } | 
|  | 4476 |  | 
| David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4477 | if (rval) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4478 | ql_log(ql_log_warn, vha, 0x0070, | 
|  | 4479 | "NVRAM configuration failed.\n"); | 
| David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4480 | } | 
|  | 4481 | return (rval); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4482 | } | 
|  | 4483 |  | 
| Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 4484 | static int | 
| Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4485 | qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr, | 
|  | 4486 | uint32_t faddr) | 
| Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4487 | { | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4488 | int	rval = QLA_SUCCESS; | 
| Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4489 | int	segments, fragment; | 
| Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4490 | uint32_t *dcode, dlen; | 
|  | 4491 | uint32_t risc_addr; | 
|  | 4492 | uint32_t risc_size; | 
|  | 4493 | uint32_t i; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4494 | struct qla_hw_data *ha = vha->hw; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4495 | struct req_que *req = ha->req_q_map[0]; | 
| Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4496 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4497 | ql_dbg(ql_dbg_init, vha, 0x008b, | 
| Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 4498 | "FW: Loading firmware from flash (%x).\n", faddr); | 
| Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4499 |  | 
| Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4500 | rval = QLA_SUCCESS; | 
|  | 4501 |  | 
|  | 4502 | segments = FA_RISC_CODE_SEGMENTS; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4503 | dcode = (uint32_t *)req->ring; | 
| Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4504 | *srisc_addr = 0; | 
|  | 4505 |  | 
|  | 4506 | /* Validate firmware image by checking version. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4507 | qla24xx_read_flash_data(vha, dcode, faddr + 4, 4); | 
| Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4508 | for (i = 0; i < 4; i++) | 
|  | 4509 | dcode[i] = be32_to_cpu(dcode[i]); | 
|  | 4510 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && | 
|  | 4511 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || | 
|  | 4512 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && | 
|  | 4513 | dcode[3] == 0)) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4514 | ql_log(ql_log_fatal, vha, 0x008c, | 
|  | 4515 | "Unable to verify the integrity of flash firmware " | 
|  | 4516 | "image.\n"); | 
|  | 4517 | ql_log(ql_log_fatal, vha, 0x008d, | 
|  | 4518 | "Firmware data: %08x %08x %08x %08x.\n", | 
|  | 4519 | dcode[0], dcode[1], dcode[2], dcode[3]); | 
| Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4520 |  | 
|  | 4521 | return QLA_FUNCTION_FAILED; | 
|  | 4522 | } | 
|  | 4523 |  | 
|  | 4524 | while (segments && rval == QLA_SUCCESS) { | 
|  | 4525 | /* Read segment's load information. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4526 | qla24xx_read_flash_data(vha, dcode, faddr, 4); | 
| Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4527 |  | 
|  | 4528 | risc_addr = be32_to_cpu(dcode[2]); | 
|  | 4529 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; | 
|  | 4530 | risc_size = be32_to_cpu(dcode[3]); | 
|  | 4531 |  | 
|  | 4532 | fragment = 0; | 
|  | 4533 | while (risc_size > 0 && rval == QLA_SUCCESS) { | 
|  | 4534 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); | 
|  | 4535 | if (dlen > risc_size) | 
|  | 4536 | dlen = risc_size; | 
|  | 4537 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4538 | ql_dbg(ql_dbg_init, vha, 0x008e, | 
|  | 4539 | "Loading risc segment@ risc addr %x " | 
|  | 4540 | "number of dwords 0x%x offset 0x%x.\n", | 
|  | 4541 | risc_addr, dlen, faddr); | 
| Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4542 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4543 | qla24xx_read_flash_data(vha, dcode, faddr, dlen); | 
| Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4544 | for (i = 0; i < dlen; i++) | 
|  | 4545 | dcode[i] = swab32(dcode[i]); | 
|  | 4546 |  | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4547 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, | 
| Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4548 | dlen); | 
|  | 4549 | if (rval) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4550 | ql_log(ql_log_fatal, vha, 0x008f, | 
|  | 4551 | "Failed to load segment %d of firmware.\n", | 
|  | 4552 | fragment); | 
| Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4553 | break; | 
|  | 4554 | } | 
|  | 4555 |  | 
|  | 4556 | faddr += dlen; | 
|  | 4557 | risc_addr += dlen; | 
|  | 4558 | risc_size -= dlen; | 
|  | 4559 | fragment++; | 
|  | 4560 | } | 
|  | 4561 |  | 
|  | 4562 | /* Next segment. */ | 
|  | 4563 | segments--; | 
|  | 4564 | } | 
|  | 4565 |  | 
|  | 4566 | return rval; | 
|  | 4567 | } | 
|  | 4568 |  | 
| Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4569 | #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/" | 
|  | 4570 |  | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4571 | int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4572 | qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4573 | { | 
|  | 4574 | int	rval; | 
|  | 4575 | int	i, fragment; | 
|  | 4576 | uint16_t *wcode, *fwcode; | 
|  | 4577 | uint32_t risc_addr, risc_size, fwclen, wlen, *seg; | 
|  | 4578 | struct fw_blob *blob; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4579 | struct qla_hw_data *ha = vha->hw; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4580 | struct req_que *req = ha->req_q_map[0]; | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4581 |  | 
|  | 4582 | /* Load firmware blob. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4583 | blob = qla2x00_request_firmware(vha); | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4584 | if (!blob) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4585 | ql_log(ql_log_info, vha, 0x0083, | 
|  | 4586 | "Fimware image unavailable.\n"); | 
|  | 4587 | ql_log(ql_log_info, vha, 0x0084, | 
|  | 4588 | "Firmware images can be retrieved from: "QLA_FW_URL ".\n"); | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4589 | return QLA_FUNCTION_FAILED; | 
|  | 4590 | } | 
|  | 4591 |  | 
|  | 4592 | rval = QLA_SUCCESS; | 
|  | 4593 |  | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4594 | wcode = (uint16_t *)req->ring; | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4595 | *srisc_addr = 0; | 
|  | 4596 | fwcode = (uint16_t *)blob->fw->data; | 
|  | 4597 | fwclen = 0; | 
|  | 4598 |  | 
|  | 4599 | /* Validate firmware image by checking version. */ | 
|  | 4600 | if (blob->fw->size < 8 * sizeof(uint16_t)) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4601 | ql_log(ql_log_fatal, vha, 0x0085, | 
|  | 4602 | "Unable to verify integrity of firmware image (%Zd).\n", | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4603 | blob->fw->size); | 
|  | 4604 | goto fail_fw_integrity; | 
|  | 4605 | } | 
|  | 4606 | for (i = 0; i < 4; i++) | 
|  | 4607 | wcode[i] = be16_to_cpu(fwcode[i + 4]); | 
|  | 4608 | if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff && | 
|  | 4609 | wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 && | 
|  | 4610 | wcode[2] == 0 && wcode[3] == 0)) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4611 | ql_log(ql_log_fatal, vha, 0x0086, | 
|  | 4612 | "Unable to verify integrity of firmware image.\n"); | 
|  | 4613 | ql_log(ql_log_fatal, vha, 0x0087, | 
|  | 4614 | "Firmware data: %04x %04x %04x %04x.\n", | 
|  | 4615 | wcode[0], wcode[1], wcode[2], wcode[3]); | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4616 | goto fail_fw_integrity; | 
|  | 4617 | } | 
|  | 4618 |  | 
|  | 4619 | seg = blob->segs; | 
|  | 4620 | while (*seg && rval == QLA_SUCCESS) { | 
|  | 4621 | risc_addr = *seg; | 
|  | 4622 | *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr; | 
|  | 4623 | risc_size = be16_to_cpu(fwcode[3]); | 
|  | 4624 |  | 
|  | 4625 | /* Validate firmware image size. */ | 
|  | 4626 | fwclen += risc_size * sizeof(uint16_t); | 
|  | 4627 | if (blob->fw->size < fwclen) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4628 | ql_log(ql_log_fatal, vha, 0x0088, | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4629 | "Unable to verify integrity of firmware image " | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4630 | "(%Zd).\n", blob->fw->size); | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4631 | goto fail_fw_integrity; | 
|  | 4632 | } | 
|  | 4633 |  | 
|  | 4634 | fragment = 0; | 
|  | 4635 | while (risc_size > 0 && rval == QLA_SUCCESS) { | 
|  | 4636 | wlen = (uint16_t)(ha->fw_transfer_size >> 1); | 
|  | 4637 | if (wlen > risc_size) | 
|  | 4638 | wlen = risc_size; | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4639 | ql_dbg(ql_dbg_init, vha, 0x0089, | 
|  | 4640 | "Loading risc segment@ risc addr %x number of " | 
|  | 4641 | "words 0x%x.\n", risc_addr, wlen); | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4642 |  | 
|  | 4643 | for (i = 0; i < wlen; i++) | 
|  | 4644 | wcode[i] = swab16(fwcode[i]); | 
|  | 4645 |  | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4646 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4647 | wlen); | 
|  | 4648 | if (rval) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4649 | ql_log(ql_log_fatal, vha, 0x008a, | 
|  | 4650 | "Failed to load segment %d of firmware.\n", | 
|  | 4651 | fragment); | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4652 | break; | 
|  | 4653 | } | 
|  | 4654 |  | 
|  | 4655 | fwcode += wlen; | 
|  | 4656 | risc_addr += wlen; | 
|  | 4657 | risc_size -= wlen; | 
|  | 4658 | fragment++; | 
|  | 4659 | } | 
|  | 4660 |  | 
|  | 4661 | /* Next segment. */ | 
|  | 4662 | seg++; | 
|  | 4663 | } | 
|  | 4664 | return rval; | 
|  | 4665 |  | 
|  | 4666 | fail_fw_integrity: | 
|  | 4667 | return QLA_FUNCTION_FAILED; | 
|  | 4668 | } | 
|  | 4669 |  | 
| Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4670 | static int | 
|  | 4671 | 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] | 4672 | { | 
|  | 4673 | int	rval; | 
|  | 4674 | int	segments, fragment; | 
|  | 4675 | uint32_t *dcode, dlen; | 
|  | 4676 | uint32_t risc_addr; | 
|  | 4677 | uint32_t risc_size; | 
|  | 4678 | uint32_t i; | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4679 | struct fw_blob *blob; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4680 | uint32_t *fwcode, fwclen; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4681 | struct qla_hw_data *ha = vha->hw; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4682 | struct req_que *req = ha->req_q_map[0]; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4683 |  | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4684 | /* Load firmware blob. */ | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4685 | blob = qla2x00_request_firmware(vha); | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4686 | if (!blob) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4687 | ql_log(ql_log_warn, vha, 0x0090, | 
|  | 4688 | "Fimware image unavailable.\n"); | 
|  | 4689 | ql_log(ql_log_warn, vha, 0x0091, | 
|  | 4690 | "Firmware images can be retrieved from: " | 
|  | 4691 | QLA_FW_URL ".\n"); | 
| Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4692 |  | 
| Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4693 | return QLA_FUNCTION_FAILED; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4694 | } | 
|  | 4695 |  | 
| Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 4696 | ql_dbg(ql_dbg_init, vha, 0x0092, | 
|  | 4697 | "FW: Loading via request-firmware.\n"); | 
| Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4698 |  | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4699 | rval = QLA_SUCCESS; | 
|  | 4700 |  | 
|  | 4701 | segments = FA_RISC_CODE_SEGMENTS; | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4702 | dcode = (uint32_t *)req->ring; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4703 | *srisc_addr = 0; | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4704 | fwcode = (uint32_t *)blob->fw->data; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4705 | fwclen = 0; | 
|  | 4706 |  | 
|  | 4707 | /* Validate firmware image by checking version. */ | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4708 | if (blob->fw->size < 8 * sizeof(uint32_t)) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4709 | ql_log(ql_log_fatal, vha, 0x0093, | 
|  | 4710 | "Unable to verify integrity of firmware image (%Zd).\n", | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4711 | blob->fw->size); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4712 | goto fail_fw_integrity; | 
|  | 4713 | } | 
|  | 4714 | for (i = 0; i < 4; i++) | 
|  | 4715 | dcode[i] = be32_to_cpu(fwcode[i + 4]); | 
|  | 4716 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && | 
|  | 4717 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || | 
|  | 4718 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && | 
|  | 4719 | dcode[3] == 0)) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4720 | ql_log(ql_log_fatal, vha, 0x0094, | 
|  | 4721 | "Unable to verify integrity of firmware image (%Zd).\n", | 
|  | 4722 | blob->fw->size); | 
|  | 4723 | ql_log(ql_log_fatal, vha, 0x0095, | 
|  | 4724 | "Firmware data: %08x %08x %08x %08x.\n", | 
|  | 4725 | dcode[0], dcode[1], dcode[2], dcode[3]); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4726 | goto fail_fw_integrity; | 
|  | 4727 | } | 
|  | 4728 |  | 
|  | 4729 | while (segments && rval == QLA_SUCCESS) { | 
|  | 4730 | risc_addr = be32_to_cpu(fwcode[2]); | 
|  | 4731 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; | 
|  | 4732 | risc_size = be32_to_cpu(fwcode[3]); | 
|  | 4733 |  | 
|  | 4734 | /* Validate firmware image size. */ | 
|  | 4735 | fwclen += risc_size * sizeof(uint32_t); | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4736 | if (blob->fw->size < fwclen) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4737 | ql_log(ql_log_fatal, vha, 0x0096, | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4738 | "Unable to verify integrity of firmware image " | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4739 | "(%Zd).\n", blob->fw->size); | 
| Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4740 |  | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4741 | goto fail_fw_integrity; | 
|  | 4742 | } | 
|  | 4743 |  | 
|  | 4744 | fragment = 0; | 
|  | 4745 | while (risc_size > 0 && rval == QLA_SUCCESS) { | 
|  | 4746 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); | 
|  | 4747 | if (dlen > risc_size) | 
|  | 4748 | dlen = risc_size; | 
|  | 4749 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4750 | ql_dbg(ql_dbg_init, vha, 0x0097, | 
|  | 4751 | "Loading risc segment@ risc addr %x " | 
|  | 4752 | "number of dwords 0x%x.\n", risc_addr, dlen); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4753 |  | 
|  | 4754 | for (i = 0; i < dlen; i++) | 
|  | 4755 | dcode[i] = swab32(fwcode[i]); | 
|  | 4756 |  | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4757 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, | 
| andrew.vasquez@qlogic.com | 590f98e | 2006-01-13 17:05:37 -0800 | [diff] [blame] | 4758 | dlen); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4759 | if (rval) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4760 | ql_log(ql_log_fatal, vha, 0x0098, | 
|  | 4761 | "Failed to load segment %d of firmware.\n", | 
|  | 4762 | fragment); | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4763 | break; | 
|  | 4764 | } | 
|  | 4765 |  | 
|  | 4766 | fwcode += dlen; | 
|  | 4767 | risc_addr += dlen; | 
|  | 4768 | risc_size -= dlen; | 
|  | 4769 | fragment++; | 
|  | 4770 | } | 
|  | 4771 |  | 
|  | 4772 | /* Next segment. */ | 
|  | 4773 | segments--; | 
|  | 4774 | } | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4775 | return rval; | 
|  | 4776 |  | 
|  | 4777 | fail_fw_integrity: | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4778 | return QLA_FUNCTION_FAILED; | 
| Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4779 | } | 
| Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4780 |  | 
| Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4781 | int | 
|  | 4782 | qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) | 
|  | 4783 | { | 
|  | 4784 | int rval; | 
|  | 4785 |  | 
| Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 4786 | if (ql2xfwloadbin == 1) | 
|  | 4787 | return qla81xx_load_risc(vha, srisc_addr); | 
|  | 4788 |  | 
| Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4789 | /* | 
|  | 4790 | * FW Load priority: | 
|  | 4791 | * 1) Firmware via request-firmware interface (.bin file). | 
|  | 4792 | * 2) Firmware residing in flash. | 
|  | 4793 | */ | 
|  | 4794 | rval = qla24xx_load_risc_blob(vha, srisc_addr); | 
|  | 4795 | if (rval == QLA_SUCCESS) | 
|  | 4796 | return rval; | 
|  | 4797 |  | 
| Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4798 | return qla24xx_load_risc_flash(vha, srisc_addr, | 
|  | 4799 | vha->hw->flt_region_fw); | 
| Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4800 | } | 
|  | 4801 |  | 
|  | 4802 | int | 
|  | 4803 | qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) | 
|  | 4804 | { | 
|  | 4805 | int rval; | 
| Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4806 | struct qla_hw_data *ha = vha->hw; | 
| Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4807 |  | 
| Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 4808 | if (ql2xfwloadbin == 2) | 
| Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4809 | goto try_blob_fw; | 
| Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 4810 |  | 
| Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4811 | /* | 
|  | 4812 | * FW Load priority: | 
|  | 4813 | * 1) Firmware residing in flash. | 
|  | 4814 | * 2) Firmware via request-firmware interface (.bin file). | 
| Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4815 | * 3) Golden-Firmware residing in flash -- limited operation. | 
| Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4816 | */ | 
| Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4817 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw); | 
| Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4818 | if (rval == QLA_SUCCESS) | 
|  | 4819 | return rval; | 
|  | 4820 |  | 
| Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4821 | try_blob_fw: | 
|  | 4822 | rval = qla24xx_load_risc_blob(vha, srisc_addr); | 
|  | 4823 | if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw) | 
|  | 4824 | return rval; | 
|  | 4825 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4826 | ql_log(ql_log_info, vha, 0x0099, | 
|  | 4827 | "Attempting to fallback to golden firmware.\n"); | 
| Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4828 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw); | 
|  | 4829 | if (rval != QLA_SUCCESS) | 
|  | 4830 | return rval; | 
|  | 4831 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4832 | ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n"); | 
| Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4833 | ha->flags.running_gold_fw = 1; | 
| Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4834 | return rval; | 
| Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4835 | } | 
|  | 4836 |  | 
| Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4837 | void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4838 | qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha) | 
| Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4839 | { | 
|  | 4840 | int ret, retries; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4841 | struct qla_hw_data *ha = vha->hw; | 
| Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4842 |  | 
| Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 4843 | if (ha->flags.pci_channel_io_perm_failure) | 
|  | 4844 | return; | 
| Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 4845 | if (!IS_FWI2_CAPABLE(ha)) | 
| Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4846 | return; | 
| Andrew Vasquez | 75edf81 | 2007-05-07 07:43:00 -0700 | [diff] [blame] | 4847 | if (!ha->fw_major_version) | 
|  | 4848 | return; | 
| Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4849 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4850 | ret = qla2x00_stop_firmware(vha); | 
| Andrew Vasquez | 7c7f1f2 | 2008-02-28 14:06:09 -0800 | [diff] [blame] | 4851 | for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT && | 
| Andrew Vasquez | b469a7c | 2009-04-06 22:33:48 -0700 | [diff] [blame] | 4852 | ret != QLA_INVALID_COMMAND && retries ; retries--) { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4853 | ha->isp_ops->reset_chip(vha); | 
|  | 4854 | if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS) | 
| Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4855 | continue; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4856 | if (qla2x00_setup_chip(vha) != QLA_SUCCESS) | 
| Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4857 | continue; | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4858 | ql_log(ql_log_info, vha, 0x8015, | 
|  | 4859 | "Attempting retry of stop-firmware command.\n"); | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4860 | ret = qla2x00_stop_firmware(vha); | 
| Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4861 | } | 
|  | 4862 | } | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4863 |  | 
|  | 4864 | int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4865 | qla24xx_configure_vhba(scsi_qla_host_t *vha) | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4866 | { | 
|  | 4867 | int rval = QLA_SUCCESS; | 
| Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 4868 | int rval2; | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4869 | uint16_t mb[MAILBOX_REGISTER_COUNT]; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4870 | struct qla_hw_data *ha = vha->hw; | 
|  | 4871 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); | 
| Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 4872 | struct req_que *req; | 
|  | 4873 | struct rsp_que *rsp; | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4874 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4875 | if (!vha->vp_idx) | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4876 | return -EINVAL; | 
|  | 4877 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4878 | rval = qla2x00_fw_ready(base_vha); | 
| Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 4879 | if (ha->flags.cpu_affinity_enabled) | 
| Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 4880 | req = ha->req_q_map[0]; | 
|  | 4881 | else | 
|  | 4882 | req = vha->req; | 
|  | 4883 | rsp = req->rsp; | 
|  | 4884 |  | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4885 | if (rval == QLA_SUCCESS) { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4886 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); | 
| Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4887 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4888 | } | 
|  | 4889 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4890 | vha->flags.management_server_logged_in = 0; | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4891 |  | 
|  | 4892 | /* Login to SNS first */ | 
| Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 4893 | rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, | 
|  | 4894 | BIT_1); | 
|  | 4895 | if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) { | 
|  | 4896 | if (rval2 == QLA_MEMORY_ALLOC_FAILED) | 
|  | 4897 | ql_dbg(ql_dbg_init, vha, 0x0120, | 
|  | 4898 | "Failed SNS login: loop_id=%x, rval2=%d\n", | 
|  | 4899 | NPH_SNS, rval2); | 
|  | 4900 | else | 
|  | 4901 | ql_dbg(ql_dbg_init, vha, 0x0103, | 
|  | 4902 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x " | 
|  | 4903 | "mb[2]=%x mb[6]=%x mb[7]=%x.\n", | 
|  | 4904 | NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]); | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4905 | return (QLA_FUNCTION_FAILED); | 
|  | 4906 | } | 
|  | 4907 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4908 | atomic_set(&vha->loop_down_timer, 0); | 
|  | 4909 | atomic_set(&vha->loop_state, LOOP_UP); | 
|  | 4910 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); | 
|  | 4911 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); | 
|  | 4912 | rval = qla2x00_loop_resync(base_vha); | 
| Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4913 |  | 
|  | 4914 | return rval; | 
|  | 4915 | } | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 4916 |  | 
|  | 4917 | /* 84XX Support **************************************************************/ | 
|  | 4918 |  | 
|  | 4919 | static LIST_HEAD(qla_cs84xx_list); | 
|  | 4920 | static DEFINE_MUTEX(qla_cs84xx_mutex); | 
|  | 4921 |  | 
|  | 4922 | static struct qla_chip_state_84xx * | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4923 | qla84xx_get_chip(struct scsi_qla_host *vha) | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 4924 | { | 
|  | 4925 | struct qla_chip_state_84xx *cs84xx; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4926 | struct qla_hw_data *ha = vha->hw; | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 4927 |  | 
|  | 4928 | mutex_lock(&qla_cs84xx_mutex); | 
|  | 4929 |  | 
|  | 4930 | /* Find any shared 84xx chip. */ | 
|  | 4931 | list_for_each_entry(cs84xx, &qla_cs84xx_list, list) { | 
|  | 4932 | if (cs84xx->bus == ha->pdev->bus) { | 
|  | 4933 | kref_get(&cs84xx->kref); | 
|  | 4934 | goto done; | 
|  | 4935 | } | 
|  | 4936 | } | 
|  | 4937 |  | 
|  | 4938 | cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL); | 
|  | 4939 | if (!cs84xx) | 
|  | 4940 | goto done; | 
|  | 4941 |  | 
|  | 4942 | kref_init(&cs84xx->kref); | 
|  | 4943 | spin_lock_init(&cs84xx->access_lock); | 
|  | 4944 | mutex_init(&cs84xx->fw_update_mutex); | 
|  | 4945 | cs84xx->bus = ha->pdev->bus; | 
|  | 4946 |  | 
|  | 4947 | list_add_tail(&cs84xx->list, &qla_cs84xx_list); | 
|  | 4948 | done: | 
|  | 4949 | mutex_unlock(&qla_cs84xx_mutex); | 
|  | 4950 | return cs84xx; | 
|  | 4951 | } | 
|  | 4952 |  | 
|  | 4953 | static void | 
|  | 4954 | __qla84xx_chip_release(struct kref *kref) | 
|  | 4955 | { | 
|  | 4956 | struct qla_chip_state_84xx *cs84xx = | 
|  | 4957 | container_of(kref, struct qla_chip_state_84xx, kref); | 
|  | 4958 |  | 
|  | 4959 | mutex_lock(&qla_cs84xx_mutex); | 
|  | 4960 | list_del(&cs84xx->list); | 
|  | 4961 | mutex_unlock(&qla_cs84xx_mutex); | 
|  | 4962 | kfree(cs84xx); | 
|  | 4963 | } | 
|  | 4964 |  | 
|  | 4965 | void | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4966 | qla84xx_put_chip(struct scsi_qla_host *vha) | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 4967 | { | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4968 | struct qla_hw_data *ha = vha->hw; | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 4969 | if (ha->cs84xx) | 
|  | 4970 | kref_put(&ha->cs84xx->kref, __qla84xx_chip_release); | 
|  | 4971 | } | 
|  | 4972 |  | 
|  | 4973 | static int | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4974 | qla84xx_init_chip(scsi_qla_host_t *vha) | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 4975 | { | 
|  | 4976 | int rval; | 
|  | 4977 | uint16_t status[2]; | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4978 | struct qla_hw_data *ha = vha->hw; | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 4979 |  | 
|  | 4980 | mutex_lock(&ha->cs84xx->fw_update_mutex); | 
|  | 4981 |  | 
| Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4982 | rval = qla84xx_verify_chip(vha, status); | 
| Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 4983 |  | 
|  | 4984 | mutex_unlock(&ha->cs84xx->fw_update_mutex); | 
|  | 4985 |  | 
|  | 4986 | return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED: | 
|  | 4987 | QLA_SUCCESS; | 
|  | 4988 | } | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 4989 |  | 
|  | 4990 | /* 81XX Support **************************************************************/ | 
|  | 4991 |  | 
|  | 4992 | int | 
|  | 4993 | qla81xx_nvram_config(scsi_qla_host_t *vha) | 
|  | 4994 | { | 
|  | 4995 | int   rval; | 
|  | 4996 | struct init_cb_81xx *icb; | 
|  | 4997 | struct nvram_81xx *nv; | 
|  | 4998 | uint32_t *dptr; | 
|  | 4999 | uint8_t  *dptr1, *dptr2; | 
|  | 5000 | uint32_t chksum; | 
|  | 5001 | uint16_t cnt; | 
|  | 5002 | struct qla_hw_data *ha = vha->hw; | 
|  | 5003 |  | 
|  | 5004 | rval = QLA_SUCCESS; | 
|  | 5005 | icb = (struct init_cb_81xx *)ha->init_cb; | 
|  | 5006 | nv = ha->nvram; | 
|  | 5007 |  | 
|  | 5008 | /* Determine NVRAM starting address. */ | 
|  | 5009 | ha->nvram_size = sizeof(struct nvram_81xx); | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5010 | ha->vpd_size = FA_NVRAM_VPD_SIZE; | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5011 |  | 
|  | 5012 | /* Get VPD data into cache */ | 
|  | 5013 | ha->vpd = ha->nvram + VPD_OFFSET; | 
| Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 5014 | ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2, | 
|  | 5015 | ha->vpd_size); | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5016 |  | 
|  | 5017 | /* Get NVRAM data into cache and calculate checksum. */ | 
| Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 5018 | 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] | 5019 | ha->nvram_size); | 
| Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 5020 | dptr = (uint32_t *)nv; | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5021 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++) | 
|  | 5022 | chksum += le32_to_cpu(*dptr++); | 
|  | 5023 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5024 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111, | 
|  | 5025 | "Contents of NVRAM:\n"); | 
|  | 5026 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112, | 
|  | 5027 | (uint8_t *)nv, ha->nvram_size); | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5028 |  | 
|  | 5029 | /* Bad NVRAM data, set defaults parameters. */ | 
|  | 5030 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' | 
|  | 5031 | || nv->id[3] != ' ' || | 
|  | 5032 | nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) { | 
|  | 5033 | /* Reset NVRAM data. */ | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5034 | ql_log(ql_log_info, vha, 0x0073, | 
| Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 5035 | "Inconsistent NVRAM detected: checksum=0x%x id=%c " | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5036 | "version=0x%x.\n", chksum, nv->id[0], | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5037 | le16_to_cpu(nv->nvram_version)); | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5038 | ql_log(ql_log_info, vha, 0x0074, | 
|  | 5039 | "Falling back to functioning (yet invalid -- WWPN) " | 
|  | 5040 | "defaults.\n"); | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5041 |  | 
|  | 5042 | /* | 
|  | 5043 | * Set default initialization control block. | 
|  | 5044 | */ | 
|  | 5045 | memset(nv, 0, ha->nvram_size); | 
|  | 5046 | nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION); | 
|  | 5047 | nv->version = __constant_cpu_to_le16(ICB_VERSION); | 
|  | 5048 | nv->frame_payload_size = __constant_cpu_to_le16(2048); | 
|  | 5049 | nv->execution_throttle = __constant_cpu_to_le16(0xFFFF); | 
|  | 5050 | nv->exchange_count = __constant_cpu_to_le16(0); | 
|  | 5051 | nv->port_name[0] = 0x21; | 
| Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5052 | nv->port_name[1] = 0x00 + ha->port_no; | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5053 | nv->port_name[2] = 0x00; | 
|  | 5054 | nv->port_name[3] = 0xe0; | 
|  | 5055 | nv->port_name[4] = 0x8b; | 
|  | 5056 | nv->port_name[5] = 0x1c; | 
|  | 5057 | nv->port_name[6] = 0x55; | 
|  | 5058 | nv->port_name[7] = 0x86; | 
|  | 5059 | nv->node_name[0] = 0x20; | 
|  | 5060 | nv->node_name[1] = 0x00; | 
|  | 5061 | nv->node_name[2] = 0x00; | 
|  | 5062 | nv->node_name[3] = 0xe0; | 
|  | 5063 | nv->node_name[4] = 0x8b; | 
|  | 5064 | nv->node_name[5] = 0x1c; | 
|  | 5065 | nv->node_name[6] = 0x55; | 
|  | 5066 | nv->node_name[7] = 0x86; | 
|  | 5067 | nv->login_retry_count = __constant_cpu_to_le16(8); | 
|  | 5068 | nv->interrupt_delay_timer = __constant_cpu_to_le16(0); | 
|  | 5069 | nv->login_timeout = __constant_cpu_to_le16(0); | 
|  | 5070 | nv->firmware_options_1 = | 
|  | 5071 | __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); | 
|  | 5072 | nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4); | 
|  | 5073 | nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12); | 
|  | 5074 | nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13); | 
|  | 5075 | nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10); | 
|  | 5076 | nv->efi_parameters = __constant_cpu_to_le32(0); | 
|  | 5077 | nv->reset_delay = 5; | 
|  | 5078 | nv->max_luns_per_target = __constant_cpu_to_le16(128); | 
|  | 5079 | nv->port_down_retry_count = __constant_cpu_to_le16(30); | 
| Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 5080 | nv->link_down_timeout = __constant_cpu_to_le16(180); | 
| Andrew Vasquez | eeebcc9 | 2009-06-03 09:55:24 -0700 | [diff] [blame] | 5081 | nv->enode_mac[0] = 0x00; | 
| Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 5082 | nv->enode_mac[1] = 0xC0; | 
|  | 5083 | nv->enode_mac[2] = 0xDD; | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5084 | nv->enode_mac[3] = 0x04; | 
|  | 5085 | nv->enode_mac[4] = 0x05; | 
| Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5086 | nv->enode_mac[5] = 0x06 + ha->port_no; | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5087 |  | 
|  | 5088 | rval = 1; | 
|  | 5089 | } | 
|  | 5090 |  | 
|  | 5091 | /* Reset Initialization control block */ | 
| Andrew Vasquez | 773120e | 2011-05-10 11:30:14 -0700 | [diff] [blame] | 5092 | memset(icb, 0, ha->init_cb_size); | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5093 |  | 
|  | 5094 | /* Copy 1st segment. */ | 
|  | 5095 | dptr1 = (uint8_t *)icb; | 
|  | 5096 | dptr2 = (uint8_t *)&nv->version; | 
|  | 5097 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; | 
|  | 5098 | while (cnt--) | 
|  | 5099 | *dptr1++ = *dptr2++; | 
|  | 5100 |  | 
|  | 5101 | icb->login_retry_count = nv->login_retry_count; | 
|  | 5102 |  | 
|  | 5103 | /* Copy 2nd segment. */ | 
|  | 5104 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; | 
|  | 5105 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; | 
|  | 5106 | cnt = (uint8_t *)&icb->reserved_5 - | 
|  | 5107 | (uint8_t *)&icb->interrupt_delay_timer; | 
|  | 5108 | while (cnt--) | 
|  | 5109 | *dptr1++ = *dptr2++; | 
|  | 5110 |  | 
|  | 5111 | memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac)); | 
|  | 5112 | /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */ | 
|  | 5113 | 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] | 5114 | icb->enode_mac[0] = 0x00; | 
|  | 5115 | icb->enode_mac[1] = 0xC0; | 
|  | 5116 | icb->enode_mac[2] = 0xDD; | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5117 | icb->enode_mac[3] = 0x04; | 
|  | 5118 | icb->enode_mac[4] = 0x05; | 
| Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5119 | icb->enode_mac[5] = 0x06 + ha->port_no; | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5120 | } | 
|  | 5121 |  | 
| Andrew Vasquez | b64b0e8 | 2009-03-24 09:08:01 -0700 | [diff] [blame] | 5122 | /* Use extended-initialization control block. */ | 
|  | 5123 | memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb)); | 
|  | 5124 |  | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5125 | /* | 
|  | 5126 | * Setup driver NVRAM options. | 
|  | 5127 | */ | 
|  | 5128 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5129 | "QLE8XXX"); | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5130 |  | 
|  | 5131 | /* Use alternate WWN? */ | 
|  | 5132 | if (nv->host_p & __constant_cpu_to_le32(BIT_15)) { | 
|  | 5133 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); | 
|  | 5134 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); | 
|  | 5135 | } | 
|  | 5136 |  | 
|  | 5137 | /* Prepare nodename */ | 
|  | 5138 | if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) { | 
|  | 5139 | /* | 
|  | 5140 | * Firmware will apply the following mask if the nodename was | 
|  | 5141 | * not provided. | 
|  | 5142 | */ | 
|  | 5143 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); | 
|  | 5144 | icb->node_name[0] &= 0xF0; | 
|  | 5145 | } | 
|  | 5146 |  | 
|  | 5147 | /* Set host adapter parameters. */ | 
|  | 5148 | ha->flags.disable_risc_code_load = 0; | 
|  | 5149 | ha->flags.enable_lip_reset = 0; | 
|  | 5150 | ha->flags.enable_lip_full_login = | 
|  | 5151 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; | 
|  | 5152 | ha->flags.enable_target_reset = | 
|  | 5153 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; | 
|  | 5154 | ha->flags.enable_led_scheme = 0; | 
|  | 5155 | ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0; | 
|  | 5156 |  | 
|  | 5157 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & | 
|  | 5158 | (BIT_6 | BIT_5 | BIT_4)) >> 4; | 
|  | 5159 |  | 
|  | 5160 | /* save HBA serial number */ | 
|  | 5161 | ha->serial0 = icb->port_name[5]; | 
|  | 5162 | ha->serial1 = icb->port_name[6]; | 
|  | 5163 | ha->serial2 = icb->port_name[7]; | 
|  | 5164 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); | 
|  | 5165 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); | 
|  | 5166 |  | 
|  | 5167 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); | 
|  | 5168 |  | 
|  | 5169 | ha->retry_count = le16_to_cpu(nv->login_retry_count); | 
|  | 5170 |  | 
|  | 5171 | /* Set minimum login_timeout to 4 seconds. */ | 
|  | 5172 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) | 
|  | 5173 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); | 
|  | 5174 | if (le16_to_cpu(nv->login_timeout) < 4) | 
|  | 5175 | nv->login_timeout = __constant_cpu_to_le16(4); | 
|  | 5176 | ha->login_timeout = le16_to_cpu(nv->login_timeout); | 
|  | 5177 | icb->login_timeout = nv->login_timeout; | 
|  | 5178 |  | 
|  | 5179 | /* Set minimum RATOV to 100 tenths of a second. */ | 
|  | 5180 | ha->r_a_tov = 100; | 
|  | 5181 |  | 
|  | 5182 | ha->loop_reset_delay = nv->reset_delay; | 
|  | 5183 |  | 
|  | 5184 | /* Link Down Timeout = 0: | 
|  | 5185 | * | 
|  | 5186 | * 	When Port Down timer expires we will start returning | 
|  | 5187 | *	I/O's to OS with "DID_NO_CONNECT". | 
|  | 5188 | * | 
|  | 5189 | * Link Down Timeout != 0: | 
|  | 5190 | * | 
|  | 5191 | *	 The driver waits for the link to come up after link down | 
|  | 5192 | *	 before returning I/Os to OS with "DID_NO_CONNECT". | 
|  | 5193 | */ | 
|  | 5194 | if (le16_to_cpu(nv->link_down_timeout) == 0) { | 
|  | 5195 | ha->loop_down_abort_time = | 
|  | 5196 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); | 
|  | 5197 | } else { | 
|  | 5198 | ha->link_down_timeout =	le16_to_cpu(nv->link_down_timeout); | 
|  | 5199 | ha->loop_down_abort_time = | 
|  | 5200 | (LOOP_DOWN_TIME - ha->link_down_timeout); | 
|  | 5201 | } | 
|  | 5202 |  | 
|  | 5203 | /* Need enough time to try and get the port back. */ | 
|  | 5204 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); | 
|  | 5205 | if (qlport_down_retry) | 
|  | 5206 | ha->port_down_retry_count = qlport_down_retry; | 
|  | 5207 |  | 
|  | 5208 | /* Set login_retry_count */ | 
|  | 5209 | ha->login_retry_count  = le16_to_cpu(nv->login_retry_count); | 
|  | 5210 | if (ha->port_down_retry_count == | 
|  | 5211 | le16_to_cpu(nv->port_down_retry_count) && | 
|  | 5212 | ha->port_down_retry_count > 3) | 
|  | 5213 | ha->login_retry_count = ha->port_down_retry_count; | 
|  | 5214 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) | 
|  | 5215 | ha->login_retry_count = ha->port_down_retry_count; | 
|  | 5216 | if (ql2xloginretrycount) | 
|  | 5217 | ha->login_retry_count = ql2xloginretrycount; | 
|  | 5218 |  | 
| Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 5219 | /* if not running MSI-X we need handshaking on interrupts */ | 
|  | 5220 | if (!vha->hw->flags.msix_enabled && IS_QLA83XX(ha)) | 
|  | 5221 | icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22); | 
|  | 5222 |  | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5223 | /* Enable ZIO. */ | 
|  | 5224 | if (!vha->flags.init_done) { | 
|  | 5225 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & | 
|  | 5226 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); | 
|  | 5227 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? | 
|  | 5228 | le16_to_cpu(icb->interrupt_delay_timer): 2; | 
|  | 5229 | } | 
|  | 5230 | icb->firmware_options_2 &= __constant_cpu_to_le32( | 
|  | 5231 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); | 
|  | 5232 | vha->flags.process_response_queue = 0; | 
|  | 5233 | if (ha->zio_mode != QLA_ZIO_DISABLED) { | 
|  | 5234 | ha->zio_mode = QLA_ZIO_MODE_6; | 
|  | 5235 |  | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5236 | ql_log(ql_log_info, vha, 0x0075, | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5237 | "ZIO mode %d enabled; timer delay (%d us).\n", | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5238 | ha->zio_mode, | 
|  | 5239 | ha->zio_timer * 100); | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5240 |  | 
|  | 5241 | icb->firmware_options_2 |= cpu_to_le32( | 
|  | 5242 | (uint32_t)ha->zio_mode); | 
|  | 5243 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); | 
|  | 5244 | vha->flags.process_response_queue = 1; | 
|  | 5245 | } | 
|  | 5246 |  | 
|  | 5247 | if (rval) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5248 | ql_log(ql_log_warn, vha, 0x0076, | 
|  | 5249 | "NVRAM configuration failed.\n"); | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5250 | } | 
|  | 5251 | return (rval); | 
|  | 5252 | } | 
|  | 5253 |  | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5254 | int | 
|  | 5255 | qla82xx_restart_isp(scsi_qla_host_t *vha) | 
|  | 5256 | { | 
|  | 5257 | int status, rval; | 
|  | 5258 | uint32_t wait_time; | 
|  | 5259 | struct qla_hw_data *ha = vha->hw; | 
|  | 5260 | struct req_que *req = ha->req_q_map[0]; | 
|  | 5261 | struct rsp_que *rsp = ha->rsp_q_map[0]; | 
|  | 5262 | struct scsi_qla_host *vp; | 
| Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5263 | unsigned long flags; | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5264 |  | 
|  | 5265 | status = qla2x00_init_rings(vha); | 
|  | 5266 | if (!status) { | 
|  | 5267 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); | 
|  | 5268 | ha->flags.chip_reset_done = 1; | 
|  | 5269 |  | 
|  | 5270 | status = qla2x00_fw_ready(vha); | 
|  | 5271 | if (!status) { | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5272 | ql_log(ql_log_info, vha, 0x803c, | 
|  | 5273 | "Start configure loop, status =%d.\n", status); | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5274 |  | 
|  | 5275 | /* Issue a marker after FW becomes ready. */ | 
|  | 5276 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); | 
|  | 5277 |  | 
|  | 5278 | vha->flags.online = 1; | 
|  | 5279 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ | 
|  | 5280 | wait_time = 256; | 
|  | 5281 | do { | 
|  | 5282 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); | 
|  | 5283 | qla2x00_configure_loop(vha); | 
|  | 5284 | wait_time--; | 
|  | 5285 | } while (!atomic_read(&vha->loop_down_timer) && | 
|  | 5286 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) && | 
|  | 5287 | wait_time && | 
|  | 5288 | (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))); | 
|  | 5289 | } | 
|  | 5290 |  | 
|  | 5291 | /* if no cable then assume it's good */ | 
|  | 5292 | if ((vha->device_flags & DFLG_NO_CABLE)) | 
|  | 5293 | status = 0; | 
|  | 5294 |  | 
| Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5295 | ql_log(ql_log_info, vha, 0x8000, | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5296 | "Configure loop done, status = 0x%x.\n", status); | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5297 | } | 
|  | 5298 |  | 
|  | 5299 | if (!status) { | 
|  | 5300 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); | 
|  | 5301 |  | 
|  | 5302 | if (!atomic_read(&vha->loop_down_timer)) { | 
|  | 5303 | /* | 
|  | 5304 | * Issue marker command only when we are going | 
|  | 5305 | * to start the I/O . | 
|  | 5306 | */ | 
|  | 5307 | vha->marker_needed = 1; | 
|  | 5308 | } | 
|  | 5309 |  | 
|  | 5310 | vha->flags.online = 1; | 
|  | 5311 |  | 
|  | 5312 | ha->isp_ops->enable_intrs(ha); | 
|  | 5313 |  | 
|  | 5314 | ha->isp_abort_cnt = 0; | 
|  | 5315 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); | 
|  | 5316 |  | 
| Saurav Kashyap | 5329678 | 2011-05-10 11:30:06 -0700 | [diff] [blame] | 5317 | /* Update the firmware version */ | 
| Giridhar Malavali | 3173167 | 2011-08-16 11:31:54 -0700 | [diff] [blame] | 5318 | status = qla82xx_check_md_needed(vha); | 
| Saurav Kashyap | 5329678 | 2011-05-10 11:30:06 -0700 | [diff] [blame] | 5319 |  | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5320 | if (ha->fce) { | 
|  | 5321 | ha->flags.fce_enabled = 1; | 
|  | 5322 | memset(ha->fce, 0, | 
|  | 5323 | fce_calc_size(ha->fce_bufs)); | 
|  | 5324 | rval = qla2x00_enable_fce_trace(vha, | 
|  | 5325 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, | 
|  | 5326 | &ha->fce_bufs); | 
|  | 5327 | if (rval) { | 
| Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5328 | ql_log(ql_log_warn, vha, 0x8001, | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5329 | "Unable to reinitialize FCE (%d).\n", | 
|  | 5330 | rval); | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5331 | ha->flags.fce_enabled = 0; | 
|  | 5332 | } | 
|  | 5333 | } | 
|  | 5334 |  | 
|  | 5335 | if (ha->eft) { | 
|  | 5336 | memset(ha->eft, 0, EFT_SIZE); | 
|  | 5337 | rval = qla2x00_enable_eft_trace(vha, | 
|  | 5338 | ha->eft_dma, EFT_NUM_BUFFERS); | 
|  | 5339 | if (rval) { | 
| Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5340 | ql_log(ql_log_warn, vha, 0x8010, | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5341 | "Unable to reinitialize EFT (%d).\n", | 
|  | 5342 | rval); | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5343 | } | 
|  | 5344 | } | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5345 | } | 
|  | 5346 |  | 
|  | 5347 | if (!status) { | 
| Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5348 | ql_dbg(ql_dbg_taskm, vha, 0x8011, | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5349 | "qla82xx_restart_isp succeeded.\n"); | 
| Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5350 |  | 
|  | 5351 | spin_lock_irqsave(&ha->vport_slock, flags); | 
|  | 5352 | list_for_each_entry(vp, &ha->vp_list, list) { | 
|  | 5353 | if (vp->vp_idx) { | 
|  | 5354 | atomic_inc(&vp->vref_count); | 
|  | 5355 | spin_unlock_irqrestore(&ha->vport_slock, flags); | 
|  | 5356 |  | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5357 | qla2x00_vp_abort_isp(vp); | 
| Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5358 |  | 
|  | 5359 | spin_lock_irqsave(&ha->vport_slock, flags); | 
|  | 5360 | atomic_dec(&vp->vref_count); | 
|  | 5361 | } | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5362 | } | 
| Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5363 | spin_unlock_irqrestore(&ha->vport_slock, flags); | 
|  | 5364 |  | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5365 | } else { | 
| Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5366 | ql_log(ql_log_warn, vha, 0x8016, | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5367 | "qla82xx_restart_isp **** FAILED ****.\n"); | 
| Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5368 | } | 
|  | 5369 |  | 
|  | 5370 | return status; | 
|  | 5371 | } | 
|  | 5372 |  | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5373 | void | 
| Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 5374 | qla81xx_update_fw_options(scsi_qla_host_t *vha) | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5375 | { | 
| Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 5376 | struct qla_hw_data *ha = vha->hw; | 
|  | 5377 |  | 
|  | 5378 | if (!ql2xetsenable) | 
|  | 5379 | return; | 
|  | 5380 |  | 
|  | 5381 | /* Enable ETS Burst. */ | 
|  | 5382 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); | 
|  | 5383 | ha->fw_options[2] |= BIT_9; | 
|  | 5384 | qla2x00_set_fw_options(vha, ha->fw_options); | 
| Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5385 | } | 
| Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5386 |  | 
|  | 5387 | /* | 
|  | 5388 | * qla24xx_get_fcp_prio | 
|  | 5389 | *	Gets the fcp cmd priority value for the logged in port. | 
|  | 5390 | *	Looks for a match of the port descriptors within | 
|  | 5391 | *	each of the fcp prio config entries. If a match is found, | 
|  | 5392 | *	the tag (priority) value is returned. | 
|  | 5393 | * | 
|  | 5394 | * Input: | 
| Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5395 | *	vha = scsi host structure pointer. | 
| Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5396 | *	fcport = port structure pointer. | 
|  | 5397 | * | 
|  | 5398 | * Return: | 
| Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 5399 | *	non-zero (if found) | 
| Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5400 | *	-1 (if not found) | 
| Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5401 | * | 
|  | 5402 | * Context: | 
|  | 5403 | * 	Kernel context | 
|  | 5404 | */ | 
| Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5405 | static int | 
| Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5406 | qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport) | 
|  | 5407 | { | 
|  | 5408 | int i, entries; | 
|  | 5409 | uint8_t pid_match, wwn_match; | 
| Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5410 | int priority; | 
| Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5411 | uint32_t pid1, pid2; | 
|  | 5412 | uint64_t wwn1, wwn2; | 
|  | 5413 | struct qla_fcp_prio_entry *pri_entry; | 
|  | 5414 | struct qla_hw_data *ha = vha->hw; | 
|  | 5415 |  | 
|  | 5416 | if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled) | 
| Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5417 | return -1; | 
| Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5418 |  | 
| Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5419 | priority = -1; | 
| Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5420 | entries = ha->fcp_prio_cfg->num_entries; | 
|  | 5421 | pri_entry = &ha->fcp_prio_cfg->entry[0]; | 
|  | 5422 |  | 
|  | 5423 | for (i = 0; i < entries; i++) { | 
|  | 5424 | pid_match = wwn_match = 0; | 
|  | 5425 |  | 
|  | 5426 | if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) { | 
|  | 5427 | pri_entry++; | 
|  | 5428 | continue; | 
|  | 5429 | } | 
|  | 5430 |  | 
|  | 5431 | /* check source pid for a match */ | 
|  | 5432 | if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) { | 
|  | 5433 | pid1 = pri_entry->src_pid & INVALID_PORT_ID; | 
|  | 5434 | pid2 = vha->d_id.b24 & INVALID_PORT_ID; | 
|  | 5435 | if (pid1 == INVALID_PORT_ID) | 
|  | 5436 | pid_match++; | 
|  | 5437 | else if (pid1 == pid2) | 
|  | 5438 | pid_match++; | 
|  | 5439 | } | 
|  | 5440 |  | 
|  | 5441 | /* check destination pid for a match */ | 
|  | 5442 | if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) { | 
|  | 5443 | pid1 = pri_entry->dst_pid & INVALID_PORT_ID; | 
|  | 5444 | pid2 = fcport->d_id.b24 & INVALID_PORT_ID; | 
|  | 5445 | if (pid1 == INVALID_PORT_ID) | 
|  | 5446 | pid_match++; | 
|  | 5447 | else if (pid1 == pid2) | 
|  | 5448 | pid_match++; | 
|  | 5449 | } | 
|  | 5450 |  | 
|  | 5451 | /* check source WWN for a match */ | 
|  | 5452 | if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) { | 
|  | 5453 | wwn1 = wwn_to_u64(vha->port_name); | 
|  | 5454 | wwn2 = wwn_to_u64(pri_entry->src_wwpn); | 
|  | 5455 | if (wwn2 == (uint64_t)-1) | 
|  | 5456 | wwn_match++; | 
|  | 5457 | else if (wwn1 == wwn2) | 
|  | 5458 | wwn_match++; | 
|  | 5459 | } | 
|  | 5460 |  | 
|  | 5461 | /* check destination WWN for a match */ | 
|  | 5462 | if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) { | 
|  | 5463 | wwn1 = wwn_to_u64(fcport->port_name); | 
|  | 5464 | wwn2 = wwn_to_u64(pri_entry->dst_wwpn); | 
|  | 5465 | if (wwn2 == (uint64_t)-1) | 
|  | 5466 | wwn_match++; | 
|  | 5467 | else if (wwn1 == wwn2) | 
|  | 5468 | wwn_match++; | 
|  | 5469 | } | 
|  | 5470 |  | 
|  | 5471 | if (pid_match == 2 || wwn_match == 2) { | 
|  | 5472 | /* Found a matching entry */ | 
|  | 5473 | if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID) | 
|  | 5474 | priority = pri_entry->tag; | 
|  | 5475 | break; | 
|  | 5476 | } | 
|  | 5477 |  | 
|  | 5478 | pri_entry++; | 
|  | 5479 | } | 
|  | 5480 |  | 
|  | 5481 | return priority; | 
|  | 5482 | } | 
|  | 5483 |  | 
|  | 5484 | /* | 
|  | 5485 | * qla24xx_update_fcport_fcp_prio | 
|  | 5486 | *	Activates fcp priority for the logged in fc port | 
|  | 5487 | * | 
|  | 5488 | * Input: | 
| Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5489 | *	vha = scsi host structure pointer. | 
| Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5490 | *	fcp = port structure pointer. | 
|  | 5491 | * | 
|  | 5492 | * Return: | 
|  | 5493 | *	QLA_SUCCESS or QLA_FUNCTION_FAILED | 
|  | 5494 | * | 
|  | 5495 | * Context: | 
|  | 5496 | *	Kernel context. | 
|  | 5497 | */ | 
|  | 5498 | int | 
| Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5499 | 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] | 5500 | { | 
|  | 5501 | int ret; | 
| Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5502 | int priority; | 
| Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5503 | uint16_t mb[5]; | 
|  | 5504 |  | 
| Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5505 | if (fcport->port_type != FCT_TARGET || | 
|  | 5506 | fcport->loop_id == FC_NO_LOOP_ID) | 
| Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5507 | return QLA_FUNCTION_FAILED; | 
|  | 5508 |  | 
| Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5509 | priority = qla24xx_get_fcp_prio(vha, fcport); | 
| Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5510 | if (priority < 0) | 
|  | 5511 | return QLA_FUNCTION_FAILED; | 
|  | 5512 |  | 
| Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 5513 | if (IS_QLA82XX(vha->hw)) { | 
|  | 5514 | fcport->fcp_prio = priority & 0xf; | 
|  | 5515 | return QLA_SUCCESS; | 
|  | 5516 | } | 
|  | 5517 |  | 
| Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5518 | ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb); | 
| Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5519 | if (ret == QLA_SUCCESS) { | 
|  | 5520 | if (fcport->fcp_prio != priority) | 
|  | 5521 | ql_dbg(ql_dbg_user, vha, 0x709e, | 
|  | 5522 | "Updated FCP_CMND priority - value=%d loop_id=%d " | 
|  | 5523 | "port_id=%02x%02x%02x.\n", priority, | 
|  | 5524 | fcport->loop_id, fcport->d_id.b.domain, | 
|  | 5525 | fcport->d_id.b.area, fcport->d_id.b.al_pa); | 
| Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 5526 | fcport->fcp_prio = priority & 0xf; | 
| Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5527 | } else | 
| Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5528 | ql_dbg(ql_dbg_user, vha, 0x704f, | 
| Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 5529 | "Unable to update FCP_CMND priority - ret=0x%x for " | 
|  | 5530 | "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id, | 
|  | 5531 | fcport->d_id.b.domain, fcport->d_id.b.area, | 
|  | 5532 | fcport->d_id.b.al_pa); | 
| Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5533 | return  ret; | 
|  | 5534 | } | 
|  | 5535 |  | 
|  | 5536 | /* | 
|  | 5537 | * qla24xx_update_all_fcp_prio | 
|  | 5538 | *	Activates fcp priority for all the logged in ports | 
|  | 5539 | * | 
|  | 5540 | * Input: | 
|  | 5541 | *	ha = adapter block pointer. | 
|  | 5542 | * | 
|  | 5543 | * Return: | 
|  | 5544 | *	QLA_SUCCESS or QLA_FUNCTION_FAILED | 
|  | 5545 | * | 
|  | 5546 | * Context: | 
|  | 5547 | *	Kernel context. | 
|  | 5548 | */ | 
|  | 5549 | int | 
|  | 5550 | qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha) | 
|  | 5551 | { | 
|  | 5552 | int ret; | 
|  | 5553 | fc_port_t *fcport; | 
|  | 5554 |  | 
|  | 5555 | ret = QLA_FUNCTION_FAILED; | 
|  | 5556 | /* We need to set priority for all logged in ports */ | 
|  | 5557 | list_for_each_entry(fcport, &vha->vp_fcports, list) | 
|  | 5558 | ret = qla24xx_update_fcport_fcp_prio(vha, fcport); | 
|  | 5559 |  | 
|  | 5560 | return ret; | 
|  | 5561 | } |