1/*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 *  Copyright (c) 2009-2020 Alexander Motin <mav@FreeBSD.org>
5 *  Copyright (c) 1997-2009 by Matthew Jacob
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 *
12 *  1. Redistributions of source code must retain the above copyright
13 *     notice, this list of conditions and the following disclaimer.
14 *  2. Redistributions in binary form must reproduce the above copyright
15 *     notice, this list of conditions and the following disclaimer in the
16 *     documentation and/or other materials provided with the distribution.
17 *
18 *  THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 *  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 *  ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
22 *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 *  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 *  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 *  SUCH DAMAGE.
29 *
30 */
31#ifndef _ISP_LIBRARY_H
32#define _ISP_LIBRARY_H
33
34/*
35 * Common command shipping routine.
36 *
37 * This used to be platform specific, but basically once you get the segment
38 * stuff figured out, you can make all the code in one spot.
39 */
40int isp_send_cmd(ispsoftc_t *, void *, void *, uint32_t);
41
42/*
43 * Handle management functions.
44 *
45 * These handles are associate with a command.
46 */
47uint32_t isp_allocate_handle(ispsoftc_t *, void *, int);
48void *isp_find_xs(ispsoftc_t *, uint32_t);
49uint32_t isp_find_handle(ispsoftc_t *, void *);
50void isp_destroy_handle(ispsoftc_t *, uint32_t);
51
52/*
53 * Request Queue allocation
54 */
55static inline int
56isp_rqentry_avail(ispsoftc_t *isp, uint32_t num)
57{
58	if (ISP_QAVAIL(isp) >= num)
59		return (1);
60	/* We don't have enough in cached.  Reread the hardware. */
61	isp->isp_reqodx = ISP_READ(isp, BIU2400_REQOUTP);
62	return (ISP_QAVAIL(isp) >= num);
63}
64
65static inline void *
66isp_getrqentry(ispsoftc_t *isp)
67{
68	if (!isp_rqentry_avail(isp, 1))
69		return (NULL);
70	return (ISP_QUEUE_ENTRY(isp->isp_rquest, isp->isp_reqidx));
71}
72
73/*
74 * Queue Entry debug functions
75 */
76void isp_print_qentry (ispsoftc_t *, const char *, int, void *);
77void isp_print_bytes(ispsoftc_t *, const char *, int, void *);
78
79/*
80 * Fibre Channel specific routines and data.
81 */
82extern const char *isp_class3_roles[4];
83int isp_fc_runstate(ispsoftc_t *, int, int);
84void isp_dump_portdb(ispsoftc_t *, int);
85void isp_gen_role_str(char *, size_t, uint16_t);
86
87const char *isp_fc_fw_statename(int);
88const char *isp_fc_loop_statename(int);
89const char *isp_fc_toponame(fcparam *);
90
91/*
92 * Cleanup
93 */
94void isp_clear_commands(ispsoftc_t *);
95
96/*
97 * Put/Get routines to push from CPU view to device view
98 * or to pull from device view to CPU view for various
99 * data structures (IOCB)
100 */
101void isp_put_hdr(ispsoftc_t *, isphdr_t *, isphdr_t *);
102void isp_get_hdr(ispsoftc_t *, isphdr_t *, isphdr_t *);
103int isp_get_response_type(ispsoftc_t *, isphdr_t *);
104void isp_put_marker_24xx(ispsoftc_t *, isp_marker_24xx_t *, isp_marker_24xx_t *);
105void isp_put_request_t7(ispsoftc_t *, ispreqt7_t *, ispreqt7_t *);
106void isp_put_24xx_tmf(ispsoftc_t *, isp24xx_tmf_t *, isp24xx_tmf_t *);
107void isp_put_24xx_abrt(ispsoftc_t *, isp24xx_abrt_t *, isp24xx_abrt_t *);
108void isp_put_cont64_req(ispsoftc_t *, ispcontreq64_t *, ispcontreq64_t *);
109void isp_get_cont_response(ispsoftc_t *, ispstatus_cont_t *, ispstatus_cont_t *);
110void isp_get_24xx_response(ispsoftc_t *, isp24xx_statusreq_t *, isp24xx_statusreq_t *);
111void isp_get_24xx_abrt(ispsoftc_t *, isp24xx_abrt_t *, isp24xx_abrt_t *);
112void isp_put_icb_2400(ispsoftc_t *, isp_icb_2400_t *, isp_icb_2400_t *);
113void isp_put_icb_2400_vpinfo(ispsoftc_t *, isp_icb_2400_vpinfo_t *, isp_icb_2400_vpinfo_t *);
114void isp_put_vp_port_info(ispsoftc_t *, vp_port_info_t *, vp_port_info_t *);
115void isp_get_vp_port_info(ispsoftc_t *, vp_port_info_t *, vp_port_info_t *);
116void isp_put_vp_ctrl_info(ispsoftc_t *, vp_ctrl_info_t *, vp_ctrl_info_t *);
117void isp_get_vp_ctrl_info(ispsoftc_t *, vp_ctrl_info_t *, vp_ctrl_info_t *);
118void isp_put_vp_modify(ispsoftc_t *, vp_modify_t *, vp_modify_t *);
119void isp_get_vp_modify(ispsoftc_t *, vp_modify_t *, vp_modify_t *);
120void isp_get_pdb_24xx(ispsoftc_t *, isp_pdb_24xx_t *, isp_pdb_24xx_t *);
121void isp_get_pnhle_24xx(ispsoftc_t *, isp_pnhle_24xx_t *, isp_pnhle_24xx_t *);
122void isp_get_ridacq(ispsoftc_t *, isp_ridacq_t *, isp_ridacq_t *);
123void isp_get_plogx(ispsoftc_t *, isp_plogx_t *, isp_plogx_t *);
124void isp_put_plogx(ispsoftc_t *, isp_plogx_t *, isp_plogx_t *);
125void isp_get_ct_pt(ispsoftc_t *isp, isp_ct_pt_t *, isp_ct_pt_t *);
126void isp_put_ct_pt(ispsoftc_t *isp, isp_ct_pt_t *, isp_ct_pt_t *);
127void isp_put_gid_ft_request(ispsoftc_t *, sns_gid_ft_req_t *, sns_gid_ft_req_t *);
128void isp_get_gid_xx_response(ispsoftc_t *, sns_gid_xx_rsp_t *, sns_gid_xx_rsp_t *, int);
129void isp_get_gxn_id_response(ispsoftc_t *, sns_gxn_id_rsp_t *, sns_gxn_id_rsp_t *);
130void isp_get_gft_id_response(ispsoftc_t *, sns_gft_id_rsp_t *, sns_gft_id_rsp_t *);
131void isp_get_gff_id_response(ispsoftc_t *, sns_gff_id_rsp_t *, sns_gff_id_rsp_t *);
132void isp_get_ga_nxt_response(ispsoftc_t *, sns_ga_nxt_rsp_t *, sns_ga_nxt_rsp_t *);
133void isp_get_fc_hdr(ispsoftc_t *, fc_hdr_t *, fc_hdr_t *);
134void isp_put_fc_hdr(ispsoftc_t *, fc_hdr_t *, fc_hdr_t *);
135void isp_get_fcp_cmnd_iu(ispsoftc_t *, fcp_cmnd_iu_t *, fcp_cmnd_iu_t *);
136void isp_put_rft_id(ispsoftc_t *, rft_id_t *, rft_id_t *);
137void isp_put_rspn_id(ispsoftc_t *, rspn_id_t *, rspn_id_t *);
138void isp_put_rff_id(ispsoftc_t *, rff_id_t *, rff_id_t *);
139void isp_put_rsnn_nn(ispsoftc_t *, rsnn_nn_t *, rsnn_nn_t *);
140void isp_get_ct_hdr(ispsoftc_t *isp, ct_hdr_t *, ct_hdr_t *);
141void isp_put_ct_hdr(ispsoftc_t *isp, ct_hdr_t *, ct_hdr_t *);
142void isp_put_fcp_rsp_iu(ispsoftc_t *isp, fcp_rsp_iu_t *, fcp_rsp_iu_t *);
143void isp_get_atio7(ispsoftc_t *isp, at7_entry_t *, at7_entry_t *);
144void isp_put_ctio7(ispsoftc_t *, ct7_entry_t *, ct7_entry_t *);
145void isp_get_ctio7(ispsoftc_t *, ct7_entry_t *, ct7_entry_t *);
146void isp_put_notify_24xx(ispsoftc_t *, in_fcentry_24xx_t *, in_fcentry_24xx_t *);
147void isp_get_notify_24xx(ispsoftc_t *, in_fcentry_24xx_t *, in_fcentry_24xx_t *);
148void isp_put_notify_ack_24xx(ispsoftc_t *, na_fcentry_24xx_t *, na_fcentry_24xx_t *);
149void isp_get_notify_ack_24xx(ispsoftc_t *, na_fcentry_24xx_t *, na_fcentry_24xx_t *);
150void isp_get_abts(ispsoftc_t *, abts_t *, abts_t *);
151void isp_put_abts_rsp(ispsoftc_t *, abts_rsp_t *, abts_rsp_t *);
152void isp_get_abts_rsp(ispsoftc_t *, abts_rsp_t *, abts_rsp_t *);
153
154void isp_put_entry(ispsoftc_t *, void *, void *);
155void isp_get_entry(ispsoftc_t *, void *, void *);
156int isp_send_entry(ispsoftc_t *, void *);
157int isp_exec_entry_mbox(ispsoftc_t *, void *, void *, int);
158int isp_exec_entry_queue(ispsoftc_t *, void *, void *, int);
159
160#define ISP_HANDLE_MASK  0x7fff
161
162#ifdef ISP_TARGET_MODE
163#if defined(__NetBSD__) || defined(__OpenBSD__)
164#include <dev/ic/isp_target.h>
165#elif  defined(__FreeBSD__)
166#include <dev/isp/isp_target.h>
167#else
168#include "isp_target.h"
169#endif
170#endif
171
172int isp_find_pdb_empty(ispsoftc_t *, int, fcportdb_t **);
173int isp_find_pdb_by_wwpn(ispsoftc_t *, int, uint64_t, fcportdb_t **);
174int isp_find_pdb_by_handle(ispsoftc_t *, int, uint16_t, fcportdb_t **);
175int isp_find_pdb_by_portid(ispsoftc_t *, int, uint32_t, fcportdb_t **);
176#ifdef ISP_TARGET_MODE
177void isp_find_chan_by_did(ispsoftc_t *, uint32_t, uint16_t *);
178void isp_add_wwn_entry(ispsoftc_t *, int, uint64_t, uint64_t, uint16_t, uint32_t, uint16_t);
179void isp_del_wwn_entry(ispsoftc_t *, int, uint64_t, uint16_t, uint32_t);
180#endif /* ISP_TARGET_MODE */
181#endif /* _ISP_LIBRARY_H */
182