2 * Copyright (C) 2005 - 2010 ServerEngines
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation. The full GNU General
8 * Public License is included in this distribution in the file called COPYING.
10 * Written by: Jayamohan Kallickal (jayamohank@serverengines.com)
12 * Contact Information:
13 * linux-drivers@serverengines.com
16 * 209 N. Fair Oaks Ave
20 #include <linux/reboot.h>
21 #include <linux/delay.h>
22 #include <linux/slab.h>
23 #include <linux/interrupt.h>
24 #include <linux/blkdev.h>
25 #include <linux/pci.h>
26 #include <linux/string.h>
27 #include <linux/kernel.h>
28 #include <linux/semaphore.h>
30 #include <scsi/libiscsi.h>
31 #include <scsi/scsi_transport_iscsi.h>
32 #include <scsi/scsi_transport.h>
33 #include <scsi/scsi_cmnd.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_host.h>
36 #include <scsi/scsi.h>
41 static unsigned int be_iopoll_budget
= 10;
42 static unsigned int be_max_phys_size
= 64;
43 static unsigned int enable_msix
= 1;
45 MODULE_DEVICE_TABLE(pci
, beiscsi_pci_id_table
);
46 MODULE_DESCRIPTION(DRV_DESC
" " BUILD_STR
);
47 MODULE_AUTHOR("ServerEngines Corporation");
48 MODULE_LICENSE("GPL");
49 module_param(be_iopoll_budget
, int, 0);
50 module_param(enable_msix
, int, 0);
51 module_param(be_max_phys_size
, uint
, S_IRUGO
);
52 MODULE_PARM_DESC(be_max_phys_size
, "Maximum Size (In Kilobytes) of physically"
53 "contiguous memory that can be allocated."
56 static int beiscsi_slave_configure(struct scsi_device
*sdev
)
58 blk_queue_max_segment_size(sdev
->request_queue
, 65536);
62 static int beiscsi_eh_abort(struct scsi_cmnd
*sc
)
64 struct iscsi_cls_session
*cls_session
;
65 struct iscsi_task
*aborted_task
= (struct iscsi_task
*)sc
->SCp
.ptr
;
66 struct beiscsi_io_task
*aborted_io_task
;
67 struct iscsi_conn
*conn
;
68 struct beiscsi_conn
*beiscsi_conn
;
69 struct beiscsi_hba
*phba
;
70 struct iscsi_session
*session
;
71 struct invalidate_command_table
*inv_tbl
;
72 unsigned int cid
, tag
, num_invalidate
;
74 cls_session
= starget_to_session(scsi_target(sc
->device
));
75 session
= cls_session
->dd_data
;
77 spin_lock_bh(&session
->lock
);
78 if (!aborted_task
|| !aborted_task
->sc
) {
80 spin_unlock_bh(&session
->lock
);
84 aborted_io_task
= aborted_task
->dd_data
;
85 if (!aborted_io_task
->scsi_cmnd
) {
86 /* raced or invalid command */
87 spin_unlock_bh(&session
->lock
);
90 spin_unlock_bh(&session
->lock
);
91 conn
= aborted_task
->conn
;
92 beiscsi_conn
= conn
->dd_data
;
93 phba
= beiscsi_conn
->phba
;
96 cid
= beiscsi_conn
->beiscsi_conn_cid
;
97 inv_tbl
= phba
->inv_tbl
;
98 memset(inv_tbl
, 0x0, sizeof(*inv_tbl
));
100 inv_tbl
->icd
= aborted_io_task
->psgl_handle
->sgl_index
;
102 tag
= mgmt_invalidate_icds(phba
, inv_tbl
, num_invalidate
, cid
);
104 shost_printk(KERN_WARNING
, phba
->shost
,
105 "mgmt_invalidate_icds could not be"
109 wait_event_interruptible(phba
->ctrl
.mcc_wait
[tag
],
110 phba
->ctrl
.mcc_numtag
[tag
]);
111 free_mcc_tag(&phba
->ctrl
, tag
);
114 return iscsi_eh_abort(sc
);
117 static int beiscsi_eh_device_reset(struct scsi_cmnd
*sc
)
119 struct iscsi_task
*abrt_task
;
120 struct beiscsi_io_task
*abrt_io_task
;
121 struct iscsi_conn
*conn
;
122 struct beiscsi_conn
*beiscsi_conn
;
123 struct beiscsi_hba
*phba
;
124 struct iscsi_session
*session
;
125 struct iscsi_cls_session
*cls_session
;
126 struct invalidate_command_table
*inv_tbl
;
127 unsigned int cid
, tag
, i
, num_invalidate
;
130 /* invalidate iocbs */
131 cls_session
= starget_to_session(scsi_target(sc
->device
));
132 session
= cls_session
->dd_data
;
133 spin_lock_bh(&session
->lock
);
134 if (!session
->leadconn
|| session
->state
!= ISCSI_STATE_LOGGED_IN
)
137 conn
= session
->leadconn
;
138 beiscsi_conn
= conn
->dd_data
;
139 phba
= beiscsi_conn
->phba
;
140 cid
= beiscsi_conn
->beiscsi_conn_cid
;
141 inv_tbl
= phba
->inv_tbl
;
142 memset(inv_tbl
, 0x0, sizeof(*inv_tbl
) * BE2_CMDS_PER_CXN
);
144 for (i
= 0; i
< conn
->session
->cmds_max
; i
++) {
145 abrt_task
= conn
->session
->cmds
[i
];
146 abrt_io_task
= abrt_task
->dd_data
;
147 if (!abrt_task
->sc
|| abrt_task
->state
== ISCSI_TASK_FREE
)
150 if (abrt_task
->sc
->device
->lun
!= abrt_task
->sc
->device
->lun
)
154 inv_tbl
->icd
= abrt_io_task
->psgl_handle
->sgl_index
;
158 spin_unlock_bh(&session
->lock
);
159 inv_tbl
= phba
->inv_tbl
;
161 tag
= mgmt_invalidate_icds(phba
, inv_tbl
, num_invalidate
, cid
);
163 shost_printk(KERN_WARNING
, phba
->shost
,
164 "mgmt_invalidate_icds could not be"
168 wait_event_interruptible(phba
->ctrl
.mcc_wait
[tag
],
169 phba
->ctrl
.mcc_numtag
[tag
]);
170 free_mcc_tag(&phba
->ctrl
, tag
);
173 return iscsi_eh_device_reset(sc
);
175 spin_unlock_bh(&session
->lock
);
179 /*------------------- PCI Driver operations and data ----------------- */
180 static DEFINE_PCI_DEVICE_TABLE(beiscsi_pci_id_table
) = {
181 { PCI_DEVICE(BE_VENDOR_ID
, BE_DEVICE_ID1
) },
182 { PCI_DEVICE(BE_VENDOR_ID
, BE_DEVICE_ID2
) },
183 { PCI_DEVICE(BE_VENDOR_ID
, OC_DEVICE_ID1
) },
184 { PCI_DEVICE(BE_VENDOR_ID
, OC_DEVICE_ID2
) },
185 { PCI_DEVICE(BE_VENDOR_ID
, OC_DEVICE_ID3
) },
188 MODULE_DEVICE_TABLE(pci
, beiscsi_pci_id_table
);
190 static struct scsi_host_template beiscsi_sht
= {
191 .module
= THIS_MODULE
,
192 .name
= "ServerEngines 10Gbe open-iscsi Initiator Driver",
193 .proc_name
= DRV_NAME
,
194 .queuecommand
= iscsi_queuecommand
,
195 .change_queue_depth
= iscsi_change_queue_depth
,
196 .slave_configure
= beiscsi_slave_configure
,
197 .target_alloc
= iscsi_target_alloc
,
198 .eh_abort_handler
= beiscsi_eh_abort
,
199 .eh_device_reset_handler
= beiscsi_eh_device_reset
,
200 .eh_target_reset_handler
= iscsi_eh_session_reset
,
201 .sg_tablesize
= BEISCSI_SGLIST_ELEMENTS
,
202 .can_queue
= BE2_IO_DEPTH
,
204 .max_sectors
= BEISCSI_MAX_SECTORS
,
205 .cmd_per_lun
= BEISCSI_CMD_PER_LUN
,
206 .use_clustering
= ENABLE_CLUSTERING
,
209 static struct scsi_transport_template
*beiscsi_scsi_transport
;
211 static struct beiscsi_hba
*beiscsi_hba_alloc(struct pci_dev
*pcidev
)
213 struct beiscsi_hba
*phba
;
214 struct Scsi_Host
*shost
;
216 shost
= iscsi_host_alloc(&beiscsi_sht
, sizeof(*phba
), 0);
218 dev_err(&pcidev
->dev
, "beiscsi_hba_alloc -"
219 "iscsi_host_alloc failed \n");
222 shost
->dma_boundary
= pcidev
->dma_mask
;
223 shost
->max_id
= BE2_MAX_SESSIONS
;
224 shost
->max_channel
= 0;
225 shost
->max_cmd_len
= BEISCSI_MAX_CMD_LEN
;
226 shost
->max_lun
= BEISCSI_NUM_MAX_LUN
;
227 shost
->transportt
= beiscsi_scsi_transport
;
228 phba
= iscsi_host_priv(shost
);
229 memset(phba
, 0, sizeof(*phba
));
231 phba
->pcidev
= pci_dev_get(pcidev
);
232 pci_set_drvdata(pcidev
, phba
);
234 if (iscsi_host_add(shost
, &phba
->pcidev
->dev
))
239 pci_dev_put(phba
->pcidev
);
240 iscsi_host_free(phba
->shost
);
244 static void beiscsi_unmap_pci_function(struct beiscsi_hba
*phba
)
247 iounmap(phba
->csr_va
);
251 iounmap(phba
->db_va
);
255 iounmap(phba
->pci_va
);
260 static int beiscsi_map_pci_bars(struct beiscsi_hba
*phba
,
261 struct pci_dev
*pcidev
)
266 addr
= ioremap_nocache(pci_resource_start(pcidev
, 2),
267 pci_resource_len(pcidev
, 2));
270 phba
->ctrl
.csr
= addr
;
272 phba
->csr_pa
.u
.a64
.address
= pci_resource_start(pcidev
, 2);
274 addr
= ioremap_nocache(pci_resource_start(pcidev
, 4), 128 * 1024);
277 phba
->ctrl
.db
= addr
;
279 phba
->db_pa
.u
.a64
.address
= pci_resource_start(pcidev
, 4);
281 if (phba
->generation
== BE_GEN2
)
286 addr
= ioremap_nocache(pci_resource_start(pcidev
, pcicfg_reg
),
287 pci_resource_len(pcidev
, pcicfg_reg
));
291 phba
->ctrl
.pcicfg
= addr
;
293 phba
->pci_pa
.u
.a64
.address
= pci_resource_start(pcidev
, pcicfg_reg
);
297 beiscsi_unmap_pci_function(phba
);
301 static int beiscsi_enable_pci(struct pci_dev
*pcidev
)
305 ret
= pci_enable_device(pcidev
);
307 dev_err(&pcidev
->dev
, "beiscsi_enable_pci - enable device "
308 "failed. Returning -ENODEV\n");
312 pci_set_master(pcidev
);
313 if (pci_set_consistent_dma_mask(pcidev
, DMA_BIT_MASK(64))) {
314 ret
= pci_set_consistent_dma_mask(pcidev
, DMA_BIT_MASK(32));
316 dev_err(&pcidev
->dev
, "Could not set PCI DMA Mask\n");
317 pci_disable_device(pcidev
);
324 static int be_ctrl_init(struct beiscsi_hba
*phba
, struct pci_dev
*pdev
)
326 struct be_ctrl_info
*ctrl
= &phba
->ctrl
;
327 struct be_dma_mem
*mbox_mem_alloc
= &ctrl
->mbox_mem_alloced
;
328 struct be_dma_mem
*mbox_mem_align
= &ctrl
->mbox_mem
;
332 status
= beiscsi_map_pci_bars(phba
, pdev
);
335 mbox_mem_alloc
->size
= sizeof(struct be_mcc_mailbox
) + 16;
336 mbox_mem_alloc
->va
= pci_alloc_consistent(pdev
,
337 mbox_mem_alloc
->size
,
338 &mbox_mem_alloc
->dma
);
339 if (!mbox_mem_alloc
->va
) {
340 beiscsi_unmap_pci_function(phba
);
345 mbox_mem_align
->size
= sizeof(struct be_mcc_mailbox
);
346 mbox_mem_align
->va
= PTR_ALIGN(mbox_mem_alloc
->va
, 16);
347 mbox_mem_align
->dma
= PTR_ALIGN(mbox_mem_alloc
->dma
, 16);
348 memset(mbox_mem_align
->va
, 0, sizeof(struct be_mcc_mailbox
));
349 spin_lock_init(&ctrl
->mbox_lock
);
350 spin_lock_init(&phba
->ctrl
.mcc_lock
);
351 spin_lock_init(&phba
->ctrl
.mcc_cq_lock
);
356 static void beiscsi_get_params(struct beiscsi_hba
*phba
)
358 phba
->params
.ios_per_ctrl
= (phba
->fw_config
.iscsi_icd_count
359 - (phba
->fw_config
.iscsi_cid_count
362 phba
->params
.cxns_per_ctrl
= phba
->fw_config
.iscsi_cid_count
;
363 phba
->params
.asyncpdus_per_ctrl
= phba
->fw_config
.iscsi_cid_count
* 2;
364 phba
->params
.icds_per_ctrl
= phba
->fw_config
.iscsi_icd_count
;;
365 phba
->params
.num_sge_per_io
= BE2_SGE
;
366 phba
->params
.defpdu_hdr_sz
= BE2_DEFPDU_HDR_SZ
;
367 phba
->params
.defpdu_data_sz
= BE2_DEFPDU_DATA_SZ
;
368 phba
->params
.eq_timer
= 64;
369 phba
->params
.num_eq_entries
=
370 (((BE2_CMDS_PER_CXN
* 2 + phba
->fw_config
.iscsi_cid_count
* 2
371 + BE2_TMFS
) / 512) + 1) * 512;
372 phba
->params
.num_eq_entries
= (phba
->params
.num_eq_entries
< 1024)
373 ? 1024 : phba
->params
.num_eq_entries
;
374 SE_DEBUG(DBG_LVL_8
, "phba->params.num_eq_entries=%d \n",
375 phba
->params
.num_eq_entries
);
376 phba
->params
.num_cq_entries
=
377 (((BE2_CMDS_PER_CXN
* 2 + phba
->fw_config
.iscsi_cid_count
* 2
378 + BE2_TMFS
) / 512) + 1) * 512;
379 phba
->params
.wrbs_per_cxn
= 256;
382 static void hwi_ring_eq_db(struct beiscsi_hba
*phba
,
383 unsigned int id
, unsigned int clr_interrupt
,
384 unsigned int num_processed
,
385 unsigned char rearm
, unsigned char event
)
388 val
|= id
& DB_EQ_RING_ID_MASK
;
390 val
|= 1 << DB_EQ_REARM_SHIFT
;
392 val
|= 1 << DB_EQ_CLR_SHIFT
;
394 val
|= 1 << DB_EQ_EVNT_SHIFT
;
395 val
|= num_processed
<< DB_EQ_NUM_POPPED_SHIFT
;
396 iowrite32(val
, phba
->db_va
+ DB_EQ_OFFSET
);
400 * be_isr_mcc - The isr routine of the driver.
402 * @dev_id: Pointer to host adapter structure
404 static irqreturn_t
be_isr_mcc(int irq
, void *dev_id
)
406 struct beiscsi_hba
*phba
;
407 struct be_eq_entry
*eqe
= NULL
;
408 struct be_queue_info
*eq
;
409 struct be_queue_info
*mcc
;
410 unsigned int num_eq_processed
;
411 struct be_eq_obj
*pbe_eq
;
417 mcc
= &phba
->ctrl
.mcc_obj
.cq
;
418 eqe
= queue_tail_node(eq
);
420 SE_DEBUG(DBG_LVL_1
, "eqe is NULL\n");
422 num_eq_processed
= 0;
424 while (eqe
->dw
[offsetof(struct amap_eq_entry
, valid
) / 32]
426 if (((eqe
->dw
[offsetof(struct amap_eq_entry
,
428 EQE_RESID_MASK
) >> 16) == mcc
->id
) {
429 spin_lock_irqsave(&phba
->isr_lock
, flags
);
430 phba
->todo_mcc_cq
= 1;
431 spin_unlock_irqrestore(&phba
->isr_lock
, flags
);
433 AMAP_SET_BITS(struct amap_eq_entry
, valid
, eqe
, 0);
435 eqe
= queue_tail_node(eq
);
438 if (phba
->todo_mcc_cq
)
439 queue_work(phba
->wq
, &phba
->work_cqs
);
440 if (num_eq_processed
)
441 hwi_ring_eq_db(phba
, eq
->id
, 1, num_eq_processed
, 1, 1);
447 * be_isr_msix - The isr routine of the driver.
449 * @dev_id: Pointer to host adapter structure
451 static irqreturn_t
be_isr_msix(int irq
, void *dev_id
)
453 struct beiscsi_hba
*phba
;
454 struct be_eq_entry
*eqe
= NULL
;
455 struct be_queue_info
*eq
;
456 struct be_queue_info
*cq
;
457 unsigned int num_eq_processed
;
458 struct be_eq_obj
*pbe_eq
;
464 eqe
= queue_tail_node(eq
);
466 SE_DEBUG(DBG_LVL_1
, "eqe is NULL\n");
469 num_eq_processed
= 0;
470 if (blk_iopoll_enabled
) {
471 while (eqe
->dw
[offsetof(struct amap_eq_entry
, valid
) / 32]
473 if (!blk_iopoll_sched_prep(&pbe_eq
->iopoll
))
474 blk_iopoll_sched(&pbe_eq
->iopoll
);
476 AMAP_SET_BITS(struct amap_eq_entry
, valid
, eqe
, 0);
478 eqe
= queue_tail_node(eq
);
481 if (num_eq_processed
)
482 hwi_ring_eq_db(phba
, eq
->id
, 1, num_eq_processed
, 0, 1);
486 while (eqe
->dw
[offsetof(struct amap_eq_entry
, valid
) / 32]
488 spin_lock_irqsave(&phba
->isr_lock
, flags
);
490 spin_unlock_irqrestore(&phba
->isr_lock
, flags
);
491 AMAP_SET_BITS(struct amap_eq_entry
, valid
, eqe
, 0);
493 eqe
= queue_tail_node(eq
);
497 queue_work(phba
->wq
, &phba
->work_cqs
);
499 if (num_eq_processed
)
500 hwi_ring_eq_db(phba
, eq
->id
, 1, num_eq_processed
, 1, 1);
507 * be_isr - The isr routine of the driver.
509 * @dev_id: Pointer to host adapter structure
511 static irqreturn_t
be_isr(int irq
, void *dev_id
)
513 struct beiscsi_hba
*phba
;
514 struct hwi_controller
*phwi_ctrlr
;
515 struct hwi_context_memory
*phwi_context
;
516 struct be_eq_entry
*eqe
= NULL
;
517 struct be_queue_info
*eq
;
518 struct be_queue_info
*cq
;
519 struct be_queue_info
*mcc
;
520 unsigned long flags
, index
;
521 unsigned int num_mcceq_processed
, num_ioeq_processed
;
522 struct be_ctrl_info
*ctrl
;
523 struct be_eq_obj
*pbe_eq
;
528 isr
= ioread32(ctrl
->csr
+ CEV_ISR0_OFFSET
+
529 (PCI_FUNC(ctrl
->pdev
->devfn
) * CEV_ISR_SIZE
));
533 phwi_ctrlr
= phba
->phwi_ctrlr
;
534 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
535 pbe_eq
= &phwi_context
->be_eq
[0];
537 eq
= &phwi_context
->be_eq
[0].q
;
538 mcc
= &phba
->ctrl
.mcc_obj
.cq
;
540 eqe
= queue_tail_node(eq
);
542 SE_DEBUG(DBG_LVL_1
, "eqe is NULL\n");
544 num_ioeq_processed
= 0;
545 num_mcceq_processed
= 0;
546 if (blk_iopoll_enabled
) {
547 while (eqe
->dw
[offsetof(struct amap_eq_entry
, valid
) / 32]
549 if (((eqe
->dw
[offsetof(struct amap_eq_entry
,
551 EQE_RESID_MASK
) >> 16) == mcc
->id
) {
552 spin_lock_irqsave(&phba
->isr_lock
, flags
);
553 phba
->todo_mcc_cq
= 1;
554 spin_unlock_irqrestore(&phba
->isr_lock
, flags
);
555 num_mcceq_processed
++;
557 if (!blk_iopoll_sched_prep(&pbe_eq
->iopoll
))
558 blk_iopoll_sched(&pbe_eq
->iopoll
);
559 num_ioeq_processed
++;
561 AMAP_SET_BITS(struct amap_eq_entry
, valid
, eqe
, 0);
563 eqe
= queue_tail_node(eq
);
565 if (num_ioeq_processed
|| num_mcceq_processed
) {
566 if (phba
->todo_mcc_cq
)
567 queue_work(phba
->wq
, &phba
->work_cqs
);
569 if ((num_mcceq_processed
) && (!num_ioeq_processed
))
570 hwi_ring_eq_db(phba
, eq
->id
, 0,
571 (num_ioeq_processed
+
572 num_mcceq_processed
) , 1, 1);
574 hwi_ring_eq_db(phba
, eq
->id
, 0,
575 (num_ioeq_processed
+
576 num_mcceq_processed
), 0, 1);
582 cq
= &phwi_context
->be_cq
[0];
583 while (eqe
->dw
[offsetof(struct amap_eq_entry
, valid
) / 32]
586 if (((eqe
->dw
[offsetof(struct amap_eq_entry
,
588 EQE_RESID_MASK
) >> 16) != cq
->id
) {
589 spin_lock_irqsave(&phba
->isr_lock
, flags
);
590 phba
->todo_mcc_cq
= 1;
591 spin_unlock_irqrestore(&phba
->isr_lock
, flags
);
593 spin_lock_irqsave(&phba
->isr_lock
, flags
);
595 spin_unlock_irqrestore(&phba
->isr_lock
, flags
);
597 AMAP_SET_BITS(struct amap_eq_entry
, valid
, eqe
, 0);
599 eqe
= queue_tail_node(eq
);
600 num_ioeq_processed
++;
602 if (phba
->todo_cq
|| phba
->todo_mcc_cq
)
603 queue_work(phba
->wq
, &phba
->work_cqs
);
605 if (num_ioeq_processed
) {
606 hwi_ring_eq_db(phba
, eq
->id
, 0,
607 num_ioeq_processed
, 1, 1);
614 static int beiscsi_init_irqs(struct beiscsi_hba
*phba
)
616 struct pci_dev
*pcidev
= phba
->pcidev
;
617 struct hwi_controller
*phwi_ctrlr
;
618 struct hwi_context_memory
*phwi_context
;
619 int ret
, msix_vec
, i
= 0;
622 phwi_ctrlr
= phba
->phwi_ctrlr
;
623 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
625 if (phba
->msix_enabled
) {
626 for (i
= 0; i
< phba
->num_cpus
; i
++) {
627 sprintf(desc
, "beiscsi_msix_%04x", i
);
628 msix_vec
= phba
->msix_entries
[i
].vector
;
629 ret
= request_irq(msix_vec
, be_isr_msix
, 0, desc
,
630 &phwi_context
->be_eq
[i
]);
632 msix_vec
= phba
->msix_entries
[i
].vector
;
633 ret
= request_irq(msix_vec
, be_isr_mcc
, 0, "beiscsi_msix_mcc",
634 &phwi_context
->be_eq
[i
]);
636 ret
= request_irq(pcidev
->irq
, be_isr
, IRQF_SHARED
,
639 shost_printk(KERN_ERR
, phba
->shost
, "beiscsi_init_irqs-"
640 "Failed to register irq\\n");
647 static void hwi_ring_cq_db(struct beiscsi_hba
*phba
,
648 unsigned int id
, unsigned int num_processed
,
649 unsigned char rearm
, unsigned char event
)
652 val
|= id
& DB_CQ_RING_ID_MASK
;
654 val
|= 1 << DB_CQ_REARM_SHIFT
;
655 val
|= num_processed
<< DB_CQ_NUM_POPPED_SHIFT
;
656 iowrite32(val
, phba
->db_va
+ DB_CQ_OFFSET
);
660 beiscsi_process_async_pdu(struct beiscsi_conn
*beiscsi_conn
,
661 struct beiscsi_hba
*phba
,
663 struct pdu_base
*ppdu
,
664 unsigned long pdu_len
,
665 void *pbuffer
, unsigned long buf_len
)
667 struct iscsi_conn
*conn
= beiscsi_conn
->conn
;
668 struct iscsi_session
*session
= conn
->session
;
669 struct iscsi_task
*task
;
670 struct beiscsi_io_task
*io_task
;
671 struct iscsi_hdr
*login_hdr
;
673 switch (ppdu
->dw
[offsetof(struct amap_pdu_base
, opcode
) / 32] &
674 PDUBASE_OPCODE_MASK
) {
675 case ISCSI_OP_NOOP_IN
:
679 case ISCSI_OP_ASYNC_EVENT
:
681 case ISCSI_OP_REJECT
:
683 WARN_ON(!(buf_len
== 48));
684 SE_DEBUG(DBG_LVL_1
, "In ISCSI_OP_REJECT\n");
686 case ISCSI_OP_LOGIN_RSP
:
687 case ISCSI_OP_TEXT_RSP
:
688 task
= conn
->login_task
;
689 io_task
= task
->dd_data
;
690 login_hdr
= (struct iscsi_hdr
*)ppdu
;
691 login_hdr
->itt
= io_task
->libiscsi_itt
;
694 shost_printk(KERN_WARNING
, phba
->shost
,
695 "Unrecognized opcode 0x%x in async msg \n",
697 dw
[offsetof(struct amap_pdu_base
, opcode
) / 32]
698 & PDUBASE_OPCODE_MASK
));
702 spin_lock_bh(&session
->lock
);
703 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)ppdu
, pbuffer
, buf_len
);
704 spin_unlock_bh(&session
->lock
);
708 static struct sgl_handle
*alloc_io_sgl_handle(struct beiscsi_hba
*phba
)
710 struct sgl_handle
*psgl_handle
;
712 if (phba
->io_sgl_hndl_avbl
) {
714 "In alloc_io_sgl_handle,io_sgl_alloc_index=%d \n",
715 phba
->io_sgl_alloc_index
);
716 psgl_handle
= phba
->io_sgl_hndl_base
[phba
->
718 phba
->io_sgl_hndl_base
[phba
->io_sgl_alloc_index
] = NULL
;
719 phba
->io_sgl_hndl_avbl
--;
720 if (phba
->io_sgl_alloc_index
== (phba
->params
.
722 phba
->io_sgl_alloc_index
= 0;
724 phba
->io_sgl_alloc_index
++;
731 free_io_sgl_handle(struct beiscsi_hba
*phba
, struct sgl_handle
*psgl_handle
)
733 SE_DEBUG(DBG_LVL_8
, "In free_,io_sgl_free_index=%d \n",
734 phba
->io_sgl_free_index
);
735 if (phba
->io_sgl_hndl_base
[phba
->io_sgl_free_index
]) {
737 * this can happen if clean_task is called on a task that
738 * failed in xmit_task or alloc_pdu.
741 "Double Free in IO SGL io_sgl_free_index=%d,"
742 "value there=%p \n", phba
->io_sgl_free_index
,
743 phba
->io_sgl_hndl_base
[phba
->io_sgl_free_index
]);
746 phba
->io_sgl_hndl_base
[phba
->io_sgl_free_index
] = psgl_handle
;
747 phba
->io_sgl_hndl_avbl
++;
748 if (phba
->io_sgl_free_index
== (phba
->params
.ios_per_ctrl
- 1))
749 phba
->io_sgl_free_index
= 0;
751 phba
->io_sgl_free_index
++;
755 * alloc_wrb_handle - To allocate a wrb handle
756 * @phba: The hba pointer
757 * @cid: The cid to use for allocation
759 * This happens under session_lock until submission to chip
761 struct wrb_handle
*alloc_wrb_handle(struct beiscsi_hba
*phba
, unsigned int cid
)
763 struct hwi_wrb_context
*pwrb_context
;
764 struct hwi_controller
*phwi_ctrlr
;
765 struct wrb_handle
*pwrb_handle
, *pwrb_handle_tmp
;
767 phwi_ctrlr
= phba
->phwi_ctrlr
;
768 pwrb_context
= &phwi_ctrlr
->wrb_context
[cid
];
769 if (pwrb_context
->wrb_handles_available
>= 2) {
770 pwrb_handle
= pwrb_context
->pwrb_handle_base
[
771 pwrb_context
->alloc_index
];
772 pwrb_context
->wrb_handles_available
--;
773 if (pwrb_context
->alloc_index
==
774 (phba
->params
.wrbs_per_cxn
- 1))
775 pwrb_context
->alloc_index
= 0;
777 pwrb_context
->alloc_index
++;
778 pwrb_handle_tmp
= pwrb_context
->pwrb_handle_base
[
779 pwrb_context
->alloc_index
];
780 pwrb_handle
->nxt_wrb_index
= pwrb_handle_tmp
->wrb_index
;
787 * free_wrb_handle - To free the wrb handle back to pool
788 * @phba: The hba pointer
789 * @pwrb_context: The context to free from
790 * @pwrb_handle: The wrb_handle to free
792 * This happens under session_lock until submission to chip
795 free_wrb_handle(struct beiscsi_hba
*phba
, struct hwi_wrb_context
*pwrb_context
,
796 struct wrb_handle
*pwrb_handle
)
798 pwrb_context
->pwrb_handle_base
[pwrb_context
->free_index
] = pwrb_handle
;
799 pwrb_context
->wrb_handles_available
++;
800 if (pwrb_context
->free_index
== (phba
->params
.wrbs_per_cxn
- 1))
801 pwrb_context
->free_index
= 0;
803 pwrb_context
->free_index
++;
806 "FREE WRB: pwrb_handle=%p free_index=0x%x"
807 "wrb_handles_available=%d \n",
808 pwrb_handle
, pwrb_context
->free_index
,
809 pwrb_context
->wrb_handles_available
);
812 static struct sgl_handle
*alloc_mgmt_sgl_handle(struct beiscsi_hba
*phba
)
814 struct sgl_handle
*psgl_handle
;
816 if (phba
->eh_sgl_hndl_avbl
) {
817 psgl_handle
= phba
->eh_sgl_hndl_base
[phba
->eh_sgl_alloc_index
];
818 phba
->eh_sgl_hndl_base
[phba
->eh_sgl_alloc_index
] = NULL
;
819 SE_DEBUG(DBG_LVL_8
, "mgmt_sgl_alloc_index=%d=0x%x \n",
820 phba
->eh_sgl_alloc_index
, phba
->eh_sgl_alloc_index
);
821 phba
->eh_sgl_hndl_avbl
--;
822 if (phba
->eh_sgl_alloc_index
==
823 (phba
->params
.icds_per_ctrl
- phba
->params
.ios_per_ctrl
-
825 phba
->eh_sgl_alloc_index
= 0;
827 phba
->eh_sgl_alloc_index
++;
834 free_mgmt_sgl_handle(struct beiscsi_hba
*phba
, struct sgl_handle
*psgl_handle
)
837 SE_DEBUG(DBG_LVL_8
, "In free_mgmt_sgl_handle,eh_sgl_free_index=%d \n",
838 phba
->eh_sgl_free_index
);
839 if (phba
->eh_sgl_hndl_base
[phba
->eh_sgl_free_index
]) {
841 * this can happen if clean_task is called on a task that
842 * failed in xmit_task or alloc_pdu.
845 "Double Free in eh SGL ,eh_sgl_free_index=%d \n",
846 phba
->eh_sgl_free_index
);
849 phba
->eh_sgl_hndl_base
[phba
->eh_sgl_free_index
] = psgl_handle
;
850 phba
->eh_sgl_hndl_avbl
++;
851 if (phba
->eh_sgl_free_index
==
852 (phba
->params
.icds_per_ctrl
- phba
->params
.ios_per_ctrl
- 1))
853 phba
->eh_sgl_free_index
= 0;
855 phba
->eh_sgl_free_index
++;
859 be_complete_io(struct beiscsi_conn
*beiscsi_conn
,
860 struct iscsi_task
*task
, struct sol_cqe
*psol
)
862 struct beiscsi_io_task
*io_task
= task
->dd_data
;
863 struct be_status_bhs
*sts_bhs
=
864 (struct be_status_bhs
*)io_task
->cmd_bhs
;
865 struct iscsi_conn
*conn
= beiscsi_conn
->conn
;
866 unsigned int sense_len
;
867 unsigned char *sense
;
868 u32 resid
= 0, exp_cmdsn
, max_cmdsn
;
869 u8 rsp
, status
, flags
;
872 dw
[offsetof(struct amap_sol_cqe
, i_exp_cmd_sn
) / 32]
873 & SOL_EXP_CMD_SN_MASK
);
875 dw
[offsetof(struct amap_sol_cqe
, i_exp_cmd_sn
) / 32]
876 & SOL_EXP_CMD_SN_MASK
) +
877 ((psol
->dw
[offsetof(struct amap_sol_cqe
, i_cmd_wnd
)
878 / 32] & SOL_CMD_WND_MASK
) >> 24) - 1);
879 rsp
= ((psol
->dw
[offsetof(struct amap_sol_cqe
, i_resp
) / 32]
880 & SOL_RESP_MASK
) >> 16);
881 status
= ((psol
->dw
[offsetof(struct amap_sol_cqe
, i_sts
) / 32]
882 & SOL_STS_MASK
) >> 8);
883 flags
= ((psol
->dw
[offsetof(struct amap_sol_cqe
, i_flags
) / 32]
884 & SOL_FLAGS_MASK
) >> 24) | 0x80;
886 task
->sc
->result
= (DID_OK
<< 16) | status
;
887 if (rsp
!= ISCSI_STATUS_CMD_COMPLETED
) {
888 task
->sc
->result
= DID_ERROR
<< 16;
892 /* bidi not initially supported */
893 if (flags
& (ISCSI_FLAG_CMD_UNDERFLOW
| ISCSI_FLAG_CMD_OVERFLOW
)) {
894 resid
= (psol
->dw
[offsetof(struct amap_sol_cqe
, i_res_cnt
) /
895 32] & SOL_RES_CNT_MASK
);
897 if (!status
&& (flags
& ISCSI_FLAG_CMD_OVERFLOW
))
898 task
->sc
->result
= DID_ERROR
<< 16;
900 if (flags
& ISCSI_FLAG_CMD_UNDERFLOW
) {
901 scsi_set_resid(task
->sc
, resid
);
902 if (!status
&& (scsi_bufflen(task
->sc
) - resid
<
903 task
->sc
->underflow
))
904 task
->sc
->result
= DID_ERROR
<< 16;
908 if (status
== SAM_STAT_CHECK_CONDITION
) {
909 unsigned short *slen
= (unsigned short *)sts_bhs
->sense_info
;
910 sense
= sts_bhs
->sense_info
+ sizeof(unsigned short);
911 sense_len
= cpu_to_be16(*slen
);
912 memcpy(task
->sc
->sense_buffer
, sense
,
913 min_t(u16
, sense_len
, SCSI_SENSE_BUFFERSIZE
));
916 if (io_task
->cmd_bhs
->iscsi_hdr
.flags
& ISCSI_FLAG_CMD_READ
) {
917 if (psol
->dw
[offsetof(struct amap_sol_cqe
, i_res_cnt
) / 32]
919 conn
->rxdata_octets
+= (psol
->
920 dw
[offsetof(struct amap_sol_cqe
, i_res_cnt
) / 32]
924 scsi_dma_unmap(io_task
->scsi_cmnd
);
925 iscsi_complete_scsi_task(task
, exp_cmdsn
, max_cmdsn
);
929 be_complete_logout(struct beiscsi_conn
*beiscsi_conn
,
930 struct iscsi_task
*task
, struct sol_cqe
*psol
)
932 struct iscsi_logout_rsp
*hdr
;
933 struct beiscsi_io_task
*io_task
= task
->dd_data
;
934 struct iscsi_conn
*conn
= beiscsi_conn
->conn
;
936 hdr
= (struct iscsi_logout_rsp
*)task
->hdr
;
937 hdr
->opcode
= ISCSI_OP_LOGOUT_RSP
;
940 hdr
->flags
= ((psol
->dw
[offsetof(struct amap_sol_cqe
, i_flags
) / 32]
941 & SOL_FLAGS_MASK
) >> 24) | 0x80;
942 hdr
->response
= (psol
->dw
[offsetof(struct amap_sol_cqe
, i_resp
) /
943 32] & SOL_RESP_MASK
);
944 hdr
->exp_cmdsn
= cpu_to_be32(psol
->
945 dw
[offsetof(struct amap_sol_cqe
, i_exp_cmd_sn
) / 32]
946 & SOL_EXP_CMD_SN_MASK
);
947 hdr
->max_cmdsn
= be32_to_cpu((psol
->
948 dw
[offsetof(struct amap_sol_cqe
, i_exp_cmd_sn
) / 32]
949 & SOL_EXP_CMD_SN_MASK
) +
950 ((psol
->dw
[offsetof(struct amap_sol_cqe
, i_cmd_wnd
)
951 / 32] & SOL_CMD_WND_MASK
) >> 24) - 1);
956 hdr
->itt
= io_task
->libiscsi_itt
;
957 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)hdr
, NULL
, 0);
961 be_complete_tmf(struct beiscsi_conn
*beiscsi_conn
,
962 struct iscsi_task
*task
, struct sol_cqe
*psol
)
964 struct iscsi_tm_rsp
*hdr
;
965 struct iscsi_conn
*conn
= beiscsi_conn
->conn
;
966 struct beiscsi_io_task
*io_task
= task
->dd_data
;
968 hdr
= (struct iscsi_tm_rsp
*)task
->hdr
;
969 hdr
->opcode
= ISCSI_OP_SCSI_TMFUNC_RSP
;
970 hdr
->flags
= ((psol
->dw
[offsetof(struct amap_sol_cqe
, i_flags
) / 32]
971 & SOL_FLAGS_MASK
) >> 24) | 0x80;
972 hdr
->response
= (psol
->dw
[offsetof(struct amap_sol_cqe
, i_resp
) /
973 32] & SOL_RESP_MASK
);
974 hdr
->exp_cmdsn
= cpu_to_be32(psol
->dw
[offsetof(struct amap_sol_cqe
,
975 i_exp_cmd_sn
) / 32] & SOL_EXP_CMD_SN_MASK
);
976 hdr
->max_cmdsn
= be32_to_cpu((psol
->dw
[offsetof(struct amap_sol_cqe
,
977 i_exp_cmd_sn
) / 32] & SOL_EXP_CMD_SN_MASK
) +
978 ((psol
->dw
[offsetof(struct amap_sol_cqe
, i_cmd_wnd
)
979 / 32] & SOL_CMD_WND_MASK
) >> 24) - 1);
980 hdr
->itt
= io_task
->libiscsi_itt
;
981 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)hdr
, NULL
, 0);
985 hwi_complete_drvr_msgs(struct beiscsi_conn
*beiscsi_conn
,
986 struct beiscsi_hba
*phba
, struct sol_cqe
*psol
)
988 struct hwi_wrb_context
*pwrb_context
;
989 struct wrb_handle
*pwrb_handle
= NULL
;
990 struct hwi_controller
*phwi_ctrlr
;
991 struct iscsi_task
*task
;
992 struct beiscsi_io_task
*io_task
;
993 struct iscsi_conn
*conn
= beiscsi_conn
->conn
;
994 struct iscsi_session
*session
= conn
->session
;
996 phwi_ctrlr
= phba
->phwi_ctrlr
;
997 pwrb_context
= &phwi_ctrlr
->wrb_context
[((psol
->
998 dw
[offsetof(struct amap_sol_cqe
, cid
) / 32] &
999 SOL_CID_MASK
) >> 6) -
1000 phba
->fw_config
.iscsi_cid_start
];
1001 pwrb_handle
= pwrb_context
->pwrb_handle_basestd
[((psol
->
1002 dw
[offsetof(struct amap_sol_cqe
, wrb_index
) /
1003 32] & SOL_WRB_INDEX_MASK
) >> 16)];
1004 task
= pwrb_handle
->pio_handle
;
1006 io_task
= task
->dd_data
;
1007 spin_lock(&phba
->mgmt_sgl_lock
);
1008 free_mgmt_sgl_handle(phba
, io_task
->psgl_handle
);
1009 spin_unlock(&phba
->mgmt_sgl_lock
);
1010 spin_lock_bh(&session
->lock
);
1011 free_wrb_handle(phba
, pwrb_context
, pwrb_handle
);
1012 spin_unlock_bh(&session
->lock
);
1016 be_complete_nopin_resp(struct beiscsi_conn
*beiscsi_conn
,
1017 struct iscsi_task
*task
, struct sol_cqe
*psol
)
1019 struct iscsi_nopin
*hdr
;
1020 struct iscsi_conn
*conn
= beiscsi_conn
->conn
;
1021 struct beiscsi_io_task
*io_task
= task
->dd_data
;
1023 hdr
= (struct iscsi_nopin
*)task
->hdr
;
1024 hdr
->flags
= ((psol
->dw
[offsetof(struct amap_sol_cqe
, i_flags
) / 32]
1025 & SOL_FLAGS_MASK
) >> 24) | 0x80;
1026 hdr
->exp_cmdsn
= cpu_to_be32(psol
->dw
[offsetof(struct amap_sol_cqe
,
1027 i_exp_cmd_sn
) / 32] & SOL_EXP_CMD_SN_MASK
);
1028 hdr
->max_cmdsn
= be32_to_cpu((psol
->dw
[offsetof(struct amap_sol_cqe
,
1029 i_exp_cmd_sn
) / 32] & SOL_EXP_CMD_SN_MASK
) +
1030 ((psol
->dw
[offsetof(struct amap_sol_cqe
, i_cmd_wnd
)
1031 / 32] & SOL_CMD_WND_MASK
) >> 24) - 1);
1032 hdr
->opcode
= ISCSI_OP_NOOP_IN
;
1033 hdr
->itt
= io_task
->libiscsi_itt
;
1034 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)hdr
, NULL
, 0);
1037 static void hwi_complete_cmd(struct beiscsi_conn
*beiscsi_conn
,
1038 struct beiscsi_hba
*phba
, struct sol_cqe
*psol
)
1040 struct hwi_wrb_context
*pwrb_context
;
1041 struct wrb_handle
*pwrb_handle
;
1042 struct iscsi_wrb
*pwrb
= NULL
;
1043 struct hwi_controller
*phwi_ctrlr
;
1044 struct iscsi_task
*task
;
1046 struct iscsi_conn
*conn
= beiscsi_conn
->conn
;
1047 struct iscsi_session
*session
= conn
->session
;
1049 phwi_ctrlr
= phba
->phwi_ctrlr
;
1050 pwrb_context
= &phwi_ctrlr
->wrb_context
[((psol
->dw
[offsetof
1051 (struct amap_sol_cqe
, cid
) / 32]
1052 & SOL_CID_MASK
) >> 6) -
1053 phba
->fw_config
.iscsi_cid_start
];
1054 pwrb_handle
= pwrb_context
->pwrb_handle_basestd
[((psol
->
1055 dw
[offsetof(struct amap_sol_cqe
, wrb_index
) /
1056 32] & SOL_WRB_INDEX_MASK
) >> 16)];
1057 task
= pwrb_handle
->pio_handle
;
1058 pwrb
= pwrb_handle
->pwrb
;
1059 type
= (pwrb
->dw
[offsetof(struct amap_iscsi_wrb
, type
) / 32] &
1060 WRB_TYPE_MASK
) >> 28;
1062 spin_lock_bh(&session
->lock
);
1065 case HWH_TYPE_IO_RD
:
1066 if ((task
->hdr
->opcode
& ISCSI_OPCODE_MASK
) ==
1068 be_complete_nopin_resp(beiscsi_conn
, task
, psol
);
1070 be_complete_io(beiscsi_conn
, task
, psol
);
1073 case HWH_TYPE_LOGOUT
:
1074 if ((task
->hdr
->opcode
& ISCSI_OPCODE_MASK
) == ISCSI_OP_LOGOUT
)
1075 be_complete_logout(beiscsi_conn
, task
, psol
);
1077 be_complete_tmf(beiscsi_conn
, task
, psol
);
1081 case HWH_TYPE_LOGIN
:
1083 "\t\t No HWH_TYPE_LOGIN Expected in hwi_complete_cmd"
1084 "- Solicited path \n");
1088 be_complete_nopin_resp(beiscsi_conn
, task
, psol
);
1092 shost_printk(KERN_WARNING
, phba
->shost
,
1093 "In hwi_complete_cmd, unknown type = %d"
1094 "wrb_index 0x%x CID 0x%x\n", type
,
1095 ((psol
->dw
[offsetof(struct amap_iscsi_wrb
,
1096 type
) / 32] & SOL_WRB_INDEX_MASK
) >> 16),
1097 ((psol
->dw
[offsetof(struct amap_sol_cqe
,
1098 cid
) / 32] & SOL_CID_MASK
) >> 6));
1102 spin_unlock_bh(&session
->lock
);
1105 static struct list_head
*hwi_get_async_busy_list(struct hwi_async_pdu_context
1106 *pasync_ctx
, unsigned int is_header
,
1107 unsigned int host_write_ptr
)
1110 return &pasync_ctx
->async_entry
[host_write_ptr
].
1113 return &pasync_ctx
->async_entry
[host_write_ptr
].data_busy_list
;
1116 static struct async_pdu_handle
*
1117 hwi_get_async_handle(struct beiscsi_hba
*phba
,
1118 struct beiscsi_conn
*beiscsi_conn
,
1119 struct hwi_async_pdu_context
*pasync_ctx
,
1120 struct i_t_dpdu_cqe
*pdpdu_cqe
, unsigned int *pcq_index
)
1122 struct be_bus_address phys_addr
;
1123 struct list_head
*pbusy_list
;
1124 struct async_pdu_handle
*pasync_handle
= NULL
;
1126 unsigned char buffer_index
= -1;
1127 unsigned char is_header
= 0;
1129 phys_addr
.u
.a32
.address_lo
=
1130 pdpdu_cqe
->dw
[offsetof(struct amap_i_t_dpdu_cqe
, db_addr_lo
) / 32] -
1131 ((pdpdu_cqe
->dw
[offsetof(struct amap_i_t_dpdu_cqe
, dpl
) / 32]
1132 & PDUCQE_DPL_MASK
) >> 16);
1133 phys_addr
.u
.a32
.address_hi
=
1134 pdpdu_cqe
->dw
[offsetof(struct amap_i_t_dpdu_cqe
, db_addr_hi
) / 32];
1136 phys_addr
.u
.a64
.address
=
1137 *((unsigned long long *)(&phys_addr
.u
.a64
.address
));
1139 switch (pdpdu_cqe
->dw
[offsetof(struct amap_i_t_dpdu_cqe
, code
) / 32]
1140 & PDUCQE_CODE_MASK
) {
1141 case UNSOL_HDR_NOTIFY
:
1144 pbusy_list
= hwi_get_async_busy_list(pasync_ctx
, 1,
1145 (pdpdu_cqe
->dw
[offsetof(struct amap_i_t_dpdu_cqe
,
1146 index
) / 32] & PDUCQE_INDEX_MASK
));
1148 buffer_len
= (unsigned int)(phys_addr
.u
.a64
.address
-
1149 pasync_ctx
->async_header
.pa_base
.u
.a64
.address
);
1151 buffer_index
= buffer_len
/
1152 pasync_ctx
->async_header
.buffer_size
;
1155 case UNSOL_DATA_NOTIFY
:
1156 pbusy_list
= hwi_get_async_busy_list(pasync_ctx
, 0, (pdpdu_cqe
->
1157 dw
[offsetof(struct amap_i_t_dpdu_cqe
,
1158 index
) / 32] & PDUCQE_INDEX_MASK
));
1159 buffer_len
= (unsigned long)(phys_addr
.u
.a64
.address
-
1160 pasync_ctx
->async_data
.pa_base
.u
.
1162 buffer_index
= buffer_len
/ pasync_ctx
->async_data
.buffer_size
;
1166 shost_printk(KERN_WARNING
, phba
->shost
,
1167 "Unexpected code=%d \n",
1168 pdpdu_cqe
->dw
[offsetof(struct amap_i_t_dpdu_cqe
,
1169 code
) / 32] & PDUCQE_CODE_MASK
);
1173 WARN_ON(!(buffer_index
<= pasync_ctx
->async_data
.num_entries
));
1174 WARN_ON(list_empty(pbusy_list
));
1175 list_for_each_entry(pasync_handle
, pbusy_list
, link
) {
1176 WARN_ON(pasync_handle
->consumed
);
1177 if (pasync_handle
->index
== buffer_index
)
1181 WARN_ON(!pasync_handle
);
1183 pasync_handle
->cri
= (unsigned short)beiscsi_conn
->beiscsi_conn_cid
-
1184 phba
->fw_config
.iscsi_cid_start
;
1185 pasync_handle
->is_header
= is_header
;
1186 pasync_handle
->buffer_len
= ((pdpdu_cqe
->
1187 dw
[offsetof(struct amap_i_t_dpdu_cqe
, dpl
) / 32]
1188 & PDUCQE_DPL_MASK
) >> 16);
1190 *pcq_index
= (pdpdu_cqe
->dw
[offsetof(struct amap_i_t_dpdu_cqe
,
1191 index
) / 32] & PDUCQE_INDEX_MASK
);
1192 return pasync_handle
;
1196 hwi_update_async_writables(struct hwi_async_pdu_context
*pasync_ctx
,
1197 unsigned int is_header
, unsigned int cq_index
)
1199 struct list_head
*pbusy_list
;
1200 struct async_pdu_handle
*pasync_handle
;
1201 unsigned int num_entries
, writables
= 0;
1202 unsigned int *pep_read_ptr
, *pwritables
;
1206 pep_read_ptr
= &pasync_ctx
->async_header
.ep_read_ptr
;
1207 pwritables
= &pasync_ctx
->async_header
.writables
;
1208 num_entries
= pasync_ctx
->async_header
.num_entries
;
1210 pep_read_ptr
= &pasync_ctx
->async_data
.ep_read_ptr
;
1211 pwritables
= &pasync_ctx
->async_data
.writables
;
1212 num_entries
= pasync_ctx
->async_data
.num_entries
;
1215 while ((*pep_read_ptr
) != cq_index
) {
1217 *pep_read_ptr
= (*pep_read_ptr
) % num_entries
;
1219 pbusy_list
= hwi_get_async_busy_list(pasync_ctx
, is_header
,
1222 WARN_ON(list_empty(pbusy_list
));
1224 if (!list_empty(pbusy_list
)) {
1225 pasync_handle
= list_entry(pbusy_list
->next
,
1226 struct async_pdu_handle
,
1228 WARN_ON(!pasync_handle
);
1229 pasync_handle
->consumed
= 1;
1237 "Duplicate notification received - index 0x%x!!\n",
1242 *pwritables
= *pwritables
+ writables
;
1246 static unsigned int hwi_free_async_msg(struct beiscsi_hba
*phba
,
1249 struct hwi_controller
*phwi_ctrlr
;
1250 struct hwi_async_pdu_context
*pasync_ctx
;
1251 struct async_pdu_handle
*pasync_handle
, *tmp_handle
;
1252 struct list_head
*plist
;
1255 phwi_ctrlr
= phba
->phwi_ctrlr
;
1256 pasync_ctx
= HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr
);
1258 plist
= &pasync_ctx
->async_entry
[cri
].wait_queue
.list
;
1260 list_for_each_entry_safe(pasync_handle
, tmp_handle
, plist
, link
) {
1261 list_del(&pasync_handle
->link
);
1264 list_add_tail(&pasync_handle
->link
,
1265 &pasync_ctx
->async_header
.free_list
);
1266 pasync_ctx
->async_header
.free_entries
++;
1269 list_add_tail(&pasync_handle
->link
,
1270 &pasync_ctx
->async_data
.free_list
);
1271 pasync_ctx
->async_data
.free_entries
++;
1276 INIT_LIST_HEAD(&pasync_ctx
->async_entry
[cri
].wait_queue
.list
);
1277 pasync_ctx
->async_entry
[cri
].wait_queue
.hdr_received
= 0;
1278 pasync_ctx
->async_entry
[cri
].wait_queue
.bytes_received
= 0;
1282 static struct phys_addr
*
1283 hwi_get_ring_address(struct hwi_async_pdu_context
*pasync_ctx
,
1284 unsigned int is_header
, unsigned int host_write_ptr
)
1286 struct phys_addr
*pasync_sge
= NULL
;
1289 pasync_sge
= pasync_ctx
->async_header
.ring_base
;
1291 pasync_sge
= pasync_ctx
->async_data
.ring_base
;
1293 return pasync_sge
+ host_write_ptr
;
1296 static void hwi_post_async_buffers(struct beiscsi_hba
*phba
,
1297 unsigned int is_header
)
1299 struct hwi_controller
*phwi_ctrlr
;
1300 struct hwi_async_pdu_context
*pasync_ctx
;
1301 struct async_pdu_handle
*pasync_handle
;
1302 struct list_head
*pfree_link
, *pbusy_list
;
1303 struct phys_addr
*pasync_sge
;
1304 unsigned int ring_id
, num_entries
;
1305 unsigned int host_write_num
;
1306 unsigned int writables
;
1310 phwi_ctrlr
= phba
->phwi_ctrlr
;
1311 pasync_ctx
= HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr
);
1314 num_entries
= pasync_ctx
->async_header
.num_entries
;
1315 writables
= min(pasync_ctx
->async_header
.writables
,
1316 pasync_ctx
->async_header
.free_entries
);
1317 pfree_link
= pasync_ctx
->async_header
.free_list
.next
;
1318 host_write_num
= pasync_ctx
->async_header
.host_write_ptr
;
1319 ring_id
= phwi_ctrlr
->default_pdu_hdr
.id
;
1321 num_entries
= pasync_ctx
->async_data
.num_entries
;
1322 writables
= min(pasync_ctx
->async_data
.writables
,
1323 pasync_ctx
->async_data
.free_entries
);
1324 pfree_link
= pasync_ctx
->async_data
.free_list
.next
;
1325 host_write_num
= pasync_ctx
->async_data
.host_write_ptr
;
1326 ring_id
= phwi_ctrlr
->default_pdu_data
.id
;
1329 writables
= (writables
/ 8) * 8;
1331 for (i
= 0; i
< writables
; i
++) {
1333 hwi_get_async_busy_list(pasync_ctx
, is_header
,
1336 list_entry(pfree_link
, struct async_pdu_handle
,
1338 WARN_ON(!pasync_handle
);
1339 pasync_handle
->consumed
= 0;
1341 pfree_link
= pfree_link
->next
;
1343 pasync_sge
= hwi_get_ring_address(pasync_ctx
,
1344 is_header
, host_write_num
);
1346 pasync_sge
->hi
= pasync_handle
->pa
.u
.a32
.address_lo
;
1347 pasync_sge
->lo
= pasync_handle
->pa
.u
.a32
.address_hi
;
1349 list_move(&pasync_handle
->link
, pbusy_list
);
1352 host_write_num
= host_write_num
% num_entries
;
1356 pasync_ctx
->async_header
.host_write_ptr
=
1358 pasync_ctx
->async_header
.free_entries
-= writables
;
1359 pasync_ctx
->async_header
.writables
-= writables
;
1360 pasync_ctx
->async_header
.busy_entries
+= writables
;
1362 pasync_ctx
->async_data
.host_write_ptr
= host_write_num
;
1363 pasync_ctx
->async_data
.free_entries
-= writables
;
1364 pasync_ctx
->async_data
.writables
-= writables
;
1365 pasync_ctx
->async_data
.busy_entries
+= writables
;
1368 doorbell
|= ring_id
& DB_DEF_PDU_RING_ID_MASK
;
1369 doorbell
|= 1 << DB_DEF_PDU_REARM_SHIFT
;
1370 doorbell
|= 0 << DB_DEF_PDU_EVENT_SHIFT
;
1371 doorbell
|= (writables
& DB_DEF_PDU_CQPROC_MASK
)
1372 << DB_DEF_PDU_CQPROC_SHIFT
;
1374 iowrite32(doorbell
, phba
->db_va
+ DB_RXULP0_OFFSET
);
1378 static void hwi_flush_default_pdu_buffer(struct beiscsi_hba
*phba
,
1379 struct beiscsi_conn
*beiscsi_conn
,
1380 struct i_t_dpdu_cqe
*pdpdu_cqe
)
1382 struct hwi_controller
*phwi_ctrlr
;
1383 struct hwi_async_pdu_context
*pasync_ctx
;
1384 struct async_pdu_handle
*pasync_handle
= NULL
;
1385 unsigned int cq_index
= -1;
1387 phwi_ctrlr
= phba
->phwi_ctrlr
;
1388 pasync_ctx
= HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr
);
1390 pasync_handle
= hwi_get_async_handle(phba
, beiscsi_conn
, pasync_ctx
,
1391 pdpdu_cqe
, &cq_index
);
1392 BUG_ON(pasync_handle
->is_header
!= 0);
1393 if (pasync_handle
->consumed
== 0)
1394 hwi_update_async_writables(pasync_ctx
, pasync_handle
->is_header
,
1397 hwi_free_async_msg(phba
, pasync_handle
->cri
);
1398 hwi_post_async_buffers(phba
, pasync_handle
->is_header
);
1402 hwi_fwd_async_msg(struct beiscsi_conn
*beiscsi_conn
,
1403 struct beiscsi_hba
*phba
,
1404 struct hwi_async_pdu_context
*pasync_ctx
, unsigned short cri
)
1406 struct list_head
*plist
;
1407 struct async_pdu_handle
*pasync_handle
;
1409 unsigned int hdr_len
= 0, buf_len
= 0;
1410 unsigned int status
, index
= 0, offset
= 0;
1411 void *pfirst_buffer
= NULL
;
1412 unsigned int num_buf
= 0;
1414 plist
= &pasync_ctx
->async_entry
[cri
].wait_queue
.list
;
1416 list_for_each_entry(pasync_handle
, plist
, link
) {
1418 phdr
= pasync_handle
->pbuffer
;
1419 hdr_len
= pasync_handle
->buffer_len
;
1421 buf_len
= pasync_handle
->buffer_len
;
1423 pfirst_buffer
= pasync_handle
->pbuffer
;
1426 memcpy(pfirst_buffer
+ offset
,
1427 pasync_handle
->pbuffer
, buf_len
);
1433 status
= beiscsi_process_async_pdu(beiscsi_conn
, phba
,
1434 (beiscsi_conn
->beiscsi_conn_cid
-
1435 phba
->fw_config
.iscsi_cid_start
),
1436 phdr
, hdr_len
, pfirst_buffer
,
1440 hwi_free_async_msg(phba
, cri
);
1445 hwi_gather_async_pdu(struct beiscsi_conn
*beiscsi_conn
,
1446 struct beiscsi_hba
*phba
,
1447 struct async_pdu_handle
*pasync_handle
)
1449 struct hwi_async_pdu_context
*pasync_ctx
;
1450 struct hwi_controller
*phwi_ctrlr
;
1451 unsigned int bytes_needed
= 0, status
= 0;
1452 unsigned short cri
= pasync_handle
->cri
;
1453 struct pdu_base
*ppdu
;
1455 phwi_ctrlr
= phba
->phwi_ctrlr
;
1456 pasync_ctx
= HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr
);
1458 list_del(&pasync_handle
->link
);
1459 if (pasync_handle
->is_header
) {
1460 pasync_ctx
->async_header
.busy_entries
--;
1461 if (pasync_ctx
->async_entry
[cri
].wait_queue
.hdr_received
) {
1462 hwi_free_async_msg(phba
, cri
);
1466 pasync_ctx
->async_entry
[cri
].wait_queue
.bytes_received
= 0;
1467 pasync_ctx
->async_entry
[cri
].wait_queue
.hdr_received
= 1;
1468 pasync_ctx
->async_entry
[cri
].wait_queue
.hdr_len
=
1469 (unsigned short)pasync_handle
->buffer_len
;
1470 list_add_tail(&pasync_handle
->link
,
1471 &pasync_ctx
->async_entry
[cri
].wait_queue
.list
);
1473 ppdu
= pasync_handle
->pbuffer
;
1474 bytes_needed
= ((((ppdu
->dw
[offsetof(struct amap_pdu_base
,
1475 data_len_hi
) / 32] & PDUBASE_DATALENHI_MASK
) << 8) &
1476 0xFFFF0000) | ((be16_to_cpu((ppdu
->
1477 dw
[offsetof(struct amap_pdu_base
, data_len_lo
) / 32]
1478 & PDUBASE_DATALENLO_MASK
) >> 16)) & 0x0000FFFF));
1481 pasync_ctx
->async_entry
[cri
].wait_queue
.bytes_needed
=
1484 if (bytes_needed
== 0)
1485 status
= hwi_fwd_async_msg(beiscsi_conn
, phba
,
1489 pasync_ctx
->async_data
.busy_entries
--;
1490 if (pasync_ctx
->async_entry
[cri
].wait_queue
.hdr_received
) {
1491 list_add_tail(&pasync_handle
->link
,
1492 &pasync_ctx
->async_entry
[cri
].wait_queue
.
1494 pasync_ctx
->async_entry
[cri
].wait_queue
.
1496 (unsigned short)pasync_handle
->buffer_len
;
1498 if (pasync_ctx
->async_entry
[cri
].wait_queue
.
1500 pasync_ctx
->async_entry
[cri
].wait_queue
.
1502 status
= hwi_fwd_async_msg(beiscsi_conn
, phba
,
1509 static void hwi_process_default_pdu_ring(struct beiscsi_conn
*beiscsi_conn
,
1510 struct beiscsi_hba
*phba
,
1511 struct i_t_dpdu_cqe
*pdpdu_cqe
)
1513 struct hwi_controller
*phwi_ctrlr
;
1514 struct hwi_async_pdu_context
*pasync_ctx
;
1515 struct async_pdu_handle
*pasync_handle
= NULL
;
1516 unsigned int cq_index
= -1;
1518 phwi_ctrlr
= phba
->phwi_ctrlr
;
1519 pasync_ctx
= HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr
);
1520 pasync_handle
= hwi_get_async_handle(phba
, beiscsi_conn
, pasync_ctx
,
1521 pdpdu_cqe
, &cq_index
);
1523 if (pasync_handle
->consumed
== 0)
1524 hwi_update_async_writables(pasync_ctx
, pasync_handle
->is_header
,
1526 hwi_gather_async_pdu(beiscsi_conn
, phba
, pasync_handle
);
1527 hwi_post_async_buffers(phba
, pasync_handle
->is_header
);
1530 static void beiscsi_process_mcc_isr(struct beiscsi_hba
*phba
)
1532 struct be_queue_info
*mcc_cq
;
1533 struct be_mcc_compl
*mcc_compl
;
1534 unsigned int num_processed
= 0;
1536 mcc_cq
= &phba
->ctrl
.mcc_obj
.cq
;
1537 mcc_compl
= queue_tail_node(mcc_cq
);
1538 mcc_compl
->flags
= le32_to_cpu(mcc_compl
->flags
);
1539 while (mcc_compl
->flags
& CQE_FLAGS_VALID_MASK
) {
1541 if (num_processed
>= 32) {
1542 hwi_ring_cq_db(phba
, mcc_cq
->id
,
1543 num_processed
, 0, 0);
1546 if (mcc_compl
->flags
& CQE_FLAGS_ASYNC_MASK
) {
1547 /* Interpret flags as an async trailer */
1548 if (is_link_state_evt(mcc_compl
->flags
))
1549 /* Interpret compl as a async link evt */
1550 beiscsi_async_link_state_process(phba
,
1551 (struct be_async_event_link_state
*) mcc_compl
);
1554 " Unsupported Async Event, flags"
1555 " = 0x%08x \n", mcc_compl
->flags
);
1556 } else if (mcc_compl
->flags
& CQE_FLAGS_COMPLETED_MASK
) {
1557 be_mcc_compl_process_isr(&phba
->ctrl
, mcc_compl
);
1558 atomic_dec(&phba
->ctrl
.mcc_obj
.q
.used
);
1561 mcc_compl
->flags
= 0;
1562 queue_tail_inc(mcc_cq
);
1563 mcc_compl
= queue_tail_node(mcc_cq
);
1564 mcc_compl
->flags
= le32_to_cpu(mcc_compl
->flags
);
1568 if (num_processed
> 0)
1569 hwi_ring_cq_db(phba
, mcc_cq
->id
, num_processed
, 1, 0);
1573 static unsigned int beiscsi_process_cq(struct be_eq_obj
*pbe_eq
)
1575 struct be_queue_info
*cq
;
1576 struct sol_cqe
*sol
;
1577 struct dmsg_cqe
*dmsg
;
1578 unsigned int num_processed
= 0;
1579 unsigned int tot_nump
= 0;
1580 struct beiscsi_conn
*beiscsi_conn
;
1581 struct beiscsi_endpoint
*beiscsi_ep
;
1582 struct iscsi_endpoint
*ep
;
1583 struct beiscsi_hba
*phba
;
1586 sol
= queue_tail_node(cq
);
1587 phba
= pbe_eq
->phba
;
1589 while (sol
->dw
[offsetof(struct amap_sol_cqe
, valid
) / 32] &
1591 be_dws_le_to_cpu(sol
, sizeof(struct sol_cqe
));
1593 ep
= phba
->ep_array
[(u32
) ((sol
->
1594 dw
[offsetof(struct amap_sol_cqe
, cid
) / 32] &
1595 SOL_CID_MASK
) >> 6) -
1596 phba
->fw_config
.iscsi_cid_start
];
1598 beiscsi_ep
= ep
->dd_data
;
1599 beiscsi_conn
= beiscsi_ep
->conn
;
1601 if (num_processed
>= 32) {
1602 hwi_ring_cq_db(phba
, cq
->id
,
1603 num_processed
, 0, 0);
1604 tot_nump
+= num_processed
;
1608 switch ((u32
) sol
->dw
[offsetof(struct amap_sol_cqe
, code
) /
1609 32] & CQE_CODE_MASK
) {
1610 case SOL_CMD_COMPLETE
:
1611 hwi_complete_cmd(beiscsi_conn
, phba
, sol
);
1613 case DRIVERMSG_NOTIFY
:
1614 SE_DEBUG(DBG_LVL_8
, "Received DRIVERMSG_NOTIFY \n");
1615 dmsg
= (struct dmsg_cqe
*)sol
;
1616 hwi_complete_drvr_msgs(beiscsi_conn
, phba
, sol
);
1618 case UNSOL_HDR_NOTIFY
:
1619 SE_DEBUG(DBG_LVL_8
, "Received UNSOL_HDR_ NOTIFY\n");
1620 hwi_process_default_pdu_ring(beiscsi_conn
, phba
,
1621 (struct i_t_dpdu_cqe
*)sol
);
1623 case UNSOL_DATA_NOTIFY
:
1624 SE_DEBUG(DBG_LVL_8
, "Received UNSOL_DATA_NOTIFY\n");
1625 hwi_process_default_pdu_ring(beiscsi_conn
, phba
,
1626 (struct i_t_dpdu_cqe
*)sol
);
1628 case CXN_INVALIDATE_INDEX_NOTIFY
:
1629 case CMD_INVALIDATED_NOTIFY
:
1630 case CXN_INVALIDATE_NOTIFY
:
1632 "Ignoring CQ Error notification for cmd/cxn"
1635 case SOL_CMD_KILLED_DATA_DIGEST_ERR
:
1636 case CMD_KILLED_INVALID_STATSN_RCVD
:
1637 case CMD_KILLED_INVALID_R2T_RCVD
:
1638 case CMD_CXN_KILLED_LUN_INVALID
:
1639 case CMD_CXN_KILLED_ICD_INVALID
:
1640 case CMD_CXN_KILLED_ITT_INVALID
:
1641 case CMD_CXN_KILLED_SEQ_OUTOFORDER
:
1642 case CMD_CXN_KILLED_INVALID_DATASN_RCVD
:
1644 "CQ Error notification for cmd.. "
1645 "code %d cid 0x%x\n",
1646 sol
->dw
[offsetof(struct amap_sol_cqe
, code
) /
1647 32] & CQE_CODE_MASK
,
1648 (sol
->dw
[offsetof(struct amap_sol_cqe
, cid
) /
1649 32] & SOL_CID_MASK
));
1651 case UNSOL_DATA_DIGEST_ERROR_NOTIFY
:
1653 "Digest error on def pdu ring, dropping..\n");
1654 hwi_flush_default_pdu_buffer(phba
, beiscsi_conn
,
1655 (struct i_t_dpdu_cqe
*) sol
);
1657 case CXN_KILLED_PDU_SIZE_EXCEEDS_DSL
:
1658 case CXN_KILLED_BURST_LEN_MISMATCH
:
1659 case CXN_KILLED_AHS_RCVD
:
1660 case CXN_KILLED_HDR_DIGEST_ERR
:
1661 case CXN_KILLED_UNKNOWN_HDR
:
1662 case CXN_KILLED_STALE_ITT_TTT_RCVD
:
1663 case CXN_KILLED_INVALID_ITT_TTT_RCVD
:
1664 case CXN_KILLED_TIMED_OUT
:
1665 case CXN_KILLED_FIN_RCVD
:
1666 case CXN_KILLED_BAD_UNSOL_PDU_RCVD
:
1667 case CXN_KILLED_BAD_WRB_INDEX_ERROR
:
1668 case CXN_KILLED_OVER_RUN_RESIDUAL
:
1669 case CXN_KILLED_UNDER_RUN_RESIDUAL
:
1670 case CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN
:
1671 SE_DEBUG(DBG_LVL_1
, "CQ Error %d, reset CID "
1673 sol
->dw
[offsetof(struct amap_sol_cqe
, code
) /
1674 32] & CQE_CODE_MASK
,
1675 (sol
->dw
[offsetof(struct amap_sol_cqe
, cid
) /
1676 32] & CQE_CID_MASK
));
1677 iscsi_conn_failure(beiscsi_conn
->conn
,
1678 ISCSI_ERR_CONN_FAILED
);
1680 case CXN_KILLED_RST_SENT
:
1681 case CXN_KILLED_RST_RCVD
:
1682 SE_DEBUG(DBG_LVL_1
, "CQ Error %d, reset"
1683 "received/sent on CID 0x%x...\n",
1684 sol
->dw
[offsetof(struct amap_sol_cqe
, code
) /
1685 32] & CQE_CODE_MASK
,
1686 (sol
->dw
[offsetof(struct amap_sol_cqe
, cid
) /
1687 32] & CQE_CID_MASK
));
1688 iscsi_conn_failure(beiscsi_conn
->conn
,
1689 ISCSI_ERR_CONN_FAILED
);
1692 SE_DEBUG(DBG_LVL_1
, "CQ Error Invalid code= %d "
1693 "received on CID 0x%x...\n",
1694 sol
->dw
[offsetof(struct amap_sol_cqe
, code
) /
1695 32] & CQE_CODE_MASK
,
1696 (sol
->dw
[offsetof(struct amap_sol_cqe
, cid
) /
1697 32] & CQE_CID_MASK
));
1701 AMAP_SET_BITS(struct amap_sol_cqe
, valid
, sol
, 0);
1703 sol
= queue_tail_node(cq
);
1707 if (num_processed
> 0) {
1708 tot_nump
+= num_processed
;
1709 hwi_ring_cq_db(phba
, cq
->id
, num_processed
, 1, 0);
1714 void beiscsi_process_all_cqs(struct work_struct
*work
)
1716 unsigned long flags
;
1717 struct hwi_controller
*phwi_ctrlr
;
1718 struct hwi_context_memory
*phwi_context
;
1719 struct be_eq_obj
*pbe_eq
;
1720 struct beiscsi_hba
*phba
=
1721 container_of(work
, struct beiscsi_hba
, work_cqs
);
1723 phwi_ctrlr
= phba
->phwi_ctrlr
;
1724 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
1725 if (phba
->msix_enabled
)
1726 pbe_eq
= &phwi_context
->be_eq
[phba
->num_cpus
];
1728 pbe_eq
= &phwi_context
->be_eq
[0];
1730 if (phba
->todo_mcc_cq
) {
1731 spin_lock_irqsave(&phba
->isr_lock
, flags
);
1732 phba
->todo_mcc_cq
= 0;
1733 spin_unlock_irqrestore(&phba
->isr_lock
, flags
);
1734 beiscsi_process_mcc_isr(phba
);
1737 if (phba
->todo_cq
) {
1738 spin_lock_irqsave(&phba
->isr_lock
, flags
);
1740 spin_unlock_irqrestore(&phba
->isr_lock
, flags
);
1741 beiscsi_process_cq(pbe_eq
);
1745 static int be_iopoll(struct blk_iopoll
*iop
, int budget
)
1747 static unsigned int ret
;
1748 struct beiscsi_hba
*phba
;
1749 struct be_eq_obj
*pbe_eq
;
1751 pbe_eq
= container_of(iop
, struct be_eq_obj
, iopoll
);
1752 ret
= beiscsi_process_cq(pbe_eq
);
1754 phba
= pbe_eq
->phba
;
1755 blk_iopoll_complete(iop
);
1756 SE_DEBUG(DBG_LVL_8
, "rearm pbe_eq->q.id =%d\n", pbe_eq
->q
.id
);
1757 hwi_ring_eq_db(phba
, pbe_eq
->q
.id
, 0, 0, 1, 1);
1763 hwi_write_sgl(struct iscsi_wrb
*pwrb
, struct scatterlist
*sg
,
1764 unsigned int num_sg
, struct beiscsi_io_task
*io_task
)
1766 struct iscsi_sge
*psgl
;
1767 unsigned short sg_len
, index
;
1768 unsigned int sge_len
= 0;
1769 unsigned long long addr
;
1770 struct scatterlist
*l_sg
;
1771 unsigned int offset
;
1773 AMAP_SET_BITS(struct amap_iscsi_wrb
, iscsi_bhs_addr_lo
, pwrb
,
1774 io_task
->bhs_pa
.u
.a32
.address_lo
);
1775 AMAP_SET_BITS(struct amap_iscsi_wrb
, iscsi_bhs_addr_hi
, pwrb
,
1776 io_task
->bhs_pa
.u
.a32
.address_hi
);
1779 for (index
= 0; (index
< num_sg
) && (index
< 2); index
++,
1782 sg_len
= sg_dma_len(sg
);
1783 addr
= (u64
) sg_dma_address(sg
);
1784 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_addr_lo
, pwrb
,
1785 (addr
& 0xFFFFFFFF));
1786 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_addr_hi
, pwrb
,
1788 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_len
, pwrb
,
1792 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge1_r2t_offset
,
1794 sg_len
= sg_dma_len(sg
);
1795 addr
= (u64
) sg_dma_address(sg
);
1796 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge1_addr_lo
, pwrb
,
1797 (addr
& 0xFFFFFFFF));
1798 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge1_addr_hi
, pwrb
,
1800 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge1_len
, pwrb
,
1804 psgl
= (struct iscsi_sge
*)io_task
->psgl_handle
->pfrag
;
1805 memset(psgl
, 0, sizeof(*psgl
) * BE2_SGE
);
1807 AMAP_SET_BITS(struct amap_iscsi_sge
, len
, psgl
, io_task
->bhs_len
- 2);
1809 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_hi
, psgl
,
1810 io_task
->bhs_pa
.u
.a32
.address_hi
);
1811 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_lo
, psgl
,
1812 io_task
->bhs_pa
.u
.a32
.address_lo
);
1815 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_last
, pwrb
,
1817 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge1_last
, pwrb
,
1819 } else if (num_sg
== 2) {
1820 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_last
, pwrb
,
1822 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge1_last
, pwrb
,
1825 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_last
, pwrb
,
1827 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge1_last
, pwrb
,
1834 for (index
= 0; index
< num_sg
; index
++, sg
= sg_next(sg
), psgl
++) {
1835 sg_len
= sg_dma_len(sg
);
1836 addr
= (u64
) sg_dma_address(sg
);
1837 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_lo
, psgl
,
1838 (addr
& 0xFFFFFFFF));
1839 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_hi
, psgl
,
1841 AMAP_SET_BITS(struct amap_iscsi_sge
, len
, psgl
, sg_len
);
1842 AMAP_SET_BITS(struct amap_iscsi_sge
, sge_offset
, psgl
, offset
);
1843 AMAP_SET_BITS(struct amap_iscsi_sge
, last_sge
, psgl
, 0);
1847 AMAP_SET_BITS(struct amap_iscsi_sge
, last_sge
, psgl
, 1);
1850 static void hwi_write_buffer(struct iscsi_wrb
*pwrb
, struct iscsi_task
*task
)
1852 struct iscsi_sge
*psgl
;
1853 unsigned long long addr
;
1854 struct beiscsi_io_task
*io_task
= task
->dd_data
;
1855 struct beiscsi_conn
*beiscsi_conn
= io_task
->conn
;
1856 struct beiscsi_hba
*phba
= beiscsi_conn
->phba
;
1858 io_task
->bhs_len
= sizeof(struct be_nonio_bhs
) - 2;
1859 AMAP_SET_BITS(struct amap_iscsi_wrb
, iscsi_bhs_addr_lo
, pwrb
,
1860 io_task
->bhs_pa
.u
.a32
.address_lo
);
1861 AMAP_SET_BITS(struct amap_iscsi_wrb
, iscsi_bhs_addr_hi
, pwrb
,
1862 io_task
->bhs_pa
.u
.a32
.address_hi
);
1865 if (task
->data_count
) {
1866 AMAP_SET_BITS(struct amap_iscsi_wrb
, dsp
, pwrb
, 1);
1867 addr
= (u64
) pci_map_single(phba
->pcidev
,
1869 task
->data_count
, 1);
1871 AMAP_SET_BITS(struct amap_iscsi_wrb
, dsp
, pwrb
, 0);
1874 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_addr_lo
, pwrb
,
1875 (addr
& 0xFFFFFFFF));
1876 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_addr_hi
, pwrb
,
1878 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_len
, pwrb
,
1881 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_last
, pwrb
, 1);
1883 AMAP_SET_BITS(struct amap_iscsi_wrb
, dsp
, pwrb
, 0);
1887 psgl
= (struct iscsi_sge
*)io_task
->psgl_handle
->pfrag
;
1889 AMAP_SET_BITS(struct amap_iscsi_sge
, len
, psgl
, io_task
->bhs_len
);
1891 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_hi
, psgl
,
1892 io_task
->bhs_pa
.u
.a32
.address_hi
);
1893 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_lo
, psgl
,
1894 io_task
->bhs_pa
.u
.a32
.address_lo
);
1897 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_hi
, psgl
, 0);
1898 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_lo
, psgl
, 0);
1899 AMAP_SET_BITS(struct amap_iscsi_sge
, len
, psgl
, 0);
1900 AMAP_SET_BITS(struct amap_iscsi_sge
, sge_offset
, psgl
, 0);
1901 AMAP_SET_BITS(struct amap_iscsi_sge
, rsvd0
, psgl
, 0);
1902 AMAP_SET_BITS(struct amap_iscsi_sge
, last_sge
, psgl
, 0);
1906 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_lo
, psgl
,
1907 (addr
& 0xFFFFFFFF));
1908 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_hi
, psgl
,
1911 AMAP_SET_BITS(struct amap_iscsi_sge
, len
, psgl
, 0x106);
1913 AMAP_SET_BITS(struct amap_iscsi_sge
, last_sge
, psgl
, 1);
1916 static void beiscsi_find_mem_req(struct beiscsi_hba
*phba
)
1918 unsigned int num_cq_pages
, num_async_pdu_buf_pages
;
1919 unsigned int num_async_pdu_data_pages
, wrb_sz_per_cxn
;
1920 unsigned int num_async_pdu_buf_sgl_pages
, num_async_pdu_data_sgl_pages
;
1922 num_cq_pages
= PAGES_REQUIRED(phba
->params
.num_cq_entries
* \
1923 sizeof(struct sol_cqe
));
1924 num_async_pdu_buf_pages
=
1925 PAGES_REQUIRED(phba
->params
.asyncpdus_per_ctrl
* \
1926 phba
->params
.defpdu_hdr_sz
);
1927 num_async_pdu_buf_sgl_pages
=
1928 PAGES_REQUIRED(phba
->params
.asyncpdus_per_ctrl
* \
1929 sizeof(struct phys_addr
));
1930 num_async_pdu_data_pages
=
1931 PAGES_REQUIRED(phba
->params
.asyncpdus_per_ctrl
* \
1932 phba
->params
.defpdu_data_sz
);
1933 num_async_pdu_data_sgl_pages
=
1934 PAGES_REQUIRED(phba
->params
.asyncpdus_per_ctrl
* \
1935 sizeof(struct phys_addr
));
1937 phba
->params
.hwi_ws_sz
= sizeof(struct hwi_controller
);
1939 phba
->mem_req
[ISCSI_MEM_GLOBAL_HEADER
] = 2 *
1940 BE_ISCSI_PDU_HEADER_SIZE
;
1941 phba
->mem_req
[HWI_MEM_ADDN_CONTEXT
] =
1942 sizeof(struct hwi_context_memory
);
1945 phba
->mem_req
[HWI_MEM_WRB
] = sizeof(struct iscsi_wrb
)
1946 * (phba
->params
.wrbs_per_cxn
)
1947 * phba
->params
.cxns_per_ctrl
;
1948 wrb_sz_per_cxn
= sizeof(struct wrb_handle
) *
1949 (phba
->params
.wrbs_per_cxn
);
1950 phba
->mem_req
[HWI_MEM_WRBH
] = roundup_pow_of_two((wrb_sz_per_cxn
) *
1951 phba
->params
.cxns_per_ctrl
);
1953 phba
->mem_req
[HWI_MEM_SGLH
] = sizeof(struct sgl_handle
) *
1954 phba
->params
.icds_per_ctrl
;
1955 phba
->mem_req
[HWI_MEM_SGE
] = sizeof(struct iscsi_sge
) *
1956 phba
->params
.num_sge_per_io
* phba
->params
.icds_per_ctrl
;
1958 phba
->mem_req
[HWI_MEM_ASYNC_HEADER_BUF
] =
1959 num_async_pdu_buf_pages
* PAGE_SIZE
;
1960 phba
->mem_req
[HWI_MEM_ASYNC_DATA_BUF
] =
1961 num_async_pdu_data_pages
* PAGE_SIZE
;
1962 phba
->mem_req
[HWI_MEM_ASYNC_HEADER_RING
] =
1963 num_async_pdu_buf_sgl_pages
* PAGE_SIZE
;
1964 phba
->mem_req
[HWI_MEM_ASYNC_DATA_RING
] =
1965 num_async_pdu_data_sgl_pages
* PAGE_SIZE
;
1966 phba
->mem_req
[HWI_MEM_ASYNC_HEADER_HANDLE
] =
1967 phba
->params
.asyncpdus_per_ctrl
*
1968 sizeof(struct async_pdu_handle
);
1969 phba
->mem_req
[HWI_MEM_ASYNC_DATA_HANDLE
] =
1970 phba
->params
.asyncpdus_per_ctrl
*
1971 sizeof(struct async_pdu_handle
);
1972 phba
->mem_req
[HWI_MEM_ASYNC_PDU_CONTEXT
] =
1973 sizeof(struct hwi_async_pdu_context
) +
1974 (phba
->params
.cxns_per_ctrl
* sizeof(struct hwi_async_entry
));
1977 static int beiscsi_alloc_mem(struct beiscsi_hba
*phba
)
1979 struct be_mem_descriptor
*mem_descr
;
1981 struct mem_array
*mem_arr
, *mem_arr_orig
;
1982 unsigned int i
, j
, alloc_size
, curr_alloc_size
;
1984 phba
->phwi_ctrlr
= kmalloc(phba
->params
.hwi_ws_sz
, GFP_KERNEL
);
1985 if (!phba
->phwi_ctrlr
)
1988 phba
->init_mem
= kcalloc(SE_MEM_MAX
, sizeof(*mem_descr
),
1990 if (!phba
->init_mem
) {
1991 kfree(phba
->phwi_ctrlr
);
1995 mem_arr_orig
= kmalloc(sizeof(*mem_arr_orig
) * BEISCSI_MAX_FRAGS_INIT
,
1997 if (!mem_arr_orig
) {
1998 kfree(phba
->init_mem
);
1999 kfree(phba
->phwi_ctrlr
);
2003 mem_descr
= phba
->init_mem
;
2004 for (i
= 0; i
< SE_MEM_MAX
; i
++) {
2006 mem_arr
= mem_arr_orig
;
2007 alloc_size
= phba
->mem_req
[i
];
2008 memset(mem_arr
, 0, sizeof(struct mem_array
) *
2009 BEISCSI_MAX_FRAGS_INIT
);
2010 curr_alloc_size
= min(be_max_phys_size
* 1024, alloc_size
);
2012 mem_arr
->virtual_address
= pci_alloc_consistent(
2016 if (!mem_arr
->virtual_address
) {
2017 if (curr_alloc_size
<= BE_MIN_MEM_SIZE
)
2019 if (curr_alloc_size
-
2020 rounddown_pow_of_two(curr_alloc_size
))
2021 curr_alloc_size
= rounddown_pow_of_two
2024 curr_alloc_size
= curr_alloc_size
/ 2;
2026 mem_arr
->bus_address
.u
.
2027 a64
.address
= (__u64
) bus_add
;
2028 mem_arr
->size
= curr_alloc_size
;
2029 alloc_size
-= curr_alloc_size
;
2030 curr_alloc_size
= min(be_max_phys_size
*
2035 } while (alloc_size
);
2036 mem_descr
->num_elements
= j
;
2037 mem_descr
->size_in_bytes
= phba
->mem_req
[i
];
2038 mem_descr
->mem_array
= kmalloc(sizeof(*mem_arr
) * j
,
2040 if (!mem_descr
->mem_array
)
2043 memcpy(mem_descr
->mem_array
, mem_arr_orig
,
2044 sizeof(struct mem_array
) * j
);
2047 kfree(mem_arr_orig
);
2050 mem_descr
->num_elements
= j
;
2051 while ((i
) || (j
)) {
2052 for (j
= mem_descr
->num_elements
; j
> 0; j
--) {
2053 pci_free_consistent(phba
->pcidev
,
2054 mem_descr
->mem_array
[j
- 1].size
,
2055 mem_descr
->mem_array
[j
- 1].
2057 mem_descr
->mem_array
[j
- 1].
2058 bus_address
.u
.a64
.address
);
2062 kfree(mem_descr
->mem_array
);
2066 kfree(mem_arr_orig
);
2067 kfree(phba
->init_mem
);
2068 kfree(phba
->phwi_ctrlr
);
2072 static int beiscsi_get_memory(struct beiscsi_hba
*phba
)
2074 beiscsi_find_mem_req(phba
);
2075 return beiscsi_alloc_mem(phba
);
2078 static void iscsi_init_global_templates(struct beiscsi_hba
*phba
)
2080 struct pdu_data_out
*pdata_out
;
2081 struct pdu_nop_out
*pnop_out
;
2082 struct be_mem_descriptor
*mem_descr
;
2084 mem_descr
= phba
->init_mem
;
2085 mem_descr
+= ISCSI_MEM_GLOBAL_HEADER
;
2087 (struct pdu_data_out
*)mem_descr
->mem_array
[0].virtual_address
;
2088 memset(pdata_out
, 0, BE_ISCSI_PDU_HEADER_SIZE
);
2090 AMAP_SET_BITS(struct amap_pdu_data_out
, opcode
, pdata_out
,
2094 (struct pdu_nop_out
*)((unsigned char *)mem_descr
->mem_array
[0].
2095 virtual_address
+ BE_ISCSI_PDU_HEADER_SIZE
);
2097 memset(pnop_out
, 0, BE_ISCSI_PDU_HEADER_SIZE
);
2098 AMAP_SET_BITS(struct amap_pdu_nop_out
, ttt
, pnop_out
, 0xFFFFFFFF);
2099 AMAP_SET_BITS(struct amap_pdu_nop_out
, f_bit
, pnop_out
, 1);
2100 AMAP_SET_BITS(struct amap_pdu_nop_out
, i_bit
, pnop_out
, 0);
2103 static void beiscsi_init_wrb_handle(struct beiscsi_hba
*phba
)
2105 struct be_mem_descriptor
*mem_descr_wrbh
, *mem_descr_wrb
;
2106 struct wrb_handle
*pwrb_handle
;
2107 struct hwi_controller
*phwi_ctrlr
;
2108 struct hwi_wrb_context
*pwrb_context
;
2109 struct iscsi_wrb
*pwrb
;
2110 unsigned int num_cxn_wrbh
;
2111 unsigned int num_cxn_wrb
, j
, idx
, index
;
2113 mem_descr_wrbh
= phba
->init_mem
;
2114 mem_descr_wrbh
+= HWI_MEM_WRBH
;
2116 mem_descr_wrb
= phba
->init_mem
;
2117 mem_descr_wrb
+= HWI_MEM_WRB
;
2120 pwrb_handle
= mem_descr_wrbh
->mem_array
[idx
].virtual_address
;
2121 num_cxn_wrbh
= ((mem_descr_wrbh
->mem_array
[idx
].size
) /
2122 ((sizeof(struct wrb_handle
)) *
2123 phba
->params
.wrbs_per_cxn
));
2124 phwi_ctrlr
= phba
->phwi_ctrlr
;
2126 for (index
= 0; index
< phba
->params
.cxns_per_ctrl
* 2; index
+= 2) {
2127 pwrb_context
= &phwi_ctrlr
->wrb_context
[index
];
2128 pwrb_context
->pwrb_handle_base
=
2129 kzalloc(sizeof(struct wrb_handle
*) *
2130 phba
->params
.wrbs_per_cxn
, GFP_KERNEL
);
2131 pwrb_context
->pwrb_handle_basestd
=
2132 kzalloc(sizeof(struct wrb_handle
*) *
2133 phba
->params
.wrbs_per_cxn
, GFP_KERNEL
);
2135 pwrb_context
->alloc_index
= 0;
2136 pwrb_context
->wrb_handles_available
= 0;
2137 for (j
= 0; j
< phba
->params
.wrbs_per_cxn
; j
++) {
2138 pwrb_context
->pwrb_handle_base
[j
] = pwrb_handle
;
2139 pwrb_context
->pwrb_handle_basestd
[j
] =
2141 pwrb_context
->wrb_handles_available
++;
2142 pwrb_handle
->wrb_index
= j
;
2145 pwrb_context
->free_index
= 0;
2150 mem_descr_wrbh
->mem_array
[idx
].virtual_address
;
2152 ((mem_descr_wrbh
->mem_array
[idx
].size
) /
2153 ((sizeof(struct wrb_handle
)) *
2154 phba
->params
.wrbs_per_cxn
));
2155 pwrb_context
->alloc_index
= 0;
2156 for (j
= 0; j
< phba
->params
.wrbs_per_cxn
; j
++) {
2157 pwrb_context
->pwrb_handle_base
[j
] = pwrb_handle
;
2158 pwrb_context
->pwrb_handle_basestd
[j
] =
2160 pwrb_context
->wrb_handles_available
++;
2161 pwrb_handle
->wrb_index
= j
;
2164 pwrb_context
->free_index
= 0;
2169 pwrb
= mem_descr_wrb
->mem_array
[idx
].virtual_address
;
2170 num_cxn_wrb
= (mem_descr_wrb
->mem_array
[idx
].size
) /
2171 ((sizeof(struct iscsi_wrb
) *
2172 phba
->params
.wrbs_per_cxn
));
2173 for (index
= 0; index
< phba
->params
.cxns_per_ctrl
* 2; index
+= 2) {
2174 pwrb_context
= &phwi_ctrlr
->wrb_context
[index
];
2176 for (j
= 0; j
< phba
->params
.wrbs_per_cxn
; j
++) {
2177 pwrb_handle
= pwrb_context
->pwrb_handle_base
[j
];
2178 pwrb_handle
->pwrb
= pwrb
;
2184 pwrb
= mem_descr_wrb
->mem_array
[idx
].virtual_address
;
2185 num_cxn_wrb
= (mem_descr_wrb
->mem_array
[idx
].size
) /
2186 ((sizeof(struct iscsi_wrb
) *
2187 phba
->params
.wrbs_per_cxn
));
2188 for (j
= 0; j
< phba
->params
.wrbs_per_cxn
; j
++) {
2189 pwrb_handle
= pwrb_context
->pwrb_handle_base
[j
];
2190 pwrb_handle
->pwrb
= pwrb
;
2198 static void hwi_init_async_pdu_ctx(struct beiscsi_hba
*phba
)
2200 struct hwi_controller
*phwi_ctrlr
;
2201 struct hba_parameters
*p
= &phba
->params
;
2202 struct hwi_async_pdu_context
*pasync_ctx
;
2203 struct async_pdu_handle
*pasync_header_h
, *pasync_data_h
;
2205 struct be_mem_descriptor
*mem_descr
;
2207 mem_descr
= (struct be_mem_descriptor
*)phba
->init_mem
;
2208 mem_descr
+= HWI_MEM_ASYNC_PDU_CONTEXT
;
2210 phwi_ctrlr
= phba
->phwi_ctrlr
;
2211 phwi_ctrlr
->phwi_ctxt
->pasync_ctx
= (struct hwi_async_pdu_context
*)
2212 mem_descr
->mem_array
[0].virtual_address
;
2213 pasync_ctx
= phwi_ctrlr
->phwi_ctxt
->pasync_ctx
;
2214 memset(pasync_ctx
, 0, sizeof(*pasync_ctx
));
2216 pasync_ctx
->async_header
.num_entries
= p
->asyncpdus_per_ctrl
;
2217 pasync_ctx
->async_header
.buffer_size
= p
->defpdu_hdr_sz
;
2218 pasync_ctx
->async_data
.buffer_size
= p
->defpdu_data_sz
;
2219 pasync_ctx
->async_data
.num_entries
= p
->asyncpdus_per_ctrl
;
2221 mem_descr
= (struct be_mem_descriptor
*)phba
->init_mem
;
2222 mem_descr
+= HWI_MEM_ASYNC_HEADER_BUF
;
2223 if (mem_descr
->mem_array
[0].virtual_address
) {
2225 "hwi_init_async_pdu_ctx HWI_MEM_ASYNC_HEADER_BUF"
2226 "va=%p \n", mem_descr
->mem_array
[0].virtual_address
);
2228 shost_printk(KERN_WARNING
, phba
->shost
,
2229 "No Virtual address \n");
2231 pasync_ctx
->async_header
.va_base
=
2232 mem_descr
->mem_array
[0].virtual_address
;
2234 pasync_ctx
->async_header
.pa_base
.u
.a64
.address
=
2235 mem_descr
->mem_array
[0].bus_address
.u
.a64
.address
;
2237 mem_descr
= (struct be_mem_descriptor
*)phba
->init_mem
;
2238 mem_descr
+= HWI_MEM_ASYNC_HEADER_RING
;
2239 if (mem_descr
->mem_array
[0].virtual_address
) {
2241 "hwi_init_async_pdu_ctx HWI_MEM_ASYNC_HEADER_RING"
2242 "va=%p \n", mem_descr
->mem_array
[0].virtual_address
);
2244 shost_printk(KERN_WARNING
, phba
->shost
,
2245 "No Virtual address \n");
2246 pasync_ctx
->async_header
.ring_base
=
2247 mem_descr
->mem_array
[0].virtual_address
;
2249 mem_descr
= (struct be_mem_descriptor
*)phba
->init_mem
;
2250 mem_descr
+= HWI_MEM_ASYNC_HEADER_HANDLE
;
2251 if (mem_descr
->mem_array
[0].virtual_address
) {
2253 "hwi_init_async_pdu_ctx HWI_MEM_ASYNC_HEADER_HANDLE"
2254 "va=%p \n", mem_descr
->mem_array
[0].virtual_address
);
2256 shost_printk(KERN_WARNING
, phba
->shost
,
2257 "No Virtual address \n");
2259 pasync_ctx
->async_header
.handle_base
=
2260 mem_descr
->mem_array
[0].virtual_address
;
2261 pasync_ctx
->async_header
.writables
= 0;
2262 INIT_LIST_HEAD(&pasync_ctx
->async_header
.free_list
);
2264 mem_descr
= (struct be_mem_descriptor
*)phba
->init_mem
;
2265 mem_descr
+= HWI_MEM_ASYNC_DATA_BUF
;
2266 if (mem_descr
->mem_array
[0].virtual_address
) {
2268 "hwi_init_async_pdu_ctx HWI_MEM_ASYNC_DATA_BUF"
2269 "va=%p \n", mem_descr
->mem_array
[0].virtual_address
);
2271 shost_printk(KERN_WARNING
, phba
->shost
,
2272 "No Virtual address \n");
2273 pasync_ctx
->async_data
.va_base
=
2274 mem_descr
->mem_array
[0].virtual_address
;
2275 pasync_ctx
->async_data
.pa_base
.u
.a64
.address
=
2276 mem_descr
->mem_array
[0].bus_address
.u
.a64
.address
;
2278 mem_descr
= (struct be_mem_descriptor
*)phba
->init_mem
;
2279 mem_descr
+= HWI_MEM_ASYNC_DATA_RING
;
2280 if (mem_descr
->mem_array
[0].virtual_address
) {
2282 "hwi_init_async_pdu_ctx HWI_MEM_ASYNC_DATA_RING"
2283 "va=%p \n", mem_descr
->mem_array
[0].virtual_address
);
2285 shost_printk(KERN_WARNING
, phba
->shost
,
2286 "No Virtual address \n");
2288 pasync_ctx
->async_data
.ring_base
=
2289 mem_descr
->mem_array
[0].virtual_address
;
2291 mem_descr
= (struct be_mem_descriptor
*)phba
->init_mem
;
2292 mem_descr
+= HWI_MEM_ASYNC_DATA_HANDLE
;
2293 if (!mem_descr
->mem_array
[0].virtual_address
)
2294 shost_printk(KERN_WARNING
, phba
->shost
,
2295 "No Virtual address \n");
2297 pasync_ctx
->async_data
.handle_base
=
2298 mem_descr
->mem_array
[0].virtual_address
;
2299 pasync_ctx
->async_data
.writables
= 0;
2300 INIT_LIST_HEAD(&pasync_ctx
->async_data
.free_list
);
2303 (struct async_pdu_handle
*)pasync_ctx
->async_header
.handle_base
;
2305 (struct async_pdu_handle
*)pasync_ctx
->async_data
.handle_base
;
2307 for (index
= 0; index
< p
->asyncpdus_per_ctrl
; index
++) {
2308 pasync_header_h
->cri
= -1;
2309 pasync_header_h
->index
= (char)index
;
2310 INIT_LIST_HEAD(&pasync_header_h
->link
);
2311 pasync_header_h
->pbuffer
=
2312 (void *)((unsigned long)
2313 (pasync_ctx
->async_header
.va_base
) +
2314 (p
->defpdu_hdr_sz
* index
));
2316 pasync_header_h
->pa
.u
.a64
.address
=
2317 pasync_ctx
->async_header
.pa_base
.u
.a64
.address
+
2318 (p
->defpdu_hdr_sz
* index
);
2320 list_add_tail(&pasync_header_h
->link
,
2321 &pasync_ctx
->async_header
.free_list
);
2323 pasync_ctx
->async_header
.free_entries
++;
2324 pasync_ctx
->async_header
.writables
++;
2326 INIT_LIST_HEAD(&pasync_ctx
->async_entry
[index
].wait_queue
.list
);
2327 INIT_LIST_HEAD(&pasync_ctx
->async_entry
[index
].
2329 pasync_data_h
->cri
= -1;
2330 pasync_data_h
->index
= (char)index
;
2331 INIT_LIST_HEAD(&pasync_data_h
->link
);
2332 pasync_data_h
->pbuffer
=
2333 (void *)((unsigned long)
2334 (pasync_ctx
->async_data
.va_base
) +
2335 (p
->defpdu_data_sz
* index
));
2337 pasync_data_h
->pa
.u
.a64
.address
=
2338 pasync_ctx
->async_data
.pa_base
.u
.a64
.address
+
2339 (p
->defpdu_data_sz
* index
);
2341 list_add_tail(&pasync_data_h
->link
,
2342 &pasync_ctx
->async_data
.free_list
);
2344 pasync_ctx
->async_data
.free_entries
++;
2345 pasync_ctx
->async_data
.writables
++;
2347 INIT_LIST_HEAD(&pasync_ctx
->async_entry
[index
].data_busy_list
);
2350 pasync_ctx
->async_header
.host_write_ptr
= 0;
2351 pasync_ctx
->async_header
.ep_read_ptr
= -1;
2352 pasync_ctx
->async_data
.host_write_ptr
= 0;
2353 pasync_ctx
->async_data
.ep_read_ptr
= -1;
2357 be_sgl_create_contiguous(void *virtual_address
,
2358 u64 physical_address
, u32 length
,
2359 struct be_dma_mem
*sgl
)
2361 WARN_ON(!virtual_address
);
2362 WARN_ON(!physical_address
);
2363 WARN_ON(!length
> 0);
2366 sgl
->va
= virtual_address
;
2367 sgl
->dma
= physical_address
;
2373 static void be_sgl_destroy_contiguous(struct be_dma_mem
*sgl
)
2375 memset(sgl
, 0, sizeof(*sgl
));
2379 hwi_build_be_sgl_arr(struct beiscsi_hba
*phba
,
2380 struct mem_array
*pmem
, struct be_dma_mem
*sgl
)
2383 be_sgl_destroy_contiguous(sgl
);
2385 be_sgl_create_contiguous(pmem
->virtual_address
,
2386 pmem
->bus_address
.u
.a64
.address
,
2391 hwi_build_be_sgl_by_offset(struct beiscsi_hba
*phba
,
2392 struct mem_array
*pmem
, struct be_dma_mem
*sgl
)
2395 be_sgl_destroy_contiguous(sgl
);
2397 be_sgl_create_contiguous((unsigned char *)pmem
->virtual_address
,
2398 pmem
->bus_address
.u
.a64
.address
,
2402 static int be_fill_queue(struct be_queue_info
*q
,
2403 u16 len
, u16 entry_size
, void *vaddress
)
2405 struct be_dma_mem
*mem
= &q
->dma_mem
;
2407 memset(q
, 0, sizeof(*q
));
2409 q
->entry_size
= entry_size
;
2410 mem
->size
= len
* entry_size
;
2414 memset(mem
->va
, 0, mem
->size
);
2418 static int beiscsi_create_eqs(struct beiscsi_hba
*phba
,
2419 struct hwi_context_memory
*phwi_context
)
2421 unsigned int i
, num_eq_pages
;
2422 int ret
, eq_for_mcc
;
2423 struct be_queue_info
*eq
;
2424 struct be_dma_mem
*mem
;
2428 num_eq_pages
= PAGES_REQUIRED(phba
->params
.num_eq_entries
* \
2429 sizeof(struct be_eq_entry
));
2431 if (phba
->msix_enabled
)
2435 for (i
= 0; i
< (phba
->num_cpus
+ eq_for_mcc
); i
++) {
2436 eq
= &phwi_context
->be_eq
[i
].q
;
2438 phwi_context
->be_eq
[i
].phba
= phba
;
2439 eq_vaddress
= pci_alloc_consistent(phba
->pcidev
,
2440 num_eq_pages
* PAGE_SIZE
,
2443 goto create_eq_error
;
2445 mem
->va
= eq_vaddress
;
2446 ret
= be_fill_queue(eq
, phba
->params
.num_eq_entries
,
2447 sizeof(struct be_eq_entry
), eq_vaddress
);
2449 shost_printk(KERN_ERR
, phba
->shost
,
2450 "be_fill_queue Failed for EQ \n");
2451 goto create_eq_error
;
2455 ret
= beiscsi_cmd_eq_create(&phba
->ctrl
, eq
,
2456 phwi_context
->cur_eqd
);
2458 shost_printk(KERN_ERR
, phba
->shost
,
2459 "beiscsi_cmd_eq_create"
2461 goto create_eq_error
;
2463 SE_DEBUG(DBG_LVL_8
, "eqid = %d\n", phwi_context
->be_eq
[i
].q
.id
);
2467 for (i
= 0; i
< (phba
->num_cpus
+ 1); i
++) {
2468 eq
= &phwi_context
->be_eq
[i
].q
;
2471 pci_free_consistent(phba
->pcidev
, num_eq_pages
2478 static int beiscsi_create_cqs(struct beiscsi_hba
*phba
,
2479 struct hwi_context_memory
*phwi_context
)
2481 unsigned int i
, num_cq_pages
;
2483 struct be_queue_info
*cq
, *eq
;
2484 struct be_dma_mem
*mem
;
2485 struct be_eq_obj
*pbe_eq
;
2489 num_cq_pages
= PAGES_REQUIRED(phba
->params
.num_cq_entries
* \
2490 sizeof(struct sol_cqe
));
2492 for (i
= 0; i
< phba
->num_cpus
; i
++) {
2493 cq
= &phwi_context
->be_cq
[i
];
2494 eq
= &phwi_context
->be_eq
[i
].q
;
2495 pbe_eq
= &phwi_context
->be_eq
[i
];
2497 pbe_eq
->phba
= phba
;
2499 cq_vaddress
= pci_alloc_consistent(phba
->pcidev
,
2500 num_cq_pages
* PAGE_SIZE
,
2503 goto create_cq_error
;
2504 ret
= be_fill_queue(cq
, phba
->params
.num_cq_entries
,
2505 sizeof(struct sol_cqe
), cq_vaddress
);
2507 shost_printk(KERN_ERR
, phba
->shost
,
2508 "be_fill_queue Failed for ISCSI CQ \n");
2509 goto create_cq_error
;
2513 ret
= beiscsi_cmd_cq_create(&phba
->ctrl
, cq
, eq
, false,
2516 shost_printk(KERN_ERR
, phba
->shost
,
2517 "beiscsi_cmd_eq_create"
2518 "Failed for ISCSI CQ \n");
2519 goto create_cq_error
;
2521 SE_DEBUG(DBG_LVL_8
, "iscsi cq_id is %d for eq_id %d\n",
2523 SE_DEBUG(DBG_LVL_8
, "ISCSI CQ CREATED\n");
2528 for (i
= 0; i
< phba
->num_cpus
; i
++) {
2529 cq
= &phwi_context
->be_cq
[i
];
2532 pci_free_consistent(phba
->pcidev
, num_cq_pages
2541 beiscsi_create_def_hdr(struct beiscsi_hba
*phba
,
2542 struct hwi_context_memory
*phwi_context
,
2543 struct hwi_controller
*phwi_ctrlr
,
2544 unsigned int def_pdu_ring_sz
)
2548 struct be_queue_info
*dq
, *cq
;
2549 struct be_dma_mem
*mem
;
2550 struct be_mem_descriptor
*mem_descr
;
2554 dq
= &phwi_context
->be_def_hdrq
;
2555 cq
= &phwi_context
->be_cq
[0];
2557 mem_descr
= phba
->init_mem
;
2558 mem_descr
+= HWI_MEM_ASYNC_HEADER_RING
;
2559 dq_vaddress
= mem_descr
->mem_array
[idx
].virtual_address
;
2560 ret
= be_fill_queue(dq
, mem_descr
->mem_array
[0].size
/
2561 sizeof(struct phys_addr
),
2562 sizeof(struct phys_addr
), dq_vaddress
);
2564 shost_printk(KERN_ERR
, phba
->shost
,
2565 "be_fill_queue Failed for DEF PDU HDR\n");
2568 mem
->dma
= mem_descr
->mem_array
[idx
].bus_address
.u
.a64
.address
;
2569 ret
= be_cmd_create_default_pdu_queue(&phba
->ctrl
, cq
, dq
,
2571 phba
->params
.defpdu_hdr_sz
);
2573 shost_printk(KERN_ERR
, phba
->shost
,
2574 "be_cmd_create_default_pdu_queue Failed DEFHDR\n");
2577 phwi_ctrlr
->default_pdu_hdr
.id
= phwi_context
->be_def_hdrq
.id
;
2578 SE_DEBUG(DBG_LVL_8
, "iscsi def pdu id is %d\n",
2579 phwi_context
->be_def_hdrq
.id
);
2580 hwi_post_async_buffers(phba
, 1);
2585 beiscsi_create_def_data(struct beiscsi_hba
*phba
,
2586 struct hwi_context_memory
*phwi_context
,
2587 struct hwi_controller
*phwi_ctrlr
,
2588 unsigned int def_pdu_ring_sz
)
2592 struct be_queue_info
*dataq
, *cq
;
2593 struct be_dma_mem
*mem
;
2594 struct be_mem_descriptor
*mem_descr
;
2598 dataq
= &phwi_context
->be_def_dataq
;
2599 cq
= &phwi_context
->be_cq
[0];
2600 mem
= &dataq
->dma_mem
;
2601 mem_descr
= phba
->init_mem
;
2602 mem_descr
+= HWI_MEM_ASYNC_DATA_RING
;
2603 dq_vaddress
= mem_descr
->mem_array
[idx
].virtual_address
;
2604 ret
= be_fill_queue(dataq
, mem_descr
->mem_array
[0].size
/
2605 sizeof(struct phys_addr
),
2606 sizeof(struct phys_addr
), dq_vaddress
);
2608 shost_printk(KERN_ERR
, phba
->shost
,
2609 "be_fill_queue Failed for DEF PDU DATA\n");
2612 mem
->dma
= mem_descr
->mem_array
[idx
].bus_address
.u
.a64
.address
;
2613 ret
= be_cmd_create_default_pdu_queue(&phba
->ctrl
, cq
, dataq
,
2615 phba
->params
.defpdu_data_sz
);
2617 shost_printk(KERN_ERR
, phba
->shost
,
2618 "be_cmd_create_default_pdu_queue Failed"
2619 " for DEF PDU DATA\n");
2622 phwi_ctrlr
->default_pdu_data
.id
= phwi_context
->be_def_dataq
.id
;
2623 SE_DEBUG(DBG_LVL_8
, "iscsi def data id is %d\n",
2624 phwi_context
->be_def_dataq
.id
);
2625 hwi_post_async_buffers(phba
, 0);
2626 SE_DEBUG(DBG_LVL_8
, "DEFAULT PDU DATA RING CREATED \n");
2631 beiscsi_post_pages(struct beiscsi_hba
*phba
)
2633 struct be_mem_descriptor
*mem_descr
;
2634 struct mem_array
*pm_arr
;
2635 unsigned int page_offset
, i
;
2636 struct be_dma_mem sgl
;
2639 mem_descr
= phba
->init_mem
;
2640 mem_descr
+= HWI_MEM_SGE
;
2641 pm_arr
= mem_descr
->mem_array
;
2643 page_offset
= (sizeof(struct iscsi_sge
) * phba
->params
.num_sge_per_io
*
2644 phba
->fw_config
.iscsi_icd_start
) / PAGE_SIZE
;
2645 for (i
= 0; i
< mem_descr
->num_elements
; i
++) {
2646 hwi_build_be_sgl_arr(phba
, pm_arr
, &sgl
);
2647 status
= be_cmd_iscsi_post_sgl_pages(&phba
->ctrl
, &sgl
,
2649 (pm_arr
->size
/ PAGE_SIZE
));
2650 page_offset
+= pm_arr
->size
/ PAGE_SIZE
;
2652 shost_printk(KERN_ERR
, phba
->shost
,
2653 "post sgl failed.\n");
2658 SE_DEBUG(DBG_LVL_8
, "POSTED PAGES \n");
2662 static void be_queue_free(struct beiscsi_hba
*phba
, struct be_queue_info
*q
)
2664 struct be_dma_mem
*mem
= &q
->dma_mem
;
2666 pci_free_consistent(phba
->pcidev
, mem
->size
,
2670 static int be_queue_alloc(struct beiscsi_hba
*phba
, struct be_queue_info
*q
,
2671 u16 len
, u16 entry_size
)
2673 struct be_dma_mem
*mem
= &q
->dma_mem
;
2675 memset(q
, 0, sizeof(*q
));
2677 q
->entry_size
= entry_size
;
2678 mem
->size
= len
* entry_size
;
2679 mem
->va
= pci_alloc_consistent(phba
->pcidev
, mem
->size
, &mem
->dma
);
2682 memset(mem
->va
, 0, mem
->size
);
2687 beiscsi_create_wrb_rings(struct beiscsi_hba
*phba
,
2688 struct hwi_context_memory
*phwi_context
,
2689 struct hwi_controller
*phwi_ctrlr
)
2691 unsigned int wrb_mem_index
, offset
, size
, num_wrb_rings
;
2693 unsigned int idx
, num
, i
;
2694 struct mem_array
*pwrb_arr
;
2696 struct be_dma_mem sgl
;
2697 struct be_mem_descriptor
*mem_descr
;
2701 mem_descr
= phba
->init_mem
;
2702 mem_descr
+= HWI_MEM_WRB
;
2703 pwrb_arr
= kmalloc(sizeof(*pwrb_arr
) * phba
->params
.cxns_per_ctrl
,
2706 shost_printk(KERN_ERR
, phba
->shost
,
2707 "Memory alloc failed in create wrb ring.\n");
2710 wrb_vaddr
= mem_descr
->mem_array
[idx
].virtual_address
;
2711 pa_addr_lo
= mem_descr
->mem_array
[idx
].bus_address
.u
.a64
.address
;
2712 num_wrb_rings
= mem_descr
->mem_array
[idx
].size
/
2713 (phba
->params
.wrbs_per_cxn
* sizeof(struct iscsi_wrb
));
2715 for (num
= 0; num
< phba
->params
.cxns_per_ctrl
; num
++) {
2716 if (num_wrb_rings
) {
2717 pwrb_arr
[num
].virtual_address
= wrb_vaddr
;
2718 pwrb_arr
[num
].bus_address
.u
.a64
.address
= pa_addr_lo
;
2719 pwrb_arr
[num
].size
= phba
->params
.wrbs_per_cxn
*
2720 sizeof(struct iscsi_wrb
);
2721 wrb_vaddr
+= pwrb_arr
[num
].size
;
2722 pa_addr_lo
+= pwrb_arr
[num
].size
;
2726 wrb_vaddr
= mem_descr
->mem_array
[idx
].virtual_address
;
2727 pa_addr_lo
= mem_descr
->mem_array
[idx
].\
2728 bus_address
.u
.a64
.address
;
2729 num_wrb_rings
= mem_descr
->mem_array
[idx
].size
/
2730 (phba
->params
.wrbs_per_cxn
*
2731 sizeof(struct iscsi_wrb
));
2732 pwrb_arr
[num
].virtual_address
= wrb_vaddr
;
2733 pwrb_arr
[num
].bus_address
.u
.a64
.address\
2735 pwrb_arr
[num
].size
= phba
->params
.wrbs_per_cxn
*
2736 sizeof(struct iscsi_wrb
);
2737 wrb_vaddr
+= pwrb_arr
[num
].size
;
2738 pa_addr_lo
+= pwrb_arr
[num
].size
;
2742 for (i
= 0; i
< phba
->params
.cxns_per_ctrl
; i
++) {
2747 hwi_build_be_sgl_by_offset(phba
, &pwrb_arr
[i
], &sgl
);
2748 status
= be_cmd_wrbq_create(&phba
->ctrl
, &sgl
,
2749 &phwi_context
->be_wrbq
[i
]);
2751 shost_printk(KERN_ERR
, phba
->shost
,
2752 "wrbq create failed.");
2755 phwi_ctrlr
->wrb_context
[i
* 2].cid
= phwi_context
->be_wrbq
[i
].
2762 static void free_wrb_handles(struct beiscsi_hba
*phba
)
2765 struct hwi_controller
*phwi_ctrlr
;
2766 struct hwi_wrb_context
*pwrb_context
;
2768 phwi_ctrlr
= phba
->phwi_ctrlr
;
2769 for (index
= 0; index
< phba
->params
.cxns_per_ctrl
* 2; index
+= 2) {
2770 pwrb_context
= &phwi_ctrlr
->wrb_context
[index
];
2771 kfree(pwrb_context
->pwrb_handle_base
);
2772 kfree(pwrb_context
->pwrb_handle_basestd
);
2776 static void be_mcc_queues_destroy(struct beiscsi_hba
*phba
)
2778 struct be_queue_info
*q
;
2779 struct be_ctrl_info
*ctrl
= &phba
->ctrl
;
2781 q
= &phba
->ctrl
.mcc_obj
.q
;
2783 beiscsi_cmd_q_destroy(ctrl
, q
, QTYPE_MCCQ
);
2784 be_queue_free(phba
, q
);
2786 q
= &phba
->ctrl
.mcc_obj
.cq
;
2788 beiscsi_cmd_q_destroy(ctrl
, q
, QTYPE_CQ
);
2789 be_queue_free(phba
, q
);
2792 static void hwi_cleanup(struct beiscsi_hba
*phba
)
2794 struct be_queue_info
*q
;
2795 struct be_ctrl_info
*ctrl
= &phba
->ctrl
;
2796 struct hwi_controller
*phwi_ctrlr
;
2797 struct hwi_context_memory
*phwi_context
;
2800 phwi_ctrlr
= phba
->phwi_ctrlr
;
2801 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
2802 for (i
= 0; i
< phba
->params
.cxns_per_ctrl
; i
++) {
2803 q
= &phwi_context
->be_wrbq
[i
];
2805 beiscsi_cmd_q_destroy(ctrl
, q
, QTYPE_WRBQ
);
2807 free_wrb_handles(phba
);
2809 q
= &phwi_context
->be_def_hdrq
;
2811 beiscsi_cmd_q_destroy(ctrl
, q
, QTYPE_DPDUQ
);
2813 q
= &phwi_context
->be_def_dataq
;
2815 beiscsi_cmd_q_destroy(ctrl
, q
, QTYPE_DPDUQ
);
2817 beiscsi_cmd_q_destroy(ctrl
, NULL
, QTYPE_SGL
);
2819 for (i
= 0; i
< (phba
->num_cpus
); i
++) {
2820 q
= &phwi_context
->be_cq
[i
];
2822 beiscsi_cmd_q_destroy(ctrl
, q
, QTYPE_CQ
);
2824 if (phba
->msix_enabled
)
2828 for (i
= 0; i
< (phba
->num_cpus
+ eq_num
); i
++) {
2829 q
= &phwi_context
->be_eq
[i
].q
;
2831 beiscsi_cmd_q_destroy(ctrl
, q
, QTYPE_EQ
);
2833 be_mcc_queues_destroy(phba
);
2836 static int be_mcc_queues_create(struct beiscsi_hba
*phba
,
2837 struct hwi_context_memory
*phwi_context
)
2839 struct be_queue_info
*q
, *cq
;
2840 struct be_ctrl_info
*ctrl
= &phba
->ctrl
;
2842 /* Alloc MCC compl queue */
2843 cq
= &phba
->ctrl
.mcc_obj
.cq
;
2844 if (be_queue_alloc(phba
, cq
, MCC_CQ_LEN
,
2845 sizeof(struct be_mcc_compl
)))
2847 /* Ask BE to create MCC compl queue; */
2848 if (phba
->msix_enabled
) {
2849 if (beiscsi_cmd_cq_create(ctrl
, cq
, &phwi_context
->be_eq
2850 [phba
->num_cpus
].q
, false, true, 0))
2853 if (beiscsi_cmd_cq_create(ctrl
, cq
, &phwi_context
->be_eq
[0].q
,
2858 /* Alloc MCC queue */
2859 q
= &phba
->ctrl
.mcc_obj
.q
;
2860 if (be_queue_alloc(phba
, q
, MCC_Q_LEN
, sizeof(struct be_mcc_wrb
)))
2861 goto mcc_cq_destroy
;
2863 /* Ask BE to create MCC queue */
2864 if (beiscsi_cmd_mccq_create(phba
, q
, cq
))
2870 be_queue_free(phba
, q
);
2872 beiscsi_cmd_q_destroy(ctrl
, cq
, QTYPE_CQ
);
2874 be_queue_free(phba
, cq
);
2879 static int find_num_cpus(void)
2883 num_cpus
= num_online_cpus();
2884 if (num_cpus
>= MAX_CPUS
)
2885 num_cpus
= MAX_CPUS
- 1;
2887 SE_DEBUG(DBG_LVL_8
, "num_cpus = %d \n", num_cpus
);
2891 static int hwi_init_port(struct beiscsi_hba
*phba
)
2893 struct hwi_controller
*phwi_ctrlr
;
2894 struct hwi_context_memory
*phwi_context
;
2895 unsigned int def_pdu_ring_sz
;
2896 struct be_ctrl_info
*ctrl
= &phba
->ctrl
;
2900 phba
->params
.asyncpdus_per_ctrl
* sizeof(struct phys_addr
);
2901 phwi_ctrlr
= phba
->phwi_ctrlr
;
2902 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
2903 phwi_context
->max_eqd
= 0;
2904 phwi_context
->min_eqd
= 0;
2905 phwi_context
->cur_eqd
= 64;
2906 be_cmd_fw_initialize(&phba
->ctrl
);
2908 status
= beiscsi_create_eqs(phba
, phwi_context
);
2910 shost_printk(KERN_ERR
, phba
->shost
, "EQ not created \n");
2914 status
= be_mcc_queues_create(phba
, phwi_context
);
2918 status
= mgmt_check_supported_fw(ctrl
, phba
);
2920 shost_printk(KERN_ERR
, phba
->shost
,
2921 "Unsupported fw version \n");
2925 status
= beiscsi_create_cqs(phba
, phwi_context
);
2927 shost_printk(KERN_ERR
, phba
->shost
, "CQ not created\n");
2931 status
= beiscsi_create_def_hdr(phba
, phwi_context
, phwi_ctrlr
,
2934 shost_printk(KERN_ERR
, phba
->shost
,
2935 "Default Header not created\n");
2939 status
= beiscsi_create_def_data(phba
, phwi_context
,
2940 phwi_ctrlr
, def_pdu_ring_sz
);
2942 shost_printk(KERN_ERR
, phba
->shost
,
2943 "Default Data not created\n");
2947 status
= beiscsi_post_pages(phba
);
2949 shost_printk(KERN_ERR
, phba
->shost
, "Post SGL Pages Failed\n");
2953 status
= beiscsi_create_wrb_rings(phba
, phwi_context
, phwi_ctrlr
);
2955 shost_printk(KERN_ERR
, phba
->shost
,
2956 "WRB Rings not created\n");
2960 SE_DEBUG(DBG_LVL_8
, "hwi_init_port success\n");
2964 shost_printk(KERN_ERR
, phba
->shost
, "hwi_init_port failed");
2969 static int hwi_init_controller(struct beiscsi_hba
*phba
)
2971 struct hwi_controller
*phwi_ctrlr
;
2973 phwi_ctrlr
= phba
->phwi_ctrlr
;
2974 if (1 == phba
->init_mem
[HWI_MEM_ADDN_CONTEXT
].num_elements
) {
2975 phwi_ctrlr
->phwi_ctxt
= (struct hwi_context_memory
*)phba
->
2976 init_mem
[HWI_MEM_ADDN_CONTEXT
].mem_array
[0].virtual_address
;
2977 SE_DEBUG(DBG_LVL_8
, " phwi_ctrlr->phwi_ctxt=%p \n",
2978 phwi_ctrlr
->phwi_ctxt
);
2980 shost_printk(KERN_ERR
, phba
->shost
,
2981 "HWI_MEM_ADDN_CONTEXT is more than one element."
2982 "Failing to load\n");
2986 iscsi_init_global_templates(phba
);
2987 beiscsi_init_wrb_handle(phba
);
2988 hwi_init_async_pdu_ctx(phba
);
2989 if (hwi_init_port(phba
) != 0) {
2990 shost_printk(KERN_ERR
, phba
->shost
,
2991 "hwi_init_controller failed\n");
2997 static void beiscsi_free_mem(struct beiscsi_hba
*phba
)
2999 struct be_mem_descriptor
*mem_descr
;
3002 mem_descr
= phba
->init_mem
;
3005 for (i
= 0; i
< SE_MEM_MAX
; i
++) {
3006 for (j
= mem_descr
->num_elements
; j
> 0; j
--) {
3007 pci_free_consistent(phba
->pcidev
,
3008 mem_descr
->mem_array
[j
- 1].size
,
3009 mem_descr
->mem_array
[j
- 1].virtual_address
,
3010 mem_descr
->mem_array
[j
- 1].bus_address
.
3013 kfree(mem_descr
->mem_array
);
3016 kfree(phba
->init_mem
);
3017 kfree(phba
->phwi_ctrlr
);
3020 static int beiscsi_init_controller(struct beiscsi_hba
*phba
)
3024 ret
= beiscsi_get_memory(phba
);
3026 shost_printk(KERN_ERR
, phba
->shost
, "beiscsi_dev_probe -"
3027 "Failed in beiscsi_alloc_memory \n");
3031 ret
= hwi_init_controller(phba
);
3034 SE_DEBUG(DBG_LVL_8
, "Return success from beiscsi_init_controller");
3038 beiscsi_free_mem(phba
);
3042 static int beiscsi_init_sgl_handle(struct beiscsi_hba
*phba
)
3044 struct be_mem_descriptor
*mem_descr_sglh
, *mem_descr_sg
;
3045 struct sgl_handle
*psgl_handle
;
3046 struct iscsi_sge
*pfrag
;
3047 unsigned int arr_index
, i
, idx
;
3049 phba
->io_sgl_hndl_avbl
= 0;
3050 phba
->eh_sgl_hndl_avbl
= 0;
3052 mem_descr_sglh
= phba
->init_mem
;
3053 mem_descr_sglh
+= HWI_MEM_SGLH
;
3054 if (1 == mem_descr_sglh
->num_elements
) {
3055 phba
->io_sgl_hndl_base
= kzalloc(sizeof(struct sgl_handle
*) *
3056 phba
->params
.ios_per_ctrl
,
3058 if (!phba
->io_sgl_hndl_base
) {
3059 shost_printk(KERN_ERR
, phba
->shost
,
3060 "Mem Alloc Failed. Failing to load\n");
3063 phba
->eh_sgl_hndl_base
= kzalloc(sizeof(struct sgl_handle
*) *
3064 (phba
->params
.icds_per_ctrl
-
3065 phba
->params
.ios_per_ctrl
),
3067 if (!phba
->eh_sgl_hndl_base
) {
3068 kfree(phba
->io_sgl_hndl_base
);
3069 shost_printk(KERN_ERR
, phba
->shost
,
3070 "Mem Alloc Failed. Failing to load\n");
3074 shost_printk(KERN_ERR
, phba
->shost
,
3075 "HWI_MEM_SGLH is more than one element."
3076 "Failing to load\n");
3082 while (idx
< mem_descr_sglh
->num_elements
) {
3083 psgl_handle
= mem_descr_sglh
->mem_array
[idx
].virtual_address
;
3085 for (i
= 0; i
< (mem_descr_sglh
->mem_array
[idx
].size
/
3086 sizeof(struct sgl_handle
)); i
++) {
3087 if (arr_index
< phba
->params
.ios_per_ctrl
) {
3088 phba
->io_sgl_hndl_base
[arr_index
] = psgl_handle
;
3089 phba
->io_sgl_hndl_avbl
++;
3092 phba
->eh_sgl_hndl_base
[arr_index
-
3093 phba
->params
.ios_per_ctrl
] =
3096 phba
->eh_sgl_hndl_avbl
++;
3103 "phba->io_sgl_hndl_avbl=%d"
3104 "phba->eh_sgl_hndl_avbl=%d \n",
3105 phba
->io_sgl_hndl_avbl
,
3106 phba
->eh_sgl_hndl_avbl
);
3107 mem_descr_sg
= phba
->init_mem
;
3108 mem_descr_sg
+= HWI_MEM_SGE
;
3109 SE_DEBUG(DBG_LVL_8
, "\n mem_descr_sg->num_elements=%d \n",
3110 mem_descr_sg
->num_elements
);
3113 while (idx
< mem_descr_sg
->num_elements
) {
3114 pfrag
= mem_descr_sg
->mem_array
[idx
].virtual_address
;
3117 i
< (mem_descr_sg
->mem_array
[idx
].size
) /
3118 (sizeof(struct iscsi_sge
) * phba
->params
.num_sge_per_io
);
3120 if (arr_index
< phba
->params
.ios_per_ctrl
)
3121 psgl_handle
= phba
->io_sgl_hndl_base
[arr_index
];
3123 psgl_handle
= phba
->eh_sgl_hndl_base
[arr_index
-
3124 phba
->params
.ios_per_ctrl
];
3125 psgl_handle
->pfrag
= pfrag
;
3126 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_hi
, pfrag
, 0);
3127 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_lo
, pfrag
, 0);
3128 pfrag
+= phba
->params
.num_sge_per_io
;
3129 psgl_handle
->sgl_index
=
3130 phba
->fw_config
.iscsi_icd_start
+ arr_index
++;
3134 phba
->io_sgl_free_index
= 0;
3135 phba
->io_sgl_alloc_index
= 0;
3136 phba
->eh_sgl_free_index
= 0;
3137 phba
->eh_sgl_alloc_index
= 0;
3141 static int hba_setup_cid_tbls(struct beiscsi_hba
*phba
)
3145 phba
->cid_array
= kzalloc(sizeof(void *) * phba
->params
.cxns_per_ctrl
,
3147 if (!phba
->cid_array
) {
3148 shost_printk(KERN_ERR
, phba
->shost
,
3149 "Failed to allocate memory in "
3150 "hba_setup_cid_tbls\n");
3153 phba
->ep_array
= kzalloc(sizeof(struct iscsi_endpoint
*) *
3154 phba
->params
.cxns_per_ctrl
* 2, GFP_KERNEL
);
3155 if (!phba
->ep_array
) {
3156 shost_printk(KERN_ERR
, phba
->shost
,
3157 "Failed to allocate memory in "
3158 "hba_setup_cid_tbls \n");
3159 kfree(phba
->cid_array
);
3162 new_cid
= phba
->fw_config
.iscsi_cid_start
;
3163 for (i
= 0; i
< phba
->params
.cxns_per_ctrl
; i
++) {
3164 phba
->cid_array
[i
] = new_cid
;
3167 phba
->avlbl_cids
= phba
->params
.cxns_per_ctrl
;
3171 static unsigned char hwi_enable_intr(struct beiscsi_hba
*phba
)
3173 struct be_ctrl_info
*ctrl
= &phba
->ctrl
;
3174 struct hwi_controller
*phwi_ctrlr
;
3175 struct hwi_context_memory
*phwi_context
;
3176 struct be_queue_info
*eq
;
3181 phwi_ctrlr
= phba
->phwi_ctrlr
;
3182 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
3184 addr
= (u8 __iomem
*) ((u8 __iomem
*) ctrl
->pcicfg
+
3185 PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET
);
3186 reg
= ioread32(addr
);
3187 SE_DEBUG(DBG_LVL_8
, "reg =x%08x \n", reg
);
3189 enabled
= reg
& MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK
;
3191 reg
|= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK
;
3192 SE_DEBUG(DBG_LVL_8
, "reg =x%08x addr=%p \n", reg
, addr
);
3193 iowrite32(reg
, addr
);
3194 if (!phba
->msix_enabled
) {
3195 eq
= &phwi_context
->be_eq
[0].q
;
3196 SE_DEBUG(DBG_LVL_8
, "eq->id=%d \n", eq
->id
);
3197 hwi_ring_eq_db(phba
, eq
->id
, 0, 0, 1, 1);
3199 for (i
= 0; i
<= phba
->num_cpus
; i
++) {
3200 eq
= &phwi_context
->be_eq
[i
].q
;
3201 SE_DEBUG(DBG_LVL_8
, "eq->id=%d \n", eq
->id
);
3202 hwi_ring_eq_db(phba
, eq
->id
, 0, 0, 1, 1);
3209 static void hwi_disable_intr(struct beiscsi_hba
*phba
)
3211 struct be_ctrl_info
*ctrl
= &phba
->ctrl
;
3213 u8 __iomem
*addr
= ctrl
->pcicfg
+ PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET
;
3214 u32 reg
= ioread32(addr
);
3216 u32 enabled
= reg
& MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK
;
3218 reg
&= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK
;
3219 iowrite32(reg
, addr
);
3221 shost_printk(KERN_WARNING
, phba
->shost
,
3222 "In hwi_disable_intr, Already Disabled \n");
3225 static int beiscsi_init_port(struct beiscsi_hba
*phba
)
3229 ret
= beiscsi_init_controller(phba
);
3231 shost_printk(KERN_ERR
, phba
->shost
,
3232 "beiscsi_dev_probe - Failed in"
3233 "beiscsi_init_controller \n");
3236 ret
= beiscsi_init_sgl_handle(phba
);
3238 shost_printk(KERN_ERR
, phba
->shost
,
3239 "beiscsi_dev_probe - Failed in"
3240 "beiscsi_init_sgl_handle \n");
3241 goto do_cleanup_ctrlr
;
3244 if (hba_setup_cid_tbls(phba
)) {
3245 shost_printk(KERN_ERR
, phba
->shost
,
3246 "Failed in hba_setup_cid_tbls\n");
3247 kfree(phba
->io_sgl_hndl_base
);
3248 kfree(phba
->eh_sgl_hndl_base
);
3249 goto do_cleanup_ctrlr
;
3259 static void hwi_purge_eq(struct beiscsi_hba
*phba
)
3261 struct hwi_controller
*phwi_ctrlr
;
3262 struct hwi_context_memory
*phwi_context
;
3263 struct be_queue_info
*eq
;
3264 struct be_eq_entry
*eqe
= NULL
;
3266 unsigned int num_processed
;
3268 phwi_ctrlr
= phba
->phwi_ctrlr
;
3269 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
3270 if (phba
->msix_enabled
)
3275 for (i
= 0; i
< (phba
->num_cpus
+ eq_msix
); i
++) {
3276 eq
= &phwi_context
->be_eq
[i
].q
;
3277 eqe
= queue_tail_node(eq
);
3279 while (eqe
->dw
[offsetof(struct amap_eq_entry
, valid
) / 32]
3281 AMAP_SET_BITS(struct amap_eq_entry
, valid
, eqe
, 0);
3283 eqe
= queue_tail_node(eq
);
3288 hwi_ring_eq_db(phba
, eq
->id
, 1, num_processed
, 1, 1);
3292 static void beiscsi_clean_port(struct beiscsi_hba
*phba
)
3294 unsigned char mgmt_status
;
3296 mgmt_status
= mgmt_epfw_cleanup(phba
, CMD_CONNECTION_CHUTE_0
);
3298 shost_printk(KERN_WARNING
, phba
->shost
,
3299 "mgmt_epfw_cleanup FAILED \n");
3303 kfree(phba
->io_sgl_hndl_base
);
3304 kfree(phba
->eh_sgl_hndl_base
);
3305 kfree(phba
->cid_array
);
3306 kfree(phba
->ep_array
);
3310 beiscsi_offload_connection(struct beiscsi_conn
*beiscsi_conn
,
3311 struct beiscsi_offload_params
*params
)
3313 struct wrb_handle
*pwrb_handle
;
3314 struct iscsi_target_context_update_wrb
*pwrb
= NULL
;
3315 struct be_mem_descriptor
*mem_descr
;
3316 struct beiscsi_hba
*phba
= beiscsi_conn
->phba
;
3320 * We can always use 0 here because it is reserved by libiscsi for
3321 * login/startup related tasks.
3323 pwrb_handle
= alloc_wrb_handle(phba
, (beiscsi_conn
->beiscsi_conn_cid
-
3324 phba
->fw_config
.iscsi_cid_start
));
3325 pwrb
= (struct iscsi_target_context_update_wrb
*)pwrb_handle
->pwrb
;
3326 memset(pwrb
, 0, sizeof(*pwrb
));
3327 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb
,
3328 max_burst_length
, pwrb
, params
->dw
[offsetof
3329 (struct amap_beiscsi_offload_params
,
3330 max_burst_length
) / 32]);
3331 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb
,
3332 max_send_data_segment_length
, pwrb
,
3333 params
->dw
[offsetof(struct amap_beiscsi_offload_params
,
3334 max_send_data_segment_length
) / 32]);
3335 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb
,
3338 params
->dw
[offsetof(struct amap_beiscsi_offload_params
,
3339 first_burst_length
) / 32]);
3341 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb
, erl
, pwrb
,
3342 (params
->dw
[offsetof(struct amap_beiscsi_offload_params
,
3343 erl
) / 32] & OFFLD_PARAMS_ERL
));
3344 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb
, dde
, pwrb
,
3345 (params
->dw
[offsetof(struct amap_beiscsi_offload_params
,
3346 dde
) / 32] & OFFLD_PARAMS_DDE
) >> 2);
3347 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb
, hde
, pwrb
,
3348 (params
->dw
[offsetof(struct amap_beiscsi_offload_params
,
3349 hde
) / 32] & OFFLD_PARAMS_HDE
) >> 3);
3350 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb
, ir2t
, pwrb
,
3351 (params
->dw
[offsetof(struct amap_beiscsi_offload_params
,
3352 ir2t
) / 32] & OFFLD_PARAMS_IR2T
) >> 4);
3353 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb
, imd
, pwrb
,
3354 (params
->dw
[offsetof(struct amap_beiscsi_offload_params
,
3355 imd
) / 32] & OFFLD_PARAMS_IMD
) >> 5);
3356 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb
, stat_sn
,
3358 (params
->dw
[offsetof(struct amap_beiscsi_offload_params
,
3359 exp_statsn
) / 32] + 1));
3360 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb
, type
, pwrb
,
3362 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb
, wrb_idx
,
3363 pwrb
, pwrb_handle
->wrb_index
);
3364 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb
, ptr2nextwrb
,
3365 pwrb
, pwrb_handle
->nxt_wrb_index
);
3366 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb
,
3367 session_state
, pwrb
, 0);
3368 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb
, compltonack
,
3370 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb
, notpredblq
,
3372 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb
, mode
, pwrb
,
3375 mem_descr
= phba
->init_mem
;
3376 mem_descr
+= ISCSI_MEM_GLOBAL_HEADER
;
3378 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb
,
3379 pad_buffer_addr_hi
, pwrb
,
3380 mem_descr
->mem_array
[0].bus_address
.u
.a32
.address_hi
);
3381 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb
,
3382 pad_buffer_addr_lo
, pwrb
,
3383 mem_descr
->mem_array
[0].bus_address
.u
.a32
.address_lo
);
3385 be_dws_le_to_cpu(pwrb
, sizeof(struct iscsi_target_context_update_wrb
));
3387 doorbell
|= beiscsi_conn
->beiscsi_conn_cid
& DB_WRB_POST_CID_MASK
;
3388 doorbell
|= (pwrb_handle
->wrb_index
& DB_DEF_PDU_WRB_INDEX_MASK
)
3389 << DB_DEF_PDU_WRB_INDEX_SHIFT
;
3390 doorbell
|= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT
;
3392 iowrite32(doorbell
, phba
->db_va
+ DB_TXULP0_OFFSET
);
3395 static void beiscsi_parse_pdu(struct iscsi_conn
*conn
, itt_t itt
,
3396 int *index
, int *age
)
3400 *age
= conn
->session
->age
;
3404 * beiscsi_alloc_pdu - allocates pdu and related resources
3405 * @task: libiscsi task
3406 * @opcode: opcode of pdu for task
3408 * This is called with the session lock held. It will allocate
3409 * the wrb and sgl if needed for the command. And it will prep
3410 * the pdu's itt. beiscsi_parse_pdu will later translate
3411 * the pdu itt to the libiscsi task itt.
3413 static int beiscsi_alloc_pdu(struct iscsi_task
*task
, uint8_t opcode
)
3415 struct beiscsi_io_task
*io_task
= task
->dd_data
;
3416 struct iscsi_conn
*conn
= task
->conn
;
3417 struct beiscsi_conn
*beiscsi_conn
= conn
->dd_data
;
3418 struct beiscsi_hba
*phba
= beiscsi_conn
->phba
;
3419 struct hwi_wrb_context
*pwrb_context
;
3420 struct hwi_controller
*phwi_ctrlr
;
3422 struct beiscsi_session
*beiscsi_sess
= beiscsi_conn
->beiscsi_sess
;
3425 io_task
->cmd_bhs
= pci_pool_alloc(beiscsi_sess
->bhs_pool
,
3426 GFP_KERNEL
, &paddr
);
3427 if (!io_task
->cmd_bhs
)
3429 io_task
->bhs_pa
.u
.a64
.address
= paddr
;
3430 io_task
->libiscsi_itt
= (itt_t
)task
->itt
;
3431 io_task
->pwrb_handle
= alloc_wrb_handle(phba
,
3432 beiscsi_conn
->beiscsi_conn_cid
-
3433 phba
->fw_config
.iscsi_cid_start
3435 io_task
->conn
= beiscsi_conn
;
3437 task
->hdr
= (struct iscsi_hdr
*)&io_task
->cmd_bhs
->iscsi_hdr
;
3438 task
->hdr_max
= sizeof(struct be_cmd_bhs
);
3441 spin_lock(&phba
->io_sgl_lock
);
3442 io_task
->psgl_handle
= alloc_io_sgl_handle(phba
);
3443 spin_unlock(&phba
->io_sgl_lock
);
3444 if (!io_task
->psgl_handle
)
3447 io_task
->scsi_cmnd
= NULL
;
3448 if ((opcode
& ISCSI_OPCODE_MASK
) == ISCSI_OP_LOGIN
) {
3449 if (!beiscsi_conn
->login_in_progress
) {
3450 spin_lock(&phba
->mgmt_sgl_lock
);
3451 io_task
->psgl_handle
= (struct sgl_handle
*)
3452 alloc_mgmt_sgl_handle(phba
);
3453 spin_unlock(&phba
->mgmt_sgl_lock
);
3454 if (!io_task
->psgl_handle
)
3457 beiscsi_conn
->login_in_progress
= 1;
3458 beiscsi_conn
->plogin_sgl_handle
=
3459 io_task
->psgl_handle
;
3461 io_task
->psgl_handle
=
3462 beiscsi_conn
->plogin_sgl_handle
;
3465 spin_lock(&phba
->mgmt_sgl_lock
);
3466 io_task
->psgl_handle
= alloc_mgmt_sgl_handle(phba
);
3467 spin_unlock(&phba
->mgmt_sgl_lock
);
3468 if (!io_task
->psgl_handle
)
3472 itt
= (itt_t
) cpu_to_be32(((unsigned int)io_task
->pwrb_handle
->
3473 wrb_index
<< 16) | (unsigned int)
3474 (io_task
->psgl_handle
->sgl_index
));
3475 io_task
->pwrb_handle
->pio_handle
= task
;
3477 io_task
->cmd_bhs
->iscsi_hdr
.itt
= itt
;
3481 phwi_ctrlr
= phba
->phwi_ctrlr
;
3482 pwrb_context
= &phwi_ctrlr
->wrb_context
[
3483 beiscsi_conn
->beiscsi_conn_cid
-
3484 phba
->fw_config
.iscsi_cid_start
];
3485 free_wrb_handle(phba
, pwrb_context
, io_task
->pwrb_handle
);
3486 io_task
->pwrb_handle
= NULL
;
3487 pci_pool_free(beiscsi_sess
->bhs_pool
, io_task
->cmd_bhs
,
3488 io_task
->bhs_pa
.u
.a64
.address
);
3489 SE_DEBUG(DBG_LVL_1
, "Alloc of SGL_ICD Failed \n");
3493 static void beiscsi_cleanup_task(struct iscsi_task
*task
)
3495 struct beiscsi_io_task
*io_task
= task
->dd_data
;
3496 struct iscsi_conn
*conn
= task
->conn
;
3497 struct beiscsi_conn
*beiscsi_conn
= conn
->dd_data
;
3498 struct beiscsi_hba
*phba
= beiscsi_conn
->phba
;
3499 struct beiscsi_session
*beiscsi_sess
= beiscsi_conn
->beiscsi_sess
;
3500 struct hwi_wrb_context
*pwrb_context
;
3501 struct hwi_controller
*phwi_ctrlr
;
3503 phwi_ctrlr
= phba
->phwi_ctrlr
;
3504 pwrb_context
= &phwi_ctrlr
->wrb_context
[beiscsi_conn
->beiscsi_conn_cid
3505 - phba
->fw_config
.iscsi_cid_start
];
3506 if (io_task
->pwrb_handle
) {
3507 free_wrb_handle(phba
, pwrb_context
, io_task
->pwrb_handle
);
3508 io_task
->pwrb_handle
= NULL
;
3511 if (io_task
->cmd_bhs
) {
3512 pci_pool_free(beiscsi_sess
->bhs_pool
, io_task
->cmd_bhs
,
3513 io_task
->bhs_pa
.u
.a64
.address
);
3517 if (io_task
->psgl_handle
) {
3518 spin_lock(&phba
->io_sgl_lock
);
3519 free_io_sgl_handle(phba
, io_task
->psgl_handle
);
3520 spin_unlock(&phba
->io_sgl_lock
);
3521 io_task
->psgl_handle
= NULL
;
3524 if ((task
->hdr
->opcode
& ISCSI_OPCODE_MASK
) == ISCSI_OP_LOGIN
)
3526 if (io_task
->psgl_handle
) {
3527 spin_lock(&phba
->mgmt_sgl_lock
);
3528 free_mgmt_sgl_handle(phba
, io_task
->psgl_handle
);
3529 spin_unlock(&phba
->mgmt_sgl_lock
);
3530 io_task
->psgl_handle
= NULL
;
3535 static int beiscsi_iotask(struct iscsi_task
*task
, struct scatterlist
*sg
,
3536 unsigned int num_sg
, unsigned int xferlen
,
3537 unsigned int writedir
)
3540 struct beiscsi_io_task
*io_task
= task
->dd_data
;
3541 struct iscsi_conn
*conn
= task
->conn
;
3542 struct beiscsi_conn
*beiscsi_conn
= conn
->dd_data
;
3543 struct beiscsi_hba
*phba
= beiscsi_conn
->phba
;
3544 struct iscsi_wrb
*pwrb
= NULL
;
3545 unsigned int doorbell
= 0;
3547 pwrb
= io_task
->pwrb_handle
->pwrb
;
3548 io_task
->cmd_bhs
->iscsi_hdr
.exp_statsn
= 0;
3549 io_task
->bhs_len
= sizeof(struct be_cmd_bhs
);
3552 memset(&io_task
->cmd_bhs
->iscsi_data_pdu
, 0, 48);
3553 AMAP_SET_BITS(struct amap_pdu_data_out
, itt
,
3554 &io_task
->cmd_bhs
->iscsi_data_pdu
,
3555 (unsigned int)io_task
->cmd_bhs
->iscsi_hdr
.itt
);
3556 AMAP_SET_BITS(struct amap_pdu_data_out
, opcode
,
3557 &io_task
->cmd_bhs
->iscsi_data_pdu
,
3558 ISCSI_OPCODE_SCSI_DATA_OUT
);
3559 AMAP_SET_BITS(struct amap_pdu_data_out
, final_bit
,
3560 &io_task
->cmd_bhs
->iscsi_data_pdu
, 1);
3561 AMAP_SET_BITS(struct amap_iscsi_wrb
, type
, pwrb
,
3563 AMAP_SET_BITS(struct amap_iscsi_wrb
, dsp
, pwrb
, 1);
3565 AMAP_SET_BITS(struct amap_iscsi_wrb
, type
, pwrb
,
3567 AMAP_SET_BITS(struct amap_iscsi_wrb
, dsp
, pwrb
, 0);
3569 memcpy(&io_task
->cmd_bhs
->iscsi_data_pdu
.
3570 dw
[offsetof(struct amap_pdu_data_out
, lun
) / 32],
3571 io_task
->cmd_bhs
->iscsi_hdr
.lun
, sizeof(struct scsi_lun
));
3573 AMAP_SET_BITS(struct amap_iscsi_wrb
, lun
, pwrb
,
3574 cpu_to_be16((unsigned short)io_task
->cmd_bhs
->iscsi_hdr
.
3576 AMAP_SET_BITS(struct amap_iscsi_wrb
, r2t_exp_dtl
, pwrb
, xferlen
);
3577 AMAP_SET_BITS(struct amap_iscsi_wrb
, wrb_idx
, pwrb
,
3578 io_task
->pwrb_handle
->wrb_index
);
3579 AMAP_SET_BITS(struct amap_iscsi_wrb
, cmdsn_itt
, pwrb
,
3580 be32_to_cpu(task
->cmdsn
));
3581 AMAP_SET_BITS(struct amap_iscsi_wrb
, sgl_icd_idx
, pwrb
,
3582 io_task
->psgl_handle
->sgl_index
);
3584 hwi_write_sgl(pwrb
, sg
, num_sg
, io_task
);
3586 AMAP_SET_BITS(struct amap_iscsi_wrb
, ptr2nextwrb
, pwrb
,
3587 io_task
->pwrb_handle
->nxt_wrb_index
);
3588 be_dws_le_to_cpu(pwrb
, sizeof(struct iscsi_wrb
));
3590 doorbell
|= beiscsi_conn
->beiscsi_conn_cid
& DB_WRB_POST_CID_MASK
;
3591 doorbell
|= (io_task
->pwrb_handle
->wrb_index
&
3592 DB_DEF_PDU_WRB_INDEX_MASK
) << DB_DEF_PDU_WRB_INDEX_SHIFT
;
3593 doorbell
|= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT
;
3595 iowrite32(doorbell
, phba
->db_va
+ DB_TXULP0_OFFSET
);
3599 static int beiscsi_mtask(struct iscsi_task
*task
)
3601 struct beiscsi_io_task
*io_task
= task
->dd_data
;
3602 struct iscsi_conn
*conn
= task
->conn
;
3603 struct beiscsi_conn
*beiscsi_conn
= conn
->dd_data
;
3604 struct beiscsi_hba
*phba
= beiscsi_conn
->phba
;
3605 struct iscsi_wrb
*pwrb
= NULL
;
3606 unsigned int doorbell
= 0;
3609 cid
= beiscsi_conn
->beiscsi_conn_cid
;
3610 pwrb
= io_task
->pwrb_handle
->pwrb
;
3611 memset(pwrb
, 0, sizeof(*pwrb
));
3612 AMAP_SET_BITS(struct amap_iscsi_wrb
, cmdsn_itt
, pwrb
,
3613 be32_to_cpu(task
->cmdsn
));
3614 AMAP_SET_BITS(struct amap_iscsi_wrb
, wrb_idx
, pwrb
,
3615 io_task
->pwrb_handle
->wrb_index
);
3616 AMAP_SET_BITS(struct amap_iscsi_wrb
, sgl_icd_idx
, pwrb
,
3617 io_task
->psgl_handle
->sgl_index
);
3619 switch (task
->hdr
->opcode
& ISCSI_OPCODE_MASK
) {
3620 case ISCSI_OP_LOGIN
:
3621 AMAP_SET_BITS(struct amap_iscsi_wrb
, type
, pwrb
,
3623 AMAP_SET_BITS(struct amap_iscsi_wrb
, dmsg
, pwrb
, 0);
3624 AMAP_SET_BITS(struct amap_iscsi_wrb
, cmdsn_itt
, pwrb
, 1);
3625 hwi_write_buffer(pwrb
, task
);
3627 case ISCSI_OP_NOOP_OUT
:
3628 AMAP_SET_BITS(struct amap_iscsi_wrb
, type
, pwrb
,
3630 if (task
->hdr
->ttt
== ISCSI_RESERVED_TAG
)
3631 AMAP_SET_BITS(struct amap_iscsi_wrb
, dmsg
, pwrb
, 0);
3633 AMAP_SET_BITS(struct amap_iscsi_wrb
, dmsg
, pwrb
, 1);
3634 hwi_write_buffer(pwrb
, task
);
3637 AMAP_SET_BITS(struct amap_iscsi_wrb
, type
, pwrb
,
3639 AMAP_SET_BITS(struct amap_iscsi_wrb
, dmsg
, pwrb
, 0);
3640 hwi_write_buffer(pwrb
, task
);
3642 case ISCSI_OP_SCSI_TMFUNC
:
3643 AMAP_SET_BITS(struct amap_iscsi_wrb
, type
, pwrb
,
3645 AMAP_SET_BITS(struct amap_iscsi_wrb
, dmsg
, pwrb
, 0);
3646 hwi_write_buffer(pwrb
, task
);
3648 case ISCSI_OP_LOGOUT
:
3649 AMAP_SET_BITS(struct amap_iscsi_wrb
, dmsg
, pwrb
, 0);
3650 AMAP_SET_BITS(struct amap_iscsi_wrb
, type
, pwrb
,
3652 hwi_write_buffer(pwrb
, task
);
3656 SE_DEBUG(DBG_LVL_1
, "opcode =%d Not supported \n",
3657 task
->hdr
->opcode
& ISCSI_OPCODE_MASK
);
3661 AMAP_SET_BITS(struct amap_iscsi_wrb
, r2t_exp_dtl
, pwrb
,
3663 AMAP_SET_BITS(struct amap_iscsi_wrb
, ptr2nextwrb
, pwrb
,
3664 io_task
->pwrb_handle
->nxt_wrb_index
);
3665 be_dws_le_to_cpu(pwrb
, sizeof(struct iscsi_wrb
));
3667 doorbell
|= cid
& DB_WRB_POST_CID_MASK
;
3668 doorbell
|= (io_task
->pwrb_handle
->wrb_index
&
3669 DB_DEF_PDU_WRB_INDEX_MASK
) << DB_DEF_PDU_WRB_INDEX_SHIFT
;
3670 doorbell
|= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT
;
3671 iowrite32(doorbell
, phba
->db_va
+ DB_TXULP0_OFFSET
);
3675 static int beiscsi_task_xmit(struct iscsi_task
*task
)
3677 struct beiscsi_io_task
*io_task
= task
->dd_data
;
3678 struct scsi_cmnd
*sc
= task
->sc
;
3679 struct scatterlist
*sg
;
3681 unsigned int writedir
= 0, xferlen
= 0;
3684 return beiscsi_mtask(task
);
3686 io_task
->scsi_cmnd
= sc
;
3687 num_sg
= scsi_dma_map(sc
);
3689 SE_DEBUG(DBG_LVL_1
, " scsi_dma_map Failed\n")
3692 SE_DEBUG(DBG_LVL_4
, "xferlen=0x%08x scmd=%p num_sg=%d sernum=%lu\n",
3693 (scsi_bufflen(sc
)), sc
, num_sg
, sc
->serial_number
);
3694 xferlen
= scsi_bufflen(sc
);
3695 sg
= scsi_sglist(sc
);
3696 if (sc
->sc_data_direction
== DMA_TO_DEVICE
) {
3698 SE_DEBUG(DBG_LVL_4
, "task->imm_count=0x%08x \n",
3702 return beiscsi_iotask(task
, sg
, num_sg
, xferlen
, writedir
);
3705 static void beiscsi_remove(struct pci_dev
*pcidev
)
3707 struct beiscsi_hba
*phba
= NULL
;
3708 struct hwi_controller
*phwi_ctrlr
;
3709 struct hwi_context_memory
*phwi_context
;
3710 struct be_eq_obj
*pbe_eq
;
3711 unsigned int i
, msix_vec
;
3713 phba
= (struct beiscsi_hba
*)pci_get_drvdata(pcidev
);
3715 dev_err(&pcidev
->dev
, "beiscsi_remove called with no phba \n");
3719 phwi_ctrlr
= phba
->phwi_ctrlr
;
3720 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
3721 hwi_disable_intr(phba
);
3722 if (phba
->msix_enabled
) {
3723 for (i
= 0; i
<= phba
->num_cpus
; i
++) {
3724 msix_vec
= phba
->msix_entries
[i
].vector
;
3725 free_irq(msix_vec
, &phwi_context
->be_eq
[i
]);
3728 if (phba
->pcidev
->irq
)
3729 free_irq(phba
->pcidev
->irq
, phba
);
3730 pci_disable_msix(phba
->pcidev
);
3731 destroy_workqueue(phba
->wq
);
3732 if (blk_iopoll_enabled
)
3733 for (i
= 0; i
< phba
->num_cpus
; i
++) {
3734 pbe_eq
= &phwi_context
->be_eq
[i
];
3735 blk_iopoll_disable(&pbe_eq
->iopoll
);
3738 beiscsi_clean_port(phba
);
3739 beiscsi_free_mem(phba
);
3740 beiscsi_unmap_pci_function(phba
);
3741 pci_free_consistent(phba
->pcidev
,
3742 phba
->ctrl
.mbox_mem_alloced
.size
,
3743 phba
->ctrl
.mbox_mem_alloced
.va
,
3744 phba
->ctrl
.mbox_mem_alloced
.dma
);
3745 iscsi_host_remove(phba
->shost
);
3746 pci_dev_put(phba
->pcidev
);
3747 iscsi_host_free(phba
->shost
);
3750 static void beiscsi_msix_enable(struct beiscsi_hba
*phba
)
3754 for (i
= 0; i
<= phba
->num_cpus
; i
++)
3755 phba
->msix_entries
[i
].entry
= i
;
3757 status
= pci_enable_msix(phba
->pcidev
, phba
->msix_entries
,
3758 (phba
->num_cpus
+ 1));
3760 phba
->msix_enabled
= true;
3765 static int __devinit
beiscsi_dev_probe(struct pci_dev
*pcidev
,
3766 const struct pci_device_id
*id
)
3768 struct beiscsi_hba
*phba
= NULL
;
3769 struct hwi_controller
*phwi_ctrlr
;
3770 struct hwi_context_memory
*phwi_context
;
3771 struct be_eq_obj
*pbe_eq
;
3772 int ret
, msix_vec
, num_cpus
, i
;
3774 ret
= beiscsi_enable_pci(pcidev
);
3776 shost_printk(KERN_ERR
, phba
->shost
, "beiscsi_dev_probe-"
3777 "Failed to enable pci device \n");
3781 phba
= beiscsi_hba_alloc(pcidev
);
3783 dev_err(&pcidev
->dev
, "beiscsi_dev_probe-"
3784 " Failed in beiscsi_hba_alloc \n");
3788 switch (pcidev
->device
) {
3792 phba
->generation
= BE_GEN2
;
3796 phba
->generation
= BE_GEN3
;
3799 phba
->generation
= 0;
3803 num_cpus
= find_num_cpus();
3806 phba
->num_cpus
= num_cpus
;
3807 SE_DEBUG(DBG_LVL_8
, "num_cpus = %d \n", phba
->num_cpus
);
3810 beiscsi_msix_enable(phba
);
3811 ret
= be_ctrl_init(phba
, pcidev
);
3813 shost_printk(KERN_ERR
, phba
->shost
, "beiscsi_dev_probe-"
3814 "Failed in be_ctrl_init\n");
3818 spin_lock_init(&phba
->io_sgl_lock
);
3819 spin_lock_init(&phba
->mgmt_sgl_lock
);
3820 spin_lock_init(&phba
->isr_lock
);
3821 ret
= mgmt_get_fw_config(&phba
->ctrl
, phba
);
3823 shost_printk(KERN_ERR
, phba
->shost
,
3824 "Error getting fw config\n");
3827 phba
->shost
->max_id
= phba
->fw_config
.iscsi_cid_count
;
3828 beiscsi_get_params(phba
);
3829 phba
->shost
->can_queue
= phba
->params
.ios_per_ctrl
;
3830 ret
= beiscsi_init_port(phba
);
3832 shost_printk(KERN_ERR
, phba
->shost
, "beiscsi_dev_probe-"
3833 "Failed in beiscsi_init_port\n");
3837 for (i
= 0; i
< MAX_MCC_CMD
; i
++) {
3838 init_waitqueue_head(&phba
->ctrl
.mcc_wait
[i
+ 1]);
3839 phba
->ctrl
.mcc_tag
[i
] = i
+ 1;
3840 phba
->ctrl
.mcc_numtag
[i
+ 1] = 0;
3841 phba
->ctrl
.mcc_tag_available
++;
3844 phba
->ctrl
.mcc_alloc_index
= phba
->ctrl
.mcc_free_index
= 0;
3846 snprintf(phba
->wq_name
, sizeof(phba
->wq_name
), "beiscsi_q_irq%u",
3847 phba
->shost
->host_no
);
3848 phba
->wq
= create_workqueue(phba
->wq_name
);
3850 shost_printk(KERN_ERR
, phba
->shost
, "beiscsi_dev_probe-"
3851 "Failed to allocate work queue\n");
3855 INIT_WORK(&phba
->work_cqs
, beiscsi_process_all_cqs
);
3857 phwi_ctrlr
= phba
->phwi_ctrlr
;
3858 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
3859 if (blk_iopoll_enabled
) {
3860 for (i
= 0; i
< phba
->num_cpus
; i
++) {
3861 pbe_eq
= &phwi_context
->be_eq
[i
];
3862 blk_iopoll_init(&pbe_eq
->iopoll
, be_iopoll_budget
,
3864 blk_iopoll_enable(&pbe_eq
->iopoll
);
3867 ret
= beiscsi_init_irqs(phba
);
3869 shost_printk(KERN_ERR
, phba
->shost
, "beiscsi_dev_probe-"
3870 "Failed to beiscsi_init_irqs\n");
3873 ret
= hwi_enable_intr(phba
);
3875 shost_printk(KERN_ERR
, phba
->shost
, "beiscsi_dev_probe-"
3876 "Failed to hwi_enable_intr\n");
3879 SE_DEBUG(DBG_LVL_8
, "\n\n\n SUCCESS - DRIVER LOADED \n\n\n");
3883 if (phba
->msix_enabled
) {
3884 for (i
= 0; i
<= phba
->num_cpus
; i
++) {
3885 msix_vec
= phba
->msix_entries
[i
].vector
;
3886 free_irq(msix_vec
, &phwi_context
->be_eq
[i
]);
3889 if (phba
->pcidev
->irq
)
3890 free_irq(phba
->pcidev
->irq
, phba
);
3891 pci_disable_msix(phba
->pcidev
);
3893 destroy_workqueue(phba
->wq
);
3894 if (blk_iopoll_enabled
)
3895 for (i
= 0; i
< phba
->num_cpus
; i
++) {
3896 pbe_eq
= &phwi_context
->be_eq
[i
];
3897 blk_iopoll_disable(&pbe_eq
->iopoll
);
3900 beiscsi_clean_port(phba
);
3901 beiscsi_free_mem(phba
);
3903 pci_free_consistent(phba
->pcidev
,
3904 phba
->ctrl
.mbox_mem_alloced
.size
,
3905 phba
->ctrl
.mbox_mem_alloced
.va
,
3906 phba
->ctrl
.mbox_mem_alloced
.dma
);
3907 beiscsi_unmap_pci_function(phba
);
3909 iscsi_host_remove(phba
->shost
);
3910 pci_dev_put(phba
->pcidev
);
3911 iscsi_host_free(phba
->shost
);
3913 pci_disable_device(pcidev
);
3917 struct iscsi_transport beiscsi_iscsi_transport
= {
3918 .owner
= THIS_MODULE
,
3920 .caps
= CAP_RECOVERY_L0
| CAP_HDRDGST
| CAP_TEXT_NEGO
|
3921 CAP_MULTI_R2T
| CAP_DATADGST
| CAP_DATA_PATH_OFFLOAD
,
3922 .param_mask
= ISCSI_MAX_RECV_DLENGTH
|
3923 ISCSI_MAX_XMIT_DLENGTH
|
3926 ISCSI_INITIAL_R2T_EN
|
3931 ISCSI_PDU_INORDER_EN
|
3932 ISCSI_DATASEQ_INORDER_EN
|
3935 ISCSI_CONN_ADDRESS
|
3937 ISCSI_PERSISTENT_PORT
|
3938 ISCSI_PERSISTENT_ADDRESS
|
3939 ISCSI_TARGET_NAME
| ISCSI_TPGT
|
3940 ISCSI_USERNAME
| ISCSI_PASSWORD
|
3941 ISCSI_USERNAME_IN
| ISCSI_PASSWORD_IN
|
3942 ISCSI_FAST_ABORT
| ISCSI_ABORT_TMO
|
3943 ISCSI_LU_RESET_TMO
|
3944 ISCSI_PING_TMO
| ISCSI_RECV_TMO
|
3945 ISCSI_IFACE_NAME
| ISCSI_INITIATOR_NAME
,
3946 .host_param_mask
= ISCSI_HOST_HWADDRESS
| ISCSI_HOST_IPADDRESS
|
3947 ISCSI_HOST_INITIATOR_NAME
,
3948 .create_session
= beiscsi_session_create
,
3949 .destroy_session
= beiscsi_session_destroy
,
3950 .create_conn
= beiscsi_conn_create
,
3951 .bind_conn
= beiscsi_conn_bind
,
3952 .destroy_conn
= iscsi_conn_teardown
,
3953 .set_param
= beiscsi_set_param
,
3954 .get_conn_param
= beiscsi_conn_get_param
,
3955 .get_session_param
= iscsi_session_get_param
,
3956 .get_host_param
= beiscsi_get_host_param
,
3957 .start_conn
= beiscsi_conn_start
,
3958 .stop_conn
= beiscsi_conn_stop
,
3959 .send_pdu
= iscsi_conn_send_pdu
,
3960 .xmit_task
= beiscsi_task_xmit
,
3961 .cleanup_task
= beiscsi_cleanup_task
,
3962 .alloc_pdu
= beiscsi_alloc_pdu
,
3963 .parse_pdu_itt
= beiscsi_parse_pdu
,
3964 .get_stats
= beiscsi_conn_get_stats
,
3965 .ep_connect
= beiscsi_ep_connect
,
3966 .ep_poll
= beiscsi_ep_poll
,
3967 .ep_disconnect
= beiscsi_ep_disconnect
,
3968 .session_recovery_timedout
= iscsi_session_recovery_timedout
,
3971 static struct pci_driver beiscsi_pci_driver
= {
3973 .probe
= beiscsi_dev_probe
,
3974 .remove
= beiscsi_remove
,
3975 .id_table
= beiscsi_pci_id_table
3979 static int __init
beiscsi_module_init(void)
3983 beiscsi_scsi_transport
=
3984 iscsi_register_transport(&beiscsi_iscsi_transport
);
3985 if (!beiscsi_scsi_transport
) {
3987 "beiscsi_module_init - Unable to register beiscsi"
3991 SE_DEBUG(DBG_LVL_8
, "In beiscsi_module_init, tt=%p \n",
3992 &beiscsi_iscsi_transport
);
3994 ret
= pci_register_driver(&beiscsi_pci_driver
);
3997 "beiscsi_module_init - Unable to register"
3998 "beiscsi pci driver.\n");
3999 goto unregister_iscsi_transport
;
4003 unregister_iscsi_transport
:
4004 iscsi_unregister_transport(&beiscsi_iscsi_transport
);
4008 static void __exit
beiscsi_module_exit(void)
4010 pci_unregister_driver(&beiscsi_pci_driver
);
4011 iscsi_unregister_transport(&beiscsi_iscsi_transport
);
4014 module_init(beiscsi_module_init
);
4015 module_exit(beiscsi_module_exit
);