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 | |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 289 | rc = beiscsi_mccq_compl(phba, tag, NULL, &nonemb_cmd); |
| 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 | |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 370 | rc = beiscsi_mccq_compl(phba, tag, NULL, &nonemb_cmd); |
| 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; |
| 383 | int rc; |
| 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; |
| 437 | default: |
| 438 | rc = -ENOSYS; |
| 439 | break; |
| 440 | } |
| 441 | return rc; |
| 442 | } |
| 443 | |
| 444 | static ssize_t beiscsi_show_boot_ini_info(void *data, int type, char *buf) |
| 445 | { |
| 446 | struct beiscsi_hba *phba = data; |
| 447 | char *str = buf; |
| 448 | int rc; |
| 449 | |
| 450 | switch (type) { |
| 451 | case ISCSI_BOOT_INI_INITIATOR_NAME: |
| 452 | rc = sprintf(str, "%s\n", phba->boot_sess.initiator_iscsiname); |
| 453 | break; |
| 454 | default: |
| 455 | rc = -ENOSYS; |
| 456 | break; |
| 457 | } |
| 458 | return rc; |
| 459 | } |
| 460 | |
| 461 | static ssize_t beiscsi_show_boot_eth_info(void *data, int type, char *buf) |
| 462 | { |
| 463 | struct beiscsi_hba *phba = data; |
| 464 | char *str = buf; |
| 465 | int rc; |
| 466 | |
| 467 | switch (type) { |
| 468 | case ISCSI_BOOT_ETH_FLAGS: |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 469 | rc = sprintf(str, "2\n"); |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 470 | break; |
| 471 | case ISCSI_BOOT_ETH_INDEX: |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 472 | rc = sprintf(str, "0\n"); |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 473 | break; |
| 474 | case ISCSI_BOOT_ETH_MAC: |
Mike Christie | 0e43895 | 2012-04-03 23:41:51 -0500 | [diff] [blame] | 475 | rc = beiscsi_get_macaddr(str, phba); |
| 476 | break; |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 477 | default: |
| 478 | rc = -ENOSYS; |
| 479 | break; |
| 480 | } |
| 481 | return rc; |
| 482 | } |
| 483 | |
| 484 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 485 | static umode_t beiscsi_tgt_get_attr_visibility(void *data, int type) |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 486 | { |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 487 | umode_t rc; |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 488 | |
| 489 | switch (type) { |
| 490 | case ISCSI_BOOT_TGT_NAME: |
| 491 | case ISCSI_BOOT_TGT_IP_ADDR: |
| 492 | case ISCSI_BOOT_TGT_PORT: |
| 493 | case ISCSI_BOOT_TGT_CHAP_NAME: |
| 494 | case ISCSI_BOOT_TGT_CHAP_SECRET: |
| 495 | case ISCSI_BOOT_TGT_REV_CHAP_NAME: |
| 496 | case ISCSI_BOOT_TGT_REV_CHAP_SECRET: |
| 497 | case ISCSI_BOOT_TGT_NIC_ASSOC: |
| 498 | case ISCSI_BOOT_TGT_FLAGS: |
| 499 | rc = S_IRUGO; |
| 500 | break; |
| 501 | default: |
| 502 | rc = 0; |
| 503 | break; |
| 504 | } |
| 505 | return rc; |
| 506 | } |
| 507 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 508 | static umode_t beiscsi_ini_get_attr_visibility(void *data, int type) |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 509 | { |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 510 | umode_t rc; |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 511 | |
| 512 | switch (type) { |
| 513 | case ISCSI_BOOT_INI_INITIATOR_NAME: |
| 514 | rc = S_IRUGO; |
| 515 | break; |
| 516 | default: |
| 517 | rc = 0; |
| 518 | break; |
| 519 | } |
| 520 | return rc; |
| 521 | } |
| 522 | |
| 523 | |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 524 | static umode_t beiscsi_eth_get_attr_visibility(void *data, int type) |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 525 | { |
Al Viro | 587a1f1 | 2011-07-23 23:11:19 -0400 | [diff] [blame] | 526 | umode_t rc; |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 527 | |
| 528 | switch (type) { |
| 529 | case ISCSI_BOOT_ETH_FLAGS: |
| 530 | case ISCSI_BOOT_ETH_MAC: |
| 531 | case ISCSI_BOOT_ETH_INDEX: |
| 532 | rc = S_IRUGO; |
| 533 | break; |
| 534 | default: |
| 535 | rc = 0; |
| 536 | break; |
| 537 | } |
| 538 | return rc; |
| 539 | } |
| 540 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 541 | /*------------------- PCI Driver operations and data ----------------- */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 542 | static const struct pci_device_id beiscsi_pci_id_table[] = { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 543 | { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) }, |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 544 | { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) }, |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 545 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) }, |
| 546 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) }, |
| 547 | { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID3) }, |
John Soni Jose | 139a1b1 | 2012-10-20 04:43:20 +0530 | [diff] [blame] | 548 | { PCI_DEVICE(ELX_VENDOR_ID, OC_SKH_ID1) }, |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 549 | { 0 } |
| 550 | }; |
| 551 | MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table); |
| 552 | |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 553 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 554 | static struct scsi_host_template beiscsi_sht = { |
| 555 | .module = THIS_MODULE, |
Ketan Mukadam | c4f39bd | 2015-07-04 04:12:33 +0530 | [diff] [blame] | 556 | .name = "Emulex 10Gbe open-iscsi Initiator Driver", |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 557 | .proc_name = DRV_NAME, |
| 558 | .queuecommand = iscsi_queuecommand, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 559 | .change_queue_depth = scsi_change_queue_depth, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 560 | .slave_configure = beiscsi_slave_configure, |
| 561 | .target_alloc = iscsi_target_alloc, |
Jayamohan Kallickal | 4183122 | 2010-02-20 08:02:39 +0530 | [diff] [blame] | 562 | .eh_abort_handler = beiscsi_eh_abort, |
| 563 | .eh_device_reset_handler = beiscsi_eh_device_reset, |
Jayamohan Kallickal | 309ce15 | 2010-02-20 08:02:10 +0530 | [diff] [blame] | 564 | .eh_target_reset_handler = iscsi_eh_session_reset, |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 565 | .shost_attrs = beiscsi_attrs, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 566 | .sg_tablesize = BEISCSI_SGLIST_ELEMENTS, |
| 567 | .can_queue = BE2_IO_DEPTH, |
| 568 | .this_id = -1, |
| 569 | .max_sectors = BEISCSI_MAX_SECTORS, |
| 570 | .cmd_per_lun = BEISCSI_CMD_PER_LUN, |
| 571 | .use_clustering = ENABLE_CLUSTERING, |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 572 | .vendor_id = SCSI_NL_VID_TYPE_PCI | BE_VENDOR_ID, |
Christoph Hellwig | c40ecc1 | 2014-11-13 14:25:11 +0100 | [diff] [blame] | 573 | .track_queue_depth = 1, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 574 | }; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 575 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 576 | static struct scsi_transport_template *beiscsi_scsi_transport; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 577 | |
| 578 | static struct beiscsi_hba *beiscsi_hba_alloc(struct pci_dev *pcidev) |
| 579 | { |
| 580 | struct beiscsi_hba *phba; |
| 581 | struct Scsi_Host *shost; |
| 582 | |
| 583 | shost = iscsi_host_alloc(&beiscsi_sht, sizeof(*phba), 0); |
| 584 | if (!shost) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 585 | dev_err(&pcidev->dev, |
| 586 | "beiscsi_hba_alloc - iscsi_host_alloc failed\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 587 | return NULL; |
| 588 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 589 | shost->max_id = BE2_MAX_SESSIONS; |
| 590 | shost->max_channel = 0; |
| 591 | shost->max_cmd_len = BEISCSI_MAX_CMD_LEN; |
| 592 | shost->max_lun = BEISCSI_NUM_MAX_LUN; |
| 593 | shost->transportt = beiscsi_scsi_transport; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 594 | phba = iscsi_host_priv(shost); |
| 595 | memset(phba, 0, sizeof(*phba)); |
| 596 | phba->shost = shost; |
| 597 | phba->pcidev = pci_dev_get(pcidev); |
Jayamohan Kallickal | 2807afb | 2010-01-05 05:07:49 +0530 | [diff] [blame] | 598 | pci_set_drvdata(pcidev, phba); |
Mike Christie | 0e43895 | 2012-04-03 23:41:51 -0500 | [diff] [blame] | 599 | phba->interface_handle = 0xFFFFFFFF; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 600 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 601 | return phba; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | static void beiscsi_unmap_pci_function(struct beiscsi_hba *phba) |
| 605 | { |
| 606 | if (phba->csr_va) { |
| 607 | iounmap(phba->csr_va); |
| 608 | phba->csr_va = NULL; |
| 609 | } |
| 610 | if (phba->db_va) { |
| 611 | iounmap(phba->db_va); |
| 612 | phba->db_va = NULL; |
| 613 | } |
| 614 | if (phba->pci_va) { |
| 615 | iounmap(phba->pci_va); |
| 616 | phba->pci_va = NULL; |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | static int beiscsi_map_pci_bars(struct beiscsi_hba *phba, |
| 621 | struct pci_dev *pcidev) |
| 622 | { |
| 623 | u8 __iomem *addr; |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 624 | int pcicfg_reg; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 625 | |
| 626 | addr = ioremap_nocache(pci_resource_start(pcidev, 2), |
| 627 | pci_resource_len(pcidev, 2)); |
| 628 | if (addr == NULL) |
| 629 | return -ENOMEM; |
| 630 | phba->ctrl.csr = addr; |
| 631 | phba->csr_va = addr; |
| 632 | phba->csr_pa.u.a64.address = pci_resource_start(pcidev, 2); |
| 633 | |
| 634 | addr = ioremap_nocache(pci_resource_start(pcidev, 4), 128 * 1024); |
| 635 | if (addr == NULL) |
| 636 | goto pci_map_err; |
| 637 | phba->ctrl.db = addr; |
| 638 | phba->db_va = addr; |
| 639 | phba->db_pa.u.a64.address = pci_resource_start(pcidev, 4); |
| 640 | |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 641 | if (phba->generation == BE_GEN2) |
| 642 | pcicfg_reg = 1; |
| 643 | else |
| 644 | pcicfg_reg = 0; |
| 645 | |
| 646 | addr = ioremap_nocache(pci_resource_start(pcidev, pcicfg_reg), |
| 647 | pci_resource_len(pcidev, pcicfg_reg)); |
| 648 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 649 | if (addr == NULL) |
| 650 | goto pci_map_err; |
| 651 | phba->ctrl.pcicfg = addr; |
| 652 | phba->pci_va = addr; |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 653 | phba->pci_pa.u.a64.address = pci_resource_start(pcidev, pcicfg_reg); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 654 | return 0; |
| 655 | |
| 656 | pci_map_err: |
| 657 | beiscsi_unmap_pci_function(phba); |
| 658 | return -ENOMEM; |
| 659 | } |
| 660 | |
| 661 | static int beiscsi_enable_pci(struct pci_dev *pcidev) |
| 662 | { |
| 663 | int ret; |
| 664 | |
| 665 | ret = pci_enable_device(pcidev); |
| 666 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 667 | dev_err(&pcidev->dev, |
| 668 | "beiscsi_enable_pci - enable device failed\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 669 | return ret; |
| 670 | } |
| 671 | |
John Soni Jose | e307f3a | 2015-04-25 08:17:19 +0530 | [diff] [blame] | 672 | ret = pci_request_regions(pcidev, DRV_NAME); |
| 673 | if (ret) { |
| 674 | dev_err(&pcidev->dev, |
| 675 | "beiscsi_enable_pci - request region failed\n"); |
| 676 | goto pci_dev_disable; |
| 677 | } |
| 678 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 679 | pci_set_master(pcidev); |
Jayamohan Kallickal | 6c57625b | 2014-01-29 02:16:45 -0500 | [diff] [blame] | 680 | ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(64)); |
| 681 | if (ret) { |
| 682 | ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(32)); |
| 683 | if (ret) { |
| 684 | dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n"); |
John Soni Jose | e307f3a | 2015-04-25 08:17:19 +0530 | [diff] [blame] | 685 | goto pci_region_release; |
Jayamohan Kallickal | 6c57625b | 2014-01-29 02:16:45 -0500 | [diff] [blame] | 686 | } else { |
| 687 | ret = pci_set_consistent_dma_mask(pcidev, |
| 688 | DMA_BIT_MASK(32)); |
| 689 | } |
| 690 | } else { |
| 691 | ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 692 | if (ret) { |
| 693 | dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n"); |
John Soni Jose | e307f3a | 2015-04-25 08:17:19 +0530 | [diff] [blame] | 694 | goto pci_region_release; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 695 | } |
| 696 | } |
| 697 | return 0; |
John Soni Jose | e307f3a | 2015-04-25 08:17:19 +0530 | [diff] [blame] | 698 | |
| 699 | pci_region_release: |
| 700 | pci_release_regions(pcidev); |
| 701 | pci_dev_disable: |
| 702 | pci_disable_device(pcidev); |
| 703 | |
| 704 | return ret; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | static int be_ctrl_init(struct beiscsi_hba *phba, struct pci_dev *pdev) |
| 708 | { |
| 709 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 710 | struct be_dma_mem *mbox_mem_alloc = &ctrl->mbox_mem_alloced; |
| 711 | struct be_dma_mem *mbox_mem_align = &ctrl->mbox_mem; |
| 712 | int status = 0; |
| 713 | |
| 714 | ctrl->pdev = pdev; |
| 715 | status = beiscsi_map_pci_bars(phba, pdev); |
| 716 | if (status) |
| 717 | return status; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 718 | mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16; |
| 719 | mbox_mem_alloc->va = pci_alloc_consistent(pdev, |
| 720 | mbox_mem_alloc->size, |
| 721 | &mbox_mem_alloc->dma); |
| 722 | if (!mbox_mem_alloc->va) { |
| 723 | beiscsi_unmap_pci_function(phba); |
Jayamohan Kallickal | a49e06d | 2012-04-03 23:41:44 -0500 | [diff] [blame] | 724 | return -ENOMEM; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | mbox_mem_align->size = sizeof(struct be_mcc_mailbox); |
| 728 | mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16); |
| 729 | mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16); |
| 730 | memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox)); |
Jitendra Bhivare | c03a50f | 2016-01-20 14:10:46 +0530 | [diff] [blame] | 731 | mutex_init(&ctrl->mbox_lock); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 732 | spin_lock_init(&phba->ctrl.mcc_lock); |
| 733 | spin_lock_init(&phba->ctrl.mcc_cq_lock); |
| 734 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 735 | return status; |
| 736 | } |
| 737 | |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 738 | /** |
| 739 | * beiscsi_get_params()- Set the config paramters |
| 740 | * @phba: ptr device priv structure |
| 741 | **/ |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 742 | static void beiscsi_get_params(struct beiscsi_hba *phba) |
| 743 | { |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 744 | uint32_t total_cid_count = 0; |
| 745 | uint32_t total_icd_count = 0; |
| 746 | uint8_t ulp_num = 0; |
| 747 | |
| 748 | total_cid_count = BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP0) + |
| 749 | BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP1); |
| 750 | |
Jayamohan Kallickal | cf987b7 | 2013-09-28 15:35:59 -0700 | [diff] [blame] | 751 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 752 | uint32_t align_mask = 0; |
| 753 | uint32_t icd_post_per_page = 0; |
| 754 | uint32_t icd_count_unavailable = 0; |
| 755 | uint32_t icd_start = 0, icd_count = 0; |
| 756 | uint32_t icd_start_align = 0, icd_count_align = 0; |
| 757 | |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 758 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
Jayamohan Kallickal | cf987b7 | 2013-09-28 15:35:59 -0700 | [diff] [blame] | 759 | icd_start = phba->fw_config.iscsi_icd_start[ulp_num]; |
| 760 | icd_count = phba->fw_config.iscsi_icd_count[ulp_num]; |
| 761 | |
| 762 | /* Get ICD count that can be posted on each page */ |
| 763 | icd_post_per_page = (PAGE_SIZE / (BE2_SGE * |
| 764 | sizeof(struct iscsi_sge))); |
| 765 | align_mask = (icd_post_per_page - 1); |
| 766 | |
| 767 | /* Check if icd_start is aligned ICD per page posting */ |
| 768 | if (icd_start % icd_post_per_page) { |
| 769 | icd_start_align = ((icd_start + |
| 770 | icd_post_per_page) & |
| 771 | ~(align_mask)); |
| 772 | phba->fw_config. |
| 773 | iscsi_icd_start[ulp_num] = |
| 774 | icd_start_align; |
| 775 | } |
| 776 | |
| 777 | icd_count_align = (icd_count & ~align_mask); |
| 778 | |
| 779 | /* ICD discarded in the process of alignment */ |
| 780 | if (icd_start_align) |
| 781 | icd_count_unavailable = ((icd_start_align - |
| 782 | icd_start) + |
| 783 | (icd_count - |
| 784 | icd_count_align)); |
| 785 | |
| 786 | /* Updated ICD count available */ |
| 787 | phba->fw_config.iscsi_icd_count[ulp_num] = (icd_count - |
| 788 | icd_count_unavailable); |
| 789 | |
| 790 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 791 | "BM_%d : Aligned ICD values\n" |
| 792 | "\t ICD Start : %d\n" |
| 793 | "\t ICD Count : %d\n" |
| 794 | "\t ICD Discarded : %d\n", |
| 795 | phba->fw_config. |
| 796 | iscsi_icd_start[ulp_num], |
| 797 | phba->fw_config. |
| 798 | iscsi_icd_count[ulp_num], |
| 799 | icd_count_unavailable); |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 800 | break; |
| 801 | } |
Jayamohan Kallickal | cf987b7 | 2013-09-28 15:35:59 -0700 | [diff] [blame] | 802 | } |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 803 | |
Jayamohan Kallickal | cf987b7 | 2013-09-28 15:35:59 -0700 | [diff] [blame] | 804 | total_icd_count = phba->fw_config.iscsi_icd_count[ulp_num]; |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 805 | phba->params.ios_per_ctrl = (total_icd_count - |
| 806 | (total_cid_count + |
| 807 | BE2_TMFS + BE2_NOPOUT_REQ)); |
| 808 | phba->params.cxns_per_ctrl = total_cid_count; |
| 809 | phba->params.asyncpdus_per_ctrl = total_cid_count; |
| 810 | phba->params.icds_per_ctrl = total_icd_count; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 811 | phba->params.num_sge_per_io = BE2_SGE; |
| 812 | phba->params.defpdu_hdr_sz = BE2_DEFPDU_HDR_SZ; |
| 813 | phba->params.defpdu_data_sz = BE2_DEFPDU_DATA_SZ; |
| 814 | phba->params.eq_timer = 64; |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 815 | phba->params.num_eq_entries = 1024; |
| 816 | phba->params.num_cq_entries = 1024; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 817 | phba->params.wrbs_per_cxn = 256; |
| 818 | } |
| 819 | |
| 820 | static void hwi_ring_eq_db(struct beiscsi_hba *phba, |
| 821 | unsigned int id, unsigned int clr_interrupt, |
| 822 | unsigned int num_processed, |
| 823 | unsigned char rearm, unsigned char event) |
| 824 | { |
| 825 | u32 val = 0; |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 826 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 827 | if (rearm) |
| 828 | val |= 1 << DB_EQ_REARM_SHIFT; |
| 829 | if (clr_interrupt) |
| 830 | val |= 1 << DB_EQ_CLR_SHIFT; |
| 831 | if (event) |
| 832 | val |= 1 << DB_EQ_EVNT_SHIFT; |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 833 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 834 | val |= num_processed << DB_EQ_NUM_POPPED_SHIFT; |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 835 | /* Setting lower order EQ_ID Bits */ |
| 836 | val |= (id & DB_EQ_RING_ID_LOW_MASK); |
| 837 | |
| 838 | /* Setting Higher order EQ_ID Bits */ |
| 839 | val |= (((id >> DB_EQ_HIGH_FEILD_SHIFT) & |
| 840 | DB_EQ_RING_ID_HIGH_MASK) |
| 841 | << DB_EQ_HIGH_SET_SHIFT); |
| 842 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 843 | iowrite32(val, phba->db_va + DB_EQ_OFFSET); |
| 844 | } |
| 845 | |
| 846 | /** |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 847 | * be_isr_mcc - The isr routine of the driver. |
| 848 | * @irq: Not used |
| 849 | * @dev_id: Pointer to host adapter structure |
| 850 | */ |
| 851 | static irqreturn_t be_isr_mcc(int irq, void *dev_id) |
| 852 | { |
| 853 | struct beiscsi_hba *phba; |
| 854 | struct be_eq_entry *eqe = NULL; |
| 855 | struct be_queue_info *eq; |
| 856 | struct be_queue_info *mcc; |
| 857 | unsigned int num_eq_processed; |
| 858 | struct be_eq_obj *pbe_eq; |
| 859 | unsigned long flags; |
| 860 | |
| 861 | pbe_eq = dev_id; |
| 862 | eq = &pbe_eq->q; |
| 863 | phba = pbe_eq->phba; |
| 864 | mcc = &phba->ctrl.mcc_obj.cq; |
| 865 | eqe = queue_tail_node(eq); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 866 | |
| 867 | num_eq_processed = 0; |
| 868 | |
| 869 | while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32] |
| 870 | & EQE_VALID_MASK) { |
| 871 | if (((eqe->dw[offsetof(struct amap_eq_entry, |
| 872 | resource_id) / 32] & |
| 873 | EQE_RESID_MASK) >> 16) == mcc->id) { |
| 874 | spin_lock_irqsave(&phba->isr_lock, flags); |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 875 | pbe_eq->todo_mcc_cq = true; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 876 | spin_unlock_irqrestore(&phba->isr_lock, flags); |
| 877 | } |
| 878 | AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0); |
| 879 | queue_tail_inc(eq); |
| 880 | eqe = queue_tail_node(eq); |
| 881 | num_eq_processed++; |
| 882 | } |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 883 | if (pbe_eq->todo_mcc_cq) |
| 884 | queue_work(phba->wq, &pbe_eq->work_cqs); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 885 | if (num_eq_processed) |
| 886 | hwi_ring_eq_db(phba, eq->id, 1, num_eq_processed, 1, 1); |
| 887 | |
| 888 | return IRQ_HANDLED; |
| 889 | } |
| 890 | |
| 891 | /** |
| 892 | * be_isr_msix - The isr routine of the driver. |
| 893 | * @irq: Not used |
| 894 | * @dev_id: Pointer to host adapter structure |
| 895 | */ |
| 896 | static irqreturn_t be_isr_msix(int irq, void *dev_id) |
| 897 | { |
| 898 | struct beiscsi_hba *phba; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 899 | struct be_queue_info *eq; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 900 | struct be_eq_obj *pbe_eq; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 901 | |
| 902 | pbe_eq = dev_id; |
| 903 | eq = &pbe_eq->q; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 904 | |
| 905 | phba = pbe_eq->phba; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 906 | |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 907 | /* disable interrupt till iopoll completes */ |
| 908 | hwi_ring_eq_db(phba, eq->id, 1, 0, 0, 1); |
| 909 | irq_poll_sched(&pbe_eq->iopoll); |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 910 | |
| 911 | return IRQ_HANDLED; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | /** |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 915 | * be_isr - The isr routine of the driver. |
| 916 | * @irq: Not used |
| 917 | * @dev_id: Pointer to host adapter structure |
| 918 | */ |
| 919 | static irqreturn_t be_isr(int irq, void *dev_id) |
| 920 | { |
| 921 | struct beiscsi_hba *phba; |
| 922 | struct hwi_controller *phwi_ctrlr; |
| 923 | struct hwi_context_memory *phwi_context; |
| 924 | struct be_eq_entry *eqe = NULL; |
| 925 | struct be_queue_info *eq; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 926 | struct be_queue_info *mcc; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 927 | unsigned long flags, index; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 928 | unsigned int num_mcceq_processed, num_ioeq_processed; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 929 | struct be_ctrl_info *ctrl; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 930 | struct be_eq_obj *pbe_eq; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 931 | int isr; |
| 932 | |
| 933 | phba = dev_id; |
Justin P. Mattock | 6eab04a | 2011-04-08 19:49:08 -0700 | [diff] [blame] | 934 | ctrl = &phba->ctrl; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 935 | isr = ioread32(ctrl->csr + CEV_ISR0_OFFSET + |
| 936 | (PCI_FUNC(ctrl->pdev->devfn) * CEV_ISR_SIZE)); |
| 937 | if (!isr) |
| 938 | return IRQ_NONE; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 939 | |
| 940 | phwi_ctrlr = phba->phwi_ctrlr; |
| 941 | phwi_context = phwi_ctrlr->phwi_ctxt; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 942 | pbe_eq = &phwi_context->be_eq[0]; |
| 943 | |
| 944 | eq = &phwi_context->be_eq[0].q; |
| 945 | mcc = &phba->ctrl.mcc_obj.cq; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 946 | index = 0; |
| 947 | eqe = queue_tail_node(eq); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 948 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 949 | num_ioeq_processed = 0; |
| 950 | num_mcceq_processed = 0; |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 951 | while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32] |
| 952 | & EQE_VALID_MASK) { |
| 953 | if (((eqe->dw[offsetof(struct amap_eq_entry, |
| 954 | resource_id) / 32] & |
| 955 | EQE_RESID_MASK) >> 16) == mcc->id) { |
| 956 | spin_lock_irqsave(&phba->isr_lock, flags); |
| 957 | pbe_eq->todo_mcc_cq = true; |
| 958 | spin_unlock_irqrestore(&phba->isr_lock, flags); |
| 959 | num_mcceq_processed++; |
| 960 | } else { |
Christoph Hellwig | ea51190 | 2015-12-07 06:41:11 -0800 | [diff] [blame] | 961 | irq_poll_sched(&pbe_eq->iopoll); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 962 | num_ioeq_processed++; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 963 | } |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 964 | AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0); |
| 965 | queue_tail_inc(eq); |
| 966 | eqe = queue_tail_node(eq); |
| 967 | } |
| 968 | if (num_ioeq_processed || num_mcceq_processed) { |
| 969 | if (pbe_eq->todo_mcc_cq) |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 970 | queue_work(phba->wq, &pbe_eq->work_cqs); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 971 | |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 972 | if ((num_mcceq_processed) && (!num_ioeq_processed)) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 973 | hwi_ring_eq_db(phba, eq->id, 0, |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 974 | (num_ioeq_processed + |
| 975 | num_mcceq_processed) , 1, 1); |
| 976 | else |
| 977 | hwi_ring_eq_db(phba, eq->id, 0, |
| 978 | (num_ioeq_processed + |
| 979 | num_mcceq_processed), 0, 1); |
| 980 | |
| 981 | return IRQ_HANDLED; |
| 982 | } else |
| 983 | return IRQ_NONE; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 984 | } |
| 985 | |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 986 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 987 | static int beiscsi_init_irqs(struct beiscsi_hba *phba) |
| 988 | { |
| 989 | struct pci_dev *pcidev = phba->pcidev; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 990 | struct hwi_controller *phwi_ctrlr; |
| 991 | struct hwi_context_memory *phwi_context; |
Jayamohan Kallickal | 4f5af07 | 2010-07-22 04:23:55 +0530 | [diff] [blame] | 992 | int ret, msix_vec, i, j; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 993 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 994 | phwi_ctrlr = phba->phwi_ctrlr; |
| 995 | phwi_context = phwi_ctrlr->phwi_ctxt; |
| 996 | |
| 997 | if (phba->msix_enabled) { |
| 998 | for (i = 0; i < phba->num_cpus; i++) { |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 999 | phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME, |
| 1000 | GFP_KERNEL); |
| 1001 | if (!phba->msi_name[i]) { |
| 1002 | ret = -ENOMEM; |
| 1003 | goto free_msix_irqs; |
| 1004 | } |
| 1005 | |
| 1006 | sprintf(phba->msi_name[i], "beiscsi_%02x_%02x", |
| 1007 | phba->shost->host_no, i); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1008 | msix_vec = phba->msix_entries[i].vector; |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 1009 | ret = request_irq(msix_vec, be_isr_msix, 0, |
| 1010 | 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-Failed to" |
| 1015 | "register msix for i = %d\n", |
| 1016 | i); |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 1017 | kfree(phba->msi_name[i]); |
Jayamohan Kallickal | 4f5af07 | 2010-07-22 04:23:55 +0530 | [diff] [blame] | 1018 | goto free_msix_irqs; |
| 1019 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1020 | } |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 1021 | phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME, GFP_KERNEL); |
| 1022 | if (!phba->msi_name[i]) { |
| 1023 | ret = -ENOMEM; |
| 1024 | goto free_msix_irqs; |
| 1025 | } |
| 1026 | sprintf(phba->msi_name[i], "beiscsi_mcc_%02x", |
| 1027 | phba->shost->host_no); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1028 | msix_vec = phba->msix_entries[i].vector; |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 1029 | 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] | 1030 | &phwi_context->be_eq[i]); |
Jayamohan Kallickal | 4f5af07 | 2010-07-22 04:23:55 +0530 | [diff] [blame] | 1031 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1032 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT , |
| 1033 | "BM_%d : beiscsi_init_irqs-" |
| 1034 | "Failed to register beiscsi_msix_mcc\n"); |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 1035 | kfree(phba->msi_name[i]); |
Jayamohan Kallickal | 4f5af07 | 2010-07-22 04:23:55 +0530 | [diff] [blame] | 1036 | goto free_msix_irqs; |
| 1037 | } |
| 1038 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1039 | } else { |
| 1040 | ret = request_irq(pcidev->irq, be_isr, IRQF_SHARED, |
| 1041 | "beiscsi", phba); |
| 1042 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1043 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 1044 | "BM_%d : beiscsi_init_irqs-" |
| 1045 | "Failed to register irq\\n"); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1046 | return ret; |
| 1047 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1048 | } |
| 1049 | return 0; |
Jayamohan Kallickal | 4f5af07 | 2010-07-22 04:23:55 +0530 | [diff] [blame] | 1050 | free_msix_irqs: |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 1051 | for (j = i - 1; j >= 0; j--) { |
| 1052 | kfree(phba->msi_name[j]); |
| 1053 | msix_vec = phba->msix_entries[j].vector; |
Jayamohan Kallickal | 4f5af07 | 2010-07-22 04:23:55 +0530 | [diff] [blame] | 1054 | free_irq(msix_vec, &phwi_context->be_eq[j]); |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 1055 | } |
Jayamohan Kallickal | 4f5af07 | 2010-07-22 04:23:55 +0530 | [diff] [blame] | 1056 | return ret; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1057 | } |
| 1058 | |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 1059 | void hwi_ring_cq_db(struct beiscsi_hba *phba, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1060 | unsigned int id, unsigned int num_processed, |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 1061 | unsigned char rearm) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1062 | { |
| 1063 | u32 val = 0; |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 1064 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1065 | if (rearm) |
| 1066 | val |= 1 << DB_CQ_REARM_SHIFT; |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 1067 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1068 | val |= num_processed << DB_CQ_NUM_POPPED_SHIFT; |
Jayamohan Kallickal | e08b3c8 | 2014-01-29 02:16:42 -0500 | [diff] [blame] | 1069 | |
| 1070 | /* Setting lower order CQ_ID Bits */ |
| 1071 | val |= (id & DB_CQ_RING_ID_LOW_MASK); |
| 1072 | |
| 1073 | /* Setting Higher order CQ_ID Bits */ |
| 1074 | val |= (((id >> DB_CQ_HIGH_FEILD_SHIFT) & |
| 1075 | DB_CQ_RING_ID_HIGH_MASK) |
| 1076 | << DB_CQ_HIGH_SET_SHIFT); |
| 1077 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1078 | iowrite32(val, phba->db_va + DB_CQ_OFFSET); |
| 1079 | } |
| 1080 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1081 | static unsigned int |
| 1082 | beiscsi_process_async_pdu(struct beiscsi_conn *beiscsi_conn, |
| 1083 | struct beiscsi_hba *phba, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1084 | struct pdu_base *ppdu, |
| 1085 | unsigned long pdu_len, |
| 1086 | void *pbuffer, unsigned long buf_len) |
| 1087 | { |
| 1088 | struct iscsi_conn *conn = beiscsi_conn->conn; |
| 1089 | struct iscsi_session *session = conn->session; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1090 | struct iscsi_task *task; |
| 1091 | struct beiscsi_io_task *io_task; |
| 1092 | struct iscsi_hdr *login_hdr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1093 | |
| 1094 | switch (ppdu->dw[offsetof(struct amap_pdu_base, opcode) / 32] & |
| 1095 | PDUBASE_OPCODE_MASK) { |
| 1096 | case ISCSI_OP_NOOP_IN: |
| 1097 | pbuffer = NULL; |
| 1098 | buf_len = 0; |
| 1099 | break; |
| 1100 | case ISCSI_OP_ASYNC_EVENT: |
| 1101 | break; |
| 1102 | case ISCSI_OP_REJECT: |
| 1103 | WARN_ON(!pbuffer); |
| 1104 | WARN_ON(!(buf_len == 48)); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1105 | beiscsi_log(phba, KERN_ERR, |
| 1106 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
| 1107 | "BM_%d : In ISCSI_OP_REJECT\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1108 | break; |
| 1109 | case ISCSI_OP_LOGIN_RSP: |
Jayamohan Kallickal | 7bd6e25 | 2010-01-05 05:07:02 +0530 | [diff] [blame] | 1110 | case ISCSI_OP_TEXT_RSP: |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1111 | task = conn->login_task; |
| 1112 | io_task = task->dd_data; |
| 1113 | login_hdr = (struct iscsi_hdr *)ppdu; |
| 1114 | login_hdr->itt = io_task->libiscsi_itt; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1115 | break; |
| 1116 | default: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1117 | beiscsi_log(phba, KERN_WARNING, |
| 1118 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
| 1119 | "BM_%d : Unrecognized opcode 0x%x in async msg\n", |
| 1120 | (ppdu-> |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1121 | dw[offsetof(struct amap_pdu_base, opcode) / 32] |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1122 | & PDUBASE_OPCODE_MASK)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1123 | return 1; |
| 1124 | } |
| 1125 | |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 1126 | spin_lock_bh(&session->back_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1127 | __iscsi_complete_pdu(conn, (struct iscsi_hdr *)ppdu, pbuffer, buf_len); |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 1128 | spin_unlock_bh(&session->back_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1129 | return 0; |
| 1130 | } |
| 1131 | |
| 1132 | static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba) |
| 1133 | { |
| 1134 | struct sgl_handle *psgl_handle; |
| 1135 | |
| 1136 | if (phba->io_sgl_hndl_avbl) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1137 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO, |
| 1138 | "BM_%d : In alloc_io_sgl_handle," |
| 1139 | " io_sgl_alloc_index=%d\n", |
| 1140 | phba->io_sgl_alloc_index); |
| 1141 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1142 | psgl_handle = phba->io_sgl_hndl_base[phba-> |
| 1143 | io_sgl_alloc_index]; |
| 1144 | phba->io_sgl_hndl_base[phba->io_sgl_alloc_index] = NULL; |
| 1145 | phba->io_sgl_hndl_avbl--; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1146 | if (phba->io_sgl_alloc_index == (phba->params. |
| 1147 | ios_per_ctrl - 1)) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1148 | phba->io_sgl_alloc_index = 0; |
| 1149 | else |
| 1150 | phba->io_sgl_alloc_index++; |
| 1151 | } else |
| 1152 | psgl_handle = NULL; |
| 1153 | return psgl_handle; |
| 1154 | } |
| 1155 | |
| 1156 | static void |
| 1157 | free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle) |
| 1158 | { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1159 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO, |
| 1160 | "BM_%d : In free_,io_sgl_free_index=%d\n", |
| 1161 | phba->io_sgl_free_index); |
| 1162 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1163 | if (phba->io_sgl_hndl_base[phba->io_sgl_free_index]) { |
| 1164 | /* |
| 1165 | * this can happen if clean_task is called on a task that |
| 1166 | * failed in xmit_task or alloc_pdu. |
| 1167 | */ |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1168 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO, |
| 1169 | "BM_%d : Double Free in IO SGL io_sgl_free_index=%d," |
| 1170 | "value there=%p\n", phba->io_sgl_free_index, |
| 1171 | phba->io_sgl_hndl_base |
| 1172 | [phba->io_sgl_free_index]); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1173 | return; |
| 1174 | } |
| 1175 | phba->io_sgl_hndl_base[phba->io_sgl_free_index] = psgl_handle; |
| 1176 | phba->io_sgl_hndl_avbl++; |
| 1177 | if (phba->io_sgl_free_index == (phba->params.ios_per_ctrl - 1)) |
| 1178 | phba->io_sgl_free_index = 0; |
| 1179 | else |
| 1180 | phba->io_sgl_free_index++; |
| 1181 | } |
| 1182 | |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame^] | 1183 | static inline struct wrb_handle * |
| 1184 | beiscsi_get_wrb_handle(struct hwi_wrb_context *pwrb_context, |
| 1185 | unsigned int wrbs_per_cxn) |
| 1186 | { |
| 1187 | struct wrb_handle *pwrb_handle; |
| 1188 | |
| 1189 | pwrb_handle = pwrb_context->pwrb_handle_base[pwrb_context->alloc_index]; |
| 1190 | pwrb_context->wrb_handles_available--; |
| 1191 | if (pwrb_context->alloc_index == (wrbs_per_cxn - 1)) |
| 1192 | pwrb_context->alloc_index = 0; |
| 1193 | else |
| 1194 | pwrb_context->alloc_index++; |
| 1195 | |
| 1196 | return pwrb_handle; |
| 1197 | } |
| 1198 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1199 | /** |
| 1200 | * alloc_wrb_handle - To allocate a wrb handle |
| 1201 | * @phba: The hba pointer |
| 1202 | * @cid: The cid to use for allocation |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 1203 | * @pwrb_context: ptr to ptr to wrb context |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1204 | * |
| 1205 | * This happens under session_lock until submission to chip |
| 1206 | */ |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 1207 | 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^] | 1208 | struct hwi_wrb_context **pcontext) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1209 | { |
| 1210 | struct hwi_wrb_context *pwrb_context; |
| 1211 | struct hwi_controller *phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 1212 | uint16_t cri_index = BE_GET_CRI_FROM_CID(cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1213 | |
| 1214 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 1215 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame^] | 1216 | /* return the context address */ |
| 1217 | *pcontext = pwrb_context; |
| 1218 | return beiscsi_get_wrb_handle(pwrb_context, phba->params.wrbs_per_cxn); |
| 1219 | } |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 1220 | |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame^] | 1221 | static inline void |
| 1222 | beiscsi_put_wrb_handle(struct hwi_wrb_context *pwrb_context, |
| 1223 | struct wrb_handle *pwrb_handle, |
| 1224 | unsigned int wrbs_per_cxn) |
| 1225 | { |
| 1226 | pwrb_context->pwrb_handle_base[pwrb_context->free_index] = pwrb_handle; |
| 1227 | pwrb_context->wrb_handles_available++; |
| 1228 | if (pwrb_context->free_index == (wrbs_per_cxn - 1)) |
| 1229 | pwrb_context->free_index = 0; |
| 1230 | else |
| 1231 | pwrb_context->free_index++; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | /** |
| 1235 | * free_wrb_handle - To free the wrb handle back to pool |
| 1236 | * @phba: The hba pointer |
| 1237 | * @pwrb_context: The context to free from |
| 1238 | * @pwrb_handle: The wrb_handle to free |
| 1239 | * |
| 1240 | * This happens under session_lock until submission to chip |
| 1241 | */ |
| 1242 | static void |
| 1243 | free_wrb_handle(struct beiscsi_hba *phba, struct hwi_wrb_context *pwrb_context, |
| 1244 | struct wrb_handle *pwrb_handle) |
| 1245 | { |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame^] | 1246 | beiscsi_put_wrb_handle(pwrb_context, |
| 1247 | pwrb_handle, |
| 1248 | phba->params.wrbs_per_cxn); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1249 | beiscsi_log(phba, KERN_INFO, |
| 1250 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
| 1251 | "BM_%d : FREE WRB: pwrb_handle=%p free_index=0x%x" |
| 1252 | "wrb_handles_available=%d\n", |
| 1253 | pwrb_handle, pwrb_context->free_index, |
| 1254 | pwrb_context->wrb_handles_available); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba) |
| 1258 | { |
| 1259 | struct sgl_handle *psgl_handle; |
| 1260 | |
| 1261 | if (phba->eh_sgl_hndl_avbl) { |
| 1262 | psgl_handle = phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index]; |
| 1263 | phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index] = NULL; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1264 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG, |
| 1265 | "BM_%d : mgmt_sgl_alloc_index=%d=0x%x\n", |
| 1266 | phba->eh_sgl_alloc_index, |
| 1267 | phba->eh_sgl_alloc_index); |
| 1268 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1269 | phba->eh_sgl_hndl_avbl--; |
| 1270 | if (phba->eh_sgl_alloc_index == |
| 1271 | (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl - |
| 1272 | 1)) |
| 1273 | phba->eh_sgl_alloc_index = 0; |
| 1274 | else |
| 1275 | phba->eh_sgl_alloc_index++; |
| 1276 | } else |
| 1277 | psgl_handle = NULL; |
| 1278 | return psgl_handle; |
| 1279 | } |
| 1280 | |
| 1281 | void |
| 1282 | free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle) |
| 1283 | { |
| 1284 | |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1285 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG, |
| 1286 | "BM_%d : In free_mgmt_sgl_handle," |
| 1287 | "eh_sgl_free_index=%d\n", |
| 1288 | phba->eh_sgl_free_index); |
| 1289 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1290 | if (phba->eh_sgl_hndl_base[phba->eh_sgl_free_index]) { |
| 1291 | /* |
| 1292 | * this can happen if clean_task is called on a task that |
| 1293 | * failed in xmit_task or alloc_pdu. |
| 1294 | */ |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1295 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG, |
| 1296 | "BM_%d : Double Free in eh SGL ," |
| 1297 | "eh_sgl_free_index=%d\n", |
| 1298 | phba->eh_sgl_free_index); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1299 | return; |
| 1300 | } |
| 1301 | phba->eh_sgl_hndl_base[phba->eh_sgl_free_index] = psgl_handle; |
| 1302 | phba->eh_sgl_hndl_avbl++; |
| 1303 | if (phba->eh_sgl_free_index == |
| 1304 | (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl - 1)) |
| 1305 | phba->eh_sgl_free_index = 0; |
| 1306 | else |
| 1307 | phba->eh_sgl_free_index++; |
| 1308 | } |
| 1309 | |
| 1310 | static void |
| 1311 | be_complete_io(struct beiscsi_conn *beiscsi_conn, |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1312 | struct iscsi_task *task, |
| 1313 | struct common_sol_cqe *csol_cqe) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1314 | { |
| 1315 | struct beiscsi_io_task *io_task = task->dd_data; |
| 1316 | struct be_status_bhs *sts_bhs = |
| 1317 | (struct be_status_bhs *)io_task->cmd_bhs; |
| 1318 | struct iscsi_conn *conn = beiscsi_conn->conn; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1319 | unsigned char *sense; |
| 1320 | u32 resid = 0, exp_cmdsn, max_cmdsn; |
| 1321 | u8 rsp, status, flags; |
| 1322 | |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1323 | exp_cmdsn = csol_cqe->exp_cmdsn; |
| 1324 | max_cmdsn = (csol_cqe->exp_cmdsn + |
| 1325 | csol_cqe->cmd_wnd - 1); |
| 1326 | rsp = csol_cqe->i_resp; |
| 1327 | status = csol_cqe->i_sts; |
| 1328 | flags = csol_cqe->i_flags; |
| 1329 | resid = csol_cqe->res_cnt; |
| 1330 | |
Jayamohan Kallickal | bd53545 | 2011-10-07 19:31:10 -0500 | [diff] [blame] | 1331 | if (!task->sc) { |
Jayamohan Kallickal | da33497 | 2014-01-29 02:16:44 -0500 | [diff] [blame] | 1332 | if (io_task->scsi_cmnd) { |
Jayamohan Kallickal | bd53545 | 2011-10-07 19:31:10 -0500 | [diff] [blame] | 1333 | scsi_dma_unmap(io_task->scsi_cmnd); |
Jayamohan Kallickal | da33497 | 2014-01-29 02:16:44 -0500 | [diff] [blame] | 1334 | io_task->scsi_cmnd = NULL; |
| 1335 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1336 | |
Jayamohan Kallickal | bd53545 | 2011-10-07 19:31:10 -0500 | [diff] [blame] | 1337 | return; |
| 1338 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1339 | task->sc->result = (DID_OK << 16) | status; |
| 1340 | if (rsp != ISCSI_STATUS_CMD_COMPLETED) { |
| 1341 | task->sc->result = DID_ERROR << 16; |
| 1342 | goto unmap; |
| 1343 | } |
| 1344 | |
| 1345 | /* bidi not initially supported */ |
| 1346 | if (flags & (ISCSI_FLAG_CMD_UNDERFLOW | ISCSI_FLAG_CMD_OVERFLOW)) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1347 | if (!status && (flags & ISCSI_FLAG_CMD_OVERFLOW)) |
| 1348 | task->sc->result = DID_ERROR << 16; |
| 1349 | |
| 1350 | if (flags & ISCSI_FLAG_CMD_UNDERFLOW) { |
| 1351 | scsi_set_resid(task->sc, resid); |
| 1352 | if (!status && (scsi_bufflen(task->sc) - resid < |
| 1353 | task->sc->underflow)) |
| 1354 | task->sc->result = DID_ERROR << 16; |
| 1355 | } |
| 1356 | } |
| 1357 | |
| 1358 | if (status == SAM_STAT_CHECK_CONDITION) { |
Dan Carpenter | 4053a4b | 2011-09-26 09:23:37 +0300 | [diff] [blame] | 1359 | u16 sense_len; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1360 | unsigned short *slen = (unsigned short *)sts_bhs->sense_info; |
Dan Carpenter | 4053a4b | 2011-09-26 09:23:37 +0300 | [diff] [blame] | 1361 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1362 | sense = sts_bhs->sense_info + sizeof(unsigned short); |
Dan Carpenter | 4053a4b | 2011-09-26 09:23:37 +0300 | [diff] [blame] | 1363 | sense_len = be16_to_cpu(*slen); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1364 | memcpy(task->sc->sense_buffer, sense, |
| 1365 | min_t(u16, sense_len, SCSI_SENSE_BUFFERSIZE)); |
| 1366 | } |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 1367 | |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1368 | if (io_task->cmd_bhs->iscsi_hdr.flags & ISCSI_FLAG_CMD_READ) |
| 1369 | conn->rxdata_octets += resid; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1370 | unmap: |
John Soni Jose | eb1c469 | 2015-04-25 08:17:45 +0530 | [diff] [blame] | 1371 | if (io_task->scsi_cmnd) { |
| 1372 | scsi_dma_unmap(io_task->scsi_cmnd); |
| 1373 | io_task->scsi_cmnd = NULL; |
| 1374 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1375 | iscsi_complete_scsi_task(task, exp_cmdsn, max_cmdsn); |
| 1376 | } |
| 1377 | |
| 1378 | static void |
| 1379 | be_complete_logout(struct beiscsi_conn *beiscsi_conn, |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1380 | struct iscsi_task *task, |
| 1381 | struct common_sol_cqe *csol_cqe) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1382 | { |
| 1383 | struct iscsi_logout_rsp *hdr; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1384 | struct beiscsi_io_task *io_task = task->dd_data; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1385 | struct iscsi_conn *conn = beiscsi_conn->conn; |
| 1386 | |
| 1387 | hdr = (struct iscsi_logout_rsp *)task->hdr; |
Jayamohan Kallickal | 7bd6e25 | 2010-01-05 05:07:02 +0530 | [diff] [blame] | 1388 | hdr->opcode = ISCSI_OP_LOGOUT_RSP; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1389 | hdr->t2wait = 5; |
| 1390 | hdr->t2retain = 0; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1391 | hdr->flags = csol_cqe->i_flags; |
| 1392 | hdr->response = csol_cqe->i_resp; |
Jayamohan Kallickal | 702dc5e | 2013-04-05 20:38:37 -0700 | [diff] [blame] | 1393 | hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn); |
| 1394 | hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn + |
| 1395 | csol_cqe->cmd_wnd - 1); |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1396 | |
Jayamohan Kallickal | 7bd6e25 | 2010-01-05 05:07:02 +0530 | [diff] [blame] | 1397 | hdr->dlength[0] = 0; |
| 1398 | hdr->dlength[1] = 0; |
| 1399 | hdr->dlength[2] = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1400 | hdr->hlength = 0; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1401 | hdr->itt = io_task->libiscsi_itt; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1402 | __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0); |
| 1403 | } |
| 1404 | |
| 1405 | static void |
| 1406 | be_complete_tmf(struct beiscsi_conn *beiscsi_conn, |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1407 | struct iscsi_task *task, |
| 1408 | struct common_sol_cqe *csol_cqe) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1409 | { |
| 1410 | struct iscsi_tm_rsp *hdr; |
| 1411 | struct iscsi_conn *conn = beiscsi_conn->conn; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1412 | struct beiscsi_io_task *io_task = task->dd_data; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1413 | |
| 1414 | hdr = (struct iscsi_tm_rsp *)task->hdr; |
Jayamohan Kallickal | 7bd6e25 | 2010-01-05 05:07:02 +0530 | [diff] [blame] | 1415 | hdr->opcode = ISCSI_OP_SCSI_TMFUNC_RSP; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1416 | hdr->flags = csol_cqe->i_flags; |
| 1417 | hdr->response = csol_cqe->i_resp; |
Jayamohan Kallickal | 702dc5e | 2013-04-05 20:38:37 -0700 | [diff] [blame] | 1418 | hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn); |
| 1419 | hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn + |
| 1420 | csol_cqe->cmd_wnd - 1); |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1421 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1422 | hdr->itt = io_task->libiscsi_itt; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1423 | __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0); |
| 1424 | } |
| 1425 | |
| 1426 | static void |
| 1427 | hwi_complete_drvr_msgs(struct beiscsi_conn *beiscsi_conn, |
| 1428 | struct beiscsi_hba *phba, struct sol_cqe *psol) |
| 1429 | { |
| 1430 | struct hwi_wrb_context *pwrb_context; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1431 | struct wrb_handle *pwrb_handle = NULL; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1432 | struct hwi_controller *phwi_ctrlr; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1433 | struct iscsi_task *task; |
| 1434 | struct beiscsi_io_task *io_task; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 1435 | uint16_t wrb_index, cid, cri_index; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1436 | |
| 1437 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 1438 | if (is_chip_be2_be3r(phba)) { |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1439 | wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe, |
| 1440 | wrb_idx, psol); |
| 1441 | cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe, |
| 1442 | cid, psol); |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 1443 | } else { |
| 1444 | wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2, |
| 1445 | wrb_idx, psol); |
| 1446 | cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2, |
| 1447 | cid, psol); |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1448 | } |
| 1449 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 1450 | cri_index = BE_GET_CRI_FROM_CID(cid); |
| 1451 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1452 | pwrb_handle = pwrb_context->pwrb_handle_basestd[wrb_index]; |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 1453 | task = pwrb_handle->pio_handle; |
Jayamohan Kallickal | 35e6601 | 2009-10-23 11:53:49 +0530 | [diff] [blame] | 1454 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1455 | io_task = task->dd_data; |
Jayamohan Kallickal | 4a4a11b | 2013-04-05 20:38:31 -0700 | [diff] [blame] | 1456 | memset(io_task->pwrb_handle->pwrb, 0, sizeof(struct iscsi_wrb)); |
| 1457 | iscsi_put_task(task); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1458 | } |
| 1459 | |
| 1460 | static void |
| 1461 | be_complete_nopin_resp(struct beiscsi_conn *beiscsi_conn, |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1462 | struct iscsi_task *task, |
| 1463 | struct common_sol_cqe *csol_cqe) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1464 | { |
| 1465 | struct iscsi_nopin *hdr; |
| 1466 | struct iscsi_conn *conn = beiscsi_conn->conn; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1467 | struct beiscsi_io_task *io_task = task->dd_data; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1468 | |
| 1469 | hdr = (struct iscsi_nopin *)task->hdr; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1470 | hdr->flags = csol_cqe->i_flags; |
| 1471 | hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn); |
Jayamohan Kallickal | 702dc5e | 2013-04-05 20:38:37 -0700 | [diff] [blame] | 1472 | hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn + |
| 1473 | csol_cqe->cmd_wnd - 1); |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1474 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1475 | hdr->opcode = ISCSI_OP_NOOP_IN; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1476 | hdr->itt = io_task->libiscsi_itt; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1477 | __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0); |
| 1478 | } |
| 1479 | |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1480 | static void adapter_get_sol_cqe(struct beiscsi_hba *phba, |
| 1481 | struct sol_cqe *psol, |
| 1482 | struct common_sol_cqe *csol_cqe) |
| 1483 | { |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 1484 | if (is_chip_be2_be3r(phba)) { |
| 1485 | csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1486 | i_exp_cmd_sn, psol); |
| 1487 | csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1488 | i_res_cnt, psol); |
| 1489 | csol_cqe->cmd_wnd = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1490 | i_cmd_wnd, psol); |
| 1491 | csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1492 | wrb_index, psol); |
| 1493 | csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1494 | cid, psol); |
| 1495 | csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1496 | hw_sts, psol); |
| 1497 | csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1498 | i_resp, psol); |
| 1499 | csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1500 | i_sts, psol); |
| 1501 | csol_cqe->i_flags = AMAP_GET_BITS(struct amap_sol_cqe, |
| 1502 | i_flags, psol); |
| 1503 | } else { |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1504 | csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1505 | i_exp_cmd_sn, psol); |
| 1506 | csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1507 | i_res_cnt, psol); |
| 1508 | csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1509 | wrb_index, psol); |
| 1510 | csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1511 | cid, psol); |
| 1512 | csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1513 | hw_sts, psol); |
Jayamohan Kallickal | 702dc5e | 2013-04-05 20:38:37 -0700 | [diff] [blame] | 1514 | 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] | 1515 | i_cmd_wnd, psol); |
| 1516 | if (AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1517 | cmd_cmpl, psol)) |
| 1518 | csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1519 | i_sts, psol); |
| 1520 | else |
| 1521 | csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1522 | i_sts, psol); |
| 1523 | if (AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1524 | u, psol)) |
| 1525 | csol_cqe->i_flags = ISCSI_FLAG_CMD_UNDERFLOW; |
| 1526 | |
| 1527 | if (AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 1528 | o, psol)) |
| 1529 | csol_cqe->i_flags |= ISCSI_FLAG_CMD_OVERFLOW; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1530 | } |
| 1531 | } |
| 1532 | |
| 1533 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1534 | static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn, |
| 1535 | struct beiscsi_hba *phba, struct sol_cqe *psol) |
| 1536 | { |
| 1537 | struct hwi_wrb_context *pwrb_context; |
| 1538 | struct wrb_handle *pwrb_handle; |
| 1539 | struct iscsi_wrb *pwrb = NULL; |
| 1540 | struct hwi_controller *phwi_ctrlr; |
| 1541 | struct iscsi_task *task; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1542 | unsigned int type; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1543 | struct iscsi_conn *conn = beiscsi_conn->conn; |
| 1544 | struct iscsi_session *session = conn->session; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1545 | struct common_sol_cqe csol_cqe = {0}; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 1546 | uint16_t cri_index = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1547 | |
| 1548 | phwi_ctrlr = phba->phwi_ctrlr; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1549 | |
| 1550 | /* Copy the elements to a common structure */ |
| 1551 | adapter_get_sol_cqe(phba, psol, &csol_cqe); |
| 1552 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 1553 | cri_index = BE_GET_CRI_FROM_CID(csol_cqe.cid); |
| 1554 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1555 | |
| 1556 | pwrb_handle = pwrb_context->pwrb_handle_basestd[ |
| 1557 | csol_cqe.wrb_index]; |
| 1558 | |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 1559 | task = pwrb_handle->pio_handle; |
| 1560 | pwrb = pwrb_handle->pwrb; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1561 | type = ((struct beiscsi_io_task *)task->dd_data)->wrb_type; |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 1562 | |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 1563 | spin_lock_bh(&session->back_lock); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1564 | switch (type) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1565 | case HWH_TYPE_IO: |
| 1566 | case HWH_TYPE_IO_RD: |
| 1567 | if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 1568 | ISCSI_OP_NOOP_OUT) |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1569 | be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe); |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 1570 | else |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1571 | be_complete_io(beiscsi_conn, task, &csol_cqe); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1572 | break; |
| 1573 | |
| 1574 | case HWH_TYPE_LOGOUT: |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 1575 | if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGOUT) |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1576 | be_complete_logout(beiscsi_conn, task, &csol_cqe); |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 1577 | else |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1578 | be_complete_tmf(beiscsi_conn, task, &csol_cqe); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1579 | break; |
| 1580 | |
| 1581 | case HWH_TYPE_LOGIN: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1582 | beiscsi_log(phba, KERN_ERR, |
| 1583 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
| 1584 | "BM_%d :\t\t No HWH_TYPE_LOGIN Expected in" |
| 1585 | " hwi_complete_cmd- Solicited path\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1586 | break; |
| 1587 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1588 | case HWH_TYPE_NOP: |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1589 | be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1590 | break; |
| 1591 | |
| 1592 | default: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1593 | beiscsi_log(phba, KERN_WARNING, |
| 1594 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
| 1595 | "BM_%d : In hwi_complete_cmd, unknown type = %d" |
| 1596 | "wrb_index 0x%x CID 0x%x\n", type, |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1597 | csol_cqe.wrb_index, |
| 1598 | csol_cqe.cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1599 | break; |
| 1600 | } |
Jayamohan Kallickal | 35e6601 | 2009-10-23 11:53:49 +0530 | [diff] [blame] | 1601 | |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 1602 | spin_unlock_bh(&session->back_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | static struct list_head *hwi_get_async_busy_list(struct hwi_async_pdu_context |
| 1606 | *pasync_ctx, unsigned int is_header, |
| 1607 | unsigned int host_write_ptr) |
| 1608 | { |
| 1609 | if (is_header) |
| 1610 | return &pasync_ctx->async_entry[host_write_ptr]. |
| 1611 | header_busy_list; |
| 1612 | else |
| 1613 | return &pasync_ctx->async_entry[host_write_ptr].data_busy_list; |
| 1614 | } |
| 1615 | |
| 1616 | static struct async_pdu_handle * |
| 1617 | hwi_get_async_handle(struct beiscsi_hba *phba, |
| 1618 | struct beiscsi_conn *beiscsi_conn, |
| 1619 | struct hwi_async_pdu_context *pasync_ctx, |
| 1620 | struct i_t_dpdu_cqe *pdpdu_cqe, unsigned int *pcq_index) |
| 1621 | { |
| 1622 | struct be_bus_address phys_addr; |
| 1623 | struct list_head *pbusy_list; |
| 1624 | struct async_pdu_handle *pasync_handle = NULL; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1625 | unsigned char is_header = 0; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1626 | unsigned int index, dpl; |
| 1627 | |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 1628 | if (is_chip_be2_be3r(phba)) { |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1629 | dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, |
| 1630 | dpl, pdpdu_cqe); |
| 1631 | index = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe, |
| 1632 | index, pdpdu_cqe); |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 1633 | } else { |
| 1634 | dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2, |
| 1635 | dpl, pdpdu_cqe); |
| 1636 | index = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2, |
| 1637 | index, pdpdu_cqe); |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1638 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1639 | |
| 1640 | phys_addr.u.a32.address_lo = |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1641 | (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, |
| 1642 | db_addr_lo) / 32] - dpl); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1643 | phys_addr.u.a32.address_hi = |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1644 | pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, |
| 1645 | db_addr_hi) / 32]; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1646 | |
| 1647 | phys_addr.u.a64.address = |
| 1648 | *((unsigned long long *)(&phys_addr.u.a64.address)); |
| 1649 | |
| 1650 | switch (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, code) / 32] |
| 1651 | & PDUCQE_CODE_MASK) { |
| 1652 | case UNSOL_HDR_NOTIFY: |
| 1653 | is_header = 1; |
| 1654 | |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1655 | pbusy_list = hwi_get_async_busy_list(pasync_ctx, |
| 1656 | is_header, index); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1657 | break; |
| 1658 | case UNSOL_DATA_NOTIFY: |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1659 | pbusy_list = hwi_get_async_busy_list(pasync_ctx, |
| 1660 | is_header, index); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1661 | break; |
| 1662 | default: |
| 1663 | pbusy_list = NULL; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1664 | beiscsi_log(phba, KERN_WARNING, |
| 1665 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
| 1666 | "BM_%d : Unexpected code=%d\n", |
| 1667 | pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, |
| 1668 | code) / 32] & PDUCQE_CODE_MASK); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1669 | return NULL; |
| 1670 | } |
| 1671 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1672 | WARN_ON(list_empty(pbusy_list)); |
| 1673 | list_for_each_entry(pasync_handle, pbusy_list, link) { |
Jayamohan Kallickal | dc63aac | 2012-04-03 23:41:36 -0500 | [diff] [blame] | 1674 | if (pasync_handle->pa.u.a64.address == phys_addr.u.a64.address) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1675 | break; |
| 1676 | } |
| 1677 | |
| 1678 | WARN_ON(!pasync_handle); |
| 1679 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1680 | pasync_handle->cri = BE_GET_ASYNC_CRI_FROM_CID( |
| 1681 | beiscsi_conn->beiscsi_conn_cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1682 | pasync_handle->is_header = is_header; |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 1683 | pasync_handle->buffer_len = dpl; |
| 1684 | *pcq_index = index; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1685 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1686 | return pasync_handle; |
| 1687 | } |
| 1688 | |
| 1689 | static unsigned int |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1690 | hwi_update_async_writables(struct beiscsi_hba *phba, |
| 1691 | struct hwi_async_pdu_context *pasync_ctx, |
| 1692 | unsigned int is_header, unsigned int cq_index) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1693 | { |
| 1694 | struct list_head *pbusy_list; |
| 1695 | struct async_pdu_handle *pasync_handle; |
| 1696 | unsigned int num_entries, writables = 0; |
| 1697 | unsigned int *pep_read_ptr, *pwritables; |
| 1698 | |
Jayamohan Kallickal | dc63aac | 2012-04-03 23:41:36 -0500 | [diff] [blame] | 1699 | num_entries = pasync_ctx->num_entries; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1700 | if (is_header) { |
| 1701 | pep_read_ptr = &pasync_ctx->async_header.ep_read_ptr; |
| 1702 | pwritables = &pasync_ctx->async_header.writables; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1703 | } else { |
| 1704 | pep_read_ptr = &pasync_ctx->async_data.ep_read_ptr; |
| 1705 | pwritables = &pasync_ctx->async_data.writables; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1706 | } |
| 1707 | |
| 1708 | while ((*pep_read_ptr) != cq_index) { |
| 1709 | (*pep_read_ptr)++; |
| 1710 | *pep_read_ptr = (*pep_read_ptr) % num_entries; |
| 1711 | |
| 1712 | pbusy_list = hwi_get_async_busy_list(pasync_ctx, is_header, |
| 1713 | *pep_read_ptr); |
| 1714 | if (writables == 0) |
| 1715 | WARN_ON(list_empty(pbusy_list)); |
| 1716 | |
| 1717 | if (!list_empty(pbusy_list)) { |
| 1718 | pasync_handle = list_entry(pbusy_list->next, |
| 1719 | struct async_pdu_handle, |
| 1720 | link); |
| 1721 | WARN_ON(!pasync_handle); |
| 1722 | pasync_handle->consumed = 1; |
| 1723 | } |
| 1724 | |
| 1725 | writables++; |
| 1726 | } |
| 1727 | |
| 1728 | if (!writables) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1729 | beiscsi_log(phba, KERN_ERR, |
| 1730 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
| 1731 | "BM_%d : Duplicate notification received - index 0x%x!!\n", |
| 1732 | cq_index); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1733 | WARN_ON(1); |
| 1734 | } |
| 1735 | |
| 1736 | *pwritables = *pwritables + writables; |
| 1737 | return 0; |
| 1738 | } |
| 1739 | |
Jayamohan Kallickal | 9728d8d | 2012-04-03 23:41:47 -0500 | [diff] [blame] | 1740 | static void hwi_free_async_msg(struct beiscsi_hba *phba, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1741 | struct hwi_async_pdu_context *pasync_ctx, |
| 1742 | unsigned int cri) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1743 | { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1744 | struct async_pdu_handle *pasync_handle, *tmp_handle; |
| 1745 | struct list_head *plist; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1746 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1747 | plist = &pasync_ctx->async_entry[cri].wait_queue.list; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1748 | list_for_each_entry_safe(pasync_handle, tmp_handle, plist, link) { |
| 1749 | list_del(&pasync_handle->link); |
| 1750 | |
Jayamohan Kallickal | 9728d8d | 2012-04-03 23:41:47 -0500 | [diff] [blame] | 1751 | if (pasync_handle->is_header) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1752 | list_add_tail(&pasync_handle->link, |
| 1753 | &pasync_ctx->async_header.free_list); |
| 1754 | pasync_ctx->async_header.free_entries++; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1755 | } else { |
| 1756 | list_add_tail(&pasync_handle->link, |
| 1757 | &pasync_ctx->async_data.free_list); |
| 1758 | pasync_ctx->async_data.free_entries++; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1759 | } |
| 1760 | } |
| 1761 | |
| 1762 | INIT_LIST_HEAD(&pasync_ctx->async_entry[cri].wait_queue.list); |
| 1763 | pasync_ctx->async_entry[cri].wait_queue.hdr_received = 0; |
| 1764 | pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1765 | } |
| 1766 | |
| 1767 | static struct phys_addr * |
| 1768 | hwi_get_ring_address(struct hwi_async_pdu_context *pasync_ctx, |
| 1769 | unsigned int is_header, unsigned int host_write_ptr) |
| 1770 | { |
| 1771 | struct phys_addr *pasync_sge = NULL; |
| 1772 | |
| 1773 | if (is_header) |
| 1774 | pasync_sge = pasync_ctx->async_header.ring_base; |
| 1775 | else |
| 1776 | pasync_sge = pasync_ctx->async_data.ring_base; |
| 1777 | |
| 1778 | return pasync_sge + host_write_ptr; |
| 1779 | } |
| 1780 | |
| 1781 | static void hwi_post_async_buffers(struct beiscsi_hba *phba, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1782 | unsigned int is_header, uint8_t ulp_num) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1783 | { |
| 1784 | struct hwi_controller *phwi_ctrlr; |
| 1785 | struct hwi_async_pdu_context *pasync_ctx; |
| 1786 | struct async_pdu_handle *pasync_handle; |
| 1787 | struct list_head *pfree_link, *pbusy_list; |
| 1788 | struct phys_addr *pasync_sge; |
| 1789 | unsigned int ring_id, num_entries; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1790 | unsigned int host_write_num, doorbell_offset; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1791 | unsigned int writables; |
| 1792 | unsigned int i = 0; |
| 1793 | u32 doorbell = 0; |
| 1794 | |
| 1795 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1796 | pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr, ulp_num); |
Jayamohan Kallickal | dc63aac | 2012-04-03 23:41:36 -0500 | [diff] [blame] | 1797 | num_entries = pasync_ctx->num_entries; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1798 | |
| 1799 | if (is_header) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1800 | writables = min(pasync_ctx->async_header.writables, |
| 1801 | pasync_ctx->async_header.free_entries); |
| 1802 | pfree_link = pasync_ctx->async_header.free_list.next; |
| 1803 | host_write_num = pasync_ctx->async_header.host_write_ptr; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1804 | ring_id = phwi_ctrlr->default_pdu_hdr[ulp_num].id; |
| 1805 | doorbell_offset = phwi_ctrlr->default_pdu_hdr[ulp_num]. |
| 1806 | doorbell_offset; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1807 | } else { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1808 | writables = min(pasync_ctx->async_data.writables, |
| 1809 | pasync_ctx->async_data.free_entries); |
| 1810 | pfree_link = pasync_ctx->async_data.free_list.next; |
| 1811 | host_write_num = pasync_ctx->async_data.host_write_ptr; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1812 | ring_id = phwi_ctrlr->default_pdu_data[ulp_num].id; |
| 1813 | doorbell_offset = phwi_ctrlr->default_pdu_data[ulp_num]. |
| 1814 | doorbell_offset; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | writables = (writables / 8) * 8; |
| 1818 | if (writables) { |
| 1819 | for (i = 0; i < writables; i++) { |
| 1820 | pbusy_list = |
| 1821 | hwi_get_async_busy_list(pasync_ctx, is_header, |
| 1822 | host_write_num); |
| 1823 | pasync_handle = |
| 1824 | list_entry(pfree_link, struct async_pdu_handle, |
| 1825 | link); |
| 1826 | WARN_ON(!pasync_handle); |
| 1827 | pasync_handle->consumed = 0; |
| 1828 | |
| 1829 | pfree_link = pfree_link->next; |
| 1830 | |
| 1831 | pasync_sge = hwi_get_ring_address(pasync_ctx, |
| 1832 | is_header, host_write_num); |
| 1833 | |
| 1834 | pasync_sge->hi = pasync_handle->pa.u.a32.address_lo; |
| 1835 | pasync_sge->lo = pasync_handle->pa.u.a32.address_hi; |
| 1836 | |
| 1837 | list_move(&pasync_handle->link, pbusy_list); |
| 1838 | |
| 1839 | host_write_num++; |
| 1840 | host_write_num = host_write_num % num_entries; |
| 1841 | } |
| 1842 | |
| 1843 | if (is_header) { |
| 1844 | pasync_ctx->async_header.host_write_ptr = |
| 1845 | host_write_num; |
| 1846 | pasync_ctx->async_header.free_entries -= writables; |
| 1847 | pasync_ctx->async_header.writables -= writables; |
| 1848 | pasync_ctx->async_header.busy_entries += writables; |
| 1849 | } else { |
| 1850 | pasync_ctx->async_data.host_write_ptr = host_write_num; |
| 1851 | pasync_ctx->async_data.free_entries -= writables; |
| 1852 | pasync_ctx->async_data.writables -= writables; |
| 1853 | pasync_ctx->async_data.busy_entries += writables; |
| 1854 | } |
| 1855 | |
| 1856 | doorbell |= ring_id & DB_DEF_PDU_RING_ID_MASK; |
| 1857 | doorbell |= 1 << DB_DEF_PDU_REARM_SHIFT; |
| 1858 | doorbell |= 0 << DB_DEF_PDU_EVENT_SHIFT; |
| 1859 | doorbell |= (writables & DB_DEF_PDU_CQPROC_MASK) |
| 1860 | << DB_DEF_PDU_CQPROC_SHIFT; |
| 1861 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1862 | iowrite32(doorbell, phba->db_va + doorbell_offset); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1863 | } |
| 1864 | } |
| 1865 | |
| 1866 | static void hwi_flush_default_pdu_buffer(struct beiscsi_hba *phba, |
| 1867 | struct beiscsi_conn *beiscsi_conn, |
| 1868 | struct i_t_dpdu_cqe *pdpdu_cqe) |
| 1869 | { |
| 1870 | struct hwi_controller *phwi_ctrlr; |
| 1871 | struct hwi_async_pdu_context *pasync_ctx; |
| 1872 | struct async_pdu_handle *pasync_handle = NULL; |
| 1873 | unsigned int cq_index = -1; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1874 | uint16_t cri_index = BE_GET_CRI_FROM_CID( |
| 1875 | beiscsi_conn->beiscsi_conn_cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1876 | |
| 1877 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1878 | pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr, |
| 1879 | BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr, |
| 1880 | cri_index)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1881 | |
| 1882 | pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx, |
| 1883 | pdpdu_cqe, &cq_index); |
| 1884 | BUG_ON(pasync_handle->is_header != 0); |
| 1885 | if (pasync_handle->consumed == 0) |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1886 | hwi_update_async_writables(phba, pasync_ctx, |
| 1887 | pasync_handle->is_header, cq_index); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1888 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1889 | hwi_free_async_msg(phba, pasync_ctx, pasync_handle->cri); |
| 1890 | hwi_post_async_buffers(phba, pasync_handle->is_header, |
| 1891 | BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr, |
| 1892 | cri_index)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | static unsigned int |
| 1896 | hwi_fwd_async_msg(struct beiscsi_conn *beiscsi_conn, |
| 1897 | struct beiscsi_hba *phba, |
| 1898 | struct hwi_async_pdu_context *pasync_ctx, unsigned short cri) |
| 1899 | { |
| 1900 | struct list_head *plist; |
| 1901 | struct async_pdu_handle *pasync_handle; |
| 1902 | void *phdr = NULL; |
| 1903 | unsigned int hdr_len = 0, buf_len = 0; |
| 1904 | unsigned int status, index = 0, offset = 0; |
| 1905 | void *pfirst_buffer = NULL; |
| 1906 | unsigned int num_buf = 0; |
| 1907 | |
| 1908 | plist = &pasync_ctx->async_entry[cri].wait_queue.list; |
| 1909 | |
| 1910 | list_for_each_entry(pasync_handle, plist, link) { |
| 1911 | if (index == 0) { |
| 1912 | phdr = pasync_handle->pbuffer; |
| 1913 | hdr_len = pasync_handle->buffer_len; |
| 1914 | } else { |
| 1915 | buf_len = pasync_handle->buffer_len; |
| 1916 | if (!num_buf) { |
| 1917 | pfirst_buffer = pasync_handle->pbuffer; |
| 1918 | num_buf++; |
| 1919 | } |
| 1920 | memcpy(pfirst_buffer + offset, |
| 1921 | pasync_handle->pbuffer, buf_len); |
Jayamohan Kallickal | f2ba02b | 2012-04-03 23:41:37 -0500 | [diff] [blame] | 1922 | offset += buf_len; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1923 | } |
| 1924 | index++; |
| 1925 | } |
| 1926 | |
| 1927 | status = beiscsi_process_async_pdu(beiscsi_conn, phba, |
Jayamohan Kallickal | 7da5087 | 2010-01-05 05:04:12 +0530 | [diff] [blame] | 1928 | phdr, hdr_len, pfirst_buffer, |
Jayamohan Kallickal | f2ba02b | 2012-04-03 23:41:37 -0500 | [diff] [blame] | 1929 | offset); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1930 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1931 | hwi_free_async_msg(phba, pasync_ctx, cri); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1932 | return 0; |
| 1933 | } |
| 1934 | |
| 1935 | static unsigned int |
| 1936 | hwi_gather_async_pdu(struct beiscsi_conn *beiscsi_conn, |
| 1937 | struct beiscsi_hba *phba, |
| 1938 | struct async_pdu_handle *pasync_handle) |
| 1939 | { |
| 1940 | struct hwi_async_pdu_context *pasync_ctx; |
| 1941 | struct hwi_controller *phwi_ctrlr; |
| 1942 | unsigned int bytes_needed = 0, status = 0; |
| 1943 | unsigned short cri = pasync_handle->cri; |
| 1944 | struct pdu_base *ppdu; |
| 1945 | |
| 1946 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1947 | pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr, |
| 1948 | BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr, |
| 1949 | BE_GET_CRI_FROM_CID(beiscsi_conn-> |
| 1950 | beiscsi_conn_cid))); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1951 | |
| 1952 | list_del(&pasync_handle->link); |
| 1953 | if (pasync_handle->is_header) { |
| 1954 | pasync_ctx->async_header.busy_entries--; |
| 1955 | if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) { |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 1956 | hwi_free_async_msg(phba, pasync_ctx, cri); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1957 | BUG(); |
| 1958 | } |
| 1959 | |
| 1960 | pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0; |
| 1961 | pasync_ctx->async_entry[cri].wait_queue.hdr_received = 1; |
| 1962 | pasync_ctx->async_entry[cri].wait_queue.hdr_len = |
| 1963 | (unsigned short)pasync_handle->buffer_len; |
| 1964 | list_add_tail(&pasync_handle->link, |
| 1965 | &pasync_ctx->async_entry[cri].wait_queue.list); |
| 1966 | |
| 1967 | ppdu = pasync_handle->pbuffer; |
| 1968 | bytes_needed = ((((ppdu->dw[offsetof(struct amap_pdu_base, |
| 1969 | data_len_hi) / 32] & PDUBASE_DATALENHI_MASK) << 8) & |
| 1970 | 0xFFFF0000) | ((be16_to_cpu((ppdu-> |
| 1971 | dw[offsetof(struct amap_pdu_base, data_len_lo) / 32] |
| 1972 | & PDUBASE_DATALENLO_MASK) >> 16)) & 0x0000FFFF)); |
| 1973 | |
| 1974 | if (status == 0) { |
| 1975 | pasync_ctx->async_entry[cri].wait_queue.bytes_needed = |
| 1976 | bytes_needed; |
| 1977 | |
| 1978 | if (bytes_needed == 0) |
| 1979 | status = hwi_fwd_async_msg(beiscsi_conn, phba, |
| 1980 | pasync_ctx, cri); |
| 1981 | } |
| 1982 | } else { |
| 1983 | pasync_ctx->async_data.busy_entries--; |
| 1984 | if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) { |
| 1985 | list_add_tail(&pasync_handle->link, |
| 1986 | &pasync_ctx->async_entry[cri].wait_queue. |
| 1987 | list); |
| 1988 | pasync_ctx->async_entry[cri].wait_queue. |
| 1989 | bytes_received += |
| 1990 | (unsigned short)pasync_handle->buffer_len; |
| 1991 | |
| 1992 | if (pasync_ctx->async_entry[cri].wait_queue. |
| 1993 | bytes_received >= |
| 1994 | pasync_ctx->async_entry[cri].wait_queue. |
| 1995 | bytes_needed) |
| 1996 | status = hwi_fwd_async_msg(beiscsi_conn, phba, |
| 1997 | pasync_ctx, cri); |
| 1998 | } |
| 1999 | } |
| 2000 | return status; |
| 2001 | } |
| 2002 | |
| 2003 | static void hwi_process_default_pdu_ring(struct beiscsi_conn *beiscsi_conn, |
| 2004 | struct beiscsi_hba *phba, |
| 2005 | struct i_t_dpdu_cqe *pdpdu_cqe) |
| 2006 | { |
| 2007 | struct hwi_controller *phwi_ctrlr; |
| 2008 | struct hwi_async_pdu_context *pasync_ctx; |
| 2009 | struct async_pdu_handle *pasync_handle = NULL; |
| 2010 | unsigned int cq_index = -1; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2011 | uint16_t cri_index = BE_GET_CRI_FROM_CID( |
| 2012 | beiscsi_conn->beiscsi_conn_cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2013 | |
| 2014 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2015 | pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr, |
| 2016 | BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr, |
| 2017 | cri_index)); |
| 2018 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2019 | pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx, |
| 2020 | pdpdu_cqe, &cq_index); |
| 2021 | |
| 2022 | if (pasync_handle->consumed == 0) |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2023 | hwi_update_async_writables(phba, pasync_ctx, |
| 2024 | pasync_handle->is_header, cq_index); |
| 2025 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2026 | hwi_gather_async_pdu(beiscsi_conn, phba, pasync_handle); |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2027 | hwi_post_async_buffers(phba, pasync_handle->is_header, |
| 2028 | BEISCSI_GET_ULP_FROM_CRI( |
| 2029 | phwi_ctrlr, cri_index)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2030 | } |
| 2031 | |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 2032 | static void beiscsi_process_mcc_isr(struct beiscsi_hba *phba) |
| 2033 | { |
| 2034 | struct be_queue_info *mcc_cq; |
| 2035 | struct be_mcc_compl *mcc_compl; |
| 2036 | unsigned int num_processed = 0; |
| 2037 | |
| 2038 | mcc_cq = &phba->ctrl.mcc_obj.cq; |
| 2039 | mcc_compl = queue_tail_node(mcc_cq); |
| 2040 | mcc_compl->flags = le32_to_cpu(mcc_compl->flags); |
| 2041 | while (mcc_compl->flags & CQE_FLAGS_VALID_MASK) { |
| 2042 | |
| 2043 | if (num_processed >= 32) { |
| 2044 | hwi_ring_cq_db(phba, mcc_cq->id, |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2045 | num_processed, 0); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 2046 | num_processed = 0; |
| 2047 | } |
| 2048 | if (mcc_compl->flags & CQE_FLAGS_ASYNC_MASK) { |
Jitendra Bhivare | 53aefe2 | 2016-01-20 14:10:53 +0530 | [diff] [blame] | 2049 | beiscsi_process_async_event(phba, mcc_compl); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 2050 | } else if (mcc_compl->flags & CQE_FLAGS_COMPLETED_MASK) { |
| 2051 | be_mcc_compl_process_isr(&phba->ctrl, mcc_compl); |
| 2052 | atomic_dec(&phba->ctrl.mcc_obj.q.used); |
| 2053 | } |
| 2054 | |
| 2055 | mcc_compl->flags = 0; |
| 2056 | queue_tail_inc(mcc_cq); |
| 2057 | mcc_compl = queue_tail_node(mcc_cq); |
| 2058 | mcc_compl->flags = le32_to_cpu(mcc_compl->flags); |
| 2059 | num_processed++; |
| 2060 | } |
| 2061 | |
| 2062 | if (num_processed > 0) |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2063 | hwi_ring_cq_db(phba, mcc_cq->id, num_processed, 1); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 2064 | |
| 2065 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2066 | |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 2067 | /** |
| 2068 | * beiscsi_process_cq()- Process the Completion Queue |
| 2069 | * @pbe_eq: Event Q on which the Completion has come |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2070 | * @budget: Max number of events to processed |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 2071 | * |
| 2072 | * return |
| 2073 | * Number of Completion Entries processed. |
| 2074 | **/ |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2075 | 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] | 2076 | { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2077 | struct be_queue_info *cq; |
| 2078 | struct sol_cqe *sol; |
| 2079 | struct dmsg_cqe *dmsg; |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2080 | unsigned int total = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2081 | unsigned int num_processed = 0; |
John Soni Jose | 0a513dd | 2012-08-20 23:00:55 +0530 | [diff] [blame] | 2082 | unsigned short code = 0, cid = 0; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2083 | uint16_t cri_index = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2084 | struct beiscsi_conn *beiscsi_conn; |
Jayamohan Kallickal | c246228 | 2010-01-05 05:05:34 +0530 | [diff] [blame] | 2085 | struct beiscsi_endpoint *beiscsi_ep; |
| 2086 | struct iscsi_endpoint *ep; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2087 | struct beiscsi_hba *phba; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2088 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2089 | cq = pbe_eq->cq; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2090 | sol = queue_tail_node(cq); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2091 | phba = pbe_eq->phba; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2092 | |
| 2093 | while (sol->dw[offsetof(struct amap_sol_cqe, valid) / 32] & |
| 2094 | CQE_VALID_MASK) { |
| 2095 | be_dws_le_to_cpu(sol, sizeof(struct sol_cqe)); |
| 2096 | |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 2097 | code = (sol->dw[offsetof(struct amap_sol_cqe, code) / |
| 2098 | 32] & CQE_CODE_MASK); |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 2099 | |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 2100 | /* Get the CID */ |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 2101 | if (is_chip_be2_be3r(phba)) { |
| 2102 | cid = AMAP_GET_BITS(struct amap_sol_cqe, cid, sol); |
| 2103 | } else { |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 2104 | if ((code == DRIVERMSG_NOTIFY) || |
| 2105 | (code == UNSOL_HDR_NOTIFY) || |
| 2106 | (code == UNSOL_DATA_NOTIFY)) |
| 2107 | cid = AMAP_GET_BITS( |
| 2108 | struct amap_i_t_dpdu_cqe_v2, |
| 2109 | cid, sol); |
| 2110 | else |
| 2111 | cid = AMAP_GET_BITS(struct amap_sol_cqe_v2, |
| 2112 | cid, sol); |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 2113 | } |
John Soni Jose | 7313326 | 2012-10-20 04:44:49 +0530 | [diff] [blame] | 2114 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2115 | cri_index = BE_GET_CRI_FROM_CID(cid); |
| 2116 | ep = phba->ep_array[cri_index]; |
Jayamohan Kallickal | b7ab35b | 2014-08-08 01:00:01 -0400 | [diff] [blame] | 2117 | |
| 2118 | if (ep == NULL) { |
| 2119 | /* connection has already been freed |
| 2120 | * just move on to next one |
| 2121 | */ |
| 2122 | beiscsi_log(phba, KERN_WARNING, |
| 2123 | BEISCSI_LOG_INIT, |
| 2124 | "BM_%d : proc cqe of disconn ep: cid %d\n", |
| 2125 | cid); |
| 2126 | goto proc_next_cqe; |
| 2127 | } |
| 2128 | |
Jayamohan Kallickal | c246228 | 2010-01-05 05:05:34 +0530 | [diff] [blame] | 2129 | beiscsi_ep = ep->dd_data; |
| 2130 | beiscsi_conn = beiscsi_ep->conn; |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 2131 | |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2132 | /* replenish cq */ |
| 2133 | if (num_processed == 32) { |
| 2134 | hwi_ring_cq_db(phba, cq->id, 32, 0); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2135 | num_processed = 0; |
| 2136 | } |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2137 | total++; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2138 | |
John Soni Jose | 0a513dd | 2012-08-20 23:00:55 +0530 | [diff] [blame] | 2139 | switch (code) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2140 | case SOL_CMD_COMPLETE: |
| 2141 | hwi_complete_cmd(beiscsi_conn, phba, sol); |
| 2142 | break; |
| 2143 | case DRIVERMSG_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 | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2149 | dmsg = (struct dmsg_cqe *)sol; |
| 2150 | hwi_complete_drvr_msgs(beiscsi_conn, phba, sol); |
| 2151 | break; |
| 2152 | case UNSOL_HDR_NOTIFY: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2153 | beiscsi_log(phba, KERN_INFO, |
| 2154 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 2155 | "BM_%d : Received %s[%d] on CID : %d\n", |
| 2156 | cqe_desc[code], code, cid); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2157 | |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 2158 | spin_lock_bh(&phba->async_pdu_lock); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2159 | hwi_process_default_pdu_ring(beiscsi_conn, phba, |
| 2160 | (struct i_t_dpdu_cqe *)sol); |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 2161 | spin_unlock_bh(&phba->async_pdu_lock); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2162 | break; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2163 | case UNSOL_DATA_NOTIFY: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2164 | beiscsi_log(phba, KERN_INFO, |
| 2165 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 2166 | "BM_%d : Received %s[%d] on CID : %d\n", |
| 2167 | cqe_desc[code], code, cid); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2168 | |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 2169 | spin_lock_bh(&phba->async_pdu_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2170 | hwi_process_default_pdu_ring(beiscsi_conn, phba, |
| 2171 | (struct i_t_dpdu_cqe *)sol); |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 2172 | spin_unlock_bh(&phba->async_pdu_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2173 | break; |
| 2174 | case CXN_INVALIDATE_INDEX_NOTIFY: |
| 2175 | case CMD_INVALIDATED_NOTIFY: |
| 2176 | case CXN_INVALIDATE_NOTIFY: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2177 | beiscsi_log(phba, KERN_ERR, |
| 2178 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 2179 | "BM_%d : Ignoring %s[%d] on CID : %d\n", |
| 2180 | cqe_desc[code], code, cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2181 | break; |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2182 | case CXN_KILLED_HDR_DIGEST_ERR: |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2183 | case SOL_CMD_KILLED_DATA_DIGEST_ERR: |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2184 | beiscsi_log(phba, KERN_ERR, |
| 2185 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
| 2186 | "BM_%d : Cmd Notification %s[%d] on CID : %d\n", |
| 2187 | cqe_desc[code], code, cid); |
| 2188 | break; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2189 | case CMD_KILLED_INVALID_STATSN_RCVD: |
| 2190 | case CMD_KILLED_INVALID_R2T_RCVD: |
| 2191 | case CMD_CXN_KILLED_LUN_INVALID: |
| 2192 | case CMD_CXN_KILLED_ICD_INVALID: |
| 2193 | case CMD_CXN_KILLED_ITT_INVALID: |
| 2194 | case CMD_CXN_KILLED_SEQ_OUTOFORDER: |
| 2195 | case CMD_CXN_KILLED_INVALID_DATASN_RCVD: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2196 | beiscsi_log(phba, KERN_ERR, |
| 2197 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 2198 | "BM_%d : Cmd Notification %s[%d] on CID : %d\n", |
| 2199 | cqe_desc[code], code, cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2200 | break; |
| 2201 | case UNSOL_DATA_DIGEST_ERROR_NOTIFY: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2202 | beiscsi_log(phba, KERN_ERR, |
| 2203 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 2204 | "BM_%d : Dropping %s[%d] on DPDU ring on CID : %d\n", |
| 2205 | cqe_desc[code], code, cid); |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 2206 | spin_lock_bh(&phba->async_pdu_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2207 | hwi_flush_default_pdu_buffer(phba, beiscsi_conn, |
| 2208 | (struct i_t_dpdu_cqe *) sol); |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 2209 | spin_unlock_bh(&phba->async_pdu_lock); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2210 | break; |
| 2211 | case CXN_KILLED_PDU_SIZE_EXCEEDS_DSL: |
| 2212 | case CXN_KILLED_BURST_LEN_MISMATCH: |
| 2213 | case CXN_KILLED_AHS_RCVD: |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2214 | case CXN_KILLED_UNKNOWN_HDR: |
| 2215 | case CXN_KILLED_STALE_ITT_TTT_RCVD: |
| 2216 | case CXN_KILLED_INVALID_ITT_TTT_RCVD: |
| 2217 | case CXN_KILLED_TIMED_OUT: |
| 2218 | case CXN_KILLED_FIN_RCVD: |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 2219 | case CXN_KILLED_RST_SENT: |
| 2220 | case CXN_KILLED_RST_RCVD: |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2221 | case CXN_KILLED_BAD_UNSOL_PDU_RCVD: |
| 2222 | case CXN_KILLED_BAD_WRB_INDEX_ERROR: |
| 2223 | case CXN_KILLED_OVER_RUN_RESIDUAL: |
| 2224 | case CXN_KILLED_UNDER_RUN_RESIDUAL: |
| 2225 | case CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN: |
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 : Event %s[%d] received on CID : %d\n", |
| 2229 | cqe_desc[code], code, cid); |
John Soni Jose | 0a513dd | 2012-08-20 23:00:55 +0530 | [diff] [blame] | 2230 | if (beiscsi_conn) |
| 2231 | iscsi_conn_failure(beiscsi_conn->conn, |
| 2232 | ISCSI_ERR_CONN_FAILED); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2233 | break; |
| 2234 | default: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2235 | beiscsi_log(phba, KERN_ERR, |
| 2236 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
John Soni Jose | 6763daa | 2012-10-20 04:41:45 +0530 | [diff] [blame] | 2237 | "BM_%d : Invalid CQE Event Received Code : %d" |
| 2238 | "CID 0x%x...\n", |
John Soni Jose | 0a513dd | 2012-08-20 23:00:55 +0530 | [diff] [blame] | 2239 | code, cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2240 | break; |
| 2241 | } |
| 2242 | |
Jayamohan Kallickal | b7ab35b | 2014-08-08 01:00:01 -0400 | [diff] [blame] | 2243 | proc_next_cqe: |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2244 | AMAP_SET_BITS(struct amap_sol_cqe, valid, sol, 0); |
| 2245 | queue_tail_inc(cq); |
| 2246 | sol = queue_tail_node(cq); |
| 2247 | num_processed++; |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2248 | if (total == budget) |
| 2249 | break; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2250 | } |
| 2251 | |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2252 | hwi_ring_cq_db(phba, cq->id, num_processed, 1); |
| 2253 | return total; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2254 | } |
| 2255 | |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 2256 | void beiscsi_process_all_cqs(struct work_struct *work) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2257 | { |
| 2258 | unsigned long flags; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2259 | struct hwi_controller *phwi_ctrlr; |
| 2260 | struct hwi_context_memory *phwi_context; |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 2261 | struct beiscsi_hba *phba; |
| 2262 | struct be_eq_obj *pbe_eq = |
| 2263 | container_of(work, struct be_eq_obj, work_cqs); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2264 | |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 2265 | phba = pbe_eq->phba; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2266 | phwi_ctrlr = phba->phwi_ctrlr; |
| 2267 | phwi_context = phwi_ctrlr->phwi_ctxt; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2268 | |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 2269 | if (pbe_eq->todo_mcc_cq) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2270 | spin_lock_irqsave(&phba->isr_lock, flags); |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 2271 | pbe_eq->todo_mcc_cq = false; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2272 | spin_unlock_irqrestore(&phba->isr_lock, flags); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 2273 | beiscsi_process_mcc_isr(phba); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2274 | } |
| 2275 | |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 2276 | if (pbe_eq->todo_cq) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2277 | spin_lock_irqsave(&phba->isr_lock, flags); |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 2278 | pbe_eq->todo_cq = false; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2279 | spin_unlock_irqrestore(&phba->isr_lock, flags); |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2280 | beiscsi_process_cq(pbe_eq, BE2_MAX_NUM_CQ_PROC); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2281 | } |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 2282 | |
| 2283 | /* rearm EQ for further interrupts */ |
| 2284 | 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] | 2285 | } |
| 2286 | |
Christoph Hellwig | 511cbce | 2015-11-10 14:56:14 +0100 | [diff] [blame] | 2287 | static int be_iopoll(struct irq_poll *iop, int budget) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2288 | { |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2289 | unsigned int ret, num_eq_processed; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2290 | struct beiscsi_hba *phba; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2291 | struct be_eq_obj *pbe_eq; |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2292 | struct be_eq_entry *eqe = NULL; |
| 2293 | struct be_queue_info *eq; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2294 | |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2295 | num_eq_processed = 0; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2296 | pbe_eq = container_of(iop, struct be_eq_obj, iopoll); |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2297 | phba = pbe_eq->phba; |
| 2298 | eq = &pbe_eq->q; |
| 2299 | eqe = queue_tail_node(eq); |
| 2300 | |
| 2301 | while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32] & |
| 2302 | EQE_VALID_MASK) { |
| 2303 | AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0); |
| 2304 | queue_tail_inc(eq); |
| 2305 | eqe = queue_tail_node(eq); |
| 2306 | num_eq_processed++; |
| 2307 | } |
| 2308 | |
| 2309 | hwi_ring_eq_db(phba, eq->id, 1, num_eq_processed, 0, 1); |
| 2310 | |
| 2311 | ret = beiscsi_process_cq(pbe_eq, budget); |
Jayamohan Kallickal | 73af08e | 2014-05-05 21:41:26 -0400 | [diff] [blame] | 2312 | pbe_eq->cq_count += ret; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2313 | if (ret < budget) { |
Christoph Hellwig | 511cbce | 2015-11-10 14:56:14 +0100 | [diff] [blame] | 2314 | irq_poll_complete(iop); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2315 | beiscsi_log(phba, KERN_INFO, |
| 2316 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO, |
Jitendra Bhivare | 1094cf6 | 2016-01-20 14:10:56 +0530 | [diff] [blame] | 2317 | "BM_%d : rearm pbe_eq->q.id =%d ret %d\n", |
| 2318 | pbe_eq->q.id, ret); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2319 | 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] | 2320 | } |
| 2321 | return ret; |
| 2322 | } |
| 2323 | |
| 2324 | static void |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2325 | hwi_write_sgl_v2(struct iscsi_wrb *pwrb, struct scatterlist *sg, |
| 2326 | unsigned int num_sg, struct beiscsi_io_task *io_task) |
| 2327 | { |
| 2328 | struct iscsi_sge *psgl; |
| 2329 | unsigned int sg_len, index; |
| 2330 | unsigned int sge_len = 0; |
| 2331 | unsigned long long addr; |
| 2332 | struct scatterlist *l_sg; |
| 2333 | unsigned int offset; |
| 2334 | |
| 2335 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_lo, pwrb, |
| 2336 | io_task->bhs_pa.u.a32.address_lo); |
| 2337 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_hi, pwrb, |
| 2338 | io_task->bhs_pa.u.a32.address_hi); |
| 2339 | |
| 2340 | l_sg = sg; |
| 2341 | for (index = 0; (index < num_sg) && (index < 2); index++, |
| 2342 | sg = sg_next(sg)) { |
| 2343 | if (index == 0) { |
| 2344 | sg_len = sg_dma_len(sg); |
| 2345 | addr = (u64) sg_dma_address(sg); |
| 2346 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
| 2347 | sge0_addr_lo, pwrb, |
| 2348 | lower_32_bits(addr)); |
| 2349 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
| 2350 | sge0_addr_hi, pwrb, |
| 2351 | upper_32_bits(addr)); |
| 2352 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
| 2353 | sge0_len, pwrb, |
| 2354 | sg_len); |
| 2355 | sge_len = sg_len; |
| 2356 | } else { |
| 2357 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_r2t_offset, |
| 2358 | pwrb, sge_len); |
| 2359 | sg_len = sg_dma_len(sg); |
| 2360 | addr = (u64) sg_dma_address(sg); |
| 2361 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
| 2362 | sge1_addr_lo, pwrb, |
| 2363 | lower_32_bits(addr)); |
| 2364 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
| 2365 | sge1_addr_hi, pwrb, |
| 2366 | upper_32_bits(addr)); |
| 2367 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
| 2368 | sge1_len, pwrb, |
| 2369 | sg_len); |
| 2370 | } |
| 2371 | } |
| 2372 | psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag; |
| 2373 | memset(psgl, 0, sizeof(*psgl) * BE2_SGE); |
| 2374 | |
| 2375 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2); |
| 2376 | |
| 2377 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, |
| 2378 | io_task->bhs_pa.u.a32.address_hi); |
| 2379 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, |
| 2380 | io_task->bhs_pa.u.a32.address_lo); |
| 2381 | |
| 2382 | if (num_sg == 1) { |
| 2383 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb, |
| 2384 | 1); |
| 2385 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb, |
| 2386 | 0); |
| 2387 | } else if (num_sg == 2) { |
| 2388 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb, |
| 2389 | 0); |
| 2390 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb, |
| 2391 | 1); |
| 2392 | } else { |
| 2393 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb, |
| 2394 | 0); |
| 2395 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb, |
| 2396 | 0); |
| 2397 | } |
| 2398 | |
| 2399 | sg = l_sg; |
| 2400 | psgl++; |
| 2401 | psgl++; |
| 2402 | offset = 0; |
| 2403 | for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) { |
| 2404 | sg_len = sg_dma_len(sg); |
| 2405 | addr = (u64) sg_dma_address(sg); |
| 2406 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, |
| 2407 | lower_32_bits(addr)); |
| 2408 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, |
| 2409 | upper_32_bits(addr)); |
| 2410 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len); |
| 2411 | AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset); |
| 2412 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0); |
| 2413 | offset += sg_len; |
| 2414 | } |
| 2415 | psgl--; |
| 2416 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1); |
| 2417 | } |
| 2418 | |
| 2419 | static void |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2420 | hwi_write_sgl(struct iscsi_wrb *pwrb, struct scatterlist *sg, |
| 2421 | unsigned int num_sg, struct beiscsi_io_task *io_task) |
| 2422 | { |
| 2423 | struct iscsi_sge *psgl; |
Jayamohan Kallickal | 58ff4bd | 2010-10-06 23:46:47 +0530 | [diff] [blame] | 2424 | unsigned int sg_len, index; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2425 | unsigned int sge_len = 0; |
| 2426 | unsigned long long addr; |
| 2427 | struct scatterlist *l_sg; |
| 2428 | unsigned int offset; |
| 2429 | |
| 2430 | AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb, |
| 2431 | io_task->bhs_pa.u.a32.address_lo); |
| 2432 | AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb, |
| 2433 | io_task->bhs_pa.u.a32.address_hi); |
| 2434 | |
| 2435 | l_sg = sg; |
Jayamohan Kallickal | 48bd86c | 2010-01-07 01:50:19 +0530 | [diff] [blame] | 2436 | for (index = 0; (index < num_sg) && (index < 2); index++, |
| 2437 | sg = sg_next(sg)) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2438 | if (index == 0) { |
| 2439 | sg_len = sg_dma_len(sg); |
| 2440 | addr = (u64) sg_dma_address(sg); |
| 2441 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb, |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 2442 | ((u32)(addr & 0xFFFFFFFF))); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2443 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb, |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 2444 | ((u32)(addr >> 32))); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2445 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb, |
| 2446 | sg_len); |
| 2447 | sge_len = sg_len; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2448 | } else { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2449 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_r2t_offset, |
| 2450 | pwrb, sge_len); |
| 2451 | sg_len = sg_dma_len(sg); |
| 2452 | addr = (u64) sg_dma_address(sg); |
| 2453 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_lo, pwrb, |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 2454 | ((u32)(addr & 0xFFFFFFFF))); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2455 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_hi, pwrb, |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 2456 | ((u32)(addr >> 32))); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2457 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_len, pwrb, |
| 2458 | sg_len); |
| 2459 | } |
| 2460 | } |
| 2461 | psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag; |
| 2462 | memset(psgl, 0, sizeof(*psgl) * BE2_SGE); |
| 2463 | |
| 2464 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2); |
| 2465 | |
| 2466 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, |
| 2467 | io_task->bhs_pa.u.a32.address_hi); |
| 2468 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, |
| 2469 | io_task->bhs_pa.u.a32.address_lo); |
| 2470 | |
Jayamohan Kallickal | caf818f | 2010-01-23 05:38:18 +0530 | [diff] [blame] | 2471 | if (num_sg == 1) { |
| 2472 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, |
| 2473 | 1); |
| 2474 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb, |
| 2475 | 0); |
| 2476 | } else if (num_sg == 2) { |
| 2477 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, |
| 2478 | 0); |
| 2479 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb, |
| 2480 | 1); |
| 2481 | } else { |
| 2482 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, |
| 2483 | 0); |
| 2484 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb, |
| 2485 | 0); |
| 2486 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2487 | sg = l_sg; |
| 2488 | psgl++; |
| 2489 | psgl++; |
| 2490 | offset = 0; |
Jayamohan Kallickal | 48bd86c | 2010-01-07 01:50:19 +0530 | [diff] [blame] | 2491 | for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2492 | sg_len = sg_dma_len(sg); |
| 2493 | addr = (u64) sg_dma_address(sg); |
| 2494 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, |
| 2495 | (addr & 0xFFFFFFFF)); |
| 2496 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, |
| 2497 | (addr >> 32)); |
| 2498 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len); |
| 2499 | AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset); |
| 2500 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0); |
| 2501 | offset += sg_len; |
| 2502 | } |
| 2503 | psgl--; |
| 2504 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1); |
| 2505 | } |
| 2506 | |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2507 | /** |
| 2508 | * hwi_write_buffer()- Populate the WRB with task info |
| 2509 | * @pwrb: ptr to the WRB entry |
| 2510 | * @task: iscsi task which is to be executed |
| 2511 | **/ |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2512 | static void hwi_write_buffer(struct iscsi_wrb *pwrb, struct iscsi_task *task) |
| 2513 | { |
| 2514 | struct iscsi_sge *psgl; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2515 | struct beiscsi_io_task *io_task = task->dd_data; |
| 2516 | struct beiscsi_conn *beiscsi_conn = io_task->conn; |
| 2517 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2518 | uint8_t dsp_value = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2519 | |
| 2520 | io_task->bhs_len = sizeof(struct be_nonio_bhs) - 2; |
| 2521 | AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb, |
| 2522 | io_task->bhs_pa.u.a32.address_lo); |
| 2523 | AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb, |
| 2524 | io_task->bhs_pa.u.a32.address_hi); |
| 2525 | |
| 2526 | if (task->data) { |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2527 | |
| 2528 | /* Check for the data_count */ |
| 2529 | dsp_value = (task->data_count) ? 1 : 0; |
| 2530 | |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 2531 | if (is_chip_be2_be3r(phba)) |
| 2532 | AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2533 | pwrb, dsp_value); |
| 2534 | else |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 2535 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2536 | pwrb, dsp_value); |
| 2537 | |
| 2538 | /* Map addr only if there is data_count */ |
| 2539 | if (dsp_value) { |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2540 | io_task->mtask_addr = pci_map_single(phba->pcidev, |
| 2541 | task->data, |
| 2542 | task->data_count, |
| 2543 | PCI_DMA_TODEVICE); |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2544 | io_task->mtask_data_count = task->data_count; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2545 | } else |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2546 | io_task->mtask_addr = 0; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 2547 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2548 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb, |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2549 | lower_32_bits(io_task->mtask_addr)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2550 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb, |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2551 | upper_32_bits(io_task->mtask_addr)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2552 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb, |
| 2553 | task->data_count); |
| 2554 | |
| 2555 | AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, 1); |
| 2556 | } else { |
| 2557 | AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0); |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2558 | io_task->mtask_addr = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2559 | } |
| 2560 | |
| 2561 | psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag; |
| 2562 | |
| 2563 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len); |
| 2564 | |
| 2565 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, |
| 2566 | io_task->bhs_pa.u.a32.address_hi); |
| 2567 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, |
| 2568 | io_task->bhs_pa.u.a32.address_lo); |
| 2569 | if (task->data) { |
| 2570 | psgl++; |
| 2571 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, 0); |
| 2572 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, 0); |
| 2573 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0); |
| 2574 | AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, 0); |
| 2575 | AMAP_SET_BITS(struct amap_iscsi_sge, rsvd0, psgl, 0); |
| 2576 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0); |
| 2577 | |
| 2578 | psgl++; |
| 2579 | if (task->data) { |
| 2580 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2581 | lower_32_bits(io_task->mtask_addr)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2582 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 2583 | upper_32_bits(io_task->mtask_addr)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2584 | } |
| 2585 | AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0x106); |
| 2586 | } |
| 2587 | AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1); |
| 2588 | } |
| 2589 | |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 2590 | /** |
| 2591 | * beiscsi_find_mem_req()- Find mem needed |
| 2592 | * @phba: ptr to HBA struct |
| 2593 | **/ |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2594 | static void beiscsi_find_mem_req(struct beiscsi_hba *phba) |
| 2595 | { |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2596 | uint8_t mem_descr_index, ulp_num; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2597 | unsigned int num_cq_pages, num_async_pdu_buf_pages; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2598 | unsigned int num_async_pdu_data_pages, wrb_sz_per_cxn; |
| 2599 | unsigned int num_async_pdu_buf_sgl_pages, num_async_pdu_data_sgl_pages; |
| 2600 | |
| 2601 | num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \ |
| 2602 | sizeof(struct sol_cqe)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2603 | |
| 2604 | phba->params.hwi_ws_sz = sizeof(struct hwi_controller); |
| 2605 | |
| 2606 | phba->mem_req[ISCSI_MEM_GLOBAL_HEADER] = 2 * |
| 2607 | BE_ISCSI_PDU_HEADER_SIZE; |
| 2608 | phba->mem_req[HWI_MEM_ADDN_CONTEXT] = |
| 2609 | sizeof(struct hwi_context_memory); |
| 2610 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2611 | |
| 2612 | phba->mem_req[HWI_MEM_WRB] = sizeof(struct iscsi_wrb) |
| 2613 | * (phba->params.wrbs_per_cxn) |
| 2614 | * phba->params.cxns_per_ctrl; |
| 2615 | wrb_sz_per_cxn = sizeof(struct wrb_handle) * |
| 2616 | (phba->params.wrbs_per_cxn); |
| 2617 | phba->mem_req[HWI_MEM_WRBH] = roundup_pow_of_two((wrb_sz_per_cxn) * |
| 2618 | phba->params.cxns_per_ctrl); |
| 2619 | |
| 2620 | phba->mem_req[HWI_MEM_SGLH] = sizeof(struct sgl_handle) * |
| 2621 | phba->params.icds_per_ctrl; |
| 2622 | phba->mem_req[HWI_MEM_SGE] = sizeof(struct iscsi_sge) * |
| 2623 | phba->params.num_sge_per_io * phba->params.icds_per_ctrl; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2624 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 2625 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2626 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2627 | num_async_pdu_buf_sgl_pages = |
| 2628 | PAGES_REQUIRED(BEISCSI_GET_CID_COUNT( |
| 2629 | phba, ulp_num) * |
| 2630 | sizeof(struct phys_addr)); |
| 2631 | |
| 2632 | num_async_pdu_buf_pages = |
| 2633 | PAGES_REQUIRED(BEISCSI_GET_CID_COUNT( |
| 2634 | phba, ulp_num) * |
| 2635 | phba->params.defpdu_hdr_sz); |
| 2636 | |
| 2637 | num_async_pdu_data_pages = |
| 2638 | PAGES_REQUIRED(BEISCSI_GET_CID_COUNT( |
| 2639 | phba, ulp_num) * |
| 2640 | phba->params.defpdu_data_sz); |
| 2641 | |
| 2642 | num_async_pdu_data_sgl_pages = |
| 2643 | PAGES_REQUIRED(BEISCSI_GET_CID_COUNT( |
| 2644 | phba, ulp_num) * |
| 2645 | sizeof(struct phys_addr)); |
| 2646 | |
Jayamohan Kallickal | a129d92 | 2013-09-28 15:35:46 -0700 | [diff] [blame] | 2647 | mem_descr_index = (HWI_MEM_TEMPLATE_HDR_ULP0 + |
| 2648 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2649 | phba->mem_req[mem_descr_index] = |
| 2650 | BEISCSI_GET_CID_COUNT(phba, ulp_num) * |
| 2651 | BEISCSI_TEMPLATE_HDR_PER_CXN_SIZE; |
| 2652 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2653 | mem_descr_index = (HWI_MEM_ASYNC_HEADER_BUF_ULP0 + |
| 2654 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2655 | phba->mem_req[mem_descr_index] = |
| 2656 | num_async_pdu_buf_pages * |
| 2657 | PAGE_SIZE; |
| 2658 | |
| 2659 | mem_descr_index = (HWI_MEM_ASYNC_DATA_BUF_ULP0 + |
| 2660 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2661 | phba->mem_req[mem_descr_index] = |
| 2662 | num_async_pdu_data_pages * |
| 2663 | PAGE_SIZE; |
| 2664 | |
| 2665 | mem_descr_index = (HWI_MEM_ASYNC_HEADER_RING_ULP0 + |
| 2666 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2667 | phba->mem_req[mem_descr_index] = |
| 2668 | num_async_pdu_buf_sgl_pages * |
| 2669 | PAGE_SIZE; |
| 2670 | |
| 2671 | mem_descr_index = (HWI_MEM_ASYNC_DATA_RING_ULP0 + |
| 2672 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2673 | phba->mem_req[mem_descr_index] = |
| 2674 | num_async_pdu_data_sgl_pages * |
| 2675 | PAGE_SIZE; |
| 2676 | |
| 2677 | mem_descr_index = (HWI_MEM_ASYNC_HEADER_HANDLE_ULP0 + |
| 2678 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2679 | phba->mem_req[mem_descr_index] = |
| 2680 | BEISCSI_GET_CID_COUNT(phba, ulp_num) * |
| 2681 | sizeof(struct async_pdu_handle); |
| 2682 | |
| 2683 | mem_descr_index = (HWI_MEM_ASYNC_DATA_HANDLE_ULP0 + |
| 2684 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2685 | phba->mem_req[mem_descr_index] = |
| 2686 | BEISCSI_GET_CID_COUNT(phba, ulp_num) * |
| 2687 | sizeof(struct async_pdu_handle); |
| 2688 | |
| 2689 | mem_descr_index = (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0 + |
| 2690 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2691 | phba->mem_req[mem_descr_index] = |
| 2692 | sizeof(struct hwi_async_pdu_context) + |
| 2693 | (BEISCSI_GET_CID_COUNT(phba, ulp_num) * |
| 2694 | sizeof(struct hwi_async_entry)); |
| 2695 | } |
| 2696 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2697 | } |
| 2698 | |
| 2699 | static int beiscsi_alloc_mem(struct beiscsi_hba *phba) |
| 2700 | { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2701 | dma_addr_t bus_add; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2702 | struct hwi_controller *phwi_ctrlr; |
| 2703 | struct be_mem_descriptor *mem_descr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2704 | struct mem_array *mem_arr, *mem_arr_orig; |
| 2705 | unsigned int i, j, alloc_size, curr_alloc_size; |
| 2706 | |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2707 | phba->phwi_ctrlr = kzalloc(phba->params.hwi_ws_sz, GFP_KERNEL); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2708 | if (!phba->phwi_ctrlr) |
| 2709 | return -ENOMEM; |
| 2710 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2711 | /* Allocate memory for wrb_context */ |
| 2712 | phwi_ctrlr = phba->phwi_ctrlr; |
| 2713 | phwi_ctrlr->wrb_context = kzalloc(sizeof(struct hwi_wrb_context) * |
| 2714 | phba->params.cxns_per_ctrl, |
| 2715 | GFP_KERNEL); |
| 2716 | if (!phwi_ctrlr->wrb_context) |
| 2717 | return -ENOMEM; |
| 2718 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2719 | phba->init_mem = kcalloc(SE_MEM_MAX, sizeof(*mem_descr), |
| 2720 | GFP_KERNEL); |
| 2721 | if (!phba->init_mem) { |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2722 | kfree(phwi_ctrlr->wrb_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2723 | kfree(phba->phwi_ctrlr); |
| 2724 | return -ENOMEM; |
| 2725 | } |
| 2726 | |
| 2727 | mem_arr_orig = kmalloc(sizeof(*mem_arr_orig) * BEISCSI_MAX_FRAGS_INIT, |
| 2728 | GFP_KERNEL); |
| 2729 | if (!mem_arr_orig) { |
| 2730 | kfree(phba->init_mem); |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2731 | kfree(phwi_ctrlr->wrb_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2732 | kfree(phba->phwi_ctrlr); |
| 2733 | return -ENOMEM; |
| 2734 | } |
| 2735 | |
| 2736 | mem_descr = phba->init_mem; |
| 2737 | for (i = 0; i < SE_MEM_MAX; i++) { |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2738 | if (!phba->mem_req[i]) { |
| 2739 | mem_descr->mem_array = NULL; |
| 2740 | mem_descr++; |
| 2741 | continue; |
| 2742 | } |
| 2743 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2744 | j = 0; |
| 2745 | mem_arr = mem_arr_orig; |
| 2746 | alloc_size = phba->mem_req[i]; |
| 2747 | memset(mem_arr, 0, sizeof(struct mem_array) * |
| 2748 | BEISCSI_MAX_FRAGS_INIT); |
| 2749 | curr_alloc_size = min(be_max_phys_size * 1024, alloc_size); |
| 2750 | do { |
| 2751 | mem_arr->virtual_address = pci_alloc_consistent( |
| 2752 | phba->pcidev, |
| 2753 | curr_alloc_size, |
| 2754 | &bus_add); |
| 2755 | if (!mem_arr->virtual_address) { |
| 2756 | if (curr_alloc_size <= BE_MIN_MEM_SIZE) |
| 2757 | goto free_mem; |
| 2758 | if (curr_alloc_size - |
| 2759 | rounddown_pow_of_two(curr_alloc_size)) |
| 2760 | curr_alloc_size = rounddown_pow_of_two |
| 2761 | (curr_alloc_size); |
| 2762 | else |
| 2763 | curr_alloc_size = curr_alloc_size / 2; |
| 2764 | } else { |
| 2765 | mem_arr->bus_address.u. |
| 2766 | a64.address = (__u64) bus_add; |
| 2767 | mem_arr->size = curr_alloc_size; |
| 2768 | alloc_size -= curr_alloc_size; |
| 2769 | curr_alloc_size = min(be_max_phys_size * |
| 2770 | 1024, alloc_size); |
| 2771 | j++; |
| 2772 | mem_arr++; |
| 2773 | } |
| 2774 | } while (alloc_size); |
| 2775 | mem_descr->num_elements = j; |
| 2776 | mem_descr->size_in_bytes = phba->mem_req[i]; |
| 2777 | mem_descr->mem_array = kmalloc(sizeof(*mem_arr) * j, |
| 2778 | GFP_KERNEL); |
| 2779 | if (!mem_descr->mem_array) |
| 2780 | goto free_mem; |
| 2781 | |
| 2782 | memcpy(mem_descr->mem_array, mem_arr_orig, |
| 2783 | sizeof(struct mem_array) * j); |
| 2784 | mem_descr++; |
| 2785 | } |
| 2786 | kfree(mem_arr_orig); |
| 2787 | return 0; |
| 2788 | free_mem: |
| 2789 | mem_descr->num_elements = j; |
| 2790 | while ((i) || (j)) { |
| 2791 | for (j = mem_descr->num_elements; j > 0; j--) { |
| 2792 | pci_free_consistent(phba->pcidev, |
| 2793 | mem_descr->mem_array[j - 1].size, |
| 2794 | mem_descr->mem_array[j - 1]. |
| 2795 | virtual_address, |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 2796 | (unsigned long)mem_descr-> |
| 2797 | mem_array[j - 1]. |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2798 | bus_address.u.a64.address); |
| 2799 | } |
| 2800 | if (i) { |
| 2801 | i--; |
| 2802 | kfree(mem_descr->mem_array); |
| 2803 | mem_descr--; |
| 2804 | } |
| 2805 | } |
| 2806 | kfree(mem_arr_orig); |
| 2807 | kfree(phba->init_mem); |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2808 | kfree(phba->phwi_ctrlr->wrb_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2809 | kfree(phba->phwi_ctrlr); |
| 2810 | return -ENOMEM; |
| 2811 | } |
| 2812 | |
| 2813 | static int beiscsi_get_memory(struct beiscsi_hba *phba) |
| 2814 | { |
| 2815 | beiscsi_find_mem_req(phba); |
| 2816 | return beiscsi_alloc_mem(phba); |
| 2817 | } |
| 2818 | |
| 2819 | static void iscsi_init_global_templates(struct beiscsi_hba *phba) |
| 2820 | { |
| 2821 | struct pdu_data_out *pdata_out; |
| 2822 | struct pdu_nop_out *pnop_out; |
| 2823 | struct be_mem_descriptor *mem_descr; |
| 2824 | |
| 2825 | mem_descr = phba->init_mem; |
| 2826 | mem_descr += ISCSI_MEM_GLOBAL_HEADER; |
| 2827 | pdata_out = |
| 2828 | (struct pdu_data_out *)mem_descr->mem_array[0].virtual_address; |
| 2829 | memset(pdata_out, 0, BE_ISCSI_PDU_HEADER_SIZE); |
| 2830 | |
| 2831 | AMAP_SET_BITS(struct amap_pdu_data_out, opcode, pdata_out, |
| 2832 | IIOC_SCSI_DATA); |
| 2833 | |
| 2834 | pnop_out = |
| 2835 | (struct pdu_nop_out *)((unsigned char *)mem_descr->mem_array[0]. |
| 2836 | virtual_address + BE_ISCSI_PDU_HEADER_SIZE); |
| 2837 | |
| 2838 | memset(pnop_out, 0, BE_ISCSI_PDU_HEADER_SIZE); |
| 2839 | AMAP_SET_BITS(struct amap_pdu_nop_out, ttt, pnop_out, 0xFFFFFFFF); |
| 2840 | AMAP_SET_BITS(struct amap_pdu_nop_out, f_bit, pnop_out, 1); |
| 2841 | AMAP_SET_BITS(struct amap_pdu_nop_out, i_bit, pnop_out, 0); |
| 2842 | } |
| 2843 | |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2844 | static int beiscsi_init_wrb_handle(struct beiscsi_hba *phba) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2845 | { |
| 2846 | struct be_mem_descriptor *mem_descr_wrbh, *mem_descr_wrb; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2847 | struct hwi_context_memory *phwi_ctxt; |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2848 | struct wrb_handle *pwrb_handle = NULL; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2849 | struct hwi_controller *phwi_ctrlr; |
| 2850 | struct hwi_wrb_context *pwrb_context; |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2851 | struct iscsi_wrb *pwrb = NULL; |
| 2852 | unsigned int num_cxn_wrbh = 0; |
| 2853 | unsigned int num_cxn_wrb = 0, j, idx = 0, index; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2854 | |
| 2855 | mem_descr_wrbh = phba->init_mem; |
| 2856 | mem_descr_wrbh += HWI_MEM_WRBH; |
| 2857 | |
| 2858 | mem_descr_wrb = phba->init_mem; |
| 2859 | mem_descr_wrb += HWI_MEM_WRB; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2860 | phwi_ctrlr = phba->phwi_ctrlr; |
| 2861 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2862 | /* Allocate memory for WRBQ */ |
| 2863 | phwi_ctxt = phwi_ctrlr->phwi_ctxt; |
| 2864 | phwi_ctxt->be_wrbq = kzalloc(sizeof(struct be_queue_info) * |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 2865 | phba->params.cxns_per_ctrl, |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2866 | GFP_KERNEL); |
| 2867 | if (!phwi_ctxt->be_wrbq) { |
| 2868 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 2869 | "BM_%d : WRBQ Mem Alloc Failed\n"); |
| 2870 | return -ENOMEM; |
| 2871 | } |
| 2872 | |
| 2873 | for (index = 0; index < phba->params.cxns_per_ctrl; index++) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2874 | pwrb_context = &phwi_ctrlr->wrb_context[index]; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2875 | pwrb_context->pwrb_handle_base = |
| 2876 | kzalloc(sizeof(struct wrb_handle *) * |
| 2877 | phba->params.wrbs_per_cxn, GFP_KERNEL); |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2878 | if (!pwrb_context->pwrb_handle_base) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2879 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 2880 | "BM_%d : Mem Alloc Failed. Failing to load\n"); |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2881 | goto init_wrb_hndl_failed; |
| 2882 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2883 | pwrb_context->pwrb_handle_basestd = |
| 2884 | kzalloc(sizeof(struct wrb_handle *) * |
| 2885 | phba->params.wrbs_per_cxn, GFP_KERNEL); |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2886 | if (!pwrb_context->pwrb_handle_basestd) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 2887 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 2888 | "BM_%d : Mem Alloc Failed. Failing to load\n"); |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2889 | goto init_wrb_hndl_failed; |
| 2890 | } |
| 2891 | if (!num_cxn_wrbh) { |
| 2892 | pwrb_handle = |
| 2893 | mem_descr_wrbh->mem_array[idx].virtual_address; |
| 2894 | num_cxn_wrbh = ((mem_descr_wrbh->mem_array[idx].size) / |
| 2895 | ((sizeof(struct wrb_handle)) * |
| 2896 | phba->params.wrbs_per_cxn)); |
| 2897 | idx++; |
| 2898 | } |
| 2899 | pwrb_context->alloc_index = 0; |
| 2900 | pwrb_context->wrb_handles_available = 0; |
| 2901 | pwrb_context->free_index = 0; |
| 2902 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2903 | if (num_cxn_wrbh) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2904 | for (j = 0; j < phba->params.wrbs_per_cxn; j++) { |
| 2905 | pwrb_context->pwrb_handle_base[j] = pwrb_handle; |
| 2906 | pwrb_context->pwrb_handle_basestd[j] = |
| 2907 | pwrb_handle; |
| 2908 | pwrb_context->wrb_handles_available++; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 2909 | pwrb_handle->wrb_index = j; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2910 | pwrb_handle++; |
| 2911 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2912 | num_cxn_wrbh--; |
| 2913 | } |
| 2914 | } |
| 2915 | idx = 0; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2916 | for (index = 0; index < phba->params.cxns_per_ctrl; index++) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2917 | pwrb_context = &phwi_ctrlr->wrb_context[index]; |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2918 | if (!num_cxn_wrb) { |
| 2919 | pwrb = mem_descr_wrb->mem_array[idx].virtual_address; |
| 2920 | num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) / |
| 2921 | ((sizeof(struct iscsi_wrb) * |
| 2922 | phba->params.wrbs_per_cxn)); |
| 2923 | idx++; |
| 2924 | } |
| 2925 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2926 | if (num_cxn_wrb) { |
| 2927 | for (j = 0; j < phba->params.wrbs_per_cxn; j++) { |
| 2928 | pwrb_handle = pwrb_context->pwrb_handle_base[j]; |
| 2929 | pwrb_handle->pwrb = pwrb; |
| 2930 | pwrb++; |
| 2931 | } |
| 2932 | num_cxn_wrb--; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2933 | } |
| 2934 | } |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 2935 | return 0; |
| 2936 | init_wrb_hndl_failed: |
| 2937 | for (j = index; j > 0; j--) { |
| 2938 | pwrb_context = &phwi_ctrlr->wrb_context[j]; |
| 2939 | kfree(pwrb_context->pwrb_handle_base); |
| 2940 | kfree(pwrb_context->pwrb_handle_basestd); |
| 2941 | } |
| 2942 | return -ENOMEM; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2943 | } |
| 2944 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 2945 | static int hwi_init_async_pdu_ctx(struct beiscsi_hba *phba) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2946 | { |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2947 | uint8_t ulp_num; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2948 | struct hwi_controller *phwi_ctrlr; |
| 2949 | struct hba_parameters *p = &phba->params; |
| 2950 | struct hwi_async_pdu_context *pasync_ctx; |
| 2951 | struct async_pdu_handle *pasync_header_h, *pasync_data_h; |
Jayamohan Kallickal | dc63aac | 2012-04-03 23:41:36 -0500 | [diff] [blame] | 2952 | unsigned int index, idx, num_per_mem, num_async_data; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2953 | struct be_mem_descriptor *mem_descr; |
| 2954 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2955 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 2956 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2957 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2958 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 2959 | mem_descr += (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0 + |
| 2960 | (ulp_num * MEM_DESCR_OFFSET)); |
| 2961 | |
| 2962 | phwi_ctrlr = phba->phwi_ctrlr; |
| 2963 | phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num] = |
| 2964 | (struct hwi_async_pdu_context *) |
| 2965 | mem_descr->mem_array[0].virtual_address; |
| 2966 | |
| 2967 | pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num]; |
| 2968 | memset(pasync_ctx, 0, sizeof(*pasync_ctx)); |
| 2969 | |
| 2970 | pasync_ctx->async_entry = |
| 2971 | (struct hwi_async_entry *) |
| 2972 | ((long unsigned int)pasync_ctx + |
| 2973 | sizeof(struct hwi_async_pdu_context)); |
| 2974 | |
| 2975 | pasync_ctx->num_entries = BEISCSI_GET_CID_COUNT(phba, |
| 2976 | ulp_num); |
| 2977 | pasync_ctx->buffer_size = p->defpdu_hdr_sz; |
| 2978 | |
| 2979 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 2980 | mem_descr += HWI_MEM_ASYNC_HEADER_BUF_ULP0 + |
| 2981 | (ulp_num * MEM_DESCR_OFFSET); |
| 2982 | if (mem_descr->mem_array[0].virtual_address) { |
| 2983 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 2984 | "BM_%d : hwi_init_async_pdu_ctx" |
| 2985 | " HWI_MEM_ASYNC_HEADER_BUF_ULP%d va=%p\n", |
| 2986 | ulp_num, |
| 2987 | mem_descr->mem_array[0]. |
| 2988 | virtual_address); |
| 2989 | } else |
| 2990 | beiscsi_log(phba, KERN_WARNING, |
| 2991 | BEISCSI_LOG_INIT, |
| 2992 | "BM_%d : No Virtual address for ULP : %d\n", |
| 2993 | ulp_num); |
| 2994 | |
| 2995 | pasync_ctx->async_header.va_base = |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2996 | mem_descr->mem_array[0].virtual_address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 2997 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 2998 | pasync_ctx->async_header.pa_base.u.a64.address = |
| 2999 | mem_descr->mem_array[0]. |
| 3000 | bus_address.u.a64.address; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 3001 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3002 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 3003 | mem_descr += HWI_MEM_ASYNC_HEADER_RING_ULP0 + |
| 3004 | (ulp_num * MEM_DESCR_OFFSET); |
| 3005 | if (mem_descr->mem_array[0].virtual_address) { |
| 3006 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3007 | "BM_%d : hwi_init_async_pdu_ctx" |
| 3008 | " HWI_MEM_ASYNC_HEADER_RING_ULP%d va=%p\n", |
| 3009 | ulp_num, |
| 3010 | mem_descr->mem_array[0]. |
| 3011 | virtual_address); |
| 3012 | } else |
| 3013 | beiscsi_log(phba, KERN_WARNING, |
| 3014 | BEISCSI_LOG_INIT, |
| 3015 | "BM_%d : No Virtual address for ULP : %d\n", |
| 3016 | ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3017 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3018 | pasync_ctx->async_header.ring_base = |
| 3019 | mem_descr->mem_array[0].virtual_address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3020 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3021 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 3022 | mem_descr += HWI_MEM_ASYNC_HEADER_HANDLE_ULP0 + |
| 3023 | (ulp_num * MEM_DESCR_OFFSET); |
| 3024 | if (mem_descr->mem_array[0].virtual_address) { |
| 3025 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3026 | "BM_%d : hwi_init_async_pdu_ctx" |
| 3027 | " HWI_MEM_ASYNC_HEADER_HANDLE_ULP%d va=%p\n", |
| 3028 | ulp_num, |
| 3029 | mem_descr->mem_array[0]. |
| 3030 | virtual_address); |
| 3031 | } else |
| 3032 | beiscsi_log(phba, KERN_WARNING, |
| 3033 | BEISCSI_LOG_INIT, |
| 3034 | "BM_%d : No Virtual address for ULP : %d\n", |
| 3035 | ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3036 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3037 | pasync_ctx->async_header.handle_base = |
| 3038 | mem_descr->mem_array[0].virtual_address; |
| 3039 | pasync_ctx->async_header.writables = 0; |
| 3040 | INIT_LIST_HEAD(&pasync_ctx->async_header.free_list); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3041 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3042 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 3043 | mem_descr += HWI_MEM_ASYNC_DATA_RING_ULP0 + |
| 3044 | (ulp_num * MEM_DESCR_OFFSET); |
| 3045 | if (mem_descr->mem_array[0].virtual_address) { |
| 3046 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3047 | "BM_%d : hwi_init_async_pdu_ctx" |
| 3048 | " HWI_MEM_ASYNC_DATA_RING_ULP%d va=%p\n", |
| 3049 | ulp_num, |
| 3050 | mem_descr->mem_array[0]. |
| 3051 | virtual_address); |
| 3052 | } else |
| 3053 | beiscsi_log(phba, KERN_WARNING, |
| 3054 | BEISCSI_LOG_INIT, |
| 3055 | "BM_%d : No Virtual address for ULP : %d\n", |
| 3056 | ulp_num); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3057 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3058 | pasync_ctx->async_data.ring_base = |
| 3059 | mem_descr->mem_array[0].virtual_address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3060 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3061 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 3062 | mem_descr += HWI_MEM_ASYNC_DATA_HANDLE_ULP0 + |
| 3063 | (ulp_num * MEM_DESCR_OFFSET); |
| 3064 | if (!mem_descr->mem_array[0].virtual_address) |
| 3065 | beiscsi_log(phba, KERN_WARNING, |
| 3066 | BEISCSI_LOG_INIT, |
| 3067 | "BM_%d : No Virtual address for ULP : %d\n", |
| 3068 | ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3069 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3070 | pasync_ctx->async_data.handle_base = |
| 3071 | mem_descr->mem_array[0].virtual_address; |
| 3072 | pasync_ctx->async_data.writables = 0; |
| 3073 | INIT_LIST_HEAD(&pasync_ctx->async_data.free_list); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3074 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3075 | pasync_header_h = |
| 3076 | (struct async_pdu_handle *) |
| 3077 | pasync_ctx->async_header.handle_base; |
| 3078 | pasync_data_h = |
| 3079 | (struct async_pdu_handle *) |
| 3080 | pasync_ctx->async_data.handle_base; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3081 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3082 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 3083 | mem_descr += HWI_MEM_ASYNC_DATA_BUF_ULP0 + |
| 3084 | (ulp_num * MEM_DESCR_OFFSET); |
| 3085 | if (mem_descr->mem_array[0].virtual_address) { |
| 3086 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3087 | "BM_%d : hwi_init_async_pdu_ctx" |
| 3088 | " HWI_MEM_ASYNC_DATA_BUF_ULP%d va=%p\n", |
| 3089 | ulp_num, |
| 3090 | mem_descr->mem_array[0]. |
| 3091 | virtual_address); |
| 3092 | } else |
| 3093 | beiscsi_log(phba, KERN_WARNING, |
| 3094 | BEISCSI_LOG_INIT, |
| 3095 | "BM_%d : No Virtual address for ULP : %d\n", |
| 3096 | ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3097 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3098 | idx = 0; |
Jayamohan Kallickal | dc63aac | 2012-04-03 23:41:36 -0500 | [diff] [blame] | 3099 | pasync_ctx->async_data.va_base = |
| 3100 | mem_descr->mem_array[idx].virtual_address; |
| 3101 | pasync_ctx->async_data.pa_base.u.a64.address = |
| 3102 | mem_descr->mem_array[idx]. |
| 3103 | bus_address.u.a64.address; |
| 3104 | |
| 3105 | num_async_data = ((mem_descr->mem_array[idx].size) / |
| 3106 | phba->params.defpdu_data_sz); |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3107 | num_per_mem = 0; |
| 3108 | |
| 3109 | for (index = 0; index < BEISCSI_GET_CID_COUNT |
| 3110 | (phba, ulp_num); index++) { |
| 3111 | pasync_header_h->cri = -1; |
| 3112 | pasync_header_h->index = (char)index; |
| 3113 | INIT_LIST_HEAD(&pasync_header_h->link); |
| 3114 | pasync_header_h->pbuffer = |
| 3115 | (void *)((unsigned long) |
| 3116 | (pasync_ctx-> |
| 3117 | async_header.va_base) + |
| 3118 | (p->defpdu_hdr_sz * index)); |
| 3119 | |
| 3120 | pasync_header_h->pa.u.a64.address = |
| 3121 | pasync_ctx->async_header.pa_base.u.a64. |
| 3122 | address + (p->defpdu_hdr_sz * index); |
| 3123 | |
| 3124 | list_add_tail(&pasync_header_h->link, |
| 3125 | &pasync_ctx->async_header. |
| 3126 | free_list); |
| 3127 | pasync_header_h++; |
| 3128 | pasync_ctx->async_header.free_entries++; |
| 3129 | pasync_ctx->async_header.writables++; |
| 3130 | |
| 3131 | INIT_LIST_HEAD(&pasync_ctx->async_entry[index]. |
| 3132 | wait_queue.list); |
| 3133 | INIT_LIST_HEAD(&pasync_ctx->async_entry[index]. |
| 3134 | header_busy_list); |
| 3135 | pasync_data_h->cri = -1; |
| 3136 | pasync_data_h->index = (char)index; |
| 3137 | INIT_LIST_HEAD(&pasync_data_h->link); |
| 3138 | |
| 3139 | if (!num_async_data) { |
| 3140 | num_per_mem = 0; |
| 3141 | idx++; |
| 3142 | pasync_ctx->async_data.va_base = |
| 3143 | mem_descr->mem_array[idx]. |
| 3144 | virtual_address; |
| 3145 | pasync_ctx->async_data.pa_base.u. |
| 3146 | a64.address = |
| 3147 | mem_descr->mem_array[idx]. |
| 3148 | bus_address.u.a64.address; |
| 3149 | num_async_data = |
| 3150 | ((mem_descr->mem_array[idx]. |
| 3151 | size) / |
| 3152 | phba->params.defpdu_data_sz); |
| 3153 | } |
| 3154 | pasync_data_h->pbuffer = |
| 3155 | (void *)((unsigned long) |
| 3156 | (pasync_ctx->async_data.va_base) + |
| 3157 | (p->defpdu_data_sz * num_per_mem)); |
| 3158 | |
| 3159 | pasync_data_h->pa.u.a64.address = |
| 3160 | pasync_ctx->async_data.pa_base.u.a64. |
| 3161 | address + (p->defpdu_data_sz * |
| 3162 | num_per_mem); |
| 3163 | num_per_mem++; |
| 3164 | num_async_data--; |
| 3165 | |
| 3166 | list_add_tail(&pasync_data_h->link, |
| 3167 | &pasync_ctx->async_data. |
| 3168 | free_list); |
| 3169 | pasync_data_h++; |
| 3170 | pasync_ctx->async_data.free_entries++; |
| 3171 | pasync_ctx->async_data.writables++; |
| 3172 | |
| 3173 | INIT_LIST_HEAD(&pasync_ctx->async_entry[index]. |
| 3174 | data_busy_list); |
| 3175 | } |
| 3176 | |
| 3177 | pasync_ctx->async_header.host_write_ptr = 0; |
| 3178 | pasync_ctx->async_header.ep_read_ptr = -1; |
| 3179 | pasync_ctx->async_data.host_write_ptr = 0; |
| 3180 | pasync_ctx->async_data.ep_read_ptr = -1; |
Jayamohan Kallickal | dc63aac | 2012-04-03 23:41:36 -0500 | [diff] [blame] | 3181 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3182 | } |
| 3183 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 3184 | return 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3185 | } |
| 3186 | |
| 3187 | static int |
| 3188 | be_sgl_create_contiguous(void *virtual_address, |
| 3189 | u64 physical_address, u32 length, |
| 3190 | struct be_dma_mem *sgl) |
| 3191 | { |
| 3192 | WARN_ON(!virtual_address); |
| 3193 | WARN_ON(!physical_address); |
Tim Gardner | dd29dae | 2015-10-30 12:22:58 -0600 | [diff] [blame] | 3194 | WARN_ON(!length); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3195 | WARN_ON(!sgl); |
| 3196 | |
| 3197 | sgl->va = virtual_address; |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 3198 | sgl->dma = (unsigned long)physical_address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3199 | sgl->size = length; |
| 3200 | |
| 3201 | return 0; |
| 3202 | } |
| 3203 | |
| 3204 | static void be_sgl_destroy_contiguous(struct be_dma_mem *sgl) |
| 3205 | { |
| 3206 | memset(sgl, 0, sizeof(*sgl)); |
| 3207 | } |
| 3208 | |
| 3209 | static void |
| 3210 | hwi_build_be_sgl_arr(struct beiscsi_hba *phba, |
| 3211 | struct mem_array *pmem, struct be_dma_mem *sgl) |
| 3212 | { |
| 3213 | if (sgl->va) |
| 3214 | be_sgl_destroy_contiguous(sgl); |
| 3215 | |
| 3216 | be_sgl_create_contiguous(pmem->virtual_address, |
| 3217 | pmem->bus_address.u.a64.address, |
| 3218 | pmem->size, sgl); |
| 3219 | } |
| 3220 | |
| 3221 | static void |
| 3222 | hwi_build_be_sgl_by_offset(struct beiscsi_hba *phba, |
| 3223 | struct mem_array *pmem, struct be_dma_mem *sgl) |
| 3224 | { |
| 3225 | if (sgl->va) |
| 3226 | be_sgl_destroy_contiguous(sgl); |
| 3227 | |
| 3228 | be_sgl_create_contiguous((unsigned char *)pmem->virtual_address, |
| 3229 | pmem->bus_address.u.a64.address, |
| 3230 | pmem->size, sgl); |
| 3231 | } |
| 3232 | |
| 3233 | static int be_fill_queue(struct be_queue_info *q, |
| 3234 | u16 len, u16 entry_size, void *vaddress) |
| 3235 | { |
| 3236 | struct be_dma_mem *mem = &q->dma_mem; |
| 3237 | |
| 3238 | memset(q, 0, sizeof(*q)); |
| 3239 | q->len = len; |
| 3240 | q->entry_size = entry_size; |
| 3241 | mem->size = len * entry_size; |
| 3242 | mem->va = vaddress; |
| 3243 | if (!mem->va) |
| 3244 | return -ENOMEM; |
| 3245 | memset(mem->va, 0, mem->size); |
| 3246 | return 0; |
| 3247 | } |
| 3248 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3249 | static int beiscsi_create_eqs(struct beiscsi_hba *phba, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3250 | struct hwi_context_memory *phwi_context) |
| 3251 | { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3252 | unsigned int i, num_eq_pages; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3253 | int ret = 0, eq_for_mcc; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3254 | struct be_queue_info *eq; |
| 3255 | struct be_dma_mem *mem; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3256 | void *eq_vaddress; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3257 | dma_addr_t paddr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3258 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3259 | num_eq_pages = PAGES_REQUIRED(phba->params.num_eq_entries * \ |
| 3260 | sizeof(struct be_eq_entry)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3261 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3262 | if (phba->msix_enabled) |
| 3263 | eq_for_mcc = 1; |
| 3264 | else |
| 3265 | eq_for_mcc = 0; |
| 3266 | for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) { |
| 3267 | eq = &phwi_context->be_eq[i].q; |
| 3268 | mem = &eq->dma_mem; |
| 3269 | phwi_context->be_eq[i].phba = phba; |
| 3270 | eq_vaddress = pci_alloc_consistent(phba->pcidev, |
| 3271 | num_eq_pages * PAGE_SIZE, |
| 3272 | &paddr); |
| 3273 | if (!eq_vaddress) |
| 3274 | goto create_eq_error; |
| 3275 | |
| 3276 | mem->va = eq_vaddress; |
| 3277 | ret = be_fill_queue(eq, phba->params.num_eq_entries, |
| 3278 | sizeof(struct be_eq_entry), eq_vaddress); |
| 3279 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3280 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3281 | "BM_%d : be_fill_queue Failed for EQ\n"); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3282 | goto create_eq_error; |
| 3283 | } |
| 3284 | |
| 3285 | mem->dma = paddr; |
| 3286 | ret = beiscsi_cmd_eq_create(&phba->ctrl, eq, |
| 3287 | phwi_context->cur_eqd); |
| 3288 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3289 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3290 | "BM_%d : beiscsi_cmd_eq_create" |
| 3291 | "Failed for EQ\n"); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3292 | goto create_eq_error; |
| 3293 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3294 | |
| 3295 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3296 | "BM_%d : eqid = %d\n", |
| 3297 | phwi_context->be_eq[i].q.id); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3298 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3299 | return 0; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3300 | create_eq_error: |
John Soni Jose | 107dfcb | 2012-10-20 04:42:13 +0530 | [diff] [blame] | 3301 | for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3302 | eq = &phwi_context->be_eq[i].q; |
| 3303 | mem = &eq->dma_mem; |
| 3304 | if (mem->va) |
| 3305 | pci_free_consistent(phba->pcidev, num_eq_pages |
| 3306 | * PAGE_SIZE, |
| 3307 | mem->va, mem->dma); |
| 3308 | } |
| 3309 | return ret; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3310 | } |
| 3311 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3312 | static int beiscsi_create_cqs(struct beiscsi_hba *phba, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3313 | struct hwi_context_memory *phwi_context) |
| 3314 | { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3315 | unsigned int i, num_cq_pages; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3316 | int ret = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3317 | struct be_queue_info *cq, *eq; |
| 3318 | struct be_dma_mem *mem; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3319 | struct be_eq_obj *pbe_eq; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3320 | void *cq_vaddress; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3321 | dma_addr_t paddr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3322 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3323 | num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \ |
| 3324 | sizeof(struct sol_cqe)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3325 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3326 | for (i = 0; i < phba->num_cpus; i++) { |
| 3327 | cq = &phwi_context->be_cq[i]; |
| 3328 | eq = &phwi_context->be_eq[i].q; |
| 3329 | pbe_eq = &phwi_context->be_eq[i]; |
| 3330 | pbe_eq->cq = cq; |
| 3331 | pbe_eq->phba = phba; |
| 3332 | mem = &cq->dma_mem; |
| 3333 | cq_vaddress = pci_alloc_consistent(phba->pcidev, |
| 3334 | num_cq_pages * PAGE_SIZE, |
| 3335 | &paddr); |
| 3336 | if (!cq_vaddress) |
| 3337 | goto create_cq_error; |
Jayamohan Kallickal | 7da5087 | 2010-01-05 05:04:12 +0530 | [diff] [blame] | 3338 | ret = be_fill_queue(cq, phba->params.num_cq_entries, |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3339 | sizeof(struct sol_cqe), cq_vaddress); |
| 3340 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3341 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3342 | "BM_%d : be_fill_queue Failed " |
| 3343 | "for ISCSI CQ\n"); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3344 | goto create_cq_error; |
| 3345 | } |
| 3346 | |
| 3347 | mem->dma = paddr; |
| 3348 | ret = beiscsi_cmd_cq_create(&phba->ctrl, cq, eq, false, |
| 3349 | false, 0); |
| 3350 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3351 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3352 | "BM_%d : beiscsi_cmd_eq_create" |
| 3353 | "Failed for ISCSI CQ\n"); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3354 | goto create_cq_error; |
| 3355 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3356 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3357 | "BM_%d : iscsi cq_id is %d for eq_id %d\n" |
| 3358 | "iSCSI CQ CREATED\n", cq->id, eq->id); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3359 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3360 | return 0; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3361 | |
| 3362 | create_cq_error: |
| 3363 | for (i = 0; i < phba->num_cpus; i++) { |
| 3364 | cq = &phwi_context->be_cq[i]; |
| 3365 | mem = &cq->dma_mem; |
| 3366 | if (mem->va) |
| 3367 | pci_free_consistent(phba->pcidev, num_cq_pages |
| 3368 | * PAGE_SIZE, |
| 3369 | mem->va, mem->dma); |
| 3370 | } |
| 3371 | return ret; |
| 3372 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3373 | } |
| 3374 | |
| 3375 | static int |
| 3376 | beiscsi_create_def_hdr(struct beiscsi_hba *phba, |
| 3377 | struct hwi_context_memory *phwi_context, |
| 3378 | struct hwi_controller *phwi_ctrlr, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3379 | unsigned int def_pdu_ring_sz, uint8_t ulp_num) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3380 | { |
| 3381 | unsigned int idx; |
| 3382 | int ret; |
| 3383 | struct be_queue_info *dq, *cq; |
| 3384 | struct be_dma_mem *mem; |
| 3385 | struct be_mem_descriptor *mem_descr; |
| 3386 | void *dq_vaddress; |
| 3387 | |
| 3388 | idx = 0; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3389 | dq = &phwi_context->be_def_hdrq[ulp_num]; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3390 | cq = &phwi_context->be_cq[0]; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3391 | mem = &dq->dma_mem; |
| 3392 | mem_descr = phba->init_mem; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3393 | mem_descr += HWI_MEM_ASYNC_HEADER_RING_ULP0 + |
| 3394 | (ulp_num * MEM_DESCR_OFFSET); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3395 | dq_vaddress = mem_descr->mem_array[idx].virtual_address; |
| 3396 | ret = be_fill_queue(dq, mem_descr->mem_array[0].size / |
| 3397 | sizeof(struct phys_addr), |
| 3398 | sizeof(struct phys_addr), dq_vaddress); |
| 3399 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3400 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3401 | "BM_%d : be_fill_queue Failed for DEF PDU HDR on ULP : %d\n", |
| 3402 | ulp_num); |
| 3403 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3404 | return ret; |
| 3405 | } |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 3406 | mem->dma = (unsigned long)mem_descr->mem_array[idx]. |
| 3407 | bus_address.u.a64.address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3408 | ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dq, |
| 3409 | def_pdu_ring_sz, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3410 | phba->params.defpdu_hdr_sz, |
| 3411 | BEISCSI_DEFQ_HDR, ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3412 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3413 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3414 | "BM_%d : be_cmd_create_default_pdu_queue Failed DEFHDR on ULP : %d\n", |
| 3415 | ulp_num); |
| 3416 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3417 | return ret; |
| 3418 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3419 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3420 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3421 | "BM_%d : iscsi hdr def pdu id for ULP : %d is %d\n", |
| 3422 | ulp_num, |
| 3423 | phwi_context->be_def_hdrq[ulp_num].id); |
| 3424 | hwi_post_async_buffers(phba, BEISCSI_DEFQ_HDR, ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3425 | return 0; |
| 3426 | } |
| 3427 | |
| 3428 | static int |
| 3429 | beiscsi_create_def_data(struct beiscsi_hba *phba, |
| 3430 | struct hwi_context_memory *phwi_context, |
| 3431 | struct hwi_controller *phwi_ctrlr, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3432 | unsigned int def_pdu_ring_sz, uint8_t ulp_num) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3433 | { |
| 3434 | unsigned int idx; |
| 3435 | int ret; |
| 3436 | struct be_queue_info *dataq, *cq; |
| 3437 | struct be_dma_mem *mem; |
| 3438 | struct be_mem_descriptor *mem_descr; |
| 3439 | void *dq_vaddress; |
| 3440 | |
| 3441 | idx = 0; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3442 | dataq = &phwi_context->be_def_dataq[ulp_num]; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3443 | cq = &phwi_context->be_cq[0]; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3444 | mem = &dataq->dma_mem; |
| 3445 | mem_descr = phba->init_mem; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3446 | mem_descr += HWI_MEM_ASYNC_DATA_RING_ULP0 + |
| 3447 | (ulp_num * MEM_DESCR_OFFSET); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3448 | dq_vaddress = mem_descr->mem_array[idx].virtual_address; |
| 3449 | ret = be_fill_queue(dataq, mem_descr->mem_array[0].size / |
| 3450 | sizeof(struct phys_addr), |
| 3451 | sizeof(struct phys_addr), dq_vaddress); |
| 3452 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3453 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3454 | "BM_%d : be_fill_queue Failed for DEF PDU " |
| 3455 | "DATA on ULP : %d\n", |
| 3456 | ulp_num); |
| 3457 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3458 | return ret; |
| 3459 | } |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 3460 | mem->dma = (unsigned long)mem_descr->mem_array[idx]. |
| 3461 | bus_address.u.a64.address; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3462 | ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dataq, |
| 3463 | def_pdu_ring_sz, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3464 | phba->params.defpdu_data_sz, |
| 3465 | BEISCSI_DEFQ_DATA, ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3466 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3467 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3468 | "BM_%d be_cmd_create_default_pdu_queue" |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3469 | " Failed for DEF PDU DATA on ULP : %d\n", |
| 3470 | ulp_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3471 | return ret; |
| 3472 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3473 | |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3474 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3475 | "BM_%d : iscsi def data id on ULP : %d is %d\n", |
| 3476 | ulp_num, |
| 3477 | phwi_context->be_def_dataq[ulp_num].id); |
| 3478 | |
| 3479 | hwi_post_async_buffers(phba, BEISCSI_DEFQ_DATA, ulp_num); |
| 3480 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3481 | "BM_%d : DEFAULT PDU DATA RING CREATED" |
| 3482 | "on ULP : %d\n", ulp_num); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3483 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3484 | return 0; |
| 3485 | } |
| 3486 | |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3487 | |
| 3488 | static int |
| 3489 | beiscsi_post_template_hdr(struct beiscsi_hba *phba) |
| 3490 | { |
| 3491 | struct be_mem_descriptor *mem_descr; |
| 3492 | struct mem_array *pm_arr; |
| 3493 | struct be_dma_mem sgl; |
Jayamohan Kallickal | a129d92 | 2013-09-28 15:35:46 -0700 | [diff] [blame] | 3494 | int status, ulp_num; |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3495 | |
Jayamohan Kallickal | a129d92 | 2013-09-28 15:35:46 -0700 | [diff] [blame] | 3496 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 3497 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
| 3498 | mem_descr = (struct be_mem_descriptor *)phba->init_mem; |
| 3499 | mem_descr += HWI_MEM_TEMPLATE_HDR_ULP0 + |
| 3500 | (ulp_num * MEM_DESCR_OFFSET); |
| 3501 | pm_arr = mem_descr->mem_array; |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3502 | |
Jayamohan Kallickal | a129d92 | 2013-09-28 15:35:46 -0700 | [diff] [blame] | 3503 | hwi_build_be_sgl_arr(phba, pm_arr, &sgl); |
| 3504 | status = be_cmd_iscsi_post_template_hdr( |
| 3505 | &phba->ctrl, &sgl); |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3506 | |
Jayamohan Kallickal | a129d92 | 2013-09-28 15:35:46 -0700 | [diff] [blame] | 3507 | if (status != 0) { |
| 3508 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3509 | "BM_%d : Post Template HDR Failed for" |
| 3510 | "ULP_%d\n", ulp_num); |
| 3511 | return status; |
| 3512 | } |
| 3513 | |
| 3514 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3515 | "BM_%d : Template HDR Pages Posted for" |
| 3516 | "ULP_%d\n", ulp_num); |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3517 | } |
| 3518 | } |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3519 | return 0; |
| 3520 | } |
| 3521 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3522 | static int |
| 3523 | beiscsi_post_pages(struct beiscsi_hba *phba) |
| 3524 | { |
| 3525 | struct be_mem_descriptor *mem_descr; |
| 3526 | struct mem_array *pm_arr; |
| 3527 | unsigned int page_offset, i; |
| 3528 | struct be_dma_mem sgl; |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 3529 | int status, ulp_num = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3530 | |
| 3531 | mem_descr = phba->init_mem; |
| 3532 | mem_descr += HWI_MEM_SGE; |
| 3533 | pm_arr = mem_descr->mem_array; |
| 3534 | |
Jayamohan Kallickal | 90622db | 2013-09-28 15:35:47 -0700 | [diff] [blame] | 3535 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) |
| 3536 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) |
| 3537 | break; |
| 3538 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3539 | page_offset = (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io * |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 3540 | phba->fw_config.iscsi_icd_start[ulp_num]) / PAGE_SIZE; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3541 | for (i = 0; i < mem_descr->num_elements; i++) { |
| 3542 | hwi_build_be_sgl_arr(phba, pm_arr, &sgl); |
| 3543 | status = be_cmd_iscsi_post_sgl_pages(&phba->ctrl, &sgl, |
| 3544 | page_offset, |
| 3545 | (pm_arr->size / PAGE_SIZE)); |
| 3546 | page_offset += pm_arr->size / PAGE_SIZE; |
| 3547 | if (status != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3548 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3549 | "BM_%d : post sgl failed.\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3550 | return status; |
| 3551 | } |
| 3552 | pm_arr++; |
| 3553 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3554 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3555 | "BM_%d : POSTED PAGES\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3556 | return 0; |
| 3557 | } |
| 3558 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3559 | static void be_queue_free(struct beiscsi_hba *phba, struct be_queue_info *q) |
| 3560 | { |
| 3561 | struct be_dma_mem *mem = &q->dma_mem; |
Jayamohan Kallickal | c8b2559 | 2012-04-03 23:41:42 -0500 | [diff] [blame] | 3562 | if (mem->va) { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3563 | pci_free_consistent(phba->pcidev, mem->size, |
| 3564 | mem->va, mem->dma); |
Jayamohan Kallickal | c8b2559 | 2012-04-03 23:41:42 -0500 | [diff] [blame] | 3565 | mem->va = NULL; |
| 3566 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3567 | } |
| 3568 | |
| 3569 | static int be_queue_alloc(struct beiscsi_hba *phba, struct be_queue_info *q, |
| 3570 | u16 len, u16 entry_size) |
| 3571 | { |
| 3572 | struct be_dma_mem *mem = &q->dma_mem; |
| 3573 | |
| 3574 | memset(q, 0, sizeof(*q)); |
| 3575 | q->len = len; |
| 3576 | q->entry_size = entry_size; |
| 3577 | mem->size = len * entry_size; |
Joe Perches | 7c845eb | 2014-08-08 14:24:46 -0700 | [diff] [blame] | 3578 | mem->va = pci_zalloc_consistent(phba->pcidev, mem->size, &mem->dma); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3579 | if (!mem->va) |
Jayamohan Kallickal | d3ad2bb | 2010-07-22 04:16:38 +0530 | [diff] [blame] | 3580 | return -ENOMEM; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3581 | return 0; |
| 3582 | } |
| 3583 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3584 | static int |
| 3585 | beiscsi_create_wrb_rings(struct beiscsi_hba *phba, |
| 3586 | struct hwi_context_memory *phwi_context, |
| 3587 | struct hwi_controller *phwi_ctrlr) |
| 3588 | { |
| 3589 | unsigned int wrb_mem_index, offset, size, num_wrb_rings; |
| 3590 | u64 pa_addr_lo; |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 3591 | unsigned int idx, num, i, ulp_num; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3592 | struct mem_array *pwrb_arr; |
| 3593 | void *wrb_vaddr; |
| 3594 | struct be_dma_mem sgl; |
| 3595 | struct be_mem_descriptor *mem_descr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 3596 | struct hwi_wrb_context *pwrb_context; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3597 | int status; |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 3598 | uint8_t ulp_count = 0, ulp_base_num = 0; |
| 3599 | uint16_t cid_count_ulp[BEISCSI_ULP_COUNT] = { 0 }; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3600 | |
| 3601 | idx = 0; |
| 3602 | mem_descr = phba->init_mem; |
| 3603 | mem_descr += HWI_MEM_WRB; |
| 3604 | pwrb_arr = kmalloc(sizeof(*pwrb_arr) * phba->params.cxns_per_ctrl, |
| 3605 | GFP_KERNEL); |
| 3606 | if (!pwrb_arr) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3607 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3608 | "BM_%d : Memory alloc failed in create wrb ring.\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3609 | return -ENOMEM; |
| 3610 | } |
| 3611 | wrb_vaddr = mem_descr->mem_array[idx].virtual_address; |
| 3612 | pa_addr_lo = mem_descr->mem_array[idx].bus_address.u.a64.address; |
| 3613 | num_wrb_rings = mem_descr->mem_array[idx].size / |
| 3614 | (phba->params.wrbs_per_cxn * sizeof(struct iscsi_wrb)); |
| 3615 | |
| 3616 | for (num = 0; num < phba->params.cxns_per_ctrl; num++) { |
| 3617 | if (num_wrb_rings) { |
| 3618 | pwrb_arr[num].virtual_address = wrb_vaddr; |
| 3619 | pwrb_arr[num].bus_address.u.a64.address = pa_addr_lo; |
| 3620 | pwrb_arr[num].size = phba->params.wrbs_per_cxn * |
| 3621 | sizeof(struct iscsi_wrb); |
| 3622 | wrb_vaddr += pwrb_arr[num].size; |
| 3623 | pa_addr_lo += pwrb_arr[num].size; |
| 3624 | num_wrb_rings--; |
| 3625 | } else { |
| 3626 | idx++; |
| 3627 | wrb_vaddr = mem_descr->mem_array[idx].virtual_address; |
| 3628 | pa_addr_lo = mem_descr->mem_array[idx].\ |
| 3629 | bus_address.u.a64.address; |
| 3630 | num_wrb_rings = mem_descr->mem_array[idx].size / |
| 3631 | (phba->params.wrbs_per_cxn * |
| 3632 | sizeof(struct iscsi_wrb)); |
| 3633 | pwrb_arr[num].virtual_address = wrb_vaddr; |
| 3634 | pwrb_arr[num].bus_address.u.a64.address\ |
| 3635 | = pa_addr_lo; |
| 3636 | pwrb_arr[num].size = phba->params.wrbs_per_cxn * |
| 3637 | sizeof(struct iscsi_wrb); |
| 3638 | wrb_vaddr += pwrb_arr[num].size; |
| 3639 | pa_addr_lo += pwrb_arr[num].size; |
| 3640 | num_wrb_rings--; |
| 3641 | } |
| 3642 | } |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 3643 | |
| 3644 | /* Get the ULP Count */ |
| 3645 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) |
| 3646 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
| 3647 | ulp_count++; |
| 3648 | ulp_base_num = ulp_num; |
| 3649 | cid_count_ulp[ulp_num] = |
| 3650 | BEISCSI_GET_CID_COUNT(phba, ulp_num); |
| 3651 | } |
| 3652 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3653 | for (i = 0; i < phba->params.cxns_per_ctrl; i++) { |
| 3654 | wrb_mem_index = 0; |
| 3655 | offset = 0; |
| 3656 | size = 0; |
| 3657 | |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 3658 | if (ulp_count > 1) { |
| 3659 | ulp_base_num = (ulp_base_num + 1) % BEISCSI_ULP_COUNT; |
| 3660 | |
| 3661 | if (!cid_count_ulp[ulp_base_num]) |
| 3662 | ulp_base_num = (ulp_base_num + 1) % |
| 3663 | BEISCSI_ULP_COUNT; |
| 3664 | |
| 3665 | cid_count_ulp[ulp_base_num]--; |
| 3666 | } |
| 3667 | |
| 3668 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3669 | hwi_build_be_sgl_by_offset(phba, &pwrb_arr[i], &sgl); |
| 3670 | status = be_cmd_wrbq_create(&phba->ctrl, &sgl, |
Jayamohan Kallickal | 4eea99d | 2013-09-28 15:35:48 -0700 | [diff] [blame] | 3671 | &phwi_context->be_wrbq[i], |
| 3672 | &phwi_ctrlr->wrb_context[i], |
| 3673 | ulp_base_num); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3674 | if (status != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3675 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3676 | "BM_%d : wrbq create failed."); |
Dan Carpenter | 1462b8f | 2010-06-10 09:52:21 +0200 | [diff] [blame] | 3677 | kfree(pwrb_arr); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3678 | return status; |
| 3679 | } |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 3680 | pwrb_context = &phwi_ctrlr->wrb_context[i]; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 3681 | BE_SET_CID_TO_CRI(i, pwrb_context->cid); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3682 | } |
| 3683 | kfree(pwrb_arr); |
| 3684 | return 0; |
| 3685 | } |
| 3686 | |
| 3687 | static void free_wrb_handles(struct beiscsi_hba *phba) |
| 3688 | { |
| 3689 | unsigned int index; |
| 3690 | struct hwi_controller *phwi_ctrlr; |
| 3691 | struct hwi_wrb_context *pwrb_context; |
| 3692 | |
| 3693 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 3694 | for (index = 0; index < phba->params.cxns_per_ctrl; index++) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3695 | pwrb_context = &phwi_ctrlr->wrb_context[index]; |
| 3696 | kfree(pwrb_context->pwrb_handle_base); |
| 3697 | kfree(pwrb_context->pwrb_handle_basestd); |
| 3698 | } |
| 3699 | } |
| 3700 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3701 | static void be_mcc_queues_destroy(struct beiscsi_hba *phba) |
| 3702 | { |
| 3703 | struct be_queue_info *q; |
| 3704 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 3705 | |
| 3706 | q = &phba->ctrl.mcc_obj.q; |
John Soni Jose | 4e2bdf7 | 2015-04-25 08:17:31 +0530 | [diff] [blame] | 3707 | if (q->created) { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3708 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_MCCQ); |
John Soni Jose | 4e2bdf7 | 2015-04-25 08:17:31 +0530 | [diff] [blame] | 3709 | be_queue_free(phba, q); |
| 3710 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3711 | |
| 3712 | q = &phba->ctrl.mcc_obj.cq; |
John Soni Jose | 4e2bdf7 | 2015-04-25 08:17:31 +0530 | [diff] [blame] | 3713 | if (q->created) { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3714 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ); |
John Soni Jose | 4e2bdf7 | 2015-04-25 08:17:31 +0530 | [diff] [blame] | 3715 | be_queue_free(phba, q); |
| 3716 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3717 | } |
| 3718 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3719 | static void hwi_cleanup(struct beiscsi_hba *phba) |
| 3720 | { |
| 3721 | struct be_queue_info *q; |
| 3722 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 3723 | struct hwi_controller *phwi_ctrlr; |
| 3724 | struct hwi_context_memory *phwi_context; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 3725 | struct hwi_async_pdu_context *pasync_ctx; |
Jayamohan Kallickal | 2318816 | 2014-05-05 21:41:29 -0400 | [diff] [blame] | 3726 | int i, eq_for_mcc, ulp_num; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3727 | |
| 3728 | phwi_ctrlr = phba->phwi_ctrlr; |
| 3729 | phwi_context = phwi_ctrlr->phwi_ctxt; |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3730 | |
| 3731 | be_cmd_iscsi_remove_template_hdr(ctrl); |
| 3732 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3733 | for (i = 0; i < phba->params.cxns_per_ctrl; i++) { |
| 3734 | q = &phwi_context->be_wrbq[i]; |
| 3735 | if (q->created) |
| 3736 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_WRBQ); |
| 3737 | } |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 3738 | kfree(phwi_context->be_wrbq); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3739 | free_wrb_handles(phba); |
| 3740 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3741 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 3742 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3743 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3744 | q = &phwi_context->be_def_hdrq[ulp_num]; |
| 3745 | if (q->created) |
| 3746 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ); |
| 3747 | |
| 3748 | q = &phwi_context->be_def_dataq[ulp_num]; |
| 3749 | if (q->created) |
| 3750 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ); |
| 3751 | |
| 3752 | pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num]; |
| 3753 | } |
| 3754 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3755 | |
| 3756 | beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL); |
| 3757 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3758 | for (i = 0; i < (phba->num_cpus); i++) { |
| 3759 | q = &phwi_context->be_cq[i]; |
John Soni Jose | 4e2bdf7 | 2015-04-25 08:17:31 +0530 | [diff] [blame] | 3760 | if (q->created) { |
| 3761 | be_queue_free(phba, q); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3762 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ); |
John Soni Jose | 4e2bdf7 | 2015-04-25 08:17:31 +0530 | [diff] [blame] | 3763 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3764 | } |
Jayamohan Kallickal | 2318816 | 2014-05-05 21:41:29 -0400 | [diff] [blame] | 3765 | |
| 3766 | be_mcc_queues_destroy(phba); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3767 | if (phba->msix_enabled) |
Jayamohan Kallickal | 2318816 | 2014-05-05 21:41:29 -0400 | [diff] [blame] | 3768 | eq_for_mcc = 1; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3769 | else |
Jayamohan Kallickal | 2318816 | 2014-05-05 21:41:29 -0400 | [diff] [blame] | 3770 | eq_for_mcc = 0; |
| 3771 | for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3772 | q = &phwi_context->be_eq[i].q; |
John Soni Jose | 4e2bdf7 | 2015-04-25 08:17:31 +0530 | [diff] [blame] | 3773 | if (q->created) { |
| 3774 | be_queue_free(phba, q); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3775 | beiscsi_cmd_q_destroy(ctrl, q, QTYPE_EQ); |
John Soni Jose | 4e2bdf7 | 2015-04-25 08:17:31 +0530 | [diff] [blame] | 3776 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3777 | } |
Jayamohan Kallickal | 0283fbb | 2013-04-05 20:38:21 -0700 | [diff] [blame] | 3778 | be_cmd_fw_uninit(ctrl); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3779 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3780 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3781 | static int be_mcc_queues_create(struct beiscsi_hba *phba, |
| 3782 | struct hwi_context_memory *phwi_context) |
| 3783 | { |
| 3784 | struct be_queue_info *q, *cq; |
| 3785 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 3786 | |
| 3787 | /* Alloc MCC compl queue */ |
| 3788 | cq = &phba->ctrl.mcc_obj.cq; |
| 3789 | if (be_queue_alloc(phba, cq, MCC_CQ_LEN, |
| 3790 | sizeof(struct be_mcc_compl))) |
| 3791 | goto err; |
| 3792 | /* Ask BE to create MCC compl queue; */ |
| 3793 | if (phba->msix_enabled) { |
| 3794 | if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq |
| 3795 | [phba->num_cpus].q, false, true, 0)) |
| 3796 | goto mcc_cq_free; |
| 3797 | } else { |
| 3798 | if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq[0].q, |
| 3799 | false, true, 0)) |
| 3800 | goto mcc_cq_free; |
| 3801 | } |
| 3802 | |
| 3803 | /* Alloc MCC queue */ |
| 3804 | q = &phba->ctrl.mcc_obj.q; |
| 3805 | if (be_queue_alloc(phba, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb))) |
| 3806 | goto mcc_cq_destroy; |
| 3807 | |
| 3808 | /* Ask BE to create MCC queue */ |
Jayamohan Kallickal | 35e6601 | 2009-10-23 11:53:49 +0530 | [diff] [blame] | 3809 | if (beiscsi_cmd_mccq_create(phba, q, cq)) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3810 | goto mcc_q_free; |
| 3811 | |
| 3812 | return 0; |
| 3813 | |
| 3814 | mcc_q_free: |
| 3815 | be_queue_free(phba, q); |
| 3816 | mcc_cq_destroy: |
| 3817 | beiscsi_cmd_q_destroy(ctrl, cq, QTYPE_CQ); |
| 3818 | mcc_cq_free: |
| 3819 | be_queue_free(phba, cq); |
| 3820 | err: |
Jayamohan Kallickal | d3ad2bb | 2010-07-22 04:16:38 +0530 | [diff] [blame] | 3821 | return -ENOMEM; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3822 | } |
| 3823 | |
John Soni Jose | 107dfcb | 2012-10-20 04:42:13 +0530 | [diff] [blame] | 3824 | /** |
| 3825 | * find_num_cpus()- Get the CPU online count |
| 3826 | * @phba: ptr to priv structure |
| 3827 | * |
| 3828 | * CPU count is used for creating EQ. |
| 3829 | **/ |
| 3830 | static void find_num_cpus(struct beiscsi_hba *phba) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3831 | { |
| 3832 | int num_cpus = 0; |
| 3833 | |
| 3834 | num_cpus = num_online_cpus(); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3835 | |
John Soni Jose | 22abeef | 2012-10-20 04:43:32 +0530 | [diff] [blame] | 3836 | switch (phba->generation) { |
| 3837 | case BE_GEN2: |
| 3838 | case BE_GEN3: |
| 3839 | phba->num_cpus = (num_cpus > BEISCSI_MAX_NUM_CPUS) ? |
| 3840 | BEISCSI_MAX_NUM_CPUS : num_cpus; |
| 3841 | break; |
| 3842 | case BE_GEN4: |
Jayamohan Kallickal | 68c26a3 | 2013-09-28 15:35:54 -0700 | [diff] [blame] | 3843 | /* |
| 3844 | * If eqid_count == 1 fall back to |
| 3845 | * INTX mechanism |
| 3846 | **/ |
| 3847 | if (phba->fw_config.eqid_count == 1) { |
| 3848 | enable_msix = 0; |
| 3849 | phba->num_cpus = 1; |
| 3850 | return; |
| 3851 | } |
| 3852 | |
| 3853 | phba->num_cpus = |
| 3854 | (num_cpus > (phba->fw_config.eqid_count - 1)) ? |
| 3855 | (phba->fw_config.eqid_count - 1) : num_cpus; |
John Soni Jose | 22abeef | 2012-10-20 04:43:32 +0530 | [diff] [blame] | 3856 | break; |
| 3857 | default: |
| 3858 | phba->num_cpus = 1; |
| 3859 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3860 | } |
| 3861 | |
| 3862 | static int hwi_init_port(struct beiscsi_hba *phba) |
| 3863 | { |
| 3864 | struct hwi_controller *phwi_ctrlr; |
| 3865 | struct hwi_context_memory *phwi_context; |
| 3866 | unsigned int def_pdu_ring_sz; |
| 3867 | struct be_ctrl_info *ctrl = &phba->ctrl; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3868 | int status, ulp_num; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3869 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3870 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3871 | phwi_context = phwi_ctrlr->phwi_ctxt; |
Jayamohan Kallickal | 73af08e | 2014-05-05 21:41:26 -0400 | [diff] [blame] | 3872 | phwi_context->max_eqd = 128; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3873 | phwi_context->min_eqd = 0; |
Jayamohan Kallickal | 73af08e | 2014-05-05 21:41:26 -0400 | [diff] [blame] | 3874 | phwi_context->cur_eqd = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3875 | be_cmd_fw_initialize(&phba->ctrl); |
Jitendra Bhivare | 53aefe2 | 2016-01-20 14:10:53 +0530 | [diff] [blame] | 3876 | /* set optic state to unknown */ |
| 3877 | phba->optic_state = 0xff; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3878 | |
| 3879 | status = beiscsi_create_eqs(phba, phwi_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3880 | if (status != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3881 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3882 | "BM_%d : EQ not created\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3883 | goto error; |
| 3884 | } |
| 3885 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3886 | status = be_mcc_queues_create(phba, phwi_context); |
| 3887 | if (status != 0) |
| 3888 | goto error; |
| 3889 | |
| 3890 | status = mgmt_check_supported_fw(ctrl, phba); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3891 | if (status != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3892 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3893 | "BM_%d : Unsupported fw version\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3894 | goto error; |
| 3895 | } |
| 3896 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 3897 | status = beiscsi_create_cqs(phba, phwi_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3898 | if (status != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3899 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3900 | "BM_%d : CQ not created\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3901 | goto error; |
| 3902 | } |
| 3903 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3904 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 3905 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3906 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3907 | def_pdu_ring_sz = |
| 3908 | BEISCSI_GET_CID_COUNT(phba, ulp_num) * |
| 3909 | sizeof(struct phys_addr); |
| 3910 | |
| 3911 | status = beiscsi_create_def_hdr(phba, phwi_context, |
| 3912 | phwi_ctrlr, |
| 3913 | def_pdu_ring_sz, |
| 3914 | ulp_num); |
| 3915 | if (status != 0) { |
| 3916 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3917 | "BM_%d : Default Header not created for ULP : %d\n", |
| 3918 | ulp_num); |
| 3919 | goto error; |
| 3920 | } |
| 3921 | |
| 3922 | status = beiscsi_create_def_data(phba, phwi_context, |
| 3923 | phwi_ctrlr, |
| 3924 | def_pdu_ring_sz, |
| 3925 | ulp_num); |
| 3926 | if (status != 0) { |
| 3927 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3928 | "BM_%d : Default Data not created for ULP : %d\n", |
| 3929 | ulp_num); |
| 3930 | goto error; |
| 3931 | } |
| 3932 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3933 | } |
| 3934 | |
| 3935 | status = beiscsi_post_pages(phba); |
| 3936 | if (status != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3937 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3938 | "BM_%d : Post SGL Pages Failed\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3939 | goto error; |
| 3940 | } |
| 3941 | |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 3942 | status = beiscsi_post_template_hdr(phba); |
| 3943 | if (status != 0) { |
| 3944 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3945 | "BM_%d : Template HDR Posting for CXN Failed\n"); |
| 3946 | } |
| 3947 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3948 | status = beiscsi_create_wrb_rings(phba, phwi_context, phwi_ctrlr); |
| 3949 | if (status != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3950 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3951 | "BM_%d : WRB Rings not created\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3952 | goto error; |
| 3953 | } |
| 3954 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 3955 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 3956 | uint16_t async_arr_idx = 0; |
| 3957 | |
| 3958 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) { |
| 3959 | uint16_t cri = 0; |
| 3960 | struct hwi_async_pdu_context *pasync_ctx; |
| 3961 | |
| 3962 | pasync_ctx = HWI_GET_ASYNC_PDU_CTX( |
| 3963 | phwi_ctrlr, ulp_num); |
| 3964 | for (cri = 0; cri < |
| 3965 | phba->params.cxns_per_ctrl; cri++) { |
| 3966 | if (ulp_num == BEISCSI_GET_ULP_FROM_CRI |
| 3967 | (phwi_ctrlr, cri)) |
| 3968 | pasync_ctx->cid_to_async_cri_map[ |
| 3969 | phwi_ctrlr->wrb_context[cri].cid] = |
| 3970 | async_arr_idx++; |
| 3971 | } |
| 3972 | } |
| 3973 | } |
| 3974 | |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3975 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3976 | "BM_%d : hwi_init_port success\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3977 | return 0; |
| 3978 | |
| 3979 | error: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3980 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3981 | "BM_%d : hwi_init_port failed"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3982 | hwi_cleanup(phba); |
Jayamohan Kallickal | a49e06d | 2012-04-03 23:41:44 -0500 | [diff] [blame] | 3983 | return status; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3984 | } |
| 3985 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3986 | static int hwi_init_controller(struct beiscsi_hba *phba) |
| 3987 | { |
| 3988 | struct hwi_controller *phwi_ctrlr; |
| 3989 | |
| 3990 | phwi_ctrlr = phba->phwi_ctrlr; |
| 3991 | if (1 == phba->init_mem[HWI_MEM_ADDN_CONTEXT].num_elements) { |
| 3992 | phwi_ctrlr->phwi_ctxt = (struct hwi_context_memory *)phba-> |
| 3993 | init_mem[HWI_MEM_ADDN_CONTEXT].mem_array[0].virtual_address; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3994 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 3995 | "BM_%d : phwi_ctrlr->phwi_ctxt=%p\n", |
| 3996 | phwi_ctrlr->phwi_ctxt); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3997 | } else { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 3998 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 3999 | "BM_%d : HWI_MEM_ADDN_CONTEXT is more " |
| 4000 | "than one element.Failing to load\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4001 | return -ENOMEM; |
| 4002 | } |
| 4003 | |
| 4004 | iscsi_init_global_templates(phba); |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 4005 | if (beiscsi_init_wrb_handle(phba)) |
| 4006 | return -ENOMEM; |
| 4007 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4008 | if (hwi_init_async_pdu_ctx(phba)) { |
| 4009 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4010 | "BM_%d : hwi_init_async_pdu_ctx failed\n"); |
| 4011 | return -ENOMEM; |
| 4012 | } |
| 4013 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4014 | if (hwi_init_port(phba) != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4015 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4016 | "BM_%d : hwi_init_controller failed\n"); |
| 4017 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4018 | return -ENOMEM; |
| 4019 | } |
| 4020 | return 0; |
| 4021 | } |
| 4022 | |
| 4023 | static void beiscsi_free_mem(struct beiscsi_hba *phba) |
| 4024 | { |
| 4025 | struct be_mem_descriptor *mem_descr; |
| 4026 | int i, j; |
| 4027 | |
| 4028 | mem_descr = phba->init_mem; |
| 4029 | i = 0; |
| 4030 | j = 0; |
| 4031 | for (i = 0; i < SE_MEM_MAX; i++) { |
| 4032 | for (j = mem_descr->num_elements; j > 0; j--) { |
| 4033 | pci_free_consistent(phba->pcidev, |
| 4034 | mem_descr->mem_array[j - 1].size, |
| 4035 | mem_descr->mem_array[j - 1].virtual_address, |
Jayamohan Kallickal | 457ff3b | 2010-07-22 04:16:00 +0530 | [diff] [blame] | 4036 | (unsigned long)mem_descr->mem_array[j - 1]. |
| 4037 | bus_address.u.a64.address); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4038 | } |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame] | 4039 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4040 | kfree(mem_descr->mem_array); |
| 4041 | mem_descr++; |
| 4042 | } |
| 4043 | kfree(phba->init_mem); |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4044 | kfree(phba->phwi_ctrlr->wrb_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4045 | kfree(phba->phwi_ctrlr); |
| 4046 | } |
| 4047 | |
| 4048 | static int beiscsi_init_controller(struct beiscsi_hba *phba) |
| 4049 | { |
| 4050 | int ret = -ENOMEM; |
| 4051 | |
| 4052 | ret = beiscsi_get_memory(phba); |
| 4053 | if (ret < 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4054 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4055 | "BM_%d : beiscsi_dev_probe -" |
| 4056 | "Failed in beiscsi_alloc_memory\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4057 | return ret; |
| 4058 | } |
| 4059 | |
| 4060 | ret = hwi_init_controller(phba); |
| 4061 | if (ret) |
| 4062 | goto free_init; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4063 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 4064 | "BM_%d : Return success from beiscsi_init_controller"); |
| 4065 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4066 | return 0; |
| 4067 | |
| 4068 | free_init: |
| 4069 | beiscsi_free_mem(phba); |
Jayamohan Kallickal | a49e06d | 2012-04-03 23:41:44 -0500 | [diff] [blame] | 4070 | return ret; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4071 | } |
| 4072 | |
| 4073 | static int beiscsi_init_sgl_handle(struct beiscsi_hba *phba) |
| 4074 | { |
| 4075 | struct be_mem_descriptor *mem_descr_sglh, *mem_descr_sg; |
| 4076 | struct sgl_handle *psgl_handle; |
| 4077 | struct iscsi_sge *pfrag; |
Jayamohan Kallickal | 90622db | 2013-09-28 15:35:47 -0700 | [diff] [blame] | 4078 | unsigned int arr_index, i, idx; |
| 4079 | unsigned int ulp_icd_start, ulp_num = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4080 | |
| 4081 | phba->io_sgl_hndl_avbl = 0; |
| 4082 | phba->eh_sgl_hndl_avbl = 0; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4083 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4084 | mem_descr_sglh = phba->init_mem; |
| 4085 | mem_descr_sglh += HWI_MEM_SGLH; |
| 4086 | if (1 == mem_descr_sglh->num_elements) { |
| 4087 | phba->io_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) * |
| 4088 | phba->params.ios_per_ctrl, |
| 4089 | GFP_KERNEL); |
| 4090 | if (!phba->io_sgl_hndl_base) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4091 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4092 | "BM_%d : Mem Alloc Failed. Failing to load\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4093 | return -ENOMEM; |
| 4094 | } |
| 4095 | phba->eh_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) * |
| 4096 | (phba->params.icds_per_ctrl - |
| 4097 | phba->params.ios_per_ctrl), |
| 4098 | GFP_KERNEL); |
| 4099 | if (!phba->eh_sgl_hndl_base) { |
| 4100 | kfree(phba->io_sgl_hndl_base); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4101 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4102 | "BM_%d : Mem Alloc Failed. Failing to load\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4103 | return -ENOMEM; |
| 4104 | } |
| 4105 | } else { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4106 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4107 | "BM_%d : HWI_MEM_SGLH is more than one element." |
| 4108 | "Failing to load\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4109 | return -ENOMEM; |
| 4110 | } |
| 4111 | |
| 4112 | arr_index = 0; |
| 4113 | idx = 0; |
| 4114 | while (idx < mem_descr_sglh->num_elements) { |
| 4115 | psgl_handle = mem_descr_sglh->mem_array[idx].virtual_address; |
| 4116 | |
| 4117 | for (i = 0; i < (mem_descr_sglh->mem_array[idx].size / |
| 4118 | sizeof(struct sgl_handle)); i++) { |
| 4119 | if (arr_index < phba->params.ios_per_ctrl) { |
| 4120 | phba->io_sgl_hndl_base[arr_index] = psgl_handle; |
| 4121 | phba->io_sgl_hndl_avbl++; |
| 4122 | arr_index++; |
| 4123 | } else { |
| 4124 | phba->eh_sgl_hndl_base[arr_index - |
| 4125 | phba->params.ios_per_ctrl] = |
| 4126 | psgl_handle; |
| 4127 | arr_index++; |
| 4128 | phba->eh_sgl_hndl_avbl++; |
| 4129 | } |
| 4130 | psgl_handle++; |
| 4131 | } |
| 4132 | idx++; |
| 4133 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4134 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 4135 | "BM_%d : phba->io_sgl_hndl_avbl=%d" |
| 4136 | "phba->eh_sgl_hndl_avbl=%d\n", |
| 4137 | phba->io_sgl_hndl_avbl, |
| 4138 | phba->eh_sgl_hndl_avbl); |
| 4139 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4140 | mem_descr_sg = phba->init_mem; |
| 4141 | mem_descr_sg += HWI_MEM_SGE; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4142 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 4143 | "\n BM_%d : mem_descr_sg->num_elements=%d\n", |
| 4144 | mem_descr_sg->num_elements); |
| 4145 | |
Jayamohan Kallickal | 90622db | 2013-09-28 15:35:47 -0700 | [diff] [blame] | 4146 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) |
| 4147 | if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) |
| 4148 | break; |
| 4149 | |
| 4150 | ulp_icd_start = phba->fw_config.iscsi_icd_start[ulp_num]; |
| 4151 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4152 | arr_index = 0; |
| 4153 | idx = 0; |
| 4154 | while (idx < mem_descr_sg->num_elements) { |
| 4155 | pfrag = mem_descr_sg->mem_array[idx].virtual_address; |
| 4156 | |
| 4157 | for (i = 0; |
| 4158 | i < (mem_descr_sg->mem_array[idx].size) / |
| 4159 | (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io); |
| 4160 | i++) { |
| 4161 | if (arr_index < phba->params.ios_per_ctrl) |
| 4162 | psgl_handle = phba->io_sgl_hndl_base[arr_index]; |
| 4163 | else |
| 4164 | psgl_handle = phba->eh_sgl_hndl_base[arr_index - |
| 4165 | phba->params.ios_per_ctrl]; |
| 4166 | psgl_handle->pfrag = pfrag; |
| 4167 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, pfrag, 0); |
| 4168 | AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, pfrag, 0); |
| 4169 | pfrag += phba->params.num_sge_per_io; |
Jayamohan Kallickal | 90622db | 2013-09-28 15:35:47 -0700 | [diff] [blame] | 4170 | psgl_handle->sgl_index = ulp_icd_start + arr_index++; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4171 | } |
| 4172 | idx++; |
| 4173 | } |
| 4174 | phba->io_sgl_free_index = 0; |
| 4175 | phba->io_sgl_alloc_index = 0; |
| 4176 | phba->eh_sgl_free_index = 0; |
| 4177 | phba->eh_sgl_alloc_index = 0; |
| 4178 | return 0; |
| 4179 | } |
| 4180 | |
| 4181 | static int hba_setup_cid_tbls(struct beiscsi_hba *phba) |
| 4182 | { |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4183 | int ret; |
| 4184 | uint16_t i, ulp_num; |
| 4185 | struct ulp_cid_info *ptr_cid_info = NULL; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4186 | |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4187 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 4188 | if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) { |
| 4189 | ptr_cid_info = kzalloc(sizeof(struct ulp_cid_info), |
| 4190 | GFP_KERNEL); |
| 4191 | |
| 4192 | if (!ptr_cid_info) { |
| 4193 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4194 | "BM_%d : Failed to allocate memory" |
| 4195 | "for ULP_CID_INFO for ULP : %d\n", |
| 4196 | ulp_num); |
| 4197 | ret = -ENOMEM; |
| 4198 | goto free_memory; |
| 4199 | |
| 4200 | } |
| 4201 | |
| 4202 | /* Allocate memory for CID array */ |
| 4203 | ptr_cid_info->cid_array = kzalloc(sizeof(void *) * |
| 4204 | BEISCSI_GET_CID_COUNT(phba, |
| 4205 | ulp_num), GFP_KERNEL); |
| 4206 | if (!ptr_cid_info->cid_array) { |
| 4207 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4208 | "BM_%d : Failed to allocate memory" |
| 4209 | "for CID_ARRAY for ULP : %d\n", |
| 4210 | ulp_num); |
| 4211 | kfree(ptr_cid_info); |
| 4212 | ptr_cid_info = NULL; |
| 4213 | ret = -ENOMEM; |
| 4214 | |
| 4215 | goto free_memory; |
| 4216 | } |
| 4217 | ptr_cid_info->avlbl_cids = BEISCSI_GET_CID_COUNT( |
| 4218 | phba, ulp_num); |
| 4219 | |
| 4220 | /* Save the cid_info_array ptr */ |
| 4221 | phba->cid_array_info[ulp_num] = ptr_cid_info; |
| 4222 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4223 | } |
Jayamohan Kallickal | c246228 | 2010-01-05 05:05:34 +0530 | [diff] [blame] | 4224 | phba->ep_array = kzalloc(sizeof(struct iscsi_endpoint *) * |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4225 | phba->params.cxns_per_ctrl, GFP_KERNEL); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4226 | if (!phba->ep_array) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4227 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4228 | "BM_%d : Failed to allocate memory in " |
| 4229 | "hba_setup_cid_tbls\n"); |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4230 | ret = -ENOMEM; |
| 4231 | |
| 4232 | goto free_memory; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4233 | } |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4234 | |
| 4235 | phba->conn_table = kzalloc(sizeof(struct beiscsi_conn *) * |
| 4236 | phba->params.cxns_per_ctrl, GFP_KERNEL); |
| 4237 | if (!phba->conn_table) { |
| 4238 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4239 | "BM_%d : Failed to allocate memory in" |
| 4240 | "hba_setup_cid_tbls\n"); |
| 4241 | |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4242 | kfree(phba->ep_array); |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4243 | phba->ep_array = NULL; |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4244 | ret = -ENOMEM; |
Tomas Henzl | 5f2d25e | 2014-06-06 14:06:30 +0200 | [diff] [blame] | 4245 | |
| 4246 | goto free_memory; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4247 | } |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4248 | |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4249 | for (i = 0; i < phba->params.cxns_per_ctrl; i++) { |
| 4250 | ulp_num = phba->phwi_ctrlr->wrb_context[i].ulp_num; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4251 | |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4252 | ptr_cid_info = phba->cid_array_info[ulp_num]; |
| 4253 | ptr_cid_info->cid_array[ptr_cid_info->cid_alloc++] = |
| 4254 | phba->phwi_ctrlr->wrb_context[i].cid; |
| 4255 | |
| 4256 | } |
| 4257 | |
| 4258 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 4259 | if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) { |
| 4260 | ptr_cid_info = phba->cid_array_info[ulp_num]; |
| 4261 | |
| 4262 | ptr_cid_info->cid_alloc = 0; |
| 4263 | ptr_cid_info->cid_free = 0; |
| 4264 | } |
| 4265 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4266 | return 0; |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4267 | |
| 4268 | free_memory: |
| 4269 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 4270 | if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) { |
| 4271 | ptr_cid_info = phba->cid_array_info[ulp_num]; |
| 4272 | |
| 4273 | if (ptr_cid_info) { |
| 4274 | kfree(ptr_cid_info->cid_array); |
| 4275 | kfree(ptr_cid_info); |
| 4276 | phba->cid_array_info[ulp_num] = NULL; |
| 4277 | } |
| 4278 | } |
| 4279 | } |
| 4280 | |
| 4281 | return ret; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4282 | } |
| 4283 | |
Jayamohan Kallickal | 238f6b7 | 2010-07-22 04:23:22 +0530 | [diff] [blame] | 4284 | static void hwi_enable_intr(struct beiscsi_hba *phba) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4285 | { |
| 4286 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 4287 | struct hwi_controller *phwi_ctrlr; |
| 4288 | struct hwi_context_memory *phwi_context; |
| 4289 | struct be_queue_info *eq; |
| 4290 | u8 __iomem *addr; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4291 | u32 reg, i; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4292 | u32 enabled; |
| 4293 | |
| 4294 | phwi_ctrlr = phba->phwi_ctrlr; |
| 4295 | phwi_context = phwi_ctrlr->phwi_ctxt; |
| 4296 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4297 | addr = (u8 __iomem *) ((u8 __iomem *) ctrl->pcicfg + |
| 4298 | PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET); |
| 4299 | reg = ioread32(addr); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4300 | |
| 4301 | enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
| 4302 | if (!enabled) { |
| 4303 | reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4304 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 4305 | "BM_%d : reg =x%08x addr=%p\n", reg, addr); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4306 | iowrite32(reg, addr); |
Jayamohan Kallickal | 665d6d9 | 2011-04-29 14:30:06 -0500 | [diff] [blame] | 4307 | } |
| 4308 | |
| 4309 | if (!phba->msix_enabled) { |
| 4310 | eq = &phwi_context->be_eq[0].q; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4311 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 4312 | "BM_%d : eq->id=%d\n", eq->id); |
| 4313 | |
Jayamohan Kallickal | 665d6d9 | 2011-04-29 14:30:06 -0500 | [diff] [blame] | 4314 | hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1); |
| 4315 | } else { |
| 4316 | for (i = 0; i <= phba->num_cpus; i++) { |
| 4317 | eq = &phwi_context->be_eq[i].q; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4318 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 4319 | "BM_%d : eq->id=%d\n", eq->id); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4320 | hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1); |
| 4321 | } |
Jayamohan Kallickal | c03af1a | 2010-02-20 08:05:43 +0530 | [diff] [blame] | 4322 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4323 | } |
| 4324 | |
| 4325 | static void hwi_disable_intr(struct beiscsi_hba *phba) |
| 4326 | { |
| 4327 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 4328 | |
| 4329 | u8 __iomem *addr = ctrl->pcicfg + PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET; |
| 4330 | u32 reg = ioread32(addr); |
| 4331 | |
| 4332 | u32 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
| 4333 | if (enabled) { |
| 4334 | reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK; |
| 4335 | iowrite32(reg, addr); |
| 4336 | } else |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4337 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT, |
| 4338 | "BM_%d : In hwi_disable_intr, Already Disabled\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4339 | } |
| 4340 | |
John Soni Jose | 9aef420 | 2012-08-20 23:00:08 +0530 | [diff] [blame] | 4341 | /** |
| 4342 | * beiscsi_get_boot_info()- Get the boot session info |
| 4343 | * @phba: The device priv structure instance |
| 4344 | * |
| 4345 | * Get the boot target info and store in driver priv structure |
| 4346 | * |
| 4347 | * return values |
| 4348 | * Success: 0 |
| 4349 | * Failure: Non-Zero Value |
| 4350 | **/ |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4351 | static int beiscsi_get_boot_info(struct beiscsi_hba *phba) |
| 4352 | { |
Mike Christie | 0e43895 | 2012-04-03 23:41:51 -0500 | [diff] [blame] | 4353 | struct be_cmd_get_session_resp *session_resp; |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4354 | struct be_dma_mem nonemb_cmd; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 4355 | unsigned int tag; |
John Soni Jose | 9aef420 | 2012-08-20 23:00:08 +0530 | [diff] [blame] | 4356 | unsigned int s_handle; |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 4357 | int ret = -ENOMEM; |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4358 | |
John Soni Jose | 9aef420 | 2012-08-20 23:00:08 +0530 | [diff] [blame] | 4359 | /* Get the session handle of the boot target */ |
| 4360 | ret = be_mgmt_get_boot_shandle(phba, &s_handle); |
| 4361 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4362 | beiscsi_log(phba, KERN_ERR, |
| 4363 | BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG, |
| 4364 | "BM_%d : No boot session\n"); |
John Soni Jose | 3efde86 | 2015-04-25 08:16:57 +0530 | [diff] [blame] | 4365 | |
| 4366 | if (ret == -ENXIO) |
| 4367 | phba->get_boot = 0; |
| 4368 | |
| 4369 | |
John Soni Jose | 9aef420 | 2012-08-20 23:00:08 +0530 | [diff] [blame] | 4370 | return ret; |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4371 | } |
John Soni Jose | 3efde86 | 2015-04-25 08:16:57 +0530 | [diff] [blame] | 4372 | phba->get_boot = 0; |
Joe Perches | 7c845eb | 2014-08-08 14:24:46 -0700 | [diff] [blame] | 4373 | nonemb_cmd.va = pci_zalloc_consistent(phba->ctrl.pdev, |
| 4374 | sizeof(*session_resp), |
| 4375 | &nonemb_cmd.dma); |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4376 | if (nonemb_cmd.va == NULL) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4377 | beiscsi_log(phba, KERN_ERR, |
| 4378 | BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG, |
| 4379 | "BM_%d : Failed to allocate memory for" |
| 4380 | "beiscsi_get_session_info\n"); |
| 4381 | |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4382 | return -ENOMEM; |
| 4383 | } |
| 4384 | |
John Soni Jose | 9aef420 | 2012-08-20 23:00:08 +0530 | [diff] [blame] | 4385 | tag = mgmt_get_session_info(phba, s_handle, |
Mike Christie | 0e43895 | 2012-04-03 23:41:51 -0500 | [diff] [blame] | 4386 | &nonemb_cmd); |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4387 | if (!tag) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4388 | beiscsi_log(phba, KERN_ERR, |
| 4389 | BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG, |
| 4390 | "BM_%d : beiscsi_get_session_info" |
| 4391 | " Failed\n"); |
| 4392 | |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4393 | goto boot_freemem; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 4394 | } |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4395 | |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 4396 | ret = beiscsi_mccq_compl(phba, tag, NULL, &nonemb_cmd); |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 4397 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4398 | beiscsi_log(phba, KERN_ERR, |
| 4399 | BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG, |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 4400 | "BM_%d : beiscsi_get_session_info Failed"); |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 4401 | |
| 4402 | if (ret != -EBUSY) |
| 4403 | goto boot_freemem; |
| 4404 | else |
| 4405 | return ret; |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4406 | } |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 4407 | |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4408 | session_resp = nonemb_cmd.va ; |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 4409 | |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4410 | memcpy(&phba->boot_sess, &session_resp->session_info, |
| 4411 | sizeof(struct mgmt_session_info)); |
John Soni Jose | 3f4134c | 2015-04-25 08:18:13 +0530 | [diff] [blame] | 4412 | |
| 4413 | beiscsi_logout_fw_sess(phba, |
| 4414 | phba->boot_sess.session_handle); |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 4415 | ret = 0; |
| 4416 | |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4417 | boot_freemem: |
| 4418 | pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size, |
| 4419 | nonemb_cmd.va, nonemb_cmd.dma); |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 4420 | return ret; |
| 4421 | } |
| 4422 | |
| 4423 | static void beiscsi_boot_release(void *data) |
| 4424 | { |
| 4425 | struct beiscsi_hba *phba = data; |
| 4426 | |
| 4427 | scsi_host_put(phba->shost); |
| 4428 | } |
| 4429 | |
| 4430 | static int beiscsi_setup_boot_info(struct beiscsi_hba *phba) |
| 4431 | { |
| 4432 | struct iscsi_boot_kobj *boot_kobj; |
| 4433 | |
Jayamohan Kallickal | a3d313e | 2014-08-08 01:00:00 -0400 | [diff] [blame] | 4434 | /* it has been created previously */ |
| 4435 | if (phba->boot_kset) |
| 4436 | return 0; |
| 4437 | |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 4438 | /* get boot info using mgmt cmd */ |
| 4439 | if (beiscsi_get_boot_info(phba)) |
| 4440 | /* Try to see if we can carry on without this */ |
| 4441 | return 0; |
| 4442 | |
| 4443 | phba->boot_kset = iscsi_boot_create_host_kset(phba->shost->host_no); |
| 4444 | if (!phba->boot_kset) |
| 4445 | return -ENOMEM; |
| 4446 | |
| 4447 | /* get a ref because the show function will ref the phba */ |
| 4448 | if (!scsi_host_get(phba->shost)) |
| 4449 | goto free_kset; |
| 4450 | boot_kobj = iscsi_boot_create_target(phba->boot_kset, 0, phba, |
| 4451 | beiscsi_show_boot_tgt_info, |
| 4452 | beiscsi_tgt_get_attr_visibility, |
| 4453 | beiscsi_boot_release); |
| 4454 | if (!boot_kobj) |
| 4455 | goto put_shost; |
| 4456 | |
| 4457 | if (!scsi_host_get(phba->shost)) |
| 4458 | goto free_kset; |
| 4459 | boot_kobj = iscsi_boot_create_initiator(phba->boot_kset, 0, phba, |
| 4460 | beiscsi_show_boot_ini_info, |
| 4461 | beiscsi_ini_get_attr_visibility, |
| 4462 | beiscsi_boot_release); |
| 4463 | if (!boot_kobj) |
| 4464 | goto put_shost; |
| 4465 | |
| 4466 | if (!scsi_host_get(phba->shost)) |
| 4467 | goto free_kset; |
| 4468 | boot_kobj = iscsi_boot_create_ethernet(phba->boot_kset, 0, phba, |
| 4469 | beiscsi_show_boot_eth_info, |
| 4470 | beiscsi_eth_get_attr_visibility, |
| 4471 | beiscsi_boot_release); |
| 4472 | if (!boot_kobj) |
| 4473 | goto put_shost; |
| 4474 | return 0; |
| 4475 | |
| 4476 | put_shost: |
| 4477 | scsi_host_put(phba->shost); |
| 4478 | free_kset: |
| 4479 | iscsi_boot_destroy_kset(phba->boot_kset); |
Jayamohan Kallickal | c7acc5b | 2010-07-22 04:29:18 +0530 | [diff] [blame] | 4480 | return -ENOMEM; |
| 4481 | } |
| 4482 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4483 | static int beiscsi_init_port(struct beiscsi_hba *phba) |
| 4484 | { |
| 4485 | int ret; |
| 4486 | |
| 4487 | ret = beiscsi_init_controller(phba); |
| 4488 | if (ret < 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4489 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4490 | "BM_%d : beiscsi_dev_probe - Failed in" |
| 4491 | "beiscsi_init_controller\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4492 | return ret; |
| 4493 | } |
| 4494 | ret = beiscsi_init_sgl_handle(phba); |
| 4495 | if (ret < 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4496 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4497 | "BM_%d : beiscsi_dev_probe - Failed in" |
| 4498 | "beiscsi_init_sgl_handle\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4499 | goto do_cleanup_ctrlr; |
| 4500 | } |
| 4501 | |
| 4502 | if (hba_setup_cid_tbls(phba)) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 4503 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 4504 | "BM_%d : Failed in hba_setup_cid_tbls\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4505 | kfree(phba->io_sgl_hndl_base); |
| 4506 | kfree(phba->eh_sgl_hndl_base); |
| 4507 | goto do_cleanup_ctrlr; |
| 4508 | } |
| 4509 | |
| 4510 | return ret; |
| 4511 | |
| 4512 | do_cleanup_ctrlr: |
| 4513 | hwi_cleanup(phba); |
| 4514 | return ret; |
| 4515 | } |
| 4516 | |
| 4517 | static void hwi_purge_eq(struct beiscsi_hba *phba) |
| 4518 | { |
| 4519 | struct hwi_controller *phwi_ctrlr; |
| 4520 | struct hwi_context_memory *phwi_context; |
| 4521 | struct be_queue_info *eq; |
| 4522 | struct be_eq_entry *eqe = NULL; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4523 | int i, eq_msix; |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 4524 | unsigned int num_processed; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4525 | |
| 4526 | phwi_ctrlr = phba->phwi_ctrlr; |
| 4527 | phwi_context = phwi_ctrlr->phwi_ctxt; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4528 | if (phba->msix_enabled) |
| 4529 | eq_msix = 1; |
| 4530 | else |
| 4531 | eq_msix = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4532 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4533 | for (i = 0; i < (phba->num_cpus + eq_msix); i++) { |
| 4534 | eq = &phwi_context->be_eq[i].q; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4535 | eqe = queue_tail_node(eq); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 4536 | num_processed = 0; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4537 | while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32] |
| 4538 | & EQE_VALID_MASK) { |
| 4539 | AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0); |
| 4540 | queue_tail_inc(eq); |
| 4541 | eqe = queue_tail_node(eq); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 4542 | num_processed++; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4543 | } |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 4544 | |
| 4545 | if (num_processed) |
| 4546 | hwi_ring_eq_db(phba, eq->id, 1, num_processed, 1, 1); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4547 | } |
| 4548 | } |
| 4549 | |
| 4550 | static void beiscsi_clean_port(struct beiscsi_hba *phba) |
| 4551 | { |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4552 | int mgmt_status, ulp_num; |
| 4553 | struct ulp_cid_info *ptr_cid_info = NULL; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4554 | |
Jayamohan Kallickal | bd41c2b | 2013-09-28 15:35:51 -0700 | [diff] [blame] | 4555 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 4556 | if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) { |
| 4557 | mgmt_status = mgmt_epfw_cleanup(phba, ulp_num); |
| 4558 | if (mgmt_status) |
| 4559 | beiscsi_log(phba, KERN_WARNING, |
| 4560 | BEISCSI_LOG_INIT, |
| 4561 | "BM_%d : mgmt_epfw_cleanup FAILED" |
| 4562 | " for ULP_%d\n", ulp_num); |
| 4563 | } |
| 4564 | } |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 4565 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4566 | hwi_purge_eq(phba); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 4567 | hwi_cleanup(phba); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4568 | kfree(phba->io_sgl_hndl_base); |
| 4569 | kfree(phba->eh_sgl_hndl_base); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4570 | kfree(phba->ep_array); |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4571 | kfree(phba->conn_table); |
Jayamohan Kallickal | 0a3db7c | 2013-09-28 15:35:49 -0700 | [diff] [blame] | 4572 | |
| 4573 | for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) { |
| 4574 | if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) { |
| 4575 | ptr_cid_info = phba->cid_array_info[ulp_num]; |
| 4576 | |
| 4577 | if (ptr_cid_info) { |
| 4578 | kfree(ptr_cid_info->cid_array); |
| 4579 | kfree(ptr_cid_info); |
| 4580 | phba->cid_array_info[ulp_num] = NULL; |
| 4581 | } |
| 4582 | } |
| 4583 | } |
| 4584 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4585 | } |
| 4586 | |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 4587 | /** |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4588 | * beiscsi_free_mgmt_task_handles()- Free driver CXN resources |
| 4589 | * @beiscsi_conn: ptr to the conn to be cleaned up |
Jayamohan Kallickal | 4a4a11b | 2013-04-05 20:38:31 -0700 | [diff] [blame] | 4590 | * @task: ptr to iscsi_task resource to be freed. |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4591 | * |
| 4592 | * Free driver mgmt resources binded to CXN. |
| 4593 | **/ |
| 4594 | void |
Jayamohan Kallickal | 4a4a11b | 2013-04-05 20:38:31 -0700 | [diff] [blame] | 4595 | beiscsi_free_mgmt_task_handles(struct beiscsi_conn *beiscsi_conn, |
| 4596 | struct iscsi_task *task) |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4597 | { |
| 4598 | struct beiscsi_io_task *io_task; |
| 4599 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 4600 | struct hwi_wrb_context *pwrb_context; |
| 4601 | struct hwi_controller *phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4602 | uint16_t cri_index = BE_GET_CRI_FROM_CID( |
| 4603 | beiscsi_conn->beiscsi_conn_cid); |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4604 | |
| 4605 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4606 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
| 4607 | |
Jayamohan Kallickal | 4a4a11b | 2013-04-05 20:38:31 -0700 | [diff] [blame] | 4608 | io_task = task->dd_data; |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4609 | |
| 4610 | if (io_task->pwrb_handle) { |
| 4611 | memset(io_task->pwrb_handle->pwrb, 0, |
| 4612 | sizeof(struct iscsi_wrb)); |
| 4613 | free_wrb_handle(phba, pwrb_context, |
| 4614 | io_task->pwrb_handle); |
| 4615 | io_task->pwrb_handle = NULL; |
| 4616 | } |
| 4617 | |
| 4618 | if (io_task->psgl_handle) { |
| 4619 | spin_lock_bh(&phba->mgmt_sgl_lock); |
| 4620 | free_mgmt_sgl_handle(phba, |
| 4621 | io_task->psgl_handle); |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4622 | io_task->psgl_handle = NULL; |
Jayamohan Kallickal | 4a4a11b | 2013-04-05 20:38:31 -0700 | [diff] [blame] | 4623 | spin_unlock_bh(&phba->mgmt_sgl_lock); |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4624 | } |
| 4625 | |
John Soni Jose | eb1c469 | 2015-04-25 08:17:45 +0530 | [diff] [blame] | 4626 | if (io_task->mtask_addr) { |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4627 | pci_unmap_single(phba->pcidev, |
| 4628 | io_task->mtask_addr, |
| 4629 | io_task->mtask_data_count, |
| 4630 | PCI_DMA_TODEVICE); |
John Soni Jose | eb1c469 | 2015-04-25 08:17:45 +0530 | [diff] [blame] | 4631 | io_task->mtask_addr = 0; |
| 4632 | } |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4633 | } |
| 4634 | |
| 4635 | /** |
John Soni Jose | d629c47 | 2012-10-20 04:42:00 +0530 | [diff] [blame] | 4636 | * beiscsi_cleanup_task()- Free driver resources of the task |
| 4637 | * @task: ptr to the iscsi task |
| 4638 | * |
| 4639 | **/ |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4640 | static void beiscsi_cleanup_task(struct iscsi_task *task) |
| 4641 | { |
| 4642 | struct beiscsi_io_task *io_task = task->dd_data; |
| 4643 | struct iscsi_conn *conn = task->conn; |
| 4644 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; |
| 4645 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 4646 | struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess; |
| 4647 | struct hwi_wrb_context *pwrb_context; |
| 4648 | struct hwi_controller *phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4649 | uint16_t cri_index = BE_GET_CRI_FROM_CID( |
| 4650 | beiscsi_conn->beiscsi_conn_cid); |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4651 | |
| 4652 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4653 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4654 | |
| 4655 | if (io_task->cmd_bhs) { |
| 4656 | pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs, |
| 4657 | io_task->bhs_pa.u.a64.address); |
| 4658 | io_task->cmd_bhs = NULL; |
| 4659 | } |
| 4660 | |
| 4661 | if (task->sc) { |
| 4662 | if (io_task->pwrb_handle) { |
| 4663 | free_wrb_handle(phba, pwrb_context, |
| 4664 | io_task->pwrb_handle); |
| 4665 | io_task->pwrb_handle = NULL; |
| 4666 | } |
| 4667 | |
| 4668 | if (io_task->psgl_handle) { |
| 4669 | spin_lock(&phba->io_sgl_lock); |
| 4670 | free_io_sgl_handle(phba, io_task->psgl_handle); |
| 4671 | spin_unlock(&phba->io_sgl_lock); |
| 4672 | io_task->psgl_handle = NULL; |
| 4673 | } |
Jayamohan Kallickal | da33497 | 2014-01-29 02:16:44 -0500 | [diff] [blame] | 4674 | |
| 4675 | if (io_task->scsi_cmnd) { |
| 4676 | scsi_dma_unmap(io_task->scsi_cmnd); |
| 4677 | io_task->scsi_cmnd = NULL; |
| 4678 | } |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4679 | } else { |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4680 | if (!beiscsi_conn->login_in_progress) |
Jayamohan Kallickal | 4a4a11b | 2013-04-05 20:38:31 -0700 | [diff] [blame] | 4681 | beiscsi_free_mgmt_task_handles(beiscsi_conn, task); |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4682 | } |
| 4683 | } |
| 4684 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4685 | void |
| 4686 | beiscsi_offload_connection(struct beiscsi_conn *beiscsi_conn, |
| 4687 | struct beiscsi_offload_params *params) |
| 4688 | { |
| 4689 | struct wrb_handle *pwrb_handle; |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4690 | struct hwi_wrb_context *pwrb_context = NULL; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4691 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4692 | struct iscsi_task *task = beiscsi_conn->task; |
| 4693 | struct iscsi_session *session = task->conn->session; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4694 | u32 doorbell = 0; |
| 4695 | |
| 4696 | /* |
| 4697 | * We can always use 0 here because it is reserved by libiscsi for |
| 4698 | * login/startup related tasks. |
| 4699 | */ |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4700 | beiscsi_conn->login_in_progress = 0; |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 4701 | spin_lock_bh(&session->back_lock); |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4702 | beiscsi_cleanup_task(task); |
Shlomo Pongratz | 659743b | 2014-02-07 00:41:38 -0600 | [diff] [blame] | 4703 | spin_unlock_bh(&session->back_lock); |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4704 | |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4705 | pwrb_handle = alloc_wrb_handle(phba, beiscsi_conn->beiscsi_conn_cid, |
| 4706 | &pwrb_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4707 | |
John Soni Jose | acb9693 | 2012-10-20 04:44:35 +0530 | [diff] [blame] | 4708 | /* Check for the adapter family */ |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 4709 | if (is_chip_be2_be3r(phba)) |
John Soni Jose | acb9693 | 2012-10-20 04:44:35 +0530 | [diff] [blame] | 4710 | beiscsi_offload_cxn_v0(params, pwrb_handle, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4711 | phba->init_mem, |
| 4712 | pwrb_context); |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 4713 | else |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4714 | beiscsi_offload_cxn_v2(params, pwrb_handle, |
| 4715 | pwrb_context); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4716 | |
John Soni Jose | acb9693 | 2012-10-20 04:44:35 +0530 | [diff] [blame] | 4717 | be_dws_le_to_cpu(pwrb_handle->pwrb, |
| 4718 | sizeof(struct iscsi_target_context_update_wrb)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4719 | |
| 4720 | doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK; |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 4721 | doorbell |= (pwrb_handle->wrb_index & DB_DEF_PDU_WRB_INDEX_MASK) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4722 | << DB_DEF_PDU_WRB_INDEX_SHIFT; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4723 | doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT; |
Jayamohan Kallickal | 1e4be6f | 2013-09-28 15:35:50 -0700 | [diff] [blame] | 4724 | iowrite32(doorbell, phba->db_va + |
| 4725 | beiscsi_conn->doorbell_offset); |
Jitendra Bhivare | cb564c6 | 2016-01-20 14:11:00 +0530 | [diff] [blame^] | 4726 | |
| 4727 | /* |
| 4728 | * There is no completion for CONTEXT_UPDATE. The completion of next |
| 4729 | * WRB posted guarantees FW's processing and DMA'ing of it. |
| 4730 | * Use beiscsi_put_wrb_handle to put it back in the pool which makes |
| 4731 | * sure zero'ing or reuse of the WRB only after wrbs_per_cxn. |
| 4732 | */ |
| 4733 | beiscsi_put_wrb_handle(pwrb_context, pwrb_handle, |
| 4734 | phba->params.wrbs_per_cxn); |
| 4735 | beiscsi_log(phba, KERN_INFO, |
| 4736 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
| 4737 | "BM_%d : put CONTEXT_UPDATE pwrb_handle=%p free_index=0x%x wrb_handles_available=%d\n", |
| 4738 | pwrb_handle, pwrb_context->free_index, |
| 4739 | pwrb_context->wrb_handles_available); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4740 | } |
| 4741 | |
| 4742 | static void beiscsi_parse_pdu(struct iscsi_conn *conn, itt_t itt, |
| 4743 | int *index, int *age) |
| 4744 | { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4745 | *index = (int)itt; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4746 | if (age) |
| 4747 | *age = conn->session->age; |
| 4748 | } |
| 4749 | |
| 4750 | /** |
| 4751 | * beiscsi_alloc_pdu - allocates pdu and related resources |
| 4752 | * @task: libiscsi task |
| 4753 | * @opcode: opcode of pdu for task |
| 4754 | * |
| 4755 | * This is called with the session lock held. It will allocate |
| 4756 | * the wrb and sgl if needed for the command. And it will prep |
| 4757 | * the pdu's itt. beiscsi_parse_pdu will later translate |
| 4758 | * the pdu itt to the libiscsi task itt. |
| 4759 | */ |
| 4760 | static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode) |
| 4761 | { |
| 4762 | struct beiscsi_io_task *io_task = task->dd_data; |
| 4763 | struct iscsi_conn *conn = task->conn; |
| 4764 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; |
| 4765 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 4766 | struct hwi_wrb_context *pwrb_context; |
| 4767 | struct hwi_controller *phwi_ctrlr; |
| 4768 | itt_t itt; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4769 | uint16_t cri_index = 0; |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4770 | struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess; |
| 4771 | dma_addr_t paddr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4772 | |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4773 | io_task->cmd_bhs = pci_pool_alloc(beiscsi_sess->bhs_pool, |
Mike Christie | bc7acce | 2010-12-31 02:22:19 -0600 | [diff] [blame] | 4774 | GFP_ATOMIC, &paddr); |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4775 | if (!io_task->cmd_bhs) |
| 4776 | return -ENOMEM; |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4777 | io_task->bhs_pa.u.a64.address = paddr; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4778 | io_task->libiscsi_itt = (itt_t)task->itt; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4779 | io_task->conn = beiscsi_conn; |
| 4780 | |
| 4781 | task->hdr = (struct iscsi_hdr *)&io_task->cmd_bhs->iscsi_hdr; |
| 4782 | task->hdr_max = sizeof(struct be_cmd_bhs); |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4783 | io_task->psgl_handle = NULL; |
Jayamohan Kallickal | 3ec7827 | 2012-04-03 23:41:38 -0500 | [diff] [blame] | 4784 | io_task->pwrb_handle = NULL; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4785 | |
| 4786 | if (task->sc) { |
| 4787 | spin_lock(&phba->io_sgl_lock); |
| 4788 | io_task->psgl_handle = alloc_io_sgl_handle(phba); |
| 4789 | spin_unlock(&phba->io_sgl_lock); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4790 | if (!io_task->psgl_handle) { |
| 4791 | beiscsi_log(phba, KERN_ERR, |
| 4792 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
| 4793 | "BM_%d : Alloc of IO_SGL_ICD Failed" |
| 4794 | "for the CID : %d\n", |
| 4795 | beiscsi_conn->beiscsi_conn_cid); |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4796 | goto free_hndls; |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4797 | } |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4798 | io_task->pwrb_handle = alloc_wrb_handle(phba, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4799 | beiscsi_conn->beiscsi_conn_cid, |
| 4800 | &io_task->pwrb_context); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4801 | if (!io_task->pwrb_handle) { |
| 4802 | beiscsi_log(phba, KERN_ERR, |
| 4803 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
| 4804 | "BM_%d : Alloc of WRB_HANDLE Failed" |
| 4805 | "for the CID : %d\n", |
| 4806 | beiscsi_conn->beiscsi_conn_cid); |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4807 | goto free_io_hndls; |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4808 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4809 | } else { |
| 4810 | io_task->scsi_cmnd = NULL; |
Jayamohan Kallickal | d7aea67 | 2010-01-05 05:08:39 +0530 | [diff] [blame] | 4811 | if ((opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN) { |
Jayamohan Kallickal | 43f388b | 2013-04-05 20:38:25 -0700 | [diff] [blame] | 4812 | beiscsi_conn->task = task; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4813 | if (!beiscsi_conn->login_in_progress) { |
| 4814 | spin_lock(&phba->mgmt_sgl_lock); |
| 4815 | io_task->psgl_handle = (struct sgl_handle *) |
| 4816 | alloc_mgmt_sgl_handle(phba); |
| 4817 | spin_unlock(&phba->mgmt_sgl_lock); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4818 | if (!io_task->psgl_handle) { |
| 4819 | beiscsi_log(phba, KERN_ERR, |
| 4820 | BEISCSI_LOG_IO | |
| 4821 | BEISCSI_LOG_CONFIG, |
| 4822 | "BM_%d : Alloc of MGMT_SGL_ICD Failed" |
| 4823 | "for the CID : %d\n", |
| 4824 | beiscsi_conn-> |
| 4825 | beiscsi_conn_cid); |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4826 | goto free_hndls; |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4827 | } |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4828 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4829 | beiscsi_conn->login_in_progress = 1; |
| 4830 | beiscsi_conn->plogin_sgl_handle = |
| 4831 | io_task->psgl_handle; |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4832 | io_task->pwrb_handle = |
| 4833 | alloc_wrb_handle(phba, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4834 | beiscsi_conn->beiscsi_conn_cid, |
| 4835 | &io_task->pwrb_context); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4836 | if (!io_task->pwrb_handle) { |
| 4837 | beiscsi_log(phba, KERN_ERR, |
| 4838 | BEISCSI_LOG_IO | |
| 4839 | BEISCSI_LOG_CONFIG, |
| 4840 | "BM_%d : Alloc of WRB_HANDLE Failed" |
| 4841 | "for the CID : %d\n", |
| 4842 | beiscsi_conn-> |
| 4843 | beiscsi_conn_cid); |
| 4844 | goto free_mgmt_hndls; |
| 4845 | } |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4846 | beiscsi_conn->plogin_wrb_handle = |
| 4847 | io_task->pwrb_handle; |
| 4848 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4849 | } else { |
| 4850 | io_task->psgl_handle = |
| 4851 | beiscsi_conn->plogin_sgl_handle; |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4852 | io_task->pwrb_handle = |
| 4853 | beiscsi_conn->plogin_wrb_handle; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4854 | } |
| 4855 | } else { |
| 4856 | spin_lock(&phba->mgmt_sgl_lock); |
| 4857 | io_task->psgl_handle = alloc_mgmt_sgl_handle(phba); |
| 4858 | spin_unlock(&phba->mgmt_sgl_lock); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4859 | if (!io_task->psgl_handle) { |
| 4860 | beiscsi_log(phba, KERN_ERR, |
| 4861 | BEISCSI_LOG_IO | |
| 4862 | BEISCSI_LOG_CONFIG, |
| 4863 | "BM_%d : Alloc of MGMT_SGL_ICD Failed" |
| 4864 | "for the CID : %d\n", |
| 4865 | beiscsi_conn-> |
| 4866 | beiscsi_conn_cid); |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4867 | goto free_hndls; |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4868 | } |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4869 | io_task->pwrb_handle = |
| 4870 | alloc_wrb_handle(phba, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4871 | beiscsi_conn->beiscsi_conn_cid, |
| 4872 | &io_task->pwrb_context); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4873 | if (!io_task->pwrb_handle) { |
| 4874 | beiscsi_log(phba, KERN_ERR, |
| 4875 | BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG, |
| 4876 | "BM_%d : Alloc of WRB_HANDLE Failed" |
| 4877 | "for the CID : %d\n", |
| 4878 | beiscsi_conn->beiscsi_conn_cid); |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4879 | goto free_mgmt_hndls; |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 4880 | } |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4881 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4882 | } |
| 4883 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4884 | itt = (itt_t) cpu_to_be32(((unsigned int)io_task->pwrb_handle-> |
| 4885 | wrb_index << 16) | (unsigned int) |
| 4886 | (io_task->psgl_handle->sgl_index)); |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 4887 | io_task->pwrb_handle->pio_handle = task; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 4888 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4889 | io_task->cmd_bhs->iscsi_hdr.itt = itt; |
| 4890 | return 0; |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4891 | |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4892 | free_io_hndls: |
| 4893 | spin_lock(&phba->io_sgl_lock); |
| 4894 | free_io_sgl_handle(phba, io_task->psgl_handle); |
| 4895 | spin_unlock(&phba->io_sgl_lock); |
| 4896 | goto free_hndls; |
| 4897 | free_mgmt_hndls: |
| 4898 | spin_lock(&phba->mgmt_sgl_lock); |
| 4899 | free_mgmt_sgl_handle(phba, io_task->psgl_handle); |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4900 | io_task->psgl_handle = NULL; |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4901 | spin_unlock(&phba->mgmt_sgl_lock); |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4902 | free_hndls: |
| 4903 | phwi_ctrlr = phba->phwi_ctrlr; |
Jayamohan Kallickal | a7909b3 | 2013-04-05 20:38:32 -0700 | [diff] [blame] | 4904 | cri_index = BE_GET_CRI_FROM_CID( |
| 4905 | beiscsi_conn->beiscsi_conn_cid); |
| 4906 | pwrb_context = &phwi_ctrlr->wrb_context[cri_index]; |
Jayamohan Kallickal | d2cecf0 | 2010-07-22 04:25:40 +0530 | [diff] [blame] | 4907 | if (io_task->pwrb_handle) |
| 4908 | free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle); |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4909 | io_task->pwrb_handle = NULL; |
| 4910 | pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs, |
| 4911 | io_task->bhs_pa.u.a64.address); |
Mike Christie | 1282ab7 | 2012-04-18 03:06:00 -0500 | [diff] [blame] | 4912 | io_task->cmd_bhs = NULL; |
Jayamohan Kallickal | 2afc95b | 2009-09-22 08:22:26 +0530 | [diff] [blame] | 4913 | return -ENOMEM; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4914 | } |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4915 | int beiscsi_iotask_v2(struct iscsi_task *task, struct scatterlist *sg, |
| 4916 | unsigned int num_sg, unsigned int xferlen, |
| 4917 | unsigned int writedir) |
| 4918 | { |
| 4919 | |
| 4920 | struct beiscsi_io_task *io_task = task->dd_data; |
| 4921 | struct iscsi_conn *conn = task->conn; |
| 4922 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; |
| 4923 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 4924 | struct iscsi_wrb *pwrb = NULL; |
| 4925 | unsigned int doorbell = 0; |
| 4926 | |
| 4927 | pwrb = io_task->pwrb_handle->pwrb; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4928 | |
| 4929 | io_task->cmd_bhs->iscsi_hdr.exp_statsn = 0; |
| 4930 | io_task->bhs_len = sizeof(struct be_cmd_bhs); |
| 4931 | |
| 4932 | if (writedir) { |
| 4933 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb, |
| 4934 | INI_WR_CMD); |
| 4935 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 1); |
| 4936 | } else { |
| 4937 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb, |
| 4938 | INI_RD_CMD); |
| 4939 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 0); |
| 4940 | } |
| 4941 | |
| 4942 | io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb_v2, |
| 4943 | type, pwrb); |
| 4944 | |
| 4945 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, lun, pwrb, |
| 4946 | cpu_to_be16(*(unsigned short *) |
| 4947 | &io_task->cmd_bhs->iscsi_hdr.lun)); |
| 4948 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb, xferlen); |
| 4949 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb, |
| 4950 | io_task->pwrb_handle->wrb_index); |
| 4951 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb, |
| 4952 | be32_to_cpu(task->cmdsn)); |
| 4953 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb, |
| 4954 | io_task->psgl_handle->sgl_index); |
| 4955 | |
| 4956 | hwi_write_sgl_v2(pwrb, sg, num_sg, io_task); |
| 4957 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 4958 | io_task->pwrb_handle->wrb_index); |
| 4959 | if (io_task->pwrb_context->plast_wrb) |
| 4960 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, |
| 4961 | io_task->pwrb_context->plast_wrb, |
| 4962 | io_task->pwrb_handle->wrb_index); |
| 4963 | io_task->pwrb_context->plast_wrb = pwrb; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4964 | |
| 4965 | be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb)); |
| 4966 | |
| 4967 | doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK; |
| 4968 | doorbell |= (io_task->pwrb_handle->wrb_index & |
| 4969 | DB_DEF_PDU_WRB_INDEX_MASK) << |
| 4970 | DB_DEF_PDU_WRB_INDEX_SHIFT; |
| 4971 | doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT; |
Jayamohan Kallickal | 1e4be6f | 2013-09-28 15:35:50 -0700 | [diff] [blame] | 4972 | iowrite32(doorbell, phba->db_va + |
| 4973 | beiscsi_conn->doorbell_offset); |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 4974 | return 0; |
| 4975 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4976 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4977 | static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg, |
| 4978 | unsigned int num_sg, unsigned int xferlen, |
| 4979 | unsigned int writedir) |
| 4980 | { |
| 4981 | |
| 4982 | struct beiscsi_io_task *io_task = task->dd_data; |
| 4983 | struct iscsi_conn *conn = task->conn; |
| 4984 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; |
| 4985 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 4986 | struct iscsi_wrb *pwrb = NULL; |
| 4987 | unsigned int doorbell = 0; |
| 4988 | |
| 4989 | pwrb = io_task->pwrb_handle->pwrb; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4990 | io_task->cmd_bhs->iscsi_hdr.exp_statsn = 0; |
| 4991 | io_task->bhs_len = sizeof(struct be_cmd_bhs); |
| 4992 | |
| 4993 | if (writedir) { |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 4994 | AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb, |
| 4995 | INI_WR_CMD); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4996 | AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 4997 | } else { |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 4998 | AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb, |
| 4999 | INI_RD_CMD); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5000 | AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0); |
| 5001 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5002 | |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5003 | io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb, |
| 5004 | type, pwrb); |
| 5005 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5006 | AMAP_SET_BITS(struct amap_iscsi_wrb, lun, pwrb, |
Jayamohan Kallickal | dc63aac | 2012-04-03 23:41:36 -0500 | [diff] [blame] | 5007 | cpu_to_be16(*(unsigned short *) |
| 5008 | &io_task->cmd_bhs->iscsi_hdr.lun)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5009 | AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, xferlen); |
| 5010 | AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb, |
| 5011 | io_task->pwrb_handle->wrb_index); |
| 5012 | AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, |
| 5013 | be32_to_cpu(task->cmdsn)); |
| 5014 | AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb, |
| 5015 | io_task->psgl_handle->sgl_index); |
| 5016 | |
| 5017 | hwi_write_sgl(pwrb, sg, num_sg, io_task); |
| 5018 | |
| 5019 | AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 5020 | io_task->pwrb_handle->wrb_index); |
| 5021 | if (io_task->pwrb_context->plast_wrb) |
| 5022 | AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, |
| 5023 | io_task->pwrb_context->plast_wrb, |
| 5024 | io_task->pwrb_handle->wrb_index); |
| 5025 | io_task->pwrb_context->plast_wrb = pwrb; |
| 5026 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5027 | be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb)); |
| 5028 | |
| 5029 | doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK; |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 5030 | doorbell |= (io_task->pwrb_handle->wrb_index & |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5031 | DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT; |
| 5032 | doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT; |
| 5033 | |
Jayamohan Kallickal | 1e4be6f | 2013-09-28 15:35:50 -0700 | [diff] [blame] | 5034 | iowrite32(doorbell, phba->db_va + |
| 5035 | beiscsi_conn->doorbell_offset); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5036 | return 0; |
| 5037 | } |
| 5038 | |
| 5039 | static int beiscsi_mtask(struct iscsi_task *task) |
| 5040 | { |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 5041 | struct beiscsi_io_task *io_task = task->dd_data; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5042 | struct iscsi_conn *conn = task->conn; |
| 5043 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; |
| 5044 | struct beiscsi_hba *phba = beiscsi_conn->phba; |
| 5045 | struct iscsi_wrb *pwrb = NULL; |
| 5046 | unsigned int doorbell = 0; |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 5047 | unsigned int cid; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5048 | unsigned int pwrb_typeoffset = 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5049 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5050 | cid = beiscsi_conn->beiscsi_conn_cid; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5051 | pwrb = io_task->pwrb_handle->pwrb; |
Jayamohan Kallickal | caf818f | 2010-01-23 05:38:18 +0530 | [diff] [blame] | 5052 | memset(pwrb, 0, sizeof(*pwrb)); |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5053 | |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 5054 | if (is_chip_be2_be3r(phba)) { |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5055 | AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, |
| 5056 | be32_to_cpu(task->cmdsn)); |
| 5057 | AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb, |
| 5058 | io_task->pwrb_handle->wrb_index); |
| 5059 | AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb, |
| 5060 | io_task->psgl_handle->sgl_index); |
| 5061 | AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, |
| 5062 | task->data_count); |
| 5063 | AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 5064 | io_task->pwrb_handle->wrb_index); |
| 5065 | if (io_task->pwrb_context->plast_wrb) |
| 5066 | AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, |
| 5067 | io_task->pwrb_context->plast_wrb, |
| 5068 | io_task->pwrb_handle->wrb_index); |
| 5069 | io_task->pwrb_context->plast_wrb = pwrb; |
| 5070 | |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5071 | pwrb_typeoffset = BE_WRB_TYPE_OFFSET; |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 5072 | } else { |
| 5073 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb, |
| 5074 | be32_to_cpu(task->cmdsn)); |
| 5075 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb, |
| 5076 | io_task->pwrb_handle->wrb_index); |
| 5077 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb, |
| 5078 | io_task->psgl_handle->sgl_index); |
| 5079 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb, |
| 5080 | task->data_count); |
| 5081 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb, |
John Soni Jose | 340c99e | 2015-08-20 04:44:30 +0530 | [diff] [blame] | 5082 | io_task->pwrb_handle->wrb_index); |
| 5083 | if (io_task->pwrb_context->plast_wrb) |
| 5084 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, |
| 5085 | io_task->pwrb_context->plast_wrb, |
| 5086 | io_task->pwrb_handle->wrb_index); |
| 5087 | io_task->pwrb_context->plast_wrb = pwrb; |
| 5088 | |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 5089 | pwrb_typeoffset = SKH_WRB_TYPE_OFFSET; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5090 | } |
| 5091 | |
Jayamohan Kallickal | dafab8e | 2010-02-20 08:03:56 +0530 | [diff] [blame] | 5092 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5093 | switch (task->hdr->opcode & ISCSI_OPCODE_MASK) { |
| 5094 | case ISCSI_OP_LOGIN: |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5095 | AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, 1); |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5096 | ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5097 | hwi_write_buffer(pwrb, task); |
| 5098 | break; |
| 5099 | case ISCSI_OP_NOOP_OUT: |
Jayamohan Kallickal | 1390b01 | 2011-03-25 14:24:01 -0700 | [diff] [blame] | 5100 | if (task->hdr->ttt != ISCSI_RESERVED_TAG) { |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5101 | ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset); |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 5102 | if (is_chip_be2_be3r(phba)) |
| 5103 | AMAP_SET_BITS(struct amap_iscsi_wrb, |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5104 | dmsg, pwrb, 1); |
| 5105 | else |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 5106 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5107 | dmsg, pwrb, 1); |
Jayamohan Kallickal | 1390b01 | 2011-03-25 14:24:01 -0700 | [diff] [blame] | 5108 | } else { |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5109 | ADAPTER_SET_WRB_TYPE(pwrb, INI_RD_CMD, pwrb_typeoffset); |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 5110 | if (is_chip_be2_be3r(phba)) |
| 5111 | AMAP_SET_BITS(struct amap_iscsi_wrb, |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5112 | dmsg, pwrb, 0); |
| 5113 | else |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 5114 | AMAP_SET_BITS(struct amap_iscsi_wrb_v2, |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5115 | dmsg, pwrb, 0); |
Jayamohan Kallickal | 1390b01 | 2011-03-25 14:24:01 -0700 | [diff] [blame] | 5116 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5117 | hwi_write_buffer(pwrb, task); |
| 5118 | break; |
| 5119 | case ISCSI_OP_TEXT: |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5120 | ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5121 | hwi_write_buffer(pwrb, task); |
| 5122 | break; |
| 5123 | case ISCSI_OP_SCSI_TMFUNC: |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5124 | ADAPTER_SET_WRB_TYPE(pwrb, INI_TMF_CMD, pwrb_typeoffset); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5125 | hwi_write_buffer(pwrb, task); |
| 5126 | break; |
| 5127 | case ISCSI_OP_LOGOUT: |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5128 | ADAPTER_SET_WRB_TYPE(pwrb, HWH_TYPE_LOGOUT, pwrb_typeoffset); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5129 | hwi_write_buffer(pwrb, task); |
| 5130 | break; |
| 5131 | |
| 5132 | default: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5133 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
| 5134 | "BM_%d : opcode =%d Not supported\n", |
| 5135 | task->hdr->opcode & ISCSI_OPCODE_MASK); |
| 5136 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5137 | return -EINVAL; |
| 5138 | } |
| 5139 | |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5140 | /* Set the task type */ |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 5141 | io_task->wrb_type = (is_chip_be2_be3r(phba)) ? |
| 5142 | AMAP_GET_BITS(struct amap_iscsi_wrb, type, pwrb) : |
| 5143 | AMAP_GET_BITS(struct amap_iscsi_wrb_v2, type, pwrb); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5144 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5145 | doorbell |= cid & DB_WRB_POST_CID_MASK; |
Jayamohan Kallickal | 32951dd | 2010-01-23 05:34:24 +0530 | [diff] [blame] | 5146 | doorbell |= (io_task->pwrb_handle->wrb_index & |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5147 | DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT; |
| 5148 | doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT; |
Jayamohan Kallickal | 1e4be6f | 2013-09-28 15:35:50 -0700 | [diff] [blame] | 5149 | iowrite32(doorbell, phba->db_va + |
| 5150 | beiscsi_conn->doorbell_offset); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5151 | return 0; |
| 5152 | } |
| 5153 | |
| 5154 | static int beiscsi_task_xmit(struct iscsi_task *task) |
| 5155 | { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5156 | struct beiscsi_io_task *io_task = task->dd_data; |
| 5157 | struct scsi_cmnd *sc = task->sc; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5158 | struct beiscsi_hba *phba = NULL; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5159 | struct scatterlist *sg; |
| 5160 | int num_sg; |
| 5161 | unsigned int writedir = 0, xferlen = 0; |
| 5162 | |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5163 | phba = ((struct beiscsi_conn *)task->conn->dd_data)->phba; |
| 5164 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5165 | if (!sc) |
| 5166 | return beiscsi_mtask(task); |
| 5167 | |
| 5168 | io_task->scsi_cmnd = sc; |
| 5169 | num_sg = scsi_dma_map(sc); |
| 5170 | if (num_sg < 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5171 | struct iscsi_conn *conn = task->conn; |
| 5172 | struct beiscsi_hba *phba = NULL; |
| 5173 | |
| 5174 | phba = ((struct beiscsi_conn *)conn->dd_data)->phba; |
Jayamohan Kallickal | afb9605 | 2013-09-28 15:35:55 -0700 | [diff] [blame] | 5175 | beiscsi_log(phba, KERN_ERR, |
| 5176 | BEISCSI_LOG_IO | BEISCSI_LOG_ISCSI, |
| 5177 | "BM_%d : scsi_dma_map Failed " |
| 5178 | "Driver_ITT : 0x%x ITT : 0x%x Xferlen : 0x%x\n", |
| 5179 | be32_to_cpu(io_task->cmd_bhs->iscsi_hdr.itt), |
| 5180 | io_task->libiscsi_itt, scsi_bufflen(sc)); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5181 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5182 | return num_sg; |
| 5183 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5184 | xferlen = scsi_bufflen(sc); |
| 5185 | sg = scsi_sglist(sc); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5186 | if (sc->sc_data_direction == DMA_TO_DEVICE) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5187 | writedir = 1; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5188 | else |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5189 | writedir = 0; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5190 | |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5191 | return phba->iotask_fn(task, sg, num_sg, xferlen, writedir); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5192 | } |
| 5193 | |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 5194 | /** |
| 5195 | * beiscsi_bsg_request - handle bsg request from ISCSI transport |
| 5196 | * @job: job to handle |
| 5197 | */ |
| 5198 | static int beiscsi_bsg_request(struct bsg_job *job) |
| 5199 | { |
| 5200 | struct Scsi_Host *shost; |
| 5201 | struct beiscsi_hba *phba; |
| 5202 | struct iscsi_bsg_request *bsg_req = job->request; |
| 5203 | int rc = -EINVAL; |
| 5204 | unsigned int tag; |
| 5205 | struct be_dma_mem nonemb_cmd; |
| 5206 | struct be_cmd_resp_hdr *resp; |
| 5207 | struct iscsi_bsg_reply *bsg_reply = job->reply; |
| 5208 | unsigned short status, extd_status; |
| 5209 | |
| 5210 | shost = iscsi_job_to_shost(job); |
| 5211 | phba = iscsi_host_priv(shost); |
| 5212 | |
| 5213 | switch (bsg_req->msgcode) { |
| 5214 | case ISCSI_BSG_HST_VENDOR: |
| 5215 | nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev, |
| 5216 | job->request_payload.payload_len, |
| 5217 | &nonemb_cmd.dma); |
| 5218 | if (nonemb_cmd.va == NULL) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5219 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
| 5220 | "BM_%d : Failed to allocate memory for " |
| 5221 | "beiscsi_bsg_request\n"); |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 5222 | return -ENOMEM; |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 5223 | } |
| 5224 | tag = mgmt_vendor_specific_fw_cmd(&phba->ctrl, phba, job, |
| 5225 | &nonemb_cmd); |
| 5226 | if (!tag) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5227 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 5228 | "BM_%d : MBX Tag Allocation Failed\n"); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5229 | |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 5230 | pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size, |
| 5231 | nonemb_cmd.va, nonemb_cmd.dma); |
| 5232 | return -EAGAIN; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 5233 | } |
| 5234 | |
| 5235 | rc = wait_event_interruptible_timeout( |
| 5236 | phba->ctrl.mcc_wait[tag], |
| 5237 | phba->ctrl.mcc_numtag[tag], |
| 5238 | msecs_to_jiffies( |
| 5239 | BEISCSI_HOST_MBX_TIMEOUT)); |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 5240 | extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8; |
| 5241 | status = phba->ctrl.mcc_numtag[tag] & 0x000000FF; |
| 5242 | free_mcc_tag(&phba->ctrl, tag); |
| 5243 | resp = (struct be_cmd_resp_hdr *)nonemb_cmd.va; |
| 5244 | sg_copy_from_buffer(job->reply_payload.sg_list, |
| 5245 | job->reply_payload.sg_cnt, |
| 5246 | nonemb_cmd.va, (resp->response_length |
| 5247 | + sizeof(*resp))); |
| 5248 | bsg_reply->reply_payload_rcv_len = resp->response_length; |
| 5249 | bsg_reply->result = status; |
| 5250 | bsg_job_done(job, bsg_reply->result, |
| 5251 | bsg_reply->reply_payload_rcv_len); |
| 5252 | pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size, |
| 5253 | nonemb_cmd.va, nonemb_cmd.dma); |
| 5254 | if (status || extd_status) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5255 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 5256 | "BM_%d : MBX Cmd Failed" |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5257 | " status = %d extd_status = %d\n", |
| 5258 | status, extd_status); |
| 5259 | |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 5260 | return -EIO; |
John Soni Jose | 8359c79 | 2012-10-20 04:43:03 +0530 | [diff] [blame] | 5261 | } else { |
| 5262 | rc = 0; |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 5263 | } |
| 5264 | break; |
| 5265 | |
| 5266 | default: |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5267 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
| 5268 | "BM_%d : Unsupported bsg command: 0x%x\n", |
| 5269 | bsg_req->msgcode); |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 5270 | break; |
| 5271 | } |
| 5272 | |
| 5273 | return rc; |
| 5274 | } |
| 5275 | |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5276 | void beiscsi_hba_attrs_init(struct beiscsi_hba *phba) |
| 5277 | { |
| 5278 | /* Set the logging parameter */ |
| 5279 | beiscsi_log_enable_init(phba, beiscsi_log_enable); |
| 5280 | } |
| 5281 | |
John Soni Jose | 4d4d1ef | 2012-10-20 04:42:37 +0530 | [diff] [blame] | 5282 | /* |
| 5283 | * beiscsi_quiesce()- Cleanup Driver resources |
| 5284 | * @phba: Instance Priv structure |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5285 | * @unload_state:i Clean or EEH unload state |
John Soni Jose | 4d4d1ef | 2012-10-20 04:42:37 +0530 | [diff] [blame] | 5286 | * |
| 5287 | * Free the OS and HW resources held by the driver |
| 5288 | **/ |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5289 | static void beiscsi_quiesce(struct beiscsi_hba *phba, |
| 5290 | uint32_t unload_state) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5291 | { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5292 | struct hwi_controller *phwi_ctrlr; |
| 5293 | struct hwi_context_memory *phwi_context; |
| 5294 | struct be_eq_obj *pbe_eq; |
| 5295 | unsigned int i, msix_vec; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5296 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5297 | phwi_ctrlr = phba->phwi_ctrlr; |
| 5298 | phwi_context = phwi_ctrlr->phwi_ctxt; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5299 | hwi_disable_intr(phba); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5300 | if (phba->msix_enabled) { |
| 5301 | for (i = 0; i <= phba->num_cpus; i++) { |
| 5302 | msix_vec = phba->msix_entries[i].vector; |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5303 | synchronize_irq(msix_vec); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5304 | free_irq(msix_vec, &phwi_context->be_eq[i]); |
Jayamohan Kallickal | 8fcfb21 | 2011-08-24 16:05:30 -0700 | [diff] [blame] | 5305 | kfree(phba->msi_name[i]); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5306 | } |
| 5307 | } else |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5308 | if (phba->pcidev->irq) { |
| 5309 | synchronize_irq(phba->pcidev->irq); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5310 | free_irq(phba->pcidev->irq, phba); |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5311 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5312 | pci_disable_msix(phba->pcidev); |
John Soni Jose | 53281ed | 2014-09-26 15:13:55 -0400 | [diff] [blame] | 5313 | cancel_delayed_work_sync(&phba->beiscsi_hw_check_task); |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5314 | |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5315 | for (i = 0; i < phba->num_cpus; i++) { |
| 5316 | pbe_eq = &phwi_context->be_eq[i]; |
Christoph Hellwig | 511cbce | 2015-11-10 14:56:14 +0100 | [diff] [blame] | 5317 | irq_poll_disable(&pbe_eq->iopoll); |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5318 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5319 | |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5320 | if (unload_state == BEISCSI_CLEAN_UNLOAD) { |
| 5321 | destroy_workqueue(phba->wq); |
| 5322 | beiscsi_clean_port(phba); |
| 5323 | beiscsi_free_mem(phba); |
Jayamohan Kallickal | e9b9119 | 2010-07-22 04:24:53 +0530 | [diff] [blame] | 5324 | |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5325 | beiscsi_unmap_pci_function(phba); |
| 5326 | pci_free_consistent(phba->pcidev, |
| 5327 | phba->ctrl.mbox_mem_alloced.size, |
| 5328 | phba->ctrl.mbox_mem_alloced.va, |
| 5329 | phba->ctrl.mbox_mem_alloced.dma); |
| 5330 | } else { |
| 5331 | hwi_purge_eq(phba); |
| 5332 | hwi_cleanup(phba); |
| 5333 | } |
John Soni Jose | 7a15800 | 2012-10-20 04:45:51 +0530 | [diff] [blame] | 5334 | |
Jayamohan Kallickal | 25602c9 | 2011-08-22 10:08:28 -0700 | [diff] [blame] | 5335 | } |
| 5336 | |
| 5337 | static void beiscsi_remove(struct pci_dev *pcidev) |
| 5338 | { |
Jayamohan Kallickal | 25602c9 | 2011-08-22 10:08:28 -0700 | [diff] [blame] | 5339 | struct beiscsi_hba *phba = NULL; |
| 5340 | |
| 5341 | phba = pci_get_drvdata(pcidev); |
| 5342 | if (!phba) { |
| 5343 | dev_err(&pcidev->dev, "beiscsi_remove called with no phba\n"); |
| 5344 | return; |
| 5345 | } |
| 5346 | |
Mike Christie | 0e43895 | 2012-04-03 23:41:51 -0500 | [diff] [blame] | 5347 | beiscsi_destroy_def_ifaces(phba); |
Mike Christie | 9d04516 | 2011-06-24 15:11:52 -0500 | [diff] [blame] | 5348 | iscsi_boot_destroy_kset(phba->boot_kset); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5349 | iscsi_host_remove(phba->shost); |
Jitendra Bhivare | cdaa4de | 2016-01-20 14:10:51 +0530 | [diff] [blame] | 5350 | beiscsi_quiesce(phba, BEISCSI_CLEAN_UNLOAD); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5351 | pci_dev_put(phba->pcidev); |
| 5352 | iscsi_host_free(phba->shost); |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5353 | pci_disable_pcie_error_reporting(pcidev); |
| 5354 | pci_set_drvdata(pcidev, NULL); |
John Soni Jose | e307f3a | 2015-04-25 08:17:19 +0530 | [diff] [blame] | 5355 | pci_release_regions(pcidev); |
Jayamohan Kallickal | 8dce69f | 2011-08-22 10:08:29 -0700 | [diff] [blame] | 5356 | pci_disable_device(pcidev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5357 | } |
| 5358 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5359 | static void beiscsi_msix_enable(struct beiscsi_hba *phba) |
| 5360 | { |
| 5361 | int i, status; |
| 5362 | |
| 5363 | for (i = 0; i <= phba->num_cpus; i++) |
| 5364 | phba->msix_entries[i].entry = i; |
| 5365 | |
Alexander Gordeev | e149fc1 | 2014-08-18 08:01:48 +0200 | [diff] [blame] | 5366 | status = pci_enable_msix_range(phba->pcidev, phba->msix_entries, |
| 5367 | phba->num_cpus + 1, phba->num_cpus + 1); |
| 5368 | if (status > 0) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5369 | phba->msix_enabled = true; |
| 5370 | |
| 5371 | return; |
| 5372 | } |
| 5373 | |
Jayamohan Kallickal | 73af08e | 2014-05-05 21:41:26 -0400 | [diff] [blame] | 5374 | static void be_eqd_update(struct beiscsi_hba *phba) |
| 5375 | { |
| 5376 | struct be_set_eqd set_eqd[MAX_CPUS]; |
| 5377 | struct be_aic_obj *aic; |
| 5378 | struct be_eq_obj *pbe_eq; |
| 5379 | struct hwi_controller *phwi_ctrlr; |
| 5380 | struct hwi_context_memory *phwi_context; |
| 5381 | int eqd, i, num = 0; |
| 5382 | ulong now; |
| 5383 | u32 pps, delta; |
| 5384 | unsigned int tag; |
| 5385 | |
| 5386 | phwi_ctrlr = phba->phwi_ctrlr; |
| 5387 | phwi_context = phwi_ctrlr->phwi_ctxt; |
| 5388 | |
| 5389 | for (i = 0; i <= phba->num_cpus; i++) { |
| 5390 | aic = &phba->aic_obj[i]; |
| 5391 | pbe_eq = &phwi_context->be_eq[i]; |
| 5392 | now = jiffies; |
| 5393 | if (!aic->jiffs || time_before(now, aic->jiffs) || |
| 5394 | pbe_eq->cq_count < aic->eq_prev) { |
| 5395 | aic->jiffs = now; |
| 5396 | aic->eq_prev = pbe_eq->cq_count; |
| 5397 | continue; |
| 5398 | } |
| 5399 | delta = jiffies_to_msecs(now - aic->jiffs); |
| 5400 | pps = (((u32)(pbe_eq->cq_count - aic->eq_prev) * 1000) / delta); |
| 5401 | eqd = (pps / 1500) << 2; |
| 5402 | |
| 5403 | if (eqd < 8) |
| 5404 | eqd = 0; |
| 5405 | eqd = min_t(u32, eqd, phwi_context->max_eqd); |
| 5406 | eqd = max_t(u32, eqd, phwi_context->min_eqd); |
| 5407 | |
| 5408 | aic->jiffs = now; |
| 5409 | aic->eq_prev = pbe_eq->cq_count; |
| 5410 | |
| 5411 | if (eqd != aic->prev_eqd) { |
| 5412 | set_eqd[num].delay_multiplier = (eqd * 65)/100; |
| 5413 | set_eqd[num].eq_id = pbe_eq->q.id; |
| 5414 | aic->prev_eqd = eqd; |
| 5415 | num++; |
| 5416 | } |
| 5417 | } |
| 5418 | if (num) { |
| 5419 | tag = be_cmd_modify_eq_delay(phba, set_eqd, num); |
| 5420 | if (tag) |
| 5421 | beiscsi_mccq_compl(phba, tag, NULL, NULL); |
| 5422 | } |
| 5423 | } |
| 5424 | |
Jayamohan Kallickal | a3d313e | 2014-08-08 01:00:00 -0400 | [diff] [blame] | 5425 | static void be_check_boot_session(struct beiscsi_hba *phba) |
| 5426 | { |
| 5427 | if (beiscsi_setup_boot_info(phba)) |
| 5428 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5429 | "BM_%d : Could not set up " |
| 5430 | "iSCSI boot info on async event.\n"); |
| 5431 | } |
| 5432 | |
John Soni Jose | 7a15800 | 2012-10-20 04:45:51 +0530 | [diff] [blame] | 5433 | /* |
| 5434 | * beiscsi_hw_health_check()- Check adapter health |
| 5435 | * @work: work item to check HW health |
| 5436 | * |
| 5437 | * Check if adapter in an unrecoverable state or not. |
| 5438 | **/ |
| 5439 | static void |
| 5440 | beiscsi_hw_health_check(struct work_struct *work) |
| 5441 | { |
| 5442 | struct beiscsi_hba *phba = |
| 5443 | container_of(work, struct beiscsi_hba, |
| 5444 | beiscsi_hw_check_task.work); |
| 5445 | |
Jayamohan Kallickal | 73af08e | 2014-05-05 21:41:26 -0400 | [diff] [blame] | 5446 | be_eqd_update(phba); |
| 5447 | |
Jayamohan Kallickal | a3d313e | 2014-08-08 01:00:00 -0400 | [diff] [blame] | 5448 | if (phba->state & BE_ADAPTER_CHECK_BOOT) { |
John Soni Jose | 3efde86 | 2015-04-25 08:16:57 +0530 | [diff] [blame] | 5449 | if ((phba->get_boot > 0) && (!phba->boot_kset)) { |
| 5450 | phba->get_boot--; |
| 5451 | if (!(phba->get_boot % BE_GET_BOOT_TO)) |
| 5452 | be_check_boot_session(phba); |
| 5453 | } else { |
| 5454 | phba->state &= ~BE_ADAPTER_CHECK_BOOT; |
| 5455 | phba->get_boot = 0; |
| 5456 | } |
Jayamohan Kallickal | a3d313e | 2014-08-08 01:00:00 -0400 | [diff] [blame] | 5457 | } |
| 5458 | |
John Soni Jose | 7a15800 | 2012-10-20 04:45:51 +0530 | [diff] [blame] | 5459 | beiscsi_ue_detect(phba); |
| 5460 | |
| 5461 | schedule_delayed_work(&phba->beiscsi_hw_check_task, |
| 5462 | msecs_to_jiffies(1000)); |
| 5463 | } |
| 5464 | |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5465 | |
| 5466 | static pci_ers_result_t beiscsi_eeh_err_detected(struct pci_dev *pdev, |
| 5467 | pci_channel_state_t state) |
| 5468 | { |
| 5469 | struct beiscsi_hba *phba = NULL; |
| 5470 | |
| 5471 | phba = (struct beiscsi_hba *)pci_get_drvdata(pdev); |
| 5472 | phba->state |= BE_ADAPTER_PCI_ERR; |
| 5473 | |
| 5474 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5475 | "BM_%d : EEH error detected\n"); |
| 5476 | |
| 5477 | beiscsi_quiesce(phba, BEISCSI_EEH_UNLOAD); |
| 5478 | |
| 5479 | if (state == pci_channel_io_perm_failure) { |
| 5480 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5481 | "BM_%d : EEH : State PERM Failure"); |
| 5482 | return PCI_ERS_RESULT_DISCONNECT; |
| 5483 | } |
| 5484 | |
| 5485 | pci_disable_device(pdev); |
| 5486 | |
| 5487 | /* The error could cause the FW to trigger a flash debug dump. |
| 5488 | * Resetting the card while flash dump is in progress |
| 5489 | * can cause it not to recover; wait for it to finish. |
| 5490 | * Wait only for first function as it is needed only once per |
| 5491 | * adapter. |
| 5492 | **/ |
| 5493 | if (pdev->devfn == 0) |
| 5494 | ssleep(30); |
| 5495 | |
| 5496 | return PCI_ERS_RESULT_NEED_RESET; |
| 5497 | } |
| 5498 | |
| 5499 | static pci_ers_result_t beiscsi_eeh_reset(struct pci_dev *pdev) |
| 5500 | { |
| 5501 | struct beiscsi_hba *phba = NULL; |
| 5502 | int status = 0; |
| 5503 | |
| 5504 | phba = (struct beiscsi_hba *)pci_get_drvdata(pdev); |
| 5505 | |
| 5506 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5507 | "BM_%d : EEH Reset\n"); |
| 5508 | |
| 5509 | status = pci_enable_device(pdev); |
| 5510 | if (status) |
| 5511 | return PCI_ERS_RESULT_DISCONNECT; |
| 5512 | |
| 5513 | pci_set_master(pdev); |
| 5514 | pci_set_power_state(pdev, PCI_D0); |
| 5515 | pci_restore_state(pdev); |
| 5516 | |
| 5517 | /* Wait for the CHIP Reset to complete */ |
| 5518 | status = be_chk_reset_complete(phba); |
| 5519 | if (!status) { |
| 5520 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT, |
| 5521 | "BM_%d : EEH Reset Completed\n"); |
| 5522 | } else { |
| 5523 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT, |
| 5524 | "BM_%d : EEH Reset Completion Failure\n"); |
| 5525 | return PCI_ERS_RESULT_DISCONNECT; |
| 5526 | } |
| 5527 | |
| 5528 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 5529 | return PCI_ERS_RESULT_RECOVERED; |
| 5530 | } |
| 5531 | |
| 5532 | static void beiscsi_eeh_resume(struct pci_dev *pdev) |
| 5533 | { |
| 5534 | int ret = 0, i; |
| 5535 | struct be_eq_obj *pbe_eq; |
| 5536 | struct beiscsi_hba *phba = NULL; |
| 5537 | struct hwi_controller *phwi_ctrlr; |
| 5538 | struct hwi_context_memory *phwi_context; |
| 5539 | |
| 5540 | phba = (struct beiscsi_hba *)pci_get_drvdata(pdev); |
| 5541 | pci_save_state(pdev); |
| 5542 | |
| 5543 | if (enable_msix) |
| 5544 | find_num_cpus(phba); |
| 5545 | else |
| 5546 | phba->num_cpus = 1; |
| 5547 | |
| 5548 | if (enable_msix) { |
| 5549 | beiscsi_msix_enable(phba); |
| 5550 | if (!phba->msix_enabled) |
| 5551 | phba->num_cpus = 1; |
| 5552 | } |
| 5553 | |
| 5554 | ret = beiscsi_cmd_reset_function(phba); |
| 5555 | if (ret) { |
| 5556 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5557 | "BM_%d : Reset Failed\n"); |
| 5558 | goto ret_err; |
| 5559 | } |
| 5560 | |
| 5561 | ret = be_chk_reset_complete(phba); |
| 5562 | if (ret) { |
| 5563 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5564 | "BM_%d : Failed to get out of reset.\n"); |
| 5565 | goto ret_err; |
| 5566 | } |
| 5567 | |
| 5568 | beiscsi_get_params(phba); |
| 5569 | phba->shost->max_id = phba->params.cxns_per_ctrl; |
| 5570 | phba->shost->can_queue = phba->params.ios_per_ctrl; |
| 5571 | ret = hwi_init_controller(phba); |
| 5572 | |
| 5573 | for (i = 0; i < MAX_MCC_CMD; i++) { |
| 5574 | init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]); |
| 5575 | phba->ctrl.mcc_tag[i] = i + 1; |
| 5576 | phba->ctrl.mcc_numtag[i + 1] = 0; |
| 5577 | phba->ctrl.mcc_tag_available++; |
| 5578 | } |
| 5579 | |
| 5580 | phwi_ctrlr = phba->phwi_ctrlr; |
| 5581 | phwi_context = phwi_ctrlr->phwi_ctxt; |
| 5582 | |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5583 | for (i = 0; i < phba->num_cpus; i++) { |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5584 | pbe_eq = &phwi_context->be_eq[i]; |
Christoph Hellwig | 511cbce | 2015-11-10 14:56:14 +0100 | [diff] [blame] | 5585 | irq_poll_init(&pbe_eq->iopoll, be_iopoll_budget, |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5586 | be_iopoll); |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5587 | } |
| 5588 | |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5589 | i = (phba->msix_enabled) ? i : 0; |
| 5590 | /* Work item for MCC handling */ |
| 5591 | pbe_eq = &phwi_context->be_eq[i]; |
| 5592 | INIT_WORK(&pbe_eq->work_cqs, beiscsi_process_all_cqs); |
| 5593 | |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5594 | ret = beiscsi_init_irqs(phba); |
| 5595 | if (ret < 0) { |
| 5596 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5597 | "BM_%d : beiscsi_eeh_resume - " |
| 5598 | "Failed to beiscsi_init_irqs\n"); |
| 5599 | goto ret_err; |
| 5600 | } |
| 5601 | |
| 5602 | hwi_enable_intr(phba); |
| 5603 | phba->state &= ~BE_ADAPTER_PCI_ERR; |
| 5604 | |
| 5605 | return; |
| 5606 | ret_err: |
| 5607 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5608 | "BM_%d : AER EEH Resume Failed\n"); |
| 5609 | } |
| 5610 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5611 | static int beiscsi_dev_probe(struct pci_dev *pcidev, |
| 5612 | const struct pci_device_id *id) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5613 | { |
| 5614 | struct beiscsi_hba *phba = NULL; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5615 | struct hwi_controller *phwi_ctrlr; |
| 5616 | struct hwi_context_memory *phwi_context; |
| 5617 | struct be_eq_obj *pbe_eq; |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5618 | int ret = 0, i; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5619 | |
| 5620 | ret = beiscsi_enable_pci(pcidev); |
| 5621 | if (ret < 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5622 | dev_err(&pcidev->dev, |
| 5623 | "beiscsi_dev_probe - Failed to enable pci device\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5624 | return ret; |
| 5625 | } |
| 5626 | |
| 5627 | phba = beiscsi_hba_alloc(pcidev); |
| 5628 | if (!phba) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5629 | dev_err(&pcidev->dev, |
| 5630 | "beiscsi_dev_probe - Failed in beiscsi_hba_alloc\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5631 | goto disable_pci; |
| 5632 | } |
| 5633 | |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5634 | /* Enable EEH reporting */ |
| 5635 | ret = pci_enable_pcie_error_reporting(pcidev); |
| 5636 | if (ret) |
| 5637 | beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT, |
| 5638 | "BM_%d : PCIe Error Reporting " |
| 5639 | "Enabling Failed\n"); |
| 5640 | |
| 5641 | pci_save_state(pcidev); |
| 5642 | |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5643 | /* Initialize Driver configuration Paramters */ |
| 5644 | beiscsi_hba_attrs_init(phba); |
| 5645 | |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 5646 | phba->fw_timeout = false; |
Jayamohan Kallickal | 6c83185 | 2013-09-28 15:35:40 -0700 | [diff] [blame] | 5647 | phba->mac_addr_set = false; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 5648 | |
| 5649 | |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 5650 | switch (pcidev->device) { |
| 5651 | case BE_DEVICE_ID1: |
| 5652 | case OC_DEVICE_ID1: |
| 5653 | case OC_DEVICE_ID2: |
| 5654 | phba->generation = BE_GEN2; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5655 | phba->iotask_fn = beiscsi_iotask; |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 5656 | break; |
| 5657 | case BE_DEVICE_ID2: |
| 5658 | case OC_DEVICE_ID3: |
| 5659 | phba->generation = BE_GEN3; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5660 | phba->iotask_fn = beiscsi_iotask; |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 5661 | break; |
John Soni Jose | 139a1b1 | 2012-10-20 04:43:20 +0530 | [diff] [blame] | 5662 | case OC_SKH_ID1: |
| 5663 | phba->generation = BE_GEN4; |
John Soni Jose | 09a1093 | 2012-10-20 04:44:23 +0530 | [diff] [blame] | 5664 | phba->iotask_fn = beiscsi_iotask_v2; |
Jayamohan Kallickal | bf9131c | 2013-04-05 20:38:24 -0700 | [diff] [blame] | 5665 | break; |
Jayamohan Kallickal | f98c96b | 2010-02-11 05:11:15 +0530 | [diff] [blame] | 5666 | default: |
| 5667 | phba->generation = 0; |
| 5668 | } |
| 5669 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5670 | ret = be_ctrl_init(phba, pcidev); |
| 5671 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5672 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5673 | "BM_%d : beiscsi_dev_probe-" |
| 5674 | "Failed in be_ctrl_init\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5675 | goto hba_free; |
| 5676 | } |
| 5677 | |
Jitendra Bhivare | cdaa4de | 2016-01-20 14:10:51 +0530 | [diff] [blame] | 5678 | /* |
| 5679 | * FUNCTION_RESET should clean up any stale info in FW for this fn |
| 5680 | */ |
John Soni Jose | 4d4d1ef | 2012-10-20 04:42:37 +0530 | [diff] [blame] | 5681 | ret = beiscsi_cmd_reset_function(phba); |
| 5682 | if (ret) { |
| 5683 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
Jayamohan Kallickal | 92665a6 | 2013-09-28 15:35:43 -0700 | [diff] [blame] | 5684 | "BM_%d : Reset Failed\n"); |
John Soni Jose | 4d4d1ef | 2012-10-20 04:42:37 +0530 | [diff] [blame] | 5685 | goto hba_free; |
| 5686 | } |
| 5687 | ret = be_chk_reset_complete(phba); |
| 5688 | if (ret) { |
| 5689 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
Jayamohan Kallickal | 92665a6 | 2013-09-28 15:35:43 -0700 | [diff] [blame] | 5690 | "BM_%d : Failed to get out of reset.\n"); |
John Soni Jose | 4d4d1ef | 2012-10-20 04:42:37 +0530 | [diff] [blame] | 5691 | goto hba_free; |
Jayamohan Kallickal | e9b9119 | 2010-07-22 04:24:53 +0530 | [diff] [blame] | 5692 | } |
| 5693 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5694 | spin_lock_init(&phba->io_sgl_lock); |
| 5695 | spin_lock_init(&phba->mgmt_sgl_lock); |
| 5696 | spin_lock_init(&phba->isr_lock); |
Jayamohan Kallickal | 8f09a3b | 2013-09-28 15:35:42 -0700 | [diff] [blame] | 5697 | spin_lock_init(&phba->async_pdu_lock); |
Jayamohan Kallickal | 7da5087 | 2010-01-05 05:04:12 +0530 | [diff] [blame] | 5698 | ret = mgmt_get_fw_config(&phba->ctrl, phba); |
| 5699 | if (ret != 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5700 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5701 | "BM_%d : Error getting fw config\n"); |
Jayamohan Kallickal | 7da5087 | 2010-01-05 05:04:12 +0530 | [diff] [blame] | 5702 | goto free_port; |
| 5703 | } |
Jitendra Bhivare | 53aefe2 | 2016-01-20 14:10:53 +0530 | [diff] [blame] | 5704 | mgmt_get_port_name(&phba->ctrl, phba); |
Jitendra Bhivare | 4570f16 | 2016-01-20 14:10:54 +0530 | [diff] [blame] | 5705 | beiscsi_get_params(phba); |
Jayamohan Kallickal | 68c26a3 | 2013-09-28 15:35:54 -0700 | [diff] [blame] | 5706 | |
| 5707 | if (enable_msix) |
| 5708 | find_num_cpus(phba); |
| 5709 | else |
| 5710 | phba->num_cpus = 1; |
| 5711 | |
| 5712 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 5713 | "BM_%d : num_cpus = %d\n", |
| 5714 | phba->num_cpus); |
| 5715 | |
| 5716 | if (enable_msix) { |
| 5717 | beiscsi_msix_enable(phba); |
| 5718 | if (!phba->msix_enabled) |
| 5719 | phba->num_cpus = 1; |
| 5720 | } |
| 5721 | |
Jayamohan Kallickal | 843ae75 | 2013-09-28 15:35:44 -0700 | [diff] [blame] | 5722 | phba->shost->max_id = phba->params.cxns_per_ctrl; |
Jayamohan Kallickal | aa874f0 | 2010-01-05 05:12:03 +0530 | [diff] [blame] | 5723 | phba->shost->can_queue = phba->params.ios_per_ctrl; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5724 | ret = beiscsi_init_port(phba); |
| 5725 | if (ret < 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5726 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5727 | "BM_%d : beiscsi_dev_probe-" |
| 5728 | "Failed in beiscsi_init_port\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5729 | goto free_port; |
| 5730 | } |
| 5731 | |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5732 | for (i = 0; i < MAX_MCC_CMD; i++) { |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 5733 | init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]); |
| 5734 | phba->ctrl.mcc_tag[i] = i + 1; |
| 5735 | phba->ctrl.mcc_numtag[i + 1] = 0; |
| 5736 | phba->ctrl.mcc_tag_available++; |
Jayamohan Kallickal | 1957aa7 | 2014-01-29 02:16:39 -0500 | [diff] [blame] | 5737 | memset(&phba->ctrl.ptag_state[i].tag_mem_state, 0, |
Jayamohan Kallickal | 8fc01ea | 2014-05-05 21:41:28 -0400 | [diff] [blame] | 5738 | sizeof(struct be_dma_mem)); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 5739 | } |
| 5740 | |
| 5741 | phba->ctrl.mcc_alloc_index = phba->ctrl.mcc_free_index = 0; |
| 5742 | |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 5743 | snprintf(phba->wq_name, sizeof(phba->wq_name), "beiscsi_%02x_wq", |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5744 | phba->shost->host_no); |
Kees Cook | d853754 | 2013-07-03 15:04:57 -0700 | [diff] [blame] | 5745 | phba->wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 1, phba->wq_name); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5746 | if (!phba->wq) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5747 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5748 | "BM_%d : beiscsi_dev_probe-" |
| 5749 | "Failed to allocate work queue\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5750 | goto free_twq; |
| 5751 | } |
| 5752 | |
John Soni Jose | 7a15800 | 2012-10-20 04:45:51 +0530 | [diff] [blame] | 5753 | INIT_DELAYED_WORK(&phba->beiscsi_hw_check_task, |
| 5754 | beiscsi_hw_health_check); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5755 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5756 | phwi_ctrlr = phba->phwi_ctrlr; |
| 5757 | phwi_context = phwi_ctrlr->phwi_ctxt; |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 5758 | |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5759 | for (i = 0; i < phba->num_cpus; i++) { |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 5760 | pbe_eq = &phwi_context->be_eq[i]; |
Christoph Hellwig | 511cbce | 2015-11-10 14:56:14 +0100 | [diff] [blame] | 5761 | irq_poll_init(&pbe_eq->iopoll, be_iopoll_budget, |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5762 | be_iopoll); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5763 | } |
John Soni Jose | 72fb46a | 2012-10-20 04:42:49 +0530 | [diff] [blame] | 5764 | |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5765 | i = (phba->msix_enabled) ? i : 0; |
| 5766 | /* Work item for MCC handling */ |
| 5767 | pbe_eq = &phwi_context->be_eq[i]; |
| 5768 | INIT_WORK(&pbe_eq->work_cqs, beiscsi_process_all_cqs); |
| 5769 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5770 | ret = beiscsi_init_irqs(phba); |
| 5771 | if (ret < 0) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5772 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5773 | "BM_%d : beiscsi_dev_probe-" |
| 5774 | "Failed to beiscsi_init_irqs\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5775 | goto free_blkenbld; |
| 5776 | } |
Jayamohan Kallickal | 238f6b7 | 2010-07-22 04:23:22 +0530 | [diff] [blame] | 5777 | hwi_enable_intr(phba); |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 5778 | |
Jayamohan Kallickal | 0598b8a | 2014-05-05 21:41:25 -0400 | [diff] [blame] | 5779 | if (iscsi_host_add(phba->shost, &phba->pcidev->dev)) |
| 5780 | goto free_blkenbld; |
| 5781 | |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 5782 | if (beiscsi_setup_boot_info(phba)) |
| 5783 | /* |
| 5784 | * log error but continue, because we may not be using |
| 5785 | * iscsi boot. |
| 5786 | */ |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5787 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 5788 | "BM_%d : Could not set up " |
| 5789 | "iSCSI boot info.\n"); |
Mike Christie | f457a46 | 2011-06-24 15:11:53 -0500 | [diff] [blame] | 5790 | |
Mike Christie | 0e43895 | 2012-04-03 23:41:51 -0500 | [diff] [blame] | 5791 | beiscsi_create_def_ifaces(phba); |
John Soni Jose | 7a15800 | 2012-10-20 04:45:51 +0530 | [diff] [blame] | 5792 | schedule_delayed_work(&phba->beiscsi_hw_check_task, |
| 5793 | msecs_to_jiffies(1000)); |
| 5794 | |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5795 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 5796 | "\n\n\n BM_%d : SUCCESS - DRIVER LOADED\n\n\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5797 | return 0; |
| 5798 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5799 | free_blkenbld: |
| 5800 | destroy_workqueue(phba->wq); |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5801 | for (i = 0; i < phba->num_cpus; i++) { |
| 5802 | pbe_eq = &phwi_context->be_eq[i]; |
Christoph Hellwig | 511cbce | 2015-11-10 14:56:14 +0100 | [diff] [blame] | 5803 | irq_poll_disable(&pbe_eq->iopoll); |
Jens Axboe | 89f8b33 | 2014-03-13 09:38:42 -0600 | [diff] [blame] | 5804 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5805 | free_twq: |
| 5806 | beiscsi_clean_port(phba); |
| 5807 | beiscsi_free_mem(phba); |
| 5808 | free_port: |
| 5809 | pci_free_consistent(phba->pcidev, |
| 5810 | phba->ctrl.mbox_mem_alloced.size, |
| 5811 | phba->ctrl.mbox_mem_alloced.va, |
| 5812 | phba->ctrl.mbox_mem_alloced.dma); |
| 5813 | beiscsi_unmap_pci_function(phba); |
| 5814 | hba_free: |
Jayamohan Kallickal | 238f6b7 | 2010-07-22 04:23:22 +0530 | [diff] [blame] | 5815 | if (phba->msix_enabled) |
| 5816 | pci_disable_msix(phba->pcidev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5817 | pci_dev_put(phba->pcidev); |
| 5818 | iscsi_host_free(phba->shost); |
John Soni Jose | 2e7cee0 | 2015-02-12 06:45:47 +0530 | [diff] [blame] | 5819 | pci_set_drvdata(pcidev, NULL); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5820 | disable_pci: |
John Soni Jose | e307f3a | 2015-04-25 08:17:19 +0530 | [diff] [blame] | 5821 | pci_release_regions(pcidev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5822 | pci_disable_device(pcidev); |
| 5823 | return ret; |
| 5824 | } |
| 5825 | |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5826 | static struct pci_error_handlers beiscsi_eeh_handlers = { |
| 5827 | .error_detected = beiscsi_eeh_err_detected, |
| 5828 | .slot_reset = beiscsi_eeh_reset, |
| 5829 | .resume = beiscsi_eeh_resume, |
| 5830 | }; |
| 5831 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5832 | struct iscsi_transport beiscsi_iscsi_transport = { |
| 5833 | .owner = THIS_MODULE, |
| 5834 | .name = DRV_NAME, |
Jayamohan Kallickal | 9db0fb3 | 2010-01-05 05:12:43 +0530 | [diff] [blame] | 5835 | .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_TEXT_NEGO | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5836 | CAP_MULTI_R2T | CAP_DATADGST | CAP_DATA_PATH_OFFLOAD, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5837 | .create_session = beiscsi_session_create, |
| 5838 | .destroy_session = beiscsi_session_destroy, |
| 5839 | .create_conn = beiscsi_conn_create, |
| 5840 | .bind_conn = beiscsi_conn_bind, |
| 5841 | .destroy_conn = iscsi_conn_teardown, |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 5842 | .attr_is_visible = be2iscsi_attr_is_visible, |
Mike Christie | 0e43895 | 2012-04-03 23:41:51 -0500 | [diff] [blame] | 5843 | .set_iface_param = be2iscsi_iface_set_param, |
| 5844 | .get_iface_param = be2iscsi_iface_get_param, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5845 | .set_param = beiscsi_set_param, |
Mike Christie | c7f7fd5 | 2011-02-16 15:04:41 -0600 | [diff] [blame] | 5846 | .get_conn_param = iscsi_conn_get_param, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5847 | .get_session_param = iscsi_session_get_param, |
| 5848 | .get_host_param = beiscsi_get_host_param, |
| 5849 | .start_conn = beiscsi_conn_start, |
Mike Christie | fa95d20 | 2010-06-09 03:30:08 -0500 | [diff] [blame] | 5850 | .stop_conn = iscsi_conn_stop, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5851 | .send_pdu = iscsi_conn_send_pdu, |
| 5852 | .xmit_task = beiscsi_task_xmit, |
| 5853 | .cleanup_task = beiscsi_cleanup_task, |
| 5854 | .alloc_pdu = beiscsi_alloc_pdu, |
| 5855 | .parse_pdu_itt = beiscsi_parse_pdu, |
| 5856 | .get_stats = beiscsi_conn_get_stats, |
Mike Christie | c7f7fd5 | 2011-02-16 15:04:41 -0600 | [diff] [blame] | 5857 | .get_ep_param = beiscsi_ep_get_param, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5858 | .ep_connect = beiscsi_ep_connect, |
| 5859 | .ep_poll = beiscsi_ep_poll, |
| 5860 | .ep_disconnect = beiscsi_ep_disconnect, |
| 5861 | .session_recovery_timedout = iscsi_session_recovery_timedout, |
Jayamohan Kallickal | ffce3e2 | 2012-04-03 23:41:50 -0500 | [diff] [blame] | 5862 | .bsg_request = beiscsi_bsg_request, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5863 | }; |
| 5864 | |
| 5865 | static struct pci_driver beiscsi_pci_driver = { |
| 5866 | .name = DRV_NAME, |
| 5867 | .probe = beiscsi_dev_probe, |
| 5868 | .remove = beiscsi_remove, |
Jayamohan Kallickal | 3567f36 | 2013-09-28 15:35:58 -0700 | [diff] [blame] | 5869 | .id_table = beiscsi_pci_id_table, |
| 5870 | .err_handler = &beiscsi_eeh_handlers |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5871 | }; |
| 5872 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 5873 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5874 | static int __init beiscsi_module_init(void) |
| 5875 | { |
| 5876 | int ret; |
| 5877 | |
| 5878 | beiscsi_scsi_transport = |
| 5879 | iscsi_register_transport(&beiscsi_iscsi_transport); |
| 5880 | if (!beiscsi_scsi_transport) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5881 | printk(KERN_ERR |
| 5882 | "beiscsi_module_init - Unable to register beiscsi transport.\n"); |
Jayamohan Kallickal | f55a24f | 2010-01-23 05:37:40 +0530 | [diff] [blame] | 5883 | return -ENOMEM; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5884 | } |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5885 | printk(KERN_INFO "In beiscsi_module_init, tt=%p\n", |
| 5886 | &beiscsi_iscsi_transport); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5887 | |
| 5888 | ret = pci_register_driver(&beiscsi_pci_driver); |
| 5889 | if (ret) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 5890 | printk(KERN_ERR |
| 5891 | "beiscsi_module_init - Unable to register beiscsi pci driver.\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5892 | goto unregister_iscsi_transport; |
| 5893 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 5894 | return 0; |
| 5895 | |
| 5896 | unregister_iscsi_transport: |
| 5897 | iscsi_unregister_transport(&beiscsi_iscsi_transport); |
| 5898 | return ret; |
| 5899 | } |
| 5900 | |
| 5901 | static void __exit beiscsi_module_exit(void) |
| 5902 | { |
| 5903 | pci_unregister_driver(&beiscsi_pci_driver); |
| 5904 | iscsi_unregister_transport(&beiscsi_iscsi_transport); |
| 5905 | } |
| 5906 | |
| 5907 | module_init(beiscsi_module_init); |
| 5908 | module_exit(beiscsi_module_exit); |