2 * Copyright (C) 2005 - 2015 Emulex
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation. The full GNU General
8 * Public License is included in this distribution in the file called COPYING.
10 * Written by: Jayamohan Kallickal (jayamohan.kallickal@avagotech.com)
12 * Contact Information:
13 * linux-drivers@avagotech.com
17 * Costa Mesa, CA 92626
20 #include <linux/reboot.h>
21 #include <linux/delay.h>
22 #include <linux/slab.h>
23 #include <linux/interrupt.h>
24 #include <linux/blkdev.h>
25 #include <linux/pci.h>
26 #include <linux/string.h>
27 #include <linux/kernel.h>
28 #include <linux/semaphore.h>
29 #include <linux/iscsi_boot_sysfs.h>
30 #include <linux/module.h>
31 #include <linux/bsg-lib.h>
32 #include <linux/irq_poll.h>
34 #include <scsi/libiscsi.h>
35 #include <scsi/scsi_bsg_iscsi.h>
36 #include <scsi/scsi_netlink.h>
37 #include <scsi/scsi_transport_iscsi.h>
38 #include <scsi/scsi_transport.h>
39 #include <scsi/scsi_cmnd.h>
40 #include <scsi/scsi_device.h>
41 #include <scsi/scsi_host.h>
42 #include <scsi/scsi.h>
48 static unsigned int be_iopoll_budget = 10;
49 static unsigned int be_max_phys_size = 64;
50 static unsigned int enable_msix = 1;
52 MODULE_DESCRIPTION(DRV_DESC " " BUILD_STR);
53 MODULE_VERSION(BUILD_STR);
54 MODULE_AUTHOR("Emulex Corporation");
55 MODULE_LICENSE("GPL");
56 module_param(be_iopoll_budget, int, 0);
57 module_param(enable_msix, int, 0);
58 module_param(be_max_phys_size, uint, S_IRUGO);
59 MODULE_PARM_DESC(be_max_phys_size,
60 "Maximum Size (In Kilobytes) of physically contiguous "
61 "memory that can be allocated. Range is 16 - 128");
63 #define beiscsi_disp_param(_name)\
65 beiscsi_##_name##_disp(struct device *dev,\
66 struct device_attribute *attrib, char *buf) \
68 struct Scsi_Host *shost = class_to_shost(dev);\
69 struct beiscsi_hba *phba = iscsi_host_priv(shost); \
70 uint32_t param_val = 0; \
71 param_val = phba->attr_##_name;\
72 return snprintf(buf, PAGE_SIZE, "%d\n",\
76 #define beiscsi_change_param(_name, _minval, _maxval, _defaval)\
78 beiscsi_##_name##_change(struct beiscsi_hba *phba, uint32_t val)\
80 if (val >= _minval && val <= _maxval) {\
81 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,\
82 "BA_%d : beiscsi_"#_name" updated "\
83 "from 0x%x ==> 0x%x\n",\
84 phba->attr_##_name, val); \
85 phba->attr_##_name = val;\
88 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, \
89 "BA_%d beiscsi_"#_name" attribute "\
90 "cannot be updated to 0x%x, "\
91 "range allowed is ["#_minval" - "#_maxval"]\n", val);\
95 #define beiscsi_store_param(_name) \
97 beiscsi_##_name##_store(struct device *dev,\
98 struct device_attribute *attr, const char *buf,\
101 struct Scsi_Host *shost = class_to_shost(dev);\
102 struct beiscsi_hba *phba = iscsi_host_priv(shost);\
103 uint32_t param_val = 0;\
104 if (!isdigit(buf[0]))\
106 if (sscanf(buf, "%i", ¶m_val) != 1)\
108 if (beiscsi_##_name##_change(phba, param_val) == 0) \
114 #define beiscsi_init_param(_name, _minval, _maxval, _defval) \
116 beiscsi_##_name##_init(struct beiscsi_hba *phba, uint32_t val) \
118 if (val >= _minval && val <= _maxval) {\
119 phba->attr_##_name = val;\
122 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,\
123 "BA_%d beiscsi_"#_name" attribute " \
124 "cannot be updated to 0x%x, "\
125 "range allowed is ["#_minval" - "#_maxval"]\n", val);\
126 phba->attr_##_name = _defval;\
130 #define BEISCSI_RW_ATTR(_name, _minval, _maxval, _defval, _descp) \
131 static uint beiscsi_##_name = _defval;\
132 module_param(beiscsi_##_name, uint, S_IRUGO);\
133 MODULE_PARM_DESC(beiscsi_##_name, _descp);\
134 beiscsi_disp_param(_name)\
135 beiscsi_change_param(_name, _minval, _maxval, _defval)\
136 beiscsi_store_param(_name)\
137 beiscsi_init_param(_name, _minval, _maxval, _defval)\
138 DEVICE_ATTR(beiscsi_##_name, S_IRUGO | S_IWUSR,\
139 beiscsi_##_name##_disp, beiscsi_##_name##_store)
142 * When new log level added update the
143 * the MAX allowed value for log_enable
145 BEISCSI_RW_ATTR(log_enable, 0x00,
146 0xFF, 0x00, "Enable logging Bit Mask\n"
147 "\t\t\t\tInitialization Events : 0x01\n"
148 "\t\t\t\tMailbox Events : 0x02\n"
149 "\t\t\t\tMiscellaneous Events : 0x04\n"
150 "\t\t\t\tError Handling : 0x08\n"
151 "\t\t\t\tIO Path Events : 0x10\n"
152 "\t\t\t\tConfiguration Path : 0x20\n"
153 "\t\t\t\tiSCSI Protocol : 0x40\n");
155 DEVICE_ATTR(beiscsi_drvr_ver, S_IRUGO, beiscsi_drvr_ver_disp, NULL);
156 DEVICE_ATTR(beiscsi_adapter_family, S_IRUGO, beiscsi_adap_family_disp, NULL);
157 DEVICE_ATTR(beiscsi_fw_ver, S_IRUGO, beiscsi_fw_ver_disp, NULL);
158 DEVICE_ATTR(beiscsi_phys_port, S_IRUGO, beiscsi_phys_port_disp, NULL);
159 DEVICE_ATTR(beiscsi_active_session_count, S_IRUGO,
160 beiscsi_active_session_disp, NULL);
161 DEVICE_ATTR(beiscsi_free_session_count, S_IRUGO,
162 beiscsi_free_session_disp, NULL);
163 struct device_attribute *beiscsi_attrs[] = {
164 &dev_attr_beiscsi_log_enable,
165 &dev_attr_beiscsi_drvr_ver,
166 &dev_attr_beiscsi_adapter_family,
167 &dev_attr_beiscsi_fw_ver,
168 &dev_attr_beiscsi_active_session_count,
169 &dev_attr_beiscsi_free_session_count,
170 &dev_attr_beiscsi_phys_port,
174 static char const *cqe_desc[] = {
177 "SOL_CMD_KILLED_DATA_DIGEST_ERR",
178 "CXN_KILLED_PDU_SIZE_EXCEEDS_DSL",
179 "CXN_KILLED_BURST_LEN_MISMATCH",
180 "CXN_KILLED_AHS_RCVD",
181 "CXN_KILLED_HDR_DIGEST_ERR",
182 "CXN_KILLED_UNKNOWN_HDR",
183 "CXN_KILLED_STALE_ITT_TTT_RCVD",
184 "CXN_KILLED_INVALID_ITT_TTT_RCVD",
185 "CXN_KILLED_RST_RCVD",
186 "CXN_KILLED_TIMED_OUT",
187 "CXN_KILLED_RST_SENT",
188 "CXN_KILLED_FIN_RCVD",
189 "CXN_KILLED_BAD_UNSOL_PDU_RCVD",
190 "CXN_KILLED_BAD_WRB_INDEX_ERROR",
191 "CXN_KILLED_OVER_RUN_RESIDUAL",
192 "CXN_KILLED_UNDER_RUN_RESIDUAL",
193 "CMD_KILLED_INVALID_STATSN_RCVD",
194 "CMD_KILLED_INVALID_R2T_RCVD",
195 "CMD_CXN_KILLED_LUN_INVALID",
196 "CMD_CXN_KILLED_ICD_INVALID",
197 "CMD_CXN_KILLED_ITT_INVALID",
198 "CMD_CXN_KILLED_SEQ_OUTOFORDER",
199 "CMD_CXN_KILLED_INVALID_DATASN_RCVD",
200 "CXN_INVALIDATE_NOTIFY",
201 "CXN_INVALIDATE_INDEX_NOTIFY",
202 "CMD_INVALIDATED_NOTIFY",
205 "UNSOL_DATA_DIGEST_ERROR_NOTIFY",
207 "CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN",
208 "SOL_CMD_KILLED_DIF_ERR",
209 "CXN_KILLED_SYN_RCVD",
210 "CXN_KILLED_IMM_DATA_RCVD"
213 static int beiscsi_slave_configure(struct scsi_device *sdev)
215 blk_queue_max_segment_size(sdev->request_queue, 65536);
219 static int beiscsi_eh_abort(struct scsi_cmnd *sc)
221 struct iscsi_cls_session *cls_session;
222 struct iscsi_task *aborted_task = (struct iscsi_task *)sc->SCp.ptr;
223 struct beiscsi_io_task *aborted_io_task;
224 struct iscsi_conn *conn;
225 struct beiscsi_conn *beiscsi_conn;
226 struct beiscsi_hba *phba;
227 struct iscsi_session *session;
228 struct invalidate_command_table *inv_tbl;
229 struct be_dma_mem nonemb_cmd;
230 unsigned int cid, tag, num_invalidate;
233 cls_session = starget_to_session(scsi_target(sc->device));
234 session = cls_session->dd_data;
236 spin_lock_bh(&session->frwd_lock);
237 if (!aborted_task || !aborted_task->sc) {
239 spin_unlock_bh(&session->frwd_lock);
243 aborted_io_task = aborted_task->dd_data;
244 if (!aborted_io_task->scsi_cmnd) {
245 /* raced or invalid command */
246 spin_unlock_bh(&session->frwd_lock);
249 spin_unlock_bh(&session->frwd_lock);
250 /* Invalidate WRB Posted for this Task */
251 AMAP_SET_BITS(struct amap_iscsi_wrb, invld,
252 aborted_io_task->pwrb_handle->pwrb,
255 conn = aborted_task->conn;
256 beiscsi_conn = conn->dd_data;
257 phba = beiscsi_conn->phba;
259 /* invalidate iocb */
260 cid = beiscsi_conn->beiscsi_conn_cid;
261 inv_tbl = phba->inv_tbl;
262 memset(inv_tbl, 0x0, sizeof(*inv_tbl));
264 inv_tbl->icd = aborted_io_task->psgl_handle->sgl_index;
266 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
267 sizeof(struct invalidate_commands_params_in),
269 if (nonemb_cmd.va == NULL) {
270 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
271 "BM_%d : Failed to allocate memory for"
272 "mgmt_invalidate_icds\n");
275 nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
277 tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
280 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH,
281 "BM_%d : mgmt_invalidate_icds could not be"
283 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
284 nonemb_cmd.va, nonemb_cmd.dma);
289 rc = beiscsi_mccq_compl_wait(phba, tag, NULL, &nonemb_cmd);
291 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
292 nonemb_cmd.va, nonemb_cmd.dma);
294 return iscsi_eh_abort(sc);
297 static int beiscsi_eh_device_reset(struct scsi_cmnd *sc)
299 struct iscsi_task *abrt_task;
300 struct beiscsi_io_task *abrt_io_task;
301 struct iscsi_conn *conn;
302 struct beiscsi_conn *beiscsi_conn;
303 struct beiscsi_hba *phba;
304 struct iscsi_session *session;
305 struct iscsi_cls_session *cls_session;
306 struct invalidate_command_table *inv_tbl;
307 struct be_dma_mem nonemb_cmd;
308 unsigned int cid, tag, i, num_invalidate;
311 /* invalidate iocbs */
312 cls_session = starget_to_session(scsi_target(sc->device));
313 session = cls_session->dd_data;
314 spin_lock_bh(&session->frwd_lock);
315 if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN) {
316 spin_unlock_bh(&session->frwd_lock);
319 conn = session->leadconn;
320 beiscsi_conn = conn->dd_data;
321 phba = beiscsi_conn->phba;
322 cid = beiscsi_conn->beiscsi_conn_cid;
323 inv_tbl = phba->inv_tbl;
324 memset(inv_tbl, 0x0, sizeof(*inv_tbl) * BE2_CMDS_PER_CXN);
326 for (i = 0; i < conn->session->cmds_max; i++) {
327 abrt_task = conn->session->cmds[i];
328 abrt_io_task = abrt_task->dd_data;
329 if (!abrt_task->sc || abrt_task->state == ISCSI_TASK_FREE)
332 if (sc->device->lun != abrt_task->sc->device->lun)
335 /* Invalidate WRB Posted for this Task */
336 AMAP_SET_BITS(struct amap_iscsi_wrb, invld,
337 abrt_io_task->pwrb_handle->pwrb,
341 inv_tbl->icd = abrt_io_task->psgl_handle->sgl_index;
345 spin_unlock_bh(&session->frwd_lock);
346 inv_tbl = phba->inv_tbl;
348 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
349 sizeof(struct invalidate_commands_params_in),
351 if (nonemb_cmd.va == NULL) {
352 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
353 "BM_%d : Failed to allocate memory for"
354 "mgmt_invalidate_icds\n");
357 nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
358 memset(nonemb_cmd.va, 0, nonemb_cmd.size);
359 tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
362 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH,
363 "BM_%d : mgmt_invalidate_icds could not be"
365 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
366 nonemb_cmd.va, nonemb_cmd.dma);
370 rc = beiscsi_mccq_compl_wait(phba, tag, NULL, &nonemb_cmd);
372 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
373 nonemb_cmd.va, nonemb_cmd.dma);
374 return iscsi_eh_device_reset(sc);
377 /*------------------- PCI Driver operations and data ----------------- */
378 static const struct pci_device_id beiscsi_pci_id_table[] = {
379 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) },
380 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) },
381 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) },
382 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) },
383 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID3) },
384 { PCI_DEVICE(ELX_VENDOR_ID, OC_SKH_ID1) },
387 MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
390 static struct scsi_host_template beiscsi_sht = {
391 .module = THIS_MODULE,
392 .name = "Emulex 10Gbe open-iscsi Initiator Driver",
393 .proc_name = DRV_NAME,
394 .queuecommand = iscsi_queuecommand,
395 .change_queue_depth = scsi_change_queue_depth,
396 .slave_configure = beiscsi_slave_configure,
397 .target_alloc = iscsi_target_alloc,
398 .eh_abort_handler = beiscsi_eh_abort,
399 .eh_device_reset_handler = beiscsi_eh_device_reset,
400 .eh_target_reset_handler = iscsi_eh_session_reset,
401 .shost_attrs = beiscsi_attrs,
402 .sg_tablesize = BEISCSI_SGLIST_ELEMENTS,
403 .can_queue = BE2_IO_DEPTH,
405 .max_sectors = BEISCSI_MAX_SECTORS,
406 .cmd_per_lun = BEISCSI_CMD_PER_LUN,
407 .use_clustering = ENABLE_CLUSTERING,
408 .vendor_id = SCSI_NL_VID_TYPE_PCI | BE_VENDOR_ID,
409 .track_queue_depth = 1,
412 static struct scsi_transport_template *beiscsi_scsi_transport;
414 static struct beiscsi_hba *beiscsi_hba_alloc(struct pci_dev *pcidev)
416 struct beiscsi_hba *phba;
417 struct Scsi_Host *shost;
419 shost = iscsi_host_alloc(&beiscsi_sht, sizeof(*phba), 0);
421 dev_err(&pcidev->dev,
422 "beiscsi_hba_alloc - iscsi_host_alloc failed\n");
425 shost->max_id = BE2_MAX_SESSIONS;
426 shost->max_channel = 0;
427 shost->max_cmd_len = BEISCSI_MAX_CMD_LEN;
428 shost->max_lun = BEISCSI_NUM_MAX_LUN;
429 shost->transportt = beiscsi_scsi_transport;
430 phba = iscsi_host_priv(shost);
431 memset(phba, 0, sizeof(*phba));
433 phba->pcidev = pci_dev_get(pcidev);
434 pci_set_drvdata(pcidev, phba);
435 phba->interface_handle = 0xFFFFFFFF;
440 static void beiscsi_unmap_pci_function(struct beiscsi_hba *phba)
443 iounmap(phba->csr_va);
447 iounmap(phba->db_va);
451 iounmap(phba->pci_va);
456 static int beiscsi_map_pci_bars(struct beiscsi_hba *phba,
457 struct pci_dev *pcidev)
462 addr = ioremap_nocache(pci_resource_start(pcidev, 2),
463 pci_resource_len(pcidev, 2));
466 phba->ctrl.csr = addr;
468 phba->csr_pa.u.a64.address = pci_resource_start(pcidev, 2);
470 addr = ioremap_nocache(pci_resource_start(pcidev, 4), 128 * 1024);
473 phba->ctrl.db = addr;
475 phba->db_pa.u.a64.address = pci_resource_start(pcidev, 4);
477 if (phba->generation == BE_GEN2)
482 addr = ioremap_nocache(pci_resource_start(pcidev, pcicfg_reg),
483 pci_resource_len(pcidev, pcicfg_reg));
487 phba->ctrl.pcicfg = addr;
489 phba->pci_pa.u.a64.address = pci_resource_start(pcidev, pcicfg_reg);
493 beiscsi_unmap_pci_function(phba);
497 static int beiscsi_enable_pci(struct pci_dev *pcidev)
501 ret = pci_enable_device(pcidev);
503 dev_err(&pcidev->dev,
504 "beiscsi_enable_pci - enable device failed\n");
508 ret = pci_request_regions(pcidev, DRV_NAME);
510 dev_err(&pcidev->dev,
511 "beiscsi_enable_pci - request region failed\n");
512 goto pci_dev_disable;
515 pci_set_master(pcidev);
516 ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(64));
518 ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(32));
520 dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n");
521 goto pci_region_release;
523 ret = pci_set_consistent_dma_mask(pcidev,
527 ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64));
529 dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n");
530 goto pci_region_release;
536 pci_release_regions(pcidev);
538 pci_disable_device(pcidev);
543 static int be_ctrl_init(struct beiscsi_hba *phba, struct pci_dev *pdev)
545 struct be_ctrl_info *ctrl = &phba->ctrl;
546 struct be_dma_mem *mbox_mem_alloc = &ctrl->mbox_mem_alloced;
547 struct be_dma_mem *mbox_mem_align = &ctrl->mbox_mem;
551 status = beiscsi_map_pci_bars(phba, pdev);
554 mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16;
555 mbox_mem_alloc->va = pci_alloc_consistent(pdev,
556 mbox_mem_alloc->size,
557 &mbox_mem_alloc->dma);
558 if (!mbox_mem_alloc->va) {
559 beiscsi_unmap_pci_function(phba);
563 mbox_mem_align->size = sizeof(struct be_mcc_mailbox);
564 mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16);
565 mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16);
566 memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox));
567 mutex_init(&ctrl->mbox_lock);
568 spin_lock_init(&phba->ctrl.mcc_lock);
574 * beiscsi_get_params()- Set the config paramters
575 * @phba: ptr device priv structure
577 static void beiscsi_get_params(struct beiscsi_hba *phba)
579 uint32_t total_cid_count = 0;
580 uint32_t total_icd_count = 0;
583 total_cid_count = BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP0) +
584 BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP1);
586 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
587 uint32_t align_mask = 0;
588 uint32_t icd_post_per_page = 0;
589 uint32_t icd_count_unavailable = 0;
590 uint32_t icd_start = 0, icd_count = 0;
591 uint32_t icd_start_align = 0, icd_count_align = 0;
593 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
594 icd_start = phba->fw_config.iscsi_icd_start[ulp_num];
595 icd_count = phba->fw_config.iscsi_icd_count[ulp_num];
597 /* Get ICD count that can be posted on each page */
598 icd_post_per_page = (PAGE_SIZE / (BE2_SGE *
599 sizeof(struct iscsi_sge)));
600 align_mask = (icd_post_per_page - 1);
602 /* Check if icd_start is aligned ICD per page posting */
603 if (icd_start % icd_post_per_page) {
604 icd_start_align = ((icd_start +
608 iscsi_icd_start[ulp_num] =
612 icd_count_align = (icd_count & ~align_mask);
614 /* ICD discarded in the process of alignment */
616 icd_count_unavailable = ((icd_start_align -
621 /* Updated ICD count available */
622 phba->fw_config.iscsi_icd_count[ulp_num] = (icd_count -
623 icd_count_unavailable);
625 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
626 "BM_%d : Aligned ICD values\n"
627 "\t ICD Start : %d\n"
628 "\t ICD Count : %d\n"
629 "\t ICD Discarded : %d\n",
631 iscsi_icd_start[ulp_num],
633 iscsi_icd_count[ulp_num],
634 icd_count_unavailable);
639 total_icd_count = phba->fw_config.iscsi_icd_count[ulp_num];
640 phba->params.ios_per_ctrl = (total_icd_count -
642 BE2_TMFS + BE2_NOPOUT_REQ));
643 phba->params.cxns_per_ctrl = total_cid_count;
644 phba->params.asyncpdus_per_ctrl = total_cid_count;
645 phba->params.icds_per_ctrl = total_icd_count;
646 phba->params.num_sge_per_io = BE2_SGE;
647 phba->params.defpdu_hdr_sz = BE2_DEFPDU_HDR_SZ;
648 phba->params.defpdu_data_sz = BE2_DEFPDU_DATA_SZ;
649 phba->params.eq_timer = 64;
650 phba->params.num_eq_entries = 1024;
651 phba->params.num_cq_entries = 1024;
652 phba->params.wrbs_per_cxn = 256;
655 static void hwi_ring_eq_db(struct beiscsi_hba *phba,
656 unsigned int id, unsigned int clr_interrupt,
657 unsigned int num_processed,
658 unsigned char rearm, unsigned char event)
663 val |= 1 << DB_EQ_REARM_SHIFT;
665 val |= 1 << DB_EQ_CLR_SHIFT;
667 val |= 1 << DB_EQ_EVNT_SHIFT;
669 val |= num_processed << DB_EQ_NUM_POPPED_SHIFT;
670 /* Setting lower order EQ_ID Bits */
671 val |= (id & DB_EQ_RING_ID_LOW_MASK);
673 /* Setting Higher order EQ_ID Bits */
674 val |= (((id >> DB_EQ_HIGH_FEILD_SHIFT) &
675 DB_EQ_RING_ID_HIGH_MASK)
676 << DB_EQ_HIGH_SET_SHIFT);
678 iowrite32(val, phba->db_va + DB_EQ_OFFSET);
682 * be_isr_mcc - The isr routine of the driver.
684 * @dev_id: Pointer to host adapter structure
686 static irqreturn_t be_isr_mcc(int irq, void *dev_id)
688 struct beiscsi_hba *phba;
689 struct be_eq_entry *eqe;
690 struct be_queue_info *eq;
691 struct be_queue_info *mcc;
692 unsigned int mcc_events;
693 struct be_eq_obj *pbe_eq;
698 mcc = &phba->ctrl.mcc_obj.cq;
699 eqe = queue_tail_node(eq);
702 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
704 if (((eqe->dw[offsetof(struct amap_eq_entry,
706 EQE_RESID_MASK) >> 16) == mcc->id) {
709 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
711 eqe = queue_tail_node(eq);
715 queue_work(phba->wq, &pbe_eq->mcc_work);
716 hwi_ring_eq_db(phba, eq->id, 1, mcc_events, 1, 1);
722 * be_isr_msix - The isr routine of the driver.
724 * @dev_id: Pointer to host adapter structure
726 static irqreturn_t be_isr_msix(int irq, void *dev_id)
728 struct beiscsi_hba *phba;
729 struct be_queue_info *eq;
730 struct be_eq_obj *pbe_eq;
736 /* disable interrupt till iopoll completes */
737 hwi_ring_eq_db(phba, eq->id, 1, 0, 0, 1);
738 irq_poll_sched(&pbe_eq->iopoll);
744 * be_isr - The isr routine of the driver.
746 * @dev_id: Pointer to host adapter structure
748 static irqreturn_t be_isr(int irq, void *dev_id)
750 struct beiscsi_hba *phba;
751 struct hwi_controller *phwi_ctrlr;
752 struct hwi_context_memory *phwi_context;
753 struct be_eq_entry *eqe;
754 struct be_queue_info *eq;
755 struct be_queue_info *mcc;
756 unsigned int mcc_events, io_events;
757 struct be_ctrl_info *ctrl;
758 struct be_eq_obj *pbe_eq;
763 isr = ioread32(ctrl->csr + CEV_ISR0_OFFSET +
764 (PCI_FUNC(ctrl->pdev->devfn) * CEV_ISR_SIZE));
768 phwi_ctrlr = phba->phwi_ctrlr;
769 phwi_context = phwi_ctrlr->phwi_ctxt;
770 pbe_eq = &phwi_context->be_eq[0];
772 eq = &phwi_context->be_eq[0].q;
773 mcc = &phba->ctrl.mcc_obj.cq;
774 eqe = queue_tail_node(eq);
778 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
780 if (((eqe->dw[offsetof(struct amap_eq_entry,
781 resource_id) / 32] & EQE_RESID_MASK) >> 16) == mcc->id)
785 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
787 eqe = queue_tail_node(eq);
789 if (!io_events && !mcc_events)
792 /* no need to rearm if interrupt is only for IOs */
795 queue_work(phba->wq, &pbe_eq->mcc_work);
800 irq_poll_sched(&pbe_eq->iopoll);
801 hwi_ring_eq_db(phba, eq->id, 0, (io_events + mcc_events), rearm, 1);
806 static int beiscsi_init_irqs(struct beiscsi_hba *phba)
808 struct pci_dev *pcidev = phba->pcidev;
809 struct hwi_controller *phwi_ctrlr;
810 struct hwi_context_memory *phwi_context;
811 int ret, msix_vec, i, j;
813 phwi_ctrlr = phba->phwi_ctrlr;
814 phwi_context = phwi_ctrlr->phwi_ctxt;
816 if (phba->msix_enabled) {
817 for (i = 0; i < phba->num_cpus; i++) {
818 phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME,
820 if (!phba->msi_name[i]) {
825 sprintf(phba->msi_name[i], "beiscsi_%02x_%02x",
826 phba->shost->host_no, i);
827 msix_vec = phba->msix_entries[i].vector;
828 ret = request_irq(msix_vec, be_isr_msix, 0,
830 &phwi_context->be_eq[i]);
832 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
833 "BM_%d : beiscsi_init_irqs-Failed to"
834 "register msix for i = %d\n",
836 kfree(phba->msi_name[i]);
840 phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME, GFP_KERNEL);
841 if (!phba->msi_name[i]) {
845 sprintf(phba->msi_name[i], "beiscsi_mcc_%02x",
846 phba->shost->host_no);
847 msix_vec = phba->msix_entries[i].vector;
848 ret = request_irq(msix_vec, be_isr_mcc, 0, phba->msi_name[i],
849 &phwi_context->be_eq[i]);
851 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT ,
852 "BM_%d : beiscsi_init_irqs-"
853 "Failed to register beiscsi_msix_mcc\n");
854 kfree(phba->msi_name[i]);
859 ret = request_irq(pcidev->irq, be_isr, IRQF_SHARED,
862 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
863 "BM_%d : beiscsi_init_irqs-"
864 "Failed to register irq\\n");
870 for (j = i - 1; j >= 0; j--) {
871 kfree(phba->msi_name[j]);
872 msix_vec = phba->msix_entries[j].vector;
873 free_irq(msix_vec, &phwi_context->be_eq[j]);
878 void hwi_ring_cq_db(struct beiscsi_hba *phba,
879 unsigned int id, unsigned int num_processed,
885 val |= 1 << DB_CQ_REARM_SHIFT;
887 val |= num_processed << DB_CQ_NUM_POPPED_SHIFT;
889 /* Setting lower order CQ_ID Bits */
890 val |= (id & DB_CQ_RING_ID_LOW_MASK);
892 /* Setting Higher order CQ_ID Bits */
893 val |= (((id >> DB_CQ_HIGH_FEILD_SHIFT) &
894 DB_CQ_RING_ID_HIGH_MASK)
895 << DB_CQ_HIGH_SET_SHIFT);
897 iowrite32(val, phba->db_va + DB_CQ_OFFSET);
901 beiscsi_process_async_pdu(struct beiscsi_conn *beiscsi_conn,
902 struct beiscsi_hba *phba,
903 struct pdu_base *ppdu,
904 unsigned long pdu_len,
905 void *pbuffer, unsigned long buf_len)
907 struct iscsi_conn *conn = beiscsi_conn->conn;
908 struct iscsi_session *session = conn->session;
909 struct iscsi_task *task;
910 struct beiscsi_io_task *io_task;
911 struct iscsi_hdr *login_hdr;
913 switch (ppdu->dw[offsetof(struct amap_pdu_base, opcode) / 32] &
914 PDUBASE_OPCODE_MASK) {
915 case ISCSI_OP_NOOP_IN:
919 case ISCSI_OP_ASYNC_EVENT:
921 case ISCSI_OP_REJECT:
923 WARN_ON(!(buf_len == 48));
924 beiscsi_log(phba, KERN_ERR,
925 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
926 "BM_%d : In ISCSI_OP_REJECT\n");
928 case ISCSI_OP_LOGIN_RSP:
929 case ISCSI_OP_TEXT_RSP:
930 task = conn->login_task;
931 io_task = task->dd_data;
932 login_hdr = (struct iscsi_hdr *)ppdu;
933 login_hdr->itt = io_task->libiscsi_itt;
936 beiscsi_log(phba, KERN_WARNING,
937 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
938 "BM_%d : Unrecognized opcode 0x%x in async msg\n",
940 dw[offsetof(struct amap_pdu_base, opcode) / 32]
941 & PDUBASE_OPCODE_MASK));
945 spin_lock_bh(&session->back_lock);
946 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)ppdu, pbuffer, buf_len);
947 spin_unlock_bh(&session->back_lock);
951 static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba)
953 struct sgl_handle *psgl_handle;
955 spin_lock_bh(&phba->io_sgl_lock);
956 if (phba->io_sgl_hndl_avbl) {
957 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
958 "BM_%d : In alloc_io_sgl_handle,"
959 " io_sgl_alloc_index=%d\n",
960 phba->io_sgl_alloc_index);
962 psgl_handle = phba->io_sgl_hndl_base[phba->
964 phba->io_sgl_hndl_base[phba->io_sgl_alloc_index] = NULL;
965 phba->io_sgl_hndl_avbl--;
966 if (phba->io_sgl_alloc_index == (phba->params.
968 phba->io_sgl_alloc_index = 0;
970 phba->io_sgl_alloc_index++;
973 spin_unlock_bh(&phba->io_sgl_lock);
978 free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
980 spin_lock_bh(&phba->io_sgl_lock);
981 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
982 "BM_%d : In free_,io_sgl_free_index=%d\n",
983 phba->io_sgl_free_index);
985 if (phba->io_sgl_hndl_base[phba->io_sgl_free_index]) {
987 * this can happen if clean_task is called on a task that
988 * failed in xmit_task or alloc_pdu.
990 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
991 "BM_%d : Double Free in IO SGL io_sgl_free_index=%d,"
992 "value there=%p\n", phba->io_sgl_free_index,
993 phba->io_sgl_hndl_base
994 [phba->io_sgl_free_index]);
995 spin_unlock_bh(&phba->io_sgl_lock);
998 phba->io_sgl_hndl_base[phba->io_sgl_free_index] = psgl_handle;
999 phba->io_sgl_hndl_avbl++;
1000 if (phba->io_sgl_free_index == (phba->params.ios_per_ctrl - 1))
1001 phba->io_sgl_free_index = 0;
1003 phba->io_sgl_free_index++;
1004 spin_unlock_bh(&phba->io_sgl_lock);
1007 static inline struct wrb_handle *
1008 beiscsi_get_wrb_handle(struct hwi_wrb_context *pwrb_context,
1009 unsigned int wrbs_per_cxn)
1011 struct wrb_handle *pwrb_handle;
1013 spin_lock_bh(&pwrb_context->wrb_lock);
1014 pwrb_handle = pwrb_context->pwrb_handle_base[pwrb_context->alloc_index];
1015 pwrb_context->wrb_handles_available--;
1016 if (pwrb_context->alloc_index == (wrbs_per_cxn - 1))
1017 pwrb_context->alloc_index = 0;
1019 pwrb_context->alloc_index++;
1020 spin_unlock_bh(&pwrb_context->wrb_lock);
1026 * alloc_wrb_handle - To allocate a wrb handle
1027 * @phba: The hba pointer
1028 * @cid: The cid to use for allocation
1029 * @pwrb_context: ptr to ptr to wrb context
1031 * This happens under session_lock until submission to chip
1033 struct wrb_handle *alloc_wrb_handle(struct beiscsi_hba *phba, unsigned int cid,
1034 struct hwi_wrb_context **pcontext)
1036 struct hwi_wrb_context *pwrb_context;
1037 struct hwi_controller *phwi_ctrlr;
1038 uint16_t cri_index = BE_GET_CRI_FROM_CID(cid);
1040 phwi_ctrlr = phba->phwi_ctrlr;
1041 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
1042 /* return the context address */
1043 *pcontext = pwrb_context;
1044 return beiscsi_get_wrb_handle(pwrb_context, phba->params.wrbs_per_cxn);
1048 beiscsi_put_wrb_handle(struct hwi_wrb_context *pwrb_context,
1049 struct wrb_handle *pwrb_handle,
1050 unsigned int wrbs_per_cxn)
1052 spin_lock_bh(&pwrb_context->wrb_lock);
1053 pwrb_context->pwrb_handle_base[pwrb_context->free_index] = pwrb_handle;
1054 pwrb_context->wrb_handles_available++;
1055 if (pwrb_context->free_index == (wrbs_per_cxn - 1))
1056 pwrb_context->free_index = 0;
1058 pwrb_context->free_index++;
1059 spin_unlock_bh(&pwrb_context->wrb_lock);
1063 * free_wrb_handle - To free the wrb handle back to pool
1064 * @phba: The hba pointer
1065 * @pwrb_context: The context to free from
1066 * @pwrb_handle: The wrb_handle to free
1068 * This happens under session_lock until submission to chip
1071 free_wrb_handle(struct beiscsi_hba *phba, struct hwi_wrb_context *pwrb_context,
1072 struct wrb_handle *pwrb_handle)
1074 beiscsi_put_wrb_handle(pwrb_context,
1076 phba->params.wrbs_per_cxn);
1077 beiscsi_log(phba, KERN_INFO,
1078 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1079 "BM_%d : FREE WRB: pwrb_handle=%p free_index=0x%x"
1080 "wrb_handles_available=%d\n",
1081 pwrb_handle, pwrb_context->free_index,
1082 pwrb_context->wrb_handles_available);
1085 static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba)
1087 struct sgl_handle *psgl_handle;
1089 spin_lock_bh(&phba->mgmt_sgl_lock);
1090 if (phba->eh_sgl_hndl_avbl) {
1091 psgl_handle = phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index];
1092 phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index] = NULL;
1093 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1094 "BM_%d : mgmt_sgl_alloc_index=%d=0x%x\n",
1095 phba->eh_sgl_alloc_index,
1096 phba->eh_sgl_alloc_index);
1098 phba->eh_sgl_hndl_avbl--;
1099 if (phba->eh_sgl_alloc_index ==
1100 (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl -
1102 phba->eh_sgl_alloc_index = 0;
1104 phba->eh_sgl_alloc_index++;
1107 spin_unlock_bh(&phba->mgmt_sgl_lock);
1112 free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
1114 spin_lock_bh(&phba->mgmt_sgl_lock);
1115 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1116 "BM_%d : In free_mgmt_sgl_handle,"
1117 "eh_sgl_free_index=%d\n",
1118 phba->eh_sgl_free_index);
1120 if (phba->eh_sgl_hndl_base[phba->eh_sgl_free_index]) {
1122 * this can happen if clean_task is called on a task that
1123 * failed in xmit_task or alloc_pdu.
1125 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1126 "BM_%d : Double Free in eh SGL ,"
1127 "eh_sgl_free_index=%d\n",
1128 phba->eh_sgl_free_index);
1129 spin_unlock_bh(&phba->mgmt_sgl_lock);
1132 phba->eh_sgl_hndl_base[phba->eh_sgl_free_index] = psgl_handle;
1133 phba->eh_sgl_hndl_avbl++;
1134 if (phba->eh_sgl_free_index ==
1135 (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl - 1))
1136 phba->eh_sgl_free_index = 0;
1138 phba->eh_sgl_free_index++;
1139 spin_unlock_bh(&phba->mgmt_sgl_lock);
1143 be_complete_io(struct beiscsi_conn *beiscsi_conn,
1144 struct iscsi_task *task,
1145 struct common_sol_cqe *csol_cqe)
1147 struct beiscsi_io_task *io_task = task->dd_data;
1148 struct be_status_bhs *sts_bhs =
1149 (struct be_status_bhs *)io_task->cmd_bhs;
1150 struct iscsi_conn *conn = beiscsi_conn->conn;
1151 unsigned char *sense;
1152 u32 resid = 0, exp_cmdsn, max_cmdsn;
1153 u8 rsp, status, flags;
1155 exp_cmdsn = csol_cqe->exp_cmdsn;
1156 max_cmdsn = (csol_cqe->exp_cmdsn +
1157 csol_cqe->cmd_wnd - 1);
1158 rsp = csol_cqe->i_resp;
1159 status = csol_cqe->i_sts;
1160 flags = csol_cqe->i_flags;
1161 resid = csol_cqe->res_cnt;
1164 if (io_task->scsi_cmnd) {
1165 scsi_dma_unmap(io_task->scsi_cmnd);
1166 io_task->scsi_cmnd = NULL;
1171 task->sc->result = (DID_OK << 16) | status;
1172 if (rsp != ISCSI_STATUS_CMD_COMPLETED) {
1173 task->sc->result = DID_ERROR << 16;
1177 /* bidi not initially supported */
1178 if (flags & (ISCSI_FLAG_CMD_UNDERFLOW | ISCSI_FLAG_CMD_OVERFLOW)) {
1179 if (!status && (flags & ISCSI_FLAG_CMD_OVERFLOW))
1180 task->sc->result = DID_ERROR << 16;
1182 if (flags & ISCSI_FLAG_CMD_UNDERFLOW) {
1183 scsi_set_resid(task->sc, resid);
1184 if (!status && (scsi_bufflen(task->sc) - resid <
1185 task->sc->underflow))
1186 task->sc->result = DID_ERROR << 16;
1190 if (status == SAM_STAT_CHECK_CONDITION) {
1192 unsigned short *slen = (unsigned short *)sts_bhs->sense_info;
1194 sense = sts_bhs->sense_info + sizeof(unsigned short);
1195 sense_len = be16_to_cpu(*slen);
1196 memcpy(task->sc->sense_buffer, sense,
1197 min_t(u16, sense_len, SCSI_SENSE_BUFFERSIZE));
1200 if (io_task->cmd_bhs->iscsi_hdr.flags & ISCSI_FLAG_CMD_READ)
1201 conn->rxdata_octets += resid;
1203 if (io_task->scsi_cmnd) {
1204 scsi_dma_unmap(io_task->scsi_cmnd);
1205 io_task->scsi_cmnd = NULL;
1207 iscsi_complete_scsi_task(task, exp_cmdsn, max_cmdsn);
1211 be_complete_logout(struct beiscsi_conn *beiscsi_conn,
1212 struct iscsi_task *task,
1213 struct common_sol_cqe *csol_cqe)
1215 struct iscsi_logout_rsp *hdr;
1216 struct beiscsi_io_task *io_task = task->dd_data;
1217 struct iscsi_conn *conn = beiscsi_conn->conn;
1219 hdr = (struct iscsi_logout_rsp *)task->hdr;
1220 hdr->opcode = ISCSI_OP_LOGOUT_RSP;
1223 hdr->flags = csol_cqe->i_flags;
1224 hdr->response = csol_cqe->i_resp;
1225 hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn);
1226 hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn +
1227 csol_cqe->cmd_wnd - 1);
1229 hdr->dlength[0] = 0;
1230 hdr->dlength[1] = 0;
1231 hdr->dlength[2] = 0;
1233 hdr->itt = io_task->libiscsi_itt;
1234 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1238 be_complete_tmf(struct beiscsi_conn *beiscsi_conn,
1239 struct iscsi_task *task,
1240 struct common_sol_cqe *csol_cqe)
1242 struct iscsi_tm_rsp *hdr;
1243 struct iscsi_conn *conn = beiscsi_conn->conn;
1244 struct beiscsi_io_task *io_task = task->dd_data;
1246 hdr = (struct iscsi_tm_rsp *)task->hdr;
1247 hdr->opcode = ISCSI_OP_SCSI_TMFUNC_RSP;
1248 hdr->flags = csol_cqe->i_flags;
1249 hdr->response = csol_cqe->i_resp;
1250 hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn);
1251 hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn +
1252 csol_cqe->cmd_wnd - 1);
1254 hdr->itt = io_task->libiscsi_itt;
1255 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1259 hwi_complete_drvr_msgs(struct beiscsi_conn *beiscsi_conn,
1260 struct beiscsi_hba *phba, struct sol_cqe *psol)
1262 struct hwi_wrb_context *pwrb_context;
1263 struct wrb_handle *pwrb_handle = NULL;
1264 struct hwi_controller *phwi_ctrlr;
1265 struct iscsi_task *task;
1266 struct beiscsi_io_task *io_task;
1267 uint16_t wrb_index, cid, cri_index;
1269 phwi_ctrlr = phba->phwi_ctrlr;
1270 if (is_chip_be2_be3r(phba)) {
1271 wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe,
1273 cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe,
1276 wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2,
1278 cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2,
1282 cri_index = BE_GET_CRI_FROM_CID(cid);
1283 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
1284 pwrb_handle = pwrb_context->pwrb_handle_basestd[wrb_index];
1285 task = pwrb_handle->pio_handle;
1287 io_task = task->dd_data;
1288 memset(io_task->pwrb_handle->pwrb, 0, sizeof(struct iscsi_wrb));
1289 iscsi_put_task(task);
1293 be_complete_nopin_resp(struct beiscsi_conn *beiscsi_conn,
1294 struct iscsi_task *task,
1295 struct common_sol_cqe *csol_cqe)
1297 struct iscsi_nopin *hdr;
1298 struct iscsi_conn *conn = beiscsi_conn->conn;
1299 struct beiscsi_io_task *io_task = task->dd_data;
1301 hdr = (struct iscsi_nopin *)task->hdr;
1302 hdr->flags = csol_cqe->i_flags;
1303 hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn);
1304 hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn +
1305 csol_cqe->cmd_wnd - 1);
1307 hdr->opcode = ISCSI_OP_NOOP_IN;
1308 hdr->itt = io_task->libiscsi_itt;
1309 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1312 static void adapter_get_sol_cqe(struct beiscsi_hba *phba,
1313 struct sol_cqe *psol,
1314 struct common_sol_cqe *csol_cqe)
1316 if (is_chip_be2_be3r(phba)) {
1317 csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe,
1318 i_exp_cmd_sn, psol);
1319 csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe,
1321 csol_cqe->cmd_wnd = AMAP_GET_BITS(struct amap_sol_cqe,
1323 csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe,
1325 csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe,
1327 csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe,
1329 csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe,
1331 csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe,
1333 csol_cqe->i_flags = AMAP_GET_BITS(struct amap_sol_cqe,
1336 csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1337 i_exp_cmd_sn, psol);
1338 csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1340 csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1342 csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1344 csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1346 csol_cqe->cmd_wnd = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1348 if (AMAP_GET_BITS(struct amap_sol_cqe_v2,
1350 csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1353 csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1355 if (AMAP_GET_BITS(struct amap_sol_cqe_v2,
1357 csol_cqe->i_flags = ISCSI_FLAG_CMD_UNDERFLOW;
1359 if (AMAP_GET_BITS(struct amap_sol_cqe_v2,
1361 csol_cqe->i_flags |= ISCSI_FLAG_CMD_OVERFLOW;
1366 static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn,
1367 struct beiscsi_hba *phba, struct sol_cqe *psol)
1369 struct hwi_wrb_context *pwrb_context;
1370 struct wrb_handle *pwrb_handle;
1371 struct iscsi_wrb *pwrb = NULL;
1372 struct hwi_controller *phwi_ctrlr;
1373 struct iscsi_task *task;
1375 struct iscsi_conn *conn = beiscsi_conn->conn;
1376 struct iscsi_session *session = conn->session;
1377 struct common_sol_cqe csol_cqe = {0};
1378 uint16_t cri_index = 0;
1380 phwi_ctrlr = phba->phwi_ctrlr;
1382 /* Copy the elements to a common structure */
1383 adapter_get_sol_cqe(phba, psol, &csol_cqe);
1385 cri_index = BE_GET_CRI_FROM_CID(csol_cqe.cid);
1386 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
1388 pwrb_handle = pwrb_context->pwrb_handle_basestd[
1389 csol_cqe.wrb_index];
1391 task = pwrb_handle->pio_handle;
1392 pwrb = pwrb_handle->pwrb;
1393 type = ((struct beiscsi_io_task *)task->dd_data)->wrb_type;
1395 spin_lock_bh(&session->back_lock);
1398 case HWH_TYPE_IO_RD:
1399 if ((task->hdr->opcode & ISCSI_OPCODE_MASK) ==
1401 be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe);
1403 be_complete_io(beiscsi_conn, task, &csol_cqe);
1406 case HWH_TYPE_LOGOUT:
1407 if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGOUT)
1408 be_complete_logout(beiscsi_conn, task, &csol_cqe);
1410 be_complete_tmf(beiscsi_conn, task, &csol_cqe);
1413 case HWH_TYPE_LOGIN:
1414 beiscsi_log(phba, KERN_ERR,
1415 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1416 "BM_%d :\t\t No HWH_TYPE_LOGIN Expected in"
1417 " hwi_complete_cmd- Solicited path\n");
1421 be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe);
1425 beiscsi_log(phba, KERN_WARNING,
1426 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1427 "BM_%d : In hwi_complete_cmd, unknown type = %d"
1428 "wrb_index 0x%x CID 0x%x\n", type,
1434 spin_unlock_bh(&session->back_lock);
1437 static struct list_head *hwi_get_async_busy_list(struct hwi_async_pdu_context
1438 *pasync_ctx, unsigned int is_header,
1439 unsigned int host_write_ptr)
1442 return &pasync_ctx->async_entry[host_write_ptr].
1445 return &pasync_ctx->async_entry[host_write_ptr].data_busy_list;
1448 static struct async_pdu_handle *
1449 hwi_get_async_handle(struct beiscsi_hba *phba,
1450 struct beiscsi_conn *beiscsi_conn,
1451 struct hwi_async_pdu_context *pasync_ctx,
1452 struct i_t_dpdu_cqe *pdpdu_cqe, unsigned int *pcq_index)
1454 struct be_bus_address phys_addr;
1455 struct list_head *pbusy_list;
1456 struct async_pdu_handle *pasync_handle = NULL;
1457 unsigned char is_header = 0;
1458 unsigned int index, dpl;
1460 if (is_chip_be2_be3r(phba)) {
1461 dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe,
1463 index = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe,
1466 dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2,
1468 index = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2,
1472 phys_addr.u.a32.address_lo =
1473 (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
1474 db_addr_lo) / 32] - dpl);
1475 phys_addr.u.a32.address_hi =
1476 pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
1479 phys_addr.u.a64.address =
1480 *((unsigned long long *)(&phys_addr.u.a64.address));
1482 switch (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, code) / 32]
1483 & PDUCQE_CODE_MASK) {
1484 case UNSOL_HDR_NOTIFY:
1487 pbusy_list = hwi_get_async_busy_list(pasync_ctx,
1490 case UNSOL_DATA_NOTIFY:
1491 pbusy_list = hwi_get_async_busy_list(pasync_ctx,
1496 beiscsi_log(phba, KERN_WARNING,
1497 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1498 "BM_%d : Unexpected code=%d\n",
1499 pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
1500 code) / 32] & PDUCQE_CODE_MASK);
1504 WARN_ON(list_empty(pbusy_list));
1505 list_for_each_entry(pasync_handle, pbusy_list, link) {
1506 if (pasync_handle->pa.u.a64.address == phys_addr.u.a64.address)
1510 WARN_ON(!pasync_handle);
1512 pasync_handle->cri = BE_GET_ASYNC_CRI_FROM_CID(
1513 beiscsi_conn->beiscsi_conn_cid);
1514 pasync_handle->is_header = is_header;
1515 pasync_handle->buffer_len = dpl;
1518 return pasync_handle;
1522 hwi_update_async_writables(struct beiscsi_hba *phba,
1523 struct hwi_async_pdu_context *pasync_ctx,
1524 unsigned int is_header, unsigned int cq_index)
1526 struct list_head *pbusy_list;
1527 struct async_pdu_handle *pasync_handle;
1528 unsigned int num_entries, writables = 0;
1529 unsigned int *pep_read_ptr, *pwritables;
1531 num_entries = pasync_ctx->num_entries;
1533 pep_read_ptr = &pasync_ctx->async_header.ep_read_ptr;
1534 pwritables = &pasync_ctx->async_header.writables;
1536 pep_read_ptr = &pasync_ctx->async_data.ep_read_ptr;
1537 pwritables = &pasync_ctx->async_data.writables;
1540 while ((*pep_read_ptr) != cq_index) {
1542 *pep_read_ptr = (*pep_read_ptr) % num_entries;
1544 pbusy_list = hwi_get_async_busy_list(pasync_ctx, is_header,
1547 WARN_ON(list_empty(pbusy_list));
1549 if (!list_empty(pbusy_list)) {
1550 pasync_handle = list_entry(pbusy_list->next,
1551 struct async_pdu_handle,
1553 WARN_ON(!pasync_handle);
1554 pasync_handle->consumed = 1;
1561 beiscsi_log(phba, KERN_ERR,
1562 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1563 "BM_%d : Duplicate notification received - index 0x%x!!\n",
1568 *pwritables = *pwritables + writables;
1572 static void hwi_free_async_msg(struct beiscsi_hba *phba,
1573 struct hwi_async_pdu_context *pasync_ctx,
1576 struct async_pdu_handle *pasync_handle, *tmp_handle;
1577 struct list_head *plist;
1579 plist = &pasync_ctx->async_entry[cri].wait_queue.list;
1580 list_for_each_entry_safe(pasync_handle, tmp_handle, plist, link) {
1581 list_del(&pasync_handle->link);
1583 if (pasync_handle->is_header) {
1584 list_add_tail(&pasync_handle->link,
1585 &pasync_ctx->async_header.free_list);
1586 pasync_ctx->async_header.free_entries++;
1588 list_add_tail(&pasync_handle->link,
1589 &pasync_ctx->async_data.free_list);
1590 pasync_ctx->async_data.free_entries++;
1594 INIT_LIST_HEAD(&pasync_ctx->async_entry[cri].wait_queue.list);
1595 pasync_ctx->async_entry[cri].wait_queue.hdr_received = 0;
1596 pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0;
1599 static struct phys_addr *
1600 hwi_get_ring_address(struct hwi_async_pdu_context *pasync_ctx,
1601 unsigned int is_header, unsigned int host_write_ptr)
1603 struct phys_addr *pasync_sge = NULL;
1606 pasync_sge = pasync_ctx->async_header.ring_base;
1608 pasync_sge = pasync_ctx->async_data.ring_base;
1610 return pasync_sge + host_write_ptr;
1613 static void hwi_post_async_buffers(struct beiscsi_hba *phba,
1614 unsigned int is_header, uint8_t ulp_num)
1616 struct hwi_controller *phwi_ctrlr;
1617 struct hwi_async_pdu_context *pasync_ctx;
1618 struct async_pdu_handle *pasync_handle;
1619 struct list_head *pfree_link, *pbusy_list;
1620 struct phys_addr *pasync_sge;
1621 unsigned int ring_id, num_entries;
1622 unsigned int host_write_num, doorbell_offset;
1623 unsigned int writables;
1627 phwi_ctrlr = phba->phwi_ctrlr;
1628 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr, ulp_num);
1629 num_entries = pasync_ctx->num_entries;
1632 writables = min(pasync_ctx->async_header.writables,
1633 pasync_ctx->async_header.free_entries);
1634 pfree_link = pasync_ctx->async_header.free_list.next;
1635 host_write_num = pasync_ctx->async_header.host_write_ptr;
1636 ring_id = phwi_ctrlr->default_pdu_hdr[ulp_num].id;
1637 doorbell_offset = phwi_ctrlr->default_pdu_hdr[ulp_num].
1640 writables = min(pasync_ctx->async_data.writables,
1641 pasync_ctx->async_data.free_entries);
1642 pfree_link = pasync_ctx->async_data.free_list.next;
1643 host_write_num = pasync_ctx->async_data.host_write_ptr;
1644 ring_id = phwi_ctrlr->default_pdu_data[ulp_num].id;
1645 doorbell_offset = phwi_ctrlr->default_pdu_data[ulp_num].
1649 writables = (writables / 8) * 8;
1651 for (i = 0; i < writables; i++) {
1653 hwi_get_async_busy_list(pasync_ctx, is_header,
1656 list_entry(pfree_link, struct async_pdu_handle,
1658 WARN_ON(!pasync_handle);
1659 pasync_handle->consumed = 0;
1661 pfree_link = pfree_link->next;
1663 pasync_sge = hwi_get_ring_address(pasync_ctx,
1664 is_header, host_write_num);
1666 pasync_sge->hi = pasync_handle->pa.u.a32.address_lo;
1667 pasync_sge->lo = pasync_handle->pa.u.a32.address_hi;
1669 list_move(&pasync_handle->link, pbusy_list);
1672 host_write_num = host_write_num % num_entries;
1676 pasync_ctx->async_header.host_write_ptr =
1678 pasync_ctx->async_header.free_entries -= writables;
1679 pasync_ctx->async_header.writables -= writables;
1680 pasync_ctx->async_header.busy_entries += writables;
1682 pasync_ctx->async_data.host_write_ptr = host_write_num;
1683 pasync_ctx->async_data.free_entries -= writables;
1684 pasync_ctx->async_data.writables -= writables;
1685 pasync_ctx->async_data.busy_entries += writables;
1688 doorbell |= ring_id & DB_DEF_PDU_RING_ID_MASK;
1689 doorbell |= 1 << DB_DEF_PDU_REARM_SHIFT;
1690 doorbell |= 0 << DB_DEF_PDU_EVENT_SHIFT;
1691 doorbell |= (writables & DB_DEF_PDU_CQPROC_MASK)
1692 << DB_DEF_PDU_CQPROC_SHIFT;
1694 iowrite32(doorbell, phba->db_va + doorbell_offset);
1698 static void hwi_flush_default_pdu_buffer(struct beiscsi_hba *phba,
1699 struct beiscsi_conn *beiscsi_conn,
1700 struct i_t_dpdu_cqe *pdpdu_cqe)
1702 struct hwi_controller *phwi_ctrlr;
1703 struct hwi_async_pdu_context *pasync_ctx;
1704 struct async_pdu_handle *pasync_handle = NULL;
1705 unsigned int cq_index = -1;
1706 uint16_t cri_index = BE_GET_CRI_FROM_CID(
1707 beiscsi_conn->beiscsi_conn_cid);
1709 phwi_ctrlr = phba->phwi_ctrlr;
1710 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr,
1711 BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr,
1714 pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
1715 pdpdu_cqe, &cq_index);
1716 BUG_ON(pasync_handle->is_header != 0);
1717 if (pasync_handle->consumed == 0)
1718 hwi_update_async_writables(phba, pasync_ctx,
1719 pasync_handle->is_header, cq_index);
1721 hwi_free_async_msg(phba, pasync_ctx, pasync_handle->cri);
1722 hwi_post_async_buffers(phba, pasync_handle->is_header,
1723 BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr,
1728 hwi_fwd_async_msg(struct beiscsi_conn *beiscsi_conn,
1729 struct beiscsi_hba *phba,
1730 struct hwi_async_pdu_context *pasync_ctx, unsigned short cri)
1732 struct list_head *plist;
1733 struct async_pdu_handle *pasync_handle;
1735 unsigned int hdr_len = 0, buf_len = 0;
1736 unsigned int status, index = 0, offset = 0;
1737 void *pfirst_buffer = NULL;
1738 unsigned int num_buf = 0;
1740 plist = &pasync_ctx->async_entry[cri].wait_queue.list;
1742 list_for_each_entry(pasync_handle, plist, link) {
1744 phdr = pasync_handle->pbuffer;
1745 hdr_len = pasync_handle->buffer_len;
1747 buf_len = pasync_handle->buffer_len;
1749 pfirst_buffer = pasync_handle->pbuffer;
1752 memcpy(pfirst_buffer + offset,
1753 pasync_handle->pbuffer, buf_len);
1759 status = beiscsi_process_async_pdu(beiscsi_conn, phba,
1760 phdr, hdr_len, pfirst_buffer,
1763 hwi_free_async_msg(phba, pasync_ctx, cri);
1768 hwi_gather_async_pdu(struct beiscsi_conn *beiscsi_conn,
1769 struct beiscsi_hba *phba,
1770 struct async_pdu_handle *pasync_handle)
1772 struct hwi_async_pdu_context *pasync_ctx;
1773 struct hwi_controller *phwi_ctrlr;
1774 unsigned int bytes_needed = 0, status = 0;
1775 unsigned short cri = pasync_handle->cri;
1776 struct pdu_base *ppdu;
1778 phwi_ctrlr = phba->phwi_ctrlr;
1779 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr,
1780 BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr,
1781 BE_GET_CRI_FROM_CID(beiscsi_conn->
1782 beiscsi_conn_cid)));
1784 list_del(&pasync_handle->link);
1785 if (pasync_handle->is_header) {
1786 pasync_ctx->async_header.busy_entries--;
1787 if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) {
1788 hwi_free_async_msg(phba, pasync_ctx, cri);
1792 pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0;
1793 pasync_ctx->async_entry[cri].wait_queue.hdr_received = 1;
1794 pasync_ctx->async_entry[cri].wait_queue.hdr_len =
1795 (unsigned short)pasync_handle->buffer_len;
1796 list_add_tail(&pasync_handle->link,
1797 &pasync_ctx->async_entry[cri].wait_queue.list);
1799 ppdu = pasync_handle->pbuffer;
1800 bytes_needed = ((((ppdu->dw[offsetof(struct amap_pdu_base,
1801 data_len_hi) / 32] & PDUBASE_DATALENHI_MASK) << 8) &
1802 0xFFFF0000) | ((be16_to_cpu((ppdu->
1803 dw[offsetof(struct amap_pdu_base, data_len_lo) / 32]
1804 & PDUBASE_DATALENLO_MASK) >> 16)) & 0x0000FFFF));
1807 pasync_ctx->async_entry[cri].wait_queue.bytes_needed =
1810 if (bytes_needed == 0)
1811 status = hwi_fwd_async_msg(beiscsi_conn, phba,
1815 pasync_ctx->async_data.busy_entries--;
1816 if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) {
1817 list_add_tail(&pasync_handle->link,
1818 &pasync_ctx->async_entry[cri].wait_queue.
1820 pasync_ctx->async_entry[cri].wait_queue.
1822 (unsigned short)pasync_handle->buffer_len;
1824 if (pasync_ctx->async_entry[cri].wait_queue.
1826 pasync_ctx->async_entry[cri].wait_queue.
1828 status = hwi_fwd_async_msg(beiscsi_conn, phba,
1835 static void hwi_process_default_pdu_ring(struct beiscsi_conn *beiscsi_conn,
1836 struct beiscsi_hba *phba,
1837 struct i_t_dpdu_cqe *pdpdu_cqe)
1839 struct hwi_controller *phwi_ctrlr;
1840 struct hwi_async_pdu_context *pasync_ctx;
1841 struct async_pdu_handle *pasync_handle = NULL;
1842 unsigned int cq_index = -1;
1843 uint16_t cri_index = BE_GET_CRI_FROM_CID(
1844 beiscsi_conn->beiscsi_conn_cid);
1846 phwi_ctrlr = phba->phwi_ctrlr;
1847 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr,
1848 BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr,
1851 pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
1852 pdpdu_cqe, &cq_index);
1854 if (pasync_handle->consumed == 0)
1855 hwi_update_async_writables(phba, pasync_ctx,
1856 pasync_handle->is_header, cq_index);
1858 hwi_gather_async_pdu(beiscsi_conn, phba, pasync_handle);
1859 hwi_post_async_buffers(phba, pasync_handle->is_header,
1860 BEISCSI_GET_ULP_FROM_CRI(
1861 phwi_ctrlr, cri_index));
1864 void beiscsi_process_mcc_cq(struct beiscsi_hba *phba)
1866 struct be_queue_info *mcc_cq;
1867 struct be_mcc_compl *mcc_compl;
1868 unsigned int num_processed = 0;
1870 mcc_cq = &phba->ctrl.mcc_obj.cq;
1871 mcc_compl = queue_tail_node(mcc_cq);
1872 mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
1873 while (mcc_compl->flags & CQE_FLAGS_VALID_MASK) {
1874 if (beiscsi_hba_in_error(phba))
1877 if (num_processed >= 32) {
1878 hwi_ring_cq_db(phba, mcc_cq->id,
1882 if (mcc_compl->flags & CQE_FLAGS_ASYNC_MASK) {
1883 beiscsi_process_async_event(phba, mcc_compl);
1884 } else if (mcc_compl->flags & CQE_FLAGS_COMPLETED_MASK) {
1885 beiscsi_process_mcc_compl(&phba->ctrl, mcc_compl);
1888 mcc_compl->flags = 0;
1889 queue_tail_inc(mcc_cq);
1890 mcc_compl = queue_tail_node(mcc_cq);
1891 mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
1895 if (num_processed > 0)
1896 hwi_ring_cq_db(phba, mcc_cq->id, num_processed, 1);
1899 static void beiscsi_mcc_work(struct work_struct *work)
1901 struct be_eq_obj *pbe_eq;
1902 struct beiscsi_hba *phba;
1904 pbe_eq = container_of(work, struct be_eq_obj, mcc_work);
1905 phba = pbe_eq->phba;
1906 beiscsi_process_mcc_cq(phba);
1907 /* rearm EQ for further interrupts */
1908 if (!beiscsi_hba_in_error(phba))
1909 hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1);
1913 * beiscsi_process_cq()- Process the Completion Queue
1914 * @pbe_eq: Event Q on which the Completion has come
1915 * @budget: Max number of events to processed
1918 * Number of Completion Entries processed.
1920 unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq, int budget)
1922 struct be_queue_info *cq;
1923 struct sol_cqe *sol;
1924 struct dmsg_cqe *dmsg;
1925 unsigned int total = 0;
1926 unsigned int num_processed = 0;
1927 unsigned short code = 0, cid = 0;
1928 uint16_t cri_index = 0;
1929 struct beiscsi_conn *beiscsi_conn;
1930 struct beiscsi_endpoint *beiscsi_ep;
1931 struct iscsi_endpoint *ep;
1932 struct beiscsi_hba *phba;
1935 sol = queue_tail_node(cq);
1936 phba = pbe_eq->phba;
1938 while (sol->dw[offsetof(struct amap_sol_cqe, valid) / 32] &
1940 if (beiscsi_hba_in_error(phba))
1943 be_dws_le_to_cpu(sol, sizeof(struct sol_cqe));
1945 code = (sol->dw[offsetof(struct amap_sol_cqe, code) /
1946 32] & CQE_CODE_MASK);
1949 if (is_chip_be2_be3r(phba)) {
1950 cid = AMAP_GET_BITS(struct amap_sol_cqe, cid, sol);
1952 if ((code == DRIVERMSG_NOTIFY) ||
1953 (code == UNSOL_HDR_NOTIFY) ||
1954 (code == UNSOL_DATA_NOTIFY))
1955 cid = AMAP_GET_BITS(
1956 struct amap_i_t_dpdu_cqe_v2,
1959 cid = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1963 cri_index = BE_GET_CRI_FROM_CID(cid);
1964 ep = phba->ep_array[cri_index];
1967 /* connection has already been freed
1968 * just move on to next one
1970 beiscsi_log(phba, KERN_WARNING,
1972 "BM_%d : proc cqe of disconn ep: cid %d\n",
1977 beiscsi_ep = ep->dd_data;
1978 beiscsi_conn = beiscsi_ep->conn;
1981 if (num_processed == 32) {
1982 hwi_ring_cq_db(phba, cq->id, 32, 0);
1988 case SOL_CMD_COMPLETE:
1989 hwi_complete_cmd(beiscsi_conn, phba, sol);
1991 case DRIVERMSG_NOTIFY:
1992 beiscsi_log(phba, KERN_INFO,
1993 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1994 "BM_%d : Received %s[%d] on CID : %d\n",
1995 cqe_desc[code], code, cid);
1997 dmsg = (struct dmsg_cqe *)sol;
1998 hwi_complete_drvr_msgs(beiscsi_conn, phba, sol);
2000 case UNSOL_HDR_NOTIFY:
2001 beiscsi_log(phba, KERN_INFO,
2002 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
2003 "BM_%d : Received %s[%d] on CID : %d\n",
2004 cqe_desc[code], code, cid);
2006 spin_lock_bh(&phba->async_pdu_lock);
2007 hwi_process_default_pdu_ring(beiscsi_conn, phba,
2008 (struct i_t_dpdu_cqe *)sol);
2009 spin_unlock_bh(&phba->async_pdu_lock);
2011 case UNSOL_DATA_NOTIFY:
2012 beiscsi_log(phba, KERN_INFO,
2013 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
2014 "BM_%d : Received %s[%d] on CID : %d\n",
2015 cqe_desc[code], code, cid);
2017 spin_lock_bh(&phba->async_pdu_lock);
2018 hwi_process_default_pdu_ring(beiscsi_conn, phba,
2019 (struct i_t_dpdu_cqe *)sol);
2020 spin_unlock_bh(&phba->async_pdu_lock);
2022 case CXN_INVALIDATE_INDEX_NOTIFY:
2023 case CMD_INVALIDATED_NOTIFY:
2024 case CXN_INVALIDATE_NOTIFY:
2025 beiscsi_log(phba, KERN_ERR,
2026 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
2027 "BM_%d : Ignoring %s[%d] on CID : %d\n",
2028 cqe_desc[code], code, cid);
2030 case CXN_KILLED_HDR_DIGEST_ERR:
2031 case SOL_CMD_KILLED_DATA_DIGEST_ERR:
2032 beiscsi_log(phba, KERN_ERR,
2033 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
2034 "BM_%d : Cmd Notification %s[%d] on CID : %d\n",
2035 cqe_desc[code], code, cid);
2037 case CMD_KILLED_INVALID_STATSN_RCVD:
2038 case CMD_KILLED_INVALID_R2T_RCVD:
2039 case CMD_CXN_KILLED_LUN_INVALID:
2040 case CMD_CXN_KILLED_ICD_INVALID:
2041 case CMD_CXN_KILLED_ITT_INVALID:
2042 case CMD_CXN_KILLED_SEQ_OUTOFORDER:
2043 case CMD_CXN_KILLED_INVALID_DATASN_RCVD:
2044 beiscsi_log(phba, KERN_ERR,
2045 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
2046 "BM_%d : Cmd Notification %s[%d] on CID : %d\n",
2047 cqe_desc[code], code, cid);
2049 case UNSOL_DATA_DIGEST_ERROR_NOTIFY:
2050 beiscsi_log(phba, KERN_ERR,
2051 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
2052 "BM_%d : Dropping %s[%d] on DPDU ring on CID : %d\n",
2053 cqe_desc[code], code, cid);
2054 spin_lock_bh(&phba->async_pdu_lock);
2055 hwi_flush_default_pdu_buffer(phba, beiscsi_conn,
2056 (struct i_t_dpdu_cqe *) sol);
2057 spin_unlock_bh(&phba->async_pdu_lock);
2059 case CXN_KILLED_PDU_SIZE_EXCEEDS_DSL:
2060 case CXN_KILLED_BURST_LEN_MISMATCH:
2061 case CXN_KILLED_AHS_RCVD:
2062 case CXN_KILLED_UNKNOWN_HDR:
2063 case CXN_KILLED_STALE_ITT_TTT_RCVD:
2064 case CXN_KILLED_INVALID_ITT_TTT_RCVD:
2065 case CXN_KILLED_TIMED_OUT:
2066 case CXN_KILLED_FIN_RCVD:
2067 case CXN_KILLED_RST_SENT:
2068 case CXN_KILLED_RST_RCVD:
2069 case CXN_KILLED_BAD_UNSOL_PDU_RCVD:
2070 case CXN_KILLED_BAD_WRB_INDEX_ERROR:
2071 case CXN_KILLED_OVER_RUN_RESIDUAL:
2072 case CXN_KILLED_UNDER_RUN_RESIDUAL:
2073 case CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN:
2074 beiscsi_log(phba, KERN_ERR,
2075 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
2076 "BM_%d : Event %s[%d] received on CID : %d\n",
2077 cqe_desc[code], code, cid);
2079 iscsi_conn_failure(beiscsi_conn->conn,
2080 ISCSI_ERR_CONN_FAILED);
2083 beiscsi_log(phba, KERN_ERR,
2084 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
2085 "BM_%d : Invalid CQE Event Received Code : %d"
2092 AMAP_SET_BITS(struct amap_sol_cqe, valid, sol, 0);
2094 sol = queue_tail_node(cq);
2096 if (total == budget)
2100 hwi_ring_cq_db(phba, cq->id, num_processed, 1);
2104 static int be_iopoll(struct irq_poll *iop, int budget)
2106 unsigned int ret, io_events;
2107 struct beiscsi_hba *phba;
2108 struct be_eq_obj *pbe_eq;
2109 struct be_eq_entry *eqe = NULL;
2110 struct be_queue_info *eq;
2112 pbe_eq = container_of(iop, struct be_eq_obj, iopoll);
2113 phba = pbe_eq->phba;
2114 if (beiscsi_hba_in_error(phba)) {
2115 irq_poll_complete(iop);
2121 eqe = queue_tail_node(eq);
2122 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32] &
2124 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
2126 eqe = queue_tail_node(eq);
2129 hwi_ring_eq_db(phba, eq->id, 1, io_events, 0, 1);
2131 ret = beiscsi_process_cq(pbe_eq, budget);
2132 pbe_eq->cq_count += ret;
2134 irq_poll_complete(iop);
2135 beiscsi_log(phba, KERN_INFO,
2136 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
2137 "BM_%d : rearm pbe_eq->q.id =%d ret %d\n",
2139 if (!beiscsi_hba_in_error(phba))
2140 hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1);
2146 hwi_write_sgl_v2(struct iscsi_wrb *pwrb, struct scatterlist *sg,
2147 unsigned int num_sg, struct beiscsi_io_task *io_task)
2149 struct iscsi_sge *psgl;
2150 unsigned int sg_len, index;
2151 unsigned int sge_len = 0;
2152 unsigned long long addr;
2153 struct scatterlist *l_sg;
2154 unsigned int offset;
2156 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_lo, pwrb,
2157 io_task->bhs_pa.u.a32.address_lo);
2158 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_hi, pwrb,
2159 io_task->bhs_pa.u.a32.address_hi);
2162 for (index = 0; (index < num_sg) && (index < 2); index++,
2165 sg_len = sg_dma_len(sg);
2166 addr = (u64) sg_dma_address(sg);
2167 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2169 lower_32_bits(addr));
2170 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2172 upper_32_bits(addr));
2173 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2178 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_r2t_offset,
2180 sg_len = sg_dma_len(sg);
2181 addr = (u64) sg_dma_address(sg);
2182 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2184 lower_32_bits(addr));
2185 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2187 upper_32_bits(addr));
2188 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2193 psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
2194 memset(psgl, 0, sizeof(*psgl) * BE2_SGE);
2196 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2);
2198 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2199 io_task->bhs_pa.u.a32.address_hi);
2200 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2201 io_task->bhs_pa.u.a32.address_lo);
2204 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb,
2206 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb,
2208 } else if (num_sg == 2) {
2209 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb,
2211 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb,
2214 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb,
2216 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb,
2224 for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) {
2225 sg_len = sg_dma_len(sg);
2226 addr = (u64) sg_dma_address(sg);
2227 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2228 lower_32_bits(addr));
2229 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2230 upper_32_bits(addr));
2231 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len);
2232 AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset);
2233 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
2237 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
2241 hwi_write_sgl(struct iscsi_wrb *pwrb, struct scatterlist *sg,
2242 unsigned int num_sg, struct beiscsi_io_task *io_task)
2244 struct iscsi_sge *psgl;
2245 unsigned int sg_len, index;
2246 unsigned int sge_len = 0;
2247 unsigned long long addr;
2248 struct scatterlist *l_sg;
2249 unsigned int offset;
2251 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
2252 io_task->bhs_pa.u.a32.address_lo);
2253 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
2254 io_task->bhs_pa.u.a32.address_hi);
2257 for (index = 0; (index < num_sg) && (index < 2); index++,
2260 sg_len = sg_dma_len(sg);
2261 addr = (u64) sg_dma_address(sg);
2262 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
2263 ((u32)(addr & 0xFFFFFFFF)));
2264 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
2265 ((u32)(addr >> 32)));
2266 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
2270 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_r2t_offset,
2272 sg_len = sg_dma_len(sg);
2273 addr = (u64) sg_dma_address(sg);
2274 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_lo, pwrb,
2275 ((u32)(addr & 0xFFFFFFFF)));
2276 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_hi, pwrb,
2277 ((u32)(addr >> 32)));
2278 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_len, pwrb,
2282 psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
2283 memset(psgl, 0, sizeof(*psgl) * BE2_SGE);
2285 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2);
2287 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2288 io_task->bhs_pa.u.a32.address_hi);
2289 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2290 io_task->bhs_pa.u.a32.address_lo);
2293 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
2295 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
2297 } else if (num_sg == 2) {
2298 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
2300 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
2303 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
2305 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
2312 for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) {
2313 sg_len = sg_dma_len(sg);
2314 addr = (u64) sg_dma_address(sg);
2315 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2316 (addr & 0xFFFFFFFF));
2317 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2319 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len);
2320 AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset);
2321 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
2325 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
2329 * hwi_write_buffer()- Populate the WRB with task info
2330 * @pwrb: ptr to the WRB entry
2331 * @task: iscsi task which is to be executed
2333 static int hwi_write_buffer(struct iscsi_wrb *pwrb, struct iscsi_task *task)
2335 struct iscsi_sge *psgl;
2336 struct beiscsi_io_task *io_task = task->dd_data;
2337 struct beiscsi_conn *beiscsi_conn = io_task->conn;
2338 struct beiscsi_hba *phba = beiscsi_conn->phba;
2339 uint8_t dsp_value = 0;
2341 io_task->bhs_len = sizeof(struct be_nonio_bhs) - 2;
2342 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
2343 io_task->bhs_pa.u.a32.address_lo);
2344 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
2345 io_task->bhs_pa.u.a32.address_hi);
2349 /* Check for the data_count */
2350 dsp_value = (task->data_count) ? 1 : 0;
2352 if (is_chip_be2_be3r(phba))
2353 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp,
2356 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp,
2359 /* Map addr only if there is data_count */
2361 io_task->mtask_addr = pci_map_single(phba->pcidev,
2365 if (pci_dma_mapping_error(phba->pcidev,
2366 io_task->mtask_addr))
2368 io_task->mtask_data_count = task->data_count;
2370 io_task->mtask_addr = 0;
2372 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
2373 lower_32_bits(io_task->mtask_addr));
2374 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
2375 upper_32_bits(io_task->mtask_addr));
2376 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
2379 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, 1);
2381 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
2382 io_task->mtask_addr = 0;
2385 psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
2387 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len);
2389 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2390 io_task->bhs_pa.u.a32.address_hi);
2391 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2392 io_task->bhs_pa.u.a32.address_lo);
2395 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, 0);
2396 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, 0);
2397 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0);
2398 AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, 0);
2399 AMAP_SET_BITS(struct amap_iscsi_sge, rsvd0, psgl, 0);
2400 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
2404 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2405 lower_32_bits(io_task->mtask_addr));
2406 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2407 upper_32_bits(io_task->mtask_addr));
2409 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0x106);
2411 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
2416 * beiscsi_find_mem_req()- Find mem needed
2417 * @phba: ptr to HBA struct
2419 static void beiscsi_find_mem_req(struct beiscsi_hba *phba)
2421 uint8_t mem_descr_index, ulp_num;
2422 unsigned int num_cq_pages, num_async_pdu_buf_pages;
2423 unsigned int num_async_pdu_data_pages, wrb_sz_per_cxn;
2424 unsigned int num_async_pdu_buf_sgl_pages, num_async_pdu_data_sgl_pages;
2426 num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
2427 sizeof(struct sol_cqe));
2429 phba->params.hwi_ws_sz = sizeof(struct hwi_controller);
2431 phba->mem_req[ISCSI_MEM_GLOBAL_HEADER] = 2 *
2432 BE_ISCSI_PDU_HEADER_SIZE;
2433 phba->mem_req[HWI_MEM_ADDN_CONTEXT] =
2434 sizeof(struct hwi_context_memory);
2437 phba->mem_req[HWI_MEM_WRB] = sizeof(struct iscsi_wrb)
2438 * (phba->params.wrbs_per_cxn)
2439 * phba->params.cxns_per_ctrl;
2440 wrb_sz_per_cxn = sizeof(struct wrb_handle) *
2441 (phba->params.wrbs_per_cxn);
2442 phba->mem_req[HWI_MEM_WRBH] = roundup_pow_of_two((wrb_sz_per_cxn) *
2443 phba->params.cxns_per_ctrl);
2445 phba->mem_req[HWI_MEM_SGLH] = sizeof(struct sgl_handle) *
2446 phba->params.icds_per_ctrl;
2447 phba->mem_req[HWI_MEM_SGE] = sizeof(struct iscsi_sge) *
2448 phba->params.num_sge_per_io * phba->params.icds_per_ctrl;
2449 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
2450 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
2452 num_async_pdu_buf_sgl_pages =
2453 PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
2455 sizeof(struct phys_addr));
2457 num_async_pdu_buf_pages =
2458 PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
2460 phba->params.defpdu_hdr_sz);
2462 num_async_pdu_data_pages =
2463 PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
2465 phba->params.defpdu_data_sz);
2467 num_async_pdu_data_sgl_pages =
2468 PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
2470 sizeof(struct phys_addr));
2472 mem_descr_index = (HWI_MEM_TEMPLATE_HDR_ULP0 +
2473 (ulp_num * MEM_DESCR_OFFSET));
2474 phba->mem_req[mem_descr_index] =
2475 BEISCSI_GET_CID_COUNT(phba, ulp_num) *
2476 BEISCSI_TEMPLATE_HDR_PER_CXN_SIZE;
2478 mem_descr_index = (HWI_MEM_ASYNC_HEADER_BUF_ULP0 +
2479 (ulp_num * MEM_DESCR_OFFSET));
2480 phba->mem_req[mem_descr_index] =
2481 num_async_pdu_buf_pages *
2484 mem_descr_index = (HWI_MEM_ASYNC_DATA_BUF_ULP0 +
2485 (ulp_num * MEM_DESCR_OFFSET));
2486 phba->mem_req[mem_descr_index] =
2487 num_async_pdu_data_pages *
2490 mem_descr_index = (HWI_MEM_ASYNC_HEADER_RING_ULP0 +
2491 (ulp_num * MEM_DESCR_OFFSET));
2492 phba->mem_req[mem_descr_index] =
2493 num_async_pdu_buf_sgl_pages *
2496 mem_descr_index = (HWI_MEM_ASYNC_DATA_RING_ULP0 +
2497 (ulp_num * MEM_DESCR_OFFSET));
2498 phba->mem_req[mem_descr_index] =
2499 num_async_pdu_data_sgl_pages *
2502 mem_descr_index = (HWI_MEM_ASYNC_HEADER_HANDLE_ULP0 +
2503 (ulp_num * MEM_DESCR_OFFSET));
2504 phba->mem_req[mem_descr_index] =
2505 BEISCSI_GET_CID_COUNT(phba, ulp_num) *
2506 sizeof(struct async_pdu_handle);
2508 mem_descr_index = (HWI_MEM_ASYNC_DATA_HANDLE_ULP0 +
2509 (ulp_num * MEM_DESCR_OFFSET));
2510 phba->mem_req[mem_descr_index] =
2511 BEISCSI_GET_CID_COUNT(phba, ulp_num) *
2512 sizeof(struct async_pdu_handle);
2514 mem_descr_index = (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0 +
2515 (ulp_num * MEM_DESCR_OFFSET));
2516 phba->mem_req[mem_descr_index] =
2517 sizeof(struct hwi_async_pdu_context) +
2518 (BEISCSI_GET_CID_COUNT(phba, ulp_num) *
2519 sizeof(struct hwi_async_entry));
2524 static int beiscsi_alloc_mem(struct beiscsi_hba *phba)
2527 struct hwi_controller *phwi_ctrlr;
2528 struct be_mem_descriptor *mem_descr;
2529 struct mem_array *mem_arr, *mem_arr_orig;
2530 unsigned int i, j, alloc_size, curr_alloc_size;
2532 phba->phwi_ctrlr = kzalloc(phba->params.hwi_ws_sz, GFP_KERNEL);
2533 if (!phba->phwi_ctrlr)
2536 /* Allocate memory for wrb_context */
2537 phwi_ctrlr = phba->phwi_ctrlr;
2538 phwi_ctrlr->wrb_context = kzalloc(sizeof(struct hwi_wrb_context) *
2539 phba->params.cxns_per_ctrl,
2541 if (!phwi_ctrlr->wrb_context) {
2542 kfree(phba->phwi_ctrlr);
2546 phba->init_mem = kcalloc(SE_MEM_MAX, sizeof(*mem_descr),
2548 if (!phba->init_mem) {
2549 kfree(phwi_ctrlr->wrb_context);
2550 kfree(phba->phwi_ctrlr);
2554 mem_arr_orig = kmalloc(sizeof(*mem_arr_orig) * BEISCSI_MAX_FRAGS_INIT,
2556 if (!mem_arr_orig) {
2557 kfree(phba->init_mem);
2558 kfree(phwi_ctrlr->wrb_context);
2559 kfree(phba->phwi_ctrlr);
2563 mem_descr = phba->init_mem;
2564 for (i = 0; i < SE_MEM_MAX; i++) {
2565 if (!phba->mem_req[i]) {
2566 mem_descr->mem_array = NULL;
2572 mem_arr = mem_arr_orig;
2573 alloc_size = phba->mem_req[i];
2574 memset(mem_arr, 0, sizeof(struct mem_array) *
2575 BEISCSI_MAX_FRAGS_INIT);
2576 curr_alloc_size = min(be_max_phys_size * 1024, alloc_size);
2578 mem_arr->virtual_address = pci_alloc_consistent(
2582 if (!mem_arr->virtual_address) {
2583 if (curr_alloc_size <= BE_MIN_MEM_SIZE)
2585 if (curr_alloc_size -
2586 rounddown_pow_of_two(curr_alloc_size))
2587 curr_alloc_size = rounddown_pow_of_two
2590 curr_alloc_size = curr_alloc_size / 2;
2592 mem_arr->bus_address.u.
2593 a64.address = (__u64) bus_add;
2594 mem_arr->size = curr_alloc_size;
2595 alloc_size -= curr_alloc_size;
2596 curr_alloc_size = min(be_max_phys_size *
2601 } while (alloc_size);
2602 mem_descr->num_elements = j;
2603 mem_descr->size_in_bytes = phba->mem_req[i];
2604 mem_descr->mem_array = kmalloc(sizeof(*mem_arr) * j,
2606 if (!mem_descr->mem_array)
2609 memcpy(mem_descr->mem_array, mem_arr_orig,
2610 sizeof(struct mem_array) * j);
2613 kfree(mem_arr_orig);
2616 mem_descr->num_elements = j;
2617 while ((i) || (j)) {
2618 for (j = mem_descr->num_elements; j > 0; j--) {
2619 pci_free_consistent(phba->pcidev,
2620 mem_descr->mem_array[j - 1].size,
2621 mem_descr->mem_array[j - 1].
2623 (unsigned long)mem_descr->
2625 bus_address.u.a64.address);
2629 kfree(mem_descr->mem_array);
2633 kfree(mem_arr_orig);
2634 kfree(phba->init_mem);
2635 kfree(phba->phwi_ctrlr->wrb_context);
2636 kfree(phba->phwi_ctrlr);
2640 static int beiscsi_get_memory(struct beiscsi_hba *phba)
2642 beiscsi_find_mem_req(phba);
2643 return beiscsi_alloc_mem(phba);
2646 static void iscsi_init_global_templates(struct beiscsi_hba *phba)
2648 struct pdu_data_out *pdata_out;
2649 struct pdu_nop_out *pnop_out;
2650 struct be_mem_descriptor *mem_descr;
2652 mem_descr = phba->init_mem;
2653 mem_descr += ISCSI_MEM_GLOBAL_HEADER;
2655 (struct pdu_data_out *)mem_descr->mem_array[0].virtual_address;
2656 memset(pdata_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
2658 AMAP_SET_BITS(struct amap_pdu_data_out, opcode, pdata_out,
2662 (struct pdu_nop_out *)((unsigned char *)mem_descr->mem_array[0].
2663 virtual_address + BE_ISCSI_PDU_HEADER_SIZE);
2665 memset(pnop_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
2666 AMAP_SET_BITS(struct amap_pdu_nop_out, ttt, pnop_out, 0xFFFFFFFF);
2667 AMAP_SET_BITS(struct amap_pdu_nop_out, f_bit, pnop_out, 1);
2668 AMAP_SET_BITS(struct amap_pdu_nop_out, i_bit, pnop_out, 0);
2671 static int beiscsi_init_wrb_handle(struct beiscsi_hba *phba)
2673 struct be_mem_descriptor *mem_descr_wrbh, *mem_descr_wrb;
2674 struct hwi_context_memory *phwi_ctxt;
2675 struct wrb_handle *pwrb_handle = NULL;
2676 struct hwi_controller *phwi_ctrlr;
2677 struct hwi_wrb_context *pwrb_context;
2678 struct iscsi_wrb *pwrb = NULL;
2679 unsigned int num_cxn_wrbh = 0;
2680 unsigned int num_cxn_wrb = 0, j, idx = 0, index;
2682 mem_descr_wrbh = phba->init_mem;
2683 mem_descr_wrbh += HWI_MEM_WRBH;
2685 mem_descr_wrb = phba->init_mem;
2686 mem_descr_wrb += HWI_MEM_WRB;
2687 phwi_ctrlr = phba->phwi_ctrlr;
2689 /* Allocate memory for WRBQ */
2690 phwi_ctxt = phwi_ctrlr->phwi_ctxt;
2691 phwi_ctxt->be_wrbq = kzalloc(sizeof(struct be_queue_info) *
2692 phba->params.cxns_per_ctrl,
2694 if (!phwi_ctxt->be_wrbq) {
2695 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2696 "BM_%d : WRBQ Mem Alloc Failed\n");
2700 for (index = 0; index < phba->params.cxns_per_ctrl; index++) {
2701 pwrb_context = &phwi_ctrlr->wrb_context[index];
2702 pwrb_context->pwrb_handle_base =
2703 kzalloc(sizeof(struct wrb_handle *) *
2704 phba->params.wrbs_per_cxn, GFP_KERNEL);
2705 if (!pwrb_context->pwrb_handle_base) {
2706 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2707 "BM_%d : Mem Alloc Failed. Failing to load\n");
2708 goto init_wrb_hndl_failed;
2710 pwrb_context->pwrb_handle_basestd =
2711 kzalloc(sizeof(struct wrb_handle *) *
2712 phba->params.wrbs_per_cxn, GFP_KERNEL);
2713 if (!pwrb_context->pwrb_handle_basestd) {
2714 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2715 "BM_%d : Mem Alloc Failed. Failing to load\n");
2716 goto init_wrb_hndl_failed;
2718 if (!num_cxn_wrbh) {
2720 mem_descr_wrbh->mem_array[idx].virtual_address;
2721 num_cxn_wrbh = ((mem_descr_wrbh->mem_array[idx].size) /
2722 ((sizeof(struct wrb_handle)) *
2723 phba->params.wrbs_per_cxn));
2726 pwrb_context->alloc_index = 0;
2727 pwrb_context->wrb_handles_available = 0;
2728 pwrb_context->free_index = 0;
2731 for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
2732 pwrb_context->pwrb_handle_base[j] = pwrb_handle;
2733 pwrb_context->pwrb_handle_basestd[j] =
2735 pwrb_context->wrb_handles_available++;
2736 pwrb_handle->wrb_index = j;
2741 spin_lock_init(&pwrb_context->wrb_lock);
2744 for (index = 0; index < phba->params.cxns_per_ctrl; index++) {
2745 pwrb_context = &phwi_ctrlr->wrb_context[index];
2747 pwrb = mem_descr_wrb->mem_array[idx].virtual_address;
2748 num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) /
2749 ((sizeof(struct iscsi_wrb) *
2750 phba->params.wrbs_per_cxn));
2755 for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
2756 pwrb_handle = pwrb_context->pwrb_handle_base[j];
2757 pwrb_handle->pwrb = pwrb;
2764 init_wrb_hndl_failed:
2765 for (j = index; j > 0; j--) {
2766 pwrb_context = &phwi_ctrlr->wrb_context[j];
2767 kfree(pwrb_context->pwrb_handle_base);
2768 kfree(pwrb_context->pwrb_handle_basestd);
2773 static int hwi_init_async_pdu_ctx(struct beiscsi_hba *phba)
2776 struct hwi_controller *phwi_ctrlr;
2777 struct hba_parameters *p = &phba->params;
2778 struct hwi_async_pdu_context *pasync_ctx;
2779 struct async_pdu_handle *pasync_header_h, *pasync_data_h;
2780 unsigned int index, idx, num_per_mem, num_async_data;
2781 struct be_mem_descriptor *mem_descr;
2783 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
2784 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
2786 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2787 mem_descr += (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0 +
2788 (ulp_num * MEM_DESCR_OFFSET));
2790 phwi_ctrlr = phba->phwi_ctrlr;
2791 phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num] =
2792 (struct hwi_async_pdu_context *)
2793 mem_descr->mem_array[0].virtual_address;
2795 pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num];
2796 memset(pasync_ctx, 0, sizeof(*pasync_ctx));
2798 pasync_ctx->async_entry =
2799 (struct hwi_async_entry *)
2800 ((long unsigned int)pasync_ctx +
2801 sizeof(struct hwi_async_pdu_context));
2803 pasync_ctx->num_entries = BEISCSI_GET_CID_COUNT(phba,
2805 pasync_ctx->buffer_size = p->defpdu_hdr_sz;
2807 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2808 mem_descr += HWI_MEM_ASYNC_HEADER_BUF_ULP0 +
2809 (ulp_num * MEM_DESCR_OFFSET);
2810 if (mem_descr->mem_array[0].virtual_address) {
2811 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2812 "BM_%d : hwi_init_async_pdu_ctx"
2813 " HWI_MEM_ASYNC_HEADER_BUF_ULP%d va=%p\n",
2815 mem_descr->mem_array[0].
2818 beiscsi_log(phba, KERN_WARNING,
2820 "BM_%d : No Virtual address for ULP : %d\n",
2823 pasync_ctx->async_header.va_base =
2824 mem_descr->mem_array[0].virtual_address;
2826 pasync_ctx->async_header.pa_base.u.a64.address =
2827 mem_descr->mem_array[0].
2828 bus_address.u.a64.address;
2830 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2831 mem_descr += HWI_MEM_ASYNC_HEADER_RING_ULP0 +
2832 (ulp_num * MEM_DESCR_OFFSET);
2833 if (mem_descr->mem_array[0].virtual_address) {
2834 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2835 "BM_%d : hwi_init_async_pdu_ctx"
2836 " HWI_MEM_ASYNC_HEADER_RING_ULP%d va=%p\n",
2838 mem_descr->mem_array[0].
2841 beiscsi_log(phba, KERN_WARNING,
2843 "BM_%d : No Virtual address for ULP : %d\n",
2846 pasync_ctx->async_header.ring_base =
2847 mem_descr->mem_array[0].virtual_address;
2849 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2850 mem_descr += HWI_MEM_ASYNC_HEADER_HANDLE_ULP0 +
2851 (ulp_num * MEM_DESCR_OFFSET);
2852 if (mem_descr->mem_array[0].virtual_address) {
2853 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2854 "BM_%d : hwi_init_async_pdu_ctx"
2855 " HWI_MEM_ASYNC_HEADER_HANDLE_ULP%d va=%p\n",
2857 mem_descr->mem_array[0].
2860 beiscsi_log(phba, KERN_WARNING,
2862 "BM_%d : No Virtual address for ULP : %d\n",
2865 pasync_ctx->async_header.handle_base =
2866 mem_descr->mem_array[0].virtual_address;
2867 pasync_ctx->async_header.writables = 0;
2868 INIT_LIST_HEAD(&pasync_ctx->async_header.free_list);
2870 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2871 mem_descr += HWI_MEM_ASYNC_DATA_RING_ULP0 +
2872 (ulp_num * MEM_DESCR_OFFSET);
2873 if (mem_descr->mem_array[0].virtual_address) {
2874 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2875 "BM_%d : hwi_init_async_pdu_ctx"
2876 " HWI_MEM_ASYNC_DATA_RING_ULP%d va=%p\n",
2878 mem_descr->mem_array[0].
2881 beiscsi_log(phba, KERN_WARNING,
2883 "BM_%d : No Virtual address for ULP : %d\n",
2886 pasync_ctx->async_data.ring_base =
2887 mem_descr->mem_array[0].virtual_address;
2889 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2890 mem_descr += HWI_MEM_ASYNC_DATA_HANDLE_ULP0 +
2891 (ulp_num * MEM_DESCR_OFFSET);
2892 if (!mem_descr->mem_array[0].virtual_address)
2893 beiscsi_log(phba, KERN_WARNING,
2895 "BM_%d : No Virtual address for ULP : %d\n",
2898 pasync_ctx->async_data.handle_base =
2899 mem_descr->mem_array[0].virtual_address;
2900 pasync_ctx->async_data.writables = 0;
2901 INIT_LIST_HEAD(&pasync_ctx->async_data.free_list);
2904 (struct async_pdu_handle *)
2905 pasync_ctx->async_header.handle_base;
2907 (struct async_pdu_handle *)
2908 pasync_ctx->async_data.handle_base;
2910 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2911 mem_descr += HWI_MEM_ASYNC_DATA_BUF_ULP0 +
2912 (ulp_num * MEM_DESCR_OFFSET);
2913 if (mem_descr->mem_array[0].virtual_address) {
2914 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2915 "BM_%d : hwi_init_async_pdu_ctx"
2916 " HWI_MEM_ASYNC_DATA_BUF_ULP%d va=%p\n",
2918 mem_descr->mem_array[0].
2921 beiscsi_log(phba, KERN_WARNING,
2923 "BM_%d : No Virtual address for ULP : %d\n",
2927 pasync_ctx->async_data.va_base =
2928 mem_descr->mem_array[idx].virtual_address;
2929 pasync_ctx->async_data.pa_base.u.a64.address =
2930 mem_descr->mem_array[idx].
2931 bus_address.u.a64.address;
2933 num_async_data = ((mem_descr->mem_array[idx].size) /
2934 phba->params.defpdu_data_sz);
2937 for (index = 0; index < BEISCSI_GET_CID_COUNT
2938 (phba, ulp_num); index++) {
2939 pasync_header_h->cri = -1;
2940 pasync_header_h->index = (char)index;
2941 INIT_LIST_HEAD(&pasync_header_h->link);
2942 pasync_header_h->pbuffer =
2943 (void *)((unsigned long)
2945 async_header.va_base) +
2946 (p->defpdu_hdr_sz * index));
2948 pasync_header_h->pa.u.a64.address =
2949 pasync_ctx->async_header.pa_base.u.a64.
2950 address + (p->defpdu_hdr_sz * index);
2952 list_add_tail(&pasync_header_h->link,
2953 &pasync_ctx->async_header.
2956 pasync_ctx->async_header.free_entries++;
2957 pasync_ctx->async_header.writables++;
2959 INIT_LIST_HEAD(&pasync_ctx->async_entry[index].
2961 INIT_LIST_HEAD(&pasync_ctx->async_entry[index].
2963 pasync_data_h->cri = -1;
2964 pasync_data_h->index = (char)index;
2965 INIT_LIST_HEAD(&pasync_data_h->link);
2967 if (!num_async_data) {
2970 pasync_ctx->async_data.va_base =
2971 mem_descr->mem_array[idx].
2973 pasync_ctx->async_data.pa_base.u.
2975 mem_descr->mem_array[idx].
2976 bus_address.u.a64.address;
2978 ((mem_descr->mem_array[idx].
2980 phba->params.defpdu_data_sz);
2982 pasync_data_h->pbuffer =
2983 (void *)((unsigned long)
2984 (pasync_ctx->async_data.va_base) +
2985 (p->defpdu_data_sz * num_per_mem));
2987 pasync_data_h->pa.u.a64.address =
2988 pasync_ctx->async_data.pa_base.u.a64.
2989 address + (p->defpdu_data_sz *
2994 list_add_tail(&pasync_data_h->link,
2995 &pasync_ctx->async_data.
2998 pasync_ctx->async_data.free_entries++;
2999 pasync_ctx->async_data.writables++;
3001 INIT_LIST_HEAD(&pasync_ctx->async_entry[index].
3005 pasync_ctx->async_header.host_write_ptr = 0;
3006 pasync_ctx->async_header.ep_read_ptr = -1;
3007 pasync_ctx->async_data.host_write_ptr = 0;
3008 pasync_ctx->async_data.ep_read_ptr = -1;
3016 be_sgl_create_contiguous(void *virtual_address,
3017 u64 physical_address, u32 length,
3018 struct be_dma_mem *sgl)
3020 WARN_ON(!virtual_address);
3021 WARN_ON(!physical_address);
3025 sgl->va = virtual_address;
3026 sgl->dma = (unsigned long)physical_address;
3032 static void be_sgl_destroy_contiguous(struct be_dma_mem *sgl)
3034 memset(sgl, 0, sizeof(*sgl));
3038 hwi_build_be_sgl_arr(struct beiscsi_hba *phba,
3039 struct mem_array *pmem, struct be_dma_mem *sgl)
3042 be_sgl_destroy_contiguous(sgl);
3044 be_sgl_create_contiguous(pmem->virtual_address,
3045 pmem->bus_address.u.a64.address,
3050 hwi_build_be_sgl_by_offset(struct beiscsi_hba *phba,
3051 struct mem_array *pmem, struct be_dma_mem *sgl)
3054 be_sgl_destroy_contiguous(sgl);
3056 be_sgl_create_contiguous((unsigned char *)pmem->virtual_address,
3057 pmem->bus_address.u.a64.address,
3061 static int be_fill_queue(struct be_queue_info *q,
3062 u16 len, u16 entry_size, void *vaddress)
3064 struct be_dma_mem *mem = &q->dma_mem;
3066 memset(q, 0, sizeof(*q));
3068 q->entry_size = entry_size;
3069 mem->size = len * entry_size;
3073 memset(mem->va, 0, mem->size);
3077 static int beiscsi_create_eqs(struct beiscsi_hba *phba,
3078 struct hwi_context_memory *phwi_context)
3080 unsigned int i, num_eq_pages;
3081 int ret = 0, eq_for_mcc;
3082 struct be_queue_info *eq;
3083 struct be_dma_mem *mem;
3087 num_eq_pages = PAGES_REQUIRED(phba->params.num_eq_entries * \
3088 sizeof(struct be_eq_entry));
3090 if (phba->msix_enabled)
3094 for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
3095 eq = &phwi_context->be_eq[i].q;
3097 phwi_context->be_eq[i].phba = phba;
3098 eq_vaddress = pci_alloc_consistent(phba->pcidev,
3099 num_eq_pages * PAGE_SIZE,
3102 goto create_eq_error;
3104 mem->va = eq_vaddress;
3105 ret = be_fill_queue(eq, phba->params.num_eq_entries,
3106 sizeof(struct be_eq_entry), eq_vaddress);
3108 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3109 "BM_%d : be_fill_queue Failed for EQ\n");
3110 goto create_eq_error;
3114 ret = beiscsi_cmd_eq_create(&phba->ctrl, eq,
3115 phwi_context->cur_eqd);
3117 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3118 "BM_%d : beiscsi_cmd_eq_create"
3120 goto create_eq_error;
3123 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3124 "BM_%d : eqid = %d\n",
3125 phwi_context->be_eq[i].q.id);
3129 for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
3130 eq = &phwi_context->be_eq[i].q;
3133 pci_free_consistent(phba->pcidev, num_eq_pages
3140 static int beiscsi_create_cqs(struct beiscsi_hba *phba,
3141 struct hwi_context_memory *phwi_context)
3143 unsigned int i, num_cq_pages;
3145 struct be_queue_info *cq, *eq;
3146 struct be_dma_mem *mem;
3147 struct be_eq_obj *pbe_eq;
3151 num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
3152 sizeof(struct sol_cqe));
3154 for (i = 0; i < phba->num_cpus; i++) {
3155 cq = &phwi_context->be_cq[i];
3156 eq = &phwi_context->be_eq[i].q;
3157 pbe_eq = &phwi_context->be_eq[i];
3159 pbe_eq->phba = phba;
3161 cq_vaddress = pci_alloc_consistent(phba->pcidev,
3162 num_cq_pages * PAGE_SIZE,
3165 goto create_cq_error;
3166 ret = be_fill_queue(cq, phba->params.num_cq_entries,
3167 sizeof(struct sol_cqe), cq_vaddress);
3169 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3170 "BM_%d : be_fill_queue Failed "
3172 goto create_cq_error;
3176 ret = beiscsi_cmd_cq_create(&phba->ctrl, cq, eq, false,
3179 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3180 "BM_%d : beiscsi_cmd_eq_create"
3181 "Failed for ISCSI CQ\n");
3182 goto create_cq_error;
3184 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3185 "BM_%d : iscsi cq_id is %d for eq_id %d\n"
3186 "iSCSI CQ CREATED\n", cq->id, eq->id);
3191 for (i = 0; i < phba->num_cpus; i++) {
3192 cq = &phwi_context->be_cq[i];
3195 pci_free_consistent(phba->pcidev, num_cq_pages
3204 beiscsi_create_def_hdr(struct beiscsi_hba *phba,
3205 struct hwi_context_memory *phwi_context,
3206 struct hwi_controller *phwi_ctrlr,
3207 unsigned int def_pdu_ring_sz, uint8_t ulp_num)
3211 struct be_queue_info *dq, *cq;
3212 struct be_dma_mem *mem;
3213 struct be_mem_descriptor *mem_descr;
3217 dq = &phwi_context->be_def_hdrq[ulp_num];
3218 cq = &phwi_context->be_cq[0];
3220 mem_descr = phba->init_mem;
3221 mem_descr += HWI_MEM_ASYNC_HEADER_RING_ULP0 +
3222 (ulp_num * MEM_DESCR_OFFSET);
3223 dq_vaddress = mem_descr->mem_array[idx].virtual_address;
3224 ret = be_fill_queue(dq, mem_descr->mem_array[0].size /
3225 sizeof(struct phys_addr),
3226 sizeof(struct phys_addr), dq_vaddress);
3228 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3229 "BM_%d : be_fill_queue Failed for DEF PDU HDR on ULP : %d\n",
3234 mem->dma = (unsigned long)mem_descr->mem_array[idx].
3235 bus_address.u.a64.address;
3236 ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dq,
3238 phba->params.defpdu_hdr_sz,
3239 BEISCSI_DEFQ_HDR, ulp_num);
3241 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3242 "BM_%d : be_cmd_create_default_pdu_queue Failed DEFHDR on ULP : %d\n",
3248 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3249 "BM_%d : iscsi hdr def pdu id for ULP : %d is %d\n",
3251 phwi_context->be_def_hdrq[ulp_num].id);
3256 beiscsi_create_def_data(struct beiscsi_hba *phba,
3257 struct hwi_context_memory *phwi_context,
3258 struct hwi_controller *phwi_ctrlr,
3259 unsigned int def_pdu_ring_sz, uint8_t ulp_num)
3263 struct be_queue_info *dataq, *cq;
3264 struct be_dma_mem *mem;
3265 struct be_mem_descriptor *mem_descr;
3269 dataq = &phwi_context->be_def_dataq[ulp_num];
3270 cq = &phwi_context->be_cq[0];
3271 mem = &dataq->dma_mem;
3272 mem_descr = phba->init_mem;
3273 mem_descr += HWI_MEM_ASYNC_DATA_RING_ULP0 +
3274 (ulp_num * MEM_DESCR_OFFSET);
3275 dq_vaddress = mem_descr->mem_array[idx].virtual_address;
3276 ret = be_fill_queue(dataq, mem_descr->mem_array[0].size /
3277 sizeof(struct phys_addr),
3278 sizeof(struct phys_addr), dq_vaddress);
3280 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3281 "BM_%d : be_fill_queue Failed for DEF PDU "
3282 "DATA on ULP : %d\n",
3287 mem->dma = (unsigned long)mem_descr->mem_array[idx].
3288 bus_address.u.a64.address;
3289 ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dataq,
3291 phba->params.defpdu_data_sz,
3292 BEISCSI_DEFQ_DATA, ulp_num);
3294 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3295 "BM_%d be_cmd_create_default_pdu_queue"
3296 " Failed for DEF PDU DATA on ULP : %d\n",
3301 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3302 "BM_%d : iscsi def data id on ULP : %d is %d\n",
3304 phwi_context->be_def_dataq[ulp_num].id);
3306 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3307 "BM_%d : DEFAULT PDU DATA RING CREATED"
3308 "on ULP : %d\n", ulp_num);
3314 beiscsi_post_template_hdr(struct beiscsi_hba *phba)
3316 struct be_mem_descriptor *mem_descr;
3317 struct mem_array *pm_arr;
3318 struct be_dma_mem sgl;
3319 int status, ulp_num;
3321 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
3322 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
3323 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
3324 mem_descr += HWI_MEM_TEMPLATE_HDR_ULP0 +
3325 (ulp_num * MEM_DESCR_OFFSET);
3326 pm_arr = mem_descr->mem_array;
3328 hwi_build_be_sgl_arr(phba, pm_arr, &sgl);
3329 status = be_cmd_iscsi_post_template_hdr(
3333 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3334 "BM_%d : Post Template HDR Failed for"
3335 "ULP_%d\n", ulp_num);
3339 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3340 "BM_%d : Template HDR Pages Posted for"
3341 "ULP_%d\n", ulp_num);
3348 beiscsi_post_pages(struct beiscsi_hba *phba)
3350 struct be_mem_descriptor *mem_descr;
3351 struct mem_array *pm_arr;
3352 unsigned int page_offset, i;
3353 struct be_dma_mem sgl;
3354 int status, ulp_num = 0;
3356 mem_descr = phba->init_mem;
3357 mem_descr += HWI_MEM_SGE;
3358 pm_arr = mem_descr->mem_array;
3360 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
3361 if (test_bit(ulp_num, &phba->fw_config.ulp_supported))
3364 page_offset = (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io *
3365 phba->fw_config.iscsi_icd_start[ulp_num]) / PAGE_SIZE;
3366 for (i = 0; i < mem_descr->num_elements; i++) {
3367 hwi_build_be_sgl_arr(phba, pm_arr, &sgl);
3368 status = be_cmd_iscsi_post_sgl_pages(&phba->ctrl, &sgl,
3370 (pm_arr->size / PAGE_SIZE));
3371 page_offset += pm_arr->size / PAGE_SIZE;
3373 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3374 "BM_%d : post sgl failed.\n");
3379 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3380 "BM_%d : POSTED PAGES\n");
3384 static void be_queue_free(struct beiscsi_hba *phba, struct be_queue_info *q)
3386 struct be_dma_mem *mem = &q->dma_mem;
3388 pci_free_consistent(phba->pcidev, mem->size,
3394 static int be_queue_alloc(struct beiscsi_hba *phba, struct be_queue_info *q,
3395 u16 len, u16 entry_size)
3397 struct be_dma_mem *mem = &q->dma_mem;
3399 memset(q, 0, sizeof(*q));
3401 q->entry_size = entry_size;
3402 mem->size = len * entry_size;
3403 mem->va = pci_zalloc_consistent(phba->pcidev, mem->size, &mem->dma);
3410 beiscsi_create_wrb_rings(struct beiscsi_hba *phba,
3411 struct hwi_context_memory *phwi_context,
3412 struct hwi_controller *phwi_ctrlr)
3414 unsigned int wrb_mem_index, offset, size, num_wrb_rings;
3416 unsigned int idx, num, i, ulp_num;
3417 struct mem_array *pwrb_arr;
3419 struct be_dma_mem sgl;
3420 struct be_mem_descriptor *mem_descr;
3421 struct hwi_wrb_context *pwrb_context;
3423 uint8_t ulp_count = 0, ulp_base_num = 0;
3424 uint16_t cid_count_ulp[BEISCSI_ULP_COUNT] = { 0 };
3427 mem_descr = phba->init_mem;
3428 mem_descr += HWI_MEM_WRB;
3429 pwrb_arr = kmalloc(sizeof(*pwrb_arr) * phba->params.cxns_per_ctrl,
3432 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3433 "BM_%d : Memory alloc failed in create wrb ring.\n");
3436 wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
3437 pa_addr_lo = mem_descr->mem_array[idx].bus_address.u.a64.address;
3438 num_wrb_rings = mem_descr->mem_array[idx].size /
3439 (phba->params.wrbs_per_cxn * sizeof(struct iscsi_wrb));
3441 for (num = 0; num < phba->params.cxns_per_ctrl; num++) {
3442 if (num_wrb_rings) {
3443 pwrb_arr[num].virtual_address = wrb_vaddr;
3444 pwrb_arr[num].bus_address.u.a64.address = pa_addr_lo;
3445 pwrb_arr[num].size = phba->params.wrbs_per_cxn *
3446 sizeof(struct iscsi_wrb);
3447 wrb_vaddr += pwrb_arr[num].size;
3448 pa_addr_lo += pwrb_arr[num].size;
3452 wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
3453 pa_addr_lo = mem_descr->mem_array[idx].\
3454 bus_address.u.a64.address;
3455 num_wrb_rings = mem_descr->mem_array[idx].size /
3456 (phba->params.wrbs_per_cxn *
3457 sizeof(struct iscsi_wrb));
3458 pwrb_arr[num].virtual_address = wrb_vaddr;
3459 pwrb_arr[num].bus_address.u.a64.address\
3461 pwrb_arr[num].size = phba->params.wrbs_per_cxn *
3462 sizeof(struct iscsi_wrb);
3463 wrb_vaddr += pwrb_arr[num].size;
3464 pa_addr_lo += pwrb_arr[num].size;
3469 /* Get the ULP Count */
3470 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
3471 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
3473 ulp_base_num = ulp_num;
3474 cid_count_ulp[ulp_num] =
3475 BEISCSI_GET_CID_COUNT(phba, ulp_num);
3478 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
3483 if (ulp_count > 1) {
3484 ulp_base_num = (ulp_base_num + 1) % BEISCSI_ULP_COUNT;
3486 if (!cid_count_ulp[ulp_base_num])
3487 ulp_base_num = (ulp_base_num + 1) %
3490 cid_count_ulp[ulp_base_num]--;
3494 hwi_build_be_sgl_by_offset(phba, &pwrb_arr[i], &sgl);
3495 status = be_cmd_wrbq_create(&phba->ctrl, &sgl,
3496 &phwi_context->be_wrbq[i],
3497 &phwi_ctrlr->wrb_context[i],
3500 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3501 "BM_%d : wrbq create failed.");
3505 pwrb_context = &phwi_ctrlr->wrb_context[i];
3506 BE_SET_CID_TO_CRI(i, pwrb_context->cid);
3512 static void free_wrb_handles(struct beiscsi_hba *phba)
3515 struct hwi_controller *phwi_ctrlr;
3516 struct hwi_wrb_context *pwrb_context;
3518 phwi_ctrlr = phba->phwi_ctrlr;
3519 for (index = 0; index < phba->params.cxns_per_ctrl; index++) {
3520 pwrb_context = &phwi_ctrlr->wrb_context[index];
3521 kfree(pwrb_context->pwrb_handle_base);
3522 kfree(pwrb_context->pwrb_handle_basestd);
3526 static void be_mcc_queues_destroy(struct beiscsi_hba *phba)
3528 struct be_ctrl_info *ctrl = &phba->ctrl;
3529 struct be_dma_mem *ptag_mem;
3530 struct be_queue_info *q;
3533 q = &phba->ctrl.mcc_obj.q;
3534 for (i = 0; i < MAX_MCC_CMD; i++) {
3536 if (!test_bit(MCC_TAG_STATE_RUNNING,
3537 &ctrl->ptag_state[tag].tag_state))
3540 if (test_bit(MCC_TAG_STATE_TIMEOUT,
3541 &ctrl->ptag_state[tag].tag_state)) {
3542 ptag_mem = &ctrl->ptag_state[tag].tag_mem_state;
3543 if (ptag_mem->size) {
3544 pci_free_consistent(ctrl->pdev,
3553 * If MCC is still active and waiting then wake up the process.
3554 * We are here only because port is going offline. The process
3555 * sees that (BEISCSI_HBA_ONLINE is cleared) and EIO error is
3556 * returned for the operation and allocated memory cleaned up.
3558 if (waitqueue_active(&ctrl->mcc_wait[tag])) {
3559 ctrl->mcc_tag_status[tag] = MCC_STATUS_FAILED;
3560 ctrl->mcc_tag_status[tag] |= CQE_VALID_MASK;
3561 wake_up_interruptible(&ctrl->mcc_wait[tag]);
3563 * Control tag info gets reinitialized in enable
3564 * so wait for the process to clear running state.
3566 while (test_bit(MCC_TAG_STATE_RUNNING,
3567 &ctrl->ptag_state[tag].tag_state))
3568 schedule_timeout_uninterruptible(HZ);
3571 * For MCC with tag_states MCC_TAG_STATE_ASYNC and
3572 * MCC_TAG_STATE_IGNORE nothing needs to done.
3576 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_MCCQ);
3577 be_queue_free(phba, q);
3580 q = &phba->ctrl.mcc_obj.cq;
3582 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
3583 be_queue_free(phba, q);
3587 static int be_mcc_queues_create(struct beiscsi_hba *phba,
3588 struct hwi_context_memory *phwi_context)
3590 struct be_queue_info *q, *cq;
3591 struct be_ctrl_info *ctrl = &phba->ctrl;
3593 /* Alloc MCC compl queue */
3594 cq = &phba->ctrl.mcc_obj.cq;
3595 if (be_queue_alloc(phba, cq, MCC_CQ_LEN,
3596 sizeof(struct be_mcc_compl)))
3598 /* Ask BE to create MCC compl queue; */
3599 if (phba->msix_enabled) {
3600 if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq
3601 [phba->num_cpus].q, false, true, 0))
3604 if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq[0].q,
3609 /* Alloc MCC queue */
3610 q = &phba->ctrl.mcc_obj.q;
3611 if (be_queue_alloc(phba, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb)))
3612 goto mcc_cq_destroy;
3614 /* Ask BE to create MCC queue */
3615 if (beiscsi_cmd_mccq_create(phba, q, cq))
3621 be_queue_free(phba, q);
3623 beiscsi_cmd_q_destroy(ctrl, cq, QTYPE_CQ);
3625 be_queue_free(phba, cq);
3631 * find_num_cpus()- Get the CPU online count
3632 * @phba: ptr to priv structure
3634 * CPU count is used for creating EQ.
3636 static void find_num_cpus(struct beiscsi_hba *phba)
3640 num_cpus = num_online_cpus();
3642 switch (phba->generation) {
3645 phba->num_cpus = (num_cpus > BEISCSI_MAX_NUM_CPUS) ?
3646 BEISCSI_MAX_NUM_CPUS : num_cpus;
3650 * If eqid_count == 1 fall back to
3653 if (phba->fw_config.eqid_count == 1) {
3660 (num_cpus > (phba->fw_config.eqid_count - 1)) ?
3661 (phba->fw_config.eqid_count - 1) : num_cpus;
3668 static void hwi_purge_eq(struct beiscsi_hba *phba)
3670 struct hwi_controller *phwi_ctrlr;
3671 struct hwi_context_memory *phwi_context;
3672 struct be_queue_info *eq;
3673 struct be_eq_entry *eqe = NULL;
3675 unsigned int num_processed;
3677 if (beiscsi_hba_in_error(phba))
3680 phwi_ctrlr = phba->phwi_ctrlr;
3681 phwi_context = phwi_ctrlr->phwi_ctxt;
3682 if (phba->msix_enabled)
3687 for (i = 0; i < (phba->num_cpus + eq_msix); i++) {
3688 eq = &phwi_context->be_eq[i].q;
3689 eqe = queue_tail_node(eq);
3691 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
3693 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
3695 eqe = queue_tail_node(eq);
3700 hwi_ring_eq_db(phba, eq->id, 1, num_processed, 1, 1);
3704 static void hwi_cleanup_port(struct beiscsi_hba *phba)
3706 struct be_queue_info *q;
3707 struct be_ctrl_info *ctrl = &phba->ctrl;
3708 struct hwi_controller *phwi_ctrlr;
3709 struct hwi_context_memory *phwi_context;
3710 struct hwi_async_pdu_context *pasync_ctx;
3711 int i, eq_for_mcc, ulp_num;
3713 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
3714 if (test_bit(ulp_num, &phba->fw_config.ulp_supported))
3715 beiscsi_cmd_iscsi_cleanup(phba, ulp_num);
3718 * Purge all EQ entries that may have been left out. This is to
3719 * workaround a problem we've seen occasionally where driver gets an
3720 * interrupt with EQ entry bit set after stopping the controller.
3724 phwi_ctrlr = phba->phwi_ctrlr;
3725 phwi_context = phwi_ctrlr->phwi_ctxt;
3727 be_cmd_iscsi_remove_template_hdr(ctrl);
3729 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
3730 q = &phwi_context->be_wrbq[i];
3732 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_WRBQ);
3734 kfree(phwi_context->be_wrbq);
3735 free_wrb_handles(phba);
3737 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
3738 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
3740 q = &phwi_context->be_def_hdrq[ulp_num];
3742 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
3744 q = &phwi_context->be_def_dataq[ulp_num];
3746 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
3748 pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num];
3752 beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
3754 for (i = 0; i < (phba->num_cpus); i++) {
3755 q = &phwi_context->be_cq[i];
3757 be_queue_free(phba, q);
3758 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
3762 be_mcc_queues_destroy(phba);
3763 if (phba->msix_enabled)
3767 for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
3768 q = &phwi_context->be_eq[i].q;
3770 be_queue_free(phba, q);
3771 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_EQ);
3774 /* last communication, indicate driver is unloading */
3775 beiscsi_cmd_special_wrb(&phba->ctrl, 0);
3777 static int hwi_init_port(struct beiscsi_hba *phba)
3779 struct hwi_controller *phwi_ctrlr;
3780 struct hwi_context_memory *phwi_context;
3781 unsigned int def_pdu_ring_sz;
3782 struct be_ctrl_info *ctrl = &phba->ctrl;
3783 int status, ulp_num;
3785 phwi_ctrlr = phba->phwi_ctrlr;
3786 phwi_context = phwi_ctrlr->phwi_ctxt;
3787 phwi_context->max_eqd = 128;
3788 phwi_context->min_eqd = 0;
3789 phwi_context->cur_eqd = 0;
3790 /* set port optic state to unknown */
3791 phba->optic_state = 0xff;
3793 status = beiscsi_create_eqs(phba, phwi_context);
3795 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3796 "BM_%d : EQ not created\n");
3800 status = be_mcc_queues_create(phba, phwi_context);
3804 status = beiscsi_check_supported_fw(ctrl, phba);
3806 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3807 "BM_%d : Unsupported fw version\n");
3811 status = beiscsi_create_cqs(phba, phwi_context);
3813 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3814 "BM_%d : CQ not created\n");
3818 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
3819 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
3822 BEISCSI_GET_CID_COUNT(phba, ulp_num) *
3823 sizeof(struct phys_addr);
3825 status = beiscsi_create_def_hdr(phba, phwi_context,
3830 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3831 "BM_%d : Default Header not created for ULP : %d\n",
3836 status = beiscsi_create_def_data(phba, phwi_context,
3841 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3842 "BM_%d : Default Data not created for ULP : %d\n",
3847 * Now that the default PDU rings have been created,
3848 * let EP know about it.
3849 * Call beiscsi_cmd_iscsi_cleanup before posting?
3851 hwi_post_async_buffers(phba, BEISCSI_DEFQ_HDR,
3853 hwi_post_async_buffers(phba, BEISCSI_DEFQ_DATA,
3858 status = beiscsi_post_pages(phba);
3860 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3861 "BM_%d : Post SGL Pages Failed\n");
3865 status = beiscsi_post_template_hdr(phba);
3867 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3868 "BM_%d : Template HDR Posting for CXN Failed\n");
3871 status = beiscsi_create_wrb_rings(phba, phwi_context, phwi_ctrlr);
3873 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3874 "BM_%d : WRB Rings not created\n");
3878 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
3879 uint16_t async_arr_idx = 0;
3881 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
3883 struct hwi_async_pdu_context *pasync_ctx;
3885 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(
3886 phwi_ctrlr, ulp_num);
3888 phba->params.cxns_per_ctrl; cri++) {
3889 if (ulp_num == BEISCSI_GET_ULP_FROM_CRI
3891 pasync_ctx->cid_to_async_cri_map[
3892 phwi_ctrlr->wrb_context[cri].cid] =
3898 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3899 "BM_%d : hwi_init_port success\n");
3903 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3904 "BM_%d : hwi_init_port failed");
3905 hwi_cleanup_port(phba);
3909 static int hwi_init_controller(struct beiscsi_hba *phba)
3911 struct hwi_controller *phwi_ctrlr;
3913 phwi_ctrlr = phba->phwi_ctrlr;
3914 if (1 == phba->init_mem[HWI_MEM_ADDN_CONTEXT].num_elements) {
3915 phwi_ctrlr->phwi_ctxt = (struct hwi_context_memory *)phba->
3916 init_mem[HWI_MEM_ADDN_CONTEXT].mem_array[0].virtual_address;
3917 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3918 "BM_%d : phwi_ctrlr->phwi_ctxt=%p\n",
3919 phwi_ctrlr->phwi_ctxt);
3921 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3922 "BM_%d : HWI_MEM_ADDN_CONTEXT is more "
3923 "than one element.Failing to load\n");
3927 iscsi_init_global_templates(phba);
3928 if (beiscsi_init_wrb_handle(phba))
3931 if (hwi_init_async_pdu_ctx(phba)) {
3932 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3933 "BM_%d : hwi_init_async_pdu_ctx failed\n");
3937 if (hwi_init_port(phba) != 0) {
3938 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3939 "BM_%d : hwi_init_controller failed\n");
3946 static void beiscsi_free_mem(struct beiscsi_hba *phba)
3948 struct be_mem_descriptor *mem_descr;
3951 mem_descr = phba->init_mem;
3954 for (i = 0; i < SE_MEM_MAX; i++) {
3955 for (j = mem_descr->num_elements; j > 0; j--) {
3956 pci_free_consistent(phba->pcidev,
3957 mem_descr->mem_array[j - 1].size,
3958 mem_descr->mem_array[j - 1].virtual_address,
3959 (unsigned long)mem_descr->mem_array[j - 1].
3960 bus_address.u.a64.address);
3963 kfree(mem_descr->mem_array);
3966 kfree(phba->init_mem);
3967 kfree(phba->phwi_ctrlr->wrb_context);
3968 kfree(phba->phwi_ctrlr);
3971 static int beiscsi_init_controller(struct beiscsi_hba *phba)
3975 ret = beiscsi_get_memory(phba);
3977 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3978 "BM_%d : beiscsi_dev_probe -"
3979 "Failed in beiscsi_alloc_memory\n");
3983 ret = hwi_init_controller(phba);
3986 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3987 "BM_%d : Return success from beiscsi_init_controller");
3992 beiscsi_free_mem(phba);
3996 static int beiscsi_init_sgl_handle(struct beiscsi_hba *phba)
3998 struct be_mem_descriptor *mem_descr_sglh, *mem_descr_sg;
3999 struct sgl_handle *psgl_handle;
4000 struct iscsi_sge *pfrag;
4001 unsigned int arr_index, i, idx;
4002 unsigned int ulp_icd_start, ulp_num = 0;
4004 phba->io_sgl_hndl_avbl = 0;
4005 phba->eh_sgl_hndl_avbl = 0;
4007 mem_descr_sglh = phba->init_mem;
4008 mem_descr_sglh += HWI_MEM_SGLH;
4009 if (1 == mem_descr_sglh->num_elements) {
4010 phba->io_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
4011 phba->params.ios_per_ctrl,
4013 if (!phba->io_sgl_hndl_base) {
4014 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4015 "BM_%d : Mem Alloc Failed. Failing to load\n");
4018 phba->eh_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
4019 (phba->params.icds_per_ctrl -
4020 phba->params.ios_per_ctrl),
4022 if (!phba->eh_sgl_hndl_base) {
4023 kfree(phba->io_sgl_hndl_base);
4024 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4025 "BM_%d : Mem Alloc Failed. Failing to load\n");
4029 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4030 "BM_%d : HWI_MEM_SGLH is more than one element."
4031 "Failing to load\n");
4037 while (idx < mem_descr_sglh->num_elements) {
4038 psgl_handle = mem_descr_sglh->mem_array[idx].virtual_address;
4040 for (i = 0; i < (mem_descr_sglh->mem_array[idx].size /
4041 sizeof(struct sgl_handle)); i++) {
4042 if (arr_index < phba->params.ios_per_ctrl) {
4043 phba->io_sgl_hndl_base[arr_index] = psgl_handle;
4044 phba->io_sgl_hndl_avbl++;
4047 phba->eh_sgl_hndl_base[arr_index -
4048 phba->params.ios_per_ctrl] =
4051 phba->eh_sgl_hndl_avbl++;
4057 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4058 "BM_%d : phba->io_sgl_hndl_avbl=%d"
4059 "phba->eh_sgl_hndl_avbl=%d\n",
4060 phba->io_sgl_hndl_avbl,
4061 phba->eh_sgl_hndl_avbl);
4063 mem_descr_sg = phba->init_mem;
4064 mem_descr_sg += HWI_MEM_SGE;
4065 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4066 "\n BM_%d : mem_descr_sg->num_elements=%d\n",
4067 mem_descr_sg->num_elements);
4069 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
4070 if (test_bit(ulp_num, &phba->fw_config.ulp_supported))
4073 ulp_icd_start = phba->fw_config.iscsi_icd_start[ulp_num];
4077 while (idx < mem_descr_sg->num_elements) {
4078 pfrag = mem_descr_sg->mem_array[idx].virtual_address;
4081 i < (mem_descr_sg->mem_array[idx].size) /
4082 (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io);
4084 if (arr_index < phba->params.ios_per_ctrl)
4085 psgl_handle = phba->io_sgl_hndl_base[arr_index];
4087 psgl_handle = phba->eh_sgl_hndl_base[arr_index -
4088 phba->params.ios_per_ctrl];
4089 psgl_handle->pfrag = pfrag;
4090 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, pfrag, 0);
4091 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, pfrag, 0);
4092 pfrag += phba->params.num_sge_per_io;
4093 psgl_handle->sgl_index = ulp_icd_start + arr_index++;
4097 phba->io_sgl_free_index = 0;
4098 phba->io_sgl_alloc_index = 0;
4099 phba->eh_sgl_free_index = 0;
4100 phba->eh_sgl_alloc_index = 0;
4104 static int hba_setup_cid_tbls(struct beiscsi_hba *phba)
4107 uint16_t i, ulp_num;
4108 struct ulp_cid_info *ptr_cid_info = NULL;
4110 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
4111 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
4112 ptr_cid_info = kzalloc(sizeof(struct ulp_cid_info),
4115 if (!ptr_cid_info) {
4116 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4117 "BM_%d : Failed to allocate memory"
4118 "for ULP_CID_INFO for ULP : %d\n",
4125 /* Allocate memory for CID array */
4126 ptr_cid_info->cid_array = kzalloc(sizeof(void *) *
4127 BEISCSI_GET_CID_COUNT(phba,
4128 ulp_num), GFP_KERNEL);
4129 if (!ptr_cid_info->cid_array) {
4130 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4131 "BM_%d : Failed to allocate memory"
4132 "for CID_ARRAY for ULP : %d\n",
4134 kfree(ptr_cid_info);
4135 ptr_cid_info = NULL;
4140 ptr_cid_info->avlbl_cids = BEISCSI_GET_CID_COUNT(
4143 /* Save the cid_info_array ptr */
4144 phba->cid_array_info[ulp_num] = ptr_cid_info;
4147 phba->ep_array = kzalloc(sizeof(struct iscsi_endpoint *) *
4148 phba->params.cxns_per_ctrl, GFP_KERNEL);
4149 if (!phba->ep_array) {
4150 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4151 "BM_%d : Failed to allocate memory in "
4152 "hba_setup_cid_tbls\n");
4158 phba->conn_table = kzalloc(sizeof(struct beiscsi_conn *) *
4159 phba->params.cxns_per_ctrl, GFP_KERNEL);
4160 if (!phba->conn_table) {
4161 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4162 "BM_%d : Failed to allocate memory in"
4163 "hba_setup_cid_tbls\n");
4165 kfree(phba->ep_array);
4166 phba->ep_array = NULL;
4172 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
4173 ulp_num = phba->phwi_ctrlr->wrb_context[i].ulp_num;
4175 ptr_cid_info = phba->cid_array_info[ulp_num];
4176 ptr_cid_info->cid_array[ptr_cid_info->cid_alloc++] =
4177 phba->phwi_ctrlr->wrb_context[i].cid;
4181 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
4182 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
4183 ptr_cid_info = phba->cid_array_info[ulp_num];
4185 ptr_cid_info->cid_alloc = 0;
4186 ptr_cid_info->cid_free = 0;
4192 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
4193 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
4194 ptr_cid_info = phba->cid_array_info[ulp_num];
4197 kfree(ptr_cid_info->cid_array);
4198 kfree(ptr_cid_info);
4199 phba->cid_array_info[ulp_num] = NULL;
4207 static void hwi_enable_intr(struct beiscsi_hba *phba)
4209 struct be_ctrl_info *ctrl = &phba->ctrl;
4210 struct hwi_controller *phwi_ctrlr;
4211 struct hwi_context_memory *phwi_context;
4212 struct be_queue_info *eq;
4217 phwi_ctrlr = phba->phwi_ctrlr;
4218 phwi_context = phwi_ctrlr->phwi_ctxt;
4220 addr = (u8 __iomem *) ((u8 __iomem *) ctrl->pcicfg +
4221 PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET);
4222 reg = ioread32(addr);
4224 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
4226 reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
4227 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4228 "BM_%d : reg =x%08x addr=%p\n", reg, addr);
4229 iowrite32(reg, addr);
4232 if (!phba->msix_enabled) {
4233 eq = &phwi_context->be_eq[0].q;
4234 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4235 "BM_%d : eq->id=%d\n", eq->id);
4237 hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
4239 for (i = 0; i <= phba->num_cpus; i++) {
4240 eq = &phwi_context->be_eq[i].q;
4241 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4242 "BM_%d : eq->id=%d\n", eq->id);
4243 hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
4248 static void hwi_disable_intr(struct beiscsi_hba *phba)
4250 struct be_ctrl_info *ctrl = &phba->ctrl;
4252 u8 __iomem *addr = ctrl->pcicfg + PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET;
4253 u32 reg = ioread32(addr);
4255 u32 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
4257 reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
4258 iowrite32(reg, addr);
4260 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
4261 "BM_%d : In hwi_disable_intr, Already Disabled\n");
4264 static int beiscsi_init_port(struct beiscsi_hba *phba)
4268 ret = beiscsi_init_controller(phba);
4270 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4271 "BM_%d : beiscsi_dev_probe - Failed in"
4272 "beiscsi_init_controller\n");
4275 ret = beiscsi_init_sgl_handle(phba);
4277 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4278 "BM_%d : beiscsi_dev_probe - Failed in"
4279 "beiscsi_init_sgl_handle\n");
4280 goto do_cleanup_ctrlr;
4283 if (hba_setup_cid_tbls(phba)) {
4284 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4285 "BM_%d : Failed in hba_setup_cid_tbls\n");
4286 kfree(phba->io_sgl_hndl_base);
4287 kfree(phba->eh_sgl_hndl_base);
4288 goto do_cleanup_ctrlr;
4294 hwi_cleanup_port(phba);
4298 static void beiscsi_cleanup_port(struct beiscsi_hba *phba)
4300 struct ulp_cid_info *ptr_cid_info = NULL;
4303 kfree(phba->io_sgl_hndl_base);
4304 kfree(phba->eh_sgl_hndl_base);
4305 kfree(phba->ep_array);
4306 kfree(phba->conn_table);
4308 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
4309 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
4310 ptr_cid_info = phba->cid_array_info[ulp_num];
4313 kfree(ptr_cid_info->cid_array);
4314 kfree(ptr_cid_info);
4315 phba->cid_array_info[ulp_num] = NULL;
4322 * beiscsi_free_mgmt_task_handles()- Free driver CXN resources
4323 * @beiscsi_conn: ptr to the conn to be cleaned up
4324 * @task: ptr to iscsi_task resource to be freed.
4326 * Free driver mgmt resources binded to CXN.
4329 beiscsi_free_mgmt_task_handles(struct beiscsi_conn *beiscsi_conn,
4330 struct iscsi_task *task)
4332 struct beiscsi_io_task *io_task;
4333 struct beiscsi_hba *phba = beiscsi_conn->phba;
4334 struct hwi_wrb_context *pwrb_context;
4335 struct hwi_controller *phwi_ctrlr;
4336 uint16_t cri_index = BE_GET_CRI_FROM_CID(
4337 beiscsi_conn->beiscsi_conn_cid);
4339 phwi_ctrlr = phba->phwi_ctrlr;
4340 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
4342 io_task = task->dd_data;
4344 if (io_task->pwrb_handle) {
4345 memset(io_task->pwrb_handle->pwrb, 0,
4346 sizeof(struct iscsi_wrb));
4347 free_wrb_handle(phba, pwrb_context,
4348 io_task->pwrb_handle);
4349 io_task->pwrb_handle = NULL;
4352 if (io_task->psgl_handle) {
4353 free_mgmt_sgl_handle(phba,
4354 io_task->psgl_handle);
4355 io_task->psgl_handle = NULL;
4358 if (io_task->mtask_addr) {
4359 pci_unmap_single(phba->pcidev,
4360 io_task->mtask_addr,
4361 io_task->mtask_data_count,
4363 io_task->mtask_addr = 0;
4368 * beiscsi_cleanup_task()- Free driver resources of the task
4369 * @task: ptr to the iscsi task
4372 static void beiscsi_cleanup_task(struct iscsi_task *task)
4374 struct beiscsi_io_task *io_task = task->dd_data;
4375 struct iscsi_conn *conn = task->conn;
4376 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4377 struct beiscsi_hba *phba = beiscsi_conn->phba;
4378 struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
4379 struct hwi_wrb_context *pwrb_context;
4380 struct hwi_controller *phwi_ctrlr;
4381 uint16_t cri_index = BE_GET_CRI_FROM_CID(
4382 beiscsi_conn->beiscsi_conn_cid);
4384 phwi_ctrlr = phba->phwi_ctrlr;
4385 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
4387 if (io_task->cmd_bhs) {
4388 pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
4389 io_task->bhs_pa.u.a64.address);
4390 io_task->cmd_bhs = NULL;
4394 if (io_task->pwrb_handle) {
4395 free_wrb_handle(phba, pwrb_context,
4396 io_task->pwrb_handle);
4397 io_task->pwrb_handle = NULL;
4400 if (io_task->psgl_handle) {
4401 free_io_sgl_handle(phba, io_task->psgl_handle);
4402 io_task->psgl_handle = NULL;
4405 if (io_task->scsi_cmnd) {
4406 if (io_task->num_sg)
4407 scsi_dma_unmap(io_task->scsi_cmnd);
4408 io_task->scsi_cmnd = NULL;
4411 if (!beiscsi_conn->login_in_progress)
4412 beiscsi_free_mgmt_task_handles(beiscsi_conn, task);
4417 beiscsi_offload_connection(struct beiscsi_conn *beiscsi_conn,
4418 struct beiscsi_offload_params *params)
4420 struct wrb_handle *pwrb_handle;
4421 struct hwi_wrb_context *pwrb_context = NULL;
4422 struct beiscsi_hba *phba = beiscsi_conn->phba;
4423 struct iscsi_task *task = beiscsi_conn->task;
4424 struct iscsi_session *session = task->conn->session;
4428 * We can always use 0 here because it is reserved by libiscsi for
4429 * login/startup related tasks.
4431 beiscsi_conn->login_in_progress = 0;
4432 spin_lock_bh(&session->back_lock);
4433 beiscsi_cleanup_task(task);
4434 spin_unlock_bh(&session->back_lock);
4436 pwrb_handle = alloc_wrb_handle(phba, beiscsi_conn->beiscsi_conn_cid,
4439 /* Check for the adapter family */
4440 if (is_chip_be2_be3r(phba))
4441 beiscsi_offload_cxn_v0(params, pwrb_handle,
4445 beiscsi_offload_cxn_v2(params, pwrb_handle,
4448 be_dws_le_to_cpu(pwrb_handle->pwrb,
4449 sizeof(struct iscsi_target_context_update_wrb));
4451 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
4452 doorbell |= (pwrb_handle->wrb_index & DB_DEF_PDU_WRB_INDEX_MASK)
4453 << DB_DEF_PDU_WRB_INDEX_SHIFT;
4454 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
4455 iowrite32(doorbell, phba->db_va +
4456 beiscsi_conn->doorbell_offset);
4459 * There is no completion for CONTEXT_UPDATE. The completion of next
4460 * WRB posted guarantees FW's processing and DMA'ing of it.
4461 * Use beiscsi_put_wrb_handle to put it back in the pool which makes
4462 * sure zero'ing or reuse of the WRB only after wrbs_per_cxn.
4464 beiscsi_put_wrb_handle(pwrb_context, pwrb_handle,
4465 phba->params.wrbs_per_cxn);
4466 beiscsi_log(phba, KERN_INFO,
4467 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
4468 "BM_%d : put CONTEXT_UPDATE pwrb_handle=%p free_index=0x%x wrb_handles_available=%d\n",
4469 pwrb_handle, pwrb_context->free_index,
4470 pwrb_context->wrb_handles_available);
4473 static void beiscsi_parse_pdu(struct iscsi_conn *conn, itt_t itt,
4474 int *index, int *age)
4478 *age = conn->session->age;
4482 * beiscsi_alloc_pdu - allocates pdu and related resources
4483 * @task: libiscsi task
4484 * @opcode: opcode of pdu for task
4486 * This is called with the session lock held. It will allocate
4487 * the wrb and sgl if needed for the command. And it will prep
4488 * the pdu's itt. beiscsi_parse_pdu will later translate
4489 * the pdu itt to the libiscsi task itt.
4491 static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
4493 struct beiscsi_io_task *io_task = task->dd_data;
4494 struct iscsi_conn *conn = task->conn;
4495 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4496 struct beiscsi_hba *phba = beiscsi_conn->phba;
4497 struct hwi_wrb_context *pwrb_context;
4498 struct hwi_controller *phwi_ctrlr;
4500 uint16_t cri_index = 0;
4501 struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
4504 io_task->cmd_bhs = pci_pool_alloc(beiscsi_sess->bhs_pool,
4505 GFP_ATOMIC, &paddr);
4506 if (!io_task->cmd_bhs)
4508 io_task->bhs_pa.u.a64.address = paddr;
4509 io_task->libiscsi_itt = (itt_t)task->itt;
4510 io_task->conn = beiscsi_conn;
4512 task->hdr = (struct iscsi_hdr *)&io_task->cmd_bhs->iscsi_hdr;
4513 task->hdr_max = sizeof(struct be_cmd_bhs);
4514 io_task->psgl_handle = NULL;
4515 io_task->pwrb_handle = NULL;
4518 io_task->psgl_handle = alloc_io_sgl_handle(phba);
4519 if (!io_task->psgl_handle) {
4520 beiscsi_log(phba, KERN_ERR,
4521 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
4522 "BM_%d : Alloc of IO_SGL_ICD Failed"
4523 "for the CID : %d\n",
4524 beiscsi_conn->beiscsi_conn_cid);
4527 io_task->pwrb_handle = alloc_wrb_handle(phba,
4528 beiscsi_conn->beiscsi_conn_cid,
4529 &io_task->pwrb_context);
4530 if (!io_task->pwrb_handle) {
4531 beiscsi_log(phba, KERN_ERR,
4532 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
4533 "BM_%d : Alloc of WRB_HANDLE Failed"
4534 "for the CID : %d\n",
4535 beiscsi_conn->beiscsi_conn_cid);
4539 io_task->scsi_cmnd = NULL;
4540 if ((opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN) {
4541 beiscsi_conn->task = task;
4542 if (!beiscsi_conn->login_in_progress) {
4543 io_task->psgl_handle = (struct sgl_handle *)
4544 alloc_mgmt_sgl_handle(phba);
4545 if (!io_task->psgl_handle) {
4546 beiscsi_log(phba, KERN_ERR,
4549 "BM_%d : Alloc of MGMT_SGL_ICD Failed"
4550 "for the CID : %d\n",
4556 beiscsi_conn->login_in_progress = 1;
4557 beiscsi_conn->plogin_sgl_handle =
4558 io_task->psgl_handle;
4559 io_task->pwrb_handle =
4560 alloc_wrb_handle(phba,
4561 beiscsi_conn->beiscsi_conn_cid,
4562 &io_task->pwrb_context);
4563 if (!io_task->pwrb_handle) {
4564 beiscsi_log(phba, KERN_ERR,
4567 "BM_%d : Alloc of WRB_HANDLE Failed"
4568 "for the CID : %d\n",
4571 goto free_mgmt_hndls;
4573 beiscsi_conn->plogin_wrb_handle =
4574 io_task->pwrb_handle;
4577 io_task->psgl_handle =
4578 beiscsi_conn->plogin_sgl_handle;
4579 io_task->pwrb_handle =
4580 beiscsi_conn->plogin_wrb_handle;
4583 io_task->psgl_handle = alloc_mgmt_sgl_handle(phba);
4584 if (!io_task->psgl_handle) {
4585 beiscsi_log(phba, KERN_ERR,
4588 "BM_%d : Alloc of MGMT_SGL_ICD Failed"
4589 "for the CID : %d\n",
4594 io_task->pwrb_handle =
4595 alloc_wrb_handle(phba,
4596 beiscsi_conn->beiscsi_conn_cid,
4597 &io_task->pwrb_context);
4598 if (!io_task->pwrb_handle) {
4599 beiscsi_log(phba, KERN_ERR,
4600 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
4601 "BM_%d : Alloc of WRB_HANDLE Failed"
4602 "for the CID : %d\n",
4603 beiscsi_conn->beiscsi_conn_cid);
4604 goto free_mgmt_hndls;
4609 itt = (itt_t) cpu_to_be32(((unsigned int)io_task->pwrb_handle->
4610 wrb_index << 16) | (unsigned int)
4611 (io_task->psgl_handle->sgl_index));
4612 io_task->pwrb_handle->pio_handle = task;
4614 io_task->cmd_bhs->iscsi_hdr.itt = itt;
4618 free_io_sgl_handle(phba, io_task->psgl_handle);
4621 free_mgmt_sgl_handle(phba, io_task->psgl_handle);
4622 io_task->psgl_handle = NULL;
4624 phwi_ctrlr = phba->phwi_ctrlr;
4625 cri_index = BE_GET_CRI_FROM_CID(
4626 beiscsi_conn->beiscsi_conn_cid);
4627 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
4628 if (io_task->pwrb_handle)
4629 free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle);
4630 io_task->pwrb_handle = NULL;
4631 pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
4632 io_task->bhs_pa.u.a64.address);
4633 io_task->cmd_bhs = NULL;
4636 int beiscsi_iotask_v2(struct iscsi_task *task, struct scatterlist *sg,
4637 unsigned int num_sg, unsigned int xferlen,
4638 unsigned int writedir)
4641 struct beiscsi_io_task *io_task = task->dd_data;
4642 struct iscsi_conn *conn = task->conn;
4643 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4644 struct beiscsi_hba *phba = beiscsi_conn->phba;
4645 struct iscsi_wrb *pwrb = NULL;
4646 unsigned int doorbell = 0;
4648 pwrb = io_task->pwrb_handle->pwrb;
4650 io_task->bhs_len = sizeof(struct be_cmd_bhs);
4653 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb,
4655 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 1);
4657 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb,
4659 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 0);
4662 io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb_v2,
4665 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, lun, pwrb,
4666 cpu_to_be16(*(unsigned short *)
4667 &io_task->cmd_bhs->iscsi_hdr.lun));
4668 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb, xferlen);
4669 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb,
4670 io_task->pwrb_handle->wrb_index);
4671 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb,
4672 be32_to_cpu(task->cmdsn));
4673 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb,
4674 io_task->psgl_handle->sgl_index);
4676 hwi_write_sgl_v2(pwrb, sg, num_sg, io_task);
4677 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb,
4678 io_task->pwrb_handle->wrb_index);
4679 if (io_task->pwrb_context->plast_wrb)
4680 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb,
4681 io_task->pwrb_context->plast_wrb,
4682 io_task->pwrb_handle->wrb_index);
4683 io_task->pwrb_context->plast_wrb = pwrb;
4685 be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
4687 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
4688 doorbell |= (io_task->pwrb_handle->wrb_index &
4689 DB_DEF_PDU_WRB_INDEX_MASK) <<
4690 DB_DEF_PDU_WRB_INDEX_SHIFT;
4691 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
4692 iowrite32(doorbell, phba->db_va +
4693 beiscsi_conn->doorbell_offset);
4697 static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg,
4698 unsigned int num_sg, unsigned int xferlen,
4699 unsigned int writedir)
4702 struct beiscsi_io_task *io_task = task->dd_data;
4703 struct iscsi_conn *conn = task->conn;
4704 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4705 struct beiscsi_hba *phba = beiscsi_conn->phba;
4706 struct iscsi_wrb *pwrb = NULL;
4707 unsigned int doorbell = 0;
4709 pwrb = io_task->pwrb_handle->pwrb;
4710 io_task->bhs_len = sizeof(struct be_cmd_bhs);
4713 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4715 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1);
4717 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4719 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
4722 io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb,
4725 AMAP_SET_BITS(struct amap_iscsi_wrb, lun, pwrb,
4726 cpu_to_be16(*(unsigned short *)
4727 &io_task->cmd_bhs->iscsi_hdr.lun));
4728 AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, xferlen);
4729 AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
4730 io_task->pwrb_handle->wrb_index);
4731 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
4732 be32_to_cpu(task->cmdsn));
4733 AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
4734 io_task->psgl_handle->sgl_index);
4736 hwi_write_sgl(pwrb, sg, num_sg, io_task);
4738 AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
4739 io_task->pwrb_handle->wrb_index);
4740 if (io_task->pwrb_context->plast_wrb)
4741 AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb,
4742 io_task->pwrb_context->plast_wrb,
4743 io_task->pwrb_handle->wrb_index);
4744 io_task->pwrb_context->plast_wrb = pwrb;
4746 be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
4748 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
4749 doorbell |= (io_task->pwrb_handle->wrb_index &
4750 DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
4751 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
4753 iowrite32(doorbell, phba->db_va +
4754 beiscsi_conn->doorbell_offset);
4758 static int beiscsi_mtask(struct iscsi_task *task)
4760 struct beiscsi_io_task *io_task = task->dd_data;
4761 struct iscsi_conn *conn = task->conn;
4762 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4763 struct beiscsi_hba *phba = beiscsi_conn->phba;
4764 struct iscsi_wrb *pwrb = NULL;
4765 unsigned int doorbell = 0;
4767 unsigned int pwrb_typeoffset = 0;
4770 cid = beiscsi_conn->beiscsi_conn_cid;
4771 pwrb = io_task->pwrb_handle->pwrb;
4772 memset(pwrb, 0, sizeof(*pwrb));
4774 if (is_chip_be2_be3r(phba)) {
4775 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
4776 be32_to_cpu(task->cmdsn));
4777 AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
4778 io_task->pwrb_handle->wrb_index);
4779 AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
4780 io_task->psgl_handle->sgl_index);
4781 AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb,
4783 AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
4784 io_task->pwrb_handle->wrb_index);
4785 if (io_task->pwrb_context->plast_wrb)
4786 AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb,
4787 io_task->pwrb_context->plast_wrb,
4788 io_task->pwrb_handle->wrb_index);
4789 io_task->pwrb_context->plast_wrb = pwrb;
4791 pwrb_typeoffset = BE_WRB_TYPE_OFFSET;
4793 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb,
4794 be32_to_cpu(task->cmdsn));
4795 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb,
4796 io_task->pwrb_handle->wrb_index);
4797 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb,
4798 io_task->psgl_handle->sgl_index);
4799 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb,
4801 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb,
4802 io_task->pwrb_handle->wrb_index);
4803 if (io_task->pwrb_context->plast_wrb)
4804 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb,
4805 io_task->pwrb_context->plast_wrb,
4806 io_task->pwrb_handle->wrb_index);
4807 io_task->pwrb_context->plast_wrb = pwrb;
4809 pwrb_typeoffset = SKH_WRB_TYPE_OFFSET;
4813 switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
4814 case ISCSI_OP_LOGIN:
4815 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, 1);
4816 ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset);
4817 ret = hwi_write_buffer(pwrb, task);
4819 case ISCSI_OP_NOOP_OUT:
4820 if (task->hdr->ttt != ISCSI_RESERVED_TAG) {
4821 ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset);
4822 if (is_chip_be2_be3r(phba))
4823 AMAP_SET_BITS(struct amap_iscsi_wrb,
4826 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
4829 ADAPTER_SET_WRB_TYPE(pwrb, INI_RD_CMD, pwrb_typeoffset);
4830 if (is_chip_be2_be3r(phba))
4831 AMAP_SET_BITS(struct amap_iscsi_wrb,
4834 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
4837 ret = hwi_write_buffer(pwrb, task);
4840 ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset);
4841 ret = hwi_write_buffer(pwrb, task);
4843 case ISCSI_OP_SCSI_TMFUNC:
4844 ADAPTER_SET_WRB_TYPE(pwrb, INI_TMF_CMD, pwrb_typeoffset);
4845 ret = hwi_write_buffer(pwrb, task);
4847 case ISCSI_OP_LOGOUT:
4848 ADAPTER_SET_WRB_TYPE(pwrb, HWH_TYPE_LOGOUT, pwrb_typeoffset);
4849 ret = hwi_write_buffer(pwrb, task);
4853 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
4854 "BM_%d : opcode =%d Not supported\n",
4855 task->hdr->opcode & ISCSI_OPCODE_MASK);
4863 /* Set the task type */
4864 io_task->wrb_type = (is_chip_be2_be3r(phba)) ?
4865 AMAP_GET_BITS(struct amap_iscsi_wrb, type, pwrb) :
4866 AMAP_GET_BITS(struct amap_iscsi_wrb_v2, type, pwrb);
4868 doorbell |= cid & DB_WRB_POST_CID_MASK;
4869 doorbell |= (io_task->pwrb_handle->wrb_index &
4870 DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
4871 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
4872 iowrite32(doorbell, phba->db_va +
4873 beiscsi_conn->doorbell_offset);
4877 static int beiscsi_task_xmit(struct iscsi_task *task)
4879 struct beiscsi_io_task *io_task = task->dd_data;
4880 struct scsi_cmnd *sc = task->sc;
4881 struct beiscsi_hba *phba;
4882 struct scatterlist *sg;
4884 unsigned int writedir = 0, xferlen = 0;
4886 phba = io_task->conn->phba;
4888 * HBA in error includes BEISCSI_HBA_FW_TIMEOUT. IO path might be
4889 * operational if FW still gets heartbeat from EP FW. Is management
4890 * path really needed to continue further?
4892 if (!beiscsi_hba_is_online(phba))
4895 if (!io_task->conn->login_in_progress)
4896 task->hdr->exp_statsn = 0;
4899 return beiscsi_mtask(task);
4901 io_task->scsi_cmnd = sc;
4902 io_task->num_sg = 0;
4903 num_sg = scsi_dma_map(sc);
4905 beiscsi_log(phba, KERN_ERR,
4906 BEISCSI_LOG_IO | BEISCSI_LOG_ISCSI,
4907 "BM_%d : scsi_dma_map Failed "
4908 "Driver_ITT : 0x%x ITT : 0x%x Xferlen : 0x%x\n",
4909 be32_to_cpu(io_task->cmd_bhs->iscsi_hdr.itt),
4910 io_task->libiscsi_itt, scsi_bufflen(sc));
4915 * For scsi cmd task, check num_sg before unmapping in cleanup_task.
4916 * For management task, cleanup_task checks mtask_addr before unmapping.
4918 io_task->num_sg = num_sg;
4919 xferlen = scsi_bufflen(sc);
4920 sg = scsi_sglist(sc);
4921 if (sc->sc_data_direction == DMA_TO_DEVICE)
4926 return phba->iotask_fn(task, sg, num_sg, xferlen, writedir);
4930 * beiscsi_bsg_request - handle bsg request from ISCSI transport
4931 * @job: job to handle
4933 static int beiscsi_bsg_request(struct bsg_job *job)
4935 struct Scsi_Host *shost;
4936 struct beiscsi_hba *phba;
4937 struct iscsi_bsg_request *bsg_req = job->request;
4940 struct be_dma_mem nonemb_cmd;
4941 struct be_cmd_resp_hdr *resp;
4942 struct iscsi_bsg_reply *bsg_reply = job->reply;
4943 unsigned short status, extd_status;
4945 shost = iscsi_job_to_shost(job);
4946 phba = iscsi_host_priv(shost);
4948 if (!beiscsi_hba_is_online(phba)) {
4949 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
4950 "BM_%d : HBA in error 0x%lx\n", phba->state);
4954 switch (bsg_req->msgcode) {
4955 case ISCSI_BSG_HST_VENDOR:
4956 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
4957 job->request_payload.payload_len,
4959 if (nonemb_cmd.va == NULL) {
4960 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
4961 "BM_%d : Failed to allocate memory for "
4962 "beiscsi_bsg_request\n");
4965 tag = mgmt_vendor_specific_fw_cmd(&phba->ctrl, phba, job,
4968 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
4969 "BM_%d : MBX Tag Allocation Failed\n");
4971 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
4972 nonemb_cmd.va, nonemb_cmd.dma);
4976 rc = wait_event_interruptible_timeout(
4977 phba->ctrl.mcc_wait[tag],
4978 phba->ctrl.mcc_tag_status[tag],
4980 BEISCSI_HOST_MBX_TIMEOUT));
4982 if (!test_bit(BEISCSI_HBA_ONLINE, &phba->state)) {
4983 clear_bit(MCC_TAG_STATE_RUNNING,
4984 &phba->ctrl.ptag_state[tag].tag_state);
4985 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
4986 nonemb_cmd.va, nonemb_cmd.dma);
4989 extd_status = (phba->ctrl.mcc_tag_status[tag] &
4990 CQE_STATUS_ADDL_MASK) >> CQE_STATUS_ADDL_SHIFT;
4991 status = phba->ctrl.mcc_tag_status[tag] & CQE_STATUS_MASK;
4992 free_mcc_wrb(&phba->ctrl, tag);
4993 resp = (struct be_cmd_resp_hdr *)nonemb_cmd.va;
4994 sg_copy_from_buffer(job->reply_payload.sg_list,
4995 job->reply_payload.sg_cnt,
4996 nonemb_cmd.va, (resp->response_length
4998 bsg_reply->reply_payload_rcv_len = resp->response_length;
4999 bsg_reply->result = status;
5000 bsg_job_done(job, bsg_reply->result,
5001 bsg_reply->reply_payload_rcv_len);
5002 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
5003 nonemb_cmd.va, nonemb_cmd.dma);
5004 if (status || extd_status) {
5005 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
5006 "BM_%d : MBX Cmd Failed"
5007 " status = %d extd_status = %d\n",
5008 status, extd_status);
5017 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
5018 "BM_%d : Unsupported bsg command: 0x%x\n",
5026 void beiscsi_hba_attrs_init(struct beiscsi_hba *phba)
5028 /* Set the logging parameter */
5029 beiscsi_log_enable_init(phba, beiscsi_log_enable);
5032 void beiscsi_start_boot_work(struct beiscsi_hba *phba, unsigned int s_handle)
5034 if (phba->boot_struct.boot_kset)
5037 /* skip if boot work is already in progress */
5038 if (test_and_set_bit(BEISCSI_HBA_BOOT_WORK, &phba->state))
5041 phba->boot_struct.retry = 3;
5042 phba->boot_struct.tag = 0;
5043 phba->boot_struct.s_handle = s_handle;
5044 phba->boot_struct.action = BEISCSI_BOOT_GET_SHANDLE;
5045 schedule_work(&phba->boot_work);
5048 static ssize_t beiscsi_show_boot_tgt_info(void *data, int type, char *buf)
5050 struct beiscsi_hba *phba = data;
5051 struct mgmt_session_info *boot_sess = &phba->boot_struct.boot_sess;
5052 struct mgmt_conn_info *boot_conn = &boot_sess->conn_list[0];
5057 case ISCSI_BOOT_TGT_NAME:
5058 rc = sprintf(buf, "%.*s\n",
5059 (int)strlen(boot_sess->target_name),
5060 (char *)&boot_sess->target_name);
5062 case ISCSI_BOOT_TGT_IP_ADDR:
5063 if (boot_conn->dest_ipaddr.ip_type == BEISCSI_IP_TYPE_V4)
5064 rc = sprintf(buf, "%pI4\n",
5065 (char *)&boot_conn->dest_ipaddr.addr);
5067 rc = sprintf(str, "%pI6\n",
5068 (char *)&boot_conn->dest_ipaddr.addr);
5070 case ISCSI_BOOT_TGT_PORT:
5071 rc = sprintf(str, "%d\n", boot_conn->dest_port);
5074 case ISCSI_BOOT_TGT_CHAP_NAME:
5075 rc = sprintf(str, "%.*s\n",
5076 boot_conn->negotiated_login_options.auth_data.chap.
5077 target_chap_name_length,
5078 (char *)&boot_conn->negotiated_login_options.
5079 auth_data.chap.target_chap_name);
5081 case ISCSI_BOOT_TGT_CHAP_SECRET:
5082 rc = sprintf(str, "%.*s\n",
5083 boot_conn->negotiated_login_options.auth_data.chap.
5084 target_secret_length,
5085 (char *)&boot_conn->negotiated_login_options.
5086 auth_data.chap.target_secret);
5088 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5089 rc = sprintf(str, "%.*s\n",
5090 boot_conn->negotiated_login_options.auth_data.chap.
5091 intr_chap_name_length,
5092 (char *)&boot_conn->negotiated_login_options.
5093 auth_data.chap.intr_chap_name);
5095 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5096 rc = sprintf(str, "%.*s\n",
5097 boot_conn->negotiated_login_options.auth_data.chap.
5099 (char *)&boot_conn->negotiated_login_options.
5100 auth_data.chap.intr_secret);
5102 case ISCSI_BOOT_TGT_FLAGS:
5103 rc = sprintf(str, "2\n");
5105 case ISCSI_BOOT_TGT_NIC_ASSOC:
5106 rc = sprintf(str, "0\n");
5112 static ssize_t beiscsi_show_boot_ini_info(void *data, int type, char *buf)
5114 struct beiscsi_hba *phba = data;
5119 case ISCSI_BOOT_INI_INITIATOR_NAME:
5120 rc = sprintf(str, "%s\n",
5121 phba->boot_struct.boot_sess.initiator_iscsiname);
5127 static ssize_t beiscsi_show_boot_eth_info(void *data, int type, char *buf)
5129 struct beiscsi_hba *phba = data;
5134 case ISCSI_BOOT_ETH_FLAGS:
5135 rc = sprintf(str, "2\n");
5137 case ISCSI_BOOT_ETH_INDEX:
5138 rc = sprintf(str, "0\n");
5140 case ISCSI_BOOT_ETH_MAC:
5141 rc = beiscsi_get_macaddr(str, phba);
5147 static umode_t beiscsi_tgt_get_attr_visibility(void *data, int type)
5152 case ISCSI_BOOT_TGT_NAME:
5153 case ISCSI_BOOT_TGT_IP_ADDR:
5154 case ISCSI_BOOT_TGT_PORT:
5155 case ISCSI_BOOT_TGT_CHAP_NAME:
5156 case ISCSI_BOOT_TGT_CHAP_SECRET:
5157 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
5158 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
5159 case ISCSI_BOOT_TGT_NIC_ASSOC:
5160 case ISCSI_BOOT_TGT_FLAGS:
5167 static umode_t beiscsi_ini_get_attr_visibility(void *data, int type)
5172 case ISCSI_BOOT_INI_INITIATOR_NAME:
5179 static umode_t beiscsi_eth_get_attr_visibility(void *data, int type)
5184 case ISCSI_BOOT_ETH_FLAGS:
5185 case ISCSI_BOOT_ETH_MAC:
5186 case ISCSI_BOOT_ETH_INDEX:
5193 static void beiscsi_boot_kobj_release(void *data)
5195 struct beiscsi_hba *phba = data;
5197 scsi_host_put(phba->shost);
5200 static int beiscsi_boot_create_kset(struct beiscsi_hba *phba)
5202 struct boot_struct *bs = &phba->boot_struct;
5203 struct iscsi_boot_kobj *boot_kobj;
5205 if (bs->boot_kset) {
5206 __beiscsi_log(phba, KERN_ERR,
5207 "BM_%d: boot_kset already created\n");
5211 bs->boot_kset = iscsi_boot_create_host_kset(phba->shost->host_no);
5212 if (!bs->boot_kset) {
5213 __beiscsi_log(phba, KERN_ERR,
5214 "BM_%d: boot_kset alloc failed\n");
5218 /* get shost ref because the show function will refer phba */
5219 if (!scsi_host_get(phba->shost))
5222 boot_kobj = iscsi_boot_create_target(bs->boot_kset, 0, phba,
5223 beiscsi_show_boot_tgt_info,
5224 beiscsi_tgt_get_attr_visibility,
5225 beiscsi_boot_kobj_release);
5229 if (!scsi_host_get(phba->shost))
5232 boot_kobj = iscsi_boot_create_initiator(bs->boot_kset, 0, phba,
5233 beiscsi_show_boot_ini_info,
5234 beiscsi_ini_get_attr_visibility,
5235 beiscsi_boot_kobj_release);
5239 if (!scsi_host_get(phba->shost))
5242 boot_kobj = iscsi_boot_create_ethernet(bs->boot_kset, 0, phba,
5243 beiscsi_show_boot_eth_info,
5244 beiscsi_eth_get_attr_visibility,
5245 beiscsi_boot_kobj_release);
5252 scsi_host_put(phba->shost);
5254 iscsi_boot_destroy_kset(bs->boot_kset);
5255 bs->boot_kset = NULL;
5259 static void beiscsi_boot_work(struct work_struct *work)
5261 struct beiscsi_hba *phba =
5262 container_of(work, struct beiscsi_hba, boot_work);
5263 struct boot_struct *bs = &phba->boot_struct;
5264 unsigned int tag = 0;
5266 if (!beiscsi_hba_is_online(phba))
5269 beiscsi_log(phba, KERN_INFO,
5270 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
5271 "BM_%d : %s action %d\n",
5272 __func__, phba->boot_struct.action);
5274 switch (phba->boot_struct.action) {
5275 case BEISCSI_BOOT_REOPEN_SESS:
5276 tag = beiscsi_boot_reopen_sess(phba);
5278 case BEISCSI_BOOT_GET_SHANDLE:
5279 tag = __beiscsi_boot_get_shandle(phba, 1);
5281 case BEISCSI_BOOT_GET_SINFO:
5282 tag = beiscsi_boot_get_sinfo(phba);
5284 case BEISCSI_BOOT_LOGOUT_SESS:
5285 tag = beiscsi_boot_logout_sess(phba);
5287 case BEISCSI_BOOT_CREATE_KSET:
5288 beiscsi_boot_create_kset(phba);
5290 * updated boot_kset is made visible to all before
5291 * ending the boot work.
5294 clear_bit(BEISCSI_HBA_BOOT_WORK, &phba->state);
5299 schedule_work(&phba->boot_work);
5301 clear_bit(BEISCSI_HBA_BOOT_WORK, &phba->state);
5305 static void beiscsi_eqd_update_work(struct work_struct *work)
5307 struct hwi_context_memory *phwi_context;
5308 struct be_set_eqd set_eqd[MAX_CPUS];
5309 struct hwi_controller *phwi_ctrlr;
5310 struct be_eq_obj *pbe_eq;
5311 struct beiscsi_hba *phba;
5312 unsigned int pps, delta;
5313 struct be_aic_obj *aic;
5314 int eqd, i, num = 0;
5317 phba = container_of(work, struct beiscsi_hba, eqd_update.work);
5318 if (!beiscsi_hba_is_online(phba))
5321 phwi_ctrlr = phba->phwi_ctrlr;
5322 phwi_context = phwi_ctrlr->phwi_ctxt;
5324 for (i = 0; i <= phba->num_cpus; i++) {
5325 aic = &phba->aic_obj[i];
5326 pbe_eq = &phwi_context->be_eq[i];
5328 if (!aic->jiffies || time_before(now, aic->jiffies) ||
5329 pbe_eq->cq_count < aic->eq_prev) {
5331 aic->eq_prev = pbe_eq->cq_count;
5334 delta = jiffies_to_msecs(now - aic->jiffies);
5335 pps = (((u32)(pbe_eq->cq_count - aic->eq_prev) * 1000) / delta);
5336 eqd = (pps / 1500) << 2;
5340 eqd = min_t(u32, eqd, phwi_context->max_eqd);
5341 eqd = max_t(u32, eqd, phwi_context->min_eqd);
5344 aic->eq_prev = pbe_eq->cq_count;
5346 if (eqd != aic->prev_eqd) {
5347 set_eqd[num].delay_multiplier = (eqd * 65)/100;
5348 set_eqd[num].eq_id = pbe_eq->q.id;
5349 aic->prev_eqd = eqd;
5354 /* completion of this is ignored */
5355 beiscsi_modify_eq_delay(phba, set_eqd, num);
5357 schedule_delayed_work(&phba->eqd_update,
5358 msecs_to_jiffies(BEISCSI_EQD_UPDATE_INTERVAL));
5361 static void beiscsi_msix_enable(struct beiscsi_hba *phba)
5365 for (i = 0; i <= phba->num_cpus; i++)
5366 phba->msix_entries[i].entry = i;
5368 status = pci_enable_msix_range(phba->pcidev, phba->msix_entries,
5369 phba->num_cpus + 1, phba->num_cpus + 1);
5371 phba->msix_enabled = true;
5374 static void beiscsi_hw_tpe_check(unsigned long ptr)
5376 struct beiscsi_hba *phba;
5379 phba = (struct beiscsi_hba *)ptr;
5380 /* if not TPE, do nothing */
5381 if (!beiscsi_detect_tpe(phba))
5384 /* wait default 4000ms before recovering */
5386 if (phba->ue2rp > BEISCSI_UE_DETECT_INTERVAL)
5387 wait = phba->ue2rp - BEISCSI_UE_DETECT_INTERVAL;
5388 queue_delayed_work(phba->wq, &phba->recover_port,
5389 msecs_to_jiffies(wait));
5392 static void beiscsi_hw_health_check(unsigned long ptr)
5394 struct beiscsi_hba *phba;
5396 phba = (struct beiscsi_hba *)ptr;
5397 beiscsi_detect_ue(phba);
5398 if (beiscsi_detect_ue(phba)) {
5399 __beiscsi_log(phba, KERN_ERR,
5400 "BM_%d : port in error: %lx\n", phba->state);
5401 /* detect TPE if UER supported */
5402 if (!test_bit(BEISCSI_HBA_UER_SUPP, &phba->state))
5404 /* modify this timer to check TPE */
5405 phba->hw_check.function = beiscsi_hw_tpe_check;
5408 mod_timer(&phba->hw_check,
5409 jiffies + msecs_to_jiffies(BEISCSI_UE_DETECT_INTERVAL));
5413 * beiscsi_enable_port()- Enables the disabled port.
5414 * Only port resources freed in disable function are reallocated.
5415 * This is called in HBA error handling path.
5417 * @phba: Instance of driver private structure
5420 static int beiscsi_enable_port(struct beiscsi_hba *phba)
5422 struct hwi_context_memory *phwi_context;
5423 struct hwi_controller *phwi_ctrlr;
5424 struct be_eq_obj *pbe_eq;
5427 if (test_bit(BEISCSI_HBA_ONLINE, &phba->state)) {
5428 __beiscsi_log(phba, KERN_ERR,
5429 "BM_%d : %s : port is online %lx\n",
5430 __func__, phba->state);
5434 ret = beiscsi_init_sliport(phba);
5439 find_num_cpus(phba);
5443 beiscsi_msix_enable(phba);
5444 if (!phba->msix_enabled)
5448 beiscsi_get_params(phba);
5449 /* Re-enable UER. If different TPE occurs then it is recoverable. */
5450 beiscsi_set_uer_feature(phba);
5452 phba->shost->max_id = phba->params.cxns_per_ctrl;
5453 phba->shost->can_queue = phba->params.ios_per_ctrl;
5454 ret = hwi_init_controller(phba);
5456 __beiscsi_log(phba, KERN_ERR,
5457 "BM_%d : init controller failed %d\n", ret);
5461 for (i = 0; i < MAX_MCC_CMD; i++) {
5462 init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]);
5463 phba->ctrl.mcc_tag[i] = i + 1;
5464 phba->ctrl.mcc_tag_status[i + 1] = 0;
5465 phba->ctrl.mcc_tag_available++;
5468 phwi_ctrlr = phba->phwi_ctrlr;
5469 phwi_context = phwi_ctrlr->phwi_ctxt;
5470 for (i = 0; i < phba->num_cpus; i++) {
5471 pbe_eq = &phwi_context->be_eq[i];
5472 irq_poll_init(&pbe_eq->iopoll, be_iopoll_budget, be_iopoll);
5475 i = (phba->msix_enabled) ? i : 0;
5476 /* Work item for MCC handling */
5477 pbe_eq = &phwi_context->be_eq[i];
5478 INIT_WORK(&pbe_eq->mcc_work, beiscsi_mcc_work);
5480 ret = beiscsi_init_irqs(phba);
5482 __beiscsi_log(phba, KERN_ERR,
5483 "BM_%d : setup IRQs failed %d\n", ret);
5486 hwi_enable_intr(phba);
5487 /* port operational: clear all error bits */
5488 set_bit(BEISCSI_HBA_ONLINE, &phba->state);
5489 __beiscsi_log(phba, KERN_INFO,
5490 "BM_%d : port online: 0x%lx\n", phba->state);
5492 /* start hw_check timer and eqd_update work */
5493 schedule_delayed_work(&phba->eqd_update,
5494 msecs_to_jiffies(BEISCSI_EQD_UPDATE_INTERVAL));
5497 * Timer function gets modified for TPE detection.
5498 * Always reinit to do health check first.
5500 phba->hw_check.function = beiscsi_hw_health_check;
5501 mod_timer(&phba->hw_check,
5502 jiffies + msecs_to_jiffies(BEISCSI_UE_DETECT_INTERVAL));
5506 for (i = 0; i < phba->num_cpus; i++) {
5507 pbe_eq = &phwi_context->be_eq[i];
5508 irq_poll_disable(&pbe_eq->iopoll);
5510 hwi_cleanup_port(phba);
5513 if (phba->msix_enabled)
5514 pci_disable_msix(phba->pcidev);
5520 * beiscsi_disable_port()- Disable port and cleanup driver resources.
5521 * This is called in HBA error handling and driver removal.
5522 * @phba: Instance Priv structure
5523 * @unload: indicate driver is unloading
5525 * Free the OS and HW resources held by the driver
5527 static void beiscsi_disable_port(struct beiscsi_hba *phba, int unload)
5529 struct hwi_context_memory *phwi_context;
5530 struct hwi_controller *phwi_ctrlr;
5531 struct be_eq_obj *pbe_eq;
5532 unsigned int i, msix_vec;
5534 if (!test_and_clear_bit(BEISCSI_HBA_ONLINE, &phba->state))
5537 phwi_ctrlr = phba->phwi_ctrlr;
5538 phwi_context = phwi_ctrlr->phwi_ctxt;
5539 hwi_disable_intr(phba);
5540 if (phba->msix_enabled) {
5541 for (i = 0; i <= phba->num_cpus; i++) {
5542 msix_vec = phba->msix_entries[i].vector;
5543 free_irq(msix_vec, &phwi_context->be_eq[i]);
5544 kfree(phba->msi_name[i]);
5547 if (phba->pcidev->irq)
5548 free_irq(phba->pcidev->irq, phba);
5549 pci_disable_msix(phba->pcidev);
5551 for (i = 0; i < phba->num_cpus; i++) {
5552 pbe_eq = &phwi_context->be_eq[i];
5553 irq_poll_disable(&pbe_eq->iopoll);
5555 cancel_delayed_work_sync(&phba->eqd_update);
5556 cancel_work_sync(&phba->boot_work);
5557 /* WQ might be running cancel queued mcc_work if we are not exiting */
5558 if (!unload && beiscsi_hba_in_error(phba)) {
5559 pbe_eq = &phwi_context->be_eq[i];
5560 cancel_work_sync(&pbe_eq->mcc_work);
5562 hwi_cleanup_port(phba);
5565 static void beiscsi_recover_port(struct work_struct *work)
5567 struct beiscsi_hba *phba;
5569 phba = container_of(work, struct beiscsi_hba, recover_port.work);
5570 iscsi_host_for_each_session(phba->shost, beiscsi_session_fail);
5571 beiscsi_disable_port(phba, 0);
5572 beiscsi_enable_port(phba);
5575 static pci_ers_result_t beiscsi_eeh_err_detected(struct pci_dev *pdev,
5576 pci_channel_state_t state)
5578 struct beiscsi_hba *phba = NULL;
5580 phba = (struct beiscsi_hba *)pci_get_drvdata(pdev);
5581 set_bit(BEISCSI_HBA_PCI_ERR, &phba->state);
5583 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5584 "BM_%d : EEH error detected\n");
5586 /* first stop UE detection when PCI error detected */
5587 del_timer_sync(&phba->hw_check);
5588 cancel_delayed_work_sync(&phba->recover_port);
5590 beiscsi_disable_port(phba, 0);
5592 if (state == pci_channel_io_perm_failure) {
5593 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5594 "BM_%d : EEH : State PERM Failure");
5595 return PCI_ERS_RESULT_DISCONNECT;
5598 pci_disable_device(pdev);
5600 /* The error could cause the FW to trigger a flash debug dump.
5601 * Resetting the card while flash dump is in progress
5602 * can cause it not to recover; wait for it to finish.
5603 * Wait only for first function as it is needed only once per
5606 if (pdev->devfn == 0)
5609 return PCI_ERS_RESULT_NEED_RESET;
5612 static pci_ers_result_t beiscsi_eeh_reset(struct pci_dev *pdev)
5614 struct beiscsi_hba *phba = NULL;
5617 phba = (struct beiscsi_hba *)pci_get_drvdata(pdev);
5619 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5620 "BM_%d : EEH Reset\n");
5622 status = pci_enable_device(pdev);
5624 return PCI_ERS_RESULT_DISCONNECT;
5626 pci_set_master(pdev);
5627 pci_set_power_state(pdev, PCI_D0);
5628 pci_restore_state(pdev);
5630 status = beiscsi_check_fw_rdy(phba);
5632 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
5633 "BM_%d : EEH Reset Completed\n");
5635 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
5636 "BM_%d : EEH Reset Completion Failure\n");
5637 return PCI_ERS_RESULT_DISCONNECT;
5640 pci_cleanup_aer_uncorrect_error_status(pdev);
5641 return PCI_ERS_RESULT_RECOVERED;
5644 static void beiscsi_eeh_resume(struct pci_dev *pdev)
5646 struct beiscsi_hba *phba;
5649 phba = (struct beiscsi_hba *)pci_get_drvdata(pdev);
5650 pci_save_state(pdev);
5652 ret = beiscsi_enable_port(phba);
5654 __beiscsi_log(phba, KERN_ERR,
5655 "BM_%d : AER EEH resume failed\n");
5658 static int beiscsi_dev_probe(struct pci_dev *pcidev,
5659 const struct pci_device_id *id)
5661 struct beiscsi_hba *phba = NULL;
5662 struct hwi_controller *phwi_ctrlr;
5663 struct hwi_context_memory *phwi_context;
5664 struct be_eq_obj *pbe_eq;
5665 unsigned int s_handle;
5668 ret = beiscsi_enable_pci(pcidev);
5670 dev_err(&pcidev->dev,
5671 "beiscsi_dev_probe - Failed to enable pci device\n");
5675 phba = beiscsi_hba_alloc(pcidev);
5677 dev_err(&pcidev->dev,
5678 "beiscsi_dev_probe - Failed in beiscsi_hba_alloc\n");
5682 /* Enable EEH reporting */
5683 ret = pci_enable_pcie_error_reporting(pcidev);
5685 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
5686 "BM_%d : PCIe Error Reporting "
5687 "Enabling Failed\n");
5689 pci_save_state(pcidev);
5691 /* Initialize Driver configuration Paramters */
5692 beiscsi_hba_attrs_init(phba);
5694 phba->mac_addr_set = false;
5696 switch (pcidev->device) {
5700 phba->generation = BE_GEN2;
5701 phba->iotask_fn = beiscsi_iotask;
5705 phba->generation = BE_GEN3;
5706 phba->iotask_fn = beiscsi_iotask;
5709 phba->generation = BE_GEN4;
5710 phba->iotask_fn = beiscsi_iotask_v2;
5713 phba->generation = 0;
5716 ret = be_ctrl_init(phba, pcidev);
5718 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5719 "BM_%d : be_ctrl_init failed\n");
5723 ret = beiscsi_init_sliport(phba);
5727 spin_lock_init(&phba->io_sgl_lock);
5728 spin_lock_init(&phba->mgmt_sgl_lock);
5729 spin_lock_init(&phba->async_pdu_lock);
5730 ret = beiscsi_get_fw_config(&phba->ctrl, phba);
5732 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5733 "BM_%d : Error getting fw config\n");
5736 beiscsi_get_port_name(&phba->ctrl, phba);
5737 beiscsi_get_params(phba);
5738 beiscsi_set_uer_feature(phba);
5741 find_num_cpus(phba);
5745 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
5746 "BM_%d : num_cpus = %d\n",
5750 beiscsi_msix_enable(phba);
5751 if (!phba->msix_enabled)
5755 phba->shost->max_id = phba->params.cxns_per_ctrl;
5756 phba->shost->can_queue = phba->params.ios_per_ctrl;
5757 ret = beiscsi_init_port(phba);
5759 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5760 "BM_%d : beiscsi_dev_probe-"
5761 "Failed in beiscsi_init_port\n");
5765 for (i = 0; i < MAX_MCC_CMD; i++) {
5766 init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]);
5767 phba->ctrl.mcc_tag[i] = i + 1;
5768 phba->ctrl.mcc_tag_status[i + 1] = 0;
5769 phba->ctrl.mcc_tag_available++;
5770 memset(&phba->ctrl.ptag_state[i].tag_mem_state, 0,
5771 sizeof(struct be_dma_mem));
5774 phba->ctrl.mcc_alloc_index = phba->ctrl.mcc_free_index = 0;
5776 snprintf(phba->wq_name, sizeof(phba->wq_name), "beiscsi_%02x_wq",
5777 phba->shost->host_no);
5778 phba->wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 1, phba->wq_name);
5780 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5781 "BM_%d : beiscsi_dev_probe-"
5782 "Failed to allocate work queue\n");
5786 INIT_DELAYED_WORK(&phba->eqd_update, beiscsi_eqd_update_work);
5788 phwi_ctrlr = phba->phwi_ctrlr;
5789 phwi_context = phwi_ctrlr->phwi_ctxt;
5791 for (i = 0; i < phba->num_cpus; i++) {
5792 pbe_eq = &phwi_context->be_eq[i];
5793 irq_poll_init(&pbe_eq->iopoll, be_iopoll_budget, be_iopoll);
5796 i = (phba->msix_enabled) ? i : 0;
5797 /* Work item for MCC handling */
5798 pbe_eq = &phwi_context->be_eq[i];
5799 INIT_WORK(&pbe_eq->mcc_work, beiscsi_mcc_work);
5801 ret = beiscsi_init_irqs(phba);
5803 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5804 "BM_%d : beiscsi_dev_probe-"
5805 "Failed to beiscsi_init_irqs\n");
5808 hwi_enable_intr(phba);
5810 ret = iscsi_host_add(phba->shost, &phba->pcidev->dev);
5814 /* set online bit after port is operational */
5815 set_bit(BEISCSI_HBA_ONLINE, &phba->state);
5816 __beiscsi_log(phba, KERN_INFO,
5817 "BM_%d : port online: 0x%lx\n", phba->state);
5819 INIT_WORK(&phba->boot_work, beiscsi_boot_work);
5820 ret = beiscsi_boot_get_shandle(phba, &s_handle);
5822 beiscsi_start_boot_work(phba, s_handle);
5824 * Set this bit after starting the work to let
5825 * probe handle it first.
5826 * ASYNC event can too schedule this work.
5828 set_bit(BEISCSI_HBA_BOOT_FOUND, &phba->state);
5831 beiscsi_iface_create_default(phba);
5832 schedule_delayed_work(&phba->eqd_update,
5833 msecs_to_jiffies(BEISCSI_EQD_UPDATE_INTERVAL));
5835 INIT_DELAYED_WORK(&phba->recover_port, beiscsi_recover_port);
5837 * Start UE detection here. UE before this will cause stall in probe
5838 * and eventually fail the probe.
5840 init_timer(&phba->hw_check);
5841 phba->hw_check.function = beiscsi_hw_health_check;
5842 phba->hw_check.data = (unsigned long)phba;
5843 mod_timer(&phba->hw_check,
5844 jiffies + msecs_to_jiffies(BEISCSI_UE_DETECT_INTERVAL));
5846 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
5847 "\n\n\n BM_%d : SUCCESS - DRIVER LOADED\n\n\n");
5851 destroy_workqueue(phba->wq);
5852 for (i = 0; i < phba->num_cpus; i++) {
5853 pbe_eq = &phwi_context->be_eq[i];
5854 irq_poll_disable(&pbe_eq->iopoll);
5857 hwi_cleanup_port(phba);
5858 beiscsi_cleanup_port(phba);
5859 beiscsi_free_mem(phba);
5861 pci_free_consistent(phba->pcidev,
5862 phba->ctrl.mbox_mem_alloced.size,
5863 phba->ctrl.mbox_mem_alloced.va,
5864 phba->ctrl.mbox_mem_alloced.dma);
5865 beiscsi_unmap_pci_function(phba);
5867 if (phba->msix_enabled)
5868 pci_disable_msix(phba->pcidev);
5869 pci_dev_put(phba->pcidev);
5870 iscsi_host_free(phba->shost);
5871 pci_set_drvdata(pcidev, NULL);
5873 pci_release_regions(pcidev);
5874 pci_disable_device(pcidev);
5878 static void beiscsi_remove(struct pci_dev *pcidev)
5880 struct beiscsi_hba *phba = NULL;
5882 phba = pci_get_drvdata(pcidev);
5884 dev_err(&pcidev->dev, "beiscsi_remove called with no phba\n");
5888 /* first stop UE detection before unloading */
5889 del_timer_sync(&phba->hw_check);
5890 cancel_delayed_work_sync(&phba->recover_port);
5892 beiscsi_iface_destroy_default(phba);
5893 iscsi_host_remove(phba->shost);
5894 beiscsi_disable_port(phba, 1);
5896 /* after cancelling boot_work */
5897 iscsi_boot_destroy_kset(phba->boot_struct.boot_kset);
5899 /* free all resources */
5900 destroy_workqueue(phba->wq);
5901 beiscsi_cleanup_port(phba);
5902 beiscsi_free_mem(phba);
5905 beiscsi_unmap_pci_function(phba);
5906 pci_free_consistent(phba->pcidev,
5907 phba->ctrl.mbox_mem_alloced.size,
5908 phba->ctrl.mbox_mem_alloced.va,
5909 phba->ctrl.mbox_mem_alloced.dma);
5911 pci_dev_put(phba->pcidev);
5912 iscsi_host_free(phba->shost);
5913 pci_disable_pcie_error_reporting(pcidev);
5914 pci_set_drvdata(pcidev, NULL);
5915 pci_release_regions(pcidev);
5916 pci_disable_device(pcidev);
5920 static struct pci_error_handlers beiscsi_eeh_handlers = {
5921 .error_detected = beiscsi_eeh_err_detected,
5922 .slot_reset = beiscsi_eeh_reset,
5923 .resume = beiscsi_eeh_resume,
5926 struct iscsi_transport beiscsi_iscsi_transport = {
5927 .owner = THIS_MODULE,
5929 .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_TEXT_NEGO |
5930 CAP_MULTI_R2T | CAP_DATADGST | CAP_DATA_PATH_OFFLOAD,
5931 .create_session = beiscsi_session_create,
5932 .destroy_session = beiscsi_session_destroy,
5933 .create_conn = beiscsi_conn_create,
5934 .bind_conn = beiscsi_conn_bind,
5935 .destroy_conn = iscsi_conn_teardown,
5936 .attr_is_visible = beiscsi_attr_is_visible,
5937 .set_iface_param = beiscsi_iface_set_param,
5938 .get_iface_param = beiscsi_iface_get_param,
5939 .set_param = beiscsi_set_param,
5940 .get_conn_param = iscsi_conn_get_param,
5941 .get_session_param = iscsi_session_get_param,
5942 .get_host_param = beiscsi_get_host_param,
5943 .start_conn = beiscsi_conn_start,
5944 .stop_conn = iscsi_conn_stop,
5945 .send_pdu = iscsi_conn_send_pdu,
5946 .xmit_task = beiscsi_task_xmit,
5947 .cleanup_task = beiscsi_cleanup_task,
5948 .alloc_pdu = beiscsi_alloc_pdu,
5949 .parse_pdu_itt = beiscsi_parse_pdu,
5950 .get_stats = beiscsi_conn_get_stats,
5951 .get_ep_param = beiscsi_ep_get_param,
5952 .ep_connect = beiscsi_ep_connect,
5953 .ep_poll = beiscsi_ep_poll,
5954 .ep_disconnect = beiscsi_ep_disconnect,
5955 .session_recovery_timedout = iscsi_session_recovery_timedout,
5956 .bsg_request = beiscsi_bsg_request,
5959 static struct pci_driver beiscsi_pci_driver = {
5961 .probe = beiscsi_dev_probe,
5962 .remove = beiscsi_remove,
5963 .id_table = beiscsi_pci_id_table,
5964 .err_handler = &beiscsi_eeh_handlers
5967 static int __init beiscsi_module_init(void)
5971 beiscsi_scsi_transport =
5972 iscsi_register_transport(&beiscsi_iscsi_transport);
5973 if (!beiscsi_scsi_transport) {
5975 "beiscsi_module_init - Unable to register beiscsi transport.\n");
5978 printk(KERN_INFO "In beiscsi_module_init, tt=%p\n",
5979 &beiscsi_iscsi_transport);
5981 ret = pci_register_driver(&beiscsi_pci_driver);
5984 "beiscsi_module_init - Unable to register beiscsi pci driver.\n");
5985 goto unregister_iscsi_transport;
5989 unregister_iscsi_transport:
5990 iscsi_unregister_transport(&beiscsi_iscsi_transport);
5994 static void __exit beiscsi_module_exit(void)
5996 pci_unregister_driver(&beiscsi_pci_driver);
5997 iscsi_unregister_transport(&beiscsi_iscsi_transport);
6000 module_init(beiscsi_module_init);
6001 module_exit(beiscsi_module_exit);