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