FreeBSD kernel CAM code
scsi_enc_ses.c
Go to the documentation of this file.
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2000 Matthew Jacob
5 * Copyright (c) 2010 Spectra Logic Corporation
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions, and the following disclaimer,
13 * without modification, immediately at the beginning of the file.
14 * 2. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
36#include <sys/cdefs.h>
37__FBSDID("$FreeBSD$");
38
39#include <sys/param.h>
40
41#include <sys/ctype.h>
42#include <sys/errno.h>
43#include <sys/kernel.h>
44#include <sys/lock.h>
45#include <sys/malloc.h>
46#include <sys/mutex.h>
47#include <sys/queue.h>
48#include <sys/sbuf.h>
49#include <sys/sx.h>
50#include <sys/systm.h>
51#include <sys/types.h>
52
53#include <cam/cam.h>
54#include <cam/cam_ccb.h>
55#include <cam/cam_xpt_periph.h>
56#include <cam/cam_periph.h>
57
59#include <cam/scsi/scsi_enc.h>
61
62/* SES Native Type Device Support */
63
64/* SES Diagnostic Page Codes */
65typedef enum {
75 SesArrayControl = 0x6, /* Obsolete in SES v2 */
82
83typedef struct ses_type {
84 const struct ses_elm_type_desc *hdr;
85 const char *text;
87
88typedef struct ses_comstat {
89 uint8_t comstatus;
90 uint8_t comstat[3];
92
93typedef union ses_addl_data {
97 struct ses_fcobj_port *fc_ports;
99
100typedef struct ses_addl_status {
102 union {
103 union ses_fcobj_hdr *fc;
107 union ses_addl_data proto_data; /* array sizes stored in header */
109
110typedef struct ses_element {
111 uint8_t eip; /* eip bit is set */
112 uint16_t descr_len; /* length of the descriptor */
113 const char *descr; /* descriptor for this object */
114 struct ses_addl_status addl; /* additional status info */
116
117typedef struct ses_control_request {
121 TAILQ_ENTRY(ses_control_request) links;
123TAILQ_HEAD(ses_control_reqlist, ses_control_request);
124typedef struct ses_control_reqlist ses_control_reqlist_t;
125enum {
128
129static void
131{
133
134 while ((req = TAILQ_FIRST(reqlist)) != NULL) {
135 TAILQ_REMOVE(reqlist, req, links);
136 req->result = result;
137 wakeup(req);
138 }
139}
140
151
157 ITERATOR_INDEX_END = INT_MAX
159
189
191
197
206
218
226
239};
240
241typedef enum {
253
255
256#define SCSZ 0x8000
257
268
270{
271 { "SES_UPDATE_NONE", 0, 0, 0, NULL, NULL, NULL },
272 {
273 "SES_UPDATE_PAGES",
275 SCSZ,
276 60 * 1000,
280 },
281 {
282 "SES_UPDATE_GETCONFIG",
284 SCSZ,
285 60 * 1000,
289 },
290 {
291 "SES_UPDATE_GETSTATUS",
293 SCSZ,
294 60 * 1000,
298 },
299 {
300 "SES_UPDATE_GETELMDESCS",
302 SCSZ,
303 60 * 1000,
307 },
308 {
309 "SES_UPDATE_GETELMADDLSTATUS",
311 SCSZ,
312 60 * 1000,
316 },
317 {
318 "SES_PROCESS_CONTROL_REQS",
320 SCSZ,
321 60 * 1000,
325 },
326 {
327 "SES_PUBLISH_PHYSPATHS",
328 0,
329 0,
330 0,
331 NULL,
333 NULL
334 },
335 {
336 "SES_PUBLISH_CACHE",
337 0,
338 0,
339 0,
340 NULL,
342 NULL
343 }
344};
345
346typedef struct ses_cache {
347 /* Source for all the configuration data pointers */
348 const struct ses_cfg_page *cfg_page;
349
350 /* References into the config page. */
352 const struct ses_enc_desc * const *subencs;
355
356 /* Source for all the status pointers */
358
359 /* Source for all the object descriptor pointers */
361
362 /* Source for all the additional object status pointers */
364
366
367typedef struct ses_softc {
368 uint32_t ses_flags;
369#define SES_FLAG_TIMEDCOMP 0x01
370#define SES_FLAG_ADDLSTATUS 0x02
371#define SES_FLAG_DESC 0x04
372
376
377static int ses_search_globally = 0;
378SYSCTL_INT(_kern_cam_enc, OID_AUTO, search_globally, CTLFLAG_RWTUN,
379 &ses_search_globally, 0, "Search for disks on other buses");
380
391static void
393{
394 /*
395 * Set our indexes to just before the first valid element
396 * of the first type (ITERATOR_INDEX_INVALID == -1). This
397 * simplifies the implementation of ses_iter_next().
398 */
399 iter->type_index = 0;
404}
405
415static void
417{
418 iter->enc = enc;
419 iter->cache = cache;
420 ses_iter_reset(iter);
421}
422
432static enc_element_t *
434{
436 const ses_type_t *element_type;
437
438 ses_cache = iter->cache->private;
439
440 /*
441 * Note: Treat nelms as signed, so we will hit this case
442 * and immediately terminate the iteration if the
443 * configuration has 0 objects.
444 */
445 if (iter->global_element_index >= (int)iter->cache->nelms - 1) {
446 /* Elements exhausted. */
452 return (NULL);
453 }
454
455 KASSERT((iter->type_index < ses_cache->ses_ntypes),
456 ("Corrupted element iterator. %d not less than %d",
458
459 element_type = &ses_cache->ses_types[iter->type_index];
460 iter->global_element_index++;
461 iter->type_element_index++;
462
463 /*
464 * There is an object for overal type status in addition
465 * to one for each allowed element, but only if the element
466 * count is non-zero.
467 */
468 if (iter->type_element_index > element_type->hdr->etype_maxelt) {
469 /*
470 * We've exhausted the elements of this type.
471 * This next element belongs to the next type.
472 */
473 iter->type_index++;
474 iter->type_element_index = 0;
476 }
477
478 if (iter->type_element_index > 0) {
481 }
482
483 return (&iter->cache->elm_map[iter->global_element_index]);
484}
485
489typedef enum {
495
505
517static enc_element_t *
518ses_iter_seek_to(struct ses_iterator *iter, int element_index,
519 ses_elem_index_type_t index_type)
520{
521 enc_element_t *element;
522 int *cur_index;
523
524 if (index_type == SES_ELEM_INDEX_GLOBAL)
525 cur_index = &iter->global_element_index;
526 else
527 cur_index = &iter->individual_element_index;
528
529 if (*cur_index == element_index) {
530 /* Already there. */
531 return (&iter->cache->elm_map[iter->global_element_index]);
532 }
533
534 ses_iter_reset(iter);
535 while ((element = ses_iter_next(iter)) != NULL
536 && *cur_index != element_index)
537 ;
538
539 if (*cur_index != element_index)
540 return (NULL);
541
542 return (element);
543}
544
545#if 0
546static int ses_encode(enc_softc_t *, uint8_t *, int, int,
547 struct ses_comstat *);
548#endif
549static int ses_set_timed_completion(enc_softc_t *, uint8_t);
550#if 0
551static int ses_putstatus(enc_softc_t *, int, struct ses_comstat *);
552#endif
553
554static void ses_poll_status(enc_softc_t *);
556
557/*=========================== SES cleanup routines ===========================*/
558
559static void
561{
563 ses_cache_t *other_ses_cache;
564 enc_element_t *cur_elm;
565 enc_element_t *last_elm;
566
567 ENC_DLOG(enc, "%s: enter\n", __func__);
568 ses_cache = cache->private;
569 if (ses_cache->elm_addlstatus_page == NULL)
570 return;
571
572 for (cur_elm = cache->elm_map,
573 last_elm = &cache->elm_map[cache->nelms];
574 cur_elm != last_elm; cur_elm++) {
575 ses_element_t *elmpriv;
576
577 elmpriv = cur_elm->elm_private;
578
579 /* Clear references to the additional status page. */
580 bzero(&elmpriv->addl, sizeof(elmpriv->addl));
581 }
582
583 other_ses_cache = enc_other_cache(enc, cache)->private;
584 if (other_ses_cache->elm_addlstatus_page
588}
589
590static void
592{
594 ses_cache_t *other_ses_cache;
595 enc_element_t *cur_elm;
596 enc_element_t *last_elm;
597
598 ENC_DLOG(enc, "%s: enter\n", __func__);
599 ses_cache = cache->private;
600 if (ses_cache->elm_descs_page == NULL)
601 return;
602
603 for (cur_elm = cache->elm_map,
604 last_elm = &cache->elm_map[cache->nelms];
605 cur_elm != last_elm; cur_elm++) {
606 ses_element_t *elmpriv;
607
608 elmpriv = cur_elm->elm_private;
609 elmpriv->descr_len = 0;
610 elmpriv->descr = NULL;
611 }
612
613 other_ses_cache = enc_other_cache(enc, cache)->private;
614 if (other_ses_cache->elm_descs_page
618}
619
620static void
622{
624 ses_cache_t *other_ses_cache;
625
626 ENC_DLOG(enc, "%s: enter\n", __func__);
627 ses_cache = cache->private;
628 if (ses_cache->status_page == NULL)
629 return;
630
631 other_ses_cache = enc_other_cache(enc, cache)->private;
632 if (other_ses_cache->status_page != ses_cache->status_page)
634 ses_cache->status_page = NULL;
635}
636
637static void
639{
640 enc_element_t *cur_elm;
641 enc_element_t *last_elm;
642
643 ENC_DLOG(enc, "%s: enter\n", __func__);
644 if (cache->elm_map == NULL)
645 return;
646
647 ses_cache_free_elm_descs(enc, cache);
649 for (cur_elm = cache->elm_map,
650 last_elm = &cache->elm_map[cache->nelms];
651 cur_elm != last_elm; cur_elm++) {
653 }
655 cache->nelms = 0;
656 ENC_DLOG(enc, "%s: exit\n", __func__);
657}
658
659static void
661{
662 ses_cache_t *other_ses_cache;
664
665 ENC_DLOG(enc, "%s: enter\n", __func__);
667 ses_cache_free_status(enc, cache);
668 ses_cache_free_elm_map(enc, cache);
669
670 ses_cache = cache->private;
672
673 other_ses_cache = enc_other_cache(enc, cache)->private;
674 if (other_ses_cache->subencs != ses_cache->subencs)
676 ses_cache->subencs = NULL;
677
678 if (other_ses_cache->ses_types != ses_cache->ses_types)
680 ses_cache->ses_types = NULL;
681
682 if (other_ses_cache->cfg_page != ses_cache->cfg_page)
684 ses_cache->cfg_page = NULL;
685
686 ENC_DLOG(enc, "%s: exit\n", __func__);
687}
688
689static void
691{
692 ses_cache_t *dst_ses_cache;
693 ses_cache_t *src_ses_cache;
694 enc_element_t *src_elm;
695 enc_element_t *dst_elm;
696 enc_element_t *last_elm;
697
698 ses_cache_free(enc, dst);
699 src_ses_cache = src->private;
700 dst_ses_cache = dst->private;
701
702 /*
703 * The cloned enclosure cache and ses specific cache are
704 * mostly identical to the source.
705 */
706 *dst = *src;
707 *dst_ses_cache = *src_ses_cache;
708
709 /*
710 * But the ses cache storage is still independent. Restore
711 * the pointer that was clobbered by the structure copy above.
712 */
713 dst->private = dst_ses_cache;
714
715 /*
716 * The element map is independent even though it starts out
717 * pointing to the same constant page data.
718 */
719 dst->elm_map = malloc(dst->nelms * sizeof(enc_element_t),
720 M_SCSIENC, M_WAITOK);
721 memcpy(dst->elm_map, src->elm_map, dst->nelms * sizeof(enc_element_t));
722 for (dst_elm = dst->elm_map, src_elm = src->elm_map,
723 last_elm = &src->elm_map[src->nelms];
724 src_elm != last_elm; src_elm++, dst_elm++) {
725 dst_elm->elm_private = malloc(sizeof(ses_element_t),
726 M_SCSIENC, M_WAITOK);
727 memcpy(dst_elm->elm_private, src_elm->elm_private,
728 sizeof(ses_element_t));
729 }
730}
731
732/* Structure accessors. These are strongly typed to avoid errors. */
733
734int
736{
737 return ((obj)->base_hdr.byte1 >> 6);
738}
739int
741{
742 return ((hdr)->byte0 & 0xf);
743}
744int
746{
747 return ((hdr)->byte0 >> 4 & 0x1);
748}
749int
751{
752 return ((hdr)->byte0 >> 7);
753}
754int
756{
757 return ((hdr)->type0_noneip.byte1 & 0x1);
758}
759int
761{
762 return ((phy)->target_ports & 0x1);
763}
764int
766{
767 return ((phy)->target_ports >> 7);
768}
769int
771{
772 return (((phy)->byte0 >> 4) & 0x7);
773}
774
786static int
788{
789 uint32_t cache_gc;
790 uint32_t cur_gc;
791
792 if (ses_cache->cfg_page == NULL)
793 return (0);
794
796 cur_gc = scsi_4btoul(gen_code);
797 return (cache_gc == cur_gc);
798}
799
804 struct scsi_vpd_id_descriptor *, void *);
805
817static void
819 ses_devid_callback_t *callback, void *callback_arg)
820{
821 ses_element_t *elmpriv;
822 struct ses_addl_status *addl;
823 u_int i;
824 size_t devid_record_size;
825
826 elmpriv = elm->elm_private;
827 addl = &(elmpriv->addl);
828
829 devid_record_size = SVPD_DEVICE_ID_DESC_HDR_LEN
830 + sizeof(struct scsi_vpd_id_naa_ieee_reg);
831 for (i = 0; i < addl->proto_hdr.sas->base_hdr.num_phys; i++) {
832 uint8_t devid_buf[devid_record_size];
833 struct scsi_vpd_id_descriptor *devid;
834 uint8_t *phy_addr;
835
836 devid = (struct scsi_vpd_id_descriptor *)devid_buf;
837 phy_addr = addl->proto_data.sasdev_phys[i].phy_addr;
840 devid->id_type = SVPD_ID_PIV
843 devid->reserved = 0;
844 devid->length = sizeof(struct scsi_vpd_id_naa_ieee_reg);
845 memcpy(devid->identifier, phy_addr, devid->length);
846
847 callback(enc, elm, devid, callback_arg);
848 }
849}
850
855 struct cam_path *, void *);
856
861typedef struct ses_path_iter_args {
865
875static void
877 struct scsi_vpd_id_descriptor *devid,
878 void *arg)
879{
880 struct ccb_dev_match cdm;
883 struct device_match_result *device_match;
884 struct device_match_pattern *device_pattern;
886 struct cam_path *path;
887
888 args = (ses_path_iter_args_t *)arg;
890 device_pattern = &match_pattern.pattern.device_pattern;
891 device_pattern->flags = DEV_MATCH_DEVID;
892 device_pattern->data.devid_pat.id_len =
893 offsetof(struct scsi_vpd_id_descriptor, identifier)
894 + devid->length;
895 memcpy(device_pattern->data.devid_pat.id, devid,
896 device_pattern->data.devid_pat.id_len);
897 if (!ses_search_globally) {
898 device_pattern->flags |= DEV_MATCH_PATH;
899 device_pattern->path_id = xpt_path_path_id(enc->periph->path);
900 }
901
902 memset(&cdm, 0, sizeof(cdm));
903 if (xpt_create_path(&cdm.ccb_h.path, /*periph*/NULL,
907 return;
908
910 cdm.num_patterns = 1;
911 cdm.patterns = &match_pattern;
912 cdm.pattern_buf_len = sizeof(match_pattern);
913 cdm.match_buf_len = sizeof(match_result);
914 cdm.matches = &match_result;
915
916 do {
917 xpt_action((union ccb *)&cdm);
918
919 if ((cdm.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP ||
920 (cdm.status != CAM_DEV_MATCH_LAST &&
921 cdm.status != CAM_DEV_MATCH_MORE) ||
922 cdm.num_matches == 0)
923 break;
924
925 device_match = &match_result.result.device_result;
926 if (xpt_create_path(&path, /*periph*/NULL,
927 device_match->path_id,
928 device_match->target_id,
929 device_match->target_lun) == CAM_REQ_CMP) {
930 args->callback(enc, elem, path, args->callback_arg);
931
932 xpt_free_path(path);
933 }
934 } while (cdm.status == CAM_DEV_MATCH_MORE);
935
937}
938
949static void
951 ses_path_callback_t *callback, void *callback_arg)
952{
953 ses_element_t *elmpriv;
954 struct ses_addl_status *addl;
955
956 elmpriv = elm->elm_private;
957 addl = &(elmpriv->addl);
958
959 if (addl->hdr == NULL)
960 return;
961
962 switch(ses_elm_addlstatus_proto(addl->hdr)) {
963 case SPSP_PROTO_SAS:
964 if (addl->proto_hdr.sas != NULL &&
965 addl->proto_data.sasdev_phys != NULL) {
967
968 args.callback = callback;
969 args.callback_arg = callback_arg;
971 &args);
972 }
973 break;
974 case SPSP_PROTO_ATA:
975 if (addl->proto_hdr.ata != NULL) {
976 struct cam_path *path;
977 struct ccb_getdev cgd;
978
979 if (xpt_create_path(&path, /*periph*/NULL,
981 scsi_4btoul(addl->proto_hdr.ata->target), 0)
982 != CAM_REQ_CMP)
983 return;
984
985 memset(&cgd, 0, sizeof(cgd));
988 xpt_action((union ccb *)&cgd);
989 if (cgd.ccb_h.status == CAM_REQ_CMP)
990 callback(enc, elm, path, callback_arg);
991
992 xpt_free_path(path);
993 }
994 break;
995 }
996}
997
1008static void
1010 struct cam_path *path, void *arg)
1011{
1012 struct sbuf *sb;
1013
1014 sb = (struct sbuf *)arg;
1015 cam_periph_list(path, sb);
1016}
1017
1023 struct sbuf *physpath;
1026
1036static void
1038 struct cam_path *path, void *arg)
1039{
1040 struct ccb_dev_advinfo cdai;
1042 char *old_physpath;
1043
1044 args = (ses_setphyspath_callback_args_t *)arg;
1045 old_physpath = malloc(MAXPATHLEN, M_SCSIENC, M_WAITOK|M_ZERO);
1046 xpt_path_lock(path);
1047 memset(&cdai, 0, sizeof(cdai));
1051 cdai.flags = CDAI_FLAG_NONE;
1052 cdai.bufsiz = MAXPATHLEN;
1053 cdai.buf = old_physpath;
1054 xpt_action((union ccb *)&cdai);
1055 if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
1056 cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
1057
1058 if (strcmp(old_physpath, sbuf_data(args->physpath)) != 0) {
1062 cdai.flags = CDAI_FLAG_STORE;
1063 cdai.bufsiz = sbuf_len(args->physpath);
1064 cdai.buf = sbuf_data(args->physpath);
1065 xpt_action((union ccb *)&cdai);
1066 if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
1067 cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
1068 if (cdai.ccb_h.status == CAM_REQ_CMP)
1069 args->num_set++;
1070 }
1071 xpt_path_unlock(path);
1072 free(old_physpath, M_SCSIENC);
1073}
1074
1084static int
1086 struct ses_iterator *iter)
1087{
1088 struct ccb_dev_advinfo cdai;
1090 int i, ret;
1091 struct sbuf sb;
1092 struct scsi_vpd_id_descriptor *idd;
1093 uint8_t *devid;
1094 ses_element_t *elmpriv;
1095 const char *c;
1096
1097 ret = EIO;
1098 devid = NULL;
1099
1100 elmpriv = elm->elm_private;
1101 if (elmpriv->addl.hdr == NULL)
1102 goto out;
1103
1104 /*
1105 * Assemble the components of the physical path starting with
1106 * the device ID of the enclosure itself.
1107 */
1108 memset(&cdai, 0, sizeof(cdai));
1111 cdai.flags = CDAI_FLAG_NONE;
1114 cdai.buf = devid = malloc(cdai.bufsiz, M_SCSIENC, M_WAITOK|M_ZERO);
1115 cam_periph_lock(enc->periph);
1116 xpt_action((union ccb *)&cdai);
1117 if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
1118 cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
1120 if (cdai.ccb_h.status != CAM_REQ_CMP)
1121 goto out;
1122
1123 idd = scsi_get_devid((struct scsi_vpd_device_id *)cdai.buf,
1125 if (idd == NULL)
1126 goto out;
1127
1128 if (sbuf_new(&sb, NULL, 128, SBUF_AUTOEXTEND) == NULL) {
1129 ret = ENOMEM;
1130 goto out;
1131 }
1132 /* Next, generate the physical path string */
1133 sbuf_printf(&sb, "id1,enc@n%jx/type@%x/slot@%x",
1134 scsi_8btou64(idd->identifier), iter->type_index,
1135 iter->type_element_index);
1136 /* Append the element descriptor if one exists */
1137 if (elmpriv->descr != NULL && elmpriv->descr_len > 0) {
1138 sbuf_cat(&sb, "/elmdesc@");
1139 for (i = 0, c = elmpriv->descr; i < elmpriv->descr_len;
1140 i++, c++) {
1141 if (!isprint(*c) || isspace(*c) || *c == '/')
1142 sbuf_putc(&sb, '_');
1143 else
1144 sbuf_putc(&sb, *c);
1145 }
1146 }
1147 sbuf_finish(&sb);
1148
1149 /*
1150 * Set this physical path on any CAM devices with a device ID
1151 * descriptor that matches one created from the SES additional
1152 * status data for this element.
1153 */
1154 args.physpath= &sb;
1155 args.num_set = 0;
1156 ses_paths_iter(enc, elm, ses_setphyspath_callback, &args);
1157 sbuf_delete(&sb);
1158
1159 ret = args.num_set == 0 ? ENOENT : 0;
1160
1161out:
1162 if (devid != NULL)
1163 ENC_FREE(devid);
1164 return (ret);
1165}
1166
1174static void
1175ses_page_cdb(char *cdb, int bufsiz, SesDiagPageCodes pagenum, int dir)
1176{
1177
1178 /* Ref: SPC-4 r25 Section 6.20 Table 223 */
1179 if (dir == CAM_DIR_IN) {
1180 cdb[0] = RECEIVE_DIAGNOSTIC;
1181 cdb[1] = 1; /* Set page code valid bit */
1182 cdb[2] = pagenum;
1183 } else {
1184 cdb[0] = SEND_DIAGNOSTIC;
1185 cdb[1] = 0x10;
1186 cdb[2] = pagenum;
1187 }
1188 cdb[3] = bufsiz >> 8; /* high bits */
1189 cdb[4] = bufsiz & 0xff; /* low bits */
1190 cdb[5] = 0;
1191}
1192
1203static int
1205{
1206 union ccb *ccb;
1207 struct cam_periph *periph;
1208 struct ses_mgmt_mode_page *mgmt;
1209 uint8_t *mode_buf;
1210 size_t mode_buf_len;
1211 ses_softc_t *ses;
1212
1213 periph = enc->periph;
1214 ses = enc->enc_private;
1216
1217 mode_buf_len = sizeof(struct ses_mgmt_mode_page);
1218 mode_buf = ENC_MALLOCZ(mode_buf_len);
1219 if (mode_buf == NULL)
1220 goto out;
1221
1222 scsi_mode_sense(&ccb->csio, /*retries*/4, NULL, MSG_SIMPLE_Q_TAG,
1224 mode_buf, mode_buf_len, SSD_FULL_SIZE, /*timeout*/60 * 1000);
1225
1226 /*
1227 * Ignore illegal request errors, as they are quite common and we
1228 * will print something out in that case anyway.
1229 */
1231 ENC_FLAGS|SF_QUIET_IR, NULL);
1232 if (ccb->ccb_h.status != CAM_REQ_CMP) {
1233 ENC_VLOG(enc, "Timed Completion Unsupported\n");
1234 goto release;
1235 }
1236
1237 /* Skip the mode select if the desired value is already set */
1238 mgmt = (struct ses_mgmt_mode_page *)mode_buf;
1239 if ((mgmt->byte5 & SES_MGMT_TIMED_COMP_EN) == tc_en)
1240 goto done;
1241
1242 /* Value is not what we wanted, set it */
1243 if (tc_en)
1245 else
1246 mgmt->byte5 &= ~SES_MGMT_TIMED_COMP_EN;
1247 /* SES2r20: a completion time of zero means as long as possible */
1248 bzero(&mgmt->max_comp_time, sizeof(mgmt->max_comp_time));
1249
1251 /*page_fmt*/FALSE, /*save_pages*/TRUE, mode_buf, mode_buf_len,
1252 SSD_FULL_SIZE, /*timeout*/60 * 1000);
1253
1255 if (ccb->ccb_h.status != CAM_REQ_CMP) {
1256 ENC_VLOG(enc, "Timed Completion Set Failed\n");
1257 goto release;
1258 }
1259
1260done:
1261 if ((mgmt->byte5 & SES_MGMT_TIMED_COMP_EN) != 0) {
1262 ENC_LOG(enc, "Timed Completion Enabled\n");
1264 } else {
1265 ENC_LOG(enc, "Timed Completion Disabled\n");
1266 ses->ses_flags &= ~SES_FLAG_TIMEDCOMP;
1267 }
1268release:
1269 ENC_FREE(mode_buf);
1271out:
1272 return (ses->ses_flags & SES_FLAG_TIMEDCOMP);
1273}
1274
1284static int
1286 union ccb *ccb, uint8_t **bufp, int error, int xfer_len)
1287{
1288 ses_softc_t *ses;
1289 struct scsi_diag_page *page;
1290 int err, i, length;
1291
1293 ("entering %s(%p, %d)\n", __func__, bufp, xfer_len));
1294 ses = enc->enc_private;
1295 err = -1;
1296
1297 if (error != 0) {
1298 err = error;
1299 goto out;
1300 }
1301 if (xfer_len < sizeof(*page)) {
1302 ENC_VLOG(enc, "Unable to parse Diag Pages List Header\n");
1303 err = EIO;
1304 goto out;
1305 }
1306 page = (struct scsi_diag_page *)*bufp;
1307 length = scsi_2btoul(page->length);
1308 if (length + offsetof(struct scsi_diag_page, params) > xfer_len) {
1309 ENC_VLOG(enc, "Diag Pages List Too Long\n");
1310 goto out;
1311 }
1312 ENC_DLOG(enc, "%s: page length %d, xfer_len %d\n",
1313 __func__, length, xfer_len);
1314
1315 err = 0;
1316 for (i = 0; i < length; i++) {
1317 if (page->params[i] == SesElementDescriptor)
1318 ses->ses_flags |= SES_FLAG_DESC;
1319 else if (page->params[i] == SesAddlElementStatus)
1321 }
1322
1323out:
1324 ENC_DLOG(enc, "%s: exiting with err %d\n", __func__, err);
1325 return (err);
1326}
1327
1337static int
1339 union ccb *ccb, uint8_t **bufp, int error, int xfer_len)
1340{
1341 struct ses_iterator iter;
1344 uint8_t *buf;
1345 int length;
1346 int err;
1347 int nelm;
1348 int ntype;
1349 struct ses_cfg_page *cfg_page;
1350 struct ses_enc_desc *buf_subenc;
1351 const struct ses_enc_desc **subencs;
1352 const struct ses_enc_desc **cur_subenc;
1353 const struct ses_enc_desc **last_subenc;
1354 ses_type_t *ses_types;
1355 ses_type_t *sestype;
1356 const struct ses_elm_type_desc *cur_buf_type;
1357 const struct ses_elm_type_desc *last_buf_type;
1358 uint8_t *last_valid_byte;
1359 enc_element_t *element;
1360 const char *type_text;
1361
1363 ("entering %s(%p, %d)\n", __func__, bufp, xfer_len));
1366 buf = *bufp;
1367 err = -1;
1368
1369 if (error != 0) {
1370 err = error;
1371 goto out;
1372 }
1373 if (xfer_len < sizeof(cfg_page->hdr)) {
1374 ENC_VLOG(enc, "Unable to parse SES Config Header\n");
1375 err = EIO;
1376 goto out;
1377 }
1378
1379 cfg_page = (struct ses_cfg_page *)buf;
1380 length = ses_page_length(&cfg_page->hdr);
1381 if (length > xfer_len) {
1382 ENC_VLOG(enc, "Enclosure Config Page Too Long\n");
1383 goto out;
1384 }
1385 last_valid_byte = &buf[length - 1];
1386
1387 ENC_DLOG(enc, "%s: total page length %d, xfer_len %d\n",
1388 __func__, length, xfer_len);
1389
1390 err = 0;
1391 if (ses_config_cache_valid(ses_cache, cfg_page->hdr.gen_code)) {
1392 /* Our cache is still valid. Proceed to fetching status. */
1393 goto out;
1394 }
1395
1396 /* Cache is no longer valid. Free old data to make way for new. */
1398 ENC_VLOG(enc, "Generation Code 0x%x has %d SubEnclosures\n",
1399 scsi_4btoul(cfg_page->hdr.gen_code),
1400 ses_cfg_page_get_num_subenc(cfg_page));
1401
1402 /* Take ownership of the buffer. */
1403 ses_cache->cfg_page = cfg_page;
1404 *bufp = NULL;
1405
1406 /*
1407 * Now waltz through all the subenclosures summing the number of
1408 * types available in each.
1409 */
1410 subencs = malloc(ses_cfg_page_get_num_subenc(cfg_page)
1411 * sizeof(*subencs), M_SCSIENC, M_WAITOK|M_ZERO);
1412 /*
1413 * Sub-enclosure data is const after construction (i.e. when
1414 * accessed via our cache object.
1415 *
1416 * The cast here is not required in C++ but C99 is not so
1417 * sophisticated (see C99 6.5.16.1(1)).
1418 */
1421
1422 buf_subenc = cfg_page->subencs;
1423 cur_subenc = subencs;
1424 last_subenc = &subencs[ses_cache->ses_nsubencs - 1];
1425 ntype = 0;
1426 while (cur_subenc <= last_subenc) {
1427 if (!ses_enc_desc_is_complete(buf_subenc, last_valid_byte)) {
1428 ENC_VLOG(enc, "Enclosure %d Beyond End of "
1429 "Descriptors\n", cur_subenc - subencs);
1430 err = EIO;
1431 goto out;
1432 }
1433
1434 ENC_VLOG(enc, " SubEnclosure ID %d, %d Types With this ID, "
1435 "Descriptor Length %d, offset %d\n", buf_subenc->subenc_id,
1436 buf_subenc->num_types, buf_subenc->length,
1437 &buf_subenc->byte0 - buf);
1438 ENC_VLOG(enc, "WWN: %jx\n",
1439 (uintmax_t)scsi_8btou64(buf_subenc->logical_id));
1440
1441 ntype += buf_subenc->num_types;
1442 *cur_subenc = buf_subenc;
1443 cur_subenc++;
1444 buf_subenc = ses_enc_desc_next(buf_subenc);
1445 }
1446
1447 /* Process the type headers. */
1448 ses_types = malloc(ntype * sizeof(*ses_types),
1449 M_SCSIENC, M_WAITOK|M_ZERO);
1450 /*
1451 * Type data is const after construction (i.e. when accessed via
1452 * our cache object.
1453 */
1454 ses_cache->ses_ntypes = ntype;
1455 ses_cache->ses_types = ses_types;
1456
1457 cur_buf_type = (const struct ses_elm_type_desc *)
1458 (&(*last_subenc)->length + (*last_subenc)->length + 1);
1459 last_buf_type = cur_buf_type + ntype - 1;
1460 type_text = (const uint8_t *)(last_buf_type + 1);
1461 nelm = 0;
1462 sestype = ses_types;
1463 while (cur_buf_type <= last_buf_type) {
1464 if (&cur_buf_type->etype_txt_len > last_valid_byte) {
1465 ENC_VLOG(enc, "Runt Enclosure Type Header %d\n",
1466 sestype - ses_types);
1467 err = EIO;
1468 goto out;
1469 }
1470 sestype->hdr = cur_buf_type;
1471 sestype->text = type_text;
1472 type_text += cur_buf_type->etype_txt_len;
1473 ENC_VLOG(enc, " Type Desc[%d]: Type 0x%x, MaxElt %d, In Subenc "
1474 "%d, Text Length %d: %.*s\n", sestype - ses_types,
1475 sestype->hdr->etype_elm_type, sestype->hdr->etype_maxelt,
1476 sestype->hdr->etype_subenc, sestype->hdr->etype_txt_len,
1477 sestype->hdr->etype_txt_len, sestype->text);
1478
1479 nelm += sestype->hdr->etype_maxelt
1480 + /*overall status element*/1;
1481 sestype++;
1482 cur_buf_type++;
1483 }
1484
1485 /* Create the object map. */
1486 enc_cache->elm_map = malloc(nelm * sizeof(enc_element_t),
1487 M_SCSIENC, M_WAITOK|M_ZERO);
1488 enc_cache->nelms = nelm;
1489
1490 ses_iter_init(enc, enc_cache, &iter);
1491 while ((element = ses_iter_next(&iter)) != NULL) {
1492 const struct ses_elm_type_desc *thdr;
1493
1494 ENC_DLOG(enc, "%s: checking obj %d(%d,%d)\n", __func__,
1495 iter.global_element_index, iter.type_index, nelm,
1496 iter.type_element_index);
1497 thdr = ses_cache->ses_types[iter.type_index].hdr;
1498 element->elm_idx = iter.global_element_index;
1499 element->elm_type = thdr->etype_elm_type;
1500 element->subenclosure = thdr->etype_subenc;
1501 element->type_elm_idx = iter.type_element_index;
1502 element->elm_private = malloc(sizeof(ses_element_t),
1503 M_SCSIENC, M_WAITOK|M_ZERO);
1504 ENC_DLOG(enc, "%s: creating elmpriv %d(%d,%d) subenc %d "
1505 "type 0x%x\n", __func__, iter.global_element_index,
1506 iter.type_index, iter.type_element_index,
1507 thdr->etype_subenc, thdr->etype_elm_type);
1508 }
1509
1510 err = 0;
1511
1512out:
1513 if (err)
1515 else {
1516 ses_poll_status(enc);
1518 }
1519 ENC_DLOG(enc, "%s: exiting with err %d\n", __func__, err);
1520 return (err);
1521}
1522
1532static int
1534 union ccb *ccb, uint8_t **bufp, int error, int xfer_len)
1535{
1536 struct ses_iterator iter;
1537 enc_element_t *element;
1538 ses_softc_t *ses;
1541 uint8_t *buf;
1542 int err = -1;
1543 int length;
1544 struct ses_status_page *page;
1545 union ses_status_element *cur_stat;
1546 union ses_status_element *last_stat;
1547
1548 ses = enc->enc_private;
1551 buf = *bufp;
1552
1553 ENC_DLOG(enc, "%s: enter (%p, %p, %d)\n", __func__, enc, buf, xfer_len);
1554 page = (struct ses_status_page *)buf;
1555 length = ses_page_length(&page->hdr);
1556
1557 if (error != 0) {
1558 err = error;
1559 goto out;
1560 }
1561 /*
1562 * Make sure the length fits in the buffer.
1563 *
1564 * XXX all this means is that the page is larger than the space
1565 * we allocated. Since we use a statically sized buffer, this
1566 * could happen... Need to use dynamic discovery of the size.
1567 */
1568 if (length > xfer_len) {
1569 ENC_VLOG(enc, "Enclosure Status Page Too Long\n");
1570 goto out;
1571 }
1572
1573 /* Check for simple enclosure reporting short enclosure status. */
1574 if (length >= 4 && page->hdr.page_code == SesShortStatus) {
1575 ENC_DLOG(enc, "Got Short Enclosure Status page\n");
1580 err = 0;
1581 goto out;
1582 }
1583
1584 /* Make sure the length contains at least one header and status */
1585 if (length < (sizeof(*page) + sizeof(*page->elements))) {
1586 ENC_VLOG(enc, "Enclosure Status Page Too Short\n");
1587 goto out;
1588 }
1589
1591 ENC_DLOG(enc, "%s: Generation count change detected\n",
1592 __func__);
1594 goto out;
1595 }
1596
1598 ses_cache->status_page = page;
1599 *bufp = NULL;
1600
1602
1603 /*
1604 * Read in individual element status. The element order
1605 * matches the order reported in the config page (i.e. the
1606 * order of an unfiltered iteration of the config objects)..
1607 */
1608 ses_iter_init(enc, enc_cache, &iter);
1609 cur_stat = page->elements;
1610 last_stat = (union ses_status_element *)
1611 &buf[length - sizeof(*last_stat)];
1612 ENC_DLOG(enc, "%s: total page length %d, xfer_len %d\n",
1613 __func__, length, xfer_len);
1614 while (cur_stat <= last_stat
1615 && (element = ses_iter_next(&iter)) != NULL) {
1616 ENC_DLOG(enc, "%s: obj %d(%d,%d) off=0x%tx status=%jx\n",
1617 __func__, iter.global_element_index, iter.type_index,
1618 iter.type_element_index, (uint8_t *)cur_stat - buf,
1619 scsi_4btoul(cur_stat->bytes));
1620
1621 memcpy(&element->encstat, cur_stat, sizeof(element->encstat));
1622 element->svalid = 1;
1623 cur_stat++;
1624 }
1625
1626 if (ses_iter_next(&iter) != NULL) {
1627 ENC_VLOG(enc, "Status page, length insufficient for "
1628 "expected number of objects\n");
1629 } else {
1630 if (cur_stat <= last_stat)
1631 ENC_VLOG(enc, "Status page, exhausted objects before "
1632 "exhausing page\n");
1634 err = 0;
1635 }
1636out:
1637 ENC_DLOG(enc, "%s: exiting with error %d\n", __func__, err);
1638 return (err);
1639}
1640
1641typedef enum {
1652
1658
1665
1678{
1681
1684 switch(ses_cache->ses_types[typidx].hdr->etype_elm_type) {
1685 case ELMTYP_DEVICE:
1686 case ELMTYP_ARRAY_DEV:
1687 case ELMTYP_SAS_EXP:
1689 case ELMTYP_SCSI_INI:
1690 case ELMTYP_SCSI_TGT:
1691 case ELMTYP_ESCC:
1692 return (TYPE_ADDLSTATUS_OPTIONAL);
1693 default:
1694 /* No additional status information available. */
1695 break;
1696 }
1697 return (TYPE_ADDLSTATUS_NONE);
1698}
1699
1701 uint8_t *, int);
1702static int ses_get_elm_addlstatus_sas(enc_softc_t *, enc_cache_t *, uint8_t *,
1703 int, int, int, int);
1704static int ses_get_elm_addlstatus_ata(enc_softc_t *, enc_cache_t *, uint8_t *,
1705 int, int, int, int);
1706
1717static int
1719 union ccb *ccb, uint8_t **bufp, int error, int xfer_len)
1720{
1721 struct ses_iterator iter, titer;
1722 int eip;
1723 int err;
1724 int length;
1725 int offset;
1728 uint8_t *buf;
1729 ses_element_t *elmpriv;
1730 const struct ses_page_hdr *hdr;
1731 enc_element_t *element, *telement;
1732
1735 buf = *bufp;
1736 err = -1;
1737
1738 if (error != 0) {
1739 err = error;
1740 goto out;
1741 }
1744 (struct ses_addl_elem_status_page *)buf;
1745 *bufp = NULL;
1746
1747 /*
1748 * The objects appear in the same order here as in Enclosure Status,
1749 * which itself is ordered by the Type Descriptors from the Config
1750 * page. However, it is necessary to skip elements that are not
1751 * supported by this page when counting them.
1752 */
1754 length = ses_page_length(hdr);
1755 ENC_DLOG(enc, "Additional Element Status Page Length 0x%x\n", length);
1756 /* Make sure the length includes at least one header. */
1757 if (length < sizeof(*hdr)+sizeof(struct ses_elm_addlstatus_base_hdr)) {
1758 ENC_VLOG(enc, "Runt Additional Element Status Page\n");
1759 goto out;
1760 }
1761 if (length > xfer_len) {
1762 ENC_VLOG(enc, "Additional Element Status Page Too Long\n");
1763 goto out;
1764 }
1765
1767 ENC_DLOG(enc, "%s: Generation count change detected\n",
1768 __func__);
1770 goto out;
1771 }
1772
1773 offset = sizeof(struct ses_page_hdr);
1774 ses_iter_init(enc, enc_cache, &iter);
1775 while (offset < length
1776 && (element = ses_iter_next(&iter)) != NULL) {
1777 struct ses_elm_addlstatus_base_hdr *elm_hdr;
1778 int proto_info_len;
1779 ses_addlstatus_avail_t status_type;
1780
1781 /*
1782 * Additional element status is only provided for
1783 * individual elements (i.e. overal status elements
1784 * are excluded) and those of the types specified
1785 * in the SES spec.
1786 */
1787 status_type = ses_typehasaddlstatus(enc, iter.type_index);
1789 || status_type == TYPE_ADDLSTATUS_NONE)
1790 continue;
1791
1792 elm_hdr = (struct ses_elm_addlstatus_base_hdr *)&buf[offset];
1793 eip = ses_elm_addlstatus_eip(elm_hdr);
1794 if (eip) {
1795 struct ses_elm_addlstatus_eip_hdr *eip_hdr;
1796 int expected_index, index;
1797 ses_elem_index_type_t index_type;
1798
1799 eip_hdr = (struct ses_elm_addlstatus_eip_hdr *)elm_hdr;
1800 if (SES_ADDL_EIP_EIIOE_EI_GLOB(eip_hdr->byte2)) {
1801 index_type = SES_ELEM_INDEX_GLOBAL;
1802 expected_index = iter.global_element_index;
1803 } else {
1804 index_type = SES_ELEM_INDEX_INDIVIDUAL;
1805 expected_index = iter.individual_element_index;
1806 }
1807 if (eip_hdr->element_index < expected_index) {
1808 ENC_VLOG(enc, "%s: provided %selement index "
1809 "%d is lower then expected %d\n",
1811 eip_hdr->byte2) ? "global " : "",
1812 eip_hdr->element_index, expected_index);
1813 goto badindex;
1814 }
1815 titer = iter;
1816 telement = ses_iter_seek_to(&titer,
1817 eip_hdr->element_index, index_type);
1818 if (telement == NULL) {
1819 ENC_VLOG(enc, "%s: provided %selement index "
1820 "%d does not exist\n", __func__,
1822 "global " : "", eip_hdr->element_index);
1823 goto badindex;
1824 }
1825 if (ses_typehasaddlstatus(enc, titer.type_index) ==
1827 ENC_VLOG(enc, "%s: provided %selement index "
1828 "%d can't have additional status\n",
1829 __func__,
1831 "global " : "", eip_hdr->element_index);
1832badindex:
1833 /*
1834 * If we expected mandatory element, we may
1835 * guess it was just a wrong index and we may
1836 * use the status. If element was optional,
1837 * then we have no idea where status belongs.
1838 */
1839 if (status_type == TYPE_ADDLSTATUS_OPTIONAL)
1840 break;
1841 } else {
1842 iter = titer;
1843 element = telement;
1844 }
1845
1846 if (SES_ADDL_EIP_EIIOE_EI_GLOB(eip_hdr->byte2))
1847 index = iter.global_element_index;
1848 else
1849 index = iter.individual_element_index;
1850 if (index > expected_index
1851 && status_type == TYPE_ADDLSTATUS_MANDATORY) {
1852 ENC_VLOG(enc, "%s: provided %s element"
1853 "index %d skips mandatory status "
1854 " element at index %d\n",
1856 eip_hdr->byte2) ? "global " : "",
1857 index, expected_index);
1858 }
1859 }
1860 elmpriv = element->elm_private;
1861 ENC_DLOG(enc, "%s: global element index=%d, type index=%d "
1862 "type element index=%d, offset=0x%x, "
1863 "byte0=0x%x, length=0x%x\n", __func__,
1865 iter.type_element_index, offset, elm_hdr->byte0,
1866 elm_hdr->length);
1867
1868 /* Skip to after the length field */
1869 offset += sizeof(struct ses_elm_addlstatus_base_hdr);
1870
1871 /* Make sure the descriptor is within bounds */
1872 if ((offset + elm_hdr->length) > length) {
1873 ENC_VLOG(enc, "Element %d Beyond End "
1874 "of Additional Element Status Descriptors\n",
1876 break;
1877 }
1878
1879 /* Skip elements marked as invalid. */
1880 if (ses_elm_addlstatus_invalid(elm_hdr)) {
1881 offset += elm_hdr->length;
1882 continue;
1883 }
1884 elmpriv->addl.hdr = elm_hdr;
1885
1886 /* Advance to the protocol data, skipping eip bytes if needed */
1887 offset += (eip * SES_EIP_HDR_EXTRA_LEN);
1888 proto_info_len = elm_hdr->length
1889 - (eip * SES_EIP_HDR_EXTRA_LEN);
1890
1891 /* Errors in this block are ignored as they are non-fatal */
1892 switch(ses_elm_addlstatus_proto(elm_hdr)) {
1893 case SPSP_PROTO_FC:
1894 if (elm_hdr->length == 0)
1895 break;
1897 &buf[offset], proto_info_len);
1898 break;
1899 case SPSP_PROTO_SAS:
1900 if (elm_hdr->length <= 2)
1901 break;
1903 &buf[offset],
1904 proto_info_len,
1905 eip, iter.type_index,
1907 break;
1908 case SPSP_PROTO_ATA:
1910 &buf[offset],
1911 proto_info_len,
1912 eip, iter.type_index,
1914 break;
1915 default:
1916 ENC_VLOG(enc, "Element %d: Unknown Additional Element "
1917 "Protocol 0x%x\n", iter.global_element_index,
1918 ses_elm_addlstatus_proto(elm_hdr));
1919 break;
1920 }
1921
1922 offset += proto_info_len;
1923 }
1924 err = 0;
1925out:
1926 if (err)
1930 return (err);
1931}
1932
1933static int
1935 union ccb *ccb, uint8_t **bufp, int error, int xfer_len)
1936{
1937 ses_softc_t *ses;
1938
1939 ses = enc->enc_private;
1940 /*
1941 * Possible errors:
1942 * o Generation count wrong.
1943 * o Some SCSI status error.
1944 */
1946 ses_poll_status(enc);
1947 return (0);
1948}
1949
1950static int
1952 union ccb *ccb, uint8_t **bufp, int error, int xfer_len)
1953{
1954 struct ses_iterator iter;
1956 enc_element_t *element;
1957
1959
1960 ses_iter_init(enc, enc_cache, &iter);
1961 while ((element = ses_iter_next(&iter)) != NULL) {
1962 /*
1963 * ses_set_physpath() returns success if we changed
1964 * the physpath of any element. This allows us to
1965 * only announce devices once regardless of how
1966 * many times we process additional element status.
1967 */
1968 if (ses_set_physpath(enc, element, &iter) == 0)
1969 ses_print_addl_data(enc, element);
1970 }
1971
1972 return (0);
1973}
1974
1975static int
1977 union ccb *ccb, uint8_t **bufp, int error, int xfer_len)
1978{
1979
1980 sx_xlock(&enc->enc_cache_lock);
1982 /*dst*/&enc->enc_cache);
1983 sx_xunlock(&enc->enc_cache_lock);
1984
1985 return (0);
1986}
1987
1988/*
1989 * \brief Sanitize an element descriptor
1990 *
1991 * The SES4r3 standard, sections 3.1.2 and 6.1.10, specifies that element
1992 * descriptors may only contain ASCII characters in the range 0x20 to 0x7e.
1993 * But some vendors violate that rule. Ensure that we only expose compliant
1994 * descriptors to userland.
1995 *
1996 * \param desc SES element descriptor as reported by the hardware
1997 * \param len Length of desc in bytes, not necessarily including
1998 * trailing NUL. It will be modified if desc is invalid.
1999 */
2000static const char*
2001ses_sanitize_elm_desc(const char *desc, uint16_t *len)
2002{
2003 const char *invalid = "<invalid>";
2004 int i;
2005
2006 for (i = 0; i < *len; i++) {
2007 if (desc[i] == 0) {
2008 break;
2009 } else if (desc[i] < 0x20 || desc[i] > 0x7e) {
2010 *len = strlen(invalid);
2011 return (invalid);
2012 }
2013 }
2014 return (desc);
2015}
2016
2026static int
2028 union ccb *ccb, uint8_t **bufp, int error, int xfer_len)
2029{
2030 ses_softc_t *ses;
2031 struct ses_iterator iter;
2032 enc_element_t *element;
2033 int err;
2034 int offset;
2035 u_long length, plength;
2038 uint8_t *buf;
2039 ses_element_t *elmpriv;
2040 const struct ses_page_hdr *phdr;
2041 const struct ses_elm_desc_hdr *hdr;
2042
2043 ses = enc->enc_private;
2046 buf = *bufp;
2047 err = -1;
2048
2049 if (error != 0) {
2050 err = error;
2051 goto out;
2052 }
2055 *bufp = NULL;
2056
2057 phdr = &ses_cache->elm_descs_page->hdr;
2058 plength = ses_page_length(phdr);
2059 if (xfer_len < sizeof(struct ses_page_hdr)) {
2060 ENC_VLOG(enc, "Runt Element Descriptor Page\n");
2061 goto out;
2062 }
2063 if (plength > xfer_len) {
2064 ENC_VLOG(enc, "Element Descriptor Page Too Long\n");
2065 goto out;
2066 }
2067
2069 ENC_VLOG(enc, "%s: Generation count change detected\n",
2070 __func__);
2072 goto out;
2073 }
2074
2075 offset = sizeof(struct ses_page_hdr);
2076
2077 ses_iter_init(enc, enc_cache, &iter);
2078 while (offset < plength
2079 && (element = ses_iter_next(&iter)) != NULL) {
2080 if ((offset + sizeof(struct ses_elm_desc_hdr)) > plength) {
2081 ENC_VLOG(enc, "Element %d Descriptor Header Past "
2082 "End of Buffer\n", iter.global_element_index);
2083 goto out;
2084 }
2085 hdr = (struct ses_elm_desc_hdr *)&buf[offset];
2086 length = scsi_2btoul(hdr->length);
2087 ENC_DLOG(enc, "%s: obj %d(%d,%d) length=%d off=%d\n", __func__,
2089 iter.type_element_index, length, offset);
2090 if ((offset + sizeof(*hdr) + length) > plength) {
2091 ENC_VLOG(enc, "Element%d Descriptor Past "
2092 "End of Buffer\n", iter.global_element_index);
2093 goto out;
2094 }
2095 offset += sizeof(*hdr);
2096
2097 if (length > 0) {
2098 elmpriv = element->elm_private;
2099 elmpriv->descr_len = length;
2100 elmpriv->descr = ses_sanitize_elm_desc(&buf[offset],
2101 &elmpriv->descr_len);
2102 }
2103
2104 /* skip over the descriptor itself */
2105 offset += length;
2106 }
2107
2108 err = 0;
2109out:
2110 if (err == 0) {
2111 if (ses->ses_flags & SES_FLAG_ADDLSTATUS)
2113 }
2115 return (err);
2116}
2117
2118static int
2120 union ccb *ccb, uint8_t *buf)
2121{
2122
2123 if (enc->enc_type == ENC_SEMB_SES) {
2125 NULL, MSG_SIMPLE_Q_TAG, /*pcv*/1,
2126 state->page_code, buf, state->buf_size,
2127 state->timeout);
2128 } else {
2130 NULL, MSG_SIMPLE_Q_TAG, /*pcv*/1,
2131 state->page_code, buf, state->buf_size,
2132 SSD_FULL_SIZE, state->timeout);
2133 }
2134 return (0);
2135}
2136
2150static int
2151ses_encode(enc_softc_t *enc, uint8_t *buf, int amt, ses_control_request_t *req)
2152{
2153 struct ses_iterator iter;
2154 enc_element_t *element;
2155 int offset;
2156 struct ses_control_page_hdr *hdr;
2157
2158 ses_iter_init(enc, &enc->enc_cache, &iter);
2159 hdr = (struct ses_control_page_hdr *)buf;
2160 if (req->elm_idx == -1) {
2161 /* for enclosure status, at least 2 bytes are needed */
2162 if (amt < 2)
2163 return EIO;
2164 hdr->control_flags =
2166 ENC_DLOG(enc, "Set EncStat %x\n", hdr->control_flags);
2167 return (0);
2168 }
2169
2170 element = ses_iter_seek_to(&iter, req->elm_idx, SES_ELEM_INDEX_GLOBAL);
2171 if (element == NULL)
2172 return (ENXIO);
2173
2174 /*
2175 * Seek to the type set that corresponds to the requested object.
2176 * The +1 is for the overall status element for the type.
2177 */
2178 offset = sizeof(struct ses_control_page_hdr)
2179 + (iter.global_element_index * sizeof(struct ses_comstat));
2180
2181 /* Check for buffer overflow. */
2182 if (offset + sizeof(struct ses_comstat) > amt)
2183 return (EIO);
2184
2185 /* Set the status. */
2186 memcpy(&buf[offset], &req->elm_stat, sizeof(struct ses_comstat));
2187
2188 ENC_DLOG(enc, "Set Type 0x%x Obj 0x%x (offset %d) with %x %x %x %x\n",
2189 iter.type_index, iter.global_element_index, offset,
2190 req->elm_stat.comstatus, req->elm_stat.comstat[0],
2191 req->elm_stat.comstat[1], req->elm_stat.comstat[2]);
2192
2193 return (0);
2194}
2195
2196static int
2198 union ccb *ccb, uint8_t *buf)
2199{
2200 ses_softc_t *ses;
2203 struct ses_control_page_hdr *hdr;
2205 size_t plength;
2206 size_t offset;
2207
2208 ses = enc->enc_private;
2211 hdr = (struct ses_control_page_hdr *)buf;
2212
2213 if (ses_cache->status_page == NULL) {
2215 return (EIO);
2216 }
2217
2219 memcpy(buf, ses_cache->status_page, plength);
2220
2221 /* Disable the select bits in all status entries. */
2222 offset = sizeof(struct ses_control_page_hdr);
2223 for (offset = sizeof(struct ses_control_page_hdr);
2224 offset < plength; offset += sizeof(struct ses_comstat)) {
2225 buf[offset] &= ~SESCTL_CSEL;
2226 }
2227
2228 /* And make sure the INVOP bit is clear. */
2229 hdr->control_flags &= ~SES_ENCSTAT_INVOP;
2230
2231 /* Apply incoming requests. */
2232 while ((req = TAILQ_FIRST(&ses->ses_requests)) != NULL) {
2233 TAILQ_REMOVE(&ses->ses_requests, req, links);
2234 req->result = ses_encode(enc, buf, plength, req);
2235 if (req->result != 0) {
2236 wakeup(req);
2237 continue;
2238 }
2239 TAILQ_INSERT_TAIL(&ses->ses_pending_requests, req, links);
2240 }
2241
2242 if (TAILQ_EMPTY(&ses->ses_pending_requests) != 0)
2243 return (ENOENT);
2244
2245 /* Fill out the ccb */
2246 if (enc->enc_type == ENC_SEMB_SES) {
2247 semb_send_diagnostic(&ccb->ataio, /*retries*/5, NULL,
2248 MSG_SIMPLE_Q_TAG,
2249 buf, ses_page_length(&ses_cache->status_page->hdr),
2250 state->timeout);
2251 } else {
2252 scsi_send_diagnostic(&ccb->csio, /*retries*/5, NULL,
2253 MSG_SIMPLE_Q_TAG, /*unit_offline*/0,
2254 /*device_offline*/0, /*self_test*/0,
2255 /*page_format*/1, /*self_test_code*/0,
2256 buf, ses_page_length(&ses_cache->status_page->hdr),
2257 SSD_FULL_SIZE, state->timeout);
2258 }
2259 return (0);
2260}
2261
2262static int
2264 uint8_t *buf, int bufsiz)
2265{
2266 ENC_VLOG(enc, "FC Device Support Stubbed in Additional Status Page\n");
2267 return (ENODEV);
2268}
2269
2270#define SES_PRINT_PORTS(p, type) do { \
2271 if (((p) & SES_SASOBJ_DEV_PHY_PROTOMASK) != 0) { \
2272 sbuf_printf(sbp, " %s (", type); \
2273 if ((p) & SES_SASOBJ_DEV_PHY_SMP) \
2274 sbuf_printf(sbp, " SMP"); \
2275 if ((p) & SES_SASOBJ_DEV_PHY_STP) \
2276 sbuf_printf(sbp, " STP"); \
2277 if ((p) & SES_SASOBJ_DEV_PHY_SSP) \
2278 sbuf_printf(sbp, " SSP"); \
2279 sbuf_printf(sbp, " )"); \
2280 } \
2281} while(0)
2282
2291static void
2292ses_print_addl_data_sas_type0(char *sesname, struct sbuf *sbp,
2293 enc_element_t *obj)
2294{
2295 int i;
2296 ses_element_t *elmpriv;
2297 struct ses_addl_status *addl;
2298 struct ses_elm_sas_device_phy *phy;
2299
2300 elmpriv = obj->elm_private;
2301 addl = &(elmpriv->addl);
2302 sbuf_printf(sbp, ", SAS Slot: %d%s phys",
2304 ses_elm_sas_type0_not_all_phys(addl->proto_hdr.sas) ? "+" : "");
2305 if (ses_elm_addlstatus_eip(addl->hdr))
2306 sbuf_printf(sbp, " at slot %d",
2308 sbuf_printf(sbp, "\n");
2309 if (addl->proto_data.sasdev_phys == NULL)
2310 return;
2311 for (i = 0;i < addl->proto_hdr.sas->base_hdr.num_phys;i++) {
2312 phy = &addl->proto_data.sasdev_phys[i];
2313 sbuf_printf(sbp, "%s: phy %d:", sesname, i);
2315 /* Spec says all other fields are specific values */
2316 sbuf_printf(sbp, " SATA device\n");
2317 else {
2318 sbuf_printf(sbp, " SAS device type %d phy %d",
2320 SES_PRINT_PORTS(phy->initiator_ports, "Initiator");
2321 SES_PRINT_PORTS(phy->target_ports, "Target");
2322 sbuf_printf(sbp, "\n");
2323 }
2324 sbuf_printf(sbp, "%s: phy %d: parent %jx addr %jx\n",
2325 sesname, i,
2326 (uintmax_t)scsi_8btou64(phy->parent_addr),
2327 (uintmax_t)scsi_8btou64(phy->phy_addr));
2328 }
2329}
2330#undef SES_PRINT_PORTS
2331
2340static void
2341ses_print_addl_data_sas_type1(char *sesname, struct sbuf *sbp,
2342 enc_element_t *obj)
2343{
2344 int i, num_phys;
2345 ses_element_t *elmpriv;
2346 struct ses_addl_status *addl;
2347 struct ses_elm_sas_expander_phy *exp_phy;
2348 struct ses_elm_sas_port_phy *port_phy;
2349
2350 elmpriv = obj->elm_private;
2351 addl = &(elmpriv->addl);
2352 sbuf_printf(sbp, ", SAS ");
2353 if (obj->elm_type == ELMTYP_SAS_EXP) {
2354 num_phys = addl->proto_hdr.sas->base_hdr.num_phys;
2355 sbuf_printf(sbp, "Expander: %d phys", num_phys);
2356 if (addl->proto_data.sasexp_phys == NULL)
2357 return;
2358 for (i = 0;i < num_phys;i++) {
2359 exp_phy = &addl->proto_data.sasexp_phys[i];
2360 sbuf_printf(sbp, "%s: phy %d: connector %d other %d\n",
2361 sesname, i, exp_phy->connector_index,
2362 exp_phy->other_index);
2363 }
2364 } else {
2365 num_phys = addl->proto_hdr.sas->base_hdr.num_phys;
2366 sbuf_printf(sbp, "Port: %d phys", num_phys);
2367 if (addl->proto_data.sasport_phys == NULL)
2368 return;
2369 for (i = 0;i < num_phys;i++) {
2370 port_phy = &addl->proto_data.sasport_phys[i];
2371 sbuf_printf(sbp,
2372 "%s: phy %d: id %d connector %d other %d\n",
2373 sesname, i, port_phy->phy_id,
2374 port_phy->connector_index, port_phy->other_index);
2375 sbuf_printf(sbp, "%s: phy %d: addr %jx\n", sesname, i,
2376 (uintmax_t)scsi_8btou64(port_phy->phy_addr));
2377 }
2378 }
2379}
2380
2388static void
2390{
2391 ses_element_t *elmpriv = obj->elm_private;
2392 struct ses_addl_status *addl = &elmpriv->addl;
2393 struct ses_elm_ata_hdr *ata = addl->proto_hdr.ata;
2394
2395 sbuf_printf(sbp, ", SATA Slot: scbus%d target %d\n",
2396 scsi_4btoul(ata->bus), scsi_4btoul(ata->target));
2397}
2398
2405static void
2407{
2408 ses_element_t *elmpriv;
2409 struct ses_addl_status *addl;
2410 struct sbuf sesname, name, out;
2411
2412 elmpriv = obj->elm_private;
2413 if (elmpriv == NULL)
2414 return;
2415
2416 addl = &(elmpriv->addl);
2417 if (addl->hdr == NULL)
2418 return;
2419
2420 sbuf_new(&sesname, NULL, 16, SBUF_AUTOEXTEND);
2421 sbuf_new(&name, NULL, 16, SBUF_AUTOEXTEND);
2422 sbuf_new(&out, NULL, 512, SBUF_AUTOEXTEND);
2423 ses_paths_iter(enc, obj, ses_elmdevname_callback, &name);
2424 if (sbuf_len(&name) == 0)
2425 sbuf_printf(&name, "(none)");
2426 sbuf_finish(&name);
2427 sbuf_printf(&sesname, "%s%d", enc->periph->periph_name,
2428 enc->periph->unit_number);
2429 sbuf_finish(&sesname);
2430 sbuf_printf(&out, "%s: %s in ", sbuf_data(&sesname), sbuf_data(&name));
2431 if (elmpriv->descr != NULL)
2432 sbuf_printf(&out, "'%s'", elmpriv->descr);
2433 else {
2434 if (obj->elm_type <= ELMTYP_LAST)
2435 sbuf_cat(&out, elm_type_names[obj->elm_type]);
2436 else
2437 sbuf_printf(&out, "<Type 0x%02x>", obj->elm_type);
2438 sbuf_printf(&out, " %d", obj->type_elm_idx);
2439 if (obj->subenclosure != 0)
2440 sbuf_printf(&out, " of subenc %d", obj->subenclosure);
2441 }
2442 switch(ses_elm_addlstatus_proto(addl->hdr)) {
2443 case SPSP_PROTO_FC:
2444 goto noaddl; /* stubbed for now */
2445 case SPSP_PROTO_SAS:
2446 if (addl->proto_hdr.sas == NULL)
2447 goto noaddl;
2448 switch(ses_elm_sas_descr_type(addl->proto_hdr.sas)) {
2450 ses_print_addl_data_sas_type0(sbuf_data(&sesname),
2451 &out, obj);
2452 break;
2454 ses_print_addl_data_sas_type1(sbuf_data(&sesname),
2455 &out, obj);
2456 break;
2457 default:
2458 goto noaddl;
2459 }
2460 break;
2461 case SPSP_PROTO_ATA:
2462 if (addl->proto_hdr.ata == NULL)
2463 goto noaddl;
2464 ses_print_addl_data_ata(&out, obj);
2465 break;
2466 default:
2467noaddl:
2468 sbuf_cat(&out, "\n");
2469 break;
2470 }
2471 sbuf_finish(&out);
2472 printf("%s", sbuf_data(&out));
2473 sbuf_delete(&out);
2474 sbuf_delete(&name);
2475 sbuf_delete(&sesname);
2476}
2477
2490static int
2492 uint8_t *buf, int bufsiz, int eip, int nobj)
2493{
2494 int err, offset, physz;
2495 enc_element_t *obj;
2496 ses_element_t *elmpriv;
2497 struct ses_addl_status *addl;
2498
2499 err = offset = 0;
2500
2501 /* basic object setup */
2502 obj = &(enc_cache->elm_map[nobj]);
2503 elmpriv = obj->elm_private;
2504 addl = &(elmpriv->addl);
2505
2506 addl->proto_hdr.sas = (union ses_elm_sas_hdr *)&buf[offset];
2507
2508 /* Don't assume this object has any phys */
2509 bzero(&addl->proto_data, sizeof(addl->proto_data));
2510 if (addl->proto_hdr.sas->base_hdr.num_phys == 0)
2511 goto out;
2512
2513 /* Skip forward to the phy list */
2514 if (eip)
2515 offset += sizeof(struct ses_elm_sas_type0_eip_hdr);
2516 else
2517 offset += sizeof(struct ses_elm_sas_type0_base_hdr);
2518
2519 /* Make sure the phy list fits in the buffer */
2520 physz = addl->proto_hdr.sas->base_hdr.num_phys;
2521 physz *= sizeof(struct ses_elm_sas_device_phy);
2522 if (physz > (bufsiz - offset + 4)) {
2523 ENC_VLOG(enc, "Element %d Device Phy List Beyond End Of Buffer\n",
2524 nobj);
2525 err = EIO;
2526 goto out;
2527 }
2528
2529 /* Point to the phy list */
2530 addl->proto_data.sasdev_phys =
2531 (struct ses_elm_sas_device_phy *)&buf[offset];
2532
2533out:
2534 return (err);
2535}
2536
2549static int
2551 uint8_t *buf, int bufsiz, int eip, int nobj)
2552{
2553 int err, offset, physz;
2554 enc_element_t *obj;
2555 ses_element_t *elmpriv;
2556 struct ses_addl_status *addl;
2557
2558 err = offset = 0;
2559
2560 /* basic object setup */
2561 obj = &(enc_cache->elm_map[nobj]);
2562 elmpriv = obj->elm_private;
2563 addl = &(elmpriv->addl);
2564
2565 addl->proto_hdr.sas = (union ses_elm_sas_hdr *)&buf[offset];
2566
2567 /* Don't assume this object has any phys */
2568 bzero(&addl->proto_data, sizeof(addl->proto_data));
2569 if (addl->proto_hdr.sas->base_hdr.num_phys == 0)
2570 goto out;
2571
2572 /* Process expanders differently from other type1 cases */
2573 if (obj->elm_type == ELMTYP_SAS_EXP) {
2574 offset += sizeof(struct ses_elm_sas_type1_expander_hdr);
2575 physz = addl->proto_hdr.sas->base_hdr.num_phys *
2576 sizeof(struct ses_elm_sas_expander_phy);
2577 if (physz > (bufsiz - offset)) {
2578 ENC_VLOG(enc, "Element %d: Expander Phy List Beyond "
2579 "End Of Buffer\n", nobj);
2580 err = EIO;
2581 goto out;
2582 }
2583 addl->proto_data.sasexp_phys =
2584 (struct ses_elm_sas_expander_phy *)&buf[offset];
2585 } else {
2586 offset += sizeof(struct ses_elm_sas_type1_nonexpander_hdr);
2587 physz = addl->proto_hdr.sas->base_hdr.num_phys *
2588 sizeof(struct ses_elm_sas_port_phy);
2589 if (physz > (bufsiz - offset + 4)) {
2590 ENC_VLOG(enc, "Element %d: Port Phy List Beyond End "
2591 "Of Buffer\n", nobj);
2592 err = EIO;
2593 goto out;
2594 }
2595 addl->proto_data.sasport_phys =
2596 (struct ses_elm_sas_port_phy *)&buf[offset];
2597 }
2598
2599out:
2600 return (err);
2601}
2602
2616static int
2618 uint8_t *buf, int bufsiz, int eip, int tidx,
2619 int nobj)
2620{
2621 int dtype, err;
2623 union ses_elm_sas_hdr *hdr;
2624
2625 /* Need to be able to read the descriptor type! */
2626 if (bufsiz < sizeof(union ses_elm_sas_hdr)) {
2627 err = EIO;
2628 goto out;
2629 }
2630
2632
2633 hdr = (union ses_elm_sas_hdr *)buf;
2634 dtype = ses_elm_sas_descr_type(hdr);
2635 switch(dtype) {
2637 switch(ses_cache->ses_types[tidx].hdr->etype_elm_type) {
2638 case ELMTYP_DEVICE:
2639 case ELMTYP_ARRAY_DEV:
2640 break;
2641 default:
2642 ENC_VLOG(enc, "Element %d has Additional Status type 0, "
2643 "invalid for SES element type 0x%x\n", nobj,
2645 err = ENODEV;
2646 goto out;
2647 }
2649 buf, bufsiz, eip,
2650 nobj);
2651 break;
2653 switch(ses_cache->ses_types[tidx].hdr->etype_elm_type) {
2654 case ELMTYP_SAS_EXP:
2655 case ELMTYP_SCSI_INI:
2656 case ELMTYP_SCSI_TGT:
2657 case ELMTYP_ESCC:
2658 break;
2659 default:
2660 ENC_VLOG(enc, "Element %d has Additional Status type 1, "
2661 "invalid for SES element type 0x%x\n", nobj,
2663 err = ENODEV;
2664 goto out;
2665 }
2667 bufsiz, eip, nobj);
2668 break;
2669 default:
2670 ENC_VLOG(enc, "Element %d of type 0x%x has Additional Status "
2671 "of unknown type 0x%x\n", nobj,
2672 ses_cache->ses_types[tidx].hdr->etype_elm_type, dtype);
2673 err = ENODEV;
2674 break;
2675 }
2676
2677out:
2678 return (err);
2679}
2680
2694static int
2696 uint8_t *buf, int bufsiz, int eip, int tidx,
2697 int nobj)
2698{
2699 int err;
2701
2702 if (bufsiz < sizeof(struct ses_elm_ata_hdr)) {
2703 err = EIO;
2704 goto out;
2705 }
2706
2708 switch(ses_cache->ses_types[tidx].hdr->etype_elm_type) {
2709 case ELMTYP_DEVICE:
2710 case ELMTYP_ARRAY_DEV:
2711 break;
2712 default:
2713 ENC_VLOG(enc, "Element %d has Additional Status, "
2714 "invalid for SES element type 0x%x\n", nobj,
2716 err = ENODEV;
2717 goto out;
2718 }
2719
2721 ->addl.proto_hdr.ata = (struct ses_elm_ata_hdr *)buf;
2722 err = 0;
2723
2724out:
2725 return (err);
2726}
2727
2728static void
2730{
2731 ses_softc_t *ses;
2732
2733 ses = enc->enc_private;
2735}
2736
2737static void
2739{
2740
2741 ses_cache_free(enc, &enc->enc_cache);
2742 ses_cache_free(enc, &enc->enc_daemon_cache);
2746}
2747
2748static int
2750{
2751 return (0);
2752}
2753
2754static int
2755ses_set_enc_status(enc_softc_t *enc, uint8_t encstat, int slpflag)
2756{
2758 ses_softc_t *ses;
2759
2760 ses = enc->enc_private;
2762 req.elm_stat.comstatus = encstat & 0xf;
2763
2764 TAILQ_INSERT_TAIL(&ses->ses_requests, &req, links);
2766 cam_periph_sleep(enc->periph, &req, PUSER, "encstat", 0);
2767
2768 return (req.result);
2769}
2770
2771static int
2773{
2774 unsigned int i = elms->elm_idx;
2775
2776 memcpy(elms->cstat, &enc->enc_cache.elm_map[i].encstat, 4);
2777 return (0);
2778}
2779
2780static int
2782{
2784 ses_softc_t *ses;
2785
2786 /* If this is clear, we don't do diddly. */
2787 if ((elms->cstat[0] & SESCTL_CSEL) == 0)
2788 return (0);
2789
2790 ses = enc->enc_private;
2791 req.elm_idx = elms->elm_idx;
2792 memcpy(&req.elm_stat, elms->cstat, sizeof(req.elm_stat));
2793
2794 TAILQ_INSERT_TAIL(&ses->ses_requests, &req, links);
2796 cam_periph_sleep(enc->periph, &req, PUSER, "encstat", 0);
2797
2798 return (req.result);
2799}
2800
2801static int
2803{
2804 int i = (int)elmd->elm_idx;
2805 ses_element_t *elmpriv;
2806
2807 /* Assume caller has already checked obj_id validity */
2808 elmpriv = enc->enc_cache.elm_map[i].elm_private;
2809 /* object might not have a descriptor */
2810 if (elmpriv == NULL || elmpriv->descr == NULL) {
2811 elmd->elm_desc_len = 0;
2812 return (0);
2813 }
2814 if (elmd->elm_desc_len > elmpriv->descr_len)
2815 elmd->elm_desc_len = elmpriv->descr_len;
2816 copyout(elmpriv->descr, elmd->elm_desc_str, elmd->elm_desc_len);
2817 return (0);
2818}
2819
2829static int
2831{
2832 struct sbuf sb;
2833 int len;
2834
2835 len = elmdn->elm_names_size;
2836 if (len < 0)
2837 return (EINVAL);
2838
2840 sbuf_new(&sb, NULL, len, SBUF_FIXEDLEN);
2841 ses_paths_iter(enc, &enc->enc_cache.elm_map[elmdn->elm_idx],
2843 sbuf_finish(&sb);
2844 elmdn->elm_names_len = sbuf_len(&sb);
2845 copyout(sbuf_data(&sb), elmdn->elm_devnames, elmdn->elm_names_len + 1);
2846 sbuf_delete(&sb);
2847 cam_periph_lock(enc->periph);
2848 return (elmdn->elm_names_len > 0 ? 0 : ENODEV);
2849}
2850
2861static int
2862ses_handle_string(enc_softc_t *enc, encioc_string_t *sstr, unsigned long ioc)
2863{
2866 const struct ses_enc_desc *enc_desc;
2867 int amt, payload, ret;
2868 char cdb[6];
2869 char str[32];
2870 char vendor[9];
2871 char product[17];
2872 char rev[5];
2873 uint8_t *buf;
2874 size_t size, rsize;
2875
2878
2879 /* Implement SES2r20 6.1.6 */
2880 if (sstr->bufsiz > ENC_STRING_MAX)
2881 return (EINVAL); /* buffer size too large */
2882
2883 switch (ioc) {
2884 case ENCIOC_SETSTRING:
2885 payload = sstr->bufsiz + 4; /* header for SEND DIAGNOSTIC */
2886 amt = 0 - payload;
2887 buf = ENC_MALLOC(payload);
2888 if (buf == NULL)
2889 return (ENOMEM);
2890 ses_page_cdb(cdb, payload, 0, CAM_DIR_OUT);
2891 /* Construct the page request */
2892 buf[0] = SesStringOut;
2893 buf[1] = 0;
2894 buf[2] = sstr->bufsiz >> 8;
2895 buf[3] = sstr->bufsiz & 0xff;
2896 ret = copyin(sstr->buf, &buf[4], sstr->bufsiz);
2897 if (ret != 0) {
2898 ENC_FREE(buf);
2899 return (ret);
2900 }
2901 break;
2902 case ENCIOC_GETSTRING:
2903 payload = sstr->bufsiz;
2904 amt = payload;
2905 buf = ENC_MALLOC(payload);
2906 if (buf == NULL)
2907 return (ENOMEM);
2908 ses_page_cdb(cdb, payload, SesStringIn, CAM_DIR_IN);
2909 break;
2910 case ENCIOC_GETENCNAME:
2911 if (ses_cache->ses_nsubencs < 1)
2912 return (ENODEV);
2913 enc_desc = ses_cache->subencs[0];
2914 cam_strvis(vendor, enc_desc->vendor_id,
2915 sizeof(enc_desc->vendor_id), sizeof(vendor));
2916 cam_strvis(product, enc_desc->product_id,
2917 sizeof(enc_desc->product_id), sizeof(product));
2918 cam_strvis(rev, enc_desc->product_rev,
2919 sizeof(enc_desc->product_rev), sizeof(rev));
2920 rsize = snprintf(str, sizeof(str), "%s %s %s",
2921 vendor, product, rev) + 1;
2922 if (rsize > sizeof(str))
2923 rsize = sizeof(str);
2924 size = rsize;
2925 if (size > sstr->bufsiz)
2926 size = sstr->bufsiz;
2927 copyout(str, sstr->buf, size);
2928 sstr->bufsiz = rsize;
2929 return (size == rsize ? 0 : ENOMEM);
2930 case ENCIOC_GETENCID:
2931 if (ses_cache->ses_nsubencs < 1)
2932 return (ENODEV);
2933 enc_desc = ses_cache->subencs[0];
2934 rsize = snprintf(str, sizeof(str), "%16jx",
2935 scsi_8btou64(enc_desc->logical_id)) + 1;
2936 if (rsize > sizeof(str))
2937 rsize = sizeof(str);
2938 size = rsize;
2939 if (size > sstr->bufsiz)
2940 size = sstr->bufsiz;
2941 copyout(str, sstr->buf, size);
2942 sstr->bufsiz = rsize;
2943 return (size == rsize ? 0 : ENOMEM);
2944 default:
2945 return (EINVAL);
2946 }
2947 ret = enc_runcmd(enc, cdb, 6, buf, &amt);
2948 if (ret == 0 && ioc == ENCIOC_GETSTRING)
2949 ret = copyout(buf, sstr->buf, sstr->bufsiz);
2950 if (ioc == ENCIOC_SETSTRING || ioc == ENCIOC_GETSTRING)
2951 ENC_FREE(buf);
2952 return (ret);
2953}
2954
2958static void
2960{
2961 ses_softc_t *ses;
2962
2963 ses = enc->enc_private;
2965 if (ses->ses_flags & SES_FLAG_DESC)
2967 if (ses->ses_flags & SES_FLAG_ADDLSTATUS)
2969}
2970
2977static void
2979{
2980 ses_poll_status(enc);
2982}
2983
2984static struct enc_vec ses_enc_vec =
2985{
2987 .softc_cleanup = ses_softc_cleanup,
2988 .init_enc = ses_init_enc,
2989 .set_enc_status = ses_set_enc_status,
2990 .get_elm_status = ses_get_elm_status,
2991 .set_elm_status = ses_set_elm_status,
2992 .get_elm_desc = ses_get_elm_desc,
2993 .get_elm_devnames = ses_get_elm_devnames,
2994 .handle_string = ses_handle_string,
2995 .device_found = ses_device_found,
2996 .poll_status = ses_poll_status
2997};
2998
3007int
3009{
3011
3013 ("entering enc_softc_init(%p)\n", enc));
3014
3015 enc->enc_vec = ses_enc_vec;
3017
3018 if (enc->enc_private == NULL)
3019 enc->enc_private = ENC_MALLOCZ(sizeof(ses_softc_t));
3020 if (enc->enc_cache.private == NULL)
3021 enc->enc_cache.private = ENC_MALLOCZ(sizeof(ses_cache_t));
3022 if (enc->enc_daemon_cache.private == NULL)
3024 ENC_MALLOCZ(sizeof(ses_cache_t));
3025
3026 if (enc->enc_private == NULL
3027 || enc->enc_cache.private == NULL
3028 || enc->enc_daemon_cache.private == NULL) {
3032 return (ENOMEM);
3033 }
3034
3035 ses_softc = enc->enc_private;
3036 TAILQ_INIT(&ses_softc->ses_requests);
3037 TAILQ_INIT(&ses_softc->ses_pending_requests);
3038
3040
3041 // XXX: Move this to the FSM so it doesn't hang init
3042 if (0) (void) ses_set_timed_completion(enc, 1);
3043
3044 return (0);
3045}
void semb_receive_diagnostic_results(struct ccb_ataio *ataio, u_int32_t retries, void(*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, int pcv, uint8_t page_code, uint8_t *data_ptr, uint16_t length, uint32_t timeout)
Definition: ata_all.c:1039
void cam_strvis(u_int8_t *dst, const u_int8_t *src, int srclen, int dstlen)
Definition: cam.c:124
@ SF_QUIET_IR
Definition: cam.h:124
#define CAM_TARGET_WILDCARD
Definition: cam.h:48
#define CAM_LUN_WILDCARD
Definition: cam.h:49
#define CAM_XPT_PATH_ID
Definition: cam.h:46
#define CAM_PRIORITY_NORMAL
Definition: cam.h:92
@ CAM_REQ_CMP
Definition: cam.h:137
@ CAM_STATUS_MASK
Definition: cam.h:302
@ CAM_DEV_QFRZN
Definition: cam.h:287
#define CDAI_FLAG_STORE
Definition: cam_ccb.h:1312
@ DEV_MATCH_DEVICE
Definition: cam_ccb.h:491
#define CAM_SCSI_DEVID_MAXLEN
Definition: cam_ccb.h:1324
@ DEV_MATCH_DEVID
Definition: cam_ccb.h:448
@ DEV_MATCH_PATH
Definition: cam_ccb.h:444
@ CAM_DIR_IN
Definition: cam_ccb.h:79
@ CAM_DIR_OUT
Definition: cam_ccb.h:80
@ CAM_DEV_MATCH_LAST
Definition: cam_ccb.h:542
@ CAM_DEV_MATCH_MORE
Definition: cam_ccb.h:543
@ XPT_DEV_ADVINFO
Definition: cam_ccb.h:166
@ XPT_GDEV_TYPE
Definition: cam_ccb.h:143
@ XPT_DEV_MATCH
Definition: cam_ccb.h:158
#define CDAI_FLAG_NONE
Definition: cam_ccb.h:1311
#define CDAI_TYPE_PHYS_PATH
Definition: cam_ccb.h:1317
#define CDAI_TYPE_SCSI_DEVID
Definition: cam_ccb.h:1315
@ CAM_DEBUG_SUBTRACE
Definition: cam_debug.h:42
#define CAM_DEBUG(path, flag, printfargs)
Definition: cam_debug.h:93
int cam_periph_list(struct cam_path *path, struct sbuf *sb)
Definition: cam_periph.c:370
u_int32_t cam_release_devq(struct cam_path *path, u_int32_t relsim_flags, u_int32_t openings, u_int32_t arg, int getcount_only)
Definition: cam_periph.c:1342
int cam_periph_runccb(union ccb *ccb, int(*error_routine)(union ccb *ccb, cam_flags camflags, u_int32_t sense_flags), cam_flags camflags, u_int32_t sense_flags, struct devstat *ds)
Definition: cam_periph.c:1207
#define cam_periph_lock(periph)
Definition: cam_periph.h:224
union ccb * cam_periph_getccb(struct cam_periph *periph, u_int32_t priority)
Definition: cam_xpt.c:4695
#define cam_periph_unlock(periph)
Definition: cam_periph.h:227
#define cam_periph_sleep(periph, chan, priority, wmesg, timo)
Definition: cam_periph.h:233
cam_status xpt_create_path(struct cam_path **new_path_ptr, struct cam_periph *perph, path_id_t path_id, target_id_t target_id, lun_id_t lun_id)
Definition: cam_xpt.c:3527
path_id_t xpt_path_path_id(struct cam_path *path)
Definition: cam_xpt.c:3880
void xpt_setup_ccb(struct ccb_hdr *ccb_h, struct cam_path *path, u_int32_t priority)
Definition: cam_xpt.c:3520
void xpt_action(union ccb *start_ccb)
Definition: cam_xpt.c:2601
void xpt_free_path(struct cam_path *path)
Definition: cam_xpt.c:3672
void xpt_release_ccb(union ccb *free_ccb)
Definition: cam_xpt.c:3924
#define xpt_path_unlock(path)
Definition: cam_xpt.h:129
#define xpt_path_lock(path)
Definition: cam_xpt.h:128
union ccb * ccb
Definition: mmc_sim_if.m:53
void scsi_mode_sense(struct ccb_scsiio *csio, uint32_t retries, void(*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, int dbd, uint8_t pc, uint8_t page, uint8_t *param_buf, uint32_t param_len, uint8_t sense_len, uint32_t timeout)
Definition: scsi_all.c:7625
void scsi_receive_diagnostic_results(struct ccb_scsiio *csio, u_int32_t retries, void(*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, int pcv, uint8_t page_code, uint8_t *data_ptr, uint16_t allocation_length, uint8_t sense_len, uint32_t timeout)
Definition: scsi_all.c:8688
void scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries, void(*cbfcnp)(struct cam_periph *, union ccb *), u_int8_t tag_action, int scsi_page_fmt, int save_pages, u_int8_t *param_buf, u_int32_t param_len, u_int8_t sense_len, u_int32_t timeout)
Definition: scsi_all.c:7704
int scsi_devid_is_naa_ieee_reg(uint8_t *bufp)
Definition: scsi_all.c:5589
struct scsi_vpd_id_descriptor * scsi_get_devid(struct scsi_vpd_device_id *id, uint32_t page_len, scsi_devid_checkfn_t ck_fn)
Definition: scsi_all.c:5732
#define SPSP_PROTO_ATA
Definition: scsi_all.h:885
#define SPSP_PROTO_SAS
Definition: scsi_all.h:883
#define SEND_DIAGNOSTIC
Definition: scsi_all.h:2093
static __inline uint64_t scsi_8btou64(const uint8_t *bytes)
Definition: scsi_all.h:4459
#define SVPD_ID_PROTO_SHIFT
Definition: scsi_all.h:2368
static __inline uint32_t scsi_2btoul(const uint8_t *bytes)
Definition: scsi_all.h:4415
#define SVPD_ID_PIV
Definition: scsi_all.h:2374
#define SVPD_ID_CODESET_BINARY
Definition: scsi_all.h:2369
#define RECEIVE_DIAGNOSTIC
Definition: scsi_all.h:2092
#define SVPD_ID_TYPE_NAA
Definition: scsi_all.h:2382
static __inline uint32_t scsi_4btoul(const uint8_t *bytes)
Definition: scsi_all.h:4447
#define SMS_PAGE_CTRL_CURRENT
Definition: scsi_all.h:204
#define SVPD_ID_ASSOC_PORT
Definition: scsi_all.h:2376
#define SSD_FULL_SIZE
Definition: scsi_all.h:3251
#define SPSP_PROTO_FC
Definition: scsi_all.h:877
#define SCSI_PROTO_SAS
Definition: scsi_all.h:864
#define SVPD_DEVICE_ID_DESC_HDR_LEN
Definition: scsi_all.h:2393
int enc_runcmd(struct enc_softc *enc, char *cdb, int cdbl, char *dptr, int *dlenp)
Definition: scsi_enc.c:579
const char * elm_type_names[]
Definition: scsi_enc.c:92
void enc_update_request(enc_softc_t *enc, uint32_t action)
Queue an update request for a given action, if needed.
Definition: scsi_enc.c:735
int enc_error(union ccb *ccb, uint32_t cflags, uint32_t sflags)
Definition: scsi_enc.c:346
#define ENCIOC_SETSTRING
Definition: scsi_enc.h:50
#define ENCIOC_GETENCID
Definition: scsi_enc.h:52
#define ENCIOC_GETSTRING
Definition: scsi_enc.h:49
@ ELMTYP_SCSI_TGT
Definition: scsi_enc.h:119
@ ELMTYP_ESCC
Definition: scsi_enc.h:106
@ ELMTYP_ARRAY_DEV
Definition: scsi_enc.h:122
@ ELMTYP_LAST
Definition: scsi_enc.h:125
@ ELMTYP_SCSI_INI
Definition: scsi_enc.h:120
@ ELMTYP_DEVICE
Definition: scsi_enc.h:100
@ ELMTYP_SAS_EXP
Definition: scsi_enc.h:123
#define ENCIOC_GETENCNAME
Definition: scsi_enc.h:51
#define ENC_STRING_MAX
Definition: scsi_enc.h:191
#define SES_MGMT_TIMED_COMP_EN
#define ENC_FLAGS
#define ENC_DLOG
#define SES_MGMT_MODE_PAGE_CODE
#define ENC_CFLAGS
int fsm_fill_handler_t(enc_softc_t *ssc, struct enc_fsm_state *state, union ccb *ccb, uint8_t *buf)
#define ENC_LOG
static enc_cache_t * enc_other_cache(enc_softc_t *enc, enc_cache_t *primary)
@ ENC_SEMB_SES
int fsm_done_handler_t(enc_softc_t *ssc, struct enc_fsm_state *state, union ccb *ccb, uint8_t **bufp, int error, int xfer_len)
#define ENC_FREE(ptr)
void() enc_softc_cleanup_t(enc_softc_t *)
#define ENC_MALLOC(amt)
#define ENC_VLOG
#define ENC_FREE_AND_NULL(ptr)
#define ENC_MALLOCZ(amt)
static void ses_cache_clone(enc_softc_t *enc, enc_cache_t *src, enc_cache_t *dst)
Definition: scsi_enc_ses.c:690
struct ses_element ses_element_t
static void ses_cache_free(enc_softc_t *enc, enc_cache_t *cache)
Definition: scsi_enc_ses.c:660
int ses_elm_addlstatus_proto(struct ses_elm_addlstatus_base_hdr *hdr)
Definition: scsi_enc_ses.c:740
static void ses_page_cdb(char *cdb, int bufsiz, SesDiagPageCodes pagenum, int dir)
Helper to set the CDB fields appropriately.
struct ses_setphyspath_callback_args ses_setphyspath_callback_args_t
static int ses_get_elm_addlstatus_sas_type0(enc_softc_t *enc, enc_cache_t *enc_cache, uint8_t *buf, int bufsiz, int eip, int nobj)
Update the softc with the additional element status data for this object, for SAS type 0 objects.
static fsm_done_handler_t ses_process_elm_descs
Definition: scsi_enc_ses.c:263
int ses_elm_sas_dev_phy_sata_dev(struct ses_elm_sas_device_phy *phy)
Definition: scsi_enc_ses.c:760
static void ses_print_addl_data(enc_softc_t *, enc_element_t *)
Print the additional element status data for this object.
static void ses_setphyspath_callback(enc_softc_t *enc, enc_element_t *elm, struct cam_path *path, void *arg)
ses_paths_iter() callback to set the physical path on the CAM EDT entries corresponding to a given SE...
ses_iter_index_values
Definition: scsi_enc_ses.c:141
@ ITERATOR_INDEX_INVALID
Value of an initialized but invalid index in a ses_iterator object.
Definition: scsi_enc_ses.c:150
@ ITERATOR_INDEX_END
Value of an index in a ses_iterator object when the iterator has traversed past the last valid elemen...
Definition: scsi_enc_ses.c:157
static void ses_device_found(enc_softc_t *enc)
Notification received when CAM detects a new device in the SCSI domain in which this SEP resides.
static int ses_search_globally
Definition: scsi_enc_ses.c:377
TAILQ_HEAD(ses_control_reqlist, ses_control_request)
static int ses_init_enc(enc_softc_t *enc)
int ses_elm_sas_dev_phy_sata_port(struct ses_elm_sas_device_phy *phy)
Definition: scsi_enc_ses.c:765
static void ses_poll_status(enc_softc_t *)
static int ses_get_elm_addlstatus_sas_type1(enc_softc_t *enc, enc_cache_t *enc_cache, uint8_t *buf, int bufsiz, int eip, int nobj)
Update the softc with the additional element status data for this object, for SAS type 1 objects.
static struct enc_fsm_state enc_fsm_states[SES_NUM_UPDATE_STATES]
Definition: scsi_enc_ses.c:269
void ses_path_callback_t(enc_softc_t *, enc_element_t *, struct cam_path *, void *)
Definition: scsi_enc_ses.c:854
#define SES_FLAG_DESC
Definition: scsi_enc_ses.c:371
SesDiagPageCodes
Definition: scsi_enc_ses.c:65
@ SesControlPage
Definition: scsi_enc_ses.c:68
@ SesSupportedPages
Definition: scsi_enc_ses.c:66
@ SesConfigPage
Definition: scsi_enc_ses.c:67
@ SesThresholdOut
Definition: scsi_enc_ses.c:73
@ SesShortStatus
Definition: scsi_enc_ses.c:78
@ SesElementDescriptor
Definition: scsi_enc_ses.c:77
@ SesArrayStatus
Definition: scsi_enc_ses.c:76
@ SesAddlElementStatus
Definition: scsi_enc_ses.c:80
@ SesHelpTxt
Definition: scsi_enc_ses.c:70
@ SesEnclosureBusy
Definition: scsi_enc_ses.c:79
@ SesStatusPage
Definition: scsi_enc_ses.c:69
@ SesStringIn
Definition: scsi_enc_ses.c:72
@ SesThresholdIn
Definition: scsi_enc_ses.c:74
@ SesArrayControl
Definition: scsi_enc_ses.c:75
@ SesStringOut
Definition: scsi_enc_ses.c:71
static void ses_print_addl_data_ata(struct sbuf *sbp, enc_element_t *obj)
Print the additional element status data for this object, for ATA objects.
static int ses_get_elm_addlstatus_ata(enc_softc_t *, enc_cache_t *, uint8_t *, int, int, int, int)
Update the softc with the additional element status data for this object, for ATA objects.
void ses_devid_callback_t(enc_softc_t *, enc_element_t *, struct scsi_vpd_id_descriptor *, void *)
Definition: scsi_enc_ses.c:803
struct ses_control_reqlist ses_control_reqlist_t
Definition: scsi_enc_ses.c:124
static void ses_paths_iter(enc_softc_t *enc, enc_element_t *elm, ses_path_callback_t *callback, void *callback_arg)
Iterate over and find the matching periph objects for the specified element.
Definition: scsi_enc_ses.c:950
static void ses_cache_free_elm_descs(enc_softc_t *enc, enc_cache_t *cache)
Definition: scsi_enc_ses.c:591
static fsm_done_handler_t ses_publish_cache
Definition: scsi_enc_ses.c:267
static enc_element_t * ses_iter_next(struct ses_iterator *iter)
Traverse the provided SES iterator to the next element within the configuration.
Definition: scsi_enc_ses.c:433
static void ses_devids_iter(enc_softc_t *enc, enc_element_t *elm, ses_devid_callback_t *callback, void *callback_arg)
Iterate over and create vpd device id records from the additional element status data for elm,...
Definition: scsi_enc_ses.c:818
static void ses_terminate_control_requests(ses_control_reqlist_t *reqlist, int result)
Definition: scsi_enc_ses.c:130
static int ses_set_elm_status(enc_softc_t *enc, encioc_elm_status_t *elms, int slpflag)
struct ses_softc ses_softc_t
static void ses_iter_init(enc_softc_t *enc, enc_cache_t *cache, struct ses_iterator *iter)
Initialize the storage of a SES iterator and reset it to the position just before the first element o...
Definition: scsi_enc_ses.c:416
static fsm_done_handler_t ses_process_control_request
Definition: scsi_enc_ses.c:265
static ses_addlstatus_avail_t ses_typehasaddlstatus(enc_softc_t *enc, uint8_t typidx)
Check to see whether a given type (as obtained via type headers) is supported by the additional statu...
struct ses_type ses_type_t
static int ses_handle_string(enc_softc_t *enc, encioc_string_t *sstr, unsigned long ioc)
Send a string to the primary subenclosure using the String Out SES diagnostic page.
static fsm_done_handler_t ses_process_elm_addlstatus
Definition: scsi_enc_ses.c:264
int ses_elm_sas_dev_phy_dev_type(struct ses_elm_sas_device_phy *phy)
Definition: scsi_enc_ses.c:770
ses_elem_index_type_t
Definition: scsi_enc_ses.c:489
@ SES_ELEM_INDEX_INDIVIDUAL
Index relative to all individual elements in the system.
Definition: scsi_enc_ses.c:503
@ SES_ELEM_INDEX_GLOBAL
Definition: scsi_enc_ses.c:494
struct ses_comstat ses_comstat_t
int ses_elm_addlstatus_eip(struct ses_elm_addlstatus_base_hdr *hdr)
Definition: scsi_enc_ses.c:745
static void ses_cache_free_elm_map(enc_softc_t *enc, enc_cache_t *cache)
Definition: scsi_enc_ses.c:638
static void ses_cache_free_elm_addlstatus(enc_softc_t *enc, enc_cache_t *cache)
Definition: scsi_enc_ses.c:560
static fsm_done_handler_t ses_process_config
Definition: scsi_enc_ses.c:261
static int ses_set_enc_status(enc_softc_t *enc, uint8_t encstat, int slpflag)
ses_addlstatus_avail_t
@ TYPE_ADDLSTATUS_OPTIONAL
@ TYPE_ADDLSTATUS_NONE
@ TYPE_ADDLSTATUS_MANDATORY
__FBSDID("$FreeBSD$")
static fsm_done_handler_t ses_process_pages
Definition: scsi_enc_ses.c:260
struct ses_control_request ses_control_request_t
struct ses_cache ses_cache_t
static int ses_get_elm_addlstatus_fc(enc_softc_t *, enc_cache_t *, uint8_t *, int)
#define SES_FLAG_TIMEDCOMP
Definition: scsi_enc_ses.c:369
static fsm_done_handler_t ses_publish_physpaths
Definition: scsi_enc_ses.c:266
struct ses_path_iter_args ses_path_iter_args_t
static int ses_get_elm_status(enc_softc_t *enc, encioc_elm_status_t *elms, int slpflag)
static void ses_print_addl_data_sas_type1(char *sesname, struct sbuf *sbp, enc_element_t *obj)
Print the additional element status data for this object, for SAS type 1 objects. See SES2 r20 Sectio...
static void ses_path_iter_devid_callback(enc_softc_t *enc, enc_element_t *elem, struct scsi_vpd_id_descriptor *devid, void *arg)
Definition: scsi_enc_ses.c:876
static int ses_get_elm_devnames(enc_softc_t *enc, encioc_elm_devnames_t *elmdn)
Respond to ENCIOC_GETELMDEVNAME, providing a device name for the given object id if one is available.
#define SCSZ
Definition: scsi_enc_ses.c:256
static void ses_elmdevname_callback(enc_softc_t *enc, enc_element_t *elem, struct cam_path *path, void *arg)
static void ses_softc_invalidate(enc_softc_t *enc)
@ SES_SETSTATUS_ENC_IDX
Definition: scsi_enc_ses.c:126
static enc_softc_cleanup_t ses_softc_cleanup
Definition: scsi_enc_ses.c:254
static struct enc_vec ses_enc_vec
static fsm_done_handler_t ses_process_status
Definition: scsi_enc_ses.c:262
static int ses_get_elm_addlstatus_sas(enc_softc_t *, enc_cache_t *, uint8_t *, int, int, int, int)
Update the softc with the additional element status data for this object, for SAS objects.
int ses_elm_sas_descr_type(union ses_elm_sas_hdr *obj)
Definition: scsi_enc_ses.c:735
static enc_element_t * ses_iter_seek_to(struct ses_iterator *iter, int element_index, ses_elem_index_type_t index_type)
Move the provided iterator forwards or backwards to the object having the give index.
Definition: scsi_enc_ses.c:518
#define SES_FLAG_ADDLSTATUS
Definition: scsi_enc_ses.c:370
static int ses_config_cache_valid(ses_cache_t *ses_cache, const uint8_t *gen_code)
Verify that the cached configuration data in our softc is valid for processing the page data correspo...
Definition: scsi_enc_ses.c:787
int ses_elm_sas_type0_not_all_phys(union ses_elm_sas_hdr *hdr)
Definition: scsi_enc_ses.c:755
static void ses_cache_free_status(enc_softc_t *enc, enc_cache_t *cache)
Definition: scsi_enc_ses.c:621
static void ses_print_addl_data_sas_type0(char *sesname, struct sbuf *sbp, enc_element_t *obj)
Print the additional element status data for this object, for SAS type 0 objects. See SES2 r20 Sectio...
SYSCTL_INT(_kern_cam_enc, OID_AUTO, search_globally, CTLFLAG_RWTUN, &ses_search_globally, 0, "Search for disks on other buses")
static fsm_fill_handler_t ses_fill_control_request
Definition: scsi_enc_ses.c:259
static const char * ses_sanitize_elm_desc(const char *desc, uint16_t *len)
struct ses_addl_status ses_add_status_t
int ses_softc_init(enc_softc_t *enc)
Initialize a new SES instance.
static void ses_iter_reset(struct ses_iterator *iter)
Reset a SES iterator to just before the first element in the configuration.
Definition: scsi_enc_ses.c:392
static int ses_get_elm_desc(enc_softc_t *enc, encioc_elm_desc_t *elmd)
static int ses_encode(enc_softc_t *enc, uint8_t *buf, int amt, ses_control_request_t *req)
Encode the object status into the response buffer, which is expected to contain the current enclosure...
static int ses_set_timed_completion(enc_softc_t *, uint8_t)
Discover whether this instance supports timed completion of a RECEIVE DIAGNOSTIC RESULTS command requ...
union ses_addl_data ses_add_data_t
int ses_elm_addlstatus_invalid(struct ses_elm_addlstatus_base_hdr *hdr)
Definition: scsi_enc_ses.c:750
static fsm_fill_handler_t ses_fill_rcv_diag_io
Definition: scsi_enc_ses.c:258
#define SES_PRINT_PORTS(p, type)
ses_update_action
Definition: scsi_enc_ses.c:241
@ SES_UPDATE_GETELMADDLSTATUS
Definition: scsi_enc_ses.c:247
@ SES_UPDATE_PAGES
Definition: scsi_enc_ses.c:243
@ SES_UPDATE_GETCONFIG
Definition: scsi_enc_ses.c:244
@ SES_UPDATE_GETELMDESCS
Definition: scsi_enc_ses.c:246
@ SES_UPDATE_GETSTATUS
Definition: scsi_enc_ses.c:245
@ SES_UPDATE_NONE
Definition: scsi_enc_ses.c:242
@ SES_PUBLISH_CACHE
Definition: scsi_enc_ses.c:250
@ SES_NUM_UPDATE_STATES
Definition: scsi_enc_ses.c:251
@ SES_PUBLISH_PHYSPATHS
Definition: scsi_enc_ses.c:249
@ SES_PROCESS_CONTROL_REQS
Definition: scsi_enc_ses.c:248
static int ses_set_physpath(enc_softc_t *enc, enc_element_t *elm, struct ses_iterator *iter)
Set a device's physical path string in CAM XPT.
#define MSG_SIMPLE_Q_TAG
Definition: scsi_message.h:35
#define SES_SET_STATUS_MASK
Definition: scsi_ses.h:2197
#define SES_SASOBJ_TYPE_SLOT
Definition: scsi_ses.h:2441
static int ses_enc_desc_is_complete(struct ses_enc_desc *encdesc, uint8_t *last_buf_byte)
Definition: scsi_ses.h:132
#define SES_ADDL_EIP_EIIOE_EI_GLOB(x)
Definition: scsi_ses.h:2488
static int ses_cfg_page_get_num_subenc(struct ses_cfg_page *page)
Definition: scsi_ses.h:153
#define SESCTL_CSEL
Definition: scsi_ses.h:2220
static size_t ses_page_length(const struct ses_page_hdr *hdr)
Definition: scsi_ses.h:89
#define SES_SASOBJ_TYPE_OTHER
Definition: scsi_ses.h:2442
#define SES_EIP_HDR_EXTRA_LEN
Definition: scsi_ses.h:2492
static struct ses_enc_desc * ses_enc_desc_next(struct ses_enc_desc *encdesc)
Definition: scsi_ses.h:126
char * periph_name
Definition: cam_periph.h:123
u_int32_t unit_number
Definition: cam_periph.h:127
struct cam_path * path
Definition: cam_periph.h:124
struct ccb_hdr ccb_h
Definition: cam_ccb.h:1309
uint32_t buftype
Definition: cam_ccb.h:1313
uint8_t * buf
Definition: cam_ccb.h:1326
uint32_t flags
Definition: cam_ccb.h:1310
struct dev_match_result * matches
Definition: cam_ccb.h:587
ccb_dev_match_status status
Definition: cam_ccb.h:581
struct ccb_hdr ccb_h
Definition: cam_ccb.h:580
u_int32_t match_buf_len
Definition: cam_ccb.h:586
u_int32_t num_patterns
Definition: cam_ccb.h:582
u_int32_t pattern_buf_len
Definition: cam_ccb.h:583
struct dev_match_pattern * patterns
Definition: cam_ccb.h:584
struct ccb_hdr ccb_h
Definition: cam_ccb.h:379
struct cam_path * path
Definition: cam_ccb.h:364
xpt_opcode func_code
Definition: cam_ccb.h:362
u_int32_t status
Definition: cam_ccb.h:363
uint8_t id[256]
Definition: cam_ccb.h:453
union device_match_pattern::@1 data
path_id_t path_id
Definition: cam_ccb.h:457
dev_pattern_flags flags
Definition: cam_ccb.h:460
struct device_id_match_pattern devid_pat
Definition: cam_ccb.h:463
target_id_t target_id
Definition: cam_ccb.h:515
path_id_t path_id
Definition: cam_ccb.h:514
lun_id_t target_lun
Definition: cam_ccb.h:516
enc_element_t * elm_map
encioc_enc_status_t enc_status
uint8_t encstat[4]
uint8_t type_elm_idx
uint8_t subenclosure
void * enc_private
struct enc_vec enc_vec
struct cam_periph * periph
struct sx enc_cache_lock
struct enc_fsm_state * enc_fsm_states
enc_cache_t enc_cache
enc_cache_t enc_daemon_cache
enc_softc_invalidate_t * softc_invalidate
uint16_t elm_desc_len
Definition: scsi_enc.h:203
unsigned int elm_idx
Definition: scsi_enc.h:202
char * elm_desc_str
Definition: scsi_enc.h:204
size_t elm_names_len
Definition: scsi_enc.h:214
size_t elm_names_size
Definition: scsi_enc.h:213
unsigned int elm_idx
Definition: scsi_enc.h:212
unsigned char cstat[4]
Definition: scsi_enc.h:182
unsigned int elm_idx
Definition: scsi_enc.h:181
uint8_t * buf
Definition: scsi_enc.h:192
size_t bufsiz
Definition: scsi_enc.h:190
uint8_t length[2]
Definition: scsi_all.h:2604
uint8_t params[0]
Definition: scsi_all.h:2605
u_int8_t identifier[]
Definition: scsi_all.h:2395
struct ses_page_hdr hdr
Definition: scsi_ses.h:2160
struct ses_elm_addlstatus_base_hdr * hdr
Definition: scsi_enc_ses.c:101
union ses_fcobj_hdr * fc
Definition: scsi_enc_ses.c:103
union ses_addl_status::@24 proto_hdr
struct ses_elm_ata_hdr * ata
Definition: scsi_enc_ses.c:105
union ses_elm_sas_hdr * sas
Definition: scsi_enc_ses.c:104
union ses_addl_data proto_data
Definition: scsi_enc_ses.c:107
const struct ses_status_page * status_page
Definition: scsi_enc_ses.c:357
const struct ses_elem_descr_page * elm_descs_page
Definition: scsi_enc_ses.c:360
const struct ses_cfg_page * cfg_page
Definition: scsi_enc_ses.c:348
int ses_nsubencs
Definition: scsi_enc_ses.c:351
const struct ses_enc_desc *const * subencs
Definition: scsi_enc_ses.c:352
const struct ses_addl_elem_status_page * elm_addlstatus_page
Definition: scsi_enc_ses.c:363
int ses_ntypes
Definition: scsi_enc_ses.c:353
const ses_type_t * ses_types
Definition: scsi_enc_ses.c:354
struct ses_page_hdr hdr
Definition: scsi_ses.h:146
struct ses_enc_desc subencs[]
Definition: scsi_ses.h:147
uint8_t comstat[3]
Definition: scsi_enc_ses.c:90
uint8_t comstatus
Definition: scsi_enc_ses.c:89
ses_comstat_t elm_stat
Definition: scsi_enc_ses.c:119
struct ses_page_hdr hdr
Definition: scsi_ses.h:2154
struct ses_addl_status addl
Definition: scsi_enc_ses.c:114
const char * descr
Definition: scsi_enc_ses.c:113
uint8_t eip
Definition: scsi_enc_ses.c:111
uint16_t descr_len
Definition: scsi_enc_ses.c:112
uint8_t target[4]
Definition: scsi_ses.h:2463
uint8_t bus[4]
Definition: scsi_ses.h:2462
uint8_t length[2]
Definition: scsi_ses.h:2268
uint8_t parent_addr[8]
Definition: scsi_ses.h:2370
uint8_t connector_index
Definition: scsi_ses.h:2389
uint8_t phy_addr[8]
Definition: scsi_ses.h:2391
uint8_t etype_subenc
Definition: scsi_ses.h:141
uint8_t etype_txt_len
Definition: scsi_ses.h:142
uint8_t etype_elm_type
Definition: scsi_ses.h:139
uint8_t etype_maxelt
Definition: scsi_ses.h:140
uint8_t vendor_id[8]
Definition: scsi_ses.h:113
uint8_t subenc_id
Definition: scsi_ses.h:109
uint8_t logical_id[8]
Definition: scsi_ses.h:112
uint8_t byte0
Definition: scsi_ses.h:102
uint8_t length
Definition: scsi_ses.h:111
uint8_t product_id[16]
Definition: scsi_ses.h:114
uint8_t num_types
Definition: scsi_ses.h:110
uint8_t product_rev[4]
Definition: scsi_ses.h:115
Structure encapsulating all data necessary to traverse the elements of a SES configuration.
Definition: scsi_enc_ses.c:181
int saved_individual_element_index
The last valid individual element index of this iterator.
Definition: scsi_enc_ses.c:238
enc_cache_t * cache
Definition: scsi_enc_ses.c:190
int individual_element_index
The position (0 based) of this element relative to all other individual status elements in the config...
Definition: scsi_enc_ses.c:217
int global_element_index
The position (0 based) of this element relative to all elements in the configration.
Definition: scsi_enc_ses.c:225
int type_index
Index of the type of the current element within the ses_cache's ses_types array.
Definition: scsi_enc_ses.c:196
int type_element_index
The position (0 based) of this element relative to all other elements of this type.
Definition: scsi_enc_ses.c:205
enc_softc_t * enc
Backlink to the overal software configuration structure.
Definition: scsi_enc_ses.c:188
uint8_t page_specific_flags
Definition: scsi_ses.h:83
uint8_t length[2]
Definition: scsi_ses.h:84
uint8_t page_code
Definition: scsi_ses.h:82
uint8_t gen_code[4]
Definition: scsi_ses.h:85
ses_path_callback_t * callback
Definition: scsi_enc_ses.c:862
ses_control_reqlist_t ses_pending_requests
Definition: scsi_enc_ses.c:374
uint32_t ses_flags
Definition: scsi_enc_ses.c:368
ses_control_reqlist_t ses_requests
Definition: scsi_enc_ses.c:373
struct ses_page_hdr hdr
Definition: scsi_ses.h:2107
union ses_status_element elements[]
Definition: scsi_ses.h:2108
const struct ses_elm_type_desc * hdr
Definition: scsi_enc_ses.c:84
const char * text
Definition: scsi_enc_ses.c:85
Definition: cam_ccb.h:1345
struct ccb_hdr ccb_h
Definition: cam_ccb.h:1346
struct ccb_scsiio csio
Definition: cam_ccb.h:1347
struct ccb_ataio ataio
Definition: cam_ccb.h:1376
struct device_match_pattern device_pattern
Definition: cam_ccb.h:485
struct device_match_result device_result
Definition: cam_ccb.h:532
struct ses_elm_sas_device_phy * sasdev_phys
Definition: scsi_enc_ses.c:94
struct ses_elm_sas_port_phy * sasport_phys
Definition: scsi_enc_ses.c:96
struct ses_elm_sas_expander_phy * sasexp_phys
Definition: scsi_enc_ses.c:95
struct ses_fcobj_port * fc_ports
Definition: scsi_enc_ses.c:97
struct ses_elm_sas_type0_eip_hdr type0_eip
Definition: scsi_ses.h:2448
struct ses_elm_sas_base_hdr base_hdr
Definition: scsi_ses.h:2446
uint8_t bytes[4]
Definition: scsi_ses.h:2058