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