2 * Copyright (C) 2005 - 2014 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_DESCRIPTION(DRV_DESC
" " BUILD_STR
);
52 MODULE_VERSION(BUILD_STR
);
53 MODULE_AUTHOR("Emulex Corporation");
54 MODULE_LICENSE("GPL");
55 module_param(be_iopoll_budget
, int, 0);
56 module_param(enable_msix
, int, 0);
57 module_param(be_max_phys_size
, uint
, S_IRUGO
);
58 MODULE_PARM_DESC(be_max_phys_size
,
59 "Maximum Size (In Kilobytes) of physically contiguous "
60 "memory that can be allocated. Range is 16 - 128");
62 #define beiscsi_disp_param(_name)\
64 beiscsi_##_name##_disp(struct device *dev,\
65 struct device_attribute *attrib, char *buf) \
67 struct Scsi_Host *shost = class_to_shost(dev);\
68 struct beiscsi_hba *phba = iscsi_host_priv(shost); \
69 uint32_t param_val = 0; \
70 param_val = phba->attr_##_name;\
71 return snprintf(buf, PAGE_SIZE, "%d\n",\
75 #define beiscsi_change_param(_name, _minval, _maxval, _defaval)\
77 beiscsi_##_name##_change(struct beiscsi_hba *phba, uint32_t val)\
79 if (val >= _minval && val <= _maxval) {\
80 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,\
81 "BA_%d : beiscsi_"#_name" updated "\
82 "from 0x%x ==> 0x%x\n",\
83 phba->attr_##_name, val); \
84 phba->attr_##_name = val;\
87 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, \
88 "BA_%d beiscsi_"#_name" attribute "\
89 "cannot be updated to 0x%x, "\
90 "range allowed is ["#_minval" - "#_maxval"]\n", val);\
94 #define beiscsi_store_param(_name) \
96 beiscsi_##_name##_store(struct device *dev,\
97 struct device_attribute *attr, const char *buf,\
100 struct Scsi_Host *shost = class_to_shost(dev);\
101 struct beiscsi_hba *phba = iscsi_host_priv(shost);\
102 uint32_t param_val = 0;\
103 if (!isdigit(buf[0]))\
105 if (sscanf(buf, "%i", ¶m_val) != 1)\
107 if (beiscsi_##_name##_change(phba, param_val) == 0) \
113 #define beiscsi_init_param(_name, _minval, _maxval, _defval) \
115 beiscsi_##_name##_init(struct beiscsi_hba *phba, uint32_t val) \
117 if (val >= _minval && val <= _maxval) {\
118 phba->attr_##_name = val;\
121 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,\
122 "BA_%d beiscsi_"#_name" attribute " \
123 "cannot be updated to 0x%x, "\
124 "range allowed is ["#_minval" - "#_maxval"]\n", val);\
125 phba->attr_##_name = _defval;\
129 #define BEISCSI_RW_ATTR(_name, _minval, _maxval, _defval, _descp) \
130 static uint beiscsi_##_name = _defval;\
131 module_param(beiscsi_##_name, uint, S_IRUGO);\
132 MODULE_PARM_DESC(beiscsi_##_name, _descp);\
133 beiscsi_disp_param(_name)\
134 beiscsi_change_param(_name, _minval, _maxval, _defval)\
135 beiscsi_store_param(_name)\
136 beiscsi_init_param(_name, _minval, _maxval, _defval)\
137 DEVICE_ATTR(beiscsi_##_name, S_IRUGO | S_IWUSR,\
138 beiscsi_##_name##_disp, beiscsi_##_name##_store)
141 * When new log level added update the
142 * the MAX allowed value for log_enable
144 BEISCSI_RW_ATTR(log_enable
, 0x00,
145 0xFF, 0x00, "Enable logging Bit Mask\n"
146 "\t\t\t\tInitialization Events : 0x01\n"
147 "\t\t\t\tMailbox Events : 0x02\n"
148 "\t\t\t\tMiscellaneous Events : 0x04\n"
149 "\t\t\t\tError Handling : 0x08\n"
150 "\t\t\t\tIO Path Events : 0x10\n"
151 "\t\t\t\tConfiguration Path : 0x20\n"
152 "\t\t\t\tiSCSI Protocol : 0x40\n");
154 DEVICE_ATTR(beiscsi_drvr_ver
, S_IRUGO
, beiscsi_drvr_ver_disp
, NULL
);
155 DEVICE_ATTR(beiscsi_adapter_family
, S_IRUGO
, beiscsi_adap_family_disp
, NULL
);
156 DEVICE_ATTR(beiscsi_fw_ver
, S_IRUGO
, beiscsi_fw_ver_disp
, NULL
);
157 DEVICE_ATTR(beiscsi_phys_port
, S_IRUGO
, beiscsi_phys_port_disp
, NULL
);
158 DEVICE_ATTR(beiscsi_active_session_count
, S_IRUGO
,
159 beiscsi_active_session_disp
, NULL
);
160 DEVICE_ATTR(beiscsi_free_session_count
, S_IRUGO
,
161 beiscsi_free_session_disp
, NULL
);
162 struct device_attribute
*beiscsi_attrs
[] = {
163 &dev_attr_beiscsi_log_enable
,
164 &dev_attr_beiscsi_drvr_ver
,
165 &dev_attr_beiscsi_adapter_family
,
166 &dev_attr_beiscsi_fw_ver
,
167 &dev_attr_beiscsi_active_session_count
,
168 &dev_attr_beiscsi_free_session_count
,
169 &dev_attr_beiscsi_phys_port
,
173 static char const *cqe_desc
[] = {
176 "SOL_CMD_KILLED_DATA_DIGEST_ERR",
177 "CXN_KILLED_PDU_SIZE_EXCEEDS_DSL",
178 "CXN_KILLED_BURST_LEN_MISMATCH",
179 "CXN_KILLED_AHS_RCVD",
180 "CXN_KILLED_HDR_DIGEST_ERR",
181 "CXN_KILLED_UNKNOWN_HDR",
182 "CXN_KILLED_STALE_ITT_TTT_RCVD",
183 "CXN_KILLED_INVALID_ITT_TTT_RCVD",
184 "CXN_KILLED_RST_RCVD",
185 "CXN_KILLED_TIMED_OUT",
186 "CXN_KILLED_RST_SENT",
187 "CXN_KILLED_FIN_RCVD",
188 "CXN_KILLED_BAD_UNSOL_PDU_RCVD",
189 "CXN_KILLED_BAD_WRB_INDEX_ERROR",
190 "CXN_KILLED_OVER_RUN_RESIDUAL",
191 "CXN_KILLED_UNDER_RUN_RESIDUAL",
192 "CMD_KILLED_INVALID_STATSN_RCVD",
193 "CMD_KILLED_INVALID_R2T_RCVD",
194 "CMD_CXN_KILLED_LUN_INVALID",
195 "CMD_CXN_KILLED_ICD_INVALID",
196 "CMD_CXN_KILLED_ITT_INVALID",
197 "CMD_CXN_KILLED_SEQ_OUTOFORDER",
198 "CMD_CXN_KILLED_INVALID_DATASN_RCVD",
199 "CXN_INVALIDATE_NOTIFY",
200 "CXN_INVALIDATE_INDEX_NOTIFY",
201 "CMD_INVALIDATED_NOTIFY",
204 "UNSOL_DATA_DIGEST_ERROR_NOTIFY",
206 "CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN",
207 "SOL_CMD_KILLED_DIF_ERR",
208 "CXN_KILLED_SYN_RCVD",
209 "CXN_KILLED_IMM_DATA_RCVD"
212 static int beiscsi_slave_configure(struct scsi_device
*sdev
)
214 blk_queue_max_segment_size(sdev
->request_queue
, 65536);
218 static int beiscsi_eh_abort(struct scsi_cmnd
*sc
)
220 struct iscsi_cls_session
*cls_session
;
221 struct iscsi_task
*aborted_task
= (struct iscsi_task
*)sc
->SCp
.ptr
;
222 struct beiscsi_io_task
*aborted_io_task
;
223 struct iscsi_conn
*conn
;
224 struct beiscsi_conn
*beiscsi_conn
;
225 struct beiscsi_hba
*phba
;
226 struct iscsi_session
*session
;
227 struct invalidate_command_table
*inv_tbl
;
228 struct be_dma_mem nonemb_cmd
;
229 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
->frwd_lock
);
236 if (!aborted_task
|| !aborted_task
->sc
) {
238 spin_unlock_bh(&session
->frwd_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
->frwd_lock
);
248 spin_unlock_bh(&session
->frwd_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 rc
= beiscsi_mccq_compl(phba
, tag
, NULL
, &nonemb_cmd
);
290 pci_free_consistent(phba
->ctrl
.pdev
, nonemb_cmd
.size
,
291 nonemb_cmd
.va
, nonemb_cmd
.dma
);
293 return iscsi_eh_abort(sc
);
296 static int beiscsi_eh_device_reset(struct scsi_cmnd
*sc
)
298 struct iscsi_task
*abrt_task
;
299 struct beiscsi_io_task
*abrt_io_task
;
300 struct iscsi_conn
*conn
;
301 struct beiscsi_conn
*beiscsi_conn
;
302 struct beiscsi_hba
*phba
;
303 struct iscsi_session
*session
;
304 struct iscsi_cls_session
*cls_session
;
305 struct invalidate_command_table
*inv_tbl
;
306 struct be_dma_mem nonemb_cmd
;
307 unsigned int cid
, tag
, i
, num_invalidate
;
310 /* invalidate iocbs */
311 cls_session
= starget_to_session(scsi_target(sc
->device
));
312 session
= cls_session
->dd_data
;
313 spin_lock_bh(&session
->frwd_lock
);
314 if (!session
->leadconn
|| session
->state
!= ISCSI_STATE_LOGGED_IN
) {
315 spin_unlock_bh(&session
->frwd_lock
);
318 conn
= session
->leadconn
;
319 beiscsi_conn
= conn
->dd_data
;
320 phba
= beiscsi_conn
->phba
;
321 cid
= beiscsi_conn
->beiscsi_conn_cid
;
322 inv_tbl
= phba
->inv_tbl
;
323 memset(inv_tbl
, 0x0, sizeof(*inv_tbl
) * BE2_CMDS_PER_CXN
);
325 for (i
= 0; i
< conn
->session
->cmds_max
; i
++) {
326 abrt_task
= conn
->session
->cmds
[i
];
327 abrt_io_task
= abrt_task
->dd_data
;
328 if (!abrt_task
->sc
|| abrt_task
->state
== ISCSI_TASK_FREE
)
331 if (sc
->device
->lun
!= abrt_task
->sc
->device
->lun
)
334 /* Invalidate WRB Posted for this Task */
335 AMAP_SET_BITS(struct amap_iscsi_wrb
, invld
,
336 abrt_io_task
->pwrb_handle
->pwrb
,
340 inv_tbl
->icd
= abrt_io_task
->psgl_handle
->sgl_index
;
344 spin_unlock_bh(&session
->frwd_lock
);
345 inv_tbl
= phba
->inv_tbl
;
347 nonemb_cmd
.va
= pci_alloc_consistent(phba
->ctrl
.pdev
,
348 sizeof(struct invalidate_commands_params_in
),
350 if (nonemb_cmd
.va
== NULL
) {
351 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_EH
,
352 "BM_%d : Failed to allocate memory for"
353 "mgmt_invalidate_icds\n");
356 nonemb_cmd
.size
= sizeof(struct invalidate_commands_params_in
);
357 memset(nonemb_cmd
.va
, 0, nonemb_cmd
.size
);
358 tag
= mgmt_invalidate_icds(phba
, inv_tbl
, num_invalidate
,
361 beiscsi_log(phba
, KERN_WARNING
, BEISCSI_LOG_EH
,
362 "BM_%d : mgmt_invalidate_icds could not be"
364 pci_free_consistent(phba
->ctrl
.pdev
, nonemb_cmd
.size
,
365 nonemb_cmd
.va
, nonemb_cmd
.dma
);
369 rc
= beiscsi_mccq_compl(phba
, tag
, NULL
, &nonemb_cmd
);
371 pci_free_consistent(phba
->ctrl
.pdev
, nonemb_cmd
.size
,
372 nonemb_cmd
.va
, nonemb_cmd
.dma
);
373 return iscsi_eh_device_reset(sc
);
376 static ssize_t
beiscsi_show_boot_tgt_info(void *data
, int type
, char *buf
)
378 struct beiscsi_hba
*phba
= data
;
379 struct mgmt_session_info
*boot_sess
= &phba
->boot_sess
;
380 struct mgmt_conn_info
*boot_conn
= &boot_sess
->conn_list
[0];
385 case ISCSI_BOOT_TGT_NAME
:
386 rc
= sprintf(buf
, "%.*s\n",
387 (int)strlen(boot_sess
->target_name
),
388 (char *)&boot_sess
->target_name
);
390 case ISCSI_BOOT_TGT_IP_ADDR
:
391 if (boot_conn
->dest_ipaddr
.ip_type
== 0x1)
392 rc
= sprintf(buf
, "%pI4\n",
393 (char *)&boot_conn
->dest_ipaddr
.addr
);
395 rc
= sprintf(str
, "%pI6\n",
396 (char *)&boot_conn
->dest_ipaddr
.addr
);
398 case ISCSI_BOOT_TGT_PORT
:
399 rc
= sprintf(str
, "%d\n", boot_conn
->dest_port
);
402 case ISCSI_BOOT_TGT_CHAP_NAME
:
403 rc
= sprintf(str
, "%.*s\n",
404 boot_conn
->negotiated_login_options
.auth_data
.chap
.
405 target_chap_name_length
,
406 (char *)&boot_conn
->negotiated_login_options
.
407 auth_data
.chap
.target_chap_name
);
409 case ISCSI_BOOT_TGT_CHAP_SECRET
:
410 rc
= sprintf(str
, "%.*s\n",
411 boot_conn
->negotiated_login_options
.auth_data
.chap
.
412 target_secret_length
,
413 (char *)&boot_conn
->negotiated_login_options
.
414 auth_data
.chap
.target_secret
);
416 case ISCSI_BOOT_TGT_REV_CHAP_NAME
:
417 rc
= sprintf(str
, "%.*s\n",
418 boot_conn
->negotiated_login_options
.auth_data
.chap
.
419 intr_chap_name_length
,
420 (char *)&boot_conn
->negotiated_login_options
.
421 auth_data
.chap
.intr_chap_name
);
423 case ISCSI_BOOT_TGT_REV_CHAP_SECRET
:
424 rc
= sprintf(str
, "%.*s\n",
425 boot_conn
->negotiated_login_options
.auth_data
.chap
.
427 (char *)&boot_conn
->negotiated_login_options
.
428 auth_data
.chap
.intr_secret
);
430 case ISCSI_BOOT_TGT_FLAGS
:
431 rc
= sprintf(str
, "2\n");
433 case ISCSI_BOOT_TGT_NIC_ASSOC
:
434 rc
= sprintf(str
, "0\n");
443 static ssize_t
beiscsi_show_boot_ini_info(void *data
, int type
, char *buf
)
445 struct beiscsi_hba
*phba
= data
;
450 case ISCSI_BOOT_INI_INITIATOR_NAME
:
451 rc
= sprintf(str
, "%s\n", phba
->boot_sess
.initiator_iscsiname
);
460 static ssize_t
beiscsi_show_boot_eth_info(void *data
, int type
, char *buf
)
462 struct beiscsi_hba
*phba
= data
;
467 case ISCSI_BOOT_ETH_FLAGS
:
468 rc
= sprintf(str
, "2\n");
470 case ISCSI_BOOT_ETH_INDEX
:
471 rc
= sprintf(str
, "0\n");
473 case ISCSI_BOOT_ETH_MAC
:
474 rc
= beiscsi_get_macaddr(str
, phba
);
484 static umode_t
beiscsi_tgt_get_attr_visibility(void *data
, int type
)
489 case ISCSI_BOOT_TGT_NAME
:
490 case ISCSI_BOOT_TGT_IP_ADDR
:
491 case ISCSI_BOOT_TGT_PORT
:
492 case ISCSI_BOOT_TGT_CHAP_NAME
:
493 case ISCSI_BOOT_TGT_CHAP_SECRET
:
494 case ISCSI_BOOT_TGT_REV_CHAP_NAME
:
495 case ISCSI_BOOT_TGT_REV_CHAP_SECRET
:
496 case ISCSI_BOOT_TGT_NIC_ASSOC
:
497 case ISCSI_BOOT_TGT_FLAGS
:
507 static umode_t
beiscsi_ini_get_attr_visibility(void *data
, int type
)
512 case ISCSI_BOOT_INI_INITIATOR_NAME
:
523 static umode_t
beiscsi_eth_get_attr_visibility(void *data
, int type
)
528 case ISCSI_BOOT_ETH_FLAGS
:
529 case ISCSI_BOOT_ETH_MAC
:
530 case ISCSI_BOOT_ETH_INDEX
:
540 /*------------------- PCI Driver operations and data ----------------- */
541 static const struct pci_device_id beiscsi_pci_id_table
[] = {
542 { PCI_DEVICE(BE_VENDOR_ID
, BE_DEVICE_ID1
) },
543 { PCI_DEVICE(BE_VENDOR_ID
, BE_DEVICE_ID2
) },
544 { PCI_DEVICE(BE_VENDOR_ID
, OC_DEVICE_ID1
) },
545 { PCI_DEVICE(BE_VENDOR_ID
, OC_DEVICE_ID2
) },
546 { PCI_DEVICE(BE_VENDOR_ID
, OC_DEVICE_ID3
) },
547 { PCI_DEVICE(ELX_VENDOR_ID
, OC_SKH_ID1
) },
550 MODULE_DEVICE_TABLE(pci
, beiscsi_pci_id_table
);
553 static struct scsi_host_template beiscsi_sht
= {
554 .module
= THIS_MODULE
,
555 .name
= "Emulex 10Gbe open-iscsi Initiator Driver",
556 .proc_name
= DRV_NAME
,
557 .queuecommand
= iscsi_queuecommand
,
558 .change_queue_depth
= scsi_change_queue_depth
,
559 .slave_configure
= beiscsi_slave_configure
,
560 .target_alloc
= iscsi_target_alloc
,
561 .eh_abort_handler
= beiscsi_eh_abort
,
562 .eh_device_reset_handler
= beiscsi_eh_device_reset
,
563 .eh_target_reset_handler
= iscsi_eh_session_reset
,
564 .shost_attrs
= beiscsi_attrs
,
565 .sg_tablesize
= BEISCSI_SGLIST_ELEMENTS
,
566 .can_queue
= BE2_IO_DEPTH
,
568 .max_sectors
= BEISCSI_MAX_SECTORS
,
569 .cmd_per_lun
= BEISCSI_CMD_PER_LUN
,
570 .use_clustering
= ENABLE_CLUSTERING
,
571 .vendor_id
= SCSI_NL_VID_TYPE_PCI
| BE_VENDOR_ID
,
572 .track_queue_depth
= 1,
575 static struct scsi_transport_template
*beiscsi_scsi_transport
;
577 static struct beiscsi_hba
*beiscsi_hba_alloc(struct pci_dev
*pcidev
)
579 struct beiscsi_hba
*phba
;
580 struct Scsi_Host
*shost
;
582 shost
= iscsi_host_alloc(&beiscsi_sht
, sizeof(*phba
), 0);
584 dev_err(&pcidev
->dev
,
585 "beiscsi_hba_alloc - iscsi_host_alloc failed\n");
588 shost
->dma_boundary
= pcidev
->dma_mask
;
589 shost
->max_id
= BE2_MAX_SESSIONS
;
590 shost
->max_channel
= 0;
591 shost
->max_cmd_len
= BEISCSI_MAX_CMD_LEN
;
592 shost
->max_lun
= BEISCSI_NUM_MAX_LUN
;
593 shost
->transportt
= beiscsi_scsi_transport
;
594 phba
= iscsi_host_priv(shost
);
595 memset(phba
, 0, sizeof(*phba
));
597 phba
->pcidev
= pci_dev_get(pcidev
);
598 pci_set_drvdata(pcidev
, phba
);
599 phba
->interface_handle
= 0xFFFFFFFF;
604 static void beiscsi_unmap_pci_function(struct beiscsi_hba
*phba
)
607 iounmap(phba
->csr_va
);
611 iounmap(phba
->db_va
);
615 iounmap(phba
->pci_va
);
620 static int beiscsi_map_pci_bars(struct beiscsi_hba
*phba
,
621 struct pci_dev
*pcidev
)
626 addr
= ioremap_nocache(pci_resource_start(pcidev
, 2),
627 pci_resource_len(pcidev
, 2));
630 phba
->ctrl
.csr
= addr
;
632 phba
->csr_pa
.u
.a64
.address
= pci_resource_start(pcidev
, 2);
634 addr
= ioremap_nocache(pci_resource_start(pcidev
, 4), 128 * 1024);
637 phba
->ctrl
.db
= addr
;
639 phba
->db_pa
.u
.a64
.address
= pci_resource_start(pcidev
, 4);
641 if (phba
->generation
== BE_GEN2
)
646 addr
= ioremap_nocache(pci_resource_start(pcidev
, pcicfg_reg
),
647 pci_resource_len(pcidev
, pcicfg_reg
));
651 phba
->ctrl
.pcicfg
= addr
;
653 phba
->pci_pa
.u
.a64
.address
= pci_resource_start(pcidev
, pcicfg_reg
);
657 beiscsi_unmap_pci_function(phba
);
661 static int beiscsi_enable_pci(struct pci_dev
*pcidev
)
665 ret
= pci_enable_device(pcidev
);
667 dev_err(&pcidev
->dev
,
668 "beiscsi_enable_pci - enable device failed\n");
672 pci_set_master(pcidev
);
673 ret
= pci_set_dma_mask(pcidev
, DMA_BIT_MASK(64));
675 ret
= pci_set_dma_mask(pcidev
, DMA_BIT_MASK(32));
677 dev_err(&pcidev
->dev
, "Could not set PCI DMA Mask\n");
678 pci_disable_device(pcidev
);
681 ret
= pci_set_consistent_dma_mask(pcidev
,
685 ret
= pci_set_consistent_dma_mask(pcidev
, DMA_BIT_MASK(64));
687 dev_err(&pcidev
->dev
, "Could not set PCI DMA Mask\n");
688 pci_disable_device(pcidev
);
695 static int be_ctrl_init(struct beiscsi_hba
*phba
, struct pci_dev
*pdev
)
697 struct be_ctrl_info
*ctrl
= &phba
->ctrl
;
698 struct be_dma_mem
*mbox_mem_alloc
= &ctrl
->mbox_mem_alloced
;
699 struct be_dma_mem
*mbox_mem_align
= &ctrl
->mbox_mem
;
703 status
= beiscsi_map_pci_bars(phba
, pdev
);
706 mbox_mem_alloc
->size
= sizeof(struct be_mcc_mailbox
) + 16;
707 mbox_mem_alloc
->va
= pci_alloc_consistent(pdev
,
708 mbox_mem_alloc
->size
,
709 &mbox_mem_alloc
->dma
);
710 if (!mbox_mem_alloc
->va
) {
711 beiscsi_unmap_pci_function(phba
);
715 mbox_mem_align
->size
= sizeof(struct be_mcc_mailbox
);
716 mbox_mem_align
->va
= PTR_ALIGN(mbox_mem_alloc
->va
, 16);
717 mbox_mem_align
->dma
= PTR_ALIGN(mbox_mem_alloc
->dma
, 16);
718 memset(mbox_mem_align
->va
, 0, sizeof(struct be_mcc_mailbox
));
719 spin_lock_init(&ctrl
->mbox_lock
);
720 spin_lock_init(&phba
->ctrl
.mcc_lock
);
721 spin_lock_init(&phba
->ctrl
.mcc_cq_lock
);
727 * beiscsi_get_params()- Set the config paramters
728 * @phba: ptr device priv structure
730 static void beiscsi_get_params(struct beiscsi_hba
*phba
)
732 uint32_t total_cid_count
= 0;
733 uint32_t total_icd_count
= 0;
736 total_cid_count
= BEISCSI_GET_CID_COUNT(phba
, BEISCSI_ULP0
) +
737 BEISCSI_GET_CID_COUNT(phba
, BEISCSI_ULP1
);
739 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++) {
740 uint32_t align_mask
= 0;
741 uint32_t icd_post_per_page
= 0;
742 uint32_t icd_count_unavailable
= 0;
743 uint32_t icd_start
= 0, icd_count
= 0;
744 uint32_t icd_start_align
= 0, icd_count_align
= 0;
746 if (test_bit(ulp_num
, &phba
->fw_config
.ulp_supported
)) {
747 icd_start
= phba
->fw_config
.iscsi_icd_start
[ulp_num
];
748 icd_count
= phba
->fw_config
.iscsi_icd_count
[ulp_num
];
750 /* Get ICD count that can be posted on each page */
751 icd_post_per_page
= (PAGE_SIZE
/ (BE2_SGE
*
752 sizeof(struct iscsi_sge
)));
753 align_mask
= (icd_post_per_page
- 1);
755 /* Check if icd_start is aligned ICD per page posting */
756 if (icd_start
% icd_post_per_page
) {
757 icd_start_align
= ((icd_start
+
761 iscsi_icd_start
[ulp_num
] =
765 icd_count_align
= (icd_count
& ~align_mask
);
767 /* ICD discarded in the process of alignment */
769 icd_count_unavailable
= ((icd_start_align
-
774 /* Updated ICD count available */
775 phba
->fw_config
.iscsi_icd_count
[ulp_num
] = (icd_count
-
776 icd_count_unavailable
);
778 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
779 "BM_%d : Aligned ICD values\n"
780 "\t ICD Start : %d\n"
781 "\t ICD Count : %d\n"
782 "\t ICD Discarded : %d\n",
784 iscsi_icd_start
[ulp_num
],
786 iscsi_icd_count
[ulp_num
],
787 icd_count_unavailable
);
792 total_icd_count
= phba
->fw_config
.iscsi_icd_count
[ulp_num
];
793 phba
->params
.ios_per_ctrl
= (total_icd_count
-
795 BE2_TMFS
+ BE2_NOPOUT_REQ
));
796 phba
->params
.cxns_per_ctrl
= total_cid_count
;
797 phba
->params
.asyncpdus_per_ctrl
= total_cid_count
;
798 phba
->params
.icds_per_ctrl
= total_icd_count
;
799 phba
->params
.num_sge_per_io
= BE2_SGE
;
800 phba
->params
.defpdu_hdr_sz
= BE2_DEFPDU_HDR_SZ
;
801 phba
->params
.defpdu_data_sz
= BE2_DEFPDU_DATA_SZ
;
802 phba
->params
.eq_timer
= 64;
803 phba
->params
.num_eq_entries
= 1024;
804 phba
->params
.num_cq_entries
= 1024;
805 phba
->params
.wrbs_per_cxn
= 256;
808 static void hwi_ring_eq_db(struct beiscsi_hba
*phba
,
809 unsigned int id
, unsigned int clr_interrupt
,
810 unsigned int num_processed
,
811 unsigned char rearm
, unsigned char event
)
816 val
|= 1 << DB_EQ_REARM_SHIFT
;
818 val
|= 1 << DB_EQ_CLR_SHIFT
;
820 val
|= 1 << DB_EQ_EVNT_SHIFT
;
822 val
|= num_processed
<< DB_EQ_NUM_POPPED_SHIFT
;
823 /* Setting lower order EQ_ID Bits */
824 val
|= (id
& DB_EQ_RING_ID_LOW_MASK
);
826 /* Setting Higher order EQ_ID Bits */
827 val
|= (((id
>> DB_EQ_HIGH_FEILD_SHIFT
) &
828 DB_EQ_RING_ID_HIGH_MASK
)
829 << DB_EQ_HIGH_SET_SHIFT
);
831 iowrite32(val
, phba
->db_va
+ DB_EQ_OFFSET
);
835 * be_isr_mcc - The isr routine of the driver.
837 * @dev_id: Pointer to host adapter structure
839 static irqreturn_t
be_isr_mcc(int irq
, void *dev_id
)
841 struct beiscsi_hba
*phba
;
842 struct be_eq_entry
*eqe
= NULL
;
843 struct be_queue_info
*eq
;
844 struct be_queue_info
*mcc
;
845 unsigned int num_eq_processed
;
846 struct be_eq_obj
*pbe_eq
;
852 mcc
= &phba
->ctrl
.mcc_obj
.cq
;
853 eqe
= queue_tail_node(eq
);
855 num_eq_processed
= 0;
857 while (eqe
->dw
[offsetof(struct amap_eq_entry
, valid
) / 32]
859 if (((eqe
->dw
[offsetof(struct amap_eq_entry
,
861 EQE_RESID_MASK
) >> 16) == mcc
->id
) {
862 spin_lock_irqsave(&phba
->isr_lock
, flags
);
863 pbe_eq
->todo_mcc_cq
= true;
864 spin_unlock_irqrestore(&phba
->isr_lock
, flags
);
866 AMAP_SET_BITS(struct amap_eq_entry
, valid
, eqe
, 0);
868 eqe
= queue_tail_node(eq
);
871 if (pbe_eq
->todo_mcc_cq
)
872 queue_work(phba
->wq
, &pbe_eq
->work_cqs
);
873 if (num_eq_processed
)
874 hwi_ring_eq_db(phba
, eq
->id
, 1, num_eq_processed
, 1, 1);
880 * be_isr_msix - The isr routine of the driver.
882 * @dev_id: Pointer to host adapter structure
884 static irqreturn_t
be_isr_msix(int irq
, void *dev_id
)
886 struct beiscsi_hba
*phba
;
887 struct be_eq_entry
*eqe
= NULL
;
888 struct be_queue_info
*eq
;
889 struct be_queue_info
*cq
;
890 unsigned int num_eq_processed
;
891 struct be_eq_obj
*pbe_eq
;
896 eqe
= queue_tail_node(eq
);
899 num_eq_processed
= 0;
900 while (eqe
->dw
[offsetof(struct amap_eq_entry
, valid
) / 32]
902 if (!blk_iopoll_sched_prep(&pbe_eq
->iopoll
))
903 blk_iopoll_sched(&pbe_eq
->iopoll
);
905 AMAP_SET_BITS(struct amap_eq_entry
, valid
, eqe
, 0);
907 eqe
= queue_tail_node(eq
);
911 if (num_eq_processed
)
912 hwi_ring_eq_db(phba
, eq
->id
, 1, num_eq_processed
, 0, 1);
918 * be_isr - The isr routine of the driver.
920 * @dev_id: Pointer to host adapter structure
922 static irqreturn_t
be_isr(int irq
, void *dev_id
)
924 struct beiscsi_hba
*phba
;
925 struct hwi_controller
*phwi_ctrlr
;
926 struct hwi_context_memory
*phwi_context
;
927 struct be_eq_entry
*eqe
= NULL
;
928 struct be_queue_info
*eq
;
929 struct be_queue_info
*mcc
;
930 unsigned long flags
, index
;
931 unsigned int num_mcceq_processed
, num_ioeq_processed
;
932 struct be_ctrl_info
*ctrl
;
933 struct be_eq_obj
*pbe_eq
;
938 isr
= ioread32(ctrl
->csr
+ CEV_ISR0_OFFSET
+
939 (PCI_FUNC(ctrl
->pdev
->devfn
) * CEV_ISR_SIZE
));
943 phwi_ctrlr
= phba
->phwi_ctrlr
;
944 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
945 pbe_eq
= &phwi_context
->be_eq
[0];
947 eq
= &phwi_context
->be_eq
[0].q
;
948 mcc
= &phba
->ctrl
.mcc_obj
.cq
;
950 eqe
= queue_tail_node(eq
);
952 num_ioeq_processed
= 0;
953 num_mcceq_processed
= 0;
954 while (eqe
->dw
[offsetof(struct amap_eq_entry
, valid
) / 32]
956 if (((eqe
->dw
[offsetof(struct amap_eq_entry
,
958 EQE_RESID_MASK
) >> 16) == mcc
->id
) {
959 spin_lock_irqsave(&phba
->isr_lock
, flags
);
960 pbe_eq
->todo_mcc_cq
= true;
961 spin_unlock_irqrestore(&phba
->isr_lock
, flags
);
962 num_mcceq_processed
++;
964 if (!blk_iopoll_sched_prep(&pbe_eq
->iopoll
))
965 blk_iopoll_sched(&pbe_eq
->iopoll
);
966 num_ioeq_processed
++;
968 AMAP_SET_BITS(struct amap_eq_entry
, valid
, eqe
, 0);
970 eqe
= queue_tail_node(eq
);
972 if (num_ioeq_processed
|| num_mcceq_processed
) {
973 if (pbe_eq
->todo_mcc_cq
)
974 queue_work(phba
->wq
, &pbe_eq
->work_cqs
);
976 if ((num_mcceq_processed
) && (!num_ioeq_processed
))
977 hwi_ring_eq_db(phba
, eq
->id
, 0,
978 (num_ioeq_processed
+
979 num_mcceq_processed
) , 1, 1);
981 hwi_ring_eq_db(phba
, eq
->id
, 0,
982 (num_ioeq_processed
+
983 num_mcceq_processed
), 0, 1);
990 static int beiscsi_init_irqs(struct beiscsi_hba
*phba
)
992 struct pci_dev
*pcidev
= phba
->pcidev
;
993 struct hwi_controller
*phwi_ctrlr
;
994 struct hwi_context_memory
*phwi_context
;
995 int ret
, msix_vec
, i
, j
;
997 phwi_ctrlr
= phba
->phwi_ctrlr
;
998 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
1000 if (phba
->msix_enabled
) {
1001 for (i
= 0; i
< phba
->num_cpus
; i
++) {
1002 phba
->msi_name
[i
] = kzalloc(BEISCSI_MSI_NAME
,
1004 if (!phba
->msi_name
[i
]) {
1006 goto free_msix_irqs
;
1009 sprintf(phba
->msi_name
[i
], "beiscsi_%02x_%02x",
1010 phba
->shost
->host_no
, i
);
1011 msix_vec
= phba
->msix_entries
[i
].vector
;
1012 ret
= request_irq(msix_vec
, be_isr_msix
, 0,
1014 &phwi_context
->be_eq
[i
]);
1016 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
1017 "BM_%d : beiscsi_init_irqs-Failed to"
1018 "register msix for i = %d\n",
1020 kfree(phba
->msi_name
[i
]);
1021 goto free_msix_irqs
;
1024 phba
->msi_name
[i
] = kzalloc(BEISCSI_MSI_NAME
, GFP_KERNEL
);
1025 if (!phba
->msi_name
[i
]) {
1027 goto free_msix_irqs
;
1029 sprintf(phba
->msi_name
[i
], "beiscsi_mcc_%02x",
1030 phba
->shost
->host_no
);
1031 msix_vec
= phba
->msix_entries
[i
].vector
;
1032 ret
= request_irq(msix_vec
, be_isr_mcc
, 0, phba
->msi_name
[i
],
1033 &phwi_context
->be_eq
[i
]);
1035 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
1036 "BM_%d : beiscsi_init_irqs-"
1037 "Failed to register beiscsi_msix_mcc\n");
1038 kfree(phba
->msi_name
[i
]);
1039 goto free_msix_irqs
;
1043 ret
= request_irq(pcidev
->irq
, be_isr
, IRQF_SHARED
,
1046 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
1047 "BM_%d : beiscsi_init_irqs-"
1048 "Failed to register irq\\n");
1054 for (j
= i
- 1; j
>= 0; j
--) {
1055 kfree(phba
->msi_name
[j
]);
1056 msix_vec
= phba
->msix_entries
[j
].vector
;
1057 free_irq(msix_vec
, &phwi_context
->be_eq
[j
]);
1062 void hwi_ring_cq_db(struct beiscsi_hba
*phba
,
1063 unsigned int id
, unsigned int num_processed
,
1064 unsigned char rearm
, unsigned char event
)
1069 val
|= 1 << DB_CQ_REARM_SHIFT
;
1071 val
|= num_processed
<< DB_CQ_NUM_POPPED_SHIFT
;
1073 /* Setting lower order CQ_ID Bits */
1074 val
|= (id
& DB_CQ_RING_ID_LOW_MASK
);
1076 /* Setting Higher order CQ_ID Bits */
1077 val
|= (((id
>> DB_CQ_HIGH_FEILD_SHIFT
) &
1078 DB_CQ_RING_ID_HIGH_MASK
)
1079 << DB_CQ_HIGH_SET_SHIFT
);
1081 iowrite32(val
, phba
->db_va
+ DB_CQ_OFFSET
);
1085 beiscsi_process_async_pdu(struct beiscsi_conn
*beiscsi_conn
,
1086 struct beiscsi_hba
*phba
,
1087 struct pdu_base
*ppdu
,
1088 unsigned long pdu_len
,
1089 void *pbuffer
, unsigned long buf_len
)
1091 struct iscsi_conn
*conn
= beiscsi_conn
->conn
;
1092 struct iscsi_session
*session
= conn
->session
;
1093 struct iscsi_task
*task
;
1094 struct beiscsi_io_task
*io_task
;
1095 struct iscsi_hdr
*login_hdr
;
1097 switch (ppdu
->dw
[offsetof(struct amap_pdu_base
, opcode
) / 32] &
1098 PDUBASE_OPCODE_MASK
) {
1099 case ISCSI_OP_NOOP_IN
:
1103 case ISCSI_OP_ASYNC_EVENT
:
1105 case ISCSI_OP_REJECT
:
1107 WARN_ON(!(buf_len
== 48));
1108 beiscsi_log(phba
, KERN_ERR
,
1109 BEISCSI_LOG_CONFIG
| BEISCSI_LOG_IO
,
1110 "BM_%d : In ISCSI_OP_REJECT\n");
1112 case ISCSI_OP_LOGIN_RSP
:
1113 case ISCSI_OP_TEXT_RSP
:
1114 task
= conn
->login_task
;
1115 io_task
= task
->dd_data
;
1116 login_hdr
= (struct iscsi_hdr
*)ppdu
;
1117 login_hdr
->itt
= io_task
->libiscsi_itt
;
1120 beiscsi_log(phba
, KERN_WARNING
,
1121 BEISCSI_LOG_IO
| BEISCSI_LOG_CONFIG
,
1122 "BM_%d : Unrecognized opcode 0x%x in async msg\n",
1124 dw
[offsetof(struct amap_pdu_base
, opcode
) / 32]
1125 & PDUBASE_OPCODE_MASK
));
1129 spin_lock_bh(&session
->back_lock
);
1130 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)ppdu
, pbuffer
, buf_len
);
1131 spin_unlock_bh(&session
->back_lock
);
1135 static struct sgl_handle
*alloc_io_sgl_handle(struct beiscsi_hba
*phba
)
1137 struct sgl_handle
*psgl_handle
;
1139 if (phba
->io_sgl_hndl_avbl
) {
1140 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_IO
,
1141 "BM_%d : In alloc_io_sgl_handle,"
1142 " io_sgl_alloc_index=%d\n",
1143 phba
->io_sgl_alloc_index
);
1145 psgl_handle
= phba
->io_sgl_hndl_base
[phba
->
1146 io_sgl_alloc_index
];
1147 phba
->io_sgl_hndl_base
[phba
->io_sgl_alloc_index
] = NULL
;
1148 phba
->io_sgl_hndl_avbl
--;
1149 if (phba
->io_sgl_alloc_index
== (phba
->params
.
1151 phba
->io_sgl_alloc_index
= 0;
1153 phba
->io_sgl_alloc_index
++;
1160 free_io_sgl_handle(struct beiscsi_hba
*phba
, struct sgl_handle
*psgl_handle
)
1162 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_IO
,
1163 "BM_%d : In free_,io_sgl_free_index=%d\n",
1164 phba
->io_sgl_free_index
);
1166 if (phba
->io_sgl_hndl_base
[phba
->io_sgl_free_index
]) {
1168 * this can happen if clean_task is called on a task that
1169 * failed in xmit_task or alloc_pdu.
1171 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_IO
,
1172 "BM_%d : Double Free in IO SGL io_sgl_free_index=%d,"
1173 "value there=%p\n", phba
->io_sgl_free_index
,
1174 phba
->io_sgl_hndl_base
1175 [phba
->io_sgl_free_index
]);
1178 phba
->io_sgl_hndl_base
[phba
->io_sgl_free_index
] = psgl_handle
;
1179 phba
->io_sgl_hndl_avbl
++;
1180 if (phba
->io_sgl_free_index
== (phba
->params
.ios_per_ctrl
- 1))
1181 phba
->io_sgl_free_index
= 0;
1183 phba
->io_sgl_free_index
++;
1187 * alloc_wrb_handle - To allocate a wrb handle
1188 * @phba: The hba pointer
1189 * @cid: The cid to use for allocation
1191 * This happens under session_lock until submission to chip
1193 struct wrb_handle
*alloc_wrb_handle(struct beiscsi_hba
*phba
, unsigned int cid
)
1195 struct hwi_wrb_context
*pwrb_context
;
1196 struct hwi_controller
*phwi_ctrlr
;
1197 struct wrb_handle
*pwrb_handle
, *pwrb_handle_tmp
;
1198 uint16_t cri_index
= BE_GET_CRI_FROM_CID(cid
);
1200 phwi_ctrlr
= phba
->phwi_ctrlr
;
1201 pwrb_context
= &phwi_ctrlr
->wrb_context
[cri_index
];
1202 if (pwrb_context
->wrb_handles_available
>= 2) {
1203 pwrb_handle
= pwrb_context
->pwrb_handle_base
[
1204 pwrb_context
->alloc_index
];
1205 pwrb_context
->wrb_handles_available
--;
1206 if (pwrb_context
->alloc_index
==
1207 (phba
->params
.wrbs_per_cxn
- 1))
1208 pwrb_context
->alloc_index
= 0;
1210 pwrb_context
->alloc_index
++;
1211 pwrb_handle_tmp
= pwrb_context
->pwrb_handle_base
[
1212 pwrb_context
->alloc_index
];
1213 pwrb_handle
->nxt_wrb_index
= pwrb_handle_tmp
->wrb_index
;
1220 * free_wrb_handle - To free the wrb handle back to pool
1221 * @phba: The hba pointer
1222 * @pwrb_context: The context to free from
1223 * @pwrb_handle: The wrb_handle to free
1225 * This happens under session_lock until submission to chip
1228 free_wrb_handle(struct beiscsi_hba
*phba
, struct hwi_wrb_context
*pwrb_context
,
1229 struct wrb_handle
*pwrb_handle
)
1231 pwrb_context
->pwrb_handle_base
[pwrb_context
->free_index
] = pwrb_handle
;
1232 pwrb_context
->wrb_handles_available
++;
1233 if (pwrb_context
->free_index
== (phba
->params
.wrbs_per_cxn
- 1))
1234 pwrb_context
->free_index
= 0;
1236 pwrb_context
->free_index
++;
1238 beiscsi_log(phba
, KERN_INFO
,
1239 BEISCSI_LOG_IO
| BEISCSI_LOG_CONFIG
,
1240 "BM_%d : FREE WRB: pwrb_handle=%p free_index=0x%x"
1241 "wrb_handles_available=%d\n",
1242 pwrb_handle
, pwrb_context
->free_index
,
1243 pwrb_context
->wrb_handles_available
);
1246 static struct sgl_handle
*alloc_mgmt_sgl_handle(struct beiscsi_hba
*phba
)
1248 struct sgl_handle
*psgl_handle
;
1250 if (phba
->eh_sgl_hndl_avbl
) {
1251 psgl_handle
= phba
->eh_sgl_hndl_base
[phba
->eh_sgl_alloc_index
];
1252 phba
->eh_sgl_hndl_base
[phba
->eh_sgl_alloc_index
] = NULL
;
1253 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_CONFIG
,
1254 "BM_%d : mgmt_sgl_alloc_index=%d=0x%x\n",
1255 phba
->eh_sgl_alloc_index
,
1256 phba
->eh_sgl_alloc_index
);
1258 phba
->eh_sgl_hndl_avbl
--;
1259 if (phba
->eh_sgl_alloc_index
==
1260 (phba
->params
.icds_per_ctrl
- phba
->params
.ios_per_ctrl
-
1262 phba
->eh_sgl_alloc_index
= 0;
1264 phba
->eh_sgl_alloc_index
++;
1271 free_mgmt_sgl_handle(struct beiscsi_hba
*phba
, struct sgl_handle
*psgl_handle
)
1274 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_CONFIG
,
1275 "BM_%d : In free_mgmt_sgl_handle,"
1276 "eh_sgl_free_index=%d\n",
1277 phba
->eh_sgl_free_index
);
1279 if (phba
->eh_sgl_hndl_base
[phba
->eh_sgl_free_index
]) {
1281 * this can happen if clean_task is called on a task that
1282 * failed in xmit_task or alloc_pdu.
1284 beiscsi_log(phba
, KERN_WARNING
, BEISCSI_LOG_CONFIG
,
1285 "BM_%d : Double Free in eh SGL ,"
1286 "eh_sgl_free_index=%d\n",
1287 phba
->eh_sgl_free_index
);
1290 phba
->eh_sgl_hndl_base
[phba
->eh_sgl_free_index
] = psgl_handle
;
1291 phba
->eh_sgl_hndl_avbl
++;
1292 if (phba
->eh_sgl_free_index
==
1293 (phba
->params
.icds_per_ctrl
- phba
->params
.ios_per_ctrl
- 1))
1294 phba
->eh_sgl_free_index
= 0;
1296 phba
->eh_sgl_free_index
++;
1300 be_complete_io(struct beiscsi_conn
*beiscsi_conn
,
1301 struct iscsi_task
*task
,
1302 struct common_sol_cqe
*csol_cqe
)
1304 struct beiscsi_io_task
*io_task
= task
->dd_data
;
1305 struct be_status_bhs
*sts_bhs
=
1306 (struct be_status_bhs
*)io_task
->cmd_bhs
;
1307 struct iscsi_conn
*conn
= beiscsi_conn
->conn
;
1308 unsigned char *sense
;
1309 u32 resid
= 0, exp_cmdsn
, max_cmdsn
;
1310 u8 rsp
, status
, flags
;
1312 exp_cmdsn
= csol_cqe
->exp_cmdsn
;
1313 max_cmdsn
= (csol_cqe
->exp_cmdsn
+
1314 csol_cqe
->cmd_wnd
- 1);
1315 rsp
= csol_cqe
->i_resp
;
1316 status
= csol_cqe
->i_sts
;
1317 flags
= csol_cqe
->i_flags
;
1318 resid
= csol_cqe
->res_cnt
;
1321 if (io_task
->scsi_cmnd
) {
1322 scsi_dma_unmap(io_task
->scsi_cmnd
);
1323 io_task
->scsi_cmnd
= NULL
;
1328 task
->sc
->result
= (DID_OK
<< 16) | status
;
1329 if (rsp
!= ISCSI_STATUS_CMD_COMPLETED
) {
1330 task
->sc
->result
= DID_ERROR
<< 16;
1334 /* bidi not initially supported */
1335 if (flags
& (ISCSI_FLAG_CMD_UNDERFLOW
| ISCSI_FLAG_CMD_OVERFLOW
)) {
1336 if (!status
&& (flags
& ISCSI_FLAG_CMD_OVERFLOW
))
1337 task
->sc
->result
= DID_ERROR
<< 16;
1339 if (flags
& ISCSI_FLAG_CMD_UNDERFLOW
) {
1340 scsi_set_resid(task
->sc
, resid
);
1341 if (!status
&& (scsi_bufflen(task
->sc
) - resid
<
1342 task
->sc
->underflow
))
1343 task
->sc
->result
= DID_ERROR
<< 16;
1347 if (status
== SAM_STAT_CHECK_CONDITION
) {
1349 unsigned short *slen
= (unsigned short *)sts_bhs
->sense_info
;
1351 sense
= sts_bhs
->sense_info
+ sizeof(unsigned short);
1352 sense_len
= be16_to_cpu(*slen
);
1353 memcpy(task
->sc
->sense_buffer
, sense
,
1354 min_t(u16
, sense_len
, SCSI_SENSE_BUFFERSIZE
));
1357 if (io_task
->cmd_bhs
->iscsi_hdr
.flags
& ISCSI_FLAG_CMD_READ
)
1358 conn
->rxdata_octets
+= resid
;
1360 scsi_dma_unmap(io_task
->scsi_cmnd
);
1361 io_task
->scsi_cmnd
= NULL
;
1362 iscsi_complete_scsi_task(task
, exp_cmdsn
, max_cmdsn
);
1366 be_complete_logout(struct beiscsi_conn
*beiscsi_conn
,
1367 struct iscsi_task
*task
,
1368 struct common_sol_cqe
*csol_cqe
)
1370 struct iscsi_logout_rsp
*hdr
;
1371 struct beiscsi_io_task
*io_task
= task
->dd_data
;
1372 struct iscsi_conn
*conn
= beiscsi_conn
->conn
;
1374 hdr
= (struct iscsi_logout_rsp
*)task
->hdr
;
1375 hdr
->opcode
= ISCSI_OP_LOGOUT_RSP
;
1378 hdr
->flags
= csol_cqe
->i_flags
;
1379 hdr
->response
= csol_cqe
->i_resp
;
1380 hdr
->exp_cmdsn
= cpu_to_be32(csol_cqe
->exp_cmdsn
);
1381 hdr
->max_cmdsn
= cpu_to_be32(csol_cqe
->exp_cmdsn
+
1382 csol_cqe
->cmd_wnd
- 1);
1384 hdr
->dlength
[0] = 0;
1385 hdr
->dlength
[1] = 0;
1386 hdr
->dlength
[2] = 0;
1388 hdr
->itt
= io_task
->libiscsi_itt
;
1389 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)hdr
, NULL
, 0);
1393 be_complete_tmf(struct beiscsi_conn
*beiscsi_conn
,
1394 struct iscsi_task
*task
,
1395 struct common_sol_cqe
*csol_cqe
)
1397 struct iscsi_tm_rsp
*hdr
;
1398 struct iscsi_conn
*conn
= beiscsi_conn
->conn
;
1399 struct beiscsi_io_task
*io_task
= task
->dd_data
;
1401 hdr
= (struct iscsi_tm_rsp
*)task
->hdr
;
1402 hdr
->opcode
= ISCSI_OP_SCSI_TMFUNC_RSP
;
1403 hdr
->flags
= csol_cqe
->i_flags
;
1404 hdr
->response
= csol_cqe
->i_resp
;
1405 hdr
->exp_cmdsn
= cpu_to_be32(csol_cqe
->exp_cmdsn
);
1406 hdr
->max_cmdsn
= cpu_to_be32(csol_cqe
->exp_cmdsn
+
1407 csol_cqe
->cmd_wnd
- 1);
1409 hdr
->itt
= io_task
->libiscsi_itt
;
1410 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)hdr
, NULL
, 0);
1414 hwi_complete_drvr_msgs(struct beiscsi_conn
*beiscsi_conn
,
1415 struct beiscsi_hba
*phba
, struct sol_cqe
*psol
)
1417 struct hwi_wrb_context
*pwrb_context
;
1418 struct wrb_handle
*pwrb_handle
= NULL
;
1419 struct hwi_controller
*phwi_ctrlr
;
1420 struct iscsi_task
*task
;
1421 struct beiscsi_io_task
*io_task
;
1422 uint16_t wrb_index
, cid
, cri_index
;
1424 phwi_ctrlr
= phba
->phwi_ctrlr
;
1425 if (is_chip_be2_be3r(phba
)) {
1426 wrb_index
= AMAP_GET_BITS(struct amap_it_dmsg_cqe
,
1428 cid
= AMAP_GET_BITS(struct amap_it_dmsg_cqe
,
1431 wrb_index
= AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2
,
1433 cid
= AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2
,
1437 cri_index
= BE_GET_CRI_FROM_CID(cid
);
1438 pwrb_context
= &phwi_ctrlr
->wrb_context
[cri_index
];
1439 pwrb_handle
= pwrb_context
->pwrb_handle_basestd
[wrb_index
];
1440 task
= pwrb_handle
->pio_handle
;
1442 io_task
= task
->dd_data
;
1443 memset(io_task
->pwrb_handle
->pwrb
, 0, sizeof(struct iscsi_wrb
));
1444 iscsi_put_task(task
);
1448 be_complete_nopin_resp(struct beiscsi_conn
*beiscsi_conn
,
1449 struct iscsi_task
*task
,
1450 struct common_sol_cqe
*csol_cqe
)
1452 struct iscsi_nopin
*hdr
;
1453 struct iscsi_conn
*conn
= beiscsi_conn
->conn
;
1454 struct beiscsi_io_task
*io_task
= task
->dd_data
;
1456 hdr
= (struct iscsi_nopin
*)task
->hdr
;
1457 hdr
->flags
= csol_cqe
->i_flags
;
1458 hdr
->exp_cmdsn
= cpu_to_be32(csol_cqe
->exp_cmdsn
);
1459 hdr
->max_cmdsn
= cpu_to_be32(csol_cqe
->exp_cmdsn
+
1460 csol_cqe
->cmd_wnd
- 1);
1462 hdr
->opcode
= ISCSI_OP_NOOP_IN
;
1463 hdr
->itt
= io_task
->libiscsi_itt
;
1464 __iscsi_complete_pdu(conn
, (struct iscsi_hdr
*)hdr
, NULL
, 0);
1467 static void adapter_get_sol_cqe(struct beiscsi_hba
*phba
,
1468 struct sol_cqe
*psol
,
1469 struct common_sol_cqe
*csol_cqe
)
1471 if (is_chip_be2_be3r(phba
)) {
1472 csol_cqe
->exp_cmdsn
= AMAP_GET_BITS(struct amap_sol_cqe
,
1473 i_exp_cmd_sn
, psol
);
1474 csol_cqe
->res_cnt
= AMAP_GET_BITS(struct amap_sol_cqe
,
1476 csol_cqe
->cmd_wnd
= AMAP_GET_BITS(struct amap_sol_cqe
,
1478 csol_cqe
->wrb_index
= AMAP_GET_BITS(struct amap_sol_cqe
,
1480 csol_cqe
->cid
= AMAP_GET_BITS(struct amap_sol_cqe
,
1482 csol_cqe
->hw_sts
= AMAP_GET_BITS(struct amap_sol_cqe
,
1484 csol_cqe
->i_resp
= AMAP_GET_BITS(struct amap_sol_cqe
,
1486 csol_cqe
->i_sts
= AMAP_GET_BITS(struct amap_sol_cqe
,
1488 csol_cqe
->i_flags
= AMAP_GET_BITS(struct amap_sol_cqe
,
1491 csol_cqe
->exp_cmdsn
= AMAP_GET_BITS(struct amap_sol_cqe_v2
,
1492 i_exp_cmd_sn
, psol
);
1493 csol_cqe
->res_cnt
= AMAP_GET_BITS(struct amap_sol_cqe_v2
,
1495 csol_cqe
->wrb_index
= AMAP_GET_BITS(struct amap_sol_cqe_v2
,
1497 csol_cqe
->cid
= AMAP_GET_BITS(struct amap_sol_cqe_v2
,
1499 csol_cqe
->hw_sts
= AMAP_GET_BITS(struct amap_sol_cqe_v2
,
1501 csol_cqe
->cmd_wnd
= AMAP_GET_BITS(struct amap_sol_cqe_v2
,
1503 if (AMAP_GET_BITS(struct amap_sol_cqe_v2
,
1505 csol_cqe
->i_sts
= AMAP_GET_BITS(struct amap_sol_cqe_v2
,
1508 csol_cqe
->i_resp
= AMAP_GET_BITS(struct amap_sol_cqe_v2
,
1510 if (AMAP_GET_BITS(struct amap_sol_cqe_v2
,
1512 csol_cqe
->i_flags
= ISCSI_FLAG_CMD_UNDERFLOW
;
1514 if (AMAP_GET_BITS(struct amap_sol_cqe_v2
,
1516 csol_cqe
->i_flags
|= ISCSI_FLAG_CMD_OVERFLOW
;
1521 static void hwi_complete_cmd(struct beiscsi_conn
*beiscsi_conn
,
1522 struct beiscsi_hba
*phba
, struct sol_cqe
*psol
)
1524 struct hwi_wrb_context
*pwrb_context
;
1525 struct wrb_handle
*pwrb_handle
;
1526 struct iscsi_wrb
*pwrb
= NULL
;
1527 struct hwi_controller
*phwi_ctrlr
;
1528 struct iscsi_task
*task
;
1530 struct iscsi_conn
*conn
= beiscsi_conn
->conn
;
1531 struct iscsi_session
*session
= conn
->session
;
1532 struct common_sol_cqe csol_cqe
= {0};
1533 uint16_t cri_index
= 0;
1535 phwi_ctrlr
= phba
->phwi_ctrlr
;
1537 /* Copy the elements to a common structure */
1538 adapter_get_sol_cqe(phba
, psol
, &csol_cqe
);
1540 cri_index
= BE_GET_CRI_FROM_CID(csol_cqe
.cid
);
1541 pwrb_context
= &phwi_ctrlr
->wrb_context
[cri_index
];
1543 pwrb_handle
= pwrb_context
->pwrb_handle_basestd
[
1544 csol_cqe
.wrb_index
];
1546 task
= pwrb_handle
->pio_handle
;
1547 pwrb
= pwrb_handle
->pwrb
;
1548 type
= ((struct beiscsi_io_task
*)task
->dd_data
)->wrb_type
;
1550 spin_lock_bh(&session
->back_lock
);
1553 case HWH_TYPE_IO_RD
:
1554 if ((task
->hdr
->opcode
& ISCSI_OPCODE_MASK
) ==
1556 be_complete_nopin_resp(beiscsi_conn
, task
, &csol_cqe
);
1558 be_complete_io(beiscsi_conn
, task
, &csol_cqe
);
1561 case HWH_TYPE_LOGOUT
:
1562 if ((task
->hdr
->opcode
& ISCSI_OPCODE_MASK
) == ISCSI_OP_LOGOUT
)
1563 be_complete_logout(beiscsi_conn
, task
, &csol_cqe
);
1565 be_complete_tmf(beiscsi_conn
, task
, &csol_cqe
);
1568 case HWH_TYPE_LOGIN
:
1569 beiscsi_log(phba
, KERN_ERR
,
1570 BEISCSI_LOG_CONFIG
| BEISCSI_LOG_IO
,
1571 "BM_%d :\t\t No HWH_TYPE_LOGIN Expected in"
1572 " hwi_complete_cmd- Solicited path\n");
1576 be_complete_nopin_resp(beiscsi_conn
, task
, &csol_cqe
);
1580 beiscsi_log(phba
, KERN_WARNING
,
1581 BEISCSI_LOG_CONFIG
| BEISCSI_LOG_IO
,
1582 "BM_%d : In hwi_complete_cmd, unknown type = %d"
1583 "wrb_index 0x%x CID 0x%x\n", type
,
1589 spin_unlock_bh(&session
->back_lock
);
1592 static struct list_head
*hwi_get_async_busy_list(struct hwi_async_pdu_context
1593 *pasync_ctx
, unsigned int is_header
,
1594 unsigned int host_write_ptr
)
1597 return &pasync_ctx
->async_entry
[host_write_ptr
].
1600 return &pasync_ctx
->async_entry
[host_write_ptr
].data_busy_list
;
1603 static struct async_pdu_handle
*
1604 hwi_get_async_handle(struct beiscsi_hba
*phba
,
1605 struct beiscsi_conn
*beiscsi_conn
,
1606 struct hwi_async_pdu_context
*pasync_ctx
,
1607 struct i_t_dpdu_cqe
*pdpdu_cqe
, unsigned int *pcq_index
)
1609 struct be_bus_address phys_addr
;
1610 struct list_head
*pbusy_list
;
1611 struct async_pdu_handle
*pasync_handle
= NULL
;
1612 unsigned char is_header
= 0;
1613 unsigned int index
, dpl
;
1615 if (is_chip_be2_be3r(phba
)) {
1616 dpl
= AMAP_GET_BITS(struct amap_i_t_dpdu_cqe
,
1618 index
= AMAP_GET_BITS(struct amap_i_t_dpdu_cqe
,
1621 dpl
= AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2
,
1623 index
= AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2
,
1627 phys_addr
.u
.a32
.address_lo
=
1628 (pdpdu_cqe
->dw
[offsetof(struct amap_i_t_dpdu_cqe
,
1629 db_addr_lo
) / 32] - dpl
);
1630 phys_addr
.u
.a32
.address_hi
=
1631 pdpdu_cqe
->dw
[offsetof(struct amap_i_t_dpdu_cqe
,
1634 phys_addr
.u
.a64
.address
=
1635 *((unsigned long long *)(&phys_addr
.u
.a64
.address
));
1637 switch (pdpdu_cqe
->dw
[offsetof(struct amap_i_t_dpdu_cqe
, code
) / 32]
1638 & PDUCQE_CODE_MASK
) {
1639 case UNSOL_HDR_NOTIFY
:
1642 pbusy_list
= hwi_get_async_busy_list(pasync_ctx
,
1645 case UNSOL_DATA_NOTIFY
:
1646 pbusy_list
= hwi_get_async_busy_list(pasync_ctx
,
1651 beiscsi_log(phba
, KERN_WARNING
,
1652 BEISCSI_LOG_IO
| BEISCSI_LOG_CONFIG
,
1653 "BM_%d : Unexpected code=%d\n",
1654 pdpdu_cqe
->dw
[offsetof(struct amap_i_t_dpdu_cqe
,
1655 code
) / 32] & PDUCQE_CODE_MASK
);
1659 WARN_ON(list_empty(pbusy_list
));
1660 list_for_each_entry(pasync_handle
, pbusy_list
, link
) {
1661 if (pasync_handle
->pa
.u
.a64
.address
== phys_addr
.u
.a64
.address
)
1665 WARN_ON(!pasync_handle
);
1667 pasync_handle
->cri
= BE_GET_ASYNC_CRI_FROM_CID(
1668 beiscsi_conn
->beiscsi_conn_cid
);
1669 pasync_handle
->is_header
= is_header
;
1670 pasync_handle
->buffer_len
= dpl
;
1673 return pasync_handle
;
1677 hwi_update_async_writables(struct beiscsi_hba
*phba
,
1678 struct hwi_async_pdu_context
*pasync_ctx
,
1679 unsigned int is_header
, unsigned int cq_index
)
1681 struct list_head
*pbusy_list
;
1682 struct async_pdu_handle
*pasync_handle
;
1683 unsigned int num_entries
, writables
= 0;
1684 unsigned int *pep_read_ptr
, *pwritables
;
1686 num_entries
= pasync_ctx
->num_entries
;
1688 pep_read_ptr
= &pasync_ctx
->async_header
.ep_read_ptr
;
1689 pwritables
= &pasync_ctx
->async_header
.writables
;
1691 pep_read_ptr
= &pasync_ctx
->async_data
.ep_read_ptr
;
1692 pwritables
= &pasync_ctx
->async_data
.writables
;
1695 while ((*pep_read_ptr
) != cq_index
) {
1697 *pep_read_ptr
= (*pep_read_ptr
) % num_entries
;
1699 pbusy_list
= hwi_get_async_busy_list(pasync_ctx
, is_header
,
1702 WARN_ON(list_empty(pbusy_list
));
1704 if (!list_empty(pbusy_list
)) {
1705 pasync_handle
= list_entry(pbusy_list
->next
,
1706 struct async_pdu_handle
,
1708 WARN_ON(!pasync_handle
);
1709 pasync_handle
->consumed
= 1;
1716 beiscsi_log(phba
, KERN_ERR
,
1717 BEISCSI_LOG_CONFIG
| BEISCSI_LOG_IO
,
1718 "BM_%d : Duplicate notification received - index 0x%x!!\n",
1723 *pwritables
= *pwritables
+ writables
;
1727 static void hwi_free_async_msg(struct beiscsi_hba
*phba
,
1728 struct hwi_async_pdu_context
*pasync_ctx
,
1731 struct async_pdu_handle
*pasync_handle
, *tmp_handle
;
1732 struct list_head
*plist
;
1734 plist
= &pasync_ctx
->async_entry
[cri
].wait_queue
.list
;
1735 list_for_each_entry_safe(pasync_handle
, tmp_handle
, plist
, link
) {
1736 list_del(&pasync_handle
->link
);
1738 if (pasync_handle
->is_header
) {
1739 list_add_tail(&pasync_handle
->link
,
1740 &pasync_ctx
->async_header
.free_list
);
1741 pasync_ctx
->async_header
.free_entries
++;
1743 list_add_tail(&pasync_handle
->link
,
1744 &pasync_ctx
->async_data
.free_list
);
1745 pasync_ctx
->async_data
.free_entries
++;
1749 INIT_LIST_HEAD(&pasync_ctx
->async_entry
[cri
].wait_queue
.list
);
1750 pasync_ctx
->async_entry
[cri
].wait_queue
.hdr_received
= 0;
1751 pasync_ctx
->async_entry
[cri
].wait_queue
.bytes_received
= 0;
1754 static struct phys_addr
*
1755 hwi_get_ring_address(struct hwi_async_pdu_context
*pasync_ctx
,
1756 unsigned int is_header
, unsigned int host_write_ptr
)
1758 struct phys_addr
*pasync_sge
= NULL
;
1761 pasync_sge
= pasync_ctx
->async_header
.ring_base
;
1763 pasync_sge
= pasync_ctx
->async_data
.ring_base
;
1765 return pasync_sge
+ host_write_ptr
;
1768 static void hwi_post_async_buffers(struct beiscsi_hba
*phba
,
1769 unsigned int is_header
, uint8_t ulp_num
)
1771 struct hwi_controller
*phwi_ctrlr
;
1772 struct hwi_async_pdu_context
*pasync_ctx
;
1773 struct async_pdu_handle
*pasync_handle
;
1774 struct list_head
*pfree_link
, *pbusy_list
;
1775 struct phys_addr
*pasync_sge
;
1776 unsigned int ring_id
, num_entries
;
1777 unsigned int host_write_num
, doorbell_offset
;
1778 unsigned int writables
;
1782 phwi_ctrlr
= phba
->phwi_ctrlr
;
1783 pasync_ctx
= HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr
, ulp_num
);
1784 num_entries
= pasync_ctx
->num_entries
;
1787 writables
= min(pasync_ctx
->async_header
.writables
,
1788 pasync_ctx
->async_header
.free_entries
);
1789 pfree_link
= pasync_ctx
->async_header
.free_list
.next
;
1790 host_write_num
= pasync_ctx
->async_header
.host_write_ptr
;
1791 ring_id
= phwi_ctrlr
->default_pdu_hdr
[ulp_num
].id
;
1792 doorbell_offset
= phwi_ctrlr
->default_pdu_hdr
[ulp_num
].
1795 writables
= min(pasync_ctx
->async_data
.writables
,
1796 pasync_ctx
->async_data
.free_entries
);
1797 pfree_link
= pasync_ctx
->async_data
.free_list
.next
;
1798 host_write_num
= pasync_ctx
->async_data
.host_write_ptr
;
1799 ring_id
= phwi_ctrlr
->default_pdu_data
[ulp_num
].id
;
1800 doorbell_offset
= phwi_ctrlr
->default_pdu_data
[ulp_num
].
1804 writables
= (writables
/ 8) * 8;
1806 for (i
= 0; i
< writables
; i
++) {
1808 hwi_get_async_busy_list(pasync_ctx
, is_header
,
1811 list_entry(pfree_link
, struct async_pdu_handle
,
1813 WARN_ON(!pasync_handle
);
1814 pasync_handle
->consumed
= 0;
1816 pfree_link
= pfree_link
->next
;
1818 pasync_sge
= hwi_get_ring_address(pasync_ctx
,
1819 is_header
, host_write_num
);
1821 pasync_sge
->hi
= pasync_handle
->pa
.u
.a32
.address_lo
;
1822 pasync_sge
->lo
= pasync_handle
->pa
.u
.a32
.address_hi
;
1824 list_move(&pasync_handle
->link
, pbusy_list
);
1827 host_write_num
= host_write_num
% num_entries
;
1831 pasync_ctx
->async_header
.host_write_ptr
=
1833 pasync_ctx
->async_header
.free_entries
-= writables
;
1834 pasync_ctx
->async_header
.writables
-= writables
;
1835 pasync_ctx
->async_header
.busy_entries
+= writables
;
1837 pasync_ctx
->async_data
.host_write_ptr
= host_write_num
;
1838 pasync_ctx
->async_data
.free_entries
-= writables
;
1839 pasync_ctx
->async_data
.writables
-= writables
;
1840 pasync_ctx
->async_data
.busy_entries
+= writables
;
1843 doorbell
|= ring_id
& DB_DEF_PDU_RING_ID_MASK
;
1844 doorbell
|= 1 << DB_DEF_PDU_REARM_SHIFT
;
1845 doorbell
|= 0 << DB_DEF_PDU_EVENT_SHIFT
;
1846 doorbell
|= (writables
& DB_DEF_PDU_CQPROC_MASK
)
1847 << DB_DEF_PDU_CQPROC_SHIFT
;
1849 iowrite32(doorbell
, phba
->db_va
+ doorbell_offset
);
1853 static void hwi_flush_default_pdu_buffer(struct beiscsi_hba
*phba
,
1854 struct beiscsi_conn
*beiscsi_conn
,
1855 struct i_t_dpdu_cqe
*pdpdu_cqe
)
1857 struct hwi_controller
*phwi_ctrlr
;
1858 struct hwi_async_pdu_context
*pasync_ctx
;
1859 struct async_pdu_handle
*pasync_handle
= NULL
;
1860 unsigned int cq_index
= -1;
1861 uint16_t cri_index
= BE_GET_CRI_FROM_CID(
1862 beiscsi_conn
->beiscsi_conn_cid
);
1864 phwi_ctrlr
= phba
->phwi_ctrlr
;
1865 pasync_ctx
= HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr
,
1866 BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr
,
1869 pasync_handle
= hwi_get_async_handle(phba
, beiscsi_conn
, pasync_ctx
,
1870 pdpdu_cqe
, &cq_index
);
1871 BUG_ON(pasync_handle
->is_header
!= 0);
1872 if (pasync_handle
->consumed
== 0)
1873 hwi_update_async_writables(phba
, pasync_ctx
,
1874 pasync_handle
->is_header
, cq_index
);
1876 hwi_free_async_msg(phba
, pasync_ctx
, pasync_handle
->cri
);
1877 hwi_post_async_buffers(phba
, pasync_handle
->is_header
,
1878 BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr
,
1883 hwi_fwd_async_msg(struct beiscsi_conn
*beiscsi_conn
,
1884 struct beiscsi_hba
*phba
,
1885 struct hwi_async_pdu_context
*pasync_ctx
, unsigned short cri
)
1887 struct list_head
*plist
;
1888 struct async_pdu_handle
*pasync_handle
;
1890 unsigned int hdr_len
= 0, buf_len
= 0;
1891 unsigned int status
, index
= 0, offset
= 0;
1892 void *pfirst_buffer
= NULL
;
1893 unsigned int num_buf
= 0;
1895 plist
= &pasync_ctx
->async_entry
[cri
].wait_queue
.list
;
1897 list_for_each_entry(pasync_handle
, plist
, link
) {
1899 phdr
= pasync_handle
->pbuffer
;
1900 hdr_len
= pasync_handle
->buffer_len
;
1902 buf_len
= pasync_handle
->buffer_len
;
1904 pfirst_buffer
= pasync_handle
->pbuffer
;
1907 memcpy(pfirst_buffer
+ offset
,
1908 pasync_handle
->pbuffer
, buf_len
);
1914 status
= beiscsi_process_async_pdu(beiscsi_conn
, phba
,
1915 phdr
, hdr_len
, pfirst_buffer
,
1918 hwi_free_async_msg(phba
, pasync_ctx
, cri
);
1923 hwi_gather_async_pdu(struct beiscsi_conn
*beiscsi_conn
,
1924 struct beiscsi_hba
*phba
,
1925 struct async_pdu_handle
*pasync_handle
)
1927 struct hwi_async_pdu_context
*pasync_ctx
;
1928 struct hwi_controller
*phwi_ctrlr
;
1929 unsigned int bytes_needed
= 0, status
= 0;
1930 unsigned short cri
= pasync_handle
->cri
;
1931 struct pdu_base
*ppdu
;
1933 phwi_ctrlr
= phba
->phwi_ctrlr
;
1934 pasync_ctx
= HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr
,
1935 BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr
,
1936 BE_GET_CRI_FROM_CID(beiscsi_conn
->
1937 beiscsi_conn_cid
)));
1939 list_del(&pasync_handle
->link
);
1940 if (pasync_handle
->is_header
) {
1941 pasync_ctx
->async_header
.busy_entries
--;
1942 if (pasync_ctx
->async_entry
[cri
].wait_queue
.hdr_received
) {
1943 hwi_free_async_msg(phba
, pasync_ctx
, cri
);
1947 pasync_ctx
->async_entry
[cri
].wait_queue
.bytes_received
= 0;
1948 pasync_ctx
->async_entry
[cri
].wait_queue
.hdr_received
= 1;
1949 pasync_ctx
->async_entry
[cri
].wait_queue
.hdr_len
=
1950 (unsigned short)pasync_handle
->buffer_len
;
1951 list_add_tail(&pasync_handle
->link
,
1952 &pasync_ctx
->async_entry
[cri
].wait_queue
.list
);
1954 ppdu
= pasync_handle
->pbuffer
;
1955 bytes_needed
= ((((ppdu
->dw
[offsetof(struct amap_pdu_base
,
1956 data_len_hi
) / 32] & PDUBASE_DATALENHI_MASK
) << 8) &
1957 0xFFFF0000) | ((be16_to_cpu((ppdu
->
1958 dw
[offsetof(struct amap_pdu_base
, data_len_lo
) / 32]
1959 & PDUBASE_DATALENLO_MASK
) >> 16)) & 0x0000FFFF));
1962 pasync_ctx
->async_entry
[cri
].wait_queue
.bytes_needed
=
1965 if (bytes_needed
== 0)
1966 status
= hwi_fwd_async_msg(beiscsi_conn
, phba
,
1970 pasync_ctx
->async_data
.busy_entries
--;
1971 if (pasync_ctx
->async_entry
[cri
].wait_queue
.hdr_received
) {
1972 list_add_tail(&pasync_handle
->link
,
1973 &pasync_ctx
->async_entry
[cri
].wait_queue
.
1975 pasync_ctx
->async_entry
[cri
].wait_queue
.
1977 (unsigned short)pasync_handle
->buffer_len
;
1979 if (pasync_ctx
->async_entry
[cri
].wait_queue
.
1981 pasync_ctx
->async_entry
[cri
].wait_queue
.
1983 status
= hwi_fwd_async_msg(beiscsi_conn
, phba
,
1990 static void hwi_process_default_pdu_ring(struct beiscsi_conn
*beiscsi_conn
,
1991 struct beiscsi_hba
*phba
,
1992 struct i_t_dpdu_cqe
*pdpdu_cqe
)
1994 struct hwi_controller
*phwi_ctrlr
;
1995 struct hwi_async_pdu_context
*pasync_ctx
;
1996 struct async_pdu_handle
*pasync_handle
= NULL
;
1997 unsigned int cq_index
= -1;
1998 uint16_t cri_index
= BE_GET_CRI_FROM_CID(
1999 beiscsi_conn
->beiscsi_conn_cid
);
2001 phwi_ctrlr
= phba
->phwi_ctrlr
;
2002 pasync_ctx
= HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr
,
2003 BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr
,
2006 pasync_handle
= hwi_get_async_handle(phba
, beiscsi_conn
, pasync_ctx
,
2007 pdpdu_cqe
, &cq_index
);
2009 if (pasync_handle
->consumed
== 0)
2010 hwi_update_async_writables(phba
, pasync_ctx
,
2011 pasync_handle
->is_header
, cq_index
);
2013 hwi_gather_async_pdu(beiscsi_conn
, phba
, pasync_handle
);
2014 hwi_post_async_buffers(phba
, pasync_handle
->is_header
,
2015 BEISCSI_GET_ULP_FROM_CRI(
2016 phwi_ctrlr
, cri_index
));
2019 static void beiscsi_process_mcc_isr(struct beiscsi_hba
*phba
)
2021 struct be_queue_info
*mcc_cq
;
2022 struct be_mcc_compl
*mcc_compl
;
2023 unsigned int num_processed
= 0;
2025 mcc_cq
= &phba
->ctrl
.mcc_obj
.cq
;
2026 mcc_compl
= queue_tail_node(mcc_cq
);
2027 mcc_compl
->flags
= le32_to_cpu(mcc_compl
->flags
);
2028 while (mcc_compl
->flags
& CQE_FLAGS_VALID_MASK
) {
2030 if (num_processed
>= 32) {
2031 hwi_ring_cq_db(phba
, mcc_cq
->id
,
2032 num_processed
, 0, 0);
2035 if (mcc_compl
->flags
& CQE_FLAGS_ASYNC_MASK
) {
2036 /* Interpret flags as an async trailer */
2037 if (is_link_state_evt(mcc_compl
->flags
))
2038 /* Interpret compl as a async link evt */
2039 beiscsi_async_link_state_process(phba
,
2040 (struct be_async_event_link_state
*) mcc_compl
);
2042 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_MBOX
,
2043 "BM_%d : Unsupported Async Event, flags"
2046 } else if (mcc_compl
->flags
& CQE_FLAGS_COMPLETED_MASK
) {
2047 be_mcc_compl_process_isr(&phba
->ctrl
, mcc_compl
);
2048 atomic_dec(&phba
->ctrl
.mcc_obj
.q
.used
);
2051 mcc_compl
->flags
= 0;
2052 queue_tail_inc(mcc_cq
);
2053 mcc_compl
= queue_tail_node(mcc_cq
);
2054 mcc_compl
->flags
= le32_to_cpu(mcc_compl
->flags
);
2058 if (num_processed
> 0)
2059 hwi_ring_cq_db(phba
, mcc_cq
->id
, num_processed
, 1, 0);
2064 * beiscsi_process_cq()- Process the Completion Queue
2065 * @pbe_eq: Event Q on which the Completion has come
2068 * Number of Completion Entries processed.
2070 unsigned int beiscsi_process_cq(struct be_eq_obj
*pbe_eq
)
2072 struct be_queue_info
*cq
;
2073 struct sol_cqe
*sol
;
2074 struct dmsg_cqe
*dmsg
;
2075 unsigned int num_processed
= 0;
2076 unsigned int tot_nump
= 0;
2077 unsigned short code
= 0, cid
= 0;
2078 uint16_t cri_index
= 0;
2079 struct beiscsi_conn
*beiscsi_conn
;
2080 struct beiscsi_endpoint
*beiscsi_ep
;
2081 struct iscsi_endpoint
*ep
;
2082 struct beiscsi_hba
*phba
;
2085 sol
= queue_tail_node(cq
);
2086 phba
= pbe_eq
->phba
;
2088 while (sol
->dw
[offsetof(struct amap_sol_cqe
, valid
) / 32] &
2090 be_dws_le_to_cpu(sol
, sizeof(struct sol_cqe
));
2092 code
= (sol
->dw
[offsetof(struct amap_sol_cqe
, code
) /
2093 32] & CQE_CODE_MASK
);
2096 if (is_chip_be2_be3r(phba
)) {
2097 cid
= AMAP_GET_BITS(struct amap_sol_cqe
, cid
, sol
);
2099 if ((code
== DRIVERMSG_NOTIFY
) ||
2100 (code
== UNSOL_HDR_NOTIFY
) ||
2101 (code
== UNSOL_DATA_NOTIFY
))
2102 cid
= AMAP_GET_BITS(
2103 struct amap_i_t_dpdu_cqe_v2
,
2106 cid
= AMAP_GET_BITS(struct amap_sol_cqe_v2
,
2110 cri_index
= BE_GET_CRI_FROM_CID(cid
);
2111 ep
= phba
->ep_array
[cri_index
];
2114 /* connection has already been freed
2115 * just move on to next one
2117 beiscsi_log(phba
, KERN_WARNING
,
2119 "BM_%d : proc cqe of disconn ep: cid %d\n",
2124 beiscsi_ep
= ep
->dd_data
;
2125 beiscsi_conn
= beiscsi_ep
->conn
;
2127 if (num_processed
>= 32) {
2128 hwi_ring_cq_db(phba
, cq
->id
,
2129 num_processed
, 0, 0);
2130 tot_nump
+= num_processed
;
2135 case SOL_CMD_COMPLETE
:
2136 hwi_complete_cmd(beiscsi_conn
, phba
, sol
);
2138 case DRIVERMSG_NOTIFY
:
2139 beiscsi_log(phba
, KERN_INFO
,
2140 BEISCSI_LOG_IO
| BEISCSI_LOG_CONFIG
,
2141 "BM_%d : Received %s[%d] on CID : %d\n",
2142 cqe_desc
[code
], code
, cid
);
2144 dmsg
= (struct dmsg_cqe
*)sol
;
2145 hwi_complete_drvr_msgs(beiscsi_conn
, phba
, sol
);
2147 case UNSOL_HDR_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 spin_lock_bh(&phba
->async_pdu_lock
);
2154 hwi_process_default_pdu_ring(beiscsi_conn
, phba
,
2155 (struct i_t_dpdu_cqe
*)sol
);
2156 spin_unlock_bh(&phba
->async_pdu_lock
);
2158 case UNSOL_DATA_NOTIFY
:
2159 beiscsi_log(phba
, KERN_INFO
,
2160 BEISCSI_LOG_CONFIG
| BEISCSI_LOG_IO
,
2161 "BM_%d : Received %s[%d] on CID : %d\n",
2162 cqe_desc
[code
], code
, cid
);
2164 spin_lock_bh(&phba
->async_pdu_lock
);
2165 hwi_process_default_pdu_ring(beiscsi_conn
, phba
,
2166 (struct i_t_dpdu_cqe
*)sol
);
2167 spin_unlock_bh(&phba
->async_pdu_lock
);
2169 case CXN_INVALIDATE_INDEX_NOTIFY
:
2170 case CMD_INVALIDATED_NOTIFY
:
2171 case CXN_INVALIDATE_NOTIFY
:
2172 beiscsi_log(phba
, KERN_ERR
,
2173 BEISCSI_LOG_IO
| BEISCSI_LOG_CONFIG
,
2174 "BM_%d : Ignoring %s[%d] on CID : %d\n",
2175 cqe_desc
[code
], code
, cid
);
2177 case SOL_CMD_KILLED_DATA_DIGEST_ERR
:
2178 case CMD_KILLED_INVALID_STATSN_RCVD
:
2179 case CMD_KILLED_INVALID_R2T_RCVD
:
2180 case CMD_CXN_KILLED_LUN_INVALID
:
2181 case CMD_CXN_KILLED_ICD_INVALID
:
2182 case CMD_CXN_KILLED_ITT_INVALID
:
2183 case CMD_CXN_KILLED_SEQ_OUTOFORDER
:
2184 case CMD_CXN_KILLED_INVALID_DATASN_RCVD
:
2185 beiscsi_log(phba
, KERN_ERR
,
2186 BEISCSI_LOG_CONFIG
| BEISCSI_LOG_IO
,
2187 "BM_%d : Cmd Notification %s[%d] on CID : %d\n",
2188 cqe_desc
[code
], code
, cid
);
2190 case UNSOL_DATA_DIGEST_ERROR_NOTIFY
:
2191 beiscsi_log(phba
, KERN_ERR
,
2192 BEISCSI_LOG_IO
| BEISCSI_LOG_CONFIG
,
2193 "BM_%d : Dropping %s[%d] on DPDU ring on CID : %d\n",
2194 cqe_desc
[code
], code
, cid
);
2195 spin_lock_bh(&phba
->async_pdu_lock
);
2196 hwi_flush_default_pdu_buffer(phba
, beiscsi_conn
,
2197 (struct i_t_dpdu_cqe
*) sol
);
2198 spin_unlock_bh(&phba
->async_pdu_lock
);
2200 case CXN_KILLED_PDU_SIZE_EXCEEDS_DSL
:
2201 case CXN_KILLED_BURST_LEN_MISMATCH
:
2202 case CXN_KILLED_AHS_RCVD
:
2203 case CXN_KILLED_HDR_DIGEST_ERR
:
2204 case CXN_KILLED_UNKNOWN_HDR
:
2205 case CXN_KILLED_STALE_ITT_TTT_RCVD
:
2206 case CXN_KILLED_INVALID_ITT_TTT_RCVD
:
2207 case CXN_KILLED_TIMED_OUT
:
2208 case CXN_KILLED_FIN_RCVD
:
2209 case CXN_KILLED_RST_SENT
:
2210 case CXN_KILLED_RST_RCVD
:
2211 case CXN_KILLED_BAD_UNSOL_PDU_RCVD
:
2212 case CXN_KILLED_BAD_WRB_INDEX_ERROR
:
2213 case CXN_KILLED_OVER_RUN_RESIDUAL
:
2214 case CXN_KILLED_UNDER_RUN_RESIDUAL
:
2215 case CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN
:
2216 beiscsi_log(phba
, KERN_ERR
,
2217 BEISCSI_LOG_IO
| BEISCSI_LOG_CONFIG
,
2218 "BM_%d : Event %s[%d] received on CID : %d\n",
2219 cqe_desc
[code
], code
, cid
);
2221 iscsi_conn_failure(beiscsi_conn
->conn
,
2222 ISCSI_ERR_CONN_FAILED
);
2225 beiscsi_log(phba
, KERN_ERR
,
2226 BEISCSI_LOG_IO
| BEISCSI_LOG_CONFIG
,
2227 "BM_%d : Invalid CQE Event Received Code : %d"
2234 AMAP_SET_BITS(struct amap_sol_cqe
, valid
, sol
, 0);
2236 sol
= queue_tail_node(cq
);
2240 if (num_processed
> 0) {
2241 tot_nump
+= num_processed
;
2242 hwi_ring_cq_db(phba
, cq
->id
, num_processed
, 1, 0);
2247 void beiscsi_process_all_cqs(struct work_struct
*work
)
2249 unsigned long flags
;
2250 struct hwi_controller
*phwi_ctrlr
;
2251 struct hwi_context_memory
*phwi_context
;
2252 struct beiscsi_hba
*phba
;
2253 struct be_eq_obj
*pbe_eq
=
2254 container_of(work
, struct be_eq_obj
, work_cqs
);
2256 phba
= pbe_eq
->phba
;
2257 phwi_ctrlr
= phba
->phwi_ctrlr
;
2258 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
2260 if (pbe_eq
->todo_mcc_cq
) {
2261 spin_lock_irqsave(&phba
->isr_lock
, flags
);
2262 pbe_eq
->todo_mcc_cq
= false;
2263 spin_unlock_irqrestore(&phba
->isr_lock
, flags
);
2264 beiscsi_process_mcc_isr(phba
);
2267 if (pbe_eq
->todo_cq
) {
2268 spin_lock_irqsave(&phba
->isr_lock
, flags
);
2269 pbe_eq
->todo_cq
= false;
2270 spin_unlock_irqrestore(&phba
->isr_lock
, flags
);
2271 beiscsi_process_cq(pbe_eq
);
2274 /* rearm EQ for further interrupts */
2275 hwi_ring_eq_db(phba
, pbe_eq
->q
.id
, 0, 0, 1, 1);
2278 static int be_iopoll(struct blk_iopoll
*iop
, int budget
)
2281 struct beiscsi_hba
*phba
;
2282 struct be_eq_obj
*pbe_eq
;
2284 pbe_eq
= container_of(iop
, struct be_eq_obj
, iopoll
);
2285 ret
= beiscsi_process_cq(pbe_eq
);
2286 pbe_eq
->cq_count
+= ret
;
2288 phba
= pbe_eq
->phba
;
2289 blk_iopoll_complete(iop
);
2290 beiscsi_log(phba
, KERN_INFO
,
2291 BEISCSI_LOG_CONFIG
| BEISCSI_LOG_IO
,
2292 "BM_%d : rearm pbe_eq->q.id =%d\n",
2294 hwi_ring_eq_db(phba
, pbe_eq
->q
.id
, 0, 0, 1, 1);
2300 hwi_write_sgl_v2(struct iscsi_wrb
*pwrb
, struct scatterlist
*sg
,
2301 unsigned int num_sg
, struct beiscsi_io_task
*io_task
)
2303 struct iscsi_sge
*psgl
;
2304 unsigned int sg_len
, index
;
2305 unsigned int sge_len
= 0;
2306 unsigned long long addr
;
2307 struct scatterlist
*l_sg
;
2308 unsigned int offset
;
2310 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, iscsi_bhs_addr_lo
, pwrb
,
2311 io_task
->bhs_pa
.u
.a32
.address_lo
);
2312 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, iscsi_bhs_addr_hi
, pwrb
,
2313 io_task
->bhs_pa
.u
.a32
.address_hi
);
2316 for (index
= 0; (index
< num_sg
) && (index
< 2); index
++,
2319 sg_len
= sg_dma_len(sg
);
2320 addr
= (u64
) sg_dma_address(sg
);
2321 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
,
2323 lower_32_bits(addr
));
2324 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
,
2326 upper_32_bits(addr
));
2327 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
,
2332 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, sge1_r2t_offset
,
2334 sg_len
= sg_dma_len(sg
);
2335 addr
= (u64
) sg_dma_address(sg
);
2336 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
,
2338 lower_32_bits(addr
));
2339 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
,
2341 upper_32_bits(addr
));
2342 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
,
2347 psgl
= (struct iscsi_sge
*)io_task
->psgl_handle
->pfrag
;
2348 memset(psgl
, 0, sizeof(*psgl
) * BE2_SGE
);
2350 AMAP_SET_BITS(struct amap_iscsi_sge
, len
, psgl
, io_task
->bhs_len
- 2);
2352 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_hi
, psgl
,
2353 io_task
->bhs_pa
.u
.a32
.address_hi
);
2354 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_lo
, psgl
,
2355 io_task
->bhs_pa
.u
.a32
.address_lo
);
2358 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, sge0_last
, pwrb
,
2360 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, sge1_last
, pwrb
,
2362 } else if (num_sg
== 2) {
2363 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, sge0_last
, pwrb
,
2365 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, sge1_last
, pwrb
,
2368 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, sge0_last
, pwrb
,
2370 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, sge1_last
, pwrb
,
2378 for (index
= 0; index
< num_sg
; index
++, sg
= sg_next(sg
), psgl
++) {
2379 sg_len
= sg_dma_len(sg
);
2380 addr
= (u64
) sg_dma_address(sg
);
2381 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_lo
, psgl
,
2382 lower_32_bits(addr
));
2383 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_hi
, psgl
,
2384 upper_32_bits(addr
));
2385 AMAP_SET_BITS(struct amap_iscsi_sge
, len
, psgl
, sg_len
);
2386 AMAP_SET_BITS(struct amap_iscsi_sge
, sge_offset
, psgl
, offset
);
2387 AMAP_SET_BITS(struct amap_iscsi_sge
, last_sge
, psgl
, 0);
2391 AMAP_SET_BITS(struct amap_iscsi_sge
, last_sge
, psgl
, 1);
2395 hwi_write_sgl(struct iscsi_wrb
*pwrb
, struct scatterlist
*sg
,
2396 unsigned int num_sg
, struct beiscsi_io_task
*io_task
)
2398 struct iscsi_sge
*psgl
;
2399 unsigned int sg_len
, index
;
2400 unsigned int sge_len
= 0;
2401 unsigned long long addr
;
2402 struct scatterlist
*l_sg
;
2403 unsigned int offset
;
2405 AMAP_SET_BITS(struct amap_iscsi_wrb
, iscsi_bhs_addr_lo
, pwrb
,
2406 io_task
->bhs_pa
.u
.a32
.address_lo
);
2407 AMAP_SET_BITS(struct amap_iscsi_wrb
, iscsi_bhs_addr_hi
, pwrb
,
2408 io_task
->bhs_pa
.u
.a32
.address_hi
);
2411 for (index
= 0; (index
< num_sg
) && (index
< 2); index
++,
2414 sg_len
= sg_dma_len(sg
);
2415 addr
= (u64
) sg_dma_address(sg
);
2416 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_addr_lo
, pwrb
,
2417 ((u32
)(addr
& 0xFFFFFFFF)));
2418 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_addr_hi
, pwrb
,
2419 ((u32
)(addr
>> 32)));
2420 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_len
, pwrb
,
2424 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge1_r2t_offset
,
2426 sg_len
= sg_dma_len(sg
);
2427 addr
= (u64
) sg_dma_address(sg
);
2428 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge1_addr_lo
, pwrb
,
2429 ((u32
)(addr
& 0xFFFFFFFF)));
2430 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge1_addr_hi
, pwrb
,
2431 ((u32
)(addr
>> 32)));
2432 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge1_len
, pwrb
,
2436 psgl
= (struct iscsi_sge
*)io_task
->psgl_handle
->pfrag
;
2437 memset(psgl
, 0, sizeof(*psgl
) * BE2_SGE
);
2439 AMAP_SET_BITS(struct amap_iscsi_sge
, len
, psgl
, io_task
->bhs_len
- 2);
2441 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_hi
, psgl
,
2442 io_task
->bhs_pa
.u
.a32
.address_hi
);
2443 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_lo
, psgl
,
2444 io_task
->bhs_pa
.u
.a32
.address_lo
);
2447 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_last
, pwrb
,
2449 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge1_last
, pwrb
,
2451 } else if (num_sg
== 2) {
2452 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_last
, pwrb
,
2454 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge1_last
, pwrb
,
2457 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_last
, pwrb
,
2459 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge1_last
, pwrb
,
2466 for (index
= 0; index
< num_sg
; index
++, sg
= sg_next(sg
), psgl
++) {
2467 sg_len
= sg_dma_len(sg
);
2468 addr
= (u64
) sg_dma_address(sg
);
2469 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_lo
, psgl
,
2470 (addr
& 0xFFFFFFFF));
2471 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_hi
, psgl
,
2473 AMAP_SET_BITS(struct amap_iscsi_sge
, len
, psgl
, sg_len
);
2474 AMAP_SET_BITS(struct amap_iscsi_sge
, sge_offset
, psgl
, offset
);
2475 AMAP_SET_BITS(struct amap_iscsi_sge
, last_sge
, psgl
, 0);
2479 AMAP_SET_BITS(struct amap_iscsi_sge
, last_sge
, psgl
, 1);
2483 * hwi_write_buffer()- Populate the WRB with task info
2484 * @pwrb: ptr to the WRB entry
2485 * @task: iscsi task which is to be executed
2487 static void hwi_write_buffer(struct iscsi_wrb
*pwrb
, struct iscsi_task
*task
)
2489 struct iscsi_sge
*psgl
;
2490 struct beiscsi_io_task
*io_task
= task
->dd_data
;
2491 struct beiscsi_conn
*beiscsi_conn
= io_task
->conn
;
2492 struct beiscsi_hba
*phba
= beiscsi_conn
->phba
;
2493 uint8_t dsp_value
= 0;
2495 io_task
->bhs_len
= sizeof(struct be_nonio_bhs
) - 2;
2496 AMAP_SET_BITS(struct amap_iscsi_wrb
, iscsi_bhs_addr_lo
, pwrb
,
2497 io_task
->bhs_pa
.u
.a32
.address_lo
);
2498 AMAP_SET_BITS(struct amap_iscsi_wrb
, iscsi_bhs_addr_hi
, pwrb
,
2499 io_task
->bhs_pa
.u
.a32
.address_hi
);
2503 /* Check for the data_count */
2504 dsp_value
= (task
->data_count
) ? 1 : 0;
2506 if (is_chip_be2_be3r(phba
))
2507 AMAP_SET_BITS(struct amap_iscsi_wrb
, dsp
,
2510 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, dsp
,
2513 /* Map addr only if there is data_count */
2515 io_task
->mtask_addr
= pci_map_single(phba
->pcidev
,
2519 io_task
->mtask_data_count
= task
->data_count
;
2521 io_task
->mtask_addr
= 0;
2523 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_addr_lo
, pwrb
,
2524 lower_32_bits(io_task
->mtask_addr
));
2525 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_addr_hi
, pwrb
,
2526 upper_32_bits(io_task
->mtask_addr
));
2527 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_len
, pwrb
,
2530 AMAP_SET_BITS(struct amap_iscsi_wrb
, sge0_last
, pwrb
, 1);
2532 AMAP_SET_BITS(struct amap_iscsi_wrb
, dsp
, pwrb
, 0);
2533 io_task
->mtask_addr
= 0;
2536 psgl
= (struct iscsi_sge
*)io_task
->psgl_handle
->pfrag
;
2538 AMAP_SET_BITS(struct amap_iscsi_sge
, len
, psgl
, io_task
->bhs_len
);
2540 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_hi
, psgl
,
2541 io_task
->bhs_pa
.u
.a32
.address_hi
);
2542 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_lo
, psgl
,
2543 io_task
->bhs_pa
.u
.a32
.address_lo
);
2546 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_hi
, psgl
, 0);
2547 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_lo
, psgl
, 0);
2548 AMAP_SET_BITS(struct amap_iscsi_sge
, len
, psgl
, 0);
2549 AMAP_SET_BITS(struct amap_iscsi_sge
, sge_offset
, psgl
, 0);
2550 AMAP_SET_BITS(struct amap_iscsi_sge
, rsvd0
, psgl
, 0);
2551 AMAP_SET_BITS(struct amap_iscsi_sge
, last_sge
, psgl
, 0);
2555 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_lo
, psgl
,
2556 lower_32_bits(io_task
->mtask_addr
));
2557 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_hi
, psgl
,
2558 upper_32_bits(io_task
->mtask_addr
));
2560 AMAP_SET_BITS(struct amap_iscsi_sge
, len
, psgl
, 0x106);
2562 AMAP_SET_BITS(struct amap_iscsi_sge
, last_sge
, psgl
, 1);
2566 * beiscsi_find_mem_req()- Find mem needed
2567 * @phba: ptr to HBA struct
2569 static void beiscsi_find_mem_req(struct beiscsi_hba
*phba
)
2571 uint8_t mem_descr_index
, ulp_num
;
2572 unsigned int num_cq_pages
, num_async_pdu_buf_pages
;
2573 unsigned int num_async_pdu_data_pages
, wrb_sz_per_cxn
;
2574 unsigned int num_async_pdu_buf_sgl_pages
, num_async_pdu_data_sgl_pages
;
2576 num_cq_pages
= PAGES_REQUIRED(phba
->params
.num_cq_entries
* \
2577 sizeof(struct sol_cqe
));
2579 phba
->params
.hwi_ws_sz
= sizeof(struct hwi_controller
);
2581 phba
->mem_req
[ISCSI_MEM_GLOBAL_HEADER
] = 2 *
2582 BE_ISCSI_PDU_HEADER_SIZE
;
2583 phba
->mem_req
[HWI_MEM_ADDN_CONTEXT
] =
2584 sizeof(struct hwi_context_memory
);
2587 phba
->mem_req
[HWI_MEM_WRB
] = sizeof(struct iscsi_wrb
)
2588 * (phba
->params
.wrbs_per_cxn
)
2589 * phba
->params
.cxns_per_ctrl
;
2590 wrb_sz_per_cxn
= sizeof(struct wrb_handle
) *
2591 (phba
->params
.wrbs_per_cxn
);
2592 phba
->mem_req
[HWI_MEM_WRBH
] = roundup_pow_of_two((wrb_sz_per_cxn
) *
2593 phba
->params
.cxns_per_ctrl
);
2595 phba
->mem_req
[HWI_MEM_SGLH
] = sizeof(struct sgl_handle
) *
2596 phba
->params
.icds_per_ctrl
;
2597 phba
->mem_req
[HWI_MEM_SGE
] = sizeof(struct iscsi_sge
) *
2598 phba
->params
.num_sge_per_io
* phba
->params
.icds_per_ctrl
;
2599 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++) {
2600 if (test_bit(ulp_num
, &phba
->fw_config
.ulp_supported
)) {
2602 num_async_pdu_buf_sgl_pages
=
2603 PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
2605 sizeof(struct phys_addr
));
2607 num_async_pdu_buf_pages
=
2608 PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
2610 phba
->params
.defpdu_hdr_sz
);
2612 num_async_pdu_data_pages
=
2613 PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
2615 phba
->params
.defpdu_data_sz
);
2617 num_async_pdu_data_sgl_pages
=
2618 PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
2620 sizeof(struct phys_addr
));
2622 mem_descr_index
= (HWI_MEM_TEMPLATE_HDR_ULP0
+
2623 (ulp_num
* MEM_DESCR_OFFSET
));
2624 phba
->mem_req
[mem_descr_index
] =
2625 BEISCSI_GET_CID_COUNT(phba
, ulp_num
) *
2626 BEISCSI_TEMPLATE_HDR_PER_CXN_SIZE
;
2628 mem_descr_index
= (HWI_MEM_ASYNC_HEADER_BUF_ULP0
+
2629 (ulp_num
* MEM_DESCR_OFFSET
));
2630 phba
->mem_req
[mem_descr_index
] =
2631 num_async_pdu_buf_pages
*
2634 mem_descr_index
= (HWI_MEM_ASYNC_DATA_BUF_ULP0
+
2635 (ulp_num
* MEM_DESCR_OFFSET
));
2636 phba
->mem_req
[mem_descr_index
] =
2637 num_async_pdu_data_pages
*
2640 mem_descr_index
= (HWI_MEM_ASYNC_HEADER_RING_ULP0
+
2641 (ulp_num
* MEM_DESCR_OFFSET
));
2642 phba
->mem_req
[mem_descr_index
] =
2643 num_async_pdu_buf_sgl_pages
*
2646 mem_descr_index
= (HWI_MEM_ASYNC_DATA_RING_ULP0
+
2647 (ulp_num
* MEM_DESCR_OFFSET
));
2648 phba
->mem_req
[mem_descr_index
] =
2649 num_async_pdu_data_sgl_pages
*
2652 mem_descr_index
= (HWI_MEM_ASYNC_HEADER_HANDLE_ULP0
+
2653 (ulp_num
* MEM_DESCR_OFFSET
));
2654 phba
->mem_req
[mem_descr_index
] =
2655 BEISCSI_GET_CID_COUNT(phba
, ulp_num
) *
2656 sizeof(struct async_pdu_handle
);
2658 mem_descr_index
= (HWI_MEM_ASYNC_DATA_HANDLE_ULP0
+
2659 (ulp_num
* MEM_DESCR_OFFSET
));
2660 phba
->mem_req
[mem_descr_index
] =
2661 BEISCSI_GET_CID_COUNT(phba
, ulp_num
) *
2662 sizeof(struct async_pdu_handle
);
2664 mem_descr_index
= (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0
+
2665 (ulp_num
* MEM_DESCR_OFFSET
));
2666 phba
->mem_req
[mem_descr_index
] =
2667 sizeof(struct hwi_async_pdu_context
) +
2668 (BEISCSI_GET_CID_COUNT(phba
, ulp_num
) *
2669 sizeof(struct hwi_async_entry
));
2674 static int beiscsi_alloc_mem(struct beiscsi_hba
*phba
)
2677 struct hwi_controller
*phwi_ctrlr
;
2678 struct be_mem_descriptor
*mem_descr
;
2679 struct mem_array
*mem_arr
, *mem_arr_orig
;
2680 unsigned int i
, j
, alloc_size
, curr_alloc_size
;
2682 phba
->phwi_ctrlr
= kzalloc(phba
->params
.hwi_ws_sz
, GFP_KERNEL
);
2683 if (!phba
->phwi_ctrlr
)
2686 /* Allocate memory for wrb_context */
2687 phwi_ctrlr
= phba
->phwi_ctrlr
;
2688 phwi_ctrlr
->wrb_context
= kzalloc(sizeof(struct hwi_wrb_context
) *
2689 phba
->params
.cxns_per_ctrl
,
2691 if (!phwi_ctrlr
->wrb_context
)
2694 phba
->init_mem
= kcalloc(SE_MEM_MAX
, sizeof(*mem_descr
),
2696 if (!phba
->init_mem
) {
2697 kfree(phwi_ctrlr
->wrb_context
);
2698 kfree(phba
->phwi_ctrlr
);
2702 mem_arr_orig
= kmalloc(sizeof(*mem_arr_orig
) * BEISCSI_MAX_FRAGS_INIT
,
2704 if (!mem_arr_orig
) {
2705 kfree(phba
->init_mem
);
2706 kfree(phwi_ctrlr
->wrb_context
);
2707 kfree(phba
->phwi_ctrlr
);
2711 mem_descr
= phba
->init_mem
;
2712 for (i
= 0; i
< SE_MEM_MAX
; i
++) {
2713 if (!phba
->mem_req
[i
]) {
2714 mem_descr
->mem_array
= NULL
;
2720 mem_arr
= mem_arr_orig
;
2721 alloc_size
= phba
->mem_req
[i
];
2722 memset(mem_arr
, 0, sizeof(struct mem_array
) *
2723 BEISCSI_MAX_FRAGS_INIT
);
2724 curr_alloc_size
= min(be_max_phys_size
* 1024, alloc_size
);
2726 mem_arr
->virtual_address
= pci_alloc_consistent(
2730 if (!mem_arr
->virtual_address
) {
2731 if (curr_alloc_size
<= BE_MIN_MEM_SIZE
)
2733 if (curr_alloc_size
-
2734 rounddown_pow_of_two(curr_alloc_size
))
2735 curr_alloc_size
= rounddown_pow_of_two
2738 curr_alloc_size
= curr_alloc_size
/ 2;
2740 mem_arr
->bus_address
.u
.
2741 a64
.address
= (__u64
) bus_add
;
2742 mem_arr
->size
= curr_alloc_size
;
2743 alloc_size
-= curr_alloc_size
;
2744 curr_alloc_size
= min(be_max_phys_size
*
2749 } while (alloc_size
);
2750 mem_descr
->num_elements
= j
;
2751 mem_descr
->size_in_bytes
= phba
->mem_req
[i
];
2752 mem_descr
->mem_array
= kmalloc(sizeof(*mem_arr
) * j
,
2754 if (!mem_descr
->mem_array
)
2757 memcpy(mem_descr
->mem_array
, mem_arr_orig
,
2758 sizeof(struct mem_array
) * j
);
2761 kfree(mem_arr_orig
);
2764 mem_descr
->num_elements
= j
;
2765 while ((i
) || (j
)) {
2766 for (j
= mem_descr
->num_elements
; j
> 0; j
--) {
2767 pci_free_consistent(phba
->pcidev
,
2768 mem_descr
->mem_array
[j
- 1].size
,
2769 mem_descr
->mem_array
[j
- 1].
2771 (unsigned long)mem_descr
->
2773 bus_address
.u
.a64
.address
);
2777 kfree(mem_descr
->mem_array
);
2781 kfree(mem_arr_orig
);
2782 kfree(phba
->init_mem
);
2783 kfree(phba
->phwi_ctrlr
->wrb_context
);
2784 kfree(phba
->phwi_ctrlr
);
2788 static int beiscsi_get_memory(struct beiscsi_hba
*phba
)
2790 beiscsi_find_mem_req(phba
);
2791 return beiscsi_alloc_mem(phba
);
2794 static void iscsi_init_global_templates(struct beiscsi_hba
*phba
)
2796 struct pdu_data_out
*pdata_out
;
2797 struct pdu_nop_out
*pnop_out
;
2798 struct be_mem_descriptor
*mem_descr
;
2800 mem_descr
= phba
->init_mem
;
2801 mem_descr
+= ISCSI_MEM_GLOBAL_HEADER
;
2803 (struct pdu_data_out
*)mem_descr
->mem_array
[0].virtual_address
;
2804 memset(pdata_out
, 0, BE_ISCSI_PDU_HEADER_SIZE
);
2806 AMAP_SET_BITS(struct amap_pdu_data_out
, opcode
, pdata_out
,
2810 (struct pdu_nop_out
*)((unsigned char *)mem_descr
->mem_array
[0].
2811 virtual_address
+ BE_ISCSI_PDU_HEADER_SIZE
);
2813 memset(pnop_out
, 0, BE_ISCSI_PDU_HEADER_SIZE
);
2814 AMAP_SET_BITS(struct amap_pdu_nop_out
, ttt
, pnop_out
, 0xFFFFFFFF);
2815 AMAP_SET_BITS(struct amap_pdu_nop_out
, f_bit
, pnop_out
, 1);
2816 AMAP_SET_BITS(struct amap_pdu_nop_out
, i_bit
, pnop_out
, 0);
2819 static int beiscsi_init_wrb_handle(struct beiscsi_hba
*phba
)
2821 struct be_mem_descriptor
*mem_descr_wrbh
, *mem_descr_wrb
;
2822 struct hwi_context_memory
*phwi_ctxt
;
2823 struct wrb_handle
*pwrb_handle
= NULL
;
2824 struct hwi_controller
*phwi_ctrlr
;
2825 struct hwi_wrb_context
*pwrb_context
;
2826 struct iscsi_wrb
*pwrb
= NULL
;
2827 unsigned int num_cxn_wrbh
= 0;
2828 unsigned int num_cxn_wrb
= 0, j
, idx
= 0, index
;
2830 mem_descr_wrbh
= phba
->init_mem
;
2831 mem_descr_wrbh
+= HWI_MEM_WRBH
;
2833 mem_descr_wrb
= phba
->init_mem
;
2834 mem_descr_wrb
+= HWI_MEM_WRB
;
2835 phwi_ctrlr
= phba
->phwi_ctrlr
;
2837 /* Allocate memory for WRBQ */
2838 phwi_ctxt
= phwi_ctrlr
->phwi_ctxt
;
2839 phwi_ctxt
->be_wrbq
= kzalloc(sizeof(struct be_queue_info
) *
2840 phba
->params
.cxns_per_ctrl
,
2842 if (!phwi_ctxt
->be_wrbq
) {
2843 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
2844 "BM_%d : WRBQ Mem Alloc Failed\n");
2848 for (index
= 0; index
< phba
->params
.cxns_per_ctrl
; index
++) {
2849 pwrb_context
= &phwi_ctrlr
->wrb_context
[index
];
2850 pwrb_context
->pwrb_handle_base
=
2851 kzalloc(sizeof(struct wrb_handle
*) *
2852 phba
->params
.wrbs_per_cxn
, GFP_KERNEL
);
2853 if (!pwrb_context
->pwrb_handle_base
) {
2854 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
2855 "BM_%d : Mem Alloc Failed. Failing to load\n");
2856 goto init_wrb_hndl_failed
;
2858 pwrb_context
->pwrb_handle_basestd
=
2859 kzalloc(sizeof(struct wrb_handle
*) *
2860 phba
->params
.wrbs_per_cxn
, GFP_KERNEL
);
2861 if (!pwrb_context
->pwrb_handle_basestd
) {
2862 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
2863 "BM_%d : Mem Alloc Failed. Failing to load\n");
2864 goto init_wrb_hndl_failed
;
2866 if (!num_cxn_wrbh
) {
2868 mem_descr_wrbh
->mem_array
[idx
].virtual_address
;
2869 num_cxn_wrbh
= ((mem_descr_wrbh
->mem_array
[idx
].size
) /
2870 ((sizeof(struct wrb_handle
)) *
2871 phba
->params
.wrbs_per_cxn
));
2874 pwrb_context
->alloc_index
= 0;
2875 pwrb_context
->wrb_handles_available
= 0;
2876 pwrb_context
->free_index
= 0;
2879 for (j
= 0; j
< phba
->params
.wrbs_per_cxn
; j
++) {
2880 pwrb_context
->pwrb_handle_base
[j
] = pwrb_handle
;
2881 pwrb_context
->pwrb_handle_basestd
[j
] =
2883 pwrb_context
->wrb_handles_available
++;
2884 pwrb_handle
->wrb_index
= j
;
2891 for (index
= 0; index
< phba
->params
.cxns_per_ctrl
; index
++) {
2892 pwrb_context
= &phwi_ctrlr
->wrb_context
[index
];
2894 pwrb
= mem_descr_wrb
->mem_array
[idx
].virtual_address
;
2895 num_cxn_wrb
= (mem_descr_wrb
->mem_array
[idx
].size
) /
2896 ((sizeof(struct iscsi_wrb
) *
2897 phba
->params
.wrbs_per_cxn
));
2902 for (j
= 0; j
< phba
->params
.wrbs_per_cxn
; j
++) {
2903 pwrb_handle
= pwrb_context
->pwrb_handle_base
[j
];
2904 pwrb_handle
->pwrb
= pwrb
;
2911 init_wrb_hndl_failed
:
2912 for (j
= index
; j
> 0; j
--) {
2913 pwrb_context
= &phwi_ctrlr
->wrb_context
[j
];
2914 kfree(pwrb_context
->pwrb_handle_base
);
2915 kfree(pwrb_context
->pwrb_handle_basestd
);
2920 static int hwi_init_async_pdu_ctx(struct beiscsi_hba
*phba
)
2923 struct hwi_controller
*phwi_ctrlr
;
2924 struct hba_parameters
*p
= &phba
->params
;
2925 struct hwi_async_pdu_context
*pasync_ctx
;
2926 struct async_pdu_handle
*pasync_header_h
, *pasync_data_h
;
2927 unsigned int index
, idx
, num_per_mem
, num_async_data
;
2928 struct be_mem_descriptor
*mem_descr
;
2930 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++) {
2931 if (test_bit(ulp_num
, &phba
->fw_config
.ulp_supported
)) {
2933 mem_descr
= (struct be_mem_descriptor
*)phba
->init_mem
;
2934 mem_descr
+= (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0
+
2935 (ulp_num
* MEM_DESCR_OFFSET
));
2937 phwi_ctrlr
= phba
->phwi_ctrlr
;
2938 phwi_ctrlr
->phwi_ctxt
->pasync_ctx
[ulp_num
] =
2939 (struct hwi_async_pdu_context
*)
2940 mem_descr
->mem_array
[0].virtual_address
;
2942 pasync_ctx
= phwi_ctrlr
->phwi_ctxt
->pasync_ctx
[ulp_num
];
2943 memset(pasync_ctx
, 0, sizeof(*pasync_ctx
));
2945 pasync_ctx
->async_entry
=
2946 (struct hwi_async_entry
*)
2947 ((long unsigned int)pasync_ctx
+
2948 sizeof(struct hwi_async_pdu_context
));
2950 pasync_ctx
->num_entries
= BEISCSI_GET_CID_COUNT(phba
,
2952 pasync_ctx
->buffer_size
= p
->defpdu_hdr_sz
;
2954 mem_descr
= (struct be_mem_descriptor
*)phba
->init_mem
;
2955 mem_descr
+= HWI_MEM_ASYNC_HEADER_BUF_ULP0
+
2956 (ulp_num
* MEM_DESCR_OFFSET
);
2957 if (mem_descr
->mem_array
[0].virtual_address
) {
2958 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
2959 "BM_%d : hwi_init_async_pdu_ctx"
2960 " HWI_MEM_ASYNC_HEADER_BUF_ULP%d va=%p\n",
2962 mem_descr
->mem_array
[0].
2965 beiscsi_log(phba
, KERN_WARNING
,
2967 "BM_%d : No Virtual address for ULP : %d\n",
2970 pasync_ctx
->async_header
.va_base
=
2971 mem_descr
->mem_array
[0].virtual_address
;
2973 pasync_ctx
->async_header
.pa_base
.u
.a64
.address
=
2974 mem_descr
->mem_array
[0].
2975 bus_address
.u
.a64
.address
;
2977 mem_descr
= (struct be_mem_descriptor
*)phba
->init_mem
;
2978 mem_descr
+= HWI_MEM_ASYNC_HEADER_RING_ULP0
+
2979 (ulp_num
* MEM_DESCR_OFFSET
);
2980 if (mem_descr
->mem_array
[0].virtual_address
) {
2981 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
2982 "BM_%d : hwi_init_async_pdu_ctx"
2983 " HWI_MEM_ASYNC_HEADER_RING_ULP%d va=%p\n",
2985 mem_descr
->mem_array
[0].
2988 beiscsi_log(phba
, KERN_WARNING
,
2990 "BM_%d : No Virtual address for ULP : %d\n",
2993 pasync_ctx
->async_header
.ring_base
=
2994 mem_descr
->mem_array
[0].virtual_address
;
2996 mem_descr
= (struct be_mem_descriptor
*)phba
->init_mem
;
2997 mem_descr
+= HWI_MEM_ASYNC_HEADER_HANDLE_ULP0
+
2998 (ulp_num
* MEM_DESCR_OFFSET
);
2999 if (mem_descr
->mem_array
[0].virtual_address
) {
3000 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
3001 "BM_%d : hwi_init_async_pdu_ctx"
3002 " HWI_MEM_ASYNC_HEADER_HANDLE_ULP%d va=%p\n",
3004 mem_descr
->mem_array
[0].
3007 beiscsi_log(phba
, KERN_WARNING
,
3009 "BM_%d : No Virtual address for ULP : %d\n",
3012 pasync_ctx
->async_header
.handle_base
=
3013 mem_descr
->mem_array
[0].virtual_address
;
3014 pasync_ctx
->async_header
.writables
= 0;
3015 INIT_LIST_HEAD(&pasync_ctx
->async_header
.free_list
);
3017 mem_descr
= (struct be_mem_descriptor
*)phba
->init_mem
;
3018 mem_descr
+= HWI_MEM_ASYNC_DATA_RING_ULP0
+
3019 (ulp_num
* MEM_DESCR_OFFSET
);
3020 if (mem_descr
->mem_array
[0].virtual_address
) {
3021 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
3022 "BM_%d : hwi_init_async_pdu_ctx"
3023 " HWI_MEM_ASYNC_DATA_RING_ULP%d va=%p\n",
3025 mem_descr
->mem_array
[0].
3028 beiscsi_log(phba
, KERN_WARNING
,
3030 "BM_%d : No Virtual address for ULP : %d\n",
3033 pasync_ctx
->async_data
.ring_base
=
3034 mem_descr
->mem_array
[0].virtual_address
;
3036 mem_descr
= (struct be_mem_descriptor
*)phba
->init_mem
;
3037 mem_descr
+= HWI_MEM_ASYNC_DATA_HANDLE_ULP0
+
3038 (ulp_num
* MEM_DESCR_OFFSET
);
3039 if (!mem_descr
->mem_array
[0].virtual_address
)
3040 beiscsi_log(phba
, KERN_WARNING
,
3042 "BM_%d : No Virtual address for ULP : %d\n",
3045 pasync_ctx
->async_data
.handle_base
=
3046 mem_descr
->mem_array
[0].virtual_address
;
3047 pasync_ctx
->async_data
.writables
= 0;
3048 INIT_LIST_HEAD(&pasync_ctx
->async_data
.free_list
);
3051 (struct async_pdu_handle
*)
3052 pasync_ctx
->async_header
.handle_base
;
3054 (struct async_pdu_handle
*)
3055 pasync_ctx
->async_data
.handle_base
;
3057 mem_descr
= (struct be_mem_descriptor
*)phba
->init_mem
;
3058 mem_descr
+= HWI_MEM_ASYNC_DATA_BUF_ULP0
+
3059 (ulp_num
* MEM_DESCR_OFFSET
);
3060 if (mem_descr
->mem_array
[0].virtual_address
) {
3061 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
3062 "BM_%d : hwi_init_async_pdu_ctx"
3063 " HWI_MEM_ASYNC_DATA_BUF_ULP%d va=%p\n",
3065 mem_descr
->mem_array
[0].
3068 beiscsi_log(phba
, KERN_WARNING
,
3070 "BM_%d : No Virtual address for ULP : %d\n",
3074 pasync_ctx
->async_data
.va_base
=
3075 mem_descr
->mem_array
[idx
].virtual_address
;
3076 pasync_ctx
->async_data
.pa_base
.u
.a64
.address
=
3077 mem_descr
->mem_array
[idx
].
3078 bus_address
.u
.a64
.address
;
3080 num_async_data
= ((mem_descr
->mem_array
[idx
].size
) /
3081 phba
->params
.defpdu_data_sz
);
3084 for (index
= 0; index
< BEISCSI_GET_CID_COUNT
3085 (phba
, ulp_num
); index
++) {
3086 pasync_header_h
->cri
= -1;
3087 pasync_header_h
->index
= (char)index
;
3088 INIT_LIST_HEAD(&pasync_header_h
->link
);
3089 pasync_header_h
->pbuffer
=
3090 (void *)((unsigned long)
3092 async_header
.va_base
) +
3093 (p
->defpdu_hdr_sz
* index
));
3095 pasync_header_h
->pa
.u
.a64
.address
=
3096 pasync_ctx
->async_header
.pa_base
.u
.a64
.
3097 address
+ (p
->defpdu_hdr_sz
* index
);
3099 list_add_tail(&pasync_header_h
->link
,
3100 &pasync_ctx
->async_header
.
3103 pasync_ctx
->async_header
.free_entries
++;
3104 pasync_ctx
->async_header
.writables
++;
3106 INIT_LIST_HEAD(&pasync_ctx
->async_entry
[index
].
3108 INIT_LIST_HEAD(&pasync_ctx
->async_entry
[index
].
3110 pasync_data_h
->cri
= -1;
3111 pasync_data_h
->index
= (char)index
;
3112 INIT_LIST_HEAD(&pasync_data_h
->link
);
3114 if (!num_async_data
) {
3117 pasync_ctx
->async_data
.va_base
=
3118 mem_descr
->mem_array
[idx
].
3120 pasync_ctx
->async_data
.pa_base
.u
.
3122 mem_descr
->mem_array
[idx
].
3123 bus_address
.u
.a64
.address
;
3125 ((mem_descr
->mem_array
[idx
].
3127 phba
->params
.defpdu_data_sz
);
3129 pasync_data_h
->pbuffer
=
3130 (void *)((unsigned long)
3131 (pasync_ctx
->async_data
.va_base
) +
3132 (p
->defpdu_data_sz
* num_per_mem
));
3134 pasync_data_h
->pa
.u
.a64
.address
=
3135 pasync_ctx
->async_data
.pa_base
.u
.a64
.
3136 address
+ (p
->defpdu_data_sz
*
3141 list_add_tail(&pasync_data_h
->link
,
3142 &pasync_ctx
->async_data
.
3145 pasync_ctx
->async_data
.free_entries
++;
3146 pasync_ctx
->async_data
.writables
++;
3148 INIT_LIST_HEAD(&pasync_ctx
->async_entry
[index
].
3152 pasync_ctx
->async_header
.host_write_ptr
= 0;
3153 pasync_ctx
->async_header
.ep_read_ptr
= -1;
3154 pasync_ctx
->async_data
.host_write_ptr
= 0;
3155 pasync_ctx
->async_data
.ep_read_ptr
= -1;
3163 be_sgl_create_contiguous(void *virtual_address
,
3164 u64 physical_address
, u32 length
,
3165 struct be_dma_mem
*sgl
)
3167 WARN_ON(!virtual_address
);
3168 WARN_ON(!physical_address
);
3169 WARN_ON(!length
> 0);
3172 sgl
->va
= virtual_address
;
3173 sgl
->dma
= (unsigned long)physical_address
;
3179 static void be_sgl_destroy_contiguous(struct be_dma_mem
*sgl
)
3181 memset(sgl
, 0, sizeof(*sgl
));
3185 hwi_build_be_sgl_arr(struct beiscsi_hba
*phba
,
3186 struct mem_array
*pmem
, struct be_dma_mem
*sgl
)
3189 be_sgl_destroy_contiguous(sgl
);
3191 be_sgl_create_contiguous(pmem
->virtual_address
,
3192 pmem
->bus_address
.u
.a64
.address
,
3197 hwi_build_be_sgl_by_offset(struct beiscsi_hba
*phba
,
3198 struct mem_array
*pmem
, struct be_dma_mem
*sgl
)
3201 be_sgl_destroy_contiguous(sgl
);
3203 be_sgl_create_contiguous((unsigned char *)pmem
->virtual_address
,
3204 pmem
->bus_address
.u
.a64
.address
,
3208 static int be_fill_queue(struct be_queue_info
*q
,
3209 u16 len
, u16 entry_size
, void *vaddress
)
3211 struct be_dma_mem
*mem
= &q
->dma_mem
;
3213 memset(q
, 0, sizeof(*q
));
3215 q
->entry_size
= entry_size
;
3216 mem
->size
= len
* entry_size
;
3220 memset(mem
->va
, 0, mem
->size
);
3224 static int beiscsi_create_eqs(struct beiscsi_hba
*phba
,
3225 struct hwi_context_memory
*phwi_context
)
3227 unsigned int i
, num_eq_pages
;
3228 int ret
= 0, eq_for_mcc
;
3229 struct be_queue_info
*eq
;
3230 struct be_dma_mem
*mem
;
3234 num_eq_pages
= PAGES_REQUIRED(phba
->params
.num_eq_entries
* \
3235 sizeof(struct be_eq_entry
));
3237 if (phba
->msix_enabled
)
3241 for (i
= 0; i
< (phba
->num_cpus
+ eq_for_mcc
); i
++) {
3242 eq
= &phwi_context
->be_eq
[i
].q
;
3244 phwi_context
->be_eq
[i
].phba
= phba
;
3245 eq_vaddress
= pci_alloc_consistent(phba
->pcidev
,
3246 num_eq_pages
* PAGE_SIZE
,
3249 goto create_eq_error
;
3251 mem
->va
= eq_vaddress
;
3252 ret
= be_fill_queue(eq
, phba
->params
.num_eq_entries
,
3253 sizeof(struct be_eq_entry
), eq_vaddress
);
3255 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3256 "BM_%d : be_fill_queue Failed for EQ\n");
3257 goto create_eq_error
;
3261 ret
= beiscsi_cmd_eq_create(&phba
->ctrl
, eq
,
3262 phwi_context
->cur_eqd
);
3264 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3265 "BM_%d : beiscsi_cmd_eq_create"
3267 goto create_eq_error
;
3270 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
3271 "BM_%d : eqid = %d\n",
3272 phwi_context
->be_eq
[i
].q
.id
);
3276 for (i
= 0; i
< (phba
->num_cpus
+ eq_for_mcc
); i
++) {
3277 eq
= &phwi_context
->be_eq
[i
].q
;
3280 pci_free_consistent(phba
->pcidev
, num_eq_pages
3287 static int beiscsi_create_cqs(struct beiscsi_hba
*phba
,
3288 struct hwi_context_memory
*phwi_context
)
3290 unsigned int i
, num_cq_pages
;
3292 struct be_queue_info
*cq
, *eq
;
3293 struct be_dma_mem
*mem
;
3294 struct be_eq_obj
*pbe_eq
;
3298 num_cq_pages
= PAGES_REQUIRED(phba
->params
.num_cq_entries
* \
3299 sizeof(struct sol_cqe
));
3301 for (i
= 0; i
< phba
->num_cpus
; i
++) {
3302 cq
= &phwi_context
->be_cq
[i
];
3303 eq
= &phwi_context
->be_eq
[i
].q
;
3304 pbe_eq
= &phwi_context
->be_eq
[i
];
3306 pbe_eq
->phba
= phba
;
3308 cq_vaddress
= pci_alloc_consistent(phba
->pcidev
,
3309 num_cq_pages
* PAGE_SIZE
,
3312 goto create_cq_error
;
3313 ret
= be_fill_queue(cq
, phba
->params
.num_cq_entries
,
3314 sizeof(struct sol_cqe
), cq_vaddress
);
3316 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3317 "BM_%d : be_fill_queue Failed "
3319 goto create_cq_error
;
3323 ret
= beiscsi_cmd_cq_create(&phba
->ctrl
, cq
, eq
, false,
3326 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3327 "BM_%d : beiscsi_cmd_eq_create"
3328 "Failed for ISCSI CQ\n");
3329 goto create_cq_error
;
3331 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
3332 "BM_%d : iscsi cq_id is %d for eq_id %d\n"
3333 "iSCSI CQ CREATED\n", cq
->id
, eq
->id
);
3338 for (i
= 0; i
< phba
->num_cpus
; i
++) {
3339 cq
= &phwi_context
->be_cq
[i
];
3342 pci_free_consistent(phba
->pcidev
, num_cq_pages
3351 beiscsi_create_def_hdr(struct beiscsi_hba
*phba
,
3352 struct hwi_context_memory
*phwi_context
,
3353 struct hwi_controller
*phwi_ctrlr
,
3354 unsigned int def_pdu_ring_sz
, uint8_t ulp_num
)
3358 struct be_queue_info
*dq
, *cq
;
3359 struct be_dma_mem
*mem
;
3360 struct be_mem_descriptor
*mem_descr
;
3364 dq
= &phwi_context
->be_def_hdrq
[ulp_num
];
3365 cq
= &phwi_context
->be_cq
[0];
3367 mem_descr
= phba
->init_mem
;
3368 mem_descr
+= HWI_MEM_ASYNC_HEADER_RING_ULP0
+
3369 (ulp_num
* MEM_DESCR_OFFSET
);
3370 dq_vaddress
= mem_descr
->mem_array
[idx
].virtual_address
;
3371 ret
= be_fill_queue(dq
, mem_descr
->mem_array
[0].size
/
3372 sizeof(struct phys_addr
),
3373 sizeof(struct phys_addr
), dq_vaddress
);
3375 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3376 "BM_%d : be_fill_queue Failed for DEF PDU HDR on ULP : %d\n",
3381 mem
->dma
= (unsigned long)mem_descr
->mem_array
[idx
].
3382 bus_address
.u
.a64
.address
;
3383 ret
= be_cmd_create_default_pdu_queue(&phba
->ctrl
, cq
, dq
,
3385 phba
->params
.defpdu_hdr_sz
,
3386 BEISCSI_DEFQ_HDR
, ulp_num
);
3388 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3389 "BM_%d : be_cmd_create_default_pdu_queue Failed DEFHDR on ULP : %d\n",
3395 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
3396 "BM_%d : iscsi hdr def pdu id for ULP : %d is %d\n",
3398 phwi_context
->be_def_hdrq
[ulp_num
].id
);
3399 hwi_post_async_buffers(phba
, BEISCSI_DEFQ_HDR
, ulp_num
);
3404 beiscsi_create_def_data(struct beiscsi_hba
*phba
,
3405 struct hwi_context_memory
*phwi_context
,
3406 struct hwi_controller
*phwi_ctrlr
,
3407 unsigned int def_pdu_ring_sz
, uint8_t ulp_num
)
3411 struct be_queue_info
*dataq
, *cq
;
3412 struct be_dma_mem
*mem
;
3413 struct be_mem_descriptor
*mem_descr
;
3417 dataq
= &phwi_context
->be_def_dataq
[ulp_num
];
3418 cq
= &phwi_context
->be_cq
[0];
3419 mem
= &dataq
->dma_mem
;
3420 mem_descr
= phba
->init_mem
;
3421 mem_descr
+= HWI_MEM_ASYNC_DATA_RING_ULP0
+
3422 (ulp_num
* MEM_DESCR_OFFSET
);
3423 dq_vaddress
= mem_descr
->mem_array
[idx
].virtual_address
;
3424 ret
= be_fill_queue(dataq
, mem_descr
->mem_array
[0].size
/
3425 sizeof(struct phys_addr
),
3426 sizeof(struct phys_addr
), dq_vaddress
);
3428 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3429 "BM_%d : be_fill_queue Failed for DEF PDU "
3430 "DATA on ULP : %d\n",
3435 mem
->dma
= (unsigned long)mem_descr
->mem_array
[idx
].
3436 bus_address
.u
.a64
.address
;
3437 ret
= be_cmd_create_default_pdu_queue(&phba
->ctrl
, cq
, dataq
,
3439 phba
->params
.defpdu_data_sz
,
3440 BEISCSI_DEFQ_DATA
, ulp_num
);
3442 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3443 "BM_%d be_cmd_create_default_pdu_queue"
3444 " Failed for DEF PDU DATA on ULP : %d\n",
3449 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
3450 "BM_%d : iscsi def data id on ULP : %d is %d\n",
3452 phwi_context
->be_def_dataq
[ulp_num
].id
);
3454 hwi_post_async_buffers(phba
, BEISCSI_DEFQ_DATA
, ulp_num
);
3455 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
3456 "BM_%d : DEFAULT PDU DATA RING CREATED"
3457 "on ULP : %d\n", ulp_num
);
3464 beiscsi_post_template_hdr(struct beiscsi_hba
*phba
)
3466 struct be_mem_descriptor
*mem_descr
;
3467 struct mem_array
*pm_arr
;
3468 struct be_dma_mem sgl
;
3469 int status
, ulp_num
;
3471 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++) {
3472 if (test_bit(ulp_num
, &phba
->fw_config
.ulp_supported
)) {
3473 mem_descr
= (struct be_mem_descriptor
*)phba
->init_mem
;
3474 mem_descr
+= HWI_MEM_TEMPLATE_HDR_ULP0
+
3475 (ulp_num
* MEM_DESCR_OFFSET
);
3476 pm_arr
= mem_descr
->mem_array
;
3478 hwi_build_be_sgl_arr(phba
, pm_arr
, &sgl
);
3479 status
= be_cmd_iscsi_post_template_hdr(
3483 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3484 "BM_%d : Post Template HDR Failed for"
3485 "ULP_%d\n", ulp_num
);
3489 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
3490 "BM_%d : Template HDR Pages Posted for"
3491 "ULP_%d\n", ulp_num
);
3498 beiscsi_post_pages(struct beiscsi_hba
*phba
)
3500 struct be_mem_descriptor
*mem_descr
;
3501 struct mem_array
*pm_arr
;
3502 unsigned int page_offset
, i
;
3503 struct be_dma_mem sgl
;
3504 int status
, ulp_num
= 0;
3506 mem_descr
= phba
->init_mem
;
3507 mem_descr
+= HWI_MEM_SGE
;
3508 pm_arr
= mem_descr
->mem_array
;
3510 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++)
3511 if (test_bit(ulp_num
, &phba
->fw_config
.ulp_supported
))
3514 page_offset
= (sizeof(struct iscsi_sge
) * phba
->params
.num_sge_per_io
*
3515 phba
->fw_config
.iscsi_icd_start
[ulp_num
]) / PAGE_SIZE
;
3516 for (i
= 0; i
< mem_descr
->num_elements
; i
++) {
3517 hwi_build_be_sgl_arr(phba
, pm_arr
, &sgl
);
3518 status
= be_cmd_iscsi_post_sgl_pages(&phba
->ctrl
, &sgl
,
3520 (pm_arr
->size
/ PAGE_SIZE
));
3521 page_offset
+= pm_arr
->size
/ PAGE_SIZE
;
3523 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3524 "BM_%d : post sgl failed.\n");
3529 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
3530 "BM_%d : POSTED PAGES\n");
3534 static void be_queue_free(struct beiscsi_hba
*phba
, struct be_queue_info
*q
)
3536 struct be_dma_mem
*mem
= &q
->dma_mem
;
3538 pci_free_consistent(phba
->pcidev
, mem
->size
,
3544 static int be_queue_alloc(struct beiscsi_hba
*phba
, struct be_queue_info
*q
,
3545 u16 len
, u16 entry_size
)
3547 struct be_dma_mem
*mem
= &q
->dma_mem
;
3549 memset(q
, 0, sizeof(*q
));
3551 q
->entry_size
= entry_size
;
3552 mem
->size
= len
* entry_size
;
3553 mem
->va
= pci_zalloc_consistent(phba
->pcidev
, mem
->size
, &mem
->dma
);
3560 beiscsi_create_wrb_rings(struct beiscsi_hba
*phba
,
3561 struct hwi_context_memory
*phwi_context
,
3562 struct hwi_controller
*phwi_ctrlr
)
3564 unsigned int wrb_mem_index
, offset
, size
, num_wrb_rings
;
3566 unsigned int idx
, num
, i
, ulp_num
;
3567 struct mem_array
*pwrb_arr
;
3569 struct be_dma_mem sgl
;
3570 struct be_mem_descriptor
*mem_descr
;
3571 struct hwi_wrb_context
*pwrb_context
;
3573 uint8_t ulp_count
= 0, ulp_base_num
= 0;
3574 uint16_t cid_count_ulp
[BEISCSI_ULP_COUNT
] = { 0 };
3577 mem_descr
= phba
->init_mem
;
3578 mem_descr
+= HWI_MEM_WRB
;
3579 pwrb_arr
= kmalloc(sizeof(*pwrb_arr
) * phba
->params
.cxns_per_ctrl
,
3582 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3583 "BM_%d : Memory alloc failed in create wrb ring.\n");
3586 wrb_vaddr
= mem_descr
->mem_array
[idx
].virtual_address
;
3587 pa_addr_lo
= mem_descr
->mem_array
[idx
].bus_address
.u
.a64
.address
;
3588 num_wrb_rings
= mem_descr
->mem_array
[idx
].size
/
3589 (phba
->params
.wrbs_per_cxn
* sizeof(struct iscsi_wrb
));
3591 for (num
= 0; num
< phba
->params
.cxns_per_ctrl
; num
++) {
3592 if (num_wrb_rings
) {
3593 pwrb_arr
[num
].virtual_address
= wrb_vaddr
;
3594 pwrb_arr
[num
].bus_address
.u
.a64
.address
= pa_addr_lo
;
3595 pwrb_arr
[num
].size
= phba
->params
.wrbs_per_cxn
*
3596 sizeof(struct iscsi_wrb
);
3597 wrb_vaddr
+= pwrb_arr
[num
].size
;
3598 pa_addr_lo
+= pwrb_arr
[num
].size
;
3602 wrb_vaddr
= mem_descr
->mem_array
[idx
].virtual_address
;
3603 pa_addr_lo
= mem_descr
->mem_array
[idx
].\
3604 bus_address
.u
.a64
.address
;
3605 num_wrb_rings
= mem_descr
->mem_array
[idx
].size
/
3606 (phba
->params
.wrbs_per_cxn
*
3607 sizeof(struct iscsi_wrb
));
3608 pwrb_arr
[num
].virtual_address
= wrb_vaddr
;
3609 pwrb_arr
[num
].bus_address
.u
.a64
.address\
3611 pwrb_arr
[num
].size
= phba
->params
.wrbs_per_cxn
*
3612 sizeof(struct iscsi_wrb
);
3613 wrb_vaddr
+= pwrb_arr
[num
].size
;
3614 pa_addr_lo
+= pwrb_arr
[num
].size
;
3619 /* Get the ULP Count */
3620 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++)
3621 if (test_bit(ulp_num
, &phba
->fw_config
.ulp_supported
)) {
3623 ulp_base_num
= ulp_num
;
3624 cid_count_ulp
[ulp_num
] =
3625 BEISCSI_GET_CID_COUNT(phba
, ulp_num
);
3628 for (i
= 0; i
< phba
->params
.cxns_per_ctrl
; i
++) {
3633 if (ulp_count
> 1) {
3634 ulp_base_num
= (ulp_base_num
+ 1) % BEISCSI_ULP_COUNT
;
3636 if (!cid_count_ulp
[ulp_base_num
])
3637 ulp_base_num
= (ulp_base_num
+ 1) %
3640 cid_count_ulp
[ulp_base_num
]--;
3644 hwi_build_be_sgl_by_offset(phba
, &pwrb_arr
[i
], &sgl
);
3645 status
= be_cmd_wrbq_create(&phba
->ctrl
, &sgl
,
3646 &phwi_context
->be_wrbq
[i
],
3647 &phwi_ctrlr
->wrb_context
[i
],
3650 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3651 "BM_%d : wrbq create failed.");
3655 pwrb_context
= &phwi_ctrlr
->wrb_context
[i
];
3656 BE_SET_CID_TO_CRI(i
, pwrb_context
->cid
);
3662 static void free_wrb_handles(struct beiscsi_hba
*phba
)
3665 struct hwi_controller
*phwi_ctrlr
;
3666 struct hwi_wrb_context
*pwrb_context
;
3668 phwi_ctrlr
= phba
->phwi_ctrlr
;
3669 for (index
= 0; index
< phba
->params
.cxns_per_ctrl
; index
++) {
3670 pwrb_context
= &phwi_ctrlr
->wrb_context
[index
];
3671 kfree(pwrb_context
->pwrb_handle_base
);
3672 kfree(pwrb_context
->pwrb_handle_basestd
);
3676 static void be_mcc_queues_destroy(struct beiscsi_hba
*phba
)
3678 struct be_queue_info
*q
;
3679 struct be_ctrl_info
*ctrl
= &phba
->ctrl
;
3681 q
= &phba
->ctrl
.mcc_obj
.q
;
3683 beiscsi_cmd_q_destroy(ctrl
, q
, QTYPE_MCCQ
);
3684 be_queue_free(phba
, q
);
3686 q
= &phba
->ctrl
.mcc_obj
.cq
;
3688 beiscsi_cmd_q_destroy(ctrl
, q
, QTYPE_CQ
);
3689 be_queue_free(phba
, q
);
3692 static void hwi_cleanup(struct beiscsi_hba
*phba
)
3694 struct be_queue_info
*q
;
3695 struct be_ctrl_info
*ctrl
= &phba
->ctrl
;
3696 struct hwi_controller
*phwi_ctrlr
;
3697 struct hwi_context_memory
*phwi_context
;
3698 struct hwi_async_pdu_context
*pasync_ctx
;
3699 int i
, eq_for_mcc
, ulp_num
;
3701 phwi_ctrlr
= phba
->phwi_ctrlr
;
3702 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
3704 be_cmd_iscsi_remove_template_hdr(ctrl
);
3706 for (i
= 0; i
< phba
->params
.cxns_per_ctrl
; i
++) {
3707 q
= &phwi_context
->be_wrbq
[i
];
3709 beiscsi_cmd_q_destroy(ctrl
, q
, QTYPE_WRBQ
);
3711 kfree(phwi_context
->be_wrbq
);
3712 free_wrb_handles(phba
);
3714 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++) {
3715 if (test_bit(ulp_num
, &phba
->fw_config
.ulp_supported
)) {
3717 q
= &phwi_context
->be_def_hdrq
[ulp_num
];
3719 beiscsi_cmd_q_destroy(ctrl
, q
, QTYPE_DPDUQ
);
3721 q
= &phwi_context
->be_def_dataq
[ulp_num
];
3723 beiscsi_cmd_q_destroy(ctrl
, q
, QTYPE_DPDUQ
);
3725 pasync_ctx
= phwi_ctrlr
->phwi_ctxt
->pasync_ctx
[ulp_num
];
3729 beiscsi_cmd_q_destroy(ctrl
, NULL
, QTYPE_SGL
);
3731 for (i
= 0; i
< (phba
->num_cpus
); i
++) {
3732 q
= &phwi_context
->be_cq
[i
];
3734 beiscsi_cmd_q_destroy(ctrl
, q
, QTYPE_CQ
);
3737 be_mcc_queues_destroy(phba
);
3738 if (phba
->msix_enabled
)
3742 for (i
= 0; i
< (phba
->num_cpus
+ eq_for_mcc
); i
++) {
3743 q
= &phwi_context
->be_eq
[i
].q
;
3745 beiscsi_cmd_q_destroy(ctrl
, q
, QTYPE_EQ
);
3747 be_cmd_fw_uninit(ctrl
);
3750 static int be_mcc_queues_create(struct beiscsi_hba
*phba
,
3751 struct hwi_context_memory
*phwi_context
)
3753 struct be_queue_info
*q
, *cq
;
3754 struct be_ctrl_info
*ctrl
= &phba
->ctrl
;
3756 /* Alloc MCC compl queue */
3757 cq
= &phba
->ctrl
.mcc_obj
.cq
;
3758 if (be_queue_alloc(phba
, cq
, MCC_CQ_LEN
,
3759 sizeof(struct be_mcc_compl
)))
3761 /* Ask BE to create MCC compl queue; */
3762 if (phba
->msix_enabled
) {
3763 if (beiscsi_cmd_cq_create(ctrl
, cq
, &phwi_context
->be_eq
3764 [phba
->num_cpus
].q
, false, true, 0))
3767 if (beiscsi_cmd_cq_create(ctrl
, cq
, &phwi_context
->be_eq
[0].q
,
3772 /* Alloc MCC queue */
3773 q
= &phba
->ctrl
.mcc_obj
.q
;
3774 if (be_queue_alloc(phba
, q
, MCC_Q_LEN
, sizeof(struct be_mcc_wrb
)))
3775 goto mcc_cq_destroy
;
3777 /* Ask BE to create MCC queue */
3778 if (beiscsi_cmd_mccq_create(phba
, q
, cq
))
3784 be_queue_free(phba
, q
);
3786 beiscsi_cmd_q_destroy(ctrl
, cq
, QTYPE_CQ
);
3788 be_queue_free(phba
, cq
);
3794 * find_num_cpus()- Get the CPU online count
3795 * @phba: ptr to priv structure
3797 * CPU count is used for creating EQ.
3799 static void find_num_cpus(struct beiscsi_hba
*phba
)
3803 num_cpus
= num_online_cpus();
3805 switch (phba
->generation
) {
3808 phba
->num_cpus
= (num_cpus
> BEISCSI_MAX_NUM_CPUS
) ?
3809 BEISCSI_MAX_NUM_CPUS
: num_cpus
;
3813 * If eqid_count == 1 fall back to
3816 if (phba
->fw_config
.eqid_count
== 1) {
3823 (num_cpus
> (phba
->fw_config
.eqid_count
- 1)) ?
3824 (phba
->fw_config
.eqid_count
- 1) : num_cpus
;
3831 static int hwi_init_port(struct beiscsi_hba
*phba
)
3833 struct hwi_controller
*phwi_ctrlr
;
3834 struct hwi_context_memory
*phwi_context
;
3835 unsigned int def_pdu_ring_sz
;
3836 struct be_ctrl_info
*ctrl
= &phba
->ctrl
;
3837 int status
, ulp_num
;
3839 phwi_ctrlr
= phba
->phwi_ctrlr
;
3840 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
3841 phwi_context
->max_eqd
= 128;
3842 phwi_context
->min_eqd
= 0;
3843 phwi_context
->cur_eqd
= 0;
3844 be_cmd_fw_initialize(&phba
->ctrl
);
3846 status
= beiscsi_create_eqs(phba
, phwi_context
);
3848 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3849 "BM_%d : EQ not created\n");
3853 status
= be_mcc_queues_create(phba
, phwi_context
);
3857 status
= mgmt_check_supported_fw(ctrl
, phba
);
3859 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3860 "BM_%d : Unsupported fw version\n");
3864 status
= beiscsi_create_cqs(phba
, phwi_context
);
3866 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3867 "BM_%d : CQ not created\n");
3871 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++) {
3872 if (test_bit(ulp_num
, &phba
->fw_config
.ulp_supported
)) {
3875 BEISCSI_GET_CID_COUNT(phba
, ulp_num
) *
3876 sizeof(struct phys_addr
);
3878 status
= beiscsi_create_def_hdr(phba
, phwi_context
,
3883 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3884 "BM_%d : Default Header not created for ULP : %d\n",
3889 status
= beiscsi_create_def_data(phba
, phwi_context
,
3894 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3895 "BM_%d : Default Data not created for ULP : %d\n",
3902 status
= beiscsi_post_pages(phba
);
3904 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3905 "BM_%d : Post SGL Pages Failed\n");
3909 status
= beiscsi_post_template_hdr(phba
);
3911 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3912 "BM_%d : Template HDR Posting for CXN Failed\n");
3915 status
= beiscsi_create_wrb_rings(phba
, phwi_context
, phwi_ctrlr
);
3917 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3918 "BM_%d : WRB Rings not created\n");
3922 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++) {
3923 uint16_t async_arr_idx
= 0;
3925 if (test_bit(ulp_num
, &phba
->fw_config
.ulp_supported
)) {
3927 struct hwi_async_pdu_context
*pasync_ctx
;
3929 pasync_ctx
= HWI_GET_ASYNC_PDU_CTX(
3930 phwi_ctrlr
, ulp_num
);
3932 phba
->params
.cxns_per_ctrl
; cri
++) {
3933 if (ulp_num
== BEISCSI_GET_ULP_FROM_CRI
3935 pasync_ctx
->cid_to_async_cri_map
[
3936 phwi_ctrlr
->wrb_context
[cri
].cid
] =
3942 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
3943 "BM_%d : hwi_init_port success\n");
3947 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3948 "BM_%d : hwi_init_port failed");
3953 static int hwi_init_controller(struct beiscsi_hba
*phba
)
3955 struct hwi_controller
*phwi_ctrlr
;
3957 phwi_ctrlr
= phba
->phwi_ctrlr
;
3958 if (1 == phba
->init_mem
[HWI_MEM_ADDN_CONTEXT
].num_elements
) {
3959 phwi_ctrlr
->phwi_ctxt
= (struct hwi_context_memory
*)phba
->
3960 init_mem
[HWI_MEM_ADDN_CONTEXT
].mem_array
[0].virtual_address
;
3961 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
3962 "BM_%d : phwi_ctrlr->phwi_ctxt=%p\n",
3963 phwi_ctrlr
->phwi_ctxt
);
3965 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3966 "BM_%d : HWI_MEM_ADDN_CONTEXT is more "
3967 "than one element.Failing to load\n");
3971 iscsi_init_global_templates(phba
);
3972 if (beiscsi_init_wrb_handle(phba
))
3975 if (hwi_init_async_pdu_ctx(phba
)) {
3976 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3977 "BM_%d : hwi_init_async_pdu_ctx failed\n");
3981 if (hwi_init_port(phba
) != 0) {
3982 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
3983 "BM_%d : hwi_init_controller failed\n");
3990 static void beiscsi_free_mem(struct beiscsi_hba
*phba
)
3992 struct be_mem_descriptor
*mem_descr
;
3995 mem_descr
= phba
->init_mem
;
3998 for (i
= 0; i
< SE_MEM_MAX
; i
++) {
3999 for (j
= mem_descr
->num_elements
; j
> 0; j
--) {
4000 pci_free_consistent(phba
->pcidev
,
4001 mem_descr
->mem_array
[j
- 1].size
,
4002 mem_descr
->mem_array
[j
- 1].virtual_address
,
4003 (unsigned long)mem_descr
->mem_array
[j
- 1].
4004 bus_address
.u
.a64
.address
);
4007 kfree(mem_descr
->mem_array
);
4010 kfree(phba
->init_mem
);
4011 kfree(phba
->phwi_ctrlr
->wrb_context
);
4012 kfree(phba
->phwi_ctrlr
);
4015 static int beiscsi_init_controller(struct beiscsi_hba
*phba
)
4019 ret
= beiscsi_get_memory(phba
);
4021 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
4022 "BM_%d : beiscsi_dev_probe -"
4023 "Failed in beiscsi_alloc_memory\n");
4027 ret
= hwi_init_controller(phba
);
4030 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
4031 "BM_%d : Return success from beiscsi_init_controller");
4036 beiscsi_free_mem(phba
);
4040 static int beiscsi_init_sgl_handle(struct beiscsi_hba
*phba
)
4042 struct be_mem_descriptor
*mem_descr_sglh
, *mem_descr_sg
;
4043 struct sgl_handle
*psgl_handle
;
4044 struct iscsi_sge
*pfrag
;
4045 unsigned int arr_index
, i
, idx
;
4046 unsigned int ulp_icd_start
, ulp_num
= 0;
4048 phba
->io_sgl_hndl_avbl
= 0;
4049 phba
->eh_sgl_hndl_avbl
= 0;
4051 mem_descr_sglh
= phba
->init_mem
;
4052 mem_descr_sglh
+= HWI_MEM_SGLH
;
4053 if (1 == mem_descr_sglh
->num_elements
) {
4054 phba
->io_sgl_hndl_base
= kzalloc(sizeof(struct sgl_handle
*) *
4055 phba
->params
.ios_per_ctrl
,
4057 if (!phba
->io_sgl_hndl_base
) {
4058 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
4059 "BM_%d : Mem Alloc Failed. Failing to load\n");
4062 phba
->eh_sgl_hndl_base
= kzalloc(sizeof(struct sgl_handle
*) *
4063 (phba
->params
.icds_per_ctrl
-
4064 phba
->params
.ios_per_ctrl
),
4066 if (!phba
->eh_sgl_hndl_base
) {
4067 kfree(phba
->io_sgl_hndl_base
);
4068 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
4069 "BM_%d : Mem Alloc Failed. Failing to load\n");
4073 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
4074 "BM_%d : HWI_MEM_SGLH is more than one element."
4075 "Failing to load\n");
4081 while (idx
< mem_descr_sglh
->num_elements
) {
4082 psgl_handle
= mem_descr_sglh
->mem_array
[idx
].virtual_address
;
4084 for (i
= 0; i
< (mem_descr_sglh
->mem_array
[idx
].size
/
4085 sizeof(struct sgl_handle
)); i
++) {
4086 if (arr_index
< phba
->params
.ios_per_ctrl
) {
4087 phba
->io_sgl_hndl_base
[arr_index
] = psgl_handle
;
4088 phba
->io_sgl_hndl_avbl
++;
4091 phba
->eh_sgl_hndl_base
[arr_index
-
4092 phba
->params
.ios_per_ctrl
] =
4095 phba
->eh_sgl_hndl_avbl
++;
4101 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
4102 "BM_%d : phba->io_sgl_hndl_avbl=%d"
4103 "phba->eh_sgl_hndl_avbl=%d\n",
4104 phba
->io_sgl_hndl_avbl
,
4105 phba
->eh_sgl_hndl_avbl
);
4107 mem_descr_sg
= phba
->init_mem
;
4108 mem_descr_sg
+= HWI_MEM_SGE
;
4109 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
4110 "\n BM_%d : mem_descr_sg->num_elements=%d\n",
4111 mem_descr_sg
->num_elements
);
4113 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++)
4114 if (test_bit(ulp_num
, &phba
->fw_config
.ulp_supported
))
4117 ulp_icd_start
= phba
->fw_config
.iscsi_icd_start
[ulp_num
];
4121 while (idx
< mem_descr_sg
->num_elements
) {
4122 pfrag
= mem_descr_sg
->mem_array
[idx
].virtual_address
;
4125 i
< (mem_descr_sg
->mem_array
[idx
].size
) /
4126 (sizeof(struct iscsi_sge
) * phba
->params
.num_sge_per_io
);
4128 if (arr_index
< phba
->params
.ios_per_ctrl
)
4129 psgl_handle
= phba
->io_sgl_hndl_base
[arr_index
];
4131 psgl_handle
= phba
->eh_sgl_hndl_base
[arr_index
-
4132 phba
->params
.ios_per_ctrl
];
4133 psgl_handle
->pfrag
= pfrag
;
4134 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_hi
, pfrag
, 0);
4135 AMAP_SET_BITS(struct amap_iscsi_sge
, addr_lo
, pfrag
, 0);
4136 pfrag
+= phba
->params
.num_sge_per_io
;
4137 psgl_handle
->sgl_index
= ulp_icd_start
+ arr_index
++;
4141 phba
->io_sgl_free_index
= 0;
4142 phba
->io_sgl_alloc_index
= 0;
4143 phba
->eh_sgl_free_index
= 0;
4144 phba
->eh_sgl_alloc_index
= 0;
4148 static int hba_setup_cid_tbls(struct beiscsi_hba
*phba
)
4151 uint16_t i
, ulp_num
;
4152 struct ulp_cid_info
*ptr_cid_info
= NULL
;
4154 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++) {
4155 if (test_bit(ulp_num
, (void *)&phba
->fw_config
.ulp_supported
)) {
4156 ptr_cid_info
= kzalloc(sizeof(struct ulp_cid_info
),
4159 if (!ptr_cid_info
) {
4160 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
4161 "BM_%d : Failed to allocate memory"
4162 "for ULP_CID_INFO for ULP : %d\n",
4169 /* Allocate memory for CID array */
4170 ptr_cid_info
->cid_array
= kzalloc(sizeof(void *) *
4171 BEISCSI_GET_CID_COUNT(phba
,
4172 ulp_num
), GFP_KERNEL
);
4173 if (!ptr_cid_info
->cid_array
) {
4174 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
4175 "BM_%d : Failed to allocate memory"
4176 "for CID_ARRAY for ULP : %d\n",
4178 kfree(ptr_cid_info
);
4179 ptr_cid_info
= NULL
;
4184 ptr_cid_info
->avlbl_cids
= BEISCSI_GET_CID_COUNT(
4187 /* Save the cid_info_array ptr */
4188 phba
->cid_array_info
[ulp_num
] = ptr_cid_info
;
4191 phba
->ep_array
= kzalloc(sizeof(struct iscsi_endpoint
*) *
4192 phba
->params
.cxns_per_ctrl
, GFP_KERNEL
);
4193 if (!phba
->ep_array
) {
4194 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
4195 "BM_%d : Failed to allocate memory in "
4196 "hba_setup_cid_tbls\n");
4202 phba
->conn_table
= kzalloc(sizeof(struct beiscsi_conn
*) *
4203 phba
->params
.cxns_per_ctrl
, GFP_KERNEL
);
4204 if (!phba
->conn_table
) {
4205 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
4206 "BM_%d : Failed to allocate memory in"
4207 "hba_setup_cid_tbls\n");
4209 kfree(phba
->ep_array
);
4210 phba
->ep_array
= NULL
;
4216 for (i
= 0; i
< phba
->params
.cxns_per_ctrl
; i
++) {
4217 ulp_num
= phba
->phwi_ctrlr
->wrb_context
[i
].ulp_num
;
4219 ptr_cid_info
= phba
->cid_array_info
[ulp_num
];
4220 ptr_cid_info
->cid_array
[ptr_cid_info
->cid_alloc
++] =
4221 phba
->phwi_ctrlr
->wrb_context
[i
].cid
;
4225 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++) {
4226 if (test_bit(ulp_num
, (void *)&phba
->fw_config
.ulp_supported
)) {
4227 ptr_cid_info
= phba
->cid_array_info
[ulp_num
];
4229 ptr_cid_info
->cid_alloc
= 0;
4230 ptr_cid_info
->cid_free
= 0;
4236 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++) {
4237 if (test_bit(ulp_num
, (void *)&phba
->fw_config
.ulp_supported
)) {
4238 ptr_cid_info
= phba
->cid_array_info
[ulp_num
];
4241 kfree(ptr_cid_info
->cid_array
);
4242 kfree(ptr_cid_info
);
4243 phba
->cid_array_info
[ulp_num
] = NULL
;
4251 static void hwi_enable_intr(struct beiscsi_hba
*phba
)
4253 struct be_ctrl_info
*ctrl
= &phba
->ctrl
;
4254 struct hwi_controller
*phwi_ctrlr
;
4255 struct hwi_context_memory
*phwi_context
;
4256 struct be_queue_info
*eq
;
4261 phwi_ctrlr
= phba
->phwi_ctrlr
;
4262 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
4264 addr
= (u8 __iomem
*) ((u8 __iomem
*) ctrl
->pcicfg
+
4265 PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET
);
4266 reg
= ioread32(addr
);
4268 enabled
= reg
& MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK
;
4270 reg
|= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK
;
4271 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
4272 "BM_%d : reg =x%08x addr=%p\n", reg
, addr
);
4273 iowrite32(reg
, addr
);
4276 if (!phba
->msix_enabled
) {
4277 eq
= &phwi_context
->be_eq
[0].q
;
4278 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
4279 "BM_%d : eq->id=%d\n", eq
->id
);
4281 hwi_ring_eq_db(phba
, eq
->id
, 0, 0, 1, 1);
4283 for (i
= 0; i
<= phba
->num_cpus
; i
++) {
4284 eq
= &phwi_context
->be_eq
[i
].q
;
4285 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
4286 "BM_%d : eq->id=%d\n", eq
->id
);
4287 hwi_ring_eq_db(phba
, eq
->id
, 0, 0, 1, 1);
4292 static void hwi_disable_intr(struct beiscsi_hba
*phba
)
4294 struct be_ctrl_info
*ctrl
= &phba
->ctrl
;
4296 u8 __iomem
*addr
= ctrl
->pcicfg
+ PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET
;
4297 u32 reg
= ioread32(addr
);
4299 u32 enabled
= reg
& MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK
;
4301 reg
&= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK
;
4302 iowrite32(reg
, addr
);
4304 beiscsi_log(phba
, KERN_WARNING
, BEISCSI_LOG_INIT
,
4305 "BM_%d : In hwi_disable_intr, Already Disabled\n");
4309 * beiscsi_get_boot_info()- Get the boot session info
4310 * @phba: The device priv structure instance
4312 * Get the boot target info and store in driver priv structure
4316 * Failure: Non-Zero Value
4318 static int beiscsi_get_boot_info(struct beiscsi_hba
*phba
)
4320 struct be_cmd_get_session_resp
*session_resp
;
4321 struct be_dma_mem nonemb_cmd
;
4323 unsigned int s_handle
;
4326 /* Get the session handle of the boot target */
4327 ret
= be_mgmt_get_boot_shandle(phba
, &s_handle
);
4329 beiscsi_log(phba
, KERN_ERR
,
4330 BEISCSI_LOG_INIT
| BEISCSI_LOG_CONFIG
,
4331 "BM_%d : No boot session\n");
4334 nonemb_cmd
.va
= pci_zalloc_consistent(phba
->ctrl
.pdev
,
4335 sizeof(*session_resp
),
4337 if (nonemb_cmd
.va
== NULL
) {
4338 beiscsi_log(phba
, KERN_ERR
,
4339 BEISCSI_LOG_INIT
| BEISCSI_LOG_CONFIG
,
4340 "BM_%d : Failed to allocate memory for"
4341 "beiscsi_get_session_info\n");
4346 tag
= mgmt_get_session_info(phba
, s_handle
,
4349 beiscsi_log(phba
, KERN_ERR
,
4350 BEISCSI_LOG_INIT
| BEISCSI_LOG_CONFIG
,
4351 "BM_%d : beiscsi_get_session_info"
4357 ret
= beiscsi_mccq_compl(phba
, tag
, NULL
, &nonemb_cmd
);
4359 beiscsi_log(phba
, KERN_ERR
,
4360 BEISCSI_LOG_INIT
| BEISCSI_LOG_CONFIG
,
4361 "BM_%d : beiscsi_get_session_info Failed");
4369 session_resp
= nonemb_cmd
.va
;
4371 memcpy(&phba
->boot_sess
, &session_resp
->session_info
,
4372 sizeof(struct mgmt_session_info
));
4376 pci_free_consistent(phba
->ctrl
.pdev
, nonemb_cmd
.size
,
4377 nonemb_cmd
.va
, nonemb_cmd
.dma
);
4381 static void beiscsi_boot_release(void *data
)
4383 struct beiscsi_hba
*phba
= data
;
4385 scsi_host_put(phba
->shost
);
4388 static int beiscsi_setup_boot_info(struct beiscsi_hba
*phba
)
4390 struct iscsi_boot_kobj
*boot_kobj
;
4392 /* it has been created previously */
4393 if (phba
->boot_kset
)
4396 /* get boot info using mgmt cmd */
4397 if (beiscsi_get_boot_info(phba
))
4398 /* Try to see if we can carry on without this */
4401 phba
->boot_kset
= iscsi_boot_create_host_kset(phba
->shost
->host_no
);
4402 if (!phba
->boot_kset
)
4405 /* get a ref because the show function will ref the phba */
4406 if (!scsi_host_get(phba
->shost
))
4408 boot_kobj
= iscsi_boot_create_target(phba
->boot_kset
, 0, phba
,
4409 beiscsi_show_boot_tgt_info
,
4410 beiscsi_tgt_get_attr_visibility
,
4411 beiscsi_boot_release
);
4415 if (!scsi_host_get(phba
->shost
))
4417 boot_kobj
= iscsi_boot_create_initiator(phba
->boot_kset
, 0, phba
,
4418 beiscsi_show_boot_ini_info
,
4419 beiscsi_ini_get_attr_visibility
,
4420 beiscsi_boot_release
);
4424 if (!scsi_host_get(phba
->shost
))
4426 boot_kobj
= iscsi_boot_create_ethernet(phba
->boot_kset
, 0, phba
,
4427 beiscsi_show_boot_eth_info
,
4428 beiscsi_eth_get_attr_visibility
,
4429 beiscsi_boot_release
);
4435 scsi_host_put(phba
->shost
);
4437 iscsi_boot_destroy_kset(phba
->boot_kset
);
4441 static int beiscsi_init_port(struct beiscsi_hba
*phba
)
4445 ret
= beiscsi_init_controller(phba
);
4447 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
4448 "BM_%d : beiscsi_dev_probe - Failed in"
4449 "beiscsi_init_controller\n");
4452 ret
= beiscsi_init_sgl_handle(phba
);
4454 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
4455 "BM_%d : beiscsi_dev_probe - Failed in"
4456 "beiscsi_init_sgl_handle\n");
4457 goto do_cleanup_ctrlr
;
4460 if (hba_setup_cid_tbls(phba
)) {
4461 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
4462 "BM_%d : Failed in hba_setup_cid_tbls\n");
4463 kfree(phba
->io_sgl_hndl_base
);
4464 kfree(phba
->eh_sgl_hndl_base
);
4465 goto do_cleanup_ctrlr
;
4475 static void hwi_purge_eq(struct beiscsi_hba
*phba
)
4477 struct hwi_controller
*phwi_ctrlr
;
4478 struct hwi_context_memory
*phwi_context
;
4479 struct be_queue_info
*eq
;
4480 struct be_eq_entry
*eqe
= NULL
;
4482 unsigned int num_processed
;
4484 phwi_ctrlr
= phba
->phwi_ctrlr
;
4485 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
4486 if (phba
->msix_enabled
)
4491 for (i
= 0; i
< (phba
->num_cpus
+ eq_msix
); i
++) {
4492 eq
= &phwi_context
->be_eq
[i
].q
;
4493 eqe
= queue_tail_node(eq
);
4495 while (eqe
->dw
[offsetof(struct amap_eq_entry
, valid
) / 32]
4497 AMAP_SET_BITS(struct amap_eq_entry
, valid
, eqe
, 0);
4499 eqe
= queue_tail_node(eq
);
4504 hwi_ring_eq_db(phba
, eq
->id
, 1, num_processed
, 1, 1);
4508 static void beiscsi_clean_port(struct beiscsi_hba
*phba
)
4510 int mgmt_status
, ulp_num
;
4511 struct ulp_cid_info
*ptr_cid_info
= NULL
;
4513 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++) {
4514 if (test_bit(ulp_num
, (void *)&phba
->fw_config
.ulp_supported
)) {
4515 mgmt_status
= mgmt_epfw_cleanup(phba
, ulp_num
);
4517 beiscsi_log(phba
, KERN_WARNING
,
4519 "BM_%d : mgmt_epfw_cleanup FAILED"
4520 " for ULP_%d\n", ulp_num
);
4526 kfree(phba
->io_sgl_hndl_base
);
4527 kfree(phba
->eh_sgl_hndl_base
);
4528 kfree(phba
->ep_array
);
4529 kfree(phba
->conn_table
);
4531 for (ulp_num
= 0; ulp_num
< BEISCSI_ULP_COUNT
; ulp_num
++) {
4532 if (test_bit(ulp_num
, (void *)&phba
->fw_config
.ulp_supported
)) {
4533 ptr_cid_info
= phba
->cid_array_info
[ulp_num
];
4536 kfree(ptr_cid_info
->cid_array
);
4537 kfree(ptr_cid_info
);
4538 phba
->cid_array_info
[ulp_num
] = NULL
;
4546 * beiscsi_free_mgmt_task_handles()- Free driver CXN resources
4547 * @beiscsi_conn: ptr to the conn to be cleaned up
4548 * @task: ptr to iscsi_task resource to be freed.
4550 * Free driver mgmt resources binded to CXN.
4553 beiscsi_free_mgmt_task_handles(struct beiscsi_conn
*beiscsi_conn
,
4554 struct iscsi_task
*task
)
4556 struct beiscsi_io_task
*io_task
;
4557 struct beiscsi_hba
*phba
= beiscsi_conn
->phba
;
4558 struct hwi_wrb_context
*pwrb_context
;
4559 struct hwi_controller
*phwi_ctrlr
;
4560 uint16_t cri_index
= BE_GET_CRI_FROM_CID(
4561 beiscsi_conn
->beiscsi_conn_cid
);
4563 phwi_ctrlr
= phba
->phwi_ctrlr
;
4564 pwrb_context
= &phwi_ctrlr
->wrb_context
[cri_index
];
4566 io_task
= task
->dd_data
;
4568 if (io_task
->pwrb_handle
) {
4569 memset(io_task
->pwrb_handle
->pwrb
, 0,
4570 sizeof(struct iscsi_wrb
));
4571 free_wrb_handle(phba
, pwrb_context
,
4572 io_task
->pwrb_handle
);
4573 io_task
->pwrb_handle
= NULL
;
4576 if (io_task
->psgl_handle
) {
4577 spin_lock_bh(&phba
->mgmt_sgl_lock
);
4578 free_mgmt_sgl_handle(phba
,
4579 io_task
->psgl_handle
);
4580 io_task
->psgl_handle
= NULL
;
4581 spin_unlock_bh(&phba
->mgmt_sgl_lock
);
4584 if (io_task
->mtask_addr
)
4585 pci_unmap_single(phba
->pcidev
,
4586 io_task
->mtask_addr
,
4587 io_task
->mtask_data_count
,
4592 * beiscsi_cleanup_task()- Free driver resources of the task
4593 * @task: ptr to the iscsi task
4596 static void beiscsi_cleanup_task(struct iscsi_task
*task
)
4598 struct beiscsi_io_task
*io_task
= task
->dd_data
;
4599 struct iscsi_conn
*conn
= task
->conn
;
4600 struct beiscsi_conn
*beiscsi_conn
= conn
->dd_data
;
4601 struct beiscsi_hba
*phba
= beiscsi_conn
->phba
;
4602 struct beiscsi_session
*beiscsi_sess
= beiscsi_conn
->beiscsi_sess
;
4603 struct hwi_wrb_context
*pwrb_context
;
4604 struct hwi_controller
*phwi_ctrlr
;
4605 uint16_t cri_index
= BE_GET_CRI_FROM_CID(
4606 beiscsi_conn
->beiscsi_conn_cid
);
4608 phwi_ctrlr
= phba
->phwi_ctrlr
;
4609 pwrb_context
= &phwi_ctrlr
->wrb_context
[cri_index
];
4611 if (io_task
->cmd_bhs
) {
4612 pci_pool_free(beiscsi_sess
->bhs_pool
, io_task
->cmd_bhs
,
4613 io_task
->bhs_pa
.u
.a64
.address
);
4614 io_task
->cmd_bhs
= NULL
;
4618 if (io_task
->pwrb_handle
) {
4619 free_wrb_handle(phba
, pwrb_context
,
4620 io_task
->pwrb_handle
);
4621 io_task
->pwrb_handle
= NULL
;
4624 if (io_task
->psgl_handle
) {
4625 spin_lock(&phba
->io_sgl_lock
);
4626 free_io_sgl_handle(phba
, io_task
->psgl_handle
);
4627 spin_unlock(&phba
->io_sgl_lock
);
4628 io_task
->psgl_handle
= NULL
;
4631 if (io_task
->scsi_cmnd
) {
4632 scsi_dma_unmap(io_task
->scsi_cmnd
);
4633 io_task
->scsi_cmnd
= NULL
;
4636 if (!beiscsi_conn
->login_in_progress
)
4637 beiscsi_free_mgmt_task_handles(beiscsi_conn
, task
);
4642 beiscsi_offload_connection(struct beiscsi_conn
*beiscsi_conn
,
4643 struct beiscsi_offload_params
*params
)
4645 struct wrb_handle
*pwrb_handle
;
4646 struct beiscsi_hba
*phba
= beiscsi_conn
->phba
;
4647 struct iscsi_task
*task
= beiscsi_conn
->task
;
4648 struct iscsi_session
*session
= task
->conn
->session
;
4652 * We can always use 0 here because it is reserved by libiscsi for
4653 * login/startup related tasks.
4655 beiscsi_conn
->login_in_progress
= 0;
4656 spin_lock_bh(&session
->back_lock
);
4657 beiscsi_cleanup_task(task
);
4658 spin_unlock_bh(&session
->back_lock
);
4660 pwrb_handle
= alloc_wrb_handle(phba
, beiscsi_conn
->beiscsi_conn_cid
);
4662 /* Check for the adapter family */
4663 if (is_chip_be2_be3r(phba
))
4664 beiscsi_offload_cxn_v0(params
, pwrb_handle
,
4667 beiscsi_offload_cxn_v2(params
, pwrb_handle
);
4669 be_dws_le_to_cpu(pwrb_handle
->pwrb
,
4670 sizeof(struct iscsi_target_context_update_wrb
));
4672 doorbell
|= beiscsi_conn
->beiscsi_conn_cid
& DB_WRB_POST_CID_MASK
;
4673 doorbell
|= (pwrb_handle
->wrb_index
& DB_DEF_PDU_WRB_INDEX_MASK
)
4674 << DB_DEF_PDU_WRB_INDEX_SHIFT
;
4675 doorbell
|= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT
;
4676 iowrite32(doorbell
, phba
->db_va
+
4677 beiscsi_conn
->doorbell_offset
);
4680 static void beiscsi_parse_pdu(struct iscsi_conn
*conn
, itt_t itt
,
4681 int *index
, int *age
)
4685 *age
= conn
->session
->age
;
4689 * beiscsi_alloc_pdu - allocates pdu and related resources
4690 * @task: libiscsi task
4691 * @opcode: opcode of pdu for task
4693 * This is called with the session lock held. It will allocate
4694 * the wrb and sgl if needed for the command. And it will prep
4695 * the pdu's itt. beiscsi_parse_pdu will later translate
4696 * the pdu itt to the libiscsi task itt.
4698 static int beiscsi_alloc_pdu(struct iscsi_task
*task
, uint8_t opcode
)
4700 struct beiscsi_io_task
*io_task
= task
->dd_data
;
4701 struct iscsi_conn
*conn
= task
->conn
;
4702 struct beiscsi_conn
*beiscsi_conn
= conn
->dd_data
;
4703 struct beiscsi_hba
*phba
= beiscsi_conn
->phba
;
4704 struct hwi_wrb_context
*pwrb_context
;
4705 struct hwi_controller
*phwi_ctrlr
;
4707 uint16_t cri_index
= 0;
4708 struct beiscsi_session
*beiscsi_sess
= beiscsi_conn
->beiscsi_sess
;
4711 io_task
->cmd_bhs
= pci_pool_alloc(beiscsi_sess
->bhs_pool
,
4712 GFP_ATOMIC
, &paddr
);
4713 if (!io_task
->cmd_bhs
)
4715 io_task
->bhs_pa
.u
.a64
.address
= paddr
;
4716 io_task
->libiscsi_itt
= (itt_t
)task
->itt
;
4717 io_task
->conn
= beiscsi_conn
;
4719 task
->hdr
= (struct iscsi_hdr
*)&io_task
->cmd_bhs
->iscsi_hdr
;
4720 task
->hdr_max
= sizeof(struct be_cmd_bhs
);
4721 io_task
->psgl_handle
= NULL
;
4722 io_task
->pwrb_handle
= NULL
;
4725 spin_lock(&phba
->io_sgl_lock
);
4726 io_task
->psgl_handle
= alloc_io_sgl_handle(phba
);
4727 spin_unlock(&phba
->io_sgl_lock
);
4728 if (!io_task
->psgl_handle
) {
4729 beiscsi_log(phba
, KERN_ERR
,
4730 BEISCSI_LOG_IO
| BEISCSI_LOG_CONFIG
,
4731 "BM_%d : Alloc of IO_SGL_ICD Failed"
4732 "for the CID : %d\n",
4733 beiscsi_conn
->beiscsi_conn_cid
);
4736 io_task
->pwrb_handle
= alloc_wrb_handle(phba
,
4737 beiscsi_conn
->beiscsi_conn_cid
);
4738 if (!io_task
->pwrb_handle
) {
4739 beiscsi_log(phba
, KERN_ERR
,
4740 BEISCSI_LOG_IO
| BEISCSI_LOG_CONFIG
,
4741 "BM_%d : Alloc of WRB_HANDLE Failed"
4742 "for the CID : %d\n",
4743 beiscsi_conn
->beiscsi_conn_cid
);
4747 io_task
->scsi_cmnd
= NULL
;
4748 if ((opcode
& ISCSI_OPCODE_MASK
) == ISCSI_OP_LOGIN
) {
4749 beiscsi_conn
->task
= task
;
4750 if (!beiscsi_conn
->login_in_progress
) {
4751 spin_lock(&phba
->mgmt_sgl_lock
);
4752 io_task
->psgl_handle
= (struct sgl_handle
*)
4753 alloc_mgmt_sgl_handle(phba
);
4754 spin_unlock(&phba
->mgmt_sgl_lock
);
4755 if (!io_task
->psgl_handle
) {
4756 beiscsi_log(phba
, KERN_ERR
,
4759 "BM_%d : Alloc of MGMT_SGL_ICD Failed"
4760 "for the CID : %d\n",
4766 beiscsi_conn
->login_in_progress
= 1;
4767 beiscsi_conn
->plogin_sgl_handle
=
4768 io_task
->psgl_handle
;
4769 io_task
->pwrb_handle
=
4770 alloc_wrb_handle(phba
,
4771 beiscsi_conn
->beiscsi_conn_cid
);
4772 if (!io_task
->pwrb_handle
) {
4773 beiscsi_log(phba
, KERN_ERR
,
4776 "BM_%d : Alloc of WRB_HANDLE Failed"
4777 "for the CID : %d\n",
4780 goto free_mgmt_hndls
;
4782 beiscsi_conn
->plogin_wrb_handle
=
4783 io_task
->pwrb_handle
;
4786 io_task
->psgl_handle
=
4787 beiscsi_conn
->plogin_sgl_handle
;
4788 io_task
->pwrb_handle
=
4789 beiscsi_conn
->plogin_wrb_handle
;
4792 spin_lock(&phba
->mgmt_sgl_lock
);
4793 io_task
->psgl_handle
= alloc_mgmt_sgl_handle(phba
);
4794 spin_unlock(&phba
->mgmt_sgl_lock
);
4795 if (!io_task
->psgl_handle
) {
4796 beiscsi_log(phba
, KERN_ERR
,
4799 "BM_%d : Alloc of MGMT_SGL_ICD Failed"
4800 "for the CID : %d\n",
4805 io_task
->pwrb_handle
=
4806 alloc_wrb_handle(phba
,
4807 beiscsi_conn
->beiscsi_conn_cid
);
4808 if (!io_task
->pwrb_handle
) {
4809 beiscsi_log(phba
, KERN_ERR
,
4810 BEISCSI_LOG_IO
| BEISCSI_LOG_CONFIG
,
4811 "BM_%d : Alloc of WRB_HANDLE Failed"
4812 "for the CID : %d\n",
4813 beiscsi_conn
->beiscsi_conn_cid
);
4814 goto free_mgmt_hndls
;
4819 itt
= (itt_t
) cpu_to_be32(((unsigned int)io_task
->pwrb_handle
->
4820 wrb_index
<< 16) | (unsigned int)
4821 (io_task
->psgl_handle
->sgl_index
));
4822 io_task
->pwrb_handle
->pio_handle
= task
;
4824 io_task
->cmd_bhs
->iscsi_hdr
.itt
= itt
;
4828 spin_lock(&phba
->io_sgl_lock
);
4829 free_io_sgl_handle(phba
, io_task
->psgl_handle
);
4830 spin_unlock(&phba
->io_sgl_lock
);
4833 spin_lock(&phba
->mgmt_sgl_lock
);
4834 free_mgmt_sgl_handle(phba
, io_task
->psgl_handle
);
4835 io_task
->psgl_handle
= NULL
;
4836 spin_unlock(&phba
->mgmt_sgl_lock
);
4838 phwi_ctrlr
= phba
->phwi_ctrlr
;
4839 cri_index
= BE_GET_CRI_FROM_CID(
4840 beiscsi_conn
->beiscsi_conn_cid
);
4841 pwrb_context
= &phwi_ctrlr
->wrb_context
[cri_index
];
4842 if (io_task
->pwrb_handle
)
4843 free_wrb_handle(phba
, pwrb_context
, io_task
->pwrb_handle
);
4844 io_task
->pwrb_handle
= NULL
;
4845 pci_pool_free(beiscsi_sess
->bhs_pool
, io_task
->cmd_bhs
,
4846 io_task
->bhs_pa
.u
.a64
.address
);
4847 io_task
->cmd_bhs
= NULL
;
4850 int beiscsi_iotask_v2(struct iscsi_task
*task
, struct scatterlist
*sg
,
4851 unsigned int num_sg
, unsigned int xferlen
,
4852 unsigned int writedir
)
4855 struct beiscsi_io_task
*io_task
= task
->dd_data
;
4856 struct iscsi_conn
*conn
= task
->conn
;
4857 struct beiscsi_conn
*beiscsi_conn
= conn
->dd_data
;
4858 struct beiscsi_hba
*phba
= beiscsi_conn
->phba
;
4859 struct iscsi_wrb
*pwrb
= NULL
;
4860 unsigned int doorbell
= 0;
4862 pwrb
= io_task
->pwrb_handle
->pwrb
;
4864 io_task
->cmd_bhs
->iscsi_hdr
.exp_statsn
= 0;
4865 io_task
->bhs_len
= sizeof(struct be_cmd_bhs
);
4868 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, type
, pwrb
,
4870 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, dsp
, pwrb
, 1);
4872 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, type
, pwrb
,
4874 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, dsp
, pwrb
, 0);
4877 io_task
->wrb_type
= AMAP_GET_BITS(struct amap_iscsi_wrb_v2
,
4880 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, lun
, pwrb
,
4881 cpu_to_be16(*(unsigned short *)
4882 &io_task
->cmd_bhs
->iscsi_hdr
.lun
));
4883 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, r2t_exp_dtl
, pwrb
, xferlen
);
4884 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, wrb_idx
, pwrb
,
4885 io_task
->pwrb_handle
->wrb_index
);
4886 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, cmdsn_itt
, pwrb
,
4887 be32_to_cpu(task
->cmdsn
));
4888 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, sgl_idx
, pwrb
,
4889 io_task
->psgl_handle
->sgl_index
);
4891 hwi_write_sgl_v2(pwrb
, sg
, num_sg
, io_task
);
4892 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, ptr2nextwrb
, pwrb
,
4893 io_task
->pwrb_handle
->nxt_wrb_index
);
4895 be_dws_le_to_cpu(pwrb
, sizeof(struct iscsi_wrb
));
4897 doorbell
|= beiscsi_conn
->beiscsi_conn_cid
& DB_WRB_POST_CID_MASK
;
4898 doorbell
|= (io_task
->pwrb_handle
->wrb_index
&
4899 DB_DEF_PDU_WRB_INDEX_MASK
) <<
4900 DB_DEF_PDU_WRB_INDEX_SHIFT
;
4901 doorbell
|= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT
;
4902 iowrite32(doorbell
, phba
->db_va
+
4903 beiscsi_conn
->doorbell_offset
);
4907 static int beiscsi_iotask(struct iscsi_task
*task
, struct scatterlist
*sg
,
4908 unsigned int num_sg
, unsigned int xferlen
,
4909 unsigned int writedir
)
4912 struct beiscsi_io_task
*io_task
= task
->dd_data
;
4913 struct iscsi_conn
*conn
= task
->conn
;
4914 struct beiscsi_conn
*beiscsi_conn
= conn
->dd_data
;
4915 struct beiscsi_hba
*phba
= beiscsi_conn
->phba
;
4916 struct iscsi_wrb
*pwrb
= NULL
;
4917 unsigned int doorbell
= 0;
4919 pwrb
= io_task
->pwrb_handle
->pwrb
;
4920 io_task
->cmd_bhs
->iscsi_hdr
.exp_statsn
= 0;
4921 io_task
->bhs_len
= sizeof(struct be_cmd_bhs
);
4924 AMAP_SET_BITS(struct amap_iscsi_wrb
, type
, pwrb
,
4926 AMAP_SET_BITS(struct amap_iscsi_wrb
, dsp
, pwrb
, 1);
4928 AMAP_SET_BITS(struct amap_iscsi_wrb
, type
, pwrb
,
4930 AMAP_SET_BITS(struct amap_iscsi_wrb
, dsp
, pwrb
, 0);
4933 io_task
->wrb_type
= AMAP_GET_BITS(struct amap_iscsi_wrb
,
4936 AMAP_SET_BITS(struct amap_iscsi_wrb
, lun
, pwrb
,
4937 cpu_to_be16(*(unsigned short *)
4938 &io_task
->cmd_bhs
->iscsi_hdr
.lun
));
4939 AMAP_SET_BITS(struct amap_iscsi_wrb
, r2t_exp_dtl
, pwrb
, xferlen
);
4940 AMAP_SET_BITS(struct amap_iscsi_wrb
, wrb_idx
, pwrb
,
4941 io_task
->pwrb_handle
->wrb_index
);
4942 AMAP_SET_BITS(struct amap_iscsi_wrb
, cmdsn_itt
, pwrb
,
4943 be32_to_cpu(task
->cmdsn
));
4944 AMAP_SET_BITS(struct amap_iscsi_wrb
, sgl_icd_idx
, pwrb
,
4945 io_task
->psgl_handle
->sgl_index
);
4947 hwi_write_sgl(pwrb
, sg
, num_sg
, io_task
);
4949 AMAP_SET_BITS(struct amap_iscsi_wrb
, ptr2nextwrb
, pwrb
,
4950 io_task
->pwrb_handle
->nxt_wrb_index
);
4951 be_dws_le_to_cpu(pwrb
, sizeof(struct iscsi_wrb
));
4953 doorbell
|= beiscsi_conn
->beiscsi_conn_cid
& DB_WRB_POST_CID_MASK
;
4954 doorbell
|= (io_task
->pwrb_handle
->wrb_index
&
4955 DB_DEF_PDU_WRB_INDEX_MASK
) << DB_DEF_PDU_WRB_INDEX_SHIFT
;
4956 doorbell
|= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT
;
4958 iowrite32(doorbell
, phba
->db_va
+
4959 beiscsi_conn
->doorbell_offset
);
4963 static int beiscsi_mtask(struct iscsi_task
*task
)
4965 struct beiscsi_io_task
*io_task
= task
->dd_data
;
4966 struct iscsi_conn
*conn
= task
->conn
;
4967 struct beiscsi_conn
*beiscsi_conn
= conn
->dd_data
;
4968 struct beiscsi_hba
*phba
= beiscsi_conn
->phba
;
4969 struct iscsi_wrb
*pwrb
= NULL
;
4970 unsigned int doorbell
= 0;
4972 unsigned int pwrb_typeoffset
= 0;
4974 cid
= beiscsi_conn
->beiscsi_conn_cid
;
4975 pwrb
= io_task
->pwrb_handle
->pwrb
;
4976 memset(pwrb
, 0, sizeof(*pwrb
));
4978 if (is_chip_be2_be3r(phba
)) {
4979 AMAP_SET_BITS(struct amap_iscsi_wrb
, cmdsn_itt
, pwrb
,
4980 be32_to_cpu(task
->cmdsn
));
4981 AMAP_SET_BITS(struct amap_iscsi_wrb
, wrb_idx
, pwrb
,
4982 io_task
->pwrb_handle
->wrb_index
);
4983 AMAP_SET_BITS(struct amap_iscsi_wrb
, sgl_icd_idx
, pwrb
,
4984 io_task
->psgl_handle
->sgl_index
);
4985 AMAP_SET_BITS(struct amap_iscsi_wrb
, r2t_exp_dtl
, pwrb
,
4987 AMAP_SET_BITS(struct amap_iscsi_wrb
, ptr2nextwrb
, pwrb
,
4988 io_task
->pwrb_handle
->nxt_wrb_index
);
4989 pwrb_typeoffset
= BE_WRB_TYPE_OFFSET
;
4991 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, cmdsn_itt
, pwrb
,
4992 be32_to_cpu(task
->cmdsn
));
4993 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, wrb_idx
, pwrb
,
4994 io_task
->pwrb_handle
->wrb_index
);
4995 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, sgl_idx
, pwrb
,
4996 io_task
->psgl_handle
->sgl_index
);
4997 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, r2t_exp_dtl
, pwrb
,
4999 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
, ptr2nextwrb
, pwrb
,
5000 io_task
->pwrb_handle
->nxt_wrb_index
);
5001 pwrb_typeoffset
= SKH_WRB_TYPE_OFFSET
;
5005 switch (task
->hdr
->opcode
& ISCSI_OPCODE_MASK
) {
5006 case ISCSI_OP_LOGIN
:
5007 AMAP_SET_BITS(struct amap_iscsi_wrb
, cmdsn_itt
, pwrb
, 1);
5008 ADAPTER_SET_WRB_TYPE(pwrb
, TGT_DM_CMD
, pwrb_typeoffset
);
5009 hwi_write_buffer(pwrb
, task
);
5011 case ISCSI_OP_NOOP_OUT
:
5012 if (task
->hdr
->ttt
!= ISCSI_RESERVED_TAG
) {
5013 ADAPTER_SET_WRB_TYPE(pwrb
, TGT_DM_CMD
, pwrb_typeoffset
);
5014 if (is_chip_be2_be3r(phba
))
5015 AMAP_SET_BITS(struct amap_iscsi_wrb
,
5018 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
,
5021 ADAPTER_SET_WRB_TYPE(pwrb
, INI_RD_CMD
, pwrb_typeoffset
);
5022 if (is_chip_be2_be3r(phba
))
5023 AMAP_SET_BITS(struct amap_iscsi_wrb
,
5026 AMAP_SET_BITS(struct amap_iscsi_wrb_v2
,
5029 hwi_write_buffer(pwrb
, task
);
5032 ADAPTER_SET_WRB_TYPE(pwrb
, TGT_DM_CMD
, pwrb_typeoffset
);
5033 hwi_write_buffer(pwrb
, task
);
5035 case ISCSI_OP_SCSI_TMFUNC
:
5036 ADAPTER_SET_WRB_TYPE(pwrb
, INI_TMF_CMD
, pwrb_typeoffset
);
5037 hwi_write_buffer(pwrb
, task
);
5039 case ISCSI_OP_LOGOUT
:
5040 ADAPTER_SET_WRB_TYPE(pwrb
, HWH_TYPE_LOGOUT
, pwrb_typeoffset
);
5041 hwi_write_buffer(pwrb
, task
);
5045 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_CONFIG
,
5046 "BM_%d : opcode =%d Not supported\n",
5047 task
->hdr
->opcode
& ISCSI_OPCODE_MASK
);
5052 /* Set the task type */
5053 io_task
->wrb_type
= (is_chip_be2_be3r(phba
)) ?
5054 AMAP_GET_BITS(struct amap_iscsi_wrb
, type
, pwrb
) :
5055 AMAP_GET_BITS(struct amap_iscsi_wrb_v2
, type
, pwrb
);
5057 doorbell
|= cid
& DB_WRB_POST_CID_MASK
;
5058 doorbell
|= (io_task
->pwrb_handle
->wrb_index
&
5059 DB_DEF_PDU_WRB_INDEX_MASK
) << DB_DEF_PDU_WRB_INDEX_SHIFT
;
5060 doorbell
|= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT
;
5061 iowrite32(doorbell
, phba
->db_va
+
5062 beiscsi_conn
->doorbell_offset
);
5066 static int beiscsi_task_xmit(struct iscsi_task
*task
)
5068 struct beiscsi_io_task
*io_task
= task
->dd_data
;
5069 struct scsi_cmnd
*sc
= task
->sc
;
5070 struct beiscsi_hba
*phba
= NULL
;
5071 struct scatterlist
*sg
;
5073 unsigned int writedir
= 0, xferlen
= 0;
5075 phba
= ((struct beiscsi_conn
*)task
->conn
->dd_data
)->phba
;
5078 return beiscsi_mtask(task
);
5080 io_task
->scsi_cmnd
= sc
;
5081 num_sg
= scsi_dma_map(sc
);
5083 struct iscsi_conn
*conn
= task
->conn
;
5084 struct beiscsi_hba
*phba
= NULL
;
5086 phba
= ((struct beiscsi_conn
*)conn
->dd_data
)->phba
;
5087 beiscsi_log(phba
, KERN_ERR
,
5088 BEISCSI_LOG_IO
| BEISCSI_LOG_ISCSI
,
5089 "BM_%d : scsi_dma_map Failed "
5090 "Driver_ITT : 0x%x ITT : 0x%x Xferlen : 0x%x\n",
5091 be32_to_cpu(io_task
->cmd_bhs
->iscsi_hdr
.itt
),
5092 io_task
->libiscsi_itt
, scsi_bufflen(sc
));
5096 xferlen
= scsi_bufflen(sc
);
5097 sg
= scsi_sglist(sc
);
5098 if (sc
->sc_data_direction
== DMA_TO_DEVICE
)
5103 return phba
->iotask_fn(task
, sg
, num_sg
, xferlen
, writedir
);
5107 * beiscsi_bsg_request - handle bsg request from ISCSI transport
5108 * @job: job to handle
5110 static int beiscsi_bsg_request(struct bsg_job
*job
)
5112 struct Scsi_Host
*shost
;
5113 struct beiscsi_hba
*phba
;
5114 struct iscsi_bsg_request
*bsg_req
= job
->request
;
5117 struct be_dma_mem nonemb_cmd
;
5118 struct be_cmd_resp_hdr
*resp
;
5119 struct iscsi_bsg_reply
*bsg_reply
= job
->reply
;
5120 unsigned short status
, extd_status
;
5122 shost
= iscsi_job_to_shost(job
);
5123 phba
= iscsi_host_priv(shost
);
5125 switch (bsg_req
->msgcode
) {
5126 case ISCSI_BSG_HST_VENDOR
:
5127 nonemb_cmd
.va
= pci_alloc_consistent(phba
->ctrl
.pdev
,
5128 job
->request_payload
.payload_len
,
5130 if (nonemb_cmd
.va
== NULL
) {
5131 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_CONFIG
,
5132 "BM_%d : Failed to allocate memory for "
5133 "beiscsi_bsg_request\n");
5136 tag
= mgmt_vendor_specific_fw_cmd(&phba
->ctrl
, phba
, job
,
5139 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_CONFIG
,
5140 "BM_%d : MBX Tag Allocation Failed\n");
5142 pci_free_consistent(phba
->ctrl
.pdev
, nonemb_cmd
.size
,
5143 nonemb_cmd
.va
, nonemb_cmd
.dma
);
5147 rc
= wait_event_interruptible_timeout(
5148 phba
->ctrl
.mcc_wait
[tag
],
5149 phba
->ctrl
.mcc_numtag
[tag
],
5151 BEISCSI_HOST_MBX_TIMEOUT
));
5152 extd_status
= (phba
->ctrl
.mcc_numtag
[tag
] & 0x0000FF00) >> 8;
5153 status
= phba
->ctrl
.mcc_numtag
[tag
] & 0x000000FF;
5154 free_mcc_tag(&phba
->ctrl
, tag
);
5155 resp
= (struct be_cmd_resp_hdr
*)nonemb_cmd
.va
;
5156 sg_copy_from_buffer(job
->reply_payload
.sg_list
,
5157 job
->reply_payload
.sg_cnt
,
5158 nonemb_cmd
.va
, (resp
->response_length
5160 bsg_reply
->reply_payload_rcv_len
= resp
->response_length
;
5161 bsg_reply
->result
= status
;
5162 bsg_job_done(job
, bsg_reply
->result
,
5163 bsg_reply
->reply_payload_rcv_len
);
5164 pci_free_consistent(phba
->ctrl
.pdev
, nonemb_cmd
.size
,
5165 nonemb_cmd
.va
, nonemb_cmd
.dma
);
5166 if (status
|| extd_status
) {
5167 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_CONFIG
,
5168 "BM_%d : MBX Cmd Failed"
5169 " status = %d extd_status = %d\n",
5170 status
, extd_status
);
5179 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_CONFIG
,
5180 "BM_%d : Unsupported bsg command: 0x%x\n",
5188 void beiscsi_hba_attrs_init(struct beiscsi_hba
*phba
)
5190 /* Set the logging parameter */
5191 beiscsi_log_enable_init(phba
, beiscsi_log_enable
);
5195 * beiscsi_quiesce()- Cleanup Driver resources
5196 * @phba: Instance Priv structure
5197 * @unload_state:i Clean or EEH unload state
5199 * Free the OS and HW resources held by the driver
5201 static void beiscsi_quiesce(struct beiscsi_hba
*phba
,
5202 uint32_t unload_state
)
5204 struct hwi_controller
*phwi_ctrlr
;
5205 struct hwi_context_memory
*phwi_context
;
5206 struct be_eq_obj
*pbe_eq
;
5207 unsigned int i
, msix_vec
;
5209 phwi_ctrlr
= phba
->phwi_ctrlr
;
5210 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
5211 hwi_disable_intr(phba
);
5212 if (phba
->msix_enabled
) {
5213 for (i
= 0; i
<= phba
->num_cpus
; i
++) {
5214 msix_vec
= phba
->msix_entries
[i
].vector
;
5215 synchronize_irq(msix_vec
);
5216 free_irq(msix_vec
, &phwi_context
->be_eq
[i
]);
5217 kfree(phba
->msi_name
[i
]);
5220 if (phba
->pcidev
->irq
) {
5221 synchronize_irq(phba
->pcidev
->irq
);
5222 free_irq(phba
->pcidev
->irq
, phba
);
5224 pci_disable_msix(phba
->pcidev
);
5225 cancel_delayed_work_sync(&phba
->beiscsi_hw_check_task
);
5227 for (i
= 0; i
< phba
->num_cpus
; i
++) {
5228 pbe_eq
= &phwi_context
->be_eq
[i
];
5229 blk_iopoll_disable(&pbe_eq
->iopoll
);
5232 if (unload_state
== BEISCSI_CLEAN_UNLOAD
) {
5233 destroy_workqueue(phba
->wq
);
5234 beiscsi_clean_port(phba
);
5235 beiscsi_free_mem(phba
);
5237 beiscsi_unmap_pci_function(phba
);
5238 pci_free_consistent(phba
->pcidev
,
5239 phba
->ctrl
.mbox_mem_alloced
.size
,
5240 phba
->ctrl
.mbox_mem_alloced
.va
,
5241 phba
->ctrl
.mbox_mem_alloced
.dma
);
5249 static void beiscsi_remove(struct pci_dev
*pcidev
)
5252 struct beiscsi_hba
*phba
= NULL
;
5254 phba
= pci_get_drvdata(pcidev
);
5256 dev_err(&pcidev
->dev
, "beiscsi_remove called with no phba\n");
5260 beiscsi_destroy_def_ifaces(phba
);
5261 beiscsi_quiesce(phba
, BEISCSI_CLEAN_UNLOAD
);
5262 iscsi_boot_destroy_kset(phba
->boot_kset
);
5263 iscsi_host_remove(phba
->shost
);
5264 pci_dev_put(phba
->pcidev
);
5265 iscsi_host_free(phba
->shost
);
5266 pci_disable_pcie_error_reporting(pcidev
);
5267 pci_set_drvdata(pcidev
, NULL
);
5268 pci_disable_device(pcidev
);
5271 static void beiscsi_shutdown(struct pci_dev
*pcidev
)
5274 struct beiscsi_hba
*phba
= NULL
;
5276 phba
= (struct beiscsi_hba
*)pci_get_drvdata(pcidev
);
5278 dev_err(&pcidev
->dev
, "beiscsi_shutdown called with no phba\n");
5282 phba
->state
= BE_ADAPTER_STATE_SHUTDOWN
;
5283 iscsi_host_for_each_session(phba
->shost
, be2iscsi_fail_session
);
5284 beiscsi_quiesce(phba
, BEISCSI_CLEAN_UNLOAD
);
5285 pci_disable_device(pcidev
);
5288 static void beiscsi_msix_enable(struct beiscsi_hba
*phba
)
5292 for (i
= 0; i
<= phba
->num_cpus
; i
++)
5293 phba
->msix_entries
[i
].entry
= i
;
5295 status
= pci_enable_msix_range(phba
->pcidev
, phba
->msix_entries
,
5296 phba
->num_cpus
+ 1, phba
->num_cpus
+ 1);
5298 phba
->msix_enabled
= true;
5303 static void be_eqd_update(struct beiscsi_hba
*phba
)
5305 struct be_set_eqd set_eqd
[MAX_CPUS
];
5306 struct be_aic_obj
*aic
;
5307 struct be_eq_obj
*pbe_eq
;
5308 struct hwi_controller
*phwi_ctrlr
;
5309 struct hwi_context_memory
*phwi_context
;
5310 int eqd
, i
, num
= 0;
5315 phwi_ctrlr
= phba
->phwi_ctrlr
;
5316 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
5318 for (i
= 0; i
<= phba
->num_cpus
; i
++) {
5319 aic
= &phba
->aic_obj
[i
];
5320 pbe_eq
= &phwi_context
->be_eq
[i
];
5322 if (!aic
->jiffs
|| time_before(now
, aic
->jiffs
) ||
5323 pbe_eq
->cq_count
< aic
->eq_prev
) {
5325 aic
->eq_prev
= pbe_eq
->cq_count
;
5328 delta
= jiffies_to_msecs(now
- aic
->jiffs
);
5329 pps
= (((u32
)(pbe_eq
->cq_count
- aic
->eq_prev
) * 1000) / delta
);
5330 eqd
= (pps
/ 1500) << 2;
5334 eqd
= min_t(u32
, eqd
, phwi_context
->max_eqd
);
5335 eqd
= max_t(u32
, eqd
, phwi_context
->min_eqd
);
5338 aic
->eq_prev
= pbe_eq
->cq_count
;
5340 if (eqd
!= aic
->prev_eqd
) {
5341 set_eqd
[num
].delay_multiplier
= (eqd
* 65)/100;
5342 set_eqd
[num
].eq_id
= pbe_eq
->q
.id
;
5343 aic
->prev_eqd
= eqd
;
5348 tag
= be_cmd_modify_eq_delay(phba
, set_eqd
, num
);
5350 beiscsi_mccq_compl(phba
, tag
, NULL
, NULL
);
5354 static void be_check_boot_session(struct beiscsi_hba
*phba
)
5356 if (beiscsi_setup_boot_info(phba
))
5357 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5358 "BM_%d : Could not set up "
5359 "iSCSI boot info on async event.\n");
5363 * beiscsi_hw_health_check()- Check adapter health
5364 * @work: work item to check HW health
5366 * Check if adapter in an unrecoverable state or not.
5369 beiscsi_hw_health_check(struct work_struct
*work
)
5371 struct beiscsi_hba
*phba
=
5372 container_of(work
, struct beiscsi_hba
,
5373 beiscsi_hw_check_task
.work
);
5375 be_eqd_update(phba
);
5377 if (phba
->state
& BE_ADAPTER_CHECK_BOOT
) {
5378 phba
->state
&= ~BE_ADAPTER_CHECK_BOOT
;
5379 be_check_boot_session(phba
);
5382 beiscsi_ue_detect(phba
);
5384 schedule_delayed_work(&phba
->beiscsi_hw_check_task
,
5385 msecs_to_jiffies(1000));
5389 static pci_ers_result_t
beiscsi_eeh_err_detected(struct pci_dev
*pdev
,
5390 pci_channel_state_t state
)
5392 struct beiscsi_hba
*phba
= NULL
;
5394 phba
= (struct beiscsi_hba
*)pci_get_drvdata(pdev
);
5395 phba
->state
|= BE_ADAPTER_PCI_ERR
;
5397 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5398 "BM_%d : EEH error detected\n");
5400 beiscsi_quiesce(phba
, BEISCSI_EEH_UNLOAD
);
5402 if (state
== pci_channel_io_perm_failure
) {
5403 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5404 "BM_%d : EEH : State PERM Failure");
5405 return PCI_ERS_RESULT_DISCONNECT
;
5408 pci_disable_device(pdev
);
5410 /* The error could cause the FW to trigger a flash debug dump.
5411 * Resetting the card while flash dump is in progress
5412 * can cause it not to recover; wait for it to finish.
5413 * Wait only for first function as it is needed only once per
5416 if (pdev
->devfn
== 0)
5419 return PCI_ERS_RESULT_NEED_RESET
;
5422 static pci_ers_result_t
beiscsi_eeh_reset(struct pci_dev
*pdev
)
5424 struct beiscsi_hba
*phba
= NULL
;
5427 phba
= (struct beiscsi_hba
*)pci_get_drvdata(pdev
);
5429 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5430 "BM_%d : EEH Reset\n");
5432 status
= pci_enable_device(pdev
);
5434 return PCI_ERS_RESULT_DISCONNECT
;
5436 pci_set_master(pdev
);
5437 pci_set_power_state(pdev
, PCI_D0
);
5438 pci_restore_state(pdev
);
5440 /* Wait for the CHIP Reset to complete */
5441 status
= be_chk_reset_complete(phba
);
5443 beiscsi_log(phba
, KERN_WARNING
, BEISCSI_LOG_INIT
,
5444 "BM_%d : EEH Reset Completed\n");
5446 beiscsi_log(phba
, KERN_WARNING
, BEISCSI_LOG_INIT
,
5447 "BM_%d : EEH Reset Completion Failure\n");
5448 return PCI_ERS_RESULT_DISCONNECT
;
5451 pci_cleanup_aer_uncorrect_error_status(pdev
);
5452 return PCI_ERS_RESULT_RECOVERED
;
5455 static void beiscsi_eeh_resume(struct pci_dev
*pdev
)
5458 struct be_eq_obj
*pbe_eq
;
5459 struct beiscsi_hba
*phba
= NULL
;
5460 struct hwi_controller
*phwi_ctrlr
;
5461 struct hwi_context_memory
*phwi_context
;
5463 phba
= (struct beiscsi_hba
*)pci_get_drvdata(pdev
);
5464 pci_save_state(pdev
);
5467 find_num_cpus(phba
);
5472 beiscsi_msix_enable(phba
);
5473 if (!phba
->msix_enabled
)
5477 ret
= beiscsi_cmd_reset_function(phba
);
5479 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5480 "BM_%d : Reset Failed\n");
5484 ret
= be_chk_reset_complete(phba
);
5486 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5487 "BM_%d : Failed to get out of reset.\n");
5491 beiscsi_get_params(phba
);
5492 phba
->shost
->max_id
= phba
->params
.cxns_per_ctrl
;
5493 phba
->shost
->can_queue
= phba
->params
.ios_per_ctrl
;
5494 ret
= hwi_init_controller(phba
);
5496 for (i
= 0; i
< MAX_MCC_CMD
; i
++) {
5497 init_waitqueue_head(&phba
->ctrl
.mcc_wait
[i
+ 1]);
5498 phba
->ctrl
.mcc_tag
[i
] = i
+ 1;
5499 phba
->ctrl
.mcc_numtag
[i
+ 1] = 0;
5500 phba
->ctrl
.mcc_tag_available
++;
5503 phwi_ctrlr
= phba
->phwi_ctrlr
;
5504 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
5506 for (i
= 0; i
< phba
->num_cpus
; i
++) {
5507 pbe_eq
= &phwi_context
->be_eq
[i
];
5508 blk_iopoll_init(&pbe_eq
->iopoll
, be_iopoll_budget
,
5510 blk_iopoll_enable(&pbe_eq
->iopoll
);
5513 i
= (phba
->msix_enabled
) ? i
: 0;
5514 /* Work item for MCC handling */
5515 pbe_eq
= &phwi_context
->be_eq
[i
];
5516 INIT_WORK(&pbe_eq
->work_cqs
, beiscsi_process_all_cqs
);
5518 ret
= beiscsi_init_irqs(phba
);
5520 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5521 "BM_%d : beiscsi_eeh_resume - "
5522 "Failed to beiscsi_init_irqs\n");
5526 hwi_enable_intr(phba
);
5527 phba
->state
&= ~BE_ADAPTER_PCI_ERR
;
5531 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5532 "BM_%d : AER EEH Resume Failed\n");
5535 static int beiscsi_dev_probe(struct pci_dev
*pcidev
,
5536 const struct pci_device_id
*id
)
5538 struct beiscsi_hba
*phba
= NULL
;
5539 struct hwi_controller
*phwi_ctrlr
;
5540 struct hwi_context_memory
*phwi_context
;
5541 struct be_eq_obj
*pbe_eq
;
5544 ret
= beiscsi_enable_pci(pcidev
);
5546 dev_err(&pcidev
->dev
,
5547 "beiscsi_dev_probe - Failed to enable pci device\n");
5551 phba
= beiscsi_hba_alloc(pcidev
);
5553 dev_err(&pcidev
->dev
,
5554 "beiscsi_dev_probe - Failed in beiscsi_hba_alloc\n");
5558 /* Enable EEH reporting */
5559 ret
= pci_enable_pcie_error_reporting(pcidev
);
5561 beiscsi_log(phba
, KERN_WARNING
, BEISCSI_LOG_INIT
,
5562 "BM_%d : PCIe Error Reporting "
5563 "Enabling Failed\n");
5565 pci_save_state(pcidev
);
5567 /* Initialize Driver configuration Paramters */
5568 beiscsi_hba_attrs_init(phba
);
5570 phba
->fw_timeout
= false;
5571 phba
->mac_addr_set
= false;
5574 switch (pcidev
->device
) {
5578 phba
->generation
= BE_GEN2
;
5579 phba
->iotask_fn
= beiscsi_iotask
;
5583 phba
->generation
= BE_GEN3
;
5584 phba
->iotask_fn
= beiscsi_iotask
;
5587 phba
->generation
= BE_GEN4
;
5588 phba
->iotask_fn
= beiscsi_iotask_v2
;
5591 phba
->generation
= 0;
5594 ret
= be_ctrl_init(phba
, pcidev
);
5596 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5597 "BM_%d : beiscsi_dev_probe-"
5598 "Failed in be_ctrl_init\n");
5602 ret
= beiscsi_cmd_reset_function(phba
);
5604 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5605 "BM_%d : Reset Failed\n");
5608 ret
= be_chk_reset_complete(phba
);
5610 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5611 "BM_%d : Failed to get out of reset.\n");
5615 spin_lock_init(&phba
->io_sgl_lock
);
5616 spin_lock_init(&phba
->mgmt_sgl_lock
);
5617 spin_lock_init(&phba
->isr_lock
);
5618 spin_lock_init(&phba
->async_pdu_lock
);
5619 ret
= mgmt_get_fw_config(&phba
->ctrl
, phba
);
5621 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5622 "BM_%d : Error getting fw config\n");
5627 find_num_cpus(phba
);
5631 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
5632 "BM_%d : num_cpus = %d\n",
5636 beiscsi_msix_enable(phba
);
5637 if (!phba
->msix_enabled
)
5641 phba
->shost
->max_id
= phba
->params
.cxns_per_ctrl
;
5642 beiscsi_get_params(phba
);
5643 phba
->shost
->can_queue
= phba
->params
.ios_per_ctrl
;
5644 ret
= beiscsi_init_port(phba
);
5646 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5647 "BM_%d : beiscsi_dev_probe-"
5648 "Failed in beiscsi_init_port\n");
5652 for (i
= 0; i
< MAX_MCC_CMD
; i
++) {
5653 init_waitqueue_head(&phba
->ctrl
.mcc_wait
[i
+ 1]);
5654 phba
->ctrl
.mcc_tag
[i
] = i
+ 1;
5655 phba
->ctrl
.mcc_numtag
[i
+ 1] = 0;
5656 phba
->ctrl
.mcc_tag_available
++;
5657 memset(&phba
->ctrl
.ptag_state
[i
].tag_mem_state
, 0,
5658 sizeof(struct be_dma_mem
));
5661 phba
->ctrl
.mcc_alloc_index
= phba
->ctrl
.mcc_free_index
= 0;
5663 snprintf(phba
->wq_name
, sizeof(phba
->wq_name
), "beiscsi_%02x_wq",
5664 phba
->shost
->host_no
);
5665 phba
->wq
= alloc_workqueue("%s", WQ_MEM_RECLAIM
, 1, phba
->wq_name
);
5667 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5668 "BM_%d : beiscsi_dev_probe-"
5669 "Failed to allocate work queue\n");
5673 INIT_DELAYED_WORK(&phba
->beiscsi_hw_check_task
,
5674 beiscsi_hw_health_check
);
5676 phwi_ctrlr
= phba
->phwi_ctrlr
;
5677 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
5679 for (i
= 0; i
< phba
->num_cpus
; i
++) {
5680 pbe_eq
= &phwi_context
->be_eq
[i
];
5681 blk_iopoll_init(&pbe_eq
->iopoll
, be_iopoll_budget
,
5683 blk_iopoll_enable(&pbe_eq
->iopoll
);
5686 i
= (phba
->msix_enabled
) ? i
: 0;
5687 /* Work item for MCC handling */
5688 pbe_eq
= &phwi_context
->be_eq
[i
];
5689 INIT_WORK(&pbe_eq
->work_cqs
, beiscsi_process_all_cqs
);
5691 ret
= beiscsi_init_irqs(phba
);
5693 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5694 "BM_%d : beiscsi_dev_probe-"
5695 "Failed to beiscsi_init_irqs\n");
5698 hwi_enable_intr(phba
);
5700 if (iscsi_host_add(phba
->shost
, &phba
->pcidev
->dev
))
5703 if (beiscsi_setup_boot_info(phba
))
5705 * log error but continue, because we may not be using
5708 beiscsi_log(phba
, KERN_ERR
, BEISCSI_LOG_INIT
,
5709 "BM_%d : Could not set up "
5710 "iSCSI boot info.\n");
5712 beiscsi_create_def_ifaces(phba
);
5713 schedule_delayed_work(&phba
->beiscsi_hw_check_task
,
5714 msecs_to_jiffies(1000));
5716 beiscsi_log(phba
, KERN_INFO
, BEISCSI_LOG_INIT
,
5717 "\n\n\n BM_%d : SUCCESS - DRIVER LOADED\n\n\n");
5721 destroy_workqueue(phba
->wq
);
5722 for (i
= 0; i
< phba
->num_cpus
; i
++) {
5723 pbe_eq
= &phwi_context
->be_eq
[i
];
5724 blk_iopoll_disable(&pbe_eq
->iopoll
);
5727 beiscsi_clean_port(phba
);
5728 beiscsi_free_mem(phba
);
5730 pci_free_consistent(phba
->pcidev
,
5731 phba
->ctrl
.mbox_mem_alloced
.size
,
5732 phba
->ctrl
.mbox_mem_alloced
.va
,
5733 phba
->ctrl
.mbox_mem_alloced
.dma
);
5734 beiscsi_unmap_pci_function(phba
);
5736 if (phba
->msix_enabled
)
5737 pci_disable_msix(phba
->pcidev
);
5738 iscsi_host_remove(phba
->shost
);
5739 pci_dev_put(phba
->pcidev
);
5740 iscsi_host_free(phba
->shost
);
5742 pci_disable_device(pcidev
);
5746 static struct pci_error_handlers beiscsi_eeh_handlers
= {
5747 .error_detected
= beiscsi_eeh_err_detected
,
5748 .slot_reset
= beiscsi_eeh_reset
,
5749 .resume
= beiscsi_eeh_resume
,
5752 struct iscsi_transport beiscsi_iscsi_transport
= {
5753 .owner
= THIS_MODULE
,
5755 .caps
= CAP_RECOVERY_L0
| CAP_HDRDGST
| CAP_TEXT_NEGO
|
5756 CAP_MULTI_R2T
| CAP_DATADGST
| CAP_DATA_PATH_OFFLOAD
,
5757 .create_session
= beiscsi_session_create
,
5758 .destroy_session
= beiscsi_session_destroy
,
5759 .create_conn
= beiscsi_conn_create
,
5760 .bind_conn
= beiscsi_conn_bind
,
5761 .destroy_conn
= iscsi_conn_teardown
,
5762 .attr_is_visible
= be2iscsi_attr_is_visible
,
5763 .set_iface_param
= be2iscsi_iface_set_param
,
5764 .get_iface_param
= be2iscsi_iface_get_param
,
5765 .set_param
= beiscsi_set_param
,
5766 .get_conn_param
= iscsi_conn_get_param
,
5767 .get_session_param
= iscsi_session_get_param
,
5768 .get_host_param
= beiscsi_get_host_param
,
5769 .start_conn
= beiscsi_conn_start
,
5770 .stop_conn
= iscsi_conn_stop
,
5771 .send_pdu
= iscsi_conn_send_pdu
,
5772 .xmit_task
= beiscsi_task_xmit
,
5773 .cleanup_task
= beiscsi_cleanup_task
,
5774 .alloc_pdu
= beiscsi_alloc_pdu
,
5775 .parse_pdu_itt
= beiscsi_parse_pdu
,
5776 .get_stats
= beiscsi_conn_get_stats
,
5777 .get_ep_param
= beiscsi_ep_get_param
,
5778 .ep_connect
= beiscsi_ep_connect
,
5779 .ep_poll
= beiscsi_ep_poll
,
5780 .ep_disconnect
= beiscsi_ep_disconnect
,
5781 .session_recovery_timedout
= iscsi_session_recovery_timedout
,
5782 .bsg_request
= beiscsi_bsg_request
,
5785 static struct pci_driver beiscsi_pci_driver
= {
5787 .probe
= beiscsi_dev_probe
,
5788 .remove
= beiscsi_remove
,
5789 .shutdown
= beiscsi_shutdown
,
5790 .id_table
= beiscsi_pci_id_table
,
5791 .err_handler
= &beiscsi_eeh_handlers
5795 static int __init
beiscsi_module_init(void)
5799 beiscsi_scsi_transport
=
5800 iscsi_register_transport(&beiscsi_iscsi_transport
);
5801 if (!beiscsi_scsi_transport
) {
5803 "beiscsi_module_init - Unable to register beiscsi transport.\n");
5806 printk(KERN_INFO
"In beiscsi_module_init, tt=%p\n",
5807 &beiscsi_iscsi_transport
);
5809 ret
= pci_register_driver(&beiscsi_pci_driver
);
5812 "beiscsi_module_init - Unable to register beiscsi pci driver.\n");
5813 goto unregister_iscsi_transport
;
5817 unregister_iscsi_transport
:
5818 iscsi_unregister_transport(&beiscsi_iscsi_transport
);
5822 static void __exit
beiscsi_module_exit(void)
5824 pci_unregister_driver(&beiscsi_pci_driver
);
5825 iscsi_unregister_transport(&beiscsi_iscsi_transport
);
5828 module_init(beiscsi_module_init
);
5829 module_exit(beiscsi_module_exit
);