Jitendra Bhivare | 942b765 | 2017-03-24 14:11:48 +0530 | [diff] [blame] | 1 | /* |
Jitendra Bhivare | 0172dc6 | 2017-10-10 16:18:19 +0530 | [diff] [blame] | 2 | * Copyright 2017 Broadcom. All Rights Reserved. |
Jitendra Bhivare | 942b765 | 2017-03-24 14:11:48 +0530 | [diff] [blame] | 3 | * The term "Broadcom" refers to Broadcom Limited and/or its subsidiaries. |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4 | * |
| 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 |
Jitendra Bhivare | 942b765 | 2017-03-24 14:11:48 +0530 | [diff] [blame] | 7 | * as published by the Free Software Foundation. The full GNU General |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 8 | * Public License is included in this distribution in the file called COPYING. |
| 9 | * |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 10 | * Contact Information: |
Jitendra Bhivare | 60f36e0 | 2016-08-19 15:20:24 +0530 | [diff] [blame] | 11 | * linux-drivers@broadcom.com |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 12 | * |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 13 | */ |
Jayamohan Kallickal | 255fa9a | 2011-03-25 14:23:57 -0700 | [diff] [blame] | 14 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 15 | #include <linux/reboot.h> |
| 16 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 18 | #include <linux/interrupt.h> |
| 19 | #include <linux/blkdev.h> |
| 20 | #include <linux/pci.h> |
| 21 | #include <linux/string.h> |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/semaphore.h> |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 24 | #include <linux/iscsi_boot_sysfs.h> |
Paul Gortmaker | acf3368f | 2011-05-27 09:47:43 -0400 | [diff] [blame] | 25 | #include <linux/module.h> |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 26 | #include <linux/bsg-lib.h> |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 27 | #include <linux/irq_poll.h> |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 28 | |
| 29 | #include <scsi/libiscsi.h> |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 30 | #include <scsi/scsi_bsg_iscsi.h> |
| 31 | #include <scsi/scsi_netlink.h> |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 32 | #include <scsi/scsi_transport_iscsi.h> |
| 33 | #include <scsi/scsi_transport.h> |
| 34 | #include <scsi/scsi_cmnd.h> |
| 35 | #include <scsi/scsi_device.h> |
| 36 | #include <scsi/scsi_host.h> |
| 37 | #include <scsi/scsi.h> |
| 38 | #include "be_main.h" |
| 39 | #include "be_iscsi.h" |
| 40 | #include "be_mgmt.h" |
John Soni Jose | 0a513dd | 2012-08-20 23:00:55 +0530 | [diff] [blame] | 41 | #include "be_cmds.h" |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 42 | |
| 43 | static unsigned int be_iopoll_budget = 10; |
| 44 | static unsigned int be_max_phys_size = 64; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 45 | static unsigned int enable_msix = 1; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 46 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 47 | MODULE_DESCRIPTION(DRV_DESC " " BUILD_STR); |
Jayamohan Kallickal | 76d15db | 2012-04-03 23:41:46 -0500 | [diff] [blame] | 48 | MODULE_VERSION(BUILD_STR); |
Ketan Mukadam | c4f39bd | 2015-07-04 04:12:33 +0530 | [diff] [blame] | 49 | MODULE_AUTHOR("Emulex Corporation"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 50 | MODULE_LICENSE("GPL"); |
| 51 | module_param(be_iopoll_budget, int, 0); |
| 52 | module_param(enable_msix, int, 0); |
| 53 | module_param(be_max_phys_size, uint, S_IRUGO); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 54 | MODULE_PARM_DESC(be_max_phys_size, |
| 55 | "Maximum Size (In Kilobytes) of physically contiguous " |
| 56 | "memory that can be allocated. Range is 16 - 128"); |
| 57 | |
| 58 | #define beiscsi_disp_param(_name)\ |
Baoyou Xie | 0825b8e | 2016-09-26 20:00:59 +0800 | [diff] [blame] | 59 | static ssize_t \ |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 60 | beiscsi_##_name##_disp(struct device *dev,\ |
| 61 | struct device_attribute *attrib, char *buf) \ |
| 62 | { \ |
| 63 | struct Scsi_Host *shost = class_to_shost(dev);\ |
| 64 | struct beiscsi_hba *phba = iscsi_host_priv(shost); \ |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 65 | return snprintf(buf, PAGE_SIZE, "%d\n",\ |
| 66 | phba->attr_##_name);\ |
| 67 | } |
| 68 | |
| 69 | #define beiscsi_change_param(_name, _minval, _maxval, _defaval)\ |
Baoyou Xie | 0825b8e | 2016-09-26 20:00:59 +0800 | [diff] [blame] | 70 | static int \ |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 71 | beiscsi_##_name##_change(struct beiscsi_hba *phba, uint32_t val)\ |
| 72 | {\ |
| 73 | if (val >= _minval && val <= _maxval) {\ |
| 74 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,\ |
| 75 | "BA_%d : beiscsi_"#_name" updated "\ |
| 76 | "from 0x%x ==> 0x%x\n",\ |
| 77 | phba->attr_##_name, val); \ |
| 78 | phba->attr_##_name = val;\ |
| 79 | return 0;\ |
| 80 | } \ |
| 81 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, \ |
| 82 | "BA_%d beiscsi_"#_name" attribute "\ |
| 83 | "cannot be updated to 0x%x, "\ |
| 84 | "range allowed is ["#_minval" - "#_maxval"]\n", val);\ |
| 85 | return -EINVAL;\ |
| 86 | } |
| 87 | |
| 88 | #define beiscsi_store_param(_name) \ |
Baoyou Xie | 0825b8e | 2016-09-26 20:00:59 +0800 | [diff] [blame] | 89 | static ssize_t \ |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 90 | beiscsi_##_name##_store(struct device *dev,\ |
| 91 | struct device_attribute *attr, const char *buf,\ |
| 92 | size_t count) \ |
| 93 | { \ |
| 94 | struct Scsi_Host *shost = class_to_shost(dev);\ |
| 95 | struct beiscsi_hba *phba = iscsi_host_priv(shost);\ |
| 96 | uint32_t param_val = 0;\ |
| 97 | if (!isdigit(buf[0]))\ |
| 98 | return -EINVAL;\ |
| 99 | if (sscanf(buf, "%i", ¶m_val) != 1)\ |
| 100 | return -EINVAL;\ |
| 101 | if (beiscsi_##_name##_change(phba, param_val) == 0) \ |
| 102 | return strlen(buf);\ |
| 103 | else \ |
| 104 | return -EINVAL;\ |
| 105 | } |
| 106 | |
| 107 | #define beiscsi_init_param(_name, _minval, _maxval, _defval) \ |
Baoyou Xie | 0825b8e | 2016-09-26 20:00:59 +0800 | [diff] [blame] | 108 | static int \ |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 109 | beiscsi_##_name##_init(struct beiscsi_hba *phba, uint32_t val) \ |
| 110 | { \ |
| 111 | if (val >= _minval && val <= _maxval) {\ |
| 112 | phba->attr_##_name = val;\ |
| 113 | return 0;\ |
| 114 | } \ |
| 115 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,\ |
| 116 | "BA_%d beiscsi_"#_name" attribute " \ |
| 117 | "cannot be updated to 0x%x, "\ |
| 118 | "range allowed is ["#_minval" - "#_maxval"]\n", val);\ |
| 119 | phba->attr_##_name = _defval;\ |
| 120 | return -EINVAL;\ |
| 121 | } |
| 122 | |
| 123 | #define BEISCSI_RW_ATTR(_name, _minval, _maxval, _defval, _descp) \ |
| 124 | static uint beiscsi_##_name = _defval;\ |
| 125 | module_param(beiscsi_##_name, uint, S_IRUGO);\ |
| 126 | MODULE_PARM_DESC(beiscsi_##_name, _descp);\ |
| 127 | beiscsi_disp_param(_name)\ |
| 128 | beiscsi_change_param(_name, _minval, _maxval, _defval)\ |
| 129 | beiscsi_store_param(_name)\ |
| 130 | beiscsi_init_param(_name, _minval, _maxval, _defval)\ |
| 131 | DEVICE_ATTR(beiscsi_##_name, S_IRUGO | S_IWUSR,\ |
| 132 | beiscsi_##_name##_disp, beiscsi_##_name##_store) |
| 133 | |
| 134 | /* |
| 135 | * When new log level added update the |
| 136 | * the MAX allowed value for log_enable |
| 137 | */ |
| 138 | BEISCSI_RW_ATTR(log_enable, 0x00, |
| 139 | 0xFF, 0x00, "Enable logging Bit Mask\n" |
| 140 | "\t\t\t\tInitialization Events : 0x01\n" |
| 141 | "\t\t\t\tMailbox Events : 0x02\n" |
| 142 | "\t\t\t\tMiscellaneous Events : 0x04\n" |
| 143 | "\t\t\t\tError Handling : 0x08\n" |
| 144 | "\t\t\t\tIO Path Events : 0x10\n" |
Jayamohan Kallickal | afb9605 | 2013-09-28 15:35:55 -0700 | [diff] [blame] | 145 | "\t\t\t\tConfiguration Path : 0x20\n" |
| 146 | "\t\t\t\tiSCSI Protocol : 0x40\n"); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 147 | |
John Soni Jose | 5cac759 | 2012-10-20 04:42:25 +0530 | [diff] [blame] | 148 | DEVICE_ATTR(beiscsi_drvr_ver, S_IRUGO, beiscsi_drvr_ver_disp, NULL); |
John Soni Jose | 26000db | 2012-10-20 04:45:06 +0530 | [diff] [blame] | 149 | DEVICE_ATTR(beiscsi_adapter_family, S_IRUGO, beiscsi_adap_family_disp, NULL); |
Jayamohan Kallickal | 22661e2 | 2013-04-05 20:38:28 -0700 | [diff] [blame] | 150 | DEVICE_ATTR(beiscsi_fw_ver, S_IRUGO, beiscsi_fw_ver_disp, NULL); |
Jayamohan Kallickal | d3fea9a | 2013-09-28 15:35:53 -0700 | [diff] [blame] | 151 | DEVICE_ATTR(beiscsi_phys_port, S_IRUGO, beiscsi_phys_port_disp, NULL); |
Jayamohan Kallickal | 6103c1f | 2013-09-28 15:35:52 -0700 | [diff] [blame] | 152 | DEVICE_ATTR(beiscsi_active_session_count, S_IRUGO, |
| 153 | beiscsi_active_session_disp, NULL); |
| 154 | DEVICE_ATTR(beiscsi_free_session_count, S_IRUGO, |
| 155 | beiscsi_free_session_disp, NULL); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 156 | struct device_attribute *beiscsi_attrs[] = { |
| 157 | &dev_attr_beiscsi_log_enable, |
John Soni Jose | 5cac759 | 2012-10-20 04:42:25 +0530 | [diff] [blame] | 158 | &dev_attr_beiscsi_drvr_ver, |
John Soni Jose | 26000db | 2012-10-20 04:45:06 +0530 | [diff] [blame] | 159 | &dev_attr_beiscsi_adapter_family, |
Jayamohan Kallickal | 22661e2 | 2013-04-05 20:38:28 -0700 | [diff] [blame] | 160 | &dev_attr_beiscsi_fw_ver, |
Jayamohan Kallickal | 6103c1f | 2013-09-28 15:35:52 -0700 | [diff] [blame] | 161 | &dev_attr_beiscsi_active_session_count, |
| 162 | &dev_attr_beiscsi_free_session_count, |
Jayamohan Kallickal | d3fea9a | 2013-09-28 15:35:53 -0700 | [diff] [blame] | 163 | &dev_attr_beiscsi_phys_port, |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 164 | NULL, |
| 165 | }; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 166 | |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 167 | static char const *cqe_desc[] = { |
| 168 | "RESERVED_DESC", |
| 169 | "SOL_CMD_COMPLETE", |
| 170 | "SOL_CMD_KILLED_DATA_DIGEST_ERR", |
| 171 | "CXN_KILLED_PDU_SIZE_EXCEEDS_DSL", |
| 172 | "CXN_KILLED_BURST_LEN_MISMATCH", |
| 173 | "CXN_KILLED_AHS_RCVD", |
| 174 | "CXN_KILLED_HDR_DIGEST_ERR", |
| 175 | "CXN_KILLED_UNKNOWN_HDR", |
| 176 | "CXN_KILLED_STALE_ITT_TTT_RCVD", |
| 177 | "CXN_KILLED_INVALID_ITT_TTT_RCVD", |
| 178 | "CXN_KILLED_RST_RCVD", |
| 179 | "CXN_KILLED_TIMED_OUT", |
| 180 | "CXN_KILLED_RST_SENT", |
| 181 | "CXN_KILLED_FIN_RCVD", |
| 182 | "CXN_KILLED_BAD_UNSOL_PDU_RCVD", |
| 183 | "CXN_KILLED_BAD_WRB_INDEX_ERROR", |
| 184 | "CXN_KILLED_OVER_RUN_RESIDUAL", |
| 185 | "CXN_KILLED_UNDER_RUN_RESIDUAL", |
| 186 | "CMD_KILLED_INVALID_STATSN_RCVD", |
| 187 | "CMD_KILLED_INVALID_R2T_RCVD", |
| 188 | "CMD_CXN_KILLED_LUN_INVALID", |
| 189 | "CMD_CXN_KILLED_ICD_INVALID", |
| 190 | "CMD_CXN_KILLED_ITT_INVALID", |
| 191 | "CMD_CXN_KILLED_SEQ_OUTOFORDER", |
| 192 | "CMD_CXN_KILLED_INVALID_DATASN_RCVD", |
| 193 | "CXN_INVALIDATE_NOTIFY", |
| 194 | "CXN_INVALIDATE_INDEX_NOTIFY", |
| 195 | "CMD_INVALIDATED_NOTIFY", |
| 196 | "UNSOL_HDR_NOTIFY", |
| 197 | "UNSOL_DATA_NOTIFY", |
| 198 | "UNSOL_DATA_DIGEST_ERROR_NOTIFY", |
| 199 | "DRIVERMSG_NOTIFY", |
| 200 | "CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN", |
| 201 | "SOL_CMD_KILLED_DIF_ERR", |
| 202 | "CXN_KILLED_SYN_RCVD", |
| 203 | "CXN_KILLED_IMM_DATA_RCVD" |
| 204 | }; |
| 205 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 206 | static int beiscsi_slave_configure(struct scsi_device *sdev) |
| 207 | { |
| 208 | blk_queue_max_segment_size(sdev->request_queue, 65536); |
| 209 | return 0; |
| 210 | } |
| 211 | |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 212 | static int beiscsi_eh_abort(struct scsi_cmnd *sc) |
| 213 | { |
Jitendra Bhivare | faa0a22 | 2016-12-13 15:55:56 +0530 | [diff] [blame] | 214 | struct iscsi_task *abrt_task = (struct iscsi_task *)sc->SCp.ptr; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 215 | struct iscsi_cls_session *cls_session; |
Jitendra Bhivare | faa0a22 | 2016-12-13 15:55:56 +0530 | [diff] [blame] | 216 | struct beiscsi_io_task *abrt_io_task; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 217 | struct beiscsi_conn *beiscsi_conn; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 218 | struct iscsi_session *session; |
Jitendra Bhivare | f350501 | 2016-12-13 15:55:54 +0530 | [diff] [blame] | 219 | struct invldt_cmd_tbl inv_tbl; |
Jitendra Bhivare | faa0a22 | 2016-12-13 15:55:56 +0530 | [diff] [blame] | 220 | struct beiscsi_hba *phba; |
| 221 | struct iscsi_conn *conn; |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 222 | int rc; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 223 | |
| 224 | cls_session = starget_to_session(scsi_target(sc->device)); |
| 225 | session = cls_session->dd_data; |
| 226 | |
Jitendra Bhivare | faa0a22 | 2016-12-13 15:55:56 +0530 | [diff] [blame] | 227 | /* check if we raced, task just got cleaned up under us */ |
| 228 | spin_lock_bh(&session->back_lock); |
| 229 | if (!abrt_task || !abrt_task->sc) { |
| 230 | spin_unlock_bh(&session->back_lock); |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 231 | return SUCCESS; |
| 232 | } |
Jitendra Bhivare | faa0a22 | 2016-12-13 15:55:56 +0530 | [diff] [blame] | 233 | /* get a task ref till FW processes the req for the ICD used */ |
| 234 | __iscsi_get_task(abrt_task); |
| 235 | abrt_io_task = abrt_task->dd_data; |
| 236 | conn = abrt_task->conn; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 237 | beiscsi_conn = conn->dd_data; |
| 238 | phba = beiscsi_conn->phba; |
Jitendra Bhivare | faa0a22 | 2016-12-13 15:55:56 +0530 | [diff] [blame] | 239 | /* mark WRB invalid which have been not processed by FW yet */ |
Jitendra Bhivare | 392b7d2 | 2016-12-13 15:55:57 +0530 | [diff] [blame] | 240 | if (is_chip_be2_be3r(phba)) { |
| 241 | AMAP_SET_BITS(struct amap_iscsi_wrb, invld, |
| 242 | abrt_io_task->pwrb_handle->pwrb, 1); |
| 243 | } else { |
| 244 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, invld, |
| 245 | abrt_io_task->pwrb_handle->pwrb, 1); |
| 246 | } |
Jitendra Bhivare | faa0a22 | 2016-12-13 15:55:56 +0530 | [diff] [blame] | 247 | inv_tbl.cid = beiscsi_conn->beiscsi_conn_cid; |
| 248 | inv_tbl.icd = abrt_io_task->psgl_handle->sgl_index; |
| 249 | spin_unlock_bh(&session->back_lock); |
| 250 | |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 251 | rc = beiscsi_mgmt_invalidate_icds(phba, &inv_tbl, 1); |
Jitendra Bhivare | faa0a22 | 2016-12-13 15:55:56 +0530 | [diff] [blame] | 252 | iscsi_put_task(abrt_task); |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 253 | if (rc) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 254 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH, |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 255 | "BM_%d : sc %p invalidation failed %d\n", |
| 256 | sc, rc); |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 257 | return FAILED; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 258 | } |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 259 | |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 260 | return iscsi_eh_abort(sc); |
| 261 | } |
| 262 | |
| 263 | static int beiscsi_eh_device_reset(struct scsi_cmnd *sc) |
| 264 | { |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 265 | struct beiscsi_invldt_cmd_tbl { |
| 266 | struct invldt_cmd_tbl tbl[BE_INVLDT_CMD_TBL_SZ]; |
| 267 | struct iscsi_task *task[BE_INVLDT_CMD_TBL_SZ]; |
| 268 | } *inv_tbl; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 269 | struct iscsi_cls_session *cls_session; |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 270 | struct beiscsi_conn *beiscsi_conn; |
| 271 | struct beiscsi_io_task *io_task; |
| 272 | struct iscsi_session *session; |
| 273 | struct beiscsi_hba *phba; |
| 274 | struct iscsi_conn *conn; |
| 275 | struct iscsi_task *task; |
| 276 | unsigned int i, nents; |
Jitendra Bhivare | f350501 | 2016-12-13 15:55:54 +0530 | [diff] [blame] | 277 | int rc, more = 0; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 278 | |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 279 | cls_session = starget_to_session(scsi_target(sc->device)); |
| 280 | session = cls_session->dd_data; |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 281 | |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 282 | spin_lock_bh(&session->frwd_lock); |
Jayamohan Kallickal | db7f770 | 2012-04-03 23:41:43 -0500 | [diff] [blame] | 283 | if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN) { |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 284 | spin_unlock_bh(&session->frwd_lock); |
Jayamohan Kallickal | db7f770 | 2012-04-03 23:41:43 -0500 | [diff] [blame] | 285 | return FAILED; |
| 286 | } |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 287 | |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 288 | conn = session->leadconn; |
| 289 | beiscsi_conn = conn->dd_data; |
| 290 | phba = beiscsi_conn->phba; |
Jitendra Bhivare | f350501 | 2016-12-13 15:55:54 +0530 | [diff] [blame] | 291 | |
Wei Yongjun | f253473 | 2017-01-12 14:21:32 +0000 | [diff] [blame] | 292 | inv_tbl = kzalloc(sizeof(*inv_tbl), GFP_ATOMIC); |
Jitendra Bhivare | f350501 | 2016-12-13 15:55:54 +0530 | [diff] [blame] | 293 | if (!inv_tbl) { |
| 294 | spin_unlock_bh(&session->frwd_lock); |
| 295 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH, |
| 296 | "BM_%d : invldt_cmd_tbl alloc failed\n"); |
| 297 | return FAILED; |
| 298 | } |
| 299 | nents = 0; |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 300 | /* take back_lock to prevent task from getting cleaned up under us */ |
| 301 | spin_lock(&session->back_lock); |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 302 | for (i = 0; i < conn->session->cmds_max; i++) { |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 303 | task = conn->session->cmds[i]; |
| 304 | if (!task->sc) |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 305 | continue; |
| 306 | |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 307 | if (sc->device->lun != task->sc->device->lun) |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 308 | continue; |
Jitendra Bhivare | f350501 | 2016-12-13 15:55:54 +0530 | [diff] [blame] | 309 | /** |
| 310 | * Can't fit in more cmds? Normally this won't happen b'coz |
| 311 | * BEISCSI_CMD_PER_LUN is same as BE_INVLDT_CMD_TBL_SZ. |
| 312 | */ |
| 313 | if (nents == BE_INVLDT_CMD_TBL_SZ) { |
| 314 | more = 1; |
| 315 | break; |
| 316 | } |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 317 | |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 318 | /* get a task ref till FW processes the req for the ICD used */ |
| 319 | __iscsi_get_task(task); |
| 320 | io_task = task->dd_data; |
| 321 | /* mark WRB invalid which have been not processed by FW yet */ |
Jitendra Bhivare | 392b7d2 | 2016-12-13 15:55:57 +0530 | [diff] [blame] | 322 | if (is_chip_be2_be3r(phba)) { |
| 323 | AMAP_SET_BITS(struct amap_iscsi_wrb, invld, |
| 324 | io_task->pwrb_handle->pwrb, 1); |
| 325 | } else { |
| 326 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, invld, |
| 327 | io_task->pwrb_handle->pwrb, 1); |
| 328 | } |
Jayamohan Kallickal | 7626c06 | 2013-09-28 15:35:57 -0700 | [diff] [blame] | 329 | |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 330 | inv_tbl->tbl[nents].cid = beiscsi_conn->beiscsi_conn_cid; |
| 331 | inv_tbl->tbl[nents].icd = io_task->psgl_handle->sgl_index; |
| 332 | inv_tbl->task[nents] = task; |
Jitendra Bhivare | f350501 | 2016-12-13 15:55:54 +0530 | [diff] [blame] | 333 | nents++; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 334 | } |
Jitendra Bhivare | d1e1d63 | 2017-03-24 14:11:42 +0530 | [diff] [blame] | 335 | spin_unlock(&session->back_lock); |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 336 | spin_unlock_bh(&session->frwd_lock); |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 337 | |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 338 | rc = SUCCESS; |
| 339 | if (!nents) |
| 340 | goto end_reset; |
| 341 | |
Jitendra Bhivare | f350501 | 2016-12-13 15:55:54 +0530 | [diff] [blame] | 342 | if (more) { |
| 343 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH, |
| 344 | "BM_%d : number of cmds exceeds size of invalidation table\n"); |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 345 | rc = FAILED; |
| 346 | goto end_reset; |
Jitendra Bhivare | f350501 | 2016-12-13 15:55:54 +0530 | [diff] [blame] | 347 | } |
| 348 | |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 349 | if (beiscsi_mgmt_invalidate_icds(phba, &inv_tbl->tbl[0], nents)) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 350 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH, |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 351 | "BM_%d : cid %u scmds invalidation failed\n", |
| 352 | beiscsi_conn->beiscsi_conn_cid); |
| 353 | rc = FAILED; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 354 | } |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 355 | |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 356 | end_reset: |
| 357 | for (i = 0; i < nents; i++) |
| 358 | iscsi_put_task(inv_tbl->task[i]); |
| 359 | kfree(inv_tbl); |
| 360 | |
| 361 | if (rc == SUCCESS) |
| 362 | rc = iscsi_eh_device_reset(sc); |
| 363 | return rc; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 364 | } |
| 365 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 366 | /*------------------- PCI Driver operations and data ----------------- */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 367 | static const struct pci_device_id beiscsi_pci_id_table[] = { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 368 | { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) }, |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 369 | { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) }, |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 370 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) }, |
| 371 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) }, |
| 372 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID3) }, |
John Soni Jose | 139a1b1 | 2012-10-20 04:43:20 +0530 | [diff] [blame] | 373 | { PCI_DEVICE(ELX_VENDOR_ID, OC_SKH_ID1) }, |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 374 | { 0 } |
| 375 | }; |
| 376 | MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table); |
| 377 | |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 378 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 379 | static struct scsi_host_template beiscsi_sht = { |
| 380 | .module = THIS_MODULE, |
Ketan Mukadam | c4f39bd | 2015-07-04 04:12:33 +0530 | [diff] [blame] | 381 | .name = "Emulex 10Gbe open-iscsi Initiator Driver", |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 382 | .proc_name = DRV_NAME, |
| 383 | .queuecommand = iscsi_queuecommand, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 384 | .change_queue_depth = scsi_change_queue_depth, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 385 | .slave_configure = beiscsi_slave_configure, |
| 386 | .target_alloc = iscsi_target_alloc, |
Christoph Hellwig | b6a05c8 | 2017-01-30 13:18:58 +0100 | [diff] [blame] | 387 | .eh_timed_out = iscsi_eh_cmd_timed_out, |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 388 | .eh_abort_handler = beiscsi_eh_abort, |
| 389 | .eh_device_reset_handler = beiscsi_eh_device_reset, |
Jayamohan Kallickal | 309ce15 | 2010-02-20 08:02:10 +0530 | [diff] [blame] | 390 | .eh_target_reset_handler = iscsi_eh_session_reset, |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 391 | .shost_attrs = beiscsi_attrs, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 392 | .sg_tablesize = BEISCSI_SGLIST_ELEMENTS, |
| 393 | .can_queue = BE2_IO_DEPTH, |
| 394 | .this_id = -1, |
| 395 | .max_sectors = BEISCSI_MAX_SECTORS, |
| 396 | .cmd_per_lun = BEISCSI_CMD_PER_LUN, |
| 397 | .use_clustering = ENABLE_CLUSTERING, |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 398 | .vendor_id = SCSI_NL_VID_TYPE_PCI | BE_VENDOR_ID, |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 399 | .track_queue_depth = 1, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 400 | }; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 401 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 402 | static struct scsi_transport_template *beiscsi_scsi_transport; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 403 | |
| 404 | static struct beiscsi_hba *beiscsi_hba_alloc(struct pci_dev *pcidev) |
| 405 | { |
| 406 | struct beiscsi_hba *phba; |
| 407 | struct Scsi_Host *shost; |
| 408 | |
| 409 | shost = iscsi_host_alloc(&beiscsi_sht, sizeof(*phba), 0); |
| 410 | if (!shost) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 411 | dev_err(&pcidev->dev, |
| 412 | "beiscsi_hba_alloc - iscsi_host_alloc failed\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 413 | return NULL; |
| 414 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 415 | shost->max_id = BE2_MAX_SESSIONS; |
| 416 | shost->max_channel = 0; |
| 417 | shost->max_cmd_len = BEISCSI_MAX_CMD_LEN; |
| 418 | shost->max_lun = BEISCSI_NUM_MAX_LUN; |
| 419 | shost->transportt = beiscsi_scsi_transport; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 420 | phba = iscsi_host_priv(shost); |
| 421 | memset(phba, 0, sizeof(*phba)); |
| 422 | phba->shost = shost; |
| 423 | phba->pcidev = pci_dev_get(pcidev); |
Jayamohan Kallickal | 2807afb | 2010-01-05 05:07:49 +0530 | [diff] [blame] | 424 | pci_set_drvdata(pcidev, phba); |
Mike Christie | 0e43895 | 2012-04-03 23:41:51 -0500 | [diff] [blame] | 425 | phba->interface_handle = 0xFFFFFFFF; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 426 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 427 | return phba; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | static void beiscsi_unmap_pci_function(struct beiscsi_hba *phba) |
| 431 | { |
| 432 | if (phba->csr_va) { |
| 433 | iounmap(phba->csr_va); |
| 434 | phba->csr_va = NULL; |
| 435 | } |
| 436 | if (phba->db_va) { |
| 437 | iounmap(phba->db_va); |
| 438 | phba->db_va = NULL; |
| 439 | } |
| 440 | if (phba->pci_va) { |
| 441 | iounmap(phba->pci_va); |
| 442 | phba->pci_va = NULL; |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | static int beiscsi_map_pci_bars(struct beiscsi_hba *phba, |
| 447 | struct pci_dev *pcidev) |
| 448 | { |
| 449 | u8 __iomem *addr; |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 450 | int pcicfg_reg; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 451 | |
| 452 | addr = ioremap_nocache(pci_resource_start(pcidev, 2), |
| 453 | pci_resource_len(pcidev, 2)); |
| 454 | if (addr == NULL) |
| 455 | return -ENOMEM; |
| 456 | phba->ctrl.csr = addr; |
| 457 | phba->csr_va = addr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 458 | |
| 459 | addr = ioremap_nocache(pci_resource_start(pcidev, 4), 128 * 1024); |
| 460 | if (addr == NULL) |
| 461 | goto pci_map_err; |
| 462 | phba->ctrl.db = addr; |
| 463 | phba->db_va = addr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 464 | |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 465 | if (phba->generation == BE_GEN2) |
| 466 | pcicfg_reg = 1; |
| 467 | else |
| 468 | pcicfg_reg = 0; |
| 469 | |
| 470 | addr = ioremap_nocache(pci_resource_start(pcidev, pcicfg_reg), |
| 471 | pci_resource_len(pcidev, pcicfg_reg)); |
| 472 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 473 | if (addr == NULL) |
| 474 | goto pci_map_err; |
| 475 | phba->ctrl.pcicfg = addr; |
| 476 | phba->pci_va = addr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 477 | return 0; |
| 478 | |
| 479 | pci_map_err: |
| 480 | beiscsi_unmap_pci_function(phba); |
| 481 | return -ENOMEM; |
| 482 | } |
| 483 | |
| 484 | static int beiscsi_enable_pci(struct pci_dev *pcidev) |
| 485 | { |
| 486 | int ret; |
| 487 | |
| 488 | ret = pci_enable_device(pcidev); |
| 489 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 490 | dev_err(&pcidev->dev, |
| 491 | "beiscsi_enable_pci - enable device failed\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 492 | return ret; |
| 493 | } |
| 494 | |
John Soni Jose | e307f3a | 2015-04-25 08:17:19 +0530 | [diff] [blame] | 495 | ret = pci_request_regions(pcidev, DRV_NAME); |
| 496 | if (ret) { |
| 497 | dev_err(&pcidev->dev, |
| 498 | "beiscsi_enable_pci - request region failed\n"); |
| 499 | goto pci_dev_disable; |
| 500 | } |
| 501 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 502 | pci_set_master(pcidev); |
Jayamohan Kallickal | 6c57625b | 2014-01-29 02:16:45 -0500 | [diff] [blame] | 503 | ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(64)); |
| 504 | if (ret) { |
| 505 | ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(32)); |
| 506 | if (ret) { |
| 507 | dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n"); |
John Soni Jose | e307f3a | 2015-04-25 08:17:19 +0530 | [diff] [blame] | 508 | goto pci_region_release; |
Jayamohan Kallickal | 6c57625b | 2014-01-29 02:16:45 -0500 | [diff] [blame] | 509 | } else { |
| 510 | ret = pci_set_consistent_dma_mask(pcidev, |
| 511 | DMA_BIT_MASK(32)); |
| 512 | } |
| 513 | } else { |
| 514 | ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 515 | if (ret) { |
| 516 | dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n"); |
John Soni Jose | e307f3a | 2015-04-25 08:17:19 +0530 | [diff] [blame] | 517 | goto pci_region_release; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 518 | } |
| 519 | } |
| 520 | return 0; |
John Soni Jose | e307f3a | 2015-04-25 08:17:19 +0530 | [diff] [blame] | 521 | |
| 522 | pci_region_release: |
| 523 | pci_release_regions(pcidev); |
| 524 | pci_dev_disable: |
| 525 | pci_disable_device(pcidev); |
| 526 | |
| 527 | return ret; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | static int be_ctrl_init(struct beiscsi_hba *phba, struct pci_dev *pdev) |
| 531 | { |
| 532 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 533 | struct be_dma_mem *mbox_mem_alloc = &ctrl->mbox_mem_alloced; |
| 534 | struct be_dma_mem *mbox_mem_align = &ctrl->mbox_mem; |
| 535 | int status = 0; |
| 536 | |
| 537 | ctrl->pdev = pdev; |
| 538 | status = beiscsi_map_pci_bars(phba, pdev); |
| 539 | if (status) |
| 540 | return status; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 541 | mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16; |
| 542 | mbox_mem_alloc->va = pci_alloc_consistent(pdev, |
| 543 | mbox_mem_alloc->size, |
| 544 | &mbox_mem_alloc->dma); |
| 545 | if (!mbox_mem_alloc->va) { |
| 546 | beiscsi_unmap_pci_function(phba); |
Jayamohan Kallickal | a49e06d | 2012-04-03 23:41:44 -0500 | [diff] [blame] | 547 | return -ENOMEM; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | mbox_mem_align->size = sizeof(struct be_mcc_mailbox); |
| 551 | mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16); |
| 552 | mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16); |
| 553 | memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox)); |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 554 | mutex_init(&ctrl->mbox_lock); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 555 | spin_lock_init(&phba->ctrl.mcc_lock); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 556 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 557 | return status; |
| 558 | } |
| 559 | |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 560 | /** |
| 561 | * beiscsi_get_params()- Set the config paramters |
| 562 | * @phba: ptr device priv structure |
| 563 | **/ |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 564 | static void beiscsi_get_params(struct beiscsi_hba *phba) |
| 565 | { |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 566 | uint32_t total_cid_count = 0; |
| 567 | uint32_t total_icd_count = 0; |
| 568 | uint8_t ulp_num = 0; |
| 569 | |
| 570 | total_cid_count = BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP0) + |
| 571 | BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP1); |
| 572 | |
Jayamohan Kallickal | cf987b7 | 2013-09-28 15:35:59 -0700 | [diff] [blame] | 573 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 574 | uint32_t align_mask = 0; |
| 575 | uint32_t icd_post_per_page = 0; |
| 576 | uint32_t icd_count_unavailable = 0; |
| 577 | uint32_t icd_start = 0, icd_count = 0; |
| 578 | uint32_t icd_start_align = 0, icd_count_align = 0; |
| 579 | |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 580 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
Jayamohan Kallickal | cf987b7 | 2013-09-28 15:35:59 -0700 | [diff] [blame] | 581 | icd_start = phba->fw_config.iscsi_icd_start[ulp_num]; |
| 582 | icd_count = phba->fw_config.iscsi_icd_count[ulp_num]; |
| 583 | |
| 584 | /* Get ICD count that can be posted on each page */ |
| 585 | icd_post_per_page = (PAGE_SIZE / (BE2_SGE * |
| 586 | sizeof(struct iscsi_sge))); |
| 587 | align_mask = (icd_post_per_page - 1); |
| 588 | |
| 589 | /* Check if icd_start is aligned ICD per page posting */ |
| 590 | if (icd_start % icd_post_per_page) { |
| 591 | icd_start_align = ((icd_start + |
| 592 | icd_post_per_page) & |
| 593 | ~(align_mask)); |
| 594 | phba->fw_config. |
| 595 | iscsi_icd_start[ulp_num] = |
| 596 | icd_start_align; |
| 597 | } |
| 598 | |
| 599 | icd_count_align = (icd_count & ~align_mask); |
| 600 | |
| 601 | /* ICD discarded in the process of alignment */ |
| 602 | if (icd_start_align) |
| 603 | icd_count_unavailable = ((icd_start_align - |
| 604 | icd_start) + |
| 605 | (icd_count - |
| 606 | icd_count_align)); |
| 607 | |
| 608 | /* Updated ICD count available */ |
| 609 | phba->fw_config.iscsi_icd_count[ulp_num] = (icd_count - |
| 610 | icd_count_unavailable); |
| 611 | |
| 612 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 613 | "BM_%d : Aligned ICD values\n" |
| 614 | "\t ICD Start : %d\n" |
| 615 | "\t ICD Count : %d\n" |
| 616 | "\t ICD Discarded : %d\n", |
| 617 | phba->fw_config. |
| 618 | iscsi_icd_start[ulp_num], |
| 619 | phba->fw_config. |
| 620 | iscsi_icd_count[ulp_num], |
| 621 | icd_count_unavailable); |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 622 | break; |
| 623 | } |
Jayamohan Kallickal | cf987b7 | 2013-09-28 15:35:59 -0700 | [diff] [blame] | 624 | } |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 625 | |
Jayamohan Kallickal | cf987b7 | 2013-09-28 15:35:59 -0700 | [diff] [blame] | 626 | total_icd_count = phba->fw_config.iscsi_icd_count[ulp_num]; |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 627 | phba->params.ios_per_ctrl = (total_icd_count - |
| 628 | (total_cid_count + |
| 629 | BE2_TMFS + BE2_NOPOUT_REQ)); |
| 630 | phba->params.cxns_per_ctrl = total_cid_count; |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 631 | phba->params.icds_per_ctrl = total_icd_count; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 632 | phba->params.num_sge_per_io = BE2_SGE; |
| 633 | phba->params.defpdu_hdr_sz = BE2_DEFPDU_HDR_SZ; |
| 634 | phba->params.defpdu_data_sz = BE2_DEFPDU_DATA_SZ; |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 635 | phba->params.num_eq_entries = 1024; |
| 636 | phba->params.num_cq_entries = 1024; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 637 | phba->params.wrbs_per_cxn = 256; |
| 638 | } |
| 639 | |
| 640 | static void hwi_ring_eq_db(struct beiscsi_hba *phba, |
| 641 | unsigned int id, unsigned int clr_interrupt, |
| 642 | unsigned int num_processed, |
| 643 | unsigned char rearm, unsigned char event) |
| 644 | { |
| 645 | u32 val = 0; |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 646 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 647 | if (rearm) |
| 648 | val |= 1 << DB_EQ_REARM_SHIFT; |
| 649 | if (clr_interrupt) |
| 650 | val |= 1 << DB_EQ_CLR_SHIFT; |
| 651 | if (event) |
| 652 | val |= 1 << DB_EQ_EVNT_SHIFT; |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 653 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 654 | val |= num_processed << DB_EQ_NUM_POPPED_SHIFT; |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 655 | /* Setting lower order EQ_ID Bits */ |
| 656 | val |= (id & DB_EQ_RING_ID_LOW_MASK); |
| 657 | |
| 658 | /* Setting Higher order EQ_ID Bits */ |
| 659 | val |= (((id >> DB_EQ_HIGH_FEILD_SHIFT) & |
| 660 | DB_EQ_RING_ID_HIGH_MASK) |
| 661 | << DB_EQ_HIGH_SET_SHIFT); |
| 662 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 663 | iowrite32(val, phba->db_va + DB_EQ_OFFSET); |
| 664 | } |
| 665 | |
| 666 | /** |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 667 | * be_isr_mcc - The isr routine of the driver. |
| 668 | * @irq: Not used |
| 669 | * @dev_id: Pointer to host adapter structure |
| 670 | */ |
| 671 | static irqreturn_t be_isr_mcc(int irq, void *dev_id) |
| 672 | { |
| 673 | struct beiscsi_hba *phba; |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 674 | struct be_eq_entry *eqe; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 675 | struct be_queue_info *eq; |
| 676 | struct be_queue_info *mcc; |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 677 | unsigned int mcc_events; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 678 | struct be_eq_obj *pbe_eq; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 679 | |
| 680 | pbe_eq = dev_id; |
| 681 | eq = &pbe_eq->q; |
| 682 | phba = pbe_eq->phba; |
| 683 | mcc = &phba->ctrl.mcc_obj.cq; |
| 684 | eqe = queue_tail_node(eq); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 685 | |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 686 | mcc_events = 0; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 687 | while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32] |
| 688 | & EQE_VALID_MASK) { |
| 689 | if (((eqe->dw[offsetof(struct amap_eq_entry, |
| 690 | resource_id) / 32] & |
| 691 | EQE_RESID_MASK) >> 16) == mcc->id) { |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 692 | mcc_events++; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 693 | } |
| 694 | AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0); |
| 695 | queue_tail_inc(eq); |
| 696 | eqe = queue_tail_node(eq); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 697 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 698 | |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 699 | if (mcc_events) { |
| 700 | queue_work(phba->wq, &pbe_eq->mcc_work); |
| 701 | hwi_ring_eq_db(phba, eq->id, 1, mcc_events, 1, 1); |
| 702 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 703 | return IRQ_HANDLED; |
| 704 | } |
| 705 | |
| 706 | /** |
| 707 | * be_isr_msix - The isr routine of the driver. |
| 708 | * @irq: Not used |
| 709 | * @dev_id: Pointer to host adapter structure |
| 710 | */ |
| 711 | static irqreturn_t be_isr_msix(int irq, void *dev_id) |
| 712 | { |
| 713 | struct beiscsi_hba *phba; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 714 | struct be_queue_info *eq; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 715 | struct be_eq_obj *pbe_eq; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 716 | |
| 717 | pbe_eq = dev_id; |
| 718 | eq = &pbe_eq->q; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 719 | |
| 720 | phba = pbe_eq->phba; |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 721 | /* disable interrupt till iopoll completes */ |
| 722 | hwi_ring_eq_db(phba, eq->id, 1, 0, 0, 1); |
| 723 | irq_poll_sched(&pbe_eq->iopoll); |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 724 | |
| 725 | return IRQ_HANDLED; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | /** |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 729 | * be_isr - The isr routine of the driver. |
| 730 | * @irq: Not used |
| 731 | * @dev_id: Pointer to host adapter structure |
| 732 | */ |
| 733 | static irqreturn_t be_isr(int irq, void *dev_id) |
| 734 | { |
| 735 | struct beiscsi_hba *phba; |
| 736 | struct hwi_controller *phwi_ctrlr; |
| 737 | struct hwi_context_memory *phwi_context; |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 738 | struct be_eq_entry *eqe; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 739 | struct be_queue_info *eq; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 740 | struct be_queue_info *mcc; |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 741 | unsigned int mcc_events, io_events; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 742 | struct be_ctrl_info *ctrl; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 743 | struct be_eq_obj *pbe_eq; |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 744 | int isr, rearm; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 745 | |
| 746 | phba = dev_id; |
Justin P. Mattock | 6eab04a | 2011-04-08 19:49:08 -0700 | [diff] [blame] | 747 | ctrl = &phba->ctrl; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 748 | isr = ioread32(ctrl->csr + CEV_ISR0_OFFSET + |
| 749 | (PCI_FUNC(ctrl->pdev->devfn) * CEV_ISR_SIZE)); |
| 750 | if (!isr) |
| 751 | return IRQ_NONE; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 752 | |
| 753 | phwi_ctrlr = phba->phwi_ctrlr; |
| 754 | phwi_context = phwi_ctrlr->phwi_ctxt; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 755 | pbe_eq = &phwi_context->be_eq[0]; |
| 756 | |
| 757 | eq = &phwi_context->be_eq[0].q; |
| 758 | mcc = &phba->ctrl.mcc_obj.cq; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 759 | eqe = queue_tail_node(eq); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 760 | |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 761 | io_events = 0; |
| 762 | mcc_events = 0; |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 763 | while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32] |
| 764 | & EQE_VALID_MASK) { |
| 765 | if (((eqe->dw[offsetof(struct amap_eq_entry, |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 766 | resource_id) / 32] & EQE_RESID_MASK) >> 16) == mcc->id) |
| 767 | mcc_events++; |
| 768 | else |
| 769 | io_events++; |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 770 | AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0); |
| 771 | queue_tail_inc(eq); |
| 772 | eqe = queue_tail_node(eq); |
| 773 | } |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 774 | if (!io_events && !mcc_events) |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 775 | return IRQ_NONE; |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 776 | |
| 777 | /* no need to rearm if interrupt is only for IOs */ |
| 778 | rearm = 0; |
| 779 | if (mcc_events) { |
| 780 | queue_work(phba->wq, &pbe_eq->mcc_work); |
| 781 | /* rearm for MCCQ */ |
| 782 | rearm = 1; |
| 783 | } |
| 784 | if (io_events) |
| 785 | irq_poll_sched(&pbe_eq->iopoll); |
| 786 | hwi_ring_eq_db(phba, eq->id, 0, (io_events + mcc_events), rearm, 1); |
| 787 | return IRQ_HANDLED; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 788 | } |
| 789 | |
Jitendra Bhivare | 45371aa | 2017-10-10 16:18:13 +0530 | [diff] [blame] | 790 | static void beiscsi_free_irqs(struct beiscsi_hba *phba) |
| 791 | { |
| 792 | struct hwi_context_memory *phwi_context; |
| 793 | int i; |
| 794 | |
| 795 | if (!phba->pcidev->msix_enabled) { |
| 796 | if (phba->pcidev->irq) |
| 797 | free_irq(phba->pcidev->irq, phba); |
| 798 | return; |
| 799 | } |
| 800 | |
| 801 | phwi_context = phba->phwi_ctrlr->phwi_ctxt; |
| 802 | for (i = 0; i <= phba->num_cpus; i++) { |
| 803 | free_irq(pci_irq_vector(phba->pcidev, i), |
| 804 | &phwi_context->be_eq[i]); |
| 805 | kfree(phba->msi_name[i]); |
| 806 | } |
| 807 | } |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 808 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 809 | static int beiscsi_init_irqs(struct beiscsi_hba *phba) |
| 810 | { |
| 811 | struct pci_dev *pcidev = phba->pcidev; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 812 | struct hwi_controller *phwi_ctrlr; |
| 813 | struct hwi_context_memory *phwi_context; |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 814 | int ret, i, j; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 815 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 816 | phwi_ctrlr = phba->phwi_ctrlr; |
| 817 | phwi_context = phwi_ctrlr->phwi_ctxt; |
| 818 | |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 819 | if (pcidev->msix_enabled) { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 820 | for (i = 0; i < phba->num_cpus; i++) { |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 821 | phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME, |
| 822 | GFP_KERNEL); |
| 823 | if (!phba->msi_name[i]) { |
| 824 | ret = -ENOMEM; |
| 825 | goto free_msix_irqs; |
| 826 | } |
| 827 | |
| 828 | sprintf(phba->msi_name[i], "beiscsi_%02x_%02x", |
| 829 | phba->shost->host_no, i); |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 830 | ret = request_irq(pci_irq_vector(pcidev, i), |
| 831 | be_isr_msix, 0, phba->msi_name[i], |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 832 | &phwi_context->be_eq[i]); |
Jayamohan Kallickal | 4f5af07 | 2010-07-22 04:23:55 +0530 | [diff] [blame] | 833 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 834 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 835 | "BM_%d : beiscsi_init_irqs-Failed to" |
| 836 | "register msix for i = %d\n", |
| 837 | i); |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 838 | kfree(phba->msi_name[i]); |
Jayamohan Kallickal | 4f5af07 | 2010-07-22 04:23:55 +0530 | [diff] [blame] | 839 | goto free_msix_irqs; |
| 840 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 841 | } |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 842 | phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME, GFP_KERNEL); |
| 843 | if (!phba->msi_name[i]) { |
| 844 | ret = -ENOMEM; |
| 845 | goto free_msix_irqs; |
| 846 | } |
| 847 | sprintf(phba->msi_name[i], "beiscsi_mcc_%02x", |
| 848 | phba->shost->host_no); |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 849 | ret = request_irq(pci_irq_vector(pcidev, i), be_isr_mcc, 0, |
| 850 | phba->msi_name[i], &phwi_context->be_eq[i]); |
Jayamohan Kallickal | 4f5af07 | 2010-07-22 04:23:55 +0530 | [diff] [blame] | 851 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 852 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT , |
| 853 | "BM_%d : beiscsi_init_irqs-" |
| 854 | "Failed to register beiscsi_msix_mcc\n"); |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 855 | kfree(phba->msi_name[i]); |
Jayamohan Kallickal | 4f5af07 | 2010-07-22 04:23:55 +0530 | [diff] [blame] | 856 | goto free_msix_irqs; |
| 857 | } |
| 858 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 859 | } else { |
| 860 | ret = request_irq(pcidev->irq, be_isr, IRQF_SHARED, |
| 861 | "beiscsi", phba); |
| 862 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 863 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 864 | "BM_%d : beiscsi_init_irqs-" |
| 865 | "Failed to register irq\\n"); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 866 | return ret; |
| 867 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 868 | } |
| 869 | return 0; |
Jayamohan Kallickal | 4f5af07 | 2010-07-22 04:23:55 +0530 | [diff] [blame] | 870 | free_msix_irqs: |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 871 | for (j = i - 1; j >= 0; j--) { |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 872 | free_irq(pci_irq_vector(pcidev, i), &phwi_context->be_eq[j]); |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 873 | kfree(phba->msi_name[j]); |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 874 | } |
Jayamohan Kallickal | 4f5af07 | 2010-07-22 04:23:55 +0530 | [diff] [blame] | 875 | return ret; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 876 | } |
| 877 | |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 878 | void hwi_ring_cq_db(struct beiscsi_hba *phba, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 879 | unsigned int id, unsigned int num_processed, |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 880 | unsigned char rearm) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 881 | { |
| 882 | u32 val = 0; |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 883 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 884 | if (rearm) |
| 885 | val |= 1 << DB_CQ_REARM_SHIFT; |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 886 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 887 | val |= num_processed << DB_CQ_NUM_POPPED_SHIFT; |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 888 | |
| 889 | /* Setting lower order CQ_ID Bits */ |
| 890 | val |= (id & DB_CQ_RING_ID_LOW_MASK); |
| 891 | |
| 892 | /* Setting Higher order CQ_ID Bits */ |
| 893 | val |= (((id >> DB_CQ_HIGH_FEILD_SHIFT) & |
| 894 | DB_CQ_RING_ID_HIGH_MASK) |
| 895 | << DB_CQ_HIGH_SET_SHIFT); |
| 896 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 897 | iowrite32(val, phba->db_va + DB_CQ_OFFSET); |
| 898 | } |
| 899 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 900 | static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba) |
| 901 | { |
| 902 | struct sgl_handle *psgl_handle; |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 903 | unsigned long flags; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 904 | |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 905 | spin_lock_irqsave(&phba->io_sgl_lock, flags); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 906 | if (phba->io_sgl_hndl_avbl) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 907 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO, |
| 908 | "BM_%d : In alloc_io_sgl_handle," |
| 909 | " io_sgl_alloc_index=%d\n", |
| 910 | phba->io_sgl_alloc_index); |
| 911 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 912 | psgl_handle = phba->io_sgl_hndl_base[phba-> |
| 913 | io_sgl_alloc_index]; |
| 914 | phba->io_sgl_hndl_base[phba->io_sgl_alloc_index] = NULL; |
| 915 | phba->io_sgl_hndl_avbl--; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 916 | if (phba->io_sgl_alloc_index == (phba->params. |
| 917 | ios_per_ctrl - 1)) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 918 | phba->io_sgl_alloc_index = 0; |
| 919 | else |
| 920 | phba->io_sgl_alloc_index++; |
| 921 | } else |
| 922 | psgl_handle = NULL; |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 923 | spin_unlock_irqrestore(&phba->io_sgl_lock, flags); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 924 | return psgl_handle; |
| 925 | } |
| 926 | |
| 927 | static void |
| 928 | free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle) |
| 929 | { |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 930 | unsigned long flags; |
| 931 | |
| 932 | spin_lock_irqsave(&phba->io_sgl_lock, flags); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 933 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO, |
| 934 | "BM_%d : In free_,io_sgl_free_index=%d\n", |
| 935 | phba->io_sgl_free_index); |
| 936 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 937 | if (phba->io_sgl_hndl_base[phba->io_sgl_free_index]) { |
| 938 | /* |
| 939 | * this can happen if clean_task is called on a task that |
| 940 | * failed in xmit_task or alloc_pdu. |
| 941 | */ |
Jitendra Bhivare | 45efc940 | 2017-10-10 16:18:18 +0530 | [diff] [blame] | 942 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO, |
| 943 | "BM_%d : Double Free in IO SGL io_sgl_free_index=%d, value there=%p\n", |
| 944 | phba->io_sgl_free_index, |
| 945 | phba->io_sgl_hndl_base[phba->io_sgl_free_index]); |
| 946 | spin_unlock_irqrestore(&phba->io_sgl_lock, flags); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 947 | return; |
| 948 | } |
| 949 | phba->io_sgl_hndl_base[phba->io_sgl_free_index] = psgl_handle; |
| 950 | phba->io_sgl_hndl_avbl++; |
| 951 | if (phba->io_sgl_free_index == (phba->params.ios_per_ctrl - 1)) |
| 952 | phba->io_sgl_free_index = 0; |
| 953 | else |
| 954 | phba->io_sgl_free_index++; |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 955 | spin_unlock_irqrestore(&phba->io_sgl_lock, flags); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 956 | } |
| 957 | |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame] | 958 | static inline struct wrb_handle * |
| 959 | beiscsi_get_wrb_handle(struct hwi_wrb_context *pwrb_context, |
| 960 | unsigned int wrbs_per_cxn) |
| 961 | { |
| 962 | struct wrb_handle *pwrb_handle; |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 963 | unsigned long flags; |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame] | 964 | |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 965 | spin_lock_irqsave(&pwrb_context->wrb_lock, flags); |
Jitendra Bhivare | 3f7f62e | 2016-12-13 15:55:58 +0530 | [diff] [blame] | 966 | if (!pwrb_context->wrb_handles_available) { |
| 967 | spin_unlock_irqrestore(&pwrb_context->wrb_lock, flags); |
| 968 | return NULL; |
| 969 | } |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame] | 970 | pwrb_handle = pwrb_context->pwrb_handle_base[pwrb_context->alloc_index]; |
| 971 | pwrb_context->wrb_handles_available--; |
| 972 | if (pwrb_context->alloc_index == (wrbs_per_cxn - 1)) |
| 973 | pwrb_context->alloc_index = 0; |
| 974 | else |
| 975 | pwrb_context->alloc_index++; |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 976 | spin_unlock_irqrestore(&pwrb_context->wrb_lock, flags); |
Jitendra Bhivare | bf9b755 | 2016-08-26 15:09:07 +0530 | [diff] [blame] | 977 | |
| 978 | if (pwrb_handle) |
| 979 | memset(pwrb_handle->pwrb, 0, sizeof(*pwrb_handle->pwrb)); |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame] | 980 | |
| 981 | return pwrb_handle; |
| 982 | } |
| 983 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 984 | /** |
| 985 | * alloc_wrb_handle - To allocate a wrb handle |
| 986 | * @phba: The hba pointer |
| 987 | * @cid: The cid to use for allocation |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 988 | * @pwrb_context: ptr to ptr to wrb context |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 989 | * |
| 990 | * This happens under session_lock until submission to chip |
| 991 | */ |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 992 | struct wrb_handle *alloc_wrb_handle(struct beiscsi_hba *phba, unsigned int cid, |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame] | 993 | struct hwi_wrb_context **pcontext) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 994 | { |
| 995 | struct hwi_wrb_context *pwrb_context; |
| 996 | struct hwi_controller *phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 997 | uint16_t cri_index = BE_GET_CRI_FROM_CID(cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 998 | |
| 999 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 1000 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame] | 1001 | /* return the context address */ |
| 1002 | *pcontext = pwrb_context; |
| 1003 | return beiscsi_get_wrb_handle(pwrb_context, phba->params.wrbs_per_cxn); |
| 1004 | } |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 1005 | |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame] | 1006 | static inline void |
| 1007 | beiscsi_put_wrb_handle(struct hwi_wrb_context *pwrb_context, |
| 1008 | struct wrb_handle *pwrb_handle, |
| 1009 | unsigned int wrbs_per_cxn) |
| 1010 | { |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 1011 | unsigned long flags; |
| 1012 | |
| 1013 | spin_lock_irqsave(&pwrb_context->wrb_lock, flags); |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame] | 1014 | pwrb_context->pwrb_handle_base[pwrb_context->free_index] = pwrb_handle; |
| 1015 | pwrb_context->wrb_handles_available++; |
| 1016 | if (pwrb_context->free_index == (wrbs_per_cxn - 1)) |
| 1017 | pwrb_context->free_index = 0; |
| 1018 | else |
| 1019 | pwrb_context->free_index++; |
Jitendra Bhivare | 3f7f62e | 2016-12-13 15:55:58 +0530 | [diff] [blame] | 1020 | pwrb_handle->pio_handle = NULL; |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 1021 | spin_unlock_irqrestore(&pwrb_context->wrb_lock, flags); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | /** |
| 1025 | * free_wrb_handle - To free the wrb handle back to pool |
| 1026 | * @phba: The hba pointer |
| 1027 | * @pwrb_context: The context to free from |
| 1028 | * @pwrb_handle: The wrb_handle to free |
| 1029 | * |
| 1030 | * This happens under session_lock until submission to chip |
| 1031 | */ |
| 1032 | static void |
| 1033 | free_wrb_handle(struct beiscsi_hba *phba, struct hwi_wrb_context *pwrb_context, |
| 1034 | struct wrb_handle *pwrb_handle) |
| 1035 | { |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame] | 1036 | beiscsi_put_wrb_handle(pwrb_context, |
| 1037 | pwrb_handle, |
| 1038 | phba->params.wrbs_per_cxn); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1039 | beiscsi_log(phba, KERN_INFO, |
| 1040 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
| 1041 | "BM_%d : FREE WRB: pwrb_handle=%p free_index=0x%x" |
| 1042 | "wrb_handles_available=%d\n", |
| 1043 | pwrb_handle, pwrb_context->free_index, |
| 1044 | pwrb_context->wrb_handles_available); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba) |
| 1048 | { |
| 1049 | struct sgl_handle *psgl_handle; |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 1050 | unsigned long flags; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1051 | |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 1052 | spin_lock_irqsave(&phba->mgmt_sgl_lock, flags); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1053 | if (phba->eh_sgl_hndl_avbl) { |
| 1054 | psgl_handle = phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index]; |
| 1055 | phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index] = NULL; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1056 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG, |
| 1057 | "BM_%d : mgmt_sgl_alloc_index=%d=0x%x\n", |
| 1058 | phba->eh_sgl_alloc_index, |
| 1059 | phba->eh_sgl_alloc_index); |
| 1060 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1061 | phba->eh_sgl_hndl_avbl--; |
| 1062 | if (phba->eh_sgl_alloc_index == |
| 1063 | (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl - |
| 1064 | 1)) |
| 1065 | phba->eh_sgl_alloc_index = 0; |
| 1066 | else |
| 1067 | phba->eh_sgl_alloc_index++; |
| 1068 | } else |
| 1069 | psgl_handle = NULL; |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 1070 | spin_unlock_irqrestore(&phba->mgmt_sgl_lock, flags); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1071 | return psgl_handle; |
| 1072 | } |
| 1073 | |
| 1074 | void |
| 1075 | free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle) |
| 1076 | { |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 1077 | unsigned long flags; |
| 1078 | |
| 1079 | spin_lock_irqsave(&phba->mgmt_sgl_lock, flags); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1080 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG, |
| 1081 | "BM_%d : In free_mgmt_sgl_handle," |
| 1082 | "eh_sgl_free_index=%d\n", |
| 1083 | phba->eh_sgl_free_index); |
| 1084 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1085 | if (phba->eh_sgl_hndl_base[phba->eh_sgl_free_index]) { |
| 1086 | /* |
| 1087 | * this can happen if clean_task is called on a task that |
| 1088 | * failed in xmit_task or alloc_pdu. |
| 1089 | */ |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1090 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG, |
| 1091 | "BM_%d : Double Free in eh SGL ," |
| 1092 | "eh_sgl_free_index=%d\n", |
| 1093 | phba->eh_sgl_free_index); |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 1094 | spin_unlock_irqrestore(&phba->mgmt_sgl_lock, flags); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1095 | return; |
| 1096 | } |
| 1097 | phba->eh_sgl_hndl_base[phba->eh_sgl_free_index] = psgl_handle; |
| 1098 | phba->eh_sgl_hndl_avbl++; |
| 1099 | if (phba->eh_sgl_free_index == |
| 1100 | (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl - 1)) |
| 1101 | phba->eh_sgl_free_index = 0; |
| 1102 | else |
| 1103 | phba->eh_sgl_free_index++; |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 1104 | spin_unlock_irqrestore(&phba->mgmt_sgl_lock, flags); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | static void |
| 1108 | be_complete_io(struct beiscsi_conn *beiscsi_conn, |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1109 | struct iscsi_task *task, |
| 1110 | struct common_sol_cqe *csol_cqe) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1111 | { |
| 1112 | struct beiscsi_io_task *io_task = task->dd_data; |
| 1113 | struct be_status_bhs *sts_bhs = |
| 1114 | (struct be_status_bhs *)io_task->cmd_bhs; |
| 1115 | struct iscsi_conn *conn = beiscsi_conn->conn; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1116 | unsigned char *sense; |
| 1117 | u32 resid = 0, exp_cmdsn, max_cmdsn; |
| 1118 | u8 rsp, status, flags; |
| 1119 | |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1120 | exp_cmdsn = csol_cqe->exp_cmdsn; |
| 1121 | max_cmdsn = (csol_cqe->exp_cmdsn + |
| 1122 | csol_cqe->cmd_wnd - 1); |
| 1123 | rsp = csol_cqe->i_resp; |
| 1124 | status = csol_cqe->i_sts; |
| 1125 | flags = csol_cqe->i_flags; |
| 1126 | resid = csol_cqe->res_cnt; |
| 1127 | |
Jayamohan Kallickal | bd53545 | 2011-10-07 19:31:10 -0500 | [diff] [blame] | 1128 | if (!task->sc) { |
Jayamohan Kallickal | da33497 | 2014-01-29 02:16:44 -0500 | [diff] [blame] | 1129 | if (io_task->scsi_cmnd) { |
Jayamohan Kallickal | bd53545 | 2011-10-07 19:31:10 -0500 | [diff] [blame] | 1130 | scsi_dma_unmap(io_task->scsi_cmnd); |
Jayamohan Kallickal | da33497 | 2014-01-29 02:16:44 -0500 | [diff] [blame] | 1131 | io_task->scsi_cmnd = NULL; |
| 1132 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1133 | |
Jayamohan Kallickal | bd53545 | 2011-10-07 19:31:10 -0500 | [diff] [blame] | 1134 | return; |
| 1135 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1136 | task->sc->result = (DID_OK << 16) | status; |
| 1137 | if (rsp != ISCSI_STATUS_CMD_COMPLETED) { |
| 1138 | task->sc->result = DID_ERROR << 16; |
| 1139 | goto unmap; |
| 1140 | } |
| 1141 | |
| 1142 | /* bidi not initially supported */ |
| 1143 | if (flags & (ISCSI_FLAG_CMD_UNDERFLOW | ISCSI_FLAG_CMD_OVERFLOW)) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1144 | if (!status && (flags & ISCSI_FLAG_CMD_OVERFLOW)) |
| 1145 | task->sc->result = DID_ERROR << 16; |
| 1146 | |
| 1147 | if (flags & ISCSI_FLAG_CMD_UNDERFLOW) { |
| 1148 | scsi_set_resid(task->sc, resid); |
| 1149 | if (!status && (scsi_bufflen(task->sc) - resid < |
| 1150 | task->sc->underflow)) |
| 1151 | task->sc->result = DID_ERROR << 16; |
| 1152 | } |
| 1153 | } |
| 1154 | |
| 1155 | if (status == SAM_STAT_CHECK_CONDITION) { |
Dan Carpenter | 4053a4b | 2011-09-26 09:23:37 +0300 | [diff] [blame] | 1156 | u16 sense_len; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1157 | unsigned short *slen = (unsigned short *)sts_bhs->sense_info; |
Dan Carpenter | 4053a4b | 2011-09-26 09:23:37 +0300 | [diff] [blame] | 1158 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1159 | sense = sts_bhs->sense_info + sizeof(unsigned short); |
Dan Carpenter | 4053a4b | 2011-09-26 09:23:37 +0300 | [diff] [blame] | 1160 | sense_len = be16_to_cpu(*slen); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1161 | memcpy(task->sc->sense_buffer, sense, |
| 1162 | min_t(u16, sense_len, SCSI_SENSE_BUFFERSIZE)); |
| 1163 | } |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 1164 | |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1165 | if (io_task->cmd_bhs->iscsi_hdr.flags & ISCSI_FLAG_CMD_READ) |
| 1166 | conn->rxdata_octets += resid; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1167 | unmap: |
John Soni Jose | eb1c469 | 2015-04-25 08:17:45 +0530 | [diff] [blame] | 1168 | if (io_task->scsi_cmnd) { |
| 1169 | scsi_dma_unmap(io_task->scsi_cmnd); |
| 1170 | io_task->scsi_cmnd = NULL; |
| 1171 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1172 | iscsi_complete_scsi_task(task, exp_cmdsn, max_cmdsn); |
| 1173 | } |
| 1174 | |
| 1175 | static void |
| 1176 | be_complete_logout(struct beiscsi_conn *beiscsi_conn, |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1177 | struct iscsi_task *task, |
| 1178 | struct common_sol_cqe *csol_cqe) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1179 | { |
| 1180 | struct iscsi_logout_rsp *hdr; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1181 | struct beiscsi_io_task *io_task = task->dd_data; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1182 | struct iscsi_conn *conn = beiscsi_conn->conn; |
| 1183 | |
| 1184 | hdr = (struct iscsi_logout_rsp *)task->hdr; |
Jayamohan Kallickal | 7bd6e25 | 2010-01-05 05:07:02 +0530 | [diff] [blame] | 1185 | hdr->opcode = ISCSI_OP_LOGOUT_RSP; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1186 | hdr->t2wait = 5; |
| 1187 | hdr->t2retain = 0; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1188 | hdr->flags = csol_cqe->i_flags; |
| 1189 | hdr->response = csol_cqe->i_resp; |
Jayamohan Kallickal | 702dc5e | 2013-04-05 20:38:37 -0700 | [diff] [blame] | 1190 | hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn); |
| 1191 | hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn + |
| 1192 | csol_cqe->cmd_wnd - 1); |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1193 | |
Jayamohan Kallickal | 7bd6e25 | 2010-01-05 05:07:02 +0530 | [diff] [blame] | 1194 | hdr->dlength[0] = 0; |
| 1195 | hdr->dlength[1] = 0; |
| 1196 | hdr->dlength[2] = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1197 | hdr->hlength = 0; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1198 | hdr->itt = io_task->libiscsi_itt; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1199 | __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0); |
| 1200 | } |
| 1201 | |
| 1202 | static void |
| 1203 | be_complete_tmf(struct beiscsi_conn *beiscsi_conn, |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1204 | struct iscsi_task *task, |
| 1205 | struct common_sol_cqe *csol_cqe) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1206 | { |
| 1207 | struct iscsi_tm_rsp *hdr; |
| 1208 | struct iscsi_conn *conn = beiscsi_conn->conn; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1209 | struct beiscsi_io_task *io_task = task->dd_data; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1210 | |
| 1211 | hdr = (struct iscsi_tm_rsp *)task->hdr; |
Jayamohan Kallickal | 7bd6e25 | 2010-01-05 05:07:02 +0530 | [diff] [blame] | 1212 | hdr->opcode = ISCSI_OP_SCSI_TMFUNC_RSP; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1213 | hdr->flags = csol_cqe->i_flags; |
| 1214 | hdr->response = csol_cqe->i_resp; |
Jayamohan Kallickal | 702dc5e | 2013-04-05 20:38:37 -0700 | [diff] [blame] | 1215 | hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn); |
| 1216 | hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn + |
| 1217 | csol_cqe->cmd_wnd - 1); |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1218 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1219 | hdr->itt = io_task->libiscsi_itt; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1220 | __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0); |
| 1221 | } |
| 1222 | |
| 1223 | static void |
| 1224 | hwi_complete_drvr_msgs(struct beiscsi_conn *beiscsi_conn, |
| 1225 | struct beiscsi_hba *phba, struct sol_cqe *psol) |
| 1226 | { |
| 1227 | struct hwi_wrb_context *pwrb_context; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 1228 | uint16_t wrb_index, cid, cri_index; |
Jitendra Bhivare | e1f9d31 | 2016-08-19 15:20:22 +0530 | [diff] [blame] | 1229 | struct hwi_controller *phwi_ctrlr; |
| 1230 | struct wrb_handle *pwrb_handle; |
Jitendra Bhivare | 3f7f62e | 2016-12-13 15:55:58 +0530 | [diff] [blame] | 1231 | struct iscsi_session *session; |
Jitendra Bhivare | e1f9d31 | 2016-08-19 15:20:22 +0530 | [diff] [blame] | 1232 | struct iscsi_task *task; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1233 | |
| 1234 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 1235 | if (is_chip_be2_be3r(phba)) { |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1236 | wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe, |
| 1237 | wrb_idx, psol); |
| 1238 | cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe, |
| 1239 | cid, psol); |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 1240 | } else { |
| 1241 | wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2, |
| 1242 | wrb_idx, psol); |
| 1243 | cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2, |
| 1244 | cid, psol); |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1245 | } |
| 1246 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 1247 | cri_index = BE_GET_CRI_FROM_CID(cid); |
| 1248 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1249 | pwrb_handle = pwrb_context->pwrb_handle_basestd[wrb_index]; |
Jitendra Bhivare | 3f7f62e | 2016-12-13 15:55:58 +0530 | [diff] [blame] | 1250 | session = beiscsi_conn->conn->session; |
| 1251 | spin_lock_bh(&session->back_lock); |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 1252 | task = pwrb_handle->pio_handle; |
Jitendra Bhivare | 3f7f62e | 2016-12-13 15:55:58 +0530 | [diff] [blame] | 1253 | if (task) |
| 1254 | __iscsi_put_task(task); |
| 1255 | spin_unlock_bh(&session->back_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | static void |
| 1259 | be_complete_nopin_resp(struct beiscsi_conn *beiscsi_conn, |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1260 | struct iscsi_task *task, |
| 1261 | struct common_sol_cqe *csol_cqe) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1262 | { |
| 1263 | struct iscsi_nopin *hdr; |
| 1264 | struct iscsi_conn *conn = beiscsi_conn->conn; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1265 | struct beiscsi_io_task *io_task = task->dd_data; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1266 | |
| 1267 | hdr = (struct iscsi_nopin *)task->hdr; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1268 | hdr->flags = csol_cqe->i_flags; |
| 1269 | hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn); |
Jayamohan Kallickal | 702dc5e | 2013-04-05 20:38:37 -0700 | [diff] [blame] | 1270 | hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn + |
| 1271 | csol_cqe->cmd_wnd - 1); |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1272 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1273 | hdr->opcode = ISCSI_OP_NOOP_IN; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1274 | hdr->itt = io_task->libiscsi_itt; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1275 | __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0); |
| 1276 | } |
| 1277 | |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1278 | static void adapter_get_sol_cqe(struct beiscsi_hba *phba, |
| 1279 | struct sol_cqe *psol, |
| 1280 | struct common_sol_cqe *csol_cqe) |
| 1281 | { |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 1282 | if (is_chip_be2_be3r(phba)) { |
| 1283 | csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1284 | i_exp_cmd_sn, psol); |
| 1285 | csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1286 | i_res_cnt, psol); |
| 1287 | csol_cqe->cmd_wnd = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1288 | i_cmd_wnd, psol); |
| 1289 | csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1290 | wrb_index, psol); |
| 1291 | csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1292 | cid, psol); |
| 1293 | csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1294 | hw_sts, psol); |
| 1295 | csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1296 | i_resp, psol); |
| 1297 | csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1298 | i_sts, psol); |
| 1299 | csol_cqe->i_flags = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1300 | i_flags, psol); |
| 1301 | } else { |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1302 | csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1303 | i_exp_cmd_sn, psol); |
| 1304 | csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1305 | i_res_cnt, psol); |
| 1306 | csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1307 | wrb_index, psol); |
| 1308 | csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1309 | cid, psol); |
| 1310 | csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1311 | hw_sts, psol); |
Jayamohan Kallickal | 702dc5e | 2013-04-05 20:38:37 -0700 | [diff] [blame] | 1312 | csol_cqe->cmd_wnd = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1313 | i_cmd_wnd, psol); |
| 1314 | if (AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1315 | cmd_cmpl, psol)) |
| 1316 | csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1317 | i_sts, psol); |
| 1318 | else |
| 1319 | csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1320 | i_sts, psol); |
| 1321 | if (AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1322 | u, psol)) |
| 1323 | csol_cqe->i_flags = ISCSI_FLAG_CMD_UNDERFLOW; |
| 1324 | |
| 1325 | if (AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1326 | o, psol)) |
| 1327 | csol_cqe->i_flags |= ISCSI_FLAG_CMD_OVERFLOW; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1328 | } |
| 1329 | } |
| 1330 | |
| 1331 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1332 | static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn, |
| 1333 | struct beiscsi_hba *phba, struct sol_cqe *psol) |
| 1334 | { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1335 | struct iscsi_conn *conn = beiscsi_conn->conn; |
| 1336 | struct iscsi_session *session = conn->session; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1337 | struct common_sol_cqe csol_cqe = {0}; |
Jitendra Bhivare | 3f7f62e | 2016-12-13 15:55:58 +0530 | [diff] [blame] | 1338 | struct hwi_wrb_context *pwrb_context; |
| 1339 | struct hwi_controller *phwi_ctrlr; |
| 1340 | struct wrb_handle *pwrb_handle; |
Jitendra Bhivare | 3f7f62e | 2016-12-13 15:55:58 +0530 | [diff] [blame] | 1341 | struct iscsi_task *task; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 1342 | uint16_t cri_index = 0; |
Jitendra Bhivare | 3f7f62e | 2016-12-13 15:55:58 +0530 | [diff] [blame] | 1343 | uint8_t type; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1344 | |
| 1345 | phwi_ctrlr = phba->phwi_ctrlr; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1346 | |
| 1347 | /* Copy the elements to a common structure */ |
| 1348 | adapter_get_sol_cqe(phba, psol, &csol_cqe); |
| 1349 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 1350 | cri_index = BE_GET_CRI_FROM_CID(csol_cqe.cid); |
| 1351 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1352 | |
| 1353 | pwrb_handle = pwrb_context->pwrb_handle_basestd[ |
| 1354 | csol_cqe.wrb_index]; |
| 1355 | |
Jitendra Bhivare | 3f7f62e | 2016-12-13 15:55:58 +0530 | [diff] [blame] | 1356 | spin_lock_bh(&session->back_lock); |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 1357 | task = pwrb_handle->pio_handle; |
Jitendra Bhivare | 3f7f62e | 2016-12-13 15:55:58 +0530 | [diff] [blame] | 1358 | if (!task) { |
| 1359 | spin_unlock_bh(&session->back_lock); |
| 1360 | return; |
| 1361 | } |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1362 | type = ((struct beiscsi_io_task *)task->dd_data)->wrb_type; |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 1363 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1364 | switch (type) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1365 | case HWH_TYPE_IO: |
| 1366 | case HWH_TYPE_IO_RD: |
| 1367 | if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 1368 | ISCSI_OP_NOOP_OUT) |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1369 | be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe); |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 1370 | else |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1371 | be_complete_io(beiscsi_conn, task, &csol_cqe); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1372 | break; |
| 1373 | |
| 1374 | case HWH_TYPE_LOGOUT: |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 1375 | if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGOUT) |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1376 | be_complete_logout(beiscsi_conn, task, &csol_cqe); |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 1377 | else |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1378 | be_complete_tmf(beiscsi_conn, task, &csol_cqe); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1379 | break; |
| 1380 | |
| 1381 | case HWH_TYPE_LOGIN: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1382 | beiscsi_log(phba, KERN_ERR, |
| 1383 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
| 1384 | "BM_%d :\t\t No HWH_TYPE_LOGIN Expected in" |
| 1385 | " hwi_complete_cmd- Solicited path\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1386 | break; |
| 1387 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1388 | case HWH_TYPE_NOP: |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1389 | be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1390 | break; |
| 1391 | |
| 1392 | default: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1393 | beiscsi_log(phba, KERN_WARNING, |
| 1394 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
| 1395 | "BM_%d : In hwi_complete_cmd, unknown type = %d" |
| 1396 | "wrb_index 0x%x CID 0x%x\n", type, |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1397 | csol_cqe.wrb_index, |
| 1398 | csol_cqe.cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1399 | break; |
| 1400 | } |
Jayamohan Kallickal | 35e6601 | 2009-10-23 11:53:49 +0530 | [diff] [blame] | 1401 | |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 1402 | spin_unlock_bh(&session->back_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1403 | } |
| 1404 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1405 | /** |
| 1406 | * ASYNC PDUs include |
| 1407 | * a. Unsolicited NOP-In (target initiated NOP-In) |
| 1408 | * b. ASYNC Messages |
| 1409 | * c. Reject PDU |
| 1410 | * d. Login response |
| 1411 | * These headers arrive unprocessed by the EP firmware. |
| 1412 | * iSCSI layer processes them. |
| 1413 | */ |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1414 | static unsigned int |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1415 | beiscsi_complete_pdu(struct beiscsi_conn *beiscsi_conn, |
| 1416 | struct pdu_base *phdr, void *pdata, unsigned int dlen) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1417 | { |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1418 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 1419 | struct iscsi_conn *conn = beiscsi_conn->conn; |
| 1420 | struct beiscsi_io_task *io_task; |
| 1421 | struct iscsi_hdr *login_hdr; |
| 1422 | struct iscsi_task *task; |
| 1423 | u8 code; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1424 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1425 | code = AMAP_GET_BITS(struct amap_pdu_base, opcode, phdr); |
| 1426 | switch (code) { |
| 1427 | case ISCSI_OP_NOOP_IN: |
| 1428 | pdata = NULL; |
| 1429 | dlen = 0; |
| 1430 | break; |
| 1431 | case ISCSI_OP_ASYNC_EVENT: |
| 1432 | break; |
| 1433 | case ISCSI_OP_REJECT: |
| 1434 | WARN_ON(!pdata); |
| 1435 | WARN_ON(!(dlen == 48)); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1436 | beiscsi_log(phba, KERN_ERR, |
| 1437 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1438 | "BM_%d : In ISCSI_OP_REJECT\n"); |
| 1439 | break; |
| 1440 | case ISCSI_OP_LOGIN_RSP: |
| 1441 | case ISCSI_OP_TEXT_RSP: |
| 1442 | task = conn->login_task; |
| 1443 | io_task = task->dd_data; |
| 1444 | login_hdr = (struct iscsi_hdr *)phdr; |
| 1445 | login_hdr->itt = io_task->libiscsi_itt; |
| 1446 | break; |
| 1447 | default: |
| 1448 | beiscsi_log(phba, KERN_WARNING, |
| 1449 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
| 1450 | "BM_%d : unrecognized async PDU opcode 0x%x\n", |
| 1451 | code); |
| 1452 | return 1; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1453 | } |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1454 | __iscsi_complete_pdu(conn, (struct iscsi_hdr *)phdr, pdata, dlen); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1455 | return 0; |
| 1456 | } |
| 1457 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1458 | static inline void |
| 1459 | beiscsi_hdl_put_handle(struct hd_async_context *pasync_ctx, |
| 1460 | struct hd_async_handle *pasync_handle) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1461 | { |
Jitendra Bhivare | ba6983a | 2017-03-24 14:11:46 +0530 | [diff] [blame] | 1462 | pasync_handle->is_final = 0; |
| 1463 | pasync_handle->buffer_len = 0; |
| 1464 | pasync_handle->in_use = 0; |
| 1465 | list_del_init(&pasync_handle->link); |
| 1466 | } |
| 1467 | |
| 1468 | static void |
| 1469 | beiscsi_hdl_purge_handles(struct beiscsi_hba *phba, |
| 1470 | struct hd_async_context *pasync_ctx, |
| 1471 | u16 cri) |
| 1472 | { |
| 1473 | struct hd_async_handle *pasync_handle, *tmp_handle; |
| 1474 | struct list_head *plist; |
| 1475 | |
| 1476 | plist = &pasync_ctx->async_entry[cri].wq.list; |
| 1477 | list_for_each_entry_safe(pasync_handle, tmp_handle, plist, link) |
| 1478 | beiscsi_hdl_put_handle(pasync_ctx, pasync_handle); |
| 1479 | |
| 1480 | INIT_LIST_HEAD(&pasync_ctx->async_entry[cri].wq.list); |
| 1481 | pasync_ctx->async_entry[cri].wq.hdr_len = 0; |
| 1482 | pasync_ctx->async_entry[cri].wq.bytes_received = 0; |
| 1483 | pasync_ctx->async_entry[cri].wq.bytes_needed = 0; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1484 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1485 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1486 | static struct hd_async_handle * |
| 1487 | beiscsi_hdl_get_handle(struct beiscsi_conn *beiscsi_conn, |
| 1488 | struct hd_async_context *pasync_ctx, |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1489 | struct i_t_dpdu_cqe *pdpdu_cqe, |
| 1490 | u8 *header) |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1491 | { |
| 1492 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 1493 | struct hd_async_handle *pasync_handle; |
| 1494 | struct be_bus_address phys_addr; |
Jitendra Bhivare | ba6983a | 2017-03-24 14:11:46 +0530 | [diff] [blame] | 1495 | u16 cid, code, ci, cri; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1496 | u8 final, error = 0; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1497 | u32 dpl; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1498 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1499 | cid = beiscsi_conn->beiscsi_conn_cid; |
Jitendra Bhivare | ba6983a | 2017-03-24 14:11:46 +0530 | [diff] [blame] | 1500 | cri = BE_GET_ASYNC_CRI_FROM_CID(cid); |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1501 | /** |
| 1502 | * This function is invoked to get the right async_handle structure |
| 1503 | * from a given DEF PDU CQ entry. |
| 1504 | * |
| 1505 | * - index in CQ entry gives the vertical index |
| 1506 | * - address in CQ entry is the offset where the DMA last ended |
| 1507 | * - final - no more notifications for this PDU |
| 1508 | */ |
| 1509 | if (is_chip_be2_be3r(phba)) { |
| 1510 | dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, |
| 1511 | dpl, pdpdu_cqe); |
| 1512 | ci = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, |
| 1513 | index, pdpdu_cqe); |
| 1514 | final = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, |
| 1515 | final, pdpdu_cqe); |
| 1516 | } else { |
| 1517 | dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2, |
| 1518 | dpl, pdpdu_cqe); |
| 1519 | ci = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2, |
| 1520 | index, pdpdu_cqe); |
| 1521 | final = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2, |
| 1522 | final, pdpdu_cqe); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1523 | } |
| 1524 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1525 | /** |
| 1526 | * DB addr Hi/Lo is same for BE and SKH. |
| 1527 | * Subtract the dataplacementlength to get to the base. |
| 1528 | */ |
| 1529 | phys_addr.u.a32.address_lo = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, |
| 1530 | db_addr_lo, pdpdu_cqe); |
| 1531 | phys_addr.u.a32.address_lo -= dpl; |
| 1532 | phys_addr.u.a32.address_hi = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, |
| 1533 | db_addr_hi, pdpdu_cqe); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1534 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1535 | code = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, code, pdpdu_cqe); |
| 1536 | switch (code) { |
| 1537 | case UNSOL_HDR_NOTIFY: |
| 1538 | pasync_handle = pasync_ctx->async_entry[ci].header; |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1539 | *header = 1; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1540 | break; |
| 1541 | case UNSOL_DATA_DIGEST_ERROR_NOTIFY: |
| 1542 | error = 1; |
| 1543 | case UNSOL_DATA_NOTIFY: |
| 1544 | pasync_handle = pasync_ctx->async_entry[ci].data; |
| 1545 | break; |
| 1546 | /* called only for above codes */ |
| 1547 | default: |
Jitendra Bhivare | ba6983a | 2017-03-24 14:11:46 +0530 | [diff] [blame] | 1548 | return NULL; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1549 | } |
| 1550 | |
| 1551 | if (pasync_handle->pa.u.a64.address != phys_addr.u.a64.address || |
| 1552 | pasync_handle->index != ci) { |
| 1553 | /* driver bug - if ci does not match async handle index */ |
| 1554 | error = 1; |
| 1555 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_ISCSI, |
| 1556 | "BM_%d : cid %u async PDU handle mismatch - addr in %cQE %llx at %u:addr in CQE %llx ci %u\n", |
| 1557 | cid, pasync_handle->is_header ? 'H' : 'D', |
| 1558 | pasync_handle->pa.u.a64.address, |
| 1559 | pasync_handle->index, |
| 1560 | phys_addr.u.a64.address, ci); |
| 1561 | /* FW has stale address - attempt continuing by dropping */ |
| 1562 | } |
| 1563 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1564 | /** |
| 1565 | * DEF PDU header and data buffers with errors should be simply |
| 1566 | * dropped as there are no consumers for it. |
| 1567 | */ |
| 1568 | if (error) { |
| 1569 | beiscsi_hdl_put_handle(pasync_ctx, pasync_handle); |
Jitendra Bhivare | ba6983a | 2017-03-24 14:11:46 +0530 | [diff] [blame] | 1570 | return NULL; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1571 | } |
Jitendra Bhivare | ba6983a | 2017-03-24 14:11:46 +0530 | [diff] [blame] | 1572 | |
| 1573 | if (pasync_handle->in_use || !list_empty(&pasync_handle->link)) { |
| 1574 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_ISCSI, |
| 1575 | "BM_%d : cid %d async PDU handle in use - code %d ci %d addr %llx\n", |
| 1576 | cid, code, ci, phys_addr.u.a64.address); |
| 1577 | beiscsi_hdl_purge_handles(phba, pasync_ctx, cri); |
| 1578 | } |
| 1579 | |
| 1580 | list_del_init(&pasync_handle->link); |
| 1581 | /** |
| 1582 | * Each CID is associated with unique CRI. |
| 1583 | * ASYNC_CRI_FROM_CID mapping and CRI_FROM_CID are totaly different. |
| 1584 | **/ |
| 1585 | pasync_handle->cri = cri; |
| 1586 | pasync_handle->is_final = final; |
| 1587 | pasync_handle->buffer_len = dpl; |
| 1588 | pasync_handle->in_use = 1; |
| 1589 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1590 | return pasync_handle; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1591 | } |
| 1592 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1593 | static unsigned int |
| 1594 | beiscsi_hdl_fwd_pdu(struct beiscsi_conn *beiscsi_conn, |
| 1595 | struct hd_async_context *pasync_ctx, |
| 1596 | u16 cri) |
| 1597 | { |
| 1598 | struct iscsi_session *session = beiscsi_conn->conn->session; |
| 1599 | struct hd_async_handle *pasync_handle, *plast_handle; |
| 1600 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 1601 | void *phdr = NULL, *pdata = NULL; |
| 1602 | u32 dlen = 0, status = 0; |
| 1603 | struct list_head *plist; |
| 1604 | |
| 1605 | plist = &pasync_ctx->async_entry[cri].wq.list; |
| 1606 | plast_handle = NULL; |
| 1607 | list_for_each_entry(pasync_handle, plist, link) { |
| 1608 | plast_handle = pasync_handle; |
| 1609 | /* get the header, the first entry */ |
| 1610 | if (!phdr) { |
| 1611 | phdr = pasync_handle->pbuffer; |
| 1612 | continue; |
| 1613 | } |
| 1614 | /* use first buffer to collect all the data */ |
| 1615 | if (!pdata) { |
| 1616 | pdata = pasync_handle->pbuffer; |
| 1617 | dlen = pasync_handle->buffer_len; |
| 1618 | continue; |
| 1619 | } |
Jitendra Bhivare | 0ddee50 | 2017-03-24 14:11:47 +0530 | [diff] [blame] | 1620 | if (!pasync_handle->buffer_len || |
| 1621 | (dlen + pasync_handle->buffer_len) > |
| 1622 | pasync_ctx->async_data.buffer_size) |
| 1623 | break; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1624 | memcpy(pdata + dlen, pasync_handle->pbuffer, |
| 1625 | pasync_handle->buffer_len); |
| 1626 | dlen += pasync_handle->buffer_len; |
| 1627 | } |
| 1628 | |
| 1629 | if (!plast_handle->is_final) { |
| 1630 | /* last handle should have final PDU notification from FW */ |
| 1631 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_ISCSI, |
Jitendra Bhivare | 0ddee50 | 2017-03-24 14:11:47 +0530 | [diff] [blame] | 1632 | "BM_%d : cid %u %p fwd async PDU opcode %x with last handle missing - HL%u:DN%u:DR%u\n", |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1633 | beiscsi_conn->beiscsi_conn_cid, plast_handle, |
Jitendra Bhivare | 0ddee50 | 2017-03-24 14:11:47 +0530 | [diff] [blame] | 1634 | AMAP_GET_BITS(struct amap_pdu_base, opcode, phdr), |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1635 | pasync_ctx->async_entry[cri].wq.hdr_len, |
| 1636 | pasync_ctx->async_entry[cri].wq.bytes_needed, |
| 1637 | pasync_ctx->async_entry[cri].wq.bytes_received); |
| 1638 | } |
| 1639 | spin_lock_bh(&session->back_lock); |
| 1640 | status = beiscsi_complete_pdu(beiscsi_conn, phdr, pdata, dlen); |
| 1641 | spin_unlock_bh(&session->back_lock); |
| 1642 | beiscsi_hdl_purge_handles(phba, pasync_ctx, cri); |
| 1643 | return status; |
| 1644 | } |
| 1645 | |
| 1646 | static unsigned int |
| 1647 | beiscsi_hdl_gather_pdu(struct beiscsi_conn *beiscsi_conn, |
| 1648 | struct hd_async_context *pasync_ctx, |
| 1649 | struct hd_async_handle *pasync_handle) |
| 1650 | { |
| 1651 | unsigned int bytes_needed = 0, status = 0; |
| 1652 | u16 cri = pasync_handle->cri; |
| 1653 | struct cri_wait_queue *wq; |
| 1654 | struct beiscsi_hba *phba; |
| 1655 | struct pdu_base *ppdu; |
| 1656 | char *err = ""; |
| 1657 | |
| 1658 | phba = beiscsi_conn->phba; |
| 1659 | wq = &pasync_ctx->async_entry[cri].wq; |
| 1660 | if (pasync_handle->is_header) { |
| 1661 | /* check if PDU hdr is rcv'd when old hdr not completed */ |
| 1662 | if (wq->hdr_len) { |
| 1663 | err = "incomplete"; |
| 1664 | goto drop_pdu; |
| 1665 | } |
| 1666 | ppdu = pasync_handle->pbuffer; |
| 1667 | bytes_needed = AMAP_GET_BITS(struct amap_pdu_base, |
| 1668 | data_len_hi, ppdu); |
| 1669 | bytes_needed <<= 16; |
| 1670 | bytes_needed |= be16_to_cpu(AMAP_GET_BITS(struct amap_pdu_base, |
| 1671 | data_len_lo, ppdu)); |
| 1672 | wq->hdr_len = pasync_handle->buffer_len; |
| 1673 | wq->bytes_received = 0; |
| 1674 | wq->bytes_needed = bytes_needed; |
| 1675 | list_add_tail(&pasync_handle->link, &wq->list); |
| 1676 | if (!bytes_needed) |
| 1677 | status = beiscsi_hdl_fwd_pdu(beiscsi_conn, |
| 1678 | pasync_ctx, cri); |
| 1679 | } else { |
| 1680 | /* check if data received has header and is needed */ |
| 1681 | if (!wq->hdr_len || !wq->bytes_needed) { |
| 1682 | err = "header less"; |
| 1683 | goto drop_pdu; |
| 1684 | } |
| 1685 | wq->bytes_received += pasync_handle->buffer_len; |
| 1686 | /* Something got overwritten? Better catch it here. */ |
| 1687 | if (wq->bytes_received > wq->bytes_needed) { |
| 1688 | err = "overflow"; |
| 1689 | goto drop_pdu; |
| 1690 | } |
| 1691 | list_add_tail(&pasync_handle->link, &wq->list); |
| 1692 | if (wq->bytes_received == wq->bytes_needed) |
| 1693 | status = beiscsi_hdl_fwd_pdu(beiscsi_conn, |
| 1694 | pasync_ctx, cri); |
| 1695 | } |
| 1696 | return status; |
| 1697 | |
| 1698 | drop_pdu: |
| 1699 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_ISCSI, |
| 1700 | "BM_%d : cid %u async PDU %s - def-%c:HL%u:DN%u:DR%u\n", |
| 1701 | beiscsi_conn->beiscsi_conn_cid, err, |
| 1702 | pasync_handle->is_header ? 'H' : 'D', |
| 1703 | wq->hdr_len, wq->bytes_needed, |
| 1704 | pasync_handle->buffer_len); |
| 1705 | /* discard this handle */ |
| 1706 | beiscsi_hdl_put_handle(pasync_ctx, pasync_handle); |
| 1707 | /* free all the other handles in cri_wait_queue */ |
| 1708 | beiscsi_hdl_purge_handles(phba, pasync_ctx, cri); |
| 1709 | /* try continuing */ |
| 1710 | return status; |
| 1711 | } |
| 1712 | |
| 1713 | static void |
| 1714 | beiscsi_hdq_post_handles(struct beiscsi_hba *phba, |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1715 | u8 header, u8 ulp_num, u16 nbuf) |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1716 | { |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1717 | struct hd_async_handle *pasync_handle; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1718 | struct hd_async_context *pasync_ctx; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1719 | struct hwi_controller *phwi_ctrlr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1720 | struct phys_addr *pasync_sge; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1721 | u32 ring_id, doorbell = 0; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1722 | u32 doorbell_offset; |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1723 | u16 prod, pi; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1724 | |
| 1725 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1726 | pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr, ulp_num); |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1727 | if (header) { |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1728 | pasync_sge = pasync_ctx->async_header.ring_base; |
| 1729 | pi = pasync_ctx->async_header.pi; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1730 | ring_id = phwi_ctrlr->default_pdu_hdr[ulp_num].id; |
| 1731 | doorbell_offset = phwi_ctrlr->default_pdu_hdr[ulp_num]. |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1732 | doorbell_offset; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1733 | } else { |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1734 | pasync_sge = pasync_ctx->async_data.ring_base; |
| 1735 | pi = pasync_ctx->async_data.pi; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1736 | ring_id = phwi_ctrlr->default_pdu_data[ulp_num].id; |
| 1737 | doorbell_offset = phwi_ctrlr->default_pdu_data[ulp_num]. |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1738 | doorbell_offset; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1739 | } |
| 1740 | |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1741 | for (prod = 0; prod < nbuf; prod++) { |
| 1742 | if (header) |
| 1743 | pasync_handle = pasync_ctx->async_entry[pi].header; |
| 1744 | else |
| 1745 | pasync_handle = pasync_ctx->async_entry[pi].data; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1746 | WARN_ON(pasync_handle->is_header != header); |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1747 | WARN_ON(pasync_handle->index != pi); |
| 1748 | /* setup the ring only once */ |
| 1749 | if (nbuf == pasync_ctx->num_entries) { |
| 1750 | /* note hi is lo */ |
| 1751 | pasync_sge[pi].hi = pasync_handle->pa.u.a32.address_lo; |
| 1752 | pasync_sge[pi].lo = pasync_handle->pa.u.a32.address_hi; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1753 | } |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1754 | if (++pi == pasync_ctx->num_entries) |
| 1755 | pi = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1756 | } |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1757 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1758 | if (header) |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1759 | pasync_ctx->async_header.pi = pi; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1760 | else |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1761 | pasync_ctx->async_data.pi = pi; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1762 | |
| 1763 | doorbell |= ring_id & DB_DEF_PDU_RING_ID_MASK; |
| 1764 | doorbell |= 1 << DB_DEF_PDU_REARM_SHIFT; |
| 1765 | doorbell |= 0 << DB_DEF_PDU_EVENT_SHIFT; |
| 1766 | doorbell |= (prod & DB_DEF_PDU_CQPROC_MASK) << DB_DEF_PDU_CQPROC_SHIFT; |
| 1767 | iowrite32(doorbell, phba->db_va + doorbell_offset); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1768 | } |
| 1769 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1770 | static void |
| 1771 | beiscsi_hdq_process_compl(struct beiscsi_conn *beiscsi_conn, |
| 1772 | struct i_t_dpdu_cqe *pdpdu_cqe) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1773 | { |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1774 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 1775 | struct hd_async_handle *pasync_handle = NULL; |
| 1776 | struct hd_async_context *pasync_ctx; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1777 | struct hwi_controller *phwi_ctrlr; |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1778 | u8 ulp_num, consumed, header = 0; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1779 | u16 cid_cri; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1780 | |
| 1781 | phwi_ctrlr = phba->phwi_ctrlr; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1782 | cid_cri = BE_GET_CRI_FROM_CID(beiscsi_conn->beiscsi_conn_cid); |
| 1783 | ulp_num = BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr, cid_cri); |
| 1784 | pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr, ulp_num); |
| 1785 | pasync_handle = beiscsi_hdl_get_handle(beiscsi_conn, pasync_ctx, |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1786 | pdpdu_cqe, &header); |
| 1787 | if (is_chip_be2_be3r(phba)) |
| 1788 | consumed = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, |
| 1789 | num_cons, pdpdu_cqe); |
| 1790 | else |
| 1791 | consumed = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2, |
| 1792 | num_cons, pdpdu_cqe); |
| 1793 | if (pasync_handle) |
| 1794 | beiscsi_hdl_gather_pdu(beiscsi_conn, pasync_ctx, pasync_handle); |
| 1795 | /* num_cons indicates number of 8 RQEs consumed */ |
| 1796 | if (consumed) |
| 1797 | beiscsi_hdq_post_handles(phba, header, ulp_num, 8 * consumed); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1798 | } |
| 1799 | |
Jitendra Bhivare | 2e4e8f6 | 2016-02-04 15:49:11 +0530 | [diff] [blame] | 1800 | void beiscsi_process_mcc_cq(struct beiscsi_hba *phba) |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 1801 | { |
| 1802 | struct be_queue_info *mcc_cq; |
| 1803 | struct be_mcc_compl *mcc_compl; |
| 1804 | unsigned int num_processed = 0; |
| 1805 | |
| 1806 | mcc_cq = &phba->ctrl.mcc_obj.cq; |
| 1807 | mcc_compl = queue_tail_node(mcc_cq); |
| 1808 | mcc_compl->flags = le32_to_cpu(mcc_compl->flags); |
| 1809 | while (mcc_compl->flags & CQE_FLAGS_VALID_MASK) { |
Jitendra Bhivare | 9122e99 | 2016-08-19 15:20:11 +0530 | [diff] [blame] | 1810 | if (beiscsi_hba_in_error(phba)) |
| 1811 | return; |
| 1812 | |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 1813 | if (num_processed >= 32) { |
| 1814 | hwi_ring_cq_db(phba, mcc_cq->id, |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 1815 | num_processed, 0); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 1816 | num_processed = 0; |
| 1817 | } |
| 1818 | if (mcc_compl->flags & CQE_FLAGS_ASYNC_MASK) { |
Jitendra Bhivare | 53aefe2 | 2016-01-20 14:10:53 +0530 | [diff] [blame] | 1819 | beiscsi_process_async_event(phba, mcc_compl); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 1820 | } else if (mcc_compl->flags & CQE_FLAGS_COMPLETED_MASK) { |
Jitendra Bhivare | 2e4e8f6 | 2016-02-04 15:49:11 +0530 | [diff] [blame] | 1821 | beiscsi_process_mcc_compl(&phba->ctrl, mcc_compl); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | mcc_compl->flags = 0; |
| 1825 | queue_tail_inc(mcc_cq); |
| 1826 | mcc_compl = queue_tail_node(mcc_cq); |
| 1827 | mcc_compl->flags = le32_to_cpu(mcc_compl->flags); |
| 1828 | num_processed++; |
| 1829 | } |
| 1830 | |
| 1831 | if (num_processed > 0) |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 1832 | hwi_ring_cq_db(phba, mcc_cq->id, num_processed, 1); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 1833 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1834 | |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 1835 | static void beiscsi_mcc_work(struct work_struct *work) |
| 1836 | { |
| 1837 | struct be_eq_obj *pbe_eq; |
| 1838 | struct beiscsi_hba *phba; |
| 1839 | |
| 1840 | pbe_eq = container_of(work, struct be_eq_obj, mcc_work); |
| 1841 | phba = pbe_eq->phba; |
| 1842 | beiscsi_process_mcc_cq(phba); |
| 1843 | /* rearm EQ for further interrupts */ |
Jitendra Bhivare | 9122e99 | 2016-08-19 15:20:11 +0530 | [diff] [blame] | 1844 | if (!beiscsi_hba_in_error(phba)) |
| 1845 | hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1); |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 1846 | } |
| 1847 | |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 1848 | /** |
| 1849 | * beiscsi_process_cq()- Process the Completion Queue |
| 1850 | * @pbe_eq: Event Q on which the Completion has come |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 1851 | * @budget: Max number of events to processed |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 1852 | * |
| 1853 | * return |
| 1854 | * Number of Completion Entries processed. |
| 1855 | **/ |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 1856 | unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq, int budget) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1857 | { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1858 | struct be_queue_info *cq; |
| 1859 | struct sol_cqe *sol; |
| 1860 | struct dmsg_cqe *dmsg; |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 1861 | unsigned int total = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1862 | unsigned int num_processed = 0; |
John Soni Jose | 0a513dd | 2012-08-20 23:00:55 +0530 | [diff] [blame] | 1863 | unsigned short code = 0, cid = 0; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 1864 | uint16_t cri_index = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1865 | struct beiscsi_conn *beiscsi_conn; |
Jayamohan Kallickal | c246228 | 2010-01-05 05:05:34 +0530 | [diff] [blame] | 1866 | struct beiscsi_endpoint *beiscsi_ep; |
| 1867 | struct iscsi_endpoint *ep; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1868 | struct beiscsi_hba *phba; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1869 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1870 | cq = pbe_eq->cq; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1871 | sol = queue_tail_node(cq); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1872 | phba = pbe_eq->phba; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1873 | |
| 1874 | while (sol->dw[offsetof(struct amap_sol_cqe, valid) / 32] & |
| 1875 | CQE_VALID_MASK) { |
Jitendra Bhivare | 9122e99 | 2016-08-19 15:20:11 +0530 | [diff] [blame] | 1876 | if (beiscsi_hba_in_error(phba)) |
| 1877 | return 0; |
| 1878 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1879 | be_dws_le_to_cpu(sol, sizeof(struct sol_cqe)); |
| 1880 | |
Jitendra Bhivare | 45efc940 | 2017-10-10 16:18:18 +0530 | [diff] [blame] | 1881 | code = (sol->dw[offsetof(struct amap_sol_cqe, code) / 32] & |
| 1882 | CQE_CODE_MASK); |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 1883 | |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1884 | /* Get the CID */ |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 1885 | if (is_chip_be2_be3r(phba)) { |
| 1886 | cid = AMAP_GET_BITS(struct amap_sol_cqe, cid, sol); |
| 1887 | } else { |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1888 | if ((code == DRIVERMSG_NOTIFY) || |
| 1889 | (code == UNSOL_HDR_NOTIFY) || |
| 1890 | (code == UNSOL_DATA_NOTIFY)) |
| 1891 | cid = AMAP_GET_BITS( |
| 1892 | struct amap_i_t_dpdu_cqe_v2, |
| 1893 | cid, sol); |
| 1894 | else |
| 1895 | cid = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1896 | cid, sol); |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 1897 | } |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1898 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 1899 | cri_index = BE_GET_CRI_FROM_CID(cid); |
| 1900 | ep = phba->ep_array[cri_index]; |
Jayamohan Kallickal | b7ab35b | 2014-08-08 01:00:01 -0400 | [diff] [blame] | 1901 | |
| 1902 | if (ep == NULL) { |
| 1903 | /* connection has already been freed |
| 1904 | * just move on to next one |
| 1905 | */ |
| 1906 | beiscsi_log(phba, KERN_WARNING, |
| 1907 | BEISCSI_LOG_INIT, |
| 1908 | "BM_%d : proc cqe of disconn ep: cid %d\n", |
| 1909 | cid); |
| 1910 | goto proc_next_cqe; |
| 1911 | } |
| 1912 | |
Jayamohan Kallickal | c246228 | 2010-01-05 05:05:34 +0530 | [diff] [blame] | 1913 | beiscsi_ep = ep->dd_data; |
| 1914 | beiscsi_conn = beiscsi_ep->conn; |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 1915 | |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 1916 | /* replenish cq */ |
| 1917 | if (num_processed == 32) { |
| 1918 | hwi_ring_cq_db(phba, cq->id, 32, 0); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1919 | num_processed = 0; |
| 1920 | } |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 1921 | total++; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1922 | |
John Soni Jose | 0a513dd | 2012-08-20 23:00:55 +0530 | [diff] [blame] | 1923 | switch (code) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1924 | case SOL_CMD_COMPLETE: |
| 1925 | hwi_complete_cmd(beiscsi_conn, phba, sol); |
| 1926 | break; |
| 1927 | case DRIVERMSG_NOTIFY: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1928 | beiscsi_log(phba, KERN_INFO, |
| 1929 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 1930 | "BM_%d : Received %s[%d] on CID : %d\n", |
| 1931 | cqe_desc[code], code, cid); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1932 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1933 | dmsg = (struct dmsg_cqe *)sol; |
| 1934 | hwi_complete_drvr_msgs(beiscsi_conn, phba, sol); |
| 1935 | break; |
| 1936 | case UNSOL_HDR_NOTIFY: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1937 | beiscsi_log(phba, KERN_INFO, |
| 1938 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 1939 | "BM_%d : Received %s[%d] on CID : %d\n", |
| 1940 | cqe_desc[code], code, cid); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1941 | |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 1942 | spin_lock_bh(&phba->async_pdu_lock); |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1943 | beiscsi_hdq_process_compl(beiscsi_conn, |
| 1944 | (struct i_t_dpdu_cqe *)sol); |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 1945 | spin_unlock_bh(&phba->async_pdu_lock); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1946 | break; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1947 | case UNSOL_DATA_NOTIFY: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1948 | beiscsi_log(phba, KERN_INFO, |
| 1949 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 1950 | "BM_%d : Received %s[%d] on CID : %d\n", |
| 1951 | cqe_desc[code], code, cid); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1952 | |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 1953 | spin_lock_bh(&phba->async_pdu_lock); |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1954 | beiscsi_hdq_process_compl(beiscsi_conn, |
| 1955 | (struct i_t_dpdu_cqe *)sol); |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 1956 | spin_unlock_bh(&phba->async_pdu_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1957 | break; |
| 1958 | case CXN_INVALIDATE_INDEX_NOTIFY: |
| 1959 | case CMD_INVALIDATED_NOTIFY: |
| 1960 | case CXN_INVALIDATE_NOTIFY: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1961 | beiscsi_log(phba, KERN_ERR, |
| 1962 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 1963 | "BM_%d : Ignoring %s[%d] on CID : %d\n", |
| 1964 | cqe_desc[code], code, cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1965 | break; |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 1966 | case CXN_KILLED_HDR_DIGEST_ERR: |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1967 | case SOL_CMD_KILLED_DATA_DIGEST_ERR: |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 1968 | beiscsi_log(phba, KERN_ERR, |
| 1969 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
| 1970 | "BM_%d : Cmd Notification %s[%d] on CID : %d\n", |
| 1971 | cqe_desc[code], code, cid); |
| 1972 | break; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1973 | case CMD_KILLED_INVALID_STATSN_RCVD: |
| 1974 | case CMD_KILLED_INVALID_R2T_RCVD: |
| 1975 | case CMD_CXN_KILLED_LUN_INVALID: |
| 1976 | case CMD_CXN_KILLED_ICD_INVALID: |
| 1977 | case CMD_CXN_KILLED_ITT_INVALID: |
| 1978 | case CMD_CXN_KILLED_SEQ_OUTOFORDER: |
| 1979 | case CMD_CXN_KILLED_INVALID_DATASN_RCVD: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1980 | beiscsi_log(phba, KERN_ERR, |
| 1981 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 1982 | "BM_%d : Cmd Notification %s[%d] on CID : %d\n", |
| 1983 | cqe_desc[code], code, cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1984 | break; |
| 1985 | case UNSOL_DATA_DIGEST_ERROR_NOTIFY: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1986 | beiscsi_log(phba, KERN_ERR, |
| 1987 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 1988 | "BM_%d : Dropping %s[%d] on DPDU ring on CID : %d\n", |
| 1989 | cqe_desc[code], code, cid); |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 1990 | spin_lock_bh(&phba->async_pdu_lock); |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1991 | /* driver consumes the entry and drops the contents */ |
| 1992 | beiscsi_hdq_process_compl(beiscsi_conn, |
| 1993 | (struct i_t_dpdu_cqe *)sol); |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 1994 | spin_unlock_bh(&phba->async_pdu_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1995 | break; |
| 1996 | case CXN_KILLED_PDU_SIZE_EXCEEDS_DSL: |
| 1997 | case CXN_KILLED_BURST_LEN_MISMATCH: |
| 1998 | case CXN_KILLED_AHS_RCVD: |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1999 | case CXN_KILLED_UNKNOWN_HDR: |
| 2000 | case CXN_KILLED_STALE_ITT_TTT_RCVD: |
| 2001 | case CXN_KILLED_INVALID_ITT_TTT_RCVD: |
| 2002 | case CXN_KILLED_TIMED_OUT: |
| 2003 | case CXN_KILLED_FIN_RCVD: |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 2004 | case CXN_KILLED_RST_SENT: |
| 2005 | case CXN_KILLED_RST_RCVD: |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2006 | case CXN_KILLED_BAD_UNSOL_PDU_RCVD: |
| 2007 | case CXN_KILLED_BAD_WRB_INDEX_ERROR: |
| 2008 | case CXN_KILLED_OVER_RUN_RESIDUAL: |
| 2009 | case CXN_KILLED_UNDER_RUN_RESIDUAL: |
| 2010 | case CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2011 | beiscsi_log(phba, KERN_ERR, |
| 2012 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 2013 | "BM_%d : Event %s[%d] received on CID : %d\n", |
| 2014 | cqe_desc[code], code, cid); |
John Soni Jose | 0a513dd | 2012-08-20 23:00:55 +0530 | [diff] [blame] | 2015 | if (beiscsi_conn) |
| 2016 | iscsi_conn_failure(beiscsi_conn->conn, |
| 2017 | ISCSI_ERR_CONN_FAILED); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2018 | break; |
| 2019 | default: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2020 | beiscsi_log(phba, KERN_ERR, |
| 2021 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 2022 | "BM_%d : Invalid CQE Event Received Code : %d" |
| 2023 | "CID 0x%x...\n", |
John Soni Jose | 0a513dd | 2012-08-20 23:00:55 +0530 | [diff] [blame] | 2024 | code, cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2025 | break; |
| 2026 | } |
| 2027 | |
Jayamohan Kallickal | b7ab35b | 2014-08-08 01:00:01 -0400 | [diff] [blame] | 2028 | proc_next_cqe: |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2029 | AMAP_SET_BITS(struct amap_sol_cqe, valid, sol, 0); |
| 2030 | queue_tail_inc(cq); |
| 2031 | sol = queue_tail_node(cq); |
| 2032 | num_processed++; |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2033 | if (total == budget) |
| 2034 | break; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2035 | } |
| 2036 | |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2037 | hwi_ring_cq_db(phba, cq->id, num_processed, 1); |
| 2038 | return total; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2039 | } |
| 2040 | |
Christoph Hellwig | 511cbce | 2015-11-10 14:56:14 +0100 | [diff] [blame] | 2041 | static int be_iopoll(struct irq_poll *iop, int budget) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2042 | { |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 2043 | unsigned int ret, io_events; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2044 | struct beiscsi_hba *phba; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2045 | struct be_eq_obj *pbe_eq; |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2046 | struct be_eq_entry *eqe = NULL; |
| 2047 | struct be_queue_info *eq; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2048 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2049 | pbe_eq = container_of(iop, struct be_eq_obj, iopoll); |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2050 | phba = pbe_eq->phba; |
Jitendra Bhivare | 9122e99 | 2016-08-19 15:20:11 +0530 | [diff] [blame] | 2051 | if (beiscsi_hba_in_error(phba)) { |
| 2052 | irq_poll_complete(iop); |
| 2053 | return 0; |
| 2054 | } |
| 2055 | |
| 2056 | io_events = 0; |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2057 | eq = &pbe_eq->q; |
| 2058 | eqe = queue_tail_node(eq); |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2059 | while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32] & |
| 2060 | EQE_VALID_MASK) { |
| 2061 | AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0); |
| 2062 | queue_tail_inc(eq); |
| 2063 | eqe = queue_tail_node(eq); |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 2064 | io_events++; |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2065 | } |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 2066 | hwi_ring_eq_db(phba, eq->id, 1, io_events, 0, 1); |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2067 | |
| 2068 | ret = beiscsi_process_cq(pbe_eq, budget); |
Jayamohan Kallickal | 73af08e | 2014-05-05 21:41:26 -0400 | [diff] [blame] | 2069 | pbe_eq->cq_count += ret; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2070 | if (ret < budget) { |
Christoph Hellwig | 511cbce | 2015-11-10 14:56:14 +0100 | [diff] [blame] | 2071 | irq_poll_complete(iop); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2072 | beiscsi_log(phba, KERN_INFO, |
| 2073 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2074 | "BM_%d : rearm pbe_eq->q.id =%d ret %d\n", |
| 2075 | pbe_eq->q.id, ret); |
Jitendra Bhivare | 9122e99 | 2016-08-19 15:20:11 +0530 | [diff] [blame] | 2076 | if (!beiscsi_hba_in_error(phba)) |
| 2077 | hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2078 | } |
| 2079 | return ret; |
| 2080 | } |
| 2081 | |
| 2082 | static void |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2083 | hwi_write_sgl_v2(struct iscsi_wrb *pwrb, struct scatterlist *sg, |
| 2084 | unsigned int num_sg, struct beiscsi_io_task *io_task) |
| 2085 | { |
| 2086 | struct iscsi_sge *psgl; |
| 2087 | unsigned int sg_len, index; |
| 2088 | unsigned int sge_len = 0; |
| 2089 | unsigned long long addr; |
| 2090 | struct scatterlist *l_sg; |
| 2091 | unsigned int offset; |
| 2092 | |
| 2093 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_lo, pwrb, |
| 2094 | io_task->bhs_pa.u.a32.address_lo); |
| 2095 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_hi, pwrb, |
| 2096 | io_task->bhs_pa.u.a32.address_hi); |
| 2097 | |
| 2098 | l_sg = sg; |
| 2099 | for (index = 0; (index < num_sg) && (index < 2); index++, |
| 2100 | sg = sg_next(sg)) { |
| 2101 | if (index == 0) { |
| 2102 | sg_len = sg_dma_len(sg); |
| 2103 | addr = (u64) sg_dma_address(sg); |
| 2104 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
| 2105 | sge0_addr_lo, pwrb, |
| 2106 | lower_32_bits(addr)); |
| 2107 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
| 2108 | sge0_addr_hi, pwrb, |
| 2109 | upper_32_bits(addr)); |
| 2110 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
| 2111 | sge0_len, pwrb, |
| 2112 | sg_len); |
| 2113 | sge_len = sg_len; |
| 2114 | } else { |
| 2115 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_r2t_offset, |
| 2116 | pwrb, sge_len); |
| 2117 | sg_len = sg_dma_len(sg); |
| 2118 | addr = (u64) sg_dma_address(sg); |
| 2119 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
| 2120 | sge1_addr_lo, pwrb, |
| 2121 | lower_32_bits(addr)); |
| 2122 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
| 2123 | sge1_addr_hi, pwrb, |
| 2124 | upper_32_bits(addr)); |
| 2125 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
| 2126 | sge1_len, pwrb, |
| 2127 | sg_len); |
| 2128 | } |
| 2129 | } |
| 2130 | psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag; |
| 2131 | memset(psgl, 0, sizeof(*psgl) * BE2_SGE); |
| 2132 | |
| 2133 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2); |
| 2134 | |
| 2135 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, |
| 2136 | io_task->bhs_pa.u.a32.address_hi); |
| 2137 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, |
| 2138 | io_task->bhs_pa.u.a32.address_lo); |
| 2139 | |
| 2140 | if (num_sg == 1) { |
| 2141 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb, |
| 2142 | 1); |
| 2143 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb, |
| 2144 | 0); |
| 2145 | } else if (num_sg == 2) { |
| 2146 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb, |
| 2147 | 0); |
| 2148 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb, |
| 2149 | 1); |
| 2150 | } else { |
| 2151 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb, |
| 2152 | 0); |
| 2153 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb, |
| 2154 | 0); |
| 2155 | } |
| 2156 | |
| 2157 | sg = l_sg; |
| 2158 | psgl++; |
| 2159 | psgl++; |
| 2160 | offset = 0; |
| 2161 | for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) { |
| 2162 | sg_len = sg_dma_len(sg); |
| 2163 | addr = (u64) sg_dma_address(sg); |
| 2164 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, |
| 2165 | lower_32_bits(addr)); |
| 2166 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, |
| 2167 | upper_32_bits(addr)); |
| 2168 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len); |
| 2169 | AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset); |
| 2170 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0); |
| 2171 | offset += sg_len; |
| 2172 | } |
| 2173 | psgl--; |
| 2174 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1); |
| 2175 | } |
| 2176 | |
| 2177 | static void |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2178 | hwi_write_sgl(struct iscsi_wrb *pwrb, struct scatterlist *sg, |
| 2179 | unsigned int num_sg, struct beiscsi_io_task *io_task) |
| 2180 | { |
| 2181 | struct iscsi_sge *psgl; |
Jayamohan Kallickal | 58ff4bd | 2010-10-06 23:46:47 +0530 | [diff] [blame] | 2182 | unsigned int sg_len, index; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2183 | unsigned int sge_len = 0; |
| 2184 | unsigned long long addr; |
| 2185 | struct scatterlist *l_sg; |
| 2186 | unsigned int offset; |
| 2187 | |
| 2188 | AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb, |
| 2189 | io_task->bhs_pa.u.a32.address_lo); |
| 2190 | AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb, |
| 2191 | io_task->bhs_pa.u.a32.address_hi); |
| 2192 | |
| 2193 | l_sg = sg; |
Jayamohan Kallickal | 48bd86c | 2010-01-07 01:50:19 +0530 | [diff] [blame] | 2194 | for (index = 0; (index < num_sg) && (index < 2); index++, |
| 2195 | sg = sg_next(sg)) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2196 | if (index == 0) { |
| 2197 | sg_len = sg_dma_len(sg); |
| 2198 | addr = (u64) sg_dma_address(sg); |
| 2199 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb, |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 2200 | ((u32)(addr & 0xFFFFFFFF))); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2201 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb, |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 2202 | ((u32)(addr >> 32))); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2203 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb, |
| 2204 | sg_len); |
| 2205 | sge_len = sg_len; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2206 | } else { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2207 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_r2t_offset, |
| 2208 | pwrb, sge_len); |
| 2209 | sg_len = sg_dma_len(sg); |
| 2210 | addr = (u64) sg_dma_address(sg); |
| 2211 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_lo, pwrb, |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 2212 | ((u32)(addr & 0xFFFFFFFF))); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2213 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_hi, pwrb, |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 2214 | ((u32)(addr >> 32))); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2215 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_len, pwrb, |
| 2216 | sg_len); |
| 2217 | } |
| 2218 | } |
| 2219 | psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag; |
| 2220 | memset(psgl, 0, sizeof(*psgl) * BE2_SGE); |
| 2221 | |
| 2222 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2); |
| 2223 | |
| 2224 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, |
| 2225 | io_task->bhs_pa.u.a32.address_hi); |
| 2226 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, |
| 2227 | io_task->bhs_pa.u.a32.address_lo); |
| 2228 | |
Jayamohan Kallickal | caf818f | 2010-01-23 05:38:18 +0530 | [diff] [blame] | 2229 | if (num_sg == 1) { |
| 2230 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, |
| 2231 | 1); |
| 2232 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb, |
| 2233 | 0); |
| 2234 | } else if (num_sg == 2) { |
| 2235 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, |
| 2236 | 0); |
| 2237 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb, |
| 2238 | 1); |
| 2239 | } else { |
| 2240 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, |
| 2241 | 0); |
| 2242 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb, |
| 2243 | 0); |
| 2244 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2245 | sg = l_sg; |
| 2246 | psgl++; |
| 2247 | psgl++; |
| 2248 | offset = 0; |
Jayamohan Kallickal | 48bd86c | 2010-01-07 01:50:19 +0530 | [diff] [blame] | 2249 | for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2250 | sg_len = sg_dma_len(sg); |
| 2251 | addr = (u64) sg_dma_address(sg); |
| 2252 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, |
| 2253 | (addr & 0xFFFFFFFF)); |
| 2254 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, |
| 2255 | (addr >> 32)); |
| 2256 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len); |
| 2257 | AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset); |
| 2258 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0); |
| 2259 | offset += sg_len; |
| 2260 | } |
| 2261 | psgl--; |
| 2262 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1); |
| 2263 | } |
| 2264 | |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2265 | /** |
| 2266 | * hwi_write_buffer()- Populate the WRB with task info |
| 2267 | * @pwrb: ptr to the WRB entry |
| 2268 | * @task: iscsi task which is to be executed |
| 2269 | **/ |
Alexey Khoroshilov | e049362 | 2016-01-16 00:45:34 +0300 | [diff] [blame] | 2270 | static int hwi_write_buffer(struct iscsi_wrb *pwrb, struct iscsi_task *task) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2271 | { |
| 2272 | struct iscsi_sge *psgl; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2273 | struct beiscsi_io_task *io_task = task->dd_data; |
| 2274 | struct beiscsi_conn *beiscsi_conn = io_task->conn; |
| 2275 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2276 | uint8_t dsp_value = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2277 | |
| 2278 | io_task->bhs_len = sizeof(struct be_nonio_bhs) - 2; |
| 2279 | AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb, |
| 2280 | io_task->bhs_pa.u.a32.address_lo); |
| 2281 | AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb, |
| 2282 | io_task->bhs_pa.u.a32.address_hi); |
| 2283 | |
| 2284 | if (task->data) { |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2285 | |
| 2286 | /* Check for the data_count */ |
| 2287 | dsp_value = (task->data_count) ? 1 : 0; |
| 2288 | |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 2289 | if (is_chip_be2_be3r(phba)) |
| 2290 | AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2291 | pwrb, dsp_value); |
| 2292 | else |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 2293 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2294 | pwrb, dsp_value); |
| 2295 | |
| 2296 | /* Map addr only if there is data_count */ |
| 2297 | if (dsp_value) { |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2298 | io_task->mtask_addr = pci_map_single(phba->pcidev, |
| 2299 | task->data, |
| 2300 | task->data_count, |
| 2301 | PCI_DMA_TODEVICE); |
Alexey Khoroshilov | e049362 | 2016-01-16 00:45:34 +0300 | [diff] [blame] | 2302 | if (pci_dma_mapping_error(phba->pcidev, |
| 2303 | io_task->mtask_addr)) |
| 2304 | return -ENOMEM; |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2305 | io_task->mtask_data_count = task->data_count; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2306 | } else |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2307 | io_task->mtask_addr = 0; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2308 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2309 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb, |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2310 | lower_32_bits(io_task->mtask_addr)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2311 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb, |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2312 | upper_32_bits(io_task->mtask_addr)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2313 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb, |
| 2314 | task->data_count); |
| 2315 | |
| 2316 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, 1); |
| 2317 | } else { |
| 2318 | AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0); |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2319 | io_task->mtask_addr = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2320 | } |
| 2321 | |
| 2322 | psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag; |
| 2323 | |
| 2324 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len); |
| 2325 | |
| 2326 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, |
| 2327 | io_task->bhs_pa.u.a32.address_hi); |
| 2328 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, |
| 2329 | io_task->bhs_pa.u.a32.address_lo); |
| 2330 | if (task->data) { |
| 2331 | psgl++; |
| 2332 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, 0); |
| 2333 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, 0); |
| 2334 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0); |
| 2335 | AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, 0); |
| 2336 | AMAP_SET_BITS(struct amap_iscsi_sge, rsvd0, psgl, 0); |
| 2337 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0); |
| 2338 | |
| 2339 | psgl++; |
| 2340 | if (task->data) { |
| 2341 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2342 | lower_32_bits(io_task->mtask_addr)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2343 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2344 | upper_32_bits(io_task->mtask_addr)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2345 | } |
| 2346 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0x106); |
| 2347 | } |
| 2348 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1); |
Alexey Khoroshilov | e049362 | 2016-01-16 00:45:34 +0300 | [diff] [blame] | 2349 | return 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2350 | } |
| 2351 | |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 2352 | /** |
| 2353 | * beiscsi_find_mem_req()- Find mem needed |
| 2354 | * @phba: ptr to HBA struct |
| 2355 | **/ |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2356 | static void beiscsi_find_mem_req(struct beiscsi_hba *phba) |
| 2357 | { |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2358 | uint8_t mem_descr_index, ulp_num; |
Jitendra Bhivare | fa1261c | 2016-12-13 15:56:01 +0530 | [diff] [blame] | 2359 | unsigned int num_async_pdu_buf_pages; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2360 | unsigned int num_async_pdu_data_pages, wrb_sz_per_cxn; |
| 2361 | unsigned int num_async_pdu_buf_sgl_pages, num_async_pdu_data_sgl_pages; |
| 2362 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2363 | phba->params.hwi_ws_sz = sizeof(struct hwi_controller); |
| 2364 | |
| 2365 | phba->mem_req[ISCSI_MEM_GLOBAL_HEADER] = 2 * |
| 2366 | BE_ISCSI_PDU_HEADER_SIZE; |
| 2367 | phba->mem_req[HWI_MEM_ADDN_CONTEXT] = |
| 2368 | sizeof(struct hwi_context_memory); |
| 2369 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2370 | |
| 2371 | phba->mem_req[HWI_MEM_WRB] = sizeof(struct iscsi_wrb) |
| 2372 | * (phba->params.wrbs_per_cxn) |
| 2373 | * phba->params.cxns_per_ctrl; |
| 2374 | wrb_sz_per_cxn = sizeof(struct wrb_handle) * |
| 2375 | (phba->params.wrbs_per_cxn); |
| 2376 | phba->mem_req[HWI_MEM_WRBH] = roundup_pow_of_two((wrb_sz_per_cxn) * |
| 2377 | phba->params.cxns_per_ctrl); |
| 2378 | |
| 2379 | phba->mem_req[HWI_MEM_SGLH] = sizeof(struct sgl_handle) * |
| 2380 | phba->params.icds_per_ctrl; |
| 2381 | phba->mem_req[HWI_MEM_SGE] = sizeof(struct iscsi_sge) * |
| 2382 | phba->params.num_sge_per_io * phba->params.icds_per_ctrl; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2383 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 2384 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2385 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2386 | num_async_pdu_buf_sgl_pages = |
Jitendra Bhivare | fecc382 | 2017-03-24 14:11:44 +0530 | [diff] [blame] | 2387 | PAGES_REQUIRED(BEISCSI_ASYNC_HDQ_SIZE( |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2388 | phba, ulp_num) * |
| 2389 | sizeof(struct phys_addr)); |
| 2390 | |
| 2391 | num_async_pdu_buf_pages = |
Jitendra Bhivare | fecc382 | 2017-03-24 14:11:44 +0530 | [diff] [blame] | 2392 | PAGES_REQUIRED(BEISCSI_ASYNC_HDQ_SIZE( |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2393 | phba, ulp_num) * |
| 2394 | phba->params.defpdu_hdr_sz); |
| 2395 | |
| 2396 | num_async_pdu_data_pages = |
Jitendra Bhivare | fecc382 | 2017-03-24 14:11:44 +0530 | [diff] [blame] | 2397 | PAGES_REQUIRED(BEISCSI_ASYNC_HDQ_SIZE( |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2398 | phba, ulp_num) * |
| 2399 | phba->params.defpdu_data_sz); |
| 2400 | |
| 2401 | num_async_pdu_data_sgl_pages = |
Jitendra Bhivare | fecc382 | 2017-03-24 14:11:44 +0530 | [diff] [blame] | 2402 | PAGES_REQUIRED(BEISCSI_ASYNC_HDQ_SIZE( |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2403 | phba, ulp_num) * |
| 2404 | sizeof(struct phys_addr)); |
| 2405 | |
Jayamohan Kallickal | a129d92 | 2013-09-28 15:35:46 -0700 | [diff] [blame] | 2406 | mem_descr_index = (HWI_MEM_TEMPLATE_HDR_ULP0 + |
| 2407 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2408 | phba->mem_req[mem_descr_index] = |
| 2409 | BEISCSI_GET_CID_COUNT(phba, ulp_num) * |
| 2410 | BEISCSI_TEMPLATE_HDR_PER_CXN_SIZE; |
| 2411 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2412 | mem_descr_index = (HWI_MEM_ASYNC_HEADER_BUF_ULP0 + |
| 2413 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2414 | phba->mem_req[mem_descr_index] = |
| 2415 | num_async_pdu_buf_pages * |
| 2416 | PAGE_SIZE; |
| 2417 | |
| 2418 | mem_descr_index = (HWI_MEM_ASYNC_DATA_BUF_ULP0 + |
| 2419 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2420 | phba->mem_req[mem_descr_index] = |
| 2421 | num_async_pdu_data_pages * |
| 2422 | PAGE_SIZE; |
| 2423 | |
| 2424 | mem_descr_index = (HWI_MEM_ASYNC_HEADER_RING_ULP0 + |
| 2425 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2426 | phba->mem_req[mem_descr_index] = |
| 2427 | num_async_pdu_buf_sgl_pages * |
| 2428 | PAGE_SIZE; |
| 2429 | |
| 2430 | mem_descr_index = (HWI_MEM_ASYNC_DATA_RING_ULP0 + |
| 2431 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2432 | phba->mem_req[mem_descr_index] = |
| 2433 | num_async_pdu_data_sgl_pages * |
| 2434 | PAGE_SIZE; |
| 2435 | |
| 2436 | mem_descr_index = (HWI_MEM_ASYNC_HEADER_HANDLE_ULP0 + |
| 2437 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2438 | phba->mem_req[mem_descr_index] = |
Jitendra Bhivare | fecc382 | 2017-03-24 14:11:44 +0530 | [diff] [blame] | 2439 | BEISCSI_ASYNC_HDQ_SIZE(phba, ulp_num) * |
| 2440 | sizeof(struct hd_async_handle); |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2441 | |
| 2442 | mem_descr_index = (HWI_MEM_ASYNC_DATA_HANDLE_ULP0 + |
| 2443 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2444 | phba->mem_req[mem_descr_index] = |
Jitendra Bhivare | fecc382 | 2017-03-24 14:11:44 +0530 | [diff] [blame] | 2445 | BEISCSI_ASYNC_HDQ_SIZE(phba, ulp_num) * |
| 2446 | sizeof(struct hd_async_handle); |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2447 | |
| 2448 | mem_descr_index = (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0 + |
| 2449 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2450 | phba->mem_req[mem_descr_index] = |
Jitendra Bhivare | fecc382 | 2017-03-24 14:11:44 +0530 | [diff] [blame] | 2451 | sizeof(struct hd_async_context) + |
| 2452 | (BEISCSI_ASYNC_HDQ_SIZE(phba, ulp_num) * |
| 2453 | sizeof(struct hd_async_entry)); |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2454 | } |
| 2455 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2456 | } |
| 2457 | |
| 2458 | static int beiscsi_alloc_mem(struct beiscsi_hba *phba) |
| 2459 | { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2460 | dma_addr_t bus_add; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2461 | struct hwi_controller *phwi_ctrlr; |
| 2462 | struct be_mem_descriptor *mem_descr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2463 | struct mem_array *mem_arr, *mem_arr_orig; |
| 2464 | unsigned int i, j, alloc_size, curr_alloc_size; |
| 2465 | |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2466 | phba->phwi_ctrlr = kzalloc(phba->params.hwi_ws_sz, GFP_KERNEL); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2467 | if (!phba->phwi_ctrlr) |
| 2468 | return -ENOMEM; |
| 2469 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2470 | /* Allocate memory for wrb_context */ |
| 2471 | phwi_ctrlr = phba->phwi_ctrlr; |
| 2472 | phwi_ctrlr->wrb_context = kzalloc(sizeof(struct hwi_wrb_context) * |
| 2473 | phba->params.cxns_per_ctrl, |
| 2474 | GFP_KERNEL); |
Maurizio Lombardi | 0c88740 | 2015-10-01 10:56:25 +0200 | [diff] [blame] | 2475 | if (!phwi_ctrlr->wrb_context) { |
| 2476 | kfree(phba->phwi_ctrlr); |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2477 | return -ENOMEM; |
Maurizio Lombardi | 0c88740 | 2015-10-01 10:56:25 +0200 | [diff] [blame] | 2478 | } |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2479 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2480 | phba->init_mem = kcalloc(SE_MEM_MAX, sizeof(*mem_descr), |
| 2481 | GFP_KERNEL); |
| 2482 | if (!phba->init_mem) { |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2483 | kfree(phwi_ctrlr->wrb_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2484 | kfree(phba->phwi_ctrlr); |
| 2485 | return -ENOMEM; |
| 2486 | } |
| 2487 | |
| 2488 | mem_arr_orig = kmalloc(sizeof(*mem_arr_orig) * BEISCSI_MAX_FRAGS_INIT, |
| 2489 | GFP_KERNEL); |
| 2490 | if (!mem_arr_orig) { |
| 2491 | kfree(phba->init_mem); |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2492 | kfree(phwi_ctrlr->wrb_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2493 | kfree(phba->phwi_ctrlr); |
| 2494 | return -ENOMEM; |
| 2495 | } |
| 2496 | |
| 2497 | mem_descr = phba->init_mem; |
| 2498 | for (i = 0; i < SE_MEM_MAX; i++) { |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2499 | if (!phba->mem_req[i]) { |
| 2500 | mem_descr->mem_array = NULL; |
| 2501 | mem_descr++; |
| 2502 | continue; |
| 2503 | } |
| 2504 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2505 | j = 0; |
| 2506 | mem_arr = mem_arr_orig; |
| 2507 | alloc_size = phba->mem_req[i]; |
| 2508 | memset(mem_arr, 0, sizeof(struct mem_array) * |
| 2509 | BEISCSI_MAX_FRAGS_INIT); |
| 2510 | curr_alloc_size = min(be_max_phys_size * 1024, alloc_size); |
| 2511 | do { |
| 2512 | mem_arr->virtual_address = pci_alloc_consistent( |
| 2513 | phba->pcidev, |
| 2514 | curr_alloc_size, |
| 2515 | &bus_add); |
| 2516 | if (!mem_arr->virtual_address) { |
| 2517 | if (curr_alloc_size <= BE_MIN_MEM_SIZE) |
| 2518 | goto free_mem; |
| 2519 | if (curr_alloc_size - |
| 2520 | rounddown_pow_of_two(curr_alloc_size)) |
| 2521 | curr_alloc_size = rounddown_pow_of_two |
| 2522 | (curr_alloc_size); |
| 2523 | else |
| 2524 | curr_alloc_size = curr_alloc_size / 2; |
| 2525 | } else { |
| 2526 | mem_arr->bus_address.u. |
| 2527 | a64.address = (__u64) bus_add; |
| 2528 | mem_arr->size = curr_alloc_size; |
| 2529 | alloc_size -= curr_alloc_size; |
| 2530 | curr_alloc_size = min(be_max_phys_size * |
| 2531 | 1024, alloc_size); |
| 2532 | j++; |
| 2533 | mem_arr++; |
| 2534 | } |
| 2535 | } while (alloc_size); |
| 2536 | mem_descr->num_elements = j; |
| 2537 | mem_descr->size_in_bytes = phba->mem_req[i]; |
| 2538 | mem_descr->mem_array = kmalloc(sizeof(*mem_arr) * j, |
| 2539 | GFP_KERNEL); |
| 2540 | if (!mem_descr->mem_array) |
| 2541 | goto free_mem; |
| 2542 | |
| 2543 | memcpy(mem_descr->mem_array, mem_arr_orig, |
| 2544 | sizeof(struct mem_array) * j); |
| 2545 | mem_descr++; |
| 2546 | } |
| 2547 | kfree(mem_arr_orig); |
| 2548 | return 0; |
| 2549 | free_mem: |
| 2550 | mem_descr->num_elements = j; |
| 2551 | while ((i) || (j)) { |
| 2552 | for (j = mem_descr->num_elements; j > 0; j--) { |
| 2553 | pci_free_consistent(phba->pcidev, |
| 2554 | mem_descr->mem_array[j - 1].size, |
| 2555 | mem_descr->mem_array[j - 1]. |
| 2556 | virtual_address, |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 2557 | (unsigned long)mem_descr-> |
| 2558 | mem_array[j - 1]. |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2559 | bus_address.u.a64.address); |
| 2560 | } |
| 2561 | if (i) { |
| 2562 | i--; |
| 2563 | kfree(mem_descr->mem_array); |
| 2564 | mem_descr--; |
| 2565 | } |
| 2566 | } |
| 2567 | kfree(mem_arr_orig); |
| 2568 | kfree(phba->init_mem); |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2569 | kfree(phba->phwi_ctrlr->wrb_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2570 | kfree(phba->phwi_ctrlr); |
| 2571 | return -ENOMEM; |
| 2572 | } |
| 2573 | |
| 2574 | static int beiscsi_get_memory(struct beiscsi_hba *phba) |
| 2575 | { |
| 2576 | beiscsi_find_mem_req(phba); |
| 2577 | return beiscsi_alloc_mem(phba); |
| 2578 | } |
| 2579 | |
| 2580 | static void iscsi_init_global_templates(struct beiscsi_hba *phba) |
| 2581 | { |
| 2582 | struct pdu_data_out *pdata_out; |
| 2583 | struct pdu_nop_out *pnop_out; |
| 2584 | struct be_mem_descriptor *mem_descr; |
| 2585 | |
| 2586 | mem_descr = phba->init_mem; |
| 2587 | mem_descr += ISCSI_MEM_GLOBAL_HEADER; |
| 2588 | pdata_out = |
| 2589 | (struct pdu_data_out *)mem_descr->mem_array[0].virtual_address; |
| 2590 | memset(pdata_out, 0, BE_ISCSI_PDU_HEADER_SIZE); |
| 2591 | |
| 2592 | AMAP_SET_BITS(struct amap_pdu_data_out, opcode, pdata_out, |
| 2593 | IIOC_SCSI_DATA); |
| 2594 | |
| 2595 | pnop_out = |
| 2596 | (struct pdu_nop_out *)((unsigned char *)mem_descr->mem_array[0]. |
| 2597 | virtual_address + BE_ISCSI_PDU_HEADER_SIZE); |
| 2598 | |
| 2599 | memset(pnop_out, 0, BE_ISCSI_PDU_HEADER_SIZE); |
| 2600 | AMAP_SET_BITS(struct amap_pdu_nop_out, ttt, pnop_out, 0xFFFFFFFF); |
| 2601 | AMAP_SET_BITS(struct amap_pdu_nop_out, f_bit, pnop_out, 1); |
| 2602 | AMAP_SET_BITS(struct amap_pdu_nop_out, i_bit, pnop_out, 0); |
| 2603 | } |
| 2604 | |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2605 | static int beiscsi_init_wrb_handle(struct beiscsi_hba *phba) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2606 | { |
| 2607 | struct be_mem_descriptor *mem_descr_wrbh, *mem_descr_wrb; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2608 | struct hwi_context_memory *phwi_ctxt; |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2609 | struct wrb_handle *pwrb_handle = NULL; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2610 | struct hwi_controller *phwi_ctrlr; |
| 2611 | struct hwi_wrb_context *pwrb_context; |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2612 | struct iscsi_wrb *pwrb = NULL; |
| 2613 | unsigned int num_cxn_wrbh = 0; |
| 2614 | unsigned int num_cxn_wrb = 0, j, idx = 0, index; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2615 | |
| 2616 | mem_descr_wrbh = phba->init_mem; |
| 2617 | mem_descr_wrbh += HWI_MEM_WRBH; |
| 2618 | |
| 2619 | mem_descr_wrb = phba->init_mem; |
| 2620 | mem_descr_wrb += HWI_MEM_WRB; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2621 | phwi_ctrlr = phba->phwi_ctrlr; |
| 2622 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2623 | /* Allocate memory for WRBQ */ |
| 2624 | phwi_ctxt = phwi_ctrlr->phwi_ctxt; |
| 2625 | phwi_ctxt->be_wrbq = kzalloc(sizeof(struct be_queue_info) * |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 2626 | phba->params.cxns_per_ctrl, |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2627 | GFP_KERNEL); |
| 2628 | if (!phwi_ctxt->be_wrbq) { |
| 2629 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 2630 | "BM_%d : WRBQ Mem Alloc Failed\n"); |
| 2631 | return -ENOMEM; |
| 2632 | } |
| 2633 | |
| 2634 | for (index = 0; index < phba->params.cxns_per_ctrl; index++) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2635 | pwrb_context = &phwi_ctrlr->wrb_context[index]; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2636 | pwrb_context->pwrb_handle_base = |
| 2637 | kzalloc(sizeof(struct wrb_handle *) * |
| 2638 | phba->params.wrbs_per_cxn, GFP_KERNEL); |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2639 | if (!pwrb_context->pwrb_handle_base) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2640 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 2641 | "BM_%d : Mem Alloc Failed. Failing to load\n"); |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2642 | goto init_wrb_hndl_failed; |
| 2643 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2644 | pwrb_context->pwrb_handle_basestd = |
| 2645 | kzalloc(sizeof(struct wrb_handle *) * |
| 2646 | phba->params.wrbs_per_cxn, GFP_KERNEL); |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2647 | if (!pwrb_context->pwrb_handle_basestd) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2648 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 2649 | "BM_%d : Mem Alloc Failed. Failing to load\n"); |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2650 | goto init_wrb_hndl_failed; |
| 2651 | } |
| 2652 | if (!num_cxn_wrbh) { |
| 2653 | pwrb_handle = |
| 2654 | mem_descr_wrbh->mem_array[idx].virtual_address; |
| 2655 | num_cxn_wrbh = ((mem_descr_wrbh->mem_array[idx].size) / |
| 2656 | ((sizeof(struct wrb_handle)) * |
| 2657 | phba->params.wrbs_per_cxn)); |
| 2658 | idx++; |
| 2659 | } |
| 2660 | pwrb_context->alloc_index = 0; |
| 2661 | pwrb_context->wrb_handles_available = 0; |
| 2662 | pwrb_context->free_index = 0; |
| 2663 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2664 | if (num_cxn_wrbh) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2665 | for (j = 0; j < phba->params.wrbs_per_cxn; j++) { |
| 2666 | pwrb_context->pwrb_handle_base[j] = pwrb_handle; |
| 2667 | pwrb_context->pwrb_handle_basestd[j] = |
| 2668 | pwrb_handle; |
| 2669 | pwrb_context->wrb_handles_available++; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2670 | pwrb_handle->wrb_index = j; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2671 | pwrb_handle++; |
| 2672 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2673 | num_cxn_wrbh--; |
| 2674 | } |
Jitendra Bhivare | f64d92e | 2016-02-04 15:49:20 +0530 | [diff] [blame] | 2675 | spin_lock_init(&pwrb_context->wrb_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2676 | } |
| 2677 | idx = 0; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2678 | for (index = 0; index < phba->params.cxns_per_ctrl; index++) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2679 | pwrb_context = &phwi_ctrlr->wrb_context[index]; |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2680 | if (!num_cxn_wrb) { |
| 2681 | pwrb = mem_descr_wrb->mem_array[idx].virtual_address; |
| 2682 | num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) / |
| 2683 | ((sizeof(struct iscsi_wrb) * |
| 2684 | phba->params.wrbs_per_cxn)); |
| 2685 | idx++; |
| 2686 | } |
| 2687 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2688 | if (num_cxn_wrb) { |
| 2689 | for (j = 0; j < phba->params.wrbs_per_cxn; j++) { |
| 2690 | pwrb_handle = pwrb_context->pwrb_handle_base[j]; |
| 2691 | pwrb_handle->pwrb = pwrb; |
| 2692 | pwrb++; |
| 2693 | } |
| 2694 | num_cxn_wrb--; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2695 | } |
| 2696 | } |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2697 | return 0; |
| 2698 | init_wrb_hndl_failed: |
| 2699 | for (j = index; j > 0; j--) { |
| 2700 | pwrb_context = &phwi_ctrlr->wrb_context[j]; |
| 2701 | kfree(pwrb_context->pwrb_handle_base); |
| 2702 | kfree(pwrb_context->pwrb_handle_basestd); |
| 2703 | } |
| 2704 | return -ENOMEM; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2705 | } |
| 2706 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2707 | static int hwi_init_async_pdu_ctx(struct beiscsi_hba *phba) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2708 | { |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2709 | uint8_t ulp_num; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2710 | struct hwi_controller *phwi_ctrlr; |
| 2711 | struct hba_parameters *p = &phba->params; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2712 | struct hd_async_context *pasync_ctx; |
| 2713 | struct hd_async_handle *pasync_header_h, *pasync_data_h; |
Jayamohan Kallickal | dc63aac | 2012-04-03 23:41:36 -0500 | [diff] [blame] | 2714 | unsigned int index, idx, num_per_mem, num_async_data; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2715 | struct be_mem_descriptor *mem_descr; |
| 2716 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2717 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 2718 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
Jitendra Bhivare | d740105 | 2016-12-13 15:55:59 +0530 | [diff] [blame] | 2719 | /* get async_ctx for each ULP */ |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2720 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 2721 | mem_descr += (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0 + |
| 2722 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2723 | |
| 2724 | phwi_ctrlr = phba->phwi_ctrlr; |
| 2725 | phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num] = |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2726 | (struct hd_async_context *) |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2727 | mem_descr->mem_array[0].virtual_address; |
| 2728 | |
| 2729 | pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num]; |
| 2730 | memset(pasync_ctx, 0, sizeof(*pasync_ctx)); |
| 2731 | |
| 2732 | pasync_ctx->async_entry = |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2733 | (struct hd_async_entry *) |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2734 | ((long unsigned int)pasync_ctx + |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2735 | sizeof(struct hd_async_context)); |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2736 | |
Jitendra Bhivare | fecc382 | 2017-03-24 14:11:44 +0530 | [diff] [blame] | 2737 | pasync_ctx->num_entries = BEISCSI_ASYNC_HDQ_SIZE(phba, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2738 | ulp_num); |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2739 | /* setup header buffers */ |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2740 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 2741 | mem_descr += HWI_MEM_ASYNC_HEADER_BUF_ULP0 + |
| 2742 | (ulp_num * MEM_DESCR_OFFSET); |
| 2743 | if (mem_descr->mem_array[0].virtual_address) { |
| 2744 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 2745 | "BM_%d : hwi_init_async_pdu_ctx" |
| 2746 | " HWI_MEM_ASYNC_HEADER_BUF_ULP%d va=%p\n", |
| 2747 | ulp_num, |
| 2748 | mem_descr->mem_array[0]. |
| 2749 | virtual_address); |
| 2750 | } else |
| 2751 | beiscsi_log(phba, KERN_WARNING, |
| 2752 | BEISCSI_LOG_INIT, |
| 2753 | "BM_%d : No Virtual address for ULP : %d\n", |
| 2754 | ulp_num); |
| 2755 | |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 2756 | pasync_ctx->async_header.pi = 0; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2757 | pasync_ctx->async_header.buffer_size = p->defpdu_hdr_sz; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2758 | pasync_ctx->async_header.va_base = |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2759 | mem_descr->mem_array[0].virtual_address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2760 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2761 | pasync_ctx->async_header.pa_base.u.a64.address = |
| 2762 | mem_descr->mem_array[0]. |
| 2763 | bus_address.u.a64.address; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2764 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2765 | /* setup header buffer sgls */ |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2766 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 2767 | mem_descr += HWI_MEM_ASYNC_HEADER_RING_ULP0 + |
| 2768 | (ulp_num * MEM_DESCR_OFFSET); |
| 2769 | if (mem_descr->mem_array[0].virtual_address) { |
| 2770 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 2771 | "BM_%d : hwi_init_async_pdu_ctx" |
| 2772 | " HWI_MEM_ASYNC_HEADER_RING_ULP%d va=%p\n", |
| 2773 | ulp_num, |
| 2774 | mem_descr->mem_array[0]. |
| 2775 | virtual_address); |
| 2776 | } else |
| 2777 | beiscsi_log(phba, KERN_WARNING, |
| 2778 | BEISCSI_LOG_INIT, |
| 2779 | "BM_%d : No Virtual address for ULP : %d\n", |
| 2780 | ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2781 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2782 | pasync_ctx->async_header.ring_base = |
| 2783 | mem_descr->mem_array[0].virtual_address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2784 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2785 | /* setup header buffer handles */ |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2786 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 2787 | mem_descr += HWI_MEM_ASYNC_HEADER_HANDLE_ULP0 + |
| 2788 | (ulp_num * MEM_DESCR_OFFSET); |
| 2789 | if (mem_descr->mem_array[0].virtual_address) { |
| 2790 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 2791 | "BM_%d : hwi_init_async_pdu_ctx" |
| 2792 | " HWI_MEM_ASYNC_HEADER_HANDLE_ULP%d va=%p\n", |
| 2793 | ulp_num, |
| 2794 | mem_descr->mem_array[0]. |
| 2795 | virtual_address); |
| 2796 | } else |
| 2797 | beiscsi_log(phba, KERN_WARNING, |
| 2798 | BEISCSI_LOG_INIT, |
| 2799 | "BM_%d : No Virtual address for ULP : %d\n", |
| 2800 | ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2801 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2802 | pasync_ctx->async_header.handle_base = |
| 2803 | mem_descr->mem_array[0].virtual_address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2804 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2805 | /* setup data buffer sgls */ |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2806 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 2807 | mem_descr += HWI_MEM_ASYNC_DATA_RING_ULP0 + |
| 2808 | (ulp_num * MEM_DESCR_OFFSET); |
| 2809 | if (mem_descr->mem_array[0].virtual_address) { |
| 2810 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 2811 | "BM_%d : hwi_init_async_pdu_ctx" |
| 2812 | " HWI_MEM_ASYNC_DATA_RING_ULP%d va=%p\n", |
| 2813 | ulp_num, |
| 2814 | mem_descr->mem_array[0]. |
| 2815 | virtual_address); |
| 2816 | } else |
| 2817 | beiscsi_log(phba, KERN_WARNING, |
| 2818 | BEISCSI_LOG_INIT, |
| 2819 | "BM_%d : No Virtual address for ULP : %d\n", |
| 2820 | ulp_num); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2821 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2822 | pasync_ctx->async_data.ring_base = |
| 2823 | mem_descr->mem_array[0].virtual_address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2824 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2825 | /* setup data buffer handles */ |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2826 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 2827 | mem_descr += HWI_MEM_ASYNC_DATA_HANDLE_ULP0 + |
| 2828 | (ulp_num * MEM_DESCR_OFFSET); |
| 2829 | if (!mem_descr->mem_array[0].virtual_address) |
| 2830 | beiscsi_log(phba, KERN_WARNING, |
| 2831 | BEISCSI_LOG_INIT, |
| 2832 | "BM_%d : No Virtual address for ULP : %d\n", |
| 2833 | ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2834 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2835 | pasync_ctx->async_data.handle_base = |
| 2836 | mem_descr->mem_array[0].virtual_address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2837 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2838 | pasync_header_h = |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2839 | (struct hd_async_handle *) |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2840 | pasync_ctx->async_header.handle_base; |
| 2841 | pasync_data_h = |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2842 | (struct hd_async_handle *) |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2843 | pasync_ctx->async_data.handle_base; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2844 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2845 | /* setup data buffers */ |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2846 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 2847 | mem_descr += HWI_MEM_ASYNC_DATA_BUF_ULP0 + |
| 2848 | (ulp_num * MEM_DESCR_OFFSET); |
| 2849 | if (mem_descr->mem_array[0].virtual_address) { |
| 2850 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 2851 | "BM_%d : hwi_init_async_pdu_ctx" |
| 2852 | " HWI_MEM_ASYNC_DATA_BUF_ULP%d va=%p\n", |
| 2853 | ulp_num, |
| 2854 | mem_descr->mem_array[0]. |
| 2855 | virtual_address); |
| 2856 | } else |
| 2857 | beiscsi_log(phba, KERN_WARNING, |
| 2858 | BEISCSI_LOG_INIT, |
| 2859 | "BM_%d : No Virtual address for ULP : %d\n", |
| 2860 | ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2861 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2862 | idx = 0; |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 2863 | pasync_ctx->async_data.pi = 0; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2864 | pasync_ctx->async_data.buffer_size = p->defpdu_data_sz; |
Jayamohan Kallickal | dc63aac | 2012-04-03 23:41:36 -0500 | [diff] [blame] | 2865 | pasync_ctx->async_data.va_base = |
| 2866 | mem_descr->mem_array[idx].virtual_address; |
| 2867 | pasync_ctx->async_data.pa_base.u.a64.address = |
| 2868 | mem_descr->mem_array[idx]. |
| 2869 | bus_address.u.a64.address; |
| 2870 | |
| 2871 | num_async_data = ((mem_descr->mem_array[idx].size) / |
| 2872 | phba->params.defpdu_data_sz); |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2873 | num_per_mem = 0; |
| 2874 | |
Jitendra Bhivare | fecc382 | 2017-03-24 14:11:44 +0530 | [diff] [blame] | 2875 | for (index = 0; index < BEISCSI_ASYNC_HDQ_SIZE |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2876 | (phba, ulp_num); index++) { |
| 2877 | pasync_header_h->cri = -1; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2878 | pasync_header_h->is_header = 1; |
| 2879 | pasync_header_h->index = index; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2880 | INIT_LIST_HEAD(&pasync_header_h->link); |
| 2881 | pasync_header_h->pbuffer = |
| 2882 | (void *)((unsigned long) |
| 2883 | (pasync_ctx-> |
| 2884 | async_header.va_base) + |
| 2885 | (p->defpdu_hdr_sz * index)); |
| 2886 | |
| 2887 | pasync_header_h->pa.u.a64.address = |
| 2888 | pasync_ctx->async_header.pa_base.u.a64. |
| 2889 | address + (p->defpdu_hdr_sz * index); |
| 2890 | |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 2891 | pasync_ctx->async_entry[index].header = |
| 2892 | pasync_header_h; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2893 | pasync_header_h++; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2894 | INIT_LIST_HEAD(&pasync_ctx->async_entry[index]. |
| 2895 | wq.list); |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2896 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2897 | pasync_data_h->cri = -1; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2898 | pasync_data_h->is_header = 0; |
| 2899 | pasync_data_h->index = index; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2900 | INIT_LIST_HEAD(&pasync_data_h->link); |
| 2901 | |
| 2902 | if (!num_async_data) { |
| 2903 | num_per_mem = 0; |
| 2904 | idx++; |
| 2905 | pasync_ctx->async_data.va_base = |
| 2906 | mem_descr->mem_array[idx]. |
| 2907 | virtual_address; |
| 2908 | pasync_ctx->async_data.pa_base.u. |
| 2909 | a64.address = |
| 2910 | mem_descr->mem_array[idx]. |
| 2911 | bus_address.u.a64.address; |
| 2912 | num_async_data = |
| 2913 | ((mem_descr->mem_array[idx]. |
| 2914 | size) / |
| 2915 | phba->params.defpdu_data_sz); |
| 2916 | } |
| 2917 | pasync_data_h->pbuffer = |
| 2918 | (void *)((unsigned long) |
| 2919 | (pasync_ctx->async_data.va_base) + |
| 2920 | (p->defpdu_data_sz * num_per_mem)); |
| 2921 | |
| 2922 | pasync_data_h->pa.u.a64.address = |
| 2923 | pasync_ctx->async_data.pa_base.u.a64. |
| 2924 | address + (p->defpdu_data_sz * |
| 2925 | num_per_mem); |
| 2926 | num_per_mem++; |
| 2927 | num_async_data--; |
| 2928 | |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 2929 | pasync_ctx->async_entry[index].data = |
| 2930 | pasync_data_h; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2931 | pasync_data_h++; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2932 | } |
Jayamohan Kallickal | dc63aac | 2012-04-03 23:41:36 -0500 | [diff] [blame] | 2933 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2934 | } |
| 2935 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2936 | return 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2937 | } |
| 2938 | |
| 2939 | static int |
| 2940 | be_sgl_create_contiguous(void *virtual_address, |
| 2941 | u64 physical_address, u32 length, |
| 2942 | struct be_dma_mem *sgl) |
| 2943 | { |
| 2944 | WARN_ON(!virtual_address); |
| 2945 | WARN_ON(!physical_address); |
Tim Gardner | dd29dae | 2015-10-30 12:22:58 -0600 | [diff] [blame] | 2946 | WARN_ON(!length); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2947 | WARN_ON(!sgl); |
| 2948 | |
| 2949 | sgl->va = virtual_address; |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 2950 | sgl->dma = (unsigned long)physical_address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2951 | sgl->size = length; |
| 2952 | |
| 2953 | return 0; |
| 2954 | } |
| 2955 | |
| 2956 | static void be_sgl_destroy_contiguous(struct be_dma_mem *sgl) |
| 2957 | { |
| 2958 | memset(sgl, 0, sizeof(*sgl)); |
| 2959 | } |
| 2960 | |
| 2961 | static void |
| 2962 | hwi_build_be_sgl_arr(struct beiscsi_hba *phba, |
| 2963 | struct mem_array *pmem, struct be_dma_mem *sgl) |
| 2964 | { |
| 2965 | if (sgl->va) |
| 2966 | be_sgl_destroy_contiguous(sgl); |
| 2967 | |
| 2968 | be_sgl_create_contiguous(pmem->virtual_address, |
| 2969 | pmem->bus_address.u.a64.address, |
| 2970 | pmem->size, sgl); |
| 2971 | } |
| 2972 | |
| 2973 | static void |
| 2974 | hwi_build_be_sgl_by_offset(struct beiscsi_hba *phba, |
| 2975 | struct mem_array *pmem, struct be_dma_mem *sgl) |
| 2976 | { |
| 2977 | if (sgl->va) |
| 2978 | be_sgl_destroy_contiguous(sgl); |
| 2979 | |
| 2980 | be_sgl_create_contiguous((unsigned char *)pmem->virtual_address, |
| 2981 | pmem->bus_address.u.a64.address, |
| 2982 | pmem->size, sgl); |
| 2983 | } |
| 2984 | |
| 2985 | static int be_fill_queue(struct be_queue_info *q, |
| 2986 | u16 len, u16 entry_size, void *vaddress) |
| 2987 | { |
| 2988 | struct be_dma_mem *mem = &q->dma_mem; |
| 2989 | |
| 2990 | memset(q, 0, sizeof(*q)); |
| 2991 | q->len = len; |
| 2992 | q->entry_size = entry_size; |
| 2993 | mem->size = len * entry_size; |
| 2994 | mem->va = vaddress; |
| 2995 | if (!mem->va) |
| 2996 | return -ENOMEM; |
| 2997 | memset(mem->va, 0, mem->size); |
| 2998 | return 0; |
| 2999 | } |
| 3000 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3001 | static int beiscsi_create_eqs(struct beiscsi_hba *phba, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3002 | struct hwi_context_memory *phwi_context) |
| 3003 | { |
Christophe JAILLET | deeea8e | 2016-08-26 15:09:06 +0530 | [diff] [blame] | 3004 | int ret = -ENOMEM, eq_for_mcc; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3005 | unsigned int i, num_eq_pages; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3006 | struct be_queue_info *eq; |
| 3007 | struct be_dma_mem *mem; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3008 | void *eq_vaddress; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3009 | dma_addr_t paddr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3010 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3011 | num_eq_pages = PAGES_REQUIRED(phba->params.num_eq_entries * \ |
| 3012 | sizeof(struct be_eq_entry)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3013 | |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 3014 | if (phba->pcidev->msix_enabled) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3015 | eq_for_mcc = 1; |
| 3016 | else |
| 3017 | eq_for_mcc = 0; |
| 3018 | for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) { |
| 3019 | eq = &phwi_context->be_eq[i].q; |
| 3020 | mem = &eq->dma_mem; |
| 3021 | phwi_context->be_eq[i].phba = phba; |
| 3022 | eq_vaddress = pci_alloc_consistent(phba->pcidev, |
Christophe JAILLET | deeea8e | 2016-08-26 15:09:06 +0530 | [diff] [blame] | 3023 | num_eq_pages * PAGE_SIZE, |
| 3024 | &paddr); |
Pan Bian | 84a261f | 2016-12-04 13:23:04 +0800 | [diff] [blame] | 3025 | if (!eq_vaddress) { |
| 3026 | ret = -ENOMEM; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3027 | goto create_eq_error; |
Pan Bian | 84a261f | 2016-12-04 13:23:04 +0800 | [diff] [blame] | 3028 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3029 | |
| 3030 | mem->va = eq_vaddress; |
| 3031 | ret = be_fill_queue(eq, phba->params.num_eq_entries, |
| 3032 | sizeof(struct be_eq_entry), eq_vaddress); |
| 3033 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3034 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3035 | "BM_%d : be_fill_queue Failed for EQ\n"); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3036 | goto create_eq_error; |
| 3037 | } |
| 3038 | |
| 3039 | mem->dma = paddr; |
| 3040 | ret = beiscsi_cmd_eq_create(&phba->ctrl, eq, |
Jitendra Bhivare | 45efc940 | 2017-10-10 16:18:18 +0530 | [diff] [blame] | 3041 | BEISCSI_EQ_DELAY_DEF); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3042 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3043 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3044 | "BM_%d : beiscsi_cmd_eq_create" |
| 3045 | "Failed for EQ\n"); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3046 | goto create_eq_error; |
| 3047 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3048 | |
| 3049 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3050 | "BM_%d : eqid = %d\n", |
| 3051 | phwi_context->be_eq[i].q.id); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3052 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3053 | return 0; |
Christophe JAILLET | deeea8e | 2016-08-26 15:09:06 +0530 | [diff] [blame] | 3054 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3055 | create_eq_error: |
John Soni Jose | 107dfcb | 2012-10-20 04:42:13 +0530 | [diff] [blame] | 3056 | for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3057 | eq = &phwi_context->be_eq[i].q; |
| 3058 | mem = &eq->dma_mem; |
| 3059 | if (mem->va) |
| 3060 | pci_free_consistent(phba->pcidev, num_eq_pages |
| 3061 | * PAGE_SIZE, |
| 3062 | mem->va, mem->dma); |
| 3063 | } |
| 3064 | return ret; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3065 | } |
| 3066 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3067 | static int beiscsi_create_cqs(struct beiscsi_hba *phba, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3068 | struct hwi_context_memory *phwi_context) |
| 3069 | { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3070 | unsigned int i, num_cq_pages; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3071 | struct be_queue_info *cq, *eq; |
| 3072 | struct be_dma_mem *mem; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3073 | struct be_eq_obj *pbe_eq; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3074 | void *cq_vaddress; |
Christophe JAILLET | deeea8e | 2016-08-26 15:09:06 +0530 | [diff] [blame] | 3075 | int ret = -ENOMEM; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3076 | dma_addr_t paddr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3077 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3078 | num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \ |
| 3079 | sizeof(struct sol_cqe)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3080 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3081 | for (i = 0; i < phba->num_cpus; i++) { |
| 3082 | cq = &phwi_context->be_cq[i]; |
| 3083 | eq = &phwi_context->be_eq[i].q; |
| 3084 | pbe_eq = &phwi_context->be_eq[i]; |
| 3085 | pbe_eq->cq = cq; |
| 3086 | pbe_eq->phba = phba; |
| 3087 | mem = &cq->dma_mem; |
| 3088 | cq_vaddress = pci_alloc_consistent(phba->pcidev, |
Christophe JAILLET | deeea8e | 2016-08-26 15:09:06 +0530 | [diff] [blame] | 3089 | num_cq_pages * PAGE_SIZE, |
| 3090 | &paddr); |
Pan Bian | 29b3325 | 2016-12-04 13:21:42 +0800 | [diff] [blame] | 3091 | if (!cq_vaddress) { |
| 3092 | ret = -ENOMEM; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3093 | goto create_cq_error; |
Pan Bian | 29b3325 | 2016-12-04 13:21:42 +0800 | [diff] [blame] | 3094 | } |
Christophe JAILLET | deeea8e | 2016-08-26 15:09:06 +0530 | [diff] [blame] | 3095 | |
Jayamohan Kallickal | 7da5087 | 2010-01-05 05:04:12 +0530 | [diff] [blame] | 3096 | ret = be_fill_queue(cq, phba->params.num_cq_entries, |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3097 | sizeof(struct sol_cqe), cq_vaddress); |
| 3098 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3099 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3100 | "BM_%d : be_fill_queue Failed " |
| 3101 | "for ISCSI CQ\n"); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3102 | goto create_cq_error; |
| 3103 | } |
| 3104 | |
| 3105 | mem->dma = paddr; |
| 3106 | ret = beiscsi_cmd_cq_create(&phba->ctrl, cq, eq, false, |
| 3107 | false, 0); |
| 3108 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3109 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3110 | "BM_%d : beiscsi_cmd_eq_create" |
| 3111 | "Failed for ISCSI CQ\n"); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3112 | goto create_cq_error; |
| 3113 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3114 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3115 | "BM_%d : iscsi cq_id is %d for eq_id %d\n" |
| 3116 | "iSCSI CQ CREATED\n", cq->id, eq->id); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3117 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3118 | return 0; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3119 | |
| 3120 | create_cq_error: |
| 3121 | for (i = 0; i < phba->num_cpus; i++) { |
| 3122 | cq = &phwi_context->be_cq[i]; |
| 3123 | mem = &cq->dma_mem; |
| 3124 | if (mem->va) |
| 3125 | pci_free_consistent(phba->pcidev, num_cq_pages |
| 3126 | * PAGE_SIZE, |
| 3127 | mem->va, mem->dma); |
| 3128 | } |
| 3129 | return ret; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3130 | } |
| 3131 | |
| 3132 | static int |
| 3133 | beiscsi_create_def_hdr(struct beiscsi_hba *phba, |
| 3134 | struct hwi_context_memory *phwi_context, |
| 3135 | struct hwi_controller *phwi_ctrlr, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3136 | unsigned int def_pdu_ring_sz, uint8_t ulp_num) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3137 | { |
| 3138 | unsigned int idx; |
| 3139 | int ret; |
| 3140 | struct be_queue_info *dq, *cq; |
| 3141 | struct be_dma_mem *mem; |
| 3142 | struct be_mem_descriptor *mem_descr; |
| 3143 | void *dq_vaddress; |
| 3144 | |
| 3145 | idx = 0; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3146 | dq = &phwi_context->be_def_hdrq[ulp_num]; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3147 | cq = &phwi_context->be_cq[0]; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3148 | mem = &dq->dma_mem; |
| 3149 | mem_descr = phba->init_mem; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3150 | mem_descr += HWI_MEM_ASYNC_HEADER_RING_ULP0 + |
| 3151 | (ulp_num * MEM_DESCR_OFFSET); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3152 | dq_vaddress = mem_descr->mem_array[idx].virtual_address; |
| 3153 | ret = be_fill_queue(dq, mem_descr->mem_array[0].size / |
| 3154 | sizeof(struct phys_addr), |
| 3155 | sizeof(struct phys_addr), dq_vaddress); |
| 3156 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3157 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3158 | "BM_%d : be_fill_queue Failed for DEF PDU HDR on ULP : %d\n", |
| 3159 | ulp_num); |
| 3160 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3161 | return ret; |
| 3162 | } |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 3163 | mem->dma = (unsigned long)mem_descr->mem_array[idx]. |
| 3164 | bus_address.u.a64.address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3165 | ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dq, |
| 3166 | def_pdu_ring_sz, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3167 | phba->params.defpdu_hdr_sz, |
| 3168 | BEISCSI_DEFQ_HDR, ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3169 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3170 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3171 | "BM_%d : be_cmd_create_default_pdu_queue Failed DEFHDR on ULP : %d\n", |
| 3172 | ulp_num); |
| 3173 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3174 | return ret; |
| 3175 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3176 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3177 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3178 | "BM_%d : iscsi hdr def pdu id for ULP : %d is %d\n", |
| 3179 | ulp_num, |
| 3180 | phwi_context->be_def_hdrq[ulp_num].id); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3181 | return 0; |
| 3182 | } |
| 3183 | |
| 3184 | static int |
| 3185 | beiscsi_create_def_data(struct beiscsi_hba *phba, |
| 3186 | struct hwi_context_memory *phwi_context, |
| 3187 | struct hwi_controller *phwi_ctrlr, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3188 | unsigned int def_pdu_ring_sz, uint8_t ulp_num) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3189 | { |
| 3190 | unsigned int idx; |
| 3191 | int ret; |
| 3192 | struct be_queue_info *dataq, *cq; |
| 3193 | struct be_dma_mem *mem; |
| 3194 | struct be_mem_descriptor *mem_descr; |
| 3195 | void *dq_vaddress; |
| 3196 | |
| 3197 | idx = 0; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3198 | dataq = &phwi_context->be_def_dataq[ulp_num]; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3199 | cq = &phwi_context->be_cq[0]; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3200 | mem = &dataq->dma_mem; |
| 3201 | mem_descr = phba->init_mem; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3202 | mem_descr += HWI_MEM_ASYNC_DATA_RING_ULP0 + |
| 3203 | (ulp_num * MEM_DESCR_OFFSET); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3204 | dq_vaddress = mem_descr->mem_array[idx].virtual_address; |
| 3205 | ret = be_fill_queue(dataq, mem_descr->mem_array[0].size / |
| 3206 | sizeof(struct phys_addr), |
| 3207 | sizeof(struct phys_addr), dq_vaddress); |
| 3208 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3209 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3210 | "BM_%d : be_fill_queue Failed for DEF PDU " |
| 3211 | "DATA on ULP : %d\n", |
| 3212 | ulp_num); |
| 3213 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3214 | return ret; |
| 3215 | } |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 3216 | mem->dma = (unsigned long)mem_descr->mem_array[idx]. |
| 3217 | bus_address.u.a64.address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3218 | ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dataq, |
| 3219 | def_pdu_ring_sz, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3220 | phba->params.defpdu_data_sz, |
| 3221 | BEISCSI_DEFQ_DATA, ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3222 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3223 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3224 | "BM_%d be_cmd_create_default_pdu_queue" |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3225 | " Failed for DEF PDU DATA on ULP : %d\n", |
| 3226 | ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3227 | return ret; |
| 3228 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3229 | |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3230 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3231 | "BM_%d : iscsi def data id on ULP : %d is %d\n", |
| 3232 | ulp_num, |
| 3233 | phwi_context->be_def_dataq[ulp_num].id); |
| 3234 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3235 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3236 | "BM_%d : DEFAULT PDU DATA RING CREATED" |
| 3237 | "on ULP : %d\n", ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3238 | return 0; |
| 3239 | } |
| 3240 | |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3241 | |
| 3242 | static int |
| 3243 | beiscsi_post_template_hdr(struct beiscsi_hba *phba) |
| 3244 | { |
| 3245 | struct be_mem_descriptor *mem_descr; |
| 3246 | struct mem_array *pm_arr; |
| 3247 | struct be_dma_mem sgl; |
Jayamohan Kallickal | a129d92 | 2013-09-28 15:35:46 -0700 | [diff] [blame] | 3248 | int status, ulp_num; |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3249 | |
Jayamohan Kallickal | a129d92 | 2013-09-28 15:35:46 -0700 | [diff] [blame] | 3250 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 3251 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
| 3252 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 3253 | mem_descr += HWI_MEM_TEMPLATE_HDR_ULP0 + |
| 3254 | (ulp_num * MEM_DESCR_OFFSET); |
| 3255 | pm_arr = mem_descr->mem_array; |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3256 | |
Jayamohan Kallickal | a129d92 | 2013-09-28 15:35:46 -0700 | [diff] [blame] | 3257 | hwi_build_be_sgl_arr(phba, pm_arr, &sgl); |
| 3258 | status = be_cmd_iscsi_post_template_hdr( |
| 3259 | &phba->ctrl, &sgl); |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3260 | |
Jayamohan Kallickal | a129d92 | 2013-09-28 15:35:46 -0700 | [diff] [blame] | 3261 | if (status != 0) { |
| 3262 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3263 | "BM_%d : Post Template HDR Failed for" |
| 3264 | "ULP_%d\n", ulp_num); |
| 3265 | return status; |
| 3266 | } |
| 3267 | |
| 3268 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3269 | "BM_%d : Template HDR Pages Posted for" |
| 3270 | "ULP_%d\n", ulp_num); |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3271 | } |
| 3272 | } |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3273 | return 0; |
| 3274 | } |
| 3275 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3276 | static int |
| 3277 | beiscsi_post_pages(struct beiscsi_hba *phba) |
| 3278 | { |
| 3279 | struct be_mem_descriptor *mem_descr; |
| 3280 | struct mem_array *pm_arr; |
| 3281 | unsigned int page_offset, i; |
| 3282 | struct be_dma_mem sgl; |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 3283 | int status, ulp_num = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3284 | |
| 3285 | mem_descr = phba->init_mem; |
| 3286 | mem_descr += HWI_MEM_SGE; |
| 3287 | pm_arr = mem_descr->mem_array; |
| 3288 | |
Jayamohan Kallickal | 90622db | 2013-09-28 15:35:47 -0700 | [diff] [blame] | 3289 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) |
| 3290 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) |
| 3291 | break; |
| 3292 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3293 | page_offset = (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io * |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 3294 | phba->fw_config.iscsi_icd_start[ulp_num]) / PAGE_SIZE; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3295 | for (i = 0; i < mem_descr->num_elements; i++) { |
| 3296 | hwi_build_be_sgl_arr(phba, pm_arr, &sgl); |
| 3297 | status = be_cmd_iscsi_post_sgl_pages(&phba->ctrl, &sgl, |
| 3298 | page_offset, |
| 3299 | (pm_arr->size / PAGE_SIZE)); |
| 3300 | page_offset += pm_arr->size / PAGE_SIZE; |
| 3301 | if (status != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3302 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3303 | "BM_%d : post sgl failed.\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3304 | return status; |
| 3305 | } |
| 3306 | pm_arr++; |
| 3307 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3308 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3309 | "BM_%d : POSTED PAGES\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3310 | return 0; |
| 3311 | } |
| 3312 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3313 | static void be_queue_free(struct beiscsi_hba *phba, struct be_queue_info *q) |
| 3314 | { |
| 3315 | struct be_dma_mem *mem = &q->dma_mem; |
Jayamohan Kallickal | c8b2559 | 2012-04-03 23:41:42 -0500 | [diff] [blame] | 3316 | if (mem->va) { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3317 | pci_free_consistent(phba->pcidev, mem->size, |
| 3318 | mem->va, mem->dma); |
Jayamohan Kallickal | c8b2559 | 2012-04-03 23:41:42 -0500 | [diff] [blame] | 3319 | mem->va = NULL; |
| 3320 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3321 | } |
| 3322 | |
| 3323 | static int be_queue_alloc(struct beiscsi_hba *phba, struct be_queue_info *q, |
| 3324 | u16 len, u16 entry_size) |
| 3325 | { |
| 3326 | struct be_dma_mem *mem = &q->dma_mem; |
| 3327 | |
| 3328 | memset(q, 0, sizeof(*q)); |
| 3329 | q->len = len; |
| 3330 | q->entry_size = entry_size; |
| 3331 | mem->size = len * entry_size; |
Joe Perches | 7c845eb | 2014-08-08 14:24:46 -0700 | [diff] [blame] | 3332 | mem->va = pci_zalloc_consistent(phba->pcidev, mem->size, &mem->dma); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3333 | if (!mem->va) |
Jayamohan Kallickal | d3ad2bb | 2010-07-22 04:16:38 +0530 | [diff] [blame] | 3334 | return -ENOMEM; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3335 | return 0; |
| 3336 | } |
| 3337 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3338 | static int |
| 3339 | beiscsi_create_wrb_rings(struct beiscsi_hba *phba, |
| 3340 | struct hwi_context_memory *phwi_context, |
| 3341 | struct hwi_controller *phwi_ctrlr) |
| 3342 | { |
Jitendra Bhivare | fa1261c | 2016-12-13 15:56:01 +0530 | [diff] [blame] | 3343 | unsigned int num_wrb_rings; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3344 | u64 pa_addr_lo; |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 3345 | unsigned int idx, num, i, ulp_num; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3346 | struct mem_array *pwrb_arr; |
| 3347 | void *wrb_vaddr; |
| 3348 | struct be_dma_mem sgl; |
| 3349 | struct be_mem_descriptor *mem_descr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 3350 | struct hwi_wrb_context *pwrb_context; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3351 | int status; |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 3352 | uint8_t ulp_count = 0, ulp_base_num = 0; |
| 3353 | uint16_t cid_count_ulp[BEISCSI_ULP_COUNT] = { 0 }; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3354 | |
| 3355 | idx = 0; |
| 3356 | mem_descr = phba->init_mem; |
| 3357 | mem_descr += HWI_MEM_WRB; |
| 3358 | pwrb_arr = kmalloc(sizeof(*pwrb_arr) * phba->params.cxns_per_ctrl, |
| 3359 | GFP_KERNEL); |
| 3360 | if (!pwrb_arr) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3361 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3362 | "BM_%d : Memory alloc failed in create wrb ring.\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3363 | return -ENOMEM; |
| 3364 | } |
| 3365 | wrb_vaddr = mem_descr->mem_array[idx].virtual_address; |
| 3366 | pa_addr_lo = mem_descr->mem_array[idx].bus_address.u.a64.address; |
| 3367 | num_wrb_rings = mem_descr->mem_array[idx].size / |
| 3368 | (phba->params.wrbs_per_cxn * sizeof(struct iscsi_wrb)); |
| 3369 | |
| 3370 | for (num = 0; num < phba->params.cxns_per_ctrl; num++) { |
| 3371 | if (num_wrb_rings) { |
| 3372 | pwrb_arr[num].virtual_address = wrb_vaddr; |
| 3373 | pwrb_arr[num].bus_address.u.a64.address = pa_addr_lo; |
| 3374 | pwrb_arr[num].size = phba->params.wrbs_per_cxn * |
| 3375 | sizeof(struct iscsi_wrb); |
| 3376 | wrb_vaddr += pwrb_arr[num].size; |
| 3377 | pa_addr_lo += pwrb_arr[num].size; |
| 3378 | num_wrb_rings--; |
| 3379 | } else { |
| 3380 | idx++; |
| 3381 | wrb_vaddr = mem_descr->mem_array[idx].virtual_address; |
| 3382 | pa_addr_lo = mem_descr->mem_array[idx].\ |
| 3383 | bus_address.u.a64.address; |
| 3384 | num_wrb_rings = mem_descr->mem_array[idx].size / |
| 3385 | (phba->params.wrbs_per_cxn * |
| 3386 | sizeof(struct iscsi_wrb)); |
| 3387 | pwrb_arr[num].virtual_address = wrb_vaddr; |
| 3388 | pwrb_arr[num].bus_address.u.a64.address\ |
| 3389 | = pa_addr_lo; |
| 3390 | pwrb_arr[num].size = phba->params.wrbs_per_cxn * |
| 3391 | sizeof(struct iscsi_wrb); |
| 3392 | wrb_vaddr += pwrb_arr[num].size; |
| 3393 | pa_addr_lo += pwrb_arr[num].size; |
| 3394 | num_wrb_rings--; |
| 3395 | } |
| 3396 | } |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 3397 | |
| 3398 | /* Get the ULP Count */ |
| 3399 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) |
| 3400 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
| 3401 | ulp_count++; |
| 3402 | ulp_base_num = ulp_num; |
| 3403 | cid_count_ulp[ulp_num] = |
| 3404 | BEISCSI_GET_CID_COUNT(phba, ulp_num); |
| 3405 | } |
| 3406 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3407 | for (i = 0; i < phba->params.cxns_per_ctrl; i++) { |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 3408 | if (ulp_count > 1) { |
| 3409 | ulp_base_num = (ulp_base_num + 1) % BEISCSI_ULP_COUNT; |
| 3410 | |
| 3411 | if (!cid_count_ulp[ulp_base_num]) |
| 3412 | ulp_base_num = (ulp_base_num + 1) % |
| 3413 | BEISCSI_ULP_COUNT; |
| 3414 | |
| 3415 | cid_count_ulp[ulp_base_num]--; |
| 3416 | } |
| 3417 | |
| 3418 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3419 | hwi_build_be_sgl_by_offset(phba, &pwrb_arr[i], &sgl); |
| 3420 | status = be_cmd_wrbq_create(&phba->ctrl, &sgl, |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 3421 | &phwi_context->be_wrbq[i], |
| 3422 | &phwi_ctrlr->wrb_context[i], |
| 3423 | ulp_base_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3424 | if (status != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3425 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3426 | "BM_%d : wrbq create failed."); |
Dan Carpenter | 1462b8f | 2010-06-10 09:52:21 +0200 | [diff] [blame] | 3427 | kfree(pwrb_arr); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3428 | return status; |
| 3429 | } |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 3430 | pwrb_context = &phwi_ctrlr->wrb_context[i]; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 3431 | BE_SET_CID_TO_CRI(i, pwrb_context->cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3432 | } |
| 3433 | kfree(pwrb_arr); |
| 3434 | return 0; |
| 3435 | } |
| 3436 | |
| 3437 | static void free_wrb_handles(struct beiscsi_hba *phba) |
| 3438 | { |
| 3439 | unsigned int index; |
| 3440 | struct hwi_controller *phwi_ctrlr; |
| 3441 | struct hwi_wrb_context *pwrb_context; |
| 3442 | |
| 3443 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 3444 | for (index = 0; index < phba->params.cxns_per_ctrl; index++) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3445 | pwrb_context = &phwi_ctrlr->wrb_context[index]; |
| 3446 | kfree(pwrb_context->pwrb_handle_base); |
| 3447 | kfree(pwrb_context->pwrb_handle_basestd); |
| 3448 | } |
| 3449 | } |
| 3450 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3451 | static void be_mcc_queues_destroy(struct beiscsi_hba *phba) |
| 3452 | { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3453 | struct be_ctrl_info *ctrl = &phba->ctrl; |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 3454 | struct be_dma_mem *ptag_mem; |
| 3455 | struct be_queue_info *q; |
| 3456 | int i, tag; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3457 | |
| 3458 | q = &phba->ctrl.mcc_obj.q; |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 3459 | for (i = 0; i < MAX_MCC_CMD; i++) { |
| 3460 | tag = i + 1; |
| 3461 | if (!test_bit(MCC_TAG_STATE_RUNNING, |
| 3462 | &ctrl->ptag_state[tag].tag_state)) |
| 3463 | continue; |
| 3464 | |
| 3465 | if (test_bit(MCC_TAG_STATE_TIMEOUT, |
| 3466 | &ctrl->ptag_state[tag].tag_state)) { |
| 3467 | ptag_mem = &ctrl->ptag_state[tag].tag_mem_state; |
| 3468 | if (ptag_mem->size) { |
| 3469 | pci_free_consistent(ctrl->pdev, |
| 3470 | ptag_mem->size, |
| 3471 | ptag_mem->va, |
| 3472 | ptag_mem->dma); |
| 3473 | ptag_mem->size = 0; |
| 3474 | } |
| 3475 | continue; |
| 3476 | } |
| 3477 | /** |
| 3478 | * If MCC is still active and waiting then wake up the process. |
| 3479 | * We are here only because port is going offline. The process |
| 3480 | * sees that (BEISCSI_HBA_ONLINE is cleared) and EIO error is |
| 3481 | * returned for the operation and allocated memory cleaned up. |
| 3482 | */ |
| 3483 | if (waitqueue_active(&ctrl->mcc_wait[tag])) { |
| 3484 | ctrl->mcc_tag_status[tag] = MCC_STATUS_FAILED; |
| 3485 | ctrl->mcc_tag_status[tag] |= CQE_VALID_MASK; |
| 3486 | wake_up_interruptible(&ctrl->mcc_wait[tag]); |
| 3487 | /* |
| 3488 | * Control tag info gets reinitialized in enable |
| 3489 | * so wait for the process to clear running state. |
| 3490 | */ |
| 3491 | while (test_bit(MCC_TAG_STATE_RUNNING, |
| 3492 | &ctrl->ptag_state[tag].tag_state)) |
| 3493 | schedule_timeout_uninterruptible(HZ); |
| 3494 | } |
| 3495 | /** |
| 3496 | * For MCC with tag_states MCC_TAG_STATE_ASYNC and |
| 3497 | * MCC_TAG_STATE_IGNORE nothing needs to done. |
| 3498 | */ |
| 3499 | } |
John Soni Jose | 4e2bdf7 | 2015-04-25 08:17:31 +0530 | [diff] [blame] | 3500 | if (q->created) { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3501 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_MCCQ); |
John Soni Jose | 4e2bdf7 | 2015-04-25 08:17:31 +0530 | [diff] [blame] | 3502 | be_queue_free(phba, q); |
| 3503 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3504 | |
| 3505 | q = &phba->ctrl.mcc_obj.cq; |
John Soni Jose | 4e2bdf7 | 2015-04-25 08:17:31 +0530 | [diff] [blame] | 3506 | if (q->created) { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3507 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ); |
John Soni Jose | 4e2bdf7 | 2015-04-25 08:17:31 +0530 | [diff] [blame] | 3508 | be_queue_free(phba, q); |
| 3509 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3510 | } |
| 3511 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3512 | static int be_mcc_queues_create(struct beiscsi_hba *phba, |
| 3513 | struct hwi_context_memory *phwi_context) |
| 3514 | { |
| 3515 | struct be_queue_info *q, *cq; |
| 3516 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 3517 | |
| 3518 | /* Alloc MCC compl queue */ |
| 3519 | cq = &phba->ctrl.mcc_obj.cq; |
| 3520 | if (be_queue_alloc(phba, cq, MCC_CQ_LEN, |
| 3521 | sizeof(struct be_mcc_compl))) |
| 3522 | goto err; |
| 3523 | /* Ask BE to create MCC compl queue; */ |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 3524 | if (phba->pcidev->msix_enabled) { |
Jitendra Bhivare | 45efc940 | 2017-10-10 16:18:18 +0530 | [diff] [blame] | 3525 | if (beiscsi_cmd_cq_create(ctrl, cq, |
| 3526 | &phwi_context->be_eq[phba->num_cpus].q, |
| 3527 | false, true, 0)) |
| 3528 | goto mcc_cq_free; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3529 | } else { |
| 3530 | if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq[0].q, |
| 3531 | false, true, 0)) |
Jitendra Bhivare | 45efc940 | 2017-10-10 16:18:18 +0530 | [diff] [blame] | 3532 | goto mcc_cq_free; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3533 | } |
| 3534 | |
| 3535 | /* Alloc MCC queue */ |
| 3536 | q = &phba->ctrl.mcc_obj.q; |
| 3537 | if (be_queue_alloc(phba, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb))) |
| 3538 | goto mcc_cq_destroy; |
| 3539 | |
| 3540 | /* Ask BE to create MCC queue */ |
Jayamohan Kallickal | 35e6601 | 2009-10-23 11:53:49 +0530 | [diff] [blame] | 3541 | if (beiscsi_cmd_mccq_create(phba, q, cq)) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3542 | goto mcc_q_free; |
| 3543 | |
| 3544 | return 0; |
| 3545 | |
| 3546 | mcc_q_free: |
| 3547 | be_queue_free(phba, q); |
| 3548 | mcc_cq_destroy: |
| 3549 | beiscsi_cmd_q_destroy(ctrl, cq, QTYPE_CQ); |
| 3550 | mcc_cq_free: |
| 3551 | be_queue_free(phba, cq); |
| 3552 | err: |
Jayamohan Kallickal | d3ad2bb | 2010-07-22 04:16:38 +0530 | [diff] [blame] | 3553 | return -ENOMEM; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3554 | } |
| 3555 | |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 3556 | static void be2iscsi_enable_msix(struct beiscsi_hba *phba) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3557 | { |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 3558 | int nvec = 1; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3559 | |
John Soni Jose | 22abeef | 2012-10-20 04:43:32 +0530 | [diff] [blame] | 3560 | switch (phba->generation) { |
| 3561 | case BE_GEN2: |
| 3562 | case BE_GEN3: |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 3563 | nvec = BEISCSI_MAX_NUM_CPUS + 1; |
John Soni Jose | 22abeef | 2012-10-20 04:43:32 +0530 | [diff] [blame] | 3564 | break; |
| 3565 | case BE_GEN4: |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 3566 | nvec = phba->fw_config.eqid_count; |
John Soni Jose | 22abeef | 2012-10-20 04:43:32 +0530 | [diff] [blame] | 3567 | break; |
| 3568 | default: |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 3569 | nvec = 2; |
| 3570 | break; |
John Soni Jose | 22abeef | 2012-10-20 04:43:32 +0530 | [diff] [blame] | 3571 | } |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 3572 | |
| 3573 | /* if eqid_count == 1 fall back to INTX */ |
| 3574 | if (enable_msix && nvec > 1) { |
| 3575 | const struct irq_affinity desc = { .post_vectors = 1 }; |
| 3576 | |
| 3577 | if (pci_alloc_irq_vectors_affinity(phba->pcidev, 2, nvec, |
| 3578 | PCI_IRQ_MSIX | PCI_IRQ_AFFINITY, &desc) < 0) { |
| 3579 | phba->num_cpus = nvec - 1; |
| 3580 | return; |
| 3581 | } |
| 3582 | } |
| 3583 | |
| 3584 | phba->num_cpus = 1; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3585 | } |
| 3586 | |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 3587 | static void hwi_purge_eq(struct beiscsi_hba *phba) |
| 3588 | { |
| 3589 | struct hwi_controller *phwi_ctrlr; |
| 3590 | struct hwi_context_memory *phwi_context; |
| 3591 | struct be_queue_info *eq; |
| 3592 | struct be_eq_entry *eqe = NULL; |
| 3593 | int i, eq_msix; |
| 3594 | unsigned int num_processed; |
| 3595 | |
| 3596 | if (beiscsi_hba_in_error(phba)) |
| 3597 | return; |
| 3598 | |
| 3599 | phwi_ctrlr = phba->phwi_ctrlr; |
| 3600 | phwi_context = phwi_ctrlr->phwi_ctxt; |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 3601 | if (phba->pcidev->msix_enabled) |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 3602 | eq_msix = 1; |
| 3603 | else |
| 3604 | eq_msix = 0; |
| 3605 | |
| 3606 | for (i = 0; i < (phba->num_cpus + eq_msix); i++) { |
| 3607 | eq = &phwi_context->be_eq[i].q; |
| 3608 | eqe = queue_tail_node(eq); |
| 3609 | num_processed = 0; |
| 3610 | while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32] |
| 3611 | & EQE_VALID_MASK) { |
| 3612 | AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0); |
| 3613 | queue_tail_inc(eq); |
| 3614 | eqe = queue_tail_node(eq); |
| 3615 | num_processed++; |
| 3616 | } |
| 3617 | |
| 3618 | if (num_processed) |
| 3619 | hwi_ring_eq_db(phba, eq->id, 1, num_processed, 1, 1); |
| 3620 | } |
| 3621 | } |
| 3622 | |
| 3623 | static void hwi_cleanup_port(struct beiscsi_hba *phba) |
| 3624 | { |
| 3625 | struct be_queue_info *q; |
| 3626 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 3627 | struct hwi_controller *phwi_ctrlr; |
| 3628 | struct hwi_context_memory *phwi_context; |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 3629 | int i, eq_for_mcc, ulp_num; |
| 3630 | |
| 3631 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) |
| 3632 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) |
| 3633 | beiscsi_cmd_iscsi_cleanup(phba, ulp_num); |
| 3634 | |
| 3635 | /** |
| 3636 | * Purge all EQ entries that may have been left out. This is to |
| 3637 | * workaround a problem we've seen occasionally where driver gets an |
| 3638 | * interrupt with EQ entry bit set after stopping the controller. |
| 3639 | */ |
| 3640 | hwi_purge_eq(phba); |
| 3641 | |
| 3642 | phwi_ctrlr = phba->phwi_ctrlr; |
| 3643 | phwi_context = phwi_ctrlr->phwi_ctxt; |
| 3644 | |
| 3645 | be_cmd_iscsi_remove_template_hdr(ctrl); |
| 3646 | |
| 3647 | for (i = 0; i < phba->params.cxns_per_ctrl; i++) { |
| 3648 | q = &phwi_context->be_wrbq[i]; |
| 3649 | if (q->created) |
| 3650 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_WRBQ); |
| 3651 | } |
| 3652 | kfree(phwi_context->be_wrbq); |
| 3653 | free_wrb_handles(phba); |
| 3654 | |
| 3655 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 3656 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
| 3657 | |
| 3658 | q = &phwi_context->be_def_hdrq[ulp_num]; |
| 3659 | if (q->created) |
| 3660 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ); |
| 3661 | |
| 3662 | q = &phwi_context->be_def_dataq[ulp_num]; |
| 3663 | if (q->created) |
| 3664 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 3665 | } |
| 3666 | } |
| 3667 | |
| 3668 | beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL); |
| 3669 | |
| 3670 | for (i = 0; i < (phba->num_cpus); i++) { |
| 3671 | q = &phwi_context->be_cq[i]; |
| 3672 | if (q->created) { |
| 3673 | be_queue_free(phba, q); |
| 3674 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ); |
| 3675 | } |
| 3676 | } |
| 3677 | |
| 3678 | be_mcc_queues_destroy(phba); |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 3679 | if (phba->pcidev->msix_enabled) |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 3680 | eq_for_mcc = 1; |
| 3681 | else |
| 3682 | eq_for_mcc = 0; |
| 3683 | for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) { |
| 3684 | q = &phwi_context->be_eq[i].q; |
| 3685 | if (q->created) { |
| 3686 | be_queue_free(phba, q); |
| 3687 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_EQ); |
| 3688 | } |
| 3689 | } |
Jitendra Bhivare | 4ee1ec4 | 2016-08-19 15:20:20 +0530 | [diff] [blame] | 3690 | /* this ensures complete FW cleanup */ |
| 3691 | beiscsi_cmd_function_reset(phba); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 3692 | /* last communication, indicate driver is unloading */ |
| 3693 | beiscsi_cmd_special_wrb(&phba->ctrl, 0); |
| 3694 | } |
Jitendra Bhivare | 4ee1ec4 | 2016-08-19 15:20:20 +0530 | [diff] [blame] | 3695 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3696 | static int hwi_init_port(struct beiscsi_hba *phba) |
| 3697 | { |
| 3698 | struct hwi_controller *phwi_ctrlr; |
| 3699 | struct hwi_context_memory *phwi_context; |
| 3700 | unsigned int def_pdu_ring_sz; |
| 3701 | struct be_ctrl_info *ctrl = &phba->ctrl; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3702 | int status, ulp_num; |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 3703 | u16 nbufs; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3704 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3705 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3706 | phwi_context = phwi_ctrlr->phwi_ctxt; |
Jitendra Bhivare | 4d2ee1e | 2016-08-19 15:20:16 +0530 | [diff] [blame] | 3707 | /* set port optic state to unknown */ |
Jitendra Bhivare | 53aefe2 | 2016-01-20 14:10:53 +0530 | [diff] [blame] | 3708 | phba->optic_state = 0xff; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3709 | |
| 3710 | status = beiscsi_create_eqs(phba, phwi_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3711 | if (status != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3712 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3713 | "BM_%d : EQ not created\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3714 | goto error; |
| 3715 | } |
| 3716 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3717 | status = be_mcc_queues_create(phba, phwi_context); |
| 3718 | if (status != 0) |
| 3719 | goto error; |
| 3720 | |
Jitendra Bhivare | 480195c | 2016-08-19 15:20:15 +0530 | [diff] [blame] | 3721 | status = beiscsi_check_supported_fw(ctrl, phba); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3722 | if (status != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3723 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3724 | "BM_%d : Unsupported fw version\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3725 | goto error; |
| 3726 | } |
| 3727 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3728 | status = beiscsi_create_cqs(phba, phwi_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3729 | if (status != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3730 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3731 | "BM_%d : CQ not created\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3732 | goto error; |
| 3733 | } |
| 3734 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3735 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 3736 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 3737 | nbufs = phwi_context->pasync_ctx[ulp_num]->num_entries; |
| 3738 | def_pdu_ring_sz = nbufs * sizeof(struct phys_addr); |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3739 | |
| 3740 | status = beiscsi_create_def_hdr(phba, phwi_context, |
| 3741 | phwi_ctrlr, |
| 3742 | def_pdu_ring_sz, |
| 3743 | ulp_num); |
| 3744 | if (status != 0) { |
| 3745 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3746 | "BM_%d : Default Header not created for ULP : %d\n", |
| 3747 | ulp_num); |
| 3748 | goto error; |
| 3749 | } |
| 3750 | |
| 3751 | status = beiscsi_create_def_data(phba, phwi_context, |
| 3752 | phwi_ctrlr, |
| 3753 | def_pdu_ring_sz, |
| 3754 | ulp_num); |
| 3755 | if (status != 0) { |
| 3756 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3757 | "BM_%d : Default Data not created for ULP : %d\n", |
| 3758 | ulp_num); |
| 3759 | goto error; |
| 3760 | } |
Jitendra Bhivare | f79929d | 2016-08-19 15:20:17 +0530 | [diff] [blame] | 3761 | /** |
| 3762 | * Now that the default PDU rings have been created, |
| 3763 | * let EP know about it. |
Jitendra Bhivare | f79929d | 2016-08-19 15:20:17 +0530 | [diff] [blame] | 3764 | */ |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 3765 | beiscsi_hdq_post_handles(phba, BEISCSI_DEFQ_HDR, |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 3766 | ulp_num, nbufs); |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 3767 | beiscsi_hdq_post_handles(phba, BEISCSI_DEFQ_DATA, |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 3768 | ulp_num, nbufs); |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3769 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3770 | } |
| 3771 | |
| 3772 | status = beiscsi_post_pages(phba); |
| 3773 | if (status != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3774 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3775 | "BM_%d : Post SGL Pages Failed\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3776 | goto error; |
| 3777 | } |
| 3778 | |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3779 | status = beiscsi_post_template_hdr(phba); |
| 3780 | if (status != 0) { |
| 3781 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3782 | "BM_%d : Template HDR Posting for CXN Failed\n"); |
| 3783 | } |
| 3784 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3785 | status = beiscsi_create_wrb_rings(phba, phwi_context, phwi_ctrlr); |
| 3786 | if (status != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3787 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3788 | "BM_%d : WRB Rings not created\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3789 | goto error; |
| 3790 | } |
| 3791 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3792 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 3793 | uint16_t async_arr_idx = 0; |
| 3794 | |
| 3795 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
| 3796 | uint16_t cri = 0; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 3797 | struct hd_async_context *pasync_ctx; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3798 | |
| 3799 | pasync_ctx = HWI_GET_ASYNC_PDU_CTX( |
| 3800 | phwi_ctrlr, ulp_num); |
| 3801 | for (cri = 0; cri < |
| 3802 | phba->params.cxns_per_ctrl; cri++) { |
| 3803 | if (ulp_num == BEISCSI_GET_ULP_FROM_CRI |
| 3804 | (phwi_ctrlr, cri)) |
| 3805 | pasync_ctx->cid_to_async_cri_map[ |
| 3806 | phwi_ctrlr->wrb_context[cri].cid] = |
| 3807 | async_arr_idx++; |
| 3808 | } |
| 3809 | } |
| 3810 | } |
| 3811 | |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3812 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3813 | "BM_%d : hwi_init_port success\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3814 | return 0; |
| 3815 | |
| 3816 | error: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3817 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3818 | "BM_%d : hwi_init_port failed"); |
Jitendra Bhivare | 4d2ee1e | 2016-08-19 15:20:16 +0530 | [diff] [blame] | 3819 | hwi_cleanup_port(phba); |
Jayamohan Kallickal | a49e06d | 2012-04-03 23:41:44 -0500 | [diff] [blame] | 3820 | return status; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3821 | } |
| 3822 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3823 | static int hwi_init_controller(struct beiscsi_hba *phba) |
| 3824 | { |
| 3825 | struct hwi_controller *phwi_ctrlr; |
| 3826 | |
| 3827 | phwi_ctrlr = phba->phwi_ctrlr; |
| 3828 | if (1 == phba->init_mem[HWI_MEM_ADDN_CONTEXT].num_elements) { |
| 3829 | phwi_ctrlr->phwi_ctxt = (struct hwi_context_memory *)phba-> |
| 3830 | init_mem[HWI_MEM_ADDN_CONTEXT].mem_array[0].virtual_address; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3831 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3832 | "BM_%d : phwi_ctrlr->phwi_ctxt=%p\n", |
| 3833 | phwi_ctrlr->phwi_ctxt); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3834 | } else { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3835 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3836 | "BM_%d : HWI_MEM_ADDN_CONTEXT is more " |
| 3837 | "than one element.Failing to load\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3838 | return -ENOMEM; |
| 3839 | } |
| 3840 | |
| 3841 | iscsi_init_global_templates(phba); |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 3842 | if (beiscsi_init_wrb_handle(phba)) |
| 3843 | return -ENOMEM; |
| 3844 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 3845 | if (hwi_init_async_pdu_ctx(phba)) { |
| 3846 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3847 | "BM_%d : hwi_init_async_pdu_ctx failed\n"); |
| 3848 | return -ENOMEM; |
| 3849 | } |
| 3850 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3851 | if (hwi_init_port(phba) != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3852 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3853 | "BM_%d : hwi_init_controller failed\n"); |
| 3854 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3855 | return -ENOMEM; |
| 3856 | } |
| 3857 | return 0; |
| 3858 | } |
| 3859 | |
| 3860 | static void beiscsi_free_mem(struct beiscsi_hba *phba) |
| 3861 | { |
| 3862 | struct be_mem_descriptor *mem_descr; |
| 3863 | int i, j; |
| 3864 | |
| 3865 | mem_descr = phba->init_mem; |
| 3866 | i = 0; |
| 3867 | j = 0; |
| 3868 | for (i = 0; i < SE_MEM_MAX; i++) { |
| 3869 | for (j = mem_descr->num_elements; j > 0; j--) { |
| 3870 | pci_free_consistent(phba->pcidev, |
| 3871 | mem_descr->mem_array[j - 1].size, |
| 3872 | mem_descr->mem_array[j - 1].virtual_address, |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 3873 | (unsigned long)mem_descr->mem_array[j - 1]. |
| 3874 | bus_address.u.a64.address); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3875 | } |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3876 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3877 | kfree(mem_descr->mem_array); |
| 3878 | mem_descr++; |
| 3879 | } |
| 3880 | kfree(phba->init_mem); |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 3881 | kfree(phba->phwi_ctrlr->wrb_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3882 | kfree(phba->phwi_ctrlr); |
| 3883 | } |
| 3884 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3885 | static int beiscsi_init_sgl_handle(struct beiscsi_hba *phba) |
| 3886 | { |
| 3887 | struct be_mem_descriptor *mem_descr_sglh, *mem_descr_sg; |
| 3888 | struct sgl_handle *psgl_handle; |
| 3889 | struct iscsi_sge *pfrag; |
Jayamohan Kallickal | 90622db | 2013-09-28 15:35:47 -0700 | [diff] [blame] | 3890 | unsigned int arr_index, i, idx; |
| 3891 | unsigned int ulp_icd_start, ulp_num = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3892 | |
| 3893 | phba->io_sgl_hndl_avbl = 0; |
| 3894 | phba->eh_sgl_hndl_avbl = 0; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3895 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3896 | mem_descr_sglh = phba->init_mem; |
| 3897 | mem_descr_sglh += HWI_MEM_SGLH; |
| 3898 | if (1 == mem_descr_sglh->num_elements) { |
| 3899 | phba->io_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) * |
| 3900 | phba->params.ios_per_ctrl, |
| 3901 | GFP_KERNEL); |
| 3902 | if (!phba->io_sgl_hndl_base) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3903 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3904 | "BM_%d : Mem Alloc Failed. Failing to load\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3905 | return -ENOMEM; |
| 3906 | } |
| 3907 | phba->eh_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) * |
| 3908 | (phba->params.icds_per_ctrl - |
| 3909 | phba->params.ios_per_ctrl), |
| 3910 | GFP_KERNEL); |
| 3911 | if (!phba->eh_sgl_hndl_base) { |
| 3912 | kfree(phba->io_sgl_hndl_base); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3913 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3914 | "BM_%d : Mem Alloc Failed. Failing to load\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3915 | return -ENOMEM; |
| 3916 | } |
| 3917 | } else { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3918 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3919 | "BM_%d : HWI_MEM_SGLH is more than one element." |
| 3920 | "Failing to load\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3921 | return -ENOMEM; |
| 3922 | } |
| 3923 | |
| 3924 | arr_index = 0; |
| 3925 | idx = 0; |
| 3926 | while (idx < mem_descr_sglh->num_elements) { |
| 3927 | psgl_handle = mem_descr_sglh->mem_array[idx].virtual_address; |
| 3928 | |
| 3929 | for (i = 0; i < (mem_descr_sglh->mem_array[idx].size / |
| 3930 | sizeof(struct sgl_handle)); i++) { |
| 3931 | if (arr_index < phba->params.ios_per_ctrl) { |
| 3932 | phba->io_sgl_hndl_base[arr_index] = psgl_handle; |
| 3933 | phba->io_sgl_hndl_avbl++; |
| 3934 | arr_index++; |
| 3935 | } else { |
| 3936 | phba->eh_sgl_hndl_base[arr_index - |
| 3937 | phba->params.ios_per_ctrl] = |
| 3938 | psgl_handle; |
| 3939 | arr_index++; |
| 3940 | phba->eh_sgl_hndl_avbl++; |
| 3941 | } |
| 3942 | psgl_handle++; |
| 3943 | } |
| 3944 | idx++; |
| 3945 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3946 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3947 | "BM_%d : phba->io_sgl_hndl_avbl=%d" |
| 3948 | "phba->eh_sgl_hndl_avbl=%d\n", |
| 3949 | phba->io_sgl_hndl_avbl, |
| 3950 | phba->eh_sgl_hndl_avbl); |
| 3951 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3952 | mem_descr_sg = phba->init_mem; |
| 3953 | mem_descr_sg += HWI_MEM_SGE; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3954 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3955 | "\n BM_%d : mem_descr_sg->num_elements=%d\n", |
| 3956 | mem_descr_sg->num_elements); |
| 3957 | |
Jayamohan Kallickal | 90622db | 2013-09-28 15:35:47 -0700 | [diff] [blame] | 3958 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) |
| 3959 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) |
| 3960 | break; |
| 3961 | |
| 3962 | ulp_icd_start = phba->fw_config.iscsi_icd_start[ulp_num]; |
| 3963 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3964 | arr_index = 0; |
| 3965 | idx = 0; |
| 3966 | while (idx < mem_descr_sg->num_elements) { |
| 3967 | pfrag = mem_descr_sg->mem_array[idx].virtual_address; |
| 3968 | |
| 3969 | for (i = 0; |
| 3970 | i < (mem_descr_sg->mem_array[idx].size) / |
| 3971 | (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io); |
| 3972 | i++) { |
| 3973 | if (arr_index < phba->params.ios_per_ctrl) |
| 3974 | psgl_handle = phba->io_sgl_hndl_base[arr_index]; |
| 3975 | else |
| 3976 | psgl_handle = phba->eh_sgl_hndl_base[arr_index - |
| 3977 | phba->params.ios_per_ctrl]; |
| 3978 | psgl_handle->pfrag = pfrag; |
| 3979 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, pfrag, 0); |
| 3980 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, pfrag, 0); |
| 3981 | pfrag += phba->params.num_sge_per_io; |
Jayamohan Kallickal | 90622db | 2013-09-28 15:35:47 -0700 | [diff] [blame] | 3982 | psgl_handle->sgl_index = ulp_icd_start + arr_index++; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3983 | } |
| 3984 | idx++; |
| 3985 | } |
| 3986 | phba->io_sgl_free_index = 0; |
| 3987 | phba->io_sgl_alloc_index = 0; |
| 3988 | phba->eh_sgl_free_index = 0; |
| 3989 | phba->eh_sgl_alloc_index = 0; |
| 3990 | return 0; |
| 3991 | } |
| 3992 | |
| 3993 | static int hba_setup_cid_tbls(struct beiscsi_hba *phba) |
| 3994 | { |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 3995 | int ret; |
| 3996 | uint16_t i, ulp_num; |
| 3997 | struct ulp_cid_info *ptr_cid_info = NULL; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3998 | |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 3999 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 4000 | if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) { |
| 4001 | ptr_cid_info = kzalloc(sizeof(struct ulp_cid_info), |
| 4002 | GFP_KERNEL); |
| 4003 | |
| 4004 | if (!ptr_cid_info) { |
| 4005 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4006 | "BM_%d : Failed to allocate memory" |
| 4007 | "for ULP_CID_INFO for ULP : %d\n", |
| 4008 | ulp_num); |
| 4009 | ret = -ENOMEM; |
| 4010 | goto free_memory; |
| 4011 | |
| 4012 | } |
| 4013 | |
| 4014 | /* Allocate memory for CID array */ |
Jitendra Bhivare | 413f365 | 2016-12-13 15:56:03 +0530 | [diff] [blame] | 4015 | ptr_cid_info->cid_array = |
| 4016 | kcalloc(BEISCSI_GET_CID_COUNT(phba, ulp_num), |
| 4017 | sizeof(*ptr_cid_info->cid_array), |
| 4018 | GFP_KERNEL); |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4019 | if (!ptr_cid_info->cid_array) { |
| 4020 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4021 | "BM_%d : Failed to allocate memory" |
| 4022 | "for CID_ARRAY for ULP : %d\n", |
| 4023 | ulp_num); |
| 4024 | kfree(ptr_cid_info); |
| 4025 | ptr_cid_info = NULL; |
| 4026 | ret = -ENOMEM; |
| 4027 | |
| 4028 | goto free_memory; |
| 4029 | } |
| 4030 | ptr_cid_info->avlbl_cids = BEISCSI_GET_CID_COUNT( |
| 4031 | phba, ulp_num); |
| 4032 | |
| 4033 | /* Save the cid_info_array ptr */ |
| 4034 | phba->cid_array_info[ulp_num] = ptr_cid_info; |
| 4035 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4036 | } |
Jayamohan Kallickal | c246228 | 2010-01-05 05:05:34 +0530 | [diff] [blame] | 4037 | phba->ep_array = kzalloc(sizeof(struct iscsi_endpoint *) * |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4038 | phba->params.cxns_per_ctrl, GFP_KERNEL); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4039 | if (!phba->ep_array) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4040 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4041 | "BM_%d : Failed to allocate memory in " |
| 4042 | "hba_setup_cid_tbls\n"); |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4043 | ret = -ENOMEM; |
| 4044 | |
| 4045 | goto free_memory; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4046 | } |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4047 | |
| 4048 | phba->conn_table = kzalloc(sizeof(struct beiscsi_conn *) * |
| 4049 | phba->params.cxns_per_ctrl, GFP_KERNEL); |
| 4050 | if (!phba->conn_table) { |
| 4051 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4052 | "BM_%d : Failed to allocate memory in" |
| 4053 | "hba_setup_cid_tbls\n"); |
| 4054 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4055 | kfree(phba->ep_array); |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4056 | phba->ep_array = NULL; |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4057 | ret = -ENOMEM; |
Tomas Henzl | 5f2d25e | 2014-06-06 14:06:30 +0200 | [diff] [blame] | 4058 | |
| 4059 | goto free_memory; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4060 | } |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4061 | |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4062 | for (i = 0; i < phba->params.cxns_per_ctrl; i++) { |
| 4063 | ulp_num = phba->phwi_ctrlr->wrb_context[i].ulp_num; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4064 | |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4065 | ptr_cid_info = phba->cid_array_info[ulp_num]; |
| 4066 | ptr_cid_info->cid_array[ptr_cid_info->cid_alloc++] = |
| 4067 | phba->phwi_ctrlr->wrb_context[i].cid; |
| 4068 | |
| 4069 | } |
| 4070 | |
| 4071 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 4072 | if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) { |
| 4073 | ptr_cid_info = phba->cid_array_info[ulp_num]; |
| 4074 | |
| 4075 | ptr_cid_info->cid_alloc = 0; |
| 4076 | ptr_cid_info->cid_free = 0; |
| 4077 | } |
| 4078 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4079 | return 0; |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4080 | |
| 4081 | free_memory: |
| 4082 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 4083 | if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) { |
| 4084 | ptr_cid_info = phba->cid_array_info[ulp_num]; |
| 4085 | |
| 4086 | if (ptr_cid_info) { |
| 4087 | kfree(ptr_cid_info->cid_array); |
| 4088 | kfree(ptr_cid_info); |
| 4089 | phba->cid_array_info[ulp_num] = NULL; |
| 4090 | } |
| 4091 | } |
| 4092 | } |
| 4093 | |
| 4094 | return ret; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4095 | } |
| 4096 | |
Jayamohan Kallickal | 238f6b7 | 2010-07-22 04:23:22 +0530 | [diff] [blame] | 4097 | static void hwi_enable_intr(struct beiscsi_hba *phba) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4098 | { |
| 4099 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 4100 | struct hwi_controller *phwi_ctrlr; |
| 4101 | struct hwi_context_memory *phwi_context; |
| 4102 | struct be_queue_info *eq; |
| 4103 | u8 __iomem *addr; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4104 | u32 reg, i; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4105 | u32 enabled; |
| 4106 | |
| 4107 | phwi_ctrlr = phba->phwi_ctrlr; |
| 4108 | phwi_context = phwi_ctrlr->phwi_ctxt; |
| 4109 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4110 | addr = (u8 __iomem *) ((u8 __iomem *) ctrl->pcicfg + |
| 4111 | PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET); |
| 4112 | reg = ioread32(addr); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4113 | |
| 4114 | enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
| 4115 | if (!enabled) { |
| 4116 | reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4117 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 4118 | "BM_%d : reg =x%08x addr=%p\n", reg, addr); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4119 | iowrite32(reg, addr); |
Jayamohan Kallickal | 665d6d9 | 2011-04-29 14:30:06 -0500 | [diff] [blame] | 4120 | } |
| 4121 | |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 4122 | if (!phba->pcidev->msix_enabled) { |
Jayamohan Kallickal | 665d6d9 | 2011-04-29 14:30:06 -0500 | [diff] [blame] | 4123 | eq = &phwi_context->be_eq[0].q; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4124 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 4125 | "BM_%d : eq->id=%d\n", eq->id); |
| 4126 | |
Jayamohan Kallickal | 665d6d9 | 2011-04-29 14:30:06 -0500 | [diff] [blame] | 4127 | hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1); |
| 4128 | } else { |
| 4129 | for (i = 0; i <= phba->num_cpus; i++) { |
| 4130 | eq = &phwi_context->be_eq[i].q; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4131 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 4132 | "BM_%d : eq->id=%d\n", eq->id); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4133 | hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1); |
| 4134 | } |
Jayamohan Kallickal | c03af1a | 2010-02-20 08:05:43 +0530 | [diff] [blame] | 4135 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4136 | } |
| 4137 | |
| 4138 | static void hwi_disable_intr(struct beiscsi_hba *phba) |
| 4139 | { |
| 4140 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 4141 | |
| 4142 | u8 __iomem *addr = ctrl->pcicfg + PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET; |
| 4143 | u32 reg = ioread32(addr); |
| 4144 | |
| 4145 | u32 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
| 4146 | if (enabled) { |
| 4147 | reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
| 4148 | iowrite32(reg, addr); |
| 4149 | } else |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4150 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT, |
| 4151 | "BM_%d : In hwi_disable_intr, Already Disabled\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4152 | } |
| 4153 | |
| 4154 | static int beiscsi_init_port(struct beiscsi_hba *phba) |
| 4155 | { |
| 4156 | int ret; |
| 4157 | |
Jitendra Bhivare | dd94097 | 2016-12-13 15:56:04 +0530 | [diff] [blame] | 4158 | ret = hwi_init_controller(phba); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4159 | if (ret < 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4160 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
Jitendra Bhivare | dd94097 | 2016-12-13 15:56:04 +0530 | [diff] [blame] | 4161 | "BM_%d : init controller failed\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4162 | return ret; |
| 4163 | } |
| 4164 | ret = beiscsi_init_sgl_handle(phba); |
| 4165 | if (ret < 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4166 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
Jitendra Bhivare | dd94097 | 2016-12-13 15:56:04 +0530 | [diff] [blame] | 4167 | "BM_%d : init sgl handles failed\n"); |
| 4168 | goto cleanup_port; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4169 | } |
| 4170 | |
Christophe JAILLET | deeea8e | 2016-08-26 15:09:06 +0530 | [diff] [blame] | 4171 | ret = hba_setup_cid_tbls(phba); |
| 4172 | if (ret < 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4173 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
Jitendra Bhivare | dd94097 | 2016-12-13 15:56:04 +0530 | [diff] [blame] | 4174 | "BM_%d : setup CID table failed\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4175 | kfree(phba->io_sgl_hndl_base); |
| 4176 | kfree(phba->eh_sgl_hndl_base); |
Jitendra Bhivare | dd94097 | 2016-12-13 15:56:04 +0530 | [diff] [blame] | 4177 | goto cleanup_port; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4178 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4179 | return ret; |
| 4180 | |
Jitendra Bhivare | dd94097 | 2016-12-13 15:56:04 +0530 | [diff] [blame] | 4181 | cleanup_port: |
Jitendra Bhivare | 4d2ee1e | 2016-08-19 15:20:16 +0530 | [diff] [blame] | 4182 | hwi_cleanup_port(phba); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4183 | return ret; |
| 4184 | } |
| 4185 | |
Jitendra Bhivare | 4d2ee1e | 2016-08-19 15:20:16 +0530 | [diff] [blame] | 4186 | static void beiscsi_cleanup_port(struct beiscsi_hba *phba) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4187 | { |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4188 | struct ulp_cid_info *ptr_cid_info = NULL; |
Jitendra Bhivare | f79929d | 2016-08-19 15:20:17 +0530 | [diff] [blame] | 4189 | int ulp_num; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4190 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4191 | kfree(phba->io_sgl_hndl_base); |
| 4192 | kfree(phba->eh_sgl_hndl_base); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4193 | kfree(phba->ep_array); |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4194 | kfree(phba->conn_table); |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4195 | |
| 4196 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 4197 | if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) { |
| 4198 | ptr_cid_info = phba->cid_array_info[ulp_num]; |
| 4199 | |
| 4200 | if (ptr_cid_info) { |
| 4201 | kfree(ptr_cid_info->cid_array); |
| 4202 | kfree(ptr_cid_info); |
| 4203 | phba->cid_array_info[ulp_num] = NULL; |
| 4204 | } |
| 4205 | } |
| 4206 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4207 | } |
| 4208 | |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 4209 | /** |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4210 | * beiscsi_free_mgmt_task_handles()- Free driver CXN resources |
| 4211 | * @beiscsi_conn: ptr to the conn to be cleaned up |
Jayamohan Kallickal | 4a4a11b | 2013-04-05 20:38:31 -0700 | [diff] [blame] | 4212 | * @task: ptr to iscsi_task resource to be freed. |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4213 | * |
| 4214 | * Free driver mgmt resources binded to CXN. |
| 4215 | **/ |
| 4216 | void |
Jayamohan Kallickal | 4a4a11b | 2013-04-05 20:38:31 -0700 | [diff] [blame] | 4217 | beiscsi_free_mgmt_task_handles(struct beiscsi_conn *beiscsi_conn, |
| 4218 | struct iscsi_task *task) |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4219 | { |
| 4220 | struct beiscsi_io_task *io_task; |
| 4221 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 4222 | struct hwi_wrb_context *pwrb_context; |
| 4223 | struct hwi_controller *phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4224 | uint16_t cri_index = BE_GET_CRI_FROM_CID( |
| 4225 | beiscsi_conn->beiscsi_conn_cid); |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4226 | |
| 4227 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4228 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
| 4229 | |
Jayamohan Kallickal | 4a4a11b | 2013-04-05 20:38:31 -0700 | [diff] [blame] | 4230 | io_task = task->dd_data; |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4231 | |
| 4232 | if (io_task->pwrb_handle) { |
Jitendra Bhivare | e1f9d31 | 2016-08-19 15:20:22 +0530 | [diff] [blame] | 4233 | free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle); |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4234 | io_task->pwrb_handle = NULL; |
| 4235 | } |
| 4236 | |
| 4237 | if (io_task->psgl_handle) { |
Jitendra Bhivare | e1f9d31 | 2016-08-19 15:20:22 +0530 | [diff] [blame] | 4238 | free_mgmt_sgl_handle(phba, io_task->psgl_handle); |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4239 | io_task->psgl_handle = NULL; |
| 4240 | } |
| 4241 | |
John Soni Jose | eb1c469 | 2015-04-25 08:17:45 +0530 | [diff] [blame] | 4242 | if (io_task->mtask_addr) { |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4243 | pci_unmap_single(phba->pcidev, |
| 4244 | io_task->mtask_addr, |
| 4245 | io_task->mtask_data_count, |
| 4246 | PCI_DMA_TODEVICE); |
John Soni Jose | eb1c469 | 2015-04-25 08:17:45 +0530 | [diff] [blame] | 4247 | io_task->mtask_addr = 0; |
| 4248 | } |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4249 | } |
| 4250 | |
| 4251 | /** |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 4252 | * beiscsi_cleanup_task()- Free driver resources of the task |
| 4253 | * @task: ptr to the iscsi task |
| 4254 | * |
| 4255 | **/ |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4256 | static void beiscsi_cleanup_task(struct iscsi_task *task) |
| 4257 | { |
| 4258 | struct beiscsi_io_task *io_task = task->dd_data; |
| 4259 | struct iscsi_conn *conn = task->conn; |
| 4260 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; |
| 4261 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 4262 | struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess; |
| 4263 | struct hwi_wrb_context *pwrb_context; |
| 4264 | struct hwi_controller *phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4265 | uint16_t cri_index = BE_GET_CRI_FROM_CID( |
| 4266 | beiscsi_conn->beiscsi_conn_cid); |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4267 | |
| 4268 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4269 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4270 | |
| 4271 | if (io_task->cmd_bhs) { |
Romain Perier | af007b0 | 2017-07-06 10:13:03 +0200 | [diff] [blame] | 4272 | dma_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs, |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4273 | io_task->bhs_pa.u.a64.address); |
| 4274 | io_task->cmd_bhs = NULL; |
Jitendra Bhivare | e1f9d31 | 2016-08-19 15:20:22 +0530 | [diff] [blame] | 4275 | task->hdr = NULL; |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4276 | } |
| 4277 | |
| 4278 | if (task->sc) { |
| 4279 | if (io_task->pwrb_handle) { |
| 4280 | free_wrb_handle(phba, pwrb_context, |
| 4281 | io_task->pwrb_handle); |
| 4282 | io_task->pwrb_handle = NULL; |
| 4283 | } |
| 4284 | |
| 4285 | if (io_task->psgl_handle) { |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4286 | free_io_sgl_handle(phba, io_task->psgl_handle); |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4287 | io_task->psgl_handle = NULL; |
| 4288 | } |
Jayamohan Kallickal | da33497 | 2014-01-29 02:16:44 -0500 | [diff] [blame] | 4289 | |
| 4290 | if (io_task->scsi_cmnd) { |
Jitendra Bhivare | 9122e99 | 2016-08-19 15:20:11 +0530 | [diff] [blame] | 4291 | if (io_task->num_sg) |
| 4292 | scsi_dma_unmap(io_task->scsi_cmnd); |
Jayamohan Kallickal | da33497 | 2014-01-29 02:16:44 -0500 | [diff] [blame] | 4293 | io_task->scsi_cmnd = NULL; |
| 4294 | } |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4295 | } else { |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4296 | if (!beiscsi_conn->login_in_progress) |
Jayamohan Kallickal | 4a4a11b | 2013-04-05 20:38:31 -0700 | [diff] [blame] | 4297 | beiscsi_free_mgmt_task_handles(beiscsi_conn, task); |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4298 | } |
| 4299 | } |
| 4300 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4301 | void |
| 4302 | beiscsi_offload_connection(struct beiscsi_conn *beiscsi_conn, |
| 4303 | struct beiscsi_offload_params *params) |
| 4304 | { |
| 4305 | struct wrb_handle *pwrb_handle; |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4306 | struct hwi_wrb_context *pwrb_context = NULL; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4307 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4308 | struct iscsi_task *task = beiscsi_conn->task; |
| 4309 | struct iscsi_session *session = task->conn->session; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4310 | u32 doorbell = 0; |
| 4311 | |
| 4312 | /* |
| 4313 | * We can always use 0 here because it is reserved by libiscsi for |
| 4314 | * login/startup related tasks. |
| 4315 | */ |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4316 | beiscsi_conn->login_in_progress = 0; |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 4317 | spin_lock_bh(&session->back_lock); |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4318 | beiscsi_cleanup_task(task); |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 4319 | spin_unlock_bh(&session->back_lock); |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4320 | |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4321 | pwrb_handle = alloc_wrb_handle(phba, beiscsi_conn->beiscsi_conn_cid, |
| 4322 | &pwrb_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4323 | |
John Soni Jose | acb9693 | 2012-10-20 04:44:35 +0530 | [diff] [blame] | 4324 | /* Check for the adapter family */ |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 4325 | if (is_chip_be2_be3r(phba)) |
John Soni Jose | acb9693 | 2012-10-20 04:44:35 +0530 | [diff] [blame] | 4326 | beiscsi_offload_cxn_v0(params, pwrb_handle, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4327 | phba->init_mem, |
| 4328 | pwrb_context); |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 4329 | else |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4330 | beiscsi_offload_cxn_v2(params, pwrb_handle, |
| 4331 | pwrb_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4332 | |
John Soni Jose | acb9693 | 2012-10-20 04:44:35 +0530 | [diff] [blame] | 4333 | be_dws_le_to_cpu(pwrb_handle->pwrb, |
| 4334 | sizeof(struct iscsi_target_context_update_wrb)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4335 | |
| 4336 | doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK; |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 4337 | doorbell |= (pwrb_handle->wrb_index & DB_DEF_PDU_WRB_INDEX_MASK) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4338 | << DB_DEF_PDU_WRB_INDEX_SHIFT; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4339 | doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT; |
Jayamohan Kallickal | 1e4be6f | 2013-09-28 15:35:50 -0700 | [diff] [blame] | 4340 | iowrite32(doorbell, phba->db_va + |
| 4341 | beiscsi_conn->doorbell_offset); |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame] | 4342 | |
| 4343 | /* |
| 4344 | * There is no completion for CONTEXT_UPDATE. The completion of next |
| 4345 | * WRB posted guarantees FW's processing and DMA'ing of it. |
| 4346 | * Use beiscsi_put_wrb_handle to put it back in the pool which makes |
| 4347 | * sure zero'ing or reuse of the WRB only after wrbs_per_cxn. |
| 4348 | */ |
| 4349 | beiscsi_put_wrb_handle(pwrb_context, pwrb_handle, |
| 4350 | phba->params.wrbs_per_cxn); |
| 4351 | beiscsi_log(phba, KERN_INFO, |
| 4352 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
| 4353 | "BM_%d : put CONTEXT_UPDATE pwrb_handle=%p free_index=0x%x wrb_handles_available=%d\n", |
| 4354 | pwrb_handle, pwrb_context->free_index, |
| 4355 | pwrb_context->wrb_handles_available); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4356 | } |
| 4357 | |
| 4358 | static void beiscsi_parse_pdu(struct iscsi_conn *conn, itt_t itt, |
| 4359 | int *index, int *age) |
| 4360 | { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4361 | *index = (int)itt; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4362 | if (age) |
| 4363 | *age = conn->session->age; |
| 4364 | } |
| 4365 | |
| 4366 | /** |
| 4367 | * beiscsi_alloc_pdu - allocates pdu and related resources |
| 4368 | * @task: libiscsi task |
| 4369 | * @opcode: opcode of pdu for task |
| 4370 | * |
| 4371 | * This is called with the session lock held. It will allocate |
| 4372 | * the wrb and sgl if needed for the command. And it will prep |
| 4373 | * the pdu's itt. beiscsi_parse_pdu will later translate |
| 4374 | * the pdu itt to the libiscsi task itt. |
| 4375 | */ |
| 4376 | static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode) |
| 4377 | { |
| 4378 | struct beiscsi_io_task *io_task = task->dd_data; |
| 4379 | struct iscsi_conn *conn = task->conn; |
| 4380 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; |
| 4381 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 4382 | struct hwi_wrb_context *pwrb_context; |
| 4383 | struct hwi_controller *phwi_ctrlr; |
| 4384 | itt_t itt; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4385 | uint16_t cri_index = 0; |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4386 | struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess; |
| 4387 | dma_addr_t paddr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4388 | |
Romain Perier | af007b0 | 2017-07-06 10:13:03 +0200 | [diff] [blame] | 4389 | io_task->cmd_bhs = dma_pool_alloc(beiscsi_sess->bhs_pool, |
Mike Christie | bc7acce | 2010-12-31 02:22:19 -0600 | [diff] [blame] | 4390 | GFP_ATOMIC, &paddr); |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4391 | if (!io_task->cmd_bhs) |
| 4392 | return -ENOMEM; |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4393 | io_task->bhs_pa.u.a64.address = paddr; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4394 | io_task->libiscsi_itt = (itt_t)task->itt; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4395 | io_task->conn = beiscsi_conn; |
| 4396 | |
| 4397 | task->hdr = (struct iscsi_hdr *)&io_task->cmd_bhs->iscsi_hdr; |
| 4398 | task->hdr_max = sizeof(struct be_cmd_bhs); |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4399 | io_task->psgl_handle = NULL; |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 4400 | io_task->pwrb_handle = NULL; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4401 | |
| 4402 | if (task->sc) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4403 | io_task->psgl_handle = alloc_io_sgl_handle(phba); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4404 | if (!io_task->psgl_handle) { |
| 4405 | beiscsi_log(phba, KERN_ERR, |
| 4406 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
| 4407 | "BM_%d : Alloc of IO_SGL_ICD Failed" |
| 4408 | "for the CID : %d\n", |
| 4409 | beiscsi_conn->beiscsi_conn_cid); |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4410 | goto free_hndls; |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4411 | } |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4412 | io_task->pwrb_handle = alloc_wrb_handle(phba, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4413 | beiscsi_conn->beiscsi_conn_cid, |
| 4414 | &io_task->pwrb_context); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4415 | if (!io_task->pwrb_handle) { |
| 4416 | beiscsi_log(phba, KERN_ERR, |
| 4417 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
| 4418 | "BM_%d : Alloc of WRB_HANDLE Failed" |
| 4419 | "for the CID : %d\n", |
| 4420 | beiscsi_conn->beiscsi_conn_cid); |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4421 | goto free_io_hndls; |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4422 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4423 | } else { |
| 4424 | io_task->scsi_cmnd = NULL; |
Jayamohan Kallickal | d7aea67 | 2010-01-05 05:08:39 +0530 | [diff] [blame] | 4425 | if ((opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN) { |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4426 | beiscsi_conn->task = task; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4427 | if (!beiscsi_conn->login_in_progress) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4428 | io_task->psgl_handle = (struct sgl_handle *) |
| 4429 | alloc_mgmt_sgl_handle(phba); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4430 | if (!io_task->psgl_handle) { |
| 4431 | beiscsi_log(phba, KERN_ERR, |
| 4432 | BEISCSI_LOG_IO | |
| 4433 | BEISCSI_LOG_CONFIG, |
| 4434 | "BM_%d : Alloc of MGMT_SGL_ICD Failed" |
| 4435 | "for the CID : %d\n", |
| 4436 | beiscsi_conn-> |
| 4437 | beiscsi_conn_cid); |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4438 | goto free_hndls; |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4439 | } |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4440 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4441 | beiscsi_conn->login_in_progress = 1; |
| 4442 | beiscsi_conn->plogin_sgl_handle = |
| 4443 | io_task->psgl_handle; |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4444 | io_task->pwrb_handle = |
| 4445 | alloc_wrb_handle(phba, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4446 | beiscsi_conn->beiscsi_conn_cid, |
| 4447 | &io_task->pwrb_context); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4448 | if (!io_task->pwrb_handle) { |
| 4449 | beiscsi_log(phba, KERN_ERR, |
| 4450 | BEISCSI_LOG_IO | |
| 4451 | BEISCSI_LOG_CONFIG, |
| 4452 | "BM_%d : Alloc of WRB_HANDLE Failed" |
| 4453 | "for the CID : %d\n", |
| 4454 | beiscsi_conn-> |
| 4455 | beiscsi_conn_cid); |
| 4456 | goto free_mgmt_hndls; |
| 4457 | } |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4458 | beiscsi_conn->plogin_wrb_handle = |
| 4459 | io_task->pwrb_handle; |
| 4460 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4461 | } else { |
| 4462 | io_task->psgl_handle = |
| 4463 | beiscsi_conn->plogin_sgl_handle; |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4464 | io_task->pwrb_handle = |
| 4465 | beiscsi_conn->plogin_wrb_handle; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4466 | } |
| 4467 | } else { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4468 | io_task->psgl_handle = alloc_mgmt_sgl_handle(phba); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4469 | if (!io_task->psgl_handle) { |
| 4470 | beiscsi_log(phba, KERN_ERR, |
| 4471 | BEISCSI_LOG_IO | |
| 4472 | BEISCSI_LOG_CONFIG, |
| 4473 | "BM_%d : Alloc of MGMT_SGL_ICD Failed" |
| 4474 | "for the CID : %d\n", |
| 4475 | beiscsi_conn-> |
| 4476 | beiscsi_conn_cid); |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4477 | goto free_hndls; |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4478 | } |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4479 | io_task->pwrb_handle = |
| 4480 | alloc_wrb_handle(phba, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4481 | beiscsi_conn->beiscsi_conn_cid, |
| 4482 | &io_task->pwrb_context); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4483 | if (!io_task->pwrb_handle) { |
| 4484 | beiscsi_log(phba, KERN_ERR, |
| 4485 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
| 4486 | "BM_%d : Alloc of WRB_HANDLE Failed" |
| 4487 | "for the CID : %d\n", |
| 4488 | beiscsi_conn->beiscsi_conn_cid); |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4489 | goto free_mgmt_hndls; |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4490 | } |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4491 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4492 | } |
| 4493 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4494 | itt = (itt_t) cpu_to_be32(((unsigned int)io_task->pwrb_handle-> |
| 4495 | wrb_index << 16) | (unsigned int) |
| 4496 | (io_task->psgl_handle->sgl_index)); |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 4497 | io_task->pwrb_handle->pio_handle = task; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4498 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4499 | io_task->cmd_bhs->iscsi_hdr.itt = itt; |
| 4500 | return 0; |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4501 | |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4502 | free_io_hndls: |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4503 | free_io_sgl_handle(phba, io_task->psgl_handle); |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4504 | goto free_hndls; |
| 4505 | free_mgmt_hndls: |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4506 | free_mgmt_sgl_handle(phba, io_task->psgl_handle); |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4507 | io_task->psgl_handle = NULL; |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4508 | free_hndls: |
| 4509 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4510 | cri_index = BE_GET_CRI_FROM_CID( |
| 4511 | beiscsi_conn->beiscsi_conn_cid); |
| 4512 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4513 | if (io_task->pwrb_handle) |
| 4514 | free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle); |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4515 | io_task->pwrb_handle = NULL; |
Romain Perier | af007b0 | 2017-07-06 10:13:03 +0200 | [diff] [blame] | 4516 | dma_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs, |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4517 | io_task->bhs_pa.u.a64.address); |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4518 | io_task->cmd_bhs = NULL; |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4519 | return -ENOMEM; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4520 | } |
Baoyou Xie | 0825b8e | 2016-09-26 20:00:59 +0800 | [diff] [blame] | 4521 | static int beiscsi_iotask_v2(struct iscsi_task *task, struct scatterlist *sg, |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4522 | unsigned int num_sg, unsigned int xferlen, |
| 4523 | unsigned int writedir) |
| 4524 | { |
| 4525 | |
| 4526 | struct beiscsi_io_task *io_task = task->dd_data; |
| 4527 | struct iscsi_conn *conn = task->conn; |
| 4528 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; |
| 4529 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 4530 | struct iscsi_wrb *pwrb = NULL; |
| 4531 | unsigned int doorbell = 0; |
| 4532 | |
| 4533 | pwrb = io_task->pwrb_handle->pwrb; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4534 | |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4535 | io_task->bhs_len = sizeof(struct be_cmd_bhs); |
| 4536 | |
| 4537 | if (writedir) { |
| 4538 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb, |
| 4539 | INI_WR_CMD); |
| 4540 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 1); |
| 4541 | } else { |
| 4542 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb, |
| 4543 | INI_RD_CMD); |
| 4544 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 0); |
| 4545 | } |
| 4546 | |
| 4547 | io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb_v2, |
| 4548 | type, pwrb); |
| 4549 | |
| 4550 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, lun, pwrb, |
| 4551 | cpu_to_be16(*(unsigned short *) |
| 4552 | &io_task->cmd_bhs->iscsi_hdr.lun)); |
| 4553 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb, xferlen); |
| 4554 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb, |
| 4555 | io_task->pwrb_handle->wrb_index); |
| 4556 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb, |
| 4557 | be32_to_cpu(task->cmdsn)); |
| 4558 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb, |
| 4559 | io_task->psgl_handle->sgl_index); |
| 4560 | |
| 4561 | hwi_write_sgl_v2(pwrb, sg, num_sg, io_task); |
| 4562 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4563 | io_task->pwrb_handle->wrb_index); |
| 4564 | if (io_task->pwrb_context->plast_wrb) |
| 4565 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, |
| 4566 | io_task->pwrb_context->plast_wrb, |
| 4567 | io_task->pwrb_handle->wrb_index); |
| 4568 | io_task->pwrb_context->plast_wrb = pwrb; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4569 | |
| 4570 | be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb)); |
| 4571 | |
| 4572 | doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK; |
| 4573 | doorbell |= (io_task->pwrb_handle->wrb_index & |
| 4574 | DB_DEF_PDU_WRB_INDEX_MASK) << |
| 4575 | DB_DEF_PDU_WRB_INDEX_SHIFT; |
| 4576 | doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT; |
Jayamohan Kallickal | 1e4be6f | 2013-09-28 15:35:50 -0700 | [diff] [blame] | 4577 | iowrite32(doorbell, phba->db_va + |
| 4578 | beiscsi_conn->doorbell_offset); |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4579 | return 0; |
| 4580 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4581 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4582 | static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg, |
| 4583 | unsigned int num_sg, unsigned int xferlen, |
| 4584 | unsigned int writedir) |
| 4585 | { |
| 4586 | |
| 4587 | struct beiscsi_io_task *io_task = task->dd_data; |
| 4588 | struct iscsi_conn *conn = task->conn; |
| 4589 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; |
| 4590 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 4591 | struct iscsi_wrb *pwrb = NULL; |
| 4592 | unsigned int doorbell = 0; |
| 4593 | |
| 4594 | pwrb = io_task->pwrb_handle->pwrb; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4595 | io_task->bhs_len = sizeof(struct be_cmd_bhs); |
| 4596 | |
| 4597 | if (writedir) { |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 4598 | AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb, |
| 4599 | INI_WR_CMD); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4600 | AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4601 | } else { |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 4602 | AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb, |
| 4603 | INI_RD_CMD); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4604 | AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0); |
| 4605 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4606 | |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4607 | io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb, |
| 4608 | type, pwrb); |
| 4609 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4610 | AMAP_SET_BITS(struct amap_iscsi_wrb, lun, pwrb, |
Jayamohan Kallickal | dc63aac | 2012-04-03 23:41:36 -0500 | [diff] [blame] | 4611 | cpu_to_be16(*(unsigned short *) |
| 4612 | &io_task->cmd_bhs->iscsi_hdr.lun)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4613 | AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, xferlen); |
| 4614 | AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb, |
| 4615 | io_task->pwrb_handle->wrb_index); |
| 4616 | AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, |
| 4617 | be32_to_cpu(task->cmdsn)); |
| 4618 | AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb, |
| 4619 | io_task->psgl_handle->sgl_index); |
| 4620 | |
| 4621 | hwi_write_sgl(pwrb, sg, num_sg, io_task); |
| 4622 | |
| 4623 | AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4624 | io_task->pwrb_handle->wrb_index); |
| 4625 | if (io_task->pwrb_context->plast_wrb) |
| 4626 | AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, |
| 4627 | io_task->pwrb_context->plast_wrb, |
| 4628 | io_task->pwrb_handle->wrb_index); |
| 4629 | io_task->pwrb_context->plast_wrb = pwrb; |
| 4630 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4631 | be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb)); |
| 4632 | |
| 4633 | doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK; |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 4634 | doorbell |= (io_task->pwrb_handle->wrb_index & |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4635 | DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT; |
| 4636 | doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT; |
| 4637 | |
Jayamohan Kallickal | 1e4be6f | 2013-09-28 15:35:50 -0700 | [diff] [blame] | 4638 | iowrite32(doorbell, phba->db_va + |
| 4639 | beiscsi_conn->doorbell_offset); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4640 | return 0; |
| 4641 | } |
| 4642 | |
| 4643 | static int beiscsi_mtask(struct iscsi_task *task) |
| 4644 | { |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 4645 | struct beiscsi_io_task *io_task = task->dd_data; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4646 | struct iscsi_conn *conn = task->conn; |
| 4647 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; |
| 4648 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 4649 | struct iscsi_wrb *pwrb = NULL; |
| 4650 | unsigned int doorbell = 0; |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 4651 | unsigned int cid; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4652 | unsigned int pwrb_typeoffset = 0; |
Alexey Khoroshilov | e049362 | 2016-01-16 00:45:34 +0300 | [diff] [blame] | 4653 | int ret = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4654 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4655 | cid = beiscsi_conn->beiscsi_conn_cid; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4656 | pwrb = io_task->pwrb_handle->pwrb; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4657 | |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 4658 | if (is_chip_be2_be3r(phba)) { |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4659 | AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, |
| 4660 | be32_to_cpu(task->cmdsn)); |
| 4661 | AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb, |
| 4662 | io_task->pwrb_handle->wrb_index); |
| 4663 | AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb, |
| 4664 | io_task->psgl_handle->sgl_index); |
| 4665 | AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, |
| 4666 | task->data_count); |
| 4667 | AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4668 | io_task->pwrb_handle->wrb_index); |
| 4669 | if (io_task->pwrb_context->plast_wrb) |
| 4670 | AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, |
| 4671 | io_task->pwrb_context->plast_wrb, |
| 4672 | io_task->pwrb_handle->wrb_index); |
| 4673 | io_task->pwrb_context->plast_wrb = pwrb; |
| 4674 | |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4675 | pwrb_typeoffset = BE_WRB_TYPE_OFFSET; |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 4676 | } else { |
| 4677 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb, |
| 4678 | be32_to_cpu(task->cmdsn)); |
| 4679 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb, |
| 4680 | io_task->pwrb_handle->wrb_index); |
| 4681 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb, |
| 4682 | io_task->psgl_handle->sgl_index); |
| 4683 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb, |
| 4684 | task->data_count); |
| 4685 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4686 | io_task->pwrb_handle->wrb_index); |
| 4687 | if (io_task->pwrb_context->plast_wrb) |
| 4688 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, |
| 4689 | io_task->pwrb_context->plast_wrb, |
| 4690 | io_task->pwrb_handle->wrb_index); |
| 4691 | io_task->pwrb_context->plast_wrb = pwrb; |
| 4692 | |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 4693 | pwrb_typeoffset = SKH_WRB_TYPE_OFFSET; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4694 | } |
| 4695 | |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 4696 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4697 | switch (task->hdr->opcode & ISCSI_OPCODE_MASK) { |
| 4698 | case ISCSI_OP_LOGIN: |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4699 | AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, 1); |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4700 | ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset); |
Alexey Khoroshilov | e049362 | 2016-01-16 00:45:34 +0300 | [diff] [blame] | 4701 | ret = hwi_write_buffer(pwrb, task); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4702 | break; |
| 4703 | case ISCSI_OP_NOOP_OUT: |
Jayamohan Kallickal | 1390b01 | 2011-03-25 14:24:01 -0700 | [diff] [blame] | 4704 | if (task->hdr->ttt != ISCSI_RESERVED_TAG) { |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4705 | ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset); |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 4706 | if (is_chip_be2_be3r(phba)) |
| 4707 | AMAP_SET_BITS(struct amap_iscsi_wrb, |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4708 | dmsg, pwrb, 1); |
| 4709 | else |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 4710 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4711 | dmsg, pwrb, 1); |
Jayamohan Kallickal | 1390b01 | 2011-03-25 14:24:01 -0700 | [diff] [blame] | 4712 | } else { |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4713 | ADAPTER_SET_WRB_TYPE(pwrb, INI_RD_CMD, pwrb_typeoffset); |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 4714 | if (is_chip_be2_be3r(phba)) |
| 4715 | AMAP_SET_BITS(struct amap_iscsi_wrb, |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4716 | dmsg, pwrb, 0); |
| 4717 | else |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 4718 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4719 | dmsg, pwrb, 0); |
Jayamohan Kallickal | 1390b01 | 2011-03-25 14:24:01 -0700 | [diff] [blame] | 4720 | } |
Alexey Khoroshilov | e049362 | 2016-01-16 00:45:34 +0300 | [diff] [blame] | 4721 | ret = hwi_write_buffer(pwrb, task); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4722 | break; |
| 4723 | case ISCSI_OP_TEXT: |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4724 | ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset); |
Alexey Khoroshilov | e049362 | 2016-01-16 00:45:34 +0300 | [diff] [blame] | 4725 | ret = hwi_write_buffer(pwrb, task); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4726 | break; |
| 4727 | case ISCSI_OP_SCSI_TMFUNC: |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4728 | ADAPTER_SET_WRB_TYPE(pwrb, INI_TMF_CMD, pwrb_typeoffset); |
Alexey Khoroshilov | e049362 | 2016-01-16 00:45:34 +0300 | [diff] [blame] | 4729 | ret = hwi_write_buffer(pwrb, task); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4730 | break; |
| 4731 | case ISCSI_OP_LOGOUT: |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4732 | ADAPTER_SET_WRB_TYPE(pwrb, HWH_TYPE_LOGOUT, pwrb_typeoffset); |
Alexey Khoroshilov | e049362 | 2016-01-16 00:45:34 +0300 | [diff] [blame] | 4733 | ret = hwi_write_buffer(pwrb, task); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4734 | break; |
| 4735 | |
| 4736 | default: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4737 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
| 4738 | "BM_%d : opcode =%d Not supported\n", |
| 4739 | task->hdr->opcode & ISCSI_OPCODE_MASK); |
| 4740 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4741 | return -EINVAL; |
| 4742 | } |
| 4743 | |
Alexey Khoroshilov | e049362 | 2016-01-16 00:45:34 +0300 | [diff] [blame] | 4744 | if (ret) |
| 4745 | return ret; |
| 4746 | |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4747 | /* Set the task type */ |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 4748 | io_task->wrb_type = (is_chip_be2_be3r(phba)) ? |
| 4749 | AMAP_GET_BITS(struct amap_iscsi_wrb, type, pwrb) : |
| 4750 | AMAP_GET_BITS(struct amap_iscsi_wrb_v2, type, pwrb); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4751 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4752 | doorbell |= cid & DB_WRB_POST_CID_MASK; |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 4753 | doorbell |= (io_task->pwrb_handle->wrb_index & |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4754 | DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT; |
| 4755 | doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT; |
Jayamohan Kallickal | 1e4be6f | 2013-09-28 15:35:50 -0700 | [diff] [blame] | 4756 | iowrite32(doorbell, phba->db_va + |
| 4757 | beiscsi_conn->doorbell_offset); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4758 | return 0; |
| 4759 | } |
| 4760 | |
| 4761 | static int beiscsi_task_xmit(struct iscsi_task *task) |
| 4762 | { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4763 | struct beiscsi_io_task *io_task = task->dd_data; |
| 4764 | struct scsi_cmnd *sc = task->sc; |
Jitendra Bhivare | 1868379 | 2016-02-04 15:49:18 +0530 | [diff] [blame] | 4765 | struct beiscsi_hba *phba; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4766 | struct scatterlist *sg; |
| 4767 | int num_sg; |
| 4768 | unsigned int writedir = 0, xferlen = 0; |
| 4769 | |
Jitendra Bhivare | 9122e99 | 2016-08-19 15:20:11 +0530 | [diff] [blame] | 4770 | phba = io_task->conn->phba; |
| 4771 | /** |
| 4772 | * HBA in error includes BEISCSI_HBA_FW_TIMEOUT. IO path might be |
| 4773 | * operational if FW still gets heartbeat from EP FW. Is management |
| 4774 | * path really needed to continue further? |
| 4775 | */ |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 4776 | if (!beiscsi_hba_is_online(phba)) |
Jitendra Bhivare | 9122e99 | 2016-08-19 15:20:11 +0530 | [diff] [blame] | 4777 | return -EIO; |
| 4778 | |
Jitendra Bhivare | 1868379 | 2016-02-04 15:49:18 +0530 | [diff] [blame] | 4779 | if (!io_task->conn->login_in_progress) |
| 4780 | task->hdr->exp_statsn = 0; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4781 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4782 | if (!sc) |
| 4783 | return beiscsi_mtask(task); |
| 4784 | |
| 4785 | io_task->scsi_cmnd = sc; |
Jitendra Bhivare | 9122e99 | 2016-08-19 15:20:11 +0530 | [diff] [blame] | 4786 | io_task->num_sg = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4787 | num_sg = scsi_dma_map(sc); |
| 4788 | if (num_sg < 0) { |
Jayamohan Kallickal | afb9605 | 2013-09-28 15:35:55 -0700 | [diff] [blame] | 4789 | beiscsi_log(phba, KERN_ERR, |
| 4790 | BEISCSI_LOG_IO | BEISCSI_LOG_ISCSI, |
| 4791 | "BM_%d : scsi_dma_map Failed " |
| 4792 | "Driver_ITT : 0x%x ITT : 0x%x Xferlen : 0x%x\n", |
| 4793 | be32_to_cpu(io_task->cmd_bhs->iscsi_hdr.itt), |
| 4794 | io_task->libiscsi_itt, scsi_bufflen(sc)); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4795 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4796 | return num_sg; |
| 4797 | } |
Jitendra Bhivare | 9122e99 | 2016-08-19 15:20:11 +0530 | [diff] [blame] | 4798 | /** |
| 4799 | * For scsi cmd task, check num_sg before unmapping in cleanup_task. |
| 4800 | * For management task, cleanup_task checks mtask_addr before unmapping. |
| 4801 | */ |
| 4802 | io_task->num_sg = num_sg; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4803 | xferlen = scsi_bufflen(sc); |
| 4804 | sg = scsi_sglist(sc); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4805 | if (sc->sc_data_direction == DMA_TO_DEVICE) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4806 | writedir = 1; |
Jitendra Bhivare | 45efc940 | 2017-10-10 16:18:18 +0530 | [diff] [blame] | 4807 | else |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4808 | writedir = 0; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4809 | |
Jitendra Bhivare | 45efc940 | 2017-10-10 16:18:18 +0530 | [diff] [blame] | 4810 | return phba->iotask_fn(task, sg, num_sg, xferlen, writedir); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4811 | } |
| 4812 | |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 4813 | /** |
| 4814 | * beiscsi_bsg_request - handle bsg request from ISCSI transport |
| 4815 | * @job: job to handle |
| 4816 | */ |
| 4817 | static int beiscsi_bsg_request(struct bsg_job *job) |
| 4818 | { |
| 4819 | struct Scsi_Host *shost; |
| 4820 | struct beiscsi_hba *phba; |
| 4821 | struct iscsi_bsg_request *bsg_req = job->request; |
| 4822 | int rc = -EINVAL; |
| 4823 | unsigned int tag; |
| 4824 | struct be_dma_mem nonemb_cmd; |
| 4825 | struct be_cmd_resp_hdr *resp; |
| 4826 | struct iscsi_bsg_reply *bsg_reply = job->reply; |
| 4827 | unsigned short status, extd_status; |
| 4828 | |
| 4829 | shost = iscsi_job_to_shost(job); |
| 4830 | phba = iscsi_host_priv(shost); |
| 4831 | |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 4832 | if (!beiscsi_hba_is_online(phba)) { |
Jitendra Bhivare | 9122e99 | 2016-08-19 15:20:11 +0530 | [diff] [blame] | 4833 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG, |
| 4834 | "BM_%d : HBA in error 0x%lx\n", phba->state); |
| 4835 | return -ENXIO; |
| 4836 | } |
| 4837 | |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 4838 | switch (bsg_req->msgcode) { |
| 4839 | case ISCSI_BSG_HST_VENDOR: |
| 4840 | nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev, |
| 4841 | job->request_payload.payload_len, |
| 4842 | &nonemb_cmd.dma); |
| 4843 | if (nonemb_cmd.va == NULL) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4844 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
| 4845 | "BM_%d : Failed to allocate memory for " |
| 4846 | "beiscsi_bsg_request\n"); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4847 | return -ENOMEM; |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 4848 | } |
| 4849 | tag = mgmt_vendor_specific_fw_cmd(&phba->ctrl, phba, job, |
| 4850 | &nonemb_cmd); |
| 4851 | if (!tag) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4852 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4853 | "BM_%d : MBX Tag Allocation Failed\n"); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4854 | |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 4855 | pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size, |
| 4856 | nonemb_cmd.va, nonemb_cmd.dma); |
| 4857 | return -EAGAIN; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 4858 | } |
| 4859 | |
| 4860 | rc = wait_event_interruptible_timeout( |
| 4861 | phba->ctrl.mcc_wait[tag], |
Jitendra Bhivare | 67296ad | 2016-02-04 15:49:10 +0530 | [diff] [blame] | 4862 | phba->ctrl.mcc_tag_status[tag], |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 4863 | msecs_to_jiffies( |
| 4864 | BEISCSI_HOST_MBX_TIMEOUT)); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 4865 | |
| 4866 | if (!test_bit(BEISCSI_HBA_ONLINE, &phba->state)) { |
| 4867 | clear_bit(MCC_TAG_STATE_RUNNING, |
| 4868 | &phba->ctrl.ptag_state[tag].tag_state); |
| 4869 | pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size, |
| 4870 | nonemb_cmd.va, nonemb_cmd.dma); |
| 4871 | return -EIO; |
| 4872 | } |
Jitendra Bhivare | 67296ad | 2016-02-04 15:49:10 +0530 | [diff] [blame] | 4873 | extd_status = (phba->ctrl.mcc_tag_status[tag] & |
| 4874 | CQE_STATUS_ADDL_MASK) >> CQE_STATUS_ADDL_SHIFT; |
| 4875 | status = phba->ctrl.mcc_tag_status[tag] & CQE_STATUS_MASK; |
Jitendra Bhivare | 090e218 | 2016-02-04 15:49:17 +0530 | [diff] [blame] | 4876 | free_mcc_wrb(&phba->ctrl, tag); |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 4877 | resp = (struct be_cmd_resp_hdr *)nonemb_cmd.va; |
| 4878 | sg_copy_from_buffer(job->reply_payload.sg_list, |
| 4879 | job->reply_payload.sg_cnt, |
| 4880 | nonemb_cmd.va, (resp->response_length |
| 4881 | + sizeof(*resp))); |
| 4882 | bsg_reply->reply_payload_rcv_len = resp->response_length; |
| 4883 | bsg_reply->result = status; |
| 4884 | bsg_job_done(job, bsg_reply->result, |
| 4885 | bsg_reply->reply_payload_rcv_len); |
| 4886 | pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size, |
| 4887 | nonemb_cmd.va, nonemb_cmd.dma); |
| 4888 | if (status || extd_status) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4889 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4890 | "BM_%d : MBX Cmd Failed" |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4891 | " status = %d extd_status = %d\n", |
| 4892 | status, extd_status); |
| 4893 | |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 4894 | return -EIO; |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4895 | } else { |
| 4896 | rc = 0; |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 4897 | } |
| 4898 | break; |
| 4899 | |
| 4900 | default: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4901 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
| 4902 | "BM_%d : Unsupported bsg command: 0x%x\n", |
| 4903 | bsg_req->msgcode); |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 4904 | break; |
| 4905 | } |
| 4906 | |
| 4907 | return rc; |
| 4908 | } |
| 4909 | |
Baoyou Xie | 0825b8e | 2016-09-26 20:00:59 +0800 | [diff] [blame] | 4910 | static void beiscsi_hba_attrs_init(struct beiscsi_hba *phba) |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4911 | { |
| 4912 | /* Set the logging parameter */ |
| 4913 | beiscsi_log_enable_init(phba, beiscsi_log_enable); |
| 4914 | } |
| 4915 | |
Jitendra Bhivare | 50a4b82 | 2016-08-19 15:20:12 +0530 | [diff] [blame] | 4916 | void beiscsi_start_boot_work(struct beiscsi_hba *phba, unsigned int s_handle) |
| 4917 | { |
| 4918 | if (phba->boot_struct.boot_kset) |
| 4919 | return; |
| 4920 | |
| 4921 | /* skip if boot work is already in progress */ |
| 4922 | if (test_and_set_bit(BEISCSI_HBA_BOOT_WORK, &phba->state)) |
| 4923 | return; |
| 4924 | |
| 4925 | phba->boot_struct.retry = 3; |
| 4926 | phba->boot_struct.tag = 0; |
| 4927 | phba->boot_struct.s_handle = s_handle; |
| 4928 | phba->boot_struct.action = BEISCSI_BOOT_GET_SHANDLE; |
| 4929 | schedule_work(&phba->boot_work); |
| 4930 | } |
| 4931 | |
Jitendra Bhivare | 8d9ecd4 | 2017-10-10 16:18:11 +0530 | [diff] [blame] | 4932 | /** |
| 4933 | * Boot flag info for iscsi-utilities |
| 4934 | * Bit 0 Block valid flag |
| 4935 | * Bit 1 Firmware booting selected |
| 4936 | */ |
| 4937 | #define BEISCSI_SYSFS_ISCSI_BOOT_FLAGS 3 |
| 4938 | |
Jitendra Bhivare | 50a4b82 | 2016-08-19 15:20:12 +0530 | [diff] [blame] | 4939 | static ssize_t beiscsi_show_boot_tgt_info(void *data, int type, char *buf) |
| 4940 | { |
| 4941 | struct beiscsi_hba *phba = data; |
| 4942 | struct mgmt_session_info *boot_sess = &phba->boot_struct.boot_sess; |
| 4943 | struct mgmt_conn_info *boot_conn = &boot_sess->conn_list[0]; |
| 4944 | char *str = buf; |
| 4945 | int rc = -EPERM; |
| 4946 | |
| 4947 | switch (type) { |
| 4948 | case ISCSI_BOOT_TGT_NAME: |
| 4949 | rc = sprintf(buf, "%.*s\n", |
| 4950 | (int)strlen(boot_sess->target_name), |
| 4951 | (char *)&boot_sess->target_name); |
| 4952 | break; |
| 4953 | case ISCSI_BOOT_TGT_IP_ADDR: |
| 4954 | if (boot_conn->dest_ipaddr.ip_type == BEISCSI_IP_TYPE_V4) |
| 4955 | rc = sprintf(buf, "%pI4\n", |
| 4956 | (char *)&boot_conn->dest_ipaddr.addr); |
| 4957 | else |
| 4958 | rc = sprintf(str, "%pI6\n", |
| 4959 | (char *)&boot_conn->dest_ipaddr.addr); |
| 4960 | break; |
| 4961 | case ISCSI_BOOT_TGT_PORT: |
| 4962 | rc = sprintf(str, "%d\n", boot_conn->dest_port); |
| 4963 | break; |
| 4964 | |
| 4965 | case ISCSI_BOOT_TGT_CHAP_NAME: |
| 4966 | rc = sprintf(str, "%.*s\n", |
| 4967 | boot_conn->negotiated_login_options.auth_data.chap. |
| 4968 | target_chap_name_length, |
| 4969 | (char *)&boot_conn->negotiated_login_options. |
| 4970 | auth_data.chap.target_chap_name); |
| 4971 | break; |
| 4972 | case ISCSI_BOOT_TGT_CHAP_SECRET: |
| 4973 | rc = sprintf(str, "%.*s\n", |
| 4974 | boot_conn->negotiated_login_options.auth_data.chap. |
| 4975 | target_secret_length, |
| 4976 | (char *)&boot_conn->negotiated_login_options. |
| 4977 | auth_data.chap.target_secret); |
| 4978 | break; |
| 4979 | case ISCSI_BOOT_TGT_REV_CHAP_NAME: |
| 4980 | rc = sprintf(str, "%.*s\n", |
| 4981 | boot_conn->negotiated_login_options.auth_data.chap. |
| 4982 | intr_chap_name_length, |
| 4983 | (char *)&boot_conn->negotiated_login_options. |
| 4984 | auth_data.chap.intr_chap_name); |
| 4985 | break; |
| 4986 | case ISCSI_BOOT_TGT_REV_CHAP_SECRET: |
| 4987 | rc = sprintf(str, "%.*s\n", |
| 4988 | boot_conn->negotiated_login_options.auth_data.chap. |
| 4989 | intr_secret_length, |
| 4990 | (char *)&boot_conn->negotiated_login_options. |
| 4991 | auth_data.chap.intr_secret); |
| 4992 | break; |
| 4993 | case ISCSI_BOOT_TGT_FLAGS: |
Jitendra Bhivare | 8d9ecd4 | 2017-10-10 16:18:11 +0530 | [diff] [blame] | 4994 | rc = sprintf(str, "%d\n", BEISCSI_SYSFS_ISCSI_BOOT_FLAGS); |
Jitendra Bhivare | 50a4b82 | 2016-08-19 15:20:12 +0530 | [diff] [blame] | 4995 | break; |
| 4996 | case ISCSI_BOOT_TGT_NIC_ASSOC: |
| 4997 | rc = sprintf(str, "0\n"); |
| 4998 | break; |
| 4999 | } |
| 5000 | return rc; |
| 5001 | } |
| 5002 | |
| 5003 | static ssize_t beiscsi_show_boot_ini_info(void *data, int type, char *buf) |
| 5004 | { |
| 5005 | struct beiscsi_hba *phba = data; |
| 5006 | char *str = buf; |
| 5007 | int rc = -EPERM; |
| 5008 | |
| 5009 | switch (type) { |
| 5010 | case ISCSI_BOOT_INI_INITIATOR_NAME: |
| 5011 | rc = sprintf(str, "%s\n", |
| 5012 | phba->boot_struct.boot_sess.initiator_iscsiname); |
| 5013 | break; |
| 5014 | } |
| 5015 | return rc; |
| 5016 | } |
| 5017 | |
| 5018 | static ssize_t beiscsi_show_boot_eth_info(void *data, int type, char *buf) |
| 5019 | { |
| 5020 | struct beiscsi_hba *phba = data; |
| 5021 | char *str = buf; |
| 5022 | int rc = -EPERM; |
| 5023 | |
| 5024 | switch (type) { |
| 5025 | case ISCSI_BOOT_ETH_FLAGS: |
Jitendra Bhivare | 8d9ecd4 | 2017-10-10 16:18:11 +0530 | [diff] [blame] | 5026 | rc = sprintf(str, "%d\n", BEISCSI_SYSFS_ISCSI_BOOT_FLAGS); |
Jitendra Bhivare | 50a4b82 | 2016-08-19 15:20:12 +0530 | [diff] [blame] | 5027 | break; |
| 5028 | case ISCSI_BOOT_ETH_INDEX: |
| 5029 | rc = sprintf(str, "0\n"); |
| 5030 | break; |
| 5031 | case ISCSI_BOOT_ETH_MAC: |
| 5032 | rc = beiscsi_get_macaddr(str, phba); |
| 5033 | break; |
| 5034 | } |
| 5035 | return rc; |
| 5036 | } |
| 5037 | |
Jitendra Bhivare | 50a4b82 | 2016-08-19 15:20:12 +0530 | [diff] [blame] | 5038 | static umode_t beiscsi_tgt_get_attr_visibility(void *data, int type) |
| 5039 | { |
| 5040 | umode_t rc = 0; |
| 5041 | |
| 5042 | switch (type) { |
| 5043 | case ISCSI_BOOT_TGT_NAME: |
| 5044 | case ISCSI_BOOT_TGT_IP_ADDR: |
| 5045 | case ISCSI_BOOT_TGT_PORT: |
| 5046 | case ISCSI_BOOT_TGT_CHAP_NAME: |
| 5047 | case ISCSI_BOOT_TGT_CHAP_SECRET: |
| 5048 | case ISCSI_BOOT_TGT_REV_CHAP_NAME: |
| 5049 | case ISCSI_BOOT_TGT_REV_CHAP_SECRET: |
| 5050 | case ISCSI_BOOT_TGT_NIC_ASSOC: |
| 5051 | case ISCSI_BOOT_TGT_FLAGS: |
| 5052 | rc = S_IRUGO; |
| 5053 | break; |
| 5054 | } |
| 5055 | return rc; |
| 5056 | } |
| 5057 | |
| 5058 | static umode_t beiscsi_ini_get_attr_visibility(void *data, int type) |
| 5059 | { |
| 5060 | umode_t rc = 0; |
| 5061 | |
| 5062 | switch (type) { |
| 5063 | case ISCSI_BOOT_INI_INITIATOR_NAME: |
| 5064 | rc = S_IRUGO; |
| 5065 | break; |
| 5066 | } |
| 5067 | return rc; |
| 5068 | } |
| 5069 | |
Jitendra Bhivare | 50a4b82 | 2016-08-19 15:20:12 +0530 | [diff] [blame] | 5070 | static umode_t beiscsi_eth_get_attr_visibility(void *data, int type) |
| 5071 | { |
| 5072 | umode_t rc = 0; |
| 5073 | |
| 5074 | switch (type) { |
| 5075 | case ISCSI_BOOT_ETH_FLAGS: |
| 5076 | case ISCSI_BOOT_ETH_MAC: |
| 5077 | case ISCSI_BOOT_ETH_INDEX: |
| 5078 | rc = S_IRUGO; |
| 5079 | break; |
| 5080 | } |
| 5081 | return rc; |
| 5082 | } |
| 5083 | |
| 5084 | static void beiscsi_boot_kobj_release(void *data) |
| 5085 | { |
| 5086 | struct beiscsi_hba *phba = data; |
| 5087 | |
| 5088 | scsi_host_put(phba->shost); |
| 5089 | } |
| 5090 | |
| 5091 | static int beiscsi_boot_create_kset(struct beiscsi_hba *phba) |
| 5092 | { |
| 5093 | struct boot_struct *bs = &phba->boot_struct; |
| 5094 | struct iscsi_boot_kobj *boot_kobj; |
| 5095 | |
| 5096 | if (bs->boot_kset) { |
| 5097 | __beiscsi_log(phba, KERN_ERR, |
| 5098 | "BM_%d: boot_kset already created\n"); |
| 5099 | return 0; |
| 5100 | } |
| 5101 | |
| 5102 | bs->boot_kset = iscsi_boot_create_host_kset(phba->shost->host_no); |
| 5103 | if (!bs->boot_kset) { |
| 5104 | __beiscsi_log(phba, KERN_ERR, |
| 5105 | "BM_%d: boot_kset alloc failed\n"); |
| 5106 | return -ENOMEM; |
| 5107 | } |
| 5108 | |
| 5109 | /* get shost ref because the show function will refer phba */ |
| 5110 | if (!scsi_host_get(phba->shost)) |
| 5111 | goto free_kset; |
| 5112 | |
| 5113 | boot_kobj = iscsi_boot_create_target(bs->boot_kset, 0, phba, |
| 5114 | beiscsi_show_boot_tgt_info, |
| 5115 | beiscsi_tgt_get_attr_visibility, |
| 5116 | beiscsi_boot_kobj_release); |
| 5117 | if (!boot_kobj) |
| 5118 | goto put_shost; |
| 5119 | |
| 5120 | if (!scsi_host_get(phba->shost)) |
| 5121 | goto free_kset; |
| 5122 | |
| 5123 | boot_kobj = iscsi_boot_create_initiator(bs->boot_kset, 0, phba, |
| 5124 | beiscsi_show_boot_ini_info, |
| 5125 | beiscsi_ini_get_attr_visibility, |
| 5126 | beiscsi_boot_kobj_release); |
| 5127 | if (!boot_kobj) |
| 5128 | goto put_shost; |
| 5129 | |
| 5130 | if (!scsi_host_get(phba->shost)) |
| 5131 | goto free_kset; |
| 5132 | |
| 5133 | boot_kobj = iscsi_boot_create_ethernet(bs->boot_kset, 0, phba, |
| 5134 | beiscsi_show_boot_eth_info, |
| 5135 | beiscsi_eth_get_attr_visibility, |
| 5136 | beiscsi_boot_kobj_release); |
| 5137 | if (!boot_kobj) |
| 5138 | goto put_shost; |
| 5139 | |
| 5140 | return 0; |
| 5141 | |
| 5142 | put_shost: |
| 5143 | scsi_host_put(phba->shost); |
| 5144 | free_kset: |
| 5145 | iscsi_boot_destroy_kset(bs->boot_kset); |
| 5146 | bs->boot_kset = NULL; |
| 5147 | return -ENOMEM; |
| 5148 | } |
| 5149 | |
| 5150 | static void beiscsi_boot_work(struct work_struct *work) |
| 5151 | { |
| 5152 | struct beiscsi_hba *phba = |
| 5153 | container_of(work, struct beiscsi_hba, boot_work); |
| 5154 | struct boot_struct *bs = &phba->boot_struct; |
| 5155 | unsigned int tag = 0; |
| 5156 | |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5157 | if (!beiscsi_hba_is_online(phba)) |
Jitendra Bhivare | 50a4b82 | 2016-08-19 15:20:12 +0530 | [diff] [blame] | 5158 | return; |
| 5159 | |
| 5160 | beiscsi_log(phba, KERN_INFO, |
| 5161 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX, |
| 5162 | "BM_%d : %s action %d\n", |
| 5163 | __func__, phba->boot_struct.action); |
| 5164 | |
| 5165 | switch (phba->boot_struct.action) { |
| 5166 | case BEISCSI_BOOT_REOPEN_SESS: |
| 5167 | tag = beiscsi_boot_reopen_sess(phba); |
| 5168 | break; |
| 5169 | case BEISCSI_BOOT_GET_SHANDLE: |
| 5170 | tag = __beiscsi_boot_get_shandle(phba, 1); |
| 5171 | break; |
| 5172 | case BEISCSI_BOOT_GET_SINFO: |
| 5173 | tag = beiscsi_boot_get_sinfo(phba); |
| 5174 | break; |
| 5175 | case BEISCSI_BOOT_LOGOUT_SESS: |
| 5176 | tag = beiscsi_boot_logout_sess(phba); |
| 5177 | break; |
| 5178 | case BEISCSI_BOOT_CREATE_KSET: |
| 5179 | beiscsi_boot_create_kset(phba); |
| 5180 | /** |
| 5181 | * updated boot_kset is made visible to all before |
| 5182 | * ending the boot work. |
| 5183 | */ |
| 5184 | mb(); |
| 5185 | clear_bit(BEISCSI_HBA_BOOT_WORK, &phba->state); |
| 5186 | return; |
| 5187 | } |
| 5188 | if (!tag) { |
| 5189 | if (bs->retry--) |
| 5190 | schedule_work(&phba->boot_work); |
| 5191 | else |
| 5192 | clear_bit(BEISCSI_HBA_BOOT_WORK, &phba->state); |
| 5193 | } |
| 5194 | } |
| 5195 | |
Jitendra Bhivare | 10bcd47 | 2016-08-19 15:20:13 +0530 | [diff] [blame] | 5196 | static void beiscsi_eqd_update_work(struct work_struct *work) |
| 5197 | { |
| 5198 | struct hwi_context_memory *phwi_context; |
| 5199 | struct be_set_eqd set_eqd[MAX_CPUS]; |
| 5200 | struct hwi_controller *phwi_ctrlr; |
| 5201 | struct be_eq_obj *pbe_eq; |
| 5202 | struct beiscsi_hba *phba; |
| 5203 | unsigned int pps, delta; |
| 5204 | struct be_aic_obj *aic; |
| 5205 | int eqd, i, num = 0; |
| 5206 | unsigned long now; |
| 5207 | |
| 5208 | phba = container_of(work, struct beiscsi_hba, eqd_update.work); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5209 | if (!beiscsi_hba_is_online(phba)) |
Jitendra Bhivare | 9122e99 | 2016-08-19 15:20:11 +0530 | [diff] [blame] | 5210 | return; |
| 5211 | |
Jayamohan Kallickal | 73af08e | 2014-05-05 21:41:26 -0400 | [diff] [blame] | 5212 | phwi_ctrlr = phba->phwi_ctrlr; |
| 5213 | phwi_context = phwi_ctrlr->phwi_ctxt; |
| 5214 | |
| 5215 | for (i = 0; i <= phba->num_cpus; i++) { |
| 5216 | aic = &phba->aic_obj[i]; |
| 5217 | pbe_eq = &phwi_context->be_eq[i]; |
| 5218 | now = jiffies; |
Jitendra Bhivare | 10bcd47 | 2016-08-19 15:20:13 +0530 | [diff] [blame] | 5219 | if (!aic->jiffies || time_before(now, aic->jiffies) || |
Jayamohan Kallickal | 73af08e | 2014-05-05 21:41:26 -0400 | [diff] [blame] | 5220 | pbe_eq->cq_count < aic->eq_prev) { |
Jitendra Bhivare | 10bcd47 | 2016-08-19 15:20:13 +0530 | [diff] [blame] | 5221 | aic->jiffies = now; |
Jayamohan Kallickal | 73af08e | 2014-05-05 21:41:26 -0400 | [diff] [blame] | 5222 | aic->eq_prev = pbe_eq->cq_count; |
| 5223 | continue; |
| 5224 | } |
Jitendra Bhivare | 10bcd47 | 2016-08-19 15:20:13 +0530 | [diff] [blame] | 5225 | delta = jiffies_to_msecs(now - aic->jiffies); |
Jayamohan Kallickal | 73af08e | 2014-05-05 21:41:26 -0400 | [diff] [blame] | 5226 | pps = (((u32)(pbe_eq->cq_count - aic->eq_prev) * 1000) / delta); |
| 5227 | eqd = (pps / 1500) << 2; |
| 5228 | |
| 5229 | if (eqd < 8) |
| 5230 | eqd = 0; |
Jitendra Bhivare | 45efc940 | 2017-10-10 16:18:18 +0530 | [diff] [blame] | 5231 | eqd = min_t(u32, eqd, BEISCSI_EQ_DELAY_MAX); |
| 5232 | eqd = max_t(u32, eqd, BEISCSI_EQ_DELAY_MIN); |
Jayamohan Kallickal | 73af08e | 2014-05-05 21:41:26 -0400 | [diff] [blame] | 5233 | |
Jitendra Bhivare | 10bcd47 | 2016-08-19 15:20:13 +0530 | [diff] [blame] | 5234 | aic->jiffies = now; |
Jayamohan Kallickal | 73af08e | 2014-05-05 21:41:26 -0400 | [diff] [blame] | 5235 | aic->eq_prev = pbe_eq->cq_count; |
| 5236 | |
| 5237 | if (eqd != aic->prev_eqd) { |
| 5238 | set_eqd[num].delay_multiplier = (eqd * 65)/100; |
| 5239 | set_eqd[num].eq_id = pbe_eq->q.id; |
| 5240 | aic->prev_eqd = eqd; |
| 5241 | num++; |
| 5242 | } |
| 5243 | } |
Jitendra Bhivare | 10bcd47 | 2016-08-19 15:20:13 +0530 | [diff] [blame] | 5244 | if (num) |
| 5245 | /* completion of this is ignored */ |
| 5246 | beiscsi_modify_eq_delay(phba, set_eqd, num); |
Jayamohan Kallickal | 73af08e | 2014-05-05 21:41:26 -0400 | [diff] [blame] | 5247 | |
Jitendra Bhivare | 10bcd47 | 2016-08-19 15:20:13 +0530 | [diff] [blame] | 5248 | schedule_delayed_work(&phba->eqd_update, |
| 5249 | msecs_to_jiffies(BEISCSI_EQD_UPDATE_INTERVAL)); |
John Soni Jose | 7a15800 | 2012-10-20 04:45:51 +0530 | [diff] [blame] | 5250 | } |
| 5251 | |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5252 | static void beiscsi_hw_tpe_check(unsigned long ptr) |
| 5253 | { |
| 5254 | struct beiscsi_hba *phba; |
| 5255 | u32 wait; |
| 5256 | |
| 5257 | phba = (struct beiscsi_hba *)ptr; |
| 5258 | /* if not TPE, do nothing */ |
| 5259 | if (!beiscsi_detect_tpe(phba)) |
| 5260 | return; |
| 5261 | |
| 5262 | /* wait default 4000ms before recovering */ |
| 5263 | wait = 4000; |
| 5264 | if (phba->ue2rp > BEISCSI_UE_DETECT_INTERVAL) |
| 5265 | wait = phba->ue2rp - BEISCSI_UE_DETECT_INTERVAL; |
| 5266 | queue_delayed_work(phba->wq, &phba->recover_port, |
| 5267 | msecs_to_jiffies(wait)); |
| 5268 | } |
| 5269 | |
| 5270 | static void beiscsi_hw_health_check(unsigned long ptr) |
| 5271 | { |
| 5272 | struct beiscsi_hba *phba; |
| 5273 | |
| 5274 | phba = (struct beiscsi_hba *)ptr; |
| 5275 | beiscsi_detect_ue(phba); |
| 5276 | if (beiscsi_detect_ue(phba)) { |
| 5277 | __beiscsi_log(phba, KERN_ERR, |
| 5278 | "BM_%d : port in error: %lx\n", phba->state); |
Jitendra Bhivare | 10e1a44 | 2016-08-19 15:20:19 +0530 | [diff] [blame] | 5279 | /* sessions are no longer valid, so first fail the sessions */ |
| 5280 | queue_work(phba->wq, &phba->sess_work); |
| 5281 | |
| 5282 | /* detect UER supported */ |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5283 | if (!test_bit(BEISCSI_HBA_UER_SUPP, &phba->state)) |
| 5284 | return; |
| 5285 | /* modify this timer to check TPE */ |
| 5286 | phba->hw_check.function = beiscsi_hw_tpe_check; |
| 5287 | } |
| 5288 | |
| 5289 | mod_timer(&phba->hw_check, |
| 5290 | jiffies + msecs_to_jiffies(BEISCSI_UE_DETECT_INTERVAL)); |
| 5291 | } |
| 5292 | |
| 5293 | /* |
| 5294 | * beiscsi_enable_port()- Enables the disabled port. |
| 5295 | * Only port resources freed in disable function are reallocated. |
| 5296 | * This is called in HBA error handling path. |
| 5297 | * |
| 5298 | * @phba: Instance of driver private structure |
| 5299 | * |
| 5300 | **/ |
| 5301 | static int beiscsi_enable_port(struct beiscsi_hba *phba) |
| 5302 | { |
| 5303 | struct hwi_context_memory *phwi_context; |
| 5304 | struct hwi_controller *phwi_ctrlr; |
| 5305 | struct be_eq_obj *pbe_eq; |
| 5306 | int ret, i; |
| 5307 | |
| 5308 | if (test_bit(BEISCSI_HBA_ONLINE, &phba->state)) { |
| 5309 | __beiscsi_log(phba, KERN_ERR, |
| 5310 | "BM_%d : %s : port is online %lx\n", |
| 5311 | __func__, phba->state); |
| 5312 | return 0; |
| 5313 | } |
| 5314 | |
| 5315 | ret = beiscsi_init_sliport(phba); |
| 5316 | if (ret) |
| 5317 | return ret; |
| 5318 | |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 5319 | be2iscsi_enable_msix(phba); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5320 | |
| 5321 | beiscsi_get_params(phba); |
Jitendra Bhivare | 1cb3c3f | 2017-10-10 16:18:17 +0530 | [diff] [blame] | 5322 | beiscsi_set_host_data(phba); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5323 | /* Re-enable UER. If different TPE occurs then it is recoverable. */ |
| 5324 | beiscsi_set_uer_feature(phba); |
| 5325 | |
| 5326 | phba->shost->max_id = phba->params.cxns_per_ctrl; |
| 5327 | phba->shost->can_queue = phba->params.ios_per_ctrl; |
Jitendra Bhivare | dd94097 | 2016-12-13 15:56:04 +0530 | [diff] [blame] | 5328 | ret = beiscsi_init_port(phba); |
| 5329 | if (ret < 0) { |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5330 | __beiscsi_log(phba, KERN_ERR, |
Jitendra Bhivare | dd94097 | 2016-12-13 15:56:04 +0530 | [diff] [blame] | 5331 | "BM_%d : init port failed\n"); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5332 | goto disable_msix; |
| 5333 | } |
| 5334 | |
| 5335 | for (i = 0; i < MAX_MCC_CMD; i++) { |
| 5336 | init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]); |
| 5337 | phba->ctrl.mcc_tag[i] = i + 1; |
| 5338 | phba->ctrl.mcc_tag_status[i + 1] = 0; |
| 5339 | phba->ctrl.mcc_tag_available++; |
| 5340 | } |
| 5341 | |
| 5342 | phwi_ctrlr = phba->phwi_ctrlr; |
| 5343 | phwi_context = phwi_ctrlr->phwi_ctxt; |
| 5344 | for (i = 0; i < phba->num_cpus; i++) { |
| 5345 | pbe_eq = &phwi_context->be_eq[i]; |
| 5346 | irq_poll_init(&pbe_eq->iopoll, be_iopoll_budget, be_iopoll); |
| 5347 | } |
| 5348 | |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 5349 | i = (phba->pcidev->msix_enabled) ? i : 0; |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5350 | /* Work item for MCC handling */ |
| 5351 | pbe_eq = &phwi_context->be_eq[i]; |
| 5352 | INIT_WORK(&pbe_eq->mcc_work, beiscsi_mcc_work); |
| 5353 | |
| 5354 | ret = beiscsi_init_irqs(phba); |
| 5355 | if (ret < 0) { |
| 5356 | __beiscsi_log(phba, KERN_ERR, |
| 5357 | "BM_%d : setup IRQs failed %d\n", ret); |
| 5358 | goto cleanup_port; |
| 5359 | } |
| 5360 | hwi_enable_intr(phba); |
| 5361 | /* port operational: clear all error bits */ |
| 5362 | set_bit(BEISCSI_HBA_ONLINE, &phba->state); |
| 5363 | __beiscsi_log(phba, KERN_INFO, |
| 5364 | "BM_%d : port online: 0x%lx\n", phba->state); |
| 5365 | |
| 5366 | /* start hw_check timer and eqd_update work */ |
| 5367 | schedule_delayed_work(&phba->eqd_update, |
| 5368 | msecs_to_jiffies(BEISCSI_EQD_UPDATE_INTERVAL)); |
| 5369 | |
| 5370 | /** |
| 5371 | * Timer function gets modified for TPE detection. |
| 5372 | * Always reinit to do health check first. |
| 5373 | */ |
| 5374 | phba->hw_check.function = beiscsi_hw_health_check; |
| 5375 | mod_timer(&phba->hw_check, |
| 5376 | jiffies + msecs_to_jiffies(BEISCSI_UE_DETECT_INTERVAL)); |
| 5377 | return 0; |
| 5378 | |
| 5379 | cleanup_port: |
| 5380 | for (i = 0; i < phba->num_cpus; i++) { |
| 5381 | pbe_eq = &phwi_context->be_eq[i]; |
| 5382 | irq_poll_disable(&pbe_eq->iopoll); |
| 5383 | } |
| 5384 | hwi_cleanup_port(phba); |
| 5385 | |
| 5386 | disable_msix: |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 5387 | pci_free_irq_vectors(phba->pcidev); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5388 | return ret; |
| 5389 | } |
| 5390 | |
| 5391 | /* |
| 5392 | * beiscsi_disable_port()- Disable port and cleanup driver resources. |
| 5393 | * This is called in HBA error handling and driver removal. |
| 5394 | * @phba: Instance Priv structure |
| 5395 | * @unload: indicate driver is unloading |
| 5396 | * |
| 5397 | * Free the OS and HW resources held by the driver |
| 5398 | **/ |
| 5399 | static void beiscsi_disable_port(struct beiscsi_hba *phba, int unload) |
| 5400 | { |
| 5401 | struct hwi_context_memory *phwi_context; |
| 5402 | struct hwi_controller *phwi_ctrlr; |
| 5403 | struct be_eq_obj *pbe_eq; |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 5404 | unsigned int i; |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5405 | |
| 5406 | if (!test_and_clear_bit(BEISCSI_HBA_ONLINE, &phba->state)) |
| 5407 | return; |
| 5408 | |
| 5409 | phwi_ctrlr = phba->phwi_ctrlr; |
| 5410 | phwi_context = phwi_ctrlr->phwi_ctxt; |
| 5411 | hwi_disable_intr(phba); |
Jitendra Bhivare | 45371aa | 2017-10-10 16:18:13 +0530 | [diff] [blame] | 5412 | beiscsi_free_irqs(phba); |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 5413 | pci_free_irq_vectors(phba->pcidev); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5414 | |
| 5415 | for (i = 0; i < phba->num_cpus; i++) { |
| 5416 | pbe_eq = &phwi_context->be_eq[i]; |
| 5417 | irq_poll_disable(&pbe_eq->iopoll); |
| 5418 | } |
| 5419 | cancel_delayed_work_sync(&phba->eqd_update); |
| 5420 | cancel_work_sync(&phba->boot_work); |
| 5421 | /* WQ might be running cancel queued mcc_work if we are not exiting */ |
| 5422 | if (!unload && beiscsi_hba_in_error(phba)) { |
| 5423 | pbe_eq = &phwi_context->be_eq[i]; |
| 5424 | cancel_work_sync(&pbe_eq->mcc_work); |
| 5425 | } |
| 5426 | hwi_cleanup_port(phba); |
Jitendra Bhivare | dd94097 | 2016-12-13 15:56:04 +0530 | [diff] [blame] | 5427 | beiscsi_cleanup_port(phba); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5428 | } |
| 5429 | |
Jitendra Bhivare | 10e1a44 | 2016-08-19 15:20:19 +0530 | [diff] [blame] | 5430 | static void beiscsi_sess_work(struct work_struct *work) |
| 5431 | { |
| 5432 | struct beiscsi_hba *phba; |
| 5433 | |
| 5434 | phba = container_of(work, struct beiscsi_hba, sess_work); |
| 5435 | /* |
| 5436 | * This work gets scheduled only in case of HBA error. |
| 5437 | * Old sessions are gone so need to be re-established. |
| 5438 | * iscsi_session_failure needs process context hence this work. |
| 5439 | */ |
| 5440 | iscsi_host_for_each_session(phba->shost, beiscsi_session_fail); |
| 5441 | } |
| 5442 | |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5443 | static void beiscsi_recover_port(struct work_struct *work) |
| 5444 | { |
| 5445 | struct beiscsi_hba *phba; |
| 5446 | |
| 5447 | phba = container_of(work, struct beiscsi_hba, recover_port.work); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5448 | beiscsi_disable_port(phba, 0); |
| 5449 | beiscsi_enable_port(phba); |
| 5450 | } |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5451 | |
| 5452 | static pci_ers_result_t beiscsi_eeh_err_detected(struct pci_dev *pdev, |
| 5453 | pci_channel_state_t state) |
| 5454 | { |
| 5455 | struct beiscsi_hba *phba = NULL; |
| 5456 | |
| 5457 | phba = (struct beiscsi_hba *)pci_get_drvdata(pdev); |
Jitendra Bhivare | 9122e99 | 2016-08-19 15:20:11 +0530 | [diff] [blame] | 5458 | set_bit(BEISCSI_HBA_PCI_ERR, &phba->state); |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5459 | |
| 5460 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5461 | "BM_%d : EEH error detected\n"); |
| 5462 | |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5463 | /* first stop UE detection when PCI error detected */ |
| 5464 | del_timer_sync(&phba->hw_check); |
| 5465 | cancel_delayed_work_sync(&phba->recover_port); |
| 5466 | |
Jitendra Bhivare | 10e1a44 | 2016-08-19 15:20:19 +0530 | [diff] [blame] | 5467 | /* sessions are no longer valid, so first fail the sessions */ |
| 5468 | iscsi_host_for_each_session(phba->shost, beiscsi_session_fail); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5469 | beiscsi_disable_port(phba, 0); |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5470 | |
| 5471 | if (state == pci_channel_io_perm_failure) { |
| 5472 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5473 | "BM_%d : EEH : State PERM Failure"); |
| 5474 | return PCI_ERS_RESULT_DISCONNECT; |
| 5475 | } |
| 5476 | |
| 5477 | pci_disable_device(pdev); |
| 5478 | |
| 5479 | /* The error could cause the FW to trigger a flash debug dump. |
| 5480 | * Resetting the card while flash dump is in progress |
| 5481 | * can cause it not to recover; wait for it to finish. |
| 5482 | * Wait only for first function as it is needed only once per |
| 5483 | * adapter. |
| 5484 | **/ |
| 5485 | if (pdev->devfn == 0) |
| 5486 | ssleep(30); |
| 5487 | |
| 5488 | return PCI_ERS_RESULT_NEED_RESET; |
| 5489 | } |
| 5490 | |
| 5491 | static pci_ers_result_t beiscsi_eeh_reset(struct pci_dev *pdev) |
| 5492 | { |
| 5493 | struct beiscsi_hba *phba = NULL; |
| 5494 | int status = 0; |
| 5495 | |
| 5496 | phba = (struct beiscsi_hba *)pci_get_drvdata(pdev); |
| 5497 | |
| 5498 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5499 | "BM_%d : EEH Reset\n"); |
| 5500 | |
| 5501 | status = pci_enable_device(pdev); |
| 5502 | if (status) |
| 5503 | return PCI_ERS_RESULT_DISCONNECT; |
| 5504 | |
| 5505 | pci_set_master(pdev); |
| 5506 | pci_set_power_state(pdev, PCI_D0); |
| 5507 | pci_restore_state(pdev); |
| 5508 | |
Jitendra Bhivare | 4d2ee1e | 2016-08-19 15:20:16 +0530 | [diff] [blame] | 5509 | status = beiscsi_check_fw_rdy(phba); |
| 5510 | if (status) { |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5511 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT, |
| 5512 | "BM_%d : EEH Reset Completed\n"); |
| 5513 | } else { |
| 5514 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT, |
| 5515 | "BM_%d : EEH Reset Completion Failure\n"); |
| 5516 | return PCI_ERS_RESULT_DISCONNECT; |
| 5517 | } |
| 5518 | |
| 5519 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 5520 | return PCI_ERS_RESULT_RECOVERED; |
| 5521 | } |
| 5522 | |
| 5523 | static void beiscsi_eeh_resume(struct pci_dev *pdev) |
| 5524 | { |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5525 | struct beiscsi_hba *phba; |
| 5526 | int ret; |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5527 | |
| 5528 | phba = (struct beiscsi_hba *)pci_get_drvdata(pdev); |
| 5529 | pci_save_state(pdev); |
| 5530 | |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5531 | ret = beiscsi_enable_port(phba); |
Jitendra Bhivare | 4d2ee1e | 2016-08-19 15:20:16 +0530 | [diff] [blame] | 5532 | if (ret) |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5533 | __beiscsi_log(phba, KERN_ERR, |
| 5534 | "BM_%d : AER EEH resume failed\n"); |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5535 | } |
| 5536 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5537 | static int beiscsi_dev_probe(struct pci_dev *pcidev, |
| 5538 | const struct pci_device_id *id) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5539 | { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5540 | struct hwi_context_memory *phwi_context; |
Jitendra Bhivare | 29e80b7 | 2016-12-13 15:56:02 +0530 | [diff] [blame] | 5541 | struct hwi_controller *phwi_ctrlr; |
| 5542 | struct beiscsi_hba *phba = NULL; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5543 | struct be_eq_obj *pbe_eq; |
Jitendra Bhivare | 50a4b82 | 2016-08-19 15:20:12 +0530 | [diff] [blame] | 5544 | unsigned int s_handle; |
Jitendra Bhivare | 29e80b7 | 2016-12-13 15:56:02 +0530 | [diff] [blame] | 5545 | char wq_name[20]; |
Christophe JAILLET | deeea8e | 2016-08-26 15:09:06 +0530 | [diff] [blame] | 5546 | int ret, i; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5547 | |
| 5548 | ret = beiscsi_enable_pci(pcidev); |
| 5549 | if (ret < 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5550 | dev_err(&pcidev->dev, |
| 5551 | "beiscsi_dev_probe - Failed to enable pci device\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5552 | return ret; |
| 5553 | } |
| 5554 | |
| 5555 | phba = beiscsi_hba_alloc(pcidev); |
| 5556 | if (!phba) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5557 | dev_err(&pcidev->dev, |
| 5558 | "beiscsi_dev_probe - Failed in beiscsi_hba_alloc\n"); |
Christophe JAILLET | deeea8e | 2016-08-26 15:09:06 +0530 | [diff] [blame] | 5559 | ret = -ENOMEM; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5560 | goto disable_pci; |
| 5561 | } |
| 5562 | |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5563 | /* Enable EEH reporting */ |
| 5564 | ret = pci_enable_pcie_error_reporting(pcidev); |
| 5565 | if (ret) |
| 5566 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT, |
| 5567 | "BM_%d : PCIe Error Reporting " |
| 5568 | "Enabling Failed\n"); |
| 5569 | |
| 5570 | pci_save_state(pcidev); |
| 5571 | |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5572 | /* Initialize Driver configuration Paramters */ |
| 5573 | beiscsi_hba_attrs_init(phba); |
| 5574 | |
Jayamohan Kallickal | 6c83185 | 2013-09-28 15:35:40 -0700 | [diff] [blame] | 5575 | phba->mac_addr_set = false; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 5576 | |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 5577 | switch (pcidev->device) { |
| 5578 | case BE_DEVICE_ID1: |
| 5579 | case OC_DEVICE_ID1: |
| 5580 | case OC_DEVICE_ID2: |
| 5581 | phba->generation = BE_GEN2; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5582 | phba->iotask_fn = beiscsi_iotask; |
Ketan Mukadam | 5fa7db2 | 2016-12-13 15:56:05 +0530 | [diff] [blame] | 5583 | dev_warn(&pcidev->dev, |
| 5584 | "Obsolete/Unsupported BE2 Adapter Family\n"); |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 5585 | break; |
| 5586 | case BE_DEVICE_ID2: |
| 5587 | case OC_DEVICE_ID3: |
| 5588 | phba->generation = BE_GEN3; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5589 | phba->iotask_fn = beiscsi_iotask; |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 5590 | break; |
John Soni Jose | 139a1b1 | 2012-10-20 04:43:20 +0530 | [diff] [blame] | 5591 | case OC_SKH_ID1: |
| 5592 | phba->generation = BE_GEN4; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5593 | phba->iotask_fn = beiscsi_iotask_v2; |
Jayamohan Kallickal | bf9131c | 2013-04-05 20:38:24 -0700 | [diff] [blame] | 5594 | break; |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 5595 | default: |
| 5596 | phba->generation = 0; |
| 5597 | } |
| 5598 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5599 | ret = be_ctrl_init(phba, pcidev); |
| 5600 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5601 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
Jitendra Bhivare | 4d2ee1e | 2016-08-19 15:20:16 +0530 | [diff] [blame] | 5602 | "BM_%d : be_ctrl_init failed\n"); |
Jitendra Bhivare | 45371aa | 2017-10-10 16:18:13 +0530 | [diff] [blame] | 5603 | goto free_hba; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5604 | } |
| 5605 | |
Jitendra Bhivare | 4d2ee1e | 2016-08-19 15:20:16 +0530 | [diff] [blame] | 5606 | ret = beiscsi_init_sliport(phba); |
| 5607 | if (ret) |
Jitendra Bhivare | 45371aa | 2017-10-10 16:18:13 +0530 | [diff] [blame] | 5608 | goto free_hba; |
Jitendra Bhivare | 4d2ee1e | 2016-08-19 15:20:16 +0530 | [diff] [blame] | 5609 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5610 | spin_lock_init(&phba->io_sgl_lock); |
| 5611 | spin_lock_init(&phba->mgmt_sgl_lock); |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 5612 | spin_lock_init(&phba->async_pdu_lock); |
Jitendra Bhivare | 480195c | 2016-08-19 15:20:15 +0530 | [diff] [blame] | 5613 | ret = beiscsi_get_fw_config(&phba->ctrl, phba); |
Jayamohan Kallickal | 7da5087 | 2010-01-05 05:04:12 +0530 | [diff] [blame] | 5614 | if (ret != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5615 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5616 | "BM_%d : Error getting fw config\n"); |
Jayamohan Kallickal | 7da5087 | 2010-01-05 05:04:12 +0530 | [diff] [blame] | 5617 | goto free_port; |
| 5618 | } |
Jitendra Bhivare | 480195c | 2016-08-19 15:20:15 +0530 | [diff] [blame] | 5619 | beiscsi_get_port_name(&phba->ctrl, phba); |
Jitendra Bhivare | 4570f16 | 2016-01-20 14:10:54 +0530 | [diff] [blame] | 5620 | beiscsi_get_params(phba); |
Jitendra Bhivare | 1cb3c3f | 2017-10-10 16:18:17 +0530 | [diff] [blame] | 5621 | beiscsi_set_host_data(phba); |
Jitendra Bhivare | 6694095 | 2016-08-19 15:20:14 +0530 | [diff] [blame] | 5622 | beiscsi_set_uer_feature(phba); |
Jayamohan Kallickal | 68c26a3 | 2013-09-28 15:35:54 -0700 | [diff] [blame] | 5623 | |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 5624 | be2iscsi_enable_msix(phba); |
Jayamohan Kallickal | 68c26a3 | 2013-09-28 15:35:54 -0700 | [diff] [blame] | 5625 | |
| 5626 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 5627 | "BM_%d : num_cpus = %d\n", |
| 5628 | phba->num_cpus); |
| 5629 | |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 5630 | phba->shost->max_id = phba->params.cxns_per_ctrl; |
Jayamohan Kallickal | aa874f0 | 2010-01-05 05:12:03 +0530 | [diff] [blame] | 5631 | phba->shost->can_queue = phba->params.ios_per_ctrl; |
Jitendra Bhivare | dd94097 | 2016-12-13 15:56:04 +0530 | [diff] [blame] | 5632 | ret = beiscsi_get_memory(phba); |
| 5633 | if (ret < 0) { |
| 5634 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5635 | "BM_%d : alloc host mem failed\n"); |
| 5636 | goto free_port; |
| 5637 | } |
| 5638 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5639 | ret = beiscsi_init_port(phba); |
| 5640 | if (ret < 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5641 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
Jitendra Bhivare | dd94097 | 2016-12-13 15:56:04 +0530 | [diff] [blame] | 5642 | "BM_%d : init port failed\n"); |
| 5643 | beiscsi_free_mem(phba); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5644 | goto free_port; |
| 5645 | } |
| 5646 | |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5647 | for (i = 0; i < MAX_MCC_CMD; i++) { |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 5648 | init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]); |
| 5649 | phba->ctrl.mcc_tag[i] = i + 1; |
Jitendra Bhivare | 67296ad | 2016-02-04 15:49:10 +0530 | [diff] [blame] | 5650 | phba->ctrl.mcc_tag_status[i + 1] = 0; |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 5651 | phba->ctrl.mcc_tag_available++; |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 5652 | memset(&phba->ctrl.ptag_state[i].tag_mem_state, 0, |
Jayamohan Kallickal | 8fc01ea | 2014-05-05 21:41:28 -0400 | [diff] [blame] | 5653 | sizeof(struct be_dma_mem)); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 5654 | } |
| 5655 | |
| 5656 | phba->ctrl.mcc_alloc_index = phba->ctrl.mcc_free_index = 0; |
| 5657 | |
Jitendra Bhivare | 29e80b7 | 2016-12-13 15:56:02 +0530 | [diff] [blame] | 5658 | snprintf(wq_name, sizeof(wq_name), "beiscsi_%02x_wq", |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5659 | phba->shost->host_no); |
Jitendra Bhivare | 29e80b7 | 2016-12-13 15:56:02 +0530 | [diff] [blame] | 5660 | phba->wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 1, wq_name); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5661 | if (!phba->wq) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5662 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5663 | "BM_%d : beiscsi_dev_probe-" |
| 5664 | "Failed to allocate work queue\n"); |
Christophe JAILLET | deeea8e | 2016-08-26 15:09:06 +0530 | [diff] [blame] | 5665 | ret = -ENOMEM; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5666 | goto free_twq; |
| 5667 | } |
| 5668 | |
Jitendra Bhivare | 10bcd47 | 2016-08-19 15:20:13 +0530 | [diff] [blame] | 5669 | INIT_DELAYED_WORK(&phba->eqd_update, beiscsi_eqd_update_work); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5670 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5671 | phwi_ctrlr = phba->phwi_ctrlr; |
| 5672 | phwi_context = phwi_ctrlr->phwi_ctxt; |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 5673 | |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5674 | for (i = 0; i < phba->num_cpus; i++) { |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 5675 | pbe_eq = &phwi_context->be_eq[i]; |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5676 | irq_poll_init(&pbe_eq->iopoll, be_iopoll_budget, be_iopoll); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5677 | } |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 5678 | |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 5679 | i = (phba->pcidev->msix_enabled) ? i : 0; |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5680 | /* Work item for MCC handling */ |
| 5681 | pbe_eq = &phwi_context->be_eq[i]; |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 5682 | INIT_WORK(&pbe_eq->mcc_work, beiscsi_mcc_work); |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5683 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5684 | ret = beiscsi_init_irqs(phba); |
| 5685 | if (ret < 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5686 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5687 | "BM_%d : beiscsi_dev_probe-" |
| 5688 | "Failed to beiscsi_init_irqs\n"); |
Jitendra Bhivare | 45371aa | 2017-10-10 16:18:13 +0530 | [diff] [blame] | 5689 | goto disable_iopoll; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5690 | } |
Jayamohan Kallickal | 238f6b7 | 2010-07-22 04:23:22 +0530 | [diff] [blame] | 5691 | hwi_enable_intr(phba); |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 5692 | |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5693 | ret = iscsi_host_add(phba->shost, &phba->pcidev->dev); |
| 5694 | if (ret) |
Jitendra Bhivare | 45371aa | 2017-10-10 16:18:13 +0530 | [diff] [blame] | 5695 | goto free_irqs; |
Jayamohan Kallickal | 0598b8a | 2014-05-05 21:41:25 -0400 | [diff] [blame] | 5696 | |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5697 | /* set online bit after port is operational */ |
| 5698 | set_bit(BEISCSI_HBA_ONLINE, &phba->state); |
| 5699 | __beiscsi_log(phba, KERN_INFO, |
| 5700 | "BM_%d : port online: 0x%lx\n", phba->state); |
| 5701 | |
Jitendra Bhivare | 50a4b82 | 2016-08-19 15:20:12 +0530 | [diff] [blame] | 5702 | INIT_WORK(&phba->boot_work, beiscsi_boot_work); |
| 5703 | ret = beiscsi_boot_get_shandle(phba, &s_handle); |
| 5704 | if (ret > 0) { |
| 5705 | beiscsi_start_boot_work(phba, s_handle); |
| 5706 | /** |
| 5707 | * Set this bit after starting the work to let |
| 5708 | * probe handle it first. |
| 5709 | * ASYNC event can too schedule this work. |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 5710 | */ |
Jitendra Bhivare | 50a4b82 | 2016-08-19 15:20:12 +0530 | [diff] [blame] | 5711 | set_bit(BEISCSI_HBA_BOOT_FOUND, &phba->state); |
| 5712 | } |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 5713 | |
Jitendra Bhivare | 96b48b9 | 2016-08-19 15:20:06 +0530 | [diff] [blame] | 5714 | beiscsi_iface_create_default(phba); |
Jitendra Bhivare | 10bcd47 | 2016-08-19 15:20:13 +0530 | [diff] [blame] | 5715 | schedule_delayed_work(&phba->eqd_update, |
| 5716 | msecs_to_jiffies(BEISCSI_EQD_UPDATE_INTERVAL)); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5717 | |
Jitendra Bhivare | 10e1a44 | 2016-08-19 15:20:19 +0530 | [diff] [blame] | 5718 | INIT_WORK(&phba->sess_work, beiscsi_sess_work); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5719 | INIT_DELAYED_WORK(&phba->recover_port, beiscsi_recover_port); |
Jitendra Bhivare | 10bcd47 | 2016-08-19 15:20:13 +0530 | [diff] [blame] | 5720 | /** |
| 5721 | * Start UE detection here. UE before this will cause stall in probe |
| 5722 | * and eventually fail the probe. |
| 5723 | */ |
| 5724 | init_timer(&phba->hw_check); |
| 5725 | phba->hw_check.function = beiscsi_hw_health_check; |
| 5726 | phba->hw_check.data = (unsigned long)phba; |
| 5727 | mod_timer(&phba->hw_check, |
| 5728 | jiffies + msecs_to_jiffies(BEISCSI_UE_DETECT_INTERVAL)); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5729 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 5730 | "\n\n\n BM_%d : SUCCESS - DRIVER LOADED\n\n\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5731 | return 0; |
| 5732 | |
Jitendra Bhivare | 45371aa | 2017-10-10 16:18:13 +0530 | [diff] [blame] | 5733 | free_irqs: |
| 5734 | hwi_disable_intr(phba); |
| 5735 | beiscsi_free_irqs(phba); |
| 5736 | disable_iopoll: |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5737 | for (i = 0; i < phba->num_cpus; i++) { |
| 5738 | pbe_eq = &phwi_context->be_eq[i]; |
Christoph Hellwig | 511cbce | 2015-11-10 14:56:14 +0100 | [diff] [blame] | 5739 | irq_poll_disable(&pbe_eq->iopoll); |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5740 | } |
Jitendra Bhivare | 45371aa | 2017-10-10 16:18:13 +0530 | [diff] [blame] | 5741 | destroy_workqueue(phba->wq); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5742 | free_twq: |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5743 | hwi_cleanup_port(phba); |
Jitendra Bhivare | 4d2ee1e | 2016-08-19 15:20:16 +0530 | [diff] [blame] | 5744 | beiscsi_cleanup_port(phba); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5745 | beiscsi_free_mem(phba); |
| 5746 | free_port: |
| 5747 | pci_free_consistent(phba->pcidev, |
| 5748 | phba->ctrl.mbox_mem_alloced.size, |
| 5749 | phba->ctrl.mbox_mem_alloced.va, |
Jitendra Bhivare | 45371aa | 2017-10-10 16:18:13 +0530 | [diff] [blame] | 5750 | phba->ctrl.mbox_mem_alloced.dma); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5751 | beiscsi_unmap_pci_function(phba); |
Jitendra Bhivare | 45371aa | 2017-10-10 16:18:13 +0530 | [diff] [blame] | 5752 | free_hba: |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 5753 | pci_disable_msix(phba->pcidev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5754 | pci_dev_put(phba->pcidev); |
| 5755 | iscsi_host_free(phba->shost); |
John Soni Jose | 2e7cee0 | 2015-02-12 06:45:47 +0530 | [diff] [blame] | 5756 | pci_set_drvdata(pcidev, NULL); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5757 | disable_pci: |
John Soni Jose | e307f3a | 2015-04-25 08:17:19 +0530 | [diff] [blame] | 5758 | pci_release_regions(pcidev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5759 | pci_disable_device(pcidev); |
| 5760 | return ret; |
| 5761 | } |
| 5762 | |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5763 | static void beiscsi_remove(struct pci_dev *pcidev) |
| 5764 | { |
| 5765 | struct beiscsi_hba *phba = NULL; |
| 5766 | |
| 5767 | phba = pci_get_drvdata(pcidev); |
| 5768 | if (!phba) { |
| 5769 | dev_err(&pcidev->dev, "beiscsi_remove called with no phba\n"); |
| 5770 | return; |
| 5771 | } |
| 5772 | |
| 5773 | /* first stop UE detection before unloading */ |
| 5774 | del_timer_sync(&phba->hw_check); |
| 5775 | cancel_delayed_work_sync(&phba->recover_port); |
Jitendra Bhivare | 10e1a44 | 2016-08-19 15:20:19 +0530 | [diff] [blame] | 5776 | cancel_work_sync(&phba->sess_work); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5777 | |
| 5778 | beiscsi_iface_destroy_default(phba); |
| 5779 | iscsi_host_remove(phba->shost); |
| 5780 | beiscsi_disable_port(phba, 1); |
| 5781 | |
| 5782 | /* after cancelling boot_work */ |
| 5783 | iscsi_boot_destroy_kset(phba->boot_struct.boot_kset); |
| 5784 | |
| 5785 | /* free all resources */ |
| 5786 | destroy_workqueue(phba->wq); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5787 | beiscsi_free_mem(phba); |
| 5788 | |
| 5789 | /* ctrl uninit */ |
| 5790 | beiscsi_unmap_pci_function(phba); |
| 5791 | pci_free_consistent(phba->pcidev, |
| 5792 | phba->ctrl.mbox_mem_alloced.size, |
| 5793 | phba->ctrl.mbox_mem_alloced.va, |
| 5794 | phba->ctrl.mbox_mem_alloced.dma); |
| 5795 | |
| 5796 | pci_dev_put(phba->pcidev); |
| 5797 | iscsi_host_free(phba->shost); |
| 5798 | pci_disable_pcie_error_reporting(pcidev); |
| 5799 | pci_set_drvdata(pcidev, NULL); |
| 5800 | pci_release_regions(pcidev); |
| 5801 | pci_disable_device(pcidev); |
| 5802 | } |
| 5803 | |
| 5804 | |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5805 | static struct pci_error_handlers beiscsi_eeh_handlers = { |
| 5806 | .error_detected = beiscsi_eeh_err_detected, |
| 5807 | .slot_reset = beiscsi_eeh_reset, |
| 5808 | .resume = beiscsi_eeh_resume, |
| 5809 | }; |
| 5810 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5811 | struct iscsi_transport beiscsi_iscsi_transport = { |
| 5812 | .owner = THIS_MODULE, |
| 5813 | .name = DRV_NAME, |
Jayamohan Kallickal | 9db0fb3 | 2010-01-05 05:12:43 +0530 | [diff] [blame] | 5814 | .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_TEXT_NEGO | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5815 | CAP_MULTI_R2T | CAP_DATADGST | CAP_DATA_PATH_OFFLOAD, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5816 | .create_session = beiscsi_session_create, |
| 5817 | .destroy_session = beiscsi_session_destroy, |
| 5818 | .create_conn = beiscsi_conn_create, |
| 5819 | .bind_conn = beiscsi_conn_bind, |
| 5820 | .destroy_conn = iscsi_conn_teardown, |
Jitendra Bhivare | 96b48b9 | 2016-08-19 15:20:06 +0530 | [diff] [blame] | 5821 | .attr_is_visible = beiscsi_attr_is_visible, |
| 5822 | .set_iface_param = beiscsi_iface_set_param, |
| 5823 | .get_iface_param = beiscsi_iface_get_param, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5824 | .set_param = beiscsi_set_param, |
Mike Christie | c7f7fd5 | 2011-02-16 15:04:41 -0600 | [diff] [blame] | 5825 | .get_conn_param = iscsi_conn_get_param, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5826 | .get_session_param = iscsi_session_get_param, |
| 5827 | .get_host_param = beiscsi_get_host_param, |
| 5828 | .start_conn = beiscsi_conn_start, |
Mike Christie | fa95d20 | 2010-06-09 03:30:08 -0500 | [diff] [blame] | 5829 | .stop_conn = iscsi_conn_stop, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5830 | .send_pdu = iscsi_conn_send_pdu, |
| 5831 | .xmit_task = beiscsi_task_xmit, |
| 5832 | .cleanup_task = beiscsi_cleanup_task, |
| 5833 | .alloc_pdu = beiscsi_alloc_pdu, |
| 5834 | .parse_pdu_itt = beiscsi_parse_pdu, |
| 5835 | .get_stats = beiscsi_conn_get_stats, |
Mike Christie | c7f7fd5 | 2011-02-16 15:04:41 -0600 | [diff] [blame] | 5836 | .get_ep_param = beiscsi_ep_get_param, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5837 | .ep_connect = beiscsi_ep_connect, |
| 5838 | .ep_poll = beiscsi_ep_poll, |
| 5839 | .ep_disconnect = beiscsi_ep_disconnect, |
| 5840 | .session_recovery_timedout = iscsi_session_recovery_timedout, |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 5841 | .bsg_request = beiscsi_bsg_request, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5842 | }; |
| 5843 | |
| 5844 | static struct pci_driver beiscsi_pci_driver = { |
| 5845 | .name = DRV_NAME, |
| 5846 | .probe = beiscsi_dev_probe, |
| 5847 | .remove = beiscsi_remove, |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5848 | .id_table = beiscsi_pci_id_table, |
| 5849 | .err_handler = &beiscsi_eeh_handlers |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5850 | }; |
| 5851 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5852 | static int __init beiscsi_module_init(void) |
| 5853 | { |
| 5854 | int ret; |
| 5855 | |
| 5856 | beiscsi_scsi_transport = |
| 5857 | iscsi_register_transport(&beiscsi_iscsi_transport); |
| 5858 | if (!beiscsi_scsi_transport) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5859 | printk(KERN_ERR |
| 5860 | "beiscsi_module_init - Unable to register beiscsi transport.\n"); |
Jayamohan Kallickal | f55a24f | 2010-01-23 05:37:40 +0530 | [diff] [blame] | 5861 | return -ENOMEM; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5862 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5863 | printk(KERN_INFO "In beiscsi_module_init, tt=%p\n", |
| 5864 | &beiscsi_iscsi_transport); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5865 | |
| 5866 | ret = pci_register_driver(&beiscsi_pci_driver); |
| 5867 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5868 | printk(KERN_ERR |
| 5869 | "beiscsi_module_init - Unable to register beiscsi pci driver.\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5870 | goto unregister_iscsi_transport; |
| 5871 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5872 | return 0; |
| 5873 | |
| 5874 | unregister_iscsi_transport: |
| 5875 | iscsi_unregister_transport(&beiscsi_iscsi_transport); |
| 5876 | return ret; |
| 5877 | } |
| 5878 | |
| 5879 | static void __exit beiscsi_module_exit(void) |
| 5880 | { |
| 5881 | pci_unregister_driver(&beiscsi_pci_driver); |
| 5882 | iscsi_unregister_transport(&beiscsi_iscsi_transport); |
| 5883 | } |
| 5884 | |
| 5885 | module_init(beiscsi_module_init); |
| 5886 | module_exit(beiscsi_module_exit); |