Jitendra Bhivare | 942b765 | 2017-03-24 14:11:48 +0530 | [diff] [blame] | 1 | /* |
Ketan Mukadam | 9458321 | 2018-06-07 13:54:43 +0530 | [diff] [blame] | 2 | * This file is part of the Emulex Linux Device Driver for Enterprise iSCSI |
| 3 | * Host Bus Adapters. Refer to the README file included with this package |
| 4 | * for driver version and adapter compatibility. |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5 | * |
Ketan Mukadam | 9458321 | 2018-06-07 13:54:43 +0530 | [diff] [blame] | 6 | * Copyright (c) 2018 Broadcom. All Rights Reserved. |
| 7 | * The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of version 2 of the GNU General Public License as published |
| 11 | * by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful. ALL EXPRESS |
| 14 | * OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY |
| 15 | * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, |
| 16 | * OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH |
| 17 | * DISCLAIMERS ARE HELD TO BE LEGALLY INVALID. |
| 18 | * See the GNU General Public License for more details, a copy of which |
| 19 | * can be found in the file COPYING included with this package. |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 20 | * |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 21 | * Contact Information: |
Jitendra Bhivare | 60f36e0 | 2016-08-19 15:20:24 +0530 | [diff] [blame] | 22 | * linux-drivers@broadcom.com |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 23 | * |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 24 | */ |
Jayamohan Kallickal | 255fa9a | 2011-03-25 14:23:57 -0700 | [diff] [blame] | 25 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 26 | #include <linux/reboot.h> |
| 27 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 28 | #include <linux/slab.h> |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 29 | #include <linux/interrupt.h> |
| 30 | #include <linux/blkdev.h> |
| 31 | #include <linux/pci.h> |
| 32 | #include <linux/string.h> |
| 33 | #include <linux/kernel.h> |
| 34 | #include <linux/semaphore.h> |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 35 | #include <linux/iscsi_boot_sysfs.h> |
Paul Gortmaker | acf3368f | 2011-05-27 09:47:43 -0400 | [diff] [blame] | 36 | #include <linux/module.h> |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 37 | #include <linux/bsg-lib.h> |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 38 | #include <linux/irq_poll.h> |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 39 | |
| 40 | #include <scsi/libiscsi.h> |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 41 | #include <scsi/scsi_bsg_iscsi.h> |
| 42 | #include <scsi/scsi_netlink.h> |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 43 | #include <scsi/scsi_transport_iscsi.h> |
| 44 | #include <scsi/scsi_transport.h> |
| 45 | #include <scsi/scsi_cmnd.h> |
| 46 | #include <scsi/scsi_device.h> |
| 47 | #include <scsi/scsi_host.h> |
| 48 | #include <scsi/scsi.h> |
| 49 | #include "be_main.h" |
| 50 | #include "be_iscsi.h" |
| 51 | #include "be_mgmt.h" |
John Soni Jose | 0a513dd | 2012-08-20 23:00:55 +0530 | [diff] [blame] | 52 | #include "be_cmds.h" |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 53 | |
| 54 | static unsigned int be_iopoll_budget = 10; |
| 55 | static unsigned int be_max_phys_size = 64; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 56 | static unsigned int enable_msix = 1; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 57 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 58 | MODULE_DESCRIPTION(DRV_DESC " " BUILD_STR); |
Jayamohan Kallickal | 76d15db | 2012-04-03 23:41:46 -0500 | [diff] [blame] | 59 | MODULE_VERSION(BUILD_STR); |
Ketan Mukadam | c4f39bd | 2015-07-04 04:12:33 +0530 | [diff] [blame] | 60 | MODULE_AUTHOR("Emulex Corporation"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 61 | MODULE_LICENSE("GPL"); |
| 62 | module_param(be_iopoll_budget, int, 0); |
| 63 | module_param(enable_msix, int, 0); |
| 64 | module_param(be_max_phys_size, uint, S_IRUGO); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 65 | MODULE_PARM_DESC(be_max_phys_size, |
| 66 | "Maximum Size (In Kilobytes) of physically contiguous " |
| 67 | "memory that can be allocated. Range is 16 - 128"); |
| 68 | |
| 69 | #define beiscsi_disp_param(_name)\ |
Baoyou Xie | 0825b8e | 2016-09-26 20:00:59 +0800 | [diff] [blame] | 70 | static ssize_t \ |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 71 | beiscsi_##_name##_disp(struct device *dev,\ |
| 72 | struct device_attribute *attrib, char *buf) \ |
| 73 | { \ |
| 74 | struct Scsi_Host *shost = class_to_shost(dev);\ |
| 75 | struct beiscsi_hba *phba = iscsi_host_priv(shost); \ |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 76 | return snprintf(buf, PAGE_SIZE, "%d\n",\ |
| 77 | phba->attr_##_name);\ |
| 78 | } |
| 79 | |
| 80 | #define beiscsi_change_param(_name, _minval, _maxval, _defaval)\ |
Baoyou Xie | 0825b8e | 2016-09-26 20:00:59 +0800 | [diff] [blame] | 81 | static int \ |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 82 | beiscsi_##_name##_change(struct beiscsi_hba *phba, uint32_t val)\ |
| 83 | {\ |
| 84 | if (val >= _minval && val <= _maxval) {\ |
| 85 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,\ |
| 86 | "BA_%d : beiscsi_"#_name" updated "\ |
| 87 | "from 0x%x ==> 0x%x\n",\ |
| 88 | phba->attr_##_name, val); \ |
| 89 | phba->attr_##_name = val;\ |
| 90 | return 0;\ |
| 91 | } \ |
| 92 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, \ |
| 93 | "BA_%d beiscsi_"#_name" attribute "\ |
| 94 | "cannot be updated to 0x%x, "\ |
| 95 | "range allowed is ["#_minval" - "#_maxval"]\n", val);\ |
| 96 | return -EINVAL;\ |
| 97 | } |
| 98 | |
| 99 | #define beiscsi_store_param(_name) \ |
Baoyou Xie | 0825b8e | 2016-09-26 20:00:59 +0800 | [diff] [blame] | 100 | static ssize_t \ |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 101 | beiscsi_##_name##_store(struct device *dev,\ |
| 102 | struct device_attribute *attr, const char *buf,\ |
| 103 | size_t count) \ |
| 104 | { \ |
| 105 | struct Scsi_Host *shost = class_to_shost(dev);\ |
| 106 | struct beiscsi_hba *phba = iscsi_host_priv(shost);\ |
| 107 | uint32_t param_val = 0;\ |
| 108 | if (!isdigit(buf[0]))\ |
| 109 | return -EINVAL;\ |
| 110 | if (sscanf(buf, "%i", ¶m_val) != 1)\ |
| 111 | return -EINVAL;\ |
| 112 | if (beiscsi_##_name##_change(phba, param_val) == 0) \ |
| 113 | return strlen(buf);\ |
| 114 | else \ |
| 115 | return -EINVAL;\ |
| 116 | } |
| 117 | |
| 118 | #define beiscsi_init_param(_name, _minval, _maxval, _defval) \ |
Baoyou Xie | 0825b8e | 2016-09-26 20:00:59 +0800 | [diff] [blame] | 119 | static int \ |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 120 | beiscsi_##_name##_init(struct beiscsi_hba *phba, uint32_t val) \ |
| 121 | { \ |
| 122 | if (val >= _minval && val <= _maxval) {\ |
| 123 | phba->attr_##_name = val;\ |
| 124 | return 0;\ |
| 125 | } \ |
| 126 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,\ |
| 127 | "BA_%d beiscsi_"#_name" attribute " \ |
| 128 | "cannot be updated to 0x%x, "\ |
| 129 | "range allowed is ["#_minval" - "#_maxval"]\n", val);\ |
| 130 | phba->attr_##_name = _defval;\ |
| 131 | return -EINVAL;\ |
| 132 | } |
| 133 | |
| 134 | #define BEISCSI_RW_ATTR(_name, _minval, _maxval, _defval, _descp) \ |
| 135 | static uint beiscsi_##_name = _defval;\ |
| 136 | module_param(beiscsi_##_name, uint, S_IRUGO);\ |
| 137 | MODULE_PARM_DESC(beiscsi_##_name, _descp);\ |
| 138 | beiscsi_disp_param(_name)\ |
| 139 | beiscsi_change_param(_name, _minval, _maxval, _defval)\ |
| 140 | beiscsi_store_param(_name)\ |
| 141 | beiscsi_init_param(_name, _minval, _maxval, _defval)\ |
| 142 | DEVICE_ATTR(beiscsi_##_name, S_IRUGO | S_IWUSR,\ |
| 143 | beiscsi_##_name##_disp, beiscsi_##_name##_store) |
| 144 | |
| 145 | /* |
| 146 | * When new log level added update the |
| 147 | * the MAX allowed value for log_enable |
| 148 | */ |
| 149 | BEISCSI_RW_ATTR(log_enable, 0x00, |
| 150 | 0xFF, 0x00, "Enable logging Bit Mask\n" |
| 151 | "\t\t\t\tInitialization Events : 0x01\n" |
| 152 | "\t\t\t\tMailbox Events : 0x02\n" |
| 153 | "\t\t\t\tMiscellaneous Events : 0x04\n" |
| 154 | "\t\t\t\tError Handling : 0x08\n" |
| 155 | "\t\t\t\tIO Path Events : 0x10\n" |
Jayamohan Kallickal | afb9605 | 2013-09-28 15:35:55 -0700 | [diff] [blame] | 156 | "\t\t\t\tConfiguration Path : 0x20\n" |
| 157 | "\t\t\t\tiSCSI Protocol : 0x40\n"); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 158 | |
John Soni Jose | 5cac759 | 2012-10-20 04:42:25 +0530 | [diff] [blame] | 159 | 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] | 160 | DEVICE_ATTR(beiscsi_adapter_family, S_IRUGO, beiscsi_adap_family_disp, NULL); |
Jayamohan Kallickal | 22661e2 | 2013-04-05 20:38:28 -0700 | [diff] [blame] | 161 | DEVICE_ATTR(beiscsi_fw_ver, S_IRUGO, beiscsi_fw_ver_disp, NULL); |
Jayamohan Kallickal | d3fea9a | 2013-09-28 15:35:53 -0700 | [diff] [blame] | 162 | DEVICE_ATTR(beiscsi_phys_port, S_IRUGO, beiscsi_phys_port_disp, NULL); |
Jayamohan Kallickal | 6103c1f | 2013-09-28 15:35:52 -0700 | [diff] [blame] | 163 | DEVICE_ATTR(beiscsi_active_session_count, S_IRUGO, |
| 164 | beiscsi_active_session_disp, NULL); |
| 165 | DEVICE_ATTR(beiscsi_free_session_count, S_IRUGO, |
| 166 | beiscsi_free_session_disp, NULL); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 167 | struct device_attribute *beiscsi_attrs[] = { |
| 168 | &dev_attr_beiscsi_log_enable, |
John Soni Jose | 5cac759 | 2012-10-20 04:42:25 +0530 | [diff] [blame] | 169 | &dev_attr_beiscsi_drvr_ver, |
John Soni Jose | 26000db | 2012-10-20 04:45:06 +0530 | [diff] [blame] | 170 | &dev_attr_beiscsi_adapter_family, |
Jayamohan Kallickal | 22661e2 | 2013-04-05 20:38:28 -0700 | [diff] [blame] | 171 | &dev_attr_beiscsi_fw_ver, |
Jayamohan Kallickal | 6103c1f | 2013-09-28 15:35:52 -0700 | [diff] [blame] | 172 | &dev_attr_beiscsi_active_session_count, |
| 173 | &dev_attr_beiscsi_free_session_count, |
Jayamohan Kallickal | d3fea9a | 2013-09-28 15:35:53 -0700 | [diff] [blame] | 174 | &dev_attr_beiscsi_phys_port, |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 175 | NULL, |
| 176 | }; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 177 | |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 178 | static char const *cqe_desc[] = { |
| 179 | "RESERVED_DESC", |
| 180 | "SOL_CMD_COMPLETE", |
| 181 | "SOL_CMD_KILLED_DATA_DIGEST_ERR", |
| 182 | "CXN_KILLED_PDU_SIZE_EXCEEDS_DSL", |
| 183 | "CXN_KILLED_BURST_LEN_MISMATCH", |
| 184 | "CXN_KILLED_AHS_RCVD", |
| 185 | "CXN_KILLED_HDR_DIGEST_ERR", |
| 186 | "CXN_KILLED_UNKNOWN_HDR", |
| 187 | "CXN_KILLED_STALE_ITT_TTT_RCVD", |
| 188 | "CXN_KILLED_INVALID_ITT_TTT_RCVD", |
| 189 | "CXN_KILLED_RST_RCVD", |
| 190 | "CXN_KILLED_TIMED_OUT", |
| 191 | "CXN_KILLED_RST_SENT", |
| 192 | "CXN_KILLED_FIN_RCVD", |
| 193 | "CXN_KILLED_BAD_UNSOL_PDU_RCVD", |
| 194 | "CXN_KILLED_BAD_WRB_INDEX_ERROR", |
| 195 | "CXN_KILLED_OVER_RUN_RESIDUAL", |
| 196 | "CXN_KILLED_UNDER_RUN_RESIDUAL", |
| 197 | "CMD_KILLED_INVALID_STATSN_RCVD", |
| 198 | "CMD_KILLED_INVALID_R2T_RCVD", |
| 199 | "CMD_CXN_KILLED_LUN_INVALID", |
| 200 | "CMD_CXN_KILLED_ICD_INVALID", |
| 201 | "CMD_CXN_KILLED_ITT_INVALID", |
| 202 | "CMD_CXN_KILLED_SEQ_OUTOFORDER", |
| 203 | "CMD_CXN_KILLED_INVALID_DATASN_RCVD", |
| 204 | "CXN_INVALIDATE_NOTIFY", |
| 205 | "CXN_INVALIDATE_INDEX_NOTIFY", |
| 206 | "CMD_INVALIDATED_NOTIFY", |
| 207 | "UNSOL_HDR_NOTIFY", |
| 208 | "UNSOL_DATA_NOTIFY", |
| 209 | "UNSOL_DATA_DIGEST_ERROR_NOTIFY", |
| 210 | "DRIVERMSG_NOTIFY", |
| 211 | "CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN", |
| 212 | "SOL_CMD_KILLED_DIF_ERR", |
| 213 | "CXN_KILLED_SYN_RCVD", |
| 214 | "CXN_KILLED_IMM_DATA_RCVD" |
| 215 | }; |
| 216 | |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 217 | static int beiscsi_eh_abort(struct scsi_cmnd *sc) |
| 218 | { |
Jitendra Bhivare | faa0a22 | 2016-12-13 15:55:56 +0530 | [diff] [blame] | 219 | struct iscsi_task *abrt_task = (struct iscsi_task *)sc->SCp.ptr; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 220 | struct iscsi_cls_session *cls_session; |
Jitendra Bhivare | faa0a22 | 2016-12-13 15:55:56 +0530 | [diff] [blame] | 221 | struct beiscsi_io_task *abrt_io_task; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 222 | struct beiscsi_conn *beiscsi_conn; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 223 | struct iscsi_session *session; |
Jitendra Bhivare | f350501 | 2016-12-13 15:55:54 +0530 | [diff] [blame] | 224 | struct invldt_cmd_tbl inv_tbl; |
Jitendra Bhivare | faa0a22 | 2016-12-13 15:55:56 +0530 | [diff] [blame] | 225 | struct beiscsi_hba *phba; |
| 226 | struct iscsi_conn *conn; |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 227 | int rc; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 228 | |
| 229 | cls_session = starget_to_session(scsi_target(sc->device)); |
| 230 | session = cls_session->dd_data; |
| 231 | |
Jitendra Bhivare | faa0a22 | 2016-12-13 15:55:56 +0530 | [diff] [blame] | 232 | /* check if we raced, task just got cleaned up under us */ |
| 233 | spin_lock_bh(&session->back_lock); |
| 234 | if (!abrt_task || !abrt_task->sc) { |
| 235 | spin_unlock_bh(&session->back_lock); |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 236 | return SUCCESS; |
| 237 | } |
Jitendra Bhivare | faa0a22 | 2016-12-13 15:55:56 +0530 | [diff] [blame] | 238 | /* get a task ref till FW processes the req for the ICD used */ |
| 239 | __iscsi_get_task(abrt_task); |
| 240 | abrt_io_task = abrt_task->dd_data; |
| 241 | conn = abrt_task->conn; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 242 | beiscsi_conn = conn->dd_data; |
| 243 | phba = beiscsi_conn->phba; |
Jitendra Bhivare | faa0a22 | 2016-12-13 15:55:56 +0530 | [diff] [blame] | 244 | /* mark WRB invalid which have been not processed by FW yet */ |
Jitendra Bhivare | 392b7d2 | 2016-12-13 15:55:57 +0530 | [diff] [blame] | 245 | if (is_chip_be2_be3r(phba)) { |
| 246 | AMAP_SET_BITS(struct amap_iscsi_wrb, invld, |
| 247 | abrt_io_task->pwrb_handle->pwrb, 1); |
| 248 | } else { |
| 249 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, invld, |
| 250 | abrt_io_task->pwrb_handle->pwrb, 1); |
| 251 | } |
Jitendra Bhivare | faa0a22 | 2016-12-13 15:55:56 +0530 | [diff] [blame] | 252 | inv_tbl.cid = beiscsi_conn->beiscsi_conn_cid; |
| 253 | inv_tbl.icd = abrt_io_task->psgl_handle->sgl_index; |
| 254 | spin_unlock_bh(&session->back_lock); |
| 255 | |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 256 | rc = beiscsi_mgmt_invalidate_icds(phba, &inv_tbl, 1); |
Jitendra Bhivare | faa0a22 | 2016-12-13 15:55:56 +0530 | [diff] [blame] | 257 | iscsi_put_task(abrt_task); |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 258 | if (rc) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 259 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH, |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 260 | "BM_%d : sc %p invalidation failed %d\n", |
| 261 | sc, rc); |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 262 | return FAILED; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 263 | } |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 264 | |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 265 | return iscsi_eh_abort(sc); |
| 266 | } |
| 267 | |
| 268 | static int beiscsi_eh_device_reset(struct scsi_cmnd *sc) |
| 269 | { |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 270 | struct beiscsi_invldt_cmd_tbl { |
| 271 | struct invldt_cmd_tbl tbl[BE_INVLDT_CMD_TBL_SZ]; |
| 272 | struct iscsi_task *task[BE_INVLDT_CMD_TBL_SZ]; |
| 273 | } *inv_tbl; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 274 | struct iscsi_cls_session *cls_session; |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 275 | struct beiscsi_conn *beiscsi_conn; |
| 276 | struct beiscsi_io_task *io_task; |
| 277 | struct iscsi_session *session; |
| 278 | struct beiscsi_hba *phba; |
| 279 | struct iscsi_conn *conn; |
| 280 | struct iscsi_task *task; |
| 281 | unsigned int i, nents; |
Jitendra Bhivare | f350501 | 2016-12-13 15:55:54 +0530 | [diff] [blame] | 282 | int rc, more = 0; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 283 | |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 284 | cls_session = starget_to_session(scsi_target(sc->device)); |
| 285 | session = cls_session->dd_data; |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 286 | |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 287 | spin_lock_bh(&session->frwd_lock); |
Jayamohan Kallickal | db7f770 | 2012-04-03 23:41:43 -0500 | [diff] [blame] | 288 | if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN) { |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 289 | spin_unlock_bh(&session->frwd_lock); |
Jayamohan Kallickal | db7f770 | 2012-04-03 23:41:43 -0500 | [diff] [blame] | 290 | return FAILED; |
| 291 | } |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 292 | |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 293 | conn = session->leadconn; |
| 294 | beiscsi_conn = conn->dd_data; |
| 295 | phba = beiscsi_conn->phba; |
Jitendra Bhivare | f350501 | 2016-12-13 15:55:54 +0530 | [diff] [blame] | 296 | |
Wei Yongjun | f253473 | 2017-01-12 14:21:32 +0000 | [diff] [blame] | 297 | inv_tbl = kzalloc(sizeof(*inv_tbl), GFP_ATOMIC); |
Jitendra Bhivare | f350501 | 2016-12-13 15:55:54 +0530 | [diff] [blame] | 298 | if (!inv_tbl) { |
| 299 | spin_unlock_bh(&session->frwd_lock); |
| 300 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH, |
| 301 | "BM_%d : invldt_cmd_tbl alloc failed\n"); |
| 302 | return FAILED; |
| 303 | } |
| 304 | nents = 0; |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 305 | /* take back_lock to prevent task from getting cleaned up under us */ |
| 306 | spin_lock(&session->back_lock); |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 307 | for (i = 0; i < conn->session->cmds_max; i++) { |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 308 | task = conn->session->cmds[i]; |
| 309 | if (!task->sc) |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 310 | continue; |
| 311 | |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 312 | if (sc->device->lun != task->sc->device->lun) |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 313 | continue; |
Jitendra Bhivare | f350501 | 2016-12-13 15:55:54 +0530 | [diff] [blame] | 314 | /** |
| 315 | * Can't fit in more cmds? Normally this won't happen b'coz |
| 316 | * BEISCSI_CMD_PER_LUN is same as BE_INVLDT_CMD_TBL_SZ. |
| 317 | */ |
| 318 | if (nents == BE_INVLDT_CMD_TBL_SZ) { |
| 319 | more = 1; |
| 320 | break; |
| 321 | } |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 322 | |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 323 | /* get a task ref till FW processes the req for the ICD used */ |
| 324 | __iscsi_get_task(task); |
| 325 | io_task = task->dd_data; |
| 326 | /* mark WRB invalid which have been not processed by FW yet */ |
Jitendra Bhivare | 392b7d2 | 2016-12-13 15:55:57 +0530 | [diff] [blame] | 327 | if (is_chip_be2_be3r(phba)) { |
| 328 | AMAP_SET_BITS(struct amap_iscsi_wrb, invld, |
| 329 | io_task->pwrb_handle->pwrb, 1); |
| 330 | } else { |
| 331 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, invld, |
| 332 | io_task->pwrb_handle->pwrb, 1); |
| 333 | } |
Jayamohan Kallickal | 7626c06 | 2013-09-28 15:35:57 -0700 | [diff] [blame] | 334 | |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 335 | inv_tbl->tbl[nents].cid = beiscsi_conn->beiscsi_conn_cid; |
| 336 | inv_tbl->tbl[nents].icd = io_task->psgl_handle->sgl_index; |
| 337 | inv_tbl->task[nents] = task; |
Jitendra Bhivare | f350501 | 2016-12-13 15:55:54 +0530 | [diff] [blame] | 338 | nents++; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 339 | } |
Jitendra Bhivare | d1e1d63 | 2017-03-24 14:11:42 +0530 | [diff] [blame] | 340 | spin_unlock(&session->back_lock); |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 341 | spin_unlock_bh(&session->frwd_lock); |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 342 | |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 343 | rc = SUCCESS; |
| 344 | if (!nents) |
| 345 | goto end_reset; |
| 346 | |
Jitendra Bhivare | f350501 | 2016-12-13 15:55:54 +0530 | [diff] [blame] | 347 | if (more) { |
| 348 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH, |
| 349 | "BM_%d : number of cmds exceeds size of invalidation table\n"); |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 350 | rc = FAILED; |
| 351 | goto end_reset; |
Jitendra Bhivare | f350501 | 2016-12-13 15:55:54 +0530 | [diff] [blame] | 352 | } |
| 353 | |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 354 | if (beiscsi_mgmt_invalidate_icds(phba, &inv_tbl->tbl[0], nents)) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 355 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH, |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 356 | "BM_%d : cid %u scmds invalidation failed\n", |
| 357 | beiscsi_conn->beiscsi_conn_cid); |
| 358 | rc = FAILED; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 359 | } |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 360 | |
Jitendra Bhivare | 9871321 | 2016-12-13 15:55:55 +0530 | [diff] [blame] | 361 | end_reset: |
| 362 | for (i = 0; i < nents; i++) |
| 363 | iscsi_put_task(inv_tbl->task[i]); |
| 364 | kfree(inv_tbl); |
| 365 | |
| 366 | if (rc == SUCCESS) |
| 367 | rc = iscsi_eh_device_reset(sc); |
| 368 | return rc; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 369 | } |
| 370 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 371 | /*------------------- PCI Driver operations and data ----------------- */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 372 | static const struct pci_device_id beiscsi_pci_id_table[] = { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 373 | { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) }, |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 374 | { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) }, |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 375 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) }, |
| 376 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) }, |
| 377 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID3) }, |
John Soni Jose | 139a1b1 | 2012-10-20 04:43:20 +0530 | [diff] [blame] | 378 | { PCI_DEVICE(ELX_VENDOR_ID, OC_SKH_ID1) }, |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 379 | { 0 } |
| 380 | }; |
| 381 | MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table); |
| 382 | |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 383 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 384 | static struct scsi_host_template beiscsi_sht = { |
| 385 | .module = THIS_MODULE, |
Ketan Mukadam | c4f39bd | 2015-07-04 04:12:33 +0530 | [diff] [blame] | 386 | .name = "Emulex 10Gbe open-iscsi Initiator Driver", |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 387 | .proc_name = DRV_NAME, |
| 388 | .queuecommand = iscsi_queuecommand, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 389 | .change_queue_depth = scsi_change_queue_depth, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 390 | .target_alloc = iscsi_target_alloc, |
Christoph Hellwig | b6a05c8 | 2017-01-30 13:18:58 +0100 | [diff] [blame] | 391 | .eh_timed_out = iscsi_eh_cmd_timed_out, |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 392 | .eh_abort_handler = beiscsi_eh_abort, |
| 393 | .eh_device_reset_handler = beiscsi_eh_device_reset, |
Jayamohan Kallickal | 309ce15 | 2010-02-20 08:02:10 +0530 | [diff] [blame] | 394 | .eh_target_reset_handler = iscsi_eh_session_reset, |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 395 | .shost_attrs = beiscsi_attrs, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 396 | .sg_tablesize = BEISCSI_SGLIST_ELEMENTS, |
| 397 | .can_queue = BE2_IO_DEPTH, |
| 398 | .this_id = -1, |
| 399 | .max_sectors = BEISCSI_MAX_SECTORS, |
Christoph Hellwig | 50c2e91 | 2018-12-13 16:17:03 +0100 | [diff] [blame] | 400 | .max_segment_size = 65536, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 401 | .cmd_per_lun = BEISCSI_CMD_PER_LUN, |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 402 | .vendor_id = SCSI_NL_VID_TYPE_PCI | BE_VENDOR_ID, |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 403 | .track_queue_depth = 1, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 404 | }; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 405 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 406 | static struct scsi_transport_template *beiscsi_scsi_transport; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 407 | |
| 408 | static struct beiscsi_hba *beiscsi_hba_alloc(struct pci_dev *pcidev) |
| 409 | { |
| 410 | struct beiscsi_hba *phba; |
| 411 | struct Scsi_Host *shost; |
| 412 | |
| 413 | shost = iscsi_host_alloc(&beiscsi_sht, sizeof(*phba), 0); |
| 414 | if (!shost) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 415 | dev_err(&pcidev->dev, |
| 416 | "beiscsi_hba_alloc - iscsi_host_alloc failed\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 417 | return NULL; |
| 418 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 419 | shost->max_id = BE2_MAX_SESSIONS; |
| 420 | shost->max_channel = 0; |
| 421 | shost->max_cmd_len = BEISCSI_MAX_CMD_LEN; |
| 422 | shost->max_lun = BEISCSI_NUM_MAX_LUN; |
| 423 | shost->transportt = beiscsi_scsi_transport; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 424 | phba = iscsi_host_priv(shost); |
| 425 | memset(phba, 0, sizeof(*phba)); |
| 426 | phba->shost = shost; |
| 427 | phba->pcidev = pci_dev_get(pcidev); |
Jayamohan Kallickal | 2807afb | 2010-01-05 05:07:49 +0530 | [diff] [blame] | 428 | pci_set_drvdata(pcidev, phba); |
Mike Christie | 0e43895 | 2012-04-03 23:41:51 -0500 | [diff] [blame] | 429 | phba->interface_handle = 0xFFFFFFFF; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 430 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 431 | return phba; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | static void beiscsi_unmap_pci_function(struct beiscsi_hba *phba) |
| 435 | { |
| 436 | if (phba->csr_va) { |
| 437 | iounmap(phba->csr_va); |
| 438 | phba->csr_va = NULL; |
| 439 | } |
| 440 | if (phba->db_va) { |
| 441 | iounmap(phba->db_va); |
| 442 | phba->db_va = NULL; |
| 443 | } |
| 444 | if (phba->pci_va) { |
| 445 | iounmap(phba->pci_va); |
| 446 | phba->pci_va = NULL; |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | static int beiscsi_map_pci_bars(struct beiscsi_hba *phba, |
| 451 | struct pci_dev *pcidev) |
| 452 | { |
| 453 | u8 __iomem *addr; |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 454 | int pcicfg_reg; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 455 | |
| 456 | addr = ioremap_nocache(pci_resource_start(pcidev, 2), |
| 457 | pci_resource_len(pcidev, 2)); |
| 458 | if (addr == NULL) |
| 459 | return -ENOMEM; |
| 460 | phba->ctrl.csr = addr; |
| 461 | phba->csr_va = addr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 462 | |
| 463 | addr = ioremap_nocache(pci_resource_start(pcidev, 4), 128 * 1024); |
| 464 | if (addr == NULL) |
| 465 | goto pci_map_err; |
| 466 | phba->ctrl.db = addr; |
| 467 | phba->db_va = addr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 468 | |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 469 | if (phba->generation == BE_GEN2) |
| 470 | pcicfg_reg = 1; |
| 471 | else |
| 472 | pcicfg_reg = 0; |
| 473 | |
| 474 | addr = ioremap_nocache(pci_resource_start(pcidev, pcicfg_reg), |
| 475 | pci_resource_len(pcidev, pcicfg_reg)); |
| 476 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 477 | if (addr == NULL) |
| 478 | goto pci_map_err; |
| 479 | phba->ctrl.pcicfg = addr; |
| 480 | phba->pci_va = addr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 481 | return 0; |
| 482 | |
| 483 | pci_map_err: |
| 484 | beiscsi_unmap_pci_function(phba); |
| 485 | return -ENOMEM; |
| 486 | } |
| 487 | |
| 488 | static int beiscsi_enable_pci(struct pci_dev *pcidev) |
| 489 | { |
| 490 | int ret; |
| 491 | |
| 492 | ret = pci_enable_device(pcidev); |
| 493 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 494 | dev_err(&pcidev->dev, |
| 495 | "beiscsi_enable_pci - enable device failed\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 496 | return ret; |
| 497 | } |
| 498 | |
John Soni Jose | e307f3a | 2015-04-25 08:17:19 +0530 | [diff] [blame] | 499 | ret = pci_request_regions(pcidev, DRV_NAME); |
| 500 | if (ret) { |
| 501 | dev_err(&pcidev->dev, |
| 502 | "beiscsi_enable_pci - request region failed\n"); |
| 503 | goto pci_dev_disable; |
| 504 | } |
| 505 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 506 | pci_set_master(pcidev); |
Christoph Hellwig | 26a4c99 | 2018-10-10 18:22:24 +0200 | [diff] [blame] | 507 | ret = dma_set_mask_and_coherent(&pcidev->dev, DMA_BIT_MASK(64)); |
Jayamohan Kallickal | 6c57625b | 2014-01-29 02:16:45 -0500 | [diff] [blame] | 508 | if (ret) { |
Christoph Hellwig | 26a4c99 | 2018-10-10 18:22:24 +0200 | [diff] [blame] | 509 | ret = dma_set_mask_and_coherent(&pcidev->dev, DMA_BIT_MASK(32)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 510 | if (ret) { |
| 511 | dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n"); |
John Soni Jose | e307f3a | 2015-04-25 08:17:19 +0530 | [diff] [blame] | 512 | goto pci_region_release; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 513 | } |
| 514 | } |
| 515 | return 0; |
John Soni Jose | e307f3a | 2015-04-25 08:17:19 +0530 | [diff] [blame] | 516 | |
| 517 | pci_region_release: |
| 518 | pci_release_regions(pcidev); |
| 519 | pci_dev_disable: |
| 520 | pci_disable_device(pcidev); |
| 521 | |
| 522 | return ret; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | static int be_ctrl_init(struct beiscsi_hba *phba, struct pci_dev *pdev) |
| 526 | { |
| 527 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 528 | struct be_dma_mem *mbox_mem_alloc = &ctrl->mbox_mem_alloced; |
| 529 | struct be_dma_mem *mbox_mem_align = &ctrl->mbox_mem; |
| 530 | int status = 0; |
| 531 | |
| 532 | ctrl->pdev = pdev; |
| 533 | status = beiscsi_map_pci_bars(phba, pdev); |
| 534 | if (status) |
| 535 | return status; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 536 | mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16; |
Christoph Hellwig | 26a4c99 | 2018-10-10 18:22:24 +0200 | [diff] [blame] | 537 | mbox_mem_alloc->va = dma_alloc_coherent(&pdev->dev, |
| 538 | mbox_mem_alloc->size, &mbox_mem_alloc->dma, GFP_KERNEL); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 539 | if (!mbox_mem_alloc->va) { |
| 540 | beiscsi_unmap_pci_function(phba); |
Jayamohan Kallickal | a49e06d | 2012-04-03 23:41:44 -0500 | [diff] [blame] | 541 | return -ENOMEM; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | mbox_mem_align->size = sizeof(struct be_mcc_mailbox); |
| 545 | mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16); |
| 546 | mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16); |
| 547 | memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox)); |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 548 | mutex_init(&ctrl->mbox_lock); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 549 | spin_lock_init(&phba->ctrl.mcc_lock); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 550 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 551 | return status; |
| 552 | } |
| 553 | |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 554 | /** |
| 555 | * beiscsi_get_params()- Set the config paramters |
| 556 | * @phba: ptr device priv structure |
| 557 | **/ |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 558 | static void beiscsi_get_params(struct beiscsi_hba *phba) |
| 559 | { |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 560 | uint32_t total_cid_count = 0; |
| 561 | uint32_t total_icd_count = 0; |
| 562 | uint8_t ulp_num = 0; |
| 563 | |
| 564 | total_cid_count = BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP0) + |
| 565 | BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP1); |
| 566 | |
Jayamohan Kallickal | cf987b7 | 2013-09-28 15:35:59 -0700 | [diff] [blame] | 567 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 568 | uint32_t align_mask = 0; |
| 569 | uint32_t icd_post_per_page = 0; |
| 570 | uint32_t icd_count_unavailable = 0; |
| 571 | uint32_t icd_start = 0, icd_count = 0; |
| 572 | uint32_t icd_start_align = 0, icd_count_align = 0; |
| 573 | |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 574 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
Jayamohan Kallickal | cf987b7 | 2013-09-28 15:35:59 -0700 | [diff] [blame] | 575 | icd_start = phba->fw_config.iscsi_icd_start[ulp_num]; |
| 576 | icd_count = phba->fw_config.iscsi_icd_count[ulp_num]; |
| 577 | |
| 578 | /* Get ICD count that can be posted on each page */ |
| 579 | icd_post_per_page = (PAGE_SIZE / (BE2_SGE * |
| 580 | sizeof(struct iscsi_sge))); |
| 581 | align_mask = (icd_post_per_page - 1); |
| 582 | |
| 583 | /* Check if icd_start is aligned ICD per page posting */ |
| 584 | if (icd_start % icd_post_per_page) { |
| 585 | icd_start_align = ((icd_start + |
| 586 | icd_post_per_page) & |
| 587 | ~(align_mask)); |
| 588 | phba->fw_config. |
| 589 | iscsi_icd_start[ulp_num] = |
| 590 | icd_start_align; |
| 591 | } |
| 592 | |
| 593 | icd_count_align = (icd_count & ~align_mask); |
| 594 | |
| 595 | /* ICD discarded in the process of alignment */ |
| 596 | if (icd_start_align) |
| 597 | icd_count_unavailable = ((icd_start_align - |
| 598 | icd_start) + |
| 599 | (icd_count - |
| 600 | icd_count_align)); |
| 601 | |
| 602 | /* Updated ICD count available */ |
| 603 | phba->fw_config.iscsi_icd_count[ulp_num] = (icd_count - |
| 604 | icd_count_unavailable); |
| 605 | |
| 606 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 607 | "BM_%d : Aligned ICD values\n" |
| 608 | "\t ICD Start : %d\n" |
| 609 | "\t ICD Count : %d\n" |
| 610 | "\t ICD Discarded : %d\n", |
| 611 | phba->fw_config. |
| 612 | iscsi_icd_start[ulp_num], |
| 613 | phba->fw_config. |
| 614 | iscsi_icd_count[ulp_num], |
| 615 | icd_count_unavailable); |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 616 | break; |
| 617 | } |
Jayamohan Kallickal | cf987b7 | 2013-09-28 15:35:59 -0700 | [diff] [blame] | 618 | } |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 619 | |
Jayamohan Kallickal | cf987b7 | 2013-09-28 15:35:59 -0700 | [diff] [blame] | 620 | total_icd_count = phba->fw_config.iscsi_icd_count[ulp_num]; |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 621 | phba->params.ios_per_ctrl = (total_icd_count - |
| 622 | (total_cid_count + |
| 623 | BE2_TMFS + BE2_NOPOUT_REQ)); |
| 624 | phba->params.cxns_per_ctrl = total_cid_count; |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 625 | phba->params.icds_per_ctrl = total_icd_count; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 626 | phba->params.num_sge_per_io = BE2_SGE; |
| 627 | phba->params.defpdu_hdr_sz = BE2_DEFPDU_HDR_SZ; |
| 628 | phba->params.defpdu_data_sz = BE2_DEFPDU_DATA_SZ; |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 629 | phba->params.num_eq_entries = 1024; |
| 630 | phba->params.num_cq_entries = 1024; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 631 | phba->params.wrbs_per_cxn = 256; |
| 632 | } |
| 633 | |
| 634 | static void hwi_ring_eq_db(struct beiscsi_hba *phba, |
| 635 | unsigned int id, unsigned int clr_interrupt, |
| 636 | unsigned int num_processed, |
| 637 | unsigned char rearm, unsigned char event) |
| 638 | { |
| 639 | u32 val = 0; |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 640 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 641 | if (rearm) |
| 642 | val |= 1 << DB_EQ_REARM_SHIFT; |
| 643 | if (clr_interrupt) |
| 644 | val |= 1 << DB_EQ_CLR_SHIFT; |
| 645 | if (event) |
| 646 | val |= 1 << DB_EQ_EVNT_SHIFT; |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 647 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 648 | val |= num_processed << DB_EQ_NUM_POPPED_SHIFT; |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 649 | /* Setting lower order EQ_ID Bits */ |
| 650 | val |= (id & DB_EQ_RING_ID_LOW_MASK); |
| 651 | |
| 652 | /* Setting Higher order EQ_ID Bits */ |
| 653 | val |= (((id >> DB_EQ_HIGH_FEILD_SHIFT) & |
| 654 | DB_EQ_RING_ID_HIGH_MASK) |
| 655 | << DB_EQ_HIGH_SET_SHIFT); |
| 656 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 657 | iowrite32(val, phba->db_va + DB_EQ_OFFSET); |
| 658 | } |
| 659 | |
| 660 | /** |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 661 | * be_isr_mcc - The isr routine of the driver. |
| 662 | * @irq: Not used |
| 663 | * @dev_id: Pointer to host adapter structure |
| 664 | */ |
| 665 | static irqreturn_t be_isr_mcc(int irq, void *dev_id) |
| 666 | { |
| 667 | struct beiscsi_hba *phba; |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 668 | struct be_eq_entry *eqe; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 669 | struct be_queue_info *eq; |
| 670 | struct be_queue_info *mcc; |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 671 | unsigned int mcc_events; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 672 | struct be_eq_obj *pbe_eq; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 673 | |
| 674 | pbe_eq = dev_id; |
| 675 | eq = &pbe_eq->q; |
| 676 | phba = pbe_eq->phba; |
| 677 | mcc = &phba->ctrl.mcc_obj.cq; |
| 678 | eqe = queue_tail_node(eq); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 679 | |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 680 | mcc_events = 0; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 681 | while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32] |
| 682 | & EQE_VALID_MASK) { |
| 683 | if (((eqe->dw[offsetof(struct amap_eq_entry, |
| 684 | resource_id) / 32] & |
| 685 | EQE_RESID_MASK) >> 16) == mcc->id) { |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 686 | mcc_events++; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 687 | } |
| 688 | AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0); |
| 689 | queue_tail_inc(eq); |
| 690 | eqe = queue_tail_node(eq); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 691 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 692 | |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 693 | if (mcc_events) { |
| 694 | queue_work(phba->wq, &pbe_eq->mcc_work); |
| 695 | hwi_ring_eq_db(phba, eq->id, 1, mcc_events, 1, 1); |
| 696 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 697 | return IRQ_HANDLED; |
| 698 | } |
| 699 | |
| 700 | /** |
| 701 | * be_isr_msix - The isr routine of the driver. |
| 702 | * @irq: Not used |
| 703 | * @dev_id: Pointer to host adapter structure |
| 704 | */ |
| 705 | static irqreturn_t be_isr_msix(int irq, void *dev_id) |
| 706 | { |
| 707 | struct beiscsi_hba *phba; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 708 | struct be_queue_info *eq; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 709 | struct be_eq_obj *pbe_eq; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 710 | |
| 711 | pbe_eq = dev_id; |
| 712 | eq = &pbe_eq->q; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 713 | |
| 714 | phba = pbe_eq->phba; |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 715 | /* disable interrupt till iopoll completes */ |
| 716 | hwi_ring_eq_db(phba, eq->id, 1, 0, 0, 1); |
| 717 | irq_poll_sched(&pbe_eq->iopoll); |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 718 | |
| 719 | return IRQ_HANDLED; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | /** |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 723 | * be_isr - The isr routine of the driver. |
| 724 | * @irq: Not used |
| 725 | * @dev_id: Pointer to host adapter structure |
| 726 | */ |
| 727 | static irqreturn_t be_isr(int irq, void *dev_id) |
| 728 | { |
| 729 | struct beiscsi_hba *phba; |
| 730 | struct hwi_controller *phwi_ctrlr; |
| 731 | struct hwi_context_memory *phwi_context; |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 732 | struct be_eq_entry *eqe; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 733 | struct be_queue_info *eq; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 734 | struct be_queue_info *mcc; |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 735 | unsigned int mcc_events, io_events; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 736 | struct be_ctrl_info *ctrl; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 737 | struct be_eq_obj *pbe_eq; |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 738 | int isr, rearm; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 739 | |
| 740 | phba = dev_id; |
Justin P. Mattock | 6eab04a | 2011-04-08 19:49:08 -0700 | [diff] [blame] | 741 | ctrl = &phba->ctrl; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 742 | isr = ioread32(ctrl->csr + CEV_ISR0_OFFSET + |
| 743 | (PCI_FUNC(ctrl->pdev->devfn) * CEV_ISR_SIZE)); |
| 744 | if (!isr) |
| 745 | return IRQ_NONE; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 746 | |
| 747 | phwi_ctrlr = phba->phwi_ctrlr; |
| 748 | phwi_context = phwi_ctrlr->phwi_ctxt; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 749 | pbe_eq = &phwi_context->be_eq[0]; |
| 750 | |
| 751 | eq = &phwi_context->be_eq[0].q; |
| 752 | mcc = &phba->ctrl.mcc_obj.cq; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 753 | eqe = queue_tail_node(eq); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 754 | |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 755 | io_events = 0; |
| 756 | mcc_events = 0; |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 757 | while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32] |
| 758 | & EQE_VALID_MASK) { |
| 759 | if (((eqe->dw[offsetof(struct amap_eq_entry, |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 760 | resource_id) / 32] & EQE_RESID_MASK) >> 16) == mcc->id) |
| 761 | mcc_events++; |
| 762 | else |
| 763 | io_events++; |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 764 | AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0); |
| 765 | queue_tail_inc(eq); |
| 766 | eqe = queue_tail_node(eq); |
| 767 | } |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 768 | if (!io_events && !mcc_events) |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 769 | return IRQ_NONE; |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 770 | |
| 771 | /* no need to rearm if interrupt is only for IOs */ |
| 772 | rearm = 0; |
| 773 | if (mcc_events) { |
| 774 | queue_work(phba->wq, &pbe_eq->mcc_work); |
| 775 | /* rearm for MCCQ */ |
| 776 | rearm = 1; |
| 777 | } |
| 778 | if (io_events) |
| 779 | irq_poll_sched(&pbe_eq->iopoll); |
| 780 | hwi_ring_eq_db(phba, eq->id, 0, (io_events + mcc_events), rearm, 1); |
| 781 | return IRQ_HANDLED; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 782 | } |
| 783 | |
Jitendra Bhivare | 45371aa | 2017-10-10 16:18:13 +0530 | [diff] [blame] | 784 | static void beiscsi_free_irqs(struct beiscsi_hba *phba) |
| 785 | { |
| 786 | struct hwi_context_memory *phwi_context; |
| 787 | int i; |
| 788 | |
| 789 | if (!phba->pcidev->msix_enabled) { |
| 790 | if (phba->pcidev->irq) |
| 791 | free_irq(phba->pcidev->irq, phba); |
| 792 | return; |
| 793 | } |
| 794 | |
| 795 | phwi_context = phba->phwi_ctrlr->phwi_ctxt; |
| 796 | for (i = 0; i <= phba->num_cpus; i++) { |
| 797 | free_irq(pci_irq_vector(phba->pcidev, i), |
| 798 | &phwi_context->be_eq[i]); |
| 799 | kfree(phba->msi_name[i]); |
| 800 | } |
| 801 | } |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 802 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 803 | static int beiscsi_init_irqs(struct beiscsi_hba *phba) |
| 804 | { |
| 805 | struct pci_dev *pcidev = phba->pcidev; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 806 | struct hwi_controller *phwi_ctrlr; |
| 807 | struct hwi_context_memory *phwi_context; |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 808 | int ret, i, j; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 809 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 810 | phwi_ctrlr = phba->phwi_ctrlr; |
| 811 | phwi_context = phwi_ctrlr->phwi_ctxt; |
| 812 | |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 813 | if (pcidev->msix_enabled) { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 814 | for (i = 0; i < phba->num_cpus; i++) { |
Himanshu Jha | d38c9a8 | 2017-10-11 21:06:14 +0530 | [diff] [blame] | 815 | phba->msi_name[i] = kasprintf(GFP_KERNEL, |
| 816 | "beiscsi_%02x_%02x", |
| 817 | phba->shost->host_no, i); |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 818 | if (!phba->msi_name[i]) { |
| 819 | ret = -ENOMEM; |
| 820 | goto free_msix_irqs; |
| 821 | } |
| 822 | |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 823 | ret = request_irq(pci_irq_vector(pcidev, i), |
| 824 | be_isr_msix, 0, phba->msi_name[i], |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 825 | &phwi_context->be_eq[i]); |
Jayamohan Kallickal | 4f5af07 | 2010-07-22 04:23:55 +0530 | [diff] [blame] | 826 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 827 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 828 | "BM_%d : beiscsi_init_irqs-Failed to" |
| 829 | "register msix for i = %d\n", |
| 830 | i); |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 831 | kfree(phba->msi_name[i]); |
Jayamohan Kallickal | 4f5af07 | 2010-07-22 04:23:55 +0530 | [diff] [blame] | 832 | goto free_msix_irqs; |
| 833 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 834 | } |
Himanshu Jha | d38c9a8 | 2017-10-11 21:06:14 +0530 | [diff] [blame] | 835 | phba->msi_name[i] = kasprintf(GFP_KERNEL, "beiscsi_mcc_%02x", |
| 836 | phba->shost->host_no); |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 837 | if (!phba->msi_name[i]) { |
| 838 | ret = -ENOMEM; |
| 839 | goto free_msix_irqs; |
| 840 | } |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 841 | ret = request_irq(pci_irq_vector(pcidev, i), be_isr_mcc, 0, |
| 842 | phba->msi_name[i], &phwi_context->be_eq[i]); |
Jayamohan Kallickal | 4f5af07 | 2010-07-22 04:23:55 +0530 | [diff] [blame] | 843 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 844 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT , |
| 845 | "BM_%d : beiscsi_init_irqs-" |
| 846 | "Failed to register beiscsi_msix_mcc\n"); |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 847 | kfree(phba->msi_name[i]); |
Jayamohan Kallickal | 4f5af07 | 2010-07-22 04:23:55 +0530 | [diff] [blame] | 848 | goto free_msix_irqs; |
| 849 | } |
| 850 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 851 | } else { |
| 852 | ret = request_irq(pcidev->irq, be_isr, IRQF_SHARED, |
| 853 | "beiscsi", phba); |
| 854 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 855 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 856 | "BM_%d : beiscsi_init_irqs-" |
| 857 | "Failed to register irq\\n"); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 858 | return ret; |
| 859 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 860 | } |
| 861 | return 0; |
Jayamohan Kallickal | 4f5af07 | 2010-07-22 04:23:55 +0530 | [diff] [blame] | 862 | free_msix_irqs: |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 863 | for (j = i - 1; j >= 0; j--) { |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 864 | free_irq(pci_irq_vector(pcidev, i), &phwi_context->be_eq[j]); |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 865 | kfree(phba->msi_name[j]); |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 866 | } |
Jayamohan Kallickal | 4f5af07 | 2010-07-22 04:23:55 +0530 | [diff] [blame] | 867 | return ret; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 868 | } |
| 869 | |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 870 | void hwi_ring_cq_db(struct beiscsi_hba *phba, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 871 | unsigned int id, unsigned int num_processed, |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 872 | unsigned char rearm) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 873 | { |
| 874 | u32 val = 0; |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 875 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 876 | if (rearm) |
| 877 | val |= 1 << DB_CQ_REARM_SHIFT; |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 878 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 879 | val |= num_processed << DB_CQ_NUM_POPPED_SHIFT; |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 880 | |
| 881 | /* Setting lower order CQ_ID Bits */ |
| 882 | val |= (id & DB_CQ_RING_ID_LOW_MASK); |
| 883 | |
| 884 | /* Setting Higher order CQ_ID Bits */ |
| 885 | val |= (((id >> DB_CQ_HIGH_FEILD_SHIFT) & |
| 886 | DB_CQ_RING_ID_HIGH_MASK) |
| 887 | << DB_CQ_HIGH_SET_SHIFT); |
| 888 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 889 | iowrite32(val, phba->db_va + DB_CQ_OFFSET); |
| 890 | } |
| 891 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 892 | static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba) |
| 893 | { |
| 894 | struct sgl_handle *psgl_handle; |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 895 | unsigned long flags; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 896 | |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 897 | spin_lock_irqsave(&phba->io_sgl_lock, flags); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 898 | if (phba->io_sgl_hndl_avbl) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 899 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO, |
| 900 | "BM_%d : In alloc_io_sgl_handle," |
| 901 | " io_sgl_alloc_index=%d\n", |
| 902 | phba->io_sgl_alloc_index); |
| 903 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 904 | psgl_handle = phba->io_sgl_hndl_base[phba-> |
| 905 | io_sgl_alloc_index]; |
| 906 | phba->io_sgl_hndl_base[phba->io_sgl_alloc_index] = NULL; |
| 907 | phba->io_sgl_hndl_avbl--; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 908 | if (phba->io_sgl_alloc_index == (phba->params. |
| 909 | ios_per_ctrl - 1)) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 910 | phba->io_sgl_alloc_index = 0; |
| 911 | else |
| 912 | phba->io_sgl_alloc_index++; |
| 913 | } else |
| 914 | psgl_handle = NULL; |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 915 | spin_unlock_irqrestore(&phba->io_sgl_lock, flags); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 916 | return psgl_handle; |
| 917 | } |
| 918 | |
| 919 | static void |
| 920 | free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle) |
| 921 | { |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 922 | unsigned long flags; |
| 923 | |
| 924 | spin_lock_irqsave(&phba->io_sgl_lock, flags); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 925 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO, |
| 926 | "BM_%d : In free_,io_sgl_free_index=%d\n", |
| 927 | phba->io_sgl_free_index); |
| 928 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 929 | if (phba->io_sgl_hndl_base[phba->io_sgl_free_index]) { |
| 930 | /* |
| 931 | * this can happen if clean_task is called on a task that |
| 932 | * failed in xmit_task or alloc_pdu. |
| 933 | */ |
Jitendra Bhivare | 45efc940 | 2017-10-10 16:18:18 +0530 | [diff] [blame] | 934 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO, |
| 935 | "BM_%d : Double Free in IO SGL io_sgl_free_index=%d, value there=%p\n", |
| 936 | phba->io_sgl_free_index, |
| 937 | phba->io_sgl_hndl_base[phba->io_sgl_free_index]); |
| 938 | spin_unlock_irqrestore(&phba->io_sgl_lock, flags); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 939 | return; |
| 940 | } |
| 941 | phba->io_sgl_hndl_base[phba->io_sgl_free_index] = psgl_handle; |
| 942 | phba->io_sgl_hndl_avbl++; |
| 943 | if (phba->io_sgl_free_index == (phba->params.ios_per_ctrl - 1)) |
| 944 | phba->io_sgl_free_index = 0; |
| 945 | else |
| 946 | phba->io_sgl_free_index++; |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 947 | spin_unlock_irqrestore(&phba->io_sgl_lock, flags); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 948 | } |
| 949 | |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame] | 950 | static inline struct wrb_handle * |
| 951 | beiscsi_get_wrb_handle(struct hwi_wrb_context *pwrb_context, |
| 952 | unsigned int wrbs_per_cxn) |
| 953 | { |
| 954 | struct wrb_handle *pwrb_handle; |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 955 | unsigned long flags; |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame] | 956 | |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 957 | spin_lock_irqsave(&pwrb_context->wrb_lock, flags); |
Jitendra Bhivare | 3f7f62e | 2016-12-13 15:55:58 +0530 | [diff] [blame] | 958 | if (!pwrb_context->wrb_handles_available) { |
| 959 | spin_unlock_irqrestore(&pwrb_context->wrb_lock, flags); |
| 960 | return NULL; |
| 961 | } |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame] | 962 | pwrb_handle = pwrb_context->pwrb_handle_base[pwrb_context->alloc_index]; |
| 963 | pwrb_context->wrb_handles_available--; |
| 964 | if (pwrb_context->alloc_index == (wrbs_per_cxn - 1)) |
| 965 | pwrb_context->alloc_index = 0; |
| 966 | else |
| 967 | pwrb_context->alloc_index++; |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 968 | spin_unlock_irqrestore(&pwrb_context->wrb_lock, flags); |
Jitendra Bhivare | bf9b755 | 2016-08-26 15:09:07 +0530 | [diff] [blame] | 969 | |
| 970 | if (pwrb_handle) |
| 971 | memset(pwrb_handle->pwrb, 0, sizeof(*pwrb_handle->pwrb)); |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame] | 972 | |
| 973 | return pwrb_handle; |
| 974 | } |
| 975 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 976 | /** |
| 977 | * alloc_wrb_handle - To allocate a wrb handle |
| 978 | * @phba: The hba pointer |
| 979 | * @cid: The cid to use for allocation |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 980 | * @pwrb_context: ptr to ptr to wrb context |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 981 | * |
| 982 | * This happens under session_lock until submission to chip |
| 983 | */ |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 984 | 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] | 985 | struct hwi_wrb_context **pcontext) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 986 | { |
| 987 | struct hwi_wrb_context *pwrb_context; |
| 988 | struct hwi_controller *phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 989 | uint16_t cri_index = BE_GET_CRI_FROM_CID(cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 990 | |
| 991 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 992 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame] | 993 | /* return the context address */ |
| 994 | *pcontext = pwrb_context; |
| 995 | return beiscsi_get_wrb_handle(pwrb_context, phba->params.wrbs_per_cxn); |
| 996 | } |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 997 | |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame] | 998 | static inline void |
| 999 | beiscsi_put_wrb_handle(struct hwi_wrb_context *pwrb_context, |
| 1000 | struct wrb_handle *pwrb_handle, |
| 1001 | unsigned int wrbs_per_cxn) |
| 1002 | { |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 1003 | unsigned long flags; |
| 1004 | |
| 1005 | spin_lock_irqsave(&pwrb_context->wrb_lock, flags); |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame] | 1006 | pwrb_context->pwrb_handle_base[pwrb_context->free_index] = pwrb_handle; |
| 1007 | pwrb_context->wrb_handles_available++; |
| 1008 | if (pwrb_context->free_index == (wrbs_per_cxn - 1)) |
| 1009 | pwrb_context->free_index = 0; |
| 1010 | else |
| 1011 | pwrb_context->free_index++; |
Jitendra Bhivare | 3f7f62e | 2016-12-13 15:55:58 +0530 | [diff] [blame] | 1012 | pwrb_handle->pio_handle = NULL; |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 1013 | spin_unlock_irqrestore(&pwrb_context->wrb_lock, flags); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | /** |
| 1017 | * free_wrb_handle - To free the wrb handle back to pool |
| 1018 | * @phba: The hba pointer |
| 1019 | * @pwrb_context: The context to free from |
| 1020 | * @pwrb_handle: The wrb_handle to free |
| 1021 | * |
| 1022 | * This happens under session_lock until submission to chip |
| 1023 | */ |
| 1024 | static void |
| 1025 | free_wrb_handle(struct beiscsi_hba *phba, struct hwi_wrb_context *pwrb_context, |
| 1026 | struct wrb_handle *pwrb_handle) |
| 1027 | { |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame] | 1028 | beiscsi_put_wrb_handle(pwrb_context, |
| 1029 | pwrb_handle, |
| 1030 | phba->params.wrbs_per_cxn); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1031 | beiscsi_log(phba, KERN_INFO, |
| 1032 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
| 1033 | "BM_%d : FREE WRB: pwrb_handle=%p free_index=0x%x" |
| 1034 | "wrb_handles_available=%d\n", |
| 1035 | pwrb_handle, pwrb_context->free_index, |
| 1036 | pwrb_context->wrb_handles_available); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba) |
| 1040 | { |
| 1041 | struct sgl_handle *psgl_handle; |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 1042 | unsigned long flags; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1043 | |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 1044 | spin_lock_irqsave(&phba->mgmt_sgl_lock, flags); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1045 | if (phba->eh_sgl_hndl_avbl) { |
| 1046 | psgl_handle = phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index]; |
| 1047 | phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index] = NULL; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1048 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG, |
| 1049 | "BM_%d : mgmt_sgl_alloc_index=%d=0x%x\n", |
| 1050 | phba->eh_sgl_alloc_index, |
| 1051 | phba->eh_sgl_alloc_index); |
| 1052 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1053 | phba->eh_sgl_hndl_avbl--; |
| 1054 | if (phba->eh_sgl_alloc_index == |
| 1055 | (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl - |
| 1056 | 1)) |
| 1057 | phba->eh_sgl_alloc_index = 0; |
| 1058 | else |
| 1059 | phba->eh_sgl_alloc_index++; |
| 1060 | } else |
| 1061 | psgl_handle = NULL; |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 1062 | spin_unlock_irqrestore(&phba->mgmt_sgl_lock, flags); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1063 | return psgl_handle; |
| 1064 | } |
| 1065 | |
| 1066 | void |
| 1067 | free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle) |
| 1068 | { |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 1069 | unsigned long flags; |
| 1070 | |
| 1071 | spin_lock_irqsave(&phba->mgmt_sgl_lock, flags); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1072 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG, |
| 1073 | "BM_%d : In free_mgmt_sgl_handle," |
| 1074 | "eh_sgl_free_index=%d\n", |
| 1075 | phba->eh_sgl_free_index); |
| 1076 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1077 | if (phba->eh_sgl_hndl_base[phba->eh_sgl_free_index]) { |
| 1078 | /* |
| 1079 | * this can happen if clean_task is called on a task that |
| 1080 | * failed in xmit_task or alloc_pdu. |
| 1081 | */ |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1082 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG, |
| 1083 | "BM_%d : Double Free in eh SGL ," |
| 1084 | "eh_sgl_free_index=%d\n", |
| 1085 | phba->eh_sgl_free_index); |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 1086 | spin_unlock_irqrestore(&phba->mgmt_sgl_lock, flags); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1087 | return; |
| 1088 | } |
| 1089 | phba->eh_sgl_hndl_base[phba->eh_sgl_free_index] = psgl_handle; |
| 1090 | phba->eh_sgl_hndl_avbl++; |
| 1091 | if (phba->eh_sgl_free_index == |
| 1092 | (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl - 1)) |
| 1093 | phba->eh_sgl_free_index = 0; |
| 1094 | else |
| 1095 | phba->eh_sgl_free_index++; |
Jitendra Bhivare | 7d2c0d6 | 2016-10-13 12:08:49 +0530 | [diff] [blame] | 1096 | spin_unlock_irqrestore(&phba->mgmt_sgl_lock, flags); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | static void |
| 1100 | be_complete_io(struct beiscsi_conn *beiscsi_conn, |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1101 | struct iscsi_task *task, |
| 1102 | struct common_sol_cqe *csol_cqe) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1103 | { |
| 1104 | struct beiscsi_io_task *io_task = task->dd_data; |
| 1105 | struct be_status_bhs *sts_bhs = |
| 1106 | (struct be_status_bhs *)io_task->cmd_bhs; |
| 1107 | struct iscsi_conn *conn = beiscsi_conn->conn; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1108 | unsigned char *sense; |
| 1109 | u32 resid = 0, exp_cmdsn, max_cmdsn; |
| 1110 | u8 rsp, status, flags; |
| 1111 | |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1112 | exp_cmdsn = csol_cqe->exp_cmdsn; |
| 1113 | max_cmdsn = (csol_cqe->exp_cmdsn + |
| 1114 | csol_cqe->cmd_wnd - 1); |
| 1115 | rsp = csol_cqe->i_resp; |
| 1116 | status = csol_cqe->i_sts; |
| 1117 | flags = csol_cqe->i_flags; |
| 1118 | resid = csol_cqe->res_cnt; |
| 1119 | |
Jayamohan Kallickal | bd53545 | 2011-10-07 19:31:10 -0500 | [diff] [blame] | 1120 | if (!task->sc) { |
Jayamohan Kallickal | da33497 | 2014-01-29 02:16:44 -0500 | [diff] [blame] | 1121 | if (io_task->scsi_cmnd) { |
Jayamohan Kallickal | bd53545 | 2011-10-07 19:31:10 -0500 | [diff] [blame] | 1122 | scsi_dma_unmap(io_task->scsi_cmnd); |
Jayamohan Kallickal | da33497 | 2014-01-29 02:16:44 -0500 | [diff] [blame] | 1123 | io_task->scsi_cmnd = NULL; |
| 1124 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1125 | |
Jayamohan Kallickal | bd53545 | 2011-10-07 19:31:10 -0500 | [diff] [blame] | 1126 | return; |
| 1127 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1128 | task->sc->result = (DID_OK << 16) | status; |
| 1129 | if (rsp != ISCSI_STATUS_CMD_COMPLETED) { |
| 1130 | task->sc->result = DID_ERROR << 16; |
| 1131 | goto unmap; |
| 1132 | } |
| 1133 | |
| 1134 | /* bidi not initially supported */ |
| 1135 | if (flags & (ISCSI_FLAG_CMD_UNDERFLOW | ISCSI_FLAG_CMD_OVERFLOW)) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1136 | if (!status && (flags & ISCSI_FLAG_CMD_OVERFLOW)) |
| 1137 | task->sc->result = DID_ERROR << 16; |
| 1138 | |
| 1139 | if (flags & ISCSI_FLAG_CMD_UNDERFLOW) { |
| 1140 | scsi_set_resid(task->sc, resid); |
| 1141 | if (!status && (scsi_bufflen(task->sc) - resid < |
| 1142 | task->sc->underflow)) |
| 1143 | task->sc->result = DID_ERROR << 16; |
| 1144 | } |
| 1145 | } |
| 1146 | |
| 1147 | if (status == SAM_STAT_CHECK_CONDITION) { |
Dan Carpenter | 4053a4b | 2011-09-26 09:23:37 +0300 | [diff] [blame] | 1148 | u16 sense_len; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1149 | unsigned short *slen = (unsigned short *)sts_bhs->sense_info; |
Dan Carpenter | 4053a4b | 2011-09-26 09:23:37 +0300 | [diff] [blame] | 1150 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1151 | sense = sts_bhs->sense_info + sizeof(unsigned short); |
Dan Carpenter | 4053a4b | 2011-09-26 09:23:37 +0300 | [diff] [blame] | 1152 | sense_len = be16_to_cpu(*slen); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1153 | memcpy(task->sc->sense_buffer, sense, |
| 1154 | min_t(u16, sense_len, SCSI_SENSE_BUFFERSIZE)); |
| 1155 | } |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 1156 | |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1157 | if (io_task->cmd_bhs->iscsi_hdr.flags & ISCSI_FLAG_CMD_READ) |
| 1158 | conn->rxdata_octets += resid; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1159 | unmap: |
John Soni Jose | eb1c469 | 2015-04-25 08:17:45 +0530 | [diff] [blame] | 1160 | if (io_task->scsi_cmnd) { |
| 1161 | scsi_dma_unmap(io_task->scsi_cmnd); |
| 1162 | io_task->scsi_cmnd = NULL; |
| 1163 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1164 | iscsi_complete_scsi_task(task, exp_cmdsn, max_cmdsn); |
| 1165 | } |
| 1166 | |
| 1167 | static void |
| 1168 | be_complete_logout(struct beiscsi_conn *beiscsi_conn, |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1169 | struct iscsi_task *task, |
| 1170 | struct common_sol_cqe *csol_cqe) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1171 | { |
| 1172 | struct iscsi_logout_rsp *hdr; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1173 | struct beiscsi_io_task *io_task = task->dd_data; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1174 | struct iscsi_conn *conn = beiscsi_conn->conn; |
| 1175 | |
| 1176 | hdr = (struct iscsi_logout_rsp *)task->hdr; |
Jayamohan Kallickal | 7bd6e25 | 2010-01-05 05:07:02 +0530 | [diff] [blame] | 1177 | hdr->opcode = ISCSI_OP_LOGOUT_RSP; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1178 | hdr->t2wait = 5; |
| 1179 | hdr->t2retain = 0; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1180 | hdr->flags = csol_cqe->i_flags; |
| 1181 | hdr->response = csol_cqe->i_resp; |
Jayamohan Kallickal | 702dc5e | 2013-04-05 20:38:37 -0700 | [diff] [blame] | 1182 | hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn); |
| 1183 | hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn + |
| 1184 | csol_cqe->cmd_wnd - 1); |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1185 | |
Jayamohan Kallickal | 7bd6e25 | 2010-01-05 05:07:02 +0530 | [diff] [blame] | 1186 | hdr->dlength[0] = 0; |
| 1187 | hdr->dlength[1] = 0; |
| 1188 | hdr->dlength[2] = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1189 | hdr->hlength = 0; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1190 | hdr->itt = io_task->libiscsi_itt; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1191 | __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0); |
| 1192 | } |
| 1193 | |
| 1194 | static void |
| 1195 | be_complete_tmf(struct beiscsi_conn *beiscsi_conn, |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1196 | struct iscsi_task *task, |
| 1197 | struct common_sol_cqe *csol_cqe) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1198 | { |
| 1199 | struct iscsi_tm_rsp *hdr; |
| 1200 | struct iscsi_conn *conn = beiscsi_conn->conn; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1201 | struct beiscsi_io_task *io_task = task->dd_data; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1202 | |
| 1203 | hdr = (struct iscsi_tm_rsp *)task->hdr; |
Jayamohan Kallickal | 7bd6e25 | 2010-01-05 05:07:02 +0530 | [diff] [blame] | 1204 | hdr->opcode = ISCSI_OP_SCSI_TMFUNC_RSP; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1205 | hdr->flags = csol_cqe->i_flags; |
| 1206 | hdr->response = csol_cqe->i_resp; |
Jayamohan Kallickal | 702dc5e | 2013-04-05 20:38:37 -0700 | [diff] [blame] | 1207 | hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn); |
| 1208 | hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn + |
| 1209 | csol_cqe->cmd_wnd - 1); |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1210 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1211 | hdr->itt = io_task->libiscsi_itt; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1212 | __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0); |
| 1213 | } |
| 1214 | |
| 1215 | static void |
| 1216 | hwi_complete_drvr_msgs(struct beiscsi_conn *beiscsi_conn, |
| 1217 | struct beiscsi_hba *phba, struct sol_cqe *psol) |
| 1218 | { |
| 1219 | struct hwi_wrb_context *pwrb_context; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 1220 | uint16_t wrb_index, cid, cri_index; |
Jitendra Bhivare | e1f9d31 | 2016-08-19 15:20:22 +0530 | [diff] [blame] | 1221 | struct hwi_controller *phwi_ctrlr; |
| 1222 | struct wrb_handle *pwrb_handle; |
Jitendra Bhivare | 3f7f62e | 2016-12-13 15:55:58 +0530 | [diff] [blame] | 1223 | struct iscsi_session *session; |
Jitendra Bhivare | e1f9d31 | 2016-08-19 15:20:22 +0530 | [diff] [blame] | 1224 | struct iscsi_task *task; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1225 | |
| 1226 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 1227 | if (is_chip_be2_be3r(phba)) { |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1228 | wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe, |
| 1229 | wrb_idx, psol); |
| 1230 | cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe, |
| 1231 | cid, psol); |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 1232 | } else { |
| 1233 | wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2, |
| 1234 | wrb_idx, psol); |
| 1235 | cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2, |
| 1236 | cid, psol); |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1237 | } |
| 1238 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 1239 | cri_index = BE_GET_CRI_FROM_CID(cid); |
| 1240 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1241 | pwrb_handle = pwrb_context->pwrb_handle_basestd[wrb_index]; |
Jitendra Bhivare | 3f7f62e | 2016-12-13 15:55:58 +0530 | [diff] [blame] | 1242 | session = beiscsi_conn->conn->session; |
| 1243 | spin_lock_bh(&session->back_lock); |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 1244 | task = pwrb_handle->pio_handle; |
Jitendra Bhivare | 3f7f62e | 2016-12-13 15:55:58 +0530 | [diff] [blame] | 1245 | if (task) |
| 1246 | __iscsi_put_task(task); |
| 1247 | spin_unlock_bh(&session->back_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | static void |
| 1251 | be_complete_nopin_resp(struct beiscsi_conn *beiscsi_conn, |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1252 | struct iscsi_task *task, |
| 1253 | struct common_sol_cqe *csol_cqe) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1254 | { |
| 1255 | struct iscsi_nopin *hdr; |
| 1256 | struct iscsi_conn *conn = beiscsi_conn->conn; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1257 | struct beiscsi_io_task *io_task = task->dd_data; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1258 | |
| 1259 | hdr = (struct iscsi_nopin *)task->hdr; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1260 | hdr->flags = csol_cqe->i_flags; |
| 1261 | hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn); |
Jayamohan Kallickal | 702dc5e | 2013-04-05 20:38:37 -0700 | [diff] [blame] | 1262 | hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn + |
| 1263 | csol_cqe->cmd_wnd - 1); |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1264 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1265 | hdr->opcode = ISCSI_OP_NOOP_IN; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1266 | hdr->itt = io_task->libiscsi_itt; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1267 | __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0); |
| 1268 | } |
| 1269 | |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1270 | static void adapter_get_sol_cqe(struct beiscsi_hba *phba, |
| 1271 | struct sol_cqe *psol, |
| 1272 | struct common_sol_cqe *csol_cqe) |
| 1273 | { |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 1274 | if (is_chip_be2_be3r(phba)) { |
| 1275 | csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1276 | i_exp_cmd_sn, psol); |
| 1277 | csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1278 | i_res_cnt, psol); |
| 1279 | csol_cqe->cmd_wnd = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1280 | i_cmd_wnd, psol); |
| 1281 | csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1282 | wrb_index, psol); |
| 1283 | csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1284 | cid, psol); |
| 1285 | csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1286 | hw_sts, psol); |
| 1287 | csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1288 | i_resp, psol); |
| 1289 | csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1290 | i_sts, psol); |
| 1291 | csol_cqe->i_flags = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1292 | i_flags, psol); |
| 1293 | } else { |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1294 | csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1295 | i_exp_cmd_sn, psol); |
| 1296 | csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1297 | i_res_cnt, psol); |
| 1298 | csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1299 | wrb_index, psol); |
| 1300 | csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1301 | cid, psol); |
| 1302 | csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1303 | hw_sts, psol); |
Jayamohan Kallickal | 702dc5e | 2013-04-05 20:38:37 -0700 | [diff] [blame] | 1304 | 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] | 1305 | i_cmd_wnd, psol); |
| 1306 | if (AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1307 | cmd_cmpl, psol)) |
| 1308 | csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1309 | i_sts, psol); |
| 1310 | else |
| 1311 | csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1312 | i_sts, psol); |
| 1313 | if (AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1314 | u, psol)) |
| 1315 | csol_cqe->i_flags = ISCSI_FLAG_CMD_UNDERFLOW; |
| 1316 | |
| 1317 | if (AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1318 | o, psol)) |
| 1319 | csol_cqe->i_flags |= ISCSI_FLAG_CMD_OVERFLOW; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1320 | } |
| 1321 | } |
| 1322 | |
| 1323 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1324 | static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn, |
| 1325 | struct beiscsi_hba *phba, struct sol_cqe *psol) |
| 1326 | { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1327 | struct iscsi_conn *conn = beiscsi_conn->conn; |
| 1328 | struct iscsi_session *session = conn->session; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1329 | struct common_sol_cqe csol_cqe = {0}; |
Jitendra Bhivare | 3f7f62e | 2016-12-13 15:55:58 +0530 | [diff] [blame] | 1330 | struct hwi_wrb_context *pwrb_context; |
| 1331 | struct hwi_controller *phwi_ctrlr; |
| 1332 | struct wrb_handle *pwrb_handle; |
Jitendra Bhivare | 3f7f62e | 2016-12-13 15:55:58 +0530 | [diff] [blame] | 1333 | struct iscsi_task *task; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 1334 | uint16_t cri_index = 0; |
Jitendra Bhivare | 3f7f62e | 2016-12-13 15:55:58 +0530 | [diff] [blame] | 1335 | uint8_t type; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1336 | |
| 1337 | phwi_ctrlr = phba->phwi_ctrlr; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1338 | |
| 1339 | /* Copy the elements to a common structure */ |
| 1340 | adapter_get_sol_cqe(phba, psol, &csol_cqe); |
| 1341 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 1342 | cri_index = BE_GET_CRI_FROM_CID(csol_cqe.cid); |
| 1343 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1344 | |
| 1345 | pwrb_handle = pwrb_context->pwrb_handle_basestd[ |
| 1346 | csol_cqe.wrb_index]; |
| 1347 | |
Jitendra Bhivare | 3f7f62e | 2016-12-13 15:55:58 +0530 | [diff] [blame] | 1348 | spin_lock_bh(&session->back_lock); |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 1349 | task = pwrb_handle->pio_handle; |
Jitendra Bhivare | 3f7f62e | 2016-12-13 15:55:58 +0530 | [diff] [blame] | 1350 | if (!task) { |
| 1351 | spin_unlock_bh(&session->back_lock); |
| 1352 | return; |
| 1353 | } |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1354 | type = ((struct beiscsi_io_task *)task->dd_data)->wrb_type; |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 1355 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1356 | switch (type) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1357 | case HWH_TYPE_IO: |
| 1358 | case HWH_TYPE_IO_RD: |
| 1359 | if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 1360 | ISCSI_OP_NOOP_OUT) |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1361 | be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe); |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 1362 | else |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1363 | be_complete_io(beiscsi_conn, task, &csol_cqe); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1364 | break; |
| 1365 | |
| 1366 | case HWH_TYPE_LOGOUT: |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 1367 | if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGOUT) |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1368 | be_complete_logout(beiscsi_conn, task, &csol_cqe); |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 1369 | else |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1370 | be_complete_tmf(beiscsi_conn, task, &csol_cqe); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1371 | break; |
| 1372 | |
| 1373 | case HWH_TYPE_LOGIN: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1374 | beiscsi_log(phba, KERN_ERR, |
| 1375 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
| 1376 | "BM_%d :\t\t No HWH_TYPE_LOGIN Expected in" |
| 1377 | " hwi_complete_cmd- Solicited path\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1378 | break; |
| 1379 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1380 | case HWH_TYPE_NOP: |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1381 | be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1382 | break; |
| 1383 | |
| 1384 | default: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1385 | beiscsi_log(phba, KERN_WARNING, |
| 1386 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
| 1387 | "BM_%d : In hwi_complete_cmd, unknown type = %d" |
| 1388 | "wrb_index 0x%x CID 0x%x\n", type, |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1389 | csol_cqe.wrb_index, |
| 1390 | csol_cqe.cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1391 | break; |
| 1392 | } |
Jayamohan Kallickal | 35e6601 | 2009-10-23 11:53:49 +0530 | [diff] [blame] | 1393 | |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 1394 | spin_unlock_bh(&session->back_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1395 | } |
| 1396 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1397 | /** |
| 1398 | * ASYNC PDUs include |
| 1399 | * a. Unsolicited NOP-In (target initiated NOP-In) |
| 1400 | * b. ASYNC Messages |
| 1401 | * c. Reject PDU |
| 1402 | * d. Login response |
| 1403 | * These headers arrive unprocessed by the EP firmware. |
| 1404 | * iSCSI layer processes them. |
| 1405 | */ |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1406 | static unsigned int |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1407 | beiscsi_complete_pdu(struct beiscsi_conn *beiscsi_conn, |
| 1408 | struct pdu_base *phdr, void *pdata, unsigned int dlen) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1409 | { |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1410 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 1411 | struct iscsi_conn *conn = beiscsi_conn->conn; |
| 1412 | struct beiscsi_io_task *io_task; |
| 1413 | struct iscsi_hdr *login_hdr; |
| 1414 | struct iscsi_task *task; |
| 1415 | u8 code; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1416 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1417 | code = AMAP_GET_BITS(struct amap_pdu_base, opcode, phdr); |
| 1418 | switch (code) { |
| 1419 | case ISCSI_OP_NOOP_IN: |
| 1420 | pdata = NULL; |
| 1421 | dlen = 0; |
| 1422 | break; |
| 1423 | case ISCSI_OP_ASYNC_EVENT: |
| 1424 | break; |
| 1425 | case ISCSI_OP_REJECT: |
| 1426 | WARN_ON(!pdata); |
| 1427 | WARN_ON(!(dlen == 48)); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1428 | beiscsi_log(phba, KERN_ERR, |
| 1429 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1430 | "BM_%d : In ISCSI_OP_REJECT\n"); |
| 1431 | break; |
| 1432 | case ISCSI_OP_LOGIN_RSP: |
| 1433 | case ISCSI_OP_TEXT_RSP: |
| 1434 | task = conn->login_task; |
| 1435 | io_task = task->dd_data; |
| 1436 | login_hdr = (struct iscsi_hdr *)phdr; |
| 1437 | login_hdr->itt = io_task->libiscsi_itt; |
| 1438 | break; |
| 1439 | default: |
| 1440 | beiscsi_log(phba, KERN_WARNING, |
| 1441 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
| 1442 | "BM_%d : unrecognized async PDU opcode 0x%x\n", |
| 1443 | code); |
| 1444 | return 1; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1445 | } |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1446 | __iscsi_complete_pdu(conn, (struct iscsi_hdr *)phdr, pdata, dlen); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1447 | return 0; |
| 1448 | } |
| 1449 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1450 | static inline void |
| 1451 | beiscsi_hdl_put_handle(struct hd_async_context *pasync_ctx, |
| 1452 | struct hd_async_handle *pasync_handle) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1453 | { |
Jitendra Bhivare | ba6983a | 2017-03-24 14:11:46 +0530 | [diff] [blame] | 1454 | pasync_handle->is_final = 0; |
| 1455 | pasync_handle->buffer_len = 0; |
| 1456 | pasync_handle->in_use = 0; |
| 1457 | list_del_init(&pasync_handle->link); |
| 1458 | } |
| 1459 | |
| 1460 | static void |
| 1461 | beiscsi_hdl_purge_handles(struct beiscsi_hba *phba, |
| 1462 | struct hd_async_context *pasync_ctx, |
| 1463 | u16 cri) |
| 1464 | { |
| 1465 | struct hd_async_handle *pasync_handle, *tmp_handle; |
| 1466 | struct list_head *plist; |
| 1467 | |
| 1468 | plist = &pasync_ctx->async_entry[cri].wq.list; |
| 1469 | list_for_each_entry_safe(pasync_handle, tmp_handle, plist, link) |
| 1470 | beiscsi_hdl_put_handle(pasync_ctx, pasync_handle); |
| 1471 | |
| 1472 | INIT_LIST_HEAD(&pasync_ctx->async_entry[cri].wq.list); |
| 1473 | pasync_ctx->async_entry[cri].wq.hdr_len = 0; |
| 1474 | pasync_ctx->async_entry[cri].wq.bytes_received = 0; |
| 1475 | pasync_ctx->async_entry[cri].wq.bytes_needed = 0; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1476 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1477 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1478 | static struct hd_async_handle * |
| 1479 | beiscsi_hdl_get_handle(struct beiscsi_conn *beiscsi_conn, |
| 1480 | struct hd_async_context *pasync_ctx, |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1481 | struct i_t_dpdu_cqe *pdpdu_cqe, |
| 1482 | u8 *header) |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1483 | { |
| 1484 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 1485 | struct hd_async_handle *pasync_handle; |
| 1486 | struct be_bus_address phys_addr; |
Jitendra Bhivare | ba6983a | 2017-03-24 14:11:46 +0530 | [diff] [blame] | 1487 | u16 cid, code, ci, cri; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1488 | u8 final, error = 0; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1489 | u32 dpl; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1490 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1491 | cid = beiscsi_conn->beiscsi_conn_cid; |
Jitendra Bhivare | ba6983a | 2017-03-24 14:11:46 +0530 | [diff] [blame] | 1492 | cri = BE_GET_ASYNC_CRI_FROM_CID(cid); |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1493 | /** |
| 1494 | * This function is invoked to get the right async_handle structure |
| 1495 | * from a given DEF PDU CQ entry. |
| 1496 | * |
| 1497 | * - index in CQ entry gives the vertical index |
| 1498 | * - address in CQ entry is the offset where the DMA last ended |
| 1499 | * - final - no more notifications for this PDU |
| 1500 | */ |
| 1501 | if (is_chip_be2_be3r(phba)) { |
| 1502 | dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, |
| 1503 | dpl, pdpdu_cqe); |
| 1504 | ci = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, |
| 1505 | index, pdpdu_cqe); |
| 1506 | final = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, |
| 1507 | final, pdpdu_cqe); |
| 1508 | } else { |
| 1509 | dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2, |
| 1510 | dpl, pdpdu_cqe); |
| 1511 | ci = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2, |
| 1512 | index, pdpdu_cqe); |
| 1513 | final = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2, |
| 1514 | final, pdpdu_cqe); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1515 | } |
| 1516 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1517 | /** |
| 1518 | * DB addr Hi/Lo is same for BE and SKH. |
| 1519 | * Subtract the dataplacementlength to get to the base. |
| 1520 | */ |
| 1521 | phys_addr.u.a32.address_lo = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, |
| 1522 | db_addr_lo, pdpdu_cqe); |
| 1523 | phys_addr.u.a32.address_lo -= dpl; |
| 1524 | phys_addr.u.a32.address_hi = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, |
| 1525 | db_addr_hi, pdpdu_cqe); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1526 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1527 | code = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, code, pdpdu_cqe); |
| 1528 | switch (code) { |
| 1529 | case UNSOL_HDR_NOTIFY: |
| 1530 | pasync_handle = pasync_ctx->async_entry[ci].header; |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1531 | *header = 1; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1532 | break; |
| 1533 | case UNSOL_DATA_DIGEST_ERROR_NOTIFY: |
| 1534 | error = 1; |
| 1535 | case UNSOL_DATA_NOTIFY: |
| 1536 | pasync_handle = pasync_ctx->async_entry[ci].data; |
| 1537 | break; |
| 1538 | /* called only for above codes */ |
| 1539 | default: |
Jitendra Bhivare | ba6983a | 2017-03-24 14:11:46 +0530 | [diff] [blame] | 1540 | return NULL; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1541 | } |
| 1542 | |
| 1543 | if (pasync_handle->pa.u.a64.address != phys_addr.u.a64.address || |
| 1544 | pasync_handle->index != ci) { |
| 1545 | /* driver bug - if ci does not match async handle index */ |
| 1546 | error = 1; |
| 1547 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_ISCSI, |
| 1548 | "BM_%d : cid %u async PDU handle mismatch - addr in %cQE %llx at %u:addr in CQE %llx ci %u\n", |
| 1549 | cid, pasync_handle->is_header ? 'H' : 'D', |
| 1550 | pasync_handle->pa.u.a64.address, |
| 1551 | pasync_handle->index, |
| 1552 | phys_addr.u.a64.address, ci); |
| 1553 | /* FW has stale address - attempt continuing by dropping */ |
| 1554 | } |
| 1555 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1556 | /** |
| 1557 | * DEF PDU header and data buffers with errors should be simply |
| 1558 | * dropped as there are no consumers for it. |
| 1559 | */ |
| 1560 | if (error) { |
| 1561 | beiscsi_hdl_put_handle(pasync_ctx, pasync_handle); |
Jitendra Bhivare | ba6983a | 2017-03-24 14:11:46 +0530 | [diff] [blame] | 1562 | return NULL; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1563 | } |
Jitendra Bhivare | ba6983a | 2017-03-24 14:11:46 +0530 | [diff] [blame] | 1564 | |
| 1565 | if (pasync_handle->in_use || !list_empty(&pasync_handle->link)) { |
| 1566 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_ISCSI, |
| 1567 | "BM_%d : cid %d async PDU handle in use - code %d ci %d addr %llx\n", |
| 1568 | cid, code, ci, phys_addr.u.a64.address); |
| 1569 | beiscsi_hdl_purge_handles(phba, pasync_ctx, cri); |
| 1570 | } |
| 1571 | |
| 1572 | list_del_init(&pasync_handle->link); |
| 1573 | /** |
| 1574 | * Each CID is associated with unique CRI. |
| 1575 | * ASYNC_CRI_FROM_CID mapping and CRI_FROM_CID are totaly different. |
| 1576 | **/ |
| 1577 | pasync_handle->cri = cri; |
| 1578 | pasync_handle->is_final = final; |
| 1579 | pasync_handle->buffer_len = dpl; |
| 1580 | pasync_handle->in_use = 1; |
| 1581 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1582 | return pasync_handle; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1583 | } |
| 1584 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1585 | static unsigned int |
| 1586 | beiscsi_hdl_fwd_pdu(struct beiscsi_conn *beiscsi_conn, |
| 1587 | struct hd_async_context *pasync_ctx, |
| 1588 | u16 cri) |
| 1589 | { |
| 1590 | struct iscsi_session *session = beiscsi_conn->conn->session; |
| 1591 | struct hd_async_handle *pasync_handle, *plast_handle; |
| 1592 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 1593 | void *phdr = NULL, *pdata = NULL; |
| 1594 | u32 dlen = 0, status = 0; |
| 1595 | struct list_head *plist; |
| 1596 | |
| 1597 | plist = &pasync_ctx->async_entry[cri].wq.list; |
| 1598 | plast_handle = NULL; |
| 1599 | list_for_each_entry(pasync_handle, plist, link) { |
| 1600 | plast_handle = pasync_handle; |
| 1601 | /* get the header, the first entry */ |
| 1602 | if (!phdr) { |
| 1603 | phdr = pasync_handle->pbuffer; |
| 1604 | continue; |
| 1605 | } |
| 1606 | /* use first buffer to collect all the data */ |
| 1607 | if (!pdata) { |
| 1608 | pdata = pasync_handle->pbuffer; |
| 1609 | dlen = pasync_handle->buffer_len; |
| 1610 | continue; |
| 1611 | } |
Jitendra Bhivare | 0ddee50 | 2017-03-24 14:11:47 +0530 | [diff] [blame] | 1612 | if (!pasync_handle->buffer_len || |
| 1613 | (dlen + pasync_handle->buffer_len) > |
| 1614 | pasync_ctx->async_data.buffer_size) |
| 1615 | break; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1616 | memcpy(pdata + dlen, pasync_handle->pbuffer, |
| 1617 | pasync_handle->buffer_len); |
| 1618 | dlen += pasync_handle->buffer_len; |
| 1619 | } |
| 1620 | |
| 1621 | if (!plast_handle->is_final) { |
| 1622 | /* last handle should have final PDU notification from FW */ |
| 1623 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_ISCSI, |
Jitendra Bhivare | 0ddee50 | 2017-03-24 14:11:47 +0530 | [diff] [blame] | 1624 | "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] | 1625 | beiscsi_conn->beiscsi_conn_cid, plast_handle, |
Jitendra Bhivare | 0ddee50 | 2017-03-24 14:11:47 +0530 | [diff] [blame] | 1626 | AMAP_GET_BITS(struct amap_pdu_base, opcode, phdr), |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1627 | pasync_ctx->async_entry[cri].wq.hdr_len, |
| 1628 | pasync_ctx->async_entry[cri].wq.bytes_needed, |
| 1629 | pasync_ctx->async_entry[cri].wq.bytes_received); |
| 1630 | } |
| 1631 | spin_lock_bh(&session->back_lock); |
| 1632 | status = beiscsi_complete_pdu(beiscsi_conn, phdr, pdata, dlen); |
| 1633 | spin_unlock_bh(&session->back_lock); |
| 1634 | beiscsi_hdl_purge_handles(phba, pasync_ctx, cri); |
| 1635 | return status; |
| 1636 | } |
| 1637 | |
| 1638 | static unsigned int |
| 1639 | beiscsi_hdl_gather_pdu(struct beiscsi_conn *beiscsi_conn, |
| 1640 | struct hd_async_context *pasync_ctx, |
| 1641 | struct hd_async_handle *pasync_handle) |
| 1642 | { |
| 1643 | unsigned int bytes_needed = 0, status = 0; |
| 1644 | u16 cri = pasync_handle->cri; |
| 1645 | struct cri_wait_queue *wq; |
| 1646 | struct beiscsi_hba *phba; |
| 1647 | struct pdu_base *ppdu; |
| 1648 | char *err = ""; |
| 1649 | |
| 1650 | phba = beiscsi_conn->phba; |
| 1651 | wq = &pasync_ctx->async_entry[cri].wq; |
| 1652 | if (pasync_handle->is_header) { |
| 1653 | /* check if PDU hdr is rcv'd when old hdr not completed */ |
| 1654 | if (wq->hdr_len) { |
| 1655 | err = "incomplete"; |
| 1656 | goto drop_pdu; |
| 1657 | } |
| 1658 | ppdu = pasync_handle->pbuffer; |
| 1659 | bytes_needed = AMAP_GET_BITS(struct amap_pdu_base, |
| 1660 | data_len_hi, ppdu); |
| 1661 | bytes_needed <<= 16; |
| 1662 | bytes_needed |= be16_to_cpu(AMAP_GET_BITS(struct amap_pdu_base, |
| 1663 | data_len_lo, ppdu)); |
| 1664 | wq->hdr_len = pasync_handle->buffer_len; |
| 1665 | wq->bytes_received = 0; |
| 1666 | wq->bytes_needed = bytes_needed; |
| 1667 | list_add_tail(&pasync_handle->link, &wq->list); |
| 1668 | if (!bytes_needed) |
| 1669 | status = beiscsi_hdl_fwd_pdu(beiscsi_conn, |
| 1670 | pasync_ctx, cri); |
| 1671 | } else { |
| 1672 | /* check if data received has header and is needed */ |
| 1673 | if (!wq->hdr_len || !wq->bytes_needed) { |
| 1674 | err = "header less"; |
| 1675 | goto drop_pdu; |
| 1676 | } |
| 1677 | wq->bytes_received += pasync_handle->buffer_len; |
| 1678 | /* Something got overwritten? Better catch it here. */ |
| 1679 | if (wq->bytes_received > wq->bytes_needed) { |
| 1680 | err = "overflow"; |
| 1681 | goto drop_pdu; |
| 1682 | } |
| 1683 | list_add_tail(&pasync_handle->link, &wq->list); |
| 1684 | if (wq->bytes_received == wq->bytes_needed) |
| 1685 | status = beiscsi_hdl_fwd_pdu(beiscsi_conn, |
| 1686 | pasync_ctx, cri); |
| 1687 | } |
| 1688 | return status; |
| 1689 | |
| 1690 | drop_pdu: |
| 1691 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_ISCSI, |
| 1692 | "BM_%d : cid %u async PDU %s - def-%c:HL%u:DN%u:DR%u\n", |
| 1693 | beiscsi_conn->beiscsi_conn_cid, err, |
| 1694 | pasync_handle->is_header ? 'H' : 'D', |
| 1695 | wq->hdr_len, wq->bytes_needed, |
| 1696 | pasync_handle->buffer_len); |
| 1697 | /* discard this handle */ |
| 1698 | beiscsi_hdl_put_handle(pasync_ctx, pasync_handle); |
| 1699 | /* free all the other handles in cri_wait_queue */ |
| 1700 | beiscsi_hdl_purge_handles(phba, pasync_ctx, cri); |
| 1701 | /* try continuing */ |
| 1702 | return status; |
| 1703 | } |
| 1704 | |
| 1705 | static void |
| 1706 | beiscsi_hdq_post_handles(struct beiscsi_hba *phba, |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1707 | u8 header, u8 ulp_num, u16 nbuf) |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1708 | { |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1709 | struct hd_async_handle *pasync_handle; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1710 | struct hd_async_context *pasync_ctx; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1711 | struct hwi_controller *phwi_ctrlr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1712 | struct phys_addr *pasync_sge; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1713 | u32 ring_id, doorbell = 0; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1714 | u32 doorbell_offset; |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1715 | u16 prod, pi; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1716 | |
| 1717 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1718 | pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr, ulp_num); |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1719 | if (header) { |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1720 | pasync_sge = pasync_ctx->async_header.ring_base; |
| 1721 | pi = pasync_ctx->async_header.pi; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1722 | ring_id = phwi_ctrlr->default_pdu_hdr[ulp_num].id; |
| 1723 | doorbell_offset = phwi_ctrlr->default_pdu_hdr[ulp_num]. |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1724 | doorbell_offset; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1725 | } else { |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1726 | pasync_sge = pasync_ctx->async_data.ring_base; |
| 1727 | pi = pasync_ctx->async_data.pi; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1728 | ring_id = phwi_ctrlr->default_pdu_data[ulp_num].id; |
| 1729 | doorbell_offset = phwi_ctrlr->default_pdu_data[ulp_num]. |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1730 | doorbell_offset; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1731 | } |
| 1732 | |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1733 | for (prod = 0; prod < nbuf; prod++) { |
| 1734 | if (header) |
| 1735 | pasync_handle = pasync_ctx->async_entry[pi].header; |
| 1736 | else |
| 1737 | pasync_handle = pasync_ctx->async_entry[pi].data; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1738 | WARN_ON(pasync_handle->is_header != header); |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1739 | WARN_ON(pasync_handle->index != pi); |
| 1740 | /* setup the ring only once */ |
| 1741 | if (nbuf == pasync_ctx->num_entries) { |
| 1742 | /* note hi is lo */ |
| 1743 | pasync_sge[pi].hi = pasync_handle->pa.u.a32.address_lo; |
| 1744 | pasync_sge[pi].lo = pasync_handle->pa.u.a32.address_hi; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1745 | } |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1746 | if (++pi == pasync_ctx->num_entries) |
| 1747 | pi = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1748 | } |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1749 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1750 | if (header) |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1751 | pasync_ctx->async_header.pi = pi; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1752 | else |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1753 | pasync_ctx->async_data.pi = pi; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1754 | |
| 1755 | doorbell |= ring_id & DB_DEF_PDU_RING_ID_MASK; |
| 1756 | doorbell |= 1 << DB_DEF_PDU_REARM_SHIFT; |
| 1757 | doorbell |= 0 << DB_DEF_PDU_EVENT_SHIFT; |
| 1758 | doorbell |= (prod & DB_DEF_PDU_CQPROC_MASK) << DB_DEF_PDU_CQPROC_SHIFT; |
| 1759 | iowrite32(doorbell, phba->db_va + doorbell_offset); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1760 | } |
| 1761 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1762 | static void |
| 1763 | beiscsi_hdq_process_compl(struct beiscsi_conn *beiscsi_conn, |
| 1764 | struct i_t_dpdu_cqe *pdpdu_cqe) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1765 | { |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1766 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 1767 | struct hd_async_handle *pasync_handle = NULL; |
| 1768 | struct hd_async_context *pasync_ctx; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1769 | struct hwi_controller *phwi_ctrlr; |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1770 | u8 ulp_num, consumed, header = 0; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1771 | u16 cid_cri; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1772 | |
| 1773 | phwi_ctrlr = phba->phwi_ctrlr; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1774 | cid_cri = BE_GET_CRI_FROM_CID(beiscsi_conn->beiscsi_conn_cid); |
| 1775 | ulp_num = BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr, cid_cri); |
| 1776 | pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr, ulp_num); |
| 1777 | pasync_handle = beiscsi_hdl_get_handle(beiscsi_conn, pasync_ctx, |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 1778 | pdpdu_cqe, &header); |
| 1779 | if (is_chip_be2_be3r(phba)) |
| 1780 | consumed = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, |
| 1781 | num_cons, pdpdu_cqe); |
| 1782 | else |
| 1783 | consumed = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2, |
| 1784 | num_cons, pdpdu_cqe); |
| 1785 | if (pasync_handle) |
| 1786 | beiscsi_hdl_gather_pdu(beiscsi_conn, pasync_ctx, pasync_handle); |
| 1787 | /* num_cons indicates number of 8 RQEs consumed */ |
| 1788 | if (consumed) |
| 1789 | beiscsi_hdq_post_handles(phba, header, ulp_num, 8 * consumed); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1790 | } |
| 1791 | |
Jitendra Bhivare | 2e4e8f6 | 2016-02-04 15:49:11 +0530 | [diff] [blame] | 1792 | void beiscsi_process_mcc_cq(struct beiscsi_hba *phba) |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 1793 | { |
| 1794 | struct be_queue_info *mcc_cq; |
| 1795 | struct be_mcc_compl *mcc_compl; |
| 1796 | unsigned int num_processed = 0; |
| 1797 | |
| 1798 | mcc_cq = &phba->ctrl.mcc_obj.cq; |
| 1799 | mcc_compl = queue_tail_node(mcc_cq); |
| 1800 | mcc_compl->flags = le32_to_cpu(mcc_compl->flags); |
| 1801 | while (mcc_compl->flags & CQE_FLAGS_VALID_MASK) { |
Jitendra Bhivare | 9122e99 | 2016-08-19 15:20:11 +0530 | [diff] [blame] | 1802 | if (beiscsi_hba_in_error(phba)) |
| 1803 | return; |
| 1804 | |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 1805 | if (num_processed >= 32) { |
| 1806 | hwi_ring_cq_db(phba, mcc_cq->id, |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 1807 | num_processed, 0); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 1808 | num_processed = 0; |
| 1809 | } |
| 1810 | if (mcc_compl->flags & CQE_FLAGS_ASYNC_MASK) { |
Jitendra Bhivare | 53aefe2 | 2016-01-20 14:10:53 +0530 | [diff] [blame] | 1811 | beiscsi_process_async_event(phba, mcc_compl); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 1812 | } else if (mcc_compl->flags & CQE_FLAGS_COMPLETED_MASK) { |
Jitendra Bhivare | 2e4e8f6 | 2016-02-04 15:49:11 +0530 | [diff] [blame] | 1813 | beiscsi_process_mcc_compl(&phba->ctrl, mcc_compl); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 1814 | } |
| 1815 | |
| 1816 | mcc_compl->flags = 0; |
| 1817 | queue_tail_inc(mcc_cq); |
| 1818 | mcc_compl = queue_tail_node(mcc_cq); |
| 1819 | mcc_compl->flags = le32_to_cpu(mcc_compl->flags); |
| 1820 | num_processed++; |
| 1821 | } |
| 1822 | |
| 1823 | if (num_processed > 0) |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 1824 | hwi_ring_cq_db(phba, mcc_cq->id, num_processed, 1); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 1825 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1826 | |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 1827 | static void beiscsi_mcc_work(struct work_struct *work) |
| 1828 | { |
| 1829 | struct be_eq_obj *pbe_eq; |
| 1830 | struct beiscsi_hba *phba; |
| 1831 | |
| 1832 | pbe_eq = container_of(work, struct be_eq_obj, mcc_work); |
| 1833 | phba = pbe_eq->phba; |
| 1834 | beiscsi_process_mcc_cq(phba); |
| 1835 | /* rearm EQ for further interrupts */ |
Jitendra Bhivare | 9122e99 | 2016-08-19 15:20:11 +0530 | [diff] [blame] | 1836 | if (!beiscsi_hba_in_error(phba)) |
| 1837 | 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] | 1838 | } |
| 1839 | |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 1840 | /** |
| 1841 | * beiscsi_process_cq()- Process the Completion Queue |
| 1842 | * @pbe_eq: Event Q on which the Completion has come |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 1843 | * @budget: Max number of events to processed |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 1844 | * |
| 1845 | * return |
| 1846 | * Number of Completion Entries processed. |
| 1847 | **/ |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 1848 | 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] | 1849 | { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1850 | struct be_queue_info *cq; |
| 1851 | struct sol_cqe *sol; |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 1852 | unsigned int total = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1853 | unsigned int num_processed = 0; |
John Soni Jose | 0a513dd | 2012-08-20 23:00:55 +0530 | [diff] [blame] | 1854 | unsigned short code = 0, cid = 0; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 1855 | uint16_t cri_index = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1856 | struct beiscsi_conn *beiscsi_conn; |
Jayamohan Kallickal | c246228 | 2010-01-05 05:05:34 +0530 | [diff] [blame] | 1857 | struct beiscsi_endpoint *beiscsi_ep; |
| 1858 | struct iscsi_endpoint *ep; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1859 | struct beiscsi_hba *phba; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1860 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1861 | cq = pbe_eq->cq; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1862 | sol = queue_tail_node(cq); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1863 | phba = pbe_eq->phba; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1864 | |
| 1865 | while (sol->dw[offsetof(struct amap_sol_cqe, valid) / 32] & |
| 1866 | CQE_VALID_MASK) { |
Jitendra Bhivare | 9122e99 | 2016-08-19 15:20:11 +0530 | [diff] [blame] | 1867 | if (beiscsi_hba_in_error(phba)) |
| 1868 | return 0; |
| 1869 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1870 | be_dws_le_to_cpu(sol, sizeof(struct sol_cqe)); |
| 1871 | |
Jitendra Bhivare | 45efc940 | 2017-10-10 16:18:18 +0530 | [diff] [blame] | 1872 | code = (sol->dw[offsetof(struct amap_sol_cqe, code) / 32] & |
| 1873 | CQE_CODE_MASK); |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 1874 | |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1875 | /* Get the CID */ |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 1876 | if (is_chip_be2_be3r(phba)) { |
| 1877 | cid = AMAP_GET_BITS(struct amap_sol_cqe, cid, sol); |
| 1878 | } else { |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1879 | if ((code == DRIVERMSG_NOTIFY) || |
| 1880 | (code == UNSOL_HDR_NOTIFY) || |
| 1881 | (code == UNSOL_DATA_NOTIFY)) |
| 1882 | cid = AMAP_GET_BITS( |
| 1883 | struct amap_i_t_dpdu_cqe_v2, |
| 1884 | cid, sol); |
| 1885 | else |
| 1886 | cid = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1887 | cid, sol); |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 1888 | } |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1889 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 1890 | cri_index = BE_GET_CRI_FROM_CID(cid); |
| 1891 | ep = phba->ep_array[cri_index]; |
Jayamohan Kallickal | b7ab35b | 2014-08-08 01:00:01 -0400 | [diff] [blame] | 1892 | |
| 1893 | if (ep == NULL) { |
| 1894 | /* connection has already been freed |
| 1895 | * just move on to next one |
| 1896 | */ |
| 1897 | beiscsi_log(phba, KERN_WARNING, |
| 1898 | BEISCSI_LOG_INIT, |
| 1899 | "BM_%d : proc cqe of disconn ep: cid %d\n", |
| 1900 | cid); |
| 1901 | goto proc_next_cqe; |
| 1902 | } |
| 1903 | |
Jayamohan Kallickal | c246228 | 2010-01-05 05:05:34 +0530 | [diff] [blame] | 1904 | beiscsi_ep = ep->dd_data; |
| 1905 | beiscsi_conn = beiscsi_ep->conn; |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 1906 | |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 1907 | /* replenish cq */ |
| 1908 | if (num_processed == 32) { |
| 1909 | hwi_ring_cq_db(phba, cq->id, 32, 0); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1910 | num_processed = 0; |
| 1911 | } |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 1912 | total++; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1913 | |
John Soni Jose | 0a513dd | 2012-08-20 23:00:55 +0530 | [diff] [blame] | 1914 | switch (code) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1915 | case SOL_CMD_COMPLETE: |
| 1916 | hwi_complete_cmd(beiscsi_conn, phba, sol); |
| 1917 | break; |
| 1918 | case DRIVERMSG_NOTIFY: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1919 | beiscsi_log(phba, KERN_INFO, |
| 1920 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 1921 | "BM_%d : Received %s[%d] on CID : %d\n", |
| 1922 | cqe_desc[code], code, cid); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1923 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1924 | hwi_complete_drvr_msgs(beiscsi_conn, phba, sol); |
| 1925 | break; |
| 1926 | case UNSOL_HDR_NOTIFY: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1927 | beiscsi_log(phba, KERN_INFO, |
| 1928 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 1929 | "BM_%d : Received %s[%d] on CID : %d\n", |
| 1930 | cqe_desc[code], code, cid); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1931 | |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 1932 | spin_lock_bh(&phba->async_pdu_lock); |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1933 | beiscsi_hdq_process_compl(beiscsi_conn, |
| 1934 | (struct i_t_dpdu_cqe *)sol); |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 1935 | spin_unlock_bh(&phba->async_pdu_lock); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1936 | break; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1937 | case UNSOL_DATA_NOTIFY: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1938 | beiscsi_log(phba, KERN_INFO, |
| 1939 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 1940 | "BM_%d : Received %s[%d] on CID : %d\n", |
| 1941 | cqe_desc[code], code, cid); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1942 | |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 1943 | spin_lock_bh(&phba->async_pdu_lock); |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1944 | beiscsi_hdq_process_compl(beiscsi_conn, |
| 1945 | (struct i_t_dpdu_cqe *)sol); |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 1946 | spin_unlock_bh(&phba->async_pdu_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1947 | break; |
| 1948 | case CXN_INVALIDATE_INDEX_NOTIFY: |
| 1949 | case CMD_INVALIDATED_NOTIFY: |
| 1950 | case CXN_INVALIDATE_NOTIFY: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1951 | beiscsi_log(phba, KERN_ERR, |
| 1952 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 1953 | "BM_%d : Ignoring %s[%d] on CID : %d\n", |
| 1954 | cqe_desc[code], code, cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1955 | break; |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 1956 | case CXN_KILLED_HDR_DIGEST_ERR: |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1957 | case SOL_CMD_KILLED_DATA_DIGEST_ERR: |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 1958 | beiscsi_log(phba, KERN_ERR, |
| 1959 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
| 1960 | "BM_%d : Cmd Notification %s[%d] on CID : %d\n", |
| 1961 | cqe_desc[code], code, cid); |
| 1962 | break; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1963 | case CMD_KILLED_INVALID_STATSN_RCVD: |
| 1964 | case CMD_KILLED_INVALID_R2T_RCVD: |
| 1965 | case CMD_CXN_KILLED_LUN_INVALID: |
| 1966 | case CMD_CXN_KILLED_ICD_INVALID: |
| 1967 | case CMD_CXN_KILLED_ITT_INVALID: |
| 1968 | case CMD_CXN_KILLED_SEQ_OUTOFORDER: |
| 1969 | case CMD_CXN_KILLED_INVALID_DATASN_RCVD: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1970 | beiscsi_log(phba, KERN_ERR, |
| 1971 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 1972 | "BM_%d : Cmd Notification %s[%d] on CID : %d\n", |
| 1973 | cqe_desc[code], code, cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1974 | break; |
| 1975 | case UNSOL_DATA_DIGEST_ERROR_NOTIFY: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1976 | beiscsi_log(phba, KERN_ERR, |
| 1977 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 1978 | "BM_%d : Dropping %s[%d] on DPDU ring on CID : %d\n", |
| 1979 | cqe_desc[code], code, cid); |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 1980 | spin_lock_bh(&phba->async_pdu_lock); |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 1981 | /* driver consumes the entry and drops the contents */ |
| 1982 | beiscsi_hdq_process_compl(beiscsi_conn, |
| 1983 | (struct i_t_dpdu_cqe *)sol); |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 1984 | spin_unlock_bh(&phba->async_pdu_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1985 | break; |
| 1986 | case CXN_KILLED_PDU_SIZE_EXCEEDS_DSL: |
| 1987 | case CXN_KILLED_BURST_LEN_MISMATCH: |
| 1988 | case CXN_KILLED_AHS_RCVD: |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1989 | case CXN_KILLED_UNKNOWN_HDR: |
| 1990 | case CXN_KILLED_STALE_ITT_TTT_RCVD: |
| 1991 | case CXN_KILLED_INVALID_ITT_TTT_RCVD: |
| 1992 | case CXN_KILLED_TIMED_OUT: |
| 1993 | case CXN_KILLED_FIN_RCVD: |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 1994 | case CXN_KILLED_RST_SENT: |
| 1995 | case CXN_KILLED_RST_RCVD: |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1996 | case CXN_KILLED_BAD_UNSOL_PDU_RCVD: |
| 1997 | case CXN_KILLED_BAD_WRB_INDEX_ERROR: |
| 1998 | case CXN_KILLED_OVER_RUN_RESIDUAL: |
| 1999 | case CXN_KILLED_UNDER_RUN_RESIDUAL: |
| 2000 | case CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2001 | beiscsi_log(phba, KERN_ERR, |
| 2002 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 2003 | "BM_%d : Event %s[%d] received on CID : %d\n", |
| 2004 | cqe_desc[code], code, cid); |
John Soni Jose | 0a513dd | 2012-08-20 23:00:55 +0530 | [diff] [blame] | 2005 | if (beiscsi_conn) |
| 2006 | iscsi_conn_failure(beiscsi_conn->conn, |
| 2007 | ISCSI_ERR_CONN_FAILED); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2008 | break; |
| 2009 | default: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2010 | beiscsi_log(phba, KERN_ERR, |
| 2011 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 2012 | "BM_%d : Invalid CQE Event Received Code : %d" |
| 2013 | "CID 0x%x...\n", |
John Soni Jose | 0a513dd | 2012-08-20 23:00:55 +0530 | [diff] [blame] | 2014 | code, cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2015 | break; |
| 2016 | } |
| 2017 | |
Jayamohan Kallickal | b7ab35b | 2014-08-08 01:00:01 -0400 | [diff] [blame] | 2018 | proc_next_cqe: |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2019 | AMAP_SET_BITS(struct amap_sol_cqe, valid, sol, 0); |
| 2020 | queue_tail_inc(cq); |
| 2021 | sol = queue_tail_node(cq); |
| 2022 | num_processed++; |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2023 | if (total == budget) |
| 2024 | break; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2025 | } |
| 2026 | |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2027 | hwi_ring_cq_db(phba, cq->id, num_processed, 1); |
| 2028 | return total; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2029 | } |
| 2030 | |
Christoph Hellwig | 511cbce | 2015-11-10 14:56:14 +0100 | [diff] [blame] | 2031 | static int be_iopoll(struct irq_poll *iop, int budget) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2032 | { |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 2033 | unsigned int ret, io_events; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2034 | struct beiscsi_hba *phba; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2035 | struct be_eq_obj *pbe_eq; |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2036 | struct be_eq_entry *eqe = NULL; |
| 2037 | struct be_queue_info *eq; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2038 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2039 | pbe_eq = container_of(iop, struct be_eq_obj, iopoll); |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2040 | phba = pbe_eq->phba; |
Jitendra Bhivare | 9122e99 | 2016-08-19 15:20:11 +0530 | [diff] [blame] | 2041 | if (beiscsi_hba_in_error(phba)) { |
| 2042 | irq_poll_complete(iop); |
| 2043 | return 0; |
| 2044 | } |
| 2045 | |
| 2046 | io_events = 0; |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2047 | eq = &pbe_eq->q; |
| 2048 | eqe = queue_tail_node(eq); |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2049 | while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32] & |
| 2050 | EQE_VALID_MASK) { |
| 2051 | AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0); |
| 2052 | queue_tail_inc(eq); |
| 2053 | eqe = queue_tail_node(eq); |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 2054 | io_events++; |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2055 | } |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 2056 | hwi_ring_eq_db(phba, eq->id, 1, io_events, 0, 1); |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2057 | |
| 2058 | ret = beiscsi_process_cq(pbe_eq, budget); |
Jayamohan Kallickal | 73af08e | 2014-05-05 21:41:26 -0400 | [diff] [blame] | 2059 | pbe_eq->cq_count += ret; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2060 | if (ret < budget) { |
Christoph Hellwig | 511cbce | 2015-11-10 14:56:14 +0100 | [diff] [blame] | 2061 | irq_poll_complete(iop); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2062 | beiscsi_log(phba, KERN_INFO, |
| 2063 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2064 | "BM_%d : rearm pbe_eq->q.id =%d ret %d\n", |
| 2065 | pbe_eq->q.id, ret); |
Jitendra Bhivare | 9122e99 | 2016-08-19 15:20:11 +0530 | [diff] [blame] | 2066 | if (!beiscsi_hba_in_error(phba)) |
| 2067 | 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] | 2068 | } |
| 2069 | return ret; |
| 2070 | } |
| 2071 | |
| 2072 | static void |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2073 | hwi_write_sgl_v2(struct iscsi_wrb *pwrb, struct scatterlist *sg, |
| 2074 | unsigned int num_sg, struct beiscsi_io_task *io_task) |
| 2075 | { |
| 2076 | struct iscsi_sge *psgl; |
| 2077 | unsigned int sg_len, index; |
| 2078 | unsigned int sge_len = 0; |
| 2079 | unsigned long long addr; |
| 2080 | struct scatterlist *l_sg; |
| 2081 | unsigned int offset; |
| 2082 | |
| 2083 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_lo, pwrb, |
| 2084 | io_task->bhs_pa.u.a32.address_lo); |
| 2085 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_hi, pwrb, |
| 2086 | io_task->bhs_pa.u.a32.address_hi); |
| 2087 | |
| 2088 | l_sg = sg; |
| 2089 | for (index = 0; (index < num_sg) && (index < 2); index++, |
| 2090 | sg = sg_next(sg)) { |
| 2091 | if (index == 0) { |
| 2092 | sg_len = sg_dma_len(sg); |
| 2093 | addr = (u64) sg_dma_address(sg); |
| 2094 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
| 2095 | sge0_addr_lo, pwrb, |
| 2096 | lower_32_bits(addr)); |
| 2097 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
| 2098 | sge0_addr_hi, pwrb, |
| 2099 | upper_32_bits(addr)); |
| 2100 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
| 2101 | sge0_len, pwrb, |
| 2102 | sg_len); |
| 2103 | sge_len = sg_len; |
| 2104 | } else { |
| 2105 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_r2t_offset, |
| 2106 | pwrb, sge_len); |
| 2107 | sg_len = sg_dma_len(sg); |
| 2108 | addr = (u64) sg_dma_address(sg); |
| 2109 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
| 2110 | sge1_addr_lo, pwrb, |
| 2111 | lower_32_bits(addr)); |
| 2112 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
| 2113 | sge1_addr_hi, pwrb, |
| 2114 | upper_32_bits(addr)); |
| 2115 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
| 2116 | sge1_len, pwrb, |
| 2117 | sg_len); |
| 2118 | } |
| 2119 | } |
| 2120 | psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag; |
| 2121 | memset(psgl, 0, sizeof(*psgl) * BE2_SGE); |
| 2122 | |
| 2123 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2); |
| 2124 | |
| 2125 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, |
| 2126 | io_task->bhs_pa.u.a32.address_hi); |
| 2127 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, |
| 2128 | io_task->bhs_pa.u.a32.address_lo); |
| 2129 | |
| 2130 | if (num_sg == 1) { |
| 2131 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb, |
| 2132 | 1); |
| 2133 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb, |
| 2134 | 0); |
| 2135 | } else if (num_sg == 2) { |
| 2136 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb, |
| 2137 | 0); |
| 2138 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb, |
| 2139 | 1); |
| 2140 | } else { |
| 2141 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb, |
| 2142 | 0); |
| 2143 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb, |
| 2144 | 0); |
| 2145 | } |
| 2146 | |
| 2147 | sg = l_sg; |
| 2148 | psgl++; |
| 2149 | psgl++; |
| 2150 | offset = 0; |
| 2151 | for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) { |
| 2152 | sg_len = sg_dma_len(sg); |
| 2153 | addr = (u64) sg_dma_address(sg); |
| 2154 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, |
| 2155 | lower_32_bits(addr)); |
| 2156 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, |
| 2157 | upper_32_bits(addr)); |
| 2158 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len); |
| 2159 | AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset); |
| 2160 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0); |
| 2161 | offset += sg_len; |
| 2162 | } |
| 2163 | psgl--; |
| 2164 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1); |
| 2165 | } |
| 2166 | |
| 2167 | static void |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2168 | hwi_write_sgl(struct iscsi_wrb *pwrb, struct scatterlist *sg, |
| 2169 | unsigned int num_sg, struct beiscsi_io_task *io_task) |
| 2170 | { |
| 2171 | struct iscsi_sge *psgl; |
Jayamohan Kallickal | 58ff4bd | 2010-10-06 23:46:47 +0530 | [diff] [blame] | 2172 | unsigned int sg_len, index; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2173 | unsigned int sge_len = 0; |
| 2174 | unsigned long long addr; |
| 2175 | struct scatterlist *l_sg; |
| 2176 | unsigned int offset; |
| 2177 | |
| 2178 | AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb, |
| 2179 | io_task->bhs_pa.u.a32.address_lo); |
| 2180 | AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb, |
| 2181 | io_task->bhs_pa.u.a32.address_hi); |
| 2182 | |
| 2183 | l_sg = sg; |
Jayamohan Kallickal | 48bd86c | 2010-01-07 01:50:19 +0530 | [diff] [blame] | 2184 | for (index = 0; (index < num_sg) && (index < 2); index++, |
| 2185 | sg = sg_next(sg)) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2186 | if (index == 0) { |
| 2187 | sg_len = sg_dma_len(sg); |
| 2188 | addr = (u64) sg_dma_address(sg); |
| 2189 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb, |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 2190 | ((u32)(addr & 0xFFFFFFFF))); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2191 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb, |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 2192 | ((u32)(addr >> 32))); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2193 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb, |
| 2194 | sg_len); |
| 2195 | sge_len = sg_len; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2196 | } else { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2197 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_r2t_offset, |
| 2198 | pwrb, sge_len); |
| 2199 | sg_len = sg_dma_len(sg); |
| 2200 | addr = (u64) sg_dma_address(sg); |
| 2201 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_lo, pwrb, |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 2202 | ((u32)(addr & 0xFFFFFFFF))); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2203 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_hi, pwrb, |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 2204 | ((u32)(addr >> 32))); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2205 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_len, pwrb, |
| 2206 | sg_len); |
| 2207 | } |
| 2208 | } |
| 2209 | psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag; |
| 2210 | memset(psgl, 0, sizeof(*psgl) * BE2_SGE); |
| 2211 | |
| 2212 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2); |
| 2213 | |
| 2214 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, |
| 2215 | io_task->bhs_pa.u.a32.address_hi); |
| 2216 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, |
| 2217 | io_task->bhs_pa.u.a32.address_lo); |
| 2218 | |
Jayamohan Kallickal | caf818f | 2010-01-23 05:38:18 +0530 | [diff] [blame] | 2219 | if (num_sg == 1) { |
| 2220 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, |
| 2221 | 1); |
| 2222 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb, |
| 2223 | 0); |
| 2224 | } else if (num_sg == 2) { |
| 2225 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, |
| 2226 | 0); |
| 2227 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb, |
| 2228 | 1); |
| 2229 | } else { |
| 2230 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, |
| 2231 | 0); |
| 2232 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb, |
| 2233 | 0); |
| 2234 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2235 | sg = l_sg; |
| 2236 | psgl++; |
| 2237 | psgl++; |
| 2238 | offset = 0; |
Jayamohan Kallickal | 48bd86c | 2010-01-07 01:50:19 +0530 | [diff] [blame] | 2239 | for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2240 | sg_len = sg_dma_len(sg); |
| 2241 | addr = (u64) sg_dma_address(sg); |
| 2242 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, |
| 2243 | (addr & 0xFFFFFFFF)); |
| 2244 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, |
| 2245 | (addr >> 32)); |
| 2246 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len); |
| 2247 | AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset); |
| 2248 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0); |
| 2249 | offset += sg_len; |
| 2250 | } |
| 2251 | psgl--; |
| 2252 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1); |
| 2253 | } |
| 2254 | |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2255 | /** |
| 2256 | * hwi_write_buffer()- Populate the WRB with task info |
| 2257 | * @pwrb: ptr to the WRB entry |
| 2258 | * @task: iscsi task which is to be executed |
| 2259 | **/ |
Alexey Khoroshilov | e049362 | 2016-01-16 00:45:34 +0300 | [diff] [blame] | 2260 | 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] | 2261 | { |
| 2262 | struct iscsi_sge *psgl; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2263 | struct beiscsi_io_task *io_task = task->dd_data; |
| 2264 | struct beiscsi_conn *beiscsi_conn = io_task->conn; |
| 2265 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2266 | uint8_t dsp_value = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2267 | |
| 2268 | io_task->bhs_len = sizeof(struct be_nonio_bhs) - 2; |
| 2269 | AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb, |
| 2270 | io_task->bhs_pa.u.a32.address_lo); |
| 2271 | AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb, |
| 2272 | io_task->bhs_pa.u.a32.address_hi); |
| 2273 | |
| 2274 | if (task->data) { |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2275 | |
| 2276 | /* Check for the data_count */ |
| 2277 | dsp_value = (task->data_count) ? 1 : 0; |
| 2278 | |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 2279 | if (is_chip_be2_be3r(phba)) |
| 2280 | AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2281 | pwrb, dsp_value); |
| 2282 | else |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 2283 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2284 | pwrb, dsp_value); |
| 2285 | |
| 2286 | /* Map addr only if there is data_count */ |
| 2287 | if (dsp_value) { |
Christoph Hellwig | 26a4c99 | 2018-10-10 18:22:24 +0200 | [diff] [blame] | 2288 | io_task->mtask_addr = dma_map_single(&phba->pcidev->dev, |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2289 | task->data, |
| 2290 | task->data_count, |
Christoph Hellwig | 26a4c99 | 2018-10-10 18:22:24 +0200 | [diff] [blame] | 2291 | DMA_TO_DEVICE); |
| 2292 | if (dma_mapping_error(&phba->pcidev->dev, |
Alexey Khoroshilov | e049362 | 2016-01-16 00:45:34 +0300 | [diff] [blame] | 2293 | io_task->mtask_addr)) |
| 2294 | return -ENOMEM; |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2295 | io_task->mtask_data_count = task->data_count; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2296 | } else |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2297 | io_task->mtask_addr = 0; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2298 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2299 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb, |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2300 | lower_32_bits(io_task->mtask_addr)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2301 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb, |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2302 | upper_32_bits(io_task->mtask_addr)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2303 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb, |
| 2304 | task->data_count); |
| 2305 | |
| 2306 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, 1); |
| 2307 | } else { |
| 2308 | AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0); |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2309 | io_task->mtask_addr = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2310 | } |
| 2311 | |
| 2312 | psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag; |
| 2313 | |
| 2314 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len); |
| 2315 | |
| 2316 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, |
| 2317 | io_task->bhs_pa.u.a32.address_hi); |
| 2318 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, |
| 2319 | io_task->bhs_pa.u.a32.address_lo); |
| 2320 | if (task->data) { |
| 2321 | psgl++; |
| 2322 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, 0); |
| 2323 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, 0); |
| 2324 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0); |
| 2325 | AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, 0); |
| 2326 | AMAP_SET_BITS(struct amap_iscsi_sge, rsvd0, psgl, 0); |
| 2327 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0); |
| 2328 | |
| 2329 | psgl++; |
| 2330 | if (task->data) { |
| 2331 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2332 | lower_32_bits(io_task->mtask_addr)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2333 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2334 | upper_32_bits(io_task->mtask_addr)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2335 | } |
| 2336 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0x106); |
| 2337 | } |
| 2338 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1); |
Alexey Khoroshilov | e049362 | 2016-01-16 00:45:34 +0300 | [diff] [blame] | 2339 | return 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2340 | } |
| 2341 | |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 2342 | /** |
| 2343 | * beiscsi_find_mem_req()- Find mem needed |
| 2344 | * @phba: ptr to HBA struct |
| 2345 | **/ |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2346 | static void beiscsi_find_mem_req(struct beiscsi_hba *phba) |
| 2347 | { |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2348 | uint8_t mem_descr_index, ulp_num; |
Jitendra Bhivare | fa1261c | 2016-12-13 15:56:01 +0530 | [diff] [blame] | 2349 | unsigned int num_async_pdu_buf_pages; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2350 | unsigned int num_async_pdu_data_pages, wrb_sz_per_cxn; |
| 2351 | unsigned int num_async_pdu_buf_sgl_pages, num_async_pdu_data_sgl_pages; |
| 2352 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2353 | phba->params.hwi_ws_sz = sizeof(struct hwi_controller); |
| 2354 | |
| 2355 | phba->mem_req[ISCSI_MEM_GLOBAL_HEADER] = 2 * |
| 2356 | BE_ISCSI_PDU_HEADER_SIZE; |
| 2357 | phba->mem_req[HWI_MEM_ADDN_CONTEXT] = |
| 2358 | sizeof(struct hwi_context_memory); |
| 2359 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2360 | |
| 2361 | phba->mem_req[HWI_MEM_WRB] = sizeof(struct iscsi_wrb) |
| 2362 | * (phba->params.wrbs_per_cxn) |
| 2363 | * phba->params.cxns_per_ctrl; |
| 2364 | wrb_sz_per_cxn = sizeof(struct wrb_handle) * |
| 2365 | (phba->params.wrbs_per_cxn); |
| 2366 | phba->mem_req[HWI_MEM_WRBH] = roundup_pow_of_two((wrb_sz_per_cxn) * |
| 2367 | phba->params.cxns_per_ctrl); |
| 2368 | |
| 2369 | phba->mem_req[HWI_MEM_SGLH] = sizeof(struct sgl_handle) * |
| 2370 | phba->params.icds_per_ctrl; |
| 2371 | phba->mem_req[HWI_MEM_SGE] = sizeof(struct iscsi_sge) * |
| 2372 | phba->params.num_sge_per_io * phba->params.icds_per_ctrl; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2373 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 2374 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2375 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2376 | num_async_pdu_buf_sgl_pages = |
Jitendra Bhivare | fecc382 | 2017-03-24 14:11:44 +0530 | [diff] [blame] | 2377 | PAGES_REQUIRED(BEISCSI_ASYNC_HDQ_SIZE( |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2378 | phba, ulp_num) * |
| 2379 | sizeof(struct phys_addr)); |
| 2380 | |
| 2381 | num_async_pdu_buf_pages = |
Jitendra Bhivare | fecc382 | 2017-03-24 14:11:44 +0530 | [diff] [blame] | 2382 | PAGES_REQUIRED(BEISCSI_ASYNC_HDQ_SIZE( |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2383 | phba, ulp_num) * |
| 2384 | phba->params.defpdu_hdr_sz); |
| 2385 | |
| 2386 | num_async_pdu_data_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 | phba->params.defpdu_data_sz); |
| 2390 | |
| 2391 | num_async_pdu_data_sgl_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 | sizeof(struct phys_addr)); |
| 2395 | |
Jayamohan Kallickal | a129d92 | 2013-09-28 15:35:46 -0700 | [diff] [blame] | 2396 | mem_descr_index = (HWI_MEM_TEMPLATE_HDR_ULP0 + |
| 2397 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2398 | phba->mem_req[mem_descr_index] = |
| 2399 | BEISCSI_GET_CID_COUNT(phba, ulp_num) * |
| 2400 | BEISCSI_TEMPLATE_HDR_PER_CXN_SIZE; |
| 2401 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2402 | mem_descr_index = (HWI_MEM_ASYNC_HEADER_BUF_ULP0 + |
| 2403 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2404 | phba->mem_req[mem_descr_index] = |
| 2405 | num_async_pdu_buf_pages * |
| 2406 | PAGE_SIZE; |
| 2407 | |
| 2408 | mem_descr_index = (HWI_MEM_ASYNC_DATA_BUF_ULP0 + |
| 2409 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2410 | phba->mem_req[mem_descr_index] = |
| 2411 | num_async_pdu_data_pages * |
| 2412 | PAGE_SIZE; |
| 2413 | |
| 2414 | mem_descr_index = (HWI_MEM_ASYNC_HEADER_RING_ULP0 + |
| 2415 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2416 | phba->mem_req[mem_descr_index] = |
| 2417 | num_async_pdu_buf_sgl_pages * |
| 2418 | PAGE_SIZE; |
| 2419 | |
| 2420 | mem_descr_index = (HWI_MEM_ASYNC_DATA_RING_ULP0 + |
| 2421 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2422 | phba->mem_req[mem_descr_index] = |
| 2423 | num_async_pdu_data_sgl_pages * |
| 2424 | PAGE_SIZE; |
| 2425 | |
| 2426 | mem_descr_index = (HWI_MEM_ASYNC_HEADER_HANDLE_ULP0 + |
| 2427 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2428 | phba->mem_req[mem_descr_index] = |
Jitendra Bhivare | fecc382 | 2017-03-24 14:11:44 +0530 | [diff] [blame] | 2429 | BEISCSI_ASYNC_HDQ_SIZE(phba, ulp_num) * |
| 2430 | sizeof(struct hd_async_handle); |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2431 | |
| 2432 | mem_descr_index = (HWI_MEM_ASYNC_DATA_HANDLE_ULP0 + |
| 2433 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2434 | phba->mem_req[mem_descr_index] = |
Jitendra Bhivare | fecc382 | 2017-03-24 14:11:44 +0530 | [diff] [blame] | 2435 | BEISCSI_ASYNC_HDQ_SIZE(phba, ulp_num) * |
| 2436 | sizeof(struct hd_async_handle); |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2437 | |
| 2438 | mem_descr_index = (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0 + |
| 2439 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2440 | phba->mem_req[mem_descr_index] = |
Jitendra Bhivare | fecc382 | 2017-03-24 14:11:44 +0530 | [diff] [blame] | 2441 | sizeof(struct hd_async_context) + |
| 2442 | (BEISCSI_ASYNC_HDQ_SIZE(phba, ulp_num) * |
| 2443 | sizeof(struct hd_async_entry)); |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2444 | } |
| 2445 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2446 | } |
| 2447 | |
| 2448 | static int beiscsi_alloc_mem(struct beiscsi_hba *phba) |
| 2449 | { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2450 | dma_addr_t bus_add; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2451 | struct hwi_controller *phwi_ctrlr; |
| 2452 | struct be_mem_descriptor *mem_descr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2453 | struct mem_array *mem_arr, *mem_arr_orig; |
| 2454 | unsigned int i, j, alloc_size, curr_alloc_size; |
| 2455 | |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2456 | phba->phwi_ctrlr = kzalloc(phba->params.hwi_ws_sz, GFP_KERNEL); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2457 | if (!phba->phwi_ctrlr) |
| 2458 | return -ENOMEM; |
| 2459 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2460 | /* Allocate memory for wrb_context */ |
| 2461 | phwi_ctrlr = phba->phwi_ctrlr; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 2462 | phwi_ctrlr->wrb_context = kcalloc(phba->params.cxns_per_ctrl, |
| 2463 | sizeof(struct hwi_wrb_context), |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2464 | GFP_KERNEL); |
Maurizio Lombardi | 0c88740 | 2015-10-01 10:56:25 +0200 | [diff] [blame] | 2465 | if (!phwi_ctrlr->wrb_context) { |
| 2466 | kfree(phba->phwi_ctrlr); |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2467 | return -ENOMEM; |
Maurizio Lombardi | 0c88740 | 2015-10-01 10:56:25 +0200 | [diff] [blame] | 2468 | } |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2469 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2470 | phba->init_mem = kcalloc(SE_MEM_MAX, sizeof(*mem_descr), |
| 2471 | GFP_KERNEL); |
| 2472 | if (!phba->init_mem) { |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2473 | kfree(phwi_ctrlr->wrb_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2474 | kfree(phba->phwi_ctrlr); |
| 2475 | return -ENOMEM; |
| 2476 | } |
| 2477 | |
Kees Cook | 6da2ec5 | 2018-06-12 13:55:00 -0700 | [diff] [blame] | 2478 | mem_arr_orig = kmalloc_array(BEISCSI_MAX_FRAGS_INIT, |
| 2479 | sizeof(*mem_arr_orig), |
| 2480 | GFP_KERNEL); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2481 | if (!mem_arr_orig) { |
| 2482 | kfree(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_descr = phba->init_mem; |
| 2489 | for (i = 0; i < SE_MEM_MAX; i++) { |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2490 | if (!phba->mem_req[i]) { |
| 2491 | mem_descr->mem_array = NULL; |
| 2492 | mem_descr++; |
| 2493 | continue; |
| 2494 | } |
| 2495 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2496 | j = 0; |
| 2497 | mem_arr = mem_arr_orig; |
| 2498 | alloc_size = phba->mem_req[i]; |
| 2499 | memset(mem_arr, 0, sizeof(struct mem_array) * |
| 2500 | BEISCSI_MAX_FRAGS_INIT); |
| 2501 | curr_alloc_size = min(be_max_phys_size * 1024, alloc_size); |
| 2502 | do { |
Christoph Hellwig | 26a4c99 | 2018-10-10 18:22:24 +0200 | [diff] [blame] | 2503 | mem_arr->virtual_address = |
| 2504 | dma_alloc_coherent(&phba->pcidev->dev, |
| 2505 | curr_alloc_size, &bus_add, GFP_KERNEL); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2506 | if (!mem_arr->virtual_address) { |
| 2507 | if (curr_alloc_size <= BE_MIN_MEM_SIZE) |
| 2508 | goto free_mem; |
| 2509 | if (curr_alloc_size - |
| 2510 | rounddown_pow_of_two(curr_alloc_size)) |
| 2511 | curr_alloc_size = rounddown_pow_of_two |
| 2512 | (curr_alloc_size); |
| 2513 | else |
| 2514 | curr_alloc_size = curr_alloc_size / 2; |
| 2515 | } else { |
| 2516 | mem_arr->bus_address.u. |
| 2517 | a64.address = (__u64) bus_add; |
| 2518 | mem_arr->size = curr_alloc_size; |
| 2519 | alloc_size -= curr_alloc_size; |
| 2520 | curr_alloc_size = min(be_max_phys_size * |
| 2521 | 1024, alloc_size); |
| 2522 | j++; |
| 2523 | mem_arr++; |
| 2524 | } |
| 2525 | } while (alloc_size); |
| 2526 | mem_descr->num_elements = j; |
| 2527 | mem_descr->size_in_bytes = phba->mem_req[i]; |
Kees Cook | 6da2ec5 | 2018-06-12 13:55:00 -0700 | [diff] [blame] | 2528 | mem_descr->mem_array = kmalloc_array(j, sizeof(*mem_arr), |
| 2529 | GFP_KERNEL); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2530 | if (!mem_descr->mem_array) |
| 2531 | goto free_mem; |
| 2532 | |
| 2533 | memcpy(mem_descr->mem_array, mem_arr_orig, |
| 2534 | sizeof(struct mem_array) * j); |
| 2535 | mem_descr++; |
| 2536 | } |
| 2537 | kfree(mem_arr_orig); |
| 2538 | return 0; |
| 2539 | free_mem: |
| 2540 | mem_descr->num_elements = j; |
| 2541 | while ((i) || (j)) { |
| 2542 | for (j = mem_descr->num_elements; j > 0; j--) { |
Christoph Hellwig | 26a4c99 | 2018-10-10 18:22:24 +0200 | [diff] [blame] | 2543 | dma_free_coherent(&phba->pcidev->dev, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2544 | mem_descr->mem_array[j - 1].size, |
| 2545 | mem_descr->mem_array[j - 1]. |
| 2546 | virtual_address, |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 2547 | (unsigned long)mem_descr-> |
| 2548 | mem_array[j - 1]. |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2549 | bus_address.u.a64.address); |
| 2550 | } |
| 2551 | if (i) { |
| 2552 | i--; |
| 2553 | kfree(mem_descr->mem_array); |
| 2554 | mem_descr--; |
| 2555 | } |
| 2556 | } |
| 2557 | kfree(mem_arr_orig); |
| 2558 | kfree(phba->init_mem); |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2559 | kfree(phba->phwi_ctrlr->wrb_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2560 | kfree(phba->phwi_ctrlr); |
| 2561 | return -ENOMEM; |
| 2562 | } |
| 2563 | |
| 2564 | static int beiscsi_get_memory(struct beiscsi_hba *phba) |
| 2565 | { |
| 2566 | beiscsi_find_mem_req(phba); |
| 2567 | return beiscsi_alloc_mem(phba); |
| 2568 | } |
| 2569 | |
| 2570 | static void iscsi_init_global_templates(struct beiscsi_hba *phba) |
| 2571 | { |
| 2572 | struct pdu_data_out *pdata_out; |
| 2573 | struct pdu_nop_out *pnop_out; |
| 2574 | struct be_mem_descriptor *mem_descr; |
| 2575 | |
| 2576 | mem_descr = phba->init_mem; |
| 2577 | mem_descr += ISCSI_MEM_GLOBAL_HEADER; |
| 2578 | pdata_out = |
| 2579 | (struct pdu_data_out *)mem_descr->mem_array[0].virtual_address; |
| 2580 | memset(pdata_out, 0, BE_ISCSI_PDU_HEADER_SIZE); |
| 2581 | |
| 2582 | AMAP_SET_BITS(struct amap_pdu_data_out, opcode, pdata_out, |
| 2583 | IIOC_SCSI_DATA); |
| 2584 | |
| 2585 | pnop_out = |
| 2586 | (struct pdu_nop_out *)((unsigned char *)mem_descr->mem_array[0]. |
| 2587 | virtual_address + BE_ISCSI_PDU_HEADER_SIZE); |
| 2588 | |
| 2589 | memset(pnop_out, 0, BE_ISCSI_PDU_HEADER_SIZE); |
| 2590 | AMAP_SET_BITS(struct amap_pdu_nop_out, ttt, pnop_out, 0xFFFFFFFF); |
| 2591 | AMAP_SET_BITS(struct amap_pdu_nop_out, f_bit, pnop_out, 1); |
| 2592 | AMAP_SET_BITS(struct amap_pdu_nop_out, i_bit, pnop_out, 0); |
| 2593 | } |
| 2594 | |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2595 | static int beiscsi_init_wrb_handle(struct beiscsi_hba *phba) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2596 | { |
| 2597 | struct be_mem_descriptor *mem_descr_wrbh, *mem_descr_wrb; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2598 | struct hwi_context_memory *phwi_ctxt; |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2599 | struct wrb_handle *pwrb_handle = NULL; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2600 | struct hwi_controller *phwi_ctrlr; |
| 2601 | struct hwi_wrb_context *pwrb_context; |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2602 | struct iscsi_wrb *pwrb = NULL; |
| 2603 | unsigned int num_cxn_wrbh = 0; |
| 2604 | unsigned int num_cxn_wrb = 0, j, idx = 0, index; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2605 | |
| 2606 | mem_descr_wrbh = phba->init_mem; |
| 2607 | mem_descr_wrbh += HWI_MEM_WRBH; |
| 2608 | |
| 2609 | mem_descr_wrb = phba->init_mem; |
| 2610 | mem_descr_wrb += HWI_MEM_WRB; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2611 | phwi_ctrlr = phba->phwi_ctrlr; |
| 2612 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2613 | /* Allocate memory for WRBQ */ |
| 2614 | phwi_ctxt = phwi_ctrlr->phwi_ctxt; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 2615 | phwi_ctxt->be_wrbq = kcalloc(phba->params.cxns_per_ctrl, |
| 2616 | sizeof(struct be_queue_info), |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2617 | GFP_KERNEL); |
| 2618 | if (!phwi_ctxt->be_wrbq) { |
| 2619 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 2620 | "BM_%d : WRBQ Mem Alloc Failed\n"); |
| 2621 | return -ENOMEM; |
| 2622 | } |
| 2623 | |
| 2624 | for (index = 0; index < phba->params.cxns_per_ctrl; index++) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2625 | pwrb_context = &phwi_ctrlr->wrb_context[index]; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2626 | pwrb_context->pwrb_handle_base = |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 2627 | kcalloc(phba->params.wrbs_per_cxn, |
| 2628 | sizeof(struct wrb_handle *), |
| 2629 | GFP_KERNEL); |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2630 | if (!pwrb_context->pwrb_handle_base) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2631 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 2632 | "BM_%d : Mem Alloc Failed. Failing to load\n"); |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2633 | goto init_wrb_hndl_failed; |
| 2634 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2635 | pwrb_context->pwrb_handle_basestd = |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 2636 | kcalloc(phba->params.wrbs_per_cxn, |
| 2637 | sizeof(struct wrb_handle *), |
| 2638 | GFP_KERNEL); |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2639 | if (!pwrb_context->pwrb_handle_basestd) { |
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 | } |
| 2644 | if (!num_cxn_wrbh) { |
| 2645 | pwrb_handle = |
| 2646 | mem_descr_wrbh->mem_array[idx].virtual_address; |
| 2647 | num_cxn_wrbh = ((mem_descr_wrbh->mem_array[idx].size) / |
| 2648 | ((sizeof(struct wrb_handle)) * |
| 2649 | phba->params.wrbs_per_cxn)); |
| 2650 | idx++; |
| 2651 | } |
| 2652 | pwrb_context->alloc_index = 0; |
| 2653 | pwrb_context->wrb_handles_available = 0; |
| 2654 | pwrb_context->free_index = 0; |
| 2655 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2656 | if (num_cxn_wrbh) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2657 | for (j = 0; j < phba->params.wrbs_per_cxn; j++) { |
| 2658 | pwrb_context->pwrb_handle_base[j] = pwrb_handle; |
| 2659 | pwrb_context->pwrb_handle_basestd[j] = |
| 2660 | pwrb_handle; |
| 2661 | pwrb_context->wrb_handles_available++; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2662 | pwrb_handle->wrb_index = j; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2663 | pwrb_handle++; |
| 2664 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2665 | num_cxn_wrbh--; |
| 2666 | } |
Jitendra Bhivare | f64d92e | 2016-02-04 15:49:20 +0530 | [diff] [blame] | 2667 | spin_lock_init(&pwrb_context->wrb_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2668 | } |
| 2669 | idx = 0; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2670 | for (index = 0; index < phba->params.cxns_per_ctrl; index++) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2671 | pwrb_context = &phwi_ctrlr->wrb_context[index]; |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2672 | if (!num_cxn_wrb) { |
| 2673 | pwrb = mem_descr_wrb->mem_array[idx].virtual_address; |
| 2674 | num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) / |
| 2675 | ((sizeof(struct iscsi_wrb) * |
| 2676 | phba->params.wrbs_per_cxn)); |
| 2677 | idx++; |
| 2678 | } |
| 2679 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2680 | if (num_cxn_wrb) { |
| 2681 | for (j = 0; j < phba->params.wrbs_per_cxn; j++) { |
| 2682 | pwrb_handle = pwrb_context->pwrb_handle_base[j]; |
| 2683 | pwrb_handle->pwrb = pwrb; |
| 2684 | pwrb++; |
| 2685 | } |
| 2686 | num_cxn_wrb--; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2687 | } |
| 2688 | } |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2689 | return 0; |
| 2690 | init_wrb_hndl_failed: |
| 2691 | for (j = index; j > 0; j--) { |
| 2692 | pwrb_context = &phwi_ctrlr->wrb_context[j]; |
| 2693 | kfree(pwrb_context->pwrb_handle_base); |
| 2694 | kfree(pwrb_context->pwrb_handle_basestd); |
| 2695 | } |
| 2696 | return -ENOMEM; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2697 | } |
| 2698 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2699 | static int hwi_init_async_pdu_ctx(struct beiscsi_hba *phba) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2700 | { |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2701 | uint8_t ulp_num; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2702 | struct hwi_controller *phwi_ctrlr; |
| 2703 | struct hba_parameters *p = &phba->params; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2704 | struct hd_async_context *pasync_ctx; |
| 2705 | struct hd_async_handle *pasync_header_h, *pasync_data_h; |
Jayamohan Kallickal | dc63aac | 2012-04-03 23:41:36 -0500 | [diff] [blame] | 2706 | unsigned int index, idx, num_per_mem, num_async_data; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2707 | struct be_mem_descriptor *mem_descr; |
| 2708 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2709 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 2710 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
Jitendra Bhivare | d740105 | 2016-12-13 15:55:59 +0530 | [diff] [blame] | 2711 | /* get async_ctx for each ULP */ |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2712 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 2713 | mem_descr += (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0 + |
| 2714 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2715 | |
| 2716 | phwi_ctrlr = phba->phwi_ctrlr; |
| 2717 | phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num] = |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2718 | (struct hd_async_context *) |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2719 | mem_descr->mem_array[0].virtual_address; |
| 2720 | |
| 2721 | pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num]; |
| 2722 | memset(pasync_ctx, 0, sizeof(*pasync_ctx)); |
| 2723 | |
| 2724 | pasync_ctx->async_entry = |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2725 | (struct hd_async_entry *) |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2726 | ((long unsigned int)pasync_ctx + |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2727 | sizeof(struct hd_async_context)); |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2728 | |
Jitendra Bhivare | fecc382 | 2017-03-24 14:11:44 +0530 | [diff] [blame] | 2729 | pasync_ctx->num_entries = BEISCSI_ASYNC_HDQ_SIZE(phba, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2730 | ulp_num); |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2731 | /* setup header buffers */ |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2732 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 2733 | mem_descr += HWI_MEM_ASYNC_HEADER_BUF_ULP0 + |
| 2734 | (ulp_num * MEM_DESCR_OFFSET); |
| 2735 | if (mem_descr->mem_array[0].virtual_address) { |
| 2736 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 2737 | "BM_%d : hwi_init_async_pdu_ctx" |
| 2738 | " HWI_MEM_ASYNC_HEADER_BUF_ULP%d va=%p\n", |
| 2739 | ulp_num, |
| 2740 | mem_descr->mem_array[0]. |
| 2741 | virtual_address); |
| 2742 | } else |
| 2743 | beiscsi_log(phba, KERN_WARNING, |
| 2744 | BEISCSI_LOG_INIT, |
| 2745 | "BM_%d : No Virtual address for ULP : %d\n", |
| 2746 | ulp_num); |
| 2747 | |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 2748 | pasync_ctx->async_header.pi = 0; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2749 | pasync_ctx->async_header.buffer_size = p->defpdu_hdr_sz; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2750 | pasync_ctx->async_header.va_base = |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2751 | mem_descr->mem_array[0].virtual_address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2752 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2753 | pasync_ctx->async_header.pa_base.u.a64.address = |
| 2754 | mem_descr->mem_array[0]. |
| 2755 | bus_address.u.a64.address; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2756 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2757 | /* setup header buffer sgls */ |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2758 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 2759 | mem_descr += HWI_MEM_ASYNC_HEADER_RING_ULP0 + |
| 2760 | (ulp_num * MEM_DESCR_OFFSET); |
| 2761 | if (mem_descr->mem_array[0].virtual_address) { |
| 2762 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 2763 | "BM_%d : hwi_init_async_pdu_ctx" |
| 2764 | " HWI_MEM_ASYNC_HEADER_RING_ULP%d va=%p\n", |
| 2765 | ulp_num, |
| 2766 | mem_descr->mem_array[0]. |
| 2767 | virtual_address); |
| 2768 | } else |
| 2769 | beiscsi_log(phba, KERN_WARNING, |
| 2770 | BEISCSI_LOG_INIT, |
| 2771 | "BM_%d : No Virtual address for ULP : %d\n", |
| 2772 | ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2773 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2774 | pasync_ctx->async_header.ring_base = |
| 2775 | mem_descr->mem_array[0].virtual_address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2776 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2777 | /* setup header buffer handles */ |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2778 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 2779 | mem_descr += HWI_MEM_ASYNC_HEADER_HANDLE_ULP0 + |
| 2780 | (ulp_num * MEM_DESCR_OFFSET); |
| 2781 | if (mem_descr->mem_array[0].virtual_address) { |
| 2782 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 2783 | "BM_%d : hwi_init_async_pdu_ctx" |
| 2784 | " HWI_MEM_ASYNC_HEADER_HANDLE_ULP%d va=%p\n", |
| 2785 | ulp_num, |
| 2786 | mem_descr->mem_array[0]. |
| 2787 | virtual_address); |
| 2788 | } else |
| 2789 | beiscsi_log(phba, KERN_WARNING, |
| 2790 | BEISCSI_LOG_INIT, |
| 2791 | "BM_%d : No Virtual address for ULP : %d\n", |
| 2792 | ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2793 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2794 | pasync_ctx->async_header.handle_base = |
| 2795 | mem_descr->mem_array[0].virtual_address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2796 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2797 | /* setup data buffer sgls */ |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2798 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 2799 | mem_descr += HWI_MEM_ASYNC_DATA_RING_ULP0 + |
| 2800 | (ulp_num * MEM_DESCR_OFFSET); |
| 2801 | if (mem_descr->mem_array[0].virtual_address) { |
| 2802 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 2803 | "BM_%d : hwi_init_async_pdu_ctx" |
| 2804 | " HWI_MEM_ASYNC_DATA_RING_ULP%d va=%p\n", |
| 2805 | ulp_num, |
| 2806 | mem_descr->mem_array[0]. |
| 2807 | virtual_address); |
| 2808 | } else |
| 2809 | beiscsi_log(phba, KERN_WARNING, |
| 2810 | BEISCSI_LOG_INIT, |
| 2811 | "BM_%d : No Virtual address for ULP : %d\n", |
| 2812 | ulp_num); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2813 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2814 | pasync_ctx->async_data.ring_base = |
| 2815 | mem_descr->mem_array[0].virtual_address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2816 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2817 | /* setup data buffer handles */ |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2818 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 2819 | mem_descr += HWI_MEM_ASYNC_DATA_HANDLE_ULP0 + |
| 2820 | (ulp_num * MEM_DESCR_OFFSET); |
| 2821 | if (!mem_descr->mem_array[0].virtual_address) |
| 2822 | beiscsi_log(phba, KERN_WARNING, |
| 2823 | BEISCSI_LOG_INIT, |
| 2824 | "BM_%d : No Virtual address for ULP : %d\n", |
| 2825 | ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2826 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2827 | pasync_ctx->async_data.handle_base = |
| 2828 | mem_descr->mem_array[0].virtual_address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2829 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2830 | pasync_header_h = |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2831 | (struct hd_async_handle *) |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2832 | pasync_ctx->async_header.handle_base; |
| 2833 | pasync_data_h = |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2834 | (struct hd_async_handle *) |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2835 | pasync_ctx->async_data.handle_base; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2836 | |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2837 | /* setup data buffers */ |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2838 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 2839 | mem_descr += HWI_MEM_ASYNC_DATA_BUF_ULP0 + |
| 2840 | (ulp_num * MEM_DESCR_OFFSET); |
| 2841 | if (mem_descr->mem_array[0].virtual_address) { |
| 2842 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 2843 | "BM_%d : hwi_init_async_pdu_ctx" |
| 2844 | " HWI_MEM_ASYNC_DATA_BUF_ULP%d va=%p\n", |
| 2845 | ulp_num, |
| 2846 | mem_descr->mem_array[0]. |
| 2847 | virtual_address); |
| 2848 | } else |
| 2849 | beiscsi_log(phba, KERN_WARNING, |
| 2850 | BEISCSI_LOG_INIT, |
| 2851 | "BM_%d : No Virtual address for ULP : %d\n", |
| 2852 | ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2853 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2854 | idx = 0; |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 2855 | pasync_ctx->async_data.pi = 0; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2856 | pasync_ctx->async_data.buffer_size = p->defpdu_data_sz; |
Jayamohan Kallickal | dc63aac | 2012-04-03 23:41:36 -0500 | [diff] [blame] | 2857 | pasync_ctx->async_data.va_base = |
| 2858 | mem_descr->mem_array[idx].virtual_address; |
| 2859 | pasync_ctx->async_data.pa_base.u.a64.address = |
| 2860 | mem_descr->mem_array[idx]. |
| 2861 | bus_address.u.a64.address; |
| 2862 | |
| 2863 | num_async_data = ((mem_descr->mem_array[idx].size) / |
| 2864 | phba->params.defpdu_data_sz); |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2865 | num_per_mem = 0; |
| 2866 | |
Jitendra Bhivare | fecc382 | 2017-03-24 14:11:44 +0530 | [diff] [blame] | 2867 | for (index = 0; index < BEISCSI_ASYNC_HDQ_SIZE |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2868 | (phba, ulp_num); index++) { |
| 2869 | pasync_header_h->cri = -1; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2870 | pasync_header_h->is_header = 1; |
| 2871 | pasync_header_h->index = index; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2872 | INIT_LIST_HEAD(&pasync_header_h->link); |
| 2873 | pasync_header_h->pbuffer = |
| 2874 | (void *)((unsigned long) |
| 2875 | (pasync_ctx-> |
| 2876 | async_header.va_base) + |
| 2877 | (p->defpdu_hdr_sz * index)); |
| 2878 | |
| 2879 | pasync_header_h->pa.u.a64.address = |
| 2880 | pasync_ctx->async_header.pa_base.u.a64. |
| 2881 | address + (p->defpdu_hdr_sz * index); |
| 2882 | |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 2883 | pasync_ctx->async_entry[index].header = |
| 2884 | pasync_header_h; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2885 | pasync_header_h++; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2886 | INIT_LIST_HEAD(&pasync_ctx->async_entry[index]. |
| 2887 | wq.list); |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2888 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2889 | pasync_data_h->cri = -1; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 2890 | pasync_data_h->is_header = 0; |
| 2891 | pasync_data_h->index = index; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2892 | INIT_LIST_HEAD(&pasync_data_h->link); |
| 2893 | |
| 2894 | if (!num_async_data) { |
| 2895 | num_per_mem = 0; |
| 2896 | idx++; |
| 2897 | pasync_ctx->async_data.va_base = |
| 2898 | mem_descr->mem_array[idx]. |
| 2899 | virtual_address; |
| 2900 | pasync_ctx->async_data.pa_base.u. |
| 2901 | a64.address = |
| 2902 | mem_descr->mem_array[idx]. |
| 2903 | bus_address.u.a64.address; |
| 2904 | num_async_data = |
| 2905 | ((mem_descr->mem_array[idx]. |
| 2906 | size) / |
| 2907 | phba->params.defpdu_data_sz); |
| 2908 | } |
| 2909 | pasync_data_h->pbuffer = |
| 2910 | (void *)((unsigned long) |
| 2911 | (pasync_ctx->async_data.va_base) + |
| 2912 | (p->defpdu_data_sz * num_per_mem)); |
| 2913 | |
| 2914 | pasync_data_h->pa.u.a64.address = |
| 2915 | pasync_ctx->async_data.pa_base.u.a64. |
| 2916 | address + (p->defpdu_data_sz * |
| 2917 | num_per_mem); |
| 2918 | num_per_mem++; |
| 2919 | num_async_data--; |
| 2920 | |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 2921 | pasync_ctx->async_entry[index].data = |
| 2922 | pasync_data_h; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2923 | pasync_data_h++; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2924 | } |
Jayamohan Kallickal | dc63aac | 2012-04-03 23:41:36 -0500 | [diff] [blame] | 2925 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2926 | } |
| 2927 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2928 | return 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2929 | } |
| 2930 | |
| 2931 | static int |
| 2932 | be_sgl_create_contiguous(void *virtual_address, |
| 2933 | u64 physical_address, u32 length, |
| 2934 | struct be_dma_mem *sgl) |
| 2935 | { |
| 2936 | WARN_ON(!virtual_address); |
| 2937 | WARN_ON(!physical_address); |
Tim Gardner | dd29dae | 2015-10-30 12:22:58 -0600 | [diff] [blame] | 2938 | WARN_ON(!length); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2939 | WARN_ON(!sgl); |
| 2940 | |
| 2941 | sgl->va = virtual_address; |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 2942 | sgl->dma = (unsigned long)physical_address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2943 | sgl->size = length; |
| 2944 | |
| 2945 | return 0; |
| 2946 | } |
| 2947 | |
| 2948 | static void be_sgl_destroy_contiguous(struct be_dma_mem *sgl) |
| 2949 | { |
| 2950 | memset(sgl, 0, sizeof(*sgl)); |
| 2951 | } |
| 2952 | |
| 2953 | static void |
| 2954 | hwi_build_be_sgl_arr(struct beiscsi_hba *phba, |
| 2955 | struct mem_array *pmem, struct be_dma_mem *sgl) |
| 2956 | { |
| 2957 | if (sgl->va) |
| 2958 | be_sgl_destroy_contiguous(sgl); |
| 2959 | |
| 2960 | be_sgl_create_contiguous(pmem->virtual_address, |
| 2961 | pmem->bus_address.u.a64.address, |
| 2962 | pmem->size, sgl); |
| 2963 | } |
| 2964 | |
| 2965 | static void |
| 2966 | hwi_build_be_sgl_by_offset(struct beiscsi_hba *phba, |
| 2967 | struct mem_array *pmem, struct be_dma_mem *sgl) |
| 2968 | { |
| 2969 | if (sgl->va) |
| 2970 | be_sgl_destroy_contiguous(sgl); |
| 2971 | |
| 2972 | be_sgl_create_contiguous((unsigned char *)pmem->virtual_address, |
| 2973 | pmem->bus_address.u.a64.address, |
| 2974 | pmem->size, sgl); |
| 2975 | } |
| 2976 | |
| 2977 | static int be_fill_queue(struct be_queue_info *q, |
| 2978 | u16 len, u16 entry_size, void *vaddress) |
| 2979 | { |
| 2980 | struct be_dma_mem *mem = &q->dma_mem; |
| 2981 | |
| 2982 | memset(q, 0, sizeof(*q)); |
| 2983 | q->len = len; |
| 2984 | q->entry_size = entry_size; |
| 2985 | mem->size = len * entry_size; |
| 2986 | mem->va = vaddress; |
| 2987 | if (!mem->va) |
| 2988 | return -ENOMEM; |
| 2989 | memset(mem->va, 0, mem->size); |
| 2990 | return 0; |
| 2991 | } |
| 2992 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2993 | static int beiscsi_create_eqs(struct beiscsi_hba *phba, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2994 | struct hwi_context_memory *phwi_context) |
| 2995 | { |
Christophe JAILLET | deeea8e | 2016-08-26 15:09:06 +0530 | [diff] [blame] | 2996 | int ret = -ENOMEM, eq_for_mcc; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2997 | unsigned int i, num_eq_pages; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2998 | struct be_queue_info *eq; |
| 2999 | struct be_dma_mem *mem; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3000 | void *eq_vaddress; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3001 | dma_addr_t paddr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3002 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3003 | num_eq_pages = PAGES_REQUIRED(phba->params.num_eq_entries * \ |
| 3004 | sizeof(struct be_eq_entry)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3005 | |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 3006 | if (phba->pcidev->msix_enabled) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3007 | eq_for_mcc = 1; |
| 3008 | else |
| 3009 | eq_for_mcc = 0; |
| 3010 | for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) { |
| 3011 | eq = &phwi_context->be_eq[i].q; |
| 3012 | mem = &eq->dma_mem; |
| 3013 | phwi_context->be_eq[i].phba = phba; |
Christoph Hellwig | 26a4c99 | 2018-10-10 18:22:24 +0200 | [diff] [blame] | 3014 | eq_vaddress = dma_alloc_coherent(&phba->pcidev->dev, |
Christophe JAILLET | deeea8e | 2016-08-26 15:09:06 +0530 | [diff] [blame] | 3015 | num_eq_pages * PAGE_SIZE, |
Christoph Hellwig | 26a4c99 | 2018-10-10 18:22:24 +0200 | [diff] [blame] | 3016 | &paddr, GFP_KERNEL); |
Pan Bian | 84a261f | 2016-12-04 13:23:04 +0800 | [diff] [blame] | 3017 | if (!eq_vaddress) { |
| 3018 | ret = -ENOMEM; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3019 | goto create_eq_error; |
Pan Bian | 84a261f | 2016-12-04 13:23:04 +0800 | [diff] [blame] | 3020 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3021 | |
| 3022 | mem->va = eq_vaddress; |
| 3023 | ret = be_fill_queue(eq, phba->params.num_eq_entries, |
| 3024 | sizeof(struct be_eq_entry), eq_vaddress); |
| 3025 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3026 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3027 | "BM_%d : be_fill_queue Failed for EQ\n"); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3028 | goto create_eq_error; |
| 3029 | } |
| 3030 | |
| 3031 | mem->dma = paddr; |
| 3032 | ret = beiscsi_cmd_eq_create(&phba->ctrl, eq, |
Jitendra Bhivare | 45efc940 | 2017-10-10 16:18:18 +0530 | [diff] [blame] | 3033 | BEISCSI_EQ_DELAY_DEF); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3034 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3035 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3036 | "BM_%d : beiscsi_cmd_eq_create" |
| 3037 | "Failed for EQ\n"); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3038 | goto create_eq_error; |
| 3039 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3040 | |
| 3041 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3042 | "BM_%d : eqid = %d\n", |
| 3043 | phwi_context->be_eq[i].q.id); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3044 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3045 | return 0; |
Christophe JAILLET | deeea8e | 2016-08-26 15:09:06 +0530 | [diff] [blame] | 3046 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3047 | create_eq_error: |
John Soni Jose | 107dfcb | 2012-10-20 04:42:13 +0530 | [diff] [blame] | 3048 | for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3049 | eq = &phwi_context->be_eq[i].q; |
| 3050 | mem = &eq->dma_mem; |
| 3051 | if (mem->va) |
Christoph Hellwig | 26a4c99 | 2018-10-10 18:22:24 +0200 | [diff] [blame] | 3052 | dma_free_coherent(&phba->pcidev->dev, num_eq_pages |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3053 | * PAGE_SIZE, |
| 3054 | mem->va, mem->dma); |
| 3055 | } |
| 3056 | return ret; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3057 | } |
| 3058 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3059 | static int beiscsi_create_cqs(struct beiscsi_hba *phba, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3060 | struct hwi_context_memory *phwi_context) |
| 3061 | { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3062 | unsigned int i, num_cq_pages; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3063 | struct be_queue_info *cq, *eq; |
| 3064 | struct be_dma_mem *mem; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3065 | struct be_eq_obj *pbe_eq; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3066 | void *cq_vaddress; |
Christophe JAILLET | deeea8e | 2016-08-26 15:09:06 +0530 | [diff] [blame] | 3067 | int ret = -ENOMEM; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3068 | dma_addr_t paddr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3069 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3070 | num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \ |
| 3071 | sizeof(struct sol_cqe)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3072 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3073 | for (i = 0; i < phba->num_cpus; i++) { |
| 3074 | cq = &phwi_context->be_cq[i]; |
| 3075 | eq = &phwi_context->be_eq[i].q; |
| 3076 | pbe_eq = &phwi_context->be_eq[i]; |
| 3077 | pbe_eq->cq = cq; |
| 3078 | pbe_eq->phba = phba; |
| 3079 | mem = &cq->dma_mem; |
Christoph Hellwig | 26a4c99 | 2018-10-10 18:22:24 +0200 | [diff] [blame] | 3080 | cq_vaddress = dma_alloc_coherent(&phba->pcidev->dev, |
Christophe JAILLET | deeea8e | 2016-08-26 15:09:06 +0530 | [diff] [blame] | 3081 | num_cq_pages * PAGE_SIZE, |
Christoph Hellwig | 26a4c99 | 2018-10-10 18:22:24 +0200 | [diff] [blame] | 3082 | &paddr, GFP_KERNEL); |
Pan Bian | 29b3325 | 2016-12-04 13:21:42 +0800 | [diff] [blame] | 3083 | if (!cq_vaddress) { |
| 3084 | ret = -ENOMEM; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3085 | goto create_cq_error; |
Pan Bian | 29b3325 | 2016-12-04 13:21:42 +0800 | [diff] [blame] | 3086 | } |
Christophe JAILLET | deeea8e | 2016-08-26 15:09:06 +0530 | [diff] [blame] | 3087 | |
Jayamohan Kallickal | 7da5087 | 2010-01-05 05:04:12 +0530 | [diff] [blame] | 3088 | ret = be_fill_queue(cq, phba->params.num_cq_entries, |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3089 | sizeof(struct sol_cqe), cq_vaddress); |
| 3090 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3091 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3092 | "BM_%d : be_fill_queue Failed " |
| 3093 | "for ISCSI CQ\n"); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3094 | goto create_cq_error; |
| 3095 | } |
| 3096 | |
| 3097 | mem->dma = paddr; |
| 3098 | ret = beiscsi_cmd_cq_create(&phba->ctrl, cq, eq, false, |
| 3099 | false, 0); |
| 3100 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3101 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3102 | "BM_%d : beiscsi_cmd_eq_create" |
| 3103 | "Failed for ISCSI CQ\n"); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3104 | goto create_cq_error; |
| 3105 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3106 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3107 | "BM_%d : iscsi cq_id is %d for eq_id %d\n" |
| 3108 | "iSCSI CQ CREATED\n", cq->id, eq->id); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3109 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3110 | return 0; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3111 | |
| 3112 | create_cq_error: |
| 3113 | for (i = 0; i < phba->num_cpus; i++) { |
| 3114 | cq = &phwi_context->be_cq[i]; |
| 3115 | mem = &cq->dma_mem; |
| 3116 | if (mem->va) |
Christoph Hellwig | 26a4c99 | 2018-10-10 18:22:24 +0200 | [diff] [blame] | 3117 | dma_free_coherent(&phba->pcidev->dev, num_cq_pages |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3118 | * PAGE_SIZE, |
| 3119 | mem->va, mem->dma); |
| 3120 | } |
| 3121 | return ret; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3122 | } |
| 3123 | |
| 3124 | static int |
| 3125 | beiscsi_create_def_hdr(struct beiscsi_hba *phba, |
| 3126 | struct hwi_context_memory *phwi_context, |
| 3127 | struct hwi_controller *phwi_ctrlr, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3128 | unsigned int def_pdu_ring_sz, uint8_t ulp_num) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3129 | { |
| 3130 | unsigned int idx; |
| 3131 | int ret; |
| 3132 | struct be_queue_info *dq, *cq; |
| 3133 | struct be_dma_mem *mem; |
| 3134 | struct be_mem_descriptor *mem_descr; |
| 3135 | void *dq_vaddress; |
| 3136 | |
| 3137 | idx = 0; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3138 | dq = &phwi_context->be_def_hdrq[ulp_num]; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3139 | cq = &phwi_context->be_cq[0]; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3140 | mem = &dq->dma_mem; |
| 3141 | mem_descr = phba->init_mem; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3142 | mem_descr += HWI_MEM_ASYNC_HEADER_RING_ULP0 + |
| 3143 | (ulp_num * MEM_DESCR_OFFSET); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3144 | dq_vaddress = mem_descr->mem_array[idx].virtual_address; |
| 3145 | ret = be_fill_queue(dq, mem_descr->mem_array[0].size / |
| 3146 | sizeof(struct phys_addr), |
| 3147 | sizeof(struct phys_addr), dq_vaddress); |
| 3148 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3149 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3150 | "BM_%d : be_fill_queue Failed for DEF PDU HDR on ULP : %d\n", |
| 3151 | ulp_num); |
| 3152 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3153 | return ret; |
| 3154 | } |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 3155 | mem->dma = (unsigned long)mem_descr->mem_array[idx]. |
| 3156 | bus_address.u.a64.address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3157 | ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dq, |
| 3158 | def_pdu_ring_sz, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3159 | phba->params.defpdu_hdr_sz, |
| 3160 | BEISCSI_DEFQ_HDR, ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3161 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3162 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3163 | "BM_%d : be_cmd_create_default_pdu_queue Failed DEFHDR on ULP : %d\n", |
| 3164 | ulp_num); |
| 3165 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3166 | return ret; |
| 3167 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3168 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3169 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3170 | "BM_%d : iscsi hdr def pdu id for ULP : %d is %d\n", |
| 3171 | ulp_num, |
| 3172 | phwi_context->be_def_hdrq[ulp_num].id); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3173 | return 0; |
| 3174 | } |
| 3175 | |
| 3176 | static int |
| 3177 | beiscsi_create_def_data(struct beiscsi_hba *phba, |
| 3178 | struct hwi_context_memory *phwi_context, |
| 3179 | struct hwi_controller *phwi_ctrlr, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3180 | unsigned int def_pdu_ring_sz, uint8_t ulp_num) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3181 | { |
| 3182 | unsigned int idx; |
| 3183 | int ret; |
| 3184 | struct be_queue_info *dataq, *cq; |
| 3185 | struct be_dma_mem *mem; |
| 3186 | struct be_mem_descriptor *mem_descr; |
| 3187 | void *dq_vaddress; |
| 3188 | |
| 3189 | idx = 0; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3190 | dataq = &phwi_context->be_def_dataq[ulp_num]; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3191 | cq = &phwi_context->be_cq[0]; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3192 | mem = &dataq->dma_mem; |
| 3193 | mem_descr = phba->init_mem; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3194 | mem_descr += HWI_MEM_ASYNC_DATA_RING_ULP0 + |
| 3195 | (ulp_num * MEM_DESCR_OFFSET); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3196 | dq_vaddress = mem_descr->mem_array[idx].virtual_address; |
| 3197 | ret = be_fill_queue(dataq, mem_descr->mem_array[0].size / |
| 3198 | sizeof(struct phys_addr), |
| 3199 | sizeof(struct phys_addr), dq_vaddress); |
| 3200 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3201 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3202 | "BM_%d : be_fill_queue Failed for DEF PDU " |
| 3203 | "DATA on ULP : %d\n", |
| 3204 | ulp_num); |
| 3205 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3206 | return ret; |
| 3207 | } |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 3208 | mem->dma = (unsigned long)mem_descr->mem_array[idx]. |
| 3209 | bus_address.u.a64.address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3210 | ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dataq, |
| 3211 | def_pdu_ring_sz, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3212 | phba->params.defpdu_data_sz, |
| 3213 | BEISCSI_DEFQ_DATA, ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3214 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3215 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3216 | "BM_%d be_cmd_create_default_pdu_queue" |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3217 | " Failed for DEF PDU DATA on ULP : %d\n", |
| 3218 | ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3219 | return ret; |
| 3220 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3221 | |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3222 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3223 | "BM_%d : iscsi def data id on ULP : %d is %d\n", |
| 3224 | ulp_num, |
| 3225 | phwi_context->be_def_dataq[ulp_num].id); |
| 3226 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3227 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3228 | "BM_%d : DEFAULT PDU DATA RING CREATED" |
| 3229 | "on ULP : %d\n", ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3230 | return 0; |
| 3231 | } |
| 3232 | |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3233 | |
| 3234 | static int |
| 3235 | beiscsi_post_template_hdr(struct beiscsi_hba *phba) |
| 3236 | { |
| 3237 | struct be_mem_descriptor *mem_descr; |
| 3238 | struct mem_array *pm_arr; |
| 3239 | struct be_dma_mem sgl; |
Jayamohan Kallickal | a129d92 | 2013-09-28 15:35:46 -0700 | [diff] [blame] | 3240 | int status, ulp_num; |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3241 | |
Jayamohan Kallickal | a129d92 | 2013-09-28 15:35:46 -0700 | [diff] [blame] | 3242 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 3243 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
| 3244 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 3245 | mem_descr += HWI_MEM_TEMPLATE_HDR_ULP0 + |
| 3246 | (ulp_num * MEM_DESCR_OFFSET); |
| 3247 | pm_arr = mem_descr->mem_array; |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3248 | |
Jayamohan Kallickal | a129d92 | 2013-09-28 15:35:46 -0700 | [diff] [blame] | 3249 | hwi_build_be_sgl_arr(phba, pm_arr, &sgl); |
| 3250 | status = be_cmd_iscsi_post_template_hdr( |
| 3251 | &phba->ctrl, &sgl); |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3252 | |
Jayamohan Kallickal | a129d92 | 2013-09-28 15:35:46 -0700 | [diff] [blame] | 3253 | if (status != 0) { |
| 3254 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3255 | "BM_%d : Post Template HDR Failed for" |
| 3256 | "ULP_%d\n", ulp_num); |
| 3257 | return status; |
| 3258 | } |
| 3259 | |
| 3260 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3261 | "BM_%d : Template HDR Pages Posted for" |
| 3262 | "ULP_%d\n", ulp_num); |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3263 | } |
| 3264 | } |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3265 | return 0; |
| 3266 | } |
| 3267 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3268 | static int |
| 3269 | beiscsi_post_pages(struct beiscsi_hba *phba) |
| 3270 | { |
| 3271 | struct be_mem_descriptor *mem_descr; |
| 3272 | struct mem_array *pm_arr; |
| 3273 | unsigned int page_offset, i; |
| 3274 | struct be_dma_mem sgl; |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 3275 | int status, ulp_num = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3276 | |
| 3277 | mem_descr = phba->init_mem; |
| 3278 | mem_descr += HWI_MEM_SGE; |
| 3279 | pm_arr = mem_descr->mem_array; |
| 3280 | |
Jayamohan Kallickal | 90622db | 2013-09-28 15:35:47 -0700 | [diff] [blame] | 3281 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) |
| 3282 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) |
| 3283 | break; |
| 3284 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3285 | page_offset = (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io * |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 3286 | phba->fw_config.iscsi_icd_start[ulp_num]) / PAGE_SIZE; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3287 | for (i = 0; i < mem_descr->num_elements; i++) { |
| 3288 | hwi_build_be_sgl_arr(phba, pm_arr, &sgl); |
| 3289 | status = be_cmd_iscsi_post_sgl_pages(&phba->ctrl, &sgl, |
| 3290 | page_offset, |
| 3291 | (pm_arr->size / PAGE_SIZE)); |
| 3292 | page_offset += pm_arr->size / PAGE_SIZE; |
| 3293 | if (status != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3294 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3295 | "BM_%d : post sgl failed.\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3296 | return status; |
| 3297 | } |
| 3298 | pm_arr++; |
| 3299 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3300 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3301 | "BM_%d : POSTED PAGES\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3302 | return 0; |
| 3303 | } |
| 3304 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3305 | static void be_queue_free(struct beiscsi_hba *phba, struct be_queue_info *q) |
| 3306 | { |
| 3307 | struct be_dma_mem *mem = &q->dma_mem; |
Jayamohan Kallickal | c8b2559 | 2012-04-03 23:41:42 -0500 | [diff] [blame] | 3308 | if (mem->va) { |
Christoph Hellwig | 26a4c99 | 2018-10-10 18:22:24 +0200 | [diff] [blame] | 3309 | dma_free_coherent(&phba->pcidev->dev, mem->size, |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3310 | mem->va, mem->dma); |
Jayamohan Kallickal | c8b2559 | 2012-04-03 23:41:42 -0500 | [diff] [blame] | 3311 | mem->va = NULL; |
| 3312 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3313 | } |
| 3314 | |
| 3315 | static int be_queue_alloc(struct beiscsi_hba *phba, struct be_queue_info *q, |
| 3316 | u16 len, u16 entry_size) |
| 3317 | { |
| 3318 | struct be_dma_mem *mem = &q->dma_mem; |
| 3319 | |
| 3320 | memset(q, 0, sizeof(*q)); |
| 3321 | q->len = len; |
| 3322 | q->entry_size = entry_size; |
| 3323 | mem->size = len * entry_size; |
Christoph Hellwig | 26a4c99 | 2018-10-10 18:22:24 +0200 | [diff] [blame] | 3324 | mem->va = dma_zalloc_coherent(&phba->pcidev->dev, mem->size, &mem->dma, |
| 3325 | GFP_KERNEL); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3326 | if (!mem->va) |
Jayamohan Kallickal | d3ad2bb | 2010-07-22 04:16:38 +0530 | [diff] [blame] | 3327 | return -ENOMEM; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3328 | return 0; |
| 3329 | } |
| 3330 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3331 | static int |
| 3332 | beiscsi_create_wrb_rings(struct beiscsi_hba *phba, |
| 3333 | struct hwi_context_memory *phwi_context, |
| 3334 | struct hwi_controller *phwi_ctrlr) |
| 3335 | { |
Jitendra Bhivare | fa1261c | 2016-12-13 15:56:01 +0530 | [diff] [blame] | 3336 | unsigned int num_wrb_rings; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3337 | u64 pa_addr_lo; |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 3338 | unsigned int idx, num, i, ulp_num; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3339 | struct mem_array *pwrb_arr; |
| 3340 | void *wrb_vaddr; |
| 3341 | struct be_dma_mem sgl; |
| 3342 | struct be_mem_descriptor *mem_descr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 3343 | struct hwi_wrb_context *pwrb_context; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3344 | int status; |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 3345 | uint8_t ulp_count = 0, ulp_base_num = 0; |
| 3346 | uint16_t cid_count_ulp[BEISCSI_ULP_COUNT] = { 0 }; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3347 | |
| 3348 | idx = 0; |
| 3349 | mem_descr = phba->init_mem; |
| 3350 | mem_descr += HWI_MEM_WRB; |
Kees Cook | 6da2ec5 | 2018-06-12 13:55:00 -0700 | [diff] [blame] | 3351 | pwrb_arr = kmalloc_array(phba->params.cxns_per_ctrl, |
| 3352 | sizeof(*pwrb_arr), |
| 3353 | GFP_KERNEL); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3354 | if (!pwrb_arr) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3355 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3356 | "BM_%d : Memory alloc failed in create wrb ring.\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3357 | return -ENOMEM; |
| 3358 | } |
| 3359 | wrb_vaddr = mem_descr->mem_array[idx].virtual_address; |
| 3360 | pa_addr_lo = mem_descr->mem_array[idx].bus_address.u.a64.address; |
| 3361 | num_wrb_rings = mem_descr->mem_array[idx].size / |
| 3362 | (phba->params.wrbs_per_cxn * sizeof(struct iscsi_wrb)); |
| 3363 | |
| 3364 | for (num = 0; num < phba->params.cxns_per_ctrl; num++) { |
| 3365 | if (num_wrb_rings) { |
| 3366 | pwrb_arr[num].virtual_address = wrb_vaddr; |
| 3367 | pwrb_arr[num].bus_address.u.a64.address = pa_addr_lo; |
| 3368 | pwrb_arr[num].size = phba->params.wrbs_per_cxn * |
| 3369 | sizeof(struct iscsi_wrb); |
| 3370 | wrb_vaddr += pwrb_arr[num].size; |
| 3371 | pa_addr_lo += pwrb_arr[num].size; |
| 3372 | num_wrb_rings--; |
| 3373 | } else { |
| 3374 | idx++; |
| 3375 | wrb_vaddr = mem_descr->mem_array[idx].virtual_address; |
| 3376 | pa_addr_lo = mem_descr->mem_array[idx].\ |
| 3377 | bus_address.u.a64.address; |
| 3378 | num_wrb_rings = mem_descr->mem_array[idx].size / |
| 3379 | (phba->params.wrbs_per_cxn * |
| 3380 | sizeof(struct iscsi_wrb)); |
| 3381 | pwrb_arr[num].virtual_address = wrb_vaddr; |
| 3382 | pwrb_arr[num].bus_address.u.a64.address\ |
| 3383 | = pa_addr_lo; |
| 3384 | pwrb_arr[num].size = phba->params.wrbs_per_cxn * |
| 3385 | sizeof(struct iscsi_wrb); |
| 3386 | wrb_vaddr += pwrb_arr[num].size; |
| 3387 | pa_addr_lo += pwrb_arr[num].size; |
| 3388 | num_wrb_rings--; |
| 3389 | } |
| 3390 | } |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 3391 | |
| 3392 | /* Get the ULP Count */ |
| 3393 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) |
| 3394 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
| 3395 | ulp_count++; |
| 3396 | ulp_base_num = ulp_num; |
| 3397 | cid_count_ulp[ulp_num] = |
| 3398 | BEISCSI_GET_CID_COUNT(phba, ulp_num); |
| 3399 | } |
| 3400 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3401 | for (i = 0; i < phba->params.cxns_per_ctrl; i++) { |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 3402 | if (ulp_count > 1) { |
| 3403 | ulp_base_num = (ulp_base_num + 1) % BEISCSI_ULP_COUNT; |
| 3404 | |
| 3405 | if (!cid_count_ulp[ulp_base_num]) |
| 3406 | ulp_base_num = (ulp_base_num + 1) % |
| 3407 | BEISCSI_ULP_COUNT; |
| 3408 | |
| 3409 | cid_count_ulp[ulp_base_num]--; |
| 3410 | } |
| 3411 | |
| 3412 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3413 | hwi_build_be_sgl_by_offset(phba, &pwrb_arr[i], &sgl); |
| 3414 | status = be_cmd_wrbq_create(&phba->ctrl, &sgl, |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 3415 | &phwi_context->be_wrbq[i], |
| 3416 | &phwi_ctrlr->wrb_context[i], |
| 3417 | ulp_base_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3418 | if (status != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3419 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3420 | "BM_%d : wrbq create failed."); |
Dan Carpenter | 1462b8f | 2010-06-10 09:52:21 +0200 | [diff] [blame] | 3421 | kfree(pwrb_arr); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3422 | return status; |
| 3423 | } |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 3424 | pwrb_context = &phwi_ctrlr->wrb_context[i]; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 3425 | BE_SET_CID_TO_CRI(i, pwrb_context->cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3426 | } |
| 3427 | kfree(pwrb_arr); |
| 3428 | return 0; |
| 3429 | } |
| 3430 | |
| 3431 | static void free_wrb_handles(struct beiscsi_hba *phba) |
| 3432 | { |
| 3433 | unsigned int index; |
| 3434 | struct hwi_controller *phwi_ctrlr; |
| 3435 | struct hwi_wrb_context *pwrb_context; |
| 3436 | |
| 3437 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 3438 | for (index = 0; index < phba->params.cxns_per_ctrl; index++) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3439 | pwrb_context = &phwi_ctrlr->wrb_context[index]; |
| 3440 | kfree(pwrb_context->pwrb_handle_base); |
| 3441 | kfree(pwrb_context->pwrb_handle_basestd); |
| 3442 | } |
| 3443 | } |
| 3444 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3445 | static void be_mcc_queues_destroy(struct beiscsi_hba *phba) |
| 3446 | { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3447 | struct be_ctrl_info *ctrl = &phba->ctrl; |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 3448 | struct be_dma_mem *ptag_mem; |
| 3449 | struct be_queue_info *q; |
| 3450 | int i, tag; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3451 | |
| 3452 | q = &phba->ctrl.mcc_obj.q; |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 3453 | for (i = 0; i < MAX_MCC_CMD; i++) { |
| 3454 | tag = i + 1; |
| 3455 | if (!test_bit(MCC_TAG_STATE_RUNNING, |
| 3456 | &ctrl->ptag_state[tag].tag_state)) |
| 3457 | continue; |
| 3458 | |
| 3459 | if (test_bit(MCC_TAG_STATE_TIMEOUT, |
| 3460 | &ctrl->ptag_state[tag].tag_state)) { |
| 3461 | ptag_mem = &ctrl->ptag_state[tag].tag_mem_state; |
| 3462 | if (ptag_mem->size) { |
Christoph Hellwig | 26a4c99 | 2018-10-10 18:22:24 +0200 | [diff] [blame] | 3463 | dma_free_coherent(&ctrl->pdev->dev, |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 3464 | ptag_mem->size, |
| 3465 | ptag_mem->va, |
| 3466 | ptag_mem->dma); |
| 3467 | ptag_mem->size = 0; |
| 3468 | } |
| 3469 | continue; |
| 3470 | } |
| 3471 | /** |
| 3472 | * If MCC is still active and waiting then wake up the process. |
| 3473 | * We are here only because port is going offline. The process |
| 3474 | * sees that (BEISCSI_HBA_ONLINE is cleared) and EIO error is |
| 3475 | * returned for the operation and allocated memory cleaned up. |
| 3476 | */ |
| 3477 | if (waitqueue_active(&ctrl->mcc_wait[tag])) { |
| 3478 | ctrl->mcc_tag_status[tag] = MCC_STATUS_FAILED; |
| 3479 | ctrl->mcc_tag_status[tag] |= CQE_VALID_MASK; |
| 3480 | wake_up_interruptible(&ctrl->mcc_wait[tag]); |
| 3481 | /* |
| 3482 | * Control tag info gets reinitialized in enable |
| 3483 | * so wait for the process to clear running state. |
| 3484 | */ |
| 3485 | while (test_bit(MCC_TAG_STATE_RUNNING, |
| 3486 | &ctrl->ptag_state[tag].tag_state)) |
| 3487 | schedule_timeout_uninterruptible(HZ); |
| 3488 | } |
| 3489 | /** |
| 3490 | * For MCC with tag_states MCC_TAG_STATE_ASYNC and |
| 3491 | * MCC_TAG_STATE_IGNORE nothing needs to done. |
| 3492 | */ |
| 3493 | } |
John Soni Jose | 4e2bdf7 | 2015-04-25 08:17:31 +0530 | [diff] [blame] | 3494 | if (q->created) { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3495 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_MCCQ); |
John Soni Jose | 4e2bdf7 | 2015-04-25 08:17:31 +0530 | [diff] [blame] | 3496 | be_queue_free(phba, q); |
| 3497 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3498 | |
| 3499 | q = &phba->ctrl.mcc_obj.cq; |
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_CQ); |
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 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3506 | static int be_mcc_queues_create(struct beiscsi_hba *phba, |
| 3507 | struct hwi_context_memory *phwi_context) |
| 3508 | { |
| 3509 | struct be_queue_info *q, *cq; |
| 3510 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 3511 | |
| 3512 | /* Alloc MCC compl queue */ |
| 3513 | cq = &phba->ctrl.mcc_obj.cq; |
| 3514 | if (be_queue_alloc(phba, cq, MCC_CQ_LEN, |
| 3515 | sizeof(struct be_mcc_compl))) |
| 3516 | goto err; |
| 3517 | /* Ask BE to create MCC compl queue; */ |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 3518 | if (phba->pcidev->msix_enabled) { |
Jitendra Bhivare | 45efc940 | 2017-10-10 16:18:18 +0530 | [diff] [blame] | 3519 | if (beiscsi_cmd_cq_create(ctrl, cq, |
| 3520 | &phwi_context->be_eq[phba->num_cpus].q, |
| 3521 | false, true, 0)) |
| 3522 | goto mcc_cq_free; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3523 | } else { |
| 3524 | if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq[0].q, |
| 3525 | false, true, 0)) |
Jitendra Bhivare | 45efc940 | 2017-10-10 16:18:18 +0530 | [diff] [blame] | 3526 | goto mcc_cq_free; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3527 | } |
| 3528 | |
| 3529 | /* Alloc MCC queue */ |
| 3530 | q = &phba->ctrl.mcc_obj.q; |
| 3531 | if (be_queue_alloc(phba, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb))) |
| 3532 | goto mcc_cq_destroy; |
| 3533 | |
| 3534 | /* Ask BE to create MCC queue */ |
Jayamohan Kallickal | 35e6601 | 2009-10-23 11:53:49 +0530 | [diff] [blame] | 3535 | if (beiscsi_cmd_mccq_create(phba, q, cq)) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3536 | goto mcc_q_free; |
| 3537 | |
| 3538 | return 0; |
| 3539 | |
| 3540 | mcc_q_free: |
| 3541 | be_queue_free(phba, q); |
| 3542 | mcc_cq_destroy: |
| 3543 | beiscsi_cmd_q_destroy(ctrl, cq, QTYPE_CQ); |
| 3544 | mcc_cq_free: |
| 3545 | be_queue_free(phba, cq); |
| 3546 | err: |
Jayamohan Kallickal | d3ad2bb | 2010-07-22 04:16:38 +0530 | [diff] [blame] | 3547 | return -ENOMEM; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3548 | } |
| 3549 | |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 3550 | static void be2iscsi_enable_msix(struct beiscsi_hba *phba) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3551 | { |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 3552 | int nvec = 1; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3553 | |
John Soni Jose | 22abeef | 2012-10-20 04:43:32 +0530 | [diff] [blame] | 3554 | switch (phba->generation) { |
| 3555 | case BE_GEN2: |
| 3556 | case BE_GEN3: |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 3557 | nvec = BEISCSI_MAX_NUM_CPUS + 1; |
John Soni Jose | 22abeef | 2012-10-20 04:43:32 +0530 | [diff] [blame] | 3558 | break; |
| 3559 | case BE_GEN4: |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 3560 | nvec = phba->fw_config.eqid_count; |
John Soni Jose | 22abeef | 2012-10-20 04:43:32 +0530 | [diff] [blame] | 3561 | break; |
| 3562 | default: |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 3563 | nvec = 2; |
| 3564 | break; |
John Soni Jose | 22abeef | 2012-10-20 04:43:32 +0530 | [diff] [blame] | 3565 | } |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 3566 | |
| 3567 | /* if eqid_count == 1 fall back to INTX */ |
| 3568 | if (enable_msix && nvec > 1) { |
| 3569 | const struct irq_affinity desc = { .post_vectors = 1 }; |
| 3570 | |
| 3571 | if (pci_alloc_irq_vectors_affinity(phba->pcidev, 2, nvec, |
| 3572 | PCI_IRQ_MSIX | PCI_IRQ_AFFINITY, &desc) < 0) { |
| 3573 | phba->num_cpus = nvec - 1; |
| 3574 | return; |
| 3575 | } |
| 3576 | } |
| 3577 | |
| 3578 | phba->num_cpus = 1; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3579 | } |
| 3580 | |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 3581 | static void hwi_purge_eq(struct beiscsi_hba *phba) |
| 3582 | { |
| 3583 | struct hwi_controller *phwi_ctrlr; |
| 3584 | struct hwi_context_memory *phwi_context; |
| 3585 | struct be_queue_info *eq; |
| 3586 | struct be_eq_entry *eqe = NULL; |
| 3587 | int i, eq_msix; |
| 3588 | unsigned int num_processed; |
| 3589 | |
| 3590 | if (beiscsi_hba_in_error(phba)) |
| 3591 | return; |
| 3592 | |
| 3593 | phwi_ctrlr = phba->phwi_ctrlr; |
| 3594 | phwi_context = phwi_ctrlr->phwi_ctxt; |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 3595 | if (phba->pcidev->msix_enabled) |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 3596 | eq_msix = 1; |
| 3597 | else |
| 3598 | eq_msix = 0; |
| 3599 | |
| 3600 | for (i = 0; i < (phba->num_cpus + eq_msix); i++) { |
| 3601 | eq = &phwi_context->be_eq[i].q; |
| 3602 | eqe = queue_tail_node(eq); |
| 3603 | num_processed = 0; |
| 3604 | while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32] |
| 3605 | & EQE_VALID_MASK) { |
| 3606 | AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0); |
| 3607 | queue_tail_inc(eq); |
| 3608 | eqe = queue_tail_node(eq); |
| 3609 | num_processed++; |
| 3610 | } |
| 3611 | |
| 3612 | if (num_processed) |
| 3613 | hwi_ring_eq_db(phba, eq->id, 1, num_processed, 1, 1); |
| 3614 | } |
| 3615 | } |
| 3616 | |
| 3617 | static void hwi_cleanup_port(struct beiscsi_hba *phba) |
| 3618 | { |
| 3619 | struct be_queue_info *q; |
| 3620 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 3621 | struct hwi_controller *phwi_ctrlr; |
| 3622 | struct hwi_context_memory *phwi_context; |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 3623 | int i, eq_for_mcc, ulp_num; |
| 3624 | |
| 3625 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) |
| 3626 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) |
| 3627 | beiscsi_cmd_iscsi_cleanup(phba, ulp_num); |
| 3628 | |
| 3629 | /** |
| 3630 | * Purge all EQ entries that may have been left out. This is to |
| 3631 | * workaround a problem we've seen occasionally where driver gets an |
| 3632 | * interrupt with EQ entry bit set after stopping the controller. |
| 3633 | */ |
| 3634 | hwi_purge_eq(phba); |
| 3635 | |
| 3636 | phwi_ctrlr = phba->phwi_ctrlr; |
| 3637 | phwi_context = phwi_ctrlr->phwi_ctxt; |
| 3638 | |
| 3639 | be_cmd_iscsi_remove_template_hdr(ctrl); |
| 3640 | |
| 3641 | for (i = 0; i < phba->params.cxns_per_ctrl; i++) { |
| 3642 | q = &phwi_context->be_wrbq[i]; |
| 3643 | if (q->created) |
| 3644 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_WRBQ); |
| 3645 | } |
| 3646 | kfree(phwi_context->be_wrbq); |
| 3647 | free_wrb_handles(phba); |
| 3648 | |
| 3649 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 3650 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
| 3651 | |
| 3652 | q = &phwi_context->be_def_hdrq[ulp_num]; |
| 3653 | if (q->created) |
| 3654 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ); |
| 3655 | |
| 3656 | q = &phwi_context->be_def_dataq[ulp_num]; |
| 3657 | if (q->created) |
| 3658 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 3659 | } |
| 3660 | } |
| 3661 | |
| 3662 | beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL); |
| 3663 | |
| 3664 | for (i = 0; i < (phba->num_cpus); i++) { |
| 3665 | q = &phwi_context->be_cq[i]; |
| 3666 | if (q->created) { |
| 3667 | be_queue_free(phba, q); |
| 3668 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ); |
| 3669 | } |
| 3670 | } |
| 3671 | |
| 3672 | be_mcc_queues_destroy(phba); |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 3673 | if (phba->pcidev->msix_enabled) |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 3674 | eq_for_mcc = 1; |
| 3675 | else |
| 3676 | eq_for_mcc = 0; |
| 3677 | for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) { |
| 3678 | q = &phwi_context->be_eq[i].q; |
| 3679 | if (q->created) { |
| 3680 | be_queue_free(phba, q); |
| 3681 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_EQ); |
| 3682 | } |
| 3683 | } |
Jitendra Bhivare | 4ee1ec4 | 2016-08-19 15:20:20 +0530 | [diff] [blame] | 3684 | /* this ensures complete FW cleanup */ |
| 3685 | beiscsi_cmd_function_reset(phba); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 3686 | /* last communication, indicate driver is unloading */ |
| 3687 | beiscsi_cmd_special_wrb(&phba->ctrl, 0); |
| 3688 | } |
Jitendra Bhivare | 4ee1ec4 | 2016-08-19 15:20:20 +0530 | [diff] [blame] | 3689 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3690 | static int hwi_init_port(struct beiscsi_hba *phba) |
| 3691 | { |
| 3692 | struct hwi_controller *phwi_ctrlr; |
| 3693 | struct hwi_context_memory *phwi_context; |
| 3694 | unsigned int def_pdu_ring_sz; |
| 3695 | struct be_ctrl_info *ctrl = &phba->ctrl; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3696 | int status, ulp_num; |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 3697 | u16 nbufs; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3698 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3699 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3700 | phwi_context = phwi_ctrlr->phwi_ctxt; |
Jitendra Bhivare | 4d2ee1e | 2016-08-19 15:20:16 +0530 | [diff] [blame] | 3701 | /* set port optic state to unknown */ |
Jitendra Bhivare | 53aefe2 | 2016-01-20 14:10:53 +0530 | [diff] [blame] | 3702 | phba->optic_state = 0xff; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3703 | |
| 3704 | status = beiscsi_create_eqs(phba, phwi_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3705 | if (status != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3706 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3707 | "BM_%d : EQ not created\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3708 | goto error; |
| 3709 | } |
| 3710 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3711 | status = be_mcc_queues_create(phba, phwi_context); |
| 3712 | if (status != 0) |
| 3713 | goto error; |
| 3714 | |
Jitendra Bhivare | 480195c | 2016-08-19 15:20:15 +0530 | [diff] [blame] | 3715 | status = beiscsi_check_supported_fw(ctrl, phba); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3716 | if (status != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3717 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3718 | "BM_%d : Unsupported fw version\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3719 | goto error; |
| 3720 | } |
| 3721 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3722 | status = beiscsi_create_cqs(phba, phwi_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3723 | if (status != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3724 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3725 | "BM_%d : CQ not created\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3726 | goto error; |
| 3727 | } |
| 3728 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3729 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 3730 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 3731 | nbufs = phwi_context->pasync_ctx[ulp_num]->num_entries; |
| 3732 | def_pdu_ring_sz = nbufs * sizeof(struct phys_addr); |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3733 | |
| 3734 | status = beiscsi_create_def_hdr(phba, phwi_context, |
| 3735 | phwi_ctrlr, |
| 3736 | def_pdu_ring_sz, |
| 3737 | ulp_num); |
| 3738 | if (status != 0) { |
| 3739 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3740 | "BM_%d : Default Header not created for ULP : %d\n", |
| 3741 | ulp_num); |
| 3742 | goto error; |
| 3743 | } |
| 3744 | |
| 3745 | status = beiscsi_create_def_data(phba, phwi_context, |
| 3746 | phwi_ctrlr, |
| 3747 | def_pdu_ring_sz, |
| 3748 | ulp_num); |
| 3749 | if (status != 0) { |
| 3750 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3751 | "BM_%d : Default Data not created for ULP : %d\n", |
| 3752 | ulp_num); |
| 3753 | goto error; |
| 3754 | } |
Jitendra Bhivare | f79929d | 2016-08-19 15:20:17 +0530 | [diff] [blame] | 3755 | /** |
| 3756 | * Now that the default PDU rings have been created, |
| 3757 | * let EP know about it. |
Jitendra Bhivare | f79929d | 2016-08-19 15:20:17 +0530 | [diff] [blame] | 3758 | */ |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 3759 | beiscsi_hdq_post_handles(phba, BEISCSI_DEFQ_HDR, |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 3760 | ulp_num, nbufs); |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 3761 | beiscsi_hdq_post_handles(phba, BEISCSI_DEFQ_DATA, |
Jitendra Bhivare | 1e2931f | 2017-03-24 14:11:45 +0530 | [diff] [blame] | 3762 | ulp_num, nbufs); |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3763 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3764 | } |
| 3765 | |
| 3766 | status = beiscsi_post_pages(phba); |
| 3767 | if (status != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3768 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3769 | "BM_%d : Post SGL Pages Failed\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3770 | goto error; |
| 3771 | } |
| 3772 | |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3773 | status = beiscsi_post_template_hdr(phba); |
| 3774 | if (status != 0) { |
| 3775 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3776 | "BM_%d : Template HDR Posting for CXN Failed\n"); |
| 3777 | } |
| 3778 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3779 | status = beiscsi_create_wrb_rings(phba, phwi_context, phwi_ctrlr); |
| 3780 | if (status != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3781 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3782 | "BM_%d : WRB Rings not created\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3783 | goto error; |
| 3784 | } |
| 3785 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3786 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 3787 | uint16_t async_arr_idx = 0; |
| 3788 | |
| 3789 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
| 3790 | uint16_t cri = 0; |
Jitendra Bhivare | 938f372 | 2016-08-19 15:20:21 +0530 | [diff] [blame] | 3791 | struct hd_async_context *pasync_ctx; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3792 | |
| 3793 | pasync_ctx = HWI_GET_ASYNC_PDU_CTX( |
| 3794 | phwi_ctrlr, ulp_num); |
| 3795 | for (cri = 0; cri < |
| 3796 | phba->params.cxns_per_ctrl; cri++) { |
| 3797 | if (ulp_num == BEISCSI_GET_ULP_FROM_CRI |
| 3798 | (phwi_ctrlr, cri)) |
| 3799 | pasync_ctx->cid_to_async_cri_map[ |
| 3800 | phwi_ctrlr->wrb_context[cri].cid] = |
| 3801 | async_arr_idx++; |
| 3802 | } |
| 3803 | } |
| 3804 | } |
| 3805 | |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3806 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3807 | "BM_%d : hwi_init_port success\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3808 | return 0; |
| 3809 | |
| 3810 | error: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3811 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3812 | "BM_%d : hwi_init_port failed"); |
Jitendra Bhivare | 4d2ee1e | 2016-08-19 15:20:16 +0530 | [diff] [blame] | 3813 | hwi_cleanup_port(phba); |
Jayamohan Kallickal | a49e06d | 2012-04-03 23:41:44 -0500 | [diff] [blame] | 3814 | return status; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3815 | } |
| 3816 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3817 | static int hwi_init_controller(struct beiscsi_hba *phba) |
| 3818 | { |
| 3819 | struct hwi_controller *phwi_ctrlr; |
| 3820 | |
| 3821 | phwi_ctrlr = phba->phwi_ctrlr; |
| 3822 | if (1 == phba->init_mem[HWI_MEM_ADDN_CONTEXT].num_elements) { |
| 3823 | phwi_ctrlr->phwi_ctxt = (struct hwi_context_memory *)phba-> |
| 3824 | init_mem[HWI_MEM_ADDN_CONTEXT].mem_array[0].virtual_address; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3825 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3826 | "BM_%d : phwi_ctrlr->phwi_ctxt=%p\n", |
| 3827 | phwi_ctrlr->phwi_ctxt); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3828 | } else { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3829 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3830 | "BM_%d : HWI_MEM_ADDN_CONTEXT is more " |
| 3831 | "than one element.Failing to load\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3832 | return -ENOMEM; |
| 3833 | } |
| 3834 | |
| 3835 | iscsi_init_global_templates(phba); |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 3836 | if (beiscsi_init_wrb_handle(phba)) |
| 3837 | return -ENOMEM; |
| 3838 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 3839 | if (hwi_init_async_pdu_ctx(phba)) { |
| 3840 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3841 | "BM_%d : hwi_init_async_pdu_ctx failed\n"); |
| 3842 | return -ENOMEM; |
| 3843 | } |
| 3844 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3845 | if (hwi_init_port(phba) != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3846 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3847 | "BM_%d : hwi_init_controller failed\n"); |
| 3848 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3849 | return -ENOMEM; |
| 3850 | } |
| 3851 | return 0; |
| 3852 | } |
| 3853 | |
| 3854 | static void beiscsi_free_mem(struct beiscsi_hba *phba) |
| 3855 | { |
| 3856 | struct be_mem_descriptor *mem_descr; |
| 3857 | int i, j; |
| 3858 | |
| 3859 | mem_descr = phba->init_mem; |
| 3860 | i = 0; |
| 3861 | j = 0; |
| 3862 | for (i = 0; i < SE_MEM_MAX; i++) { |
| 3863 | for (j = mem_descr->num_elements; j > 0; j--) { |
Christoph Hellwig | 26a4c99 | 2018-10-10 18:22:24 +0200 | [diff] [blame] | 3864 | dma_free_coherent(&phba->pcidev->dev, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3865 | mem_descr->mem_array[j - 1].size, |
| 3866 | mem_descr->mem_array[j - 1].virtual_address, |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 3867 | (unsigned long)mem_descr->mem_array[j - 1]. |
| 3868 | bus_address.u.a64.address); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3869 | } |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3870 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3871 | kfree(mem_descr->mem_array); |
| 3872 | mem_descr++; |
| 3873 | } |
| 3874 | kfree(phba->init_mem); |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 3875 | kfree(phba->phwi_ctrlr->wrb_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3876 | kfree(phba->phwi_ctrlr); |
| 3877 | } |
| 3878 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3879 | static int beiscsi_init_sgl_handle(struct beiscsi_hba *phba) |
| 3880 | { |
| 3881 | struct be_mem_descriptor *mem_descr_sglh, *mem_descr_sg; |
| 3882 | struct sgl_handle *psgl_handle; |
| 3883 | struct iscsi_sge *pfrag; |
Jayamohan Kallickal | 90622db | 2013-09-28 15:35:47 -0700 | [diff] [blame] | 3884 | unsigned int arr_index, i, idx; |
| 3885 | unsigned int ulp_icd_start, ulp_num = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3886 | |
| 3887 | phba->io_sgl_hndl_avbl = 0; |
| 3888 | phba->eh_sgl_hndl_avbl = 0; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3889 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3890 | mem_descr_sglh = phba->init_mem; |
| 3891 | mem_descr_sglh += HWI_MEM_SGLH; |
| 3892 | if (1 == mem_descr_sglh->num_elements) { |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 3893 | phba->io_sgl_hndl_base = kcalloc(phba->params.ios_per_ctrl, |
| 3894 | sizeof(struct sgl_handle *), |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3895 | GFP_KERNEL); |
| 3896 | if (!phba->io_sgl_hndl_base) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3897 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3898 | "BM_%d : Mem Alloc Failed. Failing to load\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3899 | return -ENOMEM; |
| 3900 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 3901 | phba->eh_sgl_hndl_base = |
| 3902 | kcalloc(phba->params.icds_per_ctrl - |
| 3903 | phba->params.ios_per_ctrl, |
| 3904 | sizeof(struct sgl_handle *), GFP_KERNEL); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3905 | if (!phba->eh_sgl_hndl_base) { |
| 3906 | kfree(phba->io_sgl_hndl_base); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3907 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3908 | "BM_%d : Mem Alloc Failed. Failing to load\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3909 | return -ENOMEM; |
| 3910 | } |
| 3911 | } else { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3912 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3913 | "BM_%d : HWI_MEM_SGLH is more than one element." |
| 3914 | "Failing to load\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3915 | return -ENOMEM; |
| 3916 | } |
| 3917 | |
| 3918 | arr_index = 0; |
| 3919 | idx = 0; |
| 3920 | while (idx < mem_descr_sglh->num_elements) { |
| 3921 | psgl_handle = mem_descr_sglh->mem_array[idx].virtual_address; |
| 3922 | |
| 3923 | for (i = 0; i < (mem_descr_sglh->mem_array[idx].size / |
| 3924 | sizeof(struct sgl_handle)); i++) { |
| 3925 | if (arr_index < phba->params.ios_per_ctrl) { |
| 3926 | phba->io_sgl_hndl_base[arr_index] = psgl_handle; |
| 3927 | phba->io_sgl_hndl_avbl++; |
| 3928 | arr_index++; |
| 3929 | } else { |
| 3930 | phba->eh_sgl_hndl_base[arr_index - |
| 3931 | phba->params.ios_per_ctrl] = |
| 3932 | psgl_handle; |
| 3933 | arr_index++; |
| 3934 | phba->eh_sgl_hndl_avbl++; |
| 3935 | } |
| 3936 | psgl_handle++; |
| 3937 | } |
| 3938 | idx++; |
| 3939 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3940 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3941 | "BM_%d : phba->io_sgl_hndl_avbl=%d" |
| 3942 | "phba->eh_sgl_hndl_avbl=%d\n", |
| 3943 | phba->io_sgl_hndl_avbl, |
| 3944 | phba->eh_sgl_hndl_avbl); |
| 3945 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3946 | mem_descr_sg = phba->init_mem; |
| 3947 | mem_descr_sg += HWI_MEM_SGE; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3948 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3949 | "\n BM_%d : mem_descr_sg->num_elements=%d\n", |
| 3950 | mem_descr_sg->num_elements); |
| 3951 | |
Jayamohan Kallickal | 90622db | 2013-09-28 15:35:47 -0700 | [diff] [blame] | 3952 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) |
| 3953 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) |
| 3954 | break; |
| 3955 | |
| 3956 | ulp_icd_start = phba->fw_config.iscsi_icd_start[ulp_num]; |
| 3957 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3958 | arr_index = 0; |
| 3959 | idx = 0; |
| 3960 | while (idx < mem_descr_sg->num_elements) { |
| 3961 | pfrag = mem_descr_sg->mem_array[idx].virtual_address; |
| 3962 | |
| 3963 | for (i = 0; |
| 3964 | i < (mem_descr_sg->mem_array[idx].size) / |
| 3965 | (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io); |
| 3966 | i++) { |
| 3967 | if (arr_index < phba->params.ios_per_ctrl) |
| 3968 | psgl_handle = phba->io_sgl_hndl_base[arr_index]; |
| 3969 | else |
| 3970 | psgl_handle = phba->eh_sgl_hndl_base[arr_index - |
| 3971 | phba->params.ios_per_ctrl]; |
| 3972 | psgl_handle->pfrag = pfrag; |
| 3973 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, pfrag, 0); |
| 3974 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, pfrag, 0); |
| 3975 | pfrag += phba->params.num_sge_per_io; |
Jayamohan Kallickal | 90622db | 2013-09-28 15:35:47 -0700 | [diff] [blame] | 3976 | psgl_handle->sgl_index = ulp_icd_start + arr_index++; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3977 | } |
| 3978 | idx++; |
| 3979 | } |
| 3980 | phba->io_sgl_free_index = 0; |
| 3981 | phba->io_sgl_alloc_index = 0; |
| 3982 | phba->eh_sgl_free_index = 0; |
| 3983 | phba->eh_sgl_alloc_index = 0; |
| 3984 | return 0; |
| 3985 | } |
| 3986 | |
| 3987 | static int hba_setup_cid_tbls(struct beiscsi_hba *phba) |
| 3988 | { |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 3989 | int ret; |
| 3990 | uint16_t i, ulp_num; |
| 3991 | struct ulp_cid_info *ptr_cid_info = NULL; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3992 | |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 3993 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 3994 | if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) { |
| 3995 | ptr_cid_info = kzalloc(sizeof(struct ulp_cid_info), |
| 3996 | GFP_KERNEL); |
| 3997 | |
| 3998 | if (!ptr_cid_info) { |
| 3999 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4000 | "BM_%d : Failed to allocate memory" |
| 4001 | "for ULP_CID_INFO for ULP : %d\n", |
| 4002 | ulp_num); |
| 4003 | ret = -ENOMEM; |
| 4004 | goto free_memory; |
| 4005 | |
| 4006 | } |
| 4007 | |
| 4008 | /* Allocate memory for CID array */ |
Jitendra Bhivare | 413f365 | 2016-12-13 15:56:03 +0530 | [diff] [blame] | 4009 | ptr_cid_info->cid_array = |
| 4010 | kcalloc(BEISCSI_GET_CID_COUNT(phba, ulp_num), |
| 4011 | sizeof(*ptr_cid_info->cid_array), |
| 4012 | GFP_KERNEL); |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4013 | if (!ptr_cid_info->cid_array) { |
| 4014 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4015 | "BM_%d : Failed to allocate memory" |
| 4016 | "for CID_ARRAY for ULP : %d\n", |
| 4017 | ulp_num); |
| 4018 | kfree(ptr_cid_info); |
| 4019 | ptr_cid_info = NULL; |
| 4020 | ret = -ENOMEM; |
| 4021 | |
| 4022 | goto free_memory; |
| 4023 | } |
| 4024 | ptr_cid_info->avlbl_cids = BEISCSI_GET_CID_COUNT( |
| 4025 | phba, ulp_num); |
| 4026 | |
| 4027 | /* Save the cid_info_array ptr */ |
| 4028 | phba->cid_array_info[ulp_num] = ptr_cid_info; |
| 4029 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4030 | } |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 4031 | phba->ep_array = kcalloc(phba->params.cxns_per_ctrl, |
| 4032 | sizeof(struct iscsi_endpoint *), |
| 4033 | GFP_KERNEL); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4034 | if (!phba->ep_array) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4035 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4036 | "BM_%d : Failed to allocate memory in " |
| 4037 | "hba_setup_cid_tbls\n"); |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4038 | ret = -ENOMEM; |
| 4039 | |
| 4040 | goto free_memory; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4041 | } |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4042 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 4043 | phba->conn_table = kcalloc(phba->params.cxns_per_ctrl, |
| 4044 | sizeof(struct beiscsi_conn *), |
| 4045 | GFP_KERNEL); |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4046 | if (!phba->conn_table) { |
| 4047 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4048 | "BM_%d : Failed to allocate memory in" |
| 4049 | "hba_setup_cid_tbls\n"); |
| 4050 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4051 | kfree(phba->ep_array); |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4052 | phba->ep_array = NULL; |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4053 | ret = -ENOMEM; |
Tomas Henzl | 5f2d25e | 2014-06-06 14:06:30 +0200 | [diff] [blame] | 4054 | |
| 4055 | goto free_memory; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4056 | } |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4057 | |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4058 | for (i = 0; i < phba->params.cxns_per_ctrl; i++) { |
| 4059 | ulp_num = phba->phwi_ctrlr->wrb_context[i].ulp_num; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4060 | |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4061 | ptr_cid_info = phba->cid_array_info[ulp_num]; |
| 4062 | ptr_cid_info->cid_array[ptr_cid_info->cid_alloc++] = |
| 4063 | phba->phwi_ctrlr->wrb_context[i].cid; |
| 4064 | |
| 4065 | } |
| 4066 | |
| 4067 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 4068 | if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) { |
| 4069 | ptr_cid_info = phba->cid_array_info[ulp_num]; |
| 4070 | |
| 4071 | ptr_cid_info->cid_alloc = 0; |
| 4072 | ptr_cid_info->cid_free = 0; |
| 4073 | } |
| 4074 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4075 | return 0; |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4076 | |
| 4077 | free_memory: |
| 4078 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 4079 | if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) { |
| 4080 | ptr_cid_info = phba->cid_array_info[ulp_num]; |
| 4081 | |
| 4082 | if (ptr_cid_info) { |
| 4083 | kfree(ptr_cid_info->cid_array); |
| 4084 | kfree(ptr_cid_info); |
| 4085 | phba->cid_array_info[ulp_num] = NULL; |
| 4086 | } |
| 4087 | } |
| 4088 | } |
| 4089 | |
| 4090 | return ret; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4091 | } |
| 4092 | |
Jayamohan Kallickal | 238f6b7 | 2010-07-22 04:23:22 +0530 | [diff] [blame] | 4093 | static void hwi_enable_intr(struct beiscsi_hba *phba) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4094 | { |
| 4095 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 4096 | struct hwi_controller *phwi_ctrlr; |
| 4097 | struct hwi_context_memory *phwi_context; |
| 4098 | struct be_queue_info *eq; |
| 4099 | u8 __iomem *addr; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4100 | u32 reg, i; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4101 | u32 enabled; |
| 4102 | |
| 4103 | phwi_ctrlr = phba->phwi_ctrlr; |
| 4104 | phwi_context = phwi_ctrlr->phwi_ctxt; |
| 4105 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4106 | addr = (u8 __iomem *) ((u8 __iomem *) ctrl->pcicfg + |
| 4107 | PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET); |
| 4108 | reg = ioread32(addr); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4109 | |
| 4110 | enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
| 4111 | if (!enabled) { |
| 4112 | reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4113 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 4114 | "BM_%d : reg =x%08x addr=%p\n", reg, addr); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4115 | iowrite32(reg, addr); |
Jayamohan Kallickal | 665d6d9 | 2011-04-29 14:30:06 -0500 | [diff] [blame] | 4116 | } |
| 4117 | |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 4118 | if (!phba->pcidev->msix_enabled) { |
Jayamohan Kallickal | 665d6d9 | 2011-04-29 14:30:06 -0500 | [diff] [blame] | 4119 | eq = &phwi_context->be_eq[0].q; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4120 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 4121 | "BM_%d : eq->id=%d\n", eq->id); |
| 4122 | |
Jayamohan Kallickal | 665d6d9 | 2011-04-29 14:30:06 -0500 | [diff] [blame] | 4123 | hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1); |
| 4124 | } else { |
| 4125 | for (i = 0; i <= phba->num_cpus; i++) { |
| 4126 | eq = &phwi_context->be_eq[i].q; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4127 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 4128 | "BM_%d : eq->id=%d\n", eq->id); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4129 | hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1); |
| 4130 | } |
Jayamohan Kallickal | c03af1a | 2010-02-20 08:05:43 +0530 | [diff] [blame] | 4131 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4132 | } |
| 4133 | |
| 4134 | static void hwi_disable_intr(struct beiscsi_hba *phba) |
| 4135 | { |
| 4136 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 4137 | |
| 4138 | u8 __iomem *addr = ctrl->pcicfg + PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET; |
| 4139 | u32 reg = ioread32(addr); |
| 4140 | |
| 4141 | u32 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
| 4142 | if (enabled) { |
| 4143 | reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
| 4144 | iowrite32(reg, addr); |
| 4145 | } else |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4146 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT, |
| 4147 | "BM_%d : In hwi_disable_intr, Already Disabled\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4148 | } |
| 4149 | |
| 4150 | static int beiscsi_init_port(struct beiscsi_hba *phba) |
| 4151 | { |
| 4152 | int ret; |
| 4153 | |
Jitendra Bhivare | dd94097 | 2016-12-13 15:56:04 +0530 | [diff] [blame] | 4154 | ret = hwi_init_controller(phba); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4155 | if (ret < 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4156 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
Jitendra Bhivare | dd94097 | 2016-12-13 15:56:04 +0530 | [diff] [blame] | 4157 | "BM_%d : init controller failed\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4158 | return ret; |
| 4159 | } |
| 4160 | ret = beiscsi_init_sgl_handle(phba); |
| 4161 | if (ret < 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4162 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
Jitendra Bhivare | dd94097 | 2016-12-13 15:56:04 +0530 | [diff] [blame] | 4163 | "BM_%d : init sgl handles failed\n"); |
| 4164 | goto cleanup_port; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4165 | } |
| 4166 | |
Christophe JAILLET | deeea8e | 2016-08-26 15:09:06 +0530 | [diff] [blame] | 4167 | ret = hba_setup_cid_tbls(phba); |
| 4168 | if (ret < 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4169 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
Jitendra Bhivare | dd94097 | 2016-12-13 15:56:04 +0530 | [diff] [blame] | 4170 | "BM_%d : setup CID table failed\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4171 | kfree(phba->io_sgl_hndl_base); |
| 4172 | kfree(phba->eh_sgl_hndl_base); |
Jitendra Bhivare | dd94097 | 2016-12-13 15:56:04 +0530 | [diff] [blame] | 4173 | goto cleanup_port; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4174 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4175 | return ret; |
| 4176 | |
Jitendra Bhivare | dd94097 | 2016-12-13 15:56:04 +0530 | [diff] [blame] | 4177 | cleanup_port: |
Jitendra Bhivare | 4d2ee1e | 2016-08-19 15:20:16 +0530 | [diff] [blame] | 4178 | hwi_cleanup_port(phba); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4179 | return ret; |
| 4180 | } |
| 4181 | |
Jitendra Bhivare | 4d2ee1e | 2016-08-19 15:20:16 +0530 | [diff] [blame] | 4182 | static void beiscsi_cleanup_port(struct beiscsi_hba *phba) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4183 | { |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4184 | struct ulp_cid_info *ptr_cid_info = NULL; |
Jitendra Bhivare | f79929d | 2016-08-19 15:20:17 +0530 | [diff] [blame] | 4185 | int ulp_num; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4186 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4187 | kfree(phba->io_sgl_hndl_base); |
| 4188 | kfree(phba->eh_sgl_hndl_base); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4189 | kfree(phba->ep_array); |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4190 | kfree(phba->conn_table); |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4191 | |
| 4192 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 4193 | if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) { |
| 4194 | ptr_cid_info = phba->cid_array_info[ulp_num]; |
| 4195 | |
| 4196 | if (ptr_cid_info) { |
| 4197 | kfree(ptr_cid_info->cid_array); |
| 4198 | kfree(ptr_cid_info); |
| 4199 | phba->cid_array_info[ulp_num] = NULL; |
| 4200 | } |
| 4201 | } |
| 4202 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4203 | } |
| 4204 | |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 4205 | /** |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4206 | * beiscsi_free_mgmt_task_handles()- Free driver CXN resources |
| 4207 | * @beiscsi_conn: ptr to the conn to be cleaned up |
Jayamohan Kallickal | 4a4a11b | 2013-04-05 20:38:31 -0700 | [diff] [blame] | 4208 | * @task: ptr to iscsi_task resource to be freed. |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4209 | * |
| 4210 | * Free driver mgmt resources binded to CXN. |
| 4211 | **/ |
| 4212 | void |
Jayamohan Kallickal | 4a4a11b | 2013-04-05 20:38:31 -0700 | [diff] [blame] | 4213 | beiscsi_free_mgmt_task_handles(struct beiscsi_conn *beiscsi_conn, |
| 4214 | struct iscsi_task *task) |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4215 | { |
| 4216 | struct beiscsi_io_task *io_task; |
| 4217 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 4218 | struct hwi_wrb_context *pwrb_context; |
| 4219 | struct hwi_controller *phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4220 | uint16_t cri_index = BE_GET_CRI_FROM_CID( |
| 4221 | beiscsi_conn->beiscsi_conn_cid); |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4222 | |
| 4223 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4224 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
| 4225 | |
Jayamohan Kallickal | 4a4a11b | 2013-04-05 20:38:31 -0700 | [diff] [blame] | 4226 | io_task = task->dd_data; |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4227 | |
| 4228 | if (io_task->pwrb_handle) { |
Jitendra Bhivare | e1f9d31 | 2016-08-19 15:20:22 +0530 | [diff] [blame] | 4229 | free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle); |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4230 | io_task->pwrb_handle = NULL; |
| 4231 | } |
| 4232 | |
| 4233 | if (io_task->psgl_handle) { |
Jitendra Bhivare | e1f9d31 | 2016-08-19 15:20:22 +0530 | [diff] [blame] | 4234 | free_mgmt_sgl_handle(phba, io_task->psgl_handle); |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4235 | io_task->psgl_handle = NULL; |
| 4236 | } |
| 4237 | |
John Soni Jose | eb1c469 | 2015-04-25 08:17:45 +0530 | [diff] [blame] | 4238 | if (io_task->mtask_addr) { |
Christoph Hellwig | 26a4c99 | 2018-10-10 18:22:24 +0200 | [diff] [blame] | 4239 | dma_unmap_single(&phba->pcidev->dev, |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4240 | io_task->mtask_addr, |
| 4241 | io_task->mtask_data_count, |
Christoph Hellwig | 26a4c99 | 2018-10-10 18:22:24 +0200 | [diff] [blame] | 4242 | DMA_TO_DEVICE); |
John Soni Jose | eb1c469 | 2015-04-25 08:17:45 +0530 | [diff] [blame] | 4243 | io_task->mtask_addr = 0; |
| 4244 | } |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4245 | } |
| 4246 | |
| 4247 | /** |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 4248 | * beiscsi_cleanup_task()- Free driver resources of the task |
| 4249 | * @task: ptr to the iscsi task |
| 4250 | * |
| 4251 | **/ |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4252 | static void beiscsi_cleanup_task(struct iscsi_task *task) |
| 4253 | { |
| 4254 | struct beiscsi_io_task *io_task = task->dd_data; |
| 4255 | struct iscsi_conn *conn = task->conn; |
| 4256 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; |
| 4257 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 4258 | struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess; |
| 4259 | struct hwi_wrb_context *pwrb_context; |
| 4260 | struct hwi_controller *phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4261 | uint16_t cri_index = BE_GET_CRI_FROM_CID( |
| 4262 | beiscsi_conn->beiscsi_conn_cid); |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4263 | |
| 4264 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4265 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4266 | |
| 4267 | if (io_task->cmd_bhs) { |
Romain Perier | af007b0 | 2017-07-06 10:13:03 +0200 | [diff] [blame] | 4268 | dma_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs, |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4269 | io_task->bhs_pa.u.a64.address); |
| 4270 | io_task->cmd_bhs = NULL; |
Jitendra Bhivare | e1f9d31 | 2016-08-19 15:20:22 +0530 | [diff] [blame] | 4271 | task->hdr = NULL; |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4272 | } |
| 4273 | |
| 4274 | if (task->sc) { |
| 4275 | if (io_task->pwrb_handle) { |
| 4276 | free_wrb_handle(phba, pwrb_context, |
| 4277 | io_task->pwrb_handle); |
| 4278 | io_task->pwrb_handle = NULL; |
| 4279 | } |
| 4280 | |
| 4281 | if (io_task->psgl_handle) { |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4282 | free_io_sgl_handle(phba, io_task->psgl_handle); |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4283 | io_task->psgl_handle = NULL; |
| 4284 | } |
Jayamohan Kallickal | da33497 | 2014-01-29 02:16:44 -0500 | [diff] [blame] | 4285 | |
| 4286 | if (io_task->scsi_cmnd) { |
Jitendra Bhivare | 9122e99 | 2016-08-19 15:20:11 +0530 | [diff] [blame] | 4287 | if (io_task->num_sg) |
| 4288 | scsi_dma_unmap(io_task->scsi_cmnd); |
Jayamohan Kallickal | da33497 | 2014-01-29 02:16:44 -0500 | [diff] [blame] | 4289 | io_task->scsi_cmnd = NULL; |
| 4290 | } |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4291 | } else { |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4292 | if (!beiscsi_conn->login_in_progress) |
Jayamohan Kallickal | 4a4a11b | 2013-04-05 20:38:31 -0700 | [diff] [blame] | 4293 | beiscsi_free_mgmt_task_handles(beiscsi_conn, task); |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4294 | } |
| 4295 | } |
| 4296 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4297 | void |
| 4298 | beiscsi_offload_connection(struct beiscsi_conn *beiscsi_conn, |
| 4299 | struct beiscsi_offload_params *params) |
| 4300 | { |
| 4301 | struct wrb_handle *pwrb_handle; |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4302 | struct hwi_wrb_context *pwrb_context = NULL; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4303 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4304 | struct iscsi_task *task = beiscsi_conn->task; |
| 4305 | struct iscsi_session *session = task->conn->session; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4306 | u32 doorbell = 0; |
| 4307 | |
| 4308 | /* |
| 4309 | * We can always use 0 here because it is reserved by libiscsi for |
| 4310 | * login/startup related tasks. |
| 4311 | */ |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4312 | beiscsi_conn->login_in_progress = 0; |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 4313 | spin_lock_bh(&session->back_lock); |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4314 | beiscsi_cleanup_task(task); |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 4315 | spin_unlock_bh(&session->back_lock); |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4316 | |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4317 | pwrb_handle = alloc_wrb_handle(phba, beiscsi_conn->beiscsi_conn_cid, |
| 4318 | &pwrb_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4319 | |
John Soni Jose | acb9693 | 2012-10-20 04:44:35 +0530 | [diff] [blame] | 4320 | /* Check for the adapter family */ |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 4321 | if (is_chip_be2_be3r(phba)) |
John Soni Jose | acb9693 | 2012-10-20 04:44:35 +0530 | [diff] [blame] | 4322 | beiscsi_offload_cxn_v0(params, pwrb_handle, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4323 | phba->init_mem, |
| 4324 | pwrb_context); |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 4325 | else |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4326 | beiscsi_offload_cxn_v2(params, pwrb_handle, |
| 4327 | pwrb_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4328 | |
John Soni Jose | acb9693 | 2012-10-20 04:44:35 +0530 | [diff] [blame] | 4329 | be_dws_le_to_cpu(pwrb_handle->pwrb, |
| 4330 | sizeof(struct iscsi_target_context_update_wrb)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4331 | |
| 4332 | doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK; |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 4333 | doorbell |= (pwrb_handle->wrb_index & DB_DEF_PDU_WRB_INDEX_MASK) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4334 | << DB_DEF_PDU_WRB_INDEX_SHIFT; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4335 | doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT; |
Jayamohan Kallickal | 1e4be6f | 2013-09-28 15:35:50 -0700 | [diff] [blame] | 4336 | iowrite32(doorbell, phba->db_va + |
| 4337 | beiscsi_conn->doorbell_offset); |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame] | 4338 | |
| 4339 | /* |
| 4340 | * There is no completion for CONTEXT_UPDATE. The completion of next |
| 4341 | * WRB posted guarantees FW's processing and DMA'ing of it. |
| 4342 | * Use beiscsi_put_wrb_handle to put it back in the pool which makes |
| 4343 | * sure zero'ing or reuse of the WRB only after wrbs_per_cxn. |
| 4344 | */ |
| 4345 | beiscsi_put_wrb_handle(pwrb_context, pwrb_handle, |
| 4346 | phba->params.wrbs_per_cxn); |
| 4347 | beiscsi_log(phba, KERN_INFO, |
| 4348 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
| 4349 | "BM_%d : put CONTEXT_UPDATE pwrb_handle=%p free_index=0x%x wrb_handles_available=%d\n", |
| 4350 | pwrb_handle, pwrb_context->free_index, |
| 4351 | pwrb_context->wrb_handles_available); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4352 | } |
| 4353 | |
| 4354 | static void beiscsi_parse_pdu(struct iscsi_conn *conn, itt_t itt, |
| 4355 | int *index, int *age) |
| 4356 | { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4357 | *index = (int)itt; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4358 | if (age) |
| 4359 | *age = conn->session->age; |
| 4360 | } |
| 4361 | |
| 4362 | /** |
| 4363 | * beiscsi_alloc_pdu - allocates pdu and related resources |
| 4364 | * @task: libiscsi task |
| 4365 | * @opcode: opcode of pdu for task |
| 4366 | * |
| 4367 | * This is called with the session lock held. It will allocate |
| 4368 | * the wrb and sgl if needed for the command. And it will prep |
| 4369 | * the pdu's itt. beiscsi_parse_pdu will later translate |
| 4370 | * the pdu itt to the libiscsi task itt. |
| 4371 | */ |
| 4372 | static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode) |
| 4373 | { |
| 4374 | struct beiscsi_io_task *io_task = task->dd_data; |
| 4375 | struct iscsi_conn *conn = task->conn; |
| 4376 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; |
| 4377 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 4378 | struct hwi_wrb_context *pwrb_context; |
| 4379 | struct hwi_controller *phwi_ctrlr; |
| 4380 | itt_t itt; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4381 | uint16_t cri_index = 0; |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4382 | struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess; |
| 4383 | dma_addr_t paddr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4384 | |
Romain Perier | af007b0 | 2017-07-06 10:13:03 +0200 | [diff] [blame] | 4385 | io_task->cmd_bhs = dma_pool_alloc(beiscsi_sess->bhs_pool, |
Mike Christie | bc7acce | 2010-12-31 02:22:19 -0600 | [diff] [blame] | 4386 | GFP_ATOMIC, &paddr); |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4387 | if (!io_task->cmd_bhs) |
| 4388 | return -ENOMEM; |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4389 | io_task->bhs_pa.u.a64.address = paddr; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4390 | io_task->libiscsi_itt = (itt_t)task->itt; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4391 | io_task->conn = beiscsi_conn; |
| 4392 | |
| 4393 | task->hdr = (struct iscsi_hdr *)&io_task->cmd_bhs->iscsi_hdr; |
| 4394 | task->hdr_max = sizeof(struct be_cmd_bhs); |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4395 | io_task->psgl_handle = NULL; |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 4396 | io_task->pwrb_handle = NULL; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4397 | |
| 4398 | if (task->sc) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4399 | io_task->psgl_handle = alloc_io_sgl_handle(phba); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4400 | if (!io_task->psgl_handle) { |
| 4401 | beiscsi_log(phba, KERN_ERR, |
| 4402 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
| 4403 | "BM_%d : Alloc of IO_SGL_ICD Failed" |
| 4404 | "for the CID : %d\n", |
| 4405 | beiscsi_conn->beiscsi_conn_cid); |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4406 | goto free_hndls; |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4407 | } |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4408 | io_task->pwrb_handle = alloc_wrb_handle(phba, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4409 | beiscsi_conn->beiscsi_conn_cid, |
| 4410 | &io_task->pwrb_context); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4411 | if (!io_task->pwrb_handle) { |
| 4412 | beiscsi_log(phba, KERN_ERR, |
| 4413 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
| 4414 | "BM_%d : Alloc of WRB_HANDLE Failed" |
| 4415 | "for the CID : %d\n", |
| 4416 | beiscsi_conn->beiscsi_conn_cid); |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4417 | goto free_io_hndls; |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4418 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4419 | } else { |
| 4420 | io_task->scsi_cmnd = NULL; |
Jayamohan Kallickal | d7aea67 | 2010-01-05 05:08:39 +0530 | [diff] [blame] | 4421 | if ((opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN) { |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4422 | beiscsi_conn->task = task; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4423 | if (!beiscsi_conn->login_in_progress) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4424 | io_task->psgl_handle = (struct sgl_handle *) |
| 4425 | alloc_mgmt_sgl_handle(phba); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4426 | if (!io_task->psgl_handle) { |
| 4427 | beiscsi_log(phba, KERN_ERR, |
| 4428 | BEISCSI_LOG_IO | |
| 4429 | BEISCSI_LOG_CONFIG, |
| 4430 | "BM_%d : Alloc of MGMT_SGL_ICD Failed" |
| 4431 | "for the CID : %d\n", |
| 4432 | beiscsi_conn-> |
| 4433 | beiscsi_conn_cid); |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4434 | goto free_hndls; |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4435 | } |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4436 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4437 | beiscsi_conn->login_in_progress = 1; |
| 4438 | beiscsi_conn->plogin_sgl_handle = |
| 4439 | io_task->psgl_handle; |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4440 | io_task->pwrb_handle = |
| 4441 | alloc_wrb_handle(phba, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4442 | beiscsi_conn->beiscsi_conn_cid, |
| 4443 | &io_task->pwrb_context); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4444 | if (!io_task->pwrb_handle) { |
| 4445 | beiscsi_log(phba, KERN_ERR, |
| 4446 | BEISCSI_LOG_IO | |
| 4447 | BEISCSI_LOG_CONFIG, |
| 4448 | "BM_%d : Alloc of WRB_HANDLE Failed" |
| 4449 | "for the CID : %d\n", |
| 4450 | beiscsi_conn-> |
| 4451 | beiscsi_conn_cid); |
| 4452 | goto free_mgmt_hndls; |
| 4453 | } |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4454 | beiscsi_conn->plogin_wrb_handle = |
| 4455 | io_task->pwrb_handle; |
| 4456 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4457 | } else { |
| 4458 | io_task->psgl_handle = |
| 4459 | beiscsi_conn->plogin_sgl_handle; |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4460 | io_task->pwrb_handle = |
| 4461 | beiscsi_conn->plogin_wrb_handle; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4462 | } |
| 4463 | } else { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4464 | io_task->psgl_handle = alloc_mgmt_sgl_handle(phba); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4465 | if (!io_task->psgl_handle) { |
| 4466 | beiscsi_log(phba, KERN_ERR, |
| 4467 | BEISCSI_LOG_IO | |
| 4468 | BEISCSI_LOG_CONFIG, |
| 4469 | "BM_%d : Alloc of MGMT_SGL_ICD Failed" |
| 4470 | "for the CID : %d\n", |
| 4471 | beiscsi_conn-> |
| 4472 | beiscsi_conn_cid); |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4473 | goto free_hndls; |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4474 | } |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4475 | io_task->pwrb_handle = |
| 4476 | alloc_wrb_handle(phba, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4477 | beiscsi_conn->beiscsi_conn_cid, |
| 4478 | &io_task->pwrb_context); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4479 | if (!io_task->pwrb_handle) { |
| 4480 | beiscsi_log(phba, KERN_ERR, |
| 4481 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
| 4482 | "BM_%d : Alloc of WRB_HANDLE Failed" |
| 4483 | "for the CID : %d\n", |
| 4484 | beiscsi_conn->beiscsi_conn_cid); |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4485 | goto free_mgmt_hndls; |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4486 | } |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4487 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4488 | } |
| 4489 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4490 | itt = (itt_t) cpu_to_be32(((unsigned int)io_task->pwrb_handle-> |
| 4491 | wrb_index << 16) | (unsigned int) |
| 4492 | (io_task->psgl_handle->sgl_index)); |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 4493 | io_task->pwrb_handle->pio_handle = task; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4494 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4495 | io_task->cmd_bhs->iscsi_hdr.itt = itt; |
| 4496 | return 0; |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4497 | |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4498 | free_io_hndls: |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4499 | free_io_sgl_handle(phba, io_task->psgl_handle); |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4500 | goto free_hndls; |
| 4501 | free_mgmt_hndls: |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4502 | free_mgmt_sgl_handle(phba, io_task->psgl_handle); |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4503 | io_task->psgl_handle = NULL; |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4504 | free_hndls: |
| 4505 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4506 | cri_index = BE_GET_CRI_FROM_CID( |
| 4507 | beiscsi_conn->beiscsi_conn_cid); |
| 4508 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4509 | if (io_task->pwrb_handle) |
| 4510 | free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle); |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4511 | io_task->pwrb_handle = NULL; |
Romain Perier | af007b0 | 2017-07-06 10:13:03 +0200 | [diff] [blame] | 4512 | dma_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs, |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4513 | io_task->bhs_pa.u.a64.address); |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4514 | io_task->cmd_bhs = NULL; |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4515 | return -ENOMEM; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4516 | } |
Baoyou Xie | 0825b8e | 2016-09-26 20:00:59 +0800 | [diff] [blame] | 4517 | 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] | 4518 | unsigned int num_sg, unsigned int xferlen, |
| 4519 | unsigned int writedir) |
| 4520 | { |
| 4521 | |
| 4522 | struct beiscsi_io_task *io_task = task->dd_data; |
| 4523 | struct iscsi_conn *conn = task->conn; |
| 4524 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; |
| 4525 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 4526 | struct iscsi_wrb *pwrb = NULL; |
| 4527 | unsigned int doorbell = 0; |
| 4528 | |
| 4529 | pwrb = io_task->pwrb_handle->pwrb; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4530 | |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4531 | io_task->bhs_len = sizeof(struct be_cmd_bhs); |
| 4532 | |
| 4533 | if (writedir) { |
| 4534 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb, |
| 4535 | INI_WR_CMD); |
| 4536 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 1); |
| 4537 | } else { |
| 4538 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb, |
| 4539 | INI_RD_CMD); |
| 4540 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 0); |
| 4541 | } |
| 4542 | |
| 4543 | io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb_v2, |
| 4544 | type, pwrb); |
| 4545 | |
| 4546 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, lun, pwrb, |
| 4547 | cpu_to_be16(*(unsigned short *) |
| 4548 | &io_task->cmd_bhs->iscsi_hdr.lun)); |
| 4549 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb, xferlen); |
| 4550 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb, |
| 4551 | io_task->pwrb_handle->wrb_index); |
| 4552 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb, |
| 4553 | be32_to_cpu(task->cmdsn)); |
| 4554 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb, |
| 4555 | io_task->psgl_handle->sgl_index); |
| 4556 | |
| 4557 | hwi_write_sgl_v2(pwrb, sg, num_sg, io_task); |
| 4558 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4559 | io_task->pwrb_handle->wrb_index); |
| 4560 | if (io_task->pwrb_context->plast_wrb) |
| 4561 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, |
| 4562 | io_task->pwrb_context->plast_wrb, |
| 4563 | io_task->pwrb_handle->wrb_index); |
| 4564 | io_task->pwrb_context->plast_wrb = pwrb; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4565 | |
| 4566 | be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb)); |
| 4567 | |
| 4568 | doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK; |
| 4569 | doorbell |= (io_task->pwrb_handle->wrb_index & |
| 4570 | DB_DEF_PDU_WRB_INDEX_MASK) << |
| 4571 | DB_DEF_PDU_WRB_INDEX_SHIFT; |
| 4572 | doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT; |
Jayamohan Kallickal | 1e4be6f | 2013-09-28 15:35:50 -0700 | [diff] [blame] | 4573 | iowrite32(doorbell, phba->db_va + |
| 4574 | beiscsi_conn->doorbell_offset); |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4575 | return 0; |
| 4576 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4577 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4578 | static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg, |
| 4579 | unsigned int num_sg, unsigned int xferlen, |
| 4580 | unsigned int writedir) |
| 4581 | { |
| 4582 | |
| 4583 | struct beiscsi_io_task *io_task = task->dd_data; |
| 4584 | struct iscsi_conn *conn = task->conn; |
| 4585 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; |
| 4586 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 4587 | struct iscsi_wrb *pwrb = NULL; |
| 4588 | unsigned int doorbell = 0; |
| 4589 | |
| 4590 | pwrb = io_task->pwrb_handle->pwrb; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4591 | io_task->bhs_len = sizeof(struct be_cmd_bhs); |
| 4592 | |
| 4593 | if (writedir) { |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 4594 | AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb, |
| 4595 | INI_WR_CMD); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4596 | AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4597 | } else { |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 4598 | AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb, |
| 4599 | INI_RD_CMD); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4600 | AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0); |
| 4601 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4602 | |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4603 | io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb, |
| 4604 | type, pwrb); |
| 4605 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4606 | AMAP_SET_BITS(struct amap_iscsi_wrb, lun, pwrb, |
Jayamohan Kallickal | dc63aac | 2012-04-03 23:41:36 -0500 | [diff] [blame] | 4607 | cpu_to_be16(*(unsigned short *) |
| 4608 | &io_task->cmd_bhs->iscsi_hdr.lun)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4609 | AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, xferlen); |
| 4610 | AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb, |
| 4611 | io_task->pwrb_handle->wrb_index); |
| 4612 | AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, |
| 4613 | be32_to_cpu(task->cmdsn)); |
| 4614 | AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb, |
| 4615 | io_task->psgl_handle->sgl_index); |
| 4616 | |
| 4617 | hwi_write_sgl(pwrb, sg, num_sg, io_task); |
| 4618 | |
| 4619 | AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4620 | io_task->pwrb_handle->wrb_index); |
| 4621 | if (io_task->pwrb_context->plast_wrb) |
| 4622 | AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, |
| 4623 | io_task->pwrb_context->plast_wrb, |
| 4624 | io_task->pwrb_handle->wrb_index); |
| 4625 | io_task->pwrb_context->plast_wrb = pwrb; |
| 4626 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4627 | be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb)); |
| 4628 | |
| 4629 | doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK; |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 4630 | doorbell |= (io_task->pwrb_handle->wrb_index & |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4631 | DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT; |
| 4632 | doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT; |
| 4633 | |
Jayamohan Kallickal | 1e4be6f | 2013-09-28 15:35:50 -0700 | [diff] [blame] | 4634 | iowrite32(doorbell, phba->db_va + |
| 4635 | beiscsi_conn->doorbell_offset); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4636 | return 0; |
| 4637 | } |
| 4638 | |
| 4639 | static int beiscsi_mtask(struct iscsi_task *task) |
| 4640 | { |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 4641 | struct beiscsi_io_task *io_task = task->dd_data; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4642 | struct iscsi_conn *conn = task->conn; |
| 4643 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; |
| 4644 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 4645 | struct iscsi_wrb *pwrb = NULL; |
| 4646 | unsigned int doorbell = 0; |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 4647 | unsigned int cid; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4648 | unsigned int pwrb_typeoffset = 0; |
Alexey Khoroshilov | e049362 | 2016-01-16 00:45:34 +0300 | [diff] [blame] | 4649 | int ret = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4650 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4651 | cid = beiscsi_conn->beiscsi_conn_cid; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4652 | pwrb = io_task->pwrb_handle->pwrb; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4653 | |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 4654 | if (is_chip_be2_be3r(phba)) { |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4655 | AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, |
| 4656 | be32_to_cpu(task->cmdsn)); |
| 4657 | AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb, |
| 4658 | io_task->pwrb_handle->wrb_index); |
| 4659 | AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb, |
| 4660 | io_task->psgl_handle->sgl_index); |
| 4661 | AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, |
| 4662 | task->data_count); |
| 4663 | AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4664 | io_task->pwrb_handle->wrb_index); |
| 4665 | if (io_task->pwrb_context->plast_wrb) |
| 4666 | AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, |
| 4667 | io_task->pwrb_context->plast_wrb, |
| 4668 | io_task->pwrb_handle->wrb_index); |
| 4669 | io_task->pwrb_context->plast_wrb = pwrb; |
| 4670 | |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4671 | pwrb_typeoffset = BE_WRB_TYPE_OFFSET; |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 4672 | } else { |
| 4673 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb, |
| 4674 | be32_to_cpu(task->cmdsn)); |
| 4675 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb, |
| 4676 | io_task->pwrb_handle->wrb_index); |
| 4677 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb, |
| 4678 | io_task->psgl_handle->sgl_index); |
| 4679 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb, |
| 4680 | task->data_count); |
| 4681 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4682 | io_task->pwrb_handle->wrb_index); |
| 4683 | if (io_task->pwrb_context->plast_wrb) |
| 4684 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, |
| 4685 | io_task->pwrb_context->plast_wrb, |
| 4686 | io_task->pwrb_handle->wrb_index); |
| 4687 | io_task->pwrb_context->plast_wrb = pwrb; |
| 4688 | |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 4689 | pwrb_typeoffset = SKH_WRB_TYPE_OFFSET; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4690 | } |
| 4691 | |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 4692 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4693 | switch (task->hdr->opcode & ISCSI_OPCODE_MASK) { |
| 4694 | case ISCSI_OP_LOGIN: |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4695 | AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, 1); |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4696 | ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset); |
Alexey Khoroshilov | e049362 | 2016-01-16 00:45:34 +0300 | [diff] [blame] | 4697 | ret = hwi_write_buffer(pwrb, task); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4698 | break; |
| 4699 | case ISCSI_OP_NOOP_OUT: |
Jayamohan Kallickal | 1390b01 | 2011-03-25 14:24:01 -0700 | [diff] [blame] | 4700 | if (task->hdr->ttt != ISCSI_RESERVED_TAG) { |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4701 | ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset); |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 4702 | if (is_chip_be2_be3r(phba)) |
| 4703 | AMAP_SET_BITS(struct amap_iscsi_wrb, |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4704 | dmsg, pwrb, 1); |
| 4705 | else |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 4706 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4707 | dmsg, pwrb, 1); |
Jayamohan Kallickal | 1390b01 | 2011-03-25 14:24:01 -0700 | [diff] [blame] | 4708 | } else { |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4709 | ADAPTER_SET_WRB_TYPE(pwrb, INI_RD_CMD, pwrb_typeoffset); |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 4710 | if (is_chip_be2_be3r(phba)) |
| 4711 | AMAP_SET_BITS(struct amap_iscsi_wrb, |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4712 | dmsg, pwrb, 0); |
| 4713 | else |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 4714 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4715 | dmsg, pwrb, 0); |
Jayamohan Kallickal | 1390b01 | 2011-03-25 14:24:01 -0700 | [diff] [blame] | 4716 | } |
Alexey Khoroshilov | e049362 | 2016-01-16 00:45:34 +0300 | [diff] [blame] | 4717 | ret = hwi_write_buffer(pwrb, task); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4718 | break; |
| 4719 | case ISCSI_OP_TEXT: |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4720 | ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset); |
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_SCSI_TMFUNC: |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4724 | ADAPTER_SET_WRB_TYPE(pwrb, INI_TMF_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_LOGOUT: |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4728 | ADAPTER_SET_WRB_TYPE(pwrb, HWH_TYPE_LOGOUT, 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 | |
| 4732 | default: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4733 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
| 4734 | "BM_%d : opcode =%d Not supported\n", |
| 4735 | task->hdr->opcode & ISCSI_OPCODE_MASK); |
| 4736 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4737 | return -EINVAL; |
| 4738 | } |
| 4739 | |
Alexey Khoroshilov | e049362 | 2016-01-16 00:45:34 +0300 | [diff] [blame] | 4740 | if (ret) |
| 4741 | return ret; |
| 4742 | |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4743 | /* Set the task type */ |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 4744 | io_task->wrb_type = (is_chip_be2_be3r(phba)) ? |
| 4745 | AMAP_GET_BITS(struct amap_iscsi_wrb, type, pwrb) : |
| 4746 | AMAP_GET_BITS(struct amap_iscsi_wrb_v2, type, pwrb); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4747 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4748 | doorbell |= cid & DB_WRB_POST_CID_MASK; |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 4749 | doorbell |= (io_task->pwrb_handle->wrb_index & |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4750 | DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT; |
| 4751 | doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT; |
Jayamohan Kallickal | 1e4be6f | 2013-09-28 15:35:50 -0700 | [diff] [blame] | 4752 | iowrite32(doorbell, phba->db_va + |
| 4753 | beiscsi_conn->doorbell_offset); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4754 | return 0; |
| 4755 | } |
| 4756 | |
| 4757 | static int beiscsi_task_xmit(struct iscsi_task *task) |
| 4758 | { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4759 | struct beiscsi_io_task *io_task = task->dd_data; |
| 4760 | struct scsi_cmnd *sc = task->sc; |
Jitendra Bhivare | 1868379 | 2016-02-04 15:49:18 +0530 | [diff] [blame] | 4761 | struct beiscsi_hba *phba; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4762 | struct scatterlist *sg; |
| 4763 | int num_sg; |
| 4764 | unsigned int writedir = 0, xferlen = 0; |
| 4765 | |
Jitendra Bhivare | 9122e99 | 2016-08-19 15:20:11 +0530 | [diff] [blame] | 4766 | phba = io_task->conn->phba; |
| 4767 | /** |
| 4768 | * HBA in error includes BEISCSI_HBA_FW_TIMEOUT. IO path might be |
| 4769 | * operational if FW still gets heartbeat from EP FW. Is management |
| 4770 | * path really needed to continue further? |
| 4771 | */ |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 4772 | if (!beiscsi_hba_is_online(phba)) |
Jitendra Bhivare | 9122e99 | 2016-08-19 15:20:11 +0530 | [diff] [blame] | 4773 | return -EIO; |
| 4774 | |
Jitendra Bhivare | 1868379 | 2016-02-04 15:49:18 +0530 | [diff] [blame] | 4775 | if (!io_task->conn->login_in_progress) |
| 4776 | task->hdr->exp_statsn = 0; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4777 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4778 | if (!sc) |
| 4779 | return beiscsi_mtask(task); |
| 4780 | |
| 4781 | io_task->scsi_cmnd = sc; |
Jitendra Bhivare | 9122e99 | 2016-08-19 15:20:11 +0530 | [diff] [blame] | 4782 | io_task->num_sg = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4783 | num_sg = scsi_dma_map(sc); |
| 4784 | if (num_sg < 0) { |
Jayamohan Kallickal | afb9605 | 2013-09-28 15:35:55 -0700 | [diff] [blame] | 4785 | beiscsi_log(phba, KERN_ERR, |
| 4786 | BEISCSI_LOG_IO | BEISCSI_LOG_ISCSI, |
| 4787 | "BM_%d : scsi_dma_map Failed " |
| 4788 | "Driver_ITT : 0x%x ITT : 0x%x Xferlen : 0x%x\n", |
| 4789 | be32_to_cpu(io_task->cmd_bhs->iscsi_hdr.itt), |
| 4790 | io_task->libiscsi_itt, scsi_bufflen(sc)); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4791 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4792 | return num_sg; |
| 4793 | } |
Jitendra Bhivare | 9122e99 | 2016-08-19 15:20:11 +0530 | [diff] [blame] | 4794 | /** |
| 4795 | * For scsi cmd task, check num_sg before unmapping in cleanup_task. |
| 4796 | * For management task, cleanup_task checks mtask_addr before unmapping. |
| 4797 | */ |
| 4798 | io_task->num_sg = num_sg; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4799 | xferlen = scsi_bufflen(sc); |
| 4800 | sg = scsi_sglist(sc); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4801 | if (sc->sc_data_direction == DMA_TO_DEVICE) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4802 | writedir = 1; |
Jitendra Bhivare | 45efc940 | 2017-10-10 16:18:18 +0530 | [diff] [blame] | 4803 | else |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4804 | writedir = 0; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4805 | |
Jitendra Bhivare | 45efc940 | 2017-10-10 16:18:18 +0530 | [diff] [blame] | 4806 | return phba->iotask_fn(task, sg, num_sg, xferlen, writedir); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4807 | } |
| 4808 | |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 4809 | /** |
| 4810 | * beiscsi_bsg_request - handle bsg request from ISCSI transport |
| 4811 | * @job: job to handle |
| 4812 | */ |
| 4813 | static int beiscsi_bsg_request(struct bsg_job *job) |
| 4814 | { |
| 4815 | struct Scsi_Host *shost; |
| 4816 | struct beiscsi_hba *phba; |
| 4817 | struct iscsi_bsg_request *bsg_req = job->request; |
| 4818 | int rc = -EINVAL; |
| 4819 | unsigned int tag; |
| 4820 | struct be_dma_mem nonemb_cmd; |
| 4821 | struct be_cmd_resp_hdr *resp; |
| 4822 | struct iscsi_bsg_reply *bsg_reply = job->reply; |
| 4823 | unsigned short status, extd_status; |
| 4824 | |
| 4825 | shost = iscsi_job_to_shost(job); |
| 4826 | phba = iscsi_host_priv(shost); |
| 4827 | |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 4828 | if (!beiscsi_hba_is_online(phba)) { |
Jitendra Bhivare | 9122e99 | 2016-08-19 15:20:11 +0530 | [diff] [blame] | 4829 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG, |
| 4830 | "BM_%d : HBA in error 0x%lx\n", phba->state); |
| 4831 | return -ENXIO; |
| 4832 | } |
| 4833 | |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 4834 | switch (bsg_req->msgcode) { |
| 4835 | case ISCSI_BSG_HST_VENDOR: |
Christoph Hellwig | 26a4c99 | 2018-10-10 18:22:24 +0200 | [diff] [blame] | 4836 | nonemb_cmd.va = dma_alloc_coherent(&phba->ctrl.pdev->dev, |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 4837 | job->request_payload.payload_len, |
Christoph Hellwig | 26a4c99 | 2018-10-10 18:22:24 +0200 | [diff] [blame] | 4838 | &nonemb_cmd.dma, GFP_KERNEL); |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 4839 | if (nonemb_cmd.va == NULL) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4840 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
| 4841 | "BM_%d : Failed to allocate memory for " |
| 4842 | "beiscsi_bsg_request\n"); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4843 | return -ENOMEM; |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 4844 | } |
| 4845 | tag = mgmt_vendor_specific_fw_cmd(&phba->ctrl, phba, job, |
| 4846 | &nonemb_cmd); |
| 4847 | if (!tag) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4848 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4849 | "BM_%d : MBX Tag Allocation Failed\n"); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4850 | |
Christoph Hellwig | 26a4c99 | 2018-10-10 18:22:24 +0200 | [diff] [blame] | 4851 | dma_free_coherent(&phba->ctrl.pdev->dev, nonemb_cmd.size, |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 4852 | nonemb_cmd.va, nonemb_cmd.dma); |
| 4853 | return -EAGAIN; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 4854 | } |
| 4855 | |
| 4856 | rc = wait_event_interruptible_timeout( |
| 4857 | phba->ctrl.mcc_wait[tag], |
Jitendra Bhivare | 67296ad | 2016-02-04 15:49:10 +0530 | [diff] [blame] | 4858 | phba->ctrl.mcc_tag_status[tag], |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 4859 | msecs_to_jiffies( |
| 4860 | BEISCSI_HOST_MBX_TIMEOUT)); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 4861 | |
| 4862 | if (!test_bit(BEISCSI_HBA_ONLINE, &phba->state)) { |
| 4863 | clear_bit(MCC_TAG_STATE_RUNNING, |
| 4864 | &phba->ctrl.ptag_state[tag].tag_state); |
Christoph Hellwig | 26a4c99 | 2018-10-10 18:22:24 +0200 | [diff] [blame] | 4865 | dma_free_coherent(&phba->ctrl.pdev->dev, nonemb_cmd.size, |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 4866 | nonemb_cmd.va, nonemb_cmd.dma); |
| 4867 | return -EIO; |
| 4868 | } |
Jitendra Bhivare | 67296ad | 2016-02-04 15:49:10 +0530 | [diff] [blame] | 4869 | extd_status = (phba->ctrl.mcc_tag_status[tag] & |
| 4870 | CQE_STATUS_ADDL_MASK) >> CQE_STATUS_ADDL_SHIFT; |
| 4871 | status = phba->ctrl.mcc_tag_status[tag] & CQE_STATUS_MASK; |
Jitendra Bhivare | 090e218 | 2016-02-04 15:49:17 +0530 | [diff] [blame] | 4872 | free_mcc_wrb(&phba->ctrl, tag); |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 4873 | resp = (struct be_cmd_resp_hdr *)nonemb_cmd.va; |
| 4874 | sg_copy_from_buffer(job->reply_payload.sg_list, |
| 4875 | job->reply_payload.sg_cnt, |
| 4876 | nonemb_cmd.va, (resp->response_length |
| 4877 | + sizeof(*resp))); |
| 4878 | bsg_reply->reply_payload_rcv_len = resp->response_length; |
| 4879 | bsg_reply->result = status; |
| 4880 | bsg_job_done(job, bsg_reply->result, |
| 4881 | bsg_reply->reply_payload_rcv_len); |
Christoph Hellwig | 26a4c99 | 2018-10-10 18:22:24 +0200 | [diff] [blame] | 4882 | dma_free_coherent(&phba->ctrl.pdev->dev, nonemb_cmd.size, |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 4883 | nonemb_cmd.va, nonemb_cmd.dma); |
| 4884 | if (status || extd_status) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4885 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4886 | "BM_%d : MBX Cmd Failed" |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4887 | " status = %d extd_status = %d\n", |
| 4888 | status, extd_status); |
| 4889 | |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 4890 | return -EIO; |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4891 | } else { |
| 4892 | rc = 0; |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 4893 | } |
| 4894 | break; |
| 4895 | |
| 4896 | default: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4897 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
| 4898 | "BM_%d : Unsupported bsg command: 0x%x\n", |
| 4899 | bsg_req->msgcode); |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 4900 | break; |
| 4901 | } |
| 4902 | |
| 4903 | return rc; |
| 4904 | } |
| 4905 | |
Baoyou Xie | 0825b8e | 2016-09-26 20:00:59 +0800 | [diff] [blame] | 4906 | static void beiscsi_hba_attrs_init(struct beiscsi_hba *phba) |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4907 | { |
| 4908 | /* Set the logging parameter */ |
| 4909 | beiscsi_log_enable_init(phba, beiscsi_log_enable); |
| 4910 | } |
| 4911 | |
Jitendra Bhivare | 50a4b82 | 2016-08-19 15:20:12 +0530 | [diff] [blame] | 4912 | void beiscsi_start_boot_work(struct beiscsi_hba *phba, unsigned int s_handle) |
| 4913 | { |
| 4914 | if (phba->boot_struct.boot_kset) |
| 4915 | return; |
| 4916 | |
| 4917 | /* skip if boot work is already in progress */ |
| 4918 | if (test_and_set_bit(BEISCSI_HBA_BOOT_WORK, &phba->state)) |
| 4919 | return; |
| 4920 | |
| 4921 | phba->boot_struct.retry = 3; |
| 4922 | phba->boot_struct.tag = 0; |
| 4923 | phba->boot_struct.s_handle = s_handle; |
| 4924 | phba->boot_struct.action = BEISCSI_BOOT_GET_SHANDLE; |
| 4925 | schedule_work(&phba->boot_work); |
| 4926 | } |
| 4927 | |
Jitendra Bhivare | 8d9ecd4 | 2017-10-10 16:18:11 +0530 | [diff] [blame] | 4928 | /** |
| 4929 | * Boot flag info for iscsi-utilities |
| 4930 | * Bit 0 Block valid flag |
| 4931 | * Bit 1 Firmware booting selected |
| 4932 | */ |
| 4933 | #define BEISCSI_SYSFS_ISCSI_BOOT_FLAGS 3 |
| 4934 | |
Jitendra Bhivare | 50a4b82 | 2016-08-19 15:20:12 +0530 | [diff] [blame] | 4935 | static ssize_t beiscsi_show_boot_tgt_info(void *data, int type, char *buf) |
| 4936 | { |
| 4937 | struct beiscsi_hba *phba = data; |
| 4938 | struct mgmt_session_info *boot_sess = &phba->boot_struct.boot_sess; |
| 4939 | struct mgmt_conn_info *boot_conn = &boot_sess->conn_list[0]; |
| 4940 | char *str = buf; |
| 4941 | int rc = -EPERM; |
| 4942 | |
| 4943 | switch (type) { |
| 4944 | case ISCSI_BOOT_TGT_NAME: |
| 4945 | rc = sprintf(buf, "%.*s\n", |
| 4946 | (int)strlen(boot_sess->target_name), |
| 4947 | (char *)&boot_sess->target_name); |
| 4948 | break; |
| 4949 | case ISCSI_BOOT_TGT_IP_ADDR: |
| 4950 | if (boot_conn->dest_ipaddr.ip_type == BEISCSI_IP_TYPE_V4) |
| 4951 | rc = sprintf(buf, "%pI4\n", |
| 4952 | (char *)&boot_conn->dest_ipaddr.addr); |
| 4953 | else |
| 4954 | rc = sprintf(str, "%pI6\n", |
| 4955 | (char *)&boot_conn->dest_ipaddr.addr); |
| 4956 | break; |
| 4957 | case ISCSI_BOOT_TGT_PORT: |
| 4958 | rc = sprintf(str, "%d\n", boot_conn->dest_port); |
| 4959 | break; |
| 4960 | |
| 4961 | case ISCSI_BOOT_TGT_CHAP_NAME: |
| 4962 | rc = sprintf(str, "%.*s\n", |
| 4963 | boot_conn->negotiated_login_options.auth_data.chap. |
| 4964 | target_chap_name_length, |
| 4965 | (char *)&boot_conn->negotiated_login_options. |
| 4966 | auth_data.chap.target_chap_name); |
| 4967 | break; |
| 4968 | case ISCSI_BOOT_TGT_CHAP_SECRET: |
| 4969 | rc = sprintf(str, "%.*s\n", |
| 4970 | boot_conn->negotiated_login_options.auth_data.chap. |
| 4971 | target_secret_length, |
| 4972 | (char *)&boot_conn->negotiated_login_options. |
| 4973 | auth_data.chap.target_secret); |
| 4974 | break; |
| 4975 | case ISCSI_BOOT_TGT_REV_CHAP_NAME: |
| 4976 | rc = sprintf(str, "%.*s\n", |
| 4977 | boot_conn->negotiated_login_options.auth_data.chap. |
| 4978 | intr_chap_name_length, |
| 4979 | (char *)&boot_conn->negotiated_login_options. |
| 4980 | auth_data.chap.intr_chap_name); |
| 4981 | break; |
| 4982 | case ISCSI_BOOT_TGT_REV_CHAP_SECRET: |
| 4983 | rc = sprintf(str, "%.*s\n", |
| 4984 | boot_conn->negotiated_login_options.auth_data.chap. |
| 4985 | intr_secret_length, |
| 4986 | (char *)&boot_conn->negotiated_login_options. |
| 4987 | auth_data.chap.intr_secret); |
| 4988 | break; |
| 4989 | case ISCSI_BOOT_TGT_FLAGS: |
Jitendra Bhivare | 8d9ecd4 | 2017-10-10 16:18:11 +0530 | [diff] [blame] | 4990 | rc = sprintf(str, "%d\n", BEISCSI_SYSFS_ISCSI_BOOT_FLAGS); |
Jitendra Bhivare | 50a4b82 | 2016-08-19 15:20:12 +0530 | [diff] [blame] | 4991 | break; |
| 4992 | case ISCSI_BOOT_TGT_NIC_ASSOC: |
| 4993 | rc = sprintf(str, "0\n"); |
| 4994 | break; |
| 4995 | } |
| 4996 | return rc; |
| 4997 | } |
| 4998 | |
| 4999 | static ssize_t beiscsi_show_boot_ini_info(void *data, int type, char *buf) |
| 5000 | { |
| 5001 | struct beiscsi_hba *phba = data; |
| 5002 | char *str = buf; |
| 5003 | int rc = -EPERM; |
| 5004 | |
| 5005 | switch (type) { |
| 5006 | case ISCSI_BOOT_INI_INITIATOR_NAME: |
| 5007 | rc = sprintf(str, "%s\n", |
| 5008 | phba->boot_struct.boot_sess.initiator_iscsiname); |
| 5009 | break; |
| 5010 | } |
| 5011 | return rc; |
| 5012 | } |
| 5013 | |
| 5014 | static ssize_t beiscsi_show_boot_eth_info(void *data, int type, char *buf) |
| 5015 | { |
| 5016 | struct beiscsi_hba *phba = data; |
| 5017 | char *str = buf; |
| 5018 | int rc = -EPERM; |
| 5019 | |
| 5020 | switch (type) { |
| 5021 | case ISCSI_BOOT_ETH_FLAGS: |
Jitendra Bhivare | 8d9ecd4 | 2017-10-10 16:18:11 +0530 | [diff] [blame] | 5022 | rc = sprintf(str, "%d\n", BEISCSI_SYSFS_ISCSI_BOOT_FLAGS); |
Jitendra Bhivare | 50a4b82 | 2016-08-19 15:20:12 +0530 | [diff] [blame] | 5023 | break; |
| 5024 | case ISCSI_BOOT_ETH_INDEX: |
| 5025 | rc = sprintf(str, "0\n"); |
| 5026 | break; |
| 5027 | case ISCSI_BOOT_ETH_MAC: |
| 5028 | rc = beiscsi_get_macaddr(str, phba); |
| 5029 | break; |
| 5030 | } |
| 5031 | return rc; |
| 5032 | } |
| 5033 | |
Jitendra Bhivare | 50a4b82 | 2016-08-19 15:20:12 +0530 | [diff] [blame] | 5034 | static umode_t beiscsi_tgt_get_attr_visibility(void *data, int type) |
| 5035 | { |
| 5036 | umode_t rc = 0; |
| 5037 | |
| 5038 | switch (type) { |
| 5039 | case ISCSI_BOOT_TGT_NAME: |
| 5040 | case ISCSI_BOOT_TGT_IP_ADDR: |
| 5041 | case ISCSI_BOOT_TGT_PORT: |
| 5042 | case ISCSI_BOOT_TGT_CHAP_NAME: |
| 5043 | case ISCSI_BOOT_TGT_CHAP_SECRET: |
| 5044 | case ISCSI_BOOT_TGT_REV_CHAP_NAME: |
| 5045 | case ISCSI_BOOT_TGT_REV_CHAP_SECRET: |
| 5046 | case ISCSI_BOOT_TGT_NIC_ASSOC: |
| 5047 | case ISCSI_BOOT_TGT_FLAGS: |
| 5048 | rc = S_IRUGO; |
| 5049 | break; |
| 5050 | } |
| 5051 | return rc; |
| 5052 | } |
| 5053 | |
| 5054 | static umode_t beiscsi_ini_get_attr_visibility(void *data, int type) |
| 5055 | { |
| 5056 | umode_t rc = 0; |
| 5057 | |
| 5058 | switch (type) { |
| 5059 | case ISCSI_BOOT_INI_INITIATOR_NAME: |
| 5060 | rc = S_IRUGO; |
| 5061 | break; |
| 5062 | } |
| 5063 | return rc; |
| 5064 | } |
| 5065 | |
Jitendra Bhivare | 50a4b82 | 2016-08-19 15:20:12 +0530 | [diff] [blame] | 5066 | static umode_t beiscsi_eth_get_attr_visibility(void *data, int type) |
| 5067 | { |
| 5068 | umode_t rc = 0; |
| 5069 | |
| 5070 | switch (type) { |
| 5071 | case ISCSI_BOOT_ETH_FLAGS: |
| 5072 | case ISCSI_BOOT_ETH_MAC: |
| 5073 | case ISCSI_BOOT_ETH_INDEX: |
| 5074 | rc = S_IRUGO; |
| 5075 | break; |
| 5076 | } |
| 5077 | return rc; |
| 5078 | } |
| 5079 | |
| 5080 | static void beiscsi_boot_kobj_release(void *data) |
| 5081 | { |
| 5082 | struct beiscsi_hba *phba = data; |
| 5083 | |
| 5084 | scsi_host_put(phba->shost); |
| 5085 | } |
| 5086 | |
| 5087 | static int beiscsi_boot_create_kset(struct beiscsi_hba *phba) |
| 5088 | { |
| 5089 | struct boot_struct *bs = &phba->boot_struct; |
| 5090 | struct iscsi_boot_kobj *boot_kobj; |
| 5091 | |
| 5092 | if (bs->boot_kset) { |
| 5093 | __beiscsi_log(phba, KERN_ERR, |
| 5094 | "BM_%d: boot_kset already created\n"); |
| 5095 | return 0; |
| 5096 | } |
| 5097 | |
| 5098 | bs->boot_kset = iscsi_boot_create_host_kset(phba->shost->host_no); |
| 5099 | if (!bs->boot_kset) { |
| 5100 | __beiscsi_log(phba, KERN_ERR, |
| 5101 | "BM_%d: boot_kset alloc failed\n"); |
| 5102 | return -ENOMEM; |
| 5103 | } |
| 5104 | |
| 5105 | /* get shost ref because the show function will refer phba */ |
| 5106 | if (!scsi_host_get(phba->shost)) |
| 5107 | goto free_kset; |
| 5108 | |
| 5109 | boot_kobj = iscsi_boot_create_target(bs->boot_kset, 0, phba, |
| 5110 | beiscsi_show_boot_tgt_info, |
| 5111 | beiscsi_tgt_get_attr_visibility, |
| 5112 | beiscsi_boot_kobj_release); |
| 5113 | if (!boot_kobj) |
| 5114 | goto put_shost; |
| 5115 | |
| 5116 | if (!scsi_host_get(phba->shost)) |
| 5117 | goto free_kset; |
| 5118 | |
| 5119 | boot_kobj = iscsi_boot_create_initiator(bs->boot_kset, 0, phba, |
| 5120 | beiscsi_show_boot_ini_info, |
| 5121 | beiscsi_ini_get_attr_visibility, |
| 5122 | beiscsi_boot_kobj_release); |
| 5123 | if (!boot_kobj) |
| 5124 | goto put_shost; |
| 5125 | |
| 5126 | if (!scsi_host_get(phba->shost)) |
| 5127 | goto free_kset; |
| 5128 | |
| 5129 | boot_kobj = iscsi_boot_create_ethernet(bs->boot_kset, 0, phba, |
| 5130 | beiscsi_show_boot_eth_info, |
| 5131 | beiscsi_eth_get_attr_visibility, |
| 5132 | beiscsi_boot_kobj_release); |
| 5133 | if (!boot_kobj) |
| 5134 | goto put_shost; |
| 5135 | |
| 5136 | return 0; |
| 5137 | |
| 5138 | put_shost: |
| 5139 | scsi_host_put(phba->shost); |
| 5140 | free_kset: |
| 5141 | iscsi_boot_destroy_kset(bs->boot_kset); |
| 5142 | bs->boot_kset = NULL; |
| 5143 | return -ENOMEM; |
| 5144 | } |
| 5145 | |
| 5146 | static void beiscsi_boot_work(struct work_struct *work) |
| 5147 | { |
| 5148 | struct beiscsi_hba *phba = |
| 5149 | container_of(work, struct beiscsi_hba, boot_work); |
| 5150 | struct boot_struct *bs = &phba->boot_struct; |
| 5151 | unsigned int tag = 0; |
| 5152 | |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5153 | if (!beiscsi_hba_is_online(phba)) |
Jitendra Bhivare | 50a4b82 | 2016-08-19 15:20:12 +0530 | [diff] [blame] | 5154 | return; |
| 5155 | |
| 5156 | beiscsi_log(phba, KERN_INFO, |
| 5157 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX, |
| 5158 | "BM_%d : %s action %d\n", |
| 5159 | __func__, phba->boot_struct.action); |
| 5160 | |
| 5161 | switch (phba->boot_struct.action) { |
| 5162 | case BEISCSI_BOOT_REOPEN_SESS: |
| 5163 | tag = beiscsi_boot_reopen_sess(phba); |
| 5164 | break; |
| 5165 | case BEISCSI_BOOT_GET_SHANDLE: |
| 5166 | tag = __beiscsi_boot_get_shandle(phba, 1); |
| 5167 | break; |
| 5168 | case BEISCSI_BOOT_GET_SINFO: |
| 5169 | tag = beiscsi_boot_get_sinfo(phba); |
| 5170 | break; |
| 5171 | case BEISCSI_BOOT_LOGOUT_SESS: |
| 5172 | tag = beiscsi_boot_logout_sess(phba); |
| 5173 | break; |
| 5174 | case BEISCSI_BOOT_CREATE_KSET: |
| 5175 | beiscsi_boot_create_kset(phba); |
| 5176 | /** |
| 5177 | * updated boot_kset is made visible to all before |
| 5178 | * ending the boot work. |
| 5179 | */ |
| 5180 | mb(); |
| 5181 | clear_bit(BEISCSI_HBA_BOOT_WORK, &phba->state); |
| 5182 | return; |
| 5183 | } |
| 5184 | if (!tag) { |
| 5185 | if (bs->retry--) |
| 5186 | schedule_work(&phba->boot_work); |
| 5187 | else |
| 5188 | clear_bit(BEISCSI_HBA_BOOT_WORK, &phba->state); |
| 5189 | } |
| 5190 | } |
| 5191 | |
Jitendra Bhivare | 10bcd47 | 2016-08-19 15:20:13 +0530 | [diff] [blame] | 5192 | static void beiscsi_eqd_update_work(struct work_struct *work) |
| 5193 | { |
| 5194 | struct hwi_context_memory *phwi_context; |
| 5195 | struct be_set_eqd set_eqd[MAX_CPUS]; |
| 5196 | struct hwi_controller *phwi_ctrlr; |
| 5197 | struct be_eq_obj *pbe_eq; |
| 5198 | struct beiscsi_hba *phba; |
| 5199 | unsigned int pps, delta; |
| 5200 | struct be_aic_obj *aic; |
| 5201 | int eqd, i, num = 0; |
| 5202 | unsigned long now; |
| 5203 | |
| 5204 | phba = container_of(work, struct beiscsi_hba, eqd_update.work); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5205 | if (!beiscsi_hba_is_online(phba)) |
Jitendra Bhivare | 9122e99 | 2016-08-19 15:20:11 +0530 | [diff] [blame] | 5206 | return; |
| 5207 | |
Jayamohan Kallickal | 73af08e | 2014-05-05 21:41:26 -0400 | [diff] [blame] | 5208 | phwi_ctrlr = phba->phwi_ctrlr; |
| 5209 | phwi_context = phwi_ctrlr->phwi_ctxt; |
| 5210 | |
| 5211 | for (i = 0; i <= phba->num_cpus; i++) { |
| 5212 | aic = &phba->aic_obj[i]; |
| 5213 | pbe_eq = &phwi_context->be_eq[i]; |
| 5214 | now = jiffies; |
Jitendra Bhivare | 10bcd47 | 2016-08-19 15:20:13 +0530 | [diff] [blame] | 5215 | if (!aic->jiffies || time_before(now, aic->jiffies) || |
Jayamohan Kallickal | 73af08e | 2014-05-05 21:41:26 -0400 | [diff] [blame] | 5216 | pbe_eq->cq_count < aic->eq_prev) { |
Jitendra Bhivare | 10bcd47 | 2016-08-19 15:20:13 +0530 | [diff] [blame] | 5217 | aic->jiffies = now; |
Jayamohan Kallickal | 73af08e | 2014-05-05 21:41:26 -0400 | [diff] [blame] | 5218 | aic->eq_prev = pbe_eq->cq_count; |
| 5219 | continue; |
| 5220 | } |
Jitendra Bhivare | 10bcd47 | 2016-08-19 15:20:13 +0530 | [diff] [blame] | 5221 | delta = jiffies_to_msecs(now - aic->jiffies); |
Jayamohan Kallickal | 73af08e | 2014-05-05 21:41:26 -0400 | [diff] [blame] | 5222 | pps = (((u32)(pbe_eq->cq_count - aic->eq_prev) * 1000) / delta); |
| 5223 | eqd = (pps / 1500) << 2; |
| 5224 | |
| 5225 | if (eqd < 8) |
| 5226 | eqd = 0; |
Jitendra Bhivare | 45efc940 | 2017-10-10 16:18:18 +0530 | [diff] [blame] | 5227 | eqd = min_t(u32, eqd, BEISCSI_EQ_DELAY_MAX); |
| 5228 | eqd = max_t(u32, eqd, BEISCSI_EQ_DELAY_MIN); |
Jayamohan Kallickal | 73af08e | 2014-05-05 21:41:26 -0400 | [diff] [blame] | 5229 | |
Jitendra Bhivare | 10bcd47 | 2016-08-19 15:20:13 +0530 | [diff] [blame] | 5230 | aic->jiffies = now; |
Jayamohan Kallickal | 73af08e | 2014-05-05 21:41:26 -0400 | [diff] [blame] | 5231 | aic->eq_prev = pbe_eq->cq_count; |
| 5232 | |
| 5233 | if (eqd != aic->prev_eqd) { |
| 5234 | set_eqd[num].delay_multiplier = (eqd * 65)/100; |
| 5235 | set_eqd[num].eq_id = pbe_eq->q.id; |
| 5236 | aic->prev_eqd = eqd; |
| 5237 | num++; |
| 5238 | } |
| 5239 | } |
Jitendra Bhivare | 10bcd47 | 2016-08-19 15:20:13 +0530 | [diff] [blame] | 5240 | if (num) |
| 5241 | /* completion of this is ignored */ |
| 5242 | beiscsi_modify_eq_delay(phba, set_eqd, num); |
Jayamohan Kallickal | 73af08e | 2014-05-05 21:41:26 -0400 | [diff] [blame] | 5243 | |
Jitendra Bhivare | 10bcd47 | 2016-08-19 15:20:13 +0530 | [diff] [blame] | 5244 | schedule_delayed_work(&phba->eqd_update, |
| 5245 | msecs_to_jiffies(BEISCSI_EQD_UPDATE_INTERVAL)); |
John Soni Jose | 7a15800 | 2012-10-20 04:45:51 +0530 | [diff] [blame] | 5246 | } |
| 5247 | |
Kees Cook | b386eec | 2017-10-11 16:15:26 -0700 | [diff] [blame] | 5248 | static void beiscsi_hw_tpe_check(struct timer_list *t) |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5249 | { |
Kees Cook | b386eec | 2017-10-11 16:15:26 -0700 | [diff] [blame] | 5250 | struct beiscsi_hba *phba = from_timer(phba, t, hw_check); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5251 | u32 wait; |
| 5252 | |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5253 | /* if not TPE, do nothing */ |
| 5254 | if (!beiscsi_detect_tpe(phba)) |
| 5255 | return; |
| 5256 | |
| 5257 | /* wait default 4000ms before recovering */ |
| 5258 | wait = 4000; |
| 5259 | if (phba->ue2rp > BEISCSI_UE_DETECT_INTERVAL) |
| 5260 | wait = phba->ue2rp - BEISCSI_UE_DETECT_INTERVAL; |
| 5261 | queue_delayed_work(phba->wq, &phba->recover_port, |
| 5262 | msecs_to_jiffies(wait)); |
| 5263 | } |
| 5264 | |
Kees Cook | b386eec | 2017-10-11 16:15:26 -0700 | [diff] [blame] | 5265 | static void beiscsi_hw_health_check(struct timer_list *t) |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5266 | { |
Kees Cook | b386eec | 2017-10-11 16:15:26 -0700 | [diff] [blame] | 5267 | struct beiscsi_hba *phba = from_timer(phba, t, hw_check); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5268 | |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5269 | beiscsi_detect_ue(phba); |
| 5270 | if (beiscsi_detect_ue(phba)) { |
| 5271 | __beiscsi_log(phba, KERN_ERR, |
| 5272 | "BM_%d : port in error: %lx\n", phba->state); |
Jitendra Bhivare | 10e1a44 | 2016-08-19 15:20:19 +0530 | [diff] [blame] | 5273 | /* sessions are no longer valid, so first fail the sessions */ |
| 5274 | queue_work(phba->wq, &phba->sess_work); |
| 5275 | |
| 5276 | /* detect UER supported */ |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5277 | if (!test_bit(BEISCSI_HBA_UER_SUPP, &phba->state)) |
| 5278 | return; |
| 5279 | /* modify this timer to check TPE */ |
Kees Cook | 841b86f | 2017-10-23 09:40:42 +0200 | [diff] [blame] | 5280 | phba->hw_check.function = beiscsi_hw_tpe_check; |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5281 | } |
| 5282 | |
| 5283 | mod_timer(&phba->hw_check, |
| 5284 | jiffies + msecs_to_jiffies(BEISCSI_UE_DETECT_INTERVAL)); |
| 5285 | } |
| 5286 | |
| 5287 | /* |
| 5288 | * beiscsi_enable_port()- Enables the disabled port. |
| 5289 | * Only port resources freed in disable function are reallocated. |
| 5290 | * This is called in HBA error handling path. |
| 5291 | * |
| 5292 | * @phba: Instance of driver private structure |
| 5293 | * |
| 5294 | **/ |
| 5295 | static int beiscsi_enable_port(struct beiscsi_hba *phba) |
| 5296 | { |
| 5297 | struct hwi_context_memory *phwi_context; |
| 5298 | struct hwi_controller *phwi_ctrlr; |
| 5299 | struct be_eq_obj *pbe_eq; |
| 5300 | int ret, i; |
| 5301 | |
| 5302 | if (test_bit(BEISCSI_HBA_ONLINE, &phba->state)) { |
| 5303 | __beiscsi_log(phba, KERN_ERR, |
| 5304 | "BM_%d : %s : port is online %lx\n", |
| 5305 | __func__, phba->state); |
| 5306 | return 0; |
| 5307 | } |
| 5308 | |
| 5309 | ret = beiscsi_init_sliport(phba); |
| 5310 | if (ret) |
| 5311 | return ret; |
| 5312 | |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 5313 | be2iscsi_enable_msix(phba); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5314 | |
| 5315 | beiscsi_get_params(phba); |
Jitendra Bhivare | 1cb3c3f | 2017-10-10 16:18:17 +0530 | [diff] [blame] | 5316 | beiscsi_set_host_data(phba); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5317 | /* Re-enable UER. If different TPE occurs then it is recoverable. */ |
| 5318 | beiscsi_set_uer_feature(phba); |
| 5319 | |
| 5320 | phba->shost->max_id = phba->params.cxns_per_ctrl; |
| 5321 | phba->shost->can_queue = phba->params.ios_per_ctrl; |
Jitendra Bhivare | dd94097 | 2016-12-13 15:56:04 +0530 | [diff] [blame] | 5322 | ret = beiscsi_init_port(phba); |
| 5323 | if (ret < 0) { |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5324 | __beiscsi_log(phba, KERN_ERR, |
Jitendra Bhivare | dd94097 | 2016-12-13 15:56:04 +0530 | [diff] [blame] | 5325 | "BM_%d : init port failed\n"); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5326 | goto disable_msix; |
| 5327 | } |
| 5328 | |
| 5329 | for (i = 0; i < MAX_MCC_CMD; i++) { |
| 5330 | init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]); |
| 5331 | phba->ctrl.mcc_tag[i] = i + 1; |
| 5332 | phba->ctrl.mcc_tag_status[i + 1] = 0; |
| 5333 | phba->ctrl.mcc_tag_available++; |
| 5334 | } |
| 5335 | |
| 5336 | phwi_ctrlr = phba->phwi_ctrlr; |
| 5337 | phwi_context = phwi_ctrlr->phwi_ctxt; |
| 5338 | for (i = 0; i < phba->num_cpus; i++) { |
| 5339 | pbe_eq = &phwi_context->be_eq[i]; |
| 5340 | irq_poll_init(&pbe_eq->iopoll, be_iopoll_budget, be_iopoll); |
| 5341 | } |
| 5342 | |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 5343 | i = (phba->pcidev->msix_enabled) ? i : 0; |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5344 | /* Work item for MCC handling */ |
| 5345 | pbe_eq = &phwi_context->be_eq[i]; |
| 5346 | INIT_WORK(&pbe_eq->mcc_work, beiscsi_mcc_work); |
| 5347 | |
| 5348 | ret = beiscsi_init_irqs(phba); |
| 5349 | if (ret < 0) { |
| 5350 | __beiscsi_log(phba, KERN_ERR, |
| 5351 | "BM_%d : setup IRQs failed %d\n", ret); |
| 5352 | goto cleanup_port; |
| 5353 | } |
| 5354 | hwi_enable_intr(phba); |
| 5355 | /* port operational: clear all error bits */ |
| 5356 | set_bit(BEISCSI_HBA_ONLINE, &phba->state); |
| 5357 | __beiscsi_log(phba, KERN_INFO, |
| 5358 | "BM_%d : port online: 0x%lx\n", phba->state); |
| 5359 | |
| 5360 | /* start hw_check timer and eqd_update work */ |
| 5361 | schedule_delayed_work(&phba->eqd_update, |
| 5362 | msecs_to_jiffies(BEISCSI_EQD_UPDATE_INTERVAL)); |
| 5363 | |
| 5364 | /** |
| 5365 | * Timer function gets modified for TPE detection. |
| 5366 | * Always reinit to do health check first. |
| 5367 | */ |
Kees Cook | 841b86f | 2017-10-23 09:40:42 +0200 | [diff] [blame] | 5368 | phba->hw_check.function = beiscsi_hw_health_check; |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5369 | mod_timer(&phba->hw_check, |
| 5370 | jiffies + msecs_to_jiffies(BEISCSI_UE_DETECT_INTERVAL)); |
| 5371 | return 0; |
| 5372 | |
| 5373 | cleanup_port: |
| 5374 | for (i = 0; i < phba->num_cpus; i++) { |
| 5375 | pbe_eq = &phwi_context->be_eq[i]; |
| 5376 | irq_poll_disable(&pbe_eq->iopoll); |
| 5377 | } |
| 5378 | hwi_cleanup_port(phba); |
| 5379 | |
| 5380 | disable_msix: |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 5381 | pci_free_irq_vectors(phba->pcidev); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5382 | return ret; |
| 5383 | } |
| 5384 | |
| 5385 | /* |
| 5386 | * beiscsi_disable_port()- Disable port and cleanup driver resources. |
| 5387 | * This is called in HBA error handling and driver removal. |
| 5388 | * @phba: Instance Priv structure |
| 5389 | * @unload: indicate driver is unloading |
| 5390 | * |
| 5391 | * Free the OS and HW resources held by the driver |
| 5392 | **/ |
| 5393 | static void beiscsi_disable_port(struct beiscsi_hba *phba, int unload) |
| 5394 | { |
| 5395 | struct hwi_context_memory *phwi_context; |
| 5396 | struct hwi_controller *phwi_ctrlr; |
| 5397 | struct be_eq_obj *pbe_eq; |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 5398 | unsigned int i; |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5399 | |
| 5400 | if (!test_and_clear_bit(BEISCSI_HBA_ONLINE, &phba->state)) |
| 5401 | return; |
| 5402 | |
| 5403 | phwi_ctrlr = phba->phwi_ctrlr; |
| 5404 | phwi_context = phwi_ctrlr->phwi_ctxt; |
| 5405 | hwi_disable_intr(phba); |
Jitendra Bhivare | 45371aa | 2017-10-10 16:18:13 +0530 | [diff] [blame] | 5406 | beiscsi_free_irqs(phba); |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 5407 | pci_free_irq_vectors(phba->pcidev); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5408 | |
| 5409 | for (i = 0; i < phba->num_cpus; i++) { |
| 5410 | pbe_eq = &phwi_context->be_eq[i]; |
| 5411 | irq_poll_disable(&pbe_eq->iopoll); |
| 5412 | } |
| 5413 | cancel_delayed_work_sync(&phba->eqd_update); |
| 5414 | cancel_work_sync(&phba->boot_work); |
| 5415 | /* WQ might be running cancel queued mcc_work if we are not exiting */ |
| 5416 | if (!unload && beiscsi_hba_in_error(phba)) { |
| 5417 | pbe_eq = &phwi_context->be_eq[i]; |
| 5418 | cancel_work_sync(&pbe_eq->mcc_work); |
| 5419 | } |
| 5420 | hwi_cleanup_port(phba); |
Jitendra Bhivare | dd94097 | 2016-12-13 15:56:04 +0530 | [diff] [blame] | 5421 | beiscsi_cleanup_port(phba); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5422 | } |
| 5423 | |
Jitendra Bhivare | 10e1a44 | 2016-08-19 15:20:19 +0530 | [diff] [blame] | 5424 | static void beiscsi_sess_work(struct work_struct *work) |
| 5425 | { |
| 5426 | struct beiscsi_hba *phba; |
| 5427 | |
| 5428 | phba = container_of(work, struct beiscsi_hba, sess_work); |
| 5429 | /* |
| 5430 | * This work gets scheduled only in case of HBA error. |
| 5431 | * Old sessions are gone so need to be re-established. |
| 5432 | * iscsi_session_failure needs process context hence this work. |
| 5433 | */ |
| 5434 | iscsi_host_for_each_session(phba->shost, beiscsi_session_fail); |
| 5435 | } |
| 5436 | |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5437 | static void beiscsi_recover_port(struct work_struct *work) |
| 5438 | { |
| 5439 | struct beiscsi_hba *phba; |
| 5440 | |
| 5441 | phba = container_of(work, struct beiscsi_hba, recover_port.work); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5442 | beiscsi_disable_port(phba, 0); |
| 5443 | beiscsi_enable_port(phba); |
| 5444 | } |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5445 | |
| 5446 | static pci_ers_result_t beiscsi_eeh_err_detected(struct pci_dev *pdev, |
| 5447 | pci_channel_state_t state) |
| 5448 | { |
| 5449 | struct beiscsi_hba *phba = NULL; |
| 5450 | |
| 5451 | phba = (struct beiscsi_hba *)pci_get_drvdata(pdev); |
Jitendra Bhivare | 9122e99 | 2016-08-19 15:20:11 +0530 | [diff] [blame] | 5452 | set_bit(BEISCSI_HBA_PCI_ERR, &phba->state); |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5453 | |
| 5454 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5455 | "BM_%d : EEH error detected\n"); |
| 5456 | |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5457 | /* first stop UE detection when PCI error detected */ |
| 5458 | del_timer_sync(&phba->hw_check); |
| 5459 | cancel_delayed_work_sync(&phba->recover_port); |
| 5460 | |
Jitendra Bhivare | 10e1a44 | 2016-08-19 15:20:19 +0530 | [diff] [blame] | 5461 | /* sessions are no longer valid, so first fail the sessions */ |
| 5462 | iscsi_host_for_each_session(phba->shost, beiscsi_session_fail); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5463 | beiscsi_disable_port(phba, 0); |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5464 | |
| 5465 | if (state == pci_channel_io_perm_failure) { |
| 5466 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5467 | "BM_%d : EEH : State PERM Failure"); |
| 5468 | return PCI_ERS_RESULT_DISCONNECT; |
| 5469 | } |
| 5470 | |
| 5471 | pci_disable_device(pdev); |
| 5472 | |
| 5473 | /* The error could cause the FW to trigger a flash debug dump. |
| 5474 | * Resetting the card while flash dump is in progress |
| 5475 | * can cause it not to recover; wait for it to finish. |
| 5476 | * Wait only for first function as it is needed only once per |
| 5477 | * adapter. |
| 5478 | **/ |
| 5479 | if (pdev->devfn == 0) |
| 5480 | ssleep(30); |
| 5481 | |
| 5482 | return PCI_ERS_RESULT_NEED_RESET; |
| 5483 | } |
| 5484 | |
| 5485 | static pci_ers_result_t beiscsi_eeh_reset(struct pci_dev *pdev) |
| 5486 | { |
| 5487 | struct beiscsi_hba *phba = NULL; |
| 5488 | int status = 0; |
| 5489 | |
| 5490 | phba = (struct beiscsi_hba *)pci_get_drvdata(pdev); |
| 5491 | |
| 5492 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5493 | "BM_%d : EEH Reset\n"); |
| 5494 | |
| 5495 | status = pci_enable_device(pdev); |
| 5496 | if (status) |
| 5497 | return PCI_ERS_RESULT_DISCONNECT; |
| 5498 | |
| 5499 | pci_set_master(pdev); |
| 5500 | pci_set_power_state(pdev, PCI_D0); |
| 5501 | pci_restore_state(pdev); |
| 5502 | |
Jitendra Bhivare | 4d2ee1e | 2016-08-19 15:20:16 +0530 | [diff] [blame] | 5503 | status = beiscsi_check_fw_rdy(phba); |
| 5504 | if (status) { |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5505 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT, |
| 5506 | "BM_%d : EEH Reset Completed\n"); |
| 5507 | } else { |
| 5508 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT, |
| 5509 | "BM_%d : EEH Reset Completion Failure\n"); |
| 5510 | return PCI_ERS_RESULT_DISCONNECT; |
| 5511 | } |
| 5512 | |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5513 | return PCI_ERS_RESULT_RECOVERED; |
| 5514 | } |
| 5515 | |
| 5516 | static void beiscsi_eeh_resume(struct pci_dev *pdev) |
| 5517 | { |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5518 | struct beiscsi_hba *phba; |
| 5519 | int ret; |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5520 | |
| 5521 | phba = (struct beiscsi_hba *)pci_get_drvdata(pdev); |
| 5522 | pci_save_state(pdev); |
| 5523 | |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5524 | ret = beiscsi_enable_port(phba); |
Jitendra Bhivare | 4d2ee1e | 2016-08-19 15:20:16 +0530 | [diff] [blame] | 5525 | if (ret) |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5526 | __beiscsi_log(phba, KERN_ERR, |
| 5527 | "BM_%d : AER EEH resume failed\n"); |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5528 | } |
| 5529 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5530 | static int beiscsi_dev_probe(struct pci_dev *pcidev, |
| 5531 | const struct pci_device_id *id) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5532 | { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5533 | struct hwi_context_memory *phwi_context; |
Jitendra Bhivare | 29e80b7 | 2016-12-13 15:56:02 +0530 | [diff] [blame] | 5534 | struct hwi_controller *phwi_ctrlr; |
| 5535 | struct beiscsi_hba *phba = NULL; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5536 | struct be_eq_obj *pbe_eq; |
Jitendra Bhivare | 50a4b82 | 2016-08-19 15:20:12 +0530 | [diff] [blame] | 5537 | unsigned int s_handle; |
Jitendra Bhivare | 29e80b7 | 2016-12-13 15:56:02 +0530 | [diff] [blame] | 5538 | char wq_name[20]; |
Christophe JAILLET | deeea8e | 2016-08-26 15:09:06 +0530 | [diff] [blame] | 5539 | int ret, i; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5540 | |
| 5541 | ret = beiscsi_enable_pci(pcidev); |
| 5542 | if (ret < 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5543 | dev_err(&pcidev->dev, |
| 5544 | "beiscsi_dev_probe - Failed to enable pci device\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5545 | return ret; |
| 5546 | } |
| 5547 | |
| 5548 | phba = beiscsi_hba_alloc(pcidev); |
| 5549 | if (!phba) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5550 | dev_err(&pcidev->dev, |
| 5551 | "beiscsi_dev_probe - Failed in beiscsi_hba_alloc\n"); |
Christophe JAILLET | deeea8e | 2016-08-26 15:09:06 +0530 | [diff] [blame] | 5552 | ret = -ENOMEM; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5553 | goto disable_pci; |
| 5554 | } |
| 5555 | |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5556 | /* Enable EEH reporting */ |
| 5557 | ret = pci_enable_pcie_error_reporting(pcidev); |
| 5558 | if (ret) |
| 5559 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT, |
| 5560 | "BM_%d : PCIe Error Reporting " |
| 5561 | "Enabling Failed\n"); |
| 5562 | |
| 5563 | pci_save_state(pcidev); |
| 5564 | |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5565 | /* Initialize Driver configuration Paramters */ |
| 5566 | beiscsi_hba_attrs_init(phba); |
| 5567 | |
Jayamohan Kallickal | 6c83185 | 2013-09-28 15:35:40 -0700 | [diff] [blame] | 5568 | phba->mac_addr_set = false; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 5569 | |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 5570 | switch (pcidev->device) { |
| 5571 | case BE_DEVICE_ID1: |
| 5572 | case OC_DEVICE_ID1: |
| 5573 | case OC_DEVICE_ID2: |
| 5574 | phba->generation = BE_GEN2; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5575 | phba->iotask_fn = beiscsi_iotask; |
Ketan Mukadam | 5fa7db2 | 2016-12-13 15:56:05 +0530 | [diff] [blame] | 5576 | dev_warn(&pcidev->dev, |
| 5577 | "Obsolete/Unsupported BE2 Adapter Family\n"); |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 5578 | break; |
| 5579 | case BE_DEVICE_ID2: |
| 5580 | case OC_DEVICE_ID3: |
| 5581 | phba->generation = BE_GEN3; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5582 | phba->iotask_fn = beiscsi_iotask; |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 5583 | break; |
John Soni Jose | 139a1b1 | 2012-10-20 04:43:20 +0530 | [diff] [blame] | 5584 | case OC_SKH_ID1: |
| 5585 | phba->generation = BE_GEN4; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5586 | phba->iotask_fn = beiscsi_iotask_v2; |
Jayamohan Kallickal | bf9131c | 2013-04-05 20:38:24 -0700 | [diff] [blame] | 5587 | break; |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 5588 | default: |
| 5589 | phba->generation = 0; |
| 5590 | } |
| 5591 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5592 | ret = be_ctrl_init(phba, pcidev); |
| 5593 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5594 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
Jitendra Bhivare | 4d2ee1e | 2016-08-19 15:20:16 +0530 | [diff] [blame] | 5595 | "BM_%d : be_ctrl_init failed\n"); |
Jitendra Bhivare | 45371aa | 2017-10-10 16:18:13 +0530 | [diff] [blame] | 5596 | goto free_hba; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5597 | } |
| 5598 | |
Jitendra Bhivare | 4d2ee1e | 2016-08-19 15:20:16 +0530 | [diff] [blame] | 5599 | ret = beiscsi_init_sliport(phba); |
| 5600 | if (ret) |
Jitendra Bhivare | 45371aa | 2017-10-10 16:18:13 +0530 | [diff] [blame] | 5601 | goto free_hba; |
Jitendra Bhivare | 4d2ee1e | 2016-08-19 15:20:16 +0530 | [diff] [blame] | 5602 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5603 | spin_lock_init(&phba->io_sgl_lock); |
| 5604 | spin_lock_init(&phba->mgmt_sgl_lock); |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 5605 | spin_lock_init(&phba->async_pdu_lock); |
Jitendra Bhivare | 480195c | 2016-08-19 15:20:15 +0530 | [diff] [blame] | 5606 | ret = beiscsi_get_fw_config(&phba->ctrl, phba); |
Jayamohan Kallickal | 7da5087 | 2010-01-05 05:04:12 +0530 | [diff] [blame] | 5607 | if (ret != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5608 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5609 | "BM_%d : Error getting fw config\n"); |
Jayamohan Kallickal | 7da5087 | 2010-01-05 05:04:12 +0530 | [diff] [blame] | 5610 | goto free_port; |
| 5611 | } |
Jitendra Bhivare | 480195c | 2016-08-19 15:20:15 +0530 | [diff] [blame] | 5612 | beiscsi_get_port_name(&phba->ctrl, phba); |
Jitendra Bhivare | 4570f16 | 2016-01-20 14:10:54 +0530 | [diff] [blame] | 5613 | beiscsi_get_params(phba); |
Jitendra Bhivare | 1cb3c3f | 2017-10-10 16:18:17 +0530 | [diff] [blame] | 5614 | beiscsi_set_host_data(phba); |
Jitendra Bhivare | 6694095 | 2016-08-19 15:20:14 +0530 | [diff] [blame] | 5615 | beiscsi_set_uer_feature(phba); |
Jayamohan Kallickal | 68c26a3 | 2013-09-28 15:35:54 -0700 | [diff] [blame] | 5616 | |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 5617 | be2iscsi_enable_msix(phba); |
Jayamohan Kallickal | 68c26a3 | 2013-09-28 15:35:54 -0700 | [diff] [blame] | 5618 | |
| 5619 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 5620 | "BM_%d : num_cpus = %d\n", |
| 5621 | phba->num_cpus); |
| 5622 | |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 5623 | phba->shost->max_id = phba->params.cxns_per_ctrl; |
Jayamohan Kallickal | aa874f0 | 2010-01-05 05:12:03 +0530 | [diff] [blame] | 5624 | phba->shost->can_queue = phba->params.ios_per_ctrl; |
Jitendra Bhivare | dd94097 | 2016-12-13 15:56:04 +0530 | [diff] [blame] | 5625 | ret = beiscsi_get_memory(phba); |
| 5626 | if (ret < 0) { |
| 5627 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5628 | "BM_%d : alloc host mem failed\n"); |
| 5629 | goto free_port; |
| 5630 | } |
| 5631 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5632 | ret = beiscsi_init_port(phba); |
| 5633 | if (ret < 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5634 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
Jitendra Bhivare | dd94097 | 2016-12-13 15:56:04 +0530 | [diff] [blame] | 5635 | "BM_%d : init port failed\n"); |
| 5636 | beiscsi_free_mem(phba); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5637 | goto free_port; |
| 5638 | } |
| 5639 | |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5640 | for (i = 0; i < MAX_MCC_CMD; i++) { |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 5641 | init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]); |
| 5642 | phba->ctrl.mcc_tag[i] = i + 1; |
Jitendra Bhivare | 67296ad | 2016-02-04 15:49:10 +0530 | [diff] [blame] | 5643 | phba->ctrl.mcc_tag_status[i + 1] = 0; |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 5644 | phba->ctrl.mcc_tag_available++; |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 5645 | memset(&phba->ctrl.ptag_state[i].tag_mem_state, 0, |
Jayamohan Kallickal | 8fc01ea | 2014-05-05 21:41:28 -0400 | [diff] [blame] | 5646 | sizeof(struct be_dma_mem)); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 5647 | } |
| 5648 | |
| 5649 | phba->ctrl.mcc_alloc_index = phba->ctrl.mcc_free_index = 0; |
| 5650 | |
Jitendra Bhivare | 29e80b7 | 2016-12-13 15:56:02 +0530 | [diff] [blame] | 5651 | snprintf(wq_name, sizeof(wq_name), "beiscsi_%02x_wq", |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5652 | phba->shost->host_no); |
Jitendra Bhivare | 29e80b7 | 2016-12-13 15:56:02 +0530 | [diff] [blame] | 5653 | phba->wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 1, wq_name); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5654 | if (!phba->wq) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5655 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5656 | "BM_%d : beiscsi_dev_probe-" |
| 5657 | "Failed to allocate work queue\n"); |
Christophe JAILLET | deeea8e | 2016-08-26 15:09:06 +0530 | [diff] [blame] | 5658 | ret = -ENOMEM; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5659 | goto free_twq; |
| 5660 | } |
| 5661 | |
Jitendra Bhivare | 10bcd47 | 2016-08-19 15:20:13 +0530 | [diff] [blame] | 5662 | INIT_DELAYED_WORK(&phba->eqd_update, beiscsi_eqd_update_work); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5663 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5664 | phwi_ctrlr = phba->phwi_ctrlr; |
| 5665 | phwi_context = phwi_ctrlr->phwi_ctxt; |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 5666 | |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5667 | for (i = 0; i < phba->num_cpus; i++) { |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 5668 | pbe_eq = &phwi_context->be_eq[i]; |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5669 | irq_poll_init(&pbe_eq->iopoll, be_iopoll_budget, be_iopoll); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5670 | } |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 5671 | |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 5672 | i = (phba->pcidev->msix_enabled) ? i : 0; |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5673 | /* Work item for MCC handling */ |
| 5674 | pbe_eq = &phwi_context->be_eq[i]; |
Jitendra Bhivare | a3095016 | 2016-08-19 15:20:10 +0530 | [diff] [blame] | 5675 | INIT_WORK(&pbe_eq->mcc_work, beiscsi_mcc_work); |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5676 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5677 | ret = beiscsi_init_irqs(phba); |
| 5678 | if (ret < 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5679 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5680 | "BM_%d : beiscsi_dev_probe-" |
| 5681 | "Failed to beiscsi_init_irqs\n"); |
Jitendra Bhivare | 45371aa | 2017-10-10 16:18:13 +0530 | [diff] [blame] | 5682 | goto disable_iopoll; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5683 | } |
Jayamohan Kallickal | 238f6b7 | 2010-07-22 04:23:22 +0530 | [diff] [blame] | 5684 | hwi_enable_intr(phba); |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 5685 | |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5686 | ret = iscsi_host_add(phba->shost, &phba->pcidev->dev); |
| 5687 | if (ret) |
Jitendra Bhivare | 45371aa | 2017-10-10 16:18:13 +0530 | [diff] [blame] | 5688 | goto free_irqs; |
Jayamohan Kallickal | 0598b8a | 2014-05-05 21:41:25 -0400 | [diff] [blame] | 5689 | |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5690 | /* set online bit after port is operational */ |
| 5691 | set_bit(BEISCSI_HBA_ONLINE, &phba->state); |
| 5692 | __beiscsi_log(phba, KERN_INFO, |
| 5693 | "BM_%d : port online: 0x%lx\n", phba->state); |
| 5694 | |
Jitendra Bhivare | 50a4b82 | 2016-08-19 15:20:12 +0530 | [diff] [blame] | 5695 | INIT_WORK(&phba->boot_work, beiscsi_boot_work); |
| 5696 | ret = beiscsi_boot_get_shandle(phba, &s_handle); |
| 5697 | if (ret > 0) { |
| 5698 | beiscsi_start_boot_work(phba, s_handle); |
| 5699 | /** |
| 5700 | * Set this bit after starting the work to let |
| 5701 | * probe handle it first. |
| 5702 | * ASYNC event can too schedule this work. |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 5703 | */ |
Jitendra Bhivare | 50a4b82 | 2016-08-19 15:20:12 +0530 | [diff] [blame] | 5704 | set_bit(BEISCSI_HBA_BOOT_FOUND, &phba->state); |
| 5705 | } |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 5706 | |
Jitendra Bhivare | 96b48b9 | 2016-08-19 15:20:06 +0530 | [diff] [blame] | 5707 | beiscsi_iface_create_default(phba); |
Jitendra Bhivare | 10bcd47 | 2016-08-19 15:20:13 +0530 | [diff] [blame] | 5708 | schedule_delayed_work(&phba->eqd_update, |
| 5709 | msecs_to_jiffies(BEISCSI_EQD_UPDATE_INTERVAL)); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5710 | |
Jitendra Bhivare | 10e1a44 | 2016-08-19 15:20:19 +0530 | [diff] [blame] | 5711 | INIT_WORK(&phba->sess_work, beiscsi_sess_work); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5712 | INIT_DELAYED_WORK(&phba->recover_port, beiscsi_recover_port); |
Jitendra Bhivare | 10bcd47 | 2016-08-19 15:20:13 +0530 | [diff] [blame] | 5713 | /** |
| 5714 | * Start UE detection here. UE before this will cause stall in probe |
| 5715 | * and eventually fail the probe. |
| 5716 | */ |
Kees Cook | b386eec | 2017-10-11 16:15:26 -0700 | [diff] [blame] | 5717 | timer_setup(&phba->hw_check, beiscsi_hw_health_check, 0); |
Jitendra Bhivare | 10bcd47 | 2016-08-19 15:20:13 +0530 | [diff] [blame] | 5718 | mod_timer(&phba->hw_check, |
| 5719 | jiffies + msecs_to_jiffies(BEISCSI_UE_DETECT_INTERVAL)); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5720 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 5721 | "\n\n\n BM_%d : SUCCESS - DRIVER LOADED\n\n\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5722 | return 0; |
| 5723 | |
Jitendra Bhivare | 45371aa | 2017-10-10 16:18:13 +0530 | [diff] [blame] | 5724 | free_irqs: |
| 5725 | hwi_disable_intr(phba); |
| 5726 | beiscsi_free_irqs(phba); |
| 5727 | disable_iopoll: |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5728 | for (i = 0; i < phba->num_cpus; i++) { |
| 5729 | pbe_eq = &phwi_context->be_eq[i]; |
Christoph Hellwig | 511cbce | 2015-11-10 14:56:14 +0100 | [diff] [blame] | 5730 | irq_poll_disable(&pbe_eq->iopoll); |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5731 | } |
Jitendra Bhivare | 45371aa | 2017-10-10 16:18:13 +0530 | [diff] [blame] | 5732 | destroy_workqueue(phba->wq); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5733 | free_twq: |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5734 | hwi_cleanup_port(phba); |
Jitendra Bhivare | 4d2ee1e | 2016-08-19 15:20:16 +0530 | [diff] [blame] | 5735 | beiscsi_cleanup_port(phba); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5736 | beiscsi_free_mem(phba); |
| 5737 | free_port: |
Christoph Hellwig | 26a4c99 | 2018-10-10 18:22:24 +0200 | [diff] [blame] | 5738 | dma_free_coherent(&phba->pcidev->dev, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5739 | phba->ctrl.mbox_mem_alloced.size, |
| 5740 | phba->ctrl.mbox_mem_alloced.va, |
Jitendra Bhivare | 45371aa | 2017-10-10 16:18:13 +0530 | [diff] [blame] | 5741 | phba->ctrl.mbox_mem_alloced.dma); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5742 | beiscsi_unmap_pci_function(phba); |
Jitendra Bhivare | 45371aa | 2017-10-10 16:18:13 +0530 | [diff] [blame] | 5743 | free_hba: |
Christoph Hellwig | 8314886 | 2017-01-13 17:29:48 +0100 | [diff] [blame] | 5744 | pci_disable_msix(phba->pcidev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5745 | pci_dev_put(phba->pcidev); |
| 5746 | iscsi_host_free(phba->shost); |
John Soni Jose | 2e7cee0 | 2015-02-12 06:45:47 +0530 | [diff] [blame] | 5747 | pci_set_drvdata(pcidev, NULL); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5748 | disable_pci: |
John Soni Jose | e307f3a | 2015-04-25 08:17:19 +0530 | [diff] [blame] | 5749 | pci_release_regions(pcidev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5750 | pci_disable_device(pcidev); |
| 5751 | return ret; |
| 5752 | } |
| 5753 | |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5754 | static void beiscsi_remove(struct pci_dev *pcidev) |
| 5755 | { |
| 5756 | struct beiscsi_hba *phba = NULL; |
| 5757 | |
| 5758 | phba = pci_get_drvdata(pcidev); |
| 5759 | if (!phba) { |
| 5760 | dev_err(&pcidev->dev, "beiscsi_remove called with no phba\n"); |
| 5761 | return; |
| 5762 | } |
| 5763 | |
| 5764 | /* first stop UE detection before unloading */ |
| 5765 | del_timer_sync(&phba->hw_check); |
| 5766 | cancel_delayed_work_sync(&phba->recover_port); |
Jitendra Bhivare | 10e1a44 | 2016-08-19 15:20:19 +0530 | [diff] [blame] | 5767 | cancel_work_sync(&phba->sess_work); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5768 | |
| 5769 | beiscsi_iface_destroy_default(phba); |
| 5770 | iscsi_host_remove(phba->shost); |
| 5771 | beiscsi_disable_port(phba, 1); |
| 5772 | |
| 5773 | /* after cancelling boot_work */ |
| 5774 | iscsi_boot_destroy_kset(phba->boot_struct.boot_kset); |
| 5775 | |
| 5776 | /* free all resources */ |
| 5777 | destroy_workqueue(phba->wq); |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5778 | beiscsi_free_mem(phba); |
| 5779 | |
| 5780 | /* ctrl uninit */ |
| 5781 | beiscsi_unmap_pci_function(phba); |
Christoph Hellwig | 26a4c99 | 2018-10-10 18:22:24 +0200 | [diff] [blame] | 5782 | dma_free_coherent(&phba->pcidev->dev, |
Jitendra Bhivare | d1d5ca8 | 2016-08-19 15:20:18 +0530 | [diff] [blame] | 5783 | phba->ctrl.mbox_mem_alloced.size, |
| 5784 | phba->ctrl.mbox_mem_alloced.va, |
| 5785 | phba->ctrl.mbox_mem_alloced.dma); |
| 5786 | |
| 5787 | pci_dev_put(phba->pcidev); |
| 5788 | iscsi_host_free(phba->shost); |
| 5789 | pci_disable_pcie_error_reporting(pcidev); |
| 5790 | pci_set_drvdata(pcidev, NULL); |
| 5791 | pci_release_regions(pcidev); |
| 5792 | pci_disable_device(pcidev); |
| 5793 | } |
| 5794 | |
| 5795 | |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5796 | static struct pci_error_handlers beiscsi_eeh_handlers = { |
| 5797 | .error_detected = beiscsi_eeh_err_detected, |
| 5798 | .slot_reset = beiscsi_eeh_reset, |
| 5799 | .resume = beiscsi_eeh_resume, |
| 5800 | }; |
| 5801 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5802 | struct iscsi_transport beiscsi_iscsi_transport = { |
| 5803 | .owner = THIS_MODULE, |
| 5804 | .name = DRV_NAME, |
Jayamohan Kallickal | 9db0fb3 | 2010-01-05 05:12:43 +0530 | [diff] [blame] | 5805 | .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_TEXT_NEGO | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5806 | CAP_MULTI_R2T | CAP_DATADGST | CAP_DATA_PATH_OFFLOAD, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5807 | .create_session = beiscsi_session_create, |
| 5808 | .destroy_session = beiscsi_session_destroy, |
| 5809 | .create_conn = beiscsi_conn_create, |
| 5810 | .bind_conn = beiscsi_conn_bind, |
| 5811 | .destroy_conn = iscsi_conn_teardown, |
Jitendra Bhivare | 96b48b9 | 2016-08-19 15:20:06 +0530 | [diff] [blame] | 5812 | .attr_is_visible = beiscsi_attr_is_visible, |
| 5813 | .set_iface_param = beiscsi_iface_set_param, |
| 5814 | .get_iface_param = beiscsi_iface_get_param, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5815 | .set_param = beiscsi_set_param, |
Mike Christie | c7f7fd5 | 2011-02-16 15:04:41 -0600 | [diff] [blame] | 5816 | .get_conn_param = iscsi_conn_get_param, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5817 | .get_session_param = iscsi_session_get_param, |
| 5818 | .get_host_param = beiscsi_get_host_param, |
| 5819 | .start_conn = beiscsi_conn_start, |
Mike Christie | fa95d20 | 2010-06-09 03:30:08 -0500 | [diff] [blame] | 5820 | .stop_conn = iscsi_conn_stop, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5821 | .send_pdu = iscsi_conn_send_pdu, |
| 5822 | .xmit_task = beiscsi_task_xmit, |
| 5823 | .cleanup_task = beiscsi_cleanup_task, |
| 5824 | .alloc_pdu = beiscsi_alloc_pdu, |
| 5825 | .parse_pdu_itt = beiscsi_parse_pdu, |
| 5826 | .get_stats = beiscsi_conn_get_stats, |
Mike Christie | c7f7fd5 | 2011-02-16 15:04:41 -0600 | [diff] [blame] | 5827 | .get_ep_param = beiscsi_ep_get_param, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5828 | .ep_connect = beiscsi_ep_connect, |
| 5829 | .ep_poll = beiscsi_ep_poll, |
| 5830 | .ep_disconnect = beiscsi_ep_disconnect, |
| 5831 | .session_recovery_timedout = iscsi_session_recovery_timedout, |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 5832 | .bsg_request = beiscsi_bsg_request, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5833 | }; |
| 5834 | |
| 5835 | static struct pci_driver beiscsi_pci_driver = { |
| 5836 | .name = DRV_NAME, |
| 5837 | .probe = beiscsi_dev_probe, |
| 5838 | .remove = beiscsi_remove, |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5839 | .id_table = beiscsi_pci_id_table, |
| 5840 | .err_handler = &beiscsi_eeh_handlers |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5841 | }; |
| 5842 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5843 | static int __init beiscsi_module_init(void) |
| 5844 | { |
| 5845 | int ret; |
| 5846 | |
| 5847 | beiscsi_scsi_transport = |
| 5848 | iscsi_register_transport(&beiscsi_iscsi_transport); |
| 5849 | if (!beiscsi_scsi_transport) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5850 | printk(KERN_ERR |
| 5851 | "beiscsi_module_init - Unable to register beiscsi transport.\n"); |
Jayamohan Kallickal | f55a24f | 2010-01-23 05:37:40 +0530 | [diff] [blame] | 5852 | return -ENOMEM; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5853 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5854 | printk(KERN_INFO "In beiscsi_module_init, tt=%p\n", |
| 5855 | &beiscsi_iscsi_transport); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5856 | |
| 5857 | ret = pci_register_driver(&beiscsi_pci_driver); |
| 5858 | if (ret) { |
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 pci driver.\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5861 | goto unregister_iscsi_transport; |
| 5862 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5863 | return 0; |
| 5864 | |
| 5865 | unregister_iscsi_transport: |
| 5866 | iscsi_unregister_transport(&beiscsi_iscsi_transport); |
| 5867 | return ret; |
| 5868 | } |
| 5869 | |
| 5870 | static void __exit beiscsi_module_exit(void) |
| 5871 | { |
| 5872 | pci_unregister_driver(&beiscsi_pci_driver); |
| 5873 | iscsi_unregister_transport(&beiscsi_iscsi_transport); |
| 5874 | } |
| 5875 | |
| 5876 | module_init(beiscsi_module_init); |
| 5877 | module_exit(beiscsi_module_exit); |