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