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