]>
Commit | Line | Data |
---|---|---|
77adf3f0 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
2c3dfe3f | 2 | /* |
01e58d8e | 3 | * QLogic Fibre Channel HBA Driver |
bd21eaf9 | 4 | * Copyright (c) 2003-2014 QLogic Corporation |
2c3dfe3f SJ |
5 | */ |
6 | #include "qla_def.h" | |
7b867cf7 | 7 | #include "qla_gbl.h" |
2d70c103 | 8 | #include "qla_target.h" |
2c3dfe3f | 9 | |
2c3dfe3f SJ |
10 | #include <linux/moduleparam.h> |
11 | #include <linux/vmalloc.h> | |
5a0e3ad6 | 12 | #include <linux/slab.h> |
2c3dfe3f SJ |
13 | #include <linux/list.h> |
14 | ||
15 | #include <scsi/scsi_tcq.h> | |
16 | #include <scsi/scsicam.h> | |
17 | #include <linux/delay.h> | |
18 | ||
2c3dfe3f SJ |
19 | void |
20 | qla2x00_vp_stop_timer(scsi_qla_host_t *vha) | |
21 | { | |
7b867cf7 | 22 | if (vha->vp_idx && vha->timer_active) { |
2c3dfe3f SJ |
23 | del_timer_sync(&vha->timer); |
24 | vha->timer_active = 0; | |
25 | } | |
26 | } | |
27 | ||
a824ebb3 | 28 | static uint32_t |
2c3dfe3f SJ |
29 | qla24xx_allocate_vp_id(scsi_qla_host_t *vha) |
30 | { | |
31 | uint32_t vp_id; | |
7b867cf7 | 32 | struct qla_hw_data *ha = vha->hw; |
feafb7b1 | 33 | unsigned long flags; |
2c3dfe3f SJ |
34 | |
35 | /* Find an empty slot and assign an vp_id */ | |
6c2f527c | 36 | mutex_lock(&ha->vport_lock); |
eb66dc60 AV |
37 | vp_id = find_first_zero_bit(ha->vp_idx_map, ha->max_npiv_vports + 1); |
38 | if (vp_id > ha->max_npiv_vports) { | |
7c3df132 SK |
39 | ql_dbg(ql_dbg_vport, vha, 0xa000, |
40 | "vp_id %d is bigger than max-supported %d.\n", | |
41 | vp_id, ha->max_npiv_vports); | |
6c2f527c | 42 | mutex_unlock(&ha->vport_lock); |
2c3dfe3f SJ |
43 | return vp_id; |
44 | } | |
45 | ||
eb66dc60 | 46 | set_bit(vp_id, ha->vp_idx_map); |
2c3dfe3f SJ |
47 | ha->num_vhosts++; |
48 | vha->vp_idx = vp_id; | |
feafb7b1 AE |
49 | |
50 | spin_lock_irqsave(&ha->vport_slock, flags); | |
7b867cf7 | 51 | list_add_tail(&vha->list, &ha->vp_list); |
9d1aa4e1 | 52 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
2d70c103 | 53 | |
9d1aa4e1 | 54 | spin_lock_irqsave(&ha->hardware_lock, flags); |
2d70c103 | 55 | qlt_update_vp_map(vha, SET_VP_IDX); |
9d1aa4e1 | 56 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
feafb7b1 | 57 | |
6c2f527c | 58 | mutex_unlock(&ha->vport_lock); |
2c3dfe3f SJ |
59 | return vp_id; |
60 | } | |
61 | ||
62 | void | |
63 | qla24xx_deallocate_vp_id(scsi_qla_host_t *vha) | |
64 | { | |
65 | uint16_t vp_id; | |
7b867cf7 | 66 | struct qla_hw_data *ha = vha->hw; |
feafb7b1 | 67 | unsigned long flags = 0; |
0c9a5f3e | 68 | u32 i, bailout; |
2c3dfe3f | 69 | |
6c2f527c | 70 | mutex_lock(&ha->vport_lock); |
feafb7b1 AE |
71 | /* |
72 | * Wait for all pending activities to finish before removing vport from | |
73 | * the list. | |
74 | * Lock needs to be held for safe removal from the list (it | |
75 | * ensures no active vp_list traversal while the vport is removed | |
76 | * from the queue) | |
77 | */ | |
0c9a5f3e QT |
78 | bailout = 0; |
79 | for (i = 0; i < 500; i++) { | |
80 | spin_lock_irqsave(&ha->vport_slock, flags); | |
81 | if (atomic_read(&vha->vref_count) == 0) { | |
82 | list_del(&vha->list); | |
83 | qlt_update_vp_map(vha, RESET_VP_IDX); | |
84 | bailout = 1; | |
85 | } | |
86 | spin_unlock_irqrestore(&ha->vport_slock, flags); | |
87 | ||
88 | if (bailout) | |
8b1062d5 | 89 | break; |
0c9a5f3e QT |
90 | else |
91 | msleep(20); | |
8b1062d5 | 92 | } |
0c9a5f3e QT |
93 | if (!bailout) { |
94 | ql_log(ql_log_info, vha, 0xfffa, | |
95 | "vha->vref_count=%u timeout\n", vha->vref_count.counter); | |
96 | spin_lock_irqsave(&ha->vport_slock, flags); | |
97 | list_del(&vha->list); | |
98 | qlt_update_vp_map(vha, RESET_VP_IDX); | |
99 | spin_unlock_irqrestore(&ha->vport_slock, flags); | |
feafb7b1 | 100 | } |
feafb7b1 | 101 | |
2c3dfe3f SJ |
102 | vp_id = vha->vp_idx; |
103 | ha->num_vhosts--; | |
eb66dc60 | 104 | clear_bit(vp_id, ha->vp_idx_map); |
feafb7b1 | 105 | |
6c2f527c | 106 | mutex_unlock(&ha->vport_lock); |
2c3dfe3f SJ |
107 | } |
108 | ||
a824ebb3 | 109 | static scsi_qla_host_t * |
7b867cf7 | 110 | qla24xx_find_vhost_by_name(struct qla_hw_data *ha, uint8_t *port_name) |
2c3dfe3f SJ |
111 | { |
112 | scsi_qla_host_t *vha; | |
ee546b6e | 113 | struct scsi_qla_host *tvha; |
feafb7b1 | 114 | unsigned long flags; |
2c3dfe3f | 115 | |
feafb7b1 | 116 | spin_lock_irqsave(&ha->vport_slock, flags); |
2c3dfe3f | 117 | /* Locate matching device in database. */ |
ee546b6e | 118 | list_for_each_entry_safe(vha, tvha, &ha->vp_list, list) { |
feafb7b1 AE |
119 | if (!memcmp(port_name, vha->port_name, WWN_SIZE)) { |
120 | spin_unlock_irqrestore(&ha->vport_slock, flags); | |
2c3dfe3f | 121 | return vha; |
feafb7b1 | 122 | } |
2c3dfe3f | 123 | } |
feafb7b1 | 124 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
2c3dfe3f SJ |
125 | return NULL; |
126 | } | |
127 | ||
128 | /* | |
129 | * qla2x00_mark_vp_devices_dead | |
130 | * Updates fcport state when device goes offline. | |
131 | * | |
132 | * Input: | |
133 | * ha = adapter block pointer. | |
134 | * fcport = port structure pointer. | |
135 | * | |
136 | * Return: | |
137 | * None. | |
138 | * | |
139 | * Context: | |
140 | */ | |
26ff776d | 141 | static void |
2c3dfe3f SJ |
142 | qla2x00_mark_vp_devices_dead(scsi_qla_host_t *vha) |
143 | { | |
feafb7b1 AE |
144 | /* |
145 | * !!! NOTE !!! | |
146 | * This function, if called in contexts other than vp create, disable | |
147 | * or delete, please make sure this is synchronized with the | |
148 | * delete thread. | |
149 | */ | |
2c3dfe3f | 150 | fc_port_t *fcport; |
2c3dfe3f | 151 | |
7b867cf7 | 152 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
7c3df132 SK |
153 | ql_dbg(ql_dbg_vport, vha, 0xa001, |
154 | "Marking port dead, loop_id=0x%04x : %x.\n", | |
c6d39e23 | 155 | fcport->loop_id, fcport->vha->vp_idx); |
2c3dfe3f | 156 | |
3c75ad1d | 157 | qla2x00_mark_device_lost(vha, fcport, 0); |
ec426e10 | 158 | qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED); |
2c3dfe3f SJ |
159 | } |
160 | } | |
161 | ||
162 | int | |
163 | qla24xx_disable_vp(scsi_qla_host_t *vha) | |
164 | { | |
29c08cda | 165 | unsigned long flags; |
45235022 | 166 | int ret = QLA_SUCCESS; |
efa93f48 | 167 | fc_port_t *fcport; |
2c3dfe3f | 168 | |
9efea843 QT |
169 | if (vha->hw->flags.edif_enabled) |
170 | /* delete sessions and flush sa_indexes */ | |
171 | qla2x00_wait_for_sess_deletion(vha); | |
172 | ||
45235022 QT |
173 | if (vha->hw->flags.fw_started) |
174 | ret = qla24xx_control_vp(vha, VCE_COMMAND_DISABLE_VPS_LOGO_ALL); | |
175 | ||
2c3dfe3f SJ |
176 | atomic_set(&vha->loop_state, LOOP_DOWN); |
177 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); | |
efa93f48 QT |
178 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
179 | fcport->logout_on_delete = 0; | |
180 | ||
9efea843 QT |
181 | if (!vha->hw->flags.edif_enabled) |
182 | qla2x00_wait_for_sess_deletion(vha); | |
2c3dfe3f | 183 | |
2d70c103 | 184 | /* Remove port id from vp target map */ |
9d1aa4e1 | 185 | spin_lock_irqsave(&vha->hw->hardware_lock, flags); |
2d70c103 | 186 | qlt_update_vp_map(vha, RESET_AL_PA); |
9d1aa4e1 | 187 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); |
2d70c103 | 188 | |
2c3dfe3f SJ |
189 | qla2x00_mark_vp_devices_dead(vha); |
190 | atomic_set(&vha->vp_state, VP_FAILED); | |
191 | vha->flags.management_server_logged_in = 0; | |
192 | if (ret == QLA_SUCCESS) { | |
193 | fc_vport_set_state(vha->fc_vport, FC_VPORT_DISABLED); | |
194 | } else { | |
195 | fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED); | |
196 | return -1; | |
197 | } | |
198 | return 0; | |
199 | } | |
200 | ||
201 | int | |
202 | qla24xx_enable_vp(scsi_qla_host_t *vha) | |
203 | { | |
204 | int ret; | |
7b867cf7 AC |
205 | struct qla_hw_data *ha = vha->hw; |
206 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); | |
2c3dfe3f SJ |
207 | |
208 | /* Check if physical ha port is Up */ | |
7b867cf7 | 209 | if (atomic_read(&base_vha->loop_state) == LOOP_DOWN || |
3f3b6f98 LC |
210 | atomic_read(&base_vha->loop_state) == LOOP_DEAD || |
211 | !(ha->current_topology & ISP_CFG_F)) { | |
2c3dfe3f SJ |
212 | vha->vp_err_state = VP_ERR_PORTDWN; |
213 | fc_vport_set_state(vha->fc_vport, FC_VPORT_LINKDOWN); | |
1608cc4a QT |
214 | ql_dbg(ql_dbg_taskm, vha, 0x800b, |
215 | "%s skip enable. loop_state %x topo %x\n", | |
216 | __func__, base_vha->loop_state.counter, | |
217 | ha->current_topology); | |
218 | ||
2c3dfe3f SJ |
219 | goto enable_failed; |
220 | } | |
221 | ||
222 | /* Initialize the new vport unless it is a persistent port */ | |
6c2f527c | 223 | mutex_lock(&ha->vport_lock); |
2c3dfe3f | 224 | ret = qla24xx_modify_vp_config(vha); |
6c2f527c | 225 | mutex_unlock(&ha->vport_lock); |
2c3dfe3f SJ |
226 | |
227 | if (ret != QLA_SUCCESS) { | |
228 | fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED); | |
229 | goto enable_failed; | |
230 | } | |
231 | ||
7c3df132 SK |
232 | ql_dbg(ql_dbg_taskm, vha, 0x801a, |
233 | "Virtual port with id: %d - Enabled.\n", vha->vp_idx); | |
2c3dfe3f SJ |
234 | return 0; |
235 | ||
236 | enable_failed: | |
7c3df132 SK |
237 | ql_dbg(ql_dbg_taskm, vha, 0x801b, |
238 | "Virtual port with id: %d - Disabled.\n", vha->vp_idx); | |
2c3dfe3f SJ |
239 | return 1; |
240 | } | |
241 | ||
26ff776d | 242 | static void |
2c3dfe3f SJ |
243 | qla24xx_configure_vp(scsi_qla_host_t *vha) |
244 | { | |
245 | struct fc_vport *fc_vport; | |
246 | int ret; | |
247 | ||
248 | fc_vport = vha->fc_vport; | |
249 | ||
7c3df132 SK |
250 | ql_dbg(ql_dbg_vport, vha, 0xa002, |
251 | "%s: change request #3.\n", __func__); | |
2c3dfe3f SJ |
252 | ret = qla2x00_send_change_request(vha, 0x3, vha->vp_idx); |
253 | if (ret != QLA_SUCCESS) { | |
7c3df132 SK |
254 | ql_dbg(ql_dbg_vport, vha, 0xa003, "Failed to enable " |
255 | "receiving of RSCN requests: 0x%x.\n", ret); | |
2c3dfe3f SJ |
256 | return; |
257 | } else { | |
258 | /* Corresponds to SCR enabled */ | |
259 | clear_bit(VP_SCR_NEEDED, &vha->vp_flags); | |
260 | } | |
261 | ||
262 | vha->flags.online = 1; | |
263 | if (qla24xx_configure_vhba(vha)) | |
264 | return; | |
265 | ||
266 | atomic_set(&vha->vp_state, VP_ACTIVE); | |
267 | fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE); | |
268 | } | |
269 | ||
270 | void | |
73208dfd | 271 | qla2x00_alert_all_vps(struct rsp_que *rsp, uint16_t *mb) |
2c3dfe3f | 272 | { |
0c9a5f3e | 273 | scsi_qla_host_t *vha, *tvp; |
73208dfd | 274 | struct qla_hw_data *ha = rsp->hw; |
7b867cf7 | 275 | int i = 0; |
feafb7b1 | 276 | unsigned long flags; |
2c3dfe3f | 277 | |
feafb7b1 | 278 | spin_lock_irqsave(&ha->vport_slock, flags); |
0c9a5f3e | 279 | list_for_each_entry_safe(vha, tvp, &ha->vp_list, list) { |
7b867cf7 | 280 | if (vha->vp_idx) { |
f5187b7d QT |
281 | if (test_bit(VPORT_DELETE, &vha->dpc_flags)) |
282 | continue; | |
283 | ||
feafb7b1 AE |
284 | atomic_inc(&vha->vref_count); |
285 | spin_unlock_irqrestore(&ha->vport_slock, flags); | |
286 | ||
2c3dfe3f SJ |
287 | switch (mb[0]) { |
288 | case MBA_LIP_OCCURRED: | |
289 | case MBA_LOOP_UP: | |
290 | case MBA_LOOP_DOWN: | |
291 | case MBA_LIP_RESET: | |
292 | case MBA_POINT_TO_POINT: | |
293 | case MBA_CHG_IN_CONNECTION: | |
7c3df132 SK |
294 | ql_dbg(ql_dbg_async, vha, 0x5024, |
295 | "Async_event for VP[%d], mb=0x%x vha=%p.\n", | |
296 | i, *mb, vha); | |
73208dfd | 297 | qla2x00_async_event(vha, rsp, mb); |
2c3dfe3f | 298 | break; |
75061750 QT |
299 | case MBA_PORT_UPDATE: |
300 | case MBA_RSCN_UPDATE: | |
301 | if ((mb[3] & 0xff) == vha->vp_idx) { | |
302 | ql_dbg(ql_dbg_async, vha, 0x5024, | |
303 | "Async_event for VP[%d], mb=0x%x vha=%p\n", | |
304 | i, *mb, vha); | |
305 | qla2x00_async_event(vha, rsp, mb); | |
306 | } | |
307 | break; | |
2c3dfe3f | 308 | } |
feafb7b1 AE |
309 | |
310 | spin_lock_irqsave(&ha->vport_slock, flags); | |
311 | atomic_dec(&vha->vref_count); | |
c4a9b538 | 312 | wake_up(&vha->vref_waitq); |
2c3dfe3f | 313 | } |
7b867cf7 | 314 | i++; |
2c3dfe3f | 315 | } |
feafb7b1 | 316 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
2c3dfe3f SJ |
317 | } |
318 | ||
7b867cf7 | 319 | int |
2c3dfe3f SJ |
320 | qla2x00_vp_abort_isp(scsi_qla_host_t *vha) |
321 | { | |
f5187b7d QT |
322 | fc_port_t *fcport; |
323 | ||
324 | /* | |
325 | * To exclusively reset vport, we need to log it out first. | |
326 | * Note: This control_vp can fail if ISP reset is already | |
327 | * issued, this is expected, as the vp would be already | |
328 | * logged out due to ISP reset. | |
329 | */ | |
330 | if (!test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) { | |
331 | qla24xx_control_vp(vha, VCE_COMMAND_DISABLE_VPS_LOGO_ALL); | |
332 | list_for_each_entry(fcport, &vha->vp_fcports, list) | |
333 | fcport->logout_on_delete = 0; | |
334 | } | |
335 | ||
2c3dfe3f SJ |
336 | /* |
337 | * Physical port will do most of the abort and recovery work. We can | |
338 | * just treat it as a loop down | |
339 | */ | |
340 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { | |
341 | atomic_set(&vha->loop_state, LOOP_DOWN); | |
3c75ad1d | 342 | qla2x00_mark_all_devices_lost(vha); |
2c3dfe3f SJ |
343 | } else { |
344 | if (!atomic_read(&vha->loop_down_timer)) | |
345 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); | |
346 | } | |
347 | ||
7c3df132 SK |
348 | ql_dbg(ql_dbg_taskm, vha, 0x801d, |
349 | "Scheduling enable of Vport %d.\n", vha->vp_idx); | |
f5187b7d | 350 | |
7b867cf7 | 351 | return qla24xx_enable_vp(vha); |
2c3dfe3f SJ |
352 | } |
353 | ||
a824ebb3 | 354 | static int |
2c3dfe3f SJ |
355 | qla2x00_do_dpc_vp(scsi_qla_host_t *vha) |
356 | { | |
ded6411f SC |
357 | struct qla_hw_data *ha = vha->hw; |
358 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); | |
359 | ||
5f28d2d7 SK |
360 | ql_dbg(ql_dbg_dpc + ql_dbg_verbose, vha, 0x4012, |
361 | "Entering %s vp_flags: 0x%lx.\n", __func__, vha->vp_flags); | |
7c3df132 | 362 | |
ded6411f SC |
363 | /* Check if Fw is ready to configure VP first */ |
364 | if (test_bit(VP_CONFIG_OK, &base_vha->vp_flags)) { | |
365 | if (test_and_clear_bit(VP_IDX_ACQUIRED, &vha->vp_flags)) { | |
366 | /* VP acquired. complete port configuration */ | |
367 | ql_dbg(ql_dbg_dpc, vha, 0x4014, | |
368 | "Configure VP scheduled.\n"); | |
369 | qla24xx_configure_vp(vha); | |
370 | ql_dbg(ql_dbg_dpc, vha, 0x4015, | |
371 | "Configure VP end.\n"); | |
372 | return 0; | |
373 | } | |
2c3dfe3f SJ |
374 | } |
375 | ||
576bfde8 JC |
376 | if (test_bit(PROCESS_PUREX_IOCB, &vha->dpc_flags)) { |
377 | if (atomic_read(&vha->loop_state) == LOOP_READY) { | |
378 | qla24xx_process_purex_list(&vha->purex_list); | |
379 | clear_bit(PROCESS_PUREX_IOCB, &vha->dpc_flags); | |
380 | } | |
381 | } | |
382 | ||
7b867cf7 | 383 | if (test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags)) { |
7c3df132 SK |
384 | ql_dbg(ql_dbg_dpc, vha, 0x4016, |
385 | "FCPort update scheduled.\n"); | |
7b867cf7 AC |
386 | qla2x00_update_fcports(vha); |
387 | clear_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags); | |
7c3df132 SK |
388 | ql_dbg(ql_dbg_dpc, vha, 0x4017, |
389 | "FCPort update end.\n"); | |
7b867cf7 AC |
390 | } |
391 | ||
4005a995 QT |
392 | if (test_bit(RELOGIN_NEEDED, &vha->dpc_flags) && |
393 | !test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) && | |
394 | atomic_read(&vha->loop_state) != LOOP_DOWN) { | |
395 | ||
396 | if (!vha->relogin_jif || | |
397 | time_after_eq(jiffies, vha->relogin_jif)) { | |
398 | vha->relogin_jif = jiffies + HZ; | |
399 | clear_bit(RELOGIN_NEEDED, &vha->dpc_flags); | |
400 | ||
401 | ql_dbg(ql_dbg_dpc, vha, 0x4018, | |
402 | "Relogin needed scheduled.\n"); | |
9b3e0f4d | 403 | qla24xx_post_relogin_work(vha); |
4005a995 | 404 | } |
7b867cf7 | 405 | } |
2c3dfe3f SJ |
406 | |
407 | if (test_and_clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) && | |
408 | (!(test_and_set_bit(RESET_ACTIVE, &vha->dpc_flags)))) { | |
409 | clear_bit(RESET_ACTIVE, &vha->dpc_flags); | |
410 | } | |
411 | ||
73208dfd | 412 | if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
2c3dfe3f | 413 | if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags))) { |
7c3df132 SK |
414 | ql_dbg(ql_dbg_dpc, vha, 0x401a, |
415 | "Loop resync scheduled.\n"); | |
2c3dfe3f SJ |
416 | qla2x00_loop_resync(vha); |
417 | clear_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags); | |
7c3df132 SK |
418 | ql_dbg(ql_dbg_dpc, vha, 0x401b, |
419 | "Loop resync end.\n"); | |
2c3dfe3f SJ |
420 | } |
421 | } | |
422 | ||
5f28d2d7 | 423 | ql_dbg(ql_dbg_dpc + ql_dbg_verbose, vha, 0x401c, |
7c3df132 | 424 | "Exiting %s.\n", __func__); |
2c3dfe3f SJ |
425 | return 0; |
426 | } | |
427 | ||
428 | void | |
7b867cf7 | 429 | qla2x00_do_dpc_all_vps(scsi_qla_host_t *vha) |
2c3dfe3f | 430 | { |
7b867cf7 | 431 | struct qla_hw_data *ha = vha->hw; |
0c9a5f3e | 432 | scsi_qla_host_t *vp, *tvp; |
feafb7b1 | 433 | unsigned long flags = 0; |
2c3dfe3f | 434 | |
7b867cf7 | 435 | if (vha->vp_idx) |
2c3dfe3f SJ |
436 | return; |
437 | if (list_empty(&ha->vp_list)) | |
438 | return; | |
439 | ||
7b867cf7 | 440 | clear_bit(VP_DPC_NEEDED, &vha->dpc_flags); |
2c3dfe3f | 441 | |
0d6e61bc AV |
442 | if (!(ha->current_topology & ISP_CFG_F)) |
443 | return; | |
444 | ||
feafb7b1 | 445 | spin_lock_irqsave(&ha->vport_slock, flags); |
0c9a5f3e | 446 | list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) { |
feafb7b1 AE |
447 | if (vp->vp_idx) { |
448 | atomic_inc(&vp->vref_count); | |
449 | spin_unlock_irqrestore(&ha->vport_slock, flags); | |
450 | ||
52c82823 | 451 | qla2x00_do_dpc_vp(vp); |
feafb7b1 AE |
452 | |
453 | spin_lock_irqsave(&ha->vport_slock, flags); | |
454 | atomic_dec(&vp->vref_count); | |
455 | } | |
2c3dfe3f | 456 | } |
feafb7b1 | 457 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
2c3dfe3f SJ |
458 | } |
459 | ||
460 | int | |
461 | qla24xx_vport_create_req_sanity_check(struct fc_vport *fc_vport) | |
462 | { | |
7b867cf7 AC |
463 | scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost); |
464 | struct qla_hw_data *ha = base_vha->hw; | |
2c3dfe3f SJ |
465 | scsi_qla_host_t *vha; |
466 | uint8_t port_name[WWN_SIZE]; | |
467 | ||
468 | if (fc_vport->roles != FC_PORT_ROLE_FCP_INITIATOR) | |
469 | return VPCERR_UNSUPPORTED; | |
470 | ||
471 | /* Check up the F/W and H/W support NPIV */ | |
472 | if (!ha->flags.npiv_supported) | |
473 | return VPCERR_UNSUPPORTED; | |
474 | ||
475 | /* Check up whether npiv supported switch presented */ | |
476 | if (!(ha->switch_cap & FLOGI_MID_SUPPORT)) | |
477 | return VPCERR_NO_FABRIC_SUPP; | |
478 | ||
479 | /* Check up unique WWPN */ | |
480 | u64_to_wwn(fc_vport->port_name, port_name); | |
7b867cf7 | 481 | if (!memcmp(port_name, base_vha->port_name, WWN_SIZE)) |
50db6b13 | 482 | return VPCERR_BAD_WWN; |
2c3dfe3f SJ |
483 | vha = qla24xx_find_vhost_by_name(ha, port_name); |
484 | if (vha) | |
485 | return VPCERR_BAD_WWN; | |
486 | ||
487 | /* Check up max-npiv-supports */ | |
488 | if (ha->num_vhosts > ha->max_npiv_vports) { | |
7c3df132 SK |
489 | ql_dbg(ql_dbg_vport, vha, 0xa004, |
490 | "num_vhosts %ud is bigger " | |
491 | "than max_npiv_vports %ud.\n", | |
492 | ha->num_vhosts, ha->max_npiv_vports); | |
2c3dfe3f SJ |
493 | return VPCERR_UNSUPPORTED; |
494 | } | |
495 | return 0; | |
496 | } | |
497 | ||
498 | scsi_qla_host_t * | |
499 | qla24xx_create_vhost(struct fc_vport *fc_vport) | |
500 | { | |
7b867cf7 AC |
501 | scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost); |
502 | struct qla_hw_data *ha = base_vha->hw; | |
2c3dfe3f | 503 | scsi_qla_host_t *vha; |
a5326f86 | 504 | struct scsi_host_template *sht = &qla2xxx_driver_template; |
2c3dfe3f SJ |
505 | struct Scsi_Host *host; |
506 | ||
7b867cf7 AC |
507 | vha = qla2x00_create_host(sht, ha); |
508 | if (!vha) { | |
7c3df132 SK |
509 | ql_log(ql_log_warn, vha, 0xa005, |
510 | "scsi_host_alloc() failed for vport.\n"); | |
2c3dfe3f SJ |
511 | return(NULL); |
512 | } | |
513 | ||
7b867cf7 | 514 | host = vha->host; |
2c3dfe3f | 515 | fc_vport->dd_data = vha; |
2c3dfe3f SJ |
516 | /* New host info */ |
517 | u64_to_wwn(fc_vport->node_name, vha->node_name); | |
518 | u64_to_wwn(fc_vport->port_name, vha->port_name); | |
519 | ||
2c3dfe3f SJ |
520 | vha->fc_vport = fc_vport; |
521 | vha->device_flags = 0; | |
2c3dfe3f SJ |
522 | vha->vp_idx = qla24xx_allocate_vp_id(vha); |
523 | if (vha->vp_idx > ha->max_npiv_vports) { | |
7c3df132 SK |
524 | ql_dbg(ql_dbg_vport, vha, 0xa006, |
525 | "Couldn't allocate vp_id.\n"); | |
7b867cf7 | 526 | goto create_vhost_failed; |
2c3dfe3f | 527 | } |
f6602f3b | 528 | vha->mgmt_svr_loop_id = qla2x00_reserve_mgmt_server_loop_id(vha); |
2c3dfe3f | 529 | |
2c3dfe3f | 530 | vha->dpc_flags = 0L; |
818c7f87 JC |
531 | ha->dpc_active = 0; |
532 | set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags); | |
533 | set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags); | |
2c3dfe3f SJ |
534 | |
535 | /* | |
536 | * To fix the issue of processing a parent's RSCN for the vport before | |
537 | * its SCR is complete. | |
538 | */ | |
539 | set_bit(VP_SCR_NEEDED, &vha->vp_flags); | |
540 | atomic_set(&vha->loop_state, LOOP_DOWN); | |
541 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); | |
542 | ||
8e5f4ba0 | 543 | qla2x00_start_timer(vha, WATCH_INTERVAL); |
2c3dfe3f | 544 | |
2afa19a9 | 545 | vha->req = base_vha->req; |
850f6acd | 546 | vha->flags.nvme_enabled = base_vha->flags.nvme_enabled; |
2afa19a9 | 547 | host->can_queue = base_vha->req->length + 128; |
2c3dfe3f | 548 | host->cmd_per_lun = 3; |
e02587d7 | 549 | if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) |
0c470874 AE |
550 | host->max_cmd_len = 32; |
551 | else | |
552 | host->max_cmd_len = MAX_CMDSZ; | |
2c3dfe3f | 553 | host->max_channel = MAX_BUSES - 1; |
82515920 | 554 | host->max_lun = ql2xmaxlun; |
711c1d91 | 555 | host->unique_id = host->host_no; |
642ef983 | 556 | host->max_id = ha->max_fibre_devices; |
2c3dfe3f SJ |
557 | host->transportt = qla2xxx_transport_vport_template; |
558 | ||
7c3df132 SK |
559 | ql_dbg(ql_dbg_vport, vha, 0xa007, |
560 | "Detect vport hba %ld at address = %p.\n", | |
561 | vha->host_no, vha); | |
2c3dfe3f SJ |
562 | |
563 | vha->flags.init_done = 1; | |
2c3dfe3f | 564 | |
0d6e61bc AV |
565 | mutex_lock(&ha->vport_lock); |
566 | set_bit(vha->vp_idx, ha->vp_idx_map); | |
567 | ha->cur_vport_count++; | |
568 | mutex_unlock(&ha->vport_lock); | |
569 | ||
2c3dfe3f SJ |
570 | return vha; |
571 | ||
7b867cf7 | 572 | create_vhost_failed: |
2c3dfe3f SJ |
573 | return NULL; |
574 | } | |
73208dfd AC |
575 | |
576 | static void | |
577 | qla25xx_free_req_que(struct scsi_qla_host *vha, struct req_que *req) | |
578 | { | |
579 | struct qla_hw_data *ha = vha->hw; | |
580 | uint16_t que_id = req->id; | |
581 | ||
582 | dma_free_coherent(&ha->pdev->dev, (req->length + 1) * | |
583 | sizeof(request_t), req->ring, req->dma); | |
584 | req->ring = NULL; | |
585 | req->dma = 0; | |
586 | if (que_id) { | |
587 | ha->req_q_map[que_id] = NULL; | |
588 | mutex_lock(&ha->vport_lock); | |
589 | clear_bit(que_id, ha->req_qid_map); | |
590 | mutex_unlock(&ha->vport_lock); | |
591 | } | |
8d93f550 | 592 | kfree(req->outstanding_cmds); |
73208dfd AC |
593 | kfree(req); |
594 | req = NULL; | |
595 | } | |
596 | ||
597 | static void | |
598 | qla25xx_free_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp) | |
599 | { | |
600 | struct qla_hw_data *ha = vha->hw; | |
601 | uint16_t que_id = rsp->id; | |
602 | ||
603 | if (rsp->msix && rsp->msix->have_irq) { | |
d7459527 | 604 | free_irq(rsp->msix->vector, rsp->msix->handle); |
73208dfd | 605 | rsp->msix->have_irq = 0; |
d7459527 | 606 | rsp->msix->in_use = 0; |
4fa18345 | 607 | rsp->msix->handle = NULL; |
73208dfd AC |
608 | } |
609 | dma_free_coherent(&ha->pdev->dev, (rsp->length + 1) * | |
610 | sizeof(response_t), rsp->ring, rsp->dma); | |
611 | rsp->ring = NULL; | |
612 | rsp->dma = 0; | |
613 | if (que_id) { | |
614 | ha->rsp_q_map[que_id] = NULL; | |
615 | mutex_lock(&ha->vport_lock); | |
616 | clear_bit(que_id, ha->rsp_qid_map); | |
617 | mutex_unlock(&ha->vport_lock); | |
618 | } | |
619 | kfree(rsp); | |
620 | rsp = NULL; | |
621 | } | |
622 | ||
623 | int | |
624 | qla25xx_delete_req_que(struct scsi_qla_host *vha, struct req_que *req) | |
625 | { | |
7867b98d | 626 | int ret = QLA_SUCCESS; |
73208dfd | 627 | |
7867b98d | 628 | if (req && vha->flags.qpairs_req_created) { |
73208dfd | 629 | req->options |= BIT_0; |
618a7523 | 630 | ret = qla25xx_init_req_que(vha, req); |
7867b98d | 631 | if (ret != QLA_SUCCESS) |
632 | return QLA_FUNCTION_FAILED; | |
62aa2814 HM |
633 | |
634 | qla25xx_free_req_que(vha, req); | |
73208dfd | 635 | } |
73208dfd AC |
636 | |
637 | return ret; | |
638 | } | |
639 | ||
d7459527 | 640 | int |
73208dfd AC |
641 | qla25xx_delete_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp) |
642 | { | |
7867b98d | 643 | int ret = QLA_SUCCESS; |
73208dfd | 644 | |
7867b98d | 645 | if (rsp && vha->flags.qpairs_rsp_created) { |
73208dfd | 646 | rsp->options |= BIT_0; |
618a7523 | 647 | ret = qla25xx_init_rsp_que(vha, rsp); |
7867b98d | 648 | if (ret != QLA_SUCCESS) |
649 | return QLA_FUNCTION_FAILED; | |
62aa2814 HM |
650 | |
651 | qla25xx_free_rsp_que(vha, rsp); | |
73208dfd | 652 | } |
73208dfd AC |
653 | |
654 | return ret; | |
655 | } | |
656 | ||
73208dfd AC |
657 | /* Delete all queues for a given vhost */ |
658 | int | |
2afa19a9 | 659 | qla25xx_delete_queues(struct scsi_qla_host *vha) |
73208dfd AC |
660 | { |
661 | int cnt, ret = 0; | |
662 | struct req_que *req = NULL; | |
663 | struct rsp_que *rsp = NULL; | |
664 | struct qla_hw_data *ha = vha->hw; | |
d7459527 | 665 | struct qla_qpair *qpair, *tqpair; |
73208dfd | 666 | |
c38d1baf | 667 | if (ql2xmqsupport || ql2xnvmeenable) { |
d7459527 MH |
668 | list_for_each_entry_safe(qpair, tqpair, &vha->qp_list, |
669 | qp_list_elem) | |
670 | qla2xxx_delete_qpair(vha, qpair); | |
671 | } else { | |
672 | /* Delete request queues */ | |
673 | for (cnt = 1; cnt < ha->max_req_queues; cnt++) { | |
674 | req = ha->req_q_map[cnt]; | |
675 | if (req && test_bit(cnt, ha->req_qid_map)) { | |
676 | ret = qla25xx_delete_req_que(vha, req); | |
677 | if (ret != QLA_SUCCESS) { | |
678 | ql_log(ql_log_warn, vha, 0x00ea, | |
679 | "Couldn't delete req que %d.\n", | |
680 | req->id); | |
681 | return ret; | |
682 | } | |
73208dfd | 683 | } |
73208dfd | 684 | } |
2afa19a9 | 685 | |
d7459527 MH |
686 | /* Delete response queues */ |
687 | for (cnt = 1; cnt < ha->max_rsp_queues; cnt++) { | |
688 | rsp = ha->rsp_q_map[cnt]; | |
689 | if (rsp && test_bit(cnt, ha->rsp_qid_map)) { | |
690 | ret = qla25xx_delete_rsp_que(vha, rsp); | |
691 | if (ret != QLA_SUCCESS) { | |
692 | ql_log(ql_log_warn, vha, 0x00eb, | |
693 | "Couldn't delete rsp que %d.\n", | |
694 | rsp->id); | |
695 | return ret; | |
696 | } | |
73208dfd AC |
697 | } |
698 | } | |
699 | } | |
d7459527 | 700 | |
73208dfd AC |
701 | return ret; |
702 | } | |
703 | ||
704 | int | |
705 | qla25xx_create_req_que(struct qla_hw_data *ha, uint16_t options, | |
82de802a | 706 | uint8_t vp_idx, uint16_t rid, int rsp_que, uint8_t qos, bool startqp) |
73208dfd AC |
707 | { |
708 | int ret = 0; | |
709 | struct req_que *req = NULL; | |
710 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); | |
d65237c7 | 711 | struct scsi_qla_host *vha = pci_get_drvdata(ha->pdev); |
73208dfd | 712 | uint16_t que_id = 0; |
f73cb695 | 713 | device_reg_t *reg; |
2afa19a9 | 714 | uint32_t cnt; |
73208dfd AC |
715 | |
716 | req = kzalloc(sizeof(struct req_que), GFP_KERNEL); | |
717 | if (req == NULL) { | |
7c3df132 SK |
718 | ql_log(ql_log_fatal, base_vha, 0x00d9, |
719 | "Failed to allocate memory for request queue.\n"); | |
c7922a91 | 720 | goto failed; |
73208dfd AC |
721 | } |
722 | ||
723 | req->length = REQUEST_ENTRY_CNT_24XX; | |
724 | req->ring = dma_alloc_coherent(&ha->pdev->dev, | |
725 | (req->length + 1) * sizeof(request_t), | |
726 | &req->dma, GFP_KERNEL); | |
727 | if (req->ring == NULL) { | |
7c3df132 | 728 | ql_log(ql_log_fatal, base_vha, 0x00da, |
d6a03581 | 729 | "Failed to allocate memory for request_ring.\n"); |
73208dfd AC |
730 | goto que_failed; |
731 | } | |
732 | ||
8d93f550 CD |
733 | ret = qla2x00_alloc_outstanding_cmds(ha, req); |
734 | if (ret != QLA_SUCCESS) | |
735 | goto que_failed; | |
736 | ||
d7459527 | 737 | mutex_lock(&ha->mq_lock); |
2afa19a9 AC |
738 | que_id = find_first_zero_bit(ha->req_qid_map, ha->max_req_queues); |
739 | if (que_id >= ha->max_req_queues) { | |
d7459527 | 740 | mutex_unlock(&ha->mq_lock); |
7c3df132 SK |
741 | ql_log(ql_log_warn, base_vha, 0x00db, |
742 | "No resources to create additional request queue.\n"); | |
73208dfd AC |
743 | goto que_failed; |
744 | } | |
745 | set_bit(que_id, ha->req_qid_map); | |
746 | ha->req_q_map[que_id] = req; | |
747 | req->rid = rid; | |
748 | req->vp_idx = vp_idx; | |
749 | req->qos = qos; | |
750 | ||
7c3df132 SK |
751 | ql_dbg(ql_dbg_multiq, base_vha, 0xc002, |
752 | "queue_id=%d rid=%d vp_idx=%d qos=%d.\n", | |
753 | que_id, req->rid, req->vp_idx, req->qos); | |
754 | ql_dbg(ql_dbg_init, base_vha, 0x00dc, | |
755 | "queue_id=%d rid=%d vp_idx=%d qos=%d.\n", | |
756 | que_id, req->rid, req->vp_idx, req->qos); | |
2afa19a9 AC |
757 | if (rsp_que < 0) |
758 | req->rsp = NULL; | |
759 | else | |
73208dfd AC |
760 | req->rsp = ha->rsp_q_map[rsp_que]; |
761 | /* Use alternate PCI bus number */ | |
762 | if (MSB(req->rid)) | |
763 | options |= BIT_4; | |
764 | /* Use alternate PCI devfn */ | |
765 | if (LSB(req->rid)) | |
766 | options |= BIT_5; | |
767 | req->options = options; | |
2afa19a9 | 768 | |
7c3df132 SK |
769 | ql_dbg(ql_dbg_multiq, base_vha, 0xc003, |
770 | "options=0x%x.\n", req->options); | |
771 | ql_dbg(ql_dbg_init, base_vha, 0x00dd, | |
772 | "options=0x%x.\n", req->options); | |
8d93f550 | 773 | for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) |
2afa19a9 AC |
774 | req->outstanding_cmds[cnt] = NULL; |
775 | req->current_outstanding_cmd = 1; | |
776 | ||
73208dfd AC |
777 | req->ring_ptr = req->ring; |
778 | req->ring_index = 0; | |
779 | req->cnt = req->length; | |
780 | req->id = que_id; | |
08029990 | 781 | reg = ISP_QUE_REG(ha, que_id); |
da9b1d5c AV |
782 | req->req_q_in = ®->isp25mq.req_q_in; |
783 | req->req_q_out = ®->isp25mq.req_q_out; | |
29bdccbe | 784 | req->max_q_depth = ha->req_q_map[0]->max_q_depth; |
ab053c09 | 785 | req->out_ptr = (uint16_t *)(req->ring + req->length); |
d7459527 | 786 | mutex_unlock(&ha->mq_lock); |
7c3df132 SK |
787 | ql_dbg(ql_dbg_multiq, base_vha, 0xc004, |
788 | "ring_ptr=%p ring_index=%d, " | |
789 | "cnt=%d id=%d max_q_depth=%d.\n", | |
790 | req->ring_ptr, req->ring_index, | |
791 | req->cnt, req->id, req->max_q_depth); | |
792 | ql_dbg(ql_dbg_init, base_vha, 0x00de, | |
793 | "ring_ptr=%p ring_index=%d, " | |
794 | "cnt=%d id=%d max_q_depth=%d.\n", | |
795 | req->ring_ptr, req->ring_index, req->cnt, | |
796 | req->id, req->max_q_depth); | |
73208dfd | 797 | |
82de802a QT |
798 | if (startqp) { |
799 | ret = qla25xx_init_req_que(base_vha, req); | |
800 | if (ret != QLA_SUCCESS) { | |
801 | ql_log(ql_log_fatal, base_vha, 0x00df, | |
802 | "%s failed.\n", __func__); | |
803 | mutex_lock(&ha->mq_lock); | |
804 | clear_bit(que_id, ha->req_qid_map); | |
805 | mutex_unlock(&ha->mq_lock); | |
806 | goto que_failed; | |
807 | } | |
d65237c7 | 808 | vha->flags.qpairs_req_created = 1; |
73208dfd AC |
809 | } |
810 | ||
811 | return req->id; | |
812 | ||
813 | que_failed: | |
814 | qla25xx_free_req_que(base_vha, req); | |
c7922a91 | 815 | failed: |
73208dfd AC |
816 | return 0; |
817 | } | |
818 | ||
68ca949c AC |
819 | static void qla_do_work(struct work_struct *work) |
820 | { | |
a67093d4 | 821 | unsigned long flags; |
d7459527 | 822 | struct qla_qpair *qpair = container_of(work, struct qla_qpair, q_work); |
49db4d4e | 823 | struct scsi_qla_host *vha = qpair->vha; |
68ca949c | 824 | |
d7459527 | 825 | spin_lock_irqsave(&qpair->qp_lock, flags); |
d7459527 MH |
826 | qla24xx_process_response_queue(vha, qpair->rsp); |
827 | spin_unlock_irqrestore(&qpair->qp_lock, flags); | |
cf19c45d | 828 | |
68ca949c AC |
829 | } |
830 | ||
73208dfd AC |
831 | /* create response queue */ |
832 | int | |
833 | qla25xx_create_rsp_que(struct qla_hw_data *ha, uint16_t options, | |
82de802a | 834 | uint8_t vp_idx, uint16_t rid, struct qla_qpair *qpair, bool startqp) |
73208dfd AC |
835 | { |
836 | int ret = 0; | |
837 | struct rsp_que *rsp = NULL; | |
838 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); | |
d65237c7 | 839 | struct scsi_qla_host *vha = pci_get_drvdata(ha->pdev); |
08029990 | 840 | uint16_t que_id = 0; |
f73cb695 | 841 | device_reg_t *reg; |
73208dfd AC |
842 | |
843 | rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL); | |
844 | if (rsp == NULL) { | |
7c3df132 SK |
845 | ql_log(ql_log_warn, base_vha, 0x0066, |
846 | "Failed to allocate memory for response queue.\n"); | |
c7922a91 | 847 | goto failed; |
73208dfd AC |
848 | } |
849 | ||
2afa19a9 | 850 | rsp->length = RESPONSE_ENTRY_CNT_MQ; |
73208dfd AC |
851 | rsp->ring = dma_alloc_coherent(&ha->pdev->dev, |
852 | (rsp->length + 1) * sizeof(response_t), | |
853 | &rsp->dma, GFP_KERNEL); | |
854 | if (rsp->ring == NULL) { | |
7c3df132 SK |
855 | ql_log(ql_log_warn, base_vha, 0x00e1, |
856 | "Failed to allocate memory for response ring.\n"); | |
73208dfd AC |
857 | goto que_failed; |
858 | } | |
859 | ||
d7459527 | 860 | mutex_lock(&ha->mq_lock); |
2afa19a9 AC |
861 | que_id = find_first_zero_bit(ha->rsp_qid_map, ha->max_rsp_queues); |
862 | if (que_id >= ha->max_rsp_queues) { | |
d7459527 | 863 | mutex_unlock(&ha->mq_lock); |
7c3df132 SK |
864 | ql_log(ql_log_warn, base_vha, 0x00e2, |
865 | "No resources to create additional request queue.\n"); | |
73208dfd AC |
866 | goto que_failed; |
867 | } | |
868 | set_bit(que_id, ha->rsp_qid_map); | |
869 | ||
d7459527 | 870 | rsp->msix = qpair->msix; |
73208dfd AC |
871 | |
872 | ha->rsp_q_map[que_id] = rsp; | |
873 | rsp->rid = rid; | |
874 | rsp->vp_idx = vp_idx; | |
875 | rsp->hw = ha; | |
7c3df132 | 876 | ql_dbg(ql_dbg_init, base_vha, 0x00e4, |
d7459527 | 877 | "rsp queue_id=%d rid=%d vp_idx=%d hw=%p.\n", |
7c3df132 | 878 | que_id, rsp->rid, rsp->vp_idx, rsp->hw); |
73208dfd AC |
879 | /* Use alternate PCI bus number */ |
880 | if (MSB(rsp->rid)) | |
881 | options |= BIT_4; | |
882 | /* Use alternate PCI devfn */ | |
883 | if (LSB(rsp->rid)) | |
884 | options |= BIT_5; | |
3155754a AC |
885 | /* Enable MSIX handshake mode on for uncapable adapters */ |
886 | if (!IS_MSIX_NACK_CAPABLE(ha)) | |
887 | options |= BIT_6; | |
888 | ||
d7459527 MH |
889 | /* Set option to indicate response queue creation */ |
890 | options |= BIT_1; | |
891 | ||
73208dfd | 892 | rsp->options = options; |
73208dfd | 893 | rsp->id = que_id; |
08029990 AV |
894 | reg = ISP_QUE_REG(ha, que_id); |
895 | rsp->rsp_q_in = ®->isp25mq.rsp_q_in; | |
896 | rsp->rsp_q_out = ®->isp25mq.rsp_q_out; | |
ab053c09 | 897 | rsp->in_ptr = (uint16_t *)(rsp->ring + rsp->length); |
d7459527 | 898 | mutex_unlock(&ha->mq_lock); |
7c3df132 | 899 | ql_dbg(ql_dbg_multiq, base_vha, 0xc00b, |
d7459527 | 900 | "options=%x id=%d rsp_q_in=%p rsp_q_out=%p\n", |
7c3df132 SK |
901 | rsp->options, rsp->id, rsp->rsp_q_in, |
902 | rsp->rsp_q_out); | |
903 | ql_dbg(ql_dbg_init, base_vha, 0x00e5, | |
d7459527 | 904 | "options=%x id=%d rsp_q_in=%p rsp_q_out=%p\n", |
7c3df132 SK |
905 | rsp->options, rsp->id, rsp->rsp_q_in, |
906 | rsp->rsp_q_out); | |
73208dfd | 907 | |
d7459527 | 908 | ret = qla25xx_request_irq(ha, qpair, qpair->msix, |
7b2a7396 AV |
909 | ha->flags.disable_msix_handshake ? |
910 | QLA_MSIX_QPAIR_MULTIQ_RSP_Q : QLA_MSIX_QPAIR_MULTIQ_RSP_Q_HS); | |
73208dfd AC |
911 | if (ret) |
912 | goto que_failed; | |
913 | ||
82de802a QT |
914 | if (startqp) { |
915 | ret = qla25xx_init_rsp_que(base_vha, rsp); | |
916 | if (ret != QLA_SUCCESS) { | |
917 | ql_log(ql_log_fatal, base_vha, 0x00e7, | |
918 | "%s failed.\n", __func__); | |
919 | mutex_lock(&ha->mq_lock); | |
920 | clear_bit(que_id, ha->rsp_qid_map); | |
921 | mutex_unlock(&ha->mq_lock); | |
922 | goto que_failed; | |
923 | } | |
d65237c7 | 924 | vha->flags.qpairs_rsp_created = 1; |
73208dfd | 925 | } |
d7459527 | 926 | rsp->req = NULL; |
73208dfd AC |
927 | |
928 | qla2x00_init_response_q_entries(rsp); | |
d7459527 MH |
929 | if (qpair->hw->wq) |
930 | INIT_WORK(&qpair->q_work, qla_do_work); | |
73208dfd AC |
931 | return rsp->id; |
932 | ||
933 | que_failed: | |
934 | qla25xx_free_rsp_que(base_vha, rsp); | |
c7922a91 | 935 | failed: |
73208dfd AC |
936 | return 0; |
937 | } | |
2853192e | 938 | |
6c18a43e | 939 | static void qla_ctrlvp_sp_done(srb_t *sp, int res) |
2853192e | 940 | { |
982cc4be BVA |
941 | if (sp->comp) |
942 | complete(sp->comp); | |
2853192e QT |
943 | /* don't free sp here. Let the caller do the free */ |
944 | } | |
945 | ||
946 | /** | |
947 | * qla24xx_control_vp() - Enable a virtual port for given host | |
948 | * @vha: adapter block pointer | |
949 | * @cmd: command type to be sent for enable virtual port | |
950 | * | |
951 | * Return: qla2xxx local function return status code. | |
952 | */ | |
953 | int qla24xx_control_vp(scsi_qla_host_t *vha, int cmd) | |
954 | { | |
955 | int rval = QLA_MEMORY_ALLOC_FAILED; | |
956 | struct qla_hw_data *ha = vha->hw; | |
957 | int vp_index = vha->vp_idx; | |
958 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); | |
982cc4be | 959 | DECLARE_COMPLETION_ONSTACK(comp); |
2853192e QT |
960 | srb_t *sp; |
961 | ||
962 | ql_dbg(ql_dbg_vport, vha, 0x10c1, | |
963 | "Entered %s cmd %x index %d.\n", __func__, cmd, vp_index); | |
964 | ||
965 | if (vp_index == 0 || vp_index >= ha->max_npiv_vports) | |
966 | return QLA_PARAMETER_ERROR; | |
967 | ||
ee7bd382 | 968 | /* ref: INIT */ |
2853192e QT |
969 | sp = qla2x00_get_sp(base_vha, NULL, GFP_KERNEL); |
970 | if (!sp) | |
af2a0c51 | 971 | return rval; |
2853192e QT |
972 | |
973 | sp->type = SRB_CTRL_VP; | |
974 | sp->name = "ctrl_vp"; | |
982cc4be | 975 | sp->comp = ∁ |
75a1d041 DW |
976 | qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2, |
977 | qla_ctrlvp_sp_done); | |
2853192e QT |
978 | sp->u.iocb_cmd.u.ctrlvp.cmd = cmd; |
979 | sp->u.iocb_cmd.u.ctrlvp.vp_index = vp_index; | |
980 | ||
981 | rval = qla2x00_start_sp(sp); | |
982 | if (rval != QLA_SUCCESS) { | |
983 | ql_dbg(ql_dbg_async, vha, 0xffff, | |
984 | "%s: %s Failed submission. %x.\n", | |
985 | __func__, sp->name, rval); | |
af2a0c51 | 986 | goto done; |
2853192e QT |
987 | } |
988 | ||
989 | ql_dbg(ql_dbg_vport, vha, 0x113f, "%s hndl %x submitted\n", | |
990 | sp->name, sp->handle); | |
991 | ||
982cc4be BVA |
992 | wait_for_completion(&comp); |
993 | sp->comp = NULL; | |
994 | ||
2853192e QT |
995 | rval = sp->rc; |
996 | switch (rval) { | |
997 | case QLA_FUNCTION_TIMEOUT: | |
998 | ql_dbg(ql_dbg_vport, vha, 0xffff, "%s: %s Timeout. %x.\n", | |
999 | __func__, sp->name, rval); | |
1000 | break; | |
1001 | case QLA_SUCCESS: | |
1002 | ql_dbg(ql_dbg_vport, vha, 0xffff, "%s: %s done.\n", | |
1003 | __func__, sp->name); | |
af2a0c51 | 1004 | break; |
2853192e QT |
1005 | default: |
1006 | ql_dbg(ql_dbg_vport, vha, 0xffff, "%s: %s Failed. %x.\n", | |
1007 | __func__, sp->name, rval); | |
af2a0c51 | 1008 | break; |
2853192e QT |
1009 | } |
1010 | done: | |
ee7bd382 SK |
1011 | /* ref: INIT */ |
1012 | kref_put(&sp->cmd_kref, qla2x00_sp_release); | |
2853192e QT |
1013 | return rval; |
1014 | } |