blob: 2f58772d4e0b56226e192e95eb33a5ac991434c8 [file] [log] [blame]
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301/**
Ketan Mukadamc4f39bd2015-07-04 04:12:33 +05302 * Copyright (C) 2005 - 2015 Emulex
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation. The full GNU General
8 * Public License is included in this distribution in the file called COPYING.
9 *
Minh Tran4627de92015-05-14 23:16:17 -070010 * Written by: Jayamohan Kallickal (jayamohan.kallickal@avagotech.com)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053011 *
12 * Contact Information:
Minh Tran4627de92015-05-14 23:16:17 -070013 * linux-drivers@avagotech.com
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053014 *
Ketan Mukadamc4f39bd2015-07-04 04:12:33 +053015 * Emulex
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070016 * 3333 Susan Street
17 * Costa Mesa, CA 92626
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053018 */
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070019
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053020#include <linux/reboot.h>
21#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/slab.h>
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053023#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 Kallickalc7acc5b2010-07-22 04:29:18 +053029#include <linux/iscsi_boot_sysfs.h>
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040030#include <linux/module.h>
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -050031#include <linux/bsg-lib.h>
Jitendra Bhivare1094cf62016-01-20 14:10:56 +053032#include <linux/irq_poll.h>
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053033
34#include <scsi/libiscsi.h>
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -050035#include <scsi/scsi_bsg_iscsi.h>
36#include <scsi/scsi_netlink.h>
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053037#include <scsi/scsi_transport_iscsi.h>
38#include <scsi/scsi_transport.h>
39#include <scsi/scsi_cmnd.h>
40#include <scsi/scsi_device.h>
41#include <scsi/scsi_host.h>
42#include <scsi/scsi.h>
43#include "be_main.h"
44#include "be_iscsi.h"
45#include "be_mgmt.h"
John Soni Jose0a513dd2012-08-20 23:00:55 +053046#include "be_cmds.h"
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053047
48static unsigned int be_iopoll_budget = 10;
49static unsigned int be_max_phys_size = 64;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +053050static unsigned int enable_msix = 1;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053051
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053052MODULE_DESCRIPTION(DRV_DESC " " BUILD_STR);
Jayamohan Kallickal76d15db2012-04-03 23:41:46 -050053MODULE_VERSION(BUILD_STR);
Ketan Mukadamc4f39bd2015-07-04 04:12:33 +053054MODULE_AUTHOR("Emulex Corporation");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053055MODULE_LICENSE("GPL");
56module_param(be_iopoll_budget, int, 0);
57module_param(enable_msix, int, 0);
58module_param(be_max_phys_size, uint, S_IRUGO);
John Soni Jose99bc5d52012-08-20 23:00:18 +053059MODULE_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)\
64ssize_t \
65beiscsi_##_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)\
77int \
78beiscsi_##_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) \
96ssize_t \
97beiscsi_##_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", &param_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) \
115int \
116beiscsi_##_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) \
131static uint beiscsi_##_name = _defval;\
132module_param(beiscsi_##_name, uint, S_IRUGO);\
133MODULE_PARM_DESC(beiscsi_##_name, _descp);\
134beiscsi_disp_param(_name)\
135beiscsi_change_param(_name, _minval, _maxval, _defval)\
136beiscsi_store_param(_name)\
137beiscsi_init_param(_name, _minval, _maxval, _defval)\
138DEVICE_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 */
145BEISCSI_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 Kallickalafb96052013-09-28 15:35:55 -0700152 "\t\t\t\tConfiguration Path : 0x20\n"
153 "\t\t\t\tiSCSI Protocol : 0x40\n");
John Soni Jose99bc5d52012-08-20 23:00:18 +0530154
John Soni Jose5cac7592012-10-20 04:42:25 +0530155DEVICE_ATTR(beiscsi_drvr_ver, S_IRUGO, beiscsi_drvr_ver_disp, NULL);
John Soni Jose26000db2012-10-20 04:45:06 +0530156DEVICE_ATTR(beiscsi_adapter_family, S_IRUGO, beiscsi_adap_family_disp, NULL);
Jayamohan Kallickal22661e22013-04-05 20:38:28 -0700157DEVICE_ATTR(beiscsi_fw_ver, S_IRUGO, beiscsi_fw_ver_disp, NULL);
Jayamohan Kallickald3fea9a2013-09-28 15:35:53 -0700158DEVICE_ATTR(beiscsi_phys_port, S_IRUGO, beiscsi_phys_port_disp, NULL);
Jayamohan Kallickal6103c1f2013-09-28 15:35:52 -0700159DEVICE_ATTR(beiscsi_active_session_count, S_IRUGO,
160 beiscsi_active_session_disp, NULL);
161DEVICE_ATTR(beiscsi_free_session_count, S_IRUGO,
162 beiscsi_free_session_disp, NULL);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530163struct device_attribute *beiscsi_attrs[] = {
164 &dev_attr_beiscsi_log_enable,
John Soni Jose5cac7592012-10-20 04:42:25 +0530165 &dev_attr_beiscsi_drvr_ver,
John Soni Jose26000db2012-10-20 04:45:06 +0530166 &dev_attr_beiscsi_adapter_family,
Jayamohan Kallickal22661e22013-04-05 20:38:28 -0700167 &dev_attr_beiscsi_fw_ver,
Jayamohan Kallickal6103c1f2013-09-28 15:35:52 -0700168 &dev_attr_beiscsi_active_session_count,
169 &dev_attr_beiscsi_free_session_count,
Jayamohan Kallickald3fea9a2013-09-28 15:35:53 -0700170 &dev_attr_beiscsi_phys_port,
John Soni Jose99bc5d52012-08-20 23:00:18 +0530171 NULL,
172};
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530173
John Soni Jose6763daa2012-10-20 04:41:45 +0530174static 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 Kallickal6733b392009-09-05 07:36:35 +0530213static 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 Kallickal41831222010-02-20 08:02:39 +0530219static 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 Kallickal3cbb7a72010-07-22 04:27:47 +0530229 struct be_dma_mem nonemb_cmd;
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530230 unsigned int cid, tag, num_invalidate;
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500231 int rc;
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530232
233 cls_session = starget_to_session(scsi_target(sc->device));
234 session = cls_session->dd_data;
235
Shlomo Pongratz659743b2014-02-07 00:41:38 -0600236 spin_lock_bh(&session->frwd_lock);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530237 if (!aborted_task || !aborted_task->sc) {
238 /* we raced */
Shlomo Pongratz659743b2014-02-07 00:41:38 -0600239 spin_unlock_bh(&session->frwd_lock);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530240 return SUCCESS;
241 }
242
243 aborted_io_task = aborted_task->dd_data;
244 if (!aborted_io_task->scsi_cmnd) {
245 /* raced or invalid command */
Shlomo Pongratz659743b2014-02-07 00:41:38 -0600246 spin_unlock_bh(&session->frwd_lock);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530247 return SUCCESS;
248 }
Shlomo Pongratz659743b2014-02-07 00:41:38 -0600249 spin_unlock_bh(&session->frwd_lock);
Jayamohan Kallickal7626c062013-09-28 15:35:57 -0700250 /* Invalidate WRB Posted for this Task */
251 AMAP_SET_BITS(struct amap_iscsi_wrb, invld,
252 aborted_io_task->pwrb_handle->pwrb,
253 1);
254
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530255 conn = aborted_task->conn;
256 beiscsi_conn = conn->dd_data;
257 phba = beiscsi_conn->phba;
258
259 /* invalidate iocb */
260 cid = beiscsi_conn->beiscsi_conn_cid;
261 inv_tbl = phba->inv_tbl;
262 memset(inv_tbl, 0x0, sizeof(*inv_tbl));
263 inv_tbl->cid = cid;
264 inv_tbl->icd = aborted_io_task->psgl_handle->sgl_index;
265 num_invalidate = 1;
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530266 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
267 sizeof(struct invalidate_commands_params_in),
268 &nonemb_cmd.dma);
269 if (nonemb_cmd.va == NULL) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530270 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
271 "BM_%d : Failed to allocate memory for"
272 "mgmt_invalidate_icds\n");
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530273 return FAILED;
274 }
275 nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
276
277 tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
278 cid, &nonemb_cmd);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530279 if (!tag) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530280 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH,
281 "BM_%d : mgmt_invalidate_icds could not be"
282 "submitted\n");
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530283 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
284 nonemb_cmd.va, nonemb_cmd.dma);
285
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530286 return FAILED;
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530287 }
John Soni Josee175def2012-10-20 04:45:40 +0530288
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500289 rc = beiscsi_mccq_compl(phba, tag, NULL, &nonemb_cmd);
290 if (rc != -EBUSY)
291 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
292 nonemb_cmd.va, nonemb_cmd.dma);
293
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530294 return iscsi_eh_abort(sc);
295}
296
297static int beiscsi_eh_device_reset(struct scsi_cmnd *sc)
298{
299 struct iscsi_task *abrt_task;
300 struct beiscsi_io_task *abrt_io_task;
301 struct iscsi_conn *conn;
302 struct beiscsi_conn *beiscsi_conn;
303 struct beiscsi_hba *phba;
304 struct iscsi_session *session;
305 struct iscsi_cls_session *cls_session;
306 struct invalidate_command_table *inv_tbl;
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530307 struct be_dma_mem nonemb_cmd;
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530308 unsigned int cid, tag, i, num_invalidate;
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500309 int rc;
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530310
311 /* invalidate iocbs */
312 cls_session = starget_to_session(scsi_target(sc->device));
313 session = cls_session->dd_data;
Shlomo Pongratz659743b2014-02-07 00:41:38 -0600314 spin_lock_bh(&session->frwd_lock);
Jayamohan Kallickaldb7f7702012-04-03 23:41:43 -0500315 if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN) {
Shlomo Pongratz659743b2014-02-07 00:41:38 -0600316 spin_unlock_bh(&session->frwd_lock);
Jayamohan Kallickaldb7f7702012-04-03 23:41:43 -0500317 return FAILED;
318 }
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530319 conn = session->leadconn;
320 beiscsi_conn = conn->dd_data;
321 phba = beiscsi_conn->phba;
322 cid = beiscsi_conn->beiscsi_conn_cid;
323 inv_tbl = phba->inv_tbl;
324 memset(inv_tbl, 0x0, sizeof(*inv_tbl) * BE2_CMDS_PER_CXN);
325 num_invalidate = 0;
326 for (i = 0; i < conn->session->cmds_max; i++) {
327 abrt_task = conn->session->cmds[i];
328 abrt_io_task = abrt_task->dd_data;
329 if (!abrt_task->sc || abrt_task->state == ISCSI_TASK_FREE)
330 continue;
331
Mike Christie126e9642013-12-19 01:16:21 -0600332 if (sc->device->lun != abrt_task->sc->device->lun)
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530333 continue;
334
Jayamohan Kallickal7626c062013-09-28 15:35:57 -0700335 /* Invalidate WRB Posted for this Task */
336 AMAP_SET_BITS(struct amap_iscsi_wrb, invld,
337 abrt_io_task->pwrb_handle->pwrb,
338 1);
339
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530340 inv_tbl->cid = cid;
341 inv_tbl->icd = abrt_io_task->psgl_handle->sgl_index;
342 num_invalidate++;
343 inv_tbl++;
344 }
Shlomo Pongratz659743b2014-02-07 00:41:38 -0600345 spin_unlock_bh(&session->frwd_lock);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530346 inv_tbl = phba->inv_tbl;
347
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530348 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
349 sizeof(struct invalidate_commands_params_in),
350 &nonemb_cmd.dma);
351 if (nonemb_cmd.va == NULL) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530352 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
353 "BM_%d : Failed to allocate memory for"
354 "mgmt_invalidate_icds\n");
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530355 return FAILED;
356 }
357 nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
358 memset(nonemb_cmd.va, 0, nonemb_cmd.size);
359 tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
360 cid, &nonemb_cmd);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530361 if (!tag) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530362 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH,
363 "BM_%d : mgmt_invalidate_icds could not be"
364 " submitted\n");
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530365 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
366 nonemb_cmd.va, nonemb_cmd.dma);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530367 return FAILED;
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530368 }
John Soni Josee175def2012-10-20 04:45:40 +0530369
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -0500370 rc = beiscsi_mccq_compl(phba, tag, NULL, &nonemb_cmd);
371 if (rc != -EBUSY)
372 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
373 nonemb_cmd.va, nonemb_cmd.dma);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530374 return iscsi_eh_device_reset(sc);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530375}
376
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530377static ssize_t beiscsi_show_boot_tgt_info(void *data, int type, char *buf)
378{
379 struct beiscsi_hba *phba = data;
Mike Christief457a462011-06-24 15:11:53 -0500380 struct mgmt_session_info *boot_sess = &phba->boot_sess;
381 struct mgmt_conn_info *boot_conn = &boot_sess->conn_list[0];
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530382 char *str = buf;
383 int rc;
384
385 switch (type) {
386 case ISCSI_BOOT_TGT_NAME:
387 rc = sprintf(buf, "%.*s\n",
Mike Christief457a462011-06-24 15:11:53 -0500388 (int)strlen(boot_sess->target_name),
389 (char *)&boot_sess->target_name);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530390 break;
391 case ISCSI_BOOT_TGT_IP_ADDR:
Mike Christief457a462011-06-24 15:11:53 -0500392 if (boot_conn->dest_ipaddr.ip_type == 0x1)
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530393 rc = sprintf(buf, "%pI4\n",
Mike Christie0e438952012-04-03 23:41:51 -0500394 (char *)&boot_conn->dest_ipaddr.addr);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530395 else
396 rc = sprintf(str, "%pI6\n",
Mike Christie0e438952012-04-03 23:41:51 -0500397 (char *)&boot_conn->dest_ipaddr.addr);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530398 break;
399 case ISCSI_BOOT_TGT_PORT:
Mike Christief457a462011-06-24 15:11:53 -0500400 rc = sprintf(str, "%d\n", boot_conn->dest_port);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530401 break;
402
403 case ISCSI_BOOT_TGT_CHAP_NAME:
404 rc = sprintf(str, "%.*s\n",
Mike Christief457a462011-06-24 15:11:53 -0500405 boot_conn->negotiated_login_options.auth_data.chap.
406 target_chap_name_length,
407 (char *)&boot_conn->negotiated_login_options.
408 auth_data.chap.target_chap_name);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530409 break;
410 case ISCSI_BOOT_TGT_CHAP_SECRET:
411 rc = sprintf(str, "%.*s\n",
Mike Christief457a462011-06-24 15:11:53 -0500412 boot_conn->negotiated_login_options.auth_data.chap.
413 target_secret_length,
414 (char *)&boot_conn->negotiated_login_options.
415 auth_data.chap.target_secret);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530416 break;
417 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
418 rc = sprintf(str, "%.*s\n",
Mike Christief457a462011-06-24 15:11:53 -0500419 boot_conn->negotiated_login_options.auth_data.chap.
420 intr_chap_name_length,
421 (char *)&boot_conn->negotiated_login_options.
422 auth_data.chap.intr_chap_name);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530423 break;
424 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
Mike Christief457a462011-06-24 15:11:53 -0500425 rc = sprintf(str, "%.*s\n",
426 boot_conn->negotiated_login_options.auth_data.chap.
427 intr_secret_length,
428 (char *)&boot_conn->negotiated_login_options.
429 auth_data.chap.intr_secret);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530430 break;
431 case ISCSI_BOOT_TGT_FLAGS:
Mike Christief457a462011-06-24 15:11:53 -0500432 rc = sprintf(str, "2\n");
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530433 break;
434 case ISCSI_BOOT_TGT_NIC_ASSOC:
Mike Christief457a462011-06-24 15:11:53 -0500435 rc = sprintf(str, "0\n");
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530436 break;
437 default:
438 rc = -ENOSYS;
439 break;
440 }
441 return rc;
442}
443
444static ssize_t beiscsi_show_boot_ini_info(void *data, int type, char *buf)
445{
446 struct beiscsi_hba *phba = data;
447 char *str = buf;
448 int rc;
449
450 switch (type) {
451 case ISCSI_BOOT_INI_INITIATOR_NAME:
452 rc = sprintf(str, "%s\n", phba->boot_sess.initiator_iscsiname);
453 break;
454 default:
455 rc = -ENOSYS;
456 break;
457 }
458 return rc;
459}
460
461static ssize_t beiscsi_show_boot_eth_info(void *data, int type, char *buf)
462{
463 struct beiscsi_hba *phba = data;
464 char *str = buf;
465 int rc;
466
467 switch (type) {
468 case ISCSI_BOOT_ETH_FLAGS:
Mike Christief457a462011-06-24 15:11:53 -0500469 rc = sprintf(str, "2\n");
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530470 break;
471 case ISCSI_BOOT_ETH_INDEX:
Mike Christief457a462011-06-24 15:11:53 -0500472 rc = sprintf(str, "0\n");
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530473 break;
474 case ISCSI_BOOT_ETH_MAC:
Mike Christie0e438952012-04-03 23:41:51 -0500475 rc = beiscsi_get_macaddr(str, phba);
476 break;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530477 default:
478 rc = -ENOSYS;
479 break;
480 }
481 return rc;
482}
483
484
Al Viro587a1f12011-07-23 23:11:19 -0400485static umode_t beiscsi_tgt_get_attr_visibility(void *data, int type)
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530486{
Al Viro587a1f12011-07-23 23:11:19 -0400487 umode_t rc;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530488
489 switch (type) {
490 case ISCSI_BOOT_TGT_NAME:
491 case ISCSI_BOOT_TGT_IP_ADDR:
492 case ISCSI_BOOT_TGT_PORT:
493 case ISCSI_BOOT_TGT_CHAP_NAME:
494 case ISCSI_BOOT_TGT_CHAP_SECRET:
495 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
496 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
497 case ISCSI_BOOT_TGT_NIC_ASSOC:
498 case ISCSI_BOOT_TGT_FLAGS:
499 rc = S_IRUGO;
500 break;
501 default:
502 rc = 0;
503 break;
504 }
505 return rc;
506}
507
Al Viro587a1f12011-07-23 23:11:19 -0400508static umode_t beiscsi_ini_get_attr_visibility(void *data, int type)
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530509{
Al Viro587a1f12011-07-23 23:11:19 -0400510 umode_t rc;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530511
512 switch (type) {
513 case ISCSI_BOOT_INI_INITIATOR_NAME:
514 rc = S_IRUGO;
515 break;
516 default:
517 rc = 0;
518 break;
519 }
520 return rc;
521}
522
523
Al Viro587a1f12011-07-23 23:11:19 -0400524static umode_t beiscsi_eth_get_attr_visibility(void *data, int type)
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530525{
Al Viro587a1f12011-07-23 23:11:19 -0400526 umode_t rc;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530527
528 switch (type) {
529 case ISCSI_BOOT_ETH_FLAGS:
530 case ISCSI_BOOT_ETH_MAC:
531 case ISCSI_BOOT_ETH_INDEX:
532 rc = S_IRUGO;
533 break;
534 default:
535 rc = 0;
536 break;
537 }
538 return rc;
539}
540
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530541/*------------------- PCI Driver operations and data ----------------- */
Benoit Taine9baa3c32014-08-08 15:56:03 +0200542static const struct pci_device_id beiscsi_pci_id_table[] = {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530543 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) },
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +0530544 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) },
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530545 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) },
546 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) },
547 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID3) },
John Soni Jose139a1b12012-10-20 04:43:20 +0530548 { PCI_DEVICE(ELX_VENDOR_ID, OC_SKH_ID1) },
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530549 { 0 }
550};
551MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
552
John Soni Jose99bc5d52012-08-20 23:00:18 +0530553
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530554static struct scsi_host_template beiscsi_sht = {
555 .module = THIS_MODULE,
Ketan Mukadamc4f39bd2015-07-04 04:12:33 +0530556 .name = "Emulex 10Gbe open-iscsi Initiator Driver",
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530557 .proc_name = DRV_NAME,
558 .queuecommand = iscsi_queuecommand,
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +0100559 .change_queue_depth = scsi_change_queue_depth,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530560 .slave_configure = beiscsi_slave_configure,
561 .target_alloc = iscsi_target_alloc,
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530562 .eh_abort_handler = beiscsi_eh_abort,
563 .eh_device_reset_handler = beiscsi_eh_device_reset,
Jayamohan Kallickal309ce152010-02-20 08:02:10 +0530564 .eh_target_reset_handler = iscsi_eh_session_reset,
John Soni Jose99bc5d52012-08-20 23:00:18 +0530565 .shost_attrs = beiscsi_attrs,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530566 .sg_tablesize = BEISCSI_SGLIST_ELEMENTS,
567 .can_queue = BE2_IO_DEPTH,
568 .this_id = -1,
569 .max_sectors = BEISCSI_MAX_SECTORS,
570 .cmd_per_lun = BEISCSI_CMD_PER_LUN,
571 .use_clustering = ENABLE_CLUSTERING,
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -0500572 .vendor_id = SCSI_NL_VID_TYPE_PCI | BE_VENDOR_ID,
Christoph Hellwigc40ecc12014-11-13 14:25:11 +0100573 .track_queue_depth = 1,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530574};
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530575
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530576static struct scsi_transport_template *beiscsi_scsi_transport;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530577
578static struct beiscsi_hba *beiscsi_hba_alloc(struct pci_dev *pcidev)
579{
580 struct beiscsi_hba *phba;
581 struct Scsi_Host *shost;
582
583 shost = iscsi_host_alloc(&beiscsi_sht, sizeof(*phba), 0);
584 if (!shost) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530585 dev_err(&pcidev->dev,
586 "beiscsi_hba_alloc - iscsi_host_alloc failed\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530587 return NULL;
588 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530589 shost->max_id = BE2_MAX_SESSIONS;
590 shost->max_channel = 0;
591 shost->max_cmd_len = BEISCSI_MAX_CMD_LEN;
592 shost->max_lun = BEISCSI_NUM_MAX_LUN;
593 shost->transportt = beiscsi_scsi_transport;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530594 phba = iscsi_host_priv(shost);
595 memset(phba, 0, sizeof(*phba));
596 phba->shost = shost;
597 phba->pcidev = pci_dev_get(pcidev);
Jayamohan Kallickal2807afb2010-01-05 05:07:49 +0530598 pci_set_drvdata(pcidev, phba);
Mike Christie0e438952012-04-03 23:41:51 -0500599 phba->interface_handle = 0xFFFFFFFF;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530600
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530601 return phba;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530602}
603
604static void beiscsi_unmap_pci_function(struct beiscsi_hba *phba)
605{
606 if (phba->csr_va) {
607 iounmap(phba->csr_va);
608 phba->csr_va = NULL;
609 }
610 if (phba->db_va) {
611 iounmap(phba->db_va);
612 phba->db_va = NULL;
613 }
614 if (phba->pci_va) {
615 iounmap(phba->pci_va);
616 phba->pci_va = NULL;
617 }
618}
619
620static int beiscsi_map_pci_bars(struct beiscsi_hba *phba,
621 struct pci_dev *pcidev)
622{
623 u8 __iomem *addr;
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +0530624 int pcicfg_reg;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530625
626 addr = ioremap_nocache(pci_resource_start(pcidev, 2),
627 pci_resource_len(pcidev, 2));
628 if (addr == NULL)
629 return -ENOMEM;
630 phba->ctrl.csr = addr;
631 phba->csr_va = addr;
632 phba->csr_pa.u.a64.address = pci_resource_start(pcidev, 2);
633
634 addr = ioremap_nocache(pci_resource_start(pcidev, 4), 128 * 1024);
635 if (addr == NULL)
636 goto pci_map_err;
637 phba->ctrl.db = addr;
638 phba->db_va = addr;
639 phba->db_pa.u.a64.address = pci_resource_start(pcidev, 4);
640
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +0530641 if (phba->generation == BE_GEN2)
642 pcicfg_reg = 1;
643 else
644 pcicfg_reg = 0;
645
646 addr = ioremap_nocache(pci_resource_start(pcidev, pcicfg_reg),
647 pci_resource_len(pcidev, pcicfg_reg));
648
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530649 if (addr == NULL)
650 goto pci_map_err;
651 phba->ctrl.pcicfg = addr;
652 phba->pci_va = addr;
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +0530653 phba->pci_pa.u.a64.address = pci_resource_start(pcidev, pcicfg_reg);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530654 return 0;
655
656pci_map_err:
657 beiscsi_unmap_pci_function(phba);
658 return -ENOMEM;
659}
660
661static int beiscsi_enable_pci(struct pci_dev *pcidev)
662{
663 int ret;
664
665 ret = pci_enable_device(pcidev);
666 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530667 dev_err(&pcidev->dev,
668 "beiscsi_enable_pci - enable device failed\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530669 return ret;
670 }
671
John Soni Josee307f3a2015-04-25 08:17:19 +0530672 ret = pci_request_regions(pcidev, DRV_NAME);
673 if (ret) {
674 dev_err(&pcidev->dev,
675 "beiscsi_enable_pci - request region failed\n");
676 goto pci_dev_disable;
677 }
678
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530679 pci_set_master(pcidev);
Jayamohan Kallickal6c57625b2014-01-29 02:16:45 -0500680 ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(64));
681 if (ret) {
682 ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(32));
683 if (ret) {
684 dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n");
John Soni Josee307f3a2015-04-25 08:17:19 +0530685 goto pci_region_release;
Jayamohan Kallickal6c57625b2014-01-29 02:16:45 -0500686 } else {
687 ret = pci_set_consistent_dma_mask(pcidev,
688 DMA_BIT_MASK(32));
689 }
690 } else {
691 ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530692 if (ret) {
693 dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n");
John Soni Josee307f3a2015-04-25 08:17:19 +0530694 goto pci_region_release;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530695 }
696 }
697 return 0;
John Soni Josee307f3a2015-04-25 08:17:19 +0530698
699pci_region_release:
700 pci_release_regions(pcidev);
701pci_dev_disable:
702 pci_disable_device(pcidev);
703
704 return ret;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530705}
706
707static int be_ctrl_init(struct beiscsi_hba *phba, struct pci_dev *pdev)
708{
709 struct be_ctrl_info *ctrl = &phba->ctrl;
710 struct be_dma_mem *mbox_mem_alloc = &ctrl->mbox_mem_alloced;
711 struct be_dma_mem *mbox_mem_align = &ctrl->mbox_mem;
712 int status = 0;
713
714 ctrl->pdev = pdev;
715 status = beiscsi_map_pci_bars(phba, pdev);
716 if (status)
717 return status;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530718 mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16;
719 mbox_mem_alloc->va = pci_alloc_consistent(pdev,
720 mbox_mem_alloc->size,
721 &mbox_mem_alloc->dma);
722 if (!mbox_mem_alloc->va) {
723 beiscsi_unmap_pci_function(phba);
Jayamohan Kallickala49e06d2012-04-03 23:41:44 -0500724 return -ENOMEM;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530725 }
726
727 mbox_mem_align->size = sizeof(struct be_mcc_mailbox);
728 mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16);
729 mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16);
730 memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox));
Jitendra Bhivarec03a50f2016-01-20 14:10:46 +0530731 mutex_init(&ctrl->mbox_lock);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530732 spin_lock_init(&phba->ctrl.mcc_lock);
733 spin_lock_init(&phba->ctrl.mcc_cq_lock);
734
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530735 return status;
736}
737
Jayamohan Kallickal843ae752013-09-28 15:35:44 -0700738/**
739 * beiscsi_get_params()- Set the config paramters
740 * @phba: ptr device priv structure
741 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530742static void beiscsi_get_params(struct beiscsi_hba *phba)
743{
Jayamohan Kallickal843ae752013-09-28 15:35:44 -0700744 uint32_t total_cid_count = 0;
745 uint32_t total_icd_count = 0;
746 uint8_t ulp_num = 0;
747
748 total_cid_count = BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP0) +
749 BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP1);
750
Jayamohan Kallickalcf987b72013-09-28 15:35:59 -0700751 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
752 uint32_t align_mask = 0;
753 uint32_t icd_post_per_page = 0;
754 uint32_t icd_count_unavailable = 0;
755 uint32_t icd_start = 0, icd_count = 0;
756 uint32_t icd_start_align = 0, icd_count_align = 0;
757
Jayamohan Kallickal843ae752013-09-28 15:35:44 -0700758 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
Jayamohan Kallickalcf987b72013-09-28 15:35:59 -0700759 icd_start = phba->fw_config.iscsi_icd_start[ulp_num];
760 icd_count = phba->fw_config.iscsi_icd_count[ulp_num];
761
762 /* Get ICD count that can be posted on each page */
763 icd_post_per_page = (PAGE_SIZE / (BE2_SGE *
764 sizeof(struct iscsi_sge)));
765 align_mask = (icd_post_per_page - 1);
766
767 /* Check if icd_start is aligned ICD per page posting */
768 if (icd_start % icd_post_per_page) {
769 icd_start_align = ((icd_start +
770 icd_post_per_page) &
771 ~(align_mask));
772 phba->fw_config.
773 iscsi_icd_start[ulp_num] =
774 icd_start_align;
775 }
776
777 icd_count_align = (icd_count & ~align_mask);
778
779 /* ICD discarded in the process of alignment */
780 if (icd_start_align)
781 icd_count_unavailable = ((icd_start_align -
782 icd_start) +
783 (icd_count -
784 icd_count_align));
785
786 /* Updated ICD count available */
787 phba->fw_config.iscsi_icd_count[ulp_num] = (icd_count -
788 icd_count_unavailable);
789
790 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
791 "BM_%d : Aligned ICD values\n"
792 "\t ICD Start : %d\n"
793 "\t ICD Count : %d\n"
794 "\t ICD Discarded : %d\n",
795 phba->fw_config.
796 iscsi_icd_start[ulp_num],
797 phba->fw_config.
798 iscsi_icd_count[ulp_num],
799 icd_count_unavailable);
Jayamohan Kallickal843ae752013-09-28 15:35:44 -0700800 break;
801 }
Jayamohan Kallickalcf987b72013-09-28 15:35:59 -0700802 }
Jayamohan Kallickal843ae752013-09-28 15:35:44 -0700803
Jayamohan Kallickalcf987b72013-09-28 15:35:59 -0700804 total_icd_count = phba->fw_config.iscsi_icd_count[ulp_num];
Jayamohan Kallickal843ae752013-09-28 15:35:44 -0700805 phba->params.ios_per_ctrl = (total_icd_count -
806 (total_cid_count +
807 BE2_TMFS + BE2_NOPOUT_REQ));
808 phba->params.cxns_per_ctrl = total_cid_count;
809 phba->params.asyncpdus_per_ctrl = total_cid_count;
810 phba->params.icds_per_ctrl = total_icd_count;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530811 phba->params.num_sge_per_io = BE2_SGE;
812 phba->params.defpdu_hdr_sz = BE2_DEFPDU_HDR_SZ;
813 phba->params.defpdu_data_sz = BE2_DEFPDU_DATA_SZ;
814 phba->params.eq_timer = 64;
Jayamohan Kallickal843ae752013-09-28 15:35:44 -0700815 phba->params.num_eq_entries = 1024;
816 phba->params.num_cq_entries = 1024;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530817 phba->params.wrbs_per_cxn = 256;
818}
819
820static void hwi_ring_eq_db(struct beiscsi_hba *phba,
821 unsigned int id, unsigned int clr_interrupt,
822 unsigned int num_processed,
823 unsigned char rearm, unsigned char event)
824{
825 u32 val = 0;
Jayamohan Kallickale08b3c82014-01-29 02:16:42 -0500826
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530827 if (rearm)
828 val |= 1 << DB_EQ_REARM_SHIFT;
829 if (clr_interrupt)
830 val |= 1 << DB_EQ_CLR_SHIFT;
831 if (event)
832 val |= 1 << DB_EQ_EVNT_SHIFT;
Jayamohan Kallickale08b3c82014-01-29 02:16:42 -0500833
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530834 val |= num_processed << DB_EQ_NUM_POPPED_SHIFT;
Jayamohan Kallickale08b3c82014-01-29 02:16:42 -0500835 /* Setting lower order EQ_ID Bits */
836 val |= (id & DB_EQ_RING_ID_LOW_MASK);
837
838 /* Setting Higher order EQ_ID Bits */
839 val |= (((id >> DB_EQ_HIGH_FEILD_SHIFT) &
840 DB_EQ_RING_ID_HIGH_MASK)
841 << DB_EQ_HIGH_SET_SHIFT);
842
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530843 iowrite32(val, phba->db_va + DB_EQ_OFFSET);
844}
845
846/**
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530847 * be_isr_mcc - The isr routine of the driver.
848 * @irq: Not used
849 * @dev_id: Pointer to host adapter structure
850 */
851static irqreturn_t be_isr_mcc(int irq, void *dev_id)
852{
853 struct beiscsi_hba *phba;
854 struct be_eq_entry *eqe = NULL;
855 struct be_queue_info *eq;
856 struct be_queue_info *mcc;
857 unsigned int num_eq_processed;
858 struct be_eq_obj *pbe_eq;
859 unsigned long flags;
860
861 pbe_eq = dev_id;
862 eq = &pbe_eq->q;
863 phba = pbe_eq->phba;
864 mcc = &phba->ctrl.mcc_obj.cq;
865 eqe = queue_tail_node(eq);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530866
867 num_eq_processed = 0;
868
869 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
870 & EQE_VALID_MASK) {
871 if (((eqe->dw[offsetof(struct amap_eq_entry,
872 resource_id) / 32] &
873 EQE_RESID_MASK) >> 16) == mcc->id) {
874 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +0530875 pbe_eq->todo_mcc_cq = true;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530876 spin_unlock_irqrestore(&phba->isr_lock, flags);
877 }
878 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
879 queue_tail_inc(eq);
880 eqe = queue_tail_node(eq);
881 num_eq_processed++;
882 }
John Soni Jose72fb46a2012-10-20 04:42:49 +0530883 if (pbe_eq->todo_mcc_cq)
884 queue_work(phba->wq, &pbe_eq->work_cqs);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530885 if (num_eq_processed)
886 hwi_ring_eq_db(phba, eq->id, 1, num_eq_processed, 1, 1);
887
888 return IRQ_HANDLED;
889}
890
891/**
892 * be_isr_msix - The isr routine of the driver.
893 * @irq: Not used
894 * @dev_id: Pointer to host adapter structure
895 */
896static irqreturn_t be_isr_msix(int irq, void *dev_id)
897{
898 struct beiscsi_hba *phba;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530899 struct be_queue_info *eq;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530900 struct be_eq_obj *pbe_eq;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530901
902 pbe_eq = dev_id;
903 eq = &pbe_eq->q;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530904
905 phba = pbe_eq->phba;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530906
Jitendra Bhivare1094cf62016-01-20 14:10:56 +0530907 /* disable interrupt till iopoll completes */
908 hwi_ring_eq_db(phba, eq->id, 1, 0, 0, 1);
909 irq_poll_sched(&pbe_eq->iopoll);
John Soni Jose72fb46a2012-10-20 04:42:49 +0530910
911 return IRQ_HANDLED;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530912}
913
914/**
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530915 * be_isr - The isr routine of the driver.
916 * @irq: Not used
917 * @dev_id: Pointer to host adapter structure
918 */
919static irqreturn_t be_isr(int irq, void *dev_id)
920{
921 struct beiscsi_hba *phba;
922 struct hwi_controller *phwi_ctrlr;
923 struct hwi_context_memory *phwi_context;
924 struct be_eq_entry *eqe = NULL;
925 struct be_queue_info *eq;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530926 struct be_queue_info *mcc;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530927 unsigned long flags, index;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530928 unsigned int num_mcceq_processed, num_ioeq_processed;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530929 struct be_ctrl_info *ctrl;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530930 struct be_eq_obj *pbe_eq;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530931 int isr;
932
933 phba = dev_id;
Justin P. Mattock6eab04a2011-04-08 19:49:08 -0700934 ctrl = &phba->ctrl;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530935 isr = ioread32(ctrl->csr + CEV_ISR0_OFFSET +
936 (PCI_FUNC(ctrl->pdev->devfn) * CEV_ISR_SIZE));
937 if (!isr)
938 return IRQ_NONE;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530939
940 phwi_ctrlr = phba->phwi_ctrlr;
941 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530942 pbe_eq = &phwi_context->be_eq[0];
943
944 eq = &phwi_context->be_eq[0].q;
945 mcc = &phba->ctrl.mcc_obj.cq;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530946 index = 0;
947 eqe = queue_tail_node(eq);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530948
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530949 num_ioeq_processed = 0;
950 num_mcceq_processed = 0;
Jens Axboe89f8b332014-03-13 09:38:42 -0600951 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
952 & EQE_VALID_MASK) {
953 if (((eqe->dw[offsetof(struct amap_eq_entry,
954 resource_id) / 32] &
955 EQE_RESID_MASK) >> 16) == mcc->id) {
956 spin_lock_irqsave(&phba->isr_lock, flags);
957 pbe_eq->todo_mcc_cq = true;
958 spin_unlock_irqrestore(&phba->isr_lock, flags);
959 num_mcceq_processed++;
960 } else {
Christoph Hellwigea511902015-12-07 06:41:11 -0800961 irq_poll_sched(&pbe_eq->iopoll);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530962 num_ioeq_processed++;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530963 }
Jens Axboe89f8b332014-03-13 09:38:42 -0600964 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
965 queue_tail_inc(eq);
966 eqe = queue_tail_node(eq);
967 }
968 if (num_ioeq_processed || num_mcceq_processed) {
969 if (pbe_eq->todo_mcc_cq)
John Soni Jose72fb46a2012-10-20 04:42:49 +0530970 queue_work(phba->wq, &pbe_eq->work_cqs);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530971
Jens Axboe89f8b332014-03-13 09:38:42 -0600972 if ((num_mcceq_processed) && (!num_ioeq_processed))
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530973 hwi_ring_eq_db(phba, eq->id, 0,
Jens Axboe89f8b332014-03-13 09:38:42 -0600974 (num_ioeq_processed +
975 num_mcceq_processed) , 1, 1);
976 else
977 hwi_ring_eq_db(phba, eq->id, 0,
978 (num_ioeq_processed +
979 num_mcceq_processed), 0, 1);
980
981 return IRQ_HANDLED;
982 } else
983 return IRQ_NONE;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530984}
985
Jitendra Bhivare1094cf62016-01-20 14:10:56 +0530986
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530987static int beiscsi_init_irqs(struct beiscsi_hba *phba)
988{
989 struct pci_dev *pcidev = phba->pcidev;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530990 struct hwi_controller *phwi_ctrlr;
991 struct hwi_context_memory *phwi_context;
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +0530992 int ret, msix_vec, i, j;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530993
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530994 phwi_ctrlr = phba->phwi_ctrlr;
995 phwi_context = phwi_ctrlr->phwi_ctxt;
996
997 if (phba->msix_enabled) {
998 for (i = 0; i < phba->num_cpus; i++) {
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -0700999 phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME,
1000 GFP_KERNEL);
1001 if (!phba->msi_name[i]) {
1002 ret = -ENOMEM;
1003 goto free_msix_irqs;
1004 }
1005
1006 sprintf(phba->msi_name[i], "beiscsi_%02x_%02x",
1007 phba->shost->host_no, i);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301008 msix_vec = phba->msix_entries[i].vector;
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -07001009 ret = request_irq(msix_vec, be_isr_msix, 0,
1010 phba->msi_name[i],
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301011 &phwi_context->be_eq[i]);
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +05301012 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301013 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
1014 "BM_%d : beiscsi_init_irqs-Failed to"
1015 "register msix for i = %d\n",
1016 i);
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -07001017 kfree(phba->msi_name[i]);
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +05301018 goto free_msix_irqs;
1019 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301020 }
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -07001021 phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME, GFP_KERNEL);
1022 if (!phba->msi_name[i]) {
1023 ret = -ENOMEM;
1024 goto free_msix_irqs;
1025 }
1026 sprintf(phba->msi_name[i], "beiscsi_mcc_%02x",
1027 phba->shost->host_no);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301028 msix_vec = phba->msix_entries[i].vector;
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -07001029 ret = request_irq(msix_vec, be_isr_mcc, 0, phba->msi_name[i],
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301030 &phwi_context->be_eq[i]);
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +05301031 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301032 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT ,
1033 "BM_%d : beiscsi_init_irqs-"
1034 "Failed to register beiscsi_msix_mcc\n");
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -07001035 kfree(phba->msi_name[i]);
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +05301036 goto free_msix_irqs;
1037 }
1038
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301039 } else {
1040 ret = request_irq(pcidev->irq, be_isr, IRQF_SHARED,
1041 "beiscsi", phba);
1042 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301043 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
1044 "BM_%d : beiscsi_init_irqs-"
1045 "Failed to register irq\\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301046 return ret;
1047 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301048 }
1049 return 0;
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +05301050free_msix_irqs:
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -07001051 for (j = i - 1; j >= 0; j--) {
1052 kfree(phba->msi_name[j]);
1053 msix_vec = phba->msix_entries[j].vector;
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +05301054 free_irq(msix_vec, &phwi_context->be_eq[j]);
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -07001055 }
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +05301056 return ret;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301057}
1058
Jayamohan Kallickale08b3c82014-01-29 02:16:42 -05001059void hwi_ring_cq_db(struct beiscsi_hba *phba,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301060 unsigned int id, unsigned int num_processed,
Jitendra Bhivare1094cf62016-01-20 14:10:56 +05301061 unsigned char rearm)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301062{
1063 u32 val = 0;
Jayamohan Kallickale08b3c82014-01-29 02:16:42 -05001064
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301065 if (rearm)
1066 val |= 1 << DB_CQ_REARM_SHIFT;
Jayamohan Kallickale08b3c82014-01-29 02:16:42 -05001067
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301068 val |= num_processed << DB_CQ_NUM_POPPED_SHIFT;
Jayamohan Kallickale08b3c82014-01-29 02:16:42 -05001069
1070 /* Setting lower order CQ_ID Bits */
1071 val |= (id & DB_CQ_RING_ID_LOW_MASK);
1072
1073 /* Setting Higher order CQ_ID Bits */
1074 val |= (((id >> DB_CQ_HIGH_FEILD_SHIFT) &
1075 DB_CQ_RING_ID_HIGH_MASK)
1076 << DB_CQ_HIGH_SET_SHIFT);
1077
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301078 iowrite32(val, phba->db_va + DB_CQ_OFFSET);
1079}
1080
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301081static unsigned int
1082beiscsi_process_async_pdu(struct beiscsi_conn *beiscsi_conn,
1083 struct beiscsi_hba *phba,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301084 struct pdu_base *ppdu,
1085 unsigned long pdu_len,
1086 void *pbuffer, unsigned long buf_len)
1087{
1088 struct iscsi_conn *conn = beiscsi_conn->conn;
1089 struct iscsi_session *session = conn->session;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301090 struct iscsi_task *task;
1091 struct beiscsi_io_task *io_task;
1092 struct iscsi_hdr *login_hdr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301093
1094 switch (ppdu->dw[offsetof(struct amap_pdu_base, opcode) / 32] &
1095 PDUBASE_OPCODE_MASK) {
1096 case ISCSI_OP_NOOP_IN:
1097 pbuffer = NULL;
1098 buf_len = 0;
1099 break;
1100 case ISCSI_OP_ASYNC_EVENT:
1101 break;
1102 case ISCSI_OP_REJECT:
1103 WARN_ON(!pbuffer);
1104 WARN_ON(!(buf_len == 48));
John Soni Jose99bc5d52012-08-20 23:00:18 +05301105 beiscsi_log(phba, KERN_ERR,
1106 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1107 "BM_%d : In ISCSI_OP_REJECT\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301108 break;
1109 case ISCSI_OP_LOGIN_RSP:
Jayamohan Kallickal7bd6e252010-01-05 05:07:02 +05301110 case ISCSI_OP_TEXT_RSP:
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301111 task = conn->login_task;
1112 io_task = task->dd_data;
1113 login_hdr = (struct iscsi_hdr *)ppdu;
1114 login_hdr->itt = io_task->libiscsi_itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301115 break;
1116 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +05301117 beiscsi_log(phba, KERN_WARNING,
1118 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1119 "BM_%d : Unrecognized opcode 0x%x in async msg\n",
1120 (ppdu->
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301121 dw[offsetof(struct amap_pdu_base, opcode) / 32]
John Soni Jose99bc5d52012-08-20 23:00:18 +05301122 & PDUBASE_OPCODE_MASK));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301123 return 1;
1124 }
1125
Shlomo Pongratz659743b2014-02-07 00:41:38 -06001126 spin_lock_bh(&session->back_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301127 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)ppdu, pbuffer, buf_len);
Shlomo Pongratz659743b2014-02-07 00:41:38 -06001128 spin_unlock_bh(&session->back_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301129 return 0;
1130}
1131
1132static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba)
1133{
1134 struct sgl_handle *psgl_handle;
1135
1136 if (phba->io_sgl_hndl_avbl) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301137 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
1138 "BM_%d : In alloc_io_sgl_handle,"
1139 " io_sgl_alloc_index=%d\n",
1140 phba->io_sgl_alloc_index);
1141
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301142 psgl_handle = phba->io_sgl_hndl_base[phba->
1143 io_sgl_alloc_index];
1144 phba->io_sgl_hndl_base[phba->io_sgl_alloc_index] = NULL;
1145 phba->io_sgl_hndl_avbl--;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301146 if (phba->io_sgl_alloc_index == (phba->params.
1147 ios_per_ctrl - 1))
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301148 phba->io_sgl_alloc_index = 0;
1149 else
1150 phba->io_sgl_alloc_index++;
1151 } else
1152 psgl_handle = NULL;
1153 return psgl_handle;
1154}
1155
1156static void
1157free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
1158{
John Soni Jose99bc5d52012-08-20 23:00:18 +05301159 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
1160 "BM_%d : In free_,io_sgl_free_index=%d\n",
1161 phba->io_sgl_free_index);
1162
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301163 if (phba->io_sgl_hndl_base[phba->io_sgl_free_index]) {
1164 /*
1165 * this can happen if clean_task is called on a task that
1166 * failed in xmit_task or alloc_pdu.
1167 */
John Soni Jose99bc5d52012-08-20 23:00:18 +05301168 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
1169 "BM_%d : Double Free in IO SGL io_sgl_free_index=%d,"
1170 "value there=%p\n", phba->io_sgl_free_index,
1171 phba->io_sgl_hndl_base
1172 [phba->io_sgl_free_index]);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301173 return;
1174 }
1175 phba->io_sgl_hndl_base[phba->io_sgl_free_index] = psgl_handle;
1176 phba->io_sgl_hndl_avbl++;
1177 if (phba->io_sgl_free_index == (phba->params.ios_per_ctrl - 1))
1178 phba->io_sgl_free_index = 0;
1179 else
1180 phba->io_sgl_free_index++;
1181}
1182
Jitendra Bhivarecb564c62016-01-20 14:11:00 +05301183static inline struct wrb_handle *
1184beiscsi_get_wrb_handle(struct hwi_wrb_context *pwrb_context,
1185 unsigned int wrbs_per_cxn)
1186{
1187 struct wrb_handle *pwrb_handle;
1188
1189 pwrb_handle = pwrb_context->pwrb_handle_base[pwrb_context->alloc_index];
1190 pwrb_context->wrb_handles_available--;
1191 if (pwrb_context->alloc_index == (wrbs_per_cxn - 1))
1192 pwrb_context->alloc_index = 0;
1193 else
1194 pwrb_context->alloc_index++;
1195
1196 return pwrb_handle;
1197}
1198
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301199/**
1200 * alloc_wrb_handle - To allocate a wrb handle
1201 * @phba: The hba pointer
1202 * @cid: The cid to use for allocation
John Soni Jose340c99e2015-08-20 04:44:30 +05301203 * @pwrb_context: ptr to ptr to wrb context
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301204 *
1205 * This happens under session_lock until submission to chip
1206 */
John Soni Jose340c99e2015-08-20 04:44:30 +05301207struct wrb_handle *alloc_wrb_handle(struct beiscsi_hba *phba, unsigned int cid,
Jitendra Bhivarecb564c62016-01-20 14:11:00 +05301208 struct hwi_wrb_context **pcontext)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301209{
1210 struct hwi_wrb_context *pwrb_context;
1211 struct hwi_controller *phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001212 uint16_t cri_index = BE_GET_CRI_FROM_CID(cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301213
1214 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001215 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
Jitendra Bhivarecb564c62016-01-20 14:11:00 +05301216 /* return the context address */
1217 *pcontext = pwrb_context;
1218 return beiscsi_get_wrb_handle(pwrb_context, phba->params.wrbs_per_cxn);
1219}
John Soni Jose340c99e2015-08-20 04:44:30 +05301220
Jitendra Bhivarecb564c62016-01-20 14:11:00 +05301221static inline void
1222beiscsi_put_wrb_handle(struct hwi_wrb_context *pwrb_context,
1223 struct wrb_handle *pwrb_handle,
1224 unsigned int wrbs_per_cxn)
1225{
1226 pwrb_context->pwrb_handle_base[pwrb_context->free_index] = pwrb_handle;
1227 pwrb_context->wrb_handles_available++;
1228 if (pwrb_context->free_index == (wrbs_per_cxn - 1))
1229 pwrb_context->free_index = 0;
1230 else
1231 pwrb_context->free_index++;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301232}
1233
1234/**
1235 * free_wrb_handle - To free the wrb handle back to pool
1236 * @phba: The hba pointer
1237 * @pwrb_context: The context to free from
1238 * @pwrb_handle: The wrb_handle to free
1239 *
1240 * This happens under session_lock until submission to chip
1241 */
1242static void
1243free_wrb_handle(struct beiscsi_hba *phba, struct hwi_wrb_context *pwrb_context,
1244 struct wrb_handle *pwrb_handle)
1245{
Jitendra Bhivarecb564c62016-01-20 14:11:00 +05301246 beiscsi_put_wrb_handle(pwrb_context,
1247 pwrb_handle,
1248 phba->params.wrbs_per_cxn);
John Soni Jose99bc5d52012-08-20 23:00:18 +05301249 beiscsi_log(phba, KERN_INFO,
1250 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1251 "BM_%d : FREE WRB: pwrb_handle=%p free_index=0x%x"
1252 "wrb_handles_available=%d\n",
1253 pwrb_handle, pwrb_context->free_index,
1254 pwrb_context->wrb_handles_available);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301255}
1256
1257static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba)
1258{
1259 struct sgl_handle *psgl_handle;
1260
1261 if (phba->eh_sgl_hndl_avbl) {
1262 psgl_handle = phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index];
1263 phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index] = NULL;
John Soni Jose99bc5d52012-08-20 23:00:18 +05301264 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1265 "BM_%d : mgmt_sgl_alloc_index=%d=0x%x\n",
1266 phba->eh_sgl_alloc_index,
1267 phba->eh_sgl_alloc_index);
1268
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301269 phba->eh_sgl_hndl_avbl--;
1270 if (phba->eh_sgl_alloc_index ==
1271 (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl -
1272 1))
1273 phba->eh_sgl_alloc_index = 0;
1274 else
1275 phba->eh_sgl_alloc_index++;
1276 } else
1277 psgl_handle = NULL;
1278 return psgl_handle;
1279}
1280
1281void
1282free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
1283{
1284
John Soni Jose99bc5d52012-08-20 23:00:18 +05301285 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1286 "BM_%d : In free_mgmt_sgl_handle,"
1287 "eh_sgl_free_index=%d\n",
1288 phba->eh_sgl_free_index);
1289
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301290 if (phba->eh_sgl_hndl_base[phba->eh_sgl_free_index]) {
1291 /*
1292 * this can happen if clean_task is called on a task that
1293 * failed in xmit_task or alloc_pdu.
1294 */
John Soni Jose99bc5d52012-08-20 23:00:18 +05301295 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1296 "BM_%d : Double Free in eh SGL ,"
1297 "eh_sgl_free_index=%d\n",
1298 phba->eh_sgl_free_index);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301299 return;
1300 }
1301 phba->eh_sgl_hndl_base[phba->eh_sgl_free_index] = psgl_handle;
1302 phba->eh_sgl_hndl_avbl++;
1303 if (phba->eh_sgl_free_index ==
1304 (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl - 1))
1305 phba->eh_sgl_free_index = 0;
1306 else
1307 phba->eh_sgl_free_index++;
1308}
1309
1310static void
1311be_complete_io(struct beiscsi_conn *beiscsi_conn,
John Soni Jose73133262012-10-20 04:44:49 +05301312 struct iscsi_task *task,
1313 struct common_sol_cqe *csol_cqe)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301314{
1315 struct beiscsi_io_task *io_task = task->dd_data;
1316 struct be_status_bhs *sts_bhs =
1317 (struct be_status_bhs *)io_task->cmd_bhs;
1318 struct iscsi_conn *conn = beiscsi_conn->conn;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301319 unsigned char *sense;
1320 u32 resid = 0, exp_cmdsn, max_cmdsn;
1321 u8 rsp, status, flags;
1322
John Soni Jose73133262012-10-20 04:44:49 +05301323 exp_cmdsn = csol_cqe->exp_cmdsn;
1324 max_cmdsn = (csol_cqe->exp_cmdsn +
1325 csol_cqe->cmd_wnd - 1);
1326 rsp = csol_cqe->i_resp;
1327 status = csol_cqe->i_sts;
1328 flags = csol_cqe->i_flags;
1329 resid = csol_cqe->res_cnt;
1330
Jayamohan Kallickalbd535452011-10-07 19:31:10 -05001331 if (!task->sc) {
Jayamohan Kallickalda334972014-01-29 02:16:44 -05001332 if (io_task->scsi_cmnd) {
Jayamohan Kallickalbd535452011-10-07 19:31:10 -05001333 scsi_dma_unmap(io_task->scsi_cmnd);
Jayamohan Kallickalda334972014-01-29 02:16:44 -05001334 io_task->scsi_cmnd = NULL;
1335 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301336
Jayamohan Kallickalbd535452011-10-07 19:31:10 -05001337 return;
1338 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301339 task->sc->result = (DID_OK << 16) | status;
1340 if (rsp != ISCSI_STATUS_CMD_COMPLETED) {
1341 task->sc->result = DID_ERROR << 16;
1342 goto unmap;
1343 }
1344
1345 /* bidi not initially supported */
1346 if (flags & (ISCSI_FLAG_CMD_UNDERFLOW | ISCSI_FLAG_CMD_OVERFLOW)) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301347 if (!status && (flags & ISCSI_FLAG_CMD_OVERFLOW))
1348 task->sc->result = DID_ERROR << 16;
1349
1350 if (flags & ISCSI_FLAG_CMD_UNDERFLOW) {
1351 scsi_set_resid(task->sc, resid);
1352 if (!status && (scsi_bufflen(task->sc) - resid <
1353 task->sc->underflow))
1354 task->sc->result = DID_ERROR << 16;
1355 }
1356 }
1357
1358 if (status == SAM_STAT_CHECK_CONDITION) {
Dan Carpenter4053a4b2011-09-26 09:23:37 +03001359 u16 sense_len;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301360 unsigned short *slen = (unsigned short *)sts_bhs->sense_info;
Dan Carpenter4053a4b2011-09-26 09:23:37 +03001361
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301362 sense = sts_bhs->sense_info + sizeof(unsigned short);
Dan Carpenter4053a4b2011-09-26 09:23:37 +03001363 sense_len = be16_to_cpu(*slen);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301364 memcpy(task->sc->sense_buffer, sense,
1365 min_t(u16, sense_len, SCSI_SENSE_BUFFERSIZE));
1366 }
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05301367
John Soni Jose73133262012-10-20 04:44:49 +05301368 if (io_task->cmd_bhs->iscsi_hdr.flags & ISCSI_FLAG_CMD_READ)
1369 conn->rxdata_octets += resid;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301370unmap:
John Soni Joseeb1c4692015-04-25 08:17:45 +05301371 if (io_task->scsi_cmnd) {
1372 scsi_dma_unmap(io_task->scsi_cmnd);
1373 io_task->scsi_cmnd = NULL;
1374 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301375 iscsi_complete_scsi_task(task, exp_cmdsn, max_cmdsn);
1376}
1377
1378static void
1379be_complete_logout(struct beiscsi_conn *beiscsi_conn,
John Soni Jose73133262012-10-20 04:44:49 +05301380 struct iscsi_task *task,
1381 struct common_sol_cqe *csol_cqe)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301382{
1383 struct iscsi_logout_rsp *hdr;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301384 struct beiscsi_io_task *io_task = task->dd_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301385 struct iscsi_conn *conn = beiscsi_conn->conn;
1386
1387 hdr = (struct iscsi_logout_rsp *)task->hdr;
Jayamohan Kallickal7bd6e252010-01-05 05:07:02 +05301388 hdr->opcode = ISCSI_OP_LOGOUT_RSP;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301389 hdr->t2wait = 5;
1390 hdr->t2retain = 0;
John Soni Jose73133262012-10-20 04:44:49 +05301391 hdr->flags = csol_cqe->i_flags;
1392 hdr->response = csol_cqe->i_resp;
Jayamohan Kallickal702dc5e2013-04-05 20:38:37 -07001393 hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn);
1394 hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn +
1395 csol_cqe->cmd_wnd - 1);
John Soni Jose73133262012-10-20 04:44:49 +05301396
Jayamohan Kallickal7bd6e252010-01-05 05:07:02 +05301397 hdr->dlength[0] = 0;
1398 hdr->dlength[1] = 0;
1399 hdr->dlength[2] = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301400 hdr->hlength = 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301401 hdr->itt = io_task->libiscsi_itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301402 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1403}
1404
1405static void
1406be_complete_tmf(struct beiscsi_conn *beiscsi_conn,
John Soni Jose73133262012-10-20 04:44:49 +05301407 struct iscsi_task *task,
1408 struct common_sol_cqe *csol_cqe)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301409{
1410 struct iscsi_tm_rsp *hdr;
1411 struct iscsi_conn *conn = beiscsi_conn->conn;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301412 struct beiscsi_io_task *io_task = task->dd_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301413
1414 hdr = (struct iscsi_tm_rsp *)task->hdr;
Jayamohan Kallickal7bd6e252010-01-05 05:07:02 +05301415 hdr->opcode = ISCSI_OP_SCSI_TMFUNC_RSP;
John Soni Jose73133262012-10-20 04:44:49 +05301416 hdr->flags = csol_cqe->i_flags;
1417 hdr->response = csol_cqe->i_resp;
Jayamohan Kallickal702dc5e2013-04-05 20:38:37 -07001418 hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn);
1419 hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn +
1420 csol_cqe->cmd_wnd - 1);
John Soni Jose73133262012-10-20 04:44:49 +05301421
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301422 hdr->itt = io_task->libiscsi_itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301423 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1424}
1425
1426static void
1427hwi_complete_drvr_msgs(struct beiscsi_conn *beiscsi_conn,
1428 struct beiscsi_hba *phba, struct sol_cqe *psol)
1429{
1430 struct hwi_wrb_context *pwrb_context;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301431 struct wrb_handle *pwrb_handle = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301432 struct hwi_controller *phwi_ctrlr;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301433 struct iscsi_task *task;
1434 struct beiscsi_io_task *io_task;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001435 uint16_t wrb_index, cid, cri_index;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301436
1437 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07001438 if (is_chip_be2_be3r(phba)) {
John Soni Jose73133262012-10-20 04:44:49 +05301439 wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe,
1440 wrb_idx, psol);
1441 cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe,
1442 cid, psol);
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07001443 } else {
1444 wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2,
1445 wrb_idx, psol);
1446 cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2,
1447 cid, psol);
John Soni Jose73133262012-10-20 04:44:49 +05301448 }
1449
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001450 cri_index = BE_GET_CRI_FROM_CID(cid);
1451 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
John Soni Jose73133262012-10-20 04:44:49 +05301452 pwrb_handle = pwrb_context->pwrb_handle_basestd[wrb_index];
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05301453 task = pwrb_handle->pio_handle;
Jayamohan Kallickal35e66012009-10-23 11:53:49 +05301454
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301455 io_task = task->dd_data;
Jayamohan Kallickal4a4a11b2013-04-05 20:38:31 -07001456 memset(io_task->pwrb_handle->pwrb, 0, sizeof(struct iscsi_wrb));
1457 iscsi_put_task(task);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301458}
1459
1460static void
1461be_complete_nopin_resp(struct beiscsi_conn *beiscsi_conn,
John Soni Jose73133262012-10-20 04:44:49 +05301462 struct iscsi_task *task,
1463 struct common_sol_cqe *csol_cqe)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301464{
1465 struct iscsi_nopin *hdr;
1466 struct iscsi_conn *conn = beiscsi_conn->conn;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301467 struct beiscsi_io_task *io_task = task->dd_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301468
1469 hdr = (struct iscsi_nopin *)task->hdr;
John Soni Jose73133262012-10-20 04:44:49 +05301470 hdr->flags = csol_cqe->i_flags;
1471 hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn);
Jayamohan Kallickal702dc5e2013-04-05 20:38:37 -07001472 hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn +
1473 csol_cqe->cmd_wnd - 1);
John Soni Jose73133262012-10-20 04:44:49 +05301474
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301475 hdr->opcode = ISCSI_OP_NOOP_IN;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301476 hdr->itt = io_task->libiscsi_itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301477 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1478}
1479
John Soni Jose73133262012-10-20 04:44:49 +05301480static void adapter_get_sol_cqe(struct beiscsi_hba *phba,
1481 struct sol_cqe *psol,
1482 struct common_sol_cqe *csol_cqe)
1483{
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07001484 if (is_chip_be2_be3r(phba)) {
1485 csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe,
1486 i_exp_cmd_sn, psol);
1487 csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe,
1488 i_res_cnt, psol);
1489 csol_cqe->cmd_wnd = AMAP_GET_BITS(struct amap_sol_cqe,
1490 i_cmd_wnd, psol);
1491 csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe,
1492 wrb_index, psol);
1493 csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe,
1494 cid, psol);
1495 csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe,
1496 hw_sts, psol);
1497 csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe,
1498 i_resp, psol);
1499 csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe,
1500 i_sts, psol);
1501 csol_cqe->i_flags = AMAP_GET_BITS(struct amap_sol_cqe,
1502 i_flags, psol);
1503 } else {
John Soni Jose73133262012-10-20 04:44:49 +05301504 csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1505 i_exp_cmd_sn, psol);
1506 csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1507 i_res_cnt, psol);
1508 csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1509 wrb_index, psol);
1510 csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1511 cid, psol);
1512 csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1513 hw_sts, psol);
Jayamohan Kallickal702dc5e2013-04-05 20:38:37 -07001514 csol_cqe->cmd_wnd = AMAP_GET_BITS(struct amap_sol_cqe_v2,
John Soni Jose73133262012-10-20 04:44:49 +05301515 i_cmd_wnd, psol);
1516 if (AMAP_GET_BITS(struct amap_sol_cqe_v2,
1517 cmd_cmpl, psol))
1518 csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1519 i_sts, psol);
1520 else
1521 csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1522 i_sts, psol);
1523 if (AMAP_GET_BITS(struct amap_sol_cqe_v2,
1524 u, psol))
1525 csol_cqe->i_flags = ISCSI_FLAG_CMD_UNDERFLOW;
1526
1527 if (AMAP_GET_BITS(struct amap_sol_cqe_v2,
1528 o, psol))
1529 csol_cqe->i_flags |= ISCSI_FLAG_CMD_OVERFLOW;
John Soni Jose73133262012-10-20 04:44:49 +05301530 }
1531}
1532
1533
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301534static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn,
1535 struct beiscsi_hba *phba, struct sol_cqe *psol)
1536{
1537 struct hwi_wrb_context *pwrb_context;
1538 struct wrb_handle *pwrb_handle;
1539 struct iscsi_wrb *pwrb = NULL;
1540 struct hwi_controller *phwi_ctrlr;
1541 struct iscsi_task *task;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301542 unsigned int type;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301543 struct iscsi_conn *conn = beiscsi_conn->conn;
1544 struct iscsi_session *session = conn->session;
John Soni Jose73133262012-10-20 04:44:49 +05301545 struct common_sol_cqe csol_cqe = {0};
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001546 uint16_t cri_index = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301547
1548 phwi_ctrlr = phba->phwi_ctrlr;
John Soni Jose73133262012-10-20 04:44:49 +05301549
1550 /* Copy the elements to a common structure */
1551 adapter_get_sol_cqe(phba, psol, &csol_cqe);
1552
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001553 cri_index = BE_GET_CRI_FROM_CID(csol_cqe.cid);
1554 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
John Soni Jose73133262012-10-20 04:44:49 +05301555
1556 pwrb_handle = pwrb_context->pwrb_handle_basestd[
1557 csol_cqe.wrb_index];
1558
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05301559 task = pwrb_handle->pio_handle;
1560 pwrb = pwrb_handle->pwrb;
John Soni Jose73133262012-10-20 04:44:49 +05301561 type = ((struct beiscsi_io_task *)task->dd_data)->wrb_type;
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05301562
Shlomo Pongratz659743b2014-02-07 00:41:38 -06001563 spin_lock_bh(&session->back_lock);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301564 switch (type) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301565 case HWH_TYPE_IO:
1566 case HWH_TYPE_IO_RD:
1567 if ((task->hdr->opcode & ISCSI_OPCODE_MASK) ==
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05301568 ISCSI_OP_NOOP_OUT)
John Soni Jose73133262012-10-20 04:44:49 +05301569 be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe);
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05301570 else
John Soni Jose73133262012-10-20 04:44:49 +05301571 be_complete_io(beiscsi_conn, task, &csol_cqe);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301572 break;
1573
1574 case HWH_TYPE_LOGOUT:
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05301575 if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGOUT)
John Soni Jose73133262012-10-20 04:44:49 +05301576 be_complete_logout(beiscsi_conn, task, &csol_cqe);
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05301577 else
John Soni Jose73133262012-10-20 04:44:49 +05301578 be_complete_tmf(beiscsi_conn, task, &csol_cqe);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301579 break;
1580
1581 case HWH_TYPE_LOGIN:
John Soni Jose99bc5d52012-08-20 23:00:18 +05301582 beiscsi_log(phba, KERN_ERR,
1583 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1584 "BM_%d :\t\t No HWH_TYPE_LOGIN Expected in"
1585 " hwi_complete_cmd- Solicited path\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301586 break;
1587
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301588 case HWH_TYPE_NOP:
John Soni Jose73133262012-10-20 04:44:49 +05301589 be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301590 break;
1591
1592 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +05301593 beiscsi_log(phba, KERN_WARNING,
1594 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1595 "BM_%d : In hwi_complete_cmd, unknown type = %d"
1596 "wrb_index 0x%x CID 0x%x\n", type,
John Soni Jose73133262012-10-20 04:44:49 +05301597 csol_cqe.wrb_index,
1598 csol_cqe.cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301599 break;
1600 }
Jayamohan Kallickal35e66012009-10-23 11:53:49 +05301601
Shlomo Pongratz659743b2014-02-07 00:41:38 -06001602 spin_unlock_bh(&session->back_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301603}
1604
1605static struct list_head *hwi_get_async_busy_list(struct hwi_async_pdu_context
1606 *pasync_ctx, unsigned int is_header,
1607 unsigned int host_write_ptr)
1608{
1609 if (is_header)
1610 return &pasync_ctx->async_entry[host_write_ptr].
1611 header_busy_list;
1612 else
1613 return &pasync_ctx->async_entry[host_write_ptr].data_busy_list;
1614}
1615
1616static struct async_pdu_handle *
1617hwi_get_async_handle(struct beiscsi_hba *phba,
1618 struct beiscsi_conn *beiscsi_conn,
1619 struct hwi_async_pdu_context *pasync_ctx,
1620 struct i_t_dpdu_cqe *pdpdu_cqe, unsigned int *pcq_index)
1621{
1622 struct be_bus_address phys_addr;
1623 struct list_head *pbusy_list;
1624 struct async_pdu_handle *pasync_handle = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301625 unsigned char is_header = 0;
John Soni Jose73133262012-10-20 04:44:49 +05301626 unsigned int index, dpl;
1627
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07001628 if (is_chip_be2_be3r(phba)) {
John Soni Jose73133262012-10-20 04:44:49 +05301629 dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe,
1630 dpl, pdpdu_cqe);
1631 index = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe,
1632 index, pdpdu_cqe);
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07001633 } else {
1634 dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2,
1635 dpl, pdpdu_cqe);
1636 index = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2,
1637 index, pdpdu_cqe);
John Soni Jose73133262012-10-20 04:44:49 +05301638 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301639
1640 phys_addr.u.a32.address_lo =
John Soni Jose73133262012-10-20 04:44:49 +05301641 (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
1642 db_addr_lo) / 32] - dpl);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301643 phys_addr.u.a32.address_hi =
John Soni Jose73133262012-10-20 04:44:49 +05301644 pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
1645 db_addr_hi) / 32];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301646
1647 phys_addr.u.a64.address =
1648 *((unsigned long long *)(&phys_addr.u.a64.address));
1649
1650 switch (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, code) / 32]
1651 & PDUCQE_CODE_MASK) {
1652 case UNSOL_HDR_NOTIFY:
1653 is_header = 1;
1654
John Soni Jose73133262012-10-20 04:44:49 +05301655 pbusy_list = hwi_get_async_busy_list(pasync_ctx,
1656 is_header, index);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301657 break;
1658 case UNSOL_DATA_NOTIFY:
John Soni Jose73133262012-10-20 04:44:49 +05301659 pbusy_list = hwi_get_async_busy_list(pasync_ctx,
1660 is_header, index);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301661 break;
1662 default:
1663 pbusy_list = NULL;
John Soni Jose99bc5d52012-08-20 23:00:18 +05301664 beiscsi_log(phba, KERN_WARNING,
1665 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1666 "BM_%d : Unexpected code=%d\n",
1667 pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
1668 code) / 32] & PDUCQE_CODE_MASK);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301669 return NULL;
1670 }
1671
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301672 WARN_ON(list_empty(pbusy_list));
1673 list_for_each_entry(pasync_handle, pbusy_list, link) {
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05001674 if (pasync_handle->pa.u.a64.address == phys_addr.u.a64.address)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301675 break;
1676 }
1677
1678 WARN_ON(!pasync_handle);
1679
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001680 pasync_handle->cri = BE_GET_ASYNC_CRI_FROM_CID(
1681 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301682 pasync_handle->is_header = is_header;
John Soni Jose73133262012-10-20 04:44:49 +05301683 pasync_handle->buffer_len = dpl;
1684 *pcq_index = index;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301685
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301686 return pasync_handle;
1687}
1688
1689static unsigned int
John Soni Jose99bc5d52012-08-20 23:00:18 +05301690hwi_update_async_writables(struct beiscsi_hba *phba,
1691 struct hwi_async_pdu_context *pasync_ctx,
1692 unsigned int is_header, unsigned int cq_index)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301693{
1694 struct list_head *pbusy_list;
1695 struct async_pdu_handle *pasync_handle;
1696 unsigned int num_entries, writables = 0;
1697 unsigned int *pep_read_ptr, *pwritables;
1698
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05001699 num_entries = pasync_ctx->num_entries;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301700 if (is_header) {
1701 pep_read_ptr = &pasync_ctx->async_header.ep_read_ptr;
1702 pwritables = &pasync_ctx->async_header.writables;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301703 } else {
1704 pep_read_ptr = &pasync_ctx->async_data.ep_read_ptr;
1705 pwritables = &pasync_ctx->async_data.writables;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301706 }
1707
1708 while ((*pep_read_ptr) != cq_index) {
1709 (*pep_read_ptr)++;
1710 *pep_read_ptr = (*pep_read_ptr) % num_entries;
1711
1712 pbusy_list = hwi_get_async_busy_list(pasync_ctx, is_header,
1713 *pep_read_ptr);
1714 if (writables == 0)
1715 WARN_ON(list_empty(pbusy_list));
1716
1717 if (!list_empty(pbusy_list)) {
1718 pasync_handle = list_entry(pbusy_list->next,
1719 struct async_pdu_handle,
1720 link);
1721 WARN_ON(!pasync_handle);
1722 pasync_handle->consumed = 1;
1723 }
1724
1725 writables++;
1726 }
1727
1728 if (!writables) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301729 beiscsi_log(phba, KERN_ERR,
1730 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1731 "BM_%d : Duplicate notification received - index 0x%x!!\n",
1732 cq_index);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301733 WARN_ON(1);
1734 }
1735
1736 *pwritables = *pwritables + writables;
1737 return 0;
1738}
1739
Jayamohan Kallickal9728d8d2012-04-03 23:41:47 -05001740static void hwi_free_async_msg(struct beiscsi_hba *phba,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001741 struct hwi_async_pdu_context *pasync_ctx,
1742 unsigned int cri)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301743{
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301744 struct async_pdu_handle *pasync_handle, *tmp_handle;
1745 struct list_head *plist;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301746
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301747 plist = &pasync_ctx->async_entry[cri].wait_queue.list;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301748 list_for_each_entry_safe(pasync_handle, tmp_handle, plist, link) {
1749 list_del(&pasync_handle->link);
1750
Jayamohan Kallickal9728d8d2012-04-03 23:41:47 -05001751 if (pasync_handle->is_header) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301752 list_add_tail(&pasync_handle->link,
1753 &pasync_ctx->async_header.free_list);
1754 pasync_ctx->async_header.free_entries++;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301755 } else {
1756 list_add_tail(&pasync_handle->link,
1757 &pasync_ctx->async_data.free_list);
1758 pasync_ctx->async_data.free_entries++;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301759 }
1760 }
1761
1762 INIT_LIST_HEAD(&pasync_ctx->async_entry[cri].wait_queue.list);
1763 pasync_ctx->async_entry[cri].wait_queue.hdr_received = 0;
1764 pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301765}
1766
1767static struct phys_addr *
1768hwi_get_ring_address(struct hwi_async_pdu_context *pasync_ctx,
1769 unsigned int is_header, unsigned int host_write_ptr)
1770{
1771 struct phys_addr *pasync_sge = NULL;
1772
1773 if (is_header)
1774 pasync_sge = pasync_ctx->async_header.ring_base;
1775 else
1776 pasync_sge = pasync_ctx->async_data.ring_base;
1777
1778 return pasync_sge + host_write_ptr;
1779}
1780
1781static void hwi_post_async_buffers(struct beiscsi_hba *phba,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001782 unsigned int is_header, uint8_t ulp_num)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301783{
1784 struct hwi_controller *phwi_ctrlr;
1785 struct hwi_async_pdu_context *pasync_ctx;
1786 struct async_pdu_handle *pasync_handle;
1787 struct list_head *pfree_link, *pbusy_list;
1788 struct phys_addr *pasync_sge;
1789 unsigned int ring_id, num_entries;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001790 unsigned int host_write_num, doorbell_offset;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301791 unsigned int writables;
1792 unsigned int i = 0;
1793 u32 doorbell = 0;
1794
1795 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001796 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr, ulp_num);
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05001797 num_entries = pasync_ctx->num_entries;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301798
1799 if (is_header) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301800 writables = min(pasync_ctx->async_header.writables,
1801 pasync_ctx->async_header.free_entries);
1802 pfree_link = pasync_ctx->async_header.free_list.next;
1803 host_write_num = pasync_ctx->async_header.host_write_ptr;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001804 ring_id = phwi_ctrlr->default_pdu_hdr[ulp_num].id;
1805 doorbell_offset = phwi_ctrlr->default_pdu_hdr[ulp_num].
1806 doorbell_offset;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301807 } else {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301808 writables = min(pasync_ctx->async_data.writables,
1809 pasync_ctx->async_data.free_entries);
1810 pfree_link = pasync_ctx->async_data.free_list.next;
1811 host_write_num = pasync_ctx->async_data.host_write_ptr;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001812 ring_id = phwi_ctrlr->default_pdu_data[ulp_num].id;
1813 doorbell_offset = phwi_ctrlr->default_pdu_data[ulp_num].
1814 doorbell_offset;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301815 }
1816
1817 writables = (writables / 8) * 8;
1818 if (writables) {
1819 for (i = 0; i < writables; i++) {
1820 pbusy_list =
1821 hwi_get_async_busy_list(pasync_ctx, is_header,
1822 host_write_num);
1823 pasync_handle =
1824 list_entry(pfree_link, struct async_pdu_handle,
1825 link);
1826 WARN_ON(!pasync_handle);
1827 pasync_handle->consumed = 0;
1828
1829 pfree_link = pfree_link->next;
1830
1831 pasync_sge = hwi_get_ring_address(pasync_ctx,
1832 is_header, host_write_num);
1833
1834 pasync_sge->hi = pasync_handle->pa.u.a32.address_lo;
1835 pasync_sge->lo = pasync_handle->pa.u.a32.address_hi;
1836
1837 list_move(&pasync_handle->link, pbusy_list);
1838
1839 host_write_num++;
1840 host_write_num = host_write_num % num_entries;
1841 }
1842
1843 if (is_header) {
1844 pasync_ctx->async_header.host_write_ptr =
1845 host_write_num;
1846 pasync_ctx->async_header.free_entries -= writables;
1847 pasync_ctx->async_header.writables -= writables;
1848 pasync_ctx->async_header.busy_entries += writables;
1849 } else {
1850 pasync_ctx->async_data.host_write_ptr = host_write_num;
1851 pasync_ctx->async_data.free_entries -= writables;
1852 pasync_ctx->async_data.writables -= writables;
1853 pasync_ctx->async_data.busy_entries += writables;
1854 }
1855
1856 doorbell |= ring_id & DB_DEF_PDU_RING_ID_MASK;
1857 doorbell |= 1 << DB_DEF_PDU_REARM_SHIFT;
1858 doorbell |= 0 << DB_DEF_PDU_EVENT_SHIFT;
1859 doorbell |= (writables & DB_DEF_PDU_CQPROC_MASK)
1860 << DB_DEF_PDU_CQPROC_SHIFT;
1861
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001862 iowrite32(doorbell, phba->db_va + doorbell_offset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301863 }
1864}
1865
1866static void hwi_flush_default_pdu_buffer(struct beiscsi_hba *phba,
1867 struct beiscsi_conn *beiscsi_conn,
1868 struct i_t_dpdu_cqe *pdpdu_cqe)
1869{
1870 struct hwi_controller *phwi_ctrlr;
1871 struct hwi_async_pdu_context *pasync_ctx;
1872 struct async_pdu_handle *pasync_handle = NULL;
1873 unsigned int cq_index = -1;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001874 uint16_t cri_index = BE_GET_CRI_FROM_CID(
1875 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301876
1877 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001878 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr,
1879 BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr,
1880 cri_index));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301881
1882 pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
1883 pdpdu_cqe, &cq_index);
1884 BUG_ON(pasync_handle->is_header != 0);
1885 if (pasync_handle->consumed == 0)
John Soni Jose99bc5d52012-08-20 23:00:18 +05301886 hwi_update_async_writables(phba, pasync_ctx,
1887 pasync_handle->is_header, cq_index);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301888
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001889 hwi_free_async_msg(phba, pasync_ctx, pasync_handle->cri);
1890 hwi_post_async_buffers(phba, pasync_handle->is_header,
1891 BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr,
1892 cri_index));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301893}
1894
1895static unsigned int
1896hwi_fwd_async_msg(struct beiscsi_conn *beiscsi_conn,
1897 struct beiscsi_hba *phba,
1898 struct hwi_async_pdu_context *pasync_ctx, unsigned short cri)
1899{
1900 struct list_head *plist;
1901 struct async_pdu_handle *pasync_handle;
1902 void *phdr = NULL;
1903 unsigned int hdr_len = 0, buf_len = 0;
1904 unsigned int status, index = 0, offset = 0;
1905 void *pfirst_buffer = NULL;
1906 unsigned int num_buf = 0;
1907
1908 plist = &pasync_ctx->async_entry[cri].wait_queue.list;
1909
1910 list_for_each_entry(pasync_handle, plist, link) {
1911 if (index == 0) {
1912 phdr = pasync_handle->pbuffer;
1913 hdr_len = pasync_handle->buffer_len;
1914 } else {
1915 buf_len = pasync_handle->buffer_len;
1916 if (!num_buf) {
1917 pfirst_buffer = pasync_handle->pbuffer;
1918 num_buf++;
1919 }
1920 memcpy(pfirst_buffer + offset,
1921 pasync_handle->pbuffer, buf_len);
Jayamohan Kallickalf2ba02b2012-04-03 23:41:37 -05001922 offset += buf_len;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301923 }
1924 index++;
1925 }
1926
1927 status = beiscsi_process_async_pdu(beiscsi_conn, phba,
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05301928 phdr, hdr_len, pfirst_buffer,
Jayamohan Kallickalf2ba02b2012-04-03 23:41:37 -05001929 offset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301930
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001931 hwi_free_async_msg(phba, pasync_ctx, cri);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301932 return 0;
1933}
1934
1935static unsigned int
1936hwi_gather_async_pdu(struct beiscsi_conn *beiscsi_conn,
1937 struct beiscsi_hba *phba,
1938 struct async_pdu_handle *pasync_handle)
1939{
1940 struct hwi_async_pdu_context *pasync_ctx;
1941 struct hwi_controller *phwi_ctrlr;
1942 unsigned int bytes_needed = 0, status = 0;
1943 unsigned short cri = pasync_handle->cri;
1944 struct pdu_base *ppdu;
1945
1946 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001947 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr,
1948 BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr,
1949 BE_GET_CRI_FROM_CID(beiscsi_conn->
1950 beiscsi_conn_cid)));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301951
1952 list_del(&pasync_handle->link);
1953 if (pasync_handle->is_header) {
1954 pasync_ctx->async_header.busy_entries--;
1955 if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) {
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001956 hwi_free_async_msg(phba, pasync_ctx, cri);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301957 BUG();
1958 }
1959
1960 pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0;
1961 pasync_ctx->async_entry[cri].wait_queue.hdr_received = 1;
1962 pasync_ctx->async_entry[cri].wait_queue.hdr_len =
1963 (unsigned short)pasync_handle->buffer_len;
1964 list_add_tail(&pasync_handle->link,
1965 &pasync_ctx->async_entry[cri].wait_queue.list);
1966
1967 ppdu = pasync_handle->pbuffer;
1968 bytes_needed = ((((ppdu->dw[offsetof(struct amap_pdu_base,
1969 data_len_hi) / 32] & PDUBASE_DATALENHI_MASK) << 8) &
1970 0xFFFF0000) | ((be16_to_cpu((ppdu->
1971 dw[offsetof(struct amap_pdu_base, data_len_lo) / 32]
1972 & PDUBASE_DATALENLO_MASK) >> 16)) & 0x0000FFFF));
1973
1974 if (status == 0) {
1975 pasync_ctx->async_entry[cri].wait_queue.bytes_needed =
1976 bytes_needed;
1977
1978 if (bytes_needed == 0)
1979 status = hwi_fwd_async_msg(beiscsi_conn, phba,
1980 pasync_ctx, cri);
1981 }
1982 } else {
1983 pasync_ctx->async_data.busy_entries--;
1984 if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) {
1985 list_add_tail(&pasync_handle->link,
1986 &pasync_ctx->async_entry[cri].wait_queue.
1987 list);
1988 pasync_ctx->async_entry[cri].wait_queue.
1989 bytes_received +=
1990 (unsigned short)pasync_handle->buffer_len;
1991
1992 if (pasync_ctx->async_entry[cri].wait_queue.
1993 bytes_received >=
1994 pasync_ctx->async_entry[cri].wait_queue.
1995 bytes_needed)
1996 status = hwi_fwd_async_msg(beiscsi_conn, phba,
1997 pasync_ctx, cri);
1998 }
1999 }
2000 return status;
2001}
2002
2003static void hwi_process_default_pdu_ring(struct beiscsi_conn *beiscsi_conn,
2004 struct beiscsi_hba *phba,
2005 struct i_t_dpdu_cqe *pdpdu_cqe)
2006{
2007 struct hwi_controller *phwi_ctrlr;
2008 struct hwi_async_pdu_context *pasync_ctx;
2009 struct async_pdu_handle *pasync_handle = NULL;
2010 unsigned int cq_index = -1;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002011 uint16_t cri_index = BE_GET_CRI_FROM_CID(
2012 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302013
2014 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002015 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr,
2016 BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr,
2017 cri_index));
2018
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302019 pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
2020 pdpdu_cqe, &cq_index);
2021
2022 if (pasync_handle->consumed == 0)
John Soni Jose99bc5d52012-08-20 23:00:18 +05302023 hwi_update_async_writables(phba, pasync_ctx,
2024 pasync_handle->is_header, cq_index);
2025
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302026 hwi_gather_async_pdu(beiscsi_conn, phba, pasync_handle);
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002027 hwi_post_async_buffers(phba, pasync_handle->is_header,
2028 BEISCSI_GET_ULP_FROM_CRI(
2029 phwi_ctrlr, cri_index));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302030}
2031
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05302032static void beiscsi_process_mcc_isr(struct beiscsi_hba *phba)
2033{
2034 struct be_queue_info *mcc_cq;
2035 struct be_mcc_compl *mcc_compl;
2036 unsigned int num_processed = 0;
2037
2038 mcc_cq = &phba->ctrl.mcc_obj.cq;
2039 mcc_compl = queue_tail_node(mcc_cq);
2040 mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
2041 while (mcc_compl->flags & CQE_FLAGS_VALID_MASK) {
2042
2043 if (num_processed >= 32) {
2044 hwi_ring_cq_db(phba, mcc_cq->id,
Jitendra Bhivare1094cf62016-01-20 14:10:56 +05302045 num_processed, 0);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05302046 num_processed = 0;
2047 }
2048 if (mcc_compl->flags & CQE_FLAGS_ASYNC_MASK) {
Jitendra Bhivare53aefe22016-01-20 14:10:53 +05302049 beiscsi_process_async_event(phba, mcc_compl);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05302050 } else if (mcc_compl->flags & CQE_FLAGS_COMPLETED_MASK) {
2051 be_mcc_compl_process_isr(&phba->ctrl, mcc_compl);
2052 atomic_dec(&phba->ctrl.mcc_obj.q.used);
2053 }
2054
2055 mcc_compl->flags = 0;
2056 queue_tail_inc(mcc_cq);
2057 mcc_compl = queue_tail_node(mcc_cq);
2058 mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
2059 num_processed++;
2060 }
2061
2062 if (num_processed > 0)
Jitendra Bhivare1094cf62016-01-20 14:10:56 +05302063 hwi_ring_cq_db(phba, mcc_cq->id, num_processed, 1);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05302064
2065}
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302066
John Soni Jose6763daa2012-10-20 04:41:45 +05302067/**
2068 * beiscsi_process_cq()- Process the Completion Queue
2069 * @pbe_eq: Event Q on which the Completion has come
Jitendra Bhivare1094cf62016-01-20 14:10:56 +05302070 * @budget: Max number of events to processed
John Soni Jose6763daa2012-10-20 04:41:45 +05302071 *
2072 * return
2073 * Number of Completion Entries processed.
2074 **/
Jitendra Bhivare1094cf62016-01-20 14:10:56 +05302075unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq, int budget)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302076{
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302077 struct be_queue_info *cq;
2078 struct sol_cqe *sol;
2079 struct dmsg_cqe *dmsg;
Jitendra Bhivare1094cf62016-01-20 14:10:56 +05302080 unsigned int total = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302081 unsigned int num_processed = 0;
John Soni Jose0a513dd2012-08-20 23:00:55 +05302082 unsigned short code = 0, cid = 0;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002083 uint16_t cri_index = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302084 struct beiscsi_conn *beiscsi_conn;
Jayamohan Kallickalc2462282010-01-05 05:05:34 +05302085 struct beiscsi_endpoint *beiscsi_ep;
2086 struct iscsi_endpoint *ep;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302087 struct beiscsi_hba *phba;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302088
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302089 cq = pbe_eq->cq;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302090 sol = queue_tail_node(cq);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302091 phba = pbe_eq->phba;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302092
2093 while (sol->dw[offsetof(struct amap_sol_cqe, valid) / 32] &
2094 CQE_VALID_MASK) {
2095 be_dws_le_to_cpu(sol, sizeof(struct sol_cqe));
2096
John Soni Jose73133262012-10-20 04:44:49 +05302097 code = (sol->dw[offsetof(struct amap_sol_cqe, code) /
2098 32] & CQE_CODE_MASK);
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05302099
John Soni Jose73133262012-10-20 04:44:49 +05302100 /* Get the CID */
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07002101 if (is_chip_be2_be3r(phba)) {
2102 cid = AMAP_GET_BITS(struct amap_sol_cqe, cid, sol);
2103 } else {
John Soni Jose73133262012-10-20 04:44:49 +05302104 if ((code == DRIVERMSG_NOTIFY) ||
2105 (code == UNSOL_HDR_NOTIFY) ||
2106 (code == UNSOL_DATA_NOTIFY))
2107 cid = AMAP_GET_BITS(
2108 struct amap_i_t_dpdu_cqe_v2,
2109 cid, sol);
2110 else
2111 cid = AMAP_GET_BITS(struct amap_sol_cqe_v2,
2112 cid, sol);
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07002113 }
John Soni Jose73133262012-10-20 04:44:49 +05302114
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002115 cri_index = BE_GET_CRI_FROM_CID(cid);
2116 ep = phba->ep_array[cri_index];
Jayamohan Kallickalb7ab35b2014-08-08 01:00:01 -04002117
2118 if (ep == NULL) {
2119 /* connection has already been freed
2120 * just move on to next one
2121 */
2122 beiscsi_log(phba, KERN_WARNING,
2123 BEISCSI_LOG_INIT,
2124 "BM_%d : proc cqe of disconn ep: cid %d\n",
2125 cid);
2126 goto proc_next_cqe;
2127 }
2128
Jayamohan Kallickalc2462282010-01-05 05:05:34 +05302129 beiscsi_ep = ep->dd_data;
2130 beiscsi_conn = beiscsi_ep->conn;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05302131
Jitendra Bhivare1094cf62016-01-20 14:10:56 +05302132 /* replenish cq */
2133 if (num_processed == 32) {
2134 hwi_ring_cq_db(phba, cq->id, 32, 0);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302135 num_processed = 0;
2136 }
Jitendra Bhivare1094cf62016-01-20 14:10:56 +05302137 total++;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302138
John Soni Jose0a513dd2012-08-20 23:00:55 +05302139 switch (code) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302140 case SOL_CMD_COMPLETE:
2141 hwi_complete_cmd(beiscsi_conn, phba, sol);
2142 break;
2143 case DRIVERMSG_NOTIFY:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302144 beiscsi_log(phba, KERN_INFO,
2145 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302146 "BM_%d : Received %s[%d] on CID : %d\n",
2147 cqe_desc[code], code, cid);
John Soni Jose99bc5d52012-08-20 23:00:18 +05302148
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302149 dmsg = (struct dmsg_cqe *)sol;
2150 hwi_complete_drvr_msgs(beiscsi_conn, phba, sol);
2151 break;
2152 case UNSOL_HDR_NOTIFY:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302153 beiscsi_log(phba, KERN_INFO,
2154 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302155 "BM_%d : Received %s[%d] on CID : %d\n",
2156 cqe_desc[code], code, cid);
John Soni Jose99bc5d52012-08-20 23:00:18 +05302157
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07002158 spin_lock_bh(&phba->async_pdu_lock);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302159 hwi_process_default_pdu_ring(beiscsi_conn, phba,
2160 (struct i_t_dpdu_cqe *)sol);
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07002161 spin_unlock_bh(&phba->async_pdu_lock);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302162 break;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302163 case UNSOL_DATA_NOTIFY:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302164 beiscsi_log(phba, KERN_INFO,
2165 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
John Soni Jose6763daa2012-10-20 04:41:45 +05302166 "BM_%d : Received %s[%d] on CID : %d\n",
2167 cqe_desc[code], code, cid);
John Soni Jose99bc5d52012-08-20 23:00:18 +05302168
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07002169 spin_lock_bh(&phba->async_pdu_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302170 hwi_process_default_pdu_ring(beiscsi_conn, phba,
2171 (struct i_t_dpdu_cqe *)sol);
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07002172 spin_unlock_bh(&phba->async_pdu_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302173 break;
2174 case CXN_INVALIDATE_INDEX_NOTIFY:
2175 case CMD_INVALIDATED_NOTIFY:
2176 case CXN_INVALIDATE_NOTIFY:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302177 beiscsi_log(phba, KERN_ERR,
2178 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302179 "BM_%d : Ignoring %s[%d] on CID : %d\n",
2180 cqe_desc[code], code, cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302181 break;
Jitendra Bhivare1094cf62016-01-20 14:10:56 +05302182 case CXN_KILLED_HDR_DIGEST_ERR:
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302183 case SOL_CMD_KILLED_DATA_DIGEST_ERR:
Jitendra Bhivare1094cf62016-01-20 14:10:56 +05302184 beiscsi_log(phba, KERN_ERR,
2185 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
2186 "BM_%d : Cmd Notification %s[%d] on CID : %d\n",
2187 cqe_desc[code], code, cid);
2188 break;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302189 case CMD_KILLED_INVALID_STATSN_RCVD:
2190 case CMD_KILLED_INVALID_R2T_RCVD:
2191 case CMD_CXN_KILLED_LUN_INVALID:
2192 case CMD_CXN_KILLED_ICD_INVALID:
2193 case CMD_CXN_KILLED_ITT_INVALID:
2194 case CMD_CXN_KILLED_SEQ_OUTOFORDER:
2195 case CMD_CXN_KILLED_INVALID_DATASN_RCVD:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302196 beiscsi_log(phba, KERN_ERR,
2197 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
John Soni Jose6763daa2012-10-20 04:41:45 +05302198 "BM_%d : Cmd Notification %s[%d] on CID : %d\n",
2199 cqe_desc[code], code, cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302200 break;
2201 case UNSOL_DATA_DIGEST_ERROR_NOTIFY:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302202 beiscsi_log(phba, KERN_ERR,
2203 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302204 "BM_%d : Dropping %s[%d] on DPDU ring on CID : %d\n",
2205 cqe_desc[code], code, cid);
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07002206 spin_lock_bh(&phba->async_pdu_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302207 hwi_flush_default_pdu_buffer(phba, beiscsi_conn,
2208 (struct i_t_dpdu_cqe *) sol);
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07002209 spin_unlock_bh(&phba->async_pdu_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302210 break;
2211 case CXN_KILLED_PDU_SIZE_EXCEEDS_DSL:
2212 case CXN_KILLED_BURST_LEN_MISMATCH:
2213 case CXN_KILLED_AHS_RCVD:
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302214 case CXN_KILLED_UNKNOWN_HDR:
2215 case CXN_KILLED_STALE_ITT_TTT_RCVD:
2216 case CXN_KILLED_INVALID_ITT_TTT_RCVD:
2217 case CXN_KILLED_TIMED_OUT:
2218 case CXN_KILLED_FIN_RCVD:
John Soni Jose6763daa2012-10-20 04:41:45 +05302219 case CXN_KILLED_RST_SENT:
2220 case CXN_KILLED_RST_RCVD:
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302221 case CXN_KILLED_BAD_UNSOL_PDU_RCVD:
2222 case CXN_KILLED_BAD_WRB_INDEX_ERROR:
2223 case CXN_KILLED_OVER_RUN_RESIDUAL:
2224 case CXN_KILLED_UNDER_RUN_RESIDUAL:
2225 case CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302226 beiscsi_log(phba, KERN_ERR,
2227 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302228 "BM_%d : Event %s[%d] received on CID : %d\n",
2229 cqe_desc[code], code, cid);
John Soni Jose0a513dd2012-08-20 23:00:55 +05302230 if (beiscsi_conn)
2231 iscsi_conn_failure(beiscsi_conn->conn,
2232 ISCSI_ERR_CONN_FAILED);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302233 break;
2234 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302235 beiscsi_log(phba, KERN_ERR,
2236 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302237 "BM_%d : Invalid CQE Event Received Code : %d"
2238 "CID 0x%x...\n",
John Soni Jose0a513dd2012-08-20 23:00:55 +05302239 code, cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302240 break;
2241 }
2242
Jayamohan Kallickalb7ab35b2014-08-08 01:00:01 -04002243proc_next_cqe:
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302244 AMAP_SET_BITS(struct amap_sol_cqe, valid, sol, 0);
2245 queue_tail_inc(cq);
2246 sol = queue_tail_node(cq);
2247 num_processed++;
Jitendra Bhivare1094cf62016-01-20 14:10:56 +05302248 if (total == budget)
2249 break;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302250 }
2251
Jitendra Bhivare1094cf62016-01-20 14:10:56 +05302252 hwi_ring_cq_db(phba, cq->id, num_processed, 1);
2253 return total;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302254}
2255
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05302256void beiscsi_process_all_cqs(struct work_struct *work)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302257{
2258 unsigned long flags;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302259 struct hwi_controller *phwi_ctrlr;
2260 struct hwi_context_memory *phwi_context;
John Soni Jose72fb46a2012-10-20 04:42:49 +05302261 struct beiscsi_hba *phba;
2262 struct be_eq_obj *pbe_eq =
2263 container_of(work, struct be_eq_obj, work_cqs);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302264
John Soni Jose72fb46a2012-10-20 04:42:49 +05302265 phba = pbe_eq->phba;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302266 phwi_ctrlr = phba->phwi_ctrlr;
2267 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302268
John Soni Jose72fb46a2012-10-20 04:42:49 +05302269 if (pbe_eq->todo_mcc_cq) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302270 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +05302271 pbe_eq->todo_mcc_cq = false;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302272 spin_unlock_irqrestore(&phba->isr_lock, flags);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05302273 beiscsi_process_mcc_isr(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302274 }
2275
John Soni Jose72fb46a2012-10-20 04:42:49 +05302276 if (pbe_eq->todo_cq) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302277 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +05302278 pbe_eq->todo_cq = false;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302279 spin_unlock_irqrestore(&phba->isr_lock, flags);
Jitendra Bhivare1094cf62016-01-20 14:10:56 +05302280 beiscsi_process_cq(pbe_eq, BE2_MAX_NUM_CQ_PROC);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302281 }
John Soni Jose72fb46a2012-10-20 04:42:49 +05302282
2283 /* rearm EQ for further interrupts */
2284 hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302285}
2286
Christoph Hellwig511cbce2015-11-10 14:56:14 +01002287static int be_iopoll(struct irq_poll *iop, int budget)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302288{
Jitendra Bhivare1094cf62016-01-20 14:10:56 +05302289 unsigned int ret, num_eq_processed;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302290 struct beiscsi_hba *phba;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302291 struct be_eq_obj *pbe_eq;
Jitendra Bhivare1094cf62016-01-20 14:10:56 +05302292 struct be_eq_entry *eqe = NULL;
2293 struct be_queue_info *eq;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302294
Jitendra Bhivare1094cf62016-01-20 14:10:56 +05302295 num_eq_processed = 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302296 pbe_eq = container_of(iop, struct be_eq_obj, iopoll);
Jitendra Bhivare1094cf62016-01-20 14:10:56 +05302297 phba = pbe_eq->phba;
2298 eq = &pbe_eq->q;
2299 eqe = queue_tail_node(eq);
2300
2301 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32] &
2302 EQE_VALID_MASK) {
2303 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
2304 queue_tail_inc(eq);
2305 eqe = queue_tail_node(eq);
2306 num_eq_processed++;
2307 }
2308
2309 hwi_ring_eq_db(phba, eq->id, 1, num_eq_processed, 0, 1);
2310
2311 ret = beiscsi_process_cq(pbe_eq, budget);
Jayamohan Kallickal73af08e2014-05-05 21:41:26 -04002312 pbe_eq->cq_count += ret;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302313 if (ret < budget) {
Christoph Hellwig511cbce2015-11-10 14:56:14 +01002314 irq_poll_complete(iop);
John Soni Jose99bc5d52012-08-20 23:00:18 +05302315 beiscsi_log(phba, KERN_INFO,
2316 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
Jitendra Bhivare1094cf62016-01-20 14:10:56 +05302317 "BM_%d : rearm pbe_eq->q.id =%d ret %d\n",
2318 pbe_eq->q.id, ret);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302319 hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302320 }
2321 return ret;
2322}
2323
2324static void
John Soni Jose09a10932012-10-20 04:44:23 +05302325hwi_write_sgl_v2(struct iscsi_wrb *pwrb, struct scatterlist *sg,
2326 unsigned int num_sg, struct beiscsi_io_task *io_task)
2327{
2328 struct iscsi_sge *psgl;
2329 unsigned int sg_len, index;
2330 unsigned int sge_len = 0;
2331 unsigned long long addr;
2332 struct scatterlist *l_sg;
2333 unsigned int offset;
2334
2335 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_lo, pwrb,
2336 io_task->bhs_pa.u.a32.address_lo);
2337 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_hi, pwrb,
2338 io_task->bhs_pa.u.a32.address_hi);
2339
2340 l_sg = sg;
2341 for (index = 0; (index < num_sg) && (index < 2); index++,
2342 sg = sg_next(sg)) {
2343 if (index == 0) {
2344 sg_len = sg_dma_len(sg);
2345 addr = (u64) sg_dma_address(sg);
2346 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2347 sge0_addr_lo, pwrb,
2348 lower_32_bits(addr));
2349 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2350 sge0_addr_hi, pwrb,
2351 upper_32_bits(addr));
2352 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2353 sge0_len, pwrb,
2354 sg_len);
2355 sge_len = sg_len;
2356 } else {
2357 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_r2t_offset,
2358 pwrb, sge_len);
2359 sg_len = sg_dma_len(sg);
2360 addr = (u64) sg_dma_address(sg);
2361 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2362 sge1_addr_lo, pwrb,
2363 lower_32_bits(addr));
2364 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2365 sge1_addr_hi, pwrb,
2366 upper_32_bits(addr));
2367 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2368 sge1_len, pwrb,
2369 sg_len);
2370 }
2371 }
2372 psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
2373 memset(psgl, 0, sizeof(*psgl) * BE2_SGE);
2374
2375 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2);
2376
2377 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2378 io_task->bhs_pa.u.a32.address_hi);
2379 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2380 io_task->bhs_pa.u.a32.address_lo);
2381
2382 if (num_sg == 1) {
2383 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb,
2384 1);
2385 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb,
2386 0);
2387 } else if (num_sg == 2) {
2388 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb,
2389 0);
2390 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb,
2391 1);
2392 } else {
2393 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb,
2394 0);
2395 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb,
2396 0);
2397 }
2398
2399 sg = l_sg;
2400 psgl++;
2401 psgl++;
2402 offset = 0;
2403 for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) {
2404 sg_len = sg_dma_len(sg);
2405 addr = (u64) sg_dma_address(sg);
2406 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2407 lower_32_bits(addr));
2408 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2409 upper_32_bits(addr));
2410 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len);
2411 AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset);
2412 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
2413 offset += sg_len;
2414 }
2415 psgl--;
2416 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
2417}
2418
2419static void
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302420hwi_write_sgl(struct iscsi_wrb *pwrb, struct scatterlist *sg,
2421 unsigned int num_sg, struct beiscsi_io_task *io_task)
2422{
2423 struct iscsi_sge *psgl;
Jayamohan Kallickal58ff4bd2010-10-06 23:46:47 +05302424 unsigned int sg_len, index;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302425 unsigned int sge_len = 0;
2426 unsigned long long addr;
2427 struct scatterlist *l_sg;
2428 unsigned int offset;
2429
2430 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
2431 io_task->bhs_pa.u.a32.address_lo);
2432 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
2433 io_task->bhs_pa.u.a32.address_hi);
2434
2435 l_sg = sg;
Jayamohan Kallickal48bd86c2010-01-07 01:50:19 +05302436 for (index = 0; (index < num_sg) && (index < 2); index++,
2437 sg = sg_next(sg)) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302438 if (index == 0) {
2439 sg_len = sg_dma_len(sg);
2440 addr = (u64) sg_dma_address(sg);
2441 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302442 ((u32)(addr & 0xFFFFFFFF)));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302443 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302444 ((u32)(addr >> 32)));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302445 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
2446 sg_len);
2447 sge_len = sg_len;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302448 } else {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302449 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_r2t_offset,
2450 pwrb, sge_len);
2451 sg_len = sg_dma_len(sg);
2452 addr = (u64) sg_dma_address(sg);
2453 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_lo, pwrb,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302454 ((u32)(addr & 0xFFFFFFFF)));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302455 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_hi, pwrb,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302456 ((u32)(addr >> 32)));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302457 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_len, pwrb,
2458 sg_len);
2459 }
2460 }
2461 psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
2462 memset(psgl, 0, sizeof(*psgl) * BE2_SGE);
2463
2464 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2);
2465
2466 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2467 io_task->bhs_pa.u.a32.address_hi);
2468 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2469 io_task->bhs_pa.u.a32.address_lo);
2470
Jayamohan Kallickalcaf818f2010-01-23 05:38:18 +05302471 if (num_sg == 1) {
2472 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
2473 1);
2474 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
2475 0);
2476 } else if (num_sg == 2) {
2477 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
2478 0);
2479 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
2480 1);
2481 } else {
2482 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
2483 0);
2484 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
2485 0);
2486 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302487 sg = l_sg;
2488 psgl++;
2489 psgl++;
2490 offset = 0;
Jayamohan Kallickal48bd86c2010-01-07 01:50:19 +05302491 for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302492 sg_len = sg_dma_len(sg);
2493 addr = (u64) sg_dma_address(sg);
2494 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2495 (addr & 0xFFFFFFFF));
2496 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2497 (addr >> 32));
2498 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len);
2499 AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset);
2500 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
2501 offset += sg_len;
2502 }
2503 psgl--;
2504 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
2505}
2506
John Soni Josed629c472012-10-20 04:42:00 +05302507/**
2508 * hwi_write_buffer()- Populate the WRB with task info
2509 * @pwrb: ptr to the WRB entry
2510 * @task: iscsi task which is to be executed
2511 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302512static void hwi_write_buffer(struct iscsi_wrb *pwrb, struct iscsi_task *task)
2513{
2514 struct iscsi_sge *psgl;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302515 struct beiscsi_io_task *io_task = task->dd_data;
2516 struct beiscsi_conn *beiscsi_conn = io_task->conn;
2517 struct beiscsi_hba *phba = beiscsi_conn->phba;
John Soni Jose09a10932012-10-20 04:44:23 +05302518 uint8_t dsp_value = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302519
2520 io_task->bhs_len = sizeof(struct be_nonio_bhs) - 2;
2521 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
2522 io_task->bhs_pa.u.a32.address_lo);
2523 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
2524 io_task->bhs_pa.u.a32.address_hi);
2525
2526 if (task->data) {
John Soni Jose09a10932012-10-20 04:44:23 +05302527
2528 /* Check for the data_count */
2529 dsp_value = (task->data_count) ? 1 : 0;
2530
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07002531 if (is_chip_be2_be3r(phba))
2532 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp,
John Soni Jose09a10932012-10-20 04:44:23 +05302533 pwrb, dsp_value);
2534 else
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07002535 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp,
John Soni Jose09a10932012-10-20 04:44:23 +05302536 pwrb, dsp_value);
2537
2538 /* Map addr only if there is data_count */
2539 if (dsp_value) {
John Soni Josed629c472012-10-20 04:42:00 +05302540 io_task->mtask_addr = pci_map_single(phba->pcidev,
2541 task->data,
2542 task->data_count,
2543 PCI_DMA_TODEVICE);
John Soni Josed629c472012-10-20 04:42:00 +05302544 io_task->mtask_data_count = task->data_count;
John Soni Jose09a10932012-10-20 04:44:23 +05302545 } else
John Soni Josed629c472012-10-20 04:42:00 +05302546 io_task->mtask_addr = 0;
John Soni Jose09a10932012-10-20 04:44:23 +05302547
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302548 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
John Soni Josed629c472012-10-20 04:42:00 +05302549 lower_32_bits(io_task->mtask_addr));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302550 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
John Soni Josed629c472012-10-20 04:42:00 +05302551 upper_32_bits(io_task->mtask_addr));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302552 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
2553 task->data_count);
2554
2555 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, 1);
2556 } else {
2557 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
John Soni Josed629c472012-10-20 04:42:00 +05302558 io_task->mtask_addr = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302559 }
2560
2561 psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
2562
2563 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len);
2564
2565 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2566 io_task->bhs_pa.u.a32.address_hi);
2567 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2568 io_task->bhs_pa.u.a32.address_lo);
2569 if (task->data) {
2570 psgl++;
2571 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, 0);
2572 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, 0);
2573 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0);
2574 AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, 0);
2575 AMAP_SET_BITS(struct amap_iscsi_sge, rsvd0, psgl, 0);
2576 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
2577
2578 psgl++;
2579 if (task->data) {
2580 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
John Soni Josed629c472012-10-20 04:42:00 +05302581 lower_32_bits(io_task->mtask_addr));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302582 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
John Soni Josed629c472012-10-20 04:42:00 +05302583 upper_32_bits(io_task->mtask_addr));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302584 }
2585 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0x106);
2586 }
2587 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
2588}
2589
Jayamohan Kallickal843ae752013-09-28 15:35:44 -07002590/**
2591 * beiscsi_find_mem_req()- Find mem needed
2592 * @phba: ptr to HBA struct
2593 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302594static void beiscsi_find_mem_req(struct beiscsi_hba *phba)
2595{
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002596 uint8_t mem_descr_index, ulp_num;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302597 unsigned int num_cq_pages, num_async_pdu_buf_pages;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302598 unsigned int num_async_pdu_data_pages, wrb_sz_per_cxn;
2599 unsigned int num_async_pdu_buf_sgl_pages, num_async_pdu_data_sgl_pages;
2600
2601 num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
2602 sizeof(struct sol_cqe));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302603
2604 phba->params.hwi_ws_sz = sizeof(struct hwi_controller);
2605
2606 phba->mem_req[ISCSI_MEM_GLOBAL_HEADER] = 2 *
2607 BE_ISCSI_PDU_HEADER_SIZE;
2608 phba->mem_req[HWI_MEM_ADDN_CONTEXT] =
2609 sizeof(struct hwi_context_memory);
2610
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302611
2612 phba->mem_req[HWI_MEM_WRB] = sizeof(struct iscsi_wrb)
2613 * (phba->params.wrbs_per_cxn)
2614 * phba->params.cxns_per_ctrl;
2615 wrb_sz_per_cxn = sizeof(struct wrb_handle) *
2616 (phba->params.wrbs_per_cxn);
2617 phba->mem_req[HWI_MEM_WRBH] = roundup_pow_of_two((wrb_sz_per_cxn) *
2618 phba->params.cxns_per_ctrl);
2619
2620 phba->mem_req[HWI_MEM_SGLH] = sizeof(struct sgl_handle) *
2621 phba->params.icds_per_ctrl;
2622 phba->mem_req[HWI_MEM_SGE] = sizeof(struct iscsi_sge) *
2623 phba->params.num_sge_per_io * phba->params.icds_per_ctrl;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002624 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
2625 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302626
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002627 num_async_pdu_buf_sgl_pages =
2628 PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
2629 phba, ulp_num) *
2630 sizeof(struct phys_addr));
2631
2632 num_async_pdu_buf_pages =
2633 PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
2634 phba, ulp_num) *
2635 phba->params.defpdu_hdr_sz);
2636
2637 num_async_pdu_data_pages =
2638 PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
2639 phba, ulp_num) *
2640 phba->params.defpdu_data_sz);
2641
2642 num_async_pdu_data_sgl_pages =
2643 PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
2644 phba, ulp_num) *
2645 sizeof(struct phys_addr));
2646
Jayamohan Kallickala129d922013-09-28 15:35:46 -07002647 mem_descr_index = (HWI_MEM_TEMPLATE_HDR_ULP0 +
2648 (ulp_num * MEM_DESCR_OFFSET));
2649 phba->mem_req[mem_descr_index] =
2650 BEISCSI_GET_CID_COUNT(phba, ulp_num) *
2651 BEISCSI_TEMPLATE_HDR_PER_CXN_SIZE;
2652
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002653 mem_descr_index = (HWI_MEM_ASYNC_HEADER_BUF_ULP0 +
2654 (ulp_num * MEM_DESCR_OFFSET));
2655 phba->mem_req[mem_descr_index] =
2656 num_async_pdu_buf_pages *
2657 PAGE_SIZE;
2658
2659 mem_descr_index = (HWI_MEM_ASYNC_DATA_BUF_ULP0 +
2660 (ulp_num * MEM_DESCR_OFFSET));
2661 phba->mem_req[mem_descr_index] =
2662 num_async_pdu_data_pages *
2663 PAGE_SIZE;
2664
2665 mem_descr_index = (HWI_MEM_ASYNC_HEADER_RING_ULP0 +
2666 (ulp_num * MEM_DESCR_OFFSET));
2667 phba->mem_req[mem_descr_index] =
2668 num_async_pdu_buf_sgl_pages *
2669 PAGE_SIZE;
2670
2671 mem_descr_index = (HWI_MEM_ASYNC_DATA_RING_ULP0 +
2672 (ulp_num * MEM_DESCR_OFFSET));
2673 phba->mem_req[mem_descr_index] =
2674 num_async_pdu_data_sgl_pages *
2675 PAGE_SIZE;
2676
2677 mem_descr_index = (HWI_MEM_ASYNC_HEADER_HANDLE_ULP0 +
2678 (ulp_num * MEM_DESCR_OFFSET));
2679 phba->mem_req[mem_descr_index] =
2680 BEISCSI_GET_CID_COUNT(phba, ulp_num) *
2681 sizeof(struct async_pdu_handle);
2682
2683 mem_descr_index = (HWI_MEM_ASYNC_DATA_HANDLE_ULP0 +
2684 (ulp_num * MEM_DESCR_OFFSET));
2685 phba->mem_req[mem_descr_index] =
2686 BEISCSI_GET_CID_COUNT(phba, ulp_num) *
2687 sizeof(struct async_pdu_handle);
2688
2689 mem_descr_index = (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0 +
2690 (ulp_num * MEM_DESCR_OFFSET));
2691 phba->mem_req[mem_descr_index] =
2692 sizeof(struct hwi_async_pdu_context) +
2693 (BEISCSI_GET_CID_COUNT(phba, ulp_num) *
2694 sizeof(struct hwi_async_entry));
2695 }
2696 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302697}
2698
2699static int beiscsi_alloc_mem(struct beiscsi_hba *phba)
2700{
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302701 dma_addr_t bus_add;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002702 struct hwi_controller *phwi_ctrlr;
2703 struct be_mem_descriptor *mem_descr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302704 struct mem_array *mem_arr, *mem_arr_orig;
2705 unsigned int i, j, alloc_size, curr_alloc_size;
2706
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002707 phba->phwi_ctrlr = kzalloc(phba->params.hwi_ws_sz, GFP_KERNEL);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302708 if (!phba->phwi_ctrlr)
2709 return -ENOMEM;
2710
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002711 /* Allocate memory for wrb_context */
2712 phwi_ctrlr = phba->phwi_ctrlr;
2713 phwi_ctrlr->wrb_context = kzalloc(sizeof(struct hwi_wrb_context) *
2714 phba->params.cxns_per_ctrl,
2715 GFP_KERNEL);
2716 if (!phwi_ctrlr->wrb_context)
2717 return -ENOMEM;
2718
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302719 phba->init_mem = kcalloc(SE_MEM_MAX, sizeof(*mem_descr),
2720 GFP_KERNEL);
2721 if (!phba->init_mem) {
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002722 kfree(phwi_ctrlr->wrb_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302723 kfree(phba->phwi_ctrlr);
2724 return -ENOMEM;
2725 }
2726
2727 mem_arr_orig = kmalloc(sizeof(*mem_arr_orig) * BEISCSI_MAX_FRAGS_INIT,
2728 GFP_KERNEL);
2729 if (!mem_arr_orig) {
2730 kfree(phba->init_mem);
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002731 kfree(phwi_ctrlr->wrb_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302732 kfree(phba->phwi_ctrlr);
2733 return -ENOMEM;
2734 }
2735
2736 mem_descr = phba->init_mem;
2737 for (i = 0; i < SE_MEM_MAX; i++) {
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002738 if (!phba->mem_req[i]) {
2739 mem_descr->mem_array = NULL;
2740 mem_descr++;
2741 continue;
2742 }
2743
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302744 j = 0;
2745 mem_arr = mem_arr_orig;
2746 alloc_size = phba->mem_req[i];
2747 memset(mem_arr, 0, sizeof(struct mem_array) *
2748 BEISCSI_MAX_FRAGS_INIT);
2749 curr_alloc_size = min(be_max_phys_size * 1024, alloc_size);
2750 do {
2751 mem_arr->virtual_address = pci_alloc_consistent(
2752 phba->pcidev,
2753 curr_alloc_size,
2754 &bus_add);
2755 if (!mem_arr->virtual_address) {
2756 if (curr_alloc_size <= BE_MIN_MEM_SIZE)
2757 goto free_mem;
2758 if (curr_alloc_size -
2759 rounddown_pow_of_two(curr_alloc_size))
2760 curr_alloc_size = rounddown_pow_of_two
2761 (curr_alloc_size);
2762 else
2763 curr_alloc_size = curr_alloc_size / 2;
2764 } else {
2765 mem_arr->bus_address.u.
2766 a64.address = (__u64) bus_add;
2767 mem_arr->size = curr_alloc_size;
2768 alloc_size -= curr_alloc_size;
2769 curr_alloc_size = min(be_max_phys_size *
2770 1024, alloc_size);
2771 j++;
2772 mem_arr++;
2773 }
2774 } while (alloc_size);
2775 mem_descr->num_elements = j;
2776 mem_descr->size_in_bytes = phba->mem_req[i];
2777 mem_descr->mem_array = kmalloc(sizeof(*mem_arr) * j,
2778 GFP_KERNEL);
2779 if (!mem_descr->mem_array)
2780 goto free_mem;
2781
2782 memcpy(mem_descr->mem_array, mem_arr_orig,
2783 sizeof(struct mem_array) * j);
2784 mem_descr++;
2785 }
2786 kfree(mem_arr_orig);
2787 return 0;
2788free_mem:
2789 mem_descr->num_elements = j;
2790 while ((i) || (j)) {
2791 for (j = mem_descr->num_elements; j > 0; j--) {
2792 pci_free_consistent(phba->pcidev,
2793 mem_descr->mem_array[j - 1].size,
2794 mem_descr->mem_array[j - 1].
2795 virtual_address,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302796 (unsigned long)mem_descr->
2797 mem_array[j - 1].
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302798 bus_address.u.a64.address);
2799 }
2800 if (i) {
2801 i--;
2802 kfree(mem_descr->mem_array);
2803 mem_descr--;
2804 }
2805 }
2806 kfree(mem_arr_orig);
2807 kfree(phba->init_mem);
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002808 kfree(phba->phwi_ctrlr->wrb_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302809 kfree(phba->phwi_ctrlr);
2810 return -ENOMEM;
2811}
2812
2813static int beiscsi_get_memory(struct beiscsi_hba *phba)
2814{
2815 beiscsi_find_mem_req(phba);
2816 return beiscsi_alloc_mem(phba);
2817}
2818
2819static void iscsi_init_global_templates(struct beiscsi_hba *phba)
2820{
2821 struct pdu_data_out *pdata_out;
2822 struct pdu_nop_out *pnop_out;
2823 struct be_mem_descriptor *mem_descr;
2824
2825 mem_descr = phba->init_mem;
2826 mem_descr += ISCSI_MEM_GLOBAL_HEADER;
2827 pdata_out =
2828 (struct pdu_data_out *)mem_descr->mem_array[0].virtual_address;
2829 memset(pdata_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
2830
2831 AMAP_SET_BITS(struct amap_pdu_data_out, opcode, pdata_out,
2832 IIOC_SCSI_DATA);
2833
2834 pnop_out =
2835 (struct pdu_nop_out *)((unsigned char *)mem_descr->mem_array[0].
2836 virtual_address + BE_ISCSI_PDU_HEADER_SIZE);
2837
2838 memset(pnop_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
2839 AMAP_SET_BITS(struct amap_pdu_nop_out, ttt, pnop_out, 0xFFFFFFFF);
2840 AMAP_SET_BITS(struct amap_pdu_nop_out, f_bit, pnop_out, 1);
2841 AMAP_SET_BITS(struct amap_pdu_nop_out, i_bit, pnop_out, 0);
2842}
2843
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002844static int beiscsi_init_wrb_handle(struct beiscsi_hba *phba)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302845{
2846 struct be_mem_descriptor *mem_descr_wrbh, *mem_descr_wrb;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002847 struct hwi_context_memory *phwi_ctxt;
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002848 struct wrb_handle *pwrb_handle = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302849 struct hwi_controller *phwi_ctrlr;
2850 struct hwi_wrb_context *pwrb_context;
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002851 struct iscsi_wrb *pwrb = NULL;
2852 unsigned int num_cxn_wrbh = 0;
2853 unsigned int num_cxn_wrb = 0, j, idx = 0, index;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302854
2855 mem_descr_wrbh = phba->init_mem;
2856 mem_descr_wrbh += HWI_MEM_WRBH;
2857
2858 mem_descr_wrb = phba->init_mem;
2859 mem_descr_wrb += HWI_MEM_WRB;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302860 phwi_ctrlr = phba->phwi_ctrlr;
2861
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002862 /* Allocate memory for WRBQ */
2863 phwi_ctxt = phwi_ctrlr->phwi_ctxt;
2864 phwi_ctxt->be_wrbq = kzalloc(sizeof(struct be_queue_info) *
Jayamohan Kallickal843ae752013-09-28 15:35:44 -07002865 phba->params.cxns_per_ctrl,
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002866 GFP_KERNEL);
2867 if (!phwi_ctxt->be_wrbq) {
2868 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2869 "BM_%d : WRBQ Mem Alloc Failed\n");
2870 return -ENOMEM;
2871 }
2872
2873 for (index = 0; index < phba->params.cxns_per_ctrl; index++) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302874 pwrb_context = &phwi_ctrlr->wrb_context[index];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302875 pwrb_context->pwrb_handle_base =
2876 kzalloc(sizeof(struct wrb_handle *) *
2877 phba->params.wrbs_per_cxn, GFP_KERNEL);
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002878 if (!pwrb_context->pwrb_handle_base) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05302879 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2880 "BM_%d : Mem Alloc Failed. Failing to load\n");
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002881 goto init_wrb_hndl_failed;
2882 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302883 pwrb_context->pwrb_handle_basestd =
2884 kzalloc(sizeof(struct wrb_handle *) *
2885 phba->params.wrbs_per_cxn, GFP_KERNEL);
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002886 if (!pwrb_context->pwrb_handle_basestd) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05302887 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2888 "BM_%d : Mem Alloc Failed. Failing to load\n");
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002889 goto init_wrb_hndl_failed;
2890 }
2891 if (!num_cxn_wrbh) {
2892 pwrb_handle =
2893 mem_descr_wrbh->mem_array[idx].virtual_address;
2894 num_cxn_wrbh = ((mem_descr_wrbh->mem_array[idx].size) /
2895 ((sizeof(struct wrb_handle)) *
2896 phba->params.wrbs_per_cxn));
2897 idx++;
2898 }
2899 pwrb_context->alloc_index = 0;
2900 pwrb_context->wrb_handles_available = 0;
2901 pwrb_context->free_index = 0;
2902
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302903 if (num_cxn_wrbh) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302904 for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
2905 pwrb_context->pwrb_handle_base[j] = pwrb_handle;
2906 pwrb_context->pwrb_handle_basestd[j] =
2907 pwrb_handle;
2908 pwrb_context->wrb_handles_available++;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302909 pwrb_handle->wrb_index = j;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302910 pwrb_handle++;
2911 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302912 num_cxn_wrbh--;
2913 }
2914 }
2915 idx = 0;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002916 for (index = 0; index < phba->params.cxns_per_ctrl; index++) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302917 pwrb_context = &phwi_ctrlr->wrb_context[index];
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002918 if (!num_cxn_wrb) {
2919 pwrb = mem_descr_wrb->mem_array[idx].virtual_address;
2920 num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) /
2921 ((sizeof(struct iscsi_wrb) *
2922 phba->params.wrbs_per_cxn));
2923 idx++;
2924 }
2925
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302926 if (num_cxn_wrb) {
2927 for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
2928 pwrb_handle = pwrb_context->pwrb_handle_base[j];
2929 pwrb_handle->pwrb = pwrb;
2930 pwrb++;
2931 }
2932 num_cxn_wrb--;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302933 }
2934 }
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002935 return 0;
2936init_wrb_hndl_failed:
2937 for (j = index; j > 0; j--) {
2938 pwrb_context = &phwi_ctrlr->wrb_context[j];
2939 kfree(pwrb_context->pwrb_handle_base);
2940 kfree(pwrb_context->pwrb_handle_basestd);
2941 }
2942 return -ENOMEM;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302943}
2944
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002945static int hwi_init_async_pdu_ctx(struct beiscsi_hba *phba)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302946{
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002947 uint8_t ulp_num;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302948 struct hwi_controller *phwi_ctrlr;
2949 struct hba_parameters *p = &phba->params;
2950 struct hwi_async_pdu_context *pasync_ctx;
2951 struct async_pdu_handle *pasync_header_h, *pasync_data_h;
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05002952 unsigned int index, idx, num_per_mem, num_async_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302953 struct be_mem_descriptor *mem_descr;
2954
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002955 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
2956 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302957
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002958 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2959 mem_descr += (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0 +
2960 (ulp_num * MEM_DESCR_OFFSET));
2961
2962 phwi_ctrlr = phba->phwi_ctrlr;
2963 phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num] =
2964 (struct hwi_async_pdu_context *)
2965 mem_descr->mem_array[0].virtual_address;
2966
2967 pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num];
2968 memset(pasync_ctx, 0, sizeof(*pasync_ctx));
2969
2970 pasync_ctx->async_entry =
2971 (struct hwi_async_entry *)
2972 ((long unsigned int)pasync_ctx +
2973 sizeof(struct hwi_async_pdu_context));
2974
2975 pasync_ctx->num_entries = BEISCSI_GET_CID_COUNT(phba,
2976 ulp_num);
2977 pasync_ctx->buffer_size = p->defpdu_hdr_sz;
2978
2979 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2980 mem_descr += HWI_MEM_ASYNC_HEADER_BUF_ULP0 +
2981 (ulp_num * MEM_DESCR_OFFSET);
2982 if (mem_descr->mem_array[0].virtual_address) {
2983 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2984 "BM_%d : hwi_init_async_pdu_ctx"
2985 " HWI_MEM_ASYNC_HEADER_BUF_ULP%d va=%p\n",
2986 ulp_num,
2987 mem_descr->mem_array[0].
2988 virtual_address);
2989 } else
2990 beiscsi_log(phba, KERN_WARNING,
2991 BEISCSI_LOG_INIT,
2992 "BM_%d : No Virtual address for ULP : %d\n",
2993 ulp_num);
2994
2995 pasync_ctx->async_header.va_base =
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302996 mem_descr->mem_array[0].virtual_address;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302997
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002998 pasync_ctx->async_header.pa_base.u.a64.address =
2999 mem_descr->mem_array[0].
3000 bus_address.u.a64.address;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003001
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003002 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
3003 mem_descr += HWI_MEM_ASYNC_HEADER_RING_ULP0 +
3004 (ulp_num * MEM_DESCR_OFFSET);
3005 if (mem_descr->mem_array[0].virtual_address) {
3006 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3007 "BM_%d : hwi_init_async_pdu_ctx"
3008 " HWI_MEM_ASYNC_HEADER_RING_ULP%d va=%p\n",
3009 ulp_num,
3010 mem_descr->mem_array[0].
3011 virtual_address);
3012 } else
3013 beiscsi_log(phba, KERN_WARNING,
3014 BEISCSI_LOG_INIT,
3015 "BM_%d : No Virtual address for ULP : %d\n",
3016 ulp_num);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303017
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003018 pasync_ctx->async_header.ring_base =
3019 mem_descr->mem_array[0].virtual_address;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303020
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003021 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
3022 mem_descr += HWI_MEM_ASYNC_HEADER_HANDLE_ULP0 +
3023 (ulp_num * MEM_DESCR_OFFSET);
3024 if (mem_descr->mem_array[0].virtual_address) {
3025 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3026 "BM_%d : hwi_init_async_pdu_ctx"
3027 " HWI_MEM_ASYNC_HEADER_HANDLE_ULP%d va=%p\n",
3028 ulp_num,
3029 mem_descr->mem_array[0].
3030 virtual_address);
3031 } else
3032 beiscsi_log(phba, KERN_WARNING,
3033 BEISCSI_LOG_INIT,
3034 "BM_%d : No Virtual address for ULP : %d\n",
3035 ulp_num);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303036
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003037 pasync_ctx->async_header.handle_base =
3038 mem_descr->mem_array[0].virtual_address;
3039 pasync_ctx->async_header.writables = 0;
3040 INIT_LIST_HEAD(&pasync_ctx->async_header.free_list);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303041
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003042 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
3043 mem_descr += HWI_MEM_ASYNC_DATA_RING_ULP0 +
3044 (ulp_num * MEM_DESCR_OFFSET);
3045 if (mem_descr->mem_array[0].virtual_address) {
3046 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3047 "BM_%d : hwi_init_async_pdu_ctx"
3048 " HWI_MEM_ASYNC_DATA_RING_ULP%d va=%p\n",
3049 ulp_num,
3050 mem_descr->mem_array[0].
3051 virtual_address);
3052 } else
3053 beiscsi_log(phba, KERN_WARNING,
3054 BEISCSI_LOG_INIT,
3055 "BM_%d : No Virtual address for ULP : %d\n",
3056 ulp_num);
John Soni Jose99bc5d52012-08-20 23:00:18 +05303057
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003058 pasync_ctx->async_data.ring_base =
3059 mem_descr->mem_array[0].virtual_address;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303060
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003061 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
3062 mem_descr += HWI_MEM_ASYNC_DATA_HANDLE_ULP0 +
3063 (ulp_num * MEM_DESCR_OFFSET);
3064 if (!mem_descr->mem_array[0].virtual_address)
3065 beiscsi_log(phba, KERN_WARNING,
3066 BEISCSI_LOG_INIT,
3067 "BM_%d : No Virtual address for ULP : %d\n",
3068 ulp_num);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303069
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003070 pasync_ctx->async_data.handle_base =
3071 mem_descr->mem_array[0].virtual_address;
3072 pasync_ctx->async_data.writables = 0;
3073 INIT_LIST_HEAD(&pasync_ctx->async_data.free_list);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303074
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003075 pasync_header_h =
3076 (struct async_pdu_handle *)
3077 pasync_ctx->async_header.handle_base;
3078 pasync_data_h =
3079 (struct async_pdu_handle *)
3080 pasync_ctx->async_data.handle_base;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303081
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003082 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
3083 mem_descr += HWI_MEM_ASYNC_DATA_BUF_ULP0 +
3084 (ulp_num * MEM_DESCR_OFFSET);
3085 if (mem_descr->mem_array[0].virtual_address) {
3086 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3087 "BM_%d : hwi_init_async_pdu_ctx"
3088 " HWI_MEM_ASYNC_DATA_BUF_ULP%d va=%p\n",
3089 ulp_num,
3090 mem_descr->mem_array[0].
3091 virtual_address);
3092 } else
3093 beiscsi_log(phba, KERN_WARNING,
3094 BEISCSI_LOG_INIT,
3095 "BM_%d : No Virtual address for ULP : %d\n",
3096 ulp_num);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303097
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003098 idx = 0;
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05003099 pasync_ctx->async_data.va_base =
3100 mem_descr->mem_array[idx].virtual_address;
3101 pasync_ctx->async_data.pa_base.u.a64.address =
3102 mem_descr->mem_array[idx].
3103 bus_address.u.a64.address;
3104
3105 num_async_data = ((mem_descr->mem_array[idx].size) /
3106 phba->params.defpdu_data_sz);
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003107 num_per_mem = 0;
3108
3109 for (index = 0; index < BEISCSI_GET_CID_COUNT
3110 (phba, ulp_num); index++) {
3111 pasync_header_h->cri = -1;
3112 pasync_header_h->index = (char)index;
3113 INIT_LIST_HEAD(&pasync_header_h->link);
3114 pasync_header_h->pbuffer =
3115 (void *)((unsigned long)
3116 (pasync_ctx->
3117 async_header.va_base) +
3118 (p->defpdu_hdr_sz * index));
3119
3120 pasync_header_h->pa.u.a64.address =
3121 pasync_ctx->async_header.pa_base.u.a64.
3122 address + (p->defpdu_hdr_sz * index);
3123
3124 list_add_tail(&pasync_header_h->link,
3125 &pasync_ctx->async_header.
3126 free_list);
3127 pasync_header_h++;
3128 pasync_ctx->async_header.free_entries++;
3129 pasync_ctx->async_header.writables++;
3130
3131 INIT_LIST_HEAD(&pasync_ctx->async_entry[index].
3132 wait_queue.list);
3133 INIT_LIST_HEAD(&pasync_ctx->async_entry[index].
3134 header_busy_list);
3135 pasync_data_h->cri = -1;
3136 pasync_data_h->index = (char)index;
3137 INIT_LIST_HEAD(&pasync_data_h->link);
3138
3139 if (!num_async_data) {
3140 num_per_mem = 0;
3141 idx++;
3142 pasync_ctx->async_data.va_base =
3143 mem_descr->mem_array[idx].
3144 virtual_address;
3145 pasync_ctx->async_data.pa_base.u.
3146 a64.address =
3147 mem_descr->mem_array[idx].
3148 bus_address.u.a64.address;
3149 num_async_data =
3150 ((mem_descr->mem_array[idx].
3151 size) /
3152 phba->params.defpdu_data_sz);
3153 }
3154 pasync_data_h->pbuffer =
3155 (void *)((unsigned long)
3156 (pasync_ctx->async_data.va_base) +
3157 (p->defpdu_data_sz * num_per_mem));
3158
3159 pasync_data_h->pa.u.a64.address =
3160 pasync_ctx->async_data.pa_base.u.a64.
3161 address + (p->defpdu_data_sz *
3162 num_per_mem);
3163 num_per_mem++;
3164 num_async_data--;
3165
3166 list_add_tail(&pasync_data_h->link,
3167 &pasync_ctx->async_data.
3168 free_list);
3169 pasync_data_h++;
3170 pasync_ctx->async_data.free_entries++;
3171 pasync_ctx->async_data.writables++;
3172
3173 INIT_LIST_HEAD(&pasync_ctx->async_entry[index].
3174 data_busy_list);
3175 }
3176
3177 pasync_ctx->async_header.host_write_ptr = 0;
3178 pasync_ctx->async_header.ep_read_ptr = -1;
3179 pasync_ctx->async_data.host_write_ptr = 0;
3180 pasync_ctx->async_data.ep_read_ptr = -1;
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05003181 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303182 }
3183
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003184 return 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303185}
3186
3187static int
3188be_sgl_create_contiguous(void *virtual_address,
3189 u64 physical_address, u32 length,
3190 struct be_dma_mem *sgl)
3191{
3192 WARN_ON(!virtual_address);
3193 WARN_ON(!physical_address);
Tim Gardnerdd29dae2015-10-30 12:22:58 -06003194 WARN_ON(!length);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303195 WARN_ON(!sgl);
3196
3197 sgl->va = virtual_address;
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05303198 sgl->dma = (unsigned long)physical_address;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303199 sgl->size = length;
3200
3201 return 0;
3202}
3203
3204static void be_sgl_destroy_contiguous(struct be_dma_mem *sgl)
3205{
3206 memset(sgl, 0, sizeof(*sgl));
3207}
3208
3209static void
3210hwi_build_be_sgl_arr(struct beiscsi_hba *phba,
3211 struct mem_array *pmem, struct be_dma_mem *sgl)
3212{
3213 if (sgl->va)
3214 be_sgl_destroy_contiguous(sgl);
3215
3216 be_sgl_create_contiguous(pmem->virtual_address,
3217 pmem->bus_address.u.a64.address,
3218 pmem->size, sgl);
3219}
3220
3221static void
3222hwi_build_be_sgl_by_offset(struct beiscsi_hba *phba,
3223 struct mem_array *pmem, struct be_dma_mem *sgl)
3224{
3225 if (sgl->va)
3226 be_sgl_destroy_contiguous(sgl);
3227
3228 be_sgl_create_contiguous((unsigned char *)pmem->virtual_address,
3229 pmem->bus_address.u.a64.address,
3230 pmem->size, sgl);
3231}
3232
3233static int be_fill_queue(struct be_queue_info *q,
3234 u16 len, u16 entry_size, void *vaddress)
3235{
3236 struct be_dma_mem *mem = &q->dma_mem;
3237
3238 memset(q, 0, sizeof(*q));
3239 q->len = len;
3240 q->entry_size = entry_size;
3241 mem->size = len * entry_size;
3242 mem->va = vaddress;
3243 if (!mem->va)
3244 return -ENOMEM;
3245 memset(mem->va, 0, mem->size);
3246 return 0;
3247}
3248
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303249static int beiscsi_create_eqs(struct beiscsi_hba *phba,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303250 struct hwi_context_memory *phwi_context)
3251{
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303252 unsigned int i, num_eq_pages;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303253 int ret = 0, eq_for_mcc;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303254 struct be_queue_info *eq;
3255 struct be_dma_mem *mem;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303256 void *eq_vaddress;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303257 dma_addr_t paddr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303258
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303259 num_eq_pages = PAGES_REQUIRED(phba->params.num_eq_entries * \
3260 sizeof(struct be_eq_entry));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303261
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303262 if (phba->msix_enabled)
3263 eq_for_mcc = 1;
3264 else
3265 eq_for_mcc = 0;
3266 for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
3267 eq = &phwi_context->be_eq[i].q;
3268 mem = &eq->dma_mem;
3269 phwi_context->be_eq[i].phba = phba;
3270 eq_vaddress = pci_alloc_consistent(phba->pcidev,
3271 num_eq_pages * PAGE_SIZE,
3272 &paddr);
3273 if (!eq_vaddress)
3274 goto create_eq_error;
3275
3276 mem->va = eq_vaddress;
3277 ret = be_fill_queue(eq, phba->params.num_eq_entries,
3278 sizeof(struct be_eq_entry), eq_vaddress);
3279 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303280 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3281 "BM_%d : be_fill_queue Failed for EQ\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303282 goto create_eq_error;
3283 }
3284
3285 mem->dma = paddr;
3286 ret = beiscsi_cmd_eq_create(&phba->ctrl, eq,
3287 phwi_context->cur_eqd);
3288 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303289 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3290 "BM_%d : beiscsi_cmd_eq_create"
3291 "Failed for EQ\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303292 goto create_eq_error;
3293 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05303294
3295 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3296 "BM_%d : eqid = %d\n",
3297 phwi_context->be_eq[i].q.id);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303298 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303299 return 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303300create_eq_error:
John Soni Jose107dfcb2012-10-20 04:42:13 +05303301 for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303302 eq = &phwi_context->be_eq[i].q;
3303 mem = &eq->dma_mem;
3304 if (mem->va)
3305 pci_free_consistent(phba->pcidev, num_eq_pages
3306 * PAGE_SIZE,
3307 mem->va, mem->dma);
3308 }
3309 return ret;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303310}
3311
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303312static int beiscsi_create_cqs(struct beiscsi_hba *phba,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303313 struct hwi_context_memory *phwi_context)
3314{
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303315 unsigned int i, num_cq_pages;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303316 int ret = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303317 struct be_queue_info *cq, *eq;
3318 struct be_dma_mem *mem;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303319 struct be_eq_obj *pbe_eq;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303320 void *cq_vaddress;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303321 dma_addr_t paddr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303322
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303323 num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
3324 sizeof(struct sol_cqe));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303325
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303326 for (i = 0; i < phba->num_cpus; i++) {
3327 cq = &phwi_context->be_cq[i];
3328 eq = &phwi_context->be_eq[i].q;
3329 pbe_eq = &phwi_context->be_eq[i];
3330 pbe_eq->cq = cq;
3331 pbe_eq->phba = phba;
3332 mem = &cq->dma_mem;
3333 cq_vaddress = pci_alloc_consistent(phba->pcidev,
3334 num_cq_pages * PAGE_SIZE,
3335 &paddr);
3336 if (!cq_vaddress)
3337 goto create_cq_error;
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05303338 ret = be_fill_queue(cq, phba->params.num_cq_entries,
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303339 sizeof(struct sol_cqe), cq_vaddress);
3340 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303341 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3342 "BM_%d : be_fill_queue Failed "
3343 "for ISCSI CQ\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303344 goto create_cq_error;
3345 }
3346
3347 mem->dma = paddr;
3348 ret = beiscsi_cmd_cq_create(&phba->ctrl, cq, eq, false,
3349 false, 0);
3350 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303351 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3352 "BM_%d : beiscsi_cmd_eq_create"
3353 "Failed for ISCSI CQ\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303354 goto create_cq_error;
3355 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05303356 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3357 "BM_%d : iscsi cq_id is %d for eq_id %d\n"
3358 "iSCSI CQ CREATED\n", cq->id, eq->id);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303359 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303360 return 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303361
3362create_cq_error:
3363 for (i = 0; i < phba->num_cpus; i++) {
3364 cq = &phwi_context->be_cq[i];
3365 mem = &cq->dma_mem;
3366 if (mem->va)
3367 pci_free_consistent(phba->pcidev, num_cq_pages
3368 * PAGE_SIZE,
3369 mem->va, mem->dma);
3370 }
3371 return ret;
3372
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303373}
3374
3375static int
3376beiscsi_create_def_hdr(struct beiscsi_hba *phba,
3377 struct hwi_context_memory *phwi_context,
3378 struct hwi_controller *phwi_ctrlr,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003379 unsigned int def_pdu_ring_sz, uint8_t ulp_num)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303380{
3381 unsigned int idx;
3382 int ret;
3383 struct be_queue_info *dq, *cq;
3384 struct be_dma_mem *mem;
3385 struct be_mem_descriptor *mem_descr;
3386 void *dq_vaddress;
3387
3388 idx = 0;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003389 dq = &phwi_context->be_def_hdrq[ulp_num];
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303390 cq = &phwi_context->be_cq[0];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303391 mem = &dq->dma_mem;
3392 mem_descr = phba->init_mem;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003393 mem_descr += HWI_MEM_ASYNC_HEADER_RING_ULP0 +
3394 (ulp_num * MEM_DESCR_OFFSET);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303395 dq_vaddress = mem_descr->mem_array[idx].virtual_address;
3396 ret = be_fill_queue(dq, mem_descr->mem_array[0].size /
3397 sizeof(struct phys_addr),
3398 sizeof(struct phys_addr), dq_vaddress);
3399 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303400 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003401 "BM_%d : be_fill_queue Failed for DEF PDU HDR on ULP : %d\n",
3402 ulp_num);
3403
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303404 return ret;
3405 }
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05303406 mem->dma = (unsigned long)mem_descr->mem_array[idx].
3407 bus_address.u.a64.address;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303408 ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dq,
3409 def_pdu_ring_sz,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003410 phba->params.defpdu_hdr_sz,
3411 BEISCSI_DEFQ_HDR, ulp_num);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303412 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303413 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003414 "BM_%d : be_cmd_create_default_pdu_queue Failed DEFHDR on ULP : %d\n",
3415 ulp_num);
3416
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303417 return ret;
3418 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05303419
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003420 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3421 "BM_%d : iscsi hdr def pdu id for ULP : %d is %d\n",
3422 ulp_num,
3423 phwi_context->be_def_hdrq[ulp_num].id);
3424 hwi_post_async_buffers(phba, BEISCSI_DEFQ_HDR, ulp_num);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303425 return 0;
3426}
3427
3428static int
3429beiscsi_create_def_data(struct beiscsi_hba *phba,
3430 struct hwi_context_memory *phwi_context,
3431 struct hwi_controller *phwi_ctrlr,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003432 unsigned int def_pdu_ring_sz, uint8_t ulp_num)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303433{
3434 unsigned int idx;
3435 int ret;
3436 struct be_queue_info *dataq, *cq;
3437 struct be_dma_mem *mem;
3438 struct be_mem_descriptor *mem_descr;
3439 void *dq_vaddress;
3440
3441 idx = 0;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003442 dataq = &phwi_context->be_def_dataq[ulp_num];
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303443 cq = &phwi_context->be_cq[0];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303444 mem = &dataq->dma_mem;
3445 mem_descr = phba->init_mem;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003446 mem_descr += HWI_MEM_ASYNC_DATA_RING_ULP0 +
3447 (ulp_num * MEM_DESCR_OFFSET);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303448 dq_vaddress = mem_descr->mem_array[idx].virtual_address;
3449 ret = be_fill_queue(dataq, mem_descr->mem_array[0].size /
3450 sizeof(struct phys_addr),
3451 sizeof(struct phys_addr), dq_vaddress);
3452 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303453 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003454 "BM_%d : be_fill_queue Failed for DEF PDU "
3455 "DATA on ULP : %d\n",
3456 ulp_num);
3457
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303458 return ret;
3459 }
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05303460 mem->dma = (unsigned long)mem_descr->mem_array[idx].
3461 bus_address.u.a64.address;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303462 ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dataq,
3463 def_pdu_ring_sz,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003464 phba->params.defpdu_data_sz,
3465 BEISCSI_DEFQ_DATA, ulp_num);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303466 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303467 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3468 "BM_%d be_cmd_create_default_pdu_queue"
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003469 " Failed for DEF PDU DATA on ULP : %d\n",
3470 ulp_num);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303471 return ret;
3472 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05303473
John Soni Jose99bc5d52012-08-20 23:00:18 +05303474 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003475 "BM_%d : iscsi def data id on ULP : %d is %d\n",
3476 ulp_num,
3477 phwi_context->be_def_dataq[ulp_num].id);
3478
3479 hwi_post_async_buffers(phba, BEISCSI_DEFQ_DATA, ulp_num);
3480 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3481 "BM_%d : DEFAULT PDU DATA RING CREATED"
3482 "on ULP : %d\n", ulp_num);
John Soni Jose99bc5d52012-08-20 23:00:18 +05303483
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303484 return 0;
3485}
3486
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07003487
3488static int
3489beiscsi_post_template_hdr(struct beiscsi_hba *phba)
3490{
3491 struct be_mem_descriptor *mem_descr;
3492 struct mem_array *pm_arr;
3493 struct be_dma_mem sgl;
Jayamohan Kallickala129d922013-09-28 15:35:46 -07003494 int status, ulp_num;
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07003495
Jayamohan Kallickala129d922013-09-28 15:35:46 -07003496 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
3497 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
3498 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
3499 mem_descr += HWI_MEM_TEMPLATE_HDR_ULP0 +
3500 (ulp_num * MEM_DESCR_OFFSET);
3501 pm_arr = mem_descr->mem_array;
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07003502
Jayamohan Kallickala129d922013-09-28 15:35:46 -07003503 hwi_build_be_sgl_arr(phba, pm_arr, &sgl);
3504 status = be_cmd_iscsi_post_template_hdr(
3505 &phba->ctrl, &sgl);
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07003506
Jayamohan Kallickala129d922013-09-28 15:35:46 -07003507 if (status != 0) {
3508 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3509 "BM_%d : Post Template HDR Failed for"
3510 "ULP_%d\n", ulp_num);
3511 return status;
3512 }
3513
3514 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3515 "BM_%d : Template HDR Pages Posted for"
3516 "ULP_%d\n", ulp_num);
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07003517 }
3518 }
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07003519 return 0;
3520}
3521
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303522static int
3523beiscsi_post_pages(struct beiscsi_hba *phba)
3524{
3525 struct be_mem_descriptor *mem_descr;
3526 struct mem_array *pm_arr;
3527 unsigned int page_offset, i;
3528 struct be_dma_mem sgl;
Jayamohan Kallickal843ae752013-09-28 15:35:44 -07003529 int status, ulp_num = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303530
3531 mem_descr = phba->init_mem;
3532 mem_descr += HWI_MEM_SGE;
3533 pm_arr = mem_descr->mem_array;
3534
Jayamohan Kallickal90622db2013-09-28 15:35:47 -07003535 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
3536 if (test_bit(ulp_num, &phba->fw_config.ulp_supported))
3537 break;
3538
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303539 page_offset = (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io *
Jayamohan Kallickal843ae752013-09-28 15:35:44 -07003540 phba->fw_config.iscsi_icd_start[ulp_num]) / PAGE_SIZE;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303541 for (i = 0; i < mem_descr->num_elements; i++) {
3542 hwi_build_be_sgl_arr(phba, pm_arr, &sgl);
3543 status = be_cmd_iscsi_post_sgl_pages(&phba->ctrl, &sgl,
3544 page_offset,
3545 (pm_arr->size / PAGE_SIZE));
3546 page_offset += pm_arr->size / PAGE_SIZE;
3547 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303548 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3549 "BM_%d : post sgl failed.\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303550 return status;
3551 }
3552 pm_arr++;
3553 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05303554 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3555 "BM_%d : POSTED PAGES\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303556 return 0;
3557}
3558
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303559static void be_queue_free(struct beiscsi_hba *phba, struct be_queue_info *q)
3560{
3561 struct be_dma_mem *mem = &q->dma_mem;
Jayamohan Kallickalc8b25592012-04-03 23:41:42 -05003562 if (mem->va) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303563 pci_free_consistent(phba->pcidev, mem->size,
3564 mem->va, mem->dma);
Jayamohan Kallickalc8b25592012-04-03 23:41:42 -05003565 mem->va = NULL;
3566 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303567}
3568
3569static int be_queue_alloc(struct beiscsi_hba *phba, struct be_queue_info *q,
3570 u16 len, u16 entry_size)
3571{
3572 struct be_dma_mem *mem = &q->dma_mem;
3573
3574 memset(q, 0, sizeof(*q));
3575 q->len = len;
3576 q->entry_size = entry_size;
3577 mem->size = len * entry_size;
Joe Perches7c845eb2014-08-08 14:24:46 -07003578 mem->va = pci_zalloc_consistent(phba->pcidev, mem->size, &mem->dma);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303579 if (!mem->va)
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +05303580 return -ENOMEM;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303581 return 0;
3582}
3583
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303584static int
3585beiscsi_create_wrb_rings(struct beiscsi_hba *phba,
3586 struct hwi_context_memory *phwi_context,
3587 struct hwi_controller *phwi_ctrlr)
3588{
3589 unsigned int wrb_mem_index, offset, size, num_wrb_rings;
3590 u64 pa_addr_lo;
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07003591 unsigned int idx, num, i, ulp_num;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303592 struct mem_array *pwrb_arr;
3593 void *wrb_vaddr;
3594 struct be_dma_mem sgl;
3595 struct be_mem_descriptor *mem_descr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003596 struct hwi_wrb_context *pwrb_context;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303597 int status;
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07003598 uint8_t ulp_count = 0, ulp_base_num = 0;
3599 uint16_t cid_count_ulp[BEISCSI_ULP_COUNT] = { 0 };
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303600
3601 idx = 0;
3602 mem_descr = phba->init_mem;
3603 mem_descr += HWI_MEM_WRB;
3604 pwrb_arr = kmalloc(sizeof(*pwrb_arr) * phba->params.cxns_per_ctrl,
3605 GFP_KERNEL);
3606 if (!pwrb_arr) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303607 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3608 "BM_%d : Memory alloc failed in create wrb ring.\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303609 return -ENOMEM;
3610 }
3611 wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
3612 pa_addr_lo = mem_descr->mem_array[idx].bus_address.u.a64.address;
3613 num_wrb_rings = mem_descr->mem_array[idx].size /
3614 (phba->params.wrbs_per_cxn * sizeof(struct iscsi_wrb));
3615
3616 for (num = 0; num < phba->params.cxns_per_ctrl; num++) {
3617 if (num_wrb_rings) {
3618 pwrb_arr[num].virtual_address = wrb_vaddr;
3619 pwrb_arr[num].bus_address.u.a64.address = pa_addr_lo;
3620 pwrb_arr[num].size = phba->params.wrbs_per_cxn *
3621 sizeof(struct iscsi_wrb);
3622 wrb_vaddr += pwrb_arr[num].size;
3623 pa_addr_lo += pwrb_arr[num].size;
3624 num_wrb_rings--;
3625 } else {
3626 idx++;
3627 wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
3628 pa_addr_lo = mem_descr->mem_array[idx].\
3629 bus_address.u.a64.address;
3630 num_wrb_rings = mem_descr->mem_array[idx].size /
3631 (phba->params.wrbs_per_cxn *
3632 sizeof(struct iscsi_wrb));
3633 pwrb_arr[num].virtual_address = wrb_vaddr;
3634 pwrb_arr[num].bus_address.u.a64.address\
3635 = pa_addr_lo;
3636 pwrb_arr[num].size = phba->params.wrbs_per_cxn *
3637 sizeof(struct iscsi_wrb);
3638 wrb_vaddr += pwrb_arr[num].size;
3639 pa_addr_lo += pwrb_arr[num].size;
3640 num_wrb_rings--;
3641 }
3642 }
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07003643
3644 /* Get the ULP Count */
3645 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
3646 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
3647 ulp_count++;
3648 ulp_base_num = ulp_num;
3649 cid_count_ulp[ulp_num] =
3650 BEISCSI_GET_CID_COUNT(phba, ulp_num);
3651 }
3652
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303653 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
3654 wrb_mem_index = 0;
3655 offset = 0;
3656 size = 0;
3657
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07003658 if (ulp_count > 1) {
3659 ulp_base_num = (ulp_base_num + 1) % BEISCSI_ULP_COUNT;
3660
3661 if (!cid_count_ulp[ulp_base_num])
3662 ulp_base_num = (ulp_base_num + 1) %
3663 BEISCSI_ULP_COUNT;
3664
3665 cid_count_ulp[ulp_base_num]--;
3666 }
3667
3668
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303669 hwi_build_be_sgl_by_offset(phba, &pwrb_arr[i], &sgl);
3670 status = be_cmd_wrbq_create(&phba->ctrl, &sgl,
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07003671 &phwi_context->be_wrbq[i],
3672 &phwi_ctrlr->wrb_context[i],
3673 ulp_base_num);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303674 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303675 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3676 "BM_%d : wrbq create failed.");
Dan Carpenter1462b8f2010-06-10 09:52:21 +02003677 kfree(pwrb_arr);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303678 return status;
3679 }
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003680 pwrb_context = &phwi_ctrlr->wrb_context[i];
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003681 BE_SET_CID_TO_CRI(i, pwrb_context->cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303682 }
3683 kfree(pwrb_arr);
3684 return 0;
3685}
3686
3687static void free_wrb_handles(struct beiscsi_hba *phba)
3688{
3689 unsigned int index;
3690 struct hwi_controller *phwi_ctrlr;
3691 struct hwi_wrb_context *pwrb_context;
3692
3693 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003694 for (index = 0; index < phba->params.cxns_per_ctrl; index++) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303695 pwrb_context = &phwi_ctrlr->wrb_context[index];
3696 kfree(pwrb_context->pwrb_handle_base);
3697 kfree(pwrb_context->pwrb_handle_basestd);
3698 }
3699}
3700
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303701static void be_mcc_queues_destroy(struct beiscsi_hba *phba)
3702{
3703 struct be_queue_info *q;
3704 struct be_ctrl_info *ctrl = &phba->ctrl;
3705
3706 q = &phba->ctrl.mcc_obj.q;
John Soni Jose4e2bdf72015-04-25 08:17:31 +05303707 if (q->created) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303708 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_MCCQ);
John Soni Jose4e2bdf72015-04-25 08:17:31 +05303709 be_queue_free(phba, q);
3710 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303711
3712 q = &phba->ctrl.mcc_obj.cq;
John Soni Jose4e2bdf72015-04-25 08:17:31 +05303713 if (q->created) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303714 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
John Soni Jose4e2bdf72015-04-25 08:17:31 +05303715 be_queue_free(phba, q);
3716 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303717}
3718
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303719static void hwi_cleanup(struct beiscsi_hba *phba)
3720{
3721 struct be_queue_info *q;
3722 struct be_ctrl_info *ctrl = &phba->ctrl;
3723 struct hwi_controller *phwi_ctrlr;
3724 struct hwi_context_memory *phwi_context;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003725 struct hwi_async_pdu_context *pasync_ctx;
Jayamohan Kallickal23188162014-05-05 21:41:29 -04003726 int i, eq_for_mcc, ulp_num;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303727
3728 phwi_ctrlr = phba->phwi_ctrlr;
3729 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07003730
3731 be_cmd_iscsi_remove_template_hdr(ctrl);
3732
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303733 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
3734 q = &phwi_context->be_wrbq[i];
3735 if (q->created)
3736 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_WRBQ);
3737 }
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003738 kfree(phwi_context->be_wrbq);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303739 free_wrb_handles(phba);
3740
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003741 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
3742 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303743
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003744 q = &phwi_context->be_def_hdrq[ulp_num];
3745 if (q->created)
3746 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
3747
3748 q = &phwi_context->be_def_dataq[ulp_num];
3749 if (q->created)
3750 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
3751
3752 pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num];
3753 }
3754 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303755
3756 beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
3757
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303758 for (i = 0; i < (phba->num_cpus); i++) {
3759 q = &phwi_context->be_cq[i];
John Soni Jose4e2bdf72015-04-25 08:17:31 +05303760 if (q->created) {
3761 be_queue_free(phba, q);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303762 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
John Soni Jose4e2bdf72015-04-25 08:17:31 +05303763 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303764 }
Jayamohan Kallickal23188162014-05-05 21:41:29 -04003765
3766 be_mcc_queues_destroy(phba);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303767 if (phba->msix_enabled)
Jayamohan Kallickal23188162014-05-05 21:41:29 -04003768 eq_for_mcc = 1;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303769 else
Jayamohan Kallickal23188162014-05-05 21:41:29 -04003770 eq_for_mcc = 0;
3771 for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303772 q = &phwi_context->be_eq[i].q;
John Soni Jose4e2bdf72015-04-25 08:17:31 +05303773 if (q->created) {
3774 be_queue_free(phba, q);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303775 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_EQ);
John Soni Jose4e2bdf72015-04-25 08:17:31 +05303776 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303777 }
Jayamohan Kallickal0283fbb2013-04-05 20:38:21 -07003778 be_cmd_fw_uninit(ctrl);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303779}
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303780
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303781static int be_mcc_queues_create(struct beiscsi_hba *phba,
3782 struct hwi_context_memory *phwi_context)
3783{
3784 struct be_queue_info *q, *cq;
3785 struct be_ctrl_info *ctrl = &phba->ctrl;
3786
3787 /* Alloc MCC compl queue */
3788 cq = &phba->ctrl.mcc_obj.cq;
3789 if (be_queue_alloc(phba, cq, MCC_CQ_LEN,
3790 sizeof(struct be_mcc_compl)))
3791 goto err;
3792 /* Ask BE to create MCC compl queue; */
3793 if (phba->msix_enabled) {
3794 if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq
3795 [phba->num_cpus].q, false, true, 0))
3796 goto mcc_cq_free;
3797 } else {
3798 if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq[0].q,
3799 false, true, 0))
3800 goto mcc_cq_free;
3801 }
3802
3803 /* Alloc MCC queue */
3804 q = &phba->ctrl.mcc_obj.q;
3805 if (be_queue_alloc(phba, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb)))
3806 goto mcc_cq_destroy;
3807
3808 /* Ask BE to create MCC queue */
Jayamohan Kallickal35e66012009-10-23 11:53:49 +05303809 if (beiscsi_cmd_mccq_create(phba, q, cq))
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303810 goto mcc_q_free;
3811
3812 return 0;
3813
3814mcc_q_free:
3815 be_queue_free(phba, q);
3816mcc_cq_destroy:
3817 beiscsi_cmd_q_destroy(ctrl, cq, QTYPE_CQ);
3818mcc_cq_free:
3819 be_queue_free(phba, cq);
3820err:
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +05303821 return -ENOMEM;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303822}
3823
John Soni Jose107dfcb2012-10-20 04:42:13 +05303824/**
3825 * find_num_cpus()- Get the CPU online count
3826 * @phba: ptr to priv structure
3827 *
3828 * CPU count is used for creating EQ.
3829 **/
3830static void find_num_cpus(struct beiscsi_hba *phba)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303831{
3832 int num_cpus = 0;
3833
3834 num_cpus = num_online_cpus();
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303835
John Soni Jose22abeef2012-10-20 04:43:32 +05303836 switch (phba->generation) {
3837 case BE_GEN2:
3838 case BE_GEN3:
3839 phba->num_cpus = (num_cpus > BEISCSI_MAX_NUM_CPUS) ?
3840 BEISCSI_MAX_NUM_CPUS : num_cpus;
3841 break;
3842 case BE_GEN4:
Jayamohan Kallickal68c26a32013-09-28 15:35:54 -07003843 /*
3844 * If eqid_count == 1 fall back to
3845 * INTX mechanism
3846 **/
3847 if (phba->fw_config.eqid_count == 1) {
3848 enable_msix = 0;
3849 phba->num_cpus = 1;
3850 return;
3851 }
3852
3853 phba->num_cpus =
3854 (num_cpus > (phba->fw_config.eqid_count - 1)) ?
3855 (phba->fw_config.eqid_count - 1) : num_cpus;
John Soni Jose22abeef2012-10-20 04:43:32 +05303856 break;
3857 default:
3858 phba->num_cpus = 1;
3859 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303860}
3861
3862static int hwi_init_port(struct beiscsi_hba *phba)
3863{
3864 struct hwi_controller *phwi_ctrlr;
3865 struct hwi_context_memory *phwi_context;
3866 unsigned int def_pdu_ring_sz;
3867 struct be_ctrl_info *ctrl = &phba->ctrl;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003868 int status, ulp_num;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303869
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303870 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303871 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickal73af08e2014-05-05 21:41:26 -04003872 phwi_context->max_eqd = 128;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303873 phwi_context->min_eqd = 0;
Jayamohan Kallickal73af08e2014-05-05 21:41:26 -04003874 phwi_context->cur_eqd = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303875 be_cmd_fw_initialize(&phba->ctrl);
Jitendra Bhivare53aefe22016-01-20 14:10:53 +05303876 /* set optic state to unknown */
3877 phba->optic_state = 0xff;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303878
3879 status = beiscsi_create_eqs(phba, phwi_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303880 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303881 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3882 "BM_%d : EQ not created\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303883 goto error;
3884 }
3885
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303886 status = be_mcc_queues_create(phba, phwi_context);
3887 if (status != 0)
3888 goto error;
3889
3890 status = mgmt_check_supported_fw(ctrl, phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303891 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303892 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3893 "BM_%d : Unsupported fw version\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303894 goto error;
3895 }
3896
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303897 status = beiscsi_create_cqs(phba, phwi_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303898 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303899 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3900 "BM_%d : CQ not created\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303901 goto error;
3902 }
3903
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003904 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
3905 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303906
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003907 def_pdu_ring_sz =
3908 BEISCSI_GET_CID_COUNT(phba, ulp_num) *
3909 sizeof(struct phys_addr);
3910
3911 status = beiscsi_create_def_hdr(phba, phwi_context,
3912 phwi_ctrlr,
3913 def_pdu_ring_sz,
3914 ulp_num);
3915 if (status != 0) {
3916 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3917 "BM_%d : Default Header not created for ULP : %d\n",
3918 ulp_num);
3919 goto error;
3920 }
3921
3922 status = beiscsi_create_def_data(phba, phwi_context,
3923 phwi_ctrlr,
3924 def_pdu_ring_sz,
3925 ulp_num);
3926 if (status != 0) {
3927 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3928 "BM_%d : Default Data not created for ULP : %d\n",
3929 ulp_num);
3930 goto error;
3931 }
3932 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303933 }
3934
3935 status = beiscsi_post_pages(phba);
3936 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303937 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3938 "BM_%d : Post SGL Pages Failed\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303939 goto error;
3940 }
3941
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07003942 status = beiscsi_post_template_hdr(phba);
3943 if (status != 0) {
3944 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3945 "BM_%d : Template HDR Posting for CXN Failed\n");
3946 }
3947
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303948 status = beiscsi_create_wrb_rings(phba, phwi_context, phwi_ctrlr);
3949 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303950 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3951 "BM_%d : WRB Rings not created\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303952 goto error;
3953 }
3954
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003955 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
3956 uint16_t async_arr_idx = 0;
3957
3958 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
3959 uint16_t cri = 0;
3960 struct hwi_async_pdu_context *pasync_ctx;
3961
3962 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(
3963 phwi_ctrlr, ulp_num);
3964 for (cri = 0; cri <
3965 phba->params.cxns_per_ctrl; cri++) {
3966 if (ulp_num == BEISCSI_GET_ULP_FROM_CRI
3967 (phwi_ctrlr, cri))
3968 pasync_ctx->cid_to_async_cri_map[
3969 phwi_ctrlr->wrb_context[cri].cid] =
3970 async_arr_idx++;
3971 }
3972 }
3973 }
3974
John Soni Jose99bc5d52012-08-20 23:00:18 +05303975 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3976 "BM_%d : hwi_init_port success\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303977 return 0;
3978
3979error:
John Soni Jose99bc5d52012-08-20 23:00:18 +05303980 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3981 "BM_%d : hwi_init_port failed");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303982 hwi_cleanup(phba);
Jayamohan Kallickala49e06d2012-04-03 23:41:44 -05003983 return status;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303984}
3985
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303986static int hwi_init_controller(struct beiscsi_hba *phba)
3987{
3988 struct hwi_controller *phwi_ctrlr;
3989
3990 phwi_ctrlr = phba->phwi_ctrlr;
3991 if (1 == phba->init_mem[HWI_MEM_ADDN_CONTEXT].num_elements) {
3992 phwi_ctrlr->phwi_ctxt = (struct hwi_context_memory *)phba->
3993 init_mem[HWI_MEM_ADDN_CONTEXT].mem_array[0].virtual_address;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303994 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3995 "BM_%d : phwi_ctrlr->phwi_ctxt=%p\n",
3996 phwi_ctrlr->phwi_ctxt);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303997 } else {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303998 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3999 "BM_%d : HWI_MEM_ADDN_CONTEXT is more "
4000 "than one element.Failing to load\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304001 return -ENOMEM;
4002 }
4003
4004 iscsi_init_global_templates(phba);
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05004005 if (beiscsi_init_wrb_handle(phba))
4006 return -ENOMEM;
4007
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004008 if (hwi_init_async_pdu_ctx(phba)) {
4009 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4010 "BM_%d : hwi_init_async_pdu_ctx failed\n");
4011 return -ENOMEM;
4012 }
4013
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304014 if (hwi_init_port(phba) != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304015 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4016 "BM_%d : hwi_init_controller failed\n");
4017
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304018 return -ENOMEM;
4019 }
4020 return 0;
4021}
4022
4023static void beiscsi_free_mem(struct beiscsi_hba *phba)
4024{
4025 struct be_mem_descriptor *mem_descr;
4026 int i, j;
4027
4028 mem_descr = phba->init_mem;
4029 i = 0;
4030 j = 0;
4031 for (i = 0; i < SE_MEM_MAX; i++) {
4032 for (j = mem_descr->num_elements; j > 0; j--) {
4033 pci_free_consistent(phba->pcidev,
4034 mem_descr->mem_array[j - 1].size,
4035 mem_descr->mem_array[j - 1].virtual_address,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05304036 (unsigned long)mem_descr->mem_array[j - 1].
4037 bus_address.u.a64.address);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304038 }
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07004039
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304040 kfree(mem_descr->mem_array);
4041 mem_descr++;
4042 }
4043 kfree(phba->init_mem);
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004044 kfree(phba->phwi_ctrlr->wrb_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304045 kfree(phba->phwi_ctrlr);
4046}
4047
4048static int beiscsi_init_controller(struct beiscsi_hba *phba)
4049{
4050 int ret = -ENOMEM;
4051
4052 ret = beiscsi_get_memory(phba);
4053 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304054 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4055 "BM_%d : beiscsi_dev_probe -"
4056 "Failed in beiscsi_alloc_memory\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304057 return ret;
4058 }
4059
4060 ret = hwi_init_controller(phba);
4061 if (ret)
4062 goto free_init;
John Soni Jose99bc5d52012-08-20 23:00:18 +05304063 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4064 "BM_%d : Return success from beiscsi_init_controller");
4065
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304066 return 0;
4067
4068free_init:
4069 beiscsi_free_mem(phba);
Jayamohan Kallickala49e06d2012-04-03 23:41:44 -05004070 return ret;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304071}
4072
4073static int beiscsi_init_sgl_handle(struct beiscsi_hba *phba)
4074{
4075 struct be_mem_descriptor *mem_descr_sglh, *mem_descr_sg;
4076 struct sgl_handle *psgl_handle;
4077 struct iscsi_sge *pfrag;
Jayamohan Kallickal90622db2013-09-28 15:35:47 -07004078 unsigned int arr_index, i, idx;
4079 unsigned int ulp_icd_start, ulp_num = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304080
4081 phba->io_sgl_hndl_avbl = 0;
4082 phba->eh_sgl_hndl_avbl = 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304083
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304084 mem_descr_sglh = phba->init_mem;
4085 mem_descr_sglh += HWI_MEM_SGLH;
4086 if (1 == mem_descr_sglh->num_elements) {
4087 phba->io_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
4088 phba->params.ios_per_ctrl,
4089 GFP_KERNEL);
4090 if (!phba->io_sgl_hndl_base) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304091 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4092 "BM_%d : Mem Alloc Failed. Failing to load\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304093 return -ENOMEM;
4094 }
4095 phba->eh_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
4096 (phba->params.icds_per_ctrl -
4097 phba->params.ios_per_ctrl),
4098 GFP_KERNEL);
4099 if (!phba->eh_sgl_hndl_base) {
4100 kfree(phba->io_sgl_hndl_base);
John Soni Jose99bc5d52012-08-20 23:00:18 +05304101 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4102 "BM_%d : Mem Alloc Failed. Failing to load\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304103 return -ENOMEM;
4104 }
4105 } else {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304106 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4107 "BM_%d : HWI_MEM_SGLH is more than one element."
4108 "Failing to load\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304109 return -ENOMEM;
4110 }
4111
4112 arr_index = 0;
4113 idx = 0;
4114 while (idx < mem_descr_sglh->num_elements) {
4115 psgl_handle = mem_descr_sglh->mem_array[idx].virtual_address;
4116
4117 for (i = 0; i < (mem_descr_sglh->mem_array[idx].size /
4118 sizeof(struct sgl_handle)); i++) {
4119 if (arr_index < phba->params.ios_per_ctrl) {
4120 phba->io_sgl_hndl_base[arr_index] = psgl_handle;
4121 phba->io_sgl_hndl_avbl++;
4122 arr_index++;
4123 } else {
4124 phba->eh_sgl_hndl_base[arr_index -
4125 phba->params.ios_per_ctrl] =
4126 psgl_handle;
4127 arr_index++;
4128 phba->eh_sgl_hndl_avbl++;
4129 }
4130 psgl_handle++;
4131 }
4132 idx++;
4133 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05304134 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4135 "BM_%d : phba->io_sgl_hndl_avbl=%d"
4136 "phba->eh_sgl_hndl_avbl=%d\n",
4137 phba->io_sgl_hndl_avbl,
4138 phba->eh_sgl_hndl_avbl);
4139
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304140 mem_descr_sg = phba->init_mem;
4141 mem_descr_sg += HWI_MEM_SGE;
John Soni Jose99bc5d52012-08-20 23:00:18 +05304142 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4143 "\n BM_%d : mem_descr_sg->num_elements=%d\n",
4144 mem_descr_sg->num_elements);
4145
Jayamohan Kallickal90622db2013-09-28 15:35:47 -07004146 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
4147 if (test_bit(ulp_num, &phba->fw_config.ulp_supported))
4148 break;
4149
4150 ulp_icd_start = phba->fw_config.iscsi_icd_start[ulp_num];
4151
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304152 arr_index = 0;
4153 idx = 0;
4154 while (idx < mem_descr_sg->num_elements) {
4155 pfrag = mem_descr_sg->mem_array[idx].virtual_address;
4156
4157 for (i = 0;
4158 i < (mem_descr_sg->mem_array[idx].size) /
4159 (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io);
4160 i++) {
4161 if (arr_index < phba->params.ios_per_ctrl)
4162 psgl_handle = phba->io_sgl_hndl_base[arr_index];
4163 else
4164 psgl_handle = phba->eh_sgl_hndl_base[arr_index -
4165 phba->params.ios_per_ctrl];
4166 psgl_handle->pfrag = pfrag;
4167 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, pfrag, 0);
4168 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, pfrag, 0);
4169 pfrag += phba->params.num_sge_per_io;
Jayamohan Kallickal90622db2013-09-28 15:35:47 -07004170 psgl_handle->sgl_index = ulp_icd_start + arr_index++;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304171 }
4172 idx++;
4173 }
4174 phba->io_sgl_free_index = 0;
4175 phba->io_sgl_alloc_index = 0;
4176 phba->eh_sgl_free_index = 0;
4177 phba->eh_sgl_alloc_index = 0;
4178 return 0;
4179}
4180
4181static int hba_setup_cid_tbls(struct beiscsi_hba *phba)
4182{
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07004183 int ret;
4184 uint16_t i, ulp_num;
4185 struct ulp_cid_info *ptr_cid_info = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304186
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07004187 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
4188 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
4189 ptr_cid_info = kzalloc(sizeof(struct ulp_cid_info),
4190 GFP_KERNEL);
4191
4192 if (!ptr_cid_info) {
4193 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4194 "BM_%d : Failed to allocate memory"
4195 "for ULP_CID_INFO for ULP : %d\n",
4196 ulp_num);
4197 ret = -ENOMEM;
4198 goto free_memory;
4199
4200 }
4201
4202 /* Allocate memory for CID array */
4203 ptr_cid_info->cid_array = kzalloc(sizeof(void *) *
4204 BEISCSI_GET_CID_COUNT(phba,
4205 ulp_num), GFP_KERNEL);
4206 if (!ptr_cid_info->cid_array) {
4207 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4208 "BM_%d : Failed to allocate memory"
4209 "for CID_ARRAY for ULP : %d\n",
4210 ulp_num);
4211 kfree(ptr_cid_info);
4212 ptr_cid_info = NULL;
4213 ret = -ENOMEM;
4214
4215 goto free_memory;
4216 }
4217 ptr_cid_info->avlbl_cids = BEISCSI_GET_CID_COUNT(
4218 phba, ulp_num);
4219
4220 /* Save the cid_info_array ptr */
4221 phba->cid_array_info[ulp_num] = ptr_cid_info;
4222 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304223 }
Jayamohan Kallickalc2462282010-01-05 05:05:34 +05304224 phba->ep_array = kzalloc(sizeof(struct iscsi_endpoint *) *
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004225 phba->params.cxns_per_ctrl, GFP_KERNEL);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304226 if (!phba->ep_array) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304227 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4228 "BM_%d : Failed to allocate memory in "
4229 "hba_setup_cid_tbls\n");
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07004230 ret = -ENOMEM;
4231
4232 goto free_memory;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304233 }
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004234
4235 phba->conn_table = kzalloc(sizeof(struct beiscsi_conn *) *
4236 phba->params.cxns_per_ctrl, GFP_KERNEL);
4237 if (!phba->conn_table) {
4238 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4239 "BM_%d : Failed to allocate memory in"
4240 "hba_setup_cid_tbls\n");
4241
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004242 kfree(phba->ep_array);
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004243 phba->ep_array = NULL;
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07004244 ret = -ENOMEM;
Tomas Henzl5f2d25e2014-06-06 14:06:30 +02004245
4246 goto free_memory;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304247 }
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004248
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07004249 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
4250 ulp_num = phba->phwi_ctrlr->wrb_context[i].ulp_num;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004251
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07004252 ptr_cid_info = phba->cid_array_info[ulp_num];
4253 ptr_cid_info->cid_array[ptr_cid_info->cid_alloc++] =
4254 phba->phwi_ctrlr->wrb_context[i].cid;
4255
4256 }
4257
4258 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
4259 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
4260 ptr_cid_info = phba->cid_array_info[ulp_num];
4261
4262 ptr_cid_info->cid_alloc = 0;
4263 ptr_cid_info->cid_free = 0;
4264 }
4265 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304266 return 0;
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07004267
4268free_memory:
4269 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
4270 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
4271 ptr_cid_info = phba->cid_array_info[ulp_num];
4272
4273 if (ptr_cid_info) {
4274 kfree(ptr_cid_info->cid_array);
4275 kfree(ptr_cid_info);
4276 phba->cid_array_info[ulp_num] = NULL;
4277 }
4278 }
4279 }
4280
4281 return ret;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304282}
4283
Jayamohan Kallickal238f6b72010-07-22 04:23:22 +05304284static void hwi_enable_intr(struct beiscsi_hba *phba)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304285{
4286 struct be_ctrl_info *ctrl = &phba->ctrl;
4287 struct hwi_controller *phwi_ctrlr;
4288 struct hwi_context_memory *phwi_context;
4289 struct be_queue_info *eq;
4290 u8 __iomem *addr;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304291 u32 reg, i;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304292 u32 enabled;
4293
4294 phwi_ctrlr = phba->phwi_ctrlr;
4295 phwi_context = phwi_ctrlr->phwi_ctxt;
4296
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304297 addr = (u8 __iomem *) ((u8 __iomem *) ctrl->pcicfg +
4298 PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET);
4299 reg = ioread32(addr);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304300
4301 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
4302 if (!enabled) {
4303 reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
John Soni Jose99bc5d52012-08-20 23:00:18 +05304304 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4305 "BM_%d : reg =x%08x addr=%p\n", reg, addr);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304306 iowrite32(reg, addr);
Jayamohan Kallickal665d6d92011-04-29 14:30:06 -05004307 }
4308
4309 if (!phba->msix_enabled) {
4310 eq = &phwi_context->be_eq[0].q;
John Soni Jose99bc5d52012-08-20 23:00:18 +05304311 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4312 "BM_%d : eq->id=%d\n", eq->id);
4313
Jayamohan Kallickal665d6d92011-04-29 14:30:06 -05004314 hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
4315 } else {
4316 for (i = 0; i <= phba->num_cpus; i++) {
4317 eq = &phwi_context->be_eq[i].q;
John Soni Jose99bc5d52012-08-20 23:00:18 +05304318 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4319 "BM_%d : eq->id=%d\n", eq->id);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304320 hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
4321 }
Jayamohan Kallickalc03af1a2010-02-20 08:05:43 +05304322 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304323}
4324
4325static void hwi_disable_intr(struct beiscsi_hba *phba)
4326{
4327 struct be_ctrl_info *ctrl = &phba->ctrl;
4328
4329 u8 __iomem *addr = ctrl->pcicfg + PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET;
4330 u32 reg = ioread32(addr);
4331
4332 u32 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
4333 if (enabled) {
4334 reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
4335 iowrite32(reg, addr);
4336 } else
John Soni Jose99bc5d52012-08-20 23:00:18 +05304337 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
4338 "BM_%d : In hwi_disable_intr, Already Disabled\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304339}
4340
John Soni Jose9aef4202012-08-20 23:00:08 +05304341/**
4342 * beiscsi_get_boot_info()- Get the boot session info
4343 * @phba: The device priv structure instance
4344 *
4345 * Get the boot target info and store in driver priv structure
4346 *
4347 * return values
4348 * Success: 0
4349 * Failure: Non-Zero Value
4350 **/
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304351static int beiscsi_get_boot_info(struct beiscsi_hba *phba)
4352{
Mike Christie0e438952012-04-03 23:41:51 -05004353 struct be_cmd_get_session_resp *session_resp;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304354 struct be_dma_mem nonemb_cmd;
John Soni Josee175def2012-10-20 04:45:40 +05304355 unsigned int tag;
John Soni Jose9aef4202012-08-20 23:00:08 +05304356 unsigned int s_handle;
Mike Christief457a462011-06-24 15:11:53 -05004357 int ret = -ENOMEM;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304358
John Soni Jose9aef4202012-08-20 23:00:08 +05304359 /* Get the session handle of the boot target */
4360 ret = be_mgmt_get_boot_shandle(phba, &s_handle);
4361 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304362 beiscsi_log(phba, KERN_ERR,
4363 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
4364 "BM_%d : No boot session\n");
John Soni Jose3efde862015-04-25 08:16:57 +05304365
4366 if (ret == -ENXIO)
4367 phba->get_boot = 0;
4368
4369
John Soni Jose9aef4202012-08-20 23:00:08 +05304370 return ret;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304371 }
John Soni Jose3efde862015-04-25 08:16:57 +05304372 phba->get_boot = 0;
Joe Perches7c845eb2014-08-08 14:24:46 -07004373 nonemb_cmd.va = pci_zalloc_consistent(phba->ctrl.pdev,
4374 sizeof(*session_resp),
4375 &nonemb_cmd.dma);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304376 if (nonemb_cmd.va == NULL) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304377 beiscsi_log(phba, KERN_ERR,
4378 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
4379 "BM_%d : Failed to allocate memory for"
4380 "beiscsi_get_session_info\n");
4381
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304382 return -ENOMEM;
4383 }
4384
John Soni Jose9aef4202012-08-20 23:00:08 +05304385 tag = mgmt_get_session_info(phba, s_handle,
Mike Christie0e438952012-04-03 23:41:51 -05004386 &nonemb_cmd);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304387 if (!tag) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304388 beiscsi_log(phba, KERN_ERR,
4389 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
4390 "BM_%d : beiscsi_get_session_info"
4391 " Failed\n");
4392
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304393 goto boot_freemem;
John Soni Josee175def2012-10-20 04:45:40 +05304394 }
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304395
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -05004396 ret = beiscsi_mccq_compl(phba, tag, NULL, &nonemb_cmd);
John Soni Josee175def2012-10-20 04:45:40 +05304397 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304398 beiscsi_log(phba, KERN_ERR,
4399 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
John Soni Josee175def2012-10-20 04:45:40 +05304400 "BM_%d : beiscsi_get_session_info Failed");
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -05004401
4402 if (ret != -EBUSY)
4403 goto boot_freemem;
4404 else
4405 return ret;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304406 }
John Soni Josee175def2012-10-20 04:45:40 +05304407
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304408 session_resp = nonemb_cmd.va ;
Mike Christief457a462011-06-24 15:11:53 -05004409
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304410 memcpy(&phba->boot_sess, &session_resp->session_info,
4411 sizeof(struct mgmt_session_info));
John Soni Jose3f4134c2015-04-25 08:18:13 +05304412
4413 beiscsi_logout_fw_sess(phba,
4414 phba->boot_sess.session_handle);
Mike Christief457a462011-06-24 15:11:53 -05004415 ret = 0;
4416
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304417boot_freemem:
4418 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
4419 nonemb_cmd.va, nonemb_cmd.dma);
Mike Christief457a462011-06-24 15:11:53 -05004420 return ret;
4421}
4422
4423static void beiscsi_boot_release(void *data)
4424{
4425 struct beiscsi_hba *phba = data;
4426
4427 scsi_host_put(phba->shost);
4428}
4429
4430static int beiscsi_setup_boot_info(struct beiscsi_hba *phba)
4431{
4432 struct iscsi_boot_kobj *boot_kobj;
4433
Jayamohan Kallickala3d313e2014-08-08 01:00:00 -04004434 /* it has been created previously */
4435 if (phba->boot_kset)
4436 return 0;
4437
Mike Christief457a462011-06-24 15:11:53 -05004438 /* get boot info using mgmt cmd */
4439 if (beiscsi_get_boot_info(phba))
4440 /* Try to see if we can carry on without this */
4441 return 0;
4442
4443 phba->boot_kset = iscsi_boot_create_host_kset(phba->shost->host_no);
4444 if (!phba->boot_kset)
4445 return -ENOMEM;
4446
4447 /* get a ref because the show function will ref the phba */
4448 if (!scsi_host_get(phba->shost))
4449 goto free_kset;
4450 boot_kobj = iscsi_boot_create_target(phba->boot_kset, 0, phba,
4451 beiscsi_show_boot_tgt_info,
4452 beiscsi_tgt_get_attr_visibility,
4453 beiscsi_boot_release);
4454 if (!boot_kobj)
4455 goto put_shost;
4456
4457 if (!scsi_host_get(phba->shost))
4458 goto free_kset;
4459 boot_kobj = iscsi_boot_create_initiator(phba->boot_kset, 0, phba,
4460 beiscsi_show_boot_ini_info,
4461 beiscsi_ini_get_attr_visibility,
4462 beiscsi_boot_release);
4463 if (!boot_kobj)
4464 goto put_shost;
4465
4466 if (!scsi_host_get(phba->shost))
4467 goto free_kset;
4468 boot_kobj = iscsi_boot_create_ethernet(phba->boot_kset, 0, phba,
4469 beiscsi_show_boot_eth_info,
4470 beiscsi_eth_get_attr_visibility,
4471 beiscsi_boot_release);
4472 if (!boot_kobj)
4473 goto put_shost;
4474 return 0;
4475
4476put_shost:
4477 scsi_host_put(phba->shost);
4478free_kset:
4479 iscsi_boot_destroy_kset(phba->boot_kset);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304480 return -ENOMEM;
4481}
4482
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304483static int beiscsi_init_port(struct beiscsi_hba *phba)
4484{
4485 int ret;
4486
4487 ret = beiscsi_init_controller(phba);
4488 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304489 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4490 "BM_%d : beiscsi_dev_probe - Failed in"
4491 "beiscsi_init_controller\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304492 return ret;
4493 }
4494 ret = beiscsi_init_sgl_handle(phba);
4495 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304496 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4497 "BM_%d : beiscsi_dev_probe - Failed in"
4498 "beiscsi_init_sgl_handle\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304499 goto do_cleanup_ctrlr;
4500 }
4501
4502 if (hba_setup_cid_tbls(phba)) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304503 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4504 "BM_%d : Failed in hba_setup_cid_tbls\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304505 kfree(phba->io_sgl_hndl_base);
4506 kfree(phba->eh_sgl_hndl_base);
4507 goto do_cleanup_ctrlr;
4508 }
4509
4510 return ret;
4511
4512do_cleanup_ctrlr:
4513 hwi_cleanup(phba);
4514 return ret;
4515}
4516
4517static void hwi_purge_eq(struct beiscsi_hba *phba)
4518{
4519 struct hwi_controller *phwi_ctrlr;
4520 struct hwi_context_memory *phwi_context;
4521 struct be_queue_info *eq;
4522 struct be_eq_entry *eqe = NULL;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304523 int i, eq_msix;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05304524 unsigned int num_processed;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304525
4526 phwi_ctrlr = phba->phwi_ctrlr;
4527 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304528 if (phba->msix_enabled)
4529 eq_msix = 1;
4530 else
4531 eq_msix = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304532
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304533 for (i = 0; i < (phba->num_cpus + eq_msix); i++) {
4534 eq = &phwi_context->be_eq[i].q;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304535 eqe = queue_tail_node(eq);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05304536 num_processed = 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304537 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
4538 & EQE_VALID_MASK) {
4539 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
4540 queue_tail_inc(eq);
4541 eqe = queue_tail_node(eq);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05304542 num_processed++;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304543 }
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05304544
4545 if (num_processed)
4546 hwi_ring_eq_db(phba, eq->id, 1, num_processed, 1, 1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304547 }
4548}
4549
4550static void beiscsi_clean_port(struct beiscsi_hba *phba)
4551{
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07004552 int mgmt_status, ulp_num;
4553 struct ulp_cid_info *ptr_cid_info = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304554
Jayamohan Kallickalbd41c2b2013-09-28 15:35:51 -07004555 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
4556 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
4557 mgmt_status = mgmt_epfw_cleanup(phba, ulp_num);
4558 if (mgmt_status)
4559 beiscsi_log(phba, KERN_WARNING,
4560 BEISCSI_LOG_INIT,
4561 "BM_%d : mgmt_epfw_cleanup FAILED"
4562 " for ULP_%d\n", ulp_num);
4563 }
4564 }
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05304565
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304566 hwi_purge_eq(phba);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05304567 hwi_cleanup(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304568 kfree(phba->io_sgl_hndl_base);
4569 kfree(phba->eh_sgl_hndl_base);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304570 kfree(phba->ep_array);
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004571 kfree(phba->conn_table);
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07004572
4573 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
4574 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
4575 ptr_cid_info = phba->cid_array_info[ulp_num];
4576
4577 if (ptr_cid_info) {
4578 kfree(ptr_cid_info->cid_array);
4579 kfree(ptr_cid_info);
4580 phba->cid_array_info[ulp_num] = NULL;
4581 }
4582 }
4583 }
4584
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304585}
4586
John Soni Josed629c472012-10-20 04:42:00 +05304587/**
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004588 * beiscsi_free_mgmt_task_handles()- Free driver CXN resources
4589 * @beiscsi_conn: ptr to the conn to be cleaned up
Jayamohan Kallickal4a4a11b2013-04-05 20:38:31 -07004590 * @task: ptr to iscsi_task resource to be freed.
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004591 *
4592 * Free driver mgmt resources binded to CXN.
4593 **/
4594void
Jayamohan Kallickal4a4a11b2013-04-05 20:38:31 -07004595beiscsi_free_mgmt_task_handles(struct beiscsi_conn *beiscsi_conn,
4596 struct iscsi_task *task)
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004597{
4598 struct beiscsi_io_task *io_task;
4599 struct beiscsi_hba *phba = beiscsi_conn->phba;
4600 struct hwi_wrb_context *pwrb_context;
4601 struct hwi_controller *phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004602 uint16_t cri_index = BE_GET_CRI_FROM_CID(
4603 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004604
4605 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004606 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
4607
Jayamohan Kallickal4a4a11b2013-04-05 20:38:31 -07004608 io_task = task->dd_data;
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004609
4610 if (io_task->pwrb_handle) {
4611 memset(io_task->pwrb_handle->pwrb, 0,
4612 sizeof(struct iscsi_wrb));
4613 free_wrb_handle(phba, pwrb_context,
4614 io_task->pwrb_handle);
4615 io_task->pwrb_handle = NULL;
4616 }
4617
4618 if (io_task->psgl_handle) {
4619 spin_lock_bh(&phba->mgmt_sgl_lock);
4620 free_mgmt_sgl_handle(phba,
4621 io_task->psgl_handle);
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004622 io_task->psgl_handle = NULL;
Jayamohan Kallickal4a4a11b2013-04-05 20:38:31 -07004623 spin_unlock_bh(&phba->mgmt_sgl_lock);
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004624 }
4625
John Soni Joseeb1c4692015-04-25 08:17:45 +05304626 if (io_task->mtask_addr) {
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004627 pci_unmap_single(phba->pcidev,
4628 io_task->mtask_addr,
4629 io_task->mtask_data_count,
4630 PCI_DMA_TODEVICE);
John Soni Joseeb1c4692015-04-25 08:17:45 +05304631 io_task->mtask_addr = 0;
4632 }
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004633}
4634
4635/**
John Soni Josed629c472012-10-20 04:42:00 +05304636 * beiscsi_cleanup_task()- Free driver resources of the task
4637 * @task: ptr to the iscsi task
4638 *
4639 **/
Mike Christie1282ab72012-04-18 03:06:00 -05004640static void beiscsi_cleanup_task(struct iscsi_task *task)
4641{
4642 struct beiscsi_io_task *io_task = task->dd_data;
4643 struct iscsi_conn *conn = task->conn;
4644 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4645 struct beiscsi_hba *phba = beiscsi_conn->phba;
4646 struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
4647 struct hwi_wrb_context *pwrb_context;
4648 struct hwi_controller *phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004649 uint16_t cri_index = BE_GET_CRI_FROM_CID(
4650 beiscsi_conn->beiscsi_conn_cid);
Mike Christie1282ab72012-04-18 03:06:00 -05004651
4652 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004653 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
Mike Christie1282ab72012-04-18 03:06:00 -05004654
4655 if (io_task->cmd_bhs) {
4656 pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
4657 io_task->bhs_pa.u.a64.address);
4658 io_task->cmd_bhs = NULL;
4659 }
4660
4661 if (task->sc) {
4662 if (io_task->pwrb_handle) {
4663 free_wrb_handle(phba, pwrb_context,
4664 io_task->pwrb_handle);
4665 io_task->pwrb_handle = NULL;
4666 }
4667
4668 if (io_task->psgl_handle) {
4669 spin_lock(&phba->io_sgl_lock);
4670 free_io_sgl_handle(phba, io_task->psgl_handle);
4671 spin_unlock(&phba->io_sgl_lock);
4672 io_task->psgl_handle = NULL;
4673 }
Jayamohan Kallickalda334972014-01-29 02:16:44 -05004674
4675 if (io_task->scsi_cmnd) {
4676 scsi_dma_unmap(io_task->scsi_cmnd);
4677 io_task->scsi_cmnd = NULL;
4678 }
Mike Christie1282ab72012-04-18 03:06:00 -05004679 } else {
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004680 if (!beiscsi_conn->login_in_progress)
Jayamohan Kallickal4a4a11b2013-04-05 20:38:31 -07004681 beiscsi_free_mgmt_task_handles(beiscsi_conn, task);
Mike Christie1282ab72012-04-18 03:06:00 -05004682 }
4683}
4684
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304685void
4686beiscsi_offload_connection(struct beiscsi_conn *beiscsi_conn,
4687 struct beiscsi_offload_params *params)
4688{
4689 struct wrb_handle *pwrb_handle;
John Soni Jose340c99e2015-08-20 04:44:30 +05304690 struct hwi_wrb_context *pwrb_context = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304691 struct beiscsi_hba *phba = beiscsi_conn->phba;
Mike Christie1282ab72012-04-18 03:06:00 -05004692 struct iscsi_task *task = beiscsi_conn->task;
4693 struct iscsi_session *session = task->conn->session;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304694 u32 doorbell = 0;
4695
4696 /*
4697 * We can always use 0 here because it is reserved by libiscsi for
4698 * login/startup related tasks.
4699 */
Mike Christie1282ab72012-04-18 03:06:00 -05004700 beiscsi_conn->login_in_progress = 0;
Shlomo Pongratz659743b2014-02-07 00:41:38 -06004701 spin_lock_bh(&session->back_lock);
Mike Christie1282ab72012-04-18 03:06:00 -05004702 beiscsi_cleanup_task(task);
Shlomo Pongratz659743b2014-02-07 00:41:38 -06004703 spin_unlock_bh(&session->back_lock);
Mike Christie1282ab72012-04-18 03:06:00 -05004704
John Soni Jose340c99e2015-08-20 04:44:30 +05304705 pwrb_handle = alloc_wrb_handle(phba, beiscsi_conn->beiscsi_conn_cid,
4706 &pwrb_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304707
John Soni Joseacb96932012-10-20 04:44:35 +05304708 /* Check for the adapter family */
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004709 if (is_chip_be2_be3r(phba))
John Soni Joseacb96932012-10-20 04:44:35 +05304710 beiscsi_offload_cxn_v0(params, pwrb_handle,
John Soni Jose340c99e2015-08-20 04:44:30 +05304711 phba->init_mem,
4712 pwrb_context);
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004713 else
John Soni Jose340c99e2015-08-20 04:44:30 +05304714 beiscsi_offload_cxn_v2(params, pwrb_handle,
4715 pwrb_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304716
John Soni Joseacb96932012-10-20 04:44:35 +05304717 be_dws_le_to_cpu(pwrb_handle->pwrb,
4718 sizeof(struct iscsi_target_context_update_wrb));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304719
4720 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304721 doorbell |= (pwrb_handle->wrb_index & DB_DEF_PDU_WRB_INDEX_MASK)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304722 << DB_DEF_PDU_WRB_INDEX_SHIFT;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304723 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
Jayamohan Kallickal1e4be6f2013-09-28 15:35:50 -07004724 iowrite32(doorbell, phba->db_va +
4725 beiscsi_conn->doorbell_offset);
Jitendra Bhivarecb564c62016-01-20 14:11:00 +05304726
4727 /*
4728 * There is no completion for CONTEXT_UPDATE. The completion of next
4729 * WRB posted guarantees FW's processing and DMA'ing of it.
4730 * Use beiscsi_put_wrb_handle to put it back in the pool which makes
4731 * sure zero'ing or reuse of the WRB only after wrbs_per_cxn.
4732 */
4733 beiscsi_put_wrb_handle(pwrb_context, pwrb_handle,
4734 phba->params.wrbs_per_cxn);
4735 beiscsi_log(phba, KERN_INFO,
4736 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
4737 "BM_%d : put CONTEXT_UPDATE pwrb_handle=%p free_index=0x%x wrb_handles_available=%d\n",
4738 pwrb_handle, pwrb_context->free_index,
4739 pwrb_context->wrb_handles_available);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304740}
4741
4742static void beiscsi_parse_pdu(struct iscsi_conn *conn, itt_t itt,
4743 int *index, int *age)
4744{
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304745 *index = (int)itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304746 if (age)
4747 *age = conn->session->age;
4748}
4749
4750/**
4751 * beiscsi_alloc_pdu - allocates pdu and related resources
4752 * @task: libiscsi task
4753 * @opcode: opcode of pdu for task
4754 *
4755 * This is called with the session lock held. It will allocate
4756 * the wrb and sgl if needed for the command. And it will prep
4757 * the pdu's itt. beiscsi_parse_pdu will later translate
4758 * the pdu itt to the libiscsi task itt.
4759 */
4760static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
4761{
4762 struct beiscsi_io_task *io_task = task->dd_data;
4763 struct iscsi_conn *conn = task->conn;
4764 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4765 struct beiscsi_hba *phba = beiscsi_conn->phba;
4766 struct hwi_wrb_context *pwrb_context;
4767 struct hwi_controller *phwi_ctrlr;
4768 itt_t itt;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004769 uint16_t cri_index = 0;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304770 struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
4771 dma_addr_t paddr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304772
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304773 io_task->cmd_bhs = pci_pool_alloc(beiscsi_sess->bhs_pool,
Mike Christiebc7acce2010-12-31 02:22:19 -06004774 GFP_ATOMIC, &paddr);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304775 if (!io_task->cmd_bhs)
4776 return -ENOMEM;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304777 io_task->bhs_pa.u.a64.address = paddr;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304778 io_task->libiscsi_itt = (itt_t)task->itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304779 io_task->conn = beiscsi_conn;
4780
4781 task->hdr = (struct iscsi_hdr *)&io_task->cmd_bhs->iscsi_hdr;
4782 task->hdr_max = sizeof(struct be_cmd_bhs);
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304783 io_task->psgl_handle = NULL;
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05004784 io_task->pwrb_handle = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304785
4786 if (task->sc) {
4787 spin_lock(&phba->io_sgl_lock);
4788 io_task->psgl_handle = alloc_io_sgl_handle(phba);
4789 spin_unlock(&phba->io_sgl_lock);
John Soni Jose8359c792012-10-20 04:43:03 +05304790 if (!io_task->psgl_handle) {
4791 beiscsi_log(phba, KERN_ERR,
4792 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
4793 "BM_%d : Alloc of IO_SGL_ICD Failed"
4794 "for the CID : %d\n",
4795 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304796 goto free_hndls;
John Soni Jose8359c792012-10-20 04:43:03 +05304797 }
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304798 io_task->pwrb_handle = alloc_wrb_handle(phba,
John Soni Jose340c99e2015-08-20 04:44:30 +05304799 beiscsi_conn->beiscsi_conn_cid,
4800 &io_task->pwrb_context);
John Soni Jose8359c792012-10-20 04:43:03 +05304801 if (!io_task->pwrb_handle) {
4802 beiscsi_log(phba, KERN_ERR,
4803 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
4804 "BM_%d : Alloc of WRB_HANDLE Failed"
4805 "for the CID : %d\n",
4806 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304807 goto free_io_hndls;
John Soni Jose8359c792012-10-20 04:43:03 +05304808 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304809 } else {
4810 io_task->scsi_cmnd = NULL;
Jayamohan Kallickald7aea672010-01-05 05:08:39 +05304811 if ((opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN) {
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004812 beiscsi_conn->task = task;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304813 if (!beiscsi_conn->login_in_progress) {
4814 spin_lock(&phba->mgmt_sgl_lock);
4815 io_task->psgl_handle = (struct sgl_handle *)
4816 alloc_mgmt_sgl_handle(phba);
4817 spin_unlock(&phba->mgmt_sgl_lock);
John Soni Jose8359c792012-10-20 04:43:03 +05304818 if (!io_task->psgl_handle) {
4819 beiscsi_log(phba, KERN_ERR,
4820 BEISCSI_LOG_IO |
4821 BEISCSI_LOG_CONFIG,
4822 "BM_%d : Alloc of MGMT_SGL_ICD Failed"
4823 "for the CID : %d\n",
4824 beiscsi_conn->
4825 beiscsi_conn_cid);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304826 goto free_hndls;
John Soni Jose8359c792012-10-20 04:43:03 +05304827 }
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304828
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304829 beiscsi_conn->login_in_progress = 1;
4830 beiscsi_conn->plogin_sgl_handle =
4831 io_task->psgl_handle;
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304832 io_task->pwrb_handle =
4833 alloc_wrb_handle(phba,
John Soni Jose340c99e2015-08-20 04:44:30 +05304834 beiscsi_conn->beiscsi_conn_cid,
4835 &io_task->pwrb_context);
John Soni Jose8359c792012-10-20 04:43:03 +05304836 if (!io_task->pwrb_handle) {
4837 beiscsi_log(phba, KERN_ERR,
4838 BEISCSI_LOG_IO |
4839 BEISCSI_LOG_CONFIG,
4840 "BM_%d : Alloc of WRB_HANDLE Failed"
4841 "for the CID : %d\n",
4842 beiscsi_conn->
4843 beiscsi_conn_cid);
4844 goto free_mgmt_hndls;
4845 }
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304846 beiscsi_conn->plogin_wrb_handle =
4847 io_task->pwrb_handle;
4848
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304849 } else {
4850 io_task->psgl_handle =
4851 beiscsi_conn->plogin_sgl_handle;
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304852 io_task->pwrb_handle =
4853 beiscsi_conn->plogin_wrb_handle;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304854 }
4855 } else {
4856 spin_lock(&phba->mgmt_sgl_lock);
4857 io_task->psgl_handle = alloc_mgmt_sgl_handle(phba);
4858 spin_unlock(&phba->mgmt_sgl_lock);
John Soni Jose8359c792012-10-20 04:43:03 +05304859 if (!io_task->psgl_handle) {
4860 beiscsi_log(phba, KERN_ERR,
4861 BEISCSI_LOG_IO |
4862 BEISCSI_LOG_CONFIG,
4863 "BM_%d : Alloc of MGMT_SGL_ICD Failed"
4864 "for the CID : %d\n",
4865 beiscsi_conn->
4866 beiscsi_conn_cid);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304867 goto free_hndls;
John Soni Jose8359c792012-10-20 04:43:03 +05304868 }
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304869 io_task->pwrb_handle =
4870 alloc_wrb_handle(phba,
John Soni Jose340c99e2015-08-20 04:44:30 +05304871 beiscsi_conn->beiscsi_conn_cid,
4872 &io_task->pwrb_context);
John Soni Jose8359c792012-10-20 04:43:03 +05304873 if (!io_task->pwrb_handle) {
4874 beiscsi_log(phba, KERN_ERR,
4875 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
4876 "BM_%d : Alloc of WRB_HANDLE Failed"
4877 "for the CID : %d\n",
4878 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304879 goto free_mgmt_hndls;
John Soni Jose8359c792012-10-20 04:43:03 +05304880 }
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304881
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304882 }
4883 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304884 itt = (itt_t) cpu_to_be32(((unsigned int)io_task->pwrb_handle->
4885 wrb_index << 16) | (unsigned int)
4886 (io_task->psgl_handle->sgl_index));
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304887 io_task->pwrb_handle->pio_handle = task;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304888
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304889 io_task->cmd_bhs->iscsi_hdr.itt = itt;
4890 return 0;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304891
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304892free_io_hndls:
4893 spin_lock(&phba->io_sgl_lock);
4894 free_io_sgl_handle(phba, io_task->psgl_handle);
4895 spin_unlock(&phba->io_sgl_lock);
4896 goto free_hndls;
4897free_mgmt_hndls:
4898 spin_lock(&phba->mgmt_sgl_lock);
4899 free_mgmt_sgl_handle(phba, io_task->psgl_handle);
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004900 io_task->psgl_handle = NULL;
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304901 spin_unlock(&phba->mgmt_sgl_lock);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304902free_hndls:
4903 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004904 cri_index = BE_GET_CRI_FROM_CID(
4905 beiscsi_conn->beiscsi_conn_cid);
4906 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304907 if (io_task->pwrb_handle)
4908 free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304909 io_task->pwrb_handle = NULL;
4910 pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
4911 io_task->bhs_pa.u.a64.address);
Mike Christie1282ab72012-04-18 03:06:00 -05004912 io_task->cmd_bhs = NULL;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304913 return -ENOMEM;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304914}
John Soni Jose09a10932012-10-20 04:44:23 +05304915int beiscsi_iotask_v2(struct iscsi_task *task, struct scatterlist *sg,
4916 unsigned int num_sg, unsigned int xferlen,
4917 unsigned int writedir)
4918{
4919
4920 struct beiscsi_io_task *io_task = task->dd_data;
4921 struct iscsi_conn *conn = task->conn;
4922 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4923 struct beiscsi_hba *phba = beiscsi_conn->phba;
4924 struct iscsi_wrb *pwrb = NULL;
4925 unsigned int doorbell = 0;
4926
4927 pwrb = io_task->pwrb_handle->pwrb;
John Soni Jose09a10932012-10-20 04:44:23 +05304928
4929 io_task->cmd_bhs->iscsi_hdr.exp_statsn = 0;
4930 io_task->bhs_len = sizeof(struct be_cmd_bhs);
4931
4932 if (writedir) {
4933 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb,
4934 INI_WR_CMD);
4935 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 1);
4936 } else {
4937 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb,
4938 INI_RD_CMD);
4939 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 0);
4940 }
4941
4942 io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb_v2,
4943 type, pwrb);
4944
4945 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, lun, pwrb,
4946 cpu_to_be16(*(unsigned short *)
4947 &io_task->cmd_bhs->iscsi_hdr.lun));
4948 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb, xferlen);
4949 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb,
4950 io_task->pwrb_handle->wrb_index);
4951 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb,
4952 be32_to_cpu(task->cmdsn));
4953 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb,
4954 io_task->psgl_handle->sgl_index);
4955
4956 hwi_write_sgl_v2(pwrb, sg, num_sg, io_task);
4957 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb,
John Soni Jose340c99e2015-08-20 04:44:30 +05304958 io_task->pwrb_handle->wrb_index);
4959 if (io_task->pwrb_context->plast_wrb)
4960 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb,
4961 io_task->pwrb_context->plast_wrb,
4962 io_task->pwrb_handle->wrb_index);
4963 io_task->pwrb_context->plast_wrb = pwrb;
John Soni Jose09a10932012-10-20 04:44:23 +05304964
4965 be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
4966
4967 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
4968 doorbell |= (io_task->pwrb_handle->wrb_index &
4969 DB_DEF_PDU_WRB_INDEX_MASK) <<
4970 DB_DEF_PDU_WRB_INDEX_SHIFT;
4971 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
Jayamohan Kallickal1e4be6f2013-09-28 15:35:50 -07004972 iowrite32(doorbell, phba->db_va +
4973 beiscsi_conn->doorbell_offset);
John Soni Jose09a10932012-10-20 04:44:23 +05304974 return 0;
4975}
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304976
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304977static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg,
4978 unsigned int num_sg, unsigned int xferlen,
4979 unsigned int writedir)
4980{
4981
4982 struct beiscsi_io_task *io_task = task->dd_data;
4983 struct iscsi_conn *conn = task->conn;
4984 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4985 struct beiscsi_hba *phba = beiscsi_conn->phba;
4986 struct iscsi_wrb *pwrb = NULL;
4987 unsigned int doorbell = 0;
4988
4989 pwrb = io_task->pwrb_handle->pwrb;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304990 io_task->cmd_bhs->iscsi_hdr.exp_statsn = 0;
4991 io_task->bhs_len = sizeof(struct be_cmd_bhs);
4992
4993 if (writedir) {
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304994 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4995 INI_WR_CMD);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304996 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304997 } else {
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304998 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4999 INI_RD_CMD);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305000 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
5001 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305002
John Soni Jose09a10932012-10-20 04:44:23 +05305003 io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb,
5004 type, pwrb);
5005
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305006 AMAP_SET_BITS(struct amap_iscsi_wrb, lun, pwrb,
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05005007 cpu_to_be16(*(unsigned short *)
5008 &io_task->cmd_bhs->iscsi_hdr.lun));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305009 AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, xferlen);
5010 AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
5011 io_task->pwrb_handle->wrb_index);
5012 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
5013 be32_to_cpu(task->cmdsn));
5014 AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
5015 io_task->psgl_handle->sgl_index);
5016
5017 hwi_write_sgl(pwrb, sg, num_sg, io_task);
5018
5019 AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
John Soni Jose340c99e2015-08-20 04:44:30 +05305020 io_task->pwrb_handle->wrb_index);
5021 if (io_task->pwrb_context->plast_wrb)
5022 AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb,
5023 io_task->pwrb_context->plast_wrb,
5024 io_task->pwrb_handle->wrb_index);
5025 io_task->pwrb_context->plast_wrb = pwrb;
5026
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305027 be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
5028
5029 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05305030 doorbell |= (io_task->pwrb_handle->wrb_index &
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305031 DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
5032 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
5033
Jayamohan Kallickal1e4be6f2013-09-28 15:35:50 -07005034 iowrite32(doorbell, phba->db_va +
5035 beiscsi_conn->doorbell_offset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305036 return 0;
5037}
5038
5039static int beiscsi_mtask(struct iscsi_task *task)
5040{
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05305041 struct beiscsi_io_task *io_task = task->dd_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305042 struct iscsi_conn *conn = task->conn;
5043 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
5044 struct beiscsi_hba *phba = beiscsi_conn->phba;
5045 struct iscsi_wrb *pwrb = NULL;
5046 unsigned int doorbell = 0;
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05305047 unsigned int cid;
John Soni Jose09a10932012-10-20 04:44:23 +05305048 unsigned int pwrb_typeoffset = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305049
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305050 cid = beiscsi_conn->beiscsi_conn_cid;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305051 pwrb = io_task->pwrb_handle->pwrb;
Jayamohan Kallickalcaf818f2010-01-23 05:38:18 +05305052 memset(pwrb, 0, sizeof(*pwrb));
John Soni Jose09a10932012-10-20 04:44:23 +05305053
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07005054 if (is_chip_be2_be3r(phba)) {
John Soni Jose09a10932012-10-20 04:44:23 +05305055 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
5056 be32_to_cpu(task->cmdsn));
5057 AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
5058 io_task->pwrb_handle->wrb_index);
5059 AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
5060 io_task->psgl_handle->sgl_index);
5061 AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb,
5062 task->data_count);
5063 AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
John Soni Jose340c99e2015-08-20 04:44:30 +05305064 io_task->pwrb_handle->wrb_index);
5065 if (io_task->pwrb_context->plast_wrb)
5066 AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb,
5067 io_task->pwrb_context->plast_wrb,
5068 io_task->pwrb_handle->wrb_index);
5069 io_task->pwrb_context->plast_wrb = pwrb;
5070
John Soni Jose09a10932012-10-20 04:44:23 +05305071 pwrb_typeoffset = BE_WRB_TYPE_OFFSET;
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07005072 } else {
5073 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb,
5074 be32_to_cpu(task->cmdsn));
5075 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb,
5076 io_task->pwrb_handle->wrb_index);
5077 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb,
5078 io_task->psgl_handle->sgl_index);
5079 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb,
5080 task->data_count);
5081 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb,
John Soni Jose340c99e2015-08-20 04:44:30 +05305082 io_task->pwrb_handle->wrb_index);
5083 if (io_task->pwrb_context->plast_wrb)
5084 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb,
5085 io_task->pwrb_context->plast_wrb,
5086 io_task->pwrb_handle->wrb_index);
5087 io_task->pwrb_context->plast_wrb = pwrb;
5088
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07005089 pwrb_typeoffset = SKH_WRB_TYPE_OFFSET;
John Soni Jose09a10932012-10-20 04:44:23 +05305090 }
5091
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05305092
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305093 switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
5094 case ISCSI_OP_LOGIN:
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305095 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, 1);
John Soni Jose09a10932012-10-20 04:44:23 +05305096 ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305097 hwi_write_buffer(pwrb, task);
5098 break;
5099 case ISCSI_OP_NOOP_OUT:
Jayamohan Kallickal1390b012011-03-25 14:24:01 -07005100 if (task->hdr->ttt != ISCSI_RESERVED_TAG) {
John Soni Jose09a10932012-10-20 04:44:23 +05305101 ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset);
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07005102 if (is_chip_be2_be3r(phba))
5103 AMAP_SET_BITS(struct amap_iscsi_wrb,
John Soni Jose09a10932012-10-20 04:44:23 +05305104 dmsg, pwrb, 1);
5105 else
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07005106 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
John Soni Jose09a10932012-10-20 04:44:23 +05305107 dmsg, pwrb, 1);
Jayamohan Kallickal1390b012011-03-25 14:24:01 -07005108 } else {
John Soni Jose09a10932012-10-20 04:44:23 +05305109 ADAPTER_SET_WRB_TYPE(pwrb, INI_RD_CMD, pwrb_typeoffset);
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07005110 if (is_chip_be2_be3r(phba))
5111 AMAP_SET_BITS(struct amap_iscsi_wrb,
John Soni Jose09a10932012-10-20 04:44:23 +05305112 dmsg, pwrb, 0);
5113 else
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07005114 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
John Soni Jose09a10932012-10-20 04:44:23 +05305115 dmsg, pwrb, 0);
Jayamohan Kallickal1390b012011-03-25 14:24:01 -07005116 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305117 hwi_write_buffer(pwrb, task);
5118 break;
5119 case ISCSI_OP_TEXT:
John Soni Jose09a10932012-10-20 04:44:23 +05305120 ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305121 hwi_write_buffer(pwrb, task);
5122 break;
5123 case ISCSI_OP_SCSI_TMFUNC:
John Soni Jose09a10932012-10-20 04:44:23 +05305124 ADAPTER_SET_WRB_TYPE(pwrb, INI_TMF_CMD, pwrb_typeoffset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305125 hwi_write_buffer(pwrb, task);
5126 break;
5127 case ISCSI_OP_LOGOUT:
John Soni Jose09a10932012-10-20 04:44:23 +05305128 ADAPTER_SET_WRB_TYPE(pwrb, HWH_TYPE_LOGOUT, pwrb_typeoffset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305129 hwi_write_buffer(pwrb, task);
5130 break;
5131
5132 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +05305133 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
5134 "BM_%d : opcode =%d Not supported\n",
5135 task->hdr->opcode & ISCSI_OPCODE_MASK);
5136
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305137 return -EINVAL;
5138 }
5139
John Soni Jose09a10932012-10-20 04:44:23 +05305140 /* Set the task type */
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07005141 io_task->wrb_type = (is_chip_be2_be3r(phba)) ?
5142 AMAP_GET_BITS(struct amap_iscsi_wrb, type, pwrb) :
5143 AMAP_GET_BITS(struct amap_iscsi_wrb_v2, type, pwrb);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305144
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305145 doorbell |= cid & DB_WRB_POST_CID_MASK;
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05305146 doorbell |= (io_task->pwrb_handle->wrb_index &
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305147 DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
5148 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
Jayamohan Kallickal1e4be6f2013-09-28 15:35:50 -07005149 iowrite32(doorbell, phba->db_va +
5150 beiscsi_conn->doorbell_offset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305151 return 0;
5152}
5153
5154static int beiscsi_task_xmit(struct iscsi_task *task)
5155{
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305156 struct beiscsi_io_task *io_task = task->dd_data;
5157 struct scsi_cmnd *sc = task->sc;
John Soni Jose09a10932012-10-20 04:44:23 +05305158 struct beiscsi_hba *phba = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305159 struct scatterlist *sg;
5160 int num_sg;
5161 unsigned int writedir = 0, xferlen = 0;
5162
John Soni Jose09a10932012-10-20 04:44:23 +05305163 phba = ((struct beiscsi_conn *)task->conn->dd_data)->phba;
5164
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305165 if (!sc)
5166 return beiscsi_mtask(task);
5167
5168 io_task->scsi_cmnd = sc;
5169 num_sg = scsi_dma_map(sc);
5170 if (num_sg < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305171 struct iscsi_conn *conn = task->conn;
5172 struct beiscsi_hba *phba = NULL;
5173
5174 phba = ((struct beiscsi_conn *)conn->dd_data)->phba;
Jayamohan Kallickalafb96052013-09-28 15:35:55 -07005175 beiscsi_log(phba, KERN_ERR,
5176 BEISCSI_LOG_IO | BEISCSI_LOG_ISCSI,
5177 "BM_%d : scsi_dma_map Failed "
5178 "Driver_ITT : 0x%x ITT : 0x%x Xferlen : 0x%x\n",
5179 be32_to_cpu(io_task->cmd_bhs->iscsi_hdr.itt),
5180 io_task->libiscsi_itt, scsi_bufflen(sc));
John Soni Jose99bc5d52012-08-20 23:00:18 +05305181
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305182 return num_sg;
5183 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305184 xferlen = scsi_bufflen(sc);
5185 sg = scsi_sglist(sc);
John Soni Jose99bc5d52012-08-20 23:00:18 +05305186 if (sc->sc_data_direction == DMA_TO_DEVICE)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305187 writedir = 1;
John Soni Jose99bc5d52012-08-20 23:00:18 +05305188 else
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305189 writedir = 0;
John Soni Jose99bc5d52012-08-20 23:00:18 +05305190
John Soni Jose09a10932012-10-20 04:44:23 +05305191 return phba->iotask_fn(task, sg, num_sg, xferlen, writedir);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305192}
5193
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05005194/**
5195 * beiscsi_bsg_request - handle bsg request from ISCSI transport
5196 * @job: job to handle
5197 */
5198static int beiscsi_bsg_request(struct bsg_job *job)
5199{
5200 struct Scsi_Host *shost;
5201 struct beiscsi_hba *phba;
5202 struct iscsi_bsg_request *bsg_req = job->request;
5203 int rc = -EINVAL;
5204 unsigned int tag;
5205 struct be_dma_mem nonemb_cmd;
5206 struct be_cmd_resp_hdr *resp;
5207 struct iscsi_bsg_reply *bsg_reply = job->reply;
5208 unsigned short status, extd_status;
5209
5210 shost = iscsi_job_to_shost(job);
5211 phba = iscsi_host_priv(shost);
5212
5213 switch (bsg_req->msgcode) {
5214 case ISCSI_BSG_HST_VENDOR:
5215 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
5216 job->request_payload.payload_len,
5217 &nonemb_cmd.dma);
5218 if (nonemb_cmd.va == NULL) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305219 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
5220 "BM_%d : Failed to allocate memory for "
5221 "beiscsi_bsg_request\n");
John Soni Jose8359c792012-10-20 04:43:03 +05305222 return -ENOMEM;
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05005223 }
5224 tag = mgmt_vendor_specific_fw_cmd(&phba->ctrl, phba, job,
5225 &nonemb_cmd);
5226 if (!tag) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305227 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
John Soni Jose8359c792012-10-20 04:43:03 +05305228 "BM_%d : MBX Tag Allocation Failed\n");
John Soni Jose99bc5d52012-08-20 23:00:18 +05305229
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05005230 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
5231 nonemb_cmd.va, nonemb_cmd.dma);
5232 return -EAGAIN;
John Soni Josee175def2012-10-20 04:45:40 +05305233 }
5234
5235 rc = wait_event_interruptible_timeout(
5236 phba->ctrl.mcc_wait[tag],
5237 phba->ctrl.mcc_numtag[tag],
5238 msecs_to_jiffies(
5239 BEISCSI_HOST_MBX_TIMEOUT));
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05005240 extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
5241 status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
5242 free_mcc_tag(&phba->ctrl, tag);
5243 resp = (struct be_cmd_resp_hdr *)nonemb_cmd.va;
5244 sg_copy_from_buffer(job->reply_payload.sg_list,
5245 job->reply_payload.sg_cnt,
5246 nonemb_cmd.va, (resp->response_length
5247 + sizeof(*resp)));
5248 bsg_reply->reply_payload_rcv_len = resp->response_length;
5249 bsg_reply->result = status;
5250 bsg_job_done(job, bsg_reply->result,
5251 bsg_reply->reply_payload_rcv_len);
5252 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
5253 nonemb_cmd.va, nonemb_cmd.dma);
5254 if (status || extd_status) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305255 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
John Soni Jose8359c792012-10-20 04:43:03 +05305256 "BM_%d : MBX Cmd Failed"
John Soni Jose99bc5d52012-08-20 23:00:18 +05305257 " status = %d extd_status = %d\n",
5258 status, extd_status);
5259
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05005260 return -EIO;
John Soni Jose8359c792012-10-20 04:43:03 +05305261 } else {
5262 rc = 0;
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05005263 }
5264 break;
5265
5266 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +05305267 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
5268 "BM_%d : Unsupported bsg command: 0x%x\n",
5269 bsg_req->msgcode);
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05005270 break;
5271 }
5272
5273 return rc;
5274}
5275
John Soni Jose99bc5d52012-08-20 23:00:18 +05305276void beiscsi_hba_attrs_init(struct beiscsi_hba *phba)
5277{
5278 /* Set the logging parameter */
5279 beiscsi_log_enable_init(phba, beiscsi_log_enable);
5280}
5281
John Soni Jose4d4d1ef2012-10-20 04:42:37 +05305282/*
5283 * beiscsi_quiesce()- Cleanup Driver resources
5284 * @phba: Instance Priv structure
Jayamohan Kallickal3567f362013-09-28 15:35:58 -07005285 * @unload_state:i Clean or EEH unload state
John Soni Jose4d4d1ef2012-10-20 04:42:37 +05305286 *
5287 * Free the OS and HW resources held by the driver
5288 **/
Jayamohan Kallickal3567f362013-09-28 15:35:58 -07005289static void beiscsi_quiesce(struct beiscsi_hba *phba,
5290 uint32_t unload_state)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305291{
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305292 struct hwi_controller *phwi_ctrlr;
5293 struct hwi_context_memory *phwi_context;
5294 struct be_eq_obj *pbe_eq;
5295 unsigned int i, msix_vec;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305296
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305297 phwi_ctrlr = phba->phwi_ctrlr;
5298 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305299 hwi_disable_intr(phba);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305300 if (phba->msix_enabled) {
5301 for (i = 0; i <= phba->num_cpus; i++) {
5302 msix_vec = phba->msix_entries[i].vector;
Jayamohan Kallickal3567f362013-09-28 15:35:58 -07005303 synchronize_irq(msix_vec);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305304 free_irq(msix_vec, &phwi_context->be_eq[i]);
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -07005305 kfree(phba->msi_name[i]);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305306 }
5307 } else
Jayamohan Kallickal3567f362013-09-28 15:35:58 -07005308 if (phba->pcidev->irq) {
5309 synchronize_irq(phba->pcidev->irq);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305310 free_irq(phba->pcidev->irq, phba);
Jayamohan Kallickal3567f362013-09-28 15:35:58 -07005311 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305312 pci_disable_msix(phba->pcidev);
John Soni Jose53281ed2014-09-26 15:13:55 -04005313 cancel_delayed_work_sync(&phba->beiscsi_hw_check_task);
Jayamohan Kallickal3567f362013-09-28 15:35:58 -07005314
Jens Axboe89f8b332014-03-13 09:38:42 -06005315 for (i = 0; i < phba->num_cpus; i++) {
5316 pbe_eq = &phwi_context->be_eq[i];
Christoph Hellwig511cbce2015-11-10 14:56:14 +01005317 irq_poll_disable(&pbe_eq->iopoll);
Jens Axboe89f8b332014-03-13 09:38:42 -06005318 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305319
Jayamohan Kallickal3567f362013-09-28 15:35:58 -07005320 if (unload_state == BEISCSI_CLEAN_UNLOAD) {
5321 destroy_workqueue(phba->wq);
5322 beiscsi_clean_port(phba);
5323 beiscsi_free_mem(phba);
Jayamohan Kallickale9b91192010-07-22 04:24:53 +05305324
Jayamohan Kallickal3567f362013-09-28 15:35:58 -07005325 beiscsi_unmap_pci_function(phba);
5326 pci_free_consistent(phba->pcidev,
5327 phba->ctrl.mbox_mem_alloced.size,
5328 phba->ctrl.mbox_mem_alloced.va,
5329 phba->ctrl.mbox_mem_alloced.dma);
5330 } else {
5331 hwi_purge_eq(phba);
5332 hwi_cleanup(phba);
5333 }
John Soni Jose7a158002012-10-20 04:45:51 +05305334
Jayamohan Kallickal25602c92011-08-22 10:08:28 -07005335}
5336
5337static void beiscsi_remove(struct pci_dev *pcidev)
5338{
Jayamohan Kallickal25602c92011-08-22 10:08:28 -07005339 struct beiscsi_hba *phba = NULL;
5340
5341 phba = pci_get_drvdata(pcidev);
5342 if (!phba) {
5343 dev_err(&pcidev->dev, "beiscsi_remove called with no phba\n");
5344 return;
5345 }
5346
Mike Christie0e438952012-04-03 23:41:51 -05005347 beiscsi_destroy_def_ifaces(phba);
Mike Christie9d045162011-06-24 15:11:52 -05005348 iscsi_boot_destroy_kset(phba->boot_kset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305349 iscsi_host_remove(phba->shost);
Jitendra Bhivarecdaa4de2016-01-20 14:10:51 +05305350 beiscsi_quiesce(phba, BEISCSI_CLEAN_UNLOAD);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305351 pci_dev_put(phba->pcidev);
5352 iscsi_host_free(phba->shost);
Jayamohan Kallickal3567f362013-09-28 15:35:58 -07005353 pci_disable_pcie_error_reporting(pcidev);
5354 pci_set_drvdata(pcidev, NULL);
John Soni Josee307f3a2015-04-25 08:17:19 +05305355 pci_release_regions(pcidev);
Jayamohan Kallickal8dce69f2011-08-22 10:08:29 -07005356 pci_disable_device(pcidev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305357}
5358
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305359static void beiscsi_msix_enable(struct beiscsi_hba *phba)
5360{
5361 int i, status;
5362
5363 for (i = 0; i <= phba->num_cpus; i++)
5364 phba->msix_entries[i].entry = i;
5365
Alexander Gordeeve149fc12014-08-18 08:01:48 +02005366 status = pci_enable_msix_range(phba->pcidev, phba->msix_entries,
5367 phba->num_cpus + 1, phba->num_cpus + 1);
5368 if (status > 0)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305369 phba->msix_enabled = true;
5370
5371 return;
5372}
5373
Jayamohan Kallickal73af08e2014-05-05 21:41:26 -04005374static void be_eqd_update(struct beiscsi_hba *phba)
5375{
5376 struct be_set_eqd set_eqd[MAX_CPUS];
5377 struct be_aic_obj *aic;
5378 struct be_eq_obj *pbe_eq;
5379 struct hwi_controller *phwi_ctrlr;
5380 struct hwi_context_memory *phwi_context;
5381 int eqd, i, num = 0;
5382 ulong now;
5383 u32 pps, delta;
5384 unsigned int tag;
5385
5386 phwi_ctrlr = phba->phwi_ctrlr;
5387 phwi_context = phwi_ctrlr->phwi_ctxt;
5388
5389 for (i = 0; i <= phba->num_cpus; i++) {
5390 aic = &phba->aic_obj[i];
5391 pbe_eq = &phwi_context->be_eq[i];
5392 now = jiffies;
5393 if (!aic->jiffs || time_before(now, aic->jiffs) ||
5394 pbe_eq->cq_count < aic->eq_prev) {
5395 aic->jiffs = now;
5396 aic->eq_prev = pbe_eq->cq_count;
5397 continue;
5398 }
5399 delta = jiffies_to_msecs(now - aic->jiffs);
5400 pps = (((u32)(pbe_eq->cq_count - aic->eq_prev) * 1000) / delta);
5401 eqd = (pps / 1500) << 2;
5402
5403 if (eqd < 8)
5404 eqd = 0;
5405 eqd = min_t(u32, eqd, phwi_context->max_eqd);
5406 eqd = max_t(u32, eqd, phwi_context->min_eqd);
5407
5408 aic->jiffs = now;
5409 aic->eq_prev = pbe_eq->cq_count;
5410
5411 if (eqd != aic->prev_eqd) {
5412 set_eqd[num].delay_multiplier = (eqd * 65)/100;
5413 set_eqd[num].eq_id = pbe_eq->q.id;
5414 aic->prev_eqd = eqd;
5415 num++;
5416 }
5417 }
5418 if (num) {
5419 tag = be_cmd_modify_eq_delay(phba, set_eqd, num);
5420 if (tag)
5421 beiscsi_mccq_compl(phba, tag, NULL, NULL);
5422 }
5423}
5424
Jayamohan Kallickala3d313e2014-08-08 01:00:00 -04005425static void be_check_boot_session(struct beiscsi_hba *phba)
5426{
5427 if (beiscsi_setup_boot_info(phba))
5428 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5429 "BM_%d : Could not set up "
5430 "iSCSI boot info on async event.\n");
5431}
5432
John Soni Jose7a158002012-10-20 04:45:51 +05305433/*
5434 * beiscsi_hw_health_check()- Check adapter health
5435 * @work: work item to check HW health
5436 *
5437 * Check if adapter in an unrecoverable state or not.
5438 **/
5439static void
5440beiscsi_hw_health_check(struct work_struct *work)
5441{
5442 struct beiscsi_hba *phba =
5443 container_of(work, struct beiscsi_hba,
5444 beiscsi_hw_check_task.work);
5445
Jayamohan Kallickal73af08e2014-05-05 21:41:26 -04005446 be_eqd_update(phba);
5447
Jayamohan Kallickala3d313e2014-08-08 01:00:00 -04005448 if (phba->state & BE_ADAPTER_CHECK_BOOT) {
John Soni Jose3efde862015-04-25 08:16:57 +05305449 if ((phba->get_boot > 0) && (!phba->boot_kset)) {
5450 phba->get_boot--;
5451 if (!(phba->get_boot % BE_GET_BOOT_TO))
5452 be_check_boot_session(phba);
5453 } else {
5454 phba->state &= ~BE_ADAPTER_CHECK_BOOT;
5455 phba->get_boot = 0;
5456 }
Jayamohan Kallickala3d313e2014-08-08 01:00:00 -04005457 }
5458
John Soni Jose7a158002012-10-20 04:45:51 +05305459 beiscsi_ue_detect(phba);
5460
5461 schedule_delayed_work(&phba->beiscsi_hw_check_task,
5462 msecs_to_jiffies(1000));
5463}
5464
Jayamohan Kallickal3567f362013-09-28 15:35:58 -07005465
5466static pci_ers_result_t beiscsi_eeh_err_detected(struct pci_dev *pdev,
5467 pci_channel_state_t state)
5468{
5469 struct beiscsi_hba *phba = NULL;
5470
5471 phba = (struct beiscsi_hba *)pci_get_drvdata(pdev);
5472 phba->state |= BE_ADAPTER_PCI_ERR;
5473
5474 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5475 "BM_%d : EEH error detected\n");
5476
5477 beiscsi_quiesce(phba, BEISCSI_EEH_UNLOAD);
5478
5479 if (state == pci_channel_io_perm_failure) {
5480 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5481 "BM_%d : EEH : State PERM Failure");
5482 return PCI_ERS_RESULT_DISCONNECT;
5483 }
5484
5485 pci_disable_device(pdev);
5486
5487 /* The error could cause the FW to trigger a flash debug dump.
5488 * Resetting the card while flash dump is in progress
5489 * can cause it not to recover; wait for it to finish.
5490 * Wait only for first function as it is needed only once per
5491 * adapter.
5492 **/
5493 if (pdev->devfn == 0)
5494 ssleep(30);
5495
5496 return PCI_ERS_RESULT_NEED_RESET;
5497}
5498
5499static pci_ers_result_t beiscsi_eeh_reset(struct pci_dev *pdev)
5500{
5501 struct beiscsi_hba *phba = NULL;
5502 int status = 0;
5503
5504 phba = (struct beiscsi_hba *)pci_get_drvdata(pdev);
5505
5506 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5507 "BM_%d : EEH Reset\n");
5508
5509 status = pci_enable_device(pdev);
5510 if (status)
5511 return PCI_ERS_RESULT_DISCONNECT;
5512
5513 pci_set_master(pdev);
5514 pci_set_power_state(pdev, PCI_D0);
5515 pci_restore_state(pdev);
5516
5517 /* Wait for the CHIP Reset to complete */
5518 status = be_chk_reset_complete(phba);
5519 if (!status) {
5520 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
5521 "BM_%d : EEH Reset Completed\n");
5522 } else {
5523 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
5524 "BM_%d : EEH Reset Completion Failure\n");
5525 return PCI_ERS_RESULT_DISCONNECT;
5526 }
5527
5528 pci_cleanup_aer_uncorrect_error_status(pdev);
5529 return PCI_ERS_RESULT_RECOVERED;
5530}
5531
5532static void beiscsi_eeh_resume(struct pci_dev *pdev)
5533{
5534 int ret = 0, i;
5535 struct be_eq_obj *pbe_eq;
5536 struct beiscsi_hba *phba = NULL;
5537 struct hwi_controller *phwi_ctrlr;
5538 struct hwi_context_memory *phwi_context;
5539
5540 phba = (struct beiscsi_hba *)pci_get_drvdata(pdev);
5541 pci_save_state(pdev);
5542
5543 if (enable_msix)
5544 find_num_cpus(phba);
5545 else
5546 phba->num_cpus = 1;
5547
5548 if (enable_msix) {
5549 beiscsi_msix_enable(phba);
5550 if (!phba->msix_enabled)
5551 phba->num_cpus = 1;
5552 }
5553
5554 ret = beiscsi_cmd_reset_function(phba);
5555 if (ret) {
5556 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5557 "BM_%d : Reset Failed\n");
5558 goto ret_err;
5559 }
5560
5561 ret = be_chk_reset_complete(phba);
5562 if (ret) {
5563 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5564 "BM_%d : Failed to get out of reset.\n");
5565 goto ret_err;
5566 }
5567
5568 beiscsi_get_params(phba);
5569 phba->shost->max_id = phba->params.cxns_per_ctrl;
5570 phba->shost->can_queue = phba->params.ios_per_ctrl;
5571 ret = hwi_init_controller(phba);
5572
5573 for (i = 0; i < MAX_MCC_CMD; i++) {
5574 init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]);
5575 phba->ctrl.mcc_tag[i] = i + 1;
5576 phba->ctrl.mcc_numtag[i + 1] = 0;
5577 phba->ctrl.mcc_tag_available++;
5578 }
5579
5580 phwi_ctrlr = phba->phwi_ctrlr;
5581 phwi_context = phwi_ctrlr->phwi_ctxt;
5582
Jens Axboe89f8b332014-03-13 09:38:42 -06005583 for (i = 0; i < phba->num_cpus; i++) {
Jayamohan Kallickal3567f362013-09-28 15:35:58 -07005584 pbe_eq = &phwi_context->be_eq[i];
Christoph Hellwig511cbce2015-11-10 14:56:14 +01005585 irq_poll_init(&pbe_eq->iopoll, be_iopoll_budget,
Jens Axboe89f8b332014-03-13 09:38:42 -06005586 be_iopoll);
Jayamohan Kallickal3567f362013-09-28 15:35:58 -07005587 }
5588
Jens Axboe89f8b332014-03-13 09:38:42 -06005589 i = (phba->msix_enabled) ? i : 0;
5590 /* Work item for MCC handling */
5591 pbe_eq = &phwi_context->be_eq[i];
5592 INIT_WORK(&pbe_eq->work_cqs, beiscsi_process_all_cqs);
5593
Jayamohan Kallickal3567f362013-09-28 15:35:58 -07005594 ret = beiscsi_init_irqs(phba);
5595 if (ret < 0) {
5596 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5597 "BM_%d : beiscsi_eeh_resume - "
5598 "Failed to beiscsi_init_irqs\n");
5599 goto ret_err;
5600 }
5601
5602 hwi_enable_intr(phba);
5603 phba->state &= ~BE_ADAPTER_PCI_ERR;
5604
5605 return;
5606ret_err:
5607 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5608 "BM_%d : AER EEH Resume Failed\n");
5609}
5610
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08005611static int beiscsi_dev_probe(struct pci_dev *pcidev,
5612 const struct pci_device_id *id)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305613{
5614 struct beiscsi_hba *phba = NULL;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305615 struct hwi_controller *phwi_ctrlr;
5616 struct hwi_context_memory *phwi_context;
5617 struct be_eq_obj *pbe_eq;
Jayamohan Kallickal3567f362013-09-28 15:35:58 -07005618 int ret = 0, i;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305619
5620 ret = beiscsi_enable_pci(pcidev);
5621 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305622 dev_err(&pcidev->dev,
5623 "beiscsi_dev_probe - Failed to enable pci device\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305624 return ret;
5625 }
5626
5627 phba = beiscsi_hba_alloc(pcidev);
5628 if (!phba) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305629 dev_err(&pcidev->dev,
5630 "beiscsi_dev_probe - Failed in beiscsi_hba_alloc\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305631 goto disable_pci;
5632 }
5633
Jayamohan Kallickal3567f362013-09-28 15:35:58 -07005634 /* Enable EEH reporting */
5635 ret = pci_enable_pcie_error_reporting(pcidev);
5636 if (ret)
5637 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
5638 "BM_%d : PCIe Error Reporting "
5639 "Enabling Failed\n");
5640
5641 pci_save_state(pcidev);
5642
John Soni Jose99bc5d52012-08-20 23:00:18 +05305643 /* Initialize Driver configuration Paramters */
5644 beiscsi_hba_attrs_init(phba);
5645
John Soni Josee175def2012-10-20 04:45:40 +05305646 phba->fw_timeout = false;
Jayamohan Kallickal6c831852013-09-28 15:35:40 -07005647 phba->mac_addr_set = false;
John Soni Josee175def2012-10-20 04:45:40 +05305648
5649
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +05305650 switch (pcidev->device) {
5651 case BE_DEVICE_ID1:
5652 case OC_DEVICE_ID1:
5653 case OC_DEVICE_ID2:
5654 phba->generation = BE_GEN2;
John Soni Jose09a10932012-10-20 04:44:23 +05305655 phba->iotask_fn = beiscsi_iotask;
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +05305656 break;
5657 case BE_DEVICE_ID2:
5658 case OC_DEVICE_ID3:
5659 phba->generation = BE_GEN3;
John Soni Jose09a10932012-10-20 04:44:23 +05305660 phba->iotask_fn = beiscsi_iotask;
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +05305661 break;
John Soni Jose139a1b12012-10-20 04:43:20 +05305662 case OC_SKH_ID1:
5663 phba->generation = BE_GEN4;
John Soni Jose09a10932012-10-20 04:44:23 +05305664 phba->iotask_fn = beiscsi_iotask_v2;
Jayamohan Kallickalbf9131c2013-04-05 20:38:24 -07005665 break;
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +05305666 default:
5667 phba->generation = 0;
5668 }
5669
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305670 ret = be_ctrl_init(phba, pcidev);
5671 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305672 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5673 "BM_%d : beiscsi_dev_probe-"
5674 "Failed in be_ctrl_init\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305675 goto hba_free;
5676 }
5677
Jitendra Bhivarecdaa4de2016-01-20 14:10:51 +05305678 /*
5679 * FUNCTION_RESET should clean up any stale info in FW for this fn
5680 */
John Soni Jose4d4d1ef2012-10-20 04:42:37 +05305681 ret = beiscsi_cmd_reset_function(phba);
5682 if (ret) {
5683 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
Jayamohan Kallickal92665a62013-09-28 15:35:43 -07005684 "BM_%d : Reset Failed\n");
John Soni Jose4d4d1ef2012-10-20 04:42:37 +05305685 goto hba_free;
5686 }
5687 ret = be_chk_reset_complete(phba);
5688 if (ret) {
5689 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
Jayamohan Kallickal92665a62013-09-28 15:35:43 -07005690 "BM_%d : Failed to get out of reset.\n");
John Soni Jose4d4d1ef2012-10-20 04:42:37 +05305691 goto hba_free;
Jayamohan Kallickale9b91192010-07-22 04:24:53 +05305692 }
5693
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305694 spin_lock_init(&phba->io_sgl_lock);
5695 spin_lock_init(&phba->mgmt_sgl_lock);
5696 spin_lock_init(&phba->isr_lock);
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07005697 spin_lock_init(&phba->async_pdu_lock);
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05305698 ret = mgmt_get_fw_config(&phba->ctrl, phba);
5699 if (ret != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305700 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5701 "BM_%d : Error getting fw config\n");
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05305702 goto free_port;
5703 }
Jitendra Bhivare53aefe22016-01-20 14:10:53 +05305704 mgmt_get_port_name(&phba->ctrl, phba);
Jitendra Bhivare4570f162016-01-20 14:10:54 +05305705 beiscsi_get_params(phba);
Jayamohan Kallickal68c26a32013-09-28 15:35:54 -07005706
5707 if (enable_msix)
5708 find_num_cpus(phba);
5709 else
5710 phba->num_cpus = 1;
5711
5712 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
5713 "BM_%d : num_cpus = %d\n",
5714 phba->num_cpus);
5715
5716 if (enable_msix) {
5717 beiscsi_msix_enable(phba);
5718 if (!phba->msix_enabled)
5719 phba->num_cpus = 1;
5720 }
5721
Jayamohan Kallickal843ae752013-09-28 15:35:44 -07005722 phba->shost->max_id = phba->params.cxns_per_ctrl;
Jayamohan Kallickalaa874f02010-01-05 05:12:03 +05305723 phba->shost->can_queue = phba->params.ios_per_ctrl;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305724 ret = beiscsi_init_port(phba);
5725 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305726 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5727 "BM_%d : beiscsi_dev_probe-"
5728 "Failed in beiscsi_init_port\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305729 goto free_port;
5730 }
5731
Jayamohan Kallickal3567f362013-09-28 15:35:58 -07005732 for (i = 0; i < MAX_MCC_CMD; i++) {
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05305733 init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]);
5734 phba->ctrl.mcc_tag[i] = i + 1;
5735 phba->ctrl.mcc_numtag[i + 1] = 0;
5736 phba->ctrl.mcc_tag_available++;
Jayamohan Kallickal1957aa72014-01-29 02:16:39 -05005737 memset(&phba->ctrl.ptag_state[i].tag_mem_state, 0,
Jayamohan Kallickal8fc01ea2014-05-05 21:41:28 -04005738 sizeof(struct be_dma_mem));
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05305739 }
5740
5741 phba->ctrl.mcc_alloc_index = phba->ctrl.mcc_free_index = 0;
5742
John Soni Jose72fb46a2012-10-20 04:42:49 +05305743 snprintf(phba->wq_name, sizeof(phba->wq_name), "beiscsi_%02x_wq",
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305744 phba->shost->host_no);
Kees Cookd8537542013-07-03 15:04:57 -07005745 phba->wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 1, phba->wq_name);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305746 if (!phba->wq) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305747 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5748 "BM_%d : beiscsi_dev_probe-"
5749 "Failed to allocate work queue\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305750 goto free_twq;
5751 }
5752
John Soni Jose7a158002012-10-20 04:45:51 +05305753 INIT_DELAYED_WORK(&phba->beiscsi_hw_check_task,
5754 beiscsi_hw_health_check);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305755
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305756 phwi_ctrlr = phba->phwi_ctrlr;
5757 phwi_context = phwi_ctrlr->phwi_ctxt;
John Soni Jose72fb46a2012-10-20 04:42:49 +05305758
Jens Axboe89f8b332014-03-13 09:38:42 -06005759 for (i = 0; i < phba->num_cpus; i++) {
John Soni Jose72fb46a2012-10-20 04:42:49 +05305760 pbe_eq = &phwi_context->be_eq[i];
Christoph Hellwig511cbce2015-11-10 14:56:14 +01005761 irq_poll_init(&pbe_eq->iopoll, be_iopoll_budget,
Jens Axboe89f8b332014-03-13 09:38:42 -06005762 be_iopoll);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305763 }
John Soni Jose72fb46a2012-10-20 04:42:49 +05305764
Jens Axboe89f8b332014-03-13 09:38:42 -06005765 i = (phba->msix_enabled) ? i : 0;
5766 /* Work item for MCC handling */
5767 pbe_eq = &phwi_context->be_eq[i];
5768 INIT_WORK(&pbe_eq->work_cqs, beiscsi_process_all_cqs);
5769
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305770 ret = beiscsi_init_irqs(phba);
5771 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305772 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5773 "BM_%d : beiscsi_dev_probe-"
5774 "Failed to beiscsi_init_irqs\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305775 goto free_blkenbld;
5776 }
Jayamohan Kallickal238f6b72010-07-22 04:23:22 +05305777 hwi_enable_intr(phba);
Mike Christief457a462011-06-24 15:11:53 -05005778
Jayamohan Kallickal0598b8a2014-05-05 21:41:25 -04005779 if (iscsi_host_add(phba->shost, &phba->pcidev->dev))
5780 goto free_blkenbld;
5781
Mike Christief457a462011-06-24 15:11:53 -05005782 if (beiscsi_setup_boot_info(phba))
5783 /*
5784 * log error but continue, because we may not be using
5785 * iscsi boot.
5786 */
John Soni Jose99bc5d52012-08-20 23:00:18 +05305787 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5788 "BM_%d : Could not set up "
5789 "iSCSI boot info.\n");
Mike Christief457a462011-06-24 15:11:53 -05005790
Mike Christie0e438952012-04-03 23:41:51 -05005791 beiscsi_create_def_ifaces(phba);
John Soni Jose7a158002012-10-20 04:45:51 +05305792 schedule_delayed_work(&phba->beiscsi_hw_check_task,
5793 msecs_to_jiffies(1000));
5794
John Soni Jose99bc5d52012-08-20 23:00:18 +05305795 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
5796 "\n\n\n BM_%d : SUCCESS - DRIVER LOADED\n\n\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305797 return 0;
5798
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305799free_blkenbld:
5800 destroy_workqueue(phba->wq);
Jens Axboe89f8b332014-03-13 09:38:42 -06005801 for (i = 0; i < phba->num_cpus; i++) {
5802 pbe_eq = &phwi_context->be_eq[i];
Christoph Hellwig511cbce2015-11-10 14:56:14 +01005803 irq_poll_disable(&pbe_eq->iopoll);
Jens Axboe89f8b332014-03-13 09:38:42 -06005804 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305805free_twq:
5806 beiscsi_clean_port(phba);
5807 beiscsi_free_mem(phba);
5808free_port:
5809 pci_free_consistent(phba->pcidev,
5810 phba->ctrl.mbox_mem_alloced.size,
5811 phba->ctrl.mbox_mem_alloced.va,
5812 phba->ctrl.mbox_mem_alloced.dma);
5813 beiscsi_unmap_pci_function(phba);
5814hba_free:
Jayamohan Kallickal238f6b72010-07-22 04:23:22 +05305815 if (phba->msix_enabled)
5816 pci_disable_msix(phba->pcidev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305817 pci_dev_put(phba->pcidev);
5818 iscsi_host_free(phba->shost);
John Soni Jose2e7cee02015-02-12 06:45:47 +05305819 pci_set_drvdata(pcidev, NULL);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305820disable_pci:
John Soni Josee307f3a2015-04-25 08:17:19 +05305821 pci_release_regions(pcidev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305822 pci_disable_device(pcidev);
5823 return ret;
5824}
5825
Jayamohan Kallickal3567f362013-09-28 15:35:58 -07005826static struct pci_error_handlers beiscsi_eeh_handlers = {
5827 .error_detected = beiscsi_eeh_err_detected,
5828 .slot_reset = beiscsi_eeh_reset,
5829 .resume = beiscsi_eeh_resume,
5830};
5831
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305832struct iscsi_transport beiscsi_iscsi_transport = {
5833 .owner = THIS_MODULE,
5834 .name = DRV_NAME,
Jayamohan Kallickal9db0fb32010-01-05 05:12:43 +05305835 .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_TEXT_NEGO |
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305836 CAP_MULTI_R2T | CAP_DATADGST | CAP_DATA_PATH_OFFLOAD,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305837 .create_session = beiscsi_session_create,
5838 .destroy_session = beiscsi_session_destroy,
5839 .create_conn = beiscsi_conn_create,
5840 .bind_conn = beiscsi_conn_bind,
5841 .destroy_conn = iscsi_conn_teardown,
Mike Christie3128c6c2011-07-25 13:48:42 -05005842 .attr_is_visible = be2iscsi_attr_is_visible,
Mike Christie0e438952012-04-03 23:41:51 -05005843 .set_iface_param = be2iscsi_iface_set_param,
5844 .get_iface_param = be2iscsi_iface_get_param,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305845 .set_param = beiscsi_set_param,
Mike Christiec7f7fd52011-02-16 15:04:41 -06005846 .get_conn_param = iscsi_conn_get_param,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305847 .get_session_param = iscsi_session_get_param,
5848 .get_host_param = beiscsi_get_host_param,
5849 .start_conn = beiscsi_conn_start,
Mike Christiefa95d202010-06-09 03:30:08 -05005850 .stop_conn = iscsi_conn_stop,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305851 .send_pdu = iscsi_conn_send_pdu,
5852 .xmit_task = beiscsi_task_xmit,
5853 .cleanup_task = beiscsi_cleanup_task,
5854 .alloc_pdu = beiscsi_alloc_pdu,
5855 .parse_pdu_itt = beiscsi_parse_pdu,
5856 .get_stats = beiscsi_conn_get_stats,
Mike Christiec7f7fd52011-02-16 15:04:41 -06005857 .get_ep_param = beiscsi_ep_get_param,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305858 .ep_connect = beiscsi_ep_connect,
5859 .ep_poll = beiscsi_ep_poll,
5860 .ep_disconnect = beiscsi_ep_disconnect,
5861 .session_recovery_timedout = iscsi_session_recovery_timedout,
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05005862 .bsg_request = beiscsi_bsg_request,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305863};
5864
5865static struct pci_driver beiscsi_pci_driver = {
5866 .name = DRV_NAME,
5867 .probe = beiscsi_dev_probe,
5868 .remove = beiscsi_remove,
Jayamohan Kallickal3567f362013-09-28 15:35:58 -07005869 .id_table = beiscsi_pci_id_table,
5870 .err_handler = &beiscsi_eeh_handlers
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305871};
5872
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305873
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305874static int __init beiscsi_module_init(void)
5875{
5876 int ret;
5877
5878 beiscsi_scsi_transport =
5879 iscsi_register_transport(&beiscsi_iscsi_transport);
5880 if (!beiscsi_scsi_transport) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305881 printk(KERN_ERR
5882 "beiscsi_module_init - Unable to register beiscsi transport.\n");
Jayamohan Kallickalf55a24f2010-01-23 05:37:40 +05305883 return -ENOMEM;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305884 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05305885 printk(KERN_INFO "In beiscsi_module_init, tt=%p\n",
5886 &beiscsi_iscsi_transport);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305887
5888 ret = pci_register_driver(&beiscsi_pci_driver);
5889 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305890 printk(KERN_ERR
5891 "beiscsi_module_init - Unable to register beiscsi pci driver.\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305892 goto unregister_iscsi_transport;
5893 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305894 return 0;
5895
5896unregister_iscsi_transport:
5897 iscsi_unregister_transport(&beiscsi_iscsi_transport);
5898 return ret;
5899}
5900
5901static void __exit beiscsi_module_exit(void)
5902{
5903 pci_unregister_driver(&beiscsi_pci_driver);
5904 iscsi_unregister_transport(&beiscsi_iscsi_transport);
5905}
5906
5907module_init(beiscsi_module_init);
5908module_exit(beiscsi_module_exit);