Lines Matching +full:port +full:-

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
5 * Copyright (c) 2014-2017 Alexander Motin <mav@FreeBSD.org>
33 * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_frontend.c#4 $
77 mtx_lock(&softc->ctl_lock); in ctl_frontend_register()
78 STAILQ_FOREACH(fe_tmp, &softc->fe_list, links) { in ctl_frontend_register()
79 if (strcmp(fe_tmp->name, fe->name) == 0) { in ctl_frontend_register()
80 mtx_unlock(&softc->ctl_lock); in ctl_frontend_register()
81 return (-1); in ctl_frontend_register()
84 mtx_unlock(&softc->ctl_lock); in ctl_frontend_register()
85 STAILQ_INIT(&fe->port_list); in ctl_frontend_register()
88 if (fe->init != NULL) { in ctl_frontend_register()
89 if ((error = fe->init()) != 0) { in ctl_frontend_register()
91 fe->name, error); in ctl_frontend_register()
96 mtx_lock(&softc->ctl_lock); in ctl_frontend_register()
97 softc->num_frontends++; in ctl_frontend_register()
98 STAILQ_INSERT_TAIL(&softc->fe_list, fe, links); in ctl_frontend_register()
99 mtx_unlock(&softc->ctl_lock); in ctl_frontend_register()
110 if (fe->shutdown != NULL) { in ctl_frontend_deregister()
111 if ((error = fe->shutdown()) != 0) { in ctl_frontend_deregister()
113 fe->name, error); in ctl_frontend_deregister()
118 mtx_lock(&softc->ctl_lock); in ctl_frontend_deregister()
119 STAILQ_REMOVE(&softc->fe_list, fe, ctl_frontend, links); in ctl_frontend_deregister()
120 softc->num_frontends--; in ctl_frontend_deregister()
121 mtx_unlock(&softc->ctl_lock); in ctl_frontend_deregister()
131 mtx_lock(&softc->ctl_lock); in ctl_frontend_find()
132 STAILQ_FOREACH(fe, &softc->fe_list, links) { in ctl_frontend_find()
133 if (strcmp(fe->name, frontend_name) == 0) { in ctl_frontend_find()
134 mtx_unlock(&softc->ctl_lock); in ctl_frontend_find()
138 mtx_unlock(&softc->ctl_lock); in ctl_frontend_find()
143 ctl_port_register(struct ctl_port *port) in ctl_port_register() argument
152 port->ctl_softc = softc; in ctl_port_register()
154 mtx_lock(&softc->ctl_lock); in ctl_port_register()
155 if (port->targ_port >= 0) in ctl_port_register()
156 port_num = port->targ_port; in ctl_port_register()
158 port_num = ctl_ffz(softc->ctl_port_mask, in ctl_port_register()
159 softc->port_min, softc->port_max); in ctl_port_register()
161 (ctl_set_mask(softc->ctl_port_mask, port_num) < 0)) { in ctl_port_register()
162 mtx_unlock(&softc->ctl_lock); in ctl_port_register()
165 softc->num_ports++; in ctl_port_register()
166 mtx_unlock(&softc->ctl_lock); in ctl_port_register()
171 port->max_initiators = CTL_MAX_INIT_PER_PORT; in ctl_port_register()
172 port->wwpn_iid = malloc(sizeof(*port->wwpn_iid) * port->max_initiators, in ctl_port_register()
174 if (port->wwpn_iid == NULL) { in ctl_port_register()
187 retval = ctl_pool_create(softc, port->port_name, in ctl_port_register()
188 port->num_requested_ctl_io + 20, &pool); in ctl_port_register()
190 free(port->wwpn_iid, M_CTL); in ctl_port_register()
192 port->targ_port = -1; in ctl_port_register()
193 mtx_lock(&softc->ctl_lock); in ctl_port_register()
194 ctl_clear_mask(softc->ctl_port_mask, port_num); in ctl_port_register()
195 mtx_unlock(&softc->ctl_lock); in ctl_port_register()
198 port->targ_port = port_num; in ctl_port_register()
199 port->ctl_pool_ref = pool; in ctl_port_register()
200 if (port->options == NULL) in ctl_port_register()
201 port->options = nvlist_create(0); in ctl_port_register()
202 port->stats.item = port_num; in ctl_port_register()
203 mtx_init(&port->port_lock, "CTL port", NULL, MTX_DEF); in ctl_port_register()
205 mtx_lock(&softc->ctl_lock); in ctl_port_register()
206 STAILQ_INSERT_TAIL(&port->frontend->port_list, port, fe_links); in ctl_port_register()
207 for (tport = NULL, nport = STAILQ_FIRST(&softc->port_list); in ctl_port_register()
208 nport != NULL && nport->targ_port < port_num; in ctl_port_register()
212 STAILQ_INSERT_AFTER(&softc->port_list, tport, port, links); in ctl_port_register()
214 STAILQ_INSERT_HEAD(&softc->port_list, port, links); in ctl_port_register()
215 softc->ctl_ports[port->targ_port] = port; in ctl_port_register()
216 mtx_unlock(&softc->ctl_lock); in ctl_port_register()
222 ctl_port_deregister(struct ctl_port *port) in ctl_port_deregister() argument
224 struct ctl_softc *softc = port->ctl_softc; in ctl_port_deregister()
225 struct ctl_io_pool *pool = (struct ctl_io_pool *)port->ctl_pool_ref; in ctl_port_deregister()
228 if (port->targ_port == -1) in ctl_port_deregister()
231 mtx_lock(&softc->ctl_lock); in ctl_port_deregister()
232 STAILQ_REMOVE(&softc->port_list, port, ctl_port, links); in ctl_port_deregister()
233 STAILQ_REMOVE(&port->frontend->port_list, port, ctl_port, fe_links); in ctl_port_deregister()
234 softc->num_ports--; in ctl_port_deregister()
235 ctl_clear_mask(softc->ctl_port_mask, port->targ_port); in ctl_port_deregister()
236 softc->ctl_ports[port->targ_port] = NULL; in ctl_port_deregister()
237 mtx_unlock(&softc->ctl_lock); in ctl_port_deregister()
240 nvlist_destroy(port->options); in ctl_port_deregister()
242 ctl_lun_map_deinit(port); in ctl_port_deregister()
243 free(port->port_devid, M_CTL); in ctl_port_deregister()
244 port->port_devid = NULL; in ctl_port_deregister()
245 free(port->target_devid, M_CTL); in ctl_port_deregister()
246 port->target_devid = NULL; in ctl_port_deregister()
247 free(port->init_devid, M_CTL); in ctl_port_deregister()
248 port->init_devid = NULL; in ctl_port_deregister()
249 for (i = 0; i < port->max_initiators; i++) in ctl_port_deregister()
250 free(port->wwpn_iid[i].name, M_CTL); in ctl_port_deregister()
251 free(port->wwpn_iid, M_CTL); in ctl_port_deregister()
252 mtx_destroy(&port->port_lock); in ctl_port_deregister()
258 ctl_port_set_wwns(struct ctl_port *port, int wwnn_valid, uint64_t wwnn, in ctl_port_set_wwns() argument
264 if (port->port_type == CTL_PORT_FC) in ctl_port_set_wwns()
266 else if (port->port_type == CTL_PORT_SAS) in ctl_port_set_wwns()
268 else if (port->port_type == CTL_PORT_ISCSI) in ctl_port_set_wwns()
274 port->wwnn = wwnn; in ctl_port_set_wwns()
276 free(port->target_devid, M_CTL); in ctl_port_set_wwns()
279 port->target_devid = malloc(sizeof(struct ctl_devid) + len, in ctl_port_set_wwns()
281 port->target_devid->len = len; in ctl_port_set_wwns()
282 desc = (struct scsi_vpd_id_descriptor *)port->target_devid->data; in ctl_port_set_wwns()
283 desc->proto_codeset = proto | SVPD_ID_CODESET_BINARY; in ctl_port_set_wwns()
284 desc->id_type = SVPD_ID_PIV | SVPD_ID_ASSOC_TARGET | in ctl_port_set_wwns()
286 desc->length = CTL_WWPN_LEN; in ctl_port_set_wwns()
287 scsi_u64to8b(port->wwnn, desc->identifier); in ctl_port_set_wwns()
291 port->wwpn = wwpn; in ctl_port_set_wwns()
293 free(port->port_devid, M_CTL); in ctl_port_set_wwns()
296 port->port_devid = malloc(sizeof(struct ctl_devid) + len, in ctl_port_set_wwns()
298 port->port_devid->len = len; in ctl_port_set_wwns()
299 desc = (struct scsi_vpd_id_descriptor *)port->port_devid->data; in ctl_port_set_wwns()
300 desc->proto_codeset = proto | SVPD_ID_CODESET_BINARY; in ctl_port_set_wwns()
301 desc->id_type = SVPD_ID_PIV | SVPD_ID_ASSOC_PORT | in ctl_port_set_wwns()
303 desc->length = CTL_WWPN_LEN; in ctl_port_set_wwns()
304 scsi_u64to8b(port->wwpn, desc->identifier); in ctl_port_set_wwns()
309 ctl_port_online(struct ctl_port *port) in ctl_port_online() argument
311 struct ctl_softc *softc = port->ctl_softc; in ctl_port_online()
316 if (port->lun_enable != NULL) { in ctl_port_online()
317 if (port->lun_map) { in ctl_port_online()
318 for (l = 0; l < port->lun_map_size; l++) { in ctl_port_online()
319 if (ctl_lun_map_from_port(port, l) == in ctl_port_online()
322 port->lun_enable(port->targ_lun_arg, l); in ctl_port_online()
325 STAILQ_FOREACH(lun, &softc->lun_list, links) in ctl_port_online()
326 port->lun_enable(port->targ_lun_arg, lun->lun); in ctl_port_online()
329 if (port->port_online != NULL) in ctl_port_online()
330 port->port_online(port->onoff_arg); in ctl_port_online()
331 mtx_lock(&softc->ctl_lock); in ctl_port_online()
332 if (softc->is_single == 0) { in ctl_port_online()
333 value = dnvlist_get_string(port->options, "ha_shared", NULL); in ctl_port_online()
335 port->status |= CTL_PORT_STATUS_HA_SHARED; in ctl_port_online()
337 port->status &= ~CTL_PORT_STATUS_HA_SHARED; in ctl_port_online()
339 port->status |= CTL_PORT_STATUS_ONLINE; in ctl_port_online()
340 STAILQ_FOREACH(lun, &softc->lun_list, links) { in ctl_port_online()
341 if (ctl_lun_map_to_port(port, lun->lun) == UINT32_MAX) in ctl_port_online()
343 mtx_lock(&lun->lun_lock); in ctl_port_online()
344 ctl_est_ua_all(lun, -1, CTL_UA_INQ_CHANGE); in ctl_port_online()
345 mtx_unlock(&lun->lun_lock); in ctl_port_online()
347 mtx_unlock(&softc->ctl_lock); in ctl_port_online()
348 ctl_isc_announce_port(port); in ctl_port_online()
352 ctl_port_offline(struct ctl_port *port) in ctl_port_offline() argument
354 struct ctl_softc *softc = port->ctl_softc; in ctl_port_offline()
358 if (port->port_offline != NULL) in ctl_port_offline()
359 port->port_offline(port->onoff_arg); in ctl_port_offline()
360 if (port->lun_disable != NULL) { in ctl_port_offline()
361 if (port->lun_map) { in ctl_port_offline()
362 for (l = 0; l < port->lun_map_size; l++) { in ctl_port_offline()
363 if (ctl_lun_map_from_port(port, l) == in ctl_port_offline()
366 port->lun_disable(port->targ_lun_arg, l); in ctl_port_offline()
369 STAILQ_FOREACH(lun, &softc->lun_list, links) in ctl_port_offline()
370 port->lun_disable(port->targ_lun_arg, lun->lun); in ctl_port_offline()
373 mtx_lock(&softc->ctl_lock); in ctl_port_offline()
374 port->status &= ~CTL_PORT_STATUS_ONLINE; in ctl_port_offline()
375 STAILQ_FOREACH(lun, &softc->lun_list, links) { in ctl_port_offline()
376 if (ctl_lun_map_to_port(port, lun->lun) == UINT32_MAX) in ctl_port_offline()
378 mtx_lock(&lun->lun_lock); in ctl_port_offline()
379 ctl_est_ua_all(lun, -1, CTL_UA_INQ_CHANGE); in ctl_port_offline()
380 mtx_unlock(&lun->lun_lock); in ctl_port_offline()
382 mtx_unlock(&softc->ctl_lock); in ctl_port_offline()
383 ctl_isc_announce_port(port); in ctl_port_offline()