2 * Copyright 2017 Broadcom. All Rights Reserved.
3 * The term "Broadcom" refers to Broadcom Limited and/or its subsidiaries.
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 * Contact Information:
11 * linux-drivers@broadcom.com
15 #include <linux/reboot.h>
16 #include <linux/delay.h>
17 #include <linux/slab.h>
18 #include <linux/interrupt.h>
19 #include <linux/blkdev.h>
20 #include <linux/pci.h>
21 #include <linux/string.h>
22 #include <linux/kernel.h>
23 #include <linux/semaphore.h>
24 #include <linux/iscsi_boot_sysfs.h>
25 #include <linux/module.h>
26 #include <linux/bsg-lib.h>
27 #include <linux/irq_poll.h>
29 #include <scsi/libiscsi.h>
30 #include <scsi/scsi_bsg_iscsi.h>
31 #include <scsi/scsi_netlink.h>
32 #include <scsi/scsi_transport_iscsi.h>
33 #include <scsi/scsi_transport.h>
34 #include <scsi/scsi_cmnd.h>
35 #include <scsi/scsi_device.h>
36 #include <scsi/scsi_host.h>
37 #include <scsi/scsi.h>
43 static unsigned int be_iopoll_budget = 10;
44 static unsigned int be_max_phys_size = 64;
45 static unsigned int enable_msix = 1;
47 MODULE_DESCRIPTION(DRV_DESC " " BUILD_STR);
48 MODULE_VERSION(BUILD_STR);
49 MODULE_AUTHOR("Emulex Corporation");
50 MODULE_LICENSE("GPL");
51 module_param(be_iopoll_budget, int, 0);
52 module_param(enable_msix, int, 0);
53 module_param(be_max_phys_size, uint, S_IRUGO);
54 MODULE_PARM_DESC(be_max_phys_size,
55 "Maximum Size (In Kilobytes) of physically contiguous "
56 "memory that can be allocated. Range is 16 - 128");
58 #define beiscsi_disp_param(_name)\
60 beiscsi_##_name##_disp(struct device *dev,\
61 struct device_attribute *attrib, char *buf) \
63 struct Scsi_Host *shost = class_to_shost(dev);\
64 struct beiscsi_hba *phba = iscsi_host_priv(shost); \
65 return snprintf(buf, PAGE_SIZE, "%d\n",\
69 #define beiscsi_change_param(_name, _minval, _maxval, _defaval)\
71 beiscsi_##_name##_change(struct beiscsi_hba *phba, uint32_t val)\
73 if (val >= _minval && val <= _maxval) {\
74 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,\
75 "BA_%d : beiscsi_"#_name" updated "\
76 "from 0x%x ==> 0x%x\n",\
77 phba->attr_##_name, val); \
78 phba->attr_##_name = val;\
81 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, \
82 "BA_%d beiscsi_"#_name" attribute "\
83 "cannot be updated to 0x%x, "\
84 "range allowed is ["#_minval" - "#_maxval"]\n", val);\
88 #define beiscsi_store_param(_name) \
90 beiscsi_##_name##_store(struct device *dev,\
91 struct device_attribute *attr, const char *buf,\
94 struct Scsi_Host *shost = class_to_shost(dev);\
95 struct beiscsi_hba *phba = iscsi_host_priv(shost);\
96 uint32_t param_val = 0;\
97 if (!isdigit(buf[0]))\
99 if (sscanf(buf, "%i", ¶m_val) != 1)\
101 if (beiscsi_##_name##_change(phba, param_val) == 0) \
107 #define beiscsi_init_param(_name, _minval, _maxval, _defval) \
109 beiscsi_##_name##_init(struct beiscsi_hba *phba, uint32_t val) \
111 if (val >= _minval && val <= _maxval) {\
112 phba->attr_##_name = val;\
115 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,\
116 "BA_%d beiscsi_"#_name" attribute " \
117 "cannot be updated to 0x%x, "\
118 "range allowed is ["#_minval" - "#_maxval"]\n", val);\
119 phba->attr_##_name = _defval;\
123 #define BEISCSI_RW_ATTR(_name, _minval, _maxval, _defval, _descp) \
124 static uint beiscsi_##_name = _defval;\
125 module_param(beiscsi_##_name, uint, S_IRUGO);\
126 MODULE_PARM_DESC(beiscsi_##_name, _descp);\
127 beiscsi_disp_param(_name)\
128 beiscsi_change_param(_name, _minval, _maxval, _defval)\
129 beiscsi_store_param(_name)\
130 beiscsi_init_param(_name, _minval, _maxval, _defval)\
131 DEVICE_ATTR(beiscsi_##_name, S_IRUGO | S_IWUSR,\
132 beiscsi_##_name##_disp, beiscsi_##_name##_store)
135 * When new log level added update the
136 * the MAX allowed value for log_enable
138 BEISCSI_RW_ATTR(log_enable, 0x00,
139 0xFF, 0x00, "Enable logging Bit Mask\n"
140 "\t\t\t\tInitialization Events : 0x01\n"
141 "\t\t\t\tMailbox Events : 0x02\n"
142 "\t\t\t\tMiscellaneous Events : 0x04\n"
143 "\t\t\t\tError Handling : 0x08\n"
144 "\t\t\t\tIO Path Events : 0x10\n"
145 "\t\t\t\tConfiguration Path : 0x20\n"
146 "\t\t\t\tiSCSI Protocol : 0x40\n");
148 DEVICE_ATTR(beiscsi_drvr_ver, S_IRUGO, beiscsi_drvr_ver_disp, NULL);
149 DEVICE_ATTR(beiscsi_adapter_family, S_IRUGO, beiscsi_adap_family_disp, NULL);
150 DEVICE_ATTR(beiscsi_fw_ver, S_IRUGO, beiscsi_fw_ver_disp, NULL);
151 DEVICE_ATTR(beiscsi_phys_port, S_IRUGO, beiscsi_phys_port_disp, NULL);
152 DEVICE_ATTR(beiscsi_active_session_count, S_IRUGO,
153 beiscsi_active_session_disp, NULL);
154 DEVICE_ATTR(beiscsi_free_session_count, S_IRUGO,
155 beiscsi_free_session_disp, NULL);
156 struct device_attribute *beiscsi_attrs[] = {
157 &dev_attr_beiscsi_log_enable,
158 &dev_attr_beiscsi_drvr_ver,
159 &dev_attr_beiscsi_adapter_family,
160 &dev_attr_beiscsi_fw_ver,
161 &dev_attr_beiscsi_active_session_count,
162 &dev_attr_beiscsi_free_session_count,
163 &dev_attr_beiscsi_phys_port,
167 static char const *cqe_desc[] = {
170 "SOL_CMD_KILLED_DATA_DIGEST_ERR",
171 "CXN_KILLED_PDU_SIZE_EXCEEDS_DSL",
172 "CXN_KILLED_BURST_LEN_MISMATCH",
173 "CXN_KILLED_AHS_RCVD",
174 "CXN_KILLED_HDR_DIGEST_ERR",
175 "CXN_KILLED_UNKNOWN_HDR",
176 "CXN_KILLED_STALE_ITT_TTT_RCVD",
177 "CXN_KILLED_INVALID_ITT_TTT_RCVD",
178 "CXN_KILLED_RST_RCVD",
179 "CXN_KILLED_TIMED_OUT",
180 "CXN_KILLED_RST_SENT",
181 "CXN_KILLED_FIN_RCVD",
182 "CXN_KILLED_BAD_UNSOL_PDU_RCVD",
183 "CXN_KILLED_BAD_WRB_INDEX_ERROR",
184 "CXN_KILLED_OVER_RUN_RESIDUAL",
185 "CXN_KILLED_UNDER_RUN_RESIDUAL",
186 "CMD_KILLED_INVALID_STATSN_RCVD",
187 "CMD_KILLED_INVALID_R2T_RCVD",
188 "CMD_CXN_KILLED_LUN_INVALID",
189 "CMD_CXN_KILLED_ICD_INVALID",
190 "CMD_CXN_KILLED_ITT_INVALID",
191 "CMD_CXN_KILLED_SEQ_OUTOFORDER",
192 "CMD_CXN_KILLED_INVALID_DATASN_RCVD",
193 "CXN_INVALIDATE_NOTIFY",
194 "CXN_INVALIDATE_INDEX_NOTIFY",
195 "CMD_INVALIDATED_NOTIFY",
198 "UNSOL_DATA_DIGEST_ERROR_NOTIFY",
200 "CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN",
201 "SOL_CMD_KILLED_DIF_ERR",
202 "CXN_KILLED_SYN_RCVD",
203 "CXN_KILLED_IMM_DATA_RCVD"
206 static int beiscsi_slave_configure(struct scsi_device *sdev)
208 blk_queue_max_segment_size(sdev->request_queue, 65536);
212 static int beiscsi_eh_abort(struct scsi_cmnd *sc)
214 struct iscsi_task *abrt_task = (struct iscsi_task *)sc->SCp.ptr;
215 struct iscsi_cls_session *cls_session;
216 struct beiscsi_io_task *abrt_io_task;
217 struct beiscsi_conn *beiscsi_conn;
218 struct iscsi_session *session;
219 struct invldt_cmd_tbl inv_tbl;
220 struct beiscsi_hba *phba;
221 struct iscsi_conn *conn;
224 cls_session = starget_to_session(scsi_target(sc->device));
225 session = cls_session->dd_data;
227 /* check if we raced, task just got cleaned up under us */
228 spin_lock_bh(&session->back_lock);
229 if (!abrt_task || !abrt_task->sc) {
230 spin_unlock_bh(&session->back_lock);
233 /* get a task ref till FW processes the req for the ICD used */
234 __iscsi_get_task(abrt_task);
235 abrt_io_task = abrt_task->dd_data;
236 conn = abrt_task->conn;
237 beiscsi_conn = conn->dd_data;
238 phba = beiscsi_conn->phba;
239 /* mark WRB invalid which have been not processed by FW yet */
240 if (is_chip_be2_be3r(phba)) {
241 AMAP_SET_BITS(struct amap_iscsi_wrb, invld,
242 abrt_io_task->pwrb_handle->pwrb, 1);
244 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, invld,
245 abrt_io_task->pwrb_handle->pwrb, 1);
247 inv_tbl.cid = beiscsi_conn->beiscsi_conn_cid;
248 inv_tbl.icd = abrt_io_task->psgl_handle->sgl_index;
249 spin_unlock_bh(&session->back_lock);
251 rc = beiscsi_mgmt_invalidate_icds(phba, &inv_tbl, 1);
252 iscsi_put_task(abrt_task);
254 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH,
255 "BM_%d : sc %p invalidation failed %d\n",
260 return iscsi_eh_abort(sc);
263 static int beiscsi_eh_device_reset(struct scsi_cmnd *sc)
265 struct beiscsi_invldt_cmd_tbl {
266 struct invldt_cmd_tbl tbl[BE_INVLDT_CMD_TBL_SZ];
267 struct iscsi_task *task[BE_INVLDT_CMD_TBL_SZ];
269 struct iscsi_cls_session *cls_session;
270 struct beiscsi_conn *beiscsi_conn;
271 struct beiscsi_io_task *io_task;
272 struct iscsi_session *session;
273 struct beiscsi_hba *phba;
274 struct iscsi_conn *conn;
275 struct iscsi_task *task;
276 unsigned int i, nents;
279 cls_session = starget_to_session(scsi_target(sc->device));
280 session = cls_session->dd_data;
282 spin_lock_bh(&session->frwd_lock);
283 if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN) {
284 spin_unlock_bh(&session->frwd_lock);
288 conn = session->leadconn;
289 beiscsi_conn = conn->dd_data;
290 phba = beiscsi_conn->phba;
292 inv_tbl = kzalloc(sizeof(*inv_tbl), GFP_ATOMIC);
294 spin_unlock_bh(&session->frwd_lock);
295 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
296 "BM_%d : invldt_cmd_tbl alloc failed\n");
300 /* take back_lock to prevent task from getting cleaned up under us */
301 spin_lock(&session->back_lock);
302 for (i = 0; i < conn->session->cmds_max; i++) {
303 task = conn->session->cmds[i];
307 if (sc->device->lun != task->sc->device->lun)
310 * Can't fit in more cmds? Normally this won't happen b'coz
311 * BEISCSI_CMD_PER_LUN is same as BE_INVLDT_CMD_TBL_SZ.
313 if (nents == BE_INVLDT_CMD_TBL_SZ) {
318 /* get a task ref till FW processes the req for the ICD used */
319 __iscsi_get_task(task);
320 io_task = task->dd_data;
321 /* mark WRB invalid which have been not processed by FW yet */
322 if (is_chip_be2_be3r(phba)) {
323 AMAP_SET_BITS(struct amap_iscsi_wrb, invld,
324 io_task->pwrb_handle->pwrb, 1);
326 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, invld,
327 io_task->pwrb_handle->pwrb, 1);
330 inv_tbl->tbl[nents].cid = beiscsi_conn->beiscsi_conn_cid;
331 inv_tbl->tbl[nents].icd = io_task->psgl_handle->sgl_index;
332 inv_tbl->task[nents] = task;
335 spin_unlock(&session->back_lock);
336 spin_unlock_bh(&session->frwd_lock);
343 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
344 "BM_%d : number of cmds exceeds size of invalidation table\n");
349 if (beiscsi_mgmt_invalidate_icds(phba, &inv_tbl->tbl[0], nents)) {
350 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH,
351 "BM_%d : cid %u scmds invalidation failed\n",
352 beiscsi_conn->beiscsi_conn_cid);
357 for (i = 0; i < nents; i++)
358 iscsi_put_task(inv_tbl->task[i]);
362 rc = iscsi_eh_device_reset(sc);
366 /*------------------- PCI Driver operations and data ----------------- */
367 static const struct pci_device_id beiscsi_pci_id_table[] = {
368 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) },
369 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) },
370 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) },
371 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) },
372 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID3) },
373 { PCI_DEVICE(ELX_VENDOR_ID, OC_SKH_ID1) },
376 MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
379 static struct scsi_host_template beiscsi_sht = {
380 .module = THIS_MODULE,
381 .name = "Emulex 10Gbe open-iscsi Initiator Driver",
382 .proc_name = DRV_NAME,
383 .queuecommand = iscsi_queuecommand,
384 .change_queue_depth = scsi_change_queue_depth,
385 .slave_configure = beiscsi_slave_configure,
386 .target_alloc = iscsi_target_alloc,
387 .eh_timed_out = iscsi_eh_cmd_timed_out,
388 .eh_abort_handler = beiscsi_eh_abort,
389 .eh_device_reset_handler = beiscsi_eh_device_reset,
390 .eh_target_reset_handler = iscsi_eh_session_reset,
391 .shost_attrs = beiscsi_attrs,
392 .sg_tablesize = BEISCSI_SGLIST_ELEMENTS,
393 .can_queue = BE2_IO_DEPTH,
395 .max_sectors = BEISCSI_MAX_SECTORS,
396 .cmd_per_lun = BEISCSI_CMD_PER_LUN,
397 .use_clustering = ENABLE_CLUSTERING,
398 .vendor_id = SCSI_NL_VID_TYPE_PCI | BE_VENDOR_ID,
399 .track_queue_depth = 1,
402 static struct scsi_transport_template *beiscsi_scsi_transport;
404 static struct beiscsi_hba *beiscsi_hba_alloc(struct pci_dev *pcidev)
406 struct beiscsi_hba *phba;
407 struct Scsi_Host *shost;
409 shost = iscsi_host_alloc(&beiscsi_sht, sizeof(*phba), 0);
411 dev_err(&pcidev->dev,
412 "beiscsi_hba_alloc - iscsi_host_alloc failed\n");
415 shost->max_id = BE2_MAX_SESSIONS;
416 shost->max_channel = 0;
417 shost->max_cmd_len = BEISCSI_MAX_CMD_LEN;
418 shost->max_lun = BEISCSI_NUM_MAX_LUN;
419 shost->transportt = beiscsi_scsi_transport;
420 phba = iscsi_host_priv(shost);
421 memset(phba, 0, sizeof(*phba));
423 phba->pcidev = pci_dev_get(pcidev);
424 pci_set_drvdata(pcidev, phba);
425 phba->interface_handle = 0xFFFFFFFF;
430 static void beiscsi_unmap_pci_function(struct beiscsi_hba *phba)
433 iounmap(phba->csr_va);
437 iounmap(phba->db_va);
441 iounmap(phba->pci_va);
446 static int beiscsi_map_pci_bars(struct beiscsi_hba *phba,
447 struct pci_dev *pcidev)
452 addr = ioremap_nocache(pci_resource_start(pcidev, 2),
453 pci_resource_len(pcidev, 2));
456 phba->ctrl.csr = addr;
458 phba->csr_pa.u.a64.address = pci_resource_start(pcidev, 2);
460 addr = ioremap_nocache(pci_resource_start(pcidev, 4), 128 * 1024);
463 phba->ctrl.db = addr;
465 phba->db_pa.u.a64.address = pci_resource_start(pcidev, 4);
467 if (phba->generation == BE_GEN2)
472 addr = ioremap_nocache(pci_resource_start(pcidev, pcicfg_reg),
473 pci_resource_len(pcidev, pcicfg_reg));
477 phba->ctrl.pcicfg = addr;
479 phba->pci_pa.u.a64.address = pci_resource_start(pcidev, pcicfg_reg);
483 beiscsi_unmap_pci_function(phba);
487 static int beiscsi_enable_pci(struct pci_dev *pcidev)
491 ret = pci_enable_device(pcidev);
493 dev_err(&pcidev->dev,
494 "beiscsi_enable_pci - enable device failed\n");
498 ret = pci_request_regions(pcidev, DRV_NAME);
500 dev_err(&pcidev->dev,
501 "beiscsi_enable_pci - request region failed\n");
502 goto pci_dev_disable;
505 pci_set_master(pcidev);
506 ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(64));
508 ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(32));
510 dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n");
511 goto pci_region_release;
513 ret = pci_set_consistent_dma_mask(pcidev,
517 ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64));
519 dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n");
520 goto pci_region_release;
526 pci_release_regions(pcidev);
528 pci_disable_device(pcidev);
533 static int be_ctrl_init(struct beiscsi_hba *phba, struct pci_dev *pdev)
535 struct be_ctrl_info *ctrl = &phba->ctrl;
536 struct be_dma_mem *mbox_mem_alloc = &ctrl->mbox_mem_alloced;
537 struct be_dma_mem *mbox_mem_align = &ctrl->mbox_mem;
541 status = beiscsi_map_pci_bars(phba, pdev);
544 mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16;
545 mbox_mem_alloc->va = pci_alloc_consistent(pdev,
546 mbox_mem_alloc->size,
547 &mbox_mem_alloc->dma);
548 if (!mbox_mem_alloc->va) {
549 beiscsi_unmap_pci_function(phba);
553 mbox_mem_align->size = sizeof(struct be_mcc_mailbox);
554 mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16);
555 mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16);
556 memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox));
557 mutex_init(&ctrl->mbox_lock);
558 spin_lock_init(&phba->ctrl.mcc_lock);
564 * beiscsi_get_params()- Set the config paramters
565 * @phba: ptr device priv structure
567 static void beiscsi_get_params(struct beiscsi_hba *phba)
569 uint32_t total_cid_count = 0;
570 uint32_t total_icd_count = 0;
573 total_cid_count = BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP0) +
574 BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP1);
576 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
577 uint32_t align_mask = 0;
578 uint32_t icd_post_per_page = 0;
579 uint32_t icd_count_unavailable = 0;
580 uint32_t icd_start = 0, icd_count = 0;
581 uint32_t icd_start_align = 0, icd_count_align = 0;
583 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
584 icd_start = phba->fw_config.iscsi_icd_start[ulp_num];
585 icd_count = phba->fw_config.iscsi_icd_count[ulp_num];
587 /* Get ICD count that can be posted on each page */
588 icd_post_per_page = (PAGE_SIZE / (BE2_SGE *
589 sizeof(struct iscsi_sge)));
590 align_mask = (icd_post_per_page - 1);
592 /* Check if icd_start is aligned ICD per page posting */
593 if (icd_start % icd_post_per_page) {
594 icd_start_align = ((icd_start +
598 iscsi_icd_start[ulp_num] =
602 icd_count_align = (icd_count & ~align_mask);
604 /* ICD discarded in the process of alignment */
606 icd_count_unavailable = ((icd_start_align -
611 /* Updated ICD count available */
612 phba->fw_config.iscsi_icd_count[ulp_num] = (icd_count -
613 icd_count_unavailable);
615 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
616 "BM_%d : Aligned ICD values\n"
617 "\t ICD Start : %d\n"
618 "\t ICD Count : %d\n"
619 "\t ICD Discarded : %d\n",
621 iscsi_icd_start[ulp_num],
623 iscsi_icd_count[ulp_num],
624 icd_count_unavailable);
629 total_icd_count = phba->fw_config.iscsi_icd_count[ulp_num];
630 phba->params.ios_per_ctrl = (total_icd_count -
632 BE2_TMFS + BE2_NOPOUT_REQ));
633 phba->params.cxns_per_ctrl = total_cid_count;
634 phba->params.icds_per_ctrl = total_icd_count;
635 phba->params.num_sge_per_io = BE2_SGE;
636 phba->params.defpdu_hdr_sz = BE2_DEFPDU_HDR_SZ;
637 phba->params.defpdu_data_sz = BE2_DEFPDU_DATA_SZ;
638 phba->params.num_eq_entries = 1024;
639 phba->params.num_cq_entries = 1024;
640 phba->params.wrbs_per_cxn = 256;
643 static void hwi_ring_eq_db(struct beiscsi_hba *phba,
644 unsigned int id, unsigned int clr_interrupt,
645 unsigned int num_processed,
646 unsigned char rearm, unsigned char event)
651 val |= 1 << DB_EQ_REARM_SHIFT;
653 val |= 1 << DB_EQ_CLR_SHIFT;
655 val |= 1 << DB_EQ_EVNT_SHIFT;
657 val |= num_processed << DB_EQ_NUM_POPPED_SHIFT;
658 /* Setting lower order EQ_ID Bits */
659 val |= (id & DB_EQ_RING_ID_LOW_MASK);
661 /* Setting Higher order EQ_ID Bits */
662 val |= (((id >> DB_EQ_HIGH_FEILD_SHIFT) &
663 DB_EQ_RING_ID_HIGH_MASK)
664 << DB_EQ_HIGH_SET_SHIFT);
666 iowrite32(val, phba->db_va + DB_EQ_OFFSET);
670 * be_isr_mcc - The isr routine of the driver.
672 * @dev_id: Pointer to host adapter structure
674 static irqreturn_t be_isr_mcc(int irq, void *dev_id)
676 struct beiscsi_hba *phba;
677 struct be_eq_entry *eqe;
678 struct be_queue_info *eq;
679 struct be_queue_info *mcc;
680 unsigned int mcc_events;
681 struct be_eq_obj *pbe_eq;
686 mcc = &phba->ctrl.mcc_obj.cq;
687 eqe = queue_tail_node(eq);
690 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
692 if (((eqe->dw[offsetof(struct amap_eq_entry,
694 EQE_RESID_MASK) >> 16) == mcc->id) {
697 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
699 eqe = queue_tail_node(eq);
703 queue_work(phba->wq, &pbe_eq->mcc_work);
704 hwi_ring_eq_db(phba, eq->id, 1, mcc_events, 1, 1);
710 * be_isr_msix - The isr routine of the driver.
712 * @dev_id: Pointer to host adapter structure
714 static irqreturn_t be_isr_msix(int irq, void *dev_id)
716 struct beiscsi_hba *phba;
717 struct be_queue_info *eq;
718 struct be_eq_obj *pbe_eq;
724 /* disable interrupt till iopoll completes */
725 hwi_ring_eq_db(phba, eq->id, 1, 0, 0, 1);
726 irq_poll_sched(&pbe_eq->iopoll);
732 * be_isr - The isr routine of the driver.
734 * @dev_id: Pointer to host adapter structure
736 static irqreturn_t be_isr(int irq, void *dev_id)
738 struct beiscsi_hba *phba;
739 struct hwi_controller *phwi_ctrlr;
740 struct hwi_context_memory *phwi_context;
741 struct be_eq_entry *eqe;
742 struct be_queue_info *eq;
743 struct be_queue_info *mcc;
744 unsigned int mcc_events, io_events;
745 struct be_ctrl_info *ctrl;
746 struct be_eq_obj *pbe_eq;
751 isr = ioread32(ctrl->csr + CEV_ISR0_OFFSET +
752 (PCI_FUNC(ctrl->pdev->devfn) * CEV_ISR_SIZE));
756 phwi_ctrlr = phba->phwi_ctrlr;
757 phwi_context = phwi_ctrlr->phwi_ctxt;
758 pbe_eq = &phwi_context->be_eq[0];
760 eq = &phwi_context->be_eq[0].q;
761 mcc = &phba->ctrl.mcc_obj.cq;
762 eqe = queue_tail_node(eq);
766 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
768 if (((eqe->dw[offsetof(struct amap_eq_entry,
769 resource_id) / 32] & EQE_RESID_MASK) >> 16) == mcc->id)
773 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
775 eqe = queue_tail_node(eq);
777 if (!io_events && !mcc_events)
780 /* no need to rearm if interrupt is only for IOs */
783 queue_work(phba->wq, &pbe_eq->mcc_work);
788 irq_poll_sched(&pbe_eq->iopoll);
789 hwi_ring_eq_db(phba, eq->id, 0, (io_events + mcc_events), rearm, 1);
793 static void beiscsi_free_irqs(struct beiscsi_hba *phba)
795 struct hwi_context_memory *phwi_context;
798 if (!phba->pcidev->msix_enabled) {
799 if (phba->pcidev->irq)
800 free_irq(phba->pcidev->irq, phba);
804 phwi_context = phba->phwi_ctrlr->phwi_ctxt;
805 for (i = 0; i <= phba->num_cpus; i++) {
806 free_irq(pci_irq_vector(phba->pcidev, i),
807 &phwi_context->be_eq[i]);
808 kfree(phba->msi_name[i]);
812 static int beiscsi_init_irqs(struct beiscsi_hba *phba)
814 struct pci_dev *pcidev = phba->pcidev;
815 struct hwi_controller *phwi_ctrlr;
816 struct hwi_context_memory *phwi_context;
819 phwi_ctrlr = phba->phwi_ctrlr;
820 phwi_context = phwi_ctrlr->phwi_ctxt;
822 if (pcidev->msix_enabled) {
823 for (i = 0; i < phba->num_cpus; i++) {
824 phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME,
826 if (!phba->msi_name[i]) {
831 sprintf(phba->msi_name[i], "beiscsi_%02x_%02x",
832 phba->shost->host_no, i);
833 ret = request_irq(pci_irq_vector(pcidev, i),
834 be_isr_msix, 0, phba->msi_name[i],
835 &phwi_context->be_eq[i]);
837 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
838 "BM_%d : beiscsi_init_irqs-Failed to"
839 "register msix for i = %d\n",
841 kfree(phba->msi_name[i]);
845 phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME, GFP_KERNEL);
846 if (!phba->msi_name[i]) {
850 sprintf(phba->msi_name[i], "beiscsi_mcc_%02x",
851 phba->shost->host_no);
852 ret = request_irq(pci_irq_vector(pcidev, i), be_isr_mcc, 0,
853 phba->msi_name[i], &phwi_context->be_eq[i]);
855 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT ,
856 "BM_%d : beiscsi_init_irqs-"
857 "Failed to register beiscsi_msix_mcc\n");
858 kfree(phba->msi_name[i]);
863 ret = request_irq(pcidev->irq, be_isr, IRQF_SHARED,
866 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
867 "BM_%d : beiscsi_init_irqs-"
868 "Failed to register irq\\n");
874 for (j = i - 1; j >= 0; j--) {
875 free_irq(pci_irq_vector(pcidev, i), &phwi_context->be_eq[j]);
876 kfree(phba->msi_name[j]);
881 void hwi_ring_cq_db(struct beiscsi_hba *phba,
882 unsigned int id, unsigned int num_processed,
888 val |= 1 << DB_CQ_REARM_SHIFT;
890 val |= num_processed << DB_CQ_NUM_POPPED_SHIFT;
892 /* Setting lower order CQ_ID Bits */
893 val |= (id & DB_CQ_RING_ID_LOW_MASK);
895 /* Setting Higher order CQ_ID Bits */
896 val |= (((id >> DB_CQ_HIGH_FEILD_SHIFT) &
897 DB_CQ_RING_ID_HIGH_MASK)
898 << DB_CQ_HIGH_SET_SHIFT);
900 iowrite32(val, phba->db_va + DB_CQ_OFFSET);
903 static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba)
905 struct sgl_handle *psgl_handle;
908 spin_lock_irqsave(&phba->io_sgl_lock, flags);
909 if (phba->io_sgl_hndl_avbl) {
910 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
911 "BM_%d : In alloc_io_sgl_handle,"
912 " io_sgl_alloc_index=%d\n",
913 phba->io_sgl_alloc_index);
915 psgl_handle = phba->io_sgl_hndl_base[phba->
917 phba->io_sgl_hndl_base[phba->io_sgl_alloc_index] = NULL;
918 phba->io_sgl_hndl_avbl--;
919 if (phba->io_sgl_alloc_index == (phba->params.
921 phba->io_sgl_alloc_index = 0;
923 phba->io_sgl_alloc_index++;
926 spin_unlock_irqrestore(&phba->io_sgl_lock, flags);
931 free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
935 spin_lock_irqsave(&phba->io_sgl_lock, flags);
936 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
937 "BM_%d : In free_,io_sgl_free_index=%d\n",
938 phba->io_sgl_free_index);
940 if (phba->io_sgl_hndl_base[phba->io_sgl_free_index]) {
942 * this can happen if clean_task is called on a task that
943 * failed in xmit_task or alloc_pdu.
945 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
946 "BM_%d : Double Free in IO SGL io_sgl_free_index=%d,"
947 "value there=%p\n", phba->io_sgl_free_index,
948 phba->io_sgl_hndl_base
949 [phba->io_sgl_free_index]);
950 spin_unlock_irqrestore(&phba->io_sgl_lock, flags);
953 phba->io_sgl_hndl_base[phba->io_sgl_free_index] = psgl_handle;
954 phba->io_sgl_hndl_avbl++;
955 if (phba->io_sgl_free_index == (phba->params.ios_per_ctrl - 1))
956 phba->io_sgl_free_index = 0;
958 phba->io_sgl_free_index++;
959 spin_unlock_irqrestore(&phba->io_sgl_lock, flags);
962 static inline struct wrb_handle *
963 beiscsi_get_wrb_handle(struct hwi_wrb_context *pwrb_context,
964 unsigned int wrbs_per_cxn)
966 struct wrb_handle *pwrb_handle;
969 spin_lock_irqsave(&pwrb_context->wrb_lock, flags);
970 if (!pwrb_context->wrb_handles_available) {
971 spin_unlock_irqrestore(&pwrb_context->wrb_lock, flags);
974 pwrb_handle = pwrb_context->pwrb_handle_base[pwrb_context->alloc_index];
975 pwrb_context->wrb_handles_available--;
976 if (pwrb_context->alloc_index == (wrbs_per_cxn - 1))
977 pwrb_context->alloc_index = 0;
979 pwrb_context->alloc_index++;
980 spin_unlock_irqrestore(&pwrb_context->wrb_lock, flags);
983 memset(pwrb_handle->pwrb, 0, sizeof(*pwrb_handle->pwrb));
989 * alloc_wrb_handle - To allocate a wrb handle
990 * @phba: The hba pointer
991 * @cid: The cid to use for allocation
992 * @pwrb_context: ptr to ptr to wrb context
994 * This happens under session_lock until submission to chip
996 struct wrb_handle *alloc_wrb_handle(struct beiscsi_hba *phba, unsigned int cid,
997 struct hwi_wrb_context **pcontext)
999 struct hwi_wrb_context *pwrb_context;
1000 struct hwi_controller *phwi_ctrlr;
1001 uint16_t cri_index = BE_GET_CRI_FROM_CID(cid);
1003 phwi_ctrlr = phba->phwi_ctrlr;
1004 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
1005 /* return the context address */
1006 *pcontext = pwrb_context;
1007 return beiscsi_get_wrb_handle(pwrb_context, phba->params.wrbs_per_cxn);
1011 beiscsi_put_wrb_handle(struct hwi_wrb_context *pwrb_context,
1012 struct wrb_handle *pwrb_handle,
1013 unsigned int wrbs_per_cxn)
1015 unsigned long flags;
1017 spin_lock_irqsave(&pwrb_context->wrb_lock, flags);
1018 pwrb_context->pwrb_handle_base[pwrb_context->free_index] = pwrb_handle;
1019 pwrb_context->wrb_handles_available++;
1020 if (pwrb_context->free_index == (wrbs_per_cxn - 1))
1021 pwrb_context->free_index = 0;
1023 pwrb_context->free_index++;
1024 pwrb_handle->pio_handle = NULL;
1025 spin_unlock_irqrestore(&pwrb_context->wrb_lock, flags);
1029 * free_wrb_handle - To free the wrb handle back to pool
1030 * @phba: The hba pointer
1031 * @pwrb_context: The context to free from
1032 * @pwrb_handle: The wrb_handle to free
1034 * This happens under session_lock until submission to chip
1037 free_wrb_handle(struct beiscsi_hba *phba, struct hwi_wrb_context *pwrb_context,
1038 struct wrb_handle *pwrb_handle)
1040 beiscsi_put_wrb_handle(pwrb_context,
1042 phba->params.wrbs_per_cxn);
1043 beiscsi_log(phba, KERN_INFO,
1044 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1045 "BM_%d : FREE WRB: pwrb_handle=%p free_index=0x%x"
1046 "wrb_handles_available=%d\n",
1047 pwrb_handle, pwrb_context->free_index,
1048 pwrb_context->wrb_handles_available);
1051 static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba)
1053 struct sgl_handle *psgl_handle;
1054 unsigned long flags;
1056 spin_lock_irqsave(&phba->mgmt_sgl_lock, flags);
1057 if (phba->eh_sgl_hndl_avbl) {
1058 psgl_handle = phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index];
1059 phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index] = NULL;
1060 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1061 "BM_%d : mgmt_sgl_alloc_index=%d=0x%x\n",
1062 phba->eh_sgl_alloc_index,
1063 phba->eh_sgl_alloc_index);
1065 phba->eh_sgl_hndl_avbl--;
1066 if (phba->eh_sgl_alloc_index ==
1067 (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl -
1069 phba->eh_sgl_alloc_index = 0;
1071 phba->eh_sgl_alloc_index++;
1074 spin_unlock_irqrestore(&phba->mgmt_sgl_lock, flags);
1079 free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
1081 unsigned long flags;
1083 spin_lock_irqsave(&phba->mgmt_sgl_lock, flags);
1084 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1085 "BM_%d : In free_mgmt_sgl_handle,"
1086 "eh_sgl_free_index=%d\n",
1087 phba->eh_sgl_free_index);
1089 if (phba->eh_sgl_hndl_base[phba->eh_sgl_free_index]) {
1091 * this can happen if clean_task is called on a task that
1092 * failed in xmit_task or alloc_pdu.
1094 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1095 "BM_%d : Double Free in eh SGL ,"
1096 "eh_sgl_free_index=%d\n",
1097 phba->eh_sgl_free_index);
1098 spin_unlock_irqrestore(&phba->mgmt_sgl_lock, flags);
1101 phba->eh_sgl_hndl_base[phba->eh_sgl_free_index] = psgl_handle;
1102 phba->eh_sgl_hndl_avbl++;
1103 if (phba->eh_sgl_free_index ==
1104 (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl - 1))
1105 phba->eh_sgl_free_index = 0;
1107 phba->eh_sgl_free_index++;
1108 spin_unlock_irqrestore(&phba->mgmt_sgl_lock, flags);
1112 be_complete_io(struct beiscsi_conn *beiscsi_conn,
1113 struct iscsi_task *task,
1114 struct common_sol_cqe *csol_cqe)
1116 struct beiscsi_io_task *io_task = task->dd_data;
1117 struct be_status_bhs *sts_bhs =
1118 (struct be_status_bhs *)io_task->cmd_bhs;
1119 struct iscsi_conn *conn = beiscsi_conn->conn;
1120 unsigned char *sense;
1121 u32 resid = 0, exp_cmdsn, max_cmdsn;
1122 u8 rsp, status, flags;
1124 exp_cmdsn = csol_cqe->exp_cmdsn;
1125 max_cmdsn = (csol_cqe->exp_cmdsn +
1126 csol_cqe->cmd_wnd - 1);
1127 rsp = csol_cqe->i_resp;
1128 status = csol_cqe->i_sts;
1129 flags = csol_cqe->i_flags;
1130 resid = csol_cqe->res_cnt;
1133 if (io_task->scsi_cmnd) {
1134 scsi_dma_unmap(io_task->scsi_cmnd);
1135 io_task->scsi_cmnd = NULL;
1140 task->sc->result = (DID_OK << 16) | status;
1141 if (rsp != ISCSI_STATUS_CMD_COMPLETED) {
1142 task->sc->result = DID_ERROR << 16;
1146 /* bidi not initially supported */
1147 if (flags & (ISCSI_FLAG_CMD_UNDERFLOW | ISCSI_FLAG_CMD_OVERFLOW)) {
1148 if (!status && (flags & ISCSI_FLAG_CMD_OVERFLOW))
1149 task->sc->result = DID_ERROR << 16;
1151 if (flags & ISCSI_FLAG_CMD_UNDERFLOW) {
1152 scsi_set_resid(task->sc, resid);
1153 if (!status && (scsi_bufflen(task->sc) - resid <
1154 task->sc->underflow))
1155 task->sc->result = DID_ERROR << 16;
1159 if (status == SAM_STAT_CHECK_CONDITION) {
1161 unsigned short *slen = (unsigned short *)sts_bhs->sense_info;
1163 sense = sts_bhs->sense_info + sizeof(unsigned short);
1164 sense_len = be16_to_cpu(*slen);
1165 memcpy(task->sc->sense_buffer, sense,
1166 min_t(u16, sense_len, SCSI_SENSE_BUFFERSIZE));
1169 if (io_task->cmd_bhs->iscsi_hdr.flags & ISCSI_FLAG_CMD_READ)
1170 conn->rxdata_octets += resid;
1172 if (io_task->scsi_cmnd) {
1173 scsi_dma_unmap(io_task->scsi_cmnd);
1174 io_task->scsi_cmnd = NULL;
1176 iscsi_complete_scsi_task(task, exp_cmdsn, max_cmdsn);
1180 be_complete_logout(struct beiscsi_conn *beiscsi_conn,
1181 struct iscsi_task *task,
1182 struct common_sol_cqe *csol_cqe)
1184 struct iscsi_logout_rsp *hdr;
1185 struct beiscsi_io_task *io_task = task->dd_data;
1186 struct iscsi_conn *conn = beiscsi_conn->conn;
1188 hdr = (struct iscsi_logout_rsp *)task->hdr;
1189 hdr->opcode = ISCSI_OP_LOGOUT_RSP;
1192 hdr->flags = csol_cqe->i_flags;
1193 hdr->response = csol_cqe->i_resp;
1194 hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn);
1195 hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn +
1196 csol_cqe->cmd_wnd - 1);
1198 hdr->dlength[0] = 0;
1199 hdr->dlength[1] = 0;
1200 hdr->dlength[2] = 0;
1202 hdr->itt = io_task->libiscsi_itt;
1203 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1207 be_complete_tmf(struct beiscsi_conn *beiscsi_conn,
1208 struct iscsi_task *task,
1209 struct common_sol_cqe *csol_cqe)
1211 struct iscsi_tm_rsp *hdr;
1212 struct iscsi_conn *conn = beiscsi_conn->conn;
1213 struct beiscsi_io_task *io_task = task->dd_data;
1215 hdr = (struct iscsi_tm_rsp *)task->hdr;
1216 hdr->opcode = ISCSI_OP_SCSI_TMFUNC_RSP;
1217 hdr->flags = csol_cqe->i_flags;
1218 hdr->response = csol_cqe->i_resp;
1219 hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn);
1220 hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn +
1221 csol_cqe->cmd_wnd - 1);
1223 hdr->itt = io_task->libiscsi_itt;
1224 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1228 hwi_complete_drvr_msgs(struct beiscsi_conn *beiscsi_conn,
1229 struct beiscsi_hba *phba, struct sol_cqe *psol)
1231 struct hwi_wrb_context *pwrb_context;
1232 uint16_t wrb_index, cid, cri_index;
1233 struct hwi_controller *phwi_ctrlr;
1234 struct wrb_handle *pwrb_handle;
1235 struct iscsi_session *session;
1236 struct iscsi_task *task;
1238 phwi_ctrlr = phba->phwi_ctrlr;
1239 if (is_chip_be2_be3r(phba)) {
1240 wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe,
1242 cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe,
1245 wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2,
1247 cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2,
1251 cri_index = BE_GET_CRI_FROM_CID(cid);
1252 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
1253 pwrb_handle = pwrb_context->pwrb_handle_basestd[wrb_index];
1254 session = beiscsi_conn->conn->session;
1255 spin_lock_bh(&session->back_lock);
1256 task = pwrb_handle->pio_handle;
1258 __iscsi_put_task(task);
1259 spin_unlock_bh(&session->back_lock);
1263 be_complete_nopin_resp(struct beiscsi_conn *beiscsi_conn,
1264 struct iscsi_task *task,
1265 struct common_sol_cqe *csol_cqe)
1267 struct iscsi_nopin *hdr;
1268 struct iscsi_conn *conn = beiscsi_conn->conn;
1269 struct beiscsi_io_task *io_task = task->dd_data;
1271 hdr = (struct iscsi_nopin *)task->hdr;
1272 hdr->flags = csol_cqe->i_flags;
1273 hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn);
1274 hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn +
1275 csol_cqe->cmd_wnd - 1);
1277 hdr->opcode = ISCSI_OP_NOOP_IN;
1278 hdr->itt = io_task->libiscsi_itt;
1279 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1282 static void adapter_get_sol_cqe(struct beiscsi_hba *phba,
1283 struct sol_cqe *psol,
1284 struct common_sol_cqe *csol_cqe)
1286 if (is_chip_be2_be3r(phba)) {
1287 csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe,
1288 i_exp_cmd_sn, psol);
1289 csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe,
1291 csol_cqe->cmd_wnd = AMAP_GET_BITS(struct amap_sol_cqe,
1293 csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe,
1295 csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe,
1297 csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe,
1299 csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe,
1301 csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe,
1303 csol_cqe->i_flags = AMAP_GET_BITS(struct amap_sol_cqe,
1306 csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1307 i_exp_cmd_sn, psol);
1308 csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1310 csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1312 csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1314 csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1316 csol_cqe->cmd_wnd = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1318 if (AMAP_GET_BITS(struct amap_sol_cqe_v2,
1320 csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1323 csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1325 if (AMAP_GET_BITS(struct amap_sol_cqe_v2,
1327 csol_cqe->i_flags = ISCSI_FLAG_CMD_UNDERFLOW;
1329 if (AMAP_GET_BITS(struct amap_sol_cqe_v2,
1331 csol_cqe->i_flags |= ISCSI_FLAG_CMD_OVERFLOW;
1336 static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn,
1337 struct beiscsi_hba *phba, struct sol_cqe *psol)
1339 struct iscsi_conn *conn = beiscsi_conn->conn;
1340 struct iscsi_session *session = conn->session;
1341 struct common_sol_cqe csol_cqe = {0};
1342 struct hwi_wrb_context *pwrb_context;
1343 struct hwi_controller *phwi_ctrlr;
1344 struct wrb_handle *pwrb_handle;
1345 struct iscsi_task *task;
1346 uint16_t cri_index = 0;
1349 phwi_ctrlr = phba->phwi_ctrlr;
1351 /* Copy the elements to a common structure */
1352 adapter_get_sol_cqe(phba, psol, &csol_cqe);
1354 cri_index = BE_GET_CRI_FROM_CID(csol_cqe.cid);
1355 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
1357 pwrb_handle = pwrb_context->pwrb_handle_basestd[
1358 csol_cqe.wrb_index];
1360 spin_lock_bh(&session->back_lock);
1361 task = pwrb_handle->pio_handle;
1363 spin_unlock_bh(&session->back_lock);
1366 type = ((struct beiscsi_io_task *)task->dd_data)->wrb_type;
1370 case HWH_TYPE_IO_RD:
1371 if ((task->hdr->opcode & ISCSI_OPCODE_MASK) ==
1373 be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe);
1375 be_complete_io(beiscsi_conn, task, &csol_cqe);
1378 case HWH_TYPE_LOGOUT:
1379 if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGOUT)
1380 be_complete_logout(beiscsi_conn, task, &csol_cqe);
1382 be_complete_tmf(beiscsi_conn, task, &csol_cqe);
1385 case HWH_TYPE_LOGIN:
1386 beiscsi_log(phba, KERN_ERR,
1387 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1388 "BM_%d :\t\t No HWH_TYPE_LOGIN Expected in"
1389 " hwi_complete_cmd- Solicited path\n");
1393 be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe);
1397 beiscsi_log(phba, KERN_WARNING,
1398 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1399 "BM_%d : In hwi_complete_cmd, unknown type = %d"
1400 "wrb_index 0x%x CID 0x%x\n", type,
1406 spin_unlock_bh(&session->back_lock);
1410 * ASYNC PDUs include
1411 * a. Unsolicited NOP-In (target initiated NOP-In)
1415 * These headers arrive unprocessed by the EP firmware.
1416 * iSCSI layer processes them.
1419 beiscsi_complete_pdu(struct beiscsi_conn *beiscsi_conn,
1420 struct pdu_base *phdr, void *pdata, unsigned int dlen)
1422 struct beiscsi_hba *phba = beiscsi_conn->phba;
1423 struct iscsi_conn *conn = beiscsi_conn->conn;
1424 struct beiscsi_io_task *io_task;
1425 struct iscsi_hdr *login_hdr;
1426 struct iscsi_task *task;
1429 code = AMAP_GET_BITS(struct amap_pdu_base, opcode, phdr);
1431 case ISCSI_OP_NOOP_IN:
1435 case ISCSI_OP_ASYNC_EVENT:
1437 case ISCSI_OP_REJECT:
1439 WARN_ON(!(dlen == 48));
1440 beiscsi_log(phba, KERN_ERR,
1441 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1442 "BM_%d : In ISCSI_OP_REJECT\n");
1444 case ISCSI_OP_LOGIN_RSP:
1445 case ISCSI_OP_TEXT_RSP:
1446 task = conn->login_task;
1447 io_task = task->dd_data;
1448 login_hdr = (struct iscsi_hdr *)phdr;
1449 login_hdr->itt = io_task->libiscsi_itt;
1452 beiscsi_log(phba, KERN_WARNING,
1453 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1454 "BM_%d : unrecognized async PDU opcode 0x%x\n",
1458 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)phdr, pdata, dlen);
1463 beiscsi_hdl_put_handle(struct hd_async_context *pasync_ctx,
1464 struct hd_async_handle *pasync_handle)
1466 pasync_handle->is_final = 0;
1467 pasync_handle->buffer_len = 0;
1468 pasync_handle->in_use = 0;
1469 list_del_init(&pasync_handle->link);
1473 beiscsi_hdl_purge_handles(struct beiscsi_hba *phba,
1474 struct hd_async_context *pasync_ctx,
1477 struct hd_async_handle *pasync_handle, *tmp_handle;
1478 struct list_head *plist;
1480 plist = &pasync_ctx->async_entry[cri].wq.list;
1481 list_for_each_entry_safe(pasync_handle, tmp_handle, plist, link)
1482 beiscsi_hdl_put_handle(pasync_ctx, pasync_handle);
1484 INIT_LIST_HEAD(&pasync_ctx->async_entry[cri].wq.list);
1485 pasync_ctx->async_entry[cri].wq.hdr_len = 0;
1486 pasync_ctx->async_entry[cri].wq.bytes_received = 0;
1487 pasync_ctx->async_entry[cri].wq.bytes_needed = 0;
1490 static struct hd_async_handle *
1491 beiscsi_hdl_get_handle(struct beiscsi_conn *beiscsi_conn,
1492 struct hd_async_context *pasync_ctx,
1493 struct i_t_dpdu_cqe *pdpdu_cqe,
1496 struct beiscsi_hba *phba = beiscsi_conn->phba;
1497 struct hd_async_handle *pasync_handle;
1498 struct be_bus_address phys_addr;
1499 u16 cid, code, ci, cri;
1500 u8 final, error = 0;
1503 cid = beiscsi_conn->beiscsi_conn_cid;
1504 cri = BE_GET_ASYNC_CRI_FROM_CID(cid);
1506 * This function is invoked to get the right async_handle structure
1507 * from a given DEF PDU CQ entry.
1509 * - index in CQ entry gives the vertical index
1510 * - address in CQ entry is the offset where the DMA last ended
1511 * - final - no more notifications for this PDU
1513 if (is_chip_be2_be3r(phba)) {
1514 dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe,
1516 ci = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe,
1518 final = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe,
1521 dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2,
1523 ci = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2,
1525 final = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2,
1530 * DB addr Hi/Lo is same for BE and SKH.
1531 * Subtract the dataplacementlength to get to the base.
1533 phys_addr.u.a32.address_lo = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe,
1534 db_addr_lo, pdpdu_cqe);
1535 phys_addr.u.a32.address_lo -= dpl;
1536 phys_addr.u.a32.address_hi = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe,
1537 db_addr_hi, pdpdu_cqe);
1539 code = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, code, pdpdu_cqe);
1541 case UNSOL_HDR_NOTIFY:
1542 pasync_handle = pasync_ctx->async_entry[ci].header;
1545 case UNSOL_DATA_DIGEST_ERROR_NOTIFY:
1547 case UNSOL_DATA_NOTIFY:
1548 pasync_handle = pasync_ctx->async_entry[ci].data;
1550 /* called only for above codes */
1555 if (pasync_handle->pa.u.a64.address != phys_addr.u.a64.address ||
1556 pasync_handle->index != ci) {
1557 /* driver bug - if ci does not match async handle index */
1559 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_ISCSI,
1560 "BM_%d : cid %u async PDU handle mismatch - addr in %cQE %llx at %u:addr in CQE %llx ci %u\n",
1561 cid, pasync_handle->is_header ? 'H' : 'D',
1562 pasync_handle->pa.u.a64.address,
1563 pasync_handle->index,
1564 phys_addr.u.a64.address, ci);
1565 /* FW has stale address - attempt continuing by dropping */
1569 * DEF PDU header and data buffers with errors should be simply
1570 * dropped as there are no consumers for it.
1573 beiscsi_hdl_put_handle(pasync_ctx, pasync_handle);
1577 if (pasync_handle->in_use || !list_empty(&pasync_handle->link)) {
1578 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_ISCSI,
1579 "BM_%d : cid %d async PDU handle in use - code %d ci %d addr %llx\n",
1580 cid, code, ci, phys_addr.u.a64.address);
1581 beiscsi_hdl_purge_handles(phba, pasync_ctx, cri);
1584 list_del_init(&pasync_handle->link);
1586 * Each CID is associated with unique CRI.
1587 * ASYNC_CRI_FROM_CID mapping and CRI_FROM_CID are totaly different.
1589 pasync_handle->cri = cri;
1590 pasync_handle->is_final = final;
1591 pasync_handle->buffer_len = dpl;
1592 pasync_handle->in_use = 1;
1594 return pasync_handle;
1598 beiscsi_hdl_fwd_pdu(struct beiscsi_conn *beiscsi_conn,
1599 struct hd_async_context *pasync_ctx,
1602 struct iscsi_session *session = beiscsi_conn->conn->session;
1603 struct hd_async_handle *pasync_handle, *plast_handle;
1604 struct beiscsi_hba *phba = beiscsi_conn->phba;
1605 void *phdr = NULL, *pdata = NULL;
1606 u32 dlen = 0, status = 0;
1607 struct list_head *plist;
1609 plist = &pasync_ctx->async_entry[cri].wq.list;
1610 plast_handle = NULL;
1611 list_for_each_entry(pasync_handle, plist, link) {
1612 plast_handle = pasync_handle;
1613 /* get the header, the first entry */
1615 phdr = pasync_handle->pbuffer;
1618 /* use first buffer to collect all the data */
1620 pdata = pasync_handle->pbuffer;
1621 dlen = pasync_handle->buffer_len;
1624 if (!pasync_handle->buffer_len ||
1625 (dlen + pasync_handle->buffer_len) >
1626 pasync_ctx->async_data.buffer_size)
1628 memcpy(pdata + dlen, pasync_handle->pbuffer,
1629 pasync_handle->buffer_len);
1630 dlen += pasync_handle->buffer_len;
1633 if (!plast_handle->is_final) {
1634 /* last handle should have final PDU notification from FW */
1635 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_ISCSI,
1636 "BM_%d : cid %u %p fwd async PDU opcode %x with last handle missing - HL%u:DN%u:DR%u\n",
1637 beiscsi_conn->beiscsi_conn_cid, plast_handle,
1638 AMAP_GET_BITS(struct amap_pdu_base, opcode, phdr),
1639 pasync_ctx->async_entry[cri].wq.hdr_len,
1640 pasync_ctx->async_entry[cri].wq.bytes_needed,
1641 pasync_ctx->async_entry[cri].wq.bytes_received);
1643 spin_lock_bh(&session->back_lock);
1644 status = beiscsi_complete_pdu(beiscsi_conn, phdr, pdata, dlen);
1645 spin_unlock_bh(&session->back_lock);
1646 beiscsi_hdl_purge_handles(phba, pasync_ctx, cri);
1651 beiscsi_hdl_gather_pdu(struct beiscsi_conn *beiscsi_conn,
1652 struct hd_async_context *pasync_ctx,
1653 struct hd_async_handle *pasync_handle)
1655 unsigned int bytes_needed = 0, status = 0;
1656 u16 cri = pasync_handle->cri;
1657 struct cri_wait_queue *wq;
1658 struct beiscsi_hba *phba;
1659 struct pdu_base *ppdu;
1662 phba = beiscsi_conn->phba;
1663 wq = &pasync_ctx->async_entry[cri].wq;
1664 if (pasync_handle->is_header) {
1665 /* check if PDU hdr is rcv'd when old hdr not completed */
1670 ppdu = pasync_handle->pbuffer;
1671 bytes_needed = AMAP_GET_BITS(struct amap_pdu_base,
1673 bytes_needed <<= 16;
1674 bytes_needed |= be16_to_cpu(AMAP_GET_BITS(struct amap_pdu_base,
1675 data_len_lo, ppdu));
1676 wq->hdr_len = pasync_handle->buffer_len;
1677 wq->bytes_received = 0;
1678 wq->bytes_needed = bytes_needed;
1679 list_add_tail(&pasync_handle->link, &wq->list);
1681 status = beiscsi_hdl_fwd_pdu(beiscsi_conn,
1684 /* check if data received has header and is needed */
1685 if (!wq->hdr_len || !wq->bytes_needed) {
1686 err = "header less";
1689 wq->bytes_received += pasync_handle->buffer_len;
1690 /* Something got overwritten? Better catch it here. */
1691 if (wq->bytes_received > wq->bytes_needed) {
1695 list_add_tail(&pasync_handle->link, &wq->list);
1696 if (wq->bytes_received == wq->bytes_needed)
1697 status = beiscsi_hdl_fwd_pdu(beiscsi_conn,
1703 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_ISCSI,
1704 "BM_%d : cid %u async PDU %s - def-%c:HL%u:DN%u:DR%u\n",
1705 beiscsi_conn->beiscsi_conn_cid, err,
1706 pasync_handle->is_header ? 'H' : 'D',
1707 wq->hdr_len, wq->bytes_needed,
1708 pasync_handle->buffer_len);
1709 /* discard this handle */
1710 beiscsi_hdl_put_handle(pasync_ctx, pasync_handle);
1711 /* free all the other handles in cri_wait_queue */
1712 beiscsi_hdl_purge_handles(phba, pasync_ctx, cri);
1713 /* try continuing */
1718 beiscsi_hdq_post_handles(struct beiscsi_hba *phba,
1719 u8 header, u8 ulp_num, u16 nbuf)
1721 struct hd_async_handle *pasync_handle;
1722 struct hd_async_context *pasync_ctx;
1723 struct hwi_controller *phwi_ctrlr;
1724 struct phys_addr *pasync_sge;
1725 u32 ring_id, doorbell = 0;
1726 u32 doorbell_offset;
1729 phwi_ctrlr = phba->phwi_ctrlr;
1730 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr, ulp_num);
1732 pasync_sge = pasync_ctx->async_header.ring_base;
1733 pi = pasync_ctx->async_header.pi;
1734 ring_id = phwi_ctrlr->default_pdu_hdr[ulp_num].id;
1735 doorbell_offset = phwi_ctrlr->default_pdu_hdr[ulp_num].
1738 pasync_sge = pasync_ctx->async_data.ring_base;
1739 pi = pasync_ctx->async_data.pi;
1740 ring_id = phwi_ctrlr->default_pdu_data[ulp_num].id;
1741 doorbell_offset = phwi_ctrlr->default_pdu_data[ulp_num].
1745 for (prod = 0; prod < nbuf; prod++) {
1747 pasync_handle = pasync_ctx->async_entry[pi].header;
1749 pasync_handle = pasync_ctx->async_entry[pi].data;
1750 WARN_ON(pasync_handle->is_header != header);
1751 WARN_ON(pasync_handle->index != pi);
1752 /* setup the ring only once */
1753 if (nbuf == pasync_ctx->num_entries) {
1755 pasync_sge[pi].hi = pasync_handle->pa.u.a32.address_lo;
1756 pasync_sge[pi].lo = pasync_handle->pa.u.a32.address_hi;
1758 if (++pi == pasync_ctx->num_entries)
1763 pasync_ctx->async_header.pi = pi;
1765 pasync_ctx->async_data.pi = pi;
1767 doorbell |= ring_id & DB_DEF_PDU_RING_ID_MASK;
1768 doorbell |= 1 << DB_DEF_PDU_REARM_SHIFT;
1769 doorbell |= 0 << DB_DEF_PDU_EVENT_SHIFT;
1770 doorbell |= (prod & DB_DEF_PDU_CQPROC_MASK) << DB_DEF_PDU_CQPROC_SHIFT;
1771 iowrite32(doorbell, phba->db_va + doorbell_offset);
1775 beiscsi_hdq_process_compl(struct beiscsi_conn *beiscsi_conn,
1776 struct i_t_dpdu_cqe *pdpdu_cqe)
1778 struct beiscsi_hba *phba = beiscsi_conn->phba;
1779 struct hd_async_handle *pasync_handle = NULL;
1780 struct hd_async_context *pasync_ctx;
1781 struct hwi_controller *phwi_ctrlr;
1782 u8 ulp_num, consumed, header = 0;
1785 phwi_ctrlr = phba->phwi_ctrlr;
1786 cid_cri = BE_GET_CRI_FROM_CID(beiscsi_conn->beiscsi_conn_cid);
1787 ulp_num = BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr, cid_cri);
1788 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr, ulp_num);
1789 pasync_handle = beiscsi_hdl_get_handle(beiscsi_conn, pasync_ctx,
1790 pdpdu_cqe, &header);
1791 if (is_chip_be2_be3r(phba))
1792 consumed = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe,
1793 num_cons, pdpdu_cqe);
1795 consumed = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2,
1796 num_cons, pdpdu_cqe);
1798 beiscsi_hdl_gather_pdu(beiscsi_conn, pasync_ctx, pasync_handle);
1799 /* num_cons indicates number of 8 RQEs consumed */
1801 beiscsi_hdq_post_handles(phba, header, ulp_num, 8 * consumed);
1804 void beiscsi_process_mcc_cq(struct beiscsi_hba *phba)
1806 struct be_queue_info *mcc_cq;
1807 struct be_mcc_compl *mcc_compl;
1808 unsigned int num_processed = 0;
1810 mcc_cq = &phba->ctrl.mcc_obj.cq;
1811 mcc_compl = queue_tail_node(mcc_cq);
1812 mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
1813 while (mcc_compl->flags & CQE_FLAGS_VALID_MASK) {
1814 if (beiscsi_hba_in_error(phba))
1817 if (num_processed >= 32) {
1818 hwi_ring_cq_db(phba, mcc_cq->id,
1822 if (mcc_compl->flags & CQE_FLAGS_ASYNC_MASK) {
1823 beiscsi_process_async_event(phba, mcc_compl);
1824 } else if (mcc_compl->flags & CQE_FLAGS_COMPLETED_MASK) {
1825 beiscsi_process_mcc_compl(&phba->ctrl, mcc_compl);
1828 mcc_compl->flags = 0;
1829 queue_tail_inc(mcc_cq);
1830 mcc_compl = queue_tail_node(mcc_cq);
1831 mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
1835 if (num_processed > 0)
1836 hwi_ring_cq_db(phba, mcc_cq->id, num_processed, 1);
1839 static void beiscsi_mcc_work(struct work_struct *work)
1841 struct be_eq_obj *pbe_eq;
1842 struct beiscsi_hba *phba;
1844 pbe_eq = container_of(work, struct be_eq_obj, mcc_work);
1845 phba = pbe_eq->phba;
1846 beiscsi_process_mcc_cq(phba);
1847 /* rearm EQ for further interrupts */
1848 if (!beiscsi_hba_in_error(phba))
1849 hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1);
1853 * beiscsi_process_cq()- Process the Completion Queue
1854 * @pbe_eq: Event Q on which the Completion has come
1855 * @budget: Max number of events to processed
1858 * Number of Completion Entries processed.
1860 unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq, int budget)
1862 struct be_queue_info *cq;
1863 struct sol_cqe *sol;
1864 struct dmsg_cqe *dmsg;
1865 unsigned int total = 0;
1866 unsigned int num_processed = 0;
1867 unsigned short code = 0, cid = 0;
1868 uint16_t cri_index = 0;
1869 struct beiscsi_conn *beiscsi_conn;
1870 struct beiscsi_endpoint *beiscsi_ep;
1871 struct iscsi_endpoint *ep;
1872 struct beiscsi_hba *phba;
1875 sol = queue_tail_node(cq);
1876 phba = pbe_eq->phba;
1878 while (sol->dw[offsetof(struct amap_sol_cqe, valid) / 32] &
1880 if (beiscsi_hba_in_error(phba))
1883 be_dws_le_to_cpu(sol, sizeof(struct sol_cqe));
1885 code = (sol->dw[offsetof(struct amap_sol_cqe, code) /
1886 32] & CQE_CODE_MASK);
1889 if (is_chip_be2_be3r(phba)) {
1890 cid = AMAP_GET_BITS(struct amap_sol_cqe, cid, sol);
1892 if ((code == DRIVERMSG_NOTIFY) ||
1893 (code == UNSOL_HDR_NOTIFY) ||
1894 (code == UNSOL_DATA_NOTIFY))
1895 cid = AMAP_GET_BITS(
1896 struct amap_i_t_dpdu_cqe_v2,
1899 cid = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1903 cri_index = BE_GET_CRI_FROM_CID(cid);
1904 ep = phba->ep_array[cri_index];
1907 /* connection has already been freed
1908 * just move on to next one
1910 beiscsi_log(phba, KERN_WARNING,
1912 "BM_%d : proc cqe of disconn ep: cid %d\n",
1917 beiscsi_ep = ep->dd_data;
1918 beiscsi_conn = beiscsi_ep->conn;
1921 if (num_processed == 32) {
1922 hwi_ring_cq_db(phba, cq->id, 32, 0);
1928 case SOL_CMD_COMPLETE:
1929 hwi_complete_cmd(beiscsi_conn, phba, sol);
1931 case DRIVERMSG_NOTIFY:
1932 beiscsi_log(phba, KERN_INFO,
1933 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1934 "BM_%d : Received %s[%d] on CID : %d\n",
1935 cqe_desc[code], code, cid);
1937 dmsg = (struct dmsg_cqe *)sol;
1938 hwi_complete_drvr_msgs(beiscsi_conn, phba, sol);
1940 case UNSOL_HDR_NOTIFY:
1941 beiscsi_log(phba, KERN_INFO,
1942 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1943 "BM_%d : Received %s[%d] on CID : %d\n",
1944 cqe_desc[code], code, cid);
1946 spin_lock_bh(&phba->async_pdu_lock);
1947 beiscsi_hdq_process_compl(beiscsi_conn,
1948 (struct i_t_dpdu_cqe *)sol);
1949 spin_unlock_bh(&phba->async_pdu_lock);
1951 case UNSOL_DATA_NOTIFY:
1952 beiscsi_log(phba, KERN_INFO,
1953 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1954 "BM_%d : Received %s[%d] on CID : %d\n",
1955 cqe_desc[code], code, cid);
1957 spin_lock_bh(&phba->async_pdu_lock);
1958 beiscsi_hdq_process_compl(beiscsi_conn,
1959 (struct i_t_dpdu_cqe *)sol);
1960 spin_unlock_bh(&phba->async_pdu_lock);
1962 case CXN_INVALIDATE_INDEX_NOTIFY:
1963 case CMD_INVALIDATED_NOTIFY:
1964 case CXN_INVALIDATE_NOTIFY:
1965 beiscsi_log(phba, KERN_ERR,
1966 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1967 "BM_%d : Ignoring %s[%d] on CID : %d\n",
1968 cqe_desc[code], code, cid);
1970 case CXN_KILLED_HDR_DIGEST_ERR:
1971 case SOL_CMD_KILLED_DATA_DIGEST_ERR:
1972 beiscsi_log(phba, KERN_ERR,
1973 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1974 "BM_%d : Cmd Notification %s[%d] on CID : %d\n",
1975 cqe_desc[code], code, cid);
1977 case CMD_KILLED_INVALID_STATSN_RCVD:
1978 case CMD_KILLED_INVALID_R2T_RCVD:
1979 case CMD_CXN_KILLED_LUN_INVALID:
1980 case CMD_CXN_KILLED_ICD_INVALID:
1981 case CMD_CXN_KILLED_ITT_INVALID:
1982 case CMD_CXN_KILLED_SEQ_OUTOFORDER:
1983 case CMD_CXN_KILLED_INVALID_DATASN_RCVD:
1984 beiscsi_log(phba, KERN_ERR,
1985 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1986 "BM_%d : Cmd Notification %s[%d] on CID : %d\n",
1987 cqe_desc[code], code, cid);
1989 case UNSOL_DATA_DIGEST_ERROR_NOTIFY:
1990 beiscsi_log(phba, KERN_ERR,
1991 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1992 "BM_%d : Dropping %s[%d] on DPDU ring on CID : %d\n",
1993 cqe_desc[code], code, cid);
1994 spin_lock_bh(&phba->async_pdu_lock);
1995 /* driver consumes the entry and drops the contents */
1996 beiscsi_hdq_process_compl(beiscsi_conn,
1997 (struct i_t_dpdu_cqe *)sol);
1998 spin_unlock_bh(&phba->async_pdu_lock);
2000 case CXN_KILLED_PDU_SIZE_EXCEEDS_DSL:
2001 case CXN_KILLED_BURST_LEN_MISMATCH:
2002 case CXN_KILLED_AHS_RCVD:
2003 case CXN_KILLED_UNKNOWN_HDR:
2004 case CXN_KILLED_STALE_ITT_TTT_RCVD:
2005 case CXN_KILLED_INVALID_ITT_TTT_RCVD:
2006 case CXN_KILLED_TIMED_OUT:
2007 case CXN_KILLED_FIN_RCVD:
2008 case CXN_KILLED_RST_SENT:
2009 case CXN_KILLED_RST_RCVD:
2010 case CXN_KILLED_BAD_UNSOL_PDU_RCVD:
2011 case CXN_KILLED_BAD_WRB_INDEX_ERROR:
2012 case CXN_KILLED_OVER_RUN_RESIDUAL:
2013 case CXN_KILLED_UNDER_RUN_RESIDUAL:
2014 case CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN:
2015 beiscsi_log(phba, KERN_ERR,
2016 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
2017 "BM_%d : Event %s[%d] received on CID : %d\n",
2018 cqe_desc[code], code, cid);
2020 iscsi_conn_failure(beiscsi_conn->conn,
2021 ISCSI_ERR_CONN_FAILED);
2024 beiscsi_log(phba, KERN_ERR,
2025 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
2026 "BM_%d : Invalid CQE Event Received Code : %d"
2033 AMAP_SET_BITS(struct amap_sol_cqe, valid, sol, 0);
2035 sol = queue_tail_node(cq);
2037 if (total == budget)
2041 hwi_ring_cq_db(phba, cq->id, num_processed, 1);
2045 static int be_iopoll(struct irq_poll *iop, int budget)
2047 unsigned int ret, io_events;
2048 struct beiscsi_hba *phba;
2049 struct be_eq_obj *pbe_eq;
2050 struct be_eq_entry *eqe = NULL;
2051 struct be_queue_info *eq;
2053 pbe_eq = container_of(iop, struct be_eq_obj, iopoll);
2054 phba = pbe_eq->phba;
2055 if (beiscsi_hba_in_error(phba)) {
2056 irq_poll_complete(iop);
2062 eqe = queue_tail_node(eq);
2063 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32] &
2065 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
2067 eqe = queue_tail_node(eq);
2070 hwi_ring_eq_db(phba, eq->id, 1, io_events, 0, 1);
2072 ret = beiscsi_process_cq(pbe_eq, budget);
2073 pbe_eq->cq_count += ret;
2075 irq_poll_complete(iop);
2076 beiscsi_log(phba, KERN_INFO,
2077 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
2078 "BM_%d : rearm pbe_eq->q.id =%d ret %d\n",
2080 if (!beiscsi_hba_in_error(phba))
2081 hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1);
2087 hwi_write_sgl_v2(struct iscsi_wrb *pwrb, struct scatterlist *sg,
2088 unsigned int num_sg, struct beiscsi_io_task *io_task)
2090 struct iscsi_sge *psgl;
2091 unsigned int sg_len, index;
2092 unsigned int sge_len = 0;
2093 unsigned long long addr;
2094 struct scatterlist *l_sg;
2095 unsigned int offset;
2097 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_lo, pwrb,
2098 io_task->bhs_pa.u.a32.address_lo);
2099 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_hi, pwrb,
2100 io_task->bhs_pa.u.a32.address_hi);
2103 for (index = 0; (index < num_sg) && (index < 2); index++,
2106 sg_len = sg_dma_len(sg);
2107 addr = (u64) sg_dma_address(sg);
2108 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2110 lower_32_bits(addr));
2111 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2113 upper_32_bits(addr));
2114 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2119 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_r2t_offset,
2121 sg_len = sg_dma_len(sg);
2122 addr = (u64) sg_dma_address(sg);
2123 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2125 lower_32_bits(addr));
2126 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2128 upper_32_bits(addr));
2129 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2134 psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
2135 memset(psgl, 0, sizeof(*psgl) * BE2_SGE);
2137 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2);
2139 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2140 io_task->bhs_pa.u.a32.address_hi);
2141 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2142 io_task->bhs_pa.u.a32.address_lo);
2145 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb,
2147 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb,
2149 } else if (num_sg == 2) {
2150 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb,
2152 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb,
2155 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb,
2157 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb,
2165 for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) {
2166 sg_len = sg_dma_len(sg);
2167 addr = (u64) sg_dma_address(sg);
2168 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2169 lower_32_bits(addr));
2170 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2171 upper_32_bits(addr));
2172 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len);
2173 AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset);
2174 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
2178 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
2182 hwi_write_sgl(struct iscsi_wrb *pwrb, struct scatterlist *sg,
2183 unsigned int num_sg, struct beiscsi_io_task *io_task)
2185 struct iscsi_sge *psgl;
2186 unsigned int sg_len, index;
2187 unsigned int sge_len = 0;
2188 unsigned long long addr;
2189 struct scatterlist *l_sg;
2190 unsigned int offset;
2192 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
2193 io_task->bhs_pa.u.a32.address_lo);
2194 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
2195 io_task->bhs_pa.u.a32.address_hi);
2198 for (index = 0; (index < num_sg) && (index < 2); index++,
2201 sg_len = sg_dma_len(sg);
2202 addr = (u64) sg_dma_address(sg);
2203 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
2204 ((u32)(addr & 0xFFFFFFFF)));
2205 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
2206 ((u32)(addr >> 32)));
2207 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
2211 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_r2t_offset,
2213 sg_len = sg_dma_len(sg);
2214 addr = (u64) sg_dma_address(sg);
2215 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_lo, pwrb,
2216 ((u32)(addr & 0xFFFFFFFF)));
2217 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_hi, pwrb,
2218 ((u32)(addr >> 32)));
2219 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_len, pwrb,
2223 psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
2224 memset(psgl, 0, sizeof(*psgl) * BE2_SGE);
2226 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2);
2228 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2229 io_task->bhs_pa.u.a32.address_hi);
2230 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2231 io_task->bhs_pa.u.a32.address_lo);
2234 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
2236 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
2238 } else if (num_sg == 2) {
2239 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
2241 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
2244 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
2246 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
2253 for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) {
2254 sg_len = sg_dma_len(sg);
2255 addr = (u64) sg_dma_address(sg);
2256 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2257 (addr & 0xFFFFFFFF));
2258 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2260 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len);
2261 AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset);
2262 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
2266 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
2270 * hwi_write_buffer()- Populate the WRB with task info
2271 * @pwrb: ptr to the WRB entry
2272 * @task: iscsi task which is to be executed
2274 static int hwi_write_buffer(struct iscsi_wrb *pwrb, struct iscsi_task *task)
2276 struct iscsi_sge *psgl;
2277 struct beiscsi_io_task *io_task = task->dd_data;
2278 struct beiscsi_conn *beiscsi_conn = io_task->conn;
2279 struct beiscsi_hba *phba = beiscsi_conn->phba;
2280 uint8_t dsp_value = 0;
2282 io_task->bhs_len = sizeof(struct be_nonio_bhs) - 2;
2283 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
2284 io_task->bhs_pa.u.a32.address_lo);
2285 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
2286 io_task->bhs_pa.u.a32.address_hi);
2290 /* Check for the data_count */
2291 dsp_value = (task->data_count) ? 1 : 0;
2293 if (is_chip_be2_be3r(phba))
2294 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp,
2297 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp,
2300 /* Map addr only if there is data_count */
2302 io_task->mtask_addr = pci_map_single(phba->pcidev,
2306 if (pci_dma_mapping_error(phba->pcidev,
2307 io_task->mtask_addr))
2309 io_task->mtask_data_count = task->data_count;
2311 io_task->mtask_addr = 0;
2313 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
2314 lower_32_bits(io_task->mtask_addr));
2315 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
2316 upper_32_bits(io_task->mtask_addr));
2317 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
2320 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, 1);
2322 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
2323 io_task->mtask_addr = 0;
2326 psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
2328 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len);
2330 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2331 io_task->bhs_pa.u.a32.address_hi);
2332 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2333 io_task->bhs_pa.u.a32.address_lo);
2336 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, 0);
2337 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, 0);
2338 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0);
2339 AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, 0);
2340 AMAP_SET_BITS(struct amap_iscsi_sge, rsvd0, psgl, 0);
2341 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
2345 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2346 lower_32_bits(io_task->mtask_addr));
2347 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2348 upper_32_bits(io_task->mtask_addr));
2350 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0x106);
2352 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
2357 * beiscsi_find_mem_req()- Find mem needed
2358 * @phba: ptr to HBA struct
2360 static void beiscsi_find_mem_req(struct beiscsi_hba *phba)
2362 uint8_t mem_descr_index, ulp_num;
2363 unsigned int num_async_pdu_buf_pages;
2364 unsigned int num_async_pdu_data_pages, wrb_sz_per_cxn;
2365 unsigned int num_async_pdu_buf_sgl_pages, num_async_pdu_data_sgl_pages;
2367 phba->params.hwi_ws_sz = sizeof(struct hwi_controller);
2369 phba->mem_req[ISCSI_MEM_GLOBAL_HEADER] = 2 *
2370 BE_ISCSI_PDU_HEADER_SIZE;
2371 phba->mem_req[HWI_MEM_ADDN_CONTEXT] =
2372 sizeof(struct hwi_context_memory);
2375 phba->mem_req[HWI_MEM_WRB] = sizeof(struct iscsi_wrb)
2376 * (phba->params.wrbs_per_cxn)
2377 * phba->params.cxns_per_ctrl;
2378 wrb_sz_per_cxn = sizeof(struct wrb_handle) *
2379 (phba->params.wrbs_per_cxn);
2380 phba->mem_req[HWI_MEM_WRBH] = roundup_pow_of_two((wrb_sz_per_cxn) *
2381 phba->params.cxns_per_ctrl);
2383 phba->mem_req[HWI_MEM_SGLH] = sizeof(struct sgl_handle) *
2384 phba->params.icds_per_ctrl;
2385 phba->mem_req[HWI_MEM_SGE] = sizeof(struct iscsi_sge) *
2386 phba->params.num_sge_per_io * phba->params.icds_per_ctrl;
2387 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
2388 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
2390 num_async_pdu_buf_sgl_pages =
2391 PAGES_REQUIRED(BEISCSI_ASYNC_HDQ_SIZE(
2393 sizeof(struct phys_addr));
2395 num_async_pdu_buf_pages =
2396 PAGES_REQUIRED(BEISCSI_ASYNC_HDQ_SIZE(
2398 phba->params.defpdu_hdr_sz);
2400 num_async_pdu_data_pages =
2401 PAGES_REQUIRED(BEISCSI_ASYNC_HDQ_SIZE(
2403 phba->params.defpdu_data_sz);
2405 num_async_pdu_data_sgl_pages =
2406 PAGES_REQUIRED(BEISCSI_ASYNC_HDQ_SIZE(
2408 sizeof(struct phys_addr));
2410 mem_descr_index = (HWI_MEM_TEMPLATE_HDR_ULP0 +
2411 (ulp_num * MEM_DESCR_OFFSET));
2412 phba->mem_req[mem_descr_index] =
2413 BEISCSI_GET_CID_COUNT(phba, ulp_num) *
2414 BEISCSI_TEMPLATE_HDR_PER_CXN_SIZE;
2416 mem_descr_index = (HWI_MEM_ASYNC_HEADER_BUF_ULP0 +
2417 (ulp_num * MEM_DESCR_OFFSET));
2418 phba->mem_req[mem_descr_index] =
2419 num_async_pdu_buf_pages *
2422 mem_descr_index = (HWI_MEM_ASYNC_DATA_BUF_ULP0 +
2423 (ulp_num * MEM_DESCR_OFFSET));
2424 phba->mem_req[mem_descr_index] =
2425 num_async_pdu_data_pages *
2428 mem_descr_index = (HWI_MEM_ASYNC_HEADER_RING_ULP0 +
2429 (ulp_num * MEM_DESCR_OFFSET));
2430 phba->mem_req[mem_descr_index] =
2431 num_async_pdu_buf_sgl_pages *
2434 mem_descr_index = (HWI_MEM_ASYNC_DATA_RING_ULP0 +
2435 (ulp_num * MEM_DESCR_OFFSET));
2436 phba->mem_req[mem_descr_index] =
2437 num_async_pdu_data_sgl_pages *
2440 mem_descr_index = (HWI_MEM_ASYNC_HEADER_HANDLE_ULP0 +
2441 (ulp_num * MEM_DESCR_OFFSET));
2442 phba->mem_req[mem_descr_index] =
2443 BEISCSI_ASYNC_HDQ_SIZE(phba, ulp_num) *
2444 sizeof(struct hd_async_handle);
2446 mem_descr_index = (HWI_MEM_ASYNC_DATA_HANDLE_ULP0 +
2447 (ulp_num * MEM_DESCR_OFFSET));
2448 phba->mem_req[mem_descr_index] =
2449 BEISCSI_ASYNC_HDQ_SIZE(phba, ulp_num) *
2450 sizeof(struct hd_async_handle);
2452 mem_descr_index = (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0 +
2453 (ulp_num * MEM_DESCR_OFFSET));
2454 phba->mem_req[mem_descr_index] =
2455 sizeof(struct hd_async_context) +
2456 (BEISCSI_ASYNC_HDQ_SIZE(phba, ulp_num) *
2457 sizeof(struct hd_async_entry));
2462 static int beiscsi_alloc_mem(struct beiscsi_hba *phba)
2465 struct hwi_controller *phwi_ctrlr;
2466 struct be_mem_descriptor *mem_descr;
2467 struct mem_array *mem_arr, *mem_arr_orig;
2468 unsigned int i, j, alloc_size, curr_alloc_size;
2470 phba->phwi_ctrlr = kzalloc(phba->params.hwi_ws_sz, GFP_KERNEL);
2471 if (!phba->phwi_ctrlr)
2474 /* Allocate memory for wrb_context */
2475 phwi_ctrlr = phba->phwi_ctrlr;
2476 phwi_ctrlr->wrb_context = kzalloc(sizeof(struct hwi_wrb_context) *
2477 phba->params.cxns_per_ctrl,
2479 if (!phwi_ctrlr->wrb_context) {
2480 kfree(phba->phwi_ctrlr);
2484 phba->init_mem = kcalloc(SE_MEM_MAX, sizeof(*mem_descr),
2486 if (!phba->init_mem) {
2487 kfree(phwi_ctrlr->wrb_context);
2488 kfree(phba->phwi_ctrlr);
2492 mem_arr_orig = kmalloc(sizeof(*mem_arr_orig) * BEISCSI_MAX_FRAGS_INIT,
2494 if (!mem_arr_orig) {
2495 kfree(phba->init_mem);
2496 kfree(phwi_ctrlr->wrb_context);
2497 kfree(phba->phwi_ctrlr);
2501 mem_descr = phba->init_mem;
2502 for (i = 0; i < SE_MEM_MAX; i++) {
2503 if (!phba->mem_req[i]) {
2504 mem_descr->mem_array = NULL;
2510 mem_arr = mem_arr_orig;
2511 alloc_size = phba->mem_req[i];
2512 memset(mem_arr, 0, sizeof(struct mem_array) *
2513 BEISCSI_MAX_FRAGS_INIT);
2514 curr_alloc_size = min(be_max_phys_size * 1024, alloc_size);
2516 mem_arr->virtual_address = pci_alloc_consistent(
2520 if (!mem_arr->virtual_address) {
2521 if (curr_alloc_size <= BE_MIN_MEM_SIZE)
2523 if (curr_alloc_size -
2524 rounddown_pow_of_two(curr_alloc_size))
2525 curr_alloc_size = rounddown_pow_of_two
2528 curr_alloc_size = curr_alloc_size / 2;
2530 mem_arr->bus_address.u.
2531 a64.address = (__u64) bus_add;
2532 mem_arr->size = curr_alloc_size;
2533 alloc_size -= curr_alloc_size;
2534 curr_alloc_size = min(be_max_phys_size *
2539 } while (alloc_size);
2540 mem_descr->num_elements = j;
2541 mem_descr->size_in_bytes = phba->mem_req[i];
2542 mem_descr->mem_array = kmalloc(sizeof(*mem_arr) * j,
2544 if (!mem_descr->mem_array)
2547 memcpy(mem_descr->mem_array, mem_arr_orig,
2548 sizeof(struct mem_array) * j);
2551 kfree(mem_arr_orig);
2554 mem_descr->num_elements = j;
2555 while ((i) || (j)) {
2556 for (j = mem_descr->num_elements; j > 0; j--) {
2557 pci_free_consistent(phba->pcidev,
2558 mem_descr->mem_array[j - 1].size,
2559 mem_descr->mem_array[j - 1].
2561 (unsigned long)mem_descr->
2563 bus_address.u.a64.address);
2567 kfree(mem_descr->mem_array);
2571 kfree(mem_arr_orig);
2572 kfree(phba->init_mem);
2573 kfree(phba->phwi_ctrlr->wrb_context);
2574 kfree(phba->phwi_ctrlr);
2578 static int beiscsi_get_memory(struct beiscsi_hba *phba)
2580 beiscsi_find_mem_req(phba);
2581 return beiscsi_alloc_mem(phba);
2584 static void iscsi_init_global_templates(struct beiscsi_hba *phba)
2586 struct pdu_data_out *pdata_out;
2587 struct pdu_nop_out *pnop_out;
2588 struct be_mem_descriptor *mem_descr;
2590 mem_descr = phba->init_mem;
2591 mem_descr += ISCSI_MEM_GLOBAL_HEADER;
2593 (struct pdu_data_out *)mem_descr->mem_array[0].virtual_address;
2594 memset(pdata_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
2596 AMAP_SET_BITS(struct amap_pdu_data_out, opcode, pdata_out,
2600 (struct pdu_nop_out *)((unsigned char *)mem_descr->mem_array[0].
2601 virtual_address + BE_ISCSI_PDU_HEADER_SIZE);
2603 memset(pnop_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
2604 AMAP_SET_BITS(struct amap_pdu_nop_out, ttt, pnop_out, 0xFFFFFFFF);
2605 AMAP_SET_BITS(struct amap_pdu_nop_out, f_bit, pnop_out, 1);
2606 AMAP_SET_BITS(struct amap_pdu_nop_out, i_bit, pnop_out, 0);
2609 static int beiscsi_init_wrb_handle(struct beiscsi_hba *phba)
2611 struct be_mem_descriptor *mem_descr_wrbh, *mem_descr_wrb;
2612 struct hwi_context_memory *phwi_ctxt;
2613 struct wrb_handle *pwrb_handle = NULL;
2614 struct hwi_controller *phwi_ctrlr;
2615 struct hwi_wrb_context *pwrb_context;
2616 struct iscsi_wrb *pwrb = NULL;
2617 unsigned int num_cxn_wrbh = 0;
2618 unsigned int num_cxn_wrb = 0, j, idx = 0, index;
2620 mem_descr_wrbh = phba->init_mem;
2621 mem_descr_wrbh += HWI_MEM_WRBH;
2623 mem_descr_wrb = phba->init_mem;
2624 mem_descr_wrb += HWI_MEM_WRB;
2625 phwi_ctrlr = phba->phwi_ctrlr;
2627 /* Allocate memory for WRBQ */
2628 phwi_ctxt = phwi_ctrlr->phwi_ctxt;
2629 phwi_ctxt->be_wrbq = kzalloc(sizeof(struct be_queue_info) *
2630 phba->params.cxns_per_ctrl,
2632 if (!phwi_ctxt->be_wrbq) {
2633 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2634 "BM_%d : WRBQ Mem Alloc Failed\n");
2638 for (index = 0; index < phba->params.cxns_per_ctrl; index++) {
2639 pwrb_context = &phwi_ctrlr->wrb_context[index];
2640 pwrb_context->pwrb_handle_base =
2641 kzalloc(sizeof(struct wrb_handle *) *
2642 phba->params.wrbs_per_cxn, GFP_KERNEL);
2643 if (!pwrb_context->pwrb_handle_base) {
2644 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2645 "BM_%d : Mem Alloc Failed. Failing to load\n");
2646 goto init_wrb_hndl_failed;
2648 pwrb_context->pwrb_handle_basestd =
2649 kzalloc(sizeof(struct wrb_handle *) *
2650 phba->params.wrbs_per_cxn, GFP_KERNEL);
2651 if (!pwrb_context->pwrb_handle_basestd) {
2652 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2653 "BM_%d : Mem Alloc Failed. Failing to load\n");
2654 goto init_wrb_hndl_failed;
2656 if (!num_cxn_wrbh) {
2658 mem_descr_wrbh->mem_array[idx].virtual_address;
2659 num_cxn_wrbh = ((mem_descr_wrbh->mem_array[idx].size) /
2660 ((sizeof(struct wrb_handle)) *
2661 phba->params.wrbs_per_cxn));
2664 pwrb_context->alloc_index = 0;
2665 pwrb_context->wrb_handles_available = 0;
2666 pwrb_context->free_index = 0;
2669 for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
2670 pwrb_context->pwrb_handle_base[j] = pwrb_handle;
2671 pwrb_context->pwrb_handle_basestd[j] =
2673 pwrb_context->wrb_handles_available++;
2674 pwrb_handle->wrb_index = j;
2679 spin_lock_init(&pwrb_context->wrb_lock);
2682 for (index = 0; index < phba->params.cxns_per_ctrl; index++) {
2683 pwrb_context = &phwi_ctrlr->wrb_context[index];
2685 pwrb = mem_descr_wrb->mem_array[idx].virtual_address;
2686 num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) /
2687 ((sizeof(struct iscsi_wrb) *
2688 phba->params.wrbs_per_cxn));
2693 for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
2694 pwrb_handle = pwrb_context->pwrb_handle_base[j];
2695 pwrb_handle->pwrb = pwrb;
2702 init_wrb_hndl_failed:
2703 for (j = index; j > 0; j--) {
2704 pwrb_context = &phwi_ctrlr->wrb_context[j];
2705 kfree(pwrb_context->pwrb_handle_base);
2706 kfree(pwrb_context->pwrb_handle_basestd);
2711 static int hwi_init_async_pdu_ctx(struct beiscsi_hba *phba)
2714 struct hwi_controller *phwi_ctrlr;
2715 struct hba_parameters *p = &phba->params;
2716 struct hd_async_context *pasync_ctx;
2717 struct hd_async_handle *pasync_header_h, *pasync_data_h;
2718 unsigned int index, idx, num_per_mem, num_async_data;
2719 struct be_mem_descriptor *mem_descr;
2721 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
2722 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
2723 /* get async_ctx for each ULP */
2724 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2725 mem_descr += (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0 +
2726 (ulp_num * MEM_DESCR_OFFSET));
2728 phwi_ctrlr = phba->phwi_ctrlr;
2729 phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num] =
2730 (struct hd_async_context *)
2731 mem_descr->mem_array[0].virtual_address;
2733 pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num];
2734 memset(pasync_ctx, 0, sizeof(*pasync_ctx));
2736 pasync_ctx->async_entry =
2737 (struct hd_async_entry *)
2738 ((long unsigned int)pasync_ctx +
2739 sizeof(struct hd_async_context));
2741 pasync_ctx->num_entries = BEISCSI_ASYNC_HDQ_SIZE(phba,
2743 /* setup header buffers */
2744 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2745 mem_descr += HWI_MEM_ASYNC_HEADER_BUF_ULP0 +
2746 (ulp_num * MEM_DESCR_OFFSET);
2747 if (mem_descr->mem_array[0].virtual_address) {
2748 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2749 "BM_%d : hwi_init_async_pdu_ctx"
2750 " HWI_MEM_ASYNC_HEADER_BUF_ULP%d va=%p\n",
2752 mem_descr->mem_array[0].
2755 beiscsi_log(phba, KERN_WARNING,
2757 "BM_%d : No Virtual address for ULP : %d\n",
2760 pasync_ctx->async_header.pi = 0;
2761 pasync_ctx->async_header.buffer_size = p->defpdu_hdr_sz;
2762 pasync_ctx->async_header.va_base =
2763 mem_descr->mem_array[0].virtual_address;
2765 pasync_ctx->async_header.pa_base.u.a64.address =
2766 mem_descr->mem_array[0].
2767 bus_address.u.a64.address;
2769 /* setup header buffer sgls */
2770 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2771 mem_descr += HWI_MEM_ASYNC_HEADER_RING_ULP0 +
2772 (ulp_num * MEM_DESCR_OFFSET);
2773 if (mem_descr->mem_array[0].virtual_address) {
2774 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2775 "BM_%d : hwi_init_async_pdu_ctx"
2776 " HWI_MEM_ASYNC_HEADER_RING_ULP%d va=%p\n",
2778 mem_descr->mem_array[0].
2781 beiscsi_log(phba, KERN_WARNING,
2783 "BM_%d : No Virtual address for ULP : %d\n",
2786 pasync_ctx->async_header.ring_base =
2787 mem_descr->mem_array[0].virtual_address;
2789 /* setup header buffer handles */
2790 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2791 mem_descr += HWI_MEM_ASYNC_HEADER_HANDLE_ULP0 +
2792 (ulp_num * MEM_DESCR_OFFSET);
2793 if (mem_descr->mem_array[0].virtual_address) {
2794 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2795 "BM_%d : hwi_init_async_pdu_ctx"
2796 " HWI_MEM_ASYNC_HEADER_HANDLE_ULP%d va=%p\n",
2798 mem_descr->mem_array[0].
2801 beiscsi_log(phba, KERN_WARNING,
2803 "BM_%d : No Virtual address for ULP : %d\n",
2806 pasync_ctx->async_header.handle_base =
2807 mem_descr->mem_array[0].virtual_address;
2809 /* setup data buffer sgls */
2810 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2811 mem_descr += HWI_MEM_ASYNC_DATA_RING_ULP0 +
2812 (ulp_num * MEM_DESCR_OFFSET);
2813 if (mem_descr->mem_array[0].virtual_address) {
2814 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2815 "BM_%d : hwi_init_async_pdu_ctx"
2816 " HWI_MEM_ASYNC_DATA_RING_ULP%d va=%p\n",
2818 mem_descr->mem_array[0].
2821 beiscsi_log(phba, KERN_WARNING,
2823 "BM_%d : No Virtual address for ULP : %d\n",
2826 pasync_ctx->async_data.ring_base =
2827 mem_descr->mem_array[0].virtual_address;
2829 /* setup data buffer handles */
2830 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2831 mem_descr += HWI_MEM_ASYNC_DATA_HANDLE_ULP0 +
2832 (ulp_num * MEM_DESCR_OFFSET);
2833 if (!mem_descr->mem_array[0].virtual_address)
2834 beiscsi_log(phba, KERN_WARNING,
2836 "BM_%d : No Virtual address for ULP : %d\n",
2839 pasync_ctx->async_data.handle_base =
2840 mem_descr->mem_array[0].virtual_address;
2843 (struct hd_async_handle *)
2844 pasync_ctx->async_header.handle_base;
2846 (struct hd_async_handle *)
2847 pasync_ctx->async_data.handle_base;
2849 /* setup data buffers */
2850 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2851 mem_descr += HWI_MEM_ASYNC_DATA_BUF_ULP0 +
2852 (ulp_num * MEM_DESCR_OFFSET);
2853 if (mem_descr->mem_array[0].virtual_address) {
2854 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2855 "BM_%d : hwi_init_async_pdu_ctx"
2856 " HWI_MEM_ASYNC_DATA_BUF_ULP%d va=%p\n",
2858 mem_descr->mem_array[0].
2861 beiscsi_log(phba, KERN_WARNING,
2863 "BM_%d : No Virtual address for ULP : %d\n",
2867 pasync_ctx->async_data.pi = 0;
2868 pasync_ctx->async_data.buffer_size = p->defpdu_data_sz;
2869 pasync_ctx->async_data.va_base =
2870 mem_descr->mem_array[idx].virtual_address;
2871 pasync_ctx->async_data.pa_base.u.a64.address =
2872 mem_descr->mem_array[idx].
2873 bus_address.u.a64.address;
2875 num_async_data = ((mem_descr->mem_array[idx].size) /
2876 phba->params.defpdu_data_sz);
2879 for (index = 0; index < BEISCSI_ASYNC_HDQ_SIZE
2880 (phba, ulp_num); index++) {
2881 pasync_header_h->cri = -1;
2882 pasync_header_h->is_header = 1;
2883 pasync_header_h->index = index;
2884 INIT_LIST_HEAD(&pasync_header_h->link);
2885 pasync_header_h->pbuffer =
2886 (void *)((unsigned long)
2888 async_header.va_base) +
2889 (p->defpdu_hdr_sz * index));
2891 pasync_header_h->pa.u.a64.address =
2892 pasync_ctx->async_header.pa_base.u.a64.
2893 address + (p->defpdu_hdr_sz * index);
2895 pasync_ctx->async_entry[index].header =
2898 INIT_LIST_HEAD(&pasync_ctx->async_entry[index].
2901 pasync_data_h->cri = -1;
2902 pasync_data_h->is_header = 0;
2903 pasync_data_h->index = index;
2904 INIT_LIST_HEAD(&pasync_data_h->link);
2906 if (!num_async_data) {
2909 pasync_ctx->async_data.va_base =
2910 mem_descr->mem_array[idx].
2912 pasync_ctx->async_data.pa_base.u.
2914 mem_descr->mem_array[idx].
2915 bus_address.u.a64.address;
2917 ((mem_descr->mem_array[idx].
2919 phba->params.defpdu_data_sz);
2921 pasync_data_h->pbuffer =
2922 (void *)((unsigned long)
2923 (pasync_ctx->async_data.va_base) +
2924 (p->defpdu_data_sz * num_per_mem));
2926 pasync_data_h->pa.u.a64.address =
2927 pasync_ctx->async_data.pa_base.u.a64.
2928 address + (p->defpdu_data_sz *
2933 pasync_ctx->async_entry[index].data =
2944 be_sgl_create_contiguous(void *virtual_address,
2945 u64 physical_address, u32 length,
2946 struct be_dma_mem *sgl)
2948 WARN_ON(!virtual_address);
2949 WARN_ON(!physical_address);
2953 sgl->va = virtual_address;
2954 sgl->dma = (unsigned long)physical_address;
2960 static void be_sgl_destroy_contiguous(struct be_dma_mem *sgl)
2962 memset(sgl, 0, sizeof(*sgl));
2966 hwi_build_be_sgl_arr(struct beiscsi_hba *phba,
2967 struct mem_array *pmem, struct be_dma_mem *sgl)
2970 be_sgl_destroy_contiguous(sgl);
2972 be_sgl_create_contiguous(pmem->virtual_address,
2973 pmem->bus_address.u.a64.address,
2978 hwi_build_be_sgl_by_offset(struct beiscsi_hba *phba,
2979 struct mem_array *pmem, struct be_dma_mem *sgl)
2982 be_sgl_destroy_contiguous(sgl);
2984 be_sgl_create_contiguous((unsigned char *)pmem->virtual_address,
2985 pmem->bus_address.u.a64.address,
2989 static int be_fill_queue(struct be_queue_info *q,
2990 u16 len, u16 entry_size, void *vaddress)
2992 struct be_dma_mem *mem = &q->dma_mem;
2994 memset(q, 0, sizeof(*q));
2996 q->entry_size = entry_size;
2997 mem->size = len * entry_size;
3001 memset(mem->va, 0, mem->size);
3005 static int beiscsi_create_eqs(struct beiscsi_hba *phba,
3006 struct hwi_context_memory *phwi_context)
3008 int ret = -ENOMEM, eq_for_mcc;
3009 unsigned int i, num_eq_pages;
3010 struct be_queue_info *eq;
3011 struct be_dma_mem *mem;
3015 num_eq_pages = PAGES_REQUIRED(phba->params.num_eq_entries * \
3016 sizeof(struct be_eq_entry));
3018 if (phba->pcidev->msix_enabled)
3022 for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
3023 eq = &phwi_context->be_eq[i].q;
3025 phwi_context->be_eq[i].phba = phba;
3026 eq_vaddress = pci_alloc_consistent(phba->pcidev,
3027 num_eq_pages * PAGE_SIZE,
3031 goto create_eq_error;
3034 mem->va = eq_vaddress;
3035 ret = be_fill_queue(eq, phba->params.num_eq_entries,
3036 sizeof(struct be_eq_entry), eq_vaddress);
3038 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3039 "BM_%d : be_fill_queue Failed for EQ\n");
3040 goto create_eq_error;
3044 ret = beiscsi_cmd_eq_create(&phba->ctrl, eq,
3045 phwi_context->cur_eqd);
3047 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3048 "BM_%d : beiscsi_cmd_eq_create"
3050 goto create_eq_error;
3053 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3054 "BM_%d : eqid = %d\n",
3055 phwi_context->be_eq[i].q.id);
3060 for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
3061 eq = &phwi_context->be_eq[i].q;
3064 pci_free_consistent(phba->pcidev, num_eq_pages
3071 static int beiscsi_create_cqs(struct beiscsi_hba *phba,
3072 struct hwi_context_memory *phwi_context)
3074 unsigned int i, num_cq_pages;
3075 struct be_queue_info *cq, *eq;
3076 struct be_dma_mem *mem;
3077 struct be_eq_obj *pbe_eq;
3082 num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
3083 sizeof(struct sol_cqe));
3085 for (i = 0; i < phba->num_cpus; i++) {
3086 cq = &phwi_context->be_cq[i];
3087 eq = &phwi_context->be_eq[i].q;
3088 pbe_eq = &phwi_context->be_eq[i];
3090 pbe_eq->phba = phba;
3092 cq_vaddress = pci_alloc_consistent(phba->pcidev,
3093 num_cq_pages * PAGE_SIZE,
3097 goto create_cq_error;
3100 ret = be_fill_queue(cq, phba->params.num_cq_entries,
3101 sizeof(struct sol_cqe), cq_vaddress);
3103 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3104 "BM_%d : be_fill_queue Failed "
3106 goto create_cq_error;
3110 ret = beiscsi_cmd_cq_create(&phba->ctrl, cq, eq, false,
3113 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3114 "BM_%d : beiscsi_cmd_eq_create"
3115 "Failed for ISCSI CQ\n");
3116 goto create_cq_error;
3118 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3119 "BM_%d : iscsi cq_id is %d for eq_id %d\n"
3120 "iSCSI CQ CREATED\n", cq->id, eq->id);
3125 for (i = 0; i < phba->num_cpus; i++) {
3126 cq = &phwi_context->be_cq[i];
3129 pci_free_consistent(phba->pcidev, num_cq_pages
3137 beiscsi_create_def_hdr(struct beiscsi_hba *phba,
3138 struct hwi_context_memory *phwi_context,
3139 struct hwi_controller *phwi_ctrlr,
3140 unsigned int def_pdu_ring_sz, uint8_t ulp_num)
3144 struct be_queue_info *dq, *cq;
3145 struct be_dma_mem *mem;
3146 struct be_mem_descriptor *mem_descr;
3150 dq = &phwi_context->be_def_hdrq[ulp_num];
3151 cq = &phwi_context->be_cq[0];
3153 mem_descr = phba->init_mem;
3154 mem_descr += HWI_MEM_ASYNC_HEADER_RING_ULP0 +
3155 (ulp_num * MEM_DESCR_OFFSET);
3156 dq_vaddress = mem_descr->mem_array[idx].virtual_address;
3157 ret = be_fill_queue(dq, mem_descr->mem_array[0].size /
3158 sizeof(struct phys_addr),
3159 sizeof(struct phys_addr), dq_vaddress);
3161 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3162 "BM_%d : be_fill_queue Failed for DEF PDU HDR on ULP : %d\n",
3167 mem->dma = (unsigned long)mem_descr->mem_array[idx].
3168 bus_address.u.a64.address;
3169 ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dq,
3171 phba->params.defpdu_hdr_sz,
3172 BEISCSI_DEFQ_HDR, ulp_num);
3174 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3175 "BM_%d : be_cmd_create_default_pdu_queue Failed DEFHDR on ULP : %d\n",
3181 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3182 "BM_%d : iscsi hdr def pdu id for ULP : %d is %d\n",
3184 phwi_context->be_def_hdrq[ulp_num].id);
3189 beiscsi_create_def_data(struct beiscsi_hba *phba,
3190 struct hwi_context_memory *phwi_context,
3191 struct hwi_controller *phwi_ctrlr,
3192 unsigned int def_pdu_ring_sz, uint8_t ulp_num)
3196 struct be_queue_info *dataq, *cq;
3197 struct be_dma_mem *mem;
3198 struct be_mem_descriptor *mem_descr;
3202 dataq = &phwi_context->be_def_dataq[ulp_num];
3203 cq = &phwi_context->be_cq[0];
3204 mem = &dataq->dma_mem;
3205 mem_descr = phba->init_mem;
3206 mem_descr += HWI_MEM_ASYNC_DATA_RING_ULP0 +
3207 (ulp_num * MEM_DESCR_OFFSET);
3208 dq_vaddress = mem_descr->mem_array[idx].virtual_address;
3209 ret = be_fill_queue(dataq, mem_descr->mem_array[0].size /
3210 sizeof(struct phys_addr),
3211 sizeof(struct phys_addr), dq_vaddress);
3213 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3214 "BM_%d : be_fill_queue Failed for DEF PDU "
3215 "DATA on ULP : %d\n",
3220 mem->dma = (unsigned long)mem_descr->mem_array[idx].
3221 bus_address.u.a64.address;
3222 ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dataq,
3224 phba->params.defpdu_data_sz,
3225 BEISCSI_DEFQ_DATA, ulp_num);
3227 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3228 "BM_%d be_cmd_create_default_pdu_queue"
3229 " Failed for DEF PDU DATA on ULP : %d\n",
3234 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3235 "BM_%d : iscsi def data id on ULP : %d is %d\n",
3237 phwi_context->be_def_dataq[ulp_num].id);
3239 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3240 "BM_%d : DEFAULT PDU DATA RING CREATED"
3241 "on ULP : %d\n", ulp_num);
3247 beiscsi_post_template_hdr(struct beiscsi_hba *phba)
3249 struct be_mem_descriptor *mem_descr;
3250 struct mem_array *pm_arr;
3251 struct be_dma_mem sgl;
3252 int status, ulp_num;
3254 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
3255 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
3256 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
3257 mem_descr += HWI_MEM_TEMPLATE_HDR_ULP0 +
3258 (ulp_num * MEM_DESCR_OFFSET);
3259 pm_arr = mem_descr->mem_array;
3261 hwi_build_be_sgl_arr(phba, pm_arr, &sgl);
3262 status = be_cmd_iscsi_post_template_hdr(
3266 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3267 "BM_%d : Post Template HDR Failed for"
3268 "ULP_%d\n", ulp_num);
3272 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3273 "BM_%d : Template HDR Pages Posted for"
3274 "ULP_%d\n", ulp_num);
3281 beiscsi_post_pages(struct beiscsi_hba *phba)
3283 struct be_mem_descriptor *mem_descr;
3284 struct mem_array *pm_arr;
3285 unsigned int page_offset, i;
3286 struct be_dma_mem sgl;
3287 int status, ulp_num = 0;
3289 mem_descr = phba->init_mem;
3290 mem_descr += HWI_MEM_SGE;
3291 pm_arr = mem_descr->mem_array;
3293 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
3294 if (test_bit(ulp_num, &phba->fw_config.ulp_supported))
3297 page_offset = (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io *
3298 phba->fw_config.iscsi_icd_start[ulp_num]) / PAGE_SIZE;
3299 for (i = 0; i < mem_descr->num_elements; i++) {
3300 hwi_build_be_sgl_arr(phba, pm_arr, &sgl);
3301 status = be_cmd_iscsi_post_sgl_pages(&phba->ctrl, &sgl,
3303 (pm_arr->size / PAGE_SIZE));
3304 page_offset += pm_arr->size / PAGE_SIZE;
3306 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3307 "BM_%d : post sgl failed.\n");
3312 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3313 "BM_%d : POSTED PAGES\n");
3317 static void be_queue_free(struct beiscsi_hba *phba, struct be_queue_info *q)
3319 struct be_dma_mem *mem = &q->dma_mem;
3321 pci_free_consistent(phba->pcidev, mem->size,
3327 static int be_queue_alloc(struct beiscsi_hba *phba, struct be_queue_info *q,
3328 u16 len, u16 entry_size)
3330 struct be_dma_mem *mem = &q->dma_mem;
3332 memset(q, 0, sizeof(*q));
3334 q->entry_size = entry_size;
3335 mem->size = len * entry_size;
3336 mem->va = pci_zalloc_consistent(phba->pcidev, mem->size, &mem->dma);
3343 beiscsi_create_wrb_rings(struct beiscsi_hba *phba,
3344 struct hwi_context_memory *phwi_context,
3345 struct hwi_controller *phwi_ctrlr)
3347 unsigned int num_wrb_rings;
3349 unsigned int idx, num, i, ulp_num;
3350 struct mem_array *pwrb_arr;
3352 struct be_dma_mem sgl;
3353 struct be_mem_descriptor *mem_descr;
3354 struct hwi_wrb_context *pwrb_context;
3356 uint8_t ulp_count = 0, ulp_base_num = 0;
3357 uint16_t cid_count_ulp[BEISCSI_ULP_COUNT] = { 0 };
3360 mem_descr = phba->init_mem;
3361 mem_descr += HWI_MEM_WRB;
3362 pwrb_arr = kmalloc(sizeof(*pwrb_arr) * phba->params.cxns_per_ctrl,
3365 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3366 "BM_%d : Memory alloc failed in create wrb ring.\n");
3369 wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
3370 pa_addr_lo = mem_descr->mem_array[idx].bus_address.u.a64.address;
3371 num_wrb_rings = mem_descr->mem_array[idx].size /
3372 (phba->params.wrbs_per_cxn * sizeof(struct iscsi_wrb));
3374 for (num = 0; num < phba->params.cxns_per_ctrl; num++) {
3375 if (num_wrb_rings) {
3376 pwrb_arr[num].virtual_address = wrb_vaddr;
3377 pwrb_arr[num].bus_address.u.a64.address = pa_addr_lo;
3378 pwrb_arr[num].size = phba->params.wrbs_per_cxn *
3379 sizeof(struct iscsi_wrb);
3380 wrb_vaddr += pwrb_arr[num].size;
3381 pa_addr_lo += pwrb_arr[num].size;
3385 wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
3386 pa_addr_lo = mem_descr->mem_array[idx].\
3387 bus_address.u.a64.address;
3388 num_wrb_rings = mem_descr->mem_array[idx].size /
3389 (phba->params.wrbs_per_cxn *
3390 sizeof(struct iscsi_wrb));
3391 pwrb_arr[num].virtual_address = wrb_vaddr;
3392 pwrb_arr[num].bus_address.u.a64.address\
3394 pwrb_arr[num].size = phba->params.wrbs_per_cxn *
3395 sizeof(struct iscsi_wrb);
3396 wrb_vaddr += pwrb_arr[num].size;
3397 pa_addr_lo += pwrb_arr[num].size;
3402 /* Get the ULP Count */
3403 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
3404 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
3406 ulp_base_num = ulp_num;
3407 cid_count_ulp[ulp_num] =
3408 BEISCSI_GET_CID_COUNT(phba, ulp_num);
3411 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
3412 if (ulp_count > 1) {
3413 ulp_base_num = (ulp_base_num + 1) % BEISCSI_ULP_COUNT;
3415 if (!cid_count_ulp[ulp_base_num])
3416 ulp_base_num = (ulp_base_num + 1) %
3419 cid_count_ulp[ulp_base_num]--;
3423 hwi_build_be_sgl_by_offset(phba, &pwrb_arr[i], &sgl);
3424 status = be_cmd_wrbq_create(&phba->ctrl, &sgl,
3425 &phwi_context->be_wrbq[i],
3426 &phwi_ctrlr->wrb_context[i],
3429 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3430 "BM_%d : wrbq create failed.");
3434 pwrb_context = &phwi_ctrlr->wrb_context[i];
3435 BE_SET_CID_TO_CRI(i, pwrb_context->cid);
3441 static void free_wrb_handles(struct beiscsi_hba *phba)
3444 struct hwi_controller *phwi_ctrlr;
3445 struct hwi_wrb_context *pwrb_context;
3447 phwi_ctrlr = phba->phwi_ctrlr;
3448 for (index = 0; index < phba->params.cxns_per_ctrl; index++) {
3449 pwrb_context = &phwi_ctrlr->wrb_context[index];
3450 kfree(pwrb_context->pwrb_handle_base);
3451 kfree(pwrb_context->pwrb_handle_basestd);
3455 static void be_mcc_queues_destroy(struct beiscsi_hba *phba)
3457 struct be_ctrl_info *ctrl = &phba->ctrl;
3458 struct be_dma_mem *ptag_mem;
3459 struct be_queue_info *q;
3462 q = &phba->ctrl.mcc_obj.q;
3463 for (i = 0; i < MAX_MCC_CMD; i++) {
3465 if (!test_bit(MCC_TAG_STATE_RUNNING,
3466 &ctrl->ptag_state[tag].tag_state))
3469 if (test_bit(MCC_TAG_STATE_TIMEOUT,
3470 &ctrl->ptag_state[tag].tag_state)) {
3471 ptag_mem = &ctrl->ptag_state[tag].tag_mem_state;
3472 if (ptag_mem->size) {
3473 pci_free_consistent(ctrl->pdev,
3482 * If MCC is still active and waiting then wake up the process.
3483 * We are here only because port is going offline. The process
3484 * sees that (BEISCSI_HBA_ONLINE is cleared) and EIO error is
3485 * returned for the operation and allocated memory cleaned up.
3487 if (waitqueue_active(&ctrl->mcc_wait[tag])) {
3488 ctrl->mcc_tag_status[tag] = MCC_STATUS_FAILED;
3489 ctrl->mcc_tag_status[tag] |= CQE_VALID_MASK;
3490 wake_up_interruptible(&ctrl->mcc_wait[tag]);
3492 * Control tag info gets reinitialized in enable
3493 * so wait for the process to clear running state.
3495 while (test_bit(MCC_TAG_STATE_RUNNING,
3496 &ctrl->ptag_state[tag].tag_state))
3497 schedule_timeout_uninterruptible(HZ);
3500 * For MCC with tag_states MCC_TAG_STATE_ASYNC and
3501 * MCC_TAG_STATE_IGNORE nothing needs to done.
3505 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_MCCQ);
3506 be_queue_free(phba, q);
3509 q = &phba->ctrl.mcc_obj.cq;
3511 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
3512 be_queue_free(phba, q);
3516 static int be_mcc_queues_create(struct beiscsi_hba *phba,
3517 struct hwi_context_memory *phwi_context)
3519 struct be_queue_info *q, *cq;
3520 struct be_ctrl_info *ctrl = &phba->ctrl;
3522 /* Alloc MCC compl queue */
3523 cq = &phba->ctrl.mcc_obj.cq;
3524 if (be_queue_alloc(phba, cq, MCC_CQ_LEN,
3525 sizeof(struct be_mcc_compl)))
3527 /* Ask BE to create MCC compl queue; */
3528 if (phba->pcidev->msix_enabled) {
3529 if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq
3530 [phba->num_cpus].q, false, true, 0))
3533 if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq[0].q,
3538 /* Alloc MCC queue */
3539 q = &phba->ctrl.mcc_obj.q;
3540 if (be_queue_alloc(phba, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb)))
3541 goto mcc_cq_destroy;
3543 /* Ask BE to create MCC queue */
3544 if (beiscsi_cmd_mccq_create(phba, q, cq))
3550 be_queue_free(phba, q);
3552 beiscsi_cmd_q_destroy(ctrl, cq, QTYPE_CQ);
3554 be_queue_free(phba, cq);
3559 static void be2iscsi_enable_msix(struct beiscsi_hba *phba)
3563 switch (phba->generation) {
3566 nvec = BEISCSI_MAX_NUM_CPUS + 1;
3569 nvec = phba->fw_config.eqid_count;
3576 /* if eqid_count == 1 fall back to INTX */
3577 if (enable_msix && nvec > 1) {
3578 const struct irq_affinity desc = { .post_vectors = 1 };
3580 if (pci_alloc_irq_vectors_affinity(phba->pcidev, 2, nvec,
3581 PCI_IRQ_MSIX | PCI_IRQ_AFFINITY, &desc) < 0) {
3582 phba->num_cpus = nvec - 1;
3590 static void hwi_purge_eq(struct beiscsi_hba *phba)
3592 struct hwi_controller *phwi_ctrlr;
3593 struct hwi_context_memory *phwi_context;
3594 struct be_queue_info *eq;
3595 struct be_eq_entry *eqe = NULL;
3597 unsigned int num_processed;
3599 if (beiscsi_hba_in_error(phba))
3602 phwi_ctrlr = phba->phwi_ctrlr;
3603 phwi_context = phwi_ctrlr->phwi_ctxt;
3604 if (phba->pcidev->msix_enabled)
3609 for (i = 0; i < (phba->num_cpus + eq_msix); i++) {
3610 eq = &phwi_context->be_eq[i].q;
3611 eqe = queue_tail_node(eq);
3613 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
3615 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
3617 eqe = queue_tail_node(eq);
3622 hwi_ring_eq_db(phba, eq->id, 1, num_processed, 1, 1);
3626 static void hwi_cleanup_port(struct beiscsi_hba *phba)
3628 struct be_queue_info *q;
3629 struct be_ctrl_info *ctrl = &phba->ctrl;
3630 struct hwi_controller *phwi_ctrlr;
3631 struct hwi_context_memory *phwi_context;
3632 int i, eq_for_mcc, ulp_num;
3634 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
3635 if (test_bit(ulp_num, &phba->fw_config.ulp_supported))
3636 beiscsi_cmd_iscsi_cleanup(phba, ulp_num);
3639 * Purge all EQ entries that may have been left out. This is to
3640 * workaround a problem we've seen occasionally where driver gets an
3641 * interrupt with EQ entry bit set after stopping the controller.
3645 phwi_ctrlr = phba->phwi_ctrlr;
3646 phwi_context = phwi_ctrlr->phwi_ctxt;
3648 be_cmd_iscsi_remove_template_hdr(ctrl);
3650 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
3651 q = &phwi_context->be_wrbq[i];
3653 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_WRBQ);
3655 kfree(phwi_context->be_wrbq);
3656 free_wrb_handles(phba);
3658 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
3659 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
3661 q = &phwi_context->be_def_hdrq[ulp_num];
3663 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
3665 q = &phwi_context->be_def_dataq[ulp_num];
3667 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
3671 beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
3673 for (i = 0; i < (phba->num_cpus); i++) {
3674 q = &phwi_context->be_cq[i];
3676 be_queue_free(phba, q);
3677 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
3681 be_mcc_queues_destroy(phba);
3682 if (phba->pcidev->msix_enabled)
3686 for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
3687 q = &phwi_context->be_eq[i].q;
3689 be_queue_free(phba, q);
3690 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_EQ);
3693 /* this ensures complete FW cleanup */
3694 beiscsi_cmd_function_reset(phba);
3695 /* last communication, indicate driver is unloading */
3696 beiscsi_cmd_special_wrb(&phba->ctrl, 0);
3699 static int hwi_init_port(struct beiscsi_hba *phba)
3701 struct hwi_controller *phwi_ctrlr;
3702 struct hwi_context_memory *phwi_context;
3703 unsigned int def_pdu_ring_sz;
3704 struct be_ctrl_info *ctrl = &phba->ctrl;
3705 int status, ulp_num;
3708 phwi_ctrlr = phba->phwi_ctrlr;
3709 phwi_context = phwi_ctrlr->phwi_ctxt;
3710 phwi_context->max_eqd = 128;
3711 phwi_context->min_eqd = 0;
3712 phwi_context->cur_eqd = 32;
3713 /* set port optic state to unknown */
3714 phba->optic_state = 0xff;
3716 status = beiscsi_create_eqs(phba, phwi_context);
3718 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3719 "BM_%d : EQ not created\n");
3723 status = be_mcc_queues_create(phba, phwi_context);
3727 status = beiscsi_check_supported_fw(ctrl, phba);
3729 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3730 "BM_%d : Unsupported fw version\n");
3734 status = beiscsi_create_cqs(phba, phwi_context);
3736 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3737 "BM_%d : CQ not created\n");
3741 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
3742 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
3743 nbufs = phwi_context->pasync_ctx[ulp_num]->num_entries;
3744 def_pdu_ring_sz = nbufs * sizeof(struct phys_addr);
3746 status = beiscsi_create_def_hdr(phba, phwi_context,
3751 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3752 "BM_%d : Default Header not created for ULP : %d\n",
3757 status = beiscsi_create_def_data(phba, phwi_context,
3762 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3763 "BM_%d : Default Data not created for ULP : %d\n",
3768 * Now that the default PDU rings have been created,
3769 * let EP know about it.
3771 beiscsi_hdq_post_handles(phba, BEISCSI_DEFQ_HDR,
3773 beiscsi_hdq_post_handles(phba, BEISCSI_DEFQ_DATA,
3778 status = beiscsi_post_pages(phba);
3780 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3781 "BM_%d : Post SGL Pages Failed\n");
3785 status = beiscsi_post_template_hdr(phba);
3787 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3788 "BM_%d : Template HDR Posting for CXN Failed\n");
3791 status = beiscsi_create_wrb_rings(phba, phwi_context, phwi_ctrlr);
3793 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3794 "BM_%d : WRB Rings not created\n");
3798 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
3799 uint16_t async_arr_idx = 0;
3801 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
3803 struct hd_async_context *pasync_ctx;
3805 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(
3806 phwi_ctrlr, ulp_num);
3808 phba->params.cxns_per_ctrl; cri++) {
3809 if (ulp_num == BEISCSI_GET_ULP_FROM_CRI
3811 pasync_ctx->cid_to_async_cri_map[
3812 phwi_ctrlr->wrb_context[cri].cid] =
3818 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3819 "BM_%d : hwi_init_port success\n");
3823 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3824 "BM_%d : hwi_init_port failed");
3825 hwi_cleanup_port(phba);
3829 static int hwi_init_controller(struct beiscsi_hba *phba)
3831 struct hwi_controller *phwi_ctrlr;
3833 phwi_ctrlr = phba->phwi_ctrlr;
3834 if (1 == phba->init_mem[HWI_MEM_ADDN_CONTEXT].num_elements) {
3835 phwi_ctrlr->phwi_ctxt = (struct hwi_context_memory *)phba->
3836 init_mem[HWI_MEM_ADDN_CONTEXT].mem_array[0].virtual_address;
3837 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3838 "BM_%d : phwi_ctrlr->phwi_ctxt=%p\n",
3839 phwi_ctrlr->phwi_ctxt);
3841 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3842 "BM_%d : HWI_MEM_ADDN_CONTEXT is more "
3843 "than one element.Failing to load\n");
3847 iscsi_init_global_templates(phba);
3848 if (beiscsi_init_wrb_handle(phba))
3851 if (hwi_init_async_pdu_ctx(phba)) {
3852 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3853 "BM_%d : hwi_init_async_pdu_ctx failed\n");
3857 if (hwi_init_port(phba) != 0) {
3858 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3859 "BM_%d : hwi_init_controller failed\n");
3866 static void beiscsi_free_mem(struct beiscsi_hba *phba)
3868 struct be_mem_descriptor *mem_descr;
3871 mem_descr = phba->init_mem;
3874 for (i = 0; i < SE_MEM_MAX; i++) {
3875 for (j = mem_descr->num_elements; j > 0; j--) {
3876 pci_free_consistent(phba->pcidev,
3877 mem_descr->mem_array[j - 1].size,
3878 mem_descr->mem_array[j - 1].virtual_address,
3879 (unsigned long)mem_descr->mem_array[j - 1].
3880 bus_address.u.a64.address);
3883 kfree(mem_descr->mem_array);
3886 kfree(phba->init_mem);
3887 kfree(phba->phwi_ctrlr->wrb_context);
3888 kfree(phba->phwi_ctrlr);
3891 static int beiscsi_init_sgl_handle(struct beiscsi_hba *phba)
3893 struct be_mem_descriptor *mem_descr_sglh, *mem_descr_sg;
3894 struct sgl_handle *psgl_handle;
3895 struct iscsi_sge *pfrag;
3896 unsigned int arr_index, i, idx;
3897 unsigned int ulp_icd_start, ulp_num = 0;
3899 phba->io_sgl_hndl_avbl = 0;
3900 phba->eh_sgl_hndl_avbl = 0;
3902 mem_descr_sglh = phba->init_mem;
3903 mem_descr_sglh += HWI_MEM_SGLH;
3904 if (1 == mem_descr_sglh->num_elements) {
3905 phba->io_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
3906 phba->params.ios_per_ctrl,
3908 if (!phba->io_sgl_hndl_base) {
3909 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3910 "BM_%d : Mem Alloc Failed. Failing to load\n");
3913 phba->eh_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
3914 (phba->params.icds_per_ctrl -
3915 phba->params.ios_per_ctrl),
3917 if (!phba->eh_sgl_hndl_base) {
3918 kfree(phba->io_sgl_hndl_base);
3919 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3920 "BM_%d : Mem Alloc Failed. Failing to load\n");
3924 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3925 "BM_%d : HWI_MEM_SGLH is more than one element."
3926 "Failing to load\n");
3932 while (idx < mem_descr_sglh->num_elements) {
3933 psgl_handle = mem_descr_sglh->mem_array[idx].virtual_address;
3935 for (i = 0; i < (mem_descr_sglh->mem_array[idx].size /
3936 sizeof(struct sgl_handle)); i++) {
3937 if (arr_index < phba->params.ios_per_ctrl) {
3938 phba->io_sgl_hndl_base[arr_index] = psgl_handle;
3939 phba->io_sgl_hndl_avbl++;
3942 phba->eh_sgl_hndl_base[arr_index -
3943 phba->params.ios_per_ctrl] =
3946 phba->eh_sgl_hndl_avbl++;
3952 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3953 "BM_%d : phba->io_sgl_hndl_avbl=%d"
3954 "phba->eh_sgl_hndl_avbl=%d\n",
3955 phba->io_sgl_hndl_avbl,
3956 phba->eh_sgl_hndl_avbl);
3958 mem_descr_sg = phba->init_mem;
3959 mem_descr_sg += HWI_MEM_SGE;
3960 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3961 "\n BM_%d : mem_descr_sg->num_elements=%d\n",
3962 mem_descr_sg->num_elements);
3964 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
3965 if (test_bit(ulp_num, &phba->fw_config.ulp_supported))
3968 ulp_icd_start = phba->fw_config.iscsi_icd_start[ulp_num];
3972 while (idx < mem_descr_sg->num_elements) {
3973 pfrag = mem_descr_sg->mem_array[idx].virtual_address;
3976 i < (mem_descr_sg->mem_array[idx].size) /
3977 (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io);
3979 if (arr_index < phba->params.ios_per_ctrl)
3980 psgl_handle = phba->io_sgl_hndl_base[arr_index];
3982 psgl_handle = phba->eh_sgl_hndl_base[arr_index -
3983 phba->params.ios_per_ctrl];
3984 psgl_handle->pfrag = pfrag;
3985 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, pfrag, 0);
3986 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, pfrag, 0);
3987 pfrag += phba->params.num_sge_per_io;
3988 psgl_handle->sgl_index = ulp_icd_start + arr_index++;
3992 phba->io_sgl_free_index = 0;
3993 phba->io_sgl_alloc_index = 0;
3994 phba->eh_sgl_free_index = 0;
3995 phba->eh_sgl_alloc_index = 0;
3999 static int hba_setup_cid_tbls(struct beiscsi_hba *phba)
4002 uint16_t i, ulp_num;
4003 struct ulp_cid_info *ptr_cid_info = NULL;
4005 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
4006 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
4007 ptr_cid_info = kzalloc(sizeof(struct ulp_cid_info),
4010 if (!ptr_cid_info) {
4011 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4012 "BM_%d : Failed to allocate memory"
4013 "for ULP_CID_INFO for ULP : %d\n",
4020 /* Allocate memory for CID array */
4021 ptr_cid_info->cid_array =
4022 kcalloc(BEISCSI_GET_CID_COUNT(phba, ulp_num),
4023 sizeof(*ptr_cid_info->cid_array),
4025 if (!ptr_cid_info->cid_array) {
4026 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4027 "BM_%d : Failed to allocate memory"
4028 "for CID_ARRAY for ULP : %d\n",
4030 kfree(ptr_cid_info);
4031 ptr_cid_info = NULL;
4036 ptr_cid_info->avlbl_cids = BEISCSI_GET_CID_COUNT(
4039 /* Save the cid_info_array ptr */
4040 phba->cid_array_info[ulp_num] = ptr_cid_info;
4043 phba->ep_array = kzalloc(sizeof(struct iscsi_endpoint *) *
4044 phba->params.cxns_per_ctrl, GFP_KERNEL);
4045 if (!phba->ep_array) {
4046 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4047 "BM_%d : Failed to allocate memory in "
4048 "hba_setup_cid_tbls\n");
4054 phba->conn_table = kzalloc(sizeof(struct beiscsi_conn *) *
4055 phba->params.cxns_per_ctrl, GFP_KERNEL);
4056 if (!phba->conn_table) {
4057 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4058 "BM_%d : Failed to allocate memory in"
4059 "hba_setup_cid_tbls\n");
4061 kfree(phba->ep_array);
4062 phba->ep_array = NULL;
4068 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
4069 ulp_num = phba->phwi_ctrlr->wrb_context[i].ulp_num;
4071 ptr_cid_info = phba->cid_array_info[ulp_num];
4072 ptr_cid_info->cid_array[ptr_cid_info->cid_alloc++] =
4073 phba->phwi_ctrlr->wrb_context[i].cid;
4077 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
4078 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
4079 ptr_cid_info = phba->cid_array_info[ulp_num];
4081 ptr_cid_info->cid_alloc = 0;
4082 ptr_cid_info->cid_free = 0;
4088 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
4089 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
4090 ptr_cid_info = phba->cid_array_info[ulp_num];
4093 kfree(ptr_cid_info->cid_array);
4094 kfree(ptr_cid_info);
4095 phba->cid_array_info[ulp_num] = NULL;
4103 static void hwi_enable_intr(struct beiscsi_hba *phba)
4105 struct be_ctrl_info *ctrl = &phba->ctrl;
4106 struct hwi_controller *phwi_ctrlr;
4107 struct hwi_context_memory *phwi_context;
4108 struct be_queue_info *eq;
4113 phwi_ctrlr = phba->phwi_ctrlr;
4114 phwi_context = phwi_ctrlr->phwi_ctxt;
4116 addr = (u8 __iomem *) ((u8 __iomem *) ctrl->pcicfg +
4117 PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET);
4118 reg = ioread32(addr);
4120 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
4122 reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
4123 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4124 "BM_%d : reg =x%08x addr=%p\n", reg, addr);
4125 iowrite32(reg, addr);
4128 if (!phba->pcidev->msix_enabled) {
4129 eq = &phwi_context->be_eq[0].q;
4130 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4131 "BM_%d : eq->id=%d\n", eq->id);
4133 hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
4135 for (i = 0; i <= phba->num_cpus; i++) {
4136 eq = &phwi_context->be_eq[i].q;
4137 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4138 "BM_%d : eq->id=%d\n", eq->id);
4139 hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
4144 static void hwi_disable_intr(struct beiscsi_hba *phba)
4146 struct be_ctrl_info *ctrl = &phba->ctrl;
4148 u8 __iomem *addr = ctrl->pcicfg + PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET;
4149 u32 reg = ioread32(addr);
4151 u32 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
4153 reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
4154 iowrite32(reg, addr);
4156 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
4157 "BM_%d : In hwi_disable_intr, Already Disabled\n");
4160 static int beiscsi_init_port(struct beiscsi_hba *phba)
4164 ret = hwi_init_controller(phba);
4166 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4167 "BM_%d : init controller failed\n");
4170 ret = beiscsi_init_sgl_handle(phba);
4172 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4173 "BM_%d : init sgl handles failed\n");
4177 ret = hba_setup_cid_tbls(phba);
4179 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4180 "BM_%d : setup CID table failed\n");
4181 kfree(phba->io_sgl_hndl_base);
4182 kfree(phba->eh_sgl_hndl_base);
4188 hwi_cleanup_port(phba);
4192 static void beiscsi_cleanup_port(struct beiscsi_hba *phba)
4194 struct ulp_cid_info *ptr_cid_info = NULL;
4197 kfree(phba->io_sgl_hndl_base);
4198 kfree(phba->eh_sgl_hndl_base);
4199 kfree(phba->ep_array);
4200 kfree(phba->conn_table);
4202 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
4203 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
4204 ptr_cid_info = phba->cid_array_info[ulp_num];
4207 kfree(ptr_cid_info->cid_array);
4208 kfree(ptr_cid_info);
4209 phba->cid_array_info[ulp_num] = NULL;
4216 * beiscsi_free_mgmt_task_handles()- Free driver CXN resources
4217 * @beiscsi_conn: ptr to the conn to be cleaned up
4218 * @task: ptr to iscsi_task resource to be freed.
4220 * Free driver mgmt resources binded to CXN.
4223 beiscsi_free_mgmt_task_handles(struct beiscsi_conn *beiscsi_conn,
4224 struct iscsi_task *task)
4226 struct beiscsi_io_task *io_task;
4227 struct beiscsi_hba *phba = beiscsi_conn->phba;
4228 struct hwi_wrb_context *pwrb_context;
4229 struct hwi_controller *phwi_ctrlr;
4230 uint16_t cri_index = BE_GET_CRI_FROM_CID(
4231 beiscsi_conn->beiscsi_conn_cid);
4233 phwi_ctrlr = phba->phwi_ctrlr;
4234 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
4236 io_task = task->dd_data;
4238 if (io_task->pwrb_handle) {
4239 free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle);
4240 io_task->pwrb_handle = NULL;
4243 if (io_task->psgl_handle) {
4244 free_mgmt_sgl_handle(phba, io_task->psgl_handle);
4245 io_task->psgl_handle = NULL;
4248 if (io_task->mtask_addr) {
4249 pci_unmap_single(phba->pcidev,
4250 io_task->mtask_addr,
4251 io_task->mtask_data_count,
4253 io_task->mtask_addr = 0;
4258 * beiscsi_cleanup_task()- Free driver resources of the task
4259 * @task: ptr to the iscsi task
4262 static void beiscsi_cleanup_task(struct iscsi_task *task)
4264 struct beiscsi_io_task *io_task = task->dd_data;
4265 struct iscsi_conn *conn = task->conn;
4266 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4267 struct beiscsi_hba *phba = beiscsi_conn->phba;
4268 struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
4269 struct hwi_wrb_context *pwrb_context;
4270 struct hwi_controller *phwi_ctrlr;
4271 uint16_t cri_index = BE_GET_CRI_FROM_CID(
4272 beiscsi_conn->beiscsi_conn_cid);
4274 phwi_ctrlr = phba->phwi_ctrlr;
4275 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
4277 if (io_task->cmd_bhs) {
4278 dma_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
4279 io_task->bhs_pa.u.a64.address);
4280 io_task->cmd_bhs = NULL;
4285 if (io_task->pwrb_handle) {
4286 free_wrb_handle(phba, pwrb_context,
4287 io_task->pwrb_handle);
4288 io_task->pwrb_handle = NULL;
4291 if (io_task->psgl_handle) {
4292 free_io_sgl_handle(phba, io_task->psgl_handle);
4293 io_task->psgl_handle = NULL;
4296 if (io_task->scsi_cmnd) {
4297 if (io_task->num_sg)
4298 scsi_dma_unmap(io_task->scsi_cmnd);
4299 io_task->scsi_cmnd = NULL;
4302 if (!beiscsi_conn->login_in_progress)
4303 beiscsi_free_mgmt_task_handles(beiscsi_conn, task);
4308 beiscsi_offload_connection(struct beiscsi_conn *beiscsi_conn,
4309 struct beiscsi_offload_params *params)
4311 struct wrb_handle *pwrb_handle;
4312 struct hwi_wrb_context *pwrb_context = NULL;
4313 struct beiscsi_hba *phba = beiscsi_conn->phba;
4314 struct iscsi_task *task = beiscsi_conn->task;
4315 struct iscsi_session *session = task->conn->session;
4319 * We can always use 0 here because it is reserved by libiscsi for
4320 * login/startup related tasks.
4322 beiscsi_conn->login_in_progress = 0;
4323 spin_lock_bh(&session->back_lock);
4324 beiscsi_cleanup_task(task);
4325 spin_unlock_bh(&session->back_lock);
4327 pwrb_handle = alloc_wrb_handle(phba, beiscsi_conn->beiscsi_conn_cid,
4330 /* Check for the adapter family */
4331 if (is_chip_be2_be3r(phba))
4332 beiscsi_offload_cxn_v0(params, pwrb_handle,
4336 beiscsi_offload_cxn_v2(params, pwrb_handle,
4339 be_dws_le_to_cpu(pwrb_handle->pwrb,
4340 sizeof(struct iscsi_target_context_update_wrb));
4342 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
4343 doorbell |= (pwrb_handle->wrb_index & DB_DEF_PDU_WRB_INDEX_MASK)
4344 << DB_DEF_PDU_WRB_INDEX_SHIFT;
4345 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
4346 iowrite32(doorbell, phba->db_va +
4347 beiscsi_conn->doorbell_offset);
4350 * There is no completion for CONTEXT_UPDATE. The completion of next
4351 * WRB posted guarantees FW's processing and DMA'ing of it.
4352 * Use beiscsi_put_wrb_handle to put it back in the pool which makes
4353 * sure zero'ing or reuse of the WRB only after wrbs_per_cxn.
4355 beiscsi_put_wrb_handle(pwrb_context, pwrb_handle,
4356 phba->params.wrbs_per_cxn);
4357 beiscsi_log(phba, KERN_INFO,
4358 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
4359 "BM_%d : put CONTEXT_UPDATE pwrb_handle=%p free_index=0x%x wrb_handles_available=%d\n",
4360 pwrb_handle, pwrb_context->free_index,
4361 pwrb_context->wrb_handles_available);
4364 static void beiscsi_parse_pdu(struct iscsi_conn *conn, itt_t itt,
4365 int *index, int *age)
4369 *age = conn->session->age;
4373 * beiscsi_alloc_pdu - allocates pdu and related resources
4374 * @task: libiscsi task
4375 * @opcode: opcode of pdu for task
4377 * This is called with the session lock held. It will allocate
4378 * the wrb and sgl if needed for the command. And it will prep
4379 * the pdu's itt. beiscsi_parse_pdu will later translate
4380 * the pdu itt to the libiscsi task itt.
4382 static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
4384 struct beiscsi_io_task *io_task = task->dd_data;
4385 struct iscsi_conn *conn = task->conn;
4386 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4387 struct beiscsi_hba *phba = beiscsi_conn->phba;
4388 struct hwi_wrb_context *pwrb_context;
4389 struct hwi_controller *phwi_ctrlr;
4391 uint16_t cri_index = 0;
4392 struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
4395 io_task->cmd_bhs = dma_pool_alloc(beiscsi_sess->bhs_pool,
4396 GFP_ATOMIC, &paddr);
4397 if (!io_task->cmd_bhs)
4399 io_task->bhs_pa.u.a64.address = paddr;
4400 io_task->libiscsi_itt = (itt_t)task->itt;
4401 io_task->conn = beiscsi_conn;
4403 task->hdr = (struct iscsi_hdr *)&io_task->cmd_bhs->iscsi_hdr;
4404 task->hdr_max = sizeof(struct be_cmd_bhs);
4405 io_task->psgl_handle = NULL;
4406 io_task->pwrb_handle = NULL;
4409 io_task->psgl_handle = alloc_io_sgl_handle(phba);
4410 if (!io_task->psgl_handle) {
4411 beiscsi_log(phba, KERN_ERR,
4412 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
4413 "BM_%d : Alloc of IO_SGL_ICD Failed"
4414 "for the CID : %d\n",
4415 beiscsi_conn->beiscsi_conn_cid);
4418 io_task->pwrb_handle = alloc_wrb_handle(phba,
4419 beiscsi_conn->beiscsi_conn_cid,
4420 &io_task->pwrb_context);
4421 if (!io_task->pwrb_handle) {
4422 beiscsi_log(phba, KERN_ERR,
4423 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
4424 "BM_%d : Alloc of WRB_HANDLE Failed"
4425 "for the CID : %d\n",
4426 beiscsi_conn->beiscsi_conn_cid);
4430 io_task->scsi_cmnd = NULL;
4431 if ((opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN) {
4432 beiscsi_conn->task = task;
4433 if (!beiscsi_conn->login_in_progress) {
4434 io_task->psgl_handle = (struct sgl_handle *)
4435 alloc_mgmt_sgl_handle(phba);
4436 if (!io_task->psgl_handle) {
4437 beiscsi_log(phba, KERN_ERR,
4440 "BM_%d : Alloc of MGMT_SGL_ICD Failed"
4441 "for the CID : %d\n",
4447 beiscsi_conn->login_in_progress = 1;
4448 beiscsi_conn->plogin_sgl_handle =
4449 io_task->psgl_handle;
4450 io_task->pwrb_handle =
4451 alloc_wrb_handle(phba,
4452 beiscsi_conn->beiscsi_conn_cid,
4453 &io_task->pwrb_context);
4454 if (!io_task->pwrb_handle) {
4455 beiscsi_log(phba, KERN_ERR,
4458 "BM_%d : Alloc of WRB_HANDLE Failed"
4459 "for the CID : %d\n",
4462 goto free_mgmt_hndls;
4464 beiscsi_conn->plogin_wrb_handle =
4465 io_task->pwrb_handle;
4468 io_task->psgl_handle =
4469 beiscsi_conn->plogin_sgl_handle;
4470 io_task->pwrb_handle =
4471 beiscsi_conn->plogin_wrb_handle;
4474 io_task->psgl_handle = alloc_mgmt_sgl_handle(phba);
4475 if (!io_task->psgl_handle) {
4476 beiscsi_log(phba, KERN_ERR,
4479 "BM_%d : Alloc of MGMT_SGL_ICD Failed"
4480 "for the CID : %d\n",
4485 io_task->pwrb_handle =
4486 alloc_wrb_handle(phba,
4487 beiscsi_conn->beiscsi_conn_cid,
4488 &io_task->pwrb_context);
4489 if (!io_task->pwrb_handle) {
4490 beiscsi_log(phba, KERN_ERR,
4491 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
4492 "BM_%d : Alloc of WRB_HANDLE Failed"
4493 "for the CID : %d\n",
4494 beiscsi_conn->beiscsi_conn_cid);
4495 goto free_mgmt_hndls;
4500 itt = (itt_t) cpu_to_be32(((unsigned int)io_task->pwrb_handle->
4501 wrb_index << 16) | (unsigned int)
4502 (io_task->psgl_handle->sgl_index));
4503 io_task->pwrb_handle->pio_handle = task;
4505 io_task->cmd_bhs->iscsi_hdr.itt = itt;
4509 free_io_sgl_handle(phba, io_task->psgl_handle);
4512 free_mgmt_sgl_handle(phba, io_task->psgl_handle);
4513 io_task->psgl_handle = NULL;
4515 phwi_ctrlr = phba->phwi_ctrlr;
4516 cri_index = BE_GET_CRI_FROM_CID(
4517 beiscsi_conn->beiscsi_conn_cid);
4518 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
4519 if (io_task->pwrb_handle)
4520 free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle);
4521 io_task->pwrb_handle = NULL;
4522 dma_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
4523 io_task->bhs_pa.u.a64.address);
4524 io_task->cmd_bhs = NULL;
4527 static int beiscsi_iotask_v2(struct iscsi_task *task, struct scatterlist *sg,
4528 unsigned int num_sg, unsigned int xferlen,
4529 unsigned int writedir)
4532 struct beiscsi_io_task *io_task = task->dd_data;
4533 struct iscsi_conn *conn = task->conn;
4534 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4535 struct beiscsi_hba *phba = beiscsi_conn->phba;
4536 struct iscsi_wrb *pwrb = NULL;
4537 unsigned int doorbell = 0;
4539 pwrb = io_task->pwrb_handle->pwrb;
4541 io_task->bhs_len = sizeof(struct be_cmd_bhs);
4544 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb,
4546 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 1);
4548 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb,
4550 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 0);
4553 io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb_v2,
4556 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, lun, pwrb,
4557 cpu_to_be16(*(unsigned short *)
4558 &io_task->cmd_bhs->iscsi_hdr.lun));
4559 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb, xferlen);
4560 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb,
4561 io_task->pwrb_handle->wrb_index);
4562 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb,
4563 be32_to_cpu(task->cmdsn));
4564 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb,
4565 io_task->psgl_handle->sgl_index);
4567 hwi_write_sgl_v2(pwrb, sg, num_sg, io_task);
4568 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb,
4569 io_task->pwrb_handle->wrb_index);
4570 if (io_task->pwrb_context->plast_wrb)
4571 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb,
4572 io_task->pwrb_context->plast_wrb,
4573 io_task->pwrb_handle->wrb_index);
4574 io_task->pwrb_context->plast_wrb = pwrb;
4576 be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
4578 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
4579 doorbell |= (io_task->pwrb_handle->wrb_index &
4580 DB_DEF_PDU_WRB_INDEX_MASK) <<
4581 DB_DEF_PDU_WRB_INDEX_SHIFT;
4582 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
4583 iowrite32(doorbell, phba->db_va +
4584 beiscsi_conn->doorbell_offset);
4588 static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg,
4589 unsigned int num_sg, unsigned int xferlen,
4590 unsigned int writedir)
4593 struct beiscsi_io_task *io_task = task->dd_data;
4594 struct iscsi_conn *conn = task->conn;
4595 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4596 struct beiscsi_hba *phba = beiscsi_conn->phba;
4597 struct iscsi_wrb *pwrb = NULL;
4598 unsigned int doorbell = 0;
4600 pwrb = io_task->pwrb_handle->pwrb;
4601 io_task->bhs_len = sizeof(struct be_cmd_bhs);
4604 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4606 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1);
4608 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4610 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
4613 io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb,
4616 AMAP_SET_BITS(struct amap_iscsi_wrb, lun, pwrb,
4617 cpu_to_be16(*(unsigned short *)
4618 &io_task->cmd_bhs->iscsi_hdr.lun));
4619 AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, xferlen);
4620 AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
4621 io_task->pwrb_handle->wrb_index);
4622 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
4623 be32_to_cpu(task->cmdsn));
4624 AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
4625 io_task->psgl_handle->sgl_index);
4627 hwi_write_sgl(pwrb, sg, num_sg, io_task);
4629 AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
4630 io_task->pwrb_handle->wrb_index);
4631 if (io_task->pwrb_context->plast_wrb)
4632 AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb,
4633 io_task->pwrb_context->plast_wrb,
4634 io_task->pwrb_handle->wrb_index);
4635 io_task->pwrb_context->plast_wrb = pwrb;
4637 be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
4639 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
4640 doorbell |= (io_task->pwrb_handle->wrb_index &
4641 DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
4642 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
4644 iowrite32(doorbell, phba->db_va +
4645 beiscsi_conn->doorbell_offset);
4649 static int beiscsi_mtask(struct iscsi_task *task)
4651 struct beiscsi_io_task *io_task = task->dd_data;
4652 struct iscsi_conn *conn = task->conn;
4653 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4654 struct beiscsi_hba *phba = beiscsi_conn->phba;
4655 struct iscsi_wrb *pwrb = NULL;
4656 unsigned int doorbell = 0;
4658 unsigned int pwrb_typeoffset = 0;
4661 cid = beiscsi_conn->beiscsi_conn_cid;
4662 pwrb = io_task->pwrb_handle->pwrb;
4664 if (is_chip_be2_be3r(phba)) {
4665 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
4666 be32_to_cpu(task->cmdsn));
4667 AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
4668 io_task->pwrb_handle->wrb_index);
4669 AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
4670 io_task->psgl_handle->sgl_index);
4671 AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb,
4673 AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
4674 io_task->pwrb_handle->wrb_index);
4675 if (io_task->pwrb_context->plast_wrb)
4676 AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb,
4677 io_task->pwrb_context->plast_wrb,
4678 io_task->pwrb_handle->wrb_index);
4679 io_task->pwrb_context->plast_wrb = pwrb;
4681 pwrb_typeoffset = BE_WRB_TYPE_OFFSET;
4683 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb,
4684 be32_to_cpu(task->cmdsn));
4685 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb,
4686 io_task->pwrb_handle->wrb_index);
4687 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb,
4688 io_task->psgl_handle->sgl_index);
4689 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb,
4691 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb,
4692 io_task->pwrb_handle->wrb_index);
4693 if (io_task->pwrb_context->plast_wrb)
4694 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb,
4695 io_task->pwrb_context->plast_wrb,
4696 io_task->pwrb_handle->wrb_index);
4697 io_task->pwrb_context->plast_wrb = pwrb;
4699 pwrb_typeoffset = SKH_WRB_TYPE_OFFSET;
4703 switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
4704 case ISCSI_OP_LOGIN:
4705 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, 1);
4706 ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset);
4707 ret = hwi_write_buffer(pwrb, task);
4709 case ISCSI_OP_NOOP_OUT:
4710 if (task->hdr->ttt != ISCSI_RESERVED_TAG) {
4711 ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset);
4712 if (is_chip_be2_be3r(phba))
4713 AMAP_SET_BITS(struct amap_iscsi_wrb,
4716 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
4719 ADAPTER_SET_WRB_TYPE(pwrb, INI_RD_CMD, pwrb_typeoffset);
4720 if (is_chip_be2_be3r(phba))
4721 AMAP_SET_BITS(struct amap_iscsi_wrb,
4724 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
4727 ret = hwi_write_buffer(pwrb, task);
4730 ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset);
4731 ret = hwi_write_buffer(pwrb, task);
4733 case ISCSI_OP_SCSI_TMFUNC:
4734 ADAPTER_SET_WRB_TYPE(pwrb, INI_TMF_CMD, pwrb_typeoffset);
4735 ret = hwi_write_buffer(pwrb, task);
4737 case ISCSI_OP_LOGOUT:
4738 ADAPTER_SET_WRB_TYPE(pwrb, HWH_TYPE_LOGOUT, pwrb_typeoffset);
4739 ret = hwi_write_buffer(pwrb, task);
4743 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
4744 "BM_%d : opcode =%d Not supported\n",
4745 task->hdr->opcode & ISCSI_OPCODE_MASK);
4753 /* Set the task type */
4754 io_task->wrb_type = (is_chip_be2_be3r(phba)) ?
4755 AMAP_GET_BITS(struct amap_iscsi_wrb, type, pwrb) :
4756 AMAP_GET_BITS(struct amap_iscsi_wrb_v2, type, pwrb);
4758 doorbell |= cid & DB_WRB_POST_CID_MASK;
4759 doorbell |= (io_task->pwrb_handle->wrb_index &
4760 DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
4761 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
4762 iowrite32(doorbell, phba->db_va +
4763 beiscsi_conn->doorbell_offset);
4767 static int beiscsi_task_xmit(struct iscsi_task *task)
4769 struct beiscsi_io_task *io_task = task->dd_data;
4770 struct scsi_cmnd *sc = task->sc;
4771 struct beiscsi_hba *phba;
4772 struct scatterlist *sg;
4774 unsigned int writedir = 0, xferlen = 0;
4776 phba = io_task->conn->phba;
4778 * HBA in error includes BEISCSI_HBA_FW_TIMEOUT. IO path might be
4779 * operational if FW still gets heartbeat from EP FW. Is management
4780 * path really needed to continue further?
4782 if (!beiscsi_hba_is_online(phba))
4785 if (!io_task->conn->login_in_progress)
4786 task->hdr->exp_statsn = 0;
4789 return beiscsi_mtask(task);
4791 io_task->scsi_cmnd = sc;
4792 io_task->num_sg = 0;
4793 num_sg = scsi_dma_map(sc);
4795 beiscsi_log(phba, KERN_ERR,
4796 BEISCSI_LOG_IO | BEISCSI_LOG_ISCSI,
4797 "BM_%d : scsi_dma_map Failed "
4798 "Driver_ITT : 0x%x ITT : 0x%x Xferlen : 0x%x\n",
4799 be32_to_cpu(io_task->cmd_bhs->iscsi_hdr.itt),
4800 io_task->libiscsi_itt, scsi_bufflen(sc));
4805 * For scsi cmd task, check num_sg before unmapping in cleanup_task.
4806 * For management task, cleanup_task checks mtask_addr before unmapping.
4808 io_task->num_sg = num_sg;
4809 xferlen = scsi_bufflen(sc);
4810 sg = scsi_sglist(sc);
4811 if (sc->sc_data_direction == DMA_TO_DEVICE)
4816 return phba->iotask_fn(task, sg, num_sg, xferlen, writedir);
4820 * beiscsi_bsg_request - handle bsg request from ISCSI transport
4821 * @job: job to handle
4823 static int beiscsi_bsg_request(struct bsg_job *job)
4825 struct Scsi_Host *shost;
4826 struct beiscsi_hba *phba;
4827 struct iscsi_bsg_request *bsg_req = job->request;
4830 struct be_dma_mem nonemb_cmd;
4831 struct be_cmd_resp_hdr *resp;
4832 struct iscsi_bsg_reply *bsg_reply = job->reply;
4833 unsigned short status, extd_status;
4835 shost = iscsi_job_to_shost(job);
4836 phba = iscsi_host_priv(shost);
4838 if (!beiscsi_hba_is_online(phba)) {
4839 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
4840 "BM_%d : HBA in error 0x%lx\n", phba->state);
4844 switch (bsg_req->msgcode) {
4845 case ISCSI_BSG_HST_VENDOR:
4846 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
4847 job->request_payload.payload_len,
4849 if (nonemb_cmd.va == NULL) {
4850 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
4851 "BM_%d : Failed to allocate memory for "
4852 "beiscsi_bsg_request\n");
4855 tag = mgmt_vendor_specific_fw_cmd(&phba->ctrl, phba, job,
4858 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
4859 "BM_%d : MBX Tag Allocation Failed\n");
4861 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
4862 nonemb_cmd.va, nonemb_cmd.dma);
4866 rc = wait_event_interruptible_timeout(
4867 phba->ctrl.mcc_wait[tag],
4868 phba->ctrl.mcc_tag_status[tag],
4870 BEISCSI_HOST_MBX_TIMEOUT));
4872 if (!test_bit(BEISCSI_HBA_ONLINE, &phba->state)) {
4873 clear_bit(MCC_TAG_STATE_RUNNING,
4874 &phba->ctrl.ptag_state[tag].tag_state);
4875 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
4876 nonemb_cmd.va, nonemb_cmd.dma);
4879 extd_status = (phba->ctrl.mcc_tag_status[tag] &
4880 CQE_STATUS_ADDL_MASK) >> CQE_STATUS_ADDL_SHIFT;
4881 status = phba->ctrl.mcc_tag_status[tag] & CQE_STATUS_MASK;
4882 free_mcc_wrb(&phba->ctrl, tag);
4883 resp = (struct be_cmd_resp_hdr *)nonemb_cmd.va;
4884 sg_copy_from_buffer(job->reply_payload.sg_list,
4885 job->reply_payload.sg_cnt,
4886 nonemb_cmd.va, (resp->response_length
4888 bsg_reply->reply_payload_rcv_len = resp->response_length;
4889 bsg_reply->result = status;
4890 bsg_job_done(job, bsg_reply->result,
4891 bsg_reply->reply_payload_rcv_len);
4892 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
4893 nonemb_cmd.va, nonemb_cmd.dma);
4894 if (status || extd_status) {
4895 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
4896 "BM_%d : MBX Cmd Failed"
4897 " status = %d extd_status = %d\n",
4898 status, extd_status);
4907 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
4908 "BM_%d : Unsupported bsg command: 0x%x\n",
4916 static void beiscsi_hba_attrs_init(struct beiscsi_hba *phba)
4918 /* Set the logging parameter */
4919 beiscsi_log_enable_init(phba, beiscsi_log_enable);
4922 void beiscsi_start_boot_work(struct beiscsi_hba *phba, unsigned int s_handle)
4924 if (phba->boot_struct.boot_kset)
4927 /* skip if boot work is already in progress */
4928 if (test_and_set_bit(BEISCSI_HBA_BOOT_WORK, &phba->state))
4931 phba->boot_struct.retry = 3;
4932 phba->boot_struct.tag = 0;
4933 phba->boot_struct.s_handle = s_handle;
4934 phba->boot_struct.action = BEISCSI_BOOT_GET_SHANDLE;
4935 schedule_work(&phba->boot_work);
4939 * Boot flag info for iscsi-utilities
4940 * Bit 0 Block valid flag
4941 * Bit 1 Firmware booting selected
4943 #define BEISCSI_SYSFS_ISCSI_BOOT_FLAGS 3
4945 static ssize_t beiscsi_show_boot_tgt_info(void *data, int type, char *buf)
4947 struct beiscsi_hba *phba = data;
4948 struct mgmt_session_info *boot_sess = &phba->boot_struct.boot_sess;
4949 struct mgmt_conn_info *boot_conn = &boot_sess->conn_list[0];
4954 case ISCSI_BOOT_TGT_NAME:
4955 rc = sprintf(buf, "%.*s\n",
4956 (int)strlen(boot_sess->target_name),
4957 (char *)&boot_sess->target_name);
4959 case ISCSI_BOOT_TGT_IP_ADDR:
4960 if (boot_conn->dest_ipaddr.ip_type == BEISCSI_IP_TYPE_V4)
4961 rc = sprintf(buf, "%pI4\n",
4962 (char *)&boot_conn->dest_ipaddr.addr);
4964 rc = sprintf(str, "%pI6\n",
4965 (char *)&boot_conn->dest_ipaddr.addr);
4967 case ISCSI_BOOT_TGT_PORT:
4968 rc = sprintf(str, "%d\n", boot_conn->dest_port);
4971 case ISCSI_BOOT_TGT_CHAP_NAME:
4972 rc = sprintf(str, "%.*s\n",
4973 boot_conn->negotiated_login_options.auth_data.chap.
4974 target_chap_name_length,
4975 (char *)&boot_conn->negotiated_login_options.
4976 auth_data.chap.target_chap_name);
4978 case ISCSI_BOOT_TGT_CHAP_SECRET:
4979 rc = sprintf(str, "%.*s\n",
4980 boot_conn->negotiated_login_options.auth_data.chap.
4981 target_secret_length,
4982 (char *)&boot_conn->negotiated_login_options.
4983 auth_data.chap.target_secret);
4985 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
4986 rc = sprintf(str, "%.*s\n",
4987 boot_conn->negotiated_login_options.auth_data.chap.
4988 intr_chap_name_length,
4989 (char *)&boot_conn->negotiated_login_options.
4990 auth_data.chap.intr_chap_name);
4992 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
4993 rc = sprintf(str, "%.*s\n",
4994 boot_conn->negotiated_login_options.auth_data.chap.
4996 (char *)&boot_conn->negotiated_login_options.
4997 auth_data.chap.intr_secret);
4999 case ISCSI_BOOT_TGT_FLAGS:
5000 rc = sprintf(str, "%d\n", BEISCSI_SYSFS_ISCSI_BOOT_FLAGS);
5002 case ISCSI_BOOT_TGT_NIC_ASSOC:
5003 rc = sprintf(str, "0\n");
5009 static ssize_t beiscsi_show_boot_ini_info(void *data, int type, char *buf)
5011 struct beiscsi_hba *phba = data;
5016 case ISCSI_BOOT_INI_INITIATOR_NAME:
5017 rc = sprintf(str, "%s\n",
5018 phba->boot_struct.boot_sess.initiator_iscsiname);
5024 static ssize_t beiscsi_show_boot_eth_info(void *data, int type, char *buf)
5026 struct beiscsi_hba *phba = data;
5031 case ISCSI_BOOT_ETH_FLAGS:
5032 rc = sprintf(str, "%d\n", BEISCSI_SYSFS_ISCSI_BOOT_FLAGS);
5034 case ISCSI_BOOT_ETH_INDEX:
5035 rc = sprintf(str, "0\n");
5037 case ISCSI_BOOT_ETH_MAC:
5038 rc = beiscsi_get_macaddr(str, phba);
5044 static umode_t beiscsi_tgt_get_attr_visibility(void *data, int type)
5049 case ISCSI_BOOT_TGT_NAME:
5050 case ISCSI_BOOT_TGT_IP_ADDR:
5051 case ISCSI_BOOT_TGT_PORT:
5052 case ISCSI_BOOT_TGT_CHAP_NAME:
5053 case ISCSI_BOOT_TGT_CHAP_SECRET:
5054 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5055 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5056 case ISCSI_BOOT_TGT_NIC_ASSOC:
5057 case ISCSI_BOOT_TGT_FLAGS:
5064 static umode_t beiscsi_ini_get_attr_visibility(void *data, int type)
5069 case ISCSI_BOOT_INI_INITIATOR_NAME:
5076 static umode_t beiscsi_eth_get_attr_visibility(void *data, int type)
5081 case ISCSI_BOOT_ETH_FLAGS:
5082 case ISCSI_BOOT_ETH_MAC:
5083 case ISCSI_BOOT_ETH_INDEX:
5090 static void beiscsi_boot_kobj_release(void *data)
5092 struct beiscsi_hba *phba = data;
5094 scsi_host_put(phba->shost);
5097 static int beiscsi_boot_create_kset(struct beiscsi_hba *phba)
5099 struct boot_struct *bs = &phba->boot_struct;
5100 struct iscsi_boot_kobj *boot_kobj;
5102 if (bs->boot_kset) {
5103 __beiscsi_log(phba, KERN_ERR,
5104 "BM_%d: boot_kset already created\n");
5108 bs->boot_kset = iscsi_boot_create_host_kset(phba->shost->host_no);
5109 if (!bs->boot_kset) {
5110 __beiscsi_log(phba, KERN_ERR,
5111 "BM_%d: boot_kset alloc failed\n");
5115 /* get shost ref because the show function will refer phba */
5116 if (!scsi_host_get(phba->shost))
5119 boot_kobj = iscsi_boot_create_target(bs->boot_kset, 0, phba,
5120 beiscsi_show_boot_tgt_info,
5121 beiscsi_tgt_get_attr_visibility,
5122 beiscsi_boot_kobj_release);
5126 if (!scsi_host_get(phba->shost))
5129 boot_kobj = iscsi_boot_create_initiator(bs->boot_kset, 0, phba,
5130 beiscsi_show_boot_ini_info,
5131 beiscsi_ini_get_attr_visibility,
5132 beiscsi_boot_kobj_release);
5136 if (!scsi_host_get(phba->shost))
5139 boot_kobj = iscsi_boot_create_ethernet(bs->boot_kset, 0, phba,
5140 beiscsi_show_boot_eth_info,
5141 beiscsi_eth_get_attr_visibility,
5142 beiscsi_boot_kobj_release);
5149 scsi_host_put(phba->shost);
5151 iscsi_boot_destroy_kset(bs->boot_kset);
5152 bs->boot_kset = NULL;
5156 static void beiscsi_boot_work(struct work_struct *work)
5158 struct beiscsi_hba *phba =
5159 container_of(work, struct beiscsi_hba, boot_work);
5160 struct boot_struct *bs = &phba->boot_struct;
5161 unsigned int tag = 0;
5163 if (!beiscsi_hba_is_online(phba))
5166 beiscsi_log(phba, KERN_INFO,
5167 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
5168 "BM_%d : %s action %d\n",
5169 __func__, phba->boot_struct.action);
5171 switch (phba->boot_struct.action) {
5172 case BEISCSI_BOOT_REOPEN_SESS:
5173 tag = beiscsi_boot_reopen_sess(phba);
5175 case BEISCSI_BOOT_GET_SHANDLE:
5176 tag = __beiscsi_boot_get_shandle(phba, 1);
5178 case BEISCSI_BOOT_GET_SINFO:
5179 tag = beiscsi_boot_get_sinfo(phba);
5181 case BEISCSI_BOOT_LOGOUT_SESS:
5182 tag = beiscsi_boot_logout_sess(phba);
5184 case BEISCSI_BOOT_CREATE_KSET:
5185 beiscsi_boot_create_kset(phba);
5187 * updated boot_kset is made visible to all before
5188 * ending the boot work.
5191 clear_bit(BEISCSI_HBA_BOOT_WORK, &phba->state);
5196 schedule_work(&phba->boot_work);
5198 clear_bit(BEISCSI_HBA_BOOT_WORK, &phba->state);
5202 static void beiscsi_eqd_update_work(struct work_struct *work)
5204 struct hwi_context_memory *phwi_context;
5205 struct be_set_eqd set_eqd[MAX_CPUS];
5206 struct hwi_controller *phwi_ctrlr;
5207 struct be_eq_obj *pbe_eq;
5208 struct beiscsi_hba *phba;
5209 unsigned int pps, delta;
5210 struct be_aic_obj *aic;
5211 int eqd, i, num = 0;
5214 phba = container_of(work, struct beiscsi_hba, eqd_update.work);
5215 if (!beiscsi_hba_is_online(phba))
5218 phwi_ctrlr = phba->phwi_ctrlr;
5219 phwi_context = phwi_ctrlr->phwi_ctxt;
5221 for (i = 0; i <= phba->num_cpus; i++) {
5222 aic = &phba->aic_obj[i];
5223 pbe_eq = &phwi_context->be_eq[i];
5225 if (!aic->jiffies || time_before(now, aic->jiffies) ||
5226 pbe_eq->cq_count < aic->eq_prev) {
5228 aic->eq_prev = pbe_eq->cq_count;
5231 delta = jiffies_to_msecs(now - aic->jiffies);
5232 pps = (((u32)(pbe_eq->cq_count - aic->eq_prev) * 1000) / delta);
5233 eqd = (pps / 1500) << 2;
5237 eqd = min_t(u32, eqd, phwi_context->max_eqd);
5238 eqd = max_t(u32, eqd, phwi_context->min_eqd);
5241 aic->eq_prev = pbe_eq->cq_count;
5243 if (eqd != aic->prev_eqd) {
5244 set_eqd[num].delay_multiplier = (eqd * 65)/100;
5245 set_eqd[num].eq_id = pbe_eq->q.id;
5246 aic->prev_eqd = eqd;
5251 /* completion of this is ignored */
5252 beiscsi_modify_eq_delay(phba, set_eqd, num);
5254 schedule_delayed_work(&phba->eqd_update,
5255 msecs_to_jiffies(BEISCSI_EQD_UPDATE_INTERVAL));
5258 static void beiscsi_hw_tpe_check(unsigned long ptr)
5260 struct beiscsi_hba *phba;
5263 phba = (struct beiscsi_hba *)ptr;
5264 /* if not TPE, do nothing */
5265 if (!beiscsi_detect_tpe(phba))
5268 /* wait default 4000ms before recovering */
5270 if (phba->ue2rp > BEISCSI_UE_DETECT_INTERVAL)
5271 wait = phba->ue2rp - BEISCSI_UE_DETECT_INTERVAL;
5272 queue_delayed_work(phba->wq, &phba->recover_port,
5273 msecs_to_jiffies(wait));
5276 static void beiscsi_hw_health_check(unsigned long ptr)
5278 struct beiscsi_hba *phba;
5280 phba = (struct beiscsi_hba *)ptr;
5281 beiscsi_detect_ue(phba);
5282 if (beiscsi_detect_ue(phba)) {
5283 __beiscsi_log(phba, KERN_ERR,
5284 "BM_%d : port in error: %lx\n", phba->state);
5285 /* sessions are no longer valid, so first fail the sessions */
5286 queue_work(phba->wq, &phba->sess_work);
5288 /* detect UER supported */
5289 if (!test_bit(BEISCSI_HBA_UER_SUPP, &phba->state))
5291 /* modify this timer to check TPE */
5292 phba->hw_check.function = beiscsi_hw_tpe_check;
5295 mod_timer(&phba->hw_check,
5296 jiffies + msecs_to_jiffies(BEISCSI_UE_DETECT_INTERVAL));
5300 * beiscsi_enable_port()- Enables the disabled port.
5301 * Only port resources freed in disable function are reallocated.
5302 * This is called in HBA error handling path.
5304 * @phba: Instance of driver private structure
5307 static int beiscsi_enable_port(struct beiscsi_hba *phba)
5309 struct hwi_context_memory *phwi_context;
5310 struct hwi_controller *phwi_ctrlr;
5311 struct be_eq_obj *pbe_eq;
5314 if (test_bit(BEISCSI_HBA_ONLINE, &phba->state)) {
5315 __beiscsi_log(phba, KERN_ERR,
5316 "BM_%d : %s : port is online %lx\n",
5317 __func__, phba->state);
5321 ret = beiscsi_init_sliport(phba);
5325 be2iscsi_enable_msix(phba);
5327 beiscsi_get_params(phba);
5328 /* Re-enable UER. If different TPE occurs then it is recoverable. */
5329 beiscsi_set_uer_feature(phba);
5331 phba->shost->max_id = phba->params.cxns_per_ctrl;
5332 phba->shost->can_queue = phba->params.ios_per_ctrl;
5333 ret = beiscsi_init_port(phba);
5335 __beiscsi_log(phba, KERN_ERR,
5336 "BM_%d : init port failed\n");
5340 for (i = 0; i < MAX_MCC_CMD; i++) {
5341 init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]);
5342 phba->ctrl.mcc_tag[i] = i + 1;
5343 phba->ctrl.mcc_tag_status[i + 1] = 0;
5344 phba->ctrl.mcc_tag_available++;
5347 phwi_ctrlr = phba->phwi_ctrlr;
5348 phwi_context = phwi_ctrlr->phwi_ctxt;
5349 for (i = 0; i < phba->num_cpus; i++) {
5350 pbe_eq = &phwi_context->be_eq[i];
5351 irq_poll_init(&pbe_eq->iopoll, be_iopoll_budget, be_iopoll);
5354 i = (phba->pcidev->msix_enabled) ? i : 0;
5355 /* Work item for MCC handling */
5356 pbe_eq = &phwi_context->be_eq[i];
5357 INIT_WORK(&pbe_eq->mcc_work, beiscsi_mcc_work);
5359 ret = beiscsi_init_irqs(phba);
5361 __beiscsi_log(phba, KERN_ERR,
5362 "BM_%d : setup IRQs failed %d\n", ret);
5365 hwi_enable_intr(phba);
5366 /* port operational: clear all error bits */
5367 set_bit(BEISCSI_HBA_ONLINE, &phba->state);
5368 __beiscsi_log(phba, KERN_INFO,
5369 "BM_%d : port online: 0x%lx\n", phba->state);
5371 /* start hw_check timer and eqd_update work */
5372 schedule_delayed_work(&phba->eqd_update,
5373 msecs_to_jiffies(BEISCSI_EQD_UPDATE_INTERVAL));
5376 * Timer function gets modified for TPE detection.
5377 * Always reinit to do health check first.
5379 phba->hw_check.function = beiscsi_hw_health_check;
5380 mod_timer(&phba->hw_check,
5381 jiffies + msecs_to_jiffies(BEISCSI_UE_DETECT_INTERVAL));
5385 for (i = 0; i < phba->num_cpus; i++) {
5386 pbe_eq = &phwi_context->be_eq[i];
5387 irq_poll_disable(&pbe_eq->iopoll);
5389 hwi_cleanup_port(phba);
5392 pci_free_irq_vectors(phba->pcidev);
5397 * beiscsi_disable_port()- Disable port and cleanup driver resources.
5398 * This is called in HBA error handling and driver removal.
5399 * @phba: Instance Priv structure
5400 * @unload: indicate driver is unloading
5402 * Free the OS and HW resources held by the driver
5404 static void beiscsi_disable_port(struct beiscsi_hba *phba, int unload)
5406 struct hwi_context_memory *phwi_context;
5407 struct hwi_controller *phwi_ctrlr;
5408 struct be_eq_obj *pbe_eq;
5411 if (!test_and_clear_bit(BEISCSI_HBA_ONLINE, &phba->state))
5414 phwi_ctrlr = phba->phwi_ctrlr;
5415 phwi_context = phwi_ctrlr->phwi_ctxt;
5416 hwi_disable_intr(phba);
5417 beiscsi_free_irqs(phba);
5418 pci_free_irq_vectors(phba->pcidev);
5420 for (i = 0; i < phba->num_cpus; i++) {
5421 pbe_eq = &phwi_context->be_eq[i];
5422 irq_poll_disable(&pbe_eq->iopoll);
5424 cancel_delayed_work_sync(&phba->eqd_update);
5425 cancel_work_sync(&phba->boot_work);
5426 /* WQ might be running cancel queued mcc_work if we are not exiting */
5427 if (!unload && beiscsi_hba_in_error(phba)) {
5428 pbe_eq = &phwi_context->be_eq[i];
5429 cancel_work_sync(&pbe_eq->mcc_work);
5431 hwi_cleanup_port(phba);
5432 beiscsi_cleanup_port(phba);
5435 static void beiscsi_sess_work(struct work_struct *work)
5437 struct beiscsi_hba *phba;
5439 phba = container_of(work, struct beiscsi_hba, sess_work);
5441 * This work gets scheduled only in case of HBA error.
5442 * Old sessions are gone so need to be re-established.
5443 * iscsi_session_failure needs process context hence this work.
5445 iscsi_host_for_each_session(phba->shost, beiscsi_session_fail);
5448 static void beiscsi_recover_port(struct work_struct *work)
5450 struct beiscsi_hba *phba;
5452 phba = container_of(work, struct beiscsi_hba, recover_port.work);
5453 beiscsi_disable_port(phba, 0);
5454 beiscsi_enable_port(phba);
5457 static pci_ers_result_t beiscsi_eeh_err_detected(struct pci_dev *pdev,
5458 pci_channel_state_t state)
5460 struct beiscsi_hba *phba = NULL;
5462 phba = (struct beiscsi_hba *)pci_get_drvdata(pdev);
5463 set_bit(BEISCSI_HBA_PCI_ERR, &phba->state);
5465 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5466 "BM_%d : EEH error detected\n");
5468 /* first stop UE detection when PCI error detected */
5469 del_timer_sync(&phba->hw_check);
5470 cancel_delayed_work_sync(&phba->recover_port);
5472 /* sessions are no longer valid, so first fail the sessions */
5473 iscsi_host_for_each_session(phba->shost, beiscsi_session_fail);
5474 beiscsi_disable_port(phba, 0);
5476 if (state == pci_channel_io_perm_failure) {
5477 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5478 "BM_%d : EEH : State PERM Failure");
5479 return PCI_ERS_RESULT_DISCONNECT;
5482 pci_disable_device(pdev);
5484 /* The error could cause the FW to trigger a flash debug dump.
5485 * Resetting the card while flash dump is in progress
5486 * can cause it not to recover; wait for it to finish.
5487 * Wait only for first function as it is needed only once per
5490 if (pdev->devfn == 0)
5493 return PCI_ERS_RESULT_NEED_RESET;
5496 static pci_ers_result_t beiscsi_eeh_reset(struct pci_dev *pdev)
5498 struct beiscsi_hba *phba = NULL;
5501 phba = (struct beiscsi_hba *)pci_get_drvdata(pdev);
5503 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5504 "BM_%d : EEH Reset\n");
5506 status = pci_enable_device(pdev);
5508 return PCI_ERS_RESULT_DISCONNECT;
5510 pci_set_master(pdev);
5511 pci_set_power_state(pdev, PCI_D0);
5512 pci_restore_state(pdev);
5514 status = beiscsi_check_fw_rdy(phba);
5516 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
5517 "BM_%d : EEH Reset Completed\n");
5519 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
5520 "BM_%d : EEH Reset Completion Failure\n");
5521 return PCI_ERS_RESULT_DISCONNECT;
5524 pci_cleanup_aer_uncorrect_error_status(pdev);
5525 return PCI_ERS_RESULT_RECOVERED;
5528 static void beiscsi_eeh_resume(struct pci_dev *pdev)
5530 struct beiscsi_hba *phba;
5533 phba = (struct beiscsi_hba *)pci_get_drvdata(pdev);
5534 pci_save_state(pdev);
5536 ret = beiscsi_enable_port(phba);
5538 __beiscsi_log(phba, KERN_ERR,
5539 "BM_%d : AER EEH resume failed\n");
5542 static int beiscsi_dev_probe(struct pci_dev *pcidev,
5543 const struct pci_device_id *id)
5545 struct hwi_context_memory *phwi_context;
5546 struct hwi_controller *phwi_ctrlr;
5547 struct beiscsi_hba *phba = NULL;
5548 struct be_eq_obj *pbe_eq;
5549 unsigned int s_handle;
5553 ret = beiscsi_enable_pci(pcidev);
5555 dev_err(&pcidev->dev,
5556 "beiscsi_dev_probe - Failed to enable pci device\n");
5560 phba = beiscsi_hba_alloc(pcidev);
5562 dev_err(&pcidev->dev,
5563 "beiscsi_dev_probe - Failed in beiscsi_hba_alloc\n");
5568 /* Enable EEH reporting */
5569 ret = pci_enable_pcie_error_reporting(pcidev);
5571 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
5572 "BM_%d : PCIe Error Reporting "
5573 "Enabling Failed\n");
5575 pci_save_state(pcidev);
5577 /* Initialize Driver configuration Paramters */
5578 beiscsi_hba_attrs_init(phba);
5580 phba->mac_addr_set = false;
5582 switch (pcidev->device) {
5586 phba->generation = BE_GEN2;
5587 phba->iotask_fn = beiscsi_iotask;
5588 dev_warn(&pcidev->dev,
5589 "Obsolete/Unsupported BE2 Adapter Family\n");
5593 phba->generation = BE_GEN3;
5594 phba->iotask_fn = beiscsi_iotask;
5597 phba->generation = BE_GEN4;
5598 phba->iotask_fn = beiscsi_iotask_v2;
5601 phba->generation = 0;
5604 ret = be_ctrl_init(phba, pcidev);
5606 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5607 "BM_%d : be_ctrl_init failed\n");
5611 ret = beiscsi_init_sliport(phba);
5615 spin_lock_init(&phba->io_sgl_lock);
5616 spin_lock_init(&phba->mgmt_sgl_lock);
5617 spin_lock_init(&phba->async_pdu_lock);
5618 ret = beiscsi_get_fw_config(&phba->ctrl, phba);
5620 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5621 "BM_%d : Error getting fw config\n");
5624 beiscsi_get_port_name(&phba->ctrl, phba);
5625 beiscsi_get_params(phba);
5626 beiscsi_set_uer_feature(phba);
5628 be2iscsi_enable_msix(phba);
5630 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
5631 "BM_%d : num_cpus = %d\n",
5634 phba->shost->max_id = phba->params.cxns_per_ctrl;
5635 phba->shost->can_queue = phba->params.ios_per_ctrl;
5636 ret = beiscsi_get_memory(phba);
5638 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5639 "BM_%d : alloc host mem failed\n");
5643 ret = beiscsi_init_port(phba);
5645 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5646 "BM_%d : init port failed\n");
5647 beiscsi_free_mem(phba);
5651 for (i = 0; i < MAX_MCC_CMD; i++) {
5652 init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]);
5653 phba->ctrl.mcc_tag[i] = i + 1;
5654 phba->ctrl.mcc_tag_status[i + 1] = 0;
5655 phba->ctrl.mcc_tag_available++;
5656 memset(&phba->ctrl.ptag_state[i].tag_mem_state, 0,
5657 sizeof(struct be_dma_mem));
5660 phba->ctrl.mcc_alloc_index = phba->ctrl.mcc_free_index = 0;
5662 snprintf(wq_name, sizeof(wq_name), "beiscsi_%02x_wq",
5663 phba->shost->host_no);
5664 phba->wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 1, wq_name);
5666 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5667 "BM_%d : beiscsi_dev_probe-"
5668 "Failed to allocate work queue\n");
5673 INIT_DELAYED_WORK(&phba->eqd_update, beiscsi_eqd_update_work);
5675 phwi_ctrlr = phba->phwi_ctrlr;
5676 phwi_context = phwi_ctrlr->phwi_ctxt;
5678 for (i = 0; i < phba->num_cpus; i++) {
5679 pbe_eq = &phwi_context->be_eq[i];
5680 irq_poll_init(&pbe_eq->iopoll, be_iopoll_budget, be_iopoll);
5683 i = (phba->pcidev->msix_enabled) ? i : 0;
5684 /* Work item for MCC handling */
5685 pbe_eq = &phwi_context->be_eq[i];
5686 INIT_WORK(&pbe_eq->mcc_work, beiscsi_mcc_work);
5688 ret = beiscsi_init_irqs(phba);
5690 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5691 "BM_%d : beiscsi_dev_probe-"
5692 "Failed to beiscsi_init_irqs\n");
5693 goto disable_iopoll;
5695 hwi_enable_intr(phba);
5697 ret = iscsi_host_add(phba->shost, &phba->pcidev->dev);
5701 /* set online bit after port is operational */
5702 set_bit(BEISCSI_HBA_ONLINE, &phba->state);
5703 __beiscsi_log(phba, KERN_INFO,
5704 "BM_%d : port online: 0x%lx\n", phba->state);
5706 INIT_WORK(&phba->boot_work, beiscsi_boot_work);
5707 ret = beiscsi_boot_get_shandle(phba, &s_handle);
5709 beiscsi_start_boot_work(phba, s_handle);
5711 * Set this bit after starting the work to let
5712 * probe handle it first.
5713 * ASYNC event can too schedule this work.
5715 set_bit(BEISCSI_HBA_BOOT_FOUND, &phba->state);
5718 beiscsi_iface_create_default(phba);
5719 schedule_delayed_work(&phba->eqd_update,
5720 msecs_to_jiffies(BEISCSI_EQD_UPDATE_INTERVAL));
5722 INIT_WORK(&phba->sess_work, beiscsi_sess_work);
5723 INIT_DELAYED_WORK(&phba->recover_port, beiscsi_recover_port);
5725 * Start UE detection here. UE before this will cause stall in probe
5726 * and eventually fail the probe.
5728 init_timer(&phba->hw_check);
5729 phba->hw_check.function = beiscsi_hw_health_check;
5730 phba->hw_check.data = (unsigned long)phba;
5731 mod_timer(&phba->hw_check,
5732 jiffies + msecs_to_jiffies(BEISCSI_UE_DETECT_INTERVAL));
5733 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
5734 "\n\n\n BM_%d : SUCCESS - DRIVER LOADED\n\n\n");
5738 hwi_disable_intr(phba);
5739 beiscsi_free_irqs(phba);
5741 for (i = 0; i < phba->num_cpus; i++) {
5742 pbe_eq = &phwi_context->be_eq[i];
5743 irq_poll_disable(&pbe_eq->iopoll);
5745 destroy_workqueue(phba->wq);
5747 hwi_cleanup_port(phba);
5748 beiscsi_cleanup_port(phba);
5749 beiscsi_free_mem(phba);
5751 pci_free_consistent(phba->pcidev,
5752 phba->ctrl.mbox_mem_alloced.size,
5753 phba->ctrl.mbox_mem_alloced.va,
5754 phba->ctrl.mbox_mem_alloced.dma);
5755 beiscsi_unmap_pci_function(phba);
5757 pci_disable_msix(phba->pcidev);
5758 pci_dev_put(phba->pcidev);
5759 iscsi_host_free(phba->shost);
5760 pci_set_drvdata(pcidev, NULL);
5762 pci_release_regions(pcidev);
5763 pci_disable_device(pcidev);
5767 static void beiscsi_remove(struct pci_dev *pcidev)
5769 struct beiscsi_hba *phba = NULL;
5771 phba = pci_get_drvdata(pcidev);
5773 dev_err(&pcidev->dev, "beiscsi_remove called with no phba\n");
5777 /* first stop UE detection before unloading */
5778 del_timer_sync(&phba->hw_check);
5779 cancel_delayed_work_sync(&phba->recover_port);
5780 cancel_work_sync(&phba->sess_work);
5782 beiscsi_iface_destroy_default(phba);
5783 iscsi_host_remove(phba->shost);
5784 beiscsi_disable_port(phba, 1);
5786 /* after cancelling boot_work */
5787 iscsi_boot_destroy_kset(phba->boot_struct.boot_kset);
5789 /* free all resources */
5790 destroy_workqueue(phba->wq);
5791 beiscsi_free_mem(phba);
5794 beiscsi_unmap_pci_function(phba);
5795 pci_free_consistent(phba->pcidev,
5796 phba->ctrl.mbox_mem_alloced.size,
5797 phba->ctrl.mbox_mem_alloced.va,
5798 phba->ctrl.mbox_mem_alloced.dma);
5800 pci_dev_put(phba->pcidev);
5801 iscsi_host_free(phba->shost);
5802 pci_disable_pcie_error_reporting(pcidev);
5803 pci_set_drvdata(pcidev, NULL);
5804 pci_release_regions(pcidev);
5805 pci_disable_device(pcidev);
5809 static struct pci_error_handlers beiscsi_eeh_handlers = {
5810 .error_detected = beiscsi_eeh_err_detected,
5811 .slot_reset = beiscsi_eeh_reset,
5812 .resume = beiscsi_eeh_resume,
5815 struct iscsi_transport beiscsi_iscsi_transport = {
5816 .owner = THIS_MODULE,
5818 .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_TEXT_NEGO |
5819 CAP_MULTI_R2T | CAP_DATADGST | CAP_DATA_PATH_OFFLOAD,
5820 .create_session = beiscsi_session_create,
5821 .destroy_session = beiscsi_session_destroy,
5822 .create_conn = beiscsi_conn_create,
5823 .bind_conn = beiscsi_conn_bind,
5824 .destroy_conn = iscsi_conn_teardown,
5825 .attr_is_visible = beiscsi_attr_is_visible,
5826 .set_iface_param = beiscsi_iface_set_param,
5827 .get_iface_param = beiscsi_iface_get_param,
5828 .set_param = beiscsi_set_param,
5829 .get_conn_param = iscsi_conn_get_param,
5830 .get_session_param = iscsi_session_get_param,
5831 .get_host_param = beiscsi_get_host_param,
5832 .start_conn = beiscsi_conn_start,
5833 .stop_conn = iscsi_conn_stop,
5834 .send_pdu = iscsi_conn_send_pdu,
5835 .xmit_task = beiscsi_task_xmit,
5836 .cleanup_task = beiscsi_cleanup_task,
5837 .alloc_pdu = beiscsi_alloc_pdu,
5838 .parse_pdu_itt = beiscsi_parse_pdu,
5839 .get_stats = beiscsi_conn_get_stats,
5840 .get_ep_param = beiscsi_ep_get_param,
5841 .ep_connect = beiscsi_ep_connect,
5842 .ep_poll = beiscsi_ep_poll,
5843 .ep_disconnect = beiscsi_ep_disconnect,
5844 .session_recovery_timedout = iscsi_session_recovery_timedout,
5845 .bsg_request = beiscsi_bsg_request,
5848 static struct pci_driver beiscsi_pci_driver = {
5850 .probe = beiscsi_dev_probe,
5851 .remove = beiscsi_remove,
5852 .id_table = beiscsi_pci_id_table,
5853 .err_handler = &beiscsi_eeh_handlers
5856 static int __init beiscsi_module_init(void)
5860 beiscsi_scsi_transport =
5861 iscsi_register_transport(&beiscsi_iscsi_transport);
5862 if (!beiscsi_scsi_transport) {
5864 "beiscsi_module_init - Unable to register beiscsi transport.\n");
5867 printk(KERN_INFO "In beiscsi_module_init, tt=%p\n",
5868 &beiscsi_iscsi_transport);
5870 ret = pci_register_driver(&beiscsi_pci_driver);
5873 "beiscsi_module_init - Unable to register beiscsi pci driver.\n");
5874 goto unregister_iscsi_transport;
5878 unregister_iscsi_transport:
5879 iscsi_unregister_transport(&beiscsi_iscsi_transport);
5883 static void __exit beiscsi_module_exit(void)
5885 pci_unregister_driver(&beiscsi_pci_driver);
5886 iscsi_unregister_transport(&beiscsi_iscsi_transport);
5889 module_init(beiscsi_module_init);
5890 module_exit(beiscsi_module_exit);