blob: d539b17e4a806ef48a2bd5d58e6e739052fc84e3 [file] [log] [blame]
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301/**
Jayamohan Kallickal533c1652013-04-05 20:38:34 -07002 * Copyright (C) 2005 - 2013 Emulex
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation. The full GNU General
8 * Public License is included in this distribution in the file called COPYING.
9 *
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070010 * Written by: Jayamohan Kallickal (jayamohan.kallickal@emulex.com)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053011 *
12 * Contact Information:
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070013 * linux-drivers@emulex.com
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053014 *
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070015 * Emulex
16 * 3333 Susan Street
17 * Costa Mesa, CA 92626
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053018 */
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070019
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053020#include <linux/reboot.h>
21#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/slab.h>
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053023#include <linux/interrupt.h>
24#include <linux/blkdev.h>
25#include <linux/pci.h>
26#include <linux/string.h>
27#include <linux/kernel.h>
28#include <linux/semaphore.h>
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +053029#include <linux/iscsi_boot_sysfs.h>
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040030#include <linux/module.h>
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -050031#include <linux/bsg-lib.h>
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053032
33#include <scsi/libiscsi.h>
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -050034#include <scsi/scsi_bsg_iscsi.h>
35#include <scsi/scsi_netlink.h>
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053036#include <scsi/scsi_transport_iscsi.h>
37#include <scsi/scsi_transport.h>
38#include <scsi/scsi_cmnd.h>
39#include <scsi/scsi_device.h>
40#include <scsi/scsi_host.h>
41#include <scsi/scsi.h>
42#include "be_main.h"
43#include "be_iscsi.h"
44#include "be_mgmt.h"
John Soni Jose0a513dd2012-08-20 23:00:55 +053045#include "be_cmds.h"
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053046
47static unsigned int be_iopoll_budget = 10;
48static unsigned int be_max_phys_size = 64;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +053049static unsigned int enable_msix = 1;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053050
51MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
52MODULE_DESCRIPTION(DRV_DESC " " BUILD_STR);
Jayamohan Kallickal76d15db2012-04-03 23:41:46 -050053MODULE_VERSION(BUILD_STR);
Jayamohan Kallickal2f635882012-04-03 23:41:45 -050054MODULE_AUTHOR("Emulex Corporation");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053055MODULE_LICENSE("GPL");
56module_param(be_iopoll_budget, int, 0);
57module_param(enable_msix, int, 0);
58module_param(be_max_phys_size, uint, S_IRUGO);
John Soni Jose99bc5d52012-08-20 23:00:18 +053059MODULE_PARM_DESC(be_max_phys_size,
60 "Maximum Size (In Kilobytes) of physically contiguous "
61 "memory that can be allocated. Range is 16 - 128");
62
63#define beiscsi_disp_param(_name)\
64ssize_t \
65beiscsi_##_name##_disp(struct device *dev,\
66 struct device_attribute *attrib, char *buf) \
67{ \
68 struct Scsi_Host *shost = class_to_shost(dev);\
69 struct beiscsi_hba *phba = iscsi_host_priv(shost); \
70 uint32_t param_val = 0; \
71 param_val = phba->attr_##_name;\
72 return snprintf(buf, PAGE_SIZE, "%d\n",\
73 phba->attr_##_name);\
74}
75
76#define beiscsi_change_param(_name, _minval, _maxval, _defaval)\
77int \
78beiscsi_##_name##_change(struct beiscsi_hba *phba, uint32_t val)\
79{\
80 if (val >= _minval && val <= _maxval) {\
81 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,\
82 "BA_%d : beiscsi_"#_name" updated "\
83 "from 0x%x ==> 0x%x\n",\
84 phba->attr_##_name, val); \
85 phba->attr_##_name = val;\
86 return 0;\
87 } \
88 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, \
89 "BA_%d beiscsi_"#_name" attribute "\
90 "cannot be updated to 0x%x, "\
91 "range allowed is ["#_minval" - "#_maxval"]\n", val);\
92 return -EINVAL;\
93}
94
95#define beiscsi_store_param(_name) \
96ssize_t \
97beiscsi_##_name##_store(struct device *dev,\
98 struct device_attribute *attr, const char *buf,\
99 size_t count) \
100{ \
101 struct Scsi_Host *shost = class_to_shost(dev);\
102 struct beiscsi_hba *phba = iscsi_host_priv(shost);\
103 uint32_t param_val = 0;\
104 if (!isdigit(buf[0]))\
105 return -EINVAL;\
106 if (sscanf(buf, "%i", &param_val) != 1)\
107 return -EINVAL;\
108 if (beiscsi_##_name##_change(phba, param_val) == 0) \
109 return strlen(buf);\
110 else \
111 return -EINVAL;\
112}
113
114#define beiscsi_init_param(_name, _minval, _maxval, _defval) \
115int \
116beiscsi_##_name##_init(struct beiscsi_hba *phba, uint32_t val) \
117{ \
118 if (val >= _minval && val <= _maxval) {\
119 phba->attr_##_name = val;\
120 return 0;\
121 } \
122 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,\
123 "BA_%d beiscsi_"#_name" attribute " \
124 "cannot be updated to 0x%x, "\
125 "range allowed is ["#_minval" - "#_maxval"]\n", val);\
126 phba->attr_##_name = _defval;\
127 return -EINVAL;\
128}
129
130#define BEISCSI_RW_ATTR(_name, _minval, _maxval, _defval, _descp) \
131static uint beiscsi_##_name = _defval;\
132module_param(beiscsi_##_name, uint, S_IRUGO);\
133MODULE_PARM_DESC(beiscsi_##_name, _descp);\
134beiscsi_disp_param(_name)\
135beiscsi_change_param(_name, _minval, _maxval, _defval)\
136beiscsi_store_param(_name)\
137beiscsi_init_param(_name, _minval, _maxval, _defval)\
138DEVICE_ATTR(beiscsi_##_name, S_IRUGO | S_IWUSR,\
139 beiscsi_##_name##_disp, beiscsi_##_name##_store)
140
141/*
142 * When new log level added update the
143 * the MAX allowed value for log_enable
144 */
145BEISCSI_RW_ATTR(log_enable, 0x00,
146 0xFF, 0x00, "Enable logging Bit Mask\n"
147 "\t\t\t\tInitialization Events : 0x01\n"
148 "\t\t\t\tMailbox Events : 0x02\n"
149 "\t\t\t\tMiscellaneous Events : 0x04\n"
150 "\t\t\t\tError Handling : 0x08\n"
151 "\t\t\t\tIO Path Events : 0x10\n"
152 "\t\t\t\tConfiguration Path : 0x20\n");
153
John Soni Jose5cac7592012-10-20 04:42:25 +0530154DEVICE_ATTR(beiscsi_drvr_ver, S_IRUGO, beiscsi_drvr_ver_disp, NULL);
John Soni Jose26000db2012-10-20 04:45:06 +0530155DEVICE_ATTR(beiscsi_adapter_family, S_IRUGO, beiscsi_adap_family_disp, NULL);
Jayamohan Kallickal22661e22013-04-05 20:38:28 -0700156DEVICE_ATTR(beiscsi_fw_ver, S_IRUGO, beiscsi_fw_ver_disp, NULL);
Jayamohan Kallickal7ad4dfe2013-04-05 20:38:29 -0700157DEVICE_ATTR(beiscsi_active_cid_count, S_IRUGO, beiscsi_active_cid_disp, NULL);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530158struct device_attribute *beiscsi_attrs[] = {
159 &dev_attr_beiscsi_log_enable,
John Soni Jose5cac7592012-10-20 04:42:25 +0530160 &dev_attr_beiscsi_drvr_ver,
John Soni Jose26000db2012-10-20 04:45:06 +0530161 &dev_attr_beiscsi_adapter_family,
Jayamohan Kallickal22661e22013-04-05 20:38:28 -0700162 &dev_attr_beiscsi_fw_ver,
Jayamohan Kallickal7ad4dfe2013-04-05 20:38:29 -0700163 &dev_attr_beiscsi_active_cid_count,
John Soni Jose99bc5d52012-08-20 23:00:18 +0530164 NULL,
165};
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530166
John Soni Jose6763daa2012-10-20 04:41:45 +0530167static char const *cqe_desc[] = {
168 "RESERVED_DESC",
169 "SOL_CMD_COMPLETE",
170 "SOL_CMD_KILLED_DATA_DIGEST_ERR",
171 "CXN_KILLED_PDU_SIZE_EXCEEDS_DSL",
172 "CXN_KILLED_BURST_LEN_MISMATCH",
173 "CXN_KILLED_AHS_RCVD",
174 "CXN_KILLED_HDR_DIGEST_ERR",
175 "CXN_KILLED_UNKNOWN_HDR",
176 "CXN_KILLED_STALE_ITT_TTT_RCVD",
177 "CXN_KILLED_INVALID_ITT_TTT_RCVD",
178 "CXN_KILLED_RST_RCVD",
179 "CXN_KILLED_TIMED_OUT",
180 "CXN_KILLED_RST_SENT",
181 "CXN_KILLED_FIN_RCVD",
182 "CXN_KILLED_BAD_UNSOL_PDU_RCVD",
183 "CXN_KILLED_BAD_WRB_INDEX_ERROR",
184 "CXN_KILLED_OVER_RUN_RESIDUAL",
185 "CXN_KILLED_UNDER_RUN_RESIDUAL",
186 "CMD_KILLED_INVALID_STATSN_RCVD",
187 "CMD_KILLED_INVALID_R2T_RCVD",
188 "CMD_CXN_KILLED_LUN_INVALID",
189 "CMD_CXN_KILLED_ICD_INVALID",
190 "CMD_CXN_KILLED_ITT_INVALID",
191 "CMD_CXN_KILLED_SEQ_OUTOFORDER",
192 "CMD_CXN_KILLED_INVALID_DATASN_RCVD",
193 "CXN_INVALIDATE_NOTIFY",
194 "CXN_INVALIDATE_INDEX_NOTIFY",
195 "CMD_INVALIDATED_NOTIFY",
196 "UNSOL_HDR_NOTIFY",
197 "UNSOL_DATA_NOTIFY",
198 "UNSOL_DATA_DIGEST_ERROR_NOTIFY",
199 "DRIVERMSG_NOTIFY",
200 "CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN",
201 "SOL_CMD_KILLED_DIF_ERR",
202 "CXN_KILLED_SYN_RCVD",
203 "CXN_KILLED_IMM_DATA_RCVD"
204};
205
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530206static int beiscsi_slave_configure(struct scsi_device *sdev)
207{
208 blk_queue_max_segment_size(sdev->request_queue, 65536);
209 return 0;
210}
211
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530212static int beiscsi_eh_abort(struct scsi_cmnd *sc)
213{
214 struct iscsi_cls_session *cls_session;
215 struct iscsi_task *aborted_task = (struct iscsi_task *)sc->SCp.ptr;
216 struct beiscsi_io_task *aborted_io_task;
217 struct iscsi_conn *conn;
218 struct beiscsi_conn *beiscsi_conn;
219 struct beiscsi_hba *phba;
220 struct iscsi_session *session;
221 struct invalidate_command_table *inv_tbl;
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530222 struct be_dma_mem nonemb_cmd;
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530223 unsigned int cid, tag, num_invalidate;
224
225 cls_session = starget_to_session(scsi_target(sc->device));
226 session = cls_session->dd_data;
227
228 spin_lock_bh(&session->lock);
229 if (!aborted_task || !aborted_task->sc) {
230 /* we raced */
231 spin_unlock_bh(&session->lock);
232 return SUCCESS;
233 }
234
235 aborted_io_task = aborted_task->dd_data;
236 if (!aborted_io_task->scsi_cmnd) {
237 /* raced or invalid command */
238 spin_unlock_bh(&session->lock);
239 return SUCCESS;
240 }
241 spin_unlock_bh(&session->lock);
242 conn = aborted_task->conn;
243 beiscsi_conn = conn->dd_data;
244 phba = beiscsi_conn->phba;
245
246 /* invalidate iocb */
247 cid = beiscsi_conn->beiscsi_conn_cid;
248 inv_tbl = phba->inv_tbl;
249 memset(inv_tbl, 0x0, sizeof(*inv_tbl));
250 inv_tbl->cid = cid;
251 inv_tbl->icd = aborted_io_task->psgl_handle->sgl_index;
252 num_invalidate = 1;
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530253 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
254 sizeof(struct invalidate_commands_params_in),
255 &nonemb_cmd.dma);
256 if (nonemb_cmd.va == NULL) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530257 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
258 "BM_%d : Failed to allocate memory for"
259 "mgmt_invalidate_icds\n");
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530260 return FAILED;
261 }
262 nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
263
264 tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
265 cid, &nonemb_cmd);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530266 if (!tag) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530267 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH,
268 "BM_%d : mgmt_invalidate_icds could not be"
269 "submitted\n");
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530270 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
271 nonemb_cmd.va, nonemb_cmd.dma);
272
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530273 return FAILED;
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530274 }
John Soni Josee175def2012-10-20 04:45:40 +0530275
276 beiscsi_mccq_compl(phba, tag, NULL, nonemb_cmd.va);
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530277 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
278 nonemb_cmd.va, nonemb_cmd.dma);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530279 return iscsi_eh_abort(sc);
280}
281
282static int beiscsi_eh_device_reset(struct scsi_cmnd *sc)
283{
284 struct iscsi_task *abrt_task;
285 struct beiscsi_io_task *abrt_io_task;
286 struct iscsi_conn *conn;
287 struct beiscsi_conn *beiscsi_conn;
288 struct beiscsi_hba *phba;
289 struct iscsi_session *session;
290 struct iscsi_cls_session *cls_session;
291 struct invalidate_command_table *inv_tbl;
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530292 struct be_dma_mem nonemb_cmd;
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530293 unsigned int cid, tag, i, num_invalidate;
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530294
295 /* invalidate iocbs */
296 cls_session = starget_to_session(scsi_target(sc->device));
297 session = cls_session->dd_data;
298 spin_lock_bh(&session->lock);
Jayamohan Kallickaldb7f7702012-04-03 23:41:43 -0500299 if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN) {
300 spin_unlock_bh(&session->lock);
301 return FAILED;
302 }
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530303 conn = session->leadconn;
304 beiscsi_conn = conn->dd_data;
305 phba = beiscsi_conn->phba;
306 cid = beiscsi_conn->beiscsi_conn_cid;
307 inv_tbl = phba->inv_tbl;
308 memset(inv_tbl, 0x0, sizeof(*inv_tbl) * BE2_CMDS_PER_CXN);
309 num_invalidate = 0;
310 for (i = 0; i < conn->session->cmds_max; i++) {
311 abrt_task = conn->session->cmds[i];
312 abrt_io_task = abrt_task->dd_data;
313 if (!abrt_task->sc || abrt_task->state == ISCSI_TASK_FREE)
314 continue;
315
316 if (abrt_task->sc->device->lun != abrt_task->sc->device->lun)
317 continue;
318
319 inv_tbl->cid = cid;
320 inv_tbl->icd = abrt_io_task->psgl_handle->sgl_index;
321 num_invalidate++;
322 inv_tbl++;
323 }
324 spin_unlock_bh(&session->lock);
325 inv_tbl = phba->inv_tbl;
326
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530327 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
328 sizeof(struct invalidate_commands_params_in),
329 &nonemb_cmd.dma);
330 if (nonemb_cmd.va == NULL) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530331 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
332 "BM_%d : Failed to allocate memory for"
333 "mgmt_invalidate_icds\n");
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530334 return FAILED;
335 }
336 nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
337 memset(nonemb_cmd.va, 0, nonemb_cmd.size);
338 tag = mgmt_invalidate_icds(phba, inv_tbl, num_invalidate,
339 cid, &nonemb_cmd);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530340 if (!tag) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530341 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_EH,
342 "BM_%d : mgmt_invalidate_icds could not be"
343 " submitted\n");
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530344 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
345 nonemb_cmd.va, nonemb_cmd.dma);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530346 return FAILED;
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530347 }
John Soni Josee175def2012-10-20 04:45:40 +0530348
349 beiscsi_mccq_compl(phba, tag, NULL, nonemb_cmd.va);
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530350 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
351 nonemb_cmd.va, nonemb_cmd.dma);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530352 return iscsi_eh_device_reset(sc);
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530353}
354
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530355static ssize_t beiscsi_show_boot_tgt_info(void *data, int type, char *buf)
356{
357 struct beiscsi_hba *phba = data;
Mike Christief457a462011-06-24 15:11:53 -0500358 struct mgmt_session_info *boot_sess = &phba->boot_sess;
359 struct mgmt_conn_info *boot_conn = &boot_sess->conn_list[0];
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530360 char *str = buf;
361 int rc;
362
363 switch (type) {
364 case ISCSI_BOOT_TGT_NAME:
365 rc = sprintf(buf, "%.*s\n",
Mike Christief457a462011-06-24 15:11:53 -0500366 (int)strlen(boot_sess->target_name),
367 (char *)&boot_sess->target_name);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530368 break;
369 case ISCSI_BOOT_TGT_IP_ADDR:
Mike Christief457a462011-06-24 15:11:53 -0500370 if (boot_conn->dest_ipaddr.ip_type == 0x1)
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530371 rc = sprintf(buf, "%pI4\n",
Mike Christie0e438952012-04-03 23:41:51 -0500372 (char *)&boot_conn->dest_ipaddr.addr);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530373 else
374 rc = sprintf(str, "%pI6\n",
Mike Christie0e438952012-04-03 23:41:51 -0500375 (char *)&boot_conn->dest_ipaddr.addr);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530376 break;
377 case ISCSI_BOOT_TGT_PORT:
Mike Christief457a462011-06-24 15:11:53 -0500378 rc = sprintf(str, "%d\n", boot_conn->dest_port);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530379 break;
380
381 case ISCSI_BOOT_TGT_CHAP_NAME:
382 rc = sprintf(str, "%.*s\n",
Mike Christief457a462011-06-24 15:11:53 -0500383 boot_conn->negotiated_login_options.auth_data.chap.
384 target_chap_name_length,
385 (char *)&boot_conn->negotiated_login_options.
386 auth_data.chap.target_chap_name);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530387 break;
388 case ISCSI_BOOT_TGT_CHAP_SECRET:
389 rc = sprintf(str, "%.*s\n",
Mike Christief457a462011-06-24 15:11:53 -0500390 boot_conn->negotiated_login_options.auth_data.chap.
391 target_secret_length,
392 (char *)&boot_conn->negotiated_login_options.
393 auth_data.chap.target_secret);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530394 break;
395 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
396 rc = sprintf(str, "%.*s\n",
Mike Christief457a462011-06-24 15:11:53 -0500397 boot_conn->negotiated_login_options.auth_data.chap.
398 intr_chap_name_length,
399 (char *)&boot_conn->negotiated_login_options.
400 auth_data.chap.intr_chap_name);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530401 break;
402 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
Mike Christief457a462011-06-24 15:11:53 -0500403 rc = sprintf(str, "%.*s\n",
404 boot_conn->negotiated_login_options.auth_data.chap.
405 intr_secret_length,
406 (char *)&boot_conn->negotiated_login_options.
407 auth_data.chap.intr_secret);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530408 break;
409 case ISCSI_BOOT_TGT_FLAGS:
Mike Christief457a462011-06-24 15:11:53 -0500410 rc = sprintf(str, "2\n");
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530411 break;
412 case ISCSI_BOOT_TGT_NIC_ASSOC:
Mike Christief457a462011-06-24 15:11:53 -0500413 rc = sprintf(str, "0\n");
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530414 break;
415 default:
416 rc = -ENOSYS;
417 break;
418 }
419 return rc;
420}
421
422static ssize_t beiscsi_show_boot_ini_info(void *data, int type, char *buf)
423{
424 struct beiscsi_hba *phba = data;
425 char *str = buf;
426 int rc;
427
428 switch (type) {
429 case ISCSI_BOOT_INI_INITIATOR_NAME:
430 rc = sprintf(str, "%s\n", phba->boot_sess.initiator_iscsiname);
431 break;
432 default:
433 rc = -ENOSYS;
434 break;
435 }
436 return rc;
437}
438
439static ssize_t beiscsi_show_boot_eth_info(void *data, int type, char *buf)
440{
441 struct beiscsi_hba *phba = data;
442 char *str = buf;
443 int rc;
444
445 switch (type) {
446 case ISCSI_BOOT_ETH_FLAGS:
Mike Christief457a462011-06-24 15:11:53 -0500447 rc = sprintf(str, "2\n");
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530448 break;
449 case ISCSI_BOOT_ETH_INDEX:
Mike Christief457a462011-06-24 15:11:53 -0500450 rc = sprintf(str, "0\n");
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530451 break;
452 case ISCSI_BOOT_ETH_MAC:
Mike Christie0e438952012-04-03 23:41:51 -0500453 rc = beiscsi_get_macaddr(str, phba);
454 break;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530455 default:
456 rc = -ENOSYS;
457 break;
458 }
459 return rc;
460}
461
462
Al Viro587a1f12011-07-23 23:11:19 -0400463static umode_t beiscsi_tgt_get_attr_visibility(void *data, int type)
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530464{
Al Viro587a1f12011-07-23 23:11:19 -0400465 umode_t rc;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530466
467 switch (type) {
468 case ISCSI_BOOT_TGT_NAME:
469 case ISCSI_BOOT_TGT_IP_ADDR:
470 case ISCSI_BOOT_TGT_PORT:
471 case ISCSI_BOOT_TGT_CHAP_NAME:
472 case ISCSI_BOOT_TGT_CHAP_SECRET:
473 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
474 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
475 case ISCSI_BOOT_TGT_NIC_ASSOC:
476 case ISCSI_BOOT_TGT_FLAGS:
477 rc = S_IRUGO;
478 break;
479 default:
480 rc = 0;
481 break;
482 }
483 return rc;
484}
485
Al Viro587a1f12011-07-23 23:11:19 -0400486static umode_t beiscsi_ini_get_attr_visibility(void *data, int type)
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530487{
Al Viro587a1f12011-07-23 23:11:19 -0400488 umode_t rc;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530489
490 switch (type) {
491 case ISCSI_BOOT_INI_INITIATOR_NAME:
492 rc = S_IRUGO;
493 break;
494 default:
495 rc = 0;
496 break;
497 }
498 return rc;
499}
500
501
Al Viro587a1f12011-07-23 23:11:19 -0400502static umode_t beiscsi_eth_get_attr_visibility(void *data, int type)
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530503{
Al Viro587a1f12011-07-23 23:11:19 -0400504 umode_t rc;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530505
506 switch (type) {
507 case ISCSI_BOOT_ETH_FLAGS:
508 case ISCSI_BOOT_ETH_MAC:
509 case ISCSI_BOOT_ETH_INDEX:
510 rc = S_IRUGO;
511 break;
512 default:
513 rc = 0;
514 break;
515 }
516 return rc;
517}
518
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530519/*------------------- PCI Driver operations and data ----------------- */
520static DEFINE_PCI_DEVICE_TABLE(beiscsi_pci_id_table) = {
521 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) },
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +0530522 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) },
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530523 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) },
524 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) },
525 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID3) },
John Soni Jose139a1b12012-10-20 04:43:20 +0530526 { PCI_DEVICE(ELX_VENDOR_ID, OC_SKH_ID1) },
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530527 { 0 }
528};
529MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
530
John Soni Jose99bc5d52012-08-20 23:00:18 +0530531
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530532static struct scsi_host_template beiscsi_sht = {
533 .module = THIS_MODULE,
Jayamohan Kallickal2f635882012-04-03 23:41:45 -0500534 .name = "Emulex 10Gbe open-iscsi Initiator Driver",
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530535 .proc_name = DRV_NAME,
536 .queuecommand = iscsi_queuecommand,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530537 .change_queue_depth = iscsi_change_queue_depth,
538 .slave_configure = beiscsi_slave_configure,
539 .target_alloc = iscsi_target_alloc,
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530540 .eh_abort_handler = beiscsi_eh_abort,
541 .eh_device_reset_handler = beiscsi_eh_device_reset,
Jayamohan Kallickal309ce152010-02-20 08:02:10 +0530542 .eh_target_reset_handler = iscsi_eh_session_reset,
John Soni Jose99bc5d52012-08-20 23:00:18 +0530543 .shost_attrs = beiscsi_attrs,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530544 .sg_tablesize = BEISCSI_SGLIST_ELEMENTS,
545 .can_queue = BE2_IO_DEPTH,
546 .this_id = -1,
547 .max_sectors = BEISCSI_MAX_SECTORS,
548 .cmd_per_lun = BEISCSI_CMD_PER_LUN,
549 .use_clustering = ENABLE_CLUSTERING,
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -0500550 .vendor_id = SCSI_NL_VID_TYPE_PCI | BE_VENDOR_ID,
551
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530552};
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530553
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530554static struct scsi_transport_template *beiscsi_scsi_transport;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530555
556static struct beiscsi_hba *beiscsi_hba_alloc(struct pci_dev *pcidev)
557{
558 struct beiscsi_hba *phba;
559 struct Scsi_Host *shost;
560
561 shost = iscsi_host_alloc(&beiscsi_sht, sizeof(*phba), 0);
562 if (!shost) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530563 dev_err(&pcidev->dev,
564 "beiscsi_hba_alloc - iscsi_host_alloc failed\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530565 return NULL;
566 }
567 shost->dma_boundary = pcidev->dma_mask;
568 shost->max_id = BE2_MAX_SESSIONS;
569 shost->max_channel = 0;
570 shost->max_cmd_len = BEISCSI_MAX_CMD_LEN;
571 shost->max_lun = BEISCSI_NUM_MAX_LUN;
572 shost->transportt = beiscsi_scsi_transport;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530573 phba = iscsi_host_priv(shost);
574 memset(phba, 0, sizeof(*phba));
575 phba->shost = shost;
576 phba->pcidev = pci_dev_get(pcidev);
Jayamohan Kallickal2807afb2010-01-05 05:07:49 +0530577 pci_set_drvdata(pcidev, phba);
Mike Christie0e438952012-04-03 23:41:51 -0500578 phba->interface_handle = 0xFFFFFFFF;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530579
580 if (iscsi_host_add(shost, &phba->pcidev->dev))
581 goto free_devices;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530582
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530583 return phba;
584
585free_devices:
586 pci_dev_put(phba->pcidev);
587 iscsi_host_free(phba->shost);
588 return NULL;
589}
590
591static void beiscsi_unmap_pci_function(struct beiscsi_hba *phba)
592{
593 if (phba->csr_va) {
594 iounmap(phba->csr_va);
595 phba->csr_va = NULL;
596 }
597 if (phba->db_va) {
598 iounmap(phba->db_va);
599 phba->db_va = NULL;
600 }
601 if (phba->pci_va) {
602 iounmap(phba->pci_va);
603 phba->pci_va = NULL;
604 }
605}
606
607static int beiscsi_map_pci_bars(struct beiscsi_hba *phba,
608 struct pci_dev *pcidev)
609{
610 u8 __iomem *addr;
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +0530611 int pcicfg_reg;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530612
613 addr = ioremap_nocache(pci_resource_start(pcidev, 2),
614 pci_resource_len(pcidev, 2));
615 if (addr == NULL)
616 return -ENOMEM;
617 phba->ctrl.csr = addr;
618 phba->csr_va = addr;
619 phba->csr_pa.u.a64.address = pci_resource_start(pcidev, 2);
620
621 addr = ioremap_nocache(pci_resource_start(pcidev, 4), 128 * 1024);
622 if (addr == NULL)
623 goto pci_map_err;
624 phba->ctrl.db = addr;
625 phba->db_va = addr;
626 phba->db_pa.u.a64.address = pci_resource_start(pcidev, 4);
627
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +0530628 if (phba->generation == BE_GEN2)
629 pcicfg_reg = 1;
630 else
631 pcicfg_reg = 0;
632
633 addr = ioremap_nocache(pci_resource_start(pcidev, pcicfg_reg),
634 pci_resource_len(pcidev, pcicfg_reg));
635
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530636 if (addr == NULL)
637 goto pci_map_err;
638 phba->ctrl.pcicfg = addr;
639 phba->pci_va = addr;
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +0530640 phba->pci_pa.u.a64.address = pci_resource_start(pcidev, pcicfg_reg);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530641 return 0;
642
643pci_map_err:
644 beiscsi_unmap_pci_function(phba);
645 return -ENOMEM;
646}
647
648static int beiscsi_enable_pci(struct pci_dev *pcidev)
649{
650 int ret;
651
652 ret = pci_enable_device(pcidev);
653 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530654 dev_err(&pcidev->dev,
655 "beiscsi_enable_pci - enable device failed\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530656 return ret;
657 }
658
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530659 pci_set_master(pcidev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530660 if (pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64))) {
661 ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(32));
662 if (ret) {
663 dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n");
664 pci_disable_device(pcidev);
665 return ret;
666 }
667 }
668 return 0;
669}
670
671static int be_ctrl_init(struct beiscsi_hba *phba, struct pci_dev *pdev)
672{
673 struct be_ctrl_info *ctrl = &phba->ctrl;
674 struct be_dma_mem *mbox_mem_alloc = &ctrl->mbox_mem_alloced;
675 struct be_dma_mem *mbox_mem_align = &ctrl->mbox_mem;
676 int status = 0;
677
678 ctrl->pdev = pdev;
679 status = beiscsi_map_pci_bars(phba, pdev);
680 if (status)
681 return status;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530682 mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16;
683 mbox_mem_alloc->va = pci_alloc_consistent(pdev,
684 mbox_mem_alloc->size,
685 &mbox_mem_alloc->dma);
686 if (!mbox_mem_alloc->va) {
687 beiscsi_unmap_pci_function(phba);
Jayamohan Kallickala49e06d2012-04-03 23:41:44 -0500688 return -ENOMEM;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530689 }
690
691 mbox_mem_align->size = sizeof(struct be_mcc_mailbox);
692 mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16);
693 mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16);
694 memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox));
695 spin_lock_init(&ctrl->mbox_lock);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530696 spin_lock_init(&phba->ctrl.mcc_lock);
697 spin_lock_init(&phba->ctrl.mcc_cq_lock);
698
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530699 return status;
700}
701
Jayamohan Kallickal843ae752013-09-28 15:35:44 -0700702/**
703 * beiscsi_get_params()- Set the config paramters
704 * @phba: ptr device priv structure
705 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530706static void beiscsi_get_params(struct beiscsi_hba *phba)
707{
Jayamohan Kallickal843ae752013-09-28 15:35:44 -0700708 uint32_t total_cid_count = 0;
709 uint32_t total_icd_count = 0;
710 uint8_t ulp_num = 0;
711
712 total_cid_count = BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP0) +
713 BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP1);
714
715 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
716 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
717 total_icd_count = phba->fw_config.
718 iscsi_icd_count[ulp_num];
719 break;
720 }
721
722 phba->params.ios_per_ctrl = (total_icd_count -
723 (total_cid_count +
724 BE2_TMFS + BE2_NOPOUT_REQ));
725 phba->params.cxns_per_ctrl = total_cid_count;
726 phba->params.asyncpdus_per_ctrl = total_cid_count;
727 phba->params.icds_per_ctrl = total_icd_count;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530728 phba->params.num_sge_per_io = BE2_SGE;
729 phba->params.defpdu_hdr_sz = BE2_DEFPDU_HDR_SZ;
730 phba->params.defpdu_data_sz = BE2_DEFPDU_DATA_SZ;
731 phba->params.eq_timer = 64;
Jayamohan Kallickal843ae752013-09-28 15:35:44 -0700732 phba->params.num_eq_entries = 1024;
733 phba->params.num_cq_entries = 1024;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530734 phba->params.wrbs_per_cxn = 256;
735}
736
737static void hwi_ring_eq_db(struct beiscsi_hba *phba,
738 unsigned int id, unsigned int clr_interrupt,
739 unsigned int num_processed,
740 unsigned char rearm, unsigned char event)
741{
742 u32 val = 0;
743 val |= id & DB_EQ_RING_ID_MASK;
744 if (rearm)
745 val |= 1 << DB_EQ_REARM_SHIFT;
746 if (clr_interrupt)
747 val |= 1 << DB_EQ_CLR_SHIFT;
748 if (event)
749 val |= 1 << DB_EQ_EVNT_SHIFT;
750 val |= num_processed << DB_EQ_NUM_POPPED_SHIFT;
751 iowrite32(val, phba->db_va + DB_EQ_OFFSET);
752}
753
754/**
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530755 * be_isr_mcc - The isr routine of the driver.
756 * @irq: Not used
757 * @dev_id: Pointer to host adapter structure
758 */
759static irqreturn_t be_isr_mcc(int irq, void *dev_id)
760{
761 struct beiscsi_hba *phba;
762 struct be_eq_entry *eqe = NULL;
763 struct be_queue_info *eq;
764 struct be_queue_info *mcc;
765 unsigned int num_eq_processed;
766 struct be_eq_obj *pbe_eq;
767 unsigned long flags;
768
769 pbe_eq = dev_id;
770 eq = &pbe_eq->q;
771 phba = pbe_eq->phba;
772 mcc = &phba->ctrl.mcc_obj.cq;
773 eqe = queue_tail_node(eq);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530774
775 num_eq_processed = 0;
776
777 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
778 & EQE_VALID_MASK) {
779 if (((eqe->dw[offsetof(struct amap_eq_entry,
780 resource_id) / 32] &
781 EQE_RESID_MASK) >> 16) == mcc->id) {
782 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +0530783 pbe_eq->todo_mcc_cq = true;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530784 spin_unlock_irqrestore(&phba->isr_lock, flags);
785 }
786 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
787 queue_tail_inc(eq);
788 eqe = queue_tail_node(eq);
789 num_eq_processed++;
790 }
John Soni Jose72fb46a2012-10-20 04:42:49 +0530791 if (pbe_eq->todo_mcc_cq)
792 queue_work(phba->wq, &pbe_eq->work_cqs);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530793 if (num_eq_processed)
794 hwi_ring_eq_db(phba, eq->id, 1, num_eq_processed, 1, 1);
795
796 return IRQ_HANDLED;
797}
798
799/**
800 * be_isr_msix - The isr routine of the driver.
801 * @irq: Not used
802 * @dev_id: Pointer to host adapter structure
803 */
804static irqreturn_t be_isr_msix(int irq, void *dev_id)
805{
806 struct beiscsi_hba *phba;
807 struct be_eq_entry *eqe = NULL;
808 struct be_queue_info *eq;
809 struct be_queue_info *cq;
810 unsigned int num_eq_processed;
811 struct be_eq_obj *pbe_eq;
812 unsigned long flags;
813
814 pbe_eq = dev_id;
815 eq = &pbe_eq->q;
816 cq = pbe_eq->cq;
817 eqe = queue_tail_node(eq);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530818
819 phba = pbe_eq->phba;
820 num_eq_processed = 0;
821 if (blk_iopoll_enabled) {
822 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
823 & EQE_VALID_MASK) {
824 if (!blk_iopoll_sched_prep(&pbe_eq->iopoll))
825 blk_iopoll_sched(&pbe_eq->iopoll);
826
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 } else {
833 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
834 & EQE_VALID_MASK) {
835 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +0530836 pbe_eq->todo_cq = true;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530837 spin_unlock_irqrestore(&phba->isr_lock, flags);
838 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
839 queue_tail_inc(eq);
840 eqe = queue_tail_node(eq);
841 num_eq_processed++;
842 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530843
John Soni Jose72fb46a2012-10-20 04:42:49 +0530844 if (pbe_eq->todo_cq)
845 queue_work(phba->wq, &pbe_eq->work_cqs);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530846 }
John Soni Jose72fb46a2012-10-20 04:42:49 +0530847
848 if (num_eq_processed)
849 hwi_ring_eq_db(phba, eq->id, 1, num_eq_processed, 0, 1);
850
851 return IRQ_HANDLED;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530852}
853
854/**
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530855 * be_isr - The isr routine of the driver.
856 * @irq: Not used
857 * @dev_id: Pointer to host adapter structure
858 */
859static irqreturn_t be_isr(int irq, void *dev_id)
860{
861 struct beiscsi_hba *phba;
862 struct hwi_controller *phwi_ctrlr;
863 struct hwi_context_memory *phwi_context;
864 struct be_eq_entry *eqe = NULL;
865 struct be_queue_info *eq;
866 struct be_queue_info *cq;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530867 struct be_queue_info *mcc;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530868 unsigned long flags, index;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530869 unsigned int num_mcceq_processed, num_ioeq_processed;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530870 struct be_ctrl_info *ctrl;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530871 struct be_eq_obj *pbe_eq;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530872 int isr;
873
874 phba = dev_id;
Justin P. Mattock6eab04a2011-04-08 19:49:08 -0700875 ctrl = &phba->ctrl;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530876 isr = ioread32(ctrl->csr + CEV_ISR0_OFFSET +
877 (PCI_FUNC(ctrl->pdev->devfn) * CEV_ISR_SIZE));
878 if (!isr)
879 return IRQ_NONE;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530880
881 phwi_ctrlr = phba->phwi_ctrlr;
882 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530883 pbe_eq = &phwi_context->be_eq[0];
884
885 eq = &phwi_context->be_eq[0].q;
886 mcc = &phba->ctrl.mcc_obj.cq;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530887 index = 0;
888 eqe = queue_tail_node(eq);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530889
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530890 num_ioeq_processed = 0;
891 num_mcceq_processed = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530892 if (blk_iopoll_enabled) {
893 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
894 & EQE_VALID_MASK) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530895 if (((eqe->dw[offsetof(struct amap_eq_entry,
896 resource_id) / 32] &
897 EQE_RESID_MASK) >> 16) == mcc->id) {
898 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +0530899 pbe_eq->todo_mcc_cq = true;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530900 spin_unlock_irqrestore(&phba->isr_lock, flags);
901 num_mcceq_processed++;
902 } else {
903 if (!blk_iopoll_sched_prep(&pbe_eq->iopoll))
904 blk_iopoll_sched(&pbe_eq->iopoll);
905 num_ioeq_processed++;
906 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530907 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
908 queue_tail_inc(eq);
909 eqe = queue_tail_node(eq);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530910 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530911 if (num_ioeq_processed || num_mcceq_processed) {
John Soni Jose72fb46a2012-10-20 04:42:49 +0530912 if (pbe_eq->todo_mcc_cq)
913 queue_work(phba->wq, &pbe_eq->work_cqs);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530914
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530915 if ((num_mcceq_processed) && (!num_ioeq_processed))
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530916 hwi_ring_eq_db(phba, eq->id, 0,
917 (num_ioeq_processed +
918 num_mcceq_processed) , 1, 1);
919 else
920 hwi_ring_eq_db(phba, eq->id, 0,
921 (num_ioeq_processed +
922 num_mcceq_processed), 0, 1);
923
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530924 return IRQ_HANDLED;
925 } else
926 return IRQ_NONE;
927 } else {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530928 cq = &phwi_context->be_cq[0];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530929 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
930 & EQE_VALID_MASK) {
931
932 if (((eqe->dw[offsetof(struct amap_eq_entry,
933 resource_id) / 32] &
934 EQE_RESID_MASK) >> 16) != cq->id) {
935 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +0530936 pbe_eq->todo_mcc_cq = true;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530937 spin_unlock_irqrestore(&phba->isr_lock, flags);
938 } else {
939 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +0530940 pbe_eq->todo_cq = true;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530941 spin_unlock_irqrestore(&phba->isr_lock, flags);
942 }
943 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
944 queue_tail_inc(eq);
945 eqe = queue_tail_node(eq);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530946 num_ioeq_processed++;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530947 }
John Soni Jose72fb46a2012-10-20 04:42:49 +0530948 if (pbe_eq->todo_cq || pbe_eq->todo_mcc_cq)
949 queue_work(phba->wq, &pbe_eq->work_cqs);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530950
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530951 if (num_ioeq_processed) {
952 hwi_ring_eq_db(phba, eq->id, 0,
953 num_ioeq_processed, 1, 1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530954 return IRQ_HANDLED;
955 } else
956 return IRQ_NONE;
957 }
958}
959
960static int beiscsi_init_irqs(struct beiscsi_hba *phba)
961{
962 struct pci_dev *pcidev = phba->pcidev;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530963 struct hwi_controller *phwi_ctrlr;
964 struct hwi_context_memory *phwi_context;
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +0530965 int ret, msix_vec, i, j;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530966
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530967 phwi_ctrlr = phba->phwi_ctrlr;
968 phwi_context = phwi_ctrlr->phwi_ctxt;
969
970 if (phba->msix_enabled) {
971 for (i = 0; i < phba->num_cpus; i++) {
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -0700972 phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME,
973 GFP_KERNEL);
974 if (!phba->msi_name[i]) {
975 ret = -ENOMEM;
976 goto free_msix_irqs;
977 }
978
979 sprintf(phba->msi_name[i], "beiscsi_%02x_%02x",
980 phba->shost->host_no, i);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530981 msix_vec = phba->msix_entries[i].vector;
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -0700982 ret = request_irq(msix_vec, be_isr_msix, 0,
983 phba->msi_name[i],
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530984 &phwi_context->be_eq[i]);
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +0530985 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530986 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
987 "BM_%d : beiscsi_init_irqs-Failed to"
988 "register msix for i = %d\n",
989 i);
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -0700990 kfree(phba->msi_name[i]);
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +0530991 goto free_msix_irqs;
992 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530993 }
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -0700994 phba->msi_name[i] = kzalloc(BEISCSI_MSI_NAME, GFP_KERNEL);
995 if (!phba->msi_name[i]) {
996 ret = -ENOMEM;
997 goto free_msix_irqs;
998 }
999 sprintf(phba->msi_name[i], "beiscsi_mcc_%02x",
1000 phba->shost->host_no);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301001 msix_vec = phba->msix_entries[i].vector;
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -07001002 ret = request_irq(msix_vec, be_isr_mcc, 0, phba->msi_name[i],
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301003 &phwi_context->be_eq[i]);
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +05301004 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 beiscsi_msix_mcc\n");
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -07001008 kfree(phba->msi_name[i]);
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +05301009 goto free_msix_irqs;
1010 }
1011
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301012 } else {
1013 ret = request_irq(pcidev->irq, be_isr, IRQF_SHARED,
1014 "beiscsi", phba);
1015 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301016 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
1017 "BM_%d : beiscsi_init_irqs-"
1018 "Failed to register irq\\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301019 return ret;
1020 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301021 }
1022 return 0;
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +05301023free_msix_irqs:
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -07001024 for (j = i - 1; j >= 0; j--) {
1025 kfree(phba->msi_name[j]);
1026 msix_vec = phba->msix_entries[j].vector;
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +05301027 free_irq(msix_vec, &phwi_context->be_eq[j]);
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -07001028 }
Jayamohan Kallickal4f5af072010-07-22 04:23:55 +05301029 return ret;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301030}
1031
1032static void hwi_ring_cq_db(struct beiscsi_hba *phba,
1033 unsigned int id, unsigned int num_processed,
1034 unsigned char rearm, unsigned char event)
1035{
1036 u32 val = 0;
1037 val |= id & DB_CQ_RING_ID_MASK;
1038 if (rearm)
1039 val |= 1 << DB_CQ_REARM_SHIFT;
1040 val |= num_processed << DB_CQ_NUM_POPPED_SHIFT;
1041 iowrite32(val, phba->db_va + DB_CQ_OFFSET);
1042}
1043
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301044static unsigned int
1045beiscsi_process_async_pdu(struct beiscsi_conn *beiscsi_conn,
1046 struct beiscsi_hba *phba,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301047 struct pdu_base *ppdu,
1048 unsigned long pdu_len,
1049 void *pbuffer, unsigned long buf_len)
1050{
1051 struct iscsi_conn *conn = beiscsi_conn->conn;
1052 struct iscsi_session *session = conn->session;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301053 struct iscsi_task *task;
1054 struct beiscsi_io_task *io_task;
1055 struct iscsi_hdr *login_hdr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301056
1057 switch (ppdu->dw[offsetof(struct amap_pdu_base, opcode) / 32] &
1058 PDUBASE_OPCODE_MASK) {
1059 case ISCSI_OP_NOOP_IN:
1060 pbuffer = NULL;
1061 buf_len = 0;
1062 break;
1063 case ISCSI_OP_ASYNC_EVENT:
1064 break;
1065 case ISCSI_OP_REJECT:
1066 WARN_ON(!pbuffer);
1067 WARN_ON(!(buf_len == 48));
John Soni Jose99bc5d52012-08-20 23:00:18 +05301068 beiscsi_log(phba, KERN_ERR,
1069 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1070 "BM_%d : In ISCSI_OP_REJECT\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301071 break;
1072 case ISCSI_OP_LOGIN_RSP:
Jayamohan Kallickal7bd6e252010-01-05 05:07:02 +05301073 case ISCSI_OP_TEXT_RSP:
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301074 task = conn->login_task;
1075 io_task = task->dd_data;
1076 login_hdr = (struct iscsi_hdr *)ppdu;
1077 login_hdr->itt = io_task->libiscsi_itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301078 break;
1079 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +05301080 beiscsi_log(phba, KERN_WARNING,
1081 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1082 "BM_%d : Unrecognized opcode 0x%x in async msg\n",
1083 (ppdu->
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301084 dw[offsetof(struct amap_pdu_base, opcode) / 32]
John Soni Jose99bc5d52012-08-20 23:00:18 +05301085 & PDUBASE_OPCODE_MASK));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301086 return 1;
1087 }
1088
1089 spin_lock_bh(&session->lock);
1090 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)ppdu, pbuffer, buf_len);
1091 spin_unlock_bh(&session->lock);
1092 return 0;
1093}
1094
1095static struct sgl_handle *alloc_io_sgl_handle(struct beiscsi_hba *phba)
1096{
1097 struct sgl_handle *psgl_handle;
1098
1099 if (phba->io_sgl_hndl_avbl) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301100 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
1101 "BM_%d : In alloc_io_sgl_handle,"
1102 " io_sgl_alloc_index=%d\n",
1103 phba->io_sgl_alloc_index);
1104
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301105 psgl_handle = phba->io_sgl_hndl_base[phba->
1106 io_sgl_alloc_index];
1107 phba->io_sgl_hndl_base[phba->io_sgl_alloc_index] = NULL;
1108 phba->io_sgl_hndl_avbl--;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301109 if (phba->io_sgl_alloc_index == (phba->params.
1110 ios_per_ctrl - 1))
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301111 phba->io_sgl_alloc_index = 0;
1112 else
1113 phba->io_sgl_alloc_index++;
1114 } else
1115 psgl_handle = NULL;
1116 return psgl_handle;
1117}
1118
1119static void
1120free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
1121{
John Soni Jose99bc5d52012-08-20 23:00:18 +05301122 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
1123 "BM_%d : In free_,io_sgl_free_index=%d\n",
1124 phba->io_sgl_free_index);
1125
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301126 if (phba->io_sgl_hndl_base[phba->io_sgl_free_index]) {
1127 /*
1128 * this can happen if clean_task is called on a task that
1129 * failed in xmit_task or alloc_pdu.
1130 */
John Soni Jose99bc5d52012-08-20 23:00:18 +05301131 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_IO,
1132 "BM_%d : Double Free in IO SGL io_sgl_free_index=%d,"
1133 "value there=%p\n", phba->io_sgl_free_index,
1134 phba->io_sgl_hndl_base
1135 [phba->io_sgl_free_index]);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301136 return;
1137 }
1138 phba->io_sgl_hndl_base[phba->io_sgl_free_index] = psgl_handle;
1139 phba->io_sgl_hndl_avbl++;
1140 if (phba->io_sgl_free_index == (phba->params.ios_per_ctrl - 1))
1141 phba->io_sgl_free_index = 0;
1142 else
1143 phba->io_sgl_free_index++;
1144}
1145
1146/**
1147 * alloc_wrb_handle - To allocate a wrb handle
1148 * @phba: The hba pointer
1149 * @cid: The cid to use for allocation
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301150 *
1151 * This happens under session_lock until submission to chip
1152 */
Jayamohan Kallickald5431482010-01-05 05:06:21 +05301153struct wrb_handle *alloc_wrb_handle(struct beiscsi_hba *phba, unsigned int cid)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301154{
1155 struct hwi_wrb_context *pwrb_context;
1156 struct hwi_controller *phwi_ctrlr;
Jayamohan Kallickald5431482010-01-05 05:06:21 +05301157 struct wrb_handle *pwrb_handle, *pwrb_handle_tmp;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001158 uint16_t cri_index = BE_GET_CRI_FROM_CID(cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301159
1160 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001161 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
Jayamohan Kallickald5431482010-01-05 05:06:21 +05301162 if (pwrb_context->wrb_handles_available >= 2) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301163 pwrb_handle = pwrb_context->pwrb_handle_base[
1164 pwrb_context->alloc_index];
1165 pwrb_context->wrb_handles_available--;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301166 if (pwrb_context->alloc_index ==
1167 (phba->params.wrbs_per_cxn - 1))
1168 pwrb_context->alloc_index = 0;
1169 else
1170 pwrb_context->alloc_index++;
Jayamohan Kallickald5431482010-01-05 05:06:21 +05301171 pwrb_handle_tmp = pwrb_context->pwrb_handle_base[
1172 pwrb_context->alloc_index];
1173 pwrb_handle->nxt_wrb_index = pwrb_handle_tmp->wrb_index;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301174 } else
1175 pwrb_handle = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301176 return pwrb_handle;
1177}
1178
1179/**
1180 * free_wrb_handle - To free the wrb handle back to pool
1181 * @phba: The hba pointer
1182 * @pwrb_context: The context to free from
1183 * @pwrb_handle: The wrb_handle to free
1184 *
1185 * This happens under session_lock until submission to chip
1186 */
1187static void
1188free_wrb_handle(struct beiscsi_hba *phba, struct hwi_wrb_context *pwrb_context,
1189 struct wrb_handle *pwrb_handle)
1190{
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05301191 pwrb_context->pwrb_handle_base[pwrb_context->free_index] = pwrb_handle;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301192 pwrb_context->wrb_handles_available++;
1193 if (pwrb_context->free_index == (phba->params.wrbs_per_cxn - 1))
1194 pwrb_context->free_index = 0;
1195 else
1196 pwrb_context->free_index++;
1197
John Soni Jose99bc5d52012-08-20 23:00:18 +05301198 beiscsi_log(phba, KERN_INFO,
1199 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1200 "BM_%d : FREE WRB: pwrb_handle=%p free_index=0x%x"
1201 "wrb_handles_available=%d\n",
1202 pwrb_handle, pwrb_context->free_index,
1203 pwrb_context->wrb_handles_available);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301204}
1205
1206static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba)
1207{
1208 struct sgl_handle *psgl_handle;
1209
1210 if (phba->eh_sgl_hndl_avbl) {
1211 psgl_handle = phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index];
1212 phba->eh_sgl_hndl_base[phba->eh_sgl_alloc_index] = NULL;
John Soni Jose99bc5d52012-08-20 23:00:18 +05301213 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1214 "BM_%d : mgmt_sgl_alloc_index=%d=0x%x\n",
1215 phba->eh_sgl_alloc_index,
1216 phba->eh_sgl_alloc_index);
1217
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301218 phba->eh_sgl_hndl_avbl--;
1219 if (phba->eh_sgl_alloc_index ==
1220 (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl -
1221 1))
1222 phba->eh_sgl_alloc_index = 0;
1223 else
1224 phba->eh_sgl_alloc_index++;
1225 } else
1226 psgl_handle = NULL;
1227 return psgl_handle;
1228}
1229
1230void
1231free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
1232{
1233
John Soni Jose99bc5d52012-08-20 23:00:18 +05301234 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1235 "BM_%d : In free_mgmt_sgl_handle,"
1236 "eh_sgl_free_index=%d\n",
1237 phba->eh_sgl_free_index);
1238
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301239 if (phba->eh_sgl_hndl_base[phba->eh_sgl_free_index]) {
1240 /*
1241 * this can happen if clean_task is called on a task that
1242 * failed in xmit_task or alloc_pdu.
1243 */
John Soni Jose99bc5d52012-08-20 23:00:18 +05301244 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1245 "BM_%d : Double Free in eh SGL ,"
1246 "eh_sgl_free_index=%d\n",
1247 phba->eh_sgl_free_index);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301248 return;
1249 }
1250 phba->eh_sgl_hndl_base[phba->eh_sgl_free_index] = psgl_handle;
1251 phba->eh_sgl_hndl_avbl++;
1252 if (phba->eh_sgl_free_index ==
1253 (phba->params.icds_per_ctrl - phba->params.ios_per_ctrl - 1))
1254 phba->eh_sgl_free_index = 0;
1255 else
1256 phba->eh_sgl_free_index++;
1257}
1258
1259static void
1260be_complete_io(struct beiscsi_conn *beiscsi_conn,
John Soni Jose73133262012-10-20 04:44:49 +05301261 struct iscsi_task *task,
1262 struct common_sol_cqe *csol_cqe)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301263{
1264 struct beiscsi_io_task *io_task = task->dd_data;
1265 struct be_status_bhs *sts_bhs =
1266 (struct be_status_bhs *)io_task->cmd_bhs;
1267 struct iscsi_conn *conn = beiscsi_conn->conn;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301268 unsigned char *sense;
1269 u32 resid = 0, exp_cmdsn, max_cmdsn;
1270 u8 rsp, status, flags;
1271
John Soni Jose73133262012-10-20 04:44:49 +05301272 exp_cmdsn = csol_cqe->exp_cmdsn;
1273 max_cmdsn = (csol_cqe->exp_cmdsn +
1274 csol_cqe->cmd_wnd - 1);
1275 rsp = csol_cqe->i_resp;
1276 status = csol_cqe->i_sts;
1277 flags = csol_cqe->i_flags;
1278 resid = csol_cqe->res_cnt;
1279
Jayamohan Kallickalbd535452011-10-07 19:31:10 -05001280 if (!task->sc) {
1281 if (io_task->scsi_cmnd)
1282 scsi_dma_unmap(io_task->scsi_cmnd);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301283
Jayamohan Kallickalbd535452011-10-07 19:31:10 -05001284 return;
1285 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301286 task->sc->result = (DID_OK << 16) | status;
1287 if (rsp != ISCSI_STATUS_CMD_COMPLETED) {
1288 task->sc->result = DID_ERROR << 16;
1289 goto unmap;
1290 }
1291
1292 /* bidi not initially supported */
1293 if (flags & (ISCSI_FLAG_CMD_UNDERFLOW | ISCSI_FLAG_CMD_OVERFLOW)) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301294 if (!status && (flags & ISCSI_FLAG_CMD_OVERFLOW))
1295 task->sc->result = DID_ERROR << 16;
1296
1297 if (flags & ISCSI_FLAG_CMD_UNDERFLOW) {
1298 scsi_set_resid(task->sc, resid);
1299 if (!status && (scsi_bufflen(task->sc) - resid <
1300 task->sc->underflow))
1301 task->sc->result = DID_ERROR << 16;
1302 }
1303 }
1304
1305 if (status == SAM_STAT_CHECK_CONDITION) {
Dan Carpenter4053a4b2011-09-26 09:23:37 +03001306 u16 sense_len;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301307 unsigned short *slen = (unsigned short *)sts_bhs->sense_info;
Dan Carpenter4053a4b2011-09-26 09:23:37 +03001308
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301309 sense = sts_bhs->sense_info + sizeof(unsigned short);
Dan Carpenter4053a4b2011-09-26 09:23:37 +03001310 sense_len = be16_to_cpu(*slen);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301311 memcpy(task->sc->sense_buffer, sense,
1312 min_t(u16, sense_len, SCSI_SENSE_BUFFERSIZE));
1313 }
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05301314
John Soni Jose73133262012-10-20 04:44:49 +05301315 if (io_task->cmd_bhs->iscsi_hdr.flags & ISCSI_FLAG_CMD_READ)
1316 conn->rxdata_octets += resid;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301317unmap:
1318 scsi_dma_unmap(io_task->scsi_cmnd);
1319 iscsi_complete_scsi_task(task, exp_cmdsn, max_cmdsn);
1320}
1321
1322static void
1323be_complete_logout(struct beiscsi_conn *beiscsi_conn,
John Soni Jose73133262012-10-20 04:44:49 +05301324 struct iscsi_task *task,
1325 struct common_sol_cqe *csol_cqe)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301326{
1327 struct iscsi_logout_rsp *hdr;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301328 struct beiscsi_io_task *io_task = task->dd_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301329 struct iscsi_conn *conn = beiscsi_conn->conn;
1330
1331 hdr = (struct iscsi_logout_rsp *)task->hdr;
Jayamohan Kallickal7bd6e252010-01-05 05:07:02 +05301332 hdr->opcode = ISCSI_OP_LOGOUT_RSP;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301333 hdr->t2wait = 5;
1334 hdr->t2retain = 0;
John Soni Jose73133262012-10-20 04:44:49 +05301335 hdr->flags = csol_cqe->i_flags;
1336 hdr->response = csol_cqe->i_resp;
Jayamohan Kallickal702dc5e2013-04-05 20:38:37 -07001337 hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn);
1338 hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn +
1339 csol_cqe->cmd_wnd - 1);
John Soni Jose73133262012-10-20 04:44:49 +05301340
Jayamohan Kallickal7bd6e252010-01-05 05:07:02 +05301341 hdr->dlength[0] = 0;
1342 hdr->dlength[1] = 0;
1343 hdr->dlength[2] = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301344 hdr->hlength = 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301345 hdr->itt = io_task->libiscsi_itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301346 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1347}
1348
1349static void
1350be_complete_tmf(struct beiscsi_conn *beiscsi_conn,
John Soni Jose73133262012-10-20 04:44:49 +05301351 struct iscsi_task *task,
1352 struct common_sol_cqe *csol_cqe)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301353{
1354 struct iscsi_tm_rsp *hdr;
1355 struct iscsi_conn *conn = beiscsi_conn->conn;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301356 struct beiscsi_io_task *io_task = task->dd_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301357
1358 hdr = (struct iscsi_tm_rsp *)task->hdr;
Jayamohan Kallickal7bd6e252010-01-05 05:07:02 +05301359 hdr->opcode = ISCSI_OP_SCSI_TMFUNC_RSP;
John Soni Jose73133262012-10-20 04:44:49 +05301360 hdr->flags = csol_cqe->i_flags;
1361 hdr->response = csol_cqe->i_resp;
Jayamohan Kallickal702dc5e2013-04-05 20:38:37 -07001362 hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn);
1363 hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn +
1364 csol_cqe->cmd_wnd - 1);
John Soni Jose73133262012-10-20 04:44:49 +05301365
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301366 hdr->itt = io_task->libiscsi_itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301367 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1368}
1369
1370static void
1371hwi_complete_drvr_msgs(struct beiscsi_conn *beiscsi_conn,
1372 struct beiscsi_hba *phba, struct sol_cqe *psol)
1373{
1374 struct hwi_wrb_context *pwrb_context;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301375 struct wrb_handle *pwrb_handle = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301376 struct hwi_controller *phwi_ctrlr;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301377 struct iscsi_task *task;
1378 struct beiscsi_io_task *io_task;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001379 uint16_t wrb_index, cid, cri_index;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301380
1381 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07001382 if (is_chip_be2_be3r(phba)) {
John Soni Jose73133262012-10-20 04:44:49 +05301383 wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe,
1384 wrb_idx, psol);
1385 cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe,
1386 cid, psol);
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07001387 } else {
1388 wrb_index = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2,
1389 wrb_idx, psol);
1390 cid = AMAP_GET_BITS(struct amap_it_dmsg_cqe_v2,
1391 cid, psol);
John Soni Jose73133262012-10-20 04:44:49 +05301392 }
1393
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001394 cri_index = BE_GET_CRI_FROM_CID(cid);
1395 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
John Soni Jose73133262012-10-20 04:44:49 +05301396 pwrb_handle = pwrb_context->pwrb_handle_basestd[wrb_index];
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05301397 task = pwrb_handle->pio_handle;
Jayamohan Kallickal35e66012009-10-23 11:53:49 +05301398
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301399 io_task = task->dd_data;
Jayamohan Kallickal4a4a11b2013-04-05 20:38:31 -07001400 memset(io_task->pwrb_handle->pwrb, 0, sizeof(struct iscsi_wrb));
1401 iscsi_put_task(task);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301402}
1403
1404static void
1405be_complete_nopin_resp(struct beiscsi_conn *beiscsi_conn,
John Soni Jose73133262012-10-20 04:44:49 +05301406 struct iscsi_task *task,
1407 struct common_sol_cqe *csol_cqe)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301408{
1409 struct iscsi_nopin *hdr;
1410 struct iscsi_conn *conn = beiscsi_conn->conn;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301411 struct beiscsi_io_task *io_task = task->dd_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301412
1413 hdr = (struct iscsi_nopin *)task->hdr;
John Soni Jose73133262012-10-20 04:44:49 +05301414 hdr->flags = csol_cqe->i_flags;
1415 hdr->exp_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn);
Jayamohan Kallickal702dc5e2013-04-05 20:38:37 -07001416 hdr->max_cmdsn = cpu_to_be32(csol_cqe->exp_cmdsn +
1417 csol_cqe->cmd_wnd - 1);
John Soni Jose73133262012-10-20 04:44:49 +05301418
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301419 hdr->opcode = ISCSI_OP_NOOP_IN;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301420 hdr->itt = io_task->libiscsi_itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301421 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
1422}
1423
John Soni Jose73133262012-10-20 04:44:49 +05301424static void adapter_get_sol_cqe(struct beiscsi_hba *phba,
1425 struct sol_cqe *psol,
1426 struct common_sol_cqe *csol_cqe)
1427{
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07001428 if (is_chip_be2_be3r(phba)) {
1429 csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe,
1430 i_exp_cmd_sn, psol);
1431 csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe,
1432 i_res_cnt, psol);
1433 csol_cqe->cmd_wnd = AMAP_GET_BITS(struct amap_sol_cqe,
1434 i_cmd_wnd, psol);
1435 csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe,
1436 wrb_index, psol);
1437 csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe,
1438 cid, psol);
1439 csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe,
1440 hw_sts, psol);
1441 csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe,
1442 i_resp, psol);
1443 csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe,
1444 i_sts, psol);
1445 csol_cqe->i_flags = AMAP_GET_BITS(struct amap_sol_cqe,
1446 i_flags, psol);
1447 } else {
John Soni Jose73133262012-10-20 04:44:49 +05301448 csol_cqe->exp_cmdsn = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1449 i_exp_cmd_sn, psol);
1450 csol_cqe->res_cnt = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1451 i_res_cnt, psol);
1452 csol_cqe->wrb_index = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1453 wrb_index, psol);
1454 csol_cqe->cid = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1455 cid, psol);
1456 csol_cqe->hw_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1457 hw_sts, psol);
Jayamohan Kallickal702dc5e2013-04-05 20:38:37 -07001458 csol_cqe->cmd_wnd = AMAP_GET_BITS(struct amap_sol_cqe_v2,
John Soni Jose73133262012-10-20 04:44:49 +05301459 i_cmd_wnd, psol);
1460 if (AMAP_GET_BITS(struct amap_sol_cqe_v2,
1461 cmd_cmpl, psol))
1462 csol_cqe->i_sts = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1463 i_sts, psol);
1464 else
1465 csol_cqe->i_resp = AMAP_GET_BITS(struct amap_sol_cqe_v2,
1466 i_sts, psol);
1467 if (AMAP_GET_BITS(struct amap_sol_cqe_v2,
1468 u, psol))
1469 csol_cqe->i_flags = ISCSI_FLAG_CMD_UNDERFLOW;
1470
1471 if (AMAP_GET_BITS(struct amap_sol_cqe_v2,
1472 o, psol))
1473 csol_cqe->i_flags |= ISCSI_FLAG_CMD_OVERFLOW;
John Soni Jose73133262012-10-20 04:44:49 +05301474 }
1475}
1476
1477
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301478static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn,
1479 struct beiscsi_hba *phba, struct sol_cqe *psol)
1480{
1481 struct hwi_wrb_context *pwrb_context;
1482 struct wrb_handle *pwrb_handle;
1483 struct iscsi_wrb *pwrb = NULL;
1484 struct hwi_controller *phwi_ctrlr;
1485 struct iscsi_task *task;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301486 unsigned int type;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301487 struct iscsi_conn *conn = beiscsi_conn->conn;
1488 struct iscsi_session *session = conn->session;
John Soni Jose73133262012-10-20 04:44:49 +05301489 struct common_sol_cqe csol_cqe = {0};
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001490 uint16_t cri_index = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301491
1492 phwi_ctrlr = phba->phwi_ctrlr;
John Soni Jose73133262012-10-20 04:44:49 +05301493
1494 /* Copy the elements to a common structure */
1495 adapter_get_sol_cqe(phba, psol, &csol_cqe);
1496
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001497 cri_index = BE_GET_CRI_FROM_CID(csol_cqe.cid);
1498 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
John Soni Jose73133262012-10-20 04:44:49 +05301499
1500 pwrb_handle = pwrb_context->pwrb_handle_basestd[
1501 csol_cqe.wrb_index];
1502
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05301503 task = pwrb_handle->pio_handle;
1504 pwrb = pwrb_handle->pwrb;
John Soni Jose73133262012-10-20 04:44:49 +05301505 type = ((struct beiscsi_io_task *)task->dd_data)->wrb_type;
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05301506
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301507 spin_lock_bh(&session->lock);
1508 switch (type) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301509 case HWH_TYPE_IO:
1510 case HWH_TYPE_IO_RD:
1511 if ((task->hdr->opcode & ISCSI_OPCODE_MASK) ==
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05301512 ISCSI_OP_NOOP_OUT)
John Soni Jose73133262012-10-20 04:44:49 +05301513 be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe);
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05301514 else
John Soni Jose73133262012-10-20 04:44:49 +05301515 be_complete_io(beiscsi_conn, task, &csol_cqe);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301516 break;
1517
1518 case HWH_TYPE_LOGOUT:
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05301519 if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGOUT)
John Soni Jose73133262012-10-20 04:44:49 +05301520 be_complete_logout(beiscsi_conn, task, &csol_cqe);
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05301521 else
John Soni Jose73133262012-10-20 04:44:49 +05301522 be_complete_tmf(beiscsi_conn, task, &csol_cqe);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301523 break;
1524
1525 case HWH_TYPE_LOGIN:
John Soni Jose99bc5d52012-08-20 23:00:18 +05301526 beiscsi_log(phba, KERN_ERR,
1527 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1528 "BM_%d :\t\t No HWH_TYPE_LOGIN Expected in"
1529 " hwi_complete_cmd- Solicited path\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301530 break;
1531
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301532 case HWH_TYPE_NOP:
John Soni Jose73133262012-10-20 04:44:49 +05301533 be_complete_nopin_resp(beiscsi_conn, task, &csol_cqe);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301534 break;
1535
1536 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +05301537 beiscsi_log(phba, KERN_WARNING,
1538 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1539 "BM_%d : In hwi_complete_cmd, unknown type = %d"
1540 "wrb_index 0x%x CID 0x%x\n", type,
John Soni Jose73133262012-10-20 04:44:49 +05301541 csol_cqe.wrb_index,
1542 csol_cqe.cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301543 break;
1544 }
Jayamohan Kallickal35e66012009-10-23 11:53:49 +05301545
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301546 spin_unlock_bh(&session->lock);
1547}
1548
1549static struct list_head *hwi_get_async_busy_list(struct hwi_async_pdu_context
1550 *pasync_ctx, unsigned int is_header,
1551 unsigned int host_write_ptr)
1552{
1553 if (is_header)
1554 return &pasync_ctx->async_entry[host_write_ptr].
1555 header_busy_list;
1556 else
1557 return &pasync_ctx->async_entry[host_write_ptr].data_busy_list;
1558}
1559
1560static struct async_pdu_handle *
1561hwi_get_async_handle(struct beiscsi_hba *phba,
1562 struct beiscsi_conn *beiscsi_conn,
1563 struct hwi_async_pdu_context *pasync_ctx,
1564 struct i_t_dpdu_cqe *pdpdu_cqe, unsigned int *pcq_index)
1565{
1566 struct be_bus_address phys_addr;
1567 struct list_head *pbusy_list;
1568 struct async_pdu_handle *pasync_handle = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301569 unsigned char is_header = 0;
John Soni Jose73133262012-10-20 04:44:49 +05301570 unsigned int index, dpl;
1571
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07001572 if (is_chip_be2_be3r(phba)) {
John Soni Jose73133262012-10-20 04:44:49 +05301573 dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe,
1574 dpl, pdpdu_cqe);
1575 index = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe,
1576 index, pdpdu_cqe);
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07001577 } else {
1578 dpl = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2,
1579 dpl, pdpdu_cqe);
1580 index = AMAP_GET_BITS(struct amap_i_t_dpdu_cqe_v2,
1581 index, pdpdu_cqe);
John Soni Jose73133262012-10-20 04:44:49 +05301582 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301583
1584 phys_addr.u.a32.address_lo =
John Soni Jose73133262012-10-20 04:44:49 +05301585 (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
1586 db_addr_lo) / 32] - dpl);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301587 phys_addr.u.a32.address_hi =
John Soni Jose73133262012-10-20 04:44:49 +05301588 pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
1589 db_addr_hi) / 32];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301590
1591 phys_addr.u.a64.address =
1592 *((unsigned long long *)(&phys_addr.u.a64.address));
1593
1594 switch (pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe, code) / 32]
1595 & PDUCQE_CODE_MASK) {
1596 case UNSOL_HDR_NOTIFY:
1597 is_header = 1;
1598
John Soni Jose73133262012-10-20 04:44:49 +05301599 pbusy_list = hwi_get_async_busy_list(pasync_ctx,
1600 is_header, index);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301601 break;
1602 case UNSOL_DATA_NOTIFY:
John Soni Jose73133262012-10-20 04:44:49 +05301603 pbusy_list = hwi_get_async_busy_list(pasync_ctx,
1604 is_header, index);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301605 break;
1606 default:
1607 pbusy_list = NULL;
John Soni Jose99bc5d52012-08-20 23:00:18 +05301608 beiscsi_log(phba, KERN_WARNING,
1609 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
1610 "BM_%d : Unexpected code=%d\n",
1611 pdpdu_cqe->dw[offsetof(struct amap_i_t_dpdu_cqe,
1612 code) / 32] & PDUCQE_CODE_MASK);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301613 return NULL;
1614 }
1615
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301616 WARN_ON(list_empty(pbusy_list));
1617 list_for_each_entry(pasync_handle, pbusy_list, link) {
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05001618 if (pasync_handle->pa.u.a64.address == phys_addr.u.a64.address)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301619 break;
1620 }
1621
1622 WARN_ON(!pasync_handle);
1623
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001624 pasync_handle->cri = BE_GET_ASYNC_CRI_FROM_CID(
1625 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301626 pasync_handle->is_header = is_header;
John Soni Jose73133262012-10-20 04:44:49 +05301627 pasync_handle->buffer_len = dpl;
1628 *pcq_index = index;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301629
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301630 return pasync_handle;
1631}
1632
1633static unsigned int
John Soni Jose99bc5d52012-08-20 23:00:18 +05301634hwi_update_async_writables(struct beiscsi_hba *phba,
1635 struct hwi_async_pdu_context *pasync_ctx,
1636 unsigned int is_header, unsigned int cq_index)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301637{
1638 struct list_head *pbusy_list;
1639 struct async_pdu_handle *pasync_handle;
1640 unsigned int num_entries, writables = 0;
1641 unsigned int *pep_read_ptr, *pwritables;
1642
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05001643 num_entries = pasync_ctx->num_entries;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301644 if (is_header) {
1645 pep_read_ptr = &pasync_ctx->async_header.ep_read_ptr;
1646 pwritables = &pasync_ctx->async_header.writables;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301647 } else {
1648 pep_read_ptr = &pasync_ctx->async_data.ep_read_ptr;
1649 pwritables = &pasync_ctx->async_data.writables;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301650 }
1651
1652 while ((*pep_read_ptr) != cq_index) {
1653 (*pep_read_ptr)++;
1654 *pep_read_ptr = (*pep_read_ptr) % num_entries;
1655
1656 pbusy_list = hwi_get_async_busy_list(pasync_ctx, is_header,
1657 *pep_read_ptr);
1658 if (writables == 0)
1659 WARN_ON(list_empty(pbusy_list));
1660
1661 if (!list_empty(pbusy_list)) {
1662 pasync_handle = list_entry(pbusy_list->next,
1663 struct async_pdu_handle,
1664 link);
1665 WARN_ON(!pasync_handle);
1666 pasync_handle->consumed = 1;
1667 }
1668
1669 writables++;
1670 }
1671
1672 if (!writables) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301673 beiscsi_log(phba, KERN_ERR,
1674 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
1675 "BM_%d : Duplicate notification received - index 0x%x!!\n",
1676 cq_index);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301677 WARN_ON(1);
1678 }
1679
1680 *pwritables = *pwritables + writables;
1681 return 0;
1682}
1683
Jayamohan Kallickal9728d8d2012-04-03 23:41:47 -05001684static void hwi_free_async_msg(struct beiscsi_hba *phba,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001685 struct hwi_async_pdu_context *pasync_ctx,
1686 unsigned int cri)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301687{
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301688 struct async_pdu_handle *pasync_handle, *tmp_handle;
1689 struct list_head *plist;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301690
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301691 plist = &pasync_ctx->async_entry[cri].wait_queue.list;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301692 list_for_each_entry_safe(pasync_handle, tmp_handle, plist, link) {
1693 list_del(&pasync_handle->link);
1694
Jayamohan Kallickal9728d8d2012-04-03 23:41:47 -05001695 if (pasync_handle->is_header) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301696 list_add_tail(&pasync_handle->link,
1697 &pasync_ctx->async_header.free_list);
1698 pasync_ctx->async_header.free_entries++;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301699 } else {
1700 list_add_tail(&pasync_handle->link,
1701 &pasync_ctx->async_data.free_list);
1702 pasync_ctx->async_data.free_entries++;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301703 }
1704 }
1705
1706 INIT_LIST_HEAD(&pasync_ctx->async_entry[cri].wait_queue.list);
1707 pasync_ctx->async_entry[cri].wait_queue.hdr_received = 0;
1708 pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301709}
1710
1711static struct phys_addr *
1712hwi_get_ring_address(struct hwi_async_pdu_context *pasync_ctx,
1713 unsigned int is_header, unsigned int host_write_ptr)
1714{
1715 struct phys_addr *pasync_sge = NULL;
1716
1717 if (is_header)
1718 pasync_sge = pasync_ctx->async_header.ring_base;
1719 else
1720 pasync_sge = pasync_ctx->async_data.ring_base;
1721
1722 return pasync_sge + host_write_ptr;
1723}
1724
1725static void hwi_post_async_buffers(struct beiscsi_hba *phba,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001726 unsigned int is_header, uint8_t ulp_num)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301727{
1728 struct hwi_controller *phwi_ctrlr;
1729 struct hwi_async_pdu_context *pasync_ctx;
1730 struct async_pdu_handle *pasync_handle;
1731 struct list_head *pfree_link, *pbusy_list;
1732 struct phys_addr *pasync_sge;
1733 unsigned int ring_id, num_entries;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001734 unsigned int host_write_num, doorbell_offset;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301735 unsigned int writables;
1736 unsigned int i = 0;
1737 u32 doorbell = 0;
1738
1739 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001740 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr, ulp_num);
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05001741 num_entries = pasync_ctx->num_entries;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301742
1743 if (is_header) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301744 writables = min(pasync_ctx->async_header.writables,
1745 pasync_ctx->async_header.free_entries);
1746 pfree_link = pasync_ctx->async_header.free_list.next;
1747 host_write_num = pasync_ctx->async_header.host_write_ptr;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001748 ring_id = phwi_ctrlr->default_pdu_hdr[ulp_num].id;
1749 doorbell_offset = phwi_ctrlr->default_pdu_hdr[ulp_num].
1750 doorbell_offset;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301751 } else {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301752 writables = min(pasync_ctx->async_data.writables,
1753 pasync_ctx->async_data.free_entries);
1754 pfree_link = pasync_ctx->async_data.free_list.next;
1755 host_write_num = pasync_ctx->async_data.host_write_ptr;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001756 ring_id = phwi_ctrlr->default_pdu_data[ulp_num].id;
1757 doorbell_offset = phwi_ctrlr->default_pdu_data[ulp_num].
1758 doorbell_offset;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301759 }
1760
1761 writables = (writables / 8) * 8;
1762 if (writables) {
1763 for (i = 0; i < writables; i++) {
1764 pbusy_list =
1765 hwi_get_async_busy_list(pasync_ctx, is_header,
1766 host_write_num);
1767 pasync_handle =
1768 list_entry(pfree_link, struct async_pdu_handle,
1769 link);
1770 WARN_ON(!pasync_handle);
1771 pasync_handle->consumed = 0;
1772
1773 pfree_link = pfree_link->next;
1774
1775 pasync_sge = hwi_get_ring_address(pasync_ctx,
1776 is_header, host_write_num);
1777
1778 pasync_sge->hi = pasync_handle->pa.u.a32.address_lo;
1779 pasync_sge->lo = pasync_handle->pa.u.a32.address_hi;
1780
1781 list_move(&pasync_handle->link, pbusy_list);
1782
1783 host_write_num++;
1784 host_write_num = host_write_num % num_entries;
1785 }
1786
1787 if (is_header) {
1788 pasync_ctx->async_header.host_write_ptr =
1789 host_write_num;
1790 pasync_ctx->async_header.free_entries -= writables;
1791 pasync_ctx->async_header.writables -= writables;
1792 pasync_ctx->async_header.busy_entries += writables;
1793 } else {
1794 pasync_ctx->async_data.host_write_ptr = host_write_num;
1795 pasync_ctx->async_data.free_entries -= writables;
1796 pasync_ctx->async_data.writables -= writables;
1797 pasync_ctx->async_data.busy_entries += writables;
1798 }
1799
1800 doorbell |= ring_id & DB_DEF_PDU_RING_ID_MASK;
1801 doorbell |= 1 << DB_DEF_PDU_REARM_SHIFT;
1802 doorbell |= 0 << DB_DEF_PDU_EVENT_SHIFT;
1803 doorbell |= (writables & DB_DEF_PDU_CQPROC_MASK)
1804 << DB_DEF_PDU_CQPROC_SHIFT;
1805
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001806 iowrite32(doorbell, phba->db_va + doorbell_offset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301807 }
1808}
1809
1810static void hwi_flush_default_pdu_buffer(struct beiscsi_hba *phba,
1811 struct beiscsi_conn *beiscsi_conn,
1812 struct i_t_dpdu_cqe *pdpdu_cqe)
1813{
1814 struct hwi_controller *phwi_ctrlr;
1815 struct hwi_async_pdu_context *pasync_ctx;
1816 struct async_pdu_handle *pasync_handle = NULL;
1817 unsigned int cq_index = -1;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001818 uint16_t cri_index = BE_GET_CRI_FROM_CID(
1819 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301820
1821 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001822 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr,
1823 BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr,
1824 cri_index));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301825
1826 pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
1827 pdpdu_cqe, &cq_index);
1828 BUG_ON(pasync_handle->is_header != 0);
1829 if (pasync_handle->consumed == 0)
John Soni Jose99bc5d52012-08-20 23:00:18 +05301830 hwi_update_async_writables(phba, pasync_ctx,
1831 pasync_handle->is_header, cq_index);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301832
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001833 hwi_free_async_msg(phba, pasync_ctx, pasync_handle->cri);
1834 hwi_post_async_buffers(phba, pasync_handle->is_header,
1835 BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr,
1836 cri_index));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301837}
1838
1839static unsigned int
1840hwi_fwd_async_msg(struct beiscsi_conn *beiscsi_conn,
1841 struct beiscsi_hba *phba,
1842 struct hwi_async_pdu_context *pasync_ctx, unsigned short cri)
1843{
1844 struct list_head *plist;
1845 struct async_pdu_handle *pasync_handle;
1846 void *phdr = NULL;
1847 unsigned int hdr_len = 0, buf_len = 0;
1848 unsigned int status, index = 0, offset = 0;
1849 void *pfirst_buffer = NULL;
1850 unsigned int num_buf = 0;
1851
1852 plist = &pasync_ctx->async_entry[cri].wait_queue.list;
1853
1854 list_for_each_entry(pasync_handle, plist, link) {
1855 if (index == 0) {
1856 phdr = pasync_handle->pbuffer;
1857 hdr_len = pasync_handle->buffer_len;
1858 } else {
1859 buf_len = pasync_handle->buffer_len;
1860 if (!num_buf) {
1861 pfirst_buffer = pasync_handle->pbuffer;
1862 num_buf++;
1863 }
1864 memcpy(pfirst_buffer + offset,
1865 pasync_handle->pbuffer, buf_len);
Jayamohan Kallickalf2ba02b2012-04-03 23:41:37 -05001866 offset += buf_len;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301867 }
1868 index++;
1869 }
1870
1871 status = beiscsi_process_async_pdu(beiscsi_conn, phba,
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05301872 phdr, hdr_len, pfirst_buffer,
Jayamohan Kallickalf2ba02b2012-04-03 23:41:37 -05001873 offset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301874
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001875 hwi_free_async_msg(phba, pasync_ctx, cri);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301876 return 0;
1877}
1878
1879static unsigned int
1880hwi_gather_async_pdu(struct beiscsi_conn *beiscsi_conn,
1881 struct beiscsi_hba *phba,
1882 struct async_pdu_handle *pasync_handle)
1883{
1884 struct hwi_async_pdu_context *pasync_ctx;
1885 struct hwi_controller *phwi_ctrlr;
1886 unsigned int bytes_needed = 0, status = 0;
1887 unsigned short cri = pasync_handle->cri;
1888 struct pdu_base *ppdu;
1889
1890 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001891 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr,
1892 BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr,
1893 BE_GET_CRI_FROM_CID(beiscsi_conn->
1894 beiscsi_conn_cid)));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301895
1896 list_del(&pasync_handle->link);
1897 if (pasync_handle->is_header) {
1898 pasync_ctx->async_header.busy_entries--;
1899 if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) {
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001900 hwi_free_async_msg(phba, pasync_ctx, cri);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301901 BUG();
1902 }
1903
1904 pasync_ctx->async_entry[cri].wait_queue.bytes_received = 0;
1905 pasync_ctx->async_entry[cri].wait_queue.hdr_received = 1;
1906 pasync_ctx->async_entry[cri].wait_queue.hdr_len =
1907 (unsigned short)pasync_handle->buffer_len;
1908 list_add_tail(&pasync_handle->link,
1909 &pasync_ctx->async_entry[cri].wait_queue.list);
1910
1911 ppdu = pasync_handle->pbuffer;
1912 bytes_needed = ((((ppdu->dw[offsetof(struct amap_pdu_base,
1913 data_len_hi) / 32] & PDUBASE_DATALENHI_MASK) << 8) &
1914 0xFFFF0000) | ((be16_to_cpu((ppdu->
1915 dw[offsetof(struct amap_pdu_base, data_len_lo) / 32]
1916 & PDUBASE_DATALENLO_MASK) >> 16)) & 0x0000FFFF));
1917
1918 if (status == 0) {
1919 pasync_ctx->async_entry[cri].wait_queue.bytes_needed =
1920 bytes_needed;
1921
1922 if (bytes_needed == 0)
1923 status = hwi_fwd_async_msg(beiscsi_conn, phba,
1924 pasync_ctx, cri);
1925 }
1926 } else {
1927 pasync_ctx->async_data.busy_entries--;
1928 if (pasync_ctx->async_entry[cri].wait_queue.hdr_received) {
1929 list_add_tail(&pasync_handle->link,
1930 &pasync_ctx->async_entry[cri].wait_queue.
1931 list);
1932 pasync_ctx->async_entry[cri].wait_queue.
1933 bytes_received +=
1934 (unsigned short)pasync_handle->buffer_len;
1935
1936 if (pasync_ctx->async_entry[cri].wait_queue.
1937 bytes_received >=
1938 pasync_ctx->async_entry[cri].wait_queue.
1939 bytes_needed)
1940 status = hwi_fwd_async_msg(beiscsi_conn, phba,
1941 pasync_ctx, cri);
1942 }
1943 }
1944 return status;
1945}
1946
1947static void hwi_process_default_pdu_ring(struct beiscsi_conn *beiscsi_conn,
1948 struct beiscsi_hba *phba,
1949 struct i_t_dpdu_cqe *pdpdu_cqe)
1950{
1951 struct hwi_controller *phwi_ctrlr;
1952 struct hwi_async_pdu_context *pasync_ctx;
1953 struct async_pdu_handle *pasync_handle = NULL;
1954 unsigned int cq_index = -1;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001955 uint16_t cri_index = BE_GET_CRI_FROM_CID(
1956 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301957
1958 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001959 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(phwi_ctrlr,
1960 BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr,
1961 cri_index));
1962
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301963 pasync_handle = hwi_get_async_handle(phba, beiscsi_conn, pasync_ctx,
1964 pdpdu_cqe, &cq_index);
1965
1966 if (pasync_handle->consumed == 0)
John Soni Jose99bc5d52012-08-20 23:00:18 +05301967 hwi_update_async_writables(phba, pasync_ctx,
1968 pasync_handle->is_header, cq_index);
1969
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301970 hwi_gather_async_pdu(beiscsi_conn, phba, pasync_handle);
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07001971 hwi_post_async_buffers(phba, pasync_handle->is_header,
1972 BEISCSI_GET_ULP_FROM_CRI(
1973 phwi_ctrlr, cri_index));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301974}
1975
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05301976static void beiscsi_process_mcc_isr(struct beiscsi_hba *phba)
1977{
1978 struct be_queue_info *mcc_cq;
1979 struct be_mcc_compl *mcc_compl;
1980 unsigned int num_processed = 0;
1981
1982 mcc_cq = &phba->ctrl.mcc_obj.cq;
1983 mcc_compl = queue_tail_node(mcc_cq);
1984 mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
1985 while (mcc_compl->flags & CQE_FLAGS_VALID_MASK) {
1986
1987 if (num_processed >= 32) {
1988 hwi_ring_cq_db(phba, mcc_cq->id,
1989 num_processed, 0, 0);
1990 num_processed = 0;
1991 }
1992 if (mcc_compl->flags & CQE_FLAGS_ASYNC_MASK) {
1993 /* Interpret flags as an async trailer */
1994 if (is_link_state_evt(mcc_compl->flags))
1995 /* Interpret compl as a async link evt */
1996 beiscsi_async_link_state_process(phba,
1997 (struct be_async_event_link_state *) mcc_compl);
1998 else
John Soni Jose99bc5d52012-08-20 23:00:18 +05301999 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_MBOX,
2000 "BM_%d : Unsupported Async Event, flags"
2001 " = 0x%08x\n",
2002 mcc_compl->flags);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05302003 } else if (mcc_compl->flags & CQE_FLAGS_COMPLETED_MASK) {
2004 be_mcc_compl_process_isr(&phba->ctrl, mcc_compl);
2005 atomic_dec(&phba->ctrl.mcc_obj.q.used);
2006 }
2007
2008 mcc_compl->flags = 0;
2009 queue_tail_inc(mcc_cq);
2010 mcc_compl = queue_tail_node(mcc_cq);
2011 mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
2012 num_processed++;
2013 }
2014
2015 if (num_processed > 0)
2016 hwi_ring_cq_db(phba, mcc_cq->id, num_processed, 1, 0);
2017
2018}
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302019
John Soni Jose6763daa2012-10-20 04:41:45 +05302020/**
2021 * beiscsi_process_cq()- Process the Completion Queue
2022 * @pbe_eq: Event Q on which the Completion has come
2023 *
2024 * return
2025 * Number of Completion Entries processed.
2026 **/
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302027static unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302028{
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302029 struct be_queue_info *cq;
2030 struct sol_cqe *sol;
2031 struct dmsg_cqe *dmsg;
2032 unsigned int num_processed = 0;
2033 unsigned int tot_nump = 0;
John Soni Jose0a513dd2012-08-20 23:00:55 +05302034 unsigned short code = 0, cid = 0;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002035 uint16_t cri_index = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302036 struct beiscsi_conn *beiscsi_conn;
Jayamohan Kallickalc2462282010-01-05 05:05:34 +05302037 struct beiscsi_endpoint *beiscsi_ep;
2038 struct iscsi_endpoint *ep;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302039 struct beiscsi_hba *phba;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302040
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302041 cq = pbe_eq->cq;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302042 sol = queue_tail_node(cq);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302043 phba = pbe_eq->phba;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302044
2045 while (sol->dw[offsetof(struct amap_sol_cqe, valid) / 32] &
2046 CQE_VALID_MASK) {
2047 be_dws_le_to_cpu(sol, sizeof(struct sol_cqe));
2048
John Soni Jose73133262012-10-20 04:44:49 +05302049 code = (sol->dw[offsetof(struct amap_sol_cqe, code) /
2050 32] & CQE_CODE_MASK);
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05302051
John Soni Jose73133262012-10-20 04:44:49 +05302052 /* Get the CID */
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07002053 if (is_chip_be2_be3r(phba)) {
2054 cid = AMAP_GET_BITS(struct amap_sol_cqe, cid, sol);
2055 } else {
John Soni Jose73133262012-10-20 04:44:49 +05302056 if ((code == DRIVERMSG_NOTIFY) ||
2057 (code == UNSOL_HDR_NOTIFY) ||
2058 (code == UNSOL_DATA_NOTIFY))
2059 cid = AMAP_GET_BITS(
2060 struct amap_i_t_dpdu_cqe_v2,
2061 cid, sol);
2062 else
2063 cid = AMAP_GET_BITS(struct amap_sol_cqe_v2,
2064 cid, sol);
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07002065 }
John Soni Jose73133262012-10-20 04:44:49 +05302066
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002067 cri_index = BE_GET_CRI_FROM_CID(cid);
2068 ep = phba->ep_array[cri_index];
Jayamohan Kallickalc2462282010-01-05 05:05:34 +05302069 beiscsi_ep = ep->dd_data;
2070 beiscsi_conn = beiscsi_ep->conn;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05302071
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302072 if (num_processed >= 32) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302073 hwi_ring_cq_db(phba, cq->id,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302074 num_processed, 0, 0);
2075 tot_nump += num_processed;
2076 num_processed = 0;
2077 }
2078
John Soni Jose0a513dd2012-08-20 23:00:55 +05302079 switch (code) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302080 case SOL_CMD_COMPLETE:
2081 hwi_complete_cmd(beiscsi_conn, phba, sol);
2082 break;
2083 case DRIVERMSG_NOTIFY:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302084 beiscsi_log(phba, KERN_INFO,
2085 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302086 "BM_%d : Received %s[%d] on CID : %d\n",
2087 cqe_desc[code], code, cid);
John Soni Jose99bc5d52012-08-20 23:00:18 +05302088
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302089 dmsg = (struct dmsg_cqe *)sol;
2090 hwi_complete_drvr_msgs(beiscsi_conn, phba, sol);
2091 break;
2092 case UNSOL_HDR_NOTIFY:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302093 beiscsi_log(phba, KERN_INFO,
2094 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302095 "BM_%d : Received %s[%d] on CID : %d\n",
2096 cqe_desc[code], code, cid);
John Soni Jose99bc5d52012-08-20 23:00:18 +05302097
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07002098 spin_lock_bh(&phba->async_pdu_lock);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302099 hwi_process_default_pdu_ring(beiscsi_conn, phba,
2100 (struct i_t_dpdu_cqe *)sol);
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07002101 spin_unlock_bh(&phba->async_pdu_lock);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302102 break;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302103 case UNSOL_DATA_NOTIFY:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302104 beiscsi_log(phba, KERN_INFO,
2105 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
John Soni Jose6763daa2012-10-20 04:41:45 +05302106 "BM_%d : Received %s[%d] on CID : %d\n",
2107 cqe_desc[code], code, cid);
John Soni Jose99bc5d52012-08-20 23:00:18 +05302108
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07002109 spin_lock_bh(&phba->async_pdu_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302110 hwi_process_default_pdu_ring(beiscsi_conn, phba,
2111 (struct i_t_dpdu_cqe *)sol);
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07002112 spin_unlock_bh(&phba->async_pdu_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302113 break;
2114 case CXN_INVALIDATE_INDEX_NOTIFY:
2115 case CMD_INVALIDATED_NOTIFY:
2116 case CXN_INVALIDATE_NOTIFY:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302117 beiscsi_log(phba, KERN_ERR,
2118 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302119 "BM_%d : Ignoring %s[%d] on CID : %d\n",
2120 cqe_desc[code], code, cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302121 break;
2122 case SOL_CMD_KILLED_DATA_DIGEST_ERR:
2123 case CMD_KILLED_INVALID_STATSN_RCVD:
2124 case CMD_KILLED_INVALID_R2T_RCVD:
2125 case CMD_CXN_KILLED_LUN_INVALID:
2126 case CMD_CXN_KILLED_ICD_INVALID:
2127 case CMD_CXN_KILLED_ITT_INVALID:
2128 case CMD_CXN_KILLED_SEQ_OUTOFORDER:
2129 case CMD_CXN_KILLED_INVALID_DATASN_RCVD:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302130 beiscsi_log(phba, KERN_ERR,
2131 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
John Soni Jose6763daa2012-10-20 04:41:45 +05302132 "BM_%d : Cmd Notification %s[%d] on CID : %d\n",
2133 cqe_desc[code], code, cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302134 break;
2135 case UNSOL_DATA_DIGEST_ERROR_NOTIFY:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302136 beiscsi_log(phba, KERN_ERR,
2137 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302138 "BM_%d : Dropping %s[%d] on DPDU ring on CID : %d\n",
2139 cqe_desc[code], code, cid);
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07002140 spin_lock_bh(&phba->async_pdu_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302141 hwi_flush_default_pdu_buffer(phba, beiscsi_conn,
2142 (struct i_t_dpdu_cqe *) sol);
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07002143 spin_unlock_bh(&phba->async_pdu_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302144 break;
2145 case CXN_KILLED_PDU_SIZE_EXCEEDS_DSL:
2146 case CXN_KILLED_BURST_LEN_MISMATCH:
2147 case CXN_KILLED_AHS_RCVD:
2148 case CXN_KILLED_HDR_DIGEST_ERR:
2149 case CXN_KILLED_UNKNOWN_HDR:
2150 case CXN_KILLED_STALE_ITT_TTT_RCVD:
2151 case CXN_KILLED_INVALID_ITT_TTT_RCVD:
2152 case CXN_KILLED_TIMED_OUT:
2153 case CXN_KILLED_FIN_RCVD:
John Soni Jose6763daa2012-10-20 04:41:45 +05302154 case CXN_KILLED_RST_SENT:
2155 case CXN_KILLED_RST_RCVD:
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302156 case CXN_KILLED_BAD_UNSOL_PDU_RCVD:
2157 case CXN_KILLED_BAD_WRB_INDEX_ERROR:
2158 case CXN_KILLED_OVER_RUN_RESIDUAL:
2159 case CXN_KILLED_UNDER_RUN_RESIDUAL:
2160 case CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302161 beiscsi_log(phba, KERN_ERR,
2162 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302163 "BM_%d : Event %s[%d] received on CID : %d\n",
2164 cqe_desc[code], code, cid);
John Soni Jose0a513dd2012-08-20 23:00:55 +05302165 if (beiscsi_conn)
2166 iscsi_conn_failure(beiscsi_conn->conn,
2167 ISCSI_ERR_CONN_FAILED);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302168 break;
2169 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +05302170 beiscsi_log(phba, KERN_ERR,
2171 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
John Soni Jose6763daa2012-10-20 04:41:45 +05302172 "BM_%d : Invalid CQE Event Received Code : %d"
2173 "CID 0x%x...\n",
John Soni Jose0a513dd2012-08-20 23:00:55 +05302174 code, cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302175 break;
2176 }
2177
2178 AMAP_SET_BITS(struct amap_sol_cqe, valid, sol, 0);
2179 queue_tail_inc(cq);
2180 sol = queue_tail_node(cq);
2181 num_processed++;
2182 }
2183
2184 if (num_processed > 0) {
2185 tot_nump += num_processed;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302186 hwi_ring_cq_db(phba, cq->id, num_processed, 1, 0);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302187 }
2188 return tot_nump;
2189}
2190
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05302191void beiscsi_process_all_cqs(struct work_struct *work)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302192{
2193 unsigned long flags;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302194 struct hwi_controller *phwi_ctrlr;
2195 struct hwi_context_memory *phwi_context;
John Soni Jose72fb46a2012-10-20 04:42:49 +05302196 struct beiscsi_hba *phba;
2197 struct be_eq_obj *pbe_eq =
2198 container_of(work, struct be_eq_obj, work_cqs);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302199
John Soni Jose72fb46a2012-10-20 04:42:49 +05302200 phba = pbe_eq->phba;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302201 phwi_ctrlr = phba->phwi_ctrlr;
2202 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302203
John Soni Jose72fb46a2012-10-20 04:42:49 +05302204 if (pbe_eq->todo_mcc_cq) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302205 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +05302206 pbe_eq->todo_mcc_cq = false;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302207 spin_unlock_irqrestore(&phba->isr_lock, flags);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05302208 beiscsi_process_mcc_isr(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302209 }
2210
John Soni Jose72fb46a2012-10-20 04:42:49 +05302211 if (pbe_eq->todo_cq) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302212 spin_lock_irqsave(&phba->isr_lock, flags);
John Soni Jose72fb46a2012-10-20 04:42:49 +05302213 pbe_eq->todo_cq = false;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302214 spin_unlock_irqrestore(&phba->isr_lock, flags);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302215 beiscsi_process_cq(pbe_eq);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302216 }
John Soni Jose72fb46a2012-10-20 04:42:49 +05302217
2218 /* rearm EQ for further interrupts */
2219 hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302220}
2221
2222static int be_iopoll(struct blk_iopoll *iop, int budget)
2223{
Shlomo Pongratzad3f4282013-04-05 20:38:36 -07002224 unsigned int ret;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302225 struct beiscsi_hba *phba;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302226 struct be_eq_obj *pbe_eq;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302227
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302228 pbe_eq = container_of(iop, struct be_eq_obj, iopoll);
2229 ret = beiscsi_process_cq(pbe_eq);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302230 if (ret < budget) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302231 phba = pbe_eq->phba;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302232 blk_iopoll_complete(iop);
John Soni Jose99bc5d52012-08-20 23:00:18 +05302233 beiscsi_log(phba, KERN_INFO,
2234 BEISCSI_LOG_CONFIG | BEISCSI_LOG_IO,
2235 "BM_%d : rearm pbe_eq->q.id =%d\n",
2236 pbe_eq->q.id);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302237 hwi_ring_eq_db(phba, pbe_eq->q.id, 0, 0, 1, 1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302238 }
2239 return ret;
2240}
2241
2242static void
John Soni Jose09a10932012-10-20 04:44:23 +05302243hwi_write_sgl_v2(struct iscsi_wrb *pwrb, struct scatterlist *sg,
2244 unsigned int num_sg, struct beiscsi_io_task *io_task)
2245{
2246 struct iscsi_sge *psgl;
2247 unsigned int sg_len, index;
2248 unsigned int sge_len = 0;
2249 unsigned long long addr;
2250 struct scatterlist *l_sg;
2251 unsigned int offset;
2252
2253 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_lo, pwrb,
2254 io_task->bhs_pa.u.a32.address_lo);
2255 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, iscsi_bhs_addr_hi, pwrb,
2256 io_task->bhs_pa.u.a32.address_hi);
2257
2258 l_sg = sg;
2259 for (index = 0; (index < num_sg) && (index < 2); index++,
2260 sg = sg_next(sg)) {
2261 if (index == 0) {
2262 sg_len = sg_dma_len(sg);
2263 addr = (u64) sg_dma_address(sg);
2264 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2265 sge0_addr_lo, pwrb,
2266 lower_32_bits(addr));
2267 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2268 sge0_addr_hi, pwrb,
2269 upper_32_bits(addr));
2270 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2271 sge0_len, pwrb,
2272 sg_len);
2273 sge_len = sg_len;
2274 } else {
2275 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_r2t_offset,
2276 pwrb, sge_len);
2277 sg_len = sg_dma_len(sg);
2278 addr = (u64) sg_dma_address(sg);
2279 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2280 sge1_addr_lo, pwrb,
2281 lower_32_bits(addr));
2282 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2283 sge1_addr_hi, pwrb,
2284 upper_32_bits(addr));
2285 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
2286 sge1_len, pwrb,
2287 sg_len);
2288 }
2289 }
2290 psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
2291 memset(psgl, 0, sizeof(*psgl) * BE2_SGE);
2292
2293 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2);
2294
2295 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2296 io_task->bhs_pa.u.a32.address_hi);
2297 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2298 io_task->bhs_pa.u.a32.address_lo);
2299
2300 if (num_sg == 1) {
2301 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb,
2302 1);
2303 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb,
2304 0);
2305 } else if (num_sg == 2) {
2306 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb,
2307 0);
2308 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb,
2309 1);
2310 } else {
2311 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge0_last, pwrb,
2312 0);
2313 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sge1_last, pwrb,
2314 0);
2315 }
2316
2317 sg = l_sg;
2318 psgl++;
2319 psgl++;
2320 offset = 0;
2321 for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) {
2322 sg_len = sg_dma_len(sg);
2323 addr = (u64) sg_dma_address(sg);
2324 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2325 lower_32_bits(addr));
2326 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2327 upper_32_bits(addr));
2328 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len);
2329 AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset);
2330 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
2331 offset += sg_len;
2332 }
2333 psgl--;
2334 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
2335}
2336
2337static void
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302338hwi_write_sgl(struct iscsi_wrb *pwrb, struct scatterlist *sg,
2339 unsigned int num_sg, struct beiscsi_io_task *io_task)
2340{
2341 struct iscsi_sge *psgl;
Jayamohan Kallickal58ff4bd2010-10-06 23:46:47 +05302342 unsigned int sg_len, index;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302343 unsigned int sge_len = 0;
2344 unsigned long long addr;
2345 struct scatterlist *l_sg;
2346 unsigned int offset;
2347
2348 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
2349 io_task->bhs_pa.u.a32.address_lo);
2350 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
2351 io_task->bhs_pa.u.a32.address_hi);
2352
2353 l_sg = sg;
Jayamohan Kallickal48bd86c2010-01-07 01:50:19 +05302354 for (index = 0; (index < num_sg) && (index < 2); index++,
2355 sg = sg_next(sg)) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302356 if (index == 0) {
2357 sg_len = sg_dma_len(sg);
2358 addr = (u64) sg_dma_address(sg);
2359 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302360 ((u32)(addr & 0xFFFFFFFF)));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302361 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302362 ((u32)(addr >> 32)));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302363 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
2364 sg_len);
2365 sge_len = sg_len;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302366 } else {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302367 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_r2t_offset,
2368 pwrb, sge_len);
2369 sg_len = sg_dma_len(sg);
2370 addr = (u64) sg_dma_address(sg);
2371 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_lo, pwrb,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302372 ((u32)(addr & 0xFFFFFFFF)));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302373 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_addr_hi, pwrb,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302374 ((u32)(addr >> 32)));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302375 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_len, pwrb,
2376 sg_len);
2377 }
2378 }
2379 psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
2380 memset(psgl, 0, sizeof(*psgl) * BE2_SGE);
2381
2382 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len - 2);
2383
2384 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2385 io_task->bhs_pa.u.a32.address_hi);
2386 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2387 io_task->bhs_pa.u.a32.address_lo);
2388
Jayamohan Kallickalcaf818f2010-01-23 05:38:18 +05302389 if (num_sg == 1) {
2390 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
2391 1);
2392 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
2393 0);
2394 } else if (num_sg == 2) {
2395 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
2396 0);
2397 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
2398 1);
2399 } else {
2400 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
2401 0);
2402 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
2403 0);
2404 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302405 sg = l_sg;
2406 psgl++;
2407 psgl++;
2408 offset = 0;
Jayamohan Kallickal48bd86c2010-01-07 01:50:19 +05302409 for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302410 sg_len = sg_dma_len(sg);
2411 addr = (u64) sg_dma_address(sg);
2412 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2413 (addr & 0xFFFFFFFF));
2414 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2415 (addr >> 32));
2416 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, sg_len);
2417 AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, offset);
2418 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
2419 offset += sg_len;
2420 }
2421 psgl--;
2422 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
2423}
2424
John Soni Josed629c472012-10-20 04:42:00 +05302425/**
2426 * hwi_write_buffer()- Populate the WRB with task info
2427 * @pwrb: ptr to the WRB entry
2428 * @task: iscsi task which is to be executed
2429 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302430static void hwi_write_buffer(struct iscsi_wrb *pwrb, struct iscsi_task *task)
2431{
2432 struct iscsi_sge *psgl;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302433 struct beiscsi_io_task *io_task = task->dd_data;
2434 struct beiscsi_conn *beiscsi_conn = io_task->conn;
2435 struct beiscsi_hba *phba = beiscsi_conn->phba;
John Soni Jose09a10932012-10-20 04:44:23 +05302436 uint8_t dsp_value = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302437
2438 io_task->bhs_len = sizeof(struct be_nonio_bhs) - 2;
2439 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_lo, pwrb,
2440 io_task->bhs_pa.u.a32.address_lo);
2441 AMAP_SET_BITS(struct amap_iscsi_wrb, iscsi_bhs_addr_hi, pwrb,
2442 io_task->bhs_pa.u.a32.address_hi);
2443
2444 if (task->data) {
John Soni Jose09a10932012-10-20 04:44:23 +05302445
2446 /* Check for the data_count */
2447 dsp_value = (task->data_count) ? 1 : 0;
2448
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07002449 if (is_chip_be2_be3r(phba))
2450 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp,
John Soni Jose09a10932012-10-20 04:44:23 +05302451 pwrb, dsp_value);
2452 else
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07002453 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp,
John Soni Jose09a10932012-10-20 04:44:23 +05302454 pwrb, dsp_value);
2455
2456 /* Map addr only if there is data_count */
2457 if (dsp_value) {
John Soni Josed629c472012-10-20 04:42:00 +05302458 io_task->mtask_addr = pci_map_single(phba->pcidev,
2459 task->data,
2460 task->data_count,
2461 PCI_DMA_TODEVICE);
John Soni Josed629c472012-10-20 04:42:00 +05302462 io_task->mtask_data_count = task->data_count;
John Soni Jose09a10932012-10-20 04:44:23 +05302463 } else
John Soni Josed629c472012-10-20 04:42:00 +05302464 io_task->mtask_addr = 0;
John Soni Jose09a10932012-10-20 04:44:23 +05302465
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302466 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_lo, pwrb,
John Soni Josed629c472012-10-20 04:42:00 +05302467 lower_32_bits(io_task->mtask_addr));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302468 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_addr_hi, pwrb,
John Soni Josed629c472012-10-20 04:42:00 +05302469 upper_32_bits(io_task->mtask_addr));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302470 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
2471 task->data_count);
2472
2473 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb, 1);
2474 } else {
2475 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
John Soni Josed629c472012-10-20 04:42:00 +05302476 io_task->mtask_addr = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302477 }
2478
2479 psgl = (struct iscsi_sge *)io_task->psgl_handle->pfrag;
2480
2481 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, io_task->bhs_len);
2482
2483 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
2484 io_task->bhs_pa.u.a32.address_hi);
2485 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
2486 io_task->bhs_pa.u.a32.address_lo);
2487 if (task->data) {
2488 psgl++;
2489 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl, 0);
2490 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, 0);
2491 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0);
2492 AMAP_SET_BITS(struct amap_iscsi_sge, sge_offset, psgl, 0);
2493 AMAP_SET_BITS(struct amap_iscsi_sge, rsvd0, psgl, 0);
2494 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 0);
2495
2496 psgl++;
2497 if (task->data) {
2498 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
John Soni Josed629c472012-10-20 04:42:00 +05302499 lower_32_bits(io_task->mtask_addr));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302500 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, psgl,
John Soni Josed629c472012-10-20 04:42:00 +05302501 upper_32_bits(io_task->mtask_addr));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302502 }
2503 AMAP_SET_BITS(struct amap_iscsi_sge, len, psgl, 0x106);
2504 }
2505 AMAP_SET_BITS(struct amap_iscsi_sge, last_sge, psgl, 1);
2506}
2507
Jayamohan Kallickal843ae752013-09-28 15:35:44 -07002508/**
2509 * beiscsi_find_mem_req()- Find mem needed
2510 * @phba: ptr to HBA struct
2511 **/
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302512static void beiscsi_find_mem_req(struct beiscsi_hba *phba)
2513{
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002514 uint8_t mem_descr_index, ulp_num;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302515 unsigned int num_cq_pages, num_async_pdu_buf_pages;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302516 unsigned int num_async_pdu_data_pages, wrb_sz_per_cxn;
2517 unsigned int num_async_pdu_buf_sgl_pages, num_async_pdu_data_sgl_pages;
2518
2519 num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
2520 sizeof(struct sol_cqe));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302521
2522 phba->params.hwi_ws_sz = sizeof(struct hwi_controller);
2523
2524 phba->mem_req[ISCSI_MEM_GLOBAL_HEADER] = 2 *
2525 BE_ISCSI_PDU_HEADER_SIZE;
2526 phba->mem_req[HWI_MEM_ADDN_CONTEXT] =
2527 sizeof(struct hwi_context_memory);
2528
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302529
2530 phba->mem_req[HWI_MEM_WRB] = sizeof(struct iscsi_wrb)
2531 * (phba->params.wrbs_per_cxn)
2532 * phba->params.cxns_per_ctrl;
2533 wrb_sz_per_cxn = sizeof(struct wrb_handle) *
2534 (phba->params.wrbs_per_cxn);
2535 phba->mem_req[HWI_MEM_WRBH] = roundup_pow_of_two((wrb_sz_per_cxn) *
2536 phba->params.cxns_per_ctrl);
2537
2538 phba->mem_req[HWI_MEM_SGLH] = sizeof(struct sgl_handle) *
2539 phba->params.icds_per_ctrl;
2540 phba->mem_req[HWI_MEM_SGE] = sizeof(struct iscsi_sge) *
2541 phba->params.num_sge_per_io * phba->params.icds_per_ctrl;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002542 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
2543 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302544
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002545 num_async_pdu_buf_sgl_pages =
2546 PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
2547 phba, ulp_num) *
2548 sizeof(struct phys_addr));
2549
2550 num_async_pdu_buf_pages =
2551 PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
2552 phba, ulp_num) *
2553 phba->params.defpdu_hdr_sz);
2554
2555 num_async_pdu_data_pages =
2556 PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
2557 phba, ulp_num) *
2558 phba->params.defpdu_data_sz);
2559
2560 num_async_pdu_data_sgl_pages =
2561 PAGES_REQUIRED(BEISCSI_GET_CID_COUNT(
2562 phba, ulp_num) *
2563 sizeof(struct phys_addr));
2564
Jayamohan Kallickala129d922013-09-28 15:35:46 -07002565 mem_descr_index = (HWI_MEM_TEMPLATE_HDR_ULP0 +
2566 (ulp_num * MEM_DESCR_OFFSET));
2567 phba->mem_req[mem_descr_index] =
2568 BEISCSI_GET_CID_COUNT(phba, ulp_num) *
2569 BEISCSI_TEMPLATE_HDR_PER_CXN_SIZE;
2570
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002571 mem_descr_index = (HWI_MEM_ASYNC_HEADER_BUF_ULP0 +
2572 (ulp_num * MEM_DESCR_OFFSET));
2573 phba->mem_req[mem_descr_index] =
2574 num_async_pdu_buf_pages *
2575 PAGE_SIZE;
2576
2577 mem_descr_index = (HWI_MEM_ASYNC_DATA_BUF_ULP0 +
2578 (ulp_num * MEM_DESCR_OFFSET));
2579 phba->mem_req[mem_descr_index] =
2580 num_async_pdu_data_pages *
2581 PAGE_SIZE;
2582
2583 mem_descr_index = (HWI_MEM_ASYNC_HEADER_RING_ULP0 +
2584 (ulp_num * MEM_DESCR_OFFSET));
2585 phba->mem_req[mem_descr_index] =
2586 num_async_pdu_buf_sgl_pages *
2587 PAGE_SIZE;
2588
2589 mem_descr_index = (HWI_MEM_ASYNC_DATA_RING_ULP0 +
2590 (ulp_num * MEM_DESCR_OFFSET));
2591 phba->mem_req[mem_descr_index] =
2592 num_async_pdu_data_sgl_pages *
2593 PAGE_SIZE;
2594
2595 mem_descr_index = (HWI_MEM_ASYNC_HEADER_HANDLE_ULP0 +
2596 (ulp_num * MEM_DESCR_OFFSET));
2597 phba->mem_req[mem_descr_index] =
2598 BEISCSI_GET_CID_COUNT(phba, ulp_num) *
2599 sizeof(struct async_pdu_handle);
2600
2601 mem_descr_index = (HWI_MEM_ASYNC_DATA_HANDLE_ULP0 +
2602 (ulp_num * MEM_DESCR_OFFSET));
2603 phba->mem_req[mem_descr_index] =
2604 BEISCSI_GET_CID_COUNT(phba, ulp_num) *
2605 sizeof(struct async_pdu_handle);
2606
2607 mem_descr_index = (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0 +
2608 (ulp_num * MEM_DESCR_OFFSET));
2609 phba->mem_req[mem_descr_index] =
2610 sizeof(struct hwi_async_pdu_context) +
2611 (BEISCSI_GET_CID_COUNT(phba, ulp_num) *
2612 sizeof(struct hwi_async_entry));
2613 }
2614 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302615}
2616
2617static int beiscsi_alloc_mem(struct beiscsi_hba *phba)
2618{
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302619 dma_addr_t bus_add;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002620 struct hwi_controller *phwi_ctrlr;
2621 struct be_mem_descriptor *mem_descr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302622 struct mem_array *mem_arr, *mem_arr_orig;
2623 unsigned int i, j, alloc_size, curr_alloc_size;
2624
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002625 phba->phwi_ctrlr = kzalloc(phba->params.hwi_ws_sz, GFP_KERNEL);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302626 if (!phba->phwi_ctrlr)
2627 return -ENOMEM;
2628
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002629 /* Allocate memory for wrb_context */
2630 phwi_ctrlr = phba->phwi_ctrlr;
2631 phwi_ctrlr->wrb_context = kzalloc(sizeof(struct hwi_wrb_context) *
2632 phba->params.cxns_per_ctrl,
2633 GFP_KERNEL);
2634 if (!phwi_ctrlr->wrb_context)
2635 return -ENOMEM;
2636
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302637 phba->init_mem = kcalloc(SE_MEM_MAX, sizeof(*mem_descr),
2638 GFP_KERNEL);
2639 if (!phba->init_mem) {
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002640 kfree(phwi_ctrlr->wrb_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302641 kfree(phba->phwi_ctrlr);
2642 return -ENOMEM;
2643 }
2644
2645 mem_arr_orig = kmalloc(sizeof(*mem_arr_orig) * BEISCSI_MAX_FRAGS_INIT,
2646 GFP_KERNEL);
2647 if (!mem_arr_orig) {
2648 kfree(phba->init_mem);
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002649 kfree(phwi_ctrlr->wrb_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302650 kfree(phba->phwi_ctrlr);
2651 return -ENOMEM;
2652 }
2653
2654 mem_descr = phba->init_mem;
2655 for (i = 0; i < SE_MEM_MAX; i++) {
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002656 if (!phba->mem_req[i]) {
2657 mem_descr->mem_array = NULL;
2658 mem_descr++;
2659 continue;
2660 }
2661
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302662 j = 0;
2663 mem_arr = mem_arr_orig;
2664 alloc_size = phba->mem_req[i];
2665 memset(mem_arr, 0, sizeof(struct mem_array) *
2666 BEISCSI_MAX_FRAGS_INIT);
2667 curr_alloc_size = min(be_max_phys_size * 1024, alloc_size);
2668 do {
2669 mem_arr->virtual_address = pci_alloc_consistent(
2670 phba->pcidev,
2671 curr_alloc_size,
2672 &bus_add);
2673 if (!mem_arr->virtual_address) {
2674 if (curr_alloc_size <= BE_MIN_MEM_SIZE)
2675 goto free_mem;
2676 if (curr_alloc_size -
2677 rounddown_pow_of_two(curr_alloc_size))
2678 curr_alloc_size = rounddown_pow_of_two
2679 (curr_alloc_size);
2680 else
2681 curr_alloc_size = curr_alloc_size / 2;
2682 } else {
2683 mem_arr->bus_address.u.
2684 a64.address = (__u64) bus_add;
2685 mem_arr->size = curr_alloc_size;
2686 alloc_size -= curr_alloc_size;
2687 curr_alloc_size = min(be_max_phys_size *
2688 1024, alloc_size);
2689 j++;
2690 mem_arr++;
2691 }
2692 } while (alloc_size);
2693 mem_descr->num_elements = j;
2694 mem_descr->size_in_bytes = phba->mem_req[i];
2695 mem_descr->mem_array = kmalloc(sizeof(*mem_arr) * j,
2696 GFP_KERNEL);
2697 if (!mem_descr->mem_array)
2698 goto free_mem;
2699
2700 memcpy(mem_descr->mem_array, mem_arr_orig,
2701 sizeof(struct mem_array) * j);
2702 mem_descr++;
2703 }
2704 kfree(mem_arr_orig);
2705 return 0;
2706free_mem:
2707 mem_descr->num_elements = j;
2708 while ((i) || (j)) {
2709 for (j = mem_descr->num_elements; j > 0; j--) {
2710 pci_free_consistent(phba->pcidev,
2711 mem_descr->mem_array[j - 1].size,
2712 mem_descr->mem_array[j - 1].
2713 virtual_address,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05302714 (unsigned long)mem_descr->
2715 mem_array[j - 1].
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302716 bus_address.u.a64.address);
2717 }
2718 if (i) {
2719 i--;
2720 kfree(mem_descr->mem_array);
2721 mem_descr--;
2722 }
2723 }
2724 kfree(mem_arr_orig);
2725 kfree(phba->init_mem);
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002726 kfree(phba->phwi_ctrlr->wrb_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302727 kfree(phba->phwi_ctrlr);
2728 return -ENOMEM;
2729}
2730
2731static int beiscsi_get_memory(struct beiscsi_hba *phba)
2732{
2733 beiscsi_find_mem_req(phba);
2734 return beiscsi_alloc_mem(phba);
2735}
2736
2737static void iscsi_init_global_templates(struct beiscsi_hba *phba)
2738{
2739 struct pdu_data_out *pdata_out;
2740 struct pdu_nop_out *pnop_out;
2741 struct be_mem_descriptor *mem_descr;
2742
2743 mem_descr = phba->init_mem;
2744 mem_descr += ISCSI_MEM_GLOBAL_HEADER;
2745 pdata_out =
2746 (struct pdu_data_out *)mem_descr->mem_array[0].virtual_address;
2747 memset(pdata_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
2748
2749 AMAP_SET_BITS(struct amap_pdu_data_out, opcode, pdata_out,
2750 IIOC_SCSI_DATA);
2751
2752 pnop_out =
2753 (struct pdu_nop_out *)((unsigned char *)mem_descr->mem_array[0].
2754 virtual_address + BE_ISCSI_PDU_HEADER_SIZE);
2755
2756 memset(pnop_out, 0, BE_ISCSI_PDU_HEADER_SIZE);
2757 AMAP_SET_BITS(struct amap_pdu_nop_out, ttt, pnop_out, 0xFFFFFFFF);
2758 AMAP_SET_BITS(struct amap_pdu_nop_out, f_bit, pnop_out, 1);
2759 AMAP_SET_BITS(struct amap_pdu_nop_out, i_bit, pnop_out, 0);
2760}
2761
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002762static int beiscsi_init_wrb_handle(struct beiscsi_hba *phba)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302763{
2764 struct be_mem_descriptor *mem_descr_wrbh, *mem_descr_wrb;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002765 struct hwi_context_memory *phwi_ctxt;
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002766 struct wrb_handle *pwrb_handle = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302767 struct hwi_controller *phwi_ctrlr;
2768 struct hwi_wrb_context *pwrb_context;
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002769 struct iscsi_wrb *pwrb = NULL;
2770 unsigned int num_cxn_wrbh = 0;
2771 unsigned int num_cxn_wrb = 0, j, idx = 0, index;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302772
2773 mem_descr_wrbh = phba->init_mem;
2774 mem_descr_wrbh += HWI_MEM_WRBH;
2775
2776 mem_descr_wrb = phba->init_mem;
2777 mem_descr_wrb += HWI_MEM_WRB;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302778 phwi_ctrlr = phba->phwi_ctrlr;
2779
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002780 /* Allocate memory for WRBQ */
2781 phwi_ctxt = phwi_ctrlr->phwi_ctxt;
2782 phwi_ctxt->be_wrbq = kzalloc(sizeof(struct be_queue_info) *
Jayamohan Kallickal843ae752013-09-28 15:35:44 -07002783 phba->params.cxns_per_ctrl,
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002784 GFP_KERNEL);
2785 if (!phwi_ctxt->be_wrbq) {
2786 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2787 "BM_%d : WRBQ Mem Alloc Failed\n");
2788 return -ENOMEM;
2789 }
2790
2791 for (index = 0; index < phba->params.cxns_per_ctrl; index++) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302792 pwrb_context = &phwi_ctrlr->wrb_context[index];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302793 pwrb_context->pwrb_handle_base =
2794 kzalloc(sizeof(struct wrb_handle *) *
2795 phba->params.wrbs_per_cxn, GFP_KERNEL);
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002796 if (!pwrb_context->pwrb_handle_base) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05302797 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2798 "BM_%d : Mem Alloc Failed. Failing to load\n");
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002799 goto init_wrb_hndl_failed;
2800 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302801 pwrb_context->pwrb_handle_basestd =
2802 kzalloc(sizeof(struct wrb_handle *) *
2803 phba->params.wrbs_per_cxn, GFP_KERNEL);
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002804 if (!pwrb_context->pwrb_handle_basestd) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05302805 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
2806 "BM_%d : Mem Alloc Failed. Failing to load\n");
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002807 goto init_wrb_hndl_failed;
2808 }
2809 if (!num_cxn_wrbh) {
2810 pwrb_handle =
2811 mem_descr_wrbh->mem_array[idx].virtual_address;
2812 num_cxn_wrbh = ((mem_descr_wrbh->mem_array[idx].size) /
2813 ((sizeof(struct wrb_handle)) *
2814 phba->params.wrbs_per_cxn));
2815 idx++;
2816 }
2817 pwrb_context->alloc_index = 0;
2818 pwrb_context->wrb_handles_available = 0;
2819 pwrb_context->free_index = 0;
2820
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302821 if (num_cxn_wrbh) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302822 for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
2823 pwrb_context->pwrb_handle_base[j] = pwrb_handle;
2824 pwrb_context->pwrb_handle_basestd[j] =
2825 pwrb_handle;
2826 pwrb_context->wrb_handles_available++;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05302827 pwrb_handle->wrb_index = j;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302828 pwrb_handle++;
2829 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302830 num_cxn_wrbh--;
2831 }
2832 }
2833 idx = 0;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002834 for (index = 0; index < phba->params.cxns_per_ctrl; index++) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302835 pwrb_context = &phwi_ctrlr->wrb_context[index];
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002836 if (!num_cxn_wrb) {
2837 pwrb = mem_descr_wrb->mem_array[idx].virtual_address;
2838 num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) /
2839 ((sizeof(struct iscsi_wrb) *
2840 phba->params.wrbs_per_cxn));
2841 idx++;
2842 }
2843
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302844 if (num_cxn_wrb) {
2845 for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
2846 pwrb_handle = pwrb_context->pwrb_handle_base[j];
2847 pwrb_handle->pwrb = pwrb;
2848 pwrb++;
2849 }
2850 num_cxn_wrb--;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302851 }
2852 }
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05002853 return 0;
2854init_wrb_hndl_failed:
2855 for (j = index; j > 0; j--) {
2856 pwrb_context = &phwi_ctrlr->wrb_context[j];
2857 kfree(pwrb_context->pwrb_handle_base);
2858 kfree(pwrb_context->pwrb_handle_basestd);
2859 }
2860 return -ENOMEM;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302861}
2862
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002863static int hwi_init_async_pdu_ctx(struct beiscsi_hba *phba)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302864{
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002865 uint8_t ulp_num;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302866 struct hwi_controller *phwi_ctrlr;
2867 struct hba_parameters *p = &phba->params;
2868 struct hwi_async_pdu_context *pasync_ctx;
2869 struct async_pdu_handle *pasync_header_h, *pasync_data_h;
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05002870 unsigned int index, idx, num_per_mem, num_async_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302871 struct be_mem_descriptor *mem_descr;
2872
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002873 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
2874 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302875
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002876 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2877 mem_descr += (HWI_MEM_ASYNC_PDU_CONTEXT_ULP0 +
2878 (ulp_num * MEM_DESCR_OFFSET));
2879
2880 phwi_ctrlr = phba->phwi_ctrlr;
2881 phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num] =
2882 (struct hwi_async_pdu_context *)
2883 mem_descr->mem_array[0].virtual_address;
2884
2885 pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num];
2886 memset(pasync_ctx, 0, sizeof(*pasync_ctx));
2887
2888 pasync_ctx->async_entry =
2889 (struct hwi_async_entry *)
2890 ((long unsigned int)pasync_ctx +
2891 sizeof(struct hwi_async_pdu_context));
2892
2893 pasync_ctx->num_entries = BEISCSI_GET_CID_COUNT(phba,
2894 ulp_num);
2895 pasync_ctx->buffer_size = p->defpdu_hdr_sz;
2896
2897 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2898 mem_descr += HWI_MEM_ASYNC_HEADER_BUF_ULP0 +
2899 (ulp_num * MEM_DESCR_OFFSET);
2900 if (mem_descr->mem_array[0].virtual_address) {
2901 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2902 "BM_%d : hwi_init_async_pdu_ctx"
2903 " HWI_MEM_ASYNC_HEADER_BUF_ULP%d va=%p\n",
2904 ulp_num,
2905 mem_descr->mem_array[0].
2906 virtual_address);
2907 } else
2908 beiscsi_log(phba, KERN_WARNING,
2909 BEISCSI_LOG_INIT,
2910 "BM_%d : No Virtual address for ULP : %d\n",
2911 ulp_num);
2912
2913 pasync_ctx->async_header.va_base =
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302914 mem_descr->mem_array[0].virtual_address;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302915
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002916 pasync_ctx->async_header.pa_base.u.a64.address =
2917 mem_descr->mem_array[0].
2918 bus_address.u.a64.address;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07002919
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002920 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2921 mem_descr += HWI_MEM_ASYNC_HEADER_RING_ULP0 +
2922 (ulp_num * MEM_DESCR_OFFSET);
2923 if (mem_descr->mem_array[0].virtual_address) {
2924 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2925 "BM_%d : hwi_init_async_pdu_ctx"
2926 " HWI_MEM_ASYNC_HEADER_RING_ULP%d va=%p\n",
2927 ulp_num,
2928 mem_descr->mem_array[0].
2929 virtual_address);
2930 } else
2931 beiscsi_log(phba, KERN_WARNING,
2932 BEISCSI_LOG_INIT,
2933 "BM_%d : No Virtual address for ULP : %d\n",
2934 ulp_num);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302935
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002936 pasync_ctx->async_header.ring_base =
2937 mem_descr->mem_array[0].virtual_address;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302938
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002939 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2940 mem_descr += HWI_MEM_ASYNC_HEADER_HANDLE_ULP0 +
2941 (ulp_num * MEM_DESCR_OFFSET);
2942 if (mem_descr->mem_array[0].virtual_address) {
2943 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2944 "BM_%d : hwi_init_async_pdu_ctx"
2945 " HWI_MEM_ASYNC_HEADER_HANDLE_ULP%d va=%p\n",
2946 ulp_num,
2947 mem_descr->mem_array[0].
2948 virtual_address);
2949 } else
2950 beiscsi_log(phba, KERN_WARNING,
2951 BEISCSI_LOG_INIT,
2952 "BM_%d : No Virtual address for ULP : %d\n",
2953 ulp_num);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302954
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002955 pasync_ctx->async_header.handle_base =
2956 mem_descr->mem_array[0].virtual_address;
2957 pasync_ctx->async_header.writables = 0;
2958 INIT_LIST_HEAD(&pasync_ctx->async_header.free_list);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302959
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002960 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2961 mem_descr += HWI_MEM_ASYNC_DATA_RING_ULP0 +
2962 (ulp_num * MEM_DESCR_OFFSET);
2963 if (mem_descr->mem_array[0].virtual_address) {
2964 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
2965 "BM_%d : hwi_init_async_pdu_ctx"
2966 " HWI_MEM_ASYNC_DATA_RING_ULP%d va=%p\n",
2967 ulp_num,
2968 mem_descr->mem_array[0].
2969 virtual_address);
2970 } else
2971 beiscsi_log(phba, KERN_WARNING,
2972 BEISCSI_LOG_INIT,
2973 "BM_%d : No Virtual address for ULP : %d\n",
2974 ulp_num);
John Soni Jose99bc5d52012-08-20 23:00:18 +05302975
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002976 pasync_ctx->async_data.ring_base =
2977 mem_descr->mem_array[0].virtual_address;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302978
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002979 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
2980 mem_descr += HWI_MEM_ASYNC_DATA_HANDLE_ULP0 +
2981 (ulp_num * MEM_DESCR_OFFSET);
2982 if (!mem_descr->mem_array[0].virtual_address)
2983 beiscsi_log(phba, KERN_WARNING,
2984 BEISCSI_LOG_INIT,
2985 "BM_%d : No Virtual address for ULP : %d\n",
2986 ulp_num);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302987
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002988 pasync_ctx->async_data.handle_base =
2989 mem_descr->mem_array[0].virtual_address;
2990 pasync_ctx->async_data.writables = 0;
2991 INIT_LIST_HEAD(&pasync_ctx->async_data.free_list);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302992
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07002993 pasync_header_h =
2994 (struct async_pdu_handle *)
2995 pasync_ctx->async_header.handle_base;
2996 pasync_data_h =
2997 (struct async_pdu_handle *)
2998 pasync_ctx->async_data.handle_base;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05302999
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003000 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
3001 mem_descr += HWI_MEM_ASYNC_DATA_BUF_ULP0 +
3002 (ulp_num * MEM_DESCR_OFFSET);
3003 if (mem_descr->mem_array[0].virtual_address) {
3004 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3005 "BM_%d : hwi_init_async_pdu_ctx"
3006 " HWI_MEM_ASYNC_DATA_BUF_ULP%d va=%p\n",
3007 ulp_num,
3008 mem_descr->mem_array[0].
3009 virtual_address);
3010 } else
3011 beiscsi_log(phba, KERN_WARNING,
3012 BEISCSI_LOG_INIT,
3013 "BM_%d : No Virtual address for ULP : %d\n",
3014 ulp_num);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303015
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003016 idx = 0;
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05003017 pasync_ctx->async_data.va_base =
3018 mem_descr->mem_array[idx].virtual_address;
3019 pasync_ctx->async_data.pa_base.u.a64.address =
3020 mem_descr->mem_array[idx].
3021 bus_address.u.a64.address;
3022
3023 num_async_data = ((mem_descr->mem_array[idx].size) /
3024 phba->params.defpdu_data_sz);
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003025 num_per_mem = 0;
3026
3027 for (index = 0; index < BEISCSI_GET_CID_COUNT
3028 (phba, ulp_num); index++) {
3029 pasync_header_h->cri = -1;
3030 pasync_header_h->index = (char)index;
3031 INIT_LIST_HEAD(&pasync_header_h->link);
3032 pasync_header_h->pbuffer =
3033 (void *)((unsigned long)
3034 (pasync_ctx->
3035 async_header.va_base) +
3036 (p->defpdu_hdr_sz * index));
3037
3038 pasync_header_h->pa.u.a64.address =
3039 pasync_ctx->async_header.pa_base.u.a64.
3040 address + (p->defpdu_hdr_sz * index);
3041
3042 list_add_tail(&pasync_header_h->link,
3043 &pasync_ctx->async_header.
3044 free_list);
3045 pasync_header_h++;
3046 pasync_ctx->async_header.free_entries++;
3047 pasync_ctx->async_header.writables++;
3048
3049 INIT_LIST_HEAD(&pasync_ctx->async_entry[index].
3050 wait_queue.list);
3051 INIT_LIST_HEAD(&pasync_ctx->async_entry[index].
3052 header_busy_list);
3053 pasync_data_h->cri = -1;
3054 pasync_data_h->index = (char)index;
3055 INIT_LIST_HEAD(&pasync_data_h->link);
3056
3057 if (!num_async_data) {
3058 num_per_mem = 0;
3059 idx++;
3060 pasync_ctx->async_data.va_base =
3061 mem_descr->mem_array[idx].
3062 virtual_address;
3063 pasync_ctx->async_data.pa_base.u.
3064 a64.address =
3065 mem_descr->mem_array[idx].
3066 bus_address.u.a64.address;
3067 num_async_data =
3068 ((mem_descr->mem_array[idx].
3069 size) /
3070 phba->params.defpdu_data_sz);
3071 }
3072 pasync_data_h->pbuffer =
3073 (void *)((unsigned long)
3074 (pasync_ctx->async_data.va_base) +
3075 (p->defpdu_data_sz * num_per_mem));
3076
3077 pasync_data_h->pa.u.a64.address =
3078 pasync_ctx->async_data.pa_base.u.a64.
3079 address + (p->defpdu_data_sz *
3080 num_per_mem);
3081 num_per_mem++;
3082 num_async_data--;
3083
3084 list_add_tail(&pasync_data_h->link,
3085 &pasync_ctx->async_data.
3086 free_list);
3087 pasync_data_h++;
3088 pasync_ctx->async_data.free_entries++;
3089 pasync_ctx->async_data.writables++;
3090
3091 INIT_LIST_HEAD(&pasync_ctx->async_entry[index].
3092 data_busy_list);
3093 }
3094
3095 pasync_ctx->async_header.host_write_ptr = 0;
3096 pasync_ctx->async_header.ep_read_ptr = -1;
3097 pasync_ctx->async_data.host_write_ptr = 0;
3098 pasync_ctx->async_data.ep_read_ptr = -1;
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05003099 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303100 }
3101
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003102 return 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303103}
3104
3105static int
3106be_sgl_create_contiguous(void *virtual_address,
3107 u64 physical_address, u32 length,
3108 struct be_dma_mem *sgl)
3109{
3110 WARN_ON(!virtual_address);
3111 WARN_ON(!physical_address);
3112 WARN_ON(!length > 0);
3113 WARN_ON(!sgl);
3114
3115 sgl->va = virtual_address;
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05303116 sgl->dma = (unsigned long)physical_address;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303117 sgl->size = length;
3118
3119 return 0;
3120}
3121
3122static void be_sgl_destroy_contiguous(struct be_dma_mem *sgl)
3123{
3124 memset(sgl, 0, sizeof(*sgl));
3125}
3126
3127static void
3128hwi_build_be_sgl_arr(struct beiscsi_hba *phba,
3129 struct mem_array *pmem, struct be_dma_mem *sgl)
3130{
3131 if (sgl->va)
3132 be_sgl_destroy_contiguous(sgl);
3133
3134 be_sgl_create_contiguous(pmem->virtual_address,
3135 pmem->bus_address.u.a64.address,
3136 pmem->size, sgl);
3137}
3138
3139static void
3140hwi_build_be_sgl_by_offset(struct beiscsi_hba *phba,
3141 struct mem_array *pmem, struct be_dma_mem *sgl)
3142{
3143 if (sgl->va)
3144 be_sgl_destroy_contiguous(sgl);
3145
3146 be_sgl_create_contiguous((unsigned char *)pmem->virtual_address,
3147 pmem->bus_address.u.a64.address,
3148 pmem->size, sgl);
3149}
3150
3151static int be_fill_queue(struct be_queue_info *q,
3152 u16 len, u16 entry_size, void *vaddress)
3153{
3154 struct be_dma_mem *mem = &q->dma_mem;
3155
3156 memset(q, 0, sizeof(*q));
3157 q->len = len;
3158 q->entry_size = entry_size;
3159 mem->size = len * entry_size;
3160 mem->va = vaddress;
3161 if (!mem->va)
3162 return -ENOMEM;
3163 memset(mem->va, 0, mem->size);
3164 return 0;
3165}
3166
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303167static int beiscsi_create_eqs(struct beiscsi_hba *phba,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303168 struct hwi_context_memory *phwi_context)
3169{
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303170 unsigned int i, num_eq_pages;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303171 int ret = 0, eq_for_mcc;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303172 struct be_queue_info *eq;
3173 struct be_dma_mem *mem;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303174 void *eq_vaddress;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303175 dma_addr_t paddr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303176
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303177 num_eq_pages = PAGES_REQUIRED(phba->params.num_eq_entries * \
3178 sizeof(struct be_eq_entry));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303179
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303180 if (phba->msix_enabled)
3181 eq_for_mcc = 1;
3182 else
3183 eq_for_mcc = 0;
3184 for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
3185 eq = &phwi_context->be_eq[i].q;
3186 mem = &eq->dma_mem;
3187 phwi_context->be_eq[i].phba = phba;
3188 eq_vaddress = pci_alloc_consistent(phba->pcidev,
3189 num_eq_pages * PAGE_SIZE,
3190 &paddr);
3191 if (!eq_vaddress)
3192 goto create_eq_error;
3193
3194 mem->va = eq_vaddress;
3195 ret = be_fill_queue(eq, phba->params.num_eq_entries,
3196 sizeof(struct be_eq_entry), eq_vaddress);
3197 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303198 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3199 "BM_%d : be_fill_queue Failed for EQ\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303200 goto create_eq_error;
3201 }
3202
3203 mem->dma = paddr;
3204 ret = beiscsi_cmd_eq_create(&phba->ctrl, eq,
3205 phwi_context->cur_eqd);
3206 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303207 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3208 "BM_%d : beiscsi_cmd_eq_create"
3209 "Failed for EQ\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303210 goto create_eq_error;
3211 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05303212
3213 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3214 "BM_%d : eqid = %d\n",
3215 phwi_context->be_eq[i].q.id);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303216 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303217 return 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303218create_eq_error:
John Soni Jose107dfcb2012-10-20 04:42:13 +05303219 for (i = 0; i < (phba->num_cpus + eq_for_mcc); i++) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303220 eq = &phwi_context->be_eq[i].q;
3221 mem = &eq->dma_mem;
3222 if (mem->va)
3223 pci_free_consistent(phba->pcidev, num_eq_pages
3224 * PAGE_SIZE,
3225 mem->va, mem->dma);
3226 }
3227 return ret;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303228}
3229
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303230static int beiscsi_create_cqs(struct beiscsi_hba *phba,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303231 struct hwi_context_memory *phwi_context)
3232{
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303233 unsigned int i, num_cq_pages;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303234 int ret = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303235 struct be_queue_info *cq, *eq;
3236 struct be_dma_mem *mem;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303237 struct be_eq_obj *pbe_eq;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303238 void *cq_vaddress;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303239 dma_addr_t paddr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303240
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303241 num_cq_pages = PAGES_REQUIRED(phba->params.num_cq_entries * \
3242 sizeof(struct sol_cqe));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303243
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303244 for (i = 0; i < phba->num_cpus; i++) {
3245 cq = &phwi_context->be_cq[i];
3246 eq = &phwi_context->be_eq[i].q;
3247 pbe_eq = &phwi_context->be_eq[i];
3248 pbe_eq->cq = cq;
3249 pbe_eq->phba = phba;
3250 mem = &cq->dma_mem;
3251 cq_vaddress = pci_alloc_consistent(phba->pcidev,
3252 num_cq_pages * PAGE_SIZE,
3253 &paddr);
3254 if (!cq_vaddress)
3255 goto create_cq_error;
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05303256 ret = be_fill_queue(cq, phba->params.num_cq_entries,
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303257 sizeof(struct sol_cqe), cq_vaddress);
3258 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303259 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3260 "BM_%d : be_fill_queue Failed "
3261 "for ISCSI CQ\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303262 goto create_cq_error;
3263 }
3264
3265 mem->dma = paddr;
3266 ret = beiscsi_cmd_cq_create(&phba->ctrl, cq, eq, false,
3267 false, 0);
3268 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303269 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3270 "BM_%d : beiscsi_cmd_eq_create"
3271 "Failed for ISCSI CQ\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303272 goto create_cq_error;
3273 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05303274 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3275 "BM_%d : iscsi cq_id is %d for eq_id %d\n"
3276 "iSCSI CQ CREATED\n", cq->id, eq->id);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303277 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303278 return 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303279
3280create_cq_error:
3281 for (i = 0; i < phba->num_cpus; i++) {
3282 cq = &phwi_context->be_cq[i];
3283 mem = &cq->dma_mem;
3284 if (mem->va)
3285 pci_free_consistent(phba->pcidev, num_cq_pages
3286 * PAGE_SIZE,
3287 mem->va, mem->dma);
3288 }
3289 return ret;
3290
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303291}
3292
3293static int
3294beiscsi_create_def_hdr(struct beiscsi_hba *phba,
3295 struct hwi_context_memory *phwi_context,
3296 struct hwi_controller *phwi_ctrlr,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003297 unsigned int def_pdu_ring_sz, uint8_t ulp_num)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303298{
3299 unsigned int idx;
3300 int ret;
3301 struct be_queue_info *dq, *cq;
3302 struct be_dma_mem *mem;
3303 struct be_mem_descriptor *mem_descr;
3304 void *dq_vaddress;
3305
3306 idx = 0;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003307 dq = &phwi_context->be_def_hdrq[ulp_num];
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303308 cq = &phwi_context->be_cq[0];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303309 mem = &dq->dma_mem;
3310 mem_descr = phba->init_mem;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003311 mem_descr += HWI_MEM_ASYNC_HEADER_RING_ULP0 +
3312 (ulp_num * MEM_DESCR_OFFSET);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303313 dq_vaddress = mem_descr->mem_array[idx].virtual_address;
3314 ret = be_fill_queue(dq, mem_descr->mem_array[0].size /
3315 sizeof(struct phys_addr),
3316 sizeof(struct phys_addr), dq_vaddress);
3317 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303318 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003319 "BM_%d : be_fill_queue Failed for DEF PDU HDR on ULP : %d\n",
3320 ulp_num);
3321
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303322 return ret;
3323 }
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05303324 mem->dma = (unsigned long)mem_descr->mem_array[idx].
3325 bus_address.u.a64.address;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303326 ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dq,
3327 def_pdu_ring_sz,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003328 phba->params.defpdu_hdr_sz,
3329 BEISCSI_DEFQ_HDR, ulp_num);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303330 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303331 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003332 "BM_%d : be_cmd_create_default_pdu_queue Failed DEFHDR on ULP : %d\n",
3333 ulp_num);
3334
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303335 return ret;
3336 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05303337
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003338 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3339 "BM_%d : iscsi hdr def pdu id for ULP : %d is %d\n",
3340 ulp_num,
3341 phwi_context->be_def_hdrq[ulp_num].id);
3342 hwi_post_async_buffers(phba, BEISCSI_DEFQ_HDR, ulp_num);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303343 return 0;
3344}
3345
3346static int
3347beiscsi_create_def_data(struct beiscsi_hba *phba,
3348 struct hwi_context_memory *phwi_context,
3349 struct hwi_controller *phwi_ctrlr,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003350 unsigned int def_pdu_ring_sz, uint8_t ulp_num)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303351{
3352 unsigned int idx;
3353 int ret;
3354 struct be_queue_info *dataq, *cq;
3355 struct be_dma_mem *mem;
3356 struct be_mem_descriptor *mem_descr;
3357 void *dq_vaddress;
3358
3359 idx = 0;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003360 dataq = &phwi_context->be_def_dataq[ulp_num];
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303361 cq = &phwi_context->be_cq[0];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303362 mem = &dataq->dma_mem;
3363 mem_descr = phba->init_mem;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003364 mem_descr += HWI_MEM_ASYNC_DATA_RING_ULP0 +
3365 (ulp_num * MEM_DESCR_OFFSET);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303366 dq_vaddress = mem_descr->mem_array[idx].virtual_address;
3367 ret = be_fill_queue(dataq, mem_descr->mem_array[0].size /
3368 sizeof(struct phys_addr),
3369 sizeof(struct phys_addr), dq_vaddress);
3370 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303371 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003372 "BM_%d : be_fill_queue Failed for DEF PDU "
3373 "DATA on ULP : %d\n",
3374 ulp_num);
3375
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303376 return ret;
3377 }
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05303378 mem->dma = (unsigned long)mem_descr->mem_array[idx].
3379 bus_address.u.a64.address;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303380 ret = be_cmd_create_default_pdu_queue(&phba->ctrl, cq, dataq,
3381 def_pdu_ring_sz,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003382 phba->params.defpdu_data_sz,
3383 BEISCSI_DEFQ_DATA, ulp_num);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303384 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303385 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3386 "BM_%d be_cmd_create_default_pdu_queue"
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003387 " Failed for DEF PDU DATA on ULP : %d\n",
3388 ulp_num);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303389 return ret;
3390 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05303391
John Soni Jose99bc5d52012-08-20 23:00:18 +05303392 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003393 "BM_%d : iscsi def data id on ULP : %d is %d\n",
3394 ulp_num,
3395 phwi_context->be_def_dataq[ulp_num].id);
3396
3397 hwi_post_async_buffers(phba, BEISCSI_DEFQ_DATA, ulp_num);
3398 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3399 "BM_%d : DEFAULT PDU DATA RING CREATED"
3400 "on ULP : %d\n", ulp_num);
John Soni Jose99bc5d52012-08-20 23:00:18 +05303401
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303402 return 0;
3403}
3404
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07003405
3406static int
3407beiscsi_post_template_hdr(struct beiscsi_hba *phba)
3408{
3409 struct be_mem_descriptor *mem_descr;
3410 struct mem_array *pm_arr;
3411 struct be_dma_mem sgl;
Jayamohan Kallickala129d922013-09-28 15:35:46 -07003412 int status, ulp_num;
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07003413
Jayamohan Kallickala129d922013-09-28 15:35:46 -07003414 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
3415 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
3416 mem_descr = (struct be_mem_descriptor *)phba->init_mem;
3417 mem_descr += HWI_MEM_TEMPLATE_HDR_ULP0 +
3418 (ulp_num * MEM_DESCR_OFFSET);
3419 pm_arr = mem_descr->mem_array;
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07003420
Jayamohan Kallickala129d922013-09-28 15:35:46 -07003421 hwi_build_be_sgl_arr(phba, pm_arr, &sgl);
3422 status = be_cmd_iscsi_post_template_hdr(
3423 &phba->ctrl, &sgl);
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07003424
Jayamohan Kallickala129d922013-09-28 15:35:46 -07003425 if (status != 0) {
3426 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3427 "BM_%d : Post Template HDR Failed for"
3428 "ULP_%d\n", ulp_num);
3429 return status;
3430 }
3431
3432 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3433 "BM_%d : Template HDR Pages Posted for"
3434 "ULP_%d\n", ulp_num);
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07003435 }
3436 }
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07003437 return 0;
3438}
3439
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303440static int
3441beiscsi_post_pages(struct beiscsi_hba *phba)
3442{
3443 struct be_mem_descriptor *mem_descr;
3444 struct mem_array *pm_arr;
3445 unsigned int page_offset, i;
3446 struct be_dma_mem sgl;
Jayamohan Kallickal843ae752013-09-28 15:35:44 -07003447 int status, ulp_num = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303448
3449 mem_descr = phba->init_mem;
3450 mem_descr += HWI_MEM_SGE;
3451 pm_arr = mem_descr->mem_array;
3452
Jayamohan Kallickal90622db2013-09-28 15:35:47 -07003453 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
3454 if (test_bit(ulp_num, &phba->fw_config.ulp_supported))
3455 break;
3456
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303457 page_offset = (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io *
Jayamohan Kallickal843ae752013-09-28 15:35:44 -07003458 phba->fw_config.iscsi_icd_start[ulp_num]) / PAGE_SIZE;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303459 for (i = 0; i < mem_descr->num_elements; i++) {
3460 hwi_build_be_sgl_arr(phba, pm_arr, &sgl);
3461 status = be_cmd_iscsi_post_sgl_pages(&phba->ctrl, &sgl,
3462 page_offset,
3463 (pm_arr->size / PAGE_SIZE));
3464 page_offset += pm_arr->size / PAGE_SIZE;
3465 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303466 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3467 "BM_%d : post sgl failed.\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303468 return status;
3469 }
3470 pm_arr++;
3471 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05303472 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3473 "BM_%d : POSTED PAGES\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303474 return 0;
3475}
3476
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303477static void be_queue_free(struct beiscsi_hba *phba, struct be_queue_info *q)
3478{
3479 struct be_dma_mem *mem = &q->dma_mem;
Jayamohan Kallickalc8b25592012-04-03 23:41:42 -05003480 if (mem->va) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303481 pci_free_consistent(phba->pcidev, mem->size,
3482 mem->va, mem->dma);
Jayamohan Kallickalc8b25592012-04-03 23:41:42 -05003483 mem->va = NULL;
3484 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303485}
3486
3487static int be_queue_alloc(struct beiscsi_hba *phba, struct be_queue_info *q,
3488 u16 len, u16 entry_size)
3489{
3490 struct be_dma_mem *mem = &q->dma_mem;
3491
3492 memset(q, 0, sizeof(*q));
3493 q->len = len;
3494 q->entry_size = entry_size;
3495 mem->size = len * entry_size;
3496 mem->va = pci_alloc_consistent(phba->pcidev, mem->size, &mem->dma);
3497 if (!mem->va)
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +05303498 return -ENOMEM;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303499 memset(mem->va, 0, mem->size);
3500 return 0;
3501}
3502
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303503static int
3504beiscsi_create_wrb_rings(struct beiscsi_hba *phba,
3505 struct hwi_context_memory *phwi_context,
3506 struct hwi_controller *phwi_ctrlr)
3507{
3508 unsigned int wrb_mem_index, offset, size, num_wrb_rings;
3509 u64 pa_addr_lo;
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07003510 unsigned int idx, num, i, ulp_num;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303511 struct mem_array *pwrb_arr;
3512 void *wrb_vaddr;
3513 struct be_dma_mem sgl;
3514 struct be_mem_descriptor *mem_descr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003515 struct hwi_wrb_context *pwrb_context;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303516 int status;
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07003517 uint8_t ulp_count = 0, ulp_base_num = 0;
3518 uint16_t cid_count_ulp[BEISCSI_ULP_COUNT] = { 0 };
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303519
3520 idx = 0;
3521 mem_descr = phba->init_mem;
3522 mem_descr += HWI_MEM_WRB;
3523 pwrb_arr = kmalloc(sizeof(*pwrb_arr) * phba->params.cxns_per_ctrl,
3524 GFP_KERNEL);
3525 if (!pwrb_arr) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303526 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3527 "BM_%d : Memory alloc failed in create wrb ring.\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303528 return -ENOMEM;
3529 }
3530 wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
3531 pa_addr_lo = mem_descr->mem_array[idx].bus_address.u.a64.address;
3532 num_wrb_rings = mem_descr->mem_array[idx].size /
3533 (phba->params.wrbs_per_cxn * sizeof(struct iscsi_wrb));
3534
3535 for (num = 0; num < phba->params.cxns_per_ctrl; num++) {
3536 if (num_wrb_rings) {
3537 pwrb_arr[num].virtual_address = wrb_vaddr;
3538 pwrb_arr[num].bus_address.u.a64.address = pa_addr_lo;
3539 pwrb_arr[num].size = phba->params.wrbs_per_cxn *
3540 sizeof(struct iscsi_wrb);
3541 wrb_vaddr += pwrb_arr[num].size;
3542 pa_addr_lo += pwrb_arr[num].size;
3543 num_wrb_rings--;
3544 } else {
3545 idx++;
3546 wrb_vaddr = mem_descr->mem_array[idx].virtual_address;
3547 pa_addr_lo = mem_descr->mem_array[idx].\
3548 bus_address.u.a64.address;
3549 num_wrb_rings = mem_descr->mem_array[idx].size /
3550 (phba->params.wrbs_per_cxn *
3551 sizeof(struct iscsi_wrb));
3552 pwrb_arr[num].virtual_address = wrb_vaddr;
3553 pwrb_arr[num].bus_address.u.a64.address\
3554 = pa_addr_lo;
3555 pwrb_arr[num].size = phba->params.wrbs_per_cxn *
3556 sizeof(struct iscsi_wrb);
3557 wrb_vaddr += pwrb_arr[num].size;
3558 pa_addr_lo += pwrb_arr[num].size;
3559 num_wrb_rings--;
3560 }
3561 }
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07003562
3563 /* Get the ULP Count */
3564 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
3565 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
3566 ulp_count++;
3567 ulp_base_num = ulp_num;
3568 cid_count_ulp[ulp_num] =
3569 BEISCSI_GET_CID_COUNT(phba, ulp_num);
3570 }
3571
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303572 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
3573 wrb_mem_index = 0;
3574 offset = 0;
3575 size = 0;
3576
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07003577 if (ulp_count > 1) {
3578 ulp_base_num = (ulp_base_num + 1) % BEISCSI_ULP_COUNT;
3579
3580 if (!cid_count_ulp[ulp_base_num])
3581 ulp_base_num = (ulp_base_num + 1) %
3582 BEISCSI_ULP_COUNT;
3583
3584 cid_count_ulp[ulp_base_num]--;
3585 }
3586
3587
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303588 hwi_build_be_sgl_by_offset(phba, &pwrb_arr[i], &sgl);
3589 status = be_cmd_wrbq_create(&phba->ctrl, &sgl,
Jayamohan Kallickal4eea99d2013-09-28 15:35:48 -07003590 &phwi_context->be_wrbq[i],
3591 &phwi_ctrlr->wrb_context[i],
3592 ulp_base_num);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303593 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303594 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3595 "BM_%d : wrbq create failed.");
Dan Carpenter1462b8f2010-06-10 09:52:21 +02003596 kfree(pwrb_arr);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303597 return status;
3598 }
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003599 pwrb_context = &phwi_ctrlr->wrb_context[i];
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003600 BE_SET_CID_TO_CRI(i, pwrb_context->cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303601 }
3602 kfree(pwrb_arr);
3603 return 0;
3604}
3605
3606static void free_wrb_handles(struct beiscsi_hba *phba)
3607{
3608 unsigned int index;
3609 struct hwi_controller *phwi_ctrlr;
3610 struct hwi_wrb_context *pwrb_context;
3611
3612 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003613 for (index = 0; index < phba->params.cxns_per_ctrl; index++) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303614 pwrb_context = &phwi_ctrlr->wrb_context[index];
3615 kfree(pwrb_context->pwrb_handle_base);
3616 kfree(pwrb_context->pwrb_handle_basestd);
3617 }
3618}
3619
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303620static void be_mcc_queues_destroy(struct beiscsi_hba *phba)
3621{
3622 struct be_queue_info *q;
3623 struct be_ctrl_info *ctrl = &phba->ctrl;
3624
3625 q = &phba->ctrl.mcc_obj.q;
3626 if (q->created)
3627 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_MCCQ);
3628 be_queue_free(phba, q);
3629
3630 q = &phba->ctrl.mcc_obj.cq;
3631 if (q->created)
3632 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
3633 be_queue_free(phba, q);
3634}
3635
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303636static void hwi_cleanup(struct beiscsi_hba *phba)
3637{
3638 struct be_queue_info *q;
3639 struct be_ctrl_info *ctrl = &phba->ctrl;
3640 struct hwi_controller *phwi_ctrlr;
3641 struct hwi_context_memory *phwi_context;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003642 struct hwi_async_pdu_context *pasync_ctx;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003643 int i, eq_num, ulp_num;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303644
3645 phwi_ctrlr = phba->phwi_ctrlr;
3646 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07003647
3648 be_cmd_iscsi_remove_template_hdr(ctrl);
3649
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303650 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
3651 q = &phwi_context->be_wrbq[i];
3652 if (q->created)
3653 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_WRBQ);
3654 }
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003655 kfree(phwi_context->be_wrbq);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303656 free_wrb_handles(phba);
3657
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003658 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
3659 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303660
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003661 q = &phwi_context->be_def_hdrq[ulp_num];
3662 if (q->created)
3663 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
3664
3665 q = &phwi_context->be_def_dataq[ulp_num];
3666 if (q->created)
3667 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_DPDUQ);
3668
3669 pasync_ctx = phwi_ctrlr->phwi_ctxt->pasync_ctx[ulp_num];
3670 }
3671 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303672
3673 beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
3674
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303675 for (i = 0; i < (phba->num_cpus); i++) {
3676 q = &phwi_context->be_cq[i];
3677 if (q->created)
3678 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_CQ);
3679 }
3680 if (phba->msix_enabled)
3681 eq_num = 1;
3682 else
3683 eq_num = 0;
3684 for (i = 0; i < (phba->num_cpus + eq_num); i++) {
3685 q = &phwi_context->be_eq[i].q;
3686 if (q->created)
3687 beiscsi_cmd_q_destroy(ctrl, q, QTYPE_EQ);
3688 }
3689 be_mcc_queues_destroy(phba);
Jayamohan Kallickal0283fbb2013-04-05 20:38:21 -07003690 be_cmd_fw_uninit(ctrl);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303691}
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303692
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303693static int be_mcc_queues_create(struct beiscsi_hba *phba,
3694 struct hwi_context_memory *phwi_context)
3695{
3696 struct be_queue_info *q, *cq;
3697 struct be_ctrl_info *ctrl = &phba->ctrl;
3698
3699 /* Alloc MCC compl queue */
3700 cq = &phba->ctrl.mcc_obj.cq;
3701 if (be_queue_alloc(phba, cq, MCC_CQ_LEN,
3702 sizeof(struct be_mcc_compl)))
3703 goto err;
3704 /* Ask BE to create MCC compl queue; */
3705 if (phba->msix_enabled) {
3706 if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq
3707 [phba->num_cpus].q, false, true, 0))
3708 goto mcc_cq_free;
3709 } else {
3710 if (beiscsi_cmd_cq_create(ctrl, cq, &phwi_context->be_eq[0].q,
3711 false, true, 0))
3712 goto mcc_cq_free;
3713 }
3714
3715 /* Alloc MCC queue */
3716 q = &phba->ctrl.mcc_obj.q;
3717 if (be_queue_alloc(phba, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb)))
3718 goto mcc_cq_destroy;
3719
3720 /* Ask BE to create MCC queue */
Jayamohan Kallickal35e66012009-10-23 11:53:49 +05303721 if (beiscsi_cmd_mccq_create(phba, q, cq))
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303722 goto mcc_q_free;
3723
3724 return 0;
3725
3726mcc_q_free:
3727 be_queue_free(phba, q);
3728mcc_cq_destroy:
3729 beiscsi_cmd_q_destroy(ctrl, cq, QTYPE_CQ);
3730mcc_cq_free:
3731 be_queue_free(phba, cq);
3732err:
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +05303733 return -ENOMEM;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303734}
3735
John Soni Jose107dfcb2012-10-20 04:42:13 +05303736/**
3737 * find_num_cpus()- Get the CPU online count
3738 * @phba: ptr to priv structure
3739 *
3740 * CPU count is used for creating EQ.
3741 **/
3742static void find_num_cpus(struct beiscsi_hba *phba)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303743{
3744 int num_cpus = 0;
3745
3746 num_cpus = num_online_cpus();
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303747
John Soni Jose22abeef2012-10-20 04:43:32 +05303748 switch (phba->generation) {
3749 case BE_GEN2:
3750 case BE_GEN3:
3751 phba->num_cpus = (num_cpus > BEISCSI_MAX_NUM_CPUS) ?
3752 BEISCSI_MAX_NUM_CPUS : num_cpus;
3753 break;
3754 case BE_GEN4:
3755 phba->num_cpus = (num_cpus > OC_SKH_MAX_NUM_CPUS) ?
3756 OC_SKH_MAX_NUM_CPUS : num_cpus;
3757 break;
3758 default:
3759 phba->num_cpus = 1;
3760 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303761}
3762
3763static int hwi_init_port(struct beiscsi_hba *phba)
3764{
3765 struct hwi_controller *phwi_ctrlr;
3766 struct hwi_context_memory *phwi_context;
3767 unsigned int def_pdu_ring_sz;
3768 struct be_ctrl_info *ctrl = &phba->ctrl;
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003769 int status, ulp_num;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303770
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303771 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303772 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303773 phwi_context->max_eqd = 0;
3774 phwi_context->min_eqd = 0;
3775 phwi_context->cur_eqd = 64;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303776 be_cmd_fw_initialize(&phba->ctrl);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303777
3778 status = beiscsi_create_eqs(phba, phwi_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303779 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303780 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3781 "BM_%d : EQ not created\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303782 goto error;
3783 }
3784
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303785 status = be_mcc_queues_create(phba, phwi_context);
3786 if (status != 0)
3787 goto error;
3788
3789 status = mgmt_check_supported_fw(ctrl, phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303790 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303791 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3792 "BM_%d : Unsupported fw version\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303793 goto error;
3794 }
3795
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303796 status = beiscsi_create_cqs(phba, phwi_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303797 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303798 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3799 "BM_%d : CQ not created\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303800 goto error;
3801 }
3802
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003803 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
3804 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303805
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003806 def_pdu_ring_sz =
3807 BEISCSI_GET_CID_COUNT(phba, ulp_num) *
3808 sizeof(struct phys_addr);
3809
3810 status = beiscsi_create_def_hdr(phba, phwi_context,
3811 phwi_ctrlr,
3812 def_pdu_ring_sz,
3813 ulp_num);
3814 if (status != 0) {
3815 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3816 "BM_%d : Default Header not created for ULP : %d\n",
3817 ulp_num);
3818 goto error;
3819 }
3820
3821 status = beiscsi_create_def_data(phba, phwi_context,
3822 phwi_ctrlr,
3823 def_pdu_ring_sz,
3824 ulp_num);
3825 if (status != 0) {
3826 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3827 "BM_%d : Default Data not created for ULP : %d\n",
3828 ulp_num);
3829 goto error;
3830 }
3831 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303832 }
3833
3834 status = beiscsi_post_pages(phba);
3835 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303836 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3837 "BM_%d : Post SGL Pages Failed\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303838 goto error;
3839 }
3840
Jayamohan Kallickal15a90fe2013-09-28 15:35:38 -07003841 status = beiscsi_post_template_hdr(phba);
3842 if (status != 0) {
3843 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3844 "BM_%d : Template HDR Posting for CXN Failed\n");
3845 }
3846
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303847 status = beiscsi_create_wrb_rings(phba, phwi_context, phwi_ctrlr);
3848 if (status != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303849 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3850 "BM_%d : WRB Rings not created\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303851 goto error;
3852 }
3853
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003854 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
3855 uint16_t async_arr_idx = 0;
3856
3857 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
3858 uint16_t cri = 0;
3859 struct hwi_async_pdu_context *pasync_ctx;
3860
3861 pasync_ctx = HWI_GET_ASYNC_PDU_CTX(
3862 phwi_ctrlr, ulp_num);
3863 for (cri = 0; cri <
3864 phba->params.cxns_per_ctrl; cri++) {
3865 if (ulp_num == BEISCSI_GET_ULP_FROM_CRI
3866 (phwi_ctrlr, cri))
3867 pasync_ctx->cid_to_async_cri_map[
3868 phwi_ctrlr->wrb_context[cri].cid] =
3869 async_arr_idx++;
3870 }
3871 }
3872 }
3873
John Soni Jose99bc5d52012-08-20 23:00:18 +05303874 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3875 "BM_%d : hwi_init_port success\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303876 return 0;
3877
3878error:
John Soni Jose99bc5d52012-08-20 23:00:18 +05303879 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3880 "BM_%d : hwi_init_port failed");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303881 hwi_cleanup(phba);
Jayamohan Kallickala49e06d2012-04-03 23:41:44 -05003882 return status;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303883}
3884
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303885static int hwi_init_controller(struct beiscsi_hba *phba)
3886{
3887 struct hwi_controller *phwi_ctrlr;
3888
3889 phwi_ctrlr = phba->phwi_ctrlr;
3890 if (1 == phba->init_mem[HWI_MEM_ADDN_CONTEXT].num_elements) {
3891 phwi_ctrlr->phwi_ctxt = (struct hwi_context_memory *)phba->
3892 init_mem[HWI_MEM_ADDN_CONTEXT].mem_array[0].virtual_address;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303893 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3894 "BM_%d : phwi_ctrlr->phwi_ctxt=%p\n",
3895 phwi_ctrlr->phwi_ctxt);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303896 } else {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303897 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3898 "BM_%d : HWI_MEM_ADDN_CONTEXT is more "
3899 "than one element.Failing to load\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303900 return -ENOMEM;
3901 }
3902
3903 iscsi_init_global_templates(phba);
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05003904 if (beiscsi_init_wrb_handle(phba))
3905 return -ENOMEM;
3906
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003907 if (hwi_init_async_pdu_ctx(phba)) {
3908 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3909 "BM_%d : hwi_init_async_pdu_ctx failed\n");
3910 return -ENOMEM;
3911 }
3912
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303913 if (hwi_init_port(phba) != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303914 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3915 "BM_%d : hwi_init_controller failed\n");
3916
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303917 return -ENOMEM;
3918 }
3919 return 0;
3920}
3921
3922static void beiscsi_free_mem(struct beiscsi_hba *phba)
3923{
3924 struct be_mem_descriptor *mem_descr;
3925 int i, j;
3926
3927 mem_descr = phba->init_mem;
3928 i = 0;
3929 j = 0;
3930 for (i = 0; i < SE_MEM_MAX; i++) {
3931 for (j = mem_descr->num_elements; j > 0; j--) {
3932 pci_free_consistent(phba->pcidev,
3933 mem_descr->mem_array[j - 1].size,
3934 mem_descr->mem_array[j - 1].virtual_address,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +05303935 (unsigned long)mem_descr->mem_array[j - 1].
3936 bus_address.u.a64.address);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303937 }
Jayamohan Kallickal8a86e832013-09-28 15:35:45 -07003938
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303939 kfree(mem_descr->mem_array);
3940 mem_descr++;
3941 }
3942 kfree(phba->init_mem);
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07003943 kfree(phba->phwi_ctrlr->wrb_context);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303944 kfree(phba->phwi_ctrlr);
3945}
3946
3947static int beiscsi_init_controller(struct beiscsi_hba *phba)
3948{
3949 int ret = -ENOMEM;
3950
3951 ret = beiscsi_get_memory(phba);
3952 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303953 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3954 "BM_%d : beiscsi_dev_probe -"
3955 "Failed in beiscsi_alloc_memory\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303956 return ret;
3957 }
3958
3959 ret = hwi_init_controller(phba);
3960 if (ret)
3961 goto free_init;
John Soni Jose99bc5d52012-08-20 23:00:18 +05303962 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
3963 "BM_%d : Return success from beiscsi_init_controller");
3964
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303965 return 0;
3966
3967free_init:
3968 beiscsi_free_mem(phba);
Jayamohan Kallickala49e06d2012-04-03 23:41:44 -05003969 return ret;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303970}
3971
3972static int beiscsi_init_sgl_handle(struct beiscsi_hba *phba)
3973{
3974 struct be_mem_descriptor *mem_descr_sglh, *mem_descr_sg;
3975 struct sgl_handle *psgl_handle;
3976 struct iscsi_sge *pfrag;
Jayamohan Kallickal90622db2013-09-28 15:35:47 -07003977 unsigned int arr_index, i, idx;
3978 unsigned int ulp_icd_start, ulp_num = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303979
3980 phba->io_sgl_hndl_avbl = 0;
3981 phba->eh_sgl_hndl_avbl = 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05303982
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303983 mem_descr_sglh = phba->init_mem;
3984 mem_descr_sglh += HWI_MEM_SGLH;
3985 if (1 == mem_descr_sglh->num_elements) {
3986 phba->io_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
3987 phba->params.ios_per_ctrl,
3988 GFP_KERNEL);
3989 if (!phba->io_sgl_hndl_base) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05303990 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
3991 "BM_%d : Mem Alloc Failed. Failing to load\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303992 return -ENOMEM;
3993 }
3994 phba->eh_sgl_hndl_base = kzalloc(sizeof(struct sgl_handle *) *
3995 (phba->params.icds_per_ctrl -
3996 phba->params.ios_per_ctrl),
3997 GFP_KERNEL);
3998 if (!phba->eh_sgl_hndl_base) {
3999 kfree(phba->io_sgl_hndl_base);
John Soni Jose99bc5d52012-08-20 23:00:18 +05304000 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4001 "BM_%d : Mem Alloc Failed. Failing to load\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304002 return -ENOMEM;
4003 }
4004 } else {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304005 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4006 "BM_%d : HWI_MEM_SGLH is more than one element."
4007 "Failing to load\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304008 return -ENOMEM;
4009 }
4010
4011 arr_index = 0;
4012 idx = 0;
4013 while (idx < mem_descr_sglh->num_elements) {
4014 psgl_handle = mem_descr_sglh->mem_array[idx].virtual_address;
4015
4016 for (i = 0; i < (mem_descr_sglh->mem_array[idx].size /
4017 sizeof(struct sgl_handle)); i++) {
4018 if (arr_index < phba->params.ios_per_ctrl) {
4019 phba->io_sgl_hndl_base[arr_index] = psgl_handle;
4020 phba->io_sgl_hndl_avbl++;
4021 arr_index++;
4022 } else {
4023 phba->eh_sgl_hndl_base[arr_index -
4024 phba->params.ios_per_ctrl] =
4025 psgl_handle;
4026 arr_index++;
4027 phba->eh_sgl_hndl_avbl++;
4028 }
4029 psgl_handle++;
4030 }
4031 idx++;
4032 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05304033 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4034 "BM_%d : phba->io_sgl_hndl_avbl=%d"
4035 "phba->eh_sgl_hndl_avbl=%d\n",
4036 phba->io_sgl_hndl_avbl,
4037 phba->eh_sgl_hndl_avbl);
4038
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304039 mem_descr_sg = phba->init_mem;
4040 mem_descr_sg += HWI_MEM_SGE;
John Soni Jose99bc5d52012-08-20 23:00:18 +05304041 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4042 "\n BM_%d : mem_descr_sg->num_elements=%d\n",
4043 mem_descr_sg->num_elements);
4044
Jayamohan Kallickal90622db2013-09-28 15:35:47 -07004045 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
4046 if (test_bit(ulp_num, &phba->fw_config.ulp_supported))
4047 break;
4048
4049 ulp_icd_start = phba->fw_config.iscsi_icd_start[ulp_num];
4050
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304051 arr_index = 0;
4052 idx = 0;
4053 while (idx < mem_descr_sg->num_elements) {
4054 pfrag = mem_descr_sg->mem_array[idx].virtual_address;
4055
4056 for (i = 0;
4057 i < (mem_descr_sg->mem_array[idx].size) /
4058 (sizeof(struct iscsi_sge) * phba->params.num_sge_per_io);
4059 i++) {
4060 if (arr_index < phba->params.ios_per_ctrl)
4061 psgl_handle = phba->io_sgl_hndl_base[arr_index];
4062 else
4063 psgl_handle = phba->eh_sgl_hndl_base[arr_index -
4064 phba->params.ios_per_ctrl];
4065 psgl_handle->pfrag = pfrag;
4066 AMAP_SET_BITS(struct amap_iscsi_sge, addr_hi, pfrag, 0);
4067 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, pfrag, 0);
4068 pfrag += phba->params.num_sge_per_io;
Jayamohan Kallickal90622db2013-09-28 15:35:47 -07004069 psgl_handle->sgl_index = ulp_icd_start + arr_index++;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304070 }
4071 idx++;
4072 }
4073 phba->io_sgl_free_index = 0;
4074 phba->io_sgl_alloc_index = 0;
4075 phba->eh_sgl_free_index = 0;
4076 phba->eh_sgl_alloc_index = 0;
4077 return 0;
4078}
4079
4080static int hba_setup_cid_tbls(struct beiscsi_hba *phba)
4081{
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07004082 int ret;
4083 uint16_t i, ulp_num;
4084 struct ulp_cid_info *ptr_cid_info = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304085
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07004086 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
4087 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
4088 ptr_cid_info = kzalloc(sizeof(struct ulp_cid_info),
4089 GFP_KERNEL);
4090
4091 if (!ptr_cid_info) {
4092 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4093 "BM_%d : Failed to allocate memory"
4094 "for ULP_CID_INFO for ULP : %d\n",
4095 ulp_num);
4096 ret = -ENOMEM;
4097 goto free_memory;
4098
4099 }
4100
4101 /* Allocate memory for CID array */
4102 ptr_cid_info->cid_array = kzalloc(sizeof(void *) *
4103 BEISCSI_GET_CID_COUNT(phba,
4104 ulp_num), GFP_KERNEL);
4105 if (!ptr_cid_info->cid_array) {
4106 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4107 "BM_%d : Failed to allocate memory"
4108 "for CID_ARRAY for ULP : %d\n",
4109 ulp_num);
4110 kfree(ptr_cid_info);
4111 ptr_cid_info = NULL;
4112 ret = -ENOMEM;
4113
4114 goto free_memory;
4115 }
4116 ptr_cid_info->avlbl_cids = BEISCSI_GET_CID_COUNT(
4117 phba, ulp_num);
4118
4119 /* Save the cid_info_array ptr */
4120 phba->cid_array_info[ulp_num] = ptr_cid_info;
4121 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304122 }
Jayamohan Kallickalc2462282010-01-05 05:05:34 +05304123 phba->ep_array = kzalloc(sizeof(struct iscsi_endpoint *) *
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004124 phba->params.cxns_per_ctrl, GFP_KERNEL);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304125 if (!phba->ep_array) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304126 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4127 "BM_%d : Failed to allocate memory in "
4128 "hba_setup_cid_tbls\n");
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07004129 ret = -ENOMEM;
4130
4131 goto free_memory;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304132 }
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004133
4134 phba->conn_table = kzalloc(sizeof(struct beiscsi_conn *) *
4135 phba->params.cxns_per_ctrl, GFP_KERNEL);
4136 if (!phba->conn_table) {
4137 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4138 "BM_%d : Failed to allocate memory in"
4139 "hba_setup_cid_tbls\n");
4140
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004141 kfree(phba->ep_array);
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004142 phba->ep_array = NULL;
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07004143 ret = -ENOMEM;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304144 }
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004145
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07004146 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
4147 ulp_num = phba->phwi_ctrlr->wrb_context[i].ulp_num;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004148
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07004149 ptr_cid_info = phba->cid_array_info[ulp_num];
4150 ptr_cid_info->cid_array[ptr_cid_info->cid_alloc++] =
4151 phba->phwi_ctrlr->wrb_context[i].cid;
4152
4153 }
4154
4155 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
4156 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
4157 ptr_cid_info = phba->cid_array_info[ulp_num];
4158
4159 ptr_cid_info->cid_alloc = 0;
4160 ptr_cid_info->cid_free = 0;
4161 }
4162 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304163 return 0;
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07004164
4165free_memory:
4166 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
4167 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
4168 ptr_cid_info = phba->cid_array_info[ulp_num];
4169
4170 if (ptr_cid_info) {
4171 kfree(ptr_cid_info->cid_array);
4172 kfree(ptr_cid_info);
4173 phba->cid_array_info[ulp_num] = NULL;
4174 }
4175 }
4176 }
4177
4178 return ret;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304179}
4180
Jayamohan Kallickal238f6b72010-07-22 04:23:22 +05304181static void hwi_enable_intr(struct beiscsi_hba *phba)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304182{
4183 struct be_ctrl_info *ctrl = &phba->ctrl;
4184 struct hwi_controller *phwi_ctrlr;
4185 struct hwi_context_memory *phwi_context;
4186 struct be_queue_info *eq;
4187 u8 __iomem *addr;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304188 u32 reg, i;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304189 u32 enabled;
4190
4191 phwi_ctrlr = phba->phwi_ctrlr;
4192 phwi_context = phwi_ctrlr->phwi_ctxt;
4193
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304194 addr = (u8 __iomem *) ((u8 __iomem *) ctrl->pcicfg +
4195 PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET);
4196 reg = ioread32(addr);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304197
4198 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
4199 if (!enabled) {
4200 reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
John Soni Jose99bc5d52012-08-20 23:00:18 +05304201 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4202 "BM_%d : reg =x%08x addr=%p\n", reg, addr);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304203 iowrite32(reg, addr);
Jayamohan Kallickal665d6d92011-04-29 14:30:06 -05004204 }
4205
4206 if (!phba->msix_enabled) {
4207 eq = &phwi_context->be_eq[0].q;
John Soni Jose99bc5d52012-08-20 23:00:18 +05304208 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4209 "BM_%d : eq->id=%d\n", eq->id);
4210
Jayamohan Kallickal665d6d92011-04-29 14:30:06 -05004211 hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
4212 } else {
4213 for (i = 0; i <= phba->num_cpus; i++) {
4214 eq = &phwi_context->be_eq[i].q;
John Soni Jose99bc5d52012-08-20 23:00:18 +05304215 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
4216 "BM_%d : eq->id=%d\n", eq->id);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304217 hwi_ring_eq_db(phba, eq->id, 0, 0, 1, 1);
4218 }
Jayamohan Kallickalc03af1a2010-02-20 08:05:43 +05304219 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304220}
4221
4222static void hwi_disable_intr(struct beiscsi_hba *phba)
4223{
4224 struct be_ctrl_info *ctrl = &phba->ctrl;
4225
4226 u8 __iomem *addr = ctrl->pcicfg + PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET;
4227 u32 reg = ioread32(addr);
4228
4229 u32 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
4230 if (enabled) {
4231 reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
4232 iowrite32(reg, addr);
4233 } else
John Soni Jose99bc5d52012-08-20 23:00:18 +05304234 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
4235 "BM_%d : In hwi_disable_intr, Already Disabled\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304236}
4237
John Soni Jose9aef4202012-08-20 23:00:08 +05304238/**
4239 * beiscsi_get_boot_info()- Get the boot session info
4240 * @phba: The device priv structure instance
4241 *
4242 * Get the boot target info and store in driver priv structure
4243 *
4244 * return values
4245 * Success: 0
4246 * Failure: Non-Zero Value
4247 **/
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304248static int beiscsi_get_boot_info(struct beiscsi_hba *phba)
4249{
Mike Christie0e438952012-04-03 23:41:51 -05004250 struct be_cmd_get_session_resp *session_resp;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304251 struct be_dma_mem nonemb_cmd;
John Soni Josee175def2012-10-20 04:45:40 +05304252 unsigned int tag;
John Soni Jose9aef4202012-08-20 23:00:08 +05304253 unsigned int s_handle;
Mike Christief457a462011-06-24 15:11:53 -05004254 int ret = -ENOMEM;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304255
John Soni Jose9aef4202012-08-20 23:00:08 +05304256 /* Get the session handle of the boot target */
4257 ret = be_mgmt_get_boot_shandle(phba, &s_handle);
4258 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304259 beiscsi_log(phba, KERN_ERR,
4260 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
4261 "BM_%d : No boot session\n");
John Soni Jose9aef4202012-08-20 23:00:08 +05304262 return ret;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304263 }
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304264 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
4265 sizeof(*session_resp),
4266 &nonemb_cmd.dma);
4267 if (nonemb_cmd.va == NULL) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304268 beiscsi_log(phba, KERN_ERR,
4269 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
4270 "BM_%d : Failed to allocate memory for"
4271 "beiscsi_get_session_info\n");
4272
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304273 return -ENOMEM;
4274 }
4275
4276 memset(nonemb_cmd.va, 0, sizeof(*session_resp));
John Soni Jose9aef4202012-08-20 23:00:08 +05304277 tag = mgmt_get_session_info(phba, s_handle,
Mike Christie0e438952012-04-03 23:41:51 -05004278 &nonemb_cmd);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304279 if (!tag) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304280 beiscsi_log(phba, KERN_ERR,
4281 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
4282 "BM_%d : beiscsi_get_session_info"
4283 " Failed\n");
4284
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304285 goto boot_freemem;
John Soni Josee175def2012-10-20 04:45:40 +05304286 }
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304287
John Soni Josee175def2012-10-20 04:45:40 +05304288 ret = beiscsi_mccq_compl(phba, tag, NULL, nonemb_cmd.va);
4289 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304290 beiscsi_log(phba, KERN_ERR,
4291 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
John Soni Josee175def2012-10-20 04:45:40 +05304292 "BM_%d : beiscsi_get_session_info Failed");
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304293 goto boot_freemem;
4294 }
John Soni Josee175def2012-10-20 04:45:40 +05304295
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304296 session_resp = nonemb_cmd.va ;
Mike Christief457a462011-06-24 15:11:53 -05004297
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304298 memcpy(&phba->boot_sess, &session_resp->session_info,
4299 sizeof(struct mgmt_session_info));
Mike Christief457a462011-06-24 15:11:53 -05004300 ret = 0;
4301
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304302boot_freemem:
4303 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
4304 nonemb_cmd.va, nonemb_cmd.dma);
Mike Christief457a462011-06-24 15:11:53 -05004305 return ret;
4306}
4307
4308static void beiscsi_boot_release(void *data)
4309{
4310 struct beiscsi_hba *phba = data;
4311
4312 scsi_host_put(phba->shost);
4313}
4314
4315static int beiscsi_setup_boot_info(struct beiscsi_hba *phba)
4316{
4317 struct iscsi_boot_kobj *boot_kobj;
4318
4319 /* get boot info using mgmt cmd */
4320 if (beiscsi_get_boot_info(phba))
4321 /* Try to see if we can carry on without this */
4322 return 0;
4323
4324 phba->boot_kset = iscsi_boot_create_host_kset(phba->shost->host_no);
4325 if (!phba->boot_kset)
4326 return -ENOMEM;
4327
4328 /* get a ref because the show function will ref the phba */
4329 if (!scsi_host_get(phba->shost))
4330 goto free_kset;
4331 boot_kobj = iscsi_boot_create_target(phba->boot_kset, 0, phba,
4332 beiscsi_show_boot_tgt_info,
4333 beiscsi_tgt_get_attr_visibility,
4334 beiscsi_boot_release);
4335 if (!boot_kobj)
4336 goto put_shost;
4337
4338 if (!scsi_host_get(phba->shost))
4339 goto free_kset;
4340 boot_kobj = iscsi_boot_create_initiator(phba->boot_kset, 0, phba,
4341 beiscsi_show_boot_ini_info,
4342 beiscsi_ini_get_attr_visibility,
4343 beiscsi_boot_release);
4344 if (!boot_kobj)
4345 goto put_shost;
4346
4347 if (!scsi_host_get(phba->shost))
4348 goto free_kset;
4349 boot_kobj = iscsi_boot_create_ethernet(phba->boot_kset, 0, phba,
4350 beiscsi_show_boot_eth_info,
4351 beiscsi_eth_get_attr_visibility,
4352 beiscsi_boot_release);
4353 if (!boot_kobj)
4354 goto put_shost;
4355 return 0;
4356
4357put_shost:
4358 scsi_host_put(phba->shost);
4359free_kset:
4360 iscsi_boot_destroy_kset(phba->boot_kset);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +05304361 return -ENOMEM;
4362}
4363
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304364static int beiscsi_init_port(struct beiscsi_hba *phba)
4365{
4366 int ret;
4367
4368 ret = beiscsi_init_controller(phba);
4369 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304370 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4371 "BM_%d : beiscsi_dev_probe - Failed in"
4372 "beiscsi_init_controller\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304373 return ret;
4374 }
4375 ret = beiscsi_init_sgl_handle(phba);
4376 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304377 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4378 "BM_%d : beiscsi_dev_probe - Failed in"
4379 "beiscsi_init_sgl_handle\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304380 goto do_cleanup_ctrlr;
4381 }
4382
4383 if (hba_setup_cid_tbls(phba)) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304384 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
4385 "BM_%d : Failed in hba_setup_cid_tbls\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304386 kfree(phba->io_sgl_hndl_base);
4387 kfree(phba->eh_sgl_hndl_base);
4388 goto do_cleanup_ctrlr;
4389 }
4390
4391 return ret;
4392
4393do_cleanup_ctrlr:
4394 hwi_cleanup(phba);
4395 return ret;
4396}
4397
4398static void hwi_purge_eq(struct beiscsi_hba *phba)
4399{
4400 struct hwi_controller *phwi_ctrlr;
4401 struct hwi_context_memory *phwi_context;
4402 struct be_queue_info *eq;
4403 struct be_eq_entry *eqe = NULL;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304404 int i, eq_msix;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05304405 unsigned int num_processed;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304406
4407 phwi_ctrlr = phba->phwi_ctrlr;
4408 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304409 if (phba->msix_enabled)
4410 eq_msix = 1;
4411 else
4412 eq_msix = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304413
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304414 for (i = 0; i < (phba->num_cpus + eq_msix); i++) {
4415 eq = &phwi_context->be_eq[i].q;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304416 eqe = queue_tail_node(eq);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05304417 num_processed = 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304418 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
4419 & EQE_VALID_MASK) {
4420 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
4421 queue_tail_inc(eq);
4422 eqe = queue_tail_node(eq);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05304423 num_processed++;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304424 }
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05304425
4426 if (num_processed)
4427 hwi_ring_eq_db(phba, eq->id, 1, num_processed, 1, 1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304428 }
4429}
4430
4431static void beiscsi_clean_port(struct beiscsi_hba *phba)
4432{
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07004433 int mgmt_status, ulp_num;
4434 struct ulp_cid_info *ptr_cid_info = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304435
4436 mgmt_status = mgmt_epfw_cleanup(phba, CMD_CONNECTION_CHUTE_0);
4437 if (mgmt_status)
John Soni Jose99bc5d52012-08-20 23:00:18 +05304438 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
4439 "BM_%d : mgmt_epfw_cleanup FAILED\n");
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05304440
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304441 hwi_purge_eq(phba);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05304442 hwi_cleanup(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304443 kfree(phba->io_sgl_hndl_base);
4444 kfree(phba->eh_sgl_hndl_base);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304445 kfree(phba->ep_array);
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004446 kfree(phba->conn_table);
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07004447
4448 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
4449 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
4450 ptr_cid_info = phba->cid_array_info[ulp_num];
4451
4452 if (ptr_cid_info) {
4453 kfree(ptr_cid_info->cid_array);
4454 kfree(ptr_cid_info);
4455 phba->cid_array_info[ulp_num] = NULL;
4456 }
4457 }
4458 }
4459
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304460}
4461
John Soni Josed629c472012-10-20 04:42:00 +05304462/**
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004463 * beiscsi_free_mgmt_task_handles()- Free driver CXN resources
4464 * @beiscsi_conn: ptr to the conn to be cleaned up
Jayamohan Kallickal4a4a11b2013-04-05 20:38:31 -07004465 * @task: ptr to iscsi_task resource to be freed.
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004466 *
4467 * Free driver mgmt resources binded to CXN.
4468 **/
4469void
Jayamohan Kallickal4a4a11b2013-04-05 20:38:31 -07004470beiscsi_free_mgmt_task_handles(struct beiscsi_conn *beiscsi_conn,
4471 struct iscsi_task *task)
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004472{
4473 struct beiscsi_io_task *io_task;
4474 struct beiscsi_hba *phba = beiscsi_conn->phba;
4475 struct hwi_wrb_context *pwrb_context;
4476 struct hwi_controller *phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004477 uint16_t cri_index = BE_GET_CRI_FROM_CID(
4478 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004479
4480 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004481 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
4482
Jayamohan Kallickal4a4a11b2013-04-05 20:38:31 -07004483 io_task = task->dd_data;
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004484
4485 if (io_task->pwrb_handle) {
4486 memset(io_task->pwrb_handle->pwrb, 0,
4487 sizeof(struct iscsi_wrb));
4488 free_wrb_handle(phba, pwrb_context,
4489 io_task->pwrb_handle);
4490 io_task->pwrb_handle = NULL;
4491 }
4492
4493 if (io_task->psgl_handle) {
4494 spin_lock_bh(&phba->mgmt_sgl_lock);
4495 free_mgmt_sgl_handle(phba,
4496 io_task->psgl_handle);
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004497 io_task->psgl_handle = NULL;
Jayamohan Kallickal4a4a11b2013-04-05 20:38:31 -07004498 spin_unlock_bh(&phba->mgmt_sgl_lock);
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004499 }
4500
4501 if (io_task->mtask_addr)
4502 pci_unmap_single(phba->pcidev,
4503 io_task->mtask_addr,
4504 io_task->mtask_data_count,
4505 PCI_DMA_TODEVICE);
4506}
4507
4508/**
John Soni Josed629c472012-10-20 04:42:00 +05304509 * beiscsi_cleanup_task()- Free driver resources of the task
4510 * @task: ptr to the iscsi task
4511 *
4512 **/
Mike Christie1282ab72012-04-18 03:06:00 -05004513static void beiscsi_cleanup_task(struct iscsi_task *task)
4514{
4515 struct beiscsi_io_task *io_task = task->dd_data;
4516 struct iscsi_conn *conn = task->conn;
4517 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4518 struct beiscsi_hba *phba = beiscsi_conn->phba;
4519 struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
4520 struct hwi_wrb_context *pwrb_context;
4521 struct hwi_controller *phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004522 uint16_t cri_index = BE_GET_CRI_FROM_CID(
4523 beiscsi_conn->beiscsi_conn_cid);
Mike Christie1282ab72012-04-18 03:06:00 -05004524
4525 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004526 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
Mike Christie1282ab72012-04-18 03:06:00 -05004527
4528 if (io_task->cmd_bhs) {
4529 pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
4530 io_task->bhs_pa.u.a64.address);
4531 io_task->cmd_bhs = NULL;
4532 }
4533
4534 if (task->sc) {
4535 if (io_task->pwrb_handle) {
4536 free_wrb_handle(phba, pwrb_context,
4537 io_task->pwrb_handle);
4538 io_task->pwrb_handle = NULL;
4539 }
4540
4541 if (io_task->psgl_handle) {
4542 spin_lock(&phba->io_sgl_lock);
4543 free_io_sgl_handle(phba, io_task->psgl_handle);
4544 spin_unlock(&phba->io_sgl_lock);
4545 io_task->psgl_handle = NULL;
4546 }
4547 } else {
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004548 if (!beiscsi_conn->login_in_progress)
Jayamohan Kallickal4a4a11b2013-04-05 20:38:31 -07004549 beiscsi_free_mgmt_task_handles(beiscsi_conn, task);
Mike Christie1282ab72012-04-18 03:06:00 -05004550 }
4551}
4552
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304553void
4554beiscsi_offload_connection(struct beiscsi_conn *beiscsi_conn,
4555 struct beiscsi_offload_params *params)
4556{
4557 struct wrb_handle *pwrb_handle;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304558 struct beiscsi_hba *phba = beiscsi_conn->phba;
Mike Christie1282ab72012-04-18 03:06:00 -05004559 struct iscsi_task *task = beiscsi_conn->task;
4560 struct iscsi_session *session = task->conn->session;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304561 u32 doorbell = 0;
4562
4563 /*
4564 * We can always use 0 here because it is reserved by libiscsi for
4565 * login/startup related tasks.
4566 */
Mike Christie1282ab72012-04-18 03:06:00 -05004567 beiscsi_conn->login_in_progress = 0;
4568 spin_lock_bh(&session->lock);
4569 beiscsi_cleanup_task(task);
4570 spin_unlock_bh(&session->lock);
4571
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004572 pwrb_handle = alloc_wrb_handle(phba, beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304573
John Soni Joseacb96932012-10-20 04:44:35 +05304574 /* Check for the adapter family */
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004575 if (is_chip_be2_be3r(phba))
John Soni Joseacb96932012-10-20 04:44:35 +05304576 beiscsi_offload_cxn_v0(params, pwrb_handle,
4577 phba->init_mem);
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004578 else
4579 beiscsi_offload_cxn_v2(params, pwrb_handle);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304580
John Soni Joseacb96932012-10-20 04:44:35 +05304581 be_dws_le_to_cpu(pwrb_handle->pwrb,
4582 sizeof(struct iscsi_target_context_update_wrb));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304583
4584 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304585 doorbell |= (pwrb_handle->wrb_index & DB_DEF_PDU_WRB_INDEX_MASK)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304586 << DB_DEF_PDU_WRB_INDEX_SHIFT;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304587 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
Jayamohan Kallickal1e4be6f2013-09-28 15:35:50 -07004588 iowrite32(doorbell, phba->db_va +
4589 beiscsi_conn->doorbell_offset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304590}
4591
4592static void beiscsi_parse_pdu(struct iscsi_conn *conn, itt_t itt,
4593 int *index, int *age)
4594{
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304595 *index = (int)itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304596 if (age)
4597 *age = conn->session->age;
4598}
4599
4600/**
4601 * beiscsi_alloc_pdu - allocates pdu and related resources
4602 * @task: libiscsi task
4603 * @opcode: opcode of pdu for task
4604 *
4605 * This is called with the session lock held. It will allocate
4606 * the wrb and sgl if needed for the command. And it will prep
4607 * the pdu's itt. beiscsi_parse_pdu will later translate
4608 * the pdu itt to the libiscsi task itt.
4609 */
4610static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
4611{
4612 struct beiscsi_io_task *io_task = task->dd_data;
4613 struct iscsi_conn *conn = task->conn;
4614 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4615 struct beiscsi_hba *phba = beiscsi_conn->phba;
4616 struct hwi_wrb_context *pwrb_context;
4617 struct hwi_controller *phwi_ctrlr;
4618 itt_t itt;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004619 uint16_t cri_index = 0;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304620 struct beiscsi_session *beiscsi_sess = beiscsi_conn->beiscsi_sess;
4621 dma_addr_t paddr;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304622
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304623 io_task->cmd_bhs = pci_pool_alloc(beiscsi_sess->bhs_pool,
Mike Christiebc7acce2010-12-31 02:22:19 -06004624 GFP_ATOMIC, &paddr);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304625 if (!io_task->cmd_bhs)
4626 return -ENOMEM;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304627 io_task->bhs_pa.u.a64.address = paddr;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304628 io_task->libiscsi_itt = (itt_t)task->itt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304629 io_task->conn = beiscsi_conn;
4630
4631 task->hdr = (struct iscsi_hdr *)&io_task->cmd_bhs->iscsi_hdr;
4632 task->hdr_max = sizeof(struct be_cmd_bhs);
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304633 io_task->psgl_handle = NULL;
Jayamohan Kallickal3ec78272012-04-03 23:41:38 -05004634 io_task->pwrb_handle = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304635
4636 if (task->sc) {
4637 spin_lock(&phba->io_sgl_lock);
4638 io_task->psgl_handle = alloc_io_sgl_handle(phba);
4639 spin_unlock(&phba->io_sgl_lock);
John Soni Jose8359c792012-10-20 04:43:03 +05304640 if (!io_task->psgl_handle) {
4641 beiscsi_log(phba, KERN_ERR,
4642 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
4643 "BM_%d : Alloc of IO_SGL_ICD Failed"
4644 "for the CID : %d\n",
4645 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304646 goto free_hndls;
John Soni Jose8359c792012-10-20 04:43:03 +05304647 }
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304648 io_task->pwrb_handle = alloc_wrb_handle(phba,
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004649 beiscsi_conn->beiscsi_conn_cid);
John Soni Jose8359c792012-10-20 04:43:03 +05304650 if (!io_task->pwrb_handle) {
4651 beiscsi_log(phba, KERN_ERR,
4652 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
4653 "BM_%d : Alloc of WRB_HANDLE Failed"
4654 "for the CID : %d\n",
4655 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304656 goto free_io_hndls;
John Soni Jose8359c792012-10-20 04:43:03 +05304657 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304658 } else {
4659 io_task->scsi_cmnd = NULL;
Jayamohan Kallickald7aea672010-01-05 05:08:39 +05304660 if ((opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN) {
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07004661 beiscsi_conn->task = task;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304662 if (!beiscsi_conn->login_in_progress) {
4663 spin_lock(&phba->mgmt_sgl_lock);
4664 io_task->psgl_handle = (struct sgl_handle *)
4665 alloc_mgmt_sgl_handle(phba);
4666 spin_unlock(&phba->mgmt_sgl_lock);
John Soni Jose8359c792012-10-20 04:43:03 +05304667 if (!io_task->psgl_handle) {
4668 beiscsi_log(phba, KERN_ERR,
4669 BEISCSI_LOG_IO |
4670 BEISCSI_LOG_CONFIG,
4671 "BM_%d : Alloc of MGMT_SGL_ICD Failed"
4672 "for the CID : %d\n",
4673 beiscsi_conn->
4674 beiscsi_conn_cid);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304675 goto free_hndls;
John Soni Jose8359c792012-10-20 04:43:03 +05304676 }
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304677
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304678 beiscsi_conn->login_in_progress = 1;
4679 beiscsi_conn->plogin_sgl_handle =
4680 io_task->psgl_handle;
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304681 io_task->pwrb_handle =
4682 alloc_wrb_handle(phba,
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004683 beiscsi_conn->beiscsi_conn_cid);
John Soni Jose8359c792012-10-20 04:43:03 +05304684 if (!io_task->pwrb_handle) {
4685 beiscsi_log(phba, KERN_ERR,
4686 BEISCSI_LOG_IO |
4687 BEISCSI_LOG_CONFIG,
4688 "BM_%d : Alloc of WRB_HANDLE Failed"
4689 "for the CID : %d\n",
4690 beiscsi_conn->
4691 beiscsi_conn_cid);
4692 goto free_mgmt_hndls;
4693 }
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304694 beiscsi_conn->plogin_wrb_handle =
4695 io_task->pwrb_handle;
4696
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304697 } else {
4698 io_task->psgl_handle =
4699 beiscsi_conn->plogin_sgl_handle;
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304700 io_task->pwrb_handle =
4701 beiscsi_conn->plogin_wrb_handle;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304702 }
4703 } else {
4704 spin_lock(&phba->mgmt_sgl_lock);
4705 io_task->psgl_handle = alloc_mgmt_sgl_handle(phba);
4706 spin_unlock(&phba->mgmt_sgl_lock);
John Soni Jose8359c792012-10-20 04:43:03 +05304707 if (!io_task->psgl_handle) {
4708 beiscsi_log(phba, KERN_ERR,
4709 BEISCSI_LOG_IO |
4710 BEISCSI_LOG_CONFIG,
4711 "BM_%d : Alloc of MGMT_SGL_ICD Failed"
4712 "for the CID : %d\n",
4713 beiscsi_conn->
4714 beiscsi_conn_cid);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304715 goto free_hndls;
John Soni Jose8359c792012-10-20 04:43:03 +05304716 }
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304717 io_task->pwrb_handle =
4718 alloc_wrb_handle(phba,
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004719 beiscsi_conn->beiscsi_conn_cid);
John Soni Jose8359c792012-10-20 04:43:03 +05304720 if (!io_task->pwrb_handle) {
4721 beiscsi_log(phba, KERN_ERR,
4722 BEISCSI_LOG_IO | BEISCSI_LOG_CONFIG,
4723 "BM_%d : Alloc of WRB_HANDLE Failed"
4724 "for the CID : %d\n",
4725 beiscsi_conn->beiscsi_conn_cid);
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304726 goto free_mgmt_hndls;
John Soni Jose8359c792012-10-20 04:43:03 +05304727 }
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304728
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304729 }
4730 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304731 itt = (itt_t) cpu_to_be32(((unsigned int)io_task->pwrb_handle->
4732 wrb_index << 16) | (unsigned int)
4733 (io_task->psgl_handle->sgl_index));
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304734 io_task->pwrb_handle->pio_handle = task;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304735
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304736 io_task->cmd_bhs->iscsi_hdr.itt = itt;
4737 return 0;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304738
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304739free_io_hndls:
4740 spin_lock(&phba->io_sgl_lock);
4741 free_io_sgl_handle(phba, io_task->psgl_handle);
4742 spin_unlock(&phba->io_sgl_lock);
4743 goto free_hndls;
4744free_mgmt_hndls:
4745 spin_lock(&phba->mgmt_sgl_lock);
4746 free_mgmt_sgl_handle(phba, io_task->psgl_handle);
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004747 io_task->psgl_handle = NULL;
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304748 spin_unlock(&phba->mgmt_sgl_lock);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304749free_hndls:
4750 phwi_ctrlr = phba->phwi_ctrlr;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07004751 cri_index = BE_GET_CRI_FROM_CID(
4752 beiscsi_conn->beiscsi_conn_cid);
4753 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
Jayamohan Kallickald2cecf02010-07-22 04:25:40 +05304754 if (io_task->pwrb_handle)
4755 free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle);
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304756 io_task->pwrb_handle = NULL;
4757 pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
4758 io_task->bhs_pa.u.a64.address);
Mike Christie1282ab72012-04-18 03:06:00 -05004759 io_task->cmd_bhs = NULL;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +05304760 return -ENOMEM;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304761}
John Soni Jose09a10932012-10-20 04:44:23 +05304762int beiscsi_iotask_v2(struct iscsi_task *task, struct scatterlist *sg,
4763 unsigned int num_sg, unsigned int xferlen,
4764 unsigned int writedir)
4765{
4766
4767 struct beiscsi_io_task *io_task = task->dd_data;
4768 struct iscsi_conn *conn = task->conn;
4769 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4770 struct beiscsi_hba *phba = beiscsi_conn->phba;
4771 struct iscsi_wrb *pwrb = NULL;
4772 unsigned int doorbell = 0;
4773
4774 pwrb = io_task->pwrb_handle->pwrb;
John Soni Jose09a10932012-10-20 04:44:23 +05304775
4776 io_task->cmd_bhs->iscsi_hdr.exp_statsn = 0;
4777 io_task->bhs_len = sizeof(struct be_cmd_bhs);
4778
4779 if (writedir) {
4780 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb,
4781 INI_WR_CMD);
4782 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 1);
4783 } else {
4784 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, type, pwrb,
4785 INI_RD_CMD);
4786 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, dsp, pwrb, 0);
4787 }
4788
4789 io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb_v2,
4790 type, pwrb);
4791
4792 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, lun, pwrb,
4793 cpu_to_be16(*(unsigned short *)
4794 &io_task->cmd_bhs->iscsi_hdr.lun));
4795 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb, xferlen);
4796 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb,
4797 io_task->pwrb_handle->wrb_index);
4798 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb,
4799 be32_to_cpu(task->cmdsn));
4800 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb,
4801 io_task->psgl_handle->sgl_index);
4802
4803 hwi_write_sgl_v2(pwrb, sg, num_sg, io_task);
4804 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb,
4805 io_task->pwrb_handle->nxt_wrb_index);
4806
4807 be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
4808
4809 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
4810 doorbell |= (io_task->pwrb_handle->wrb_index &
4811 DB_DEF_PDU_WRB_INDEX_MASK) <<
4812 DB_DEF_PDU_WRB_INDEX_SHIFT;
4813 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
Jayamohan Kallickal1e4be6f2013-09-28 15:35:50 -07004814 iowrite32(doorbell, phba->db_va +
4815 beiscsi_conn->doorbell_offset);
John Soni Jose09a10932012-10-20 04:44:23 +05304816 return 0;
4817}
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304818
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304819static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg,
4820 unsigned int num_sg, unsigned int xferlen,
4821 unsigned int writedir)
4822{
4823
4824 struct beiscsi_io_task *io_task = task->dd_data;
4825 struct iscsi_conn *conn = task->conn;
4826 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4827 struct beiscsi_hba *phba = beiscsi_conn->phba;
4828 struct iscsi_wrb *pwrb = NULL;
4829 unsigned int doorbell = 0;
4830
4831 pwrb = io_task->pwrb_handle->pwrb;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304832 io_task->cmd_bhs->iscsi_hdr.exp_statsn = 0;
4833 io_task->bhs_len = sizeof(struct be_cmd_bhs);
4834
4835 if (writedir) {
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304836 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4837 INI_WR_CMD);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304838 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304839 } else {
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304840 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
4841 INI_RD_CMD);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304842 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
4843 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304844
John Soni Jose09a10932012-10-20 04:44:23 +05304845 io_task->wrb_type = AMAP_GET_BITS(struct amap_iscsi_wrb,
4846 type, pwrb);
4847
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304848 AMAP_SET_BITS(struct amap_iscsi_wrb, lun, pwrb,
Jayamohan Kallickaldc63aac2012-04-03 23:41:36 -05004849 cpu_to_be16(*(unsigned short *)
4850 &io_task->cmd_bhs->iscsi_hdr.lun));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304851 AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, xferlen);
4852 AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
4853 io_task->pwrb_handle->wrb_index);
4854 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
4855 be32_to_cpu(task->cmdsn));
4856 AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
4857 io_task->psgl_handle->sgl_index);
4858
4859 hwi_write_sgl(pwrb, sg, num_sg, io_task);
4860
4861 AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
4862 io_task->pwrb_handle->nxt_wrb_index);
4863 be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
4864
4865 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304866 doorbell |= (io_task->pwrb_handle->wrb_index &
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304867 DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
4868 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
4869
Jayamohan Kallickal1e4be6f2013-09-28 15:35:50 -07004870 iowrite32(doorbell, phba->db_va +
4871 beiscsi_conn->doorbell_offset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304872 return 0;
4873}
4874
4875static int beiscsi_mtask(struct iscsi_task *task)
4876{
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05304877 struct beiscsi_io_task *io_task = task->dd_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304878 struct iscsi_conn *conn = task->conn;
4879 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
4880 struct beiscsi_hba *phba = beiscsi_conn->phba;
4881 struct iscsi_wrb *pwrb = NULL;
4882 unsigned int doorbell = 0;
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05304883 unsigned int cid;
John Soni Jose09a10932012-10-20 04:44:23 +05304884 unsigned int pwrb_typeoffset = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304885
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304886 cid = beiscsi_conn->beiscsi_conn_cid;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304887 pwrb = io_task->pwrb_handle->pwrb;
Jayamohan Kallickalcaf818f2010-01-23 05:38:18 +05304888 memset(pwrb, 0, sizeof(*pwrb));
John Soni Jose09a10932012-10-20 04:44:23 +05304889
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004890 if (is_chip_be2_be3r(phba)) {
John Soni Jose09a10932012-10-20 04:44:23 +05304891 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
4892 be32_to_cpu(task->cmdsn));
4893 AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
4894 io_task->pwrb_handle->wrb_index);
4895 AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
4896 io_task->psgl_handle->sgl_index);
4897 AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb,
4898 task->data_count);
4899 AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
4900 io_task->pwrb_handle->nxt_wrb_index);
4901 pwrb_typeoffset = BE_WRB_TYPE_OFFSET;
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004902 } else {
4903 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, cmdsn_itt, pwrb,
4904 be32_to_cpu(task->cmdsn));
4905 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, wrb_idx, pwrb,
4906 io_task->pwrb_handle->wrb_index);
4907 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, sgl_idx, pwrb,
4908 io_task->psgl_handle->sgl_index);
4909 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, r2t_exp_dtl, pwrb,
4910 task->data_count);
4911 AMAP_SET_BITS(struct amap_iscsi_wrb_v2, ptr2nextwrb, pwrb,
4912 io_task->pwrb_handle->nxt_wrb_index);
4913 pwrb_typeoffset = SKH_WRB_TYPE_OFFSET;
John Soni Jose09a10932012-10-20 04:44:23 +05304914 }
4915
Jayamohan Kallickaldafab8e2010-02-20 08:03:56 +05304916
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304917 switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
4918 case ISCSI_OP_LOGIN:
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304919 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, 1);
John Soni Jose09a10932012-10-20 04:44:23 +05304920 ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304921 hwi_write_buffer(pwrb, task);
4922 break;
4923 case ISCSI_OP_NOOP_OUT:
Jayamohan Kallickal1390b012011-03-25 14:24:01 -07004924 if (task->hdr->ttt != ISCSI_RESERVED_TAG) {
John Soni Jose09a10932012-10-20 04:44:23 +05304925 ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset);
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004926 if (is_chip_be2_be3r(phba))
4927 AMAP_SET_BITS(struct amap_iscsi_wrb,
John Soni Jose09a10932012-10-20 04:44:23 +05304928 dmsg, pwrb, 1);
4929 else
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004930 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
John Soni Jose09a10932012-10-20 04:44:23 +05304931 dmsg, pwrb, 1);
Jayamohan Kallickal1390b012011-03-25 14:24:01 -07004932 } else {
John Soni Jose09a10932012-10-20 04:44:23 +05304933 ADAPTER_SET_WRB_TYPE(pwrb, INI_RD_CMD, pwrb_typeoffset);
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004934 if (is_chip_be2_be3r(phba))
4935 AMAP_SET_BITS(struct amap_iscsi_wrb,
John Soni Jose09a10932012-10-20 04:44:23 +05304936 dmsg, pwrb, 0);
4937 else
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004938 AMAP_SET_BITS(struct amap_iscsi_wrb_v2,
John Soni Jose09a10932012-10-20 04:44:23 +05304939 dmsg, pwrb, 0);
Jayamohan Kallickal1390b012011-03-25 14:24:01 -07004940 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304941 hwi_write_buffer(pwrb, task);
4942 break;
4943 case ISCSI_OP_TEXT:
John Soni Jose09a10932012-10-20 04:44:23 +05304944 ADAPTER_SET_WRB_TYPE(pwrb, TGT_DM_CMD, pwrb_typeoffset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304945 hwi_write_buffer(pwrb, task);
4946 break;
4947 case ISCSI_OP_SCSI_TMFUNC:
John Soni Jose09a10932012-10-20 04:44:23 +05304948 ADAPTER_SET_WRB_TYPE(pwrb, INI_TMF_CMD, pwrb_typeoffset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304949 hwi_write_buffer(pwrb, task);
4950 break;
4951 case ISCSI_OP_LOGOUT:
John Soni Jose09a10932012-10-20 04:44:23 +05304952 ADAPTER_SET_WRB_TYPE(pwrb, HWH_TYPE_LOGOUT, pwrb_typeoffset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304953 hwi_write_buffer(pwrb, task);
4954 break;
4955
4956 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +05304957 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
4958 "BM_%d : opcode =%d Not supported\n",
4959 task->hdr->opcode & ISCSI_OPCODE_MASK);
4960
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304961 return -EINVAL;
4962 }
4963
John Soni Jose09a10932012-10-20 04:44:23 +05304964 /* Set the task type */
Jayamohan Kallickal2c9dfd32013-04-05 20:38:26 -07004965 io_task->wrb_type = (is_chip_be2_be3r(phba)) ?
4966 AMAP_GET_BITS(struct amap_iscsi_wrb, type, pwrb) :
4967 AMAP_GET_BITS(struct amap_iscsi_wrb_v2, type, pwrb);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304968
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05304969 doorbell |= cid & DB_WRB_POST_CID_MASK;
Jayamohan Kallickal32951dd2010-01-23 05:34:24 +05304970 doorbell |= (io_task->pwrb_handle->wrb_index &
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304971 DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
4972 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
Jayamohan Kallickal1e4be6f2013-09-28 15:35:50 -07004973 iowrite32(doorbell, phba->db_va +
4974 beiscsi_conn->doorbell_offset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304975 return 0;
4976}
4977
4978static int beiscsi_task_xmit(struct iscsi_task *task)
4979{
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304980 struct beiscsi_io_task *io_task = task->dd_data;
4981 struct scsi_cmnd *sc = task->sc;
John Soni Jose09a10932012-10-20 04:44:23 +05304982 struct beiscsi_hba *phba = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304983 struct scatterlist *sg;
4984 int num_sg;
4985 unsigned int writedir = 0, xferlen = 0;
4986
John Soni Jose09a10932012-10-20 04:44:23 +05304987 phba = ((struct beiscsi_conn *)task->conn->dd_data)->phba;
4988
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05304989 if (!sc)
4990 return beiscsi_mtask(task);
4991
4992 io_task->scsi_cmnd = sc;
4993 num_sg = scsi_dma_map(sc);
4994 if (num_sg < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05304995 struct iscsi_conn *conn = task->conn;
4996 struct beiscsi_hba *phba = NULL;
4997
4998 phba = ((struct beiscsi_conn *)conn->dd_data)->phba;
4999 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_IO,
5000 "BM_%d : scsi_dma_map Failed\n");
5001
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305002 return num_sg;
5003 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305004 xferlen = scsi_bufflen(sc);
5005 sg = scsi_sglist(sc);
John Soni Jose99bc5d52012-08-20 23:00:18 +05305006 if (sc->sc_data_direction == DMA_TO_DEVICE)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305007 writedir = 1;
John Soni Jose99bc5d52012-08-20 23:00:18 +05305008 else
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305009 writedir = 0;
John Soni Jose99bc5d52012-08-20 23:00:18 +05305010
John Soni Jose09a10932012-10-20 04:44:23 +05305011 return phba->iotask_fn(task, sg, num_sg, xferlen, writedir);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305012}
5013
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05005014/**
5015 * beiscsi_bsg_request - handle bsg request from ISCSI transport
5016 * @job: job to handle
5017 */
5018static int beiscsi_bsg_request(struct bsg_job *job)
5019{
5020 struct Scsi_Host *shost;
5021 struct beiscsi_hba *phba;
5022 struct iscsi_bsg_request *bsg_req = job->request;
5023 int rc = -EINVAL;
5024 unsigned int tag;
5025 struct be_dma_mem nonemb_cmd;
5026 struct be_cmd_resp_hdr *resp;
5027 struct iscsi_bsg_reply *bsg_reply = job->reply;
5028 unsigned short status, extd_status;
5029
5030 shost = iscsi_job_to_shost(job);
5031 phba = iscsi_host_priv(shost);
5032
5033 switch (bsg_req->msgcode) {
5034 case ISCSI_BSG_HST_VENDOR:
5035 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
5036 job->request_payload.payload_len,
5037 &nonemb_cmd.dma);
5038 if (nonemb_cmd.va == NULL) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305039 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
5040 "BM_%d : Failed to allocate memory for "
5041 "beiscsi_bsg_request\n");
John Soni Jose8359c792012-10-20 04:43:03 +05305042 return -ENOMEM;
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05005043 }
5044 tag = mgmt_vendor_specific_fw_cmd(&phba->ctrl, phba, job,
5045 &nonemb_cmd);
5046 if (!tag) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305047 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
John Soni Jose8359c792012-10-20 04:43:03 +05305048 "BM_%d : MBX Tag Allocation Failed\n");
John Soni Jose99bc5d52012-08-20 23:00:18 +05305049
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05005050 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
5051 nonemb_cmd.va, nonemb_cmd.dma);
5052 return -EAGAIN;
John Soni Josee175def2012-10-20 04:45:40 +05305053 }
5054
5055 rc = wait_event_interruptible_timeout(
5056 phba->ctrl.mcc_wait[tag],
5057 phba->ctrl.mcc_numtag[tag],
5058 msecs_to_jiffies(
5059 BEISCSI_HOST_MBX_TIMEOUT));
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05005060 extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
5061 status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
5062 free_mcc_tag(&phba->ctrl, tag);
5063 resp = (struct be_cmd_resp_hdr *)nonemb_cmd.va;
5064 sg_copy_from_buffer(job->reply_payload.sg_list,
5065 job->reply_payload.sg_cnt,
5066 nonemb_cmd.va, (resp->response_length
5067 + sizeof(*resp)));
5068 bsg_reply->reply_payload_rcv_len = resp->response_length;
5069 bsg_reply->result = status;
5070 bsg_job_done(job, bsg_reply->result,
5071 bsg_reply->reply_payload_rcv_len);
5072 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
5073 nonemb_cmd.va, nonemb_cmd.dma);
5074 if (status || extd_status) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305075 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
John Soni Jose8359c792012-10-20 04:43:03 +05305076 "BM_%d : MBX Cmd Failed"
John Soni Jose99bc5d52012-08-20 23:00:18 +05305077 " status = %d extd_status = %d\n",
5078 status, extd_status);
5079
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05005080 return -EIO;
John Soni Jose8359c792012-10-20 04:43:03 +05305081 } else {
5082 rc = 0;
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05005083 }
5084 break;
5085
5086 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +05305087 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
5088 "BM_%d : Unsupported bsg command: 0x%x\n",
5089 bsg_req->msgcode);
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05005090 break;
5091 }
5092
5093 return rc;
5094}
5095
John Soni Jose99bc5d52012-08-20 23:00:18 +05305096void beiscsi_hba_attrs_init(struct beiscsi_hba *phba)
5097{
5098 /* Set the logging parameter */
5099 beiscsi_log_enable_init(phba, beiscsi_log_enable);
5100}
5101
John Soni Jose4d4d1ef2012-10-20 04:42:37 +05305102/*
5103 * beiscsi_quiesce()- Cleanup Driver resources
5104 * @phba: Instance Priv structure
5105 *
5106 * Free the OS and HW resources held by the driver
5107 **/
Jayamohan Kallickal25602c92011-08-22 10:08:28 -07005108static void beiscsi_quiesce(struct beiscsi_hba *phba)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305109{
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305110 struct hwi_controller *phwi_ctrlr;
5111 struct hwi_context_memory *phwi_context;
5112 struct be_eq_obj *pbe_eq;
5113 unsigned int i, msix_vec;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305114
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305115 phwi_ctrlr = phba->phwi_ctrlr;
5116 phwi_context = phwi_ctrlr->phwi_ctxt;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305117 hwi_disable_intr(phba);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305118 if (phba->msix_enabled) {
5119 for (i = 0; i <= phba->num_cpus; i++) {
5120 msix_vec = phba->msix_entries[i].vector;
5121 free_irq(msix_vec, &phwi_context->be_eq[i]);
Jayamohan Kallickal8fcfb212011-08-24 16:05:30 -07005122 kfree(phba->msi_name[i]);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305123 }
5124 } else
5125 if (phba->pcidev->irq)
5126 free_irq(phba->pcidev->irq, phba);
5127 pci_disable_msix(phba->pcidev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305128 destroy_workqueue(phba->wq);
5129 if (blk_iopoll_enabled)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305130 for (i = 0; i < phba->num_cpus; i++) {
5131 pbe_eq = &phwi_context->be_eq[i];
5132 blk_iopoll_disable(&pbe_eq->iopoll);
5133 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305134
5135 beiscsi_clean_port(phba);
5136 beiscsi_free_mem(phba);
Jayamohan Kallickale9b91192010-07-22 04:24:53 +05305137
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305138 beiscsi_unmap_pci_function(phba);
5139 pci_free_consistent(phba->pcidev,
5140 phba->ctrl.mbox_mem_alloced.size,
5141 phba->ctrl.mbox_mem_alloced.va,
5142 phba->ctrl.mbox_mem_alloced.dma);
John Soni Jose7a158002012-10-20 04:45:51 +05305143
5144 cancel_delayed_work_sync(&phba->beiscsi_hw_check_task);
Jayamohan Kallickal25602c92011-08-22 10:08:28 -07005145}
5146
5147static void beiscsi_remove(struct pci_dev *pcidev)
5148{
5149
5150 struct beiscsi_hba *phba = NULL;
5151
5152 phba = pci_get_drvdata(pcidev);
5153 if (!phba) {
5154 dev_err(&pcidev->dev, "beiscsi_remove called with no phba\n");
5155 return;
5156 }
5157
Mike Christie0e438952012-04-03 23:41:51 -05005158 beiscsi_destroy_def_ifaces(phba);
Jayamohan Kallickal25602c92011-08-22 10:08:28 -07005159 beiscsi_quiesce(phba);
Mike Christie9d045162011-06-24 15:11:52 -05005160 iscsi_boot_destroy_kset(phba->boot_kset);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305161 iscsi_host_remove(phba->shost);
5162 pci_dev_put(phba->pcidev);
5163 iscsi_host_free(phba->shost);
Jayamohan Kallickal8dce69f2011-08-22 10:08:29 -07005164 pci_disable_device(pcidev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305165}
5166
Jayamohan Kallickal25602c92011-08-22 10:08:28 -07005167static void beiscsi_shutdown(struct pci_dev *pcidev)
5168{
5169
5170 struct beiscsi_hba *phba = NULL;
5171
5172 phba = (struct beiscsi_hba *)pci_get_drvdata(pcidev);
5173 if (!phba) {
5174 dev_err(&pcidev->dev, "beiscsi_shutdown called with no phba\n");
5175 return;
5176 }
5177
5178 beiscsi_quiesce(phba);
Jayamohan Kallickal8dce69f2011-08-22 10:08:29 -07005179 pci_disable_device(pcidev);
Jayamohan Kallickal25602c92011-08-22 10:08:28 -07005180}
5181
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305182static void beiscsi_msix_enable(struct beiscsi_hba *phba)
5183{
5184 int i, status;
5185
5186 for (i = 0; i <= phba->num_cpus; i++)
5187 phba->msix_entries[i].entry = i;
5188
5189 status = pci_enable_msix(phba->pcidev, phba->msix_entries,
5190 (phba->num_cpus + 1));
5191 if (!status)
5192 phba->msix_enabled = true;
5193
5194 return;
5195}
5196
John Soni Jose7a158002012-10-20 04:45:51 +05305197/*
5198 * beiscsi_hw_health_check()- Check adapter health
5199 * @work: work item to check HW health
5200 *
5201 * Check if adapter in an unrecoverable state or not.
5202 **/
5203static void
5204beiscsi_hw_health_check(struct work_struct *work)
5205{
5206 struct beiscsi_hba *phba =
5207 container_of(work, struct beiscsi_hba,
5208 beiscsi_hw_check_task.work);
5209
5210 beiscsi_ue_detect(phba);
5211
5212 schedule_delayed_work(&phba->beiscsi_hw_check_task,
5213 msecs_to_jiffies(1000));
5214}
5215
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08005216static int beiscsi_dev_probe(struct pci_dev *pcidev,
5217 const struct pci_device_id *id)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305218{
5219 struct beiscsi_hba *phba = NULL;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305220 struct hwi_controller *phwi_ctrlr;
5221 struct hwi_context_memory *phwi_context;
5222 struct be_eq_obj *pbe_eq;
John Soni Jose107dfcb2012-10-20 04:42:13 +05305223 int ret, i;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305224
5225 ret = beiscsi_enable_pci(pcidev);
5226 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305227 dev_err(&pcidev->dev,
5228 "beiscsi_dev_probe - Failed to enable pci device\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305229 return ret;
5230 }
5231
5232 phba = beiscsi_hba_alloc(pcidev);
5233 if (!phba) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305234 dev_err(&pcidev->dev,
5235 "beiscsi_dev_probe - Failed in beiscsi_hba_alloc\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305236 goto disable_pci;
5237 }
5238
John Soni Jose99bc5d52012-08-20 23:00:18 +05305239 /* Initialize Driver configuration Paramters */
5240 beiscsi_hba_attrs_init(phba);
5241
John Soni Josee175def2012-10-20 04:45:40 +05305242 phba->fw_timeout = false;
Jayamohan Kallickal6c831852013-09-28 15:35:40 -07005243 phba->mac_addr_set = false;
John Soni Josee175def2012-10-20 04:45:40 +05305244
5245
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +05305246 switch (pcidev->device) {
5247 case BE_DEVICE_ID1:
5248 case OC_DEVICE_ID1:
5249 case OC_DEVICE_ID2:
5250 phba->generation = BE_GEN2;
John Soni Jose09a10932012-10-20 04:44:23 +05305251 phba->iotask_fn = beiscsi_iotask;
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +05305252 break;
5253 case BE_DEVICE_ID2:
5254 case OC_DEVICE_ID3:
5255 phba->generation = BE_GEN3;
John Soni Jose09a10932012-10-20 04:44:23 +05305256 phba->iotask_fn = beiscsi_iotask;
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +05305257 break;
John Soni Jose139a1b12012-10-20 04:43:20 +05305258 case OC_SKH_ID1:
5259 phba->generation = BE_GEN4;
John Soni Jose09a10932012-10-20 04:44:23 +05305260 phba->iotask_fn = beiscsi_iotask_v2;
Jayamohan Kallickalbf9131c2013-04-05 20:38:24 -07005261 break;
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +05305262 default:
5263 phba->generation = 0;
5264 }
5265
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305266 if (enable_msix)
John Soni Jose107dfcb2012-10-20 04:42:13 +05305267 find_num_cpus(phba);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305268 else
John Soni Jose107dfcb2012-10-20 04:42:13 +05305269 phba->num_cpus = 1;
5270
John Soni Jose99bc5d52012-08-20 23:00:18 +05305271 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
5272 "BM_%d : num_cpus = %d\n",
5273 phba->num_cpus);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305274
Jayamohan Kallickalb547f2d2012-04-03 23:41:41 -05005275 if (enable_msix) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305276 beiscsi_msix_enable(phba);
Jayamohan Kallickalb547f2d2012-04-03 23:41:41 -05005277 if (!phba->msix_enabled)
5278 phba->num_cpus = 1;
5279 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305280 ret = be_ctrl_init(phba, pcidev);
5281 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305282 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5283 "BM_%d : beiscsi_dev_probe-"
5284 "Failed in be_ctrl_init\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305285 goto hba_free;
5286 }
5287
John Soni Jose4d4d1ef2012-10-20 04:42:37 +05305288 ret = beiscsi_cmd_reset_function(phba);
5289 if (ret) {
5290 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
Jayamohan Kallickal92665a62013-09-28 15:35:43 -07005291 "BM_%d : Reset Failed\n");
John Soni Jose4d4d1ef2012-10-20 04:42:37 +05305292 goto hba_free;
5293 }
5294 ret = be_chk_reset_complete(phba);
5295 if (ret) {
5296 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
Jayamohan Kallickal92665a62013-09-28 15:35:43 -07005297 "BM_%d : Failed to get out of reset.\n");
John Soni Jose4d4d1ef2012-10-20 04:42:37 +05305298 goto hba_free;
Jayamohan Kallickale9b91192010-07-22 04:24:53 +05305299 }
5300
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305301 spin_lock_init(&phba->io_sgl_lock);
5302 spin_lock_init(&phba->mgmt_sgl_lock);
5303 spin_lock_init(&phba->isr_lock);
Jayamohan Kallickal8f09a3b2013-09-28 15:35:42 -07005304 spin_lock_init(&phba->async_pdu_lock);
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05305305 ret = mgmt_get_fw_config(&phba->ctrl, phba);
5306 if (ret != 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305307 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5308 "BM_%d : Error getting fw config\n");
Jayamohan Kallickal7da50872010-01-05 05:04:12 +05305309 goto free_port;
5310 }
Jayamohan Kallickal843ae752013-09-28 15:35:44 -07005311 phba->shost->max_id = phba->params.cxns_per_ctrl;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305312 beiscsi_get_params(phba);
Jayamohan Kallickalaa874f02010-01-05 05:12:03 +05305313 phba->shost->can_queue = phba->params.ios_per_ctrl;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305314 ret = beiscsi_init_port(phba);
5315 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305316 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5317 "BM_%d : beiscsi_dev_probe-"
5318 "Failed in beiscsi_init_port\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305319 goto free_port;
5320 }
5321
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05305322 for (i = 0; i < MAX_MCC_CMD ; i++) {
5323 init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]);
5324 phba->ctrl.mcc_tag[i] = i + 1;
5325 phba->ctrl.mcc_numtag[i + 1] = 0;
5326 phba->ctrl.mcc_tag_available++;
5327 }
5328
5329 phba->ctrl.mcc_alloc_index = phba->ctrl.mcc_free_index = 0;
5330
John Soni Jose72fb46a2012-10-20 04:42:49 +05305331 snprintf(phba->wq_name, sizeof(phba->wq_name), "beiscsi_%02x_wq",
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305332 phba->shost->host_no);
Kees Cookd8537542013-07-03 15:04:57 -07005333 phba->wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 1, phba->wq_name);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305334 if (!phba->wq) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305335 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5336 "BM_%d : beiscsi_dev_probe-"
5337 "Failed to allocate work queue\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305338 goto free_twq;
5339 }
5340
John Soni Jose7a158002012-10-20 04:45:51 +05305341 INIT_DELAYED_WORK(&phba->beiscsi_hw_check_task,
5342 beiscsi_hw_health_check);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305343
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305344 phwi_ctrlr = phba->phwi_ctrlr;
5345 phwi_context = phwi_ctrlr->phwi_ctxt;
John Soni Jose72fb46a2012-10-20 04:42:49 +05305346
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305347 if (blk_iopoll_enabled) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305348 for (i = 0; i < phba->num_cpus; i++) {
5349 pbe_eq = &phwi_context->be_eq[i];
5350 blk_iopoll_init(&pbe_eq->iopoll, be_iopoll_budget,
5351 be_iopoll);
5352 blk_iopoll_enable(&pbe_eq->iopoll);
5353 }
John Soni Jose72fb46a2012-10-20 04:42:49 +05305354
5355 i = (phba->msix_enabled) ? i : 0;
5356 /* Work item for MCC handling */
5357 pbe_eq = &phwi_context->be_eq[i];
5358 INIT_WORK(&pbe_eq->work_cqs, beiscsi_process_all_cqs);
5359 } else {
5360 if (phba->msix_enabled) {
5361 for (i = 0; i <= phba->num_cpus; i++) {
5362 pbe_eq = &phwi_context->be_eq[i];
5363 INIT_WORK(&pbe_eq->work_cqs,
5364 beiscsi_process_all_cqs);
5365 }
5366 } else {
5367 pbe_eq = &phwi_context->be_eq[0];
5368 INIT_WORK(&pbe_eq->work_cqs,
5369 beiscsi_process_all_cqs);
5370 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305371 }
John Soni Jose72fb46a2012-10-20 04:42:49 +05305372
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305373 ret = beiscsi_init_irqs(phba);
5374 if (ret < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305375 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5376 "BM_%d : beiscsi_dev_probe-"
5377 "Failed to beiscsi_init_irqs\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305378 goto free_blkenbld;
5379 }
Jayamohan Kallickal238f6b72010-07-22 04:23:22 +05305380 hwi_enable_intr(phba);
Mike Christief457a462011-06-24 15:11:53 -05005381
5382 if (beiscsi_setup_boot_info(phba))
5383 /*
5384 * log error but continue, because we may not be using
5385 * iscsi boot.
5386 */
John Soni Jose99bc5d52012-08-20 23:00:18 +05305387 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5388 "BM_%d : Could not set up "
5389 "iSCSI boot info.\n");
Mike Christief457a462011-06-24 15:11:53 -05005390
Mike Christie0e438952012-04-03 23:41:51 -05005391 beiscsi_create_def_ifaces(phba);
John Soni Jose7a158002012-10-20 04:45:51 +05305392 schedule_delayed_work(&phba->beiscsi_hw_check_task,
5393 msecs_to_jiffies(1000));
5394
John Soni Jose99bc5d52012-08-20 23:00:18 +05305395 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
5396 "\n\n\n BM_%d : SUCCESS - DRIVER LOADED\n\n\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305397 return 0;
5398
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305399free_blkenbld:
5400 destroy_workqueue(phba->wq);
5401 if (blk_iopoll_enabled)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305402 for (i = 0; i < phba->num_cpus; i++) {
5403 pbe_eq = &phwi_context->be_eq[i];
5404 blk_iopoll_disable(&pbe_eq->iopoll);
5405 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305406free_twq:
5407 beiscsi_clean_port(phba);
5408 beiscsi_free_mem(phba);
5409free_port:
5410 pci_free_consistent(phba->pcidev,
5411 phba->ctrl.mbox_mem_alloced.size,
5412 phba->ctrl.mbox_mem_alloced.va,
5413 phba->ctrl.mbox_mem_alloced.dma);
5414 beiscsi_unmap_pci_function(phba);
5415hba_free:
Jayamohan Kallickal238f6b72010-07-22 04:23:22 +05305416 if (phba->msix_enabled)
5417 pci_disable_msix(phba->pcidev);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305418 iscsi_host_remove(phba->shost);
5419 pci_dev_put(phba->pcidev);
5420 iscsi_host_free(phba->shost);
5421disable_pci:
5422 pci_disable_device(pcidev);
5423 return ret;
5424}
5425
5426struct iscsi_transport beiscsi_iscsi_transport = {
5427 .owner = THIS_MODULE,
5428 .name = DRV_NAME,
Jayamohan Kallickal9db0fb32010-01-05 05:12:43 +05305429 .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_TEXT_NEGO |
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305430 CAP_MULTI_R2T | CAP_DATADGST | CAP_DATA_PATH_OFFLOAD,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305431 .create_session = beiscsi_session_create,
5432 .destroy_session = beiscsi_session_destroy,
5433 .create_conn = beiscsi_conn_create,
5434 .bind_conn = beiscsi_conn_bind,
5435 .destroy_conn = iscsi_conn_teardown,
Mike Christie3128c6c2011-07-25 13:48:42 -05005436 .attr_is_visible = be2iscsi_attr_is_visible,
Mike Christie0e438952012-04-03 23:41:51 -05005437 .set_iface_param = be2iscsi_iface_set_param,
5438 .get_iface_param = be2iscsi_iface_get_param,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305439 .set_param = beiscsi_set_param,
Mike Christiec7f7fd52011-02-16 15:04:41 -06005440 .get_conn_param = iscsi_conn_get_param,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305441 .get_session_param = iscsi_session_get_param,
5442 .get_host_param = beiscsi_get_host_param,
5443 .start_conn = beiscsi_conn_start,
Mike Christiefa95d202010-06-09 03:30:08 -05005444 .stop_conn = iscsi_conn_stop,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305445 .send_pdu = iscsi_conn_send_pdu,
5446 .xmit_task = beiscsi_task_xmit,
5447 .cleanup_task = beiscsi_cleanup_task,
5448 .alloc_pdu = beiscsi_alloc_pdu,
5449 .parse_pdu_itt = beiscsi_parse_pdu,
5450 .get_stats = beiscsi_conn_get_stats,
Mike Christiec7f7fd52011-02-16 15:04:41 -06005451 .get_ep_param = beiscsi_ep_get_param,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305452 .ep_connect = beiscsi_ep_connect,
5453 .ep_poll = beiscsi_ep_poll,
5454 .ep_disconnect = beiscsi_ep_disconnect,
5455 .session_recovery_timedout = iscsi_session_recovery_timedout,
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -05005456 .bsg_request = beiscsi_bsg_request,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305457};
5458
5459static struct pci_driver beiscsi_pci_driver = {
5460 .name = DRV_NAME,
5461 .probe = beiscsi_dev_probe,
5462 .remove = beiscsi_remove,
Jayamohan Kallickal25602c92011-08-22 10:08:28 -07005463 .shutdown = beiscsi_shutdown,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305464 .id_table = beiscsi_pci_id_table
5465};
5466
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05305467
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305468static int __init beiscsi_module_init(void)
5469{
5470 int ret;
5471
5472 beiscsi_scsi_transport =
5473 iscsi_register_transport(&beiscsi_iscsi_transport);
5474 if (!beiscsi_scsi_transport) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305475 printk(KERN_ERR
5476 "beiscsi_module_init - Unable to register beiscsi transport.\n");
Jayamohan Kallickalf55a24f2010-01-23 05:37:40 +05305477 return -ENOMEM;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305478 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05305479 printk(KERN_INFO "In beiscsi_module_init, tt=%p\n",
5480 &beiscsi_iscsi_transport);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305481
5482 ret = pci_register_driver(&beiscsi_pci_driver);
5483 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05305484 printk(KERN_ERR
5485 "beiscsi_module_init - Unable to register beiscsi pci driver.\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305486 goto unregister_iscsi_transport;
5487 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05305488 return 0;
5489
5490unregister_iscsi_transport:
5491 iscsi_unregister_transport(&beiscsi_iscsi_transport);
5492 return ret;
5493}
5494
5495static void __exit beiscsi_module_exit(void)
5496{
5497 pci_unregister_driver(&beiscsi_pci_driver);
5498 iscsi_unregister_transport(&beiscsi_iscsi_transport);
5499}
5500
5501module_init(beiscsi_module_init);
5502module_exit(beiscsi_module_exit);