20 #include <linux/reboot.h>
22 #include <linux/slab.h>
25 #include <linux/pci.h>
26 #include <linux/string.h>
27 #include <linux/kernel.h>
30 #include <linux/module.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;
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)
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");
157 &dev_attr_beiscsi_log_enable,
161 static int beiscsi_slave_configure(
struct scsi_device *sdev)
178 unsigned int cid,
tag, num_invalidate;
181 session = cls_session->
dd_data;
183 spin_lock_bh(&session->lock);
184 if (!aborted_task || !aborted_task->
sc) {
186 spin_unlock_bh(&session->lock);
190 aborted_io_task = aborted_task->
dd_data;
191 if (!aborted_io_task->scsi_cmnd) {
193 spin_unlock_bh(&session->lock);
196 spin_unlock_bh(&session->lock);
203 inv_tbl = phba->inv_tbl;
204 memset(inv_tbl, 0x0,
sizeof(*inv_tbl));
206 inv_tbl->icd = aborted_io_task->psgl_handle->sgl_index;
211 if (nonemb_cmd.va ==
NULL) {
213 "BM_%d : Failed to allocate memory for"
214 "mgmt_invalidate_icds\n");
223 "BM_%d : mgmt_invalidate_icds could not be"
226 nonemb_cmd.va, nonemb_cmd.dma);
231 phba->ctrl.mcc_numtag[
tag]);
235 nonemb_cmd.va, nonemb_cmd.dma);
239 static int beiscsi_eh_device_reset(
struct scsi_cmnd *sc)
250 unsigned int cid,
tag,
i, num_invalidate;
254 session = cls_session->
dd_data;
255 spin_lock_bh(&session->
lock);
257 spin_unlock_bh(&session->
lock);
262 phba = beiscsi_conn->
phba;
267 for (i = 0; i < conn->
session->cmds_max; i++) {
269 abrt_io_task = abrt_task->
dd_data;
273 if (abrt_task->
sc->device->lun != abrt_task->
sc->device->lun)
281 spin_unlock_bh(&session->
lock);
287 if (nonemb_cmd.va ==
NULL) {
289 "BM_%d : Failed to allocate memory for"
290 "mgmt_invalidate_icds\n");
294 memset(nonemb_cmd.va, 0, nonemb_cmd.size);
299 "BM_%d : mgmt_invalidate_icds could not be"
302 nonemb_cmd.va, nonemb_cmd.dma);
306 phba->
ctrl.mcc_numtag[tag]);
310 nonemb_cmd.va, nonemb_cmd.dma);
343 target_chap_name_length,
345 auth_data.chap.target_chap_name);
350 target_secret_length,
352 auth_data.chap.target_secret);
357 intr_chap_name_length,
359 auth_data.chap.intr_chap_name);
366 auth_data.chap.intr_secret);
381 static ssize_t beiscsi_show_boot_ini_info(
void *data,
int type,
char *buf)
398 static ssize_t beiscsi_show_boot_eth_info(
void *data,
int type,
char *buf)
422 static umode_t beiscsi_tgt_get_attr_visibility(
void *data,
int type)
445 static umode_t beiscsi_ini_get_attr_visibility(
void *data,
int type)
461 static umode_t beiscsi_eth_get_attr_visibility(
void *data,
int type)
492 .name =
"Emulex 10Gbe open-iscsi Initiator Driver",
496 .slave_configure = beiscsi_slave_configure,
498 .eh_abort_handler = beiscsi_eh_abort,
499 .eh_device_reset_handler = beiscsi_eh_device_reset,
522 "beiscsi_hba_alloc - iscsi_host_alloc failed\n");
532 memset(phba, 0,
sizeof(*phba));
535 pci_set_drvdata(pcidev, phba);
549 static void beiscsi_unmap_pci_function(
struct beiscsi_hba *phba)
565 static int beiscsi_map_pci_bars(
struct beiscsi_hba *phba,
602 beiscsi_unmap_pci_function(phba);
606 static int beiscsi_enable_pci(
struct pci_dev *pcidev)
613 "beiscsi_enable_pci - enable device failed\n");
618 if (pci_set_consistent_dma_mask(pcidev,
DMA_BIT_MASK(64))) {
619 ret = pci_set_consistent_dma_mask(pcidev,
DMA_BIT_MASK(32));
621 dev_err(&pcidev->
dev,
"Could not set PCI DMA Mask\n");
637 status = beiscsi_map_pci_bars(phba, pdev);
642 mbox_mem_alloc->
size,
643 &mbox_mem_alloc->
dma);
644 if (!mbox_mem_alloc->
va) {
645 beiscsi_unmap_pci_function(phba);
660 static void beiscsi_get_params(
struct beiscsi_hba *phba)
672 phba->
params.eq_timer = 64;
673 phba->
params.num_eq_entries =
676 phba->
params.num_eq_entries = (phba->
params.num_eq_entries < 1024)
677 ? 1024 : phba->
params.num_eq_entries;
679 "BM_%d : phba->params.num_eq_entries=%d\n",
680 phba->
params.num_eq_entries);
681 phba->
params.num_cq_entries =
684 phba->
params.wrbs_per_cxn = 256;
687 static void hwi_ring_eq_db(
struct beiscsi_hba *phba,
688 unsigned int id,
unsigned int clr_interrupt,
689 unsigned int num_processed,
690 unsigned char rearm,
unsigned char event)
715 unsigned int num_eq_processed;
722 mcc = &phba->
ctrl.mcc_obj.cq;
723 eqe = queue_tail_node(eq);
725 num_eq_processed = 0;
734 spin_unlock_irqrestore(&phba->
isr_lock, flags);
738 eqe = queue_tail_node(eq);
743 if (num_eq_processed)
744 hwi_ring_eq_db(phba, eq->
id, 1, num_eq_processed, 1, 1);
754 static irqreturn_t be_isr_msix(
int irq,
void *dev_id)
760 unsigned int num_eq_processed;
767 eqe = queue_tail_node(eq);
770 num_eq_processed = 0;
774 if (!blk_iopoll_sched_prep(&pbe_eq->
iopoll))
779 eqe = queue_tail_node(eq);
782 if (num_eq_processed)
783 hwi_ring_eq_db(phba, eq->
id, 1, num_eq_processed, 0, 1);
791 spin_unlock_irqrestore(&phba->
isr_lock, flags);
794 eqe = queue_tail_node(eq);
800 if (num_eq_processed)
801 hwi_ring_eq_db(phba, eq->
id, 1, num_eq_processed, 1, 1);
822 unsigned int num_mcceq_processed, num_ioeq_processed;
836 pbe_eq = &phwi_context->
be_eq[0];
838 eq = &phwi_context->
be_eq[0].q;
839 mcc = &phba->
ctrl.mcc_obj.cq;
841 eqe = queue_tail_node(eq);
843 num_ioeq_processed = 0;
844 num_mcceq_processed = 0;
853 spin_unlock_irqrestore(&phba->
isr_lock, flags);
854 num_mcceq_processed++;
856 if (!blk_iopoll_sched_prep(&pbe_eq->
iopoll))
858 num_ioeq_processed++;
862 eqe = queue_tail_node(eq);
864 if (num_ioeq_processed || num_mcceq_processed) {
868 if ((num_mcceq_processed) && (!num_ioeq_processed))
869 hwi_ring_eq_db(phba, eq->
id, 0,
870 (num_ioeq_processed +
871 num_mcceq_processed) , 1, 1);
873 hwi_ring_eq_db(phba, eq->
id, 0,
874 (num_ioeq_processed +
875 num_mcceq_processed), 0, 1);
881 cq = &phwi_context->
be_cq[0];
890 spin_unlock_irqrestore(&phba->
isr_lock, flags);
894 spin_unlock_irqrestore(&phba->
isr_lock, flags);
898 eqe = queue_tail_node(eq);
899 num_ioeq_processed++;
904 if (num_ioeq_processed) {
905 hwi_ring_eq_db(phba, eq->
id, 0,
906 num_ioeq_processed, 1, 1);
913 static int beiscsi_init_irqs(
struct beiscsi_hba *phba)
918 int ret, msix_vec,
i,
j;
924 for (i = 0; i < phba->
num_cpus; i++) {
933 phba->
shost->host_no, i);
937 &phwi_context->
be_eq[i]);
940 "BM_%d : beiscsi_init_irqs-Failed to"
941 "register msix for i = %d\n",
953 phba->
shost->host_no);
956 &phwi_context->
be_eq[i]);
959 "BM_%d : beiscsi_init_irqs-"
960 "Failed to register beiscsi_msix_mcc\n");
970 "BM_%d : beiscsi_init_irqs-"
971 "Failed to register irq\\n");
977 for (j = i - 1; j >= 0; j--) {
985 static void hwi_ring_cq_db(
struct beiscsi_hba *phba,
986 unsigned int id,
unsigned int num_processed,
987 unsigned char rearm,
unsigned char event)
998 beiscsi_process_async_pdu(
struct beiscsi_conn *beiscsi_conn,
1002 unsigned long pdu_len,
1003 void *pbuffer,
unsigned long buf_len)
1024 "BM_%d : In ISCSI_OP_REJECT\n");
1036 "BM_%d : Unrecognized opcode 0x%x in async msg\n",
1043 spin_lock_bh(&session->
lock);
1045 spin_unlock_bh(&session->
lock);
1055 "BM_%d : In alloc_io_sgl_handle,"
1056 " io_sgl_alloc_index=%d\n",
1060 io_sgl_alloc_index];
1077 "BM_%d : In free_,io_sgl_free_index=%d\n",
1086 "BM_%d : Double Free in IO SGL io_sgl_free_index=%d,"
1111 struct wrb_handle *pwrb_handle, *pwrb_handle_tmp;
1120 (phba->
params.wrbs_per_cxn - 1))
1153 "BM_%d : FREE WRB: pwrb_handle=%p free_index=0x%x"
1154 "wrb_handles_available=%d\n",
1167 "BM_%d : mgmt_sgl_alloc_index=%d=0x%x\n",
1173 (phba->
params.icds_per_ctrl - phba->
params.ios_per_ctrl -
1188 "BM_%d : In free_mgmt_sgl_handle,"
1189 "eh_sgl_free_index=%d\n",
1198 "BM_%d : Double Free in eh SGL ,"
1199 "eh_sgl_free_index=%d\n",
1206 (phba->
params.icds_per_ctrl - phba->
params.ios_per_ctrl - 1))
1213 be_complete_io(
struct beiscsi_conn *beiscsi_conn,
1220 unsigned char *
sense;
1221 u32 resid = 0, exp_cmdsn, max_cmdsn;
1222 u8 rsp, status, flags;
1227 max_cmdsn = ((psol->
1244 task->
sc->result = (
DID_OK << 16) | status;
1259 scsi_set_resid(task->
sc, resid);
1260 if (!status && (scsi_bufflen(task->
sc) - resid <
1261 task->
sc->underflow))
1268 unsigned short *slen = (
unsigned short *)sts_bhs->
sense_info;
1289 be_complete_logout(
struct beiscsi_conn *beiscsi_conn,
1321 be_complete_tmf(
struct beiscsi_conn *beiscsi_conn,
1345 hwi_complete_drvr_msgs(
struct beiscsi_conn *beiscsi_conn,
1370 spin_lock_bh(&session->
lock);
1371 free_wrb_handle(phba, pwrb_context, pwrb_handle);
1372 spin_unlock_bh(&session->
lock);
1376 be_complete_nopin_resp(
struct beiscsi_conn *beiscsi_conn,
1397 static void hwi_complete_cmd(
struct beiscsi_conn *beiscsi_conn,
1418 pwrb = pwrb_handle->
pwrb;
1422 spin_lock_bh(&session->
lock);
1428 be_complete_nopin_resp(beiscsi_conn, task, psol);
1430 be_complete_io(beiscsi_conn, task, psol);
1435 be_complete_logout(beiscsi_conn, task, psol);
1437 be_complete_tmf(beiscsi_conn, task, psol);
1444 "BM_%d :\t\t No HWH_TYPE_LOGIN Expected in"
1445 " hwi_complete_cmd- Solicited path\n");
1449 be_complete_nopin_resp(beiscsi_conn, task, psol);
1455 "BM_%d : In hwi_complete_cmd, unknown type = %d"
1456 "wrb_index 0x%x CID 0x%x\n", type,
1464 spin_unlock_bh(&session->
lock);
1468 *pasync_ctx,
unsigned int is_header,
1469 unsigned int host_write_ptr)
1475 return &pasync_ctx->
async_entry[host_write_ptr].data_busy_list;
1480 struct beiscsi_conn *beiscsi_conn,
1482 struct i_t_dpdu_cqe *pdpdu_cqe,
unsigned int *pcq_index)
1487 unsigned char is_header = 0;
1497 *((
unsigned long long *)(&
phys_addr.u.a64.address));
1504 pbusy_list = hwi_get_async_busy_list(pasync_ctx, 1,
1509 pbusy_list = hwi_get_async_busy_list(pasync_ctx, 0, (pdpdu_cqe->
1517 "BM_%d : Unexpected code=%d\n",
1523 WARN_ON(list_empty(pbusy_list));
1525 if (pasync_handle->
pa.u.a64.address ==
phys_addr.u.a64.address)
1540 return pasync_handle;
1544 hwi_update_async_writables(
struct beiscsi_hba *phba,
1546 unsigned int is_header,
unsigned int cq_index)
1551 unsigned int *pep_read_ptr, *pwritables;
1558 pep_read_ptr = &pasync_ctx->
async_data.ep_read_ptr;
1559 pwritables = &pasync_ctx->
async_data.writables;
1562 while ((*pep_read_ptr) != cq_index) {
1566 pbusy_list = hwi_get_async_busy_list(pasync_ctx, is_header,
1569 WARN_ON(list_empty(pbusy_list));
1571 if (!list_empty(pbusy_list)) {
1585 "BM_%d : Duplicate notification received - index 0x%x!!\n",
1590 *pwritables = *pwritables + writables;
1594 static void hwi_free_async_msg(
struct beiscsi_hba *phba,
1605 plist = &pasync_ctx->
async_entry[cri].wait_queue.list;
1621 INIT_LIST_HEAD(&pasync_ctx->
async_entry[cri].wait_queue.list);
1622 pasync_ctx->
async_entry[cri].wait_queue.hdr_received = 0;
1623 pasync_ctx->
async_entry[cri].wait_queue.bytes_received = 0;
1628 unsigned int is_header,
unsigned int host_write_ptr)
1635 pasync_sge = pasync_ctx->
async_data.ring_base;
1637 return pasync_sge + host_write_ptr;
1640 static void hwi_post_async_buffers(
struct beiscsi_hba *phba,
1641 unsigned int is_header)
1646 struct list_head *pfree_link, *pbusy_list;
1649 unsigned int host_write_num;
1650 unsigned int writables;
1662 host_write_num = pasync_ctx->
async_header.host_write_ptr;
1667 pfree_link = pasync_ctx->
async_data.free_list.next;
1668 host_write_num = pasync_ctx->
async_data.host_write_ptr;
1672 writables = (writables / 8) * 8;
1674 for (i = 0; i < writables; i++) {
1676 hwi_get_async_busy_list(pasync_ctx, is_header,
1684 pfree_link = pfree_link->
next;
1686 pasync_sge = hwi_get_ring_address(pasync_ctx,
1687 is_header, host_write_num);
1689 pasync_sge->
hi = pasync_handle->
pa.u.a32.address_lo;
1690 pasync_sge->
lo = pasync_handle->
pa.u.a32.address_hi;
1692 list_move(&pasync_handle->
link, pbusy_list);
1705 pasync_ctx->
async_data.host_write_ptr = host_write_num;
1706 pasync_ctx->
async_data.free_entries -= writables;
1707 pasync_ctx->
async_data.writables -= writables;
1708 pasync_ctx->
async_data.busy_entries += writables;
1721 static void hwi_flush_default_pdu_buffer(
struct beiscsi_hba *phba,
1722 struct beiscsi_conn *beiscsi_conn,
1728 unsigned int cq_index = -1;
1733 pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
1734 pdpdu_cqe, &cq_index);
1737 hwi_update_async_writables(phba, pasync_ctx,
1740 hwi_free_async_msg(phba, pasync_handle->
cri);
1741 hwi_post_async_buffers(phba, pasync_handle->
is_header);
1745 hwi_fwd_async_msg(
struct beiscsi_conn *beiscsi_conn,
1752 unsigned int hdr_len = 0, buf_len = 0;
1754 void *pfirst_buffer =
NULL;
1755 unsigned int num_buf = 0;
1761 phdr = pasync_handle->
pbuffer;
1766 pfirst_buffer = pasync_handle->
pbuffer;
1770 pasync_handle->
pbuffer, buf_len);
1776 status = beiscsi_process_async_pdu(beiscsi_conn, phba,
1779 phdr, hdr_len, pfirst_buffer,
1782 hwi_free_async_msg(phba, cri);
1787 hwi_gather_async_pdu(
struct beiscsi_conn *beiscsi_conn,
1793 unsigned int bytes_needed = 0, status = 0;
1794 unsigned short cri = pasync_handle->
cri;
1803 if (pasync_ctx->
async_entry[cri].wait_queue.hdr_received) {
1804 hwi_free_async_msg(phba, cri);
1808 pasync_ctx->
async_entry[cri].wait_queue.bytes_received = 0;
1809 pasync_ctx->
async_entry[cri].wait_queue.hdr_received = 1;
1815 ppdu = pasync_handle->
pbuffer;
1823 pasync_ctx->
async_entry[cri].wait_queue.bytes_needed =
1826 if (bytes_needed == 0)
1827 status = hwi_fwd_async_msg(beiscsi_conn, phba,
1832 if (pasync_ctx->
async_entry[cri].wait_queue.hdr_received) {
1844 status = hwi_fwd_async_msg(beiscsi_conn, phba,
1851 static void hwi_process_default_pdu_ring(
struct beiscsi_conn *beiscsi_conn,
1858 unsigned int cq_index = -1;
1862 pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
1863 pdpdu_cqe, &cq_index);
1866 hwi_update_async_writables(phba, pasync_ctx,
1869 hwi_gather_async_pdu(beiscsi_conn, phba, pasync_handle);
1870 hwi_post_async_buffers(phba, pasync_handle->
is_header);
1873 static void beiscsi_process_mcc_isr(
struct beiscsi_hba *phba)
1877 unsigned int num_processed = 0;
1879 mcc_cq = &phba->
ctrl.mcc_obj.cq;
1880 mcc_compl = queue_tail_node(mcc_cq);
1884 if (num_processed >= 32) {
1885 hwi_ring_cq_db(phba, mcc_cq->
id,
1886 num_processed, 0, 0);
1897 "BM_%d : Unsupported Async Event, flags"
1905 mcc_compl->
flags = 0;
1906 queue_tail_inc(mcc_cq);
1907 mcc_compl = queue_tail_node(mcc_cq);
1912 if (num_processed > 0)
1913 hwi_ring_cq_db(phba, mcc_cq->
id, num_processed, 1, 0);
1917 static unsigned int beiscsi_process_cq(
struct be_eq_obj *pbe_eq)
1922 unsigned int num_processed = 0;
1923 unsigned int tot_nump = 0;
1924 unsigned short code = 0, cid = 0;
1925 struct beiscsi_conn *beiscsi_conn;
1931 sol = queue_tail_node(cq);
1932 phba = pbe_eq->
phba;
1945 beiscsi_conn = beiscsi_ep->
conn;
1947 if (num_processed >= 32) {
1948 hwi_ring_cq_db(phba, cq->
id,
1949 num_processed, 0, 0);
1950 tot_nump += num_processed;
1956 hwi_complete_cmd(beiscsi_conn, phba, sol);
1961 "BM_%d : Received DRIVERMSG_NOTIFY\n");
1964 hwi_complete_drvr_msgs(beiscsi_conn, phba, sol);
1969 "BM_%d : Received UNSOL_HDR_ NOTIFY\n");
1971 hwi_process_default_pdu_ring(beiscsi_conn, phba,
1977 "BM_%d : Received UNSOL_DATA_NOTIFY\n");
1979 hwi_process_default_pdu_ring(beiscsi_conn, phba,
1987 "BM_%d : Ignoring CQ Error notification for"
1988 " cmd/cxn invalidate\n");
2000 "BM_%d : CQ Error notification for cmd.. "
2001 "code %d cid 0x%x\n", code, cid);
2006 "BM_%d : Digest error on def pdu ring,"
2008 hwi_flush_default_pdu_buffer(phba, beiscsi_conn,
2027 "BM_%d : CQ Error %d, reset CID 0x%x...\n",
2037 "BM_%d : CQ Error %d, reset"
2038 "received/sent on CID 0x%x...\n",
2047 "BM_%d : CQ Error Invalid code= %d "
2048 "received on CID 0x%x...\n",
2055 sol = queue_tail_node(cq);
2059 if (num_processed > 0) {
2060 tot_nump += num_processed;
2061 hwi_ring_cq_db(phba, cq->
id, num_processed, 1, 0);
2068 unsigned long flags;
2080 pbe_eq = &phwi_context->
be_eq[0];
2085 spin_unlock_irqrestore(&phba->
isr_lock, flags);
2086 beiscsi_process_mcc_isr(phba);
2092 spin_unlock_irqrestore(&phba->
isr_lock, flags);
2093 beiscsi_process_cq(pbe_eq);
2099 static unsigned int ret;
2104 ret = beiscsi_process_cq(pbe_eq);
2106 phba = pbe_eq->
phba;
2110 "BM_%d : rearm pbe_eq->q.id =%d\n",
2112 hwi_ring_eq_db(phba, pbe_eq->
q.id, 0, 0, 1, 1);
2122 unsigned int sg_len,
index;
2124 unsigned long long addr;
2129 io_task->
bhs_pa.u.a32.address_lo);
2131 io_task->
bhs_pa.u.a32.address_hi);
2134 for (index = 0; (index < num_sg) && (index < 2); index++,
2140 ((
u32)(addr & 0xFFFFFFFF)));
2142 ((
u32)(addr >> 32)));
2152 ((
u32)(addr & 0xFFFFFFFF)));
2154 ((
u32)(addr >> 32)));
2165 io_task->
bhs_pa.u.a32.address_hi);
2167 io_task->
bhs_pa.u.a32.address_lo);
2174 }
else if (num_sg == 2) {
2189 for (index = 0; index < num_sg; index++, sg =
sg_next(sg), psgl++) {
2193 (addr & 0xFFFFFFFF));
2208 unsigned long long addr;
2210 struct beiscsi_conn *beiscsi_conn = io_task->
conn;
2215 io_task->
bhs_pa.u.a32.address_lo);
2217 io_task->
bhs_pa.u.a32.address_hi);
2222 addr = (
u64) pci_map_single(phba->
pcidev,
2230 ((
u32)(addr & 0xFFFFFFFF)));
2232 ((
u32)(addr >> 32)));
2247 io_task->
bhs_pa.u.a32.address_hi);
2249 io_task->
bhs_pa.u.a32.address_lo);
2262 ((
u32)(addr & 0xFFFFFFFF)));
2264 ((
u32)(addr >> 32)));
2271 static void beiscsi_find_mem_req(
struct beiscsi_hba *phba)
2273 unsigned int num_cq_pages, num_async_pdu_buf_pages;
2274 unsigned int num_async_pdu_data_pages, wrb_sz_per_cxn;
2275 unsigned int num_async_pdu_buf_sgl_pages, num_async_pdu_data_sgl_pages;
2279 num_async_pdu_buf_pages =
2281 phba->
params.defpdu_hdr_sz);
2282 num_async_pdu_buf_sgl_pages =
2285 num_async_pdu_data_pages =
2287 phba->
params.defpdu_data_sz);
2288 num_async_pdu_data_sgl_pages =
2301 * (phba->
params.wrbs_per_cxn)
2302 * phba->
params.cxns_per_ctrl;
2304 (phba->
params.wrbs_per_cxn);
2306 phba->
params.cxns_per_ctrl);
2309 phba->
params.icds_per_ctrl;
2311 phba->
params.num_sge_per_io * phba->
params.icds_per_ctrl;
2318 num_async_pdu_buf_sgl_pages *
PAGE_SIZE;
2320 num_async_pdu_data_sgl_pages *
PAGE_SIZE;
2322 phba->
params.asyncpdus_per_ctrl *
2325 phba->
params.asyncpdus_per_ctrl *
2332 static int beiscsi_alloc_mem(
struct beiscsi_hba *phba)
2336 struct mem_array *mem_arr, *mem_arr_orig;
2337 unsigned int i,
j, alloc_size, curr_alloc_size;
2352 if (!mem_arr_orig) {
2361 mem_arr = mem_arr_orig;
2365 curr_alloc_size =
min(be_max_phys_size * 1024, alloc_size);
2374 if (curr_alloc_size -
2379 curr_alloc_size = curr_alloc_size / 2;
2382 a64.address = (
__u64) bus_add;
2383 mem_arr->
size = curr_alloc_size;
2384 alloc_size -= curr_alloc_size;
2385 curr_alloc_size =
min(be_max_phys_size *
2390 }
while (alloc_size);
2402 kfree(mem_arr_orig);
2406 while ((i) || (j)) {
2412 (
unsigned long)mem_descr->
2422 kfree(mem_arr_orig);
2428 static int beiscsi_get_memory(
struct beiscsi_hba *phba)
2430 beiscsi_find_mem_req(phba);
2431 return beiscsi_alloc_mem(phba);
2434 static void iscsi_init_global_templates(
struct beiscsi_hba *phba)
2459 static int beiscsi_init_wrb_handle(
struct beiscsi_hba *phba)
2466 unsigned int num_cxn_wrbh = 0;
2467 unsigned int num_cxn_wrb = 0,
j,
idx = 0,
index;
2476 for (index = 0; index < phba->
params.cxns_per_ctrl * 2; index += 2) {
2483 "BM_%d : Mem Alloc Failed. Failing to load\n");
2484 goto init_wrb_hndl_failed;
2491 "BM_%d : Mem Alloc Failed. Failing to load\n");
2492 goto init_wrb_hndl_failed;
2494 if (!num_cxn_wrbh) {
2497 num_cxn_wrbh = ((mem_descr_wrbh->
mem_array[
idx].size) /
2499 phba->
params.wrbs_per_cxn));
2507 for (j = 0; j < phba->
params.wrbs_per_cxn; j++) {
2519 for (index = 0; index < phba->
params.cxns_per_ctrl * 2; index += 2) {
2525 phba->
params.wrbs_per_cxn));
2530 for (j = 0; j < phba->
params.wrbs_per_cxn; j++) {
2532 pwrb_handle->
pwrb = pwrb;
2539 init_wrb_hndl_failed:
2540 for (j = index; j > 0; j--) {
2548 static void hwi_init_async_pdu_ctx(
struct beiscsi_hba *phba)
2554 unsigned int index,
idx, num_per_mem, num_async_data;
2562 mem_descr->
mem_array[0].virtual_address;
2563 pasync_ctx = phwi_ctrlr->
phwi_ctxt->pasync_ctx;
2564 memset(pasync_ctx, 0,
sizeof(*pasync_ctx));
2573 "BM_%d : hwi_init_async_pdu_ctx"
2574 " HWI_MEM_ASYNC_HEADER_BUF va=%p\n",
2575 mem_descr->
mem_array[0].virtual_address);
2578 "BM_%d : No Virtual address\n");
2581 mem_descr->
mem_array[0].virtual_address;
2584 mem_descr->
mem_array[0].bus_address.u.a64.address;
2590 "BM_%d : hwi_init_async_pdu_ctx"
2591 " HWI_MEM_ASYNC_HEADER_RING va=%p\n",
2592 mem_descr->
mem_array[0].virtual_address);
2595 "BM_%d : No Virtual address\n");
2598 mem_descr->
mem_array[0].virtual_address;
2604 "BM_%d : hwi_init_async_pdu_ctx"
2605 " HWI_MEM_ASYNC_HEADER_HANDLE va=%p\n",
2606 mem_descr->
mem_array[0].virtual_address);
2609 "BM_%d : No Virtual address\n");
2612 mem_descr->
mem_array[0].virtual_address;
2621 "BM_%d : hwi_init_async_pdu_ctx"
2622 " HWI_MEM_ASYNC_DATA_RING va=%p\n",
2623 mem_descr->
mem_array[0].virtual_address);
2626 "BM_%d : No Virtual address\n");
2629 mem_descr->
mem_array[0].virtual_address;
2635 "BM_%d : No Virtual address\n");
2638 mem_descr->
mem_array[0].virtual_address;
2640 INIT_LIST_HEAD(&pasync_ctx->
async_data.free_list);
2651 "BM_%d : hwi_init_async_pdu_ctx"
2652 " HWI_MEM_ASYNC_DATA_BUF va=%p\n",
2653 mem_descr->
mem_array[0].virtual_address);
2656 "BM_%d : No Virtual address\n");
2661 pasync_ctx->
async_data.pa_base.u.a64.address =
2665 phba->
params.defpdu_data_sz);
2669 pasync_header_h->
cri = -1;
2671 INIT_LIST_HEAD(&pasync_header_h->
link);
2673 (
void *)((
unsigned long)
2677 pasync_header_h->
pa.u.a64.address =
2687 INIT_LIST_HEAD(&pasync_ctx->
async_entry[index].wait_queue.list);
2690 pasync_data_h->
cri = -1;
2692 INIT_LIST_HEAD(&pasync_data_h->
link);
2694 if (!num_async_data) {
2699 pasync_ctx->
async_data.pa_base.u.a64.address =
2701 bus_address.u.a64.address;
2704 phba->
params.defpdu_data_sz);
2707 (
void *)((
unsigned long)
2711 pasync_data_h->
pa.u.a64.address =
2712 pasync_ctx->
async_data.pa_base.u.a64.address +
2723 INIT_LIST_HEAD(&pasync_ctx->
async_entry[index].data_busy_list);
2733 be_sgl_create_contiguous(
void *virtual_address,
2742 sgl->
va = virtual_address;
2743 sgl->
dma = (
unsigned long)physical_address;
2749 static void be_sgl_destroy_contiguous(
struct be_dma_mem *
sgl)
2751 memset(sgl, 0,
sizeof(*sgl));
2759 be_sgl_destroy_contiguous(sgl);
2767 hwi_build_be_sgl_by_offset(
struct beiscsi_hba *phba,
2771 be_sgl_destroy_contiguous(sgl);
2779 u16 len,
u16 entry_size,
void *vaddress)
2783 memset(q, 0,
sizeof(*q));
2786 mem->
size = len * entry_size;
2794 static int beiscsi_create_eqs(
struct beiscsi_hba *phba,
2797 unsigned int i, num_eq_pages;
2798 int ret = 0, eq_for_mcc;
2811 for (i = 0; i < (phba->
num_cpus + eq_for_mcc); i++) {
2812 eq = &phwi_context->
be_eq[
i].q;
2814 phwi_context->
be_eq[
i].phba = phba;
2819 goto create_eq_error;
2821 mem->
va = eq_vaddress;
2822 ret = be_fill_queue(eq, phba->
params.num_eq_entries,
2826 "BM_%d : be_fill_queue Failed for EQ\n");
2827 goto create_eq_error;
2835 "BM_%d : beiscsi_cmd_eq_create"
2837 goto create_eq_error;
2841 "BM_%d : eqid = %d\n",
2842 phwi_context->
be_eq[i].q.id);
2846 for (i = 0; i < (phba->
num_cpus + 1); i++) {
2847 eq = &phwi_context->
be_eq[
i].q;
2857 static int beiscsi_create_cqs(
struct beiscsi_hba *phba,
2860 unsigned int i, num_cq_pages;
2871 for (i = 0; i < phba->
num_cpus; i++) {
2872 cq = &phwi_context->
be_cq[
i];
2873 eq = &phwi_context->
be_eq[
i].q;
2874 pbe_eq = &phwi_context->
be_eq[
i];
2882 goto create_cq_error;
2883 ret = be_fill_queue(cq, phba->
params.num_cq_entries,
2884 sizeof(
struct sol_cqe), cq_vaddress);
2887 "BM_%d : be_fill_queue Failed "
2889 goto create_cq_error;
2897 "BM_%d : beiscsi_cmd_eq_create"
2898 "Failed for ISCSI CQ\n");
2899 goto create_cq_error;
2902 "BM_%d : iscsi cq_id is %d for eq_id %d\n"
2903 "iSCSI CQ CREATED\n", cq->
id, eq->
id);
2908 for (i = 0; i < phba->
num_cpus; i++) {
2909 cq = &phwi_context->
be_cq[
i];
2924 unsigned int def_pdu_ring_sz)
2935 cq = &phwi_context->
be_cq[0];
2939 dq_vaddress = mem_descr->
mem_array[
idx].virtual_address;
2940 ret = be_fill_queue(dq, mem_descr->
mem_array[0].size /
2945 "BM_%d : be_fill_queue Failed for DEF PDU HDR\n");
2949 bus_address.u.a64.address;
2952 phba->
params.defpdu_hdr_sz);
2955 "BM_%d : be_cmd_create_default_pdu_queue Failed DEFHDR\n");
2960 "BM_%d : iscsi def pdu id is %d\n",
2963 hwi_post_async_buffers(phba, 1);
2971 unsigned int def_pdu_ring_sz)
2982 cq = &phwi_context->
be_cq[0];
2986 dq_vaddress = mem_descr->
mem_array[
idx].virtual_address;
2987 ret = be_fill_queue(dataq, mem_descr->
mem_array[0].size /
2992 "BM_%d : be_fill_queue Failed for DEF PDU DATA\n");
2996 bus_address.u.a64.address;
2999 phba->
params.defpdu_data_sz);
3002 "BM_%d be_cmd_create_default_pdu_queue"
3003 " Failed for DEF PDU DATA\n");
3008 "BM_%d : iscsi def data id is %d\n",
3011 hwi_post_async_buffers(phba, 0);
3013 "BM_%d : DEFAULT PDU DATA RING CREATED\n");
3031 page_offset = (
sizeof(
struct iscsi_sge) * phba->
params.num_sge_per_io *
3034 hwi_build_be_sgl_arr(phba, pm_arr, &sgl);
3041 "BM_%d : post sgl failed.\n");
3047 "BM_%d : POSTED PAGES\n");
3066 memset(q, 0,
sizeof(*q));
3069 mem->
size = len * entry_size;
3078 beiscsi_create_wrb_rings(
struct beiscsi_hba *phba,
3082 unsigned int wrb_mem_index,
offset,
size, num_wrb_rings;
3094 pwrb_arr =
kmalloc(
sizeof(*pwrb_arr) * phba->
params.cxns_per_ctrl,
3098 "BM_%d : Memory alloc failed in create wrb ring.\n");
3102 pa_addr_lo = mem_descr->
mem_array[
idx].bus_address.u.a64.address;
3106 for (num = 0; num < phba->
params.cxns_per_ctrl; num++) {
3107 if (num_wrb_rings) {
3109 pwrb_arr[num].
bus_address.u.a64.address = pa_addr_lo;
3110 pwrb_arr[num].
size = phba->
params.wrbs_per_cxn *
3112 wrb_vaddr += pwrb_arr[num].
size;
3113 pa_addr_lo += pwrb_arr[num].
size;
3118 pa_addr_lo = mem_descr->
mem_array[
idx].\
bus_address.u.a64.address;
3120 (phba->
params.wrbs_per_cxn *
3125 pwrb_arr[num].
size = phba->
params.wrbs_per_cxn *
3127 wrb_vaddr += pwrb_arr[num].
size;
3128 pa_addr_lo += pwrb_arr[num].
size;
3132 for (i = 0; i < phba->
params.cxns_per_ctrl; i++) {
3137 hwi_build_be_sgl_by_offset(phba, &pwrb_arr[i], &sgl);
3142 "BM_%d : wrbq create failed.");
3153 static void free_wrb_handles(
struct beiscsi_hba *phba)
3160 for (index = 0; index < phba->
params.cxns_per_ctrl * 2; index += 2) {
3167 static void be_mcc_queues_destroy(
struct beiscsi_hba *phba)
3172 q = &phba->
ctrl.mcc_obj.q;
3175 be_queue_free(phba, q);
3177 q = &phba->
ctrl.mcc_obj.cq;
3180 be_queue_free(phba, q);
3193 for (i = 0; i < phba->
params.cxns_per_ctrl; i++) {
3198 free_wrb_handles(phba);
3210 for (i = 0; i < (phba->
num_cpus); i++) {
3211 q = &phwi_context->
be_cq[
i];
3219 for (i = 0; i < (phba->
num_cpus + eq_num); i++) {
3220 q = &phwi_context->
be_eq[
i].q;
3224 be_mcc_queues_destroy(phba);
3227 static int be_mcc_queues_create(
struct beiscsi_hba *phba,
3234 cq = &phba->
ctrl.mcc_obj.cq;
3241 [phba->
num_cpus].q,
false,
true, 0))
3250 q = &phba->
ctrl.mcc_obj.q;
3252 goto mcc_cq_destroy;
3261 be_queue_free(phba, q);
3265 be_queue_free(phba, cq);
3270 static int find_num_cpus(
void)
3281 static int hwi_init_port(
struct beiscsi_hba *phba)
3285 unsigned int def_pdu_ring_sz;
3298 status = beiscsi_create_eqs(phba, phwi_context);
3301 "BM_%d : EQ not created\n");
3305 status = be_mcc_queues_create(phba, phwi_context);
3312 "BM_%d : Unsupported fw version\n");
3316 status = beiscsi_create_cqs(phba, phwi_context);
3319 "BM_%d : CQ not created\n");
3323 status = beiscsi_create_def_hdr(phba, phwi_context, phwi_ctrlr,
3327 "BM_%d : Default Header not created\n");
3331 status = beiscsi_create_def_data(phba, phwi_context,
3332 phwi_ctrlr, def_pdu_ring_sz);
3335 "BM_%d : Default Data not created\n");
3339 status = beiscsi_post_pages(phba);
3342 "BM_%d : Post SGL Pages Failed\n");
3346 status = beiscsi_create_wrb_rings(phba, phwi_context, phwi_ctrlr);
3349 "BM_%d : WRB Rings not created\n");
3354 "BM_%d : hwi_init_port success\n");
3359 "BM_%d : hwi_init_port failed");
3364 static int hwi_init_controller(
struct beiscsi_hba *phba)
3373 "BM_%d : phwi_ctrlr->phwi_ctxt=%p\n",
3377 "BM_%d : HWI_MEM_ADDN_CONTEXT is more "
3378 "than one element.Failing to load\n");
3382 iscsi_init_global_templates(phba);
3383 if (beiscsi_init_wrb_handle(phba))
3386 hwi_init_async_pdu_ctx(phba);
3387 if (hwi_init_port(phba) != 0) {
3389 "BM_%d : hwi_init_controller failed\n");
3396 static void beiscsi_free_mem(
struct beiscsi_hba *phba)
3408 mem_descr->
mem_array[j - 1].virtual_address,
3409 (
unsigned long)mem_descr->
mem_array[j - 1].
3410 bus_address.u.a64.address);
3419 static int beiscsi_init_controller(
struct beiscsi_hba *phba)
3423 ret = beiscsi_get_memory(phba);
3426 "BM_%d : beiscsi_dev_probe -"
3427 "Failed in beiscsi_alloc_memory\n");
3431 ret = hwi_init_controller(phba);
3435 "BM_%d : Return success from beiscsi_init_controller");
3440 beiscsi_free_mem(phba);
3444 static int beiscsi_init_sgl_handle(
struct beiscsi_hba *phba)
3449 unsigned int arr_index,
i,
idx;
3458 phba->
params.ios_per_ctrl,
3462 "BM_%d : Mem Alloc Failed. Failing to load\n");
3466 (phba->
params.icds_per_ctrl -
3467 phba->
params.ios_per_ctrl),
3472 "BM_%d : Mem Alloc Failed. Failing to load\n");
3477 "BM_%d : HWI_MEM_SGLH is more than one element."
3478 "Failing to load\n");
3485 psgl_handle = mem_descr_sglh->
mem_array[
idx].virtual_address;
3489 if (arr_index < phba->
params.ios_per_ctrl) {
3495 phba->
params.ios_per_ctrl] =
3505 "BM_%d : phba->io_sgl_hndl_avbl=%d"
3506 "phba->eh_sgl_hndl_avbl=%d\n",
3513 "\n BM_%d : mem_descr_sg->num_elements=%d\n",
3518 while (idx < mem_descr_sg->num_elements) {
3525 if (arr_index < phba->
params.ios_per_ctrl)
3529 phba->
params.ios_per_ctrl];
3533 pfrag += phba->
params.num_sge_per_io;
3535 phba->
fw_config.iscsi_icd_start + arr_index++;
3546 static int hba_setup_cid_tbls(
struct beiscsi_hba *phba)
3550 phba->
cid_array = kzalloc(
sizeof(
void *) * phba->
params.cxns_per_ctrl,
3554 "BM_%d : Failed to allocate memory in "
3555 "hba_setup_cid_tbls\n");
3562 "BM_%d : Failed to allocate memory in "
3563 "hba_setup_cid_tbls\n");
3567 new_cid = phba->
fw_config.iscsi_cid_start;
3568 for (i = 0; i < phba->
params.cxns_per_ctrl; i++) {
3576 static void hwi_enable_intr(
struct beiscsi_hba *phba)
3597 "BM_%d : reg =x%08x addr=%p\n", reg, addr);
3602 eq = &phwi_context->
be_eq[0].q;
3604 "BM_%d : eq->id=%d\n", eq->
id);
3606 hwi_ring_eq_db(phba, eq->
id, 0, 0, 1, 1);
3608 for (i = 0; i <= phba->
num_cpus; i++) {
3609 eq = &phwi_context->
be_eq[
i].q;
3611 "BM_%d : eq->id=%d\n", eq->
id);
3612 hwi_ring_eq_db(phba, eq->
id, 0, 0, 1, 1);
3617 static void hwi_disable_intr(
struct beiscsi_hba *phba)
3626 reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
3630 "BM_%d : In hwi_disable_intr, Already Disabled\n");
3643 static int beiscsi_get_boot_info(
struct beiscsi_hba *phba)
3648 unsigned int tag, wrb_num;
3649 unsigned short status, extd_status;
3650 unsigned int s_handle;
3659 "BM_%d : No boot session\n");
3663 sizeof(*session_resp),
3665 if (nonemb_cmd.va ==
NULL) {
3668 "BM_%d : Failed to allocate memory for"
3669 "beiscsi_get_session_info\n");
3674 memset(nonemb_cmd.va, 0,
sizeof(*session_resp));
3680 "BM_%d : beiscsi_get_session_info"
3686 phba->
ctrl.mcc_numtag[tag]);
3688 wrb_num = (phba->
ctrl.mcc_numtag[
tag] & 0x00FF0000) >> 16;
3689 extd_status = (phba->
ctrl.mcc_numtag[
tag] & 0x0000FF00) >> 8;
3690 status = phba->
ctrl.mcc_numtag[
tag] & 0x000000FF;
3691 if (status || extd_status) {
3694 "BM_%d : beiscsi_get_session_info Failed"
3695 " status = %d extd_status = %d\n",
3696 status, extd_status);
3701 wrb = queue_get_wrb(mccq, wrb_num);
3703 session_resp = nonemb_cmd.va ;
3711 nonemb_cmd.va, nonemb_cmd.dma);
3715 static void beiscsi_boot_release(
void *data)
3722 static int beiscsi_setup_boot_info(
struct beiscsi_hba *phba)
3727 if (beiscsi_get_boot_info(phba))
3739 beiscsi_show_boot_tgt_info,
3740 beiscsi_tgt_get_attr_visibility,
3741 beiscsi_boot_release);
3748 beiscsi_show_boot_ini_info,
3749 beiscsi_ini_get_attr_visibility,
3750 beiscsi_boot_release);
3757 beiscsi_show_boot_eth_info,
3758 beiscsi_eth_get_attr_visibility,
3759 beiscsi_boot_release);
3771 static int beiscsi_init_port(
struct beiscsi_hba *phba)
3775 ret = beiscsi_init_controller(phba);
3778 "BM_%d : beiscsi_dev_probe - Failed in"
3779 "beiscsi_init_controller\n");
3782 ret = beiscsi_init_sgl_handle(phba);
3785 "BM_%d : beiscsi_dev_probe - Failed in"
3786 "beiscsi_init_sgl_handle\n");
3787 goto do_cleanup_ctrlr;
3790 if (hba_setup_cid_tbls(phba)) {
3792 "BM_%d : Failed in hba_setup_cid_tbls\n");
3795 goto do_cleanup_ctrlr;
3805 static void hwi_purge_eq(
struct beiscsi_hba *phba)
3812 unsigned int num_processed;
3821 for (i = 0; i < (phba->
num_cpus + eq_msix); i++) {
3822 eq = &phwi_context->
be_eq[
i].q;
3823 eqe = queue_tail_node(eq);
3829 eqe = queue_tail_node(eq);
3834 hwi_ring_eq_db(phba, eq->
id, 1, num_processed, 1, 1);
3838 static void beiscsi_clean_port(
struct beiscsi_hba *phba)
3845 "BM_%d : mgmt_epfw_cleanup FAILED\n");
3855 static void beiscsi_cleanup_task(
struct iscsi_task *task)
3859 struct beiscsi_conn *beiscsi_conn = conn->
dd_data;
3871 io_task->
bhs_pa.u.a64.address);
3877 free_wrb_handle(phba, pwrb_context,
3891 free_wrb_handle(phba, pwrb_context,
3923 spin_lock_bh(&session->
lock);
3924 beiscsi_cleanup_task(task);
3925 spin_unlock_bh(&session->
lock);
3930 memset(pwrb, 0,
sizeof(*pwrb));
3934 max_burst_length) / 32]);
3936 max_send_data_segment_length, pwrb,
3938 max_send_data_segment_length) / 32]);
3943 first_burst_length) / 32]);
3963 exp_statsn) / 32] + 1));
3971 session_state, pwrb, 0);
3983 pad_buffer_addr_hi, pwrb,
3984 mem_descr->
mem_array[0].bus_address.u.a32.address_hi);
3986 pad_buffer_addr_lo, pwrb,
3987 mem_descr->
mem_array[0].bus_address.u.a32.address_lo);
4000 int *index,
int *age)
4021 struct beiscsi_conn *beiscsi_conn = conn->
dd_data;
4035 io_task->
conn = beiscsi_conn;
4059 alloc_mgmt_sgl_handle(phba);
4085 io_task->
psgl_handle = alloc_mgmt_sgl_handle(phba);
4094 goto free_mgmt_hndls;
4099 wrb_index << 16) | (
unsigned int)
4103 io_task->
cmd_bhs->iscsi_hdr.itt = itt;
4121 free_wrb_handle(phba, pwrb_context, io_task->
pwrb_handle);
4124 io_task->
bhs_pa.u.a64.address);
4128 "BM_%d : Alloc of SGL_ICD Failed\n");
4133 unsigned int num_sg,
unsigned int xferlen,
4134 unsigned int writedir)
4139 struct beiscsi_conn *beiscsi_conn = conn->
dd_data;
4142 unsigned int doorbell = 0;
4145 io_task->
cmd_bhs->iscsi_hdr.exp_statsn = 0;
4160 &io_task->
cmd_bhs->iscsi_hdr.lun));
4169 hwi_write_sgl(pwrb, sg, num_sg, io_task);
4184 static int beiscsi_mtask(
struct iscsi_task *task)
4188 struct beiscsi_conn *beiscsi_conn = conn->
dd_data;
4191 unsigned int doorbell = 0;
4196 memset(pwrb, 0,
sizeof(*pwrb));
4204 switch (task->
hdr->opcode & ISCSI_OPCODE_MASK) {
4210 hwi_write_buffer(pwrb, task);
4224 hwi_write_buffer(pwrb, task);
4230 hwi_write_buffer(pwrb, task);
4236 hwi_write_buffer(pwrb, task);
4242 hwi_write_buffer(pwrb, task);
4247 "BM_%d : opcode =%d Not supported\n",
4248 task->
hdr->opcode & ISCSI_OPCODE_MASK);
4267 static int beiscsi_task_xmit(
struct iscsi_task *task)
4273 unsigned int writedir = 0, xferlen = 0;
4276 return beiscsi_mtask(task);
4284 phba = ((
struct beiscsi_conn *)conn->
dd_data)->phba;
4286 "BM_%d : scsi_dma_map Failed\n");
4290 xferlen = scsi_bufflen(sc);
4291 sg = scsi_sglist(sc);
4297 return beiscsi_iotask(task, sg, num_sg, xferlen, writedir);
4304 static int beiscsi_bsg_request(
struct bsg_job *job)
4314 unsigned short status, extd_status;
4324 if (nonemb_cmd.va ==
NULL) {
4326 "BM_%d : Failed to allocate memory for "
4327 "beiscsi_bsg_request\n");
4334 "BM_%d : be_cmd_get_mac_addr Failed\n");
4337 nonemb_cmd.va, nonemb_cmd.dma);
4341 phba->
ctrl.mcc_numtag[tag]);
4342 extd_status = (phba->
ctrl.mcc_numtag[
tag] & 0x0000FF00) >> 8;
4343 status = phba->
ctrl.mcc_numtag[
tag] & 0x000000FF;
4355 nonemb_cmd.va, nonemb_cmd.dma);
4356 if (status || extd_status) {
4358 "BM_%d : be_cmd_get_mac_addr Failed"
4359 " status = %d extd_status = %d\n",
4360 status, extd_status);
4368 "BM_%d : Unsupported bsg command: 0x%x\n",
4379 beiscsi_log_enable_init(phba, beiscsi_log_enable);
4382 static void beiscsi_quiesce(
struct beiscsi_hba *phba)
4387 unsigned int i, msix_vec;
4388 u8 *real_offset = 0;
4393 hwi_disable_intr(phba);
4395 for (i = 0; i <= phba->
num_cpus; i++) {
4406 for (i = 0; i < phba->
num_cpus; i++) {
4407 pbe_eq = &phwi_context->
be_eq[
i];
4411 beiscsi_clean_port(phba);
4412 beiscsi_free_mem(phba);
4415 value =
readl((
void *)real_offset);
4417 if (value & 0x00010000) {
4418 value &= 0xfffeffff;
4419 writel(value, (
void *)real_offset);
4421 beiscsi_unmap_pci_function(phba);
4423 phba->
ctrl.mbox_mem_alloced.size,
4424 phba->
ctrl.mbox_mem_alloced.va,
4425 phba->
ctrl.mbox_mem_alloced.dma);
4428 static void beiscsi_remove(
struct pci_dev *pcidev)
4433 phba = pci_get_drvdata(pcidev);
4435 dev_err(&pcidev->
dev,
"beiscsi_remove called with no phba\n");
4440 beiscsi_quiesce(phba);
4448 static void beiscsi_shutdown(
struct pci_dev *pcidev)
4453 phba = (
struct beiscsi_hba *)pci_get_drvdata(pcidev);
4455 dev_err(&pcidev->
dev,
"beiscsi_shutdown called with no phba\n");
4459 beiscsi_quiesce(phba);
4463 static void beiscsi_msix_enable(
struct beiscsi_hba *phba)
4467 for (i = 0; i <= phba->
num_cpus; i++)
4485 int ret, num_cpus,
i;
4486 u8 *real_offset = 0;
4489 ret = beiscsi_enable_pci(pcidev);
4492 "beiscsi_dev_probe - Failed to enable pci device\n");
4496 phba = beiscsi_hba_alloc(pcidev);
4499 "beiscsi_dev_probe - Failed in beiscsi_hba_alloc\n");
4506 switch (pcidev->
device) {
4521 num_cpus = find_num_cpus();
4526 "BM_%d : num_cpus = %d\n",
4530 beiscsi_msix_enable(phba);
4534 ret = be_ctrl_init(phba, pcidev);
4537 "BM_%d : beiscsi_dev_probe-"
4538 "Failed in be_ctrl_init\n");
4544 value =
readl((
void *)real_offset);
4545 if (value & 0x00010000) {
4548 "BM_%d : Loading Driver in crashdump mode\n");
4552 "BM_%d : Reset Failed. Aborting Crashdump\n");
4558 "BM_%d : Failed to get out of reset."
4559 "Aborting Crashdump\n");
4563 value |= 0x00010000;
4564 writel(value, (
void *)real_offset);
4575 "BM_%d : Error getting fw config\n");
4579 beiscsi_get_params(phba);
4580 phba->
shost->can_queue = phba->
params.ios_per_ctrl;
4581 ret = beiscsi_init_port(phba);
4584 "BM_%d : beiscsi_dev_probe-"
4585 "Failed in beiscsi_init_port\n");
4591 phba->
ctrl.mcc_tag[
i] = i + 1;
4592 phba->
ctrl.mcc_numtag[i + 1] = 0;
4593 phba->
ctrl.mcc_tag_available++;
4596 phba->
ctrl.mcc_alloc_index = phba->
ctrl.mcc_free_index = 0;
4599 phba->
shost->host_no);
4603 "BM_%d : beiscsi_dev_probe-"
4604 "Failed to allocate work queue\n");
4613 for (i = 0; i < phba->
num_cpus; i++) {
4614 pbe_eq = &phwi_context->
be_eq[
i];
4620 ret = beiscsi_init_irqs(phba);
4623 "BM_%d : beiscsi_dev_probe-"
4624 "Failed to beiscsi_init_irqs\n");
4627 hwi_enable_intr(phba);
4629 if (beiscsi_setup_boot_info(phba))
4635 "BM_%d : Could not set up "
4636 "iSCSI boot info.\n");
4640 "\n\n\n BM_%d : SUCCESS - DRIVER LOADED\n\n\n");
4646 for (i = 0; i < phba->
num_cpus; i++) {
4647 pbe_eq = &phwi_context->
be_eq[
i];
4651 beiscsi_clean_port(phba);
4652 beiscsi_free_mem(phba);
4656 value =
readl((
void *)real_offset);
4658 if (value & 0x00010000) {
4659 value &= 0xfffeffff;
4660 writel(value, (
void *)real_offset);
4664 phba->
ctrl.mbox_mem_alloced.size,
4665 phba->
ctrl.mbox_mem_alloced.va,
4666 phba->
ctrl.mbox_mem_alloced.dma);
4667 beiscsi_unmap_pci_function(phba);
4699 .xmit_task = beiscsi_task_xmit,
4700 .cleanup_task = beiscsi_cleanup_task,
4701 .alloc_pdu = beiscsi_alloc_pdu,
4702 .parse_pdu_itt = beiscsi_parse_pdu,
4709 .bsg_request = beiscsi_bsg_request,
4712 static struct pci_driver beiscsi_pci_driver = {
4714 .probe = beiscsi_dev_probe,
4715 .remove = beiscsi_remove,
4716 .shutdown = beiscsi_shutdown,
4717 .id_table = beiscsi_pci_id_table
4721 static int __init beiscsi_module_init(
void)
4725 beiscsi_scsi_transport =
4727 if (!beiscsi_scsi_transport) {
4729 "beiscsi_module_init - Unable to register beiscsi transport.\n");
4733 &beiscsi_iscsi_transport);
4735 ret = pci_register_driver(&beiscsi_pci_driver);
4738 "beiscsi_module_init - Unable to register beiscsi pci driver.\n");
4739 goto unregister_iscsi_transport;
4743 unregister_iscsi_transport:
4748 static void __exit beiscsi_module_exit(
void)