blob: 1af777474e420cf3c70a83507c2a1dd257fb98dd [file] [log] [blame]
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301/**
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -07002 * Copyright (C) 2005 - 2011 Emulex
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation. The full GNU General
8 * Public License is included in this distribution in the file called COPYING.
9 *
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070010 * Written by: Jayamohan Kallickal (jayamohan.kallickal@emulex.com)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053011 *
12 * Contact Information:
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070013 * linux-drivers@emulex.com
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053014 *
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070015 * Emulex
16 * 3333 Susan Street
17 * Costa Mesa, CA 92626
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053018 */
19
20#include <scsi/libiscsi.h>
21#include <scsi/scsi_transport_iscsi.h>
22#include <scsi/scsi_transport.h>
23#include <scsi/scsi_cmnd.h>
24#include <scsi/scsi_device.h>
25#include <scsi/scsi_host.h>
26#include <scsi/scsi.h>
27
28#include "be_iscsi.h"
29
30extern struct iscsi_transport beiscsi_iscsi_transport;
31
32/**
33 * beiscsi_session_create - creates a new iscsi session
34 * @cmds_max: max commands supported
35 * @qdepth: max queue depth supported
36 * @initial_cmdsn: initial iscsi CMDSN
37 */
38struct iscsi_cls_session *beiscsi_session_create(struct iscsi_endpoint *ep,
39 u16 cmds_max,
40 u16 qdepth,
41 u32 initial_cmdsn)
42{
43 struct Scsi_Host *shost;
44 struct beiscsi_endpoint *beiscsi_ep;
45 struct iscsi_cls_session *cls_session;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053046 struct beiscsi_hba *phba;
Jayamohan Kallickalb8b9e1b82009-09-22 08:21:22 +053047 struct iscsi_session *sess;
48 struct beiscsi_session *beiscsi_sess;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053049 struct beiscsi_io_task *io_task;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053050
51 SE_DEBUG(DBG_LVL_8, "In beiscsi_session_create\n");
52
53 if (!ep) {
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +053054 SE_DEBUG(DBG_LVL_1, "beiscsi_session_create: invalid ep\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053055 return NULL;
56 }
57 beiscsi_ep = ep->dd_data;
58 phba = beiscsi_ep->phba;
59 shost = phba->shost;
60 if (cmds_max > beiscsi_ep->phba->params.wrbs_per_cxn) {
61 shost_printk(KERN_ERR, shost, "Cannot handle %d cmds."
62 "Max cmds per session supported is %d. Using %d. "
63 "\n", cmds_max,
64 beiscsi_ep->phba->params.wrbs_per_cxn,
65 beiscsi_ep->phba->params.wrbs_per_cxn);
66 cmds_max = beiscsi_ep->phba->params.wrbs_per_cxn;
67 }
68
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +053069 cls_session = iscsi_session_setup(&beiscsi_iscsi_transport,
70 shost, cmds_max,
71 sizeof(*beiscsi_sess),
72 sizeof(*io_task),
73 initial_cmdsn, ISCSI_MAX_TARGET);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053074 if (!cls_session)
75 return NULL;
76 sess = cls_session->dd_data;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +053077 beiscsi_sess = sess->dd_data;
78 beiscsi_sess->bhs_pool = pci_pool_create("beiscsi_bhs_pool",
79 phba->pcidev,
80 sizeof(struct be_cmd_bhs),
81 64, 0);
82 if (!beiscsi_sess->bhs_pool)
83 goto destroy_sess;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053084
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053085 return cls_session;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +053086destroy_sess:
87 iscsi_session_teardown(cls_session);
88 return NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053089}
90
91/**
92 * beiscsi_session_destroy - destroys iscsi session
93 * @cls_session: pointer to iscsi cls session
94 *
95 * Destroys iSCSI session instance and releases
96 * resources allocated for it.
97 */
98void beiscsi_session_destroy(struct iscsi_cls_session *cls_session)
99{
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530100 struct iscsi_session *sess = cls_session->dd_data;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +0530101 struct beiscsi_session *beiscsi_sess = sess->dd_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530102
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530103 SE_DEBUG(DBG_LVL_8, "In beiscsi_session_destroy\n");
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +0530104 pci_pool_destroy(beiscsi_sess->bhs_pool);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530105 iscsi_session_teardown(cls_session);
106}
107
108/**
109 * beiscsi_conn_create - create an instance of iscsi connection
110 * @cls_session: ptr to iscsi_cls_session
111 * @cid: iscsi cid
112 */
113struct iscsi_cls_conn *
114beiscsi_conn_create(struct iscsi_cls_session *cls_session, u32 cid)
115{
116 struct beiscsi_hba *phba;
117 struct Scsi_Host *shost;
118 struct iscsi_cls_conn *cls_conn;
119 struct beiscsi_conn *beiscsi_conn;
120 struct iscsi_conn *conn;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +0530121 struct iscsi_session *sess;
122 struct beiscsi_session *beiscsi_sess;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530123
124 SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_create ,cid"
125 "from iscsi layer=%d\n", cid);
126 shost = iscsi_session_to_shost(cls_session);
127 phba = iscsi_host_priv(shost);
128
129 cls_conn = iscsi_conn_setup(cls_session, sizeof(*beiscsi_conn), cid);
130 if (!cls_conn)
131 return NULL;
132
133 conn = cls_conn->dd_data;
134 beiscsi_conn = conn->dd_data;
135 beiscsi_conn->ep = NULL;
136 beiscsi_conn->phba = phba;
137 beiscsi_conn->conn = conn;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +0530138 sess = cls_session->dd_data;
139 beiscsi_sess = sess->dd_data;
140 beiscsi_conn->beiscsi_sess = beiscsi_sess;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530141 return cls_conn;
142}
143
144/**
145 * beiscsi_bindconn_cid - Bind the beiscsi_conn with phba connection table
146 * @beiscsi_conn: The pointer to beiscsi_conn structure
147 * @phba: The phba instance
148 * @cid: The cid to free
149 */
150static int beiscsi_bindconn_cid(struct beiscsi_hba *phba,
151 struct beiscsi_conn *beiscsi_conn,
152 unsigned int cid)
153{
154 if (phba->conn_table[cid]) {
155 SE_DEBUG(DBG_LVL_1,
156 "Connection table already occupied. Detected clash\n");
157 return -EINVAL;
158 } else {
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530159 SE_DEBUG(DBG_LVL_8, "phba->conn_table[%d]=%p(beiscsi_conn)\n",
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530160 cid, beiscsi_conn);
161 phba->conn_table[cid] = beiscsi_conn;
162 }
163 return 0;
164}
165
166/**
167 * beiscsi_conn_bind - Binds iscsi session/connection with TCP connection
168 * @cls_session: pointer to iscsi cls session
169 * @cls_conn: pointer to iscsi cls conn
170 * @transport_fd: EP handle(64 bit)
171 *
172 * This function binds the TCP Conn with iSCSI Connection and Session.
173 */
174int beiscsi_conn_bind(struct iscsi_cls_session *cls_session,
175 struct iscsi_cls_conn *cls_conn,
176 u64 transport_fd, int is_leading)
177{
178 struct iscsi_conn *conn = cls_conn->dd_data;
179 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
Mike Christie3093b042011-07-25 13:48:46 -0500180 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
181 struct beiscsi_hba *phba = iscsi_host_priv(shost);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530182 struct beiscsi_endpoint *beiscsi_ep;
183 struct iscsi_endpoint *ep;
184
185 SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_bind\n");
186 ep = iscsi_lookup_endpoint(transport_fd);
187 if (!ep)
188 return -EINVAL;
189
190 beiscsi_ep = ep->dd_data;
191
192 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
193 return -EINVAL;
194
195 if (beiscsi_ep->phba != phba) {
196 SE_DEBUG(DBG_LVL_8,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530197 "beiscsi_ep->hba=%p not equal to phba=%p\n",
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530198 beiscsi_ep->phba, phba);
199 return -EEXIST;
200 }
201
202 beiscsi_conn->beiscsi_conn_cid = beiscsi_ep->ep_cid;
203 beiscsi_conn->ep = beiscsi_ep;
204 beiscsi_ep->conn = beiscsi_conn;
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530205 SE_DEBUG(DBG_LVL_8, "beiscsi_conn=%p conn=%p ep_cid=%d\n",
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530206 beiscsi_conn, conn, beiscsi_ep->ep_cid);
207 return beiscsi_bindconn_cid(phba, beiscsi_conn, beiscsi_ep->ep_cid);
208}
209
210/**
Mike Christiec7f7fd52011-02-16 15:04:41 -0600211 * beiscsi_ep_get_param - get the iscsi parameter
212 * @ep: pointer to iscsi ep
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530213 * @param: parameter type identifier
214 * @buf: buffer pointer
215 *
216 * returns iscsi parameter
217 */
Mike Christiec7f7fd52011-02-16 15:04:41 -0600218int beiscsi_ep_get_param(struct iscsi_endpoint *ep,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530219 enum iscsi_param param, char *buf)
220{
Mike Christiec7f7fd52011-02-16 15:04:41 -0600221 struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530222 int len = 0;
223
Jayamohan Kallickalb5b93232012-04-03 23:41:40 -0500224 SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_get_param, param= %d\n", param);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530225
226 switch (param) {
227 case ISCSI_PARAM_CONN_PORT:
228 len = sprintf(buf, "%hu\n", beiscsi_ep->dst_tcpport);
229 break;
230 case ISCSI_PARAM_CONN_ADDRESS:
231 if (beiscsi_ep->ip_type == BE2_IPV4)
232 len = sprintf(buf, "%pI4\n", &beiscsi_ep->dst_addr);
233 else
234 len = sprintf(buf, "%pI6\n", &beiscsi_ep->dst6_addr);
235 break;
236 default:
Mike Christiec7f7fd52011-02-16 15:04:41 -0600237 return -ENOSYS;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530238 }
239 return len;
240}
241
242int beiscsi_set_param(struct iscsi_cls_conn *cls_conn,
243 enum iscsi_param param, char *buf, int buflen)
244{
245 struct iscsi_conn *conn = cls_conn->dd_data;
246 struct iscsi_session *session = conn->session;
247 int ret;
248
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530249 SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_set_param, param= %d\n", param);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530250 ret = iscsi_set_param(cls_conn, param, buf, buflen);
251 if (ret)
252 return ret;
253 /*
254 * If userspace tried to set the value to higher than we can
255 * support override here.
256 */
257 switch (param) {
258 case ISCSI_PARAM_FIRST_BURST:
259 if (session->first_burst > 8192)
260 session->first_burst = 8192;
261 break;
262 case ISCSI_PARAM_MAX_RECV_DLENGTH:
263 if (conn->max_recv_dlength > 65536)
264 conn->max_recv_dlength = 65536;
265 break;
266 case ISCSI_PARAM_MAX_BURST:
Jayamohan Kallickal230dceb2010-01-23 05:36:10 +0530267 if (session->max_burst > 262144)
268 session->max_burst = 262144;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530269 break;
Jayamohan Kallickal42f43c42010-07-22 04:26:45 +0530270 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
271 if ((conn->max_xmit_dlength > 65536) ||
272 (conn->max_xmit_dlength == 0))
273 conn->max_xmit_dlength = 65536;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530274 default:
275 return 0;
276 }
277
278 return 0;
279}
280
281/**
John Soni Jose21771992012-04-03 23:41:49 -0500282 * beiscsi_get_initname - Read Initiator Name from flash
283 * @buf: buffer bointer
284 * @phba: The device priv structure instance
285 *
286 * returns number of bytes
287 */
288static int beiscsi_get_initname(char *buf, struct beiscsi_hba *phba)
289{
290 int rc;
291 unsigned int tag, wrb_num;
292 unsigned short status, extd_status;
293 struct be_mcc_wrb *wrb;
294 struct be_cmd_hba_name *resp;
295 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
296
297 tag = be_cmd_get_initname(phba);
298 if (!tag) {
299 SE_DEBUG(DBG_LVL_1, "Getting Initiator Name Failed\n");
300 return -EBUSY;
301 } else
302 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
303 phba->ctrl.mcc_numtag[tag]);
304
305 wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
306 extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
307 status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
308
309 if (status || extd_status) {
310 SE_DEBUG(DBG_LVL_1, "MailBox Command Failed with "
311 "status = %d extd_status = %d\n",
312 status, extd_status);
313 free_mcc_tag(&phba->ctrl, tag);
314 return -EAGAIN;
315 }
316 wrb = queue_get_wrb(mccq, wrb_num);
317 free_mcc_tag(&phba->ctrl, tag);
318 resp = embedded_payload(wrb);
319 rc = sprintf(buf, "%s\n", resp->initiator_name);
320 return rc;
321}
322
323/**
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530324 * beiscsi_get_host_param - get the iscsi parameter
325 * @shost: pointer to scsi_host structure
326 * @param: parameter type identifier
327 * @buf: buffer pointer
328 *
329 * returns host parameter
330 */
331int beiscsi_get_host_param(struct Scsi_Host *shost,
332 enum iscsi_host_param param, char *buf)
333{
Mike Christie3093b042011-07-25 13:48:46 -0500334 struct beiscsi_hba *phba = iscsi_host_priv(shost);
Jayamohan Kallickalb15d05b2010-08-12 23:36:06 +0530335 int status = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530336
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530337 SE_DEBUG(DBG_LVL_8, "In beiscsi_get_host_param, param= %d\n", param);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530338 switch (param) {
339 case ISCSI_HOST_PARAM_HWADDRESS:
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530340 status = beiscsi_get_macaddr(buf, phba);
341 if (status < 0) {
342 SE_DEBUG(DBG_LVL_1, "beiscsi_get_macaddr Failed\n");
343 return status;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530344 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530345 break;
John Soni Jose21771992012-04-03 23:41:49 -0500346 case ISCSI_HOST_PARAM_INITIATOR_NAME:
347 status = beiscsi_get_initname(buf, phba);
348 if (status < 0) {
349 SE_DEBUG(DBG_LVL_1,
350 "Retreiving Initiator Name Failed\n");
351 return status;
352 }
353 break;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530354 default:
355 return iscsi_host_get_param(shost, param, buf);
356 }
Jayamohan Kallickalb15d05b2010-08-12 23:36:06 +0530357 return status;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530358}
359
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530360int beiscsi_get_macaddr(char *buf, struct beiscsi_hba *phba)
361{
362 struct be_cmd_resp_get_mac_addr *resp;
363 struct be_mcc_wrb *wrb;
364 unsigned int tag, wrb_num;
365 unsigned short status, extd_status;
366 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
367 int rc;
368
369 if (phba->read_mac_address)
370 return sysfs_format_mac(buf, phba->mac_address,
371 ETH_ALEN);
372
373 tag = be_cmd_get_mac_addr(phba);
374 if (!tag) {
375 SE_DEBUG(DBG_LVL_1, "be_cmd_get_mac_addr Failed\n");
376 return -EBUSY;
377 } else
378 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
379 phba->ctrl.mcc_numtag[tag]);
380
381 wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
382 extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
383 status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
384 if (status || extd_status) {
385 SE_DEBUG(DBG_LVL_1, "Failed to get be_cmd_get_mac_addr"
386 " status = %d extd_status = %d\n",
387 status, extd_status);
388 free_mcc_tag(&phba->ctrl, tag);
389 return -EAGAIN;
390 }
391 wrb = queue_get_wrb(mccq, wrb_num);
392 free_mcc_tag(&phba->ctrl, tag);
393 resp = embedded_payload(wrb);
394 memcpy(phba->mac_address, resp->mac_address, ETH_ALEN);
395 rc = sysfs_format_mac(buf, phba->mac_address,
396 ETH_ALEN);
397 phba->read_mac_address = 1;
398 return rc;
399}
400
401
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530402/**
403 * beiscsi_conn_get_stats - get the iscsi stats
404 * @cls_conn: pointer to iscsi cls conn
405 * @stats: pointer to iscsi_stats structure
406 *
407 * returns iscsi stats
408 */
409void beiscsi_conn_get_stats(struct iscsi_cls_conn *cls_conn,
410 struct iscsi_stats *stats)
411{
412 struct iscsi_conn *conn = cls_conn->dd_data;
413
414 SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_get_stats\n");
415 stats->txdata_octets = conn->txdata_octets;
416 stats->rxdata_octets = conn->rxdata_octets;
417 stats->dataout_pdus = conn->dataout_pdus_cnt;
418 stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
419 stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
420 stats->datain_pdus = conn->datain_pdus_cnt;
421 stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
422 stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
423 stats->r2t_pdus = conn->r2t_pdus_cnt;
424 stats->digest_err = 0;
425 stats->timeout_err = 0;
426 stats->custom_length = 0;
427 strcpy(stats->custom[0].desc, "eh_abort_cnt");
428 stats->custom[0].value = conn->eh_abort_cnt;
429}
430
431/**
432 * beiscsi_set_params_for_offld - get the parameters for offload
433 * @beiscsi_conn: pointer to beiscsi_conn
434 * @params: pointer to offload_params structure
435 */
436static void beiscsi_set_params_for_offld(struct beiscsi_conn *beiscsi_conn,
437 struct beiscsi_offload_params *params)
438{
439 struct iscsi_conn *conn = beiscsi_conn->conn;
440 struct iscsi_session *session = conn->session;
441
442 AMAP_SET_BITS(struct amap_beiscsi_offload_params, max_burst_length,
443 params, session->max_burst);
444 AMAP_SET_BITS(struct amap_beiscsi_offload_params,
445 max_send_data_segment_length, params,
446 conn->max_xmit_dlength);
447 AMAP_SET_BITS(struct amap_beiscsi_offload_params, first_burst_length,
448 params, session->first_burst);
449 AMAP_SET_BITS(struct amap_beiscsi_offload_params, erl, params,
450 session->erl);
451 AMAP_SET_BITS(struct amap_beiscsi_offload_params, dde, params,
452 conn->datadgst_en);
453 AMAP_SET_BITS(struct amap_beiscsi_offload_params, hde, params,
454 conn->hdrdgst_en);
455 AMAP_SET_BITS(struct amap_beiscsi_offload_params, ir2t, params,
456 session->initial_r2t_en);
457 AMAP_SET_BITS(struct amap_beiscsi_offload_params, imd, params,
458 session->imm_data_en);
459 AMAP_SET_BITS(struct amap_beiscsi_offload_params, exp_statsn, params,
460 (conn->exp_statsn - 1));
461}
462
463/**
464 * beiscsi_conn_start - offload of session to chip
465 * @cls_conn: pointer to beiscsi_conn
466 */
467int beiscsi_conn_start(struct iscsi_cls_conn *cls_conn)
468{
469 struct iscsi_conn *conn = cls_conn->dd_data;
470 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
471 struct beiscsi_endpoint *beiscsi_ep;
472 struct beiscsi_offload_params params;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530473
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530474 SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_start\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530475 memset(&params, 0, sizeof(struct beiscsi_offload_params));
476 beiscsi_ep = beiscsi_conn->ep;
477 if (!beiscsi_ep)
478 SE_DEBUG(DBG_LVL_1, "In beiscsi_conn_start , no beiscsi_ep\n");
479
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530480 beiscsi_conn->login_in_progress = 0;
481 beiscsi_set_params_for_offld(beiscsi_conn, &params);
482 beiscsi_offload_connection(beiscsi_conn, &params);
483 iscsi_conn_start(cls_conn);
484 return 0;
485}
486
487/**
488 * beiscsi_get_cid - Allocate a cid
489 * @phba: The phba instance
490 */
491static int beiscsi_get_cid(struct beiscsi_hba *phba)
492{
493 unsigned short cid = 0xFFFF;
494
495 if (!phba->avlbl_cids)
496 return cid;
497
498 cid = phba->cid_array[phba->cid_alloc++];
499 if (phba->cid_alloc == phba->params.cxns_per_ctrl)
500 phba->cid_alloc = 0;
501 phba->avlbl_cids--;
502 return cid;
503}
504
505/**
Mike Christiefa95d202010-06-09 03:30:08 -0500506 * beiscsi_put_cid - Free the cid
507 * @phba: The phba for which the cid is being freed
508 * @cid: The cid to free
509 */
510static void beiscsi_put_cid(struct beiscsi_hba *phba, unsigned short cid)
511{
512 phba->avlbl_cids++;
513 phba->cid_array[phba->cid_free++] = cid;
514 if (phba->cid_free == phba->params.cxns_per_ctrl)
515 phba->cid_free = 0;
516}
517
518/**
519 * beiscsi_free_ep - free endpoint
520 * @ep: pointer to iscsi endpoint structure
521 */
522static void beiscsi_free_ep(struct beiscsi_endpoint *beiscsi_ep)
523{
524 struct beiscsi_hba *phba = beiscsi_ep->phba;
525
526 beiscsi_put_cid(phba, beiscsi_ep->ep_cid);
527 beiscsi_ep->phba = NULL;
528}
529
530/**
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530531 * beiscsi_open_conn - Ask FW to open a TCP connection
532 * @ep: endpoint to be used
533 * @src_addr: The source IP address
534 * @dst_addr: The Destination IP address
535 *
536 * Asks the FW to open a TCP connection
537 */
538static int beiscsi_open_conn(struct iscsi_endpoint *ep,
539 struct sockaddr *src_addr,
540 struct sockaddr *dst_addr, int non_blocking)
541{
542 struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
543 struct beiscsi_hba *phba = beiscsi_ep->phba;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530544 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
545 struct be_mcc_wrb *wrb;
546 struct tcp_connect_and_offload_out *ptcpcnct_out;
547 unsigned short status, extd_status;
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530548 struct be_dma_mem nonemb_cmd;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530549 unsigned int tag, wrb_num;
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +0530550 int ret = -ENOMEM;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530551
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530552 SE_DEBUG(DBG_LVL_8, "In beiscsi_open_conn\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530553 beiscsi_ep->ep_cid = beiscsi_get_cid(phba);
554 if (beiscsi_ep->ep_cid == 0xFFFF) {
555 SE_DEBUG(DBG_LVL_1, "No free cid available\n");
556 return ret;
557 }
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530558 SE_DEBUG(DBG_LVL_8, "In beiscsi_open_conn, ep_cid=%d\n",
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530559 beiscsi_ep->ep_cid);
Jayamohan Kallickal7da50872010-01-05 05:04:12 +0530560 phba->ep_array[beiscsi_ep->ep_cid -
561 phba->fw_config.iscsi_cid_start] = ep;
562 if (beiscsi_ep->ep_cid > (phba->fw_config.iscsi_cid_start +
563 phba->params.cxns_per_ctrl * 2)) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530564 SE_DEBUG(DBG_LVL_1, "Failed in allocate iscsi cid\n");
Mike Christiefa95d202010-06-09 03:30:08 -0500565 goto free_ep;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530566 }
567
568 beiscsi_ep->cid_vld = 0;
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530569 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
570 sizeof(struct tcp_connect_and_offload_in),
571 &nonemb_cmd.dma);
572 if (nonemb_cmd.va == NULL) {
573 SE_DEBUG(DBG_LVL_1,
574 "Failed to allocate memory for mgmt_open_connection"
575 "\n");
576 beiscsi_put_cid(phba, beiscsi_ep->ep_cid);
577 return -ENOMEM;
578 }
579 nonemb_cmd.size = sizeof(struct tcp_connect_and_offload_in);
580 memset(nonemb_cmd.va, 0, nonemb_cmd.size);
581 tag = mgmt_open_connection(phba, dst_addr, beiscsi_ep, &nonemb_cmd);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530582 if (!tag) {
583 SE_DEBUG(DBG_LVL_1,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530584 "mgmt_open_connection Failed for cid=%d\n",
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530585 beiscsi_ep->ep_cid);
Jayamohan Kallickal1f926382010-07-22 04:22:27 +0530586 beiscsi_put_cid(phba, beiscsi_ep->ep_cid);
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530587 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
588 nonemb_cmd.va, nonemb_cmd.dma);
Jayamohan Kallickal1f926382010-07-22 04:22:27 +0530589 return -EAGAIN;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530590 } else {
591 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
592 phba->ctrl.mcc_numtag[tag]);
593 }
594 wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
595 extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
596 status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
597 if (status || extd_status) {
598 SE_DEBUG(DBG_LVL_1, "mgmt_open_connection Failed"
Mike Christiefa95d202010-06-09 03:30:08 -0500599 " status = %d extd_status = %d\n",
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530600 status, extd_status);
601 free_mcc_tag(&phba->ctrl, tag);
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530602 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
603 nonemb_cmd.va, nonemb_cmd.dma);
Mike Christiefa95d202010-06-09 03:30:08 -0500604 goto free_ep;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530605 } else {
606 wrb = queue_get_wrb(mccq, wrb_num);
607 free_mcc_tag(&phba->ctrl, tag);
608
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530609 ptcpcnct_out = embedded_payload(wrb);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530610 beiscsi_ep = ep->dd_data;
611 beiscsi_ep->fw_handle = ptcpcnct_out->connection_handle;
612 beiscsi_ep->cid_vld = 1;
613 SE_DEBUG(DBG_LVL_8, "mgmt_open_connection Success\n");
614 }
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530615 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
616 nonemb_cmd.va, nonemb_cmd.dma);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530617 return 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530618
Mike Christiefa95d202010-06-09 03:30:08 -0500619free_ep:
620 beiscsi_free_ep(beiscsi_ep);
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +0530621 return -EBUSY;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530622}
623
624/**
625 * beiscsi_ep_connect - Ask chip to create TCP Conn
626 * @scsi_host: Pointer to scsi_host structure
627 * @dst_addr: The IP address of Target
628 * @non_blocking: blocking or non-blocking call
629 *
630 * This routines first asks chip to create a connection and then allocates an EP
631 */
632struct iscsi_endpoint *
633beiscsi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
634 int non_blocking)
635{
636 struct beiscsi_hba *phba;
637 struct beiscsi_endpoint *beiscsi_ep;
638 struct iscsi_endpoint *ep;
639 int ret;
640
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530641 SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_connect\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530642 if (shost)
643 phba = iscsi_host_priv(shost);
644 else {
645 ret = -ENXIO;
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530646 SE_DEBUG(DBG_LVL_1, "shost is NULL\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530647 return ERR_PTR(ret);
648 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530649
Jayamohan Kallickal5dc1c412010-01-23 05:36:52 +0530650 if (phba->state != BE_ADAPTER_UP) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530651 ret = -EBUSY;
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530652 SE_DEBUG(DBG_LVL_1, "The Adapter state is Not UP\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530653 return ERR_PTR(ret);
654 }
655
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530656 ep = iscsi_create_endpoint(sizeof(struct beiscsi_endpoint));
657 if (!ep) {
658 ret = -ENOMEM;
659 return ERR_PTR(ret);
660 }
661
662 beiscsi_ep = ep->dd_data;
663 beiscsi_ep->phba = phba;
Jayamohan Kallickalc2462282010-01-05 05:05:34 +0530664 beiscsi_ep->openiscsi_ep = ep;
Jayamohan Kallickalf5ed7bd2010-07-22 04:18:01 +0530665 ret = beiscsi_open_conn(ep, NULL, dst_addr, non_blocking);
666 if (ret) {
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530667 SE_DEBUG(DBG_LVL_1, "Failed in beiscsi_open_conn\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530668 goto free_ep;
669 }
670
671 return ep;
672
673free_ep:
Mike Christiefa95d202010-06-09 03:30:08 -0500674 iscsi_destroy_endpoint(ep);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530675 return ERR_PTR(ret);
676}
677
678/**
679 * beiscsi_ep_poll - Poll to see if connection is established
680 * @ep: endpoint to be used
681 * @timeout_ms: timeout specified in millisecs
682 *
683 * Poll to see if TCP connection established
684 */
685int beiscsi_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
686{
687 struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
688
689 SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_poll\n");
690 if (beiscsi_ep->cid_vld == 1)
691 return 1;
692 else
693 return 0;
694}
695
696/**
697 * beiscsi_close_conn - Upload the connection
698 * @ep: The iscsi endpoint
699 * @flag: The type of connection closure
700 */
Jayamohan Kallickalc2462282010-01-05 05:05:34 +0530701static int beiscsi_close_conn(struct beiscsi_endpoint *beiscsi_ep, int flag)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530702{
703 int ret = 0;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530704 unsigned int tag;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530705 struct beiscsi_hba *phba = beiscsi_ep->phba;
706
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530707 tag = mgmt_upload_connection(phba, beiscsi_ep->ep_cid, flag);
708 if (!tag) {
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530709 SE_DEBUG(DBG_LVL_8, "upload failed for cid 0x%x\n",
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530710 beiscsi_ep->ep_cid);
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +0530711 ret = -EAGAIN;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530712 } else {
713 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
714 phba->ctrl.mcc_numtag[tag]);
715 free_mcc_tag(&phba->ctrl, tag);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530716 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530717 return ret;
718}
719
720/**
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530721 * beiscsi_unbind_conn_to_cid - Unbind the beiscsi_conn from phba conn table
722 * @phba: The phba instance
723 * @cid: The cid to free
724 */
725static int beiscsi_unbind_conn_to_cid(struct beiscsi_hba *phba,
726 unsigned int cid)
727{
728 if (phba->conn_table[cid])
729 phba->conn_table[cid] = NULL;
730 else {
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530731 SE_DEBUG(DBG_LVL_8, "Connection table Not occupied.\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530732 return -EINVAL;
733 }
734 return 0;
735}
736
737/**
Mike Christiefa95d202010-06-09 03:30:08 -0500738 * beiscsi_ep_disconnect - Tears down the TCP connection
739 * @ep: endpoint to be used
740 *
741 * Tears down the TCP connection
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530742 */
Mike Christiefa95d202010-06-09 03:30:08 -0500743void beiscsi_ep_disconnect(struct iscsi_endpoint *ep)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530744{
Mike Christiefa95d202010-06-09 03:30:08 -0500745 struct beiscsi_conn *beiscsi_conn;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530746 struct beiscsi_endpoint *beiscsi_ep;
Mike Christiefa95d202010-06-09 03:30:08 -0500747 struct beiscsi_hba *phba;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530748 unsigned int tag;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530749 unsigned short savecfg_flag = CMD_ISCSI_SESSION_SAVE_CFG_ON_FLASH;
750
Mike Christiefa95d202010-06-09 03:30:08 -0500751 beiscsi_ep = ep->dd_data;
752 phba = beiscsi_ep->phba;
753 SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_disconnect for ep_cid = %d\n",
754 beiscsi_ep->ep_cid);
755
756 if (!beiscsi_ep->conn) {
757 SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_disconnect, no "
758 "beiscsi_ep\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530759 return;
760 }
Mike Christiefa95d202010-06-09 03:30:08 -0500761 beiscsi_conn = beiscsi_ep->conn;
762 iscsi_suspend_queue(beiscsi_conn->conn);
763
764 SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_disconnect ep_cid = %d\n",
765 beiscsi_ep->ep_cid);
766
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530767 tag = mgmt_invalidate_connection(phba, beiscsi_ep,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530768 beiscsi_ep->ep_cid, 1,
769 savecfg_flag);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530770 if (!tag) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530771 SE_DEBUG(DBG_LVL_1,
Jayamohan Kallickal457ff3b2010-07-22 04:16:00 +0530772 "mgmt_invalidate_connection Failed for cid=%d\n",
Jayamohan Kallickal90a289e2010-02-20 08:04:28 +0530773 beiscsi_ep->ep_cid);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530774 } else {
775 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
776 phba->ctrl.mcc_numtag[tag]);
777 free_mcc_tag(&phba->ctrl, tag);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530778 }
Mike Christiefa95d202010-06-09 03:30:08 -0500779
Jayamohan Kallickalc2462282010-01-05 05:05:34 +0530780 beiscsi_close_conn(beiscsi_ep, CONNECTION_UPLOAD_GRACEFUL);
781 beiscsi_free_ep(beiscsi_ep);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530782 beiscsi_unbind_conn_to_cid(phba, beiscsi_ep->ep_cid);
Mike Christiefa95d202010-06-09 03:30:08 -0500783 iscsi_destroy_endpoint(beiscsi_ep->openiscsi_ep);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530784}
Mike Christie3128c6c2011-07-25 13:48:42 -0500785
Al Viro587a1f12011-07-23 23:11:19 -0400786umode_t be2iscsi_attr_is_visible(int param_type, int param)
Mike Christie3128c6c2011-07-25 13:48:42 -0500787{
788 switch (param_type) {
Mike Christief27fb2e2011-07-25 13:48:45 -0500789 case ISCSI_HOST_PARAM:
790 switch (param) {
791 case ISCSI_HOST_PARAM_HWADDRESS:
792 case ISCSI_HOST_PARAM_IPADDRESS:
793 case ISCSI_HOST_PARAM_INITIATOR_NAME:
794 return S_IRUGO;
795 default:
796 return 0;
797 }
Mike Christie3128c6c2011-07-25 13:48:42 -0500798 case ISCSI_PARAM:
799 switch (param) {
800 case ISCSI_PARAM_MAX_RECV_DLENGTH:
801 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
802 case ISCSI_PARAM_HDRDGST_EN:
803 case ISCSI_PARAM_DATADGST_EN:
804 case ISCSI_PARAM_CONN_ADDRESS:
805 case ISCSI_PARAM_CONN_PORT:
806 case ISCSI_PARAM_EXP_STATSN:
807 case ISCSI_PARAM_PERSISTENT_ADDRESS:
808 case ISCSI_PARAM_PERSISTENT_PORT:
809 case ISCSI_PARAM_PING_TMO:
810 case ISCSI_PARAM_RECV_TMO:
Mike Christie1d063c12011-07-25 13:48:43 -0500811 case ISCSI_PARAM_INITIAL_R2T_EN:
812 case ISCSI_PARAM_MAX_R2T:
813 case ISCSI_PARAM_IMM_DATA_EN:
814 case ISCSI_PARAM_FIRST_BURST:
815 case ISCSI_PARAM_MAX_BURST:
816 case ISCSI_PARAM_PDU_INORDER_EN:
817 case ISCSI_PARAM_DATASEQ_INORDER_EN:
818 case ISCSI_PARAM_ERL:
819 case ISCSI_PARAM_TARGET_NAME:
820 case ISCSI_PARAM_TPGT:
821 case ISCSI_PARAM_USERNAME:
822 case ISCSI_PARAM_PASSWORD:
823 case ISCSI_PARAM_USERNAME_IN:
824 case ISCSI_PARAM_PASSWORD_IN:
825 case ISCSI_PARAM_FAST_ABORT:
826 case ISCSI_PARAM_ABORT_TMO:
827 case ISCSI_PARAM_LU_RESET_TMO:
828 case ISCSI_PARAM_IFACE_NAME:
829 case ISCSI_PARAM_INITIATOR_NAME:
Mike Christie3128c6c2011-07-25 13:48:42 -0500830 return S_IRUGO;
831 default:
832 return 0;
833 }
834 }
835
836 return 0;
837}