Deleted Added
full compact
ctl_frontend.c (268683) ctl_frontend.c (268692)
1/*-
2 * Copyright (c) 2003 Silicon Graphics International Corp.
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
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 22 unchanged lines hidden (view full) ---

31 */
32/*
33 * CAM Target Layer front end interface code
34 *
35 * Author: Ken Merry <ken@FreeBSD.org>
36 */
37
38#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2003 Silicon Graphics International Corp.
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
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 22 unchanged lines hidden (view full) ---

31 */
32/*
33 * CAM Target Layer front end interface code
34 *
35 * Author: Ken Merry <ken@FreeBSD.org>
36 */
37
38#include <sys/cdefs.h>
39__FBSDID("$FreeBSD: stable/10/sys/cam/ctl/ctl_frontend.c 268683 2014-07-15 17:06:10Z mav $");
39__FBSDID("$FreeBSD: stable/10/sys/cam/ctl/ctl_frontend.c 268692 2014-07-15 17:14:53Z mav $");
40
41#include <sys/param.h>
42#include <sys/systm.h>
43#include <sys/kernel.h>
44#include <sys/types.h>
45#include <sys/malloc.h>
46#include <sys/lock.h>
47#include <sys/mutex.h>

--- 105 unchanged lines hidden (view full) ---

153 port->targ_port = -1;
154 mtx_unlock(&control_softc->ctl_lock);
155 return (1);
156 }
157 control_softc->num_ports++;
158 mtx_unlock(&control_softc->ctl_lock);
159
160 /*
40
41#include <sys/param.h>
42#include <sys/systm.h>
43#include <sys/kernel.h>
44#include <sys/types.h>
45#include <sys/malloc.h>
46#include <sys/lock.h>
47#include <sys/mutex.h>

--- 105 unchanged lines hidden (view full) ---

153 port->targ_port = -1;
154 mtx_unlock(&control_softc->ctl_lock);
155 return (1);
156 }
157 control_softc->num_ports++;
158 mtx_unlock(&control_softc->ctl_lock);
159
160 /*
161 * Initialize the initiator and portname mappings
162 */
163 port->max_initiators = CTL_MAX_INIT_PER_PORT;
164 port->wwpn_iid = malloc(sizeof(*port->wwpn_iid) * port->max_initiators,
165 M_CTL, M_NOWAIT | M_ZERO);
166 if (port->wwpn_iid == NULL) {
167 retval = ENOMEM;
168 goto error;
169 }
170
171 /*
161 * We add 20 to whatever the caller requests, so he doesn't get
162 * burned by queueing things back to the pending sense queue. In
163 * theory, there should probably only be one outstanding item, at
164 * most, on the pending sense queue for a LUN. We'll clear the
165 * pending sense queue on the next command, whether or not it is
166 * a REQUEST SENSE.
167 */
168 retval = ctl_pool_create(control_softc, CTL_POOL_FETD,
169 port->num_requested_ctl_io + 20, &pool);
170 if (retval != 0) {
172 * We add 20 to whatever the caller requests, so he doesn't get
173 * burned by queueing things back to the pending sense queue. In
174 * theory, there should probably only be one outstanding item, at
175 * most, on the pending sense queue for a LUN. We'll clear the
176 * pending sense queue on the next command, whether or not it is
177 * a REQUEST SENSE.
178 */
179 retval = ctl_pool_create(control_softc, CTL_POOL_FETD,
180 port->num_requested_ctl_io + 20, &pool);
181 if (retval != 0) {
182 free(port->wwpn_iid, M_CTL);
183error:
171 port->targ_port = -1;
172 mtx_lock(&control_softc->ctl_lock);
173 ctl_clear_mask(&control_softc->ctl_port_mask, port_num);
174 mtx_unlock(&control_softc->ctl_lock);
175 return (retval);
176 }
177 port->ctl_pool_ref = pool;
178
179 if (port->options.stqh_first == NULL)
180 STAILQ_INIT(&port->options);
181
182 mtx_lock(&control_softc->ctl_lock);
183 port->targ_port = port_num + (master_shelf != 0 ? 0 : CTL_MAX_PORTS);
184 port->targ_port = -1;
185 mtx_lock(&control_softc->ctl_lock);
186 ctl_clear_mask(&control_softc->ctl_port_mask, port_num);
187 mtx_unlock(&control_softc->ctl_lock);
188 return (retval);
189 }
190 port->ctl_pool_ref = pool;
191
192 if (port->options.stqh_first == NULL)
193 STAILQ_INIT(&port->options);
194
195 mtx_lock(&control_softc->ctl_lock);
196 port->targ_port = port_num + (master_shelf != 0 ? 0 : CTL_MAX_PORTS);
184 port->max_initiators = CTL_MAX_INIT_PER_PORT;
185 STAILQ_INSERT_TAIL(&port->frontend->port_list, port, fe_links);
186 STAILQ_INSERT_TAIL(&control_softc->port_list, port, links);
187 control_softc->ctl_ports[port_num] = port;
188 mtx_unlock(&control_softc->ctl_lock);
189
190 return (retval);
191}
192
193int
194ctl_port_deregister(struct ctl_port *port)
195{
196 struct ctl_io_pool *pool;
197 STAILQ_INSERT_TAIL(&port->frontend->port_list, port, fe_links);
198 STAILQ_INSERT_TAIL(&control_softc->port_list, port, links);
199 control_softc->ctl_ports[port_num] = port;
200 mtx_unlock(&control_softc->ctl_lock);
201
202 return (retval);
203}
204
205int
206ctl_port_deregister(struct ctl_port *port)
207{
208 struct ctl_io_pool *pool;
197 int port_num;
198 int retval;
209 int port_num, retval, i;
199
200 retval = 0;
201
202 pool = (struct ctl_io_pool *)port->ctl_pool_ref;
203
204 if (port->targ_port == -1) {
205 retval = 1;
206 goto bailout;

--- 11 unchanged lines hidden (view full) ---

218
219 ctl_pool_free(pool);
220 ctl_free_opts(&port->options);
221
222 free(port->port_devid, M_CTL);
223 port->port_devid = NULL;
224 free(port->target_devid, M_CTL);
225 port->target_devid = NULL;
210
211 retval = 0;
212
213 pool = (struct ctl_io_pool *)port->ctl_pool_ref;
214
215 if (port->targ_port == -1) {
216 retval = 1;
217 goto bailout;

--- 11 unchanged lines hidden (view full) ---

229
230 ctl_pool_free(pool);
231 ctl_free_opts(&port->options);
232
233 free(port->port_devid, M_CTL);
234 port->port_devid = NULL;
235 free(port->target_devid, M_CTL);
236 port->target_devid = NULL;
237 for (i = 0; i < port->max_initiators; i++)
238 free(port->wwpn_iid[i].name, M_CTL);
239 free(port->wwpn_iid, M_CTL);
226
227bailout:
228 return (retval);
229}
230
231void
232ctl_port_set_wwns(struct ctl_port *port, int wwnn_valid, uint64_t wwnn,
233 int wwpn_valid, uint64_t wwpn)

--- 65 unchanged lines hidden ---
240
241bailout:
242 return (retval);
243}
244
245void
246ctl_port_set_wwns(struct ctl_port *port, int wwnn_valid, uint64_t wwnn,
247 int wwpn_valid, uint64_t wwpn)

--- 65 unchanged lines hidden ---