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