Commit | Line | Data |
---|---|---|
2c3dfe3f | 1 | /* |
01e58d8e | 2 | * QLogic Fibre Channel HBA Driver |
1e63395c | 3 | * Copyright (c) 2003-2013 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 | */ | |
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); | |
2d70c103 | 86 | qlt_update_vp_map(vha, RESET_VP_IDX); |
feafb7b1 AE |
87 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
88 | ||
2c3dfe3f SJ |
89 | vp_id = vha->vp_idx; |
90 | ha->num_vhosts--; | |
eb66dc60 | 91 | clear_bit(vp_id, ha->vp_idx_map); |
feafb7b1 | 92 | |
6c2f527c | 93 | mutex_unlock(&ha->vport_lock); |
2c3dfe3f SJ |
94 | } |
95 | ||
a824ebb3 | 96 | static scsi_qla_host_t * |
7b867cf7 | 97 | qla24xx_find_vhost_by_name(struct qla_hw_data *ha, uint8_t *port_name) |
2c3dfe3f SJ |
98 | { |
99 | scsi_qla_host_t *vha; | |
ee546b6e | 100 | struct scsi_qla_host *tvha; |
feafb7b1 | 101 | unsigned long flags; |
2c3dfe3f | 102 | |
feafb7b1 | 103 | spin_lock_irqsave(&ha->vport_slock, flags); |
2c3dfe3f | 104 | /* Locate matching device in database. */ |
ee546b6e | 105 | list_for_each_entry_safe(vha, tvha, &ha->vp_list, list) { |
feafb7b1 AE |
106 | if (!memcmp(port_name, vha->port_name, WWN_SIZE)) { |
107 | spin_unlock_irqrestore(&ha->vport_slock, flags); | |
2c3dfe3f | 108 | return vha; |
feafb7b1 | 109 | } |
2c3dfe3f | 110 | } |
feafb7b1 | 111 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
2c3dfe3f SJ |
112 | 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 | */ | |
26ff776d | 128 | static void |
2c3dfe3f SJ |
129 | qla2x00_mark_vp_devices_dead(scsi_qla_host_t *vha) |
130 | { | |
feafb7b1 AE |
131 | /* |
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 | */ | |
2c3dfe3f | 137 | fc_port_t *fcport; |
2c3dfe3f | 138 | |
7b867cf7 | 139 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
7c3df132 SK |
140 | ql_dbg(ql_dbg_vport, vha, 0xa001, |
141 | "Marking port dead, loop_id=0x%04x : %x.\n", | |
c6d39e23 | 142 | fcport->loop_id, fcport->vha->vp_idx); |
2c3dfe3f | 143 | |
2c3dfe3f | 144 | qla2x00_mark_device_lost(vha, fcport, 0, 0); |
ec426e10 | 145 | qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED); |
2c3dfe3f SJ |
146 | } |
147 | } | |
148 | ||
149 | int | |
150 | qla24xx_disable_vp(scsi_qla_host_t *vha) | |
151 | { | |
29c08cda | 152 | unsigned long flags; |
2c3dfe3f SJ |
153 | 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 | ||
2d70c103 | 159 | /* Remove port id from vp target map */ |
29c08cda | 160 | spin_lock_irqsave(&vha->hw->vport_slock, flags); |
2d70c103 | 161 | qlt_update_vp_map(vha, RESET_AL_PA); |
29c08cda | 162 | spin_unlock_irqrestore(&vha->hw->vport_slock, flags); |
2d70c103 | 163 | |
2c3dfe3f SJ |
164 | 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 | ||
176 | int | |
177 | qla24xx_enable_vp(scsi_qla_host_t *vha) | |
178 | { | |
179 | int ret; | |
7b867cf7 AC |
180 | struct qla_hw_data *ha = vha->hw; |
181 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); | |
2c3dfe3f SJ |
182 | |
183 | /* Check if physical ha port is Up */ | |
7b867cf7 | 184 | if (atomic_read(&base_vha->loop_state) == LOOP_DOWN || |
3f3b6f98 LC |
185 | atomic_read(&base_vha->loop_state) == LOOP_DEAD || |
186 | !(ha->current_topology & ISP_CFG_F)) { | |
2c3dfe3f SJ |
187 | 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 */ | |
6c2f527c | 193 | mutex_lock(&ha->vport_lock); |
2c3dfe3f | 194 | ret = qla24xx_modify_vp_config(vha); |
6c2f527c | 195 | mutex_unlock(&ha->vport_lock); |
2c3dfe3f SJ |
196 | |
197 | if (ret != QLA_SUCCESS) { | |
198 | fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED); | |
199 | goto enable_failed; | |
200 | } | |
201 | ||
7c3df132 SK |
202 | ql_dbg(ql_dbg_taskm, vha, 0x801a, |
203 | "Virtual port with id: %d - Enabled.\n", vha->vp_idx); | |
2c3dfe3f SJ |
204 | return 0; |
205 | ||
206 | enable_failed: | |
7c3df132 SK |
207 | ql_dbg(ql_dbg_taskm, vha, 0x801b, |
208 | "Virtual port with id: %d - Disabled.\n", vha->vp_idx); | |
2c3dfe3f SJ |
209 | return 1; |
210 | } | |
211 | ||
26ff776d | 212 | static void |
2c3dfe3f SJ |
213 | qla24xx_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 | ||
7c3df132 SK |
220 | ql_dbg(ql_dbg_vport, vha, 0xa002, |
221 | "%s: change request #3.\n", __func__); | |
2c3dfe3f SJ |
222 | ret = qla2x00_send_change_request(vha, 0x3, vha->vp_idx); |
223 | if (ret != QLA_SUCCESS) { | |
7c3df132 SK |
224 | ql_dbg(ql_dbg_vport, vha, 0xa003, "Failed to enable " |
225 | "receiving of RSCN requests: 0x%x.\n", ret); | |
2c3dfe3f SJ |
226 | 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 | ||
240 | void | |
73208dfd | 241 | qla2x00_alert_all_vps(struct rsp_que *rsp, uint16_t *mb) |
2c3dfe3f | 242 | { |
feafb7b1 | 243 | scsi_qla_host_t *vha; |
73208dfd | 244 | struct qla_hw_data *ha = rsp->hw; |
7b867cf7 | 245 | int i = 0; |
feafb7b1 | 246 | unsigned long flags; |
2c3dfe3f | 247 | |
feafb7b1 AE |
248 | spin_lock_irqsave(&ha->vport_slock, flags); |
249 | list_for_each_entry(vha, &ha->vp_list, list) { | |
7b867cf7 | 250 | if (vha->vp_idx) { |
feafb7b1 AE |
251 | atomic_inc(&vha->vref_count); |
252 | spin_unlock_irqrestore(&ha->vport_slock, flags); | |
253 | ||
2c3dfe3f SJ |
254 | 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: | |
7c3df132 SK |
263 | ql_dbg(ql_dbg_async, vha, 0x5024, |
264 | "Async_event for VP[%d], mb=0x%x vha=%p.\n", | |
265 | i, *mb, vha); | |
73208dfd | 266 | qla2x00_async_event(vha, rsp, mb); |
2c3dfe3f SJ |
267 | break; |
268 | } | |
feafb7b1 AE |
269 | |
270 | spin_lock_irqsave(&ha->vport_slock, flags); | |
271 | atomic_dec(&vha->vref_count); | |
2c3dfe3f | 272 | } |
7b867cf7 | 273 | i++; |
2c3dfe3f | 274 | } |
feafb7b1 | 275 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
2c3dfe3f SJ |
276 | } |
277 | ||
7b867cf7 | 278 | int |
2c3dfe3f SJ |
279 | qla2x00_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 | ||
0d6e61bc AV |
293 | /* |
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 | */ | |
7b867cf7 AC |
298 | if (!test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) |
299 | qla24xx_control_vp(vha, VCE_COMMAND_DISABLE_VPS_LOGO_ALL); | |
300 | ||
7c3df132 SK |
301 | ql_dbg(ql_dbg_taskm, vha, 0x801d, |
302 | "Scheduling enable of Vport %d.\n", vha->vp_idx); | |
7b867cf7 | 303 | return qla24xx_enable_vp(vha); |
2c3dfe3f SJ |
304 | } |
305 | ||
a824ebb3 | 306 | static int |
2c3dfe3f SJ |
307 | qla2x00_do_dpc_vp(scsi_qla_host_t *vha) |
308 | { | |
5f28d2d7 SK |
309 | ql_dbg(ql_dbg_dpc + ql_dbg_verbose, vha, 0x4012, |
310 | "Entering %s vp_flags: 0x%lx.\n", __func__, vha->vp_flags); | |
7c3df132 | 311 | |
ac280b67 AV |
312 | qla2x00_do_work(vha); |
313 | ||
2c3dfe3f SJ |
314 | if (test_and_clear_bit(VP_IDX_ACQUIRED, &vha->vp_flags)) { |
315 | /* VP acquired. complete port configuration */ | |
7c3df132 SK |
316 | ql_dbg(ql_dbg_dpc, vha, 0x4014, |
317 | "Configure VP scheduled.\n"); | |
0d6e61bc | 318 | qla24xx_configure_vp(vha); |
7c3df132 SK |
319 | ql_dbg(ql_dbg_dpc, vha, 0x4015, |
320 | "Configure VP end.\n"); | |
2c3dfe3f SJ |
321 | return 0; |
322 | } | |
323 | ||
7b867cf7 | 324 | if (test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags)) { |
7c3df132 SK |
325 | ql_dbg(ql_dbg_dpc, vha, 0x4016, |
326 | "FCPort update scheduled.\n"); | |
7b867cf7 AC |
327 | qla2x00_update_fcports(vha); |
328 | clear_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags); | |
7c3df132 SK |
329 | ql_dbg(ql_dbg_dpc, vha, 0x4017, |
330 | "FCPort update end.\n"); | |
7b867cf7 AC |
331 | } |
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 | ||
7c3df132 SK |
337 | ql_dbg(ql_dbg_dpc, vha, 0x4018, |
338 | "Relogin needed scheduled.\n"); | |
7b867cf7 | 339 | qla2x00_relogin(vha); |
7c3df132 SK |
340 | ql_dbg(ql_dbg_dpc, vha, 0x4019, |
341 | "Relogin needed end.\n"); | |
7b867cf7 | 342 | } |
2c3dfe3f SJ |
343 | |
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 | ||
73208dfd | 349 | if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
2c3dfe3f | 350 | if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags))) { |
7c3df132 SK |
351 | ql_dbg(ql_dbg_dpc, vha, 0x401a, |
352 | "Loop resync scheduled.\n"); | |
2c3dfe3f SJ |
353 | qla2x00_loop_resync(vha); |
354 | clear_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags); | |
7c3df132 SK |
355 | ql_dbg(ql_dbg_dpc, vha, 0x401b, |
356 | "Loop resync end.\n"); | |
2c3dfe3f SJ |
357 | } |
358 | } | |
359 | ||
5f28d2d7 | 360 | ql_dbg(ql_dbg_dpc + ql_dbg_verbose, vha, 0x401c, |
7c3df132 | 361 | "Exiting %s.\n", __func__); |
2c3dfe3f SJ |
362 | return 0; |
363 | } | |
364 | ||
365 | void | |
7b867cf7 | 366 | qla2x00_do_dpc_all_vps(scsi_qla_host_t *vha) |
2c3dfe3f SJ |
367 | { |
368 | int ret; | |
7b867cf7 AC |
369 | struct qla_hw_data *ha = vha->hw; |
370 | scsi_qla_host_t *vp; | |
feafb7b1 | 371 | unsigned long flags = 0; |
2c3dfe3f | 372 | |
7b867cf7 | 373 | if (vha->vp_idx) |
2c3dfe3f SJ |
374 | return; |
375 | if (list_empty(&ha->vp_list)) | |
376 | return; | |
377 | ||
7b867cf7 | 378 | clear_bit(VP_DPC_NEEDED, &vha->dpc_flags); |
2c3dfe3f | 379 | |
0d6e61bc AV |
380 | if (!(ha->current_topology & ISP_CFG_F)) |
381 | return; | |
382 | ||
feafb7b1 AE |
383 | 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 | ||
7b867cf7 | 389 | ret = qla2x00_do_dpc_vp(vp); |
feafb7b1 AE |
390 | |
391 | spin_lock_irqsave(&ha->vport_slock, flags); | |
392 | atomic_dec(&vp->vref_count); | |
393 | } | |
2c3dfe3f | 394 | } |
feafb7b1 | 395 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
2c3dfe3f SJ |
396 | } |
397 | ||
398 | int | |
399 | qla24xx_vport_create_req_sanity_check(struct fc_vport *fc_vport) | |
400 | { | |
7b867cf7 AC |
401 | scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost); |
402 | struct qla_hw_data *ha = base_vha->hw; | |
2c3dfe3f SJ |
403 | 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); | |
7b867cf7 | 419 | if (!memcmp(port_name, base_vha->port_name, WWN_SIZE)) |
50db6b13 | 420 | return VPCERR_BAD_WWN; |
2c3dfe3f SJ |
421 | 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) { | |
7c3df132 SK |
427 | 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); | |
2c3dfe3f SJ |
431 | return VPCERR_UNSUPPORTED; |
432 | } | |
433 | return 0; | |
434 | } | |
435 | ||
436 | scsi_qla_host_t * | |
437 | qla24xx_create_vhost(struct fc_vport *fc_vport) | |
438 | { | |
7b867cf7 AC |
439 | scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost); |
440 | struct qla_hw_data *ha = base_vha->hw; | |
2c3dfe3f | 441 | scsi_qla_host_t *vha; |
a5326f86 | 442 | struct scsi_host_template *sht = &qla2xxx_driver_template; |
2c3dfe3f SJ |
443 | struct Scsi_Host *host; |
444 | ||
7b867cf7 AC |
445 | vha = qla2x00_create_host(sht, ha); |
446 | if (!vha) { | |
7c3df132 SK |
447 | ql_log(ql_log_warn, vha, 0xa005, |
448 | "scsi_host_alloc() failed for vport.\n"); | |
2c3dfe3f SJ |
449 | return(NULL); |
450 | } | |
451 | ||
7b867cf7 | 452 | host = vha->host; |
2c3dfe3f | 453 | fc_vport->dd_data = vha; |
2c3dfe3f SJ |
454 | /* 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 | ||
2c3dfe3f SJ |
458 | vha->fc_vport = fc_vport; |
459 | vha->device_flags = 0; | |
2c3dfe3f SJ |
460 | vha->vp_idx = qla24xx_allocate_vp_id(vha); |
461 | if (vha->vp_idx > ha->max_npiv_vports) { | |
7c3df132 SK |
462 | ql_dbg(ql_dbg_vport, vha, 0xa006, |
463 | "Couldn't allocate vp_id.\n"); | |
7b867cf7 | 464 | goto create_vhost_failed; |
2c3dfe3f SJ |
465 | } |
466 | vha->mgmt_svr_loop_id = 10 + vha->vp_idx; | |
467 | ||
2c3dfe3f | 468 | vha->dpc_flags = 0L; |
2c3dfe3f SJ |
469 | |
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 | ||
2afa19a9 AC |
480 | vha->req = base_vha->req; |
481 | host->can_queue = base_vha->req->length + 128; | |
2c3dfe3f | 482 | host->cmd_per_lun = 3; |
e02587d7 | 483 | if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) |
0c470874 AE |
484 | host->max_cmd_len = 32; |
485 | else | |
486 | host->max_cmd_len = MAX_CMDSZ; | |
2c3dfe3f | 487 | host->max_channel = MAX_BUSES - 1; |
82515920 | 488 | host->max_lun = ql2xmaxlun; |
711c1d91 | 489 | host->unique_id = host->host_no; |
642ef983 | 490 | host->max_id = ha->max_fibre_devices; |
2c3dfe3f SJ |
491 | host->transportt = qla2xxx_transport_vport_template; |
492 | ||
7c3df132 SK |
493 | ql_dbg(ql_dbg_vport, vha, 0xa007, |
494 | "Detect vport hba %ld at address = %p.\n", | |
495 | vha->host_no, vha); | |
2c3dfe3f SJ |
496 | |
497 | vha->flags.init_done = 1; | |
2c3dfe3f | 498 | |
0d6e61bc AV |
499 | 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 | ||
2c3dfe3f SJ |
504 | return vha; |
505 | ||
7b867cf7 | 506 | create_vhost_failed: |
2c3dfe3f SJ |
507 | return NULL; |
508 | } | |
73208dfd AC |
509 | |
510 | static void | |
511 | qla25xx_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 | } | |
8d93f550 | 526 | kfree(req->outstanding_cmds); |
73208dfd AC |
527 | kfree(req); |
528 | req = NULL; | |
529 | } | |
530 | ||
531 | static void | |
532 | qla25xx_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 | ||
556 | int | |
557 | qla25xx_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; | |
618a7523 | 563 | ret = qla25xx_init_req_que(vha, req); |
73208dfd AC |
564 | } |
565 | if (ret == QLA_SUCCESS) | |
566 | qla25xx_free_req_que(vha, req); | |
567 | ||
568 | return ret; | |
569 | } | |
570 | ||
3dbe756a | 571 | static int |
73208dfd AC |
572 | qla25xx_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; | |
618a7523 | 578 | ret = qla25xx_init_rsp_que(vha, rsp); |
73208dfd AC |
579 | } |
580 | if (ret == QLA_SUCCESS) | |
581 | qla25xx_free_rsp_que(vha, rsp); | |
582 | ||
583 | return ret; | |
584 | } | |
585 | ||
73208dfd AC |
586 | /* Delete all queues for a given vhost */ |
587 | int | |
2afa19a9 | 588 | qla25xx_delete_queues(struct scsi_qla_host *vha) |
73208dfd AC |
589 | { |
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 | ||
2afa19a9 AC |
595 | /* Delete request queues */ |
596 | for (cnt = 1; cnt < ha->max_req_queues; cnt++) { | |
597 | req = ha->req_q_map[cnt]; | |
73208dfd | 598 | if (req) { |
73208dfd AC |
599 | ret = qla25xx_delete_req_que(vha, req); |
600 | if (ret != QLA_SUCCESS) { | |
7c3df132 SK |
601 | ql_log(ql_log_warn, vha, 0x00ea, |
602 | "Couldn't delete req que %d.\n", | |
603 | req->id); | |
73208dfd AC |
604 | return ret; |
605 | } | |
73208dfd | 606 | } |
2afa19a9 AC |
607 | } |
608 | ||
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) { | |
7c3df132 SK |
615 | ql_log(ql_log_warn, vha, 0x00eb, |
616 | "Couldn't delete rsp que %d.\n", | |
617 | rsp->id); | |
2afa19a9 | 618 | return ret; |
73208dfd AC |
619 | } |
620 | } | |
621 | } | |
73208dfd AC |
622 | return ret; |
623 | } | |
624 | ||
625 | int | |
626 | qla25xx_create_req_que(struct qla_hw_data *ha, uint16_t options, | |
2afa19a9 | 627 | uint8_t vp_idx, uint16_t rid, int rsp_que, uint8_t qos) |
73208dfd AC |
628 | { |
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; | |
08029990 | 633 | device_reg_t __iomem *reg; |
2afa19a9 | 634 | uint32_t cnt; |
73208dfd AC |
635 | |
636 | req = kzalloc(sizeof(struct req_que), GFP_KERNEL); | |
637 | if (req == NULL) { | |
7c3df132 SK |
638 | ql_log(ql_log_fatal, base_vha, 0x00d9, |
639 | "Failed to allocate memory for request queue.\n"); | |
c7922a91 | 640 | goto failed; |
73208dfd AC |
641 | } |
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) { | |
7c3df132 | 648 | ql_log(ql_log_fatal, base_vha, 0x00da, |
d6a03581 | 649 | "Failed to allocate memory for request_ring.\n"); |
73208dfd AC |
650 | goto que_failed; |
651 | } | |
652 | ||
8d93f550 CD |
653 | ret = qla2x00_alloc_outstanding_cmds(ha, req); |
654 | if (ret != QLA_SUCCESS) | |
655 | goto que_failed; | |
656 | ||
73208dfd | 657 | mutex_lock(&ha->vport_lock); |
2afa19a9 AC |
658 | que_id = find_first_zero_bit(ha->req_qid_map, ha->max_req_queues); |
659 | if (que_id >= ha->max_req_queues) { | |
73208dfd | 660 | mutex_unlock(&ha->vport_lock); |
7c3df132 SK |
661 | ql_log(ql_log_warn, base_vha, 0x00db, |
662 | "No resources to create additional request queue.\n"); | |
73208dfd AC |
663 | 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 | ||
7c3df132 SK |
671 | 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); | |
2afa19a9 AC |
677 | if (rsp_que < 0) |
678 | req->rsp = NULL; | |
679 | else | |
73208dfd AC |
680 | 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; | |
2afa19a9 | 688 | |
7c3df132 SK |
689 | 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); | |
8d93f550 | 693 | for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) |
2afa19a9 AC |
694 | req->outstanding_cmds[cnt] = NULL; |
695 | req->current_outstanding_cmd = 1; | |
696 | ||
73208dfd AC |
697 | req->ring_ptr = req->ring; |
698 | req->ring_index = 0; | |
699 | req->cnt = req->length; | |
700 | req->id = que_id; | |
08029990 | 701 | reg = ISP_QUE_REG(ha, que_id); |
da9b1d5c AV |
702 | req->req_q_in = ®->isp25mq.req_q_in; |
703 | req->req_q_out = ®->isp25mq.req_q_out; | |
29bdccbe | 704 | req->max_q_depth = ha->req_q_map[0]->max_q_depth; |
73208dfd | 705 | mutex_unlock(&ha->vport_lock); |
7c3df132 SK |
706 | ql_dbg(ql_dbg_multiq, base_vha, 0xc004, |
707 | "ring_ptr=%p ring_index=%d, " | |
708 | "cnt=%d id=%d max_q_depth=%d.\n", | |
709 | req->ring_ptr, req->ring_index, | |
710 | req->cnt, req->id, req->max_q_depth); | |
711 | ql_dbg(ql_dbg_init, base_vha, 0x00de, | |
712 | "ring_ptr=%p ring_index=%d, " | |
713 | "cnt=%d id=%d max_q_depth=%d.\n", | |
714 | req->ring_ptr, req->ring_index, req->cnt, | |
715 | req->id, req->max_q_depth); | |
73208dfd | 716 | |
618a7523 | 717 | ret = qla25xx_init_req_que(base_vha, req); |
73208dfd | 718 | if (ret != QLA_SUCCESS) { |
7c3df132 SK |
719 | ql_log(ql_log_fatal, base_vha, 0x00df, |
720 | "%s failed.\n", __func__); | |
73208dfd AC |
721 | mutex_lock(&ha->vport_lock); |
722 | clear_bit(que_id, ha->req_qid_map); | |
723 | mutex_unlock(&ha->vport_lock); | |
724 | goto que_failed; | |
725 | } | |
726 | ||
727 | return req->id; | |
728 | ||
729 | que_failed: | |
730 | qla25xx_free_req_que(base_vha, req); | |
c7922a91 | 731 | failed: |
73208dfd AC |
732 | return 0; |
733 | } | |
734 | ||
68ca949c AC |
735 | static void qla_do_work(struct work_struct *work) |
736 | { | |
a67093d4 | 737 | unsigned long flags; |
68ca949c AC |
738 | struct rsp_que *rsp = container_of(work, struct rsp_que, q_work); |
739 | struct scsi_qla_host *vha; | |
a67093d4 | 740 | struct qla_hw_data *ha = rsp->hw; |
68ca949c | 741 | |
a67093d4 AC |
742 | spin_lock_irqsave(&rsp->hw->hardware_lock, flags); |
743 | vha = pci_get_drvdata(ha->pdev); | |
68ca949c | 744 | qla24xx_process_response_queue(vha, rsp); |
a67093d4 | 745 | spin_unlock_irqrestore(&rsp->hw->hardware_lock, flags); |
68ca949c AC |
746 | } |
747 | ||
73208dfd AC |
748 | /* create response queue */ |
749 | int | |
750 | qla25xx_create_rsp_que(struct qla_hw_data *ha, uint16_t options, | |
2afa19a9 | 751 | uint8_t vp_idx, uint16_t rid, int req) |
73208dfd AC |
752 | { |
753 | int ret = 0; | |
754 | struct rsp_que *rsp = NULL; | |
755 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); | |
08029990 AV |
756 | uint16_t que_id = 0; |
757 | device_reg_t __iomem *reg; | |
73208dfd AC |
758 | |
759 | rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL); | |
760 | if (rsp == NULL) { | |
7c3df132 SK |
761 | ql_log(ql_log_warn, base_vha, 0x0066, |
762 | "Failed to allocate memory for response queue.\n"); | |
c7922a91 | 763 | goto failed; |
73208dfd AC |
764 | } |
765 | ||
2afa19a9 | 766 | rsp->length = RESPONSE_ENTRY_CNT_MQ; |
73208dfd AC |
767 | rsp->ring = dma_alloc_coherent(&ha->pdev->dev, |
768 | (rsp->length + 1) * sizeof(response_t), | |
769 | &rsp->dma, GFP_KERNEL); | |
770 | if (rsp->ring == NULL) { | |
7c3df132 SK |
771 | ql_log(ql_log_warn, base_vha, 0x00e1, |
772 | "Failed to allocate memory for response ring.\n"); | |
73208dfd AC |
773 | goto que_failed; |
774 | } | |
775 | ||
776 | mutex_lock(&ha->vport_lock); | |
2afa19a9 AC |
777 | que_id = find_first_zero_bit(ha->rsp_qid_map, ha->max_rsp_queues); |
778 | if (que_id >= ha->max_rsp_queues) { | |
73208dfd | 779 | mutex_unlock(&ha->vport_lock); |
7c3df132 SK |
780 | ql_log(ql_log_warn, base_vha, 0x00e2, |
781 | "No resources to create additional request queue.\n"); | |
73208dfd AC |
782 | goto que_failed; |
783 | } | |
784 | set_bit(que_id, ha->rsp_qid_map); | |
785 | ||
786 | if (ha->flags.msix_enabled) | |
787 | rsp->msix = &ha->msix_entries[que_id + 1]; | |
788 | else | |
7c3df132 SK |
789 | ql_log(ql_log_warn, base_vha, 0x00e3, |
790 | "MSIX not enalbled.\n"); | |
73208dfd AC |
791 | |
792 | ha->rsp_q_map[que_id] = rsp; | |
793 | rsp->rid = rid; | |
794 | rsp->vp_idx = vp_idx; | |
795 | rsp->hw = ha; | |
7c3df132 SK |
796 | ql_dbg(ql_dbg_init, base_vha, 0x00e4, |
797 | "queue_id=%d rid=%d vp_idx=%d hw=%p.\n", | |
798 | que_id, rsp->rid, rsp->vp_idx, rsp->hw); | |
73208dfd AC |
799 | /* Use alternate PCI bus number */ |
800 | if (MSB(rsp->rid)) | |
801 | options |= BIT_4; | |
802 | /* Use alternate PCI devfn */ | |
803 | if (LSB(rsp->rid)) | |
804 | options |= BIT_5; | |
3155754a AC |
805 | /* Enable MSIX handshake mode on for uncapable adapters */ |
806 | if (!IS_MSIX_NACK_CAPABLE(ha)) | |
807 | options |= BIT_6; | |
808 | ||
73208dfd | 809 | rsp->options = options; |
73208dfd | 810 | rsp->id = que_id; |
08029990 AV |
811 | reg = ISP_QUE_REG(ha, que_id); |
812 | rsp->rsp_q_in = ®->isp25mq.rsp_q_in; | |
813 | rsp->rsp_q_out = ®->isp25mq.rsp_q_out; | |
73208dfd | 814 | mutex_unlock(&ha->vport_lock); |
7c3df132 SK |
815 | ql_dbg(ql_dbg_multiq, base_vha, 0xc00b, |
816 | "options=%x id=%d rsp_q_in=%p rsp_q_out=%p", | |
817 | rsp->options, rsp->id, rsp->rsp_q_in, | |
818 | rsp->rsp_q_out); | |
819 | ql_dbg(ql_dbg_init, base_vha, 0x00e5, | |
820 | "options=%x id=%d rsp_q_in=%p rsp_q_out=%p", | |
821 | rsp->options, rsp->id, rsp->rsp_q_in, | |
822 | rsp->rsp_q_out); | |
73208dfd AC |
823 | |
824 | ret = qla25xx_request_irq(rsp); | |
825 | if (ret) | |
826 | goto que_failed; | |
827 | ||
618a7523 | 828 | ret = qla25xx_init_rsp_que(base_vha, rsp); |
73208dfd | 829 | if (ret != QLA_SUCCESS) { |
7c3df132 SK |
830 | ql_log(ql_log_fatal, base_vha, 0x00e7, |
831 | "%s failed.\n", __func__); | |
73208dfd AC |
832 | mutex_lock(&ha->vport_lock); |
833 | clear_bit(que_id, ha->rsp_qid_map); | |
834 | mutex_unlock(&ha->vport_lock); | |
835 | goto que_failed; | |
836 | } | |
2afa19a9 AC |
837 | if (req >= 0) |
838 | rsp->req = ha->req_q_map[req]; | |
839 | else | |
840 | rsp->req = NULL; | |
73208dfd AC |
841 | |
842 | qla2x00_init_response_q_entries(rsp); | |
68ca949c AC |
843 | if (rsp->hw->wq) |
844 | INIT_WORK(&rsp->q_work, qla_do_work); | |
73208dfd AC |
845 | return rsp->id; |
846 | ||
847 | que_failed: | |
848 | qla25xx_free_rsp_que(base_vha, rsp); | |
c7922a91 | 849 | failed: |
73208dfd AC |
850 | return 0; |
851 | } |