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