Emulex Logo
OneCoreā„¢ Storage SDK Release 11.2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ocs_ioctl_fc.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 #include "ocs_gendump.h"
43 
44 /**
45  * @brief Retrieve transport port address
46  *
47  * Returns the transport's port address into the appropriate element
48  * of the info structure argument
49  *
50  * @param ocs pointer device structure
51  * @param info pointer to the driver info structure
52  *
53  * @return none
54  */
55 void
57 {
58  ocs_memcpy(info->hw_addr.fc.wwnn, ocs_hal_get_ptr(&ocs->hal, OCS_HAL_WWN_NODE),
59  sizeof(info->hw_addr.fc.wwnn));
60  ocs_memcpy(info->hw_addr.fc.wwpn, ocs_hal_get_ptr(&ocs->hal, OCS_HAL_WWN_PORT),
61  sizeof(info->hw_addr.fc.wwpn));
62 }
63 
64 /**
65  * @brief Perform transport specific ioctl operation
66  *
67  * Transport specific IOCTL code is found here
68  *
69  * @param ocs pointer to device structure
70  * @param cmd IOCTL command to execute
71  * @param arg IOCTL specific command argument
72  *
73  * @return returns 0 for success, a negative error code value for failure.
74  */
75 int32_t
76 ocs_device_ioctl_xport(ocs_t *ocs, unsigned int cmd, unsigned long arg)
77 {
78  int rc = 0;
79 
80  switch(cmd) {
81 
82  case OCS_IOCTL_CMD_VPORT: {
83  ocs_ioctl_vport_t *req;
84  ocs_domain_t *domain;
85  uint32_t port_id;
86 
87 #if defined(OCS_INCLUDE_SCST)
88  ocs_log_test(ocs, "Error: vport commands must be sent via SCST using the mgmt cmd in "
89  "/sys/kernel/scst_tgt/targets/ocs_scst\n");
90  return -1;
91 #endif
92 
93 
94  req = (ocs_ioctl_vport_t *)ocs_ioctl_preprocess(ocs, (void *)arg, sizeof(*req));
95  if (req == NULL) {
96  ocs_log_test(ocs, "Error: copy from user failed\n");
97  return -EFAULT;
98  }
99 
100  domain = ocs_domain_get_instance(ocs, req->domain_index);
101  if (domain == NULL) {
102  ocs_log_test(ocs, "Error: no domain found\n");
103  ocs_ioctl_free(ocs, req, sizeof(*req));
104  return -EINVAL;
105  }
106 
107  if (req->req_create) {
108  port_id = UINT32_MAX;
109 #if defined(ENABLE_FABRIC_EMULATION)
110  if (domain->femul_enable) {
111  port_id = ocs_femul_portid_alloc(domain);
112  }
113 #endif
114  rc = ocs_sport_vport_new(domain, req->wwpn, req->wwnn, port_id, req->enable_ini,
115  req->enable_tgt, NULL, NULL, TRUE);
116  } else {
117  rc = ocs_sport_vport_del(ocs, domain, req->wwpn, req->wwnn);
118  }
119 
120  if (ocs_ioctl_postprocess(ocs, (void*) arg, req, sizeof(*req))) {
121  ocs_log_test(ocs, "Error: copy to user failed\n");
122  return -EFAULT;
123  }
124 
125  return rc;
126  }
127 
128  case OCS_IOCTL_CMD_GEN_DUMP: {
129  ocs_log_info(ocs, "Call ocs_gen_dump\n");
130  rc = ocs_gen_dump(ocs);
131  if(rc) {
132  ocs_log_test(ocs, "OCS_IOCTL_CMD_GEN_DUMP failed: %d\n", rc);
133  }
134  break;
135  }
136 
138  rc = ocs_xport_control(ocs->xport, OCS_XPORT_PORT_ONLINE);
139  if (rc) {
140  ocs_log_test(ocs, "OCS_XPORT_PORT_ONLINE failed: %d\n", rc);
141  }
142  break;
143  }
144 
145  default:
146  rc = -1;
147  break;
148  }
149  return rc;
150 }
ocs_domain_t * ocs_domain_get_instance(ocs_t *ocs, uint32_t index)
Return a pointer to the domain, given the instance index.
Definition: ocs_domain.c:173
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
#define OCS_IOCTL_CMD_VPORT
Definition: ocs_ioctl.h:488
#define OCS_IOCTL_CMD_LINK_ONLINE
Definition: ocs_ioctl.h:495
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::@3 fc
int32_t ocs_xport_control(ocs_xport_t *xport, ocs_xport_ctrl_e cmd,...)
Perform transport attach function.
Definition: ocs_xport.c:100
uint32_t enable_tgt
Definition: ocs_ioctl.h:233
#define OCS_IOCTL_CMD_GEN_DUMP
Definition: ocs_ioctl.h:496
uint32_t enable_ini
Definition: ocs_ioctl.h:233
OCS_IOCTL_CMD_VPORT ioctl structure.
Definition: ocs_ioctl.h:231
DRIVER_INFO ioctl structure.
Definition: ocs_ioctl.h:60
uint32_t domain_index
Definition: ocs_ioctl.h:232
uint32_t req_create
Definition: ocs_ioctl.h:233
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
int ocs_gen_dump(ocs_t *ocs)
Definition: ocs_gendump.c:246