blob: 7e470a322e3593ebb8330e4813871083b1c7b39f [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"
Jayamohan Kallickalafb96052013-09-28 15:35:55 -0700152 "\t\t\t\tConfiguration Path : 0x20\n"
153 "\t\t\t\tiSCSI Protocol : 0x40\n");
John Soni Jose99bc5d52012-08-20 23:00:18 +0530154
John Soni Jose5cac7592012-10-20 04:42:25 +0530155DEVICE_ATTR(beiscsi_drvr_ver, S_IRUGO, beiscsi_drvr_ver_disp, NULL);
John Soni Jose26000db2012-10-20 04:45:06 +0530156DEVICE_ATTR(beiscsi_adapter_family, S_IRUGO, beiscsi_adap_family_disp, NULL);
Jayamohan Kallickal22661e22013-04-05 20:38:28 -0700157DEVICE_ATTR(beiscsi_fw_ver, S_IRUGO, beiscsi_fw_ver_disp, NULL);
Jayamohan Kallickald3fea9a2013-09-28 15:35:53 -0700158DEVICE_ATTR(beiscsi_phys_port, S_IRUGO, beiscsi_phys_port_disp, NULL);
Jayamohan Kallickal6103c1f2013-09-28 15:35:52 -0700159DEVICE_ATTR(beiscsi_active_session_count, S_IRUGO,
160 beiscsi_active_session_disp, NULL);
161DEVICE_ATTR(beiscsi_free_session_count, S_IRUGO,
162 beiscsi_free_session_disp, NULL);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530163struct device_attribute *beiscsi_attrs[] = {
164 &dev_attr_beiscsi_log_enable,
John Soni Jose5cac7592012-10-20 04:42:25 +0530165 &dev_attr_beiscsi_drvr_ver,
John Soni Jose26000db2012-10-20 04:45:06 +0530166 &dev_attr_beiscsi_adapter_family,
Jayamohan Kallickal22661e22013-04-05 20:38:28 -0700167 &dev_attr_beiscsi_fw_ver,
Jayamohan Kallickal6103c1f2013-09-28 15:35:52 -0700168 &dev_attr_beiscsi_active_session_count,
169 &dev_attr_beiscsi_free_session_count,
Jayamohan Kallickald3fea9a2013-09-28 15:35:53 -0700170 &dev_attr_beiscsi_phys_port,
John Soni Jose99bc5d52012-08-20 23:00:18 +0530171 NULL,
172};
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530173
John Soni Jose6763daa2012-10-20 04:41:45 +0530174static char const *cqe_desc[] = {
175 "RESERVED_DESC",
176 "SOL_CMD_COMPLETE",
177 "SOL_CMD_KILLED_DATA_DIGEST_ERR",
178 "CXN_KILLED_PDU_SIZE_EXCEEDS_DSL",
179 "CXN_KILLED_BURST_LEN_MISMATCH",
180 "CXN_KILLED_AHS_RCVD",
181 "CXN_KILLED_HDR_DIGEST_ERR",
182 "CXN_KILLED_UNKNOWN_HDR",
183 "CXN_KILLED_STALE_ITT_TTT_RCVD",
184 "CXN_KILLED_INVALID_ITT_TTT_RCVD",
185 "CXN_KILLED_RST_RCVD",
186 "CXN_KILLED_TIMED_OUT",
187 "CXN_KILLED_RST_SENT",
188 "CXN_KILLED_FIN_RCVD",
189 "CXN_KILLED_BAD_UNSOL_PDU_RCVD",
190 "CXN_KILLED_BAD_WRB_INDEX_ERROR",
191 "CXN_KILLED_OVER_RUN_RESIDUAL",
192 "CXN_KILLED_UNDER_RUN_RESIDUAL",
193 "CMD_KILLED_INVALID_STATSN_RCVD",
194 "CMD_KILLED_INVALID_R2T_RCVD",
195 "CMD_CXN_KILLED_LUN_INVALID",
196 "CMD_CXN_KILLED_ICD_INVALID",
197 "CMD_CXN_KILLED_ITT_INVALID",
198 "CMD_CXN_KILLED_SEQ_OUTOFORDER",
199 "CMD_CXN_KILLED_INVALID_DATASN_RCVD",
200 "CXN_INVALIDATE_NOTIFY",
201 "CXN_INVALIDATE_INDEX_NOTIFY",
202 "CMD_INVALIDATED_NOTIFY",
203 "UNSOL_HDR_NOTIFY",
204 "UNSOL_DATA_NOTIFY",
205 "UNSOL_DATA_DIGEST_ERROR_NOTIFY",
206 "DRIVERMSG_NOTIFY",
207 "CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN",
208 "SOL_CMD_KILLED_DIF_ERR",
209 "CXN_KILLED_SYN_RCVD",
210 "CXN_KILLED_IMM_DATA_RCVD"
211};
212
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530213static int beiscsi_slave_configure(struct scsi_device *sdev)
214{
215 blk_queue_max_segment_size(sdev->request_queue, 65536);
216 return 0;
217}
218
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530219static int beiscsi_eh_abort(struct scsi_cmnd *sc)
220{
221 struct iscsi_cls_session *cls_session;
222 struct iscsi_task *aborted_task = (struct iscsi_task *)sc->SCp.ptr;
223 struct beiscsi_io_task *aborted_io_task;
224 struct iscsi_conn *conn;
225 struct beiscsi_conn *beiscsi_conn;
226 struct beiscsi_hba *phba;
227 struct iscsi_session *session;
228 struct invalidate_command_table *inv_tbl;
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530229 struct be_dma_mem nonemb_cmd;
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530230 unsigned int cid, tag, num_invalidate;
231
232 cls_session = starget_to_session(scsi_target(sc->device));
233 session = cls_session->dd_data;
234
235 spin_lock_bh(&session->lock);
236 if (!aborted_task || !aborted_task->sc) {
237 /* we raced */
238 spin_unlock_bh(&session->lock);
239 return SUCCESS;
240 }
241
242 aborted_io_task = aborted_task->dd_data;
243 if (!aborted_io_task->scsi_cmnd) {
244 /* raced or invalid command */
245 spin_unlock_bh(&session->lock);
246 return SUCCESS;
247 }
248 spin_unlock_bh(&session->lock);
249 conn = aborted_task->conn;
250 beiscsi_conn = conn->dd_data;
251 phba = beiscsi_conn->phba;
252
253 /* invalidate iocb */
254 cid = beiscsi_conn->beiscsi_conn_cid;
255 inv_tbl = phba->inv_tbl;
256 memset(inv_tbl, 0x0, sizeof(*inv_tbl));
257 inv_tbl->cid = cid;
258 inv_tbl->icd = aborted_io_task->psgl_handle->sgl_index;
259 num_invalidate = 1;
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530260 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
261 sizeof(struct invalidate_commands_params_in),
262 &nonemb_cmd.dma);
263 if (nonemb_cmd.va == NULL) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530264 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
265 "BM_%d : Failed to allocate memory for"
266 "mgmt_invalidate_icds\n");
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530267 return FAILED;
268 }
269 nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
270
271 tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
272 cid, &nonemb_cmd);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530273 if (!tag) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530274 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH,
275 "BM_%d : mgmt_invalidate_icds could not be"
276 "submitted\n");
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530277 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
278 nonemb_cmd.va, nonemb_cmd.dma);
279
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530280 return FAILED;
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530281 }
John Soni Josee175def2012-10-20 04:45:40 +0530282
283 beiscsi_mccq_compl(phba, tag, NULL, nonemb_cmd.va);
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530284 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
285 nonemb_cmd.va, nonemb_cmd.dma);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530286 return iscsi_eh_abort(sc);
287}
288
289static int beiscsi_eh_device_reset(struct scsi_cmnd *sc)
290{
291 struct iscsi_task *abrt_task;
292 struct beiscsi_io_task *abrt_io_task;
293 struct iscsi_conn *conn;
294 struct beiscsi_conn *beiscsi_conn;
295 struct beiscsi_hba *phba;
296 struct iscsi_session *session;
297 struct iscsi_cls_session *cls_session;
298 struct invalidate_command_table *inv_tbl;
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530299 struct be_dma_mem nonemb_cmd;
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530300 unsigned int cid, tag, i, num_invalidate;
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530301
302 /* invalidate iocbs */
303 cls_session = starget_to_session(scsi_target(sc->device));
304 session = cls_session->dd_data;
305 spin_lock_bh(&session->lock);
Jayamohan Kallickaldb7f7702012-04-03 23:41:43 -0500306 if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN) {
307 spin_unlock_bh(&session->lock);
308 return FAILED;
309 }
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530310 conn = session->leadconn;
311 beiscsi_conn = conn->dd_data;
312 phba = beiscsi_conn->phba;
313 cid = beiscsi_conn->beiscsi_conn_cid;
314 inv_tbl = phba->inv_tbl;
315 memset(inv_tbl, 0x0, sizeof(*inv_tbl) * BE2_CMDS_PER_CXN);
316 num_invalidate = 0;
317 for (i = 0; i < conn->session->cmds_max; i++) {
318 abrt_task = conn->session->cmds[i];
319 abrt_io_task = abrt_task->dd_data;
320 if (!abrt_task->sc || abrt_task->state == ISCSI_TASK_FREE)
321 continue;
322
323 if (abrt_task->sc->device->lun != abrt_task->sc->device->lun)
324 continue;
325
326 inv_tbl->cid = cid;
327 inv_tbl->icd = abrt_io_task->psgl_handle->sgl_index;
328 num_invalidate++;
329 inv_tbl++;
330 }
331 spin_unlock_bh(&session->lock);
332 inv_tbl = phba->inv_tbl;
333
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530334 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
335 sizeof(struct invalidate_commands_params_in),
336 &nonemb_cmd.dma);
337 if (nonemb_cmd.va == NULL) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530338 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
339 "BM_%d : Failed to allocate memory for"
340 "mgmt_invalidate_icds\n");
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530341 return FAILED;
342 }
343 nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
344 memset(nonemb_cmd.va, 0, nonemb_cmd.size);
345 tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
346 cid, &nonemb_cmd);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530347 if (!tag) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530348 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH,
349 "BM_%d : mgmt_invalidate_icds could not be"
350 " submitted\n");
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530351 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
352 nonemb_cmd.va, nonemb_cmd.dma);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530353 return FAILED;
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530354 }
John Soni Josee175def2012-10-20 04:45:40 +0530355
356 beiscsi_mccq_compl(phba, tag, NULL, nonemb_cmd.va);
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530357 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
358 nonemb_cmd.va, nonemb_cmd.dma);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530359 return iscsi_eh_device_reset(sc);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530360}
361
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530362static ssize_t beiscsi_show_boot_tgt_info(void *data, int type, char *buf)
363{
364 struct beiscsi_hba *phba = data;
Mike Christief457a462011-06-24 15:11:53 -0500365 struct mgmt_session_info *boot_sess = &phba->boot_sess;
366 struct mgmt_conn_info *boot_conn = &boot_sess->conn_list[0];
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530367 char *str = buf;
368 int rc;
369
370 switch (type) {
371 case ISCSI_BOOT_TGT_NAME:
372 rc = sprintf(buf, "%.*s\n",
Mike Christief457a462011-06-24 15:11:53 -0500373 (int)strlen(boot_sess->target_name),
374 (char *)&boot_sess->target_name);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530375 break;
376 case ISCSI_BOOT_TGT_IP_ADDR:
Mike Christief457a462011-06-24 15:11:53 -0500377 if (boot_conn->dest_ipaddr.ip_type == 0x1)
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530378 rc = sprintf(buf, "%pI4\n",
Mike Christie0e438952012-04-03 23:41:51 -0500379 (char *)&boot_conn->dest_ipaddr.addr);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530380 else
381 rc = sprintf(str, "%pI6\n",
Mike Christie0e438952012-04-03 23:41:51 -0500382 (char *)&boot_conn->dest_ipaddr.addr);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530383 break;
384 case ISCSI_BOOT_TGT_PORT:
Mike Christief457a462011-06-24 15:11:53 -0500385 rc = sprintf(str, "%d\n", boot_conn->dest_port);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530386 break;
387
388 case ISCSI_BOOT_TGT_CHAP_NAME:
389 rc = sprintf(str, "%.*s\n",
Mike Christief457a462011-06-24 15:11:53 -0500390 boot_conn->negotiated_login_options.auth_data.chap.
391 target_chap_name_length,
392 (char *)&boot_conn->negotiated_login_options.
393 auth_data.chap.target_chap_name);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530394 break;
395 case ISCSI_BOOT_TGT_CHAP_SECRET:
396 rc = sprintf(str, "%.*s\n",
Mike Christief457a462011-06-24 15:11:53 -0500397 boot_conn->negotiated_login_options.auth_data.chap.
398 target_secret_length,
399 (char *)&boot_conn->negotiated_login_options.
400 auth_data.chap.target_secret);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530401 break;
402 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
403 rc = sprintf(str, "%.*s\n",
Mike Christief457a462011-06-24 15:11:53 -0500404 boot_conn->negotiated_login_options.auth_data.chap.
405 intr_chap_name_length,
406 (char *)&boot_conn->negotiated_login_options.
407 auth_data.chap.intr_chap_name);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530408 break;
409 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
Mike Christief457a462011-06-24 15:11:53 -0500410 rc = sprintf(str, "%.*s\n",
411 boot_conn->negotiated_login_options.auth_data.chap.
412 intr_secret_length,
413 (char *)&boot_conn->negotiated_login_options.
414 auth_data.chap.intr_secret);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530415 break;
416 case ISCSI_BOOT_TGT_FLAGS:
Mike Christief457a462011-06-24 15:11:53 -0500417 rc = sprintf(str, "2\n");
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530418 break;
419 case ISCSI_BOOT_TGT_NIC_ASSOC:
Mike Christief457a462011-06-24 15:11:53 -0500420 rc = sprintf(str, "0\n");
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530421 break;
422 default:
423 rc = -ENOSYS;
424 break;
425 }
426 return rc;
427}
428
429static ssize_t beiscsi_show_boot_ini_info(void *data, int type, char *buf)
430{
431 struct beiscsi_hba *phba = data;
432 char *str = buf;
433 int rc;
434
435 switch (type) {
436 case ISCSI_BOOT_INI_INITIATOR_NAME:
437 rc = sprintf(str, "%s\n", phba->boot_sess.initiator_iscsiname);
438 break;
439 default:
440 rc = -ENOSYS;
441 break;
442 }
443 return rc;
444}
445
446static ssize_t beiscsi_show_boot_eth_info(void *data, int type, char *buf)
447{
448 struct beiscsi_hba *phba = data;
449 char *str = buf;
450 int rc;
451
452 switch (type) {
453 case ISCSI_BOOT_ETH_FLAGS:
Mike Christief457a462011-06-24 15:11:53 -0500454 rc = sprintf(str, "2\n");
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530455 break;
456 case ISCSI_BOOT_ETH_INDEX:
Mike Christief457a462011-06-24 15:11:53 -0500457 rc = sprintf(str, "0\n");
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530458 break;
459 case ISCSI_BOOT_ETH_MAC:
Mike Christie0e438952012-04-03 23:41:51 -0500460 rc = beiscsi_get_macaddr(str, phba);
461 break;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530462 default:
463 rc = -ENOSYS;
464 break;
465 }
466 return rc;
467}
468
469
Al Viro587a1f12011-07-23 23:11:19 -0400470static umode_t beiscsi_tgt_get_attr_visibility(void *data, int type)
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530471{
Al Viro587a1f12011-07-23 23:11:19 -0400472 umode_t rc;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530473
474 switch (type) {
475 case ISCSI_BOOT_TGT_NAME:
476 case ISCSI_BOOT_TGT_IP_ADDR:
477 case ISCSI_BOOT_TGT_PORT:
478 case ISCSI_BOOT_TGT_CHAP_NAME:
479 case ISCSI_BOOT_TGT_CHAP_SECRET:
480 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
481 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
482 case ISCSI_BOOT_TGT_NIC_ASSOC:
483 case ISCSI_BOOT_TGT_FLAGS:
484 rc = S_IRUGO;
485 break;
486 default:
487 rc = 0;
488 break;
489 }
490 return rc;
491}
492
Al Viro587a1f12011-07-23 23:11:19 -0400493static umode_t beiscsi_ini_get_attr_visibility(void *data, int type)
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530494{
Al Viro587a1f12011-07-23 23:11:19 -0400495 umode_t rc;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530496
497 switch (type) {
498 case ISCSI_BOOT_INI_INITIATOR_NAME:
499 rc = S_IRUGO;
500 break;
501 default:
502 rc = 0;
503 break;
504 }
505 return rc;
506}
507
508
Al Viro587a1f12011-07-23 23:11:19 -0400509static umode_t beiscsi_eth_get_attr_visibility(void *data, int type)
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530510{
Al Viro587a1f12011-07-23 23:11:19 -0400511 umode_t rc;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530512
513 switch (type) {
514 case ISCSI_BOOT_ETH_FLAGS:
515 case ISCSI_BOOT_ETH_MAC:
516 case ISCSI_BOOT_ETH_INDEX:
517 rc = S_IRUGO;
518 break;
519 default:
520 rc = 0;
521 break;
522 }
523 return rc;
524}
525
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530526/*------------------- PCI Driver operations and data ----------------- */
527static DEFINE_PCI_DEVICE_TABLE(beiscsi_pci_id_table) = {
528 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) },
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +0530529 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) },
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530530 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) },
531 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) },
532 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID3) },
John Soni Jose139a1b12012-10-20 04:43:20 +0530533 { PCI_DEVICE(ELX_VENDOR_ID, OC_SKH_ID1) },
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530534 { 0 }
535};
536MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
537
John Soni Jose99bc5d52012-08-20 23:00:18 +0530538
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530539static struct scsi_host_template beiscsi_sht = {
540 .module = THIS_MODULE,
Jayamohan Kallickal2f635882012-04-03 23:41:45 -0500541 .name = "Emulex 10Gbe open-iscsi Initiator Driver",
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530542 .proc_name = DRV_NAME,
543 .queuecommand = iscsi_queuecommand,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530544 .change_queue_depth = iscsi_change_queue_depth,
545 .slave_configure = beiscsi_slave_configure,
546 .target_alloc = iscsi_target_alloc,
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530547 .eh_abort_handler = beiscsi_eh_abort,
548 .eh_device_reset_handler = beiscsi_eh_device_reset,
Jayamohan Kallickal309ce152010-02-20 08:02:10 +0530549 .eh_target_reset_handler = iscsi_eh_session_reset,
John Soni Jose99bc5d52012-08-20 23:00:18 +0530550 .shost_attrs = beiscsi_attrs,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530551 .sg_tablesize = BEISCSI_SGLIST_ELEMENTS,
552 .can_queue = BE2_IO_DEPTH,
553 .this_id = -1,
554 .max_sectors = BEISCSI_MAX_SECTORS,
555 .cmd_per_lun = BEISCSI_CMD_PER_LUN,
556 .use_clustering = ENABLE_CLUSTERING,
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -0500557 .vendor_id = SCSI_NL_VID_TYPE_PCI | BE_VENDOR_ID,
558
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530559};
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530560
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530561static struct scsi_transport_template *beiscsi_scsi_transport;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530562
563static struct beiscsi_hba *beiscsi_hba_alloc(struct pci_dev *pcidev)
564{
565 struct beiscsi_hba *phba;
566 struct Scsi_Host *shost;
567
568 shost = iscsi_host_alloc(&beiscsi_sht, sizeof(*phba), 0);
569 if (!shost) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530570 dev_err(&pcidev->dev,
571 "beiscsi_hba_alloc - iscsi_host_alloc failed\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530572 return NULL;
573 }
574 shost->dma_boundary = pcidev->dma_mask;
575 shost->max_id = BE2_MAX_SESSIONS;
576 shost->max_channel = 0;
577 shost->max_cmd_len = BEISCSI_MAX_CMD_LEN;
578 shost->max_lun = BEISCSI_NUM_MAX_LUN;
579 shost->transportt = beiscsi_scsi_transport;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530580 phba = iscsi_host_priv(shost);
581 memset(phba, 0, sizeof(*phba));
582 phba->shost = shost;
583 phba->pcidev = pci_dev_get(pcidev);
Jayamohan Kallickal2807afb2010-01-05 05:07:49 +0530584 pci_set_drvdata(pcidev, phba);
Mike Christie0e438952012-04-03 23:41:51 -0500585 phba->interface_handle = 0xFFFFFFFF;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530586
587 if (iscsi_host_add(shost, &phba->pcidev->dev))
588 goto free_devices;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530589
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530590 return phba;
591
592free_devices:
593 pci_dev_put(phba->pcidev);
594 iscsi_host_free(phba->shost);
595 return NULL;
596}
597
598static void beiscsi_unmap_pci_function(struct beiscsi_hba *phba)
599{
600 if (phba->csr_va) {
601 iounmap(phba->csr_va);
602 phba->csr_va = NULL;
603 }
604 if (phba->db_va) {
605 iounmap(phba->db_va);
606 phba->db_va = NULL;
607 }
608 if (phba->pci_va) {
609 iounmap(phba->pci_va);
610 phba->pci_va = NULL;
611 }
612}
613
614static int beiscsi_map_pci_bars(struct beiscsi_hba *phba,
615 struct pci_dev *pcidev)
616{
617 u8 __iomem *addr;
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +0530618 int pcicfg_reg;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530619
620 addr = ioremap_nocache(pci_resource_start(pcidev, 2),
621 pci_resource_len(pcidev, 2));
622 if (addr == NULL)
623 return -ENOMEM;
624 phba->ctrl.csr = addr;
625 phba->csr_va = addr;
626 phba->csr_pa.u.a64.address = pci_resource_start(pcidev, 2);
627
628 addr = ioremap_nocache(pci_resource_start(pcidev, 4), 128 * 1024);
629 if (addr == NULL)
630 goto pci_map_err;
631 phba->ctrl.db = addr;
632 phba->db_va = addr;
633 phba->db_pa.u.a64.address = pci_resource_start(pcidev, 4);
634
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +0530635 if (phba->generation == BE_GEN2)
636 pcicfg_reg = 1;
637 else
638 pcicfg_reg = 0;
639
640 addr = ioremap_nocache(pci_resource_start(pcidev, pcicfg_reg),
641 pci_resource_len(pcidev, pcicfg_reg));
642
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530643 if (addr == NULL)
644 goto pci_map_err;
645 phba->ctrl.pcicfg = addr;
646 phba->pci_va = addr;
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +0530647 phba->pci_pa.u.a64.address = pci_resource_start(pcidev, pcicfg_reg);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530648 return 0;
649
650pci_map_err:
651 beiscsi_unmap_pci_function(phba);
652 return -ENOMEM;
653}
654
655static int beiscsi_enable_pci(struct pci_dev *pcidev)
656{
657 int ret;
658
659 ret = pci_enable_device(pcidev);
660 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530661 dev_err(&pcidev->dev,
662 "beiscsi_enable_pci - enable device failed\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530663 return ret;
664 }
665
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530666 pci_set_master(pcidev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530667 if (pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64))) {
668 ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(32));
669 if (ret) {
670 dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n");
671 pci_disable_device(pcidev);
672 return ret;
673 }
674 }
675 return 0;
676}
677
678static int be_ctrl_init(struct beiscsi_hba *phba, struct pci_dev *pdev)
679{
680 struct be_ctrl_info *ctrl = &phba->ctrl;
681 struct be_dma_mem *mbox_mem_alloc = &ctrl->mbox_mem_alloced;
682 struct be_dma_mem *mbox_mem_align = &ctrl->mbox_mem;
683 int status = 0;
684
685 ctrl->pdev = pdev;
686 status = beiscsi_map_pci_bars(phba, pdev);
687 if (status)
688 return status;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530689 mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16;
690 mbox_mem_alloc->va = pci_alloc_consistent(pdev,
691 mbox_mem_alloc->size,
692 &mbox_mem_alloc->dma);
693 if (!mbox_mem_alloc->va) {
694 beiscsi_unmap_pci_function(phba);
Jayamohan Kallickala49e06d2012-04-03 23:41:44 -0500695 return -ENOMEM;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530696 }
697
698 mbox_mem_align->size = sizeof(struct be_mcc_mailbox);
699 mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16);
700 mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16);
701 memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox));
702 spin_lock_init(&ctrl->mbox_lock);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530703 spin_lock_init(&phba->ctrl.mcc_lock);
704 spin_lock_init(&phba->ctrl.mcc_cq_lock);
705
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530706 return status;
707}
708
Jayamohan Kallickal843ae752013-09-28 15:35:44 -0700709/**
710 * beiscsi_get_params()- Set the config paramters
711 * @phba: ptr device priv structure
712 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530713static void beiscsi_get_params(struct beiscsi_hba *phba)
714{
Jayamohan Kallickal843ae752013-09-28 15:35:44 -0700715 uint32_t total_cid_count = 0;
716 uint32_t total_icd_count = 0;
717 uint8_t ulp_num = 0;
718
719 total_cid_count = BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP0) +
720 BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP1);
721
722 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
723 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
724 total_icd_count = phba->fw_config.
725 iscsi_icd_count[ulp_num];
726 break;
727 }
728
729 phba->params.ios_per_ctrl = (total_icd_count -
730 (total_cid_count +
731 BE2_TMFS + BE2_NOPOUT_REQ));
732 phba->params.cxns_per_ctrl = total_cid_count;
733 phba->params.asyncpdus_per_ctrl = total_cid_count;
734 phba->params.icds_per_ctrl = total_icd_count;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530735 phba->params.num_sge_per_io = BE2_SGE;
736 phba->params.defpdu_hdr_sz = BE2_DEFPDU_HDR_SZ;
737 phba->params.defpdu_data_sz = BE2_DEFPDU_DATA_SZ;
738 phba->params.eq_timer = 64;
Jayamohan Kallickal843ae752013-09-28 15:35:44 -0700739 phba->params.num_eq_entries = 1024;
740 phba->params.num_cq_entries = 1024;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530741 phba->params.wrbs_per_cxn = 256;
742}
743
744static void hwi_ring_eq_db(struct beiscsi_hba *phba,
745 unsigned int id, unsigned int clr_interrupt,
746 unsigned int num_processed,
747 unsigned char rearm, unsigned char event)
748{
749 u32 val = 0;
750 val |= id & DB_EQ_RING_ID_MASK;
751 if (rearm)
752 val |= 1 << DB_EQ_REARM_SHIFT;
753 if (clr_interrupt)
754 val |= 1 << DB_EQ_CLR_SHIFT;
755 if (event)
756 val |= 1 << DB_EQ_EVNT_SHIFT;
757 val |= num_processed << DB_EQ_NUM_POPPED_SHIFT;
758 iowrite32(val, phba->db_va + DB_EQ_OFFSET);
759}
760
761/**
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530762 * be_isr_mcc - The isr routine of the driver.
763 * @irq: Not used
764 * @dev_id: Pointer to host adapter structure
765 */
766static irqreturn_t be_isr_mcc(int irq, void *dev_id)
767{
768 struct beiscsi_hba *phba;
769 struct be_eq_entry *eqe = NULL;
770 struct be_queue_info *eq;
771 struct be_queue_info *mcc;
772 unsigned int num_eq_processed;
773 struct be_eq_obj *pbe_eq;
774 unsigned long flags;
775
776 pbe_eq = dev_id;
777 eq = &pbe_eq->q;
778 phba = pbe_eq->phba;
779 mcc = &phba->ctrl.mcc_obj.cq;
780 eqe = queue_tail_node(eq);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530781
782 num_eq_processed = 0;
783
784 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
785 & EQE_VALID_MASK) {
786 if (((eqe->dw[offsetof(struct amap_eq_entry,
787 resource_id) / 32] &
788 EQE_RESID_MASK) >> 16) == mcc->id) {
789 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +0530790 pbe_eq->todo_mcc_cq = true;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530791 spin_unlock_irqrestore(&phba->isr_lock, flags);
792 }
793 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
794 queue_tail_inc(eq);
795 eqe = queue_tail_node(eq);
796 num_eq_processed++;
797 }
John Soni Jose72fb46a2012-10-20 04:42:49 +0530798 if (pbe_eq->todo_mcc_cq)
799 queue_work(phba->wq, &pbe_eq->work_cqs);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530800 if (num_eq_processed)
801 hwi_ring_eq_db(phba, eq->id, 1, num_eq_processed, 1, 1);
802
803 return IRQ_HANDLED;
804}
805
806/**
807 * be_isr_msix - The isr routine of the driver.
808 * @irq: Not used
809 * @dev_id: Pointer to host adapter structure
810 */
811static irqreturn_t be_isr_msix(int irq, void *dev_id)
812{
813 struct beiscsi_hba *phba;
814 struct be_eq_entry *eqe = NULL;
815 struct be_queue_info *eq;
816 struct be_queue_info *cq;
817 unsigned int num_eq_processed;
818 struct be_eq_obj *pbe_eq;
819 unsigned long flags;
820
821 pbe_eq = dev_id;
822 eq = &pbe_eq->q;
823 cq = pbe_eq->cq;
824 eqe = queue_tail_node(eq);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530825
826 phba = pbe_eq->phba;
827 num_eq_processed = 0;
828 if (blk_iopoll_enabled) {
829 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
830 & EQE_VALID_MASK) {
831 if (!blk_iopoll_sched_prep(&pbe_eq->iopoll))
832 blk_iopoll_sched(&pbe_eq->iopoll);
833
834 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
835 queue_tail_inc(eq);
836 eqe = queue_tail_node(eq);
837 num_eq_processed++;
838 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530839 } else {
840 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
841 & EQE_VALID_MASK) {
842 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +0530843 pbe_eq->todo_cq = true;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530844 spin_unlock_irqrestore(&phba->isr_lock, flags);
845 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
846 queue_tail_inc(eq);
847 eqe = queue_tail_node(eq);
848 num_eq_processed++;
849 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530850
John Soni Jose72fb46a2012-10-20 04:42:49 +0530851 if (pbe_eq->todo_cq)
852 queue_work(phba->wq, &pbe_eq->work_cqs);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530853 }
John Soni Jose72fb46a2012-10-20 04:42:49 +0530854
855 if (num_eq_processed)
856 hwi_ring_eq_db(phba, eq->id, 1, num_eq_processed, 0, 1);
857
858 return IRQ_HANDLED;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530859}
860
861/**
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530862 * be_isr - The isr routine of the driver.
863 * @irq: Not used
864 * @dev_id: Pointer to host adapter structure
865 */
866static irqreturn_t be_isr(int irq, void *dev_id)
867{
868 struct beiscsi_hba *phba;
869 struct hwi_controller *phwi_ctrlr;
870 struct hwi_context_memory *phwi_context;
871 struct be_eq_entry *eqe = NULL;
872 struct be_queue_info *eq;
873 struct be_queue_info *cq;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530874 struct be_queue_info *mcc;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530875 unsigned long flags, index;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530876 unsigned int num_mcceq_processed, num_ioeq_processed;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530877 struct be_ctrl_info *ctrl;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530878 struct be_eq_obj *pbe_eq;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530879 int isr;
880
881 phba = dev_id;
Justin P. Mattock6eab04a2011-04-08 19:49:08 -0700882 ctrl = &phba->ctrl;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530883 isr = ioread32(ctrl->csr + CEV_ISR0_OFFSET +
884 (PCI_FUNC(ctrl->pdev->devfn) * CEV_ISR_SIZE));
885 if (!isr)
886 return IRQ_NONE;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530887
888 phwi_ctrlr = phba->phwi_ctrlr;
889 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530890 pbe_eq = &phwi_context->be_eq[0];
891
892 eq = &phwi_context->be_eq[0].q;
893 mcc = &phba->ctrl.mcc_obj.cq;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530894 index = 0;
895 eqe = queue_tail_node(eq);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530896
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530897 num_ioeq_processed = 0;
898 num_mcceq_processed = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530899 if (blk_iopoll_enabled) {
900 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
901 & EQE_VALID_MASK) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530902 if (((eqe->dw[offsetof(struct amap_eq_entry,
903 resource_id) / 32] &
904 EQE_RESID_MASK) >> 16) == mcc->id) {
905 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +0530906 pbe_eq->todo_mcc_cq = true;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530907 spin_unlock_irqrestore(&phba->isr_lock, flags);
908 num_mcceq_processed++;
909 } else {
910 if (!blk_iopoll_sched_prep(&pbe_eq->iopoll))
911 blk_iopoll_sched(&pbe_eq->iopoll);
912 num_ioeq_processed++;
913 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530914 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
915 queue_tail_inc(eq);
916 eqe = queue_tail_node(eq);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530917 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530918 if (num_ioeq_processed || num_mcceq_processed) {
John Soni Jose72fb46a2012-10-20 04:42:49 +0530919 if (pbe_eq->todo_mcc_cq)
920 queue_work(phba->wq, &pbe_eq->work_cqs);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530921
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530922 if ((num_mcceq_processed) && (!num_ioeq_processed))
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530923 hwi_ring_eq_db(phba, eq->id, 0,
924 (num_ioeq_processed +
925 num_mcceq_processed) , 1, 1);
926 else
927 hwi_ring_eq_db(phba, eq->id, 0,
928 (num_ioeq_processed +
929 num_mcceq_processed), 0, 1);
930
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530931 return IRQ_HANDLED;
932 } else
933 return IRQ_NONE;
934 } else {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530935 cq = &phwi_context->be_cq[0];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530936 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
937 & EQE_VALID_MASK) {
938
939 if (((eqe->dw[offsetof(struct amap_eq_entry,
940 resource_id) / 32] &
941 EQE_RESID_MASK) >> 16) != cq->id) {
942 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +0530943 pbe_eq->todo_mcc_cq = true;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530944 spin_unlock_irqrestore(&phba->isr_lock, flags);
945 } else {
946 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +0530947 pbe_eq->todo_cq = true;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530948 spin_unlock_irqrestore(&phba->isr_lock, flags);
949 }
950 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
951 queue_tail_inc(eq);
952 eqe = queue_tail_node(eq);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530953 num_ioeq_processed++;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530954 }
John Soni Jose72fb46a2012-10-20 04:42:49 +0530955 if (pbe_eq->todo_cq || pbe_eq->todo_mcc_cq)
956 queue_work(phba->wq, &pbe_eq->work_cqs);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530957
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530958 if (num_ioeq_processed) {
959 hwi_ring_eq_db(phba, eq->id, 0,
960 num_ioeq_processed, 1, 1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530961 return IRQ_HANDLED;
962 } else
963 return IRQ_NONE;
964 }
965}
966
967static int beiscsi_init_irqs(struct beiscsi_hba *phba)
968{
969 struct pci_dev *pcidev = phba->pcidev;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530970 struct hwi_controller *phwi_ctrlr;
971 struct hwi_context_memory *phwi_context;
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +0530972 int ret, msix_vec, i, j;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530973
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530974 phwi_ctrlr = phba->phwi_ctrlr;
975 phwi_context = phwi_ctrlr->phwi_ctxt;
976
977 if (phba->msix_enabled) {
978 for (i = 0; i < phba->num_cpus; i++) {
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -0700979 phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME,
980 GFP_KERNEL);
981 if (!phba->msi_name[i]) {
982 ret = -ENOMEM;
983 goto free_msix_irqs;
984 }
985
986 sprintf(phba->msi_name[i], "beiscsi_%02x_%02x",
987 phba->shost->host_no, i);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530988 msix_vec = phba->msix_entries[i].vector;
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -0700989 ret = request_irq(msix_vec, be_isr_msix, 0,
990 phba->msi_name[i],
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530991 &phwi_context->be_eq[i]);
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +0530992 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530993 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
994 "BM_%d : beiscsi_init_irqs-Failed to"
995 "register msix for i = %d\n",
996 i);
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -0700997 kfree(phba->msi_name[i]);
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +0530998 goto free_msix_irqs;
999 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301000 }
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -07001001 phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME, GFP_KERNEL);
1002 if (!phba->msi_name[i]) {
1003 ret = -ENOMEM;
1004 goto free_msix_irqs;
1005 }
1006 sprintf(phba->msi_name[i], "beiscsi_mcc_%02x",
1007 phba->shost->host_no);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301008 msix_vec = phba->msix_entries[i].vector;
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -07001009 ret = request_irq(msix_vec, be_isr_mcc, 0, phba->msi_name[i],
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301010 &phwi_context->be_eq[i]);
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +05301011 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301012 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT ,
1013 "BM_%d : beiscsi_init_irqs-"
1014 "Failed to register beiscsi_msix_mcc\n");
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -07001015 kfree(phba->msi_name[i]);
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +05301016 goto free_msix_irqs;
1017 }
1018
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301019 } else {
1020 ret = request_irq(pcidev->irq, be_isr, IRQF_SHARED,
1021 "beiscsi", phba);
1022 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301023 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
1024 "BM_%d : beiscsi_init_irqs-"
1025 "Failed to register irq\\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301026 return ret;
1027 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301028 }
1029 return 0;
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +05301030free_msix_irqs:
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -07001031 for (j = i - 1; j >= 0; j--) {
1032 kfree(phba->msi_name[j]);
1033 msix_vec = phba->msix_entries[j].vector;
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +05301034 free_irq(msix_vec, &phwi_context->be_eq[j]);
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -07001035 }
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +05301036 return ret;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301037}
1038
1039static void hwi_ring_cq_db(struct beiscsi_hba *phba,
1040 unsigned int id, unsigned int num_processed,
1041 unsigned char rearm, unsigned char event)
1042{
1043 u32 val = 0;
1044 val |= id & DB_CQ_RING_ID_MASK;
1045 if (rearm)
1046 val |= 1 << DB_CQ_REARM_SHIFT;
1047 val |= num_processed << DB_CQ_NUM_POPPED_SHIFT;
1048 iowrite32(val, phba->db_va + DB_CQ_OFFSET);
1049}
1050
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301051static unsigned int
1052beiscsi_process_async_pdu(struct beiscsi_conn *beiscsi_conn,
1053 struct beiscsi_hba *phba,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301054 struct pdu_base *ppdu,
1055 unsigned long pdu_len,
1056 void *pbuffer, unsigned long buf_len)
1057{
1058 struct iscsi_conn *conn = beiscsi_conn->conn;
1059 struct iscsi_session *session = conn->session;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301060 struct iscsi_task *task;
1061 struct beiscsi_io_task *io_task;
1062 struct iscsi_hdr *login_hdr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301063
1064 switch (ppdu->dw[offsetof(struct amap_pdu_base, opcode) / 32] &
1065 PDUBASE_OPCODE_MASK) {
1066 case ISCSI_OP_NOOP_IN:
1067 pbuffer = NULL;
1068 buf_len = 0;
1069 break;
1070 case ISCSI_OP_ASYNC_EVENT:
1071 break;
1072 case ISCSI_OP_REJECT:
1073 WARN_ON(!pbuffer);
1074 WARN_ON(!(buf_len == 48));
John Soni Jose99bc5d52012-08-20 23:00:18 +05301075 beiscsi_log(phba, KERN_ERR,
1076 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1077 "BM_%d : In ISCSI_OP_REJECT\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301078 break;
1079 case ISCSI_OP_LOGIN_RSP:
Jayamohan Kallickal7bd6e252010-01-05 05:07:02 +05301080 case ISCSI_OP_TEXT_RSP:
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301081 task = conn->login_task;
1082 io_task = task->dd_data;
1083 login_hdr = (struct iscsi_hdr *)ppdu;
1084 login_hdr->itt = io_task->libiscsi_itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301085 break;
1086 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +05301087 beiscsi_log(phba, KERN_WARNING,
1088 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1089 "BM_%d : Unrecognized opcode 0x%x in async msg\n",
1090 (ppdu->
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301091 dw[offsetof(struct amap_pdu_base, opcode) / 32]
John Soni Jose99bc5d52012-08-20 23:00:18 +05301092 & PDUBASE_OPCODE_MASK));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301093 return 1;
1094 }
1095
1096 spin_lock_bh(&session->lock);
1097 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)ppdu, pbuffer, buf_len);
1098 spin_unlock_bh(&session->lock);
1099 return 0;
1100}
1101
1102static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba)
1103{
1104 struct sgl_handle *psgl_handle;
1105
1106 if (phba->io_sgl_hndl_avbl) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301107 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
1108 "BM_%d : In alloc_io_sgl_handle,"
1109 " io_sgl_alloc_index=%d\n",
1110 phba->io_sgl_alloc_index);
1111
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301112 psgl_handle = phba->io_sgl_hndl_base[phba->
1113 io_sgl_alloc_index];
1114 phba->io_sgl_hndl_base[phba->io_sgl_alloc_index] = NULL;
1115 phba->io_sgl_hndl_avbl--;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301116 if (phba->io_sgl_alloc_index == (phba->params.
1117 ios_per_ctrl - 1))
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301118 phba->io_sgl_alloc_index = 0;
1119 else
1120 phba->io_sgl_alloc_index++;
1121 } else
1122 psgl_handle = NULL;
1123 return psgl_handle;
1124}
1125
1126static void
1127free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
1128{
John Soni Jose99bc5d52012-08-20 23:00:18 +05301129 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
1130 "BM_%d : In free_,io_sgl_free_index=%d\n",
1131 phba->io_sgl_free_index);
1132
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301133 if (phba->io_sgl_hndl_base[phba->io_sgl_free_index]) {
1134 /*
1135 * this can happen if clean_task is called on a task that
1136 * failed in xmit_task or alloc_pdu.
1137 */
John Soni Jose99bc5d52012-08-20 23:00:18 +05301138 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
1139 "BM_%d : Double Free in IO SGL io_sgl_free_index=%d,"
1140 "value there=%p\n", phba->io_sgl_free_index,
1141 phba->io_sgl_hndl_base
1142 [phba->io_sgl_free_index]);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301143 return;
1144 }
1145 phba->io_sgl_hndl_base[phba->io_sgl_free_index] = psgl_handle;
1146 phba->io_sgl_hndl_avbl++;
1147 if (phba->io_sgl_free_index == (phba->params.ios_per_ctrl - 1))
1148 phba->io_sgl_free_index = 0;
1149 else
1150 phba->io_sgl_free_index++;
1151}
1152
1153/**
1154 * alloc_wrb_handle - To allocate a wrb handle
1155 * @phba: The hba pointer
1156 * @cid: The cid to use for allocation
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301157 *
1158 * This happens under session_lock until submission to chip
1159 */
Jayamohan Kallickald5431482010-01-05 05:06:21 +05301160struct wrb_handle *alloc_wrb_handle(struct beiscsi_hba *phba, unsigned int cid)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301161{
1162 struct hwi_wrb_context *pwrb_context;
1163 struct hwi_controller *phwi_ctrlr;
Jayamohan Kallickald5431482010-01-05 05:06:21 +05301164 struct wrb_handle *pwrb_handle, *pwrb_handle_tmp;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001165 uint16_t cri_index = BE_GET_CRI_FROM_CID(cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301166
1167 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001168 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
Jayamohan Kallickald5431482010-01-05 05:06:21 +05301169 if (pwrb_context->wrb_handles_available >= 2) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301170 pwrb_handle = pwrb_context->pwrb_handle_base[
1171 pwrb_context->alloc_index];
1172 pwrb_context->wrb_handles_available--;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301173 if (pwrb_context->alloc_index ==
1174 (phba->params.wrbs_per_cxn - 1))
1175 pwrb_context->alloc_index = 0;
1176 else
1177 pwrb_context->alloc_index++;
Jayamohan Kallickald5431482010-01-05 05:06:21 +05301178 pwrb_handle_tmp = pwrb_context->pwrb_handle_base[
1179 pwrb_context->alloc_index];
1180 pwrb_handle->nxt_wrb_index = pwrb_handle_tmp->wrb_index;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301181 } else
1182 pwrb_handle = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301183 return pwrb_handle;
1184}
1185
1186/**
1187 * free_wrb_handle - To free the wrb handle back to pool
1188 * @phba: The hba pointer
1189 * @pwrb_context: The context to free from
1190 * @pwrb_handle: The wrb_handle to free
1191 *
1192 * This happens under session_lock until submission to chip
1193 */
1194static void
1195free_wrb_handle(struct beiscsi_hba *phba, struct hwi_wrb_context *pwrb_context,
1196 struct wrb_handle *pwrb_handle)
1197{
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05301198 pwrb_context->pwrb_handle_base[pwrb_context->free_index] = pwrb_handle;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301199 pwrb_context->wrb_handles_available++;
1200 if (pwrb_context->free_index == (phba->params.wrbs_per_cxn - 1))
1201 pwrb_context->free_index = 0;
1202 else
1203 pwrb_context->free_index++;
1204
John Soni Jose99bc5d52012-08-20 23:00:18 +05301205 beiscsi_log(phba, KERN_INFO,
1206 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1207 "BM_%d : FREE WRB: pwrb_handle=%p free_index=0x%x"
1208 "wrb_handles_available=%d\n",
1209 pwrb_handle, pwrb_context->free_index,
1210 pwrb_context->wrb_handles_available);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301211}
1212
1213static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba)
1214{
1215 struct sgl_handle *psgl_handle;
1216
1217 if (phba->eh_sgl_hndl_avbl) {
1218 psgl_handle = phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index];
1219 phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index] = NULL;
John Soni Jose99bc5d52012-08-20 23:00:18 +05301220 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1221 "BM_%d : mgmt_sgl_alloc_index=%d=0x%x\n",
1222 phba->eh_sgl_alloc_index,
1223 phba->eh_sgl_alloc_index);
1224
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301225 phba->eh_sgl_hndl_avbl--;
1226 if (phba->eh_sgl_alloc_index ==
1227 (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl -
1228 1))
1229 phba->eh_sgl_alloc_index = 0;
1230 else
1231 phba->eh_sgl_alloc_index++;
1232 } else
1233 psgl_handle = NULL;
1234 return psgl_handle;
1235}
1236
1237void
1238free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
1239{
1240
John Soni Jose99bc5d52012-08-20 23:00:18 +05301241 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1242 "BM_%d : In free_mgmt_sgl_handle,"
1243 "eh_sgl_free_index=%d\n",
1244 phba->eh_sgl_free_index);
1245
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301246 if (phba->eh_sgl_hndl_base[phba->eh_sgl_free_index]) {
1247 /*
1248 * this can happen if clean_task is called on a task that
1249 * failed in xmit_task or alloc_pdu.
1250 */
John Soni Jose99bc5d52012-08-20 23:00:18 +05301251 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1252 "BM_%d : Double Free in eh SGL ,"
1253 "eh_sgl_free_index=%d\n",
1254 phba->eh_sgl_free_index);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301255 return;
1256 }
1257 phba->eh_sgl_hndl_base[phba->eh_sgl_free_index] = psgl_handle;
1258 phba->eh_sgl_hndl_avbl++;
1259 if (phba->eh_sgl_free_index ==
1260 (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl - 1))
1261 phba->eh_sgl_free_index = 0;
1262 else
1263 phba->eh_sgl_free_index++;
1264}
1265
1266static void
1267be_complete_io(struct beiscsi_conn *beiscsi_conn,
John Soni Jose73133262012-10-20 04:44:49 +05301268 struct iscsi_task *task,
1269 struct common_sol_cqe *csol_cqe)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301270{
1271 struct beiscsi_io_task *io_task = task->dd_data;
1272 struct be_status_bhs *sts_bhs =
1273 (struct be_status_bhs *)io_task->cmd_bhs;
1274 struct iscsi_conn *conn = beiscsi_conn->conn;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301275 unsigned char *sense;
1276 u32 resid = 0, exp_cmdsn, max_cmdsn;
1277 u8 rsp, status, flags;
1278
John Soni Jose73133262012-10-20 04:44:49 +05301279 exp_cmdsn = csol_cqe->exp_cmdsn;
1280 max_cmdsn = (csol_cqe->exp_cmdsn +
1281 csol_cqe->cmd_wnd - 1);
1282 rsp = csol_cqe->i_resp;
1283 status = csol_cqe->i_sts;
1284 flags = csol_cqe->i_flags;
1285 resid = csol_cqe->res_cnt;
1286
Jayamohan Kallickalbd535452011-10-07 19:31:10 -05001287 if (!task->sc) {
1288 if (io_task->scsi_cmnd)
1289 scsi_dma_unmap(io_task->scsi_cmnd);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301290
Jayamohan Kallickalbd535452011-10-07 19:31:10 -05001291 return;
1292 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301293 task->sc->result = (DID_OK << 16) | status;
1294 if (rsp != ISCSI_STATUS_CMD_COMPLETED) {
1295 task->sc->result = DID_ERROR << 16;
1296 goto unmap;
1297 }
1298
1299 /* bidi not initially supported */
1300 if (flags & (ISCSI_FLAG_CMD_UNDERFLOW | ISCSI_FLAG_CMD_OVERFLOW)) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301301 if (!status && (flags & ISCSI_FLAG_CMD_OVERFLOW))
1302 task->sc->result = DID_ERROR << 16;
1303
1304 if (flags & ISCSI_FLAG_CMD_UNDERFLOW) {
1305 scsi_set_resid(task->sc, resid);
1306 if (!status && (scsi_bufflen(task->sc) - resid <
1307 task->sc->underflow))
1308 task->sc->result = DID_ERROR << 16;
1309 }
1310 }
1311
1312 if (status == SAM_STAT_CHECK_CONDITION) {
Dan Carpenter4053a4b2011-09-26 09:23:37 +03001313 u16 sense_len;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301314 unsigned short *slen = (unsigned short *)sts_bhs->sense_info;
Dan Carpenter4053a4b2011-09-26 09:23:37 +03001315
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301316 sense = sts_bhs->sense_info + sizeof(unsigned short);
Dan Carpenter4053a4b2011-09-26 09:23:37 +03001317 sense_len = be16_to_cpu(*slen);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301318 memcpy(task->sc->sense_buffer, sense,
1319 min_t(u16, sense_len, SCSI_SENSE_BUFFERSIZE));
1320 }
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05301321
John Soni Jose73133262012-10-20 04:44:49 +05301322 if (io_task->cmd_bhs->iscsi_hdr.flags & ISCSI_FLAG_CMD_READ)
1323 conn->rxdata_octets += resid;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301324unmap:
1325 scsi_dma_unmap(io_task->scsi_cmnd);
1326 iscsi_complete_scsi_task(task, exp_cmdsn, max_cmdsn);
1327}
1328
1329static void
1330be_complete_logout(struct beiscsi_conn *beiscsi_conn,
John Soni Jose73133262012-10-20 04:44:49 +05301331 struct iscsi_task *task,
1332 struct common_sol_cqe *csol_cqe)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301333{
1334 struct iscsi_logout_rsp *hdr;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301335 struct beiscsi_io_task *io_task = task->dd_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301336 struct iscsi_conn *conn = beiscsi_conn->conn;
1337
1338 hdr = (struct iscsi_logout_rsp *)task->hdr;
Jayamohan Kallickal7bd6e252010-01-05 05:07:02 +05301339 hdr->opcode = ISCSI_OP_LOGOUT_RSP;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301340 hdr->t2wait = 5;
1341 hdr->t2retain = 0;
John Soni Jose73133262012-10-20 04:44:49 +05301342 hdr->flags = csol_cqe->i_flags;
1343 hdr->response = csol_cqe->i_resp;
Jayamohan Kallickal702dc5e2013-04-05 20:38:37 -07001344 hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn);
1345 hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn +
1346 csol_cqe->cmd_wnd - 1);
John Soni Jose73133262012-10-20 04:44:49 +05301347
Jayamohan Kallickal7bd6e252010-01-05 05:07:02 +05301348 hdr->dlength[0] = 0;
1349 hdr->dlength[1] = 0;
1350 hdr->dlength[2] = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301351 hdr->hlength = 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301352 hdr->itt = io_task->libiscsi_itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301353 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1354}
1355
1356static void
1357be_complete_tmf(struct beiscsi_conn *beiscsi_conn,
John Soni Jose73133262012-10-20 04:44:49 +05301358 struct iscsi_task *task,
1359 struct common_sol_cqe *csol_cqe)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301360{
1361 struct iscsi_tm_rsp *hdr;
1362 struct iscsi_conn *conn = beiscsi_conn->conn;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301363 struct beiscsi_io_task *io_task = task->dd_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301364
1365 hdr = (struct iscsi_tm_rsp *)task->hdr;
Jayamohan Kallickal7bd6e252010-01-05 05:07:02 +05301366 hdr->opcode = ISCSI_OP_SCSI_TMFUNC_RSP;
John Soni Jose73133262012-10-20 04:44:49 +05301367 hdr->flags = csol_cqe->i_flags;
1368 hdr->response = csol_cqe->i_resp;
Jayamohan Kallickal702dc5e2013-04-05 20:38:37 -07001369 hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn);
1370 hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn +
1371 csol_cqe->cmd_wnd - 1);
John Soni Jose73133262012-10-20 04:44:49 +05301372
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301373 hdr->itt = io_task->libiscsi_itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301374 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1375}
1376
1377static void
1378hwi_complete_drvr_msgs(struct beiscsi_conn *beiscsi_conn,
1379 struct beiscsi_hba *phba, struct sol_cqe *psol)
1380{
1381 struct hwi_wrb_context *pwrb_context;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301382 struct wrb_handle *pwrb_handle = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301383 struct hwi_controller *phwi_ctrlr;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301384 struct iscsi_task *task;
1385 struct beiscsi_io_task *io_task;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001386 uint16_t wrb_index, cid, cri_index;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301387
1388 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07001389 if (is_chip_be2_be3r(phba)) {
John Soni Jose73133262012-10-20 04:44:49 +05301390 wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe,
1391 wrb_idx, psol);
1392 cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe,
1393 cid, psol);
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07001394 } else {
1395 wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2,
1396 wrb_idx, psol);
1397 cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2,
1398 cid, psol);
John Soni Jose73133262012-10-20 04:44:49 +05301399 }
1400
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001401 cri_index = BE_GET_CRI_FROM_CID(cid);
1402 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
John Soni Jose73133262012-10-20 04:44:49 +05301403 pwrb_handle = pwrb_context->pwrb_handle_basestd[wrb_index];
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05301404 task = pwrb_handle->pio_handle;
Jayamohan Kallickal35e66012009-10-23 11:53:49 +05301405
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301406 io_task = task->dd_data;
Jayamohan Kallickal4a4a11b2013-04-05 20:38:31 -07001407 memset(io_task->pwrb_handle->pwrb, 0, sizeof(struct iscsi_wrb));
1408 iscsi_put_task(task);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301409}
1410
1411static void
1412be_complete_nopin_resp(struct beiscsi_conn *beiscsi_conn,
John Soni Jose73133262012-10-20 04:44:49 +05301413 struct iscsi_task *task,
1414 struct common_sol_cqe *csol_cqe)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301415{
1416 struct iscsi_nopin *hdr;
1417 struct iscsi_conn *conn = beiscsi_conn->conn;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301418 struct beiscsi_io_task *io_task = task->dd_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301419
1420 hdr = (struct iscsi_nopin *)task->hdr;
John Soni Jose73133262012-10-20 04:44:49 +05301421 hdr->flags = csol_cqe->i_flags;
1422 hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn);
Jayamohan Kallickal702dc5e2013-04-05 20:38:37 -07001423 hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn +
1424 csol_cqe->cmd_wnd - 1);
John Soni Jose73133262012-10-20 04:44:49 +05301425
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301426 hdr->opcode = ISCSI_OP_NOOP_IN;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301427 hdr->itt = io_task->libiscsi_itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301428 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1429}
1430
John Soni Jose73133262012-10-20 04:44:49 +05301431static void adapter_get_sol_cqe(struct beiscsi_hba *phba,
1432 struct sol_cqe *psol,
1433 struct common_sol_cqe *csol_cqe)
1434{
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07001435 if (is_chip_be2_be3r(phba)) {
1436 csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe,
1437 i_exp_cmd_sn, psol);
1438 csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe,
1439 i_res_cnt, psol);
1440 csol_cqe->cmd_wnd = AMAP_GET_BITS(struct amap_sol_cqe,
1441 i_cmd_wnd, psol);
1442 csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe,
1443 wrb_index, psol);
1444 csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe,
1445 cid, psol);
1446 csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe,
1447 hw_sts, psol);
1448 csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe,
1449 i_resp, psol);
1450 csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe,
1451 i_sts, psol);
1452 csol_cqe->i_flags = AMAP_GET_BITS(struct amap_sol_cqe,
1453 i_flags, psol);
1454 } else {
John Soni Jose73133262012-10-20 04:44:49 +05301455 csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1456 i_exp_cmd_sn, psol);
1457 csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1458 i_res_cnt, psol);
1459 csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1460 wrb_index, psol);
1461 csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1462 cid, psol);
1463 csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1464 hw_sts, psol);
Jayamohan Kallickal702dc5e2013-04-05 20:38:37 -07001465 csol_cqe->cmd_wnd = AMAP_GET_BITS(struct amap_sol_cqe_v2,
John Soni Jose73133262012-10-20 04:44:49 +05301466 i_cmd_wnd, psol);
1467 if (AMAP_GET_BITS(struct amap_sol_cqe_v2,
1468 cmd_cmpl, psol))
1469 csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1470 i_sts, psol);
1471 else
1472 csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1473 i_sts, psol);
1474 if (AMAP_GET_BITS(struct amap_sol_cqe_v2,
1475 u, psol))
1476 csol_cqe->i_flags = ISCSI_FLAG_CMD_UNDERFLOW;
1477
1478 if (AMAP_GET_BITS(struct amap_sol_cqe_v2,
1479 o, psol))
1480 csol_cqe->i_flags |= ISCSI_FLAG_CMD_OVERFLOW;
John Soni Jose73133262012-10-20 04:44:49 +05301481 }
1482}
1483
1484
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301485static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn,
1486 struct beiscsi_hba *phba, struct sol_cqe *psol)
1487{
1488 struct hwi_wrb_context *pwrb_context;
1489 struct wrb_handle *pwrb_handle;
1490 struct iscsi_wrb *pwrb = NULL;
1491 struct hwi_controller *phwi_ctrlr;
1492 struct iscsi_task *task;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301493 unsigned int type;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301494 struct iscsi_conn *conn = beiscsi_conn->conn;
1495 struct iscsi_session *session = conn->session;
John Soni Jose73133262012-10-20 04:44:49 +05301496 struct common_sol_cqe csol_cqe = {0};
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001497 uint16_t cri_index = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301498
1499 phwi_ctrlr = phba->phwi_ctrlr;
John Soni Jose73133262012-10-20 04:44:49 +05301500
1501 /* Copy the elements to a common structure */
1502 adapter_get_sol_cqe(phba, psol, &csol_cqe);
1503
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001504 cri_index = BE_GET_CRI_FROM_CID(csol_cqe.cid);
1505 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
John Soni Jose73133262012-10-20 04:44:49 +05301506
1507 pwrb_handle = pwrb_context->pwrb_handle_basestd[
1508 csol_cqe.wrb_index];
1509
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05301510 task = pwrb_handle->pio_handle;
1511 pwrb = pwrb_handle->pwrb;
John Soni Jose73133262012-10-20 04:44:49 +05301512 type = ((struct beiscsi_io_task *)task->dd_data)->wrb_type;
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05301513
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301514 spin_lock_bh(&session->lock);
1515 switch (type) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301516 case HWH_TYPE_IO:
1517 case HWH_TYPE_IO_RD:
1518 if ((task->hdr->opcode & ISCSI_OPCODE_MASK) ==
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05301519 ISCSI_OP_NOOP_OUT)
John Soni Jose73133262012-10-20 04:44:49 +05301520 be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe);
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05301521 else
John Soni Jose73133262012-10-20 04:44:49 +05301522 be_complete_io(beiscsi_conn, task, &csol_cqe);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301523 break;
1524
1525 case HWH_TYPE_LOGOUT:
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05301526 if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGOUT)
John Soni Jose73133262012-10-20 04:44:49 +05301527 be_complete_logout(beiscsi_conn, task, &csol_cqe);
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05301528 else
John Soni Jose73133262012-10-20 04:44:49 +05301529 be_complete_tmf(beiscsi_conn, task, &csol_cqe);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301530 break;
1531
1532 case HWH_TYPE_LOGIN:
John Soni Jose99bc5d52012-08-20 23:00:18 +05301533 beiscsi_log(phba, KERN_ERR,
1534 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1535 "BM_%d :\t\t No HWH_TYPE_LOGIN Expected in"
1536 " hwi_complete_cmd- Solicited path\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301537 break;
1538
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301539 case HWH_TYPE_NOP:
John Soni Jose73133262012-10-20 04:44:49 +05301540 be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301541 break;
1542
1543 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +05301544 beiscsi_log(phba, KERN_WARNING,
1545 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1546 "BM_%d : In hwi_complete_cmd, unknown type = %d"
1547 "wrb_index 0x%x CID 0x%x\n", type,
John Soni Jose73133262012-10-20 04:44:49 +05301548 csol_cqe.wrb_index,
1549 csol_cqe.cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301550 break;
1551 }
Jayamohan Kallickal35e66012009-10-23 11:53:49 +05301552
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301553 spin_unlock_bh(&session->lock);
1554}
1555
1556static struct list_head *hwi_get_async_busy_list(struct hwi_async_pdu_context
1557 *pasync_ctx, unsigned int is_header,
1558 unsigned int host_write_ptr)
1559{
1560 if (is_header)
1561 return &pasync_ctx->async_entry[host_write_ptr].
1562 header_busy_list;
1563 else
1564 return &pasync_ctx->async_entry[host_write_ptr].data_busy_list;
1565}
1566
1567static struct async_pdu_handle *
1568hwi_get_async_handle(struct beiscsi_hba *phba,
1569 struct beiscsi_conn *beiscsi_conn,
1570 struct hwi_async_pdu_context *pasync_ctx,
1571 struct i_t_dpdu_cqe *pdpdu_cqe, unsigned int *pcq_index)
1572{
1573 struct be_bus_address phys_addr;
1574 struct list_head *pbusy_list;
1575 struct async_pdu_handle *pasync_handle = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301576 unsigned char is_header = 0;
John Soni Jose73133262012-10-20 04:44:49 +05301577 unsigned int index, dpl;
1578
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07001579 if (is_chip_be2_be3r(phba)) {
John Soni Jose73133262012-10-20 04:44:49 +05301580 dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe,
1581 dpl, pdpdu_cqe);
1582 index = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe,
1583 index, pdpdu_cqe);
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07001584 } else {
1585 dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2,
1586 dpl, pdpdu_cqe);
1587 index = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2,
1588 index, pdpdu_cqe);
John Soni Jose73133262012-10-20 04:44:49 +05301589 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301590
1591 phys_addr.u.a32.address_lo =
John Soni Jose73133262012-10-20 04:44:49 +05301592 (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
1593 db_addr_lo) / 32] - dpl);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301594 phys_addr.u.a32.address_hi =
John Soni Jose73133262012-10-20 04:44:49 +05301595 pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
1596 db_addr_hi) / 32];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301597
1598 phys_addr.u.a64.address =
1599 *((unsigned long long *)(&phys_addr.u.a64.address));
1600
1601 switch (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, code) / 32]
1602 & PDUCQE_CODE_MASK) {
1603 case UNSOL_HDR_NOTIFY:
1604 is_header = 1;
1605
John Soni Jose73133262012-10-20 04:44:49 +05301606 pbusy_list = hwi_get_async_busy_list(pasync_ctx,
1607 is_header, index);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301608 break;
1609 case UNSOL_DATA_NOTIFY:
John Soni Jose73133262012-10-20 04:44:49 +05301610 pbusy_list = hwi_get_async_busy_list(pasync_ctx,
1611 is_header, index);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301612 break;
1613 default:
1614 pbusy_list = NULL;
John Soni Jose99bc5d52012-08-20 23:00:18 +05301615 beiscsi_log(phba, KERN_WARNING,
1616 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1617 "BM_%d : Unexpected code=%d\n",
1618 pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
1619 code) / 32] & PDUCQE_CODE_MASK);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301620 return NULL;
1621 }
1622
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301623 WARN_ON(list_empty(pbusy_list));
1624 list_for_each_entry(pasync_handle, pbusy_list, link) {
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05001625 if (pasync_handle->pa.u.a64.address == phys_addr.u.a64.address)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301626 break;
1627 }
1628
1629 WARN_ON(!pasync_handle);
1630
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001631 pasync_handle->cri = BE_GET_ASYNC_CRI_FROM_CID(
1632 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301633 pasync_handle->is_header = is_header;
John Soni Jose73133262012-10-20 04:44:49 +05301634 pasync_handle->buffer_len = dpl;
1635 *pcq_index = index;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301636
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301637 return pasync_handle;
1638}
1639
1640static unsigned int
John Soni Jose99bc5d52012-08-20 23:00:18 +05301641hwi_update_async_writables(struct beiscsi_hba *phba,
1642 struct hwi_async_pdu_context *pasync_ctx,
1643 unsigned int is_header, unsigned int cq_index)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301644{
1645 struct list_head *pbusy_list;
1646 struct async_pdu_handle *pasync_handle;
1647 unsigned int num_entries, writables = 0;
1648 unsigned int *pep_read_ptr, *pwritables;
1649
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05001650 num_entries = pasync_ctx->num_entries;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301651 if (is_header) {
1652 pep_read_ptr = &pasync_ctx->async_header.ep_read_ptr;
1653 pwritables = &pasync_ctx->async_header.writables;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301654 } else {
1655 pep_read_ptr = &pasync_ctx->async_data.ep_read_ptr;
1656 pwritables = &pasync_ctx->async_data.writables;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301657 }
1658
1659 while ((*pep_read_ptr) != cq_index) {
1660 (*pep_read_ptr)++;
1661 *pep_read_ptr = (*pep_read_ptr) % num_entries;
1662
1663 pbusy_list = hwi_get_async_busy_list(pasync_ctx, is_header,
1664 *pep_read_ptr);
1665 if (writables == 0)
1666 WARN_ON(list_empty(pbusy_list));
1667
1668 if (!list_empty(pbusy_list)) {
1669 pasync_handle = list_entry(pbusy_list->next,
1670 struct async_pdu_handle,
1671 link);
1672 WARN_ON(!pasync_handle);
1673 pasync_handle->consumed = 1;
1674 }
1675
1676 writables++;
1677 }
1678
1679 if (!writables) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301680 beiscsi_log(phba, KERN_ERR,
1681 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1682 "BM_%d : Duplicate notification received - index 0x%x!!\n",
1683 cq_index);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301684 WARN_ON(1);
1685 }
1686
1687 *pwritables = *pwritables + writables;
1688 return 0;
1689}
1690
Jayamohan Kallickal9728d8d2012-04-03 23:41:47 -05001691static void hwi_free_async_msg(struct beiscsi_hba *phba,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001692 struct hwi_async_pdu_context *pasync_ctx,
1693 unsigned int cri)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301694{
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301695 struct async_pdu_handle *pasync_handle, *tmp_handle;
1696 struct list_head *plist;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301697
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301698 plist = &pasync_ctx->async_entry[cri].wait_queue.list;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301699 list_for_each_entry_safe(pasync_handle, tmp_handle, plist, link) {
1700 list_del(&pasync_handle->link);
1701
Jayamohan Kallickal9728d8d2012-04-03 23:41:47 -05001702 if (pasync_handle->is_header) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301703 list_add_tail(&pasync_handle->link,
1704 &pasync_ctx->async_header.free_list);
1705 pasync_ctx->async_header.free_entries++;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301706 } else {
1707 list_add_tail(&pasync_handle->link,
1708 &pasync_ctx->async_data.free_list);
1709 pasync_ctx->async_data.free_entries++;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301710 }
1711 }
1712
1713 INIT_LIST_HEAD(&pasync_ctx->async_entry[cri].wait_queue.list);
1714 pasync_ctx->async_entry[cri].wait_queue.hdr_received = 0;
1715 pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301716}
1717
1718static struct phys_addr *
1719hwi_get_ring_address(struct hwi_async_pdu_context *pasync_ctx,
1720 unsigned int is_header, unsigned int host_write_ptr)
1721{
1722 struct phys_addr *pasync_sge = NULL;
1723
1724 if (is_header)
1725 pasync_sge = pasync_ctx->async_header.ring_base;
1726 else
1727 pasync_sge = pasync_ctx->async_data.ring_base;
1728
1729 return pasync_sge + host_write_ptr;
1730}
1731
1732static void hwi_post_async_buffers(struct beiscsi_hba *phba,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001733 unsigned int is_header, uint8_t ulp_num)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301734{
1735 struct hwi_controller *phwi_ctrlr;
1736 struct hwi_async_pdu_context *pasync_ctx;
1737 struct async_pdu_handle *pasync_handle;
1738 struct list_head *pfree_link, *pbusy_list;
1739 struct phys_addr *pasync_sge;
1740 unsigned int ring_id, num_entries;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001741 unsigned int host_write_num, doorbell_offset;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301742 unsigned int writables;
1743 unsigned int i = 0;
1744 u32 doorbell = 0;
1745
1746 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001747 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr, ulp_num);
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05001748 num_entries = pasync_ctx->num_entries;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301749
1750 if (is_header) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301751 writables = min(pasync_ctx->async_header.writables,
1752 pasync_ctx->async_header.free_entries);
1753 pfree_link = pasync_ctx->async_header.free_list.next;
1754 host_write_num = pasync_ctx->async_header.host_write_ptr;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001755 ring_id = phwi_ctrlr->default_pdu_hdr[ulp_num].id;
1756 doorbell_offset = phwi_ctrlr->default_pdu_hdr[ulp_num].
1757 doorbell_offset;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301758 } else {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301759 writables = min(pasync_ctx->async_data.writables,
1760 pasync_ctx->async_data.free_entries);
1761 pfree_link = pasync_ctx->async_data.free_list.next;
1762 host_write_num = pasync_ctx->async_data.host_write_ptr;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001763 ring_id = phwi_ctrlr->default_pdu_data[ulp_num].id;
1764 doorbell_offset = phwi_ctrlr->default_pdu_data[ulp_num].
1765 doorbell_offset;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301766 }
1767
1768 writables = (writables / 8) * 8;
1769 if (writables) {
1770 for (i = 0; i < writables; i++) {
1771 pbusy_list =
1772 hwi_get_async_busy_list(pasync_ctx, is_header,
1773 host_write_num);
1774 pasync_handle =
1775 list_entry(pfree_link, struct async_pdu_handle,
1776 link);
1777 WARN_ON(!pasync_handle);
1778 pasync_handle->consumed = 0;
1779
1780 pfree_link = pfree_link->next;
1781
1782 pasync_sge = hwi_get_ring_address(pasync_ctx,
1783 is_header, host_write_num);
1784
1785 pasync_sge->hi = pasync_handle->pa.u.a32.address_lo;
1786 pasync_sge->lo = pasync_handle->pa.u.a32.address_hi;
1787
1788 list_move(&pasync_handle->link, pbusy_list);
1789
1790 host_write_num++;
1791 host_write_num = host_write_num % num_entries;
1792 }
1793
1794 if (is_header) {
1795 pasync_ctx->async_header.host_write_ptr =
1796 host_write_num;
1797 pasync_ctx->async_header.free_entries -= writables;
1798 pasync_ctx->async_header.writables -= writables;
1799 pasync_ctx->async_header.busy_entries += writables;
1800 } else {
1801 pasync_ctx->async_data.host_write_ptr = host_write_num;
1802 pasync_ctx->async_data.free_entries -= writables;
1803 pasync_ctx->async_data.writables -= writables;
1804 pasync_ctx->async_data.busy_entries += writables;
1805 }
1806
1807 doorbell |= ring_id & DB_DEF_PDU_RING_ID_MASK;
1808 doorbell |= 1 << DB_DEF_PDU_REARM_SHIFT;
1809 doorbell |= 0 << DB_DEF_PDU_EVENT_SHIFT;
1810 doorbell |= (writables & DB_DEF_PDU_CQPROC_MASK)
1811 << DB_DEF_PDU_CQPROC_SHIFT;
1812
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001813 iowrite32(doorbell, phba->db_va + doorbell_offset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301814 }
1815}
1816
1817static void hwi_flush_default_pdu_buffer(struct beiscsi_hba *phba,
1818 struct beiscsi_conn *beiscsi_conn,
1819 struct i_t_dpdu_cqe *pdpdu_cqe)
1820{
1821 struct hwi_controller *phwi_ctrlr;
1822 struct hwi_async_pdu_context *pasync_ctx;
1823 struct async_pdu_handle *pasync_handle = NULL;
1824 unsigned int cq_index = -1;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001825 uint16_t cri_index = BE_GET_CRI_FROM_CID(
1826 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301827
1828 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001829 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr,
1830 BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr,
1831 cri_index));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301832
1833 pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
1834 pdpdu_cqe, &cq_index);
1835 BUG_ON(pasync_handle->is_header != 0);
1836 if (pasync_handle->consumed == 0)
John Soni Jose99bc5d52012-08-20 23:00:18 +05301837 hwi_update_async_writables(phba, pasync_ctx,
1838 pasync_handle->is_header, cq_index);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301839
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001840 hwi_free_async_msg(phba, pasync_ctx, pasync_handle->cri);
1841 hwi_post_async_buffers(phba, pasync_handle->is_header,
1842 BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr,
1843 cri_index));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301844}
1845
1846static unsigned int
1847hwi_fwd_async_msg(struct beiscsi_conn *beiscsi_conn,
1848 struct beiscsi_hba *phba,
1849 struct hwi_async_pdu_context *pasync_ctx, unsigned short cri)
1850{
1851 struct list_head *plist;
1852 struct async_pdu_handle *pasync_handle;
1853 void *phdr = NULL;
1854 unsigned int hdr_len = 0, buf_len = 0;
1855 unsigned int status, index = 0, offset = 0;
1856 void *pfirst_buffer = NULL;
1857 unsigned int num_buf = 0;
1858
1859 plist = &pasync_ctx->async_entry[cri].wait_queue.list;
1860
1861 list_for_each_entry(pasync_handle, plist, link) {
1862 if (index == 0) {
1863 phdr = pasync_handle->pbuffer;
1864 hdr_len = pasync_handle->buffer_len;
1865 } else {
1866 buf_len = pasync_handle->buffer_len;
1867 if (!num_buf) {
1868 pfirst_buffer = pasync_handle->pbuffer;
1869 num_buf++;
1870 }
1871 memcpy(pfirst_buffer + offset,
1872 pasync_handle->pbuffer, buf_len);
Jayamohan Kallickalf2ba02b2012-04-03 23:41:37 -05001873 offset += buf_len;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301874 }
1875 index++;
1876 }
1877
1878 status = beiscsi_process_async_pdu(beiscsi_conn, phba,
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05301879 phdr, hdr_len, pfirst_buffer,
Jayamohan Kallickalf2ba02b2012-04-03 23:41:37 -05001880 offset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301881
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001882 hwi_free_async_msg(phba, pasync_ctx, cri);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301883 return 0;
1884}
1885
1886static unsigned int
1887hwi_gather_async_pdu(struct beiscsi_conn *beiscsi_conn,
1888 struct beiscsi_hba *phba,
1889 struct async_pdu_handle *pasync_handle)
1890{
1891 struct hwi_async_pdu_context *pasync_ctx;
1892 struct hwi_controller *phwi_ctrlr;
1893 unsigned int bytes_needed = 0, status = 0;
1894 unsigned short cri = pasync_handle->cri;
1895 struct pdu_base *ppdu;
1896
1897 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001898 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr,
1899 BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr,
1900 BE_GET_CRI_FROM_CID(beiscsi_conn->
1901 beiscsi_conn_cid)));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301902
1903 list_del(&pasync_handle->link);
1904 if (pasync_handle->is_header) {
1905 pasync_ctx->async_header.busy_entries--;
1906 if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) {
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001907 hwi_free_async_msg(phba, pasync_ctx, cri);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301908 BUG();
1909 }
1910
1911 pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0;
1912 pasync_ctx->async_entry[cri].wait_queue.hdr_received = 1;
1913 pasync_ctx->async_entry[cri].wait_queue.hdr_len =
1914 (unsigned short)pasync_handle->buffer_len;
1915 list_add_tail(&pasync_handle->link,
1916 &pasync_ctx->async_entry[cri].wait_queue.list);
1917
1918 ppdu = pasync_handle->pbuffer;
1919 bytes_needed = ((((ppdu->dw[offsetof(struct amap_pdu_base,
1920 data_len_hi) / 32] & PDUBASE_DATALENHI_MASK) << 8) &
1921 0xFFFF0000) | ((be16_to_cpu((ppdu->
1922 dw[offsetof(struct amap_pdu_base, data_len_lo) / 32]
1923 & PDUBASE_DATALENLO_MASK) >> 16)) & 0x0000FFFF));
1924
1925 if (status == 0) {
1926 pasync_ctx->async_entry[cri].wait_queue.bytes_needed =
1927 bytes_needed;
1928
1929 if (bytes_needed == 0)
1930 status = hwi_fwd_async_msg(beiscsi_conn, phba,
1931 pasync_ctx, cri);
1932 }
1933 } else {
1934 pasync_ctx->async_data.busy_entries--;
1935 if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) {
1936 list_add_tail(&pasync_handle->link,
1937 &pasync_ctx->async_entry[cri].wait_queue.
1938 list);
1939 pasync_ctx->async_entry[cri].wait_queue.
1940 bytes_received +=
1941 (unsigned short)pasync_handle->buffer_len;
1942
1943 if (pasync_ctx->async_entry[cri].wait_queue.
1944 bytes_received >=
1945 pasync_ctx->async_entry[cri].wait_queue.
1946 bytes_needed)
1947 status = hwi_fwd_async_msg(beiscsi_conn, phba,
1948 pasync_ctx, cri);
1949 }
1950 }
1951 return status;
1952}
1953
1954static void hwi_process_default_pdu_ring(struct beiscsi_conn *beiscsi_conn,
1955 struct beiscsi_hba *phba,
1956 struct i_t_dpdu_cqe *pdpdu_cqe)
1957{
1958 struct hwi_controller *phwi_ctrlr;
1959 struct hwi_async_pdu_context *pasync_ctx;
1960 struct async_pdu_handle *pasync_handle = NULL;
1961 unsigned int cq_index = -1;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001962 uint16_t cri_index = BE_GET_CRI_FROM_CID(
1963 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301964
1965 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001966 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr,
1967 BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr,
1968 cri_index));
1969
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301970 pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
1971 pdpdu_cqe, &cq_index);
1972
1973 if (pasync_handle->consumed == 0)
John Soni Jose99bc5d52012-08-20 23:00:18 +05301974 hwi_update_async_writables(phba, pasync_ctx,
1975 pasync_handle->is_header, cq_index);
1976
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301977 hwi_gather_async_pdu(beiscsi_conn, phba, pasync_handle);
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001978 hwi_post_async_buffers(phba, pasync_handle->is_header,
1979 BEISCSI_GET_ULP_FROM_CRI(
1980 phwi_ctrlr, cri_index));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301981}
1982
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05301983static void beiscsi_process_mcc_isr(struct beiscsi_hba *phba)
1984{
1985 struct be_queue_info *mcc_cq;
1986 struct be_mcc_compl *mcc_compl;
1987 unsigned int num_processed = 0;
1988
1989 mcc_cq = &phba->ctrl.mcc_obj.cq;
1990 mcc_compl = queue_tail_node(mcc_cq);
1991 mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
1992 while (mcc_compl->flags & CQE_FLAGS_VALID_MASK) {
1993
1994 if (num_processed >= 32) {
1995 hwi_ring_cq_db(phba, mcc_cq->id,
1996 num_processed, 0, 0);
1997 num_processed = 0;
1998 }
1999 if (mcc_compl->flags & CQE_FLAGS_ASYNC_MASK) {
2000 /* Interpret flags as an async trailer */
2001 if (is_link_state_evt(mcc_compl->flags))
2002 /* Interpret compl as a async link evt */
2003 beiscsi_async_link_state_process(phba,
2004 (struct be_async_event_link_state *) mcc_compl);
2005 else
John Soni Jose99bc5d52012-08-20 23:00:18 +05302006 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_MBOX,
2007 "BM_%d : Unsupported Async Event, flags"
2008 " = 0x%08x\n",
2009 mcc_compl->flags);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05302010 } else if (mcc_compl->flags & CQE_FLAGS_COMPLETED_MASK) {
2011 be_mcc_compl_process_isr(&phba->ctrl, mcc_compl);
2012 atomic_dec(&phba->ctrl.mcc_obj.q.used);
2013 }
2014
2015 mcc_compl->flags = 0;
2016 queue_tail_inc(mcc_cq);
2017 mcc_compl = queue_tail_node(mcc_cq);
2018 mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
2019 num_processed++;
2020 }
2021
2022 if (num_processed > 0)
2023 hwi_ring_cq_db(phba, mcc_cq->id, num_processed, 1, 0);
2024
2025}
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302026
John Soni Jose6763daa2012-10-20 04:41:45 +05302027/**
2028 * beiscsi_process_cq()- Process the Completion Queue
2029 * @pbe_eq: Event Q on which the Completion has come
2030 *
2031 * return
2032 * Number of Completion Entries processed.
2033 **/
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302034static unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302035{
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302036 struct be_queue_info *cq;
2037 struct sol_cqe *sol;
2038 struct dmsg_cqe *dmsg;
2039 unsigned int num_processed = 0;
2040 unsigned int tot_nump = 0;
John Soni Jose0a513dd2012-08-20 23:00:55 +05302041 unsigned short code = 0, cid = 0;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002042 uint16_t cri_index = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302043 struct beiscsi_conn *beiscsi_conn;
Jayamohan Kallickalc2462282010-01-05 05:05:34 +05302044 struct beiscsi_endpoint *beiscsi_ep;
2045 struct iscsi_endpoint *ep;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302046 struct beiscsi_hba *phba;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302047
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302048 cq = pbe_eq->cq;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302049 sol = queue_tail_node(cq);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302050 phba = pbe_eq->phba;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302051
2052 while (sol->dw[offsetof(struct amap_sol_cqe, valid) / 32] &
2053 CQE_VALID_MASK) {
2054 be_dws_le_to_cpu(sol, sizeof(struct sol_cqe));
2055
John Soni Jose73133262012-10-20 04:44:49 +05302056 code = (sol->dw[offsetof(struct amap_sol_cqe, code) /
2057 32] & CQE_CODE_MASK);
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05302058
John Soni Jose73133262012-10-20 04:44:49 +05302059 /* Get the CID */
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07002060 if (is_chip_be2_be3r(phba)) {
2061 cid = AMAP_GET_BITS(struct amap_sol_cqe, cid, sol);
2062 } else {
John Soni Jose73133262012-10-20 04:44:49 +05302063 if ((code == DRIVERMSG_NOTIFY) ||
2064 (code == UNSOL_HDR_NOTIFY) ||
2065 (code == UNSOL_DATA_NOTIFY))
2066 cid = AMAP_GET_BITS(
2067 struct amap_i_t_dpdu_cqe_v2,
2068 cid, sol);
2069 else
2070 cid = AMAP_GET_BITS(struct amap_sol_cqe_v2,
2071 cid, sol);
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07002072 }
John Soni Jose73133262012-10-20 04:44:49 +05302073
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002074 cri_index = BE_GET_CRI_FROM_CID(cid);
2075 ep = phba->ep_array[cri_index];
Jayamohan Kallickalc2462282010-01-05 05:05:34 +05302076 beiscsi_ep = ep->dd_data;
2077 beiscsi_conn = beiscsi_ep->conn;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05302078
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302079 if (num_processed >= 32) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302080 hwi_ring_cq_db(phba, cq->id,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302081 num_processed, 0, 0);
2082 tot_nump += num_processed;
2083 num_processed = 0;
2084 }
2085
John Soni Jose0a513dd2012-08-20 23:00:55 +05302086 switch (code) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302087 case SOL_CMD_COMPLETE:
2088 hwi_complete_cmd(beiscsi_conn, phba, sol);
2089 break;
2090 case DRIVERMSG_NOTIFY:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302091 beiscsi_log(phba, KERN_INFO,
2092 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302093 "BM_%d : Received %s[%d] on CID : %d\n",
2094 cqe_desc[code], code, cid);
John Soni Jose99bc5d52012-08-20 23:00:18 +05302095
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302096 dmsg = (struct dmsg_cqe *)sol;
2097 hwi_complete_drvr_msgs(beiscsi_conn, phba, sol);
2098 break;
2099 case UNSOL_HDR_NOTIFY:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302100 beiscsi_log(phba, KERN_INFO,
2101 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302102 "BM_%d : Received %s[%d] on CID : %d\n",
2103 cqe_desc[code], code, cid);
John Soni Jose99bc5d52012-08-20 23:00:18 +05302104
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07002105 spin_lock_bh(&phba->async_pdu_lock);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302106 hwi_process_default_pdu_ring(beiscsi_conn, phba,
2107 (struct i_t_dpdu_cqe *)sol);
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07002108 spin_unlock_bh(&phba->async_pdu_lock);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302109 break;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302110 case UNSOL_DATA_NOTIFY:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302111 beiscsi_log(phba, KERN_INFO,
2112 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
John Soni Jose6763daa2012-10-20 04:41:45 +05302113 "BM_%d : Received %s[%d] on CID : %d\n",
2114 cqe_desc[code], code, cid);
John Soni Jose99bc5d52012-08-20 23:00:18 +05302115
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07002116 spin_lock_bh(&phba->async_pdu_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302117 hwi_process_default_pdu_ring(beiscsi_conn, phba,
2118 (struct i_t_dpdu_cqe *)sol);
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07002119 spin_unlock_bh(&phba->async_pdu_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302120 break;
2121 case CXN_INVALIDATE_INDEX_NOTIFY:
2122 case CMD_INVALIDATED_NOTIFY:
2123 case CXN_INVALIDATE_NOTIFY:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302124 beiscsi_log(phba, KERN_ERR,
2125 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302126 "BM_%d : Ignoring %s[%d] on CID : %d\n",
2127 cqe_desc[code], code, cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302128 break;
2129 case SOL_CMD_KILLED_DATA_DIGEST_ERR:
2130 case CMD_KILLED_INVALID_STATSN_RCVD:
2131 case CMD_KILLED_INVALID_R2T_RCVD:
2132 case CMD_CXN_KILLED_LUN_INVALID:
2133 case CMD_CXN_KILLED_ICD_INVALID:
2134 case CMD_CXN_KILLED_ITT_INVALID:
2135 case CMD_CXN_KILLED_SEQ_OUTOFORDER:
2136 case CMD_CXN_KILLED_INVALID_DATASN_RCVD:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302137 beiscsi_log(phba, KERN_ERR,
2138 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
John Soni Jose6763daa2012-10-20 04:41:45 +05302139 "BM_%d : Cmd Notification %s[%d] on CID : %d\n",
2140 cqe_desc[code], code, cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302141 break;
2142 case UNSOL_DATA_DIGEST_ERROR_NOTIFY:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302143 beiscsi_log(phba, KERN_ERR,
2144 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302145 "BM_%d : Dropping %s[%d] on DPDU ring on CID : %d\n",
2146 cqe_desc[code], code, cid);
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07002147 spin_lock_bh(&phba->async_pdu_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302148 hwi_flush_default_pdu_buffer(phba, beiscsi_conn,
2149 (struct i_t_dpdu_cqe *) sol);
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07002150 spin_unlock_bh(&phba->async_pdu_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302151 break;
2152 case CXN_KILLED_PDU_SIZE_EXCEEDS_DSL:
2153 case CXN_KILLED_BURST_LEN_MISMATCH:
2154 case CXN_KILLED_AHS_RCVD:
2155 case CXN_KILLED_HDR_DIGEST_ERR:
2156 case CXN_KILLED_UNKNOWN_HDR:
2157 case CXN_KILLED_STALE_ITT_TTT_RCVD:
2158 case CXN_KILLED_INVALID_ITT_TTT_RCVD:
2159 case CXN_KILLED_TIMED_OUT:
2160 case CXN_KILLED_FIN_RCVD:
John Soni Jose6763daa2012-10-20 04:41:45 +05302161 case CXN_KILLED_RST_SENT:
2162 case CXN_KILLED_RST_RCVD:
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302163 case CXN_KILLED_BAD_UNSOL_PDU_RCVD:
2164 case CXN_KILLED_BAD_WRB_INDEX_ERROR:
2165 case CXN_KILLED_OVER_RUN_RESIDUAL:
2166 case CXN_KILLED_UNDER_RUN_RESIDUAL:
2167 case CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302168 beiscsi_log(phba, KERN_ERR,
2169 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302170 "BM_%d : Event %s[%d] received on CID : %d\n",
2171 cqe_desc[code], code, cid);
John Soni Jose0a513dd2012-08-20 23:00:55 +05302172 if (beiscsi_conn)
2173 iscsi_conn_failure(beiscsi_conn->conn,
2174 ISCSI_ERR_CONN_FAILED);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302175 break;
2176 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302177 beiscsi_log(phba, KERN_ERR,
2178 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302179 "BM_%d : Invalid CQE Event Received Code : %d"
2180 "CID 0x%x...\n",
John Soni Jose0a513dd2012-08-20 23:00:55 +05302181 code, cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302182 break;
2183 }
2184
2185 AMAP_SET_BITS(struct amap_sol_cqe, valid, sol, 0);
2186 queue_tail_inc(cq);
2187 sol = queue_tail_node(cq);
2188 num_processed++;
2189 }
2190
2191 if (num_processed > 0) {
2192 tot_nump += num_processed;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302193 hwi_ring_cq_db(phba, cq->id, num_processed, 1, 0);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302194 }
2195 return tot_nump;
2196}
2197
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05302198void beiscsi_process_all_cqs(struct work_struct *work)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302199{
2200 unsigned long flags;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302201 struct hwi_controller *phwi_ctrlr;
2202 struct hwi_context_memory *phwi_context;
John Soni Jose72fb46a2012-10-20 04:42:49 +05302203 struct beiscsi_hba *phba;
2204 struct be_eq_obj *pbe_eq =
2205 container_of(work, struct be_eq_obj, work_cqs);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302206
John Soni Jose72fb46a2012-10-20 04:42:49 +05302207 phba = pbe_eq->phba;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302208 phwi_ctrlr = phba->phwi_ctrlr;
2209 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302210
John Soni Jose72fb46a2012-10-20 04:42:49 +05302211 if (pbe_eq->todo_mcc_cq) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302212 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +05302213 pbe_eq->todo_mcc_cq = false;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302214 spin_unlock_irqrestore(&phba->isr_lock, flags);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05302215 beiscsi_process_mcc_isr(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302216 }
2217
John Soni Jose72fb46a2012-10-20 04:42:49 +05302218 if (pbe_eq->todo_cq) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302219 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +05302220 pbe_eq->todo_cq = false;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302221 spin_unlock_irqrestore(&phba->isr_lock, flags);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302222 beiscsi_process_cq(pbe_eq);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302223 }
John Soni Jose72fb46a2012-10-20 04:42:49 +05302224
2225 /* rearm EQ for further interrupts */
2226 hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302227}
2228
2229static int be_iopoll(struct blk_iopoll *iop, int budget)
2230{
Shlomo Pongratzad3f4282013-04-05 20:38:36 -07002231 unsigned int ret;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302232 struct beiscsi_hba *phba;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302233 struct be_eq_obj *pbe_eq;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302234
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302235 pbe_eq = container_of(iop, struct be_eq_obj, iopoll);
2236 ret = beiscsi_process_cq(pbe_eq);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302237 if (ret < budget) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302238 phba = pbe_eq->phba;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302239 blk_iopoll_complete(iop);
John Soni Jose99bc5d52012-08-20 23:00:18 +05302240 beiscsi_log(phba, KERN_INFO,
2241 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
2242 "BM_%d : rearm pbe_eq->q.id =%d\n",
2243 pbe_eq->q.id);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302244 hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302245 }
2246 return ret;
2247}
2248
2249static void
John Soni Jose09a10932012-10-20 04:44:23 +05302250hwi_write_sgl_v2(struct iscsi_wrb *pwrb, struct scatterlist *sg,
2251 unsigned int num_sg, struct beiscsi_io_task *io_task)
2252{
2253 struct iscsi_sge *psgl;
2254 unsigned int sg_len, index;
2255 unsigned int sge_len = 0;
2256 unsigned long long addr;
2257 struct scatterlist *l_sg;
2258 unsigned int offset;
2259
2260 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_lo, pwrb,
2261 io_task->bhs_pa.u.a32.address_lo);
2262 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_hi, pwrb,
2263 io_task->bhs_pa.u.a32.address_hi);
2264
2265 l_sg = sg;
2266 for (index = 0; (index < num_sg) && (index < 2); index++,
2267 sg = sg_next(sg)) {
2268 if (index == 0) {
2269 sg_len = sg_dma_len(sg);
2270 addr = (u64) sg_dma_address(sg);
2271 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2272 sge0_addr_lo, pwrb,
2273 lower_32_bits(addr));
2274 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2275 sge0_addr_hi, pwrb,
2276 upper_32_bits(addr));
2277 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2278 sge0_len, pwrb,
2279 sg_len);
2280 sge_len = sg_len;
2281 } else {
2282 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_r2t_offset,
2283 pwrb, sge_len);
2284 sg_len = sg_dma_len(sg);
2285 addr = (u64) sg_dma_address(sg);
2286 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2287 sge1_addr_lo, pwrb,
2288 lower_32_bits(addr));
2289 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2290 sge1_addr_hi, pwrb,
2291 upper_32_bits(addr));
2292 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2293 sge1_len, pwrb,
2294 sg_len);
2295 }
2296 }
2297 psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
2298 memset(psgl, 0, sizeof(*psgl) * BE2_SGE);
2299
2300 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2);
2301
2302 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2303 io_task->bhs_pa.u.a32.address_hi);
2304 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2305 io_task->bhs_pa.u.a32.address_lo);
2306
2307 if (num_sg == 1) {
2308 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb,
2309 1);
2310 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb,
2311 0);
2312 } else if (num_sg == 2) {
2313 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb,
2314 0);
2315 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb,
2316 1);
2317 } else {
2318 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb,
2319 0);
2320 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb,
2321 0);
2322 }
2323
2324 sg = l_sg;
2325 psgl++;
2326 psgl++;
2327 offset = 0;
2328 for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) {
2329 sg_len = sg_dma_len(sg);
2330 addr = (u64) sg_dma_address(sg);
2331 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2332 lower_32_bits(addr));
2333 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2334 upper_32_bits(addr));
2335 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len);
2336 AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset);
2337 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
2338 offset += sg_len;
2339 }
2340 psgl--;
2341 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
2342}
2343
2344static void
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302345hwi_write_sgl(struct iscsi_wrb *pwrb, struct scatterlist *sg,
2346 unsigned int num_sg, struct beiscsi_io_task *io_task)
2347{
2348 struct iscsi_sge *psgl;
Jayamohan Kallickal58ff4bd2010-10-06 23:46:47 +05302349 unsigned int sg_len, index;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302350 unsigned int sge_len = 0;
2351 unsigned long long addr;
2352 struct scatterlist *l_sg;
2353 unsigned int offset;
2354
2355 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
2356 io_task->bhs_pa.u.a32.address_lo);
2357 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
2358 io_task->bhs_pa.u.a32.address_hi);
2359
2360 l_sg = sg;
Jayamohan Kallickal48bd86c2010-01-07 01:50:19 +05302361 for (index = 0; (index < num_sg) && (index < 2); index++,
2362 sg = sg_next(sg)) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302363 if (index == 0) {
2364 sg_len = sg_dma_len(sg);
2365 addr = (u64) sg_dma_address(sg);
2366 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302367 ((u32)(addr & 0xFFFFFFFF)));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302368 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302369 ((u32)(addr >> 32)));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302370 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
2371 sg_len);
2372 sge_len = sg_len;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302373 } else {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302374 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_r2t_offset,
2375 pwrb, sge_len);
2376 sg_len = sg_dma_len(sg);
2377 addr = (u64) sg_dma_address(sg);
2378 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_lo, pwrb,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302379 ((u32)(addr & 0xFFFFFFFF)));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302380 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_hi, pwrb,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302381 ((u32)(addr >> 32)));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302382 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_len, pwrb,
2383 sg_len);
2384 }
2385 }
2386 psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
2387 memset(psgl, 0, sizeof(*psgl) * BE2_SGE);
2388
2389 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2);
2390
2391 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2392 io_task->bhs_pa.u.a32.address_hi);
2393 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2394 io_task->bhs_pa.u.a32.address_lo);
2395
Jayamohan Kallickalcaf818f2010-01-23 05:38:18 +05302396 if (num_sg == 1) {
2397 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
2398 1);
2399 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
2400 0);
2401 } else if (num_sg == 2) {
2402 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
2403 0);
2404 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
2405 1);
2406 } else {
2407 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
2408 0);
2409 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
2410 0);
2411 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302412 sg = l_sg;
2413 psgl++;
2414 psgl++;
2415 offset = 0;
Jayamohan Kallickal48bd86c2010-01-07 01:50:19 +05302416 for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302417 sg_len = sg_dma_len(sg);
2418 addr = (u64) sg_dma_address(sg);
2419 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2420 (addr & 0xFFFFFFFF));
2421 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2422 (addr >> 32));
2423 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len);
2424 AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset);
2425 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
2426 offset += sg_len;
2427 }
2428 psgl--;
2429 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
2430}
2431
John Soni Josed629c472012-10-20 04:42:00 +05302432/**
2433 * hwi_write_buffer()- Populate the WRB with task info
2434 * @pwrb: ptr to the WRB entry
2435 * @task: iscsi task which is to be executed
2436 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302437static void hwi_write_buffer(struct iscsi_wrb *pwrb, struct iscsi_task *task)
2438{
2439 struct iscsi_sge *psgl;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302440 struct beiscsi_io_task *io_task = task->dd_data;
2441 struct beiscsi_conn *beiscsi_conn = io_task->conn;
2442 struct beiscsi_hba *phba = beiscsi_conn->phba;
John Soni Jose09a10932012-10-20 04:44:23 +05302443 uint8_t dsp_value = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302444
2445 io_task->bhs_len = sizeof(struct be_nonio_bhs) - 2;
2446 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
2447 io_task->bhs_pa.u.a32.address_lo);
2448 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
2449 io_task->bhs_pa.u.a32.address_hi);
2450
2451 if (task->data) {
John Soni Jose09a10932012-10-20 04:44:23 +05302452
2453 /* Check for the data_count */
2454 dsp_value = (task->data_count) ? 1 : 0;
2455
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07002456 if (is_chip_be2_be3r(phba))
2457 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp,
John Soni Jose09a10932012-10-20 04:44:23 +05302458 pwrb, dsp_value);
2459 else
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07002460 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp,
John Soni Jose09a10932012-10-20 04:44:23 +05302461 pwrb, dsp_value);
2462
2463 /* Map addr only if there is data_count */
2464 if (dsp_value) {
John Soni Josed629c472012-10-20 04:42:00 +05302465 io_task->mtask_addr = pci_map_single(phba->pcidev,
2466 task->data,
2467 task->data_count,
2468 PCI_DMA_TODEVICE);
John Soni Josed629c472012-10-20 04:42:00 +05302469 io_task->mtask_data_count = task->data_count;
John Soni Jose09a10932012-10-20 04:44:23 +05302470 } else
John Soni Josed629c472012-10-20 04:42:00 +05302471 io_task->mtask_addr = 0;
John Soni Jose09a10932012-10-20 04:44:23 +05302472
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302473 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
John Soni Josed629c472012-10-20 04:42:00 +05302474 lower_32_bits(io_task->mtask_addr));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302475 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
John Soni Josed629c472012-10-20 04:42:00 +05302476 upper_32_bits(io_task->mtask_addr));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302477 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
2478 task->data_count);
2479
2480 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, 1);
2481 } else {
2482 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
John Soni Josed629c472012-10-20 04:42:00 +05302483 io_task->mtask_addr = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302484 }
2485
2486 psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
2487
2488 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len);
2489
2490 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2491 io_task->bhs_pa.u.a32.address_hi);
2492 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2493 io_task->bhs_pa.u.a32.address_lo);
2494 if (task->data) {
2495 psgl++;
2496 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, 0);
2497 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, 0);
2498 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0);
2499 AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, 0);
2500 AMAP_SET_BITS(struct amap_iscsi_sge, rsvd0, psgl, 0);
2501 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
2502
2503 psgl++;
2504 if (task->data) {
2505 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
John Soni Josed629c472012-10-20 04:42:00 +05302506 lower_32_bits(io_task->mtask_addr));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302507 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
John Soni Josed629c472012-10-20 04:42:00 +05302508 upper_32_bits(io_task->mtask_addr));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302509 }
2510 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0x106);
2511 }
2512 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
2513}
2514
Jayamohan Kallickal843ae752013-09-28 15:35:44 -07002515/**
2516 * beiscsi_find_mem_req()- Find mem needed
2517 * @phba: ptr to HBA struct
2518 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302519static void beiscsi_find_mem_req(struct beiscsi_hba *phba)
2520{
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002521 uint8_t mem_descr_index, ulp_num;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302522 unsigned int num_cq_pages, num_async_pdu_buf_pages;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302523 unsigned int num_async_pdu_data_pages, wrb_sz_per_cxn;
2524 unsigned int num_async_pdu_buf_sgl_pages, num_async_pdu_data_sgl_pages;
2525
2526 num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
2527 sizeof(struct sol_cqe));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302528
2529 phba->params.hwi_ws_sz = sizeof(struct hwi_controller);
2530
2531 phba->mem_req[ISCSI_MEM_GLOBAL_HEADER] = 2 *
2532 BE_ISCSI_PDU_HEADER_SIZE;
2533 phba->mem_req[HWI_MEM_ADDN_CONTEXT] =
2534 sizeof(struct hwi_context_memory);
2535
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302536
2537 phba->mem_req[HWI_MEM_WRB] = sizeof(struct iscsi_wrb)
2538 * (phba->params.wrbs_per_cxn)
2539 * phba->params.cxns_per_ctrl;
2540 wrb_sz_per_cxn = sizeof(struct wrb_handle) *
2541 (phba->params.wrbs_per_cxn);
2542 phba->mem_req[HWI_MEM_WRBH] = roundup_pow_of_two((wrb_sz_per_cxn) *
2543 phba->params.cxns_per_ctrl);
2544
2545 phba->mem_req[HWI_MEM_SGLH] = sizeof(struct sgl_handle) *
2546 phba->params.icds_per_ctrl;
2547 phba->mem_req[HWI_MEM_SGE] = sizeof(struct iscsi_sge) *
2548 phba->params.num_sge_per_io * phba->params.icds_per_ctrl;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002549 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
2550 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302551
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002552 num_async_pdu_buf_sgl_pages =
2553 PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
2554 phba, ulp_num) *
2555 sizeof(struct phys_addr));
2556
2557 num_async_pdu_buf_pages =
2558 PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
2559 phba, ulp_num) *
2560 phba->params.defpdu_hdr_sz);
2561
2562 num_async_pdu_data_pages =
2563 PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
2564 phba, ulp_num) *
2565 phba->params.defpdu_data_sz);
2566
2567 num_async_pdu_data_sgl_pages =
2568 PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
2569 phba, ulp_num) *
2570 sizeof(struct phys_addr));
2571
Jayamohan Kallickala129d922013-09-28 15:35:46 -07002572 mem_descr_index = (HWI_MEM_TEMPLATE_HDR_ULP0 +
2573 (ulp_num * MEM_DESCR_OFFSET));
2574 phba->mem_req[mem_descr_index] =
2575 BEISCSI_GET_CID_COUNT(phba, ulp_num) *
2576 BEISCSI_TEMPLATE_HDR_PER_CXN_SIZE;
2577
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002578 mem_descr_index = (HWI_MEM_ASYNC_HEADER_BUF_ULP0 +
2579 (ulp_num * MEM_DESCR_OFFSET));
2580 phba->mem_req[mem_descr_index] =
2581 num_async_pdu_buf_pages *
2582 PAGE_SIZE;
2583
2584 mem_descr_index = (HWI_MEM_ASYNC_DATA_BUF_ULP0 +
2585 (ulp_num * MEM_DESCR_OFFSET));
2586 phba->mem_req[mem_descr_index] =
2587 num_async_pdu_data_pages *
2588 PAGE_SIZE;
2589
2590 mem_descr_index = (HWI_MEM_ASYNC_HEADER_RING_ULP0 +
2591 (ulp_num * MEM_DESCR_OFFSET));
2592 phba->mem_req[mem_descr_index] =
2593 num_async_pdu_buf_sgl_pages *
2594 PAGE_SIZE;
2595
2596 mem_descr_index = (HWI_MEM_ASYNC_DATA_RING_ULP0 +
2597 (ulp_num * MEM_DESCR_OFFSET));
2598 phba->mem_req[mem_descr_index] =
2599 num_async_pdu_data_sgl_pages *
2600 PAGE_SIZE;
2601
2602 mem_descr_index = (HWI_MEM_ASYNC_HEADER_HANDLE_ULP0 +
2603 (ulp_num * MEM_DESCR_OFFSET));
2604 phba->mem_req[mem_descr_index] =
2605 BEISCSI_GET_CID_COUNT(phba, ulp_num) *
2606 sizeof(struct async_pdu_handle);
2607
2608 mem_descr_index = (HWI_MEM_ASYNC_DATA_HANDLE_ULP0 +
2609 (ulp_num * MEM_DESCR_OFFSET));
2610 phba->mem_req[mem_descr_index] =
2611 BEISCSI_GET_CID_COUNT(phba, ulp_num) *
2612 sizeof(struct async_pdu_handle);
2613
2614 mem_descr_index = (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0 +
2615 (ulp_num * MEM_DESCR_OFFSET));
2616 phba->mem_req[mem_descr_index] =
2617 sizeof(struct hwi_async_pdu_context) +
2618 (BEISCSI_GET_CID_COUNT(phba, ulp_num) *
2619 sizeof(struct hwi_async_entry));
2620 }
2621 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302622}
2623
2624static int beiscsi_alloc_mem(struct beiscsi_hba *phba)
2625{
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302626 dma_addr_t bus_add;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002627 struct hwi_controller *phwi_ctrlr;
2628 struct be_mem_descriptor *mem_descr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302629 struct mem_array *mem_arr, *mem_arr_orig;
2630 unsigned int i, j, alloc_size, curr_alloc_size;
2631
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002632 phba->phwi_ctrlr = kzalloc(phba->params.hwi_ws_sz, GFP_KERNEL);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302633 if (!phba->phwi_ctrlr)
2634 return -ENOMEM;
2635
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002636 /* Allocate memory for wrb_context */
2637 phwi_ctrlr = phba->phwi_ctrlr;
2638 phwi_ctrlr->wrb_context = kzalloc(sizeof(struct hwi_wrb_context) *
2639 phba->params.cxns_per_ctrl,
2640 GFP_KERNEL);
2641 if (!phwi_ctrlr->wrb_context)
2642 return -ENOMEM;
2643
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302644 phba->init_mem = kcalloc(SE_MEM_MAX, sizeof(*mem_descr),
2645 GFP_KERNEL);
2646 if (!phba->init_mem) {
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002647 kfree(phwi_ctrlr->wrb_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302648 kfree(phba->phwi_ctrlr);
2649 return -ENOMEM;
2650 }
2651
2652 mem_arr_orig = kmalloc(sizeof(*mem_arr_orig) * BEISCSI_MAX_FRAGS_INIT,
2653 GFP_KERNEL);
2654 if (!mem_arr_orig) {
2655 kfree(phba->init_mem);
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002656 kfree(phwi_ctrlr->wrb_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302657 kfree(phba->phwi_ctrlr);
2658 return -ENOMEM;
2659 }
2660
2661 mem_descr = phba->init_mem;
2662 for (i = 0; i < SE_MEM_MAX; i++) {
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002663 if (!phba->mem_req[i]) {
2664 mem_descr->mem_array = NULL;
2665 mem_descr++;
2666 continue;
2667 }
2668
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302669 j = 0;
2670 mem_arr = mem_arr_orig;
2671 alloc_size = phba->mem_req[i];
2672 memset(mem_arr, 0, sizeof(struct mem_array) *
2673 BEISCSI_MAX_FRAGS_INIT);
2674 curr_alloc_size = min(be_max_phys_size * 1024, alloc_size);
2675 do {
2676 mem_arr->virtual_address = pci_alloc_consistent(
2677 phba->pcidev,
2678 curr_alloc_size,
2679 &bus_add);
2680 if (!mem_arr->virtual_address) {
2681 if (curr_alloc_size <= BE_MIN_MEM_SIZE)
2682 goto free_mem;
2683 if (curr_alloc_size -
2684 rounddown_pow_of_two(curr_alloc_size))
2685 curr_alloc_size = rounddown_pow_of_two
2686 (curr_alloc_size);
2687 else
2688 curr_alloc_size = curr_alloc_size / 2;
2689 } else {
2690 mem_arr->bus_address.u.
2691 a64.address = (__u64) bus_add;
2692 mem_arr->size = curr_alloc_size;
2693 alloc_size -= curr_alloc_size;
2694 curr_alloc_size = min(be_max_phys_size *
2695 1024, alloc_size);
2696 j++;
2697 mem_arr++;
2698 }
2699 } while (alloc_size);
2700 mem_descr->num_elements = j;
2701 mem_descr->size_in_bytes = phba->mem_req[i];
2702 mem_descr->mem_array = kmalloc(sizeof(*mem_arr) * j,
2703 GFP_KERNEL);
2704 if (!mem_descr->mem_array)
2705 goto free_mem;
2706
2707 memcpy(mem_descr->mem_array, mem_arr_orig,
2708 sizeof(struct mem_array) * j);
2709 mem_descr++;
2710 }
2711 kfree(mem_arr_orig);
2712 return 0;
2713free_mem:
2714 mem_descr->num_elements = j;
2715 while ((i) || (j)) {
2716 for (j = mem_descr->num_elements; j > 0; j--) {
2717 pci_free_consistent(phba->pcidev,
2718 mem_descr->mem_array[j - 1].size,
2719 mem_descr->mem_array[j - 1].
2720 virtual_address,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302721 (unsigned long)mem_descr->
2722 mem_array[j - 1].
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302723 bus_address.u.a64.address);
2724 }
2725 if (i) {
2726 i--;
2727 kfree(mem_descr->mem_array);
2728 mem_descr--;
2729 }
2730 }
2731 kfree(mem_arr_orig);
2732 kfree(phba->init_mem);
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002733 kfree(phba->phwi_ctrlr->wrb_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302734 kfree(phba->phwi_ctrlr);
2735 return -ENOMEM;
2736}
2737
2738static int beiscsi_get_memory(struct beiscsi_hba *phba)
2739{
2740 beiscsi_find_mem_req(phba);
2741 return beiscsi_alloc_mem(phba);
2742}
2743
2744static void iscsi_init_global_templates(struct beiscsi_hba *phba)
2745{
2746 struct pdu_data_out *pdata_out;
2747 struct pdu_nop_out *pnop_out;
2748 struct be_mem_descriptor *mem_descr;
2749
2750 mem_descr = phba->init_mem;
2751 mem_descr += ISCSI_MEM_GLOBAL_HEADER;
2752 pdata_out =
2753 (struct pdu_data_out *)mem_descr->mem_array[0].virtual_address;
2754 memset(pdata_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
2755
2756 AMAP_SET_BITS(struct amap_pdu_data_out, opcode, pdata_out,
2757 IIOC_SCSI_DATA);
2758
2759 pnop_out =
2760 (struct pdu_nop_out *)((unsigned char *)mem_descr->mem_array[0].
2761 virtual_address + BE_ISCSI_PDU_HEADER_SIZE);
2762
2763 memset(pnop_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
2764 AMAP_SET_BITS(struct amap_pdu_nop_out, ttt, pnop_out, 0xFFFFFFFF);
2765 AMAP_SET_BITS(struct amap_pdu_nop_out, f_bit, pnop_out, 1);
2766 AMAP_SET_BITS(struct amap_pdu_nop_out, i_bit, pnop_out, 0);
2767}
2768
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002769static int beiscsi_init_wrb_handle(struct beiscsi_hba *phba)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302770{
2771 struct be_mem_descriptor *mem_descr_wrbh, *mem_descr_wrb;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002772 struct hwi_context_memory *phwi_ctxt;
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002773 struct wrb_handle *pwrb_handle = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302774 struct hwi_controller *phwi_ctrlr;
2775 struct hwi_wrb_context *pwrb_context;
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002776 struct iscsi_wrb *pwrb = NULL;
2777 unsigned int num_cxn_wrbh = 0;
2778 unsigned int num_cxn_wrb = 0, j, idx = 0, index;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302779
2780 mem_descr_wrbh = phba->init_mem;
2781 mem_descr_wrbh += HWI_MEM_WRBH;
2782
2783 mem_descr_wrb = phba->init_mem;
2784 mem_descr_wrb += HWI_MEM_WRB;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302785 phwi_ctrlr = phba->phwi_ctrlr;
2786
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002787 /* Allocate memory for WRBQ */
2788 phwi_ctxt = phwi_ctrlr->phwi_ctxt;
2789 phwi_ctxt->be_wrbq = kzalloc(sizeof(struct be_queue_info) *
Jayamohan Kallickal843ae752013-09-28 15:35:44 -07002790 phba->params.cxns_per_ctrl,
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002791 GFP_KERNEL);
2792 if (!phwi_ctxt->be_wrbq) {
2793 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2794 "BM_%d : WRBQ Mem Alloc Failed\n");
2795 return -ENOMEM;
2796 }
2797
2798 for (index = 0; index < phba->params.cxns_per_ctrl; index++) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302799 pwrb_context = &phwi_ctrlr->wrb_context[index];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302800 pwrb_context->pwrb_handle_base =
2801 kzalloc(sizeof(struct wrb_handle *) *
2802 phba->params.wrbs_per_cxn, GFP_KERNEL);
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002803 if (!pwrb_context->pwrb_handle_base) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05302804 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2805 "BM_%d : Mem Alloc Failed. Failing to load\n");
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002806 goto init_wrb_hndl_failed;
2807 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302808 pwrb_context->pwrb_handle_basestd =
2809 kzalloc(sizeof(struct wrb_handle *) *
2810 phba->params.wrbs_per_cxn, GFP_KERNEL);
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002811 if (!pwrb_context->pwrb_handle_basestd) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05302812 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2813 "BM_%d : Mem Alloc Failed. Failing to load\n");
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002814 goto init_wrb_hndl_failed;
2815 }
2816 if (!num_cxn_wrbh) {
2817 pwrb_handle =
2818 mem_descr_wrbh->mem_array[idx].virtual_address;
2819 num_cxn_wrbh = ((mem_descr_wrbh->mem_array[idx].size) /
2820 ((sizeof(struct wrb_handle)) *
2821 phba->params.wrbs_per_cxn));
2822 idx++;
2823 }
2824 pwrb_context->alloc_index = 0;
2825 pwrb_context->wrb_handles_available = 0;
2826 pwrb_context->free_index = 0;
2827
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302828 if (num_cxn_wrbh) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302829 for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
2830 pwrb_context->pwrb_handle_base[j] = pwrb_handle;
2831 pwrb_context->pwrb_handle_basestd[j] =
2832 pwrb_handle;
2833 pwrb_context->wrb_handles_available++;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302834 pwrb_handle->wrb_index = j;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302835 pwrb_handle++;
2836 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302837 num_cxn_wrbh--;
2838 }
2839 }
2840 idx = 0;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002841 for (index = 0; index < phba->params.cxns_per_ctrl; index++) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302842 pwrb_context = &phwi_ctrlr->wrb_context[index];
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002843 if (!num_cxn_wrb) {
2844 pwrb = mem_descr_wrb->mem_array[idx].virtual_address;
2845 num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) /
2846 ((sizeof(struct iscsi_wrb) *
2847 phba->params.wrbs_per_cxn));
2848 idx++;
2849 }
2850
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302851 if (num_cxn_wrb) {
2852 for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
2853 pwrb_handle = pwrb_context->pwrb_handle_base[j];
2854 pwrb_handle->pwrb = pwrb;
2855 pwrb++;
2856 }
2857 num_cxn_wrb--;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302858 }
2859 }
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002860 return 0;
2861init_wrb_hndl_failed:
2862 for (j = index; j > 0; j--) {
2863 pwrb_context = &phwi_ctrlr->wrb_context[j];
2864 kfree(pwrb_context->pwrb_handle_base);
2865 kfree(pwrb_context->pwrb_handle_basestd);
2866 }
2867 return -ENOMEM;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302868}
2869
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002870static int hwi_init_async_pdu_ctx(struct beiscsi_hba *phba)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302871{
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002872 uint8_t ulp_num;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302873 struct hwi_controller *phwi_ctrlr;
2874 struct hba_parameters *p = &phba->params;
2875 struct hwi_async_pdu_context *pasync_ctx;
2876 struct async_pdu_handle *pasync_header_h, *pasync_data_h;
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05002877 unsigned int index, idx, num_per_mem, num_async_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302878 struct be_mem_descriptor *mem_descr;
2879
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002880 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
2881 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302882
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002883 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2884 mem_descr += (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0 +
2885 (ulp_num * MEM_DESCR_OFFSET));
2886
2887 phwi_ctrlr = phba->phwi_ctrlr;
2888 phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num] =
2889 (struct hwi_async_pdu_context *)
2890 mem_descr->mem_array[0].virtual_address;
2891
2892 pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num];
2893 memset(pasync_ctx, 0, sizeof(*pasync_ctx));
2894
2895 pasync_ctx->async_entry =
2896 (struct hwi_async_entry *)
2897 ((long unsigned int)pasync_ctx +
2898 sizeof(struct hwi_async_pdu_context));
2899
2900 pasync_ctx->num_entries = BEISCSI_GET_CID_COUNT(phba,
2901 ulp_num);
2902 pasync_ctx->buffer_size = p->defpdu_hdr_sz;
2903
2904 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2905 mem_descr += HWI_MEM_ASYNC_HEADER_BUF_ULP0 +
2906 (ulp_num * MEM_DESCR_OFFSET);
2907 if (mem_descr->mem_array[0].virtual_address) {
2908 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2909 "BM_%d : hwi_init_async_pdu_ctx"
2910 " HWI_MEM_ASYNC_HEADER_BUF_ULP%d va=%p\n",
2911 ulp_num,
2912 mem_descr->mem_array[0].
2913 virtual_address);
2914 } else
2915 beiscsi_log(phba, KERN_WARNING,
2916 BEISCSI_LOG_INIT,
2917 "BM_%d : No Virtual address for ULP : %d\n",
2918 ulp_num);
2919
2920 pasync_ctx->async_header.va_base =
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302921 mem_descr->mem_array[0].virtual_address;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302922
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002923 pasync_ctx->async_header.pa_base.u.a64.address =
2924 mem_descr->mem_array[0].
2925 bus_address.u.a64.address;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002926
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002927 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2928 mem_descr += HWI_MEM_ASYNC_HEADER_RING_ULP0 +
2929 (ulp_num * MEM_DESCR_OFFSET);
2930 if (mem_descr->mem_array[0].virtual_address) {
2931 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2932 "BM_%d : hwi_init_async_pdu_ctx"
2933 " HWI_MEM_ASYNC_HEADER_RING_ULP%d va=%p\n",
2934 ulp_num,
2935 mem_descr->mem_array[0].
2936 virtual_address);
2937 } else
2938 beiscsi_log(phba, KERN_WARNING,
2939 BEISCSI_LOG_INIT,
2940 "BM_%d : No Virtual address for ULP : %d\n",
2941 ulp_num);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302942
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002943 pasync_ctx->async_header.ring_base =
2944 mem_descr->mem_array[0].virtual_address;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302945
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002946 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2947 mem_descr += HWI_MEM_ASYNC_HEADER_HANDLE_ULP0 +
2948 (ulp_num * MEM_DESCR_OFFSET);
2949 if (mem_descr->mem_array[0].virtual_address) {
2950 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2951 "BM_%d : hwi_init_async_pdu_ctx"
2952 " HWI_MEM_ASYNC_HEADER_HANDLE_ULP%d va=%p\n",
2953 ulp_num,
2954 mem_descr->mem_array[0].
2955 virtual_address);
2956 } else
2957 beiscsi_log(phba, KERN_WARNING,
2958 BEISCSI_LOG_INIT,
2959 "BM_%d : No Virtual address for ULP : %d\n",
2960 ulp_num);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302961
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002962 pasync_ctx->async_header.handle_base =
2963 mem_descr->mem_array[0].virtual_address;
2964 pasync_ctx->async_header.writables = 0;
2965 INIT_LIST_HEAD(&pasync_ctx->async_header.free_list);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302966
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002967 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2968 mem_descr += HWI_MEM_ASYNC_DATA_RING_ULP0 +
2969 (ulp_num * MEM_DESCR_OFFSET);
2970 if (mem_descr->mem_array[0].virtual_address) {
2971 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2972 "BM_%d : hwi_init_async_pdu_ctx"
2973 " HWI_MEM_ASYNC_DATA_RING_ULP%d va=%p\n",
2974 ulp_num,
2975 mem_descr->mem_array[0].
2976 virtual_address);
2977 } else
2978 beiscsi_log(phba, KERN_WARNING,
2979 BEISCSI_LOG_INIT,
2980 "BM_%d : No Virtual address for ULP : %d\n",
2981 ulp_num);
John Soni Jose99bc5d52012-08-20 23:00:18 +05302982
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002983 pasync_ctx->async_data.ring_base =
2984 mem_descr->mem_array[0].virtual_address;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302985
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002986 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2987 mem_descr += HWI_MEM_ASYNC_DATA_HANDLE_ULP0 +
2988 (ulp_num * MEM_DESCR_OFFSET);
2989 if (!mem_descr->mem_array[0].virtual_address)
2990 beiscsi_log(phba, KERN_WARNING,
2991 BEISCSI_LOG_INIT,
2992 "BM_%d : No Virtual address for ULP : %d\n",
2993 ulp_num);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302994
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002995 pasync_ctx->async_data.handle_base =
2996 mem_descr->mem_array[0].virtual_address;
2997 pasync_ctx->async_data.writables = 0;
2998 INIT_LIST_HEAD(&pasync_ctx->async_data.free_list);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302999
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003000 pasync_header_h =
3001 (struct async_pdu_handle *)
3002 pasync_ctx->async_header.handle_base;
3003 pasync_data_h =
3004 (struct async_pdu_handle *)
3005 pasync_ctx->async_data.handle_base;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303006
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003007 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
3008 mem_descr += HWI_MEM_ASYNC_DATA_BUF_ULP0 +
3009 (ulp_num * MEM_DESCR_OFFSET);
3010 if (mem_descr->mem_array[0].virtual_address) {
3011 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3012 "BM_%d : hwi_init_async_pdu_ctx"
3013 " HWI_MEM_ASYNC_DATA_BUF_ULP%d va=%p\n",
3014 ulp_num,
3015 mem_descr->mem_array[0].
3016 virtual_address);
3017 } else
3018 beiscsi_log(phba, KERN_WARNING,
3019 BEISCSI_LOG_INIT,
3020 "BM_%d : No Virtual address for ULP : %d\n",
3021 ulp_num);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303022
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003023 idx = 0;
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05003024 pasync_ctx->async_data.va_base =
3025 mem_descr->mem_array[idx].virtual_address;
3026 pasync_ctx->async_data.pa_base.u.a64.address =
3027 mem_descr->mem_array[idx].
3028 bus_address.u.a64.address;
3029
3030 num_async_data = ((mem_descr->mem_array[idx].size) /
3031 phba->params.defpdu_data_sz);
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003032 num_per_mem = 0;
3033
3034 for (index = 0; index < BEISCSI_GET_CID_COUNT
3035 (phba, ulp_num); index++) {
3036 pasync_header_h->cri = -1;
3037 pasync_header_h->index = (char)index;
3038 INIT_LIST_HEAD(&pasync_header_h->link);
3039 pasync_header_h->pbuffer =
3040 (void *)((unsigned long)
3041 (pasync_ctx->
3042 async_header.va_base) +
3043 (p->defpdu_hdr_sz * index));
3044
3045 pasync_header_h->pa.u.a64.address =
3046 pasync_ctx->async_header.pa_base.u.a64.
3047 address + (p->defpdu_hdr_sz * index);
3048
3049 list_add_tail(&pasync_header_h->link,
3050 &pasync_ctx->async_header.
3051 free_list);
3052 pasync_header_h++;
3053 pasync_ctx->async_header.free_entries++;
3054 pasync_ctx->async_header.writables++;
3055
3056 INIT_LIST_HEAD(&pasync_ctx->async_entry[index].
3057 wait_queue.list);
3058 INIT_LIST_HEAD(&pasync_ctx->async_entry[index].
3059 header_busy_list);
3060 pasync_data_h->cri = -1;
3061 pasync_data_h->index = (char)index;
3062 INIT_LIST_HEAD(&pasync_data_h->link);
3063
3064 if (!num_async_data) {
3065 num_per_mem = 0;
3066 idx++;
3067 pasync_ctx->async_data.va_base =
3068 mem_descr->mem_array[idx].
3069 virtual_address;
3070 pasync_ctx->async_data.pa_base.u.
3071 a64.address =
3072 mem_descr->mem_array[idx].
3073 bus_address.u.a64.address;
3074 num_async_data =
3075 ((mem_descr->mem_array[idx].
3076 size) /
3077 phba->params.defpdu_data_sz);
3078 }
3079 pasync_data_h->pbuffer =
3080 (void *)((unsigned long)
3081 (pasync_ctx->async_data.va_base) +
3082 (p->defpdu_data_sz * num_per_mem));
3083
3084 pasync_data_h->pa.u.a64.address =
3085 pasync_ctx->async_data.pa_base.u.a64.
3086 address + (p->defpdu_data_sz *
3087 num_per_mem);
3088 num_per_mem++;
3089 num_async_data--;
3090
3091 list_add_tail(&pasync_data_h->link,
3092 &pasync_ctx->async_data.
3093 free_list);
3094 pasync_data_h++;
3095 pasync_ctx->async_data.free_entries++;
3096 pasync_ctx->async_data.writables++;
3097
3098 INIT_LIST_HEAD(&pasync_ctx->async_entry[index].
3099 data_busy_list);
3100 }
3101
3102 pasync_ctx->async_header.host_write_ptr = 0;
3103 pasync_ctx->async_header.ep_read_ptr = -1;
3104 pasync_ctx->async_data.host_write_ptr = 0;
3105 pasync_ctx->async_data.ep_read_ptr = -1;
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05003106 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303107 }
3108
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003109 return 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303110}
3111
3112static int
3113be_sgl_create_contiguous(void *virtual_address,
3114 u64 physical_address, u32 length,
3115 struct be_dma_mem *sgl)
3116{
3117 WARN_ON(!virtual_address);
3118 WARN_ON(!physical_address);
3119 WARN_ON(!length > 0);
3120 WARN_ON(!sgl);
3121
3122 sgl->va = virtual_address;
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05303123 sgl->dma = (unsigned long)physical_address;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303124 sgl->size = length;
3125
3126 return 0;
3127}
3128
3129static void be_sgl_destroy_contiguous(struct be_dma_mem *sgl)
3130{
3131 memset(sgl, 0, sizeof(*sgl));
3132}
3133
3134static void
3135hwi_build_be_sgl_arr(struct beiscsi_hba *phba,
3136 struct mem_array *pmem, struct be_dma_mem *sgl)
3137{
3138 if (sgl->va)
3139 be_sgl_destroy_contiguous(sgl);
3140
3141 be_sgl_create_contiguous(pmem->virtual_address,
3142 pmem->bus_address.u.a64.address,
3143 pmem->size, sgl);
3144}
3145
3146static void
3147hwi_build_be_sgl_by_offset(struct beiscsi_hba *phba,
3148 struct mem_array *pmem, struct be_dma_mem *sgl)
3149{
3150 if (sgl->va)
3151 be_sgl_destroy_contiguous(sgl);
3152
3153 be_sgl_create_contiguous((unsigned char *)pmem->virtual_address,
3154 pmem->bus_address.u.a64.address,
3155 pmem->size, sgl);
3156}
3157
3158static int be_fill_queue(struct be_queue_info *q,
3159 u16 len, u16 entry_size, void *vaddress)
3160{
3161 struct be_dma_mem *mem = &q->dma_mem;
3162
3163 memset(q, 0, sizeof(*q));
3164 q->len = len;
3165 q->entry_size = entry_size;
3166 mem->size = len * entry_size;
3167 mem->va = vaddress;
3168 if (!mem->va)
3169 return -ENOMEM;
3170 memset(mem->va, 0, mem->size);
3171 return 0;
3172}
3173
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303174static int beiscsi_create_eqs(struct beiscsi_hba *phba,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303175 struct hwi_context_memory *phwi_context)
3176{
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303177 unsigned int i, num_eq_pages;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303178 int ret = 0, eq_for_mcc;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303179 struct be_queue_info *eq;
3180 struct be_dma_mem *mem;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303181 void *eq_vaddress;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303182 dma_addr_t paddr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303183
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303184 num_eq_pages = PAGES_REQUIRED(phba->params.num_eq_entries * \
3185 sizeof(struct be_eq_entry));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303186
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303187 if (phba->msix_enabled)
3188 eq_for_mcc = 1;
3189 else
3190 eq_for_mcc = 0;
3191 for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
3192 eq = &phwi_context->be_eq[i].q;
3193 mem = &eq->dma_mem;
3194 phwi_context->be_eq[i].phba = phba;
3195 eq_vaddress = pci_alloc_consistent(phba->pcidev,
3196 num_eq_pages * PAGE_SIZE,
3197 &paddr);
3198 if (!eq_vaddress)
3199 goto create_eq_error;
3200
3201 mem->va = eq_vaddress;
3202 ret = be_fill_queue(eq, phba->params.num_eq_entries,
3203 sizeof(struct be_eq_entry), eq_vaddress);
3204 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303205 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3206 "BM_%d : be_fill_queue Failed for EQ\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303207 goto create_eq_error;
3208 }
3209
3210 mem->dma = paddr;
3211 ret = beiscsi_cmd_eq_create(&phba->ctrl, eq,
3212 phwi_context->cur_eqd);
3213 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303214 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3215 "BM_%d : beiscsi_cmd_eq_create"
3216 "Failed for EQ\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303217 goto create_eq_error;
3218 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05303219
3220 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3221 "BM_%d : eqid = %d\n",
3222 phwi_context->be_eq[i].q.id);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303223 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303224 return 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303225create_eq_error:
John Soni Jose107dfcb2012-10-20 04:42:13 +05303226 for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303227 eq = &phwi_context->be_eq[i].q;
3228 mem = &eq->dma_mem;
3229 if (mem->va)
3230 pci_free_consistent(phba->pcidev, num_eq_pages
3231 * PAGE_SIZE,
3232 mem->va, mem->dma);
3233 }
3234 return ret;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303235}
3236
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303237static int beiscsi_create_cqs(struct beiscsi_hba *phba,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303238 struct hwi_context_memory *phwi_context)
3239{
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303240 unsigned int i, num_cq_pages;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303241 int ret = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303242 struct be_queue_info *cq, *eq;
3243 struct be_dma_mem *mem;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303244 struct be_eq_obj *pbe_eq;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303245 void *cq_vaddress;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303246 dma_addr_t paddr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303247
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303248 num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
3249 sizeof(struct sol_cqe));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303250
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303251 for (i = 0; i < phba->num_cpus; i++) {
3252 cq = &phwi_context->be_cq[i];
3253 eq = &phwi_context->be_eq[i].q;
3254 pbe_eq = &phwi_context->be_eq[i];
3255 pbe_eq->cq = cq;
3256 pbe_eq->phba = phba;
3257 mem = &cq->dma_mem;
3258 cq_vaddress = pci_alloc_consistent(phba->pcidev,
3259 num_cq_pages * PAGE_SIZE,
3260 &paddr);
3261 if (!cq_vaddress)
3262 goto create_cq_error;
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05303263 ret = be_fill_queue(cq, phba->params.num_cq_entries,
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303264 sizeof(struct sol_cqe), cq_vaddress);
3265 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303266 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3267 "BM_%d : be_fill_queue Failed "
3268 "for ISCSI CQ\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303269 goto create_cq_error;
3270 }
3271
3272 mem->dma = paddr;
3273 ret = beiscsi_cmd_cq_create(&phba->ctrl, cq, eq, false,
3274 false, 0);
3275 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303276 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3277 "BM_%d : beiscsi_cmd_eq_create"
3278 "Failed for ISCSI CQ\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303279 goto create_cq_error;
3280 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05303281 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3282 "BM_%d : iscsi cq_id is %d for eq_id %d\n"
3283 "iSCSI CQ CREATED\n", cq->id, eq->id);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303284 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303285 return 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303286
3287create_cq_error:
3288 for (i = 0; i < phba->num_cpus; i++) {
3289 cq = &phwi_context->be_cq[i];
3290 mem = &cq->dma_mem;
3291 if (mem->va)
3292 pci_free_consistent(phba->pcidev, num_cq_pages
3293 * PAGE_SIZE,
3294 mem->va, mem->dma);
3295 }
3296 return ret;
3297
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303298}
3299
3300static int
3301beiscsi_create_def_hdr(struct beiscsi_hba *phba,
3302 struct hwi_context_memory *phwi_context,
3303 struct hwi_controller *phwi_ctrlr,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003304 unsigned int def_pdu_ring_sz, uint8_t ulp_num)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303305{
3306 unsigned int idx;
3307 int ret;
3308 struct be_queue_info *dq, *cq;
3309 struct be_dma_mem *mem;
3310 struct be_mem_descriptor *mem_descr;
3311 void *dq_vaddress;
3312
3313 idx = 0;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003314 dq = &phwi_context->be_def_hdrq[ulp_num];
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303315 cq = &phwi_context->be_cq[0];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303316 mem = &dq->dma_mem;
3317 mem_descr = phba->init_mem;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003318 mem_descr += HWI_MEM_ASYNC_HEADER_RING_ULP0 +
3319 (ulp_num * MEM_DESCR_OFFSET);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303320 dq_vaddress = mem_descr->mem_array[idx].virtual_address;
3321 ret = be_fill_queue(dq, mem_descr->mem_array[0].size /
3322 sizeof(struct phys_addr),
3323 sizeof(struct phys_addr), dq_vaddress);
3324 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303325 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003326 "BM_%d : be_fill_queue Failed for DEF PDU HDR on ULP : %d\n",
3327 ulp_num);
3328
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303329 return ret;
3330 }
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05303331 mem->dma = (unsigned long)mem_descr->mem_array[idx].
3332 bus_address.u.a64.address;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303333 ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dq,
3334 def_pdu_ring_sz,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003335 phba->params.defpdu_hdr_sz,
3336 BEISCSI_DEFQ_HDR, ulp_num);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303337 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303338 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003339 "BM_%d : be_cmd_create_default_pdu_queue Failed DEFHDR on ULP : %d\n",
3340 ulp_num);
3341
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303342 return ret;
3343 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05303344
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003345 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3346 "BM_%d : iscsi hdr def pdu id for ULP : %d is %d\n",
3347 ulp_num,
3348 phwi_context->be_def_hdrq[ulp_num].id);
3349 hwi_post_async_buffers(phba, BEISCSI_DEFQ_HDR, ulp_num);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303350 return 0;
3351}
3352
3353static int
3354beiscsi_create_def_data(struct beiscsi_hba *phba,
3355 struct hwi_context_memory *phwi_context,
3356 struct hwi_controller *phwi_ctrlr,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003357 unsigned int def_pdu_ring_sz, uint8_t ulp_num)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303358{
3359 unsigned int idx;
3360 int ret;
3361 struct be_queue_info *dataq, *cq;
3362 struct be_dma_mem *mem;
3363 struct be_mem_descriptor *mem_descr;
3364 void *dq_vaddress;
3365
3366 idx = 0;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003367 dataq = &phwi_context->be_def_dataq[ulp_num];
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303368 cq = &phwi_context->be_cq[0];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303369 mem = &dataq->dma_mem;
3370 mem_descr = phba->init_mem;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003371 mem_descr += HWI_MEM_ASYNC_DATA_RING_ULP0 +
3372 (ulp_num * MEM_DESCR_OFFSET);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303373 dq_vaddress = mem_descr->mem_array[idx].virtual_address;
3374 ret = be_fill_queue(dataq, mem_descr->mem_array[0].size /
3375 sizeof(struct phys_addr),
3376 sizeof(struct phys_addr), dq_vaddress);
3377 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303378 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003379 "BM_%d : be_fill_queue Failed for DEF PDU "
3380 "DATA on ULP : %d\n",
3381 ulp_num);
3382
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303383 return ret;
3384 }
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05303385 mem->dma = (unsigned long)mem_descr->mem_array[idx].
3386 bus_address.u.a64.address;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303387 ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dataq,
3388 def_pdu_ring_sz,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003389 phba->params.defpdu_data_sz,
3390 BEISCSI_DEFQ_DATA, ulp_num);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303391 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303392 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3393 "BM_%d be_cmd_create_default_pdu_queue"
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003394 " Failed for DEF PDU DATA on ULP : %d\n",
3395 ulp_num);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303396 return ret;
3397 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05303398
John Soni Jose99bc5d52012-08-20 23:00:18 +05303399 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003400 "BM_%d : iscsi def data id on ULP : %d is %d\n",
3401 ulp_num,
3402 phwi_context->be_def_dataq[ulp_num].id);
3403
3404 hwi_post_async_buffers(phba, BEISCSI_DEFQ_DATA, ulp_num);
3405 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3406 "BM_%d : DEFAULT PDU DATA RING CREATED"
3407 "on ULP : %d\n", ulp_num);
John Soni Jose99bc5d52012-08-20 23:00:18 +05303408
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303409 return 0;
3410}
3411
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07003412
3413static int
3414beiscsi_post_template_hdr(struct beiscsi_hba *phba)
3415{
3416 struct be_mem_descriptor *mem_descr;
3417 struct mem_array *pm_arr;
3418 struct be_dma_mem sgl;
Jayamohan Kallickala129d922013-09-28 15:35:46 -07003419 int status, ulp_num;
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07003420
Jayamohan Kallickala129d922013-09-28 15:35:46 -07003421 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
3422 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
3423 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
3424 mem_descr += HWI_MEM_TEMPLATE_HDR_ULP0 +
3425 (ulp_num * MEM_DESCR_OFFSET);
3426 pm_arr = mem_descr->mem_array;
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07003427
Jayamohan Kallickala129d922013-09-28 15:35:46 -07003428 hwi_build_be_sgl_arr(phba, pm_arr, &sgl);
3429 status = be_cmd_iscsi_post_template_hdr(
3430 &phba->ctrl, &sgl);
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07003431
Jayamohan Kallickala129d922013-09-28 15:35:46 -07003432 if (status != 0) {
3433 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3434 "BM_%d : Post Template HDR Failed for"
3435 "ULP_%d\n", ulp_num);
3436 return status;
3437 }
3438
3439 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3440 "BM_%d : Template HDR Pages Posted for"
3441 "ULP_%d\n", ulp_num);
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07003442 }
3443 }
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07003444 return 0;
3445}
3446
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303447static int
3448beiscsi_post_pages(struct beiscsi_hba *phba)
3449{
3450 struct be_mem_descriptor *mem_descr;
3451 struct mem_array *pm_arr;
3452 unsigned int page_offset, i;
3453 struct be_dma_mem sgl;
Jayamohan Kallickal843ae752013-09-28 15:35:44 -07003454 int status, ulp_num = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303455
3456 mem_descr = phba->init_mem;
3457 mem_descr += HWI_MEM_SGE;
3458 pm_arr = mem_descr->mem_array;
3459
Jayamohan Kallickal90622db2013-09-28 15:35:47 -07003460 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
3461 if (test_bit(ulp_num, &phba->fw_config.ulp_supported))
3462 break;
3463
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303464 page_offset = (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io *
Jayamohan Kallickal843ae752013-09-28 15:35:44 -07003465 phba->fw_config.iscsi_icd_start[ulp_num]) / PAGE_SIZE;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303466 for (i = 0; i < mem_descr->num_elements; i++) {
3467 hwi_build_be_sgl_arr(phba, pm_arr, &sgl);
3468 status = be_cmd_iscsi_post_sgl_pages(&phba->ctrl, &sgl,
3469 page_offset,
3470 (pm_arr->size / PAGE_SIZE));
3471 page_offset += pm_arr->size / PAGE_SIZE;
3472 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303473 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3474 "BM_%d : post sgl failed.\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303475 return status;
3476 }
3477 pm_arr++;
3478 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05303479 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3480 "BM_%d : POSTED PAGES\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303481 return 0;
3482}
3483
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303484static void be_queue_free(struct beiscsi_hba *phba, struct be_queue_info *q)
3485{
3486 struct be_dma_mem *mem = &q->dma_mem;
Jayamohan Kallickalc8b25592012-04-03 23:41:42 -05003487 if (mem->va) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303488 pci_free_consistent(phba->pcidev, mem->size,
3489 mem->va, mem->dma);
Jayamohan Kallickalc8b25592012-04-03 23:41:42 -05003490 mem->va = NULL;
3491 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303492}
3493
3494static int be_queue_alloc(struct beiscsi_hba *phba, struct be_queue_info *q,
3495 u16 len, u16 entry_size)
3496{
3497 struct be_dma_mem *mem = &q->dma_mem;
3498
3499 memset(q, 0, sizeof(*q));
3500 q->len = len;
3501 q->entry_size = entry_size;
3502 mem->size = len * entry_size;
3503 mem->va = pci_alloc_consistent(phba->pcidev, mem->size, &mem->dma);
3504 if (!mem->va)
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +05303505 return -ENOMEM;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303506 memset(mem->va, 0, mem->size);
3507 return 0;
3508}
3509
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303510static int
3511beiscsi_create_wrb_rings(struct beiscsi_hba *phba,
3512 struct hwi_context_memory *phwi_context,
3513 struct hwi_controller *phwi_ctrlr)
3514{
3515 unsigned int wrb_mem_index, offset, size, num_wrb_rings;
3516 u64 pa_addr_lo;
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07003517 unsigned int idx, num, i, ulp_num;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303518 struct mem_array *pwrb_arr;
3519 void *wrb_vaddr;
3520 struct be_dma_mem sgl;
3521 struct be_mem_descriptor *mem_descr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003522 struct hwi_wrb_context *pwrb_context;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303523 int status;
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07003524 uint8_t ulp_count = 0, ulp_base_num = 0;
3525 uint16_t cid_count_ulp[BEISCSI_ULP_COUNT] = { 0 };
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303526
3527 idx = 0;
3528 mem_descr = phba->init_mem;
3529 mem_descr += HWI_MEM_WRB;
3530 pwrb_arr = kmalloc(sizeof(*pwrb_arr) * phba->params.cxns_per_ctrl,
3531 GFP_KERNEL);
3532 if (!pwrb_arr) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303533 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3534 "BM_%d : Memory alloc failed in create wrb ring.\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303535 return -ENOMEM;
3536 }
3537 wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
3538 pa_addr_lo = mem_descr->mem_array[idx].bus_address.u.a64.address;
3539 num_wrb_rings = mem_descr->mem_array[idx].size /
3540 (phba->params.wrbs_per_cxn * sizeof(struct iscsi_wrb));
3541
3542 for (num = 0; num < phba->params.cxns_per_ctrl; num++) {
3543 if (num_wrb_rings) {
3544 pwrb_arr[num].virtual_address = wrb_vaddr;
3545 pwrb_arr[num].bus_address.u.a64.address = pa_addr_lo;
3546 pwrb_arr[num].size = phba->params.wrbs_per_cxn *
3547 sizeof(struct iscsi_wrb);
3548 wrb_vaddr += pwrb_arr[num].size;
3549 pa_addr_lo += pwrb_arr[num].size;
3550 num_wrb_rings--;
3551 } else {
3552 idx++;
3553 wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
3554 pa_addr_lo = mem_descr->mem_array[idx].\
3555 bus_address.u.a64.address;
3556 num_wrb_rings = mem_descr->mem_array[idx].size /
3557 (phba->params.wrbs_per_cxn *
3558 sizeof(struct iscsi_wrb));
3559 pwrb_arr[num].virtual_address = wrb_vaddr;
3560 pwrb_arr[num].bus_address.u.a64.address\
3561 = pa_addr_lo;
3562 pwrb_arr[num].size = phba->params.wrbs_per_cxn *
3563 sizeof(struct iscsi_wrb);
3564 wrb_vaddr += pwrb_arr[num].size;
3565 pa_addr_lo += pwrb_arr[num].size;
3566 num_wrb_rings--;
3567 }
3568 }
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07003569
3570 /* Get the ULP Count */
3571 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
3572 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
3573 ulp_count++;
3574 ulp_base_num = ulp_num;
3575 cid_count_ulp[ulp_num] =
3576 BEISCSI_GET_CID_COUNT(phba, ulp_num);
3577 }
3578
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303579 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
3580 wrb_mem_index = 0;
3581 offset = 0;
3582 size = 0;
3583
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07003584 if (ulp_count > 1) {
3585 ulp_base_num = (ulp_base_num + 1) % BEISCSI_ULP_COUNT;
3586
3587 if (!cid_count_ulp[ulp_base_num])
3588 ulp_base_num = (ulp_base_num + 1) %
3589 BEISCSI_ULP_COUNT;
3590
3591 cid_count_ulp[ulp_base_num]--;
3592 }
3593
3594
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303595 hwi_build_be_sgl_by_offset(phba, &pwrb_arr[i], &sgl);
3596 status = be_cmd_wrbq_create(&phba->ctrl, &sgl,
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07003597 &phwi_context->be_wrbq[i],
3598 &phwi_ctrlr->wrb_context[i],
3599 ulp_base_num);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303600 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303601 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3602 "BM_%d : wrbq create failed.");
Dan Carpenter1462b8f2010-06-10 09:52:21 +02003603 kfree(pwrb_arr);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303604 return status;
3605 }
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003606 pwrb_context = &phwi_ctrlr->wrb_context[i];
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003607 BE_SET_CID_TO_CRI(i, pwrb_context->cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303608 }
3609 kfree(pwrb_arr);
3610 return 0;
3611}
3612
3613static void free_wrb_handles(struct beiscsi_hba *phba)
3614{
3615 unsigned int index;
3616 struct hwi_controller *phwi_ctrlr;
3617 struct hwi_wrb_context *pwrb_context;
3618
3619 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003620 for (index = 0; index < phba->params.cxns_per_ctrl; index++) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303621 pwrb_context = &phwi_ctrlr->wrb_context[index];
3622 kfree(pwrb_context->pwrb_handle_base);
3623 kfree(pwrb_context->pwrb_handle_basestd);
3624 }
3625}
3626
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303627static void be_mcc_queues_destroy(struct beiscsi_hba *phba)
3628{
3629 struct be_queue_info *q;
3630 struct be_ctrl_info *ctrl = &phba->ctrl;
3631
3632 q = &phba->ctrl.mcc_obj.q;
3633 if (q->created)
3634 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_MCCQ);
3635 be_queue_free(phba, q);
3636
3637 q = &phba->ctrl.mcc_obj.cq;
3638 if (q->created)
3639 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
3640 be_queue_free(phba, q);
3641}
3642
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303643static void hwi_cleanup(struct beiscsi_hba *phba)
3644{
3645 struct be_queue_info *q;
3646 struct be_ctrl_info *ctrl = &phba->ctrl;
3647 struct hwi_controller *phwi_ctrlr;
3648 struct hwi_context_memory *phwi_context;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003649 struct hwi_async_pdu_context *pasync_ctx;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003650 int i, eq_num, ulp_num;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303651
3652 phwi_ctrlr = phba->phwi_ctrlr;
3653 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07003654
3655 be_cmd_iscsi_remove_template_hdr(ctrl);
3656
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303657 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
3658 q = &phwi_context->be_wrbq[i];
3659 if (q->created)
3660 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_WRBQ);
3661 }
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003662 kfree(phwi_context->be_wrbq);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303663 free_wrb_handles(phba);
3664
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003665 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
3666 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303667
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003668 q = &phwi_context->be_def_hdrq[ulp_num];
3669 if (q->created)
3670 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
3671
3672 q = &phwi_context->be_def_dataq[ulp_num];
3673 if (q->created)
3674 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
3675
3676 pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num];
3677 }
3678 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303679
3680 beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
3681
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303682 for (i = 0; i < (phba->num_cpus); i++) {
3683 q = &phwi_context->be_cq[i];
3684 if (q->created)
3685 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
3686 }
3687 if (phba->msix_enabled)
3688 eq_num = 1;
3689 else
3690 eq_num = 0;
3691 for (i = 0; i < (phba->num_cpus + eq_num); i++) {
3692 q = &phwi_context->be_eq[i].q;
3693 if (q->created)
3694 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_EQ);
3695 }
3696 be_mcc_queues_destroy(phba);
Jayamohan Kallickal0283fbb2013-04-05 20:38:21 -07003697 be_cmd_fw_uninit(ctrl);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303698}
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303699
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303700static int be_mcc_queues_create(struct beiscsi_hba *phba,
3701 struct hwi_context_memory *phwi_context)
3702{
3703 struct be_queue_info *q, *cq;
3704 struct be_ctrl_info *ctrl = &phba->ctrl;
3705
3706 /* Alloc MCC compl queue */
3707 cq = &phba->ctrl.mcc_obj.cq;
3708 if (be_queue_alloc(phba, cq, MCC_CQ_LEN,
3709 sizeof(struct be_mcc_compl)))
3710 goto err;
3711 /* Ask BE to create MCC compl queue; */
3712 if (phba->msix_enabled) {
3713 if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq
3714 [phba->num_cpus].q, false, true, 0))
3715 goto mcc_cq_free;
3716 } else {
3717 if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq[0].q,
3718 false, true, 0))
3719 goto mcc_cq_free;
3720 }
3721
3722 /* Alloc MCC queue */
3723 q = &phba->ctrl.mcc_obj.q;
3724 if (be_queue_alloc(phba, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb)))
3725 goto mcc_cq_destroy;
3726
3727 /* Ask BE to create MCC queue */
Jayamohan Kallickal35e66012009-10-23 11:53:49 +05303728 if (beiscsi_cmd_mccq_create(phba, q, cq))
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303729 goto mcc_q_free;
3730
3731 return 0;
3732
3733mcc_q_free:
3734 be_queue_free(phba, q);
3735mcc_cq_destroy:
3736 beiscsi_cmd_q_destroy(ctrl, cq, QTYPE_CQ);
3737mcc_cq_free:
3738 be_queue_free(phba, cq);
3739err:
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +05303740 return -ENOMEM;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303741}
3742
John Soni Jose107dfcb2012-10-20 04:42:13 +05303743/**
3744 * find_num_cpus()- Get the CPU online count
3745 * @phba: ptr to priv structure
3746 *
3747 * CPU count is used for creating EQ.
3748 **/
3749static void find_num_cpus(struct beiscsi_hba *phba)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303750{
3751 int num_cpus = 0;
3752
3753 num_cpus = num_online_cpus();
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303754
John Soni Jose22abeef2012-10-20 04:43:32 +05303755 switch (phba->generation) {
3756 case BE_GEN2:
3757 case BE_GEN3:
3758 phba->num_cpus = (num_cpus > BEISCSI_MAX_NUM_CPUS) ?
3759 BEISCSI_MAX_NUM_CPUS : num_cpus;
3760 break;
3761 case BE_GEN4:
Jayamohan Kallickal68c26a32013-09-28 15:35:54 -07003762 /*
3763 * If eqid_count == 1 fall back to
3764 * INTX mechanism
3765 **/
3766 if (phba->fw_config.eqid_count == 1) {
3767 enable_msix = 0;
3768 phba->num_cpus = 1;
3769 return;
3770 }
3771
3772 phba->num_cpus =
3773 (num_cpus > (phba->fw_config.eqid_count - 1)) ?
3774 (phba->fw_config.eqid_count - 1) : num_cpus;
John Soni Jose22abeef2012-10-20 04:43:32 +05303775 break;
3776 default:
3777 phba->num_cpus = 1;
3778 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303779}
3780
3781static int hwi_init_port(struct beiscsi_hba *phba)
3782{
3783 struct hwi_controller *phwi_ctrlr;
3784 struct hwi_context_memory *phwi_context;
3785 unsigned int def_pdu_ring_sz;
3786 struct be_ctrl_info *ctrl = &phba->ctrl;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003787 int status, ulp_num;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303788
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303789 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303790 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303791 phwi_context->max_eqd = 0;
3792 phwi_context->min_eqd = 0;
3793 phwi_context->cur_eqd = 64;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303794 be_cmd_fw_initialize(&phba->ctrl);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303795
3796 status = beiscsi_create_eqs(phba, phwi_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303797 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303798 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3799 "BM_%d : EQ not created\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303800 goto error;
3801 }
3802
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303803 status = be_mcc_queues_create(phba, phwi_context);
3804 if (status != 0)
3805 goto error;
3806
3807 status = mgmt_check_supported_fw(ctrl, phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303808 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303809 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3810 "BM_%d : Unsupported fw version\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303811 goto error;
3812 }
3813
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303814 status = beiscsi_create_cqs(phba, phwi_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303815 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303816 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3817 "BM_%d : CQ not created\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303818 goto error;
3819 }
3820
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003821 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
3822 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303823
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003824 def_pdu_ring_sz =
3825 BEISCSI_GET_CID_COUNT(phba, ulp_num) *
3826 sizeof(struct phys_addr);
3827
3828 status = beiscsi_create_def_hdr(phba, phwi_context,
3829 phwi_ctrlr,
3830 def_pdu_ring_sz,
3831 ulp_num);
3832 if (status != 0) {
3833 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3834 "BM_%d : Default Header not created for ULP : %d\n",
3835 ulp_num);
3836 goto error;
3837 }
3838
3839 status = beiscsi_create_def_data(phba, phwi_context,
3840 phwi_ctrlr,
3841 def_pdu_ring_sz,
3842 ulp_num);
3843 if (status != 0) {
3844 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3845 "BM_%d : Default Data not created for ULP : %d\n",
3846 ulp_num);
3847 goto error;
3848 }
3849 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303850 }
3851
3852 status = beiscsi_post_pages(phba);
3853 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303854 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3855 "BM_%d : Post SGL Pages Failed\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303856 goto error;
3857 }
3858
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07003859 status = beiscsi_post_template_hdr(phba);
3860 if (status != 0) {
3861 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3862 "BM_%d : Template HDR Posting for CXN Failed\n");
3863 }
3864
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303865 status = beiscsi_create_wrb_rings(phba, phwi_context, phwi_ctrlr);
3866 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303867 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3868 "BM_%d : WRB Rings not created\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303869 goto error;
3870 }
3871
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003872 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
3873 uint16_t async_arr_idx = 0;
3874
3875 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
3876 uint16_t cri = 0;
3877 struct hwi_async_pdu_context *pasync_ctx;
3878
3879 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(
3880 phwi_ctrlr, ulp_num);
3881 for (cri = 0; cri <
3882 phba->params.cxns_per_ctrl; cri++) {
3883 if (ulp_num == BEISCSI_GET_ULP_FROM_CRI
3884 (phwi_ctrlr, cri))
3885 pasync_ctx->cid_to_async_cri_map[
3886 phwi_ctrlr->wrb_context[cri].cid] =
3887 async_arr_idx++;
3888 }
3889 }
3890 }
3891
John Soni Jose99bc5d52012-08-20 23:00:18 +05303892 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3893 "BM_%d : hwi_init_port success\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303894 return 0;
3895
3896error:
John Soni Jose99bc5d52012-08-20 23:00:18 +05303897 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3898 "BM_%d : hwi_init_port failed");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303899 hwi_cleanup(phba);
Jayamohan Kallickala49e06d2012-04-03 23:41:44 -05003900 return status;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303901}
3902
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303903static int hwi_init_controller(struct beiscsi_hba *phba)
3904{
3905 struct hwi_controller *phwi_ctrlr;
3906
3907 phwi_ctrlr = phba->phwi_ctrlr;
3908 if (1 == phba->init_mem[HWI_MEM_ADDN_CONTEXT].num_elements) {
3909 phwi_ctrlr->phwi_ctxt = (struct hwi_context_memory *)phba->
3910 init_mem[HWI_MEM_ADDN_CONTEXT].mem_array[0].virtual_address;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303911 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3912 "BM_%d : phwi_ctrlr->phwi_ctxt=%p\n",
3913 phwi_ctrlr->phwi_ctxt);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303914 } else {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303915 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3916 "BM_%d : HWI_MEM_ADDN_CONTEXT is more "
3917 "than one element.Failing to load\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303918 return -ENOMEM;
3919 }
3920
3921 iscsi_init_global_templates(phba);
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05003922 if (beiscsi_init_wrb_handle(phba))
3923 return -ENOMEM;
3924
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003925 if (hwi_init_async_pdu_ctx(phba)) {
3926 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3927 "BM_%d : hwi_init_async_pdu_ctx failed\n");
3928 return -ENOMEM;
3929 }
3930
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303931 if (hwi_init_port(phba) != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303932 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3933 "BM_%d : hwi_init_controller failed\n");
3934
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303935 return -ENOMEM;
3936 }
3937 return 0;
3938}
3939
3940static void beiscsi_free_mem(struct beiscsi_hba *phba)
3941{
3942 struct be_mem_descriptor *mem_descr;
3943 int i, j;
3944
3945 mem_descr = phba->init_mem;
3946 i = 0;
3947 j = 0;
3948 for (i = 0; i < SE_MEM_MAX; i++) {
3949 for (j = mem_descr->num_elements; j > 0; j--) {
3950 pci_free_consistent(phba->pcidev,
3951 mem_descr->mem_array[j - 1].size,
3952 mem_descr->mem_array[j - 1].virtual_address,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05303953 (unsigned long)mem_descr->mem_array[j - 1].
3954 bus_address.u.a64.address);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303955 }
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003956
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303957 kfree(mem_descr->mem_array);
3958 mem_descr++;
3959 }
3960 kfree(phba->init_mem);
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003961 kfree(phba->phwi_ctrlr->wrb_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303962 kfree(phba->phwi_ctrlr);
3963}
3964
3965static int beiscsi_init_controller(struct beiscsi_hba *phba)
3966{
3967 int ret = -ENOMEM;
3968
3969 ret = beiscsi_get_memory(phba);
3970 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303971 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3972 "BM_%d : beiscsi_dev_probe -"
3973 "Failed in beiscsi_alloc_memory\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303974 return ret;
3975 }
3976
3977 ret = hwi_init_controller(phba);
3978 if (ret)
3979 goto free_init;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303980 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3981 "BM_%d : Return success from beiscsi_init_controller");
3982
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303983 return 0;
3984
3985free_init:
3986 beiscsi_free_mem(phba);
Jayamohan Kallickala49e06d2012-04-03 23:41:44 -05003987 return ret;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303988}
3989
3990static int beiscsi_init_sgl_handle(struct beiscsi_hba *phba)
3991{
3992 struct be_mem_descriptor *mem_descr_sglh, *mem_descr_sg;
3993 struct sgl_handle *psgl_handle;
3994 struct iscsi_sge *pfrag;
Jayamohan Kallickal90622db2013-09-28 15:35:47 -07003995 unsigned int arr_index, i, idx;
3996 unsigned int ulp_icd_start, ulp_num = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303997
3998 phba->io_sgl_hndl_avbl = 0;
3999 phba->eh_sgl_hndl_avbl = 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304000
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304001 mem_descr_sglh = phba->init_mem;
4002 mem_descr_sglh += HWI_MEM_SGLH;
4003 if (1 == mem_descr_sglh->num_elements) {
4004 phba->io_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
4005 phba->params.ios_per_ctrl,
4006 GFP_KERNEL);
4007 if (!phba->io_sgl_hndl_base) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304008 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4009 "BM_%d : Mem Alloc Failed. Failing to load\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304010 return -ENOMEM;
4011 }
4012 phba->eh_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
4013 (phba->params.icds_per_ctrl -
4014 phba->params.ios_per_ctrl),
4015 GFP_KERNEL);
4016 if (!phba->eh_sgl_hndl_base) {
4017 kfree(phba->io_sgl_hndl_base);
John Soni Jose99bc5d52012-08-20 23:00:18 +05304018 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4019 "BM_%d : Mem Alloc Failed. Failing to load\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304020 return -ENOMEM;
4021 }
4022 } else {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304023 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4024 "BM_%d : HWI_MEM_SGLH is more than one element."
4025 "Failing to load\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304026 return -ENOMEM;
4027 }
4028
4029 arr_index = 0;
4030 idx = 0;
4031 while (idx < mem_descr_sglh->num_elements) {
4032 psgl_handle = mem_descr_sglh->mem_array[idx].virtual_address;
4033
4034 for (i = 0; i < (mem_descr_sglh->mem_array[idx].size /
4035 sizeof(struct sgl_handle)); i++) {
4036 if (arr_index < phba->params.ios_per_ctrl) {
4037 phba->io_sgl_hndl_base[arr_index] = psgl_handle;
4038 phba->io_sgl_hndl_avbl++;
4039 arr_index++;
4040 } else {
4041 phba->eh_sgl_hndl_base[arr_index -
4042 phba->params.ios_per_ctrl] =
4043 psgl_handle;
4044 arr_index++;
4045 phba->eh_sgl_hndl_avbl++;
4046 }
4047 psgl_handle++;
4048 }
4049 idx++;
4050 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05304051 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4052 "BM_%d : phba->io_sgl_hndl_avbl=%d"
4053 "phba->eh_sgl_hndl_avbl=%d\n",
4054 phba->io_sgl_hndl_avbl,
4055 phba->eh_sgl_hndl_avbl);
4056
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304057 mem_descr_sg = phba->init_mem;
4058 mem_descr_sg += HWI_MEM_SGE;
John Soni Jose99bc5d52012-08-20 23:00:18 +05304059 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4060 "\n BM_%d : mem_descr_sg->num_elements=%d\n",
4061 mem_descr_sg->num_elements);
4062
Jayamohan Kallickal90622db2013-09-28 15:35:47 -07004063 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
4064 if (test_bit(ulp_num, &phba->fw_config.ulp_supported))
4065 break;
4066
4067 ulp_icd_start = phba->fw_config.iscsi_icd_start[ulp_num];
4068
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304069 arr_index = 0;
4070 idx = 0;
4071 while (idx < mem_descr_sg->num_elements) {
4072 pfrag = mem_descr_sg->mem_array[idx].virtual_address;
4073
4074 for (i = 0;
4075 i < (mem_descr_sg->mem_array[idx].size) /
4076 (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io);
4077 i++) {
4078 if (arr_index < phba->params.ios_per_ctrl)
4079 psgl_handle = phba->io_sgl_hndl_base[arr_index];
4080 else
4081 psgl_handle = phba->eh_sgl_hndl_base[arr_index -
4082 phba->params.ios_per_ctrl];
4083 psgl_handle->pfrag = pfrag;
4084 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, pfrag, 0);
4085 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, pfrag, 0);
4086 pfrag += phba->params.num_sge_per_io;
Jayamohan Kallickal90622db2013-09-28 15:35:47 -07004087 psgl_handle->sgl_index = ulp_icd_start + arr_index++;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304088 }
4089 idx++;
4090 }
4091 phba->io_sgl_free_index = 0;
4092 phba->io_sgl_alloc_index = 0;
4093 phba->eh_sgl_free_index = 0;
4094 phba->eh_sgl_alloc_index = 0;
4095 return 0;
4096}
4097
4098static int hba_setup_cid_tbls(struct beiscsi_hba *phba)
4099{
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07004100 int ret;
4101 uint16_t i, ulp_num;
4102 struct ulp_cid_info *ptr_cid_info = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304103
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07004104 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
4105 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
4106 ptr_cid_info = kzalloc(sizeof(struct ulp_cid_info),
4107 GFP_KERNEL);
4108
4109 if (!ptr_cid_info) {
4110 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4111 "BM_%d : Failed to allocate memory"
4112 "for ULP_CID_INFO for ULP : %d\n",
4113 ulp_num);
4114 ret = -ENOMEM;
4115 goto free_memory;
4116
4117 }
4118
4119 /* Allocate memory for CID array */
4120 ptr_cid_info->cid_array = kzalloc(sizeof(void *) *
4121 BEISCSI_GET_CID_COUNT(phba,
4122 ulp_num), GFP_KERNEL);
4123 if (!ptr_cid_info->cid_array) {
4124 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4125 "BM_%d : Failed to allocate memory"
4126 "for CID_ARRAY for ULP : %d\n",
4127 ulp_num);
4128 kfree(ptr_cid_info);
4129 ptr_cid_info = NULL;
4130 ret = -ENOMEM;
4131
4132 goto free_memory;
4133 }
4134 ptr_cid_info->avlbl_cids = BEISCSI_GET_CID_COUNT(
4135 phba, ulp_num);
4136
4137 /* Save the cid_info_array ptr */
4138 phba->cid_array_info[ulp_num] = ptr_cid_info;
4139 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304140 }
Jayamohan Kallickalc2462282010-01-05 05:05:34 +05304141 phba->ep_array = kzalloc(sizeof(struct iscsi_endpoint *) *
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004142 phba->params.cxns_per_ctrl, GFP_KERNEL);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304143 if (!phba->ep_array) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304144 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4145 "BM_%d : Failed to allocate memory in "
4146 "hba_setup_cid_tbls\n");
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07004147 ret = -ENOMEM;
4148
4149 goto free_memory;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304150 }
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004151
4152 phba->conn_table = kzalloc(sizeof(struct beiscsi_conn *) *
4153 phba->params.cxns_per_ctrl, GFP_KERNEL);
4154 if (!phba->conn_table) {
4155 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4156 "BM_%d : Failed to allocate memory in"
4157 "hba_setup_cid_tbls\n");
4158
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004159 kfree(phba->ep_array);
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004160 phba->ep_array = NULL;
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07004161 ret = -ENOMEM;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304162 }
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004163
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07004164 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
4165 ulp_num = phba->phwi_ctrlr->wrb_context[i].ulp_num;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004166
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07004167 ptr_cid_info = phba->cid_array_info[ulp_num];
4168 ptr_cid_info->cid_array[ptr_cid_info->cid_alloc++] =
4169 phba->phwi_ctrlr->wrb_context[i].cid;
4170
4171 }
4172
4173 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
4174 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
4175 ptr_cid_info = phba->cid_array_info[ulp_num];
4176
4177 ptr_cid_info->cid_alloc = 0;
4178 ptr_cid_info->cid_free = 0;
4179 }
4180 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304181 return 0;
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07004182
4183free_memory:
4184 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
4185 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
4186 ptr_cid_info = phba->cid_array_info[ulp_num];
4187
4188 if (ptr_cid_info) {
4189 kfree(ptr_cid_info->cid_array);
4190 kfree(ptr_cid_info);
4191 phba->cid_array_info[ulp_num] = NULL;
4192 }
4193 }
4194 }
4195
4196 return ret;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304197}
4198
Jayamohan Kallickal238f6b72010-07-22 04:23:22 +05304199static void hwi_enable_intr(struct beiscsi_hba *phba)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304200{
4201 struct be_ctrl_info *ctrl = &phba->ctrl;
4202 struct hwi_controller *phwi_ctrlr;
4203 struct hwi_context_memory *phwi_context;
4204 struct be_queue_info *eq;
4205 u8 __iomem *addr;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304206 u32 reg, i;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304207 u32 enabled;
4208
4209 phwi_ctrlr = phba->phwi_ctrlr;
4210 phwi_context = phwi_ctrlr->phwi_ctxt;
4211
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304212 addr = (u8 __iomem *) ((u8 __iomem *) ctrl->pcicfg +
4213 PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET);
4214 reg = ioread32(addr);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304215
4216 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
4217 if (!enabled) {
4218 reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
John Soni Jose99bc5d52012-08-20 23:00:18 +05304219 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4220 "BM_%d : reg =x%08x addr=%p\n", reg, addr);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304221 iowrite32(reg, addr);
Jayamohan Kallickal665d6d92011-04-29 14:30:06 -05004222 }
4223
4224 if (!phba->msix_enabled) {
4225 eq = &phwi_context->be_eq[0].q;
John Soni Jose99bc5d52012-08-20 23:00:18 +05304226 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4227 "BM_%d : eq->id=%d\n", eq->id);
4228
Jayamohan Kallickal665d6d92011-04-29 14:30:06 -05004229 hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
4230 } else {
4231 for (i = 0; i <= phba->num_cpus; i++) {
4232 eq = &phwi_context->be_eq[i].q;
John Soni Jose99bc5d52012-08-20 23:00:18 +05304233 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4234 "BM_%d : eq->id=%d\n", eq->id);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304235 hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
4236 }
Jayamohan Kallickalc03af1a2010-02-20 08:05:43 +05304237 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304238}
4239
4240static void hwi_disable_intr(struct beiscsi_hba *phba)
4241{
4242 struct be_ctrl_info *ctrl = &phba->ctrl;
4243
4244 u8 __iomem *addr = ctrl->pcicfg + PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET;
4245 u32 reg = ioread32(addr);
4246
4247 u32 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
4248 if (enabled) {
4249 reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
4250 iowrite32(reg, addr);
4251 } else
John Soni Jose99bc5d52012-08-20 23:00:18 +05304252 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
4253 "BM_%d : In hwi_disable_intr, Already Disabled\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304254}
4255
John Soni Jose9aef4202012-08-20 23:00:08 +05304256/**
4257 * beiscsi_get_boot_info()- Get the boot session info
4258 * @phba: The device priv structure instance
4259 *
4260 * Get the boot target info and store in driver priv structure
4261 *
4262 * return values
4263 * Success: 0
4264 * Failure: Non-Zero Value
4265 **/
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304266static int beiscsi_get_boot_info(struct beiscsi_hba *phba)
4267{
Mike Christie0e438952012-04-03 23:41:51 -05004268 struct be_cmd_get_session_resp *session_resp;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304269 struct be_dma_mem nonemb_cmd;
John Soni Josee175def2012-10-20 04:45:40 +05304270 unsigned int tag;
John Soni Jose9aef4202012-08-20 23:00:08 +05304271 unsigned int s_handle;
Mike Christief457a462011-06-24 15:11:53 -05004272 int ret = -ENOMEM;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304273
John Soni Jose9aef4202012-08-20 23:00:08 +05304274 /* Get the session handle of the boot target */
4275 ret = be_mgmt_get_boot_shandle(phba, &s_handle);
4276 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304277 beiscsi_log(phba, KERN_ERR,
4278 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
4279 "BM_%d : No boot session\n");
John Soni Jose9aef4202012-08-20 23:00:08 +05304280 return ret;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304281 }
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304282 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
4283 sizeof(*session_resp),
4284 &nonemb_cmd.dma);
4285 if (nonemb_cmd.va == NULL) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304286 beiscsi_log(phba, KERN_ERR,
4287 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
4288 "BM_%d : Failed to allocate memory for"
4289 "beiscsi_get_session_info\n");
4290
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304291 return -ENOMEM;
4292 }
4293
4294 memset(nonemb_cmd.va, 0, sizeof(*session_resp));
John Soni Jose9aef4202012-08-20 23:00:08 +05304295 tag = mgmt_get_session_info(phba, s_handle,
Mike Christie0e438952012-04-03 23:41:51 -05004296 &nonemb_cmd);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304297 if (!tag) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304298 beiscsi_log(phba, KERN_ERR,
4299 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
4300 "BM_%d : beiscsi_get_session_info"
4301 " Failed\n");
4302
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304303 goto boot_freemem;
John Soni Josee175def2012-10-20 04:45:40 +05304304 }
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304305
John Soni Josee175def2012-10-20 04:45:40 +05304306 ret = beiscsi_mccq_compl(phba, tag, NULL, nonemb_cmd.va);
4307 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304308 beiscsi_log(phba, KERN_ERR,
4309 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
John Soni Josee175def2012-10-20 04:45:40 +05304310 "BM_%d : beiscsi_get_session_info Failed");
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304311 goto boot_freemem;
4312 }
John Soni Josee175def2012-10-20 04:45:40 +05304313
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304314 session_resp = nonemb_cmd.va ;
Mike Christief457a462011-06-24 15:11:53 -05004315
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304316 memcpy(&phba->boot_sess, &session_resp->session_info,
4317 sizeof(struct mgmt_session_info));
Mike Christief457a462011-06-24 15:11:53 -05004318 ret = 0;
4319
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304320boot_freemem:
4321 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
4322 nonemb_cmd.va, nonemb_cmd.dma);
Mike Christief457a462011-06-24 15:11:53 -05004323 return ret;
4324}
4325
4326static void beiscsi_boot_release(void *data)
4327{
4328 struct beiscsi_hba *phba = data;
4329
4330 scsi_host_put(phba->shost);
4331}
4332
4333static int beiscsi_setup_boot_info(struct beiscsi_hba *phba)
4334{
4335 struct iscsi_boot_kobj *boot_kobj;
4336
4337 /* get boot info using mgmt cmd */
4338 if (beiscsi_get_boot_info(phba))
4339 /* Try to see if we can carry on without this */
4340 return 0;
4341
4342 phba->boot_kset = iscsi_boot_create_host_kset(phba->shost->host_no);
4343 if (!phba->boot_kset)
4344 return -ENOMEM;
4345
4346 /* get a ref because the show function will ref the phba */
4347 if (!scsi_host_get(phba->shost))
4348 goto free_kset;
4349 boot_kobj = iscsi_boot_create_target(phba->boot_kset, 0, phba,
4350 beiscsi_show_boot_tgt_info,
4351 beiscsi_tgt_get_attr_visibility,
4352 beiscsi_boot_release);
4353 if (!boot_kobj)
4354 goto put_shost;
4355
4356 if (!scsi_host_get(phba->shost))
4357 goto free_kset;
4358 boot_kobj = iscsi_boot_create_initiator(phba->boot_kset, 0, phba,
4359 beiscsi_show_boot_ini_info,
4360 beiscsi_ini_get_attr_visibility,
4361 beiscsi_boot_release);
4362 if (!boot_kobj)
4363 goto put_shost;
4364
4365 if (!scsi_host_get(phba->shost))
4366 goto free_kset;
4367 boot_kobj = iscsi_boot_create_ethernet(phba->boot_kset, 0, phba,
4368 beiscsi_show_boot_eth_info,
4369 beiscsi_eth_get_attr_visibility,
4370 beiscsi_boot_release);
4371 if (!boot_kobj)
4372 goto put_shost;
4373 return 0;
4374
4375put_shost:
4376 scsi_host_put(phba->shost);
4377free_kset:
4378 iscsi_boot_destroy_kset(phba->boot_kset);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304379 return -ENOMEM;
4380}
4381
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304382static int beiscsi_init_port(struct beiscsi_hba *phba)
4383{
4384 int ret;
4385
4386 ret = beiscsi_init_controller(phba);
4387 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304388 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4389 "BM_%d : beiscsi_dev_probe - Failed in"
4390 "beiscsi_init_controller\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304391 return ret;
4392 }
4393 ret = beiscsi_init_sgl_handle(phba);
4394 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304395 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4396 "BM_%d : beiscsi_dev_probe - Failed in"
4397 "beiscsi_init_sgl_handle\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304398 goto do_cleanup_ctrlr;
4399 }
4400
4401 if (hba_setup_cid_tbls(phba)) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304402 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4403 "BM_%d : Failed in hba_setup_cid_tbls\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304404 kfree(phba->io_sgl_hndl_base);
4405 kfree(phba->eh_sgl_hndl_base);
4406 goto do_cleanup_ctrlr;
4407 }
4408
4409 return ret;
4410
4411do_cleanup_ctrlr:
4412 hwi_cleanup(phba);
4413 return ret;
4414}
4415
4416static void hwi_purge_eq(struct beiscsi_hba *phba)
4417{
4418 struct hwi_controller *phwi_ctrlr;
4419 struct hwi_context_memory *phwi_context;
4420 struct be_queue_info *eq;
4421 struct be_eq_entry *eqe = NULL;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304422 int i, eq_msix;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05304423 unsigned int num_processed;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304424
4425 phwi_ctrlr = phba->phwi_ctrlr;
4426 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304427 if (phba->msix_enabled)
4428 eq_msix = 1;
4429 else
4430 eq_msix = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304431
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304432 for (i = 0; i < (phba->num_cpus + eq_msix); i++) {
4433 eq = &phwi_context->be_eq[i].q;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304434 eqe = queue_tail_node(eq);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05304435 num_processed = 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304436 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
4437 & EQE_VALID_MASK) {
4438 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
4439 queue_tail_inc(eq);
4440 eqe = queue_tail_node(eq);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05304441 num_processed++;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304442 }
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05304443
4444 if (num_processed)
4445 hwi_ring_eq_db(phba, eq->id, 1, num_processed, 1, 1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304446 }
4447}
4448
4449static void beiscsi_clean_port(struct beiscsi_hba *phba)
4450{
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07004451 int mgmt_status, ulp_num;
4452 struct ulp_cid_info *ptr_cid_info = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304453
Jayamohan Kallickalbd41c2b2013-09-28 15:35:51 -07004454 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
4455 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
4456 mgmt_status = mgmt_epfw_cleanup(phba, ulp_num);
4457 if (mgmt_status)
4458 beiscsi_log(phba, KERN_WARNING,
4459 BEISCSI_LOG_INIT,
4460 "BM_%d : mgmt_epfw_cleanup FAILED"
4461 " for ULP_%d\n", ulp_num);
4462 }
4463 }
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05304464
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304465 hwi_purge_eq(phba);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05304466 hwi_cleanup(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304467 kfree(phba->io_sgl_hndl_base);
4468 kfree(phba->eh_sgl_hndl_base);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304469 kfree(phba->ep_array);
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004470 kfree(phba->conn_table);
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07004471
4472 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
4473 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
4474 ptr_cid_info = phba->cid_array_info[ulp_num];
4475
4476 if (ptr_cid_info) {
4477 kfree(ptr_cid_info->cid_array);
4478 kfree(ptr_cid_info);
4479 phba->cid_array_info[ulp_num] = NULL;
4480 }
4481 }
4482 }
4483
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304484}
4485
John Soni Josed629c472012-10-20 04:42:00 +05304486/**
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004487 * beiscsi_free_mgmt_task_handles()- Free driver CXN resources
4488 * @beiscsi_conn: ptr to the conn to be cleaned up
Jayamohan Kallickal4a4a11b2013-04-05 20:38:31 -07004489 * @task: ptr to iscsi_task resource to be freed.
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004490 *
4491 * Free driver mgmt resources binded to CXN.
4492 **/
4493void
Jayamohan Kallickal4a4a11b2013-04-05 20:38:31 -07004494beiscsi_free_mgmt_task_handles(struct beiscsi_conn *beiscsi_conn,
4495 struct iscsi_task *task)
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004496{
4497 struct beiscsi_io_task *io_task;
4498 struct beiscsi_hba *phba = beiscsi_conn->phba;
4499 struct hwi_wrb_context *pwrb_context;
4500 struct hwi_controller *phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004501 uint16_t cri_index = BE_GET_CRI_FROM_CID(
4502 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004503
4504 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004505 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
4506
Jayamohan Kallickal4a4a11b2013-04-05 20:38:31 -07004507 io_task = task->dd_data;
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004508
4509 if (io_task->pwrb_handle) {
4510 memset(io_task->pwrb_handle->pwrb, 0,
4511 sizeof(struct iscsi_wrb));
4512 free_wrb_handle(phba, pwrb_context,
4513 io_task->pwrb_handle);
4514 io_task->pwrb_handle = NULL;
4515 }
4516
4517 if (io_task->psgl_handle) {
4518 spin_lock_bh(&phba->mgmt_sgl_lock);
4519 free_mgmt_sgl_handle(phba,
4520 io_task->psgl_handle);
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004521 io_task->psgl_handle = NULL;
Jayamohan Kallickal4a4a11b2013-04-05 20:38:31 -07004522 spin_unlock_bh(&phba->mgmt_sgl_lock);
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004523 }
4524
4525 if (io_task->mtask_addr)
4526 pci_unmap_single(phba->pcidev,
4527 io_task->mtask_addr,
4528 io_task->mtask_data_count,
4529 PCI_DMA_TODEVICE);
4530}
4531
4532/**
John Soni Josed629c472012-10-20 04:42:00 +05304533 * beiscsi_cleanup_task()- Free driver resources of the task
4534 * @task: ptr to the iscsi task
4535 *
4536 **/
Mike Christie1282ab72012-04-18 03:06:00 -05004537static void beiscsi_cleanup_task(struct iscsi_task *task)
4538{
4539 struct beiscsi_io_task *io_task = task->dd_data;
4540 struct iscsi_conn *conn = task->conn;
4541 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4542 struct beiscsi_hba *phba = beiscsi_conn->phba;
4543 struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
4544 struct hwi_wrb_context *pwrb_context;
4545 struct hwi_controller *phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004546 uint16_t cri_index = BE_GET_CRI_FROM_CID(
4547 beiscsi_conn->beiscsi_conn_cid);
Mike Christie1282ab72012-04-18 03:06:00 -05004548
4549 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004550 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
Mike Christie1282ab72012-04-18 03:06:00 -05004551
4552 if (io_task->cmd_bhs) {
4553 pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
4554 io_task->bhs_pa.u.a64.address);
4555 io_task->cmd_bhs = NULL;
4556 }
4557
4558 if (task->sc) {
4559 if (io_task->pwrb_handle) {
4560 free_wrb_handle(phba, pwrb_context,
4561 io_task->pwrb_handle);
4562 io_task->pwrb_handle = NULL;
4563 }
4564
4565 if (io_task->psgl_handle) {
4566 spin_lock(&phba->io_sgl_lock);
4567 free_io_sgl_handle(phba, io_task->psgl_handle);
4568 spin_unlock(&phba->io_sgl_lock);
4569 io_task->psgl_handle = NULL;
4570 }
4571 } else {
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004572 if (!beiscsi_conn->login_in_progress)
Jayamohan Kallickal4a4a11b2013-04-05 20:38:31 -07004573 beiscsi_free_mgmt_task_handles(beiscsi_conn, task);
Mike Christie1282ab72012-04-18 03:06:00 -05004574 }
4575}
4576
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304577void
4578beiscsi_offload_connection(struct beiscsi_conn *beiscsi_conn,
4579 struct beiscsi_offload_params *params)
4580{
4581 struct wrb_handle *pwrb_handle;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304582 struct beiscsi_hba *phba = beiscsi_conn->phba;
Mike Christie1282ab72012-04-18 03:06:00 -05004583 struct iscsi_task *task = beiscsi_conn->task;
4584 struct iscsi_session *session = task->conn->session;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304585 u32 doorbell = 0;
4586
4587 /*
4588 * We can always use 0 here because it is reserved by libiscsi for
4589 * login/startup related tasks.
4590 */
Mike Christie1282ab72012-04-18 03:06:00 -05004591 beiscsi_conn->login_in_progress = 0;
4592 spin_lock_bh(&session->lock);
4593 beiscsi_cleanup_task(task);
4594 spin_unlock_bh(&session->lock);
4595
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004596 pwrb_handle = alloc_wrb_handle(phba, beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304597
John Soni Joseacb96932012-10-20 04:44:35 +05304598 /* Check for the adapter family */
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004599 if (is_chip_be2_be3r(phba))
John Soni Joseacb96932012-10-20 04:44:35 +05304600 beiscsi_offload_cxn_v0(params, pwrb_handle,
4601 phba->init_mem);
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004602 else
4603 beiscsi_offload_cxn_v2(params, pwrb_handle);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304604
John Soni Joseacb96932012-10-20 04:44:35 +05304605 be_dws_le_to_cpu(pwrb_handle->pwrb,
4606 sizeof(struct iscsi_target_context_update_wrb));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304607
4608 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304609 doorbell |= (pwrb_handle->wrb_index & DB_DEF_PDU_WRB_INDEX_MASK)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304610 << DB_DEF_PDU_WRB_INDEX_SHIFT;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304611 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
Jayamohan Kallickal1e4be6f2013-09-28 15:35:50 -07004612 iowrite32(doorbell, phba->db_va +
4613 beiscsi_conn->doorbell_offset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304614}
4615
4616static void beiscsi_parse_pdu(struct iscsi_conn *conn, itt_t itt,
4617 int *index, int *age)
4618{
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304619 *index = (int)itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304620 if (age)
4621 *age = conn->session->age;
4622}
4623
4624/**
4625 * beiscsi_alloc_pdu - allocates pdu and related resources
4626 * @task: libiscsi task
4627 * @opcode: opcode of pdu for task
4628 *
4629 * This is called with the session lock held. It will allocate
4630 * the wrb and sgl if needed for the command. And it will prep
4631 * the pdu's itt. beiscsi_parse_pdu will later translate
4632 * the pdu itt to the libiscsi task itt.
4633 */
4634static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
4635{
4636 struct beiscsi_io_task *io_task = task->dd_data;
4637 struct iscsi_conn *conn = task->conn;
4638 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4639 struct beiscsi_hba *phba = beiscsi_conn->phba;
4640 struct hwi_wrb_context *pwrb_context;
4641 struct hwi_controller *phwi_ctrlr;
4642 itt_t itt;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004643 uint16_t cri_index = 0;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304644 struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
4645 dma_addr_t paddr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304646
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304647 io_task->cmd_bhs = pci_pool_alloc(beiscsi_sess->bhs_pool,
Mike Christiebc7acce2010-12-31 02:22:19 -06004648 GFP_ATOMIC, &paddr);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304649 if (!io_task->cmd_bhs)
4650 return -ENOMEM;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304651 io_task->bhs_pa.u.a64.address = paddr;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304652 io_task->libiscsi_itt = (itt_t)task->itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304653 io_task->conn = beiscsi_conn;
4654
4655 task->hdr = (struct iscsi_hdr *)&io_task->cmd_bhs->iscsi_hdr;
4656 task->hdr_max = sizeof(struct be_cmd_bhs);
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304657 io_task->psgl_handle = NULL;
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05004658 io_task->pwrb_handle = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304659
4660 if (task->sc) {
4661 spin_lock(&phba->io_sgl_lock);
4662 io_task->psgl_handle = alloc_io_sgl_handle(phba);
4663 spin_unlock(&phba->io_sgl_lock);
John Soni Jose8359c792012-10-20 04:43:03 +05304664 if (!io_task->psgl_handle) {
4665 beiscsi_log(phba, KERN_ERR,
4666 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
4667 "BM_%d : Alloc of IO_SGL_ICD Failed"
4668 "for the CID : %d\n",
4669 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304670 goto free_hndls;
John Soni Jose8359c792012-10-20 04:43:03 +05304671 }
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304672 io_task->pwrb_handle = alloc_wrb_handle(phba,
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004673 beiscsi_conn->beiscsi_conn_cid);
John Soni Jose8359c792012-10-20 04:43:03 +05304674 if (!io_task->pwrb_handle) {
4675 beiscsi_log(phba, KERN_ERR,
4676 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
4677 "BM_%d : Alloc of WRB_HANDLE Failed"
4678 "for the CID : %d\n",
4679 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304680 goto free_io_hndls;
John Soni Jose8359c792012-10-20 04:43:03 +05304681 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304682 } else {
4683 io_task->scsi_cmnd = NULL;
Jayamohan Kallickald7aea672010-01-05 05:08:39 +05304684 if ((opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN) {
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004685 beiscsi_conn->task = task;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304686 if (!beiscsi_conn->login_in_progress) {
4687 spin_lock(&phba->mgmt_sgl_lock);
4688 io_task->psgl_handle = (struct sgl_handle *)
4689 alloc_mgmt_sgl_handle(phba);
4690 spin_unlock(&phba->mgmt_sgl_lock);
John Soni Jose8359c792012-10-20 04:43:03 +05304691 if (!io_task->psgl_handle) {
4692 beiscsi_log(phba, KERN_ERR,
4693 BEISCSI_LOG_IO |
4694 BEISCSI_LOG_CONFIG,
4695 "BM_%d : Alloc of MGMT_SGL_ICD Failed"
4696 "for the CID : %d\n",
4697 beiscsi_conn->
4698 beiscsi_conn_cid);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304699 goto free_hndls;
John Soni Jose8359c792012-10-20 04:43:03 +05304700 }
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304701
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304702 beiscsi_conn->login_in_progress = 1;
4703 beiscsi_conn->plogin_sgl_handle =
4704 io_task->psgl_handle;
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304705 io_task->pwrb_handle =
4706 alloc_wrb_handle(phba,
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004707 beiscsi_conn->beiscsi_conn_cid);
John Soni Jose8359c792012-10-20 04:43:03 +05304708 if (!io_task->pwrb_handle) {
4709 beiscsi_log(phba, KERN_ERR,
4710 BEISCSI_LOG_IO |
4711 BEISCSI_LOG_CONFIG,
4712 "BM_%d : Alloc of WRB_HANDLE Failed"
4713 "for the CID : %d\n",
4714 beiscsi_conn->
4715 beiscsi_conn_cid);
4716 goto free_mgmt_hndls;
4717 }
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304718 beiscsi_conn->plogin_wrb_handle =
4719 io_task->pwrb_handle;
4720
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304721 } else {
4722 io_task->psgl_handle =
4723 beiscsi_conn->plogin_sgl_handle;
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304724 io_task->pwrb_handle =
4725 beiscsi_conn->plogin_wrb_handle;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304726 }
4727 } else {
4728 spin_lock(&phba->mgmt_sgl_lock);
4729 io_task->psgl_handle = alloc_mgmt_sgl_handle(phba);
4730 spin_unlock(&phba->mgmt_sgl_lock);
John Soni Jose8359c792012-10-20 04:43:03 +05304731 if (!io_task->psgl_handle) {
4732 beiscsi_log(phba, KERN_ERR,
4733 BEISCSI_LOG_IO |
4734 BEISCSI_LOG_CONFIG,
4735 "BM_%d : Alloc of MGMT_SGL_ICD Failed"
4736 "for the CID : %d\n",
4737 beiscsi_conn->
4738 beiscsi_conn_cid);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304739 goto free_hndls;
John Soni Jose8359c792012-10-20 04:43:03 +05304740 }
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304741 io_task->pwrb_handle =
4742 alloc_wrb_handle(phba,
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004743 beiscsi_conn->beiscsi_conn_cid);
John Soni Jose8359c792012-10-20 04:43:03 +05304744 if (!io_task->pwrb_handle) {
4745 beiscsi_log(phba, KERN_ERR,
4746 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
4747 "BM_%d : Alloc of WRB_HANDLE Failed"
4748 "for the CID : %d\n",
4749 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304750 goto free_mgmt_hndls;
John Soni Jose8359c792012-10-20 04:43:03 +05304751 }
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304752
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304753 }
4754 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304755 itt = (itt_t) cpu_to_be32(((unsigned int)io_task->pwrb_handle->
4756 wrb_index << 16) | (unsigned int)
4757 (io_task->psgl_handle->sgl_index));
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304758 io_task->pwrb_handle->pio_handle = task;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304759
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304760 io_task->cmd_bhs->iscsi_hdr.itt = itt;
4761 return 0;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304762
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304763free_io_hndls:
4764 spin_lock(&phba->io_sgl_lock);
4765 free_io_sgl_handle(phba, io_task->psgl_handle);
4766 spin_unlock(&phba->io_sgl_lock);
4767 goto free_hndls;
4768free_mgmt_hndls:
4769 spin_lock(&phba->mgmt_sgl_lock);
4770 free_mgmt_sgl_handle(phba, io_task->psgl_handle);
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004771 io_task->psgl_handle = NULL;
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304772 spin_unlock(&phba->mgmt_sgl_lock);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304773free_hndls:
4774 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004775 cri_index = BE_GET_CRI_FROM_CID(
4776 beiscsi_conn->beiscsi_conn_cid);
4777 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304778 if (io_task->pwrb_handle)
4779 free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304780 io_task->pwrb_handle = NULL;
4781 pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
4782 io_task->bhs_pa.u.a64.address);
Mike Christie1282ab72012-04-18 03:06:00 -05004783 io_task->cmd_bhs = NULL;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304784 return -ENOMEM;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304785}
John Soni Jose09a10932012-10-20 04:44:23 +05304786int beiscsi_iotask_v2(struct iscsi_task *task, struct scatterlist *sg,
4787 unsigned int num_sg, unsigned int xferlen,
4788 unsigned int writedir)
4789{
4790
4791 struct beiscsi_io_task *io_task = task->dd_data;
4792 struct iscsi_conn *conn = task->conn;
4793 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4794 struct beiscsi_hba *phba = beiscsi_conn->phba;
4795 struct iscsi_wrb *pwrb = NULL;
4796 unsigned int doorbell = 0;
4797
4798 pwrb = io_task->pwrb_handle->pwrb;
John Soni Jose09a10932012-10-20 04:44:23 +05304799
4800 io_task->cmd_bhs->iscsi_hdr.exp_statsn = 0;
4801 io_task->bhs_len = sizeof(struct be_cmd_bhs);
4802
4803 if (writedir) {
4804 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb,
4805 INI_WR_CMD);
4806 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 1);
4807 } else {
4808 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb,
4809 INI_RD_CMD);
4810 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 0);
4811 }
4812
4813 io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb_v2,
4814 type, pwrb);
4815
4816 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, lun, pwrb,
4817 cpu_to_be16(*(unsigned short *)
4818 &io_task->cmd_bhs->iscsi_hdr.lun));
4819 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb, xferlen);
4820 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb,
4821 io_task->pwrb_handle->wrb_index);
4822 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb,
4823 be32_to_cpu(task->cmdsn));
4824 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb,
4825 io_task->psgl_handle->sgl_index);
4826
4827 hwi_write_sgl_v2(pwrb, sg, num_sg, io_task);
4828 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb,
4829 io_task->pwrb_handle->nxt_wrb_index);
4830
4831 be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
4832
4833 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
4834 doorbell |= (io_task->pwrb_handle->wrb_index &
4835 DB_DEF_PDU_WRB_INDEX_MASK) <<
4836 DB_DEF_PDU_WRB_INDEX_SHIFT;
4837 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
Jayamohan Kallickal1e4be6f2013-09-28 15:35:50 -07004838 iowrite32(doorbell, phba->db_va +
4839 beiscsi_conn->doorbell_offset);
John Soni Jose09a10932012-10-20 04:44:23 +05304840 return 0;
4841}
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304842
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304843static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg,
4844 unsigned int num_sg, unsigned int xferlen,
4845 unsigned int writedir)
4846{
4847
4848 struct beiscsi_io_task *io_task = task->dd_data;
4849 struct iscsi_conn *conn = task->conn;
4850 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4851 struct beiscsi_hba *phba = beiscsi_conn->phba;
4852 struct iscsi_wrb *pwrb = NULL;
4853 unsigned int doorbell = 0;
4854
4855 pwrb = io_task->pwrb_handle->pwrb;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304856 io_task->cmd_bhs->iscsi_hdr.exp_statsn = 0;
4857 io_task->bhs_len = sizeof(struct be_cmd_bhs);
4858
4859 if (writedir) {
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304860 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4861 INI_WR_CMD);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304862 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304863 } else {
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304864 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4865 INI_RD_CMD);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304866 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
4867 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304868
John Soni Jose09a10932012-10-20 04:44:23 +05304869 io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb,
4870 type, pwrb);
4871
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304872 AMAP_SET_BITS(struct amap_iscsi_wrb, lun, pwrb,
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05004873 cpu_to_be16(*(unsigned short *)
4874 &io_task->cmd_bhs->iscsi_hdr.lun));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304875 AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, xferlen);
4876 AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
4877 io_task->pwrb_handle->wrb_index);
4878 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
4879 be32_to_cpu(task->cmdsn));
4880 AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
4881 io_task->psgl_handle->sgl_index);
4882
4883 hwi_write_sgl(pwrb, sg, num_sg, io_task);
4884
4885 AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
4886 io_task->pwrb_handle->nxt_wrb_index);
4887 be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
4888
4889 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304890 doorbell |= (io_task->pwrb_handle->wrb_index &
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304891 DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
4892 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
4893
Jayamohan Kallickal1e4be6f2013-09-28 15:35:50 -07004894 iowrite32(doorbell, phba->db_va +
4895 beiscsi_conn->doorbell_offset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304896 return 0;
4897}
4898
4899static int beiscsi_mtask(struct iscsi_task *task)
4900{
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05304901 struct beiscsi_io_task *io_task = task->dd_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304902 struct iscsi_conn *conn = task->conn;
4903 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4904 struct beiscsi_hba *phba = beiscsi_conn->phba;
4905 struct iscsi_wrb *pwrb = NULL;
4906 unsigned int doorbell = 0;
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05304907 unsigned int cid;
John Soni Jose09a10932012-10-20 04:44:23 +05304908 unsigned int pwrb_typeoffset = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304909
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304910 cid = beiscsi_conn->beiscsi_conn_cid;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304911 pwrb = io_task->pwrb_handle->pwrb;
Jayamohan Kallickalcaf818f2010-01-23 05:38:18 +05304912 memset(pwrb, 0, sizeof(*pwrb));
John Soni Jose09a10932012-10-20 04:44:23 +05304913
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004914 if (is_chip_be2_be3r(phba)) {
John Soni Jose09a10932012-10-20 04:44:23 +05304915 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
4916 be32_to_cpu(task->cmdsn));
4917 AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
4918 io_task->pwrb_handle->wrb_index);
4919 AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
4920 io_task->psgl_handle->sgl_index);
4921 AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb,
4922 task->data_count);
4923 AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
4924 io_task->pwrb_handle->nxt_wrb_index);
4925 pwrb_typeoffset = BE_WRB_TYPE_OFFSET;
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004926 } else {
4927 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb,
4928 be32_to_cpu(task->cmdsn));
4929 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb,
4930 io_task->pwrb_handle->wrb_index);
4931 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb,
4932 io_task->psgl_handle->sgl_index);
4933 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb,
4934 task->data_count);
4935 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb,
4936 io_task->pwrb_handle->nxt_wrb_index);
4937 pwrb_typeoffset = SKH_WRB_TYPE_OFFSET;
John Soni Jose09a10932012-10-20 04:44:23 +05304938 }
4939
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05304940
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304941 switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
4942 case ISCSI_OP_LOGIN:
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304943 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, 1);
John Soni Jose09a10932012-10-20 04:44:23 +05304944 ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304945 hwi_write_buffer(pwrb, task);
4946 break;
4947 case ISCSI_OP_NOOP_OUT:
Jayamohan Kallickal1390b012011-03-25 14:24:01 -07004948 if (task->hdr->ttt != ISCSI_RESERVED_TAG) {
John Soni Jose09a10932012-10-20 04:44:23 +05304949 ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset);
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004950 if (is_chip_be2_be3r(phba))
4951 AMAP_SET_BITS(struct amap_iscsi_wrb,
John Soni Jose09a10932012-10-20 04:44:23 +05304952 dmsg, pwrb, 1);
4953 else
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004954 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
John Soni Jose09a10932012-10-20 04:44:23 +05304955 dmsg, pwrb, 1);
Jayamohan Kallickal1390b012011-03-25 14:24:01 -07004956 } else {
John Soni Jose09a10932012-10-20 04:44:23 +05304957 ADAPTER_SET_WRB_TYPE(pwrb, INI_RD_CMD, pwrb_typeoffset);
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004958 if (is_chip_be2_be3r(phba))
4959 AMAP_SET_BITS(struct amap_iscsi_wrb,
John Soni Jose09a10932012-10-20 04:44:23 +05304960 dmsg, pwrb, 0);
4961 else
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004962 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
John Soni Jose09a10932012-10-20 04:44:23 +05304963 dmsg, pwrb, 0);
Jayamohan Kallickal1390b012011-03-25 14:24:01 -07004964 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304965 hwi_write_buffer(pwrb, task);
4966 break;
4967 case ISCSI_OP_TEXT:
John Soni Jose09a10932012-10-20 04:44:23 +05304968 ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304969 hwi_write_buffer(pwrb, task);
4970 break;
4971 case ISCSI_OP_SCSI_TMFUNC:
John Soni Jose09a10932012-10-20 04:44:23 +05304972 ADAPTER_SET_WRB_TYPE(pwrb, INI_TMF_CMD, pwrb_typeoffset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304973 hwi_write_buffer(pwrb, task);
4974 break;
4975 case ISCSI_OP_LOGOUT:
John Soni Jose09a10932012-10-20 04:44:23 +05304976 ADAPTER_SET_WRB_TYPE(pwrb, HWH_TYPE_LOGOUT, pwrb_typeoffset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304977 hwi_write_buffer(pwrb, task);
4978 break;
4979
4980 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +05304981 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
4982 "BM_%d : opcode =%d Not supported\n",
4983 task->hdr->opcode & ISCSI_OPCODE_MASK);
4984
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304985 return -EINVAL;
4986 }
4987
John Soni Jose09a10932012-10-20 04:44:23 +05304988 /* Set the task type */
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004989 io_task->wrb_type = (is_chip_be2_be3r(phba)) ?
4990 AMAP_GET_BITS(struct amap_iscsi_wrb, type, pwrb) :
4991 AMAP_GET_BITS(struct amap_iscsi_wrb_v2, type, pwrb);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304992
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304993 doorbell |= cid & DB_WRB_POST_CID_MASK;
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304994 doorbell |= (io_task->pwrb_handle->wrb_index &
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304995 DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
4996 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
Jayamohan Kallickal1e4be6f2013-09-28 15:35:50 -07004997 iowrite32(doorbell, phba->db_va +
4998 beiscsi_conn->doorbell_offset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304999 return 0;
5000}
5001
5002static int beiscsi_task_xmit(struct iscsi_task *task)
5003{
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305004 struct beiscsi_io_task *io_task = task->dd_data;
5005 struct scsi_cmnd *sc = task->sc;
John Soni Jose09a10932012-10-20 04:44:23 +05305006 struct beiscsi_hba *phba = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305007 struct scatterlist *sg;
5008 int num_sg;
5009 unsigned int writedir = 0, xferlen = 0;
5010
John Soni Jose09a10932012-10-20 04:44:23 +05305011 phba = ((struct beiscsi_conn *)task->conn->dd_data)->phba;
5012
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305013 if (!sc)
5014 return beiscsi_mtask(task);
5015
5016 io_task->scsi_cmnd = sc;
5017 num_sg = scsi_dma_map(sc);
5018 if (num_sg < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305019 struct iscsi_conn *conn = task->conn;
5020 struct beiscsi_hba *phba = NULL;
5021
5022 phba = ((struct beiscsi_conn *)conn->dd_data)->phba;
Jayamohan Kallickalafb96052013-09-28 15:35:55 -07005023 beiscsi_log(phba, KERN_ERR,
5024 BEISCSI_LOG_IO | BEISCSI_LOG_ISCSI,
5025 "BM_%d : scsi_dma_map Failed "
5026 "Driver_ITT : 0x%x ITT : 0x%x Xferlen : 0x%x\n",
5027 be32_to_cpu(io_task->cmd_bhs->iscsi_hdr.itt),
5028 io_task->libiscsi_itt, scsi_bufflen(sc));
John Soni Jose99bc5d52012-08-20 23:00:18 +05305029
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305030 return num_sg;
5031 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305032 xferlen = scsi_bufflen(sc);
5033 sg = scsi_sglist(sc);
John Soni Jose99bc5d52012-08-20 23:00:18 +05305034 if (sc->sc_data_direction == DMA_TO_DEVICE)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305035 writedir = 1;
John Soni Jose99bc5d52012-08-20 23:00:18 +05305036 else
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305037 writedir = 0;
John Soni Jose99bc5d52012-08-20 23:00:18 +05305038
John Soni Jose09a10932012-10-20 04:44:23 +05305039 return phba->iotask_fn(task, sg, num_sg, xferlen, writedir);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305040}
5041
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05005042/**
5043 * beiscsi_bsg_request - handle bsg request from ISCSI transport
5044 * @job: job to handle
5045 */
5046static int beiscsi_bsg_request(struct bsg_job *job)
5047{
5048 struct Scsi_Host *shost;
5049 struct beiscsi_hba *phba;
5050 struct iscsi_bsg_request *bsg_req = job->request;
5051 int rc = -EINVAL;
5052 unsigned int tag;
5053 struct be_dma_mem nonemb_cmd;
5054 struct be_cmd_resp_hdr *resp;
5055 struct iscsi_bsg_reply *bsg_reply = job->reply;
5056 unsigned short status, extd_status;
5057
5058 shost = iscsi_job_to_shost(job);
5059 phba = iscsi_host_priv(shost);
5060
5061 switch (bsg_req->msgcode) {
5062 case ISCSI_BSG_HST_VENDOR:
5063 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
5064 job->request_payload.payload_len,
5065 &nonemb_cmd.dma);
5066 if (nonemb_cmd.va == NULL) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305067 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
5068 "BM_%d : Failed to allocate memory for "
5069 "beiscsi_bsg_request\n");
John Soni Jose8359c792012-10-20 04:43:03 +05305070 return -ENOMEM;
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05005071 }
5072 tag = mgmt_vendor_specific_fw_cmd(&phba->ctrl, phba, job,
5073 &nonemb_cmd);
5074 if (!tag) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305075 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
John Soni Jose8359c792012-10-20 04:43:03 +05305076 "BM_%d : MBX Tag Allocation Failed\n");
John Soni Jose99bc5d52012-08-20 23:00:18 +05305077
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05005078 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
5079 nonemb_cmd.va, nonemb_cmd.dma);
5080 return -EAGAIN;
John Soni Josee175def2012-10-20 04:45:40 +05305081 }
5082
5083 rc = wait_event_interruptible_timeout(
5084 phba->ctrl.mcc_wait[tag],
5085 phba->ctrl.mcc_numtag[tag],
5086 msecs_to_jiffies(
5087 BEISCSI_HOST_MBX_TIMEOUT));
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05005088 extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
5089 status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
5090 free_mcc_tag(&phba->ctrl, tag);
5091 resp = (struct be_cmd_resp_hdr *)nonemb_cmd.va;
5092 sg_copy_from_buffer(job->reply_payload.sg_list,
5093 job->reply_payload.sg_cnt,
5094 nonemb_cmd.va, (resp->response_length
5095 + sizeof(*resp)));
5096 bsg_reply->reply_payload_rcv_len = resp->response_length;
5097 bsg_reply->result = status;
5098 bsg_job_done(job, bsg_reply->result,
5099 bsg_reply->reply_payload_rcv_len);
5100 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
5101 nonemb_cmd.va, nonemb_cmd.dma);
5102 if (status || extd_status) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305103 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
John Soni Jose8359c792012-10-20 04:43:03 +05305104 "BM_%d : MBX Cmd Failed"
John Soni Jose99bc5d52012-08-20 23:00:18 +05305105 " status = %d extd_status = %d\n",
5106 status, extd_status);
5107
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05005108 return -EIO;
John Soni Jose8359c792012-10-20 04:43:03 +05305109 } else {
5110 rc = 0;
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05005111 }
5112 break;
5113
5114 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +05305115 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
5116 "BM_%d : Unsupported bsg command: 0x%x\n",
5117 bsg_req->msgcode);
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05005118 break;
5119 }
5120
5121 return rc;
5122}
5123
John Soni Jose99bc5d52012-08-20 23:00:18 +05305124void beiscsi_hba_attrs_init(struct beiscsi_hba *phba)
5125{
5126 /* Set the logging parameter */
5127 beiscsi_log_enable_init(phba, beiscsi_log_enable);
5128}
5129
John Soni Jose4d4d1ef2012-10-20 04:42:37 +05305130/*
5131 * beiscsi_quiesce()- Cleanup Driver resources
5132 * @phba: Instance Priv structure
5133 *
5134 * Free the OS and HW resources held by the driver
5135 **/
Jayamohan Kallickal25602c92011-08-22 10:08:28 -07005136static void beiscsi_quiesce(struct beiscsi_hba *phba)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305137{
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305138 struct hwi_controller *phwi_ctrlr;
5139 struct hwi_context_memory *phwi_context;
5140 struct be_eq_obj *pbe_eq;
5141 unsigned int i, msix_vec;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305142
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305143 phwi_ctrlr = phba->phwi_ctrlr;
5144 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305145 hwi_disable_intr(phba);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305146 if (phba->msix_enabled) {
5147 for (i = 0; i <= phba->num_cpus; i++) {
5148 msix_vec = phba->msix_entries[i].vector;
5149 free_irq(msix_vec, &phwi_context->be_eq[i]);
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -07005150 kfree(phba->msi_name[i]);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305151 }
5152 } else
5153 if (phba->pcidev->irq)
5154 free_irq(phba->pcidev->irq, phba);
5155 pci_disable_msix(phba->pcidev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305156 destroy_workqueue(phba->wq);
5157 if (blk_iopoll_enabled)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305158 for (i = 0; i < phba->num_cpus; i++) {
5159 pbe_eq = &phwi_context->be_eq[i];
5160 blk_iopoll_disable(&pbe_eq->iopoll);
5161 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305162
5163 beiscsi_clean_port(phba);
5164 beiscsi_free_mem(phba);
Jayamohan Kallickale9b91192010-07-22 04:24:53 +05305165
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305166 beiscsi_unmap_pci_function(phba);
5167 pci_free_consistent(phba->pcidev,
5168 phba->ctrl.mbox_mem_alloced.size,
5169 phba->ctrl.mbox_mem_alloced.va,
5170 phba->ctrl.mbox_mem_alloced.dma);
John Soni Jose7a158002012-10-20 04:45:51 +05305171
5172 cancel_delayed_work_sync(&phba->beiscsi_hw_check_task);
Jayamohan Kallickal25602c92011-08-22 10:08:28 -07005173}
5174
5175static void beiscsi_remove(struct pci_dev *pcidev)
5176{
5177
5178 struct beiscsi_hba *phba = NULL;
5179
5180 phba = pci_get_drvdata(pcidev);
5181 if (!phba) {
5182 dev_err(&pcidev->dev, "beiscsi_remove called with no phba\n");
5183 return;
5184 }
5185
Mike Christie0e438952012-04-03 23:41:51 -05005186 beiscsi_destroy_def_ifaces(phba);
Jayamohan Kallickal25602c92011-08-22 10:08:28 -07005187 beiscsi_quiesce(phba);
Mike Christie9d045162011-06-24 15:11:52 -05005188 iscsi_boot_destroy_kset(phba->boot_kset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305189 iscsi_host_remove(phba->shost);
5190 pci_dev_put(phba->pcidev);
5191 iscsi_host_free(phba->shost);
Jayamohan Kallickal8dce69f2011-08-22 10:08:29 -07005192 pci_disable_device(pcidev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305193}
5194
Jayamohan Kallickal25602c92011-08-22 10:08:28 -07005195static void beiscsi_shutdown(struct pci_dev *pcidev)
5196{
5197
5198 struct beiscsi_hba *phba = NULL;
5199
5200 phba = (struct beiscsi_hba *)pci_get_drvdata(pcidev);
5201 if (!phba) {
5202 dev_err(&pcidev->dev, "beiscsi_shutdown called with no phba\n");
5203 return;
5204 }
5205
5206 beiscsi_quiesce(phba);
Jayamohan Kallickal8dce69f2011-08-22 10:08:29 -07005207 pci_disable_device(pcidev);
Jayamohan Kallickal25602c92011-08-22 10:08:28 -07005208}
5209
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305210static void beiscsi_msix_enable(struct beiscsi_hba *phba)
5211{
5212 int i, status;
5213
5214 for (i = 0; i <= phba->num_cpus; i++)
5215 phba->msix_entries[i].entry = i;
5216
5217 status = pci_enable_msix(phba->pcidev, phba->msix_entries,
5218 (phba->num_cpus + 1));
5219 if (!status)
5220 phba->msix_enabled = true;
5221
5222 return;
5223}
5224
John Soni Jose7a158002012-10-20 04:45:51 +05305225/*
5226 * beiscsi_hw_health_check()- Check adapter health
5227 * @work: work item to check HW health
5228 *
5229 * Check if adapter in an unrecoverable state or not.
5230 **/
5231static void
5232beiscsi_hw_health_check(struct work_struct *work)
5233{
5234 struct beiscsi_hba *phba =
5235 container_of(work, struct beiscsi_hba,
5236 beiscsi_hw_check_task.work);
5237
5238 beiscsi_ue_detect(phba);
5239
5240 schedule_delayed_work(&phba->beiscsi_hw_check_task,
5241 msecs_to_jiffies(1000));
5242}
5243
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08005244static int beiscsi_dev_probe(struct pci_dev *pcidev,
5245 const struct pci_device_id *id)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305246{
5247 struct beiscsi_hba *phba = NULL;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305248 struct hwi_controller *phwi_ctrlr;
5249 struct hwi_context_memory *phwi_context;
5250 struct be_eq_obj *pbe_eq;
John Soni Jose107dfcb2012-10-20 04:42:13 +05305251 int ret, i;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305252
5253 ret = beiscsi_enable_pci(pcidev);
5254 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305255 dev_err(&pcidev->dev,
5256 "beiscsi_dev_probe - Failed to enable pci device\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305257 return ret;
5258 }
5259
5260 phba = beiscsi_hba_alloc(pcidev);
5261 if (!phba) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305262 dev_err(&pcidev->dev,
5263 "beiscsi_dev_probe - Failed in beiscsi_hba_alloc\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305264 goto disable_pci;
5265 }
5266
John Soni Jose99bc5d52012-08-20 23:00:18 +05305267 /* Initialize Driver configuration Paramters */
5268 beiscsi_hba_attrs_init(phba);
5269
John Soni Josee175def2012-10-20 04:45:40 +05305270 phba->fw_timeout = false;
Jayamohan Kallickal6c831852013-09-28 15:35:40 -07005271 phba->mac_addr_set = false;
John Soni Josee175def2012-10-20 04:45:40 +05305272
5273
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +05305274 switch (pcidev->device) {
5275 case BE_DEVICE_ID1:
5276 case OC_DEVICE_ID1:
5277 case OC_DEVICE_ID2:
5278 phba->generation = BE_GEN2;
John Soni Jose09a10932012-10-20 04:44:23 +05305279 phba->iotask_fn = beiscsi_iotask;
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +05305280 break;
5281 case BE_DEVICE_ID2:
5282 case OC_DEVICE_ID3:
5283 phba->generation = BE_GEN3;
John Soni Jose09a10932012-10-20 04:44:23 +05305284 phba->iotask_fn = beiscsi_iotask;
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +05305285 break;
John Soni Jose139a1b12012-10-20 04:43:20 +05305286 case OC_SKH_ID1:
5287 phba->generation = BE_GEN4;
John Soni Jose09a10932012-10-20 04:44:23 +05305288 phba->iotask_fn = beiscsi_iotask_v2;
Jayamohan Kallickalbf9131c2013-04-05 20:38:24 -07005289 break;
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +05305290 default:
5291 phba->generation = 0;
5292 }
5293
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305294 ret = be_ctrl_init(phba, pcidev);
5295 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305296 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5297 "BM_%d : beiscsi_dev_probe-"
5298 "Failed in be_ctrl_init\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305299 goto hba_free;
5300 }
5301
John Soni Jose4d4d1ef2012-10-20 04:42:37 +05305302 ret = beiscsi_cmd_reset_function(phba);
5303 if (ret) {
5304 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
Jayamohan Kallickal92665a62013-09-28 15:35:43 -07005305 "BM_%d : Reset Failed\n");
John Soni Jose4d4d1ef2012-10-20 04:42:37 +05305306 goto hba_free;
5307 }
5308 ret = be_chk_reset_complete(phba);
5309 if (ret) {
5310 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
Jayamohan Kallickal92665a62013-09-28 15:35:43 -07005311 "BM_%d : Failed to get out of reset.\n");
John Soni Jose4d4d1ef2012-10-20 04:42:37 +05305312 goto hba_free;
Jayamohan Kallickale9b91192010-07-22 04:24:53 +05305313 }
5314
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305315 spin_lock_init(&phba->io_sgl_lock);
5316 spin_lock_init(&phba->mgmt_sgl_lock);
5317 spin_lock_init(&phba->isr_lock);
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07005318 spin_lock_init(&phba->async_pdu_lock);
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05305319 ret = mgmt_get_fw_config(&phba->ctrl, phba);
5320 if (ret != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305321 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5322 "BM_%d : Error getting fw config\n");
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05305323 goto free_port;
5324 }
Jayamohan Kallickal68c26a32013-09-28 15:35:54 -07005325
5326 if (enable_msix)
5327 find_num_cpus(phba);
5328 else
5329 phba->num_cpus = 1;
5330
5331 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
5332 "BM_%d : num_cpus = %d\n",
5333 phba->num_cpus);
5334
5335 if (enable_msix) {
5336 beiscsi_msix_enable(phba);
5337 if (!phba->msix_enabled)
5338 phba->num_cpus = 1;
5339 }
5340
Jayamohan Kallickal843ae752013-09-28 15:35:44 -07005341 phba->shost->max_id = phba->params.cxns_per_ctrl;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305342 beiscsi_get_params(phba);
Jayamohan Kallickalaa874f02010-01-05 05:12:03 +05305343 phba->shost->can_queue = phba->params.ios_per_ctrl;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305344 ret = beiscsi_init_port(phba);
5345 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305346 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5347 "BM_%d : beiscsi_dev_probe-"
5348 "Failed in beiscsi_init_port\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305349 goto free_port;
5350 }
5351
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05305352 for (i = 0; i < MAX_MCC_CMD ; i++) {
5353 init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]);
5354 phba->ctrl.mcc_tag[i] = i + 1;
5355 phba->ctrl.mcc_numtag[i + 1] = 0;
5356 phba->ctrl.mcc_tag_available++;
5357 }
5358
5359 phba->ctrl.mcc_alloc_index = phba->ctrl.mcc_free_index = 0;
5360
John Soni Jose72fb46a2012-10-20 04:42:49 +05305361 snprintf(phba->wq_name, sizeof(phba->wq_name), "beiscsi_%02x_wq",
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305362 phba->shost->host_no);
Kees Cookd8537542013-07-03 15:04:57 -07005363 phba->wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 1, phba->wq_name);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305364 if (!phba->wq) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305365 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5366 "BM_%d : beiscsi_dev_probe-"
5367 "Failed to allocate work queue\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305368 goto free_twq;
5369 }
5370
John Soni Jose7a158002012-10-20 04:45:51 +05305371 INIT_DELAYED_WORK(&phba->beiscsi_hw_check_task,
5372 beiscsi_hw_health_check);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305373
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305374 phwi_ctrlr = phba->phwi_ctrlr;
5375 phwi_context = phwi_ctrlr->phwi_ctxt;
John Soni Jose72fb46a2012-10-20 04:42:49 +05305376
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305377 if (blk_iopoll_enabled) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305378 for (i = 0; i < phba->num_cpus; i++) {
5379 pbe_eq = &phwi_context->be_eq[i];
5380 blk_iopoll_init(&pbe_eq->iopoll, be_iopoll_budget,
5381 be_iopoll);
5382 blk_iopoll_enable(&pbe_eq->iopoll);
5383 }
John Soni Jose72fb46a2012-10-20 04:42:49 +05305384
5385 i = (phba->msix_enabled) ? i : 0;
5386 /* Work item for MCC handling */
5387 pbe_eq = &phwi_context->be_eq[i];
5388 INIT_WORK(&pbe_eq->work_cqs, beiscsi_process_all_cqs);
5389 } else {
5390 if (phba->msix_enabled) {
5391 for (i = 0; i <= phba->num_cpus; i++) {
5392 pbe_eq = &phwi_context->be_eq[i];
5393 INIT_WORK(&pbe_eq->work_cqs,
5394 beiscsi_process_all_cqs);
5395 }
5396 } else {
5397 pbe_eq = &phwi_context->be_eq[0];
5398 INIT_WORK(&pbe_eq->work_cqs,
5399 beiscsi_process_all_cqs);
5400 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305401 }
John Soni Jose72fb46a2012-10-20 04:42:49 +05305402
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305403 ret = beiscsi_init_irqs(phba);
5404 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305405 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5406 "BM_%d : beiscsi_dev_probe-"
5407 "Failed to beiscsi_init_irqs\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305408 goto free_blkenbld;
5409 }
Jayamohan Kallickal238f6b72010-07-22 04:23:22 +05305410 hwi_enable_intr(phba);
Mike Christief457a462011-06-24 15:11:53 -05005411
5412 if (beiscsi_setup_boot_info(phba))
5413 /*
5414 * log error but continue, because we may not be using
5415 * iscsi boot.
5416 */
John Soni Jose99bc5d52012-08-20 23:00:18 +05305417 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5418 "BM_%d : Could not set up "
5419 "iSCSI boot info.\n");
Mike Christief457a462011-06-24 15:11:53 -05005420
Mike Christie0e438952012-04-03 23:41:51 -05005421 beiscsi_create_def_ifaces(phba);
John Soni Jose7a158002012-10-20 04:45:51 +05305422 schedule_delayed_work(&phba->beiscsi_hw_check_task,
5423 msecs_to_jiffies(1000));
5424
John Soni Jose99bc5d52012-08-20 23:00:18 +05305425 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
5426 "\n\n\n BM_%d : SUCCESS - DRIVER LOADED\n\n\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305427 return 0;
5428
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305429free_blkenbld:
5430 destroy_workqueue(phba->wq);
5431 if (blk_iopoll_enabled)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305432 for (i = 0; i < phba->num_cpus; i++) {
5433 pbe_eq = &phwi_context->be_eq[i];
5434 blk_iopoll_disable(&pbe_eq->iopoll);
5435 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305436free_twq:
5437 beiscsi_clean_port(phba);
5438 beiscsi_free_mem(phba);
5439free_port:
5440 pci_free_consistent(phba->pcidev,
5441 phba->ctrl.mbox_mem_alloced.size,
5442 phba->ctrl.mbox_mem_alloced.va,
5443 phba->ctrl.mbox_mem_alloced.dma);
5444 beiscsi_unmap_pci_function(phba);
5445hba_free:
Jayamohan Kallickal238f6b72010-07-22 04:23:22 +05305446 if (phba->msix_enabled)
5447 pci_disable_msix(phba->pcidev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305448 iscsi_host_remove(phba->shost);
5449 pci_dev_put(phba->pcidev);
5450 iscsi_host_free(phba->shost);
5451disable_pci:
5452 pci_disable_device(pcidev);
5453 return ret;
5454}
5455
5456struct iscsi_transport beiscsi_iscsi_transport = {
5457 .owner = THIS_MODULE,
5458 .name = DRV_NAME,
Jayamohan Kallickal9db0fb32010-01-05 05:12:43 +05305459 .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_TEXT_NEGO |
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305460 CAP_MULTI_R2T | CAP_DATADGST | CAP_DATA_PATH_OFFLOAD,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305461 .create_session = beiscsi_session_create,
5462 .destroy_session = beiscsi_session_destroy,
5463 .create_conn = beiscsi_conn_create,
5464 .bind_conn = beiscsi_conn_bind,
5465 .destroy_conn = iscsi_conn_teardown,
Mike Christie3128c6c2011-07-25 13:48:42 -05005466 .attr_is_visible = be2iscsi_attr_is_visible,
Mike Christie0e438952012-04-03 23:41:51 -05005467 .set_iface_param = be2iscsi_iface_set_param,
5468 .get_iface_param = be2iscsi_iface_get_param,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305469 .set_param = beiscsi_set_param,
Mike Christiec7f7fd52011-02-16 15:04:41 -06005470 .get_conn_param = iscsi_conn_get_param,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305471 .get_session_param = iscsi_session_get_param,
5472 .get_host_param = beiscsi_get_host_param,
5473 .start_conn = beiscsi_conn_start,
Mike Christiefa95d202010-06-09 03:30:08 -05005474 .stop_conn = iscsi_conn_stop,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305475 .send_pdu = iscsi_conn_send_pdu,
5476 .xmit_task = beiscsi_task_xmit,
5477 .cleanup_task = beiscsi_cleanup_task,
5478 .alloc_pdu = beiscsi_alloc_pdu,
5479 .parse_pdu_itt = beiscsi_parse_pdu,
5480 .get_stats = beiscsi_conn_get_stats,
Mike Christiec7f7fd52011-02-16 15:04:41 -06005481 .get_ep_param = beiscsi_ep_get_param,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305482 .ep_connect = beiscsi_ep_connect,
5483 .ep_poll = beiscsi_ep_poll,
5484 .ep_disconnect = beiscsi_ep_disconnect,
5485 .session_recovery_timedout = iscsi_session_recovery_timedout,
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05005486 .bsg_request = beiscsi_bsg_request,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305487};
5488
5489static struct pci_driver beiscsi_pci_driver = {
5490 .name = DRV_NAME,
5491 .probe = beiscsi_dev_probe,
5492 .remove = beiscsi_remove,
Jayamohan Kallickal25602c92011-08-22 10:08:28 -07005493 .shutdown = beiscsi_shutdown,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305494 .id_table = beiscsi_pci_id_table
5495};
5496
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305497
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305498static int __init beiscsi_module_init(void)
5499{
5500 int ret;
5501
5502 beiscsi_scsi_transport =
5503 iscsi_register_transport(&beiscsi_iscsi_transport);
5504 if (!beiscsi_scsi_transport) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305505 printk(KERN_ERR
5506 "beiscsi_module_init - Unable to register beiscsi transport.\n");
Jayamohan Kallickalf55a24f2010-01-23 05:37:40 +05305507 return -ENOMEM;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305508 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05305509 printk(KERN_INFO "In beiscsi_module_init, tt=%p\n",
5510 &beiscsi_iscsi_transport);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305511
5512 ret = pci_register_driver(&beiscsi_pci_driver);
5513 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305514 printk(KERN_ERR
5515 "beiscsi_module_init - Unable to register beiscsi pci driver.\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305516 goto unregister_iscsi_transport;
5517 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305518 return 0;
5519
5520unregister_iscsi_transport:
5521 iscsi_unregister_transport(&beiscsi_iscsi_transport);
5522 return ret;
5523}
5524
5525static void __exit beiscsi_module_exit(void)
5526{
5527 pci_unregister_driver(&beiscsi_pci_driver);
5528 iscsi_unregister_transport(&beiscsi_iscsi_transport);
5529}
5530
5531module_init(beiscsi_module_init);
5532module_exit(beiscsi_module_exit);