blob: 5c2e0317f1c0a31e408f89788536352c19c4c7fa [file] [log] [blame]
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001/*
Andrew Vasquez01e58d82008-04-03 13:13:13 -07002 * QLogic Fibre Channel HBA Driver
Armen Baloyanbd21eaf2014-04-11 16:54:24 -04003 * Copyright (c) 2003-2014 QLogic Corporation
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004 *
Andrew Vasquez01e58d82008-04-03 13:13:13 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006 */
7#include "qla_def.h"
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08008#include "qla_gbl.h"
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04009#include "qla_target.h"
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070010
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070011#include <linux/moduleparam.h>
12#include <linux/vmalloc.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070014#include <linux/list.h>
15
16#include <scsi/scsi_tcq.h>
17#include <scsi/scsicam.h>
18#include <linux/delay.h>
19
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070020void
21qla2x00_vp_stop_timer(scsi_qla_host_t *vha)
22{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080023 if (vha->vp_idx && vha->timer_active) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070024 del_timer_sync(&vha->timer);
25 vha->timer_active = 0;
26 }
27}
28
Adrian Bunka824ebb2008-01-17 09:02:15 -080029static uint32_t
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070030qla24xx_allocate_vp_id(scsi_qla_host_t *vha)
31{
32 uint32_t vp_id;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080033 struct qla_hw_data *ha = vha->hw;
Arun Easifeafb7b2010-09-03 14:57:00 -070034 unsigned long flags;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070035
36 /* Find an empty slot and assign an vp_id */
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -070037 mutex_lock(&ha->vport_lock);
Andrew Vasquezeb66dc62007-11-12 10:30:58 -080038 vp_id = find_first_zero_bit(ha->vp_idx_map, ha->max_npiv_vports + 1);
39 if (vp_id > ha->max_npiv_vports) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -070040 ql_dbg(ql_dbg_vport, vha, 0xa000,
41 "vp_id %d is bigger than max-supported %d.\n",
42 vp_id, ha->max_npiv_vports);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -070043 mutex_unlock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070044 return vp_id;
45 }
46
Andrew Vasquezeb66dc62007-11-12 10:30:58 -080047 set_bit(vp_id, ha->vp_idx_map);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070048 ha->num_vhosts++;
49 vha->vp_idx = vp_id;
Arun Easifeafb7b2010-09-03 14:57:00 -070050
51 spin_lock_irqsave(&ha->vport_slock, flags);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080052 list_add_tail(&vha->list, &ha->vp_list);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -040053
54 qlt_update_vp_map(vha, SET_VP_IDX);
55
Arun Easifeafb7b2010-09-03 14:57:00 -070056 spin_unlock_irqrestore(&ha->vport_slock, flags);
57
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -070058 mutex_unlock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070059 return vp_id;
60}
61
62void
63qla24xx_deallocate_vp_id(scsi_qla_host_t *vha)
64{
65 uint16_t vp_id;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080066 struct qla_hw_data *ha = vha->hw;
Arun Easifeafb7b2010-09-03 14:57:00 -070067 unsigned long flags = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070068
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -070069 mutex_lock(&ha->vport_lock);
Arun Easifeafb7b2010-09-03 14:57:00 -070070 /*
71 * Wait for all pending activities to finish before removing vport from
72 * the list.
73 * Lock needs to be held for safe removal from the list (it
74 * ensures no active vp_list traversal while the vport is removed
75 * from the queue)
76 */
77 spin_lock_irqsave(&ha->vport_slock, flags);
78 while (atomic_read(&vha->vref_count)) {
79 spin_unlock_irqrestore(&ha->vport_slock, flags);
80
81 msleep(500);
82
83 spin_lock_irqsave(&ha->vport_slock, flags);
84 }
85 list_del(&vha->list);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -040086 qlt_update_vp_map(vha, RESET_VP_IDX);
Arun Easifeafb7b2010-09-03 14:57:00 -070087 spin_unlock_irqrestore(&ha->vport_slock, flags);
88
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070089 vp_id = vha->vp_idx;
90 ha->num_vhosts--;
Andrew Vasquezeb66dc62007-11-12 10:30:58 -080091 clear_bit(vp_id, ha->vp_idx_map);
Arun Easifeafb7b2010-09-03 14:57:00 -070092
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -070093 mutex_unlock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070094}
95
Adrian Bunka824ebb2008-01-17 09:02:15 -080096static scsi_qla_host_t *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080097qla24xx_find_vhost_by_name(struct qla_hw_data *ha, uint8_t *port_name)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070098{
99 scsi_qla_host_t *vha;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -0800100 struct scsi_qla_host *tvha;
Arun Easifeafb7b2010-09-03 14:57:00 -0700101 unsigned long flags;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700102
Arun Easifeafb7b2010-09-03 14:57:00 -0700103 spin_lock_irqsave(&ha->vport_slock, flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700104 /* Locate matching device in database. */
Anirban Chakrabortyee546b62009-03-05 11:07:02 -0800105 list_for_each_entry_safe(vha, tvha, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -0700106 if (!memcmp(port_name, vha->port_name, WWN_SIZE)) {
107 spin_unlock_irqrestore(&ha->vport_slock, flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700108 return vha;
Arun Easifeafb7b2010-09-03 14:57:00 -0700109 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700110 }
Arun Easifeafb7b2010-09-03 14:57:00 -0700111 spin_unlock_irqrestore(&ha->vport_slock, flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700112 return NULL;
113}
114
115/*
116 * qla2x00_mark_vp_devices_dead
117 * Updates fcport state when device goes offline.
118 *
119 * Input:
120 * ha = adapter block pointer.
121 * fcport = port structure pointer.
122 *
123 * Return:
124 * None.
125 *
126 * Context:
127 */
Andrew Vasquez26ff7762007-09-20 14:07:47 -0700128static void
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700129qla2x00_mark_vp_devices_dead(scsi_qla_host_t *vha)
130{
Arun Easifeafb7b2010-09-03 14:57:00 -0700131 /*
132 * !!! NOTE !!!
133 * This function, if called in contexts other than vp create, disable
134 * or delete, please make sure this is synchronized with the
135 * delete thread.
136 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700137 fc_port_t *fcport;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700138
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800139 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700140 ql_dbg(ql_dbg_vport, vha, 0xa001,
141 "Marking port dead, loop_id=0x%04x : %x.\n",
Joe Carnuccioc6d39e22012-05-15 14:34:20 -0400142 fcport->loop_id, fcport->vha->vp_idx);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700143
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700144 qla2x00_mark_device_lost(vha, fcport, 0, 0);
Chad Dupuisec426e12011-03-30 11:46:32 -0700145 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700146 }
147}
148
149int
150qla24xx_disable_vp(scsi_qla_host_t *vha)
151{
Nicholas Bellinger29c08cd2012-10-09 12:12:14 -0700152 unsigned long flags;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700153 int ret;
154
155 ret = qla24xx_control_vp(vha, VCE_COMMAND_DISABLE_VPS_LOGO_ALL);
156 atomic_set(&vha->loop_state, LOOP_DOWN);
157 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
158
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400159 /* Remove port id from vp target map */
Nicholas Bellinger29c08cd2012-10-09 12:12:14 -0700160 spin_lock_irqsave(&vha->hw->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400161 qlt_update_vp_map(vha, RESET_AL_PA);
Nicholas Bellinger29c08cd2012-10-09 12:12:14 -0700162 spin_unlock_irqrestore(&vha->hw->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400163
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700164 qla2x00_mark_vp_devices_dead(vha);
165 atomic_set(&vha->vp_state, VP_FAILED);
166 vha->flags.management_server_logged_in = 0;
167 if (ret == QLA_SUCCESS) {
168 fc_vport_set_state(vha->fc_vport, FC_VPORT_DISABLED);
169 } else {
170 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
171 return -1;
172 }
173 return 0;
174}
175
176int
177qla24xx_enable_vp(scsi_qla_host_t *vha)
178{
179 int ret;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800180 struct qla_hw_data *ha = vha->hw;
181 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700182
183 /* Check if physical ha port is Up */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800184 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
Lalit Chandivade3f3b6f92010-05-28 15:08:24 -0700185 atomic_read(&base_vha->loop_state) == LOOP_DEAD ||
186 !(ha->current_topology & ISP_CFG_F)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700187 vha->vp_err_state = VP_ERR_PORTDWN;
188 fc_vport_set_state(vha->fc_vport, FC_VPORT_LINKDOWN);
189 goto enable_failed;
190 }
191
192 /* Initialize the new vport unless it is a persistent port */
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -0700193 mutex_lock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700194 ret = qla24xx_modify_vp_config(vha);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -0700195 mutex_unlock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700196
197 if (ret != QLA_SUCCESS) {
198 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
199 goto enable_failed;
200 }
201
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700202 ql_dbg(ql_dbg_taskm, vha, 0x801a,
203 "Virtual port with id: %d - Enabled.\n", vha->vp_idx);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700204 return 0;
205
206enable_failed:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700207 ql_dbg(ql_dbg_taskm, vha, 0x801b,
208 "Virtual port with id: %d - Disabled.\n", vha->vp_idx);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700209 return 1;
210}
211
Andrew Vasquez26ff7762007-09-20 14:07:47 -0700212static void
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700213qla24xx_configure_vp(scsi_qla_host_t *vha)
214{
215 struct fc_vport *fc_vport;
216 int ret;
217
218 fc_vport = vha->fc_vport;
219
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700220 ql_dbg(ql_dbg_vport, vha, 0xa002,
221 "%s: change request #3.\n", __func__);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700222 ret = qla2x00_send_change_request(vha, 0x3, vha->vp_idx);
223 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700224 ql_dbg(ql_dbg_vport, vha, 0xa003, "Failed to enable "
225 "receiving of RSCN requests: 0x%x.\n", ret);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700226 return;
227 } else {
228 /* Corresponds to SCR enabled */
229 clear_bit(VP_SCR_NEEDED, &vha->vp_flags);
230 }
231
232 vha->flags.online = 1;
233 if (qla24xx_configure_vhba(vha))
234 return;
235
236 atomic_set(&vha->vp_state, VP_ACTIVE);
237 fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE);
238}
239
240void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800241qla2x00_alert_all_vps(struct rsp_que *rsp, uint16_t *mb)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700242{
Arun Easifeafb7b2010-09-03 14:57:00 -0700243 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800244 struct qla_hw_data *ha = rsp->hw;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800245 int i = 0;
Arun Easifeafb7b2010-09-03 14:57:00 -0700246 unsigned long flags;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700247
Arun Easifeafb7b2010-09-03 14:57:00 -0700248 spin_lock_irqsave(&ha->vport_slock, flags);
249 list_for_each_entry(vha, &ha->vp_list, list) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800250 if (vha->vp_idx) {
Arun Easifeafb7b2010-09-03 14:57:00 -0700251 atomic_inc(&vha->vref_count);
252 spin_unlock_irqrestore(&ha->vport_slock, flags);
253
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700254 switch (mb[0]) {
255 case MBA_LIP_OCCURRED:
256 case MBA_LOOP_UP:
257 case MBA_LOOP_DOWN:
258 case MBA_LIP_RESET:
259 case MBA_POINT_TO_POINT:
260 case MBA_CHG_IN_CONNECTION:
261 case MBA_PORT_UPDATE:
262 case MBA_RSCN_UPDATE:
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700263 ql_dbg(ql_dbg_async, vha, 0x5024,
264 "Async_event for VP[%d], mb=0x%x vha=%p.\n",
265 i, *mb, vha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800266 qla2x00_async_event(vha, rsp, mb);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700267 break;
268 }
Arun Easifeafb7b2010-09-03 14:57:00 -0700269
270 spin_lock_irqsave(&ha->vport_slock, flags);
271 atomic_dec(&vha->vref_count);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700272 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800273 i++;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700274 }
Arun Easifeafb7b2010-09-03 14:57:00 -0700275 spin_unlock_irqrestore(&ha->vport_slock, flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700276}
277
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800278int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700279qla2x00_vp_abort_isp(scsi_qla_host_t *vha)
280{
281 /*
282 * Physical port will do most of the abort and recovery work. We can
283 * just treat it as a loop down
284 */
285 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
286 atomic_set(&vha->loop_state, LOOP_DOWN);
287 qla2x00_mark_all_devices_lost(vha, 0);
288 } else {
289 if (!atomic_read(&vha->loop_down_timer))
290 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
291 }
292
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -0700293 /*
294 * To exclusively reset vport, we need to log it out first. Note: this
295 * control_vp can fail if ISP reset is already issued, this is
296 * expected, as the vp would be already logged out due to ISP reset.
297 */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800298 if (!test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
299 qla24xx_control_vp(vha, VCE_COMMAND_DISABLE_VPS_LOGO_ALL);
300
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700301 ql_dbg(ql_dbg_taskm, vha, 0x801d,
302 "Scheduling enable of Vport %d.\n", vha->vp_idx);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800303 return qla24xx_enable_vp(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700304}
305
Adrian Bunka824ebb2008-01-17 09:02:15 -0800306static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700307qla2x00_do_dpc_vp(scsi_qla_host_t *vha)
308{
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400309 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, vha, 0x4012,
310 "Entering %s vp_flags: 0x%lx.\n", __func__, vha->vp_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700311
Andrew Vasquezac280b62009-08-20 11:06:05 -0700312 qla2x00_do_work(vha);
313
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700314 if (test_and_clear_bit(VP_IDX_ACQUIRED, &vha->vp_flags)) {
315 /* VP acquired. complete port configuration */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700316 ql_dbg(ql_dbg_dpc, vha, 0x4014,
317 "Configure VP scheduled.\n");
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -0700318 qla24xx_configure_vp(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700319 ql_dbg(ql_dbg_dpc, vha, 0x4015,
320 "Configure VP end.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700321 return 0;
322 }
323
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800324 if (test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700325 ql_dbg(ql_dbg_dpc, vha, 0x4016,
326 "FCPort update scheduled.\n");
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800327 qla2x00_update_fcports(vha);
328 clear_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700329 ql_dbg(ql_dbg_dpc, vha, 0x4017,
330 "FCPort update end.\n");
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800331 }
332
333 if ((test_and_clear_bit(RELOGIN_NEEDED, &vha->dpc_flags)) &&
334 !test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) &&
335 atomic_read(&vha->loop_state) != LOOP_DOWN) {
336
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700337 ql_dbg(ql_dbg_dpc, vha, 0x4018,
338 "Relogin needed scheduled.\n");
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800339 qla2x00_relogin(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700340 ql_dbg(ql_dbg_dpc, vha, 0x4019,
341 "Relogin needed end.\n");
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800342 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700343
344 if (test_and_clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) &&
345 (!(test_and_set_bit(RESET_ACTIVE, &vha->dpc_flags)))) {
346 clear_bit(RESET_ACTIVE, &vha->dpc_flags);
347 }
348
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800349 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700350 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags))) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700351 ql_dbg(ql_dbg_dpc, vha, 0x401a,
352 "Loop resync scheduled.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700353 qla2x00_loop_resync(vha);
354 clear_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700355 ql_dbg(ql_dbg_dpc, vha, 0x401b,
356 "Loop resync end.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700357 }
358 }
359
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400360 ql_dbg(ql_dbg_dpc + ql_dbg_verbose, vha, 0x401c,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700361 "Exiting %s.\n", __func__);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700362 return 0;
363}
364
365void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800366qla2x00_do_dpc_all_vps(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700367{
368 int ret;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800369 struct qla_hw_data *ha = vha->hw;
370 scsi_qla_host_t *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -0700371 unsigned long flags = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700372
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800373 if (vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700374 return;
375 if (list_empty(&ha->vp_list))
376 return;
377
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800378 clear_bit(VP_DPC_NEEDED, &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700379
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -0700380 if (!(ha->current_topology & ISP_CFG_F))
381 return;
382
Arun Easifeafb7b2010-09-03 14:57:00 -0700383 spin_lock_irqsave(&ha->vport_slock, flags);
384 list_for_each_entry(vp, &ha->vp_list, list) {
385 if (vp->vp_idx) {
386 atomic_inc(&vp->vref_count);
387 spin_unlock_irqrestore(&ha->vport_slock, flags);
388
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800389 ret = qla2x00_do_dpc_vp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -0700390
391 spin_lock_irqsave(&ha->vport_slock, flags);
392 atomic_dec(&vp->vref_count);
393 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700394 }
Arun Easifeafb7b2010-09-03 14:57:00 -0700395 spin_unlock_irqrestore(&ha->vport_slock, flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700396}
397
398int
399qla24xx_vport_create_req_sanity_check(struct fc_vport *fc_vport)
400{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800401 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
402 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700403 scsi_qla_host_t *vha;
404 uint8_t port_name[WWN_SIZE];
405
406 if (fc_vport->roles != FC_PORT_ROLE_FCP_INITIATOR)
407 return VPCERR_UNSUPPORTED;
408
409 /* Check up the F/W and H/W support NPIV */
410 if (!ha->flags.npiv_supported)
411 return VPCERR_UNSUPPORTED;
412
413 /* Check up whether npiv supported switch presented */
414 if (!(ha->switch_cap & FLOGI_MID_SUPPORT))
415 return VPCERR_NO_FABRIC_SUPP;
416
417 /* Check up unique WWPN */
418 u64_to_wwn(fc_vport->port_name, port_name);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800419 if (!memcmp(port_name, base_vha->port_name, WWN_SIZE))
Seokmann Ju50db6b12008-01-17 09:02:14 -0800420 return VPCERR_BAD_WWN;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700421 vha = qla24xx_find_vhost_by_name(ha, port_name);
422 if (vha)
423 return VPCERR_BAD_WWN;
424
425 /* Check up max-npiv-supports */
426 if (ha->num_vhosts > ha->max_npiv_vports) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700427 ql_dbg(ql_dbg_vport, vha, 0xa004,
428 "num_vhosts %ud is bigger "
429 "than max_npiv_vports %ud.\n",
430 ha->num_vhosts, ha->max_npiv_vports);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700431 return VPCERR_UNSUPPORTED;
432 }
433 return 0;
434}
435
436scsi_qla_host_t *
437qla24xx_create_vhost(struct fc_vport *fc_vport)
438{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800439 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
440 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700441 scsi_qla_host_t *vha;
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700442 struct scsi_host_template *sht = &qla2xxx_driver_template;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700443 struct Scsi_Host *host;
444
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800445 vha = qla2x00_create_host(sht, ha);
446 if (!vha) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700447 ql_log(ql_log_warn, vha, 0xa005,
448 "scsi_host_alloc() failed for vport.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700449 return(NULL);
450 }
451
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800452 host = vha->host;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700453 fc_vport->dd_data = vha;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700454 /* New host info */
455 u64_to_wwn(fc_vport->node_name, vha->node_name);
456 u64_to_wwn(fc_vport->port_name, vha->port_name);
457
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700458 vha->fc_vport = fc_vport;
459 vha->device_flags = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700460 vha->vp_idx = qla24xx_allocate_vp_id(vha);
461 if (vha->vp_idx > ha->max_npiv_vports) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700462 ql_dbg(ql_dbg_vport, vha, 0xa006,
463 "Couldn't allocate vp_id.\n");
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800464 goto create_vhost_failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700465 }
466 vha->mgmt_svr_loop_id = 10 + vha->vp_idx;
467
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700468 vha->dpc_flags = 0L;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700469
470 /*
471 * To fix the issue of processing a parent's RSCN for the vport before
472 * its SCR is complete.
473 */
474 set_bit(VP_SCR_NEEDED, &vha->vp_flags);
475 atomic_set(&vha->loop_state, LOOP_DOWN);
476 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
477
478 qla2x00_start_timer(vha, qla2x00_timer, WATCH_INTERVAL);
479
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700480 vha->req = base_vha->req;
481 host->can_queue = base_vha->req->length + 128;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700482 host->cmd_per_lun = 3;
Arun Easie02587d2011-08-16 11:29:23 -0700483 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
Arun Easi0c470872010-07-23 15:28:38 +0500484 host->max_cmd_len = 32;
485 else
486 host->max_cmd_len = MAX_CMDSZ;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700487 host->max_channel = MAX_BUSES - 1;
Andrew Vasquez82515922011-05-10 11:30:13 -0700488 host->max_lun = ql2xmaxlun;
Seokmann Ju711c1d92008-07-10 16:55:51 -0700489 host->unique_id = host->host_no;
Chad Dupuis642ef982012-02-09 11:15:57 -0800490 host->max_id = ha->max_fibre_devices;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700491 host->transportt = qla2xxx_transport_vport_template;
492
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700493 ql_dbg(ql_dbg_vport, vha, 0xa007,
494 "Detect vport hba %ld at address = %p.\n",
495 vha->host_no, vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700496
497 vha->flags.init_done = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700498
Andrew Vasquez0d6e61b2009-08-25 11:36:19 -0700499 mutex_lock(&ha->vport_lock);
500 set_bit(vha->vp_idx, ha->vp_idx_map);
501 ha->cur_vport_count++;
502 mutex_unlock(&ha->vport_lock);
503
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700504 return vha;
505
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800506create_vhost_failed:
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700507 return NULL;
508}
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800509
510static void
511qla25xx_free_req_que(struct scsi_qla_host *vha, struct req_que *req)
512{
513 struct qla_hw_data *ha = vha->hw;
514 uint16_t que_id = req->id;
515
516 dma_free_coherent(&ha->pdev->dev, (req->length + 1) *
517 sizeof(request_t), req->ring, req->dma);
518 req->ring = NULL;
519 req->dma = 0;
520 if (que_id) {
521 ha->req_q_map[que_id] = NULL;
522 mutex_lock(&ha->vport_lock);
523 clear_bit(que_id, ha->req_qid_map);
524 mutex_unlock(&ha->vport_lock);
525 }
Chad Dupuis8d93f552013-01-30 03:34:37 -0500526 kfree(req->outstanding_cmds);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800527 kfree(req);
528 req = NULL;
529}
530
531static void
532qla25xx_free_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
533{
534 struct qla_hw_data *ha = vha->hw;
535 uint16_t que_id = rsp->id;
536
537 if (rsp->msix && rsp->msix->have_irq) {
538 free_irq(rsp->msix->vector, rsp);
539 rsp->msix->have_irq = 0;
540 rsp->msix->rsp = NULL;
541 }
542 dma_free_coherent(&ha->pdev->dev, (rsp->length + 1) *
543 sizeof(response_t), rsp->ring, rsp->dma);
544 rsp->ring = NULL;
545 rsp->dma = 0;
546 if (que_id) {
547 ha->rsp_q_map[que_id] = NULL;
548 mutex_lock(&ha->vport_lock);
549 clear_bit(que_id, ha->rsp_qid_map);
550 mutex_unlock(&ha->vport_lock);
551 }
552 kfree(rsp);
553 rsp = NULL;
554}
555
556int
557qla25xx_delete_req_que(struct scsi_qla_host *vha, struct req_que *req)
558{
559 int ret = -1;
560
561 if (req) {
562 req->options |= BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -0800563 ret = qla25xx_init_req_que(vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800564 }
565 if (ret == QLA_SUCCESS)
566 qla25xx_free_req_que(vha, req);
567
568 return ret;
569}
570
Andrew Vasquez3dbe7562010-07-23 15:28:37 +0500571static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800572qla25xx_delete_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
573{
574 int ret = -1;
575
576 if (rsp) {
577 rsp->options |= BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -0800578 ret = qla25xx_init_rsp_que(vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800579 }
580 if (ret == QLA_SUCCESS)
581 qla25xx_free_rsp_que(vha, rsp);
582
583 return ret;
584}
585
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800586/* Delete all queues for a given vhost */
587int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700588qla25xx_delete_queues(struct scsi_qla_host *vha)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800589{
590 int cnt, ret = 0;
591 struct req_que *req = NULL;
592 struct rsp_que *rsp = NULL;
593 struct qla_hw_data *ha = vha->hw;
594
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700595 /* Delete request queues */
596 for (cnt = 1; cnt < ha->max_req_queues; cnt++) {
597 req = ha->req_q_map[cnt];
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800598 if (req) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800599 ret = qla25xx_delete_req_que(vha, req);
600 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700601 ql_log(ql_log_warn, vha, 0x00ea,
602 "Couldn't delete req que %d.\n",
603 req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800604 return ret;
605 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800606 }
607 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700608
609 /* Delete response queues */
610 for (cnt = 1; cnt < ha->max_rsp_queues; cnt++) {
611 rsp = ha->rsp_q_map[cnt];
612 if (rsp) {
613 ret = qla25xx_delete_rsp_que(vha, rsp);
614 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700615 ql_log(ql_log_warn, vha, 0x00eb,
616 "Couldn't delete rsp que %d.\n",
617 rsp->id);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700618 return ret;
619 }
620 }
621 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800622 return ret;
623}
624
625int
626qla25xx_create_req_que(struct qla_hw_data *ha, uint16_t options,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700627 uint8_t vp_idx, uint16_t rid, int rsp_que, uint8_t qos)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800628{
629 int ret = 0;
630 struct req_que *req = NULL;
631 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
632 uint16_t que_id = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500633 device_reg_t *reg;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700634 uint32_t cnt;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800635
636 req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
637 if (req == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700638 ql_log(ql_log_fatal, base_vha, 0x00d9,
639 "Failed to allocate memory for request queue.\n");
Anirban Chakrabortyc7922a92009-09-28 13:52:58 -0700640 goto failed;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800641 }
642
643 req->length = REQUEST_ENTRY_CNT_24XX;
644 req->ring = dma_alloc_coherent(&ha->pdev->dev,
645 (req->length + 1) * sizeof(request_t),
646 &req->dma, GFP_KERNEL);
647 if (req->ring == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700648 ql_log(ql_log_fatal, base_vha, 0x00da,
Masanari Iidad6a03582012-08-22 14:20:58 -0400649 "Failed to allocate memory for request_ring.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800650 goto que_failed;
651 }
652
Chad Dupuis8d93f552013-01-30 03:34:37 -0500653 ret = qla2x00_alloc_outstanding_cmds(ha, req);
654 if (ret != QLA_SUCCESS)
655 goto que_failed;
656
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800657 mutex_lock(&ha->vport_lock);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700658 que_id = find_first_zero_bit(ha->req_qid_map, ha->max_req_queues);
659 if (que_id >= ha->max_req_queues) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800660 mutex_unlock(&ha->vport_lock);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700661 ql_log(ql_log_warn, base_vha, 0x00db,
662 "No resources to create additional request queue.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800663 goto que_failed;
664 }
665 set_bit(que_id, ha->req_qid_map);
666 ha->req_q_map[que_id] = req;
667 req->rid = rid;
668 req->vp_idx = vp_idx;
669 req->qos = qos;
670
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700671 ql_dbg(ql_dbg_multiq, base_vha, 0xc002,
672 "queue_id=%d rid=%d vp_idx=%d qos=%d.\n",
673 que_id, req->rid, req->vp_idx, req->qos);
674 ql_dbg(ql_dbg_init, base_vha, 0x00dc,
675 "queue_id=%d rid=%d vp_idx=%d qos=%d.\n",
676 que_id, req->rid, req->vp_idx, req->qos);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700677 if (rsp_que < 0)
678 req->rsp = NULL;
679 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800680 req->rsp = ha->rsp_q_map[rsp_que];
681 /* Use alternate PCI bus number */
682 if (MSB(req->rid))
683 options |= BIT_4;
684 /* Use alternate PCI devfn */
685 if (LSB(req->rid))
686 options |= BIT_5;
687 req->options = options;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700688
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700689 ql_dbg(ql_dbg_multiq, base_vha, 0xc003,
690 "options=0x%x.\n", req->options);
691 ql_dbg(ql_dbg_init, base_vha, 0x00dd,
692 "options=0x%x.\n", req->options);
Chad Dupuis8d93f552013-01-30 03:34:37 -0500693 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700694 req->outstanding_cmds[cnt] = NULL;
695 req->current_outstanding_cmd = 1;
696
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800697 req->ring_ptr = req->ring;
698 req->ring_index = 0;
699 req->cnt = req->length;
700 req->id = que_id;
Andrew Vasquez08029992009-03-24 09:07:55 -0700701 reg = ISP_QUE_REG(ha, que_id);
Andrew Vasquezda9b1d52013-08-27 01:37:30 -0400702 req->req_q_in = &reg->isp25mq.req_q_in;
703 req->req_q_out = &reg->isp25mq.req_q_out;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -0800704 req->max_q_depth = ha->req_q_map[0]->max_q_depth;
Joe Carnuccio40969532014-09-25 05:16:39 -0400705 req->out_ptr = (void *)(req->ring + req->length);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800706 mutex_unlock(&ha->vport_lock);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700707 ql_dbg(ql_dbg_multiq, base_vha, 0xc004,
708 "ring_ptr=%p ring_index=%d, "
709 "cnt=%d id=%d max_q_depth=%d.\n",
710 req->ring_ptr, req->ring_index,
711 req->cnt, req->id, req->max_q_depth);
712 ql_dbg(ql_dbg_init, base_vha, 0x00de,
713 "ring_ptr=%p ring_index=%d, "
714 "cnt=%d id=%d max_q_depth=%d.\n",
715 req->ring_ptr, req->ring_index, req->cnt,
716 req->id, req->max_q_depth);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800717
Anirban Chakraborty618a7522009-02-08 20:50:11 -0800718 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800719 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700720 ql_log(ql_log_fatal, base_vha, 0x00df,
721 "%s failed.\n", __func__);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800722 mutex_lock(&ha->vport_lock);
723 clear_bit(que_id, ha->req_qid_map);
724 mutex_unlock(&ha->vport_lock);
725 goto que_failed;
726 }
727
728 return req->id;
729
730que_failed:
731 qla25xx_free_req_que(base_vha, req);
Anirban Chakrabortyc7922a92009-09-28 13:52:58 -0700732failed:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800733 return 0;
734}
735
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700736static void qla_do_work(struct work_struct *work)
737{
Anirban Chakrabortya67093d2010-02-04 14:17:59 -0800738 unsigned long flags;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700739 struct rsp_que *rsp = container_of(work, struct rsp_que, q_work);
740 struct scsi_qla_host *vha;
Anirban Chakrabortya67093d2010-02-04 14:17:59 -0800741 struct qla_hw_data *ha = rsp->hw;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700742
Anirban Chakrabortya67093d2010-02-04 14:17:59 -0800743 spin_lock_irqsave(&rsp->hw->hardware_lock, flags);
744 vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700745 qla24xx_process_response_queue(vha, rsp);
Anirban Chakrabortya67093d2010-02-04 14:17:59 -0800746 spin_unlock_irqrestore(&rsp->hw->hardware_lock, flags);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700747}
748
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800749/* create response queue */
750int
751qla25xx_create_rsp_que(struct qla_hw_data *ha, uint16_t options,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700752 uint8_t vp_idx, uint16_t rid, int req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800753{
754 int ret = 0;
755 struct rsp_que *rsp = NULL;
756 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez08029992009-03-24 09:07:55 -0700757 uint16_t que_id = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500758 device_reg_t *reg;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800759
760 rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
761 if (rsp == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700762 ql_log(ql_log_warn, base_vha, 0x0066,
763 "Failed to allocate memory for response queue.\n");
Anirban Chakrabortyc7922a92009-09-28 13:52:58 -0700764 goto failed;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800765 }
766
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700767 rsp->length = RESPONSE_ENTRY_CNT_MQ;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800768 rsp->ring = dma_alloc_coherent(&ha->pdev->dev,
769 (rsp->length + 1) * sizeof(response_t),
770 &rsp->dma, GFP_KERNEL);
771 if (rsp->ring == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700772 ql_log(ql_log_warn, base_vha, 0x00e1,
773 "Failed to allocate memory for response ring.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800774 goto que_failed;
775 }
776
777 mutex_lock(&ha->vport_lock);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700778 que_id = find_first_zero_bit(ha->rsp_qid_map, ha->max_rsp_queues);
779 if (que_id >= ha->max_rsp_queues) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800780 mutex_unlock(&ha->vport_lock);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700781 ql_log(ql_log_warn, base_vha, 0x00e2,
782 "No resources to create additional request queue.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800783 goto que_failed;
784 }
785 set_bit(que_id, ha->rsp_qid_map);
786
787 if (ha->flags.msix_enabled)
788 rsp->msix = &ha->msix_entries[que_id + 1];
789 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700790 ql_log(ql_log_warn, base_vha, 0x00e3,
791 "MSIX not enalbled.\n");
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800792
793 ha->rsp_q_map[que_id] = rsp;
794 rsp->rid = rid;
795 rsp->vp_idx = vp_idx;
796 rsp->hw = ha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700797 ql_dbg(ql_dbg_init, base_vha, 0x00e4,
798 "queue_id=%d rid=%d vp_idx=%d hw=%p.\n",
799 que_id, rsp->rid, rsp->vp_idx, rsp->hw);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800800 /* Use alternate PCI bus number */
801 if (MSB(rsp->rid))
802 options |= BIT_4;
803 /* Use alternate PCI devfn */
804 if (LSB(rsp->rid))
805 options |= BIT_5;
Anirban Chakraborty31557542009-12-02 10:36:55 -0800806 /* Enable MSIX handshake mode on for uncapable adapters */
807 if (!IS_MSIX_NACK_CAPABLE(ha))
808 options |= BIT_6;
809
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800810 rsp->options = options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800811 rsp->id = que_id;
Andrew Vasquez08029992009-03-24 09:07:55 -0700812 reg = ISP_QUE_REG(ha, que_id);
813 rsp->rsp_q_in = &reg->isp25mq.rsp_q_in;
814 rsp->rsp_q_out = &reg->isp25mq.rsp_q_out;
Joe Carnuccio40969532014-09-25 05:16:39 -0400815 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800816 mutex_unlock(&ha->vport_lock);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700817 ql_dbg(ql_dbg_multiq, base_vha, 0xc00b,
818 "options=%x id=%d rsp_q_in=%p rsp_q_out=%p",
819 rsp->options, rsp->id, rsp->rsp_q_in,
820 rsp->rsp_q_out);
821 ql_dbg(ql_dbg_init, base_vha, 0x00e5,
822 "options=%x id=%d rsp_q_in=%p rsp_q_out=%p",
823 rsp->options, rsp->id, rsp->rsp_q_in,
824 rsp->rsp_q_out);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800825
826 ret = qla25xx_request_irq(rsp);
827 if (ret)
828 goto que_failed;
829
Anirban Chakraborty618a7522009-02-08 20:50:11 -0800830 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800831 if (ret != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700832 ql_log(ql_log_fatal, base_vha, 0x00e7,
833 "%s failed.\n", __func__);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800834 mutex_lock(&ha->vport_lock);
835 clear_bit(que_id, ha->rsp_qid_map);
836 mutex_unlock(&ha->vport_lock);
837 goto que_failed;
838 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700839 if (req >= 0)
840 rsp->req = ha->req_q_map[req];
841 else
842 rsp->req = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800843
844 qla2x00_init_response_q_entries(rsp);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700845 if (rsp->hw->wq)
846 INIT_WORK(&rsp->q_work, qla_do_work);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800847 return rsp->id;
848
849que_failed:
850 qla25xx_free_rsp_que(base_vha, rsp);
Anirban Chakrabortyc7922a92009-09-28 13:52:58 -0700851failed:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800852 return 0;
853}