1fcf3ce44SJohn Forte /*
2fcf3ce44SJohn Forte  * CDDL HEADER START
3fcf3ce44SJohn Forte  *
4fcf3ce44SJohn Forte  * The contents of this file are subject to the terms of the
5fcf3ce44SJohn Forte  * Common Development and Distribution License (the "License").
6fcf3ce44SJohn Forte  * You may not use this file except in compliance with the License.
7fcf3ce44SJohn Forte  *
88f23e9faSHans Rosenfeld  * You can obtain a copy of the license at
98f23e9faSHans Rosenfeld  * http://www.opensource.org/licenses/cddl1.txt.
10fcf3ce44SJohn Forte  * See the License for the specific language governing permissions
11fcf3ce44SJohn Forte  * and limitations under the License.
12fcf3ce44SJohn Forte  *
13fcf3ce44SJohn Forte  * When distributing Covered Code, include this CDDL HEADER in each
14fcf3ce44SJohn Forte  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fcf3ce44SJohn Forte  * If applicable, add the following below this CDDL HEADER, with the
16fcf3ce44SJohn Forte  * fields enclosed by brackets "[]" replaced with your own identifying
17fcf3ce44SJohn Forte  * information: Portions Copyright [yyyy] [name of copyright owner]
18fcf3ce44SJohn Forte  *
19fcf3ce44SJohn Forte  * CDDL HEADER END
20fcf3ce44SJohn Forte  */
21fcf3ce44SJohn Forte 
22fcf3ce44SJohn Forte /*
238f23e9faSHans Rosenfeld  * Copyright (c) 2004-2012 Emulex. All rights reserved.
2482527734SSukumar Swaminathan  * Use is subject to license terms.
25*a3170057SPaul Winder  * Copyright 2020 RackTop Systems, Inc.
26fcf3ce44SJohn Forte  */
27fcf3ce44SJohn Forte 
2882527734SSukumar Swaminathan #include <emlxs.h>
29fcf3ce44SJohn Forte 
30fcf3ce44SJohn Forte /* Required for EMLXS_CONTEXT in EMLXS_MSGF calls */
31fcf3ce44SJohn Forte EMLXS_MSG_DEF(EMLXS_DFC_C);
32fcf3ce44SJohn Forte 
33291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_get_rev(emlxs_hba_t *hba, dfc_t *dfc,
34291a2b48SSukumar Swaminathan 				int32_t mode);
35291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_get_hbainfo(emlxs_hba_t *hba, dfc_t *dfc,
36291a2b48SSukumar Swaminathan 				int32_t mode);
37291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_get_hbastats(emlxs_hba_t *hba, dfc_t *dfc,
38291a2b48SSukumar Swaminathan 				int32_t mode);
39291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_get_drvstats(emlxs_hba_t *hba, dfc_t *dfc,
40291a2b48SSukumar Swaminathan 				int32_t mode);
41291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_set_diag(emlxs_hba_t *hba, dfc_t *dfc,
42291a2b48SSukumar Swaminathan 				int32_t mode);
43291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_send_mbox(emlxs_hba_t *hba, dfc_t *dfc,
44291a2b48SSukumar Swaminathan 				int32_t mode);
45291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_read_pci(emlxs_hba_t *hba, dfc_t *dfc,
46291a2b48SSukumar Swaminathan 				int32_t mode);
47291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_write_pci(emlxs_hba_t *hba, dfc_t *dfc,
48291a2b48SSukumar Swaminathan 				int32_t mode);
49291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_get_cfg(emlxs_hba_t *hba, dfc_t *dfc,
50291a2b48SSukumar Swaminathan 				int32_t mode);
51291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_set_cfg(emlxs_hba_t *hba, dfc_t *dfc,
52291a2b48SSukumar Swaminathan 				int32_t mode);
53291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_send_menlo(emlxs_hba_t *hba, dfc_t *dfc,
54291a2b48SSukumar Swaminathan 				int32_t mode);
55291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_send_ct(emlxs_hba_t *hba, dfc_t *dfc,
56291a2b48SSukumar Swaminathan 				int32_t mode);
57291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_send_ct_rsp(emlxs_hba_t *hba, dfc_t *dfc,
58291a2b48SSukumar Swaminathan 				int32_t mode);
59291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_write_flash(emlxs_hba_t *hba, dfc_t *dfc,
60291a2b48SSukumar Swaminathan 				int32_t mode);
61291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_read_flash(emlxs_hba_t *hba, dfc_t *dfc,
62291a2b48SSukumar Swaminathan 				int32_t mode);
63291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_send_els(emlxs_hba_t *hba, dfc_t *dfc,
64291a2b48SSukumar Swaminathan 				int32_t mode);
65291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_loopback_test(emlxs_hba_t *hba, dfc_t *dfc,
66291a2b48SSukumar Swaminathan 				int32_t mode);
678f23e9faSHans Rosenfeld static int32_t		emlxs_dfc_reset_port(emlxs_hba_t *hba, dfc_t *dfc,
688f23e9faSHans Rosenfeld 				int32_t mode);
69291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_get_dump_region(emlxs_hba_t *hba, dfc_t *dfc,
70291a2b48SSukumar Swaminathan 				int32_t mode);
71291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_loopback_mode(emlxs_hba_t *hba, dfc_t *dfc,
72291a2b48SSukumar Swaminathan 				int32_t mode);
73291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_get_ioinfo(emlxs_hba_t *hba, dfc_t *dfc,
74291a2b48SSukumar Swaminathan 				int32_t mode);
75291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_get_linkinfo(emlxs_hba_t *hba, dfc_t *dfc,
76291a2b48SSukumar Swaminathan 				int32_t mode);
77291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_read_mem(emlxs_hba_t *hba, dfc_t *dfc,
78291a2b48SSukumar Swaminathan 				int32_t mode);
79291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_write_mem(emlxs_hba_t *hba, dfc_t *dfc,
80291a2b48SSukumar Swaminathan 				int32_t mode);
81291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_write_ctlreg(emlxs_hba_t *hba, dfc_t *dfc,
82291a2b48SSukumar Swaminathan 				int32_t mode);
83291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_read_ctlreg(emlxs_hba_t *hba, dfc_t *dfc,
84291a2b48SSukumar Swaminathan 				int32_t mode);
85291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_get_event(emlxs_hba_t *hba, dfc_t *dfc,
86291a2b48SSukumar Swaminathan 				int32_t mode);
87291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_set_event(emlxs_hba_t *hba, dfc_t *dfc,
88291a2b48SSukumar Swaminathan 				int32_t mode);
89291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_get_eventinfo(emlxs_hba_t *hba, dfc_t *dfc,
90291a2b48SSukumar Swaminathan 				int32_t mode);
91291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_get_nodeinfo(emlxs_hba_t *hba, dfc_t *dfc,
92291a2b48SSukumar Swaminathan 				int32_t mode);
93fcf3ce44SJohn Forte 
94fcf3ce44SJohn Forte #ifdef SFCT_SUPPORT
95291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_get_fctstat(emlxs_hba_t *hba, dfc_t *dfc,
96291a2b48SSukumar Swaminathan 				int32_t mode);
97291a2b48SSukumar Swaminathan #endif /* SFCT_SUPPORT */
9882527734SSukumar Swaminathan 
99291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_create_vport(emlxs_hba_t *hba, dfc_t *dfc,
100291a2b48SSukumar Swaminathan 				int32_t mode);
101291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_destroy_vport(emlxs_hba_t *hba, dfc_t *dfc,
102291a2b48SSukumar Swaminathan 				int32_t mode);
103291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_get_vportinfo(emlxs_hba_t *hba, dfc_t *dfc,
104291a2b48SSukumar Swaminathan 				int32_t mode);
105291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_npiv_resource(emlxs_hba_t *hba, dfc_t *dfc,
106291a2b48SSukumar Swaminathan 				int32_t mode);
107291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_npiv_test(emlxs_hba_t *hba, dfc_t *dfc,
108291a2b48SSukumar Swaminathan 				int32_t mode);
10982527734SSukumar Swaminathan static emlxs_port_t	*emlxs_vport_find_wwpn(emlxs_hba_t *hba, uint8_t *wwpn);
110fcf3ce44SJohn Forte 
111fcf3ce44SJohn Forte #ifdef DHCHAP_SUPPORT
112291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_init_auth(emlxs_hba_t *hba, dfc_t *dfc,
113291a2b48SSukumar Swaminathan 				int32_t mode);
114291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_get_auth_cfg(emlxs_hba_t *hba, dfc_t *dfc,
115291a2b48SSukumar Swaminathan 				int32_t mode);
116291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_set_auth_cfg(emlxs_hba_t *hba, dfc_t *dfc,
117291a2b48SSukumar Swaminathan 				int32_t mode);
118291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_get_auth_pwd(emlxs_hba_t *hba, dfc_t *dfc,
119291a2b48SSukumar Swaminathan 				int32_t mode);
120291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_set_auth_pwd(emlxs_hba_t *hba, dfc_t *dfc,
121291a2b48SSukumar Swaminathan 				int32_t mode);
122291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_get_auth_status(emlxs_hba_t *hba, dfc_t *dfc,
123291a2b48SSukumar Swaminathan 				int32_t mode);
124291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_get_auth_cfg_table(emlxs_hba_t *hba,
125291a2b48SSukumar Swaminathan 				dfc_t *dfc, int32_t mode);
126291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_get_auth_key_table(emlxs_hba_t *hba,
127291a2b48SSukumar Swaminathan 				dfc_t *dfc, int32_t mode);
128fcf3ce44SJohn Forte #endif	/* DHCHAP_SUPPORT */
129fcf3ce44SJohn Forte 
130291a2b48SSukumar Swaminathan #ifdef SAN_DIAG_SUPPORT
1318f23e9faSHans Rosenfeld static int32_t		emlxs_dfc_sd_set_bucket(emlxs_hba_t *hba, dfc_t *dfc,
1328f23e9faSHans Rosenfeld 				int32_t mode);
1338f23e9faSHans Rosenfeld static int32_t		emlxs_dfc_sd_destroy_bucket(emlxs_hba_t *hba,
1348f23e9faSHans Rosenfeld 				dfc_t *dfc, int32_t mode);
1358f23e9faSHans Rosenfeld static int32_t		emlxs_dfc_sd_get_bucket(emlxs_hba_t *hba, dfc_t *dfc,
1368f23e9faSHans Rosenfeld 				int32_t mode);
137291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_sd_start_collection(emlxs_hba_t *hba,
138291a2b48SSukumar Swaminathan 				dfc_t *dfc, int32_t mode);
139291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_sd_stop_collection(emlxs_hba_t *hba,
140291a2b48SSukumar Swaminathan 				dfc_t *dfc, int32_t mode);
141291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_sd_reset_collection(emlxs_hba_t *hba,
142291a2b48SSukumar Swaminathan 				dfc_t *dfc, int32_t mode);
143291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_sd_get_data(emlxs_hba_t *hba, dfc_t *dfc,
144291a2b48SSukumar Swaminathan 				int32_t mode);
145291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_sd_set_event(emlxs_hba_t *hba, dfc_t *dfc,
146291a2b48SSukumar Swaminathan 				int32_t mode);
147291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_sd_get_event(emlxs_hba_t *hba, dfc_t *dfc,
148291a2b48SSukumar Swaminathan 				int32_t mode);
14982527734SSukumar Swaminathan #endif	/* SAN_DIAG_SUPPORT */
150291a2b48SSukumar Swaminathan 
151291a2b48SSukumar Swaminathan static int32_t		emlxs_dfc_send_scsi_fcp(emlxs_hba_t *hba, dfc_t *dfc,
152291a2b48SSukumar Swaminathan 				int32_t mode);
153fcf3ce44SJohn Forte #ifdef FCIO_SUPPORT
154291a2b48SSukumar Swaminathan static int32_t		emlxs_fcio_manage(emlxs_hba_t *hba, dfc_t *dfc,
155291a2b48SSukumar Swaminathan 				int32_t mode);
1568f23e9faSHans Rosenfeld static int32_t		emlxs_fcio_get_num_devs(emlxs_port_t *port,
1578f23e9faSHans Rosenfeld 				fcio_t *fcio, int32_t mode);
1588f23e9faSHans Rosenfeld static int32_t		emlxs_fcio_get_dev_list(emlxs_port_t *port,
1598f23e9faSHans Rosenfeld 				fcio_t *fcio, int32_t mode);
1608f23e9faSHans Rosenfeld static int32_t		emlxs_fcio_get_sym_pname(emlxs_port_t *port,
1618f23e9faSHans Rosenfeld 				fcio_t *fcio, int32_t mode);
1628f23e9faSHans Rosenfeld static int32_t		emlxs_fcio_get_sym_nname(emlxs_port_t *port,
1638f23e9faSHans Rosenfeld 				fcio_t *fcio, int32_t mode);
1648f23e9faSHans Rosenfeld static int32_t		emlxs_fcio_unsupported(emlxs_port_t *port,
1658f23e9faSHans Rosenfeld 				fcio_t *fcio, int32_t mode);
1668f23e9faSHans Rosenfeld static int32_t		emlxs_fcio_get_logi_params(emlxs_port_t *port,
1678f23e9faSHans Rosenfeld 				fcio_t *fcio, int32_t mode);
1688f23e9faSHans Rosenfeld static int32_t		emlxs_fcio_get_state(emlxs_port_t *port,
1698f23e9faSHans Rosenfeld 				fcio_t *fcio, int32_t mode);
1708f23e9faSHans Rosenfeld static int32_t		emlxs_fcio_get_fcode_rev(emlxs_port_t *port,
1718f23e9faSHans Rosenfeld 				fcio_t *fcio, int32_t mode);
1728f23e9faSHans Rosenfeld static int32_t		emlxs_fcio_get_fw_rev(emlxs_port_t *port,
1738f23e9faSHans Rosenfeld 				fcio_t *fcio, int32_t mode);
1748f23e9faSHans Rosenfeld static int32_t		emlxs_fcio_get_dump_size(emlxs_port_t *port,
1758f23e9faSHans Rosenfeld 				fcio_t *fcio, int32_t mode);
1768f23e9faSHans Rosenfeld static int32_t		emlxs_fcio_force_dump(emlxs_port_t *port,
1778f23e9faSHans Rosenfeld 				fcio_t *fcio, int32_t mode);
1788f23e9faSHans Rosenfeld static int32_t		emlxs_fcio_get_dump(emlxs_port_t *port,
1798f23e9faSHans Rosenfeld 				fcio_t *fcio, int32_t mode);
1808f23e9faSHans Rosenfeld static int32_t		emlxs_fcio_get_topology(emlxs_port_t *port,
1818f23e9faSHans Rosenfeld 				fcio_t *fcio, int32_t mode);
1828f23e9faSHans Rosenfeld static int32_t		emlxs_fcio_reset_link(emlxs_port_t *port,
1838f23e9faSHans Rosenfeld 				fcio_t *fcio, int32_t mode);
1848f23e9faSHans Rosenfeld static int32_t		emlxs_fcio_reset_hard(emlxs_port_t *port,
1858f23e9faSHans Rosenfeld 				fcio_t *fcio, int32_t mode);
1868f23e9faSHans Rosenfeld static int32_t		emlxs_fcio_diag(emlxs_port_t *port,
1878f23e9faSHans Rosenfeld 				fcio_t *fcio, int32_t mode);
1888f23e9faSHans Rosenfeld static int32_t		emlxs_fcio_download_fw(emlxs_port_t *port,
1898f23e9faSHans Rosenfeld 				fcio_t *fcio, int32_t mode);
1908f23e9faSHans Rosenfeld static int32_t		emlxs_fcio_get_host_params(emlxs_port_t *port,
1918f23e9faSHans Rosenfeld 				fcio_t *fcio, int32_t mode);
1928f23e9faSHans Rosenfeld static int32_t		emlxs_fcio_get_link_status(emlxs_port_t *port,
1938f23e9faSHans Rosenfeld 				fcio_t *fcio, int32_t mode);
1948f23e9faSHans Rosenfeld static int32_t		emlxs_fcio_download_fcode(emlxs_port_t *port,
1958f23e9faSHans Rosenfeld 				fcio_t *fcio, int32_t mode);
1968f23e9faSHans Rosenfeld static int32_t		emlxs_fcio_get_node_id(emlxs_port_t *port,
1978f23e9faSHans Rosenfeld 				fcio_t *fcio, int32_t mode);
1988f23e9faSHans Rosenfeld static int32_t		emlxs_fcio_set_node_id(emlxs_port_t *port,
1998f23e9faSHans Rosenfeld 				fcio_t *fcio, int32_t mode);
2008f23e9faSHans Rosenfeld static int32_t		emlxs_fcio_get_adapter_attrs(emlxs_port_t *port,
2018f23e9faSHans Rosenfeld 				fcio_t *fcio, int32_t mode);
2028f23e9faSHans Rosenfeld static int32_t		emlxs_fcio_get_other_adapter_ports(emlxs_port_t *port,
2038f23e9faSHans Rosenfeld 				fcio_t *fcio, int32_t mode);
2048f23e9faSHans Rosenfeld static int32_t		emlxs_fcio_get_adapter_port_attrs(emlxs_port_t *port,
2058f23e9faSHans Rosenfeld 				fcio_t *fcio, int32_t mode);
2068f23e9faSHans Rosenfeld static int32_t		emlxs_fcio_get_disc_port_attrs(emlxs_port_t *port,
2078f23e9faSHans Rosenfeld 				fcio_t *fcio, int32_t mode);
2088f23e9faSHans Rosenfeld static int32_t		emlxs_fcio_get_port_attrs(emlxs_port_t *port,
2098f23e9faSHans Rosenfeld 				fcio_t *fcio, int32_t mode);
210fcf3ce44SJohn Forte #endif	/* FCIO_SUPPORT */
211fcf3ce44SJohn Forte 
21282527734SSukumar Swaminathan static int32_t		emlxs_dfc_get_persist_linkdown(emlxs_hba_t *hba,
21382527734SSukumar Swaminathan 				dfc_t *dfc, int32_t mode);
21482527734SSukumar Swaminathan static int32_t		emlxs_dfc_set_persist_linkdown(emlxs_hba_t *hba,
21582527734SSukumar Swaminathan 				dfc_t *dfc, int32_t mode);
21682527734SSukumar Swaminathan 
21782527734SSukumar Swaminathan /* SLI-4 ioctls */
21882527734SSukumar Swaminathan static int32_t		emlxs_dfc_get_fcflist(emlxs_hba_t *hba, dfc_t *dfc,
21982527734SSukumar Swaminathan 				int32_t mode);
22082527734SSukumar Swaminathan static int32_t		emlxs_dfc_send_mbox4(emlxs_hba_t *hba, dfc_t *dfc,
22182527734SSukumar Swaminathan 				int32_t mode);
22282527734SSukumar Swaminathan static int		emlxs_dfc_rd_be_fcf(emlxs_hba_t *hba, dfc_t *dfc,
22382527734SSukumar Swaminathan 			    int32_t mode);
22482527734SSukumar Swaminathan static int		emlxs_dfc_set_be_dcbx(emlxs_hba_t *hba, dfc_t *dfc,
22582527734SSukumar Swaminathan 			    int32_t mode);
22682527734SSukumar Swaminathan static int		emlxs_dfc_get_be_dcbx(emlxs_hba_t *hba, dfc_t *dfc,
22782527734SSukumar Swaminathan 			    int32_t mode);
228b3660a96SSukumar Swaminathan static int		emlxs_dfc_get_qos(emlxs_hba_t *hba, dfc_t *dfc,
229b3660a96SSukumar Swaminathan 			    int32_t mode);
23082527734SSukumar Swaminathan 
231291a2b48SSukumar Swaminathan uint32_t	emlxs_loopback_tmo = 60;
232fcf3ce44SJohn Forte 
2338f23e9faSHans Rosenfeld typedef struct
2348f23e9faSHans Rosenfeld {
2358f23e9faSHans Rosenfeld 	uint32_t	code;
2368f23e9faSHans Rosenfeld 	char		string[32];
2378f23e9faSHans Rosenfeld 	int		(*func)(emlxs_hba_t *hba, dfc_t *dfc, int32_t mode);
2388f23e9faSHans Rosenfeld } emlxs_dfc_table_t;
2398f23e9faSHans Rosenfeld 
2408f23e9faSHans Rosenfeld emlxs_dfc_table_t emlxs_dfc_table[] = {
2418f23e9faSHans Rosenfeld 	{EMLXS_GET_HBAINFO, "GET_HBAINFO", emlxs_dfc_get_hbainfo},
2428f23e9faSHans Rosenfeld 	{EMLXS_GET_REV, "GET_REV", emlxs_dfc_get_rev},
2438f23e9faSHans Rosenfeld 	{EMLXS_SET_DIAG, "SET_DIAG", emlxs_dfc_set_diag},
2448f23e9faSHans Rosenfeld 	{EMLXS_SEND_MBOX, "SEND_MBOX", emlxs_dfc_send_mbox},
2458f23e9faSHans Rosenfeld 	{EMLXS_READ_PCI, "READ_PCI", emlxs_dfc_read_pci},
2468f23e9faSHans Rosenfeld 	{EMLXS_WRITE_PCI, "WRITE_PCI", emlxs_dfc_write_pci},
2478f23e9faSHans Rosenfeld 	{EMLXS_GET_CFG, "GET_CFG", emlxs_dfc_get_cfg},
2488f23e9faSHans Rosenfeld 	{EMLXS_SET_CFG, "SET_CFG", emlxs_dfc_set_cfg},
2498f23e9faSHans Rosenfeld 	{EMLXS_SEND_CT, "SEND_CT", emlxs_dfc_send_ct},
2508f23e9faSHans Rosenfeld 	{EMLXS_SEND_CT_RSP, "SEND_CT_RSP", emlxs_dfc_send_ct_rsp},
2518f23e9faSHans Rosenfeld 	{EMLXS_WRITE_FLASH, "WRITE_FLASH", emlxs_dfc_write_flash},
2528f23e9faSHans Rosenfeld 	{EMLXS_READ_FLASH, "READ_FLASH", emlxs_dfc_read_flash},
2538f23e9faSHans Rosenfeld 	{EMLXS_SEND_ELS, "SEND_ELS", emlxs_dfc_send_els},
2548f23e9faSHans Rosenfeld 	{EMLXS_LOOPBACK_TEST, "LOOPBACK_TEST", emlxs_dfc_loopback_test},
2558f23e9faSHans Rosenfeld 	{EMLXS_RESET_PORT, "RESET_PORT", emlxs_dfc_reset_port},
2568f23e9faSHans Rosenfeld 	{EMLXS_GET_DUMPREGION, "GET_DUMPREGION", emlxs_dfc_get_dump_region},
2578f23e9faSHans Rosenfeld 	{EMLXS_LOOPBACK_MODE, "LOOPBACK_MODE", emlxs_dfc_loopback_mode},
2588f23e9faSHans Rosenfeld 	{EMLXS_GET_IOINFO, "GET_IOINFO", emlxs_dfc_get_ioinfo},
2598f23e9faSHans Rosenfeld 	{EMLXS_GET_LINKINFO, "GET_LINKINFO", emlxs_dfc_get_linkinfo},
2608f23e9faSHans Rosenfeld 	{EMLXS_GET_NODEINFO, "GET_NODEINFO", emlxs_dfc_get_nodeinfo},
2618f23e9faSHans Rosenfeld 	{EMLXS_READ_MEM, "READ_MEM", emlxs_dfc_read_mem},
2628f23e9faSHans Rosenfeld 	{EMLXS_WRITE_MEM, "WRITE_MEM", emlxs_dfc_write_mem},
2638f23e9faSHans Rosenfeld 	{EMLXS_WRITE_CTLREG, "WRITE_CTLREG", emlxs_dfc_write_ctlreg},
2648f23e9faSHans Rosenfeld 	{EMLXS_READ_CTLREG, "READ_CTLREG", emlxs_dfc_read_ctlreg},
2658f23e9faSHans Rosenfeld 	{EMLXS_SEND_SCSI, "SEND_SCSI", emlxs_dfc_send_scsi_fcp},
2668f23e9faSHans Rosenfeld 	{EMLXS_GET_EVENT, "GET_EVENT", emlxs_dfc_get_event},
2678f23e9faSHans Rosenfeld 	{EMLXS_SET_EVENT, "SET_EVENT", emlxs_dfc_set_event},
2688f23e9faSHans Rosenfeld 	{EMLXS_GET_EVENTINFO, "GET_EVENTINFO", emlxs_dfc_get_eventinfo},
2698f23e9faSHans Rosenfeld 	{EMLXS_GET_HBASTATS, "GET_HBASTATS", emlxs_dfc_get_hbastats},
2708f23e9faSHans Rosenfeld 	{EMLXS_GET_DRVSTATS, "GET_DRVSTATS", emlxs_dfc_get_drvstats},
2718f23e9faSHans Rosenfeld 	{EMLXS_CREATE_VPORT, "CREATE_VPORT", emlxs_dfc_create_vport},
2728f23e9faSHans Rosenfeld 	{EMLXS_DESTROY_VPORT, "DESTROY_VPORT", emlxs_dfc_destroy_vport},
2738f23e9faSHans Rosenfeld 	{EMLXS_GET_VPORTINFO, "GET_VPORTINFO", emlxs_dfc_get_vportinfo},
2748f23e9faSHans Rosenfeld 	{EMLXS_NPIV_RESOURCE, "NPIV_RESOURCE", emlxs_dfc_npiv_resource},
2758f23e9faSHans Rosenfeld 	{EMLXS_NPIV_TEST, "NPIV_TEST", emlxs_dfc_npiv_test},
2768f23e9faSHans Rosenfeld 	{EMLXS_GET_PERSIST_LINKDOWN, "GET_PERSIST_LINKDOWN",
2778f23e9faSHans Rosenfeld 	    emlxs_dfc_get_persist_linkdown},
2788f23e9faSHans Rosenfeld 	{EMLXS_SET_PERSIST_LINKDOWN, "SET_PERSIST_LINKDOWN",
2798f23e9faSHans Rosenfeld 	    emlxs_dfc_set_persist_linkdown},
2808f23e9faSHans Rosenfeld 	{EMLXS_GET_FCOE_FCFLIST, "GET_FCOE_FCFLIST", emlxs_dfc_get_fcflist},
2818f23e9faSHans Rosenfeld 	{EMLXS_SEND_MBOX4, "SEND_MBOX4", emlxs_dfc_send_mbox4},
2828f23e9faSHans Rosenfeld 	{EMLXS_RD_BE_FCF, "RD_BE_FCF", emlxs_dfc_rd_be_fcf},
2838f23e9faSHans Rosenfeld 	{EMLXS_SET_BE_DCBX, "SET_BE_DCBX", emlxs_dfc_set_be_dcbx},
2848f23e9faSHans Rosenfeld 	{EMLXS_GET_BE_DCBX, "GET_BE_DCBX", emlxs_dfc_get_be_dcbx},
2858f23e9faSHans Rosenfeld 	{EMLXS_GET_QOS, "GET_QOS", emlxs_dfc_get_qos},
2868f23e9faSHans Rosenfeld #ifdef MENLO_SUPPORT
2878f23e9faSHans Rosenfeld 	{EMLXS_SEND_MENLO, "SEND_MENLO", emlxs_dfc_send_menlo},
2888f23e9faSHans Rosenfeld #endif /* MENLO_SUPPORT */
2898f23e9faSHans Rosenfeld #ifdef DHCHAP_SUPPORT
2908f23e9faSHans Rosenfeld 	{EMLXS_INIT_AUTH, "INIT_AUTH", emlxs_dfc_init_auth},
2918f23e9faSHans Rosenfeld 	{EMLXS_GET_AUTH_CFG, "GET_AUTH_CFG", emlxs_dfc_get_auth_cfg},
2928f23e9faSHans Rosenfeld 	{EMLXS_SET_AUTH_CFG, "SET_AUTH_CFG", emlxs_dfc_set_auth_cfg},
2938f23e9faSHans Rosenfeld 	{EMLXS_GET_AUTH_PASSWORD, "GET_AUTH_PASSWORD", emlxs_dfc_get_auth_pwd},
2948f23e9faSHans Rosenfeld 	{EMLXS_SET_AUTH_PASSWORD, "SET_AUTH_PASSWORD", emlxs_dfc_set_auth_pwd},
2958f23e9faSHans Rosenfeld 	{EMLXS_GET_AUTH_STATUS, "GET_AUTH_STATUS", emlxs_dfc_get_auth_status},
2968f23e9faSHans Rosenfeld 	{EMLXS_GET_AUTH_CFG_TABLE, "GET_AUTH_CFG_TABLE",
2978f23e9faSHans Rosenfeld 	    emlxs_dfc_get_auth_cfg_table},
2988f23e9faSHans Rosenfeld 	{EMLXS_GET_AUTH_KEY_TABLE, "GET_AUTH_KEY_TABLE",
2998f23e9faSHans Rosenfeld 	    emlxs_dfc_get_auth_key_table},
3008f23e9faSHans Rosenfeld #endif	/* DHCHAP_SUPPORT */
3018f23e9faSHans Rosenfeld #ifdef FCIO_SUPPORT
3028f23e9faSHans Rosenfeld 	{EMLXS_FCIO_CMD, "FCIO_CMD", emlxs_fcio_manage},
3038f23e9faSHans Rosenfeld #endif /* FCIO_SUPPORT */
3048f23e9faSHans Rosenfeld #ifdef SFCT_SUPPORT
3058f23e9faSHans Rosenfeld 	{EMLXS_GET_FCTSTAT, "GET_FCTSTAT", emlxs_dfc_get_fctstat},
3068f23e9faSHans Rosenfeld #endif /* SFCT_SUPPORT */
3078f23e9faSHans Rosenfeld #ifdef SAN_DIAG_SUPPORT
3088f23e9faSHans Rosenfeld 	{EMLXS_SD_SET_BUCKET, "SD_SET_BUCKET", emlxs_dfc_sd_set_bucket},
3098f23e9faSHans Rosenfeld 	{EMLXS_SD_DESTROY_BUCKET, "SD_DESTROY_BUCKET",
3108f23e9faSHans Rosenfeld 	    emlxs_dfc_sd_destroy_bucket},
3118f23e9faSHans Rosenfeld 	{EMLXS_SD_GET_BUCKET, "SD_GET_BUCKET", emlxs_dfc_sd_get_bucket},
3128f23e9faSHans Rosenfeld 	{EMLXS_SD_START_DATA_COLLECTION, "SD_START_DATA_COLLECTION",
3138f23e9faSHans Rosenfeld 	    emlxs_dfc_sd_start_collection},
3148f23e9faSHans Rosenfeld 	{EMLXS_SD_STOP_DATA_COLLECTION, "SD_STOP_DATA_COLLECTION",
3158f23e9faSHans Rosenfeld 	    emlxs_dfc_sd_stop_collection},
3168f23e9faSHans Rosenfeld 	{EMLXS_SD_RESET_DATA_COLLECTION, "SD_RESET_DATA_COLLECTION",
3178f23e9faSHans Rosenfeld 	    emlxs_dfc_sd_reset_collection},
3188f23e9faSHans Rosenfeld 	{EMLXS_SD_GET_DATA, "SD_GET_DATA", emlxs_dfc_sd_get_data},
3198f23e9faSHans Rosenfeld 	{EMLXS_SD_SET_EVENT, "SD_SET_EVENT", emlxs_dfc_sd_set_event},
3208f23e9faSHans Rosenfeld 	{EMLXS_SD_GET_EVENT, "SD_GET_EVENT", emlxs_dfc_sd_get_event},
3218f23e9faSHans Rosenfeld #endif	/* SAN_DIAG_SUPPORT */
322fcf3ce44SJohn Forte };	/* emlxs_dfc_table */
323fcf3ce44SJohn Forte 
324fcf3ce44SJohn Forte 
325291a2b48SSukumar Swaminathan emlxs_table_t emlxs_dfc_event_table[] = {
326291a2b48SSukumar Swaminathan 	{FC_REG_LINK_EVENT,		"LINK_EVENT"},
327291a2b48SSukumar Swaminathan 	{FC_REG_RSCN_EVENT,		"RSCN_EVENT"},
328291a2b48SSukumar Swaminathan 	{FC_REG_CT_EVENT,		"CT_EVENT"},
329291a2b48SSukumar Swaminathan 	{FC_REG_DUMP_EVENT,		"DUMP_EVENT"},
330291a2b48SSukumar Swaminathan 	{FC_REG_TEMP_EVENT,		"TEMP_EVENT"},
331291a2b48SSukumar Swaminathan 	{FC_REG_VPORTRSCN_EVENT,	"VPORTRSCN_EVENT"},
332291a2b48SSukumar Swaminathan 	{FC_REG_FCOE_EVENT,		"FCOE_EVENT"},
333fcf3ce44SJohn Forte 
334fcf3ce44SJohn Forte };	/* emlxs_dfc_event_table */
335fcf3ce44SJohn Forte 
336fcf3ce44SJohn Forte 
337291a2b48SSukumar Swaminathan #ifdef SAN_DIAG_SUPPORT
3388f23e9faSHans Rosenfeld kmutex_t		emlxs_sd_bucket_mutex;
3398f23e9faSHans Rosenfeld sd_bucket_info_t	emlxs_sd_bucket;
34082527734SSukumar Swaminathan #endif	/* SAN_DIAG_SUPPORT */
341291a2b48SSukumar Swaminathan 
342291a2b48SSukumar Swaminathan extern char    *
emlxs_dfc_xlate(uint16_t cmd)343fcf3ce44SJohn Forte emlxs_dfc_xlate(uint16_t cmd)
344fcf3ce44SJohn Forte {
345291a2b48SSukumar Swaminathan 	static char	buffer[32];
346291a2b48SSukumar Swaminathan 	uint32_t	i;
347291a2b48SSukumar Swaminathan 	uint32_t	count;
348fcf3ce44SJohn Forte 
3498f23e9faSHans Rosenfeld 	count = sizeof (emlxs_dfc_table) / sizeof (emlxs_dfc_table_t);
350fcf3ce44SJohn Forte 	for (i = 0; i < count; i++) {
351fcf3ce44SJohn Forte 		if (cmd == emlxs_dfc_table[i].code) {
352fcf3ce44SJohn Forte 			return (emlxs_dfc_table[i].string);
353fcf3ce44SJohn Forte 		}
354fcf3ce44SJohn Forte 	}
355fcf3ce44SJohn Forte 
3568f23e9faSHans Rosenfeld 	(void) snprintf(buffer, sizeof (buffer), "Cmd=0x%x", cmd);
357fcf3ce44SJohn Forte 	return (buffer);
358fcf3ce44SJohn Forte 
359fcf3ce44SJohn Forte } /* emlxs_dfc_xlate() */
360fcf3ce44SJohn Forte 
361fcf3ce44SJohn Forte 
3628f23e9faSHans Rosenfeld static int
emlxs_dfc_func(emlxs_hba_t * hba,dfc_t * dfc,int32_t mode)3638f23e9faSHans Rosenfeld emlxs_dfc_func(emlxs_hba_t *hba, dfc_t *dfc, int32_t mode)
3648f23e9faSHans Rosenfeld {
3658f23e9faSHans Rosenfeld 	emlxs_port_t *port = &PPORT;
3668f23e9faSHans Rosenfeld 	uint32_t	i;
3678f23e9faSHans Rosenfeld 	uint32_t	count;
3688f23e9faSHans Rosenfeld 	int		rval;
3698f23e9faSHans Rosenfeld 
3708f23e9faSHans Rosenfeld 	count = sizeof (emlxs_dfc_table) / sizeof (emlxs_dfc_table_t);
3718f23e9faSHans Rosenfeld 	for (i = 0; i < count; i++) {
3728f23e9faSHans Rosenfeld 		if (dfc->cmd == emlxs_dfc_table[i].code) {
3738f23e9faSHans Rosenfeld 			if ((dfc->cmd != EMLXS_FCIO_CMD) ||
3748f23e9faSHans Rosenfeld 			    (dfc->data1 != FCIO_DIAG) ||
3758f23e9faSHans Rosenfeld 			    (dfc->data2 != EMLXS_LOG_GET)) {
3768f23e9faSHans Rosenfeld 				EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_dfc_detail_msg,
3778f23e9faSHans Rosenfeld 				    "%s requested.",
3788f23e9faSHans Rosenfeld 				    emlxs_dfc_table[i].string);
3798f23e9faSHans Rosenfeld 			}
3808f23e9faSHans Rosenfeld 
3818f23e9faSHans Rosenfeld 			rval = emlxs_dfc_table[i].func(hba, dfc, mode);
3828f23e9faSHans Rosenfeld 			return (rval);
3838f23e9faSHans Rosenfeld 		}
3848f23e9faSHans Rosenfeld 	}
3858f23e9faSHans Rosenfeld 
3868f23e9faSHans Rosenfeld 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_dfc_detail_msg,
3878f23e9faSHans Rosenfeld 	    "Unknown DFC command. (0x%x)", dfc->cmd);
3888f23e9faSHans Rosenfeld 
3898f23e9faSHans Rosenfeld 	return (DFC_ARG_INVALID);
3908f23e9faSHans Rosenfeld 
3918f23e9faSHans Rosenfeld } /* emlxs_dfc_func() */
3928f23e9faSHans Rosenfeld 
3938f23e9faSHans Rosenfeld 
394291a2b48SSukumar Swaminathan extern char    *
emlxs_dfc_event_xlate(uint32_t event)395fcf3ce44SJohn Forte emlxs_dfc_event_xlate(uint32_t event)
396fcf3ce44SJohn Forte {
397291a2b48SSukumar Swaminathan 	static char	buffer[32];
398291a2b48SSukumar Swaminathan 	uint32_t	i;
399291a2b48SSukumar Swaminathan 	uint32_t	count;
400fcf3ce44SJohn Forte 
401fcf3ce44SJohn Forte 	count = sizeof (emlxs_dfc_event_table) / sizeof (emlxs_table_t);
402fcf3ce44SJohn Forte 	for (i = 0; i < count; i++) {
403fcf3ce44SJohn Forte 		if (event == emlxs_dfc_event_table[i].code) {
404fcf3ce44SJohn Forte 			return (emlxs_dfc_event_table[i].string);
405fcf3ce44SJohn Forte 		}
406fcf3ce44SJohn Forte 	}
407fcf3ce44SJohn Forte 
4088f23e9faSHans Rosenfeld 	(void) snprintf(buffer, sizeof (buffer), "Event=0x%x", event);
409fcf3ce44SJohn Forte 	return (buffer);
410fcf3ce44SJohn Forte 
411fcf3ce44SJohn Forte } /* emlxs_dfc_event_xlate() */
412fcf3ce44SJohn Forte 
413fcf3ce44SJohn Forte 
4148f23e9faSHans Rosenfeld static int32_t
emlxs_dfc_copyin(emlxs_hba_t * hba,void * arg,dfc_t * dfc1,dfc_t * dfc2,int32_t mode)4158f23e9faSHans Rosenfeld emlxs_dfc_copyin(emlxs_hba_t *hba, void *arg, dfc_t *dfc1, dfc_t *dfc2,
4168f23e9faSHans Rosenfeld     int32_t mode)
417fcf3ce44SJohn Forte {
418291a2b48SSukumar Swaminathan 	emlxs_port_t	*port = &PPORT;
419291a2b48SSukumar Swaminathan 	int		rval = 0;
4208f23e9faSHans Rosenfeld 	uint32_t	use32 = 0;
421fcf3ce44SJohn Forte 
422fcf3ce44SJohn Forte #ifdef	_MULTI_DATAMODEL
4238f23e9faSHans Rosenfeld 	if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) {
4248f23e9faSHans Rosenfeld 		use32 = 1;
4258f23e9faSHans Rosenfeld 	}
4268f23e9faSHans Rosenfeld #endif	/* _MULTI_DATAMODEL */
427fcf3ce44SJohn Forte 
4288f23e9faSHans Rosenfeld 	if (use32) {
4298f23e9faSHans Rosenfeld 		dfc32_t dfc32;
430291a2b48SSukumar Swaminathan 
4318f23e9faSHans Rosenfeld 		if (ddi_copyin((void *)arg, (void *)&dfc32,
4328f23e9faSHans Rosenfeld 		    sizeof (dfc32_t), mode)) {
4338f23e9faSHans Rosenfeld 			EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_dfc_error_msg,
4348f23e9faSHans Rosenfeld 			    "ddi_copyin32 failed.");
435fcf3ce44SJohn Forte 
4368f23e9faSHans Rosenfeld 			rval = DFC_COPYIN_ERROR;
4378f23e9faSHans Rosenfeld 			goto done;
438fcf3ce44SJohn Forte 		}
439fcf3ce44SJohn Forte 
4408f23e9faSHans Rosenfeld 		dfc1->cmd = dfc32.cmd;
4418f23e9faSHans Rosenfeld 		dfc1->flag = dfc32.flag;
4428f23e9faSHans Rosenfeld 		dfc1->buf1 = (void *)((uintptr_t)dfc32.buf1);
4438f23e9faSHans Rosenfeld 		dfc1->buf1_size = dfc32.buf1_size;
4448f23e9faSHans Rosenfeld 		dfc1->data1 = dfc32.data1;
4458f23e9faSHans Rosenfeld 		dfc1->buf2 = (void *)((uintptr_t)dfc32.buf2);
4468f23e9faSHans Rosenfeld 		dfc1->buf2_size = dfc32.buf2_size;
4478f23e9faSHans Rosenfeld 		dfc1->data2 = dfc32.data2;
4488f23e9faSHans Rosenfeld 		dfc1->buf3 = (void *)((uintptr_t)dfc32.buf3);
4498f23e9faSHans Rosenfeld 		dfc1->buf3_size = dfc32.buf3_size;
4508f23e9faSHans Rosenfeld 		dfc1->data3 = dfc32.data3;
4518f23e9faSHans Rosenfeld 		dfc1->buf4 = (void *)((uintptr_t)dfc32.buf4);
4528f23e9faSHans Rosenfeld 		dfc1->buf4_size = dfc32.buf4_size;
4538f23e9faSHans Rosenfeld 		dfc1->data4 = dfc32.data4;
4548f23e9faSHans Rosenfeld 
4558f23e9faSHans Rosenfeld 	} else {
4568f23e9faSHans Rosenfeld 		if (ddi_copyin((void *)arg, (void *)dfc1, sizeof (dfc_t),
457291a2b48SSukumar Swaminathan 		    mode)) {
458fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_dfc_error_msg,
4598f23e9faSHans Rosenfeld 			    "ddi_copyin failed.");
460fcf3ce44SJohn Forte 
461fcf3ce44SJohn Forte 			rval = DFC_COPYIN_ERROR;
4628f23e9faSHans Rosenfeld 			goto done;
463fcf3ce44SJohn Forte 		}
464fcf3ce44SJohn Forte 	}
465fcf3ce44SJohn Forte 
4668f23e9faSHans Rosenfeld 	/* Map dfc1 to dfc2 */
4678f23e9faSHans Rosenfeld 	dfc2->cmd   = dfc1->cmd;
4688f23e9faSHans Rosenfeld 	dfc2->flag  = dfc1->flag;
4698f23e9faSHans Rosenfeld 	dfc2->data1 = dfc1->data1;
4708f23e9faSHans Rosenfeld 	dfc2->data2 = dfc1->data2;
4718f23e9faSHans Rosenfeld 	dfc2->data3 = dfc1->data3;
4728f23e9faSHans Rosenfeld 	dfc2->data4 = dfc1->data4;
4738f23e9faSHans Rosenfeld 	dfc2->buf1  = 0;
4748f23e9faSHans Rosenfeld 	dfc2->buf1_size = 0;
4758f23e9faSHans Rosenfeld 	dfc2->buf2  = 0;
4768f23e9faSHans Rosenfeld 	dfc2->buf2_size = 0;
4778f23e9faSHans Rosenfeld 	dfc2->buf3  = 0;
4788f23e9faSHans Rosenfeld 	dfc2->buf3_size = 0;
4798f23e9faSHans Rosenfeld 	dfc2->buf4  = 0;
4808f23e9faSHans Rosenfeld 	dfc2->buf4_size = 0;
4818f23e9faSHans Rosenfeld 
4828f23e9faSHans Rosenfeld 	/* Copyin data buffers */
4838f23e9faSHans Rosenfeld 	if (dfc1->buf1_size && dfc1->buf1) {
4848f23e9faSHans Rosenfeld 		dfc2->buf1_size = dfc1->buf1_size;
4858f23e9faSHans Rosenfeld 		dfc2->buf1 = kmem_zalloc(dfc1->buf1_size, KM_SLEEP);
4868f23e9faSHans Rosenfeld 
4878f23e9faSHans Rosenfeld 		if (ddi_copyin(dfc1->buf1, dfc2->buf1, dfc1->buf1_size,
4888f23e9faSHans Rosenfeld 		    mode)) {
4898f23e9faSHans Rosenfeld 			EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_dfc_error_msg,
4908f23e9faSHans Rosenfeld 			    "%s: buf1 ddi_copyin failed. (size=%d)",
4918f23e9faSHans Rosenfeld 			    emlxs_dfc_xlate(dfc1->cmd),
4928f23e9faSHans Rosenfeld 			    dfc1->buf1_size);
493fcf3ce44SJohn Forte 
4948f23e9faSHans Rosenfeld 			rval = DFC_COPYIN_ERROR;
4958f23e9faSHans Rosenfeld 			goto done;
4968f23e9faSHans Rosenfeld 		}
4978f23e9faSHans Rosenfeld 	}
498fcf3ce44SJohn Forte 
4998f23e9faSHans Rosenfeld 	if (dfc1->buf2_size && dfc1->buf2) {
5008f23e9faSHans Rosenfeld 		dfc2->buf2_size = dfc1->buf2_size;
5018f23e9faSHans Rosenfeld 		dfc2->buf2 = kmem_zalloc(dfc1->buf2_size, KM_SLEEP);
502fcf3ce44SJohn Forte 
5038f23e9faSHans Rosenfeld 		if (ddi_copyin(dfc1->buf2, dfc2->buf2, dfc1->buf2_size,
5048f23e9faSHans Rosenfeld 		    mode)) {
5058f23e9faSHans Rosenfeld 			EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_dfc_error_msg,
5068f23e9faSHans Rosenfeld 			    "%s: buf2 ddi_copyin failed. (size=%d)",
5078f23e9faSHans Rosenfeld 			    emlxs_dfc_xlate(dfc1->cmd),
5088f23e9faSHans Rosenfeld 			    dfc1->buf2_size);
509fcf3ce44SJohn Forte 
5108f23e9faSHans Rosenfeld 			rval = DFC_COPYIN_ERROR;
5118f23e9faSHans Rosenfeld 			goto done;
512fcf3ce44SJohn Forte 		}
5138f23e9faSHans Rosenfeld 	}
514fcf3ce44SJohn Forte 
5158f23e9faSHans Rosenfeld 	if (dfc1->buf3_size && dfc1->buf3) {
5168f23e9faSHans Rosenfeld 		dfc2->buf3_size = dfc1->buf3_size;
5178f23e9faSHans Rosenfeld 		dfc2->buf3 = kmem_zalloc(dfc1->buf3_size, KM_SLEEP);
518fcf3ce44SJohn Forte 
5198f23e9faSHans Rosenfeld 		if (ddi_copyin(dfc1->buf3, dfc2->buf3, dfc1->buf3_size,
5208f23e9faSHans Rosenfeld 		    mode)) {
5218f23e9faSHans Rosenfeld 			EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_dfc_error_msg,
5228f23e9faSHans Rosenfeld 			    "%s buf3 ddi_copyin failed. (size=%d)",
5238f23e9faSHans Rosenfeld 			    emlxs_dfc_xlate(dfc1->cmd),
5248f23e9faSHans Rosenfeld 			    dfc1->buf3_size);
525fcf3ce44SJohn Forte 
5268f23e9faSHans Rosenfeld 			rval = DFC_COPYIN_ERROR;
5278f23e9faSHans Rosenfeld 			goto done;
528fcf3ce44SJohn Forte 		}
5298f23e9faSHans Rosenfeld 	}
530fcf3ce44SJohn Forte 
5318f23e9faSHans Rosenfeld 	if (dfc1->buf4_size && dfc1->buf4) {
5328f23e9faSHans Rosenfeld 		dfc2->buf4_size = dfc1->buf4_size;
5338f23e9faSHans Rosenfeld 		dfc2->buf4 = kmem_zalloc(dfc1->buf4_size, KM_SLEEP);
534fcf3ce44SJohn Forte 
5358f23e9faSHans Rosenfeld 		if (ddi_copyin(dfc1->buf4, dfc2->buf4, dfc1->buf4_size,
5368f23e9faSHans Rosenfeld 		    mode)) {
5378f23e9faSHans Rosenfeld 			EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_dfc_error_msg,
5388f23e9faSHans Rosenfeld 			    "%s: buf4 ddi_copyin failed. (size=%d)",
5398f23e9faSHans Rosenfeld 			    emlxs_dfc_xlate(dfc1->cmd),
5408f23e9faSHans Rosenfeld 			    dfc1->buf4_size);
541fcf3ce44SJohn Forte 
5428f23e9faSHans Rosenfeld 			rval = DFC_COPYIN_ERROR;
5438f23e9faSHans Rosenfeld 			goto done;
544fcf3ce44SJohn Forte 		}
5458f23e9faSHans Rosenfeld 	}
546fcf3ce44SJohn Forte 
5478f23e9faSHans Rosenfeld done:
5488f23e9faSHans Rosenfeld 	return (rval);
549fcf3ce44SJohn Forte 
5508f23e9faSHans Rosenfeld } /* emlxs_dfc_copyin() */
551fcf3ce44SJohn Forte 
552fcf3ce44SJohn Forte 
5538f23e9faSHans Rosenfeld static int32_t
emlxs_dfc_copyout(emlxs_hba_t * hba,void * arg,dfc_t * dfc2,dfc_t * dfc1,int32_t mode)554