blob: 0df2b2ac6ec97e5a4f889e2093579280ea0d9dc4 [file] [log] [blame]
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301/**
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -07002 * Copyright (C) 2005 - 2011 Emulex
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation. The full GNU General
8 * Public License is included in this distribution in the file called COPYING.
9 *
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070010 * Written by: Jayamohan Kallickal (jayamohan.kallickal@emulex.com)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053011 *
12 * Contact Information:
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070013 * linux-drivers@emulex.com
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053014 *
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070015 * Emulex
16 * 3333 Susan Street
17 * Costa Mesa, CA 92626
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053018 */
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070019
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053020#include <linux/reboot.h>
21#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/slab.h>
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053023#include <linux/interrupt.h>
24#include <linux/blkdev.h>
25#include <linux/pci.h>
26#include <linux/string.h>
27#include <linux/kernel.h>
28#include <linux/semaphore.h>
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +053029#include <linux/iscsi_boot_sysfs.h>
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040030#include <linux/module.h>
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -050031#include <linux/bsg-lib.h>
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053032
33#include <scsi/libiscsi.h>
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -050034#include <scsi/scsi_bsg_iscsi.h>
35#include <scsi/scsi_netlink.h>
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053036#include <scsi/scsi_transport_iscsi.h>
37#include <scsi/scsi_transport.h>
38#include <scsi/scsi_cmnd.h>
39#include <scsi/scsi_device.h>
40#include <scsi/scsi_host.h>
41#include <scsi/scsi.h>
42#include "be_main.h"
43#include "be_iscsi.h"
44#include "be_mgmt.h"
John Soni Jose0a513dd2012-08-20 23:00:55 +053045#include "be_cmds.h"
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053046
47static unsigned int be_iopoll_budget = 10;
48static unsigned int be_max_phys_size = 64;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +053049static unsigned int enable_msix = 1;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053050
51MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
52MODULE_DESCRIPTION(DRV_DESC " " BUILD_STR);
Jayamohan Kallickal76d15db2012-04-03 23:41:46 -050053MODULE_VERSION(BUILD_STR);
Jayamohan Kallickal2f635882012-04-03 23:41:45 -050054MODULE_AUTHOR("Emulex Corporation");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053055MODULE_LICENSE("GPL");
56module_param(be_iopoll_budget, int, 0);
57module_param(enable_msix, int, 0);
58module_param(be_max_phys_size, uint, S_IRUGO);
John Soni Jose99bc5d52012-08-20 23:00:18 +053059MODULE_PARM_DESC(be_max_phys_size,
60 "Maximum Size (In Kilobytes) of physically contiguous "
61 "memory that can be allocated. Range is 16 - 128");
62
63#define beiscsi_disp_param(_name)\
64ssize_t \
65beiscsi_##_name##_disp(struct device *dev,\
66 struct device_attribute *attrib, char *buf) \
67{ \
68 struct Scsi_Host *shost = class_to_shost(dev);\
69 struct beiscsi_hba *phba = iscsi_host_priv(shost); \
70 uint32_t param_val = 0; \
71 param_val = phba->attr_##_name;\
72 return snprintf(buf, PAGE_SIZE, "%d\n",\
73 phba->attr_##_name);\
74}
75
76#define beiscsi_change_param(_name, _minval, _maxval, _defaval)\
77int \
78beiscsi_##_name##_change(struct beiscsi_hba *phba, uint32_t val)\
79{\
80 if (val >= _minval && val <= _maxval) {\
81 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,\
82 "BA_%d : beiscsi_"#_name" updated "\
83 "from 0x%x ==> 0x%x\n",\
84 phba->attr_##_name, val); \
85 phba->attr_##_name = val;\
86 return 0;\
87 } \
88 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, \
89 "BA_%d beiscsi_"#_name" attribute "\
90 "cannot be updated to 0x%x, "\
91 "range allowed is ["#_minval" - "#_maxval"]\n", val);\
92 return -EINVAL;\
93}
94
95#define beiscsi_store_param(_name) \
96ssize_t \
97beiscsi_##_name##_store(struct device *dev,\
98 struct device_attribute *attr, const char *buf,\
99 size_t count) \
100{ \
101 struct Scsi_Host *shost = class_to_shost(dev);\
102 struct beiscsi_hba *phba = iscsi_host_priv(shost);\
103 uint32_t param_val = 0;\
104 if (!isdigit(buf[0]))\
105 return -EINVAL;\
106 if (sscanf(buf, "%i", &param_val) != 1)\
107 return -EINVAL;\
108 if (beiscsi_##_name##_change(phba, param_val) == 0) \
109 return strlen(buf);\
110 else \
111 return -EINVAL;\
112}
113
114#define beiscsi_init_param(_name, _minval, _maxval, _defval) \
115int \
116beiscsi_##_name##_init(struct beiscsi_hba *phba, uint32_t val) \
117{ \
118 if (val >= _minval && val <= _maxval) {\
119 phba->attr_##_name = val;\
120 return 0;\
121 } \
122 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,\
123 "BA_%d beiscsi_"#_name" attribute " \
124 "cannot be updated to 0x%x, "\
125 "range allowed is ["#_minval" - "#_maxval"]\n", val);\
126 phba->attr_##_name = _defval;\
127 return -EINVAL;\
128}
129
130#define BEISCSI_RW_ATTR(_name, _minval, _maxval, _defval, _descp) \
131static uint beiscsi_##_name = _defval;\
132module_param(beiscsi_##_name, uint, S_IRUGO);\
133MODULE_PARM_DESC(beiscsi_##_name, _descp);\
134beiscsi_disp_param(_name)\
135beiscsi_change_param(_name, _minval, _maxval, _defval)\
136beiscsi_store_param(_name)\
137beiscsi_init_param(_name, _minval, _maxval, _defval)\
138DEVICE_ATTR(beiscsi_##_name, S_IRUGO | S_IWUSR,\
139 beiscsi_##_name##_disp, beiscsi_##_name##_store)
140
141/*
142 * When new log level added update the
143 * the MAX allowed value for log_enable
144 */
145BEISCSI_RW_ATTR(log_enable, 0x00,
146 0xFF, 0x00, "Enable logging Bit Mask\n"
147 "\t\t\t\tInitialization Events : 0x01\n"
148 "\t\t\t\tMailbox Events : 0x02\n"
149 "\t\t\t\tMiscellaneous Events : 0x04\n"
150 "\t\t\t\tError Handling : 0x08\n"
151 "\t\t\t\tIO Path Events : 0x10\n"
152 "\t\t\t\tConfiguration Path : 0x20\n");
153
John Soni Jose5cac7592012-10-20 04:42:25 +0530154DEVICE_ATTR(beiscsi_drvr_ver, S_IRUGO, beiscsi_drvr_ver_disp, NULL);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530155struct device_attribute *beiscsi_attrs[] = {
156 &dev_attr_beiscsi_log_enable,
John Soni Jose5cac7592012-10-20 04:42:25 +0530157 &dev_attr_beiscsi_drvr_ver,
John Soni Jose99bc5d52012-08-20 23:00:18 +0530158 NULL,
159};
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530160
John Soni Jose6763daa2012-10-20 04:41:45 +0530161static char const *cqe_desc[] = {
162 "RESERVED_DESC",
163 "SOL_CMD_COMPLETE",
164 "SOL_CMD_KILLED_DATA_DIGEST_ERR",
165 "CXN_KILLED_PDU_SIZE_EXCEEDS_DSL",
166 "CXN_KILLED_BURST_LEN_MISMATCH",
167 "CXN_KILLED_AHS_RCVD",
168 "CXN_KILLED_HDR_DIGEST_ERR",
169 "CXN_KILLED_UNKNOWN_HDR",
170 "CXN_KILLED_STALE_ITT_TTT_RCVD",
171 "CXN_KILLED_INVALID_ITT_TTT_RCVD",
172 "CXN_KILLED_RST_RCVD",
173 "CXN_KILLED_TIMED_OUT",
174 "CXN_KILLED_RST_SENT",
175 "CXN_KILLED_FIN_RCVD",
176 "CXN_KILLED_BAD_UNSOL_PDU_RCVD",
177 "CXN_KILLED_BAD_WRB_INDEX_ERROR",
178 "CXN_KILLED_OVER_RUN_RESIDUAL",
179 "CXN_KILLED_UNDER_RUN_RESIDUAL",
180 "CMD_KILLED_INVALID_STATSN_RCVD",
181 "CMD_KILLED_INVALID_R2T_RCVD",
182 "CMD_CXN_KILLED_LUN_INVALID",
183 "CMD_CXN_KILLED_ICD_INVALID",
184 "CMD_CXN_KILLED_ITT_INVALID",
185 "CMD_CXN_KILLED_SEQ_OUTOFORDER",
186 "CMD_CXN_KILLED_INVALID_DATASN_RCVD",
187 "CXN_INVALIDATE_NOTIFY",
188 "CXN_INVALIDATE_INDEX_NOTIFY",
189 "CMD_INVALIDATED_NOTIFY",
190 "UNSOL_HDR_NOTIFY",
191 "UNSOL_DATA_NOTIFY",
192 "UNSOL_DATA_DIGEST_ERROR_NOTIFY",
193 "DRIVERMSG_NOTIFY",
194 "CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN",
195 "SOL_CMD_KILLED_DIF_ERR",
196 "CXN_KILLED_SYN_RCVD",
197 "CXN_KILLED_IMM_DATA_RCVD"
198};
199
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530200static int beiscsi_slave_configure(struct scsi_device *sdev)
201{
202 blk_queue_max_segment_size(sdev->request_queue, 65536);
203 return 0;
204}
205
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530206static int beiscsi_eh_abort(struct scsi_cmnd *sc)
207{
208 struct iscsi_cls_session *cls_session;
209 struct iscsi_task *aborted_task = (struct iscsi_task *)sc->SCp.ptr;
210 struct beiscsi_io_task *aborted_io_task;
211 struct iscsi_conn *conn;
212 struct beiscsi_conn *beiscsi_conn;
213 struct beiscsi_hba *phba;
214 struct iscsi_session *session;
215 struct invalidate_command_table *inv_tbl;
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530216 struct be_dma_mem nonemb_cmd;
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530217 unsigned int cid, tag, num_invalidate;
218
219 cls_session = starget_to_session(scsi_target(sc->device));
220 session = cls_session->dd_data;
221
222 spin_lock_bh(&session->lock);
223 if (!aborted_task || !aborted_task->sc) {
224 /* we raced */
225 spin_unlock_bh(&session->lock);
226 return SUCCESS;
227 }
228
229 aborted_io_task = aborted_task->dd_data;
230 if (!aborted_io_task->scsi_cmnd) {
231 /* raced or invalid command */
232 spin_unlock_bh(&session->lock);
233 return SUCCESS;
234 }
235 spin_unlock_bh(&session->lock);
236 conn = aborted_task->conn;
237 beiscsi_conn = conn->dd_data;
238 phba = beiscsi_conn->phba;
239
240 /* invalidate iocb */
241 cid = beiscsi_conn->beiscsi_conn_cid;
242 inv_tbl = phba->inv_tbl;
243 memset(inv_tbl, 0x0, sizeof(*inv_tbl));
244 inv_tbl->cid = cid;
245 inv_tbl->icd = aborted_io_task->psgl_handle->sgl_index;
246 num_invalidate = 1;
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530247 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
248 sizeof(struct invalidate_commands_params_in),
249 &nonemb_cmd.dma);
250 if (nonemb_cmd.va == NULL) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530251 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
252 "BM_%d : Failed to allocate memory for"
253 "mgmt_invalidate_icds\n");
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530254 return FAILED;
255 }
256 nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
257
258 tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
259 cid, &nonemb_cmd);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530260 if (!tag) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530261 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH,
262 "BM_%d : mgmt_invalidate_icds could not be"
263 "submitted\n");
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530264 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
265 nonemb_cmd.va, nonemb_cmd.dma);
266
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530267 return FAILED;
268 } else {
269 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
270 phba->ctrl.mcc_numtag[tag]);
271 free_mcc_tag(&phba->ctrl, tag);
272 }
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530273 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
274 nonemb_cmd.va, nonemb_cmd.dma);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530275 return iscsi_eh_abort(sc);
276}
277
278static int beiscsi_eh_device_reset(struct scsi_cmnd *sc)
279{
280 struct iscsi_task *abrt_task;
281 struct beiscsi_io_task *abrt_io_task;
282 struct iscsi_conn *conn;
283 struct beiscsi_conn *beiscsi_conn;
284 struct beiscsi_hba *phba;
285 struct iscsi_session *session;
286 struct iscsi_cls_session *cls_session;
287 struct invalidate_command_table *inv_tbl;
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530288 struct be_dma_mem nonemb_cmd;
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530289 unsigned int cid, tag, i, num_invalidate;
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530290
291 /* invalidate iocbs */
292 cls_session = starget_to_session(scsi_target(sc->device));
293 session = cls_session->dd_data;
294 spin_lock_bh(&session->lock);
Jayamohan Kallickaldb7f7702012-04-03 23:41:43 -0500295 if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN) {
296 spin_unlock_bh(&session->lock);
297 return FAILED;
298 }
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530299 conn = session->leadconn;
300 beiscsi_conn = conn->dd_data;
301 phba = beiscsi_conn->phba;
302 cid = beiscsi_conn->beiscsi_conn_cid;
303 inv_tbl = phba->inv_tbl;
304 memset(inv_tbl, 0x0, sizeof(*inv_tbl) * BE2_CMDS_PER_CXN);
305 num_invalidate = 0;
306 for (i = 0; i < conn->session->cmds_max; i++) {
307 abrt_task = conn->session->cmds[i];
308 abrt_io_task = abrt_task->dd_data;
309 if (!abrt_task->sc || abrt_task->state == ISCSI_TASK_FREE)
310 continue;
311
312 if (abrt_task->sc->device->lun != abrt_task->sc->device->lun)
313 continue;
314
315 inv_tbl->cid = cid;
316 inv_tbl->icd = abrt_io_task->psgl_handle->sgl_index;
317 num_invalidate++;
318 inv_tbl++;
319 }
320 spin_unlock_bh(&session->lock);
321 inv_tbl = phba->inv_tbl;
322
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530323 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
324 sizeof(struct invalidate_commands_params_in),
325 &nonemb_cmd.dma);
326 if (nonemb_cmd.va == NULL) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530327 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
328 "BM_%d : Failed to allocate memory for"
329 "mgmt_invalidate_icds\n");
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530330 return FAILED;
331 }
332 nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
333 memset(nonemb_cmd.va, 0, nonemb_cmd.size);
334 tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
335 cid, &nonemb_cmd);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530336 if (!tag) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530337 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH,
338 "BM_%d : mgmt_invalidate_icds could not be"
339 " submitted\n");
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530340 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
341 nonemb_cmd.va, nonemb_cmd.dma);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530342 return FAILED;
343 } else {
344 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
345 phba->ctrl.mcc_numtag[tag]);
346 free_mcc_tag(&phba->ctrl, tag);
347 }
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530348 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
349 nonemb_cmd.va, nonemb_cmd.dma);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530350 return iscsi_eh_device_reset(sc);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530351}
352
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530353static ssize_t beiscsi_show_boot_tgt_info(void *data, int type, char *buf)
354{
355 struct beiscsi_hba *phba = data;
Mike Christief457a462011-06-24 15:11:53 -0500356 struct mgmt_session_info *boot_sess = &phba->boot_sess;
357 struct mgmt_conn_info *boot_conn = &boot_sess->conn_list[0];
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530358 char *str = buf;
359 int rc;
360
361 switch (type) {
362 case ISCSI_BOOT_TGT_NAME:
363 rc = sprintf(buf, "%.*s\n",
Mike Christief457a462011-06-24 15:11:53 -0500364 (int)strlen(boot_sess->target_name),
365 (char *)&boot_sess->target_name);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530366 break;
367 case ISCSI_BOOT_TGT_IP_ADDR:
Mike Christief457a462011-06-24 15:11:53 -0500368 if (boot_conn->dest_ipaddr.ip_type == 0x1)
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530369 rc = sprintf(buf, "%pI4\n",
Mike Christie0e438952012-04-03 23:41:51 -0500370 (char *)&boot_conn->dest_ipaddr.addr);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530371 else
372 rc = sprintf(str, "%pI6\n",
Mike Christie0e438952012-04-03 23:41:51 -0500373 (char *)&boot_conn->dest_ipaddr.addr);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530374 break;
375 case ISCSI_BOOT_TGT_PORT:
Mike Christief457a462011-06-24 15:11:53 -0500376 rc = sprintf(str, "%d\n", boot_conn->dest_port);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530377 break;
378
379 case ISCSI_BOOT_TGT_CHAP_NAME:
380 rc = sprintf(str, "%.*s\n",
Mike Christief457a462011-06-24 15:11:53 -0500381 boot_conn->negotiated_login_options.auth_data.chap.
382 target_chap_name_length,
383 (char *)&boot_conn->negotiated_login_options.
384 auth_data.chap.target_chap_name);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530385 break;
386 case ISCSI_BOOT_TGT_CHAP_SECRET:
387 rc = sprintf(str, "%.*s\n",
Mike Christief457a462011-06-24 15:11:53 -0500388 boot_conn->negotiated_login_options.auth_data.chap.
389 target_secret_length,
390 (char *)&boot_conn->negotiated_login_options.
391 auth_data.chap.target_secret);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530392 break;
393 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
394 rc = sprintf(str, "%.*s\n",
Mike Christief457a462011-06-24 15:11:53 -0500395 boot_conn->negotiated_login_options.auth_data.chap.
396 intr_chap_name_length,
397 (char *)&boot_conn->negotiated_login_options.
398 auth_data.chap.intr_chap_name);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530399 break;
400 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
Mike Christief457a462011-06-24 15:11:53 -0500401 rc = sprintf(str, "%.*s\n",
402 boot_conn->negotiated_login_options.auth_data.chap.
403 intr_secret_length,
404 (char *)&boot_conn->negotiated_login_options.
405 auth_data.chap.intr_secret);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530406 break;
407 case ISCSI_BOOT_TGT_FLAGS:
Mike Christief457a462011-06-24 15:11:53 -0500408 rc = sprintf(str, "2\n");
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530409 break;
410 case ISCSI_BOOT_TGT_NIC_ASSOC:
Mike Christief457a462011-06-24 15:11:53 -0500411 rc = sprintf(str, "0\n");
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530412 break;
413 default:
414 rc = -ENOSYS;
415 break;
416 }
417 return rc;
418}
419
420static ssize_t beiscsi_show_boot_ini_info(void *data, int type, char *buf)
421{
422 struct beiscsi_hba *phba = data;
423 char *str = buf;
424 int rc;
425
426 switch (type) {
427 case ISCSI_BOOT_INI_INITIATOR_NAME:
428 rc = sprintf(str, "%s\n", phba->boot_sess.initiator_iscsiname);
429 break;
430 default:
431 rc = -ENOSYS;
432 break;
433 }
434 return rc;
435}
436
437static ssize_t beiscsi_show_boot_eth_info(void *data, int type, char *buf)
438{
439 struct beiscsi_hba *phba = data;
440 char *str = buf;
441 int rc;
442
443 switch (type) {
444 case ISCSI_BOOT_ETH_FLAGS:
Mike Christief457a462011-06-24 15:11:53 -0500445 rc = sprintf(str, "2\n");
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530446 break;
447 case ISCSI_BOOT_ETH_INDEX:
Mike Christief457a462011-06-24 15:11:53 -0500448 rc = sprintf(str, "0\n");
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530449 break;
450 case ISCSI_BOOT_ETH_MAC:
Mike Christie0e438952012-04-03 23:41:51 -0500451 rc = beiscsi_get_macaddr(str, phba);
452 break;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530453 default:
454 rc = -ENOSYS;
455 break;
456 }
457 return rc;
458}
459
460
Al Viro587a1f12011-07-23 23:11:19 -0400461static umode_t beiscsi_tgt_get_attr_visibility(void *data, int type)
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530462{
Al Viro587a1f12011-07-23 23:11:19 -0400463 umode_t rc;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530464
465 switch (type) {
466 case ISCSI_BOOT_TGT_NAME:
467 case ISCSI_BOOT_TGT_IP_ADDR:
468 case ISCSI_BOOT_TGT_PORT:
469 case ISCSI_BOOT_TGT_CHAP_NAME:
470 case ISCSI_BOOT_TGT_CHAP_SECRET:
471 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
472 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
473 case ISCSI_BOOT_TGT_NIC_ASSOC:
474 case ISCSI_BOOT_TGT_FLAGS:
475 rc = S_IRUGO;
476 break;
477 default:
478 rc = 0;
479 break;
480 }
481 return rc;
482}
483
Al Viro587a1f12011-07-23 23:11:19 -0400484static umode_t beiscsi_ini_get_attr_visibility(void *data, int type)
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530485{
Al Viro587a1f12011-07-23 23:11:19 -0400486 umode_t rc;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530487
488 switch (type) {
489 case ISCSI_BOOT_INI_INITIATOR_NAME:
490 rc = S_IRUGO;
491 break;
492 default:
493 rc = 0;
494 break;
495 }
496 return rc;
497}
498
499
Al Viro587a1f12011-07-23 23:11:19 -0400500static umode_t beiscsi_eth_get_attr_visibility(void *data, int type)
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530501{
Al Viro587a1f12011-07-23 23:11:19 -0400502 umode_t rc;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530503
504 switch (type) {
505 case ISCSI_BOOT_ETH_FLAGS:
506 case ISCSI_BOOT_ETH_MAC:
507 case ISCSI_BOOT_ETH_INDEX:
508 rc = S_IRUGO;
509 break;
510 default:
511 rc = 0;
512 break;
513 }
514 return rc;
515}
516
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530517/*------------------- PCI Driver operations and data ----------------- */
518static DEFINE_PCI_DEVICE_TABLE(beiscsi_pci_id_table) = {
519 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) },
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +0530520 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) },
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530521 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) },
522 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) },
523 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID3) },
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530524 { 0 }
525};
526MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
527
John Soni Jose99bc5d52012-08-20 23:00:18 +0530528
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530529static struct scsi_host_template beiscsi_sht = {
530 .module = THIS_MODULE,
Jayamohan Kallickal2f635882012-04-03 23:41:45 -0500531 .name = "Emulex 10Gbe open-iscsi Initiator Driver",
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530532 .proc_name = DRV_NAME,
533 .queuecommand = iscsi_queuecommand,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530534 .change_queue_depth = iscsi_change_queue_depth,
535 .slave_configure = beiscsi_slave_configure,
536 .target_alloc = iscsi_target_alloc,
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530537 .eh_abort_handler = beiscsi_eh_abort,
538 .eh_device_reset_handler = beiscsi_eh_device_reset,
Jayamohan Kallickal309ce152010-02-20 08:02:10 +0530539 .eh_target_reset_handler = iscsi_eh_session_reset,
John Soni Jose99bc5d52012-08-20 23:00:18 +0530540 .shost_attrs = beiscsi_attrs,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530541 .sg_tablesize = BEISCSI_SGLIST_ELEMENTS,
542 .can_queue = BE2_IO_DEPTH,
543 .this_id = -1,
544 .max_sectors = BEISCSI_MAX_SECTORS,
545 .cmd_per_lun = BEISCSI_CMD_PER_LUN,
546 .use_clustering = ENABLE_CLUSTERING,
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -0500547 .vendor_id = SCSI_NL_VID_TYPE_PCI | BE_VENDOR_ID,
548
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530549};
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530550
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530551static struct scsi_transport_template *beiscsi_scsi_transport;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530552
553static struct beiscsi_hba *beiscsi_hba_alloc(struct pci_dev *pcidev)
554{
555 struct beiscsi_hba *phba;
556 struct Scsi_Host *shost;
557
558 shost = iscsi_host_alloc(&beiscsi_sht, sizeof(*phba), 0);
559 if (!shost) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530560 dev_err(&pcidev->dev,
561 "beiscsi_hba_alloc - iscsi_host_alloc failed\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530562 return NULL;
563 }
564 shost->dma_boundary = pcidev->dma_mask;
565 shost->max_id = BE2_MAX_SESSIONS;
566 shost->max_channel = 0;
567 shost->max_cmd_len = BEISCSI_MAX_CMD_LEN;
568 shost->max_lun = BEISCSI_NUM_MAX_LUN;
569 shost->transportt = beiscsi_scsi_transport;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530570 phba = iscsi_host_priv(shost);
571 memset(phba, 0, sizeof(*phba));
572 phba->shost = shost;
573 phba->pcidev = pci_dev_get(pcidev);
Jayamohan Kallickal2807afb2010-01-05 05:07:49 +0530574 pci_set_drvdata(pcidev, phba);
Mike Christie0e438952012-04-03 23:41:51 -0500575 phba->interface_handle = 0xFFFFFFFF;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530576
577 if (iscsi_host_add(shost, &phba->pcidev->dev))
578 goto free_devices;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530579
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530580 return phba;
581
582free_devices:
583 pci_dev_put(phba->pcidev);
584 iscsi_host_free(phba->shost);
585 return NULL;
586}
587
588static void beiscsi_unmap_pci_function(struct beiscsi_hba *phba)
589{
590 if (phba->csr_va) {
591 iounmap(phba->csr_va);
592 phba->csr_va = NULL;
593 }
594 if (phba->db_va) {
595 iounmap(phba->db_va);
596 phba->db_va = NULL;
597 }
598 if (phba->pci_va) {
599 iounmap(phba->pci_va);
600 phba->pci_va = NULL;
601 }
602}
603
604static int beiscsi_map_pci_bars(struct beiscsi_hba *phba,
605 struct pci_dev *pcidev)
606{
607 u8 __iomem *addr;
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +0530608 int pcicfg_reg;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530609
610 addr = ioremap_nocache(pci_resource_start(pcidev, 2),
611 pci_resource_len(pcidev, 2));
612 if (addr == NULL)
613 return -ENOMEM;
614 phba->ctrl.csr = addr;
615 phba->csr_va = addr;
616 phba->csr_pa.u.a64.address = pci_resource_start(pcidev, 2);
617
618 addr = ioremap_nocache(pci_resource_start(pcidev, 4), 128 * 1024);
619 if (addr == NULL)
620 goto pci_map_err;
621 phba->ctrl.db = addr;
622 phba->db_va = addr;
623 phba->db_pa.u.a64.address = pci_resource_start(pcidev, 4);
624
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +0530625 if (phba->generation == BE_GEN2)
626 pcicfg_reg = 1;
627 else
628 pcicfg_reg = 0;
629
630 addr = ioremap_nocache(pci_resource_start(pcidev, pcicfg_reg),
631 pci_resource_len(pcidev, pcicfg_reg));
632
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530633 if (addr == NULL)
634 goto pci_map_err;
635 phba->ctrl.pcicfg = addr;
636 phba->pci_va = addr;
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +0530637 phba->pci_pa.u.a64.address = pci_resource_start(pcidev, pcicfg_reg);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530638 return 0;
639
640pci_map_err:
641 beiscsi_unmap_pci_function(phba);
642 return -ENOMEM;
643}
644
645static int beiscsi_enable_pci(struct pci_dev *pcidev)
646{
647 int ret;
648
649 ret = pci_enable_device(pcidev);
650 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530651 dev_err(&pcidev->dev,
652 "beiscsi_enable_pci - enable device failed\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530653 return ret;
654 }
655
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530656 pci_set_master(pcidev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530657 if (pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64))) {
658 ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(32));
659 if (ret) {
660 dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n");
661 pci_disable_device(pcidev);
662 return ret;
663 }
664 }
665 return 0;
666}
667
668static int be_ctrl_init(struct beiscsi_hba *phba, struct pci_dev *pdev)
669{
670 struct be_ctrl_info *ctrl = &phba->ctrl;
671 struct be_dma_mem *mbox_mem_alloc = &ctrl->mbox_mem_alloced;
672 struct be_dma_mem *mbox_mem_align = &ctrl->mbox_mem;
673 int status = 0;
674
675 ctrl->pdev = pdev;
676 status = beiscsi_map_pci_bars(phba, pdev);
677 if (status)
678 return status;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530679 mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16;
680 mbox_mem_alloc->va = pci_alloc_consistent(pdev,
681 mbox_mem_alloc->size,
682 &mbox_mem_alloc->dma);
683 if (!mbox_mem_alloc->va) {
684 beiscsi_unmap_pci_function(phba);
Jayamohan Kallickala49e06d2012-04-03 23:41:44 -0500685 return -ENOMEM;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530686 }
687
688 mbox_mem_align->size = sizeof(struct be_mcc_mailbox);
689 mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16);
690 mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16);
691 memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox));
692 spin_lock_init(&ctrl->mbox_lock);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530693 spin_lock_init(&phba->ctrl.mcc_lock);
694 spin_lock_init(&phba->ctrl.mcc_cq_lock);
695
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530696 return status;
697}
698
699static void beiscsi_get_params(struct beiscsi_hba *phba)
700{
Jayamohan Kallickal7da50872010-01-05 05:04:12 +0530701 phba->params.ios_per_ctrl = (phba->fw_config.iscsi_icd_count
702 - (phba->fw_config.iscsi_cid_count
703 + BE2_TMFS
704 + BE2_NOPOUT_REQ));
705 phba->params.cxns_per_ctrl = phba->fw_config.iscsi_cid_count;
Jayamohan Kallickaled58ea22010-02-20 08:05:07 +0530706 phba->params.asyncpdus_per_ctrl = phba->fw_config.iscsi_cid_count * 2;
Justin P. Mattock6eab04a2011-04-08 19:49:08 -0700707 phba->params.icds_per_ctrl = phba->fw_config.iscsi_icd_count;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530708 phba->params.num_sge_per_io = BE2_SGE;
709 phba->params.defpdu_hdr_sz = BE2_DEFPDU_HDR_SZ;
710 phba->params.defpdu_data_sz = BE2_DEFPDU_DATA_SZ;
711 phba->params.eq_timer = 64;
712 phba->params.num_eq_entries =
Jayamohan Kallickal7da50872010-01-05 05:04:12 +0530713 (((BE2_CMDS_PER_CXN * 2 + phba->fw_config.iscsi_cid_count * 2
714 + BE2_TMFS) / 512) + 1) * 512;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530715 phba->params.num_eq_entries = (phba->params.num_eq_entries < 1024)
716 ? 1024 : phba->params.num_eq_entries;
John Soni Jose99bc5d52012-08-20 23:00:18 +0530717 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
718 "BM_%d : phba->params.num_eq_entries=%d\n",
719 phba->params.num_eq_entries);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530720 phba->params.num_cq_entries =
Jayamohan Kallickal7da50872010-01-05 05:04:12 +0530721 (((BE2_CMDS_PER_CXN * 2 + phba->fw_config.iscsi_cid_count * 2
722 + BE2_TMFS) / 512) + 1) * 512;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530723 phba->params.wrbs_per_cxn = 256;
724}
725
726static void hwi_ring_eq_db(struct beiscsi_hba *phba,
727 unsigned int id, unsigned int clr_interrupt,
728 unsigned int num_processed,
729 unsigned char rearm, unsigned char event)
730{
731 u32 val = 0;
732 val |= id & DB_EQ_RING_ID_MASK;
733 if (rearm)
734 val |= 1 << DB_EQ_REARM_SHIFT;
735 if (clr_interrupt)
736 val |= 1 << DB_EQ_CLR_SHIFT;
737 if (event)
738 val |= 1 << DB_EQ_EVNT_SHIFT;
739 val |= num_processed << DB_EQ_NUM_POPPED_SHIFT;
740 iowrite32(val, phba->db_va + DB_EQ_OFFSET);
741}
742
743/**
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530744 * be_isr_mcc - The isr routine of the driver.
745 * @irq: Not used
746 * @dev_id: Pointer to host adapter structure
747 */
748static irqreturn_t be_isr_mcc(int irq, void *dev_id)
749{
750 struct beiscsi_hba *phba;
751 struct be_eq_entry *eqe = NULL;
752 struct be_queue_info *eq;
753 struct be_queue_info *mcc;
754 unsigned int num_eq_processed;
755 struct be_eq_obj *pbe_eq;
756 unsigned long flags;
757
758 pbe_eq = dev_id;
759 eq = &pbe_eq->q;
760 phba = pbe_eq->phba;
761 mcc = &phba->ctrl.mcc_obj.cq;
762 eqe = queue_tail_node(eq);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530763
764 num_eq_processed = 0;
765
766 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
767 & EQE_VALID_MASK) {
768 if (((eqe->dw[offsetof(struct amap_eq_entry,
769 resource_id) / 32] &
770 EQE_RESID_MASK) >> 16) == mcc->id) {
771 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +0530772 pbe_eq->todo_mcc_cq = true;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530773 spin_unlock_irqrestore(&phba->isr_lock, flags);
774 }
775 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
776 queue_tail_inc(eq);
777 eqe = queue_tail_node(eq);
778 num_eq_processed++;
779 }
John Soni Jose72fb46a2012-10-20 04:42:49 +0530780 if (pbe_eq->todo_mcc_cq)
781 queue_work(phba->wq, &pbe_eq->work_cqs);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530782 if (num_eq_processed)
783 hwi_ring_eq_db(phba, eq->id, 1, num_eq_processed, 1, 1);
784
785 return IRQ_HANDLED;
786}
787
788/**
789 * be_isr_msix - The isr routine of the driver.
790 * @irq: Not used
791 * @dev_id: Pointer to host adapter structure
792 */
793static irqreturn_t be_isr_msix(int irq, void *dev_id)
794{
795 struct beiscsi_hba *phba;
796 struct be_eq_entry *eqe = NULL;
797 struct be_queue_info *eq;
798 struct be_queue_info *cq;
799 unsigned int num_eq_processed;
800 struct be_eq_obj *pbe_eq;
801 unsigned long flags;
802
803 pbe_eq = dev_id;
804 eq = &pbe_eq->q;
805 cq = pbe_eq->cq;
806 eqe = queue_tail_node(eq);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530807
808 phba = pbe_eq->phba;
809 num_eq_processed = 0;
810 if (blk_iopoll_enabled) {
811 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
812 & EQE_VALID_MASK) {
813 if (!blk_iopoll_sched_prep(&pbe_eq->iopoll))
814 blk_iopoll_sched(&pbe_eq->iopoll);
815
816 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
817 queue_tail_inc(eq);
818 eqe = queue_tail_node(eq);
819 num_eq_processed++;
820 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530821 } else {
822 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
823 & EQE_VALID_MASK) {
824 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +0530825 pbe_eq->todo_cq = true;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530826 spin_unlock_irqrestore(&phba->isr_lock, flags);
827 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
828 queue_tail_inc(eq);
829 eqe = queue_tail_node(eq);
830 num_eq_processed++;
831 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530832
John Soni Jose72fb46a2012-10-20 04:42:49 +0530833 if (pbe_eq->todo_cq)
834 queue_work(phba->wq, &pbe_eq->work_cqs);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530835 }
John Soni Jose72fb46a2012-10-20 04:42:49 +0530836
837 if (num_eq_processed)
838 hwi_ring_eq_db(phba, eq->id, 1, num_eq_processed, 0, 1);
839
840 return IRQ_HANDLED;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530841}
842
843/**
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530844 * be_isr - The isr routine of the driver.
845 * @irq: Not used
846 * @dev_id: Pointer to host adapter structure
847 */
848static irqreturn_t be_isr(int irq, void *dev_id)
849{
850 struct beiscsi_hba *phba;
851 struct hwi_controller *phwi_ctrlr;
852 struct hwi_context_memory *phwi_context;
853 struct be_eq_entry *eqe = NULL;
854 struct be_queue_info *eq;
855 struct be_queue_info *cq;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530856 struct be_queue_info *mcc;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530857 unsigned long flags, index;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530858 unsigned int num_mcceq_processed, num_ioeq_processed;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530859 struct be_ctrl_info *ctrl;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530860 struct be_eq_obj *pbe_eq;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530861 int isr;
862
863 phba = dev_id;
Justin P. Mattock6eab04a2011-04-08 19:49:08 -0700864 ctrl = &phba->ctrl;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530865 isr = ioread32(ctrl->csr + CEV_ISR0_OFFSET +
866 (PCI_FUNC(ctrl->pdev->devfn) * CEV_ISR_SIZE));
867 if (!isr)
868 return IRQ_NONE;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530869
870 phwi_ctrlr = phba->phwi_ctrlr;
871 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530872 pbe_eq = &phwi_context->be_eq[0];
873
874 eq = &phwi_context->be_eq[0].q;
875 mcc = &phba->ctrl.mcc_obj.cq;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530876 index = 0;
877 eqe = queue_tail_node(eq);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530878
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530879 num_ioeq_processed = 0;
880 num_mcceq_processed = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530881 if (blk_iopoll_enabled) {
882 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
883 & EQE_VALID_MASK) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530884 if (((eqe->dw[offsetof(struct amap_eq_entry,
885 resource_id) / 32] &
886 EQE_RESID_MASK) >> 16) == mcc->id) {
887 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +0530888 pbe_eq->todo_mcc_cq = true;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530889 spin_unlock_irqrestore(&phba->isr_lock, flags);
890 num_mcceq_processed++;
891 } else {
892 if (!blk_iopoll_sched_prep(&pbe_eq->iopoll))
893 blk_iopoll_sched(&pbe_eq->iopoll);
894 num_ioeq_processed++;
895 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530896 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
897 queue_tail_inc(eq);
898 eqe = queue_tail_node(eq);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530899 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530900 if (num_ioeq_processed || num_mcceq_processed) {
John Soni Jose72fb46a2012-10-20 04:42:49 +0530901 if (pbe_eq->todo_mcc_cq)
902 queue_work(phba->wq, &pbe_eq->work_cqs);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530903
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530904 if ((num_mcceq_processed) && (!num_ioeq_processed))
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530905 hwi_ring_eq_db(phba, eq->id, 0,
906 (num_ioeq_processed +
907 num_mcceq_processed) , 1, 1);
908 else
909 hwi_ring_eq_db(phba, eq->id, 0,
910 (num_ioeq_processed +
911 num_mcceq_processed), 0, 1);
912
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530913 return IRQ_HANDLED;
914 } else
915 return IRQ_NONE;
916 } else {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530917 cq = &phwi_context->be_cq[0];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530918 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
919 & EQE_VALID_MASK) {
920
921 if (((eqe->dw[offsetof(struct amap_eq_entry,
922 resource_id) / 32] &
923 EQE_RESID_MASK) >> 16) != cq->id) {
924 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +0530925 pbe_eq->todo_mcc_cq = true;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530926 spin_unlock_irqrestore(&phba->isr_lock, flags);
927 } else {
928 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +0530929 pbe_eq->todo_cq = true;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530930 spin_unlock_irqrestore(&phba->isr_lock, flags);
931 }
932 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
933 queue_tail_inc(eq);
934 eqe = queue_tail_node(eq);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530935 num_ioeq_processed++;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530936 }
John Soni Jose72fb46a2012-10-20 04:42:49 +0530937 if (pbe_eq->todo_cq || pbe_eq->todo_mcc_cq)
938 queue_work(phba->wq, &pbe_eq->work_cqs);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530939
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530940 if (num_ioeq_processed) {
941 hwi_ring_eq_db(phba, eq->id, 0,
942 num_ioeq_processed, 1, 1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530943 return IRQ_HANDLED;
944 } else
945 return IRQ_NONE;
946 }
947}
948
949static int beiscsi_init_irqs(struct beiscsi_hba *phba)
950{
951 struct pci_dev *pcidev = phba->pcidev;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530952 struct hwi_controller *phwi_ctrlr;
953 struct hwi_context_memory *phwi_context;
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +0530954 int ret, msix_vec, i, j;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530955
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530956 phwi_ctrlr = phba->phwi_ctrlr;
957 phwi_context = phwi_ctrlr->phwi_ctxt;
958
959 if (phba->msix_enabled) {
960 for (i = 0; i < phba->num_cpus; i++) {
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -0700961 phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME,
962 GFP_KERNEL);
963 if (!phba->msi_name[i]) {
964 ret = -ENOMEM;
965 goto free_msix_irqs;
966 }
967
968 sprintf(phba->msi_name[i], "beiscsi_%02x_%02x",
969 phba->shost->host_no, i);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530970 msix_vec = phba->msix_entries[i].vector;
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -0700971 ret = request_irq(msix_vec, be_isr_msix, 0,
972 phba->msi_name[i],
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530973 &phwi_context->be_eq[i]);
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +0530974 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530975 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
976 "BM_%d : beiscsi_init_irqs-Failed to"
977 "register msix for i = %d\n",
978 i);
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -0700979 kfree(phba->msi_name[i]);
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +0530980 goto free_msix_irqs;
981 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530982 }
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -0700983 phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME, GFP_KERNEL);
984 if (!phba->msi_name[i]) {
985 ret = -ENOMEM;
986 goto free_msix_irqs;
987 }
988 sprintf(phba->msi_name[i], "beiscsi_mcc_%02x",
989 phba->shost->host_no);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530990 msix_vec = phba->msix_entries[i].vector;
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -0700991 ret = request_irq(msix_vec, be_isr_mcc, 0, phba->msi_name[i],
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530992 &phwi_context->be_eq[i]);
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +0530993 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530994 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT ,
995 "BM_%d : beiscsi_init_irqs-"
996 "Failed to register beiscsi_msix_mcc\n");
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 }
1000
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301001 } else {
1002 ret = request_irq(pcidev->irq, be_isr, IRQF_SHARED,
1003 "beiscsi", phba);
1004 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301005 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
1006 "BM_%d : beiscsi_init_irqs-"
1007 "Failed to register irq\\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301008 return ret;
1009 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301010 }
1011 return 0;
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +05301012free_msix_irqs:
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -07001013 for (j = i - 1; j >= 0; j--) {
1014 kfree(phba->msi_name[j]);
1015 msix_vec = phba->msix_entries[j].vector;
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +05301016 free_irq(msix_vec, &phwi_context->be_eq[j]);
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -07001017 }
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +05301018 return ret;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301019}
1020
1021static void hwi_ring_cq_db(struct beiscsi_hba *phba,
1022 unsigned int id, unsigned int num_processed,
1023 unsigned char rearm, unsigned char event)
1024{
1025 u32 val = 0;
1026 val |= id & DB_CQ_RING_ID_MASK;
1027 if (rearm)
1028 val |= 1 << DB_CQ_REARM_SHIFT;
1029 val |= num_processed << DB_CQ_NUM_POPPED_SHIFT;
1030 iowrite32(val, phba->db_va + DB_CQ_OFFSET);
1031}
1032
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301033static unsigned int
1034beiscsi_process_async_pdu(struct beiscsi_conn *beiscsi_conn,
1035 struct beiscsi_hba *phba,
1036 unsigned short cid,
1037 struct pdu_base *ppdu,
1038 unsigned long pdu_len,
1039 void *pbuffer, unsigned long buf_len)
1040{
1041 struct iscsi_conn *conn = beiscsi_conn->conn;
1042 struct iscsi_session *session = conn->session;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301043 struct iscsi_task *task;
1044 struct beiscsi_io_task *io_task;
1045 struct iscsi_hdr *login_hdr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301046
1047 switch (ppdu->dw[offsetof(struct amap_pdu_base, opcode) / 32] &
1048 PDUBASE_OPCODE_MASK) {
1049 case ISCSI_OP_NOOP_IN:
1050 pbuffer = NULL;
1051 buf_len = 0;
1052 break;
1053 case ISCSI_OP_ASYNC_EVENT:
1054 break;
1055 case ISCSI_OP_REJECT:
1056 WARN_ON(!pbuffer);
1057 WARN_ON(!(buf_len == 48));
John Soni Jose99bc5d52012-08-20 23:00:18 +05301058 beiscsi_log(phba, KERN_ERR,
1059 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1060 "BM_%d : In ISCSI_OP_REJECT\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301061 break;
1062 case ISCSI_OP_LOGIN_RSP:
Jayamohan Kallickal7bd6e252010-01-05 05:07:02 +05301063 case ISCSI_OP_TEXT_RSP:
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301064 task = conn->login_task;
1065 io_task = task->dd_data;
1066 login_hdr = (struct iscsi_hdr *)ppdu;
1067 login_hdr->itt = io_task->libiscsi_itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301068 break;
1069 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +05301070 beiscsi_log(phba, KERN_WARNING,
1071 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1072 "BM_%d : Unrecognized opcode 0x%x in async msg\n",
1073 (ppdu->
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301074 dw[offsetof(struct amap_pdu_base, opcode) / 32]
John Soni Jose99bc5d52012-08-20 23:00:18 +05301075 & PDUBASE_OPCODE_MASK));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301076 return 1;
1077 }
1078
1079 spin_lock_bh(&session->lock);
1080 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)ppdu, pbuffer, buf_len);
1081 spin_unlock_bh(&session->lock);
1082 return 0;
1083}
1084
1085static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba)
1086{
1087 struct sgl_handle *psgl_handle;
1088
1089 if (phba->io_sgl_hndl_avbl) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301090 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
1091 "BM_%d : In alloc_io_sgl_handle,"
1092 " io_sgl_alloc_index=%d\n",
1093 phba->io_sgl_alloc_index);
1094
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301095 psgl_handle = phba->io_sgl_hndl_base[phba->
1096 io_sgl_alloc_index];
1097 phba->io_sgl_hndl_base[phba->io_sgl_alloc_index] = NULL;
1098 phba->io_sgl_hndl_avbl--;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301099 if (phba->io_sgl_alloc_index == (phba->params.
1100 ios_per_ctrl - 1))
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301101 phba->io_sgl_alloc_index = 0;
1102 else
1103 phba->io_sgl_alloc_index++;
1104 } else
1105 psgl_handle = NULL;
1106 return psgl_handle;
1107}
1108
1109static void
1110free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
1111{
John Soni Jose99bc5d52012-08-20 23:00:18 +05301112 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
1113 "BM_%d : In free_,io_sgl_free_index=%d\n",
1114 phba->io_sgl_free_index);
1115
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301116 if (phba->io_sgl_hndl_base[phba->io_sgl_free_index]) {
1117 /*
1118 * this can happen if clean_task is called on a task that
1119 * failed in xmit_task or alloc_pdu.
1120 */
John Soni Jose99bc5d52012-08-20 23:00:18 +05301121 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
1122 "BM_%d : Double Free in IO SGL io_sgl_free_index=%d,"
1123 "value there=%p\n", phba->io_sgl_free_index,
1124 phba->io_sgl_hndl_base
1125 [phba->io_sgl_free_index]);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301126 return;
1127 }
1128 phba->io_sgl_hndl_base[phba->io_sgl_free_index] = psgl_handle;
1129 phba->io_sgl_hndl_avbl++;
1130 if (phba->io_sgl_free_index == (phba->params.ios_per_ctrl - 1))
1131 phba->io_sgl_free_index = 0;
1132 else
1133 phba->io_sgl_free_index++;
1134}
1135
1136/**
1137 * alloc_wrb_handle - To allocate a wrb handle
1138 * @phba: The hba pointer
1139 * @cid: The cid to use for allocation
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301140 *
1141 * This happens under session_lock until submission to chip
1142 */
Jayamohan Kallickald5431482010-01-05 05:06:21 +05301143struct wrb_handle *alloc_wrb_handle(struct beiscsi_hba *phba, unsigned int cid)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301144{
1145 struct hwi_wrb_context *pwrb_context;
1146 struct hwi_controller *phwi_ctrlr;
Jayamohan Kallickald5431482010-01-05 05:06:21 +05301147 struct wrb_handle *pwrb_handle, *pwrb_handle_tmp;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301148
1149 phwi_ctrlr = phba->phwi_ctrlr;
1150 pwrb_context = &phwi_ctrlr->wrb_context[cid];
Jayamohan Kallickald5431482010-01-05 05:06:21 +05301151 if (pwrb_context->wrb_handles_available >= 2) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301152 pwrb_handle = pwrb_context->pwrb_handle_base[
1153 pwrb_context->alloc_index];
1154 pwrb_context->wrb_handles_available--;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301155 if (pwrb_context->alloc_index ==
1156 (phba->params.wrbs_per_cxn - 1))
1157 pwrb_context->alloc_index = 0;
1158 else
1159 pwrb_context->alloc_index++;
Jayamohan Kallickald5431482010-01-05 05:06:21 +05301160 pwrb_handle_tmp = pwrb_context->pwrb_handle_base[
1161 pwrb_context->alloc_index];
1162 pwrb_handle->nxt_wrb_index = pwrb_handle_tmp->wrb_index;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301163 } else
1164 pwrb_handle = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301165 return pwrb_handle;
1166}
1167
1168/**
1169 * free_wrb_handle - To free the wrb handle back to pool
1170 * @phba: The hba pointer
1171 * @pwrb_context: The context to free from
1172 * @pwrb_handle: The wrb_handle to free
1173 *
1174 * This happens under session_lock until submission to chip
1175 */
1176static void
1177free_wrb_handle(struct beiscsi_hba *phba, struct hwi_wrb_context *pwrb_context,
1178 struct wrb_handle *pwrb_handle)
1179{
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05301180 pwrb_context->pwrb_handle_base[pwrb_context->free_index] = pwrb_handle;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301181 pwrb_context->wrb_handles_available++;
1182 if (pwrb_context->free_index == (phba->params.wrbs_per_cxn - 1))
1183 pwrb_context->free_index = 0;
1184 else
1185 pwrb_context->free_index++;
1186
John Soni Jose99bc5d52012-08-20 23:00:18 +05301187 beiscsi_log(phba, KERN_INFO,
1188 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1189 "BM_%d : FREE WRB: pwrb_handle=%p free_index=0x%x"
1190 "wrb_handles_available=%d\n",
1191 pwrb_handle, pwrb_context->free_index,
1192 pwrb_context->wrb_handles_available);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301193}
1194
1195static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba)
1196{
1197 struct sgl_handle *psgl_handle;
1198
1199 if (phba->eh_sgl_hndl_avbl) {
1200 psgl_handle = phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index];
1201 phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index] = NULL;
John Soni Jose99bc5d52012-08-20 23:00:18 +05301202 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1203 "BM_%d : mgmt_sgl_alloc_index=%d=0x%x\n",
1204 phba->eh_sgl_alloc_index,
1205 phba->eh_sgl_alloc_index);
1206
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301207 phba->eh_sgl_hndl_avbl--;
1208 if (phba->eh_sgl_alloc_index ==
1209 (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl -
1210 1))
1211 phba->eh_sgl_alloc_index = 0;
1212 else
1213 phba->eh_sgl_alloc_index++;
1214 } else
1215 psgl_handle = NULL;
1216 return psgl_handle;
1217}
1218
1219void
1220free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
1221{
1222
John Soni Jose99bc5d52012-08-20 23:00:18 +05301223 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1224 "BM_%d : In free_mgmt_sgl_handle,"
1225 "eh_sgl_free_index=%d\n",
1226 phba->eh_sgl_free_index);
1227
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301228 if (phba->eh_sgl_hndl_base[phba->eh_sgl_free_index]) {
1229 /*
1230 * this can happen if clean_task is called on a task that
1231 * failed in xmit_task or alloc_pdu.
1232 */
John Soni Jose99bc5d52012-08-20 23:00:18 +05301233 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1234 "BM_%d : Double Free in eh SGL ,"
1235 "eh_sgl_free_index=%d\n",
1236 phba->eh_sgl_free_index);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301237 return;
1238 }
1239 phba->eh_sgl_hndl_base[phba->eh_sgl_free_index] = psgl_handle;
1240 phba->eh_sgl_hndl_avbl++;
1241 if (phba->eh_sgl_free_index ==
1242 (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl - 1))
1243 phba->eh_sgl_free_index = 0;
1244 else
1245 phba->eh_sgl_free_index++;
1246}
1247
1248static void
1249be_complete_io(struct beiscsi_conn *beiscsi_conn,
1250 struct iscsi_task *task, struct sol_cqe *psol)
1251{
1252 struct beiscsi_io_task *io_task = task->dd_data;
1253 struct be_status_bhs *sts_bhs =
1254 (struct be_status_bhs *)io_task->cmd_bhs;
1255 struct iscsi_conn *conn = beiscsi_conn->conn;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301256 unsigned char *sense;
1257 u32 resid = 0, exp_cmdsn, max_cmdsn;
1258 u8 rsp, status, flags;
1259
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301260 exp_cmdsn = (psol->
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301261 dw[offsetof(struct amap_sol_cqe, i_exp_cmd_sn) / 32]
1262 & SOL_EXP_CMD_SN_MASK);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301263 max_cmdsn = ((psol->
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301264 dw[offsetof(struct amap_sol_cqe, i_exp_cmd_sn) / 32]
1265 & SOL_EXP_CMD_SN_MASK) +
1266 ((psol->dw[offsetof(struct amap_sol_cqe, i_cmd_wnd)
1267 / 32] & SOL_CMD_WND_MASK) >> 24) - 1);
1268 rsp = ((psol->dw[offsetof(struct amap_sol_cqe, i_resp) / 32]
1269 & SOL_RESP_MASK) >> 16);
1270 status = ((psol->dw[offsetof(struct amap_sol_cqe, i_sts) / 32]
1271 & SOL_STS_MASK) >> 8);
1272 flags = ((psol->dw[offsetof(struct amap_sol_cqe, i_flags) / 32]
1273 & SOL_FLAGS_MASK) >> 24) | 0x80;
Jayamohan Kallickalbd535452011-10-07 19:31:10 -05001274 if (!task->sc) {
1275 if (io_task->scsi_cmnd)
1276 scsi_dma_unmap(io_task->scsi_cmnd);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301277
Jayamohan Kallickalbd535452011-10-07 19:31:10 -05001278 return;
1279 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301280 task->sc->result = (DID_OK << 16) | status;
1281 if (rsp != ISCSI_STATUS_CMD_COMPLETED) {
1282 task->sc->result = DID_ERROR << 16;
1283 goto unmap;
1284 }
1285
1286 /* bidi not initially supported */
1287 if (flags & (ISCSI_FLAG_CMD_UNDERFLOW | ISCSI_FLAG_CMD_OVERFLOW)) {
1288 resid = (psol->dw[offsetof(struct amap_sol_cqe, i_res_cnt) /
1289 32] & SOL_RES_CNT_MASK);
1290
1291 if (!status && (flags & ISCSI_FLAG_CMD_OVERFLOW))
1292 task->sc->result = DID_ERROR << 16;
1293
1294 if (flags & ISCSI_FLAG_CMD_UNDERFLOW) {
1295 scsi_set_resid(task->sc, resid);
1296 if (!status && (scsi_bufflen(task->sc) - resid <
1297 task->sc->underflow))
1298 task->sc->result = DID_ERROR << 16;
1299 }
1300 }
1301
1302 if (status == SAM_STAT_CHECK_CONDITION) {
Dan Carpenter4053a4b2011-09-26 09:23:37 +03001303 u16 sense_len;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301304 unsigned short *slen = (unsigned short *)sts_bhs->sense_info;
Dan Carpenter4053a4b2011-09-26 09:23:37 +03001305
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301306 sense = sts_bhs->sense_info + sizeof(unsigned short);
Dan Carpenter4053a4b2011-09-26 09:23:37 +03001307 sense_len = be16_to_cpu(*slen);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301308 memcpy(task->sc->sense_buffer, sense,
1309 min_t(u16, sense_len, SCSI_SENSE_BUFFERSIZE));
1310 }
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05301311
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301312 if (io_task->cmd_bhs->iscsi_hdr.flags & ISCSI_FLAG_CMD_READ) {
1313 if (psol->dw[offsetof(struct amap_sol_cqe, i_res_cnt) / 32]
1314 & SOL_RES_CNT_MASK)
1315 conn->rxdata_octets += (psol->
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301316 dw[offsetof(struct amap_sol_cqe, i_res_cnt) / 32]
1317 & SOL_RES_CNT_MASK);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301318 }
1319unmap:
1320 scsi_dma_unmap(io_task->scsi_cmnd);
1321 iscsi_complete_scsi_task(task, exp_cmdsn, max_cmdsn);
1322}
1323
1324static void
1325be_complete_logout(struct beiscsi_conn *beiscsi_conn,
1326 struct iscsi_task *task, struct sol_cqe *psol)
1327{
1328 struct iscsi_logout_rsp *hdr;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301329 struct beiscsi_io_task *io_task = task->dd_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301330 struct iscsi_conn *conn = beiscsi_conn->conn;
1331
1332 hdr = (struct iscsi_logout_rsp *)task->hdr;
Jayamohan Kallickal7bd6e252010-01-05 05:07:02 +05301333 hdr->opcode = ISCSI_OP_LOGOUT_RSP;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301334 hdr->t2wait = 5;
1335 hdr->t2retain = 0;
1336 hdr->flags = ((psol->dw[offsetof(struct amap_sol_cqe, i_flags) / 32]
1337 & SOL_FLAGS_MASK) >> 24) | 0x80;
1338 hdr->response = (psol->dw[offsetof(struct amap_sol_cqe, i_resp) /
1339 32] & SOL_RESP_MASK);
1340 hdr->exp_cmdsn = cpu_to_be32(psol->
1341 dw[offsetof(struct amap_sol_cqe, i_exp_cmd_sn) / 32]
1342 & SOL_EXP_CMD_SN_MASK);
1343 hdr->max_cmdsn = be32_to_cpu((psol->
1344 dw[offsetof(struct amap_sol_cqe, i_exp_cmd_sn) / 32]
1345 & SOL_EXP_CMD_SN_MASK) +
1346 ((psol->dw[offsetof(struct amap_sol_cqe, i_cmd_wnd)
1347 / 32] & SOL_CMD_WND_MASK) >> 24) - 1);
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,
1358 struct iscsi_task *task, struct sol_cqe *psol)
1359{
1360 struct iscsi_tm_rsp *hdr;
1361 struct iscsi_conn *conn = beiscsi_conn->conn;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301362 struct beiscsi_io_task *io_task = task->dd_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301363
1364 hdr = (struct iscsi_tm_rsp *)task->hdr;
Jayamohan Kallickal7bd6e252010-01-05 05:07:02 +05301365 hdr->opcode = ISCSI_OP_SCSI_TMFUNC_RSP;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301366 hdr->flags = ((psol->dw[offsetof(struct amap_sol_cqe, i_flags) / 32]
1367 & SOL_FLAGS_MASK) >> 24) | 0x80;
1368 hdr->response = (psol->dw[offsetof(struct amap_sol_cqe, i_resp) /
1369 32] & SOL_RESP_MASK);
1370 hdr->exp_cmdsn = cpu_to_be32(psol->dw[offsetof(struct amap_sol_cqe,
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301371 i_exp_cmd_sn) / 32] & SOL_EXP_CMD_SN_MASK);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301372 hdr->max_cmdsn = be32_to_cpu((psol->dw[offsetof(struct amap_sol_cqe,
1373 i_exp_cmd_sn) / 32] & SOL_EXP_CMD_SN_MASK) +
1374 ((psol->dw[offsetof(struct amap_sol_cqe, i_cmd_wnd)
1375 / 32] & SOL_CMD_WND_MASK) >> 24) - 1);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301376 hdr->itt = io_task->libiscsi_itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301377 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1378}
1379
1380static void
1381hwi_complete_drvr_msgs(struct beiscsi_conn *beiscsi_conn,
1382 struct beiscsi_hba *phba, struct sol_cqe *psol)
1383{
1384 struct hwi_wrb_context *pwrb_context;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301385 struct wrb_handle *pwrb_handle = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301386 struct hwi_controller *phwi_ctrlr;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301387 struct iscsi_task *task;
1388 struct beiscsi_io_task *io_task;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301389 struct iscsi_conn *conn = beiscsi_conn->conn;
1390 struct iscsi_session *session = conn->session;
1391
1392 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05301393 pwrb_context = &phwi_ctrlr->wrb_context[((psol->
Jayamohan Kallickal35e66012009-10-23 11:53:49 +05301394 dw[offsetof(struct amap_sol_cqe, cid) / 32] &
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05301395 SOL_CID_MASK) >> 6) -
1396 phba->fw_config.iscsi_cid_start];
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05301397 pwrb_handle = pwrb_context->pwrb_handle_basestd[((psol->
Jayamohan Kallickal35e66012009-10-23 11:53:49 +05301398 dw[offsetof(struct amap_sol_cqe, wrb_index) /
1399 32] & SOL_WRB_INDEX_MASK) >> 16)];
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05301400 task = pwrb_handle->pio_handle;
Jayamohan Kallickal35e66012009-10-23 11:53:49 +05301401
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301402 io_task = task->dd_data;
Mike Christie1282ab72012-04-18 03:06:00 -05001403 spin_lock_bh(&phba->mgmt_sgl_lock);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301404 free_mgmt_sgl_handle(phba, io_task->psgl_handle);
Mike Christie1282ab72012-04-18 03:06:00 -05001405 spin_unlock_bh(&phba->mgmt_sgl_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301406 spin_lock_bh(&session->lock);
1407 free_wrb_handle(phba, pwrb_context, pwrb_handle);
1408 spin_unlock_bh(&session->lock);
1409}
1410
1411static void
1412be_complete_nopin_resp(struct beiscsi_conn *beiscsi_conn,
1413 struct iscsi_task *task, struct sol_cqe *psol)
1414{
1415 struct iscsi_nopin *hdr;
1416 struct iscsi_conn *conn = beiscsi_conn->conn;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301417 struct beiscsi_io_task *io_task = task->dd_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301418
1419 hdr = (struct iscsi_nopin *)task->hdr;
1420 hdr->flags = ((psol->dw[offsetof(struct amap_sol_cqe, i_flags) / 32]
1421 & SOL_FLAGS_MASK) >> 24) | 0x80;
1422 hdr->exp_cmdsn = cpu_to_be32(psol->dw[offsetof(struct amap_sol_cqe,
1423 i_exp_cmd_sn) / 32] & SOL_EXP_CMD_SN_MASK);
1424 hdr->max_cmdsn = be32_to_cpu((psol->dw[offsetof(struct amap_sol_cqe,
1425 i_exp_cmd_sn) / 32] & SOL_EXP_CMD_SN_MASK) +
1426 ((psol->dw[offsetof(struct amap_sol_cqe, i_cmd_wnd)
1427 / 32] & SOL_CMD_WND_MASK) >> 24) - 1);
1428 hdr->opcode = ISCSI_OP_NOOP_IN;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301429 hdr->itt = io_task->libiscsi_itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301430 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1431}
1432
1433static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn,
1434 struct beiscsi_hba *phba, struct sol_cqe *psol)
1435{
1436 struct hwi_wrb_context *pwrb_context;
1437 struct wrb_handle *pwrb_handle;
1438 struct iscsi_wrb *pwrb = NULL;
1439 struct hwi_controller *phwi_ctrlr;
1440 struct iscsi_task *task;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301441 unsigned int type;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301442 struct iscsi_conn *conn = beiscsi_conn->conn;
1443 struct iscsi_session *session = conn->session;
1444
1445 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05301446 pwrb_context = &phwi_ctrlr->wrb_context[((psol->dw[offsetof
Jayamohan Kallickal35e66012009-10-23 11:53:49 +05301447 (struct amap_sol_cqe, cid) / 32]
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05301448 & SOL_CID_MASK) >> 6) -
1449 phba->fw_config.iscsi_cid_start];
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05301450 pwrb_handle = pwrb_context->pwrb_handle_basestd[((psol->
Jayamohan Kallickal35e66012009-10-23 11:53:49 +05301451 dw[offsetof(struct amap_sol_cqe, wrb_index) /
1452 32] & SOL_WRB_INDEX_MASK) >> 16)];
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05301453 task = pwrb_handle->pio_handle;
1454 pwrb = pwrb_handle->pwrb;
1455 type = (pwrb->dw[offsetof(struct amap_iscsi_wrb, type) / 32] &
1456 WRB_TYPE_MASK) >> 28;
1457
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301458 spin_lock_bh(&session->lock);
1459 switch (type) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301460 case HWH_TYPE_IO:
1461 case HWH_TYPE_IO_RD:
1462 if ((task->hdr->opcode & ISCSI_OPCODE_MASK) ==
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05301463 ISCSI_OP_NOOP_OUT)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301464 be_complete_nopin_resp(beiscsi_conn, task, psol);
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05301465 else
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301466 be_complete_io(beiscsi_conn, task, psol);
1467 break;
1468
1469 case HWH_TYPE_LOGOUT:
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05301470 if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGOUT)
1471 be_complete_logout(beiscsi_conn, task, psol);
1472 else
1473 be_complete_tmf(beiscsi_conn, task, psol);
1474
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301475 break;
1476
1477 case HWH_TYPE_LOGIN:
John Soni Jose99bc5d52012-08-20 23:00:18 +05301478 beiscsi_log(phba, KERN_ERR,
1479 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1480 "BM_%d :\t\t No HWH_TYPE_LOGIN Expected in"
1481 " hwi_complete_cmd- Solicited path\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301482 break;
1483
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301484 case HWH_TYPE_NOP:
1485 be_complete_nopin_resp(beiscsi_conn, task, psol);
1486 break;
1487
1488 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +05301489 beiscsi_log(phba, KERN_WARNING,
1490 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1491 "BM_%d : In hwi_complete_cmd, unknown type = %d"
1492 "wrb_index 0x%x CID 0x%x\n", type,
1493 ((psol->dw[offsetof(struct amap_iscsi_wrb,
1494 type) / 32] & SOL_WRB_INDEX_MASK) >> 16),
1495 ((psol->dw[offsetof(struct amap_sol_cqe,
1496 cid) / 32] & SOL_CID_MASK) >> 6));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301497 break;
1498 }
Jayamohan Kallickal35e66012009-10-23 11:53:49 +05301499
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301500 spin_unlock_bh(&session->lock);
1501}
1502
1503static struct list_head *hwi_get_async_busy_list(struct hwi_async_pdu_context
1504 *pasync_ctx, unsigned int is_header,
1505 unsigned int host_write_ptr)
1506{
1507 if (is_header)
1508 return &pasync_ctx->async_entry[host_write_ptr].
1509 header_busy_list;
1510 else
1511 return &pasync_ctx->async_entry[host_write_ptr].data_busy_list;
1512}
1513
1514static struct async_pdu_handle *
1515hwi_get_async_handle(struct beiscsi_hba *phba,
1516 struct beiscsi_conn *beiscsi_conn,
1517 struct hwi_async_pdu_context *pasync_ctx,
1518 struct i_t_dpdu_cqe *pdpdu_cqe, unsigned int *pcq_index)
1519{
1520 struct be_bus_address phys_addr;
1521 struct list_head *pbusy_list;
1522 struct async_pdu_handle *pasync_handle = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301523 unsigned char is_header = 0;
1524
1525 phys_addr.u.a32.address_lo =
1526 pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, db_addr_lo) / 32] -
1527 ((pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, dpl) / 32]
1528 & PDUCQE_DPL_MASK) >> 16);
1529 phys_addr.u.a32.address_hi =
1530 pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, db_addr_hi) / 32];
1531
1532 phys_addr.u.a64.address =
1533 *((unsigned long long *)(&phys_addr.u.a64.address));
1534
1535 switch (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, code) / 32]
1536 & PDUCQE_CODE_MASK) {
1537 case UNSOL_HDR_NOTIFY:
1538 is_header = 1;
1539
1540 pbusy_list = hwi_get_async_busy_list(pasync_ctx, 1,
1541 (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
1542 index) / 32] & PDUCQE_INDEX_MASK));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301543 break;
1544 case UNSOL_DATA_NOTIFY:
1545 pbusy_list = hwi_get_async_busy_list(pasync_ctx, 0, (pdpdu_cqe->
1546 dw[offsetof(struct amap_i_t_dpdu_cqe,
1547 index) / 32] & PDUCQE_INDEX_MASK));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301548 break;
1549 default:
1550 pbusy_list = NULL;
John Soni Jose99bc5d52012-08-20 23:00:18 +05301551 beiscsi_log(phba, KERN_WARNING,
1552 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1553 "BM_%d : Unexpected code=%d\n",
1554 pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
1555 code) / 32] & PDUCQE_CODE_MASK);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301556 return NULL;
1557 }
1558
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301559 WARN_ON(list_empty(pbusy_list));
1560 list_for_each_entry(pasync_handle, pbusy_list, link) {
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05001561 if (pasync_handle->pa.u.a64.address == phys_addr.u.a64.address)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301562 break;
1563 }
1564
1565 WARN_ON(!pasync_handle);
1566
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05301567 pasync_handle->cri = (unsigned short)beiscsi_conn->beiscsi_conn_cid -
1568 phba->fw_config.iscsi_cid_start;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301569 pasync_handle->is_header = is_header;
1570 pasync_handle->buffer_len = ((pdpdu_cqe->
1571 dw[offsetof(struct amap_i_t_dpdu_cqe, dpl) / 32]
1572 & PDUCQE_DPL_MASK) >> 16);
1573
1574 *pcq_index = (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
1575 index) / 32] & PDUCQE_INDEX_MASK);
1576 return pasync_handle;
1577}
1578
1579static unsigned int
John Soni Jose99bc5d52012-08-20 23:00:18 +05301580hwi_update_async_writables(struct beiscsi_hba *phba,
1581 struct hwi_async_pdu_context *pasync_ctx,
1582 unsigned int is_header, unsigned int cq_index)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301583{
1584 struct list_head *pbusy_list;
1585 struct async_pdu_handle *pasync_handle;
1586 unsigned int num_entries, writables = 0;
1587 unsigned int *pep_read_ptr, *pwritables;
1588
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05001589 num_entries = pasync_ctx->num_entries;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301590 if (is_header) {
1591 pep_read_ptr = &pasync_ctx->async_header.ep_read_ptr;
1592 pwritables = &pasync_ctx->async_header.writables;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301593 } else {
1594 pep_read_ptr = &pasync_ctx->async_data.ep_read_ptr;
1595 pwritables = &pasync_ctx->async_data.writables;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301596 }
1597
1598 while ((*pep_read_ptr) != cq_index) {
1599 (*pep_read_ptr)++;
1600 *pep_read_ptr = (*pep_read_ptr) % num_entries;
1601
1602 pbusy_list = hwi_get_async_busy_list(pasync_ctx, is_header,
1603 *pep_read_ptr);
1604 if (writables == 0)
1605 WARN_ON(list_empty(pbusy_list));
1606
1607 if (!list_empty(pbusy_list)) {
1608 pasync_handle = list_entry(pbusy_list->next,
1609 struct async_pdu_handle,
1610 link);
1611 WARN_ON(!pasync_handle);
1612 pasync_handle->consumed = 1;
1613 }
1614
1615 writables++;
1616 }
1617
1618 if (!writables) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301619 beiscsi_log(phba, KERN_ERR,
1620 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1621 "BM_%d : Duplicate notification received - index 0x%x!!\n",
1622 cq_index);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301623 WARN_ON(1);
1624 }
1625
1626 *pwritables = *pwritables + writables;
1627 return 0;
1628}
1629
Jayamohan Kallickal9728d8d2012-04-03 23:41:47 -05001630static void hwi_free_async_msg(struct beiscsi_hba *phba,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301631 unsigned int cri)
1632{
1633 struct hwi_controller *phwi_ctrlr;
1634 struct hwi_async_pdu_context *pasync_ctx;
1635 struct async_pdu_handle *pasync_handle, *tmp_handle;
1636 struct list_head *plist;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301637
1638 phwi_ctrlr = phba->phwi_ctrlr;
1639 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
1640
1641 plist = &pasync_ctx->async_entry[cri].wait_queue.list;
1642
1643 list_for_each_entry_safe(pasync_handle, tmp_handle, plist, link) {
1644 list_del(&pasync_handle->link);
1645
Jayamohan Kallickal9728d8d2012-04-03 23:41:47 -05001646 if (pasync_handle->is_header) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301647 list_add_tail(&pasync_handle->link,
1648 &pasync_ctx->async_header.free_list);
1649 pasync_ctx->async_header.free_entries++;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301650 } else {
1651 list_add_tail(&pasync_handle->link,
1652 &pasync_ctx->async_data.free_list);
1653 pasync_ctx->async_data.free_entries++;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301654 }
1655 }
1656
1657 INIT_LIST_HEAD(&pasync_ctx->async_entry[cri].wait_queue.list);
1658 pasync_ctx->async_entry[cri].wait_queue.hdr_received = 0;
1659 pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301660}
1661
1662static struct phys_addr *
1663hwi_get_ring_address(struct hwi_async_pdu_context *pasync_ctx,
1664 unsigned int is_header, unsigned int host_write_ptr)
1665{
1666 struct phys_addr *pasync_sge = NULL;
1667
1668 if (is_header)
1669 pasync_sge = pasync_ctx->async_header.ring_base;
1670 else
1671 pasync_sge = pasync_ctx->async_data.ring_base;
1672
1673 return pasync_sge + host_write_ptr;
1674}
1675
1676static void hwi_post_async_buffers(struct beiscsi_hba *phba,
1677 unsigned int is_header)
1678{
1679 struct hwi_controller *phwi_ctrlr;
1680 struct hwi_async_pdu_context *pasync_ctx;
1681 struct async_pdu_handle *pasync_handle;
1682 struct list_head *pfree_link, *pbusy_list;
1683 struct phys_addr *pasync_sge;
1684 unsigned int ring_id, num_entries;
1685 unsigned int host_write_num;
1686 unsigned int writables;
1687 unsigned int i = 0;
1688 u32 doorbell = 0;
1689
1690 phwi_ctrlr = phba->phwi_ctrlr;
1691 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05001692 num_entries = pasync_ctx->num_entries;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301693
1694 if (is_header) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301695 writables = min(pasync_ctx->async_header.writables,
1696 pasync_ctx->async_header.free_entries);
1697 pfree_link = pasync_ctx->async_header.free_list.next;
1698 host_write_num = pasync_ctx->async_header.host_write_ptr;
1699 ring_id = phwi_ctrlr->default_pdu_hdr.id;
1700 } else {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301701 writables = min(pasync_ctx->async_data.writables,
1702 pasync_ctx->async_data.free_entries);
1703 pfree_link = pasync_ctx->async_data.free_list.next;
1704 host_write_num = pasync_ctx->async_data.host_write_ptr;
1705 ring_id = phwi_ctrlr->default_pdu_data.id;
1706 }
1707
1708 writables = (writables / 8) * 8;
1709 if (writables) {
1710 for (i = 0; i < writables; i++) {
1711 pbusy_list =
1712 hwi_get_async_busy_list(pasync_ctx, is_header,
1713 host_write_num);
1714 pasync_handle =
1715 list_entry(pfree_link, struct async_pdu_handle,
1716 link);
1717 WARN_ON(!pasync_handle);
1718 pasync_handle->consumed = 0;
1719
1720 pfree_link = pfree_link->next;
1721
1722 pasync_sge = hwi_get_ring_address(pasync_ctx,
1723 is_header, host_write_num);
1724
1725 pasync_sge->hi = pasync_handle->pa.u.a32.address_lo;
1726 pasync_sge->lo = pasync_handle->pa.u.a32.address_hi;
1727
1728 list_move(&pasync_handle->link, pbusy_list);
1729
1730 host_write_num++;
1731 host_write_num = host_write_num % num_entries;
1732 }
1733
1734 if (is_header) {
1735 pasync_ctx->async_header.host_write_ptr =
1736 host_write_num;
1737 pasync_ctx->async_header.free_entries -= writables;
1738 pasync_ctx->async_header.writables -= writables;
1739 pasync_ctx->async_header.busy_entries += writables;
1740 } else {
1741 pasync_ctx->async_data.host_write_ptr = host_write_num;
1742 pasync_ctx->async_data.free_entries -= writables;
1743 pasync_ctx->async_data.writables -= writables;
1744 pasync_ctx->async_data.busy_entries += writables;
1745 }
1746
1747 doorbell |= ring_id & DB_DEF_PDU_RING_ID_MASK;
1748 doorbell |= 1 << DB_DEF_PDU_REARM_SHIFT;
1749 doorbell |= 0 << DB_DEF_PDU_EVENT_SHIFT;
1750 doorbell |= (writables & DB_DEF_PDU_CQPROC_MASK)
1751 << DB_DEF_PDU_CQPROC_SHIFT;
1752
1753 iowrite32(doorbell, phba->db_va + DB_RXULP0_OFFSET);
1754 }
1755}
1756
1757static void hwi_flush_default_pdu_buffer(struct beiscsi_hba *phba,
1758 struct beiscsi_conn *beiscsi_conn,
1759 struct i_t_dpdu_cqe *pdpdu_cqe)
1760{
1761 struct hwi_controller *phwi_ctrlr;
1762 struct hwi_async_pdu_context *pasync_ctx;
1763 struct async_pdu_handle *pasync_handle = NULL;
1764 unsigned int cq_index = -1;
1765
1766 phwi_ctrlr = phba->phwi_ctrlr;
1767 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
1768
1769 pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
1770 pdpdu_cqe, &cq_index);
1771 BUG_ON(pasync_handle->is_header != 0);
1772 if (pasync_handle->consumed == 0)
John Soni Jose99bc5d52012-08-20 23:00:18 +05301773 hwi_update_async_writables(phba, pasync_ctx,
1774 pasync_handle->is_header, cq_index);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301775
1776 hwi_free_async_msg(phba, pasync_handle->cri);
1777 hwi_post_async_buffers(phba, pasync_handle->is_header);
1778}
1779
1780static unsigned int
1781hwi_fwd_async_msg(struct beiscsi_conn *beiscsi_conn,
1782 struct beiscsi_hba *phba,
1783 struct hwi_async_pdu_context *pasync_ctx, unsigned short cri)
1784{
1785 struct list_head *plist;
1786 struct async_pdu_handle *pasync_handle;
1787 void *phdr = NULL;
1788 unsigned int hdr_len = 0, buf_len = 0;
1789 unsigned int status, index = 0, offset = 0;
1790 void *pfirst_buffer = NULL;
1791 unsigned int num_buf = 0;
1792
1793 plist = &pasync_ctx->async_entry[cri].wait_queue.list;
1794
1795 list_for_each_entry(pasync_handle, plist, link) {
1796 if (index == 0) {
1797 phdr = pasync_handle->pbuffer;
1798 hdr_len = pasync_handle->buffer_len;
1799 } else {
1800 buf_len = pasync_handle->buffer_len;
1801 if (!num_buf) {
1802 pfirst_buffer = pasync_handle->pbuffer;
1803 num_buf++;
1804 }
1805 memcpy(pfirst_buffer + offset,
1806 pasync_handle->pbuffer, buf_len);
Jayamohan Kallickalf2ba02b2012-04-03 23:41:37 -05001807 offset += buf_len;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301808 }
1809 index++;
1810 }
1811
1812 status = beiscsi_process_async_pdu(beiscsi_conn, phba,
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05301813 (beiscsi_conn->beiscsi_conn_cid -
1814 phba->fw_config.iscsi_cid_start),
1815 phdr, hdr_len, pfirst_buffer,
Jayamohan Kallickalf2ba02b2012-04-03 23:41:37 -05001816 offset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301817
Jayamohan Kallickal605c6cd2012-04-03 23:41:48 -05001818 hwi_free_async_msg(phba, cri);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301819 return 0;
1820}
1821
1822static unsigned int
1823hwi_gather_async_pdu(struct beiscsi_conn *beiscsi_conn,
1824 struct beiscsi_hba *phba,
1825 struct async_pdu_handle *pasync_handle)
1826{
1827 struct hwi_async_pdu_context *pasync_ctx;
1828 struct hwi_controller *phwi_ctrlr;
1829 unsigned int bytes_needed = 0, status = 0;
1830 unsigned short cri = pasync_handle->cri;
1831 struct pdu_base *ppdu;
1832
1833 phwi_ctrlr = phba->phwi_ctrlr;
1834 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
1835
1836 list_del(&pasync_handle->link);
1837 if (pasync_handle->is_header) {
1838 pasync_ctx->async_header.busy_entries--;
1839 if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) {
1840 hwi_free_async_msg(phba, cri);
1841 BUG();
1842 }
1843
1844 pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0;
1845 pasync_ctx->async_entry[cri].wait_queue.hdr_received = 1;
1846 pasync_ctx->async_entry[cri].wait_queue.hdr_len =
1847 (unsigned short)pasync_handle->buffer_len;
1848 list_add_tail(&pasync_handle->link,
1849 &pasync_ctx->async_entry[cri].wait_queue.list);
1850
1851 ppdu = pasync_handle->pbuffer;
1852 bytes_needed = ((((ppdu->dw[offsetof(struct amap_pdu_base,
1853 data_len_hi) / 32] & PDUBASE_DATALENHI_MASK) << 8) &
1854 0xFFFF0000) | ((be16_to_cpu((ppdu->
1855 dw[offsetof(struct amap_pdu_base, data_len_lo) / 32]
1856 & PDUBASE_DATALENLO_MASK) >> 16)) & 0x0000FFFF));
1857
1858 if (status == 0) {
1859 pasync_ctx->async_entry[cri].wait_queue.bytes_needed =
1860 bytes_needed;
1861
1862 if (bytes_needed == 0)
1863 status = hwi_fwd_async_msg(beiscsi_conn, phba,
1864 pasync_ctx, cri);
1865 }
1866 } else {
1867 pasync_ctx->async_data.busy_entries--;
1868 if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) {
1869 list_add_tail(&pasync_handle->link,
1870 &pasync_ctx->async_entry[cri].wait_queue.
1871 list);
1872 pasync_ctx->async_entry[cri].wait_queue.
1873 bytes_received +=
1874 (unsigned short)pasync_handle->buffer_len;
1875
1876 if (pasync_ctx->async_entry[cri].wait_queue.
1877 bytes_received >=
1878 pasync_ctx->async_entry[cri].wait_queue.
1879 bytes_needed)
1880 status = hwi_fwd_async_msg(beiscsi_conn, phba,
1881 pasync_ctx, cri);
1882 }
1883 }
1884 return status;
1885}
1886
1887static void hwi_process_default_pdu_ring(struct beiscsi_conn *beiscsi_conn,
1888 struct beiscsi_hba *phba,
1889 struct i_t_dpdu_cqe *pdpdu_cqe)
1890{
1891 struct hwi_controller *phwi_ctrlr;
1892 struct hwi_async_pdu_context *pasync_ctx;
1893 struct async_pdu_handle *pasync_handle = NULL;
1894 unsigned int cq_index = -1;
1895
1896 phwi_ctrlr = phba->phwi_ctrlr;
1897 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr);
1898 pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
1899 pdpdu_cqe, &cq_index);
1900
1901 if (pasync_handle->consumed == 0)
John Soni Jose99bc5d52012-08-20 23:00:18 +05301902 hwi_update_async_writables(phba, pasync_ctx,
1903 pasync_handle->is_header, cq_index);
1904
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301905 hwi_gather_async_pdu(beiscsi_conn, phba, pasync_handle);
1906 hwi_post_async_buffers(phba, pasync_handle->is_header);
1907}
1908
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05301909static void beiscsi_process_mcc_isr(struct beiscsi_hba *phba)
1910{
1911 struct be_queue_info *mcc_cq;
1912 struct be_mcc_compl *mcc_compl;
1913 unsigned int num_processed = 0;
1914
1915 mcc_cq = &phba->ctrl.mcc_obj.cq;
1916 mcc_compl = queue_tail_node(mcc_cq);
1917 mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
1918 while (mcc_compl->flags & CQE_FLAGS_VALID_MASK) {
1919
1920 if (num_processed >= 32) {
1921 hwi_ring_cq_db(phba, mcc_cq->id,
1922 num_processed, 0, 0);
1923 num_processed = 0;
1924 }
1925 if (mcc_compl->flags & CQE_FLAGS_ASYNC_MASK) {
1926 /* Interpret flags as an async trailer */
1927 if (is_link_state_evt(mcc_compl->flags))
1928 /* Interpret compl as a async link evt */
1929 beiscsi_async_link_state_process(phba,
1930 (struct be_async_event_link_state *) mcc_compl);
1931 else
John Soni Jose99bc5d52012-08-20 23:00:18 +05301932 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_MBOX,
1933 "BM_%d : Unsupported Async Event, flags"
1934 " = 0x%08x\n",
1935 mcc_compl->flags);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05301936 } else if (mcc_compl->flags & CQE_FLAGS_COMPLETED_MASK) {
1937 be_mcc_compl_process_isr(&phba->ctrl, mcc_compl);
1938 atomic_dec(&phba->ctrl.mcc_obj.q.used);
1939 }
1940
1941 mcc_compl->flags = 0;
1942 queue_tail_inc(mcc_cq);
1943 mcc_compl = queue_tail_node(mcc_cq);
1944 mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
1945 num_processed++;
1946 }
1947
1948 if (num_processed > 0)
1949 hwi_ring_cq_db(phba, mcc_cq->id, num_processed, 1, 0);
1950
1951}
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301952
John Soni Jose6763daa2012-10-20 04:41:45 +05301953/**
1954 * beiscsi_process_cq()- Process the Completion Queue
1955 * @pbe_eq: Event Q on which the Completion has come
1956 *
1957 * return
1958 * Number of Completion Entries processed.
1959 **/
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301960static unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301961{
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301962 struct be_queue_info *cq;
1963 struct sol_cqe *sol;
1964 struct dmsg_cqe *dmsg;
1965 unsigned int num_processed = 0;
1966 unsigned int tot_nump = 0;
John Soni Jose0a513dd2012-08-20 23:00:55 +05301967 unsigned short code = 0, cid = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301968 struct beiscsi_conn *beiscsi_conn;
Jayamohan Kallickalc2462282010-01-05 05:05:34 +05301969 struct beiscsi_endpoint *beiscsi_ep;
1970 struct iscsi_endpoint *ep;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301971 struct beiscsi_hba *phba;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301972
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301973 cq = pbe_eq->cq;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301974 sol = queue_tail_node(cq);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301975 phba = pbe_eq->phba;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301976
1977 while (sol->dw[offsetof(struct amap_sol_cqe, valid) / 32] &
1978 CQE_VALID_MASK) {
1979 be_dws_le_to_cpu(sol, sizeof(struct sol_cqe));
1980
John Soni Jose0a513dd2012-08-20 23:00:55 +05301981 cid = ((sol->dw[offsetof(struct amap_sol_cqe, cid)/32] &
1982 CQE_CID_MASK) >> 6);
1983 code = (sol->dw[offsetof(struct amap_sol_cqe, code)/32] &
1984 CQE_CODE_MASK);
1985 ep = phba->ep_array[cid - phba->fw_config.iscsi_cid_start];
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05301986
Jayamohan Kallickalc2462282010-01-05 05:05:34 +05301987 beiscsi_ep = ep->dd_data;
1988 beiscsi_conn = beiscsi_ep->conn;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05301989
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301990 if (num_processed >= 32) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301991 hwi_ring_cq_db(phba, cq->id,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301992 num_processed, 0, 0);
1993 tot_nump += num_processed;
1994 num_processed = 0;
1995 }
1996
John Soni Jose0a513dd2012-08-20 23:00:55 +05301997 switch (code) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301998 case SOL_CMD_COMPLETE:
1999 hwi_complete_cmd(beiscsi_conn, phba, sol);
2000 break;
2001 case DRIVERMSG_NOTIFY:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302002 beiscsi_log(phba, KERN_INFO,
2003 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302004 "BM_%d : Received %s[%d] on CID : %d\n",
2005 cqe_desc[code], code, cid);
John Soni Jose99bc5d52012-08-20 23:00:18 +05302006
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302007 dmsg = (struct dmsg_cqe *)sol;
2008 hwi_complete_drvr_msgs(beiscsi_conn, phba, sol);
2009 break;
2010 case UNSOL_HDR_NOTIFY:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302011 beiscsi_log(phba, KERN_INFO,
2012 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302013 "BM_%d : Received %s[%d] on CID : %d\n",
2014 cqe_desc[code], code, cid);
John Soni Jose99bc5d52012-08-20 23:00:18 +05302015
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302016 hwi_process_default_pdu_ring(beiscsi_conn, phba,
2017 (struct i_t_dpdu_cqe *)sol);
2018 break;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302019 case UNSOL_DATA_NOTIFY:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302020 beiscsi_log(phba, KERN_INFO,
2021 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
John Soni Jose6763daa2012-10-20 04:41:45 +05302022 "BM_%d : Received %s[%d] on CID : %d\n",
2023 cqe_desc[code], code, cid);
John Soni Jose99bc5d52012-08-20 23:00:18 +05302024
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302025 hwi_process_default_pdu_ring(beiscsi_conn, phba,
2026 (struct i_t_dpdu_cqe *)sol);
2027 break;
2028 case CXN_INVALIDATE_INDEX_NOTIFY:
2029 case CMD_INVALIDATED_NOTIFY:
2030 case CXN_INVALIDATE_NOTIFY:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302031 beiscsi_log(phba, KERN_ERR,
2032 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302033 "BM_%d : Ignoring %s[%d] on CID : %d\n",
2034 cqe_desc[code], code, cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302035 break;
2036 case SOL_CMD_KILLED_DATA_DIGEST_ERR:
2037 case CMD_KILLED_INVALID_STATSN_RCVD:
2038 case CMD_KILLED_INVALID_R2T_RCVD:
2039 case CMD_CXN_KILLED_LUN_INVALID:
2040 case CMD_CXN_KILLED_ICD_INVALID:
2041 case CMD_CXN_KILLED_ITT_INVALID:
2042 case CMD_CXN_KILLED_SEQ_OUTOFORDER:
2043 case CMD_CXN_KILLED_INVALID_DATASN_RCVD:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302044 beiscsi_log(phba, KERN_ERR,
2045 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
John Soni Jose6763daa2012-10-20 04:41:45 +05302046 "BM_%d : Cmd Notification %s[%d] on CID : %d\n",
2047 cqe_desc[code], code, cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302048 break;
2049 case UNSOL_DATA_DIGEST_ERROR_NOTIFY:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302050 beiscsi_log(phba, KERN_ERR,
2051 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302052 "BM_%d : Dropping %s[%d] on DPDU ring on CID : %d\n",
2053 cqe_desc[code], code, cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302054 hwi_flush_default_pdu_buffer(phba, beiscsi_conn,
2055 (struct i_t_dpdu_cqe *) sol);
2056 break;
2057 case CXN_KILLED_PDU_SIZE_EXCEEDS_DSL:
2058 case CXN_KILLED_BURST_LEN_MISMATCH:
2059 case CXN_KILLED_AHS_RCVD:
2060 case CXN_KILLED_HDR_DIGEST_ERR:
2061 case CXN_KILLED_UNKNOWN_HDR:
2062 case CXN_KILLED_STALE_ITT_TTT_RCVD:
2063 case CXN_KILLED_INVALID_ITT_TTT_RCVD:
2064 case CXN_KILLED_TIMED_OUT:
2065 case CXN_KILLED_FIN_RCVD:
John Soni Jose6763daa2012-10-20 04:41:45 +05302066 case CXN_KILLED_RST_SENT:
2067 case CXN_KILLED_RST_RCVD:
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302068 case CXN_KILLED_BAD_UNSOL_PDU_RCVD:
2069 case CXN_KILLED_BAD_WRB_INDEX_ERROR:
2070 case CXN_KILLED_OVER_RUN_RESIDUAL:
2071 case CXN_KILLED_UNDER_RUN_RESIDUAL:
2072 case CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302073 beiscsi_log(phba, KERN_ERR,
2074 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302075 "BM_%d : Event %s[%d] received on CID : %d\n",
2076 cqe_desc[code], code, cid);
John Soni Jose0a513dd2012-08-20 23:00:55 +05302077 if (beiscsi_conn)
2078 iscsi_conn_failure(beiscsi_conn->conn,
2079 ISCSI_ERR_CONN_FAILED);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302080 break;
2081 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302082 beiscsi_log(phba, KERN_ERR,
2083 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302084 "BM_%d : Invalid CQE Event Received Code : %d"
2085 "CID 0x%x...\n",
John Soni Jose0a513dd2012-08-20 23:00:55 +05302086 code, cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302087 break;
2088 }
2089
2090 AMAP_SET_BITS(struct amap_sol_cqe, valid, sol, 0);
2091 queue_tail_inc(cq);
2092 sol = queue_tail_node(cq);
2093 num_processed++;
2094 }
2095
2096 if (num_processed > 0) {
2097 tot_nump += num_processed;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302098 hwi_ring_cq_db(phba, cq->id, num_processed, 1, 0);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302099 }
2100 return tot_nump;
2101}
2102
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05302103void beiscsi_process_all_cqs(struct work_struct *work)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302104{
2105 unsigned long flags;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302106 struct hwi_controller *phwi_ctrlr;
2107 struct hwi_context_memory *phwi_context;
John Soni Jose72fb46a2012-10-20 04:42:49 +05302108 struct beiscsi_hba *phba;
2109 struct be_eq_obj *pbe_eq =
2110 container_of(work, struct be_eq_obj, work_cqs);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302111
John Soni Jose72fb46a2012-10-20 04:42:49 +05302112 phba = pbe_eq->phba;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302113 phwi_ctrlr = phba->phwi_ctrlr;
2114 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302115
John Soni Jose72fb46a2012-10-20 04:42:49 +05302116 if (pbe_eq->todo_mcc_cq) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302117 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +05302118 pbe_eq->todo_mcc_cq = false;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302119 spin_unlock_irqrestore(&phba->isr_lock, flags);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05302120 beiscsi_process_mcc_isr(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302121 }
2122
John Soni Jose72fb46a2012-10-20 04:42:49 +05302123 if (pbe_eq->todo_cq) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302124 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +05302125 pbe_eq->todo_cq = false;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302126 spin_unlock_irqrestore(&phba->isr_lock, flags);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302127 beiscsi_process_cq(pbe_eq);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302128 }
John Soni Jose72fb46a2012-10-20 04:42:49 +05302129
2130 /* rearm EQ for further interrupts */
2131 hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302132}
2133
2134static int be_iopoll(struct blk_iopoll *iop, int budget)
2135{
2136 static unsigned int ret;
2137 struct beiscsi_hba *phba;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302138 struct be_eq_obj *pbe_eq;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302139
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302140 pbe_eq = container_of(iop, struct be_eq_obj, iopoll);
2141 ret = beiscsi_process_cq(pbe_eq);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302142 if (ret < budget) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302143 phba = pbe_eq->phba;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302144 blk_iopoll_complete(iop);
John Soni Jose99bc5d52012-08-20 23:00:18 +05302145 beiscsi_log(phba, KERN_INFO,
2146 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
2147 "BM_%d : rearm pbe_eq->q.id =%d\n",
2148 pbe_eq->q.id);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302149 hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302150 }
2151 return ret;
2152}
2153
2154static void
2155hwi_write_sgl(struct iscsi_wrb *pwrb, struct scatterlist *sg,
2156 unsigned int num_sg, struct beiscsi_io_task *io_task)
2157{
2158 struct iscsi_sge *psgl;
Jayamohan Kallickal58ff4bd2010-10-06 23:46:47 +05302159 unsigned int sg_len, index;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302160 unsigned int sge_len = 0;
2161 unsigned long long addr;
2162 struct scatterlist *l_sg;
2163 unsigned int offset;
2164
2165 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
2166 io_task->bhs_pa.u.a32.address_lo);
2167 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
2168 io_task->bhs_pa.u.a32.address_hi);
2169
2170 l_sg = sg;
Jayamohan Kallickal48bd86c2010-01-07 01:50:19 +05302171 for (index = 0; (index < num_sg) && (index < 2); index++,
2172 sg = sg_next(sg)) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302173 if (index == 0) {
2174 sg_len = sg_dma_len(sg);
2175 addr = (u64) sg_dma_address(sg);
2176 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302177 ((u32)(addr & 0xFFFFFFFF)));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302178 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302179 ((u32)(addr >> 32)));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302180 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
2181 sg_len);
2182 sge_len = sg_len;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302183 } else {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302184 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_r2t_offset,
2185 pwrb, sge_len);
2186 sg_len = sg_dma_len(sg);
2187 addr = (u64) sg_dma_address(sg);
2188 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_lo, pwrb,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302189 ((u32)(addr & 0xFFFFFFFF)));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302190 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_hi, pwrb,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302191 ((u32)(addr >> 32)));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302192 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_len, pwrb,
2193 sg_len);
2194 }
2195 }
2196 psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
2197 memset(psgl, 0, sizeof(*psgl) * BE2_SGE);
2198
2199 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2);
2200
2201 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2202 io_task->bhs_pa.u.a32.address_hi);
2203 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2204 io_task->bhs_pa.u.a32.address_lo);
2205
Jayamohan Kallickalcaf818f2010-01-23 05:38:18 +05302206 if (num_sg == 1) {
2207 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
2208 1);
2209 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
2210 0);
2211 } else if (num_sg == 2) {
2212 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
2213 0);
2214 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
2215 1);
2216 } else {
2217 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
2218 0);
2219 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
2220 0);
2221 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302222 sg = l_sg;
2223 psgl++;
2224 psgl++;
2225 offset = 0;
Jayamohan Kallickal48bd86c2010-01-07 01:50:19 +05302226 for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302227 sg_len = sg_dma_len(sg);
2228 addr = (u64) sg_dma_address(sg);
2229 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2230 (addr & 0xFFFFFFFF));
2231 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2232 (addr >> 32));
2233 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len);
2234 AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset);
2235 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
2236 offset += sg_len;
2237 }
2238 psgl--;
2239 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
2240}
2241
John Soni Josed629c472012-10-20 04:42:00 +05302242/**
2243 * hwi_write_buffer()- Populate the WRB with task info
2244 * @pwrb: ptr to the WRB entry
2245 * @task: iscsi task which is to be executed
2246 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302247static void hwi_write_buffer(struct iscsi_wrb *pwrb, struct iscsi_task *task)
2248{
2249 struct iscsi_sge *psgl;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302250 struct beiscsi_io_task *io_task = task->dd_data;
2251 struct beiscsi_conn *beiscsi_conn = io_task->conn;
2252 struct beiscsi_hba *phba = beiscsi_conn->phba;
2253
2254 io_task->bhs_len = sizeof(struct be_nonio_bhs) - 2;
2255 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
2256 io_task->bhs_pa.u.a32.address_lo);
2257 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
2258 io_task->bhs_pa.u.a32.address_hi);
2259
2260 if (task->data) {
2261 if (task->data_count) {
2262 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1);
John Soni Josed629c472012-10-20 04:42:00 +05302263 io_task->mtask_addr = pci_map_single(phba->pcidev,
2264 task->data,
2265 task->data_count,
2266 PCI_DMA_TODEVICE);
2267
2268 io_task->mtask_data_count = task->data_count;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302269 } else {
2270 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
John Soni Josed629c472012-10-20 04:42:00 +05302271 io_task->mtask_addr = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302272 }
2273 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
John Soni Josed629c472012-10-20 04:42:00 +05302274 lower_32_bits(io_task->mtask_addr));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302275 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
John Soni Josed629c472012-10-20 04:42:00 +05302276 upper_32_bits(io_task->mtask_addr));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302277 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
2278 task->data_count);
2279
2280 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, 1);
2281 } else {
2282 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
John Soni Josed629c472012-10-20 04:42:00 +05302283 io_task->mtask_addr = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302284 }
2285
2286 psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
2287
2288 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len);
2289
2290 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2291 io_task->bhs_pa.u.a32.address_hi);
2292 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2293 io_task->bhs_pa.u.a32.address_lo);
2294 if (task->data) {
2295 psgl++;
2296 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, 0);
2297 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, 0);
2298 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0);
2299 AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, 0);
2300 AMAP_SET_BITS(struct amap_iscsi_sge, rsvd0, psgl, 0);
2301 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
2302
2303 psgl++;
2304 if (task->data) {
2305 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
John Soni Josed629c472012-10-20 04:42:00 +05302306 lower_32_bits(io_task->mtask_addr));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302307 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
John Soni Josed629c472012-10-20 04:42:00 +05302308 upper_32_bits(io_task->mtask_addr));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302309 }
2310 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0x106);
2311 }
2312 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
2313}
2314
2315static void beiscsi_find_mem_req(struct beiscsi_hba *phba)
2316{
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302317 unsigned int num_cq_pages, num_async_pdu_buf_pages;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302318 unsigned int num_async_pdu_data_pages, wrb_sz_per_cxn;
2319 unsigned int num_async_pdu_buf_sgl_pages, num_async_pdu_data_sgl_pages;
2320
2321 num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
2322 sizeof(struct sol_cqe));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302323 num_async_pdu_buf_pages =
2324 PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
2325 phba->params.defpdu_hdr_sz);
2326 num_async_pdu_buf_sgl_pages =
2327 PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
2328 sizeof(struct phys_addr));
2329 num_async_pdu_data_pages =
2330 PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
2331 phba->params.defpdu_data_sz);
2332 num_async_pdu_data_sgl_pages =
2333 PAGES_REQUIRED(phba->params.asyncpdus_per_ctrl * \
2334 sizeof(struct phys_addr));
2335
2336 phba->params.hwi_ws_sz = sizeof(struct hwi_controller);
2337
2338 phba->mem_req[ISCSI_MEM_GLOBAL_HEADER] = 2 *
2339 BE_ISCSI_PDU_HEADER_SIZE;
2340 phba->mem_req[HWI_MEM_ADDN_CONTEXT] =
2341 sizeof(struct hwi_context_memory);
2342
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302343
2344 phba->mem_req[HWI_MEM_WRB] = sizeof(struct iscsi_wrb)
2345 * (phba->params.wrbs_per_cxn)
2346 * phba->params.cxns_per_ctrl;
2347 wrb_sz_per_cxn = sizeof(struct wrb_handle) *
2348 (phba->params.wrbs_per_cxn);
2349 phba->mem_req[HWI_MEM_WRBH] = roundup_pow_of_two((wrb_sz_per_cxn) *
2350 phba->params.cxns_per_ctrl);
2351
2352 phba->mem_req[HWI_MEM_SGLH] = sizeof(struct sgl_handle) *
2353 phba->params.icds_per_ctrl;
2354 phba->mem_req[HWI_MEM_SGE] = sizeof(struct iscsi_sge) *
2355 phba->params.num_sge_per_io * phba->params.icds_per_ctrl;
2356
2357 phba->mem_req[HWI_MEM_ASYNC_HEADER_BUF] =
2358 num_async_pdu_buf_pages * PAGE_SIZE;
2359 phba->mem_req[HWI_MEM_ASYNC_DATA_BUF] =
2360 num_async_pdu_data_pages * PAGE_SIZE;
2361 phba->mem_req[HWI_MEM_ASYNC_HEADER_RING] =
2362 num_async_pdu_buf_sgl_pages * PAGE_SIZE;
2363 phba->mem_req[HWI_MEM_ASYNC_DATA_RING] =
2364 num_async_pdu_data_sgl_pages * PAGE_SIZE;
2365 phba->mem_req[HWI_MEM_ASYNC_HEADER_HANDLE] =
2366 phba->params.asyncpdus_per_ctrl *
2367 sizeof(struct async_pdu_handle);
2368 phba->mem_req[HWI_MEM_ASYNC_DATA_HANDLE] =
2369 phba->params.asyncpdus_per_ctrl *
2370 sizeof(struct async_pdu_handle);
2371 phba->mem_req[HWI_MEM_ASYNC_PDU_CONTEXT] =
2372 sizeof(struct hwi_async_pdu_context) +
2373 (phba->params.cxns_per_ctrl * sizeof(struct hwi_async_entry));
2374}
2375
2376static int beiscsi_alloc_mem(struct beiscsi_hba *phba)
2377{
2378 struct be_mem_descriptor *mem_descr;
2379 dma_addr_t bus_add;
2380 struct mem_array *mem_arr, *mem_arr_orig;
2381 unsigned int i, j, alloc_size, curr_alloc_size;
2382
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002383 phba->phwi_ctrlr = kzalloc(phba->params.hwi_ws_sz, GFP_KERNEL);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302384 if (!phba->phwi_ctrlr)
2385 return -ENOMEM;
2386
2387 phba->init_mem = kcalloc(SE_MEM_MAX, sizeof(*mem_descr),
2388 GFP_KERNEL);
2389 if (!phba->init_mem) {
2390 kfree(phba->phwi_ctrlr);
2391 return -ENOMEM;
2392 }
2393
2394 mem_arr_orig = kmalloc(sizeof(*mem_arr_orig) * BEISCSI_MAX_FRAGS_INIT,
2395 GFP_KERNEL);
2396 if (!mem_arr_orig) {
2397 kfree(phba->init_mem);
2398 kfree(phba->phwi_ctrlr);
2399 return -ENOMEM;
2400 }
2401
2402 mem_descr = phba->init_mem;
2403 for (i = 0; i < SE_MEM_MAX; i++) {
2404 j = 0;
2405 mem_arr = mem_arr_orig;
2406 alloc_size = phba->mem_req[i];
2407 memset(mem_arr, 0, sizeof(struct mem_array) *
2408 BEISCSI_MAX_FRAGS_INIT);
2409 curr_alloc_size = min(be_max_phys_size * 1024, alloc_size);
2410 do {
2411 mem_arr->virtual_address = pci_alloc_consistent(
2412 phba->pcidev,
2413 curr_alloc_size,
2414 &bus_add);
2415 if (!mem_arr->virtual_address) {
2416 if (curr_alloc_size <= BE_MIN_MEM_SIZE)
2417 goto free_mem;
2418 if (curr_alloc_size -
2419 rounddown_pow_of_two(curr_alloc_size))
2420 curr_alloc_size = rounddown_pow_of_two
2421 (curr_alloc_size);
2422 else
2423 curr_alloc_size = curr_alloc_size / 2;
2424 } else {
2425 mem_arr->bus_address.u.
2426 a64.address = (__u64) bus_add;
2427 mem_arr->size = curr_alloc_size;
2428 alloc_size -= curr_alloc_size;
2429 curr_alloc_size = min(be_max_phys_size *
2430 1024, alloc_size);
2431 j++;
2432 mem_arr++;
2433 }
2434 } while (alloc_size);
2435 mem_descr->num_elements = j;
2436 mem_descr->size_in_bytes = phba->mem_req[i];
2437 mem_descr->mem_array = kmalloc(sizeof(*mem_arr) * j,
2438 GFP_KERNEL);
2439 if (!mem_descr->mem_array)
2440 goto free_mem;
2441
2442 memcpy(mem_descr->mem_array, mem_arr_orig,
2443 sizeof(struct mem_array) * j);
2444 mem_descr++;
2445 }
2446 kfree(mem_arr_orig);
2447 return 0;
2448free_mem:
2449 mem_descr->num_elements = j;
2450 while ((i) || (j)) {
2451 for (j = mem_descr->num_elements; j > 0; j--) {
2452 pci_free_consistent(phba->pcidev,
2453 mem_descr->mem_array[j - 1].size,
2454 mem_descr->mem_array[j - 1].
2455 virtual_address,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302456 (unsigned long)mem_descr->
2457 mem_array[j - 1].
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302458 bus_address.u.a64.address);
2459 }
2460 if (i) {
2461 i--;
2462 kfree(mem_descr->mem_array);
2463 mem_descr--;
2464 }
2465 }
2466 kfree(mem_arr_orig);
2467 kfree(phba->init_mem);
2468 kfree(phba->phwi_ctrlr);
2469 return -ENOMEM;
2470}
2471
2472static int beiscsi_get_memory(struct beiscsi_hba *phba)
2473{
2474 beiscsi_find_mem_req(phba);
2475 return beiscsi_alloc_mem(phba);
2476}
2477
2478static void iscsi_init_global_templates(struct beiscsi_hba *phba)
2479{
2480 struct pdu_data_out *pdata_out;
2481 struct pdu_nop_out *pnop_out;
2482 struct be_mem_descriptor *mem_descr;
2483
2484 mem_descr = phba->init_mem;
2485 mem_descr += ISCSI_MEM_GLOBAL_HEADER;
2486 pdata_out =
2487 (struct pdu_data_out *)mem_descr->mem_array[0].virtual_address;
2488 memset(pdata_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
2489
2490 AMAP_SET_BITS(struct amap_pdu_data_out, opcode, pdata_out,
2491 IIOC_SCSI_DATA);
2492
2493 pnop_out =
2494 (struct pdu_nop_out *)((unsigned char *)mem_descr->mem_array[0].
2495 virtual_address + BE_ISCSI_PDU_HEADER_SIZE);
2496
2497 memset(pnop_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
2498 AMAP_SET_BITS(struct amap_pdu_nop_out, ttt, pnop_out, 0xFFFFFFFF);
2499 AMAP_SET_BITS(struct amap_pdu_nop_out, f_bit, pnop_out, 1);
2500 AMAP_SET_BITS(struct amap_pdu_nop_out, i_bit, pnop_out, 0);
2501}
2502
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002503static int beiscsi_init_wrb_handle(struct beiscsi_hba *phba)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302504{
2505 struct be_mem_descriptor *mem_descr_wrbh, *mem_descr_wrb;
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002506 struct wrb_handle *pwrb_handle = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302507 struct hwi_controller *phwi_ctrlr;
2508 struct hwi_wrb_context *pwrb_context;
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002509 struct iscsi_wrb *pwrb = NULL;
2510 unsigned int num_cxn_wrbh = 0;
2511 unsigned int num_cxn_wrb = 0, j, idx = 0, index;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302512
2513 mem_descr_wrbh = phba->init_mem;
2514 mem_descr_wrbh += HWI_MEM_WRBH;
2515
2516 mem_descr_wrb = phba->init_mem;
2517 mem_descr_wrb += HWI_MEM_WRB;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302518 phwi_ctrlr = phba->phwi_ctrlr;
2519
2520 for (index = 0; index < phba->params.cxns_per_ctrl * 2; index += 2) {
2521 pwrb_context = &phwi_ctrlr->wrb_context[index];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302522 pwrb_context->pwrb_handle_base =
2523 kzalloc(sizeof(struct wrb_handle *) *
2524 phba->params.wrbs_per_cxn, GFP_KERNEL);
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002525 if (!pwrb_context->pwrb_handle_base) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05302526 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2527 "BM_%d : Mem Alloc Failed. Failing to load\n");
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002528 goto init_wrb_hndl_failed;
2529 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302530 pwrb_context->pwrb_handle_basestd =
2531 kzalloc(sizeof(struct wrb_handle *) *
2532 phba->params.wrbs_per_cxn, GFP_KERNEL);
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002533 if (!pwrb_context->pwrb_handle_basestd) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05302534 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2535 "BM_%d : Mem Alloc Failed. Failing to load\n");
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002536 goto init_wrb_hndl_failed;
2537 }
2538 if (!num_cxn_wrbh) {
2539 pwrb_handle =
2540 mem_descr_wrbh->mem_array[idx].virtual_address;
2541 num_cxn_wrbh = ((mem_descr_wrbh->mem_array[idx].size) /
2542 ((sizeof(struct wrb_handle)) *
2543 phba->params.wrbs_per_cxn));
2544 idx++;
2545 }
2546 pwrb_context->alloc_index = 0;
2547 pwrb_context->wrb_handles_available = 0;
2548 pwrb_context->free_index = 0;
2549
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302550 if (num_cxn_wrbh) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302551 for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
2552 pwrb_context->pwrb_handle_base[j] = pwrb_handle;
2553 pwrb_context->pwrb_handle_basestd[j] =
2554 pwrb_handle;
2555 pwrb_context->wrb_handles_available++;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302556 pwrb_handle->wrb_index = j;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302557 pwrb_handle++;
2558 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302559 num_cxn_wrbh--;
2560 }
2561 }
2562 idx = 0;
Jayamohan Kallickaled58ea22010-02-20 08:05:07 +05302563 for (index = 0; index < phba->params.cxns_per_ctrl * 2; index += 2) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302564 pwrb_context = &phwi_ctrlr->wrb_context[index];
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002565 if (!num_cxn_wrb) {
2566 pwrb = mem_descr_wrb->mem_array[idx].virtual_address;
2567 num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) /
2568 ((sizeof(struct iscsi_wrb) *
2569 phba->params.wrbs_per_cxn));
2570 idx++;
2571 }
2572
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302573 if (num_cxn_wrb) {
2574 for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
2575 pwrb_handle = pwrb_context->pwrb_handle_base[j];
2576 pwrb_handle->pwrb = pwrb;
2577 pwrb++;
2578 }
2579 num_cxn_wrb--;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302580 }
2581 }
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002582 return 0;
2583init_wrb_hndl_failed:
2584 for (j = index; j > 0; j--) {
2585 pwrb_context = &phwi_ctrlr->wrb_context[j];
2586 kfree(pwrb_context->pwrb_handle_base);
2587 kfree(pwrb_context->pwrb_handle_basestd);
2588 }
2589 return -ENOMEM;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302590}
2591
2592static void hwi_init_async_pdu_ctx(struct beiscsi_hba *phba)
2593{
2594 struct hwi_controller *phwi_ctrlr;
2595 struct hba_parameters *p = &phba->params;
2596 struct hwi_async_pdu_context *pasync_ctx;
2597 struct async_pdu_handle *pasync_header_h, *pasync_data_h;
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05002598 unsigned int index, idx, num_per_mem, num_async_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302599 struct be_mem_descriptor *mem_descr;
2600
2601 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2602 mem_descr += HWI_MEM_ASYNC_PDU_CONTEXT;
2603
2604 phwi_ctrlr = phba->phwi_ctrlr;
2605 phwi_ctrlr->phwi_ctxt->pasync_ctx = (struct hwi_async_pdu_context *)
2606 mem_descr->mem_array[0].virtual_address;
2607 pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx;
2608 memset(pasync_ctx, 0, sizeof(*pasync_ctx));
2609
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05002610 pasync_ctx->num_entries = p->asyncpdus_per_ctrl;
2611 pasync_ctx->buffer_size = p->defpdu_hdr_sz;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302612
2613 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2614 mem_descr += HWI_MEM_ASYNC_HEADER_BUF;
2615 if (mem_descr->mem_array[0].virtual_address) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05302616 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2617 "BM_%d : hwi_init_async_pdu_ctx"
2618 " HWI_MEM_ASYNC_HEADER_BUF va=%p\n",
2619 mem_descr->mem_array[0].virtual_address);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302620 } else
John Soni Jose99bc5d52012-08-20 23:00:18 +05302621 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
2622 "BM_%d : No Virtual address\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302623
2624 pasync_ctx->async_header.va_base =
2625 mem_descr->mem_array[0].virtual_address;
2626
2627 pasync_ctx->async_header.pa_base.u.a64.address =
2628 mem_descr->mem_array[0].bus_address.u.a64.address;
2629
2630 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2631 mem_descr += HWI_MEM_ASYNC_HEADER_RING;
2632 if (mem_descr->mem_array[0].virtual_address) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05302633 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2634 "BM_%d : hwi_init_async_pdu_ctx"
2635 " HWI_MEM_ASYNC_HEADER_RING va=%p\n",
2636 mem_descr->mem_array[0].virtual_address);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302637 } else
John Soni Jose99bc5d52012-08-20 23:00:18 +05302638 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
2639 "BM_%d : No Virtual address\n");
2640
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302641 pasync_ctx->async_header.ring_base =
2642 mem_descr->mem_array[0].virtual_address;
2643
2644 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2645 mem_descr += HWI_MEM_ASYNC_HEADER_HANDLE;
2646 if (mem_descr->mem_array[0].virtual_address) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05302647 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2648 "BM_%d : hwi_init_async_pdu_ctx"
2649 " HWI_MEM_ASYNC_HEADER_HANDLE va=%p\n",
2650 mem_descr->mem_array[0].virtual_address);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302651 } else
John Soni Jose99bc5d52012-08-20 23:00:18 +05302652 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
2653 "BM_%d : No Virtual address\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302654
2655 pasync_ctx->async_header.handle_base =
2656 mem_descr->mem_array[0].virtual_address;
2657 pasync_ctx->async_header.writables = 0;
2658 INIT_LIST_HEAD(&pasync_ctx->async_header.free_list);
2659
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302660
2661 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2662 mem_descr += HWI_MEM_ASYNC_DATA_RING;
2663 if (mem_descr->mem_array[0].virtual_address) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05302664 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2665 "BM_%d : hwi_init_async_pdu_ctx"
2666 " HWI_MEM_ASYNC_DATA_RING va=%p\n",
2667 mem_descr->mem_array[0].virtual_address);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302668 } else
John Soni Jose99bc5d52012-08-20 23:00:18 +05302669 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
2670 "BM_%d : No Virtual address\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302671
2672 pasync_ctx->async_data.ring_base =
2673 mem_descr->mem_array[0].virtual_address;
2674
2675 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2676 mem_descr += HWI_MEM_ASYNC_DATA_HANDLE;
2677 if (!mem_descr->mem_array[0].virtual_address)
John Soni Jose99bc5d52012-08-20 23:00:18 +05302678 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
2679 "BM_%d : No Virtual address\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302680
2681 pasync_ctx->async_data.handle_base =
2682 mem_descr->mem_array[0].virtual_address;
2683 pasync_ctx->async_data.writables = 0;
2684 INIT_LIST_HEAD(&pasync_ctx->async_data.free_list);
2685
2686 pasync_header_h =
2687 (struct async_pdu_handle *)pasync_ctx->async_header.handle_base;
2688 pasync_data_h =
2689 (struct async_pdu_handle *)pasync_ctx->async_data.handle_base;
2690
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05002691 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2692 mem_descr += HWI_MEM_ASYNC_DATA_BUF;
2693 if (mem_descr->mem_array[0].virtual_address) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05302694 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2695 "BM_%d : hwi_init_async_pdu_ctx"
2696 " HWI_MEM_ASYNC_DATA_BUF va=%p\n",
2697 mem_descr->mem_array[0].virtual_address);
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05002698 } else
John Soni Jose99bc5d52012-08-20 23:00:18 +05302699 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
2700 "BM_%d : No Virtual address\n");
2701
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05002702 idx = 0;
2703 pasync_ctx->async_data.va_base =
2704 mem_descr->mem_array[idx].virtual_address;
2705 pasync_ctx->async_data.pa_base.u.a64.address =
2706 mem_descr->mem_array[idx].bus_address.u.a64.address;
2707
2708 num_async_data = ((mem_descr->mem_array[idx].size) /
2709 phba->params.defpdu_data_sz);
2710 num_per_mem = 0;
2711
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302712 for (index = 0; index < p->asyncpdus_per_ctrl; index++) {
2713 pasync_header_h->cri = -1;
2714 pasync_header_h->index = (char)index;
2715 INIT_LIST_HEAD(&pasync_header_h->link);
2716 pasync_header_h->pbuffer =
2717 (void *)((unsigned long)
2718 (pasync_ctx->async_header.va_base) +
2719 (p->defpdu_hdr_sz * index));
2720
2721 pasync_header_h->pa.u.a64.address =
2722 pasync_ctx->async_header.pa_base.u.a64.address +
2723 (p->defpdu_hdr_sz * index);
2724
2725 list_add_tail(&pasync_header_h->link,
2726 &pasync_ctx->async_header.free_list);
2727 pasync_header_h++;
2728 pasync_ctx->async_header.free_entries++;
2729 pasync_ctx->async_header.writables++;
2730
2731 INIT_LIST_HEAD(&pasync_ctx->async_entry[index].wait_queue.list);
2732 INIT_LIST_HEAD(&pasync_ctx->async_entry[index].
2733 header_busy_list);
2734 pasync_data_h->cri = -1;
2735 pasync_data_h->index = (char)index;
2736 INIT_LIST_HEAD(&pasync_data_h->link);
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05002737
2738 if (!num_async_data) {
2739 num_per_mem = 0;
2740 idx++;
2741 pasync_ctx->async_data.va_base =
2742 mem_descr->mem_array[idx].virtual_address;
2743 pasync_ctx->async_data.pa_base.u.a64.address =
2744 mem_descr->mem_array[idx].
2745 bus_address.u.a64.address;
2746
2747 num_async_data = ((mem_descr->mem_array[idx].size) /
2748 phba->params.defpdu_data_sz);
2749 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302750 pasync_data_h->pbuffer =
2751 (void *)((unsigned long)
2752 (pasync_ctx->async_data.va_base) +
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05002753 (p->defpdu_data_sz * num_per_mem));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302754
2755 pasync_data_h->pa.u.a64.address =
2756 pasync_ctx->async_data.pa_base.u.a64.address +
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05002757 (p->defpdu_data_sz * num_per_mem);
2758 num_per_mem++;
2759 num_async_data--;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302760
2761 list_add_tail(&pasync_data_h->link,
2762 &pasync_ctx->async_data.free_list);
2763 pasync_data_h++;
2764 pasync_ctx->async_data.free_entries++;
2765 pasync_ctx->async_data.writables++;
2766
2767 INIT_LIST_HEAD(&pasync_ctx->async_entry[index].data_busy_list);
2768 }
2769
2770 pasync_ctx->async_header.host_write_ptr = 0;
2771 pasync_ctx->async_header.ep_read_ptr = -1;
2772 pasync_ctx->async_data.host_write_ptr = 0;
2773 pasync_ctx->async_data.ep_read_ptr = -1;
2774}
2775
2776static int
2777be_sgl_create_contiguous(void *virtual_address,
2778 u64 physical_address, u32 length,
2779 struct be_dma_mem *sgl)
2780{
2781 WARN_ON(!virtual_address);
2782 WARN_ON(!physical_address);
2783 WARN_ON(!length > 0);
2784 WARN_ON(!sgl);
2785
2786 sgl->va = virtual_address;
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302787 sgl->dma = (unsigned long)physical_address;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302788 sgl->size = length;
2789
2790 return 0;
2791}
2792
2793static void be_sgl_destroy_contiguous(struct be_dma_mem *sgl)
2794{
2795 memset(sgl, 0, sizeof(*sgl));
2796}
2797
2798static void
2799hwi_build_be_sgl_arr(struct beiscsi_hba *phba,
2800 struct mem_array *pmem, struct be_dma_mem *sgl)
2801{
2802 if (sgl->va)
2803 be_sgl_destroy_contiguous(sgl);
2804
2805 be_sgl_create_contiguous(pmem->virtual_address,
2806 pmem->bus_address.u.a64.address,
2807 pmem->size, sgl);
2808}
2809
2810static void
2811hwi_build_be_sgl_by_offset(struct beiscsi_hba *phba,
2812 struct mem_array *pmem, struct be_dma_mem *sgl)
2813{
2814 if (sgl->va)
2815 be_sgl_destroy_contiguous(sgl);
2816
2817 be_sgl_create_contiguous((unsigned char *)pmem->virtual_address,
2818 pmem->bus_address.u.a64.address,
2819 pmem->size, sgl);
2820}
2821
2822static int be_fill_queue(struct be_queue_info *q,
2823 u16 len, u16 entry_size, void *vaddress)
2824{
2825 struct be_dma_mem *mem = &q->dma_mem;
2826
2827 memset(q, 0, sizeof(*q));
2828 q->len = len;
2829 q->entry_size = entry_size;
2830 mem->size = len * entry_size;
2831 mem->va = vaddress;
2832 if (!mem->va)
2833 return -ENOMEM;
2834 memset(mem->va, 0, mem->size);
2835 return 0;
2836}
2837
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302838static int beiscsi_create_eqs(struct beiscsi_hba *phba,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302839 struct hwi_context_memory *phwi_context)
2840{
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302841 unsigned int i, num_eq_pages;
John Soni Jose99bc5d52012-08-20 23:00:18 +05302842 int ret = 0, eq_for_mcc;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302843 struct be_queue_info *eq;
2844 struct be_dma_mem *mem;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302845 void *eq_vaddress;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302846 dma_addr_t paddr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302847
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302848 num_eq_pages = PAGES_REQUIRED(phba->params.num_eq_entries * \
2849 sizeof(struct be_eq_entry));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302850
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302851 if (phba->msix_enabled)
2852 eq_for_mcc = 1;
2853 else
2854 eq_for_mcc = 0;
2855 for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
2856 eq = &phwi_context->be_eq[i].q;
2857 mem = &eq->dma_mem;
2858 phwi_context->be_eq[i].phba = phba;
2859 eq_vaddress = pci_alloc_consistent(phba->pcidev,
2860 num_eq_pages * PAGE_SIZE,
2861 &paddr);
2862 if (!eq_vaddress)
2863 goto create_eq_error;
2864
2865 mem->va = eq_vaddress;
2866 ret = be_fill_queue(eq, phba->params.num_eq_entries,
2867 sizeof(struct be_eq_entry), eq_vaddress);
2868 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05302869 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2870 "BM_%d : be_fill_queue Failed for EQ\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302871 goto create_eq_error;
2872 }
2873
2874 mem->dma = paddr;
2875 ret = beiscsi_cmd_eq_create(&phba->ctrl, eq,
2876 phwi_context->cur_eqd);
2877 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05302878 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2879 "BM_%d : beiscsi_cmd_eq_create"
2880 "Failed for EQ\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302881 goto create_eq_error;
2882 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05302883
2884 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2885 "BM_%d : eqid = %d\n",
2886 phwi_context->be_eq[i].q.id);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302887 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302888 return 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302889create_eq_error:
John Soni Jose107dfcb2012-10-20 04:42:13 +05302890 for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302891 eq = &phwi_context->be_eq[i].q;
2892 mem = &eq->dma_mem;
2893 if (mem->va)
2894 pci_free_consistent(phba->pcidev, num_eq_pages
2895 * PAGE_SIZE,
2896 mem->va, mem->dma);
2897 }
2898 return ret;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302899}
2900
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302901static int beiscsi_create_cqs(struct beiscsi_hba *phba,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302902 struct hwi_context_memory *phwi_context)
2903{
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302904 unsigned int i, num_cq_pages;
John Soni Jose99bc5d52012-08-20 23:00:18 +05302905 int ret = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302906 struct be_queue_info *cq, *eq;
2907 struct be_dma_mem *mem;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302908 struct be_eq_obj *pbe_eq;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302909 void *cq_vaddress;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302910 dma_addr_t paddr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302911
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302912 num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
2913 sizeof(struct sol_cqe));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302914
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302915 for (i = 0; i < phba->num_cpus; i++) {
2916 cq = &phwi_context->be_cq[i];
2917 eq = &phwi_context->be_eq[i].q;
2918 pbe_eq = &phwi_context->be_eq[i];
2919 pbe_eq->cq = cq;
2920 pbe_eq->phba = phba;
2921 mem = &cq->dma_mem;
2922 cq_vaddress = pci_alloc_consistent(phba->pcidev,
2923 num_cq_pages * PAGE_SIZE,
2924 &paddr);
2925 if (!cq_vaddress)
2926 goto create_cq_error;
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05302927 ret = be_fill_queue(cq, phba->params.num_cq_entries,
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302928 sizeof(struct sol_cqe), cq_vaddress);
2929 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05302930 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2931 "BM_%d : be_fill_queue Failed "
2932 "for ISCSI CQ\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302933 goto create_cq_error;
2934 }
2935
2936 mem->dma = paddr;
2937 ret = beiscsi_cmd_cq_create(&phba->ctrl, cq, eq, false,
2938 false, 0);
2939 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05302940 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2941 "BM_%d : beiscsi_cmd_eq_create"
2942 "Failed for ISCSI CQ\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302943 goto create_cq_error;
2944 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05302945 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2946 "BM_%d : iscsi cq_id is %d for eq_id %d\n"
2947 "iSCSI CQ CREATED\n", cq->id, eq->id);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302948 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302949 return 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302950
2951create_cq_error:
2952 for (i = 0; i < phba->num_cpus; i++) {
2953 cq = &phwi_context->be_cq[i];
2954 mem = &cq->dma_mem;
2955 if (mem->va)
2956 pci_free_consistent(phba->pcidev, num_cq_pages
2957 * PAGE_SIZE,
2958 mem->va, mem->dma);
2959 }
2960 return ret;
2961
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302962}
2963
2964static int
2965beiscsi_create_def_hdr(struct beiscsi_hba *phba,
2966 struct hwi_context_memory *phwi_context,
2967 struct hwi_controller *phwi_ctrlr,
2968 unsigned int def_pdu_ring_sz)
2969{
2970 unsigned int idx;
2971 int ret;
2972 struct be_queue_info *dq, *cq;
2973 struct be_dma_mem *mem;
2974 struct be_mem_descriptor *mem_descr;
2975 void *dq_vaddress;
2976
2977 idx = 0;
2978 dq = &phwi_context->be_def_hdrq;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302979 cq = &phwi_context->be_cq[0];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302980 mem = &dq->dma_mem;
2981 mem_descr = phba->init_mem;
2982 mem_descr += HWI_MEM_ASYNC_HEADER_RING;
2983 dq_vaddress = mem_descr->mem_array[idx].virtual_address;
2984 ret = be_fill_queue(dq, mem_descr->mem_array[0].size /
2985 sizeof(struct phys_addr),
2986 sizeof(struct phys_addr), dq_vaddress);
2987 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05302988 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2989 "BM_%d : be_fill_queue Failed for DEF PDU HDR\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302990 return ret;
2991 }
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302992 mem->dma = (unsigned long)mem_descr->mem_array[idx].
2993 bus_address.u.a64.address;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302994 ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dq,
2995 def_pdu_ring_sz,
2996 phba->params.defpdu_hdr_sz);
2997 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05302998 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2999 "BM_%d : be_cmd_create_default_pdu_queue Failed DEFHDR\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303000 return ret;
3001 }
3002 phwi_ctrlr->default_pdu_hdr.id = phwi_context->be_def_hdrq.id;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303003 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3004 "BM_%d : iscsi def pdu id is %d\n",
3005 phwi_context->be_def_hdrq.id);
3006
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303007 hwi_post_async_buffers(phba, 1);
3008 return 0;
3009}
3010
3011static int
3012beiscsi_create_def_data(struct beiscsi_hba *phba,
3013 struct hwi_context_memory *phwi_context,
3014 struct hwi_controller *phwi_ctrlr,
3015 unsigned int def_pdu_ring_sz)
3016{
3017 unsigned int idx;
3018 int ret;
3019 struct be_queue_info *dataq, *cq;
3020 struct be_dma_mem *mem;
3021 struct be_mem_descriptor *mem_descr;
3022 void *dq_vaddress;
3023
3024 idx = 0;
3025 dataq = &phwi_context->be_def_dataq;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303026 cq = &phwi_context->be_cq[0];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303027 mem = &dataq->dma_mem;
3028 mem_descr = phba->init_mem;
3029 mem_descr += HWI_MEM_ASYNC_DATA_RING;
3030 dq_vaddress = mem_descr->mem_array[idx].virtual_address;
3031 ret = be_fill_queue(dataq, mem_descr->mem_array[0].size /
3032 sizeof(struct phys_addr),
3033 sizeof(struct phys_addr), dq_vaddress);
3034 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303035 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3036 "BM_%d : be_fill_queue Failed for DEF PDU DATA\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303037 return ret;
3038 }
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05303039 mem->dma = (unsigned long)mem_descr->mem_array[idx].
3040 bus_address.u.a64.address;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303041 ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dataq,
3042 def_pdu_ring_sz,
3043 phba->params.defpdu_data_sz);
3044 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303045 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3046 "BM_%d be_cmd_create_default_pdu_queue"
3047 " Failed for DEF PDU DATA\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303048 return ret;
3049 }
3050 phwi_ctrlr->default_pdu_data.id = phwi_context->be_def_dataq.id;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303051 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3052 "BM_%d : iscsi def data id is %d\n",
3053 phwi_context->be_def_dataq.id);
3054
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303055 hwi_post_async_buffers(phba, 0);
John Soni Jose99bc5d52012-08-20 23:00:18 +05303056 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3057 "BM_%d : DEFAULT PDU DATA RING CREATED\n");
3058
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303059 return 0;
3060}
3061
3062static int
3063beiscsi_post_pages(struct beiscsi_hba *phba)
3064{
3065 struct be_mem_descriptor *mem_descr;
3066 struct mem_array *pm_arr;
3067 unsigned int page_offset, i;
3068 struct be_dma_mem sgl;
3069 int status;
3070
3071 mem_descr = phba->init_mem;
3072 mem_descr += HWI_MEM_SGE;
3073 pm_arr = mem_descr->mem_array;
3074
3075 page_offset = (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io *
3076 phba->fw_config.iscsi_icd_start) / PAGE_SIZE;
3077 for (i = 0; i < mem_descr->num_elements; i++) {
3078 hwi_build_be_sgl_arr(phba, pm_arr, &sgl);
3079 status = be_cmd_iscsi_post_sgl_pages(&phba->ctrl, &sgl,
3080 page_offset,
3081 (pm_arr->size / PAGE_SIZE));
3082 page_offset += pm_arr->size / PAGE_SIZE;
3083 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303084 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3085 "BM_%d : post sgl failed.\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303086 return status;
3087 }
3088 pm_arr++;
3089 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05303090 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3091 "BM_%d : POSTED PAGES\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303092 return 0;
3093}
3094
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303095static void be_queue_free(struct beiscsi_hba *phba, struct be_queue_info *q)
3096{
3097 struct be_dma_mem *mem = &q->dma_mem;
Jayamohan Kallickalc8b25592012-04-03 23:41:42 -05003098 if (mem->va) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303099 pci_free_consistent(phba->pcidev, mem->size,
3100 mem->va, mem->dma);
Jayamohan Kallickalc8b25592012-04-03 23:41:42 -05003101 mem->va = NULL;
3102 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303103}
3104
3105static int be_queue_alloc(struct beiscsi_hba *phba, struct be_queue_info *q,
3106 u16 len, u16 entry_size)
3107{
3108 struct be_dma_mem *mem = &q->dma_mem;
3109
3110 memset(q, 0, sizeof(*q));
3111 q->len = len;
3112 q->entry_size = entry_size;
3113 mem->size = len * entry_size;
3114 mem->va = pci_alloc_consistent(phba->pcidev, mem->size, &mem->dma);
3115 if (!mem->va)
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +05303116 return -ENOMEM;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303117 memset(mem->va, 0, mem->size);
3118 return 0;
3119}
3120
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303121static int
3122beiscsi_create_wrb_rings(struct beiscsi_hba *phba,
3123 struct hwi_context_memory *phwi_context,
3124 struct hwi_controller *phwi_ctrlr)
3125{
3126 unsigned int wrb_mem_index, offset, size, num_wrb_rings;
3127 u64 pa_addr_lo;
3128 unsigned int idx, num, i;
3129 struct mem_array *pwrb_arr;
3130 void *wrb_vaddr;
3131 struct be_dma_mem sgl;
3132 struct be_mem_descriptor *mem_descr;
3133 int status;
3134
3135 idx = 0;
3136 mem_descr = phba->init_mem;
3137 mem_descr += HWI_MEM_WRB;
3138 pwrb_arr = kmalloc(sizeof(*pwrb_arr) * phba->params.cxns_per_ctrl,
3139 GFP_KERNEL);
3140 if (!pwrb_arr) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303141 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3142 "BM_%d : Memory alloc failed in create wrb ring.\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303143 return -ENOMEM;
3144 }
3145 wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
3146 pa_addr_lo = mem_descr->mem_array[idx].bus_address.u.a64.address;
3147 num_wrb_rings = mem_descr->mem_array[idx].size /
3148 (phba->params.wrbs_per_cxn * sizeof(struct iscsi_wrb));
3149
3150 for (num = 0; num < phba->params.cxns_per_ctrl; num++) {
3151 if (num_wrb_rings) {
3152 pwrb_arr[num].virtual_address = wrb_vaddr;
3153 pwrb_arr[num].bus_address.u.a64.address = pa_addr_lo;
3154 pwrb_arr[num].size = phba->params.wrbs_per_cxn *
3155 sizeof(struct iscsi_wrb);
3156 wrb_vaddr += pwrb_arr[num].size;
3157 pa_addr_lo += pwrb_arr[num].size;
3158 num_wrb_rings--;
3159 } else {
3160 idx++;
3161 wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
3162 pa_addr_lo = mem_descr->mem_array[idx].\
3163 bus_address.u.a64.address;
3164 num_wrb_rings = mem_descr->mem_array[idx].size /
3165 (phba->params.wrbs_per_cxn *
3166 sizeof(struct iscsi_wrb));
3167 pwrb_arr[num].virtual_address = wrb_vaddr;
3168 pwrb_arr[num].bus_address.u.a64.address\
3169 = pa_addr_lo;
3170 pwrb_arr[num].size = phba->params.wrbs_per_cxn *
3171 sizeof(struct iscsi_wrb);
3172 wrb_vaddr += pwrb_arr[num].size;
3173 pa_addr_lo += pwrb_arr[num].size;
3174 num_wrb_rings--;
3175 }
3176 }
3177 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
3178 wrb_mem_index = 0;
3179 offset = 0;
3180 size = 0;
3181
3182 hwi_build_be_sgl_by_offset(phba, &pwrb_arr[i], &sgl);
3183 status = be_cmd_wrbq_create(&phba->ctrl, &sgl,
3184 &phwi_context->be_wrbq[i]);
3185 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303186 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3187 "BM_%d : wrbq create failed.");
Dan Carpenter1462b8f2010-06-10 09:52:21 +02003188 kfree(pwrb_arr);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303189 return status;
3190 }
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05303191 phwi_ctrlr->wrb_context[i * 2].cid = phwi_context->be_wrbq[i].
3192 id;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303193 }
3194 kfree(pwrb_arr);
3195 return 0;
3196}
3197
3198static void free_wrb_handles(struct beiscsi_hba *phba)
3199{
3200 unsigned int index;
3201 struct hwi_controller *phwi_ctrlr;
3202 struct hwi_wrb_context *pwrb_context;
3203
3204 phwi_ctrlr = phba->phwi_ctrlr;
3205 for (index = 0; index < phba->params.cxns_per_ctrl * 2; index += 2) {
3206 pwrb_context = &phwi_ctrlr->wrb_context[index];
3207 kfree(pwrb_context->pwrb_handle_base);
3208 kfree(pwrb_context->pwrb_handle_basestd);
3209 }
3210}
3211
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303212static void be_mcc_queues_destroy(struct beiscsi_hba *phba)
3213{
3214 struct be_queue_info *q;
3215 struct be_ctrl_info *ctrl = &phba->ctrl;
3216
3217 q = &phba->ctrl.mcc_obj.q;
3218 if (q->created)
3219 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_MCCQ);
3220 be_queue_free(phba, q);
3221
3222 q = &phba->ctrl.mcc_obj.cq;
3223 if (q->created)
3224 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
3225 be_queue_free(phba, q);
3226}
3227
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303228static void hwi_cleanup(struct beiscsi_hba *phba)
3229{
3230 struct be_queue_info *q;
3231 struct be_ctrl_info *ctrl = &phba->ctrl;
3232 struct hwi_controller *phwi_ctrlr;
3233 struct hwi_context_memory *phwi_context;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303234 int i, eq_num;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303235
3236 phwi_ctrlr = phba->phwi_ctrlr;
3237 phwi_context = phwi_ctrlr->phwi_ctxt;
3238 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
3239 q = &phwi_context->be_wrbq[i];
3240 if (q->created)
3241 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_WRBQ);
3242 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303243 free_wrb_handles(phba);
3244
3245 q = &phwi_context->be_def_hdrq;
3246 if (q->created)
3247 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
3248
3249 q = &phwi_context->be_def_dataq;
3250 if (q->created)
3251 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
3252
3253 beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
3254
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303255 for (i = 0; i < (phba->num_cpus); i++) {
3256 q = &phwi_context->be_cq[i];
3257 if (q->created)
3258 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
3259 }
3260 if (phba->msix_enabled)
3261 eq_num = 1;
3262 else
3263 eq_num = 0;
3264 for (i = 0; i < (phba->num_cpus + eq_num); i++) {
3265 q = &phwi_context->be_eq[i].q;
3266 if (q->created)
3267 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_EQ);
3268 }
3269 be_mcc_queues_destroy(phba);
3270}
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303271
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303272static int be_mcc_queues_create(struct beiscsi_hba *phba,
3273 struct hwi_context_memory *phwi_context)
3274{
3275 struct be_queue_info *q, *cq;
3276 struct be_ctrl_info *ctrl = &phba->ctrl;
3277
3278 /* Alloc MCC compl queue */
3279 cq = &phba->ctrl.mcc_obj.cq;
3280 if (be_queue_alloc(phba, cq, MCC_CQ_LEN,
3281 sizeof(struct be_mcc_compl)))
3282 goto err;
3283 /* Ask BE to create MCC compl queue; */
3284 if (phba->msix_enabled) {
3285 if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq
3286 [phba->num_cpus].q, false, true, 0))
3287 goto mcc_cq_free;
3288 } else {
3289 if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq[0].q,
3290 false, true, 0))
3291 goto mcc_cq_free;
3292 }
3293
3294 /* Alloc MCC queue */
3295 q = &phba->ctrl.mcc_obj.q;
3296 if (be_queue_alloc(phba, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb)))
3297 goto mcc_cq_destroy;
3298
3299 /* Ask BE to create MCC queue */
Jayamohan Kallickal35e66012009-10-23 11:53:49 +05303300 if (beiscsi_cmd_mccq_create(phba, q, cq))
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303301 goto mcc_q_free;
3302
3303 return 0;
3304
3305mcc_q_free:
3306 be_queue_free(phba, q);
3307mcc_cq_destroy:
3308 beiscsi_cmd_q_destroy(ctrl, cq, QTYPE_CQ);
3309mcc_cq_free:
3310 be_queue_free(phba, cq);
3311err:
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +05303312 return -ENOMEM;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303313}
3314
John Soni Jose107dfcb2012-10-20 04:42:13 +05303315/**
3316 * find_num_cpus()- Get the CPU online count
3317 * @phba: ptr to priv structure
3318 *
3319 * CPU count is used for creating EQ.
3320 **/
3321static void find_num_cpus(struct beiscsi_hba *phba)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303322{
3323 int num_cpus = 0;
3324
3325 num_cpus = num_online_cpus();
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303326
John Soni Jose107dfcb2012-10-20 04:42:13 +05303327 phba->num_cpus = (num_cpus >= BEISCSI_MAX_NUM_CPU) ?
3328 (BEISCSI_MAX_NUM_CPU - 1) : num_cpus;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303329}
3330
3331static int hwi_init_port(struct beiscsi_hba *phba)
3332{
3333 struct hwi_controller *phwi_ctrlr;
3334 struct hwi_context_memory *phwi_context;
3335 unsigned int def_pdu_ring_sz;
3336 struct be_ctrl_info *ctrl = &phba->ctrl;
3337 int status;
3338
3339 def_pdu_ring_sz =
3340 phba->params.asyncpdus_per_ctrl * sizeof(struct phys_addr);
3341 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303342 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303343 phwi_context->max_eqd = 0;
3344 phwi_context->min_eqd = 0;
3345 phwi_context->cur_eqd = 64;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303346 be_cmd_fw_initialize(&phba->ctrl);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303347
3348 status = beiscsi_create_eqs(phba, phwi_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303349 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303350 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3351 "BM_%d : EQ not created\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303352 goto error;
3353 }
3354
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303355 status = be_mcc_queues_create(phba, phwi_context);
3356 if (status != 0)
3357 goto error;
3358
3359 status = mgmt_check_supported_fw(ctrl, phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303360 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303361 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3362 "BM_%d : Unsupported fw version\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303363 goto error;
3364 }
3365
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303366 status = beiscsi_create_cqs(phba, phwi_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303367 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303368 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3369 "BM_%d : CQ not created\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303370 goto error;
3371 }
3372
3373 status = beiscsi_create_def_hdr(phba, phwi_context, phwi_ctrlr,
3374 def_pdu_ring_sz);
3375 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303376 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3377 "BM_%d : Default Header not created\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303378 goto error;
3379 }
3380
3381 status = beiscsi_create_def_data(phba, phwi_context,
3382 phwi_ctrlr, def_pdu_ring_sz);
3383 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303384 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3385 "BM_%d : Default Data not created\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303386 goto error;
3387 }
3388
3389 status = beiscsi_post_pages(phba);
3390 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303391 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3392 "BM_%d : Post SGL Pages Failed\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303393 goto error;
3394 }
3395
3396 status = beiscsi_create_wrb_rings(phba, phwi_context, phwi_ctrlr);
3397 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303398 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3399 "BM_%d : WRB Rings not created\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303400 goto error;
3401 }
3402
John Soni Jose99bc5d52012-08-20 23:00:18 +05303403 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3404 "BM_%d : hwi_init_port success\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303405 return 0;
3406
3407error:
John Soni Jose99bc5d52012-08-20 23:00:18 +05303408 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3409 "BM_%d : hwi_init_port failed");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303410 hwi_cleanup(phba);
Jayamohan Kallickala49e06d2012-04-03 23:41:44 -05003411 return status;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303412}
3413
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303414static int hwi_init_controller(struct beiscsi_hba *phba)
3415{
3416 struct hwi_controller *phwi_ctrlr;
3417
3418 phwi_ctrlr = phba->phwi_ctrlr;
3419 if (1 == phba->init_mem[HWI_MEM_ADDN_CONTEXT].num_elements) {
3420 phwi_ctrlr->phwi_ctxt = (struct hwi_context_memory *)phba->
3421 init_mem[HWI_MEM_ADDN_CONTEXT].mem_array[0].virtual_address;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303422 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3423 "BM_%d : phwi_ctrlr->phwi_ctxt=%p\n",
3424 phwi_ctrlr->phwi_ctxt);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303425 } else {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303426 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3427 "BM_%d : HWI_MEM_ADDN_CONTEXT is more "
3428 "than one element.Failing to load\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303429 return -ENOMEM;
3430 }
3431
3432 iscsi_init_global_templates(phba);
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05003433 if (beiscsi_init_wrb_handle(phba))
3434 return -ENOMEM;
3435
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303436 hwi_init_async_pdu_ctx(phba);
3437 if (hwi_init_port(phba) != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303438 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3439 "BM_%d : hwi_init_controller failed\n");
3440
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303441 return -ENOMEM;
3442 }
3443 return 0;
3444}
3445
3446static void beiscsi_free_mem(struct beiscsi_hba *phba)
3447{
3448 struct be_mem_descriptor *mem_descr;
3449 int i, j;
3450
3451 mem_descr = phba->init_mem;
3452 i = 0;
3453 j = 0;
3454 for (i = 0; i < SE_MEM_MAX; i++) {
3455 for (j = mem_descr->num_elements; j > 0; j--) {
3456 pci_free_consistent(phba->pcidev,
3457 mem_descr->mem_array[j - 1].size,
3458 mem_descr->mem_array[j - 1].virtual_address,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05303459 (unsigned long)mem_descr->mem_array[j - 1].
3460 bus_address.u.a64.address);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303461 }
3462 kfree(mem_descr->mem_array);
3463 mem_descr++;
3464 }
3465 kfree(phba->init_mem);
3466 kfree(phba->phwi_ctrlr);
3467}
3468
3469static int beiscsi_init_controller(struct beiscsi_hba *phba)
3470{
3471 int ret = -ENOMEM;
3472
3473 ret = beiscsi_get_memory(phba);
3474 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303475 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3476 "BM_%d : beiscsi_dev_probe -"
3477 "Failed in beiscsi_alloc_memory\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303478 return ret;
3479 }
3480
3481 ret = hwi_init_controller(phba);
3482 if (ret)
3483 goto free_init;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303484 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3485 "BM_%d : Return success from beiscsi_init_controller");
3486
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303487 return 0;
3488
3489free_init:
3490 beiscsi_free_mem(phba);
Jayamohan Kallickala49e06d2012-04-03 23:41:44 -05003491 return ret;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303492}
3493
3494static int beiscsi_init_sgl_handle(struct beiscsi_hba *phba)
3495{
3496 struct be_mem_descriptor *mem_descr_sglh, *mem_descr_sg;
3497 struct sgl_handle *psgl_handle;
3498 struct iscsi_sge *pfrag;
3499 unsigned int arr_index, i, idx;
3500
3501 phba->io_sgl_hndl_avbl = 0;
3502 phba->eh_sgl_hndl_avbl = 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303503
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303504 mem_descr_sglh = phba->init_mem;
3505 mem_descr_sglh += HWI_MEM_SGLH;
3506 if (1 == mem_descr_sglh->num_elements) {
3507 phba->io_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
3508 phba->params.ios_per_ctrl,
3509 GFP_KERNEL);
3510 if (!phba->io_sgl_hndl_base) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303511 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3512 "BM_%d : Mem Alloc Failed. Failing to load\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303513 return -ENOMEM;
3514 }
3515 phba->eh_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
3516 (phba->params.icds_per_ctrl -
3517 phba->params.ios_per_ctrl),
3518 GFP_KERNEL);
3519 if (!phba->eh_sgl_hndl_base) {
3520 kfree(phba->io_sgl_hndl_base);
John Soni Jose99bc5d52012-08-20 23:00:18 +05303521 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3522 "BM_%d : Mem Alloc Failed. Failing to load\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303523 return -ENOMEM;
3524 }
3525 } else {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303526 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3527 "BM_%d : HWI_MEM_SGLH is more than one element."
3528 "Failing to load\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303529 return -ENOMEM;
3530 }
3531
3532 arr_index = 0;
3533 idx = 0;
3534 while (idx < mem_descr_sglh->num_elements) {
3535 psgl_handle = mem_descr_sglh->mem_array[idx].virtual_address;
3536
3537 for (i = 0; i < (mem_descr_sglh->mem_array[idx].size /
3538 sizeof(struct sgl_handle)); i++) {
3539 if (arr_index < phba->params.ios_per_ctrl) {
3540 phba->io_sgl_hndl_base[arr_index] = psgl_handle;
3541 phba->io_sgl_hndl_avbl++;
3542 arr_index++;
3543 } else {
3544 phba->eh_sgl_hndl_base[arr_index -
3545 phba->params.ios_per_ctrl] =
3546 psgl_handle;
3547 arr_index++;
3548 phba->eh_sgl_hndl_avbl++;
3549 }
3550 psgl_handle++;
3551 }
3552 idx++;
3553 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05303554 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3555 "BM_%d : phba->io_sgl_hndl_avbl=%d"
3556 "phba->eh_sgl_hndl_avbl=%d\n",
3557 phba->io_sgl_hndl_avbl,
3558 phba->eh_sgl_hndl_avbl);
3559
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303560 mem_descr_sg = phba->init_mem;
3561 mem_descr_sg += HWI_MEM_SGE;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303562 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3563 "\n BM_%d : mem_descr_sg->num_elements=%d\n",
3564 mem_descr_sg->num_elements);
3565
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303566 arr_index = 0;
3567 idx = 0;
3568 while (idx < mem_descr_sg->num_elements) {
3569 pfrag = mem_descr_sg->mem_array[idx].virtual_address;
3570
3571 for (i = 0;
3572 i < (mem_descr_sg->mem_array[idx].size) /
3573 (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io);
3574 i++) {
3575 if (arr_index < phba->params.ios_per_ctrl)
3576 psgl_handle = phba->io_sgl_hndl_base[arr_index];
3577 else
3578 psgl_handle = phba->eh_sgl_hndl_base[arr_index -
3579 phba->params.ios_per_ctrl];
3580 psgl_handle->pfrag = pfrag;
3581 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, pfrag, 0);
3582 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, pfrag, 0);
3583 pfrag += phba->params.num_sge_per_io;
3584 psgl_handle->sgl_index =
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05303585 phba->fw_config.iscsi_icd_start + arr_index++;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303586 }
3587 idx++;
3588 }
3589 phba->io_sgl_free_index = 0;
3590 phba->io_sgl_alloc_index = 0;
3591 phba->eh_sgl_free_index = 0;
3592 phba->eh_sgl_alloc_index = 0;
3593 return 0;
3594}
3595
3596static int hba_setup_cid_tbls(struct beiscsi_hba *phba)
3597{
3598 int i, new_cid;
3599
Jayamohan Kallickalc2462282010-01-05 05:05:34 +05303600 phba->cid_array = kzalloc(sizeof(void *) * phba->params.cxns_per_ctrl,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303601 GFP_KERNEL);
3602 if (!phba->cid_array) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303603 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3604 "BM_%d : Failed to allocate memory in "
3605 "hba_setup_cid_tbls\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303606 return -ENOMEM;
3607 }
Jayamohan Kallickalc2462282010-01-05 05:05:34 +05303608 phba->ep_array = kzalloc(sizeof(struct iscsi_endpoint *) *
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303609 phba->params.cxns_per_ctrl * 2, GFP_KERNEL);
3610 if (!phba->ep_array) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303611 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3612 "BM_%d : Failed to allocate memory in "
3613 "hba_setup_cid_tbls\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303614 kfree(phba->cid_array);
3615 return -ENOMEM;
3616 }
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05303617 new_cid = phba->fw_config.iscsi_cid_start;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303618 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
3619 phba->cid_array[i] = new_cid;
3620 new_cid += 2;
3621 }
3622 phba->avlbl_cids = phba->params.cxns_per_ctrl;
3623 return 0;
3624}
3625
Jayamohan Kallickal238f6b72010-07-22 04:23:22 +05303626static void hwi_enable_intr(struct beiscsi_hba *phba)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303627{
3628 struct be_ctrl_info *ctrl = &phba->ctrl;
3629 struct hwi_controller *phwi_ctrlr;
3630 struct hwi_context_memory *phwi_context;
3631 struct be_queue_info *eq;
3632 u8 __iomem *addr;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303633 u32 reg, i;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303634 u32 enabled;
3635
3636 phwi_ctrlr = phba->phwi_ctrlr;
3637 phwi_context = phwi_ctrlr->phwi_ctxt;
3638
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303639 addr = (u8 __iomem *) ((u8 __iomem *) ctrl->pcicfg +
3640 PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET);
3641 reg = ioread32(addr);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303642
3643 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
3644 if (!enabled) {
3645 reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303646 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3647 "BM_%d : reg =x%08x addr=%p\n", reg, addr);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303648 iowrite32(reg, addr);
Jayamohan Kallickal665d6d92011-04-29 14:30:06 -05003649 }
3650
3651 if (!phba->msix_enabled) {
3652 eq = &phwi_context->be_eq[0].q;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303653 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3654 "BM_%d : eq->id=%d\n", eq->id);
3655
Jayamohan Kallickal665d6d92011-04-29 14:30:06 -05003656 hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
3657 } else {
3658 for (i = 0; i <= phba->num_cpus; i++) {
3659 eq = &phwi_context->be_eq[i].q;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303660 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3661 "BM_%d : eq->id=%d\n", eq->id);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303662 hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
3663 }
Jayamohan Kallickalc03af1a2010-02-20 08:05:43 +05303664 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303665}
3666
3667static void hwi_disable_intr(struct beiscsi_hba *phba)
3668{
3669 struct be_ctrl_info *ctrl = &phba->ctrl;
3670
3671 u8 __iomem *addr = ctrl->pcicfg + PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET;
3672 u32 reg = ioread32(addr);
3673
3674 u32 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
3675 if (enabled) {
3676 reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
3677 iowrite32(reg, addr);
3678 } else
John Soni Jose99bc5d52012-08-20 23:00:18 +05303679 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
3680 "BM_%d : In hwi_disable_intr, Already Disabled\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303681}
3682
John Soni Jose9aef4202012-08-20 23:00:08 +05303683/**
3684 * beiscsi_get_boot_info()- Get the boot session info
3685 * @phba: The device priv structure instance
3686 *
3687 * Get the boot target info and store in driver priv structure
3688 *
3689 * return values
3690 * Success: 0
3691 * Failure: Non-Zero Value
3692 **/
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05303693static int beiscsi_get_boot_info(struct beiscsi_hba *phba)
3694{
Mike Christie0e438952012-04-03 23:41:51 -05003695 struct be_cmd_get_session_resp *session_resp;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05303696 struct be_mcc_wrb *wrb;
3697 struct be_dma_mem nonemb_cmd;
3698 unsigned int tag, wrb_num;
3699 unsigned short status, extd_status;
John Soni Jose9aef4202012-08-20 23:00:08 +05303700 unsigned int s_handle;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05303701 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
Mike Christief457a462011-06-24 15:11:53 -05003702 int ret = -ENOMEM;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05303703
John Soni Jose9aef4202012-08-20 23:00:08 +05303704 /* Get the session handle of the boot target */
3705 ret = be_mgmt_get_boot_shandle(phba, &s_handle);
3706 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303707 beiscsi_log(phba, KERN_ERR,
3708 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
3709 "BM_%d : No boot session\n");
John Soni Jose9aef4202012-08-20 23:00:08 +05303710 return ret;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05303711 }
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05303712 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
3713 sizeof(*session_resp),
3714 &nonemb_cmd.dma);
3715 if (nonemb_cmd.va == NULL) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303716 beiscsi_log(phba, KERN_ERR,
3717 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
3718 "BM_%d : Failed to allocate memory for"
3719 "beiscsi_get_session_info\n");
3720
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05303721 return -ENOMEM;
3722 }
3723
3724 memset(nonemb_cmd.va, 0, sizeof(*session_resp));
John Soni Jose9aef4202012-08-20 23:00:08 +05303725 tag = mgmt_get_session_info(phba, s_handle,
Mike Christie0e438952012-04-03 23:41:51 -05003726 &nonemb_cmd);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05303727 if (!tag) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303728 beiscsi_log(phba, KERN_ERR,
3729 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
3730 "BM_%d : beiscsi_get_session_info"
3731 " Failed\n");
3732
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05303733 goto boot_freemem;
3734 } else
3735 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
3736 phba->ctrl.mcc_numtag[tag]);
3737
3738 wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
3739 extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
3740 status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
3741 if (status || extd_status) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303742 beiscsi_log(phba, KERN_ERR,
3743 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
3744 "BM_%d : beiscsi_get_session_info Failed"
3745 " status = %d extd_status = %d\n",
3746 status, extd_status);
3747
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05303748 free_mcc_tag(&phba->ctrl, tag);
3749 goto boot_freemem;
3750 }
3751 wrb = queue_get_wrb(mccq, wrb_num);
3752 free_mcc_tag(&phba->ctrl, tag);
3753 session_resp = nonemb_cmd.va ;
Mike Christief457a462011-06-24 15:11:53 -05003754
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05303755 memcpy(&phba->boot_sess, &session_resp->session_info,
3756 sizeof(struct mgmt_session_info));
Mike Christief457a462011-06-24 15:11:53 -05003757 ret = 0;
3758
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05303759boot_freemem:
3760 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
3761 nonemb_cmd.va, nonemb_cmd.dma);
Mike Christief457a462011-06-24 15:11:53 -05003762 return ret;
3763}
3764
3765static void beiscsi_boot_release(void *data)
3766{
3767 struct beiscsi_hba *phba = data;
3768
3769 scsi_host_put(phba->shost);
3770}
3771
3772static int beiscsi_setup_boot_info(struct beiscsi_hba *phba)
3773{
3774 struct iscsi_boot_kobj *boot_kobj;
3775
3776 /* get boot info using mgmt cmd */
3777 if (beiscsi_get_boot_info(phba))
3778 /* Try to see if we can carry on without this */
3779 return 0;
3780
3781 phba->boot_kset = iscsi_boot_create_host_kset(phba->shost->host_no);
3782 if (!phba->boot_kset)
3783 return -ENOMEM;
3784
3785 /* get a ref because the show function will ref the phba */
3786 if (!scsi_host_get(phba->shost))
3787 goto free_kset;
3788 boot_kobj = iscsi_boot_create_target(phba->boot_kset, 0, phba,
3789 beiscsi_show_boot_tgt_info,
3790 beiscsi_tgt_get_attr_visibility,
3791 beiscsi_boot_release);
3792 if (!boot_kobj)
3793 goto put_shost;
3794
3795 if (!scsi_host_get(phba->shost))
3796 goto free_kset;
3797 boot_kobj = iscsi_boot_create_initiator(phba->boot_kset, 0, phba,
3798 beiscsi_show_boot_ini_info,
3799 beiscsi_ini_get_attr_visibility,
3800 beiscsi_boot_release);
3801 if (!boot_kobj)
3802 goto put_shost;
3803
3804 if (!scsi_host_get(phba->shost))
3805 goto free_kset;
3806 boot_kobj = iscsi_boot_create_ethernet(phba->boot_kset, 0, phba,
3807 beiscsi_show_boot_eth_info,
3808 beiscsi_eth_get_attr_visibility,
3809 beiscsi_boot_release);
3810 if (!boot_kobj)
3811 goto put_shost;
3812 return 0;
3813
3814put_shost:
3815 scsi_host_put(phba->shost);
3816free_kset:
3817 iscsi_boot_destroy_kset(phba->boot_kset);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05303818 return -ENOMEM;
3819}
3820
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303821static int beiscsi_init_port(struct beiscsi_hba *phba)
3822{
3823 int ret;
3824
3825 ret = beiscsi_init_controller(phba);
3826 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303827 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3828 "BM_%d : beiscsi_dev_probe - Failed in"
3829 "beiscsi_init_controller\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303830 return ret;
3831 }
3832 ret = beiscsi_init_sgl_handle(phba);
3833 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303834 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3835 "BM_%d : beiscsi_dev_probe - Failed in"
3836 "beiscsi_init_sgl_handle\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303837 goto do_cleanup_ctrlr;
3838 }
3839
3840 if (hba_setup_cid_tbls(phba)) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303841 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3842 "BM_%d : Failed in hba_setup_cid_tbls\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303843 kfree(phba->io_sgl_hndl_base);
3844 kfree(phba->eh_sgl_hndl_base);
3845 goto do_cleanup_ctrlr;
3846 }
3847
3848 return ret;
3849
3850do_cleanup_ctrlr:
3851 hwi_cleanup(phba);
3852 return ret;
3853}
3854
3855static void hwi_purge_eq(struct beiscsi_hba *phba)
3856{
3857 struct hwi_controller *phwi_ctrlr;
3858 struct hwi_context_memory *phwi_context;
3859 struct be_queue_info *eq;
3860 struct be_eq_entry *eqe = NULL;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303861 int i, eq_msix;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05303862 unsigned int num_processed;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303863
3864 phwi_ctrlr = phba->phwi_ctrlr;
3865 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303866 if (phba->msix_enabled)
3867 eq_msix = 1;
3868 else
3869 eq_msix = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303870
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303871 for (i = 0; i < (phba->num_cpus + eq_msix); i++) {
3872 eq = &phwi_context->be_eq[i].q;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303873 eqe = queue_tail_node(eq);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05303874 num_processed = 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303875 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
3876 & EQE_VALID_MASK) {
3877 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
3878 queue_tail_inc(eq);
3879 eqe = queue_tail_node(eq);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05303880 num_processed++;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303881 }
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05303882
3883 if (num_processed)
3884 hwi_ring_eq_db(phba, eq->id, 1, num_processed, 1, 1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303885 }
3886}
3887
3888static void beiscsi_clean_port(struct beiscsi_hba *phba)
3889{
Jayamohan Kallickal03a12312010-07-22 04:17:16 +05303890 int mgmt_status;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303891
3892 mgmt_status = mgmt_epfw_cleanup(phba, CMD_CONNECTION_CHUTE_0);
3893 if (mgmt_status)
John Soni Jose99bc5d52012-08-20 23:00:18 +05303894 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
3895 "BM_%d : mgmt_epfw_cleanup FAILED\n");
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05303896
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303897 hwi_purge_eq(phba);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05303898 hwi_cleanup(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303899 kfree(phba->io_sgl_hndl_base);
3900 kfree(phba->eh_sgl_hndl_base);
3901 kfree(phba->cid_array);
3902 kfree(phba->ep_array);
3903}
3904
John Soni Josed629c472012-10-20 04:42:00 +05303905/**
3906 * beiscsi_cleanup_task()- Free driver resources of the task
3907 * @task: ptr to the iscsi task
3908 *
3909 **/
Mike Christie1282ab72012-04-18 03:06:00 -05003910static void beiscsi_cleanup_task(struct iscsi_task *task)
3911{
3912 struct beiscsi_io_task *io_task = task->dd_data;
3913 struct iscsi_conn *conn = task->conn;
3914 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
3915 struct beiscsi_hba *phba = beiscsi_conn->phba;
3916 struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
3917 struct hwi_wrb_context *pwrb_context;
3918 struct hwi_controller *phwi_ctrlr;
3919
3920 phwi_ctrlr = phba->phwi_ctrlr;
3921 pwrb_context = &phwi_ctrlr->wrb_context[beiscsi_conn->beiscsi_conn_cid
3922 - phba->fw_config.iscsi_cid_start];
3923
3924 if (io_task->cmd_bhs) {
3925 pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
3926 io_task->bhs_pa.u.a64.address);
3927 io_task->cmd_bhs = NULL;
3928 }
3929
3930 if (task->sc) {
3931 if (io_task->pwrb_handle) {
3932 free_wrb_handle(phba, pwrb_context,
3933 io_task->pwrb_handle);
3934 io_task->pwrb_handle = NULL;
3935 }
3936
3937 if (io_task->psgl_handle) {
3938 spin_lock(&phba->io_sgl_lock);
3939 free_io_sgl_handle(phba, io_task->psgl_handle);
3940 spin_unlock(&phba->io_sgl_lock);
3941 io_task->psgl_handle = NULL;
3942 }
3943 } else {
3944 if (!beiscsi_conn->login_in_progress) {
3945 if (io_task->pwrb_handle) {
3946 free_wrb_handle(phba, pwrb_context,
3947 io_task->pwrb_handle);
3948 io_task->pwrb_handle = NULL;
3949 }
3950 if (io_task->psgl_handle) {
3951 spin_lock(&phba->mgmt_sgl_lock);
3952 free_mgmt_sgl_handle(phba,
3953 io_task->psgl_handle);
3954 spin_unlock(&phba->mgmt_sgl_lock);
3955 io_task->psgl_handle = NULL;
3956 }
John Soni Josed629c472012-10-20 04:42:00 +05303957 if (io_task->mtask_addr) {
3958 pci_unmap_single(phba->pcidev,
3959 io_task->mtask_addr,
3960 io_task->mtask_data_count,
3961 PCI_DMA_TODEVICE);
3962 io_task->mtask_addr = 0;
3963 }
Mike Christie1282ab72012-04-18 03:06:00 -05003964 }
3965 }
3966}
3967
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303968void
3969beiscsi_offload_connection(struct beiscsi_conn *beiscsi_conn,
3970 struct beiscsi_offload_params *params)
3971{
3972 struct wrb_handle *pwrb_handle;
3973 struct iscsi_target_context_update_wrb *pwrb = NULL;
3974 struct be_mem_descriptor *mem_descr;
3975 struct beiscsi_hba *phba = beiscsi_conn->phba;
Mike Christie1282ab72012-04-18 03:06:00 -05003976 struct iscsi_task *task = beiscsi_conn->task;
3977 struct iscsi_session *session = task->conn->session;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303978 u32 doorbell = 0;
3979
3980 /*
3981 * We can always use 0 here because it is reserved by libiscsi for
3982 * login/startup related tasks.
3983 */
Mike Christie1282ab72012-04-18 03:06:00 -05003984 beiscsi_conn->login_in_progress = 0;
3985 spin_lock_bh(&session->lock);
3986 beiscsi_cleanup_task(task);
3987 spin_unlock_bh(&session->lock);
3988
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05303989 pwrb_handle = alloc_wrb_handle(phba, (beiscsi_conn->beiscsi_conn_cid -
Jayamohan Kallickald5431482010-01-05 05:06:21 +05303990 phba->fw_config.iscsi_cid_start));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303991 pwrb = (struct iscsi_target_context_update_wrb *)pwrb_handle->pwrb;
3992 memset(pwrb, 0, sizeof(*pwrb));
3993 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
3994 max_burst_length, pwrb, params->dw[offsetof
3995 (struct amap_beiscsi_offload_params,
3996 max_burst_length) / 32]);
3997 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
3998 max_send_data_segment_length, pwrb,
3999 params->dw[offsetof(struct amap_beiscsi_offload_params,
4000 max_send_data_segment_length) / 32]);
4001 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
4002 first_burst_length,
4003 pwrb,
4004 params->dw[offsetof(struct amap_beiscsi_offload_params,
4005 first_burst_length) / 32]);
4006
4007 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, erl, pwrb,
4008 (params->dw[offsetof(struct amap_beiscsi_offload_params,
4009 erl) / 32] & OFFLD_PARAMS_ERL));
4010 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, dde, pwrb,
4011 (params->dw[offsetof(struct amap_beiscsi_offload_params,
4012 dde) / 32] & OFFLD_PARAMS_DDE) >> 2);
4013 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, hde, pwrb,
4014 (params->dw[offsetof(struct amap_beiscsi_offload_params,
4015 hde) / 32] & OFFLD_PARAMS_HDE) >> 3);
4016 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, ir2t, pwrb,
4017 (params->dw[offsetof(struct amap_beiscsi_offload_params,
4018 ir2t) / 32] & OFFLD_PARAMS_IR2T) >> 4);
4019 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, imd, pwrb,
4020 (params->dw[offsetof(struct amap_beiscsi_offload_params,
4021 imd) / 32] & OFFLD_PARAMS_IMD) >> 5);
4022 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, stat_sn,
4023 pwrb,
4024 (params->dw[offsetof(struct amap_beiscsi_offload_params,
4025 exp_statsn) / 32] + 1));
4026 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, type, pwrb,
4027 0x7);
4028 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, wrb_idx,
4029 pwrb, pwrb_handle->wrb_index);
4030 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, ptr2nextwrb,
4031 pwrb, pwrb_handle->nxt_wrb_index);
4032 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
4033 session_state, pwrb, 0);
4034 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, compltonack,
4035 pwrb, 1);
4036 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, notpredblq,
4037 pwrb, 0);
4038 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, mode, pwrb,
4039 0);
4040
4041 mem_descr = phba->init_mem;
4042 mem_descr += ISCSI_MEM_GLOBAL_HEADER;
4043
4044 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
4045 pad_buffer_addr_hi, pwrb,
4046 mem_descr->mem_array[0].bus_address.u.a32.address_hi);
4047 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
4048 pad_buffer_addr_lo, pwrb,
4049 mem_descr->mem_array[0].bus_address.u.a32.address_lo);
4050
4051 be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_target_context_update_wrb));
4052
4053 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304054 doorbell |= (pwrb_handle->wrb_index & DB_DEF_PDU_WRB_INDEX_MASK)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304055 << DB_DEF_PDU_WRB_INDEX_SHIFT;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304056 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
4057
4058 iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
4059}
4060
4061static void beiscsi_parse_pdu(struct iscsi_conn *conn, itt_t itt,
4062 int *index, int *age)
4063{
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304064 *index = (int)itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304065 if (age)
4066 *age = conn->session->age;
4067}
4068
4069/**
4070 * beiscsi_alloc_pdu - allocates pdu and related resources
4071 * @task: libiscsi task
4072 * @opcode: opcode of pdu for task
4073 *
4074 * This is called with the session lock held. It will allocate
4075 * the wrb and sgl if needed for the command. And it will prep
4076 * the pdu's itt. beiscsi_parse_pdu will later translate
4077 * the pdu itt to the libiscsi task itt.
4078 */
4079static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
4080{
4081 struct beiscsi_io_task *io_task = task->dd_data;
4082 struct iscsi_conn *conn = task->conn;
4083 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4084 struct beiscsi_hba *phba = beiscsi_conn->phba;
4085 struct hwi_wrb_context *pwrb_context;
4086 struct hwi_controller *phwi_ctrlr;
4087 itt_t itt;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304088 struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
4089 dma_addr_t paddr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304090
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304091 io_task->cmd_bhs = pci_pool_alloc(beiscsi_sess->bhs_pool,
Mike Christiebc7acce2010-12-31 02:22:19 -06004092 GFP_ATOMIC, &paddr);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304093 if (!io_task->cmd_bhs)
4094 return -ENOMEM;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304095 io_task->bhs_pa.u.a64.address = paddr;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304096 io_task->libiscsi_itt = (itt_t)task->itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304097 io_task->conn = beiscsi_conn;
4098
4099 task->hdr = (struct iscsi_hdr *)&io_task->cmd_bhs->iscsi_hdr;
4100 task->hdr_max = sizeof(struct be_cmd_bhs);
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304101 io_task->psgl_handle = NULL;
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05004102 io_task->pwrb_handle = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304103
4104 if (task->sc) {
4105 spin_lock(&phba->io_sgl_lock);
4106 io_task->psgl_handle = alloc_io_sgl_handle(phba);
4107 spin_unlock(&phba->io_sgl_lock);
John Soni Jose8359c792012-10-20 04:43:03 +05304108 if (!io_task->psgl_handle) {
4109 beiscsi_log(phba, KERN_ERR,
4110 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
4111 "BM_%d : Alloc of IO_SGL_ICD Failed"
4112 "for the CID : %d\n",
4113 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304114 goto free_hndls;
John Soni Jose8359c792012-10-20 04:43:03 +05304115 }
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304116 io_task->pwrb_handle = alloc_wrb_handle(phba,
4117 beiscsi_conn->beiscsi_conn_cid -
4118 phba->fw_config.iscsi_cid_start);
John Soni Jose8359c792012-10-20 04:43:03 +05304119 if (!io_task->pwrb_handle) {
4120 beiscsi_log(phba, KERN_ERR,
4121 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
4122 "BM_%d : Alloc of WRB_HANDLE Failed"
4123 "for the CID : %d\n",
4124 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304125 goto free_io_hndls;
John Soni Jose8359c792012-10-20 04:43:03 +05304126 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304127 } else {
4128 io_task->scsi_cmnd = NULL;
Jayamohan Kallickald7aea672010-01-05 05:08:39 +05304129 if ((opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304130 if (!beiscsi_conn->login_in_progress) {
4131 spin_lock(&phba->mgmt_sgl_lock);
4132 io_task->psgl_handle = (struct sgl_handle *)
4133 alloc_mgmt_sgl_handle(phba);
4134 spin_unlock(&phba->mgmt_sgl_lock);
John Soni Jose8359c792012-10-20 04:43:03 +05304135 if (!io_task->psgl_handle) {
4136 beiscsi_log(phba, KERN_ERR,
4137 BEISCSI_LOG_IO |
4138 BEISCSI_LOG_CONFIG,
4139 "BM_%d : Alloc of MGMT_SGL_ICD Failed"
4140 "for the CID : %d\n",
4141 beiscsi_conn->
4142 beiscsi_conn_cid);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304143 goto free_hndls;
John Soni Jose8359c792012-10-20 04:43:03 +05304144 }
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304145
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304146 beiscsi_conn->login_in_progress = 1;
4147 beiscsi_conn->plogin_sgl_handle =
4148 io_task->psgl_handle;
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304149 io_task->pwrb_handle =
4150 alloc_wrb_handle(phba,
4151 beiscsi_conn->beiscsi_conn_cid -
4152 phba->fw_config.iscsi_cid_start);
John Soni Jose8359c792012-10-20 04:43:03 +05304153 if (!io_task->pwrb_handle) {
4154 beiscsi_log(phba, KERN_ERR,
4155 BEISCSI_LOG_IO |
4156 BEISCSI_LOG_CONFIG,
4157 "BM_%d : Alloc of WRB_HANDLE Failed"
4158 "for the CID : %d\n",
4159 beiscsi_conn->
4160 beiscsi_conn_cid);
4161 goto free_mgmt_hndls;
4162 }
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304163 beiscsi_conn->plogin_wrb_handle =
4164 io_task->pwrb_handle;
4165
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304166 } else {
4167 io_task->psgl_handle =
4168 beiscsi_conn->plogin_sgl_handle;
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304169 io_task->pwrb_handle =
4170 beiscsi_conn->plogin_wrb_handle;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304171 }
Mike Christie1282ab72012-04-18 03:06:00 -05004172 beiscsi_conn->task = task;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304173 } else {
4174 spin_lock(&phba->mgmt_sgl_lock);
4175 io_task->psgl_handle = alloc_mgmt_sgl_handle(phba);
4176 spin_unlock(&phba->mgmt_sgl_lock);
John Soni Jose8359c792012-10-20 04:43:03 +05304177 if (!io_task->psgl_handle) {
4178 beiscsi_log(phba, KERN_ERR,
4179 BEISCSI_LOG_IO |
4180 BEISCSI_LOG_CONFIG,
4181 "BM_%d : Alloc of MGMT_SGL_ICD Failed"
4182 "for the CID : %d\n",
4183 beiscsi_conn->
4184 beiscsi_conn_cid);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304185 goto free_hndls;
John Soni Jose8359c792012-10-20 04:43:03 +05304186 }
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304187 io_task->pwrb_handle =
4188 alloc_wrb_handle(phba,
4189 beiscsi_conn->beiscsi_conn_cid -
4190 phba->fw_config.iscsi_cid_start);
John Soni Jose8359c792012-10-20 04:43:03 +05304191 if (!io_task->pwrb_handle) {
4192 beiscsi_log(phba, KERN_ERR,
4193 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
4194 "BM_%d : Alloc of WRB_HANDLE Failed"
4195 "for the CID : %d\n",
4196 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304197 goto free_mgmt_hndls;
John Soni Jose8359c792012-10-20 04:43:03 +05304198 }
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304199
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304200 }
4201 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304202 itt = (itt_t) cpu_to_be32(((unsigned int)io_task->pwrb_handle->
4203 wrb_index << 16) | (unsigned int)
4204 (io_task->psgl_handle->sgl_index));
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304205 io_task->pwrb_handle->pio_handle = task;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304206
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304207 io_task->cmd_bhs->iscsi_hdr.itt = itt;
4208 return 0;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304209
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304210free_io_hndls:
4211 spin_lock(&phba->io_sgl_lock);
4212 free_io_sgl_handle(phba, io_task->psgl_handle);
4213 spin_unlock(&phba->io_sgl_lock);
4214 goto free_hndls;
4215free_mgmt_hndls:
4216 spin_lock(&phba->mgmt_sgl_lock);
4217 free_mgmt_sgl_handle(phba, io_task->psgl_handle);
4218 spin_unlock(&phba->mgmt_sgl_lock);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304219free_hndls:
4220 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05304221 pwrb_context = &phwi_ctrlr->wrb_context[
4222 beiscsi_conn->beiscsi_conn_cid -
4223 phba->fw_config.iscsi_cid_start];
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304224 if (io_task->pwrb_handle)
4225 free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304226 io_task->pwrb_handle = NULL;
4227 pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
4228 io_task->bhs_pa.u.a64.address);
Mike Christie1282ab72012-04-18 03:06:00 -05004229 io_task->cmd_bhs = NULL;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304230 return -ENOMEM;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304231}
4232
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304233static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg,
4234 unsigned int num_sg, unsigned int xferlen,
4235 unsigned int writedir)
4236{
4237
4238 struct beiscsi_io_task *io_task = task->dd_data;
4239 struct iscsi_conn *conn = task->conn;
4240 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4241 struct beiscsi_hba *phba = beiscsi_conn->phba;
4242 struct iscsi_wrb *pwrb = NULL;
4243 unsigned int doorbell = 0;
4244
4245 pwrb = io_task->pwrb_handle->pwrb;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304246 io_task->cmd_bhs->iscsi_hdr.exp_statsn = 0;
4247 io_task->bhs_len = sizeof(struct be_cmd_bhs);
4248
4249 if (writedir) {
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304250 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4251 INI_WR_CMD);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304252 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304253 } else {
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304254 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4255 INI_RD_CMD);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304256 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
4257 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304258
4259 AMAP_SET_BITS(struct amap_iscsi_wrb, lun, pwrb,
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05004260 cpu_to_be16(*(unsigned short *)
4261 &io_task->cmd_bhs->iscsi_hdr.lun));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304262 AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, xferlen);
4263 AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
4264 io_task->pwrb_handle->wrb_index);
4265 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
4266 be32_to_cpu(task->cmdsn));
4267 AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
4268 io_task->psgl_handle->sgl_index);
4269
4270 hwi_write_sgl(pwrb, sg, num_sg, io_task);
4271
4272 AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
4273 io_task->pwrb_handle->nxt_wrb_index);
4274 be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
4275
4276 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304277 doorbell |= (io_task->pwrb_handle->wrb_index &
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304278 DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
4279 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
4280
4281 iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
4282 return 0;
4283}
4284
4285static int beiscsi_mtask(struct iscsi_task *task)
4286{
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05304287 struct beiscsi_io_task *io_task = task->dd_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304288 struct iscsi_conn *conn = task->conn;
4289 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4290 struct beiscsi_hba *phba = beiscsi_conn->phba;
4291 struct iscsi_wrb *pwrb = NULL;
4292 unsigned int doorbell = 0;
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05304293 unsigned int cid;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304294
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304295 cid = beiscsi_conn->beiscsi_conn_cid;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304296 pwrb = io_task->pwrb_handle->pwrb;
Jayamohan Kallickalcaf818f2010-01-23 05:38:18 +05304297 memset(pwrb, 0, sizeof(*pwrb));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304298 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
4299 be32_to_cpu(task->cmdsn));
4300 AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
4301 io_task->pwrb_handle->wrb_index);
4302 AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
4303 io_task->psgl_handle->sgl_index);
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05304304
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304305 switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
4306 case ISCSI_OP_LOGIN:
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304307 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4308 TGT_DM_CMD);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304309 AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
4310 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, 1);
4311 hwi_write_buffer(pwrb, task);
4312 break;
4313 case ISCSI_OP_NOOP_OUT:
Jayamohan Kallickal1390b012011-03-25 14:24:01 -07004314 if (task->hdr->ttt != ISCSI_RESERVED_TAG) {
4315 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4316 TGT_DM_CMD);
4317 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt,
4318 pwrb, 0);
Jayamohan Kallickal685e16f2011-10-07 19:31:09 -05004319 AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 1);
Jayamohan Kallickal1390b012011-03-25 14:24:01 -07004320 } else {
4321 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4322 INI_RD_CMD);
Jayamohan Kallickal685e16f2011-10-07 19:31:09 -05004323 AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
Jayamohan Kallickal1390b012011-03-25 14:24:01 -07004324 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304325 hwi_write_buffer(pwrb, task);
4326 break;
4327 case ISCSI_OP_TEXT:
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304328 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
Jayamohan Kallickalb30c6da2010-01-23 05:38:56 +05304329 TGT_DM_CMD);
Jayamohan Kallickal0ecb0b42010-01-05 05:09:19 +05304330 AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304331 hwi_write_buffer(pwrb, task);
4332 break;
4333 case ISCSI_OP_SCSI_TMFUNC:
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304334 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4335 INI_TMF_CMD);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304336 AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
4337 hwi_write_buffer(pwrb, task);
4338 break;
4339 case ISCSI_OP_LOGOUT:
4340 AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
4341 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05304342 HWH_TYPE_LOGOUT);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304343 hwi_write_buffer(pwrb, task);
4344 break;
4345
4346 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +05304347 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
4348 "BM_%d : opcode =%d Not supported\n",
4349 task->hdr->opcode & ISCSI_OPCODE_MASK);
4350
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304351 return -EINVAL;
4352 }
4353
4354 AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb,
Jayamohan Kallickal51a46252010-01-05 05:10:01 +05304355 task->data_count);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304356 AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
4357 io_task->pwrb_handle->nxt_wrb_index);
4358 be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
4359
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304360 doorbell |= cid & DB_WRB_POST_CID_MASK;
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304361 doorbell |= (io_task->pwrb_handle->wrb_index &
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304362 DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
4363 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
4364 iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
4365 return 0;
4366}
4367
4368static int beiscsi_task_xmit(struct iscsi_task *task)
4369{
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304370 struct beiscsi_io_task *io_task = task->dd_data;
4371 struct scsi_cmnd *sc = task->sc;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304372 struct scatterlist *sg;
4373 int num_sg;
4374 unsigned int writedir = 0, xferlen = 0;
4375
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304376 if (!sc)
4377 return beiscsi_mtask(task);
4378
4379 io_task->scsi_cmnd = sc;
4380 num_sg = scsi_dma_map(sc);
4381 if (num_sg < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304382 struct iscsi_conn *conn = task->conn;
4383 struct beiscsi_hba *phba = NULL;
4384
4385 phba = ((struct beiscsi_conn *)conn->dd_data)->phba;
4386 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_IO,
4387 "BM_%d : scsi_dma_map Failed\n");
4388
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304389 return num_sg;
4390 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304391 xferlen = scsi_bufflen(sc);
4392 sg = scsi_sglist(sc);
John Soni Jose99bc5d52012-08-20 23:00:18 +05304393 if (sc->sc_data_direction == DMA_TO_DEVICE)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304394 writedir = 1;
John Soni Jose99bc5d52012-08-20 23:00:18 +05304395 else
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304396 writedir = 0;
John Soni Jose99bc5d52012-08-20 23:00:18 +05304397
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304398 return beiscsi_iotask(task, sg, num_sg, xferlen, writedir);
4399}
4400
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05004401/**
4402 * beiscsi_bsg_request - handle bsg request from ISCSI transport
4403 * @job: job to handle
4404 */
4405static int beiscsi_bsg_request(struct bsg_job *job)
4406{
4407 struct Scsi_Host *shost;
4408 struct beiscsi_hba *phba;
4409 struct iscsi_bsg_request *bsg_req = job->request;
4410 int rc = -EINVAL;
4411 unsigned int tag;
4412 struct be_dma_mem nonemb_cmd;
4413 struct be_cmd_resp_hdr *resp;
4414 struct iscsi_bsg_reply *bsg_reply = job->reply;
4415 unsigned short status, extd_status;
4416
4417 shost = iscsi_job_to_shost(job);
4418 phba = iscsi_host_priv(shost);
4419
4420 switch (bsg_req->msgcode) {
4421 case ISCSI_BSG_HST_VENDOR:
4422 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
4423 job->request_payload.payload_len,
4424 &nonemb_cmd.dma);
4425 if (nonemb_cmd.va == NULL) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304426 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
4427 "BM_%d : Failed to allocate memory for "
4428 "beiscsi_bsg_request\n");
John Soni Jose8359c792012-10-20 04:43:03 +05304429 return -ENOMEM;
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05004430 }
4431 tag = mgmt_vendor_specific_fw_cmd(&phba->ctrl, phba, job,
4432 &nonemb_cmd);
4433 if (!tag) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304434 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
John Soni Jose8359c792012-10-20 04:43:03 +05304435 "BM_%d : MBX Tag Allocation Failed\n");
John Soni Jose99bc5d52012-08-20 23:00:18 +05304436
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05004437 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
4438 nonemb_cmd.va, nonemb_cmd.dma);
4439 return -EAGAIN;
4440 } else
4441 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
4442 phba->ctrl.mcc_numtag[tag]);
4443 extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
4444 status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
4445 free_mcc_tag(&phba->ctrl, tag);
4446 resp = (struct be_cmd_resp_hdr *)nonemb_cmd.va;
4447 sg_copy_from_buffer(job->reply_payload.sg_list,
4448 job->reply_payload.sg_cnt,
4449 nonemb_cmd.va, (resp->response_length
4450 + sizeof(*resp)));
4451 bsg_reply->reply_payload_rcv_len = resp->response_length;
4452 bsg_reply->result = status;
4453 bsg_job_done(job, bsg_reply->result,
4454 bsg_reply->reply_payload_rcv_len);
4455 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
4456 nonemb_cmd.va, nonemb_cmd.dma);
4457 if (status || extd_status) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304458 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
John Soni Jose8359c792012-10-20 04:43:03 +05304459 "BM_%d : MBX Cmd Failed"
John Soni Jose99bc5d52012-08-20 23:00:18 +05304460 " status = %d extd_status = %d\n",
4461 status, extd_status);
4462
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05004463 return -EIO;
John Soni Jose8359c792012-10-20 04:43:03 +05304464 } else {
4465 rc = 0;
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05004466 }
4467 break;
4468
4469 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +05304470 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
4471 "BM_%d : Unsupported bsg command: 0x%x\n",
4472 bsg_req->msgcode);
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05004473 break;
4474 }
4475
4476 return rc;
4477}
4478
John Soni Jose99bc5d52012-08-20 23:00:18 +05304479void beiscsi_hba_attrs_init(struct beiscsi_hba *phba)
4480{
4481 /* Set the logging parameter */
4482 beiscsi_log_enable_init(phba, beiscsi_log_enable);
4483}
4484
John Soni Jose4d4d1ef2012-10-20 04:42:37 +05304485/*
4486 * beiscsi_quiesce()- Cleanup Driver resources
4487 * @phba: Instance Priv structure
4488 *
4489 * Free the OS and HW resources held by the driver
4490 **/
Jayamohan Kallickal25602c92011-08-22 10:08:28 -07004491static void beiscsi_quiesce(struct beiscsi_hba *phba)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304492{
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304493 struct hwi_controller *phwi_ctrlr;
4494 struct hwi_context_memory *phwi_context;
4495 struct be_eq_obj *pbe_eq;
4496 unsigned int i, msix_vec;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304497
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304498 phwi_ctrlr = phba->phwi_ctrlr;
4499 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304500 hwi_disable_intr(phba);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304501 if (phba->msix_enabled) {
4502 for (i = 0; i <= phba->num_cpus; i++) {
4503 msix_vec = phba->msix_entries[i].vector;
4504 free_irq(msix_vec, &phwi_context->be_eq[i]);
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -07004505 kfree(phba->msi_name[i]);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304506 }
4507 } else
4508 if (phba->pcidev->irq)
4509 free_irq(phba->pcidev->irq, phba);
4510 pci_disable_msix(phba->pcidev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304511 destroy_workqueue(phba->wq);
4512 if (blk_iopoll_enabled)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304513 for (i = 0; i < phba->num_cpus; i++) {
4514 pbe_eq = &phwi_context->be_eq[i];
4515 blk_iopoll_disable(&pbe_eq->iopoll);
4516 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304517
4518 beiscsi_clean_port(phba);
4519 beiscsi_free_mem(phba);
Jayamohan Kallickale9b91192010-07-22 04:24:53 +05304520
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304521 beiscsi_unmap_pci_function(phba);
4522 pci_free_consistent(phba->pcidev,
4523 phba->ctrl.mbox_mem_alloced.size,
4524 phba->ctrl.mbox_mem_alloced.va,
4525 phba->ctrl.mbox_mem_alloced.dma);
Jayamohan Kallickal25602c92011-08-22 10:08:28 -07004526}
4527
4528static void beiscsi_remove(struct pci_dev *pcidev)
4529{
4530
4531 struct beiscsi_hba *phba = NULL;
4532
4533 phba = pci_get_drvdata(pcidev);
4534 if (!phba) {
4535 dev_err(&pcidev->dev, "beiscsi_remove called with no phba\n");
4536 return;
4537 }
4538
Mike Christie0e438952012-04-03 23:41:51 -05004539 beiscsi_destroy_def_ifaces(phba);
Jayamohan Kallickal25602c92011-08-22 10:08:28 -07004540 beiscsi_quiesce(phba);
Mike Christie9d045162011-06-24 15:11:52 -05004541 iscsi_boot_destroy_kset(phba->boot_kset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304542 iscsi_host_remove(phba->shost);
4543 pci_dev_put(phba->pcidev);
4544 iscsi_host_free(phba->shost);
Jayamohan Kallickal8dce69f2011-08-22 10:08:29 -07004545 pci_disable_device(pcidev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304546}
4547
Jayamohan Kallickal25602c92011-08-22 10:08:28 -07004548static void beiscsi_shutdown(struct pci_dev *pcidev)
4549{
4550
4551 struct beiscsi_hba *phba = NULL;
4552
4553 phba = (struct beiscsi_hba *)pci_get_drvdata(pcidev);
4554 if (!phba) {
4555 dev_err(&pcidev->dev, "beiscsi_shutdown called with no phba\n");
4556 return;
4557 }
4558
4559 beiscsi_quiesce(phba);
Jayamohan Kallickal8dce69f2011-08-22 10:08:29 -07004560 pci_disable_device(pcidev);
Jayamohan Kallickal25602c92011-08-22 10:08:28 -07004561}
4562
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304563static void beiscsi_msix_enable(struct beiscsi_hba *phba)
4564{
4565 int i, status;
4566
4567 for (i = 0; i <= phba->num_cpus; i++)
4568 phba->msix_entries[i].entry = i;
4569
4570 status = pci_enable_msix(phba->pcidev, phba->msix_entries,
4571 (phba->num_cpus + 1));
4572 if (!status)
4573 phba->msix_enabled = true;
4574
4575 return;
4576}
4577
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304578static int __devinit beiscsi_dev_probe(struct pci_dev *pcidev,
4579 const struct pci_device_id *id)
4580{
4581 struct beiscsi_hba *phba = NULL;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304582 struct hwi_controller *phwi_ctrlr;
4583 struct hwi_context_memory *phwi_context;
4584 struct be_eq_obj *pbe_eq;
John Soni Jose107dfcb2012-10-20 04:42:13 +05304585 int ret, i;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304586
4587 ret = beiscsi_enable_pci(pcidev);
4588 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304589 dev_err(&pcidev->dev,
4590 "beiscsi_dev_probe - Failed to enable pci device\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304591 return ret;
4592 }
4593
4594 phba = beiscsi_hba_alloc(pcidev);
4595 if (!phba) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304596 dev_err(&pcidev->dev,
4597 "beiscsi_dev_probe - Failed in beiscsi_hba_alloc\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304598 goto disable_pci;
4599 }
4600
John Soni Jose99bc5d52012-08-20 23:00:18 +05304601 /* Initialize Driver configuration Paramters */
4602 beiscsi_hba_attrs_init(phba);
4603
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +05304604 switch (pcidev->device) {
4605 case BE_DEVICE_ID1:
4606 case OC_DEVICE_ID1:
4607 case OC_DEVICE_ID2:
4608 phba->generation = BE_GEN2;
4609 break;
4610 case BE_DEVICE_ID2:
4611 case OC_DEVICE_ID3:
4612 phba->generation = BE_GEN3;
4613 break;
4614 default:
4615 phba->generation = 0;
4616 }
4617
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304618 if (enable_msix)
John Soni Jose107dfcb2012-10-20 04:42:13 +05304619 find_num_cpus(phba);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304620 else
John Soni Jose107dfcb2012-10-20 04:42:13 +05304621 phba->num_cpus = 1;
4622
John Soni Jose99bc5d52012-08-20 23:00:18 +05304623 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4624 "BM_%d : num_cpus = %d\n",
4625 phba->num_cpus);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304626
Jayamohan Kallickalb547f2d2012-04-03 23:41:41 -05004627 if (enable_msix) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304628 beiscsi_msix_enable(phba);
Jayamohan Kallickalb547f2d2012-04-03 23:41:41 -05004629 if (!phba->msix_enabled)
4630 phba->num_cpus = 1;
4631 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304632 ret = be_ctrl_init(phba, pcidev);
4633 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304634 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4635 "BM_%d : beiscsi_dev_probe-"
4636 "Failed in be_ctrl_init\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304637 goto hba_free;
4638 }
4639
John Soni Jose4d4d1ef2012-10-20 04:42:37 +05304640 ret = beiscsi_cmd_reset_function(phba);
4641 if (ret) {
4642 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4643 "BM_%d : Reset Failed. Aborting Crashdump\n");
4644 goto hba_free;
4645 }
4646 ret = be_chk_reset_complete(phba);
4647 if (ret) {
4648 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4649 "BM_%d : Failed to get out of reset."
4650 "Aborting Crashdump\n");
4651 goto hba_free;
Jayamohan Kallickale9b91192010-07-22 04:24:53 +05304652 }
4653
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304654 spin_lock_init(&phba->io_sgl_lock);
4655 spin_lock_init(&phba->mgmt_sgl_lock);
4656 spin_lock_init(&phba->isr_lock);
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05304657 ret = mgmt_get_fw_config(&phba->ctrl, phba);
4658 if (ret != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304659 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4660 "BM_%d : Error getting fw config\n");
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05304661 goto free_port;
4662 }
4663 phba->shost->max_id = phba->fw_config.iscsi_cid_count;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304664 beiscsi_get_params(phba);
Jayamohan Kallickalaa874f02010-01-05 05:12:03 +05304665 phba->shost->can_queue = phba->params.ios_per_ctrl;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304666 ret = beiscsi_init_port(phba);
4667 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304668 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4669 "BM_%d : beiscsi_dev_probe-"
4670 "Failed in beiscsi_init_port\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304671 goto free_port;
4672 }
4673
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05304674 for (i = 0; i < MAX_MCC_CMD ; i++) {
4675 init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]);
4676 phba->ctrl.mcc_tag[i] = i + 1;
4677 phba->ctrl.mcc_numtag[i + 1] = 0;
4678 phba->ctrl.mcc_tag_available++;
4679 }
4680
4681 phba->ctrl.mcc_alloc_index = phba->ctrl.mcc_free_index = 0;
4682
John Soni Jose72fb46a2012-10-20 04:42:49 +05304683 snprintf(phba->wq_name, sizeof(phba->wq_name), "beiscsi_%02x_wq",
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304684 phba->shost->host_no);
Tejun Heo278274d2011-02-01 11:42:42 +01004685 phba->wq = alloc_workqueue(phba->wq_name, WQ_MEM_RECLAIM, 1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304686 if (!phba->wq) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304687 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4688 "BM_%d : beiscsi_dev_probe-"
4689 "Failed to allocate work queue\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304690 goto free_twq;
4691 }
4692
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304693
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304694 phwi_ctrlr = phba->phwi_ctrlr;
4695 phwi_context = phwi_ctrlr->phwi_ctxt;
John Soni Jose72fb46a2012-10-20 04:42:49 +05304696
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304697 if (blk_iopoll_enabled) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304698 for (i = 0; i < phba->num_cpus; i++) {
4699 pbe_eq = &phwi_context->be_eq[i];
4700 blk_iopoll_init(&pbe_eq->iopoll, be_iopoll_budget,
4701 be_iopoll);
4702 blk_iopoll_enable(&pbe_eq->iopoll);
4703 }
John Soni Jose72fb46a2012-10-20 04:42:49 +05304704
4705 i = (phba->msix_enabled) ? i : 0;
4706 /* Work item for MCC handling */
4707 pbe_eq = &phwi_context->be_eq[i];
4708 INIT_WORK(&pbe_eq->work_cqs, beiscsi_process_all_cqs);
4709 } else {
4710 if (phba->msix_enabled) {
4711 for (i = 0; i <= phba->num_cpus; i++) {
4712 pbe_eq = &phwi_context->be_eq[i];
4713 INIT_WORK(&pbe_eq->work_cqs,
4714 beiscsi_process_all_cqs);
4715 }
4716 } else {
4717 pbe_eq = &phwi_context->be_eq[0];
4718 INIT_WORK(&pbe_eq->work_cqs,
4719 beiscsi_process_all_cqs);
4720 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304721 }
John Soni Jose72fb46a2012-10-20 04:42:49 +05304722
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304723 ret = beiscsi_init_irqs(phba);
4724 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304725 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4726 "BM_%d : beiscsi_dev_probe-"
4727 "Failed to beiscsi_init_irqs\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304728 goto free_blkenbld;
4729 }
Jayamohan Kallickal238f6b72010-07-22 04:23:22 +05304730 hwi_enable_intr(phba);
Mike Christief457a462011-06-24 15:11:53 -05004731
4732 if (beiscsi_setup_boot_info(phba))
4733 /*
4734 * log error but continue, because we may not be using
4735 * iscsi boot.
4736 */
John Soni Jose99bc5d52012-08-20 23:00:18 +05304737 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4738 "BM_%d : Could not set up "
4739 "iSCSI boot info.\n");
Mike Christief457a462011-06-24 15:11:53 -05004740
Mike Christie0e438952012-04-03 23:41:51 -05004741 beiscsi_create_def_ifaces(phba);
John Soni Jose99bc5d52012-08-20 23:00:18 +05304742 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4743 "\n\n\n BM_%d : SUCCESS - DRIVER LOADED\n\n\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304744 return 0;
4745
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304746free_blkenbld:
4747 destroy_workqueue(phba->wq);
4748 if (blk_iopoll_enabled)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304749 for (i = 0; i < phba->num_cpus; i++) {
4750 pbe_eq = &phwi_context->be_eq[i];
4751 blk_iopoll_disable(&pbe_eq->iopoll);
4752 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304753free_twq:
4754 beiscsi_clean_port(phba);
4755 beiscsi_free_mem(phba);
4756free_port:
4757 pci_free_consistent(phba->pcidev,
4758 phba->ctrl.mbox_mem_alloced.size,
4759 phba->ctrl.mbox_mem_alloced.va,
4760 phba->ctrl.mbox_mem_alloced.dma);
4761 beiscsi_unmap_pci_function(phba);
4762hba_free:
Jayamohan Kallickal238f6b72010-07-22 04:23:22 +05304763 if (phba->msix_enabled)
4764 pci_disable_msix(phba->pcidev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304765 iscsi_host_remove(phba->shost);
4766 pci_dev_put(phba->pcidev);
4767 iscsi_host_free(phba->shost);
4768disable_pci:
4769 pci_disable_device(pcidev);
4770 return ret;
4771}
4772
4773struct iscsi_transport beiscsi_iscsi_transport = {
4774 .owner = THIS_MODULE,
4775 .name = DRV_NAME,
Jayamohan Kallickal9db0fb32010-01-05 05:12:43 +05304776 .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_TEXT_NEGO |
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304777 CAP_MULTI_R2T | CAP_DATADGST | CAP_DATA_PATH_OFFLOAD,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304778 .create_session = beiscsi_session_create,
4779 .destroy_session = beiscsi_session_destroy,
4780 .create_conn = beiscsi_conn_create,
4781 .bind_conn = beiscsi_conn_bind,
4782 .destroy_conn = iscsi_conn_teardown,
Mike Christie3128c6c2011-07-25 13:48:42 -05004783 .attr_is_visible = be2iscsi_attr_is_visible,
Mike Christie0e438952012-04-03 23:41:51 -05004784 .set_iface_param = be2iscsi_iface_set_param,
4785 .get_iface_param = be2iscsi_iface_get_param,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304786 .set_param = beiscsi_set_param,
Mike Christiec7f7fd52011-02-16 15:04:41 -06004787 .get_conn_param = iscsi_conn_get_param,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304788 .get_session_param = iscsi_session_get_param,
4789 .get_host_param = beiscsi_get_host_param,
4790 .start_conn = beiscsi_conn_start,
Mike Christiefa95d202010-06-09 03:30:08 -05004791 .stop_conn = iscsi_conn_stop,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304792 .send_pdu = iscsi_conn_send_pdu,
4793 .xmit_task = beiscsi_task_xmit,
4794 .cleanup_task = beiscsi_cleanup_task,
4795 .alloc_pdu = beiscsi_alloc_pdu,
4796 .parse_pdu_itt = beiscsi_parse_pdu,
4797 .get_stats = beiscsi_conn_get_stats,
Mike Christiec7f7fd52011-02-16 15:04:41 -06004798 .get_ep_param = beiscsi_ep_get_param,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304799 .ep_connect = beiscsi_ep_connect,
4800 .ep_poll = beiscsi_ep_poll,
4801 .ep_disconnect = beiscsi_ep_disconnect,
4802 .session_recovery_timedout = iscsi_session_recovery_timedout,
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05004803 .bsg_request = beiscsi_bsg_request,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304804};
4805
4806static struct pci_driver beiscsi_pci_driver = {
4807 .name = DRV_NAME,
4808 .probe = beiscsi_dev_probe,
4809 .remove = beiscsi_remove,
Jayamohan Kallickal25602c92011-08-22 10:08:28 -07004810 .shutdown = beiscsi_shutdown,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304811 .id_table = beiscsi_pci_id_table
4812};
4813
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304814
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304815static int __init beiscsi_module_init(void)
4816{
4817 int ret;
4818
4819 beiscsi_scsi_transport =
4820 iscsi_register_transport(&beiscsi_iscsi_transport);
4821 if (!beiscsi_scsi_transport) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304822 printk(KERN_ERR
4823 "beiscsi_module_init - Unable to register beiscsi transport.\n");
Jayamohan Kallickalf55a24f2010-01-23 05:37:40 +05304824 return -ENOMEM;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304825 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05304826 printk(KERN_INFO "In beiscsi_module_init, tt=%p\n",
4827 &beiscsi_iscsi_transport);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304828
4829 ret = pci_register_driver(&beiscsi_pci_driver);
4830 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304831 printk(KERN_ERR
4832 "beiscsi_module_init - Unable to register beiscsi pci driver.\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304833 goto unregister_iscsi_transport;
4834 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304835 return 0;
4836
4837unregister_iscsi_transport:
4838 iscsi_unregister_transport(&beiscsi_iscsi_transport);
4839 return ret;
4840}
4841
4842static void __exit beiscsi_module_exit(void)
4843{
4844 pci_unregister_driver(&beiscsi_pci_driver);
4845 iscsi_unregister_transport(&beiscsi_iscsi_transport);
4846}
4847
4848module_init(beiscsi_module_init);
4849module_exit(beiscsi_module_exit);