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