2 * Copyright (C) 2005 - 2013 Emulex
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation. The full GNU General
8 * Public License is included in this distribution in the file called COPYING.
10 * Written by: Jayamohan Kallickal (jayamohan.kallickal@emulex.com)
12 * Contact Information:
13 * linux-drivers@emulex.com
17 * Costa Mesa, CA 92626
20 #include <linux/reboot.h>
21 #include <linux/delay.h>
22 #include <linux/slab.h>
23 #include <linux/interrupt.h>
24 #include <linux/blkdev.h>
25 #include <linux/pci.h>
26 #include <linux/string.h>
27 #include <linux/kernel.h>
28 #include <linux/semaphore.h>
29 #include <linux/iscsi_boot_sysfs.h>
30 #include <linux/module.h>
31 #include <linux/bsg-lib.h>
33 #include <scsi/libiscsi.h>
34 #include <scsi/scsi_bsg_iscsi.h>
35 #include <scsi/scsi_netlink.h>
36 #include <scsi/scsi_transport_iscsi.h>
37 #include <scsi/scsi_transport.h>
38 #include <scsi/scsi_cmnd.h>
39 #include <scsi/scsi_device.h>
40 #include <scsi/scsi_host.h>
41 #include <scsi/scsi.h>
47 static unsigned int be_iopoll_budget
= 10;
48 static unsigned int be_max_phys_size
= 64;
49 static unsigned int enable_msix
= 1;
51 MODULE_DEVICE_TABLE(pci
, beiscsi_pci_id_table
);
52 MODULE_DESCRIPTION(DRV_DESC
" " BUILD_STR
);
53 MODULE_VERSION(BUILD_STR
);
54 MODULE_AUTHOR("Emulex Corporation");
55 MODULE_LICENSE("GPL");
56 module_param(be_iopoll_budget
, int, 0);
57 module_param(enable_msix
, int, 0);
58 module_param(be_max_phys_size
, uint
, S_IRUGO
);
59 MODULE_PARM_DESC(be_max_phys_size
,
60 "Maximum Size (In Kilobytes) of physically contiguous "
61 "memory that can be allocated. Range is 16 - 128");
63 #define beiscsi_disp_param(_name)\
65 beiscsi_##_name##_disp(struct device *dev,\
66 struct device_attribute *attrib, char *buf) \
68 struct Scsi_Host *shost = class_to_shost(dev);\
69 struct beiscsi_hba *phba = iscsi_host_priv(shost); \
70 uint32_t param_val = 0; \
71 param_val = phba->attr_##_name;\
72 return snprintf(buf, PAGE_SIZE, "%d\n",\
76 #define beiscsi_change_param(_name, _minval, _maxval, _defaval)\
78 beiscsi_##_name##_change(struct beiscsi_hba *phba, uint32_t val)\
80 if (val >= _minval && val <= _maxval) {\
81 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,\
82 "BA_%d : beiscsi_"#_name" updated "\
83 "from 0x%x ==> 0x%x\n",\
84 phba->attr_##_name, val); \
85 phba->attr_##_name = val;\
88 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, \
89 "BA_%d beiscsi_"#_name" attribute "\
90 "cannot be updated to 0x%x, "\
91 "range allowed is ["#_minval" - "#_maxval"]\n", val);\
95 #define beiscsi_store_param(_name) \
97 beiscsi_##_name##_store(struct device *dev,\
98 struct device_attribute *attr, const char *buf,\
101 struct Scsi_Host *shost = class_to_shost(dev);\
102 struct beiscsi_hba *phba = iscsi_host_priv(shost);\
103 uint32_t param_val = 0;\
104 if (!isdigit(buf[0]))\
106 if (sscanf(buf, "%i", ¶m_val) != 1)\
108 if (beiscsi_##_name##_change(phba, param_val) == 0) \
114 #define beiscsi_init_param(_name, _minval, _maxval, _defval) \
116 beiscsi_##_name##_init(struct beiscsi_hba *phba, uint32_t val) \
118 if (val >= _minval && val <= _maxval) {\
119 phba->attr_##_name = val;\
122 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,\
123 "BA_%d beiscsi_"#_name" attribute " \
124 "cannot be updated to 0x%x, "\
125 "range allowed is ["#_minval" - "#_maxval"]\n", val);\
126 phba->attr_##_name = _defval;\
130 #define BEISCSI_RW_ATTR(_name, _minval, _maxval, _defval, _descp) \
131 static uint beiscsi_##_name = _defval;\
132 module_param(beiscsi_##_name, uint, S_IRUGO);\
133 MODULE_PARM_DESC(beiscsi_##_name, _descp);\
134 beiscsi_disp_param(_name)\
135 beiscsi_change_param(_name, _minval, _maxval, _defval)\
136 beiscsi_store_param(_name)\
137 beiscsi_init_param(_name, _minval, _maxval, _defval)\
138 DEVICE_ATTR(beiscsi_##_name, S_IRUGO | S_IWUSR,\
139 beiscsi_##_name##_disp, beiscsi_##_name##_store)
142 * When new log level added update the
143 * the MAX allowed value for log_enable
145 BEISCSI_RW_ATTR(log_enable
, 0x00,
146 0xFF, 0x00, "Enable logging Bit Mask\n"
147 "\t\t\t\tInitialization Events : 0x01\n"
148 "\t\t\t\tMailbox Events : 0x02\n"
149 "\t\t\t\tMiscellaneous Events : 0x04\n"
150 "\t\t\t\tError Handling : 0x08\n"
151 "\t\t\t\tIO Path Events : 0x10\n"
152 "\t\t\t\tConfiguration Path : 0x20\n"
153 "\t\t\t\tiSCSI Protocol : 0x40\n");
155 DEVICE_ATTR(beiscsi_drvr_ver
, S_IRUGO
, beiscsi_drvr_ver_disp
, NULL
);
156 DEVICE_ATTR(beiscsi_adapter_family
, S_IRUGO
, beiscsi_adap_family_disp
, NULL
);
157 DEVICE_ATTR(beiscsi_fw_ver
, S_IRUGO
, beiscsi_fw_ver_disp
, NULL
);
158 DEVICE_ATTR(beiscsi_phys_port
, S_IRUGO
, beiscsi_phys_port_disp
, NULL
);
159 DEVICE_ATTR(beiscsi_active_session_count
, S_IRUGO
,
160 beiscsi_active_session_disp
, NULL
);
161 DEVICE_ATTR(beiscsi_free_session_count
, S_IRUGO
,
162 beiscsi_free_session_disp
, NULL
);
163 struct device_attribute
*beiscsi_attrs
[] = {
164 &dev_attr_beiscsi_log_enable
,
165 &dev_attr_beiscsi_drvr_ver
,
166 &dev_attr_beiscsi_adapter_family
,
167 &dev_attr_beiscsi_fw_ver
,
168 &dev_attr_beiscsi_active_session_count
,
169 &dev_attr_beiscsi_free_session_count
,
170 &dev_attr_beiscsi_phys_port
,
174 static char const *cqe_desc
[] = {
177 "SOL_CMD_KILLED_DATA_DIGEST_ERR",
178 "CXN_KILLED_PDU_SIZE_EXCEEDS_DSL",
179 "CXN_KILLED_BURST_LEN_MISMATCH",
180 "CXN_KILLED_AHS_RCVD",
181 "CXN_KILLED_HDR_DIGEST_ERR",
182 "CXN_KILLED_UNKNOWN_HDR",
183 "CXN_KILLED_STALE_ITT_TTT_RCVD",
184 "CXN_KILLED_INVALID_ITT_TTT_RCVD",
185 "CXN_KILLED_RST_RCVD",
186 "CXN_KILLED_TIMED_OUT",
187 "CXN_KILLED_RST_SENT",
188 "CXN_KILLED_FIN_RCVD",
189 "CXN_KILLED_BAD_UNSOL_PDU_RCVD",
190 "CXN_KILLED_BAD_WRB_INDEX_ERROR",
191 "CXN_KILLED_OVER_RUN_RESIDUAL",
192 "CXN_KILLED_UNDER_RUN_RESIDUAL",
193 "CMD_KILLED_INVALID_STATSN_RCVD",
194 "CMD_KILLED_INVALID_R2T_RCVD",
195 "CMD_CXN_KILLED_LUN_INVALID",
196 "CMD_CXN_KILLED_ICD_INVALID",
197 "CMD_CXN_KILLED_ITT_INVALID",
198 "CMD_CXN_KILLED_SEQ_OUTOFORDER",
199 "CMD_CXN_KILLED_INVALID_DATASN_RCVD",
200 "CXN_INVALIDATE_NOTIFY",
201 "CXN_INVALIDATE_INDEX_NOTIFY",
202 "CMD_INVALIDATED_NOTIFY",
205 "UNSOL_DATA_DIGEST_ERROR_NOTIFY",
207 "CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN",
208 "SOL_CMD_KILLED_DIF_ERR",
209 "CXN_KILLED_SYN_RCVD",
210 "CXN_KILLED_IMM_DATA_RCVD"
213 static int beiscsi_slave_configure(struct scsi_device
*sdev
)
215 blk_queue_max_segment_size(sdev
->request_queue
, 65536);
219 static int beiscsi_eh_abort(struct scsi_cmnd
*sc
)
221 struct iscsi_cls_session
*cls_session
;
222 struct iscsi_task
*aborted_task
= (struct iscsi_task
*)sc
->SCp
.ptr
;
223 struct beiscsi_io_task
*aborted_io_task
;
224 struct iscsi_conn
*conn
;
225 struct beiscsi_conn
*beiscsi_conn
;
226 struct beiscsi_hba
*phba
;
227 struct iscsi_session
*session
;
228 struct invalidate_command_table
*inv_tbl
;
229 struct be_dma_mem nonemb_cmd
;
230 unsigned int cid
, tag
, num_invalidate
;
232 cls_session
= starget_to_session(scsi_target(sc
->device
));
233 session
= cls_session
->dd_data
;
235 spin_lock_bh(&session
->lock
);
236 if (!aborted_task
|| !aborted_task
->sc
) {
238 spin_unlock_bh(&session
->lock
);
242 aborted_io_task
= aborted_task
->dd_data
;
243 if (!aborted_io_task
->scsi_cmnd
) {
244 /* raced or invalid command */
245 spin_unlock_bh(&session
->lock
);
248 spin_unlock_bh(&session
->lock
);
249 /* Invalidate WRB Posted for this Task */
250 AMAP_SET_BITS(struct amap_iscsi_wrb
, invld
,
251 aborted_io_task
->pwrb_handle
->pwrb
,
254 conn
= aborted_task
->conn
;
255 beiscsi_conn
= conn
->dd_data
;
256 phba
= beiscsi_conn
->phba
;
258 /* invalidate iocb */
259 cid
= beiscsi_conn
->beiscsi_conn_cid
;
260 inv_tbl
= phba
->inv_tbl
;
261 memset(inv_tbl
, 0x0, sizeof(*inv_tbl
));
263 inv_tbl
->icd
= aborted_io_task
->psgl_handle
->sgl_index
;
265 nonemb_cmd
.va
= pci_alloc_consistent(phba
->ctrl
.pdev
,
266 sizeof(struct invalidate_commands_params_in
),
268 if (nonemb_cmd
.va
== NULL
) {
269 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_EH
,
270 "BM_%d : Failed to allocate memory for"
271 "mgmt_invalidate_icds\n");
274 nonemb_cmd
.size
= sizeof(struct invalidate_commands_params_in
);
276 tag
= mgmt_invalidate_icds(phba
, inv_tbl
, num_invalidate
,
279 beiscsi_log(phba
, KERN_WARNING
, BEISCSI_LOG_EH
,
280 "BM_%d : mgmt_invalidate_icds could not be"
282 pci_free_consistent(phba
->ctrl
.pdev
, nonemb_cmd
.size
,
283 nonemb_cmd
.va
, nonemb_cmd
.dma
);
288 beiscsi_mccq_compl(phba
, tag
, NULL
, nonemb_cmd
.va
);
289 pci_free_consistent(phba
->ctrl
.pdev
, nonemb_cmd
.size
,
290 nonemb_cmd
.va
, nonemb_cmd
.dma
);
291 return iscsi_eh_abort(sc
);
294 static int beiscsi_eh_device_reset(struct scsi_cmnd
*sc
)
296 struct iscsi_task
*abrt_task
;
297 struct beiscsi_io_task
*abrt_io_task
;
298 struct iscsi_conn
*conn
;
299 struct beiscsi_conn
*beiscsi_conn
;
300 struct beiscsi_hba
*phba
;
301 struct iscsi_session
*session
;
302 struct iscsi_cls_session
*cls_session
;
303 struct invalidate_command_table
*inv_tbl
;
304 struct be_dma_mem nonemb_cmd
;
305 unsigned int cid
, tag
, i
, num_invalidate
;
307 /* invalidate iocbs */
308 cls_session
= starget_to_session(scsi_target(sc
->device
));
309 session
= cls_session
->dd_data
;
310 spin_lock_bh(&session
->lock
);
311 if (!session
->leadconn
|| session
->state
!= ISCSI_STATE_LOGGED_IN
) {
312 spin_unlock_bh(&session
->lock
);
315 conn
= session
->leadconn
;
316 beiscsi_conn
= conn
->dd_data
;
317 phba
= beiscsi_conn
->phba
;
318 cid
= beiscsi_conn
->beiscsi_conn_cid
;
319 inv_tbl
= phba
->inv_tbl
;
320 memset(inv_tbl
, 0x0, sizeof(*inv_tbl
) * BE2_CMDS_PER_CXN
);
322 for (i
= 0; i
< conn
->session
->cmds_max
; i
++) {
323 abrt_task
= conn
->session
->cmds
[i
];
324 abrt_io_task
= abrt_task
->dd_data
;
325 if (!abrt_task
->sc
|| abrt_task
->state
== ISCSI_TASK_FREE
)
328 if (abrt_task
->sc
->device
->lun
!= abrt_task
->sc
->device
->lun
)
331 /* Invalidate WRB Posted for this Task */
332 AMAP_SET_BITS(struct amap_iscsi_wrb
, invld
,
333 abrt_io_task
->pwrb_handle
->pwrb
,
337 inv_tbl
->icd
= abrt_io_task
->psgl_handle
->sgl_index
;
341 spin_unlock_bh(&session
->lock
);
342 inv_tbl
= phba
->inv_tbl
;
344 nonemb_cmd
.va
= pci_alloc_consistent(phba
->ctrl
.pdev
,
345 sizeof(struct invalidate_commands_params_in
),
347 if (nonemb_cmd
.va
== NULL
) {
348 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_EH
,
349 "BM_%d : Failed to allocate memory for"
350 "mgmt_invalidate_icds\n");
353 nonemb_cmd
.size
= sizeof(struct invalidate_commands_params_in
);
354 memset(nonemb_cmd
.va
, 0, nonemb_cmd
.size
);
355 tag
= mgmt_invalidate_icds(phba
, inv_tbl
, num_invalidate
,
358 beiscsi_log(phba
, KERN_WARNING
, BEISCSI_LOG_EH
,
359 "BM_%d : mgmt_invalidate_icds could not be"
361 pci_free_consistent(phba
->ctrl
.pdev
, nonemb_cmd
.size
,
362 nonemb_cmd
.va
, nonemb_cmd
.dma
);
366 beiscsi_mccq_compl(phba
, tag
, NULL
, nonemb_cmd
.va
);
367 pci_free_consistent(phba
->ctrl
.pdev
, nonemb_cmd
.size
,
368 nonemb_cmd
.va
, nonemb_cmd
.dma
);
369 return iscsi_eh_device_reset(sc
);
372 static ssize_t
beiscsi_show_boot_tgt_info(void *data
, int type
, char *buf
)
374 struct beiscsi_hba
*phba
= data
;
375 struct mgmt_session_info
*boot_sess
= &phba
->boot_sess
;
376 struct mgmt_conn_info
*boot_conn
= &boot_sess
->conn_list
[0];
381 case ISCSI_BOOT_TGT_NAME
:
382 rc
= sprintf(buf
, "%.*s\n",
383 (int)strlen(boot_sess
->target_name
),
384 (char *)&boot_sess
->target_name
);
386 case ISCSI_BOOT_TGT_IP_ADDR
:
387 if (boot_conn
->dest_ipaddr
.ip_type
== 0x1)
388 rc
= sprintf(buf
, "%pI4\n",
389 (char *)&boot_conn
->dest_ipaddr
.addr
);
391 rc
= sprintf(str
, "%pI6\n",
392 (char *)&boot_conn
->dest_ipaddr
.addr
);
394 case ISCSI_BOOT_TGT_PORT
:
395 rc
= sprintf(str
, "%d\n", boot_conn
->dest_port
);
398 case ISCSI_BOOT_TGT_CHAP_NAME
:
399 rc
= sprintf(str
, "%.*s\n",
400 boot_conn
->negotiated_login_options
.auth_data
.chap
.
401 target_chap_name_length
,
402 (char *)&boot_conn
->negotiated_login_options
.
403 auth_data
.chap
.target_chap_name
);
405 case ISCSI_BOOT_TGT_CHAP_SECRET
:
406 rc
= sprintf(str
, "%.*s\n",
407 boot_conn
->negotiated_login_options
.auth_data
.chap
.
408 target_secret_length
,
409 (char *)&boot_conn
->negotiated_login_options
.
410 auth_data
.chap
.target_secret
);
412 case ISCSI_BOOT_TGT_REV_CHAP_NAME
:
413 rc
= sprintf(str
, "%.*s\n",
414 boot_conn
->negotiated_login_options
.auth_data
.chap
.
415 intr_chap_name_length
,
416 (char *)&boot_conn
->negotiated_login_options
.
417 auth_data
.chap
.intr_chap_name
);
419 case ISCSI_BOOT_TGT_REV_CHAP_SECRET
:
420 rc
= sprintf(str
, "%.*s\n",
421 boot_conn
->negotiated_login_options
.auth_data
.chap
.
423 (char *)&boot_conn
->negotiated_login_options
.
424 auth_data
.chap
.intr_secret
);
426 case ISCSI_BOOT_TGT_FLAGS
:
427 rc
= sprintf(str
, "2\n");
429 case ISCSI_BOOT_TGT_NIC_ASSOC
:
430 rc
= sprintf(str
, "0\n");
439 static ssize_t
beiscsi_show_boot_ini_info(void *data
, int type
, char *buf
)
441 struct beiscsi_hba
*phba
= data
;
446 case ISCSI_BOOT_INI_INITIATOR_NAME
:
447 rc
= sprintf(str
, "%s\n", phba
->boot_sess
.initiator_iscsiname
);
456 static ssize_t
beiscsi_show_boot_eth_info(void *data
, int type
, char *buf
)
458 struct beiscsi_hba
*phba
= data
;
463 case ISCSI_BOOT_ETH_FLAGS
:
464 rc
= sprintf(str
, "2\n");
466 case ISCSI_BOOT_ETH_INDEX
:
467 rc
= sprintf(str
, "0\n");
469 case ISCSI_BOOT_ETH_MAC
:
470 rc
= beiscsi_get_macaddr(str
, phba
);
480 static umode_t
beiscsi_tgt_get_attr_visibility(void *data
, int type
)
485 case ISCSI_BOOT_TGT_NAME
:
486 case ISCSI_BOOT_TGT_IP_ADDR
:
487 case ISCSI_BOOT_TGT_PORT
:
488 case ISCSI_BOOT_TGT_CHAP_NAME
:
489 case ISCSI_BOOT_TGT_CHAP_SECRET
:
490 case ISCSI_BOOT_TGT_REV_CHAP_NAME
:
491 case ISCSI_BOOT_TGT_REV_CHAP_SECRET
:
492 case ISCSI_BOOT_TGT_NIC_ASSOC
:
493 case ISCSI_BOOT_TGT_FLAGS
:
503 static umode_t
beiscsi_ini_get_attr_visibility(void *data
, int type
)
508 case ISCSI_BOOT_INI_INITIATOR_NAME
:
519 static umode_t
beiscsi_eth_get_attr_visibility(void *data
, int type
)
524 case ISCSI_BOOT_ETH_FLAGS
:
525 case ISCSI_BOOT_ETH_MAC
:
526 case ISCSI_BOOT_ETH_INDEX
:
536 /*------------------- PCI Driver operations and data ----------------- */
537 static DEFINE_PCI_DEVICE_TABLE(beiscsi_pci_id_table
) = {
538 { PCI_DEVICE(BE_VENDOR_ID
, BE_DEVICE_ID1
) },
539 { PCI_DEVICE(BE_VENDOR_ID
, BE_DEVICE_ID2
) },
540 { PCI_DEVICE(BE_VENDOR_ID
, OC_DEVICE_ID1
) },
541 { PCI_DEVICE(BE_VENDOR_ID
, OC_DEVICE_ID2
) },
542 { PCI_DEVICE(BE_VENDOR_ID
, OC_DEVICE_ID3
) },
543 { PCI_DEVICE(ELX_VENDOR_ID
, OC_SKH_ID1
) },
546 MODULE_DEVICE_TABLE(pci
, beiscsi_pci_id_table
);
549 static struct scsi_host_template beiscsi_sht
= {
550 .module
= THIS_MODULE
,
551 .name
= "Emulex 10Gbe open-iscsi Initiator Driver",
552 .proc_name
= DRV_NAME
,
553 .queuecommand
= iscsi_queuecommand
,
554 .change_queue_depth
= iscsi_change_queue_depth
,
555 .slave_configure
= beiscsi_slave_configure
,
556 .target_alloc
= iscsi_target_alloc
,
557 .eh_abort_handler
= beiscsi_eh_abort
,
558 .eh_device_reset_handler
= beiscsi_eh_device_reset
,
559 .eh_target_reset_handler
= iscsi_eh_session_reset
,
560 .shost_attrs
= beiscsi_attrs
,
561 .sg_tablesize
= BEISCSI_SGLIST_ELEMENTS
,
562 .can_queue
= BE2_IO_DEPTH
,
564 .max_sectors
= BEISCSI_MAX_SECTORS
,
565 .cmd_per_lun
= BEISCSI_CMD_PER_LUN
,
566 .use_clustering
= ENABLE_CLUSTERING
,
567 .vendor_id
= SCSI_NL_VID_TYPE_PCI
| BE_VENDOR_ID
,
571 static struct scsi_transport_template
*beiscsi_scsi_transport
;
573 static struct beiscsi_hba
*beiscsi_hba_alloc(struct pci_dev
*pcidev
)
575 struct beiscsi_hba
*phba
;
576 struct Scsi_Host
*shost
;
578 shost
= iscsi_host_alloc(&beiscsi_sht
, sizeof(*phba
), 0);
580 dev_err(&pcidev
->dev
,
581 "beiscsi_hba_alloc - iscsi_host_alloc failed\n");
584 shost
->dma_boundary
= pcidev
->dma_mask
;
585 shost
->max_id
= BE2_MAX_SESSIONS
;
586 shost
->max_channel
= 0;
587 shost
->max_cmd_len
= BEISCSI_MAX_CMD_LEN
;
588 shost
->max_lun
= BEISCSI_NUM_MAX_LUN
;
589 shost
->transportt
= beiscsi_scsi_transport
;
590 phba
= iscsi_host_priv(shost
);
591 memset(phba
, 0, sizeof(*phba
));
593 phba
->pcidev
= pci_dev_get(pcidev
);
594 pci_set_drvdata(pcidev
, phba
);
595 phba
->interface_handle
= 0xFFFFFFFF;
597 if (iscsi_host_add(shost
, &phba
->pcidev
->dev
))
603 pci_dev_put(phba
->pcidev
);
604 iscsi_host_free(phba
->shost
);
608 static void beiscsi_unmap_pci_function(struct beiscsi_hba
*phba
)
611 iounmap(phba
->csr_va
);
615 iounmap(phba
->db_va
);
619 iounmap(phba
->pci_va
);
624 static int beiscsi_map_pci_bars(struct beiscsi_hba
*phba
,
625 struct pci_dev
*pcidev
)
630 addr
= ioremap_nocache(pci_resource_start(pcidev
, 2),
631 pci_resource_len(pcidev
, 2));
634 phba
->ctrl
.csr
= addr
;
636 phba
->csr_pa
.u
.a64
.address
= pci_resource_start(pcidev
, 2);
638 addr
= ioremap_nocache(pci_resource_start(pcidev
, 4), 128 * 1024);
641 phba
->ctrl
.db
= addr
;
643 phba
->db_pa
.u
.a64
.address
= pci_resource_start(pcidev
, 4);
645 if (phba
->generation
== BE_GEN2
)
650 addr
= ioremap_nocache(pci_resource_start(pcidev
, pcicfg_reg
),
651 pci_resource_len(pcidev
, pcicfg_reg
));
655 phba
->ctrl
.pcicfg
= addr
;
657 phba
->pci_pa
.u
.a64
.address
= pci_resource_start(pcidev
, pcicfg_reg
);
661 beiscsi_unmap_pci_function(phba
);
665 static int beiscsi_enable_pci(struct pci_dev
*pcidev
)
669 ret
= pci_enable_device(pcidev
);
671 dev_err(&pcidev
->dev
,
672 "beiscsi_enable_pci - enable device failed\n");
676 pci_set_master(pcidev
);
677 if (pci_set_consistent_dma_mask(pcidev
, DMA_BIT_MASK(64))) {
678 ret
= pci_set_consistent_dma_mask(pcidev
, DMA_BIT_MASK(32));
680 dev_err(&pcidev
->dev
, "Could not set PCI DMA Mask\n");
681 pci_disable_device(pcidev
);
688 static int be_ctrl_init(struct beiscsi_hba
*phba
, struct pci_dev
*pdev
)
690 struct be_ctrl_info
*ctrl
= &phba
->ctrl
;
691 struct be_dma_mem
*mbox_mem_alloc
= &ctrl
->mbox_mem_alloced
;
692 struct be_dma_mem
*mbox_mem_align
= &ctrl
->mbox_mem
;
696 status
= beiscsi_map_pci_bars(phba
, pdev
);
699 mbox_mem_alloc
->size
= sizeof(struct be_mcc_mailbox
) + 16;
700 mbox_mem_alloc
->va
= pci_alloc_consistent(pdev
,
701 mbox_mem_alloc
->size
,
702 &mbox_mem_alloc
->dma
);
703 if (!mbox_mem_alloc
->va
) {
704 beiscsi_unmap_pci_function(phba
);
708 mbox_mem_align
->size
= sizeof(struct be_mcc_mailbox
);
709 mbox_mem_align
->va
= PTR_ALIGN(mbox_mem_alloc
->va
, 16);
710 mbox_mem_align
->dma
= PTR_ALIGN(mbox_mem_alloc
->dma
, 16);
711 memset(mbox_mem_align
->va
, 0, sizeof(struct be_mcc_mailbox
));
712 spin_lock_init(&ctrl
->mbox_lock
);
713 spin_lock_init(&phba
->ctrl
.mcc_lock
);
714 spin_lock_init(&phba
->ctrl
.mcc_cq_lock
);
720 * beiscsi_get_params()- Set the config paramters
721 * @phba: ptr device priv structure
723 static void beiscsi_get_params(struct beiscsi_hba
*phba
)
725 uint32_t total_cid_count
= 0;
726 uint32_t total_icd_count
= 0;
729 total_cid_count
= BEISCSI_GET_CID_COUNT(phba
, BEISCSI_ULP0
) +
730 BEISCSI_GET_CID_COUNT(phba
, BEISCSI_ULP1
);
732 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++) {
733 uint32_t align_mask
= 0;
734 uint32_t icd_post_per_page
= 0;
735 uint32_t icd_count_unavailable
= 0;
736 uint32_t icd_start
= 0, icd_count
= 0;
737 uint32_t icd_start_align
= 0, icd_count_align
= 0;
739 if (test_bit(ulp_num
, &phba
->fw_config
.ulp_supported
)) {
740 icd_start
= phba
->fw_config
.iscsi_icd_start
[ulp_num
];
741 icd_count
= phba
->fw_config
.iscsi_icd_count
[ulp_num
];
743 /* Get ICD count that can be posted on each page */
744 icd_post_per_page
= (PAGE_SIZE
/ (BE2_SGE
*
745 sizeof(struct iscsi_sge
)));
746 align_mask
= (icd_post_per_page
- 1);
748 /* Check if icd_start is aligned ICD per page posting */
749 if (icd_start
% icd_post_per_page
) {
750 icd_start_align
= ((icd_start
+
754 iscsi_icd_start
[ulp_num
] =
758 icd_count_align
= (icd_count
& ~align_mask
);
760 /* ICD discarded in the process of alignment */
762 icd_count_unavailable
= ((icd_start_align
-
767 /* Updated ICD count available */
768 phba
->fw_config
.iscsi_icd_count
[ulp_num
] = (icd_count
-
769 icd_count_unavailable
);
771 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
772 "BM_%d : Aligned ICD values\n"
773 "\t ICD Start : %d\n"
774 "\t ICD Count : %d\n"
775 "\t ICD Discarded : %d\n",
777 iscsi_icd_start
[ulp_num
],
779 iscsi_icd_count
[ulp_num
],
780 icd_count_unavailable
);
785 total_icd_count
= phba
->fw_config
.iscsi_icd_count
[ulp_num
];
786 phba
->params
.ios_per_ctrl
= (total_icd_count
-
788 BE2_TMFS
+ BE2_NOPOUT_REQ
));
789 phba
->params
.cxns_per_ctrl
= total_cid_count
;
790 phba
->params
.asyncpdus_per_ctrl
= total_cid_count
;
791 phba
->params
.icds_per_ctrl
= total_icd_count
;
792 phba
->params
.num_sge_per_io
= BE2_SGE
;
793 phba
->params
.defpdu_hdr_sz
= BE2_DEFPDU_HDR_SZ
;
794 phba
->params
.defpdu_data_sz
= BE2_DEFPDU_DATA_SZ
;
795 phba
->params
.eq_timer
= 64;
796 phba
->params
.num_eq_entries
= 1024;
797 phba
->params
.num_cq_entries
= 1024;
798 phba
->params
.wrbs_per_cxn
= 256;
801 static void hwi_ring_eq_db(struct beiscsi_hba
*phba
,
802 unsigned int id
, unsigned int clr_interrupt
,
803 unsigned int num_processed
,
804 unsigned char rearm
, unsigned char event
)
807 val
|= id
& DB_EQ_RING_ID_MASK
;
809 val
|= 1 << DB_EQ_REARM_SHIFT
;
811 val
|= 1 << DB_EQ_CLR_SHIFT
;
813 val
|= 1 << DB_EQ_EVNT_SHIFT
;
814 val
|= num_processed
<< DB_EQ_NUM_POPPED_SHIFT
;
815 iowrite32(val
, phba
->db_va
+ DB_EQ_OFFSET
);
819 * be_isr_mcc - The isr routine of the driver.
821 * @dev_id: Pointer to host adapter structure
823 static irqreturn_t
be_isr_mcc(int irq
, void *dev_id
)
825 struct beiscsi_hba
*phba
;
826 struct be_eq_entry
*eqe
= NULL
;
827 struct be_queue_info
*eq
;
828 struct be_queue_info
*mcc
;
829 unsigned int num_eq_processed
;
830 struct be_eq_obj
*pbe_eq
;
836 mcc
= &phba
->ctrl
.mcc_obj
.cq
;
837 eqe
= queue_tail_node(eq
);
839 num_eq_processed
= 0;
841 while (eqe
->dw
[offsetof(struct amap_eq_entry
, valid
) / 32]
843 if (((eqe
->dw
[offsetof(struct amap_eq_entry
,
845 EQE_RESID_MASK
) >> 16) == mcc
->id
) {
846 spin_lock_irqsave(&phba
->isr_lock
, flags
);
847 pbe_eq
->todo_mcc_cq
= true;
848 spin_unlock_irqrestore(&phba
->isr_lock
, flags
);
850 AMAP_SET_BITS(struct amap_eq_entry
, valid
, eqe
, 0);
852 eqe
= queue_tail_node(eq
);
855 if (pbe_eq
->todo_mcc_cq
)
856 queue_work(phba
->wq
, &pbe_eq
->work_cqs
);
857 if (num_eq_processed
)
858 hwi_ring_eq_db(phba
, eq
->id
, 1, num_eq_processed
, 1, 1);
864 * be_isr_msix - The isr routine of the driver.
866 * @dev_id: Pointer to host adapter structure
868 static irqreturn_t
be_isr_msix(int irq
, void *dev_id
)
870 struct beiscsi_hba
*phba
;
871 struct be_eq_entry
*eqe
= NULL
;
872 struct be_queue_info
*eq
;
873 struct be_queue_info
*cq
;
874 unsigned int num_eq_processed
;
875 struct be_eq_obj
*pbe_eq
;
881 eqe
= queue_tail_node(eq
);
884 num_eq_processed
= 0;
885 if (blk_iopoll_enabled
) {
886 while (eqe
->dw
[offsetof(struct amap_eq_entry
, valid
) / 32]
888 if (!blk_iopoll_sched_prep(&pbe_eq
->iopoll
))
889 blk_iopoll_sched(&pbe_eq
->iopoll
);
891 AMAP_SET_BITS(struct amap_eq_entry
, valid
, eqe
, 0);
893 eqe
= queue_tail_node(eq
);
897 while (eqe
->dw
[offsetof(struct amap_eq_entry
, valid
) / 32]
899 spin_lock_irqsave(&phba
->isr_lock
, flags
);
900 pbe_eq
->todo_cq
= true;
901 spin_unlock_irqrestore(&phba
->isr_lock
, flags
);
902 AMAP_SET_BITS(struct amap_eq_entry
, valid
, eqe
, 0);
904 eqe
= queue_tail_node(eq
);
909 queue_work(phba
->wq
, &pbe_eq
->work_cqs
);
912 if (num_eq_processed
)
913 hwi_ring_eq_db(phba
, eq
->id
, 1, num_eq_processed
, 0, 1);
919 * be_isr - The isr routine of the driver.
921 * @dev_id: Pointer to host adapter structure
923 static irqreturn_t
be_isr(int irq
, void *dev_id
)
925 struct beiscsi_hba
*phba
;
926 struct hwi_controller
*phwi_ctrlr
;
927 struct hwi_context_memory
*phwi_context
;
928 struct be_eq_entry
*eqe
= NULL
;
929 struct be_queue_info
*eq
;
930 struct be_queue_info
*cq
;
931 struct be_queue_info
*mcc
;
932 unsigned long flags
, index
;
933 unsigned int num_mcceq_processed
, num_ioeq_processed
;
934 struct be_ctrl_info
*ctrl
;
935 struct be_eq_obj
*pbe_eq
;
940 isr
= ioread32(ctrl
->csr
+ CEV_ISR0_OFFSET
+
941 (PCI_FUNC(ctrl
->pdev
->devfn
) * CEV_ISR_SIZE
));
945 phwi_ctrlr
= phba
->phwi_ctrlr
;
946 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
947 pbe_eq
= &phwi_context
->be_eq
[0];
949 eq
= &phwi_context
->be_eq
[0].q
;
950 mcc
= &phba
->ctrl
.mcc_obj
.cq
;
952 eqe
= queue_tail_node(eq
);
954 num_ioeq_processed
= 0;
955 num_mcceq_processed
= 0;
956 if (blk_iopoll_enabled
) {
957 while (eqe
->dw
[offsetof(struct amap_eq_entry
, valid
) / 32]
959 if (((eqe
->dw
[offsetof(struct amap_eq_entry
,
961 EQE_RESID_MASK
) >> 16) == mcc
->id
) {
962 spin_lock_irqsave(&phba
->isr_lock
, flags
);
963 pbe_eq
->todo_mcc_cq
= true;
964 spin_unlock_irqrestore(&phba
->isr_lock
, flags
);
965 num_mcceq_processed
++;
967 if (!blk_iopoll_sched_prep(&pbe_eq
->iopoll
))
968 blk_iopoll_sched(&pbe_eq
->iopoll
);
969 num_ioeq_processed
++;
971 AMAP_SET_BITS(struct amap_eq_entry
, valid
, eqe
, 0);
973 eqe
= queue_tail_node(eq
);
975 if (num_ioeq_processed
|| num_mcceq_processed
) {
976 if (pbe_eq
->todo_mcc_cq
)
977 queue_work(phba
->wq
, &pbe_eq
->work_cqs
);
979 if ((num_mcceq_processed
) && (!num_ioeq_processed
))
980 hwi_ring_eq_db(phba
, eq
->id
, 0,
981 (num_ioeq_processed
+
982 num_mcceq_processed
) , 1, 1);
984 hwi_ring_eq_db(phba
, eq
->id
, 0,
985 (num_ioeq_processed
+
986 num_mcceq_processed
), 0, 1);
992 cq
= &phwi_context
->be_cq
[0];
993 while (eqe
->dw
[offsetof(struct amap_eq_entry
, valid
) / 32]
996 if (((eqe
->dw
[offsetof(struct amap_eq_entry
,
998 EQE_RESID_MASK
) >> 16) != cq
->id
) {
999 spin_lock_irqsave(&phba
->isr_lock
, flags
);
1000 pbe_eq
->todo_mcc_cq
= true;
1001 spin_unlock_irqrestore(&phba
->isr_lock
, flags
);
1003 spin_lock_irqsave(&phba
->isr_lock
, flags
);
1004 pbe_eq
->todo_cq
= true;
1005 spin_unlock_irqrestore(&phba
->isr_lock
, flags
);
1007 AMAP_SET_BITS(struct amap_eq_entry
, valid
, eqe
, 0);
1009 eqe
= queue_tail_node(eq
);
1010 num_ioeq_processed
++;
1012 if (pbe_eq
->todo_cq
|| pbe_eq
->todo_mcc_cq
)
1013 queue_work(phba
->wq
, &pbe_eq
->work_cqs
);
1015 if (num_ioeq_processed
) {
1016 hwi_ring_eq_db(phba
, eq
->id
, 0,
1017 num_ioeq_processed
, 1, 1);
1024 static int beiscsi_init_irqs(struct beiscsi_hba
*phba
)
1026 struct pci_dev
*pcidev
= phba
->pcidev
;
1027 struct hwi_controller
*phwi_ctrlr
;
1028 struct hwi_context_memory
*phwi_context
;
1029 int ret
, msix_vec
, i
, j
;
1031 phwi_ctrlr
= phba
->phwi_ctrlr
;
1032 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
1034 if (phba
->msix_enabled
) {
1035 for (i
= 0; i
< phba
->num_cpus
; i
++) {
1036 phba
->msi_name
[i
] = kzalloc(BEISCSI_MSI_NAME
,
1038 if (!phba
->msi_name
[i
]) {
1040 goto free_msix_irqs
;
1043 sprintf(phba
->msi_name
[i
], "beiscsi_%02x_%02x",
1044 phba
->shost
->host_no
, i
);
1045 msix_vec
= phba
->msix_entries
[i
].vector
;
1046 ret
= request_irq(msix_vec
, be_isr_msix
, 0,
1048 &phwi_context
->be_eq
[i
]);
1050 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
1051 "BM_%d : beiscsi_init_irqs-Failed to"
1052 "register msix for i = %d\n",
1054 kfree(phba
->msi_name
[i
]);
1055 goto free_msix_irqs
;
1058 phba
->msi_name
[i
] = kzalloc(BEISCSI_MSI_NAME
, GFP_KERNEL
);
1059 if (!phba
->msi_name
[i
]) {
1061 goto free_msix_irqs
;
1063 sprintf(phba
->msi_name
[i
], "beiscsi_mcc_%02x",
1064 phba
->shost
->host_no
);
1065 msix_vec
= phba
->msix_entries
[i
].vector
;
1066 ret
= request_irq(msix_vec
, be_isr_mcc
, 0, phba
->msi_name
[i
],
1067 &phwi_context
->be_eq
[i
]);
1069 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
1070 "BM_%d : beiscsi_init_irqs-"
1071 "Failed to register beiscsi_msix_mcc\n");
1072 kfree(phba
->msi_name
[i
]);
1073 goto free_msix_irqs
;
1077 ret
= request_irq(pcidev
->irq
, be_isr
, IRQF_SHARED
,
1080 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
1081 "BM_%d : beiscsi_init_irqs-"
1082 "Failed to register irq\\n");
1088 for (j
= i
- 1; j
>= 0; j
--) {
1089 kfree(phba
->msi_name
[j
]);
1090 msix_vec
= phba
->msix_entries
[j
].vector
;
1091 free_irq(msix_vec
, &phwi_context
->be_eq
[j
]);
1096 static void hwi_ring_cq_db(struct beiscsi_hba
*phba
,
1097 unsigned int id
, unsigned int num_processed
,
1098 unsigned char rearm
, unsigned char event
)
1101 val
|= id
& DB_CQ_RING_ID_MASK
;
1103 val
|= 1 << DB_CQ_REARM_SHIFT
;
1104 val
|= num_processed
<< DB_CQ_NUM_POPPED_SHIFT
;
1105 iowrite32(val
, phba
->db_va
+ DB_CQ_OFFSET
);
1109 beiscsi_process_async_pdu(struct beiscsi_conn
*beiscsi_conn
,
1110 struct beiscsi_hba
*phba
,
1111 struct pdu_base
*ppdu
,
1112 unsigned long pdu_len
,
1113 void *pbuffer
, unsigned long buf_len
)
1115 struct iscsi_conn
*conn
= beiscsi_conn
->conn
;
1116 struct iscsi_session
*session
= conn
->session
;
1117 struct iscsi_task
*task
;
1118 struct beiscsi_io_task
*io_task
;
1119 struct iscsi_hdr
*login_hdr
;
1121 switch (ppdu
->dw
[offsetof(struct amap_pdu_base
, opcode
) / 32] &
1122 PDUBASE_OPCODE_MASK
) {
1123 case ISCSI_OP_NOOP_IN
:
1127 case ISCSI_OP_ASYNC_EVENT
:
1129 case ISCSI_OP_REJECT
:
1131 WARN_ON(!(buf_len
== 48));
1132 beiscsi_log(phba
, KERN_ERR
,
1133 BEISCSI_LOG_CONFIG
| BEISCSI_LOG_IO
,
1134 "BM_%d : In ISCSI_OP_REJECT\n");
1136 case ISCSI_OP_LOGIN_RSP
:
1137 case ISCSI_OP_TEXT_RSP
:
1138 task
= conn
->login_task
;
1139 io_task
= task
->dd_data
;
1140 login_hdr
= (struct iscsi_hdr
*)ppdu
;
1141 login_hdr
->itt
= io_task
->libiscsi_itt
;
1144 beiscsi_log(phba
, KERN_WARNING
,
1145 BEISCSI_LOG_IO
| BEISCSI_LOG_CONFIG
,
1146 "BM_%d : Unrecognized opcode 0x%x in async msg\n",
1148 dw
[offsetof(struct amap_pdu_base
, opcode
) / 32]
1149 & PDUBASE_OPCODE_MASK
));
1153 spin_lock_bh(&session
->lock
);
1154 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)ppdu
, pbuffer
, buf_len
);
1155 spin_unlock_bh(&session
->lock
);
1159 static struct sgl_handle
*alloc_io_sgl_handle(struct beiscsi_hba
*phba
)
1161 struct sgl_handle
*psgl_handle
;
1163 if (phba
->io_sgl_hndl_avbl
) {
1164 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_IO
,
1165 "BM_%d : In alloc_io_sgl_handle,"
1166 " io_sgl_alloc_index=%d\n",
1167 phba
->io_sgl_alloc_index
);
1169 psgl_handle
= phba
->io_sgl_hndl_base
[phba
->
1170 io_sgl_alloc_index
];
1171 phba
->io_sgl_hndl_base
[phba
->io_sgl_alloc_index
] = NULL
;
1172 phba
->io_sgl_hndl_avbl
--;
1173 if (phba
->io_sgl_alloc_index
== (phba
->params
.
1175 phba
->io_sgl_alloc_index
= 0;
1177 phba
->io_sgl_alloc_index
++;
1184 free_io_sgl_handle(struct beiscsi_hba
*phba
, struct sgl_handle
*psgl_handle
)
1186 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_IO
,
1187 "BM_%d : In free_,io_sgl_free_index=%d\n",
1188 phba
->io_sgl_free_index
);
1190 if (phba
->io_sgl_hndl_base
[phba
->io_sgl_free_index
]) {
1192 * this can happen if clean_task is called on a task that
1193 * failed in xmit_task or alloc_pdu.
1195 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_IO
,
1196 "BM_%d : Double Free in IO SGL io_sgl_free_index=%d,"
1197 "value there=%p\n", phba
->io_sgl_free_index
,
1198 phba
->io_sgl_hndl_base
1199 [phba
->io_sgl_free_index
]);
1202 phba
->io_sgl_hndl_base
[phba
->io_sgl_free_index
] = psgl_handle
;
1203 phba
->io_sgl_hndl_avbl
++;
1204 if (phba
->io_sgl_free_index
== (phba
->params
.ios_per_ctrl
- 1))
1205 phba
->io_sgl_free_index
= 0;
1207 phba
->io_sgl_free_index
++;
1211 * alloc_wrb_handle - To allocate a wrb handle
1212 * @phba: The hba pointer
1213 * @cid: The cid to use for allocation
1215 * This happens under session_lock until submission to chip
1217 struct wrb_handle
*alloc_wrb_handle(struct beiscsi_hba
*phba
, unsigned int cid
)
1219 struct hwi_wrb_context
*pwrb_context
;
1220 struct hwi_controller
*phwi_ctrlr
;
1221 struct wrb_handle
*pwrb_handle
, *pwrb_handle_tmp
;
1222 uint16_t cri_index
= BE_GET_CRI_FROM_CID(cid
);
1224 phwi_ctrlr
= phba
->phwi_ctrlr
;
1225 pwrb_context
= &phwi_ctrlr
->wrb_context
[cri_index
];
1226 if (pwrb_context
->wrb_handles_available
>= 2) {
1227 pwrb_handle
= pwrb_context
->pwrb_handle_base
[
1228 pwrb_context
->alloc_index
];
1229 pwrb_context
->wrb_handles_available
--;
1230 if (pwrb_context
->alloc_index
==
1231 (phba
->params
.wrbs_per_cxn
- 1))
1232 pwrb_context
->alloc_index
= 0;
1234 pwrb_context
->alloc_index
++;
1235 pwrb_handle_tmp
= pwrb_context
->pwrb_handle_base
[
1236 pwrb_context
->alloc_index
];
1237 pwrb_handle
->nxt_wrb_index
= pwrb_handle_tmp
->wrb_index
;
1244 * free_wrb_handle - To free the wrb handle back to pool
1245 * @phba: The hba pointer
1246 * @pwrb_context: The context to free from
1247 * @pwrb_handle: The wrb_handle to free
1249 * This happens under session_lock until submission to chip
1252 free_wrb_handle(struct beiscsi_hba
*phba
, struct hwi_wrb_context
*pwrb_context
,
1253 struct wrb_handle
*pwrb_handle
)
1255 pwrb_context
->pwrb_handle_base
[pwrb_context
->free_index
] = pwrb_handle
;
1256 pwrb_context
->wrb_handles_available
++;
1257 if (pwrb_context
->free_index
== (phba
->params
.wrbs_per_cxn
- 1))
1258 pwrb_context
->free_index
= 0;
1260 pwrb_context
->free_index
++;
1262 beiscsi_log(phba
, KERN_INFO
,
1263 BEISCSI_LOG_IO
| BEISCSI_LOG_CONFIG
,
1264 "BM_%d : FREE WRB: pwrb_handle=%p free_index=0x%x"
1265 "wrb_handles_available=%d\n",
1266 pwrb_handle
, pwrb_context
->free_index
,
1267 pwrb_context
->wrb_handles_available
);
1270 static struct sgl_handle
*alloc_mgmt_sgl_handle(struct beiscsi_hba
*phba
)
1272 struct sgl_handle
*psgl_handle
;
1274 if (phba
->eh_sgl_hndl_avbl
) {
1275 psgl_handle
= phba
->eh_sgl_hndl_base
[phba
->eh_sgl_alloc_index
];
1276 phba
->eh_sgl_hndl_base
[phba
->eh_sgl_alloc_index
] = NULL
;
1277 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_CONFIG
,
1278 "BM_%d : mgmt_sgl_alloc_index=%d=0x%x\n",
1279 phba
->eh_sgl_alloc_index
,
1280 phba
->eh_sgl_alloc_index
);
1282 phba
->eh_sgl_hndl_avbl
--;
1283 if (phba
->eh_sgl_alloc_index
==
1284 (phba
->params
.icds_per_ctrl
- phba
->params
.ios_per_ctrl
-
1286 phba
->eh_sgl_alloc_index
= 0;
1288 phba
->eh_sgl_alloc_index
++;
1295 free_mgmt_sgl_handle(struct beiscsi_hba
*phba
, struct sgl_handle
*psgl_handle
)
1298 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_CONFIG
,
1299 "BM_%d : In free_mgmt_sgl_handle,"
1300 "eh_sgl_free_index=%d\n",
1301 phba
->eh_sgl_free_index
);
1303 if (phba
->eh_sgl_hndl_base
[phba
->eh_sgl_free_index
]) {
1305 * this can happen if clean_task is called on a task that
1306 * failed in xmit_task or alloc_pdu.
1308 beiscsi_log(phba
, KERN_WARNING
, BEISCSI_LOG_CONFIG
,
1309 "BM_%d : Double Free in eh SGL ,"
1310 "eh_sgl_free_index=%d\n",
1311 phba
->eh_sgl_free_index
);
1314 phba
->eh_sgl_hndl_base
[phba
->eh_sgl_free_index
] = psgl_handle
;
1315 phba
->eh_sgl_hndl_avbl
++;
1316 if (phba
->eh_sgl_free_index
==
1317 (phba
->params
.icds_per_ctrl
- phba
->params
.ios_per_ctrl
- 1))
1318 phba
->eh_sgl_free_index
= 0;
1320 phba
->eh_sgl_free_index
++;
1324 be_complete_io(struct beiscsi_conn
*beiscsi_conn
,
1325 struct iscsi_task
*task
,
1326 struct common_sol_cqe
*csol_cqe
)
1328 struct beiscsi_io_task
*io_task
= task
->dd_data
;
1329 struct be_status_bhs
*sts_bhs
=
1330 (struct be_status_bhs
*)io_task
->cmd_bhs
;
1331 struct iscsi_conn
*conn
= beiscsi_conn
->conn
;
1332 unsigned char *sense
;
1333 u32 resid
= 0, exp_cmdsn
, max_cmdsn
;
1334 u8 rsp
, status
, flags
;
1336 exp_cmdsn
= csol_cqe
->exp_cmdsn
;
1337 max_cmdsn
= (csol_cqe
->exp_cmdsn
+
1338 csol_cqe
->cmd_wnd
- 1);
1339 rsp
= csol_cqe
->i_resp
;
1340 status
= csol_cqe
->i_sts
;
1341 flags
= csol_cqe
->i_flags
;
1342 resid
= csol_cqe
->res_cnt
;
1345 if (io_task
->scsi_cmnd
)
1346 scsi_dma_unmap(io_task
->scsi_cmnd
);
1350 task
->sc
->result
= (DID_OK
<< 16) | status
;
1351 if (rsp
!= ISCSI_STATUS_CMD_COMPLETED
) {
1352 task
->sc
->result
= DID_ERROR
<< 16;
1356 /* bidi not initially supported */
1357 if (flags
& (ISCSI_FLAG_CMD_UNDERFLOW
| ISCSI_FLAG_CMD_OVERFLOW
)) {
1358 if (!status
&& (flags
& ISCSI_FLAG_CMD_OVERFLOW
))
1359 task
->sc
->result
= DID_ERROR
<< 16;
1361 if (flags
& ISCSI_FLAG_CMD_UNDERFLOW
) {
1362 scsi_set_resid(task
->sc
, resid
);
1363 if (!status
&& (scsi_bufflen(task
->sc
) - resid
<
1364 task
->sc
->underflow
))
1365 task
->sc
->result
= DID_ERROR
<< 16;
1369 if (status
== SAM_STAT_CHECK_CONDITION
) {
1371 unsigned short *slen
= (unsigned short *)sts_bhs
->sense_info
;
1373 sense
= sts_bhs
->sense_info
+ sizeof(unsigned short);
1374 sense_len
= be16_to_cpu(*slen
);
1375 memcpy(task
->sc
->sense_buffer
, sense
,
1376 min_t(u16
, sense_len
, SCSI_SENSE_BUFFERSIZE
));
1379 if (io_task
->cmd_bhs
->iscsi_hdr
.flags
& ISCSI_FLAG_CMD_READ
)
1380 conn
->rxdata_octets
+= resid
;
1382 scsi_dma_unmap(io_task
->scsi_cmnd
);
1383 iscsi_complete_scsi_task(task
, exp_cmdsn
, max_cmdsn
);
1387 be_complete_logout(struct beiscsi_conn
*beiscsi_conn
,
1388 struct iscsi_task
*task
,
1389 struct common_sol_cqe
*csol_cqe
)
1391 struct iscsi_logout_rsp
*hdr
;
1392 struct beiscsi_io_task
*io_task
= task
->dd_data
;
1393 struct iscsi_conn
*conn
= beiscsi_conn
->conn
;
1395 hdr
= (struct iscsi_logout_rsp
*)task
->hdr
;
1396 hdr
->opcode
= ISCSI_OP_LOGOUT_RSP
;
1399 hdr
->flags
= csol_cqe
->i_flags
;
1400 hdr
->response
= csol_cqe
->i_resp
;
1401 hdr
->exp_cmdsn
= cpu_to_be32(csol_cqe
->exp_cmdsn
);
1402 hdr
->max_cmdsn
= cpu_to_be32(csol_cqe
->exp_cmdsn
+
1403 csol_cqe
->cmd_wnd
- 1);
1405 hdr
->dlength
[0] = 0;
1406 hdr
->dlength
[1] = 0;
1407 hdr
->dlength
[2] = 0;
1409 hdr
->itt
= io_task
->libiscsi_itt
;
1410 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)hdr
, NULL
, 0);
1414 be_complete_tmf(struct beiscsi_conn
*beiscsi_conn
,
1415 struct iscsi_task
*task
,
1416 struct common_sol_cqe
*csol_cqe
)
1418 struct iscsi_tm_rsp
*hdr
;
1419 struct iscsi_conn
*conn
= beiscsi_conn
->conn
;
1420 struct beiscsi_io_task
*io_task
= task
->dd_data
;
1422 hdr
= (struct iscsi_tm_rsp
*)task
->hdr
;
1423 hdr
->opcode
= ISCSI_OP_SCSI_TMFUNC_RSP
;
1424 hdr
->flags
= csol_cqe
->i_flags
;
1425 hdr
->response
= csol_cqe
->i_resp
;
1426 hdr
->exp_cmdsn
= cpu_to_be32(csol_cqe
->exp_cmdsn
);
1427 hdr
->max_cmdsn
= cpu_to_be32(csol_cqe
->exp_cmdsn
+
1428 csol_cqe
->cmd_wnd
- 1);
1430 hdr
->itt
= io_task
->libiscsi_itt
;
1431 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)hdr
, NULL
, 0);
1435 hwi_complete_drvr_msgs(struct beiscsi_conn
*beiscsi_conn
,
1436 struct beiscsi_hba
*phba
, struct sol_cqe
*psol
)
1438 struct hwi_wrb_context
*pwrb_context
;
1439 struct wrb_handle
*pwrb_handle
= NULL
;
1440 struct hwi_controller
*phwi_ctrlr
;
1441 struct iscsi_task
*task
;
1442 struct beiscsi_io_task
*io_task
;
1443 uint16_t wrb_index
, cid
, cri_index
;
1445 phwi_ctrlr
= phba
->phwi_ctrlr
;
1446 if (is_chip_be2_be3r(phba
)) {
1447 wrb_index
= AMAP_GET_BITS(struct amap_it_dmsg_cqe
,
1449 cid
= AMAP_GET_BITS(struct amap_it_dmsg_cqe
,
1452 wrb_index
= AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2
,
1454 cid
= AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2
,
1458 cri_index
= BE_GET_CRI_FROM_CID(cid
);
1459 pwrb_context
= &phwi_ctrlr
->wrb_context
[cri_index
];
1460 pwrb_handle
= pwrb_context
->pwrb_handle_basestd
[wrb_index
];
1461 task
= pwrb_handle
->pio_handle
;
1463 io_task
= task
->dd_data
;
1464 memset(io_task
->pwrb_handle
->pwrb
, 0, sizeof(struct iscsi_wrb
));
1465 iscsi_put_task(task
);
1469 be_complete_nopin_resp(struct beiscsi_conn
*beiscsi_conn
,
1470 struct iscsi_task
*task
,
1471 struct common_sol_cqe
*csol_cqe
)
1473 struct iscsi_nopin
*hdr
;
1474 struct iscsi_conn
*conn
= beiscsi_conn
->conn
;
1475 struct beiscsi_io_task
*io_task
= task
->dd_data
;
1477 hdr
= (struct iscsi_nopin
*)task
->hdr
;
1478 hdr
->flags
= csol_cqe
->i_flags
;
1479 hdr
->exp_cmdsn
= cpu_to_be32(csol_cqe
->exp_cmdsn
);
1480 hdr
->max_cmdsn
= cpu_to_be32(csol_cqe
->exp_cmdsn
+
1481 csol_cqe
->cmd_wnd
- 1);
1483 hdr
->opcode
= ISCSI_OP_NOOP_IN
;
1484 hdr
->itt
= io_task
->libiscsi_itt
;
1485 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)hdr
, NULL
, 0);
1488 static void adapter_get_sol_cqe(struct beiscsi_hba
*phba
,
1489 struct sol_cqe
*psol
,
1490 struct common_sol_cqe
*csol_cqe
)
1492 if (is_chip_be2_be3r(phba
)) {
1493 csol_cqe
->exp_cmdsn
= AMAP_GET_BITS(struct amap_sol_cqe
,
1494 i_exp_cmd_sn
, psol
);
1495 csol_cqe
->res_cnt
= AMAP_GET_BITS(struct amap_sol_cqe
,
1497 csol_cqe
->cmd_wnd
= AMAP_GET_BITS(struct amap_sol_cqe
,
1499 csol_cqe
->wrb_index
= AMAP_GET_BITS(struct amap_sol_cqe
,
1501 csol_cqe
->cid
= AMAP_GET_BITS(struct amap_sol_cqe
,
1503 csol_cqe
->hw_sts
= AMAP_GET_BITS(struct amap_sol_cqe
,
1505 csol_cqe
->i_resp
= AMAP_GET_BITS(struct amap_sol_cqe
,
1507 csol_cqe
->i_sts
= AMAP_GET_BITS(struct amap_sol_cqe
,
1509 csol_cqe
->i_flags
= AMAP_GET_BITS(struct amap_sol_cqe
,
1512 csol_cqe
->exp_cmdsn
= AMAP_GET_BITS(struct amap_sol_cqe_v2
,
1513 i_exp_cmd_sn
, psol
);
1514 csol_cqe
->res_cnt
= AMAP_GET_BITS(struct amap_sol_cqe_v2
,
1516 csol_cqe
->wrb_index
= AMAP_GET_BITS(struct amap_sol_cqe_v2
,
1518 csol_cqe
->cid
= AMAP_GET_BITS(struct amap_sol_cqe_v2
,
1520 csol_cqe
->hw_sts
= AMAP_GET_BITS(struct amap_sol_cqe_v2
,
1522 csol_cqe
->cmd_wnd
= AMAP_GET_BITS(struct amap_sol_cqe_v2
,
1524 if (AMAP_GET_BITS(struct amap_sol_cqe_v2
,
1526 csol_cqe
->i_sts
= AMAP_GET_BITS(struct amap_sol_cqe_v2
,
1529 csol_cqe
->i_resp
= AMAP_GET_BITS(struct amap_sol_cqe_v2
,
1531 if (AMAP_GET_BITS(struct amap_sol_cqe_v2
,
1533 csol_cqe
->i_flags
= ISCSI_FLAG_CMD_UNDERFLOW
;
1535 if (AMAP_GET_BITS(struct amap_sol_cqe_v2
,
1537 csol_cqe
->i_flags
|= ISCSI_FLAG_CMD_OVERFLOW
;
1542 static void hwi_complete_cmd(struct beiscsi_conn
*beiscsi_conn
,
1543 struct beiscsi_hba
*phba
, struct sol_cqe
*psol
)
1545 struct hwi_wrb_context
*pwrb_context
;
1546 struct wrb_handle
*pwrb_handle
;
1547 struct iscsi_wrb
*pwrb
= NULL
;
1548 struct hwi_controller
*phwi_ctrlr
;
1549 struct iscsi_task
*task
;
1551 struct iscsi_conn
*conn
= beiscsi_conn
->conn
;
1552 struct iscsi_session
*session
= conn
->session
;
1553 struct common_sol_cqe csol_cqe
= {0};
1554 uint16_t cri_index
= 0;
1556 phwi_ctrlr
= phba
->phwi_ctrlr
;
1558 /* Copy the elements to a common structure */
1559 adapter_get_sol_cqe(phba
, psol
, &csol_cqe
);
1561 cri_index
= BE_GET_CRI_FROM_CID(csol_cqe
.cid
);
1562 pwrb_context
= &phwi_ctrlr
->wrb_context
[cri_index
];
1564 pwrb_handle
= pwrb_context
->pwrb_handle_basestd
[
1565 csol_cqe
.wrb_index
];
1567 task
= pwrb_handle
->pio_handle
;
1568 pwrb
= pwrb_handle
->pwrb
;
1569 type
= ((struct beiscsi_io_task
*)task
->dd_data
)->wrb_type
;
1571 spin_lock_bh(&session
->lock
);
1574 case HWH_TYPE_IO_RD
:
1575 if ((task
->hdr
->opcode
& ISCSI_OPCODE_MASK
) ==
1577 be_complete_nopin_resp(beiscsi_conn
, task
, &csol_cqe
);
1579 be_complete_io(beiscsi_conn
, task
, &csol_cqe
);
1582 case HWH_TYPE_LOGOUT
:
1583 if ((task
->hdr
->opcode
& ISCSI_OPCODE_MASK
) == ISCSI_OP_LOGOUT
)
1584 be_complete_logout(beiscsi_conn
, task
, &csol_cqe
);
1586 be_complete_tmf(beiscsi_conn
, task
, &csol_cqe
);
1589 case HWH_TYPE_LOGIN
:
1590 beiscsi_log(phba
, KERN_ERR
,
1591 BEISCSI_LOG_CONFIG
| BEISCSI_LOG_IO
,
1592 "BM_%d :\t\t No HWH_TYPE_LOGIN Expected in"
1593 " hwi_complete_cmd- Solicited path\n");
1597 be_complete_nopin_resp(beiscsi_conn
, task
, &csol_cqe
);
1601 beiscsi_log(phba
, KERN_WARNING
,
1602 BEISCSI_LOG_CONFIG
| BEISCSI_LOG_IO
,
1603 "BM_%d : In hwi_complete_cmd, unknown type = %d"
1604 "wrb_index 0x%x CID 0x%x\n", type
,
1610 spin_unlock_bh(&session
->lock
);
1613 static struct list_head
*hwi_get_async_busy_list(struct hwi_async_pdu_context
1614 *pasync_ctx
, unsigned int is_header
,
1615 unsigned int host_write_ptr
)
1618 return &pasync_ctx
->async_entry
[host_write_ptr
].
1621 return &pasync_ctx
->async_entry
[host_write_ptr
].data_busy_list
;
1624 static struct async_pdu_handle
*
1625 hwi_get_async_handle(struct beiscsi_hba
*phba
,
1626 struct beiscsi_conn
*beiscsi_conn
,
1627 struct hwi_async_pdu_context
*pasync_ctx
,
1628 struct i_t_dpdu_cqe
*pdpdu_cqe
, unsigned int *pcq_index
)
1630 struct be_bus_address phys_addr
;
1631 struct list_head
*pbusy_list
;
1632 struct async_pdu_handle
*pasync_handle
= NULL
;
1633 unsigned char is_header
= 0;
1634 unsigned int index
, dpl
;
1636 if (is_chip_be2_be3r(phba
)) {
1637 dpl
= AMAP_GET_BITS(struct amap_i_t_dpdu_cqe
,
1639 index
= AMAP_GET_BITS(struct amap_i_t_dpdu_cqe
,
1642 dpl
= AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2
,
1644 index
= AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2
,
1648 phys_addr
.u
.a32
.address_lo
=
1649 (pdpdu_cqe
->dw
[offsetof(struct amap_i_t_dpdu_cqe
,
1650 db_addr_lo
) / 32] - dpl
);
1651 phys_addr
.u
.a32
.address_hi
=
1652 pdpdu_cqe
->dw
[offsetof(struct amap_i_t_dpdu_cqe
,
1655 phys_addr
.u
.a64
.address
=
1656 *((unsigned long long *)(&phys_addr
.u
.a64
.address
));
1658 switch (pdpdu_cqe
->dw
[offsetof(struct amap_i_t_dpdu_cqe
, code
) / 32]
1659 & PDUCQE_CODE_MASK
) {
1660 case UNSOL_HDR_NOTIFY
:
1663 pbusy_list
= hwi_get_async_busy_list(pasync_ctx
,
1666 case UNSOL_DATA_NOTIFY
:
1667 pbusy_list
= hwi_get_async_busy_list(pasync_ctx
,
1672 beiscsi_log(phba
, KERN_WARNING
,
1673 BEISCSI_LOG_IO
| BEISCSI_LOG_CONFIG
,
1674 "BM_%d : Unexpected code=%d\n",
1675 pdpdu_cqe
->dw
[offsetof(struct amap_i_t_dpdu_cqe
,
1676 code
) / 32] & PDUCQE_CODE_MASK
);
1680 WARN_ON(list_empty(pbusy_list
));
1681 list_for_each_entry(pasync_handle
, pbusy_list
, link
) {
1682 if (pasync_handle
->pa
.u
.a64
.address
== phys_addr
.u
.a64
.address
)
1686 WARN_ON(!pasync_handle
);
1688 pasync_handle
->cri
= BE_GET_ASYNC_CRI_FROM_CID(
1689 beiscsi_conn
->beiscsi_conn_cid
);
1690 pasync_handle
->is_header
= is_header
;
1691 pasync_handle
->buffer_len
= dpl
;
1694 return pasync_handle
;
1698 hwi_update_async_writables(struct beiscsi_hba
*phba
,
1699 struct hwi_async_pdu_context
*pasync_ctx
,
1700 unsigned int is_header
, unsigned int cq_index
)
1702 struct list_head
*pbusy_list
;
1703 struct async_pdu_handle
*pasync_handle
;
1704 unsigned int num_entries
, writables
= 0;
1705 unsigned int *pep_read_ptr
, *pwritables
;
1707 num_entries
= pasync_ctx
->num_entries
;
1709 pep_read_ptr
= &pasync_ctx
->async_header
.ep_read_ptr
;
1710 pwritables
= &pasync_ctx
->async_header
.writables
;
1712 pep_read_ptr
= &pasync_ctx
->async_data
.ep_read_ptr
;
1713 pwritables
= &pasync_ctx
->async_data
.writables
;
1716 while ((*pep_read_ptr
) != cq_index
) {
1718 *pep_read_ptr
= (*pep_read_ptr
) % num_entries
;
1720 pbusy_list
= hwi_get_async_busy_list(pasync_ctx
, is_header
,
1723 WARN_ON(list_empty(pbusy_list
));
1725 if (!list_empty(pbusy_list
)) {
1726 pasync_handle
= list_entry(pbusy_list
->next
,
1727 struct async_pdu_handle
,
1729 WARN_ON(!pasync_handle
);
1730 pasync_handle
->consumed
= 1;
1737 beiscsi_log(phba
, KERN_ERR
,
1738 BEISCSI_LOG_CONFIG
| BEISCSI_LOG_IO
,
1739 "BM_%d : Duplicate notification received - index 0x%x!!\n",
1744 *pwritables
= *pwritables
+ writables
;
1748 static void hwi_free_async_msg(struct beiscsi_hba
*phba
,
1749 struct hwi_async_pdu_context
*pasync_ctx
,
1752 struct async_pdu_handle
*pasync_handle
, *tmp_handle
;
1753 struct list_head
*plist
;
1755 plist
= &pasync_ctx
->async_entry
[cri
].wait_queue
.list
;
1756 list_for_each_entry_safe(pasync_handle
, tmp_handle
, plist
, link
) {
1757 list_del(&pasync_handle
->link
);
1759 if (pasync_handle
->is_header
) {
1760 list_add_tail(&pasync_handle
->link
,
1761 &pasync_ctx
->async_header
.free_list
);
1762 pasync_ctx
->async_header
.free_entries
++;
1764 list_add_tail(&pasync_handle
->link
,
1765 &pasync_ctx
->async_data
.free_list
);
1766 pasync_ctx
->async_data
.free_entries
++;
1770 INIT_LIST_HEAD(&pasync_ctx
->async_entry
[cri
].wait_queue
.list
);
1771 pasync_ctx
->async_entry
[cri
].wait_queue
.hdr_received
= 0;
1772 pasync_ctx
->async_entry
[cri
].wait_queue
.bytes_received
= 0;
1775 static struct phys_addr
*
1776 hwi_get_ring_address(struct hwi_async_pdu_context
*pasync_ctx
,
1777 unsigned int is_header
, unsigned int host_write_ptr
)
1779 struct phys_addr
*pasync_sge
= NULL
;
1782 pasync_sge
= pasync_ctx
->async_header
.ring_base
;
1784 pasync_sge
= pasync_ctx
->async_data
.ring_base
;
1786 return pasync_sge
+ host_write_ptr
;
1789 static void hwi_post_async_buffers(struct beiscsi_hba
*phba
,
1790 unsigned int is_header
, uint8_t ulp_num
)
1792 struct hwi_controller
*phwi_ctrlr
;
1793 struct hwi_async_pdu_context
*pasync_ctx
;
1794 struct async_pdu_handle
*pasync_handle
;
1795 struct list_head
*pfree_link
, *pbusy_list
;
1796 struct phys_addr
*pasync_sge
;
1797 unsigned int ring_id
, num_entries
;
1798 unsigned int host_write_num
, doorbell_offset
;
1799 unsigned int writables
;
1803 phwi_ctrlr
= phba
->phwi_ctrlr
;
1804 pasync_ctx
= HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr
, ulp_num
);
1805 num_entries
= pasync_ctx
->num_entries
;
1808 writables
= min(pasync_ctx
->async_header
.writables
,
1809 pasync_ctx
->async_header
.free_entries
);
1810 pfree_link
= pasync_ctx
->async_header
.free_list
.next
;
1811 host_write_num
= pasync_ctx
->async_header
.host_write_ptr
;
1812 ring_id
= phwi_ctrlr
->default_pdu_hdr
[ulp_num
].id
;
1813 doorbell_offset
= phwi_ctrlr
->default_pdu_hdr
[ulp_num
].
1816 writables
= min(pasync_ctx
->async_data
.writables
,
1817 pasync_ctx
->async_data
.free_entries
);
1818 pfree_link
= pasync_ctx
->async_data
.free_list
.next
;
1819 host_write_num
= pasync_ctx
->async_data
.host_write_ptr
;
1820 ring_id
= phwi_ctrlr
->default_pdu_data
[ulp_num
].id
;
1821 doorbell_offset
= phwi_ctrlr
->default_pdu_data
[ulp_num
].
1825 writables
= (writables
/ 8) * 8;
1827 for (i
= 0; i
< writables
; i
++) {
1829 hwi_get_async_busy_list(pasync_ctx
, is_header
,
1832 list_entry(pfree_link
, struct async_pdu_handle
,
1834 WARN_ON(!pasync_handle
);
1835 pasync_handle
->consumed
= 0;
1837 pfree_link
= pfree_link
->next
;
1839 pasync_sge
= hwi_get_ring_address(pasync_ctx
,
1840 is_header
, host_write_num
);
1842 pasync_sge
->hi
= pasync_handle
->pa
.u
.a32
.address_lo
;
1843 pasync_sge
->lo
= pasync_handle
->pa
.u
.a32
.address_hi
;
1845 list_move(&pasync_handle
->link
, pbusy_list
);
1848 host_write_num
= host_write_num
% num_entries
;
1852 pasync_ctx
->async_header
.host_write_ptr
=
1854 pasync_ctx
->async_header
.free_entries
-= writables
;
1855 pasync_ctx
->async_header
.writables
-= writables
;
1856 pasync_ctx
->async_header
.busy_entries
+= writables
;
1858 pasync_ctx
->async_data
.host_write_ptr
= host_write_num
;
1859 pasync_ctx
->async_data
.free_entries
-= writables
;
1860 pasync_ctx
->async_data
.writables
-= writables
;
1861 pasync_ctx
->async_data
.busy_entries
+= writables
;
1864 doorbell
|= ring_id
& DB_DEF_PDU_RING_ID_MASK
;
1865 doorbell
|= 1 << DB_DEF_PDU_REARM_SHIFT
;
1866 doorbell
|= 0 << DB_DEF_PDU_EVENT_SHIFT
;
1867 doorbell
|= (writables
& DB_DEF_PDU_CQPROC_MASK
)
1868 << DB_DEF_PDU_CQPROC_SHIFT
;
1870 iowrite32(doorbell
, phba
->db_va
+ doorbell_offset
);
1874 static void hwi_flush_default_pdu_buffer(struct beiscsi_hba
*phba
,
1875 struct beiscsi_conn
*beiscsi_conn
,
1876 struct i_t_dpdu_cqe
*pdpdu_cqe
)
1878 struct hwi_controller
*phwi_ctrlr
;
1879 struct hwi_async_pdu_context
*pasync_ctx
;
1880 struct async_pdu_handle
*pasync_handle
= NULL
;
1881 unsigned int cq_index
= -1;
1882 uint16_t cri_index
= BE_GET_CRI_FROM_CID(
1883 beiscsi_conn
->beiscsi_conn_cid
);
1885 phwi_ctrlr
= phba
->phwi_ctrlr
;
1886 pasync_ctx
= HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr
,
1887 BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr
,
1890 pasync_handle
= hwi_get_async_handle(phba
, beiscsi_conn
, pasync_ctx
,
1891 pdpdu_cqe
, &cq_index
);
1892 BUG_ON(pasync_handle
->is_header
!= 0);
1893 if (pasync_handle
->consumed
== 0)
1894 hwi_update_async_writables(phba
, pasync_ctx
,
1895 pasync_handle
->is_header
, cq_index
);
1897 hwi_free_async_msg(phba
, pasync_ctx
, pasync_handle
->cri
);
1898 hwi_post_async_buffers(phba
, pasync_handle
->is_header
,
1899 BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr
,
1904 hwi_fwd_async_msg(struct beiscsi_conn
*beiscsi_conn
,
1905 struct beiscsi_hba
*phba
,
1906 struct hwi_async_pdu_context
*pasync_ctx
, unsigned short cri
)
1908 struct list_head
*plist
;
1909 struct async_pdu_handle
*pasync_handle
;
1911 unsigned int hdr_len
= 0, buf_len
= 0;
1912 unsigned int status
, index
= 0, offset
= 0;
1913 void *pfirst_buffer
= NULL
;
1914 unsigned int num_buf
= 0;
1916 plist
= &pasync_ctx
->async_entry
[cri
].wait_queue
.list
;
1918 list_for_each_entry(pasync_handle
, plist
, link
) {
1920 phdr
= pasync_handle
->pbuffer
;
1921 hdr_len
= pasync_handle
->buffer_len
;
1923 buf_len
= pasync_handle
->buffer_len
;
1925 pfirst_buffer
= pasync_handle
->pbuffer
;
1928 memcpy(pfirst_buffer
+ offset
,
1929 pasync_handle
->pbuffer
, buf_len
);
1935 status
= beiscsi_process_async_pdu(beiscsi_conn
, phba
,
1936 phdr
, hdr_len
, pfirst_buffer
,
1939 hwi_free_async_msg(phba
, pasync_ctx
, cri
);
1944 hwi_gather_async_pdu(struct beiscsi_conn
*beiscsi_conn
,
1945 struct beiscsi_hba
*phba
,
1946 struct async_pdu_handle
*pasync_handle
)
1948 struct hwi_async_pdu_context
*pasync_ctx
;
1949 struct hwi_controller
*phwi_ctrlr
;
1950 unsigned int bytes_needed
= 0, status
= 0;
1951 unsigned short cri
= pasync_handle
->cri
;
1952 struct pdu_base
*ppdu
;
1954 phwi_ctrlr
= phba
->phwi_ctrlr
;
1955 pasync_ctx
= HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr
,
1956 BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr
,
1957 BE_GET_CRI_FROM_CID(beiscsi_conn
->
1958 beiscsi_conn_cid
)));
1960 list_del(&pasync_handle
->link
);
1961 if (pasync_handle
->is_header
) {
1962 pasync_ctx
->async_header
.busy_entries
--;
1963 if (pasync_ctx
->async_entry
[cri
].wait_queue
.hdr_received
) {
1964 hwi_free_async_msg(phba
, pasync_ctx
, cri
);
1968 pasync_ctx
->async_entry
[cri
].wait_queue
.bytes_received
= 0;
1969 pasync_ctx
->async_entry
[cri
].wait_queue
.hdr_received
= 1;
1970 pasync_ctx
->async_entry
[cri
].wait_queue
.hdr_len
=
1971 (unsigned short)pasync_handle
->buffer_len
;
1972 list_add_tail(&pasync_handle
->link
,
1973 &pasync_ctx
->async_entry
[cri
].wait_queue
.list
);
1975 ppdu
= pasync_handle
->pbuffer
;
1976 bytes_needed
= ((((ppdu
->dw
[offsetof(struct amap_pdu_base
,
1977 data_len_hi
) / 32] & PDUBASE_DATALENHI_MASK
) << 8) &
1978 0xFFFF0000) | ((be16_to_cpu((ppdu
->
1979 dw
[offsetof(struct amap_pdu_base
, data_len_lo
) / 32]
1980 & PDUBASE_DATALENLO_MASK
) >> 16)) & 0x0000FFFF));
1983 pasync_ctx
->async_entry
[cri
].wait_queue
.bytes_needed
=
1986 if (bytes_needed
== 0)
1987 status
= hwi_fwd_async_msg(beiscsi_conn
, phba
,
1991 pasync_ctx
->async_data
.busy_entries
--;
1992 if (pasync_ctx
->async_entry
[cri
].wait_queue
.hdr_received
) {
1993 list_add_tail(&pasync_handle
->link
,
1994 &pasync_ctx
->async_entry
[cri
].wait_queue
.
1996 pasync_ctx
->async_entry
[cri
].wait_queue
.
1998 (unsigned short)pasync_handle
->buffer_len
;
2000 if (pasync_ctx
->async_entry
[cri
].wait_queue
.
2002 pasync_ctx
->async_entry
[cri
].wait_queue
.
2004 status
= hwi_fwd_async_msg(beiscsi_conn
, phba
,
2011 static void hwi_process_default_pdu_ring(struct beiscsi_conn
*beiscsi_conn
,
2012 struct beiscsi_hba
*phba
,
2013 struct i_t_dpdu_cqe
*pdpdu_cqe
)
2015 struct hwi_controller
*phwi_ctrlr
;
2016 struct hwi_async_pdu_context
*pasync_ctx
;
2017 struct async_pdu_handle
*pasync_handle
= NULL
;
2018 unsigned int cq_index
= -1;
2019 uint16_t cri_index
= BE_GET_CRI_FROM_CID(
2020 beiscsi_conn
->beiscsi_conn_cid
);
2022 phwi_ctrlr
= phba
->phwi_ctrlr
;
2023 pasync_ctx
= HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr
,
2024 BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr
,
2027 pasync_handle
= hwi_get_async_handle(phba
, beiscsi_conn
, pasync_ctx
,
2028 pdpdu_cqe
, &cq_index
);
2030 if (pasync_handle
->consumed
== 0)
2031 hwi_update_async_writables(phba
, pasync_ctx
,
2032 pasync_handle
->is_header
, cq_index
);
2034 hwi_gather_async_pdu(beiscsi_conn
, phba
, pasync_handle
);
2035 hwi_post_async_buffers(phba
, pasync_handle
->is_header
,
2036 BEISCSI_GET_ULP_FROM_CRI(
2037 phwi_ctrlr
, cri_index
));
2040 static void beiscsi_process_mcc_isr(struct beiscsi_hba
*phba
)
2042 struct be_queue_info
*mcc_cq
;
2043 struct be_mcc_compl
*mcc_compl
;
2044 unsigned int num_processed
= 0;
2046 mcc_cq
= &phba
->ctrl
.mcc_obj
.cq
;
2047 mcc_compl
= queue_tail_node(mcc_cq
);
2048 mcc_compl
->flags
= le32_to_cpu(mcc_compl
->flags
);
2049 while (mcc_compl
->flags
& CQE_FLAGS_VALID_MASK
) {
2051 if (num_processed
>= 32) {
2052 hwi_ring_cq_db(phba
, mcc_cq
->id
,
2053 num_processed
, 0, 0);
2056 if (mcc_compl
->flags
& CQE_FLAGS_ASYNC_MASK
) {
2057 /* Interpret flags as an async trailer */
2058 if (is_link_state_evt(mcc_compl
->flags
))
2059 /* Interpret compl as a async link evt */
2060 beiscsi_async_link_state_process(phba
,
2061 (struct be_async_event_link_state
*) mcc_compl
);
2063 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_MBOX
,
2064 "BM_%d : Unsupported Async Event, flags"
2067 } else if (mcc_compl
->flags
& CQE_FLAGS_COMPLETED_MASK
) {
2068 be_mcc_compl_process_isr(&phba
->ctrl
, mcc_compl
);
2069 atomic_dec(&phba
->ctrl
.mcc_obj
.q
.used
);
2072 mcc_compl
->flags
= 0;
2073 queue_tail_inc(mcc_cq
);
2074 mcc_compl
= queue_tail_node(mcc_cq
);
2075 mcc_compl
->flags
= le32_to_cpu(mcc_compl
->flags
);
2079 if (num_processed
> 0)
2080 hwi_ring_cq_db(phba
, mcc_cq
->id
, num_processed
, 1, 0);
2085 * beiscsi_process_cq()- Process the Completion Queue
2086 * @pbe_eq: Event Q on which the Completion has come
2089 * Number of Completion Entries processed.
2091 static unsigned int beiscsi_process_cq(struct be_eq_obj
*pbe_eq
)
2093 struct be_queue_info
*cq
;
2094 struct sol_cqe
*sol
;
2095 struct dmsg_cqe
*dmsg
;
2096 unsigned int num_processed
= 0;
2097 unsigned int tot_nump
= 0;
2098 unsigned short code
= 0, cid
= 0;
2099 uint16_t cri_index
= 0;
2100 struct beiscsi_conn
*beiscsi_conn
;
2101 struct beiscsi_endpoint
*beiscsi_ep
;
2102 struct iscsi_endpoint
*ep
;
2103 struct beiscsi_hba
*phba
;
2106 sol
= queue_tail_node(cq
);
2107 phba
= pbe_eq
->phba
;
2109 while (sol
->dw
[offsetof(struct amap_sol_cqe
, valid
) / 32] &
2111 be_dws_le_to_cpu(sol
, sizeof(struct sol_cqe
));
2113 code
= (sol
->dw
[offsetof(struct amap_sol_cqe
, code
) /
2114 32] & CQE_CODE_MASK
);
2117 if (is_chip_be2_be3r(phba
)) {
2118 cid
= AMAP_GET_BITS(struct amap_sol_cqe
, cid
, sol
);
2120 if ((code
== DRIVERMSG_NOTIFY
) ||
2121 (code
== UNSOL_HDR_NOTIFY
) ||
2122 (code
== UNSOL_DATA_NOTIFY
))
2123 cid
= AMAP_GET_BITS(
2124 struct amap_i_t_dpdu_cqe_v2
,
2127 cid
= AMAP_GET_BITS(struct amap_sol_cqe_v2
,
2131 cri_index
= BE_GET_CRI_FROM_CID(cid
);
2132 ep
= phba
->ep_array
[cri_index
];
2133 beiscsi_ep
= ep
->dd_data
;
2134 beiscsi_conn
= beiscsi_ep
->conn
;
2136 if (num_processed
>= 32) {
2137 hwi_ring_cq_db(phba
, cq
->id
,
2138 num_processed
, 0, 0);
2139 tot_nump
+= num_processed
;
2144 case SOL_CMD_COMPLETE
:
2145 hwi_complete_cmd(beiscsi_conn
, phba
, sol
);
2147 case DRIVERMSG_NOTIFY
:
2148 beiscsi_log(phba
, KERN_INFO
,
2149 BEISCSI_LOG_IO
| BEISCSI_LOG_CONFIG
,
2150 "BM_%d : Received %s[%d] on CID : %d\n",
2151 cqe_desc
[code
], code
, cid
);
2153 dmsg
= (struct dmsg_cqe
*)sol
;
2154 hwi_complete_drvr_msgs(beiscsi_conn
, phba
, sol
);
2156 case UNSOL_HDR_NOTIFY
:
2157 beiscsi_log(phba
, KERN_INFO
,
2158 BEISCSI_LOG_IO
| BEISCSI_LOG_CONFIG
,
2159 "BM_%d : Received %s[%d] on CID : %d\n",
2160 cqe_desc
[code
], code
, cid
);
2162 spin_lock_bh(&phba
->async_pdu_lock
);
2163 hwi_process_default_pdu_ring(beiscsi_conn
, phba
,
2164 (struct i_t_dpdu_cqe
*)sol
);
2165 spin_unlock_bh(&phba
->async_pdu_lock
);
2167 case UNSOL_DATA_NOTIFY
:
2168 beiscsi_log(phba
, KERN_INFO
,
2169 BEISCSI_LOG_CONFIG
| BEISCSI_LOG_IO
,
2170 "BM_%d : Received %s[%d] on CID : %d\n",
2171 cqe_desc
[code
], code
, cid
);
2173 spin_lock_bh(&phba
->async_pdu_lock
);
2174 hwi_process_default_pdu_ring(beiscsi_conn
, phba
,
2175 (struct i_t_dpdu_cqe
*)sol
);
2176 spin_unlock_bh(&phba
->async_pdu_lock
);
2178 case CXN_INVALIDATE_INDEX_NOTIFY
:
2179 case CMD_INVALIDATED_NOTIFY
:
2180 case CXN_INVALIDATE_NOTIFY
:
2181 beiscsi_log(phba
, KERN_ERR
,
2182 BEISCSI_LOG_IO
| BEISCSI_LOG_CONFIG
,
2183 "BM_%d : Ignoring %s[%d] on CID : %d\n",
2184 cqe_desc
[code
], code
, cid
);
2186 case SOL_CMD_KILLED_DATA_DIGEST_ERR
:
2187 case CMD_KILLED_INVALID_STATSN_RCVD
:
2188 case CMD_KILLED_INVALID_R2T_RCVD
:
2189 case CMD_CXN_KILLED_LUN_INVALID
:
2190 case CMD_CXN_KILLED_ICD_INVALID
:
2191 case CMD_CXN_KILLED_ITT_INVALID
:
2192 case CMD_CXN_KILLED_SEQ_OUTOFORDER
:
2193 case CMD_CXN_KILLED_INVALID_DATASN_RCVD
:
2194 beiscsi_log(phba
, KERN_ERR
,
2195 BEISCSI_LOG_CONFIG
| BEISCSI_LOG_IO
,
2196 "BM_%d : Cmd Notification %s[%d] on CID : %d\n",
2197 cqe_desc
[code
], code
, cid
);
2199 case UNSOL_DATA_DIGEST_ERROR_NOTIFY
:
2200 beiscsi_log(phba
, KERN_ERR
,
2201 BEISCSI_LOG_IO
| BEISCSI_LOG_CONFIG
,
2202 "BM_%d : Dropping %s[%d] on DPDU ring on CID : %d\n",
2203 cqe_desc
[code
], code
, cid
);
2204 spin_lock_bh(&phba
->async_pdu_lock
);
2205 hwi_flush_default_pdu_buffer(phba
, beiscsi_conn
,
2206 (struct i_t_dpdu_cqe
*) sol
);
2207 spin_unlock_bh(&phba
->async_pdu_lock
);
2209 case CXN_KILLED_PDU_SIZE_EXCEEDS_DSL
:
2210 case CXN_KILLED_BURST_LEN_MISMATCH
:
2211 case CXN_KILLED_AHS_RCVD
:
2212 case CXN_KILLED_HDR_DIGEST_ERR
:
2213 case CXN_KILLED_UNKNOWN_HDR
:
2214 case CXN_KILLED_STALE_ITT_TTT_RCVD
:
2215 case CXN_KILLED_INVALID_ITT_TTT_RCVD
:
2216 case CXN_KILLED_TIMED_OUT
:
2217 case CXN_KILLED_FIN_RCVD
:
2218 case CXN_KILLED_RST_SENT
:
2219 case CXN_KILLED_RST_RCVD
:
2220 case CXN_KILLED_BAD_UNSOL_PDU_RCVD
:
2221 case CXN_KILLED_BAD_WRB_INDEX_ERROR
:
2222 case CXN_KILLED_OVER_RUN_RESIDUAL
:
2223 case CXN_KILLED_UNDER_RUN_RESIDUAL
:
2224 case CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN
:
2225 beiscsi_log(phba
, KERN_ERR
,
2226 BEISCSI_LOG_IO
| BEISCSI_LOG_CONFIG
,
2227 "BM_%d : Event %s[%d] received on CID : %d\n",
2228 cqe_desc
[code
], code
, cid
);
2230 iscsi_conn_failure(beiscsi_conn
->conn
,
2231 ISCSI_ERR_CONN_FAILED
);
2234 beiscsi_log(phba
, KERN_ERR
,
2235 BEISCSI_LOG_IO
| BEISCSI_LOG_CONFIG
,
2236 "BM_%d : Invalid CQE Event Received Code : %d"
2242 AMAP_SET_BITS(struct amap_sol_cqe
, valid
, sol
, 0);
2244 sol
= queue_tail_node(cq
);
2248 if (num_processed
> 0) {
2249 tot_nump
+= num_processed
;
2250 hwi_ring_cq_db(phba
, cq
->id
, num_processed
, 1, 0);
2255 void beiscsi_process_all_cqs(struct work_struct
*work
)
2257 unsigned long flags
;
2258 struct hwi_controller
*phwi_ctrlr
;
2259 struct hwi_context_memory
*phwi_context
;
2260 struct beiscsi_hba
*phba
;
2261 struct be_eq_obj
*pbe_eq
=
2262 container_of(work
, struct be_eq_obj
, work_cqs
);
2264 phba
= pbe_eq
->phba
;
2265 phwi_ctrlr
= phba
->phwi_ctrlr
;
2266 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
2268 if (pbe_eq
->todo_mcc_cq
) {
2269 spin_lock_irqsave(&phba
->isr_lock
, flags
);
2270 pbe_eq
->todo_mcc_cq
= false;
2271 spin_unlock_irqrestore(&phba
->isr_lock
, flags
);
2272 beiscsi_process_mcc_isr(phba
);
2275 if (pbe_eq
->todo_cq
) {
2276 spin_lock_irqsave(&phba
->isr_lock
, flags
);
2277 pbe_eq
->todo_cq
= false;
2278 spin_unlock_irqrestore(&phba
->isr_lock
, flags
);
2279 beiscsi_process_cq(pbe_eq
);
2282 /* rearm EQ for further interrupts */
2283 hwi_ring_eq_db(phba
, pbe_eq
->q
.id
, 0, 0, 1, 1);
2286 static int be_iopoll(struct blk_iopoll
*iop
, int budget
)
2289 struct beiscsi_hba
*phba
;
2290 struct be_eq_obj
*pbe_eq
;
2292 pbe_eq
= container_of(iop
, struct be_eq_obj
, iopoll
);
2293 ret
= beiscsi_process_cq(pbe_eq
);
2295 phba
= pbe_eq
->phba
;
2296 blk_iopoll_complete(iop
);
2297 beiscsi_log(phba
, KERN_INFO
,
2298 BEISCSI_LOG_CONFIG
| BEISCSI_LOG_IO
,
2299 "BM_%d : rearm pbe_eq->q.id =%d\n",
2301 hwi_ring_eq_db(phba
, pbe_eq
->q
.id
, 0, 0, 1, 1);
2307 hwi_write_sgl_v2(struct iscsi_wrb
*pwrb
, struct scatterlist
*sg
,
2308 unsigned int num_sg
, struct beiscsi_io_task
*io_task
)
2310 struct iscsi_sge
*psgl
;
2311 unsigned int sg_len
, index
;
2312 unsigned int sge_len
= 0;
2313 unsigned long long addr
;
2314 struct scatterlist
*l_sg
;
2315 unsigned int offset
;
2317 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, iscsi_bhs_addr_lo
, pwrb
,
2318 io_task
->bhs_pa
.u
.a32
.address_lo
);
2319 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, iscsi_bhs_addr_hi
, pwrb
,
2320 io_task
->bhs_pa
.u
.a32
.address_hi
);
2323 for (index
= 0; (index
< num_sg
) && (index
< 2); index
++,
2326 sg_len
= sg_dma_len(sg
);
2327 addr
= (u64
) sg_dma_address(sg
);
2328 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
,
2330 lower_32_bits(addr
));
2331 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
,
2333 upper_32_bits(addr
));
2334 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
,
2339 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, sge1_r2t_offset
,
2341 sg_len
= sg_dma_len(sg
);
2342 addr
= (u64
) sg_dma_address(sg
);
2343 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
,
2345 lower_32_bits(addr
));
2346 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
,
2348 upper_32_bits(addr
));
2349 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
,
2354 psgl
= (struct iscsi_sge
*)io_task
->psgl_handle
->pfrag
;
2355 memset(psgl
, 0, sizeof(*psgl
) * BE2_SGE
);
2357 AMAP_SET_BITS(struct amap_iscsi_sge
, len
, psgl
, io_task
->bhs_len
- 2);
2359 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_hi
, psgl
,
2360 io_task
->bhs_pa
.u
.a32
.address_hi
);
2361 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_lo
, psgl
,
2362 io_task
->bhs_pa
.u
.a32
.address_lo
);
2365 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, sge0_last
, pwrb
,
2367 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, sge1_last
, pwrb
,
2369 } else if (num_sg
== 2) {
2370 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, sge0_last
, pwrb
,
2372 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, sge1_last
, pwrb
,
2375 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, sge0_last
, pwrb
,
2377 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, sge1_last
, pwrb
,
2385 for (index
= 0; index
< num_sg
; index
++, sg
= sg_next(sg
), psgl
++) {
2386 sg_len
= sg_dma_len(sg
);
2387 addr
= (u64
) sg_dma_address(sg
);
2388 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_lo
, psgl
,
2389 lower_32_bits(addr
));
2390 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_hi
, psgl
,
2391 upper_32_bits(addr
));
2392 AMAP_SET_BITS(struct amap_iscsi_sge
, len
, psgl
, sg_len
);
2393 AMAP_SET_BITS(struct amap_iscsi_sge
, sge_offset
, psgl
, offset
);
2394 AMAP_SET_BITS(struct amap_iscsi_sge
, last_sge
, psgl
, 0);
2398 AMAP_SET_BITS(struct amap_iscsi_sge
, last_sge
, psgl
, 1);
2402 hwi_write_sgl(struct iscsi_wrb
*pwrb
, struct scatterlist
*sg
,
2403 unsigned int num_sg
, struct beiscsi_io_task
*io_task
)
2405 struct iscsi_sge
*psgl
;
2406 unsigned int sg_len
, index
;
2407 unsigned int sge_len
= 0;
2408 unsigned long long addr
;
2409 struct scatterlist
*l_sg
;
2410 unsigned int offset
;
2412 AMAP_SET_BITS(struct amap_iscsi_wrb
, iscsi_bhs_addr_lo
, pwrb
,
2413 io_task
->bhs_pa
.u
.a32
.address_lo
);
2414 AMAP_SET_BITS(struct amap_iscsi_wrb
, iscsi_bhs_addr_hi
, pwrb
,
2415 io_task
->bhs_pa
.u
.a32
.address_hi
);
2418 for (index
= 0; (index
< num_sg
) && (index
< 2); index
++,
2421 sg_len
= sg_dma_len(sg
);
2422 addr
= (u64
) sg_dma_address(sg
);
2423 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_addr_lo
, pwrb
,
2424 ((u32
)(addr
& 0xFFFFFFFF)));
2425 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_addr_hi
, pwrb
,
2426 ((u32
)(addr
>> 32)));
2427 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_len
, pwrb
,
2431 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge1_r2t_offset
,
2433 sg_len
= sg_dma_len(sg
);
2434 addr
= (u64
) sg_dma_address(sg
);
2435 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge1_addr_lo
, pwrb
,
2436 ((u32
)(addr
& 0xFFFFFFFF)));
2437 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge1_addr_hi
, pwrb
,
2438 ((u32
)(addr
>> 32)));
2439 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge1_len
, pwrb
,
2443 psgl
= (struct iscsi_sge
*)io_task
->psgl_handle
->pfrag
;
2444 memset(psgl
, 0, sizeof(*psgl
) * BE2_SGE
);
2446 AMAP_SET_BITS(struct amap_iscsi_sge
, len
, psgl
, io_task
->bhs_len
- 2);
2448 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_hi
, psgl
,
2449 io_task
->bhs_pa
.u
.a32
.address_hi
);
2450 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_lo
, psgl
,
2451 io_task
->bhs_pa
.u
.a32
.address_lo
);
2454 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_last
, pwrb
,
2456 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge1_last
, pwrb
,
2458 } else if (num_sg
== 2) {
2459 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_last
, pwrb
,
2461 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge1_last
, pwrb
,
2464 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_last
, pwrb
,
2466 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge1_last
, pwrb
,
2473 for (index
= 0; index
< num_sg
; index
++, sg
= sg_next(sg
), psgl
++) {
2474 sg_len
= sg_dma_len(sg
);
2475 addr
= (u64
) sg_dma_address(sg
);
2476 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_lo
, psgl
,
2477 (addr
& 0xFFFFFFFF));
2478 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_hi
, psgl
,
2480 AMAP_SET_BITS(struct amap_iscsi_sge
, len
, psgl
, sg_len
);
2481 AMAP_SET_BITS(struct amap_iscsi_sge
, sge_offset
, psgl
, offset
);
2482 AMAP_SET_BITS(struct amap_iscsi_sge
, last_sge
, psgl
, 0);
2486 AMAP_SET_BITS(struct amap_iscsi_sge
, last_sge
, psgl
, 1);
2490 * hwi_write_buffer()- Populate the WRB with task info
2491 * @pwrb: ptr to the WRB entry
2492 * @task: iscsi task which is to be executed
2494 static void hwi_write_buffer(struct iscsi_wrb
*pwrb
, struct iscsi_task
*task
)
2496 struct iscsi_sge
*psgl
;
2497 struct beiscsi_io_task
*io_task
= task
->dd_data
;
2498 struct beiscsi_conn
*beiscsi_conn
= io_task
->conn
;
2499 struct beiscsi_hba
*phba
= beiscsi_conn
->phba
;
2500 uint8_t dsp_value
= 0;
2502 io_task
->bhs_len
= sizeof(struct be_nonio_bhs
) - 2;
2503 AMAP_SET_BITS(struct amap_iscsi_wrb
, iscsi_bhs_addr_lo
, pwrb
,
2504 io_task
->bhs_pa
.u
.a32
.address_lo
);
2505 AMAP_SET_BITS(struct amap_iscsi_wrb
, iscsi_bhs_addr_hi
, pwrb
,
2506 io_task
->bhs_pa
.u
.a32
.address_hi
);
2510 /* Check for the data_count */
2511 dsp_value
= (task
->data_count
) ? 1 : 0;
2513 if (is_chip_be2_be3r(phba
))
2514 AMAP_SET_BITS(struct amap_iscsi_wrb
, dsp
,
2517 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, dsp
,
2520 /* Map addr only if there is data_count */
2522 io_task
->mtask_addr
= pci_map_single(phba
->pcidev
,
2526 io_task
->mtask_data_count
= task
->data_count
;
2528 io_task
->mtask_addr
= 0;
2530 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_addr_lo
, pwrb
,
2531 lower_32_bits(io_task
->mtask_addr
));
2532 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_addr_hi
, pwrb
,
2533 upper_32_bits(io_task
->mtask_addr
));
2534 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_len
, pwrb
,
2537 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_last
, pwrb
, 1);
2539 AMAP_SET_BITS(struct amap_iscsi_wrb
, dsp
, pwrb
, 0);
2540 io_task
->mtask_addr
= 0;
2543 psgl
= (struct iscsi_sge
*)io_task
->psgl_handle
->pfrag
;
2545 AMAP_SET_BITS(struct amap_iscsi_sge
, len
, psgl
, io_task
->bhs_len
);
2547 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_hi
, psgl
,
2548 io_task
->bhs_pa
.u
.a32
.address_hi
);
2549 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_lo
, psgl
,
2550 io_task
->bhs_pa
.u
.a32
.address_lo
);
2553 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_hi
, psgl
, 0);
2554 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_lo
, psgl
, 0);
2555 AMAP_SET_BITS(struct amap_iscsi_sge
, len
, psgl
, 0);
2556 AMAP_SET_BITS(struct amap_iscsi_sge
, sge_offset
, psgl
, 0);
2557 AMAP_SET_BITS(struct amap_iscsi_sge
, rsvd0
, psgl
, 0);
2558 AMAP_SET_BITS(struct amap_iscsi_sge
, last_sge
, psgl
, 0);
2562 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_lo
, psgl
,
2563 lower_32_bits(io_task
->mtask_addr
));
2564 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_hi
, psgl
,
2565 upper_32_bits(io_task
->mtask_addr
));
2567 AMAP_SET_BITS(struct amap_iscsi_sge
, len
, psgl
, 0x106);
2569 AMAP_SET_BITS(struct amap_iscsi_sge
, last_sge
, psgl
, 1);
2573 * beiscsi_find_mem_req()- Find mem needed
2574 * @phba: ptr to HBA struct
2576 static void beiscsi_find_mem_req(struct beiscsi_hba
*phba
)
2578 uint8_t mem_descr_index
, ulp_num
;
2579 unsigned int num_cq_pages
, num_async_pdu_buf_pages
;
2580 unsigned int num_async_pdu_data_pages
, wrb_sz_per_cxn
;
2581 unsigned int num_async_pdu_buf_sgl_pages
, num_async_pdu_data_sgl_pages
;
2583 num_cq_pages
= PAGES_REQUIRED(phba
->params
.num_cq_entries
* \
2584 sizeof(struct sol_cqe
));
2586 phba
->params
.hwi_ws_sz
= sizeof(struct hwi_controller
);
2588 phba
->mem_req
[ISCSI_MEM_GLOBAL_HEADER
] = 2 *
2589 BE_ISCSI_PDU_HEADER_SIZE
;
2590 phba
->mem_req
[HWI_MEM_ADDN_CONTEXT
] =
2591 sizeof(struct hwi_context_memory
);
2594 phba
->mem_req
[HWI_MEM_WRB
] = sizeof(struct iscsi_wrb
)
2595 * (phba
->params
.wrbs_per_cxn
)
2596 * phba
->params
.cxns_per_ctrl
;
2597 wrb_sz_per_cxn
= sizeof(struct wrb_handle
) *
2598 (phba
->params
.wrbs_per_cxn
);
2599 phba
->mem_req
[HWI_MEM_WRBH
] = roundup_pow_of_two((wrb_sz_per_cxn
) *
2600 phba
->params
.cxns_per_ctrl
);
2602 phba
->mem_req
[HWI_MEM_SGLH
] = sizeof(struct sgl_handle
) *
2603 phba
->params
.icds_per_ctrl
;
2604 phba
->mem_req
[HWI_MEM_SGE
] = sizeof(struct iscsi_sge
) *
2605 phba
->params
.num_sge_per_io
* phba
->params
.icds_per_ctrl
;
2606 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++) {
2607 if (test_bit(ulp_num
, &phba
->fw_config
.ulp_supported
)) {
2609 num_async_pdu_buf_sgl_pages
=
2610 PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
2612 sizeof(struct phys_addr
));
2614 num_async_pdu_buf_pages
=
2615 PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
2617 phba
->params
.defpdu_hdr_sz
);
2619 num_async_pdu_data_pages
=
2620 PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
2622 phba
->params
.defpdu_data_sz
);
2624 num_async_pdu_data_sgl_pages
=
2625 PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
2627 sizeof(struct phys_addr
));
2629 mem_descr_index
= (HWI_MEM_TEMPLATE_HDR_ULP0
+
2630 (ulp_num
* MEM_DESCR_OFFSET
));
2631 phba
->mem_req
[mem_descr_index
] =
2632 BEISCSI_GET_CID_COUNT(phba
, ulp_num
) *
2633 BEISCSI_TEMPLATE_HDR_PER_CXN_SIZE
;
2635 mem_descr_index
= (HWI_MEM_ASYNC_HEADER_BUF_ULP0
+
2636 (ulp_num
* MEM_DESCR_OFFSET
));
2637 phba
->mem_req
[mem_descr_index
] =
2638 num_async_pdu_buf_pages
*
2641 mem_descr_index
= (HWI_MEM_ASYNC_DATA_BUF_ULP0
+
2642 (ulp_num
* MEM_DESCR_OFFSET
));
2643 phba
->mem_req
[mem_descr_index
] =
2644 num_async_pdu_data_pages
*
2647 mem_descr_index
= (HWI_MEM_ASYNC_HEADER_RING_ULP0
+
2648 (ulp_num
* MEM_DESCR_OFFSET
));
2649 phba
->mem_req
[mem_descr_index
] =
2650 num_async_pdu_buf_sgl_pages
*
2653 mem_descr_index
= (HWI_MEM_ASYNC_DATA_RING_ULP0
+
2654 (ulp_num
* MEM_DESCR_OFFSET
));
2655 phba
->mem_req
[mem_descr_index
] =
2656 num_async_pdu_data_sgl_pages
*
2659 mem_descr_index
= (HWI_MEM_ASYNC_HEADER_HANDLE_ULP0
+
2660 (ulp_num
* MEM_DESCR_OFFSET
));
2661 phba
->mem_req
[mem_descr_index
] =
2662 BEISCSI_GET_CID_COUNT(phba
, ulp_num
) *
2663 sizeof(struct async_pdu_handle
);
2665 mem_descr_index
= (HWI_MEM_ASYNC_DATA_HANDLE_ULP0
+
2666 (ulp_num
* MEM_DESCR_OFFSET
));
2667 phba
->mem_req
[mem_descr_index
] =
2668 BEISCSI_GET_CID_COUNT(phba
, ulp_num
) *
2669 sizeof(struct async_pdu_handle
);
2671 mem_descr_index
= (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0
+
2672 (ulp_num
* MEM_DESCR_OFFSET
));
2673 phba
->mem_req
[mem_descr_index
] =
2674 sizeof(struct hwi_async_pdu_context
) +
2675 (BEISCSI_GET_CID_COUNT(phba
, ulp_num
) *
2676 sizeof(struct hwi_async_entry
));
2681 static int beiscsi_alloc_mem(struct beiscsi_hba
*phba
)
2684 struct hwi_controller
*phwi_ctrlr
;
2685 struct be_mem_descriptor
*mem_descr
;
2686 struct mem_array
*mem_arr
, *mem_arr_orig
;
2687 unsigned int i
, j
, alloc_size
, curr_alloc_size
;
2689 phba
->phwi_ctrlr
= kzalloc(phba
->params
.hwi_ws_sz
, GFP_KERNEL
);
2690 if (!phba
->phwi_ctrlr
)
2693 /* Allocate memory for wrb_context */
2694 phwi_ctrlr
= phba
->phwi_ctrlr
;
2695 phwi_ctrlr
->wrb_context
= kzalloc(sizeof(struct hwi_wrb_context
) *
2696 phba
->params
.cxns_per_ctrl
,
2698 if (!phwi_ctrlr
->wrb_context
)
2701 phba
->init_mem
= kcalloc(SE_MEM_MAX
, sizeof(*mem_descr
),
2703 if (!phba
->init_mem
) {
2704 kfree(phwi_ctrlr
->wrb_context
);
2705 kfree(phba
->phwi_ctrlr
);
2709 mem_arr_orig
= kmalloc(sizeof(*mem_arr_orig
) * BEISCSI_MAX_FRAGS_INIT
,
2711 if (!mem_arr_orig
) {
2712 kfree(phba
->init_mem
);
2713 kfree(phwi_ctrlr
->wrb_context
);
2714 kfree(phba
->phwi_ctrlr
);
2718 mem_descr
= phba
->init_mem
;
2719 for (i
= 0; i
< SE_MEM_MAX
; i
++) {
2720 if (!phba
->mem_req
[i
]) {
2721 mem_descr
->mem_array
= NULL
;
2727 mem_arr
= mem_arr_orig
;
2728 alloc_size
= phba
->mem_req
[i
];
2729 memset(mem_arr
, 0, sizeof(struct mem_array
) *
2730 BEISCSI_MAX_FRAGS_INIT
);
2731 curr_alloc_size
= min(be_max_phys_size
* 1024, alloc_size
);
2733 mem_arr
->virtual_address
= pci_alloc_consistent(
2737 if (!mem_arr
->virtual_address
) {
2738 if (curr_alloc_size
<= BE_MIN_MEM_SIZE
)
2740 if (curr_alloc_size
-
2741 rounddown_pow_of_two(curr_alloc_size
))
2742 curr_alloc_size
= rounddown_pow_of_two
2745 curr_alloc_size
= curr_alloc_size
/ 2;
2747 mem_arr
->bus_address
.u
.
2748 a64
.address
= (__u64
) bus_add
;
2749 mem_arr
->size
= curr_alloc_size
;
2750 alloc_size
-= curr_alloc_size
;
2751 curr_alloc_size
= min(be_max_phys_size
*
2756 } while (alloc_size
);
2757 mem_descr
->num_elements
= j
;
2758 mem_descr
->size_in_bytes
= phba
->mem_req
[i
];
2759 mem_descr
->mem_array
= kmalloc(sizeof(*mem_arr
) * j
,
2761 if (!mem_descr
->mem_array
)
2764 memcpy(mem_descr
->mem_array
, mem_arr_orig
,
2765 sizeof(struct mem_array
) * j
);
2768 kfree(mem_arr_orig
);
2771 mem_descr
->num_elements
= j
;
2772 while ((i
) || (j
)) {
2773 for (j
= mem_descr
->num_elements
; j
> 0; j
--) {
2774 pci_free_consistent(phba
->pcidev
,
2775 mem_descr
->mem_array
[j
- 1].size
,
2776 mem_descr
->mem_array
[j
- 1].
2778 (unsigned long)mem_descr
->
2780 bus_address
.u
.a64
.address
);
2784 kfree(mem_descr
->mem_array
);
2788 kfree(mem_arr_orig
);
2789 kfree(phba
->init_mem
);
2790 kfree(phba
->phwi_ctrlr
->wrb_context
);
2791 kfree(phba
->phwi_ctrlr
);
2795 static int beiscsi_get_memory(struct beiscsi_hba
*phba
)
2797 beiscsi_find_mem_req(phba
);
2798 return beiscsi_alloc_mem(phba
);
2801 static void iscsi_init_global_templates(struct beiscsi_hba
*phba
)
2803 struct pdu_data_out
*pdata_out
;
2804 struct pdu_nop_out
*pnop_out
;
2805 struct be_mem_descriptor
*mem_descr
;
2807 mem_descr
= phba
->init_mem
;
2808 mem_descr
+= ISCSI_MEM_GLOBAL_HEADER
;
2810 (struct pdu_data_out
*)mem_descr
->mem_array
[0].virtual_address
;
2811 memset(pdata_out
, 0, BE_ISCSI_PDU_HEADER_SIZE
);
2813 AMAP_SET_BITS(struct amap_pdu_data_out
, opcode
, pdata_out
,
2817 (struct pdu_nop_out
*)((unsigned char *)mem_descr
->mem_array
[0].
2818 virtual_address
+ BE_ISCSI_PDU_HEADER_SIZE
);
2820 memset(pnop_out
, 0, BE_ISCSI_PDU_HEADER_SIZE
);
2821 AMAP_SET_BITS(struct amap_pdu_nop_out
, ttt
, pnop_out
, 0xFFFFFFFF);
2822 AMAP_SET_BITS(struct amap_pdu_nop_out
, f_bit
, pnop_out
, 1);
2823 AMAP_SET_BITS(struct amap_pdu_nop_out
, i_bit
, pnop_out
, 0);
2826 static int beiscsi_init_wrb_handle(struct beiscsi_hba
*phba
)
2828 struct be_mem_descriptor
*mem_descr_wrbh
, *mem_descr_wrb
;
2829 struct hwi_context_memory
*phwi_ctxt
;
2830 struct wrb_handle
*pwrb_handle
= NULL
;
2831 struct hwi_controller
*phwi_ctrlr
;
2832 struct hwi_wrb_context
*pwrb_context
;
2833 struct iscsi_wrb
*pwrb
= NULL
;
2834 unsigned int num_cxn_wrbh
= 0;
2835 unsigned int num_cxn_wrb
= 0, j
, idx
= 0, index
;
2837 mem_descr_wrbh
= phba
->init_mem
;
2838 mem_descr_wrbh
+= HWI_MEM_WRBH
;
2840 mem_descr_wrb
= phba
->init_mem
;
2841 mem_descr_wrb
+= HWI_MEM_WRB
;
2842 phwi_ctrlr
= phba
->phwi_ctrlr
;
2844 /* Allocate memory for WRBQ */
2845 phwi_ctxt
= phwi_ctrlr
->phwi_ctxt
;
2846 phwi_ctxt
->be_wrbq
= kzalloc(sizeof(struct be_queue_info
) *
2847 phba
->params
.cxns_per_ctrl
,
2849 if (!phwi_ctxt
->be_wrbq
) {
2850 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
2851 "BM_%d : WRBQ Mem Alloc Failed\n");
2855 for (index
= 0; index
< phba
->params
.cxns_per_ctrl
; index
++) {
2856 pwrb_context
= &phwi_ctrlr
->wrb_context
[index
];
2857 pwrb_context
->pwrb_handle_base
=
2858 kzalloc(sizeof(struct wrb_handle
*) *
2859 phba
->params
.wrbs_per_cxn
, GFP_KERNEL
);
2860 if (!pwrb_context
->pwrb_handle_base
) {
2861 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
2862 "BM_%d : Mem Alloc Failed. Failing to load\n");
2863 goto init_wrb_hndl_failed
;
2865 pwrb_context
->pwrb_handle_basestd
=
2866 kzalloc(sizeof(struct wrb_handle
*) *
2867 phba
->params
.wrbs_per_cxn
, GFP_KERNEL
);
2868 if (!pwrb_context
->pwrb_handle_basestd
) {
2869 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
2870 "BM_%d : Mem Alloc Failed. Failing to load\n");
2871 goto init_wrb_hndl_failed
;
2873 if (!num_cxn_wrbh
) {
2875 mem_descr_wrbh
->mem_array
[idx
].virtual_address
;
2876 num_cxn_wrbh
= ((mem_descr_wrbh
->mem_array
[idx
].size
) /
2877 ((sizeof(struct wrb_handle
)) *
2878 phba
->params
.wrbs_per_cxn
));
2881 pwrb_context
->alloc_index
= 0;
2882 pwrb_context
->wrb_handles_available
= 0;
2883 pwrb_context
->free_index
= 0;
2886 for (j
= 0; j
< phba
->params
.wrbs_per_cxn
; j
++) {
2887 pwrb_context
->pwrb_handle_base
[j
] = pwrb_handle
;
2888 pwrb_context
->pwrb_handle_basestd
[j
] =
2890 pwrb_context
->wrb_handles_available
++;
2891 pwrb_handle
->wrb_index
= j
;
2898 for (index
= 0; index
< phba
->params
.cxns_per_ctrl
; index
++) {
2899 pwrb_context
= &phwi_ctrlr
->wrb_context
[index
];
2901 pwrb
= mem_descr_wrb
->mem_array
[idx
].virtual_address
;
2902 num_cxn_wrb
= (mem_descr_wrb
->mem_array
[idx
].size
) /
2903 ((sizeof(struct iscsi_wrb
) *
2904 phba
->params
.wrbs_per_cxn
));
2909 for (j
= 0; j
< phba
->params
.wrbs_per_cxn
; j
++) {
2910 pwrb_handle
= pwrb_context
->pwrb_handle_base
[j
];
2911 pwrb_handle
->pwrb
= pwrb
;
2918 init_wrb_hndl_failed
:
2919 for (j
= index
; j
> 0; j
--) {
2920 pwrb_context
= &phwi_ctrlr
->wrb_context
[j
];
2921 kfree(pwrb_context
->pwrb_handle_base
);
2922 kfree(pwrb_context
->pwrb_handle_basestd
);
2927 static int hwi_init_async_pdu_ctx(struct beiscsi_hba
*phba
)
2930 struct hwi_controller
*phwi_ctrlr
;
2931 struct hba_parameters
*p
= &phba
->params
;
2932 struct hwi_async_pdu_context
*pasync_ctx
;
2933 struct async_pdu_handle
*pasync_header_h
, *pasync_data_h
;
2934 unsigned int index
, idx
, num_per_mem
, num_async_data
;
2935 struct be_mem_descriptor
*mem_descr
;
2937 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++) {
2938 if (test_bit(ulp_num
, &phba
->fw_config
.ulp_supported
)) {
2940 mem_descr
= (struct be_mem_descriptor
*)phba
->init_mem
;
2941 mem_descr
+= (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0
+
2942 (ulp_num
* MEM_DESCR_OFFSET
));
2944 phwi_ctrlr
= phba
->phwi_ctrlr
;
2945 phwi_ctrlr
->phwi_ctxt
->pasync_ctx
[ulp_num
] =
2946 (struct hwi_async_pdu_context
*)
2947 mem_descr
->mem_array
[0].virtual_address
;
2949 pasync_ctx
= phwi_ctrlr
->phwi_ctxt
->pasync_ctx
[ulp_num
];
2950 memset(pasync_ctx
, 0, sizeof(*pasync_ctx
));
2952 pasync_ctx
->async_entry
=
2953 (struct hwi_async_entry
*)
2954 ((long unsigned int)pasync_ctx
+
2955 sizeof(struct hwi_async_pdu_context
));
2957 pasync_ctx
->num_entries
= BEISCSI_GET_CID_COUNT(phba
,
2959 pasync_ctx
->buffer_size
= p
->defpdu_hdr_sz
;
2961 mem_descr
= (struct be_mem_descriptor
*)phba
->init_mem
;
2962 mem_descr
+= HWI_MEM_ASYNC_HEADER_BUF_ULP0
+
2963 (ulp_num
* MEM_DESCR_OFFSET
);
2964 if (mem_descr
->mem_array
[0].virtual_address
) {
2965 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
2966 "BM_%d : hwi_init_async_pdu_ctx"
2967 " HWI_MEM_ASYNC_HEADER_BUF_ULP%d va=%p\n",
2969 mem_descr
->mem_array
[0].
2972 beiscsi_log(phba
, KERN_WARNING
,
2974 "BM_%d : No Virtual address for ULP : %d\n",
2977 pasync_ctx
->async_header
.va_base
=
2978 mem_descr
->mem_array
[0].virtual_address
;
2980 pasync_ctx
->async_header
.pa_base
.u
.a64
.address
=
2981 mem_descr
->mem_array
[0].
2982 bus_address
.u
.a64
.address
;
2984 mem_descr
= (struct be_mem_descriptor
*)phba
->init_mem
;
2985 mem_descr
+= HWI_MEM_ASYNC_HEADER_RING_ULP0
+
2986 (ulp_num
* MEM_DESCR_OFFSET
);
2987 if (mem_descr
->mem_array
[0].virtual_address
) {
2988 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
2989 "BM_%d : hwi_init_async_pdu_ctx"
2990 " HWI_MEM_ASYNC_HEADER_RING_ULP%d va=%p\n",
2992 mem_descr
->mem_array
[0].
2995 beiscsi_log(phba
, KERN_WARNING
,
2997 "BM_%d : No Virtual address for ULP : %d\n",
3000 pasync_ctx
->async_header
.ring_base
=
3001 mem_descr
->mem_array
[0].virtual_address
;
3003 mem_descr
= (struct be_mem_descriptor
*)phba
->init_mem
;
3004 mem_descr
+= HWI_MEM_ASYNC_HEADER_HANDLE_ULP0
+
3005 (ulp_num
* MEM_DESCR_OFFSET
);
3006 if (mem_descr
->mem_array
[0].virtual_address
) {
3007 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
3008 "BM_%d : hwi_init_async_pdu_ctx"
3009 " HWI_MEM_ASYNC_HEADER_HANDLE_ULP%d va=%p\n",
3011 mem_descr
->mem_array
[0].
3014 beiscsi_log(phba
, KERN_WARNING
,
3016 "BM_%d : No Virtual address for ULP : %d\n",
3019 pasync_ctx
->async_header
.handle_base
=
3020 mem_descr
->mem_array
[0].virtual_address
;
3021 pasync_ctx
->async_header
.writables
= 0;
3022 INIT_LIST_HEAD(&pasync_ctx
->async_header
.free_list
);
3024 mem_descr
= (struct be_mem_descriptor
*)phba
->init_mem
;
3025 mem_descr
+= HWI_MEM_ASYNC_DATA_RING_ULP0
+
3026 (ulp_num
* MEM_DESCR_OFFSET
);
3027 if (mem_descr
->mem_array
[0].virtual_address
) {
3028 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
3029 "BM_%d : hwi_init_async_pdu_ctx"
3030 " HWI_MEM_ASYNC_DATA_RING_ULP%d va=%p\n",
3032 mem_descr
->mem_array
[0].
3035 beiscsi_log(phba
, KERN_WARNING
,
3037 "BM_%d : No Virtual address for ULP : %d\n",
3040 pasync_ctx
->async_data
.ring_base
=
3041 mem_descr
->mem_array
[0].virtual_address
;
3043 mem_descr
= (struct be_mem_descriptor
*)phba
->init_mem
;
3044 mem_descr
+= HWI_MEM_ASYNC_DATA_HANDLE_ULP0
+
3045 (ulp_num
* MEM_DESCR_OFFSET
);
3046 if (!mem_descr
->mem_array
[0].virtual_address
)
3047 beiscsi_log(phba
, KERN_WARNING
,
3049 "BM_%d : No Virtual address for ULP : %d\n",
3052 pasync_ctx
->async_data
.handle_base
=
3053 mem_descr
->mem_array
[0].virtual_address
;
3054 pasync_ctx
->async_data
.writables
= 0;
3055 INIT_LIST_HEAD(&pasync_ctx
->async_data
.free_list
);
3058 (struct async_pdu_handle
*)
3059 pasync_ctx
->async_header
.handle_base
;
3061 (struct async_pdu_handle
*)
3062 pasync_ctx
->async_data
.handle_base
;
3064 mem_descr
= (struct be_mem_descriptor
*)phba
->init_mem
;
3065 mem_descr
+= HWI_MEM_ASYNC_DATA_BUF_ULP0
+
3066 (ulp_num
* MEM_DESCR_OFFSET
);
3067 if (mem_descr
->mem_array
[0].virtual_address
) {
3068 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
3069 "BM_%d : hwi_init_async_pdu_ctx"
3070 " HWI_MEM_ASYNC_DATA_BUF_ULP%d va=%p\n",
3072 mem_descr
->mem_array
[0].
3075 beiscsi_log(phba
, KERN_WARNING
,
3077 "BM_%d : No Virtual address for ULP : %d\n",
3081 pasync_ctx
->async_data
.va_base
=
3082 mem_descr
->mem_array
[idx
].virtual_address
;
3083 pasync_ctx
->async_data
.pa_base
.u
.a64
.address
=
3084 mem_descr
->mem_array
[idx
].
3085 bus_address
.u
.a64
.address
;
3087 num_async_data
= ((mem_descr
->mem_array
[idx
].size
) /
3088 phba
->params
.defpdu_data_sz
);
3091 for (index
= 0; index
< BEISCSI_GET_CID_COUNT
3092 (phba
, ulp_num
); index
++) {
3093 pasync_header_h
->cri
= -1;
3094 pasync_header_h
->index
= (char)index
;
3095 INIT_LIST_HEAD(&pasync_header_h
->link
);
3096 pasync_header_h
->pbuffer
=
3097 (void *)((unsigned long)
3099 async_header
.va_base
) +
3100 (p
->defpdu_hdr_sz
* index
));
3102 pasync_header_h
->pa
.u
.a64
.address
=
3103 pasync_ctx
->async_header
.pa_base
.u
.a64
.
3104 address
+ (p
->defpdu_hdr_sz
* index
);
3106 list_add_tail(&pasync_header_h
->link
,
3107 &pasync_ctx
->async_header
.
3110 pasync_ctx
->async_header
.free_entries
++;
3111 pasync_ctx
->async_header
.writables
++;
3113 INIT_LIST_HEAD(&pasync_ctx
->async_entry
[index
].
3115 INIT_LIST_HEAD(&pasync_ctx
->async_entry
[index
].
3117 pasync_data_h
->cri
= -1;
3118 pasync_data_h
->index
= (char)index
;
3119 INIT_LIST_HEAD(&pasync_data_h
->link
);
3121 if (!num_async_data
) {
3124 pasync_ctx
->async_data
.va_base
=
3125 mem_descr
->mem_array
[idx
].
3127 pasync_ctx
->async_data
.pa_base
.u
.
3129 mem_descr
->mem_array
[idx
].
3130 bus_address
.u
.a64
.address
;
3132 ((mem_descr
->mem_array
[idx
].
3134 phba
->params
.defpdu_data_sz
);
3136 pasync_data_h
->pbuffer
=
3137 (void *)((unsigned long)
3138 (pasync_ctx
->async_data
.va_base
) +
3139 (p
->defpdu_data_sz
* num_per_mem
));
3141 pasync_data_h
->pa
.u
.a64
.address
=
3142 pasync_ctx
->async_data
.pa_base
.u
.a64
.
3143 address
+ (p
->defpdu_data_sz
*
3148 list_add_tail(&pasync_data_h
->link
,
3149 &pasync_ctx
->async_data
.
3152 pasync_ctx
->async_data
.free_entries
++;
3153 pasync_ctx
->async_data
.writables
++;
3155 INIT_LIST_HEAD(&pasync_ctx
->async_entry
[index
].
3159 pasync_ctx
->async_header
.host_write_ptr
= 0;
3160 pasync_ctx
->async_header
.ep_read_ptr
= -1;
3161 pasync_ctx
->async_data
.host_write_ptr
= 0;
3162 pasync_ctx
->async_data
.ep_read_ptr
= -1;
3170 be_sgl_create_contiguous(void *virtual_address
,
3171 u64 physical_address
, u32 length
,
3172 struct be_dma_mem
*sgl
)
3174 WARN_ON(!virtual_address
);
3175 WARN_ON(!physical_address
);
3176 WARN_ON(!length
> 0);
3179 sgl
->va
= virtual_address
;
3180 sgl
->dma
= (unsigned long)physical_address
;
3186 static void be_sgl_destroy_contiguous(struct be_dma_mem
*sgl
)
3188 memset(sgl
, 0, sizeof(*sgl
));
3192 hwi_build_be_sgl_arr(struct beiscsi_hba
*phba
,
3193 struct mem_array
*pmem
, struct be_dma_mem
*sgl
)
3196 be_sgl_destroy_contiguous(sgl
);
3198 be_sgl_create_contiguous(pmem
->virtual_address
,
3199 pmem
->bus_address
.u
.a64
.address
,
3204 hwi_build_be_sgl_by_offset(struct beiscsi_hba
*phba
,
3205 struct mem_array
*pmem
, struct be_dma_mem
*sgl
)
3208 be_sgl_destroy_contiguous(sgl
);
3210 be_sgl_create_contiguous((unsigned char *)pmem
->virtual_address
,
3211 pmem
->bus_address
.u
.a64
.address
,
3215 static int be_fill_queue(struct be_queue_info
*q
,
3216 u16 len
, u16 entry_size
, void *vaddress
)
3218 struct be_dma_mem
*mem
= &q
->dma_mem
;
3220 memset(q
, 0, sizeof(*q
));
3222 q
->entry_size
= entry_size
;
3223 mem
->size
= len
* entry_size
;
3227 memset(mem
->va
, 0, mem
->size
);
3231 static int beiscsi_create_eqs(struct beiscsi_hba
*phba
,
3232 struct hwi_context_memory
*phwi_context
)
3234 unsigned int i
, num_eq_pages
;
3235 int ret
= 0, eq_for_mcc
;
3236 struct be_queue_info
*eq
;
3237 struct be_dma_mem
*mem
;
3241 num_eq_pages
= PAGES_REQUIRED(phba
->params
.num_eq_entries
* \
3242 sizeof(struct be_eq_entry
));
3244 if (phba
->msix_enabled
)
3248 for (i
= 0; i
< (phba
->num_cpus
+ eq_for_mcc
); i
++) {
3249 eq
= &phwi_context
->be_eq
[i
].q
;
3251 phwi_context
->be_eq
[i
].phba
= phba
;
3252 eq_vaddress
= pci_alloc_consistent(phba
->pcidev
,
3253 num_eq_pages
* PAGE_SIZE
,
3256 goto create_eq_error
;
3258 mem
->va
= eq_vaddress
;
3259 ret
= be_fill_queue(eq
, phba
->params
.num_eq_entries
,
3260 sizeof(struct be_eq_entry
), eq_vaddress
);
3262 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3263 "BM_%d : be_fill_queue Failed for EQ\n");
3264 goto create_eq_error
;
3268 ret
= beiscsi_cmd_eq_create(&phba
->ctrl
, eq
,
3269 phwi_context
->cur_eqd
);
3271 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3272 "BM_%d : beiscsi_cmd_eq_create"
3274 goto create_eq_error
;
3277 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
3278 "BM_%d : eqid = %d\n",
3279 phwi_context
->be_eq
[i
].q
.id
);
3283 for (i
= 0; i
< (phba
->num_cpus
+ eq_for_mcc
); i
++) {
3284 eq
= &phwi_context
->be_eq
[i
].q
;
3287 pci_free_consistent(phba
->pcidev
, num_eq_pages
3294 static int beiscsi_create_cqs(struct beiscsi_hba
*phba
,
3295 struct hwi_context_memory
*phwi_context
)
3297 unsigned int i
, num_cq_pages
;
3299 struct be_queue_info
*cq
, *eq
;
3300 struct be_dma_mem
*mem
;
3301 struct be_eq_obj
*pbe_eq
;
3305 num_cq_pages
= PAGES_REQUIRED(phba
->params
.num_cq_entries
* \
3306 sizeof(struct sol_cqe
));
3308 for (i
= 0; i
< phba
->num_cpus
; i
++) {
3309 cq
= &phwi_context
->be_cq
[i
];
3310 eq
= &phwi_context
->be_eq
[i
].q
;
3311 pbe_eq
= &phwi_context
->be_eq
[i
];
3313 pbe_eq
->phba
= phba
;
3315 cq_vaddress
= pci_alloc_consistent(phba
->pcidev
,
3316 num_cq_pages
* PAGE_SIZE
,
3319 goto create_cq_error
;
3320 ret
= be_fill_queue(cq
, phba
->params
.num_cq_entries
,
3321 sizeof(struct sol_cqe
), cq_vaddress
);
3323 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3324 "BM_%d : be_fill_queue Failed "
3326 goto create_cq_error
;
3330 ret
= beiscsi_cmd_cq_create(&phba
->ctrl
, cq
, eq
, false,
3333 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3334 "BM_%d : beiscsi_cmd_eq_create"
3335 "Failed for ISCSI CQ\n");
3336 goto create_cq_error
;
3338 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
3339 "BM_%d : iscsi cq_id is %d for eq_id %d\n"
3340 "iSCSI CQ CREATED\n", cq
->id
, eq
->id
);
3345 for (i
= 0; i
< phba
->num_cpus
; i
++) {
3346 cq
= &phwi_context
->be_cq
[i
];
3349 pci_free_consistent(phba
->pcidev
, num_cq_pages
3358 beiscsi_create_def_hdr(struct beiscsi_hba
*phba
,
3359 struct hwi_context_memory
*phwi_context
,
3360 struct hwi_controller
*phwi_ctrlr
,
3361 unsigned int def_pdu_ring_sz
, uint8_t ulp_num
)
3365 struct be_queue_info
*dq
, *cq
;
3366 struct be_dma_mem
*mem
;
3367 struct be_mem_descriptor
*mem_descr
;
3371 dq
= &phwi_context
->be_def_hdrq
[ulp_num
];
3372 cq
= &phwi_context
->be_cq
[0];
3374 mem_descr
= phba
->init_mem
;
3375 mem_descr
+= HWI_MEM_ASYNC_HEADER_RING_ULP0
+
3376 (ulp_num
* MEM_DESCR_OFFSET
);
3377 dq_vaddress
= mem_descr
->mem_array
[idx
].virtual_address
;
3378 ret
= be_fill_queue(dq
, mem_descr
->mem_array
[0].size
/
3379 sizeof(struct phys_addr
),
3380 sizeof(struct phys_addr
), dq_vaddress
);
3382 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3383 "BM_%d : be_fill_queue Failed for DEF PDU HDR on ULP : %d\n",
3388 mem
->dma
= (unsigned long)mem_descr
->mem_array
[idx
].
3389 bus_address
.u
.a64
.address
;
3390 ret
= be_cmd_create_default_pdu_queue(&phba
->ctrl
, cq
, dq
,
3392 phba
->params
.defpdu_hdr_sz
,
3393 BEISCSI_DEFQ_HDR
, ulp_num
);
3395 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3396 "BM_%d : be_cmd_create_default_pdu_queue Failed DEFHDR on ULP : %d\n",
3402 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
3403 "BM_%d : iscsi hdr def pdu id for ULP : %d is %d\n",
3405 phwi_context
->be_def_hdrq
[ulp_num
].id
);
3406 hwi_post_async_buffers(phba
, BEISCSI_DEFQ_HDR
, ulp_num
);
3411 beiscsi_create_def_data(struct beiscsi_hba
*phba
,
3412 struct hwi_context_memory
*phwi_context
,
3413 struct hwi_controller
*phwi_ctrlr
,
3414 unsigned int def_pdu_ring_sz
, uint8_t ulp_num
)
3418 struct be_queue_info
*dataq
, *cq
;
3419 struct be_dma_mem
*mem
;
3420 struct be_mem_descriptor
*mem_descr
;
3424 dataq
= &phwi_context
->be_def_dataq
[ulp_num
];
3425 cq
= &phwi_context
->be_cq
[0];
3426 mem
= &dataq
->dma_mem
;
3427 mem_descr
= phba
->init_mem
;
3428 mem_descr
+= HWI_MEM_ASYNC_DATA_RING_ULP0
+
3429 (ulp_num
* MEM_DESCR_OFFSET
);
3430 dq_vaddress
= mem_descr
->mem_array
[idx
].virtual_address
;
3431 ret
= be_fill_queue(dataq
, mem_descr
->mem_array
[0].size
/
3432 sizeof(struct phys_addr
),
3433 sizeof(struct phys_addr
), dq_vaddress
);
3435 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3436 "BM_%d : be_fill_queue Failed for DEF PDU "
3437 "DATA on ULP : %d\n",
3442 mem
->dma
= (unsigned long)mem_descr
->mem_array
[idx
].
3443 bus_address
.u
.a64
.address
;
3444 ret
= be_cmd_create_default_pdu_queue(&phba
->ctrl
, cq
, dataq
,
3446 phba
->params
.defpdu_data_sz
,
3447 BEISCSI_DEFQ_DATA
, ulp_num
);
3449 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3450 "BM_%d be_cmd_create_default_pdu_queue"
3451 " Failed for DEF PDU DATA on ULP : %d\n",
3456 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
3457 "BM_%d : iscsi def data id on ULP : %d is %d\n",
3459 phwi_context
->be_def_dataq
[ulp_num
].id
);
3461 hwi_post_async_buffers(phba
, BEISCSI_DEFQ_DATA
, ulp_num
);
3462 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
3463 "BM_%d : DEFAULT PDU DATA RING CREATED"
3464 "on ULP : %d\n", ulp_num
);
3471 beiscsi_post_template_hdr(struct beiscsi_hba
*phba
)
3473 struct be_mem_descriptor
*mem_descr
;
3474 struct mem_array
*pm_arr
;
3475 struct be_dma_mem sgl
;
3476 int status
, ulp_num
;
3478 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++) {
3479 if (test_bit(ulp_num
, &phba
->fw_config
.ulp_supported
)) {
3480 mem_descr
= (struct be_mem_descriptor
*)phba
->init_mem
;
3481 mem_descr
+= HWI_MEM_TEMPLATE_HDR_ULP0
+
3482 (ulp_num
* MEM_DESCR_OFFSET
);
3483 pm_arr
= mem_descr
->mem_array
;
3485 hwi_build_be_sgl_arr(phba
, pm_arr
, &sgl
);
3486 status
= be_cmd_iscsi_post_template_hdr(
3490 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3491 "BM_%d : Post Template HDR Failed for"
3492 "ULP_%d\n", ulp_num
);
3496 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
3497 "BM_%d : Template HDR Pages Posted for"
3498 "ULP_%d\n", ulp_num
);
3505 beiscsi_post_pages(struct beiscsi_hba
*phba
)
3507 struct be_mem_descriptor
*mem_descr
;
3508 struct mem_array
*pm_arr
;
3509 unsigned int page_offset
, i
;
3510 struct be_dma_mem sgl
;
3511 int status
, ulp_num
= 0;
3513 mem_descr
= phba
->init_mem
;
3514 mem_descr
+= HWI_MEM_SGE
;
3515 pm_arr
= mem_descr
->mem_array
;
3517 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++)
3518 if (test_bit(ulp_num
, &phba
->fw_config
.ulp_supported
))
3521 page_offset
= (sizeof(struct iscsi_sge
) * phba
->params
.num_sge_per_io
*
3522 phba
->fw_config
.iscsi_icd_start
[ulp_num
]) / PAGE_SIZE
;
3523 for (i
= 0; i
< mem_descr
->num_elements
; i
++) {
3524 hwi_build_be_sgl_arr(phba
, pm_arr
, &sgl
);
3525 status
= be_cmd_iscsi_post_sgl_pages(&phba
->ctrl
, &sgl
,
3527 (pm_arr
->size
/ PAGE_SIZE
));
3528 page_offset
+= pm_arr
->size
/ PAGE_SIZE
;
3530 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3531 "BM_%d : post sgl failed.\n");
3536 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
3537 "BM_%d : POSTED PAGES\n");
3541 static void be_queue_free(struct beiscsi_hba
*phba
, struct be_queue_info
*q
)
3543 struct be_dma_mem
*mem
= &q
->dma_mem
;
3545 pci_free_consistent(phba
->pcidev
, mem
->size
,
3551 static int be_queue_alloc(struct beiscsi_hba
*phba
, struct be_queue_info
*q
,
3552 u16 len
, u16 entry_size
)
3554 struct be_dma_mem
*mem
= &q
->dma_mem
;
3556 memset(q
, 0, sizeof(*q
));
3558 q
->entry_size
= entry_size
;
3559 mem
->size
= len
* entry_size
;
3560 mem
->va
= pci_alloc_consistent(phba
->pcidev
, mem
->size
, &mem
->dma
);
3563 memset(mem
->va
, 0, mem
->size
);
3568 beiscsi_create_wrb_rings(struct beiscsi_hba
*phba
,
3569 struct hwi_context_memory
*phwi_context
,
3570 struct hwi_controller
*phwi_ctrlr
)
3572 unsigned int wrb_mem_index
, offset
, size
, num_wrb_rings
;
3574 unsigned int idx
, num
, i
, ulp_num
;
3575 struct mem_array
*pwrb_arr
;
3577 struct be_dma_mem sgl
;
3578 struct be_mem_descriptor
*mem_descr
;
3579 struct hwi_wrb_context
*pwrb_context
;
3581 uint8_t ulp_count
= 0, ulp_base_num
= 0;
3582 uint16_t cid_count_ulp
[BEISCSI_ULP_COUNT
] = { 0 };
3585 mem_descr
= phba
->init_mem
;
3586 mem_descr
+= HWI_MEM_WRB
;
3587 pwrb_arr
= kmalloc(sizeof(*pwrb_arr
) * phba
->params
.cxns_per_ctrl
,
3590 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3591 "BM_%d : Memory alloc failed in create wrb ring.\n");
3594 wrb_vaddr
= mem_descr
->mem_array
[idx
].virtual_address
;
3595 pa_addr_lo
= mem_descr
->mem_array
[idx
].bus_address
.u
.a64
.address
;
3596 num_wrb_rings
= mem_descr
->mem_array
[idx
].size
/
3597 (phba
->params
.wrbs_per_cxn
* sizeof(struct iscsi_wrb
));
3599 for (num
= 0; num
< phba
->params
.cxns_per_ctrl
; num
++) {
3600 if (num_wrb_rings
) {
3601 pwrb_arr
[num
].virtual_address
= wrb_vaddr
;
3602 pwrb_arr
[num
].bus_address
.u
.a64
.address
= pa_addr_lo
;
3603 pwrb_arr
[num
].size
= phba
->params
.wrbs_per_cxn
*
3604 sizeof(struct iscsi_wrb
);
3605 wrb_vaddr
+= pwrb_arr
[num
].size
;
3606 pa_addr_lo
+= pwrb_arr
[num
].size
;
3610 wrb_vaddr
= mem_descr
->mem_array
[idx
].virtual_address
;
3611 pa_addr_lo
= mem_descr
->mem_array
[idx
].\
3612 bus_address
.u
.a64
.address
;
3613 num_wrb_rings
= mem_descr
->mem_array
[idx
].size
/
3614 (phba
->params
.wrbs_per_cxn
*
3615 sizeof(struct iscsi_wrb
));
3616 pwrb_arr
[num
].virtual_address
= wrb_vaddr
;
3617 pwrb_arr
[num
].bus_address
.u
.a64
.address\
3619 pwrb_arr
[num
].size
= phba
->params
.wrbs_per_cxn
*
3620 sizeof(struct iscsi_wrb
);
3621 wrb_vaddr
+= pwrb_arr
[num
].size
;
3622 pa_addr_lo
+= pwrb_arr
[num
].size
;
3627 /* Get the ULP Count */
3628 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++)
3629 if (test_bit(ulp_num
, &phba
->fw_config
.ulp_supported
)) {
3631 ulp_base_num
= ulp_num
;
3632 cid_count_ulp
[ulp_num
] =
3633 BEISCSI_GET_CID_COUNT(phba
, ulp_num
);
3636 for (i
= 0; i
< phba
->params
.cxns_per_ctrl
; i
++) {
3641 if (ulp_count
> 1) {
3642 ulp_base_num
= (ulp_base_num
+ 1) % BEISCSI_ULP_COUNT
;
3644 if (!cid_count_ulp
[ulp_base_num
])
3645 ulp_base_num
= (ulp_base_num
+ 1) %
3648 cid_count_ulp
[ulp_base_num
]--;
3652 hwi_build_be_sgl_by_offset(phba
, &pwrb_arr
[i
], &sgl
);
3653 status
= be_cmd_wrbq_create(&phba
->ctrl
, &sgl
,
3654 &phwi_context
->be_wrbq
[i
],
3655 &phwi_ctrlr
->wrb_context
[i
],
3658 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3659 "BM_%d : wrbq create failed.");
3663 pwrb_context
= &phwi_ctrlr
->wrb_context
[i
];
3664 BE_SET_CID_TO_CRI(i
, pwrb_context
->cid
);
3670 static void free_wrb_handles(struct beiscsi_hba
*phba
)
3673 struct hwi_controller
*phwi_ctrlr
;
3674 struct hwi_wrb_context
*pwrb_context
;
3676 phwi_ctrlr
= phba
->phwi_ctrlr
;
3677 for (index
= 0; index
< phba
->params
.cxns_per_ctrl
; index
++) {
3678 pwrb_context
= &phwi_ctrlr
->wrb_context
[index
];
3679 kfree(pwrb_context
->pwrb_handle_base
);
3680 kfree(pwrb_context
->pwrb_handle_basestd
);
3684 static void be_mcc_queues_destroy(struct beiscsi_hba
*phba
)
3686 struct be_queue_info
*q
;
3687 struct be_ctrl_info
*ctrl
= &phba
->ctrl
;
3689 q
= &phba
->ctrl
.mcc_obj
.q
;
3691 beiscsi_cmd_q_destroy(ctrl
, q
, QTYPE_MCCQ
);
3692 be_queue_free(phba
, q
);
3694 q
= &phba
->ctrl
.mcc_obj
.cq
;
3696 beiscsi_cmd_q_destroy(ctrl
, q
, QTYPE_CQ
);
3697 be_queue_free(phba
, q
);
3700 static void hwi_cleanup(struct beiscsi_hba
*phba
)
3702 struct be_queue_info
*q
;
3703 struct be_ctrl_info
*ctrl
= &phba
->ctrl
;
3704 struct hwi_controller
*phwi_ctrlr
;
3705 struct hwi_context_memory
*phwi_context
;
3706 struct hwi_async_pdu_context
*pasync_ctx
;
3707 int i
, eq_num
, ulp_num
;
3709 phwi_ctrlr
= phba
->phwi_ctrlr
;
3710 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
3712 be_cmd_iscsi_remove_template_hdr(ctrl
);
3714 for (i
= 0; i
< phba
->params
.cxns_per_ctrl
; i
++) {
3715 q
= &phwi_context
->be_wrbq
[i
];
3717 beiscsi_cmd_q_destroy(ctrl
, q
, QTYPE_WRBQ
);
3719 kfree(phwi_context
->be_wrbq
);
3720 free_wrb_handles(phba
);
3722 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++) {
3723 if (test_bit(ulp_num
, &phba
->fw_config
.ulp_supported
)) {
3725 q
= &phwi_context
->be_def_hdrq
[ulp_num
];
3727 beiscsi_cmd_q_destroy(ctrl
, q
, QTYPE_DPDUQ
);
3729 q
= &phwi_context
->be_def_dataq
[ulp_num
];
3731 beiscsi_cmd_q_destroy(ctrl
, q
, QTYPE_DPDUQ
);
3733 pasync_ctx
= phwi_ctrlr
->phwi_ctxt
->pasync_ctx
[ulp_num
];
3737 beiscsi_cmd_q_destroy(ctrl
, NULL
, QTYPE_SGL
);
3739 for (i
= 0; i
< (phba
->num_cpus
); i
++) {
3740 q
= &phwi_context
->be_cq
[i
];
3742 beiscsi_cmd_q_destroy(ctrl
, q
, QTYPE_CQ
);
3744 if (phba
->msix_enabled
)
3748 for (i
= 0; i
< (phba
->num_cpus
+ eq_num
); i
++) {
3749 q
= &phwi_context
->be_eq
[i
].q
;
3751 beiscsi_cmd_q_destroy(ctrl
, q
, QTYPE_EQ
);
3753 be_mcc_queues_destroy(phba
);
3754 be_cmd_fw_uninit(ctrl
);
3757 static int be_mcc_queues_create(struct beiscsi_hba
*phba
,
3758 struct hwi_context_memory
*phwi_context
)
3760 struct be_queue_info
*q
, *cq
;
3761 struct be_ctrl_info
*ctrl
= &phba
->ctrl
;
3763 /* Alloc MCC compl queue */
3764 cq
= &phba
->ctrl
.mcc_obj
.cq
;
3765 if (be_queue_alloc(phba
, cq
, MCC_CQ_LEN
,
3766 sizeof(struct be_mcc_compl
)))
3768 /* Ask BE to create MCC compl queue; */
3769 if (phba
->msix_enabled
) {
3770 if (beiscsi_cmd_cq_create(ctrl
, cq
, &phwi_context
->be_eq
3771 [phba
->num_cpus
].q
, false, true, 0))
3774 if (beiscsi_cmd_cq_create(ctrl
, cq
, &phwi_context
->be_eq
[0].q
,
3779 /* Alloc MCC queue */
3780 q
= &phba
->ctrl
.mcc_obj
.q
;
3781 if (be_queue_alloc(phba
, q
, MCC_Q_LEN
, sizeof(struct be_mcc_wrb
)))
3782 goto mcc_cq_destroy
;
3784 /* Ask BE to create MCC queue */
3785 if (beiscsi_cmd_mccq_create(phba
, q
, cq
))
3791 be_queue_free(phba
, q
);
3793 beiscsi_cmd_q_destroy(ctrl
, cq
, QTYPE_CQ
);
3795 be_queue_free(phba
, cq
);
3801 * find_num_cpus()- Get the CPU online count
3802 * @phba: ptr to priv structure
3804 * CPU count is used for creating EQ.
3806 static void find_num_cpus(struct beiscsi_hba
*phba
)
3810 num_cpus
= num_online_cpus();
3812 switch (phba
->generation
) {
3815 phba
->num_cpus
= (num_cpus
> BEISCSI_MAX_NUM_CPUS
) ?
3816 BEISCSI_MAX_NUM_CPUS
: num_cpus
;
3820 * If eqid_count == 1 fall back to
3823 if (phba
->fw_config
.eqid_count
== 1) {
3830 (num_cpus
> (phba
->fw_config
.eqid_count
- 1)) ?
3831 (phba
->fw_config
.eqid_count
- 1) : num_cpus
;
3838 static int hwi_init_port(struct beiscsi_hba
*phba
)
3840 struct hwi_controller
*phwi_ctrlr
;
3841 struct hwi_context_memory
*phwi_context
;
3842 unsigned int def_pdu_ring_sz
;
3843 struct be_ctrl_info
*ctrl
= &phba
->ctrl
;
3844 int status
, ulp_num
;
3846 phwi_ctrlr
= phba
->phwi_ctrlr
;
3847 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
3848 phwi_context
->max_eqd
= 0;
3849 phwi_context
->min_eqd
= 0;
3850 phwi_context
->cur_eqd
= 64;
3851 be_cmd_fw_initialize(&phba
->ctrl
);
3853 status
= beiscsi_create_eqs(phba
, phwi_context
);
3855 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3856 "BM_%d : EQ not created\n");
3860 status
= be_mcc_queues_create(phba
, phwi_context
);
3864 status
= mgmt_check_supported_fw(ctrl
, phba
);
3866 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3867 "BM_%d : Unsupported fw version\n");
3871 status
= beiscsi_create_cqs(phba
, phwi_context
);
3873 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3874 "BM_%d : CQ not created\n");
3878 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++) {
3879 if (test_bit(ulp_num
, &phba
->fw_config
.ulp_supported
)) {
3882 BEISCSI_GET_CID_COUNT(phba
, ulp_num
) *
3883 sizeof(struct phys_addr
);
3885 status
= beiscsi_create_def_hdr(phba
, phwi_context
,
3890 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3891 "BM_%d : Default Header not created for ULP : %d\n",
3896 status
= beiscsi_create_def_data(phba
, phwi_context
,
3901 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3902 "BM_%d : Default Data not created for ULP : %d\n",
3909 status
= beiscsi_post_pages(phba
);
3911 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3912 "BM_%d : Post SGL Pages Failed\n");
3916 status
= beiscsi_post_template_hdr(phba
);
3918 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3919 "BM_%d : Template HDR Posting for CXN Failed\n");
3922 status
= beiscsi_create_wrb_rings(phba
, phwi_context
, phwi_ctrlr
);
3924 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3925 "BM_%d : WRB Rings not created\n");
3929 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++) {
3930 uint16_t async_arr_idx
= 0;
3932 if (test_bit(ulp_num
, &phba
->fw_config
.ulp_supported
)) {
3934 struct hwi_async_pdu_context
*pasync_ctx
;
3936 pasync_ctx
= HWI_GET_ASYNC_PDU_CTX(
3937 phwi_ctrlr
, ulp_num
);
3939 phba
->params
.cxns_per_ctrl
; cri
++) {
3940 if (ulp_num
== BEISCSI_GET_ULP_FROM_CRI
3942 pasync_ctx
->cid_to_async_cri_map
[
3943 phwi_ctrlr
->wrb_context
[cri
].cid
] =
3949 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
3950 "BM_%d : hwi_init_port success\n");
3954 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3955 "BM_%d : hwi_init_port failed");
3960 static int hwi_init_controller(struct beiscsi_hba
*phba
)
3962 struct hwi_controller
*phwi_ctrlr
;
3964 phwi_ctrlr
= phba
->phwi_ctrlr
;
3965 if (1 == phba
->init_mem
[HWI_MEM_ADDN_CONTEXT
].num_elements
) {
3966 phwi_ctrlr
->phwi_ctxt
= (struct hwi_context_memory
*)phba
->
3967 init_mem
[HWI_MEM_ADDN_CONTEXT
].mem_array
[0].virtual_address
;
3968 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
3969 "BM_%d : phwi_ctrlr->phwi_ctxt=%p\n",
3970 phwi_ctrlr
->phwi_ctxt
);
3972 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3973 "BM_%d : HWI_MEM_ADDN_CONTEXT is more "
3974 "than one element.Failing to load\n");
3978 iscsi_init_global_templates(phba
);
3979 if (beiscsi_init_wrb_handle(phba
))
3982 if (hwi_init_async_pdu_ctx(phba
)) {
3983 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3984 "BM_%d : hwi_init_async_pdu_ctx failed\n");
3988 if (hwi_init_port(phba
) != 0) {
3989 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3990 "BM_%d : hwi_init_controller failed\n");
3997 static void beiscsi_free_mem(struct beiscsi_hba
*phba
)
3999 struct be_mem_descriptor
*mem_descr
;
4002 mem_descr
= phba
->init_mem
;
4005 for (i
= 0; i
< SE_MEM_MAX
; i
++) {
4006 for (j
= mem_descr
->num_elements
; j
> 0; j
--) {
4007 pci_free_consistent(phba
->pcidev
,
4008 mem_descr
->mem_array
[j
- 1].size
,
4009 mem_descr
->mem_array
[j
- 1].virtual_address
,
4010 (unsigned long)mem_descr
->mem_array
[j
- 1].
4011 bus_address
.u
.a64
.address
);
4014 kfree(mem_descr
->mem_array
);
4017 kfree(phba
->init_mem
);
4018 kfree(phba
->phwi_ctrlr
->wrb_context
);
4019 kfree(phba
->phwi_ctrlr
);
4022 static int beiscsi_init_controller(struct beiscsi_hba
*phba
)
4026 ret
= beiscsi_get_memory(phba
);
4028 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
4029 "BM_%d : beiscsi_dev_probe -"
4030 "Failed in beiscsi_alloc_memory\n");
4034 ret
= hwi_init_controller(phba
);
4037 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
4038 "BM_%d : Return success from beiscsi_init_controller");
4043 beiscsi_free_mem(phba
);
4047 static int beiscsi_init_sgl_handle(struct beiscsi_hba
*phba
)
4049 struct be_mem_descriptor
*mem_descr_sglh
, *mem_descr_sg
;
4050 struct sgl_handle
*psgl_handle
;
4051 struct iscsi_sge
*pfrag
;
4052 unsigned int arr_index
, i
, idx
;
4053 unsigned int ulp_icd_start
, ulp_num
= 0;
4055 phba
->io_sgl_hndl_avbl
= 0;
4056 phba
->eh_sgl_hndl_avbl
= 0;
4058 mem_descr_sglh
= phba
->init_mem
;
4059 mem_descr_sglh
+= HWI_MEM_SGLH
;
4060 if (1 == mem_descr_sglh
->num_elements
) {
4061 phba
->io_sgl_hndl_base
= kzalloc(sizeof(struct sgl_handle
*) *
4062 phba
->params
.ios_per_ctrl
,
4064 if (!phba
->io_sgl_hndl_base
) {
4065 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
4066 "BM_%d : Mem Alloc Failed. Failing to load\n");
4069 phba
->eh_sgl_hndl_base
= kzalloc(sizeof(struct sgl_handle
*) *
4070 (phba
->params
.icds_per_ctrl
-
4071 phba
->params
.ios_per_ctrl
),
4073 if (!phba
->eh_sgl_hndl_base
) {
4074 kfree(phba
->io_sgl_hndl_base
);
4075 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
4076 "BM_%d : Mem Alloc Failed. Failing to load\n");
4080 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
4081 "BM_%d : HWI_MEM_SGLH is more than one element."
4082 "Failing to load\n");
4088 while (idx
< mem_descr_sglh
->num_elements
) {
4089 psgl_handle
= mem_descr_sglh
->mem_array
[idx
].virtual_address
;
4091 for (i
= 0; i
< (mem_descr_sglh
->mem_array
[idx
].size
/
4092 sizeof(struct sgl_handle
)); i
++) {
4093 if (arr_index
< phba
->params
.ios_per_ctrl
) {
4094 phba
->io_sgl_hndl_base
[arr_index
] = psgl_handle
;
4095 phba
->io_sgl_hndl_avbl
++;
4098 phba
->eh_sgl_hndl_base
[arr_index
-
4099 phba
->params
.ios_per_ctrl
] =
4102 phba
->eh_sgl_hndl_avbl
++;
4108 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
4109 "BM_%d : phba->io_sgl_hndl_avbl=%d"
4110 "phba->eh_sgl_hndl_avbl=%d\n",
4111 phba
->io_sgl_hndl_avbl
,
4112 phba
->eh_sgl_hndl_avbl
);
4114 mem_descr_sg
= phba
->init_mem
;
4115 mem_descr_sg
+= HWI_MEM_SGE
;
4116 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
4117 "\n BM_%d : mem_descr_sg->num_elements=%d\n",
4118 mem_descr_sg
->num_elements
);
4120 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++)
4121 if (test_bit(ulp_num
, &phba
->fw_config
.ulp_supported
))
4124 ulp_icd_start
= phba
->fw_config
.iscsi_icd_start
[ulp_num
];
4128 while (idx
< mem_descr_sg
->num_elements
) {
4129 pfrag
= mem_descr_sg
->mem_array
[idx
].virtual_address
;
4132 i
< (mem_descr_sg
->mem_array
[idx
].size
) /
4133 (sizeof(struct iscsi_sge
) * phba
->params
.num_sge_per_io
);
4135 if (arr_index
< phba
->params
.ios_per_ctrl
)
4136 psgl_handle
= phba
->io_sgl_hndl_base
[arr_index
];
4138 psgl_handle
= phba
->eh_sgl_hndl_base
[arr_index
-
4139 phba
->params
.ios_per_ctrl
];
4140 psgl_handle
->pfrag
= pfrag
;
4141 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_hi
, pfrag
, 0);
4142 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_lo
, pfrag
, 0);
4143 pfrag
+= phba
->params
.num_sge_per_io
;
4144 psgl_handle
->sgl_index
= ulp_icd_start
+ arr_index
++;
4148 phba
->io_sgl_free_index
= 0;
4149 phba
->io_sgl_alloc_index
= 0;
4150 phba
->eh_sgl_free_index
= 0;
4151 phba
->eh_sgl_alloc_index
= 0;
4155 static int hba_setup_cid_tbls(struct beiscsi_hba
*phba
)
4158 uint16_t i
, ulp_num
;
4159 struct ulp_cid_info
*ptr_cid_info
= NULL
;
4161 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++) {
4162 if (test_bit(ulp_num
, (void *)&phba
->fw_config
.ulp_supported
)) {
4163 ptr_cid_info
= kzalloc(sizeof(struct ulp_cid_info
),
4166 if (!ptr_cid_info
) {
4167 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
4168 "BM_%d : Failed to allocate memory"
4169 "for ULP_CID_INFO for ULP : %d\n",
4176 /* Allocate memory for CID array */
4177 ptr_cid_info
->cid_array
= kzalloc(sizeof(void *) *
4178 BEISCSI_GET_CID_COUNT(phba
,
4179 ulp_num
), GFP_KERNEL
);
4180 if (!ptr_cid_info
->cid_array
) {
4181 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
4182 "BM_%d : Failed to allocate memory"
4183 "for CID_ARRAY for ULP : %d\n",
4185 kfree(ptr_cid_info
);
4186 ptr_cid_info
= NULL
;
4191 ptr_cid_info
->avlbl_cids
= BEISCSI_GET_CID_COUNT(
4194 /* Save the cid_info_array ptr */
4195 phba
->cid_array_info
[ulp_num
] = ptr_cid_info
;
4198 phba
->ep_array
= kzalloc(sizeof(struct iscsi_endpoint
*) *
4199 phba
->params
.cxns_per_ctrl
, GFP_KERNEL
);
4200 if (!phba
->ep_array
) {
4201 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
4202 "BM_%d : Failed to allocate memory in "
4203 "hba_setup_cid_tbls\n");
4209 phba
->conn_table
= kzalloc(sizeof(struct beiscsi_conn
*) *
4210 phba
->params
.cxns_per_ctrl
, GFP_KERNEL
);
4211 if (!phba
->conn_table
) {
4212 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
4213 "BM_%d : Failed to allocate memory in"
4214 "hba_setup_cid_tbls\n");
4216 kfree(phba
->ep_array
);
4217 phba
->ep_array
= NULL
;
4221 for (i
= 0; i
< phba
->params
.cxns_per_ctrl
; i
++) {
4222 ulp_num
= phba
->phwi_ctrlr
->wrb_context
[i
].ulp_num
;
4224 ptr_cid_info
= phba
->cid_array_info
[ulp_num
];
4225 ptr_cid_info
->cid_array
[ptr_cid_info
->cid_alloc
++] =
4226 phba
->phwi_ctrlr
->wrb_context
[i
].cid
;
4230 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++) {
4231 if (test_bit(ulp_num
, (void *)&phba
->fw_config
.ulp_supported
)) {
4232 ptr_cid_info
= phba
->cid_array_info
[ulp_num
];
4234 ptr_cid_info
->cid_alloc
= 0;
4235 ptr_cid_info
->cid_free
= 0;
4241 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++) {
4242 if (test_bit(ulp_num
, (void *)&phba
->fw_config
.ulp_supported
)) {
4243 ptr_cid_info
= phba
->cid_array_info
[ulp_num
];
4246 kfree(ptr_cid_info
->cid_array
);
4247 kfree(ptr_cid_info
);
4248 phba
->cid_array_info
[ulp_num
] = NULL
;
4256 static void hwi_enable_intr(struct beiscsi_hba
*phba
)
4258 struct be_ctrl_info
*ctrl
= &phba
->ctrl
;
4259 struct hwi_controller
*phwi_ctrlr
;
4260 struct hwi_context_memory
*phwi_context
;
4261 struct be_queue_info
*eq
;
4266 phwi_ctrlr
= phba
->phwi_ctrlr
;
4267 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
4269 addr
= (u8 __iomem
*) ((u8 __iomem
*) ctrl
->pcicfg
+
4270 PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET
);
4271 reg
= ioread32(addr
);
4273 enabled
= reg
& MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK
;
4275 reg
|= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK
;
4276 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
4277 "BM_%d : reg =x%08x addr=%p\n", reg
, addr
);
4278 iowrite32(reg
, addr
);
4281 if (!phba
->msix_enabled
) {
4282 eq
= &phwi_context
->be_eq
[0].q
;
4283 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
4284 "BM_%d : eq->id=%d\n", eq
->id
);
4286 hwi_ring_eq_db(phba
, eq
->id
, 0, 0, 1, 1);
4288 for (i
= 0; i
<= phba
->num_cpus
; i
++) {
4289 eq
= &phwi_context
->be_eq
[i
].q
;
4290 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
4291 "BM_%d : eq->id=%d\n", eq
->id
);
4292 hwi_ring_eq_db(phba
, eq
->id
, 0, 0, 1, 1);
4297 static void hwi_disable_intr(struct beiscsi_hba
*phba
)
4299 struct be_ctrl_info
*ctrl
= &phba
->ctrl
;
4301 u8 __iomem
*addr
= ctrl
->pcicfg
+ PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET
;
4302 u32 reg
= ioread32(addr
);
4304 u32 enabled
= reg
& MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK
;
4306 reg
&= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK
;
4307 iowrite32(reg
, addr
);
4309 beiscsi_log(phba
, KERN_WARNING
, BEISCSI_LOG_INIT
,
4310 "BM_%d : In hwi_disable_intr, Already Disabled\n");
4314 * beiscsi_get_boot_info()- Get the boot session info
4315 * @phba: The device priv structure instance
4317 * Get the boot target info and store in driver priv structure
4321 * Failure: Non-Zero Value
4323 static int beiscsi_get_boot_info(struct beiscsi_hba
*phba
)
4325 struct be_cmd_get_session_resp
*session_resp
;
4326 struct be_dma_mem nonemb_cmd
;
4328 unsigned int s_handle
;
4331 /* Get the session handle of the boot target */
4332 ret
= be_mgmt_get_boot_shandle(phba
, &s_handle
);
4334 beiscsi_log(phba
, KERN_ERR
,
4335 BEISCSI_LOG_INIT
| BEISCSI_LOG_CONFIG
,
4336 "BM_%d : No boot session\n");
4339 nonemb_cmd
.va
= pci_alloc_consistent(phba
->ctrl
.pdev
,
4340 sizeof(*session_resp
),
4342 if (nonemb_cmd
.va
== NULL
) {
4343 beiscsi_log(phba
, KERN_ERR
,
4344 BEISCSI_LOG_INIT
| BEISCSI_LOG_CONFIG
,
4345 "BM_%d : Failed to allocate memory for"
4346 "beiscsi_get_session_info\n");
4351 memset(nonemb_cmd
.va
, 0, sizeof(*session_resp
));
4352 tag
= mgmt_get_session_info(phba
, s_handle
,
4355 beiscsi_log(phba
, KERN_ERR
,
4356 BEISCSI_LOG_INIT
| BEISCSI_LOG_CONFIG
,
4357 "BM_%d : beiscsi_get_session_info"
4363 ret
= beiscsi_mccq_compl(phba
, tag
, NULL
, nonemb_cmd
.va
);
4365 beiscsi_log(phba
, KERN_ERR
,
4366 BEISCSI_LOG_INIT
| BEISCSI_LOG_CONFIG
,
4367 "BM_%d : beiscsi_get_session_info Failed");
4371 session_resp
= nonemb_cmd
.va
;
4373 memcpy(&phba
->boot_sess
, &session_resp
->session_info
,
4374 sizeof(struct mgmt_session_info
));
4378 pci_free_consistent(phba
->ctrl
.pdev
, nonemb_cmd
.size
,
4379 nonemb_cmd
.va
, nonemb_cmd
.dma
);
4383 static void beiscsi_boot_release(void *data
)
4385 struct beiscsi_hba
*phba
= data
;
4387 scsi_host_put(phba
->shost
);
4390 static int beiscsi_setup_boot_info(struct beiscsi_hba
*phba
)
4392 struct iscsi_boot_kobj
*boot_kobj
;
4394 /* get boot info using mgmt cmd */
4395 if (beiscsi_get_boot_info(phba
))
4396 /* Try to see if we can carry on without this */
4399 phba
->boot_kset
= iscsi_boot_create_host_kset(phba
->shost
->host_no
);
4400 if (!phba
->boot_kset
)
4403 /* get a ref because the show function will ref the phba */
4404 if (!scsi_host_get(phba
->shost
))
4406 boot_kobj
= iscsi_boot_create_target(phba
->boot_kset
, 0, phba
,
4407 beiscsi_show_boot_tgt_info
,
4408 beiscsi_tgt_get_attr_visibility
,
4409 beiscsi_boot_release
);
4413 if (!scsi_host_get(phba
->shost
))
4415 boot_kobj
= iscsi_boot_create_initiator(phba
->boot_kset
, 0, phba
,
4416 beiscsi_show_boot_ini_info
,
4417 beiscsi_ini_get_attr_visibility
,
4418 beiscsi_boot_release
);
4422 if (!scsi_host_get(phba
->shost
))
4424 boot_kobj
= iscsi_boot_create_ethernet(phba
->boot_kset
, 0, phba
,
4425 beiscsi_show_boot_eth_info
,
4426 beiscsi_eth_get_attr_visibility
,
4427 beiscsi_boot_release
);
4433 scsi_host_put(phba
->shost
);
4435 iscsi_boot_destroy_kset(phba
->boot_kset
);
4439 static int beiscsi_init_port(struct beiscsi_hba
*phba
)
4443 ret
= beiscsi_init_controller(phba
);
4445 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
4446 "BM_%d : beiscsi_dev_probe - Failed in"
4447 "beiscsi_init_controller\n");
4450 ret
= beiscsi_init_sgl_handle(phba
);
4452 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
4453 "BM_%d : beiscsi_dev_probe - Failed in"
4454 "beiscsi_init_sgl_handle\n");
4455 goto do_cleanup_ctrlr
;
4458 if (hba_setup_cid_tbls(phba
)) {
4459 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
4460 "BM_%d : Failed in hba_setup_cid_tbls\n");
4461 kfree(phba
->io_sgl_hndl_base
);
4462 kfree(phba
->eh_sgl_hndl_base
);
4463 goto do_cleanup_ctrlr
;
4473 static void hwi_purge_eq(struct beiscsi_hba
*phba
)
4475 struct hwi_controller
*phwi_ctrlr
;
4476 struct hwi_context_memory
*phwi_context
;
4477 struct be_queue_info
*eq
;
4478 struct be_eq_entry
*eqe
= NULL
;
4480 unsigned int num_processed
;
4482 phwi_ctrlr
= phba
->phwi_ctrlr
;
4483 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
4484 if (phba
->msix_enabled
)
4489 for (i
= 0; i
< (phba
->num_cpus
+ eq_msix
); i
++) {
4490 eq
= &phwi_context
->be_eq
[i
].q
;
4491 eqe
= queue_tail_node(eq
);
4493 while (eqe
->dw
[offsetof(struct amap_eq_entry
, valid
) / 32]
4495 AMAP_SET_BITS(struct amap_eq_entry
, valid
, eqe
, 0);
4497 eqe
= queue_tail_node(eq
);
4502 hwi_ring_eq_db(phba
, eq
->id
, 1, num_processed
, 1, 1);
4506 static void beiscsi_clean_port(struct beiscsi_hba
*phba
)
4508 int mgmt_status
, ulp_num
;
4509 struct ulp_cid_info
*ptr_cid_info
= NULL
;
4511 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++) {
4512 if (test_bit(ulp_num
, (void *)&phba
->fw_config
.ulp_supported
)) {
4513 mgmt_status
= mgmt_epfw_cleanup(phba
, ulp_num
);
4515 beiscsi_log(phba
, KERN_WARNING
,
4517 "BM_%d : mgmt_epfw_cleanup FAILED"
4518 " for ULP_%d\n", ulp_num
);
4524 kfree(phba
->io_sgl_hndl_base
);
4525 kfree(phba
->eh_sgl_hndl_base
);
4526 kfree(phba
->ep_array
);
4527 kfree(phba
->conn_table
);
4529 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++) {
4530 if (test_bit(ulp_num
, (void *)&phba
->fw_config
.ulp_supported
)) {
4531 ptr_cid_info
= phba
->cid_array_info
[ulp_num
];
4534 kfree(ptr_cid_info
->cid_array
);
4535 kfree(ptr_cid_info
);
4536 phba
->cid_array_info
[ulp_num
] = NULL
;
4544 * beiscsi_free_mgmt_task_handles()- Free driver CXN resources
4545 * @beiscsi_conn: ptr to the conn to be cleaned up
4546 * @task: ptr to iscsi_task resource to be freed.
4548 * Free driver mgmt resources binded to CXN.
4551 beiscsi_free_mgmt_task_handles(struct beiscsi_conn
*beiscsi_conn
,
4552 struct iscsi_task
*task
)
4554 struct beiscsi_io_task
*io_task
;
4555 struct beiscsi_hba
*phba
= beiscsi_conn
->phba
;
4556 struct hwi_wrb_context
*pwrb_context
;
4557 struct hwi_controller
*phwi_ctrlr
;
4558 uint16_t cri_index
= BE_GET_CRI_FROM_CID(
4559 beiscsi_conn
->beiscsi_conn_cid
);
4561 phwi_ctrlr
= phba
->phwi_ctrlr
;
4562 pwrb_context
= &phwi_ctrlr
->wrb_context
[cri_index
];
4564 io_task
= task
->dd_data
;
4566 if (io_task
->pwrb_handle
) {
4567 memset(io_task
->pwrb_handle
->pwrb
, 0,
4568 sizeof(struct iscsi_wrb
));
4569 free_wrb_handle(phba
, pwrb_context
,
4570 io_task
->pwrb_handle
);
4571 io_task
->pwrb_handle
= NULL
;
4574 if (io_task
->psgl_handle
) {
4575 spin_lock_bh(&phba
->mgmt_sgl_lock
);
4576 free_mgmt_sgl_handle(phba
,
4577 io_task
->psgl_handle
);
4578 io_task
->psgl_handle
= NULL
;
4579 spin_unlock_bh(&phba
->mgmt_sgl_lock
);
4582 if (io_task
->mtask_addr
)
4583 pci_unmap_single(phba
->pcidev
,
4584 io_task
->mtask_addr
,
4585 io_task
->mtask_data_count
,
4590 * beiscsi_cleanup_task()- Free driver resources of the task
4591 * @task: ptr to the iscsi task
4594 static void beiscsi_cleanup_task(struct iscsi_task
*task
)
4596 struct beiscsi_io_task
*io_task
= task
->dd_data
;
4597 struct iscsi_conn
*conn
= task
->conn
;
4598 struct beiscsi_conn
*beiscsi_conn
= conn
->dd_data
;
4599 struct beiscsi_hba
*phba
= beiscsi_conn
->phba
;
4600 struct beiscsi_session
*beiscsi_sess
= beiscsi_conn
->beiscsi_sess
;
4601 struct hwi_wrb_context
*pwrb_context
;
4602 struct hwi_controller
*phwi_ctrlr
;
4603 uint16_t cri_index
= BE_GET_CRI_FROM_CID(
4604 beiscsi_conn
->beiscsi_conn_cid
);
4606 phwi_ctrlr
= phba
->phwi_ctrlr
;
4607 pwrb_context
= &phwi_ctrlr
->wrb_context
[cri_index
];
4609 if (io_task
->cmd_bhs
) {
4610 pci_pool_free(beiscsi_sess
->bhs_pool
, io_task
->cmd_bhs
,
4611 io_task
->bhs_pa
.u
.a64
.address
);
4612 io_task
->cmd_bhs
= NULL
;
4616 if (io_task
->pwrb_handle
) {
4617 free_wrb_handle(phba
, pwrb_context
,
4618 io_task
->pwrb_handle
);
4619 io_task
->pwrb_handle
= NULL
;
4622 if (io_task
->psgl_handle
) {
4623 spin_lock(&phba
->io_sgl_lock
);
4624 free_io_sgl_handle(phba
, io_task
->psgl_handle
);
4625 spin_unlock(&phba
->io_sgl_lock
);
4626 io_task
->psgl_handle
= NULL
;
4629 if (!beiscsi_conn
->login_in_progress
)
4630 beiscsi_free_mgmt_task_handles(beiscsi_conn
, task
);
4635 beiscsi_offload_connection(struct beiscsi_conn
*beiscsi_conn
,
4636 struct beiscsi_offload_params
*params
)
4638 struct wrb_handle
*pwrb_handle
;
4639 struct beiscsi_hba
*phba
= beiscsi_conn
->phba
;
4640 struct iscsi_task
*task
= beiscsi_conn
->task
;
4641 struct iscsi_session
*session
= task
->conn
->session
;
4645 * We can always use 0 here because it is reserved by libiscsi for
4646 * login/startup related tasks.
4648 beiscsi_conn
->login_in_progress
= 0;
4649 spin_lock_bh(&session
->lock
);
4650 beiscsi_cleanup_task(task
);
4651 spin_unlock_bh(&session
->lock
);
4653 pwrb_handle
= alloc_wrb_handle(phba
, beiscsi_conn
->beiscsi_conn_cid
);
4655 /* Check for the adapter family */
4656 if (is_chip_be2_be3r(phba
))
4657 beiscsi_offload_cxn_v0(params
, pwrb_handle
,
4660 beiscsi_offload_cxn_v2(params
, pwrb_handle
);
4662 be_dws_le_to_cpu(pwrb_handle
->pwrb
,
4663 sizeof(struct iscsi_target_context_update_wrb
));
4665 doorbell
|= beiscsi_conn
->beiscsi_conn_cid
& DB_WRB_POST_CID_MASK
;
4666 doorbell
|= (pwrb_handle
->wrb_index
& DB_DEF_PDU_WRB_INDEX_MASK
)
4667 << DB_DEF_PDU_WRB_INDEX_SHIFT
;
4668 doorbell
|= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT
;
4669 iowrite32(doorbell
, phba
->db_va
+
4670 beiscsi_conn
->doorbell_offset
);
4673 static void beiscsi_parse_pdu(struct iscsi_conn
*conn
, itt_t itt
,
4674 int *index
, int *age
)
4678 *age
= conn
->session
->age
;
4682 * beiscsi_alloc_pdu - allocates pdu and related resources
4683 * @task: libiscsi task
4684 * @opcode: opcode of pdu for task
4686 * This is called with the session lock held. It will allocate
4687 * the wrb and sgl if needed for the command. And it will prep
4688 * the pdu's itt. beiscsi_parse_pdu will later translate
4689 * the pdu itt to the libiscsi task itt.
4691 static int beiscsi_alloc_pdu(struct iscsi_task
*task
, uint8_t opcode
)
4693 struct beiscsi_io_task
*io_task
= task
->dd_data
;
4694 struct iscsi_conn
*conn
= task
->conn
;
4695 struct beiscsi_conn
*beiscsi_conn
= conn
->dd_data
;
4696 struct beiscsi_hba
*phba
= beiscsi_conn
->phba
;
4697 struct hwi_wrb_context
*pwrb_context
;
4698 struct hwi_controller
*phwi_ctrlr
;
4700 uint16_t cri_index
= 0;
4701 struct beiscsi_session
*beiscsi_sess
= beiscsi_conn
->beiscsi_sess
;
4704 io_task
->cmd_bhs
= pci_pool_alloc(beiscsi_sess
->bhs_pool
,
4705 GFP_ATOMIC
, &paddr
);
4706 if (!io_task
->cmd_bhs
)
4708 io_task
->bhs_pa
.u
.a64
.address
= paddr
;
4709 io_task
->libiscsi_itt
= (itt_t
)task
->itt
;
4710 io_task
->conn
= beiscsi_conn
;
4712 task
->hdr
= (struct iscsi_hdr
*)&io_task
->cmd_bhs
->iscsi_hdr
;
4713 task
->hdr_max
= sizeof(struct be_cmd_bhs
);
4714 io_task
->psgl_handle
= NULL
;
4715 io_task
->pwrb_handle
= NULL
;
4718 spin_lock(&phba
->io_sgl_lock
);
4719 io_task
->psgl_handle
= alloc_io_sgl_handle(phba
);
4720 spin_unlock(&phba
->io_sgl_lock
);
4721 if (!io_task
->psgl_handle
) {
4722 beiscsi_log(phba
, KERN_ERR
,
4723 BEISCSI_LOG_IO
| BEISCSI_LOG_CONFIG
,
4724 "BM_%d : Alloc of IO_SGL_ICD Failed"
4725 "for the CID : %d\n",
4726 beiscsi_conn
->beiscsi_conn_cid
);
4729 io_task
->pwrb_handle
= alloc_wrb_handle(phba
,
4730 beiscsi_conn
->beiscsi_conn_cid
);
4731 if (!io_task
->pwrb_handle
) {
4732 beiscsi_log(phba
, KERN_ERR
,
4733 BEISCSI_LOG_IO
| BEISCSI_LOG_CONFIG
,
4734 "BM_%d : Alloc of WRB_HANDLE Failed"
4735 "for the CID : %d\n",
4736 beiscsi_conn
->beiscsi_conn_cid
);
4740 io_task
->scsi_cmnd
= NULL
;
4741 if ((opcode
& ISCSI_OPCODE_MASK
) == ISCSI_OP_LOGIN
) {
4742 beiscsi_conn
->task
= task
;
4743 if (!beiscsi_conn
->login_in_progress
) {
4744 spin_lock(&phba
->mgmt_sgl_lock
);
4745 io_task
->psgl_handle
= (struct sgl_handle
*)
4746 alloc_mgmt_sgl_handle(phba
);
4747 spin_unlock(&phba
->mgmt_sgl_lock
);
4748 if (!io_task
->psgl_handle
) {
4749 beiscsi_log(phba
, KERN_ERR
,
4752 "BM_%d : Alloc of MGMT_SGL_ICD Failed"
4753 "for the CID : %d\n",
4759 beiscsi_conn
->login_in_progress
= 1;
4760 beiscsi_conn
->plogin_sgl_handle
=
4761 io_task
->psgl_handle
;
4762 io_task
->pwrb_handle
=
4763 alloc_wrb_handle(phba
,
4764 beiscsi_conn
->beiscsi_conn_cid
);
4765 if (!io_task
->pwrb_handle
) {
4766 beiscsi_log(phba
, KERN_ERR
,
4769 "BM_%d : Alloc of WRB_HANDLE Failed"
4770 "for the CID : %d\n",
4773 goto free_mgmt_hndls
;
4775 beiscsi_conn
->plogin_wrb_handle
=
4776 io_task
->pwrb_handle
;
4779 io_task
->psgl_handle
=
4780 beiscsi_conn
->plogin_sgl_handle
;
4781 io_task
->pwrb_handle
=
4782 beiscsi_conn
->plogin_wrb_handle
;
4785 spin_lock(&phba
->mgmt_sgl_lock
);
4786 io_task
->psgl_handle
= alloc_mgmt_sgl_handle(phba
);
4787 spin_unlock(&phba
->mgmt_sgl_lock
);
4788 if (!io_task
->psgl_handle
) {
4789 beiscsi_log(phba
, KERN_ERR
,
4792 "BM_%d : Alloc of MGMT_SGL_ICD Failed"
4793 "for the CID : %d\n",
4798 io_task
->pwrb_handle
=
4799 alloc_wrb_handle(phba
,
4800 beiscsi_conn
->beiscsi_conn_cid
);
4801 if (!io_task
->pwrb_handle
) {
4802 beiscsi_log(phba
, KERN_ERR
,
4803 BEISCSI_LOG_IO
| BEISCSI_LOG_CONFIG
,
4804 "BM_%d : Alloc of WRB_HANDLE Failed"
4805 "for the CID : %d\n",
4806 beiscsi_conn
->beiscsi_conn_cid
);
4807 goto free_mgmt_hndls
;
4812 itt
= (itt_t
) cpu_to_be32(((unsigned int)io_task
->pwrb_handle
->
4813 wrb_index
<< 16) | (unsigned int)
4814 (io_task
->psgl_handle
->sgl_index
));
4815 io_task
->pwrb_handle
->pio_handle
= task
;
4817 io_task
->cmd_bhs
->iscsi_hdr
.itt
= itt
;
4821 spin_lock(&phba
->io_sgl_lock
);
4822 free_io_sgl_handle(phba
, io_task
->psgl_handle
);
4823 spin_unlock(&phba
->io_sgl_lock
);
4826 spin_lock(&phba
->mgmt_sgl_lock
);
4827 free_mgmt_sgl_handle(phba
, io_task
->psgl_handle
);
4828 io_task
->psgl_handle
= NULL
;
4829 spin_unlock(&phba
->mgmt_sgl_lock
);
4831 phwi_ctrlr
= phba
->phwi_ctrlr
;
4832 cri_index
= BE_GET_CRI_FROM_CID(
4833 beiscsi_conn
->beiscsi_conn_cid
);
4834 pwrb_context
= &phwi_ctrlr
->wrb_context
[cri_index
];
4835 if (io_task
->pwrb_handle
)
4836 free_wrb_handle(phba
, pwrb_context
, io_task
->pwrb_handle
);
4837 io_task
->pwrb_handle
= NULL
;
4838 pci_pool_free(beiscsi_sess
->bhs_pool
, io_task
->cmd_bhs
,
4839 io_task
->bhs_pa
.u
.a64
.address
);
4840 io_task
->cmd_bhs
= NULL
;
4843 int beiscsi_iotask_v2(struct iscsi_task
*task
, struct scatterlist
*sg
,
4844 unsigned int num_sg
, unsigned int xferlen
,
4845 unsigned int writedir
)
4848 struct beiscsi_io_task
*io_task
= task
->dd_data
;
4849 struct iscsi_conn
*conn
= task
->conn
;
4850 struct beiscsi_conn
*beiscsi_conn
= conn
->dd_data
;
4851 struct beiscsi_hba
*phba
= beiscsi_conn
->phba
;
4852 struct iscsi_wrb
*pwrb
= NULL
;
4853 unsigned int doorbell
= 0;
4855 pwrb
= io_task
->pwrb_handle
->pwrb
;
4857 io_task
->cmd_bhs
->iscsi_hdr
.exp_statsn
= 0;
4858 io_task
->bhs_len
= sizeof(struct be_cmd_bhs
);
4861 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, type
, pwrb
,
4863 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, dsp
, pwrb
, 1);
4865 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, type
, pwrb
,
4867 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, dsp
, pwrb
, 0);
4870 io_task
->wrb_type
= AMAP_GET_BITS(struct amap_iscsi_wrb_v2
,
4873 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, lun
, pwrb
,
4874 cpu_to_be16(*(unsigned short *)
4875 &io_task
->cmd_bhs
->iscsi_hdr
.lun
));
4876 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, r2t_exp_dtl
, pwrb
, xferlen
);
4877 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, wrb_idx
, pwrb
,
4878 io_task
->pwrb_handle
->wrb_index
);
4879 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, cmdsn_itt
, pwrb
,
4880 be32_to_cpu(task
->cmdsn
));
4881 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, sgl_idx
, pwrb
,
4882 io_task
->psgl_handle
->sgl_index
);
4884 hwi_write_sgl_v2(pwrb
, sg
, num_sg
, io_task
);
4885 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, ptr2nextwrb
, pwrb
,
4886 io_task
->pwrb_handle
->nxt_wrb_index
);
4888 be_dws_le_to_cpu(pwrb
, sizeof(struct iscsi_wrb
));
4890 doorbell
|= beiscsi_conn
->beiscsi_conn_cid
& DB_WRB_POST_CID_MASK
;
4891 doorbell
|= (io_task
->pwrb_handle
->wrb_index
&
4892 DB_DEF_PDU_WRB_INDEX_MASK
) <<
4893 DB_DEF_PDU_WRB_INDEX_SHIFT
;
4894 doorbell
|= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT
;
4895 iowrite32(doorbell
, phba
->db_va
+
4896 beiscsi_conn
->doorbell_offset
);
4900 static int beiscsi_iotask(struct iscsi_task
*task
, struct scatterlist
*sg
,
4901 unsigned int num_sg
, unsigned int xferlen
,
4902 unsigned int writedir
)
4905 struct beiscsi_io_task
*io_task
= task
->dd_data
;
4906 struct iscsi_conn
*conn
= task
->conn
;
4907 struct beiscsi_conn
*beiscsi_conn
= conn
->dd_data
;
4908 struct beiscsi_hba
*phba
= beiscsi_conn
->phba
;
4909 struct iscsi_wrb
*pwrb
= NULL
;
4910 unsigned int doorbell
= 0;
4912 pwrb
= io_task
->pwrb_handle
->pwrb
;
4913 io_task
->cmd_bhs
->iscsi_hdr
.exp_statsn
= 0;
4914 io_task
->bhs_len
= sizeof(struct be_cmd_bhs
);
4917 AMAP_SET_BITS(struct amap_iscsi_wrb
, type
, pwrb
,
4919 AMAP_SET_BITS(struct amap_iscsi_wrb
, dsp
, pwrb
, 1);
4921 AMAP_SET_BITS(struct amap_iscsi_wrb
, type
, pwrb
,
4923 AMAP_SET_BITS(struct amap_iscsi_wrb
, dsp
, pwrb
, 0);
4926 io_task
->wrb_type
= AMAP_GET_BITS(struct amap_iscsi_wrb
,
4929 AMAP_SET_BITS(struct amap_iscsi_wrb
, lun
, pwrb
,
4930 cpu_to_be16(*(unsigned short *)
4931 &io_task
->cmd_bhs
->iscsi_hdr
.lun
));
4932 AMAP_SET_BITS(struct amap_iscsi_wrb
, r2t_exp_dtl
, pwrb
, xferlen
);
4933 AMAP_SET_BITS(struct amap_iscsi_wrb
, wrb_idx
, pwrb
,
4934 io_task
->pwrb_handle
->wrb_index
);
4935 AMAP_SET_BITS(struct amap_iscsi_wrb
, cmdsn_itt
, pwrb
,
4936 be32_to_cpu(task
->cmdsn
));
4937 AMAP_SET_BITS(struct amap_iscsi_wrb
, sgl_icd_idx
, pwrb
,
4938 io_task
->psgl_handle
->sgl_index
);
4940 hwi_write_sgl(pwrb
, sg
, num_sg
, io_task
);
4942 AMAP_SET_BITS(struct amap_iscsi_wrb
, ptr2nextwrb
, pwrb
,
4943 io_task
->pwrb_handle
->nxt_wrb_index
);
4944 be_dws_le_to_cpu(pwrb
, sizeof(struct iscsi_wrb
));
4946 doorbell
|= beiscsi_conn
->beiscsi_conn_cid
& DB_WRB_POST_CID_MASK
;
4947 doorbell
|= (io_task
->pwrb_handle
->wrb_index
&
4948 DB_DEF_PDU_WRB_INDEX_MASK
) << DB_DEF_PDU_WRB_INDEX_SHIFT
;
4949 doorbell
|= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT
;
4951 iowrite32(doorbell
, phba
->db_va
+
4952 beiscsi_conn
->doorbell_offset
);
4956 static int beiscsi_mtask(struct iscsi_task
*task
)
4958 struct beiscsi_io_task
*io_task
= task
->dd_data
;
4959 struct iscsi_conn
*conn
= task
->conn
;
4960 struct beiscsi_conn
*beiscsi_conn
= conn
->dd_data
;
4961 struct beiscsi_hba
*phba
= beiscsi_conn
->phba
;
4962 struct iscsi_wrb
*pwrb
= NULL
;
4963 unsigned int doorbell
= 0;
4965 unsigned int pwrb_typeoffset
= 0;
4967 cid
= beiscsi_conn
->beiscsi_conn_cid
;
4968 pwrb
= io_task
->pwrb_handle
->pwrb
;
4969 memset(pwrb
, 0, sizeof(*pwrb
));
4971 if (is_chip_be2_be3r(phba
)) {
4972 AMAP_SET_BITS(struct amap_iscsi_wrb
, cmdsn_itt
, pwrb
,
4973 be32_to_cpu(task
->cmdsn
));
4974 AMAP_SET_BITS(struct amap_iscsi_wrb
, wrb_idx
, pwrb
,
4975 io_task
->pwrb_handle
->wrb_index
);
4976 AMAP_SET_BITS(struct amap_iscsi_wrb
, sgl_icd_idx
, pwrb
,
4977 io_task
->psgl_handle
->sgl_index
);
4978 AMAP_SET_BITS(struct amap_iscsi_wrb
, r2t_exp_dtl
, pwrb
,
4980 AMAP_SET_BITS(struct amap_iscsi_wrb
, ptr2nextwrb
, pwrb
,
4981 io_task
->pwrb_handle
->nxt_wrb_index
);
4982 pwrb_typeoffset
= BE_WRB_TYPE_OFFSET
;
4984 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, cmdsn_itt
, pwrb
,
4985 be32_to_cpu(task
->cmdsn
));
4986 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, wrb_idx
, pwrb
,
4987 io_task
->pwrb_handle
->wrb_index
);
4988 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, sgl_idx
, pwrb
,
4989 io_task
->psgl_handle
->sgl_index
);
4990 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, r2t_exp_dtl
, pwrb
,
4992 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, ptr2nextwrb
, pwrb
,
4993 io_task
->pwrb_handle
->nxt_wrb_index
);
4994 pwrb_typeoffset
= SKH_WRB_TYPE_OFFSET
;
4998 switch (task
->hdr
->opcode
& ISCSI_OPCODE_MASK
) {
4999 case ISCSI_OP_LOGIN
:
5000 AMAP_SET_BITS(struct amap_iscsi_wrb
, cmdsn_itt
, pwrb
, 1);
5001 ADAPTER_SET_WRB_TYPE(pwrb
, TGT_DM_CMD
, pwrb_typeoffset
);
5002 hwi_write_buffer(pwrb
, task
);
5004 case ISCSI_OP_NOOP_OUT
:
5005 if (task
->hdr
->ttt
!= ISCSI_RESERVED_TAG
) {
5006 ADAPTER_SET_WRB_TYPE(pwrb
, TGT_DM_CMD
, pwrb_typeoffset
);
5007 if (is_chip_be2_be3r(phba
))
5008 AMAP_SET_BITS(struct amap_iscsi_wrb
,
5011 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
,
5014 ADAPTER_SET_WRB_TYPE(pwrb
, INI_RD_CMD
, pwrb_typeoffset
);
5015 if (is_chip_be2_be3r(phba
))
5016 AMAP_SET_BITS(struct amap_iscsi_wrb
,
5019 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
,
5022 hwi_write_buffer(pwrb
, task
);
5025 ADAPTER_SET_WRB_TYPE(pwrb
, TGT_DM_CMD
, pwrb_typeoffset
);
5026 hwi_write_buffer(pwrb
, task
);
5028 case ISCSI_OP_SCSI_TMFUNC
:
5029 ADAPTER_SET_WRB_TYPE(pwrb
, INI_TMF_CMD
, pwrb_typeoffset
);
5030 hwi_write_buffer(pwrb
, task
);
5032 case ISCSI_OP_LOGOUT
:
5033 ADAPTER_SET_WRB_TYPE(pwrb
, HWH_TYPE_LOGOUT
, pwrb_typeoffset
);
5034 hwi_write_buffer(pwrb
, task
);
5038 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_CONFIG
,
5039 "BM_%d : opcode =%d Not supported\n",
5040 task
->hdr
->opcode
& ISCSI_OPCODE_MASK
);
5045 /* Set the task type */
5046 io_task
->wrb_type
= (is_chip_be2_be3r(phba
)) ?
5047 AMAP_GET_BITS(struct amap_iscsi_wrb
, type
, pwrb
) :
5048 AMAP_GET_BITS(struct amap_iscsi_wrb_v2
, type
, pwrb
);
5050 doorbell
|= cid
& DB_WRB_POST_CID_MASK
;
5051 doorbell
|= (io_task
->pwrb_handle
->wrb_index
&
5052 DB_DEF_PDU_WRB_INDEX_MASK
) << DB_DEF_PDU_WRB_INDEX_SHIFT
;
5053 doorbell
|= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT
;
5054 iowrite32(doorbell
, phba
->db_va
+
5055 beiscsi_conn
->doorbell_offset
);
5059 static int beiscsi_task_xmit(struct iscsi_task
*task
)
5061 struct beiscsi_io_task
*io_task
= task
->dd_data
;
5062 struct scsi_cmnd
*sc
= task
->sc
;
5063 struct beiscsi_hba
*phba
= NULL
;
5064 struct scatterlist
*sg
;
5066 unsigned int writedir
= 0, xferlen
= 0;
5068 phba
= ((struct beiscsi_conn
*)task
->conn
->dd_data
)->phba
;
5071 return beiscsi_mtask(task
);
5073 io_task
->scsi_cmnd
= sc
;
5074 num_sg
= scsi_dma_map(sc
);
5076 struct iscsi_conn
*conn
= task
->conn
;
5077 struct beiscsi_hba
*phba
= NULL
;
5079 phba
= ((struct beiscsi_conn
*)conn
->dd_data
)->phba
;
5080 beiscsi_log(phba
, KERN_ERR
,
5081 BEISCSI_LOG_IO
| BEISCSI_LOG_ISCSI
,
5082 "BM_%d : scsi_dma_map Failed "
5083 "Driver_ITT : 0x%x ITT : 0x%x Xferlen : 0x%x\n",
5084 be32_to_cpu(io_task
->cmd_bhs
->iscsi_hdr
.itt
),
5085 io_task
->libiscsi_itt
, scsi_bufflen(sc
));
5089 xferlen
= scsi_bufflen(sc
);
5090 sg
= scsi_sglist(sc
);
5091 if (sc
->sc_data_direction
== DMA_TO_DEVICE
)
5096 return phba
->iotask_fn(task
, sg
, num_sg
, xferlen
, writedir
);
5100 * beiscsi_bsg_request - handle bsg request from ISCSI transport
5101 * @job: job to handle
5103 static int beiscsi_bsg_request(struct bsg_job
*job
)
5105 struct Scsi_Host
*shost
;
5106 struct beiscsi_hba
*phba
;
5107 struct iscsi_bsg_request
*bsg_req
= job
->request
;
5110 struct be_dma_mem nonemb_cmd
;
5111 struct be_cmd_resp_hdr
*resp
;
5112 struct iscsi_bsg_reply
*bsg_reply
= job
->reply
;
5113 unsigned short status
, extd_status
;
5115 shost
= iscsi_job_to_shost(job
);
5116 phba
= iscsi_host_priv(shost
);
5118 switch (bsg_req
->msgcode
) {
5119 case ISCSI_BSG_HST_VENDOR
:
5120 nonemb_cmd
.va
= pci_alloc_consistent(phba
->ctrl
.pdev
,
5121 job
->request_payload
.payload_len
,
5123 if (nonemb_cmd
.va
== NULL
) {
5124 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_CONFIG
,
5125 "BM_%d : Failed to allocate memory for "
5126 "beiscsi_bsg_request\n");
5129 tag
= mgmt_vendor_specific_fw_cmd(&phba
->ctrl
, phba
, job
,
5132 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_CONFIG
,
5133 "BM_%d : MBX Tag Allocation Failed\n");
5135 pci_free_consistent(phba
->ctrl
.pdev
, nonemb_cmd
.size
,
5136 nonemb_cmd
.va
, nonemb_cmd
.dma
);
5140 rc
= wait_event_interruptible_timeout(
5141 phba
->ctrl
.mcc_wait
[tag
],
5142 phba
->ctrl
.mcc_numtag
[tag
],
5144 BEISCSI_HOST_MBX_TIMEOUT
));
5145 extd_status
= (phba
->ctrl
.mcc_numtag
[tag
] & 0x0000FF00) >> 8;
5146 status
= phba
->ctrl
.mcc_numtag
[tag
] & 0x000000FF;
5147 free_mcc_tag(&phba
->ctrl
, tag
);
5148 resp
= (struct be_cmd_resp_hdr
*)nonemb_cmd
.va
;
5149 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
5150 job
->reply_payload
.sg_cnt
,
5151 nonemb_cmd
.va
, (resp
->response_length
5153 bsg_reply
->reply_payload_rcv_len
= resp
->response_length
;
5154 bsg_reply
->result
= status
;
5155 bsg_job_done(job
, bsg_reply
->result
,
5156 bsg_reply
->reply_payload_rcv_len
);
5157 pci_free_consistent(phba
->ctrl
.pdev
, nonemb_cmd
.size
,
5158 nonemb_cmd
.va
, nonemb_cmd
.dma
);
5159 if (status
|| extd_status
) {
5160 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_CONFIG
,
5161 "BM_%d : MBX Cmd Failed"
5162 " status = %d extd_status = %d\n",
5163 status
, extd_status
);
5172 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_CONFIG
,
5173 "BM_%d : Unsupported bsg command: 0x%x\n",
5181 void beiscsi_hba_attrs_init(struct beiscsi_hba
*phba
)
5183 /* Set the logging parameter */
5184 beiscsi_log_enable_init(phba
, beiscsi_log_enable
);
5188 * beiscsi_quiesce()- Cleanup Driver resources
5189 * @phba: Instance Priv structure
5190 * @unload_state:i Clean or EEH unload state
5192 * Free the OS and HW resources held by the driver
5194 static void beiscsi_quiesce(struct beiscsi_hba
*phba
,
5195 uint32_t unload_state
)
5197 struct hwi_controller
*phwi_ctrlr
;
5198 struct hwi_context_memory
*phwi_context
;
5199 struct be_eq_obj
*pbe_eq
;
5200 unsigned int i
, msix_vec
;
5202 phwi_ctrlr
= phba
->phwi_ctrlr
;
5203 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
5204 hwi_disable_intr(phba
);
5205 if (phba
->msix_enabled
) {
5206 for (i
= 0; i
<= phba
->num_cpus
; i
++) {
5207 msix_vec
= phba
->msix_entries
[i
].vector
;
5208 synchronize_irq(msix_vec
);
5209 free_irq(msix_vec
, &phwi_context
->be_eq
[i
]);
5210 kfree(phba
->msi_name
[i
]);
5213 if (phba
->pcidev
->irq
) {
5214 synchronize_irq(phba
->pcidev
->irq
);
5215 free_irq(phba
->pcidev
->irq
, phba
);
5217 pci_disable_msix(phba
->pcidev
);
5219 if (blk_iopoll_enabled
)
5220 for (i
= 0; i
< phba
->num_cpus
; i
++) {
5221 pbe_eq
= &phwi_context
->be_eq
[i
];
5222 blk_iopoll_disable(&pbe_eq
->iopoll
);
5225 if (unload_state
== BEISCSI_CLEAN_UNLOAD
) {
5226 destroy_workqueue(phba
->wq
);
5227 beiscsi_clean_port(phba
);
5228 beiscsi_free_mem(phba
);
5230 beiscsi_unmap_pci_function(phba
);
5231 pci_free_consistent(phba
->pcidev
,
5232 phba
->ctrl
.mbox_mem_alloced
.size
,
5233 phba
->ctrl
.mbox_mem_alloced
.va
,
5234 phba
->ctrl
.mbox_mem_alloced
.dma
);
5240 cancel_delayed_work_sync(&phba
->beiscsi_hw_check_task
);
5243 static void beiscsi_remove(struct pci_dev
*pcidev
)
5246 struct beiscsi_hba
*phba
= NULL
;
5248 phba
= pci_get_drvdata(pcidev
);
5250 dev_err(&pcidev
->dev
, "beiscsi_remove called with no phba\n");
5254 beiscsi_destroy_def_ifaces(phba
);
5255 beiscsi_quiesce(phba
, BEISCSI_CLEAN_UNLOAD
);
5256 iscsi_boot_destroy_kset(phba
->boot_kset
);
5257 iscsi_host_remove(phba
->shost
);
5258 pci_dev_put(phba
->pcidev
);
5259 iscsi_host_free(phba
->shost
);
5260 pci_disable_pcie_error_reporting(pcidev
);
5261 pci_set_drvdata(pcidev
, NULL
);
5262 pci_disable_device(pcidev
);
5265 static void beiscsi_shutdown(struct pci_dev
*pcidev
)
5268 struct beiscsi_hba
*phba
= NULL
;
5270 phba
= (struct beiscsi_hba
*)pci_get_drvdata(pcidev
);
5272 dev_err(&pcidev
->dev
, "beiscsi_shutdown called with no phba\n");
5276 beiscsi_quiesce(phba
, BEISCSI_CLEAN_UNLOAD
);
5277 pci_disable_device(pcidev
);
5280 static void beiscsi_msix_enable(struct beiscsi_hba
*phba
)
5284 for (i
= 0; i
<= phba
->num_cpus
; i
++)
5285 phba
->msix_entries
[i
].entry
= i
;
5287 status
= pci_enable_msix(phba
->pcidev
, phba
->msix_entries
,
5288 (phba
->num_cpus
+ 1));
5290 phba
->msix_enabled
= true;
5296 * beiscsi_hw_health_check()- Check adapter health
5297 * @work: work item to check HW health
5299 * Check if adapter in an unrecoverable state or not.
5302 beiscsi_hw_health_check(struct work_struct
*work
)
5304 struct beiscsi_hba
*phba
=
5305 container_of(work
, struct beiscsi_hba
,
5306 beiscsi_hw_check_task
.work
);
5308 beiscsi_ue_detect(phba
);
5310 schedule_delayed_work(&phba
->beiscsi_hw_check_task
,
5311 msecs_to_jiffies(1000));
5315 static pci_ers_result_t
beiscsi_eeh_err_detected(struct pci_dev
*pdev
,
5316 pci_channel_state_t state
)
5318 struct beiscsi_hba
*phba
= NULL
;
5320 phba
= (struct beiscsi_hba
*)pci_get_drvdata(pdev
);
5321 phba
->state
|= BE_ADAPTER_PCI_ERR
;
5323 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5324 "BM_%d : EEH error detected\n");
5326 beiscsi_quiesce(phba
, BEISCSI_EEH_UNLOAD
);
5328 if (state
== pci_channel_io_perm_failure
) {
5329 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5330 "BM_%d : EEH : State PERM Failure");
5331 return PCI_ERS_RESULT_DISCONNECT
;
5334 pci_disable_device(pdev
);
5336 /* The error could cause the FW to trigger a flash debug dump.
5337 * Resetting the card while flash dump is in progress
5338 * can cause it not to recover; wait for it to finish.
5339 * Wait only for first function as it is needed only once per
5342 if (pdev
->devfn
== 0)
5345 return PCI_ERS_RESULT_NEED_RESET
;
5348 static pci_ers_result_t
beiscsi_eeh_reset(struct pci_dev
*pdev
)
5350 struct beiscsi_hba
*phba
= NULL
;
5353 phba
= (struct beiscsi_hba
*)pci_get_drvdata(pdev
);
5355 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5356 "BM_%d : EEH Reset\n");
5358 status
= pci_enable_device(pdev
);
5360 return PCI_ERS_RESULT_DISCONNECT
;
5362 pci_set_master(pdev
);
5363 pci_set_power_state(pdev
, PCI_D0
);
5364 pci_restore_state(pdev
);
5366 /* Wait for the CHIP Reset to complete */
5367 status
= be_chk_reset_complete(phba
);
5369 beiscsi_log(phba
, KERN_WARNING
, BEISCSI_LOG_INIT
,
5370 "BM_%d : EEH Reset Completed\n");
5372 beiscsi_log(phba
, KERN_WARNING
, BEISCSI_LOG_INIT
,
5373 "BM_%d : EEH Reset Completion Failure\n");
5374 return PCI_ERS_RESULT_DISCONNECT
;
5377 pci_cleanup_aer_uncorrect_error_status(pdev
);
5378 return PCI_ERS_RESULT_RECOVERED
;
5381 static void beiscsi_eeh_resume(struct pci_dev
*pdev
)
5384 struct be_eq_obj
*pbe_eq
;
5385 struct beiscsi_hba
*phba
= NULL
;
5386 struct hwi_controller
*phwi_ctrlr
;
5387 struct hwi_context_memory
*phwi_context
;
5389 phba
= (struct beiscsi_hba
*)pci_get_drvdata(pdev
);
5390 pci_save_state(pdev
);
5393 find_num_cpus(phba
);
5398 beiscsi_msix_enable(phba
);
5399 if (!phba
->msix_enabled
)
5403 ret
= beiscsi_cmd_reset_function(phba
);
5405 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5406 "BM_%d : Reset Failed\n");
5410 ret
= be_chk_reset_complete(phba
);
5412 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5413 "BM_%d : Failed to get out of reset.\n");
5417 beiscsi_get_params(phba
);
5418 phba
->shost
->max_id
= phba
->params
.cxns_per_ctrl
;
5419 phba
->shost
->can_queue
= phba
->params
.ios_per_ctrl
;
5420 ret
= hwi_init_controller(phba
);
5422 for (i
= 0; i
< MAX_MCC_CMD
; i
++) {
5423 init_waitqueue_head(&phba
->ctrl
.mcc_wait
[i
+ 1]);
5424 phba
->ctrl
.mcc_tag
[i
] = i
+ 1;
5425 phba
->ctrl
.mcc_numtag
[i
+ 1] = 0;
5426 phba
->ctrl
.mcc_tag_available
++;
5429 phwi_ctrlr
= phba
->phwi_ctrlr
;
5430 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
5432 if (blk_iopoll_enabled
) {
5433 for (i
= 0; i
< phba
->num_cpus
; i
++) {
5434 pbe_eq
= &phwi_context
->be_eq
[i
];
5435 blk_iopoll_init(&pbe_eq
->iopoll
, be_iopoll_budget
,
5437 blk_iopoll_enable(&pbe_eq
->iopoll
);
5440 i
= (phba
->msix_enabled
) ? i
: 0;
5441 /* Work item for MCC handling */
5442 pbe_eq
= &phwi_context
->be_eq
[i
];
5443 INIT_WORK(&pbe_eq
->work_cqs
, beiscsi_process_all_cqs
);
5445 if (phba
->msix_enabled
) {
5446 for (i
= 0; i
<= phba
->num_cpus
; i
++) {
5447 pbe_eq
= &phwi_context
->be_eq
[i
];
5448 INIT_WORK(&pbe_eq
->work_cqs
,
5449 beiscsi_process_all_cqs
);
5452 pbe_eq
= &phwi_context
->be_eq
[0];
5453 INIT_WORK(&pbe_eq
->work_cqs
,
5454 beiscsi_process_all_cqs
);
5458 ret
= beiscsi_init_irqs(phba
);
5460 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5461 "BM_%d : beiscsi_eeh_resume - "
5462 "Failed to beiscsi_init_irqs\n");
5466 hwi_enable_intr(phba
);
5467 phba
->state
&= ~BE_ADAPTER_PCI_ERR
;
5471 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5472 "BM_%d : AER EEH Resume Failed\n");
5475 static int beiscsi_dev_probe(struct pci_dev
*pcidev
,
5476 const struct pci_device_id
*id
)
5478 struct beiscsi_hba
*phba
= NULL
;
5479 struct hwi_controller
*phwi_ctrlr
;
5480 struct hwi_context_memory
*phwi_context
;
5481 struct be_eq_obj
*pbe_eq
;
5484 ret
= beiscsi_enable_pci(pcidev
);
5486 dev_err(&pcidev
->dev
,
5487 "beiscsi_dev_probe - Failed to enable pci device\n");
5491 phba
= beiscsi_hba_alloc(pcidev
);
5493 dev_err(&pcidev
->dev
,
5494 "beiscsi_dev_probe - Failed in beiscsi_hba_alloc\n");
5498 /* Enable EEH reporting */
5499 ret
= pci_enable_pcie_error_reporting(pcidev
);
5501 beiscsi_log(phba
, KERN_WARNING
, BEISCSI_LOG_INIT
,
5502 "BM_%d : PCIe Error Reporting "
5503 "Enabling Failed\n");
5505 pci_save_state(pcidev
);
5507 /* Initialize Driver configuration Paramters */
5508 beiscsi_hba_attrs_init(phba
);
5510 phba
->fw_timeout
= false;
5511 phba
->mac_addr_set
= false;
5514 switch (pcidev
->device
) {
5518 phba
->generation
= BE_GEN2
;
5519 phba
->iotask_fn
= beiscsi_iotask
;
5523 phba
->generation
= BE_GEN3
;
5524 phba
->iotask_fn
= beiscsi_iotask
;
5527 phba
->generation
= BE_GEN4
;
5528 phba
->iotask_fn
= beiscsi_iotask_v2
;
5531 phba
->generation
= 0;
5534 ret
= be_ctrl_init(phba
, pcidev
);
5536 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5537 "BM_%d : beiscsi_dev_probe-"
5538 "Failed in be_ctrl_init\n");
5542 ret
= beiscsi_cmd_reset_function(phba
);
5544 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5545 "BM_%d : Reset Failed\n");
5548 ret
= be_chk_reset_complete(phba
);
5550 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5551 "BM_%d : Failed to get out of reset.\n");
5555 spin_lock_init(&phba
->io_sgl_lock
);
5556 spin_lock_init(&phba
->mgmt_sgl_lock
);
5557 spin_lock_init(&phba
->isr_lock
);
5558 spin_lock_init(&phba
->async_pdu_lock
);
5559 ret
= mgmt_get_fw_config(&phba
->ctrl
, phba
);
5561 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5562 "BM_%d : Error getting fw config\n");
5567 find_num_cpus(phba
);
5571 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
5572 "BM_%d : num_cpus = %d\n",
5576 beiscsi_msix_enable(phba
);
5577 if (!phba
->msix_enabled
)
5581 phba
->shost
->max_id
= phba
->params
.cxns_per_ctrl
;
5582 beiscsi_get_params(phba
);
5583 phba
->shost
->can_queue
= phba
->params
.ios_per_ctrl
;
5584 ret
= beiscsi_init_port(phba
);
5586 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5587 "BM_%d : beiscsi_dev_probe-"
5588 "Failed in beiscsi_init_port\n");
5592 for (i
= 0; i
< MAX_MCC_CMD
; i
++) {
5593 init_waitqueue_head(&phba
->ctrl
.mcc_wait
[i
+ 1]);
5594 phba
->ctrl
.mcc_tag
[i
] = i
+ 1;
5595 phba
->ctrl
.mcc_numtag
[i
+ 1] = 0;
5596 phba
->ctrl
.mcc_tag_available
++;
5599 phba
->ctrl
.mcc_alloc_index
= phba
->ctrl
.mcc_free_index
= 0;
5601 snprintf(phba
->wq_name
, sizeof(phba
->wq_name
), "beiscsi_%02x_wq",
5602 phba
->shost
->host_no
);
5603 phba
->wq
= alloc_workqueue("%s", WQ_MEM_RECLAIM
, 1, phba
->wq_name
);
5605 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5606 "BM_%d : beiscsi_dev_probe-"
5607 "Failed to allocate work queue\n");
5611 INIT_DELAYED_WORK(&phba
->beiscsi_hw_check_task
,
5612 beiscsi_hw_health_check
);
5614 phwi_ctrlr
= phba
->phwi_ctrlr
;
5615 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
5617 if (blk_iopoll_enabled
) {
5618 for (i
= 0; i
< phba
->num_cpus
; i
++) {
5619 pbe_eq
= &phwi_context
->be_eq
[i
];
5620 blk_iopoll_init(&pbe_eq
->iopoll
, be_iopoll_budget
,
5622 blk_iopoll_enable(&pbe_eq
->iopoll
);
5625 i
= (phba
->msix_enabled
) ? i
: 0;
5626 /* Work item for MCC handling */
5627 pbe_eq
= &phwi_context
->be_eq
[i
];
5628 INIT_WORK(&pbe_eq
->work_cqs
, beiscsi_process_all_cqs
);
5630 if (phba
->msix_enabled
) {
5631 for (i
= 0; i
<= phba
->num_cpus
; i
++) {
5632 pbe_eq
= &phwi_context
->be_eq
[i
];
5633 INIT_WORK(&pbe_eq
->work_cqs
,
5634 beiscsi_process_all_cqs
);
5637 pbe_eq
= &phwi_context
->be_eq
[0];
5638 INIT_WORK(&pbe_eq
->work_cqs
,
5639 beiscsi_process_all_cqs
);
5643 ret
= beiscsi_init_irqs(phba
);
5645 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5646 "BM_%d : beiscsi_dev_probe-"
5647 "Failed to beiscsi_init_irqs\n");
5650 hwi_enable_intr(phba
);
5652 if (beiscsi_setup_boot_info(phba
))
5654 * log error but continue, because we may not be using
5657 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5658 "BM_%d : Could not set up "
5659 "iSCSI boot info.\n");
5661 beiscsi_create_def_ifaces(phba
);
5662 schedule_delayed_work(&phba
->beiscsi_hw_check_task
,
5663 msecs_to_jiffies(1000));
5665 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
5666 "\n\n\n BM_%d : SUCCESS - DRIVER LOADED\n\n\n");
5670 destroy_workqueue(phba
->wq
);
5671 if (blk_iopoll_enabled
)
5672 for (i
= 0; i
< phba
->num_cpus
; i
++) {
5673 pbe_eq
= &phwi_context
->be_eq
[i
];
5674 blk_iopoll_disable(&pbe_eq
->iopoll
);
5677 beiscsi_clean_port(phba
);
5678 beiscsi_free_mem(phba
);
5680 pci_free_consistent(phba
->pcidev
,
5681 phba
->ctrl
.mbox_mem_alloced
.size
,
5682 phba
->ctrl
.mbox_mem_alloced
.va
,
5683 phba
->ctrl
.mbox_mem_alloced
.dma
);
5684 beiscsi_unmap_pci_function(phba
);
5686 if (phba
->msix_enabled
)
5687 pci_disable_msix(phba
->pcidev
);
5688 iscsi_host_remove(phba
->shost
);
5689 pci_dev_put(phba
->pcidev
);
5690 iscsi_host_free(phba
->shost
);
5692 pci_disable_device(pcidev
);
5696 static struct pci_error_handlers beiscsi_eeh_handlers
= {
5697 .error_detected
= beiscsi_eeh_err_detected
,
5698 .slot_reset
= beiscsi_eeh_reset
,
5699 .resume
= beiscsi_eeh_resume
,
5702 struct iscsi_transport beiscsi_iscsi_transport
= {
5703 .owner
= THIS_MODULE
,
5705 .caps
= CAP_RECOVERY_L0
| CAP_HDRDGST
| CAP_TEXT_NEGO
|
5706 CAP_MULTI_R2T
| CAP_DATADGST
| CAP_DATA_PATH_OFFLOAD
,
5707 .create_session
= beiscsi_session_create
,
5708 .destroy_session
= beiscsi_session_destroy
,
5709 .create_conn
= beiscsi_conn_create
,
5710 .bind_conn
= beiscsi_conn_bind
,
5711 .destroy_conn
= iscsi_conn_teardown
,
5712 .attr_is_visible
= be2iscsi_attr_is_visible
,
5713 .set_iface_param
= be2iscsi_iface_set_param
,
5714 .get_iface_param
= be2iscsi_iface_get_param
,
5715 .set_param
= beiscsi_set_param
,
5716 .get_conn_param
= iscsi_conn_get_param
,
5717 .get_session_param
= iscsi_session_get_param
,
5718 .get_host_param
= beiscsi_get_host_param
,
5719 .start_conn
= beiscsi_conn_start
,
5720 .stop_conn
= iscsi_conn_stop
,
5721 .send_pdu
= iscsi_conn_send_pdu
,
5722 .xmit_task
= beiscsi_task_xmit
,
5723 .cleanup_task
= beiscsi_cleanup_task
,
5724 .alloc_pdu
= beiscsi_alloc_pdu
,
5725 .parse_pdu_itt
= beiscsi_parse_pdu
,
5726 .get_stats
= beiscsi_conn_get_stats
,
5727 .get_ep_param
= beiscsi_ep_get_param
,
5728 .ep_connect
= beiscsi_ep_connect
,
5729 .ep_poll
= beiscsi_ep_poll
,
5730 .ep_disconnect
= beiscsi_ep_disconnect
,
5731 .session_recovery_timedout
= iscsi_session_recovery_timedout
,
5732 .bsg_request
= beiscsi_bsg_request
,
5735 static struct pci_driver beiscsi_pci_driver
= {
5737 .probe
= beiscsi_dev_probe
,
5738 .remove
= beiscsi_remove
,
5739 .shutdown
= beiscsi_shutdown
,
5740 .id_table
= beiscsi_pci_id_table
,
5741 .err_handler
= &beiscsi_eeh_handlers
5745 static int __init
beiscsi_module_init(void)
5749 beiscsi_scsi_transport
=
5750 iscsi_register_transport(&beiscsi_iscsi_transport
);
5751 if (!beiscsi_scsi_transport
) {
5753 "beiscsi_module_init - Unable to register beiscsi transport.\n");
5756 printk(KERN_INFO
"In beiscsi_module_init, tt=%p\n",
5757 &beiscsi_iscsi_transport
);
5759 ret
= pci_register_driver(&beiscsi_pci_driver
);
5762 "beiscsi_module_init - Unable to register beiscsi pci driver.\n");
5763 goto unregister_iscsi_transport
;
5767 unregister_iscsi_transport
:
5768 iscsi_unregister_transport(&beiscsi_iscsi_transport
);
5772 static void __exit
beiscsi_module_exit(void)
5774 pci_unregister_driver(&beiscsi_pci_driver
);
5775 iscsi_unregister_transport(&beiscsi_iscsi_transport
);
5778 module_init(beiscsi_module_init
);
5779 module_exit(beiscsi_module_exit
);