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