Emulex Logo
OneCoreā„¢ Storage SDK Release 11.2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ocs_ioctl_iscsi.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2015, Emulex
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  *
31  */
32 
33 /**
34  * @file
35  *
36  */
37 
38 
39 #include "ocs.h"
40 #include "ocs_ioctl.h"
41 #include "ocs_ioctl_xport.h"
42 
43 /**
44  * @brief Retrieve transport port address
45  *
46  * Returns the transport's port address into the appropriate element
47  * of the info structure argument
48  *
49  * @param ocs pointer device structure
50  * @param info pointer to the driver info structure
51  *
52  * @return none
53  */
54 void
56 {
57  ocs_memcpy(info->hw_addr.iscsi.mac_addr, ocs_hal_get_ptr(&ocs->hal, OCS_HAL_MAC_ADDR),
58  sizeof(info->hw_addr.iscsi.mac_addr));
59 }
60 
61 /**
62  * @brief Perform transport specific ioctl operation
63  *
64  * Transport specific IOCTL code is found here
65  *
66  * @param ocs pointer to device structure
67  * @param cmd IOCTL command to execute
68  * @param arg IOCTL specific command argument
69  *
70  * @return returns 0 for success, a negative error code value for failure.
71  */
72 int32_t
73 ocs_device_ioctl_xport(ocs_t *ocs, unsigned int cmd, unsigned long arg)
74 {
75  int rc = 0;
76 
77  switch(cmd) {
78 
80  ocs_sli_port_t *sport;
81  ocs_ioctl_connections_t *connections;
82  ocs_ioctl_connection_info_t *connection_info;
83  ocs_cxn_t *cxn;
84  uint32_t num_connections;
85  uint32_t i;
86 
87  connections = (ocs_ioctl_connections_t *)ocs_ioctl_preprocess(ocs, (void *)arg, sizeof(*connections));
88  if (connections == NULL) {
89  ocs_log_test(ocs, "Error: copy from user failed\n");
90  return -EFAULT;
91  }
92 
93  /* Figure out how many connections we currently have open */
94  num_connections = ocs->hal.domain->node_instance_count;
95 
96  /* Don't report more than the user has space for */
97  if (num_connections > connections->max_connections) {
98  num_connections = connections->max_connections;
99  }
100 
101  connections->num_connections = num_connections;
102 
103  /* Allocate a chunk of kernel memory temporarily to build the response */
104  connection_info = ocs_malloc(ocs, sizeof(ocs_ioctl_connection_info_t) * num_connections,
105  OCS_M_NOWAIT | OCS_M_ZERO);
106  if (connection_info == NULL) {
107  ocs_ioctl_free(ocs, connections, sizeof(*connections));
108  ocs_log_err(ocs, "alloc for connection_info failed\n");
109  return -EFAULT;
110  }
111 
112  /* Fill in the connection info array */
113  i=0;
114  ocs_list_foreach(&ocs->hal.domain->sport_list, sport) {
115  ocs_list_foreach(&sport->node_list, cxn) {
116 
117  /* Don't report more than the user has space for */
118  if (i + 1 > connections->max_connections) {
119  break;
120  }
121 
122  connection_info[i].connection_handle = cxn->conn_hdl;
123  connection_info[i].connection_id = cxn->wq_id;
124  connection_info[i].source_ip_type = cxn->source_ip_type;
125  ocs_memcpy(connection_info[i].source_ip, cxn->source_ip, 16);
126  connection_info[i].source_port = cxn->source_port;
127  connection_info[i].dest_ip_type = cxn->dest_ip_type;
128  ocs_memcpy(connection_info[i].dest_ip, cxn->dest_ip, 16);
129  connection_info[i].dest_port = cxn->dest_port;
130 
131  i++;
132  }
133  }
134 
135 
136  /* Copy the connection info array back to user space */
137  if (ocs_copy_to_user(connections->connections, connection_info,
138  sizeof(ocs_ioctl_connection_info_t) * num_connections)) {
139  ocs_free(ocs, connection_info, sizeof(*connection_info));
140  ocs_ioctl_free(ocs, connections, sizeof(*connections));
141  ocs_log_test(ocs, "ocs_copy_to_user(1) failed\n");
142  return -EFAULT;
143  }
144 
145  /* Copy the argument back to user space */
146  if (ocs_ioctl_postprocess(ocs, (void *)arg, connections, sizeof(*connections))) {
147  ocs_free(ocs, connection_info, sizeof(*connection_info));
148  ocs_log_test(ocs, "copy_to_user(2) failed\n");
149  return -EFAULT;
150  }
151 
152  ocs_free(ocs, connection_info, sizeof(*connection_info));
153  break;
154  }
155  default:
156  rc = -1;
157  }
158 
159  return rc;
160 }
#define OCS_IOCTL_CMD_CONNECTION_INFO
Definition: ocs_ioctl.h:487
connection info ioctl structure
Definition: ocs_ioctl.h:247
void ocs_info_get_xport_address(ocs_t *ocs, ocs_ioctl_driver_info_t *info)
Retrieve transport port address.
Definition: ocs_ioctl_fc.c:56
int32_t ocs_device_ioctl_xport(ocs_t *ocs, unsigned int cmd, unsigned long arg)
Perform transport specific ioctl operation.
Definition: ocs_ioctl_fc.c:76
struct ocs_ioctl_driver_info_t::@2::@4 iscsi
ocs_ioctl_connection_info_t * connections
Definition: ocs_ioctl.h:261
DRIVER_INFO ioctl structure.
Definition: ocs_ioctl.h:60
void * ocs_hal_get_ptr(ocs_hal_t *hal, ocs_hal_property_e prop)
Definition: ocs_hal.c:2753
union ocs_ioctl_driver_info_t::@2 hw_addr
#define ocs_list_foreach(list, item)
Iterate a linked list.
Definition: ocs_list.h:428