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;
50 static unsigned int gcrashmode = 0;
51 static unsigned int num_hba = 0;
53 MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
54 MODULE_DESCRIPTION(DRV_DESC " " BUILD_STR);
55 MODULE_VERSION(BUILD_STR);
56 MODULE_AUTHOR("Emulex Corporation");
57 MODULE_LICENSE("GPL");
58 module_param(be_iopoll_budget, int, 0);
59 module_param(enable_msix, int, 0);
60 module_param(be_max_phys_size, uint, S_IRUGO);
61 MODULE_PARM_DESC(be_max_phys_size,
62 "Maximum Size (In Kilobytes) of physically contiguous "
63 "memory that can be allocated. Range is 16 - 128");
65 #define beiscsi_disp_param(_name)\
67 beiscsi_##_name##_disp(struct device *dev,\
68 struct device_attribute *attrib, char *buf) \
70 struct Scsi_Host *shost = class_to_shost(dev);\
71 struct beiscsi_hba *phba = iscsi_host_priv(shost); \
72 uint32_t param_val = 0; \
73 param_val = phba->attr_##_name;\
74 return snprintf(buf, PAGE_SIZE, "%d\n",\
78 #define beiscsi_change_param(_name, _minval, _maxval, _defaval)\
80 beiscsi_##_name##_change(struct beiscsi_hba *phba, uint32_t val)\
82 if (val >= _minval && val <= _maxval) {\
83 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,\
84 "BA_%d : beiscsi_"#_name" updated "\
85 "from 0x%x ==> 0x%x\n",\
86 phba->attr_##_name, val); \
87 phba->attr_##_name = val;\
90 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, \
91 "BA_%d beiscsi_"#_name" attribute "\
92 "cannot be updated to 0x%x, "\
93 "range allowed is ["#_minval" - "#_maxval"]\n", val);\
97 #define beiscsi_store_param(_name) \
99 beiscsi_##_name##_store(struct device *dev,\
100 struct device_attribute *attr, const char *buf,\
103 struct Scsi_Host *shost = class_to_shost(dev);\
104 struct beiscsi_hba *phba = iscsi_host_priv(shost);\
105 uint32_t param_val = 0;\
106 if (!isdigit(buf[0]))\
108 if (sscanf(buf, "%i", ¶m_val) != 1)\
110 if (beiscsi_##_name##_change(phba, param_val) == 0) \
116 #define beiscsi_init_param(_name, _minval, _maxval, _defval) \
118 beiscsi_##_name##_init(struct beiscsi_hba *phba, uint32_t val) \
120 if (val >= _minval && val <= _maxval) {\
121 phba->attr_##_name = val;\
124 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,\
125 "BA_%d beiscsi_"#_name" attribute " \
126 "cannot be updated to 0x%x, "\
127 "range allowed is ["#_minval" - "#_maxval"]\n", val);\
128 phba->attr_##_name = _defval;\
132 #define BEISCSI_RW_ATTR(_name, _minval, _maxval, _defval, _descp) \
133 static uint beiscsi_##_name = _defval;\
134 module_param(beiscsi_##_name, uint, S_IRUGO);\
135 MODULE_PARM_DESC(beiscsi_##_name, _descp);\
136 beiscsi_disp_param(_name)\
137 beiscsi_change_param(_name, _minval, _maxval, _defval)\
138 beiscsi_store_param(_name)\
139 beiscsi_init_param(_name, _minval, _maxval, _defval)\
140 DEVICE_ATTR(beiscsi_##_name, S_IRUGO | S_IWUSR,\
141 beiscsi_##_name##_disp, beiscsi_##_name##_store)
144 * When new log level added update the
145 * the MAX allowed value for log_enable
147 BEISCSI_RW_ATTR(log_enable, 0x00,
148 0xFF, 0x00, "Enable logging Bit Mask\n"
149 "\t\t\t\tInitialization Events : 0x01\n"
150 "\t\t\t\tMailbox Events : 0x02\n"
151 "\t\t\t\tMiscellaneous Events : 0x04\n"
152 "\t\t\t\tError Handling : 0x08\n"
153 "\t\t\t\tIO Path Events : 0x10\n"
154 "\t\t\t\tConfiguration Path : 0x20\n");
156 DEVICE_ATTR(beiscsi_drvr_ver, S_IRUGO, beiscsi_drvr_ver_disp, NULL);
157 struct device_attribute *beiscsi_attrs[] = {
158 &dev_attr_beiscsi_log_enable,
159 &dev_attr_beiscsi_drvr_ver,
163 static char const *cqe_desc[] = {
166 "SOL_CMD_KILLED_DATA_DIGEST_ERR",
167 "CXN_KILLED_PDU_SIZE_EXCEEDS_DSL",
168 "CXN_KILLED_BURST_LEN_MISMATCH",
169 "CXN_KILLED_AHS_RCVD",
170 "CXN_KILLED_HDR_DIGEST_ERR",
171 "CXN_KILLED_UNKNOWN_HDR",
172 "CXN_KILLED_STALE_ITT_TTT_RCVD",
173 "CXN_KILLED_INVALID_ITT_TTT_RCVD",
174 "CXN_KILLED_RST_RCVD",
175 "CXN_KILLED_TIMED_OUT",
176 "CXN_KILLED_RST_SENT",
177 "CXN_KILLED_FIN_RCVD",
178 "CXN_KILLED_BAD_UNSOL_PDU_RCVD",
179 "CXN_KILLED_BAD_WRB_INDEX_ERROR",
180 "CXN_KILLED_OVER_RUN_RESIDUAL",
181 "CXN_KILLED_UNDER_RUN_RESIDUAL",
182 "CMD_KILLED_INVALID_STATSN_RCVD",
183 "CMD_KILLED_INVALID_R2T_RCVD",
184 "CMD_CXN_KILLED_LUN_INVALID",
185 "CMD_CXN_KILLED_ICD_INVALID",
186 "CMD_CXN_KILLED_ITT_INVALID",
187 "CMD_CXN_KILLED_SEQ_OUTOFORDER",
188 "CMD_CXN_KILLED_INVALID_DATASN_RCVD",
189 "CXN_INVALIDATE_NOTIFY",
190 "CXN_INVALIDATE_INDEX_NOTIFY",
191 "CMD_INVALIDATED_NOTIFY",
194 "UNSOL_DATA_DIGEST_ERROR_NOTIFY",
196 "CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN",
197 "SOL_CMD_KILLED_DIF_ERR",
198 "CXN_KILLED_SYN_RCVD",
199 "CXN_KILLED_IMM_DATA_RCVD"
202 static int beiscsi_slave_configure(struct scsi_device *sdev)
204 blk_queue_max_segment_size(sdev->request_queue, 65536);
208 static int beiscsi_eh_abort(struct scsi_cmnd *sc)
210 struct iscsi_cls_session *cls_session;
211 struct iscsi_task *aborted_task = (struct iscsi_task *)sc->SCp.ptr;
212 struct beiscsi_io_task *aborted_io_task;
213 struct iscsi_conn *conn;
214 struct beiscsi_conn *beiscsi_conn;
215 struct beiscsi_hba *phba;
216 struct iscsi_session *session;
217 struct invalidate_command_table *inv_tbl;
218 struct be_dma_mem nonemb_cmd;
219 unsigned int cid, tag, num_invalidate;
221 cls_session = starget_to_session(scsi_target(sc->device));
222 session = cls_session->dd_data;
224 spin_lock_bh(&session->lock);
225 if (!aborted_task || !aborted_task->sc) {
227 spin_unlock_bh(&session->lock);
231 aborted_io_task = aborted_task->dd_data;
232 if (!aborted_io_task->scsi_cmnd) {
233 /* raced or invalid command */
234 spin_unlock_bh(&session->lock);
237 spin_unlock_bh(&session->lock);
238 conn = aborted_task->conn;
239 beiscsi_conn = conn->dd_data;
240 phba = beiscsi_conn->phba;
242 /* invalidate iocb */
243 cid = beiscsi_conn->beiscsi_conn_cid;
244 inv_tbl = phba->inv_tbl;
245 memset(inv_tbl, 0x0, sizeof(*inv_tbl));
247 inv_tbl->icd = aborted_io_task->psgl_handle->sgl_index;
249 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
250 sizeof(struct invalidate_commands_params_in),
252 if (nonemb_cmd.va == NULL) {
253 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
254 "BM_%d : Failed to allocate memory for"
255 "mgmt_invalidate_icds\n");
258 nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
260 tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
263 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH,
264 "BM_%d : mgmt_invalidate_icds could not be"
266 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
267 nonemb_cmd.va, nonemb_cmd.dma);
271 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
272 phba->ctrl.mcc_numtag[tag]);
273 free_mcc_tag(&phba->ctrl, tag);
275 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
276 nonemb_cmd.va, nonemb_cmd.dma);
277 return iscsi_eh_abort(sc);
280 static int beiscsi_eh_device_reset(struct scsi_cmnd *sc)
282 struct iscsi_task *abrt_task;
283 struct beiscsi_io_task *abrt_io_task;
284 struct iscsi_conn *conn;
285 struct beiscsi_conn *beiscsi_conn;
286 struct beiscsi_hba *phba;
287 struct iscsi_session *session;
288 struct iscsi_cls_session *cls_session;
289 struct invalidate_command_table *inv_tbl;
290 struct be_dma_mem nonemb_cmd;
291 unsigned int cid, tag, i, num_invalidate;
293 /* invalidate iocbs */
294 cls_session = starget_to_session(scsi_target(sc->device));
295 session = cls_session->dd_data;
296 spin_lock_bh(&session->lock);
297 if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN) {
298 spin_unlock_bh(&session->lock);
301 conn = session->leadconn;
302 beiscsi_conn = conn->dd_data;
303 phba = beiscsi_conn->phba;
304 cid = beiscsi_conn->beiscsi_conn_cid;
305 inv_tbl = phba->inv_tbl;
306 memset(inv_tbl, 0x0, sizeof(*inv_tbl) * BE2_CMDS_PER_CXN);
308 for (i = 0; i < conn->session->cmds_max; i++) {
309 abrt_task = conn->session->cmds[i];
310 abrt_io_task = abrt_task->dd_data;
311 if (!abrt_task->sc || abrt_task->state == ISCSI_TASK_FREE)
314 if (abrt_task->sc->device->lun != abrt_task->sc->device->lun)
318 inv_tbl->icd = abrt_io_task->psgl_handle->sgl_index;
322 spin_unlock_bh(&session->lock);
323 inv_tbl = phba->inv_tbl;
325 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
326 sizeof(struct invalidate_commands_params_in),
328 if (nonemb_cmd.va == NULL) {
329 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
330 "BM_%d : Failed to allocate memory for"
331 "mgmt_invalidate_icds\n");
334 nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
335 memset(nonemb_cmd.va, 0, nonemb_cmd.size);
336 tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
339 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH,
340 "BM_%d : mgmt_invalidate_icds could not be"
342 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
343 nonemb_cmd.va, nonemb_cmd.dma);
346 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
347 phba->ctrl.mcc_numtag[tag]);
348 free_mcc_tag(&phba->ctrl, tag);
350 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
351 nonemb_cmd.va, nonemb_cmd.dma);
352 return iscsi_eh_device_reset(sc);
355 static ssize_t beiscsi_show_boot_tgt_info(void *data, int type, char *buf)
357 struct beiscsi_hba *phba = data;
358 struct mgmt_session_info *boot_sess = &phba->boot_sess;
359 struct mgmt_conn_info *boot_conn = &boot_sess->conn_list[0];
364 case ISCSI_BOOT_TGT_NAME:
365 rc = sprintf(buf, "%.*s\n",
366 (int)strlen(boot_sess->target_name),
367 (char *)&boot_sess->target_name);
369 case ISCSI_BOOT_TGT_IP_ADDR:
370 if (boot_conn->dest_ipaddr.ip_type == 0x1)
371 rc = sprintf(buf, "%pI4\n",
372 (char *)&boot_conn->dest_ipaddr.addr);
374 rc = sprintf(str, "%pI6\n",
375 (char *)&boot_conn->dest_ipaddr.addr);
377 case ISCSI_BOOT_TGT_PORT:
378 rc = sprintf(str, "%d\n", boot_conn->dest_port);
381 case ISCSI_BOOT_TGT_CHAP_NAME:
382 rc = sprintf(str, "%.*s\n",
383 boot_conn->negotiated_login_options.auth_data.chap.
384 target_chap_name_length,
385 (char *)&boot_conn->negotiated_login_options.
386 auth_data.chap.target_chap_name);
388 case ISCSI_BOOT_TGT_CHAP_SECRET:
389 rc = sprintf(str, "%.*s\n",
390 boot_conn->negotiated_login_options.auth_data.chap.
391 target_secret_length,
392 (char *)&boot_conn->negotiated_login_options.
393 auth_data.chap.target_secret);
395 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
396 rc = sprintf(str, "%.*s\n",
397 boot_conn->negotiated_login_options.auth_data.chap.
398 intr_chap_name_length,
399 (char *)&boot_conn->negotiated_login_options.
400 auth_data.chap.intr_chap_name);
402 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
403 rc = sprintf(str, "%.*s\n",
404 boot_conn->negotiated_login_options.auth_data.chap.
406 (char *)&boot_conn->negotiated_login_options.
407 auth_data.chap.intr_secret);
409 case ISCSI_BOOT_TGT_FLAGS:
410 rc = sprintf(str, "2\n");
412 case ISCSI_BOOT_TGT_NIC_ASSOC:
413 rc = sprintf(str, "0\n");
422 static ssize_t beiscsi_show_boot_ini_info(void *data, int type, char *buf)
424 struct beiscsi_hba *phba = data;
429 case ISCSI_BOOT_INI_INITIATOR_NAME:
430 rc = sprintf(str, "%s\n", phba->boot_sess.initiator_iscsiname);
439 static ssize_t beiscsi_show_boot_eth_info(void *data, int type, char *buf)
441 struct beiscsi_hba *phba = data;
446 case ISCSI_BOOT_ETH_FLAGS:
447 rc = sprintf(str, "2\n");
449 case ISCSI_BOOT_ETH_INDEX:
450 rc = sprintf(str, "0\n");
452 case ISCSI_BOOT_ETH_MAC:
453 rc = beiscsi_get_macaddr(str, phba);
463 static umode_t beiscsi_tgt_get_attr_visibility(void *data, int type)
468 case ISCSI_BOOT_TGT_NAME:
469 case ISCSI_BOOT_TGT_IP_ADDR:
470 case ISCSI_BOOT_TGT_PORT:
471 case ISCSI_BOOT_TGT_CHAP_NAME:
472 case ISCSI_BOOT_TGT_CHAP_SECRET:
473 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
474 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
475 case ISCSI_BOOT_TGT_NIC_ASSOC:
476 case ISCSI_BOOT_TGT_FLAGS:
486 static umode_t beiscsi_ini_get_attr_visibility(void *data, int type)
491 case ISCSI_BOOT_INI_INITIATOR_NAME:
502 static umode_t beiscsi_eth_get_attr_visibility(void *data, int type)
507 case ISCSI_BOOT_ETH_FLAGS:
508 case ISCSI_BOOT_ETH_MAC:
509 case ISCSI_BOOT_ETH_INDEX:
519 /*------------------- PCI Driver operations and data ----------------- */
520 static DEFINE_PCI_DEVICE_TABLE(beiscsi_pci_id_table) = {
521 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) },
522 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) },
523 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) },
524 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) },
525 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID3) },
528 MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
531 static struct scsi_host_template beiscsi_sht = {
532 .module = THIS_MODULE,
533 .name = "Emulex 10Gbe open-iscsi Initiator Driver",
534 .proc_name = DRV_NAME,
535 .queuecommand = iscsi_queuecommand,
536 .change_queue_depth = iscsi_change_queue_depth,
537 .slave_configure = beiscsi_slave_configure,
538 .target_alloc = iscsi_target_alloc,
539 .eh_abort_handler = beiscsi_eh_abort,
540 .eh_device_reset_handler = beiscsi_eh_device_reset,
541 .eh_target_reset_handler = iscsi_eh_session_reset,
542 .shost_attrs = beiscsi_attrs,
543 .sg_tablesize = BEISCSI_SGLIST_ELEMENTS,
544 .can_queue = BE2_IO_DEPTH,
546 .max_sectors = BEISCSI_MAX_SECTORS,
547 .cmd_per_lun = BEISCSI_CMD_PER_LUN,
548 .use_clustering = ENABLE_CLUSTERING,
549 .vendor_id = SCSI_NL_VID_TYPE_PCI | BE_VENDOR_ID,
553 static struct scsi_transport_template *beiscsi_scsi_transport;
555 static struct beiscsi_hba *beiscsi_hba_alloc(struct pci_dev *pcidev)
557 struct beiscsi_hba *phba;
558 struct Scsi_Host *shost;
560 shost = iscsi_host_alloc(&beiscsi_sht, sizeof(*phba), 0);
562 dev_err(&pcidev->dev,
563 "beiscsi_hba_alloc - iscsi_host_alloc failed\n");
566 shost->dma_boundary = pcidev->dma_mask;
567 shost->max_id = BE2_MAX_SESSIONS;
568 shost->max_channel = 0;
569 shost->max_cmd_len = BEISCSI_MAX_CMD_LEN;
570 shost->max_lun = BEISCSI_NUM_MAX_LUN;
571 shost->transportt = beiscsi_scsi_transport;
572 phba = iscsi_host_priv(shost);
573 memset(phba, 0, sizeof(*phba));
575 phba->pcidev = pci_dev_get(pcidev);
576 pci_set_drvdata(pcidev, phba);
577 phba->interface_handle = 0xFFFFFFFF;
579 if (iscsi_host_add(shost, &phba->pcidev->dev))
585 pci_dev_put(phba->pcidev);
586 iscsi_host_free(phba->shost);
590 static void beiscsi_unmap_pci_function(struct beiscsi_hba *phba)
593 iounmap(phba->csr_va);
597 iounmap(phba->db_va);
601 iounmap(phba->pci_va);
606 static int beiscsi_map_pci_bars(struct beiscsi_hba *phba,
607 struct pci_dev *pcidev)
612 addr = ioremap_nocache(pci_resource_start(pcidev, 2),
613 pci_resource_len(pcidev, 2));
616 phba->ctrl.csr = addr;
618 phba->csr_pa.u.a64.address = pci_resource_start(pcidev, 2);
620 addr = ioremap_nocache(pci_resource_start(pcidev, 4), 128 * 1024);
623 phba->ctrl.db = addr;
625 phba->db_pa.u.a64.address = pci_resource_start(pcidev, 4);
627 if (phba->generation == BE_GEN2)
632 addr = ioremap_nocache(pci_resource_start(pcidev, pcicfg_reg),
633 pci_resource_len(pcidev, pcicfg_reg));
637 phba->ctrl.pcicfg = addr;
639 phba->pci_pa.u.a64.address = pci_resource_start(pcidev, pcicfg_reg);
643 beiscsi_unmap_pci_function(phba);
647 static int beiscsi_enable_pci(struct pci_dev *pcidev)
651 ret = pci_enable_device(pcidev);
653 dev_err(&pcidev->dev,
654 "beiscsi_enable_pci - enable device failed\n");
658 pci_set_master(pcidev);
659 if (pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64))) {
660 ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(32));
662 dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n");
663 pci_disable_device(pcidev);
670 static int be_ctrl_init(struct beiscsi_hba *phba, struct pci_dev *pdev)
672 struct be_ctrl_info *ctrl = &phba->ctrl;
673 struct be_dma_mem *mbox_mem_alloc = &ctrl->mbox_mem_alloced;
674 struct be_dma_mem *mbox_mem_align = &ctrl->mbox_mem;
678 status = beiscsi_map_pci_bars(phba, pdev);
681 mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16;
682 mbox_mem_alloc->va = pci_alloc_consistent(pdev,
683 mbox_mem_alloc->size,
684 &mbox_mem_alloc->dma);
685 if (!mbox_mem_alloc->va) {
686 beiscsi_unmap_pci_function(phba);
690 mbox_mem_align->size = sizeof(struct be_mcc_mailbox);
691 mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16);
692 mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16);
693 memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox));
694 spin_lock_init(&ctrl->mbox_lock);
695 spin_lock_init(&phba->ctrl.mcc_lock);
696 spin_lock_init(&phba->ctrl.mcc_cq_lock);
701 static void beiscsi_get_params(struct beiscsi_hba *phba)
703 phba->params.ios_per_ctrl = (phba->fw_config.iscsi_icd_count
704 - (phba->fw_config.iscsi_cid_count
707 phba->params.cxns_per_ctrl = phba->fw_config.iscsi_cid_count;
708 phba->params.asyncpdus_per_ctrl = phba->fw_config.iscsi_cid_count * 2;
709 phba->params.icds_per_ctrl = phba->fw_config.iscsi_icd_count;
710 phba->params.num_sge_per_io = BE2_SGE;
711 phba->params.defpdu_hdr_sz = BE2_DEFPDU_HDR_SZ;
712 phba->params.defpdu_data_sz = BE2_DEFPDU_DATA_SZ;
713 phba->params.eq_timer = 64;
714 phba->params.num_eq_entries =
715 (((BE2_CMDS_PER_CXN * 2 + phba->fw_config.iscsi_cid_count * 2
716 + BE2_TMFS) / 512) + 1) * 512;
717 phba->params.num_eq_entries = (phba->params.num_eq_entries < 1024)
718 ? 1024 : phba->params.num_eq_entries;
719 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
720 "BM_%d : phba->params.num_eq_entries=%d\n",
721 phba->params.num_eq_entries);
722 phba->params.num_cq_entries =
723 (((BE2_CMDS_PER_CXN * 2 + phba->fw_config.iscsi_cid_count * 2
724 + BE2_TMFS) / 512) + 1) * 512;
725 phba->params.wrbs_per_cxn = 256;
728 static void hwi_ring_eq_db(struct beiscsi_hba *phba,
729 unsigned int id, unsigned int clr_interrupt,
730 unsigned int num_processed,
731 unsigned char rearm, unsigned char event)
734 val |= id & DB_EQ_RING_ID_MASK;
736 val |= 1 << DB_EQ_REARM_SHIFT;
738 val |= 1 << DB_EQ_CLR_SHIFT;
740 val |= 1 << DB_EQ_EVNT_SHIFT;
741 val |= num_processed << DB_EQ_NUM_POPPED_SHIFT;
742 iowrite32(val, phba->db_va + DB_EQ_OFFSET);
746 * be_isr_mcc - The isr routine of the driver.
748 * @dev_id: Pointer to host adapter structure
750 static irqreturn_t be_isr_mcc(int irq, void *dev_id)
752 struct beiscsi_hba *phba;
753 struct be_eq_entry *eqe = NULL;
754 struct be_queue_info *eq;
755 struct be_queue_info *mcc;
756 unsigned int num_eq_processed;
757 struct be_eq_obj *pbe_eq;
763 mcc = &phba->ctrl.mcc_obj.cq;
764 eqe = queue_tail_node(eq);
766 num_eq_processed = 0;
768 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
770 if (((eqe->dw[offsetof(struct amap_eq_entry,
772 EQE_RESID_MASK) >> 16) == mcc->id) {
773 spin_lock_irqsave(&phba->isr_lock, flags);
774 phba->todo_mcc_cq = 1;
775 spin_unlock_irqrestore(&phba->isr_lock, flags);
777 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
779 eqe = queue_tail_node(eq);
782 if (phba->todo_mcc_cq)
783 queue_work(phba->wq, &phba->work_cqs);
784 if (num_eq_processed)
785 hwi_ring_eq_db(phba, eq->id, 1, num_eq_processed, 1, 1);
791 * be_isr_msix - The isr routine of the driver.
793 * @dev_id: Pointer to host adapter structure
795 static irqreturn_t be_isr_msix(int irq, void *dev_id)
797 struct beiscsi_hba *phba;
798 struct be_eq_entry *eqe = NULL;
799 struct be_queue_info *eq;
800 struct be_queue_info *cq;
801 unsigned int num_eq_processed;
802 struct be_eq_obj *pbe_eq;
808 eqe = queue_tail_node(eq);
811 num_eq_processed = 0;
812 if (blk_iopoll_enabled) {
813 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
815 if (!blk_iopoll_sched_prep(&pbe_eq->iopoll))
816 blk_iopoll_sched(&pbe_eq->iopoll);
818 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
820 eqe = queue_tail_node(eq);
823 if (num_eq_processed)
824 hwi_ring_eq_db(phba, eq->id, 1, num_eq_processed, 0, 1);
828 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
830 spin_lock_irqsave(&phba->isr_lock, flags);
832 spin_unlock_irqrestore(&phba->isr_lock, flags);
833 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
835 eqe = queue_tail_node(eq);
839 queue_work(phba->wq, &phba->work_cqs);
841 if (num_eq_processed)
842 hwi_ring_eq_db(phba, eq->id, 1, num_eq_processed, 1, 1);
849 * be_isr - The isr routine of the driver.
851 * @dev_id: Pointer to host adapter structure
853 static irqreturn_t be_isr(int irq, void *dev_id)
855 struct beiscsi_hba *phba;
856 struct hwi_controller *phwi_ctrlr;
857 struct hwi_context_memory *phwi_context;
858 struct be_eq_entry *eqe = NULL;
859 struct be_queue_info *eq;
860 struct be_queue_info *cq;
861 struct be_queue_info *mcc;
862 unsigned long flags, index;
863 unsigned int num_mcceq_processed, num_ioeq_processed;
864 struct be_ctrl_info *ctrl;
865 struct be_eq_obj *pbe_eq;
870 isr = ioread32(ctrl->csr + CEV_ISR0_OFFSET +
871 (PCI_FUNC(ctrl->pdev->devfn) * CEV_ISR_SIZE));
875 phwi_ctrlr = phba->phwi_ctrlr;
876 phwi_context = phwi_ctrlr->phwi_ctxt;
877 pbe_eq = &phwi_context->be_eq[0];
879 eq = &phwi_context->be_eq[0].q;
880 mcc = &phba->ctrl.mcc_obj.cq;
882 eqe = queue_tail_node(eq);
884 num_ioeq_processed = 0;
885 num_mcceq_processed = 0;
886 if (blk_iopoll_enabled) {
887 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
889 if (((eqe->dw[offsetof(struct amap_eq_entry,
891 EQE_RESID_MASK) >> 16) == mcc->id) {
892 spin_lock_irqsave(&phba->isr_lock, flags);
893 phba->todo_mcc_cq = 1;
894 spin_unlock_irqrestore(&phba->isr_lock, flags);
895 num_mcceq_processed++;
897 if (!blk_iopoll_sched_prep(&pbe_eq->iopoll))
898 blk_iopoll_sched(&pbe_eq->iopoll);
899 num_ioeq_processed++;
901 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
903 eqe = queue_tail_node(eq);
905 if (num_ioeq_processed || num_mcceq_processed) {
906 if (phba->todo_mcc_cq)
907 queue_work(phba->wq, &phba->work_cqs);
909 if ((num_mcceq_processed) && (!num_ioeq_processed))
910 hwi_ring_eq_db(phba, eq->id, 0,
911 (num_ioeq_processed +
912 num_mcceq_processed) , 1, 1);
914 hwi_ring_eq_db(phba, eq->id, 0,
915 (num_ioeq_processed +
916 num_mcceq_processed), 0, 1);
922 cq = &phwi_context->be_cq[0];
923 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
926 if (((eqe->dw[offsetof(struct amap_eq_entry,
928 EQE_RESID_MASK) >> 16) != cq->id) {
929 spin_lock_irqsave(&phba->isr_lock, flags);
930 phba->todo_mcc_cq = 1;
931 spin_unlock_irqrestore(&phba->isr_lock, flags);
933 spin_lock_irqsave(&phba->isr_lock, flags);
935 spin_unlock_irqrestore(&phba->isr_lock, flags);
937 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
939 eqe = queue_tail_node(eq);
940 num_ioeq_processed++;
942 if (phba->todo_cq || phba->todo_mcc_cq)
943 queue_work(phba->wq, &phba->work_cqs);
945 if (num_ioeq_processed) {
946 hwi_ring_eq_db(phba, eq->id, 0,
947 num_ioeq_processed, 1, 1);
954 static int beiscsi_init_irqs(struct beiscsi_hba *phba)
956 struct pci_dev *pcidev = phba->pcidev;
957 struct hwi_controller *phwi_ctrlr;
958 struct hwi_context_memory *phwi_context;
959 int ret, msix_vec, i, j;
961 phwi_ctrlr = phba->phwi_ctrlr;
962 phwi_context = phwi_ctrlr->phwi_ctxt;
964 if (phba->msix_enabled) {
965 for (i = 0; i < phba->num_cpus; i++) {
966 phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME,
968 if (!phba->msi_name[i]) {
973 sprintf(phba->msi_name[i], "beiscsi_%02x_%02x",
974 phba->shost->host_no, i);
975 msix_vec = phba->msix_entries[i].vector;
976 ret = request_irq(msix_vec, be_isr_msix, 0,
978 &phwi_context->be_eq[i]);
980 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
981 "BM_%d : beiscsi_init_irqs-Failed to"
982 "register msix for i = %d\n",
984 kfree(phba->msi_name[i]);
988 phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME, GFP_KERNEL);
989 if (!phba->msi_name[i]) {
993 sprintf(phba->msi_name[i], "beiscsi_mcc_%02x",
994 phba->shost->host_no);
995 msix_vec = phba->msix_entries[i].vector;
996 ret = request_irq(msix_vec, be_isr_mcc, 0, phba->msi_name[i],
997 &phwi_context->be_eq[i]);
999 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT ,
1000 "BM_%d : beiscsi_init_irqs-"
1001 "Failed to register beiscsi_msix_mcc\n");
1002 kfree(phba->msi_name[i]);
1003 goto free_msix_irqs;
1007 ret = request_irq(pcidev->irq, be_isr, IRQF_SHARED,
1010 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
1011 "BM_%d : beiscsi_init_irqs-"
1012 "Failed to register irq\\n");
1018 for (j = i - 1; j >= 0; j--) {
1019 kfree(phba->msi_name[j]);
1020 msix_vec = phba->msix_entries[j].vector;
1021 free_irq(msix_vec, &phwi_context->be_eq[j]);
1026 static void hwi_ring_cq_db(struct beiscsi_hba *phba,
1027 unsigned int id, unsigned int num_processed,
1028 unsigned char rearm, unsigned char event)
1031 val |= id & DB_CQ_RING_ID_MASK;
1033 val |= 1 << DB_CQ_REARM_SHIFT;
1034 val |= num_processed << DB_CQ_NUM_POPPED_SHIFT;
1035 iowrite32(val, phba->db_va + DB_CQ_OFFSET);
1039 beiscsi_process_async_pdu(struct beiscsi_conn *beiscsi_conn,
1040 struct beiscsi_hba *phba,
1042 struct pdu_base *ppdu,
1043 unsigned long pdu_len,
1044 void *pbuffer, unsigned long buf_len)
1046 struct iscsi_conn *conn = beiscsi_conn->conn;
1047 struct iscsi_session *session = conn->session;
1048 struct iscsi_task *task;
1049 struct beiscsi_io_task *io_task;
1050 struct iscsi_hdr *login_hdr;
1052 switch (ppdu->dw[offsetof(struct amap_pdu_base, opcode) / 32] &
1053 PDUBASE_OPCODE_MASK) {
1054 case ISCSI_OP_NOOP_IN:
1058 case ISCSI_OP_ASYNC_EVENT:
1060 case ISCSI_OP_REJECT:
1062 WARN_ON(!(buf_len == 48));
1063 beiscsi_log(phba, KERN_ERR,
1064 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1065 "BM_%d : In ISCSI_OP_REJECT\n");
1067 case ISCSI_OP_LOGIN_RSP:
1068 case ISCSI_OP_TEXT_RSP:
1069 task = conn->login_task;
1070 io_task = task->dd_data;
1071 login_hdr = (struct iscsi_hdr *)ppdu;
1072 login_hdr->itt = io_task->libiscsi_itt;
1075 beiscsi_log(phba, KERN_WARNING,
1076 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1077 "BM_%d : Unrecognized opcode 0x%x in async msg\n",
1079 dw[offsetof(struct amap_pdu_base, opcode) / 32]
1080 & PDUBASE_OPCODE_MASK));
1084 spin_lock_bh(&session->lock);
1085 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)ppdu, pbuffer, buf_len);
1086 spin_unlock_bh(&session->lock);
1090 static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba)
1092 struct sgl_handle *psgl_handle;
1094 if (phba->io_sgl_hndl_avbl) {
1095 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
1096 "BM_%d : In alloc_io_sgl_handle,"
1097 " io_sgl_alloc_index=%d\n",
1098 phba->io_sgl_alloc_index);
1100 psgl_handle = phba->io_sgl_hndl_base[phba->
1101 io_sgl_alloc_index];
1102 phba->io_sgl_hndl_base[phba->io_sgl_alloc_index] = NULL;
1103 phba->io_sgl_hndl_avbl--;
1104 if (phba->io_sgl_alloc_index == (phba->params.
1106 phba->io_sgl_alloc_index = 0;
1108 phba->io_sgl_alloc_index++;
1115 free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
1117 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
1118 "BM_%d : In free_,io_sgl_free_index=%d\n",
1119 phba->io_sgl_free_index);
1121 if (phba->io_sgl_hndl_base[phba->io_sgl_free_index]) {
1123 * this can happen if clean_task is called on a task that
1124 * failed in xmit_task or alloc_pdu.
1126 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
1127 "BM_%d : Double Free in IO SGL io_sgl_free_index=%d,"
1128 "value there=%p\n", phba->io_sgl_free_index,
1129 phba->io_sgl_hndl_base
1130 [phba->io_sgl_free_index]);
1133 phba->io_sgl_hndl_base[phba->io_sgl_free_index] = psgl_handle;
1134 phba->io_sgl_hndl_avbl++;
1135 if (phba->io_sgl_free_index == (phba->params.ios_per_ctrl - 1))
1136 phba->io_sgl_free_index = 0;
1138 phba->io_sgl_free_index++;
1142 * alloc_wrb_handle - To allocate a wrb handle
1143 * @phba: The hba pointer
1144 * @cid: The cid to use for allocation
1146 * This happens under session_lock until submission to chip
1148 struct wrb_handle *alloc_wrb_handle(struct beiscsi_hba *phba, unsigned int cid)
1150 struct hwi_wrb_context *pwrb_context;
1151 struct hwi_controller *phwi_ctrlr;
1152 struct wrb_handle *pwrb_handle, *pwrb_handle_tmp;
1154 phwi_ctrlr = phba->phwi_ctrlr;
1155 pwrb_context = &phwi_ctrlr->wrb_context[cid];
1156 if (pwrb_context->wrb_handles_available >= 2) {
1157 pwrb_handle = pwrb_context->pwrb_handle_base[
1158 pwrb_context->alloc_index];
1159 pwrb_context->wrb_handles_available--;
1160 if (pwrb_context->alloc_index ==
1161 (phba->params.wrbs_per_cxn - 1))
1162 pwrb_context->alloc_index = 0;
1164 pwrb_context->alloc_index++;
1165 pwrb_handle_tmp = pwrb_context->pwrb_handle_base[
1166 pwrb_context->alloc_index];
1167 pwrb_handle->nxt_wrb_index = pwrb_handle_tmp->wrb_index;
1174 * free_wrb_handle - To free the wrb handle back to pool
1175 * @phba: The hba pointer
1176 * @pwrb_context: The context to free from
1177 * @pwrb_handle: The wrb_handle to free
1179 * This happens under session_lock until submission to chip
1182 free_wrb_handle(struct beiscsi_hba *phba, struct hwi_wrb_context *pwrb_context,
1183 struct wrb_handle *pwrb_handle)
1185 pwrb_context->pwrb_handle_base[pwrb_context->free_index] = pwrb_handle;
1186 pwrb_context->wrb_handles_available++;
1187 if (pwrb_context->free_index == (phba->params.wrbs_per_cxn - 1))
1188 pwrb_context->free_index = 0;
1190 pwrb_context->free_index++;
1192 beiscsi_log(phba, KERN_INFO,
1193 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1194 "BM_%d : FREE WRB: pwrb_handle=%p free_index=0x%x"
1195 "wrb_handles_available=%d\n",
1196 pwrb_handle, pwrb_context->free_index,
1197 pwrb_context->wrb_handles_available);
1200 static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba)
1202 struct sgl_handle *psgl_handle;
1204 if (phba->eh_sgl_hndl_avbl) {
1205 psgl_handle = phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index];
1206 phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index] = NULL;
1207 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1208 "BM_%d : mgmt_sgl_alloc_index=%d=0x%x\n",
1209 phba->eh_sgl_alloc_index,
1210 phba->eh_sgl_alloc_index);
1212 phba->eh_sgl_hndl_avbl--;
1213 if (phba->eh_sgl_alloc_index ==
1214 (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl -
1216 phba->eh_sgl_alloc_index = 0;
1218 phba->eh_sgl_alloc_index++;
1225 free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
1228 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1229 "BM_%d : In free_mgmt_sgl_handle,"
1230 "eh_sgl_free_index=%d\n",
1231 phba->eh_sgl_free_index);
1233 if (phba->eh_sgl_hndl_base[phba->eh_sgl_free_index]) {
1235 * this can happen if clean_task is called on a task that
1236 * failed in xmit_task or alloc_pdu.
1238 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1239 "BM_%d : Double Free in eh SGL ,"
1240 "eh_sgl_free_index=%d\n",
1241 phba->eh_sgl_free_index);
1244 phba->eh_sgl_hndl_base[phba->eh_sgl_free_index] = psgl_handle;
1245 phba->eh_sgl_hndl_avbl++;
1246 if (phba->eh_sgl_free_index ==
1247 (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl - 1))
1248 phba->eh_sgl_free_index = 0;
1250 phba->eh_sgl_free_index++;
1254 be_complete_io(struct beiscsi_conn *beiscsi_conn,
1255 struct iscsi_task *task, struct sol_cqe *psol)
1257 struct beiscsi_io_task *io_task = task->dd_data;
1258 struct be_status_bhs *sts_bhs =
1259 (struct be_status_bhs *)io_task->cmd_bhs;
1260 struct iscsi_conn *conn = beiscsi_conn->conn;
1261 unsigned char *sense;
1262 u32 resid = 0, exp_cmdsn, max_cmdsn;
1263 u8 rsp, status, flags;
1266 dw[offsetof(struct amap_sol_cqe, i_exp_cmd_sn) / 32]
1267 & SOL_EXP_CMD_SN_MASK);
1268 max_cmdsn = ((psol->
1269 dw[offsetof(struct amap_sol_cqe, i_exp_cmd_sn) / 32]
1270 & SOL_EXP_CMD_SN_MASK) +
1271 ((psol->dw[offsetof(struct amap_sol_cqe, i_cmd_wnd)
1272 / 32] & SOL_CMD_WND_MASK) >> 24) - 1);
1273 rsp = ((psol->dw[offsetof(struct amap_sol_cqe, i_resp) / 32]
1274 & SOL_RESP_MASK) >> 16);
1275 status = ((psol->dw[offsetof(struct amap_sol_cqe, i_sts) / 32]
1276 & SOL_STS_MASK) >> 8);
1277 flags = ((psol->dw[offsetof(struct amap_sol_cqe, i_flags) / 32]
1278 & SOL_FLAGS_MASK) >> 24) | 0x80;
1280 if (io_task->scsi_cmnd)
1281 scsi_dma_unmap(io_task->scsi_cmnd);
1285 task->sc->result = (DID_OK << 16) | status;
1286 if (rsp != ISCSI_STATUS_CMD_COMPLETED) {
1287 task->sc->result = DID_ERROR << 16;
1291 /* bidi not initially supported */
1292 if (flags & (ISCSI_FLAG_CMD_UNDERFLOW | ISCSI_FLAG_CMD_OVERFLOW)) {
1293 resid = (psol->dw[offsetof(struct amap_sol_cqe, i_res_cnt) /
1294 32] & SOL_RES_CNT_MASK);
1296 if (!status && (flags & ISCSI_FLAG_CMD_OVERFLOW))
1297 task->sc->result = DID_ERROR << 16;
1299 if (flags & ISCSI_FLAG_CMD_UNDERFLOW) {
1300 scsi_set_resid(task->sc, resid);
1301 if (!status && (scsi_bufflen(task->sc) - resid <
1302 task->sc->underflow))
1303 task->sc->result = DID_ERROR << 16;
1307 if (status == SAM_STAT_CHECK_CONDITION) {
1309 unsigned short *slen = (unsigned short *)sts_bhs->sense_info;
1311 sense = sts_bhs->sense_info + sizeof(unsigned short);
1312 sense_len = be16_to_cpu(*slen);
1313 memcpy(task->sc->sense_buffer, sense,
1314 min_t(u16, sense_len, SCSI_SENSE_BUFFERSIZE));
1317 if (io_task->cmd_bhs->iscsi_hdr.flags & ISCSI_FLAG_CMD_READ) {
1318 if (psol->dw[offsetof(struct amap_sol_cqe, i_res_cnt) / 32]
1320 conn->rxdata_octets += (psol->
1321 dw[offsetof(struct amap_sol_cqe, i_res_cnt) / 32]
1322 & SOL_RES_CNT_MASK);
1325 scsi_dma_unmap(io_task->scsi_cmnd);
1326 iscsi_complete_scsi_task(task, exp_cmdsn, max_cmdsn);
1330 be_complete_logout(struct beiscsi_conn *beiscsi_conn,
1331 struct iscsi_task *task, struct sol_cqe *psol)
1333 struct iscsi_logout_rsp *hdr;
1334 struct beiscsi_io_task *io_task = task->dd_data;
1335 struct iscsi_conn *conn = beiscsi_conn->conn;
1337 hdr = (struct iscsi_logout_rsp *)task->hdr;
1338 hdr->opcode = ISCSI_OP_LOGOUT_RSP;
1341 hdr->flags = ((psol->dw[offsetof(struct amap_sol_cqe, i_flags) / 32]
1342 & SOL_FLAGS_MASK) >> 24) | 0x80;
1343 hdr->response = (psol->dw[offsetof(struct amap_sol_cqe, i_resp) /
1344 32] & SOL_RESP_MASK);
1345 hdr->exp_cmdsn = cpu_to_be32(psol->
1346 dw[offsetof(struct amap_sol_cqe, i_exp_cmd_sn) / 32]
1347 & SOL_EXP_CMD_SN_MASK);
1348 hdr->max_cmdsn = be32_to_cpu((psol->
1349 dw[offsetof(struct amap_sol_cqe, i_exp_cmd_sn) / 32]
1350 & SOL_EXP_CMD_SN_MASK) +
1351 ((psol->dw[offsetof(struct amap_sol_cqe, i_cmd_wnd)
1352 / 32] & SOL_CMD_WND_MASK) >> 24) - 1);
1353 hdr->dlength[0] = 0;
1354 hdr->dlength[1] = 0;
1355 hdr->dlength[2] = 0;
1357 hdr->itt = io_task->libiscsi_itt;
1358 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1362 be_complete_tmf(struct beiscsi_conn *beiscsi_conn,
1363 struct iscsi_task *task, struct sol_cqe *psol)
1365 struct iscsi_tm_rsp *hdr;
1366 struct iscsi_conn *conn = beiscsi_conn->conn;
1367 struct beiscsi_io_task *io_task = task->dd_data;
1369 hdr = (struct iscsi_tm_rsp *)task->hdr;
1370 hdr->opcode = ISCSI_OP_SCSI_TMFUNC_RSP;
1371 hdr->flags = ((psol->dw[offsetof(struct amap_sol_cqe, i_flags) / 32]
1372 & SOL_FLAGS_MASK) >> 24) | 0x80;
1373 hdr->response = (psol->dw[offsetof(struct amap_sol_cqe, i_resp) /
1374 32] & SOL_RESP_MASK);
1375 hdr->exp_cmdsn = cpu_to_be32(psol->dw[offsetof(struct amap_sol_cqe,
1376 i_exp_cmd_sn) / 32] & SOL_EXP_CMD_SN_MASK);
1377 hdr->max_cmdsn = be32_to_cpu((psol->dw[offsetof(struct amap_sol_cqe,
1378 i_exp_cmd_sn) / 32] & SOL_EXP_CMD_SN_MASK) +
1379 ((psol->dw[offsetof(struct amap_sol_cqe, i_cmd_wnd)
1380 / 32] & SOL_CMD_WND_MASK) >> 24) - 1);
1381 hdr->itt = io_task->libiscsi_itt;
1382 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1386 hwi_complete_drvr_msgs(struct beiscsi_conn *beiscsi_conn,
1387 struct beiscsi_hba *phba, struct sol_cqe *psol)
1389 struct hwi_wrb_context *pwrb_context;
1390 struct wrb_handle *pwrb_handle = NULL;
1391 struct hwi_controller *phwi_ctrlr;
1392 struct iscsi_task *task;
1393 struct beiscsi_io_task *io_task;
1394 struct iscsi_conn *conn = beiscsi_conn->conn;
1395 struct iscsi_session *session = conn->session;
1397 phwi_ctrlr = phba->phwi_ctrlr;
1398 pwrb_context = &phwi_ctrlr->wrb_context[((psol->
1399 dw[offsetof(struct amap_sol_cqe, cid) / 32] &
1400 SOL_CID_MASK) >> 6) -
1401 phba->fw_config.iscsi_cid_start];
1402 pwrb_handle = pwrb_context->pwrb_handle_basestd[((psol->
1403 dw[offsetof(struct amap_sol_cqe, wrb_index) /
1404 32] & SOL_WRB_INDEX_MASK) >> 16)];
1405 task = pwrb_handle->pio_handle;
1407 io_task = task->dd_data;
1408 spin_lock_bh(&phba->mgmt_sgl_lock);
1409 free_mgmt_sgl_handle(phba, io_task->psgl_handle);
1410 spin_unlock_bh(&phba->mgmt_sgl_lock);
1411 spin_lock_bh(&session->lock);
1412 free_wrb_handle(phba, pwrb_context, pwrb_handle);
1413 spin_unlock_bh(&session->lock);
1417 be_complete_nopin_resp(struct beiscsi_conn *beiscsi_conn,
1418 struct iscsi_task *task, struct sol_cqe *psol)
1420 struct iscsi_nopin *hdr;
1421 struct iscsi_conn *conn = beiscsi_conn->conn;
1422 struct beiscsi_io_task *io_task = task->dd_data;
1424 hdr = (struct iscsi_nopin *)task->hdr;
1425 hdr->flags = ((psol->dw[offsetof(struct amap_sol_cqe, i_flags) / 32]
1426 & SOL_FLAGS_MASK) >> 24) | 0x80;
1427 hdr->exp_cmdsn = cpu_to_be32(psol->dw[offsetof(struct amap_sol_cqe,
1428 i_exp_cmd_sn) / 32] & SOL_EXP_CMD_SN_MASK);
1429 hdr->max_cmdsn = be32_to_cpu((psol->dw[offsetof(struct amap_sol_cqe,
1430 i_exp_cmd_sn) / 32] & SOL_EXP_CMD_SN_MASK) +
1431 ((psol->dw[offsetof(struct amap_sol_cqe, i_cmd_wnd)
1432 / 32] & SOL_CMD_WND_MASK) >> 24) - 1);
1433 hdr->opcode = ISCSI_OP_NOOP_IN;
1434 hdr->itt = io_task->libiscsi_itt;
1435 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1438 static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn,
1439 struct beiscsi_hba *phba, struct sol_cqe *psol)
1441 struct hwi_wrb_context *pwrb_context;
1442 struct wrb_handle *pwrb_handle;
1443 struct iscsi_wrb *pwrb = NULL;
1444 struct hwi_controller *phwi_ctrlr;
1445 struct iscsi_task *task;
1447 struct iscsi_conn *conn = beiscsi_conn->conn;
1448 struct iscsi_session *session = conn->session;
1450 phwi_ctrlr = phba->phwi_ctrlr;
1451 pwrb_context = &phwi_ctrlr->wrb_context[((psol->dw[offsetof
1452 (struct amap_sol_cqe, cid) / 32]
1453 & SOL_CID_MASK) >> 6) -
1454 phba->fw_config.iscsi_cid_start];
1455 pwrb_handle = pwrb_context->pwrb_handle_basestd[((psol->
1456 dw[offsetof(struct amap_sol_cqe, wrb_index) /
1457 32] & SOL_WRB_INDEX_MASK) >> 16)];
1458 task = pwrb_handle->pio_handle;
1459 pwrb = pwrb_handle->pwrb;
1460 type = (pwrb->dw[offsetof(struct amap_iscsi_wrb, type) / 32] &
1461 WRB_TYPE_MASK) >> 28;
1463 spin_lock_bh(&session->lock);
1466 case HWH_TYPE_IO_RD:
1467 if ((task->hdr->opcode & ISCSI_OPCODE_MASK) ==
1469 be_complete_nopin_resp(beiscsi_conn, task, psol);
1471 be_complete_io(beiscsi_conn, task, psol);
1474 case HWH_TYPE_LOGOUT:
1475 if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGOUT)
1476 be_complete_logout(beiscsi_conn, task, psol);
1478 be_complete_tmf(beiscsi_conn, task, psol);
1482 case HWH_TYPE_LOGIN:
1483 beiscsi_log(phba, KERN_ERR,
1484 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1485 "BM_%d :\t\t No HWH_TYPE_LOGIN Expected in"
1486 " hwi_complete_cmd- Solicited path\n");
1490 be_complete_nopin_resp(beiscsi_conn, task, psol);
1494 beiscsi_log(phba, KERN_WARNING,
1495 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1496 "BM_%d : In hwi_complete_cmd, unknown type = %d"
1497 "wrb_index 0x%x CID 0x%x\n", type,
1498 ((psol->dw[offsetof(struct amap_iscsi_wrb,
1499 type) / 32] & SOL_WRB_INDEX_MASK) >> 16),
1500 ((psol->dw[offsetof(struct amap_sol_cqe,
1501 cid) / 32] & SOL_CID_MASK) >> 6));
1505 spin_unlock_bh(&session->lock);
1508 static struct list_head *hwi_get_async_busy_list(struct hwi_async_pdu_context
1509 *pasync_ctx, unsigned int is_header,
1510 unsigned int host_write_ptr)
1513 return &pasync_ctx->async_entry[host_write_ptr].
1516 return &pasync_ctx->async_entry[host_write_ptr].data_busy_list;
1519 static struct async_pdu_handle *
1520 hwi_get_async_handle(struct beiscsi_hba *phba,
1521 struct beiscsi_conn *beiscsi_conn,
1522 struct hwi_async_pdu_context *pasync_ctx,
1523 struct i_t_dpdu_cqe *pdpdu_cqe, unsigned int *pcq_index)
1525 struct be_bus_address phys_addr;
1526 struct list_head *pbusy_list;
1527 struct async_pdu_handle *pasync_handle = NULL;
1528 unsigned char is_header = 0;
1530 phys_addr.u.a32.address_lo =
1531 pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, db_addr_lo) / 32] -
1532 ((pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, dpl) / 32]
1533 & PDUCQE_DPL_MASK) >> 16);
1534 phys_addr.u.a32.address_hi =
1535 pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, db_addr_hi) / 32];
1537 phys_addr.u.a64.address =
1538 *((unsigned long long *)(&phys_addr.u.a64.address));
1540 switch (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, code) / 32]
1541 & PDUCQE_CODE_MASK) {
1542 case UNSOL_HDR_NOTIFY:
1545 pbusy_list = hwi_get_async_busy_list(pasync_ctx, 1,
1546 (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
1547 index) / 32] & PDUCQE_INDEX_MASK));
1549 case UNSOL_DATA_NOTIFY:
1550 pbusy_list = hwi_get_async_busy_list(pasync_ctx, 0, (pdpdu_cqe->
1551 dw[offsetof(struct amap_i_t_dpdu_cqe,
1552 index) / 32] & PDUCQE_INDEX_MASK));
1556 beiscsi_log(phba, KERN_WARNING,
1557 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1558 "BM_%d : Unexpected code=%d\n",
1559 pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
1560 code) / 32] & PDUCQE_CODE_MASK);
1564 WARN_ON(list_empty(pbusy_list));
1565 list_for_each_entry(pasync_handle, pbusy_list, link) {
1566 if (pasync_handle->pa.u.a64.address == phys_addr.u.a64.address)
1570 WARN_ON(!pasync_handle);
1572 pasync_handle->cri = (unsigned short)beiscsi_conn->beiscsi_conn_cid -
1573 phba->fw_config.iscsi_cid_start;
1574 pasync_handle->is_header = is_header;
1575 pasync_handle->buffer_len = ((pdpdu_cqe->
1576 dw[offsetof(struct amap_i_t_dpdu_cqe, dpl) / 32]
1577 & PDUCQE_DPL_MASK) >> 16);
1579 *pcq_index = (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
1580 index) / 32] & PDUCQE_INDEX_MASK);
1581 return pasync_handle;
1585 hwi_update_async_writables(struct beiscsi_hba *phba,
1586 struct hwi_async_pdu_context *pasync_ctx,
1587 unsigned int is_header, unsigned int cq_index)
1589 struct list_head *pbusy_list;
1590 struct async_pdu_handle *pasync_handle;
1591 unsigned int num_entries, writables = 0;
1592 unsigned int *pep_read_ptr, *pwritables;
1594 num_entries = pasync_ctx->num_entries;
1596 pep_read_ptr = &pasync_ctx->async_header.ep_read_ptr;
1597 pwritables = &pasync_ctx->async_header.writables;
1599 pep_read_ptr = &pasync_ctx->async_data.ep_read_ptr;
1600 pwritables = &pasync_ctx->async_data.writables;
1603 while ((*pep_read_ptr) != cq_index) {
1605 *pep_read_ptr = (*pep_read_ptr) % num_entries;
1607 pbusy_list = hwi_get_async_busy_list(pasync_ctx, is_header,
1610 WARN_ON(list_empty(pbusy_list));
1612 if (!list_empty(pbusy_list)) {
1613 pasync_handle = list_entry(pbusy_list->next,
1614 struct async_pdu_handle,
1616 WARN_ON(!pasync_handle);
1617 pasync_handle->consumed = 1;
1624 beiscsi_log(phba, KERN_ERR,
1625 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1626 "BM_%d : Duplicate notification received - index 0x%x!!\n",
1631 *pwritables = *pwritables + writables;
1635 static void hwi_free_async_msg(struct beiscsi_hba *phba,
1638 struct hwi_controller *phwi_ctrlr;
1639 struct hwi_async_pdu_context *pasync_ctx;
1640 struct async_pdu_handle *pasync_handle, *tmp_handle;
1641 struct list_head *plist;
1643 phwi_ctrlr = phba->phwi_ctrlr;
1644 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
1646 plist = &pasync_ctx->async_entry[cri].wait_queue.list;
1648 list_for_each_entry_safe(pasync_handle, tmp_handle, plist, link) {
1649 list_del(&pasync_handle->link);
1651 if (pasync_handle->is_header) {
1652 list_add_tail(&pasync_handle->link,
1653 &pasync_ctx->async_header.free_list);
1654 pasync_ctx->async_header.free_entries++;
1656 list_add_tail(&pasync_handle->link,
1657 &pasync_ctx->async_data.free_list);
1658 pasync_ctx->async_data.free_entries++;
1662 INIT_LIST_HEAD(&pasync_ctx->async_entry[cri].wait_queue.list);
1663 pasync_ctx->async_entry[cri].wait_queue.hdr_received = 0;
1664 pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0;
1667 static struct phys_addr *
1668 hwi_get_ring_address(struct hwi_async_pdu_context *pasync_ctx,
1669 unsigned int is_header, unsigned int host_write_ptr)
1671 struct phys_addr *pasync_sge = NULL;
1674 pasync_sge = pasync_ctx->async_header.ring_base;
1676 pasync_sge = pasync_ctx->async_data.ring_base;
1678 return pasync_sge + host_write_ptr;
1681 static void hwi_post_async_buffers(struct beiscsi_hba *phba,
1682 unsigned int is_header)
1684 struct hwi_controller *phwi_ctrlr;
1685 struct hwi_async_pdu_context *pasync_ctx;
1686 struct async_pdu_handle *pasync_handle;
1687 struct list_head *pfree_link, *pbusy_list;
1688 struct phys_addr *pasync_sge;
1689 unsigned int ring_id, num_entries;
1690 unsigned int host_write_num;
1691 unsigned int writables;
1695 phwi_ctrlr = phba->phwi_ctrlr;
1696 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
1697 num_entries = pasync_ctx->num_entries;
1700 writables = min(pasync_ctx->async_header.writables,
1701 pasync_ctx->async_header.free_entries);
1702 pfree_link = pasync_ctx->async_header.free_list.next;
1703 host_write_num = pasync_ctx->async_header.host_write_ptr;
1704 ring_id = phwi_ctrlr->default_pdu_hdr.id;
1706 writables = min(pasync_ctx->async_data.writables,
1707 pasync_ctx->async_data.free_entries);
1708 pfree_link = pasync_ctx->async_data.free_list.next;
1709 host_write_num = pasync_ctx->async_data.host_write_ptr;
1710 ring_id = phwi_ctrlr->default_pdu_data.id;
1713 writables = (writables / 8) * 8;
1715 for (i = 0; i < writables; i++) {
1717 hwi_get_async_busy_list(pasync_ctx, is_header,
1720 list_entry(pfree_link, struct async_pdu_handle,
1722 WARN_ON(!pasync_handle);
1723 pasync_handle->consumed = 0;
1725 pfree_link = pfree_link->next;
1727 pasync_sge = hwi_get_ring_address(pasync_ctx,
1728 is_header, host_write_num);
1730 pasync_sge->hi = pasync_handle->pa.u.a32.address_lo;
1731 pasync_sge->lo = pasync_handle->pa.u.a32.address_hi;
1733 list_move(&pasync_handle->link, pbusy_list);
1736 host_write_num = host_write_num % num_entries;
1740 pasync_ctx->async_header.host_write_ptr =
1742 pasync_ctx->async_header.free_entries -= writables;
1743 pasync_ctx->async_header.writables -= writables;
1744 pasync_ctx->async_header.busy_entries += writables;
1746 pasync_ctx->async_data.host_write_ptr = host_write_num;
1747 pasync_ctx->async_data.free_entries -= writables;
1748 pasync_ctx->async_data.writables -= writables;
1749 pasync_ctx->async_data.busy_entries += writables;
1752 doorbell |= ring_id & DB_DEF_PDU_RING_ID_MASK;
1753 doorbell |= 1 << DB_DEF_PDU_REARM_SHIFT;
1754 doorbell |= 0 << DB_DEF_PDU_EVENT_SHIFT;
1755 doorbell |= (writables & DB_DEF_PDU_CQPROC_MASK)
1756 << DB_DEF_PDU_CQPROC_SHIFT;
1758 iowrite32(doorbell, phba->db_va + DB_RXULP0_OFFSET);
1762 static void hwi_flush_default_pdu_buffer(struct beiscsi_hba *phba,
1763 struct beiscsi_conn *beiscsi_conn,
1764 struct i_t_dpdu_cqe *pdpdu_cqe)
1766 struct hwi_controller *phwi_ctrlr;
1767 struct hwi_async_pdu_context *pasync_ctx;
1768 struct async_pdu_handle *pasync_handle = NULL;
1769 unsigned int cq_index = -1;
1771 phwi_ctrlr = phba->phwi_ctrlr;
1772 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
1774 pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
1775 pdpdu_cqe, &cq_index);
1776 BUG_ON(pasync_handle->is_header != 0);
1777 if (pasync_handle->consumed == 0)
1778 hwi_update_async_writables(phba, pasync_ctx,
1779 pasync_handle->is_header, cq_index);
1781 hwi_free_async_msg(phba, pasync_handle->cri);
1782 hwi_post_async_buffers(phba, pasync_handle->is_header);
1786 hwi_fwd_async_msg(struct beiscsi_conn *beiscsi_conn,
1787 struct beiscsi_hba *phba,
1788 struct hwi_async_pdu_context *pasync_ctx, unsigned short cri)
1790 struct list_head *plist;
1791 struct async_pdu_handle *pasync_handle;
1793 unsigned int hdr_len = 0, buf_len = 0;
1794 unsigned int status, index = 0, offset = 0;
1795 void *pfirst_buffer = NULL;
1796 unsigned int num_buf = 0;
1798 plist = &pasync_ctx->async_entry[cri].wait_queue.list;
1800 list_for_each_entry(pasync_handle, plist, link) {
1802 phdr = pasync_handle->pbuffer;
1803 hdr_len = pasync_handle->buffer_len;
1805 buf_len = pasync_handle->buffer_len;
1807 pfirst_buffer = pasync_handle->pbuffer;
1810 memcpy(pfirst_buffer + offset,
1811 pasync_handle->pbuffer, buf_len);
1817 status = beiscsi_process_async_pdu(beiscsi_conn, phba,
1818 (beiscsi_conn->beiscsi_conn_cid -
1819 phba->fw_config.iscsi_cid_start),
1820 phdr, hdr_len, pfirst_buffer,
1823 hwi_free_async_msg(phba, cri);
1828 hwi_gather_async_pdu(struct beiscsi_conn *beiscsi_conn,
1829 struct beiscsi_hba *phba,
1830 struct async_pdu_handle *pasync_handle)
1832 struct hwi_async_pdu_context *pasync_ctx;
1833 struct hwi_controller *phwi_ctrlr;
1834 unsigned int bytes_needed = 0, status = 0;
1835 unsigned short cri = pasync_handle->cri;
1836 struct pdu_base *ppdu;
1838 phwi_ctrlr = phba->phwi_ctrlr;
1839 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
1841 list_del(&pasync_handle->link);
1842 if (pasync_handle->is_header) {
1843 pasync_ctx->async_header.busy_entries--;
1844 if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) {
1845 hwi_free_async_msg(phba, cri);
1849 pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0;
1850 pasync_ctx->async_entry[cri].wait_queue.hdr_received = 1;
1851 pasync_ctx->async_entry[cri].wait_queue.hdr_len =
1852 (unsigned short)pasync_handle->buffer_len;
1853 list_add_tail(&pasync_handle->link,
1854 &pasync_ctx->async_entry[cri].wait_queue.list);
1856 ppdu = pasync_handle->pbuffer;
1857 bytes_needed = ((((ppdu->dw[offsetof(struct amap_pdu_base,
1858 data_len_hi) / 32] & PDUBASE_DATALENHI_MASK) << 8) &
1859 0xFFFF0000) | ((be16_to_cpu((ppdu->
1860 dw[offsetof(struct amap_pdu_base, data_len_lo) / 32]
1861 & PDUBASE_DATALENLO_MASK) >> 16)) & 0x0000FFFF));
1864 pasync_ctx->async_entry[cri].wait_queue.bytes_needed =
1867 if (bytes_needed == 0)
1868 status = hwi_fwd_async_msg(beiscsi_conn, phba,
1872 pasync_ctx->async_data.busy_entries--;
1873 if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) {
1874 list_add_tail(&pasync_handle->link,
1875 &pasync_ctx->async_entry[cri].wait_queue.
1877 pasync_ctx->async_entry[cri].wait_queue.
1879 (unsigned short)pasync_handle->buffer_len;
1881 if (pasync_ctx->async_entry[cri].wait_queue.
1883 pasync_ctx->async_entry[cri].wait_queue.
1885 status = hwi_fwd_async_msg(beiscsi_conn, phba,
1892 static void hwi_process_default_pdu_ring(struct beiscsi_conn *beiscsi_conn,
1893 struct beiscsi_hba *phba,
1894 struct i_t_dpdu_cqe *pdpdu_cqe)
1896 struct hwi_controller *phwi_ctrlr;
1897 struct hwi_async_pdu_context *pasync_ctx;
1898 struct async_pdu_handle *pasync_handle = NULL;
1899 unsigned int cq_index = -1;
1901 phwi_ctrlr = phba->phwi_ctrlr;
1902 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
1903 pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
1904 pdpdu_cqe, &cq_index);
1906 if (pasync_handle->consumed == 0)
1907 hwi_update_async_writables(phba, pasync_ctx,
1908 pasync_handle->is_header, cq_index);
1910 hwi_gather_async_pdu(beiscsi_conn, phba, pasync_handle);
1911 hwi_post_async_buffers(phba, pasync_handle->is_header);
1914 static void beiscsi_process_mcc_isr(struct beiscsi_hba *phba)
1916 struct be_queue_info *mcc_cq;
1917 struct be_mcc_compl *mcc_compl;
1918 unsigned int num_processed = 0;
1920 mcc_cq = &phba->ctrl.mcc_obj.cq;
1921 mcc_compl = queue_tail_node(mcc_cq);
1922 mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
1923 while (mcc_compl->flags & CQE_FLAGS_VALID_MASK) {
1925 if (num_processed >= 32) {
1926 hwi_ring_cq_db(phba, mcc_cq->id,
1927 num_processed, 0, 0);
1930 if (mcc_compl->flags & CQE_FLAGS_ASYNC_MASK) {
1931 /* Interpret flags as an async trailer */
1932 if (is_link_state_evt(mcc_compl->flags))
1933 /* Interpret compl as a async link evt */
1934 beiscsi_async_link_state_process(phba,
1935 (struct be_async_event_link_state *) mcc_compl);
1937 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_MBOX,
1938 "BM_%d : Unsupported Async Event, flags"
1941 } else if (mcc_compl->flags & CQE_FLAGS_COMPLETED_MASK) {
1942 be_mcc_compl_process_isr(&phba->ctrl, mcc_compl);
1943 atomic_dec(&phba->ctrl.mcc_obj.q.used);
1946 mcc_compl->flags = 0;
1947 queue_tail_inc(mcc_cq);
1948 mcc_compl = queue_tail_node(mcc_cq);
1949 mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
1953 if (num_processed > 0)
1954 hwi_ring_cq_db(phba, mcc_cq->id, num_processed, 1, 0);
1959 * beiscsi_process_cq()- Process the Completion Queue
1960 * @pbe_eq: Event Q on which the Completion has come
1963 * Number of Completion Entries processed.
1965 static unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq)
1967 struct be_queue_info *cq;
1968 struct sol_cqe *sol;
1969 struct dmsg_cqe *dmsg;
1970 unsigned int num_processed = 0;
1971 unsigned int tot_nump = 0;
1972 unsigned short code = 0, cid = 0;
1973 struct beiscsi_conn *beiscsi_conn;
1974 struct beiscsi_endpoint *beiscsi_ep;
1975 struct iscsi_endpoint *ep;
1976 struct beiscsi_hba *phba;
1979 sol = queue_tail_node(cq);
1980 phba = pbe_eq->phba;
1982 while (sol->dw[offsetof(struct amap_sol_cqe, valid) / 32] &
1984 be_dws_le_to_cpu(sol, sizeof(struct sol_cqe));
1986 cid = ((sol->dw[offsetof(struct amap_sol_cqe, cid)/32] &
1987 CQE_CID_MASK) >> 6);
1988 code = (sol->dw[offsetof(struct amap_sol_cqe, code)/32] &
1990 ep = phba->ep_array[cid - phba->fw_config.iscsi_cid_start];
1992 beiscsi_ep = ep->dd_data;
1993 beiscsi_conn = beiscsi_ep->conn;
1995 if (num_processed >= 32) {
1996 hwi_ring_cq_db(phba, cq->id,
1997 num_processed, 0, 0);
1998 tot_nump += num_processed;
2003 case SOL_CMD_COMPLETE:
2004 hwi_complete_cmd(beiscsi_conn, phba, sol);
2006 case DRIVERMSG_NOTIFY:
2007 beiscsi_log(phba, KERN_INFO,
2008 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
2009 "BM_%d : Received %s[%d] on CID : %d\n",
2010 cqe_desc[code], code, cid);
2012 dmsg = (struct dmsg_cqe *)sol;
2013 hwi_complete_drvr_msgs(beiscsi_conn, phba, sol);
2015 case UNSOL_HDR_NOTIFY:
2016 beiscsi_log(phba, KERN_INFO,
2017 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
2018 "BM_%d : Received %s[%d] on CID : %d\n",
2019 cqe_desc[code], code, cid);
2021 hwi_process_default_pdu_ring(beiscsi_conn, phba,
2022 (struct i_t_dpdu_cqe *)sol);
2024 case UNSOL_DATA_NOTIFY:
2025 beiscsi_log(phba, KERN_INFO,
2026 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
2027 "BM_%d : Received %s[%d] on CID : %d\n",
2028 cqe_desc[code], code, cid);
2030 hwi_process_default_pdu_ring(beiscsi_conn, phba,
2031 (struct i_t_dpdu_cqe *)sol);
2033 case CXN_INVALIDATE_INDEX_NOTIFY:
2034 case CMD_INVALIDATED_NOTIFY:
2035 case CXN_INVALIDATE_NOTIFY:
2036 beiscsi_log(phba, KERN_ERR,
2037 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
2038 "BM_%d : Ignoring %s[%d] on CID : %d\n",
2039 cqe_desc[code], code, cid);
2041 case SOL_CMD_KILLED_DATA_DIGEST_ERR:
2042 case CMD_KILLED_INVALID_STATSN_RCVD:
2043 case CMD_KILLED_INVALID_R2T_RCVD:
2044 case CMD_CXN_KILLED_LUN_INVALID:
2045 case CMD_CXN_KILLED_ICD_INVALID:
2046 case CMD_CXN_KILLED_ITT_INVALID:
2047 case CMD_CXN_KILLED_SEQ_OUTOFORDER:
2048 case CMD_CXN_KILLED_INVALID_DATASN_RCVD:
2049 beiscsi_log(phba, KERN_ERR,
2050 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
2051 "BM_%d : Cmd Notification %s[%d] on CID : %d\n",
2052 cqe_desc[code], code, cid);
2054 case UNSOL_DATA_DIGEST_ERROR_NOTIFY:
2055 beiscsi_log(phba, KERN_ERR,
2056 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
2057 "BM_%d : Dropping %s[%d] on DPDU ring on CID : %d\n",
2058 cqe_desc[code], code, cid);
2059 hwi_flush_default_pdu_buffer(phba, beiscsi_conn,
2060 (struct i_t_dpdu_cqe *) sol);
2062 case CXN_KILLED_PDU_SIZE_EXCEEDS_DSL:
2063 case CXN_KILLED_BURST_LEN_MISMATCH:
2064 case CXN_KILLED_AHS_RCVD:
2065 case CXN_KILLED_HDR_DIGEST_ERR:
2066 case CXN_KILLED_UNKNOWN_HDR:
2067 case CXN_KILLED_STALE_ITT_TTT_RCVD:
2068 case CXN_KILLED_INVALID_ITT_TTT_RCVD:
2069 case CXN_KILLED_TIMED_OUT:
2070 case CXN_KILLED_FIN_RCVD:
2071 case CXN_KILLED_RST_SENT:
2072 case CXN_KILLED_RST_RCVD:
2073 case CXN_KILLED_BAD_UNSOL_PDU_RCVD:
2074 case CXN_KILLED_BAD_WRB_INDEX_ERROR:
2075 case CXN_KILLED_OVER_RUN_RESIDUAL:
2076 case CXN_KILLED_UNDER_RUN_RESIDUAL:
2077 case CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN:
2078 beiscsi_log(phba, KERN_ERR,
2079 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
2080 "BM_%d : Event %s[%d] received on CID : %d\n",
2081 cqe_desc[code], code, cid);
2083 iscsi_conn_failure(beiscsi_conn->conn,
2084 ISCSI_ERR_CONN_FAILED);
2087 beiscsi_log(phba, KERN_ERR,
2088 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
2089 "BM_%d : Invalid CQE Event Received Code : %d"
2095 AMAP_SET_BITS(struct amap_sol_cqe, valid, sol, 0);
2097 sol = queue_tail_node(cq);
2101 if (num_processed > 0) {
2102 tot_nump += num_processed;
2103 hwi_ring_cq_db(phba, cq->id, num_processed, 1, 0);
2108 void beiscsi_process_all_cqs(struct work_struct *work)
2110 unsigned long flags;
2111 struct hwi_controller *phwi_ctrlr;
2112 struct hwi_context_memory *phwi_context;
2113 struct be_eq_obj *pbe_eq;
2114 struct beiscsi_hba *phba =
2115 container_of(work, struct beiscsi_hba, work_cqs);
2117 phwi_ctrlr = phba->phwi_ctrlr;
2118 phwi_context = phwi_ctrlr->phwi_ctxt;
2119 if (phba->msix_enabled)
2120 pbe_eq = &phwi_context->be_eq[phba->num_cpus];
2122 pbe_eq = &phwi_context->be_eq[0];
2124 if (phba->todo_mcc_cq) {
2125 spin_lock_irqsave(&phba->isr_lock, flags);
2126 phba->todo_mcc_cq = 0;
2127 spin_unlock_irqrestore(&phba->isr_lock, flags);
2128 beiscsi_process_mcc_isr(phba);
2131 if (phba->todo_cq) {
2132 spin_lock_irqsave(&phba->isr_lock, flags);
2134 spin_unlock_irqrestore(&phba->isr_lock, flags);
2135 beiscsi_process_cq(pbe_eq);
2139 static int be_iopoll(struct blk_iopoll *iop, int budget)
2141 static unsigned int ret;
2142 struct beiscsi_hba *phba;
2143 struct be_eq_obj *pbe_eq;
2145 pbe_eq = container_of(iop, struct be_eq_obj, iopoll);
2146 ret = beiscsi_process_cq(pbe_eq);
2148 phba = pbe_eq->phba;
2149 blk_iopoll_complete(iop);
2150 beiscsi_log(phba, KERN_INFO,
2151 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
2152 "BM_%d : rearm pbe_eq->q.id =%d\n",
2154 hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1);
2160 hwi_write_sgl(struct iscsi_wrb *pwrb, struct scatterlist *sg,
2161 unsigned int num_sg, struct beiscsi_io_task *io_task)
2163 struct iscsi_sge *psgl;
2164 unsigned int sg_len, index;
2165 unsigned int sge_len = 0;
2166 unsigned long long addr;
2167 struct scatterlist *l_sg;
2168 unsigned int offset;
2170 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
2171 io_task->bhs_pa.u.a32.address_lo);
2172 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
2173 io_task->bhs_pa.u.a32.address_hi);
2176 for (index = 0; (index < num_sg) && (index < 2); index++,
2179 sg_len = sg_dma_len(sg);
2180 addr = (u64) sg_dma_address(sg);
2181 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
2182 ((u32)(addr & 0xFFFFFFFF)));
2183 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
2184 ((u32)(addr >> 32)));
2185 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
2189 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_r2t_offset,
2191 sg_len = sg_dma_len(sg);
2192 addr = (u64) sg_dma_address(sg);
2193 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_lo, pwrb,
2194 ((u32)(addr & 0xFFFFFFFF)));
2195 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_hi, pwrb,
2196 ((u32)(addr >> 32)));
2197 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_len, pwrb,
2201 psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
2202 memset(psgl, 0, sizeof(*psgl) * BE2_SGE);
2204 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2);
2206 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2207 io_task->bhs_pa.u.a32.address_hi);
2208 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2209 io_task->bhs_pa.u.a32.address_lo);
2212 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
2214 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
2216 } else if (num_sg == 2) {
2217 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
2219 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
2222 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
2224 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
2231 for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) {
2232 sg_len = sg_dma_len(sg);
2233 addr = (u64) sg_dma_address(sg);
2234 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2235 (addr & 0xFFFFFFFF));
2236 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2238 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len);
2239 AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset);
2240 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
2244 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
2248 * hwi_write_buffer()- Populate the WRB with task info
2249 * @pwrb: ptr to the WRB entry
2250 * @task: iscsi task which is to be executed
2252 static void hwi_write_buffer(struct iscsi_wrb *pwrb, struct iscsi_task *task)
2254 struct iscsi_sge *psgl;
2255 struct beiscsi_io_task *io_task = task->dd_data;
2256 struct beiscsi_conn *beiscsi_conn = io_task->conn;
2257 struct beiscsi_hba *phba = beiscsi_conn->phba;
2259 io_task->bhs_len = sizeof(struct be_nonio_bhs) - 2;
2260 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
2261 io_task->bhs_pa.u.a32.address_lo);
2262 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
2263 io_task->bhs_pa.u.a32.address_hi);
2266 if (task->data_count) {
2267 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1);
2268 io_task->mtask_addr = pci_map_single(phba->pcidev,
2273 io_task->mtask_data_count = task->data_count;
2275 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
2276 io_task->mtask_addr = 0;
2278 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
2279 lower_32_bits(io_task->mtask_addr));
2280 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
2281 upper_32_bits(io_task->mtask_addr));
2282 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
2285 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, 1);
2287 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
2288 io_task->mtask_addr = 0;
2291 psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
2293 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len);
2295 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2296 io_task->bhs_pa.u.a32.address_hi);
2297 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2298 io_task->bhs_pa.u.a32.address_lo);
2301 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, 0);
2302 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, 0);
2303 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0);
2304 AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, 0);
2305 AMAP_SET_BITS(struct amap_iscsi_sge, rsvd0, psgl, 0);
2306 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
2310 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2311 lower_32_bits(io_task->mtask_addr));
2312 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2313 upper_32_bits(io_task->mtask_addr));
2315 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0x106);
2317 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
2320 static void beiscsi_find_mem_req(struct beiscsi_hba *phba)
2322 unsigned int num_cq_pages, num_async_pdu_buf_pages;
2323 unsigned int num_async_pdu_data_pages, wrb_sz_per_cxn;
2324 unsigned int num_async_pdu_buf_sgl_pages, num_async_pdu_data_sgl_pages;
2326 num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
2327 sizeof(struct sol_cqe));
2328 num_async_pdu_buf_pages =
2329 PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
2330 phba->params.defpdu_hdr_sz);
2331 num_async_pdu_buf_sgl_pages =
2332 PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
2333 sizeof(struct phys_addr));
2334 num_async_pdu_data_pages =
2335 PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
2336 phba->params.defpdu_data_sz);
2337 num_async_pdu_data_sgl_pages =
2338 PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
2339 sizeof(struct phys_addr));
2341 phba->params.hwi_ws_sz = sizeof(struct hwi_controller);
2343 phba->mem_req[ISCSI_MEM_GLOBAL_HEADER] = 2 *
2344 BE_ISCSI_PDU_HEADER_SIZE;
2345 phba->mem_req[HWI_MEM_ADDN_CONTEXT] =
2346 sizeof(struct hwi_context_memory);
2349 phba->mem_req[HWI_MEM_WRB] = sizeof(struct iscsi_wrb)
2350 * (phba->params.wrbs_per_cxn)
2351 * phba->params.cxns_per_ctrl;
2352 wrb_sz_per_cxn = sizeof(struct wrb_handle) *
2353 (phba->params.wrbs_per_cxn);
2354 phba->mem_req[HWI_MEM_WRBH] = roundup_pow_of_two((wrb_sz_per_cxn) *
2355 phba->params.cxns_per_ctrl);
2357 phba->mem_req[HWI_MEM_SGLH] = sizeof(struct sgl_handle) *
2358 phba->params.icds_per_ctrl;
2359 phba->mem_req[HWI_MEM_SGE] = sizeof(struct iscsi_sge) *
2360 phba->params.num_sge_per_io * phba->params.icds_per_ctrl;
2362 phba->mem_req[HWI_MEM_ASYNC_HEADER_BUF] =
2363 num_async_pdu_buf_pages * PAGE_SIZE;
2364 phba->mem_req[HWI_MEM_ASYNC_DATA_BUF] =
2365 num_async_pdu_data_pages * PAGE_SIZE;
2366 phba->mem_req[HWI_MEM_ASYNC_HEADER_RING] =
2367 num_async_pdu_buf_sgl_pages * PAGE_SIZE;
2368 phba->mem_req[HWI_MEM_ASYNC_DATA_RING] =
2369 num_async_pdu_data_sgl_pages * PAGE_SIZE;
2370 phba->mem_req[HWI_MEM_ASYNC_HEADER_HANDLE] =
2371 phba->params.asyncpdus_per_ctrl *
2372 sizeof(struct async_pdu_handle);
2373 phba->mem_req[HWI_MEM_ASYNC_DATA_HANDLE] =
2374 phba->params.asyncpdus_per_ctrl *
2375 sizeof(struct async_pdu_handle);
2376 phba->mem_req[HWI_MEM_ASYNC_PDU_CONTEXT] =
2377 sizeof(struct hwi_async_pdu_context) +
2378 (phba->params.cxns_per_ctrl * sizeof(struct hwi_async_entry));
2381 static int beiscsi_alloc_mem(struct beiscsi_hba *phba)
2383 struct be_mem_descriptor *mem_descr;
2385 struct mem_array *mem_arr, *mem_arr_orig;
2386 unsigned int i, j, alloc_size, curr_alloc_size;
2388 phba->phwi_ctrlr = kzalloc(phba->params.hwi_ws_sz, GFP_KERNEL);
2389 if (!phba->phwi_ctrlr)
2392 phba->init_mem = kcalloc(SE_MEM_MAX, sizeof(*mem_descr),
2394 if (!phba->init_mem) {
2395 kfree(phba->phwi_ctrlr);
2399 mem_arr_orig = kmalloc(sizeof(*mem_arr_orig) * BEISCSI_MAX_FRAGS_INIT,
2401 if (!mem_arr_orig) {
2402 kfree(phba->init_mem);
2403 kfree(phba->phwi_ctrlr);
2407 mem_descr = phba->init_mem;
2408 for (i = 0; i < SE_MEM_MAX; i++) {
2410 mem_arr = mem_arr_orig;
2411 alloc_size = phba->mem_req[i];
2412 memset(mem_arr, 0, sizeof(struct mem_array) *
2413 BEISCSI_MAX_FRAGS_INIT);
2414 curr_alloc_size = min(be_max_phys_size * 1024, alloc_size);
2416 mem_arr->virtual_address = pci_alloc_consistent(
2420 if (!mem_arr->virtual_address) {
2421 if (curr_alloc_size <= BE_MIN_MEM_SIZE)
2423 if (curr_alloc_size -
2424 rounddown_pow_of_two(curr_alloc_size))
2425 curr_alloc_size = rounddown_pow_of_two
2428 curr_alloc_size = curr_alloc_size / 2;
2430 mem_arr->bus_address.u.
2431 a64.address = (__u64) bus_add;
2432 mem_arr->size = curr_alloc_size;
2433 alloc_size -= curr_alloc_size;
2434 curr_alloc_size = min(be_max_phys_size *
2439 } while (alloc_size);
2440 mem_descr->num_elements = j;
2441 mem_descr->size_in_bytes = phba->mem_req[i];
2442 mem_descr->mem_array = kmalloc(sizeof(*mem_arr) * j,
2444 if (!mem_descr->mem_array)
2447 memcpy(mem_descr->mem_array, mem_arr_orig,
2448 sizeof(struct mem_array) * j);
2451 kfree(mem_arr_orig);
2454 mem_descr->num_elements = j;
2455 while ((i) || (j)) {
2456 for (j = mem_descr->num_elements; j > 0; j--) {
2457 pci_free_consistent(phba->pcidev,
2458 mem_descr->mem_array[j - 1].size,
2459 mem_descr->mem_array[j - 1].
2461 (unsigned long)mem_descr->
2463 bus_address.u.a64.address);
2467 kfree(mem_descr->mem_array);
2471 kfree(mem_arr_orig);
2472 kfree(phba->init_mem);
2473 kfree(phba->phwi_ctrlr);
2477 static int beiscsi_get_memory(struct beiscsi_hba *phba)
2479 beiscsi_find_mem_req(phba);
2480 return beiscsi_alloc_mem(phba);
2483 static void iscsi_init_global_templates(struct beiscsi_hba *phba)
2485 struct pdu_data_out *pdata_out;
2486 struct pdu_nop_out *pnop_out;
2487 struct be_mem_descriptor *mem_descr;
2489 mem_descr = phba->init_mem;
2490 mem_descr += ISCSI_MEM_GLOBAL_HEADER;
2492 (struct pdu_data_out *)mem_descr->mem_array[0].virtual_address;
2493 memset(pdata_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
2495 AMAP_SET_BITS(struct amap_pdu_data_out, opcode, pdata_out,
2499 (struct pdu_nop_out *)((unsigned char *)mem_descr->mem_array[0].
2500 virtual_address + BE_ISCSI_PDU_HEADER_SIZE);
2502 memset(pnop_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
2503 AMAP_SET_BITS(struct amap_pdu_nop_out, ttt, pnop_out, 0xFFFFFFFF);
2504 AMAP_SET_BITS(struct amap_pdu_nop_out, f_bit, pnop_out, 1);
2505 AMAP_SET_BITS(struct amap_pdu_nop_out, i_bit, pnop_out, 0);
2508 static int beiscsi_init_wrb_handle(struct beiscsi_hba *phba)
2510 struct be_mem_descriptor *mem_descr_wrbh, *mem_descr_wrb;
2511 struct wrb_handle *pwrb_handle = NULL;
2512 struct hwi_controller *phwi_ctrlr;
2513 struct hwi_wrb_context *pwrb_context;
2514 struct iscsi_wrb *pwrb = NULL;
2515 unsigned int num_cxn_wrbh = 0;
2516 unsigned int num_cxn_wrb = 0, j, idx = 0, index;
2518 mem_descr_wrbh = phba->init_mem;
2519 mem_descr_wrbh += HWI_MEM_WRBH;
2521 mem_descr_wrb = phba->init_mem;
2522 mem_descr_wrb += HWI_MEM_WRB;
2523 phwi_ctrlr = phba->phwi_ctrlr;
2525 for (index = 0; index < phba->params.cxns_per_ctrl * 2; index += 2) {
2526 pwrb_context = &phwi_ctrlr->wrb_context[index];
2527 pwrb_context->pwrb_handle_base =
2528 kzalloc(sizeof(struct wrb_handle *) *
2529 phba->params.wrbs_per_cxn, GFP_KERNEL);
2530 if (!pwrb_context->pwrb_handle_base) {
2531 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2532 "BM_%d : Mem Alloc Failed. Failing to load\n");
2533 goto init_wrb_hndl_failed;
2535 pwrb_context->pwrb_handle_basestd =
2536 kzalloc(sizeof(struct wrb_handle *) *
2537 phba->params.wrbs_per_cxn, GFP_KERNEL);
2538 if (!pwrb_context->pwrb_handle_basestd) {
2539 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2540 "BM_%d : Mem Alloc Failed. Failing to load\n");
2541 goto init_wrb_hndl_failed;
2543 if (!num_cxn_wrbh) {
2545 mem_descr_wrbh->mem_array[idx].virtual_address;
2546 num_cxn_wrbh = ((mem_descr_wrbh->mem_array[idx].size) /
2547 ((sizeof(struct wrb_handle)) *
2548 phba->params.wrbs_per_cxn));
2551 pwrb_context->alloc_index = 0;
2552 pwrb_context->wrb_handles_available = 0;
2553 pwrb_context->free_index = 0;
2556 for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
2557 pwrb_context->pwrb_handle_base[j] = pwrb_handle;
2558 pwrb_context->pwrb_handle_basestd[j] =
2560 pwrb_context->wrb_handles_available++;
2561 pwrb_handle->wrb_index = j;
2568 for (index = 0; index < phba->params.cxns_per_ctrl * 2; index += 2) {
2569 pwrb_context = &phwi_ctrlr->wrb_context[index];
2571 pwrb = mem_descr_wrb->mem_array[idx].virtual_address;
2572 num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) /
2573 ((sizeof(struct iscsi_wrb) *
2574 phba->params.wrbs_per_cxn));
2579 for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
2580 pwrb_handle = pwrb_context->pwrb_handle_base[j];
2581 pwrb_handle->pwrb = pwrb;
2588 init_wrb_hndl_failed:
2589 for (j = index; j > 0; j--) {
2590 pwrb_context = &phwi_ctrlr->wrb_context[j];
2591 kfree(pwrb_context->pwrb_handle_base);
2592 kfree(pwrb_context->pwrb_handle_basestd);
2597 static void hwi_init_async_pdu_ctx(struct beiscsi_hba *phba)
2599 struct hwi_controller *phwi_ctrlr;
2600 struct hba_parameters *p = &phba->params;
2601 struct hwi_async_pdu_context *pasync_ctx;
2602 struct async_pdu_handle *pasync_header_h, *pasync_data_h;
2603 unsigned int index, idx, num_per_mem, num_async_data;
2604 struct be_mem_descriptor *mem_descr;
2606 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2607 mem_descr += HWI_MEM_ASYNC_PDU_CONTEXT;
2609 phwi_ctrlr = phba->phwi_ctrlr;
2610 phwi_ctrlr->phwi_ctxt->pasync_ctx = (struct hwi_async_pdu_context *)
2611 mem_descr->mem_array[0].virtual_address;
2612 pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx;
2613 memset(pasync_ctx, 0, sizeof(*pasync_ctx));
2615 pasync_ctx->num_entries = p->asyncpdus_per_ctrl;
2616 pasync_ctx->buffer_size = p->defpdu_hdr_sz;
2618 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2619 mem_descr += HWI_MEM_ASYNC_HEADER_BUF;
2620 if (mem_descr->mem_array[0].virtual_address) {
2621 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2622 "BM_%d : hwi_init_async_pdu_ctx"
2623 " HWI_MEM_ASYNC_HEADER_BUF va=%p\n",
2624 mem_descr->mem_array[0].virtual_address);
2626 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
2627 "BM_%d : No Virtual address\n");
2629 pasync_ctx->async_header.va_base =
2630 mem_descr->mem_array[0].virtual_address;
2632 pasync_ctx->async_header.pa_base.u.a64.address =
2633 mem_descr->mem_array[0].bus_address.u.a64.address;
2635 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2636 mem_descr += HWI_MEM_ASYNC_HEADER_RING;
2637 if (mem_descr->mem_array[0].virtual_address) {
2638 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2639 "BM_%d : hwi_init_async_pdu_ctx"
2640 " HWI_MEM_ASYNC_HEADER_RING va=%p\n",
2641 mem_descr->mem_array[0].virtual_address);
2643 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
2644 "BM_%d : No Virtual address\n");
2646 pasync_ctx->async_header.ring_base =
2647 mem_descr->mem_array[0].virtual_address;
2649 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2650 mem_descr += HWI_MEM_ASYNC_HEADER_HANDLE;
2651 if (mem_descr->mem_array[0].virtual_address) {
2652 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2653 "BM_%d : hwi_init_async_pdu_ctx"
2654 " HWI_MEM_ASYNC_HEADER_HANDLE va=%p\n",
2655 mem_descr->mem_array[0].virtual_address);
2657 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
2658 "BM_%d : No Virtual address\n");
2660 pasync_ctx->async_header.handle_base =
2661 mem_descr->mem_array[0].virtual_address;
2662 pasync_ctx->async_header.writables = 0;
2663 INIT_LIST_HEAD(&pasync_ctx->async_header.free_list);
2666 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2667 mem_descr += HWI_MEM_ASYNC_DATA_RING;
2668 if (mem_descr->mem_array[0].virtual_address) {
2669 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2670 "BM_%d : hwi_init_async_pdu_ctx"
2671 " HWI_MEM_ASYNC_DATA_RING va=%p\n",
2672 mem_descr->mem_array[0].virtual_address);
2674 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
2675 "BM_%d : No Virtual address\n");
2677 pasync_ctx->async_data.ring_base =
2678 mem_descr->mem_array[0].virtual_address;
2680 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2681 mem_descr += HWI_MEM_ASYNC_DATA_HANDLE;
2682 if (!mem_descr->mem_array[0].virtual_address)
2683 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
2684 "BM_%d : No Virtual address\n");
2686 pasync_ctx->async_data.handle_base =
2687 mem_descr->mem_array[0].virtual_address;
2688 pasync_ctx->async_data.writables = 0;
2689 INIT_LIST_HEAD(&pasync_ctx->async_data.free_list);
2692 (struct async_pdu_handle *)pasync_ctx->async_header.handle_base;
2694 (struct async_pdu_handle *)pasync_ctx->async_data.handle_base;
2696 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2697 mem_descr += HWI_MEM_ASYNC_DATA_BUF;
2698 if (mem_descr->mem_array[0].virtual_address) {
2699 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2700 "BM_%d : hwi_init_async_pdu_ctx"
2701 " HWI_MEM_ASYNC_DATA_BUF va=%p\n",
2702 mem_descr->mem_array[0].virtual_address);
2704 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
2705 "BM_%d : No Virtual address\n");
2708 pasync_ctx->async_data.va_base =
2709 mem_descr->mem_array[idx].virtual_address;
2710 pasync_ctx->async_data.pa_base.u.a64.address =
2711 mem_descr->mem_array[idx].bus_address.u.a64.address;
2713 num_async_data = ((mem_descr->mem_array[idx].size) /
2714 phba->params.defpdu_data_sz);
2717 for (index = 0; index < p->asyncpdus_per_ctrl; index++) {
2718 pasync_header_h->cri = -1;
2719 pasync_header_h->index = (char)index;
2720 INIT_LIST_HEAD(&pasync_header_h->link);
2721 pasync_header_h->pbuffer =
2722 (void *)((unsigned long)
2723 (pasync_ctx->async_header.va_base) +
2724 (p->defpdu_hdr_sz * index));
2726 pasync_header_h->pa.u.a64.address =
2727 pasync_ctx->async_header.pa_base.u.a64.address +
2728 (p->defpdu_hdr_sz * index);
2730 list_add_tail(&pasync_header_h->link,
2731 &pasync_ctx->async_header.free_list);
2733 pasync_ctx->async_header.free_entries++;
2734 pasync_ctx->async_header.writables++;
2736 INIT_LIST_HEAD(&pasync_ctx->async_entry[index].wait_queue.list);
2737 INIT_LIST_HEAD(&pasync_ctx->async_entry[index].
2739 pasync_data_h->cri = -1;
2740 pasync_data_h->index = (char)index;
2741 INIT_LIST_HEAD(&pasync_data_h->link);
2743 if (!num_async_data) {
2746 pasync_ctx->async_data.va_base =
2747 mem_descr->mem_array[idx].virtual_address;
2748 pasync_ctx->async_data.pa_base.u.a64.address =
2749 mem_descr->mem_array[idx].
2750 bus_address.u.a64.address;
2752 num_async_data = ((mem_descr->mem_array[idx].size) /
2753 phba->params.defpdu_data_sz);
2755 pasync_data_h->pbuffer =
2756 (void *)((unsigned long)
2757 (pasync_ctx->async_data.va_base) +
2758 (p->defpdu_data_sz * num_per_mem));
2760 pasync_data_h->pa.u.a64.address =
2761 pasync_ctx->async_data.pa_base.u.a64.address +
2762 (p->defpdu_data_sz * num_per_mem);
2766 list_add_tail(&pasync_data_h->link,
2767 &pasync_ctx->async_data.free_list);
2769 pasync_ctx->async_data.free_entries++;
2770 pasync_ctx->async_data.writables++;
2772 INIT_LIST_HEAD(&pasync_ctx->async_entry[index].data_busy_list);
2775 pasync_ctx->async_header.host_write_ptr = 0;
2776 pasync_ctx->async_header.ep_read_ptr = -1;
2777 pasync_ctx->async_data.host_write_ptr = 0;
2778 pasync_ctx->async_data.ep_read_ptr = -1;
2782 be_sgl_create_contiguous(void *virtual_address,
2783 u64 physical_address, u32 length,
2784 struct be_dma_mem *sgl)
2786 WARN_ON(!virtual_address);
2787 WARN_ON(!physical_address);
2788 WARN_ON(!length > 0);
2791 sgl->va = virtual_address;
2792 sgl->dma = (unsigned long)physical_address;
2798 static void be_sgl_destroy_contiguous(struct be_dma_mem *sgl)
2800 memset(sgl, 0, sizeof(*sgl));
2804 hwi_build_be_sgl_arr(struct beiscsi_hba *phba,
2805 struct mem_array *pmem, struct be_dma_mem *sgl)
2808 be_sgl_destroy_contiguous(sgl);
2810 be_sgl_create_contiguous(pmem->virtual_address,
2811 pmem->bus_address.u.a64.address,
2816 hwi_build_be_sgl_by_offset(struct beiscsi_hba *phba,
2817 struct mem_array *pmem, struct be_dma_mem *sgl)
2820 be_sgl_destroy_contiguous(sgl);
2822 be_sgl_create_contiguous((unsigned char *)pmem->virtual_address,
2823 pmem->bus_address.u.a64.address,
2827 static int be_fill_queue(struct be_queue_info *q,
2828 u16 len, u16 entry_size, void *vaddress)
2830 struct be_dma_mem *mem = &q->dma_mem;
2832 memset(q, 0, sizeof(*q));
2834 q->entry_size = entry_size;
2835 mem->size = len * entry_size;
2839 memset(mem->va, 0, mem->size);
2843 static int beiscsi_create_eqs(struct beiscsi_hba *phba,
2844 struct hwi_context_memory *phwi_context)
2846 unsigned int i, num_eq_pages;
2847 int ret = 0, eq_for_mcc;
2848 struct be_queue_info *eq;
2849 struct be_dma_mem *mem;
2853 num_eq_pages = PAGES_REQUIRED(phba->params.num_eq_entries * \
2854 sizeof(struct be_eq_entry));
2856 if (phba->msix_enabled)
2860 for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
2861 eq = &phwi_context->be_eq[i].q;
2863 phwi_context->be_eq[i].phba = phba;
2864 eq_vaddress = pci_alloc_consistent(phba->pcidev,
2865 num_eq_pages * PAGE_SIZE,
2868 goto create_eq_error;
2870 mem->va = eq_vaddress;
2871 ret = be_fill_queue(eq, phba->params.num_eq_entries,
2872 sizeof(struct be_eq_entry), eq_vaddress);
2874 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2875 "BM_%d : be_fill_queue Failed for EQ\n");
2876 goto create_eq_error;
2880 ret = beiscsi_cmd_eq_create(&phba->ctrl, eq,
2881 phwi_context->cur_eqd);
2883 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2884 "BM_%d : beiscsi_cmd_eq_create"
2886 goto create_eq_error;
2889 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2890 "BM_%d : eqid = %d\n",
2891 phwi_context->be_eq[i].q.id);
2895 for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
2896 eq = &phwi_context->be_eq[i].q;
2899 pci_free_consistent(phba->pcidev, num_eq_pages
2906 static int beiscsi_create_cqs(struct beiscsi_hba *phba,
2907 struct hwi_context_memory *phwi_context)
2909 unsigned int i, num_cq_pages;
2911 struct be_queue_info *cq, *eq;
2912 struct be_dma_mem *mem;
2913 struct be_eq_obj *pbe_eq;
2917 num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
2918 sizeof(struct sol_cqe));
2920 for (i = 0; i < phba->num_cpus; i++) {
2921 cq = &phwi_context->be_cq[i];
2922 eq = &phwi_context->be_eq[i].q;
2923 pbe_eq = &phwi_context->be_eq[i];
2925 pbe_eq->phba = phba;
2927 cq_vaddress = pci_alloc_consistent(phba->pcidev,
2928 num_cq_pages * PAGE_SIZE,
2931 goto create_cq_error;
2932 ret = be_fill_queue(cq, phba->params.num_cq_entries,
2933 sizeof(struct sol_cqe), cq_vaddress);
2935 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2936 "BM_%d : be_fill_queue Failed "
2938 goto create_cq_error;
2942 ret = beiscsi_cmd_cq_create(&phba->ctrl, cq, eq, false,
2945 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2946 "BM_%d : beiscsi_cmd_eq_create"
2947 "Failed for ISCSI CQ\n");
2948 goto create_cq_error;
2950 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2951 "BM_%d : iscsi cq_id is %d for eq_id %d\n"
2952 "iSCSI CQ CREATED\n", cq->id, eq->id);
2957 for (i = 0; i < phba->num_cpus; i++) {
2958 cq = &phwi_context->be_cq[i];
2961 pci_free_consistent(phba->pcidev, num_cq_pages
2970 beiscsi_create_def_hdr(struct beiscsi_hba *phba,
2971 struct hwi_context_memory *phwi_context,
2972 struct hwi_controller *phwi_ctrlr,
2973 unsigned int def_pdu_ring_sz)
2977 struct be_queue_info *dq, *cq;
2978 struct be_dma_mem *mem;
2979 struct be_mem_descriptor *mem_descr;
2983 dq = &phwi_context->be_def_hdrq;
2984 cq = &phwi_context->be_cq[0];
2986 mem_descr = phba->init_mem;
2987 mem_descr += HWI_MEM_ASYNC_HEADER_RING;
2988 dq_vaddress = mem_descr->mem_array[idx].virtual_address;
2989 ret = be_fill_queue(dq, mem_descr->mem_array[0].size /
2990 sizeof(struct phys_addr),
2991 sizeof(struct phys_addr), dq_vaddress);
2993 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2994 "BM_%d : be_fill_queue Failed for DEF PDU HDR\n");
2997 mem->dma = (unsigned long)mem_descr->mem_array[idx].
2998 bus_address.u.a64.address;
2999 ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dq,
3001 phba->params.defpdu_hdr_sz);
3003 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3004 "BM_%d : be_cmd_create_default_pdu_queue Failed DEFHDR\n");
3007 phwi_ctrlr->default_pdu_hdr.id = phwi_context->be_def_hdrq.id;
3008 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3009 "BM_%d : iscsi def pdu id is %d\n",
3010 phwi_context->be_def_hdrq.id);
3012 hwi_post_async_buffers(phba, 1);
3017 beiscsi_create_def_data(struct beiscsi_hba *phba,
3018 struct hwi_context_memory *phwi_context,
3019 struct hwi_controller *phwi_ctrlr,
3020 unsigned int def_pdu_ring_sz)
3024 struct be_queue_info *dataq, *cq;
3025 struct be_dma_mem *mem;
3026 struct be_mem_descriptor *mem_descr;
3030 dataq = &phwi_context->be_def_dataq;
3031 cq = &phwi_context->be_cq[0];
3032 mem = &dataq->dma_mem;
3033 mem_descr = phba->init_mem;
3034 mem_descr += HWI_MEM_ASYNC_DATA_RING;
3035 dq_vaddress = mem_descr->mem_array[idx].virtual_address;
3036 ret = be_fill_queue(dataq, mem_descr->mem_array[0].size /
3037 sizeof(struct phys_addr),
3038 sizeof(struct phys_addr), dq_vaddress);
3040 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3041 "BM_%d : be_fill_queue Failed for DEF PDU DATA\n");
3044 mem->dma = (unsigned long)mem_descr->mem_array[idx].
3045 bus_address.u.a64.address;
3046 ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dataq,
3048 phba->params.defpdu_data_sz);
3050 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3051 "BM_%d be_cmd_create_default_pdu_queue"
3052 " Failed for DEF PDU DATA\n");
3055 phwi_ctrlr->default_pdu_data.id = phwi_context->be_def_dataq.id;
3056 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3057 "BM_%d : iscsi def data id is %d\n",
3058 phwi_context->be_def_dataq.id);
3060 hwi_post_async_buffers(phba, 0);
3061 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3062 "BM_%d : DEFAULT PDU DATA RING CREATED\n");
3068 beiscsi_post_pages(struct beiscsi_hba *phba)
3070 struct be_mem_descriptor *mem_descr;
3071 struct mem_array *pm_arr;
3072 unsigned int page_offset, i;
3073 struct be_dma_mem sgl;
3076 mem_descr = phba->init_mem;
3077 mem_descr += HWI_MEM_SGE;
3078 pm_arr = mem_descr->mem_array;
3080 page_offset = (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io *
3081 phba->fw_config.iscsi_icd_start) / PAGE_SIZE;
3082 for (i = 0; i < mem_descr->num_elements; i++) {
3083 hwi_build_be_sgl_arr(phba, pm_arr, &sgl);
3084 status = be_cmd_iscsi_post_sgl_pages(&phba->ctrl, &sgl,
3086 (pm_arr->size / PAGE_SIZE));
3087 page_offset += pm_arr->size / PAGE_SIZE;
3089 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3090 "BM_%d : post sgl failed.\n");
3095 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3096 "BM_%d : POSTED PAGES\n");
3100 static void be_queue_free(struct beiscsi_hba *phba, struct be_queue_info *q)
3102 struct be_dma_mem *mem = &q->dma_mem;
3104 pci_free_consistent(phba->pcidev, mem->size,
3110 static int be_queue_alloc(struct beiscsi_hba *phba, struct be_queue_info *q,
3111 u16 len, u16 entry_size)
3113 struct be_dma_mem *mem = &q->dma_mem;
3115 memset(q, 0, sizeof(*q));
3117 q->entry_size = entry_size;
3118 mem->size = len * entry_size;
3119 mem->va = pci_alloc_consistent(phba->pcidev, mem->size, &mem->dma);
3122 memset(mem->va, 0, mem->size);
3127 beiscsi_create_wrb_rings(struct beiscsi_hba *phba,
3128 struct hwi_context_memory *phwi_context,
3129 struct hwi_controller *phwi_ctrlr)
3131 unsigned int wrb_mem_index, offset, size, num_wrb_rings;
3133 unsigned int idx, num, i;
3134 struct mem_array *pwrb_arr;
3136 struct be_dma_mem sgl;
3137 struct be_mem_descriptor *mem_descr;
3141 mem_descr = phba->init_mem;
3142 mem_descr += HWI_MEM_WRB;
3143 pwrb_arr = kmalloc(sizeof(*pwrb_arr) * phba->params.cxns_per_ctrl,
3146 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3147 "BM_%d : Memory alloc failed in create wrb ring.\n");
3150 wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
3151 pa_addr_lo = mem_descr->mem_array[idx].bus_address.u.a64.address;
3152 num_wrb_rings = mem_descr->mem_array[idx].size /
3153 (phba->params.wrbs_per_cxn * sizeof(struct iscsi_wrb));
3155 for (num = 0; num < phba->params.cxns_per_ctrl; num++) {
3156 if (num_wrb_rings) {
3157 pwrb_arr[num].virtual_address = wrb_vaddr;
3158 pwrb_arr[num].bus_address.u.a64.address = pa_addr_lo;
3159 pwrb_arr[num].size = phba->params.wrbs_per_cxn *
3160 sizeof(struct iscsi_wrb);
3161 wrb_vaddr += pwrb_arr[num].size;
3162 pa_addr_lo += pwrb_arr[num].size;
3166 wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
3167 pa_addr_lo = mem_descr->mem_array[idx].\
3168 bus_address.u.a64.address;
3169 num_wrb_rings = mem_descr->mem_array[idx].size /
3170 (phba->params.wrbs_per_cxn *
3171 sizeof(struct iscsi_wrb));
3172 pwrb_arr[num].virtual_address = wrb_vaddr;
3173 pwrb_arr[num].bus_address.u.a64.address\
3175 pwrb_arr[num].size = phba->params.wrbs_per_cxn *
3176 sizeof(struct iscsi_wrb);
3177 wrb_vaddr += pwrb_arr[num].size;
3178 pa_addr_lo += pwrb_arr[num].size;
3182 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
3187 hwi_build_be_sgl_by_offset(phba, &pwrb_arr[i], &sgl);
3188 status = be_cmd_wrbq_create(&phba->ctrl, &sgl,
3189 &phwi_context->be_wrbq[i]);
3191 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3192 "BM_%d : wrbq create failed.");
3196 phwi_ctrlr->wrb_context[i * 2].cid = phwi_context->be_wrbq[i].
3203 static void free_wrb_handles(struct beiscsi_hba *phba)
3206 struct hwi_controller *phwi_ctrlr;
3207 struct hwi_wrb_context *pwrb_context;
3209 phwi_ctrlr = phba->phwi_ctrlr;
3210 for (index = 0; index < phba->params.cxns_per_ctrl * 2; index += 2) {
3211 pwrb_context = &phwi_ctrlr->wrb_context[index];
3212 kfree(pwrb_context->pwrb_handle_base);
3213 kfree(pwrb_context->pwrb_handle_basestd);
3217 static void be_mcc_queues_destroy(struct beiscsi_hba *phba)
3219 struct be_queue_info *q;
3220 struct be_ctrl_info *ctrl = &phba->ctrl;
3222 q = &phba->ctrl.mcc_obj.q;
3224 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_MCCQ);
3225 be_queue_free(phba, q);
3227 q = &phba->ctrl.mcc_obj.cq;
3229 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
3230 be_queue_free(phba, q);
3233 static void hwi_cleanup(struct beiscsi_hba *phba)
3235 struct be_queue_info *q;
3236 struct be_ctrl_info *ctrl = &phba->ctrl;
3237 struct hwi_controller *phwi_ctrlr;
3238 struct hwi_context_memory *phwi_context;
3241 phwi_ctrlr = phba->phwi_ctrlr;
3242 phwi_context = phwi_ctrlr->phwi_ctxt;
3243 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
3244 q = &phwi_context->be_wrbq[i];
3246 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_WRBQ);
3248 free_wrb_handles(phba);
3250 q = &phwi_context->be_def_hdrq;
3252 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
3254 q = &phwi_context->be_def_dataq;
3256 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
3258 beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
3260 for (i = 0; i < (phba->num_cpus); i++) {
3261 q = &phwi_context->be_cq[i];
3263 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
3265 if (phba->msix_enabled)
3269 for (i = 0; i < (phba->num_cpus + eq_num); i++) {
3270 q = &phwi_context->be_eq[i].q;
3272 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_EQ);
3274 be_mcc_queues_destroy(phba);
3277 static int be_mcc_queues_create(struct beiscsi_hba *phba,
3278 struct hwi_context_memory *phwi_context)
3280 struct be_queue_info *q, *cq;
3281 struct be_ctrl_info *ctrl = &phba->ctrl;
3283 /* Alloc MCC compl queue */
3284 cq = &phba->ctrl.mcc_obj.cq;
3285 if (be_queue_alloc(phba, cq, MCC_CQ_LEN,
3286 sizeof(struct be_mcc_compl)))
3288 /* Ask BE to create MCC compl queue; */
3289 if (phba->msix_enabled) {
3290 if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq
3291 [phba->num_cpus].q, false, true, 0))
3294 if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq[0].q,
3299 /* Alloc MCC queue */
3300 q = &phba->ctrl.mcc_obj.q;
3301 if (be_queue_alloc(phba, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb)))
3302 goto mcc_cq_destroy;
3304 /* Ask BE to create MCC queue */
3305 if (beiscsi_cmd_mccq_create(phba, q, cq))
3311 be_queue_free(phba, q);
3313 beiscsi_cmd_q_destroy(ctrl, cq, QTYPE_CQ);
3315 be_queue_free(phba, cq);
3321 * find_num_cpus()- Get the CPU online count
3322 * @phba: ptr to priv structure
3324 * CPU count is used for creating EQ.
3326 static void find_num_cpus(struct beiscsi_hba *phba)
3330 num_cpus = num_online_cpus();
3332 phba->num_cpus = (num_cpus >= BEISCSI_MAX_NUM_CPU) ?
3333 (BEISCSI_MAX_NUM_CPU - 1) : num_cpus;
3336 static int hwi_init_port(struct beiscsi_hba *phba)
3338 struct hwi_controller *phwi_ctrlr;
3339 struct hwi_context_memory *phwi_context;
3340 unsigned int def_pdu_ring_sz;
3341 struct be_ctrl_info *ctrl = &phba->ctrl;
3345 phba->params.asyncpdus_per_ctrl * sizeof(struct phys_addr);
3346 phwi_ctrlr = phba->phwi_ctrlr;
3347 phwi_context = phwi_ctrlr->phwi_ctxt;
3348 phwi_context->max_eqd = 0;
3349 phwi_context->min_eqd = 0;
3350 phwi_context->cur_eqd = 64;
3351 be_cmd_fw_initialize(&phba->ctrl);
3353 status = beiscsi_create_eqs(phba, phwi_context);
3355 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3356 "BM_%d : EQ not created\n");
3360 status = be_mcc_queues_create(phba, phwi_context);
3364 status = mgmt_check_supported_fw(ctrl, phba);
3366 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3367 "BM_%d : Unsupported fw version\n");
3371 status = beiscsi_create_cqs(phba, phwi_context);
3373 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3374 "BM_%d : CQ not created\n");
3378 status = beiscsi_create_def_hdr(phba, phwi_context, phwi_ctrlr,
3381 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3382 "BM_%d : Default Header not created\n");
3386 status = beiscsi_create_def_data(phba, phwi_context,
3387 phwi_ctrlr, def_pdu_ring_sz);
3389 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3390 "BM_%d : Default Data not created\n");
3394 status = beiscsi_post_pages(phba);
3396 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3397 "BM_%d : Post SGL Pages Failed\n");
3401 status = beiscsi_create_wrb_rings(phba, phwi_context, phwi_ctrlr);
3403 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3404 "BM_%d : WRB Rings not created\n");
3408 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3409 "BM_%d : hwi_init_port success\n");
3413 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3414 "BM_%d : hwi_init_port failed");
3419 static int hwi_init_controller(struct beiscsi_hba *phba)
3421 struct hwi_controller *phwi_ctrlr;
3423 phwi_ctrlr = phba->phwi_ctrlr;
3424 if (1 == phba->init_mem[HWI_MEM_ADDN_CONTEXT].num_elements) {
3425 phwi_ctrlr->phwi_ctxt = (struct hwi_context_memory *)phba->
3426 init_mem[HWI_MEM_ADDN_CONTEXT].mem_array[0].virtual_address;
3427 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3428 "BM_%d : phwi_ctrlr->phwi_ctxt=%p\n",
3429 phwi_ctrlr->phwi_ctxt);
3431 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3432 "BM_%d : HWI_MEM_ADDN_CONTEXT is more "
3433 "than one element.Failing to load\n");
3437 iscsi_init_global_templates(phba);
3438 if (beiscsi_init_wrb_handle(phba))
3441 hwi_init_async_pdu_ctx(phba);
3442 if (hwi_init_port(phba) != 0) {
3443 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3444 "BM_%d : hwi_init_controller failed\n");
3451 static void beiscsi_free_mem(struct beiscsi_hba *phba)
3453 struct be_mem_descriptor *mem_descr;
3456 mem_descr = phba->init_mem;
3459 for (i = 0; i < SE_MEM_MAX; i++) {
3460 for (j = mem_descr->num_elements; j > 0; j--) {
3461 pci_free_consistent(phba->pcidev,
3462 mem_descr->mem_array[j - 1].size,
3463 mem_descr->mem_array[j - 1].virtual_address,
3464 (unsigned long)mem_descr->mem_array[j - 1].
3465 bus_address.u.a64.address);
3467 kfree(mem_descr->mem_array);
3470 kfree(phba->init_mem);
3471 kfree(phba->phwi_ctrlr);
3474 static int beiscsi_init_controller(struct beiscsi_hba *phba)
3478 ret = beiscsi_get_memory(phba);
3480 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3481 "BM_%d : beiscsi_dev_probe -"
3482 "Failed in beiscsi_alloc_memory\n");
3486 ret = hwi_init_controller(phba);
3489 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3490 "BM_%d : Return success from beiscsi_init_controller");
3495 beiscsi_free_mem(phba);
3499 static int beiscsi_init_sgl_handle(struct beiscsi_hba *phba)
3501 struct be_mem_descriptor *mem_descr_sglh, *mem_descr_sg;
3502 struct sgl_handle *psgl_handle;
3503 struct iscsi_sge *pfrag;
3504 unsigned int arr_index, i, idx;
3506 phba->io_sgl_hndl_avbl = 0;
3507 phba->eh_sgl_hndl_avbl = 0;
3509 mem_descr_sglh = phba->init_mem;
3510 mem_descr_sglh += HWI_MEM_SGLH;
3511 if (1 == mem_descr_sglh->num_elements) {
3512 phba->io_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
3513 phba->params.ios_per_ctrl,
3515 if (!phba->io_sgl_hndl_base) {
3516 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3517 "BM_%d : Mem Alloc Failed. Failing to load\n");
3520 phba->eh_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
3521 (phba->params.icds_per_ctrl -
3522 phba->params.ios_per_ctrl),
3524 if (!phba->eh_sgl_hndl_base) {
3525 kfree(phba->io_sgl_hndl_base);
3526 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3527 "BM_%d : Mem Alloc Failed. Failing to load\n");
3531 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3532 "BM_%d : HWI_MEM_SGLH is more than one element."
3533 "Failing to load\n");
3539 while (idx < mem_descr_sglh->num_elements) {
3540 psgl_handle = mem_descr_sglh->mem_array[idx].virtual_address;
3542 for (i = 0; i < (mem_descr_sglh->mem_array[idx].size /
3543 sizeof(struct sgl_handle)); i++) {
3544 if (arr_index < phba->params.ios_per_ctrl) {
3545 phba->io_sgl_hndl_base[arr_index] = psgl_handle;
3546 phba->io_sgl_hndl_avbl++;
3549 phba->eh_sgl_hndl_base[arr_index -
3550 phba->params.ios_per_ctrl] =
3553 phba->eh_sgl_hndl_avbl++;
3559 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3560 "BM_%d : phba->io_sgl_hndl_avbl=%d"
3561 "phba->eh_sgl_hndl_avbl=%d\n",
3562 phba->io_sgl_hndl_avbl,
3563 phba->eh_sgl_hndl_avbl);
3565 mem_descr_sg = phba->init_mem;
3566 mem_descr_sg += HWI_MEM_SGE;
3567 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3568 "\n BM_%d : mem_descr_sg->num_elements=%d\n",
3569 mem_descr_sg->num_elements);
3573 while (idx < mem_descr_sg->num_elements) {
3574 pfrag = mem_descr_sg->mem_array[idx].virtual_address;
3577 i < (mem_descr_sg->mem_array[idx].size) /
3578 (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io);
3580 if (arr_index < phba->params.ios_per_ctrl)
3581 psgl_handle = phba->io_sgl_hndl_base[arr_index];
3583 psgl_handle = phba->eh_sgl_hndl_base[arr_index -
3584 phba->params.ios_per_ctrl];
3585 psgl_handle->pfrag = pfrag;
3586 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, pfrag, 0);
3587 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, pfrag, 0);
3588 pfrag += phba->params.num_sge_per_io;
3589 psgl_handle->sgl_index =
3590 phba->fw_config.iscsi_icd_start + arr_index++;
3594 phba->io_sgl_free_index = 0;
3595 phba->io_sgl_alloc_index = 0;
3596 phba->eh_sgl_free_index = 0;
3597 phba->eh_sgl_alloc_index = 0;
3601 static int hba_setup_cid_tbls(struct beiscsi_hba *phba)
3605 phba->cid_array = kzalloc(sizeof(void *) * phba->params.cxns_per_ctrl,
3607 if (!phba->cid_array) {
3608 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3609 "BM_%d : Failed to allocate memory in "
3610 "hba_setup_cid_tbls\n");
3613 phba->ep_array = kzalloc(sizeof(struct iscsi_endpoint *) *
3614 phba->params.cxns_per_ctrl * 2, GFP_KERNEL);
3615 if (!phba->ep_array) {
3616 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3617 "BM_%d : Failed to allocate memory in "
3618 "hba_setup_cid_tbls\n");
3619 kfree(phba->cid_array);
3622 new_cid = phba->fw_config.iscsi_cid_start;
3623 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
3624 phba->cid_array[i] = new_cid;
3627 phba->avlbl_cids = phba->params.cxns_per_ctrl;
3631 static void hwi_enable_intr(struct beiscsi_hba *phba)
3633 struct be_ctrl_info *ctrl = &phba->ctrl;
3634 struct hwi_controller *phwi_ctrlr;
3635 struct hwi_context_memory *phwi_context;
3636 struct be_queue_info *eq;
3641 phwi_ctrlr = phba->phwi_ctrlr;
3642 phwi_context = phwi_ctrlr->phwi_ctxt;
3644 addr = (u8 __iomem *) ((u8 __iomem *) ctrl->pcicfg +
3645 PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET);
3646 reg = ioread32(addr);
3648 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
3650 reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
3651 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3652 "BM_%d : reg =x%08x addr=%p\n", reg, addr);
3653 iowrite32(reg, addr);
3656 if (!phba->msix_enabled) {
3657 eq = &phwi_context->be_eq[0].q;
3658 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3659 "BM_%d : eq->id=%d\n", eq->id);
3661 hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
3663 for (i = 0; i <= phba->num_cpus; i++) {
3664 eq = &phwi_context->be_eq[i].q;
3665 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3666 "BM_%d : eq->id=%d\n", eq->id);
3667 hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
3672 static void hwi_disable_intr(struct beiscsi_hba *phba)
3674 struct be_ctrl_info *ctrl = &phba->ctrl;
3676 u8 __iomem *addr = ctrl->pcicfg + PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET;
3677 u32 reg = ioread32(addr);
3679 u32 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
3681 reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
3682 iowrite32(reg, addr);
3684 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
3685 "BM_%d : In hwi_disable_intr, Already Disabled\n");
3689 * beiscsi_get_boot_info()- Get the boot session info
3690 * @phba: The device priv structure instance
3692 * Get the boot target info and store in driver priv structure
3696 * Failure: Non-Zero Value
3698 static int beiscsi_get_boot_info(struct beiscsi_hba *phba)
3700 struct be_cmd_get_session_resp *session_resp;
3701 struct be_mcc_wrb *wrb;
3702 struct be_dma_mem nonemb_cmd;
3703 unsigned int tag, wrb_num;
3704 unsigned short status, extd_status;
3705 unsigned int s_handle;
3706 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
3709 /* Get the session handle of the boot target */
3710 ret = be_mgmt_get_boot_shandle(phba, &s_handle);
3712 beiscsi_log(phba, KERN_ERR,
3713 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
3714 "BM_%d : No boot session\n");
3717 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
3718 sizeof(*session_resp),
3720 if (nonemb_cmd.va == NULL) {
3721 beiscsi_log(phba, KERN_ERR,
3722 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
3723 "BM_%d : Failed to allocate memory for"
3724 "beiscsi_get_session_info\n");
3729 memset(nonemb_cmd.va, 0, sizeof(*session_resp));
3730 tag = mgmt_get_session_info(phba, s_handle,
3733 beiscsi_log(phba, KERN_ERR,
3734 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
3735 "BM_%d : beiscsi_get_session_info"
3740 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
3741 phba->ctrl.mcc_numtag[tag]);
3743 wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
3744 extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
3745 status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
3746 if (status || extd_status) {
3747 beiscsi_log(phba, KERN_ERR,
3748 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
3749 "BM_%d : beiscsi_get_session_info Failed"
3750 " status = %d extd_status = %d\n",
3751 status, extd_status);
3753 free_mcc_tag(&phba->ctrl, tag);
3756 wrb = queue_get_wrb(mccq, wrb_num);
3757 free_mcc_tag(&phba->ctrl, tag);
3758 session_resp = nonemb_cmd.va ;
3760 memcpy(&phba->boot_sess, &session_resp->session_info,
3761 sizeof(struct mgmt_session_info));
3765 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
3766 nonemb_cmd.va, nonemb_cmd.dma);
3770 static void beiscsi_boot_release(void *data)
3772 struct beiscsi_hba *phba = data;
3774 scsi_host_put(phba->shost);
3777 static int beiscsi_setup_boot_info(struct beiscsi_hba *phba)
3779 struct iscsi_boot_kobj *boot_kobj;
3781 /* get boot info using mgmt cmd */
3782 if (beiscsi_get_boot_info(phba))
3783 /* Try to see if we can carry on without this */
3786 phba->boot_kset = iscsi_boot_create_host_kset(phba->shost->host_no);
3787 if (!phba->boot_kset)
3790 /* get a ref because the show function will ref the phba */
3791 if (!scsi_host_get(phba->shost))
3793 boot_kobj = iscsi_boot_create_target(phba->boot_kset, 0, phba,
3794 beiscsi_show_boot_tgt_info,
3795 beiscsi_tgt_get_attr_visibility,
3796 beiscsi_boot_release);
3800 if (!scsi_host_get(phba->shost))
3802 boot_kobj = iscsi_boot_create_initiator(phba->boot_kset, 0, phba,
3803 beiscsi_show_boot_ini_info,
3804 beiscsi_ini_get_attr_visibility,
3805 beiscsi_boot_release);
3809 if (!scsi_host_get(phba->shost))
3811 boot_kobj = iscsi_boot_create_ethernet(phba->boot_kset, 0, phba,
3812 beiscsi_show_boot_eth_info,
3813 beiscsi_eth_get_attr_visibility,
3814 beiscsi_boot_release);
3820 scsi_host_put(phba->shost);
3822 iscsi_boot_destroy_kset(phba->boot_kset);
3826 static int beiscsi_init_port(struct beiscsi_hba *phba)
3830 ret = beiscsi_init_controller(phba);
3832 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3833 "BM_%d : beiscsi_dev_probe - Failed in"
3834 "beiscsi_init_controller\n");
3837 ret = beiscsi_init_sgl_handle(phba);
3839 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3840 "BM_%d : beiscsi_dev_probe - Failed in"
3841 "beiscsi_init_sgl_handle\n");
3842 goto do_cleanup_ctrlr;
3845 if (hba_setup_cid_tbls(phba)) {
3846 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3847 "BM_%d : Failed in hba_setup_cid_tbls\n");
3848 kfree(phba->io_sgl_hndl_base);
3849 kfree(phba->eh_sgl_hndl_base);
3850 goto do_cleanup_ctrlr;
3860 static void hwi_purge_eq(struct beiscsi_hba *phba)
3862 struct hwi_controller *phwi_ctrlr;
3863 struct hwi_context_memory *phwi_context;
3864 struct be_queue_info *eq;
3865 struct be_eq_entry *eqe = NULL;
3867 unsigned int num_processed;
3869 phwi_ctrlr = phba->phwi_ctrlr;
3870 phwi_context = phwi_ctrlr->phwi_ctxt;
3871 if (phba->msix_enabled)
3876 for (i = 0; i < (phba->num_cpus + eq_msix); i++) {
3877 eq = &phwi_context->be_eq[i].q;
3878 eqe = queue_tail_node(eq);
3880 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
3882 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
3884 eqe = queue_tail_node(eq);
3889 hwi_ring_eq_db(phba, eq->id, 1, num_processed, 1, 1);
3893 static void beiscsi_clean_port(struct beiscsi_hba *phba)
3897 mgmt_status = mgmt_epfw_cleanup(phba, CMD_CONNECTION_CHUTE_0);
3899 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
3900 "BM_%d : mgmt_epfw_cleanup FAILED\n");
3904 kfree(phba->io_sgl_hndl_base);
3905 kfree(phba->eh_sgl_hndl_base);
3906 kfree(phba->cid_array);
3907 kfree(phba->ep_array);
3911 * beiscsi_cleanup_task()- Free driver resources of the task
3912 * @task: ptr to the iscsi task
3915 static void beiscsi_cleanup_task(struct iscsi_task *task)
3917 struct beiscsi_io_task *io_task = task->dd_data;
3918 struct iscsi_conn *conn = task->conn;
3919 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
3920 struct beiscsi_hba *phba = beiscsi_conn->phba;
3921 struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
3922 struct hwi_wrb_context *pwrb_context;
3923 struct hwi_controller *phwi_ctrlr;
3925 phwi_ctrlr = phba->phwi_ctrlr;
3926 pwrb_context = &phwi_ctrlr->wrb_context[beiscsi_conn->beiscsi_conn_cid
3927 - phba->fw_config.iscsi_cid_start];
3929 if (io_task->cmd_bhs) {
3930 pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
3931 io_task->bhs_pa.u.a64.address);
3932 io_task->cmd_bhs = NULL;
3936 if (io_task->pwrb_handle) {
3937 free_wrb_handle(phba, pwrb_context,
3938 io_task->pwrb_handle);
3939 io_task->pwrb_handle = NULL;
3942 if (io_task->psgl_handle) {
3943 spin_lock(&phba->io_sgl_lock);
3944 free_io_sgl_handle(phba, io_task->psgl_handle);
3945 spin_unlock(&phba->io_sgl_lock);
3946 io_task->psgl_handle = NULL;
3949 if (!beiscsi_conn->login_in_progress) {
3950 if (io_task->pwrb_handle) {
3951 free_wrb_handle(phba, pwrb_context,
3952 io_task->pwrb_handle);
3953 io_task->pwrb_handle = NULL;
3955 if (io_task->psgl_handle) {
3956 spin_lock(&phba->mgmt_sgl_lock);
3957 free_mgmt_sgl_handle(phba,
3958 io_task->psgl_handle);
3959 spin_unlock(&phba->mgmt_sgl_lock);
3960 io_task->psgl_handle = NULL;
3962 if (io_task->mtask_addr) {
3963 pci_unmap_single(phba->pcidev,
3964 io_task->mtask_addr,
3965 io_task->mtask_data_count,
3967 io_task->mtask_addr = 0;
3974 beiscsi_offload_connection(struct beiscsi_conn *beiscsi_conn,
3975 struct beiscsi_offload_params *params)
3977 struct wrb_handle *pwrb_handle;
3978 struct iscsi_target_context_update_wrb *pwrb = NULL;
3979 struct be_mem_descriptor *mem_descr;
3980 struct beiscsi_hba *phba = beiscsi_conn->phba;
3981 struct iscsi_task *task = beiscsi_conn->task;
3982 struct iscsi_session *session = task->conn->session;
3986 * We can always use 0 here because it is reserved by libiscsi for
3987 * login/startup related tasks.
3989 beiscsi_conn->login_in_progress = 0;
3990 spin_lock_bh(&session->lock);
3991 beiscsi_cleanup_task(task);
3992 spin_unlock_bh(&session->lock);
3994 pwrb_handle = alloc_wrb_handle(phba, (beiscsi_conn->beiscsi_conn_cid -
3995 phba->fw_config.iscsi_cid_start));
3996 pwrb = (struct iscsi_target_context_update_wrb *)pwrb_handle->pwrb;
3997 memset(pwrb, 0, sizeof(*pwrb));
3998 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
3999 max_burst_length, pwrb, params->dw[offsetof
4000 (struct amap_beiscsi_offload_params,
4001 max_burst_length) / 32]);
4002 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
4003 max_send_data_segment_length, pwrb,
4004 params->dw[offsetof(struct amap_beiscsi_offload_params,
4005 max_send_data_segment_length) / 32]);
4006 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
4009 params->dw[offsetof(struct amap_beiscsi_offload_params,
4010 first_burst_length) / 32]);
4012 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, erl, pwrb,
4013 (params->dw[offsetof(struct amap_beiscsi_offload_params,
4014 erl) / 32] & OFFLD_PARAMS_ERL));
4015 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, dde, pwrb,
4016 (params->dw[offsetof(struct amap_beiscsi_offload_params,
4017 dde) / 32] & OFFLD_PARAMS_DDE) >> 2);
4018 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, hde, pwrb,
4019 (params->dw[offsetof(struct amap_beiscsi_offload_params,
4020 hde) / 32] & OFFLD_PARAMS_HDE) >> 3);
4021 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, ir2t, pwrb,
4022 (params->dw[offsetof(struct amap_beiscsi_offload_params,
4023 ir2t) / 32] & OFFLD_PARAMS_IR2T) >> 4);
4024 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, imd, pwrb,
4025 (params->dw[offsetof(struct amap_beiscsi_offload_params,
4026 imd) / 32] & OFFLD_PARAMS_IMD) >> 5);
4027 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, stat_sn,
4029 (params->dw[offsetof(struct amap_beiscsi_offload_params,
4030 exp_statsn) / 32] + 1));
4031 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, type, pwrb,
4033 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, wrb_idx,
4034 pwrb, pwrb_handle->wrb_index);
4035 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, ptr2nextwrb,
4036 pwrb, pwrb_handle->nxt_wrb_index);
4037 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
4038 session_state, pwrb, 0);
4039 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, compltonack,
4041 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, notpredblq,
4043 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, mode, pwrb,
4046 mem_descr = phba->init_mem;
4047 mem_descr += ISCSI_MEM_GLOBAL_HEADER;
4049 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
4050 pad_buffer_addr_hi, pwrb,
4051 mem_descr->mem_array[0].bus_address.u.a32.address_hi);
4052 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
4053 pad_buffer_addr_lo, pwrb,
4054 mem_descr->mem_array[0].bus_address.u.a32.address_lo);
4056 be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_target_context_update_wrb));
4058 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
4059 doorbell |= (pwrb_handle->wrb_index & DB_DEF_PDU_WRB_INDEX_MASK)
4060 << DB_DEF_PDU_WRB_INDEX_SHIFT;
4061 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
4063 iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
4066 static void beiscsi_parse_pdu(struct iscsi_conn *conn, itt_t itt,
4067 int *index, int *age)
4071 *age = conn->session->age;
4075 * beiscsi_alloc_pdu - allocates pdu and related resources
4076 * @task: libiscsi task
4077 * @opcode: opcode of pdu for task
4079 * This is called with the session lock held. It will allocate
4080 * the wrb and sgl if needed for the command. And it will prep
4081 * the pdu's itt. beiscsi_parse_pdu will later translate
4082 * the pdu itt to the libiscsi task itt.
4084 static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
4086 struct beiscsi_io_task *io_task = task->dd_data;
4087 struct iscsi_conn *conn = task->conn;
4088 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4089 struct beiscsi_hba *phba = beiscsi_conn->phba;
4090 struct hwi_wrb_context *pwrb_context;
4091 struct hwi_controller *phwi_ctrlr;
4093 struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
4096 io_task->cmd_bhs = pci_pool_alloc(beiscsi_sess->bhs_pool,
4097 GFP_ATOMIC, &paddr);
4098 if (!io_task->cmd_bhs)
4100 io_task->bhs_pa.u.a64.address = paddr;
4101 io_task->libiscsi_itt = (itt_t)task->itt;
4102 io_task->conn = beiscsi_conn;
4104 task->hdr = (struct iscsi_hdr *)&io_task->cmd_bhs->iscsi_hdr;
4105 task->hdr_max = sizeof(struct be_cmd_bhs);
4106 io_task->psgl_handle = NULL;
4107 io_task->pwrb_handle = NULL;
4110 spin_lock(&phba->io_sgl_lock);
4111 io_task->psgl_handle = alloc_io_sgl_handle(phba);
4112 spin_unlock(&phba->io_sgl_lock);
4113 if (!io_task->psgl_handle)
4115 io_task->pwrb_handle = alloc_wrb_handle(phba,
4116 beiscsi_conn->beiscsi_conn_cid -
4117 phba->fw_config.iscsi_cid_start);
4118 if (!io_task->pwrb_handle)
4121 io_task->scsi_cmnd = NULL;
4122 if ((opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN) {
4123 if (!beiscsi_conn->login_in_progress) {
4124 spin_lock(&phba->mgmt_sgl_lock);
4125 io_task->psgl_handle = (struct sgl_handle *)
4126 alloc_mgmt_sgl_handle(phba);
4127 spin_unlock(&phba->mgmt_sgl_lock);
4128 if (!io_task->psgl_handle)
4131 beiscsi_conn->login_in_progress = 1;
4132 beiscsi_conn->plogin_sgl_handle =
4133 io_task->psgl_handle;
4134 io_task->pwrb_handle =
4135 alloc_wrb_handle(phba,
4136 beiscsi_conn->beiscsi_conn_cid -
4137 phba->fw_config.iscsi_cid_start);
4138 if (!io_task->pwrb_handle)
4140 beiscsi_conn->plogin_wrb_handle =
4141 io_task->pwrb_handle;
4144 io_task->psgl_handle =
4145 beiscsi_conn->plogin_sgl_handle;
4146 io_task->pwrb_handle =
4147 beiscsi_conn->plogin_wrb_handle;
4149 beiscsi_conn->task = task;
4151 spin_lock(&phba->mgmt_sgl_lock);
4152 io_task->psgl_handle = alloc_mgmt_sgl_handle(phba);
4153 spin_unlock(&phba->mgmt_sgl_lock);
4154 if (!io_task->psgl_handle)
4156 io_task->pwrb_handle =
4157 alloc_wrb_handle(phba,
4158 beiscsi_conn->beiscsi_conn_cid -
4159 phba->fw_config.iscsi_cid_start);
4160 if (!io_task->pwrb_handle)
4161 goto free_mgmt_hndls;
4165 itt = (itt_t) cpu_to_be32(((unsigned int)io_task->pwrb_handle->
4166 wrb_index << 16) | (unsigned int)
4167 (io_task->psgl_handle->sgl_index));
4168 io_task->pwrb_handle->pio_handle = task;
4170 io_task->cmd_bhs->iscsi_hdr.itt = itt;
4174 spin_lock(&phba->io_sgl_lock);
4175 free_io_sgl_handle(phba, io_task->psgl_handle);
4176 spin_unlock(&phba->io_sgl_lock);
4179 spin_lock(&phba->mgmt_sgl_lock);
4180 free_mgmt_sgl_handle(phba, io_task->psgl_handle);
4181 spin_unlock(&phba->mgmt_sgl_lock);
4183 phwi_ctrlr = phba->phwi_ctrlr;
4184 pwrb_context = &phwi_ctrlr->wrb_context[
4185 beiscsi_conn->beiscsi_conn_cid -
4186 phba->fw_config.iscsi_cid_start];
4187 if (io_task->pwrb_handle)
4188 free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle);
4189 io_task->pwrb_handle = NULL;
4190 pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
4191 io_task->bhs_pa.u.a64.address);
4192 io_task->cmd_bhs = NULL;
4193 beiscsi_log(phba, KERN_ERR,
4194 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
4195 "BM_%d : Alloc of SGL_ICD Failed\n");
4199 static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg,
4200 unsigned int num_sg, unsigned int xferlen,
4201 unsigned int writedir)
4204 struct beiscsi_io_task *io_task = task->dd_data;
4205 struct iscsi_conn *conn = task->conn;
4206 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4207 struct beiscsi_hba *phba = beiscsi_conn->phba;
4208 struct iscsi_wrb *pwrb = NULL;
4209 unsigned int doorbell = 0;
4211 pwrb = io_task->pwrb_handle->pwrb;
4212 io_task->cmd_bhs->iscsi_hdr.exp_statsn = 0;
4213 io_task->bhs_len = sizeof(struct be_cmd_bhs);
4216 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4218 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1);
4220 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4222 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
4225 AMAP_SET_BITS(struct amap_iscsi_wrb, lun, pwrb,
4226 cpu_to_be16(*(unsigned short *)
4227 &io_task->cmd_bhs->iscsi_hdr.lun));
4228 AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, xferlen);
4229 AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
4230 io_task->pwrb_handle->wrb_index);
4231 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
4232 be32_to_cpu(task->cmdsn));
4233 AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
4234 io_task->psgl_handle->sgl_index);
4236 hwi_write_sgl(pwrb, sg, num_sg, io_task);
4238 AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
4239 io_task->pwrb_handle->nxt_wrb_index);
4240 be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
4242 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
4243 doorbell |= (io_task->pwrb_handle->wrb_index &
4244 DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
4245 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
4247 iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
4251 static int beiscsi_mtask(struct iscsi_task *task)
4253 struct beiscsi_io_task *io_task = task->dd_data;
4254 struct iscsi_conn *conn = task->conn;
4255 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4256 struct beiscsi_hba *phba = beiscsi_conn->phba;
4257 struct iscsi_wrb *pwrb = NULL;
4258 unsigned int doorbell = 0;
4261 cid = beiscsi_conn->beiscsi_conn_cid;
4262 pwrb = io_task->pwrb_handle->pwrb;
4263 memset(pwrb, 0, sizeof(*pwrb));
4264 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
4265 be32_to_cpu(task->cmdsn));
4266 AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
4267 io_task->pwrb_handle->wrb_index);
4268 AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
4269 io_task->psgl_handle->sgl_index);
4271 switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
4272 case ISCSI_OP_LOGIN:
4273 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4275 AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
4276 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, 1);
4277 hwi_write_buffer(pwrb, task);
4279 case ISCSI_OP_NOOP_OUT:
4280 if (task->hdr->ttt != ISCSI_RESERVED_TAG) {
4281 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4283 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt,
4285 AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 1);
4287 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4289 AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
4291 hwi_write_buffer(pwrb, task);
4294 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4296 AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
4297 hwi_write_buffer(pwrb, task);
4299 case ISCSI_OP_SCSI_TMFUNC:
4300 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4302 AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
4303 hwi_write_buffer(pwrb, task);
4305 case ISCSI_OP_LOGOUT:
4306 AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
4307 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4309 hwi_write_buffer(pwrb, task);
4313 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
4314 "BM_%d : opcode =%d Not supported\n",
4315 task->hdr->opcode & ISCSI_OPCODE_MASK);
4320 AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb,
4322 AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
4323 io_task->pwrb_handle->nxt_wrb_index);
4324 be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
4326 doorbell |= cid & DB_WRB_POST_CID_MASK;
4327 doorbell |= (io_task->pwrb_handle->wrb_index &
4328 DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
4329 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
4330 iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
4334 static int beiscsi_task_xmit(struct iscsi_task *task)
4336 struct beiscsi_io_task *io_task = task->dd_data;
4337 struct scsi_cmnd *sc = task->sc;
4338 struct scatterlist *sg;
4340 unsigned int writedir = 0, xferlen = 0;
4343 return beiscsi_mtask(task);
4345 io_task->scsi_cmnd = sc;
4346 num_sg = scsi_dma_map(sc);
4348 struct iscsi_conn *conn = task->conn;
4349 struct beiscsi_hba *phba = NULL;
4351 phba = ((struct beiscsi_conn *)conn->dd_data)->phba;
4352 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_IO,
4353 "BM_%d : scsi_dma_map Failed\n");
4357 xferlen = scsi_bufflen(sc);
4358 sg = scsi_sglist(sc);
4359 if (sc->sc_data_direction == DMA_TO_DEVICE)
4364 return beiscsi_iotask(task, sg, num_sg, xferlen, writedir);
4368 * beiscsi_bsg_request - handle bsg request from ISCSI transport
4369 * @job: job to handle
4371 static int beiscsi_bsg_request(struct bsg_job *job)
4373 struct Scsi_Host *shost;
4374 struct beiscsi_hba *phba;
4375 struct iscsi_bsg_request *bsg_req = job->request;
4378 struct be_dma_mem nonemb_cmd;
4379 struct be_cmd_resp_hdr *resp;
4380 struct iscsi_bsg_reply *bsg_reply = job->reply;
4381 unsigned short status, extd_status;
4383 shost = iscsi_job_to_shost(job);
4384 phba = iscsi_host_priv(shost);
4386 switch (bsg_req->msgcode) {
4387 case ISCSI_BSG_HST_VENDOR:
4388 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
4389 job->request_payload.payload_len,
4391 if (nonemb_cmd.va == NULL) {
4392 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
4393 "BM_%d : Failed to allocate memory for "
4394 "beiscsi_bsg_request\n");
4397 tag = mgmt_vendor_specific_fw_cmd(&phba->ctrl, phba, job,
4400 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
4401 "BM_%d : be_cmd_get_mac_addr Failed\n");
4403 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
4404 nonemb_cmd.va, nonemb_cmd.dma);
4407 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
4408 phba->ctrl.mcc_numtag[tag]);
4409 extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
4410 status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
4411 free_mcc_tag(&phba->ctrl, tag);
4412 resp = (struct be_cmd_resp_hdr *)nonemb_cmd.va;
4413 sg_copy_from_buffer(job->reply_payload.sg_list,
4414 job->reply_payload.sg_cnt,
4415 nonemb_cmd.va, (resp->response_length
4417 bsg_reply->reply_payload_rcv_len = resp->response_length;
4418 bsg_reply->result = status;
4419 bsg_job_done(job, bsg_reply->result,
4420 bsg_reply->reply_payload_rcv_len);
4421 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
4422 nonemb_cmd.va, nonemb_cmd.dma);
4423 if (status || extd_status) {
4424 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
4425 "BM_%d : be_cmd_get_mac_addr Failed"
4426 " status = %d extd_status = %d\n",
4427 status, extd_status);
4434 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
4435 "BM_%d : Unsupported bsg command: 0x%x\n",
4443 void beiscsi_hba_attrs_init(struct beiscsi_hba *phba)
4445 /* Set the logging parameter */
4446 beiscsi_log_enable_init(phba, beiscsi_log_enable);
4449 static void beiscsi_quiesce(struct beiscsi_hba *phba)
4451 struct hwi_controller *phwi_ctrlr;
4452 struct hwi_context_memory *phwi_context;
4453 struct be_eq_obj *pbe_eq;
4454 unsigned int i, msix_vec;
4455 u8 *real_offset = 0;
4458 phwi_ctrlr = phba->phwi_ctrlr;
4459 phwi_context = phwi_ctrlr->phwi_ctxt;
4460 hwi_disable_intr(phba);
4461 if (phba->msix_enabled) {
4462 for (i = 0; i <= phba->num_cpus; i++) {
4463 msix_vec = phba->msix_entries[i].vector;
4464 free_irq(msix_vec, &phwi_context->be_eq[i]);
4465 kfree(phba->msi_name[i]);
4468 if (phba->pcidev->irq)
4469 free_irq(phba->pcidev->irq, phba);
4470 pci_disable_msix(phba->pcidev);
4471 destroy_workqueue(phba->wq);
4472 if (blk_iopoll_enabled)
4473 for (i = 0; i < phba->num_cpus; i++) {
4474 pbe_eq = &phwi_context->be_eq[i];
4475 blk_iopoll_disable(&pbe_eq->iopoll);
4478 beiscsi_clean_port(phba);
4479 beiscsi_free_mem(phba);
4480 real_offset = (u8 *)phba->csr_va + MPU_EP_SEMAPHORE;
4482 value = readl((void *)real_offset);
4484 if (value & 0x00010000) {
4485 value &= 0xfffeffff;
4486 writel(value, (void *)real_offset);
4488 beiscsi_unmap_pci_function(phba);
4489 pci_free_consistent(phba->pcidev,
4490 phba->ctrl.mbox_mem_alloced.size,
4491 phba->ctrl.mbox_mem_alloced.va,
4492 phba->ctrl.mbox_mem_alloced.dma);
4495 static void beiscsi_remove(struct pci_dev *pcidev)
4498 struct beiscsi_hba *phba = NULL;
4500 phba = pci_get_drvdata(pcidev);
4502 dev_err(&pcidev->dev, "beiscsi_remove called with no phba\n");
4506 beiscsi_destroy_def_ifaces(phba);
4507 beiscsi_quiesce(phba);
4508 iscsi_boot_destroy_kset(phba->boot_kset);
4509 iscsi_host_remove(phba->shost);
4510 pci_dev_put(phba->pcidev);
4511 iscsi_host_free(phba->shost);
4512 pci_disable_device(pcidev);
4515 static void beiscsi_shutdown(struct pci_dev *pcidev)
4518 struct beiscsi_hba *phba = NULL;
4520 phba = (struct beiscsi_hba *)pci_get_drvdata(pcidev);
4522 dev_err(&pcidev->dev, "beiscsi_shutdown called with no phba\n");
4526 beiscsi_quiesce(phba);
4527 pci_disable_device(pcidev);
4530 static void beiscsi_msix_enable(struct beiscsi_hba *phba)
4534 for (i = 0; i <= phba->num_cpus; i++)
4535 phba->msix_entries[i].entry = i;
4537 status = pci_enable_msix(phba->pcidev, phba->msix_entries,
4538 (phba->num_cpus + 1));
4540 phba->msix_enabled = true;
4545 static int __devinit beiscsi_dev_probe(struct pci_dev *pcidev,
4546 const struct pci_device_id *id)
4548 struct beiscsi_hba *phba = NULL;
4549 struct hwi_controller *phwi_ctrlr;
4550 struct hwi_context_memory *phwi_context;
4551 struct be_eq_obj *pbe_eq;
4553 u8 *real_offset = 0;
4556 ret = beiscsi_enable_pci(pcidev);
4558 dev_err(&pcidev->dev,
4559 "beiscsi_dev_probe - Failed to enable pci device\n");
4563 phba = beiscsi_hba_alloc(pcidev);
4565 dev_err(&pcidev->dev,
4566 "beiscsi_dev_probe - Failed in beiscsi_hba_alloc\n");
4570 /* Initialize Driver configuration Paramters */
4571 beiscsi_hba_attrs_init(phba);
4573 switch (pcidev->device) {
4577 phba->generation = BE_GEN2;
4581 phba->generation = BE_GEN3;
4584 phba->generation = 0;
4588 find_num_cpus(phba);
4592 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4593 "BM_%d : num_cpus = %d\n",
4597 beiscsi_msix_enable(phba);
4598 if (!phba->msix_enabled)
4601 ret = be_ctrl_init(phba, pcidev);
4603 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4604 "BM_%d : beiscsi_dev_probe-"
4605 "Failed in be_ctrl_init\n");
4610 real_offset = (u8 *)phba->csr_va + MPU_EP_SEMAPHORE;
4611 value = readl((void *)real_offset);
4612 if (value & 0x00010000) {
4614 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4615 "BM_%d : Loading Driver in crashdump mode\n");
4616 ret = beiscsi_cmd_reset_function(phba);
4618 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4619 "BM_%d : Reset Failed. Aborting Crashdump\n");
4622 ret = be_chk_reset_complete(phba);
4624 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4625 "BM_%d : Failed to get out of reset."
4626 "Aborting Crashdump\n");
4630 value |= 0x00010000;
4631 writel(value, (void *)real_offset);
4636 spin_lock_init(&phba->io_sgl_lock);
4637 spin_lock_init(&phba->mgmt_sgl_lock);
4638 spin_lock_init(&phba->isr_lock);
4639 ret = mgmt_get_fw_config(&phba->ctrl, phba);
4641 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4642 "BM_%d : Error getting fw config\n");
4645 phba->shost->max_id = phba->fw_config.iscsi_cid_count;
4646 beiscsi_get_params(phba);
4647 phba->shost->can_queue = phba->params.ios_per_ctrl;
4648 ret = beiscsi_init_port(phba);
4650 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4651 "BM_%d : beiscsi_dev_probe-"
4652 "Failed in beiscsi_init_port\n");
4656 for (i = 0; i < MAX_MCC_CMD ; i++) {
4657 init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]);
4658 phba->ctrl.mcc_tag[i] = i + 1;
4659 phba->ctrl.mcc_numtag[i + 1] = 0;
4660 phba->ctrl.mcc_tag_available++;
4663 phba->ctrl.mcc_alloc_index = phba->ctrl.mcc_free_index = 0;
4665 snprintf(phba->wq_name, sizeof(phba->wq_name), "beiscsi_q_irq%u",
4666 phba->shost->host_no);
4667 phba->wq = alloc_workqueue(phba->wq_name, WQ_MEM_RECLAIM, 1);
4669 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4670 "BM_%d : beiscsi_dev_probe-"
4671 "Failed to allocate work queue\n");
4675 INIT_WORK(&phba->work_cqs, beiscsi_process_all_cqs);
4677 phwi_ctrlr = phba->phwi_ctrlr;
4678 phwi_context = phwi_ctrlr->phwi_ctxt;
4679 if (blk_iopoll_enabled) {
4680 for (i = 0; i < phba->num_cpus; i++) {
4681 pbe_eq = &phwi_context->be_eq[i];
4682 blk_iopoll_init(&pbe_eq->iopoll, be_iopoll_budget,
4684 blk_iopoll_enable(&pbe_eq->iopoll);
4687 ret = beiscsi_init_irqs(phba);
4689 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4690 "BM_%d : beiscsi_dev_probe-"
4691 "Failed to beiscsi_init_irqs\n");
4694 hwi_enable_intr(phba);
4696 if (beiscsi_setup_boot_info(phba))
4698 * log error but continue, because we may not be using
4701 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4702 "BM_%d : Could not set up "
4703 "iSCSI boot info.\n");
4705 beiscsi_create_def_ifaces(phba);
4706 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4707 "\n\n\n BM_%d : SUCCESS - DRIVER LOADED\n\n\n");
4711 destroy_workqueue(phba->wq);
4712 if (blk_iopoll_enabled)
4713 for (i = 0; i < phba->num_cpus; i++) {
4714 pbe_eq = &phwi_context->be_eq[i];
4715 blk_iopoll_disable(&pbe_eq->iopoll);
4718 beiscsi_clean_port(phba);
4719 beiscsi_free_mem(phba);
4721 real_offset = (u8 *)phba->csr_va + MPU_EP_SEMAPHORE;
4723 value = readl((void *)real_offset);
4725 if (value & 0x00010000) {
4726 value &= 0xfffeffff;
4727 writel(value, (void *)real_offset);
4730 pci_free_consistent(phba->pcidev,
4731 phba->ctrl.mbox_mem_alloced.size,
4732 phba->ctrl.mbox_mem_alloced.va,
4733 phba->ctrl.mbox_mem_alloced.dma);
4734 beiscsi_unmap_pci_function(phba);
4736 if (phba->msix_enabled)
4737 pci_disable_msix(phba->pcidev);
4738 iscsi_host_remove(phba->shost);
4739 pci_dev_put(phba->pcidev);
4740 iscsi_host_free(phba->shost);
4742 pci_disable_device(pcidev);
4746 struct iscsi_transport beiscsi_iscsi_transport = {
4747 .owner = THIS_MODULE,
4749 .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_TEXT_NEGO |
4750 CAP_MULTI_R2T | CAP_DATADGST | CAP_DATA_PATH_OFFLOAD,
4751 .create_session = beiscsi_session_create,
4752 .destroy_session = beiscsi_session_destroy,
4753 .create_conn = beiscsi_conn_create,
4754 .bind_conn = beiscsi_conn_bind,
4755 .destroy_conn = iscsi_conn_teardown,
4756 .attr_is_visible = be2iscsi_attr_is_visible,
4757 .set_iface_param = be2iscsi_iface_set_param,
4758 .get_iface_param = be2iscsi_iface_get_param,
4759 .set_param = beiscsi_set_param,
4760 .get_conn_param = iscsi_conn_get_param,
4761 .get_session_param = iscsi_session_get_param,
4762 .get_host_param = beiscsi_get_host_param,
4763 .start_conn = beiscsi_conn_start,
4764 .stop_conn = iscsi_conn_stop,
4765 .send_pdu = iscsi_conn_send_pdu,
4766 .xmit_task = beiscsi_task_xmit,
4767 .cleanup_task = beiscsi_cleanup_task,
4768 .alloc_pdu = beiscsi_alloc_pdu,
4769 .parse_pdu_itt = beiscsi_parse_pdu,
4770 .get_stats = beiscsi_conn_get_stats,
4771 .get_ep_param = beiscsi_ep_get_param,
4772 .ep_connect = beiscsi_ep_connect,
4773 .ep_poll = beiscsi_ep_poll,
4774 .ep_disconnect = beiscsi_ep_disconnect,
4775 .session_recovery_timedout = iscsi_session_recovery_timedout,
4776 .bsg_request = beiscsi_bsg_request,
4779 static struct pci_driver beiscsi_pci_driver = {
4781 .probe = beiscsi_dev_probe,
4782 .remove = beiscsi_remove,
4783 .shutdown = beiscsi_shutdown,
4784 .id_table = beiscsi_pci_id_table
4788 static int __init beiscsi_module_init(void)
4792 beiscsi_scsi_transport =
4793 iscsi_register_transport(&beiscsi_iscsi_transport);
4794 if (!beiscsi_scsi_transport) {
4796 "beiscsi_module_init - Unable to register beiscsi transport.\n");
4799 printk(KERN_INFO "In beiscsi_module_init, tt=%p\n",
4800 &beiscsi_iscsi_transport);
4802 ret = pci_register_driver(&beiscsi_pci_driver);
4805 "beiscsi_module_init - Unable to register beiscsi pci driver.\n");
4806 goto unregister_iscsi_transport;
4810 unregister_iscsi_transport:
4811 iscsi_unregister_transport(&beiscsi_iscsi_transport);
4815 static void __exit beiscsi_module_exit(void)
4817 pci_unregister_driver(&beiscsi_pci_driver);
4818 iscsi_unregister_transport(&beiscsi_iscsi_transport);
4821 module_init(beiscsi_module_init);
4822 module_exit(beiscsi_module_exit);