1291a2b48SSukumar Swaminathan /*
2291a2b48SSukumar Swaminathan  * CDDL HEADER START
3291a2b48SSukumar Swaminathan  *
4291a2b48SSukumar Swaminathan  * The contents of this file are subject to the terms of the
5291a2b48SSukumar Swaminathan  * Common Development and Distribution License (the "License").
6291a2b48SSukumar Swaminathan  * You may not use this file except in compliance with the License.
7291a2b48SSukumar Swaminathan  *
88f23e9faSHans Rosenfeld  * You can obtain a copy of the license at
98f23e9faSHans Rosenfeld  * http://www.opensource.org/licenses/cddl1.txt.
10291a2b48SSukumar Swaminathan  * See the License for the specific language governing permissions
11291a2b48SSukumar Swaminathan  * and limitations under the License.
12291a2b48SSukumar Swaminathan  *
13291a2b48SSukumar Swaminathan  * When distributing Covered Code, include this CDDL HEADER in each
14291a2b48SSukumar Swaminathan  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15291a2b48SSukumar Swaminathan  * If applicable, add the following below this CDDL HEADER, with the
16291a2b48SSukumar Swaminathan  * fields enclosed by brackets "[]" replaced with your own identifying
17291a2b48SSukumar Swaminathan  * information: Portions Copyright [yyyy] [name of copyright owner]
18291a2b48SSukumar Swaminathan  *
19291a2b48SSukumar Swaminathan  * CDDL HEADER END
20291a2b48SSukumar Swaminathan  */
21291a2b48SSukumar Swaminathan 
22291a2b48SSukumar Swaminathan /*
238f23e9faSHans Rosenfeld  * Copyright (c) 2004-2012 Emulex. All rights reserved.
2482527734SSukumar Swaminathan  * Use is subject to license terms.
25291a2b48SSukumar Swaminathan  */
26291a2b48SSukumar Swaminathan 
27291a2b48SSukumar Swaminathan #include <emlxs.h>
28291a2b48SSukumar Swaminathan 
29291a2b48SSukumar Swaminathan #ifdef DUMP_SUPPORT
30291a2b48SSukumar Swaminathan 
31291a2b48SSukumar Swaminathan /* Required for EMLXS_CONTEXT in EMLXS_MSGF calls */
32291a2b48SSukumar Swaminathan EMLXS_MSG_DEF(EMLXS_DUMP_C);
33291a2b48SSukumar Swaminathan 
34291a2b48SSukumar Swaminathan /* ************************************************************************* */
35291a2b48SSukumar Swaminathan /* Utility functions */
36291a2b48SSukumar Swaminathan /* ************************************************************************* */
37291a2b48SSukumar Swaminathan 
38291a2b48SSukumar Swaminathan static uint32_t
emlxs_menlo_set_mode(emlxs_hba_t * hba,uint32_t mode)39291a2b48SSukumar Swaminathan emlxs_menlo_set_mode(
40291a2b48SSukumar Swaminathan 	emlxs_hba_t *hba,
41291a2b48SSukumar Swaminathan 	uint32_t mode)
42291a2b48SSukumar Swaminathan {
43291a2b48SSukumar Swaminathan 	emlxs_port_t *port = &PPORT;
44291a2b48SSukumar Swaminathan 	uint32_t cmd_size;
45291a2b48SSukumar Swaminathan 	uint32_t rsp_size;
46291a2b48SSukumar Swaminathan 	menlo_cmd_t *cmd_buf = NULL;
47291a2b48SSukumar Swaminathan 	menlo_rsp_t *rsp_buf = NULL;
48291a2b48SSukumar Swaminathan 	uint32_t rval = 0;
49291a2b48SSukumar Swaminathan 
50*a3170057SPaul Winder 	if (hba->model_info.vendor_id != PCI_VENDOR_ID_EMULEX ||
51*a3170057SPaul Winder 	    hba->model_info.device_id != PCI_DEVICE_ID_HORNET) {
5282527734SSukumar Swaminathan 		return (DFC_INVALID_ADAPTER);
53291a2b48SSukumar Swaminathan 	}
54291a2b48SSukumar Swaminathan 
5582527734SSukumar Swaminathan 	cmd_size = sizeof (menlo_set_cmd_t);
5682527734SSukumar Swaminathan 	cmd_buf = (menlo_cmd_t *)kmem_zalloc(cmd_size, KM_SLEEP);
57291a2b48SSukumar Swaminathan 
5882527734SSukumar Swaminathan 	rsp_size = 4;
5982527734SSukumar Swaminathan 	rsp_buf = (menlo_rsp_t *)kmem_zalloc(rsp_size, KM_SLEEP);
60291a2b48SSukumar Swaminathan 
61291a2b48SSukumar Swaminathan 	cmd_buf->code = MENLO_CMD_SET_MODE;
62291a2b48SSukumar Swaminathan 	cmd_buf->set.value1 = mode;
63291a2b48SSukumar Swaminathan 	cmd_buf->set.value2 = 0;
64291a2b48SSukumar Swaminathan 
65291a2b48SSukumar Swaminathan #ifdef EMLXS_BIG_ENDIAN
66291a2b48SSukumar Swaminathan 	emlxs_swap32_buffer((uint8_t *)cmd_buf, cmd_size);
67291a2b48SSukumar Swaminathan #endif /* EMLXS_BIG_ENDIAN */
68291a2b48SSukumar Swaminathan 
69291a2b48SSukumar Swaminathan 	if (rval = emlxs_send_menlo_cmd(hba, (uint8_t *)cmd_buf, cmd_size,
70291a2b48SSukumar Swaminathan 	    (uint8_t *)rsp_buf, &rsp_size)) {
71291a2b48SSukumar Swaminathan 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_sli_detail_msg,
728f23e9faSHans Rosenfeld 		    "menlo_set_mode: Unable to send command.");
73291a2b48SSukumar Swaminathan 		goto done;
74291a2b48SSukumar Swaminathan 	}
75291a2b48SSukumar Swaminathan #ifdef EMLXS_BIG_ENDIAN
76291a2b48SSukumar Swaminathan 	emlxs_swap32_buffer((uint8_t *)rsp_buf, rsp_size);
77291a2b48SSukumar Swaminathan #endif /* EMLXS_BIG_ENDIAN */
78291a2b48SSukumar Swaminathan 
79291a2b48SSukumar Swaminathan 	if (rsp_buf->code != 0) {
80291a2b48SSukumar Swaminathan 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_sli_detail_msg,
818f23e9faSHans Rosenfeld 		    "menlo_set_mode: Menlo command error. code=%d.\n",
82291a2b48SSukumar Swaminathan 		    rsp_buf->code);
83291a2b48SSukumar Swaminathan 	}
84291a2b48SSukumar Swaminathan 
85291a2b48SSukumar Swaminathan 	rval = rsp_buf->code;
86291a2b48SSukumar Swaminathan 
87291a2b48SSukumar Swaminathan done:
88291a2b48SSukumar Swaminathan 
89291a2b48SSukumar Swaminathan 	if (cmd_buf) {
90291a2b48SSukumar Swaminathan 		kmem_free(cmd_buf, sizeof (menlo_set_cmd_t));
91291a2b48SSukumar Swaminathan 	}
92291a2b48SSukumar Swaminathan 
93291a2b48SSukumar Swaminathan 	if (rsp_buf) {
94291a2b48SSukumar Swaminathan 		kmem_free(rsp_buf, 4);
95291a2b48SSukumar Swaminathan 	}
96291a2b48SSukumar Swaminathan 
97291a2b48SSukumar Swaminathan 	return (rval);
98291a2b48SSukumar Swaminathan 
9982527734SSukumar Swaminathan } /* emlxs_menlo_set_mode() */
100291a2b48SSukumar Swaminathan 
101291a2b48SSukumar Swaminathan 
102291a2b48SSukumar Swaminathan static uint32_t
emlxs_menlo_reset(emlxs_hba_t * hba,uint32_t firmware)103291a2b48SSukumar Swaminathan emlxs_menlo_reset(
104291a2b48SSukumar Swaminathan 	emlxs_hba_t *hba,
105291a2b48SSukumar Swaminathan 	uint32_t firmware)
106291a2b48SSukumar Swaminathan {
107291a2b48SSukumar Swaminathan 	emlxs_port_t *port = &PPORT;
108291a2b48SSukumar Swaminathan 	uint32_t cmd_size;
109291a2b48SSukumar Swaminathan 	uint32_t rsp_size;
110291a2b48SSukumar Swaminathan 	menlo_cmd_t *cmd_buf = NULL;
111291a2b48SSukumar Swaminathan 	menlo_rsp_t *rsp_buf = NULL;
112291a2b48SSukumar Swaminathan 	uint32_t rval = 0;
113291a2b48SSukumar Swaminathan 
114*a3170057SPaul Winder 	if (hba->model_info.vendor_id != PCI_VENDOR_ID_EMULEX ||
115*a3170057SPaul Winder 	    hba->model_info.device_id != PCI_DEVICE_ID_HORNET) {
11682527734SSukumar Swaminathan 		return (DFC_INVALID_ADAPTER);
117291a2b48SSukumar Swaminathan 	}
118291a2b48SSukumar Swaminathan 
11982527734SSukumar Swaminathan 	cmd_size = sizeof (menlo_reset_cmd_t);
12082527734SSukumar Swaminathan 	cmd_buf = (menlo_cmd_t *)kmem_zalloc(cmd_size, KM_SLEEP);
121291a2b48SSukumar Swaminathan 
12282527734SSukumar Swaminathan 	rsp_size = 4;
12382527734SSukumar Swaminathan 	rsp_buf = (menlo_rsp_t *)kmem_zalloc(rsp_size, KM_SLEEP);
124291a2b48SSukumar Swaminathan 
125291a2b48SSukumar Swaminathan 	cmd_buf->code = MENLO_CMD_RESET;
126291a2b48SSukumar Swaminathan 	cmd_buf->reset.firmware = firmware;
127291a2b48SSukumar Swaminathan 
128291a2b48SSukumar Swaminathan #ifdef EMLXS_BIG_ENDIAN
129291a2b48SSukumar Swaminathan 	emlxs_swap32_buffer((uint8_t *)cmd_buf, cmd_size);
130291a2b48SSukumar Swaminathan #endif /* EMLXS_BIG_ENDIAN */
131291a2b48SSukumar Swaminathan 
132291a2b48SSukumar Swaminathan 	if (rval = emlxs_send_menlo_cmd(hba, (uint8_t *)cmd_buf, cmd_size,
133291a2b48SSukumar Swaminathan 	    (uint8_t *)rsp_buf, &rsp_size)) {
134291a2b48SSukumar Swaminathan 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_sli_detail_msg,
1358f23e9faSHans Rosenfeld 		    "menlo_reset: Unable to send command.");
136291a2b48SSukumar Swaminathan 		goto done;
137291a2b48SSukumar Swaminathan 	}
138291a2b48SSukumar Swaminathan #ifdef EMLXS_BIG_ENDIAN
139291a2b48SSukumar Swaminathan 	emlxs_swap32_buffer((uint8_t *)rsp_buf, rsp_size);
140291a2b48SSukumar Swaminathan #endif /* EMLXS_BIG_ENDIAN */
141291a2b48SSukumar Swaminathan 
142291a2b48SSukumar Swaminathan 	if (rsp_buf->code != 0) {
143291a2b48SSukumar Swaminathan 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_sli_detail_msg,
1448f23e9faSHans Rosenfeld 		    "menlo_reset: Menlo command error. code=%d.\n",
145291a2b48SSukumar Swaminathan 		    rsp_buf->code);
146291a2b48SSukumar Swaminathan 	}
147291a2b48SSukumar Swaminathan 
148291a2b48SSukumar Swaminathan 	rval = rsp_buf->code;
149291a2b48SSukumar Swaminathan 
150291a2b48SSukumar Swaminathan done:
151291a2b48SSukumar Swaminathan 
152291a2b48SSukumar Swaminathan 	if (cmd_buf) {
153291a2b48SSukumar Swaminathan 		kmem_free(cmd_buf, sizeof (menlo_reset_cmd_t));
154291a2b48SSukumar Swaminathan 	}
155291a2b48SSukumar Swaminathan 
156291a2b48SSukumar Swaminathan 	if (rsp_buf) {
157291a2b48SSukumar Swaminathan 		kmem_free(rsp_buf, 4);
158291a2b48SSukumar Swaminathan 	}
159291a2b48SSukumar Swaminathan 
160291a2b48SSukumar Swaminathan 	return (rval);
161291a2b48SSukumar Swaminathan 
16282527734SSukumar Swaminathan } /* emlxs_menlo_reset() */
163291a2b48SSukumar Swaminathan 
164291a2b48SSukumar Swaminathan 
165291a2b48SSukumar Swaminathan static uint32_t
emlxs_menlo_get_cfg(emlxs_hba_t * hba,menlo_get_config_rsp_t * rsp_buf,uint32_t rsp_size)166291a2b48SSukumar Swaminathan emlxs_menlo_get_cfg(
167291a2b48SSukumar Swaminathan 	emlxs_hba_t *hba,
168291a2b48SSukumar Swaminathan 	menlo_get_config_rsp_t *rsp_buf,
169291a2b48SSukumar Swaminathan 	uint32_t rsp_size)
170291a2b48SSukumar Swaminathan {
171291a2b48SSukumar Swaminathan 	emlxs_port_t *port = &PPORT;
172291a2b48SSukumar Swaminathan 	uint32_t cmd_size;
173291a2b48SSukumar Swaminathan 	menlo_cmd_t *cmd_buf = NULL;
174291a2b48SSukumar Swaminathan 	uint32_t rval = 0;
175291a2b48SSukumar Swaminathan 
176*a3170057SPaul Winder 	if (hba->model_info.vendor_id != PCI_VENDOR_ID_EMULEX ||
177*a3170057SPaul Winder 	    hba->model_info.device_id != PCI_DEVICE_ID_HORNET) {
17882527734SSukumar Swaminathan 		return (DFC_INVALID_ADAPTER);
179291a2b48SSukumar Swaminathan 	}
180291a2b48SSukumar Swaminathan 
18182527734SSukumar Swaminathan 	cmd_size = sizeof (menlo_get_cmd_t);
18282527734SSukumar Swaminathan 	cmd_buf = (menlo_cmd_t *)kmem_zalloc(cmd_size, KM_SLEEP);
18382527734SSukumar Swaminathan 
184291a2b48SSukumar Swaminathan 	rsp_size = sizeof (menlo_get_config_rsp_t);
185291a2b48SSukumar Swaminathan 
186291a2b48SSukumar Swaminathan 	cmd_buf->code = MENLO_CMD_GET_CONFIG;
187291a2b48SSukumar Swaminathan 	cmd_buf->get.context = 0;
188291a2b48SSukumar Swaminathan 	cmd_buf->get.length = rsp_size;
189291a2b48SSukumar Swaminathan 
190291a2b48SSukumar Swaminathan #ifdef EMLXS_BIG_ENDIAN
191291a2b48SSukumar Swaminathan 	emlxs_swap32_buffer((uint8_t *)cmd_buf, cmd_size);
192291a2b48SSukumar Swaminathan #endif /* EMLXS_BIG_ENDIAN */
193291a2b48SSukumar Swaminathan 
194291a2b48SSukumar Swaminathan 	if (rval = emlxs_send_menlo_cmd(hba, (uint8_t *)cmd_buf, cmd_size,
195291a2b48SSukumar Swaminathan 	    (uint8_t *)rsp_buf, &rsp_size)) {
196291a2b48SSukumar Swaminathan 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_sli_detail_msg,
1978f23e9faSHans Rosenfeld 		    "menlo_get_cfg: Unable to send command.");
198291a2b48SSukumar Swaminathan 		goto done;
199291a2b48SSukumar Swaminathan 	}
200291a2b48SSukumar Swaminathan #ifdef EMLXS_BIG_ENDIAN
201291a2b48SSukumar Swaminathan 	emlxs_swap32_buffer((uint8_t *)rsp_buf, rsp_size);
202291a2b48SSukumar Swaminathan #endif /* EMLXS_BIG_ENDIAN */
203291a2b48SSukumar Swaminathan 
204291a2b48SSukumar Swaminathan 	if (rsp_buf->code != 0) {
205291a2b48SSukumar Swaminathan 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_sli_detail_msg,
2068f23e9faSHans Rosenfeld 		    "menlo_get_cfg: Menlo command error. code=%d.\n",
207291a2b48SSukumar Swaminathan 		    rsp_buf->code);
208291a2b48SSukumar Swaminathan 	}
209291a2b48SSukumar Swaminathan 
210291a2b48SSukumar Swaminathan 	rval = rsp_buf->code;
211291a2b48SSukumar Swaminathan 
212291a2b48SSukumar Swaminathan done:
213291a2b48SSukumar Swaminathan 
214291a2b48SSukumar Swaminathan 	if (cmd_buf) {
215291a2b48SSukumar Swaminathan 		kmem_free(cmd_buf, sizeof (menlo_get_cmd_t));
216291a2b48SSukumar Swaminathan 	}
217291a2b48SSukumar Swaminathan 
218291a2b48SSukumar Swaminathan 	return (rval);
219291a2b48SSukumar Swaminathan 
22082527734SSukumar Swaminathan } /* emlxs_menlo_get_cfg() */
221291a2b48SSukumar Swaminathan 
222291a2b48SSukumar Swaminathan 
223291a2b48SSukumar Swaminathan 
224291a2b48SSukumar Swaminathan static uint32_t
emlxs_menlo_get_logcfg(emlxs_hba_t * hba,menlo_rsp_t * rsp_buf,uint32_t rsp_size)225291a2b48SSukumar Swaminathan emlxs_menlo_get_logcfg(
226291a2b48SSukumar Swaminathan 	emlxs_hba_t *hba,
227291a2b48SSukumar Swaminathan 	menlo_rsp_t *rsp_buf,
228291a2b48SSukumar Swaminathan 	uint32_t rsp_size)
229291a2b48SSukumar Swaminathan {
230291a2b48SSukumar Swaminathan 	emlxs_port_t *port = &PPORT;
231291a2b48SSukumar Swaminathan 	uint32_t cmd_size;
232291a2b48SSukumar Swaminathan 	menlo_cmd_t *cmd_buf = NULL;
233291a2b48SSukumar Swaminathan 	uint32_t rval = 0;
234291a2b48SSukumar Swaminathan 
235*a3170057SPaul Winder 	if (hba->model_info.vendor_id != PCI_VENDOR_ID_EMULEX ||
236*a3170057SPaul Winder 	    hba->model_info.device_id != PCI_DEVICE_ID_HORNET) {
23782527734SSukumar Swaminathan 		return (DFC_INVALID_ADAPTER);
238291a2b48SSukumar Swaminathan 	}
239291a2b48SSukumar Swaminathan 
24082527734SSukumar Swaminathan 	cmd_size = sizeof (menlo_get_cmd_t);
24182527734SSukumar Swaminathan 	cmd_buf = (menlo_cmd_t *)kmem_zalloc(cmd_size, KM_SLEEP);
24282527734SSukumar Swaminathan 
243291a2b48SSukumar Swaminathan 	cmd_buf->code = MENLO_CMD_GET_LOG_CONFIG;
244291a2b48SSukumar Swaminathan 	cmd_buf->get.context = 0;
245291a2b48SSukumar Swaminathan 	cmd_buf->get.length = rsp_size;
246291a2b48SSukumar Swaminathan 
247291a2b48SSukumar Swaminathan #ifdef EMLXS_BIG_ENDIAN
248291a2b48SSukumar Swaminathan 	emlxs_swap32_buffer((uint8_t *)cmd_buf, cmd_size);
249291a2b48SSukumar Swaminathan #endif /* EMLXS_BIG_ENDIAN */
250291a2b48SSukumar Swaminathan 
251291a2b48SSukumar Swaminathan 	if (rval = emlxs_send_menlo_cmd(hba, (uint8_t *)cmd_buf, cmd_size,
252291a2b48SSukumar Swaminathan 	    (uint8_t *)rsp_buf, &rsp_size)) {
253291a2b48SSukumar Swaminathan 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_sli_detail_msg,
2548f23e9faSHans Rosenfeld 		    "menlo_get_logcfg: Unable to send command.");
255291a2b48SSukumar Swaminathan 		goto done;
256291a2b48SSukumar Swaminathan 	}
257291a2b48SSukumar Swaminathan #ifdef EMLXS_BIG_ENDIAN
258291a2b48SSukumar Swaminathan 	emlxs_swap32_buffer((uint8_t *)rsp_buf, rsp_size);
259291a2b48SSukumar Swaminathan #endif /* EMLXS_BIG_ENDIAN */
260291a2b48SSukumar Swaminathan 
261291a2b48SSukumar Swaminathan 	if (rsp_buf->code != 0) {
262291a2b48SSukumar Swaminathan 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_sli_detail_msg,
2638f23e9faSHans Rosenfeld 		    "menlo_get_logcfg: Menlo command error. code=%d.\n",
264291a2b48SSukumar Swaminathan 		    rsp_buf->code);
265291a2b48SSukumar Swaminathan 	}
266291a2b48SSukumar Swaminathan 
267291a2b48SSukumar Swaminathan 	rval = rsp_buf->code;
268291a2b48SSukumar Swaminathan 
269291a2b48SSukumar Swaminathan done:
270291a2b48SSukumar Swaminathan 
271291a2b48SSukumar Swaminathan 	if (cmd_buf) {
272291a2b48SSukumar Swaminathan 		kmem_free(cmd_buf, sizeof (menlo_get_cmd_t));
273291a2b48SSukumar Swaminathan 	}
274291a2b48SSukumar Swaminathan 
275291a2b48SSukumar Swaminathan 	return (rval);
276291a2b48SSukumar Swaminathan 
27782527734SSukumar Swaminathan } /* emlxs_menlo_get_logcfg() */
278291a2b48SSukumar Swaminathan 
279291a2b48SSukumar Swaminathan 
280291a2b48SSukumar Swaminathan static uint32_t
emlxs_menlo_get_log(emlxs_hba_t * hba,uint32_t id,menlo_rsp_t * rsp_buf,uint32_t rsp_size)281291a2b48SSukumar Swaminathan emlxs_menlo_get_log(
282291a2b48SSukumar Swaminathan 	emlxs_hba_t *hba,
283291a2b48SSukumar Swaminathan 	uint32_t id,
284291a2b48SSukumar Swaminathan 	menlo_rsp_t *rsp_buf,
285291a2b48SSukumar Swaminathan 	uint32_t rsp_size)
286291a2b48SSukumar Swaminathan {
287291a2b48SSukumar Swaminathan 	emlxs_port_t *port = &PPORT;
288291a2b48SSukumar Swaminathan 	uint32_t cmd_size;
289291a2b48SSukumar Swaminathan 	menlo_cmd_t *cmd_buf = NULL;
290291a2b48SSukumar Swaminathan 	uint32_t rval = 0;
291291a2b48SSukumar Swaminathan 
292*a3170057SPaul Winder 	if (hba->model_info.vendor_id != PCI_VENDOR_ID_EMULEX ||
293*a3170057SPaul Winder 	    hba->model_info.device_id != PCI_DEVICE_ID_HORNET) {
29482527734SSukumar Swaminathan 		return (DFC_INVALID_ADAPTER);
295291a2b48SSukumar Swaminathan 	}
296291a2b48SSukumar Swaminathan 
29782527734SSukumar Swaminathan 	cmd_size = sizeof (menlo_get_cmd_t);
29882527734SSukumar Swaminathan 	cmd_buf = (menlo_cmd_t *)kmem_zalloc(cmd_size, KM_SLEEP);
29982527734SSukumar Swaminathan 
300291a2b48SSukumar Swaminathan 	cmd_buf->code = MENLO_CMD_GET_LOG_DATA;
301291a2b48SSukumar Swaminathan 	cmd_buf->get.context = id;
302291a2b48SSukumar Swaminathan 	cmd_buf->get.length = rsp_size;
303291a2b48SSukumar Swaminathan 
304291a2b48SSukumar Swaminathan #ifdef EMLXS_BIG_ENDIAN
305291a2b48SSukumar Swaminathan 	emlxs_swap32_buffer((uint8_t *)cmd_buf, cmd_size);
306291a2b48SSukumar Swaminathan #endif /* EMLXS_BIG_ENDIAN */
307291a2b48SSukumar Swaminathan 
308291a2b48SSukumar Swaminathan 	if (rval = emlxs_send_menlo_cmd(hba, (uint8_t *)cmd_buf, cmd_size,
309291a2b48SSukumar Swaminathan 	    (uint8_t *)rsp_buf, &rsp_size)) {
310291a2b48SSukumar Swaminathan 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_sli_detail_msg,
3118f23e9faSHans Rosenfeld 		    "menlo_get_log: Unable to send command.");
312291a2b48SSukumar Swaminathan 		goto done;
313291a2b48SSukumar Swaminathan 	}
314291a2b48SSukumar Swaminathan #ifdef EMLXS_BIG_ENDIAN
315291a2b48SSukumar Swaminathan 	emlxs_swap32_buffer((uint8_t *)rsp_buf, rsp_size);
316291a2b48SSukumar Swaminathan #endif /* EMLXS_BIG_ENDIAN */
317291a2b48SSukumar Swaminathan 
318291a2b48SSukumar Swaminathan 	if (rsp_buf->code != 0) {
319291a2b48SSukumar Swaminathan 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_sli_detail_msg,
3208f23e9faSHans Rosenfeld 		    "menlo_get_log: Menlo command error. code=%d.\n",
321291a2b48SSukumar Swaminathan 		    rsp_buf->code);
322291a2b48SSukumar Swaminathan 	}
323291a2b48SSukumar Swaminathan 
324291a2b48SSukumar Swaminathan 	rval = rsp_buf->code;
325291a2b48SSukumar Swaminathan 
326291a2b48SSukumar Swaminathan done:
327291a2b48SSukumar Swaminathan 
328291a2b48SSukumar Swaminathan 	if (cmd_buf) {
329291a2b48SSukumar Swaminathan 		kmem_free(cmd_buf, sizeof (menlo_get_cmd_t));
330291a2b48SSukumar Swaminathan 	}
331291a2b48SSukumar Swaminathan 
332291a2b48SSukumar Swaminathan 	return (rval);
333291a2b48SSukumar Swaminathan 
33482527734SSukumar Swaminathan } /* emlxs_menlo_get_log() */
335291a2b48SSukumar Swaminathan 
336291a2b48SSukumar Swaminathan 
337291a2b48SSukumar Swaminathan static uint32_t
emlxs_menlo_get_paniclog(emlxs_hba_t * hba,menlo_rsp_t * rsp_buf,uint32_t rsp_size)338291a2b48SSukumar Swaminathan emlxs_menlo_get_paniclog(
339291a2b48SSukumar Swaminathan 	emlxs_hba_t *hba,
340291a2b48SSukumar Swaminathan 	menlo_rsp_t *rsp_buf,
341291a2b48SSukumar Swaminathan 	uint32_t rsp_size)
342291a2b48SSukumar Swaminathan {
343291a2b48SSukumar Swaminathan 	emlxs_port_t *port = &PPORT;
344291a2b48SSukumar Swaminathan 	uint32_t cmd_size;
345291a2b48SSukumar Swaminathan 	menlo_cmd_t *cmd_buf = NULL;
346291a2b48SSukumar Swaminathan 	uint32_t rval = 0;
347291a2b48SSukumar Swaminathan 
348*a3170057SPaul Winder 	if (hba->model_info.vendor_id != PCI_VENDOR_ID_EMULEX ||
349*a3170057SPaul Winder 	    hba->model_info.device_id != PCI_DEVICE_ID_HORNET) {
35082527734SSukumar Swaminathan 		return (DFC_INVALID_ADAPTER);
351291a2b48SSukumar Swaminathan 	}
352291a2b48SSukumar Swaminathan 
35382527734SSukumar Swaminathan 	cmd_size = sizeof (menlo_get_cmd_t);
35482527734SSukumar Swaminathan 	cmd_buf = (menlo_cmd_t *)kmem_zalloc(cmd_size, KM_SLEEP);
35582527734SSukumar Swaminathan 
356291a2b48SSukumar Swaminathan 	cmd_buf->code = MENLO_CMD_GET_PANIC_LOG;
357291a2b48SSukumar Swaminathan 	cmd_buf->get.context = 0;
358291a2b48SSukumar Swaminathan 	cmd_buf->get.length = rsp_size;
359291a2b48SSukumar Swaminathan 
360291a2b48SSukumar Swaminathan #ifdef EMLXS_BIG_ENDIAN
361291a2b48SSukumar Swaminathan 	emlxs_swap32_buffer((uint8_t *)cmd_buf, cmd_size);
362291a2b48SSukumar Swaminathan #endif /* EMLXS_BIG_ENDIAN */
363291a2b48SSukumar Swaminathan 
364291a2b48SSukumar Swaminathan 	if (rval = emlxs_send_menlo_cmd(hba, (uint8_t *)cmd_buf, cmd_size,
365291a2b48SSukumar Swaminathan 	    (uint8_t *)rsp_buf, &rsp_size)) {
366291a2b48SSukumar Swaminathan 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_sli_detail_msg,
3678f23e9faSHans Rosenfeld 		    "menlo_get_paniclog: Unable to send command.");
368291a2b48SSukumar Swaminathan 		goto done;
369291a2b48SSukumar Swaminathan 	}
370291a2b48SSukumar Swaminathan #ifdef EMLXS_BIG_ENDIAN
371291a2b48SSukumar Swaminathan 	emlxs_swap32_buffer((uint8_t *)rsp_buf, rsp_size);
372291a2b48SSukumar Swaminathan #endif /* EMLXS_BIG_ENDIAN */
373291a2b48SSukumar Swaminathan 
374291a2b48SSukumar Swaminathan 	if (rsp_buf->code != 0) {
375291a2b48SSukumar Swaminathan 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_sli_detail_msg,
3768f23e9faSHans Rosenfeld 		    "menlo_get_paniclog: Menlo command error. code=%d.\n",
377291a2b48SSukumar Swaminathan 		    rsp_buf->code);
378291a2b48SSukumar Swaminathan 	}
379291a2b48SSukumar Swaminathan 
380291a2b48SSukumar Swaminathan 	rval = rsp_buf->code;
381291a2b48SSukumar Swaminathan 
382291a2b48SSukumar Swaminathan done:
383291a2b48SSukumar Swaminathan 
384291a2b48SSukumar Swaminathan 	if (cmd_buf) {
385291a2b48SSukumar Swaminathan 		kmem_free(cmd_buf, sizeof (menlo_get_cmd_t));
386291a2b48SSukumar Swaminathan 	}
387291a2b48SSukumar Swaminathan 
388291a2b48SSukumar Swaminathan 	return (rval);
389291a2b48SSukumar Swaminathan 
39082527734SSukumar Swaminathan } /* emlxs_menlo_get_paniclog() */
391291a2b48SSukumar Swaminathan 
392291a2b48SSukumar Swaminathan 
393291a2b48SSukumar Swaminathan 
394291a2b48SSukumar Swaminathan 
39582527734SSukumar Swaminathan extern void
emlxs_fflush(emlxs_file_t * fp)396291a2b48SSukumar Swaminathan emlxs_fflush(
397291a2b48SSukumar Swaminathan 	emlxs_file_t *fp)
398291a2b48SSukumar Swaminathan {
399291a2b48SSukumar Swaminathan 	uint32_t offset;
400291a2b48SSukumar Swaminathan 
401291a2b48SSukumar Swaminathan 	offset = (uint32_t)((uintptr_t)fp->ptr - (uintptr_t)fp->buffer);
402291a2b48SSukumar Swaminathan 
403291a2b48SSukumar Swaminathan 	if (offset > fp->size) {
404291a2b48SSukumar Swaminathan 		fp->ptr = fp->buffer + fp->size;
405291a2b48SSukumar Swaminathan 	}
406291a2b48SSukumar Swaminathan 
407291a2b48SSukumar Swaminathan 	return;
408291a2b48SSukumar Swaminathan 
409