blob: e82ab812495846632a4a0d6528367605c893811b [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 */
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>
Mike Christie0e438952012-04-03 23:41:51 -050026#include <scsi/scsi_netlink.h>
27#include <net/netlink.h>
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053028#include <scsi/scsi.h>
29
30#include "be_iscsi.h"
31
32extern struct iscsi_transport beiscsi_iscsi_transport;
33
34/**
35 * beiscsi_session_create - creates a new iscsi session
36 * @cmds_max: max commands supported
37 * @qdepth: max queue depth supported
38 * @initial_cmdsn: initial iscsi CMDSN
39 */
40struct iscsi_cls_session *beiscsi_session_create(struct iscsi_endpoint *ep,
41 u16 cmds_max,
42 u16 qdepth,
43 u32 initial_cmdsn)
44{
45 struct Scsi_Host *shost;
46 struct beiscsi_endpoint *beiscsi_ep;
47 struct iscsi_cls_session *cls_session;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053048 struct beiscsi_hba *phba;
Jayamohan Kallickalb8b9e1b82009-09-22 08:21:22 +053049 struct iscsi_session *sess;
50 struct beiscsi_session *beiscsi_sess;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053051 struct beiscsi_io_task *io_task;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053052
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053053
54 if (!ep) {
John Soni Jose99bc5d52012-08-20 23:00:18 +053055 printk(KERN_ERR
56 "beiscsi_session_create: invalid ep\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053057 return NULL;
58 }
59 beiscsi_ep = ep->dd_data;
60 phba = beiscsi_ep->phba;
61 shost = phba->shost;
John Soni Jose99bc5d52012-08-20 23:00:18 +053062
63 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
64 "BS_%d : In beiscsi_session_create\n");
65
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053066 if (cmds_max > beiscsi_ep->phba->params.wrbs_per_cxn) {
John Soni Jose99bc5d52012-08-20 23:00:18 +053067 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
68 "BS_%d : Cannot handle %d cmds."
69 "Max cmds per session supported is %d. Using %d."
70 "\n", cmds_max,
71 beiscsi_ep->phba->params.wrbs_per_cxn,
72 beiscsi_ep->phba->params.wrbs_per_cxn);
73
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053074 cmds_max = beiscsi_ep->phba->params.wrbs_per_cxn;
75 }
76
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +053077 cls_session = iscsi_session_setup(&beiscsi_iscsi_transport,
78 shost, cmds_max,
79 sizeof(*beiscsi_sess),
80 sizeof(*io_task),
81 initial_cmdsn, ISCSI_MAX_TARGET);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053082 if (!cls_session)
83 return NULL;
84 sess = cls_session->dd_data;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +053085 beiscsi_sess = sess->dd_data;
86 beiscsi_sess->bhs_pool = pci_pool_create("beiscsi_bhs_pool",
87 phba->pcidev,
88 sizeof(struct be_cmd_bhs),
89 64, 0);
90 if (!beiscsi_sess->bhs_pool)
91 goto destroy_sess;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053092
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053093 return cls_session;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +053094destroy_sess:
95 iscsi_session_teardown(cls_session);
96 return NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053097}
98
99/**
100 * beiscsi_session_destroy - destroys iscsi session
101 * @cls_session: pointer to iscsi cls session
102 *
103 * Destroys iSCSI session instance and releases
104 * resources allocated for it.
105 */
106void beiscsi_session_destroy(struct iscsi_cls_session *cls_session)
107{
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530108 struct iscsi_session *sess = cls_session->dd_data;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +0530109 struct beiscsi_session *beiscsi_sess = sess->dd_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530110
John Soni Jose99bc5d52012-08-20 23:00:18 +0530111 printk(KERN_INFO "In beiscsi_session_destroy\n");
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +0530112 pci_pool_destroy(beiscsi_sess->bhs_pool);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530113 iscsi_session_teardown(cls_session);
114}
115
116/**
117 * beiscsi_conn_create - create an instance of iscsi connection
118 * @cls_session: ptr to iscsi_cls_session
119 * @cid: iscsi cid
120 */
121struct iscsi_cls_conn *
122beiscsi_conn_create(struct iscsi_cls_session *cls_session, u32 cid)
123{
124 struct beiscsi_hba *phba;
125 struct Scsi_Host *shost;
126 struct iscsi_cls_conn *cls_conn;
127 struct beiscsi_conn *beiscsi_conn;
128 struct iscsi_conn *conn;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +0530129 struct iscsi_session *sess;
130 struct beiscsi_session *beiscsi_sess;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530131
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530132 shost = iscsi_session_to_shost(cls_session);
133 phba = iscsi_host_priv(shost);
134
John Soni Jose99bc5d52012-08-20 23:00:18 +0530135 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
136 "BS_%d : In beiscsi_conn_create ,cid"
137 "from iscsi layer=%d\n", cid);
138
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530139 cls_conn = iscsi_conn_setup(cls_session, sizeof(*beiscsi_conn), cid);
140 if (!cls_conn)
141 return NULL;
142
143 conn = cls_conn->dd_data;
144 beiscsi_conn = conn->dd_data;
145 beiscsi_conn->ep = NULL;
146 beiscsi_conn->phba = phba;
147 beiscsi_conn->conn = conn;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +0530148 sess = cls_session->dd_data;
149 beiscsi_sess = sess->dd_data;
150 beiscsi_conn->beiscsi_sess = beiscsi_sess;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530151 return cls_conn;
152}
153
154/**
155 * beiscsi_bindconn_cid - Bind the beiscsi_conn with phba connection table
156 * @beiscsi_conn: The pointer to beiscsi_conn structure
157 * @phba: The phba instance
158 * @cid: The cid to free
159 */
160static int beiscsi_bindconn_cid(struct beiscsi_hba *phba,
161 struct beiscsi_conn *beiscsi_conn,
162 unsigned int cid)
163{
Jayamohan Kallickala7909b32013-04-05 20:38:32 -0700164 uint16_t cri_index = BE_GET_CRI_FROM_CID(cid);
165
166 if (phba->conn_table[cri_index]) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530167 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
168 "BS_%d : Connection table already occupied. Detected clash\n");
169
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530170 return -EINVAL;
171 } else {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530172 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
173 "BS_%d : phba->conn_table[%d]=%p(beiscsi_conn)\n",
Jayamohan Kallickala7909b32013-04-05 20:38:32 -0700174 cri_index, beiscsi_conn);
John Soni Jose99bc5d52012-08-20 23:00:18 +0530175
Jayamohan Kallickala7909b32013-04-05 20:38:32 -0700176 phba->conn_table[cri_index] = beiscsi_conn;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530177 }
178 return 0;
179}
180
181/**
182 * beiscsi_conn_bind - Binds iscsi session/connection with TCP connection
183 * @cls_session: pointer to iscsi cls session
184 * @cls_conn: pointer to iscsi cls conn
185 * @transport_fd: EP handle(64 bit)
186 *
187 * This function binds the TCP Conn with iSCSI Connection and Session.
188 */
189int beiscsi_conn_bind(struct iscsi_cls_session *cls_session,
190 struct iscsi_cls_conn *cls_conn,
191 u64 transport_fd, int is_leading)
192{
193 struct iscsi_conn *conn = cls_conn->dd_data;
194 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
Mike Christie3093b042011-07-25 13:48:46 -0500195 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
196 struct beiscsi_hba *phba = iscsi_host_priv(shost);
Jayamohan Kallickal1e4be6f2013-09-28 15:35:50 -0700197 struct hwi_controller *phwi_ctrlr = phba->phwi_ctrlr;
198 struct hwi_wrb_context *pwrb_context;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530199 struct beiscsi_endpoint *beiscsi_ep;
200 struct iscsi_endpoint *ep;
201
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530202 ep = iscsi_lookup_endpoint(transport_fd);
203 if (!ep)
204 return -EINVAL;
205
206 beiscsi_ep = ep->dd_data;
207
208 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
209 return -EINVAL;
210
211 if (beiscsi_ep->phba != phba) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530212 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
213 "BS_%d : beiscsi_ep->hba=%p not equal to phba=%p\n",
214 beiscsi_ep->phba, phba);
215
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530216 return -EEXIST;
217 }
218
Jayamohan Kallickal1e4be6f2013-09-28 15:35:50 -0700219 pwrb_context = &phwi_ctrlr->wrb_context[BE_GET_CRI_FROM_CID(
220 beiscsi_ep->ep_cid)];
221
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530222 beiscsi_conn->beiscsi_conn_cid = beiscsi_ep->ep_cid;
223 beiscsi_conn->ep = beiscsi_ep;
224 beiscsi_ep->conn = beiscsi_conn;
Jayamohan Kallickal1e4be6f2013-09-28 15:35:50 -0700225 beiscsi_conn->doorbell_offset = pwrb_context->doorbell_offset;
John Soni Jose99bc5d52012-08-20 23:00:18 +0530226
227 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
228 "BS_%d : beiscsi_conn=%p conn=%p ep_cid=%d\n",
229 beiscsi_conn, conn, beiscsi_ep->ep_cid);
230
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530231 return beiscsi_bindconn_cid(phba, beiscsi_conn, beiscsi_ep->ep_cid);
232}
233
Mike Christie0e438952012-04-03 23:41:51 -0500234static int beiscsi_create_ipv4_iface(struct beiscsi_hba *phba)
235{
236 if (phba->ipv4_iface)
237 return 0;
238
239 phba->ipv4_iface = iscsi_create_iface(phba->shost,
240 &beiscsi_iscsi_transport,
241 ISCSI_IFACE_TYPE_IPV4,
242 0, 0);
243 if (!phba->ipv4_iface) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530244 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
245 "BS_%d : Could not "
246 "create default IPv4 address.\n");
Mike Christie0e438952012-04-03 23:41:51 -0500247 return -ENODEV;
248 }
249
250 return 0;
251}
252
253static int beiscsi_create_ipv6_iface(struct beiscsi_hba *phba)
254{
255 if (phba->ipv6_iface)
256 return 0;
257
258 phba->ipv6_iface = iscsi_create_iface(phba->shost,
259 &beiscsi_iscsi_transport,
260 ISCSI_IFACE_TYPE_IPV6,
261 0, 0);
262 if (!phba->ipv6_iface) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530263 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
264 "BS_%d : Could not "
265 "create default IPv6 address.\n");
Mike Christie0e438952012-04-03 23:41:51 -0500266 return -ENODEV;
267 }
268
269 return 0;
270}
271
272void beiscsi_create_def_ifaces(struct beiscsi_hba *phba)
273{
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700274 struct be_cmd_get_if_info_resp *if_info;
Mike Christie0e438952012-04-03 23:41:51 -0500275
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700276 if (!mgmt_get_if_info(phba, BE2_IPV4, &if_info)) {
Mike Christie0e438952012-04-03 23:41:51 -0500277 beiscsi_create_ipv4_iface(phba);
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700278 kfree(if_info);
279 }
Mike Christie0e438952012-04-03 23:41:51 -0500280
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700281 if (!mgmt_get_if_info(phba, BE2_IPV6, &if_info)) {
Mike Christie0e438952012-04-03 23:41:51 -0500282 beiscsi_create_ipv6_iface(phba);
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700283 kfree(if_info);
284 }
Mike Christie0e438952012-04-03 23:41:51 -0500285}
286
287void beiscsi_destroy_def_ifaces(struct beiscsi_hba *phba)
288{
289 if (phba->ipv6_iface)
290 iscsi_destroy_iface(phba->ipv6_iface);
291 if (phba->ipv4_iface)
292 iscsi_destroy_iface(phba->ipv4_iface);
293}
294
295static int
296beiscsi_set_static_ip(struct Scsi_Host *shost,
297 struct iscsi_iface_param_info *iface_param,
298 void *data, uint32_t dt_len)
299{
300 struct beiscsi_hba *phba = iscsi_host_priv(shost);
301 struct iscsi_iface_param_info *iface_ip = NULL;
302 struct iscsi_iface_param_info *iface_subnet = NULL;
303 struct nlattr *nla;
304 int ret;
305
306
307 switch (iface_param->param) {
308 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
309 nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_ADDR);
310 if (nla)
311 iface_ip = nla_data(nla);
312
313 nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_SUBNET);
314 if (nla)
315 iface_subnet = nla_data(nla);
316 break;
317 case ISCSI_NET_PARAM_IPV4_ADDR:
318 iface_ip = iface_param;
319 nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_SUBNET);
320 if (nla)
321 iface_subnet = nla_data(nla);
322 break;
323 case ISCSI_NET_PARAM_IPV4_SUBNET:
324 iface_subnet = iface_param;
325 nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_ADDR);
326 if (nla)
327 iface_ip = nla_data(nla);
328 break;
329 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +0530330 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
331 "BS_%d : Unsupported param %d\n",
332 iface_param->param);
Mike Christie0e438952012-04-03 23:41:51 -0500333 }
334
335 if (!iface_ip || !iface_subnet) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530336 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
337 "BS_%d : IP and Subnet Mask required\n");
Mike Christie0e438952012-04-03 23:41:51 -0500338 return -EINVAL;
339 }
340
341 ret = mgmt_set_ip(phba, iface_ip, iface_subnet,
342 ISCSI_BOOTPROTO_STATIC);
343
344 return ret;
345}
346
John Soni Jose6f722382012-08-20 23:00:43 +0530347/**
348 * beiscsi_set_vlan_tag()- Set the VLAN TAG
349 * @shost: Scsi Host for the driver instance
350 * @iface_param: Interface paramters
351 *
352 * Set the VLAN TAG for the adapter or disable
353 * the VLAN config
354 *
355 * returns
356 * Success: 0
357 * Failure: Non-Zero Value
358 **/
359static int
360beiscsi_set_vlan_tag(struct Scsi_Host *shost,
361 struct iscsi_iface_param_info *iface_param)
362{
363 struct beiscsi_hba *phba = iscsi_host_priv(shost);
364 int ret = 0;
365
366 /* Get the Interface Handle */
367 if (mgmt_get_all_if_id(phba)) {
368 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
369 "BS_%d : Getting Interface Handle Failed\n");
370 return -EIO;
371 }
372
373 switch (iface_param->param) {
374 case ISCSI_NET_PARAM_VLAN_ENABLED:
375 if (iface_param->value[0] != ISCSI_VLAN_ENABLE)
376 ret = mgmt_set_vlan(phba, BEISCSI_VLAN_DISABLE);
377 break;
378 case ISCSI_NET_PARAM_VLAN_TAG:
379 ret = mgmt_set_vlan(phba,
380 *((uint16_t *)iface_param->value));
381 break;
382 default:
383 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
Masanari Iidab23f7a02013-04-18 00:12:55 +0900384 "BS_%d : Unknown Param Type : %d\n",
John Soni Jose6f722382012-08-20 23:00:43 +0530385 iface_param->param);
386 return -ENOSYS;
387 }
388 return ret;
389}
390
391
Mike Christie0e438952012-04-03 23:41:51 -0500392static int
393beiscsi_set_ipv4(struct Scsi_Host *shost,
394 struct iscsi_iface_param_info *iface_param,
395 void *data, uint32_t dt_len)
396{
397 struct beiscsi_hba *phba = iscsi_host_priv(shost);
398 int ret = 0;
399
400 /* Check the param */
401 switch (iface_param->param) {
402 case ISCSI_NET_PARAM_IPV4_GW:
403 ret = mgmt_set_gateway(phba, iface_param);
404 break;
405 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
406 if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
407 ret = mgmt_set_ip(phba, iface_param,
408 NULL, ISCSI_BOOTPROTO_DHCP);
409 else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
410 ret = beiscsi_set_static_ip(shost, iface_param,
411 data, dt_len);
412 else
John Soni Jose99bc5d52012-08-20 23:00:18 +0530413 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
414 "BS_%d : Invalid BOOTPROTO: %d\n",
415 iface_param->value[0]);
Mike Christie0e438952012-04-03 23:41:51 -0500416 break;
417 case ISCSI_NET_PARAM_IFACE_ENABLE:
418 if (iface_param->value[0] == ISCSI_IFACE_ENABLE)
419 ret = beiscsi_create_ipv4_iface(phba);
420 else
421 iscsi_destroy_iface(phba->ipv4_iface);
422 break;
423 case ISCSI_NET_PARAM_IPV4_SUBNET:
424 case ISCSI_NET_PARAM_IPV4_ADDR:
425 ret = beiscsi_set_static_ip(shost, iface_param,
426 data, dt_len);
427 break;
John Soni Jose6f722382012-08-20 23:00:43 +0530428 case ISCSI_NET_PARAM_VLAN_ENABLED:
429 case ISCSI_NET_PARAM_VLAN_TAG:
430 ret = beiscsi_set_vlan_tag(shost, iface_param);
431 break;
Mike Christie0e438952012-04-03 23:41:51 -0500432 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +0530433 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
434 "BS_%d : Param %d not supported\n",
435 iface_param->param);
Mike Christie0e438952012-04-03 23:41:51 -0500436 }
437
438 return ret;
439}
440
441static int
442beiscsi_set_ipv6(struct Scsi_Host *shost,
443 struct iscsi_iface_param_info *iface_param,
444 void *data, uint32_t dt_len)
445{
446 struct beiscsi_hba *phba = iscsi_host_priv(shost);
447 int ret = 0;
448
449 switch (iface_param->param) {
450 case ISCSI_NET_PARAM_IFACE_ENABLE:
451 if (iface_param->value[0] == ISCSI_IFACE_ENABLE)
452 ret = beiscsi_create_ipv6_iface(phba);
453 else {
454 iscsi_destroy_iface(phba->ipv6_iface);
455 ret = 0;
456 }
457 break;
458 case ISCSI_NET_PARAM_IPV6_ADDR:
459 ret = mgmt_set_ip(phba, iface_param, NULL,
460 ISCSI_BOOTPROTO_STATIC);
461 break;
462 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +0530463 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
464 "BS_%d : Param %d not supported\n",
465 iface_param->param);
Mike Christie0e438952012-04-03 23:41:51 -0500466 }
467
468 return ret;
469}
470
471int be2iscsi_iface_set_param(struct Scsi_Host *shost,
472 void *data, uint32_t dt_len)
473{
474 struct iscsi_iface_param_info *iface_param = NULL;
John Soni Jose99bc5d52012-08-20 23:00:18 +0530475 struct beiscsi_hba *phba = iscsi_host_priv(shost);
Mike Christie0e438952012-04-03 23:41:51 -0500476 struct nlattr *attrib;
477 uint32_t rm_len = dt_len;
478 int ret = 0 ;
479
480 nla_for_each_attr(attrib, data, dt_len, rm_len) {
481 iface_param = nla_data(attrib);
482
483 if (iface_param->param_type != ISCSI_NET_PARAM)
484 continue;
485
486 /*
487 * BE2ISCSI only supports 1 interface
488 */
489 if (iface_param->iface_num) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530490 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
491 "BS_%d : Invalid iface_num %d."
492 "Only iface_num 0 is supported.\n",
493 iface_param->iface_num);
494
Mike Christie0e438952012-04-03 23:41:51 -0500495 return -EINVAL;
496 }
497
498 switch (iface_param->iface_type) {
499 case ISCSI_IFACE_TYPE_IPV4:
500 ret = beiscsi_set_ipv4(shost, iface_param,
501 data, dt_len);
502 break;
503 case ISCSI_IFACE_TYPE_IPV6:
504 ret = beiscsi_set_ipv6(shost, iface_param,
505 data, dt_len);
506 break;
507 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +0530508 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
509 "BS_%d : Invalid iface type :%d passed\n",
510 iface_param->iface_type);
Mike Christie0e438952012-04-03 23:41:51 -0500511 break;
512 }
513
514 if (ret)
515 return ret;
516 }
517
518 return ret;
519}
520
521static int be2iscsi_get_if_param(struct beiscsi_hba *phba,
522 struct iscsi_iface *iface, int param,
523 char *buf)
524{
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700525 struct be_cmd_get_if_info_resp *if_info;
Mike Christie0e438952012-04-03 23:41:51 -0500526 int len, ip_type = BE2_IPV4;
527
Mike Christie0e438952012-04-03 23:41:51 -0500528 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
529 ip_type = BE2_IPV6;
530
531 len = mgmt_get_if_info(phba, ip_type, &if_info);
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700532 if (len) {
533 kfree(if_info);
Mike Christie0e438952012-04-03 23:41:51 -0500534 return len;
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700535 }
Mike Christie0e438952012-04-03 23:41:51 -0500536
537 switch (param) {
538 case ISCSI_NET_PARAM_IPV4_ADDR:
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700539 len = sprintf(buf, "%pI4\n", if_info->ip_addr.addr);
Mike Christie0e438952012-04-03 23:41:51 -0500540 break;
541 case ISCSI_NET_PARAM_IPV6_ADDR:
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700542 len = sprintf(buf, "%pI6\n", if_info->ip_addr.addr);
Mike Christie0e438952012-04-03 23:41:51 -0500543 break;
544 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700545 if (!if_info->dhcp_state)
John Soni Jose8359c792012-10-20 04:43:03 +0530546 len = sprintf(buf, "static\n");
Mike Christie0e438952012-04-03 23:41:51 -0500547 else
John Soni Jose8359c792012-10-20 04:43:03 +0530548 len = sprintf(buf, "dhcp\n");
Mike Christie0e438952012-04-03 23:41:51 -0500549 break;
550 case ISCSI_NET_PARAM_IPV4_SUBNET:
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700551 len = sprintf(buf, "%pI4\n", if_info->ip_addr.subnet_mask);
Mike Christie0e438952012-04-03 23:41:51 -0500552 break;
John Soni Jose6f722382012-08-20 23:00:43 +0530553 case ISCSI_NET_PARAM_VLAN_ENABLED:
554 len = sprintf(buf, "%s\n",
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700555 (if_info->vlan_priority == BEISCSI_VLAN_DISABLE)
John Soni Jose8359c792012-10-20 04:43:03 +0530556 ? "Disabled\n" : "Enabled\n");
John Soni Jose6f722382012-08-20 23:00:43 +0530557 break;
558 case ISCSI_NET_PARAM_VLAN_ID:
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700559 if (if_info->vlan_priority == BEISCSI_VLAN_DISABLE)
John Soni Jose6f722382012-08-20 23:00:43 +0530560 return -EINVAL;
561 else
562 len = sprintf(buf, "%d\n",
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700563 (if_info->vlan_priority &
John Soni Jose6f722382012-08-20 23:00:43 +0530564 ISCSI_MAX_VLAN_ID));
565 break;
566 case ISCSI_NET_PARAM_VLAN_PRIORITY:
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700567 if (if_info->vlan_priority == BEISCSI_VLAN_DISABLE)
John Soni Jose6f722382012-08-20 23:00:43 +0530568 return -EINVAL;
569 else
570 len = sprintf(buf, "%d\n",
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700571 ((if_info->vlan_priority >> 13) &
John Soni Jose6f722382012-08-20 23:00:43 +0530572 ISCSI_MAX_VLAN_PRIORITY));
573 break;
Mike Christie0e438952012-04-03 23:41:51 -0500574 default:
575 WARN_ON(1);
576 }
577
Jayamohan Kallickal1f536d42013-09-28 15:35:56 -0700578 kfree(if_info);
Mike Christie0e438952012-04-03 23:41:51 -0500579 return len;
580}
581
582int be2iscsi_iface_get_param(struct iscsi_iface *iface,
583 enum iscsi_param_type param_type,
584 int param, char *buf)
585{
586 struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
587 struct beiscsi_hba *phba = iscsi_host_priv(shost);
588 struct be_cmd_get_def_gateway_resp gateway;
589 int len = -ENOSYS;
590
591 switch (param) {
592 case ISCSI_NET_PARAM_IPV4_ADDR:
593 case ISCSI_NET_PARAM_IPV4_SUBNET:
594 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
595 case ISCSI_NET_PARAM_IPV6_ADDR:
John Soni Jose6f722382012-08-20 23:00:43 +0530596 case ISCSI_NET_PARAM_VLAN_ENABLED:
597 case ISCSI_NET_PARAM_VLAN_ID:
598 case ISCSI_NET_PARAM_VLAN_PRIORITY:
Mike Christie0e438952012-04-03 23:41:51 -0500599 len = be2iscsi_get_if_param(phba, iface, param, buf);
600 break;
601 case ISCSI_NET_PARAM_IFACE_ENABLE:
John Soni Jose8359c792012-10-20 04:43:03 +0530602 len = sprintf(buf, "enabled\n");
Mike Christie0e438952012-04-03 23:41:51 -0500603 break;
604 case ISCSI_NET_PARAM_IPV4_GW:
605 memset(&gateway, 0, sizeof(gateway));
606 len = mgmt_get_gateway(phba, BE2_IPV4, &gateway);
607 if (!len)
608 len = sprintf(buf, "%pI4\n", &gateway.ip_addr.addr);
609 break;
610 default:
611 len = -ENOSYS;
612 }
613
614 return len;
615}
616
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530617/**
Mike Christiec7f7fd52011-02-16 15:04:41 -0600618 * beiscsi_ep_get_param - get the iscsi parameter
619 * @ep: pointer to iscsi ep
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530620 * @param: parameter type identifier
621 * @buf: buffer pointer
622 *
623 * returns iscsi parameter
624 */
Mike Christiec7f7fd52011-02-16 15:04:41 -0600625int beiscsi_ep_get_param(struct iscsi_endpoint *ep,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530626 enum iscsi_param param, char *buf)
627{
Mike Christiec7f7fd52011-02-16 15:04:41 -0600628 struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530629 int len = 0;
630
John Soni Jose99bc5d52012-08-20 23:00:18 +0530631 beiscsi_log(beiscsi_ep->phba, KERN_INFO,
632 BEISCSI_LOG_CONFIG,
633 "BS_%d : In beiscsi_ep_get_param,"
634 " param= %d\n", param);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530635
636 switch (param) {
637 case ISCSI_PARAM_CONN_PORT:
638 len = sprintf(buf, "%hu\n", beiscsi_ep->dst_tcpport);
639 break;
640 case ISCSI_PARAM_CONN_ADDRESS:
641 if (beiscsi_ep->ip_type == BE2_IPV4)
642 len = sprintf(buf, "%pI4\n", &beiscsi_ep->dst_addr);
643 else
644 len = sprintf(buf, "%pI6\n", &beiscsi_ep->dst6_addr);
645 break;
646 default:
Mike Christiec7f7fd52011-02-16 15:04:41 -0600647 return -ENOSYS;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530648 }
649 return len;
650}
651
652int beiscsi_set_param(struct iscsi_cls_conn *cls_conn,
653 enum iscsi_param param, char *buf, int buflen)
654{
655 struct iscsi_conn *conn = cls_conn->dd_data;
656 struct iscsi_session *session = conn->session;
John Soni Jose99bc5d52012-08-20 23:00:18 +0530657 struct beiscsi_hba *phba = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530658 int ret;
659
John Soni Jose99bc5d52012-08-20 23:00:18 +0530660 phba = ((struct beiscsi_conn *)conn->dd_data)->phba;
661 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
662 "BS_%d : In beiscsi_conn_set_param,"
663 " param= %d\n", param);
664
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530665 ret = iscsi_set_param(cls_conn, param, buf, buflen);
666 if (ret)
667 return ret;
668 /*
669 * If userspace tried to set the value to higher than we can
670 * support override here.
671 */
672 switch (param) {
673 case ISCSI_PARAM_FIRST_BURST:
674 if (session->first_burst > 8192)
675 session->first_burst = 8192;
676 break;
677 case ISCSI_PARAM_MAX_RECV_DLENGTH:
678 if (conn->max_recv_dlength > 65536)
679 conn->max_recv_dlength = 65536;
680 break;
681 case ISCSI_PARAM_MAX_BURST:
Jayamohan Kallickal230dceb2010-01-23 05:36:10 +0530682 if (session->max_burst > 262144)
683 session->max_burst = 262144;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530684 break;
Jayamohan Kallickal42f43c42010-07-22 04:26:45 +0530685 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
Jayamohan Kallickal73316132013-09-28 15:35:41 -0700686 if (conn->max_xmit_dlength > 65536)
Jayamohan Kallickal42f43c42010-07-22 04:26:45 +0530687 conn->max_xmit_dlength = 65536;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530688 default:
689 return 0;
690 }
691
692 return 0;
693}
694
695/**
John Soni Jose21771992012-04-03 23:41:49 -0500696 * beiscsi_get_initname - Read Initiator Name from flash
697 * @buf: buffer bointer
698 * @phba: The device priv structure instance
699 *
700 * returns number of bytes
701 */
702static int beiscsi_get_initname(char *buf, struct beiscsi_hba *phba)
703{
704 int rc;
John Soni Josee175def2012-10-20 04:45:40 +0530705 unsigned int tag;
John Soni Jose21771992012-04-03 23:41:49 -0500706 struct be_mcc_wrb *wrb;
707 struct be_cmd_hba_name *resp;
John Soni Jose21771992012-04-03 23:41:49 -0500708
709 tag = be_cmd_get_initname(phba);
710 if (!tag) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530711 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
712 "BS_%d : Getting Initiator Name Failed\n");
713
John Soni Jose21771992012-04-03 23:41:49 -0500714 return -EBUSY;
John Soni Josee175def2012-10-20 04:45:40 +0530715 }
John Soni Jose21771992012-04-03 23:41:49 -0500716
John Soni Josee175def2012-10-20 04:45:40 +0530717 rc = beiscsi_mccq_compl(phba, tag, &wrb, NULL);
718 if (rc) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530719 beiscsi_log(phba, KERN_ERR,
720 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
John Soni Josee175def2012-10-20 04:45:40 +0530721 "BS_%d : Initiator Name MBX Failed\n");
722 return rc;
John Soni Jose21771992012-04-03 23:41:49 -0500723 }
John Soni Josee175def2012-10-20 04:45:40 +0530724
John Soni Jose21771992012-04-03 23:41:49 -0500725 resp = embedded_payload(wrb);
726 rc = sprintf(buf, "%s\n", resp->initiator_name);
727 return rc;
728}
729
730/**
John Soni Josec62eef02012-04-03 23:41:52 -0500731 * beiscsi_get_port_state - Get the Port State
732 * @shost : pointer to scsi_host structure
733 *
John Soni Josec62eef02012-04-03 23:41:52 -0500734 */
735static void beiscsi_get_port_state(struct Scsi_Host *shost)
736{
737 struct beiscsi_hba *phba = iscsi_host_priv(shost);
738 struct iscsi_cls_host *ihost = shost->shost_data;
739
740 ihost->port_state = (phba->state == BE_ADAPTER_UP) ?
741 ISCSI_PORT_STATE_UP : ISCSI_PORT_STATE_DOWN;
742}
743
744/**
745 * beiscsi_get_port_speed - Get the Port Speed from Adapter
746 * @shost : pointer to scsi_host structure
747 *
748 * returns Success/Failure
749 */
750static int beiscsi_get_port_speed(struct Scsi_Host *shost)
751{
John Soni Josee175def2012-10-20 04:45:40 +0530752 int rc;
753 unsigned int tag;
John Soni Josec62eef02012-04-03 23:41:52 -0500754 struct be_mcc_wrb *wrb;
755 struct be_cmd_ntwk_link_status_resp *resp;
756 struct beiscsi_hba *phba = iscsi_host_priv(shost);
757 struct iscsi_cls_host *ihost = shost->shost_data;
John Soni Josec62eef02012-04-03 23:41:52 -0500758
759 tag = be_cmd_get_port_speed(phba);
760 if (!tag) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530761 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
762 "BS_%d : Getting Port Speed Failed\n");
763
John Soni Josec62eef02012-04-03 23:41:52 -0500764 return -EBUSY;
John Soni Josee175def2012-10-20 04:45:40 +0530765 }
766 rc = beiscsi_mccq_compl(phba, tag, &wrb, NULL);
767 if (rc) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530768 beiscsi_log(phba, KERN_ERR,
769 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
John Soni Josee175def2012-10-20 04:45:40 +0530770 "BS_%d : Port Speed MBX Failed\n");
771 return rc;
John Soni Josec62eef02012-04-03 23:41:52 -0500772 }
John Soni Josec62eef02012-04-03 23:41:52 -0500773 resp = embedded_payload(wrb);
774
775 switch (resp->mac_speed) {
776 case BE2ISCSI_LINK_SPEED_10MBPS:
777 ihost->port_speed = ISCSI_PORT_SPEED_10MBPS;
778 break;
779 case BE2ISCSI_LINK_SPEED_100MBPS:
780 ihost->port_speed = BE2ISCSI_LINK_SPEED_100MBPS;
781 break;
782 case BE2ISCSI_LINK_SPEED_1GBPS:
783 ihost->port_speed = ISCSI_PORT_SPEED_1GBPS;
784 break;
785 case BE2ISCSI_LINK_SPEED_10GBPS:
786 ihost->port_speed = ISCSI_PORT_SPEED_10GBPS;
787 break;
788 default:
789 ihost->port_speed = ISCSI_PORT_SPEED_UNKNOWN;
790 }
791 return 0;
792}
793
794/**
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530795 * beiscsi_get_host_param - get the iscsi parameter
796 * @shost: pointer to scsi_host structure
797 * @param: parameter type identifier
798 * @buf: buffer pointer
799 *
800 * returns host parameter
801 */
802int beiscsi_get_host_param(struct Scsi_Host *shost,
803 enum iscsi_host_param param, char *buf)
804{
Mike Christie3093b042011-07-25 13:48:46 -0500805 struct beiscsi_hba *phba = iscsi_host_priv(shost);
Jayamohan Kallickalb15d05b2010-08-12 23:36:06 +0530806 int status = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530807
John Soni Jose99bc5d52012-08-20 23:00:18 +0530808 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
809 "BS_%d : In beiscsi_get_host_param,"
810 " param= %d\n", param);
811
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530812 switch (param) {
813 case ISCSI_HOST_PARAM_HWADDRESS:
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530814 status = beiscsi_get_macaddr(buf, phba);
815 if (status < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530816 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
817 "BS_%d : beiscsi_get_macaddr Failed\n");
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530818 return status;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530819 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530820 break;
John Soni Jose21771992012-04-03 23:41:49 -0500821 case ISCSI_HOST_PARAM_INITIATOR_NAME:
822 status = beiscsi_get_initname(buf, phba);
823 if (status < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530824 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
825 "BS_%d : Retreiving Initiator Name Failed\n");
John Soni Jose21771992012-04-03 23:41:49 -0500826 return status;
827 }
828 break;
John Soni Josec62eef02012-04-03 23:41:52 -0500829 case ISCSI_HOST_PARAM_PORT_STATE:
830 beiscsi_get_port_state(shost);
831 status = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
832 break;
833 case ISCSI_HOST_PARAM_PORT_SPEED:
834 status = beiscsi_get_port_speed(shost);
835 if (status) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530836 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
837 "BS_%d : Retreiving Port Speed Failed\n");
John Soni Josec62eef02012-04-03 23:41:52 -0500838 return status;
839 }
840 status = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
841 break;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530842 default:
843 return iscsi_host_get_param(shost, param, buf);
844 }
Jayamohan Kallickalb15d05b2010-08-12 23:36:06 +0530845 return status;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530846}
847
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530848int beiscsi_get_macaddr(char *buf, struct beiscsi_hba *phba)
849{
Mike Christie0e438952012-04-03 23:41:51 -0500850 struct be_cmd_get_nic_conf_resp resp;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530851 int rc;
852
Jayamohan Kallickal6c831852013-09-28 15:35:40 -0700853 if (phba->mac_addr_set)
John Soni Josedf5d0e62012-08-20 23:00:31 +0530854 return sysfs_format_mac(buf, phba->mac_address, ETH_ALEN);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530855
Mike Christie0e438952012-04-03 23:41:51 -0500856 memset(&resp, 0, sizeof(resp));
857 rc = mgmt_get_nic_conf(phba, &resp);
858 if (rc)
859 return rc;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530860
Jayamohan Kallickal6c831852013-09-28 15:35:40 -0700861 phba->mac_addr_set = true;
Mike Christie0e438952012-04-03 23:41:51 -0500862 memcpy(phba->mac_address, resp.mac_address, ETH_ALEN);
863 return sysfs_format_mac(buf, phba->mac_address, ETH_ALEN);
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530864}
865
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530866/**
867 * beiscsi_conn_get_stats - get the iscsi stats
868 * @cls_conn: pointer to iscsi cls conn
869 * @stats: pointer to iscsi_stats structure
870 *
871 * returns iscsi stats
872 */
873void beiscsi_conn_get_stats(struct iscsi_cls_conn *cls_conn,
874 struct iscsi_stats *stats)
875{
876 struct iscsi_conn *conn = cls_conn->dd_data;
John Soni Jose99bc5d52012-08-20 23:00:18 +0530877 struct beiscsi_hba *phba = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530878
John Soni Jose99bc5d52012-08-20 23:00:18 +0530879 phba = ((struct beiscsi_conn *)conn->dd_data)->phba;
880 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
881 "BS_%d : In beiscsi_conn_get_stats\n");
882
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530883 stats->txdata_octets = conn->txdata_octets;
884 stats->rxdata_octets = conn->rxdata_octets;
885 stats->dataout_pdus = conn->dataout_pdus_cnt;
886 stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
887 stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
888 stats->datain_pdus = conn->datain_pdus_cnt;
889 stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
890 stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
891 stats->r2t_pdus = conn->r2t_pdus_cnt;
892 stats->digest_err = 0;
893 stats->timeout_err = 0;
894 stats->custom_length = 0;
895 strcpy(stats->custom[0].desc, "eh_abort_cnt");
896 stats->custom[0].value = conn->eh_abort_cnt;
897}
898
899/**
900 * beiscsi_set_params_for_offld - get the parameters for offload
901 * @beiscsi_conn: pointer to beiscsi_conn
902 * @params: pointer to offload_params structure
903 */
904static void beiscsi_set_params_for_offld(struct beiscsi_conn *beiscsi_conn,
905 struct beiscsi_offload_params *params)
906{
907 struct iscsi_conn *conn = beiscsi_conn->conn;
908 struct iscsi_session *session = conn->session;
909
910 AMAP_SET_BITS(struct amap_beiscsi_offload_params, max_burst_length,
911 params, session->max_burst);
912 AMAP_SET_BITS(struct amap_beiscsi_offload_params,
913 max_send_data_segment_length, params,
914 conn->max_xmit_dlength);
915 AMAP_SET_BITS(struct amap_beiscsi_offload_params, first_burst_length,
916 params, session->first_burst);
917 AMAP_SET_BITS(struct amap_beiscsi_offload_params, erl, params,
918 session->erl);
919 AMAP_SET_BITS(struct amap_beiscsi_offload_params, dde, params,
920 conn->datadgst_en);
921 AMAP_SET_BITS(struct amap_beiscsi_offload_params, hde, params,
922 conn->hdrdgst_en);
923 AMAP_SET_BITS(struct amap_beiscsi_offload_params, ir2t, params,
924 session->initial_r2t_en);
925 AMAP_SET_BITS(struct amap_beiscsi_offload_params, imd, params,
926 session->imm_data_en);
John Soni Joseacb96932012-10-20 04:44:35 +0530927 AMAP_SET_BITS(struct amap_beiscsi_offload_params,
928 data_seq_inorder, params,
929 session->dataseq_inorder_en);
930 AMAP_SET_BITS(struct amap_beiscsi_offload_params,
931 pdu_seq_inorder, params,
932 session->pdu_inorder_en);
933 AMAP_SET_BITS(struct amap_beiscsi_offload_params, max_r2t, params,
934 session->max_r2t);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530935 AMAP_SET_BITS(struct amap_beiscsi_offload_params, exp_statsn, params,
936 (conn->exp_statsn - 1));
Jayamohan Kallickal73316132013-09-28 15:35:41 -0700937 AMAP_SET_BITS(struct amap_beiscsi_offload_params,
938 max_recv_data_segment_length, params,
939 conn->max_recv_dlength);
940
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530941}
942
943/**
944 * beiscsi_conn_start - offload of session to chip
945 * @cls_conn: pointer to beiscsi_conn
946 */
947int beiscsi_conn_start(struct iscsi_cls_conn *cls_conn)
948{
949 struct iscsi_conn *conn = cls_conn->dd_data;
950 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
951 struct beiscsi_endpoint *beiscsi_ep;
952 struct beiscsi_offload_params params;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530953
John Soni Jose99bc5d52012-08-20 23:00:18 +0530954 beiscsi_log(beiscsi_conn->phba, KERN_INFO,
955 BEISCSI_LOG_CONFIG,
956 "BS_%d : In beiscsi_conn_start\n");
957
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530958 memset(&params, 0, sizeof(struct beiscsi_offload_params));
959 beiscsi_ep = beiscsi_conn->ep;
960 if (!beiscsi_ep)
John Soni Jose99bc5d52012-08-20 23:00:18 +0530961 beiscsi_log(beiscsi_conn->phba, KERN_ERR,
962 BEISCSI_LOG_CONFIG,
963 "BS_%d : In beiscsi_conn_start , no beiscsi_ep\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530964
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530965 beiscsi_conn->login_in_progress = 0;
966 beiscsi_set_params_for_offld(beiscsi_conn, &params);
967 beiscsi_offload_connection(beiscsi_conn, &params);
968 iscsi_conn_start(cls_conn);
969 return 0;
970}
971
972/**
973 * beiscsi_get_cid - Allocate a cid
974 * @phba: The phba instance
975 */
976static int beiscsi_get_cid(struct beiscsi_hba *phba)
977{
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -0700978 unsigned short cid = 0xFFFF, cid_from_ulp;
979 struct ulp_cid_info *cid_info = NULL;
980 uint16_t cid_avlbl_ulp0, cid_avlbl_ulp1;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530981
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -0700982 /* Find the ULP which has more CID available */
983 cid_avlbl_ulp0 = (phba->cid_array_info[BEISCSI_ULP0]) ?
984 BEISCSI_ULP0_AVLBL_CID(phba) : 0;
985 cid_avlbl_ulp1 = (phba->cid_array_info[BEISCSI_ULP1]) ?
986 BEISCSI_ULP1_AVLBL_CID(phba) : 0;
987 cid_from_ulp = (cid_avlbl_ulp0 > cid_avlbl_ulp1) ?
988 BEISCSI_ULP0 : BEISCSI_ULP1;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530989
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -0700990 if (test_bit(cid_from_ulp, (void *)&phba->fw_config.ulp_supported)) {
991 cid_info = phba->cid_array_info[cid_from_ulp];
992 if (!cid_info->avlbl_cids)
993 return cid;
994
995 cid = cid_info->cid_array[cid_info->cid_alloc++];
996
997 if (cid_info->cid_alloc == BEISCSI_GET_CID_COUNT(
998 phba, cid_from_ulp))
999 cid_info->cid_alloc = 0;
1000
1001 cid_info->avlbl_cids--;
1002 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301003 return cid;
1004}
1005
1006/**
Mike Christiefa95d202010-06-09 03:30:08 -05001007 * beiscsi_put_cid - Free the cid
1008 * @phba: The phba for which the cid is being freed
1009 * @cid: The cid to free
1010 */
1011static void beiscsi_put_cid(struct beiscsi_hba *phba, unsigned short cid)
1012{
Jayamohan Kallickal0a3db7c2013-09-28 15:35:49 -07001013 uint16_t cid_post_ulp;
1014 struct hwi_controller *phwi_ctrlr;
1015 struct hwi_wrb_context *pwrb_context;
1016 struct ulp_cid_info *cid_info = NULL;
1017 uint16_t cri_index = BE_GET_CRI_FROM_CID(cid);
1018
1019 phwi_ctrlr = phba->phwi_ctrlr;
1020 pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
1021 cid_post_ulp = pwrb_context->ulp_num;
1022
1023 cid_info = phba->cid_array_info[cid_post_ulp];
1024 cid_info->avlbl_cids++;
1025
1026 cid_info->cid_array[cid_info->cid_free++] = cid;
1027 if (cid_info->cid_free == BEISCSI_GET_CID_COUNT(phba, cid_post_ulp))
1028 cid_info->cid_free = 0;
Mike Christiefa95d202010-06-09 03:30:08 -05001029}
1030
1031/**
1032 * beiscsi_free_ep - free endpoint
1033 * @ep: pointer to iscsi endpoint structure
1034 */
1035static void beiscsi_free_ep(struct beiscsi_endpoint *beiscsi_ep)
1036{
1037 struct beiscsi_hba *phba = beiscsi_ep->phba;
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07001038 struct beiscsi_conn *beiscsi_conn;
Mike Christiefa95d202010-06-09 03:30:08 -05001039
1040 beiscsi_put_cid(phba, beiscsi_ep->ep_cid);
1041 beiscsi_ep->phba = NULL;
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001042 phba->ep_array[BE_GET_CRI_FROM_CID
1043 (beiscsi_ep->ep_cid)] = NULL;
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07001044
1045 /**
1046 * Check if any connection resource allocated by driver
1047 * is to be freed.This case occurs when target redirection
1048 * or connection retry is done.
1049 **/
1050 if (!beiscsi_ep->conn)
1051 return;
1052
1053 beiscsi_conn = beiscsi_ep->conn;
1054 if (beiscsi_conn->login_in_progress) {
Jayamohan Kallickal4a4a11b2013-04-05 20:38:31 -07001055 beiscsi_free_mgmt_task_handles(beiscsi_conn,
1056 beiscsi_conn->task);
Jayamohan Kallickal43f388b2013-04-05 20:38:25 -07001057 beiscsi_conn->login_in_progress = 0;
1058 }
Mike Christiefa95d202010-06-09 03:30:08 -05001059}
1060
1061/**
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301062 * beiscsi_open_conn - Ask FW to open a TCP connection
1063 * @ep: endpoint to be used
1064 * @src_addr: The source IP address
1065 * @dst_addr: The Destination IP address
1066 *
1067 * Asks the FW to open a TCP connection
1068 */
1069static int beiscsi_open_conn(struct iscsi_endpoint *ep,
1070 struct sockaddr *src_addr,
1071 struct sockaddr *dst_addr, int non_blocking)
1072{
1073 struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
1074 struct beiscsi_hba *phba = beiscsi_ep->phba;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05301075 struct tcp_connect_and_offload_out *ptcpcnct_out;
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +05301076 struct be_dma_mem nonemb_cmd;
John Soni Josee175def2012-10-20 04:45:40 +05301077 unsigned int tag;
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +05301078 int ret = -ENOMEM;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301079
John Soni Jose99bc5d52012-08-20 23:00:18 +05301080 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1081 "BS_%d : In beiscsi_open_conn\n");
1082
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301083 beiscsi_ep->ep_cid = beiscsi_get_cid(phba);
1084 if (beiscsi_ep->ep_cid == 0xFFFF) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301085 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
1086 "BS_%d : No free cid available\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301087 return ret;
1088 }
John Soni Jose99bc5d52012-08-20 23:00:18 +05301089
1090 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1091 "BS_%d : In beiscsi_open_conn, ep_cid=%d\n",
1092 beiscsi_ep->ep_cid);
1093
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001094 phba->ep_array[BE_GET_CRI_FROM_CID
1095 (beiscsi_ep->ep_cid)] = ep;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301096
1097 beiscsi_ep->cid_vld = 0;
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +05301098 nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
1099 sizeof(struct tcp_connect_and_offload_in),
1100 &nonemb_cmd.dma);
1101 if (nonemb_cmd.va == NULL) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301102
1103 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
1104 "BS_%d : Failed to allocate memory for"
1105 " mgmt_open_connection\n");
1106
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001107 beiscsi_free_ep(beiscsi_ep);
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +05301108 return -ENOMEM;
1109 }
1110 nonemb_cmd.size = sizeof(struct tcp_connect_and_offload_in);
1111 memset(nonemb_cmd.va, 0, nonemb_cmd.size);
1112 tag = mgmt_open_connection(phba, dst_addr, beiscsi_ep, &nonemb_cmd);
Jayamohan Kallickal1e234bb2013-04-05 20:38:23 -07001113 if (tag <= 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301114 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
1115 "BS_%d : mgmt_open_connection Failed for cid=%d\n",
1116 beiscsi_ep->ep_cid);
1117
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +05301118 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
1119 nonemb_cmd.va, nonemb_cmd.dma);
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001120 beiscsi_free_ep(beiscsi_ep);
Jayamohan Kallickal1f926382010-07-22 04:22:27 +05301121 return -EAGAIN;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05301122 }
John Soni Josee175def2012-10-20 04:45:40 +05301123
Jayamohan Kallickal1e234bb2013-04-05 20:38:23 -07001124 ret = beiscsi_mccq_compl(phba, tag, NULL, nonemb_cmd.va);
John Soni Josee175def2012-10-20 04:45:40 +05301125 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301126 beiscsi_log(phba, KERN_ERR,
1127 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
John Soni Josee175def2012-10-20 04:45:40 +05301128 "BS_%d : mgmt_open_connection Failed");
John Soni Jose99bc5d52012-08-20 23:00:18 +05301129
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +05301130 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
1131 nonemb_cmd.va, nonemb_cmd.dma);
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001132 beiscsi_free_ep(beiscsi_ep);
1133 return -EBUSY;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05301134 }
John Soni Josee175def2012-10-20 04:45:40 +05301135
Jayamohan Kallickal1e234bb2013-04-05 20:38:23 -07001136 ptcpcnct_out = (struct tcp_connect_and_offload_out *)nonemb_cmd.va;
John Soni Josee175def2012-10-20 04:45:40 +05301137 beiscsi_ep = ep->dd_data;
1138 beiscsi_ep->fw_handle = ptcpcnct_out->connection_handle;
1139 beiscsi_ep->cid_vld = 1;
1140 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1141 "BS_%d : mgmt_open_connection Success\n");
1142
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +05301143 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
1144 nonemb_cmd.va, nonemb_cmd.dma);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05301145 return 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301146}
1147
1148/**
1149 * beiscsi_ep_connect - Ask chip to create TCP Conn
1150 * @scsi_host: Pointer to scsi_host structure
1151 * @dst_addr: The IP address of Target
1152 * @non_blocking: blocking or non-blocking call
1153 *
1154 * This routines first asks chip to create a connection and then allocates an EP
1155 */
1156struct iscsi_endpoint *
1157beiscsi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
1158 int non_blocking)
1159{
1160 struct beiscsi_hba *phba;
1161 struct beiscsi_endpoint *beiscsi_ep;
1162 struct iscsi_endpoint *ep;
1163 int ret;
1164
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301165 if (shost)
1166 phba = iscsi_host_priv(shost);
1167 else {
1168 ret = -ENXIO;
John Soni Jose99bc5d52012-08-20 23:00:18 +05301169 printk(KERN_ERR
1170 "beiscsi_ep_connect shost is NULL\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301171 return ERR_PTR(ret);
1172 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301173
Jayamohan Kallickalcf6e3c62013-04-05 20:38:33 -07001174 if (beiscsi_error(phba)) {
1175 ret = -EIO;
1176 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1177 "BS_%d : The FW state Not Stable!!!\n");
1178 return ERR_PTR(ret);
1179 }
1180
Jayamohan Kallickal5dc1c412010-01-23 05:36:52 +05301181 if (phba->state != BE_ADAPTER_UP) {
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301182 ret = -EBUSY;
John Soni Jose8359c792012-10-20 04:43:03 +05301183 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1184 "BS_%d : The Adapter Port state is Down!!!\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +05301185 return ERR_PTR(ret);
1186 }
1187
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301188 ep = iscsi_create_endpoint(sizeof(struct beiscsi_endpoint));
1189 if (!ep) {
1190 ret = -ENOMEM;
1191 return ERR_PTR(ret);
1192 }
1193
1194 beiscsi_ep = ep->dd_data;
1195 beiscsi_ep->phba = phba;
Jayamohan Kallickalc2462282010-01-05 05:05:34 +05301196 beiscsi_ep->openiscsi_ep = ep;
Jayamohan Kallickalf5ed7bd2010-07-22 04:18:01 +05301197 ret = beiscsi_open_conn(ep, NULL, dst_addr, non_blocking);
1198 if (ret) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301199 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
1200 "BS_%d : Failed in beiscsi_open_conn\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301201 goto free_ep;
1202 }
1203
1204 return ep;
1205
1206free_ep:
Mike Christiefa95d202010-06-09 03:30:08 -05001207 iscsi_destroy_endpoint(ep);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301208 return ERR_PTR(ret);
1209}
1210
1211/**
1212 * beiscsi_ep_poll - Poll to see if connection is established
1213 * @ep: endpoint to be used
1214 * @timeout_ms: timeout specified in millisecs
1215 *
1216 * Poll to see if TCP connection established
1217 */
1218int beiscsi_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
1219{
1220 struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
1221
John Soni Jose99bc5d52012-08-20 23:00:18 +05301222 beiscsi_log(beiscsi_ep->phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1223 "BS_%d : In beiscsi_ep_poll\n");
1224
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301225 if (beiscsi_ep->cid_vld == 1)
1226 return 1;
1227 else
1228 return 0;
1229}
1230
1231/**
1232 * beiscsi_close_conn - Upload the connection
1233 * @ep: The iscsi endpoint
1234 * @flag: The type of connection closure
1235 */
Jayamohan Kallickalc2462282010-01-05 05:05:34 +05301236static int beiscsi_close_conn(struct beiscsi_endpoint *beiscsi_ep, int flag)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301237{
1238 int ret = 0;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05301239 unsigned int tag;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301240 struct beiscsi_hba *phba = beiscsi_ep->phba;
1241
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05301242 tag = mgmt_upload_connection(phba, beiscsi_ep->ep_cid, flag);
1243 if (!tag) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301244 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1245 "BS_%d : upload failed for cid 0x%x\n",
1246 beiscsi_ep->ep_cid);
1247
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +05301248 ret = -EAGAIN;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301249 }
John Soni Josee175def2012-10-20 04:45:40 +05301250
1251 ret = beiscsi_mccq_compl(phba, tag, NULL, NULL);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301252 return ret;
1253}
1254
1255/**
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301256 * beiscsi_unbind_conn_to_cid - Unbind the beiscsi_conn from phba conn table
1257 * @phba: The phba instance
1258 * @cid: The cid to free
1259 */
1260static int beiscsi_unbind_conn_to_cid(struct beiscsi_hba *phba,
1261 unsigned int cid)
1262{
Jayamohan Kallickala7909b32013-04-05 20:38:32 -07001263 uint16_t cri_index = BE_GET_CRI_FROM_CID(cid);
1264
1265 if (phba->conn_table[cri_index])
1266 phba->conn_table[cri_index] = NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301267 else {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301268 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1269 "BS_%d : Connection table Not occupied.\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301270 return -EINVAL;
1271 }
1272 return 0;
1273}
1274
1275/**
Mike Christiefa95d202010-06-09 03:30:08 -05001276 * beiscsi_ep_disconnect - Tears down the TCP connection
1277 * @ep: endpoint to be used
1278 *
1279 * Tears down the TCP connection
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301280 */
Mike Christiefa95d202010-06-09 03:30:08 -05001281void beiscsi_ep_disconnect(struct iscsi_endpoint *ep)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301282{
Mike Christiefa95d202010-06-09 03:30:08 -05001283 struct beiscsi_conn *beiscsi_conn;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301284 struct beiscsi_endpoint *beiscsi_ep;
Mike Christiefa95d202010-06-09 03:30:08 -05001285 struct beiscsi_hba *phba;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05301286 unsigned int tag;
John Soni Jose0a513dd2012-08-20 23:00:55 +05301287 uint8_t mgmt_invalidate_flag, tcp_upload_flag;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301288 unsigned short savecfg_flag = CMD_ISCSI_SESSION_SAVE_CFG_ON_FLASH;
1289
Mike Christiefa95d202010-06-09 03:30:08 -05001290 beiscsi_ep = ep->dd_data;
1291 phba = beiscsi_ep->phba;
John Soni Jose99bc5d52012-08-20 23:00:18 +05301292 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1293 "BS_%d : In beiscsi_ep_disconnect for ep_cid = %d\n",
1294 beiscsi_ep->ep_cid);
Mike Christiefa95d202010-06-09 03:30:08 -05001295
John Soni Jose0a513dd2012-08-20 23:00:55 +05301296 if (beiscsi_ep->conn) {
1297 beiscsi_conn = beiscsi_ep->conn;
1298 iscsi_suspend_queue(beiscsi_conn->conn);
1299 mgmt_invalidate_flag = ~BEISCSI_NO_RST_ISSUE;
1300 tcp_upload_flag = CONNECTION_UPLOAD_GRACEFUL;
1301 } else {
1302 mgmt_invalidate_flag = BEISCSI_NO_RST_ISSUE;
1303 tcp_upload_flag = CONNECTION_UPLOAD_ABORT;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301304 }
Mike Christiefa95d202010-06-09 03:30:08 -05001305
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05301306 tag = mgmt_invalidate_connection(phba, beiscsi_ep,
John Soni Jose0a513dd2012-08-20 23:00:55 +05301307 beiscsi_ep->ep_cid,
1308 mgmt_invalidate_flag,
1309 savecfg_flag);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +05301310 if (!tag) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301311 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
John Soni Jose0a513dd2012-08-20 23:00:55 +05301312 "BS_%d : mgmt_invalidate_connection Failed for cid=%d\n",
John Soni Jose99bc5d52012-08-20 23:00:18 +05301313 beiscsi_ep->ep_cid);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301314 }
Mike Christiefa95d202010-06-09 03:30:08 -05001315
John Soni Josee175def2012-10-20 04:45:40 +05301316 beiscsi_mccq_compl(phba, tag, NULL, NULL);
John Soni Jose0a513dd2012-08-20 23:00:55 +05301317 beiscsi_close_conn(beiscsi_ep, tcp_upload_flag);
Jayamohan Kallickalc2462282010-01-05 05:05:34 +05301318 beiscsi_free_ep(beiscsi_ep);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301319 beiscsi_unbind_conn_to_cid(phba, beiscsi_ep->ep_cid);
Mike Christiefa95d202010-06-09 03:30:08 -05001320 iscsi_destroy_endpoint(beiscsi_ep->openiscsi_ep);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301321}
Mike Christie3128c6c2011-07-25 13:48:42 -05001322
Al Viro587a1f12011-07-23 23:11:19 -04001323umode_t be2iscsi_attr_is_visible(int param_type, int param)
Mike Christie3128c6c2011-07-25 13:48:42 -05001324{
1325 switch (param_type) {
Mike Christie0e438952012-04-03 23:41:51 -05001326 case ISCSI_NET_PARAM:
1327 switch (param) {
1328 case ISCSI_NET_PARAM_IFACE_ENABLE:
1329 case ISCSI_NET_PARAM_IPV4_ADDR:
1330 case ISCSI_NET_PARAM_IPV4_SUBNET:
1331 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
1332 case ISCSI_NET_PARAM_IPV4_GW:
1333 case ISCSI_NET_PARAM_IPV6_ADDR:
John Soni Jose6f722382012-08-20 23:00:43 +05301334 case ISCSI_NET_PARAM_VLAN_ID:
1335 case ISCSI_NET_PARAM_VLAN_PRIORITY:
1336 case ISCSI_NET_PARAM_VLAN_ENABLED:
Mike Christie0e438952012-04-03 23:41:51 -05001337 return S_IRUGO;
1338 default:
1339 return 0;
1340 }
Mike Christief27fb2e2011-07-25 13:48:45 -05001341 case ISCSI_HOST_PARAM:
1342 switch (param) {
1343 case ISCSI_HOST_PARAM_HWADDRESS:
John Soni Josec62eef02012-04-03 23:41:52 -05001344 case ISCSI_HOST_PARAM_INITIATOR_NAME:
1345 case ISCSI_HOST_PARAM_PORT_STATE:
1346 case ISCSI_HOST_PARAM_PORT_SPEED:
Mike Christief27fb2e2011-07-25 13:48:45 -05001347 return S_IRUGO;
1348 default:
1349 return 0;
1350 }
Mike Christie3128c6c2011-07-25 13:48:42 -05001351 case ISCSI_PARAM:
1352 switch (param) {
1353 case ISCSI_PARAM_MAX_RECV_DLENGTH:
1354 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
1355 case ISCSI_PARAM_HDRDGST_EN:
1356 case ISCSI_PARAM_DATADGST_EN:
1357 case ISCSI_PARAM_CONN_ADDRESS:
1358 case ISCSI_PARAM_CONN_PORT:
1359 case ISCSI_PARAM_EXP_STATSN:
1360 case ISCSI_PARAM_PERSISTENT_ADDRESS:
1361 case ISCSI_PARAM_PERSISTENT_PORT:
1362 case ISCSI_PARAM_PING_TMO:
1363 case ISCSI_PARAM_RECV_TMO:
Mike Christie1d063c12011-07-25 13:48:43 -05001364 case ISCSI_PARAM_INITIAL_R2T_EN:
1365 case ISCSI_PARAM_MAX_R2T:
1366 case ISCSI_PARAM_IMM_DATA_EN:
1367 case ISCSI_PARAM_FIRST_BURST:
1368 case ISCSI_PARAM_MAX_BURST:
1369 case ISCSI_PARAM_PDU_INORDER_EN:
1370 case ISCSI_PARAM_DATASEQ_INORDER_EN:
1371 case ISCSI_PARAM_ERL:
1372 case ISCSI_PARAM_TARGET_NAME:
1373 case ISCSI_PARAM_TPGT:
1374 case ISCSI_PARAM_USERNAME:
1375 case ISCSI_PARAM_PASSWORD:
1376 case ISCSI_PARAM_USERNAME_IN:
1377 case ISCSI_PARAM_PASSWORD_IN:
1378 case ISCSI_PARAM_FAST_ABORT:
1379 case ISCSI_PARAM_ABORT_TMO:
1380 case ISCSI_PARAM_LU_RESET_TMO:
1381 case ISCSI_PARAM_IFACE_NAME:
1382 case ISCSI_PARAM_INITIATOR_NAME:
Mike Christie3128c6c2011-07-25 13:48:42 -05001383 return S_IRUGO;
1384 default:
1385 return 0;
1386 }
1387 }
1388
1389 return 0;
1390}