1*96c4a178SChris Horne /*
2*96c4a178SChris Horne * CDDL HEADER START
3*96c4a178SChris Horne *
4*96c4a178SChris Horne * The contents of this file are subject to the terms of the
5*96c4a178SChris Horne * Common Development and Distribution License (the "License").
6*96c4a178SChris Horne * You may not use this file except in compliance with the License.
7*96c4a178SChris Horne *
8*96c4a178SChris Horne * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*96c4a178SChris Horne * or http://www.opensolaris.org/os/licensing.
10*96c4a178SChris Horne * See the License for the specific language governing permissions
11*96c4a178SChris Horne * and limitations under the License.
12*96c4a178SChris Horne *
13*96c4a178SChris Horne * When distributing Covered Code, include this CDDL HEADER in each
14*96c4a178SChris Horne * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*96c4a178SChris Horne * If applicable, add the following below this CDDL HEADER, with the
16*96c4a178SChris Horne * fields enclosed by brackets "[]" replaced with your own identifying
17*96c4a178SChris Horne * information: Portions Copyright [yyyy] [name of copyright owner]
18*96c4a178SChris Horne *
19*96c4a178SChris Horne * CDDL HEADER END
20*96c4a178SChris Horne */
21*96c4a178SChris Horne /*
22*96c4a178SChris Horne * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23*96c4a178SChris Horne * Use is subject to license terms.
24*96c4a178SChris Horne */
25*96c4a178SChris Horne
26*96c4a178SChris Horne #include <sys/byteorder.h>
27*96c4a178SChris Horne #include <sys/scsi/scsi.h>
28*96c4a178SChris Horne
29*96c4a178SChris Horne static int
smp_device_prop_update_inqstring(struct smp_device * smp_sd,char * name,char * data,size_t len)30*96c4a178SChris Horne smp_device_prop_update_inqstring(struct smp_device *smp_sd,
31*96c4a178SChris Horne char *name, char *data, size_t len)
32*96c4a178SChris Horne {
33*96c4a178SChris Horne int ilen;
34*96c4a178SChris Horne char *data_string;
35*96c4a178SChris Horne int rv;
36*96c4a178SChris Horne
37*96c4a178SChris Horne /* SMP information follows SCSI INQUIRY rules */
38*96c4a178SChris Horne ilen = scsi_ascii_inquiry_len(data, len);
39*96c4a178SChris Horne ASSERT(ilen <= (int)len);
40*96c4a178SChris Horne if (ilen <= 0)
41*96c4a178SChris Horne return (DDI_PROP_INVAL_ARG);
42*96c4a178SChris Horne
43*96c4a178SChris Horne /* ensure null termination */
44*96c4a178SChris Horne data_string = kmem_zalloc(ilen + 1, KM_SLEEP);
45*96c4a178SChris Horne bcopy(data, data_string, ilen);
46*96c4a178SChris Horne rv = ndi_prop_update_string(DDI_DEV_T_NONE,
47*96c4a178SChris Horne smp_sd->smp_sd_dev, name, data_string);
48*96c4a178SChris Horne kmem_free(data_string, ilen + 1);
49*96c4a178SChris Horne return (rv);
50*96c4a178SChris Horne }
51*96c4a178SChris Horne
52*96c4a178SChris Horne /*
53*96c4a178SChris Horne * smp_probe: probe device and create inquiry-like properties.
54*96c4a178SChris Horne */
55*96c4a178SChris Horne int
smp_probe(struct smp_device * smp_sd)56*96c4a178SChris Horne smp_probe(struct smp_device *smp_sd)
57*96c4a178SChris Horne {
58*96c4a178SChris Horne smp_pkt_t *smp_pkt;
59*96c4a178SChris Horne smp_pkt_t smp_pkt_data;
60*96c4a178SChris Horne smp_request_frame_t *srq;
61*96c4a178SChris Horne smp_response_frame_t *srs;
62*96c4a178SChris Horne smp_report_manufacturer_info_resp_t *srmir;
63*96c4a178SChris Horne int ilen, clen;
64*96c4a178SChris Horne char *component;
65*96c4a178SChris Horne uint8_t srq_buf[SMP_REQ_MINLEN];
66*96c4a178SChris Horne uint8_t srs_buf[SMP_RESP_MINLEN + sizeof (*srmir)];
67*96c4a178SChris Horne
68*96c4a178SChris Horne srq = (smp_request_frame_t *)srq_buf;
69*96c4a178SChris Horne bzero(srq, sizeof (srq_buf));
70*96c4a178SChris Horne srq->srf_frame_type = SMP_FRAME_TYPE_REQUEST;
71*96c4a178SChris Horne srq->srf_function = SMP_FUNC_REPORT_MANUFACTURER_INFO;
72*96c4a178SChris Horne
73*96c4a178SChris Horne smp_pkt = &smp_pkt_data;
74*96c4a178SChris Horne bzero(smp_pkt, sizeof (*smp_pkt));
75*96c4a178SChris Horne smp_pkt->smp_pkt_address = &smp_sd->smp_sd_address;
76*96c4a178SChris Horne smp_pkt->smp_pkt_req = (caddr_t)srq;
77*96c4a178SChris Horne smp_pkt->smp_pkt_reqsize = sizeof (srq_buf);
78*96c4a178SChris Horne smp_pkt->smp_pkt_rsp = (caddr_t)srs_buf;
79*96c4a178SChris Horne smp_pkt->smp_pkt_rspsize = sizeof (srs_buf);
80*96c4a178SChris Horne smp_pkt->smp_pkt_timeout = SMP_DEFAULT_TIMEOUT;
81*96c4a178SChris Horne
82*96c4a178SChris Horne bzero(srs_buf, sizeof (srs_buf));
83*96c4a178SChris Horne
84*96c4a178SChris Horne if (smp_transport(smp_pkt) != DDI_SUCCESS) {
85*96c4a178SChris Horne /*
86*96c4a178SChris Horne * The EOVERFLOW should be excluded here, because it indicates
87*96c4a178SChris Horne * the buffer (defined according to SAS1.1 Spec) to store
88*96c4a178SChris Horne * response is shorter than transferred message frame.
89*96c4a178SChris Horne * In this case, the smp device is alive and should be
90*96c4a178SChris Horne * enumerated.
91*96c4a178SChris Horne */
92*96c4a178SChris Horne if (smp_pkt->smp_pkt_reason != EOVERFLOW)
93*96c4a178SChris Horne return (DDI_PROBE_FAILURE);
94*96c4a178SChris Horne }
95*96c4a178SChris Horne
96*96c4a178SChris Horne /*
97*96c4a178SChris Horne * NOTE: Deal with old drivers (mpt, mpt_sas) that allocate
98*96c4a178SChris Horne * 'struct smp_device' on the stack. When these drivers convert to
99*96c4a178SChris Horne * SCSAv3, the check for a NULL smp_sd_dev can be removed.
100*96c4a178SChris Horne */
101*96c4a178SChris Horne if (smp_sd->smp_sd_dev == NULL)
102*96c4a178SChris Horne return (DDI_PROBE_SUCCESS);
103*96c4a178SChris Horne
104*96c4a178SChris Horne /* Save raw response data for devid */
105*96c4a178SChris Horne srs = (smp_response_frame_t *)srs_buf;
106*96c4a178SChris Horne if (srs->srf_result != SMP_RES_FUNCTION_ACCEPTED)
107*96c4a178SChris Horne return (DDI_PROBE_SUCCESS);
108*96c4a178SChris Horne
109*96c4a178SChris Horne /*
110*96c4a178SChris Horne * Convert smp_report_manufacturer_info_resp_t data into properties.
111*96c4a178SChris Horne * NOTE: since things show up in the oposite order in prtconf, we are
112*96c4a178SChris Horne * going from detailed information to generic here.
113*96c4a178SChris Horne */
114*96c4a178SChris Horne srmir = (smp_report_manufacturer_info_resp_t *)&srs->srf_data[0];
115*96c4a178SChris Horne if (srmir->srmir_sas_1_1_format) {
116*96c4a178SChris Horne /* Establish 'component' property. */
117*96c4a178SChris Horne ilen = scsi_ascii_inquiry_len(
118*96c4a178SChris Horne srmir->srmir_component_vendor_identification,
119*96c4a178SChris Horne sizeof (srmir->srmir_component_vendor_identification));
120*96c4a178SChris Horne if (ilen > 0) {
121*96c4a178SChris Horne /* component value format is '%s.%05d.%03d' */
122*96c4a178SChris Horne clen = ilen + 1 + 5 + 1 + 3 + 1;
123*96c4a178SChris Horne component = kmem_zalloc(clen, KM_SLEEP);
124*96c4a178SChris Horne bcopy(srmir->srmir_component_vendor_identification,
125*96c4a178SChris Horne component, ilen);
126*96c4a178SChris Horne (void) snprintf(&component[ilen], clen - ilen,
127*96c4a178SChris Horne ".%05d.%03d", BE_16(srmir->srmir_component_id),
128*96c4a178SChris Horne srmir->srmir_component_revision_level);
129*96c4a178SChris Horne if (ddi_prop_exists(DDI_DEV_T_NONE, smp_sd->smp_sd_dev,
130*96c4a178SChris Horne DDI_PROP_DONTPASS | DDI_PROP_NOTPROM,
131*96c4a178SChris Horne "component") == 0)
132*96c4a178SChris Horne (void) ndi_prop_update_string(DDI_DEV_T_NONE,
133*96c4a178SChris Horne smp_sd->smp_sd_dev, "component", component);
134*96c4a178SChris Horne kmem_free(component, clen);
135*96c4a178SChris Horne }
136*96c4a178SChris Horne }
137*96c4a178SChris Horne /* First one to define the property wins */
138*96c4a178SChris Horne if (ddi_prop_exists(DDI_DEV_T_NONE, smp_sd->smp_sd_dev,
139*96c4a178SChris Horne DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, INQUIRY_REVISION_ID) == 0)
140*96c4a178SChris Horne (void) smp_device_prop_update_inqstring(smp_sd,
141*96c4a178SChris Horne INQUIRY_REVISION_ID, srmir->srmir_product_revision_level,
142*96c4a178SChris Horne sizeof (srmir->srmir_product_revision_level));
143*96c4a178SChris Horne
144*96c4a178SChris Horne if (ddi_prop_exists(DDI_DEV_T_NONE, smp_sd->smp_sd_dev,
145*96c4a178SChris Horne DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, INQUIRY_PRODUCT_ID) == 0)
146*96c4a178SChris Horne (void) smp_device_prop_update_inqstring(smp_sd,
147*96c4a178SChris Horne INQUIRY_PRODUCT_ID, srmir->srmir_product_identification,
148*96c4a178SChris Horne sizeof (srmir->srmir_product_identification));
149*96c4a178SChris Horne
150*96c4a178SChris Horne if (ddi_prop_exists(DDI_DEV_T_NONE, smp_sd->smp_sd_dev,
151*96c4a178SChris Horne DDI_PROP_DONTPASS | DDI_PROP_NOTPROM, INQUIRY_VENDOR_ID) == 0)
152*96c4a178SChris Horne (void) smp_device_prop_update_inqstring(smp_sd,
153*96c4a178SChris Horne INQUIRY_VENDOR_ID, srmir->srmir_vendor_identification,
154*96c4a178SChris Horne sizeof (srmir->srmir_vendor_identification));
155*96c4a178SChris Horne
156*96c4a178SChris Horne /* NOTE: SMP_PROP_REPORT_MANUFACTURER is deleted after devid created */
157*96c4a178SChris Horne if (ddi_prop_exists(DDI_DEV_T_NONE, smp_sd->smp_sd_dev,
158*96c4a178SChris Horne DDI_PROP_DONTPASS | DDI_PROP_NOTPROM,
159*96c4a178SChris Horne SMP_PROP_REPORT_MANUFACTURER) == 0)
160*96c4a178SChris Horne (void) ndi_prop_update_byte_array(DDI_DEV_T_NONE,
161*96c4a178SChris Horne smp_sd->smp_sd_dev, SMP_PROP_REPORT_MANUFACTURER,
162*96c4a178SChris Horne (uchar_t *)srs, sizeof (srs_buf));
163*96c4a178SChris Horne
164*96c4a178SChris Horne return (DDI_PROBE_SUCCESS);
165*96c4a178SChris Horne }
166*96c4a178SChris Horne
167*96c4a178SChris Horne int
smp_transport(struct smp_pkt * smp_pkt)168*96c4a178SChris Horne smp_transport(struct smp_pkt *smp_pkt)
169*96c4a178SChris Horne {
170*96c4a178SChris Horne return (smp_pkt->smp_pkt_address->
171*96c4a178SChris Horne smp_a_hba_tran->smp_tran_start(smp_pkt));
172*96c4a178SChris Horne }
173