Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1 | /* |
Andrew Vasquez | 01e58d8 | 2008-04-03 13:13:13 -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 |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4 | * |
Andrew Vasquez | 01e58d8 | 2008-04-03 13:13:13 -0700 | [diff] [blame] | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6 | */ |
| 7 | #include "qla_def.h" |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 8 | #include "qla_gbl.h" |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 9 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 10 | #include <linux/moduleparam.h> |
| 11 | #include <linux/vmalloc.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 13 | #include <linux/list.h> |
| 14 | |
| 15 | #include <scsi/scsi_tcq.h> |
| 16 | #include <scsi/scsicam.h> |
| 17 | #include <linux/delay.h> |
| 18 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 19 | void |
| 20 | qla2x00_vp_stop_timer(scsi_qla_host_t *vha) |
| 21 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 22 | if (vha->vp_idx && vha->timer_active) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 23 | del_timer_sync(&vha->timer); |
| 24 | vha->timer_active = 0; |
| 25 | } |
| 26 | } |
| 27 | |
Adrian Bunk | a824ebb | 2008-01-17 09:02:15 -0800 | [diff] [blame] | 28 | static uint32_t |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 29 | qla24xx_allocate_vp_id(scsi_qla_host_t *vha) |
| 30 | { |
| 31 | uint32_t vp_id; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 32 | struct qla_hw_data *ha = vha->hw; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 33 | unsigned long flags; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 34 | |
| 35 | /* Find an empty slot and assign an vp_id */ |
matthias@kaehlcke.net | 6c2f527 | 2008-05-12 22:21:11 -0700 | [diff] [blame] | 36 | mutex_lock(&ha->vport_lock); |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 37 | vp_id = find_first_zero_bit(ha->vp_idx_map, ha->max_npiv_vports + 1); |
| 38 | if (vp_id > ha->max_npiv_vports) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 39 | ql_dbg(ql_dbg_vport, vha, 0xa000, |
| 40 | "vp_id %d is bigger than max-supported %d.\n", |
| 41 | vp_id, ha->max_npiv_vports); |
matthias@kaehlcke.net | 6c2f527 | 2008-05-12 22:21:11 -0700 | [diff] [blame] | 42 | mutex_unlock(&ha->vport_lock); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 43 | return vp_id; |
| 44 | } |
| 45 | |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 46 | set_bit(vp_id, ha->vp_idx_map); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 47 | ha->num_vhosts++; |
| 48 | vha->vp_idx = vp_id; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 49 | |
| 50 | spin_lock_irqsave(&ha->vport_slock, flags); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 51 | list_add_tail(&vha->list, &ha->vp_list); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 52 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 53 | |
matthias@kaehlcke.net | 6c2f527 | 2008-05-12 22:21:11 -0700 | [diff] [blame] | 54 | mutex_unlock(&ha->vport_lock); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 55 | return vp_id; |
| 56 | } |
| 57 | |
| 58 | void |
| 59 | qla24xx_deallocate_vp_id(scsi_qla_host_t *vha) |
| 60 | { |
| 61 | uint16_t vp_id; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 62 | struct qla_hw_data *ha = vha->hw; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 63 | unsigned long flags = 0; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 64 | |
matthias@kaehlcke.net | 6c2f527 | 2008-05-12 22:21:11 -0700 | [diff] [blame] | 65 | mutex_lock(&ha->vport_lock); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 66 | /* |
| 67 | * Wait for all pending activities to finish before removing vport from |
| 68 | * the list. |
| 69 | * Lock needs to be held for safe removal from the list (it |
| 70 | * ensures no active vp_list traversal while the vport is removed |
| 71 | * from the queue) |
| 72 | */ |
| 73 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 74 | while (atomic_read(&vha->vref_count)) { |
| 75 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 76 | |
| 77 | msleep(500); |
| 78 | |
| 79 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 80 | } |
| 81 | list_del(&vha->list); |
| 82 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 83 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 84 | vp_id = vha->vp_idx; |
| 85 | ha->num_vhosts--; |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 86 | clear_bit(vp_id, ha->vp_idx_map); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 87 | |
matthias@kaehlcke.net | 6c2f527 | 2008-05-12 22:21:11 -0700 | [diff] [blame] | 88 | mutex_unlock(&ha->vport_lock); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Adrian Bunk | a824ebb | 2008-01-17 09:02:15 -0800 | [diff] [blame] | 91 | static scsi_qla_host_t * |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 92 | qla24xx_find_vhost_by_name(struct qla_hw_data *ha, uint8_t *port_name) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 93 | { |
| 94 | scsi_qla_host_t *vha; |
Anirban Chakraborty | ee546b6 | 2009-03-05 11:07:02 -0800 | [diff] [blame] | 95 | struct scsi_qla_host *tvha; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 96 | unsigned long flags; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 97 | |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 98 | spin_lock_irqsave(&ha->vport_slock, flags); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 99 | /* Locate matching device in database. */ |
Anirban Chakraborty | ee546b6 | 2009-03-05 11:07:02 -0800 | [diff] [blame] | 100 | list_for_each_entry_safe(vha, tvha, &ha->vp_list, list) { |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 101 | if (!memcmp(port_name, vha->port_name, WWN_SIZE)) { |
| 102 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 103 | return vha; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 104 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 105 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 106 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 107 | return NULL; |
| 108 | } |
| 109 | |
| 110 | /* |
| 111 | * qla2x00_mark_vp_devices_dead |
| 112 | * Updates fcport state when device goes offline. |
| 113 | * |
| 114 | * Input: |
| 115 | * ha = adapter block pointer. |
| 116 | * fcport = port structure pointer. |
| 117 | * |
| 118 | * Return: |
| 119 | * None. |
| 120 | * |
| 121 | * Context: |
| 122 | */ |
Andrew Vasquez | 26ff776 | 2007-09-20 14:07:47 -0700 | [diff] [blame] | 123 | static void |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 124 | qla2x00_mark_vp_devices_dead(scsi_qla_host_t *vha) |
| 125 | { |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 126 | /* |
| 127 | * !!! NOTE !!! |
| 128 | * This function, if called in contexts other than vp create, disable |
| 129 | * or delete, please make sure this is synchronized with the |
| 130 | * delete thread. |
| 131 | */ |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 132 | fc_port_t *fcport; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 133 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 134 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 135 | ql_dbg(ql_dbg_vport, vha, 0xa001, |
| 136 | "Marking port dead, loop_id=0x%04x : %x.\n", |
Joe Carnuccio | c6d39e2 | 2012-05-15 14:34:20 -0400 | [diff] [blame] | 137 | fcport->loop_id, fcport->vha->vp_idx); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 138 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 139 | qla2x00_mark_device_lost(vha, fcport, 0, 0); |
Chad Dupuis | ec426e1 | 2011-03-30 11:46:32 -0700 | [diff] [blame] | 140 | qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 141 | } |
| 142 | } |
| 143 | |
| 144 | int |
| 145 | qla24xx_disable_vp(scsi_qla_host_t *vha) |
| 146 | { |
| 147 | int ret; |
| 148 | |
| 149 | ret = qla24xx_control_vp(vha, VCE_COMMAND_DISABLE_VPS_LOGO_ALL); |
| 150 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 151 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 152 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 153 | qla2x00_mark_vp_devices_dead(vha); |
| 154 | atomic_set(&vha->vp_state, VP_FAILED); |
| 155 | vha->flags.management_server_logged_in = 0; |
| 156 | if (ret == QLA_SUCCESS) { |
| 157 | fc_vport_set_state(vha->fc_vport, FC_VPORT_DISABLED); |
| 158 | } else { |
| 159 | fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED); |
| 160 | return -1; |
| 161 | } |
| 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | int |
| 166 | qla24xx_enable_vp(scsi_qla_host_t *vha) |
| 167 | { |
| 168 | int ret; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 169 | struct qla_hw_data *ha = vha->hw; |
| 170 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 171 | |
| 172 | /* Check if physical ha port is Up */ |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 173 | if (atomic_read(&base_vha->loop_state) == LOOP_DOWN || |
Lalit Chandivade | 3f3b6f9 | 2010-05-28 15:08:24 -0700 | [diff] [blame] | 174 | atomic_read(&base_vha->loop_state) == LOOP_DEAD || |
| 175 | !(ha->current_topology & ISP_CFG_F)) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 176 | vha->vp_err_state = VP_ERR_PORTDWN; |
| 177 | fc_vport_set_state(vha->fc_vport, FC_VPORT_LINKDOWN); |
| 178 | goto enable_failed; |
| 179 | } |
| 180 | |
| 181 | /* Initialize the new vport unless it is a persistent port */ |
matthias@kaehlcke.net | 6c2f527 | 2008-05-12 22:21:11 -0700 | [diff] [blame] | 182 | mutex_lock(&ha->vport_lock); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 183 | ret = qla24xx_modify_vp_config(vha); |
matthias@kaehlcke.net | 6c2f527 | 2008-05-12 22:21:11 -0700 | [diff] [blame] | 184 | mutex_unlock(&ha->vport_lock); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 185 | |
| 186 | if (ret != QLA_SUCCESS) { |
| 187 | fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED); |
| 188 | goto enable_failed; |
| 189 | } |
| 190 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 191 | ql_dbg(ql_dbg_taskm, vha, 0x801a, |
| 192 | "Virtual port with id: %d - Enabled.\n", vha->vp_idx); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 193 | return 0; |
| 194 | |
| 195 | enable_failed: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 196 | ql_dbg(ql_dbg_taskm, vha, 0x801b, |
| 197 | "Virtual port with id: %d - Disabled.\n", vha->vp_idx); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 198 | return 1; |
| 199 | } |
| 200 | |
Andrew Vasquez | 26ff776 | 2007-09-20 14:07:47 -0700 | [diff] [blame] | 201 | static void |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 202 | qla24xx_configure_vp(scsi_qla_host_t *vha) |
| 203 | { |
| 204 | struct fc_vport *fc_vport; |
| 205 | int ret; |
| 206 | |
| 207 | fc_vport = vha->fc_vport; |
| 208 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 209 | ql_dbg(ql_dbg_vport, vha, 0xa002, |
| 210 | "%s: change request #3.\n", __func__); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 211 | ret = qla2x00_send_change_request(vha, 0x3, vha->vp_idx); |
| 212 | if (ret != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 213 | ql_dbg(ql_dbg_vport, vha, 0xa003, "Failed to enable " |
| 214 | "receiving of RSCN requests: 0x%x.\n", ret); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 215 | return; |
| 216 | } else { |
| 217 | /* Corresponds to SCR enabled */ |
| 218 | clear_bit(VP_SCR_NEEDED, &vha->vp_flags); |
| 219 | } |
| 220 | |
| 221 | vha->flags.online = 1; |
| 222 | if (qla24xx_configure_vhba(vha)) |
| 223 | return; |
| 224 | |
| 225 | atomic_set(&vha->vp_state, VP_ACTIVE); |
| 226 | fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE); |
| 227 | } |
| 228 | |
| 229 | void |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 230 | qla2x00_alert_all_vps(struct rsp_que *rsp, uint16_t *mb) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 231 | { |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 232 | scsi_qla_host_t *vha; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 233 | struct qla_hw_data *ha = rsp->hw; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 234 | int i = 0; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 235 | unsigned long flags; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 236 | |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 237 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 238 | list_for_each_entry(vha, &ha->vp_list, list) { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 239 | if (vha->vp_idx) { |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 240 | atomic_inc(&vha->vref_count); |
| 241 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 242 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 243 | switch (mb[0]) { |
| 244 | case MBA_LIP_OCCURRED: |
| 245 | case MBA_LOOP_UP: |
| 246 | case MBA_LOOP_DOWN: |
| 247 | case MBA_LIP_RESET: |
| 248 | case MBA_POINT_TO_POINT: |
| 249 | case MBA_CHG_IN_CONNECTION: |
| 250 | case MBA_PORT_UPDATE: |
| 251 | case MBA_RSCN_UPDATE: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 252 | ql_dbg(ql_dbg_async, vha, 0x5024, |
| 253 | "Async_event for VP[%d], mb=0x%x vha=%p.\n", |
| 254 | i, *mb, vha); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 255 | qla2x00_async_event(vha, rsp, mb); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 256 | break; |
| 257 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 258 | |
| 259 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 260 | atomic_dec(&vha->vref_count); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 261 | } |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 262 | i++; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 263 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 264 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 267 | int |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 268 | qla2x00_vp_abort_isp(scsi_qla_host_t *vha) |
| 269 | { |
| 270 | /* |
| 271 | * Physical port will do most of the abort and recovery work. We can |
| 272 | * just treat it as a loop down |
| 273 | */ |
| 274 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 275 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 276 | qla2x00_mark_all_devices_lost(vha, 0); |
| 277 | } else { |
| 278 | if (!atomic_read(&vha->loop_down_timer)) |
| 279 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 280 | } |
| 281 | |
Andrew Vasquez | 0d6e61b | 2009-08-25 11:36:19 -0700 | [diff] [blame] | 282 | /* |
| 283 | * To exclusively reset vport, we need to log it out first. Note: this |
| 284 | * control_vp can fail if ISP reset is already issued, this is |
| 285 | * expected, as the vp would be already logged out due to ISP reset. |
| 286 | */ |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 287 | if (!test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) |
| 288 | qla24xx_control_vp(vha, VCE_COMMAND_DISABLE_VPS_LOGO_ALL); |
| 289 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 290 | ql_dbg(ql_dbg_taskm, vha, 0x801d, |
| 291 | "Scheduling enable of Vport %d.\n", vha->vp_idx); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 292 | return qla24xx_enable_vp(vha); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Adrian Bunk | a824ebb | 2008-01-17 09:02:15 -0800 | [diff] [blame] | 295 | static int |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 296 | qla2x00_do_dpc_vp(scsi_qla_host_t *vha) |
| 297 | { |
Saurav Kashyap | 5f28d2d | 2012-05-15 14:34:15 -0400 | [diff] [blame] | 298 | ql_dbg(ql_dbg_dpc + ql_dbg_verbose, vha, 0x4012, |
| 299 | "Entering %s vp_flags: 0x%lx.\n", __func__, vha->vp_flags); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 300 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 301 | qla2x00_do_work(vha); |
| 302 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 303 | if (test_and_clear_bit(VP_IDX_ACQUIRED, &vha->vp_flags)) { |
| 304 | /* VP acquired. complete port configuration */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 305 | ql_dbg(ql_dbg_dpc, vha, 0x4014, |
| 306 | "Configure VP scheduled.\n"); |
Andrew Vasquez | 0d6e61b | 2009-08-25 11:36:19 -0700 | [diff] [blame] | 307 | qla24xx_configure_vp(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 308 | ql_dbg(ql_dbg_dpc, vha, 0x4015, |
| 309 | "Configure VP end.\n"); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 310 | return 0; |
| 311 | } |
| 312 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 313 | if (test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 314 | ql_dbg(ql_dbg_dpc, vha, 0x4016, |
| 315 | "FCPort update scheduled.\n"); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 316 | qla2x00_update_fcports(vha); |
| 317 | clear_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 318 | ql_dbg(ql_dbg_dpc, vha, 0x4017, |
| 319 | "FCPort update end.\n"); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | if ((test_and_clear_bit(RELOGIN_NEEDED, &vha->dpc_flags)) && |
| 323 | !test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) && |
| 324 | atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 325 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 326 | ql_dbg(ql_dbg_dpc, vha, 0x4018, |
| 327 | "Relogin needed scheduled.\n"); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 328 | qla2x00_relogin(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 329 | ql_dbg(ql_dbg_dpc, vha, 0x4019, |
| 330 | "Relogin needed end.\n"); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 331 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 332 | |
| 333 | if (test_and_clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) && |
| 334 | (!(test_and_set_bit(RESET_ACTIVE, &vha->dpc_flags)))) { |
| 335 | clear_bit(RESET_ACTIVE, &vha->dpc_flags); |
| 336 | } |
| 337 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 338 | if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 339 | if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags))) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 340 | ql_dbg(ql_dbg_dpc, vha, 0x401a, |
| 341 | "Loop resync scheduled.\n"); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 342 | qla2x00_loop_resync(vha); |
| 343 | clear_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 344 | ql_dbg(ql_dbg_dpc, vha, 0x401b, |
| 345 | "Loop resync end.\n"); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | |
Saurav Kashyap | 5f28d2d | 2012-05-15 14:34:15 -0400 | [diff] [blame] | 349 | ql_dbg(ql_dbg_dpc + ql_dbg_verbose, vha, 0x401c, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 350 | "Exiting %s.\n", __func__); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 351 | return 0; |
| 352 | } |
| 353 | |
| 354 | void |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 355 | qla2x00_do_dpc_all_vps(scsi_qla_host_t *vha) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 356 | { |
| 357 | int ret; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 358 | struct qla_hw_data *ha = vha->hw; |
| 359 | scsi_qla_host_t *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 360 | unsigned long flags = 0; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 361 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 362 | if (vha->vp_idx) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 363 | return; |
| 364 | if (list_empty(&ha->vp_list)) |
| 365 | return; |
| 366 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 367 | clear_bit(VP_DPC_NEEDED, &vha->dpc_flags); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 368 | |
Andrew Vasquez | 0d6e61b | 2009-08-25 11:36:19 -0700 | [diff] [blame] | 369 | if (!(ha->current_topology & ISP_CFG_F)) |
| 370 | return; |
| 371 | |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 372 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 373 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 374 | if (vp->vp_idx) { |
| 375 | atomic_inc(&vp->vref_count); |
| 376 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 377 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 378 | ret = qla2x00_do_dpc_vp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 379 | |
| 380 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 381 | atomic_dec(&vp->vref_count); |
| 382 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 383 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 384 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | int |
| 388 | qla24xx_vport_create_req_sanity_check(struct fc_vport *fc_vport) |
| 389 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 390 | scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost); |
| 391 | struct qla_hw_data *ha = base_vha->hw; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 392 | scsi_qla_host_t *vha; |
| 393 | uint8_t port_name[WWN_SIZE]; |
| 394 | |
| 395 | if (fc_vport->roles != FC_PORT_ROLE_FCP_INITIATOR) |
| 396 | return VPCERR_UNSUPPORTED; |
| 397 | |
| 398 | /* Check up the F/W and H/W support NPIV */ |
| 399 | if (!ha->flags.npiv_supported) |
| 400 | return VPCERR_UNSUPPORTED; |
| 401 | |
| 402 | /* Check up whether npiv supported switch presented */ |
| 403 | if (!(ha->switch_cap & FLOGI_MID_SUPPORT)) |
| 404 | return VPCERR_NO_FABRIC_SUPP; |
| 405 | |
| 406 | /* Check up unique WWPN */ |
| 407 | u64_to_wwn(fc_vport->port_name, port_name); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 408 | if (!memcmp(port_name, base_vha->port_name, WWN_SIZE)) |
Seokmann Ju | 50db6b1 | 2008-01-17 09:02:14 -0800 | [diff] [blame] | 409 | return VPCERR_BAD_WWN; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 410 | vha = qla24xx_find_vhost_by_name(ha, port_name); |
| 411 | if (vha) |
| 412 | return VPCERR_BAD_WWN; |
| 413 | |
| 414 | /* Check up max-npiv-supports */ |
| 415 | if (ha->num_vhosts > ha->max_npiv_vports) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 416 | ql_dbg(ql_dbg_vport, vha, 0xa004, |
| 417 | "num_vhosts %ud is bigger " |
| 418 | "than max_npiv_vports %ud.\n", |
| 419 | ha->num_vhosts, ha->max_npiv_vports); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 420 | return VPCERR_UNSUPPORTED; |
| 421 | } |
| 422 | return 0; |
| 423 | } |
| 424 | |
| 425 | scsi_qla_host_t * |
| 426 | qla24xx_create_vhost(struct fc_vport *fc_vport) |
| 427 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 428 | scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost); |
| 429 | struct qla_hw_data *ha = base_vha->hw; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 430 | scsi_qla_host_t *vha; |
Giridhar Malavali | a5326f8 | 2009-03-24 09:07:56 -0700 | [diff] [blame] | 431 | struct scsi_host_template *sht = &qla2xxx_driver_template; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 432 | struct Scsi_Host *host; |
| 433 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 434 | vha = qla2x00_create_host(sht, ha); |
| 435 | if (!vha) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 436 | ql_log(ql_log_warn, vha, 0xa005, |
| 437 | "scsi_host_alloc() failed for vport.\n"); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 438 | return(NULL); |
| 439 | } |
| 440 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 441 | host = vha->host; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 442 | fc_vport->dd_data = vha; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 443 | /* New host info */ |
| 444 | u64_to_wwn(fc_vport->node_name, vha->node_name); |
| 445 | u64_to_wwn(fc_vport->port_name, vha->port_name); |
| 446 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 447 | vha->fc_vport = fc_vport; |
| 448 | vha->device_flags = 0; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 449 | vha->vp_idx = qla24xx_allocate_vp_id(vha); |
| 450 | if (vha->vp_idx > ha->max_npiv_vports) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 451 | ql_dbg(ql_dbg_vport, vha, 0xa006, |
| 452 | "Couldn't allocate vp_id.\n"); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 453 | goto create_vhost_failed; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 454 | } |
| 455 | vha->mgmt_svr_loop_id = 10 + vha->vp_idx; |
| 456 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 457 | vha->dpc_flags = 0L; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 458 | |
| 459 | /* |
| 460 | * To fix the issue of processing a parent's RSCN for the vport before |
| 461 | * its SCR is complete. |
| 462 | */ |
| 463 | set_bit(VP_SCR_NEEDED, &vha->vp_flags); |
| 464 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 465 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 466 | |
| 467 | qla2x00_start_timer(vha, qla2x00_timer, WATCH_INTERVAL); |
| 468 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 469 | vha->req = base_vha->req; |
| 470 | host->can_queue = base_vha->req->length + 128; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 471 | host->this_id = 255; |
| 472 | host->cmd_per_lun = 3; |
Arun Easi | e02587d | 2011-08-16 11:29:23 -0700 | [diff] [blame] | 473 | if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) |
Arun Easi | 0c47087 | 2010-07-23 15:28:38 +0500 | [diff] [blame] | 474 | host->max_cmd_len = 32; |
| 475 | else |
| 476 | host->max_cmd_len = MAX_CMDSZ; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 477 | host->max_channel = MAX_BUSES - 1; |
Andrew Vasquez | 8251592 | 2011-05-10 11:30:13 -0700 | [diff] [blame] | 478 | host->max_lun = ql2xmaxlun; |
Seokmann Ju | 711c1d9 | 2008-07-10 16:55:51 -0700 | [diff] [blame] | 479 | host->unique_id = host->host_no; |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 480 | host->max_id = ha->max_fibre_devices; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 481 | host->transportt = qla2xxx_transport_vport_template; |
| 482 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 483 | ql_dbg(ql_dbg_vport, vha, 0xa007, |
| 484 | "Detect vport hba %ld at address = %p.\n", |
| 485 | vha->host_no, vha); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 486 | |
| 487 | vha->flags.init_done = 1; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 488 | |
Andrew Vasquez | 0d6e61b | 2009-08-25 11:36:19 -0700 | [diff] [blame] | 489 | mutex_lock(&ha->vport_lock); |
| 490 | set_bit(vha->vp_idx, ha->vp_idx_map); |
| 491 | ha->cur_vport_count++; |
| 492 | mutex_unlock(&ha->vport_lock); |
| 493 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 494 | return vha; |
| 495 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame] | 496 | create_vhost_failed: |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 497 | return NULL; |
| 498 | } |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 499 | |
| 500 | static void |
| 501 | qla25xx_free_req_que(struct scsi_qla_host *vha, struct req_que *req) |
| 502 | { |
| 503 | struct qla_hw_data *ha = vha->hw; |
| 504 | uint16_t que_id = req->id; |
| 505 | |
| 506 | dma_free_coherent(&ha->pdev->dev, (req->length + 1) * |
| 507 | sizeof(request_t), req->ring, req->dma); |
| 508 | req->ring = NULL; |
| 509 | req->dma = 0; |
| 510 | if (que_id) { |
| 511 | ha->req_q_map[que_id] = NULL; |
| 512 | mutex_lock(&ha->vport_lock); |
| 513 | clear_bit(que_id, ha->req_qid_map); |
| 514 | mutex_unlock(&ha->vport_lock); |
| 515 | } |
| 516 | kfree(req); |
| 517 | req = NULL; |
| 518 | } |
| 519 | |
| 520 | static void |
| 521 | qla25xx_free_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp) |
| 522 | { |
| 523 | struct qla_hw_data *ha = vha->hw; |
| 524 | uint16_t que_id = rsp->id; |
| 525 | |
| 526 | if (rsp->msix && rsp->msix->have_irq) { |
| 527 | free_irq(rsp->msix->vector, rsp); |
| 528 | rsp->msix->have_irq = 0; |
| 529 | rsp->msix->rsp = NULL; |
| 530 | } |
| 531 | dma_free_coherent(&ha->pdev->dev, (rsp->length + 1) * |
| 532 | sizeof(response_t), rsp->ring, rsp->dma); |
| 533 | rsp->ring = NULL; |
| 534 | rsp->dma = 0; |
| 535 | if (que_id) { |
| 536 | ha->rsp_q_map[que_id] = NULL; |
| 537 | mutex_lock(&ha->vport_lock); |
| 538 | clear_bit(que_id, ha->rsp_qid_map); |
| 539 | mutex_unlock(&ha->vport_lock); |
| 540 | } |
| 541 | kfree(rsp); |
| 542 | rsp = NULL; |
| 543 | } |
| 544 | |
| 545 | int |
| 546 | qla25xx_delete_req_que(struct scsi_qla_host *vha, struct req_que *req) |
| 547 | { |
| 548 | int ret = -1; |
| 549 | |
| 550 | if (req) { |
| 551 | req->options |= BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 552 | ret = qla25xx_init_req_que(vha, req); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 553 | } |
| 554 | if (ret == QLA_SUCCESS) |
| 555 | qla25xx_free_req_que(vha, req); |
| 556 | |
| 557 | return ret; |
| 558 | } |
| 559 | |
Andrew Vasquez | 3dbe756 | 2010-07-23 15:28:37 +0500 | [diff] [blame] | 560 | static int |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 561 | qla25xx_delete_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp) |
| 562 | { |
| 563 | int ret = -1; |
| 564 | |
| 565 | if (rsp) { |
| 566 | rsp->options |= BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 567 | ret = qla25xx_init_rsp_que(vha, rsp); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 568 | } |
| 569 | if (ret == QLA_SUCCESS) |
| 570 | qla25xx_free_rsp_que(vha, rsp); |
| 571 | |
| 572 | return ret; |
| 573 | } |
| 574 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 575 | /* Delete all queues for a given vhost */ |
| 576 | int |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 577 | qla25xx_delete_queues(struct scsi_qla_host *vha) |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 578 | { |
| 579 | int cnt, ret = 0; |
| 580 | struct req_que *req = NULL; |
| 581 | struct rsp_que *rsp = NULL; |
| 582 | struct qla_hw_data *ha = vha->hw; |
| 583 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 584 | /* Delete request queues */ |
| 585 | for (cnt = 1; cnt < ha->max_req_queues; cnt++) { |
| 586 | req = ha->req_q_map[cnt]; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 587 | if (req) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 588 | ret = qla25xx_delete_req_que(vha, req); |
| 589 | if (ret != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 590 | ql_log(ql_log_warn, vha, 0x00ea, |
| 591 | "Couldn't delete req que %d.\n", |
| 592 | req->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 593 | return ret; |
| 594 | } |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 595 | } |
| 596 | } |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 597 | |
| 598 | /* Delete response queues */ |
| 599 | for (cnt = 1; cnt < ha->max_rsp_queues; cnt++) { |
| 600 | rsp = ha->rsp_q_map[cnt]; |
| 601 | if (rsp) { |
| 602 | ret = qla25xx_delete_rsp_que(vha, rsp); |
| 603 | if (ret != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 604 | ql_log(ql_log_warn, vha, 0x00eb, |
| 605 | "Couldn't delete rsp que %d.\n", |
| 606 | rsp->id); |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 607 | return ret; |
| 608 | } |
| 609 | } |
| 610 | } |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 611 | return ret; |
| 612 | } |
| 613 | |
| 614 | int |
| 615 | qla25xx_create_req_que(struct qla_hw_data *ha, uint16_t options, |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 616 | uint8_t vp_idx, uint16_t rid, int rsp_que, uint8_t qos) |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 617 | { |
| 618 | int ret = 0; |
| 619 | struct req_que *req = NULL; |
| 620 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
| 621 | uint16_t que_id = 0; |
Andrew Vasquez | 0802999 | 2009-03-24 09:07:55 -0700 | [diff] [blame] | 622 | device_reg_t __iomem *reg; |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 623 | uint32_t cnt; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 624 | |
| 625 | req = kzalloc(sizeof(struct req_que), GFP_KERNEL); |
| 626 | if (req == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 627 | ql_log(ql_log_fatal, base_vha, 0x00d9, |
| 628 | "Failed to allocate memory for request queue.\n"); |
Anirban Chakraborty | c7922a9 | 2009-09-28 13:52:58 -0700 | [diff] [blame] | 629 | goto failed; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | req->length = REQUEST_ENTRY_CNT_24XX; |
| 633 | req->ring = dma_alloc_coherent(&ha->pdev->dev, |
| 634 | (req->length + 1) * sizeof(request_t), |
| 635 | &req->dma, GFP_KERNEL); |
| 636 | if (req->ring == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 637 | ql_log(ql_log_fatal, base_vha, 0x00da, |
| 638 | "Failed to allocte memory for request_ring.\n"); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 639 | goto que_failed; |
| 640 | } |
| 641 | |
| 642 | mutex_lock(&ha->vport_lock); |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 643 | que_id = find_first_zero_bit(ha->req_qid_map, ha->max_req_queues); |
| 644 | if (que_id >= ha->max_req_queues) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 645 | mutex_unlock(&ha->vport_lock); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 646 | ql_log(ql_log_warn, base_vha, 0x00db, |
| 647 | "No resources to create additional request queue.\n"); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 648 | goto que_failed; |
| 649 | } |
| 650 | set_bit(que_id, ha->req_qid_map); |
| 651 | ha->req_q_map[que_id] = req; |
| 652 | req->rid = rid; |
| 653 | req->vp_idx = vp_idx; |
| 654 | req->qos = qos; |
| 655 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 656 | ql_dbg(ql_dbg_multiq, base_vha, 0xc002, |
| 657 | "queue_id=%d rid=%d vp_idx=%d qos=%d.\n", |
| 658 | que_id, req->rid, req->vp_idx, req->qos); |
| 659 | ql_dbg(ql_dbg_init, base_vha, 0x00dc, |
| 660 | "queue_id=%d rid=%d vp_idx=%d qos=%d.\n", |
| 661 | que_id, req->rid, req->vp_idx, req->qos); |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 662 | if (rsp_que < 0) |
| 663 | req->rsp = NULL; |
| 664 | else |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 665 | req->rsp = ha->rsp_q_map[rsp_que]; |
| 666 | /* Use alternate PCI bus number */ |
| 667 | if (MSB(req->rid)) |
| 668 | options |= BIT_4; |
| 669 | /* Use alternate PCI devfn */ |
| 670 | if (LSB(req->rid)) |
| 671 | options |= BIT_5; |
| 672 | req->options = options; |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 673 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 674 | ql_dbg(ql_dbg_multiq, base_vha, 0xc003, |
| 675 | "options=0x%x.\n", req->options); |
| 676 | ql_dbg(ql_dbg_init, base_vha, 0x00dd, |
| 677 | "options=0x%x.\n", req->options); |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 678 | for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) |
| 679 | req->outstanding_cmds[cnt] = NULL; |
| 680 | req->current_outstanding_cmd = 1; |
| 681 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 682 | req->ring_ptr = req->ring; |
| 683 | req->ring_index = 0; |
| 684 | req->cnt = req->length; |
| 685 | req->id = que_id; |
Andrew Vasquez | 0802999 | 2009-03-24 09:07:55 -0700 | [diff] [blame] | 686 | reg = ISP_QUE_REG(ha, que_id); |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 687 | req->max_q_depth = ha->req_q_map[0]->max_q_depth; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 688 | mutex_unlock(&ha->vport_lock); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 689 | ql_dbg(ql_dbg_multiq, base_vha, 0xc004, |
| 690 | "ring_ptr=%p ring_index=%d, " |
| 691 | "cnt=%d id=%d max_q_depth=%d.\n", |
| 692 | req->ring_ptr, req->ring_index, |
| 693 | req->cnt, req->id, req->max_q_depth); |
| 694 | ql_dbg(ql_dbg_init, base_vha, 0x00de, |
| 695 | "ring_ptr=%p ring_index=%d, " |
| 696 | "cnt=%d id=%d max_q_depth=%d.\n", |
| 697 | req->ring_ptr, req->ring_index, req->cnt, |
| 698 | req->id, req->max_q_depth); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 699 | |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 700 | ret = qla25xx_init_req_que(base_vha, req); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 701 | if (ret != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 702 | ql_log(ql_log_fatal, base_vha, 0x00df, |
| 703 | "%s failed.\n", __func__); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 704 | mutex_lock(&ha->vport_lock); |
| 705 | clear_bit(que_id, ha->req_qid_map); |
| 706 | mutex_unlock(&ha->vport_lock); |
| 707 | goto que_failed; |
| 708 | } |
| 709 | |
| 710 | return req->id; |
| 711 | |
| 712 | que_failed: |
| 713 | qla25xx_free_req_que(base_vha, req); |
Anirban Chakraborty | c7922a9 | 2009-09-28 13:52:58 -0700 | [diff] [blame] | 714 | failed: |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 715 | return 0; |
| 716 | } |
| 717 | |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 718 | static void qla_do_work(struct work_struct *work) |
| 719 | { |
Anirban Chakraborty | a67093d | 2010-02-04 14:17:59 -0800 | [diff] [blame] | 720 | unsigned long flags; |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 721 | struct rsp_que *rsp = container_of(work, struct rsp_que, q_work); |
| 722 | struct scsi_qla_host *vha; |
Anirban Chakraborty | a67093d | 2010-02-04 14:17:59 -0800 | [diff] [blame] | 723 | struct qla_hw_data *ha = rsp->hw; |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 724 | |
Anirban Chakraborty | a67093d | 2010-02-04 14:17:59 -0800 | [diff] [blame] | 725 | spin_lock_irqsave(&rsp->hw->hardware_lock, flags); |
| 726 | vha = pci_get_drvdata(ha->pdev); |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 727 | qla24xx_process_response_queue(vha, rsp); |
Anirban Chakraborty | a67093d | 2010-02-04 14:17:59 -0800 | [diff] [blame] | 728 | spin_unlock_irqrestore(&rsp->hw->hardware_lock, flags); |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 729 | } |
| 730 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 731 | /* create response queue */ |
| 732 | int |
| 733 | qla25xx_create_rsp_que(struct qla_hw_data *ha, uint16_t options, |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 734 | uint8_t vp_idx, uint16_t rid, int req) |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 735 | { |
| 736 | int ret = 0; |
| 737 | struct rsp_que *rsp = NULL; |
| 738 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Andrew Vasquez | 0802999 | 2009-03-24 09:07:55 -0700 | [diff] [blame] | 739 | uint16_t que_id = 0; |
| 740 | device_reg_t __iomem *reg; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 741 | |
| 742 | rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL); |
| 743 | if (rsp == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 744 | ql_log(ql_log_warn, base_vha, 0x0066, |
| 745 | "Failed to allocate memory for response queue.\n"); |
Anirban Chakraborty | c7922a9 | 2009-09-28 13:52:58 -0700 | [diff] [blame] | 746 | goto failed; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 747 | } |
| 748 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 749 | rsp->length = RESPONSE_ENTRY_CNT_MQ; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 750 | rsp->ring = dma_alloc_coherent(&ha->pdev->dev, |
| 751 | (rsp->length + 1) * sizeof(response_t), |
| 752 | &rsp->dma, GFP_KERNEL); |
| 753 | if (rsp->ring == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 754 | ql_log(ql_log_warn, base_vha, 0x00e1, |
| 755 | "Failed to allocate memory for response ring.\n"); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 756 | goto que_failed; |
| 757 | } |
| 758 | |
| 759 | mutex_lock(&ha->vport_lock); |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 760 | que_id = find_first_zero_bit(ha->rsp_qid_map, ha->max_rsp_queues); |
| 761 | if (que_id >= ha->max_rsp_queues) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 762 | mutex_unlock(&ha->vport_lock); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 763 | ql_log(ql_log_warn, base_vha, 0x00e2, |
| 764 | "No resources to create additional request queue.\n"); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 765 | goto que_failed; |
| 766 | } |
| 767 | set_bit(que_id, ha->rsp_qid_map); |
| 768 | |
| 769 | if (ha->flags.msix_enabled) |
| 770 | rsp->msix = &ha->msix_entries[que_id + 1]; |
| 771 | else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 772 | ql_log(ql_log_warn, base_vha, 0x00e3, |
| 773 | "MSIX not enalbled.\n"); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 774 | |
| 775 | ha->rsp_q_map[que_id] = rsp; |
| 776 | rsp->rid = rid; |
| 777 | rsp->vp_idx = vp_idx; |
| 778 | rsp->hw = ha; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 779 | ql_dbg(ql_dbg_init, base_vha, 0x00e4, |
| 780 | "queue_id=%d rid=%d vp_idx=%d hw=%p.\n", |
| 781 | que_id, rsp->rid, rsp->vp_idx, rsp->hw); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 782 | /* Use alternate PCI bus number */ |
| 783 | if (MSB(rsp->rid)) |
| 784 | options |= BIT_4; |
| 785 | /* Use alternate PCI devfn */ |
| 786 | if (LSB(rsp->rid)) |
| 787 | options |= BIT_5; |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 788 | /* Enable MSIX handshake mode on for uncapable adapters */ |
| 789 | if (!IS_MSIX_NACK_CAPABLE(ha)) |
| 790 | options |= BIT_6; |
| 791 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 792 | rsp->options = options; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 793 | rsp->id = que_id; |
Andrew Vasquez | 0802999 | 2009-03-24 09:07:55 -0700 | [diff] [blame] | 794 | reg = ISP_QUE_REG(ha, que_id); |
| 795 | rsp->rsp_q_in = ®->isp25mq.rsp_q_in; |
| 796 | rsp->rsp_q_out = ®->isp25mq.rsp_q_out; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 797 | mutex_unlock(&ha->vport_lock); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 798 | ql_dbg(ql_dbg_multiq, base_vha, 0xc00b, |
| 799 | "options=%x id=%d rsp_q_in=%p rsp_q_out=%p", |
| 800 | rsp->options, rsp->id, rsp->rsp_q_in, |
| 801 | rsp->rsp_q_out); |
| 802 | ql_dbg(ql_dbg_init, base_vha, 0x00e5, |
| 803 | "options=%x id=%d rsp_q_in=%p rsp_q_out=%p", |
| 804 | rsp->options, rsp->id, rsp->rsp_q_in, |
| 805 | rsp->rsp_q_out); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 806 | |
| 807 | ret = qla25xx_request_irq(rsp); |
| 808 | if (ret) |
| 809 | goto que_failed; |
| 810 | |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 811 | ret = qla25xx_init_rsp_que(base_vha, rsp); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 812 | if (ret != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 813 | ql_log(ql_log_fatal, base_vha, 0x00e7, |
| 814 | "%s failed.\n", __func__); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 815 | mutex_lock(&ha->vport_lock); |
| 816 | clear_bit(que_id, ha->rsp_qid_map); |
| 817 | mutex_unlock(&ha->vport_lock); |
| 818 | goto que_failed; |
| 819 | } |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 820 | if (req >= 0) |
| 821 | rsp->req = ha->req_q_map[req]; |
| 822 | else |
| 823 | rsp->req = NULL; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 824 | |
| 825 | qla2x00_init_response_q_entries(rsp); |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 826 | if (rsp->hw->wq) |
| 827 | INIT_WORK(&rsp->q_work, qla_do_work); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 828 | return rsp->id; |
| 829 | |
| 830 | que_failed: |
| 831 | qla25xx_free_rsp_que(base_vha, rsp); |
Anirban Chakraborty | c7922a9 | 2009-09-28 13:52:58 -0700 | [diff] [blame] | 832 | failed: |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 833 | return 0; |
| 834 | } |