2 * Copyright (C) 2005 - 2011 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@emulex.com)
12 * Contact Information:
13 * linux-drivers@emulex.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>
33 #include <scsi/libiscsi.h>
34 #include <scsi/scsi_bsg_iscsi.h>
35 #include <scsi/scsi_netlink.h>
36 #include <scsi/scsi_transport_iscsi.h>
37 #include <scsi/scsi_transport.h>
38 #include <scsi/scsi_cmnd.h>
39 #include <scsi/scsi_device.h>
40 #include <scsi/scsi_host.h>
41 #include <scsi/scsi.h>
47 static unsigned int be_iopoll_budget = 10;
48 static unsigned int be_max_phys_size = 64;
49 static unsigned int enable_msix = 1;
51 MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
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");
154 DEVICE_ATTR(beiscsi_drvr_ver, S_IRUGO, beiscsi_drvr_ver_disp, NULL);
155 struct device_attribute *beiscsi_attrs[] = {
156 &dev_attr_beiscsi_log_enable,
157 &dev_attr_beiscsi_drvr_ver,
161 static char const *cqe_desc[] = {
164 "SOL_CMD_KILLED_DATA_DIGEST_ERR",
165 "CXN_KILLED_PDU_SIZE_EXCEEDS_DSL",
166 "CXN_KILLED_BURST_LEN_MISMATCH",
167 "CXN_KILLED_AHS_RCVD",
168 "CXN_KILLED_HDR_DIGEST_ERR",
169 "CXN_KILLED_UNKNOWN_HDR",
170 "CXN_KILLED_STALE_ITT_TTT_RCVD",
171 "CXN_KILLED_INVALID_ITT_TTT_RCVD",
172 "CXN_KILLED_RST_RCVD",
173 "CXN_KILLED_TIMED_OUT",
174 "CXN_KILLED_RST_SENT",
175 "CXN_KILLED_FIN_RCVD",
176 "CXN_KILLED_BAD_UNSOL_PDU_RCVD",
177 "CXN_KILLED_BAD_WRB_INDEX_ERROR",
178 "CXN_KILLED_OVER_RUN_RESIDUAL",
179 "CXN_KILLED_UNDER_RUN_RESIDUAL",
180 "CMD_KILLED_INVALID_STATSN_RCVD",
181 "CMD_KILLED_INVALID_R2T_RCVD",
182 "CMD_CXN_KILLED_LUN_INVALID",
183 "CMD_CXN_KILLED_ICD_INVALID",
184 "CMD_CXN_KILLED_ITT_INVALID",
185 "CMD_CXN_KILLED_SEQ_OUTOFORDER",
186 "CMD_CXN_KILLED_INVALID_DATASN_RCVD",
187 "CXN_INVALIDATE_NOTIFY",
188 "CXN_INVALIDATE_INDEX_NOTIFY",
189 "CMD_INVALIDATED_NOTIFY",
192 "UNSOL_DATA_DIGEST_ERROR_NOTIFY",
194 "CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN",
195 "SOL_CMD_KILLED_DIF_ERR",
196 "CXN_KILLED_SYN_RCVD",
197 "CXN_KILLED_IMM_DATA_RCVD"
200 static int beiscsi_slave_configure(struct scsi_device *sdev)
202 blk_queue_max_segment_size(sdev->request_queue, 65536);
206 static int beiscsi_eh_abort(struct scsi_cmnd *sc)
208 struct iscsi_cls_session *cls_session;
209 struct iscsi_task *aborted_task = (struct iscsi_task *)sc->SCp.ptr;
210 struct beiscsi_io_task *aborted_io_task;
211 struct iscsi_conn *conn;
212 struct beiscsi_conn *beiscsi_conn;
213 struct beiscsi_hba *phba;
214 struct iscsi_session *session;
215 struct invalidate_command_table *inv_tbl;
216 struct be_dma_mem nonemb_cmd;
217 unsigned int cid, tag, num_invalidate;
219 cls_session = starget_to_session(scsi_target(sc->device));
220 session = cls_session->dd_data;
222 spin_lock_bh(&session->lock);
223 if (!aborted_task || !aborted_task->sc) {
225 spin_unlock_bh(&session->lock);
229 aborted_io_task = aborted_task->dd_data;
230 if (!aborted_io_task->scsi_cmnd) {
231 /* raced or invalid command */
232 spin_unlock_bh(&session->lock);
235 spin_unlock_bh(&session->lock);
236 conn = aborted_task->conn;
237 beiscsi_conn = conn->dd_data;
238 phba = beiscsi_conn->phba;
240 /* invalidate iocb */
241 cid = beiscsi_conn->beiscsi_conn_cid;
242 inv_tbl = phba->inv_tbl;
243 memset(inv_tbl, 0x0, sizeof(*inv_tbl));
245 inv_tbl->icd = aborted_io_task->psgl_handle->sgl_index;
247 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
248 sizeof(struct invalidate_commands_params_in),
250 if (nonemb_cmd.va == NULL) {
251 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
252 "BM_%d : Failed to allocate memory for"
253 "mgmt_invalidate_icds\n");
256 nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
258 tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
261 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH,
262 "BM_%d : mgmt_invalidate_icds could not be"
264 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
265 nonemb_cmd.va, nonemb_cmd.dma);
269 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
270 phba->ctrl.mcc_numtag[tag]);
271 free_mcc_tag(&phba->ctrl, tag);
273 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
274 nonemb_cmd.va, nonemb_cmd.dma);
275 return iscsi_eh_abort(sc);
278 static int beiscsi_eh_device_reset(struct scsi_cmnd *sc)
280 struct iscsi_task *abrt_task;
281 struct beiscsi_io_task *abrt_io_task;
282 struct iscsi_conn *conn;
283 struct beiscsi_conn *beiscsi_conn;
284 struct beiscsi_hba *phba;
285 struct iscsi_session *session;
286 struct iscsi_cls_session *cls_session;
287 struct invalidate_command_table *inv_tbl;
288 struct be_dma_mem nonemb_cmd;
289 unsigned int cid, tag, i, num_invalidate;
291 /* invalidate iocbs */
292 cls_session = starget_to_session(scsi_target(sc->device));
293 session = cls_session->dd_data;
294 spin_lock_bh(&session->lock);
295 if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN) {
296 spin_unlock_bh(&session->lock);
299 conn = session->leadconn;
300 beiscsi_conn = conn->dd_data;
301 phba = beiscsi_conn->phba;
302 cid = beiscsi_conn->beiscsi_conn_cid;
303 inv_tbl = phba->inv_tbl;
304 memset(inv_tbl, 0x0, sizeof(*inv_tbl) * BE2_CMDS_PER_CXN);
306 for (i = 0; i < conn->session->cmds_max; i++) {
307 abrt_task = conn->session->cmds[i];
308 abrt_io_task = abrt_task->dd_data;
309 if (!abrt_task->sc || abrt_task->state == ISCSI_TASK_FREE)
312 if (abrt_task->sc->device->lun != abrt_task->sc->device->lun)
316 inv_tbl->icd = abrt_io_task->psgl_handle->sgl_index;
320 spin_unlock_bh(&session->lock);
321 inv_tbl = phba->inv_tbl;
323 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
324 sizeof(struct invalidate_commands_params_in),
326 if (nonemb_cmd.va == NULL) {
327 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
328 "BM_%d : Failed to allocate memory for"
329 "mgmt_invalidate_icds\n");
332 nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
333 memset(nonemb_cmd.va, 0, nonemb_cmd.size);
334 tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
337 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH,
338 "BM_%d : mgmt_invalidate_icds could not be"
340 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
341 nonemb_cmd.va, nonemb_cmd.dma);
344 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
345 phba->ctrl.mcc_numtag[tag]);
346 free_mcc_tag(&phba->ctrl, tag);
348 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
349 nonemb_cmd.va, nonemb_cmd.dma);
350 return iscsi_eh_device_reset(sc);
353 static ssize_t beiscsi_show_boot_tgt_info(void *data, int type, char *buf)
355 struct beiscsi_hba *phba = data;
356 struct mgmt_session_info *boot_sess = &phba->boot_sess;
357 struct mgmt_conn_info *boot_conn = &boot_sess->conn_list[0];
362 case ISCSI_BOOT_TGT_NAME:
363 rc = sprintf(buf, "%.*s\n",
364 (int)strlen(boot_sess->target_name),
365 (char *)&boot_sess->target_name);
367 case ISCSI_BOOT_TGT_IP_ADDR:
368 if (boot_conn->dest_ipaddr.ip_type == 0x1)
369 rc = sprintf(buf, "%pI4\n",
370 (char *)&boot_conn->dest_ipaddr.addr);
372 rc = sprintf(str, "%pI6\n",
373 (char *)&boot_conn->dest_ipaddr.addr);
375 case ISCSI_BOOT_TGT_PORT:
376 rc = sprintf(str, "%d\n", boot_conn->dest_port);
379 case ISCSI_BOOT_TGT_CHAP_NAME:
380 rc = sprintf(str, "%.*s\n",
381 boot_conn->negotiated_login_options.auth_data.chap.
382 target_chap_name_length,
383 (char *)&boot_conn->negotiated_login_options.
384 auth_data.chap.target_chap_name);
386 case ISCSI_BOOT_TGT_CHAP_SECRET:
387 rc = sprintf(str, "%.*s\n",
388 boot_conn->negotiated_login_options.auth_data.chap.
389 target_secret_length,
390 (char *)&boot_conn->negotiated_login_options.
391 auth_data.chap.target_secret);
393 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
394 rc = sprintf(str, "%.*s\n",
395 boot_conn->negotiated_login_options.auth_data.chap.
396 intr_chap_name_length,
397 (char *)&boot_conn->negotiated_login_options.
398 auth_data.chap.intr_chap_name);
400 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
401 rc = sprintf(str, "%.*s\n",
402 boot_conn->negotiated_login_options.auth_data.chap.
404 (char *)&boot_conn->negotiated_login_options.
405 auth_data.chap.intr_secret);
407 case ISCSI_BOOT_TGT_FLAGS:
408 rc = sprintf(str, "2\n");
410 case ISCSI_BOOT_TGT_NIC_ASSOC:
411 rc = sprintf(str, "0\n");
420 static ssize_t beiscsi_show_boot_ini_info(void *data, int type, char *buf)
422 struct beiscsi_hba *phba = data;
427 case ISCSI_BOOT_INI_INITIATOR_NAME:
428 rc = sprintf(str, "%s\n", phba->boot_sess.initiator_iscsiname);
437 static ssize_t beiscsi_show_boot_eth_info(void *data, int type, char *buf)
439 struct beiscsi_hba *phba = data;
444 case ISCSI_BOOT_ETH_FLAGS:
445 rc = sprintf(str, "2\n");
447 case ISCSI_BOOT_ETH_INDEX:
448 rc = sprintf(str, "0\n");
450 case ISCSI_BOOT_ETH_MAC:
451 rc = beiscsi_get_macaddr(str, phba);
461 static umode_t beiscsi_tgt_get_attr_visibility(void *data, int type)
466 case ISCSI_BOOT_TGT_NAME:
467 case ISCSI_BOOT_TGT_IP_ADDR:
468 case ISCSI_BOOT_TGT_PORT:
469 case ISCSI_BOOT_TGT_CHAP_NAME:
470 case ISCSI_BOOT_TGT_CHAP_SECRET:
471 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
472 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
473 case ISCSI_BOOT_TGT_NIC_ASSOC:
474 case ISCSI_BOOT_TGT_FLAGS:
484 static umode_t beiscsi_ini_get_attr_visibility(void *data, int type)
489 case ISCSI_BOOT_INI_INITIATOR_NAME:
500 static umode_t beiscsi_eth_get_attr_visibility(void *data, int type)
505 case ISCSI_BOOT_ETH_FLAGS:
506 case ISCSI_BOOT_ETH_MAC:
507 case ISCSI_BOOT_ETH_INDEX:
517 /*------------------- PCI Driver operations and data ----------------- */
518 static DEFINE_PCI_DEVICE_TABLE(beiscsi_pci_id_table) = {
519 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) },
520 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) },
521 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) },
522 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) },
523 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID3) },
526 MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
529 static struct scsi_host_template beiscsi_sht = {
530 .module = THIS_MODULE,
531 .name = "Emulex 10Gbe open-iscsi Initiator Driver",
532 .proc_name = DRV_NAME,
533 .queuecommand = iscsi_queuecommand,
534 .change_queue_depth = iscsi_change_queue_depth,
535 .slave_configure = beiscsi_slave_configure,
536 .target_alloc = iscsi_target_alloc,
537 .eh_abort_handler = beiscsi_eh_abort,
538 .eh_device_reset_handler = beiscsi_eh_device_reset,
539 .eh_target_reset_handler = iscsi_eh_session_reset,
540 .shost_attrs = beiscsi_attrs,
541 .sg_tablesize = BEISCSI_SGLIST_ELEMENTS,
542 .can_queue = BE2_IO_DEPTH,
544 .max_sectors = BEISCSI_MAX_SECTORS,
545 .cmd_per_lun = BEISCSI_CMD_PER_LUN,
546 .use_clustering = ENABLE_CLUSTERING,
547 .vendor_id = SCSI_NL_VID_TYPE_PCI | BE_VENDOR_ID,
551 static struct scsi_transport_template *beiscsi_scsi_transport;
553 static struct beiscsi_hba *beiscsi_hba_alloc(struct pci_dev *pcidev)
555 struct beiscsi_hba *phba;
556 struct Scsi_Host *shost;
558 shost = iscsi_host_alloc(&beiscsi_sht, sizeof(*phba), 0);
560 dev_err(&pcidev->dev,
561 "beiscsi_hba_alloc - iscsi_host_alloc failed\n");
564 shost->dma_boundary = pcidev->dma_mask;
565 shost->max_id = BE2_MAX_SESSIONS;
566 shost->max_channel = 0;
567 shost->max_cmd_len = BEISCSI_MAX_CMD_LEN;
568 shost->max_lun = BEISCSI_NUM_MAX_LUN;
569 shost->transportt = beiscsi_scsi_transport;
570 phba = iscsi_host_priv(shost);
571 memset(phba, 0, sizeof(*phba));
573 phba->pcidev = pci_dev_get(pcidev);
574 pci_set_drvdata(pcidev, phba);
575 phba->interface_handle = 0xFFFFFFFF;
577 if (iscsi_host_add(shost, &phba->pcidev->dev))
583 pci_dev_put(phba->pcidev);
584 iscsi_host_free(phba->shost);
588 static void beiscsi_unmap_pci_function(struct beiscsi_hba *phba)
591 iounmap(phba->csr_va);
595 iounmap(phba->db_va);
599 iounmap(phba->pci_va);
604 static int beiscsi_map_pci_bars(struct beiscsi_hba *phba,
605 struct pci_dev *pcidev)
610 addr = ioremap_nocache(pci_resource_start(pcidev, 2),
611 pci_resource_len(pcidev, 2));
614 phba->ctrl.csr = addr;
616 phba->csr_pa.u.a64.address = pci_resource_start(pcidev, 2);
618 addr = ioremap_nocache(pci_resource_start(pcidev, 4), 128 * 1024);
621 phba->ctrl.db = addr;
623 phba->db_pa.u.a64.address = pci_resource_start(pcidev, 4);
625 if (phba->generation == BE_GEN2)
630 addr = ioremap_nocache(pci_resource_start(pcidev, pcicfg_reg),
631 pci_resource_len(pcidev, pcicfg_reg));
635 phba->ctrl.pcicfg = addr;
637 phba->pci_pa.u.a64.address = pci_resource_start(pcidev, pcicfg_reg);
641 beiscsi_unmap_pci_function(phba);
645 static int beiscsi_enable_pci(struct pci_dev *pcidev)
649 ret = pci_enable_device(pcidev);
651 dev_err(&pcidev->dev,
652 "beiscsi_enable_pci - enable device failed\n");
656 pci_set_master(pcidev);
657 if (pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64))) {
658 ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(32));
660 dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n");
661 pci_disable_device(pcidev);
668 static int be_ctrl_init(struct beiscsi_hba *phba, struct pci_dev *pdev)
670 struct be_ctrl_info *ctrl = &phba->ctrl;
671 struct be_dma_mem *mbox_mem_alloc = &ctrl->mbox_mem_alloced;
672 struct be_dma_mem *mbox_mem_align = &ctrl->mbox_mem;
676 status = beiscsi_map_pci_bars(phba, pdev);
679 mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16;
680 mbox_mem_alloc->va = pci_alloc_consistent(pdev,
681 mbox_mem_alloc->size,
682 &mbox_mem_alloc->dma);
683 if (!mbox_mem_alloc->va) {
684 beiscsi_unmap_pci_function(phba);
688 mbox_mem_align->size = sizeof(struct be_mcc_mailbox);
689 mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16);
690 mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16);
691 memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox));
692 spin_lock_init(&ctrl->mbox_lock);
693 spin_lock_init(&phba->ctrl.mcc_lock);
694 spin_lock_init(&phba->ctrl.mcc_cq_lock);
699 static void beiscsi_get_params(struct beiscsi_hba *phba)
701 phba->params.ios_per_ctrl = (phba->fw_config.iscsi_icd_count
702 - (phba->fw_config.iscsi_cid_count
705 phba->params.cxns_per_ctrl = phba->fw_config.iscsi_cid_count;
706 phba->params.asyncpdus_per_ctrl = phba->fw_config.iscsi_cid_count * 2;
707 phba->params.icds_per_ctrl = phba->fw_config.iscsi_icd_count;
708 phba->params.num_sge_per_io = BE2_SGE;
709 phba->params.defpdu_hdr_sz = BE2_DEFPDU_HDR_SZ;
710 phba->params.defpdu_data_sz = BE2_DEFPDU_DATA_SZ;
711 phba->params.eq_timer = 64;
712 phba->params.num_eq_entries =
713 (((BE2_CMDS_PER_CXN * 2 + phba->fw_config.iscsi_cid_count * 2
714 + BE2_TMFS) / 512) + 1) * 512;
715 phba->params.num_eq_entries = (phba->params.num_eq_entries < 1024)
716 ? 1024 : phba->params.num_eq_entries;
717 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
718 "BM_%d : phba->params.num_eq_entries=%d\n",
719 phba->params.num_eq_entries);
720 phba->params.num_cq_entries =
721 (((BE2_CMDS_PER_CXN * 2 + phba->fw_config.iscsi_cid_count * 2
722 + BE2_TMFS) / 512) + 1) * 512;
723 phba->params.wrbs_per_cxn = 256;
726 static void hwi_ring_eq_db(struct beiscsi_hba *phba,
727 unsigned int id, unsigned int clr_interrupt,
728 unsigned int num_processed,
729 unsigned char rearm, unsigned char event)
732 val |= id & DB_EQ_RING_ID_MASK;
734 val |= 1 << DB_EQ_REARM_SHIFT;
736 val |= 1 << DB_EQ_CLR_SHIFT;
738 val |= 1 << DB_EQ_EVNT_SHIFT;
739 val |= num_processed << DB_EQ_NUM_POPPED_SHIFT;
740 iowrite32(val, phba->db_va + DB_EQ_OFFSET);
744 * be_isr_mcc - The isr routine of the driver.
746 * @dev_id: Pointer to host adapter structure
748 static irqreturn_t be_isr_mcc(int irq, void *dev_id)
750 struct beiscsi_hba *phba;
751 struct be_eq_entry *eqe = NULL;
752 struct be_queue_info *eq;
753 struct be_queue_info *mcc;
754 unsigned int num_eq_processed;
755 struct be_eq_obj *pbe_eq;
761 mcc = &phba->ctrl.mcc_obj.cq;
762 eqe = queue_tail_node(eq);
764 num_eq_processed = 0;
766 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
768 if (((eqe->dw[offsetof(struct amap_eq_entry,
770 EQE_RESID_MASK) >> 16) == mcc->id) {
771 spin_lock_irqsave(&phba->isr_lock, flags);
772 pbe_eq->todo_mcc_cq = true;
773 spin_unlock_irqrestore(&phba->isr_lock, flags);
775 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
777 eqe = queue_tail_node(eq);
780 if (pbe_eq->todo_mcc_cq)
781 queue_work(phba->wq, &pbe_eq->work_cqs);
782 if (num_eq_processed)
783 hwi_ring_eq_db(phba, eq->id, 1, num_eq_processed, 1, 1);
789 * be_isr_msix - The isr routine of the driver.
791 * @dev_id: Pointer to host adapter structure
793 static irqreturn_t be_isr_msix(int irq, void *dev_id)
795 struct beiscsi_hba *phba;
796 struct be_eq_entry *eqe = NULL;
797 struct be_queue_info *eq;
798 struct be_queue_info *cq;
799 unsigned int num_eq_processed;
800 struct be_eq_obj *pbe_eq;
806 eqe = queue_tail_node(eq);
809 num_eq_processed = 0;
810 if (blk_iopoll_enabled) {
811 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
813 if (!blk_iopoll_sched_prep(&pbe_eq->iopoll))
814 blk_iopoll_sched(&pbe_eq->iopoll);
816 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
818 eqe = queue_tail_node(eq);
822 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
824 spin_lock_irqsave(&phba->isr_lock, flags);
825 pbe_eq->todo_cq = true;
826 spin_unlock_irqrestore(&phba->isr_lock, flags);
827 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
829 eqe = queue_tail_node(eq);
834 queue_work(phba->wq, &pbe_eq->work_cqs);
837 if (num_eq_processed)
838 hwi_ring_eq_db(phba, eq->id, 1, num_eq_processed, 0, 1);
844 * be_isr - The isr routine of the driver.
846 * @dev_id: Pointer to host adapter structure
848 static irqreturn_t be_isr(int irq, void *dev_id)
850 struct beiscsi_hba *phba;
851 struct hwi_controller *phwi_ctrlr;
852 struct hwi_context_memory *phwi_context;
853 struct be_eq_entry *eqe = NULL;
854 struct be_queue_info *eq;
855 struct be_queue_info *cq;
856 struct be_queue_info *mcc;
857 unsigned long flags, index;
858 unsigned int num_mcceq_processed, num_ioeq_processed;
859 struct be_ctrl_info *ctrl;
860 struct be_eq_obj *pbe_eq;
865 isr = ioread32(ctrl->csr + CEV_ISR0_OFFSET +
866 (PCI_FUNC(ctrl->pdev->devfn) * CEV_ISR_SIZE));
870 phwi_ctrlr = phba->phwi_ctrlr;
871 phwi_context = phwi_ctrlr->phwi_ctxt;
872 pbe_eq = &phwi_context->be_eq[0];
874 eq = &phwi_context->be_eq[0].q;
875 mcc = &phba->ctrl.mcc_obj.cq;
877 eqe = queue_tail_node(eq);
879 num_ioeq_processed = 0;
880 num_mcceq_processed = 0;
881 if (blk_iopoll_enabled) {
882 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
884 if (((eqe->dw[offsetof(struct amap_eq_entry,
886 EQE_RESID_MASK) >> 16) == mcc->id) {
887 spin_lock_irqsave(&phba->isr_lock, flags);
888 pbe_eq->todo_mcc_cq = true;
889 spin_unlock_irqrestore(&phba->isr_lock, flags);
890 num_mcceq_processed++;
892 if (!blk_iopoll_sched_prep(&pbe_eq->iopoll))
893 blk_iopoll_sched(&pbe_eq->iopoll);
894 num_ioeq_processed++;
896 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
898 eqe = queue_tail_node(eq);
900 if (num_ioeq_processed || num_mcceq_processed) {
901 if (pbe_eq->todo_mcc_cq)
902 queue_work(phba->wq, &pbe_eq->work_cqs);
904 if ((num_mcceq_processed) && (!num_ioeq_processed))
905 hwi_ring_eq_db(phba, eq->id, 0,
906 (num_ioeq_processed +
907 num_mcceq_processed) , 1, 1);
909 hwi_ring_eq_db(phba, eq->id, 0,
910 (num_ioeq_processed +
911 num_mcceq_processed), 0, 1);
917 cq = &phwi_context->be_cq[0];
918 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
921 if (((eqe->dw[offsetof(struct amap_eq_entry,
923 EQE_RESID_MASK) >> 16) != cq->id) {
924 spin_lock_irqsave(&phba->isr_lock, flags);
925 pbe_eq->todo_mcc_cq = true;
926 spin_unlock_irqrestore(&phba->isr_lock, flags);
928 spin_lock_irqsave(&phba->isr_lock, flags);
929 pbe_eq->todo_cq = true;
930 spin_unlock_irqrestore(&phba->isr_lock, flags);
932 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
934 eqe = queue_tail_node(eq);
935 num_ioeq_processed++;
937 if (pbe_eq->todo_cq || pbe_eq->todo_mcc_cq)
938 queue_work(phba->wq, &pbe_eq->work_cqs);
940 if (num_ioeq_processed) {
941 hwi_ring_eq_db(phba, eq->id, 0,
942 num_ioeq_processed, 1, 1);
949 static int beiscsi_init_irqs(struct beiscsi_hba *phba)
951 struct pci_dev *pcidev = phba->pcidev;
952 struct hwi_controller *phwi_ctrlr;
953 struct hwi_context_memory *phwi_context;
954 int ret, msix_vec, i, j;
956 phwi_ctrlr = phba->phwi_ctrlr;
957 phwi_context = phwi_ctrlr->phwi_ctxt;
959 if (phba->msix_enabled) {
960 for (i = 0; i < phba->num_cpus; i++) {
961 phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME,
963 if (!phba->msi_name[i]) {
968 sprintf(phba->msi_name[i], "beiscsi_%02x_%02x",
969 phba->shost->host_no, i);
970 msix_vec = phba->msix_entries[i].vector;
971 ret = request_irq(msix_vec, be_isr_msix, 0,
973 &phwi_context->be_eq[i]);
975 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
976 "BM_%d : beiscsi_init_irqs-Failed to"
977 "register msix for i = %d\n",
979 kfree(phba->msi_name[i]);
983 phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME, GFP_KERNEL);
984 if (!phba->msi_name[i]) {
988 sprintf(phba->msi_name[i], "beiscsi_mcc_%02x",
989 phba->shost->host_no);
990 msix_vec = phba->msix_entries[i].vector;
991 ret = request_irq(msix_vec, be_isr_mcc, 0, phba->msi_name[i],
992 &phwi_context->be_eq[i]);
994 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT ,
995 "BM_%d : beiscsi_init_irqs-"
996 "Failed to register beiscsi_msix_mcc\n");
997 kfree(phba->msi_name[i]);
1002 ret = request_irq(pcidev->irq, be_isr, IRQF_SHARED,
1005 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
1006 "BM_%d : beiscsi_init_irqs-"
1007 "Failed to register irq\\n");
1013 for (j = i - 1; j >= 0; j--) {
1014 kfree(phba->msi_name[j]);
1015 msix_vec = phba->msix_entries[j].vector;
1016 free_irq(msix_vec, &phwi_context->be_eq[j]);
1021 static void hwi_ring_cq_db(struct beiscsi_hba *phba,
1022 unsigned int id, unsigned int num_processed,
1023 unsigned char rearm, unsigned char event)
1026 val |= id & DB_CQ_RING_ID_MASK;
1028 val |= 1 << DB_CQ_REARM_SHIFT;
1029 val |= num_processed << DB_CQ_NUM_POPPED_SHIFT;
1030 iowrite32(val, phba->db_va + DB_CQ_OFFSET);
1034 beiscsi_process_async_pdu(struct beiscsi_conn *beiscsi_conn,
1035 struct beiscsi_hba *phba,
1037 struct pdu_base *ppdu,
1038 unsigned long pdu_len,
1039 void *pbuffer, unsigned long buf_len)
1041 struct iscsi_conn *conn = beiscsi_conn->conn;
1042 struct iscsi_session *session = conn->session;
1043 struct iscsi_task *task;
1044 struct beiscsi_io_task *io_task;
1045 struct iscsi_hdr *login_hdr;
1047 switch (ppdu->dw[offsetof(struct amap_pdu_base, opcode) / 32] &
1048 PDUBASE_OPCODE_MASK) {
1049 case ISCSI_OP_NOOP_IN:
1053 case ISCSI_OP_ASYNC_EVENT:
1055 case ISCSI_OP_REJECT:
1057 WARN_ON(!(buf_len == 48));
1058 beiscsi_log(phba, KERN_ERR,
1059 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1060 "BM_%d : In ISCSI_OP_REJECT\n");
1062 case ISCSI_OP_LOGIN_RSP:
1063 case ISCSI_OP_TEXT_RSP:
1064 task = conn->login_task;
1065 io_task = task->dd_data;
1066 login_hdr = (struct iscsi_hdr *)ppdu;
1067 login_hdr->itt = io_task->libiscsi_itt;
1070 beiscsi_log(phba, KERN_WARNING,
1071 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1072 "BM_%d : Unrecognized opcode 0x%x in async msg\n",
1074 dw[offsetof(struct amap_pdu_base, opcode) / 32]
1075 & PDUBASE_OPCODE_MASK));
1079 spin_lock_bh(&session->lock);
1080 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)ppdu, pbuffer, buf_len);
1081 spin_unlock_bh(&session->lock);
1085 static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba)
1087 struct sgl_handle *psgl_handle;
1089 if (phba->io_sgl_hndl_avbl) {
1090 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
1091 "BM_%d : In alloc_io_sgl_handle,"
1092 " io_sgl_alloc_index=%d\n",
1093 phba->io_sgl_alloc_index);
1095 psgl_handle = phba->io_sgl_hndl_base[phba->
1096 io_sgl_alloc_index];
1097 phba->io_sgl_hndl_base[phba->io_sgl_alloc_index] = NULL;
1098 phba->io_sgl_hndl_avbl--;
1099 if (phba->io_sgl_alloc_index == (phba->params.
1101 phba->io_sgl_alloc_index = 0;
1103 phba->io_sgl_alloc_index++;
1110 free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
1112 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
1113 "BM_%d : In free_,io_sgl_free_index=%d\n",
1114 phba->io_sgl_free_index);
1116 if (phba->io_sgl_hndl_base[phba->io_sgl_free_index]) {
1118 * this can happen if clean_task is called on a task that
1119 * failed in xmit_task or alloc_pdu.
1121 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
1122 "BM_%d : Double Free in IO SGL io_sgl_free_index=%d,"
1123 "value there=%p\n", phba->io_sgl_free_index,
1124 phba->io_sgl_hndl_base
1125 [phba->io_sgl_free_index]);
1128 phba->io_sgl_hndl_base[phba->io_sgl_free_index] = psgl_handle;
1129 phba->io_sgl_hndl_avbl++;
1130 if (phba->io_sgl_free_index == (phba->params.ios_per_ctrl - 1))
1131 phba->io_sgl_free_index = 0;
1133 phba->io_sgl_free_index++;
1137 * alloc_wrb_handle - To allocate a wrb handle
1138 * @phba: The hba pointer
1139 * @cid: The cid to use for allocation
1141 * This happens under session_lock until submission to chip
1143 struct wrb_handle *alloc_wrb_handle(struct beiscsi_hba *phba, unsigned int cid)
1145 struct hwi_wrb_context *pwrb_context;
1146 struct hwi_controller *phwi_ctrlr;
1147 struct wrb_handle *pwrb_handle, *pwrb_handle_tmp;
1149 phwi_ctrlr = phba->phwi_ctrlr;
1150 pwrb_context = &phwi_ctrlr->wrb_context[cid];
1151 if (pwrb_context->wrb_handles_available >= 2) {
1152 pwrb_handle = pwrb_context->pwrb_handle_base[
1153 pwrb_context->alloc_index];
1154 pwrb_context->wrb_handles_available--;
1155 if (pwrb_context->alloc_index ==
1156 (phba->params.wrbs_per_cxn - 1))
1157 pwrb_context->alloc_index = 0;
1159 pwrb_context->alloc_index++;
1160 pwrb_handle_tmp = pwrb_context->pwrb_handle_base[
1161 pwrb_context->alloc_index];
1162 pwrb_handle->nxt_wrb_index = pwrb_handle_tmp->wrb_index;
1169 * free_wrb_handle - To free the wrb handle back to pool
1170 * @phba: The hba pointer
1171 * @pwrb_context: The context to free from
1172 * @pwrb_handle: The wrb_handle to free
1174 * This happens under session_lock until submission to chip
1177 free_wrb_handle(struct beiscsi_hba *phba, struct hwi_wrb_context *pwrb_context,
1178 struct wrb_handle *pwrb_handle)
1180 pwrb_context->pwrb_handle_base[pwrb_context->free_index] = pwrb_handle;
1181 pwrb_context->wrb_handles_available++;
1182 if (pwrb_context->free_index == (phba->params.wrbs_per_cxn - 1))
1183 pwrb_context->free_index = 0;
1185 pwrb_context->free_index++;
1187 beiscsi_log(phba, KERN_INFO,
1188 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1189 "BM_%d : FREE WRB: pwrb_handle=%p free_index=0x%x"
1190 "wrb_handles_available=%d\n",
1191 pwrb_handle, pwrb_context->free_index,
1192 pwrb_context->wrb_handles_available);
1195 static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba)
1197 struct sgl_handle *psgl_handle;
1199 if (phba->eh_sgl_hndl_avbl) {
1200 psgl_handle = phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index];
1201 phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index] = NULL;
1202 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1203 "BM_%d : mgmt_sgl_alloc_index=%d=0x%x\n",
1204 phba->eh_sgl_alloc_index,
1205 phba->eh_sgl_alloc_index);
1207 phba->eh_sgl_hndl_avbl--;
1208 if (phba->eh_sgl_alloc_index ==
1209 (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl -
1211 phba->eh_sgl_alloc_index = 0;
1213 phba->eh_sgl_alloc_index++;
1220 free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
1223 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1224 "BM_%d : In free_mgmt_sgl_handle,"
1225 "eh_sgl_free_index=%d\n",
1226 phba->eh_sgl_free_index);
1228 if (phba->eh_sgl_hndl_base[phba->eh_sgl_free_index]) {
1230 * this can happen if clean_task is called on a task that
1231 * failed in xmit_task or alloc_pdu.
1233 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1234 "BM_%d : Double Free in eh SGL ,"
1235 "eh_sgl_free_index=%d\n",
1236 phba->eh_sgl_free_index);
1239 phba->eh_sgl_hndl_base[phba->eh_sgl_free_index] = psgl_handle;
1240 phba->eh_sgl_hndl_avbl++;
1241 if (phba->eh_sgl_free_index ==
1242 (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl - 1))
1243 phba->eh_sgl_free_index = 0;
1245 phba->eh_sgl_free_index++;
1249 be_complete_io(struct beiscsi_conn *beiscsi_conn,
1250 struct iscsi_task *task, struct sol_cqe *psol)
1252 struct beiscsi_io_task *io_task = task->dd_data;
1253 struct be_status_bhs *sts_bhs =
1254 (struct be_status_bhs *)io_task->cmd_bhs;
1255 struct iscsi_conn *conn = beiscsi_conn->conn;
1256 unsigned char *sense;
1257 u32 resid = 0, exp_cmdsn, max_cmdsn;
1258 u8 rsp, status, flags;
1261 dw[offsetof(struct amap_sol_cqe, i_exp_cmd_sn) / 32]
1262 & SOL_EXP_CMD_SN_MASK);
1263 max_cmdsn = ((psol->
1264 dw[offsetof(struct amap_sol_cqe, i_exp_cmd_sn) / 32]
1265 & SOL_EXP_CMD_SN_MASK) +
1266 ((psol->dw[offsetof(struct amap_sol_cqe, i_cmd_wnd)
1267 / 32] & SOL_CMD_WND_MASK) >> 24) - 1);
1268 rsp = ((psol->dw[offsetof(struct amap_sol_cqe, i_resp) / 32]
1269 & SOL_RESP_MASK) >> 16);
1270 status = ((psol->dw[offsetof(struct amap_sol_cqe, i_sts) / 32]
1271 & SOL_STS_MASK) >> 8);
1272 flags = ((psol->dw[offsetof(struct amap_sol_cqe, i_flags) / 32]
1273 & SOL_FLAGS_MASK) >> 24) | 0x80;
1275 if (io_task->scsi_cmnd)
1276 scsi_dma_unmap(io_task->scsi_cmnd);
1280 task->sc->result = (DID_OK << 16) | status;
1281 if (rsp != ISCSI_STATUS_CMD_COMPLETED) {
1282 task->sc->result = DID_ERROR << 16;
1286 /* bidi not initially supported */
1287 if (flags & (ISCSI_FLAG_CMD_UNDERFLOW | ISCSI_FLAG_CMD_OVERFLOW)) {
1288 resid = (psol->dw[offsetof(struct amap_sol_cqe, i_res_cnt) /
1289 32] & SOL_RES_CNT_MASK);
1291 if (!status && (flags & ISCSI_FLAG_CMD_OVERFLOW))
1292 task->sc->result = DID_ERROR << 16;
1294 if (flags & ISCSI_FLAG_CMD_UNDERFLOW) {
1295 scsi_set_resid(task->sc, resid);
1296 if (!status && (scsi_bufflen(task->sc) - resid <
1297 task->sc->underflow))
1298 task->sc->result = DID_ERROR << 16;
1302 if (status == SAM_STAT_CHECK_CONDITION) {
1304 unsigned short *slen = (unsigned short *)sts_bhs->sense_info;
1306 sense = sts_bhs->sense_info + sizeof(unsigned short);
1307 sense_len = be16_to_cpu(*slen);
1308 memcpy(task->sc->sense_buffer, sense,
1309 min_t(u16, sense_len, SCSI_SENSE_BUFFERSIZE));
1312 if (io_task->cmd_bhs->iscsi_hdr.flags & ISCSI_FLAG_CMD_READ) {
1313 if (psol->dw[offsetof(struct amap_sol_cqe, i_res_cnt) / 32]
1315 conn->rxdata_octets += (psol->
1316 dw[offsetof(struct amap_sol_cqe, i_res_cnt) / 32]
1317 & SOL_RES_CNT_MASK);
1320 scsi_dma_unmap(io_task->scsi_cmnd);
1321 iscsi_complete_scsi_task(task, exp_cmdsn, max_cmdsn);
1325 be_complete_logout(struct beiscsi_conn *beiscsi_conn,
1326 struct iscsi_task *task, struct sol_cqe *psol)
1328 struct iscsi_logout_rsp *hdr;
1329 struct beiscsi_io_task *io_task = task->dd_data;
1330 struct iscsi_conn *conn = beiscsi_conn->conn;
1332 hdr = (struct iscsi_logout_rsp *)task->hdr;
1333 hdr->opcode = ISCSI_OP_LOGOUT_RSP;
1336 hdr->flags = ((psol->dw[offsetof(struct amap_sol_cqe, i_flags) / 32]
1337 & SOL_FLAGS_MASK) >> 24) | 0x80;
1338 hdr->response = (psol->dw[offsetof(struct amap_sol_cqe, i_resp) /
1339 32] & SOL_RESP_MASK);
1340 hdr->exp_cmdsn = cpu_to_be32(psol->
1341 dw[offsetof(struct amap_sol_cqe, i_exp_cmd_sn) / 32]
1342 & SOL_EXP_CMD_SN_MASK);
1343 hdr->max_cmdsn = be32_to_cpu((psol->
1344 dw[offsetof(struct amap_sol_cqe, i_exp_cmd_sn) / 32]
1345 & SOL_EXP_CMD_SN_MASK) +
1346 ((psol->dw[offsetof(struct amap_sol_cqe, i_cmd_wnd)
1347 / 32] & SOL_CMD_WND_MASK) >> 24) - 1);
1348 hdr->dlength[0] = 0;
1349 hdr->dlength[1] = 0;
1350 hdr->dlength[2] = 0;
1352 hdr->itt = io_task->libiscsi_itt;
1353 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1357 be_complete_tmf(struct beiscsi_conn *beiscsi_conn,
1358 struct iscsi_task *task, struct sol_cqe *psol)
1360 struct iscsi_tm_rsp *hdr;
1361 struct iscsi_conn *conn = beiscsi_conn->conn;
1362 struct beiscsi_io_task *io_task = task->dd_data;
1364 hdr = (struct iscsi_tm_rsp *)task->hdr;
1365 hdr->opcode = ISCSI_OP_SCSI_TMFUNC_RSP;
1366 hdr->flags = ((psol->dw[offsetof(struct amap_sol_cqe, i_flags) / 32]
1367 & SOL_FLAGS_MASK) >> 24) | 0x80;
1368 hdr->response = (psol->dw[offsetof(struct amap_sol_cqe, i_resp) /
1369 32] & SOL_RESP_MASK);
1370 hdr->exp_cmdsn = cpu_to_be32(psol->dw[offsetof(struct amap_sol_cqe,
1371 i_exp_cmd_sn) / 32] & SOL_EXP_CMD_SN_MASK);
1372 hdr->max_cmdsn = be32_to_cpu((psol->dw[offsetof(struct amap_sol_cqe,
1373 i_exp_cmd_sn) / 32] & SOL_EXP_CMD_SN_MASK) +
1374 ((psol->dw[offsetof(struct amap_sol_cqe, i_cmd_wnd)
1375 / 32] & SOL_CMD_WND_MASK) >> 24) - 1);
1376 hdr->itt = io_task->libiscsi_itt;
1377 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1381 hwi_complete_drvr_msgs(struct beiscsi_conn *beiscsi_conn,
1382 struct beiscsi_hba *phba, struct sol_cqe *psol)
1384 struct hwi_wrb_context *pwrb_context;
1385 struct wrb_handle *pwrb_handle = NULL;
1386 struct hwi_controller *phwi_ctrlr;
1387 struct iscsi_task *task;
1388 struct beiscsi_io_task *io_task;
1389 struct iscsi_conn *conn = beiscsi_conn->conn;
1390 struct iscsi_session *session = conn->session;
1392 phwi_ctrlr = phba->phwi_ctrlr;
1393 pwrb_context = &phwi_ctrlr->wrb_context[((psol->
1394 dw[offsetof(struct amap_sol_cqe, cid) / 32] &
1395 SOL_CID_MASK) >> 6) -
1396 phba->fw_config.iscsi_cid_start];
1397 pwrb_handle = pwrb_context->pwrb_handle_basestd[((psol->
1398 dw[offsetof(struct amap_sol_cqe, wrb_index) /
1399 32] & SOL_WRB_INDEX_MASK) >> 16)];
1400 task = pwrb_handle->pio_handle;
1402 io_task = task->dd_data;
1403 spin_lock_bh(&phba->mgmt_sgl_lock);
1404 free_mgmt_sgl_handle(phba, io_task->psgl_handle);
1405 spin_unlock_bh(&phba->mgmt_sgl_lock);
1406 spin_lock_bh(&session->lock);
1407 free_wrb_handle(phba, pwrb_context, pwrb_handle);
1408 spin_unlock_bh(&session->lock);
1412 be_complete_nopin_resp(struct beiscsi_conn *beiscsi_conn,
1413 struct iscsi_task *task, struct sol_cqe *psol)
1415 struct iscsi_nopin *hdr;
1416 struct iscsi_conn *conn = beiscsi_conn->conn;
1417 struct beiscsi_io_task *io_task = task->dd_data;
1419 hdr = (struct iscsi_nopin *)task->hdr;
1420 hdr->flags = ((psol->dw[offsetof(struct amap_sol_cqe, i_flags) / 32]
1421 & SOL_FLAGS_MASK) >> 24) | 0x80;
1422 hdr->exp_cmdsn = cpu_to_be32(psol->dw[offsetof(struct amap_sol_cqe,
1423 i_exp_cmd_sn) / 32] & SOL_EXP_CMD_SN_MASK);
1424 hdr->max_cmdsn = be32_to_cpu((psol->dw[offsetof(struct amap_sol_cqe,
1425 i_exp_cmd_sn) / 32] & SOL_EXP_CMD_SN_MASK) +
1426 ((psol->dw[offsetof(struct amap_sol_cqe, i_cmd_wnd)
1427 / 32] & SOL_CMD_WND_MASK) >> 24) - 1);
1428 hdr->opcode = ISCSI_OP_NOOP_IN;
1429 hdr->itt = io_task->libiscsi_itt;
1430 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1433 static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn,
1434 struct beiscsi_hba *phba, struct sol_cqe *psol)
1436 struct hwi_wrb_context *pwrb_context;
1437 struct wrb_handle *pwrb_handle;
1438 struct iscsi_wrb *pwrb = NULL;
1439 struct hwi_controller *phwi_ctrlr;
1440 struct iscsi_task *task;
1442 struct iscsi_conn *conn = beiscsi_conn->conn;
1443 struct iscsi_session *session = conn->session;
1445 phwi_ctrlr = phba->phwi_ctrlr;
1446 pwrb_context = &phwi_ctrlr->wrb_context[((psol->dw[offsetof
1447 (struct amap_sol_cqe, cid) / 32]
1448 & SOL_CID_MASK) >> 6) -
1449 phba->fw_config.iscsi_cid_start];
1450 pwrb_handle = pwrb_context->pwrb_handle_basestd[((psol->
1451 dw[offsetof(struct amap_sol_cqe, wrb_index) /
1452 32] & SOL_WRB_INDEX_MASK) >> 16)];
1453 task = pwrb_handle->pio_handle;
1454 pwrb = pwrb_handle->pwrb;
1455 type = (pwrb->dw[offsetof(struct amap_iscsi_wrb, type) / 32] &
1456 WRB_TYPE_MASK) >> 28;
1458 spin_lock_bh(&session->lock);
1461 case HWH_TYPE_IO_RD:
1462 if ((task->hdr->opcode & ISCSI_OPCODE_MASK) ==
1464 be_complete_nopin_resp(beiscsi_conn, task, psol);
1466 be_complete_io(beiscsi_conn, task, psol);
1469 case HWH_TYPE_LOGOUT:
1470 if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGOUT)
1471 be_complete_logout(beiscsi_conn, task, psol);
1473 be_complete_tmf(beiscsi_conn, task, psol);
1477 case HWH_TYPE_LOGIN:
1478 beiscsi_log(phba, KERN_ERR,
1479 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1480 "BM_%d :\t\t No HWH_TYPE_LOGIN Expected in"
1481 " hwi_complete_cmd- Solicited path\n");
1485 be_complete_nopin_resp(beiscsi_conn, task, psol);
1489 beiscsi_log(phba, KERN_WARNING,
1490 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1491 "BM_%d : In hwi_complete_cmd, unknown type = %d"
1492 "wrb_index 0x%x CID 0x%x\n", type,
1493 ((psol->dw[offsetof(struct amap_iscsi_wrb,
1494 type) / 32] & SOL_WRB_INDEX_MASK) >> 16),
1495 ((psol->dw[offsetof(struct amap_sol_cqe,
1496 cid) / 32] & SOL_CID_MASK) >> 6));
1500 spin_unlock_bh(&session->lock);
1503 static struct list_head *hwi_get_async_busy_list(struct hwi_async_pdu_context
1504 *pasync_ctx, unsigned int is_header,
1505 unsigned int host_write_ptr)
1508 return &pasync_ctx->async_entry[host_write_ptr].
1511 return &pasync_ctx->async_entry[host_write_ptr].data_busy_list;
1514 static struct async_pdu_handle *
1515 hwi_get_async_handle(struct beiscsi_hba *phba,
1516 struct beiscsi_conn *beiscsi_conn,
1517 struct hwi_async_pdu_context *pasync_ctx,
1518 struct i_t_dpdu_cqe *pdpdu_cqe, unsigned int *pcq_index)
1520 struct be_bus_address phys_addr;
1521 struct list_head *pbusy_list;
1522 struct async_pdu_handle *pasync_handle = NULL;
1523 unsigned char is_header = 0;
1525 phys_addr.u.a32.address_lo =
1526 pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, db_addr_lo) / 32] -
1527 ((pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, dpl) / 32]
1528 & PDUCQE_DPL_MASK) >> 16);
1529 phys_addr.u.a32.address_hi =
1530 pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, db_addr_hi) / 32];
1532 phys_addr.u.a64.address =
1533 *((unsigned long long *)(&phys_addr.u.a64.address));
1535 switch (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, code) / 32]
1536 & PDUCQE_CODE_MASK) {
1537 case UNSOL_HDR_NOTIFY:
1540 pbusy_list = hwi_get_async_busy_list(pasync_ctx, 1,
1541 (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
1542 index) / 32] & PDUCQE_INDEX_MASK));
1544 case UNSOL_DATA_NOTIFY:
1545 pbusy_list = hwi_get_async_busy_list(pasync_ctx, 0, (pdpdu_cqe->
1546 dw[offsetof(struct amap_i_t_dpdu_cqe,
1547 index) / 32] & PDUCQE_INDEX_MASK));
1551 beiscsi_log(phba, KERN_WARNING,
1552 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1553 "BM_%d : Unexpected code=%d\n",
1554 pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
1555 code) / 32] & PDUCQE_CODE_MASK);
1559 WARN_ON(list_empty(pbusy_list));
1560 list_for_each_entry(pasync_handle, pbusy_list, link) {
1561 if (pasync_handle->pa.u.a64.address == phys_addr.u.a64.address)
1565 WARN_ON(!pasync_handle);
1567 pasync_handle->cri = (unsigned short)beiscsi_conn->beiscsi_conn_cid -
1568 phba->fw_config.iscsi_cid_start;
1569 pasync_handle->is_header = is_header;
1570 pasync_handle->buffer_len = ((pdpdu_cqe->
1571 dw[offsetof(struct amap_i_t_dpdu_cqe, dpl) / 32]
1572 & PDUCQE_DPL_MASK) >> 16);
1574 *pcq_index = (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
1575 index) / 32] & PDUCQE_INDEX_MASK);
1576 return pasync_handle;
1580 hwi_update_async_writables(struct beiscsi_hba *phba,
1581 struct hwi_async_pdu_context *pasync_ctx,
1582 unsigned int is_header, unsigned int cq_index)
1584 struct list_head *pbusy_list;
1585 struct async_pdu_handle *pasync_handle;
1586 unsigned int num_entries, writables = 0;
1587 unsigned int *pep_read_ptr, *pwritables;
1589 num_entries = pasync_ctx->num_entries;
1591 pep_read_ptr = &pasync_ctx->async_header.ep_read_ptr;
1592 pwritables = &pasync_ctx->async_header.writables;
1594 pep_read_ptr = &pasync_ctx->async_data.ep_read_ptr;
1595 pwritables = &pasync_ctx->async_data.writables;
1598 while ((*pep_read_ptr) != cq_index) {
1600 *pep_read_ptr = (*pep_read_ptr) % num_entries;
1602 pbusy_list = hwi_get_async_busy_list(pasync_ctx, is_header,
1605 WARN_ON(list_empty(pbusy_list));
1607 if (!list_empty(pbusy_list)) {
1608 pasync_handle = list_entry(pbusy_list->next,
1609 struct async_pdu_handle,
1611 WARN_ON(!pasync_handle);
1612 pasync_handle->consumed = 1;
1619 beiscsi_log(phba, KERN_ERR,
1620 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1621 "BM_%d : Duplicate notification received - index 0x%x!!\n",
1626 *pwritables = *pwritables + writables;
1630 static void hwi_free_async_msg(struct beiscsi_hba *phba,
1633 struct hwi_controller *phwi_ctrlr;
1634 struct hwi_async_pdu_context *pasync_ctx;
1635 struct async_pdu_handle *pasync_handle, *tmp_handle;
1636 struct list_head *plist;
1638 phwi_ctrlr = phba->phwi_ctrlr;
1639 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
1641 plist = &pasync_ctx->async_entry[cri].wait_queue.list;
1643 list_for_each_entry_safe(pasync_handle, tmp_handle, plist, link) {
1644 list_del(&pasync_handle->link);
1646 if (pasync_handle->is_header) {
1647 list_add_tail(&pasync_handle->link,
1648 &pasync_ctx->async_header.free_list);
1649 pasync_ctx->async_header.free_entries++;
1651 list_add_tail(&pasync_handle->link,
1652 &pasync_ctx->async_data.free_list);
1653 pasync_ctx->async_data.free_entries++;
1657 INIT_LIST_HEAD(&pasync_ctx->async_entry[cri].wait_queue.list);
1658 pasync_ctx->async_entry[cri].wait_queue.hdr_received = 0;
1659 pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0;
1662 static struct phys_addr *
1663 hwi_get_ring_address(struct hwi_async_pdu_context *pasync_ctx,
1664 unsigned int is_header, unsigned int host_write_ptr)
1666 struct phys_addr *pasync_sge = NULL;
1669 pasync_sge = pasync_ctx->async_header.ring_base;
1671 pasync_sge = pasync_ctx->async_data.ring_base;
1673 return pasync_sge + host_write_ptr;
1676 static void hwi_post_async_buffers(struct beiscsi_hba *phba,
1677 unsigned int is_header)
1679 struct hwi_controller *phwi_ctrlr;
1680 struct hwi_async_pdu_context *pasync_ctx;
1681 struct async_pdu_handle *pasync_handle;
1682 struct list_head *pfree_link, *pbusy_list;
1683 struct phys_addr *pasync_sge;
1684 unsigned int ring_id, num_entries;
1685 unsigned int host_write_num;
1686 unsigned int writables;
1690 phwi_ctrlr = phba->phwi_ctrlr;
1691 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
1692 num_entries = pasync_ctx->num_entries;
1695 writables = min(pasync_ctx->async_header.writables,
1696 pasync_ctx->async_header.free_entries);
1697 pfree_link = pasync_ctx->async_header.free_list.next;
1698 host_write_num = pasync_ctx->async_header.host_write_ptr;
1699 ring_id = phwi_ctrlr->default_pdu_hdr.id;
1701 writables = min(pasync_ctx->async_data.writables,
1702 pasync_ctx->async_data.free_entries);
1703 pfree_link = pasync_ctx->async_data.free_list.next;
1704 host_write_num = pasync_ctx->async_data.host_write_ptr;
1705 ring_id = phwi_ctrlr->default_pdu_data.id;
1708 writables = (writables / 8) * 8;
1710 for (i = 0; i < writables; i++) {
1712 hwi_get_async_busy_list(pasync_ctx, is_header,
1715 list_entry(pfree_link, struct async_pdu_handle,
1717 WARN_ON(!pasync_handle);
1718 pasync_handle->consumed = 0;
1720 pfree_link = pfree_link->next;
1722 pasync_sge = hwi_get_ring_address(pasync_ctx,
1723 is_header, host_write_num);
1725 pasync_sge->hi = pasync_handle->pa.u.a32.address_lo;
1726 pasync_sge->lo = pasync_handle->pa.u.a32.address_hi;
1728 list_move(&pasync_handle->link, pbusy_list);
1731 host_write_num = host_write_num % num_entries;
1735 pasync_ctx->async_header.host_write_ptr =
1737 pasync_ctx->async_header.free_entries -= writables;
1738 pasync_ctx->async_header.writables -= writables;
1739 pasync_ctx->async_header.busy_entries += writables;
1741 pasync_ctx->async_data.host_write_ptr = host_write_num;
1742 pasync_ctx->async_data.free_entries -= writables;
1743 pasync_ctx->async_data.writables -= writables;
1744 pasync_ctx->async_data.busy_entries += writables;
1747 doorbell |= ring_id & DB_DEF_PDU_RING_ID_MASK;
1748 doorbell |= 1 << DB_DEF_PDU_REARM_SHIFT;
1749 doorbell |= 0 << DB_DEF_PDU_EVENT_SHIFT;
1750 doorbell |= (writables & DB_DEF_PDU_CQPROC_MASK)
1751 << DB_DEF_PDU_CQPROC_SHIFT;
1753 iowrite32(doorbell, phba->db_va + DB_RXULP0_OFFSET);
1757 static void hwi_flush_default_pdu_buffer(struct beiscsi_hba *phba,
1758 struct beiscsi_conn *beiscsi_conn,
1759 struct i_t_dpdu_cqe *pdpdu_cqe)
1761 struct hwi_controller *phwi_ctrlr;
1762 struct hwi_async_pdu_context *pasync_ctx;
1763 struct async_pdu_handle *pasync_handle = NULL;
1764 unsigned int cq_index = -1;
1766 phwi_ctrlr = phba->phwi_ctrlr;
1767 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
1769 pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
1770 pdpdu_cqe, &cq_index);
1771 BUG_ON(pasync_handle->is_header != 0);
1772 if (pasync_handle->consumed == 0)
1773 hwi_update_async_writables(phba, pasync_ctx,
1774 pasync_handle->is_header, cq_index);
1776 hwi_free_async_msg(phba, pasync_handle->cri);
1777 hwi_post_async_buffers(phba, pasync_handle->is_header);
1781 hwi_fwd_async_msg(struct beiscsi_conn *beiscsi_conn,
1782 struct beiscsi_hba *phba,
1783 struct hwi_async_pdu_context *pasync_ctx, unsigned short cri)
1785 struct list_head *plist;
1786 struct async_pdu_handle *pasync_handle;
1788 unsigned int hdr_len = 0, buf_len = 0;
1789 unsigned int status, index = 0, offset = 0;
1790 void *pfirst_buffer = NULL;
1791 unsigned int num_buf = 0;
1793 plist = &pasync_ctx->async_entry[cri].wait_queue.list;
1795 list_for_each_entry(pasync_handle, plist, link) {
1797 phdr = pasync_handle->pbuffer;
1798 hdr_len = pasync_handle->buffer_len;
1800 buf_len = pasync_handle->buffer_len;
1802 pfirst_buffer = pasync_handle->pbuffer;
1805 memcpy(pfirst_buffer + offset,
1806 pasync_handle->pbuffer, buf_len);
1812 status = beiscsi_process_async_pdu(beiscsi_conn, phba,
1813 (beiscsi_conn->beiscsi_conn_cid -
1814 phba->fw_config.iscsi_cid_start),
1815 phdr, hdr_len, pfirst_buffer,
1818 hwi_free_async_msg(phba, cri);
1823 hwi_gather_async_pdu(struct beiscsi_conn *beiscsi_conn,
1824 struct beiscsi_hba *phba,
1825 struct async_pdu_handle *pasync_handle)
1827 struct hwi_async_pdu_context *pasync_ctx;
1828 struct hwi_controller *phwi_ctrlr;
1829 unsigned int bytes_needed = 0, status = 0;
1830 unsigned short cri = pasync_handle->cri;
1831 struct pdu_base *ppdu;
1833 phwi_ctrlr = phba->phwi_ctrlr;
1834 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
1836 list_del(&pasync_handle->link);
1837 if (pasync_handle->is_header) {
1838 pasync_ctx->async_header.busy_entries--;
1839 if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) {
1840 hwi_free_async_msg(phba, cri);
1844 pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0;
1845 pasync_ctx->async_entry[cri].wait_queue.hdr_received = 1;
1846 pasync_ctx->async_entry[cri].wait_queue.hdr_len =
1847 (unsigned short)pasync_handle->buffer_len;
1848 list_add_tail(&pasync_handle->link,
1849 &pasync_ctx->async_entry[cri].wait_queue.list);
1851 ppdu = pasync_handle->pbuffer;
1852 bytes_needed = ((((ppdu->dw[offsetof(struct amap_pdu_base,
1853 data_len_hi) / 32] & PDUBASE_DATALENHI_MASK) << 8) &
1854 0xFFFF0000) | ((be16_to_cpu((ppdu->
1855 dw[offsetof(struct amap_pdu_base, data_len_lo) / 32]
1856 & PDUBASE_DATALENLO_MASK) >> 16)) & 0x0000FFFF));
1859 pasync_ctx->async_entry[cri].wait_queue.bytes_needed =
1862 if (bytes_needed == 0)
1863 status = hwi_fwd_async_msg(beiscsi_conn, phba,
1867 pasync_ctx->async_data.busy_entries--;
1868 if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) {
1869 list_add_tail(&pasync_handle->link,
1870 &pasync_ctx->async_entry[cri].wait_queue.
1872 pasync_ctx->async_entry[cri].wait_queue.
1874 (unsigned short)pasync_handle->buffer_len;
1876 if (pasync_ctx->async_entry[cri].wait_queue.
1878 pasync_ctx->async_entry[cri].wait_queue.
1880 status = hwi_fwd_async_msg(beiscsi_conn, phba,
1887 static void hwi_process_default_pdu_ring(struct beiscsi_conn *beiscsi_conn,
1888 struct beiscsi_hba *phba,
1889 struct i_t_dpdu_cqe *pdpdu_cqe)
1891 struct hwi_controller *phwi_ctrlr;
1892 struct hwi_async_pdu_context *pasync_ctx;
1893 struct async_pdu_handle *pasync_handle = NULL;
1894 unsigned int cq_index = -1;
1896 phwi_ctrlr = phba->phwi_ctrlr;
1897 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
1898 pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
1899 pdpdu_cqe, &cq_index);
1901 if (pasync_handle->consumed == 0)
1902 hwi_update_async_writables(phba, pasync_ctx,
1903 pasync_handle->is_header, cq_index);
1905 hwi_gather_async_pdu(beiscsi_conn, phba, pasync_handle);
1906 hwi_post_async_buffers(phba, pasync_handle->is_header);
1909 static void beiscsi_process_mcc_isr(struct beiscsi_hba *phba)
1911 struct be_queue_info *mcc_cq;
1912 struct be_mcc_compl *mcc_compl;
1913 unsigned int num_processed = 0;
1915 mcc_cq = &phba->ctrl.mcc_obj.cq;
1916 mcc_compl = queue_tail_node(mcc_cq);
1917 mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
1918 while (mcc_compl->flags & CQE_FLAGS_VALID_MASK) {
1920 if (num_processed >= 32) {
1921 hwi_ring_cq_db(phba, mcc_cq->id,
1922 num_processed, 0, 0);
1925 if (mcc_compl->flags & CQE_FLAGS_ASYNC_MASK) {
1926 /* Interpret flags as an async trailer */
1927 if (is_link_state_evt(mcc_compl->flags))
1928 /* Interpret compl as a async link evt */
1929 beiscsi_async_link_state_process(phba,
1930 (struct be_async_event_link_state *) mcc_compl);
1932 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_MBOX,
1933 "BM_%d : Unsupported Async Event, flags"
1936 } else if (mcc_compl->flags & CQE_FLAGS_COMPLETED_MASK) {
1937 be_mcc_compl_process_isr(&phba->ctrl, mcc_compl);
1938 atomic_dec(&phba->ctrl.mcc_obj.q.used);
1941 mcc_compl->flags = 0;
1942 queue_tail_inc(mcc_cq);
1943 mcc_compl = queue_tail_node(mcc_cq);
1944 mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
1948 if (num_processed > 0)
1949 hwi_ring_cq_db(phba, mcc_cq->id, num_processed, 1, 0);
1954 * beiscsi_process_cq()- Process the Completion Queue
1955 * @pbe_eq: Event Q on which the Completion has come
1958 * Number of Completion Entries processed.
1960 static unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq)
1962 struct be_queue_info *cq;
1963 struct sol_cqe *sol;
1964 struct dmsg_cqe *dmsg;
1965 unsigned int num_processed = 0;
1966 unsigned int tot_nump = 0;
1967 unsigned short code = 0, cid = 0;
1968 struct beiscsi_conn *beiscsi_conn;
1969 struct beiscsi_endpoint *beiscsi_ep;
1970 struct iscsi_endpoint *ep;
1971 struct beiscsi_hba *phba;
1974 sol = queue_tail_node(cq);
1975 phba = pbe_eq->phba;
1977 while (sol->dw[offsetof(struct amap_sol_cqe, valid) / 32] &
1979 be_dws_le_to_cpu(sol, sizeof(struct sol_cqe));
1981 cid = ((sol->dw[offsetof(struct amap_sol_cqe, cid)/32] &
1982 CQE_CID_MASK) >> 6);
1983 code = (sol->dw[offsetof(struct amap_sol_cqe, code)/32] &
1985 ep = phba->ep_array[cid - phba->fw_config.iscsi_cid_start];
1987 beiscsi_ep = ep->dd_data;
1988 beiscsi_conn = beiscsi_ep->conn;
1990 if (num_processed >= 32) {
1991 hwi_ring_cq_db(phba, cq->id,
1992 num_processed, 0, 0);
1993 tot_nump += num_processed;
1998 case SOL_CMD_COMPLETE:
1999 hwi_complete_cmd(beiscsi_conn, phba, sol);
2001 case DRIVERMSG_NOTIFY:
2002 beiscsi_log(phba, KERN_INFO,
2003 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
2004 "BM_%d : Received %s[%d] on CID : %d\n",
2005 cqe_desc[code], code, cid);
2007 dmsg = (struct dmsg_cqe *)sol;
2008 hwi_complete_drvr_msgs(beiscsi_conn, phba, sol);
2010 case UNSOL_HDR_NOTIFY:
2011 beiscsi_log(phba, KERN_INFO,
2012 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
2013 "BM_%d : Received %s[%d] on CID : %d\n",
2014 cqe_desc[code], code, cid);
2016 hwi_process_default_pdu_ring(beiscsi_conn, phba,
2017 (struct i_t_dpdu_cqe *)sol);
2019 case UNSOL_DATA_NOTIFY:
2020 beiscsi_log(phba, KERN_INFO,
2021 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
2022 "BM_%d : Received %s[%d] on CID : %d\n",
2023 cqe_desc[code], code, cid);
2025 hwi_process_default_pdu_ring(beiscsi_conn, phba,
2026 (struct i_t_dpdu_cqe *)sol);
2028 case CXN_INVALIDATE_INDEX_NOTIFY:
2029 case CMD_INVALIDATED_NOTIFY:
2030 case CXN_INVALIDATE_NOTIFY:
2031 beiscsi_log(phba, KERN_ERR,
2032 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
2033 "BM_%d : Ignoring %s[%d] on CID : %d\n",
2034 cqe_desc[code], code, cid);
2036 case SOL_CMD_KILLED_DATA_DIGEST_ERR:
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 hwi_flush_default_pdu_buffer(phba, beiscsi_conn,
2055 (struct i_t_dpdu_cqe *) sol);
2057 case CXN_KILLED_PDU_SIZE_EXCEEDS_DSL:
2058 case CXN_KILLED_BURST_LEN_MISMATCH:
2059 case CXN_KILLED_AHS_RCVD:
2060 case CXN_KILLED_HDR_DIGEST_ERR:
2061 case CXN_KILLED_UNKNOWN_HDR:
2062 case CXN_KILLED_STALE_ITT_TTT_RCVD:
2063 case CXN_KILLED_INVALID_ITT_TTT_RCVD:
2064 case CXN_KILLED_TIMED_OUT:
2065 case CXN_KILLED_FIN_RCVD:
2066 case CXN_KILLED_RST_SENT:
2067 case CXN_KILLED_RST_RCVD:
2068 case CXN_KILLED_BAD_UNSOL_PDU_RCVD:
2069 case CXN_KILLED_BAD_WRB_INDEX_ERROR:
2070 case CXN_KILLED_OVER_RUN_RESIDUAL:
2071 case CXN_KILLED_UNDER_RUN_RESIDUAL:
2072 case CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN:
2073 beiscsi_log(phba, KERN_ERR,
2074 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
2075 "BM_%d : Event %s[%d] received on CID : %d\n",
2076 cqe_desc[code], code, cid);
2078 iscsi_conn_failure(beiscsi_conn->conn,
2079 ISCSI_ERR_CONN_FAILED);
2082 beiscsi_log(phba, KERN_ERR,
2083 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
2084 "BM_%d : Invalid CQE Event Received Code : %d"
2090 AMAP_SET_BITS(struct amap_sol_cqe, valid, sol, 0);
2092 sol = queue_tail_node(cq);
2096 if (num_processed > 0) {
2097 tot_nump += num_processed;
2098 hwi_ring_cq_db(phba, cq->id, num_processed, 1, 0);
2103 void beiscsi_process_all_cqs(struct work_struct *work)
2105 unsigned long flags;
2106 struct hwi_controller *phwi_ctrlr;
2107 struct hwi_context_memory *phwi_context;
2108 struct beiscsi_hba *phba;
2109 struct be_eq_obj *pbe_eq =
2110 container_of(work, struct be_eq_obj, work_cqs);
2112 phba = pbe_eq->phba;
2113 phwi_ctrlr = phba->phwi_ctrlr;
2114 phwi_context = phwi_ctrlr->phwi_ctxt;
2116 if (pbe_eq->todo_mcc_cq) {
2117 spin_lock_irqsave(&phba->isr_lock, flags);
2118 pbe_eq->todo_mcc_cq = false;
2119 spin_unlock_irqrestore(&phba->isr_lock, flags);
2120 beiscsi_process_mcc_isr(phba);
2123 if (pbe_eq->todo_cq) {
2124 spin_lock_irqsave(&phba->isr_lock, flags);
2125 pbe_eq->todo_cq = false;
2126 spin_unlock_irqrestore(&phba->isr_lock, flags);
2127 beiscsi_process_cq(pbe_eq);
2130 /* rearm EQ for further interrupts */
2131 hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1);
2134 static int be_iopoll(struct blk_iopoll *iop, int budget)
2136 static unsigned int ret;
2137 struct beiscsi_hba *phba;
2138 struct be_eq_obj *pbe_eq;
2140 pbe_eq = container_of(iop, struct be_eq_obj, iopoll);
2141 ret = beiscsi_process_cq(pbe_eq);
2143 phba = pbe_eq->phba;
2144 blk_iopoll_complete(iop);
2145 beiscsi_log(phba, KERN_INFO,
2146 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
2147 "BM_%d : rearm pbe_eq->q.id =%d\n",
2149 hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1);
2155 hwi_write_sgl(struct iscsi_wrb *pwrb, struct scatterlist *sg,
2156 unsigned int num_sg, struct beiscsi_io_task *io_task)
2158 struct iscsi_sge *psgl;
2159 unsigned int sg_len, index;
2160 unsigned int sge_len = 0;
2161 unsigned long long addr;
2162 struct scatterlist *l_sg;
2163 unsigned int offset;
2165 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
2166 io_task->bhs_pa.u.a32.address_lo);
2167 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
2168 io_task->bhs_pa.u.a32.address_hi);
2171 for (index = 0; (index < num_sg) && (index < 2); index++,
2174 sg_len = sg_dma_len(sg);
2175 addr = (u64) sg_dma_address(sg);
2176 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
2177 ((u32)(addr & 0xFFFFFFFF)));
2178 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
2179 ((u32)(addr >> 32)));
2180 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
2184 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_r2t_offset,
2186 sg_len = sg_dma_len(sg);
2187 addr = (u64) sg_dma_address(sg);
2188 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_lo, pwrb,
2189 ((u32)(addr & 0xFFFFFFFF)));
2190 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_hi, pwrb,
2191 ((u32)(addr >> 32)));
2192 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_len, pwrb,
2196 psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
2197 memset(psgl, 0, sizeof(*psgl) * BE2_SGE);
2199 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2);
2201 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2202 io_task->bhs_pa.u.a32.address_hi);
2203 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2204 io_task->bhs_pa.u.a32.address_lo);
2207 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
2209 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
2211 } else if (num_sg == 2) {
2212 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
2214 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
2217 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
2219 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
2226 for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) {
2227 sg_len = sg_dma_len(sg);
2228 addr = (u64) sg_dma_address(sg);
2229 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2230 (addr & 0xFFFFFFFF));
2231 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2233 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len);
2234 AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset);
2235 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
2239 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
2243 * hwi_write_buffer()- Populate the WRB with task info
2244 * @pwrb: ptr to the WRB entry
2245 * @task: iscsi task which is to be executed
2247 static void hwi_write_buffer(struct iscsi_wrb *pwrb, struct iscsi_task *task)
2249 struct iscsi_sge *psgl;
2250 struct beiscsi_io_task *io_task = task->dd_data;
2251 struct beiscsi_conn *beiscsi_conn = io_task->conn;
2252 struct beiscsi_hba *phba = beiscsi_conn->phba;
2254 io_task->bhs_len = sizeof(struct be_nonio_bhs) - 2;
2255 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
2256 io_task->bhs_pa.u.a32.address_lo);
2257 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
2258 io_task->bhs_pa.u.a32.address_hi);
2261 if (task->data_count) {
2262 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1);
2263 io_task->mtask_addr = pci_map_single(phba->pcidev,
2268 io_task->mtask_data_count = task->data_count;
2270 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
2271 io_task->mtask_addr = 0;
2273 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
2274 lower_32_bits(io_task->mtask_addr));
2275 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
2276 upper_32_bits(io_task->mtask_addr));
2277 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
2280 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, 1);
2282 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
2283 io_task->mtask_addr = 0;
2286 psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
2288 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len);
2290 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2291 io_task->bhs_pa.u.a32.address_hi);
2292 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2293 io_task->bhs_pa.u.a32.address_lo);
2296 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, 0);
2297 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, 0);
2298 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0);
2299 AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, 0);
2300 AMAP_SET_BITS(struct amap_iscsi_sge, rsvd0, psgl, 0);
2301 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
2305 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2306 lower_32_bits(io_task->mtask_addr));
2307 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2308 upper_32_bits(io_task->mtask_addr));
2310 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0x106);
2312 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
2315 static void beiscsi_find_mem_req(struct beiscsi_hba *phba)
2317 unsigned int num_cq_pages, num_async_pdu_buf_pages;
2318 unsigned int num_async_pdu_data_pages, wrb_sz_per_cxn;
2319 unsigned int num_async_pdu_buf_sgl_pages, num_async_pdu_data_sgl_pages;
2321 num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
2322 sizeof(struct sol_cqe));
2323 num_async_pdu_buf_pages =
2324 PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
2325 phba->params.defpdu_hdr_sz);
2326 num_async_pdu_buf_sgl_pages =
2327 PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
2328 sizeof(struct phys_addr));
2329 num_async_pdu_data_pages =
2330 PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
2331 phba->params.defpdu_data_sz);
2332 num_async_pdu_data_sgl_pages =
2333 PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
2334 sizeof(struct phys_addr));
2336 phba->params.hwi_ws_sz = sizeof(struct hwi_controller);
2338 phba->mem_req[ISCSI_MEM_GLOBAL_HEADER] = 2 *
2339 BE_ISCSI_PDU_HEADER_SIZE;
2340 phba->mem_req[HWI_MEM_ADDN_CONTEXT] =
2341 sizeof(struct hwi_context_memory);
2344 phba->mem_req[HWI_MEM_WRB] = sizeof(struct iscsi_wrb)
2345 * (phba->params.wrbs_per_cxn)
2346 * phba->params.cxns_per_ctrl;
2347 wrb_sz_per_cxn = sizeof(struct wrb_handle) *
2348 (phba->params.wrbs_per_cxn);
2349 phba->mem_req[HWI_MEM_WRBH] = roundup_pow_of_two((wrb_sz_per_cxn) *
2350 phba->params.cxns_per_ctrl);
2352 phba->mem_req[HWI_MEM_SGLH] = sizeof(struct sgl_handle) *
2353 phba->params.icds_per_ctrl;
2354 phba->mem_req[HWI_MEM_SGE] = sizeof(struct iscsi_sge) *
2355 phba->params.num_sge_per_io * phba->params.icds_per_ctrl;
2357 phba->mem_req[HWI_MEM_ASYNC_HEADER_BUF] =
2358 num_async_pdu_buf_pages * PAGE_SIZE;
2359 phba->mem_req[HWI_MEM_ASYNC_DATA_BUF] =
2360 num_async_pdu_data_pages * PAGE_SIZE;
2361 phba->mem_req[HWI_MEM_ASYNC_HEADER_RING] =
2362 num_async_pdu_buf_sgl_pages * PAGE_SIZE;
2363 phba->mem_req[HWI_MEM_ASYNC_DATA_RING] =
2364 num_async_pdu_data_sgl_pages * PAGE_SIZE;
2365 phba->mem_req[HWI_MEM_ASYNC_HEADER_HANDLE] =
2366 phba->params.asyncpdus_per_ctrl *
2367 sizeof(struct async_pdu_handle);
2368 phba->mem_req[HWI_MEM_ASYNC_DATA_HANDLE] =
2369 phba->params.asyncpdus_per_ctrl *
2370 sizeof(struct async_pdu_handle);
2371 phba->mem_req[HWI_MEM_ASYNC_PDU_CONTEXT] =
2372 sizeof(struct hwi_async_pdu_context) +
2373 (phba->params.cxns_per_ctrl * sizeof(struct hwi_async_entry));
2376 static int beiscsi_alloc_mem(struct beiscsi_hba *phba)
2378 struct be_mem_descriptor *mem_descr;
2380 struct mem_array *mem_arr, *mem_arr_orig;
2381 unsigned int i, j, alloc_size, curr_alloc_size;
2383 phba->phwi_ctrlr = kzalloc(phba->params.hwi_ws_sz, GFP_KERNEL);
2384 if (!phba->phwi_ctrlr)
2387 phba->init_mem = kcalloc(SE_MEM_MAX, sizeof(*mem_descr),
2389 if (!phba->init_mem) {
2390 kfree(phba->phwi_ctrlr);
2394 mem_arr_orig = kmalloc(sizeof(*mem_arr_orig) * BEISCSI_MAX_FRAGS_INIT,
2396 if (!mem_arr_orig) {
2397 kfree(phba->init_mem);
2398 kfree(phba->phwi_ctrlr);
2402 mem_descr = phba->init_mem;
2403 for (i = 0; i < SE_MEM_MAX; i++) {
2405 mem_arr = mem_arr_orig;
2406 alloc_size = phba->mem_req[i];
2407 memset(mem_arr, 0, sizeof(struct mem_array) *
2408 BEISCSI_MAX_FRAGS_INIT);
2409 curr_alloc_size = min(be_max_phys_size * 1024, alloc_size);
2411 mem_arr->virtual_address = pci_alloc_consistent(
2415 if (!mem_arr->virtual_address) {
2416 if (curr_alloc_size <= BE_MIN_MEM_SIZE)
2418 if (curr_alloc_size -
2419 rounddown_pow_of_two(curr_alloc_size))
2420 curr_alloc_size = rounddown_pow_of_two
2423 curr_alloc_size = curr_alloc_size / 2;
2425 mem_arr->bus_address.u.
2426 a64.address = (__u64) bus_add;
2427 mem_arr->size = curr_alloc_size;
2428 alloc_size -= curr_alloc_size;
2429 curr_alloc_size = min(be_max_phys_size *
2434 } while (alloc_size);
2435 mem_descr->num_elements = j;
2436 mem_descr->size_in_bytes = phba->mem_req[i];
2437 mem_descr->mem_array = kmalloc(sizeof(*mem_arr) * j,
2439 if (!mem_descr->mem_array)
2442 memcpy(mem_descr->mem_array, mem_arr_orig,
2443 sizeof(struct mem_array) * j);
2446 kfree(mem_arr_orig);
2449 mem_descr->num_elements = j;
2450 while ((i) || (j)) {
2451 for (j = mem_descr->num_elements; j > 0; j--) {
2452 pci_free_consistent(phba->pcidev,
2453 mem_descr->mem_array[j - 1].size,
2454 mem_descr->mem_array[j - 1].
2456 (unsigned long)mem_descr->
2458 bus_address.u.a64.address);
2462 kfree(mem_descr->mem_array);
2466 kfree(mem_arr_orig);
2467 kfree(phba->init_mem);
2468 kfree(phba->phwi_ctrlr);
2472 static int beiscsi_get_memory(struct beiscsi_hba *phba)
2474 beiscsi_find_mem_req(phba);
2475 return beiscsi_alloc_mem(phba);
2478 static void iscsi_init_global_templates(struct beiscsi_hba *phba)
2480 struct pdu_data_out *pdata_out;
2481 struct pdu_nop_out *pnop_out;
2482 struct be_mem_descriptor *mem_descr;
2484 mem_descr = phba->init_mem;
2485 mem_descr += ISCSI_MEM_GLOBAL_HEADER;
2487 (struct pdu_data_out *)mem_descr->mem_array[0].virtual_address;
2488 memset(pdata_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
2490 AMAP_SET_BITS(struct amap_pdu_data_out, opcode, pdata_out,
2494 (struct pdu_nop_out *)((unsigned char *)mem_descr->mem_array[0].
2495 virtual_address + BE_ISCSI_PDU_HEADER_SIZE);
2497 memset(pnop_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
2498 AMAP_SET_BITS(struct amap_pdu_nop_out, ttt, pnop_out, 0xFFFFFFFF);
2499 AMAP_SET_BITS(struct amap_pdu_nop_out, f_bit, pnop_out, 1);
2500 AMAP_SET_BITS(struct amap_pdu_nop_out, i_bit, pnop_out, 0);
2503 static int beiscsi_init_wrb_handle(struct beiscsi_hba *phba)
2505 struct be_mem_descriptor *mem_descr_wrbh, *mem_descr_wrb;
2506 struct wrb_handle *pwrb_handle = NULL;
2507 struct hwi_controller *phwi_ctrlr;
2508 struct hwi_wrb_context *pwrb_context;
2509 struct iscsi_wrb *pwrb = NULL;
2510 unsigned int num_cxn_wrbh = 0;
2511 unsigned int num_cxn_wrb = 0, j, idx = 0, index;
2513 mem_descr_wrbh = phba->init_mem;
2514 mem_descr_wrbh += HWI_MEM_WRBH;
2516 mem_descr_wrb = phba->init_mem;
2517 mem_descr_wrb += HWI_MEM_WRB;
2518 phwi_ctrlr = phba->phwi_ctrlr;
2520 for (index = 0; index < phba->params.cxns_per_ctrl * 2; index += 2) {
2521 pwrb_context = &phwi_ctrlr->wrb_context[index];
2522 pwrb_context->pwrb_handle_base =
2523 kzalloc(sizeof(struct wrb_handle *) *
2524 phba->params.wrbs_per_cxn, GFP_KERNEL);
2525 if (!pwrb_context->pwrb_handle_base) {
2526 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2527 "BM_%d : Mem Alloc Failed. Failing to load\n");
2528 goto init_wrb_hndl_failed;
2530 pwrb_context->pwrb_handle_basestd =
2531 kzalloc(sizeof(struct wrb_handle *) *
2532 phba->params.wrbs_per_cxn, GFP_KERNEL);
2533 if (!pwrb_context->pwrb_handle_basestd) {
2534 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2535 "BM_%d : Mem Alloc Failed. Failing to load\n");
2536 goto init_wrb_hndl_failed;
2538 if (!num_cxn_wrbh) {
2540 mem_descr_wrbh->mem_array[idx].virtual_address;
2541 num_cxn_wrbh = ((mem_descr_wrbh->mem_array[idx].size) /
2542 ((sizeof(struct wrb_handle)) *
2543 phba->params.wrbs_per_cxn));
2546 pwrb_context->alloc_index = 0;
2547 pwrb_context->wrb_handles_available = 0;
2548 pwrb_context->free_index = 0;
2551 for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
2552 pwrb_context->pwrb_handle_base[j] = pwrb_handle;
2553 pwrb_context->pwrb_handle_basestd[j] =
2555 pwrb_context->wrb_handles_available++;
2556 pwrb_handle->wrb_index = j;
2563 for (index = 0; index < phba->params.cxns_per_ctrl * 2; index += 2) {
2564 pwrb_context = &phwi_ctrlr->wrb_context[index];
2566 pwrb = mem_descr_wrb->mem_array[idx].virtual_address;
2567 num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) /
2568 ((sizeof(struct iscsi_wrb) *
2569 phba->params.wrbs_per_cxn));
2574 for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
2575 pwrb_handle = pwrb_context->pwrb_handle_base[j];
2576 pwrb_handle->pwrb = pwrb;
2583 init_wrb_hndl_failed:
2584 for (j = index; j > 0; j--) {
2585 pwrb_context = &phwi_ctrlr->wrb_context[j];
2586 kfree(pwrb_context->pwrb_handle_base);
2587 kfree(pwrb_context->pwrb_handle_basestd);
2592 static void hwi_init_async_pdu_ctx(struct beiscsi_hba *phba)
2594 struct hwi_controller *phwi_ctrlr;
2595 struct hba_parameters *p = &phba->params;
2596 struct hwi_async_pdu_context *pasync_ctx;
2597 struct async_pdu_handle *pasync_header_h, *pasync_data_h;
2598 unsigned int index, idx, num_per_mem, num_async_data;
2599 struct be_mem_descriptor *mem_descr;
2601 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2602 mem_descr += HWI_MEM_ASYNC_PDU_CONTEXT;
2604 phwi_ctrlr = phba->phwi_ctrlr;
2605 phwi_ctrlr->phwi_ctxt->pasync_ctx = (struct hwi_async_pdu_context *)
2606 mem_descr->mem_array[0].virtual_address;
2607 pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx;
2608 memset(pasync_ctx, 0, sizeof(*pasync_ctx));
2610 pasync_ctx->num_entries = p->asyncpdus_per_ctrl;
2611 pasync_ctx->buffer_size = p->defpdu_hdr_sz;
2613 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2614 mem_descr += HWI_MEM_ASYNC_HEADER_BUF;
2615 if (mem_descr->mem_array[0].virtual_address) {
2616 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2617 "BM_%d : hwi_init_async_pdu_ctx"
2618 " HWI_MEM_ASYNC_HEADER_BUF va=%p\n",
2619 mem_descr->mem_array[0].virtual_address);
2621 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
2622 "BM_%d : No Virtual address\n");
2624 pasync_ctx->async_header.va_base =
2625 mem_descr->mem_array[0].virtual_address;
2627 pasync_ctx->async_header.pa_base.u.a64.address =
2628 mem_descr->mem_array[0].bus_address.u.a64.address;
2630 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2631 mem_descr += HWI_MEM_ASYNC_HEADER_RING;
2632 if (mem_descr->mem_array[0].virtual_address) {
2633 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2634 "BM_%d : hwi_init_async_pdu_ctx"
2635 " HWI_MEM_ASYNC_HEADER_RING va=%p\n",
2636 mem_descr->mem_array[0].virtual_address);
2638 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
2639 "BM_%d : No Virtual address\n");
2641 pasync_ctx->async_header.ring_base =
2642 mem_descr->mem_array[0].virtual_address;
2644 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2645 mem_descr += HWI_MEM_ASYNC_HEADER_HANDLE;
2646 if (mem_descr->mem_array[0].virtual_address) {
2647 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2648 "BM_%d : hwi_init_async_pdu_ctx"
2649 " HWI_MEM_ASYNC_HEADER_HANDLE va=%p\n",
2650 mem_descr->mem_array[0].virtual_address);
2652 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
2653 "BM_%d : No Virtual address\n");
2655 pasync_ctx->async_header.handle_base =
2656 mem_descr->mem_array[0].virtual_address;
2657 pasync_ctx->async_header.writables = 0;
2658 INIT_LIST_HEAD(&pasync_ctx->async_header.free_list);
2661 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2662 mem_descr += HWI_MEM_ASYNC_DATA_RING;
2663 if (mem_descr->mem_array[0].virtual_address) {
2664 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2665 "BM_%d : hwi_init_async_pdu_ctx"
2666 " HWI_MEM_ASYNC_DATA_RING va=%p\n",
2667 mem_descr->mem_array[0].virtual_address);
2669 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
2670 "BM_%d : No Virtual address\n");
2672 pasync_ctx->async_data.ring_base =
2673 mem_descr->mem_array[0].virtual_address;
2675 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2676 mem_descr += HWI_MEM_ASYNC_DATA_HANDLE;
2677 if (!mem_descr->mem_array[0].virtual_address)
2678 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
2679 "BM_%d : No Virtual address\n");
2681 pasync_ctx->async_data.handle_base =
2682 mem_descr->mem_array[0].virtual_address;
2683 pasync_ctx->async_data.writables = 0;
2684 INIT_LIST_HEAD(&pasync_ctx->async_data.free_list);
2687 (struct async_pdu_handle *)pasync_ctx->async_header.handle_base;
2689 (struct async_pdu_handle *)pasync_ctx->async_data.handle_base;
2691 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2692 mem_descr += HWI_MEM_ASYNC_DATA_BUF;
2693 if (mem_descr->mem_array[0].virtual_address) {
2694 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2695 "BM_%d : hwi_init_async_pdu_ctx"
2696 " HWI_MEM_ASYNC_DATA_BUF va=%p\n",
2697 mem_descr->mem_array[0].virtual_address);
2699 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
2700 "BM_%d : No Virtual address\n");
2703 pasync_ctx->async_data.va_base =
2704 mem_descr->mem_array[idx].virtual_address;
2705 pasync_ctx->async_data.pa_base.u.a64.address =
2706 mem_descr->mem_array[idx].bus_address.u.a64.address;
2708 num_async_data = ((mem_descr->mem_array[idx].size) /
2709 phba->params.defpdu_data_sz);
2712 for (index = 0; index < p->asyncpdus_per_ctrl; index++) {
2713 pasync_header_h->cri = -1;
2714 pasync_header_h->index = (char)index;
2715 INIT_LIST_HEAD(&pasync_header_h->link);
2716 pasync_header_h->pbuffer =
2717 (void *)((unsigned long)
2718 (pasync_ctx->async_header.va_base) +
2719 (p->defpdu_hdr_sz * index));
2721 pasync_header_h->pa.u.a64.address =
2722 pasync_ctx->async_header.pa_base.u.a64.address +
2723 (p->defpdu_hdr_sz * index);
2725 list_add_tail(&pasync_header_h->link,
2726 &pasync_ctx->async_header.free_list);
2728 pasync_ctx->async_header.free_entries++;
2729 pasync_ctx->async_header.writables++;
2731 INIT_LIST_HEAD(&pasync_ctx->async_entry[index].wait_queue.list);
2732 INIT_LIST_HEAD(&pasync_ctx->async_entry[index].
2734 pasync_data_h->cri = -1;
2735 pasync_data_h->index = (char)index;
2736 INIT_LIST_HEAD(&pasync_data_h->link);
2738 if (!num_async_data) {
2741 pasync_ctx->async_data.va_base =
2742 mem_descr->mem_array[idx].virtual_address;
2743 pasync_ctx->async_data.pa_base.u.a64.address =
2744 mem_descr->mem_array[idx].
2745 bus_address.u.a64.address;
2747 num_async_data = ((mem_descr->mem_array[idx].size) /
2748 phba->params.defpdu_data_sz);
2750 pasync_data_h->pbuffer =
2751 (void *)((unsigned long)
2752 (pasync_ctx->async_data.va_base) +
2753 (p->defpdu_data_sz * num_per_mem));
2755 pasync_data_h->pa.u.a64.address =
2756 pasync_ctx->async_data.pa_base.u.a64.address +
2757 (p->defpdu_data_sz * num_per_mem);
2761 list_add_tail(&pasync_data_h->link,
2762 &pasync_ctx->async_data.free_list);
2764 pasync_ctx->async_data.free_entries++;
2765 pasync_ctx->async_data.writables++;
2767 INIT_LIST_HEAD(&pasync_ctx->async_entry[index].data_busy_list);
2770 pasync_ctx->async_header.host_write_ptr = 0;
2771 pasync_ctx->async_header.ep_read_ptr = -1;
2772 pasync_ctx->async_data.host_write_ptr = 0;
2773 pasync_ctx->async_data.ep_read_ptr = -1;
2777 be_sgl_create_contiguous(void *virtual_address,
2778 u64 physical_address, u32 length,
2779 struct be_dma_mem *sgl)
2781 WARN_ON(!virtual_address);
2782 WARN_ON(!physical_address);
2783 WARN_ON(!length > 0);
2786 sgl->va = virtual_address;
2787 sgl->dma = (unsigned long)physical_address;
2793 static void be_sgl_destroy_contiguous(struct be_dma_mem *sgl)
2795 memset(sgl, 0, sizeof(*sgl));
2799 hwi_build_be_sgl_arr(struct beiscsi_hba *phba,
2800 struct mem_array *pmem, struct be_dma_mem *sgl)
2803 be_sgl_destroy_contiguous(sgl);
2805 be_sgl_create_contiguous(pmem->virtual_address,
2806 pmem->bus_address.u.a64.address,
2811 hwi_build_be_sgl_by_offset(struct beiscsi_hba *phba,
2812 struct mem_array *pmem, struct be_dma_mem *sgl)
2815 be_sgl_destroy_contiguous(sgl);
2817 be_sgl_create_contiguous((unsigned char *)pmem->virtual_address,
2818 pmem->bus_address.u.a64.address,
2822 static int be_fill_queue(struct be_queue_info *q,
2823 u16 len, u16 entry_size, void *vaddress)
2825 struct be_dma_mem *mem = &q->dma_mem;
2827 memset(q, 0, sizeof(*q));
2829 q->entry_size = entry_size;
2830 mem->size = len * entry_size;
2834 memset(mem->va, 0, mem->size);
2838 static int beiscsi_create_eqs(struct beiscsi_hba *phba,
2839 struct hwi_context_memory *phwi_context)
2841 unsigned int i, num_eq_pages;
2842 int ret = 0, eq_for_mcc;
2843 struct be_queue_info *eq;
2844 struct be_dma_mem *mem;
2848 num_eq_pages = PAGES_REQUIRED(phba->params.num_eq_entries * \
2849 sizeof(struct be_eq_entry));
2851 if (phba->msix_enabled)
2855 for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
2856 eq = &phwi_context->be_eq[i].q;
2858 phwi_context->be_eq[i].phba = phba;
2859 eq_vaddress = pci_alloc_consistent(phba->pcidev,
2860 num_eq_pages * PAGE_SIZE,
2863 goto create_eq_error;
2865 mem->va = eq_vaddress;
2866 ret = be_fill_queue(eq, phba->params.num_eq_entries,
2867 sizeof(struct be_eq_entry), eq_vaddress);
2869 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2870 "BM_%d : be_fill_queue Failed for EQ\n");
2871 goto create_eq_error;
2875 ret = beiscsi_cmd_eq_create(&phba->ctrl, eq,
2876 phwi_context->cur_eqd);
2878 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2879 "BM_%d : beiscsi_cmd_eq_create"
2881 goto create_eq_error;
2884 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2885 "BM_%d : eqid = %d\n",
2886 phwi_context->be_eq[i].q.id);
2890 for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
2891 eq = &phwi_context->be_eq[i].q;
2894 pci_free_consistent(phba->pcidev, num_eq_pages
2901 static int beiscsi_create_cqs(struct beiscsi_hba *phba,
2902 struct hwi_context_memory *phwi_context)
2904 unsigned int i, num_cq_pages;
2906 struct be_queue_info *cq, *eq;
2907 struct be_dma_mem *mem;
2908 struct be_eq_obj *pbe_eq;
2912 num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
2913 sizeof(struct sol_cqe));
2915 for (i = 0; i < phba->num_cpus; i++) {
2916 cq = &phwi_context->be_cq[i];
2917 eq = &phwi_context->be_eq[i].q;
2918 pbe_eq = &phwi_context->be_eq[i];
2920 pbe_eq->phba = phba;
2922 cq_vaddress = pci_alloc_consistent(phba->pcidev,
2923 num_cq_pages * PAGE_SIZE,
2926 goto create_cq_error;
2927 ret = be_fill_queue(cq, phba->params.num_cq_entries,
2928 sizeof(struct sol_cqe), cq_vaddress);
2930 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2931 "BM_%d : be_fill_queue Failed "
2933 goto create_cq_error;
2937 ret = beiscsi_cmd_cq_create(&phba->ctrl, cq, eq, false,
2940 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2941 "BM_%d : beiscsi_cmd_eq_create"
2942 "Failed for ISCSI CQ\n");
2943 goto create_cq_error;
2945 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2946 "BM_%d : iscsi cq_id is %d for eq_id %d\n"
2947 "iSCSI CQ CREATED\n", cq->id, eq->id);
2952 for (i = 0; i < phba->num_cpus; i++) {
2953 cq = &phwi_context->be_cq[i];
2956 pci_free_consistent(phba->pcidev, num_cq_pages
2965 beiscsi_create_def_hdr(struct beiscsi_hba *phba,
2966 struct hwi_context_memory *phwi_context,
2967 struct hwi_controller *phwi_ctrlr,
2968 unsigned int def_pdu_ring_sz)
2972 struct be_queue_info *dq, *cq;
2973 struct be_dma_mem *mem;
2974 struct be_mem_descriptor *mem_descr;
2978 dq = &phwi_context->be_def_hdrq;
2979 cq = &phwi_context->be_cq[0];
2981 mem_descr = phba->init_mem;
2982 mem_descr += HWI_MEM_ASYNC_HEADER_RING;
2983 dq_vaddress = mem_descr->mem_array[idx].virtual_address;
2984 ret = be_fill_queue(dq, mem_descr->mem_array[0].size /
2985 sizeof(struct phys_addr),
2986 sizeof(struct phys_addr), dq_vaddress);
2988 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2989 "BM_%d : be_fill_queue Failed for DEF PDU HDR\n");
2992 mem->dma = (unsigned long)mem_descr->mem_array[idx].
2993 bus_address.u.a64.address;
2994 ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dq,
2996 phba->params.defpdu_hdr_sz);
2998 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2999 "BM_%d : be_cmd_create_default_pdu_queue Failed DEFHDR\n");
3002 phwi_ctrlr->default_pdu_hdr.id = phwi_context->be_def_hdrq.id;
3003 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3004 "BM_%d : iscsi def pdu id is %d\n",
3005 phwi_context->be_def_hdrq.id);
3007 hwi_post_async_buffers(phba, 1);
3012 beiscsi_create_def_data(struct beiscsi_hba *phba,
3013 struct hwi_context_memory *phwi_context,
3014 struct hwi_controller *phwi_ctrlr,
3015 unsigned int def_pdu_ring_sz)
3019 struct be_queue_info *dataq, *cq;
3020 struct be_dma_mem *mem;
3021 struct be_mem_descriptor *mem_descr;
3025 dataq = &phwi_context->be_def_dataq;
3026 cq = &phwi_context->be_cq[0];
3027 mem = &dataq->dma_mem;
3028 mem_descr = phba->init_mem;
3029 mem_descr += HWI_MEM_ASYNC_DATA_RING;
3030 dq_vaddress = mem_descr->mem_array[idx].virtual_address;
3031 ret = be_fill_queue(dataq, mem_descr->mem_array[0].size /
3032 sizeof(struct phys_addr),
3033 sizeof(struct phys_addr), dq_vaddress);
3035 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3036 "BM_%d : be_fill_queue Failed for DEF PDU DATA\n");
3039 mem->dma = (unsigned long)mem_descr->mem_array[idx].
3040 bus_address.u.a64.address;
3041 ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dataq,
3043 phba->params.defpdu_data_sz);
3045 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3046 "BM_%d be_cmd_create_default_pdu_queue"
3047 " Failed for DEF PDU DATA\n");
3050 phwi_ctrlr->default_pdu_data.id = phwi_context->be_def_dataq.id;
3051 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3052 "BM_%d : iscsi def data id is %d\n",
3053 phwi_context->be_def_dataq.id);
3055 hwi_post_async_buffers(phba, 0);
3056 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3057 "BM_%d : DEFAULT PDU DATA RING CREATED\n");
3063 beiscsi_post_pages(struct beiscsi_hba *phba)
3065 struct be_mem_descriptor *mem_descr;
3066 struct mem_array *pm_arr;
3067 unsigned int page_offset, i;
3068 struct be_dma_mem sgl;
3071 mem_descr = phba->init_mem;
3072 mem_descr += HWI_MEM_SGE;
3073 pm_arr = mem_descr->mem_array;
3075 page_offset = (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io *
3076 phba->fw_config.iscsi_icd_start) / PAGE_SIZE;
3077 for (i = 0; i < mem_descr->num_elements; i++) {
3078 hwi_build_be_sgl_arr(phba, pm_arr, &sgl);
3079 status = be_cmd_iscsi_post_sgl_pages(&phba->ctrl, &sgl,
3081 (pm_arr->size / PAGE_SIZE));
3082 page_offset += pm_arr->size / PAGE_SIZE;
3084 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3085 "BM_%d : post sgl failed.\n");
3090 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3091 "BM_%d : POSTED PAGES\n");
3095 static void be_queue_free(struct beiscsi_hba *phba, struct be_queue_info *q)
3097 struct be_dma_mem *mem = &q->dma_mem;
3099 pci_free_consistent(phba->pcidev, mem->size,
3105 static int be_queue_alloc(struct beiscsi_hba *phba, struct be_queue_info *q,
3106 u16 len, u16 entry_size)
3108 struct be_dma_mem *mem = &q->dma_mem;
3110 memset(q, 0, sizeof(*q));
3112 q->entry_size = entry_size;
3113 mem->size = len * entry_size;
3114 mem->va = pci_alloc_consistent(phba->pcidev, mem->size, &mem->dma);
3117 memset(mem->va, 0, mem->size);
3122 beiscsi_create_wrb_rings(struct beiscsi_hba *phba,
3123 struct hwi_context_memory *phwi_context,
3124 struct hwi_controller *phwi_ctrlr)
3126 unsigned int wrb_mem_index, offset, size, num_wrb_rings;
3128 unsigned int idx, num, i;
3129 struct mem_array *pwrb_arr;
3131 struct be_dma_mem sgl;
3132 struct be_mem_descriptor *mem_descr;
3136 mem_descr = phba->init_mem;
3137 mem_descr += HWI_MEM_WRB;
3138 pwrb_arr = kmalloc(sizeof(*pwrb_arr) * phba->params.cxns_per_ctrl,
3141 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3142 "BM_%d : Memory alloc failed in create wrb ring.\n");
3145 wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
3146 pa_addr_lo = mem_descr->mem_array[idx].bus_address.u.a64.address;
3147 num_wrb_rings = mem_descr->mem_array[idx].size /
3148 (phba->params.wrbs_per_cxn * sizeof(struct iscsi_wrb));
3150 for (num = 0; num < phba->params.cxns_per_ctrl; num++) {
3151 if (num_wrb_rings) {
3152 pwrb_arr[num].virtual_address = wrb_vaddr;
3153 pwrb_arr[num].bus_address.u.a64.address = pa_addr_lo;
3154 pwrb_arr[num].size = phba->params.wrbs_per_cxn *
3155 sizeof(struct iscsi_wrb);
3156 wrb_vaddr += pwrb_arr[num].size;
3157 pa_addr_lo += pwrb_arr[num].size;
3161 wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
3162 pa_addr_lo = mem_descr->mem_array[idx].\
3163 bus_address.u.a64.address;
3164 num_wrb_rings = mem_descr->mem_array[idx].size /
3165 (phba->params.wrbs_per_cxn *
3166 sizeof(struct iscsi_wrb));
3167 pwrb_arr[num].virtual_address = wrb_vaddr;
3168 pwrb_arr[num].bus_address.u.a64.address\
3170 pwrb_arr[num].size = phba->params.wrbs_per_cxn *
3171 sizeof(struct iscsi_wrb);
3172 wrb_vaddr += pwrb_arr[num].size;
3173 pa_addr_lo += pwrb_arr[num].size;
3177 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
3182 hwi_build_be_sgl_by_offset(phba, &pwrb_arr[i], &sgl);
3183 status = be_cmd_wrbq_create(&phba->ctrl, &sgl,
3184 &phwi_context->be_wrbq[i]);
3186 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3187 "BM_%d : wrbq create failed.");
3191 phwi_ctrlr->wrb_context[i * 2].cid = phwi_context->be_wrbq[i].
3198 static void free_wrb_handles(struct beiscsi_hba *phba)
3201 struct hwi_controller *phwi_ctrlr;
3202 struct hwi_wrb_context *pwrb_context;
3204 phwi_ctrlr = phba->phwi_ctrlr;
3205 for (index = 0; index < phba->params.cxns_per_ctrl * 2; index += 2) {
3206 pwrb_context = &phwi_ctrlr->wrb_context[index];
3207 kfree(pwrb_context->pwrb_handle_base);
3208 kfree(pwrb_context->pwrb_handle_basestd);
3212 static void be_mcc_queues_destroy(struct beiscsi_hba *phba)
3214 struct be_queue_info *q;
3215 struct be_ctrl_info *ctrl = &phba->ctrl;
3217 q = &phba->ctrl.mcc_obj.q;
3219 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_MCCQ);
3220 be_queue_free(phba, q);
3222 q = &phba->ctrl.mcc_obj.cq;
3224 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
3225 be_queue_free(phba, q);
3228 static void hwi_cleanup(struct beiscsi_hba *phba)
3230 struct be_queue_info *q;
3231 struct be_ctrl_info *ctrl = &phba->ctrl;
3232 struct hwi_controller *phwi_ctrlr;
3233 struct hwi_context_memory *phwi_context;
3236 phwi_ctrlr = phba->phwi_ctrlr;
3237 phwi_context = phwi_ctrlr->phwi_ctxt;
3238 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
3239 q = &phwi_context->be_wrbq[i];
3241 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_WRBQ);
3243 free_wrb_handles(phba);
3245 q = &phwi_context->be_def_hdrq;
3247 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
3249 q = &phwi_context->be_def_dataq;
3251 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
3253 beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
3255 for (i = 0; i < (phba->num_cpus); i++) {
3256 q = &phwi_context->be_cq[i];
3258 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
3260 if (phba->msix_enabled)
3264 for (i = 0; i < (phba->num_cpus + eq_num); i++) {
3265 q = &phwi_context->be_eq[i].q;
3267 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_EQ);
3269 be_mcc_queues_destroy(phba);
3272 static int be_mcc_queues_create(struct beiscsi_hba *phba,
3273 struct hwi_context_memory *phwi_context)
3275 struct be_queue_info *q, *cq;
3276 struct be_ctrl_info *ctrl = &phba->ctrl;
3278 /* Alloc MCC compl queue */
3279 cq = &phba->ctrl.mcc_obj.cq;
3280 if (be_queue_alloc(phba, cq, MCC_CQ_LEN,
3281 sizeof(struct be_mcc_compl)))
3283 /* Ask BE to create MCC compl queue; */
3284 if (phba->msix_enabled) {
3285 if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq
3286 [phba->num_cpus].q, false, true, 0))
3289 if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq[0].q,
3294 /* Alloc MCC queue */
3295 q = &phba->ctrl.mcc_obj.q;
3296 if (be_queue_alloc(phba, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb)))
3297 goto mcc_cq_destroy;
3299 /* Ask BE to create MCC queue */
3300 if (beiscsi_cmd_mccq_create(phba, q, cq))
3306 be_queue_free(phba, q);
3308 beiscsi_cmd_q_destroy(ctrl, cq, QTYPE_CQ);
3310 be_queue_free(phba, cq);
3316 * find_num_cpus()- Get the CPU online count
3317 * @phba: ptr to priv structure
3319 * CPU count is used for creating EQ.
3321 static void find_num_cpus(struct beiscsi_hba *phba)
3325 num_cpus = num_online_cpus();
3327 phba->num_cpus = (num_cpus >= BEISCSI_MAX_NUM_CPU) ?
3328 (BEISCSI_MAX_NUM_CPU - 1) : num_cpus;
3331 static int hwi_init_port(struct beiscsi_hba *phba)
3333 struct hwi_controller *phwi_ctrlr;
3334 struct hwi_context_memory *phwi_context;
3335 unsigned int def_pdu_ring_sz;
3336 struct be_ctrl_info *ctrl = &phba->ctrl;
3340 phba->params.asyncpdus_per_ctrl * sizeof(struct phys_addr);
3341 phwi_ctrlr = phba->phwi_ctrlr;
3342 phwi_context = phwi_ctrlr->phwi_ctxt;
3343 phwi_context->max_eqd = 0;
3344 phwi_context->min_eqd = 0;
3345 phwi_context->cur_eqd = 64;
3346 be_cmd_fw_initialize(&phba->ctrl);
3348 status = beiscsi_create_eqs(phba, phwi_context);
3350 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3351 "BM_%d : EQ not created\n");
3355 status = be_mcc_queues_create(phba, phwi_context);
3359 status = mgmt_check_supported_fw(ctrl, phba);
3361 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3362 "BM_%d : Unsupported fw version\n");
3366 status = beiscsi_create_cqs(phba, phwi_context);
3368 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3369 "BM_%d : CQ not created\n");
3373 status = beiscsi_create_def_hdr(phba, phwi_context, phwi_ctrlr,
3376 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3377 "BM_%d : Default Header not created\n");
3381 status = beiscsi_create_def_data(phba, phwi_context,
3382 phwi_ctrlr, def_pdu_ring_sz);
3384 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3385 "BM_%d : Default Data not created\n");
3389 status = beiscsi_post_pages(phba);
3391 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3392 "BM_%d : Post SGL Pages Failed\n");
3396 status = beiscsi_create_wrb_rings(phba, phwi_context, phwi_ctrlr);
3398 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3399 "BM_%d : WRB Rings not created\n");
3403 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3404 "BM_%d : hwi_init_port success\n");
3408 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3409 "BM_%d : hwi_init_port failed");
3414 static int hwi_init_controller(struct beiscsi_hba *phba)
3416 struct hwi_controller *phwi_ctrlr;
3418 phwi_ctrlr = phba->phwi_ctrlr;
3419 if (1 == phba->init_mem[HWI_MEM_ADDN_CONTEXT].num_elements) {
3420 phwi_ctrlr->phwi_ctxt = (struct hwi_context_memory *)phba->
3421 init_mem[HWI_MEM_ADDN_CONTEXT].mem_array[0].virtual_address;
3422 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3423 "BM_%d : phwi_ctrlr->phwi_ctxt=%p\n",
3424 phwi_ctrlr->phwi_ctxt);
3426 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3427 "BM_%d : HWI_MEM_ADDN_CONTEXT is more "
3428 "than one element.Failing to load\n");
3432 iscsi_init_global_templates(phba);
3433 if (beiscsi_init_wrb_handle(phba))
3436 hwi_init_async_pdu_ctx(phba);
3437 if (hwi_init_port(phba) != 0) {
3438 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3439 "BM_%d : hwi_init_controller failed\n");
3446 static void beiscsi_free_mem(struct beiscsi_hba *phba)
3448 struct be_mem_descriptor *mem_descr;
3451 mem_descr = phba->init_mem;
3454 for (i = 0; i < SE_MEM_MAX; i++) {
3455 for (j = mem_descr->num_elements; j > 0; j--) {
3456 pci_free_consistent(phba->pcidev,
3457 mem_descr->mem_array[j - 1].size,
3458 mem_descr->mem_array[j - 1].virtual_address,
3459 (unsigned long)mem_descr->mem_array[j - 1].
3460 bus_address.u.a64.address);
3462 kfree(mem_descr->mem_array);
3465 kfree(phba->init_mem);
3466 kfree(phba->phwi_ctrlr);
3469 static int beiscsi_init_controller(struct beiscsi_hba *phba)
3473 ret = beiscsi_get_memory(phba);
3475 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3476 "BM_%d : beiscsi_dev_probe -"
3477 "Failed in beiscsi_alloc_memory\n");
3481 ret = hwi_init_controller(phba);
3484 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3485 "BM_%d : Return success from beiscsi_init_controller");
3490 beiscsi_free_mem(phba);
3494 static int beiscsi_init_sgl_handle(struct beiscsi_hba *phba)
3496 struct be_mem_descriptor *mem_descr_sglh, *mem_descr_sg;
3497 struct sgl_handle *psgl_handle;
3498 struct iscsi_sge *pfrag;
3499 unsigned int arr_index, i, idx;
3501 phba->io_sgl_hndl_avbl = 0;
3502 phba->eh_sgl_hndl_avbl = 0;
3504 mem_descr_sglh = phba->init_mem;
3505 mem_descr_sglh += HWI_MEM_SGLH;
3506 if (1 == mem_descr_sglh->num_elements) {
3507 phba->io_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
3508 phba->params.ios_per_ctrl,
3510 if (!phba->io_sgl_hndl_base) {
3511 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3512 "BM_%d : Mem Alloc Failed. Failing to load\n");
3515 phba->eh_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
3516 (phba->params.icds_per_ctrl -
3517 phba->params.ios_per_ctrl),
3519 if (!phba->eh_sgl_hndl_base) {
3520 kfree(phba->io_sgl_hndl_base);
3521 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3522 "BM_%d : Mem Alloc Failed. Failing to load\n");
3526 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3527 "BM_%d : HWI_MEM_SGLH is more than one element."
3528 "Failing to load\n");
3534 while (idx < mem_descr_sglh->num_elements) {
3535 psgl_handle = mem_descr_sglh->mem_array[idx].virtual_address;
3537 for (i = 0; i < (mem_descr_sglh->mem_array[idx].size /
3538 sizeof(struct sgl_handle)); i++) {
3539 if (arr_index < phba->params.ios_per_ctrl) {
3540 phba->io_sgl_hndl_base[arr_index] = psgl_handle;
3541 phba->io_sgl_hndl_avbl++;
3544 phba->eh_sgl_hndl_base[arr_index -
3545 phba->params.ios_per_ctrl] =
3548 phba->eh_sgl_hndl_avbl++;
3554 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3555 "BM_%d : phba->io_sgl_hndl_avbl=%d"
3556 "phba->eh_sgl_hndl_avbl=%d\n",
3557 phba->io_sgl_hndl_avbl,
3558 phba->eh_sgl_hndl_avbl);
3560 mem_descr_sg = phba->init_mem;
3561 mem_descr_sg += HWI_MEM_SGE;
3562 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3563 "\n BM_%d : mem_descr_sg->num_elements=%d\n",
3564 mem_descr_sg->num_elements);
3568 while (idx < mem_descr_sg->num_elements) {
3569 pfrag = mem_descr_sg->mem_array[idx].virtual_address;
3572 i < (mem_descr_sg->mem_array[idx].size) /
3573 (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io);
3575 if (arr_index < phba->params.ios_per_ctrl)
3576 psgl_handle = phba->io_sgl_hndl_base[arr_index];
3578 psgl_handle = phba->eh_sgl_hndl_base[arr_index -
3579 phba->params.ios_per_ctrl];
3580 psgl_handle->pfrag = pfrag;
3581 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, pfrag, 0);
3582 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, pfrag, 0);
3583 pfrag += phba->params.num_sge_per_io;
3584 psgl_handle->sgl_index =
3585 phba->fw_config.iscsi_icd_start + arr_index++;
3589 phba->io_sgl_free_index = 0;
3590 phba->io_sgl_alloc_index = 0;
3591 phba->eh_sgl_free_index = 0;
3592 phba->eh_sgl_alloc_index = 0;
3596 static int hba_setup_cid_tbls(struct beiscsi_hba *phba)
3600 phba->cid_array = kzalloc(sizeof(void *) * phba->params.cxns_per_ctrl,
3602 if (!phba->cid_array) {
3603 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3604 "BM_%d : Failed to allocate memory in "
3605 "hba_setup_cid_tbls\n");
3608 phba->ep_array = kzalloc(sizeof(struct iscsi_endpoint *) *
3609 phba->params.cxns_per_ctrl * 2, GFP_KERNEL);
3610 if (!phba->ep_array) {
3611 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3612 "BM_%d : Failed to allocate memory in "
3613 "hba_setup_cid_tbls\n");
3614 kfree(phba->cid_array);
3617 new_cid = phba->fw_config.iscsi_cid_start;
3618 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
3619 phba->cid_array[i] = new_cid;
3622 phba->avlbl_cids = phba->params.cxns_per_ctrl;
3626 static void hwi_enable_intr(struct beiscsi_hba *phba)
3628 struct be_ctrl_info *ctrl = &phba->ctrl;
3629 struct hwi_controller *phwi_ctrlr;
3630 struct hwi_context_memory *phwi_context;
3631 struct be_queue_info *eq;
3636 phwi_ctrlr = phba->phwi_ctrlr;
3637 phwi_context = phwi_ctrlr->phwi_ctxt;
3639 addr = (u8 __iomem *) ((u8 __iomem *) ctrl->pcicfg +
3640 PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET);
3641 reg = ioread32(addr);
3643 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
3645 reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
3646 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3647 "BM_%d : reg =x%08x addr=%p\n", reg, addr);
3648 iowrite32(reg, addr);
3651 if (!phba->msix_enabled) {
3652 eq = &phwi_context->be_eq[0].q;
3653 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3654 "BM_%d : eq->id=%d\n", eq->id);
3656 hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
3658 for (i = 0; i <= phba->num_cpus; i++) {
3659 eq = &phwi_context->be_eq[i].q;
3660 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3661 "BM_%d : eq->id=%d\n", eq->id);
3662 hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
3667 static void hwi_disable_intr(struct beiscsi_hba *phba)
3669 struct be_ctrl_info *ctrl = &phba->ctrl;
3671 u8 __iomem *addr = ctrl->pcicfg + PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET;
3672 u32 reg = ioread32(addr);
3674 u32 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
3676 reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
3677 iowrite32(reg, addr);
3679 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
3680 "BM_%d : In hwi_disable_intr, Already Disabled\n");
3684 * beiscsi_get_boot_info()- Get the boot session info
3685 * @phba: The device priv structure instance
3687 * Get the boot target info and store in driver priv structure
3691 * Failure: Non-Zero Value
3693 static int beiscsi_get_boot_info(struct beiscsi_hba *phba)
3695 struct be_cmd_get_session_resp *session_resp;
3696 struct be_mcc_wrb *wrb;
3697 struct be_dma_mem nonemb_cmd;
3698 unsigned int tag, wrb_num;
3699 unsigned short status, extd_status;
3700 unsigned int s_handle;
3701 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
3704 /* Get the session handle of the boot target */
3705 ret = be_mgmt_get_boot_shandle(phba, &s_handle);
3707 beiscsi_log(phba, KERN_ERR,
3708 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
3709 "BM_%d : No boot session\n");
3712 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
3713 sizeof(*session_resp),
3715 if (nonemb_cmd.va == NULL) {
3716 beiscsi_log(phba, KERN_ERR,
3717 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
3718 "BM_%d : Failed to allocate memory for"
3719 "beiscsi_get_session_info\n");
3724 memset(nonemb_cmd.va, 0, sizeof(*session_resp));
3725 tag = mgmt_get_session_info(phba, s_handle,
3728 beiscsi_log(phba, KERN_ERR,
3729 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
3730 "BM_%d : beiscsi_get_session_info"
3735 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
3736 phba->ctrl.mcc_numtag[tag]);
3738 wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
3739 extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
3740 status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
3741 if (status || extd_status) {
3742 beiscsi_log(phba, KERN_ERR,
3743 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
3744 "BM_%d : beiscsi_get_session_info Failed"
3745 " status = %d extd_status = %d\n",
3746 status, extd_status);
3748 free_mcc_tag(&phba->ctrl, tag);
3751 wrb = queue_get_wrb(mccq, wrb_num);
3752 free_mcc_tag(&phba->ctrl, tag);
3753 session_resp = nonemb_cmd.va ;
3755 memcpy(&phba->boot_sess, &session_resp->session_info,
3756 sizeof(struct mgmt_session_info));
3760 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
3761 nonemb_cmd.va, nonemb_cmd.dma);
3765 static void beiscsi_boot_release(void *data)
3767 struct beiscsi_hba *phba = data;
3769 scsi_host_put(phba->shost);
3772 static int beiscsi_setup_boot_info(struct beiscsi_hba *phba)
3774 struct iscsi_boot_kobj *boot_kobj;
3776 /* get boot info using mgmt cmd */
3777 if (beiscsi_get_boot_info(phba))
3778 /* Try to see if we can carry on without this */
3781 phba->boot_kset = iscsi_boot_create_host_kset(phba->shost->host_no);
3782 if (!phba->boot_kset)
3785 /* get a ref because the show function will ref the phba */
3786 if (!scsi_host_get(phba->shost))
3788 boot_kobj = iscsi_boot_create_target(phba->boot_kset, 0, phba,
3789 beiscsi_show_boot_tgt_info,
3790 beiscsi_tgt_get_attr_visibility,
3791 beiscsi_boot_release);
3795 if (!scsi_host_get(phba->shost))
3797 boot_kobj = iscsi_boot_create_initiator(phba->boot_kset, 0, phba,
3798 beiscsi_show_boot_ini_info,
3799 beiscsi_ini_get_attr_visibility,
3800 beiscsi_boot_release);
3804 if (!scsi_host_get(phba->shost))
3806 boot_kobj = iscsi_boot_create_ethernet(phba->boot_kset, 0, phba,
3807 beiscsi_show_boot_eth_info,
3808 beiscsi_eth_get_attr_visibility,
3809 beiscsi_boot_release);
3815 scsi_host_put(phba->shost);
3817 iscsi_boot_destroy_kset(phba->boot_kset);
3821 static int beiscsi_init_port(struct beiscsi_hba *phba)
3825 ret = beiscsi_init_controller(phba);
3827 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3828 "BM_%d : beiscsi_dev_probe - Failed in"
3829 "beiscsi_init_controller\n");
3832 ret = beiscsi_init_sgl_handle(phba);
3834 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3835 "BM_%d : beiscsi_dev_probe - Failed in"
3836 "beiscsi_init_sgl_handle\n");
3837 goto do_cleanup_ctrlr;
3840 if (hba_setup_cid_tbls(phba)) {
3841 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3842 "BM_%d : Failed in hba_setup_cid_tbls\n");
3843 kfree(phba->io_sgl_hndl_base);
3844 kfree(phba->eh_sgl_hndl_base);
3845 goto do_cleanup_ctrlr;
3855 static void hwi_purge_eq(struct beiscsi_hba *phba)
3857 struct hwi_controller *phwi_ctrlr;
3858 struct hwi_context_memory *phwi_context;
3859 struct be_queue_info *eq;
3860 struct be_eq_entry *eqe = NULL;
3862 unsigned int num_processed;
3864 phwi_ctrlr = phba->phwi_ctrlr;
3865 phwi_context = phwi_ctrlr->phwi_ctxt;
3866 if (phba->msix_enabled)
3871 for (i = 0; i < (phba->num_cpus + eq_msix); i++) {
3872 eq = &phwi_context->be_eq[i].q;
3873 eqe = queue_tail_node(eq);
3875 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
3877 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
3879 eqe = queue_tail_node(eq);
3884 hwi_ring_eq_db(phba, eq->id, 1, num_processed, 1, 1);
3888 static void beiscsi_clean_port(struct beiscsi_hba *phba)
3892 mgmt_status = mgmt_epfw_cleanup(phba, CMD_CONNECTION_CHUTE_0);
3894 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
3895 "BM_%d : mgmt_epfw_cleanup FAILED\n");
3899 kfree(phba->io_sgl_hndl_base);
3900 kfree(phba->eh_sgl_hndl_base);
3901 kfree(phba->cid_array);
3902 kfree(phba->ep_array);
3906 * beiscsi_cleanup_task()- Free driver resources of the task
3907 * @task: ptr to the iscsi task
3910 static void beiscsi_cleanup_task(struct iscsi_task *task)
3912 struct beiscsi_io_task *io_task = task->dd_data;
3913 struct iscsi_conn *conn = task->conn;
3914 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
3915 struct beiscsi_hba *phba = beiscsi_conn->phba;
3916 struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
3917 struct hwi_wrb_context *pwrb_context;
3918 struct hwi_controller *phwi_ctrlr;
3920 phwi_ctrlr = phba->phwi_ctrlr;
3921 pwrb_context = &phwi_ctrlr->wrb_context[beiscsi_conn->beiscsi_conn_cid
3922 - phba->fw_config.iscsi_cid_start];
3924 if (io_task->cmd_bhs) {
3925 pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
3926 io_task->bhs_pa.u.a64.address);
3927 io_task->cmd_bhs = NULL;
3931 if (io_task->pwrb_handle) {
3932 free_wrb_handle(phba, pwrb_context,
3933 io_task->pwrb_handle);
3934 io_task->pwrb_handle = NULL;
3937 if (io_task->psgl_handle) {
3938 spin_lock(&phba->io_sgl_lock);
3939 free_io_sgl_handle(phba, io_task->psgl_handle);
3940 spin_unlock(&phba->io_sgl_lock);
3941 io_task->psgl_handle = NULL;
3944 if (!beiscsi_conn->login_in_progress) {
3945 if (io_task->pwrb_handle) {
3946 free_wrb_handle(phba, pwrb_context,
3947 io_task->pwrb_handle);
3948 io_task->pwrb_handle = NULL;
3950 if (io_task->psgl_handle) {
3951 spin_lock(&phba->mgmt_sgl_lock);
3952 free_mgmt_sgl_handle(phba,
3953 io_task->psgl_handle);
3954 spin_unlock(&phba->mgmt_sgl_lock);
3955 io_task->psgl_handle = NULL;
3957 if (io_task->mtask_addr) {
3958 pci_unmap_single(phba->pcidev,
3959 io_task->mtask_addr,
3960 io_task->mtask_data_count,
3962 io_task->mtask_addr = 0;
3969 beiscsi_offload_connection(struct beiscsi_conn *beiscsi_conn,
3970 struct beiscsi_offload_params *params)
3972 struct wrb_handle *pwrb_handle;
3973 struct iscsi_target_context_update_wrb *pwrb = NULL;
3974 struct be_mem_descriptor *mem_descr;
3975 struct beiscsi_hba *phba = beiscsi_conn->phba;
3976 struct iscsi_task *task = beiscsi_conn->task;
3977 struct iscsi_session *session = task->conn->session;
3981 * We can always use 0 here because it is reserved by libiscsi for
3982 * login/startup related tasks.
3984 beiscsi_conn->login_in_progress = 0;
3985 spin_lock_bh(&session->lock);
3986 beiscsi_cleanup_task(task);
3987 spin_unlock_bh(&session->lock);
3989 pwrb_handle = alloc_wrb_handle(phba, (beiscsi_conn->beiscsi_conn_cid -
3990 phba->fw_config.iscsi_cid_start));
3991 pwrb = (struct iscsi_target_context_update_wrb *)pwrb_handle->pwrb;
3992 memset(pwrb, 0, sizeof(*pwrb));
3993 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
3994 max_burst_length, pwrb, params->dw[offsetof
3995 (struct amap_beiscsi_offload_params,
3996 max_burst_length) / 32]);
3997 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
3998 max_send_data_segment_length, pwrb,
3999 params->dw[offsetof(struct amap_beiscsi_offload_params,
4000 max_send_data_segment_length) / 32]);
4001 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
4004 params->dw[offsetof(struct amap_beiscsi_offload_params,
4005 first_burst_length) / 32]);
4007 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, erl, pwrb,
4008 (params->dw[offsetof(struct amap_beiscsi_offload_params,
4009 erl) / 32] & OFFLD_PARAMS_ERL));
4010 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, dde, pwrb,
4011 (params->dw[offsetof(struct amap_beiscsi_offload_params,
4012 dde) / 32] & OFFLD_PARAMS_DDE) >> 2);
4013 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, hde, pwrb,
4014 (params->dw[offsetof(struct amap_beiscsi_offload_params,
4015 hde) / 32] & OFFLD_PARAMS_HDE) >> 3);
4016 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, ir2t, pwrb,
4017 (params->dw[offsetof(struct amap_beiscsi_offload_params,
4018 ir2t) / 32] & OFFLD_PARAMS_IR2T) >> 4);
4019 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, imd, pwrb,
4020 (params->dw[offsetof(struct amap_beiscsi_offload_params,
4021 imd) / 32] & OFFLD_PARAMS_IMD) >> 5);
4022 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, stat_sn,
4024 (params->dw[offsetof(struct amap_beiscsi_offload_params,
4025 exp_statsn) / 32] + 1));
4026 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, type, pwrb,
4028 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, wrb_idx,
4029 pwrb, pwrb_handle->wrb_index);
4030 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, ptr2nextwrb,
4031 pwrb, pwrb_handle->nxt_wrb_index);
4032 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
4033 session_state, pwrb, 0);
4034 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, compltonack,
4036 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, notpredblq,
4038 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, mode, pwrb,
4041 mem_descr = phba->init_mem;
4042 mem_descr += ISCSI_MEM_GLOBAL_HEADER;
4044 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
4045 pad_buffer_addr_hi, pwrb,
4046 mem_descr->mem_array[0].bus_address.u.a32.address_hi);
4047 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
4048 pad_buffer_addr_lo, pwrb,
4049 mem_descr->mem_array[0].bus_address.u.a32.address_lo);
4051 be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_target_context_update_wrb));
4053 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
4054 doorbell |= (pwrb_handle->wrb_index & DB_DEF_PDU_WRB_INDEX_MASK)
4055 << DB_DEF_PDU_WRB_INDEX_SHIFT;
4056 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
4058 iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
4061 static void beiscsi_parse_pdu(struct iscsi_conn *conn, itt_t itt,
4062 int *index, int *age)
4066 *age = conn->session->age;
4070 * beiscsi_alloc_pdu - allocates pdu and related resources
4071 * @task: libiscsi task
4072 * @opcode: opcode of pdu for task
4074 * This is called with the session lock held. It will allocate
4075 * the wrb and sgl if needed for the command. And it will prep
4076 * the pdu's itt. beiscsi_parse_pdu will later translate
4077 * the pdu itt to the libiscsi task itt.
4079 static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
4081 struct beiscsi_io_task *io_task = task->dd_data;
4082 struct iscsi_conn *conn = task->conn;
4083 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4084 struct beiscsi_hba *phba = beiscsi_conn->phba;
4085 struct hwi_wrb_context *pwrb_context;
4086 struct hwi_controller *phwi_ctrlr;
4088 struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
4091 io_task->cmd_bhs = pci_pool_alloc(beiscsi_sess->bhs_pool,
4092 GFP_ATOMIC, &paddr);
4093 if (!io_task->cmd_bhs)
4095 io_task->bhs_pa.u.a64.address = paddr;
4096 io_task->libiscsi_itt = (itt_t)task->itt;
4097 io_task->conn = beiscsi_conn;
4099 task->hdr = (struct iscsi_hdr *)&io_task->cmd_bhs->iscsi_hdr;
4100 task->hdr_max = sizeof(struct be_cmd_bhs);
4101 io_task->psgl_handle = NULL;
4102 io_task->pwrb_handle = NULL;
4105 spin_lock(&phba->io_sgl_lock);
4106 io_task->psgl_handle = alloc_io_sgl_handle(phba);
4107 spin_unlock(&phba->io_sgl_lock);
4108 if (!io_task->psgl_handle)
4110 io_task->pwrb_handle = alloc_wrb_handle(phba,
4111 beiscsi_conn->beiscsi_conn_cid -
4112 phba->fw_config.iscsi_cid_start);
4113 if (!io_task->pwrb_handle)
4116 io_task->scsi_cmnd = NULL;
4117 if ((opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN) {
4118 if (!beiscsi_conn->login_in_progress) {
4119 spin_lock(&phba->mgmt_sgl_lock);
4120 io_task->psgl_handle = (struct sgl_handle *)
4121 alloc_mgmt_sgl_handle(phba);
4122 spin_unlock(&phba->mgmt_sgl_lock);
4123 if (!io_task->psgl_handle)
4126 beiscsi_conn->login_in_progress = 1;
4127 beiscsi_conn->plogin_sgl_handle =
4128 io_task->psgl_handle;
4129 io_task->pwrb_handle =
4130 alloc_wrb_handle(phba,
4131 beiscsi_conn->beiscsi_conn_cid -
4132 phba->fw_config.iscsi_cid_start);
4133 if (!io_task->pwrb_handle)
4135 beiscsi_conn->plogin_wrb_handle =
4136 io_task->pwrb_handle;
4139 io_task->psgl_handle =
4140 beiscsi_conn->plogin_sgl_handle;
4141 io_task->pwrb_handle =
4142 beiscsi_conn->plogin_wrb_handle;
4144 beiscsi_conn->task = task;
4146 spin_lock(&phba->mgmt_sgl_lock);
4147 io_task->psgl_handle = alloc_mgmt_sgl_handle(phba);
4148 spin_unlock(&phba->mgmt_sgl_lock);
4149 if (!io_task->psgl_handle)
4151 io_task->pwrb_handle =
4152 alloc_wrb_handle(phba,
4153 beiscsi_conn->beiscsi_conn_cid -
4154 phba->fw_config.iscsi_cid_start);
4155 if (!io_task->pwrb_handle)
4156 goto free_mgmt_hndls;
4160 itt = (itt_t) cpu_to_be32(((unsigned int)io_task->pwrb_handle->
4161 wrb_index << 16) | (unsigned int)
4162 (io_task->psgl_handle->sgl_index));
4163 io_task->pwrb_handle->pio_handle = task;
4165 io_task->cmd_bhs->iscsi_hdr.itt = itt;
4169 spin_lock(&phba->io_sgl_lock);
4170 free_io_sgl_handle(phba, io_task->psgl_handle);
4171 spin_unlock(&phba->io_sgl_lock);
4174 spin_lock(&phba->mgmt_sgl_lock);
4175 free_mgmt_sgl_handle(phba, io_task->psgl_handle);
4176 spin_unlock(&phba->mgmt_sgl_lock);
4178 phwi_ctrlr = phba->phwi_ctrlr;
4179 pwrb_context = &phwi_ctrlr->wrb_context[
4180 beiscsi_conn->beiscsi_conn_cid -
4181 phba->fw_config.iscsi_cid_start];
4182 if (io_task->pwrb_handle)
4183 free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle);
4184 io_task->pwrb_handle = NULL;
4185 pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
4186 io_task->bhs_pa.u.a64.address);
4187 io_task->cmd_bhs = NULL;
4188 beiscsi_log(phba, KERN_ERR,
4189 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
4190 "BM_%d : Alloc of SGL_ICD Failed\n");
4194 static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg,
4195 unsigned int num_sg, unsigned int xferlen,
4196 unsigned int writedir)
4199 struct beiscsi_io_task *io_task = task->dd_data;
4200 struct iscsi_conn *conn = task->conn;
4201 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4202 struct beiscsi_hba *phba = beiscsi_conn->phba;
4203 struct iscsi_wrb *pwrb = NULL;
4204 unsigned int doorbell = 0;
4206 pwrb = io_task->pwrb_handle->pwrb;
4207 io_task->cmd_bhs->iscsi_hdr.exp_statsn = 0;
4208 io_task->bhs_len = sizeof(struct be_cmd_bhs);
4211 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4213 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1);
4215 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4217 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
4220 AMAP_SET_BITS(struct amap_iscsi_wrb, lun, pwrb,
4221 cpu_to_be16(*(unsigned short *)
4222 &io_task->cmd_bhs->iscsi_hdr.lun));
4223 AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, xferlen);
4224 AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
4225 io_task->pwrb_handle->wrb_index);
4226 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
4227 be32_to_cpu(task->cmdsn));
4228 AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
4229 io_task->psgl_handle->sgl_index);
4231 hwi_write_sgl(pwrb, sg, num_sg, io_task);
4233 AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
4234 io_task->pwrb_handle->nxt_wrb_index);
4235 be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
4237 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
4238 doorbell |= (io_task->pwrb_handle->wrb_index &
4239 DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
4240 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
4242 iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
4246 static int beiscsi_mtask(struct iscsi_task *task)
4248 struct beiscsi_io_task *io_task = task->dd_data;
4249 struct iscsi_conn *conn = task->conn;
4250 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4251 struct beiscsi_hba *phba = beiscsi_conn->phba;
4252 struct iscsi_wrb *pwrb = NULL;
4253 unsigned int doorbell = 0;
4256 cid = beiscsi_conn->beiscsi_conn_cid;
4257 pwrb = io_task->pwrb_handle->pwrb;
4258 memset(pwrb, 0, sizeof(*pwrb));
4259 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
4260 be32_to_cpu(task->cmdsn));
4261 AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
4262 io_task->pwrb_handle->wrb_index);
4263 AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
4264 io_task->psgl_handle->sgl_index);
4266 switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
4267 case ISCSI_OP_LOGIN:
4268 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4270 AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
4271 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, 1);
4272 hwi_write_buffer(pwrb, task);
4274 case ISCSI_OP_NOOP_OUT:
4275 if (task->hdr->ttt != ISCSI_RESERVED_TAG) {
4276 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4278 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt,
4280 AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 1);
4282 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4284 AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
4286 hwi_write_buffer(pwrb, task);
4289 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4291 AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
4292 hwi_write_buffer(pwrb, task);
4294 case ISCSI_OP_SCSI_TMFUNC:
4295 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4297 AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
4298 hwi_write_buffer(pwrb, task);
4300 case ISCSI_OP_LOGOUT:
4301 AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
4302 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4304 hwi_write_buffer(pwrb, task);
4308 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
4309 "BM_%d : opcode =%d Not supported\n",
4310 task->hdr->opcode & ISCSI_OPCODE_MASK);
4315 AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb,
4317 AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
4318 io_task->pwrb_handle->nxt_wrb_index);
4319 be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
4321 doorbell |= cid & DB_WRB_POST_CID_MASK;
4322 doorbell |= (io_task->pwrb_handle->wrb_index &
4323 DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
4324 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
4325 iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
4329 static int beiscsi_task_xmit(struct iscsi_task *task)
4331 struct beiscsi_io_task *io_task = task->dd_data;
4332 struct scsi_cmnd *sc = task->sc;
4333 struct scatterlist *sg;
4335 unsigned int writedir = 0, xferlen = 0;
4338 return beiscsi_mtask(task);
4340 io_task->scsi_cmnd = sc;
4341 num_sg = scsi_dma_map(sc);
4343 struct iscsi_conn *conn = task->conn;
4344 struct beiscsi_hba *phba = NULL;
4346 phba = ((struct beiscsi_conn *)conn->dd_data)->phba;
4347 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_IO,
4348 "BM_%d : scsi_dma_map Failed\n");
4352 xferlen = scsi_bufflen(sc);
4353 sg = scsi_sglist(sc);
4354 if (sc->sc_data_direction == DMA_TO_DEVICE)
4359 return beiscsi_iotask(task, sg, num_sg, xferlen, writedir);
4363 * beiscsi_bsg_request - handle bsg request from ISCSI transport
4364 * @job: job to handle
4366 static int beiscsi_bsg_request(struct bsg_job *job)
4368 struct Scsi_Host *shost;
4369 struct beiscsi_hba *phba;
4370 struct iscsi_bsg_request *bsg_req = job->request;
4373 struct be_dma_mem nonemb_cmd;
4374 struct be_cmd_resp_hdr *resp;
4375 struct iscsi_bsg_reply *bsg_reply = job->reply;
4376 unsigned short status, extd_status;
4378 shost = iscsi_job_to_shost(job);
4379 phba = iscsi_host_priv(shost);
4381 switch (bsg_req->msgcode) {
4382 case ISCSI_BSG_HST_VENDOR:
4383 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
4384 job->request_payload.payload_len,
4386 if (nonemb_cmd.va == NULL) {
4387 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
4388 "BM_%d : Failed to allocate memory for "
4389 "beiscsi_bsg_request\n");
4392 tag = mgmt_vendor_specific_fw_cmd(&phba->ctrl, phba, job,
4395 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
4396 "BM_%d : be_cmd_get_mac_addr Failed\n");
4398 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
4399 nonemb_cmd.va, nonemb_cmd.dma);
4402 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
4403 phba->ctrl.mcc_numtag[tag]);
4404 extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
4405 status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
4406 free_mcc_tag(&phba->ctrl, tag);
4407 resp = (struct be_cmd_resp_hdr *)nonemb_cmd.va;
4408 sg_copy_from_buffer(job->reply_payload.sg_list,
4409 job->reply_payload.sg_cnt,
4410 nonemb_cmd.va, (resp->response_length
4412 bsg_reply->reply_payload_rcv_len = resp->response_length;
4413 bsg_reply->result = status;
4414 bsg_job_done(job, bsg_reply->result,
4415 bsg_reply->reply_payload_rcv_len);
4416 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
4417 nonemb_cmd.va, nonemb_cmd.dma);
4418 if (status || extd_status) {
4419 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
4420 "BM_%d : be_cmd_get_mac_addr Failed"
4421 " status = %d extd_status = %d\n",
4422 status, extd_status);
4429 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
4430 "BM_%d : Unsupported bsg command: 0x%x\n",
4438 void beiscsi_hba_attrs_init(struct beiscsi_hba *phba)
4440 /* Set the logging parameter */
4441 beiscsi_log_enable_init(phba, beiscsi_log_enable);
4445 * beiscsi_quiesce()- Cleanup Driver resources
4446 * @phba: Instance Priv structure
4448 * Free the OS and HW resources held by the driver
4450 static void beiscsi_quiesce(struct beiscsi_hba *phba)
4452 struct hwi_controller *phwi_ctrlr;
4453 struct hwi_context_memory *phwi_context;
4454 struct be_eq_obj *pbe_eq;
4455 unsigned int i, msix_vec;
4457 phwi_ctrlr = phba->phwi_ctrlr;
4458 phwi_context = phwi_ctrlr->phwi_ctxt;
4459 hwi_disable_intr(phba);
4460 if (phba->msix_enabled) {
4461 for (i = 0; i <= phba->num_cpus; i++) {
4462 msix_vec = phba->msix_entries[i].vector;
4463 free_irq(msix_vec, &phwi_context->be_eq[i]);
4464 kfree(phba->msi_name[i]);
4467 if (phba->pcidev->irq)
4468 free_irq(phba->pcidev->irq, phba);
4469 pci_disable_msix(phba->pcidev);
4470 destroy_workqueue(phba->wq);
4471 if (blk_iopoll_enabled)
4472 for (i = 0; i < phba->num_cpus; i++) {
4473 pbe_eq = &phwi_context->be_eq[i];
4474 blk_iopoll_disable(&pbe_eq->iopoll);
4477 beiscsi_clean_port(phba);
4478 beiscsi_free_mem(phba);
4480 beiscsi_unmap_pci_function(phba);
4481 pci_free_consistent(phba->pcidev,
4482 phba->ctrl.mbox_mem_alloced.size,
4483 phba->ctrl.mbox_mem_alloced.va,
4484 phba->ctrl.mbox_mem_alloced.dma);
4487 static void beiscsi_remove(struct pci_dev *pcidev)
4490 struct beiscsi_hba *phba = NULL;
4492 phba = pci_get_drvdata(pcidev);
4494 dev_err(&pcidev->dev, "beiscsi_remove called with no phba\n");
4498 beiscsi_destroy_def_ifaces(phba);
4499 beiscsi_quiesce(phba);
4500 iscsi_boot_destroy_kset(phba->boot_kset);
4501 iscsi_host_remove(phba->shost);
4502 pci_dev_put(phba->pcidev);
4503 iscsi_host_free(phba->shost);
4504 pci_disable_device(pcidev);
4507 static void beiscsi_shutdown(struct pci_dev *pcidev)
4510 struct beiscsi_hba *phba = NULL;
4512 phba = (struct beiscsi_hba *)pci_get_drvdata(pcidev);
4514 dev_err(&pcidev->dev, "beiscsi_shutdown called with no phba\n");
4518 beiscsi_quiesce(phba);
4519 pci_disable_device(pcidev);
4522 static void beiscsi_msix_enable(struct beiscsi_hba *phba)
4526 for (i = 0; i <= phba->num_cpus; i++)
4527 phba->msix_entries[i].entry = i;
4529 status = pci_enable_msix(phba->pcidev, phba->msix_entries,
4530 (phba->num_cpus + 1));
4532 phba->msix_enabled = true;
4537 static int __devinit beiscsi_dev_probe(struct pci_dev *pcidev,
4538 const struct pci_device_id *id)
4540 struct beiscsi_hba *phba = NULL;
4541 struct hwi_controller *phwi_ctrlr;
4542 struct hwi_context_memory *phwi_context;
4543 struct be_eq_obj *pbe_eq;
4546 ret = beiscsi_enable_pci(pcidev);
4548 dev_err(&pcidev->dev,
4549 "beiscsi_dev_probe - Failed to enable pci device\n");
4553 phba = beiscsi_hba_alloc(pcidev);
4555 dev_err(&pcidev->dev,
4556 "beiscsi_dev_probe - Failed in beiscsi_hba_alloc\n");
4560 /* Initialize Driver configuration Paramters */
4561 beiscsi_hba_attrs_init(phba);
4563 switch (pcidev->device) {
4567 phba->generation = BE_GEN2;
4571 phba->generation = BE_GEN3;
4574 phba->generation = 0;
4578 find_num_cpus(phba);
4582 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4583 "BM_%d : num_cpus = %d\n",
4587 beiscsi_msix_enable(phba);
4588 if (!phba->msix_enabled)
4591 ret = be_ctrl_init(phba, pcidev);
4593 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4594 "BM_%d : beiscsi_dev_probe-"
4595 "Failed in be_ctrl_init\n");
4599 ret = beiscsi_cmd_reset_function(phba);
4601 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4602 "BM_%d : Reset Failed. Aborting Crashdump\n");
4605 ret = be_chk_reset_complete(phba);
4607 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4608 "BM_%d : Failed to get out of reset."
4609 "Aborting Crashdump\n");
4613 spin_lock_init(&phba->io_sgl_lock);
4614 spin_lock_init(&phba->mgmt_sgl_lock);
4615 spin_lock_init(&phba->isr_lock);
4616 ret = mgmt_get_fw_config(&phba->ctrl, phba);
4618 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4619 "BM_%d : Error getting fw config\n");
4622 phba->shost->max_id = phba->fw_config.iscsi_cid_count;
4623 beiscsi_get_params(phba);
4624 phba->shost->can_queue = phba->params.ios_per_ctrl;
4625 ret = beiscsi_init_port(phba);
4627 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4628 "BM_%d : beiscsi_dev_probe-"
4629 "Failed in beiscsi_init_port\n");
4633 for (i = 0; i < MAX_MCC_CMD ; i++) {
4634 init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]);
4635 phba->ctrl.mcc_tag[i] = i + 1;
4636 phba->ctrl.mcc_numtag[i + 1] = 0;
4637 phba->ctrl.mcc_tag_available++;
4640 phba->ctrl.mcc_alloc_index = phba->ctrl.mcc_free_index = 0;
4642 snprintf(phba->wq_name, sizeof(phba->wq_name), "beiscsi_%02x_wq",
4643 phba->shost->host_no);
4644 phba->wq = alloc_workqueue(phba->wq_name, WQ_MEM_RECLAIM, 1);
4646 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4647 "BM_%d : beiscsi_dev_probe-"
4648 "Failed to allocate work queue\n");
4653 phwi_ctrlr = phba->phwi_ctrlr;
4654 phwi_context = phwi_ctrlr->phwi_ctxt;
4656 if (blk_iopoll_enabled) {
4657 for (i = 0; i < phba->num_cpus; i++) {
4658 pbe_eq = &phwi_context->be_eq[i];
4659 blk_iopoll_init(&pbe_eq->iopoll, be_iopoll_budget,
4661 blk_iopoll_enable(&pbe_eq->iopoll);
4664 i = (phba->msix_enabled) ? i : 0;
4665 /* Work item for MCC handling */
4666 pbe_eq = &phwi_context->be_eq[i];
4667 INIT_WORK(&pbe_eq->work_cqs, beiscsi_process_all_cqs);
4669 if (phba->msix_enabled) {
4670 for (i = 0; i <= phba->num_cpus; i++) {
4671 pbe_eq = &phwi_context->be_eq[i];
4672 INIT_WORK(&pbe_eq->work_cqs,
4673 beiscsi_process_all_cqs);
4676 pbe_eq = &phwi_context->be_eq[0];
4677 INIT_WORK(&pbe_eq->work_cqs,
4678 beiscsi_process_all_cqs);
4682 ret = beiscsi_init_irqs(phba);
4684 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4685 "BM_%d : beiscsi_dev_probe-"
4686 "Failed to beiscsi_init_irqs\n");
4689 hwi_enable_intr(phba);
4691 if (beiscsi_setup_boot_info(phba))
4693 * log error but continue, because we may not be using
4696 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4697 "BM_%d : Could not set up "
4698 "iSCSI boot info.\n");
4700 beiscsi_create_def_ifaces(phba);
4701 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4702 "\n\n\n BM_%d : SUCCESS - DRIVER LOADED\n\n\n");
4706 destroy_workqueue(phba->wq);
4707 if (blk_iopoll_enabled)
4708 for (i = 0; i < phba->num_cpus; i++) {
4709 pbe_eq = &phwi_context->be_eq[i];
4710 blk_iopoll_disable(&pbe_eq->iopoll);
4713 beiscsi_clean_port(phba);
4714 beiscsi_free_mem(phba);
4716 pci_free_consistent(phba->pcidev,
4717 phba->ctrl.mbox_mem_alloced.size,
4718 phba->ctrl.mbox_mem_alloced.va,
4719 phba->ctrl.mbox_mem_alloced.dma);
4720 beiscsi_unmap_pci_function(phba);
4722 if (phba->msix_enabled)
4723 pci_disable_msix(phba->pcidev);
4724 iscsi_host_remove(phba->shost);
4725 pci_dev_put(phba->pcidev);
4726 iscsi_host_free(phba->shost);
4728 pci_disable_device(pcidev);
4732 struct iscsi_transport beiscsi_iscsi_transport = {
4733 .owner = THIS_MODULE,
4735 .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_TEXT_NEGO |
4736 CAP_MULTI_R2T | CAP_DATADGST | CAP_DATA_PATH_OFFLOAD,
4737 .create_session = beiscsi_session_create,
4738 .destroy_session = beiscsi_session_destroy,
4739 .create_conn = beiscsi_conn_create,
4740 .bind_conn = beiscsi_conn_bind,
4741 .destroy_conn = iscsi_conn_teardown,
4742 .attr_is_visible = be2iscsi_attr_is_visible,
4743 .set_iface_param = be2iscsi_iface_set_param,
4744 .get_iface_param = be2iscsi_iface_get_param,
4745 .set_param = beiscsi_set_param,
4746 .get_conn_param = iscsi_conn_get_param,
4747 .get_session_param = iscsi_session_get_param,
4748 .get_host_param = beiscsi_get_host_param,
4749 .start_conn = beiscsi_conn_start,
4750 .stop_conn = iscsi_conn_stop,
4751 .send_pdu = iscsi_conn_send_pdu,
4752 .xmit_task = beiscsi_task_xmit,
4753 .cleanup_task = beiscsi_cleanup_task,
4754 .alloc_pdu = beiscsi_alloc_pdu,
4755 .parse_pdu_itt = beiscsi_parse_pdu,
4756 .get_stats = beiscsi_conn_get_stats,
4757 .get_ep_param = beiscsi_ep_get_param,
4758 .ep_connect = beiscsi_ep_connect,
4759 .ep_poll = beiscsi_ep_poll,
4760 .ep_disconnect = beiscsi_ep_disconnect,
4761 .session_recovery_timedout = iscsi_session_recovery_timedout,
4762 .bsg_request = beiscsi_bsg_request,
4765 static struct pci_driver beiscsi_pci_driver = {
4767 .probe = beiscsi_dev_probe,
4768 .remove = beiscsi_remove,
4769 .shutdown = beiscsi_shutdown,
4770 .id_table = beiscsi_pci_id_table
4774 static int __init beiscsi_module_init(void)
4778 beiscsi_scsi_transport =
4779 iscsi_register_transport(&beiscsi_iscsi_transport);
4780 if (!beiscsi_scsi_transport) {
4782 "beiscsi_module_init - Unable to register beiscsi transport.\n");
4785 printk(KERN_INFO "In beiscsi_module_init, tt=%p\n",
4786 &beiscsi_iscsi_transport);
4788 ret = pci_register_driver(&beiscsi_pci_driver);
4791 "beiscsi_module_init - Unable to register beiscsi pci driver.\n");
4792 goto unregister_iscsi_transport;
4796 unregister_iscsi_transport:
4797 iscsi_unregister_transport(&beiscsi_iscsi_transport);
4801 static void __exit beiscsi_module_exit(void)
4803 pci_unregister_driver(&beiscsi_pci_driver);
4804 iscsi_unregister_transport(&beiscsi_iscsi_transport);
4807 module_init(beiscsi_module_init);
4808 module_exit(beiscsi_module_exit);