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