Deleted Added
full compact
ctl_frontend.c (274962) ctl_frontend.c (275942)
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: head/sys/cam/ctl/ctl_frontend.c 274962 2014-11-24 11:37:27Z mav $");
39__FBSDID("$FreeBSD: head/sys/cam/ctl/ctl_frontend.c 275942 2014-12-19 20:35:06Z 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>

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

63#include <cam/ctl/ctl_private.h>
64#include <cam/ctl/ctl_debug.h>
65
66extern struct ctl_softc *control_softc;
67
68int
69ctl_frontend_register(struct ctl_frontend *fe)
70{
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>

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

63#include <cam/ctl/ctl_private.h>
64#include <cam/ctl/ctl_debug.h>
65
66extern struct ctl_softc *control_softc;
67
68int
69ctl_frontend_register(struct ctl_frontend *fe)
70{
71 struct ctl_softc *softc = control_softc;
71 struct ctl_frontend *fe_tmp;
72
72 struct ctl_frontend *fe_tmp;
73
73 KASSERT(control_softc != NULL, ("CTL is not initialized"));
74 KASSERT(softc != NULL, ("CTL is not initialized"));
74
75 /*
76 * Sanity check, make sure this isn't a duplicate registration.
77 */
75
76 /*
77 * Sanity check, make sure this isn't a duplicate registration.
78 */
78 mtx_lock(&control_softc->ctl_lock);
79 STAILQ_FOREACH(fe_tmp, &control_softc->fe_list, links) {
79 mtx_lock(&softc->ctl_lock);
80 STAILQ_FOREACH(fe_tmp, &softc->fe_list, links) {
80 if (strcmp(fe_tmp->name, fe->name) == 0) {
81 if (strcmp(fe_tmp->name, fe->name) == 0) {
81 mtx_unlock(&control_softc->ctl_lock);
82 mtx_unlock(&softc->ctl_lock);
82 return (-1);
83 }
84 }
83 return (-1);
84 }
85 }
85 mtx_unlock(&control_softc->ctl_lock);
86 mtx_unlock(&softc->ctl_lock);
86 STAILQ_INIT(&fe->port_list);
87
88 /*
89 * Call the frontend's initialization routine.
90 */
91 if (fe->init != NULL)
92 fe->init();
93
87 STAILQ_INIT(&fe->port_list);
88
89 /*
90 * Call the frontend's initialization routine.
91 */
92 if (fe->init != NULL)
93 fe->init();
94
94 mtx_lock(&control_softc->ctl_lock);
95 control_softc->num_frontends++;
96 STAILQ_INSERT_TAIL(&control_softc->fe_list, fe, links);
97 mtx_unlock(&control_softc->ctl_lock);
95 mtx_lock(&softc->ctl_lock);
96 softc->num_frontends++;
97 STAILQ_INSERT_TAIL(&softc->fe_list, fe, links);
98 mtx_unlock(&softc->ctl_lock);
98 return (0);
99}
100
101int
102ctl_frontend_deregister(struct ctl_frontend *fe)
103{
99 return (0);
100}
101
102int
103ctl_frontend_deregister(struct ctl_frontend *fe)
104{
105 struct ctl_softc *softc = control_softc;
104
105 if (!STAILQ_EMPTY(&fe->port_list))
106 return (-1);
107
106
107 if (!STAILQ_EMPTY(&fe->port_list))
108 return (-1);
109
108 mtx_lock(&control_softc->ctl_lock);
109 STAILQ_REMOVE(&control_softc->fe_list, fe, ctl_frontend, links);
110 control_softc->num_frontends--;
111 mtx_unlock(&control_softc->ctl_lock);
110 mtx_lock(&softc->ctl_lock);
111 STAILQ_REMOVE(&softc->fe_list, fe, ctl_frontend, links);
112 softc->num_frontends--;
113 mtx_unlock(&softc->ctl_lock);
112
113 /*
114 * Call the frontend's shutdown routine.
115 */
116 if (fe->shutdown != NULL)
117 fe->shutdown();
118 return (0);
119}
120
121struct ctl_frontend *
122ctl_frontend_find(char *frontend_name)
123{
114
115 /*
116 * Call the frontend's shutdown routine.
117 */
118 if (fe->shutdown != NULL)
119 fe->shutdown();
120 return (0);
121}
122
123struct ctl_frontend *
124ctl_frontend_find(char *frontend_name)
125{
124 struct ctl_softc *ctl_softc = control_softc;
126 struct ctl_softc *softc = control_softc;
125 struct ctl_frontend *fe;
126
127 struct ctl_frontend *fe;
128
127 mtx_lock(&ctl_softc->ctl_lock);
128 STAILQ_FOREACH(fe, &ctl_softc->fe_list, links) {
129 mtx_lock(&softc->ctl_lock);
130 STAILQ_FOREACH(fe, &softc->fe_list, links) {
129 if (strcmp(fe->name, frontend_name) == 0) {
131 if (strcmp(fe->name, frontend_name) == 0) {
130 mtx_unlock(&ctl_softc->ctl_lock);
132 mtx_unlock(&softc->ctl_lock);
131 return (fe);
132 }
133 }
133 return (fe);
134 }
135 }
134 mtx_unlock(&ctl_softc->ctl_lock);
136 mtx_unlock(&softc->ctl_lock);
135 return (NULL);
136}
137
138int
139ctl_port_register(struct ctl_port *port)
140{
137 return (NULL);
138}
139
140int
141ctl_port_register(struct ctl_port *port)
142{
143 struct ctl_softc *softc = control_softc;
141 void *pool;
142 int port_num;
143 int retval;
144
145 retval = 0;
146
144 void *pool;
145 int port_num;
146 int retval;
147
148 retval = 0;
149
147 KASSERT(control_softc != NULL, ("CTL is not initialized"));
150 KASSERT(softc != NULL, ("CTL is not initialized"));
148
151
149 mtx_lock(&control_softc->ctl_lock);
150 port_num = ctl_ffz(control_softc->ctl_port_mask, CTL_MAX_PORTS);
152 mtx_lock(&softc->ctl_lock);
153 port_num = ctl_ffz(softc->ctl_port_mask, CTL_MAX_PORTS);
151 if ((port_num == -1)
154 if ((port_num == -1)
152 || (ctl_set_mask(control_softc->ctl_port_mask, port_num) == -1)) {
155 || (ctl_set_mask(softc->ctl_port_mask, port_num) == -1)) {
153 port->targ_port = -1;
156 port->targ_port = -1;
154 mtx_unlock(&control_softc->ctl_lock);
157 mtx_unlock(&softc->ctl_lock);
155 return (1);
156 }
158 return (1);
159 }
157 control_softc->num_ports++;
158 mtx_unlock(&control_softc->ctl_lock);
160 softc->num_ports++;
161 mtx_unlock(&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) {

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

171 /*
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 */
162
163 /*
164 * Initialize the initiator and portname mappings
165 */
166 port->max_initiators = CTL_MAX_INIT_PER_PORT;
167 port->wwpn_iid = malloc(sizeof(*port->wwpn_iid) * port->max_initiators,
168 M_CTL, M_NOWAIT | M_ZERO);
169 if (port->wwpn_iid == NULL) {

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

174 /*
175 * We add 20 to whatever the caller requests, so he doesn't get
176 * burned by queueing things back to the pending sense queue. In
177 * theory, there should probably only be one outstanding item, at
178 * most, on the pending sense queue for a LUN. We'll clear the
179 * pending sense queue on the next command, whether or not it is
180 * a REQUEST SENSE.
181 */
179 retval = ctl_pool_create(control_softc, port->port_name,
182 retval = ctl_pool_create(softc, port->port_name,
180 port->num_requested_ctl_io + 20, &pool);
181 if (retval != 0) {
182 free(port->wwpn_iid, M_CTL);
183error:
184 port->targ_port = -1;
183 port->num_requested_ctl_io + 20, &pool);
184 if (retval != 0) {
185 free(port->wwpn_iid, M_CTL);
186error:
187 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 mtx_lock(&softc->ctl_lock);
189 ctl_clear_mask(softc->ctl_port_mask, port_num);
190 mtx_unlock(&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
191 return (retval);
192 }
193 port->ctl_pool_ref = pool;
194
195 if (port->options.stqh_first == NULL)
196 STAILQ_INIT(&port->options);
197
195 mtx_lock(&control_softc->ctl_lock);
196 port->targ_port = port_num + control_softc->port_offset;
198 mtx_lock(&softc->ctl_lock);
199 port->targ_port = port_num + softc->port_offset;
197 STAILQ_INSERT_TAIL(&port->frontend->port_list, port, fe_links);
200 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 STAILQ_INSERT_TAIL(&softc->port_list, port, links);
202 softc->ctl_ports[port_num] = port;
203 mtx_unlock(&softc->ctl_lock);
201
202 return (retval);
203}
204
205int
206ctl_port_deregister(struct ctl_port *port)
207{
204
205 return (retval);
206}
207
208int
209ctl_port_deregister(struct ctl_port *port)
210{
211 struct ctl_softc *softc = control_softc;
208 struct ctl_io_pool *pool;
209 int port_num, retval, i;
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;
218 }
219
212 struct ctl_io_pool *pool;
213 int port_num, retval, i;
214
215 retval = 0;
216
217 pool = (struct ctl_io_pool *)port->ctl_pool_ref;
218
219 if (port->targ_port == -1) {
220 retval = 1;
221 goto bailout;
222 }
223
220 mtx_lock(&control_softc->ctl_lock);
221 STAILQ_REMOVE(&control_softc->port_list, port, ctl_port, links);
224 mtx_lock(&softc->ctl_lock);
225 STAILQ_REMOVE(&softc->port_list, port, ctl_port, links);
222 STAILQ_REMOVE(&port->frontend->port_list, port, ctl_port, fe_links);
226 STAILQ_REMOVE(&port->frontend->port_list, port, ctl_port, fe_links);
223 control_softc->num_ports--;
227 softc->num_ports--;
224 port_num = (port->targ_port < CTL_MAX_PORTS) ? port->targ_port :
225 port->targ_port - CTL_MAX_PORTS;
228 port_num = (port->targ_port < CTL_MAX_PORTS) ? port->targ_port :
229 port->targ_port - CTL_MAX_PORTS;
226 ctl_clear_mask(control_softc->ctl_port_mask, port_num);
227 control_softc->ctl_ports[port_num] = NULL;
228 mtx_unlock(&control_softc->ctl_lock);
230 ctl_clear_mask(softc->ctl_port_mask, port_num);
231 softc->ctl_ports[port_num] = NULL;
232 mtx_unlock(&softc->ctl_lock);
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;

--- 78 unchanged lines hidden ---
233
234 ctl_pool_free(pool);
235 ctl_free_opts(&port->options);
236
237 free(port->port_devid, M_CTL);
238 port->port_devid = NULL;
239 free(port->target_devid, M_CTL);
240 port->target_devid = NULL;

--- 78 unchanged lines hidden ---