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