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