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