blob: 991858262b72622539280db36fe28bf9b63314e9 [file] [log] [blame]
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301/**
Jayamohan Kallickal533c1652013-04-05 20:38:34 -07002 * Copyright (C) 2005 - 2013 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 *
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070010 * Written by: Jayamohan Kallickal (jayamohan.kallickal@emulex.com)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053011 *
12 * Contact Information:
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070013 * linux-drivers@emulex.com
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053014 *
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070015 * Emulex
16 * 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>
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053032
33#include <scsi/libiscsi.h>
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -050034#include <scsi/scsi_bsg_iscsi.h>
35#include <scsi/scsi_netlink.h>
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053036#include <scsi/scsi_transport_iscsi.h>
37#include <scsi/scsi_transport.h>
38#include <scsi/scsi_cmnd.h>
39#include <scsi/scsi_device.h>
40#include <scsi/scsi_host.h>
41#include <scsi/scsi.h>
42#include "be_main.h"
43#include "be_iscsi.h"
44#include "be_mgmt.h"
John Soni Jose0a513dd2012-08-20 23:00:55 +053045#include "be_cmds.h"
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053046
47static unsigned int be_iopoll_budget = 10;
48static unsigned int be_max_phys_size = 64;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +053049static unsigned int enable_msix = 1;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053050
51MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
52MODULE_DESCRIPTION(DRV_DESC " " BUILD_STR);
Jayamohan Kallickal76d15db2012-04-03 23:41:46 -050053MODULE_VERSION(BUILD_STR);
Jayamohan Kallickal2f635882012-04-03 23:41:45 -050054MODULE_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"
152 "\t\t\t\tConfiguration Path : 0x20\n");
153
John Soni Jose5cac7592012-10-20 04:42:25 +0530154DEVICE_ATTR(beiscsi_drvr_ver, S_IRUGO, beiscsi_drvr_ver_disp, NULL);
John Soni Jose26000db2012-10-20 04:45:06 +0530155DEVICE_ATTR(beiscsi_adapter_family, S_IRUGO, beiscsi_adap_family_disp, NULL);
Jayamohan Kallickal22661e22013-04-05 20:38:28 -0700156DEVICE_ATTR(beiscsi_fw_ver, S_IRUGO, beiscsi_fw_ver_disp, NULL);
Jayamohan Kallickal7ad4dfe2013-04-05 20:38:29 -0700157DEVICE_ATTR(beiscsi_active_cid_count, S_IRUGO, beiscsi_active_cid_disp, NULL);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530158struct device_attribute *beiscsi_attrs[] = {
159 &dev_attr_beiscsi_log_enable,
John Soni Jose5cac7592012-10-20 04:42:25 +0530160 &dev_attr_beiscsi_drvr_ver,
John Soni Jose26000db2012-10-20 04:45:06 +0530161 &dev_attr_beiscsi_adapter_family,
Jayamohan Kallickal22661e22013-04-05 20:38:28 -0700162 &dev_attr_beiscsi_fw_ver,
Jayamohan Kallickal7ad4dfe2013-04-05 20:38:29 -0700163 &dev_attr_beiscsi_active_cid_count,
John Soni Jose99bc5d52012-08-20 23:00:18 +0530164 NULL,
165};
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530166
John Soni Jose6763daa2012-10-20 04:41:45 +0530167static char const *cqe_desc[] = {
168 "RESERVED_DESC",
169 "SOL_CMD_COMPLETE",
170 "SOL_CMD_KILLED_DATA_DIGEST_ERR",
171 "CXN_KILLED_PDU_SIZE_EXCEEDS_DSL",
172 "CXN_KILLED_BURST_LEN_MISMATCH",
173 "CXN_KILLED_AHS_RCVD",
174 "CXN_KILLED_HDR_DIGEST_ERR",
175 "CXN_KILLED_UNKNOWN_HDR",
176 "CXN_KILLED_STALE_ITT_TTT_RCVD",
177 "CXN_KILLED_INVALID_ITT_TTT_RCVD",
178 "CXN_KILLED_RST_RCVD",
179 "CXN_KILLED_TIMED_OUT",
180 "CXN_KILLED_RST_SENT",
181 "CXN_KILLED_FIN_RCVD",
182 "CXN_KILLED_BAD_UNSOL_PDU_RCVD",
183 "CXN_KILLED_BAD_WRB_INDEX_ERROR",
184 "CXN_KILLED_OVER_RUN_RESIDUAL",
185 "CXN_KILLED_UNDER_RUN_RESIDUAL",
186 "CMD_KILLED_INVALID_STATSN_RCVD",
187 "CMD_KILLED_INVALID_R2T_RCVD",
188 "CMD_CXN_KILLED_LUN_INVALID",
189 "CMD_CXN_KILLED_ICD_INVALID",
190 "CMD_CXN_KILLED_ITT_INVALID",
191 "CMD_CXN_KILLED_SEQ_OUTOFORDER",
192 "CMD_CXN_KILLED_INVALID_DATASN_RCVD",
193 "CXN_INVALIDATE_NOTIFY",
194 "CXN_INVALIDATE_INDEX_NOTIFY",
195 "CMD_INVALIDATED_NOTIFY",
196 "UNSOL_HDR_NOTIFY",
197 "UNSOL_DATA_NOTIFY",
198 "UNSOL_DATA_DIGEST_ERROR_NOTIFY",
199 "DRIVERMSG_NOTIFY",
200 "CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN",
201 "SOL_CMD_KILLED_DIF_ERR",
202 "CXN_KILLED_SYN_RCVD",
203 "CXN_KILLED_IMM_DATA_RCVD"
204};
205
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530206static int beiscsi_slave_configure(struct scsi_device *sdev)
207{
208 blk_queue_max_segment_size(sdev->request_queue, 65536);
209 return 0;
210}
211
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530212static int beiscsi_eh_abort(struct scsi_cmnd *sc)
213{
214 struct iscsi_cls_session *cls_session;
215 struct iscsi_task *aborted_task = (struct iscsi_task *)sc->SCp.ptr;
216 struct beiscsi_io_task *aborted_io_task;
217 struct iscsi_conn *conn;
218 struct beiscsi_conn *beiscsi_conn;
219 struct beiscsi_hba *phba;
220 struct iscsi_session *session;
221 struct invalidate_command_table *inv_tbl;
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530222 struct be_dma_mem nonemb_cmd;
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530223 unsigned int cid, tag, num_invalidate;
224
225 cls_session = starget_to_session(scsi_target(sc->device));
226 session = cls_session->dd_data;
227
228 spin_lock_bh(&session->lock);
229 if (!aborted_task || !aborted_task->sc) {
230 /* we raced */
231 spin_unlock_bh(&session->lock);
232 return SUCCESS;
233 }
234
235 aborted_io_task = aborted_task->dd_data;
236 if (!aborted_io_task->scsi_cmnd) {
237 /* raced or invalid command */
238 spin_unlock_bh(&session->lock);
239 return SUCCESS;
240 }
241 spin_unlock_bh(&session->lock);
242 conn = aborted_task->conn;
243 beiscsi_conn = conn->dd_data;
244 phba = beiscsi_conn->phba;
245
246 /* invalidate iocb */
247 cid = beiscsi_conn->beiscsi_conn_cid;
248 inv_tbl = phba->inv_tbl;
249 memset(inv_tbl, 0x0, sizeof(*inv_tbl));
250 inv_tbl->cid = cid;
251 inv_tbl->icd = aborted_io_task->psgl_handle->sgl_index;
252 num_invalidate = 1;
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530253 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
254 sizeof(struct invalidate_commands_params_in),
255 &nonemb_cmd.dma);
256 if (nonemb_cmd.va == NULL) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530257 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
258 "BM_%d : Failed to allocate memory for"
259 "mgmt_invalidate_icds\n");
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530260 return FAILED;
261 }
262 nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
263
264 tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
265 cid, &nonemb_cmd);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530266 if (!tag) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530267 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH,
268 "BM_%d : mgmt_invalidate_icds could not be"
269 "submitted\n");
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530270 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
271 nonemb_cmd.va, nonemb_cmd.dma);
272
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530273 return FAILED;
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530274 }
John Soni Josee175def2012-10-20 04:45:40 +0530275
276 beiscsi_mccq_compl(phba, tag, NULL, nonemb_cmd.va);
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530277 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
278 nonemb_cmd.va, nonemb_cmd.dma);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530279 return iscsi_eh_abort(sc);
280}
281
282static int beiscsi_eh_device_reset(struct scsi_cmnd *sc)
283{
284 struct iscsi_task *abrt_task;
285 struct beiscsi_io_task *abrt_io_task;
286 struct iscsi_conn *conn;
287 struct beiscsi_conn *beiscsi_conn;
288 struct beiscsi_hba *phba;
289 struct iscsi_session *session;
290 struct iscsi_cls_session *cls_session;
291 struct invalidate_command_table *inv_tbl;
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530292 struct be_dma_mem nonemb_cmd;
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530293 unsigned int cid, tag, i, num_invalidate;
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530294
295 /* invalidate iocbs */
296 cls_session = starget_to_session(scsi_target(sc->device));
297 session = cls_session->dd_data;
298 spin_lock_bh(&session->lock);
Jayamohan Kallickaldb7f7702012-04-03 23:41:43 -0500299 if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN) {
300 spin_unlock_bh(&session->lock);
301 return FAILED;
302 }
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530303 conn = session->leadconn;
304 beiscsi_conn = conn->dd_data;
305 phba = beiscsi_conn->phba;
306 cid = beiscsi_conn->beiscsi_conn_cid;
307 inv_tbl = phba->inv_tbl;
308 memset(inv_tbl, 0x0, sizeof(*inv_tbl) * BE2_CMDS_PER_CXN);
309 num_invalidate = 0;
310 for (i = 0; i < conn->session->cmds_max; i++) {
311 abrt_task = conn->session->cmds[i];
312 abrt_io_task = abrt_task->dd_data;
313 if (!abrt_task->sc || abrt_task->state == ISCSI_TASK_FREE)
314 continue;
315
316 if (abrt_task->sc->device->lun != abrt_task->sc->device->lun)
317 continue;
318
319 inv_tbl->cid = cid;
320 inv_tbl->icd = abrt_io_task->psgl_handle->sgl_index;
321 num_invalidate++;
322 inv_tbl++;
323 }
324 spin_unlock_bh(&session->lock);
325 inv_tbl = phba->inv_tbl;
326
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530327 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
328 sizeof(struct invalidate_commands_params_in),
329 &nonemb_cmd.dma);
330 if (nonemb_cmd.va == NULL) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530331 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
332 "BM_%d : Failed to allocate memory for"
333 "mgmt_invalidate_icds\n");
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530334 return FAILED;
335 }
336 nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
337 memset(nonemb_cmd.va, 0, nonemb_cmd.size);
338 tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
339 cid, &nonemb_cmd);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530340 if (!tag) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530341 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH,
342 "BM_%d : mgmt_invalidate_icds could not be"
343 " submitted\n");
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530344 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
345 nonemb_cmd.va, nonemb_cmd.dma);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530346 return FAILED;
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530347 }
John Soni Josee175def2012-10-20 04:45:40 +0530348
349 beiscsi_mccq_compl(phba, tag, NULL, nonemb_cmd.va);
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530350 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
351 nonemb_cmd.va, nonemb_cmd.dma);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530352 return iscsi_eh_device_reset(sc);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530353}
354
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530355static ssize_t beiscsi_show_boot_tgt_info(void *data, int type, char *buf)
356{
357 struct beiscsi_hba *phba = data;
Mike Christief457a462011-06-24 15:11:53 -0500358 struct mgmt_session_info *boot_sess = &phba->boot_sess;
359 struct mgmt_conn_info *boot_conn = &boot_sess->conn_list[0];
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530360 char *str = buf;
361 int rc;
362
363 switch (type) {
364 case ISCSI_BOOT_TGT_NAME:
365 rc = sprintf(buf, "%.*s\n",
Mike Christief457a462011-06-24 15:11:53 -0500366 (int)strlen(boot_sess->target_name),
367 (char *)&boot_sess->target_name);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530368 break;
369 case ISCSI_BOOT_TGT_IP_ADDR:
Mike Christief457a462011-06-24 15:11:53 -0500370 if (boot_conn->dest_ipaddr.ip_type == 0x1)
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530371 rc = sprintf(buf, "%pI4\n",
Mike Christie0e438952012-04-03 23:41:51 -0500372 (char *)&boot_conn->dest_ipaddr.addr);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530373 else
374 rc = sprintf(str, "%pI6\n",
Mike Christie0e438952012-04-03 23:41:51 -0500375 (char *)&boot_conn->dest_ipaddr.addr);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530376 break;
377 case ISCSI_BOOT_TGT_PORT:
Mike Christief457a462011-06-24 15:11:53 -0500378 rc = sprintf(str, "%d\n", boot_conn->dest_port);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530379 break;
380
381 case ISCSI_BOOT_TGT_CHAP_NAME:
382 rc = sprintf(str, "%.*s\n",
Mike Christief457a462011-06-24 15:11:53 -0500383 boot_conn->negotiated_login_options.auth_data.chap.
384 target_chap_name_length,
385 (char *)&boot_conn->negotiated_login_options.
386 auth_data.chap.target_chap_name);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530387 break;
388 case ISCSI_BOOT_TGT_CHAP_SECRET:
389 rc = sprintf(str, "%.*s\n",
Mike Christief457a462011-06-24 15:11:53 -0500390 boot_conn->negotiated_login_options.auth_data.chap.
391 target_secret_length,
392 (char *)&boot_conn->negotiated_login_options.
393 auth_data.chap.target_secret);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530394 break;
395 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
396 rc = sprintf(str, "%.*s\n",
Mike Christief457a462011-06-24 15:11:53 -0500397 boot_conn->negotiated_login_options.auth_data.chap.
398 intr_chap_name_length,
399 (char *)&boot_conn->negotiated_login_options.
400 auth_data.chap.intr_chap_name);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530401 break;
402 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
Mike Christief457a462011-06-24 15:11:53 -0500403 rc = sprintf(str, "%.*s\n",
404 boot_conn->negotiated_login_options.auth_data.chap.
405 intr_secret_length,
406 (char *)&boot_conn->negotiated_login_options.
407 auth_data.chap.intr_secret);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530408 break;
409 case ISCSI_BOOT_TGT_FLAGS:
Mike Christief457a462011-06-24 15:11:53 -0500410 rc = sprintf(str, "2\n");
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530411 break;
412 case ISCSI_BOOT_TGT_NIC_ASSOC:
Mike Christief457a462011-06-24 15:11:53 -0500413 rc = sprintf(str, "0\n");
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530414 break;
415 default:
416 rc = -ENOSYS;
417 break;
418 }
419 return rc;
420}
421
422static ssize_t beiscsi_show_boot_ini_info(void *data, int type, char *buf)
423{
424 struct beiscsi_hba *phba = data;
425 char *str = buf;
426 int rc;
427
428 switch (type) {
429 case ISCSI_BOOT_INI_INITIATOR_NAME:
430 rc = sprintf(str, "%s\n", phba->boot_sess.initiator_iscsiname);
431 break;
432 default:
433 rc = -ENOSYS;
434 break;
435 }
436 return rc;
437}
438
439static ssize_t beiscsi_show_boot_eth_info(void *data, int type, char *buf)
440{
441 struct beiscsi_hba *phba = data;
442 char *str = buf;
443 int rc;
444
445 switch (type) {
446 case ISCSI_BOOT_ETH_FLAGS:
Mike Christief457a462011-06-24 15:11:53 -0500447 rc = sprintf(str, "2\n");
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530448 break;
449 case ISCSI_BOOT_ETH_INDEX:
Mike Christief457a462011-06-24 15:11:53 -0500450 rc = sprintf(str, "0\n");
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530451 break;
452 case ISCSI_BOOT_ETH_MAC:
Mike Christie0e438952012-04-03 23:41:51 -0500453 rc = beiscsi_get_macaddr(str, phba);
454 break;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530455 default:
456 rc = -ENOSYS;
457 break;
458 }
459 return rc;
460}
461
462
Al Viro587a1f12011-07-23 23:11:19 -0400463static umode_t beiscsi_tgt_get_attr_visibility(void *data, int type)
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530464{
Al Viro587a1f12011-07-23 23:11:19 -0400465 umode_t rc;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530466
467 switch (type) {
468 case ISCSI_BOOT_TGT_NAME:
469 case ISCSI_BOOT_TGT_IP_ADDR:
470 case ISCSI_BOOT_TGT_PORT:
471 case ISCSI_BOOT_TGT_CHAP_NAME:
472 case ISCSI_BOOT_TGT_CHAP_SECRET:
473 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
474 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
475 case ISCSI_BOOT_TGT_NIC_ASSOC:
476 case ISCSI_BOOT_TGT_FLAGS:
477 rc = S_IRUGO;
478 break;
479 default:
480 rc = 0;
481 break;
482 }
483 return rc;
484}
485
Al Viro587a1f12011-07-23 23:11:19 -0400486static umode_t beiscsi_ini_get_attr_visibility(void *data, int type)
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530487{
Al Viro587a1f12011-07-23 23:11:19 -0400488 umode_t rc;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530489
490 switch (type) {
491 case ISCSI_BOOT_INI_INITIATOR_NAME:
492 rc = S_IRUGO;
493 break;
494 default:
495 rc = 0;
496 break;
497 }
498 return rc;
499}
500
501
Al Viro587a1f12011-07-23 23:11:19 -0400502static umode_t beiscsi_eth_get_attr_visibility(void *data, int type)
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530503{
Al Viro587a1f12011-07-23 23:11:19 -0400504 umode_t rc;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530505
506 switch (type) {
507 case ISCSI_BOOT_ETH_FLAGS:
508 case ISCSI_BOOT_ETH_MAC:
509 case ISCSI_BOOT_ETH_INDEX:
510 rc = S_IRUGO;
511 break;
512 default:
513 rc = 0;
514 break;
515 }
516 return rc;
517}
518
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530519/*------------------- PCI Driver operations and data ----------------- */
520static DEFINE_PCI_DEVICE_TABLE(beiscsi_pci_id_table) = {
521 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) },
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +0530522 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) },
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530523 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) },
524 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) },
525 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID3) },
John Soni Jose139a1b12012-10-20 04:43:20 +0530526 { PCI_DEVICE(ELX_VENDOR_ID, OC_SKH_ID1) },
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530527 { 0 }
528};
529MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
530
John Soni Jose99bc5d52012-08-20 23:00:18 +0530531
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530532static struct scsi_host_template beiscsi_sht = {
533 .module = THIS_MODULE,
Jayamohan Kallickal2f635882012-04-03 23:41:45 -0500534 .name = "Emulex 10Gbe open-iscsi Initiator Driver",
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530535 .proc_name = DRV_NAME,
536 .queuecommand = iscsi_queuecommand,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530537 .change_queue_depth = iscsi_change_queue_depth,
538 .slave_configure = beiscsi_slave_configure,
539 .target_alloc = iscsi_target_alloc,
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530540 .eh_abort_handler = beiscsi_eh_abort,
541 .eh_device_reset_handler = beiscsi_eh_device_reset,
Jayamohan Kallickal309ce1562010-02-20 08:02:10 +0530542 .eh_target_reset_handler = iscsi_eh_session_reset,
John Soni Jose99bc5d52012-08-20 23:00:18 +0530543 .shost_attrs = beiscsi_attrs,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530544 .sg_tablesize = BEISCSI_SGLIST_ELEMENTS,
545 .can_queue = BE2_IO_DEPTH,
546 .this_id = -1,
547 .max_sectors = BEISCSI_MAX_SECTORS,
548 .cmd_per_lun = BEISCSI_CMD_PER_LUN,
549 .use_clustering = ENABLE_CLUSTERING,
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -0500550 .vendor_id = SCSI_NL_VID_TYPE_PCI | BE_VENDOR_ID,
551
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530552};
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530553
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530554static struct scsi_transport_template *beiscsi_scsi_transport;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530555
556static struct beiscsi_hba *beiscsi_hba_alloc(struct pci_dev *pcidev)
557{
558 struct beiscsi_hba *phba;
559 struct Scsi_Host *shost;
560
561 shost = iscsi_host_alloc(&beiscsi_sht, sizeof(*phba), 0);
562 if (!shost) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530563 dev_err(&pcidev->dev,
564 "beiscsi_hba_alloc - iscsi_host_alloc failed\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530565 return NULL;
566 }
567 shost->dma_boundary = pcidev->dma_mask;
568 shost->max_id = BE2_MAX_SESSIONS;
569 shost->max_channel = 0;
570 shost->max_cmd_len = BEISCSI_MAX_CMD_LEN;
571 shost->max_lun = BEISCSI_NUM_MAX_LUN;
572 shost->transportt = beiscsi_scsi_transport;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530573 phba = iscsi_host_priv(shost);
574 memset(phba, 0, sizeof(*phba));
575 phba->shost = shost;
576 phba->pcidev = pci_dev_get(pcidev);
Jayamohan Kallickal2807afb2010-01-05 05:07:49 +0530577 pci_set_drvdata(pcidev, phba);
Mike Christie0e438952012-04-03 23:41:51 -0500578 phba->interface_handle = 0xFFFFFFFF;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530579
580 if (iscsi_host_add(shost, &phba->pcidev->dev))
581 goto free_devices;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530582
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530583 return phba;
584
585free_devices:
586 pci_dev_put(phba->pcidev);
587 iscsi_host_free(phba->shost);
588 return NULL;
589}
590
591static void beiscsi_unmap_pci_function(struct beiscsi_hba *phba)
592{
593 if (phba->csr_va) {
594 iounmap(phba->csr_va);
595 phba->csr_va = NULL;
596 }
597 if (phba->db_va) {
598 iounmap(phba->db_va);
599 phba->db_va = NULL;
600 }
601 if (phba->pci_va) {
602 iounmap(phba->pci_va);
603 phba->pci_va = NULL;
604 }
605}
606
607static int beiscsi_map_pci_bars(struct beiscsi_hba *phba,
608 struct pci_dev *pcidev)
609{
610 u8 __iomem *addr;
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +0530611 int pcicfg_reg;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530612
613 addr = ioremap_nocache(pci_resource_start(pcidev, 2),
614 pci_resource_len(pcidev, 2));
615 if (addr == NULL)
616 return -ENOMEM;
617 phba->ctrl.csr = addr;
618 phba->csr_va = addr;
619 phba->csr_pa.u.a64.address = pci_resource_start(pcidev, 2);
620
621 addr = ioremap_nocache(pci_resource_start(pcidev, 4), 128 * 1024);
622 if (addr == NULL)
623 goto pci_map_err;
624 phba->ctrl.db = addr;
625 phba->db_va = addr;
626 phba->db_pa.u.a64.address = pci_resource_start(pcidev, 4);
627
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +0530628 if (phba->generation == BE_GEN2)
629 pcicfg_reg = 1;
630 else
631 pcicfg_reg = 0;
632
633 addr = ioremap_nocache(pci_resource_start(pcidev, pcicfg_reg),
634 pci_resource_len(pcidev, pcicfg_reg));
635
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530636 if (addr == NULL)
637 goto pci_map_err;
638 phba->ctrl.pcicfg = addr;
639 phba->pci_va = addr;
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +0530640 phba->pci_pa.u.a64.address = pci_resource_start(pcidev, pcicfg_reg);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530641 return 0;
642
643pci_map_err:
644 beiscsi_unmap_pci_function(phba);
645 return -ENOMEM;
646}
647
648static int beiscsi_enable_pci(struct pci_dev *pcidev)
649{
650 int ret;
651
652 ret = pci_enable_device(pcidev);
653 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530654 dev_err(&pcidev->dev,
655 "beiscsi_enable_pci - enable device failed\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530656 return ret;
657 }
658
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530659 pci_set_master(pcidev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530660 if (pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64))) {
661 ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(32));
662 if (ret) {
663 dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n");
664 pci_disable_device(pcidev);
665 return ret;
666 }
667 }
668 return 0;
669}
670
671static int be_ctrl_init(struct beiscsi_hba *phba, struct pci_dev *pdev)
672{
673 struct be_ctrl_info *ctrl = &phba->ctrl;
674 struct be_dma_mem *mbox_mem_alloc = &ctrl->mbox_mem_alloced;
675 struct be_dma_mem *mbox_mem_align = &ctrl->mbox_mem;
676 int status = 0;
677
678 ctrl->pdev = pdev;
679 status = beiscsi_map_pci_bars(phba, pdev);
680 if (status)
681 return status;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530682 mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16;
683 mbox_mem_alloc->va = pci_alloc_consistent(pdev,
684 mbox_mem_alloc->size,
685 &mbox_mem_alloc->dma);
686 if (!mbox_mem_alloc->va) {
687 beiscsi_unmap_pci_function(phba);
Jayamohan Kallickala49e06d2012-04-03 23:41:44 -0500688 return -ENOMEM;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530689 }
690
691 mbox_mem_align->size = sizeof(struct be_mcc_mailbox);
692 mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16);
693 mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16);
694 memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox));
695 spin_lock_init(&ctrl->mbox_lock);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530696 spin_lock_init(&phba->ctrl.mcc_lock);
697 spin_lock_init(&phba->ctrl.mcc_cq_lock);
698
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530699 return status;
700}
701
702static void beiscsi_get_params(struct beiscsi_hba *phba)
703{
Jayamohan Kallickal7da50872010-01-05 05:04:12 +0530704 phba->params.ios_per_ctrl = (phba->fw_config.iscsi_icd_count
705 - (phba->fw_config.iscsi_cid_count
706 + BE2_TMFS
707 + BE2_NOPOUT_REQ));
708 phba->params.cxns_per_ctrl = phba->fw_config.iscsi_cid_count;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -0700709 phba->params.asyncpdus_per_ctrl = phba->fw_config.iscsi_cid_count;
Justin P. Mattock6eab04a2011-04-08 19:49:08 -0700710 phba->params.icds_per_ctrl = phba->fw_config.iscsi_icd_count;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530711 phba->params.num_sge_per_io = BE2_SGE;
712 phba->params.defpdu_hdr_sz = BE2_DEFPDU_HDR_SZ;
713 phba->params.defpdu_data_sz = BE2_DEFPDU_DATA_SZ;
714 phba->params.eq_timer = 64;
715 phba->params.num_eq_entries =
Jayamohan Kallickal7da50872010-01-05 05:04:12 +0530716 (((BE2_CMDS_PER_CXN * 2 + phba->fw_config.iscsi_cid_count * 2
717 + BE2_TMFS) / 512) + 1) * 512;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530718 phba->params.num_eq_entries = (phba->params.num_eq_entries < 1024)
719 ? 1024 : phba->params.num_eq_entries;
John Soni Jose99bc5d52012-08-20 23:00:18 +0530720 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
721 "BM_%d : phba->params.num_eq_entries=%d\n",
722 phba->params.num_eq_entries);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530723 phba->params.num_cq_entries =
Jayamohan Kallickal7da50872010-01-05 05:04:12 +0530724 (((BE2_CMDS_PER_CXN * 2 + phba->fw_config.iscsi_cid_count * 2
725 + BE2_TMFS) / 512) + 1) * 512;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530726 phba->params.wrbs_per_cxn = 256;
727}
728
729static void hwi_ring_eq_db(struct beiscsi_hba *phba,
730 unsigned int id, unsigned int clr_interrupt,
731 unsigned int num_processed,
732 unsigned char rearm, unsigned char event)
733{
734 u32 val = 0;
735 val |= id & DB_EQ_RING_ID_MASK;
736 if (rearm)
737 val |= 1 << DB_EQ_REARM_SHIFT;
738 if (clr_interrupt)
739 val |= 1 << DB_EQ_CLR_SHIFT;
740 if (event)
741 val |= 1 << DB_EQ_EVNT_SHIFT;
742 val |= num_processed << DB_EQ_NUM_POPPED_SHIFT;
743 iowrite32(val, phba->db_va + DB_EQ_OFFSET);
744}
745
746/**
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530747 * be_isr_mcc - The isr routine of the driver.
748 * @irq: Not used
749 * @dev_id: Pointer to host adapter structure
750 */
751static irqreturn_t be_isr_mcc(int irq, void *dev_id)
752{
753 struct beiscsi_hba *phba;
754 struct be_eq_entry *eqe = NULL;
755 struct be_queue_info *eq;
756 struct be_queue_info *mcc;
757 unsigned int num_eq_processed;
758 struct be_eq_obj *pbe_eq;
759 unsigned long flags;
760
761 pbe_eq = dev_id;
762 eq = &pbe_eq->q;
763 phba = pbe_eq->phba;
764 mcc = &phba->ctrl.mcc_obj.cq;
765 eqe = queue_tail_node(eq);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530766
767 num_eq_processed = 0;
768
769 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
770 & EQE_VALID_MASK) {
771 if (((eqe->dw[offsetof(struct amap_eq_entry,
772 resource_id) / 32] &
773 EQE_RESID_MASK) >> 16) == mcc->id) {
774 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +0530775 pbe_eq->todo_mcc_cq = true;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530776 spin_unlock_irqrestore(&phba->isr_lock, flags);
777 }
778 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
779 queue_tail_inc(eq);
780 eqe = queue_tail_node(eq);
781 num_eq_processed++;
782 }
John Soni Jose72fb46a2012-10-20 04:42:49 +0530783 if (pbe_eq->todo_mcc_cq)
784 queue_work(phba->wq, &pbe_eq->work_cqs);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530785 if (num_eq_processed)
786 hwi_ring_eq_db(phba, eq->id, 1, num_eq_processed, 1, 1);
787
788 return IRQ_HANDLED;
789}
790
791/**
792 * be_isr_msix - The isr routine of the driver.
793 * @irq: Not used
794 * @dev_id: Pointer to host adapter structure
795 */
796static irqreturn_t be_isr_msix(int irq, void *dev_id)
797{
798 struct beiscsi_hba *phba;
799 struct be_eq_entry *eqe = NULL;
800 struct be_queue_info *eq;
801 struct be_queue_info *cq;
802 unsigned int num_eq_processed;
803 struct be_eq_obj *pbe_eq;
804 unsigned long flags;
805
806 pbe_eq = dev_id;
807 eq = &pbe_eq->q;
808 cq = pbe_eq->cq;
809 eqe = queue_tail_node(eq);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530810
811 phba = pbe_eq->phba;
812 num_eq_processed = 0;
813 if (blk_iopoll_enabled) {
814 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
815 & EQE_VALID_MASK) {
816 if (!blk_iopoll_sched_prep(&pbe_eq->iopoll))
817 blk_iopoll_sched(&pbe_eq->iopoll);
818
819 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
820 queue_tail_inc(eq);
821 eqe = queue_tail_node(eq);
822 num_eq_processed++;
823 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530824 } else {
825 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
826 & EQE_VALID_MASK) {
827 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +0530828 pbe_eq->todo_cq = true;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530829 spin_unlock_irqrestore(&phba->isr_lock, flags);
830 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
831 queue_tail_inc(eq);
832 eqe = queue_tail_node(eq);
833 num_eq_processed++;
834 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530835
John Soni Jose72fb46a2012-10-20 04:42:49 +0530836 if (pbe_eq->todo_cq)
837 queue_work(phba->wq, &pbe_eq->work_cqs);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530838 }
John Soni Jose72fb46a2012-10-20 04:42:49 +0530839
840 if (num_eq_processed)
841 hwi_ring_eq_db(phba, eq->id, 1, num_eq_processed, 0, 1);
842
843 return IRQ_HANDLED;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530844}
845
846/**
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530847 * be_isr - The isr routine of the driver.
848 * @irq: Not used
849 * @dev_id: Pointer to host adapter structure
850 */
851static irqreturn_t be_isr(int irq, void *dev_id)
852{
853 struct beiscsi_hba *phba;
854 struct hwi_controller *phwi_ctrlr;
855 struct hwi_context_memory *phwi_context;
856 struct be_eq_entry *eqe = NULL;
857 struct be_queue_info *eq;
858 struct be_queue_info *cq;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530859 struct be_queue_info *mcc;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530860 unsigned long flags, index;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530861 unsigned int num_mcceq_processed, num_ioeq_processed;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530862 struct be_ctrl_info *ctrl;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530863 struct be_eq_obj *pbe_eq;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530864 int isr;
865
866 phba = dev_id;
Justin P. Mattock6eab04a2011-04-08 19:49:08 -0700867 ctrl = &phba->ctrl;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530868 isr = ioread32(ctrl->csr + CEV_ISR0_OFFSET +
869 (PCI_FUNC(ctrl->pdev->devfn) * CEV_ISR_SIZE));
870 if (!isr)
871 return IRQ_NONE;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530872
873 phwi_ctrlr = phba->phwi_ctrlr;
874 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530875 pbe_eq = &phwi_context->be_eq[0];
876
877 eq = &phwi_context->be_eq[0].q;
878 mcc = &phba->ctrl.mcc_obj.cq;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530879 index = 0;
880 eqe = queue_tail_node(eq);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530881
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530882 num_ioeq_processed = 0;
883 num_mcceq_processed = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530884 if (blk_iopoll_enabled) {
885 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
886 & EQE_VALID_MASK) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530887 if (((eqe->dw[offsetof(struct amap_eq_entry,
888 resource_id) / 32] &
889 EQE_RESID_MASK) >> 16) == mcc->id) {
890 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +0530891 pbe_eq->todo_mcc_cq = true;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530892 spin_unlock_irqrestore(&phba->isr_lock, flags);
893 num_mcceq_processed++;
894 } else {
895 if (!blk_iopoll_sched_prep(&pbe_eq->iopoll))
896 blk_iopoll_sched(&pbe_eq->iopoll);
897 num_ioeq_processed++;
898 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530899 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
900 queue_tail_inc(eq);
901 eqe = queue_tail_node(eq);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530902 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530903 if (num_ioeq_processed || num_mcceq_processed) {
John Soni Jose72fb46a2012-10-20 04:42:49 +0530904 if (pbe_eq->todo_mcc_cq)
905 queue_work(phba->wq, &pbe_eq->work_cqs);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530906
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530907 if ((num_mcceq_processed) && (!num_ioeq_processed))
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530908 hwi_ring_eq_db(phba, eq->id, 0,
909 (num_ioeq_processed +
910 num_mcceq_processed) , 1, 1);
911 else
912 hwi_ring_eq_db(phba, eq->id, 0,
913 (num_ioeq_processed +
914 num_mcceq_processed), 0, 1);
915
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530916 return IRQ_HANDLED;
917 } else
918 return IRQ_NONE;
919 } else {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530920 cq = &phwi_context->be_cq[0];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530921 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
922 & EQE_VALID_MASK) {
923
924 if (((eqe->dw[offsetof(struct amap_eq_entry,
925 resource_id) / 32] &
926 EQE_RESID_MASK) >> 16) != cq->id) {
927 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +0530928 pbe_eq->todo_mcc_cq = true;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530929 spin_unlock_irqrestore(&phba->isr_lock, flags);
930 } else {
931 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +0530932 pbe_eq->todo_cq = true;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530933 spin_unlock_irqrestore(&phba->isr_lock, flags);
934 }
935 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
936 queue_tail_inc(eq);
937 eqe = queue_tail_node(eq);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530938 num_ioeq_processed++;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530939 }
John Soni Jose72fb46a2012-10-20 04:42:49 +0530940 if (pbe_eq->todo_cq || pbe_eq->todo_mcc_cq)
941 queue_work(phba->wq, &pbe_eq->work_cqs);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530942
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530943 if (num_ioeq_processed) {
944 hwi_ring_eq_db(phba, eq->id, 0,
945 num_ioeq_processed, 1, 1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530946 return IRQ_HANDLED;
947 } else
948 return IRQ_NONE;
949 }
950}
951
952static int beiscsi_init_irqs(struct beiscsi_hba *phba)
953{
954 struct pci_dev *pcidev = phba->pcidev;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530955 struct hwi_controller *phwi_ctrlr;
956 struct hwi_context_memory *phwi_context;
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +0530957 int ret, msix_vec, i, j;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530958
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530959 phwi_ctrlr = phba->phwi_ctrlr;
960 phwi_context = phwi_ctrlr->phwi_ctxt;
961
962 if (phba->msix_enabled) {
963 for (i = 0; i < phba->num_cpus; i++) {
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -0700964 phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME,
965 GFP_KERNEL);
966 if (!phba->msi_name[i]) {
967 ret = -ENOMEM;
968 goto free_msix_irqs;
969 }
970
971 sprintf(phba->msi_name[i], "beiscsi_%02x_%02x",
972 phba->shost->host_no, i);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530973 msix_vec = phba->msix_entries[i].vector;
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -0700974 ret = request_irq(msix_vec, be_isr_msix, 0,
975 phba->msi_name[i],
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530976 &phwi_context->be_eq[i]);
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +0530977 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530978 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
979 "BM_%d : beiscsi_init_irqs-Failed to"
980 "register msix for i = %d\n",
981 i);
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -0700982 kfree(phba->msi_name[i]);
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +0530983 goto free_msix_irqs;
984 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530985 }
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -0700986 phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME, GFP_KERNEL);
987 if (!phba->msi_name[i]) {
988 ret = -ENOMEM;
989 goto free_msix_irqs;
990 }
991 sprintf(phba->msi_name[i], "beiscsi_mcc_%02x",
992 phba->shost->host_no);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530993 msix_vec = phba->msix_entries[i].vector;
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -0700994 ret = request_irq(msix_vec, be_isr_mcc, 0, phba->msi_name[i],
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530995 &phwi_context->be_eq[i]);
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +0530996 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530997 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT ,
998 "BM_%d : beiscsi_init_irqs-"
999 "Failed to register beiscsi_msix_mcc\n");
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -07001000 kfree(phba->msi_name[i]);
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +05301001 goto free_msix_irqs;
1002 }
1003
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301004 } else {
1005 ret = request_irq(pcidev->irq, be_isr, IRQF_SHARED,
1006 "beiscsi", phba);
1007 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301008 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
1009 "BM_%d : beiscsi_init_irqs-"
1010 "Failed to register irq\\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301011 return ret;
1012 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301013 }
1014 return 0;
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +05301015free_msix_irqs:
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -07001016 for (j = i - 1; j >= 0; j--) {
1017 kfree(phba->msi_name[j]);
1018 msix_vec = phba->msix_entries[j].vector;
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +05301019 free_irq(msix_vec, &phwi_context->be_eq[j]);
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -07001020 }
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +05301021 return ret;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301022}
1023
1024static void hwi_ring_cq_db(struct beiscsi_hba *phba,
1025 unsigned int id, unsigned int num_processed,
1026 unsigned char rearm, unsigned char event)
1027{
1028 u32 val = 0;
1029 val |= id & DB_CQ_RING_ID_MASK;
1030 if (rearm)
1031 val |= 1 << DB_CQ_REARM_SHIFT;
1032 val |= num_processed << DB_CQ_NUM_POPPED_SHIFT;
1033 iowrite32(val, phba->db_va + DB_CQ_OFFSET);
1034}
1035
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301036static unsigned int
1037beiscsi_process_async_pdu(struct beiscsi_conn *beiscsi_conn,
1038 struct beiscsi_hba *phba,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301039 struct pdu_base *ppdu,
1040 unsigned long pdu_len,
1041 void *pbuffer, unsigned long buf_len)
1042{
1043 struct iscsi_conn *conn = beiscsi_conn->conn;
1044 struct iscsi_session *session = conn->session;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301045 struct iscsi_task *task;
1046 struct beiscsi_io_task *io_task;
1047 struct iscsi_hdr *login_hdr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301048
1049 switch (ppdu->dw[offsetof(struct amap_pdu_base, opcode) / 32] &
1050 PDUBASE_OPCODE_MASK) {
1051 case ISCSI_OP_NOOP_IN:
1052 pbuffer = NULL;
1053 buf_len = 0;
1054 break;
1055 case ISCSI_OP_ASYNC_EVENT:
1056 break;
1057 case ISCSI_OP_REJECT:
1058 WARN_ON(!pbuffer);
1059 WARN_ON(!(buf_len == 48));
John Soni Jose99bc5d52012-08-20 23:00:18 +05301060 beiscsi_log(phba, KERN_ERR,
1061 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1062 "BM_%d : In ISCSI_OP_REJECT\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301063 break;
1064 case ISCSI_OP_LOGIN_RSP:
Jayamohan Kallickal7bd6e252010-01-05 05:07:02 +05301065 case ISCSI_OP_TEXT_RSP:
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301066 task = conn->login_task;
1067 io_task = task->dd_data;
1068 login_hdr = (struct iscsi_hdr *)ppdu;
1069 login_hdr->itt = io_task->libiscsi_itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301070 break;
1071 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +05301072 beiscsi_log(phba, KERN_WARNING,
1073 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1074 "BM_%d : Unrecognized opcode 0x%x in async msg\n",
1075 (ppdu->
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301076 dw[offsetof(struct amap_pdu_base, opcode) / 32]
John Soni Jose99bc5d52012-08-20 23:00:18 +05301077 & PDUBASE_OPCODE_MASK));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301078 return 1;
1079 }
1080
1081 spin_lock_bh(&session->lock);
1082 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)ppdu, pbuffer, buf_len);
1083 spin_unlock_bh(&session->lock);
1084 return 0;
1085}
1086
1087static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba)
1088{
1089 struct sgl_handle *psgl_handle;
1090
1091 if (phba->io_sgl_hndl_avbl) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301092 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
1093 "BM_%d : In alloc_io_sgl_handle,"
1094 " io_sgl_alloc_index=%d\n",
1095 phba->io_sgl_alloc_index);
1096
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301097 psgl_handle = phba->io_sgl_hndl_base[phba->
1098 io_sgl_alloc_index];
1099 phba->io_sgl_hndl_base[phba->io_sgl_alloc_index] = NULL;
1100 phba->io_sgl_hndl_avbl--;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301101 if (phba->io_sgl_alloc_index == (phba->params.
1102 ios_per_ctrl - 1))
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301103 phba->io_sgl_alloc_index = 0;
1104 else
1105 phba->io_sgl_alloc_index++;
1106 } else
1107 psgl_handle = NULL;
1108 return psgl_handle;
1109}
1110
1111static void
1112free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
1113{
John Soni Jose99bc5d52012-08-20 23:00:18 +05301114 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
1115 "BM_%d : In free_,io_sgl_free_index=%d\n",
1116 phba->io_sgl_free_index);
1117
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301118 if (phba->io_sgl_hndl_base[phba->io_sgl_free_index]) {
1119 /*
1120 * this can happen if clean_task is called on a task that
1121 * failed in xmit_task or alloc_pdu.
1122 */
John Soni Jose99bc5d52012-08-20 23:00:18 +05301123 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
1124 "BM_%d : Double Free in IO SGL io_sgl_free_index=%d,"
1125 "value there=%p\n", phba->io_sgl_free_index,
1126 phba->io_sgl_hndl_base
1127 [phba->io_sgl_free_index]);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301128 return;
1129 }
1130 phba->io_sgl_hndl_base[phba->io_sgl_free_index] = psgl_handle;
1131 phba->io_sgl_hndl_avbl++;
1132 if (phba->io_sgl_free_index == (phba->params.ios_per_ctrl - 1))
1133 phba->io_sgl_free_index = 0;
1134 else
1135 phba->io_sgl_free_index++;
1136}
1137
1138/**
1139 * alloc_wrb_handle - To allocate a wrb handle
1140 * @phba: The hba pointer
1141 * @cid: The cid to use for allocation
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301142 *
1143 * This happens under session_lock until submission to chip
1144 */
Jayamohan Kallickald5431482010-01-05 05:06:21 +05301145struct wrb_handle *alloc_wrb_handle(struct beiscsi_hba *phba, unsigned int cid)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301146{
1147 struct hwi_wrb_context *pwrb_context;
1148 struct hwi_controller *phwi_ctrlr;
Jayamohan Kallickald5431482010-01-05 05:06:21 +05301149 struct wrb_handle *pwrb_handle, *pwrb_handle_tmp;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001150 uint16_t cri_index = BE_GET_CRI_FROM_CID(cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301151
1152 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001153 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
Jayamohan Kallickald5431482010-01-05 05:06:21 +05301154 if (pwrb_context->wrb_handles_available >= 2) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301155 pwrb_handle = pwrb_context->pwrb_handle_base[
1156 pwrb_context->alloc_index];
1157 pwrb_context->wrb_handles_available--;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301158 if (pwrb_context->alloc_index ==
1159 (phba->params.wrbs_per_cxn - 1))
1160 pwrb_context->alloc_index = 0;
1161 else
1162 pwrb_context->alloc_index++;
Jayamohan Kallickald5431482010-01-05 05:06:21 +05301163 pwrb_handle_tmp = pwrb_context->pwrb_handle_base[
1164 pwrb_context->alloc_index];
1165 pwrb_handle->nxt_wrb_index = pwrb_handle_tmp->wrb_index;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301166 } else
1167 pwrb_handle = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301168 return pwrb_handle;
1169}
1170
1171/**
1172 * free_wrb_handle - To free the wrb handle back to pool
1173 * @phba: The hba pointer
1174 * @pwrb_context: The context to free from
1175 * @pwrb_handle: The wrb_handle to free
1176 *
1177 * This happens under session_lock until submission to chip
1178 */
1179static void
1180free_wrb_handle(struct beiscsi_hba *phba, struct hwi_wrb_context *pwrb_context,
1181 struct wrb_handle *pwrb_handle)
1182{
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05301183 pwrb_context->pwrb_handle_base[pwrb_context->free_index] = pwrb_handle;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301184 pwrb_context->wrb_handles_available++;
1185 if (pwrb_context->free_index == (phba->params.wrbs_per_cxn - 1))
1186 pwrb_context->free_index = 0;
1187 else
1188 pwrb_context->free_index++;
1189
John Soni Jose99bc5d52012-08-20 23:00:18 +05301190 beiscsi_log(phba, KERN_INFO,
1191 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1192 "BM_%d : FREE WRB: pwrb_handle=%p free_index=0x%x"
1193 "wrb_handles_available=%d\n",
1194 pwrb_handle, pwrb_context->free_index,
1195 pwrb_context->wrb_handles_available);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301196}
1197
1198static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba)
1199{
1200 struct sgl_handle *psgl_handle;
1201
1202 if (phba->eh_sgl_hndl_avbl) {
1203 psgl_handle = phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index];
1204 phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index] = NULL;
John Soni Jose99bc5d52012-08-20 23:00:18 +05301205 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1206 "BM_%d : mgmt_sgl_alloc_index=%d=0x%x\n",
1207 phba->eh_sgl_alloc_index,
1208 phba->eh_sgl_alloc_index);
1209
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301210 phba->eh_sgl_hndl_avbl--;
1211 if (phba->eh_sgl_alloc_index ==
1212 (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl -
1213 1))
1214 phba->eh_sgl_alloc_index = 0;
1215 else
1216 phba->eh_sgl_alloc_index++;
1217 } else
1218 psgl_handle = NULL;
1219 return psgl_handle;
1220}
1221
1222void
1223free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
1224{
1225
John Soni Jose99bc5d52012-08-20 23:00:18 +05301226 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1227 "BM_%d : In free_mgmt_sgl_handle,"
1228 "eh_sgl_free_index=%d\n",
1229 phba->eh_sgl_free_index);
1230
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301231 if (phba->eh_sgl_hndl_base[phba->eh_sgl_free_index]) {
1232 /*
1233 * this can happen if clean_task is called on a task that
1234 * failed in xmit_task or alloc_pdu.
1235 */
John Soni Jose99bc5d52012-08-20 23:00:18 +05301236 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1237 "BM_%d : Double Free in eh SGL ,"
1238 "eh_sgl_free_index=%d\n",
1239 phba->eh_sgl_free_index);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301240 return;
1241 }
1242 phba->eh_sgl_hndl_base[phba->eh_sgl_free_index] = psgl_handle;
1243 phba->eh_sgl_hndl_avbl++;
1244 if (phba->eh_sgl_free_index ==
1245 (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl - 1))
1246 phba->eh_sgl_free_index = 0;
1247 else
1248 phba->eh_sgl_free_index++;
1249}
1250
1251static void
1252be_complete_io(struct beiscsi_conn *beiscsi_conn,
John Soni Jose73133262012-10-20 04:44:49 +05301253 struct iscsi_task *task,
1254 struct common_sol_cqe *csol_cqe)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301255{
1256 struct beiscsi_io_task *io_task = task->dd_data;
1257 struct be_status_bhs *sts_bhs =
1258 (struct be_status_bhs *)io_task->cmd_bhs;
1259 struct iscsi_conn *conn = beiscsi_conn->conn;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301260 unsigned char *sense;
1261 u32 resid = 0, exp_cmdsn, max_cmdsn;
1262 u8 rsp, status, flags;
1263
John Soni Jose73133262012-10-20 04:44:49 +05301264 exp_cmdsn = csol_cqe->exp_cmdsn;
1265 max_cmdsn = (csol_cqe->exp_cmdsn +
1266 csol_cqe->cmd_wnd - 1);
1267 rsp = csol_cqe->i_resp;
1268 status = csol_cqe->i_sts;
1269 flags = csol_cqe->i_flags;
1270 resid = csol_cqe->res_cnt;
1271
Jayamohan Kallickalbd535452011-10-07 19:31:10 -05001272 if (!task->sc) {
1273 if (io_task->scsi_cmnd)
1274 scsi_dma_unmap(io_task->scsi_cmnd);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301275
Jayamohan Kallickalbd535452011-10-07 19:31:10 -05001276 return;
1277 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301278 task->sc->result = (DID_OK << 16) | status;
1279 if (rsp != ISCSI_STATUS_CMD_COMPLETED) {
1280 task->sc->result = DID_ERROR << 16;
1281 goto unmap;
1282 }
1283
1284 /* bidi not initially supported */
1285 if (flags & (ISCSI_FLAG_CMD_UNDERFLOW | ISCSI_FLAG_CMD_OVERFLOW)) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301286 if (!status && (flags & ISCSI_FLAG_CMD_OVERFLOW))
1287 task->sc->result = DID_ERROR << 16;
1288
1289 if (flags & ISCSI_FLAG_CMD_UNDERFLOW) {
1290 scsi_set_resid(task->sc, resid);
1291 if (!status && (scsi_bufflen(task->sc) - resid <
1292 task->sc->underflow))
1293 task->sc->result = DID_ERROR << 16;
1294 }
1295 }
1296
1297 if (status == SAM_STAT_CHECK_CONDITION) {
Dan Carpenter4053a4be2011-09-26 09:23:37 +03001298 u16 sense_len;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301299 unsigned short *slen = (unsigned short *)sts_bhs->sense_info;
Dan Carpenter4053a4be2011-09-26 09:23:37 +03001300
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301301 sense = sts_bhs->sense_info + sizeof(unsigned short);
Dan Carpenter4053a4be2011-09-26 09:23:37 +03001302 sense_len = be16_to_cpu(*slen);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301303 memcpy(task->sc->sense_buffer, sense,
1304 min_t(u16, sense_len, SCSI_SENSE_BUFFERSIZE));
1305 }
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05301306
John Soni Jose73133262012-10-20 04:44:49 +05301307 if (io_task->cmd_bhs->iscsi_hdr.flags & ISCSI_FLAG_CMD_READ)
1308 conn->rxdata_octets += resid;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301309unmap:
1310 scsi_dma_unmap(io_task->scsi_cmnd);
1311 iscsi_complete_scsi_task(task, exp_cmdsn, max_cmdsn);
1312}
1313
1314static void
1315be_complete_logout(struct beiscsi_conn *beiscsi_conn,
John Soni Jose73133262012-10-20 04:44:49 +05301316 struct iscsi_task *task,
1317 struct common_sol_cqe *csol_cqe)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301318{
1319 struct iscsi_logout_rsp *hdr;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301320 struct beiscsi_io_task *io_task = task->dd_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301321 struct iscsi_conn *conn = beiscsi_conn->conn;
1322
1323 hdr = (struct iscsi_logout_rsp *)task->hdr;
Jayamohan Kallickal7bd6e252010-01-05 05:07:02 +05301324 hdr->opcode = ISCSI_OP_LOGOUT_RSP;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301325 hdr->t2wait = 5;
1326 hdr->t2retain = 0;
John Soni Jose73133262012-10-20 04:44:49 +05301327 hdr->flags = csol_cqe->i_flags;
1328 hdr->response = csol_cqe->i_resp;
Jayamohan Kallickal702dc5e2013-04-05 20:38:37 -07001329 hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn);
1330 hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn +
1331 csol_cqe->cmd_wnd - 1);
John Soni Jose73133262012-10-20 04:44:49 +05301332
Jayamohan Kallickal7bd6e252010-01-05 05:07:02 +05301333 hdr->dlength[0] = 0;
1334 hdr->dlength[1] = 0;
1335 hdr->dlength[2] = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301336 hdr->hlength = 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301337 hdr->itt = io_task->libiscsi_itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301338 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1339}
1340
1341static void
1342be_complete_tmf(struct beiscsi_conn *beiscsi_conn,
John Soni Jose73133262012-10-20 04:44:49 +05301343 struct iscsi_task *task,
1344 struct common_sol_cqe *csol_cqe)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301345{
1346 struct iscsi_tm_rsp *hdr;
1347 struct iscsi_conn *conn = beiscsi_conn->conn;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301348 struct beiscsi_io_task *io_task = task->dd_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301349
1350 hdr = (struct iscsi_tm_rsp *)task->hdr;
Jayamohan Kallickal7bd6e252010-01-05 05:07:02 +05301351 hdr->opcode = ISCSI_OP_SCSI_TMFUNC_RSP;
John Soni Jose73133262012-10-20 04:44:49 +05301352 hdr->flags = csol_cqe->i_flags;
1353 hdr->response = csol_cqe->i_resp;
Jayamohan Kallickal702dc5e2013-04-05 20:38:37 -07001354 hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn);
1355 hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn +
1356 csol_cqe->cmd_wnd - 1);
John Soni Jose73133262012-10-20 04:44:49 +05301357
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301358 hdr->itt = io_task->libiscsi_itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301359 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1360}
1361
1362static void
1363hwi_complete_drvr_msgs(struct beiscsi_conn *beiscsi_conn,
1364 struct beiscsi_hba *phba, struct sol_cqe *psol)
1365{
1366 struct hwi_wrb_context *pwrb_context;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301367 struct wrb_handle *pwrb_handle = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301368 struct hwi_controller *phwi_ctrlr;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301369 struct iscsi_task *task;
1370 struct beiscsi_io_task *io_task;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001371 uint16_t wrb_index, cid, cri_index;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301372
1373 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07001374 if (is_chip_be2_be3r(phba)) {
John Soni Jose73133262012-10-20 04:44:49 +05301375 wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe,
1376 wrb_idx, psol);
1377 cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe,
1378 cid, psol);
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07001379 } else {
1380 wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2,
1381 wrb_idx, psol);
1382 cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2,
1383 cid, psol);
John Soni Jose73133262012-10-20 04:44:49 +05301384 }
1385
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001386 cri_index = BE_GET_CRI_FROM_CID(cid);
1387 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
John Soni Jose73133262012-10-20 04:44:49 +05301388 pwrb_handle = pwrb_context->pwrb_handle_basestd[wrb_index];
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05301389 task = pwrb_handle->pio_handle;
Jayamohan Kallickal35e66012009-10-23 11:53:49 +05301390
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301391 io_task = task->dd_data;
Jayamohan Kallickal4a4a11b2013-04-05 20:38:31 -07001392 memset(io_task->pwrb_handle->pwrb, 0, sizeof(struct iscsi_wrb));
1393 iscsi_put_task(task);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301394}
1395
1396static void
1397be_complete_nopin_resp(struct beiscsi_conn *beiscsi_conn,
John Soni Jose73133262012-10-20 04:44:49 +05301398 struct iscsi_task *task,
1399 struct common_sol_cqe *csol_cqe)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301400{
1401 struct iscsi_nopin *hdr;
1402 struct iscsi_conn *conn = beiscsi_conn->conn;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301403 struct beiscsi_io_task *io_task = task->dd_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301404
1405 hdr = (struct iscsi_nopin *)task->hdr;
John Soni Jose73133262012-10-20 04:44:49 +05301406 hdr->flags = csol_cqe->i_flags;
1407 hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn);
Jayamohan Kallickal702dc5e2013-04-05 20:38:37 -07001408 hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn +
1409 csol_cqe->cmd_wnd - 1);
John Soni Jose73133262012-10-20 04:44:49 +05301410
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301411 hdr->opcode = ISCSI_OP_NOOP_IN;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301412 hdr->itt = io_task->libiscsi_itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301413 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1414}
1415
John Soni Jose73133262012-10-20 04:44:49 +05301416static void adapter_get_sol_cqe(struct beiscsi_hba *phba,
1417 struct sol_cqe *psol,
1418 struct common_sol_cqe *csol_cqe)
1419{
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07001420 if (is_chip_be2_be3r(phba)) {
1421 csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe,
1422 i_exp_cmd_sn, psol);
1423 csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe,
1424 i_res_cnt, psol);
1425 csol_cqe->cmd_wnd = AMAP_GET_BITS(struct amap_sol_cqe,
1426 i_cmd_wnd, psol);
1427 csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe,
1428 wrb_index, psol);
1429 csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe,
1430 cid, psol);
1431 csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe,
1432 hw_sts, psol);
1433 csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe,
1434 i_resp, psol);
1435 csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe,
1436 i_sts, psol);
1437 csol_cqe->i_flags = AMAP_GET_BITS(struct amap_sol_cqe,
1438 i_flags, psol);
1439 } else {
John Soni Jose73133262012-10-20 04:44:49 +05301440 csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1441 i_exp_cmd_sn, psol);
1442 csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1443 i_res_cnt, psol);
1444 csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1445 wrb_index, psol);
1446 csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1447 cid, psol);
1448 csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1449 hw_sts, psol);
Jayamohan Kallickal702dc5e2013-04-05 20:38:37 -07001450 csol_cqe->cmd_wnd = AMAP_GET_BITS(struct amap_sol_cqe_v2,
John Soni Jose73133262012-10-20 04:44:49 +05301451 i_cmd_wnd, psol);
1452 if (AMAP_GET_BITS(struct amap_sol_cqe_v2,
1453 cmd_cmpl, psol))
1454 csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1455 i_sts, psol);
1456 else
1457 csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1458 i_sts, psol);
1459 if (AMAP_GET_BITS(struct amap_sol_cqe_v2,
1460 u, psol))
1461 csol_cqe->i_flags = ISCSI_FLAG_CMD_UNDERFLOW;
1462
1463 if (AMAP_GET_BITS(struct amap_sol_cqe_v2,
1464 o, psol))
1465 csol_cqe->i_flags |= ISCSI_FLAG_CMD_OVERFLOW;
John Soni Jose73133262012-10-20 04:44:49 +05301466 }
1467}
1468
1469
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301470static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn,
1471 struct beiscsi_hba *phba, struct sol_cqe *psol)
1472{
1473 struct hwi_wrb_context *pwrb_context;
1474 struct wrb_handle *pwrb_handle;
1475 struct iscsi_wrb *pwrb = NULL;
1476 struct hwi_controller *phwi_ctrlr;
1477 struct iscsi_task *task;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301478 unsigned int type;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301479 struct iscsi_conn *conn = beiscsi_conn->conn;
1480 struct iscsi_session *session = conn->session;
John Soni Jose73133262012-10-20 04:44:49 +05301481 struct common_sol_cqe csol_cqe = {0};
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001482 uint16_t cri_index = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301483
1484 phwi_ctrlr = phba->phwi_ctrlr;
John Soni Jose73133262012-10-20 04:44:49 +05301485
1486 /* Copy the elements to a common structure */
1487 adapter_get_sol_cqe(phba, psol, &csol_cqe);
1488
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001489 cri_index = BE_GET_CRI_FROM_CID(csol_cqe.cid);
1490 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
John Soni Jose73133262012-10-20 04:44:49 +05301491
1492 pwrb_handle = pwrb_context->pwrb_handle_basestd[
1493 csol_cqe.wrb_index];
1494
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05301495 task = pwrb_handle->pio_handle;
1496 pwrb = pwrb_handle->pwrb;
John Soni Jose73133262012-10-20 04:44:49 +05301497 type = ((struct beiscsi_io_task *)task->dd_data)->wrb_type;
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05301498
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301499 spin_lock_bh(&session->lock);
1500 switch (type) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301501 case HWH_TYPE_IO:
1502 case HWH_TYPE_IO_RD:
1503 if ((task->hdr->opcode & ISCSI_OPCODE_MASK) ==
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05301504 ISCSI_OP_NOOP_OUT)
John Soni Jose73133262012-10-20 04:44:49 +05301505 be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe);
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05301506 else
John Soni Jose73133262012-10-20 04:44:49 +05301507 be_complete_io(beiscsi_conn, task, &csol_cqe);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301508 break;
1509
1510 case HWH_TYPE_LOGOUT:
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05301511 if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGOUT)
John Soni Jose73133262012-10-20 04:44:49 +05301512 be_complete_logout(beiscsi_conn, task, &csol_cqe);
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05301513 else
John Soni Jose73133262012-10-20 04:44:49 +05301514 be_complete_tmf(beiscsi_conn, task, &csol_cqe);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301515 break;
1516
1517 case HWH_TYPE_LOGIN:
John Soni Jose99bc5d52012-08-20 23:00:18 +05301518 beiscsi_log(phba, KERN_ERR,
1519 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1520 "BM_%d :\t\t No HWH_TYPE_LOGIN Expected in"
1521 " hwi_complete_cmd- Solicited path\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301522 break;
1523
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301524 case HWH_TYPE_NOP:
John Soni Jose73133262012-10-20 04:44:49 +05301525 be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301526 break;
1527
1528 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +05301529 beiscsi_log(phba, KERN_WARNING,
1530 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1531 "BM_%d : In hwi_complete_cmd, unknown type = %d"
1532 "wrb_index 0x%x CID 0x%x\n", type,
John Soni Jose73133262012-10-20 04:44:49 +05301533 csol_cqe.wrb_index,
1534 csol_cqe.cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301535 break;
1536 }
Jayamohan Kallickal35e66012009-10-23 11:53:49 +05301537
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301538 spin_unlock_bh(&session->lock);
1539}
1540
1541static struct list_head *hwi_get_async_busy_list(struct hwi_async_pdu_context
1542 *pasync_ctx, unsigned int is_header,
1543 unsigned int host_write_ptr)
1544{
1545 if (is_header)
1546 return &pasync_ctx->async_entry[host_write_ptr].
1547 header_busy_list;
1548 else
1549 return &pasync_ctx->async_entry[host_write_ptr].data_busy_list;
1550}
1551
1552static struct async_pdu_handle *
1553hwi_get_async_handle(struct beiscsi_hba *phba,
1554 struct beiscsi_conn *beiscsi_conn,
1555 struct hwi_async_pdu_context *pasync_ctx,
1556 struct i_t_dpdu_cqe *pdpdu_cqe, unsigned int *pcq_index)
1557{
1558 struct be_bus_address phys_addr;
1559 struct list_head *pbusy_list;
1560 struct async_pdu_handle *pasync_handle = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301561 unsigned char is_header = 0;
John Soni Jose73133262012-10-20 04:44:49 +05301562 unsigned int index, dpl;
1563
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07001564 if (is_chip_be2_be3r(phba)) {
John Soni Jose73133262012-10-20 04:44:49 +05301565 dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe,
1566 dpl, pdpdu_cqe);
1567 index = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe,
1568 index, pdpdu_cqe);
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07001569 } else {
1570 dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2,
1571 dpl, pdpdu_cqe);
1572 index = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2,
1573 index, pdpdu_cqe);
John Soni Jose73133262012-10-20 04:44:49 +05301574 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301575
1576 phys_addr.u.a32.address_lo =
John Soni Jose73133262012-10-20 04:44:49 +05301577 (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
1578 db_addr_lo) / 32] - dpl);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301579 phys_addr.u.a32.address_hi =
John Soni Jose73133262012-10-20 04:44:49 +05301580 pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
1581 db_addr_hi) / 32];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301582
1583 phys_addr.u.a64.address =
1584 *((unsigned long long *)(&phys_addr.u.a64.address));
1585
1586 switch (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, code) / 32]
1587 & PDUCQE_CODE_MASK) {
1588 case UNSOL_HDR_NOTIFY:
1589 is_header = 1;
1590
John Soni Jose73133262012-10-20 04:44:49 +05301591 pbusy_list = hwi_get_async_busy_list(pasync_ctx,
1592 is_header, index);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301593 break;
1594 case UNSOL_DATA_NOTIFY:
John Soni Jose73133262012-10-20 04:44:49 +05301595 pbusy_list = hwi_get_async_busy_list(pasync_ctx,
1596 is_header, index);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301597 break;
1598 default:
1599 pbusy_list = NULL;
John Soni Jose99bc5d52012-08-20 23:00:18 +05301600 beiscsi_log(phba, KERN_WARNING,
1601 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1602 "BM_%d : Unexpected code=%d\n",
1603 pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
1604 code) / 32] & PDUCQE_CODE_MASK);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301605 return NULL;
1606 }
1607
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301608 WARN_ON(list_empty(pbusy_list));
1609 list_for_each_entry(pasync_handle, pbusy_list, link) {
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05001610 if (pasync_handle->pa.u.a64.address == phys_addr.u.a64.address)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301611 break;
1612 }
1613
1614 WARN_ON(!pasync_handle);
1615
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001616 pasync_handle->cri =
1617 BE_GET_CRI_FROM_CID(beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301618 pasync_handle->is_header = is_header;
John Soni Jose73133262012-10-20 04:44:49 +05301619 pasync_handle->buffer_len = dpl;
1620 *pcq_index = index;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301621
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301622 return pasync_handle;
1623}
1624
1625static unsigned int
John Soni Jose99bc5d52012-08-20 23:00:18 +05301626hwi_update_async_writables(struct beiscsi_hba *phba,
1627 struct hwi_async_pdu_context *pasync_ctx,
1628 unsigned int is_header, unsigned int cq_index)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301629{
1630 struct list_head *pbusy_list;
1631 struct async_pdu_handle *pasync_handle;
1632 unsigned int num_entries, writables = 0;
1633 unsigned int *pep_read_ptr, *pwritables;
1634
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05001635 num_entries = pasync_ctx->num_entries;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301636 if (is_header) {
1637 pep_read_ptr = &pasync_ctx->async_header.ep_read_ptr;
1638 pwritables = &pasync_ctx->async_header.writables;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301639 } else {
1640 pep_read_ptr = &pasync_ctx->async_data.ep_read_ptr;
1641 pwritables = &pasync_ctx->async_data.writables;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301642 }
1643
1644 while ((*pep_read_ptr) != cq_index) {
1645 (*pep_read_ptr)++;
1646 *pep_read_ptr = (*pep_read_ptr) % num_entries;
1647
1648 pbusy_list = hwi_get_async_busy_list(pasync_ctx, is_header,
1649 *pep_read_ptr);
1650 if (writables == 0)
1651 WARN_ON(list_empty(pbusy_list));
1652
1653 if (!list_empty(pbusy_list)) {
1654 pasync_handle = list_entry(pbusy_list->next,
1655 struct async_pdu_handle,
1656 link);
1657 WARN_ON(!pasync_handle);
1658 pasync_handle->consumed = 1;
1659 }
1660
1661 writables++;
1662 }
1663
1664 if (!writables) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301665 beiscsi_log(phba, KERN_ERR,
1666 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1667 "BM_%d : Duplicate notification received - index 0x%x!!\n",
1668 cq_index);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301669 WARN_ON(1);
1670 }
1671
1672 *pwritables = *pwritables + writables;
1673 return 0;
1674}
1675
Jayamohan Kallickal9728d8d2012-04-03 23:41:47 -05001676static void hwi_free_async_msg(struct beiscsi_hba *phba,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301677 unsigned int cri)
1678{
1679 struct hwi_controller *phwi_ctrlr;
1680 struct hwi_async_pdu_context *pasync_ctx;
1681 struct async_pdu_handle *pasync_handle, *tmp_handle;
1682 struct list_head *plist;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301683
1684 phwi_ctrlr = phba->phwi_ctrlr;
1685 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
1686
1687 plist = &pasync_ctx->async_entry[cri].wait_queue.list;
1688
1689 list_for_each_entry_safe(pasync_handle, tmp_handle, plist, link) {
1690 list_del(&pasync_handle->link);
1691
Jayamohan Kallickal9728d8d2012-04-03 23:41:47 -05001692 if (pasync_handle->is_header) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301693 list_add_tail(&pasync_handle->link,
1694 &pasync_ctx->async_header.free_list);
1695 pasync_ctx->async_header.free_entries++;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301696 } else {
1697 list_add_tail(&pasync_handle->link,
1698 &pasync_ctx->async_data.free_list);
1699 pasync_ctx->async_data.free_entries++;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301700 }
1701 }
1702
1703 INIT_LIST_HEAD(&pasync_ctx->async_entry[cri].wait_queue.list);
1704 pasync_ctx->async_entry[cri].wait_queue.hdr_received = 0;
1705 pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301706}
1707
1708static struct phys_addr *
1709hwi_get_ring_address(struct hwi_async_pdu_context *pasync_ctx,
1710 unsigned int is_header, unsigned int host_write_ptr)
1711{
1712 struct phys_addr *pasync_sge = NULL;
1713
1714 if (is_header)
1715 pasync_sge = pasync_ctx->async_header.ring_base;
1716 else
1717 pasync_sge = pasync_ctx->async_data.ring_base;
1718
1719 return pasync_sge + host_write_ptr;
1720}
1721
1722static void hwi_post_async_buffers(struct beiscsi_hba *phba,
1723 unsigned int is_header)
1724{
1725 struct hwi_controller *phwi_ctrlr;
1726 struct hwi_async_pdu_context *pasync_ctx;
1727 struct async_pdu_handle *pasync_handle;
1728 struct list_head *pfree_link, *pbusy_list;
1729 struct phys_addr *pasync_sge;
1730 unsigned int ring_id, num_entries;
1731 unsigned int host_write_num;
1732 unsigned int writables;
1733 unsigned int i = 0;
1734 u32 doorbell = 0;
1735
1736 phwi_ctrlr = phba->phwi_ctrlr;
1737 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05001738 num_entries = pasync_ctx->num_entries;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301739
1740 if (is_header) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301741 writables = min(pasync_ctx->async_header.writables,
1742 pasync_ctx->async_header.free_entries);
1743 pfree_link = pasync_ctx->async_header.free_list.next;
1744 host_write_num = pasync_ctx->async_header.host_write_ptr;
1745 ring_id = phwi_ctrlr->default_pdu_hdr.id;
1746 } else {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301747 writables = min(pasync_ctx->async_data.writables,
1748 pasync_ctx->async_data.free_entries);
1749 pfree_link = pasync_ctx->async_data.free_list.next;
1750 host_write_num = pasync_ctx->async_data.host_write_ptr;
1751 ring_id = phwi_ctrlr->default_pdu_data.id;
1752 }
1753
1754 writables = (writables / 8) * 8;
1755 if (writables) {
1756 for (i = 0; i < writables; i++) {
1757 pbusy_list =
1758 hwi_get_async_busy_list(pasync_ctx, is_header,
1759 host_write_num);
1760 pasync_handle =
1761 list_entry(pfree_link, struct async_pdu_handle,
1762 link);
1763 WARN_ON(!pasync_handle);
1764 pasync_handle->consumed = 0;
1765
1766 pfree_link = pfree_link->next;
1767
1768 pasync_sge = hwi_get_ring_address(pasync_ctx,
1769 is_header, host_write_num);
1770
1771 pasync_sge->hi = pasync_handle->pa.u.a32.address_lo;
1772 pasync_sge->lo = pasync_handle->pa.u.a32.address_hi;
1773
1774 list_move(&pasync_handle->link, pbusy_list);
1775
1776 host_write_num++;
1777 host_write_num = host_write_num % num_entries;
1778 }
1779
1780 if (is_header) {
1781 pasync_ctx->async_header.host_write_ptr =
1782 host_write_num;
1783 pasync_ctx->async_header.free_entries -= writables;
1784 pasync_ctx->async_header.writables -= writables;
1785 pasync_ctx->async_header.busy_entries += writables;
1786 } else {
1787 pasync_ctx->async_data.host_write_ptr = host_write_num;
1788 pasync_ctx->async_data.free_entries -= writables;
1789 pasync_ctx->async_data.writables -= writables;
1790 pasync_ctx->async_data.busy_entries += writables;
1791 }
1792
1793 doorbell |= ring_id & DB_DEF_PDU_RING_ID_MASK;
1794 doorbell |= 1 << DB_DEF_PDU_REARM_SHIFT;
1795 doorbell |= 0 << DB_DEF_PDU_EVENT_SHIFT;
1796 doorbell |= (writables & DB_DEF_PDU_CQPROC_MASK)
1797 << DB_DEF_PDU_CQPROC_SHIFT;
1798
1799 iowrite32(doorbell, phba->db_va + DB_RXULP0_OFFSET);
1800 }
1801}
1802
1803static void hwi_flush_default_pdu_buffer(struct beiscsi_hba *phba,
1804 struct beiscsi_conn *beiscsi_conn,
1805 struct i_t_dpdu_cqe *pdpdu_cqe)
1806{
1807 struct hwi_controller *phwi_ctrlr;
1808 struct hwi_async_pdu_context *pasync_ctx;
1809 struct async_pdu_handle *pasync_handle = NULL;
1810 unsigned int cq_index = -1;
1811
1812 phwi_ctrlr = phba->phwi_ctrlr;
1813 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
1814
1815 pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
1816 pdpdu_cqe, &cq_index);
1817 BUG_ON(pasync_handle->is_header != 0);
1818 if (pasync_handle->consumed == 0)
John Soni Jose99bc5d52012-08-20 23:00:18 +05301819 hwi_update_async_writables(phba, pasync_ctx,
1820 pasync_handle->is_header, cq_index);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301821
1822 hwi_free_async_msg(phba, pasync_handle->cri);
1823 hwi_post_async_buffers(phba, pasync_handle->is_header);
1824}
1825
1826static unsigned int
1827hwi_fwd_async_msg(struct beiscsi_conn *beiscsi_conn,
1828 struct beiscsi_hba *phba,
1829 struct hwi_async_pdu_context *pasync_ctx, unsigned short cri)
1830{
1831 struct list_head *plist;
1832 struct async_pdu_handle *pasync_handle;
1833 void *phdr = NULL;
1834 unsigned int hdr_len = 0, buf_len = 0;
1835 unsigned int status, index = 0, offset = 0;
1836 void *pfirst_buffer = NULL;
1837 unsigned int num_buf = 0;
1838
1839 plist = &pasync_ctx->async_entry[cri].wait_queue.list;
1840
1841 list_for_each_entry(pasync_handle, plist, link) {
1842 if (index == 0) {
1843 phdr = pasync_handle->pbuffer;
1844 hdr_len = pasync_handle->buffer_len;
1845 } else {
1846 buf_len = pasync_handle->buffer_len;
1847 if (!num_buf) {
1848 pfirst_buffer = pasync_handle->pbuffer;
1849 num_buf++;
1850 }
1851 memcpy(pfirst_buffer + offset,
1852 pasync_handle->pbuffer, buf_len);
Jayamohan Kallickalf2ba02b2012-04-03 23:41:37 -05001853 offset += buf_len;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301854 }
1855 index++;
1856 }
1857
1858 status = beiscsi_process_async_pdu(beiscsi_conn, phba,
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05301859 phdr, hdr_len, pfirst_buffer,
Jayamohan Kallickalf2ba02b2012-04-03 23:41:37 -05001860 offset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301861
Jayamohan Kallickal605c6cd2012-04-03 23:41:48 -05001862 hwi_free_async_msg(phba, cri);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301863 return 0;
1864}
1865
1866static unsigned int
1867hwi_gather_async_pdu(struct beiscsi_conn *beiscsi_conn,
1868 struct beiscsi_hba *phba,
1869 struct async_pdu_handle *pasync_handle)
1870{
1871 struct hwi_async_pdu_context *pasync_ctx;
1872 struct hwi_controller *phwi_ctrlr;
1873 unsigned int bytes_needed = 0, status = 0;
1874 unsigned short cri = pasync_handle->cri;
1875 struct pdu_base *ppdu;
1876
1877 phwi_ctrlr = phba->phwi_ctrlr;
1878 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
1879
1880 list_del(&pasync_handle->link);
1881 if (pasync_handle->is_header) {
1882 pasync_ctx->async_header.busy_entries--;
1883 if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) {
1884 hwi_free_async_msg(phba, cri);
1885 BUG();
1886 }
1887
1888 pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0;
1889 pasync_ctx->async_entry[cri].wait_queue.hdr_received = 1;
1890 pasync_ctx->async_entry[cri].wait_queue.hdr_len =
1891 (unsigned short)pasync_handle->buffer_len;
1892 list_add_tail(&pasync_handle->link,
1893 &pasync_ctx->async_entry[cri].wait_queue.list);
1894
1895 ppdu = pasync_handle->pbuffer;
1896 bytes_needed = ((((ppdu->dw[offsetof(struct amap_pdu_base,
1897 data_len_hi) / 32] & PDUBASE_DATALENHI_MASK) << 8) &
1898 0xFFFF0000) | ((be16_to_cpu((ppdu->
1899 dw[offsetof(struct amap_pdu_base, data_len_lo) / 32]
1900 & PDUBASE_DATALENLO_MASK) >> 16)) & 0x0000FFFF));
1901
1902 if (status == 0) {
1903 pasync_ctx->async_entry[cri].wait_queue.bytes_needed =
1904 bytes_needed;
1905
1906 if (bytes_needed == 0)
1907 status = hwi_fwd_async_msg(beiscsi_conn, phba,
1908 pasync_ctx, cri);
1909 }
1910 } else {
1911 pasync_ctx->async_data.busy_entries--;
1912 if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) {
1913 list_add_tail(&pasync_handle->link,
1914 &pasync_ctx->async_entry[cri].wait_queue.
1915 list);
1916 pasync_ctx->async_entry[cri].wait_queue.
1917 bytes_received +=
1918 (unsigned short)pasync_handle->buffer_len;
1919
1920 if (pasync_ctx->async_entry[cri].wait_queue.
1921 bytes_received >=
1922 pasync_ctx->async_entry[cri].wait_queue.
1923 bytes_needed)
1924 status = hwi_fwd_async_msg(beiscsi_conn, phba,
1925 pasync_ctx, cri);
1926 }
1927 }
1928 return status;
1929}
1930
1931static void hwi_process_default_pdu_ring(struct beiscsi_conn *beiscsi_conn,
1932 struct beiscsi_hba *phba,
1933 struct i_t_dpdu_cqe *pdpdu_cqe)
1934{
1935 struct hwi_controller *phwi_ctrlr;
1936 struct hwi_async_pdu_context *pasync_ctx;
1937 struct async_pdu_handle *pasync_handle = NULL;
1938 unsigned int cq_index = -1;
1939
1940 phwi_ctrlr = phba->phwi_ctrlr;
1941 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
1942 pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
1943 pdpdu_cqe, &cq_index);
1944
1945 if (pasync_handle->consumed == 0)
John Soni Jose99bc5d52012-08-20 23:00:18 +05301946 hwi_update_async_writables(phba, pasync_ctx,
1947 pasync_handle->is_header, cq_index);
1948
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301949 hwi_gather_async_pdu(beiscsi_conn, phba, pasync_handle);
1950 hwi_post_async_buffers(phba, pasync_handle->is_header);
1951}
1952
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05301953static void beiscsi_process_mcc_isr(struct beiscsi_hba *phba)
1954{
1955 struct be_queue_info *mcc_cq;
1956 struct be_mcc_compl *mcc_compl;
1957 unsigned int num_processed = 0;
1958
1959 mcc_cq = &phba->ctrl.mcc_obj.cq;
1960 mcc_compl = queue_tail_node(mcc_cq);
1961 mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
1962 while (mcc_compl->flags & CQE_FLAGS_VALID_MASK) {
1963
1964 if (num_processed >= 32) {
1965 hwi_ring_cq_db(phba, mcc_cq->id,
1966 num_processed, 0, 0);
1967 num_processed = 0;
1968 }
1969 if (mcc_compl->flags & CQE_FLAGS_ASYNC_MASK) {
1970 /* Interpret flags as an async trailer */
1971 if (is_link_state_evt(mcc_compl->flags))
1972 /* Interpret compl as a async link evt */
1973 beiscsi_async_link_state_process(phba,
1974 (struct be_async_event_link_state *) mcc_compl);
1975 else
John Soni Jose99bc5d52012-08-20 23:00:18 +05301976 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_MBOX,
1977 "BM_%d : Unsupported Async Event, flags"
1978 " = 0x%08x\n",
1979 mcc_compl->flags);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05301980 } else if (mcc_compl->flags & CQE_FLAGS_COMPLETED_MASK) {
1981 be_mcc_compl_process_isr(&phba->ctrl, mcc_compl);
1982 atomic_dec(&phba->ctrl.mcc_obj.q.used);
1983 }
1984
1985 mcc_compl->flags = 0;
1986 queue_tail_inc(mcc_cq);
1987 mcc_compl = queue_tail_node(mcc_cq);
1988 mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
1989 num_processed++;
1990 }
1991
1992 if (num_processed > 0)
1993 hwi_ring_cq_db(phba, mcc_cq->id, num_processed, 1, 0);
1994
1995}
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301996
John Soni Jose6763daa2012-10-20 04:41:45 +05301997/**
1998 * beiscsi_process_cq()- Process the Completion Queue
1999 * @pbe_eq: Event Q on which the Completion has come
2000 *
2001 * return
2002 * Number of Completion Entries processed.
2003 **/
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302004static unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302005{
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302006 struct be_queue_info *cq;
2007 struct sol_cqe *sol;
2008 struct dmsg_cqe *dmsg;
2009 unsigned int num_processed = 0;
2010 unsigned int tot_nump = 0;
John Soni Jose0a513dd2012-08-20 23:00:55 +05302011 unsigned short code = 0, cid = 0;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002012 uint16_t cri_index = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302013 struct beiscsi_conn *beiscsi_conn;
Jayamohan Kallickalc24622882010-01-05 05:05:34 +05302014 struct beiscsi_endpoint *beiscsi_ep;
2015 struct iscsi_endpoint *ep;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302016 struct beiscsi_hba *phba;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302017
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302018 cq = pbe_eq->cq;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302019 sol = queue_tail_node(cq);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302020 phba = pbe_eq->phba;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302021
2022 while (sol->dw[offsetof(struct amap_sol_cqe, valid) / 32] &
2023 CQE_VALID_MASK) {
2024 be_dws_le_to_cpu(sol, sizeof(struct sol_cqe));
2025
John Soni Jose73133262012-10-20 04:44:49 +05302026 code = (sol->dw[offsetof(struct amap_sol_cqe, code) /
2027 32] & CQE_CODE_MASK);
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05302028
John Soni Jose73133262012-10-20 04:44:49 +05302029 /* Get the CID */
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07002030 if (is_chip_be2_be3r(phba)) {
2031 cid = AMAP_GET_BITS(struct amap_sol_cqe, cid, sol);
2032 } else {
John Soni Jose73133262012-10-20 04:44:49 +05302033 if ((code == DRIVERMSG_NOTIFY) ||
2034 (code == UNSOL_HDR_NOTIFY) ||
2035 (code == UNSOL_DATA_NOTIFY))
2036 cid = AMAP_GET_BITS(
2037 struct amap_i_t_dpdu_cqe_v2,
2038 cid, sol);
2039 else
2040 cid = AMAP_GET_BITS(struct amap_sol_cqe_v2,
2041 cid, sol);
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07002042 }
John Soni Jose73133262012-10-20 04:44:49 +05302043
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002044 cri_index = BE_GET_CRI_FROM_CID(cid);
2045 ep = phba->ep_array[cri_index];
Jayamohan Kallickalc24622882010-01-05 05:05:34 +05302046 beiscsi_ep = ep->dd_data;
2047 beiscsi_conn = beiscsi_ep->conn;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05302048
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302049 if (num_processed >= 32) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302050 hwi_ring_cq_db(phba, cq->id,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302051 num_processed, 0, 0);
2052 tot_nump += num_processed;
2053 num_processed = 0;
2054 }
2055
John Soni Jose0a513dd2012-08-20 23:00:55 +05302056 switch (code) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302057 case SOL_CMD_COMPLETE:
2058 hwi_complete_cmd(beiscsi_conn, phba, sol);
2059 break;
2060 case DRIVERMSG_NOTIFY:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302061 beiscsi_log(phba, KERN_INFO,
2062 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302063 "BM_%d : Received %s[%d] on CID : %d\n",
2064 cqe_desc[code], code, cid);
John Soni Jose99bc5d52012-08-20 23:00:18 +05302065
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302066 dmsg = (struct dmsg_cqe *)sol;
2067 hwi_complete_drvr_msgs(beiscsi_conn, phba, sol);
2068 break;
2069 case UNSOL_HDR_NOTIFY:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302070 beiscsi_log(phba, KERN_INFO,
2071 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302072 "BM_%d : Received %s[%d] on CID : %d\n",
2073 cqe_desc[code], code, cid);
John Soni Jose99bc5d52012-08-20 23:00:18 +05302074
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07002075 spin_lock_bh(&phba->async_pdu_lock);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302076 hwi_process_default_pdu_ring(beiscsi_conn, phba,
2077 (struct i_t_dpdu_cqe *)sol);
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07002078 spin_unlock_bh(&phba->async_pdu_lock);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302079 break;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302080 case UNSOL_DATA_NOTIFY:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302081 beiscsi_log(phba, KERN_INFO,
2082 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
John Soni Jose6763daa2012-10-20 04:41:45 +05302083 "BM_%d : Received %s[%d] on CID : %d\n",
2084 cqe_desc[code], code, cid);
John Soni Jose99bc5d52012-08-20 23:00:18 +05302085
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07002086 spin_lock_bh(&phba->async_pdu_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302087 hwi_process_default_pdu_ring(beiscsi_conn, phba,
2088 (struct i_t_dpdu_cqe *)sol);
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07002089 spin_unlock_bh(&phba->async_pdu_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302090 break;
2091 case CXN_INVALIDATE_INDEX_NOTIFY:
2092 case CMD_INVALIDATED_NOTIFY:
2093 case CXN_INVALIDATE_NOTIFY:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302094 beiscsi_log(phba, KERN_ERR,
2095 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302096 "BM_%d : Ignoring %s[%d] on CID : %d\n",
2097 cqe_desc[code], code, cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302098 break;
2099 case SOL_CMD_KILLED_DATA_DIGEST_ERR:
2100 case CMD_KILLED_INVALID_STATSN_RCVD:
2101 case CMD_KILLED_INVALID_R2T_RCVD:
2102 case CMD_CXN_KILLED_LUN_INVALID:
2103 case CMD_CXN_KILLED_ICD_INVALID:
2104 case CMD_CXN_KILLED_ITT_INVALID:
2105 case CMD_CXN_KILLED_SEQ_OUTOFORDER:
2106 case CMD_CXN_KILLED_INVALID_DATASN_RCVD:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302107 beiscsi_log(phba, KERN_ERR,
2108 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
John Soni Jose6763daa2012-10-20 04:41:45 +05302109 "BM_%d : Cmd Notification %s[%d] on CID : %d\n",
2110 cqe_desc[code], code, cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302111 break;
2112 case UNSOL_DATA_DIGEST_ERROR_NOTIFY:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302113 beiscsi_log(phba, KERN_ERR,
2114 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302115 "BM_%d : Dropping %s[%d] on DPDU ring on CID : %d\n",
2116 cqe_desc[code], code, cid);
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07002117 spin_lock_bh(&phba->async_pdu_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302118 hwi_flush_default_pdu_buffer(phba, beiscsi_conn,
2119 (struct i_t_dpdu_cqe *) sol);
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07002120 spin_unlock_bh(&phba->async_pdu_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302121 break;
2122 case CXN_KILLED_PDU_SIZE_EXCEEDS_DSL:
2123 case CXN_KILLED_BURST_LEN_MISMATCH:
2124 case CXN_KILLED_AHS_RCVD:
2125 case CXN_KILLED_HDR_DIGEST_ERR:
2126 case CXN_KILLED_UNKNOWN_HDR:
2127 case CXN_KILLED_STALE_ITT_TTT_RCVD:
2128 case CXN_KILLED_INVALID_ITT_TTT_RCVD:
2129 case CXN_KILLED_TIMED_OUT:
2130 case CXN_KILLED_FIN_RCVD:
John Soni Jose6763daa2012-10-20 04:41:45 +05302131 case CXN_KILLED_RST_SENT:
2132 case CXN_KILLED_RST_RCVD:
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302133 case CXN_KILLED_BAD_UNSOL_PDU_RCVD:
2134 case CXN_KILLED_BAD_WRB_INDEX_ERROR:
2135 case CXN_KILLED_OVER_RUN_RESIDUAL:
2136 case CXN_KILLED_UNDER_RUN_RESIDUAL:
2137 case CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302138 beiscsi_log(phba, KERN_ERR,
2139 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302140 "BM_%d : Event %s[%d] received on CID : %d\n",
2141 cqe_desc[code], code, cid);
John Soni Jose0a513dd2012-08-20 23:00:55 +05302142 if (beiscsi_conn)
2143 iscsi_conn_failure(beiscsi_conn->conn,
2144 ISCSI_ERR_CONN_FAILED);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302145 break;
2146 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302147 beiscsi_log(phba, KERN_ERR,
2148 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302149 "BM_%d : Invalid CQE Event Received Code : %d"
2150 "CID 0x%x...\n",
John Soni Jose0a513dd2012-08-20 23:00:55 +05302151 code, cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302152 break;
2153 }
2154
2155 AMAP_SET_BITS(struct amap_sol_cqe, valid, sol, 0);
2156 queue_tail_inc(cq);
2157 sol = queue_tail_node(cq);
2158 num_processed++;
2159 }
2160
2161 if (num_processed > 0) {
2162 tot_nump += num_processed;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302163 hwi_ring_cq_db(phba, cq->id, num_processed, 1, 0);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302164 }
2165 return tot_nump;
2166}
2167
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05302168void beiscsi_process_all_cqs(struct work_struct *work)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302169{
2170 unsigned long flags;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302171 struct hwi_controller *phwi_ctrlr;
2172 struct hwi_context_memory *phwi_context;
John Soni Jose72fb46a2012-10-20 04:42:49 +05302173 struct beiscsi_hba *phba;
2174 struct be_eq_obj *pbe_eq =
2175 container_of(work, struct be_eq_obj, work_cqs);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302176
John Soni Jose72fb46a2012-10-20 04:42:49 +05302177 phba = pbe_eq->phba;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302178 phwi_ctrlr = phba->phwi_ctrlr;
2179 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302180
John Soni Jose72fb46a2012-10-20 04:42:49 +05302181 if (pbe_eq->todo_mcc_cq) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302182 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +05302183 pbe_eq->todo_mcc_cq = false;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302184 spin_unlock_irqrestore(&phba->isr_lock, flags);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05302185 beiscsi_process_mcc_isr(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302186 }
2187
John Soni Jose72fb46a2012-10-20 04:42:49 +05302188 if (pbe_eq->todo_cq) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302189 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +05302190 pbe_eq->todo_cq = false;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302191 spin_unlock_irqrestore(&phba->isr_lock, flags);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302192 beiscsi_process_cq(pbe_eq);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302193 }
John Soni Jose72fb46a2012-10-20 04:42:49 +05302194
2195 /* rearm EQ for further interrupts */
2196 hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302197}
2198
2199static int be_iopoll(struct blk_iopoll *iop, int budget)
2200{
Shlomo Pongratzad3f4282013-04-05 20:38:36 -07002201 unsigned int ret;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302202 struct beiscsi_hba *phba;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302203 struct be_eq_obj *pbe_eq;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302204
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302205 pbe_eq = container_of(iop, struct be_eq_obj, iopoll);
2206 ret = beiscsi_process_cq(pbe_eq);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302207 if (ret < budget) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302208 phba = pbe_eq->phba;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302209 blk_iopoll_complete(iop);
John Soni Jose99bc5d52012-08-20 23:00:18 +05302210 beiscsi_log(phba, KERN_INFO,
2211 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
2212 "BM_%d : rearm pbe_eq->q.id =%d\n",
2213 pbe_eq->q.id);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302214 hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302215 }
2216 return ret;
2217}
2218
2219static void
John Soni Jose09a10932012-10-20 04:44:23 +05302220hwi_write_sgl_v2(struct iscsi_wrb *pwrb, struct scatterlist *sg,
2221 unsigned int num_sg, struct beiscsi_io_task *io_task)
2222{
2223 struct iscsi_sge *psgl;
2224 unsigned int sg_len, index;
2225 unsigned int sge_len = 0;
2226 unsigned long long addr;
2227 struct scatterlist *l_sg;
2228 unsigned int offset;
2229
2230 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_lo, pwrb,
2231 io_task->bhs_pa.u.a32.address_lo);
2232 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_hi, pwrb,
2233 io_task->bhs_pa.u.a32.address_hi);
2234
2235 l_sg = sg;
2236 for (index = 0; (index < num_sg) && (index < 2); index++,
2237 sg = sg_next(sg)) {
2238 if (index == 0) {
2239 sg_len = sg_dma_len(sg);
2240 addr = (u64) sg_dma_address(sg);
2241 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2242 sge0_addr_lo, pwrb,
2243 lower_32_bits(addr));
2244 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2245 sge0_addr_hi, pwrb,
2246 upper_32_bits(addr));
2247 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2248 sge0_len, pwrb,
2249 sg_len);
2250 sge_len = sg_len;
2251 } else {
2252 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_r2t_offset,
2253 pwrb, sge_len);
2254 sg_len = sg_dma_len(sg);
2255 addr = (u64) sg_dma_address(sg);
2256 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2257 sge1_addr_lo, pwrb,
2258 lower_32_bits(addr));
2259 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2260 sge1_addr_hi, pwrb,
2261 upper_32_bits(addr));
2262 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2263 sge1_len, pwrb,
2264 sg_len);
2265 }
2266 }
2267 psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
2268 memset(psgl, 0, sizeof(*psgl) * BE2_SGE);
2269
2270 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2);
2271
2272 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2273 io_task->bhs_pa.u.a32.address_hi);
2274 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2275 io_task->bhs_pa.u.a32.address_lo);
2276
2277 if (num_sg == 1) {
2278 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb,
2279 1);
2280 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb,
2281 0);
2282 } else if (num_sg == 2) {
2283 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb,
2284 0);
2285 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb,
2286 1);
2287 } else {
2288 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb,
2289 0);
2290 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb,
2291 0);
2292 }
2293
2294 sg = l_sg;
2295 psgl++;
2296 psgl++;
2297 offset = 0;
2298 for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) {
2299 sg_len = sg_dma_len(sg);
2300 addr = (u64) sg_dma_address(sg);
2301 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2302 lower_32_bits(addr));
2303 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2304 upper_32_bits(addr));
2305 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len);
2306 AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset);
2307 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
2308 offset += sg_len;
2309 }
2310 psgl--;
2311 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
2312}
2313
2314static void
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302315hwi_write_sgl(struct iscsi_wrb *pwrb, struct scatterlist *sg,
2316 unsigned int num_sg, struct beiscsi_io_task *io_task)
2317{
2318 struct iscsi_sge *psgl;
Jayamohan Kallickal58ff4bd2010-10-06 23:46:47 +05302319 unsigned int sg_len, index;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302320 unsigned int sge_len = 0;
2321 unsigned long long addr;
2322 struct scatterlist *l_sg;
2323 unsigned int offset;
2324
2325 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
2326 io_task->bhs_pa.u.a32.address_lo);
2327 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
2328 io_task->bhs_pa.u.a32.address_hi);
2329
2330 l_sg = sg;
Jayamohan Kallickal48bd86c2010-01-07 01:50:19 +05302331 for (index = 0; (index < num_sg) && (index < 2); index++,
2332 sg = sg_next(sg)) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302333 if (index == 0) {
2334 sg_len = sg_dma_len(sg);
2335 addr = (u64) sg_dma_address(sg);
2336 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302337 ((u32)(addr & 0xFFFFFFFF)));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302338 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302339 ((u32)(addr >> 32)));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302340 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
2341 sg_len);
2342 sge_len = sg_len;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302343 } else {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302344 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_r2t_offset,
2345 pwrb, sge_len);
2346 sg_len = sg_dma_len(sg);
2347 addr = (u64) sg_dma_address(sg);
2348 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_lo, pwrb,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302349 ((u32)(addr & 0xFFFFFFFF)));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302350 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_hi, pwrb,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302351 ((u32)(addr >> 32)));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302352 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_len, pwrb,
2353 sg_len);
2354 }
2355 }
2356 psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
2357 memset(psgl, 0, sizeof(*psgl) * BE2_SGE);
2358
2359 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2);
2360
2361 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2362 io_task->bhs_pa.u.a32.address_hi);
2363 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2364 io_task->bhs_pa.u.a32.address_lo);
2365
Jayamohan Kallickalcaf818f2010-01-23 05:38:18 +05302366 if (num_sg == 1) {
2367 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
2368 1);
2369 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
2370 0);
2371 } else if (num_sg == 2) {
2372 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
2373 0);
2374 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
2375 1);
2376 } else {
2377 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
2378 0);
2379 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
2380 0);
2381 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302382 sg = l_sg;
2383 psgl++;
2384 psgl++;
2385 offset = 0;
Jayamohan Kallickal48bd86c2010-01-07 01:50:19 +05302386 for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302387 sg_len = sg_dma_len(sg);
2388 addr = (u64) sg_dma_address(sg);
2389 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2390 (addr & 0xFFFFFFFF));
2391 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2392 (addr >> 32));
2393 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len);
2394 AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset);
2395 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
2396 offset += sg_len;
2397 }
2398 psgl--;
2399 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
2400}
2401
John Soni Josed629c472012-10-20 04:42:00 +05302402/**
2403 * hwi_write_buffer()- Populate the WRB with task info
2404 * @pwrb: ptr to the WRB entry
2405 * @task: iscsi task which is to be executed
2406 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302407static void hwi_write_buffer(struct iscsi_wrb *pwrb, struct iscsi_task *task)
2408{
2409 struct iscsi_sge *psgl;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302410 struct beiscsi_io_task *io_task = task->dd_data;
2411 struct beiscsi_conn *beiscsi_conn = io_task->conn;
2412 struct beiscsi_hba *phba = beiscsi_conn->phba;
John Soni Jose09a10932012-10-20 04:44:23 +05302413 uint8_t dsp_value = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302414
2415 io_task->bhs_len = sizeof(struct be_nonio_bhs) - 2;
2416 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
2417 io_task->bhs_pa.u.a32.address_lo);
2418 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
2419 io_task->bhs_pa.u.a32.address_hi);
2420
2421 if (task->data) {
John Soni Jose09a10932012-10-20 04:44:23 +05302422
2423 /* Check for the data_count */
2424 dsp_value = (task->data_count) ? 1 : 0;
2425
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07002426 if (is_chip_be2_be3r(phba))
2427 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp,
John Soni Jose09a10932012-10-20 04:44:23 +05302428 pwrb, dsp_value);
2429 else
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07002430 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp,
John Soni Jose09a10932012-10-20 04:44:23 +05302431 pwrb, dsp_value);
2432
2433 /* Map addr only if there is data_count */
2434 if (dsp_value) {
John Soni Josed629c472012-10-20 04:42:00 +05302435 io_task->mtask_addr = pci_map_single(phba->pcidev,
2436 task->data,
2437 task->data_count,
2438 PCI_DMA_TODEVICE);
John Soni Josed629c472012-10-20 04:42:00 +05302439 io_task->mtask_data_count = task->data_count;
John Soni Jose09a10932012-10-20 04:44:23 +05302440 } else
John Soni Josed629c472012-10-20 04:42:00 +05302441 io_task->mtask_addr = 0;
John Soni Jose09a10932012-10-20 04:44:23 +05302442
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302443 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
John Soni Josed629c472012-10-20 04:42:00 +05302444 lower_32_bits(io_task->mtask_addr));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302445 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
John Soni Josed629c472012-10-20 04:42:00 +05302446 upper_32_bits(io_task->mtask_addr));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302447 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
2448 task->data_count);
2449
2450 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, 1);
2451 } else {
2452 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
John Soni Josed629c472012-10-20 04:42:00 +05302453 io_task->mtask_addr = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302454 }
2455
2456 psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
2457
2458 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len);
2459
2460 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2461 io_task->bhs_pa.u.a32.address_hi);
2462 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2463 io_task->bhs_pa.u.a32.address_lo);
2464 if (task->data) {
2465 psgl++;
2466 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, 0);
2467 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, 0);
2468 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0);
2469 AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, 0);
2470 AMAP_SET_BITS(struct amap_iscsi_sge, rsvd0, psgl, 0);
2471 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
2472
2473 psgl++;
2474 if (task->data) {
2475 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
John Soni Josed629c472012-10-20 04:42:00 +05302476 lower_32_bits(io_task->mtask_addr));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302477 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
John Soni Josed629c472012-10-20 04:42:00 +05302478 upper_32_bits(io_task->mtask_addr));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302479 }
2480 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0x106);
2481 }
2482 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
2483}
2484
2485static void beiscsi_find_mem_req(struct beiscsi_hba *phba)
2486{
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302487 unsigned int num_cq_pages, num_async_pdu_buf_pages;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302488 unsigned int num_async_pdu_data_pages, wrb_sz_per_cxn;
2489 unsigned int num_async_pdu_buf_sgl_pages, num_async_pdu_data_sgl_pages;
2490
2491 num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
2492 sizeof(struct sol_cqe));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302493 num_async_pdu_buf_pages =
2494 PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
2495 phba->params.defpdu_hdr_sz);
2496 num_async_pdu_buf_sgl_pages =
2497 PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
2498 sizeof(struct phys_addr));
2499 num_async_pdu_data_pages =
2500 PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
2501 phba->params.defpdu_data_sz);
2502 num_async_pdu_data_sgl_pages =
2503 PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
2504 sizeof(struct phys_addr));
2505
2506 phba->params.hwi_ws_sz = sizeof(struct hwi_controller);
2507
2508 phba->mem_req[ISCSI_MEM_GLOBAL_HEADER] = 2 *
2509 BE_ISCSI_PDU_HEADER_SIZE;
2510 phba->mem_req[HWI_MEM_ADDN_CONTEXT] =
2511 sizeof(struct hwi_context_memory);
2512
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302513
2514 phba->mem_req[HWI_MEM_WRB] = sizeof(struct iscsi_wrb)
2515 * (phba->params.wrbs_per_cxn)
2516 * phba->params.cxns_per_ctrl;
2517 wrb_sz_per_cxn = sizeof(struct wrb_handle) *
2518 (phba->params.wrbs_per_cxn);
2519 phba->mem_req[HWI_MEM_WRBH] = roundup_pow_of_two((wrb_sz_per_cxn) *
2520 phba->params.cxns_per_ctrl);
2521
2522 phba->mem_req[HWI_MEM_SGLH] = sizeof(struct sgl_handle) *
2523 phba->params.icds_per_ctrl;
2524 phba->mem_req[HWI_MEM_SGE] = sizeof(struct iscsi_sge) *
2525 phba->params.num_sge_per_io * phba->params.icds_per_ctrl;
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07002526 phba->mem_req[HWI_MEM_TEMPLATE_HDR] = phba->params.cxns_per_ctrl *
2527 BEISCSI_TEMPLATE_HDR_PER_CXN_SIZE;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302528
2529 phba->mem_req[HWI_MEM_ASYNC_HEADER_BUF] =
2530 num_async_pdu_buf_pages * PAGE_SIZE;
2531 phba->mem_req[HWI_MEM_ASYNC_DATA_BUF] =
2532 num_async_pdu_data_pages * PAGE_SIZE;
2533 phba->mem_req[HWI_MEM_ASYNC_HEADER_RING] =
2534 num_async_pdu_buf_sgl_pages * PAGE_SIZE;
2535 phba->mem_req[HWI_MEM_ASYNC_DATA_RING] =
2536 num_async_pdu_data_sgl_pages * PAGE_SIZE;
2537 phba->mem_req[HWI_MEM_ASYNC_HEADER_HANDLE] =
2538 phba->params.asyncpdus_per_ctrl *
2539 sizeof(struct async_pdu_handle);
2540 phba->mem_req[HWI_MEM_ASYNC_DATA_HANDLE] =
2541 phba->params.asyncpdus_per_ctrl *
2542 sizeof(struct async_pdu_handle);
2543 phba->mem_req[HWI_MEM_ASYNC_PDU_CONTEXT] =
2544 sizeof(struct hwi_async_pdu_context) +
2545 (phba->params.cxns_per_ctrl * sizeof(struct hwi_async_entry));
2546}
2547
2548static int beiscsi_alloc_mem(struct beiscsi_hba *phba)
2549{
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302550 dma_addr_t bus_add;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002551 struct hwi_controller *phwi_ctrlr;
2552 struct be_mem_descriptor *mem_descr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302553 struct mem_array *mem_arr, *mem_arr_orig;
2554 unsigned int i, j, alloc_size, curr_alloc_size;
2555
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002556 phba->phwi_ctrlr = kzalloc(phba->params.hwi_ws_sz, GFP_KERNEL);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302557 if (!phba->phwi_ctrlr)
2558 return -ENOMEM;
2559
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002560 /* Allocate memory for wrb_context */
2561 phwi_ctrlr = phba->phwi_ctrlr;
2562 phwi_ctrlr->wrb_context = kzalloc(sizeof(struct hwi_wrb_context) *
2563 phba->params.cxns_per_ctrl,
2564 GFP_KERNEL);
2565 if (!phwi_ctrlr->wrb_context)
2566 return -ENOMEM;
2567
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302568 phba->init_mem = kcalloc(SE_MEM_MAX, sizeof(*mem_descr),
2569 GFP_KERNEL);
2570 if (!phba->init_mem) {
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002571 kfree(phwi_ctrlr->wrb_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302572 kfree(phba->phwi_ctrlr);
2573 return -ENOMEM;
2574 }
2575
2576 mem_arr_orig = kmalloc(sizeof(*mem_arr_orig) * BEISCSI_MAX_FRAGS_INIT,
2577 GFP_KERNEL);
2578 if (!mem_arr_orig) {
2579 kfree(phba->init_mem);
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002580 kfree(phwi_ctrlr->wrb_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302581 kfree(phba->phwi_ctrlr);
2582 return -ENOMEM;
2583 }
2584
2585 mem_descr = phba->init_mem;
2586 for (i = 0; i < SE_MEM_MAX; i++) {
2587 j = 0;
2588 mem_arr = mem_arr_orig;
2589 alloc_size = phba->mem_req[i];
2590 memset(mem_arr, 0, sizeof(struct mem_array) *
2591 BEISCSI_MAX_FRAGS_INIT);
2592 curr_alloc_size = min(be_max_phys_size * 1024, alloc_size);
2593 do {
2594 mem_arr->virtual_address = pci_alloc_consistent(
2595 phba->pcidev,
2596 curr_alloc_size,
2597 &bus_add);
2598 if (!mem_arr->virtual_address) {
2599 if (curr_alloc_size <= BE_MIN_MEM_SIZE)
2600 goto free_mem;
2601 if (curr_alloc_size -
2602 rounddown_pow_of_two(curr_alloc_size))
2603 curr_alloc_size = rounddown_pow_of_two
2604 (curr_alloc_size);
2605 else
2606 curr_alloc_size = curr_alloc_size / 2;
2607 } else {
2608 mem_arr->bus_address.u.
2609 a64.address = (__u64) bus_add;
2610 mem_arr->size = curr_alloc_size;
2611 alloc_size -= curr_alloc_size;
2612 curr_alloc_size = min(be_max_phys_size *
2613 1024, alloc_size);
2614 j++;
2615 mem_arr++;
2616 }
2617 } while (alloc_size);
2618 mem_descr->num_elements = j;
2619 mem_descr->size_in_bytes = phba->mem_req[i];
2620 mem_descr->mem_array = kmalloc(sizeof(*mem_arr) * j,
2621 GFP_KERNEL);
2622 if (!mem_descr->mem_array)
2623 goto free_mem;
2624
2625 memcpy(mem_descr->mem_array, mem_arr_orig,
2626 sizeof(struct mem_array) * j);
2627 mem_descr++;
2628 }
2629 kfree(mem_arr_orig);
2630 return 0;
2631free_mem:
2632 mem_descr->num_elements = j;
2633 while ((i) || (j)) {
2634 for (j = mem_descr->num_elements; j > 0; j--) {
2635 pci_free_consistent(phba->pcidev,
2636 mem_descr->mem_array[j - 1].size,
2637 mem_descr->mem_array[j - 1].
2638 virtual_address,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302639 (unsigned long)mem_descr->
2640 mem_array[j - 1].
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302641 bus_address.u.a64.address);
2642 }
2643 if (i) {
2644 i--;
2645 kfree(mem_descr->mem_array);
2646 mem_descr--;
2647 }
2648 }
2649 kfree(mem_arr_orig);
2650 kfree(phba->init_mem);
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002651 kfree(phba->phwi_ctrlr->wrb_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302652 kfree(phba->phwi_ctrlr);
2653 return -ENOMEM;
2654}
2655
2656static int beiscsi_get_memory(struct beiscsi_hba *phba)
2657{
2658 beiscsi_find_mem_req(phba);
2659 return beiscsi_alloc_mem(phba);
2660}
2661
2662static void iscsi_init_global_templates(struct beiscsi_hba *phba)
2663{
2664 struct pdu_data_out *pdata_out;
2665 struct pdu_nop_out *pnop_out;
2666 struct be_mem_descriptor *mem_descr;
2667
2668 mem_descr = phba->init_mem;
2669 mem_descr += ISCSI_MEM_GLOBAL_HEADER;
2670 pdata_out =
2671 (struct pdu_data_out *)mem_descr->mem_array[0].virtual_address;
2672 memset(pdata_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
2673
2674 AMAP_SET_BITS(struct amap_pdu_data_out, opcode, pdata_out,
2675 IIOC_SCSI_DATA);
2676
2677 pnop_out =
2678 (struct pdu_nop_out *)((unsigned char *)mem_descr->mem_array[0].
2679 virtual_address + BE_ISCSI_PDU_HEADER_SIZE);
2680
2681 memset(pnop_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
2682 AMAP_SET_BITS(struct amap_pdu_nop_out, ttt, pnop_out, 0xFFFFFFFF);
2683 AMAP_SET_BITS(struct amap_pdu_nop_out, f_bit, pnop_out, 1);
2684 AMAP_SET_BITS(struct amap_pdu_nop_out, i_bit, pnop_out, 0);
2685}
2686
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002687static int beiscsi_init_wrb_handle(struct beiscsi_hba *phba)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302688{
2689 struct be_mem_descriptor *mem_descr_wrbh, *mem_descr_wrb;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002690 struct hwi_context_memory *phwi_ctxt;
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002691 struct wrb_handle *pwrb_handle = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302692 struct hwi_controller *phwi_ctrlr;
2693 struct hwi_wrb_context *pwrb_context;
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002694 struct iscsi_wrb *pwrb = NULL;
2695 unsigned int num_cxn_wrbh = 0;
2696 unsigned int num_cxn_wrb = 0, j, idx = 0, index;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302697
2698 mem_descr_wrbh = phba->init_mem;
2699 mem_descr_wrbh += HWI_MEM_WRBH;
2700
2701 mem_descr_wrb = phba->init_mem;
2702 mem_descr_wrb += HWI_MEM_WRB;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302703 phwi_ctrlr = phba->phwi_ctrlr;
2704
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002705 /* Allocate memory for WRBQ */
2706 phwi_ctxt = phwi_ctrlr->phwi_ctxt;
2707 phwi_ctxt->be_wrbq = kzalloc(sizeof(struct be_queue_info) *
2708 phba->fw_config.iscsi_cid_count,
2709 GFP_KERNEL);
2710 if (!phwi_ctxt->be_wrbq) {
2711 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2712 "BM_%d : WRBQ Mem Alloc Failed\n");
2713 return -ENOMEM;
2714 }
2715
2716 for (index = 0; index < phba->params.cxns_per_ctrl; index++) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302717 pwrb_context = &phwi_ctrlr->wrb_context[index];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302718 pwrb_context->pwrb_handle_base =
2719 kzalloc(sizeof(struct wrb_handle *) *
2720 phba->params.wrbs_per_cxn, GFP_KERNEL);
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002721 if (!pwrb_context->pwrb_handle_base) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05302722 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2723 "BM_%d : Mem Alloc Failed. Failing to load\n");
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002724 goto init_wrb_hndl_failed;
2725 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302726 pwrb_context->pwrb_handle_basestd =
2727 kzalloc(sizeof(struct wrb_handle *) *
2728 phba->params.wrbs_per_cxn, GFP_KERNEL);
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002729 if (!pwrb_context->pwrb_handle_basestd) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05302730 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2731 "BM_%d : Mem Alloc Failed. Failing to load\n");
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002732 goto init_wrb_hndl_failed;
2733 }
2734 if (!num_cxn_wrbh) {
2735 pwrb_handle =
2736 mem_descr_wrbh->mem_array[idx].virtual_address;
2737 num_cxn_wrbh = ((mem_descr_wrbh->mem_array[idx].size) /
2738 ((sizeof(struct wrb_handle)) *
2739 phba->params.wrbs_per_cxn));
2740 idx++;
2741 }
2742 pwrb_context->alloc_index = 0;
2743 pwrb_context->wrb_handles_available = 0;
2744 pwrb_context->free_index = 0;
2745
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302746 if (num_cxn_wrbh) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302747 for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
2748 pwrb_context->pwrb_handle_base[j] = pwrb_handle;
2749 pwrb_context->pwrb_handle_basestd[j] =
2750 pwrb_handle;
2751 pwrb_context->wrb_handles_available++;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302752 pwrb_handle->wrb_index = j;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302753 pwrb_handle++;
2754 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302755 num_cxn_wrbh--;
2756 }
2757 }
2758 idx = 0;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002759 for (index = 0; index < phba->params.cxns_per_ctrl; index++) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302760 pwrb_context = &phwi_ctrlr->wrb_context[index];
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002761 if (!num_cxn_wrb) {
2762 pwrb = mem_descr_wrb->mem_array[idx].virtual_address;
2763 num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) /
2764 ((sizeof(struct iscsi_wrb) *
2765 phba->params.wrbs_per_cxn));
2766 idx++;
2767 }
2768
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302769 if (num_cxn_wrb) {
2770 for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
2771 pwrb_handle = pwrb_context->pwrb_handle_base[j];
2772 pwrb_handle->pwrb = pwrb;
2773 pwrb++;
2774 }
2775 num_cxn_wrb--;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302776 }
2777 }
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002778 return 0;
2779init_wrb_hndl_failed:
2780 for (j = index; j > 0; j--) {
2781 pwrb_context = &phwi_ctrlr->wrb_context[j];
2782 kfree(pwrb_context->pwrb_handle_base);
2783 kfree(pwrb_context->pwrb_handle_basestd);
2784 }
2785 return -ENOMEM;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302786}
2787
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002788static int hwi_init_async_pdu_ctx(struct beiscsi_hba *phba)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302789{
2790 struct hwi_controller *phwi_ctrlr;
2791 struct hba_parameters *p = &phba->params;
2792 struct hwi_async_pdu_context *pasync_ctx;
2793 struct async_pdu_handle *pasync_header_h, *pasync_data_h;
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05002794 unsigned int index, idx, num_per_mem, num_async_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302795 struct be_mem_descriptor *mem_descr;
2796
2797 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2798 mem_descr += HWI_MEM_ASYNC_PDU_CONTEXT;
2799
2800 phwi_ctrlr = phba->phwi_ctrlr;
2801 phwi_ctrlr->phwi_ctxt->pasync_ctx = (struct hwi_async_pdu_context *)
2802 mem_descr->mem_array[0].virtual_address;
2803 pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx;
2804 memset(pasync_ctx, 0, sizeof(*pasync_ctx));
2805
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002806 pasync_ctx->async_entry = kzalloc(sizeof(struct hwi_async_entry) *
2807 phba->fw_config.iscsi_cid_count,
2808 GFP_KERNEL);
2809 if (!pasync_ctx->async_entry) {
2810 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2811 "BM_%d : hwi_init_async_pdu_ctx Mem Alloc Failed\n");
2812 return -ENOMEM;
2813 }
2814
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05002815 pasync_ctx->num_entries = p->asyncpdus_per_ctrl;
2816 pasync_ctx->buffer_size = p->defpdu_hdr_sz;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302817
2818 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2819 mem_descr += HWI_MEM_ASYNC_HEADER_BUF;
2820 if (mem_descr->mem_array[0].virtual_address) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05302821 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2822 "BM_%d : hwi_init_async_pdu_ctx"
2823 " HWI_MEM_ASYNC_HEADER_BUF va=%p\n",
2824 mem_descr->mem_array[0].virtual_address);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302825 } else
John Soni Jose99bc5d52012-08-20 23:00:18 +05302826 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
2827 "BM_%d : No Virtual address\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302828
2829 pasync_ctx->async_header.va_base =
2830 mem_descr->mem_array[0].virtual_address;
2831
2832 pasync_ctx->async_header.pa_base.u.a64.address =
2833 mem_descr->mem_array[0].bus_address.u.a64.address;
2834
2835 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2836 mem_descr += HWI_MEM_ASYNC_HEADER_RING;
2837 if (mem_descr->mem_array[0].virtual_address) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05302838 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2839 "BM_%d : hwi_init_async_pdu_ctx"
2840 " HWI_MEM_ASYNC_HEADER_RING va=%p\n",
2841 mem_descr->mem_array[0].virtual_address);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302842 } else
John Soni Jose99bc5d52012-08-20 23:00:18 +05302843 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
2844 "BM_%d : No Virtual address\n");
2845
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302846 pasync_ctx->async_header.ring_base =
2847 mem_descr->mem_array[0].virtual_address;
2848
2849 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2850 mem_descr += HWI_MEM_ASYNC_HEADER_HANDLE;
2851 if (mem_descr->mem_array[0].virtual_address) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05302852 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2853 "BM_%d : hwi_init_async_pdu_ctx"
2854 " HWI_MEM_ASYNC_HEADER_HANDLE va=%p\n",
2855 mem_descr->mem_array[0].virtual_address);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302856 } else
John Soni Jose99bc5d52012-08-20 23:00:18 +05302857 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
2858 "BM_%d : No Virtual address\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302859
2860 pasync_ctx->async_header.handle_base =
2861 mem_descr->mem_array[0].virtual_address;
2862 pasync_ctx->async_header.writables = 0;
2863 INIT_LIST_HEAD(&pasync_ctx->async_header.free_list);
2864
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302865
2866 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2867 mem_descr += HWI_MEM_ASYNC_DATA_RING;
2868 if (mem_descr->mem_array[0].virtual_address) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05302869 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2870 "BM_%d : hwi_init_async_pdu_ctx"
2871 " HWI_MEM_ASYNC_DATA_RING va=%p\n",
2872 mem_descr->mem_array[0].virtual_address);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302873 } else
John Soni Jose99bc5d52012-08-20 23:00:18 +05302874 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
2875 "BM_%d : No Virtual address\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302876
2877 pasync_ctx->async_data.ring_base =
2878 mem_descr->mem_array[0].virtual_address;
2879
2880 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2881 mem_descr += HWI_MEM_ASYNC_DATA_HANDLE;
2882 if (!mem_descr->mem_array[0].virtual_address)
John Soni Jose99bc5d52012-08-20 23:00:18 +05302883 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
2884 "BM_%d : No Virtual address\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302885
2886 pasync_ctx->async_data.handle_base =
2887 mem_descr->mem_array[0].virtual_address;
2888 pasync_ctx->async_data.writables = 0;
2889 INIT_LIST_HEAD(&pasync_ctx->async_data.free_list);
2890
2891 pasync_header_h =
2892 (struct async_pdu_handle *)pasync_ctx->async_header.handle_base;
2893 pasync_data_h =
2894 (struct async_pdu_handle *)pasync_ctx->async_data.handle_base;
2895
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05002896 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2897 mem_descr += HWI_MEM_ASYNC_DATA_BUF;
2898 if (mem_descr->mem_array[0].virtual_address) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05302899 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2900 "BM_%d : hwi_init_async_pdu_ctx"
2901 " HWI_MEM_ASYNC_DATA_BUF va=%p\n",
2902 mem_descr->mem_array[0].virtual_address);
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05002903 } else
John Soni Jose99bc5d52012-08-20 23:00:18 +05302904 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
2905 "BM_%d : No Virtual address\n");
2906
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05002907 idx = 0;
2908 pasync_ctx->async_data.va_base =
2909 mem_descr->mem_array[idx].virtual_address;
2910 pasync_ctx->async_data.pa_base.u.a64.address =
2911 mem_descr->mem_array[idx].bus_address.u.a64.address;
2912
2913 num_async_data = ((mem_descr->mem_array[idx].size) /
2914 phba->params.defpdu_data_sz);
2915 num_per_mem = 0;
2916
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302917 for (index = 0; index < p->asyncpdus_per_ctrl; index++) {
2918 pasync_header_h->cri = -1;
2919 pasync_header_h->index = (char)index;
2920 INIT_LIST_HEAD(&pasync_header_h->link);
2921 pasync_header_h->pbuffer =
2922 (void *)((unsigned long)
2923 (pasync_ctx->async_header.va_base) +
2924 (p->defpdu_hdr_sz * index));
2925
2926 pasync_header_h->pa.u.a64.address =
2927 pasync_ctx->async_header.pa_base.u.a64.address +
2928 (p->defpdu_hdr_sz * index);
2929
2930 list_add_tail(&pasync_header_h->link,
2931 &pasync_ctx->async_header.free_list);
2932 pasync_header_h++;
2933 pasync_ctx->async_header.free_entries++;
2934 pasync_ctx->async_header.writables++;
2935
2936 INIT_LIST_HEAD(&pasync_ctx->async_entry[index].wait_queue.list);
2937 INIT_LIST_HEAD(&pasync_ctx->async_entry[index].
2938 header_busy_list);
2939 pasync_data_h->cri = -1;
2940 pasync_data_h->index = (char)index;
2941 INIT_LIST_HEAD(&pasync_data_h->link);
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05002942
2943 if (!num_async_data) {
2944 num_per_mem = 0;
2945 idx++;
2946 pasync_ctx->async_data.va_base =
2947 mem_descr->mem_array[idx].virtual_address;
2948 pasync_ctx->async_data.pa_base.u.a64.address =
2949 mem_descr->mem_array[idx].
2950 bus_address.u.a64.address;
2951
2952 num_async_data = ((mem_descr->mem_array[idx].size) /
2953 phba->params.defpdu_data_sz);
2954 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302955 pasync_data_h->pbuffer =
2956 (void *)((unsigned long)
2957 (pasync_ctx->async_data.va_base) +
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05002958 (p->defpdu_data_sz * num_per_mem));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302959
2960 pasync_data_h->pa.u.a64.address =
2961 pasync_ctx->async_data.pa_base.u.a64.address +
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05002962 (p->defpdu_data_sz * num_per_mem);
2963 num_per_mem++;
2964 num_async_data--;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302965
2966 list_add_tail(&pasync_data_h->link,
2967 &pasync_ctx->async_data.free_list);
2968 pasync_data_h++;
2969 pasync_ctx->async_data.free_entries++;
2970 pasync_ctx->async_data.writables++;
2971
2972 INIT_LIST_HEAD(&pasync_ctx->async_entry[index].data_busy_list);
2973 }
2974
2975 pasync_ctx->async_header.host_write_ptr = 0;
2976 pasync_ctx->async_header.ep_read_ptr = -1;
2977 pasync_ctx->async_data.host_write_ptr = 0;
2978 pasync_ctx->async_data.ep_read_ptr = -1;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002979
2980 return 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302981}
2982
2983static int
2984be_sgl_create_contiguous(void *virtual_address,
2985 u64 physical_address, u32 length,
2986 struct be_dma_mem *sgl)
2987{
2988 WARN_ON(!virtual_address);
2989 WARN_ON(!physical_address);
2990 WARN_ON(!length > 0);
2991 WARN_ON(!sgl);
2992
2993 sgl->va = virtual_address;
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302994 sgl->dma = (unsigned long)physical_address;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302995 sgl->size = length;
2996
2997 return 0;
2998}
2999
3000static void be_sgl_destroy_contiguous(struct be_dma_mem *sgl)
3001{
3002 memset(sgl, 0, sizeof(*sgl));
3003}
3004
3005static void
3006hwi_build_be_sgl_arr(struct beiscsi_hba *phba,
3007 struct mem_array *pmem, struct be_dma_mem *sgl)
3008{
3009 if (sgl->va)
3010 be_sgl_destroy_contiguous(sgl);
3011
3012 be_sgl_create_contiguous(pmem->virtual_address,
3013 pmem->bus_address.u.a64.address,
3014 pmem->size, sgl);
3015}
3016
3017static void
3018hwi_build_be_sgl_by_offset(struct beiscsi_hba *phba,
3019 struct mem_array *pmem, struct be_dma_mem *sgl)
3020{
3021 if (sgl->va)
3022 be_sgl_destroy_contiguous(sgl);
3023
3024 be_sgl_create_contiguous((unsigned char *)pmem->virtual_address,
3025 pmem->bus_address.u.a64.address,
3026 pmem->size, sgl);
3027}
3028
3029static int be_fill_queue(struct be_queue_info *q,
3030 u16 len, u16 entry_size, void *vaddress)
3031{
3032 struct be_dma_mem *mem = &q->dma_mem;
3033
3034 memset(q, 0, sizeof(*q));
3035 q->len = len;
3036 q->entry_size = entry_size;
3037 mem->size = len * entry_size;
3038 mem->va = vaddress;
3039 if (!mem->va)
3040 return -ENOMEM;
3041 memset(mem->va, 0, mem->size);
3042 return 0;
3043}
3044
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303045static int beiscsi_create_eqs(struct beiscsi_hba *phba,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303046 struct hwi_context_memory *phwi_context)
3047{
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303048 unsigned int i, num_eq_pages;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303049 int ret = 0, eq_for_mcc;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303050 struct be_queue_info *eq;
3051 struct be_dma_mem *mem;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303052 void *eq_vaddress;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303053 dma_addr_t paddr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303054
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303055 num_eq_pages = PAGES_REQUIRED(phba->params.num_eq_entries * \
3056 sizeof(struct be_eq_entry));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303057
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303058 if (phba->msix_enabled)
3059 eq_for_mcc = 1;
3060 else
3061 eq_for_mcc = 0;
3062 for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
3063 eq = &phwi_context->be_eq[i].q;
3064 mem = &eq->dma_mem;
3065 phwi_context->be_eq[i].phba = phba;
3066 eq_vaddress = pci_alloc_consistent(phba->pcidev,
3067 num_eq_pages * PAGE_SIZE,
3068 &paddr);
3069 if (!eq_vaddress)
3070 goto create_eq_error;
3071
3072 mem->va = eq_vaddress;
3073 ret = be_fill_queue(eq, phba->params.num_eq_entries,
3074 sizeof(struct be_eq_entry), eq_vaddress);
3075 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303076 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3077 "BM_%d : be_fill_queue Failed for EQ\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303078 goto create_eq_error;
3079 }
3080
3081 mem->dma = paddr;
3082 ret = beiscsi_cmd_eq_create(&phba->ctrl, eq,
3083 phwi_context->cur_eqd);
3084 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303085 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3086 "BM_%d : beiscsi_cmd_eq_create"
3087 "Failed for EQ\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303088 goto create_eq_error;
3089 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05303090
3091 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3092 "BM_%d : eqid = %d\n",
3093 phwi_context->be_eq[i].q.id);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303094 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303095 return 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303096create_eq_error:
John Soni Jose107dfcb2012-10-20 04:42:13 +05303097 for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303098 eq = &phwi_context->be_eq[i].q;
3099 mem = &eq->dma_mem;
3100 if (mem->va)
3101 pci_free_consistent(phba->pcidev, num_eq_pages
3102 * PAGE_SIZE,
3103 mem->va, mem->dma);
3104 }
3105 return ret;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303106}
3107
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303108static int beiscsi_create_cqs(struct beiscsi_hba *phba,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303109 struct hwi_context_memory *phwi_context)
3110{
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303111 unsigned int i, num_cq_pages;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303112 int ret = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303113 struct be_queue_info *cq, *eq;
3114 struct be_dma_mem *mem;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303115 struct be_eq_obj *pbe_eq;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303116 void *cq_vaddress;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303117 dma_addr_t paddr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303118
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303119 num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
3120 sizeof(struct sol_cqe));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303121
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303122 for (i = 0; i < phba->num_cpus; i++) {
3123 cq = &phwi_context->be_cq[i];
3124 eq = &phwi_context->be_eq[i].q;
3125 pbe_eq = &phwi_context->be_eq[i];
3126 pbe_eq->cq = cq;
3127 pbe_eq->phba = phba;
3128 mem = &cq->dma_mem;
3129 cq_vaddress = pci_alloc_consistent(phba->pcidev,
3130 num_cq_pages * PAGE_SIZE,
3131 &paddr);
3132 if (!cq_vaddress)
3133 goto create_cq_error;
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05303134 ret = be_fill_queue(cq, phba->params.num_cq_entries,
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303135 sizeof(struct sol_cqe), cq_vaddress);
3136 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303137 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3138 "BM_%d : be_fill_queue Failed "
3139 "for ISCSI CQ\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303140 goto create_cq_error;
3141 }
3142
3143 mem->dma = paddr;
3144 ret = beiscsi_cmd_cq_create(&phba->ctrl, cq, eq, false,
3145 false, 0);
3146 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303147 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3148 "BM_%d : beiscsi_cmd_eq_create"
3149 "Failed for ISCSI CQ\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303150 goto create_cq_error;
3151 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05303152 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3153 "BM_%d : iscsi cq_id is %d for eq_id %d\n"
3154 "iSCSI CQ CREATED\n", cq->id, eq->id);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303155 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303156 return 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303157
3158create_cq_error:
3159 for (i = 0; i < phba->num_cpus; i++) {
3160 cq = &phwi_context->be_cq[i];
3161 mem = &cq->dma_mem;
3162 if (mem->va)
3163 pci_free_consistent(phba->pcidev, num_cq_pages
3164 * PAGE_SIZE,
3165 mem->va, mem->dma);
3166 }
3167 return ret;
3168
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303169}
3170
3171static int
3172beiscsi_create_def_hdr(struct beiscsi_hba *phba,
3173 struct hwi_context_memory *phwi_context,
3174 struct hwi_controller *phwi_ctrlr,
3175 unsigned int def_pdu_ring_sz)
3176{
3177 unsigned int idx;
3178 int ret;
3179 struct be_queue_info *dq, *cq;
3180 struct be_dma_mem *mem;
3181 struct be_mem_descriptor *mem_descr;
3182 void *dq_vaddress;
3183
3184 idx = 0;
3185 dq = &phwi_context->be_def_hdrq;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303186 cq = &phwi_context->be_cq[0];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303187 mem = &dq->dma_mem;
3188 mem_descr = phba->init_mem;
3189 mem_descr += HWI_MEM_ASYNC_HEADER_RING;
3190 dq_vaddress = mem_descr->mem_array[idx].virtual_address;
3191 ret = be_fill_queue(dq, mem_descr->mem_array[0].size /
3192 sizeof(struct phys_addr),
3193 sizeof(struct phys_addr), dq_vaddress);
3194 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303195 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3196 "BM_%d : be_fill_queue Failed for DEF PDU HDR\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303197 return ret;
3198 }
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05303199 mem->dma = (unsigned long)mem_descr->mem_array[idx].
3200 bus_address.u.a64.address;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303201 ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dq,
3202 def_pdu_ring_sz,
3203 phba->params.defpdu_hdr_sz);
3204 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303205 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3206 "BM_%d : be_cmd_create_default_pdu_queue Failed DEFHDR\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303207 return ret;
3208 }
3209 phwi_ctrlr->default_pdu_hdr.id = phwi_context->be_def_hdrq.id;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303210 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3211 "BM_%d : iscsi def pdu id is %d\n",
3212 phwi_context->be_def_hdrq.id);
3213
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303214 hwi_post_async_buffers(phba, 1);
3215 return 0;
3216}
3217
3218static int
3219beiscsi_create_def_data(struct beiscsi_hba *phba,
3220 struct hwi_context_memory *phwi_context,
3221 struct hwi_controller *phwi_ctrlr,
3222 unsigned int def_pdu_ring_sz)
3223{
3224 unsigned int idx;
3225 int ret;
3226 struct be_queue_info *dataq, *cq;
3227 struct be_dma_mem *mem;
3228 struct be_mem_descriptor *mem_descr;
3229 void *dq_vaddress;
3230
3231 idx = 0;
3232 dataq = &phwi_context->be_def_dataq;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303233 cq = &phwi_context->be_cq[0];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303234 mem = &dataq->dma_mem;
3235 mem_descr = phba->init_mem;
3236 mem_descr += HWI_MEM_ASYNC_DATA_RING;
3237 dq_vaddress = mem_descr->mem_array[idx].virtual_address;
3238 ret = be_fill_queue(dataq, mem_descr->mem_array[0].size /
3239 sizeof(struct phys_addr),
3240 sizeof(struct phys_addr), dq_vaddress);
3241 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303242 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3243 "BM_%d : be_fill_queue Failed for DEF PDU DATA\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303244 return ret;
3245 }
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05303246 mem->dma = (unsigned long)mem_descr->mem_array[idx].
3247 bus_address.u.a64.address;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303248 ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dataq,
3249 def_pdu_ring_sz,
3250 phba->params.defpdu_data_sz);
3251 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303252 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3253 "BM_%d be_cmd_create_default_pdu_queue"
3254 " Failed for DEF PDU DATA\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303255 return ret;
3256 }
3257 phwi_ctrlr->default_pdu_data.id = phwi_context->be_def_dataq.id;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303258 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3259 "BM_%d : iscsi def data id is %d\n",
3260 phwi_context->be_def_dataq.id);
3261
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303262 hwi_post_async_buffers(phba, 0);
John Soni Jose99bc5d52012-08-20 23:00:18 +05303263 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3264 "BM_%d : DEFAULT PDU DATA RING CREATED\n");
3265
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303266 return 0;
3267}
3268
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07003269
3270static int
3271beiscsi_post_template_hdr(struct beiscsi_hba *phba)
3272{
3273 struct be_mem_descriptor *mem_descr;
3274 struct mem_array *pm_arr;
3275 struct be_dma_mem sgl;
3276 int status, i;
3277
3278 mem_descr = phba->init_mem;
3279 mem_descr += HWI_MEM_TEMPLATE_HDR;
3280 pm_arr = mem_descr->mem_array;
3281
3282 for (i = 0; i < mem_descr->num_elements; i++) {
3283 hwi_build_be_sgl_arr(phba, pm_arr, &sgl);
3284 status = be_cmd_iscsi_post_template_hdr(&phba->ctrl, &sgl);
3285
3286 if (status != 0) {
3287 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3288 "BM_%d : Post Template HDR Failed\n");
3289 return status;
3290 }
3291 }
3292
3293 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3294 "BM_%d : Template HDR Pages Posted\n");
3295
3296 return 0;
3297}
3298
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303299static int
3300beiscsi_post_pages(struct beiscsi_hba *phba)
3301{
3302 struct be_mem_descriptor *mem_descr;
3303 struct mem_array *pm_arr;
3304 unsigned int page_offset, i;
3305 struct be_dma_mem sgl;
3306 int status;
3307
3308 mem_descr = phba->init_mem;
3309 mem_descr += HWI_MEM_SGE;
3310 pm_arr = mem_descr->mem_array;
3311
3312 page_offset = (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io *
3313 phba->fw_config.iscsi_icd_start) / PAGE_SIZE;
3314 for (i = 0; i < mem_descr->num_elements; i++) {
3315 hwi_build_be_sgl_arr(phba, pm_arr, &sgl);
3316 status = be_cmd_iscsi_post_sgl_pages(&phba->ctrl, &sgl,
3317 page_offset,
3318 (pm_arr->size / PAGE_SIZE));
3319 page_offset += pm_arr->size / PAGE_SIZE;
3320 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303321 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3322 "BM_%d : post sgl failed.\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303323 return status;
3324 }
3325 pm_arr++;
3326 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05303327 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3328 "BM_%d : POSTED PAGES\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303329 return 0;
3330}
3331
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303332static void be_queue_free(struct beiscsi_hba *phba, struct be_queue_info *q)
3333{
3334 struct be_dma_mem *mem = &q->dma_mem;
Jayamohan Kallickalc8b25592012-04-03 23:41:42 -05003335 if (mem->va) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303336 pci_free_consistent(phba->pcidev, mem->size,
3337 mem->va, mem->dma);
Jayamohan Kallickalc8b25592012-04-03 23:41:42 -05003338 mem->va = NULL;
3339 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303340}
3341
3342static int be_queue_alloc(struct beiscsi_hba *phba, struct be_queue_info *q,
3343 u16 len, u16 entry_size)
3344{
3345 struct be_dma_mem *mem = &q->dma_mem;
3346
3347 memset(q, 0, sizeof(*q));
3348 q->len = len;
3349 q->entry_size = entry_size;
3350 mem->size = len * entry_size;
3351 mem->va = pci_alloc_consistent(phba->pcidev, mem->size, &mem->dma);
3352 if (!mem->va)
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +05303353 return -ENOMEM;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303354 memset(mem->va, 0, mem->size);
3355 return 0;
3356}
3357
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303358static int
3359beiscsi_create_wrb_rings(struct beiscsi_hba *phba,
3360 struct hwi_context_memory *phwi_context,
3361 struct hwi_controller *phwi_ctrlr)
3362{
3363 unsigned int wrb_mem_index, offset, size, num_wrb_rings;
3364 u64 pa_addr_lo;
3365 unsigned int idx, num, i;
3366 struct mem_array *pwrb_arr;
3367 void *wrb_vaddr;
3368 struct be_dma_mem sgl;
3369 struct be_mem_descriptor *mem_descr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003370 struct hwi_wrb_context *pwrb_context;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303371 int status;
3372
3373 idx = 0;
3374 mem_descr = phba->init_mem;
3375 mem_descr += HWI_MEM_WRB;
3376 pwrb_arr = kmalloc(sizeof(*pwrb_arr) * phba->params.cxns_per_ctrl,
3377 GFP_KERNEL);
3378 if (!pwrb_arr) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303379 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3380 "BM_%d : Memory alloc failed in create wrb ring.\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303381 return -ENOMEM;
3382 }
3383 wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
3384 pa_addr_lo = mem_descr->mem_array[idx].bus_address.u.a64.address;
3385 num_wrb_rings = mem_descr->mem_array[idx].size /
3386 (phba->params.wrbs_per_cxn * sizeof(struct iscsi_wrb));
3387
3388 for (num = 0; num < phba->params.cxns_per_ctrl; num++) {
3389 if (num_wrb_rings) {
3390 pwrb_arr[num].virtual_address = wrb_vaddr;
3391 pwrb_arr[num].bus_address.u.a64.address = pa_addr_lo;
3392 pwrb_arr[num].size = phba->params.wrbs_per_cxn *
3393 sizeof(struct iscsi_wrb);
3394 wrb_vaddr += pwrb_arr[num].size;
3395 pa_addr_lo += pwrb_arr[num].size;
3396 num_wrb_rings--;
3397 } else {
3398 idx++;
3399 wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
3400 pa_addr_lo = mem_descr->mem_array[idx].\
3401 bus_address.u.a64.address;
3402 num_wrb_rings = mem_descr->mem_array[idx].size /
3403 (phba->params.wrbs_per_cxn *
3404 sizeof(struct iscsi_wrb));
3405 pwrb_arr[num].virtual_address = wrb_vaddr;
3406 pwrb_arr[num].bus_address.u.a64.address\
3407 = pa_addr_lo;
3408 pwrb_arr[num].size = phba->params.wrbs_per_cxn *
3409 sizeof(struct iscsi_wrb);
3410 wrb_vaddr += pwrb_arr[num].size;
3411 pa_addr_lo += pwrb_arr[num].size;
3412 num_wrb_rings--;
3413 }
3414 }
3415 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
3416 wrb_mem_index = 0;
3417 offset = 0;
3418 size = 0;
3419
3420 hwi_build_be_sgl_by_offset(phba, &pwrb_arr[i], &sgl);
3421 status = be_cmd_wrbq_create(&phba->ctrl, &sgl,
3422 &phwi_context->be_wrbq[i]);
3423 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303424 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3425 "BM_%d : wrbq create failed.");
Dan Carpenter1462b8ff2010-06-10 09:52:21 +02003426 kfree(pwrb_arr);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303427 return status;
3428 }
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003429 pwrb_context = &phwi_ctrlr->wrb_context[i];
3430 pwrb_context->cid = phwi_context->be_wrbq[i].id;
3431 BE_SET_CID_TO_CRI(i, pwrb_context->cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303432 }
3433 kfree(pwrb_arr);
3434 return 0;
3435}
3436
3437static void free_wrb_handles(struct beiscsi_hba *phba)
3438{
3439 unsigned int index;
3440 struct hwi_controller *phwi_ctrlr;
3441 struct hwi_wrb_context *pwrb_context;
3442
3443 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003444 for (index = 0; index < phba->params.cxns_per_ctrl; index++) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303445 pwrb_context = &phwi_ctrlr->wrb_context[index];
3446 kfree(pwrb_context->pwrb_handle_base);
3447 kfree(pwrb_context->pwrb_handle_basestd);
3448 }
3449}
3450
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303451static void be_mcc_queues_destroy(struct beiscsi_hba *phba)
3452{
3453 struct be_queue_info *q;
3454 struct be_ctrl_info *ctrl = &phba->ctrl;
3455
3456 q = &phba->ctrl.mcc_obj.q;
3457 if (q->created)
3458 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_MCCQ);
3459 be_queue_free(phba, q);
3460
3461 q = &phba->ctrl.mcc_obj.cq;
3462 if (q->created)
3463 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
3464 be_queue_free(phba, q);
3465}
3466
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303467static void hwi_cleanup(struct beiscsi_hba *phba)
3468{
3469 struct be_queue_info *q;
3470 struct be_ctrl_info *ctrl = &phba->ctrl;
3471 struct hwi_controller *phwi_ctrlr;
3472 struct hwi_context_memory *phwi_context;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003473 struct hwi_async_pdu_context *pasync_ctx;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303474 int i, eq_num;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303475
3476 phwi_ctrlr = phba->phwi_ctrlr;
3477 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07003478
3479 be_cmd_iscsi_remove_template_hdr(ctrl);
3480
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303481 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
3482 q = &phwi_context->be_wrbq[i];
3483 if (q->created)
3484 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_WRBQ);
3485 }
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003486 kfree(phwi_context->be_wrbq);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303487 free_wrb_handles(phba);
3488
3489 q = &phwi_context->be_def_hdrq;
3490 if (q->created)
3491 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
3492
3493 q = &phwi_context->be_def_dataq;
3494 if (q->created)
3495 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
3496
3497 beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
3498
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303499 for (i = 0; i < (phba->num_cpus); i++) {
3500 q = &phwi_context->be_cq[i];
3501 if (q->created)
3502 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
3503 }
3504 if (phba->msix_enabled)
3505 eq_num = 1;
3506 else
3507 eq_num = 0;
3508 for (i = 0; i < (phba->num_cpus + eq_num); i++) {
3509 q = &phwi_context->be_eq[i].q;
3510 if (q->created)
3511 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_EQ);
3512 }
3513 be_mcc_queues_destroy(phba);
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003514
3515 pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx;
3516 kfree(pasync_ctx->async_entry);
Jayamohan Kallickal0283fbb2013-04-05 20:38:21 -07003517 be_cmd_fw_uninit(ctrl);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303518}
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303519
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303520static int be_mcc_queues_create(struct beiscsi_hba *phba,
3521 struct hwi_context_memory *phwi_context)
3522{
3523 struct be_queue_info *q, *cq;
3524 struct be_ctrl_info *ctrl = &phba->ctrl;
3525
3526 /* Alloc MCC compl queue */
3527 cq = &phba->ctrl.mcc_obj.cq;
3528 if (be_queue_alloc(phba, cq, MCC_CQ_LEN,
3529 sizeof(struct be_mcc_compl)))
3530 goto err;
3531 /* Ask BE to create MCC compl queue; */
3532 if (phba->msix_enabled) {
3533 if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq
3534 [phba->num_cpus].q, false, true, 0))
3535 goto mcc_cq_free;
3536 } else {
3537 if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq[0].q,
3538 false, true, 0))
3539 goto mcc_cq_free;
3540 }
3541
3542 /* Alloc MCC queue */
3543 q = &phba->ctrl.mcc_obj.q;
3544 if (be_queue_alloc(phba, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb)))
3545 goto mcc_cq_destroy;
3546
3547 /* Ask BE to create MCC queue */
Jayamohan Kallickal35e66012009-10-23 11:53:49 +05303548 if (beiscsi_cmd_mccq_create(phba, q, cq))
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303549 goto mcc_q_free;
3550
3551 return 0;
3552
3553mcc_q_free:
3554 be_queue_free(phba, q);
3555mcc_cq_destroy:
3556 beiscsi_cmd_q_destroy(ctrl, cq, QTYPE_CQ);
3557mcc_cq_free:
3558 be_queue_free(phba, cq);
3559err:
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +05303560 return -ENOMEM;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303561}
3562
John Soni Jose107dfcb2012-10-20 04:42:13 +05303563/**
3564 * find_num_cpus()- Get the CPU online count
3565 * @phba: ptr to priv structure
3566 *
3567 * CPU count is used for creating EQ.
3568 **/
3569static void find_num_cpus(struct beiscsi_hba *phba)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303570{
3571 int num_cpus = 0;
3572
3573 num_cpus = num_online_cpus();
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303574
John Soni Jose22abeef2012-10-20 04:43:32 +05303575 switch (phba->generation) {
3576 case BE_GEN2:
3577 case BE_GEN3:
3578 phba->num_cpus = (num_cpus > BEISCSI_MAX_NUM_CPUS) ?
3579 BEISCSI_MAX_NUM_CPUS : num_cpus;
3580 break;
3581 case BE_GEN4:
3582 phba->num_cpus = (num_cpus > OC_SKH_MAX_NUM_CPUS) ?
3583 OC_SKH_MAX_NUM_CPUS : num_cpus;
3584 break;
3585 default:
3586 phba->num_cpus = 1;
3587 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303588}
3589
3590static int hwi_init_port(struct beiscsi_hba *phba)
3591{
3592 struct hwi_controller *phwi_ctrlr;
3593 struct hwi_context_memory *phwi_context;
3594 unsigned int def_pdu_ring_sz;
3595 struct be_ctrl_info *ctrl = &phba->ctrl;
3596 int status;
3597
3598 def_pdu_ring_sz =
3599 phba->params.asyncpdus_per_ctrl * sizeof(struct phys_addr);
3600 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303601 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303602 phwi_context->max_eqd = 0;
3603 phwi_context->min_eqd = 0;
3604 phwi_context->cur_eqd = 64;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303605 be_cmd_fw_initialize(&phba->ctrl);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303606
3607 status = beiscsi_create_eqs(phba, phwi_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303608 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303609 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3610 "BM_%d : EQ not created\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303611 goto error;
3612 }
3613
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303614 status = be_mcc_queues_create(phba, phwi_context);
3615 if (status != 0)
3616 goto error;
3617
3618 status = mgmt_check_supported_fw(ctrl, phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303619 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303620 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3621 "BM_%d : Unsupported fw version\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303622 goto error;
3623 }
3624
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303625 status = beiscsi_create_cqs(phba, phwi_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303626 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303627 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3628 "BM_%d : CQ not created\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303629 goto error;
3630 }
3631
3632 status = beiscsi_create_def_hdr(phba, phwi_context, phwi_ctrlr,
3633 def_pdu_ring_sz);
3634 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303635 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3636 "BM_%d : Default Header not created\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303637 goto error;
3638 }
3639
3640 status = beiscsi_create_def_data(phba, phwi_context,
3641 phwi_ctrlr, def_pdu_ring_sz);
3642 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303643 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3644 "BM_%d : Default Data not created\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303645 goto error;
3646 }
3647
3648 status = beiscsi_post_pages(phba);
3649 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303650 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3651 "BM_%d : Post SGL Pages Failed\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303652 goto error;
3653 }
3654
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07003655 status = beiscsi_post_template_hdr(phba);
3656 if (status != 0) {
3657 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3658 "BM_%d : Template HDR Posting for CXN Failed\n");
3659 }
3660
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303661 status = beiscsi_create_wrb_rings(phba, phwi_context, phwi_ctrlr);
3662 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303663 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3664 "BM_%d : WRB Rings not created\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303665 goto error;
3666 }
3667
John Soni Jose99bc5d52012-08-20 23:00:18 +05303668 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3669 "BM_%d : hwi_init_port success\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303670 return 0;
3671
3672error:
John Soni Jose99bc5d52012-08-20 23:00:18 +05303673 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3674 "BM_%d : hwi_init_port failed");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303675 hwi_cleanup(phba);
Jayamohan Kallickala49e06d2012-04-03 23:41:44 -05003676 return status;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303677}
3678
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303679static int hwi_init_controller(struct beiscsi_hba *phba)
3680{
3681 struct hwi_controller *phwi_ctrlr;
3682
3683 phwi_ctrlr = phba->phwi_ctrlr;
3684 if (1 == phba->init_mem[HWI_MEM_ADDN_CONTEXT].num_elements) {
3685 phwi_ctrlr->phwi_ctxt = (struct hwi_context_memory *)phba->
3686 init_mem[HWI_MEM_ADDN_CONTEXT].mem_array[0].virtual_address;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303687 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3688 "BM_%d : phwi_ctrlr->phwi_ctxt=%p\n",
3689 phwi_ctrlr->phwi_ctxt);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303690 } else {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303691 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3692 "BM_%d : HWI_MEM_ADDN_CONTEXT is more "
3693 "than one element.Failing to load\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303694 return -ENOMEM;
3695 }
3696
3697 iscsi_init_global_templates(phba);
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05003698 if (beiscsi_init_wrb_handle(phba))
3699 return -ENOMEM;
3700
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003701 if (hwi_init_async_pdu_ctx(phba)) {
3702 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3703 "BM_%d : hwi_init_async_pdu_ctx failed\n");
3704 return -ENOMEM;
3705 }
3706
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303707 if (hwi_init_port(phba) != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303708 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3709 "BM_%d : hwi_init_controller failed\n");
3710
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303711 return -ENOMEM;
3712 }
3713 return 0;
3714}
3715
3716static void beiscsi_free_mem(struct beiscsi_hba *phba)
3717{
3718 struct be_mem_descriptor *mem_descr;
3719 int i, j;
3720
3721 mem_descr = phba->init_mem;
3722 i = 0;
3723 j = 0;
3724 for (i = 0; i < SE_MEM_MAX; i++) {
3725 for (j = mem_descr->num_elements; j > 0; j--) {
3726 pci_free_consistent(phba->pcidev,
3727 mem_descr->mem_array[j - 1].size,
3728 mem_descr->mem_array[j - 1].virtual_address,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05303729 (unsigned long)mem_descr->mem_array[j - 1].
3730 bus_address.u.a64.address);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303731 }
3732 kfree(mem_descr->mem_array);
3733 mem_descr++;
3734 }
3735 kfree(phba->init_mem);
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003736 kfree(phba->phwi_ctrlr->wrb_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303737 kfree(phba->phwi_ctrlr);
3738}
3739
3740static int beiscsi_init_controller(struct beiscsi_hba *phba)
3741{
3742 int ret = -ENOMEM;
3743
3744 ret = beiscsi_get_memory(phba);
3745 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303746 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3747 "BM_%d : beiscsi_dev_probe -"
3748 "Failed in beiscsi_alloc_memory\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303749 return ret;
3750 }
3751
3752 ret = hwi_init_controller(phba);
3753 if (ret)
3754 goto free_init;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303755 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3756 "BM_%d : Return success from beiscsi_init_controller");
3757
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303758 return 0;
3759
3760free_init:
3761 beiscsi_free_mem(phba);
Jayamohan Kallickala49e06d2012-04-03 23:41:44 -05003762 return ret;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303763}
3764
3765static int beiscsi_init_sgl_handle(struct beiscsi_hba *phba)
3766{
3767 struct be_mem_descriptor *mem_descr_sglh, *mem_descr_sg;
3768 struct sgl_handle *psgl_handle;
3769 struct iscsi_sge *pfrag;
3770 unsigned int arr_index, i, idx;
3771
3772 phba->io_sgl_hndl_avbl = 0;
3773 phba->eh_sgl_hndl_avbl = 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303774
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303775 mem_descr_sglh = phba->init_mem;
3776 mem_descr_sglh += HWI_MEM_SGLH;
3777 if (1 == mem_descr_sglh->num_elements) {
3778 phba->io_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
3779 phba->params.ios_per_ctrl,
3780 GFP_KERNEL);
3781 if (!phba->io_sgl_hndl_base) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303782 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3783 "BM_%d : Mem Alloc Failed. Failing to load\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303784 return -ENOMEM;
3785 }
3786 phba->eh_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
3787 (phba->params.icds_per_ctrl -
3788 phba->params.ios_per_ctrl),
3789 GFP_KERNEL);
3790 if (!phba->eh_sgl_hndl_base) {
3791 kfree(phba->io_sgl_hndl_base);
John Soni Jose99bc5d52012-08-20 23:00:18 +05303792 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3793 "BM_%d : Mem Alloc Failed. Failing to load\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303794 return -ENOMEM;
3795 }
3796 } else {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303797 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3798 "BM_%d : HWI_MEM_SGLH is more than one element."
3799 "Failing to load\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303800 return -ENOMEM;
3801 }
3802
3803 arr_index = 0;
3804 idx = 0;
3805 while (idx < mem_descr_sglh->num_elements) {
3806 psgl_handle = mem_descr_sglh->mem_array[idx].virtual_address;
3807
3808 for (i = 0; i < (mem_descr_sglh->mem_array[idx].size /
3809 sizeof(struct sgl_handle)); i++) {
3810 if (arr_index < phba->params.ios_per_ctrl) {
3811 phba->io_sgl_hndl_base[arr_index] = psgl_handle;
3812 phba->io_sgl_hndl_avbl++;
3813 arr_index++;
3814 } else {
3815 phba->eh_sgl_hndl_base[arr_index -
3816 phba->params.ios_per_ctrl] =
3817 psgl_handle;
3818 arr_index++;
3819 phba->eh_sgl_hndl_avbl++;
3820 }
3821 psgl_handle++;
3822 }
3823 idx++;
3824 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05303825 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3826 "BM_%d : phba->io_sgl_hndl_avbl=%d"
3827 "phba->eh_sgl_hndl_avbl=%d\n",
3828 phba->io_sgl_hndl_avbl,
3829 phba->eh_sgl_hndl_avbl);
3830
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303831 mem_descr_sg = phba->init_mem;
3832 mem_descr_sg += HWI_MEM_SGE;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303833 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3834 "\n BM_%d : mem_descr_sg->num_elements=%d\n",
3835 mem_descr_sg->num_elements);
3836
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303837 arr_index = 0;
3838 idx = 0;
3839 while (idx < mem_descr_sg->num_elements) {
3840 pfrag = mem_descr_sg->mem_array[idx].virtual_address;
3841
3842 for (i = 0;
3843 i < (mem_descr_sg->mem_array[idx].size) /
3844 (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io);
3845 i++) {
3846 if (arr_index < phba->params.ios_per_ctrl)
3847 psgl_handle = phba->io_sgl_hndl_base[arr_index];
3848 else
3849 psgl_handle = phba->eh_sgl_hndl_base[arr_index -
3850 phba->params.ios_per_ctrl];
3851 psgl_handle->pfrag = pfrag;
3852 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, pfrag, 0);
3853 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, pfrag, 0);
3854 pfrag += phba->params.num_sge_per_io;
3855 psgl_handle->sgl_index =
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05303856 phba->fw_config.iscsi_icd_start + arr_index++;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303857 }
3858 idx++;
3859 }
3860 phba->io_sgl_free_index = 0;
3861 phba->io_sgl_alloc_index = 0;
3862 phba->eh_sgl_free_index = 0;
3863 phba->eh_sgl_alloc_index = 0;
3864 return 0;
3865}
3866
3867static int hba_setup_cid_tbls(struct beiscsi_hba *phba)
3868{
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003869 int i;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303870
Jayamohan Kallickalc24622882010-01-05 05:05:34 +05303871 phba->cid_array = kzalloc(sizeof(void *) * phba->params.cxns_per_ctrl,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303872 GFP_KERNEL);
3873 if (!phba->cid_array) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303874 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3875 "BM_%d : Failed to allocate memory in "
3876 "hba_setup_cid_tbls\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303877 return -ENOMEM;
3878 }
Jayamohan Kallickalc24622882010-01-05 05:05:34 +05303879 phba->ep_array = kzalloc(sizeof(struct iscsi_endpoint *) *
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003880 phba->params.cxns_per_ctrl, GFP_KERNEL);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303881 if (!phba->ep_array) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303882 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3883 "BM_%d : Failed to allocate memory in "
3884 "hba_setup_cid_tbls\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303885 kfree(phba->cid_array);
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003886 phba->cid_array = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303887 return -ENOMEM;
3888 }
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003889
3890 phba->conn_table = kzalloc(sizeof(struct beiscsi_conn *) *
3891 phba->params.cxns_per_ctrl, GFP_KERNEL);
3892 if (!phba->conn_table) {
3893 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3894 "BM_%d : Failed to allocate memory in"
3895 "hba_setup_cid_tbls\n");
3896
3897 kfree(phba->cid_array);
3898 kfree(phba->ep_array);
3899 phba->cid_array = NULL;
3900 phba->ep_array = NULL;
3901 return -ENOMEM;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303902 }
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003903
3904 for (i = 0; i < phba->params.cxns_per_ctrl; i++)
3905 phba->cid_array[i] = phba->phwi_ctrlr->wrb_context[i].cid;
3906
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303907 phba->avlbl_cids = phba->params.cxns_per_ctrl;
3908 return 0;
3909}
3910
Jayamohan Kallickal238f6b72010-07-22 04:23:22 +05303911static void hwi_enable_intr(struct beiscsi_hba *phba)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303912{
3913 struct be_ctrl_info *ctrl = &phba->ctrl;
3914 struct hwi_controller *phwi_ctrlr;
3915 struct hwi_context_memory *phwi_context;
3916 struct be_queue_info *eq;
3917 u8 __iomem *addr;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303918 u32 reg, i;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303919 u32 enabled;
3920
3921 phwi_ctrlr = phba->phwi_ctrlr;
3922 phwi_context = phwi_ctrlr->phwi_ctxt;
3923
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303924 addr = (u8 __iomem *) ((u8 __iomem *) ctrl->pcicfg +
3925 PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET);
3926 reg = ioread32(addr);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303927
3928 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
3929 if (!enabled) {
3930 reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303931 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3932 "BM_%d : reg =x%08x addr=%p\n", reg, addr);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303933 iowrite32(reg, addr);
Jayamohan Kallickal665d6d92011-04-29 14:30:06 -05003934 }
3935
3936 if (!phba->msix_enabled) {
3937 eq = &phwi_context->be_eq[0].q;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303938 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3939 "BM_%d : eq->id=%d\n", eq->id);
3940
Jayamohan Kallickal665d6d92011-04-29 14:30:06 -05003941 hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
3942 } else {
3943 for (i = 0; i <= phba->num_cpus; i++) {
3944 eq = &phwi_context->be_eq[i].q;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303945 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3946 "BM_%d : eq->id=%d\n", eq->id);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303947 hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
3948 }
Jayamohan Kallickalc03af1a2010-02-20 08:05:43 +05303949 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303950}
3951
3952static void hwi_disable_intr(struct beiscsi_hba *phba)
3953{
3954 struct be_ctrl_info *ctrl = &phba->ctrl;
3955
3956 u8 __iomem *addr = ctrl->pcicfg + PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET;
3957 u32 reg = ioread32(addr);
3958
3959 u32 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
3960 if (enabled) {
3961 reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
3962 iowrite32(reg, addr);
3963 } else
John Soni Jose99bc5d52012-08-20 23:00:18 +05303964 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
3965 "BM_%d : In hwi_disable_intr, Already Disabled\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303966}
3967
John Soni Jose9aef4202012-08-20 23:00:08 +05303968/**
3969 * beiscsi_get_boot_info()- Get the boot session info
3970 * @phba: The device priv structure instance
3971 *
3972 * Get the boot target info and store in driver priv structure
3973 *
3974 * return values
3975 * Success: 0
3976 * Failure: Non-Zero Value
3977 **/
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05303978static int beiscsi_get_boot_info(struct beiscsi_hba *phba)
3979{
Mike Christie0e438952012-04-03 23:41:51 -05003980 struct be_cmd_get_session_resp *session_resp;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05303981 struct be_dma_mem nonemb_cmd;
John Soni Josee175def2012-10-20 04:45:40 +05303982 unsigned int tag;
John Soni Jose9aef4202012-08-20 23:00:08 +05303983 unsigned int s_handle;
Mike Christief457a462011-06-24 15:11:53 -05003984 int ret = -ENOMEM;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05303985
John Soni Jose9aef4202012-08-20 23:00:08 +05303986 /* Get the session handle of the boot target */
3987 ret = be_mgmt_get_boot_shandle(phba, &s_handle);
3988 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303989 beiscsi_log(phba, KERN_ERR,
3990 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
3991 "BM_%d : No boot session\n");
John Soni Jose9aef4202012-08-20 23:00:08 +05303992 return ret;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05303993 }
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05303994 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
3995 sizeof(*session_resp),
3996 &nonemb_cmd.dma);
3997 if (nonemb_cmd.va == NULL) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303998 beiscsi_log(phba, KERN_ERR,
3999 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
4000 "BM_%d : Failed to allocate memory for"
4001 "beiscsi_get_session_info\n");
4002
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304003 return -ENOMEM;
4004 }
4005
4006 memset(nonemb_cmd.va, 0, sizeof(*session_resp));
John Soni Jose9aef4202012-08-20 23:00:08 +05304007 tag = mgmt_get_session_info(phba, s_handle,
Mike Christie0e438952012-04-03 23:41:51 -05004008 &nonemb_cmd);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304009 if (!tag) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304010 beiscsi_log(phba, KERN_ERR,
4011 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
4012 "BM_%d : beiscsi_get_session_info"
4013 " Failed\n");
4014
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304015 goto boot_freemem;
John Soni Josee175def2012-10-20 04:45:40 +05304016 }
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304017
John Soni Josee175def2012-10-20 04:45:40 +05304018 ret = beiscsi_mccq_compl(phba, tag, NULL, nonemb_cmd.va);
4019 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304020 beiscsi_log(phba, KERN_ERR,
4021 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
John Soni Josee175def2012-10-20 04:45:40 +05304022 "BM_%d : beiscsi_get_session_info Failed");
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304023 goto boot_freemem;
4024 }
John Soni Josee175def2012-10-20 04:45:40 +05304025
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304026 session_resp = nonemb_cmd.va ;
Mike Christief457a462011-06-24 15:11:53 -05004027
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304028 memcpy(&phba->boot_sess, &session_resp->session_info,
4029 sizeof(struct mgmt_session_info));
Mike Christief457a462011-06-24 15:11:53 -05004030 ret = 0;
4031
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304032boot_freemem:
4033 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
4034 nonemb_cmd.va, nonemb_cmd.dma);
Mike Christief457a462011-06-24 15:11:53 -05004035 return ret;
4036}
4037
4038static void beiscsi_boot_release(void *data)
4039{
4040 struct beiscsi_hba *phba = data;
4041
4042 scsi_host_put(phba->shost);
4043}
4044
4045static int beiscsi_setup_boot_info(struct beiscsi_hba *phba)
4046{
4047 struct iscsi_boot_kobj *boot_kobj;
4048
4049 /* get boot info using mgmt cmd */
4050 if (beiscsi_get_boot_info(phba))
4051 /* Try to see if we can carry on without this */
4052 return 0;
4053
4054 phba->boot_kset = iscsi_boot_create_host_kset(phba->shost->host_no);
4055 if (!phba->boot_kset)
4056 return -ENOMEM;
4057
4058 /* get a ref because the show function will ref the phba */
4059 if (!scsi_host_get(phba->shost))
4060 goto free_kset;
4061 boot_kobj = iscsi_boot_create_target(phba->boot_kset, 0, phba,
4062 beiscsi_show_boot_tgt_info,
4063 beiscsi_tgt_get_attr_visibility,
4064 beiscsi_boot_release);
4065 if (!boot_kobj)
4066 goto put_shost;
4067
4068 if (!scsi_host_get(phba->shost))
4069 goto free_kset;
4070 boot_kobj = iscsi_boot_create_initiator(phba->boot_kset, 0, phba,
4071 beiscsi_show_boot_ini_info,
4072 beiscsi_ini_get_attr_visibility,
4073 beiscsi_boot_release);
4074 if (!boot_kobj)
4075 goto put_shost;
4076
4077 if (!scsi_host_get(phba->shost))
4078 goto free_kset;
4079 boot_kobj = iscsi_boot_create_ethernet(phba->boot_kset, 0, phba,
4080 beiscsi_show_boot_eth_info,
4081 beiscsi_eth_get_attr_visibility,
4082 beiscsi_boot_release);
4083 if (!boot_kobj)
4084 goto put_shost;
4085 return 0;
4086
4087put_shost:
4088 scsi_host_put(phba->shost);
4089free_kset:
4090 iscsi_boot_destroy_kset(phba->boot_kset);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304091 return -ENOMEM;
4092}
4093
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304094static int beiscsi_init_port(struct beiscsi_hba *phba)
4095{
4096 int ret;
4097
4098 ret = beiscsi_init_controller(phba);
4099 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304100 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4101 "BM_%d : beiscsi_dev_probe - Failed in"
4102 "beiscsi_init_controller\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304103 return ret;
4104 }
4105 ret = beiscsi_init_sgl_handle(phba);
4106 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304107 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4108 "BM_%d : beiscsi_dev_probe - Failed in"
4109 "beiscsi_init_sgl_handle\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304110 goto do_cleanup_ctrlr;
4111 }
4112
4113 if (hba_setup_cid_tbls(phba)) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304114 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4115 "BM_%d : Failed in hba_setup_cid_tbls\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304116 kfree(phba->io_sgl_hndl_base);
4117 kfree(phba->eh_sgl_hndl_base);
4118 goto do_cleanup_ctrlr;
4119 }
4120
4121 return ret;
4122
4123do_cleanup_ctrlr:
4124 hwi_cleanup(phba);
4125 return ret;
4126}
4127
4128static void hwi_purge_eq(struct beiscsi_hba *phba)
4129{
4130 struct hwi_controller *phwi_ctrlr;
4131 struct hwi_context_memory *phwi_context;
4132 struct be_queue_info *eq;
4133 struct be_eq_entry *eqe = NULL;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304134 int i, eq_msix;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05304135 unsigned int num_processed;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304136
4137 phwi_ctrlr = phba->phwi_ctrlr;
4138 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304139 if (phba->msix_enabled)
4140 eq_msix = 1;
4141 else
4142 eq_msix = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304143
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304144 for (i = 0; i < (phba->num_cpus + eq_msix); i++) {
4145 eq = &phwi_context->be_eq[i].q;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304146 eqe = queue_tail_node(eq);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05304147 num_processed = 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304148 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
4149 & EQE_VALID_MASK) {
4150 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
4151 queue_tail_inc(eq);
4152 eqe = queue_tail_node(eq);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05304153 num_processed++;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304154 }
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05304155
4156 if (num_processed)
4157 hwi_ring_eq_db(phba, eq->id, 1, num_processed, 1, 1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304158 }
4159}
4160
4161static void beiscsi_clean_port(struct beiscsi_hba *phba)
4162{
Jayamohan Kallickal03a12312010-07-22 04:17:16 +05304163 int mgmt_status;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304164
4165 mgmt_status = mgmt_epfw_cleanup(phba, CMD_CONNECTION_CHUTE_0);
4166 if (mgmt_status)
John Soni Jose99bc5d52012-08-20 23:00:18 +05304167 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
4168 "BM_%d : mgmt_epfw_cleanup FAILED\n");
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05304169
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304170 hwi_purge_eq(phba);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05304171 hwi_cleanup(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304172 kfree(phba->io_sgl_hndl_base);
4173 kfree(phba->eh_sgl_hndl_base);
4174 kfree(phba->cid_array);
4175 kfree(phba->ep_array);
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004176 kfree(phba->conn_table);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304177}
4178
John Soni Josed629c472012-10-20 04:42:00 +05304179/**
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004180 * beiscsi_free_mgmt_task_handles()- Free driver CXN resources
4181 * @beiscsi_conn: ptr to the conn to be cleaned up
Jayamohan Kallickal4a4a11b2013-04-05 20:38:31 -07004182 * @task: ptr to iscsi_task resource to be freed.
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004183 *
4184 * Free driver mgmt resources binded to CXN.
4185 **/
4186void
Jayamohan Kallickal4a4a11b2013-04-05 20:38:31 -07004187beiscsi_free_mgmt_task_handles(struct beiscsi_conn *beiscsi_conn,
4188 struct iscsi_task *task)
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004189{
4190 struct beiscsi_io_task *io_task;
4191 struct beiscsi_hba *phba = beiscsi_conn->phba;
4192 struct hwi_wrb_context *pwrb_context;
4193 struct hwi_controller *phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004194 uint16_t cri_index = BE_GET_CRI_FROM_CID(
4195 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004196
4197 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004198 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
4199
Jayamohan Kallickal4a4a11b2013-04-05 20:38:31 -07004200 io_task = task->dd_data;
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004201
4202 if (io_task->pwrb_handle) {
4203 memset(io_task->pwrb_handle->pwrb, 0,
4204 sizeof(struct iscsi_wrb));
4205 free_wrb_handle(phba, pwrb_context,
4206 io_task->pwrb_handle);
4207 io_task->pwrb_handle = NULL;
4208 }
4209
4210 if (io_task->psgl_handle) {
4211 spin_lock_bh(&phba->mgmt_sgl_lock);
4212 free_mgmt_sgl_handle(phba,
4213 io_task->psgl_handle);
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004214 io_task->psgl_handle = NULL;
Jayamohan Kallickal4a4a11b2013-04-05 20:38:31 -07004215 spin_unlock_bh(&phba->mgmt_sgl_lock);
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004216 }
4217
4218 if (io_task->mtask_addr)
4219 pci_unmap_single(phba->pcidev,
4220 io_task->mtask_addr,
4221 io_task->mtask_data_count,
4222 PCI_DMA_TODEVICE);
4223}
4224
4225/**
John Soni Josed629c472012-10-20 04:42:00 +05304226 * beiscsi_cleanup_task()- Free driver resources of the task
4227 * @task: ptr to the iscsi task
4228 *
4229 **/
Mike Christie1282ab72012-04-18 03:06:00 -05004230static void beiscsi_cleanup_task(struct iscsi_task *task)
4231{
4232 struct beiscsi_io_task *io_task = task->dd_data;
4233 struct iscsi_conn *conn = task->conn;
4234 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4235 struct beiscsi_hba *phba = beiscsi_conn->phba;
4236 struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
4237 struct hwi_wrb_context *pwrb_context;
4238 struct hwi_controller *phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004239 uint16_t cri_index = BE_GET_CRI_FROM_CID(
4240 beiscsi_conn->beiscsi_conn_cid);
Mike Christie1282ab72012-04-18 03:06:00 -05004241
4242 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004243 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
Mike Christie1282ab72012-04-18 03:06:00 -05004244
4245 if (io_task->cmd_bhs) {
4246 pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
4247 io_task->bhs_pa.u.a64.address);
4248 io_task->cmd_bhs = NULL;
4249 }
4250
4251 if (task->sc) {
4252 if (io_task->pwrb_handle) {
4253 free_wrb_handle(phba, pwrb_context,
4254 io_task->pwrb_handle);
4255 io_task->pwrb_handle = NULL;
4256 }
4257
4258 if (io_task->psgl_handle) {
4259 spin_lock(&phba->io_sgl_lock);
4260 free_io_sgl_handle(phba, io_task->psgl_handle);
4261 spin_unlock(&phba->io_sgl_lock);
4262 io_task->psgl_handle = NULL;
4263 }
4264 } else {
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004265 if (!beiscsi_conn->login_in_progress)
Jayamohan Kallickal4a4a11b2013-04-05 20:38:31 -07004266 beiscsi_free_mgmt_task_handles(beiscsi_conn, task);
Mike Christie1282ab72012-04-18 03:06:00 -05004267 }
4268}
4269
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304270void
4271beiscsi_offload_connection(struct beiscsi_conn *beiscsi_conn,
4272 struct beiscsi_offload_params *params)
4273{
4274 struct wrb_handle *pwrb_handle;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304275 struct beiscsi_hba *phba = beiscsi_conn->phba;
Mike Christie1282ab72012-04-18 03:06:00 -05004276 struct iscsi_task *task = beiscsi_conn->task;
4277 struct iscsi_session *session = task->conn->session;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304278 u32 doorbell = 0;
4279
4280 /*
4281 * We can always use 0 here because it is reserved by libiscsi for
4282 * login/startup related tasks.
4283 */
Mike Christie1282ab72012-04-18 03:06:00 -05004284 beiscsi_conn->login_in_progress = 0;
4285 spin_lock_bh(&session->lock);
4286 beiscsi_cleanup_task(task);
4287 spin_unlock_bh(&session->lock);
4288
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004289 pwrb_handle = alloc_wrb_handle(phba, beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304290
John Soni Joseacb96932012-10-20 04:44:35 +05304291 /* Check for the adapter family */
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004292 if (is_chip_be2_be3r(phba))
John Soni Joseacb96932012-10-20 04:44:35 +05304293 beiscsi_offload_cxn_v0(params, pwrb_handle,
4294 phba->init_mem);
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004295 else
4296 beiscsi_offload_cxn_v2(params, pwrb_handle);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304297
John Soni Joseacb96932012-10-20 04:44:35 +05304298 be_dws_le_to_cpu(pwrb_handle->pwrb,
4299 sizeof(struct iscsi_target_context_update_wrb));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304300
4301 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304302 doorbell |= (pwrb_handle->wrb_index & DB_DEF_PDU_WRB_INDEX_MASK)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304303 << DB_DEF_PDU_WRB_INDEX_SHIFT;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304304 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
4305
4306 iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
4307}
4308
4309static void beiscsi_parse_pdu(struct iscsi_conn *conn, itt_t itt,
4310 int *index, int *age)
4311{
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304312 *index = (int)itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304313 if (age)
4314 *age = conn->session->age;
4315}
4316
4317/**
4318 * beiscsi_alloc_pdu - allocates pdu and related resources
4319 * @task: libiscsi task
4320 * @opcode: opcode of pdu for task
4321 *
4322 * This is called with the session lock held. It will allocate
4323 * the wrb and sgl if needed for the command. And it will prep
4324 * the pdu's itt. beiscsi_parse_pdu will later translate
4325 * the pdu itt to the libiscsi task itt.
4326 */
4327static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
4328{
4329 struct beiscsi_io_task *io_task = task->dd_data;
4330 struct iscsi_conn *conn = task->conn;
4331 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4332 struct beiscsi_hba *phba = beiscsi_conn->phba;
4333 struct hwi_wrb_context *pwrb_context;
4334 struct hwi_controller *phwi_ctrlr;
4335 itt_t itt;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004336 uint16_t cri_index = 0;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304337 struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
4338 dma_addr_t paddr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304339
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304340 io_task->cmd_bhs = pci_pool_alloc(beiscsi_sess->bhs_pool,
Mike Christiebc7acce2010-12-31 02:22:19 -06004341 GFP_ATOMIC, &paddr);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304342 if (!io_task->cmd_bhs)
4343 return -ENOMEM;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304344 io_task->bhs_pa.u.a64.address = paddr;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304345 io_task->libiscsi_itt = (itt_t)task->itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304346 io_task->conn = beiscsi_conn;
4347
4348 task->hdr = (struct iscsi_hdr *)&io_task->cmd_bhs->iscsi_hdr;
4349 task->hdr_max = sizeof(struct be_cmd_bhs);
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304350 io_task->psgl_handle = NULL;
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05004351 io_task->pwrb_handle = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304352
4353 if (task->sc) {
4354 spin_lock(&phba->io_sgl_lock);
4355 io_task->psgl_handle = alloc_io_sgl_handle(phba);
4356 spin_unlock(&phba->io_sgl_lock);
John Soni Jose8359c792012-10-20 04:43:03 +05304357 if (!io_task->psgl_handle) {
4358 beiscsi_log(phba, KERN_ERR,
4359 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
4360 "BM_%d : Alloc of IO_SGL_ICD Failed"
4361 "for the CID : %d\n",
4362 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304363 goto free_hndls;
John Soni Jose8359c792012-10-20 04:43:03 +05304364 }
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304365 io_task->pwrb_handle = alloc_wrb_handle(phba,
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004366 beiscsi_conn->beiscsi_conn_cid);
John Soni Jose8359c792012-10-20 04:43:03 +05304367 if (!io_task->pwrb_handle) {
4368 beiscsi_log(phba, KERN_ERR,
4369 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
4370 "BM_%d : Alloc of WRB_HANDLE Failed"
4371 "for the CID : %d\n",
4372 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304373 goto free_io_hndls;
John Soni Jose8359c792012-10-20 04:43:03 +05304374 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304375 } else {
4376 io_task->scsi_cmnd = NULL;
Jayamohan Kallickald7aea672010-01-05 05:08:39 +05304377 if ((opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN) {
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004378 beiscsi_conn->task = task;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304379 if (!beiscsi_conn->login_in_progress) {
4380 spin_lock(&phba->mgmt_sgl_lock);
4381 io_task->psgl_handle = (struct sgl_handle *)
4382 alloc_mgmt_sgl_handle(phba);
4383 spin_unlock(&phba->mgmt_sgl_lock);
John Soni Jose8359c792012-10-20 04:43:03 +05304384 if (!io_task->psgl_handle) {
4385 beiscsi_log(phba, KERN_ERR,
4386 BEISCSI_LOG_IO |
4387 BEISCSI_LOG_CONFIG,
4388 "BM_%d : Alloc of MGMT_SGL_ICD Failed"
4389 "for the CID : %d\n",
4390 beiscsi_conn->
4391 beiscsi_conn_cid);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304392 goto free_hndls;
John Soni Jose8359c792012-10-20 04:43:03 +05304393 }
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304394
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304395 beiscsi_conn->login_in_progress = 1;
4396 beiscsi_conn->plogin_sgl_handle =
4397 io_task->psgl_handle;
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304398 io_task->pwrb_handle =
4399 alloc_wrb_handle(phba,
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004400 beiscsi_conn->beiscsi_conn_cid);
John Soni Jose8359c792012-10-20 04:43:03 +05304401 if (!io_task->pwrb_handle) {
4402 beiscsi_log(phba, KERN_ERR,
4403 BEISCSI_LOG_IO |
4404 BEISCSI_LOG_CONFIG,
4405 "BM_%d : Alloc of WRB_HANDLE Failed"
4406 "for the CID : %d\n",
4407 beiscsi_conn->
4408 beiscsi_conn_cid);
4409 goto free_mgmt_hndls;
4410 }
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304411 beiscsi_conn->plogin_wrb_handle =
4412 io_task->pwrb_handle;
4413
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304414 } else {
4415 io_task->psgl_handle =
4416 beiscsi_conn->plogin_sgl_handle;
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304417 io_task->pwrb_handle =
4418 beiscsi_conn->plogin_wrb_handle;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304419 }
4420 } else {
4421 spin_lock(&phba->mgmt_sgl_lock);
4422 io_task->psgl_handle = alloc_mgmt_sgl_handle(phba);
4423 spin_unlock(&phba->mgmt_sgl_lock);
John Soni Jose8359c792012-10-20 04:43:03 +05304424 if (!io_task->psgl_handle) {
4425 beiscsi_log(phba, KERN_ERR,
4426 BEISCSI_LOG_IO |
4427 BEISCSI_LOG_CONFIG,
4428 "BM_%d : Alloc of MGMT_SGL_ICD Failed"
4429 "for the CID : %d\n",
4430 beiscsi_conn->
4431 beiscsi_conn_cid);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304432 goto free_hndls;
John Soni Jose8359c792012-10-20 04:43:03 +05304433 }
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304434 io_task->pwrb_handle =
4435 alloc_wrb_handle(phba,
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004436 beiscsi_conn->beiscsi_conn_cid);
John Soni Jose8359c792012-10-20 04:43:03 +05304437 if (!io_task->pwrb_handle) {
4438 beiscsi_log(phba, KERN_ERR,
4439 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
4440 "BM_%d : Alloc of WRB_HANDLE Failed"
4441 "for the CID : %d\n",
4442 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304443 goto free_mgmt_hndls;
John Soni Jose8359c792012-10-20 04:43:03 +05304444 }
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304445
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304446 }
4447 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304448 itt = (itt_t) cpu_to_be32(((unsigned int)io_task->pwrb_handle->
4449 wrb_index << 16) | (unsigned int)
4450 (io_task->psgl_handle->sgl_index));
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304451 io_task->pwrb_handle->pio_handle = task;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304452
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304453 io_task->cmd_bhs->iscsi_hdr.itt = itt;
4454 return 0;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304455
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304456free_io_hndls:
4457 spin_lock(&phba->io_sgl_lock);
4458 free_io_sgl_handle(phba, io_task->psgl_handle);
4459 spin_unlock(&phba->io_sgl_lock);
4460 goto free_hndls;
4461free_mgmt_hndls:
4462 spin_lock(&phba->mgmt_sgl_lock);
4463 free_mgmt_sgl_handle(phba, io_task->psgl_handle);
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004464 io_task->psgl_handle = NULL;
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304465 spin_unlock(&phba->mgmt_sgl_lock);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304466free_hndls:
4467 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004468 cri_index = BE_GET_CRI_FROM_CID(
4469 beiscsi_conn->beiscsi_conn_cid);
4470 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304471 if (io_task->pwrb_handle)
4472 free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304473 io_task->pwrb_handle = NULL;
4474 pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
4475 io_task->bhs_pa.u.a64.address);
Mike Christie1282ab72012-04-18 03:06:00 -05004476 io_task->cmd_bhs = NULL;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304477 return -ENOMEM;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304478}
John Soni Jose09a10932012-10-20 04:44:23 +05304479int beiscsi_iotask_v2(struct iscsi_task *task, struct scatterlist *sg,
4480 unsigned int num_sg, unsigned int xferlen,
4481 unsigned int writedir)
4482{
4483
4484 struct beiscsi_io_task *io_task = task->dd_data;
4485 struct iscsi_conn *conn = task->conn;
4486 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4487 struct beiscsi_hba *phba = beiscsi_conn->phba;
4488 struct iscsi_wrb *pwrb = NULL;
4489 unsigned int doorbell = 0;
4490
4491 pwrb = io_task->pwrb_handle->pwrb;
John Soni Jose09a10932012-10-20 04:44:23 +05304492
4493 io_task->cmd_bhs->iscsi_hdr.exp_statsn = 0;
4494 io_task->bhs_len = sizeof(struct be_cmd_bhs);
4495
4496 if (writedir) {
4497 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb,
4498 INI_WR_CMD);
4499 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 1);
4500 } else {
4501 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb,
4502 INI_RD_CMD);
4503 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 0);
4504 }
4505
4506 io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb_v2,
4507 type, pwrb);
4508
4509 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, lun, pwrb,
4510 cpu_to_be16(*(unsigned short *)
4511 &io_task->cmd_bhs->iscsi_hdr.lun));
4512 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb, xferlen);
4513 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb,
4514 io_task->pwrb_handle->wrb_index);
4515 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb,
4516 be32_to_cpu(task->cmdsn));
4517 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb,
4518 io_task->psgl_handle->sgl_index);
4519
4520 hwi_write_sgl_v2(pwrb, sg, num_sg, io_task);
4521 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb,
4522 io_task->pwrb_handle->nxt_wrb_index);
4523
4524 be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
4525
4526 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
4527 doorbell |= (io_task->pwrb_handle->wrb_index &
4528 DB_DEF_PDU_WRB_INDEX_MASK) <<
4529 DB_DEF_PDU_WRB_INDEX_SHIFT;
4530 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
4531 iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
4532 return 0;
4533}
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304534
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304535static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg,
4536 unsigned int num_sg, unsigned int xferlen,
4537 unsigned int writedir)
4538{
4539
4540 struct beiscsi_io_task *io_task = task->dd_data;
4541 struct iscsi_conn *conn = task->conn;
4542 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4543 struct beiscsi_hba *phba = beiscsi_conn->phba;
4544 struct iscsi_wrb *pwrb = NULL;
4545 unsigned int doorbell = 0;
4546
4547 pwrb = io_task->pwrb_handle->pwrb;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304548 io_task->cmd_bhs->iscsi_hdr.exp_statsn = 0;
4549 io_task->bhs_len = sizeof(struct be_cmd_bhs);
4550
4551 if (writedir) {
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304552 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4553 INI_WR_CMD);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304554 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304555 } else {
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304556 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4557 INI_RD_CMD);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304558 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
4559 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304560
John Soni Jose09a10932012-10-20 04:44:23 +05304561 io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb,
4562 type, pwrb);
4563
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304564 AMAP_SET_BITS(struct amap_iscsi_wrb, lun, pwrb,
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05004565 cpu_to_be16(*(unsigned short *)
4566 &io_task->cmd_bhs->iscsi_hdr.lun));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304567 AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, xferlen);
4568 AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
4569 io_task->pwrb_handle->wrb_index);
4570 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
4571 be32_to_cpu(task->cmdsn));
4572 AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
4573 io_task->psgl_handle->sgl_index);
4574
4575 hwi_write_sgl(pwrb, sg, num_sg, io_task);
4576
4577 AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
4578 io_task->pwrb_handle->nxt_wrb_index);
4579 be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
4580
4581 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304582 doorbell |= (io_task->pwrb_handle->wrb_index &
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304583 DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
4584 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
4585
4586 iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
4587 return 0;
4588}
4589
4590static int beiscsi_mtask(struct iscsi_task *task)
4591{
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05304592 struct beiscsi_io_task *io_task = task->dd_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304593 struct iscsi_conn *conn = task->conn;
4594 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4595 struct beiscsi_hba *phba = beiscsi_conn->phba;
4596 struct iscsi_wrb *pwrb = NULL;
4597 unsigned int doorbell = 0;
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05304598 unsigned int cid;
John Soni Jose09a10932012-10-20 04:44:23 +05304599 unsigned int pwrb_typeoffset = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304600
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304601 cid = beiscsi_conn->beiscsi_conn_cid;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304602 pwrb = io_task->pwrb_handle->pwrb;
Jayamohan Kallickalcaf818f2010-01-23 05:38:18 +05304603 memset(pwrb, 0, sizeof(*pwrb));
John Soni Jose09a10932012-10-20 04:44:23 +05304604
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004605 if (is_chip_be2_be3r(phba)) {
John Soni Jose09a10932012-10-20 04:44:23 +05304606 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
4607 be32_to_cpu(task->cmdsn));
4608 AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
4609 io_task->pwrb_handle->wrb_index);
4610 AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
4611 io_task->psgl_handle->sgl_index);
4612 AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb,
4613 task->data_count);
4614 AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
4615 io_task->pwrb_handle->nxt_wrb_index);
4616 pwrb_typeoffset = BE_WRB_TYPE_OFFSET;
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004617 } else {
4618 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb,
4619 be32_to_cpu(task->cmdsn));
4620 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb,
4621 io_task->pwrb_handle->wrb_index);
4622 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb,
4623 io_task->psgl_handle->sgl_index);
4624 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb,
4625 task->data_count);
4626 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb,
4627 io_task->pwrb_handle->nxt_wrb_index);
4628 pwrb_typeoffset = SKH_WRB_TYPE_OFFSET;
John Soni Jose09a10932012-10-20 04:44:23 +05304629 }
4630
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05304631
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304632 switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
4633 case ISCSI_OP_LOGIN:
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304634 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, 1);
John Soni Jose09a10932012-10-20 04:44:23 +05304635 ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304636 hwi_write_buffer(pwrb, task);
4637 break;
4638 case ISCSI_OP_NOOP_OUT:
Jayamohan Kallickal1390b012011-03-25 14:24:01 -07004639 if (task->hdr->ttt != ISCSI_RESERVED_TAG) {
John Soni Jose09a10932012-10-20 04:44:23 +05304640 ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset);
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004641 if (is_chip_be2_be3r(phba))
4642 AMAP_SET_BITS(struct amap_iscsi_wrb,
John Soni Jose09a10932012-10-20 04:44:23 +05304643 dmsg, pwrb, 1);
4644 else
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004645 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
John Soni Jose09a10932012-10-20 04:44:23 +05304646 dmsg, pwrb, 1);
Jayamohan Kallickal1390b012011-03-25 14:24:01 -07004647 } else {
John Soni Jose09a10932012-10-20 04:44:23 +05304648 ADAPTER_SET_WRB_TYPE(pwrb, INI_RD_CMD, pwrb_typeoffset);
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004649 if (is_chip_be2_be3r(phba))
4650 AMAP_SET_BITS(struct amap_iscsi_wrb,
John Soni Jose09a10932012-10-20 04:44:23 +05304651 dmsg, pwrb, 0);
4652 else
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004653 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
John Soni Jose09a10932012-10-20 04:44:23 +05304654 dmsg, pwrb, 0);
Jayamohan Kallickal1390b012011-03-25 14:24:01 -07004655 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304656 hwi_write_buffer(pwrb, task);
4657 break;
4658 case ISCSI_OP_TEXT:
John Soni Jose09a10932012-10-20 04:44:23 +05304659 ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304660 hwi_write_buffer(pwrb, task);
4661 break;
4662 case ISCSI_OP_SCSI_TMFUNC:
John Soni Jose09a10932012-10-20 04:44:23 +05304663 ADAPTER_SET_WRB_TYPE(pwrb, INI_TMF_CMD, pwrb_typeoffset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304664 hwi_write_buffer(pwrb, task);
4665 break;
4666 case ISCSI_OP_LOGOUT:
John Soni Jose09a10932012-10-20 04:44:23 +05304667 ADAPTER_SET_WRB_TYPE(pwrb, HWH_TYPE_LOGOUT, pwrb_typeoffset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304668 hwi_write_buffer(pwrb, task);
4669 break;
4670
4671 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +05304672 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
4673 "BM_%d : opcode =%d Not supported\n",
4674 task->hdr->opcode & ISCSI_OPCODE_MASK);
4675
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304676 return -EINVAL;
4677 }
4678
John Soni Jose09a10932012-10-20 04:44:23 +05304679 /* Set the task type */
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004680 io_task->wrb_type = (is_chip_be2_be3r(phba)) ?
4681 AMAP_GET_BITS(struct amap_iscsi_wrb, type, pwrb) :
4682 AMAP_GET_BITS(struct amap_iscsi_wrb_v2, type, pwrb);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304683
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304684 doorbell |= cid & DB_WRB_POST_CID_MASK;
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304685 doorbell |= (io_task->pwrb_handle->wrb_index &
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304686 DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
4687 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
4688 iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
4689 return 0;
4690}
4691
4692static int beiscsi_task_xmit(struct iscsi_task *task)
4693{
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304694 struct beiscsi_io_task *io_task = task->dd_data;
4695 struct scsi_cmnd *sc = task->sc;
John Soni Jose09a10932012-10-20 04:44:23 +05304696 struct beiscsi_hba *phba = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304697 struct scatterlist *sg;
4698 int num_sg;
4699 unsigned int writedir = 0, xferlen = 0;
4700
John Soni Jose09a10932012-10-20 04:44:23 +05304701 phba = ((struct beiscsi_conn *)task->conn->dd_data)->phba;
4702
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304703 if (!sc)
4704 return beiscsi_mtask(task);
4705
4706 io_task->scsi_cmnd = sc;
4707 num_sg = scsi_dma_map(sc);
4708 if (num_sg < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304709 struct iscsi_conn *conn = task->conn;
4710 struct beiscsi_hba *phba = NULL;
4711
4712 phba = ((struct beiscsi_conn *)conn->dd_data)->phba;
4713 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_IO,
4714 "BM_%d : scsi_dma_map Failed\n");
4715
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304716 return num_sg;
4717 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304718 xferlen = scsi_bufflen(sc);
4719 sg = scsi_sglist(sc);
John Soni Jose99bc5d52012-08-20 23:00:18 +05304720 if (sc->sc_data_direction == DMA_TO_DEVICE)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304721 writedir = 1;
John Soni Jose99bc5d52012-08-20 23:00:18 +05304722 else
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304723 writedir = 0;
John Soni Jose99bc5d52012-08-20 23:00:18 +05304724
John Soni Jose09a10932012-10-20 04:44:23 +05304725 return phba->iotask_fn(task, sg, num_sg, xferlen, writedir);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304726}
4727
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05004728/**
4729 * beiscsi_bsg_request - handle bsg request from ISCSI transport
4730 * @job: job to handle
4731 */
4732static int beiscsi_bsg_request(struct bsg_job *job)
4733{
4734 struct Scsi_Host *shost;
4735 struct beiscsi_hba *phba;
4736 struct iscsi_bsg_request *bsg_req = job->request;
4737 int rc = -EINVAL;
4738 unsigned int tag;
4739 struct be_dma_mem nonemb_cmd;
4740 struct be_cmd_resp_hdr *resp;
4741 struct iscsi_bsg_reply *bsg_reply = job->reply;
4742 unsigned short status, extd_status;
4743
4744 shost = iscsi_job_to_shost(job);
4745 phba = iscsi_host_priv(shost);
4746
4747 switch (bsg_req->msgcode) {
4748 case ISCSI_BSG_HST_VENDOR:
4749 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
4750 job->request_payload.payload_len,
4751 &nonemb_cmd.dma);
4752 if (nonemb_cmd.va == NULL) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304753 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
4754 "BM_%d : Failed to allocate memory for "
4755 "beiscsi_bsg_request\n");
John Soni Jose8359c792012-10-20 04:43:03 +05304756 return -ENOMEM;
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05004757 }
4758 tag = mgmt_vendor_specific_fw_cmd(&phba->ctrl, phba, job,
4759 &nonemb_cmd);
4760 if (!tag) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304761 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
John Soni Jose8359c792012-10-20 04:43:03 +05304762 "BM_%d : MBX Tag Allocation Failed\n");
John Soni Jose99bc5d52012-08-20 23:00:18 +05304763
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05004764 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
4765 nonemb_cmd.va, nonemb_cmd.dma);
4766 return -EAGAIN;
John Soni Josee175def2012-10-20 04:45:40 +05304767 }
4768
4769 rc = wait_event_interruptible_timeout(
4770 phba->ctrl.mcc_wait[tag],
4771 phba->ctrl.mcc_numtag[tag],
4772 msecs_to_jiffies(
4773 BEISCSI_HOST_MBX_TIMEOUT));
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05004774 extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
4775 status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
4776 free_mcc_tag(&phba->ctrl, tag);
4777 resp = (struct be_cmd_resp_hdr *)nonemb_cmd.va;
4778 sg_copy_from_buffer(job->reply_payload.sg_list,
4779 job->reply_payload.sg_cnt,
4780 nonemb_cmd.va, (resp->response_length
4781 + sizeof(*resp)));
4782 bsg_reply->reply_payload_rcv_len = resp->response_length;
4783 bsg_reply->result = status;
4784 bsg_job_done(job, bsg_reply->result,
4785 bsg_reply->reply_payload_rcv_len);
4786 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
4787 nonemb_cmd.va, nonemb_cmd.dma);
4788 if (status || extd_status) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304789 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
John Soni Jose8359c792012-10-20 04:43:03 +05304790 "BM_%d : MBX Cmd Failed"
John Soni Jose99bc5d52012-08-20 23:00:18 +05304791 " status = %d extd_status = %d\n",
4792 status, extd_status);
4793
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05004794 return -EIO;
John Soni Jose8359c792012-10-20 04:43:03 +05304795 } else {
4796 rc = 0;
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05004797 }
4798 break;
4799
4800 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +05304801 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
4802 "BM_%d : Unsupported bsg command: 0x%x\n",
4803 bsg_req->msgcode);
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05004804 break;
4805 }
4806
4807 return rc;
4808}
4809
John Soni Jose99bc5d52012-08-20 23:00:18 +05304810void beiscsi_hba_attrs_init(struct beiscsi_hba *phba)
4811{
4812 /* Set the logging parameter */
4813 beiscsi_log_enable_init(phba, beiscsi_log_enable);
4814}
4815
John Soni Jose4d4d1ef2012-10-20 04:42:37 +05304816/*
4817 * beiscsi_quiesce()- Cleanup Driver resources
4818 * @phba: Instance Priv structure
4819 *
4820 * Free the OS and HW resources held by the driver
4821 **/
Jayamohan Kallickal25602c92011-08-22 10:08:28 -07004822static void beiscsi_quiesce(struct beiscsi_hba *phba)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304823{
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304824 struct hwi_controller *phwi_ctrlr;
4825 struct hwi_context_memory *phwi_context;
4826 struct be_eq_obj *pbe_eq;
4827 unsigned int i, msix_vec;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304828
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304829 phwi_ctrlr = phba->phwi_ctrlr;
4830 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304831 hwi_disable_intr(phba);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304832 if (phba->msix_enabled) {
4833 for (i = 0; i <= phba->num_cpus; i++) {
4834 msix_vec = phba->msix_entries[i].vector;
4835 free_irq(msix_vec, &phwi_context->be_eq[i]);
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -07004836 kfree(phba->msi_name[i]);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304837 }
4838 } else
4839 if (phba->pcidev->irq)
4840 free_irq(phba->pcidev->irq, phba);
4841 pci_disable_msix(phba->pcidev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304842 destroy_workqueue(phba->wq);
4843 if (blk_iopoll_enabled)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304844 for (i = 0; i < phba->num_cpus; i++) {
4845 pbe_eq = &phwi_context->be_eq[i];
4846 blk_iopoll_disable(&pbe_eq->iopoll);
4847 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304848
4849 beiscsi_clean_port(phba);
4850 beiscsi_free_mem(phba);
Jayamohan Kallickale9b91192010-07-22 04:24:53 +05304851
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304852 beiscsi_unmap_pci_function(phba);
4853 pci_free_consistent(phba->pcidev,
4854 phba->ctrl.mbox_mem_alloced.size,
4855 phba->ctrl.mbox_mem_alloced.va,
4856 phba->ctrl.mbox_mem_alloced.dma);
John Soni Jose7a158002012-10-20 04:45:51 +05304857
4858 cancel_delayed_work_sync(&phba->beiscsi_hw_check_task);
Jayamohan Kallickal25602c92011-08-22 10:08:28 -07004859}
4860
4861static void beiscsi_remove(struct pci_dev *pcidev)
4862{
4863
4864 struct beiscsi_hba *phba = NULL;
4865
4866 phba = pci_get_drvdata(pcidev);
4867 if (!phba) {
4868 dev_err(&pcidev->dev, "beiscsi_remove called with no phba\n");
4869 return;
4870 }
4871
Mike Christie0e438952012-04-03 23:41:51 -05004872 beiscsi_destroy_def_ifaces(phba);
Jayamohan Kallickal25602c92011-08-22 10:08:28 -07004873 beiscsi_quiesce(phba);
Mike Christie9d045162011-06-24 15:11:52 -05004874 iscsi_boot_destroy_kset(phba->boot_kset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304875 iscsi_host_remove(phba->shost);
4876 pci_dev_put(phba->pcidev);
4877 iscsi_host_free(phba->shost);
Jayamohan Kallickal8dce69f2011-08-22 10:08:29 -07004878 pci_disable_device(pcidev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304879}
4880
Jayamohan Kallickal25602c92011-08-22 10:08:28 -07004881static void beiscsi_shutdown(struct pci_dev *pcidev)
4882{
4883
4884 struct beiscsi_hba *phba = NULL;
4885
4886 phba = (struct beiscsi_hba *)pci_get_drvdata(pcidev);
4887 if (!phba) {
4888 dev_err(&pcidev->dev, "beiscsi_shutdown called with no phba\n");
4889 return;
4890 }
4891
4892 beiscsi_quiesce(phba);
Jayamohan Kallickal8dce69f2011-08-22 10:08:29 -07004893 pci_disable_device(pcidev);
Jayamohan Kallickal25602c92011-08-22 10:08:28 -07004894}
4895
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304896static void beiscsi_msix_enable(struct beiscsi_hba *phba)
4897{
4898 int i, status;
4899
4900 for (i = 0; i <= phba->num_cpus; i++)
4901 phba->msix_entries[i].entry = i;
4902
4903 status = pci_enable_msix(phba->pcidev, phba->msix_entries,
4904 (phba->num_cpus + 1));
4905 if (!status)
4906 phba->msix_enabled = true;
4907
4908 return;
4909}
4910
John Soni Jose7a158002012-10-20 04:45:51 +05304911/*
4912 * beiscsi_hw_health_check()- Check adapter health
4913 * @work: work item to check HW health
4914 *
4915 * Check if adapter in an unrecoverable state or not.
4916 **/
4917static void
4918beiscsi_hw_health_check(struct work_struct *work)
4919{
4920 struct beiscsi_hba *phba =
4921 container_of(work, struct beiscsi_hba,
4922 beiscsi_hw_check_task.work);
4923
4924 beiscsi_ue_detect(phba);
4925
4926 schedule_delayed_work(&phba->beiscsi_hw_check_task,
4927 msecs_to_jiffies(1000));
4928}
4929
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08004930static int beiscsi_dev_probe(struct pci_dev *pcidev,
4931 const struct pci_device_id *id)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304932{
4933 struct beiscsi_hba *phba = NULL;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304934 struct hwi_controller *phwi_ctrlr;
4935 struct hwi_context_memory *phwi_context;
4936 struct be_eq_obj *pbe_eq;
John Soni Jose107dfcb2012-10-20 04:42:13 +05304937 int ret, i;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304938
4939 ret = beiscsi_enable_pci(pcidev);
4940 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304941 dev_err(&pcidev->dev,
4942 "beiscsi_dev_probe - Failed to enable pci device\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304943 return ret;
4944 }
4945
4946 phba = beiscsi_hba_alloc(pcidev);
4947 if (!phba) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304948 dev_err(&pcidev->dev,
4949 "beiscsi_dev_probe - Failed in beiscsi_hba_alloc\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304950 goto disable_pci;
4951 }
4952
John Soni Jose99bc5d52012-08-20 23:00:18 +05304953 /* Initialize Driver configuration Paramters */
4954 beiscsi_hba_attrs_init(phba);
4955
John Soni Josee175def2012-10-20 04:45:40 +05304956 phba->fw_timeout = false;
Jayamohan Kallickal6c831852013-09-28 15:35:40 -07004957 phba->mac_addr_set = false;
John Soni Josee175def2012-10-20 04:45:40 +05304958
4959
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +05304960 switch (pcidev->device) {
4961 case BE_DEVICE_ID1:
4962 case OC_DEVICE_ID1:
4963 case OC_DEVICE_ID2:
4964 phba->generation = BE_GEN2;
John Soni Jose09a10932012-10-20 04:44:23 +05304965 phba->iotask_fn = beiscsi_iotask;
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +05304966 break;
4967 case BE_DEVICE_ID2:
4968 case OC_DEVICE_ID3:
4969 phba->generation = BE_GEN3;
John Soni Jose09a10932012-10-20 04:44:23 +05304970 phba->iotask_fn = beiscsi_iotask;
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +05304971 break;
John Soni Jose139a1b12012-10-20 04:43:20 +05304972 case OC_SKH_ID1:
4973 phba->generation = BE_GEN4;
John Soni Jose09a10932012-10-20 04:44:23 +05304974 phba->iotask_fn = beiscsi_iotask_v2;
Jayamohan Kallickalbf9131c2013-04-05 20:38:24 -07004975 break;
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +05304976 default:
4977 phba->generation = 0;
4978 }
4979
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304980 if (enable_msix)
John Soni Jose107dfcb2012-10-20 04:42:13 +05304981 find_num_cpus(phba);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304982 else
John Soni Jose107dfcb2012-10-20 04:42:13 +05304983 phba->num_cpus = 1;
4984
John Soni Jose99bc5d52012-08-20 23:00:18 +05304985 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4986 "BM_%d : num_cpus = %d\n",
4987 phba->num_cpus);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304988
Jayamohan Kallickalb547f2d2012-04-03 23:41:41 -05004989 if (enable_msix) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304990 beiscsi_msix_enable(phba);
Jayamohan Kallickalb547f2d2012-04-03 23:41:41 -05004991 if (!phba->msix_enabled)
4992 phba->num_cpus = 1;
4993 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304994 ret = be_ctrl_init(phba, pcidev);
4995 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304996 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4997 "BM_%d : beiscsi_dev_probe-"
4998 "Failed in be_ctrl_init\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304999 goto hba_free;
5000 }
5001
John Soni Jose4d4d1ef2012-10-20 04:42:37 +05305002 ret = beiscsi_cmd_reset_function(phba);
5003 if (ret) {
5004 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5005 "BM_%d : Reset Failed. Aborting Crashdump\n");
5006 goto hba_free;
5007 }
5008 ret = be_chk_reset_complete(phba);
5009 if (ret) {
5010 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5011 "BM_%d : Failed to get out of reset."
5012 "Aborting Crashdump\n");
5013 goto hba_free;
Jayamohan Kallickale9b91192010-07-22 04:24:53 +05305014 }
5015
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305016 spin_lock_init(&phba->io_sgl_lock);
5017 spin_lock_init(&phba->mgmt_sgl_lock);
5018 spin_lock_init(&phba->isr_lock);
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07005019 spin_lock_init(&phba->async_pdu_lock);
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05305020 ret = mgmt_get_fw_config(&phba->ctrl, phba);
5021 if (ret != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305022 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5023 "BM_%d : Error getting fw config\n");
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05305024 goto free_port;
5025 }
5026 phba->shost->max_id = phba->fw_config.iscsi_cid_count;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305027 beiscsi_get_params(phba);
Jayamohan Kallickalaa874f02010-01-05 05:12:03 +05305028 phba->shost->can_queue = phba->params.ios_per_ctrl;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305029 ret = beiscsi_init_port(phba);
5030 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305031 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5032 "BM_%d : beiscsi_dev_probe-"
5033 "Failed in beiscsi_init_port\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305034 goto free_port;
5035 }
5036
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05305037 for (i = 0; i < MAX_MCC_CMD ; i++) {
5038 init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]);
5039 phba->ctrl.mcc_tag[i] = i + 1;
5040 phba->ctrl.mcc_numtag[i + 1] = 0;
5041 phba->ctrl.mcc_tag_available++;
5042 }
5043
5044 phba->ctrl.mcc_alloc_index = phba->ctrl.mcc_free_index = 0;
5045
John Soni Jose72fb46a2012-10-20 04:42:49 +05305046 snprintf(phba->wq_name, sizeof(phba->wq_name), "beiscsi_%02x_wq",
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305047 phba->shost->host_no);
Kees Cookd8537542013-07-03 15:04:57 -07005048 phba->wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 1, phba->wq_name);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305049 if (!phba->wq) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305050 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5051 "BM_%d : beiscsi_dev_probe-"
5052 "Failed to allocate work queue\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305053 goto free_twq;
5054 }
5055
John Soni Jose7a158002012-10-20 04:45:51 +05305056 INIT_DELAYED_WORK(&phba->beiscsi_hw_check_task,
5057 beiscsi_hw_health_check);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305058
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305059 phwi_ctrlr = phba->phwi_ctrlr;
5060 phwi_context = phwi_ctrlr->phwi_ctxt;
John Soni Jose72fb46a2012-10-20 04:42:49 +05305061
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305062 if (blk_iopoll_enabled) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305063 for (i = 0; i < phba->num_cpus; i++) {
5064 pbe_eq = &phwi_context->be_eq[i];
5065 blk_iopoll_init(&pbe_eq->iopoll, be_iopoll_budget,
5066 be_iopoll);
5067 blk_iopoll_enable(&pbe_eq->iopoll);
5068 }
John Soni Jose72fb46a2012-10-20 04:42:49 +05305069
5070 i = (phba->msix_enabled) ? i : 0;
5071 /* Work item for MCC handling */
5072 pbe_eq = &phwi_context->be_eq[i];
5073 INIT_WORK(&pbe_eq->work_cqs, beiscsi_process_all_cqs);
5074 } else {
5075 if (phba->msix_enabled) {
5076 for (i = 0; i <= phba->num_cpus; i++) {
5077 pbe_eq = &phwi_context->be_eq[i];
5078 INIT_WORK(&pbe_eq->work_cqs,
5079 beiscsi_process_all_cqs);
5080 }
5081 } else {
5082 pbe_eq = &phwi_context->be_eq[0];
5083 INIT_WORK(&pbe_eq->work_cqs,
5084 beiscsi_process_all_cqs);
5085 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305086 }
John Soni Jose72fb46a2012-10-20 04:42:49 +05305087
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305088 ret = beiscsi_init_irqs(phba);
5089 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305090 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5091 "BM_%d : beiscsi_dev_probe-"
5092 "Failed to beiscsi_init_irqs\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305093 goto free_blkenbld;
5094 }
Jayamohan Kallickal238f6b72010-07-22 04:23:22 +05305095 hwi_enable_intr(phba);
Mike Christief457a462011-06-24 15:11:53 -05005096
5097 if (beiscsi_setup_boot_info(phba))
5098 /*
5099 * log error but continue, because we may not be using
5100 * iscsi boot.
5101 */
John Soni Jose99bc5d52012-08-20 23:00:18 +05305102 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5103 "BM_%d : Could not set up "
5104 "iSCSI boot info.\n");
Mike Christief457a462011-06-24 15:11:53 -05005105
Mike Christie0e438952012-04-03 23:41:51 -05005106 beiscsi_create_def_ifaces(phba);
John Soni Jose7a158002012-10-20 04:45:51 +05305107 schedule_delayed_work(&phba->beiscsi_hw_check_task,
5108 msecs_to_jiffies(1000));
5109
John Soni Jose99bc5d52012-08-20 23:00:18 +05305110 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
5111 "\n\n\n BM_%d : SUCCESS - DRIVER LOADED\n\n\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305112 return 0;
5113
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305114free_blkenbld:
5115 destroy_workqueue(phba->wq);
5116 if (blk_iopoll_enabled)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305117 for (i = 0; i < phba->num_cpus; i++) {
5118 pbe_eq = &phwi_context->be_eq[i];
5119 blk_iopoll_disable(&pbe_eq->iopoll);
5120 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305121free_twq:
5122 beiscsi_clean_port(phba);
5123 beiscsi_free_mem(phba);
5124free_port:
5125 pci_free_consistent(phba->pcidev,
5126 phba->ctrl.mbox_mem_alloced.size,
5127 phba->ctrl.mbox_mem_alloced.va,
5128 phba->ctrl.mbox_mem_alloced.dma);
5129 beiscsi_unmap_pci_function(phba);
5130hba_free:
Jayamohan Kallickal238f6b72010-07-22 04:23:22 +05305131 if (phba->msix_enabled)
5132 pci_disable_msix(phba->pcidev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305133 iscsi_host_remove(phba->shost);
5134 pci_dev_put(phba->pcidev);
5135 iscsi_host_free(phba->shost);
5136disable_pci:
5137 pci_disable_device(pcidev);
5138 return ret;
5139}
5140
5141struct iscsi_transport beiscsi_iscsi_transport = {
5142 .owner = THIS_MODULE,
5143 .name = DRV_NAME,
Jayamohan Kallickal9db0fb32010-01-05 05:12:43 +05305144 .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_TEXT_NEGO |
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305145 CAP_MULTI_R2T | CAP_DATADGST | CAP_DATA_PATH_OFFLOAD,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305146 .create_session = beiscsi_session_create,
5147 .destroy_session = beiscsi_session_destroy,
5148 .create_conn = beiscsi_conn_create,
5149 .bind_conn = beiscsi_conn_bind,
5150 .destroy_conn = iscsi_conn_teardown,
Mike Christie3128c6c2011-07-25 13:48:42 -05005151 .attr_is_visible = be2iscsi_attr_is_visible,
Mike Christie0e438952012-04-03 23:41:51 -05005152 .set_iface_param = be2iscsi_iface_set_param,
5153 .get_iface_param = be2iscsi_iface_get_param,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305154 .set_param = beiscsi_set_param,
Mike Christiec7f7fd52011-02-16 15:04:41 -06005155 .get_conn_param = iscsi_conn_get_param,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305156 .get_session_param = iscsi_session_get_param,
5157 .get_host_param = beiscsi_get_host_param,
5158 .start_conn = beiscsi_conn_start,
Mike Christiefa95d202010-06-09 03:30:08 -05005159 .stop_conn = iscsi_conn_stop,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305160 .send_pdu = iscsi_conn_send_pdu,
5161 .xmit_task = beiscsi_task_xmit,
5162 .cleanup_task = beiscsi_cleanup_task,
5163 .alloc_pdu = beiscsi_alloc_pdu,
5164 .parse_pdu_itt = beiscsi_parse_pdu,
5165 .get_stats = beiscsi_conn_get_stats,
Mike Christiec7f7fd52011-02-16 15:04:41 -06005166 .get_ep_param = beiscsi_ep_get_param,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305167 .ep_connect = beiscsi_ep_connect,
5168 .ep_poll = beiscsi_ep_poll,
5169 .ep_disconnect = beiscsi_ep_disconnect,
5170 .session_recovery_timedout = iscsi_session_recovery_timedout,
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05005171 .bsg_request = beiscsi_bsg_request,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305172};
5173
5174static struct pci_driver beiscsi_pci_driver = {
5175 .name = DRV_NAME,
5176 .probe = beiscsi_dev_probe,
5177 .remove = beiscsi_remove,
Jayamohan Kallickal25602c92011-08-22 10:08:28 -07005178 .shutdown = beiscsi_shutdown,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305179 .id_table = beiscsi_pci_id_table
5180};
5181
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305182
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305183static int __init beiscsi_module_init(void)
5184{
5185 int ret;
5186
5187 beiscsi_scsi_transport =
5188 iscsi_register_transport(&beiscsi_iscsi_transport);
5189 if (!beiscsi_scsi_transport) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305190 printk(KERN_ERR
5191 "beiscsi_module_init - Unable to register beiscsi transport.\n");
Jayamohan Kallickalf55a24f2010-01-23 05:37:40 +05305192 return -ENOMEM;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305193 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05305194 printk(KERN_INFO "In beiscsi_module_init, tt=%p\n",
5195 &beiscsi_iscsi_transport);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305196
5197 ret = pci_register_driver(&beiscsi_pci_driver);
5198 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305199 printk(KERN_ERR
5200 "beiscsi_module_init - Unable to register beiscsi pci driver.\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305201 goto unregister_iscsi_transport;
5202 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305203 return 0;
5204
5205unregister_iscsi_transport:
5206 iscsi_unregister_transport(&beiscsi_iscsi_transport);
5207 return ret;
5208}
5209
5210static void __exit beiscsi_module_exit(void)
5211{
5212 pci_unregister_driver(&beiscsi_pci_driver);
5213 iscsi_unregister_transport(&beiscsi_iscsi_transport);
5214}
5215
5216module_init(beiscsi_module_init);
5217module_exit(beiscsi_module_exit);