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