Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1 | /** |
Ketan Mukadam | c4f39bd | 2015-07-04 04:12:33 +0530 | [diff] [blame] | 2 | * Copyright (C) 2005 - 2015 Emulex |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3 | * All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License version 2 |
| 7 | * as published by the Free Software Foundation. The full GNU General |
| 8 | * Public License is included in this distribution in the file called COPYING. |
| 9 | * |
Minh Tran | 4627de9 | 2015-05-14 23:16:17 -0700 | [diff] [blame] | 10 | * Written by: Jayamohan Kallickal (jayamohan.kallickal@avagotech.com) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 11 | * |
| 12 | * Contact Information: |
Minh Tran | 4627de9 | 2015-05-14 23:16:17 -0700 | [diff] [blame] | 13 | * linux-drivers@avagotech.com |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 14 | * |
Ketan Mukadam | c4f39bd | 2015-07-04 04:12:33 +0530 | [diff] [blame] | 15 | * Emulex |
Jayamohan Kallickal | 255fa9a | 2011-03-25 14:23:57 -0700 | [diff] [blame] | 16 | * 3333 Susan Street |
| 17 | * Costa Mesa, CA 92626 |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 18 | */ |
Jayamohan Kallickal | 255fa9a | 2011-03-25 14:23:57 -0700 | [diff] [blame] | 19 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 20 | #include <linux/reboot.h> |
| 21 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/slab.h> |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 23 | #include <linux/interrupt.h> |
| 24 | #include <linux/blkdev.h> |
| 25 | #include <linux/pci.h> |
| 26 | #include <linux/string.h> |
| 27 | #include <linux/kernel.h> |
| 28 | #include <linux/semaphore.h> |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 29 | #include <linux/iscsi_boot_sysfs.h> |
Paul Gortmaker | acf3368f | 2011-05-27 09:47:43 -0400 | [diff] [blame] | 30 | #include <linux/module.h> |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 31 | #include <linux/bsg-lib.h> |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 32 | #include <linux/irq_poll.h> |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 33 | |
| 34 | #include <scsi/libiscsi.h> |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 35 | #include <scsi/scsi_bsg_iscsi.h> |
| 36 | #include <scsi/scsi_netlink.h> |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 37 | #include <scsi/scsi_transport_iscsi.h> |
| 38 | #include <scsi/scsi_transport.h> |
| 39 | #include <scsi/scsi_cmnd.h> |
| 40 | #include <scsi/scsi_device.h> |
| 41 | #include <scsi/scsi_host.h> |
| 42 | #include <scsi/scsi.h> |
| 43 | #include "be_main.h" |
| 44 | #include "be_iscsi.h" |
| 45 | #include "be_mgmt.h" |
John Soni Jose | 0a513dd | 2012-08-20 23:00:55 +0530 | [diff] [blame] | 46 | #include "be_cmds.h" |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 47 | |
| 48 | static unsigned int be_iopoll_budget = 10; |
| 49 | static unsigned int be_max_phys_size = 64; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 50 | static unsigned int enable_msix = 1; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 51 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 52 | MODULE_DESCRIPTION(DRV_DESC " " BUILD_STR); |
Jayamohan Kallickal | 76d15db | 2012-04-03 23:41:46 -0500 | [diff] [blame] | 53 | MODULE_VERSION(BUILD_STR); |
Ketan Mukadam | c4f39bd | 2015-07-04 04:12:33 +0530 | [diff] [blame] | 54 | MODULE_AUTHOR("Emulex Corporation"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 55 | MODULE_LICENSE("GPL"); |
| 56 | module_param(be_iopoll_budget, int, 0); |
| 57 | module_param(enable_msix, int, 0); |
| 58 | module_param(be_max_phys_size, uint, S_IRUGO); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 59 | MODULE_PARM_DESC(be_max_phys_size, |
| 60 | "Maximum Size (In Kilobytes) of physically contiguous " |
| 61 | "memory that can be allocated. Range is 16 - 128"); |
| 62 | |
| 63 | #define beiscsi_disp_param(_name)\ |
| 64 | ssize_t \ |
| 65 | beiscsi_##_name##_disp(struct device *dev,\ |
| 66 | struct device_attribute *attrib, char *buf) \ |
| 67 | { \ |
| 68 | struct Scsi_Host *shost = class_to_shost(dev);\ |
| 69 | struct beiscsi_hba *phba = iscsi_host_priv(shost); \ |
| 70 | uint32_t param_val = 0; \ |
| 71 | param_val = phba->attr_##_name;\ |
| 72 | return snprintf(buf, PAGE_SIZE, "%d\n",\ |
| 73 | phba->attr_##_name);\ |
| 74 | } |
| 75 | |
| 76 | #define beiscsi_change_param(_name, _minval, _maxval, _defaval)\ |
| 77 | int \ |
| 78 | beiscsi_##_name##_change(struct beiscsi_hba *phba, uint32_t val)\ |
| 79 | {\ |
| 80 | if (val >= _minval && val <= _maxval) {\ |
| 81 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,\ |
| 82 | "BA_%d : beiscsi_"#_name" updated "\ |
| 83 | "from 0x%x ==> 0x%x\n",\ |
| 84 | phba->attr_##_name, val); \ |
| 85 | phba->attr_##_name = val;\ |
| 86 | return 0;\ |
| 87 | } \ |
| 88 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, \ |
| 89 | "BA_%d beiscsi_"#_name" attribute "\ |
| 90 | "cannot be updated to 0x%x, "\ |
| 91 | "range allowed is ["#_minval" - "#_maxval"]\n", val);\ |
| 92 | return -EINVAL;\ |
| 93 | } |
| 94 | |
| 95 | #define beiscsi_store_param(_name) \ |
| 96 | ssize_t \ |
| 97 | beiscsi_##_name##_store(struct device *dev,\ |
| 98 | struct device_attribute *attr, const char *buf,\ |
| 99 | size_t count) \ |
| 100 | { \ |
| 101 | struct Scsi_Host *shost = class_to_shost(dev);\ |
| 102 | struct beiscsi_hba *phba = iscsi_host_priv(shost);\ |
| 103 | uint32_t param_val = 0;\ |
| 104 | if (!isdigit(buf[0]))\ |
| 105 | return -EINVAL;\ |
| 106 | if (sscanf(buf, "%i", ¶m_val) != 1)\ |
| 107 | return -EINVAL;\ |
| 108 | if (beiscsi_##_name##_change(phba, param_val) == 0) \ |
| 109 | return strlen(buf);\ |
| 110 | else \ |
| 111 | return -EINVAL;\ |
| 112 | } |
| 113 | |
| 114 | #define beiscsi_init_param(_name, _minval, _maxval, _defval) \ |
| 115 | int \ |
| 116 | beiscsi_##_name##_init(struct beiscsi_hba *phba, uint32_t val) \ |
| 117 | { \ |
| 118 | if (val >= _minval && val <= _maxval) {\ |
| 119 | phba->attr_##_name = val;\ |
| 120 | return 0;\ |
| 121 | } \ |
| 122 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,\ |
| 123 | "BA_%d beiscsi_"#_name" attribute " \ |
| 124 | "cannot be updated to 0x%x, "\ |
| 125 | "range allowed is ["#_minval" - "#_maxval"]\n", val);\ |
| 126 | phba->attr_##_name = _defval;\ |
| 127 | return -EINVAL;\ |
| 128 | } |
| 129 | |
| 130 | #define BEISCSI_RW_ATTR(_name, _minval, _maxval, _defval, _descp) \ |
| 131 | static uint beiscsi_##_name = _defval;\ |
| 132 | module_param(beiscsi_##_name, uint, S_IRUGO);\ |
| 133 | MODULE_PARM_DESC(beiscsi_##_name, _descp);\ |
| 134 | beiscsi_disp_param(_name)\ |
| 135 | beiscsi_change_param(_name, _minval, _maxval, _defval)\ |
| 136 | beiscsi_store_param(_name)\ |
| 137 | beiscsi_init_param(_name, _minval, _maxval, _defval)\ |
| 138 | DEVICE_ATTR(beiscsi_##_name, S_IRUGO | S_IWUSR,\ |
| 139 | beiscsi_##_name##_disp, beiscsi_##_name##_store) |
| 140 | |
| 141 | /* |
| 142 | * When new log level added update the |
| 143 | * the MAX allowed value for log_enable |
| 144 | */ |
| 145 | BEISCSI_RW_ATTR(log_enable, 0x00, |
| 146 | 0xFF, 0x00, "Enable logging Bit Mask\n" |
| 147 | "\t\t\t\tInitialization Events : 0x01\n" |
| 148 | "\t\t\t\tMailbox Events : 0x02\n" |
| 149 | "\t\t\t\tMiscellaneous Events : 0x04\n" |
| 150 | "\t\t\t\tError Handling : 0x08\n" |
| 151 | "\t\t\t\tIO Path Events : 0x10\n" |
Jayamohan Kallickal | afb9605 | 2013-09-28 15:35:55 -0700 | [diff] [blame] | 152 | "\t\t\t\tConfiguration Path : 0x20\n" |
| 153 | "\t\t\t\tiSCSI Protocol : 0x40\n"); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 154 | |
John Soni Jose | 5cac759 | 2012-10-20 04:42:25 +0530 | [diff] [blame] | 155 | 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] | 156 | DEVICE_ATTR(beiscsi_adapter_family, S_IRUGO, beiscsi_adap_family_disp, NULL); |
Jayamohan Kallickal | 22661e2 | 2013-04-05 20:38:28 -0700 | [diff] [blame] | 157 | DEVICE_ATTR(beiscsi_fw_ver, S_IRUGO, beiscsi_fw_ver_disp, NULL); |
Jayamohan Kallickal | d3fea9a | 2013-09-28 15:35:53 -0700 | [diff] [blame] | 158 | DEVICE_ATTR(beiscsi_phys_port, S_IRUGO, beiscsi_phys_port_disp, NULL); |
Jayamohan Kallickal | 6103c1f | 2013-09-28 15:35:52 -0700 | [diff] [blame] | 159 | DEVICE_ATTR(beiscsi_active_session_count, S_IRUGO, |
| 160 | beiscsi_active_session_disp, NULL); |
| 161 | DEVICE_ATTR(beiscsi_free_session_count, S_IRUGO, |
| 162 | beiscsi_free_session_disp, NULL); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 163 | struct device_attribute *beiscsi_attrs[] = { |
| 164 | &dev_attr_beiscsi_log_enable, |
John Soni Jose | 5cac759 | 2012-10-20 04:42:25 +0530 | [diff] [blame] | 165 | &dev_attr_beiscsi_drvr_ver, |
John Soni Jose | 26000db | 2012-10-20 04:45:06 +0530 | [diff] [blame] | 166 | &dev_attr_beiscsi_adapter_family, |
Jayamohan Kallickal | 22661e2 | 2013-04-05 20:38:28 -0700 | [diff] [blame] | 167 | &dev_attr_beiscsi_fw_ver, |
Jayamohan Kallickal | 6103c1f | 2013-09-28 15:35:52 -0700 | [diff] [blame] | 168 | &dev_attr_beiscsi_active_session_count, |
| 169 | &dev_attr_beiscsi_free_session_count, |
Jayamohan Kallickal | d3fea9a | 2013-09-28 15:35:53 -0700 | [diff] [blame] | 170 | &dev_attr_beiscsi_phys_port, |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 171 | NULL, |
| 172 | }; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 173 | |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 174 | static char const *cqe_desc[] = { |
| 175 | "RESERVED_DESC", |
| 176 | "SOL_CMD_COMPLETE", |
| 177 | "SOL_CMD_KILLED_DATA_DIGEST_ERR", |
| 178 | "CXN_KILLED_PDU_SIZE_EXCEEDS_DSL", |
| 179 | "CXN_KILLED_BURST_LEN_MISMATCH", |
| 180 | "CXN_KILLED_AHS_RCVD", |
| 181 | "CXN_KILLED_HDR_DIGEST_ERR", |
| 182 | "CXN_KILLED_UNKNOWN_HDR", |
| 183 | "CXN_KILLED_STALE_ITT_TTT_RCVD", |
| 184 | "CXN_KILLED_INVALID_ITT_TTT_RCVD", |
| 185 | "CXN_KILLED_RST_RCVD", |
| 186 | "CXN_KILLED_TIMED_OUT", |
| 187 | "CXN_KILLED_RST_SENT", |
| 188 | "CXN_KILLED_FIN_RCVD", |
| 189 | "CXN_KILLED_BAD_UNSOL_PDU_RCVD", |
| 190 | "CXN_KILLED_BAD_WRB_INDEX_ERROR", |
| 191 | "CXN_KILLED_OVER_RUN_RESIDUAL", |
| 192 | "CXN_KILLED_UNDER_RUN_RESIDUAL", |
| 193 | "CMD_KILLED_INVALID_STATSN_RCVD", |
| 194 | "CMD_KILLED_INVALID_R2T_RCVD", |
| 195 | "CMD_CXN_KILLED_LUN_INVALID", |
| 196 | "CMD_CXN_KILLED_ICD_INVALID", |
| 197 | "CMD_CXN_KILLED_ITT_INVALID", |
| 198 | "CMD_CXN_KILLED_SEQ_OUTOFORDER", |
| 199 | "CMD_CXN_KILLED_INVALID_DATASN_RCVD", |
| 200 | "CXN_INVALIDATE_NOTIFY", |
| 201 | "CXN_INVALIDATE_INDEX_NOTIFY", |
| 202 | "CMD_INVALIDATED_NOTIFY", |
| 203 | "UNSOL_HDR_NOTIFY", |
| 204 | "UNSOL_DATA_NOTIFY", |
| 205 | "UNSOL_DATA_DIGEST_ERROR_NOTIFY", |
| 206 | "DRIVERMSG_NOTIFY", |
| 207 | "CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN", |
| 208 | "SOL_CMD_KILLED_DIF_ERR", |
| 209 | "CXN_KILLED_SYN_RCVD", |
| 210 | "CXN_KILLED_IMM_DATA_RCVD" |
| 211 | }; |
| 212 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 213 | static int beiscsi_slave_configure(struct scsi_device *sdev) |
| 214 | { |
| 215 | blk_queue_max_segment_size(sdev->request_queue, 65536); |
| 216 | return 0; |
| 217 | } |
| 218 | |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 219 | static int beiscsi_eh_abort(struct scsi_cmnd *sc) |
| 220 | { |
| 221 | struct iscsi_cls_session *cls_session; |
| 222 | struct iscsi_task *aborted_task = (struct iscsi_task *)sc->SCp.ptr; |
| 223 | struct beiscsi_io_task *aborted_io_task; |
| 224 | struct iscsi_conn *conn; |
| 225 | struct beiscsi_conn *beiscsi_conn; |
| 226 | struct beiscsi_hba *phba; |
| 227 | struct iscsi_session *session; |
| 228 | struct invalidate_command_table *inv_tbl; |
Jayamohan Kallickal | 3cbb7a7 | 2010-07-22 04:27:47 +0530 | [diff] [blame] | 229 | struct be_dma_mem nonemb_cmd; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 230 | unsigned int cid, tag, num_invalidate; |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 231 | int rc; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 232 | |
| 233 | cls_session = starget_to_session(scsi_target(sc->device)); |
| 234 | session = cls_session->dd_data; |
| 235 | |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 236 | spin_lock_bh(&session->frwd_lock); |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 237 | if (!aborted_task || !aborted_task->sc) { |
| 238 | /* we raced */ |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 239 | spin_unlock_bh(&session->frwd_lock); |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 240 | return SUCCESS; |
| 241 | } |
| 242 | |
| 243 | aborted_io_task = aborted_task->dd_data; |
| 244 | if (!aborted_io_task->scsi_cmnd) { |
| 245 | /* raced or invalid command */ |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 246 | spin_unlock_bh(&session->frwd_lock); |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 247 | return SUCCESS; |
| 248 | } |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 249 | spin_unlock_bh(&session->frwd_lock); |
Jayamohan Kallickal | 7626c06 | 2013-09-28 15:35:57 -0700 | [diff] [blame] | 250 | /* Invalidate WRB Posted for this Task */ |
| 251 | AMAP_SET_BITS(struct amap_iscsi_wrb, invld, |
| 252 | aborted_io_task->pwrb_handle->pwrb, |
| 253 | 1); |
| 254 | |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 255 | conn = aborted_task->conn; |
| 256 | beiscsi_conn = conn->dd_data; |
| 257 | phba = beiscsi_conn->phba; |
| 258 | |
| 259 | /* invalidate iocb */ |
| 260 | cid = beiscsi_conn->beiscsi_conn_cid; |
| 261 | inv_tbl = phba->inv_tbl; |
| 262 | memset(inv_tbl, 0x0, sizeof(*inv_tbl)); |
| 263 | inv_tbl->cid = cid; |
| 264 | inv_tbl->icd = aborted_io_task->psgl_handle->sgl_index; |
| 265 | num_invalidate = 1; |
Jayamohan Kallickal | 3cbb7a7 | 2010-07-22 04:27:47 +0530 | [diff] [blame] | 266 | nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev, |
| 267 | sizeof(struct invalidate_commands_params_in), |
| 268 | &nonemb_cmd.dma); |
| 269 | if (nonemb_cmd.va == NULL) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 270 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH, |
| 271 | "BM_%d : Failed to allocate memory for" |
| 272 | "mgmt_invalidate_icds\n"); |
Jayamohan Kallickal | 3cbb7a7 | 2010-07-22 04:27:47 +0530 | [diff] [blame] | 273 | return FAILED; |
| 274 | } |
| 275 | nonemb_cmd.size = sizeof(struct invalidate_commands_params_in); |
| 276 | |
| 277 | tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate, |
| 278 | cid, &nonemb_cmd); |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 279 | if (!tag) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 280 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH, |
| 281 | "BM_%d : mgmt_invalidate_icds could not be" |
| 282 | "submitted\n"); |
Jayamohan Kallickal | 3cbb7a7 | 2010-07-22 04:27:47 +0530 | [diff] [blame] | 283 | pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size, |
| 284 | nonemb_cmd.va, nonemb_cmd.dma); |
| 285 | |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 286 | return FAILED; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 287 | } |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 288 | |
Jitendra Bhivare | 8884033 | 2016-02-04 15:49:12 +0530 | [diff] [blame] | 289 | rc = beiscsi_mccq_compl_wait(phba, tag, NULL, &nonemb_cmd); |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 290 | if (rc != -EBUSY) |
| 291 | pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size, |
| 292 | nonemb_cmd.va, nonemb_cmd.dma); |
| 293 | |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 294 | return iscsi_eh_abort(sc); |
| 295 | } |
| 296 | |
| 297 | static int beiscsi_eh_device_reset(struct scsi_cmnd *sc) |
| 298 | { |
| 299 | struct iscsi_task *abrt_task; |
| 300 | struct beiscsi_io_task *abrt_io_task; |
| 301 | struct iscsi_conn *conn; |
| 302 | struct beiscsi_conn *beiscsi_conn; |
| 303 | struct beiscsi_hba *phba; |
| 304 | struct iscsi_session *session; |
| 305 | struct iscsi_cls_session *cls_session; |
| 306 | struct invalidate_command_table *inv_tbl; |
Jayamohan Kallickal | 3cbb7a7 | 2010-07-22 04:27:47 +0530 | [diff] [blame] | 307 | struct be_dma_mem nonemb_cmd; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 308 | unsigned int cid, tag, i, num_invalidate; |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 309 | int rc; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 310 | |
| 311 | /* invalidate iocbs */ |
| 312 | cls_session = starget_to_session(scsi_target(sc->device)); |
| 313 | session = cls_session->dd_data; |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 314 | spin_lock_bh(&session->frwd_lock); |
Jayamohan Kallickal | db7f770 | 2012-04-03 23:41:43 -0500 | [diff] [blame] | 315 | if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN) { |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 316 | spin_unlock_bh(&session->frwd_lock); |
Jayamohan Kallickal | db7f770 | 2012-04-03 23:41:43 -0500 | [diff] [blame] | 317 | return FAILED; |
| 318 | } |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 319 | conn = session->leadconn; |
| 320 | beiscsi_conn = conn->dd_data; |
| 321 | phba = beiscsi_conn->phba; |
| 322 | cid = beiscsi_conn->beiscsi_conn_cid; |
| 323 | inv_tbl = phba->inv_tbl; |
| 324 | memset(inv_tbl, 0x0, sizeof(*inv_tbl) * BE2_CMDS_PER_CXN); |
| 325 | num_invalidate = 0; |
| 326 | for (i = 0; i < conn->session->cmds_max; i++) { |
| 327 | abrt_task = conn->session->cmds[i]; |
| 328 | abrt_io_task = abrt_task->dd_data; |
| 329 | if (!abrt_task->sc || abrt_task->state == ISCSI_TASK_FREE) |
| 330 | continue; |
| 331 | |
Mike Christie | 126e964 | 2013-12-19 01:16:21 -0600 | [diff] [blame] | 332 | if (sc->device->lun != abrt_task->sc->device->lun) |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 333 | continue; |
| 334 | |
Jayamohan Kallickal | 7626c06 | 2013-09-28 15:35:57 -0700 | [diff] [blame] | 335 | /* Invalidate WRB Posted for this Task */ |
| 336 | AMAP_SET_BITS(struct amap_iscsi_wrb, invld, |
| 337 | abrt_io_task->pwrb_handle->pwrb, |
| 338 | 1); |
| 339 | |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 340 | inv_tbl->cid = cid; |
| 341 | inv_tbl->icd = abrt_io_task->psgl_handle->sgl_index; |
| 342 | num_invalidate++; |
| 343 | inv_tbl++; |
| 344 | } |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 345 | spin_unlock_bh(&session->frwd_lock); |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 346 | inv_tbl = phba->inv_tbl; |
| 347 | |
Jayamohan Kallickal | 3cbb7a7 | 2010-07-22 04:27:47 +0530 | [diff] [blame] | 348 | nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev, |
| 349 | sizeof(struct invalidate_commands_params_in), |
| 350 | &nonemb_cmd.dma); |
| 351 | if (nonemb_cmd.va == NULL) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 352 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH, |
| 353 | "BM_%d : Failed to allocate memory for" |
| 354 | "mgmt_invalidate_icds\n"); |
Jayamohan Kallickal | 3cbb7a7 | 2010-07-22 04:27:47 +0530 | [diff] [blame] | 355 | return FAILED; |
| 356 | } |
| 357 | nonemb_cmd.size = sizeof(struct invalidate_commands_params_in); |
| 358 | memset(nonemb_cmd.va, 0, nonemb_cmd.size); |
| 359 | tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate, |
| 360 | cid, &nonemb_cmd); |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 361 | if (!tag) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 362 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH, |
| 363 | "BM_%d : mgmt_invalidate_icds could not be" |
| 364 | " submitted\n"); |
Jayamohan Kallickal | 3cbb7a7 | 2010-07-22 04:27:47 +0530 | [diff] [blame] | 365 | pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size, |
| 366 | nonemb_cmd.va, nonemb_cmd.dma); |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 367 | return FAILED; |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 368 | } |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 369 | |
Jitendra Bhivare | 8884033 | 2016-02-04 15:49:12 +0530 | [diff] [blame] | 370 | rc = beiscsi_mccq_compl_wait(phba, tag, NULL, &nonemb_cmd); |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 371 | if (rc != -EBUSY) |
| 372 | pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size, |
| 373 | nonemb_cmd.va, nonemb_cmd.dma); |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 374 | return iscsi_eh_device_reset(sc); |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 375 | } |
| 376 | |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 377 | static ssize_t beiscsi_show_boot_tgt_info(void *data, int type, char *buf) |
| 378 | { |
| 379 | struct beiscsi_hba *phba = data; |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 380 | struct mgmt_session_info *boot_sess = &phba->boot_sess; |
| 381 | struct mgmt_conn_info *boot_conn = &boot_sess->conn_list[0]; |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 382 | char *str = buf; |
Jitendra Bhivare | c5bf888 | 2016-08-19 15:20:05 +0530 | [diff] [blame] | 383 | int rc = -EPERM; |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 384 | |
| 385 | switch (type) { |
| 386 | case ISCSI_BOOT_TGT_NAME: |
| 387 | rc = sprintf(buf, "%.*s\n", |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 388 | (int)strlen(boot_sess->target_name), |
| 389 | (char *)&boot_sess->target_name); |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 390 | break; |
| 391 | case ISCSI_BOOT_TGT_IP_ADDR: |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 392 | if (boot_conn->dest_ipaddr.ip_type == 0x1) |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 393 | rc = sprintf(buf, "%pI4\n", |
Mike Christie | 0e43895 | 2012-04-03 23:41:51 -0500 | [diff] [blame] | 394 | (char *)&boot_conn->dest_ipaddr.addr); |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 395 | else |
| 396 | rc = sprintf(str, "%pI6\n", |
Mike Christie | 0e43895 | 2012-04-03 23:41:51 -0500 | [diff] [blame] | 397 | (char *)&boot_conn->dest_ipaddr.addr); |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 398 | break; |
| 399 | case ISCSI_BOOT_TGT_PORT: |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 400 | rc = sprintf(str, "%d\n", boot_conn->dest_port); |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 401 | break; |
| 402 | |
| 403 | case ISCSI_BOOT_TGT_CHAP_NAME: |
| 404 | rc = sprintf(str, "%.*s\n", |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 405 | boot_conn->negotiated_login_options.auth_data.chap. |
| 406 | target_chap_name_length, |
| 407 | (char *)&boot_conn->negotiated_login_options. |
| 408 | auth_data.chap.target_chap_name); |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 409 | break; |
| 410 | case ISCSI_BOOT_TGT_CHAP_SECRET: |
| 411 | rc = sprintf(str, "%.*s\n", |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 412 | boot_conn->negotiated_login_options.auth_data.chap. |
| 413 | target_secret_length, |
| 414 | (char *)&boot_conn->negotiated_login_options. |
| 415 | auth_data.chap.target_secret); |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 416 | break; |
| 417 | case ISCSI_BOOT_TGT_REV_CHAP_NAME: |
| 418 | rc = sprintf(str, "%.*s\n", |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 419 | boot_conn->negotiated_login_options.auth_data.chap. |
| 420 | intr_chap_name_length, |
| 421 | (char *)&boot_conn->negotiated_login_options. |
| 422 | auth_data.chap.intr_chap_name); |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 423 | break; |
| 424 | case ISCSI_BOOT_TGT_REV_CHAP_SECRET: |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 425 | rc = sprintf(str, "%.*s\n", |
| 426 | boot_conn->negotiated_login_options.auth_data.chap. |
| 427 | intr_secret_length, |
| 428 | (char *)&boot_conn->negotiated_login_options. |
| 429 | auth_data.chap.intr_secret); |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 430 | break; |
| 431 | case ISCSI_BOOT_TGT_FLAGS: |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 432 | rc = sprintf(str, "2\n"); |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 433 | break; |
| 434 | case ISCSI_BOOT_TGT_NIC_ASSOC: |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 435 | rc = sprintf(str, "0\n"); |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 436 | break; |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 437 | } |
| 438 | return rc; |
| 439 | } |
| 440 | |
| 441 | static ssize_t beiscsi_show_boot_ini_info(void *data, int type, char *buf) |
| 442 | { |
| 443 | struct beiscsi_hba *phba = data; |
| 444 | char *str = buf; |
Jitendra Bhivare | c5bf888 | 2016-08-19 15:20:05 +0530 | [diff] [blame] | 445 | int rc = -EPERM; |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 446 | |
| 447 | switch (type) { |
| 448 | case ISCSI_BOOT_INI_INITIATOR_NAME: |
| 449 | rc = sprintf(str, "%s\n", phba->boot_sess.initiator_iscsiname); |
| 450 | break; |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 451 | } |
| 452 | return rc; |
| 453 | } |
| 454 | |
| 455 | static ssize_t beiscsi_show_boot_eth_info(void *data, int type, char *buf) |
| 456 | { |
| 457 | struct beiscsi_hba *phba = data; |
| 458 | char *str = buf; |
Jitendra Bhivare | c5bf888 | 2016-08-19 15:20:05 +0530 | [diff] [blame] | 459 | int rc = -EPERM; |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 460 | |
| 461 | switch (type) { |
| 462 | case ISCSI_BOOT_ETH_FLAGS: |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 463 | rc = sprintf(str, "2\n"); |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 464 | break; |
| 465 | case ISCSI_BOOT_ETH_INDEX: |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 466 | rc = sprintf(str, "0\n"); |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 467 | break; |
| 468 | case ISCSI_BOOT_ETH_MAC: |
Mike Christie | 0e43895 | 2012-04-03 23:41:51 -0500 | [diff] [blame] | 469 | rc = beiscsi_get_macaddr(str, phba); |
| 470 | break; |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 471 | } |
| 472 | return rc; |
| 473 | } |
| 474 | |
| 475 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 476 | static umode_t beiscsi_tgt_get_attr_visibility(void *data, int type) |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 477 | { |
Jitendra Bhivare | c5bf888 | 2016-08-19 15:20:05 +0530 | [diff] [blame] | 478 | umode_t rc = 0; |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 479 | |
| 480 | switch (type) { |
| 481 | case ISCSI_BOOT_TGT_NAME: |
| 482 | case ISCSI_BOOT_TGT_IP_ADDR: |
| 483 | case ISCSI_BOOT_TGT_PORT: |
| 484 | case ISCSI_BOOT_TGT_CHAP_NAME: |
| 485 | case ISCSI_BOOT_TGT_CHAP_SECRET: |
| 486 | case ISCSI_BOOT_TGT_REV_CHAP_NAME: |
| 487 | case ISCSI_BOOT_TGT_REV_CHAP_SECRET: |
| 488 | case ISCSI_BOOT_TGT_NIC_ASSOC: |
| 489 | case ISCSI_BOOT_TGT_FLAGS: |
| 490 | rc = S_IRUGO; |
| 491 | break; |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 492 | } |
| 493 | return rc; |
| 494 | } |
| 495 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 496 | static umode_t beiscsi_ini_get_attr_visibility(void *data, int type) |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 497 | { |
Jitendra Bhivare | c5bf888 | 2016-08-19 15:20:05 +0530 | [diff] [blame] | 498 | umode_t rc = 0; |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 499 | |
| 500 | switch (type) { |
| 501 | case ISCSI_BOOT_INI_INITIATOR_NAME: |
| 502 | rc = S_IRUGO; |
| 503 | break; |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 504 | } |
| 505 | return rc; |
| 506 | } |
| 507 | |
| 508 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 509 | static umode_t beiscsi_eth_get_attr_visibility(void *data, int type) |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 510 | { |
Jitendra Bhivare | c5bf888 | 2016-08-19 15:20:05 +0530 | [diff] [blame] | 511 | umode_t rc = 0; |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 512 | |
| 513 | switch (type) { |
| 514 | case ISCSI_BOOT_ETH_FLAGS: |
| 515 | case ISCSI_BOOT_ETH_MAC: |
| 516 | case ISCSI_BOOT_ETH_INDEX: |
| 517 | rc = S_IRUGO; |
| 518 | break; |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 519 | } |
| 520 | return rc; |
| 521 | } |
| 522 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 523 | /*------------------- PCI Driver operations and data ----------------- */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 524 | static const struct pci_device_id beiscsi_pci_id_table[] = { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 525 | { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) }, |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 526 | { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) }, |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 527 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) }, |
| 528 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) }, |
| 529 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID3) }, |
John Soni Jose | 139a1b1 | 2012-10-20 04:43:20 +0530 | [diff] [blame] | 530 | { PCI_DEVICE(ELX_VENDOR_ID, OC_SKH_ID1) }, |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 531 | { 0 } |
| 532 | }; |
| 533 | MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table); |
| 534 | |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 535 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 536 | static struct scsi_host_template beiscsi_sht = { |
| 537 | .module = THIS_MODULE, |
Ketan Mukadam | c4f39bd | 2015-07-04 04:12:33 +0530 | [diff] [blame] | 538 | .name = "Emulex 10Gbe open-iscsi Initiator Driver", |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 539 | .proc_name = DRV_NAME, |
| 540 | .queuecommand = iscsi_queuecommand, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 541 | .change_queue_depth = scsi_change_queue_depth, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 542 | .slave_configure = beiscsi_slave_configure, |
| 543 | .target_alloc = iscsi_target_alloc, |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 544 | .eh_abort_handler = beiscsi_eh_abort, |
| 545 | .eh_device_reset_handler = beiscsi_eh_device_reset, |
Jayamohan Kallickal | 309ce15 | 2010-02-20 08:02:10 +0530 | [diff] [blame] | 546 | .eh_target_reset_handler = iscsi_eh_session_reset, |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 547 | .shost_attrs = beiscsi_attrs, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 548 | .sg_tablesize = BEISCSI_SGLIST_ELEMENTS, |
| 549 | .can_queue = BE2_IO_DEPTH, |
| 550 | .this_id = -1, |
| 551 | .max_sectors = BEISCSI_MAX_SECTORS, |
| 552 | .cmd_per_lun = BEISCSI_CMD_PER_LUN, |
| 553 | .use_clustering = ENABLE_CLUSTERING, |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 554 | .vendor_id = SCSI_NL_VID_TYPE_PCI | BE_VENDOR_ID, |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 555 | .track_queue_depth = 1, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 556 | }; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 557 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 558 | static struct scsi_transport_template *beiscsi_scsi_transport; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 559 | |
| 560 | static struct beiscsi_hba *beiscsi_hba_alloc(struct pci_dev *pcidev) |
| 561 | { |
| 562 | struct beiscsi_hba *phba; |
| 563 | struct Scsi_Host *shost; |
| 564 | |
| 565 | shost = iscsi_host_alloc(&beiscsi_sht, sizeof(*phba), 0); |
| 566 | if (!shost) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 567 | dev_err(&pcidev->dev, |
| 568 | "beiscsi_hba_alloc - iscsi_host_alloc failed\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 569 | return NULL; |
| 570 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 571 | shost->max_id = BE2_MAX_SESSIONS; |
| 572 | shost->max_channel = 0; |
| 573 | shost->max_cmd_len = BEISCSI_MAX_CMD_LEN; |
| 574 | shost->max_lun = BEISCSI_NUM_MAX_LUN; |
| 575 | shost->transportt = beiscsi_scsi_transport; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 576 | phba = iscsi_host_priv(shost); |
| 577 | memset(phba, 0, sizeof(*phba)); |
| 578 | phba->shost = shost; |
| 579 | phba->pcidev = pci_dev_get(pcidev); |
Jayamohan Kallickal | 2807afb | 2010-01-05 05:07:49 +0530 | [diff] [blame] | 580 | pci_set_drvdata(pcidev, phba); |
Mike Christie | 0e43895 | 2012-04-03 23:41:51 -0500 | [diff] [blame] | 581 | phba->interface_handle = 0xFFFFFFFF; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 582 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 583 | return phba; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | static void beiscsi_unmap_pci_function(struct beiscsi_hba *phba) |
| 587 | { |
| 588 | if (phba->csr_va) { |
| 589 | iounmap(phba->csr_va); |
| 590 | phba->csr_va = NULL; |
| 591 | } |
| 592 | if (phba->db_va) { |
| 593 | iounmap(phba->db_va); |
| 594 | phba->db_va = NULL; |
| 595 | } |
| 596 | if (phba->pci_va) { |
| 597 | iounmap(phba->pci_va); |
| 598 | phba->pci_va = NULL; |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | static int beiscsi_map_pci_bars(struct beiscsi_hba *phba, |
| 603 | struct pci_dev *pcidev) |
| 604 | { |
| 605 | u8 __iomem *addr; |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 606 | int pcicfg_reg; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 607 | |
| 608 | addr = ioremap_nocache(pci_resource_start(pcidev, 2), |
| 609 | pci_resource_len(pcidev, 2)); |
| 610 | if (addr == NULL) |
| 611 | return -ENOMEM; |
| 612 | phba->ctrl.csr = addr; |
| 613 | phba->csr_va = addr; |
| 614 | phba->csr_pa.u.a64.address = pci_resource_start(pcidev, 2); |
| 615 | |
| 616 | addr = ioremap_nocache(pci_resource_start(pcidev, 4), 128 * 1024); |
| 617 | if (addr == NULL) |
| 618 | goto pci_map_err; |
| 619 | phba->ctrl.db = addr; |
| 620 | phba->db_va = addr; |
| 621 | phba->db_pa.u.a64.address = pci_resource_start(pcidev, 4); |
| 622 | |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 623 | if (phba->generation == BE_GEN2) |
| 624 | pcicfg_reg = 1; |
| 625 | else |
| 626 | pcicfg_reg = 0; |
| 627 | |
| 628 | addr = ioremap_nocache(pci_resource_start(pcidev, pcicfg_reg), |
| 629 | pci_resource_len(pcidev, pcicfg_reg)); |
| 630 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 631 | if (addr == NULL) |
| 632 | goto pci_map_err; |
| 633 | phba->ctrl.pcicfg = addr; |
| 634 | phba->pci_va = addr; |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 635 | phba->pci_pa.u.a64.address = pci_resource_start(pcidev, pcicfg_reg); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 636 | return 0; |
| 637 | |
| 638 | pci_map_err: |
| 639 | beiscsi_unmap_pci_function(phba); |
| 640 | return -ENOMEM; |
| 641 | } |
| 642 | |
| 643 | static int beiscsi_enable_pci(struct pci_dev *pcidev) |
| 644 | { |
| 645 | int ret; |
| 646 | |
| 647 | ret = pci_enable_device(pcidev); |
| 648 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 649 | dev_err(&pcidev->dev, |
| 650 | "beiscsi_enable_pci - enable device failed\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 651 | return ret; |
| 652 | } |
| 653 | |
John Soni Jose | e307f3a | 2015-04-25 08:17:19 +0530 | [diff] [blame] | 654 | ret = pci_request_regions(pcidev, DRV_NAME); |
| 655 | if (ret) { |
| 656 | dev_err(&pcidev->dev, |
| 657 | "beiscsi_enable_pci - request region failed\n"); |
| 658 | goto pci_dev_disable; |
| 659 | } |
| 660 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 661 | pci_set_master(pcidev); |
Jayamohan Kallickal | 6c57625b | 2014-01-29 02:16:45 -0500 | [diff] [blame] | 662 | ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(64)); |
| 663 | if (ret) { |
| 664 | ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(32)); |
| 665 | if (ret) { |
| 666 | dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n"); |
John Soni Jose | e307f3a | 2015-04-25 08:17:19 +0530 | [diff] [blame] | 667 | goto pci_region_release; |
Jayamohan Kallickal | 6c57625b | 2014-01-29 02:16:45 -0500 | [diff] [blame] | 668 | } else { |
| 669 | ret = pci_set_consistent_dma_mask(pcidev, |
| 670 | DMA_BIT_MASK(32)); |
| 671 | } |
| 672 | } else { |
| 673 | ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 674 | if (ret) { |
| 675 | dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n"); |
John Soni Jose | e307f3a | 2015-04-25 08:17:19 +0530 | [diff] [blame] | 676 | goto pci_region_release; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 677 | } |
| 678 | } |
| 679 | return 0; |
John Soni Jose | e307f3a | 2015-04-25 08:17:19 +0530 | [diff] [blame] | 680 | |
| 681 | pci_region_release: |
| 682 | pci_release_regions(pcidev); |
| 683 | pci_dev_disable: |
| 684 | pci_disable_device(pcidev); |
| 685 | |
| 686 | return ret; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | static int be_ctrl_init(struct beiscsi_hba *phba, struct pci_dev *pdev) |
| 690 | { |
| 691 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 692 | struct be_dma_mem *mbox_mem_alloc = &ctrl->mbox_mem_alloced; |
| 693 | struct be_dma_mem *mbox_mem_align = &ctrl->mbox_mem; |
| 694 | int status = 0; |
| 695 | |
| 696 | ctrl->pdev = pdev; |
| 697 | status = beiscsi_map_pci_bars(phba, pdev); |
| 698 | if (status) |
| 699 | return status; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 700 | mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16; |
| 701 | mbox_mem_alloc->va = pci_alloc_consistent(pdev, |
| 702 | mbox_mem_alloc->size, |
| 703 | &mbox_mem_alloc->dma); |
| 704 | if (!mbox_mem_alloc->va) { |
| 705 | beiscsi_unmap_pci_function(phba); |
Jayamohan Kallickal | a49e06d | 2012-04-03 23:41:44 -0500 | [diff] [blame] | 706 | return -ENOMEM; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | mbox_mem_align->size = sizeof(struct be_mcc_mailbox); |
| 710 | mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16); |
| 711 | mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16); |
| 712 | memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox)); |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 713 | mutex_init(&ctrl->mbox_lock); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 714 | spin_lock_init(&phba->ctrl.mcc_lock); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 715 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 716 | return status; |
| 717 | } |
| 718 | |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 719 | /** |
| 720 | * beiscsi_get_params()- Set the config paramters |
| 721 | * @phba: ptr device priv structure |
| 722 | **/ |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 723 | static void beiscsi_get_params(struct beiscsi_hba *phba) |
| 724 | { |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 725 | uint32_t total_cid_count = 0; |
| 726 | uint32_t total_icd_count = 0; |
| 727 | uint8_t ulp_num = 0; |
| 728 | |
| 729 | total_cid_count = BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP0) + |
| 730 | BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP1); |
| 731 | |
Jayamohan Kallickal | cf987b7 | 2013-09-28 15:35:59 -0700 | [diff] [blame] | 732 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 733 | uint32_t align_mask = 0; |
| 734 | uint32_t icd_post_per_page = 0; |
| 735 | uint32_t icd_count_unavailable = 0; |
| 736 | uint32_t icd_start = 0, icd_count = 0; |
| 737 | uint32_t icd_start_align = 0, icd_count_align = 0; |
| 738 | |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 739 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
Jayamohan Kallickal | cf987b7 | 2013-09-28 15:35:59 -0700 | [diff] [blame] | 740 | icd_start = phba->fw_config.iscsi_icd_start[ulp_num]; |
| 741 | icd_count = phba->fw_config.iscsi_icd_count[ulp_num]; |
| 742 | |
| 743 | /* Get ICD count that can be posted on each page */ |
| 744 | icd_post_per_page = (PAGE_SIZE / (BE2_SGE * |
| 745 | sizeof(struct iscsi_sge))); |
| 746 | align_mask = (icd_post_per_page - 1); |
| 747 | |
| 748 | /* Check if icd_start is aligned ICD per page posting */ |
| 749 | if (icd_start % icd_post_per_page) { |
| 750 | icd_start_align = ((icd_start + |
| 751 | icd_post_per_page) & |
| 752 | ~(align_mask)); |
| 753 | phba->fw_config. |
| 754 | iscsi_icd_start[ulp_num] = |
| 755 | icd_start_align; |
| 756 | } |
| 757 | |
| 758 | icd_count_align = (icd_count & ~align_mask); |
| 759 | |
| 760 | /* ICD discarded in the process of alignment */ |
| 761 | if (icd_start_align) |
| 762 | icd_count_unavailable = ((icd_start_align - |
| 763 | icd_start) + |
| 764 | (icd_count - |
| 765 | icd_count_align)); |
| 766 | |
| 767 | /* Updated ICD count available */ |
| 768 | phba->fw_config.iscsi_icd_count[ulp_num] = (icd_count - |
| 769 | icd_count_unavailable); |
| 770 | |
| 771 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 772 | "BM_%d : Aligned ICD values\n" |
| 773 | "\t ICD Start : %d\n" |
| 774 | "\t ICD Count : %d\n" |
| 775 | "\t ICD Discarded : %d\n", |
| 776 | phba->fw_config. |
| 777 | iscsi_icd_start[ulp_num], |
| 778 | phba->fw_config. |
| 779 | iscsi_icd_count[ulp_num], |
| 780 | icd_count_unavailable); |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 781 | break; |
| 782 | } |
Jayamohan Kallickal | cf987b7 | 2013-09-28 15:35:59 -0700 | [diff] [blame] | 783 | } |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 784 | |
Jayamohan Kallickal | cf987b7 | 2013-09-28 15:35:59 -0700 | [diff] [blame] | 785 | total_icd_count = phba->fw_config.iscsi_icd_count[ulp_num]; |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 786 | phba->params.ios_per_ctrl = (total_icd_count - |
| 787 | (total_cid_count + |
| 788 | BE2_TMFS + BE2_NOPOUT_REQ)); |
| 789 | phba->params.cxns_per_ctrl = total_cid_count; |
| 790 | phba->params.asyncpdus_per_ctrl = total_cid_count; |
| 791 | phba->params.icds_per_ctrl = total_icd_count; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 792 | phba->params.num_sge_per_io = BE2_SGE; |
| 793 | phba->params.defpdu_hdr_sz = BE2_DEFPDU_HDR_SZ; |
| 794 | phba->params.defpdu_data_sz = BE2_DEFPDU_DATA_SZ; |
| 795 | phba->params.eq_timer = 64; |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 796 | phba->params.num_eq_entries = 1024; |
| 797 | phba->params.num_cq_entries = 1024; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 798 | phba->params.wrbs_per_cxn = 256; |
| 799 | } |
| 800 | |
| 801 | static void hwi_ring_eq_db(struct beiscsi_hba *phba, |
| 802 | unsigned int id, unsigned int clr_interrupt, |
| 803 | unsigned int num_processed, |
| 804 | unsigned char rearm, unsigned char event) |
| 805 | { |
| 806 | u32 val = 0; |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 807 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 808 | if (rearm) |
| 809 | val |= 1 << DB_EQ_REARM_SHIFT; |
| 810 | if (clr_interrupt) |
| 811 | val |= 1 << DB_EQ_CLR_SHIFT; |
| 812 | if (event) |
| 813 | val |= 1 << DB_EQ_EVNT_SHIFT; |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 814 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 815 | val |= num_processed << DB_EQ_NUM_POPPED_SHIFT; |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 816 | /* Setting lower order EQ_ID Bits */ |
| 817 | val |= (id & DB_EQ_RING_ID_LOW_MASK); |
| 818 | |
| 819 | /* Setting Higher order EQ_ID Bits */ |
| 820 | val |= (((id >> DB_EQ_HIGH_FEILD_SHIFT) & |
| 821 | DB_EQ_RING_ID_HIGH_MASK) |
| 822 | << DB_EQ_HIGH_SET_SHIFT); |
| 823 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 824 | iowrite32(val, phba->db_va + DB_EQ_OFFSET); |
| 825 | } |
| 826 | |
| 827 | /** |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 828 | * be_isr_mcc - The isr routine of the driver. |
| 829 | * @irq: Not used |
| 830 | * @dev_id: Pointer to host adapter structure |
| 831 | */ |
| 832 | static irqreturn_t be_isr_mcc(int irq, void *dev_id) |
| 833 | { |
| 834 | struct beiscsi_hba *phba; |
| 835 | struct be_eq_entry *eqe = NULL; |
| 836 | struct be_queue_info *eq; |
| 837 | struct be_queue_info *mcc; |
| 838 | unsigned int num_eq_processed; |
| 839 | struct be_eq_obj *pbe_eq; |
| 840 | unsigned long flags; |
| 841 | |
| 842 | pbe_eq = dev_id; |
| 843 | eq = &pbe_eq->q; |
| 844 | phba = pbe_eq->phba; |
| 845 | mcc = &phba->ctrl.mcc_obj.cq; |
| 846 | eqe = queue_tail_node(eq); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 847 | |
| 848 | num_eq_processed = 0; |
| 849 | |
| 850 | while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32] |
| 851 | & EQE_VALID_MASK) { |
| 852 | if (((eqe->dw[offsetof(struct amap_eq_entry, |
| 853 | resource_id) / 32] & |
| 854 | EQE_RESID_MASK) >> 16) == mcc->id) { |
| 855 | spin_lock_irqsave(&phba->isr_lock, flags); |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 856 | pbe_eq->todo_mcc_cq = true; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 857 | spin_unlock_irqrestore(&phba->isr_lock, flags); |
| 858 | } |
| 859 | AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0); |
| 860 | queue_tail_inc(eq); |
| 861 | eqe = queue_tail_node(eq); |
| 862 | num_eq_processed++; |
| 863 | } |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 864 | if (pbe_eq->todo_mcc_cq) |
| 865 | queue_work(phba->wq, &pbe_eq->work_cqs); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 866 | if (num_eq_processed) |
| 867 | hwi_ring_eq_db(phba, eq->id, 1, num_eq_processed, 1, 1); |
| 868 | |
| 869 | return IRQ_HANDLED; |
| 870 | } |
| 871 | |
| 872 | /** |
| 873 | * be_isr_msix - The isr routine of the driver. |
| 874 | * @irq: Not used |
| 875 | * @dev_id: Pointer to host adapter structure |
| 876 | */ |
| 877 | static irqreturn_t be_isr_msix(int irq, void *dev_id) |
| 878 | { |
| 879 | struct beiscsi_hba *phba; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 880 | struct be_queue_info *eq; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 881 | struct be_eq_obj *pbe_eq; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 882 | |
| 883 | pbe_eq = dev_id; |
| 884 | eq = &pbe_eq->q; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 885 | |
| 886 | phba = pbe_eq->phba; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 887 | |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 888 | /* disable interrupt till iopoll completes */ |
| 889 | hwi_ring_eq_db(phba, eq->id, 1, 0, 0, 1); |
| 890 | irq_poll_sched(&pbe_eq->iopoll); |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 891 | |
| 892 | return IRQ_HANDLED; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | /** |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 896 | * be_isr - The isr routine of the driver. |
| 897 | * @irq: Not used |
| 898 | * @dev_id: Pointer to host adapter structure |
| 899 | */ |
| 900 | static irqreturn_t be_isr(int irq, void *dev_id) |
| 901 | { |
| 902 | struct beiscsi_hba *phba; |
| 903 | struct hwi_controller *phwi_ctrlr; |
| 904 | struct hwi_context_memory *phwi_context; |
| 905 | struct be_eq_entry *eqe = NULL; |
| 906 | struct be_queue_info *eq; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 907 | struct be_queue_info *mcc; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 908 | unsigned long flags, index; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 909 | unsigned int num_mcceq_processed, num_ioeq_processed; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 910 | struct be_ctrl_info *ctrl; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 911 | struct be_eq_obj *pbe_eq; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 912 | int isr; |
| 913 | |
| 914 | phba = dev_id; |
Justin P. Mattock | 6eab04a | 2011-04-08 19:49:08 -0700 | [diff] [blame] | 915 | ctrl = &phba->ctrl; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 916 | isr = ioread32(ctrl->csr + CEV_ISR0_OFFSET + |
| 917 | (PCI_FUNC(ctrl->pdev->devfn) * CEV_ISR_SIZE)); |
| 918 | if (!isr) |
| 919 | return IRQ_NONE; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 920 | |
| 921 | phwi_ctrlr = phba->phwi_ctrlr; |
| 922 | phwi_context = phwi_ctrlr->phwi_ctxt; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 923 | pbe_eq = &phwi_context->be_eq[0]; |
| 924 | |
| 925 | eq = &phwi_context->be_eq[0].q; |
| 926 | mcc = &phba->ctrl.mcc_obj.cq; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 927 | index = 0; |
| 928 | eqe = queue_tail_node(eq); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 929 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 930 | num_ioeq_processed = 0; |
| 931 | num_mcceq_processed = 0; |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 932 | while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32] |
| 933 | & EQE_VALID_MASK) { |
| 934 | if (((eqe->dw[offsetof(struct amap_eq_entry, |
| 935 | resource_id) / 32] & |
| 936 | EQE_RESID_MASK) >> 16) == mcc->id) { |
| 937 | spin_lock_irqsave(&phba->isr_lock, flags); |
| 938 | pbe_eq->todo_mcc_cq = true; |
| 939 | spin_unlock_irqrestore(&phba->isr_lock, flags); |
| 940 | num_mcceq_processed++; |
| 941 | } else { |
Christoph Hellwig | ea51190 | 2015-12-07 06:41:11 -0800 | [diff] [blame] | 942 | irq_poll_sched(&pbe_eq->iopoll); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 943 | num_ioeq_processed++; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 944 | } |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 945 | AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0); |
| 946 | queue_tail_inc(eq); |
| 947 | eqe = queue_tail_node(eq); |
| 948 | } |
| 949 | if (num_ioeq_processed || num_mcceq_processed) { |
| 950 | if (pbe_eq->todo_mcc_cq) |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 951 | queue_work(phba->wq, &pbe_eq->work_cqs); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 952 | |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 953 | if ((num_mcceq_processed) && (!num_ioeq_processed)) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 954 | hwi_ring_eq_db(phba, eq->id, 0, |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 955 | (num_ioeq_processed + |
| 956 | num_mcceq_processed) , 1, 1); |
| 957 | else |
| 958 | hwi_ring_eq_db(phba, eq->id, 0, |
| 959 | (num_ioeq_processed + |
| 960 | num_mcceq_processed), 0, 1); |
| 961 | |
| 962 | return IRQ_HANDLED; |
| 963 | } else |
| 964 | return IRQ_NONE; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 965 | } |
| 966 | |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 967 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 968 | static int beiscsi_init_irqs(struct beiscsi_hba *phba) |
| 969 | { |
| 970 | struct pci_dev *pcidev = phba->pcidev; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 971 | struct hwi_controller *phwi_ctrlr; |
| 972 | struct hwi_context_memory *phwi_context; |
Jayamohan Kallickal | 4f5af07 | 2010-07-22 04:23:55 +0530 | [diff] [blame] | 973 | int ret, msix_vec, i, j; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 974 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 975 | phwi_ctrlr = phba->phwi_ctrlr; |
| 976 | phwi_context = phwi_ctrlr->phwi_ctxt; |
| 977 | |
| 978 | if (phba->msix_enabled) { |
| 979 | for (i = 0; i < phba->num_cpus; i++) { |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 980 | phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME, |
| 981 | GFP_KERNEL); |
| 982 | if (!phba->msi_name[i]) { |
| 983 | ret = -ENOMEM; |
| 984 | goto free_msix_irqs; |
| 985 | } |
| 986 | |
| 987 | sprintf(phba->msi_name[i], "beiscsi_%02x_%02x", |
| 988 | phba->shost->host_no, i); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 989 | msix_vec = phba->msix_entries[i].vector; |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 990 | ret = request_irq(msix_vec, be_isr_msix, 0, |
| 991 | phba->msi_name[i], |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 992 | &phwi_context->be_eq[i]); |
Jayamohan Kallickal | 4f5af07 | 2010-07-22 04:23:55 +0530 | [diff] [blame] | 993 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 994 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 995 | "BM_%d : beiscsi_init_irqs-Failed to" |
| 996 | "register msix for i = %d\n", |
| 997 | i); |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 998 | kfree(phba->msi_name[i]); |
Jayamohan Kallickal | 4f5af07 | 2010-07-22 04:23:55 +0530 | [diff] [blame] | 999 | goto free_msix_irqs; |
| 1000 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1001 | } |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 1002 | phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME, GFP_KERNEL); |
| 1003 | if (!phba->msi_name[i]) { |
| 1004 | ret = -ENOMEM; |
| 1005 | goto free_msix_irqs; |
| 1006 | } |
| 1007 | sprintf(phba->msi_name[i], "beiscsi_mcc_%02x", |
| 1008 | phba->shost->host_no); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1009 | msix_vec = phba->msix_entries[i].vector; |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 1010 | ret = request_irq(msix_vec, be_isr_mcc, 0, phba->msi_name[i], |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1011 | &phwi_context->be_eq[i]); |
Jayamohan Kallickal | 4f5af07 | 2010-07-22 04:23:55 +0530 | [diff] [blame] | 1012 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1013 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT , |
| 1014 | "BM_%d : beiscsi_init_irqs-" |
| 1015 | "Failed to register beiscsi_msix_mcc\n"); |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 1016 | kfree(phba->msi_name[i]); |
Jayamohan Kallickal | 4f5af07 | 2010-07-22 04:23:55 +0530 | [diff] [blame] | 1017 | goto free_msix_irqs; |
| 1018 | } |
| 1019 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1020 | } else { |
| 1021 | ret = request_irq(pcidev->irq, be_isr, IRQF_SHARED, |
| 1022 | "beiscsi", phba); |
| 1023 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1024 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 1025 | "BM_%d : beiscsi_init_irqs-" |
| 1026 | "Failed to register irq\\n"); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1027 | return ret; |
| 1028 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1029 | } |
| 1030 | return 0; |
Jayamohan Kallickal | 4f5af07 | 2010-07-22 04:23:55 +0530 | [diff] [blame] | 1031 | free_msix_irqs: |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 1032 | for (j = i - 1; j >= 0; j--) { |
| 1033 | kfree(phba->msi_name[j]); |
| 1034 | msix_vec = phba->msix_entries[j].vector; |
Jayamohan Kallickal | 4f5af07 | 2010-07-22 04:23:55 +0530 | [diff] [blame] | 1035 | free_irq(msix_vec, &phwi_context->be_eq[j]); |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 1036 | } |
Jayamohan Kallickal | 4f5af07 | 2010-07-22 04:23:55 +0530 | [diff] [blame] | 1037 | return ret; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1038 | } |
| 1039 | |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 1040 | void hwi_ring_cq_db(struct beiscsi_hba *phba, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1041 | unsigned int id, unsigned int num_processed, |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 1042 | unsigned char rearm) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1043 | { |
| 1044 | u32 val = 0; |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 1045 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1046 | if (rearm) |
| 1047 | val |= 1 << DB_CQ_REARM_SHIFT; |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 1048 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1049 | val |= num_processed << DB_CQ_NUM_POPPED_SHIFT; |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 1050 | |
| 1051 | /* Setting lower order CQ_ID Bits */ |
| 1052 | val |= (id & DB_CQ_RING_ID_LOW_MASK); |
| 1053 | |
| 1054 | /* Setting Higher order CQ_ID Bits */ |
| 1055 | val |= (((id >> DB_CQ_HIGH_FEILD_SHIFT) & |
| 1056 | DB_CQ_RING_ID_HIGH_MASK) |
| 1057 | << DB_CQ_HIGH_SET_SHIFT); |
| 1058 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1059 | iowrite32(val, phba->db_va + DB_CQ_OFFSET); |
| 1060 | } |
| 1061 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1062 | static unsigned int |
| 1063 | beiscsi_process_async_pdu(struct beiscsi_conn *beiscsi_conn, |
| 1064 | struct beiscsi_hba *phba, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1065 | struct pdu_base *ppdu, |
| 1066 | unsigned long pdu_len, |
| 1067 | void *pbuffer, unsigned long buf_len) |
| 1068 | { |
| 1069 | struct iscsi_conn *conn = beiscsi_conn->conn; |
| 1070 | struct iscsi_session *session = conn->session; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1071 | struct iscsi_task *task; |
| 1072 | struct beiscsi_io_task *io_task; |
| 1073 | struct iscsi_hdr *login_hdr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1074 | |
| 1075 | switch (ppdu->dw[offsetof(struct amap_pdu_base, opcode) / 32] & |
| 1076 | PDUBASE_OPCODE_MASK) { |
| 1077 | case ISCSI_OP_NOOP_IN: |
| 1078 | pbuffer = NULL; |
| 1079 | buf_len = 0; |
| 1080 | break; |
| 1081 | case ISCSI_OP_ASYNC_EVENT: |
| 1082 | break; |
| 1083 | case ISCSI_OP_REJECT: |
| 1084 | WARN_ON(!pbuffer); |
| 1085 | WARN_ON(!(buf_len == 48)); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1086 | beiscsi_log(phba, KERN_ERR, |
| 1087 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
| 1088 | "BM_%d : In ISCSI_OP_REJECT\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1089 | break; |
| 1090 | case ISCSI_OP_LOGIN_RSP: |
Jayamohan Kallickal | 7bd6e25 | 2010-01-05 05:07:02 +0530 | [diff] [blame] | 1091 | case ISCSI_OP_TEXT_RSP: |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1092 | task = conn->login_task; |
| 1093 | io_task = task->dd_data; |
| 1094 | login_hdr = (struct iscsi_hdr *)ppdu; |
| 1095 | login_hdr->itt = io_task->libiscsi_itt; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1096 | break; |
| 1097 | default: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1098 | beiscsi_log(phba, KERN_WARNING, |
| 1099 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
| 1100 | "BM_%d : Unrecognized opcode 0x%x in async msg\n", |
| 1101 | (ppdu-> |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1102 | dw[offsetof(struct amap_pdu_base, opcode) / 32] |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1103 | & PDUBASE_OPCODE_MASK)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1104 | return 1; |
| 1105 | } |
| 1106 | |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 1107 | spin_lock_bh(&session->back_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1108 | __iscsi_complete_pdu(conn, (struct iscsi_hdr *)ppdu, pbuffer, buf_len); |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 1109 | spin_unlock_bh(&session->back_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1110 | return 0; |
| 1111 | } |
| 1112 | |
| 1113 | static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba) |
| 1114 | { |
| 1115 | struct sgl_handle *psgl_handle; |
| 1116 | |
Jitendra Bhivare | 10139fe | 2016-02-04 15:49:19 +0530 | [diff] [blame] | 1117 | spin_lock_bh(&phba->io_sgl_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1118 | if (phba->io_sgl_hndl_avbl) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1119 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO, |
| 1120 | "BM_%d : In alloc_io_sgl_handle," |
| 1121 | " io_sgl_alloc_index=%d\n", |
| 1122 | phba->io_sgl_alloc_index); |
| 1123 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1124 | psgl_handle = phba->io_sgl_hndl_base[phba-> |
| 1125 | io_sgl_alloc_index]; |
| 1126 | phba->io_sgl_hndl_base[phba->io_sgl_alloc_index] = NULL; |
| 1127 | phba->io_sgl_hndl_avbl--; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1128 | if (phba->io_sgl_alloc_index == (phba->params. |
| 1129 | ios_per_ctrl - 1)) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1130 | phba->io_sgl_alloc_index = 0; |
| 1131 | else |
| 1132 | phba->io_sgl_alloc_index++; |
| 1133 | } else |
| 1134 | psgl_handle = NULL; |
Jitendra Bhivare | 10139fe | 2016-02-04 15:49:19 +0530 | [diff] [blame] | 1135 | spin_unlock_bh(&phba->io_sgl_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1136 | return psgl_handle; |
| 1137 | } |
| 1138 | |
| 1139 | static void |
| 1140 | free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle) |
| 1141 | { |
Jitendra Bhivare | 10139fe | 2016-02-04 15:49:19 +0530 | [diff] [blame] | 1142 | spin_lock_bh(&phba->io_sgl_lock); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1143 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO, |
| 1144 | "BM_%d : In free_,io_sgl_free_index=%d\n", |
| 1145 | phba->io_sgl_free_index); |
| 1146 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1147 | if (phba->io_sgl_hndl_base[phba->io_sgl_free_index]) { |
| 1148 | /* |
| 1149 | * this can happen if clean_task is called on a task that |
| 1150 | * failed in xmit_task or alloc_pdu. |
| 1151 | */ |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1152 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO, |
| 1153 | "BM_%d : Double Free in IO SGL io_sgl_free_index=%d," |
| 1154 | "value there=%p\n", phba->io_sgl_free_index, |
| 1155 | phba->io_sgl_hndl_base |
| 1156 | [phba->io_sgl_free_index]); |
Jitendra Bhivare | 10139fe | 2016-02-04 15:49:19 +0530 | [diff] [blame] | 1157 | spin_unlock_bh(&phba->io_sgl_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1158 | return; |
| 1159 | } |
| 1160 | phba->io_sgl_hndl_base[phba->io_sgl_free_index] = psgl_handle; |
| 1161 | phba->io_sgl_hndl_avbl++; |
| 1162 | if (phba->io_sgl_free_index == (phba->params.ios_per_ctrl - 1)) |
| 1163 | phba->io_sgl_free_index = 0; |
| 1164 | else |
| 1165 | phba->io_sgl_free_index++; |
Jitendra Bhivare | 10139fe | 2016-02-04 15:49:19 +0530 | [diff] [blame] | 1166 | spin_unlock_bh(&phba->io_sgl_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1167 | } |
| 1168 | |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame] | 1169 | static inline struct wrb_handle * |
| 1170 | beiscsi_get_wrb_handle(struct hwi_wrb_context *pwrb_context, |
| 1171 | unsigned int wrbs_per_cxn) |
| 1172 | { |
| 1173 | struct wrb_handle *pwrb_handle; |
| 1174 | |
Jitendra Bhivare | f64d92e | 2016-02-04 15:49:20 +0530 | [diff] [blame] | 1175 | spin_lock_bh(&pwrb_context->wrb_lock); |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame] | 1176 | pwrb_handle = pwrb_context->pwrb_handle_base[pwrb_context->alloc_index]; |
| 1177 | pwrb_context->wrb_handles_available--; |
| 1178 | if (pwrb_context->alloc_index == (wrbs_per_cxn - 1)) |
| 1179 | pwrb_context->alloc_index = 0; |
| 1180 | else |
| 1181 | pwrb_context->alloc_index++; |
Jitendra Bhivare | f64d92e | 2016-02-04 15:49:20 +0530 | [diff] [blame] | 1182 | spin_unlock_bh(&pwrb_context->wrb_lock); |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame] | 1183 | |
| 1184 | return pwrb_handle; |
| 1185 | } |
| 1186 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1187 | /** |
| 1188 | * alloc_wrb_handle - To allocate a wrb handle |
| 1189 | * @phba: The hba pointer |
| 1190 | * @cid: The cid to use for allocation |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 1191 | * @pwrb_context: ptr to ptr to wrb context |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1192 | * |
| 1193 | * This happens under session_lock until submission to chip |
| 1194 | */ |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 1195 | 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] | 1196 | struct hwi_wrb_context **pcontext) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1197 | { |
| 1198 | struct hwi_wrb_context *pwrb_context; |
| 1199 | struct hwi_controller *phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 1200 | uint16_t cri_index = BE_GET_CRI_FROM_CID(cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1201 | |
| 1202 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 1203 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame] | 1204 | /* return the context address */ |
| 1205 | *pcontext = pwrb_context; |
| 1206 | return beiscsi_get_wrb_handle(pwrb_context, phba->params.wrbs_per_cxn); |
| 1207 | } |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 1208 | |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame] | 1209 | static inline void |
| 1210 | beiscsi_put_wrb_handle(struct hwi_wrb_context *pwrb_context, |
| 1211 | struct wrb_handle *pwrb_handle, |
| 1212 | unsigned int wrbs_per_cxn) |
| 1213 | { |
Jitendra Bhivare | f64d92e | 2016-02-04 15:49:20 +0530 | [diff] [blame] | 1214 | spin_lock_bh(&pwrb_context->wrb_lock); |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame] | 1215 | pwrb_context->pwrb_handle_base[pwrb_context->free_index] = pwrb_handle; |
| 1216 | pwrb_context->wrb_handles_available++; |
| 1217 | if (pwrb_context->free_index == (wrbs_per_cxn - 1)) |
| 1218 | pwrb_context->free_index = 0; |
| 1219 | else |
| 1220 | pwrb_context->free_index++; |
Jitendra Bhivare | f64d92e | 2016-02-04 15:49:20 +0530 | [diff] [blame] | 1221 | spin_unlock_bh(&pwrb_context->wrb_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1222 | } |
| 1223 | |
| 1224 | /** |
| 1225 | * free_wrb_handle - To free the wrb handle back to pool |
| 1226 | * @phba: The hba pointer |
| 1227 | * @pwrb_context: The context to free from |
| 1228 | * @pwrb_handle: The wrb_handle to free |
| 1229 | * |
| 1230 | * This happens under session_lock until submission to chip |
| 1231 | */ |
| 1232 | static void |
| 1233 | free_wrb_handle(struct beiscsi_hba *phba, struct hwi_wrb_context *pwrb_context, |
| 1234 | struct wrb_handle *pwrb_handle) |
| 1235 | { |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame] | 1236 | beiscsi_put_wrb_handle(pwrb_context, |
| 1237 | pwrb_handle, |
| 1238 | phba->params.wrbs_per_cxn); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1239 | beiscsi_log(phba, KERN_INFO, |
| 1240 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
| 1241 | "BM_%d : FREE WRB: pwrb_handle=%p free_index=0x%x" |
| 1242 | "wrb_handles_available=%d\n", |
| 1243 | pwrb_handle, pwrb_context->free_index, |
| 1244 | pwrb_context->wrb_handles_available); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba) |
| 1248 | { |
| 1249 | struct sgl_handle *psgl_handle; |
| 1250 | |
Jitendra Bhivare | 10139fe | 2016-02-04 15:49:19 +0530 | [diff] [blame] | 1251 | spin_lock_bh(&phba->mgmt_sgl_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1252 | if (phba->eh_sgl_hndl_avbl) { |
| 1253 | psgl_handle = phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index]; |
| 1254 | phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index] = NULL; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1255 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG, |
| 1256 | "BM_%d : mgmt_sgl_alloc_index=%d=0x%x\n", |
| 1257 | phba->eh_sgl_alloc_index, |
| 1258 | phba->eh_sgl_alloc_index); |
| 1259 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1260 | phba->eh_sgl_hndl_avbl--; |
| 1261 | if (phba->eh_sgl_alloc_index == |
| 1262 | (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl - |
| 1263 | 1)) |
| 1264 | phba->eh_sgl_alloc_index = 0; |
| 1265 | else |
| 1266 | phba->eh_sgl_alloc_index++; |
| 1267 | } else |
| 1268 | psgl_handle = NULL; |
Jitendra Bhivare | 10139fe | 2016-02-04 15:49:19 +0530 | [diff] [blame] | 1269 | spin_unlock_bh(&phba->mgmt_sgl_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1270 | return psgl_handle; |
| 1271 | } |
| 1272 | |
| 1273 | void |
| 1274 | free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle) |
| 1275 | { |
Jitendra Bhivare | 10139fe | 2016-02-04 15:49:19 +0530 | [diff] [blame] | 1276 | spin_lock_bh(&phba->mgmt_sgl_lock); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1277 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG, |
| 1278 | "BM_%d : In free_mgmt_sgl_handle," |
| 1279 | "eh_sgl_free_index=%d\n", |
| 1280 | phba->eh_sgl_free_index); |
| 1281 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1282 | if (phba->eh_sgl_hndl_base[phba->eh_sgl_free_index]) { |
| 1283 | /* |
| 1284 | * this can happen if clean_task is called on a task that |
| 1285 | * failed in xmit_task or alloc_pdu. |
| 1286 | */ |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1287 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG, |
| 1288 | "BM_%d : Double Free in eh SGL ," |
| 1289 | "eh_sgl_free_index=%d\n", |
| 1290 | phba->eh_sgl_free_index); |
Jitendra Bhivare | 10139fe | 2016-02-04 15:49:19 +0530 | [diff] [blame] | 1291 | spin_unlock_bh(&phba->mgmt_sgl_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1292 | return; |
| 1293 | } |
| 1294 | phba->eh_sgl_hndl_base[phba->eh_sgl_free_index] = psgl_handle; |
| 1295 | phba->eh_sgl_hndl_avbl++; |
| 1296 | if (phba->eh_sgl_free_index == |
| 1297 | (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl - 1)) |
| 1298 | phba->eh_sgl_free_index = 0; |
| 1299 | else |
| 1300 | phba->eh_sgl_free_index++; |
Jitendra Bhivare | 10139fe | 2016-02-04 15:49:19 +0530 | [diff] [blame] | 1301 | spin_unlock_bh(&phba->mgmt_sgl_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | static void |
| 1305 | be_complete_io(struct beiscsi_conn *beiscsi_conn, |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1306 | struct iscsi_task *task, |
| 1307 | struct common_sol_cqe *csol_cqe) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1308 | { |
| 1309 | struct beiscsi_io_task *io_task = task->dd_data; |
| 1310 | struct be_status_bhs *sts_bhs = |
| 1311 | (struct be_status_bhs *)io_task->cmd_bhs; |
| 1312 | struct iscsi_conn *conn = beiscsi_conn->conn; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1313 | unsigned char *sense; |
| 1314 | u32 resid = 0, exp_cmdsn, max_cmdsn; |
| 1315 | u8 rsp, status, flags; |
| 1316 | |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1317 | exp_cmdsn = csol_cqe->exp_cmdsn; |
| 1318 | max_cmdsn = (csol_cqe->exp_cmdsn + |
| 1319 | csol_cqe->cmd_wnd - 1); |
| 1320 | rsp = csol_cqe->i_resp; |
| 1321 | status = csol_cqe->i_sts; |
| 1322 | flags = csol_cqe->i_flags; |
| 1323 | resid = csol_cqe->res_cnt; |
| 1324 | |
Jayamohan Kallickal | bd53545 | 2011-10-07 19:31:10 -0500 | [diff] [blame] | 1325 | if (!task->sc) { |
Jayamohan Kallickal | da33497 | 2014-01-29 02:16:44 -0500 | [diff] [blame] | 1326 | if (io_task->scsi_cmnd) { |
Jayamohan Kallickal | bd53545 | 2011-10-07 19:31:10 -0500 | [diff] [blame] | 1327 | scsi_dma_unmap(io_task->scsi_cmnd); |
Jayamohan Kallickal | da33497 | 2014-01-29 02:16:44 -0500 | [diff] [blame] | 1328 | io_task->scsi_cmnd = NULL; |
| 1329 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1330 | |
Jayamohan Kallickal | bd53545 | 2011-10-07 19:31:10 -0500 | [diff] [blame] | 1331 | return; |
| 1332 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1333 | task->sc->result = (DID_OK << 16) | status; |
| 1334 | if (rsp != ISCSI_STATUS_CMD_COMPLETED) { |
| 1335 | task->sc->result = DID_ERROR << 16; |
| 1336 | goto unmap; |
| 1337 | } |
| 1338 | |
| 1339 | /* bidi not initially supported */ |
| 1340 | if (flags & (ISCSI_FLAG_CMD_UNDERFLOW | ISCSI_FLAG_CMD_OVERFLOW)) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1341 | if (!status && (flags & ISCSI_FLAG_CMD_OVERFLOW)) |
| 1342 | task->sc->result = DID_ERROR << 16; |
| 1343 | |
| 1344 | if (flags & ISCSI_FLAG_CMD_UNDERFLOW) { |
| 1345 | scsi_set_resid(task->sc, resid); |
| 1346 | if (!status && (scsi_bufflen(task->sc) - resid < |
| 1347 | task->sc->underflow)) |
| 1348 | task->sc->result = DID_ERROR << 16; |
| 1349 | } |
| 1350 | } |
| 1351 | |
| 1352 | if (status == SAM_STAT_CHECK_CONDITION) { |
Dan Carpenter | 4053a4b | 2011-09-26 09:23:37 +0300 | [diff] [blame] | 1353 | u16 sense_len; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1354 | unsigned short *slen = (unsigned short *)sts_bhs->sense_info; |
Dan Carpenter | 4053a4b | 2011-09-26 09:23:37 +0300 | [diff] [blame] | 1355 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1356 | sense = sts_bhs->sense_info + sizeof(unsigned short); |
Dan Carpenter | 4053a4b | 2011-09-26 09:23:37 +0300 | [diff] [blame] | 1357 | sense_len = be16_to_cpu(*slen); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1358 | memcpy(task->sc->sense_buffer, sense, |
| 1359 | min_t(u16, sense_len, SCSI_SENSE_BUFFERSIZE)); |
| 1360 | } |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 1361 | |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1362 | if (io_task->cmd_bhs->iscsi_hdr.flags & ISCSI_FLAG_CMD_READ) |
| 1363 | conn->rxdata_octets += resid; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1364 | unmap: |
John Soni Jose | eb1c469 | 2015-04-25 08:17:45 +0530 | [diff] [blame] | 1365 | if (io_task->scsi_cmnd) { |
| 1366 | scsi_dma_unmap(io_task->scsi_cmnd); |
| 1367 | io_task->scsi_cmnd = NULL; |
| 1368 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1369 | iscsi_complete_scsi_task(task, exp_cmdsn, max_cmdsn); |
| 1370 | } |
| 1371 | |
| 1372 | static void |
| 1373 | be_complete_logout(struct beiscsi_conn *beiscsi_conn, |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1374 | struct iscsi_task *task, |
| 1375 | struct common_sol_cqe *csol_cqe) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1376 | { |
| 1377 | struct iscsi_logout_rsp *hdr; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1378 | struct beiscsi_io_task *io_task = task->dd_data; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1379 | struct iscsi_conn *conn = beiscsi_conn->conn; |
| 1380 | |
| 1381 | hdr = (struct iscsi_logout_rsp *)task->hdr; |
Jayamohan Kallickal | 7bd6e25 | 2010-01-05 05:07:02 +0530 | [diff] [blame] | 1382 | hdr->opcode = ISCSI_OP_LOGOUT_RSP; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1383 | hdr->t2wait = 5; |
| 1384 | hdr->t2retain = 0; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1385 | hdr->flags = csol_cqe->i_flags; |
| 1386 | hdr->response = csol_cqe->i_resp; |
Jayamohan Kallickal | 702dc5e | 2013-04-05 20:38:37 -0700 | [diff] [blame] | 1387 | hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn); |
| 1388 | hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn + |
| 1389 | csol_cqe->cmd_wnd - 1); |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1390 | |
Jayamohan Kallickal | 7bd6e25 | 2010-01-05 05:07:02 +0530 | [diff] [blame] | 1391 | hdr->dlength[0] = 0; |
| 1392 | hdr->dlength[1] = 0; |
| 1393 | hdr->dlength[2] = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1394 | hdr->hlength = 0; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1395 | hdr->itt = io_task->libiscsi_itt; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1396 | __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0); |
| 1397 | } |
| 1398 | |
| 1399 | static void |
| 1400 | be_complete_tmf(struct beiscsi_conn *beiscsi_conn, |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1401 | struct iscsi_task *task, |
| 1402 | struct common_sol_cqe *csol_cqe) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1403 | { |
| 1404 | struct iscsi_tm_rsp *hdr; |
| 1405 | struct iscsi_conn *conn = beiscsi_conn->conn; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1406 | struct beiscsi_io_task *io_task = task->dd_data; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1407 | |
| 1408 | hdr = (struct iscsi_tm_rsp *)task->hdr; |
Jayamohan Kallickal | 7bd6e25 | 2010-01-05 05:07:02 +0530 | [diff] [blame] | 1409 | hdr->opcode = ISCSI_OP_SCSI_TMFUNC_RSP; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1410 | hdr->flags = csol_cqe->i_flags; |
| 1411 | hdr->response = csol_cqe->i_resp; |
Jayamohan Kallickal | 702dc5e | 2013-04-05 20:38:37 -0700 | [diff] [blame] | 1412 | hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn); |
| 1413 | hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn + |
| 1414 | csol_cqe->cmd_wnd - 1); |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1415 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1416 | hdr->itt = io_task->libiscsi_itt; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1417 | __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0); |
| 1418 | } |
| 1419 | |
| 1420 | static void |
| 1421 | hwi_complete_drvr_msgs(struct beiscsi_conn *beiscsi_conn, |
| 1422 | struct beiscsi_hba *phba, struct sol_cqe *psol) |
| 1423 | { |
| 1424 | struct hwi_wrb_context *pwrb_context; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1425 | struct wrb_handle *pwrb_handle = NULL; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1426 | struct hwi_controller *phwi_ctrlr; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1427 | struct iscsi_task *task; |
| 1428 | struct beiscsi_io_task *io_task; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 1429 | uint16_t wrb_index, cid, cri_index; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1430 | |
| 1431 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 1432 | if (is_chip_be2_be3r(phba)) { |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1433 | wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe, |
| 1434 | wrb_idx, psol); |
| 1435 | cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe, |
| 1436 | cid, psol); |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 1437 | } else { |
| 1438 | wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2, |
| 1439 | wrb_idx, psol); |
| 1440 | cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2, |
| 1441 | cid, psol); |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1442 | } |
| 1443 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 1444 | cri_index = BE_GET_CRI_FROM_CID(cid); |
| 1445 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1446 | pwrb_handle = pwrb_context->pwrb_handle_basestd[wrb_index]; |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 1447 | task = pwrb_handle->pio_handle; |
Jayamohan Kallickal | 35e6601 | 2009-10-23 11:53:49 +0530 | [diff] [blame] | 1448 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1449 | io_task = task->dd_data; |
Jayamohan Kallickal | 4a4a11b | 2013-04-05 20:38:31 -0700 | [diff] [blame] | 1450 | memset(io_task->pwrb_handle->pwrb, 0, sizeof(struct iscsi_wrb)); |
| 1451 | iscsi_put_task(task); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | static void |
| 1455 | be_complete_nopin_resp(struct beiscsi_conn *beiscsi_conn, |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1456 | struct iscsi_task *task, |
| 1457 | struct common_sol_cqe *csol_cqe) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1458 | { |
| 1459 | struct iscsi_nopin *hdr; |
| 1460 | struct iscsi_conn *conn = beiscsi_conn->conn; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1461 | struct beiscsi_io_task *io_task = task->dd_data; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1462 | |
| 1463 | hdr = (struct iscsi_nopin *)task->hdr; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1464 | hdr->flags = csol_cqe->i_flags; |
| 1465 | hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn); |
Jayamohan Kallickal | 702dc5e | 2013-04-05 20:38:37 -0700 | [diff] [blame] | 1466 | hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn + |
| 1467 | csol_cqe->cmd_wnd - 1); |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1468 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1469 | hdr->opcode = ISCSI_OP_NOOP_IN; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1470 | hdr->itt = io_task->libiscsi_itt; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1471 | __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0); |
| 1472 | } |
| 1473 | |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1474 | static void adapter_get_sol_cqe(struct beiscsi_hba *phba, |
| 1475 | struct sol_cqe *psol, |
| 1476 | struct common_sol_cqe *csol_cqe) |
| 1477 | { |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 1478 | if (is_chip_be2_be3r(phba)) { |
| 1479 | csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1480 | i_exp_cmd_sn, psol); |
| 1481 | csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1482 | i_res_cnt, psol); |
| 1483 | csol_cqe->cmd_wnd = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1484 | i_cmd_wnd, psol); |
| 1485 | csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1486 | wrb_index, psol); |
| 1487 | csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1488 | cid, psol); |
| 1489 | csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1490 | hw_sts, psol); |
| 1491 | csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1492 | i_resp, psol); |
| 1493 | csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1494 | i_sts, psol); |
| 1495 | csol_cqe->i_flags = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1496 | i_flags, psol); |
| 1497 | } else { |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1498 | csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1499 | i_exp_cmd_sn, psol); |
| 1500 | csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1501 | i_res_cnt, psol); |
| 1502 | csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1503 | wrb_index, psol); |
| 1504 | csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1505 | cid, psol); |
| 1506 | csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1507 | hw_sts, psol); |
Jayamohan Kallickal | 702dc5e | 2013-04-05 20:38:37 -0700 | [diff] [blame] | 1508 | 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] | 1509 | i_cmd_wnd, psol); |
| 1510 | if (AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1511 | cmd_cmpl, psol)) |
| 1512 | csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1513 | i_sts, psol); |
| 1514 | else |
| 1515 | csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1516 | i_sts, psol); |
| 1517 | if (AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1518 | u, psol)) |
| 1519 | csol_cqe->i_flags = ISCSI_FLAG_CMD_UNDERFLOW; |
| 1520 | |
| 1521 | if (AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1522 | o, psol)) |
| 1523 | csol_cqe->i_flags |= ISCSI_FLAG_CMD_OVERFLOW; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1524 | } |
| 1525 | } |
| 1526 | |
| 1527 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1528 | static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn, |
| 1529 | struct beiscsi_hba *phba, struct sol_cqe *psol) |
| 1530 | { |
| 1531 | struct hwi_wrb_context *pwrb_context; |
| 1532 | struct wrb_handle *pwrb_handle; |
| 1533 | struct iscsi_wrb *pwrb = NULL; |
| 1534 | struct hwi_controller *phwi_ctrlr; |
| 1535 | struct iscsi_task *task; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1536 | unsigned int type; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1537 | struct iscsi_conn *conn = beiscsi_conn->conn; |
| 1538 | struct iscsi_session *session = conn->session; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1539 | struct common_sol_cqe csol_cqe = {0}; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 1540 | uint16_t cri_index = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1541 | |
| 1542 | phwi_ctrlr = phba->phwi_ctrlr; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1543 | |
| 1544 | /* Copy the elements to a common structure */ |
| 1545 | adapter_get_sol_cqe(phba, psol, &csol_cqe); |
| 1546 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 1547 | cri_index = BE_GET_CRI_FROM_CID(csol_cqe.cid); |
| 1548 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1549 | |
| 1550 | pwrb_handle = pwrb_context->pwrb_handle_basestd[ |
| 1551 | csol_cqe.wrb_index]; |
| 1552 | |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 1553 | task = pwrb_handle->pio_handle; |
| 1554 | pwrb = pwrb_handle->pwrb; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1555 | type = ((struct beiscsi_io_task *)task->dd_data)->wrb_type; |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 1556 | |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 1557 | spin_lock_bh(&session->back_lock); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1558 | switch (type) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1559 | case HWH_TYPE_IO: |
| 1560 | case HWH_TYPE_IO_RD: |
| 1561 | if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 1562 | ISCSI_OP_NOOP_OUT) |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1563 | be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe); |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 1564 | else |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1565 | be_complete_io(beiscsi_conn, task, &csol_cqe); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1566 | break; |
| 1567 | |
| 1568 | case HWH_TYPE_LOGOUT: |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 1569 | if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGOUT) |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1570 | be_complete_logout(beiscsi_conn, task, &csol_cqe); |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 1571 | else |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1572 | be_complete_tmf(beiscsi_conn, task, &csol_cqe); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1573 | break; |
| 1574 | |
| 1575 | case HWH_TYPE_LOGIN: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1576 | beiscsi_log(phba, KERN_ERR, |
| 1577 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
| 1578 | "BM_%d :\t\t No HWH_TYPE_LOGIN Expected in" |
| 1579 | " hwi_complete_cmd- Solicited path\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1580 | break; |
| 1581 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1582 | case HWH_TYPE_NOP: |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1583 | be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1584 | break; |
| 1585 | |
| 1586 | default: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1587 | beiscsi_log(phba, KERN_WARNING, |
| 1588 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
| 1589 | "BM_%d : In hwi_complete_cmd, unknown type = %d" |
| 1590 | "wrb_index 0x%x CID 0x%x\n", type, |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1591 | csol_cqe.wrb_index, |
| 1592 | csol_cqe.cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1593 | break; |
| 1594 | } |
Jayamohan Kallickal | 35e6601 | 2009-10-23 11:53:49 +0530 | [diff] [blame] | 1595 | |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 1596 | spin_unlock_bh(&session->back_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | static struct list_head *hwi_get_async_busy_list(struct hwi_async_pdu_context |
| 1600 | *pasync_ctx, unsigned int is_header, |
| 1601 | unsigned int host_write_ptr) |
| 1602 | { |
| 1603 | if (is_header) |
| 1604 | return &pasync_ctx->async_entry[host_write_ptr]. |
| 1605 | header_busy_list; |
| 1606 | else |
| 1607 | return &pasync_ctx->async_entry[host_write_ptr].data_busy_list; |
| 1608 | } |
| 1609 | |
| 1610 | static struct async_pdu_handle * |
| 1611 | hwi_get_async_handle(struct beiscsi_hba *phba, |
| 1612 | struct beiscsi_conn *beiscsi_conn, |
| 1613 | struct hwi_async_pdu_context *pasync_ctx, |
| 1614 | struct i_t_dpdu_cqe *pdpdu_cqe, unsigned int *pcq_index) |
| 1615 | { |
| 1616 | struct be_bus_address phys_addr; |
| 1617 | struct list_head *pbusy_list; |
| 1618 | struct async_pdu_handle *pasync_handle = NULL; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1619 | unsigned char is_header = 0; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1620 | unsigned int index, dpl; |
| 1621 | |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 1622 | if (is_chip_be2_be3r(phba)) { |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1623 | dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, |
| 1624 | dpl, pdpdu_cqe); |
| 1625 | index = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, |
| 1626 | index, pdpdu_cqe); |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 1627 | } else { |
| 1628 | dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2, |
| 1629 | dpl, pdpdu_cqe); |
| 1630 | index = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2, |
| 1631 | index, pdpdu_cqe); |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1632 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1633 | |
| 1634 | phys_addr.u.a32.address_lo = |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1635 | (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, |
| 1636 | db_addr_lo) / 32] - dpl); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1637 | phys_addr.u.a32.address_hi = |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1638 | pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, |
| 1639 | db_addr_hi) / 32]; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1640 | |
| 1641 | phys_addr.u.a64.address = |
| 1642 | *((unsigned long long *)(&phys_addr.u.a64.address)); |
| 1643 | |
| 1644 | switch (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, code) / 32] |
| 1645 | & PDUCQE_CODE_MASK) { |
| 1646 | case UNSOL_HDR_NOTIFY: |
| 1647 | is_header = 1; |
| 1648 | |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1649 | pbusy_list = hwi_get_async_busy_list(pasync_ctx, |
| 1650 | is_header, index); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1651 | break; |
| 1652 | case UNSOL_DATA_NOTIFY: |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1653 | pbusy_list = hwi_get_async_busy_list(pasync_ctx, |
| 1654 | is_header, index); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1655 | break; |
| 1656 | default: |
| 1657 | pbusy_list = NULL; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1658 | beiscsi_log(phba, KERN_WARNING, |
| 1659 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
| 1660 | "BM_%d : Unexpected code=%d\n", |
| 1661 | pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, |
| 1662 | code) / 32] & PDUCQE_CODE_MASK); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1663 | return NULL; |
| 1664 | } |
| 1665 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1666 | WARN_ON(list_empty(pbusy_list)); |
| 1667 | list_for_each_entry(pasync_handle, pbusy_list, link) { |
Jayamohan Kallickal | dc63aac | 2012-04-03 23:41:36 -0500 | [diff] [blame] | 1668 | if (pasync_handle->pa.u.a64.address == phys_addr.u.a64.address) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1669 | break; |
| 1670 | } |
| 1671 | |
| 1672 | WARN_ON(!pasync_handle); |
| 1673 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1674 | pasync_handle->cri = BE_GET_ASYNC_CRI_FROM_CID( |
| 1675 | beiscsi_conn->beiscsi_conn_cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1676 | pasync_handle->is_header = is_header; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1677 | pasync_handle->buffer_len = dpl; |
| 1678 | *pcq_index = index; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1679 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1680 | return pasync_handle; |
| 1681 | } |
| 1682 | |
| 1683 | static unsigned int |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1684 | hwi_update_async_writables(struct beiscsi_hba *phba, |
| 1685 | struct hwi_async_pdu_context *pasync_ctx, |
| 1686 | unsigned int is_header, unsigned int cq_index) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1687 | { |
| 1688 | struct list_head *pbusy_list; |
| 1689 | struct async_pdu_handle *pasync_handle; |
| 1690 | unsigned int num_entries, writables = 0; |
| 1691 | unsigned int *pep_read_ptr, *pwritables; |
| 1692 | |
Jayamohan Kallickal | dc63aac | 2012-04-03 23:41:36 -0500 | [diff] [blame] | 1693 | num_entries = pasync_ctx->num_entries; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1694 | if (is_header) { |
| 1695 | pep_read_ptr = &pasync_ctx->async_header.ep_read_ptr; |
| 1696 | pwritables = &pasync_ctx->async_header.writables; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1697 | } else { |
| 1698 | pep_read_ptr = &pasync_ctx->async_data.ep_read_ptr; |
| 1699 | pwritables = &pasync_ctx->async_data.writables; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1700 | } |
| 1701 | |
| 1702 | while ((*pep_read_ptr) != cq_index) { |
| 1703 | (*pep_read_ptr)++; |
| 1704 | *pep_read_ptr = (*pep_read_ptr) % num_entries; |
| 1705 | |
| 1706 | pbusy_list = hwi_get_async_busy_list(pasync_ctx, is_header, |
| 1707 | *pep_read_ptr); |
| 1708 | if (writables == 0) |
| 1709 | WARN_ON(list_empty(pbusy_list)); |
| 1710 | |
| 1711 | if (!list_empty(pbusy_list)) { |
| 1712 | pasync_handle = list_entry(pbusy_list->next, |
| 1713 | struct async_pdu_handle, |
| 1714 | link); |
| 1715 | WARN_ON(!pasync_handle); |
| 1716 | pasync_handle->consumed = 1; |
| 1717 | } |
| 1718 | |
| 1719 | writables++; |
| 1720 | } |
| 1721 | |
| 1722 | if (!writables) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1723 | beiscsi_log(phba, KERN_ERR, |
| 1724 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
| 1725 | "BM_%d : Duplicate notification received - index 0x%x!!\n", |
| 1726 | cq_index); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1727 | WARN_ON(1); |
| 1728 | } |
| 1729 | |
| 1730 | *pwritables = *pwritables + writables; |
| 1731 | return 0; |
| 1732 | } |
| 1733 | |
Jayamohan Kallickal | 9728d8d | 2012-04-03 23:41:47 -0500 | [diff] [blame] | 1734 | static void hwi_free_async_msg(struct beiscsi_hba *phba, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1735 | struct hwi_async_pdu_context *pasync_ctx, |
| 1736 | unsigned int cri) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1737 | { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1738 | struct async_pdu_handle *pasync_handle, *tmp_handle; |
| 1739 | struct list_head *plist; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1740 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1741 | plist = &pasync_ctx->async_entry[cri].wait_queue.list; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1742 | list_for_each_entry_safe(pasync_handle, tmp_handle, plist, link) { |
| 1743 | list_del(&pasync_handle->link); |
| 1744 | |
Jayamohan Kallickal | 9728d8d | 2012-04-03 23:41:47 -0500 | [diff] [blame] | 1745 | if (pasync_handle->is_header) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1746 | list_add_tail(&pasync_handle->link, |
| 1747 | &pasync_ctx->async_header.free_list); |
| 1748 | pasync_ctx->async_header.free_entries++; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1749 | } else { |
| 1750 | list_add_tail(&pasync_handle->link, |
| 1751 | &pasync_ctx->async_data.free_list); |
| 1752 | pasync_ctx->async_data.free_entries++; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1753 | } |
| 1754 | } |
| 1755 | |
| 1756 | INIT_LIST_HEAD(&pasync_ctx->async_entry[cri].wait_queue.list); |
| 1757 | pasync_ctx->async_entry[cri].wait_queue.hdr_received = 0; |
| 1758 | pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1759 | } |
| 1760 | |
| 1761 | static struct phys_addr * |
| 1762 | hwi_get_ring_address(struct hwi_async_pdu_context *pasync_ctx, |
| 1763 | unsigned int is_header, unsigned int host_write_ptr) |
| 1764 | { |
| 1765 | struct phys_addr *pasync_sge = NULL; |
| 1766 | |
| 1767 | if (is_header) |
| 1768 | pasync_sge = pasync_ctx->async_header.ring_base; |
| 1769 | else |
| 1770 | pasync_sge = pasync_ctx->async_data.ring_base; |
| 1771 | |
| 1772 | return pasync_sge + host_write_ptr; |
| 1773 | } |
| 1774 | |
| 1775 | static void hwi_post_async_buffers(struct beiscsi_hba *phba, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1776 | unsigned int is_header, uint8_t ulp_num) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1777 | { |
| 1778 | struct hwi_controller *phwi_ctrlr; |
| 1779 | struct hwi_async_pdu_context *pasync_ctx; |
| 1780 | struct async_pdu_handle *pasync_handle; |
| 1781 | struct list_head *pfree_link, *pbusy_list; |
| 1782 | struct phys_addr *pasync_sge; |
| 1783 | unsigned int ring_id, num_entries; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1784 | unsigned int host_write_num, doorbell_offset; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1785 | unsigned int writables; |
| 1786 | unsigned int i = 0; |
| 1787 | u32 doorbell = 0; |
| 1788 | |
| 1789 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1790 | pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr, ulp_num); |
Jayamohan Kallickal | dc63aac | 2012-04-03 23:41:36 -0500 | [diff] [blame] | 1791 | num_entries = pasync_ctx->num_entries; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1792 | |
| 1793 | if (is_header) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1794 | writables = min(pasync_ctx->async_header.writables, |
| 1795 | pasync_ctx->async_header.free_entries); |
| 1796 | pfree_link = pasync_ctx->async_header.free_list.next; |
| 1797 | host_write_num = pasync_ctx->async_header.host_write_ptr; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1798 | ring_id = phwi_ctrlr->default_pdu_hdr[ulp_num].id; |
| 1799 | doorbell_offset = phwi_ctrlr->default_pdu_hdr[ulp_num]. |
| 1800 | doorbell_offset; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1801 | } else { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1802 | writables = min(pasync_ctx->async_data.writables, |
| 1803 | pasync_ctx->async_data.free_entries); |
| 1804 | pfree_link = pasync_ctx->async_data.free_list.next; |
| 1805 | host_write_num = pasync_ctx->async_data.host_write_ptr; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1806 | ring_id = phwi_ctrlr->default_pdu_data[ulp_num].id; |
| 1807 | doorbell_offset = phwi_ctrlr->default_pdu_data[ulp_num]. |
| 1808 | doorbell_offset; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | writables = (writables / 8) * 8; |
| 1812 | if (writables) { |
| 1813 | for (i = 0; i < writables; i++) { |
| 1814 | pbusy_list = |
| 1815 | hwi_get_async_busy_list(pasync_ctx, is_header, |
| 1816 | host_write_num); |
| 1817 | pasync_handle = |
| 1818 | list_entry(pfree_link, struct async_pdu_handle, |
| 1819 | link); |
| 1820 | WARN_ON(!pasync_handle); |
| 1821 | pasync_handle->consumed = 0; |
| 1822 | |
| 1823 | pfree_link = pfree_link->next; |
| 1824 | |
| 1825 | pasync_sge = hwi_get_ring_address(pasync_ctx, |
| 1826 | is_header, host_write_num); |
| 1827 | |
| 1828 | pasync_sge->hi = pasync_handle->pa.u.a32.address_lo; |
| 1829 | pasync_sge->lo = pasync_handle->pa.u.a32.address_hi; |
| 1830 | |
| 1831 | list_move(&pasync_handle->link, pbusy_list); |
| 1832 | |
| 1833 | host_write_num++; |
| 1834 | host_write_num = host_write_num % num_entries; |
| 1835 | } |
| 1836 | |
| 1837 | if (is_header) { |
| 1838 | pasync_ctx->async_header.host_write_ptr = |
| 1839 | host_write_num; |
| 1840 | pasync_ctx->async_header.free_entries -= writables; |
| 1841 | pasync_ctx->async_header.writables -= writables; |
| 1842 | pasync_ctx->async_header.busy_entries += writables; |
| 1843 | } else { |
| 1844 | pasync_ctx->async_data.host_write_ptr = host_write_num; |
| 1845 | pasync_ctx->async_data.free_entries -= writables; |
| 1846 | pasync_ctx->async_data.writables -= writables; |
| 1847 | pasync_ctx->async_data.busy_entries += writables; |
| 1848 | } |
| 1849 | |
| 1850 | doorbell |= ring_id & DB_DEF_PDU_RING_ID_MASK; |
| 1851 | doorbell |= 1 << DB_DEF_PDU_REARM_SHIFT; |
| 1852 | doorbell |= 0 << DB_DEF_PDU_EVENT_SHIFT; |
| 1853 | doorbell |= (writables & DB_DEF_PDU_CQPROC_MASK) |
| 1854 | << DB_DEF_PDU_CQPROC_SHIFT; |
| 1855 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1856 | iowrite32(doorbell, phba->db_va + doorbell_offset); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1857 | } |
| 1858 | } |
| 1859 | |
| 1860 | static void hwi_flush_default_pdu_buffer(struct beiscsi_hba *phba, |
| 1861 | struct beiscsi_conn *beiscsi_conn, |
| 1862 | struct i_t_dpdu_cqe *pdpdu_cqe) |
| 1863 | { |
| 1864 | struct hwi_controller *phwi_ctrlr; |
| 1865 | struct hwi_async_pdu_context *pasync_ctx; |
| 1866 | struct async_pdu_handle *pasync_handle = NULL; |
| 1867 | unsigned int cq_index = -1; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1868 | uint16_t cri_index = BE_GET_CRI_FROM_CID( |
| 1869 | beiscsi_conn->beiscsi_conn_cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1870 | |
| 1871 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1872 | pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr, |
| 1873 | BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr, |
| 1874 | cri_index)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1875 | |
| 1876 | pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx, |
| 1877 | pdpdu_cqe, &cq_index); |
| 1878 | BUG_ON(pasync_handle->is_header != 0); |
| 1879 | if (pasync_handle->consumed == 0) |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1880 | hwi_update_async_writables(phba, pasync_ctx, |
| 1881 | pasync_handle->is_header, cq_index); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1882 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1883 | hwi_free_async_msg(phba, pasync_ctx, pasync_handle->cri); |
| 1884 | hwi_post_async_buffers(phba, pasync_handle->is_header, |
| 1885 | BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr, |
| 1886 | cri_index)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1887 | } |
| 1888 | |
| 1889 | static unsigned int |
| 1890 | hwi_fwd_async_msg(struct beiscsi_conn *beiscsi_conn, |
| 1891 | struct beiscsi_hba *phba, |
| 1892 | struct hwi_async_pdu_context *pasync_ctx, unsigned short cri) |
| 1893 | { |
| 1894 | struct list_head *plist; |
| 1895 | struct async_pdu_handle *pasync_handle; |
| 1896 | void *phdr = NULL; |
| 1897 | unsigned int hdr_len = 0, buf_len = 0; |
| 1898 | unsigned int status, index = 0, offset = 0; |
| 1899 | void *pfirst_buffer = NULL; |
| 1900 | unsigned int num_buf = 0; |
| 1901 | |
| 1902 | plist = &pasync_ctx->async_entry[cri].wait_queue.list; |
| 1903 | |
| 1904 | list_for_each_entry(pasync_handle, plist, link) { |
| 1905 | if (index == 0) { |
| 1906 | phdr = pasync_handle->pbuffer; |
| 1907 | hdr_len = pasync_handle->buffer_len; |
| 1908 | } else { |
| 1909 | buf_len = pasync_handle->buffer_len; |
| 1910 | if (!num_buf) { |
| 1911 | pfirst_buffer = pasync_handle->pbuffer; |
| 1912 | num_buf++; |
| 1913 | } |
| 1914 | memcpy(pfirst_buffer + offset, |
| 1915 | pasync_handle->pbuffer, buf_len); |
Jayamohan Kallickal | f2ba02b | 2012-04-03 23:41:37 -0500 | [diff] [blame] | 1916 | offset += buf_len; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1917 | } |
| 1918 | index++; |
| 1919 | } |
| 1920 | |
| 1921 | status = beiscsi_process_async_pdu(beiscsi_conn, phba, |
Jayamohan Kallickal | 7da5087 | 2010-01-05 05:04:12 +0530 | [diff] [blame] | 1922 | phdr, hdr_len, pfirst_buffer, |
Jayamohan Kallickal | f2ba02b | 2012-04-03 23:41:37 -0500 | [diff] [blame] | 1923 | offset); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1924 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1925 | hwi_free_async_msg(phba, pasync_ctx, cri); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1926 | return 0; |
| 1927 | } |
| 1928 | |
| 1929 | static unsigned int |
| 1930 | hwi_gather_async_pdu(struct beiscsi_conn *beiscsi_conn, |
| 1931 | struct beiscsi_hba *phba, |
| 1932 | struct async_pdu_handle *pasync_handle) |
| 1933 | { |
| 1934 | struct hwi_async_pdu_context *pasync_ctx; |
| 1935 | struct hwi_controller *phwi_ctrlr; |
| 1936 | unsigned int bytes_needed = 0, status = 0; |
| 1937 | unsigned short cri = pasync_handle->cri; |
| 1938 | struct pdu_base *ppdu; |
| 1939 | |
| 1940 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1941 | pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr, |
| 1942 | BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr, |
| 1943 | BE_GET_CRI_FROM_CID(beiscsi_conn-> |
| 1944 | beiscsi_conn_cid))); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1945 | |
| 1946 | list_del(&pasync_handle->link); |
| 1947 | if (pasync_handle->is_header) { |
| 1948 | pasync_ctx->async_header.busy_entries--; |
| 1949 | if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) { |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1950 | hwi_free_async_msg(phba, pasync_ctx, cri); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1951 | BUG(); |
| 1952 | } |
| 1953 | |
| 1954 | pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0; |
| 1955 | pasync_ctx->async_entry[cri].wait_queue.hdr_received = 1; |
| 1956 | pasync_ctx->async_entry[cri].wait_queue.hdr_len = |
| 1957 | (unsigned short)pasync_handle->buffer_len; |
| 1958 | list_add_tail(&pasync_handle->link, |
| 1959 | &pasync_ctx->async_entry[cri].wait_queue.list); |
| 1960 | |
| 1961 | ppdu = pasync_handle->pbuffer; |
| 1962 | bytes_needed = ((((ppdu->dw[offsetof(struct amap_pdu_base, |
| 1963 | data_len_hi) / 32] & PDUBASE_DATALENHI_MASK) << 8) & |
| 1964 | 0xFFFF0000) | ((be16_to_cpu((ppdu-> |
| 1965 | dw[offsetof(struct amap_pdu_base, data_len_lo) / 32] |
| 1966 | & PDUBASE_DATALENLO_MASK) >> 16)) & 0x0000FFFF)); |
| 1967 | |
| 1968 | if (status == 0) { |
| 1969 | pasync_ctx->async_entry[cri].wait_queue.bytes_needed = |
| 1970 | bytes_needed; |
| 1971 | |
| 1972 | if (bytes_needed == 0) |
| 1973 | status = hwi_fwd_async_msg(beiscsi_conn, phba, |
| 1974 | pasync_ctx, cri); |
| 1975 | } |
| 1976 | } else { |
| 1977 | pasync_ctx->async_data.busy_entries--; |
| 1978 | if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) { |
| 1979 | list_add_tail(&pasync_handle->link, |
| 1980 | &pasync_ctx->async_entry[cri].wait_queue. |
| 1981 | list); |
| 1982 | pasync_ctx->async_entry[cri].wait_queue. |
| 1983 | bytes_received += |
| 1984 | (unsigned short)pasync_handle->buffer_len; |
| 1985 | |
| 1986 | if (pasync_ctx->async_entry[cri].wait_queue. |
| 1987 | bytes_received >= |
| 1988 | pasync_ctx->async_entry[cri].wait_queue. |
| 1989 | bytes_needed) |
| 1990 | status = hwi_fwd_async_msg(beiscsi_conn, phba, |
| 1991 | pasync_ctx, cri); |
| 1992 | } |
| 1993 | } |
| 1994 | return status; |
| 1995 | } |
| 1996 | |
| 1997 | static void hwi_process_default_pdu_ring(struct beiscsi_conn *beiscsi_conn, |
| 1998 | struct beiscsi_hba *phba, |
| 1999 | struct i_t_dpdu_cqe *pdpdu_cqe) |
| 2000 | { |
| 2001 | struct hwi_controller *phwi_ctrlr; |
| 2002 | struct hwi_async_pdu_context *pasync_ctx; |
| 2003 | struct async_pdu_handle *pasync_handle = NULL; |
| 2004 | unsigned int cq_index = -1; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2005 | uint16_t cri_index = BE_GET_CRI_FROM_CID( |
| 2006 | beiscsi_conn->beiscsi_conn_cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2007 | |
| 2008 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2009 | pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr, |
| 2010 | BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr, |
| 2011 | cri_index)); |
| 2012 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2013 | pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx, |
| 2014 | pdpdu_cqe, &cq_index); |
| 2015 | |
| 2016 | if (pasync_handle->consumed == 0) |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2017 | hwi_update_async_writables(phba, pasync_ctx, |
| 2018 | pasync_handle->is_header, cq_index); |
| 2019 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2020 | hwi_gather_async_pdu(beiscsi_conn, phba, pasync_handle); |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2021 | hwi_post_async_buffers(phba, pasync_handle->is_header, |
| 2022 | BEISCSI_GET_ULP_FROM_CRI( |
| 2023 | phwi_ctrlr, cri_index)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2024 | } |
| 2025 | |
Jitendra Bhivare | 2e4e8f6 | 2016-02-04 15:49:11 +0530 | [diff] [blame] | 2026 | void beiscsi_process_mcc_cq(struct beiscsi_hba *phba) |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 2027 | { |
| 2028 | struct be_queue_info *mcc_cq; |
| 2029 | struct be_mcc_compl *mcc_compl; |
| 2030 | unsigned int num_processed = 0; |
| 2031 | |
| 2032 | mcc_cq = &phba->ctrl.mcc_obj.cq; |
| 2033 | mcc_compl = queue_tail_node(mcc_cq); |
| 2034 | mcc_compl->flags = le32_to_cpu(mcc_compl->flags); |
| 2035 | while (mcc_compl->flags & CQE_FLAGS_VALID_MASK) { |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 2036 | if (num_processed >= 32) { |
| 2037 | hwi_ring_cq_db(phba, mcc_cq->id, |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2038 | num_processed, 0); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 2039 | num_processed = 0; |
| 2040 | } |
| 2041 | if (mcc_compl->flags & CQE_FLAGS_ASYNC_MASK) { |
Jitendra Bhivare | 53aefe2 | 2016-01-20 14:10:53 +0530 | [diff] [blame] | 2042 | beiscsi_process_async_event(phba, mcc_compl); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 2043 | } else if (mcc_compl->flags & CQE_FLAGS_COMPLETED_MASK) { |
Jitendra Bhivare | 2e4e8f6 | 2016-02-04 15:49:11 +0530 | [diff] [blame] | 2044 | beiscsi_process_mcc_compl(&phba->ctrl, mcc_compl); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 2045 | } |
| 2046 | |
| 2047 | mcc_compl->flags = 0; |
| 2048 | queue_tail_inc(mcc_cq); |
| 2049 | mcc_compl = queue_tail_node(mcc_cq); |
| 2050 | mcc_compl->flags = le32_to_cpu(mcc_compl->flags); |
| 2051 | num_processed++; |
| 2052 | } |
| 2053 | |
| 2054 | if (num_processed > 0) |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2055 | hwi_ring_cq_db(phba, mcc_cq->id, num_processed, 1); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 2056 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2057 | |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 2058 | /** |
| 2059 | * beiscsi_process_cq()- Process the Completion Queue |
| 2060 | * @pbe_eq: Event Q on which the Completion has come |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2061 | * @budget: Max number of events to processed |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 2062 | * |
| 2063 | * return |
| 2064 | * Number of Completion Entries processed. |
| 2065 | **/ |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2066 | 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] | 2067 | { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2068 | struct be_queue_info *cq; |
| 2069 | struct sol_cqe *sol; |
| 2070 | struct dmsg_cqe *dmsg; |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2071 | unsigned int total = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2072 | unsigned int num_processed = 0; |
John Soni Jose | 0a513dd | 2012-08-20 23:00:55 +0530 | [diff] [blame] | 2073 | unsigned short code = 0, cid = 0; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2074 | uint16_t cri_index = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2075 | struct beiscsi_conn *beiscsi_conn; |
Jayamohan Kallickal | c246228 | 2010-01-05 05:05:34 +0530 | [diff] [blame] | 2076 | struct beiscsi_endpoint *beiscsi_ep; |
| 2077 | struct iscsi_endpoint *ep; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2078 | struct beiscsi_hba *phba; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2079 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2080 | cq = pbe_eq->cq; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2081 | sol = queue_tail_node(cq); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2082 | phba = pbe_eq->phba; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2083 | |
| 2084 | while (sol->dw[offsetof(struct amap_sol_cqe, valid) / 32] & |
| 2085 | CQE_VALID_MASK) { |
| 2086 | be_dws_le_to_cpu(sol, sizeof(struct sol_cqe)); |
| 2087 | |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 2088 | code = (sol->dw[offsetof(struct amap_sol_cqe, code) / |
| 2089 | 32] & CQE_CODE_MASK); |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 2090 | |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 2091 | /* Get the CID */ |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 2092 | if (is_chip_be2_be3r(phba)) { |
| 2093 | cid = AMAP_GET_BITS(struct amap_sol_cqe, cid, sol); |
| 2094 | } else { |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 2095 | if ((code == DRIVERMSG_NOTIFY) || |
| 2096 | (code == UNSOL_HDR_NOTIFY) || |
| 2097 | (code == UNSOL_DATA_NOTIFY)) |
| 2098 | cid = AMAP_GET_BITS( |
| 2099 | struct amap_i_t_dpdu_cqe_v2, |
| 2100 | cid, sol); |
| 2101 | else |
| 2102 | cid = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 2103 | cid, sol); |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 2104 | } |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 2105 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2106 | cri_index = BE_GET_CRI_FROM_CID(cid); |
| 2107 | ep = phba->ep_array[cri_index]; |
Jayamohan Kallickal | b7ab35b | 2014-08-08 01:00:01 -0400 | [diff] [blame] | 2108 | |
| 2109 | if (ep == NULL) { |
| 2110 | /* connection has already been freed |
| 2111 | * just move on to next one |
| 2112 | */ |
| 2113 | beiscsi_log(phba, KERN_WARNING, |
| 2114 | BEISCSI_LOG_INIT, |
| 2115 | "BM_%d : proc cqe of disconn ep: cid %d\n", |
| 2116 | cid); |
| 2117 | goto proc_next_cqe; |
| 2118 | } |
| 2119 | |
Jayamohan Kallickal | c246228 | 2010-01-05 05:05:34 +0530 | [diff] [blame] | 2120 | beiscsi_ep = ep->dd_data; |
| 2121 | beiscsi_conn = beiscsi_ep->conn; |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 2122 | |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2123 | /* replenish cq */ |
| 2124 | if (num_processed == 32) { |
| 2125 | hwi_ring_cq_db(phba, cq->id, 32, 0); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2126 | num_processed = 0; |
| 2127 | } |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2128 | total++; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2129 | |
John Soni Jose | 0a513dd | 2012-08-20 23:00:55 +0530 | [diff] [blame] | 2130 | switch (code) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2131 | case SOL_CMD_COMPLETE: |
| 2132 | hwi_complete_cmd(beiscsi_conn, phba, sol); |
| 2133 | break; |
| 2134 | case DRIVERMSG_NOTIFY: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2135 | beiscsi_log(phba, KERN_INFO, |
| 2136 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 2137 | "BM_%d : Received %s[%d] on CID : %d\n", |
| 2138 | cqe_desc[code], code, cid); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2139 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2140 | dmsg = (struct dmsg_cqe *)sol; |
| 2141 | hwi_complete_drvr_msgs(beiscsi_conn, phba, sol); |
| 2142 | break; |
| 2143 | case UNSOL_HDR_NOTIFY: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2144 | beiscsi_log(phba, KERN_INFO, |
| 2145 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 2146 | "BM_%d : Received %s[%d] on CID : %d\n", |
| 2147 | cqe_desc[code], code, cid); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2148 | |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 2149 | spin_lock_bh(&phba->async_pdu_lock); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2150 | hwi_process_default_pdu_ring(beiscsi_conn, phba, |
| 2151 | (struct i_t_dpdu_cqe *)sol); |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 2152 | spin_unlock_bh(&phba->async_pdu_lock); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2153 | break; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2154 | case UNSOL_DATA_NOTIFY: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2155 | beiscsi_log(phba, KERN_INFO, |
| 2156 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 2157 | "BM_%d : Received %s[%d] on CID : %d\n", |
| 2158 | cqe_desc[code], code, cid); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2159 | |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 2160 | spin_lock_bh(&phba->async_pdu_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2161 | hwi_process_default_pdu_ring(beiscsi_conn, phba, |
| 2162 | (struct i_t_dpdu_cqe *)sol); |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 2163 | spin_unlock_bh(&phba->async_pdu_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2164 | break; |
| 2165 | case CXN_INVALIDATE_INDEX_NOTIFY: |
| 2166 | case CMD_INVALIDATED_NOTIFY: |
| 2167 | case CXN_INVALIDATE_NOTIFY: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2168 | beiscsi_log(phba, KERN_ERR, |
| 2169 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 2170 | "BM_%d : Ignoring %s[%d] on CID : %d\n", |
| 2171 | cqe_desc[code], code, cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2172 | break; |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2173 | case CXN_KILLED_HDR_DIGEST_ERR: |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2174 | case SOL_CMD_KILLED_DATA_DIGEST_ERR: |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2175 | beiscsi_log(phba, KERN_ERR, |
| 2176 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
| 2177 | "BM_%d : Cmd Notification %s[%d] on CID : %d\n", |
| 2178 | cqe_desc[code], code, cid); |
| 2179 | break; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2180 | case CMD_KILLED_INVALID_STATSN_RCVD: |
| 2181 | case CMD_KILLED_INVALID_R2T_RCVD: |
| 2182 | case CMD_CXN_KILLED_LUN_INVALID: |
| 2183 | case CMD_CXN_KILLED_ICD_INVALID: |
| 2184 | case CMD_CXN_KILLED_ITT_INVALID: |
| 2185 | case CMD_CXN_KILLED_SEQ_OUTOFORDER: |
| 2186 | case CMD_CXN_KILLED_INVALID_DATASN_RCVD: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2187 | beiscsi_log(phba, KERN_ERR, |
| 2188 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 2189 | "BM_%d : Cmd Notification %s[%d] on CID : %d\n", |
| 2190 | cqe_desc[code], code, cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2191 | break; |
| 2192 | case UNSOL_DATA_DIGEST_ERROR_NOTIFY: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2193 | beiscsi_log(phba, KERN_ERR, |
| 2194 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 2195 | "BM_%d : Dropping %s[%d] on DPDU ring on CID : %d\n", |
| 2196 | cqe_desc[code], code, cid); |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 2197 | spin_lock_bh(&phba->async_pdu_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2198 | hwi_flush_default_pdu_buffer(phba, beiscsi_conn, |
| 2199 | (struct i_t_dpdu_cqe *) sol); |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 2200 | spin_unlock_bh(&phba->async_pdu_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2201 | break; |
| 2202 | case CXN_KILLED_PDU_SIZE_EXCEEDS_DSL: |
| 2203 | case CXN_KILLED_BURST_LEN_MISMATCH: |
| 2204 | case CXN_KILLED_AHS_RCVD: |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2205 | case CXN_KILLED_UNKNOWN_HDR: |
| 2206 | case CXN_KILLED_STALE_ITT_TTT_RCVD: |
| 2207 | case CXN_KILLED_INVALID_ITT_TTT_RCVD: |
| 2208 | case CXN_KILLED_TIMED_OUT: |
| 2209 | case CXN_KILLED_FIN_RCVD: |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 2210 | case CXN_KILLED_RST_SENT: |
| 2211 | case CXN_KILLED_RST_RCVD: |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2212 | case CXN_KILLED_BAD_UNSOL_PDU_RCVD: |
| 2213 | case CXN_KILLED_BAD_WRB_INDEX_ERROR: |
| 2214 | case CXN_KILLED_OVER_RUN_RESIDUAL: |
| 2215 | case CXN_KILLED_UNDER_RUN_RESIDUAL: |
| 2216 | case CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2217 | beiscsi_log(phba, KERN_ERR, |
| 2218 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 2219 | "BM_%d : Event %s[%d] received on CID : %d\n", |
| 2220 | cqe_desc[code], code, cid); |
John Soni Jose | 0a513dd | 2012-08-20 23:00:55 +0530 | [diff] [blame] | 2221 | if (beiscsi_conn) |
| 2222 | iscsi_conn_failure(beiscsi_conn->conn, |
| 2223 | ISCSI_ERR_CONN_FAILED); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2224 | break; |
| 2225 | default: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2226 | beiscsi_log(phba, KERN_ERR, |
| 2227 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 2228 | "BM_%d : Invalid CQE Event Received Code : %d" |
| 2229 | "CID 0x%x...\n", |
John Soni Jose | 0a513dd | 2012-08-20 23:00:55 +0530 | [diff] [blame] | 2230 | code, cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2231 | break; |
| 2232 | } |
| 2233 | |
Jayamohan Kallickal | b7ab35b | 2014-08-08 01:00:01 -0400 | [diff] [blame] | 2234 | proc_next_cqe: |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2235 | AMAP_SET_BITS(struct amap_sol_cqe, valid, sol, 0); |
| 2236 | queue_tail_inc(cq); |
| 2237 | sol = queue_tail_node(cq); |
| 2238 | num_processed++; |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2239 | if (total == budget) |
| 2240 | break; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2241 | } |
| 2242 | |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2243 | hwi_ring_cq_db(phba, cq->id, num_processed, 1); |
| 2244 | return total; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2245 | } |
| 2246 | |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 2247 | void beiscsi_process_all_cqs(struct work_struct *work) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2248 | { |
| 2249 | unsigned long flags; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2250 | struct hwi_controller *phwi_ctrlr; |
| 2251 | struct hwi_context_memory *phwi_context; |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 2252 | struct beiscsi_hba *phba; |
| 2253 | struct be_eq_obj *pbe_eq = |
| 2254 | container_of(work, struct be_eq_obj, work_cqs); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2255 | |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 2256 | phba = pbe_eq->phba; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2257 | phwi_ctrlr = phba->phwi_ctrlr; |
| 2258 | phwi_context = phwi_ctrlr->phwi_ctxt; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2259 | |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 2260 | if (pbe_eq->todo_mcc_cq) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2261 | spin_lock_irqsave(&phba->isr_lock, flags); |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 2262 | pbe_eq->todo_mcc_cq = false; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2263 | spin_unlock_irqrestore(&phba->isr_lock, flags); |
Jitendra Bhivare | 2e4e8f6 | 2016-02-04 15:49:11 +0530 | [diff] [blame] | 2264 | beiscsi_process_mcc_cq(phba); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2265 | } |
| 2266 | |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 2267 | if (pbe_eq->todo_cq) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2268 | spin_lock_irqsave(&phba->isr_lock, flags); |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 2269 | pbe_eq->todo_cq = false; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2270 | spin_unlock_irqrestore(&phba->isr_lock, flags); |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2271 | beiscsi_process_cq(pbe_eq, BE2_MAX_NUM_CQ_PROC); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2272 | } |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 2273 | |
| 2274 | /* rearm EQ for further interrupts */ |
| 2275 | 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] | 2276 | } |
| 2277 | |
Christoph Hellwig | 511cbce | 2015-11-10 14:56:14 +0100 | [diff] [blame] | 2278 | static int be_iopoll(struct irq_poll *iop, int budget) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2279 | { |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2280 | unsigned int ret, num_eq_processed; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2281 | struct beiscsi_hba *phba; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2282 | struct be_eq_obj *pbe_eq; |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2283 | struct be_eq_entry *eqe = NULL; |
| 2284 | struct be_queue_info *eq; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2285 | |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2286 | num_eq_processed = 0; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2287 | pbe_eq = container_of(iop, struct be_eq_obj, iopoll); |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2288 | phba = pbe_eq->phba; |
| 2289 | eq = &pbe_eq->q; |
| 2290 | eqe = queue_tail_node(eq); |
| 2291 | |
| 2292 | while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32] & |
| 2293 | EQE_VALID_MASK) { |
| 2294 | AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0); |
| 2295 | queue_tail_inc(eq); |
| 2296 | eqe = queue_tail_node(eq); |
| 2297 | num_eq_processed++; |
| 2298 | } |
| 2299 | |
| 2300 | hwi_ring_eq_db(phba, eq->id, 1, num_eq_processed, 0, 1); |
| 2301 | |
| 2302 | ret = beiscsi_process_cq(pbe_eq, budget); |
Jayamohan Kallickal | 73af08e | 2014-05-05 21:41:26 -0400 | [diff] [blame] | 2303 | pbe_eq->cq_count += ret; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2304 | if (ret < budget) { |
Christoph Hellwig | 511cbce | 2015-11-10 14:56:14 +0100 | [diff] [blame] | 2305 | irq_poll_complete(iop); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2306 | beiscsi_log(phba, KERN_INFO, |
| 2307 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2308 | "BM_%d : rearm pbe_eq->q.id =%d ret %d\n", |
| 2309 | pbe_eq->q.id, ret); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2310 | 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] | 2311 | } |
| 2312 | return ret; |
| 2313 | } |
| 2314 | |
| 2315 | static void |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2316 | hwi_write_sgl_v2(struct iscsi_wrb *pwrb, struct scatterlist *sg, |
| 2317 | unsigned int num_sg, struct beiscsi_io_task *io_task) |
| 2318 | { |
| 2319 | struct iscsi_sge *psgl; |
| 2320 | unsigned int sg_len, index; |
| 2321 | unsigned int sge_len = 0; |
| 2322 | unsigned long long addr; |
| 2323 | struct scatterlist *l_sg; |
| 2324 | unsigned int offset; |
| 2325 | |
| 2326 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_lo, pwrb, |
| 2327 | io_task->bhs_pa.u.a32.address_lo); |
| 2328 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_hi, pwrb, |
| 2329 | io_task->bhs_pa.u.a32.address_hi); |
| 2330 | |
| 2331 | l_sg = sg; |
| 2332 | for (index = 0; (index < num_sg) && (index < 2); index++, |
| 2333 | sg = sg_next(sg)) { |
| 2334 | if (index == 0) { |
| 2335 | sg_len = sg_dma_len(sg); |
| 2336 | addr = (u64) sg_dma_address(sg); |
| 2337 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
| 2338 | sge0_addr_lo, pwrb, |
| 2339 | lower_32_bits(addr)); |
| 2340 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
| 2341 | sge0_addr_hi, pwrb, |
| 2342 | upper_32_bits(addr)); |
| 2343 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
| 2344 | sge0_len, pwrb, |
| 2345 | sg_len); |
| 2346 | sge_len = sg_len; |
| 2347 | } else { |
| 2348 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_r2t_offset, |
| 2349 | pwrb, sge_len); |
| 2350 | sg_len = sg_dma_len(sg); |
| 2351 | addr = (u64) sg_dma_address(sg); |
| 2352 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
| 2353 | sge1_addr_lo, pwrb, |
| 2354 | lower_32_bits(addr)); |
| 2355 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
| 2356 | sge1_addr_hi, pwrb, |
| 2357 | upper_32_bits(addr)); |
| 2358 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
| 2359 | sge1_len, pwrb, |
| 2360 | sg_len); |
| 2361 | } |
| 2362 | } |
| 2363 | psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag; |
| 2364 | memset(psgl, 0, sizeof(*psgl) * BE2_SGE); |
| 2365 | |
| 2366 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2); |
| 2367 | |
| 2368 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, |
| 2369 | io_task->bhs_pa.u.a32.address_hi); |
| 2370 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, |
| 2371 | io_task->bhs_pa.u.a32.address_lo); |
| 2372 | |
| 2373 | if (num_sg == 1) { |
| 2374 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb, |
| 2375 | 1); |
| 2376 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb, |
| 2377 | 0); |
| 2378 | } else if (num_sg == 2) { |
| 2379 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb, |
| 2380 | 0); |
| 2381 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb, |
| 2382 | 1); |
| 2383 | } else { |
| 2384 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb, |
| 2385 | 0); |
| 2386 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb, |
| 2387 | 0); |
| 2388 | } |
| 2389 | |
| 2390 | sg = l_sg; |
| 2391 | psgl++; |
| 2392 | psgl++; |
| 2393 | offset = 0; |
| 2394 | for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) { |
| 2395 | sg_len = sg_dma_len(sg); |
| 2396 | addr = (u64) sg_dma_address(sg); |
| 2397 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, |
| 2398 | lower_32_bits(addr)); |
| 2399 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, |
| 2400 | upper_32_bits(addr)); |
| 2401 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len); |
| 2402 | AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset); |
| 2403 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0); |
| 2404 | offset += sg_len; |
| 2405 | } |
| 2406 | psgl--; |
| 2407 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1); |
| 2408 | } |
| 2409 | |
| 2410 | static void |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2411 | hwi_write_sgl(struct iscsi_wrb *pwrb, struct scatterlist *sg, |
| 2412 | unsigned int num_sg, struct beiscsi_io_task *io_task) |
| 2413 | { |
| 2414 | struct iscsi_sge *psgl; |
Jayamohan Kallickal | 58ff4bd | 2010-10-06 23:46:47 +0530 | [diff] [blame] | 2415 | unsigned int sg_len, index; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2416 | unsigned int sge_len = 0; |
| 2417 | unsigned long long addr; |
| 2418 | struct scatterlist *l_sg; |
| 2419 | unsigned int offset; |
| 2420 | |
| 2421 | AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb, |
| 2422 | io_task->bhs_pa.u.a32.address_lo); |
| 2423 | AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb, |
| 2424 | io_task->bhs_pa.u.a32.address_hi); |
| 2425 | |
| 2426 | l_sg = sg; |
Jayamohan Kallickal | 48bd86c | 2010-01-07 01:50:19 +0530 | [diff] [blame] | 2427 | for (index = 0; (index < num_sg) && (index < 2); index++, |
| 2428 | sg = sg_next(sg)) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2429 | if (index == 0) { |
| 2430 | sg_len = sg_dma_len(sg); |
| 2431 | addr = (u64) sg_dma_address(sg); |
| 2432 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb, |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 2433 | ((u32)(addr & 0xFFFFFFFF))); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2434 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb, |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 2435 | ((u32)(addr >> 32))); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2436 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb, |
| 2437 | sg_len); |
| 2438 | sge_len = sg_len; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2439 | } else { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2440 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_r2t_offset, |
| 2441 | pwrb, sge_len); |
| 2442 | sg_len = sg_dma_len(sg); |
| 2443 | addr = (u64) sg_dma_address(sg); |
| 2444 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_lo, pwrb, |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 2445 | ((u32)(addr & 0xFFFFFFFF))); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2446 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_hi, pwrb, |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 2447 | ((u32)(addr >> 32))); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2448 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_len, pwrb, |
| 2449 | sg_len); |
| 2450 | } |
| 2451 | } |
| 2452 | psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag; |
| 2453 | memset(psgl, 0, sizeof(*psgl) * BE2_SGE); |
| 2454 | |
| 2455 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2); |
| 2456 | |
| 2457 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, |
| 2458 | io_task->bhs_pa.u.a32.address_hi); |
| 2459 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, |
| 2460 | io_task->bhs_pa.u.a32.address_lo); |
| 2461 | |
Jayamohan Kallickal | caf818f | 2010-01-23 05:38:18 +0530 | [diff] [blame] | 2462 | if (num_sg == 1) { |
| 2463 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, |
| 2464 | 1); |
| 2465 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb, |
| 2466 | 0); |
| 2467 | } else if (num_sg == 2) { |
| 2468 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, |
| 2469 | 0); |
| 2470 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb, |
| 2471 | 1); |
| 2472 | } else { |
| 2473 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, |
| 2474 | 0); |
| 2475 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb, |
| 2476 | 0); |
| 2477 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2478 | sg = l_sg; |
| 2479 | psgl++; |
| 2480 | psgl++; |
| 2481 | offset = 0; |
Jayamohan Kallickal | 48bd86c | 2010-01-07 01:50:19 +0530 | [diff] [blame] | 2482 | for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2483 | sg_len = sg_dma_len(sg); |
| 2484 | addr = (u64) sg_dma_address(sg); |
| 2485 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, |
| 2486 | (addr & 0xFFFFFFFF)); |
| 2487 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, |
| 2488 | (addr >> 32)); |
| 2489 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len); |
| 2490 | AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset); |
| 2491 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0); |
| 2492 | offset += sg_len; |
| 2493 | } |
| 2494 | psgl--; |
| 2495 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1); |
| 2496 | } |
| 2497 | |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2498 | /** |
| 2499 | * hwi_write_buffer()- Populate the WRB with task info |
| 2500 | * @pwrb: ptr to the WRB entry |
| 2501 | * @task: iscsi task which is to be executed |
| 2502 | **/ |
Alexey Khoroshilov | e049362 | 2016-01-16 00:45:34 +0300 | [diff] [blame] | 2503 | 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] | 2504 | { |
| 2505 | struct iscsi_sge *psgl; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2506 | struct beiscsi_io_task *io_task = task->dd_data; |
| 2507 | struct beiscsi_conn *beiscsi_conn = io_task->conn; |
| 2508 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2509 | uint8_t dsp_value = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2510 | |
| 2511 | io_task->bhs_len = sizeof(struct be_nonio_bhs) - 2; |
| 2512 | AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb, |
| 2513 | io_task->bhs_pa.u.a32.address_lo); |
| 2514 | AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb, |
| 2515 | io_task->bhs_pa.u.a32.address_hi); |
| 2516 | |
| 2517 | if (task->data) { |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2518 | |
| 2519 | /* Check for the data_count */ |
| 2520 | dsp_value = (task->data_count) ? 1 : 0; |
| 2521 | |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 2522 | if (is_chip_be2_be3r(phba)) |
| 2523 | AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2524 | pwrb, dsp_value); |
| 2525 | else |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 2526 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2527 | pwrb, dsp_value); |
| 2528 | |
| 2529 | /* Map addr only if there is data_count */ |
| 2530 | if (dsp_value) { |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2531 | io_task->mtask_addr = pci_map_single(phba->pcidev, |
| 2532 | task->data, |
| 2533 | task->data_count, |
| 2534 | PCI_DMA_TODEVICE); |
Alexey Khoroshilov | e049362 | 2016-01-16 00:45:34 +0300 | [diff] [blame] | 2535 | if (pci_dma_mapping_error(phba->pcidev, |
| 2536 | io_task->mtask_addr)) |
| 2537 | return -ENOMEM; |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2538 | io_task->mtask_data_count = task->data_count; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2539 | } else |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2540 | io_task->mtask_addr = 0; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2541 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2542 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb, |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2543 | lower_32_bits(io_task->mtask_addr)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2544 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb, |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2545 | upper_32_bits(io_task->mtask_addr)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2546 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb, |
| 2547 | task->data_count); |
| 2548 | |
| 2549 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, 1); |
| 2550 | } else { |
| 2551 | AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0); |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2552 | io_task->mtask_addr = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2553 | } |
| 2554 | |
| 2555 | psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag; |
| 2556 | |
| 2557 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len); |
| 2558 | |
| 2559 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, |
| 2560 | io_task->bhs_pa.u.a32.address_hi); |
| 2561 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, |
| 2562 | io_task->bhs_pa.u.a32.address_lo); |
| 2563 | if (task->data) { |
| 2564 | psgl++; |
| 2565 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, 0); |
| 2566 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, 0); |
| 2567 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0); |
| 2568 | AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, 0); |
| 2569 | AMAP_SET_BITS(struct amap_iscsi_sge, rsvd0, psgl, 0); |
| 2570 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0); |
| 2571 | |
| 2572 | psgl++; |
| 2573 | if (task->data) { |
| 2574 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2575 | lower_32_bits(io_task->mtask_addr)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2576 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2577 | upper_32_bits(io_task->mtask_addr)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2578 | } |
| 2579 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0x106); |
| 2580 | } |
| 2581 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1); |
Alexey Khoroshilov | e049362 | 2016-01-16 00:45:34 +0300 | [diff] [blame] | 2582 | return 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2583 | } |
| 2584 | |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 2585 | /** |
| 2586 | * beiscsi_find_mem_req()- Find mem needed |
| 2587 | * @phba: ptr to HBA struct |
| 2588 | **/ |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2589 | static void beiscsi_find_mem_req(struct beiscsi_hba *phba) |
| 2590 | { |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2591 | uint8_t mem_descr_index, ulp_num; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2592 | unsigned int num_cq_pages, num_async_pdu_buf_pages; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2593 | unsigned int num_async_pdu_data_pages, wrb_sz_per_cxn; |
| 2594 | unsigned int num_async_pdu_buf_sgl_pages, num_async_pdu_data_sgl_pages; |
| 2595 | |
| 2596 | num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \ |
| 2597 | sizeof(struct sol_cqe)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2598 | |
| 2599 | phba->params.hwi_ws_sz = sizeof(struct hwi_controller); |
| 2600 | |
| 2601 | phba->mem_req[ISCSI_MEM_GLOBAL_HEADER] = 2 * |
| 2602 | BE_ISCSI_PDU_HEADER_SIZE; |
| 2603 | phba->mem_req[HWI_MEM_ADDN_CONTEXT] = |
| 2604 | sizeof(struct hwi_context_memory); |
| 2605 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2606 | |
| 2607 | phba->mem_req[HWI_MEM_WRB] = sizeof(struct iscsi_wrb) |
| 2608 | * (phba->params.wrbs_per_cxn) |
| 2609 | * phba->params.cxns_per_ctrl; |
| 2610 | wrb_sz_per_cxn = sizeof(struct wrb_handle) * |
| 2611 | (phba->params.wrbs_per_cxn); |
| 2612 | phba->mem_req[HWI_MEM_WRBH] = roundup_pow_of_two((wrb_sz_per_cxn) * |
| 2613 | phba->params.cxns_per_ctrl); |
| 2614 | |
| 2615 | phba->mem_req[HWI_MEM_SGLH] = sizeof(struct sgl_handle) * |
| 2616 | phba->params.icds_per_ctrl; |
| 2617 | phba->mem_req[HWI_MEM_SGE] = sizeof(struct iscsi_sge) * |
| 2618 | phba->params.num_sge_per_io * phba->params.icds_per_ctrl; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2619 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 2620 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2621 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2622 | num_async_pdu_buf_sgl_pages = |
| 2623 | PAGES_REQUIRED(BEISCSI_GET_CID_COUNT( |
| 2624 | phba, ulp_num) * |
| 2625 | sizeof(struct phys_addr)); |
| 2626 | |
| 2627 | num_async_pdu_buf_pages = |
| 2628 | PAGES_REQUIRED(BEISCSI_GET_CID_COUNT( |
| 2629 | phba, ulp_num) * |
| 2630 | phba->params.defpdu_hdr_sz); |
| 2631 | |
| 2632 | num_async_pdu_data_pages = |
| 2633 | PAGES_REQUIRED(BEISCSI_GET_CID_COUNT( |
| 2634 | phba, ulp_num) * |
| 2635 | phba->params.defpdu_data_sz); |
| 2636 | |
| 2637 | num_async_pdu_data_sgl_pages = |
| 2638 | PAGES_REQUIRED(BEISCSI_GET_CID_COUNT( |
| 2639 | phba, ulp_num) * |
| 2640 | sizeof(struct phys_addr)); |
| 2641 | |
Jayamohan Kallickal | a129d92 | 2013-09-28 15:35:46 -0700 | [diff] [blame] | 2642 | mem_descr_index = (HWI_MEM_TEMPLATE_HDR_ULP0 + |
| 2643 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2644 | phba->mem_req[mem_descr_index] = |
| 2645 | BEISCSI_GET_CID_COUNT(phba, ulp_num) * |
| 2646 | BEISCSI_TEMPLATE_HDR_PER_CXN_SIZE; |
| 2647 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2648 | mem_descr_index = (HWI_MEM_ASYNC_HEADER_BUF_ULP0 + |
| 2649 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2650 | phba->mem_req[mem_descr_index] = |
| 2651 | num_async_pdu_buf_pages * |
| 2652 | PAGE_SIZE; |
| 2653 | |
| 2654 | mem_descr_index = (HWI_MEM_ASYNC_DATA_BUF_ULP0 + |
| 2655 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2656 | phba->mem_req[mem_descr_index] = |
| 2657 | num_async_pdu_data_pages * |
| 2658 | PAGE_SIZE; |
| 2659 | |
| 2660 | mem_descr_index = (HWI_MEM_ASYNC_HEADER_RING_ULP0 + |
| 2661 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2662 | phba->mem_req[mem_descr_index] = |
| 2663 | num_async_pdu_buf_sgl_pages * |
| 2664 | PAGE_SIZE; |
| 2665 | |
| 2666 | mem_descr_index = (HWI_MEM_ASYNC_DATA_RING_ULP0 + |
| 2667 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2668 | phba->mem_req[mem_descr_index] = |
| 2669 | num_async_pdu_data_sgl_pages * |
| 2670 | PAGE_SIZE; |
| 2671 | |
| 2672 | mem_descr_index = (HWI_MEM_ASYNC_HEADER_HANDLE_ULP0 + |
| 2673 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2674 | phba->mem_req[mem_descr_index] = |
| 2675 | BEISCSI_GET_CID_COUNT(phba, ulp_num) * |
| 2676 | sizeof(struct async_pdu_handle); |
| 2677 | |
| 2678 | mem_descr_index = (HWI_MEM_ASYNC_DATA_HANDLE_ULP0 + |
| 2679 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2680 | phba->mem_req[mem_descr_index] = |
| 2681 | BEISCSI_GET_CID_COUNT(phba, ulp_num) * |
| 2682 | sizeof(struct async_pdu_handle); |
| 2683 | |
| 2684 | mem_descr_index = (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0 + |
| 2685 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2686 | phba->mem_req[mem_descr_index] = |
| 2687 | sizeof(struct hwi_async_pdu_context) + |
| 2688 | (BEISCSI_GET_CID_COUNT(phba, ulp_num) * |
| 2689 | sizeof(struct hwi_async_entry)); |
| 2690 | } |
| 2691 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2692 | } |
| 2693 | |
| 2694 | static int beiscsi_alloc_mem(struct beiscsi_hba *phba) |
| 2695 | { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2696 | dma_addr_t bus_add; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2697 | struct hwi_controller *phwi_ctrlr; |
| 2698 | struct be_mem_descriptor *mem_descr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2699 | struct mem_array *mem_arr, *mem_arr_orig; |
| 2700 | unsigned int i, j, alloc_size, curr_alloc_size; |
| 2701 | |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2702 | phba->phwi_ctrlr = kzalloc(phba->params.hwi_ws_sz, GFP_KERNEL); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2703 | if (!phba->phwi_ctrlr) |
| 2704 | return -ENOMEM; |
| 2705 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2706 | /* Allocate memory for wrb_context */ |
| 2707 | phwi_ctrlr = phba->phwi_ctrlr; |
| 2708 | phwi_ctrlr->wrb_context = kzalloc(sizeof(struct hwi_wrb_context) * |
| 2709 | phba->params.cxns_per_ctrl, |
| 2710 | GFP_KERNEL); |
Maurizio Lombardi | 0c88740 | 2015-10-01 10:56:25 +0200 | [diff] [blame] | 2711 | if (!phwi_ctrlr->wrb_context) { |
| 2712 | kfree(phba->phwi_ctrlr); |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2713 | return -ENOMEM; |
Maurizio Lombardi | 0c88740 | 2015-10-01 10:56:25 +0200 | [diff] [blame] | 2714 | } |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2715 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2716 | phba->init_mem = kcalloc(SE_MEM_MAX, sizeof(*mem_descr), |
| 2717 | GFP_KERNEL); |
| 2718 | if (!phba->init_mem) { |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2719 | kfree(phwi_ctrlr->wrb_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2720 | kfree(phba->phwi_ctrlr); |
| 2721 | return -ENOMEM; |
| 2722 | } |
| 2723 | |
| 2724 | mem_arr_orig = kmalloc(sizeof(*mem_arr_orig) * BEISCSI_MAX_FRAGS_INIT, |
| 2725 | GFP_KERNEL); |
| 2726 | if (!mem_arr_orig) { |
| 2727 | kfree(phba->init_mem); |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2728 | kfree(phwi_ctrlr->wrb_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2729 | kfree(phba->phwi_ctrlr); |
| 2730 | return -ENOMEM; |
| 2731 | } |
| 2732 | |
| 2733 | mem_descr = phba->init_mem; |
| 2734 | for (i = 0; i < SE_MEM_MAX; i++) { |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2735 | if (!phba->mem_req[i]) { |
| 2736 | mem_descr->mem_array = NULL; |
| 2737 | mem_descr++; |
| 2738 | continue; |
| 2739 | } |
| 2740 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2741 | j = 0; |
| 2742 | mem_arr = mem_arr_orig; |
| 2743 | alloc_size = phba->mem_req[i]; |
| 2744 | memset(mem_arr, 0, sizeof(struct mem_array) * |
| 2745 | BEISCSI_MAX_FRAGS_INIT); |
| 2746 | curr_alloc_size = min(be_max_phys_size * 1024, alloc_size); |
| 2747 | do { |
| 2748 | mem_arr->virtual_address = pci_alloc_consistent( |
| 2749 | phba->pcidev, |
| 2750 | curr_alloc_size, |
| 2751 | &bus_add); |
| 2752 | if (!mem_arr->virtual_address) { |
| 2753 | if (curr_alloc_size <= BE_MIN_MEM_SIZE) |
| 2754 | goto free_mem; |
| 2755 | if (curr_alloc_size - |
| 2756 | rounddown_pow_of_two(curr_alloc_size)) |
| 2757 | curr_alloc_size = rounddown_pow_of_two |
| 2758 | (curr_alloc_size); |
| 2759 | else |
| 2760 | curr_alloc_size = curr_alloc_size / 2; |
| 2761 | } else { |
| 2762 | mem_arr->bus_address.u. |
| 2763 | a64.address = (__u64) bus_add; |
| 2764 | mem_arr->size = curr_alloc_size; |
| 2765 | alloc_size -= curr_alloc_size; |
| 2766 | curr_alloc_size = min(be_max_phys_size * |
| 2767 | 1024, alloc_size); |
| 2768 | j++; |
| 2769 | mem_arr++; |
| 2770 | } |
| 2771 | } while (alloc_size); |
| 2772 | mem_descr->num_elements = j; |
| 2773 | mem_descr->size_in_bytes = phba->mem_req[i]; |
| 2774 | mem_descr->mem_array = kmalloc(sizeof(*mem_arr) * j, |
| 2775 | GFP_KERNEL); |
| 2776 | if (!mem_descr->mem_array) |
| 2777 | goto free_mem; |
| 2778 | |
| 2779 | memcpy(mem_descr->mem_array, mem_arr_orig, |
| 2780 | sizeof(struct mem_array) * j); |
| 2781 | mem_descr++; |
| 2782 | } |
| 2783 | kfree(mem_arr_orig); |
| 2784 | return 0; |
| 2785 | free_mem: |
| 2786 | mem_descr->num_elements = j; |
| 2787 | while ((i) || (j)) { |
| 2788 | for (j = mem_descr->num_elements; j > 0; j--) { |
| 2789 | pci_free_consistent(phba->pcidev, |
| 2790 | mem_descr->mem_array[j - 1].size, |
| 2791 | mem_descr->mem_array[j - 1]. |
| 2792 | virtual_address, |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 2793 | (unsigned long)mem_descr-> |
| 2794 | mem_array[j - 1]. |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2795 | bus_address.u.a64.address); |
| 2796 | } |
| 2797 | if (i) { |
| 2798 | i--; |
| 2799 | kfree(mem_descr->mem_array); |
| 2800 | mem_descr--; |
| 2801 | } |
| 2802 | } |
| 2803 | kfree(mem_arr_orig); |
| 2804 | kfree(phba->init_mem); |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2805 | kfree(phba->phwi_ctrlr->wrb_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2806 | kfree(phba->phwi_ctrlr); |
| 2807 | return -ENOMEM; |
| 2808 | } |
| 2809 | |
| 2810 | static int beiscsi_get_memory(struct beiscsi_hba *phba) |
| 2811 | { |
| 2812 | beiscsi_find_mem_req(phba); |
| 2813 | return beiscsi_alloc_mem(phba); |
| 2814 | } |
| 2815 | |
| 2816 | static void iscsi_init_global_templates(struct beiscsi_hba *phba) |
| 2817 | { |
| 2818 | struct pdu_data_out *pdata_out; |
| 2819 | struct pdu_nop_out *pnop_out; |
| 2820 | struct be_mem_descriptor *mem_descr; |
| 2821 | |
| 2822 | mem_descr = phba->init_mem; |
| 2823 | mem_descr += ISCSI_MEM_GLOBAL_HEADER; |
| 2824 | pdata_out = |
| 2825 | (struct pdu_data_out *)mem_descr->mem_array[0].virtual_address; |
| 2826 | memset(pdata_out, 0, BE_ISCSI_PDU_HEADER_SIZE); |
| 2827 | |
| 2828 | AMAP_SET_BITS(struct amap_pdu_data_out, opcode, pdata_out, |
| 2829 | IIOC_SCSI_DATA); |
| 2830 | |
| 2831 | pnop_out = |
| 2832 | (struct pdu_nop_out *)((unsigned char *)mem_descr->mem_array[0]. |
| 2833 | virtual_address + BE_ISCSI_PDU_HEADER_SIZE); |
| 2834 | |
| 2835 | memset(pnop_out, 0, BE_ISCSI_PDU_HEADER_SIZE); |
| 2836 | AMAP_SET_BITS(struct amap_pdu_nop_out, ttt, pnop_out, 0xFFFFFFFF); |
| 2837 | AMAP_SET_BITS(struct amap_pdu_nop_out, f_bit, pnop_out, 1); |
| 2838 | AMAP_SET_BITS(struct amap_pdu_nop_out, i_bit, pnop_out, 0); |
| 2839 | } |
| 2840 | |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2841 | static int beiscsi_init_wrb_handle(struct beiscsi_hba *phba) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2842 | { |
| 2843 | struct be_mem_descriptor *mem_descr_wrbh, *mem_descr_wrb; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2844 | struct hwi_context_memory *phwi_ctxt; |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2845 | struct wrb_handle *pwrb_handle = NULL; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2846 | struct hwi_controller *phwi_ctrlr; |
| 2847 | struct hwi_wrb_context *pwrb_context; |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2848 | struct iscsi_wrb *pwrb = NULL; |
| 2849 | unsigned int num_cxn_wrbh = 0; |
| 2850 | unsigned int num_cxn_wrb = 0, j, idx = 0, index; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2851 | |
| 2852 | mem_descr_wrbh = phba->init_mem; |
| 2853 | mem_descr_wrbh += HWI_MEM_WRBH; |
| 2854 | |
| 2855 | mem_descr_wrb = phba->init_mem; |
| 2856 | mem_descr_wrb += HWI_MEM_WRB; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2857 | phwi_ctrlr = phba->phwi_ctrlr; |
| 2858 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2859 | /* Allocate memory for WRBQ */ |
| 2860 | phwi_ctxt = phwi_ctrlr->phwi_ctxt; |
| 2861 | phwi_ctxt->be_wrbq = kzalloc(sizeof(struct be_queue_info) * |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 2862 | phba->params.cxns_per_ctrl, |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2863 | GFP_KERNEL); |
| 2864 | if (!phwi_ctxt->be_wrbq) { |
| 2865 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 2866 | "BM_%d : WRBQ Mem Alloc Failed\n"); |
| 2867 | return -ENOMEM; |
| 2868 | } |
| 2869 | |
| 2870 | for (index = 0; index < phba->params.cxns_per_ctrl; index++) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2871 | pwrb_context = &phwi_ctrlr->wrb_context[index]; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2872 | pwrb_context->pwrb_handle_base = |
| 2873 | kzalloc(sizeof(struct wrb_handle *) * |
| 2874 | phba->params.wrbs_per_cxn, GFP_KERNEL); |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2875 | if (!pwrb_context->pwrb_handle_base) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2876 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 2877 | "BM_%d : Mem Alloc Failed. Failing to load\n"); |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2878 | goto init_wrb_hndl_failed; |
| 2879 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2880 | pwrb_context->pwrb_handle_basestd = |
| 2881 | kzalloc(sizeof(struct wrb_handle *) * |
| 2882 | phba->params.wrbs_per_cxn, GFP_KERNEL); |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2883 | if (!pwrb_context->pwrb_handle_basestd) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2884 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 2885 | "BM_%d : Mem Alloc Failed. Failing to load\n"); |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2886 | goto init_wrb_hndl_failed; |
| 2887 | } |
| 2888 | if (!num_cxn_wrbh) { |
| 2889 | pwrb_handle = |
| 2890 | mem_descr_wrbh->mem_array[idx].virtual_address; |
| 2891 | num_cxn_wrbh = ((mem_descr_wrbh->mem_array[idx].size) / |
| 2892 | ((sizeof(struct wrb_handle)) * |
| 2893 | phba->params.wrbs_per_cxn)); |
| 2894 | idx++; |
| 2895 | } |
| 2896 | pwrb_context->alloc_index = 0; |
| 2897 | pwrb_context->wrb_handles_available = 0; |
| 2898 | pwrb_context->free_index = 0; |
| 2899 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2900 | if (num_cxn_wrbh) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2901 | for (j = 0; j < phba->params.wrbs_per_cxn; j++) { |
| 2902 | pwrb_context->pwrb_handle_base[j] = pwrb_handle; |
| 2903 | pwrb_context->pwrb_handle_basestd[j] = |
| 2904 | pwrb_handle; |
| 2905 | pwrb_context->wrb_handles_available++; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2906 | pwrb_handle->wrb_index = j; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2907 | pwrb_handle++; |
| 2908 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2909 | num_cxn_wrbh--; |
| 2910 | } |
Jitendra Bhivare | f64d92e | 2016-02-04 15:49:20 +0530 | [diff] [blame] | 2911 | spin_lock_init(&pwrb_context->wrb_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2912 | } |
| 2913 | idx = 0; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2914 | for (index = 0; index < phba->params.cxns_per_ctrl; index++) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2915 | pwrb_context = &phwi_ctrlr->wrb_context[index]; |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2916 | if (!num_cxn_wrb) { |
| 2917 | pwrb = mem_descr_wrb->mem_array[idx].virtual_address; |
| 2918 | num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) / |
| 2919 | ((sizeof(struct iscsi_wrb) * |
| 2920 | phba->params.wrbs_per_cxn)); |
| 2921 | idx++; |
| 2922 | } |
| 2923 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2924 | if (num_cxn_wrb) { |
| 2925 | for (j = 0; j < phba->params.wrbs_per_cxn; j++) { |
| 2926 | pwrb_handle = pwrb_context->pwrb_handle_base[j]; |
| 2927 | pwrb_handle->pwrb = pwrb; |
| 2928 | pwrb++; |
| 2929 | } |
| 2930 | num_cxn_wrb--; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2931 | } |
| 2932 | } |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2933 | return 0; |
| 2934 | init_wrb_hndl_failed: |
| 2935 | for (j = index; j > 0; j--) { |
| 2936 | pwrb_context = &phwi_ctrlr->wrb_context[j]; |
| 2937 | kfree(pwrb_context->pwrb_handle_base); |
| 2938 | kfree(pwrb_context->pwrb_handle_basestd); |
| 2939 | } |
| 2940 | return -ENOMEM; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2941 | } |
| 2942 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2943 | static int hwi_init_async_pdu_ctx(struct beiscsi_hba *phba) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2944 | { |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2945 | uint8_t ulp_num; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2946 | struct hwi_controller *phwi_ctrlr; |
| 2947 | struct hba_parameters *p = &phba->params; |
| 2948 | struct hwi_async_pdu_context *pasync_ctx; |
| 2949 | struct async_pdu_handle *pasync_header_h, *pasync_data_h; |
Jayamohan Kallickal | dc63aac | 2012-04-03 23:41:36 -0500 | [diff] [blame] | 2950 | unsigned int index, idx, num_per_mem, num_async_data; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2951 | struct be_mem_descriptor *mem_descr; |
| 2952 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2953 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 2954 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2955 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2956 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 2957 | mem_descr += (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0 + |
| 2958 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2959 | |
| 2960 | phwi_ctrlr = phba->phwi_ctrlr; |
| 2961 | phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num] = |
| 2962 | (struct hwi_async_pdu_context *) |
| 2963 | mem_descr->mem_array[0].virtual_address; |
| 2964 | |
| 2965 | pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num]; |
| 2966 | memset(pasync_ctx, 0, sizeof(*pasync_ctx)); |
| 2967 | |
| 2968 | pasync_ctx->async_entry = |
| 2969 | (struct hwi_async_entry *) |
| 2970 | ((long unsigned int)pasync_ctx + |
| 2971 | sizeof(struct hwi_async_pdu_context)); |
| 2972 | |
| 2973 | pasync_ctx->num_entries = BEISCSI_GET_CID_COUNT(phba, |
| 2974 | ulp_num); |
| 2975 | pasync_ctx->buffer_size = p->defpdu_hdr_sz; |
| 2976 | |
| 2977 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 2978 | mem_descr += HWI_MEM_ASYNC_HEADER_BUF_ULP0 + |
| 2979 | (ulp_num * MEM_DESCR_OFFSET); |
| 2980 | if (mem_descr->mem_array[0].virtual_address) { |
| 2981 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 2982 | "BM_%d : hwi_init_async_pdu_ctx" |
| 2983 | " HWI_MEM_ASYNC_HEADER_BUF_ULP%d va=%p\n", |
| 2984 | ulp_num, |
| 2985 | mem_descr->mem_array[0]. |
| 2986 | virtual_address); |
| 2987 | } else |
| 2988 | beiscsi_log(phba, KERN_WARNING, |
| 2989 | BEISCSI_LOG_INIT, |
| 2990 | "BM_%d : No Virtual address for ULP : %d\n", |
| 2991 | ulp_num); |
| 2992 | |
| 2993 | pasync_ctx->async_header.va_base = |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2994 | mem_descr->mem_array[0].virtual_address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2995 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2996 | pasync_ctx->async_header.pa_base.u.a64.address = |
| 2997 | mem_descr->mem_array[0]. |
| 2998 | bus_address.u.a64.address; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2999 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3000 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 3001 | mem_descr += HWI_MEM_ASYNC_HEADER_RING_ULP0 + |
| 3002 | (ulp_num * MEM_DESCR_OFFSET); |
| 3003 | if (mem_descr->mem_array[0].virtual_address) { |
| 3004 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3005 | "BM_%d : hwi_init_async_pdu_ctx" |
| 3006 | " HWI_MEM_ASYNC_HEADER_RING_ULP%d va=%p\n", |
| 3007 | ulp_num, |
| 3008 | mem_descr->mem_array[0]. |
| 3009 | virtual_address); |
| 3010 | } else |
| 3011 | beiscsi_log(phba, KERN_WARNING, |
| 3012 | BEISCSI_LOG_INIT, |
| 3013 | "BM_%d : No Virtual address for ULP : %d\n", |
| 3014 | ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3015 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3016 | pasync_ctx->async_header.ring_base = |
| 3017 | mem_descr->mem_array[0].virtual_address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3018 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3019 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 3020 | mem_descr += HWI_MEM_ASYNC_HEADER_HANDLE_ULP0 + |
| 3021 | (ulp_num * MEM_DESCR_OFFSET); |
| 3022 | if (mem_descr->mem_array[0].virtual_address) { |
| 3023 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3024 | "BM_%d : hwi_init_async_pdu_ctx" |
| 3025 | " HWI_MEM_ASYNC_HEADER_HANDLE_ULP%d va=%p\n", |
| 3026 | ulp_num, |
| 3027 | mem_descr->mem_array[0]. |
| 3028 | virtual_address); |
| 3029 | } else |
| 3030 | beiscsi_log(phba, KERN_WARNING, |
| 3031 | BEISCSI_LOG_INIT, |
| 3032 | "BM_%d : No Virtual address for ULP : %d\n", |
| 3033 | ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3034 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3035 | pasync_ctx->async_header.handle_base = |
| 3036 | mem_descr->mem_array[0].virtual_address; |
| 3037 | pasync_ctx->async_header.writables = 0; |
| 3038 | INIT_LIST_HEAD(&pasync_ctx->async_header.free_list); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3039 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3040 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 3041 | mem_descr += HWI_MEM_ASYNC_DATA_RING_ULP0 + |
| 3042 | (ulp_num * MEM_DESCR_OFFSET); |
| 3043 | if (mem_descr->mem_array[0].virtual_address) { |
| 3044 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3045 | "BM_%d : hwi_init_async_pdu_ctx" |
| 3046 | " HWI_MEM_ASYNC_DATA_RING_ULP%d va=%p\n", |
| 3047 | ulp_num, |
| 3048 | mem_descr->mem_array[0]. |
| 3049 | virtual_address); |
| 3050 | } else |
| 3051 | beiscsi_log(phba, KERN_WARNING, |
| 3052 | BEISCSI_LOG_INIT, |
| 3053 | "BM_%d : No Virtual address for ULP : %d\n", |
| 3054 | ulp_num); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3055 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3056 | pasync_ctx->async_data.ring_base = |
| 3057 | mem_descr->mem_array[0].virtual_address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3058 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3059 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 3060 | mem_descr += HWI_MEM_ASYNC_DATA_HANDLE_ULP0 + |
| 3061 | (ulp_num * MEM_DESCR_OFFSET); |
| 3062 | if (!mem_descr->mem_array[0].virtual_address) |
| 3063 | beiscsi_log(phba, KERN_WARNING, |
| 3064 | BEISCSI_LOG_INIT, |
| 3065 | "BM_%d : No Virtual address for ULP : %d\n", |
| 3066 | ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3067 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3068 | pasync_ctx->async_data.handle_base = |
| 3069 | mem_descr->mem_array[0].virtual_address; |
| 3070 | pasync_ctx->async_data.writables = 0; |
| 3071 | INIT_LIST_HEAD(&pasync_ctx->async_data.free_list); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3072 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3073 | pasync_header_h = |
| 3074 | (struct async_pdu_handle *) |
| 3075 | pasync_ctx->async_header.handle_base; |
| 3076 | pasync_data_h = |
| 3077 | (struct async_pdu_handle *) |
| 3078 | pasync_ctx->async_data.handle_base; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3079 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3080 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 3081 | mem_descr += HWI_MEM_ASYNC_DATA_BUF_ULP0 + |
| 3082 | (ulp_num * MEM_DESCR_OFFSET); |
| 3083 | if (mem_descr->mem_array[0].virtual_address) { |
| 3084 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3085 | "BM_%d : hwi_init_async_pdu_ctx" |
| 3086 | " HWI_MEM_ASYNC_DATA_BUF_ULP%d va=%p\n", |
| 3087 | ulp_num, |
| 3088 | mem_descr->mem_array[0]. |
| 3089 | virtual_address); |
| 3090 | } else |
| 3091 | beiscsi_log(phba, KERN_WARNING, |
| 3092 | BEISCSI_LOG_INIT, |
| 3093 | "BM_%d : No Virtual address for ULP : %d\n", |
| 3094 | ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3095 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3096 | idx = 0; |
Jayamohan Kallickal | dc63aac | 2012-04-03 23:41:36 -0500 | [diff] [blame] | 3097 | pasync_ctx->async_data.va_base = |
| 3098 | mem_descr->mem_array[idx].virtual_address; |
| 3099 | pasync_ctx->async_data.pa_base.u.a64.address = |
| 3100 | mem_descr->mem_array[idx]. |
| 3101 | bus_address.u.a64.address; |
| 3102 | |
| 3103 | num_async_data = ((mem_descr->mem_array[idx].size) / |
| 3104 | phba->params.defpdu_data_sz); |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3105 | num_per_mem = 0; |
| 3106 | |
| 3107 | for (index = 0; index < BEISCSI_GET_CID_COUNT |
| 3108 | (phba, ulp_num); index++) { |
| 3109 | pasync_header_h->cri = -1; |
| 3110 | pasync_header_h->index = (char)index; |
| 3111 | INIT_LIST_HEAD(&pasync_header_h->link); |
| 3112 | pasync_header_h->pbuffer = |
| 3113 | (void *)((unsigned long) |
| 3114 | (pasync_ctx-> |
| 3115 | async_header.va_base) + |
| 3116 | (p->defpdu_hdr_sz * index)); |
| 3117 | |
| 3118 | pasync_header_h->pa.u.a64.address = |
| 3119 | pasync_ctx->async_header.pa_base.u.a64. |
| 3120 | address + (p->defpdu_hdr_sz * index); |
| 3121 | |
| 3122 | list_add_tail(&pasync_header_h->link, |
| 3123 | &pasync_ctx->async_header. |
| 3124 | free_list); |
| 3125 | pasync_header_h++; |
| 3126 | pasync_ctx->async_header.free_entries++; |
| 3127 | pasync_ctx->async_header.writables++; |
| 3128 | |
| 3129 | INIT_LIST_HEAD(&pasync_ctx->async_entry[index]. |
| 3130 | wait_queue.list); |
| 3131 | INIT_LIST_HEAD(&pasync_ctx->async_entry[index]. |
| 3132 | header_busy_list); |
| 3133 | pasync_data_h->cri = -1; |
| 3134 | pasync_data_h->index = (char)index; |
| 3135 | INIT_LIST_HEAD(&pasync_data_h->link); |
| 3136 | |
| 3137 | if (!num_async_data) { |
| 3138 | num_per_mem = 0; |
| 3139 | idx++; |
| 3140 | pasync_ctx->async_data.va_base = |
| 3141 | mem_descr->mem_array[idx]. |
| 3142 | virtual_address; |
| 3143 | pasync_ctx->async_data.pa_base.u. |
| 3144 | a64.address = |
| 3145 | mem_descr->mem_array[idx]. |
| 3146 | bus_address.u.a64.address; |
| 3147 | num_async_data = |
| 3148 | ((mem_descr->mem_array[idx]. |
| 3149 | size) / |
| 3150 | phba->params.defpdu_data_sz); |
| 3151 | } |
| 3152 | pasync_data_h->pbuffer = |
| 3153 | (void *)((unsigned long) |
| 3154 | (pasync_ctx->async_data.va_base) + |
| 3155 | (p->defpdu_data_sz * num_per_mem)); |
| 3156 | |
| 3157 | pasync_data_h->pa.u.a64.address = |
| 3158 | pasync_ctx->async_data.pa_base.u.a64. |
| 3159 | address + (p->defpdu_data_sz * |
| 3160 | num_per_mem); |
| 3161 | num_per_mem++; |
| 3162 | num_async_data--; |
| 3163 | |
| 3164 | list_add_tail(&pasync_data_h->link, |
| 3165 | &pasync_ctx->async_data. |
| 3166 | free_list); |
| 3167 | pasync_data_h++; |
| 3168 | pasync_ctx->async_data.free_entries++; |
| 3169 | pasync_ctx->async_data.writables++; |
| 3170 | |
| 3171 | INIT_LIST_HEAD(&pasync_ctx->async_entry[index]. |
| 3172 | data_busy_list); |
| 3173 | } |
| 3174 | |
| 3175 | pasync_ctx->async_header.host_write_ptr = 0; |
| 3176 | pasync_ctx->async_header.ep_read_ptr = -1; |
| 3177 | pasync_ctx->async_data.host_write_ptr = 0; |
| 3178 | pasync_ctx->async_data.ep_read_ptr = -1; |
Jayamohan Kallickal | dc63aac | 2012-04-03 23:41:36 -0500 | [diff] [blame] | 3179 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3180 | } |
| 3181 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 3182 | return 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3183 | } |
| 3184 | |
| 3185 | static int |
| 3186 | be_sgl_create_contiguous(void *virtual_address, |
| 3187 | u64 physical_address, u32 length, |
| 3188 | struct be_dma_mem *sgl) |
| 3189 | { |
| 3190 | WARN_ON(!virtual_address); |
| 3191 | WARN_ON(!physical_address); |
Tim Gardner | dd29dae | 2015-10-30 12:22:58 -0600 | [diff] [blame] | 3192 | WARN_ON(!length); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3193 | WARN_ON(!sgl); |
| 3194 | |
| 3195 | sgl->va = virtual_address; |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 3196 | sgl->dma = (unsigned long)physical_address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3197 | sgl->size = length; |
| 3198 | |
| 3199 | return 0; |
| 3200 | } |
| 3201 | |
| 3202 | static void be_sgl_destroy_contiguous(struct be_dma_mem *sgl) |
| 3203 | { |
| 3204 | memset(sgl, 0, sizeof(*sgl)); |
| 3205 | } |
| 3206 | |
| 3207 | static void |
| 3208 | hwi_build_be_sgl_arr(struct beiscsi_hba *phba, |
| 3209 | struct mem_array *pmem, struct be_dma_mem *sgl) |
| 3210 | { |
| 3211 | if (sgl->va) |
| 3212 | be_sgl_destroy_contiguous(sgl); |
| 3213 | |
| 3214 | be_sgl_create_contiguous(pmem->virtual_address, |
| 3215 | pmem->bus_address.u.a64.address, |
| 3216 | pmem->size, sgl); |
| 3217 | } |
| 3218 | |
| 3219 | static void |
| 3220 | hwi_build_be_sgl_by_offset(struct beiscsi_hba *phba, |
| 3221 | struct mem_array *pmem, struct be_dma_mem *sgl) |
| 3222 | { |
| 3223 | if (sgl->va) |
| 3224 | be_sgl_destroy_contiguous(sgl); |
| 3225 | |
| 3226 | be_sgl_create_contiguous((unsigned char *)pmem->virtual_address, |
| 3227 | pmem->bus_address.u.a64.address, |
| 3228 | pmem->size, sgl); |
| 3229 | } |
| 3230 | |
| 3231 | static int be_fill_queue(struct be_queue_info *q, |
| 3232 | u16 len, u16 entry_size, void *vaddress) |
| 3233 | { |
| 3234 | struct be_dma_mem *mem = &q->dma_mem; |
| 3235 | |
| 3236 | memset(q, 0, sizeof(*q)); |
| 3237 | q->len = len; |
| 3238 | q->entry_size = entry_size; |
| 3239 | mem->size = len * entry_size; |
| 3240 | mem->va = vaddress; |
| 3241 | if (!mem->va) |
| 3242 | return -ENOMEM; |
| 3243 | memset(mem->va, 0, mem->size); |
| 3244 | return 0; |
| 3245 | } |
| 3246 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3247 | static int beiscsi_create_eqs(struct beiscsi_hba *phba, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3248 | struct hwi_context_memory *phwi_context) |
| 3249 | { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3250 | unsigned int i, num_eq_pages; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3251 | int ret = 0, eq_for_mcc; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3252 | struct be_queue_info *eq; |
| 3253 | struct be_dma_mem *mem; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3254 | void *eq_vaddress; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3255 | dma_addr_t paddr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3256 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3257 | num_eq_pages = PAGES_REQUIRED(phba->params.num_eq_entries * \ |
| 3258 | sizeof(struct be_eq_entry)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3259 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3260 | if (phba->msix_enabled) |
| 3261 | eq_for_mcc = 1; |
| 3262 | else |
| 3263 | eq_for_mcc = 0; |
| 3264 | for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) { |
| 3265 | eq = &phwi_context->be_eq[i].q; |
| 3266 | mem = &eq->dma_mem; |
| 3267 | phwi_context->be_eq[i].phba = phba; |
| 3268 | eq_vaddress = pci_alloc_consistent(phba->pcidev, |
| 3269 | num_eq_pages * PAGE_SIZE, |
| 3270 | &paddr); |
| 3271 | if (!eq_vaddress) |
| 3272 | goto create_eq_error; |
| 3273 | |
| 3274 | mem->va = eq_vaddress; |
| 3275 | ret = be_fill_queue(eq, phba->params.num_eq_entries, |
| 3276 | sizeof(struct be_eq_entry), eq_vaddress); |
| 3277 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3278 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3279 | "BM_%d : be_fill_queue Failed for EQ\n"); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3280 | goto create_eq_error; |
| 3281 | } |
| 3282 | |
| 3283 | mem->dma = paddr; |
| 3284 | ret = beiscsi_cmd_eq_create(&phba->ctrl, eq, |
| 3285 | phwi_context->cur_eqd); |
| 3286 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3287 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3288 | "BM_%d : beiscsi_cmd_eq_create" |
| 3289 | "Failed for EQ\n"); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3290 | goto create_eq_error; |
| 3291 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3292 | |
| 3293 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3294 | "BM_%d : eqid = %d\n", |
| 3295 | phwi_context->be_eq[i].q.id); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3296 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3297 | return 0; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3298 | create_eq_error: |
John Soni Jose | 107dfcb | 2012-10-20 04:42:13 +0530 | [diff] [blame] | 3299 | for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3300 | eq = &phwi_context->be_eq[i].q; |
| 3301 | mem = &eq->dma_mem; |
| 3302 | if (mem->va) |
| 3303 | pci_free_consistent(phba->pcidev, num_eq_pages |
| 3304 | * PAGE_SIZE, |
| 3305 | mem->va, mem->dma); |
| 3306 | } |
| 3307 | return ret; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3308 | } |
| 3309 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3310 | static int beiscsi_create_cqs(struct beiscsi_hba *phba, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3311 | struct hwi_context_memory *phwi_context) |
| 3312 | { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3313 | unsigned int i, num_cq_pages; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3314 | int ret = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3315 | struct be_queue_info *cq, *eq; |
| 3316 | struct be_dma_mem *mem; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3317 | struct be_eq_obj *pbe_eq; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3318 | void *cq_vaddress; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3319 | dma_addr_t paddr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3320 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3321 | num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \ |
| 3322 | sizeof(struct sol_cqe)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3323 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3324 | for (i = 0; i < phba->num_cpus; i++) { |
| 3325 | cq = &phwi_context->be_cq[i]; |
| 3326 | eq = &phwi_context->be_eq[i].q; |
| 3327 | pbe_eq = &phwi_context->be_eq[i]; |
| 3328 | pbe_eq->cq = cq; |
| 3329 | pbe_eq->phba = phba; |
| 3330 | mem = &cq->dma_mem; |
| 3331 | cq_vaddress = pci_alloc_consistent(phba->pcidev, |
| 3332 | num_cq_pages * PAGE_SIZE, |
| 3333 | &paddr); |
| 3334 | if (!cq_vaddress) |
| 3335 | goto create_cq_error; |
Jayamohan Kallickal | 7da5087 | 2010-01-05 05:04:12 +0530 | [diff] [blame] | 3336 | ret = be_fill_queue(cq, phba->params.num_cq_entries, |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3337 | sizeof(struct sol_cqe), cq_vaddress); |
| 3338 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3339 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3340 | "BM_%d : be_fill_queue Failed " |
| 3341 | "for ISCSI CQ\n"); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3342 | goto create_cq_error; |
| 3343 | } |
| 3344 | |
| 3345 | mem->dma = paddr; |
| 3346 | ret = beiscsi_cmd_cq_create(&phba->ctrl, cq, eq, false, |
| 3347 | false, 0); |
| 3348 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3349 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3350 | "BM_%d : beiscsi_cmd_eq_create" |
| 3351 | "Failed for ISCSI CQ\n"); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3352 | goto create_cq_error; |
| 3353 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3354 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3355 | "BM_%d : iscsi cq_id is %d for eq_id %d\n" |
| 3356 | "iSCSI CQ CREATED\n", cq->id, eq->id); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3357 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3358 | return 0; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3359 | |
| 3360 | create_cq_error: |
| 3361 | for (i = 0; i < phba->num_cpus; i++) { |
| 3362 | cq = &phwi_context->be_cq[i]; |
| 3363 | mem = &cq->dma_mem; |
| 3364 | if (mem->va) |
| 3365 | pci_free_consistent(phba->pcidev, num_cq_pages |
| 3366 | * PAGE_SIZE, |
| 3367 | mem->va, mem->dma); |
| 3368 | } |
| 3369 | return ret; |
| 3370 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3371 | } |
| 3372 | |
| 3373 | static int |
| 3374 | beiscsi_create_def_hdr(struct beiscsi_hba *phba, |
| 3375 | struct hwi_context_memory *phwi_context, |
| 3376 | struct hwi_controller *phwi_ctrlr, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3377 | unsigned int def_pdu_ring_sz, uint8_t ulp_num) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3378 | { |
| 3379 | unsigned int idx; |
| 3380 | int ret; |
| 3381 | struct be_queue_info *dq, *cq; |
| 3382 | struct be_dma_mem *mem; |
| 3383 | struct be_mem_descriptor *mem_descr; |
| 3384 | void *dq_vaddress; |
| 3385 | |
| 3386 | idx = 0; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3387 | dq = &phwi_context->be_def_hdrq[ulp_num]; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3388 | cq = &phwi_context->be_cq[0]; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3389 | mem = &dq->dma_mem; |
| 3390 | mem_descr = phba->init_mem; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3391 | mem_descr += HWI_MEM_ASYNC_HEADER_RING_ULP0 + |
| 3392 | (ulp_num * MEM_DESCR_OFFSET); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3393 | dq_vaddress = mem_descr->mem_array[idx].virtual_address; |
| 3394 | ret = be_fill_queue(dq, mem_descr->mem_array[0].size / |
| 3395 | sizeof(struct phys_addr), |
| 3396 | sizeof(struct phys_addr), dq_vaddress); |
| 3397 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3398 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3399 | "BM_%d : be_fill_queue Failed for DEF PDU HDR on ULP : %d\n", |
| 3400 | ulp_num); |
| 3401 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3402 | return ret; |
| 3403 | } |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 3404 | mem->dma = (unsigned long)mem_descr->mem_array[idx]. |
| 3405 | bus_address.u.a64.address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3406 | ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dq, |
| 3407 | def_pdu_ring_sz, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3408 | phba->params.defpdu_hdr_sz, |
| 3409 | BEISCSI_DEFQ_HDR, ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3410 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3411 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3412 | "BM_%d : be_cmd_create_default_pdu_queue Failed DEFHDR on ULP : %d\n", |
| 3413 | ulp_num); |
| 3414 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3415 | return ret; |
| 3416 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3417 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3418 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3419 | "BM_%d : iscsi hdr def pdu id for ULP : %d is %d\n", |
| 3420 | ulp_num, |
| 3421 | phwi_context->be_def_hdrq[ulp_num].id); |
| 3422 | hwi_post_async_buffers(phba, BEISCSI_DEFQ_HDR, ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3423 | return 0; |
| 3424 | } |
| 3425 | |
| 3426 | static int |
| 3427 | beiscsi_create_def_data(struct beiscsi_hba *phba, |
| 3428 | struct hwi_context_memory *phwi_context, |
| 3429 | struct hwi_controller *phwi_ctrlr, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3430 | unsigned int def_pdu_ring_sz, uint8_t ulp_num) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3431 | { |
| 3432 | unsigned int idx; |
| 3433 | int ret; |
| 3434 | struct be_queue_info *dataq, *cq; |
| 3435 | struct be_dma_mem *mem; |
| 3436 | struct be_mem_descriptor *mem_descr; |
| 3437 | void *dq_vaddress; |
| 3438 | |
| 3439 | idx = 0; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3440 | dataq = &phwi_context->be_def_dataq[ulp_num]; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3441 | cq = &phwi_context->be_cq[0]; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3442 | mem = &dataq->dma_mem; |
| 3443 | mem_descr = phba->init_mem; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3444 | mem_descr += HWI_MEM_ASYNC_DATA_RING_ULP0 + |
| 3445 | (ulp_num * MEM_DESCR_OFFSET); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3446 | dq_vaddress = mem_descr->mem_array[idx].virtual_address; |
| 3447 | ret = be_fill_queue(dataq, mem_descr->mem_array[0].size / |
| 3448 | sizeof(struct phys_addr), |
| 3449 | sizeof(struct phys_addr), dq_vaddress); |
| 3450 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3451 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3452 | "BM_%d : be_fill_queue Failed for DEF PDU " |
| 3453 | "DATA on ULP : %d\n", |
| 3454 | ulp_num); |
| 3455 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3456 | return ret; |
| 3457 | } |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 3458 | mem->dma = (unsigned long)mem_descr->mem_array[idx]. |
| 3459 | bus_address.u.a64.address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3460 | ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dataq, |
| 3461 | def_pdu_ring_sz, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3462 | phba->params.defpdu_data_sz, |
| 3463 | BEISCSI_DEFQ_DATA, ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3464 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3465 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3466 | "BM_%d be_cmd_create_default_pdu_queue" |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3467 | " Failed for DEF PDU DATA on ULP : %d\n", |
| 3468 | ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3469 | return ret; |
| 3470 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3471 | |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3472 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3473 | "BM_%d : iscsi def data id on ULP : %d is %d\n", |
| 3474 | ulp_num, |
| 3475 | phwi_context->be_def_dataq[ulp_num].id); |
| 3476 | |
| 3477 | hwi_post_async_buffers(phba, BEISCSI_DEFQ_DATA, ulp_num); |
| 3478 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3479 | "BM_%d : DEFAULT PDU DATA RING CREATED" |
| 3480 | "on ULP : %d\n", ulp_num); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3481 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3482 | return 0; |
| 3483 | } |
| 3484 | |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3485 | |
| 3486 | static int |
| 3487 | beiscsi_post_template_hdr(struct beiscsi_hba *phba) |
| 3488 | { |
| 3489 | struct be_mem_descriptor *mem_descr; |
| 3490 | struct mem_array *pm_arr; |
| 3491 | struct be_dma_mem sgl; |
Jayamohan Kallickal | a129d92 | 2013-09-28 15:35:46 -0700 | [diff] [blame] | 3492 | int status, ulp_num; |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3493 | |
Jayamohan Kallickal | a129d92 | 2013-09-28 15:35:46 -0700 | [diff] [blame] | 3494 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 3495 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
| 3496 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 3497 | mem_descr += HWI_MEM_TEMPLATE_HDR_ULP0 + |
| 3498 | (ulp_num * MEM_DESCR_OFFSET); |
| 3499 | pm_arr = mem_descr->mem_array; |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3500 | |
Jayamohan Kallickal | a129d92 | 2013-09-28 15:35:46 -0700 | [diff] [blame] | 3501 | hwi_build_be_sgl_arr(phba, pm_arr, &sgl); |
| 3502 | status = be_cmd_iscsi_post_template_hdr( |
| 3503 | &phba->ctrl, &sgl); |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3504 | |
Jayamohan Kallickal | a129d92 | 2013-09-28 15:35:46 -0700 | [diff] [blame] | 3505 | if (status != 0) { |
| 3506 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3507 | "BM_%d : Post Template HDR Failed for" |
| 3508 | "ULP_%d\n", ulp_num); |
| 3509 | return status; |
| 3510 | } |
| 3511 | |
| 3512 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3513 | "BM_%d : Template HDR Pages Posted for" |
| 3514 | "ULP_%d\n", ulp_num); |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3515 | } |
| 3516 | } |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3517 | return 0; |
| 3518 | } |
| 3519 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3520 | static int |
| 3521 | beiscsi_post_pages(struct beiscsi_hba *phba) |
| 3522 | { |
| 3523 | struct be_mem_descriptor *mem_descr; |
| 3524 | struct mem_array *pm_arr; |
| 3525 | unsigned int page_offset, i; |
| 3526 | struct be_dma_mem sgl; |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 3527 | int status, ulp_num = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3528 | |
| 3529 | mem_descr = phba->init_mem; |
| 3530 | mem_descr += HWI_MEM_SGE; |
| 3531 | pm_arr = mem_descr->mem_array; |
| 3532 | |
Jayamohan Kallickal | 90622db | 2013-09-28 15:35:47 -0700 | [diff] [blame] | 3533 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) |
| 3534 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) |
| 3535 | break; |
| 3536 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3537 | page_offset = (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io * |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 3538 | phba->fw_config.iscsi_icd_start[ulp_num]) / PAGE_SIZE; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3539 | for (i = 0; i < mem_descr->num_elements; i++) { |
| 3540 | hwi_build_be_sgl_arr(phba, pm_arr, &sgl); |
| 3541 | status = be_cmd_iscsi_post_sgl_pages(&phba->ctrl, &sgl, |
| 3542 | page_offset, |
| 3543 | (pm_arr->size / PAGE_SIZE)); |
| 3544 | page_offset += pm_arr->size / PAGE_SIZE; |
| 3545 | if (status != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3546 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3547 | "BM_%d : post sgl failed.\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3548 | return status; |
| 3549 | } |
| 3550 | pm_arr++; |
| 3551 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3552 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3553 | "BM_%d : POSTED PAGES\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3554 | return 0; |
| 3555 | } |
| 3556 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3557 | static void be_queue_free(struct beiscsi_hba *phba, struct be_queue_info *q) |
| 3558 | { |
| 3559 | struct be_dma_mem *mem = &q->dma_mem; |
Jayamohan Kallickal | c8b2559 | 2012-04-03 23:41:42 -0500 | [diff] [blame] | 3560 | if (mem->va) { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3561 | pci_free_consistent(phba->pcidev, mem->size, |
| 3562 | mem->va, mem->dma); |
Jayamohan Kallickal | c8b2559 | 2012-04-03 23:41:42 -0500 | [diff] [blame] | 3563 | mem->va = NULL; |
| 3564 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3565 | } |
| 3566 | |
| 3567 | static int be_queue_alloc(struct beiscsi_hba *phba, struct be_queue_info *q, |
| 3568 | u16 len, u16 entry_size) |
| 3569 | { |
| 3570 | struct be_dma_mem *mem = &q->dma_mem; |
| 3571 | |
| 3572 | memset(q, 0, sizeof(*q)); |
| 3573 | q->len = len; |
| 3574 | q->entry_size = entry_size; |
| 3575 | mem->size = len * entry_size; |
Joe Perches | 7c845eb | 2014-08-08 14:24:46 -0700 | [diff] [blame] | 3576 | mem->va = pci_zalloc_consistent(phba->pcidev, mem->size, &mem->dma); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3577 | if (!mem->va) |
Jayamohan Kallickal | d3ad2bb | 2010-07-22 04:16:38 +0530 | [diff] [blame] | 3578 | return -ENOMEM; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3579 | return 0; |
| 3580 | } |
| 3581 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3582 | static int |
| 3583 | beiscsi_create_wrb_rings(struct beiscsi_hba *phba, |
| 3584 | struct hwi_context_memory *phwi_context, |
| 3585 | struct hwi_controller *phwi_ctrlr) |
| 3586 | { |
| 3587 | unsigned int wrb_mem_index, offset, size, num_wrb_rings; |
| 3588 | u64 pa_addr_lo; |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 3589 | unsigned int idx, num, i, ulp_num; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3590 | struct mem_array *pwrb_arr; |
| 3591 | void *wrb_vaddr; |
| 3592 | struct be_dma_mem sgl; |
| 3593 | struct be_mem_descriptor *mem_descr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 3594 | struct hwi_wrb_context *pwrb_context; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3595 | int status; |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 3596 | uint8_t ulp_count = 0, ulp_base_num = 0; |
| 3597 | uint16_t cid_count_ulp[BEISCSI_ULP_COUNT] = { 0 }; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3598 | |
| 3599 | idx = 0; |
| 3600 | mem_descr = phba->init_mem; |
| 3601 | mem_descr += HWI_MEM_WRB; |
| 3602 | pwrb_arr = kmalloc(sizeof(*pwrb_arr) * phba->params.cxns_per_ctrl, |
| 3603 | GFP_KERNEL); |
| 3604 | if (!pwrb_arr) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3605 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3606 | "BM_%d : Memory alloc failed in create wrb ring.\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3607 | return -ENOMEM; |
| 3608 | } |
| 3609 | wrb_vaddr = mem_descr->mem_array[idx].virtual_address; |
| 3610 | pa_addr_lo = mem_descr->mem_array[idx].bus_address.u.a64.address; |
| 3611 | num_wrb_rings = mem_descr->mem_array[idx].size / |
| 3612 | (phba->params.wrbs_per_cxn * sizeof(struct iscsi_wrb)); |
| 3613 | |
| 3614 | for (num = 0; num < phba->params.cxns_per_ctrl; num++) { |
| 3615 | if (num_wrb_rings) { |
| 3616 | pwrb_arr[num].virtual_address = wrb_vaddr; |
| 3617 | pwrb_arr[num].bus_address.u.a64.address = pa_addr_lo; |
| 3618 | pwrb_arr[num].size = phba->params.wrbs_per_cxn * |
| 3619 | sizeof(struct iscsi_wrb); |
| 3620 | wrb_vaddr += pwrb_arr[num].size; |
| 3621 | pa_addr_lo += pwrb_arr[num].size; |
| 3622 | num_wrb_rings--; |
| 3623 | } else { |
| 3624 | idx++; |
| 3625 | wrb_vaddr = mem_descr->mem_array[idx].virtual_address; |
| 3626 | pa_addr_lo = mem_descr->mem_array[idx].\ |
| 3627 | bus_address.u.a64.address; |
| 3628 | num_wrb_rings = mem_descr->mem_array[idx].size / |
| 3629 | (phba->params.wrbs_per_cxn * |
| 3630 | sizeof(struct iscsi_wrb)); |
| 3631 | pwrb_arr[num].virtual_address = wrb_vaddr; |
| 3632 | pwrb_arr[num].bus_address.u.a64.address\ |
| 3633 | = pa_addr_lo; |
| 3634 | pwrb_arr[num].size = phba->params.wrbs_per_cxn * |
| 3635 | sizeof(struct iscsi_wrb); |
| 3636 | wrb_vaddr += pwrb_arr[num].size; |
| 3637 | pa_addr_lo += pwrb_arr[num].size; |
| 3638 | num_wrb_rings--; |
| 3639 | } |
| 3640 | } |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 3641 | |
| 3642 | /* Get the ULP Count */ |
| 3643 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) |
| 3644 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
| 3645 | ulp_count++; |
| 3646 | ulp_base_num = ulp_num; |
| 3647 | cid_count_ulp[ulp_num] = |
| 3648 | BEISCSI_GET_CID_COUNT(phba, ulp_num); |
| 3649 | } |
| 3650 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3651 | for (i = 0; i < phba->params.cxns_per_ctrl; i++) { |
| 3652 | wrb_mem_index = 0; |
| 3653 | offset = 0; |
| 3654 | size = 0; |
| 3655 | |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 3656 | if (ulp_count > 1) { |
| 3657 | ulp_base_num = (ulp_base_num + 1) % BEISCSI_ULP_COUNT; |
| 3658 | |
| 3659 | if (!cid_count_ulp[ulp_base_num]) |
| 3660 | ulp_base_num = (ulp_base_num + 1) % |
| 3661 | BEISCSI_ULP_COUNT; |
| 3662 | |
| 3663 | cid_count_ulp[ulp_base_num]--; |
| 3664 | } |
| 3665 | |
| 3666 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3667 | hwi_build_be_sgl_by_offset(phba, &pwrb_arr[i], &sgl); |
| 3668 | status = be_cmd_wrbq_create(&phba->ctrl, &sgl, |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 3669 | &phwi_context->be_wrbq[i], |
| 3670 | &phwi_ctrlr->wrb_context[i], |
| 3671 | ulp_base_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3672 | if (status != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3673 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3674 | "BM_%d : wrbq create failed."); |
Dan Carpenter | 1462b8f | 2010-06-10 09:52:21 +0200 | [diff] [blame] | 3675 | kfree(pwrb_arr); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3676 | return status; |
| 3677 | } |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 3678 | pwrb_context = &phwi_ctrlr->wrb_context[i]; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 3679 | BE_SET_CID_TO_CRI(i, pwrb_context->cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3680 | } |
| 3681 | kfree(pwrb_arr); |
| 3682 | return 0; |
| 3683 | } |
| 3684 | |
| 3685 | static void free_wrb_handles(struct beiscsi_hba *phba) |
| 3686 | { |
| 3687 | unsigned int index; |
| 3688 | struct hwi_controller *phwi_ctrlr; |
| 3689 | struct hwi_wrb_context *pwrb_context; |
| 3690 | |
| 3691 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 3692 | for (index = 0; index < phba->params.cxns_per_ctrl; index++) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3693 | pwrb_context = &phwi_ctrlr->wrb_context[index]; |
| 3694 | kfree(pwrb_context->pwrb_handle_base); |
| 3695 | kfree(pwrb_context->pwrb_handle_basestd); |
| 3696 | } |
| 3697 | } |
| 3698 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3699 | static void be_mcc_queues_destroy(struct beiscsi_hba *phba) |
| 3700 | { |
| 3701 | struct be_queue_info *q; |
| 3702 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 3703 | |
| 3704 | q = &phba->ctrl.mcc_obj.q; |
John Soni Jose | 4e2bdf7 | 2015-04-25 08:17:31 +0530 | [diff] [blame] | 3705 | if (q->created) { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3706 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_MCCQ); |
John Soni Jose | 4e2bdf7 | 2015-04-25 08:17:31 +0530 | [diff] [blame] | 3707 | be_queue_free(phba, q); |
| 3708 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3709 | |
| 3710 | q = &phba->ctrl.mcc_obj.cq; |
John Soni Jose | 4e2bdf7 | 2015-04-25 08:17:31 +0530 | [diff] [blame] | 3711 | if (q->created) { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3712 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ); |
John Soni Jose | 4e2bdf7 | 2015-04-25 08:17:31 +0530 | [diff] [blame] | 3713 | be_queue_free(phba, q); |
| 3714 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3715 | } |
| 3716 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3717 | static void hwi_cleanup(struct beiscsi_hba *phba) |
| 3718 | { |
| 3719 | struct be_queue_info *q; |
| 3720 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 3721 | struct hwi_controller *phwi_ctrlr; |
| 3722 | struct hwi_context_memory *phwi_context; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 3723 | struct hwi_async_pdu_context *pasync_ctx; |
Jayamohan Kallickal | 2318816 | 2014-05-05 21:41:29 -0400 | [diff] [blame] | 3724 | int i, eq_for_mcc, ulp_num; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3725 | |
| 3726 | phwi_ctrlr = phba->phwi_ctrlr; |
| 3727 | phwi_context = phwi_ctrlr->phwi_ctxt; |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3728 | |
| 3729 | be_cmd_iscsi_remove_template_hdr(ctrl); |
| 3730 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3731 | for (i = 0; i < phba->params.cxns_per_ctrl; i++) { |
| 3732 | q = &phwi_context->be_wrbq[i]; |
| 3733 | if (q->created) |
| 3734 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_WRBQ); |
| 3735 | } |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 3736 | kfree(phwi_context->be_wrbq); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3737 | free_wrb_handles(phba); |
| 3738 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3739 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 3740 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3741 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3742 | q = &phwi_context->be_def_hdrq[ulp_num]; |
| 3743 | if (q->created) |
| 3744 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ); |
| 3745 | |
| 3746 | q = &phwi_context->be_def_dataq[ulp_num]; |
| 3747 | if (q->created) |
| 3748 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ); |
| 3749 | |
| 3750 | pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num]; |
| 3751 | } |
| 3752 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3753 | |
| 3754 | beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL); |
| 3755 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3756 | for (i = 0; i < (phba->num_cpus); i++) { |
| 3757 | q = &phwi_context->be_cq[i]; |
John Soni Jose | 4e2bdf7 | 2015-04-25 08:17:31 +0530 | [diff] [blame] | 3758 | if (q->created) { |
| 3759 | be_queue_free(phba, q); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3760 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ); |
John Soni Jose | 4e2bdf7 | 2015-04-25 08:17:31 +0530 | [diff] [blame] | 3761 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3762 | } |
Jayamohan Kallickal | 2318816 | 2014-05-05 21:41:29 -0400 | [diff] [blame] | 3763 | |
| 3764 | be_mcc_queues_destroy(phba); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3765 | if (phba->msix_enabled) |
Jayamohan Kallickal | 2318816 | 2014-05-05 21:41:29 -0400 | [diff] [blame] | 3766 | eq_for_mcc = 1; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3767 | else |
Jayamohan Kallickal | 2318816 | 2014-05-05 21:41:29 -0400 | [diff] [blame] | 3768 | eq_for_mcc = 0; |
| 3769 | for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3770 | q = &phwi_context->be_eq[i].q; |
John Soni Jose | 4e2bdf7 | 2015-04-25 08:17:31 +0530 | [diff] [blame] | 3771 | if (q->created) { |
| 3772 | be_queue_free(phba, q); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3773 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_EQ); |
John Soni Jose | 4e2bdf7 | 2015-04-25 08:17:31 +0530 | [diff] [blame] | 3774 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3775 | } |
Jayamohan Kallickal | 0283fbb | 2013-04-05 20:38:21 -0700 | [diff] [blame] | 3776 | be_cmd_fw_uninit(ctrl); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3777 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3778 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3779 | static int be_mcc_queues_create(struct beiscsi_hba *phba, |
| 3780 | struct hwi_context_memory *phwi_context) |
| 3781 | { |
| 3782 | struct be_queue_info *q, *cq; |
| 3783 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 3784 | |
| 3785 | /* Alloc MCC compl queue */ |
| 3786 | cq = &phba->ctrl.mcc_obj.cq; |
| 3787 | if (be_queue_alloc(phba, cq, MCC_CQ_LEN, |
| 3788 | sizeof(struct be_mcc_compl))) |
| 3789 | goto err; |
| 3790 | /* Ask BE to create MCC compl queue; */ |
| 3791 | if (phba->msix_enabled) { |
| 3792 | if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq |
| 3793 | [phba->num_cpus].q, false, true, 0)) |
| 3794 | goto mcc_cq_free; |
| 3795 | } else { |
| 3796 | if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq[0].q, |
| 3797 | false, true, 0)) |
| 3798 | goto mcc_cq_free; |
| 3799 | } |
| 3800 | |
| 3801 | /* Alloc MCC queue */ |
| 3802 | q = &phba->ctrl.mcc_obj.q; |
| 3803 | if (be_queue_alloc(phba, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb))) |
| 3804 | goto mcc_cq_destroy; |
| 3805 | |
| 3806 | /* Ask BE to create MCC queue */ |
Jayamohan Kallickal | 35e6601 | 2009-10-23 11:53:49 +0530 | [diff] [blame] | 3807 | if (beiscsi_cmd_mccq_create(phba, q, cq)) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3808 | goto mcc_q_free; |
| 3809 | |
| 3810 | return 0; |
| 3811 | |
| 3812 | mcc_q_free: |
| 3813 | be_queue_free(phba, q); |
| 3814 | mcc_cq_destroy: |
| 3815 | beiscsi_cmd_q_destroy(ctrl, cq, QTYPE_CQ); |
| 3816 | mcc_cq_free: |
| 3817 | be_queue_free(phba, cq); |
| 3818 | err: |
Jayamohan Kallickal | d3ad2bb | 2010-07-22 04:16:38 +0530 | [diff] [blame] | 3819 | return -ENOMEM; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3820 | } |
| 3821 | |
John Soni Jose | 107dfcb | 2012-10-20 04:42:13 +0530 | [diff] [blame] | 3822 | /** |
| 3823 | * find_num_cpus()- Get the CPU online count |
| 3824 | * @phba: ptr to priv structure |
| 3825 | * |
| 3826 | * CPU count is used for creating EQ. |
| 3827 | **/ |
| 3828 | static void find_num_cpus(struct beiscsi_hba *phba) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3829 | { |
| 3830 | int num_cpus = 0; |
| 3831 | |
| 3832 | num_cpus = num_online_cpus(); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3833 | |
John Soni Jose | 22abeef | 2012-10-20 04:43:32 +0530 | [diff] [blame] | 3834 | switch (phba->generation) { |
| 3835 | case BE_GEN2: |
| 3836 | case BE_GEN3: |
| 3837 | phba->num_cpus = (num_cpus > BEISCSI_MAX_NUM_CPUS) ? |
| 3838 | BEISCSI_MAX_NUM_CPUS : num_cpus; |
| 3839 | break; |
| 3840 | case BE_GEN4: |
Jayamohan Kallickal | 68c26a3 | 2013-09-28 15:35:54 -0700 | [diff] [blame] | 3841 | /* |
| 3842 | * If eqid_count == 1 fall back to |
| 3843 | * INTX mechanism |
| 3844 | **/ |
| 3845 | if (phba->fw_config.eqid_count == 1) { |
| 3846 | enable_msix = 0; |
| 3847 | phba->num_cpus = 1; |
| 3848 | return; |
| 3849 | } |
| 3850 | |
| 3851 | phba->num_cpus = |
| 3852 | (num_cpus > (phba->fw_config.eqid_count - 1)) ? |
| 3853 | (phba->fw_config.eqid_count - 1) : num_cpus; |
John Soni Jose | 22abeef | 2012-10-20 04:43:32 +0530 | [diff] [blame] | 3854 | break; |
| 3855 | default: |
| 3856 | phba->num_cpus = 1; |
| 3857 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3858 | } |
| 3859 | |
| 3860 | static int hwi_init_port(struct beiscsi_hba *phba) |
| 3861 | { |
| 3862 | struct hwi_controller *phwi_ctrlr; |
| 3863 | struct hwi_context_memory *phwi_context; |
| 3864 | unsigned int def_pdu_ring_sz; |
| 3865 | struct be_ctrl_info *ctrl = &phba->ctrl; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3866 | int status, ulp_num; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3867 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3868 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3869 | phwi_context = phwi_ctrlr->phwi_ctxt; |
Jayamohan Kallickal | 73af08e | 2014-05-05 21:41:26 -0400 | [diff] [blame] | 3870 | phwi_context->max_eqd = 128; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3871 | phwi_context->min_eqd = 0; |
Jayamohan Kallickal | 73af08e | 2014-05-05 21:41:26 -0400 | [diff] [blame] | 3872 | phwi_context->cur_eqd = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3873 | be_cmd_fw_initialize(&phba->ctrl); |
Jitendra Bhivare | 53aefe2 | 2016-01-20 14:10:53 +0530 | [diff] [blame] | 3874 | /* set optic state to unknown */ |
| 3875 | phba->optic_state = 0xff; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3876 | |
| 3877 | status = beiscsi_create_eqs(phba, phwi_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3878 | if (status != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3879 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3880 | "BM_%d : EQ not created\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3881 | goto error; |
| 3882 | } |
| 3883 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3884 | status = be_mcc_queues_create(phba, phwi_context); |
| 3885 | if (status != 0) |
| 3886 | goto error; |
| 3887 | |
| 3888 | status = mgmt_check_supported_fw(ctrl, phba); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3889 | if (status != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3890 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3891 | "BM_%d : Unsupported fw version\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3892 | goto error; |
| 3893 | } |
| 3894 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3895 | status = beiscsi_create_cqs(phba, phwi_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3896 | if (status != 0) { |
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 : CQ not created\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3899 | goto error; |
| 3900 | } |
| 3901 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3902 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 3903 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3904 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3905 | def_pdu_ring_sz = |
| 3906 | BEISCSI_GET_CID_COUNT(phba, ulp_num) * |
| 3907 | sizeof(struct phys_addr); |
| 3908 | |
| 3909 | status = beiscsi_create_def_hdr(phba, phwi_context, |
| 3910 | phwi_ctrlr, |
| 3911 | def_pdu_ring_sz, |
| 3912 | ulp_num); |
| 3913 | if (status != 0) { |
| 3914 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3915 | "BM_%d : Default Header not created for ULP : %d\n", |
| 3916 | ulp_num); |
| 3917 | goto error; |
| 3918 | } |
| 3919 | |
| 3920 | status = beiscsi_create_def_data(phba, phwi_context, |
| 3921 | phwi_ctrlr, |
| 3922 | def_pdu_ring_sz, |
| 3923 | ulp_num); |
| 3924 | if (status != 0) { |
| 3925 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3926 | "BM_%d : Default Data not created for ULP : %d\n", |
| 3927 | ulp_num); |
| 3928 | goto error; |
| 3929 | } |
| 3930 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3931 | } |
| 3932 | |
| 3933 | status = beiscsi_post_pages(phba); |
| 3934 | if (status != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3935 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3936 | "BM_%d : Post SGL Pages Failed\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3937 | goto error; |
| 3938 | } |
| 3939 | |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3940 | status = beiscsi_post_template_hdr(phba); |
| 3941 | if (status != 0) { |
| 3942 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3943 | "BM_%d : Template HDR Posting for CXN Failed\n"); |
| 3944 | } |
| 3945 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3946 | status = beiscsi_create_wrb_rings(phba, phwi_context, phwi_ctrlr); |
| 3947 | if (status != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3948 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3949 | "BM_%d : WRB Rings not created\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3950 | goto error; |
| 3951 | } |
| 3952 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3953 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 3954 | uint16_t async_arr_idx = 0; |
| 3955 | |
| 3956 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
| 3957 | uint16_t cri = 0; |
| 3958 | struct hwi_async_pdu_context *pasync_ctx; |
| 3959 | |
| 3960 | pasync_ctx = HWI_GET_ASYNC_PDU_CTX( |
| 3961 | phwi_ctrlr, ulp_num); |
| 3962 | for (cri = 0; cri < |
| 3963 | phba->params.cxns_per_ctrl; cri++) { |
| 3964 | if (ulp_num == BEISCSI_GET_ULP_FROM_CRI |
| 3965 | (phwi_ctrlr, cri)) |
| 3966 | pasync_ctx->cid_to_async_cri_map[ |
| 3967 | phwi_ctrlr->wrb_context[cri].cid] = |
| 3968 | async_arr_idx++; |
| 3969 | } |
| 3970 | } |
| 3971 | } |
| 3972 | |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3973 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3974 | "BM_%d : hwi_init_port success\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3975 | return 0; |
| 3976 | |
| 3977 | error: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3978 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3979 | "BM_%d : hwi_init_port failed"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3980 | hwi_cleanup(phba); |
Jayamohan Kallickal | a49e06d | 2012-04-03 23:41:44 -0500 | [diff] [blame] | 3981 | return status; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3982 | } |
| 3983 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3984 | static int hwi_init_controller(struct beiscsi_hba *phba) |
| 3985 | { |
| 3986 | struct hwi_controller *phwi_ctrlr; |
| 3987 | |
| 3988 | phwi_ctrlr = phba->phwi_ctrlr; |
| 3989 | if (1 == phba->init_mem[HWI_MEM_ADDN_CONTEXT].num_elements) { |
| 3990 | phwi_ctrlr->phwi_ctxt = (struct hwi_context_memory *)phba-> |
| 3991 | init_mem[HWI_MEM_ADDN_CONTEXT].mem_array[0].virtual_address; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3992 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3993 | "BM_%d : phwi_ctrlr->phwi_ctxt=%p\n", |
| 3994 | phwi_ctrlr->phwi_ctxt); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3995 | } else { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3996 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3997 | "BM_%d : HWI_MEM_ADDN_CONTEXT is more " |
| 3998 | "than one element.Failing to load\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3999 | return -ENOMEM; |
| 4000 | } |
| 4001 | |
| 4002 | iscsi_init_global_templates(phba); |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 4003 | if (beiscsi_init_wrb_handle(phba)) |
| 4004 | return -ENOMEM; |
| 4005 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4006 | if (hwi_init_async_pdu_ctx(phba)) { |
| 4007 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4008 | "BM_%d : hwi_init_async_pdu_ctx failed\n"); |
| 4009 | return -ENOMEM; |
| 4010 | } |
| 4011 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4012 | if (hwi_init_port(phba) != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4013 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4014 | "BM_%d : hwi_init_controller failed\n"); |
| 4015 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4016 | return -ENOMEM; |
| 4017 | } |
| 4018 | return 0; |
| 4019 | } |
| 4020 | |
| 4021 | static void beiscsi_free_mem(struct beiscsi_hba *phba) |
| 4022 | { |
| 4023 | struct be_mem_descriptor *mem_descr; |
| 4024 | int i, j; |
| 4025 | |
| 4026 | mem_descr = phba->init_mem; |
| 4027 | i = 0; |
| 4028 | j = 0; |
| 4029 | for (i = 0; i < SE_MEM_MAX; i++) { |
| 4030 | for (j = mem_descr->num_elements; j > 0; j--) { |
| 4031 | pci_free_consistent(phba->pcidev, |
| 4032 | mem_descr->mem_array[j - 1].size, |
| 4033 | mem_descr->mem_array[j - 1].virtual_address, |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 4034 | (unsigned long)mem_descr->mem_array[j - 1]. |
| 4035 | bus_address.u.a64.address); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4036 | } |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 4037 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4038 | kfree(mem_descr->mem_array); |
| 4039 | mem_descr++; |
| 4040 | } |
| 4041 | kfree(phba->init_mem); |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4042 | kfree(phba->phwi_ctrlr->wrb_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4043 | kfree(phba->phwi_ctrlr); |
| 4044 | } |
| 4045 | |
| 4046 | static int beiscsi_init_controller(struct beiscsi_hba *phba) |
| 4047 | { |
| 4048 | int ret = -ENOMEM; |
| 4049 | |
| 4050 | ret = beiscsi_get_memory(phba); |
| 4051 | if (ret < 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4052 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4053 | "BM_%d : beiscsi_dev_probe -" |
| 4054 | "Failed in beiscsi_alloc_memory\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4055 | return ret; |
| 4056 | } |
| 4057 | |
| 4058 | ret = hwi_init_controller(phba); |
| 4059 | if (ret) |
| 4060 | goto free_init; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4061 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 4062 | "BM_%d : Return success from beiscsi_init_controller"); |
| 4063 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4064 | return 0; |
| 4065 | |
| 4066 | free_init: |
| 4067 | beiscsi_free_mem(phba); |
Jayamohan Kallickal | a49e06d | 2012-04-03 23:41:44 -0500 | [diff] [blame] | 4068 | return ret; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4069 | } |
| 4070 | |
| 4071 | static int beiscsi_init_sgl_handle(struct beiscsi_hba *phba) |
| 4072 | { |
| 4073 | struct be_mem_descriptor *mem_descr_sglh, *mem_descr_sg; |
| 4074 | struct sgl_handle *psgl_handle; |
| 4075 | struct iscsi_sge *pfrag; |
Jayamohan Kallickal | 90622db | 2013-09-28 15:35:47 -0700 | [diff] [blame] | 4076 | unsigned int arr_index, i, idx; |
| 4077 | unsigned int ulp_icd_start, ulp_num = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4078 | |
| 4079 | phba->io_sgl_hndl_avbl = 0; |
| 4080 | phba->eh_sgl_hndl_avbl = 0; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4081 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4082 | mem_descr_sglh = phba->init_mem; |
| 4083 | mem_descr_sglh += HWI_MEM_SGLH; |
| 4084 | if (1 == mem_descr_sglh->num_elements) { |
| 4085 | phba->io_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) * |
| 4086 | phba->params.ios_per_ctrl, |
| 4087 | GFP_KERNEL); |
| 4088 | if (!phba->io_sgl_hndl_base) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4089 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4090 | "BM_%d : Mem Alloc Failed. Failing to load\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4091 | return -ENOMEM; |
| 4092 | } |
| 4093 | phba->eh_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) * |
| 4094 | (phba->params.icds_per_ctrl - |
| 4095 | phba->params.ios_per_ctrl), |
| 4096 | GFP_KERNEL); |
| 4097 | if (!phba->eh_sgl_hndl_base) { |
| 4098 | kfree(phba->io_sgl_hndl_base); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4099 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4100 | "BM_%d : Mem Alloc Failed. Failing to load\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4101 | return -ENOMEM; |
| 4102 | } |
| 4103 | } else { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4104 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4105 | "BM_%d : HWI_MEM_SGLH is more than one element." |
| 4106 | "Failing to load\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4107 | return -ENOMEM; |
| 4108 | } |
| 4109 | |
| 4110 | arr_index = 0; |
| 4111 | idx = 0; |
| 4112 | while (idx < mem_descr_sglh->num_elements) { |
| 4113 | psgl_handle = mem_descr_sglh->mem_array[idx].virtual_address; |
| 4114 | |
| 4115 | for (i = 0; i < (mem_descr_sglh->mem_array[idx].size / |
| 4116 | sizeof(struct sgl_handle)); i++) { |
| 4117 | if (arr_index < phba->params.ios_per_ctrl) { |
| 4118 | phba->io_sgl_hndl_base[arr_index] = psgl_handle; |
| 4119 | phba->io_sgl_hndl_avbl++; |
| 4120 | arr_index++; |
| 4121 | } else { |
| 4122 | phba->eh_sgl_hndl_base[arr_index - |
| 4123 | phba->params.ios_per_ctrl] = |
| 4124 | psgl_handle; |
| 4125 | arr_index++; |
| 4126 | phba->eh_sgl_hndl_avbl++; |
| 4127 | } |
| 4128 | psgl_handle++; |
| 4129 | } |
| 4130 | idx++; |
| 4131 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4132 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 4133 | "BM_%d : phba->io_sgl_hndl_avbl=%d" |
| 4134 | "phba->eh_sgl_hndl_avbl=%d\n", |
| 4135 | phba->io_sgl_hndl_avbl, |
| 4136 | phba->eh_sgl_hndl_avbl); |
| 4137 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4138 | mem_descr_sg = phba->init_mem; |
| 4139 | mem_descr_sg += HWI_MEM_SGE; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4140 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 4141 | "\n BM_%d : mem_descr_sg->num_elements=%d\n", |
| 4142 | mem_descr_sg->num_elements); |
| 4143 | |
Jayamohan Kallickal | 90622db | 2013-09-28 15:35:47 -0700 | [diff] [blame] | 4144 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) |
| 4145 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) |
| 4146 | break; |
| 4147 | |
| 4148 | ulp_icd_start = phba->fw_config.iscsi_icd_start[ulp_num]; |
| 4149 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4150 | arr_index = 0; |
| 4151 | idx = 0; |
| 4152 | while (idx < mem_descr_sg->num_elements) { |
| 4153 | pfrag = mem_descr_sg->mem_array[idx].virtual_address; |
| 4154 | |
| 4155 | for (i = 0; |
| 4156 | i < (mem_descr_sg->mem_array[idx].size) / |
| 4157 | (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io); |
| 4158 | i++) { |
| 4159 | if (arr_index < phba->params.ios_per_ctrl) |
| 4160 | psgl_handle = phba->io_sgl_hndl_base[arr_index]; |
| 4161 | else |
| 4162 | psgl_handle = phba->eh_sgl_hndl_base[arr_index - |
| 4163 | phba->params.ios_per_ctrl]; |
| 4164 | psgl_handle->pfrag = pfrag; |
| 4165 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, pfrag, 0); |
| 4166 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, pfrag, 0); |
| 4167 | pfrag += phba->params.num_sge_per_io; |
Jayamohan Kallickal | 90622db | 2013-09-28 15:35:47 -0700 | [diff] [blame] | 4168 | psgl_handle->sgl_index = ulp_icd_start + arr_index++; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4169 | } |
| 4170 | idx++; |
| 4171 | } |
| 4172 | phba->io_sgl_free_index = 0; |
| 4173 | phba->io_sgl_alloc_index = 0; |
| 4174 | phba->eh_sgl_free_index = 0; |
| 4175 | phba->eh_sgl_alloc_index = 0; |
| 4176 | return 0; |
| 4177 | } |
| 4178 | |
| 4179 | static int hba_setup_cid_tbls(struct beiscsi_hba *phba) |
| 4180 | { |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4181 | int ret; |
| 4182 | uint16_t i, ulp_num; |
| 4183 | struct ulp_cid_info *ptr_cid_info = NULL; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4184 | |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4185 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 4186 | if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) { |
| 4187 | ptr_cid_info = kzalloc(sizeof(struct ulp_cid_info), |
| 4188 | GFP_KERNEL); |
| 4189 | |
| 4190 | if (!ptr_cid_info) { |
| 4191 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4192 | "BM_%d : Failed to allocate memory" |
| 4193 | "for ULP_CID_INFO for ULP : %d\n", |
| 4194 | ulp_num); |
| 4195 | ret = -ENOMEM; |
| 4196 | goto free_memory; |
| 4197 | |
| 4198 | } |
| 4199 | |
| 4200 | /* Allocate memory for CID array */ |
| 4201 | ptr_cid_info->cid_array = kzalloc(sizeof(void *) * |
| 4202 | BEISCSI_GET_CID_COUNT(phba, |
| 4203 | ulp_num), GFP_KERNEL); |
| 4204 | if (!ptr_cid_info->cid_array) { |
| 4205 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4206 | "BM_%d : Failed to allocate memory" |
| 4207 | "for CID_ARRAY for ULP : %d\n", |
| 4208 | ulp_num); |
| 4209 | kfree(ptr_cid_info); |
| 4210 | ptr_cid_info = NULL; |
| 4211 | ret = -ENOMEM; |
| 4212 | |
| 4213 | goto free_memory; |
| 4214 | } |
| 4215 | ptr_cid_info->avlbl_cids = BEISCSI_GET_CID_COUNT( |
| 4216 | phba, ulp_num); |
| 4217 | |
| 4218 | /* Save the cid_info_array ptr */ |
| 4219 | phba->cid_array_info[ulp_num] = ptr_cid_info; |
| 4220 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4221 | } |
Jayamohan Kallickal | c246228 | 2010-01-05 05:05:34 +0530 | [diff] [blame] | 4222 | phba->ep_array = kzalloc(sizeof(struct iscsi_endpoint *) * |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4223 | phba->params.cxns_per_ctrl, GFP_KERNEL); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4224 | if (!phba->ep_array) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4225 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4226 | "BM_%d : Failed to allocate memory in " |
| 4227 | "hba_setup_cid_tbls\n"); |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4228 | ret = -ENOMEM; |
| 4229 | |
| 4230 | goto free_memory; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4231 | } |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4232 | |
| 4233 | phba->conn_table = kzalloc(sizeof(struct beiscsi_conn *) * |
| 4234 | phba->params.cxns_per_ctrl, GFP_KERNEL); |
| 4235 | if (!phba->conn_table) { |
| 4236 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4237 | "BM_%d : Failed to allocate memory in" |
| 4238 | "hba_setup_cid_tbls\n"); |
| 4239 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4240 | kfree(phba->ep_array); |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4241 | phba->ep_array = NULL; |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4242 | ret = -ENOMEM; |
Tomas Henzl | 5f2d25e | 2014-06-06 14:06:30 +0200 | [diff] [blame] | 4243 | |
| 4244 | goto free_memory; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4245 | } |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4246 | |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4247 | for (i = 0; i < phba->params.cxns_per_ctrl; i++) { |
| 4248 | ulp_num = phba->phwi_ctrlr->wrb_context[i].ulp_num; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4249 | |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4250 | ptr_cid_info = phba->cid_array_info[ulp_num]; |
| 4251 | ptr_cid_info->cid_array[ptr_cid_info->cid_alloc++] = |
| 4252 | phba->phwi_ctrlr->wrb_context[i].cid; |
| 4253 | |
| 4254 | } |
| 4255 | |
| 4256 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 4257 | if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) { |
| 4258 | ptr_cid_info = phba->cid_array_info[ulp_num]; |
| 4259 | |
| 4260 | ptr_cid_info->cid_alloc = 0; |
| 4261 | ptr_cid_info->cid_free = 0; |
| 4262 | } |
| 4263 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4264 | return 0; |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4265 | |
| 4266 | free_memory: |
| 4267 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 4268 | if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) { |
| 4269 | ptr_cid_info = phba->cid_array_info[ulp_num]; |
| 4270 | |
| 4271 | if (ptr_cid_info) { |
| 4272 | kfree(ptr_cid_info->cid_array); |
| 4273 | kfree(ptr_cid_info); |
| 4274 | phba->cid_array_info[ulp_num] = NULL; |
| 4275 | } |
| 4276 | } |
| 4277 | } |
| 4278 | |
| 4279 | return ret; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4280 | } |
| 4281 | |
Jayamohan Kallickal | 238f6b7 | 2010-07-22 04:23:22 +0530 | [diff] [blame] | 4282 | static void hwi_enable_intr(struct beiscsi_hba *phba) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4283 | { |
| 4284 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 4285 | struct hwi_controller *phwi_ctrlr; |
| 4286 | struct hwi_context_memory *phwi_context; |
| 4287 | struct be_queue_info *eq; |
| 4288 | u8 __iomem *addr; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4289 | u32 reg, i; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4290 | u32 enabled; |
| 4291 | |
| 4292 | phwi_ctrlr = phba->phwi_ctrlr; |
| 4293 | phwi_context = phwi_ctrlr->phwi_ctxt; |
| 4294 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4295 | addr = (u8 __iomem *) ((u8 __iomem *) ctrl->pcicfg + |
| 4296 | PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET); |
| 4297 | reg = ioread32(addr); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4298 | |
| 4299 | enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
| 4300 | if (!enabled) { |
| 4301 | reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4302 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 4303 | "BM_%d : reg =x%08x addr=%p\n", reg, addr); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4304 | iowrite32(reg, addr); |
Jayamohan Kallickal | 665d6d9 | 2011-04-29 14:30:06 -0500 | [diff] [blame] | 4305 | } |
| 4306 | |
| 4307 | if (!phba->msix_enabled) { |
| 4308 | eq = &phwi_context->be_eq[0].q; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4309 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 4310 | "BM_%d : eq->id=%d\n", eq->id); |
| 4311 | |
Jayamohan Kallickal | 665d6d9 | 2011-04-29 14:30:06 -0500 | [diff] [blame] | 4312 | hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1); |
| 4313 | } else { |
| 4314 | for (i = 0; i <= phba->num_cpus; i++) { |
| 4315 | eq = &phwi_context->be_eq[i].q; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4316 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 4317 | "BM_%d : eq->id=%d\n", eq->id); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4318 | hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1); |
| 4319 | } |
Jayamohan Kallickal | c03af1a | 2010-02-20 08:05:43 +0530 | [diff] [blame] | 4320 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4321 | } |
| 4322 | |
| 4323 | static void hwi_disable_intr(struct beiscsi_hba *phba) |
| 4324 | { |
| 4325 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 4326 | |
| 4327 | u8 __iomem *addr = ctrl->pcicfg + PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET; |
| 4328 | u32 reg = ioread32(addr); |
| 4329 | |
| 4330 | u32 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
| 4331 | if (enabled) { |
| 4332 | reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
| 4333 | iowrite32(reg, addr); |
| 4334 | } else |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4335 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT, |
| 4336 | "BM_%d : In hwi_disable_intr, Already Disabled\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4337 | } |
| 4338 | |
John Soni Jose | 9aef420 | 2012-08-20 23:00:08 +0530 | [diff] [blame] | 4339 | /** |
| 4340 | * beiscsi_get_boot_info()- Get the boot session info |
| 4341 | * @phba: The device priv structure instance |
| 4342 | * |
| 4343 | * Get the boot target info and store in driver priv structure |
| 4344 | * |
| 4345 | * return values |
| 4346 | * Success: 0 |
| 4347 | * Failure: Non-Zero Value |
| 4348 | **/ |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4349 | static int beiscsi_get_boot_info(struct beiscsi_hba *phba) |
| 4350 | { |
Mike Christie | 0e43895 | 2012-04-03 23:41:51 -0500 | [diff] [blame] | 4351 | struct be_cmd_get_session_resp *session_resp; |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4352 | struct be_dma_mem nonemb_cmd; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 4353 | unsigned int tag; |
John Soni Jose | 9aef420 | 2012-08-20 23:00:08 +0530 | [diff] [blame] | 4354 | unsigned int s_handle; |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 4355 | int ret = -ENOMEM; |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4356 | |
John Soni Jose | 9aef420 | 2012-08-20 23:00:08 +0530 | [diff] [blame] | 4357 | /* Get the session handle of the boot target */ |
| 4358 | ret = be_mgmt_get_boot_shandle(phba, &s_handle); |
| 4359 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4360 | beiscsi_log(phba, KERN_ERR, |
| 4361 | BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG, |
| 4362 | "BM_%d : No boot session\n"); |
John Soni Jose | 3efde86 | 2015-04-25 08:16:57 +0530 | [diff] [blame] | 4363 | |
| 4364 | if (ret == -ENXIO) |
| 4365 | phba->get_boot = 0; |
| 4366 | |
| 4367 | |
John Soni Jose | 9aef420 | 2012-08-20 23:00:08 +0530 | [diff] [blame] | 4368 | return ret; |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4369 | } |
John Soni Jose | 3efde86 | 2015-04-25 08:16:57 +0530 | [diff] [blame] | 4370 | phba->get_boot = 0; |
Joe Perches | 7c845eb | 2014-08-08 14:24:46 -0700 | [diff] [blame] | 4371 | nonemb_cmd.va = pci_zalloc_consistent(phba->ctrl.pdev, |
| 4372 | sizeof(*session_resp), |
| 4373 | &nonemb_cmd.dma); |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4374 | if (nonemb_cmd.va == NULL) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4375 | beiscsi_log(phba, KERN_ERR, |
| 4376 | BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG, |
| 4377 | "BM_%d : Failed to allocate memory for" |
| 4378 | "beiscsi_get_session_info\n"); |
| 4379 | |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4380 | return -ENOMEM; |
| 4381 | } |
| 4382 | |
John Soni Jose | 9aef420 | 2012-08-20 23:00:08 +0530 | [diff] [blame] | 4383 | tag = mgmt_get_session_info(phba, s_handle, |
Mike Christie | 0e43895 | 2012-04-03 23:41:51 -0500 | [diff] [blame] | 4384 | &nonemb_cmd); |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4385 | if (!tag) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4386 | beiscsi_log(phba, KERN_ERR, |
| 4387 | BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG, |
| 4388 | "BM_%d : beiscsi_get_session_info" |
| 4389 | " Failed\n"); |
| 4390 | |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4391 | goto boot_freemem; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 4392 | } |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4393 | |
Jitendra Bhivare | 8884033 | 2016-02-04 15:49:12 +0530 | [diff] [blame] | 4394 | ret = beiscsi_mccq_compl_wait(phba, tag, NULL, &nonemb_cmd); |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 4395 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4396 | beiscsi_log(phba, KERN_ERR, |
| 4397 | BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG, |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 4398 | "BM_%d : beiscsi_get_session_info Failed"); |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 4399 | |
| 4400 | if (ret != -EBUSY) |
| 4401 | goto boot_freemem; |
| 4402 | else |
| 4403 | return ret; |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4404 | } |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 4405 | |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4406 | session_resp = nonemb_cmd.va ; |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 4407 | |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4408 | memcpy(&phba->boot_sess, &session_resp->session_info, |
| 4409 | sizeof(struct mgmt_session_info)); |
John Soni Jose | 3f4134c | 2015-04-25 08:18:13 +0530 | [diff] [blame] | 4410 | |
| 4411 | beiscsi_logout_fw_sess(phba, |
| 4412 | phba->boot_sess.session_handle); |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 4413 | ret = 0; |
| 4414 | |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4415 | boot_freemem: |
| 4416 | pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size, |
| 4417 | nonemb_cmd.va, nonemb_cmd.dma); |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 4418 | return ret; |
| 4419 | } |
| 4420 | |
| 4421 | static void beiscsi_boot_release(void *data) |
| 4422 | { |
| 4423 | struct beiscsi_hba *phba = data; |
| 4424 | |
| 4425 | scsi_host_put(phba->shost); |
| 4426 | } |
| 4427 | |
| 4428 | static int beiscsi_setup_boot_info(struct beiscsi_hba *phba) |
| 4429 | { |
| 4430 | struct iscsi_boot_kobj *boot_kobj; |
| 4431 | |
Jayamohan Kallickal | a3d313e | 2014-08-08 01:00:00 -0400 | [diff] [blame] | 4432 | /* it has been created previously */ |
| 4433 | if (phba->boot_kset) |
| 4434 | return 0; |
| 4435 | |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 4436 | /* get boot info using mgmt cmd */ |
| 4437 | if (beiscsi_get_boot_info(phba)) |
| 4438 | /* Try to see if we can carry on without this */ |
| 4439 | return 0; |
| 4440 | |
| 4441 | phba->boot_kset = iscsi_boot_create_host_kset(phba->shost->host_no); |
| 4442 | if (!phba->boot_kset) |
| 4443 | return -ENOMEM; |
| 4444 | |
| 4445 | /* get a ref because the show function will ref the phba */ |
| 4446 | if (!scsi_host_get(phba->shost)) |
| 4447 | goto free_kset; |
| 4448 | boot_kobj = iscsi_boot_create_target(phba->boot_kset, 0, phba, |
| 4449 | beiscsi_show_boot_tgt_info, |
| 4450 | beiscsi_tgt_get_attr_visibility, |
| 4451 | beiscsi_boot_release); |
| 4452 | if (!boot_kobj) |
| 4453 | goto put_shost; |
| 4454 | |
| 4455 | if (!scsi_host_get(phba->shost)) |
| 4456 | goto free_kset; |
| 4457 | boot_kobj = iscsi_boot_create_initiator(phba->boot_kset, 0, phba, |
| 4458 | beiscsi_show_boot_ini_info, |
| 4459 | beiscsi_ini_get_attr_visibility, |
| 4460 | beiscsi_boot_release); |
| 4461 | if (!boot_kobj) |
| 4462 | goto put_shost; |
| 4463 | |
| 4464 | if (!scsi_host_get(phba->shost)) |
| 4465 | goto free_kset; |
| 4466 | boot_kobj = iscsi_boot_create_ethernet(phba->boot_kset, 0, phba, |
| 4467 | beiscsi_show_boot_eth_info, |
| 4468 | beiscsi_eth_get_attr_visibility, |
| 4469 | beiscsi_boot_release); |
| 4470 | if (!boot_kobj) |
| 4471 | goto put_shost; |
| 4472 | return 0; |
| 4473 | |
| 4474 | put_shost: |
| 4475 | scsi_host_put(phba->shost); |
| 4476 | free_kset: |
| 4477 | iscsi_boot_destroy_kset(phba->boot_kset); |
Maurizio Lombardi | 84bd649 | 2016-03-04 10:41:49 +0100 | [diff] [blame] | 4478 | phba->boot_kset = NULL; |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4479 | return -ENOMEM; |
| 4480 | } |
| 4481 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4482 | static int beiscsi_init_port(struct beiscsi_hba *phba) |
| 4483 | { |
| 4484 | int ret; |
| 4485 | |
| 4486 | ret = beiscsi_init_controller(phba); |
| 4487 | if (ret < 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4488 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4489 | "BM_%d : beiscsi_dev_probe - Failed in" |
| 4490 | "beiscsi_init_controller\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4491 | return ret; |
| 4492 | } |
| 4493 | ret = beiscsi_init_sgl_handle(phba); |
| 4494 | if (ret < 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4495 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4496 | "BM_%d : beiscsi_dev_probe - Failed in" |
| 4497 | "beiscsi_init_sgl_handle\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4498 | goto do_cleanup_ctrlr; |
| 4499 | } |
| 4500 | |
| 4501 | if (hba_setup_cid_tbls(phba)) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4502 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4503 | "BM_%d : Failed in hba_setup_cid_tbls\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4504 | kfree(phba->io_sgl_hndl_base); |
| 4505 | kfree(phba->eh_sgl_hndl_base); |
| 4506 | goto do_cleanup_ctrlr; |
| 4507 | } |
| 4508 | |
| 4509 | return ret; |
| 4510 | |
| 4511 | do_cleanup_ctrlr: |
| 4512 | hwi_cleanup(phba); |
| 4513 | return ret; |
| 4514 | } |
| 4515 | |
| 4516 | static void hwi_purge_eq(struct beiscsi_hba *phba) |
| 4517 | { |
| 4518 | struct hwi_controller *phwi_ctrlr; |
| 4519 | struct hwi_context_memory *phwi_context; |
| 4520 | struct be_queue_info *eq; |
| 4521 | struct be_eq_entry *eqe = NULL; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4522 | int i, eq_msix; |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 4523 | unsigned int num_processed; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4524 | |
| 4525 | phwi_ctrlr = phba->phwi_ctrlr; |
| 4526 | phwi_context = phwi_ctrlr->phwi_ctxt; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4527 | if (phba->msix_enabled) |
| 4528 | eq_msix = 1; |
| 4529 | else |
| 4530 | eq_msix = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4531 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4532 | for (i = 0; i < (phba->num_cpus + eq_msix); i++) { |
| 4533 | eq = &phwi_context->be_eq[i].q; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4534 | eqe = queue_tail_node(eq); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 4535 | num_processed = 0; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4536 | while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32] |
| 4537 | & EQE_VALID_MASK) { |
| 4538 | AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0); |
| 4539 | queue_tail_inc(eq); |
| 4540 | eqe = queue_tail_node(eq); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 4541 | num_processed++; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4542 | } |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 4543 | |
| 4544 | if (num_processed) |
| 4545 | hwi_ring_eq_db(phba, eq->id, 1, num_processed, 1, 1); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4546 | } |
| 4547 | } |
| 4548 | |
| 4549 | static void beiscsi_clean_port(struct beiscsi_hba *phba) |
| 4550 | { |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4551 | int mgmt_status, ulp_num; |
| 4552 | struct ulp_cid_info *ptr_cid_info = NULL; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4553 | |
Jayamohan Kallickal | bd41c2b | 2013-09-28 15:35:51 -0700 | [diff] [blame] | 4554 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 4555 | if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) { |
| 4556 | mgmt_status = mgmt_epfw_cleanup(phba, ulp_num); |
| 4557 | if (mgmt_status) |
| 4558 | beiscsi_log(phba, KERN_WARNING, |
| 4559 | BEISCSI_LOG_INIT, |
| 4560 | "BM_%d : mgmt_epfw_cleanup FAILED" |
| 4561 | " for ULP_%d\n", ulp_num); |
| 4562 | } |
| 4563 | } |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 4564 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4565 | hwi_purge_eq(phba); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 4566 | hwi_cleanup(phba); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4567 | kfree(phba->io_sgl_hndl_base); |
| 4568 | kfree(phba->eh_sgl_hndl_base); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4569 | kfree(phba->ep_array); |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4570 | kfree(phba->conn_table); |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4571 | |
| 4572 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 4573 | if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) { |
| 4574 | ptr_cid_info = phba->cid_array_info[ulp_num]; |
| 4575 | |
| 4576 | if (ptr_cid_info) { |
| 4577 | kfree(ptr_cid_info->cid_array); |
| 4578 | kfree(ptr_cid_info); |
| 4579 | phba->cid_array_info[ulp_num] = NULL; |
| 4580 | } |
| 4581 | } |
| 4582 | } |
| 4583 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4584 | } |
| 4585 | |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 4586 | /** |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4587 | * beiscsi_free_mgmt_task_handles()- Free driver CXN resources |
| 4588 | * @beiscsi_conn: ptr to the conn to be cleaned up |
Jayamohan Kallickal | 4a4a11b | 2013-04-05 20:38:31 -0700 | [diff] [blame] | 4589 | * @task: ptr to iscsi_task resource to be freed. |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4590 | * |
| 4591 | * Free driver mgmt resources binded to CXN. |
| 4592 | **/ |
| 4593 | void |
Jayamohan Kallickal | 4a4a11b | 2013-04-05 20:38:31 -0700 | [diff] [blame] | 4594 | beiscsi_free_mgmt_task_handles(struct beiscsi_conn *beiscsi_conn, |
| 4595 | struct iscsi_task *task) |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4596 | { |
| 4597 | struct beiscsi_io_task *io_task; |
| 4598 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 4599 | struct hwi_wrb_context *pwrb_context; |
| 4600 | struct hwi_controller *phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4601 | uint16_t cri_index = BE_GET_CRI_FROM_CID( |
| 4602 | beiscsi_conn->beiscsi_conn_cid); |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4603 | |
| 4604 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4605 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
| 4606 | |
Jayamohan Kallickal | 4a4a11b | 2013-04-05 20:38:31 -0700 | [diff] [blame] | 4607 | io_task = task->dd_data; |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4608 | |
| 4609 | if (io_task->pwrb_handle) { |
| 4610 | memset(io_task->pwrb_handle->pwrb, 0, |
| 4611 | sizeof(struct iscsi_wrb)); |
| 4612 | free_wrb_handle(phba, pwrb_context, |
| 4613 | io_task->pwrb_handle); |
| 4614 | io_task->pwrb_handle = NULL; |
| 4615 | } |
| 4616 | |
| 4617 | if (io_task->psgl_handle) { |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4618 | free_mgmt_sgl_handle(phba, |
| 4619 | io_task->psgl_handle); |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4620 | io_task->psgl_handle = NULL; |
| 4621 | } |
| 4622 | |
John Soni Jose | eb1c469 | 2015-04-25 08:17:45 +0530 | [diff] [blame] | 4623 | if (io_task->mtask_addr) { |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4624 | pci_unmap_single(phba->pcidev, |
| 4625 | io_task->mtask_addr, |
| 4626 | io_task->mtask_data_count, |
| 4627 | PCI_DMA_TODEVICE); |
John Soni Jose | eb1c469 | 2015-04-25 08:17:45 +0530 | [diff] [blame] | 4628 | io_task->mtask_addr = 0; |
| 4629 | } |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4630 | } |
| 4631 | |
| 4632 | /** |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 4633 | * beiscsi_cleanup_task()- Free driver resources of the task |
| 4634 | * @task: ptr to the iscsi task |
| 4635 | * |
| 4636 | **/ |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4637 | static void beiscsi_cleanup_task(struct iscsi_task *task) |
| 4638 | { |
| 4639 | struct beiscsi_io_task *io_task = task->dd_data; |
| 4640 | struct iscsi_conn *conn = task->conn; |
| 4641 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; |
| 4642 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 4643 | struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess; |
| 4644 | struct hwi_wrb_context *pwrb_context; |
| 4645 | struct hwi_controller *phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4646 | uint16_t cri_index = BE_GET_CRI_FROM_CID( |
| 4647 | beiscsi_conn->beiscsi_conn_cid); |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4648 | |
| 4649 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4650 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4651 | |
| 4652 | if (io_task->cmd_bhs) { |
| 4653 | pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs, |
| 4654 | io_task->bhs_pa.u.a64.address); |
| 4655 | io_task->cmd_bhs = NULL; |
| 4656 | } |
| 4657 | |
| 4658 | if (task->sc) { |
| 4659 | if (io_task->pwrb_handle) { |
| 4660 | free_wrb_handle(phba, pwrb_context, |
| 4661 | io_task->pwrb_handle); |
| 4662 | io_task->pwrb_handle = NULL; |
| 4663 | } |
| 4664 | |
| 4665 | if (io_task->psgl_handle) { |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4666 | free_io_sgl_handle(phba, io_task->psgl_handle); |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4667 | io_task->psgl_handle = NULL; |
| 4668 | } |
Jayamohan Kallickal | da33497 | 2014-01-29 02:16:44 -0500 | [diff] [blame] | 4669 | |
| 4670 | if (io_task->scsi_cmnd) { |
| 4671 | scsi_dma_unmap(io_task->scsi_cmnd); |
| 4672 | io_task->scsi_cmnd = NULL; |
| 4673 | } |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4674 | } else { |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4675 | if (!beiscsi_conn->login_in_progress) |
Jayamohan Kallickal | 4a4a11b | 2013-04-05 20:38:31 -0700 | [diff] [blame] | 4676 | beiscsi_free_mgmt_task_handles(beiscsi_conn, task); |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4677 | } |
| 4678 | } |
| 4679 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4680 | void |
| 4681 | beiscsi_offload_connection(struct beiscsi_conn *beiscsi_conn, |
| 4682 | struct beiscsi_offload_params *params) |
| 4683 | { |
| 4684 | struct wrb_handle *pwrb_handle; |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4685 | struct hwi_wrb_context *pwrb_context = NULL; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4686 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4687 | struct iscsi_task *task = beiscsi_conn->task; |
| 4688 | struct iscsi_session *session = task->conn->session; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4689 | u32 doorbell = 0; |
| 4690 | |
| 4691 | /* |
| 4692 | * We can always use 0 here because it is reserved by libiscsi for |
| 4693 | * login/startup related tasks. |
| 4694 | */ |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4695 | beiscsi_conn->login_in_progress = 0; |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 4696 | spin_lock_bh(&session->back_lock); |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4697 | beiscsi_cleanup_task(task); |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 4698 | spin_unlock_bh(&session->back_lock); |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4699 | |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4700 | pwrb_handle = alloc_wrb_handle(phba, beiscsi_conn->beiscsi_conn_cid, |
| 4701 | &pwrb_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4702 | |
John Soni Jose | acb9693 | 2012-10-20 04:44:35 +0530 | [diff] [blame] | 4703 | /* Check for the adapter family */ |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 4704 | if (is_chip_be2_be3r(phba)) |
John Soni Jose | acb9693 | 2012-10-20 04:44:35 +0530 | [diff] [blame] | 4705 | beiscsi_offload_cxn_v0(params, pwrb_handle, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4706 | phba->init_mem, |
| 4707 | pwrb_context); |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 4708 | else |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4709 | beiscsi_offload_cxn_v2(params, pwrb_handle, |
| 4710 | pwrb_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4711 | |
John Soni Jose | acb9693 | 2012-10-20 04:44:35 +0530 | [diff] [blame] | 4712 | be_dws_le_to_cpu(pwrb_handle->pwrb, |
| 4713 | sizeof(struct iscsi_target_context_update_wrb)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4714 | |
| 4715 | doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK; |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 4716 | doorbell |= (pwrb_handle->wrb_index & DB_DEF_PDU_WRB_INDEX_MASK) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4717 | << DB_DEF_PDU_WRB_INDEX_SHIFT; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4718 | doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT; |
Jayamohan Kallickal | 1e4be6f | 2013-09-28 15:35:50 -0700 | [diff] [blame] | 4719 | iowrite32(doorbell, phba->db_va + |
| 4720 | beiscsi_conn->doorbell_offset); |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame] | 4721 | |
| 4722 | /* |
| 4723 | * There is no completion for CONTEXT_UPDATE. The completion of next |
| 4724 | * WRB posted guarantees FW's processing and DMA'ing of it. |
| 4725 | * Use beiscsi_put_wrb_handle to put it back in the pool which makes |
| 4726 | * sure zero'ing or reuse of the WRB only after wrbs_per_cxn. |
| 4727 | */ |
| 4728 | beiscsi_put_wrb_handle(pwrb_context, pwrb_handle, |
| 4729 | phba->params.wrbs_per_cxn); |
| 4730 | beiscsi_log(phba, KERN_INFO, |
| 4731 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
| 4732 | "BM_%d : put CONTEXT_UPDATE pwrb_handle=%p free_index=0x%x wrb_handles_available=%d\n", |
| 4733 | pwrb_handle, pwrb_context->free_index, |
| 4734 | pwrb_context->wrb_handles_available); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4735 | } |
| 4736 | |
| 4737 | static void beiscsi_parse_pdu(struct iscsi_conn *conn, itt_t itt, |
| 4738 | int *index, int *age) |
| 4739 | { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4740 | *index = (int)itt; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4741 | if (age) |
| 4742 | *age = conn->session->age; |
| 4743 | } |
| 4744 | |
| 4745 | /** |
| 4746 | * beiscsi_alloc_pdu - allocates pdu and related resources |
| 4747 | * @task: libiscsi task |
| 4748 | * @opcode: opcode of pdu for task |
| 4749 | * |
| 4750 | * This is called with the session lock held. It will allocate |
| 4751 | * the wrb and sgl if needed for the command. And it will prep |
| 4752 | * the pdu's itt. beiscsi_parse_pdu will later translate |
| 4753 | * the pdu itt to the libiscsi task itt. |
| 4754 | */ |
| 4755 | static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode) |
| 4756 | { |
| 4757 | struct beiscsi_io_task *io_task = task->dd_data; |
| 4758 | struct iscsi_conn *conn = task->conn; |
| 4759 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; |
| 4760 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 4761 | struct hwi_wrb_context *pwrb_context; |
| 4762 | struct hwi_controller *phwi_ctrlr; |
| 4763 | itt_t itt; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4764 | uint16_t cri_index = 0; |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4765 | struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess; |
| 4766 | dma_addr_t paddr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4767 | |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4768 | io_task->cmd_bhs = pci_pool_alloc(beiscsi_sess->bhs_pool, |
Mike Christie | bc7acce | 2010-12-31 02:22:19 -0600 | [diff] [blame] | 4769 | GFP_ATOMIC, &paddr); |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4770 | if (!io_task->cmd_bhs) |
| 4771 | return -ENOMEM; |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4772 | io_task->bhs_pa.u.a64.address = paddr; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4773 | io_task->libiscsi_itt = (itt_t)task->itt; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4774 | io_task->conn = beiscsi_conn; |
| 4775 | |
| 4776 | task->hdr = (struct iscsi_hdr *)&io_task->cmd_bhs->iscsi_hdr; |
| 4777 | task->hdr_max = sizeof(struct be_cmd_bhs); |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4778 | io_task->psgl_handle = NULL; |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 4779 | io_task->pwrb_handle = NULL; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4780 | |
| 4781 | if (task->sc) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4782 | io_task->psgl_handle = alloc_io_sgl_handle(phba); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4783 | if (!io_task->psgl_handle) { |
| 4784 | beiscsi_log(phba, KERN_ERR, |
| 4785 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
| 4786 | "BM_%d : Alloc of IO_SGL_ICD Failed" |
| 4787 | "for the CID : %d\n", |
| 4788 | beiscsi_conn->beiscsi_conn_cid); |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4789 | goto free_hndls; |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4790 | } |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4791 | io_task->pwrb_handle = alloc_wrb_handle(phba, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4792 | beiscsi_conn->beiscsi_conn_cid, |
| 4793 | &io_task->pwrb_context); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4794 | if (!io_task->pwrb_handle) { |
| 4795 | beiscsi_log(phba, KERN_ERR, |
| 4796 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
| 4797 | "BM_%d : Alloc of WRB_HANDLE Failed" |
| 4798 | "for the CID : %d\n", |
| 4799 | beiscsi_conn->beiscsi_conn_cid); |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4800 | goto free_io_hndls; |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4801 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4802 | } else { |
| 4803 | io_task->scsi_cmnd = NULL; |
Jayamohan Kallickal | d7aea67 | 2010-01-05 05:08:39 +0530 | [diff] [blame] | 4804 | if ((opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN) { |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4805 | beiscsi_conn->task = task; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4806 | if (!beiscsi_conn->login_in_progress) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4807 | io_task->psgl_handle = (struct sgl_handle *) |
| 4808 | alloc_mgmt_sgl_handle(phba); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4809 | if (!io_task->psgl_handle) { |
| 4810 | beiscsi_log(phba, KERN_ERR, |
| 4811 | BEISCSI_LOG_IO | |
| 4812 | BEISCSI_LOG_CONFIG, |
| 4813 | "BM_%d : Alloc of MGMT_SGL_ICD Failed" |
| 4814 | "for the CID : %d\n", |
| 4815 | beiscsi_conn-> |
| 4816 | beiscsi_conn_cid); |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4817 | goto free_hndls; |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4818 | } |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4819 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4820 | beiscsi_conn->login_in_progress = 1; |
| 4821 | beiscsi_conn->plogin_sgl_handle = |
| 4822 | io_task->psgl_handle; |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4823 | io_task->pwrb_handle = |
| 4824 | alloc_wrb_handle(phba, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4825 | beiscsi_conn->beiscsi_conn_cid, |
| 4826 | &io_task->pwrb_context); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4827 | if (!io_task->pwrb_handle) { |
| 4828 | beiscsi_log(phba, KERN_ERR, |
| 4829 | BEISCSI_LOG_IO | |
| 4830 | BEISCSI_LOG_CONFIG, |
| 4831 | "BM_%d : Alloc of WRB_HANDLE Failed" |
| 4832 | "for the CID : %d\n", |
| 4833 | beiscsi_conn-> |
| 4834 | beiscsi_conn_cid); |
| 4835 | goto free_mgmt_hndls; |
| 4836 | } |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4837 | beiscsi_conn->plogin_wrb_handle = |
| 4838 | io_task->pwrb_handle; |
| 4839 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4840 | } else { |
| 4841 | io_task->psgl_handle = |
| 4842 | beiscsi_conn->plogin_sgl_handle; |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4843 | io_task->pwrb_handle = |
| 4844 | beiscsi_conn->plogin_wrb_handle; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4845 | } |
| 4846 | } else { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4847 | io_task->psgl_handle = alloc_mgmt_sgl_handle(phba); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4848 | if (!io_task->psgl_handle) { |
| 4849 | beiscsi_log(phba, KERN_ERR, |
| 4850 | BEISCSI_LOG_IO | |
| 4851 | BEISCSI_LOG_CONFIG, |
| 4852 | "BM_%d : Alloc of MGMT_SGL_ICD Failed" |
| 4853 | "for the CID : %d\n", |
| 4854 | beiscsi_conn-> |
| 4855 | beiscsi_conn_cid); |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4856 | goto free_hndls; |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4857 | } |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4858 | io_task->pwrb_handle = |
| 4859 | alloc_wrb_handle(phba, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4860 | beiscsi_conn->beiscsi_conn_cid, |
| 4861 | &io_task->pwrb_context); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4862 | if (!io_task->pwrb_handle) { |
| 4863 | beiscsi_log(phba, KERN_ERR, |
| 4864 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
| 4865 | "BM_%d : Alloc of WRB_HANDLE Failed" |
| 4866 | "for the CID : %d\n", |
| 4867 | beiscsi_conn->beiscsi_conn_cid); |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4868 | goto free_mgmt_hndls; |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4869 | } |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4870 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4871 | } |
| 4872 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4873 | itt = (itt_t) cpu_to_be32(((unsigned int)io_task->pwrb_handle-> |
| 4874 | wrb_index << 16) | (unsigned int) |
| 4875 | (io_task->psgl_handle->sgl_index)); |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 4876 | io_task->pwrb_handle->pio_handle = task; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4877 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4878 | io_task->cmd_bhs->iscsi_hdr.itt = itt; |
| 4879 | return 0; |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4880 | |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4881 | free_io_hndls: |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4882 | free_io_sgl_handle(phba, io_task->psgl_handle); |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4883 | goto free_hndls; |
| 4884 | free_mgmt_hndls: |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4885 | free_mgmt_sgl_handle(phba, io_task->psgl_handle); |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4886 | io_task->psgl_handle = NULL; |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4887 | free_hndls: |
| 4888 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4889 | cri_index = BE_GET_CRI_FROM_CID( |
| 4890 | beiscsi_conn->beiscsi_conn_cid); |
| 4891 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4892 | if (io_task->pwrb_handle) |
| 4893 | free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle); |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4894 | io_task->pwrb_handle = NULL; |
| 4895 | pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs, |
| 4896 | io_task->bhs_pa.u.a64.address); |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4897 | io_task->cmd_bhs = NULL; |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4898 | return -ENOMEM; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4899 | } |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4900 | int beiscsi_iotask_v2(struct iscsi_task *task, struct scatterlist *sg, |
| 4901 | unsigned int num_sg, unsigned int xferlen, |
| 4902 | unsigned int writedir) |
| 4903 | { |
| 4904 | |
| 4905 | struct beiscsi_io_task *io_task = task->dd_data; |
| 4906 | struct iscsi_conn *conn = task->conn; |
| 4907 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; |
| 4908 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 4909 | struct iscsi_wrb *pwrb = NULL; |
| 4910 | unsigned int doorbell = 0; |
| 4911 | |
| 4912 | pwrb = io_task->pwrb_handle->pwrb; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4913 | |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4914 | io_task->bhs_len = sizeof(struct be_cmd_bhs); |
| 4915 | |
| 4916 | if (writedir) { |
| 4917 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb, |
| 4918 | INI_WR_CMD); |
| 4919 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 1); |
| 4920 | } else { |
| 4921 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb, |
| 4922 | INI_RD_CMD); |
| 4923 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 0); |
| 4924 | } |
| 4925 | |
| 4926 | io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb_v2, |
| 4927 | type, pwrb); |
| 4928 | |
| 4929 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, lun, pwrb, |
| 4930 | cpu_to_be16(*(unsigned short *) |
| 4931 | &io_task->cmd_bhs->iscsi_hdr.lun)); |
| 4932 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb, xferlen); |
| 4933 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb, |
| 4934 | io_task->pwrb_handle->wrb_index); |
| 4935 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb, |
| 4936 | be32_to_cpu(task->cmdsn)); |
| 4937 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb, |
| 4938 | io_task->psgl_handle->sgl_index); |
| 4939 | |
| 4940 | hwi_write_sgl_v2(pwrb, sg, num_sg, io_task); |
| 4941 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4942 | io_task->pwrb_handle->wrb_index); |
| 4943 | if (io_task->pwrb_context->plast_wrb) |
| 4944 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, |
| 4945 | io_task->pwrb_context->plast_wrb, |
| 4946 | io_task->pwrb_handle->wrb_index); |
| 4947 | io_task->pwrb_context->plast_wrb = pwrb; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4948 | |
| 4949 | be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb)); |
| 4950 | |
| 4951 | doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK; |
| 4952 | doorbell |= (io_task->pwrb_handle->wrb_index & |
| 4953 | DB_DEF_PDU_WRB_INDEX_MASK) << |
| 4954 | DB_DEF_PDU_WRB_INDEX_SHIFT; |
| 4955 | doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT; |
Jayamohan Kallickal | 1e4be6f | 2013-09-28 15:35:50 -0700 | [diff] [blame] | 4956 | iowrite32(doorbell, phba->db_va + |
| 4957 | beiscsi_conn->doorbell_offset); |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4958 | return 0; |
| 4959 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4960 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4961 | static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg, |
| 4962 | unsigned int num_sg, unsigned int xferlen, |
| 4963 | unsigned int writedir) |
| 4964 | { |
| 4965 | |
| 4966 | struct beiscsi_io_task *io_task = task->dd_data; |
| 4967 | struct iscsi_conn *conn = task->conn; |
| 4968 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; |
| 4969 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 4970 | struct iscsi_wrb *pwrb = NULL; |
| 4971 | unsigned int doorbell = 0; |
| 4972 | |
| 4973 | pwrb = io_task->pwrb_handle->pwrb; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4974 | io_task->bhs_len = sizeof(struct be_cmd_bhs); |
| 4975 | |
| 4976 | if (writedir) { |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 4977 | AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb, |
| 4978 | INI_WR_CMD); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4979 | AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4980 | } else { |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 4981 | AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb, |
| 4982 | INI_RD_CMD); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4983 | AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0); |
| 4984 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4985 | |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4986 | io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb, |
| 4987 | type, pwrb); |
| 4988 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4989 | AMAP_SET_BITS(struct amap_iscsi_wrb, lun, pwrb, |
Jayamohan Kallickal | dc63aac | 2012-04-03 23:41:36 -0500 | [diff] [blame] | 4990 | cpu_to_be16(*(unsigned short *) |
| 4991 | &io_task->cmd_bhs->iscsi_hdr.lun)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4992 | AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, xferlen); |
| 4993 | AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb, |
| 4994 | io_task->pwrb_handle->wrb_index); |
| 4995 | AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, |
| 4996 | be32_to_cpu(task->cmdsn)); |
| 4997 | AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb, |
| 4998 | io_task->psgl_handle->sgl_index); |
| 4999 | |
| 5000 | hwi_write_sgl(pwrb, sg, num_sg, io_task); |
| 5001 | |
| 5002 | AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 5003 | io_task->pwrb_handle->wrb_index); |
| 5004 | if (io_task->pwrb_context->plast_wrb) |
| 5005 | AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, |
| 5006 | io_task->pwrb_context->plast_wrb, |
| 5007 | io_task->pwrb_handle->wrb_index); |
| 5008 | io_task->pwrb_context->plast_wrb = pwrb; |
| 5009 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5010 | be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb)); |
| 5011 | |
| 5012 | doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK; |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 5013 | doorbell |= (io_task->pwrb_handle->wrb_index & |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5014 | DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT; |
| 5015 | doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT; |
| 5016 | |
Jayamohan Kallickal | 1e4be6f | 2013-09-28 15:35:50 -0700 | [diff] [blame] | 5017 | iowrite32(doorbell, phba->db_va + |
| 5018 | beiscsi_conn->doorbell_offset); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5019 | return 0; |
| 5020 | } |
| 5021 | |
| 5022 | static int beiscsi_mtask(struct iscsi_task *task) |
| 5023 | { |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 5024 | struct beiscsi_io_task *io_task = task->dd_data; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5025 | struct iscsi_conn *conn = task->conn; |
| 5026 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; |
| 5027 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 5028 | struct iscsi_wrb *pwrb = NULL; |
| 5029 | unsigned int doorbell = 0; |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 5030 | unsigned int cid; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5031 | unsigned int pwrb_typeoffset = 0; |
Alexey Khoroshilov | e049362 | 2016-01-16 00:45:34 +0300 | [diff] [blame] | 5032 | int ret = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5033 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5034 | cid = beiscsi_conn->beiscsi_conn_cid; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5035 | pwrb = io_task->pwrb_handle->pwrb; |
Jayamohan Kallickal | caf818f | 2010-01-23 05:38:18 +0530 | [diff] [blame] | 5036 | memset(pwrb, 0, sizeof(*pwrb)); |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5037 | |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 5038 | if (is_chip_be2_be3r(phba)) { |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5039 | AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, |
| 5040 | be32_to_cpu(task->cmdsn)); |
| 5041 | AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb, |
| 5042 | io_task->pwrb_handle->wrb_index); |
| 5043 | AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb, |
| 5044 | io_task->psgl_handle->sgl_index); |
| 5045 | AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, |
| 5046 | task->data_count); |
| 5047 | AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 5048 | io_task->pwrb_handle->wrb_index); |
| 5049 | if (io_task->pwrb_context->plast_wrb) |
| 5050 | AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, |
| 5051 | io_task->pwrb_context->plast_wrb, |
| 5052 | io_task->pwrb_handle->wrb_index); |
| 5053 | io_task->pwrb_context->plast_wrb = pwrb; |
| 5054 | |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5055 | pwrb_typeoffset = BE_WRB_TYPE_OFFSET; |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 5056 | } else { |
| 5057 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb, |
| 5058 | be32_to_cpu(task->cmdsn)); |
| 5059 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb, |
| 5060 | io_task->pwrb_handle->wrb_index); |
| 5061 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb, |
| 5062 | io_task->psgl_handle->sgl_index); |
| 5063 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb, |
| 5064 | task->data_count); |
| 5065 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 5066 | io_task->pwrb_handle->wrb_index); |
| 5067 | if (io_task->pwrb_context->plast_wrb) |
| 5068 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, |
| 5069 | io_task->pwrb_context->plast_wrb, |
| 5070 | io_task->pwrb_handle->wrb_index); |
| 5071 | io_task->pwrb_context->plast_wrb = pwrb; |
| 5072 | |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 5073 | pwrb_typeoffset = SKH_WRB_TYPE_OFFSET; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5074 | } |
| 5075 | |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 5076 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5077 | switch (task->hdr->opcode & ISCSI_OPCODE_MASK) { |
| 5078 | case ISCSI_OP_LOGIN: |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5079 | AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, 1); |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5080 | ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset); |
Alexey Khoroshilov | e049362 | 2016-01-16 00:45:34 +0300 | [diff] [blame] | 5081 | ret = hwi_write_buffer(pwrb, task); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5082 | break; |
| 5083 | case ISCSI_OP_NOOP_OUT: |
Jayamohan Kallickal | 1390b01 | 2011-03-25 14:24:01 -0700 | [diff] [blame] | 5084 | if (task->hdr->ttt != ISCSI_RESERVED_TAG) { |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5085 | ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset); |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 5086 | if (is_chip_be2_be3r(phba)) |
| 5087 | AMAP_SET_BITS(struct amap_iscsi_wrb, |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5088 | dmsg, pwrb, 1); |
| 5089 | else |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 5090 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5091 | dmsg, pwrb, 1); |
Jayamohan Kallickal | 1390b01 | 2011-03-25 14:24:01 -0700 | [diff] [blame] | 5092 | } else { |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5093 | ADAPTER_SET_WRB_TYPE(pwrb, INI_RD_CMD, pwrb_typeoffset); |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 5094 | if (is_chip_be2_be3r(phba)) |
| 5095 | AMAP_SET_BITS(struct amap_iscsi_wrb, |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5096 | dmsg, pwrb, 0); |
| 5097 | else |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 5098 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5099 | dmsg, pwrb, 0); |
Jayamohan Kallickal | 1390b01 | 2011-03-25 14:24:01 -0700 | [diff] [blame] | 5100 | } |
Alexey Khoroshilov | e049362 | 2016-01-16 00:45:34 +0300 | [diff] [blame] | 5101 | ret = hwi_write_buffer(pwrb, task); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5102 | break; |
| 5103 | case ISCSI_OP_TEXT: |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5104 | ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset); |
Alexey Khoroshilov | e049362 | 2016-01-16 00:45:34 +0300 | [diff] [blame] | 5105 | ret = hwi_write_buffer(pwrb, task); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5106 | break; |
| 5107 | case ISCSI_OP_SCSI_TMFUNC: |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5108 | ADAPTER_SET_WRB_TYPE(pwrb, INI_TMF_CMD, pwrb_typeoffset); |
Alexey Khoroshilov | e049362 | 2016-01-16 00:45:34 +0300 | [diff] [blame] | 5109 | ret = hwi_write_buffer(pwrb, task); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5110 | break; |
| 5111 | case ISCSI_OP_LOGOUT: |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5112 | ADAPTER_SET_WRB_TYPE(pwrb, HWH_TYPE_LOGOUT, pwrb_typeoffset); |
Alexey Khoroshilov | e049362 | 2016-01-16 00:45:34 +0300 | [diff] [blame] | 5113 | ret = hwi_write_buffer(pwrb, task); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5114 | break; |
| 5115 | |
| 5116 | default: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5117 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
| 5118 | "BM_%d : opcode =%d Not supported\n", |
| 5119 | task->hdr->opcode & ISCSI_OPCODE_MASK); |
| 5120 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5121 | return -EINVAL; |
| 5122 | } |
| 5123 | |
Alexey Khoroshilov | e049362 | 2016-01-16 00:45:34 +0300 | [diff] [blame] | 5124 | if (ret) |
| 5125 | return ret; |
| 5126 | |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5127 | /* Set the task type */ |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 5128 | io_task->wrb_type = (is_chip_be2_be3r(phba)) ? |
| 5129 | AMAP_GET_BITS(struct amap_iscsi_wrb, type, pwrb) : |
| 5130 | AMAP_GET_BITS(struct amap_iscsi_wrb_v2, type, pwrb); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5131 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5132 | doorbell |= cid & DB_WRB_POST_CID_MASK; |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 5133 | doorbell |= (io_task->pwrb_handle->wrb_index & |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5134 | DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT; |
| 5135 | doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT; |
Jayamohan Kallickal | 1e4be6f | 2013-09-28 15:35:50 -0700 | [diff] [blame] | 5136 | iowrite32(doorbell, phba->db_va + |
| 5137 | beiscsi_conn->doorbell_offset); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5138 | return 0; |
| 5139 | } |
| 5140 | |
| 5141 | static int beiscsi_task_xmit(struct iscsi_task *task) |
| 5142 | { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5143 | struct beiscsi_io_task *io_task = task->dd_data; |
| 5144 | struct scsi_cmnd *sc = task->sc; |
Jitendra Bhivare | 1868379 | 2016-02-04 15:49:18 +0530 | [diff] [blame] | 5145 | struct beiscsi_hba *phba; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5146 | struct scatterlist *sg; |
| 5147 | int num_sg; |
| 5148 | unsigned int writedir = 0, xferlen = 0; |
| 5149 | |
Jitendra Bhivare | 1868379 | 2016-02-04 15:49:18 +0530 | [diff] [blame] | 5150 | if (!io_task->conn->login_in_progress) |
| 5151 | task->hdr->exp_statsn = 0; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5152 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5153 | if (!sc) |
| 5154 | return beiscsi_mtask(task); |
| 5155 | |
| 5156 | io_task->scsi_cmnd = sc; |
| 5157 | num_sg = scsi_dma_map(sc); |
Jitendra Bhivare | 1868379 | 2016-02-04 15:49:18 +0530 | [diff] [blame] | 5158 | phba = io_task->conn->phba; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5159 | if (num_sg < 0) { |
Jayamohan Kallickal | afb9605 | 2013-09-28 15:35:55 -0700 | [diff] [blame] | 5160 | beiscsi_log(phba, KERN_ERR, |
| 5161 | BEISCSI_LOG_IO | BEISCSI_LOG_ISCSI, |
| 5162 | "BM_%d : scsi_dma_map Failed " |
| 5163 | "Driver_ITT : 0x%x ITT : 0x%x Xferlen : 0x%x\n", |
| 5164 | be32_to_cpu(io_task->cmd_bhs->iscsi_hdr.itt), |
| 5165 | io_task->libiscsi_itt, scsi_bufflen(sc)); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5166 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5167 | return num_sg; |
| 5168 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5169 | xferlen = scsi_bufflen(sc); |
| 5170 | sg = scsi_sglist(sc); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5171 | if (sc->sc_data_direction == DMA_TO_DEVICE) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5172 | writedir = 1; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5173 | else |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5174 | writedir = 0; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5175 | |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5176 | return phba->iotask_fn(task, sg, num_sg, xferlen, writedir); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5177 | } |
| 5178 | |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 5179 | /** |
| 5180 | * beiscsi_bsg_request - handle bsg request from ISCSI transport |
| 5181 | * @job: job to handle |
| 5182 | */ |
| 5183 | static int beiscsi_bsg_request(struct bsg_job *job) |
| 5184 | { |
| 5185 | struct Scsi_Host *shost; |
| 5186 | struct beiscsi_hba *phba; |
| 5187 | struct iscsi_bsg_request *bsg_req = job->request; |
| 5188 | int rc = -EINVAL; |
| 5189 | unsigned int tag; |
| 5190 | struct be_dma_mem nonemb_cmd; |
| 5191 | struct be_cmd_resp_hdr *resp; |
| 5192 | struct iscsi_bsg_reply *bsg_reply = job->reply; |
| 5193 | unsigned short status, extd_status; |
| 5194 | |
| 5195 | shost = iscsi_job_to_shost(job); |
| 5196 | phba = iscsi_host_priv(shost); |
| 5197 | |
| 5198 | switch (bsg_req->msgcode) { |
| 5199 | case ISCSI_BSG_HST_VENDOR: |
| 5200 | nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev, |
| 5201 | job->request_payload.payload_len, |
| 5202 | &nonemb_cmd.dma); |
| 5203 | if (nonemb_cmd.va == NULL) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5204 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
| 5205 | "BM_%d : Failed to allocate memory for " |
| 5206 | "beiscsi_bsg_request\n"); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 5207 | return -ENOMEM; |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 5208 | } |
| 5209 | tag = mgmt_vendor_specific_fw_cmd(&phba->ctrl, phba, job, |
| 5210 | &nonemb_cmd); |
| 5211 | if (!tag) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5212 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 5213 | "BM_%d : MBX Tag Allocation Failed\n"); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5214 | |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 5215 | pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size, |
| 5216 | nonemb_cmd.va, nonemb_cmd.dma); |
| 5217 | return -EAGAIN; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 5218 | } |
| 5219 | |
| 5220 | rc = wait_event_interruptible_timeout( |
| 5221 | phba->ctrl.mcc_wait[tag], |
Jitendra Bhivare | 67296ad | 2016-02-04 15:49:10 +0530 | [diff] [blame] | 5222 | phba->ctrl.mcc_tag_status[tag], |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 5223 | msecs_to_jiffies( |
| 5224 | BEISCSI_HOST_MBX_TIMEOUT)); |
Jitendra Bhivare | 67296ad | 2016-02-04 15:49:10 +0530 | [diff] [blame] | 5225 | extd_status = (phba->ctrl.mcc_tag_status[tag] & |
| 5226 | CQE_STATUS_ADDL_MASK) >> CQE_STATUS_ADDL_SHIFT; |
| 5227 | status = phba->ctrl.mcc_tag_status[tag] & CQE_STATUS_MASK; |
Jitendra Bhivare | 090e218 | 2016-02-04 15:49:17 +0530 | [diff] [blame] | 5228 | free_mcc_wrb(&phba->ctrl, tag); |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 5229 | resp = (struct be_cmd_resp_hdr *)nonemb_cmd.va; |
| 5230 | sg_copy_from_buffer(job->reply_payload.sg_list, |
| 5231 | job->reply_payload.sg_cnt, |
| 5232 | nonemb_cmd.va, (resp->response_length |
| 5233 | + sizeof(*resp))); |
| 5234 | bsg_reply->reply_payload_rcv_len = resp->response_length; |
| 5235 | bsg_reply->result = status; |
| 5236 | bsg_job_done(job, bsg_reply->result, |
| 5237 | bsg_reply->reply_payload_rcv_len); |
| 5238 | pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size, |
| 5239 | nonemb_cmd.va, nonemb_cmd.dma); |
| 5240 | if (status || extd_status) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5241 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 5242 | "BM_%d : MBX Cmd Failed" |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5243 | " status = %d extd_status = %d\n", |
| 5244 | status, extd_status); |
| 5245 | |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 5246 | return -EIO; |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 5247 | } else { |
| 5248 | rc = 0; |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 5249 | } |
| 5250 | break; |
| 5251 | |
| 5252 | default: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5253 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
| 5254 | "BM_%d : Unsupported bsg command: 0x%x\n", |
| 5255 | bsg_req->msgcode); |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 5256 | break; |
| 5257 | } |
| 5258 | |
| 5259 | return rc; |
| 5260 | } |
| 5261 | |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5262 | void beiscsi_hba_attrs_init(struct beiscsi_hba *phba) |
| 5263 | { |
| 5264 | /* Set the logging parameter */ |
| 5265 | beiscsi_log_enable_init(phba, beiscsi_log_enable); |
| 5266 | } |
| 5267 | |
John Soni Jose | 4d4d1ef | 2012-10-20 04:42:37 +0530 | [diff] [blame] | 5268 | /* |
| 5269 | * beiscsi_quiesce()- Cleanup Driver resources |
| 5270 | * @phba: Instance Priv structure |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5271 | * @unload_state:i Clean or EEH unload state |
John Soni Jose | 4d4d1ef | 2012-10-20 04:42:37 +0530 | [diff] [blame] | 5272 | * |
| 5273 | * Free the OS and HW resources held by the driver |
| 5274 | **/ |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5275 | static void beiscsi_quiesce(struct beiscsi_hba *phba, |
| 5276 | uint32_t unload_state) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5277 | { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5278 | struct hwi_controller *phwi_ctrlr; |
| 5279 | struct hwi_context_memory *phwi_context; |
| 5280 | struct be_eq_obj *pbe_eq; |
| 5281 | unsigned int i, msix_vec; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5282 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5283 | phwi_ctrlr = phba->phwi_ctrlr; |
| 5284 | phwi_context = phwi_ctrlr->phwi_ctxt; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5285 | hwi_disable_intr(phba); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5286 | if (phba->msix_enabled) { |
| 5287 | for (i = 0; i <= phba->num_cpus; i++) { |
| 5288 | msix_vec = phba->msix_entries[i].vector; |
| 5289 | free_irq(msix_vec, &phwi_context->be_eq[i]); |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 5290 | kfree(phba->msi_name[i]); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5291 | } |
| 5292 | } else |
Lars-Peter Clausen | e729b50 | 2016-03-04 11:15:06 +0100 | [diff] [blame] | 5293 | if (phba->pcidev->irq) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5294 | free_irq(phba->pcidev->irq, phba); |
| 5295 | pci_disable_msix(phba->pcidev); |
John Soni Jose | 53281ed | 2014-09-26 15:13:55 -0400 | [diff] [blame] | 5296 | cancel_delayed_work_sync(&phba->beiscsi_hw_check_task); |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5297 | |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5298 | for (i = 0; i < phba->num_cpus; i++) { |
| 5299 | pbe_eq = &phwi_context->be_eq[i]; |
Christoph Hellwig | 511cbce | 2015-11-10 14:56:14 +0100 | [diff] [blame] | 5300 | irq_poll_disable(&pbe_eq->iopoll); |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5301 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5302 | |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5303 | if (unload_state == BEISCSI_CLEAN_UNLOAD) { |
| 5304 | destroy_workqueue(phba->wq); |
| 5305 | beiscsi_clean_port(phba); |
| 5306 | beiscsi_free_mem(phba); |
Jayamohan Kallickal | e9b9119 | 2010-07-22 04:24:53 +0530 | [diff] [blame] | 5307 | |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5308 | beiscsi_unmap_pci_function(phba); |
| 5309 | pci_free_consistent(phba->pcidev, |
| 5310 | phba->ctrl.mbox_mem_alloced.size, |
| 5311 | phba->ctrl.mbox_mem_alloced.va, |
| 5312 | phba->ctrl.mbox_mem_alloced.dma); |
| 5313 | } else { |
| 5314 | hwi_purge_eq(phba); |
| 5315 | hwi_cleanup(phba); |
| 5316 | } |
John Soni Jose | 7a15800 | 2012-10-20 04:45:51 +0530 | [diff] [blame] | 5317 | |
Jayamohan Kallickal | 25602c9 | 2011-08-22 10:08:28 -0700 | [diff] [blame] | 5318 | } |
| 5319 | |
| 5320 | static void beiscsi_remove(struct pci_dev *pcidev) |
| 5321 | { |
Jayamohan Kallickal | 25602c9 | 2011-08-22 10:08:28 -0700 | [diff] [blame] | 5322 | struct beiscsi_hba *phba = NULL; |
| 5323 | |
| 5324 | phba = pci_get_drvdata(pcidev); |
| 5325 | if (!phba) { |
| 5326 | dev_err(&pcidev->dev, "beiscsi_remove called with no phba\n"); |
| 5327 | return; |
| 5328 | } |
| 5329 | |
Jitendra Bhivare | 96b48b9 | 2016-08-19 15:20:06 +0530 | [diff] [blame^] | 5330 | beiscsi_iface_destroy_default(phba); |
Mike Christie | 9d04516 | 2011-06-24 15:11:52 -0500 | [diff] [blame] | 5331 | iscsi_boot_destroy_kset(phba->boot_kset); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5332 | iscsi_host_remove(phba->shost); |
Jitendra Bhivare | cdaa4de | 2016-01-20 14:10:51 +0530 | [diff] [blame] | 5333 | beiscsi_quiesce(phba, BEISCSI_CLEAN_UNLOAD); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5334 | pci_dev_put(phba->pcidev); |
| 5335 | iscsi_host_free(phba->shost); |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5336 | pci_disable_pcie_error_reporting(pcidev); |
| 5337 | pci_set_drvdata(pcidev, NULL); |
John Soni Jose | e307f3a | 2015-04-25 08:17:19 +0530 | [diff] [blame] | 5338 | pci_release_regions(pcidev); |
Jayamohan Kallickal | 8dce69f | 2011-08-22 10:08:29 -0700 | [diff] [blame] | 5339 | pci_disable_device(pcidev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5340 | } |
| 5341 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5342 | static void beiscsi_msix_enable(struct beiscsi_hba *phba) |
| 5343 | { |
| 5344 | int i, status; |
| 5345 | |
| 5346 | for (i = 0; i <= phba->num_cpus; i++) |
| 5347 | phba->msix_entries[i].entry = i; |
| 5348 | |
Alexander Gordeev | e149fc1 | 2014-08-18 08:01:48 +0200 | [diff] [blame] | 5349 | status = pci_enable_msix_range(phba->pcidev, phba->msix_entries, |
| 5350 | phba->num_cpus + 1, phba->num_cpus + 1); |
| 5351 | if (status > 0) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5352 | phba->msix_enabled = true; |
| 5353 | |
| 5354 | return; |
| 5355 | } |
| 5356 | |
Jayamohan Kallickal | 73af08e | 2014-05-05 21:41:26 -0400 | [diff] [blame] | 5357 | static void be_eqd_update(struct beiscsi_hba *phba) |
| 5358 | { |
| 5359 | struct be_set_eqd set_eqd[MAX_CPUS]; |
| 5360 | struct be_aic_obj *aic; |
| 5361 | struct be_eq_obj *pbe_eq; |
| 5362 | struct hwi_controller *phwi_ctrlr; |
| 5363 | struct hwi_context_memory *phwi_context; |
| 5364 | int eqd, i, num = 0; |
| 5365 | ulong now; |
| 5366 | u32 pps, delta; |
| 5367 | unsigned int tag; |
| 5368 | |
| 5369 | phwi_ctrlr = phba->phwi_ctrlr; |
| 5370 | phwi_context = phwi_ctrlr->phwi_ctxt; |
| 5371 | |
| 5372 | for (i = 0; i <= phba->num_cpus; i++) { |
| 5373 | aic = &phba->aic_obj[i]; |
| 5374 | pbe_eq = &phwi_context->be_eq[i]; |
| 5375 | now = jiffies; |
| 5376 | if (!aic->jiffs || time_before(now, aic->jiffs) || |
| 5377 | pbe_eq->cq_count < aic->eq_prev) { |
| 5378 | aic->jiffs = now; |
| 5379 | aic->eq_prev = pbe_eq->cq_count; |
| 5380 | continue; |
| 5381 | } |
| 5382 | delta = jiffies_to_msecs(now - aic->jiffs); |
| 5383 | pps = (((u32)(pbe_eq->cq_count - aic->eq_prev) * 1000) / delta); |
| 5384 | eqd = (pps / 1500) << 2; |
| 5385 | |
| 5386 | if (eqd < 8) |
| 5387 | eqd = 0; |
| 5388 | eqd = min_t(u32, eqd, phwi_context->max_eqd); |
| 5389 | eqd = max_t(u32, eqd, phwi_context->min_eqd); |
| 5390 | |
| 5391 | aic->jiffs = now; |
| 5392 | aic->eq_prev = pbe_eq->cq_count; |
| 5393 | |
| 5394 | if (eqd != aic->prev_eqd) { |
| 5395 | set_eqd[num].delay_multiplier = (eqd * 65)/100; |
| 5396 | set_eqd[num].eq_id = pbe_eq->q.id; |
| 5397 | aic->prev_eqd = eqd; |
| 5398 | num++; |
| 5399 | } |
| 5400 | } |
| 5401 | if (num) { |
| 5402 | tag = be_cmd_modify_eq_delay(phba, set_eqd, num); |
| 5403 | if (tag) |
Jitendra Bhivare | 8884033 | 2016-02-04 15:49:12 +0530 | [diff] [blame] | 5404 | beiscsi_mccq_compl_wait(phba, tag, NULL, NULL); |
Jayamohan Kallickal | 73af08e | 2014-05-05 21:41:26 -0400 | [diff] [blame] | 5405 | } |
| 5406 | } |
| 5407 | |
Jayamohan Kallickal | a3d313e | 2014-08-08 01:00:00 -0400 | [diff] [blame] | 5408 | static void be_check_boot_session(struct beiscsi_hba *phba) |
| 5409 | { |
| 5410 | if (beiscsi_setup_boot_info(phba)) |
| 5411 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5412 | "BM_%d : Could not set up " |
| 5413 | "iSCSI boot info on async event.\n"); |
| 5414 | } |
| 5415 | |
John Soni Jose | 7a15800 | 2012-10-20 04:45:51 +0530 | [diff] [blame] | 5416 | /* |
| 5417 | * beiscsi_hw_health_check()- Check adapter health |
| 5418 | * @work: work item to check HW health |
| 5419 | * |
| 5420 | * Check if adapter in an unrecoverable state or not. |
| 5421 | **/ |
| 5422 | static void |
| 5423 | beiscsi_hw_health_check(struct work_struct *work) |
| 5424 | { |
| 5425 | struct beiscsi_hba *phba = |
| 5426 | container_of(work, struct beiscsi_hba, |
| 5427 | beiscsi_hw_check_task.work); |
| 5428 | |
Jayamohan Kallickal | 73af08e | 2014-05-05 21:41:26 -0400 | [diff] [blame] | 5429 | be_eqd_update(phba); |
| 5430 | |
Jayamohan Kallickal | a3d313e | 2014-08-08 01:00:00 -0400 | [diff] [blame] | 5431 | if (phba->state & BE_ADAPTER_CHECK_BOOT) { |
John Soni Jose | 3efde86 | 2015-04-25 08:16:57 +0530 | [diff] [blame] | 5432 | if ((phba->get_boot > 0) && (!phba->boot_kset)) { |
| 5433 | phba->get_boot--; |
| 5434 | if (!(phba->get_boot % BE_GET_BOOT_TO)) |
| 5435 | be_check_boot_session(phba); |
| 5436 | } else { |
| 5437 | phba->state &= ~BE_ADAPTER_CHECK_BOOT; |
| 5438 | phba->get_boot = 0; |
| 5439 | } |
Jayamohan Kallickal | a3d313e | 2014-08-08 01:00:00 -0400 | [diff] [blame] | 5440 | } |
| 5441 | |
John Soni Jose | 7a15800 | 2012-10-20 04:45:51 +0530 | [diff] [blame] | 5442 | beiscsi_ue_detect(phba); |
| 5443 | |
| 5444 | schedule_delayed_work(&phba->beiscsi_hw_check_task, |
| 5445 | msecs_to_jiffies(1000)); |
| 5446 | } |
| 5447 | |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5448 | |
| 5449 | static pci_ers_result_t beiscsi_eeh_err_detected(struct pci_dev *pdev, |
| 5450 | pci_channel_state_t state) |
| 5451 | { |
| 5452 | struct beiscsi_hba *phba = NULL; |
| 5453 | |
| 5454 | phba = (struct beiscsi_hba *)pci_get_drvdata(pdev); |
| 5455 | phba->state |= BE_ADAPTER_PCI_ERR; |
| 5456 | |
| 5457 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5458 | "BM_%d : EEH error detected\n"); |
| 5459 | |
| 5460 | beiscsi_quiesce(phba, BEISCSI_EEH_UNLOAD); |
| 5461 | |
| 5462 | if (state == pci_channel_io_perm_failure) { |
| 5463 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5464 | "BM_%d : EEH : State PERM Failure"); |
| 5465 | return PCI_ERS_RESULT_DISCONNECT; |
| 5466 | } |
| 5467 | |
| 5468 | pci_disable_device(pdev); |
| 5469 | |
| 5470 | /* The error could cause the FW to trigger a flash debug dump. |
| 5471 | * Resetting the card while flash dump is in progress |
| 5472 | * can cause it not to recover; wait for it to finish. |
| 5473 | * Wait only for first function as it is needed only once per |
| 5474 | * adapter. |
| 5475 | **/ |
| 5476 | if (pdev->devfn == 0) |
| 5477 | ssleep(30); |
| 5478 | |
| 5479 | return PCI_ERS_RESULT_NEED_RESET; |
| 5480 | } |
| 5481 | |
| 5482 | static pci_ers_result_t beiscsi_eeh_reset(struct pci_dev *pdev) |
| 5483 | { |
| 5484 | struct beiscsi_hba *phba = NULL; |
| 5485 | int status = 0; |
| 5486 | |
| 5487 | phba = (struct beiscsi_hba *)pci_get_drvdata(pdev); |
| 5488 | |
| 5489 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5490 | "BM_%d : EEH Reset\n"); |
| 5491 | |
| 5492 | status = pci_enable_device(pdev); |
| 5493 | if (status) |
| 5494 | return PCI_ERS_RESULT_DISCONNECT; |
| 5495 | |
| 5496 | pci_set_master(pdev); |
| 5497 | pci_set_power_state(pdev, PCI_D0); |
| 5498 | pci_restore_state(pdev); |
| 5499 | |
| 5500 | /* Wait for the CHIP Reset to complete */ |
| 5501 | status = be_chk_reset_complete(phba); |
| 5502 | if (!status) { |
| 5503 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT, |
| 5504 | "BM_%d : EEH Reset Completed\n"); |
| 5505 | } else { |
| 5506 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT, |
| 5507 | "BM_%d : EEH Reset Completion Failure\n"); |
| 5508 | return PCI_ERS_RESULT_DISCONNECT; |
| 5509 | } |
| 5510 | |
| 5511 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 5512 | return PCI_ERS_RESULT_RECOVERED; |
| 5513 | } |
| 5514 | |
| 5515 | static void beiscsi_eeh_resume(struct pci_dev *pdev) |
| 5516 | { |
| 5517 | int ret = 0, i; |
| 5518 | struct be_eq_obj *pbe_eq; |
| 5519 | struct beiscsi_hba *phba = NULL; |
| 5520 | struct hwi_controller *phwi_ctrlr; |
| 5521 | struct hwi_context_memory *phwi_context; |
| 5522 | |
| 5523 | phba = (struct beiscsi_hba *)pci_get_drvdata(pdev); |
| 5524 | pci_save_state(pdev); |
| 5525 | |
| 5526 | if (enable_msix) |
| 5527 | find_num_cpus(phba); |
| 5528 | else |
| 5529 | phba->num_cpus = 1; |
| 5530 | |
| 5531 | if (enable_msix) { |
| 5532 | beiscsi_msix_enable(phba); |
| 5533 | if (!phba->msix_enabled) |
| 5534 | phba->num_cpus = 1; |
| 5535 | } |
| 5536 | |
| 5537 | ret = beiscsi_cmd_reset_function(phba); |
| 5538 | if (ret) { |
| 5539 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5540 | "BM_%d : Reset Failed\n"); |
| 5541 | goto ret_err; |
| 5542 | } |
| 5543 | |
| 5544 | ret = be_chk_reset_complete(phba); |
| 5545 | if (ret) { |
| 5546 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5547 | "BM_%d : Failed to get out of reset.\n"); |
| 5548 | goto ret_err; |
| 5549 | } |
| 5550 | |
| 5551 | beiscsi_get_params(phba); |
| 5552 | phba->shost->max_id = phba->params.cxns_per_ctrl; |
| 5553 | phba->shost->can_queue = phba->params.ios_per_ctrl; |
| 5554 | ret = hwi_init_controller(phba); |
Nicholas Krause | c6fff32 | 2016-02-27 12:43:25 -0500 | [diff] [blame] | 5555 | if (ret) { |
| 5556 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5557 | "BM_%d : beiscsi_eeh_resume -" |
| 5558 | "Failed to initialize beiscsi_hba.\n"); |
| 5559 | goto ret_err; |
| 5560 | } |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5561 | |
| 5562 | for (i = 0; i < MAX_MCC_CMD; i++) { |
| 5563 | init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]); |
| 5564 | phba->ctrl.mcc_tag[i] = i + 1; |
Jitendra Bhivare | 67296ad | 2016-02-04 15:49:10 +0530 | [diff] [blame] | 5565 | phba->ctrl.mcc_tag_status[i + 1] = 0; |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5566 | phba->ctrl.mcc_tag_available++; |
| 5567 | } |
| 5568 | |
| 5569 | phwi_ctrlr = phba->phwi_ctrlr; |
| 5570 | phwi_context = phwi_ctrlr->phwi_ctxt; |
| 5571 | |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5572 | for (i = 0; i < phba->num_cpus; i++) { |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5573 | pbe_eq = &phwi_context->be_eq[i]; |
Christoph Hellwig | 511cbce | 2015-11-10 14:56:14 +0100 | [diff] [blame] | 5574 | irq_poll_init(&pbe_eq->iopoll, be_iopoll_budget, |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5575 | be_iopoll); |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5576 | } |
| 5577 | |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5578 | i = (phba->msix_enabled) ? i : 0; |
| 5579 | /* Work item for MCC handling */ |
| 5580 | pbe_eq = &phwi_context->be_eq[i]; |
| 5581 | INIT_WORK(&pbe_eq->work_cqs, beiscsi_process_all_cqs); |
| 5582 | |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5583 | ret = beiscsi_init_irqs(phba); |
| 5584 | if (ret < 0) { |
| 5585 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5586 | "BM_%d : beiscsi_eeh_resume - " |
| 5587 | "Failed to beiscsi_init_irqs\n"); |
| 5588 | goto ret_err; |
| 5589 | } |
| 5590 | |
| 5591 | hwi_enable_intr(phba); |
| 5592 | phba->state &= ~BE_ADAPTER_PCI_ERR; |
| 5593 | |
| 5594 | return; |
| 5595 | ret_err: |
| 5596 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5597 | "BM_%d : AER EEH Resume Failed\n"); |
| 5598 | } |
| 5599 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5600 | static int beiscsi_dev_probe(struct pci_dev *pcidev, |
| 5601 | const struct pci_device_id *id) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5602 | { |
| 5603 | struct beiscsi_hba *phba = NULL; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5604 | struct hwi_controller *phwi_ctrlr; |
| 5605 | struct hwi_context_memory *phwi_context; |
| 5606 | struct be_eq_obj *pbe_eq; |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5607 | int ret = 0, i; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5608 | |
| 5609 | ret = beiscsi_enable_pci(pcidev); |
| 5610 | if (ret < 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5611 | dev_err(&pcidev->dev, |
| 5612 | "beiscsi_dev_probe - Failed to enable pci device\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5613 | return ret; |
| 5614 | } |
| 5615 | |
| 5616 | phba = beiscsi_hba_alloc(pcidev); |
| 5617 | if (!phba) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5618 | dev_err(&pcidev->dev, |
| 5619 | "beiscsi_dev_probe - Failed in beiscsi_hba_alloc\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5620 | goto disable_pci; |
| 5621 | } |
| 5622 | |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5623 | /* Enable EEH reporting */ |
| 5624 | ret = pci_enable_pcie_error_reporting(pcidev); |
| 5625 | if (ret) |
| 5626 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT, |
| 5627 | "BM_%d : PCIe Error Reporting " |
| 5628 | "Enabling Failed\n"); |
| 5629 | |
| 5630 | pci_save_state(pcidev); |
| 5631 | |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5632 | /* Initialize Driver configuration Paramters */ |
| 5633 | beiscsi_hba_attrs_init(phba); |
| 5634 | |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 5635 | phba->fw_timeout = false; |
Jayamohan Kallickal | 6c83185 | 2013-09-28 15:35:40 -0700 | [diff] [blame] | 5636 | phba->mac_addr_set = false; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 5637 | |
| 5638 | |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 5639 | switch (pcidev->device) { |
| 5640 | case BE_DEVICE_ID1: |
| 5641 | case OC_DEVICE_ID1: |
| 5642 | case OC_DEVICE_ID2: |
| 5643 | phba->generation = BE_GEN2; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5644 | phba->iotask_fn = beiscsi_iotask; |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 5645 | break; |
| 5646 | case BE_DEVICE_ID2: |
| 5647 | case OC_DEVICE_ID3: |
| 5648 | phba->generation = BE_GEN3; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5649 | phba->iotask_fn = beiscsi_iotask; |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 5650 | break; |
John Soni Jose | 139a1b1 | 2012-10-20 04:43:20 +0530 | [diff] [blame] | 5651 | case OC_SKH_ID1: |
| 5652 | phba->generation = BE_GEN4; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5653 | phba->iotask_fn = beiscsi_iotask_v2; |
Jayamohan Kallickal | bf9131c | 2013-04-05 20:38:24 -0700 | [diff] [blame] | 5654 | break; |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 5655 | default: |
| 5656 | phba->generation = 0; |
| 5657 | } |
| 5658 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5659 | ret = be_ctrl_init(phba, pcidev); |
| 5660 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5661 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5662 | "BM_%d : beiscsi_dev_probe-" |
| 5663 | "Failed in be_ctrl_init\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5664 | goto hba_free; |
| 5665 | } |
| 5666 | |
Jitendra Bhivare | cdaa4de | 2016-01-20 14:10:51 +0530 | [diff] [blame] | 5667 | /* |
| 5668 | * FUNCTION_RESET should clean up any stale info in FW for this fn |
| 5669 | */ |
John Soni Jose | 4d4d1ef | 2012-10-20 04:42:37 +0530 | [diff] [blame] | 5670 | ret = beiscsi_cmd_reset_function(phba); |
| 5671 | if (ret) { |
| 5672 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
Jayamohan Kallickal | 92665a6 | 2013-09-28 15:35:43 -0700 | [diff] [blame] | 5673 | "BM_%d : Reset Failed\n"); |
John Soni Jose | 4d4d1ef | 2012-10-20 04:42:37 +0530 | [diff] [blame] | 5674 | goto hba_free; |
| 5675 | } |
| 5676 | ret = be_chk_reset_complete(phba); |
| 5677 | if (ret) { |
| 5678 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
Jayamohan Kallickal | 92665a6 | 2013-09-28 15:35:43 -0700 | [diff] [blame] | 5679 | "BM_%d : Failed to get out of reset.\n"); |
John Soni Jose | 4d4d1ef | 2012-10-20 04:42:37 +0530 | [diff] [blame] | 5680 | goto hba_free; |
Jayamohan Kallickal | e9b9119 | 2010-07-22 04:24:53 +0530 | [diff] [blame] | 5681 | } |
| 5682 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5683 | spin_lock_init(&phba->io_sgl_lock); |
| 5684 | spin_lock_init(&phba->mgmt_sgl_lock); |
| 5685 | spin_lock_init(&phba->isr_lock); |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 5686 | spin_lock_init(&phba->async_pdu_lock); |
Jayamohan Kallickal | 7da5087 | 2010-01-05 05:04:12 +0530 | [diff] [blame] | 5687 | ret = mgmt_get_fw_config(&phba->ctrl, phba); |
| 5688 | if (ret != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5689 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5690 | "BM_%d : Error getting fw config\n"); |
Jayamohan Kallickal | 7da5087 | 2010-01-05 05:04:12 +0530 | [diff] [blame] | 5691 | goto free_port; |
| 5692 | } |
Jitendra Bhivare | 53aefe2 | 2016-01-20 14:10:53 +0530 | [diff] [blame] | 5693 | mgmt_get_port_name(&phba->ctrl, phba); |
Jitendra Bhivare | 4570f16 | 2016-01-20 14:10:54 +0530 | [diff] [blame] | 5694 | beiscsi_get_params(phba); |
Jayamohan Kallickal | 68c26a3 | 2013-09-28 15:35:54 -0700 | [diff] [blame] | 5695 | |
| 5696 | if (enable_msix) |
| 5697 | find_num_cpus(phba); |
| 5698 | else |
| 5699 | phba->num_cpus = 1; |
| 5700 | |
| 5701 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 5702 | "BM_%d : num_cpus = %d\n", |
| 5703 | phba->num_cpus); |
| 5704 | |
| 5705 | if (enable_msix) { |
| 5706 | beiscsi_msix_enable(phba); |
| 5707 | if (!phba->msix_enabled) |
| 5708 | phba->num_cpus = 1; |
| 5709 | } |
| 5710 | |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 5711 | phba->shost->max_id = phba->params.cxns_per_ctrl; |
Jayamohan Kallickal | aa874f0 | 2010-01-05 05:12:03 +0530 | [diff] [blame] | 5712 | phba->shost->can_queue = phba->params.ios_per_ctrl; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5713 | ret = beiscsi_init_port(phba); |
| 5714 | if (ret < 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5715 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5716 | "BM_%d : beiscsi_dev_probe-" |
| 5717 | "Failed in beiscsi_init_port\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5718 | goto free_port; |
| 5719 | } |
| 5720 | |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5721 | for (i = 0; i < MAX_MCC_CMD; i++) { |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 5722 | init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]); |
| 5723 | phba->ctrl.mcc_tag[i] = i + 1; |
Jitendra Bhivare | 67296ad | 2016-02-04 15:49:10 +0530 | [diff] [blame] | 5724 | phba->ctrl.mcc_tag_status[i + 1] = 0; |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 5725 | phba->ctrl.mcc_tag_available++; |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 5726 | memset(&phba->ctrl.ptag_state[i].tag_mem_state, 0, |
Jayamohan Kallickal | 8fc01ea | 2014-05-05 21:41:28 -0400 | [diff] [blame] | 5727 | sizeof(struct be_dma_mem)); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 5728 | } |
| 5729 | |
| 5730 | phba->ctrl.mcc_alloc_index = phba->ctrl.mcc_free_index = 0; |
| 5731 | |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 5732 | snprintf(phba->wq_name, sizeof(phba->wq_name), "beiscsi_%02x_wq", |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5733 | phba->shost->host_no); |
Kees Cook | d853754 | 2013-07-03 15:04:57 -0700 | [diff] [blame] | 5734 | phba->wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 1, phba->wq_name); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5735 | if (!phba->wq) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5736 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5737 | "BM_%d : beiscsi_dev_probe-" |
| 5738 | "Failed to allocate work queue\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5739 | goto free_twq; |
| 5740 | } |
| 5741 | |
John Soni Jose | 7a15800 | 2012-10-20 04:45:51 +0530 | [diff] [blame] | 5742 | INIT_DELAYED_WORK(&phba->beiscsi_hw_check_task, |
| 5743 | beiscsi_hw_health_check); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5744 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5745 | phwi_ctrlr = phba->phwi_ctrlr; |
| 5746 | phwi_context = phwi_ctrlr->phwi_ctxt; |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 5747 | |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5748 | for (i = 0; i < phba->num_cpus; i++) { |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 5749 | pbe_eq = &phwi_context->be_eq[i]; |
Christoph Hellwig | 511cbce | 2015-11-10 14:56:14 +0100 | [diff] [blame] | 5750 | irq_poll_init(&pbe_eq->iopoll, be_iopoll_budget, |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5751 | be_iopoll); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5752 | } |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 5753 | |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5754 | i = (phba->msix_enabled) ? i : 0; |
| 5755 | /* Work item for MCC handling */ |
| 5756 | pbe_eq = &phwi_context->be_eq[i]; |
| 5757 | INIT_WORK(&pbe_eq->work_cqs, beiscsi_process_all_cqs); |
| 5758 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5759 | ret = beiscsi_init_irqs(phba); |
| 5760 | if (ret < 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5761 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5762 | "BM_%d : beiscsi_dev_probe-" |
| 5763 | "Failed to beiscsi_init_irqs\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5764 | goto free_blkenbld; |
| 5765 | } |
Jayamohan Kallickal | 238f6b7 | 2010-07-22 04:23:22 +0530 | [diff] [blame] | 5766 | hwi_enable_intr(phba); |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 5767 | |
Jayamohan Kallickal | 0598b8a | 2014-05-05 21:41:25 -0400 | [diff] [blame] | 5768 | if (iscsi_host_add(phba->shost, &phba->pcidev->dev)) |
| 5769 | goto free_blkenbld; |
| 5770 | |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 5771 | if (beiscsi_setup_boot_info(phba)) |
| 5772 | /* |
| 5773 | * log error but continue, because we may not be using |
| 5774 | * iscsi boot. |
| 5775 | */ |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5776 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5777 | "BM_%d : Could not set up " |
| 5778 | "iSCSI boot info.\n"); |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 5779 | |
Jitendra Bhivare | 96b48b9 | 2016-08-19 15:20:06 +0530 | [diff] [blame^] | 5780 | beiscsi_iface_create_default(phba); |
John Soni Jose | 7a15800 | 2012-10-20 04:45:51 +0530 | [diff] [blame] | 5781 | schedule_delayed_work(&phba->beiscsi_hw_check_task, |
| 5782 | msecs_to_jiffies(1000)); |
| 5783 | |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5784 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 5785 | "\n\n\n BM_%d : SUCCESS - DRIVER LOADED\n\n\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5786 | return 0; |
| 5787 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5788 | free_blkenbld: |
| 5789 | destroy_workqueue(phba->wq); |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5790 | for (i = 0; i < phba->num_cpus; i++) { |
| 5791 | pbe_eq = &phwi_context->be_eq[i]; |
Christoph Hellwig | 511cbce | 2015-11-10 14:56:14 +0100 | [diff] [blame] | 5792 | irq_poll_disable(&pbe_eq->iopoll); |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5793 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5794 | free_twq: |
| 5795 | beiscsi_clean_port(phba); |
| 5796 | beiscsi_free_mem(phba); |
| 5797 | free_port: |
| 5798 | pci_free_consistent(phba->pcidev, |
| 5799 | phba->ctrl.mbox_mem_alloced.size, |
| 5800 | phba->ctrl.mbox_mem_alloced.va, |
| 5801 | phba->ctrl.mbox_mem_alloced.dma); |
| 5802 | beiscsi_unmap_pci_function(phba); |
| 5803 | hba_free: |
Jayamohan Kallickal | 238f6b7 | 2010-07-22 04:23:22 +0530 | [diff] [blame] | 5804 | if (phba->msix_enabled) |
| 5805 | pci_disable_msix(phba->pcidev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5806 | pci_dev_put(phba->pcidev); |
| 5807 | iscsi_host_free(phba->shost); |
John Soni Jose | 2e7cee0 | 2015-02-12 06:45:47 +0530 | [diff] [blame] | 5808 | pci_set_drvdata(pcidev, NULL); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5809 | disable_pci: |
John Soni Jose | e307f3a | 2015-04-25 08:17:19 +0530 | [diff] [blame] | 5810 | pci_release_regions(pcidev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5811 | pci_disable_device(pcidev); |
| 5812 | return ret; |
| 5813 | } |
| 5814 | |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5815 | static struct pci_error_handlers beiscsi_eeh_handlers = { |
| 5816 | .error_detected = beiscsi_eeh_err_detected, |
| 5817 | .slot_reset = beiscsi_eeh_reset, |
| 5818 | .resume = beiscsi_eeh_resume, |
| 5819 | }; |
| 5820 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5821 | struct iscsi_transport beiscsi_iscsi_transport = { |
| 5822 | .owner = THIS_MODULE, |
| 5823 | .name = DRV_NAME, |
Jayamohan Kallickal | 9db0fb3 | 2010-01-05 05:12:43 +0530 | [diff] [blame] | 5824 | .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_TEXT_NEGO | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5825 | CAP_MULTI_R2T | CAP_DATADGST | CAP_DATA_PATH_OFFLOAD, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5826 | .create_session = beiscsi_session_create, |
| 5827 | .destroy_session = beiscsi_session_destroy, |
| 5828 | .create_conn = beiscsi_conn_create, |
| 5829 | .bind_conn = beiscsi_conn_bind, |
| 5830 | .destroy_conn = iscsi_conn_teardown, |
Jitendra Bhivare | 96b48b9 | 2016-08-19 15:20:06 +0530 | [diff] [blame^] | 5831 | .attr_is_visible = beiscsi_attr_is_visible, |
| 5832 | .set_iface_param = beiscsi_iface_set_param, |
| 5833 | .get_iface_param = beiscsi_iface_get_param, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5834 | .set_param = beiscsi_set_param, |
Mike Christie | c7f7fd5 | 2011-02-16 15:04:41 -0600 | [diff] [blame] | 5835 | .get_conn_param = iscsi_conn_get_param, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5836 | .get_session_param = iscsi_session_get_param, |
| 5837 | .get_host_param = beiscsi_get_host_param, |
| 5838 | .start_conn = beiscsi_conn_start, |
Mike Christie | fa95d20 | 2010-06-09 03:30:08 -0500 | [diff] [blame] | 5839 | .stop_conn = iscsi_conn_stop, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5840 | .send_pdu = iscsi_conn_send_pdu, |
| 5841 | .xmit_task = beiscsi_task_xmit, |
| 5842 | .cleanup_task = beiscsi_cleanup_task, |
| 5843 | .alloc_pdu = beiscsi_alloc_pdu, |
| 5844 | .parse_pdu_itt = beiscsi_parse_pdu, |
| 5845 | .get_stats = beiscsi_conn_get_stats, |
Mike Christie | c7f7fd5 | 2011-02-16 15:04:41 -0600 | [diff] [blame] | 5846 | .get_ep_param = beiscsi_ep_get_param, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5847 | .ep_connect = beiscsi_ep_connect, |
| 5848 | .ep_poll = beiscsi_ep_poll, |
| 5849 | .ep_disconnect = beiscsi_ep_disconnect, |
| 5850 | .session_recovery_timedout = iscsi_session_recovery_timedout, |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 5851 | .bsg_request = beiscsi_bsg_request, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5852 | }; |
| 5853 | |
| 5854 | static struct pci_driver beiscsi_pci_driver = { |
| 5855 | .name = DRV_NAME, |
| 5856 | .probe = beiscsi_dev_probe, |
| 5857 | .remove = beiscsi_remove, |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5858 | .id_table = beiscsi_pci_id_table, |
| 5859 | .err_handler = &beiscsi_eeh_handlers |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5860 | }; |
| 5861 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5862 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5863 | static int __init beiscsi_module_init(void) |
| 5864 | { |
| 5865 | int ret; |
| 5866 | |
| 5867 | beiscsi_scsi_transport = |
| 5868 | iscsi_register_transport(&beiscsi_iscsi_transport); |
| 5869 | if (!beiscsi_scsi_transport) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5870 | printk(KERN_ERR |
| 5871 | "beiscsi_module_init - Unable to register beiscsi transport.\n"); |
Jayamohan Kallickal | f55a24f | 2010-01-23 05:37:40 +0530 | [diff] [blame] | 5872 | return -ENOMEM; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5873 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5874 | printk(KERN_INFO "In beiscsi_module_init, tt=%p\n", |
| 5875 | &beiscsi_iscsi_transport); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5876 | |
| 5877 | ret = pci_register_driver(&beiscsi_pci_driver); |
| 5878 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5879 | printk(KERN_ERR |
| 5880 | "beiscsi_module_init - Unable to register beiscsi pci driver.\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5881 | goto unregister_iscsi_transport; |
| 5882 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5883 | return 0; |
| 5884 | |
| 5885 | unregister_iscsi_transport: |
| 5886 | iscsi_unregister_transport(&beiscsi_iscsi_transport); |
| 5887 | return ret; |
| 5888 | } |
| 5889 | |
| 5890 | static void __exit beiscsi_module_exit(void) |
| 5891 | { |
| 5892 | pci_unregister_driver(&beiscsi_pci_driver); |
| 5893 | iscsi_unregister_transport(&beiscsi_iscsi_transport); |
| 5894 | } |
| 5895 | |
| 5896 | module_init(beiscsi_module_init); |
| 5897 | module_exit(beiscsi_module_exit); |