xref: /OK3568_Linux_fs/kernel/sound/pci/asihpi/hpimsgx.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /******************************************************************************
3*4882a593Smuzhiyun 
4*4882a593Smuzhiyun     AudioScience HPI driver
5*4882a593Smuzhiyun     Copyright (C) 1997-2014  AudioScience Inc. <support@audioscience.com>
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun Extended Message Function With Response Caching
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun (C) Copyright AudioScience Inc. 2002
11*4882a593Smuzhiyun *****************************************************************************/
12*4882a593Smuzhiyun #define SOURCEFILE_NAME "hpimsgx.c"
13*4882a593Smuzhiyun #include "hpi_internal.h"
14*4882a593Smuzhiyun #include "hpi_version.h"
15*4882a593Smuzhiyun #include "hpimsginit.h"
16*4882a593Smuzhiyun #include "hpicmn.h"
17*4882a593Smuzhiyun #include "hpimsgx.h"
18*4882a593Smuzhiyun #include "hpidebug.h"
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun static const struct pci_device_id asihpi_pci_tbl[] = {
21*4882a593Smuzhiyun #include "hpipcida.h"
22*4882a593Smuzhiyun };
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun static struct hpios_spinlock msgx_lock;
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun static hpi_handler_func *hpi_entry_points[HPI_MAX_ADAPTERS];
27*4882a593Smuzhiyun static int logging_enabled = 1;
28*4882a593Smuzhiyun 
hpi_lookup_entry_point_function(const struct hpi_pci * pci_info)29*4882a593Smuzhiyun static hpi_handler_func *hpi_lookup_entry_point_function(const struct hpi_pci
30*4882a593Smuzhiyun 	*pci_info)
31*4882a593Smuzhiyun {
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun 	int i;
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun 	for (i = 0; asihpi_pci_tbl[i].vendor != 0; i++) {
36*4882a593Smuzhiyun 		if (asihpi_pci_tbl[i].vendor != PCI_ANY_ID
37*4882a593Smuzhiyun 			&& asihpi_pci_tbl[i].vendor !=
38*4882a593Smuzhiyun 			pci_info->pci_dev->vendor)
39*4882a593Smuzhiyun 			continue;
40*4882a593Smuzhiyun 		if (asihpi_pci_tbl[i].device != PCI_ANY_ID
41*4882a593Smuzhiyun 			&& asihpi_pci_tbl[i].device !=
42*4882a593Smuzhiyun 			pci_info->pci_dev->device)
43*4882a593Smuzhiyun 			continue;
44*4882a593Smuzhiyun 		if (asihpi_pci_tbl[i].subvendor != PCI_ANY_ID
45*4882a593Smuzhiyun 			&& asihpi_pci_tbl[i].subvendor !=
46*4882a593Smuzhiyun 			pci_info->pci_dev->subsystem_vendor)
47*4882a593Smuzhiyun 			continue;
48*4882a593Smuzhiyun 		if (asihpi_pci_tbl[i].subdevice != PCI_ANY_ID
49*4882a593Smuzhiyun 			&& asihpi_pci_tbl[i].subdevice !=
50*4882a593Smuzhiyun 			pci_info->pci_dev->subsystem_device)
51*4882a593Smuzhiyun 			continue;
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun 		/* HPI_DEBUG_LOG(DEBUG, " %x,%lx\n", i,
54*4882a593Smuzhiyun 		   asihpi_pci_tbl[i].driver_data); */
55*4882a593Smuzhiyun 		return (hpi_handler_func *) asihpi_pci_tbl[i].driver_data;
56*4882a593Smuzhiyun 	}
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun 	return NULL;
59*4882a593Smuzhiyun }
60*4882a593Smuzhiyun 
hw_entry_point(struct hpi_message * phm,struct hpi_response * phr)61*4882a593Smuzhiyun static inline void hw_entry_point(struct hpi_message *phm,
62*4882a593Smuzhiyun 	struct hpi_response *phr)
63*4882a593Smuzhiyun {
64*4882a593Smuzhiyun 	if ((phm->adapter_index < HPI_MAX_ADAPTERS)
65*4882a593Smuzhiyun 		&& hpi_entry_points[phm->adapter_index])
66*4882a593Smuzhiyun 		hpi_entry_points[phm->adapter_index] (phm, phr);
67*4882a593Smuzhiyun 	else
68*4882a593Smuzhiyun 		hpi_init_response(phr, phm->object, phm->function,
69*4882a593Smuzhiyun 			HPI_ERROR_PROCESSING_MESSAGE);
70*4882a593Smuzhiyun }
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun static void adapter_open(struct hpi_message *phm, struct hpi_response *phr);
73*4882a593Smuzhiyun static void adapter_close(struct hpi_message *phm, struct hpi_response *phr);
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun static void mixer_open(struct hpi_message *phm, struct hpi_response *phr);
76*4882a593Smuzhiyun static void mixer_close(struct hpi_message *phm, struct hpi_response *phr);
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun static void outstream_open(struct hpi_message *phm, struct hpi_response *phr,
79*4882a593Smuzhiyun 	void *h_owner);
80*4882a593Smuzhiyun static void outstream_close(struct hpi_message *phm, struct hpi_response *phr,
81*4882a593Smuzhiyun 	void *h_owner);
82*4882a593Smuzhiyun static void instream_open(struct hpi_message *phm, struct hpi_response *phr,
83*4882a593Smuzhiyun 	void *h_owner);
84*4882a593Smuzhiyun static void instream_close(struct hpi_message *phm, struct hpi_response *phr,
85*4882a593Smuzhiyun 	void *h_owner);
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun static void HPIMSGX__reset(u16 adapter_index);
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun static u16 HPIMSGX__init(struct hpi_message *phm, struct hpi_response *phr);
90*4882a593Smuzhiyun static void HPIMSGX__cleanup(u16 adapter_index, void *h_owner);
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun #ifndef DISABLE_PRAGMA_PACK1
93*4882a593Smuzhiyun #pragma pack(push, 1)
94*4882a593Smuzhiyun #endif
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun struct hpi_subsys_response {
97*4882a593Smuzhiyun 	struct hpi_response_header h;
98*4882a593Smuzhiyun 	struct hpi_subsys_res s;
99*4882a593Smuzhiyun };
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun struct hpi_adapter_response {
102*4882a593Smuzhiyun 	struct hpi_response_header h;
103*4882a593Smuzhiyun 	struct hpi_adapter_res a;
104*4882a593Smuzhiyun };
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun struct hpi_mixer_response {
107*4882a593Smuzhiyun 	struct hpi_response_header h;
108*4882a593Smuzhiyun 	struct hpi_mixer_res m;
109*4882a593Smuzhiyun };
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun struct hpi_stream_response {
112*4882a593Smuzhiyun 	struct hpi_response_header h;
113*4882a593Smuzhiyun 	struct hpi_stream_res d;
114*4882a593Smuzhiyun };
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun struct adapter_info {
117*4882a593Smuzhiyun 	u16 type;
118*4882a593Smuzhiyun 	u16 num_instreams;
119*4882a593Smuzhiyun 	u16 num_outstreams;
120*4882a593Smuzhiyun };
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun struct asi_open_state {
123*4882a593Smuzhiyun 	int open_flag;
124*4882a593Smuzhiyun 	void *h_owner;
125*4882a593Smuzhiyun };
126*4882a593Smuzhiyun 
127*4882a593Smuzhiyun #ifndef DISABLE_PRAGMA_PACK1
128*4882a593Smuzhiyun #pragma pack(pop)
129*4882a593Smuzhiyun #endif
130*4882a593Smuzhiyun 
131*4882a593Smuzhiyun /* Globals */
132*4882a593Smuzhiyun static struct hpi_adapter_response rESP_HPI_ADAPTER_OPEN[HPI_MAX_ADAPTERS];
133*4882a593Smuzhiyun 
134*4882a593Smuzhiyun static struct hpi_stream_response
135*4882a593Smuzhiyun 	rESP_HPI_OSTREAM_OPEN[HPI_MAX_ADAPTERS][HPI_MAX_STREAMS];
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun static struct hpi_stream_response
138*4882a593Smuzhiyun 	rESP_HPI_ISTREAM_OPEN[HPI_MAX_ADAPTERS][HPI_MAX_STREAMS];
139*4882a593Smuzhiyun 
140*4882a593Smuzhiyun static struct hpi_mixer_response rESP_HPI_MIXER_OPEN[HPI_MAX_ADAPTERS];
141*4882a593Smuzhiyun 
142*4882a593Smuzhiyun static struct adapter_info aDAPTER_INFO[HPI_MAX_ADAPTERS];
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun /* use these to keep track of opens from user mode apps/DLLs */
145*4882a593Smuzhiyun static struct asi_open_state
146*4882a593Smuzhiyun 	outstream_user_open[HPI_MAX_ADAPTERS][HPI_MAX_STREAMS];
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun static struct asi_open_state
149*4882a593Smuzhiyun 	instream_user_open[HPI_MAX_ADAPTERS][HPI_MAX_STREAMS];
150*4882a593Smuzhiyun 
subsys_message(struct hpi_message * phm,struct hpi_response * phr,void * h_owner)151*4882a593Smuzhiyun static void subsys_message(struct hpi_message *phm, struct hpi_response *phr,
152*4882a593Smuzhiyun 	void *h_owner)
153*4882a593Smuzhiyun {
154*4882a593Smuzhiyun 	if (phm->adapter_index != HPI_ADAPTER_INDEX_INVALID)
155*4882a593Smuzhiyun 		HPI_DEBUG_LOG(WARNING,
156*4882a593Smuzhiyun 			"suspicious adapter index %d in subsys message 0x%x.\n",
157*4882a593Smuzhiyun 			phm->adapter_index, phm->function);
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun 	switch (phm->function) {
160*4882a593Smuzhiyun 	case HPI_SUBSYS_GET_VERSION:
161*4882a593Smuzhiyun 		hpi_init_response(phr, HPI_OBJ_SUBSYSTEM,
162*4882a593Smuzhiyun 			HPI_SUBSYS_GET_VERSION, 0);
163*4882a593Smuzhiyun 		phr->u.s.version = HPI_VER >> 8;	/* return major.minor */
164*4882a593Smuzhiyun 		phr->u.s.data = HPI_VER;	/* return major.minor.release */
165*4882a593Smuzhiyun 		break;
166*4882a593Smuzhiyun 	case HPI_SUBSYS_OPEN:
167*4882a593Smuzhiyun 		/*do not propagate the message down the chain */
168*4882a593Smuzhiyun 		hpi_init_response(phr, HPI_OBJ_SUBSYSTEM, HPI_SUBSYS_OPEN, 0);
169*4882a593Smuzhiyun 		break;
170*4882a593Smuzhiyun 	case HPI_SUBSYS_CLOSE:
171*4882a593Smuzhiyun 		/*do not propagate the message down the chain */
172*4882a593Smuzhiyun 		hpi_init_response(phr, HPI_OBJ_SUBSYSTEM, HPI_SUBSYS_CLOSE,
173*4882a593Smuzhiyun 			0);
174*4882a593Smuzhiyun 		HPIMSGX__cleanup(HPIMSGX_ALLADAPTERS, h_owner);
175*4882a593Smuzhiyun 		break;
176*4882a593Smuzhiyun 	case HPI_SUBSYS_DRIVER_LOAD:
177*4882a593Smuzhiyun 		/* Initialize this module's internal state */
178*4882a593Smuzhiyun 		hpios_msgxlock_init(&msgx_lock);
179*4882a593Smuzhiyun 		memset(&hpi_entry_points, 0, sizeof(hpi_entry_points));
180*4882a593Smuzhiyun 		/* Init subsys_findadapters response to no-adapters */
181*4882a593Smuzhiyun 		HPIMSGX__reset(HPIMSGX_ALLADAPTERS);
182*4882a593Smuzhiyun 		hpi_init_response(phr, HPI_OBJ_SUBSYSTEM,
183*4882a593Smuzhiyun 			HPI_SUBSYS_DRIVER_LOAD, 0);
184*4882a593Smuzhiyun 		/* individual HPIs dont implement driver load */
185*4882a593Smuzhiyun 		HPI_COMMON(phm, phr);
186*4882a593Smuzhiyun 		break;
187*4882a593Smuzhiyun 	case HPI_SUBSYS_DRIVER_UNLOAD:
188*4882a593Smuzhiyun 		HPI_COMMON(phm, phr);
189*4882a593Smuzhiyun 		HPIMSGX__cleanup(HPIMSGX_ALLADAPTERS, h_owner);
190*4882a593Smuzhiyun 		hpi_init_response(phr, HPI_OBJ_SUBSYSTEM,
191*4882a593Smuzhiyun 			HPI_SUBSYS_DRIVER_UNLOAD, 0);
192*4882a593Smuzhiyun 		return;
193*4882a593Smuzhiyun 
194*4882a593Smuzhiyun 	case HPI_SUBSYS_GET_NUM_ADAPTERS:
195*4882a593Smuzhiyun 	case HPI_SUBSYS_GET_ADAPTER:
196*4882a593Smuzhiyun 		HPI_COMMON(phm, phr);
197*4882a593Smuzhiyun 		break;
198*4882a593Smuzhiyun 
199*4882a593Smuzhiyun 	case HPI_SUBSYS_CREATE_ADAPTER:
200*4882a593Smuzhiyun 		HPIMSGX__init(phm, phr);
201*4882a593Smuzhiyun 		break;
202*4882a593Smuzhiyun 
203*4882a593Smuzhiyun 	default:
204*4882a593Smuzhiyun 		/* Must explicitly handle every subsys message in this switch */
205*4882a593Smuzhiyun 		hpi_init_response(phr, HPI_OBJ_SUBSYSTEM, phm->function,
206*4882a593Smuzhiyun 			HPI_ERROR_INVALID_FUNC);
207*4882a593Smuzhiyun 		break;
208*4882a593Smuzhiyun 	}
209*4882a593Smuzhiyun }
210*4882a593Smuzhiyun 
adapter_message(struct hpi_message * phm,struct hpi_response * phr,void * h_owner)211*4882a593Smuzhiyun static void adapter_message(struct hpi_message *phm, struct hpi_response *phr,
212*4882a593Smuzhiyun 	void *h_owner)
213*4882a593Smuzhiyun {
214*4882a593Smuzhiyun 	switch (phm->function) {
215*4882a593Smuzhiyun 	case HPI_ADAPTER_OPEN:
216*4882a593Smuzhiyun 		adapter_open(phm, phr);
217*4882a593Smuzhiyun 		break;
218*4882a593Smuzhiyun 	case HPI_ADAPTER_CLOSE:
219*4882a593Smuzhiyun 		adapter_close(phm, phr);
220*4882a593Smuzhiyun 		break;
221*4882a593Smuzhiyun 	case HPI_ADAPTER_DELETE:
222*4882a593Smuzhiyun 		HPIMSGX__cleanup(phm->adapter_index, h_owner);
223*4882a593Smuzhiyun 		{
224*4882a593Smuzhiyun 			struct hpi_message hm;
225*4882a593Smuzhiyun 			struct hpi_response hr;
226*4882a593Smuzhiyun 			hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
227*4882a593Smuzhiyun 				HPI_ADAPTER_CLOSE);
228*4882a593Smuzhiyun 			hm.adapter_index = phm->adapter_index;
229*4882a593Smuzhiyun 			hw_entry_point(&hm, &hr);
230*4882a593Smuzhiyun 		}
231*4882a593Smuzhiyun 		hw_entry_point(phm, phr);
232*4882a593Smuzhiyun 		break;
233*4882a593Smuzhiyun 
234*4882a593Smuzhiyun 	default:
235*4882a593Smuzhiyun 		hw_entry_point(phm, phr);
236*4882a593Smuzhiyun 		break;
237*4882a593Smuzhiyun 	}
238*4882a593Smuzhiyun }
239*4882a593Smuzhiyun 
mixer_message(struct hpi_message * phm,struct hpi_response * phr)240*4882a593Smuzhiyun static void mixer_message(struct hpi_message *phm, struct hpi_response *phr)
241*4882a593Smuzhiyun {
242*4882a593Smuzhiyun 	switch (phm->function) {
243*4882a593Smuzhiyun 	case HPI_MIXER_OPEN:
244*4882a593Smuzhiyun 		mixer_open(phm, phr);
245*4882a593Smuzhiyun 		break;
246*4882a593Smuzhiyun 	case HPI_MIXER_CLOSE:
247*4882a593Smuzhiyun 		mixer_close(phm, phr);
248*4882a593Smuzhiyun 		break;
249*4882a593Smuzhiyun 	default:
250*4882a593Smuzhiyun 		hw_entry_point(phm, phr);
251*4882a593Smuzhiyun 		break;
252*4882a593Smuzhiyun 	}
253*4882a593Smuzhiyun }
254*4882a593Smuzhiyun 
outstream_message(struct hpi_message * phm,struct hpi_response * phr,void * h_owner)255*4882a593Smuzhiyun static void outstream_message(struct hpi_message *phm,
256*4882a593Smuzhiyun 	struct hpi_response *phr, void *h_owner)
257*4882a593Smuzhiyun {
258*4882a593Smuzhiyun 	if (phm->obj_index >= aDAPTER_INFO[phm->adapter_index].num_outstreams) {
259*4882a593Smuzhiyun 		hpi_init_response(phr, HPI_OBJ_OSTREAM, phm->function,
260*4882a593Smuzhiyun 			HPI_ERROR_INVALID_OBJ_INDEX);
261*4882a593Smuzhiyun 		return;
262*4882a593Smuzhiyun 	}
263*4882a593Smuzhiyun 
264*4882a593Smuzhiyun 	switch (phm->function) {
265*4882a593Smuzhiyun 	case HPI_OSTREAM_OPEN:
266*4882a593Smuzhiyun 		outstream_open(phm, phr, h_owner);
267*4882a593Smuzhiyun 		break;
268*4882a593Smuzhiyun 	case HPI_OSTREAM_CLOSE:
269*4882a593Smuzhiyun 		outstream_close(phm, phr, h_owner);
270*4882a593Smuzhiyun 		break;
271*4882a593Smuzhiyun 	default:
272*4882a593Smuzhiyun 		hw_entry_point(phm, phr);
273*4882a593Smuzhiyun 		break;
274*4882a593Smuzhiyun 	}
275*4882a593Smuzhiyun }
276*4882a593Smuzhiyun 
instream_message(struct hpi_message * phm,struct hpi_response * phr,void * h_owner)277*4882a593Smuzhiyun static void instream_message(struct hpi_message *phm,
278*4882a593Smuzhiyun 	struct hpi_response *phr, void *h_owner)
279*4882a593Smuzhiyun {
280*4882a593Smuzhiyun 	if (phm->obj_index >= aDAPTER_INFO[phm->adapter_index].num_instreams) {
281*4882a593Smuzhiyun 		hpi_init_response(phr, HPI_OBJ_ISTREAM, phm->function,
282*4882a593Smuzhiyun 			HPI_ERROR_INVALID_OBJ_INDEX);
283*4882a593Smuzhiyun 		return;
284*4882a593Smuzhiyun 	}
285*4882a593Smuzhiyun 
286*4882a593Smuzhiyun 	switch (phm->function) {
287*4882a593Smuzhiyun 	case HPI_ISTREAM_OPEN:
288*4882a593Smuzhiyun 		instream_open(phm, phr, h_owner);
289*4882a593Smuzhiyun 		break;
290*4882a593Smuzhiyun 	case HPI_ISTREAM_CLOSE:
291*4882a593Smuzhiyun 		instream_close(phm, phr, h_owner);
292*4882a593Smuzhiyun 		break;
293*4882a593Smuzhiyun 	default:
294*4882a593Smuzhiyun 		hw_entry_point(phm, phr);
295*4882a593Smuzhiyun 		break;
296*4882a593Smuzhiyun 	}
297*4882a593Smuzhiyun }
298*4882a593Smuzhiyun 
299*4882a593Smuzhiyun /* NOTE: HPI_Message() must be defined in the driver as a wrapper for
300*4882a593Smuzhiyun  * HPI_MessageEx so that functions in hpifunc.c compile.
301*4882a593Smuzhiyun  */
hpi_send_recv_ex(struct hpi_message * phm,struct hpi_response * phr,void * h_owner)302*4882a593Smuzhiyun void hpi_send_recv_ex(struct hpi_message *phm, struct hpi_response *phr,
303*4882a593Smuzhiyun 	void *h_owner)
304*4882a593Smuzhiyun {
305*4882a593Smuzhiyun 
306*4882a593Smuzhiyun 	if (logging_enabled)
307*4882a593Smuzhiyun 		HPI_DEBUG_MESSAGE(DEBUG, phm);
308*4882a593Smuzhiyun 
309*4882a593Smuzhiyun 	if (phm->type != HPI_TYPE_REQUEST) {
310*4882a593Smuzhiyun 		hpi_init_response(phr, phm->object, phm->function,
311*4882a593Smuzhiyun 			HPI_ERROR_INVALID_TYPE);
312*4882a593Smuzhiyun 		return;
313*4882a593Smuzhiyun 	}
314*4882a593Smuzhiyun 
315*4882a593Smuzhiyun 	if (phm->adapter_index >= HPI_MAX_ADAPTERS
316*4882a593Smuzhiyun 		&& phm->adapter_index != HPIMSGX_ALLADAPTERS) {
317*4882a593Smuzhiyun 		hpi_init_response(phr, phm->object, phm->function,
318*4882a593Smuzhiyun 			HPI_ERROR_BAD_ADAPTER_NUMBER);
319*4882a593Smuzhiyun 		return;
320*4882a593Smuzhiyun 	}
321*4882a593Smuzhiyun 
322*4882a593Smuzhiyun 	switch (phm->object) {
323*4882a593Smuzhiyun 	case HPI_OBJ_SUBSYSTEM:
324*4882a593Smuzhiyun 		subsys_message(phm, phr, h_owner);
325*4882a593Smuzhiyun 		break;
326*4882a593Smuzhiyun 
327*4882a593Smuzhiyun 	case HPI_OBJ_ADAPTER:
328*4882a593Smuzhiyun 		adapter_message(phm, phr, h_owner);
329*4882a593Smuzhiyun 		break;
330*4882a593Smuzhiyun 
331*4882a593Smuzhiyun 	case HPI_OBJ_MIXER:
332*4882a593Smuzhiyun 		mixer_message(phm, phr);
333*4882a593Smuzhiyun 		break;
334*4882a593Smuzhiyun 
335*4882a593Smuzhiyun 	case HPI_OBJ_OSTREAM:
336*4882a593Smuzhiyun 		outstream_message(phm, phr, h_owner);
337*4882a593Smuzhiyun 		break;
338*4882a593Smuzhiyun 
339*4882a593Smuzhiyun 	case HPI_OBJ_ISTREAM:
340*4882a593Smuzhiyun 		instream_message(phm, phr, h_owner);
341*4882a593Smuzhiyun 		break;
342*4882a593Smuzhiyun 
343*4882a593Smuzhiyun 	default:
344*4882a593Smuzhiyun 		hw_entry_point(phm, phr);
345*4882a593Smuzhiyun 		break;
346*4882a593Smuzhiyun 	}
347*4882a593Smuzhiyun 
348*4882a593Smuzhiyun 	if (logging_enabled)
349*4882a593Smuzhiyun 		HPI_DEBUG_RESPONSE(phr);
350*4882a593Smuzhiyun 
351*4882a593Smuzhiyun 	if (phr->error >= HPI_ERROR_DSP_COMMUNICATION) {
352*4882a593Smuzhiyun 		hpi_debug_level_set(HPI_DEBUG_LEVEL_ERROR);
353*4882a593Smuzhiyun 		logging_enabled = 0;
354*4882a593Smuzhiyun 	}
355*4882a593Smuzhiyun }
356*4882a593Smuzhiyun 
adapter_open(struct hpi_message * phm,struct hpi_response * phr)357*4882a593Smuzhiyun static void adapter_open(struct hpi_message *phm, struct hpi_response *phr)
358*4882a593Smuzhiyun {
359*4882a593Smuzhiyun 	HPI_DEBUG_LOG(VERBOSE, "adapter_open\n");
360*4882a593Smuzhiyun 	memcpy(phr, &rESP_HPI_ADAPTER_OPEN[phm->adapter_index],
361*4882a593Smuzhiyun 		sizeof(rESP_HPI_ADAPTER_OPEN[0]));
362*4882a593Smuzhiyun }
363*4882a593Smuzhiyun 
adapter_close(struct hpi_message * phm,struct hpi_response * phr)364*4882a593Smuzhiyun static void adapter_close(struct hpi_message *phm, struct hpi_response *phr)
365*4882a593Smuzhiyun {
366*4882a593Smuzhiyun 	HPI_DEBUG_LOG(VERBOSE, "adapter_close\n");
367*4882a593Smuzhiyun 	hpi_init_response(phr, HPI_OBJ_ADAPTER, HPI_ADAPTER_CLOSE, 0);
368*4882a593Smuzhiyun }
369*4882a593Smuzhiyun 
mixer_open(struct hpi_message * phm,struct hpi_response * phr)370*4882a593Smuzhiyun static void mixer_open(struct hpi_message *phm, struct hpi_response *phr)
371*4882a593Smuzhiyun {
372*4882a593Smuzhiyun 	memcpy(phr, &rESP_HPI_MIXER_OPEN[phm->adapter_index],
373*4882a593Smuzhiyun 		sizeof(rESP_HPI_MIXER_OPEN[0]));
374*4882a593Smuzhiyun }
375*4882a593Smuzhiyun 
mixer_close(struct hpi_message * phm,struct hpi_response * phr)376*4882a593Smuzhiyun static void mixer_close(struct hpi_message *phm, struct hpi_response *phr)
377*4882a593Smuzhiyun {
378*4882a593Smuzhiyun 	hpi_init_response(phr, HPI_OBJ_MIXER, HPI_MIXER_CLOSE, 0);
379*4882a593Smuzhiyun }
380*4882a593Smuzhiyun 
instream_open(struct hpi_message * phm,struct hpi_response * phr,void * h_owner)381*4882a593Smuzhiyun static void instream_open(struct hpi_message *phm, struct hpi_response *phr,
382*4882a593Smuzhiyun 	void *h_owner)
383*4882a593Smuzhiyun {
384*4882a593Smuzhiyun 
385*4882a593Smuzhiyun 	struct hpi_message hm;
386*4882a593Smuzhiyun 	struct hpi_response hr;
387*4882a593Smuzhiyun 
388*4882a593Smuzhiyun 	hpi_init_response(phr, HPI_OBJ_ISTREAM, HPI_ISTREAM_OPEN, 0);
389*4882a593Smuzhiyun 
390*4882a593Smuzhiyun 	hpios_msgxlock_lock(&msgx_lock);
391*4882a593Smuzhiyun 
392*4882a593Smuzhiyun 	if (instream_user_open[phm->adapter_index][phm->obj_index].open_flag)
393*4882a593Smuzhiyun 		phr->error = HPI_ERROR_OBJ_ALREADY_OPEN;
394*4882a593Smuzhiyun 	else if (rESP_HPI_ISTREAM_OPEN[phm->adapter_index]
395*4882a593Smuzhiyun 		[phm->obj_index].h.error)
396*4882a593Smuzhiyun 		memcpy(phr,
397*4882a593Smuzhiyun 			&rESP_HPI_ISTREAM_OPEN[phm->adapter_index][phm->
398*4882a593Smuzhiyun 				obj_index],
399*4882a593Smuzhiyun 			sizeof(rESP_HPI_ISTREAM_OPEN[0][0]));
400*4882a593Smuzhiyun 	else {
401*4882a593Smuzhiyun 		instream_user_open[phm->adapter_index][phm->
402*4882a593Smuzhiyun 			obj_index].open_flag = 1;
403*4882a593Smuzhiyun 		hpios_msgxlock_unlock(&msgx_lock);
404*4882a593Smuzhiyun 
405*4882a593Smuzhiyun 		/* issue a reset */
406*4882a593Smuzhiyun 		hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
407*4882a593Smuzhiyun 			HPI_ISTREAM_RESET);
408*4882a593Smuzhiyun 		hm.adapter_index = phm->adapter_index;
409*4882a593Smuzhiyun 		hm.obj_index = phm->obj_index;
410*4882a593Smuzhiyun 		hw_entry_point(&hm, &hr);
411*4882a593Smuzhiyun 
412*4882a593Smuzhiyun 		hpios_msgxlock_lock(&msgx_lock);
413*4882a593Smuzhiyun 		if (hr.error) {
414*4882a593Smuzhiyun 			instream_user_open[phm->adapter_index][phm->
415*4882a593Smuzhiyun 				obj_index].open_flag = 0;
416*4882a593Smuzhiyun 			phr->error = hr.error;
417*4882a593Smuzhiyun 		} else {
418*4882a593Smuzhiyun 			instream_user_open[phm->adapter_index][phm->
419*4882a593Smuzhiyun 				obj_index].open_flag = 1;
420*4882a593Smuzhiyun 			instream_user_open[phm->adapter_index][phm->
421*4882a593Smuzhiyun 				obj_index].h_owner = h_owner;
422*4882a593Smuzhiyun 			memcpy(phr,
423*4882a593Smuzhiyun 				&rESP_HPI_ISTREAM_OPEN[phm->adapter_index]
424*4882a593Smuzhiyun 				[phm->obj_index],
425*4882a593Smuzhiyun 				sizeof(rESP_HPI_ISTREAM_OPEN[0][0]));
426*4882a593Smuzhiyun 		}
427*4882a593Smuzhiyun 	}
428*4882a593Smuzhiyun 	hpios_msgxlock_unlock(&msgx_lock);
429*4882a593Smuzhiyun }
430*4882a593Smuzhiyun 
instream_close(struct hpi_message * phm,struct hpi_response * phr,void * h_owner)431*4882a593Smuzhiyun static void instream_close(struct hpi_message *phm, struct hpi_response *phr,
432*4882a593Smuzhiyun 	void *h_owner)
433*4882a593Smuzhiyun {
434*4882a593Smuzhiyun 
435*4882a593Smuzhiyun 	struct hpi_message hm;
436*4882a593Smuzhiyun 	struct hpi_response hr;
437*4882a593Smuzhiyun 
438*4882a593Smuzhiyun 	hpi_init_response(phr, HPI_OBJ_ISTREAM, HPI_ISTREAM_CLOSE, 0);
439*4882a593Smuzhiyun 
440*4882a593Smuzhiyun 	hpios_msgxlock_lock(&msgx_lock);
441*4882a593Smuzhiyun 	if (h_owner ==
442*4882a593Smuzhiyun 		instream_user_open[phm->adapter_index][phm->
443*4882a593Smuzhiyun 			obj_index].h_owner) {
444*4882a593Smuzhiyun 		/* HPI_DEBUG_LOG(INFO,"closing adapter %d "
445*4882a593Smuzhiyun 		   "instream %d owned by %p\n",
446*4882a593Smuzhiyun 		   phm->wAdapterIndex, phm->wObjIndex, hOwner); */
447*4882a593Smuzhiyun 		instream_user_open[phm->adapter_index][phm->
448*4882a593Smuzhiyun 			obj_index].h_owner = NULL;
449*4882a593Smuzhiyun 		hpios_msgxlock_unlock(&msgx_lock);
450*4882a593Smuzhiyun 		/* issue a reset */
451*4882a593Smuzhiyun 		hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
452*4882a593Smuzhiyun 			HPI_ISTREAM_RESET);
453*4882a593Smuzhiyun 		hm.adapter_index = phm->adapter_index;
454*4882a593Smuzhiyun 		hm.obj_index = phm->obj_index;
455*4882a593Smuzhiyun 		hw_entry_point(&hm, &hr);
456*4882a593Smuzhiyun 		hpios_msgxlock_lock(&msgx_lock);
457*4882a593Smuzhiyun 		if (hr.error) {
458*4882a593Smuzhiyun 			instream_user_open[phm->adapter_index][phm->
459*4882a593Smuzhiyun 				obj_index].h_owner = h_owner;
460*4882a593Smuzhiyun 			phr->error = hr.error;
461*4882a593Smuzhiyun 		} else {
462*4882a593Smuzhiyun 			instream_user_open[phm->adapter_index][phm->
463*4882a593Smuzhiyun 				obj_index].open_flag = 0;
464*4882a593Smuzhiyun 			instream_user_open[phm->adapter_index][phm->
465*4882a593Smuzhiyun 				obj_index].h_owner = NULL;
466*4882a593Smuzhiyun 		}
467*4882a593Smuzhiyun 	} else {
468*4882a593Smuzhiyun 		HPI_DEBUG_LOG(WARNING,
469*4882a593Smuzhiyun 			"%p trying to close %d instream %d owned by %p\n",
470*4882a593Smuzhiyun 			h_owner, phm->adapter_index, phm->obj_index,
471*4882a593Smuzhiyun 			instream_user_open[phm->adapter_index][phm->
472*4882a593Smuzhiyun 				obj_index].h_owner);
473*4882a593Smuzhiyun 		phr->error = HPI_ERROR_OBJ_NOT_OPEN;
474*4882a593Smuzhiyun 	}
475*4882a593Smuzhiyun 	hpios_msgxlock_unlock(&msgx_lock);
476*4882a593Smuzhiyun }
477*4882a593Smuzhiyun 
outstream_open(struct hpi_message * phm,struct hpi_response * phr,void * h_owner)478*4882a593Smuzhiyun static void outstream_open(struct hpi_message *phm, struct hpi_response *phr,
479*4882a593Smuzhiyun 	void *h_owner)
480*4882a593Smuzhiyun {
481*4882a593Smuzhiyun 
482*4882a593Smuzhiyun 	struct hpi_message hm;
483*4882a593Smuzhiyun 	struct hpi_response hr;
484*4882a593Smuzhiyun 
485*4882a593Smuzhiyun 	hpi_init_response(phr, HPI_OBJ_OSTREAM, HPI_OSTREAM_OPEN, 0);
486*4882a593Smuzhiyun 
487*4882a593Smuzhiyun 	hpios_msgxlock_lock(&msgx_lock);
488*4882a593Smuzhiyun 
489*4882a593Smuzhiyun 	if (outstream_user_open[phm->adapter_index][phm->obj_index].open_flag)
490*4882a593Smuzhiyun 		phr->error = HPI_ERROR_OBJ_ALREADY_OPEN;
491*4882a593Smuzhiyun 	else if (rESP_HPI_OSTREAM_OPEN[phm->adapter_index]
492*4882a593Smuzhiyun 		[phm->obj_index].h.error)
493*4882a593Smuzhiyun 		memcpy(phr,
494*4882a593Smuzhiyun 			&rESP_HPI_OSTREAM_OPEN[phm->adapter_index][phm->
495*4882a593Smuzhiyun 				obj_index],
496*4882a593Smuzhiyun 			sizeof(rESP_HPI_OSTREAM_OPEN[0][0]));
497*4882a593Smuzhiyun 	else {
498*4882a593Smuzhiyun 		outstream_user_open[phm->adapter_index][phm->
499*4882a593Smuzhiyun 			obj_index].open_flag = 1;
500*4882a593Smuzhiyun 		hpios_msgxlock_unlock(&msgx_lock);
501*4882a593Smuzhiyun 
502*4882a593Smuzhiyun 		/* issue a reset */
503*4882a593Smuzhiyun 		hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
504*4882a593Smuzhiyun 			HPI_OSTREAM_RESET);
505*4882a593Smuzhiyun 		hm.adapter_index = phm->adapter_index;
506*4882a593Smuzhiyun 		hm.obj_index = phm->obj_index;
507*4882a593Smuzhiyun 		hw_entry_point(&hm, &hr);
508*4882a593Smuzhiyun 
509*4882a593Smuzhiyun 		hpios_msgxlock_lock(&msgx_lock);
510*4882a593Smuzhiyun 		if (hr.error) {
511*4882a593Smuzhiyun 			outstream_user_open[phm->adapter_index][phm->
512*4882a593Smuzhiyun 				obj_index].open_flag = 0;
513*4882a593Smuzhiyun 			phr->error = hr.error;
514*4882a593Smuzhiyun 		} else {
515*4882a593Smuzhiyun 			outstream_user_open[phm->adapter_index][phm->
516*4882a593Smuzhiyun 				obj_index].open_flag = 1;
517*4882a593Smuzhiyun 			outstream_user_open[phm->adapter_index][phm->
518*4882a593Smuzhiyun 				obj_index].h_owner = h_owner;
519*4882a593Smuzhiyun 			memcpy(phr,
520*4882a593Smuzhiyun 				&rESP_HPI_OSTREAM_OPEN[phm->adapter_index]
521*4882a593Smuzhiyun 				[phm->obj_index],
522*4882a593Smuzhiyun 				sizeof(rESP_HPI_OSTREAM_OPEN[0][0]));
523*4882a593Smuzhiyun 		}
524*4882a593Smuzhiyun 	}
525*4882a593Smuzhiyun 	hpios_msgxlock_unlock(&msgx_lock);
526*4882a593Smuzhiyun }
527*4882a593Smuzhiyun 
outstream_close(struct hpi_message * phm,struct hpi_response * phr,void * h_owner)528*4882a593Smuzhiyun static void outstream_close(struct hpi_message *phm, struct hpi_response *phr,
529*4882a593Smuzhiyun 	void *h_owner)
530*4882a593Smuzhiyun {
531*4882a593Smuzhiyun 
532*4882a593Smuzhiyun 	struct hpi_message hm;
533*4882a593Smuzhiyun 	struct hpi_response hr;
534*4882a593Smuzhiyun 
535*4882a593Smuzhiyun 	hpi_init_response(phr, HPI_OBJ_OSTREAM, HPI_OSTREAM_CLOSE, 0);
536*4882a593Smuzhiyun 
537*4882a593Smuzhiyun 	hpios_msgxlock_lock(&msgx_lock);
538*4882a593Smuzhiyun 
539*4882a593Smuzhiyun 	if (h_owner ==
540*4882a593Smuzhiyun 		outstream_user_open[phm->adapter_index][phm->
541*4882a593Smuzhiyun 			obj_index].h_owner) {
542*4882a593Smuzhiyun 		/* HPI_DEBUG_LOG(INFO,"closing adapter %d "
543*4882a593Smuzhiyun 		   "outstream %d owned by %p\n",
544*4882a593Smuzhiyun 		   phm->wAdapterIndex, phm->wObjIndex, hOwner); */
545*4882a593Smuzhiyun 		outstream_user_open[phm->adapter_index][phm->
546*4882a593Smuzhiyun 			obj_index].h_owner = NULL;
547*4882a593Smuzhiyun 		hpios_msgxlock_unlock(&msgx_lock);
548*4882a593Smuzhiyun 		/* issue a reset */
549*4882a593Smuzhiyun 		hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
550*4882a593Smuzhiyun 			HPI_OSTREAM_RESET);
551*4882a593Smuzhiyun 		hm.adapter_index = phm->adapter_index;
552*4882a593Smuzhiyun 		hm.obj_index = phm->obj_index;
553*4882a593Smuzhiyun 		hw_entry_point(&hm, &hr);
554*4882a593Smuzhiyun 		hpios_msgxlock_lock(&msgx_lock);
555*4882a593Smuzhiyun 		if (hr.error) {
556*4882a593Smuzhiyun 			outstream_user_open[phm->adapter_index][phm->
557*4882a593Smuzhiyun 				obj_index].h_owner = h_owner;
558*4882a593Smuzhiyun 			phr->error = hr.error;
559*4882a593Smuzhiyun 		} else {
560*4882a593Smuzhiyun 			outstream_user_open[phm->adapter_index][phm->
561*4882a593Smuzhiyun 				obj_index].open_flag = 0;
562*4882a593Smuzhiyun 			outstream_user_open[phm->adapter_index][phm->
563*4882a593Smuzhiyun 				obj_index].h_owner = NULL;
564*4882a593Smuzhiyun 		}
565*4882a593Smuzhiyun 	} else {
566*4882a593Smuzhiyun 		HPI_DEBUG_LOG(WARNING,
567*4882a593Smuzhiyun 			"%p trying to close %d outstream %d owned by %p\n",
568*4882a593Smuzhiyun 			h_owner, phm->adapter_index, phm->obj_index,
569*4882a593Smuzhiyun 			outstream_user_open[phm->adapter_index][phm->
570*4882a593Smuzhiyun 				obj_index].h_owner);
571*4882a593Smuzhiyun 		phr->error = HPI_ERROR_OBJ_NOT_OPEN;
572*4882a593Smuzhiyun 	}
573*4882a593Smuzhiyun 	hpios_msgxlock_unlock(&msgx_lock);
574*4882a593Smuzhiyun }
575*4882a593Smuzhiyun 
adapter_prepare(u16 adapter)576*4882a593Smuzhiyun static u16 adapter_prepare(u16 adapter)
577*4882a593Smuzhiyun {
578*4882a593Smuzhiyun 	struct hpi_message hm;
579*4882a593Smuzhiyun 	struct hpi_response hr;
580*4882a593Smuzhiyun 
581*4882a593Smuzhiyun 	/* Open the adapter and streams */
582*4882a593Smuzhiyun 	u16 i;
583*4882a593Smuzhiyun 
584*4882a593Smuzhiyun 	/* call to HPI_ADAPTER_OPEN */
585*4882a593Smuzhiyun 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
586*4882a593Smuzhiyun 		HPI_ADAPTER_OPEN);
587*4882a593Smuzhiyun 	hm.adapter_index = adapter;
588*4882a593Smuzhiyun 	hw_entry_point(&hm, &hr);
589*4882a593Smuzhiyun 	memcpy(&rESP_HPI_ADAPTER_OPEN[adapter], &hr,
590*4882a593Smuzhiyun 		sizeof(rESP_HPI_ADAPTER_OPEN[0]));
591*4882a593Smuzhiyun 	if (hr.error)
592*4882a593Smuzhiyun 		return hr.error;
593*4882a593Smuzhiyun 
594*4882a593Smuzhiyun 	/* call to HPI_ADAPTER_GET_INFO */
595*4882a593Smuzhiyun 	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
596*4882a593Smuzhiyun 		HPI_ADAPTER_GET_INFO);
597*4882a593Smuzhiyun 	hm.adapter_index = adapter;
598*4882a593Smuzhiyun 	hw_entry_point(&hm, &hr);
599*4882a593Smuzhiyun 	if (hr.error)
600*4882a593Smuzhiyun 		return hr.error;
601*4882a593Smuzhiyun 
602*4882a593Smuzhiyun 	aDAPTER_INFO[adapter].num_outstreams = hr.u.ax.info.num_outstreams;
603*4882a593Smuzhiyun 	aDAPTER_INFO[adapter].num_instreams = hr.u.ax.info.num_instreams;
604*4882a593Smuzhiyun 	aDAPTER_INFO[adapter].type = hr.u.ax.info.adapter_type;
605*4882a593Smuzhiyun 
606*4882a593Smuzhiyun 	/* call to HPI_OSTREAM_OPEN */
607*4882a593Smuzhiyun 	for (i = 0; i < aDAPTER_INFO[adapter].num_outstreams; i++) {
608*4882a593Smuzhiyun 		hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
609*4882a593Smuzhiyun 			HPI_OSTREAM_OPEN);
610*4882a593Smuzhiyun 		hm.adapter_index = adapter;
611*4882a593Smuzhiyun 		hm.obj_index = i;
612*4882a593Smuzhiyun 		hw_entry_point(&hm, &hr);
613*4882a593Smuzhiyun 		memcpy(&rESP_HPI_OSTREAM_OPEN[adapter][i], &hr,
614*4882a593Smuzhiyun 			sizeof(rESP_HPI_OSTREAM_OPEN[0][0]));
615*4882a593Smuzhiyun 		outstream_user_open[adapter][i].open_flag = 0;
616*4882a593Smuzhiyun 		outstream_user_open[adapter][i].h_owner = NULL;
617*4882a593Smuzhiyun 	}
618*4882a593Smuzhiyun 
619*4882a593Smuzhiyun 	/* call to HPI_ISTREAM_OPEN */
620*4882a593Smuzhiyun 	for (i = 0; i < aDAPTER_INFO[adapter].num_instreams; i++) {
621*4882a593Smuzhiyun 		hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
622*4882a593Smuzhiyun 			HPI_ISTREAM_OPEN);
623*4882a593Smuzhiyun 		hm.adapter_index = adapter;
624*4882a593Smuzhiyun 		hm.obj_index = i;
625*4882a593Smuzhiyun 		hw_entry_point(&hm, &hr);
626*4882a593Smuzhiyun 		memcpy(&rESP_HPI_ISTREAM_OPEN[adapter][i], &hr,
627*4882a593Smuzhiyun 			sizeof(rESP_HPI_ISTREAM_OPEN[0][0]));
628*4882a593Smuzhiyun 		instream_user_open[adapter][i].open_flag = 0;
629*4882a593Smuzhiyun 		instream_user_open[adapter][i].h_owner = NULL;
630*4882a593Smuzhiyun 	}
631*4882a593Smuzhiyun 
632*4882a593Smuzhiyun 	/* call to HPI_MIXER_OPEN */
633*4882a593Smuzhiyun 	hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_OPEN);
634*4882a593Smuzhiyun 	hm.adapter_index = adapter;
635*4882a593Smuzhiyun 	hw_entry_point(&hm, &hr);
636*4882a593Smuzhiyun 	memcpy(&rESP_HPI_MIXER_OPEN[adapter], &hr,
637*4882a593Smuzhiyun 		sizeof(rESP_HPI_MIXER_OPEN[0]));
638*4882a593Smuzhiyun 
639*4882a593Smuzhiyun 	return 0;
640*4882a593Smuzhiyun }
641*4882a593Smuzhiyun 
HPIMSGX__reset(u16 adapter_index)642*4882a593Smuzhiyun static void HPIMSGX__reset(u16 adapter_index)
643*4882a593Smuzhiyun {
644*4882a593Smuzhiyun 	int i;
645*4882a593Smuzhiyun 	u16 adapter;
646*4882a593Smuzhiyun 	struct hpi_response hr;
647*4882a593Smuzhiyun 
648*4882a593Smuzhiyun 	if (adapter_index == HPIMSGX_ALLADAPTERS) {
649*4882a593Smuzhiyun 		for (adapter = 0; adapter < HPI_MAX_ADAPTERS; adapter++) {
650*4882a593Smuzhiyun 
651*4882a593Smuzhiyun 			hpi_init_response(&hr, HPI_OBJ_ADAPTER,
652*4882a593Smuzhiyun 				HPI_ADAPTER_OPEN, HPI_ERROR_BAD_ADAPTER);
653*4882a593Smuzhiyun 			memcpy(&rESP_HPI_ADAPTER_OPEN[adapter], &hr,
654*4882a593Smuzhiyun 				sizeof(rESP_HPI_ADAPTER_OPEN[adapter]));
655*4882a593Smuzhiyun 
656*4882a593Smuzhiyun 			hpi_init_response(&hr, HPI_OBJ_MIXER, HPI_MIXER_OPEN,
657*4882a593Smuzhiyun 				HPI_ERROR_INVALID_OBJ);
658*4882a593Smuzhiyun 			memcpy(&rESP_HPI_MIXER_OPEN[adapter], &hr,
659*4882a593Smuzhiyun 				sizeof(rESP_HPI_MIXER_OPEN[adapter]));
660*4882a593Smuzhiyun 
661*4882a593Smuzhiyun 			for (i = 0; i < HPI_MAX_STREAMS; i++) {
662*4882a593Smuzhiyun 				hpi_init_response(&hr, HPI_OBJ_OSTREAM,
663*4882a593Smuzhiyun 					HPI_OSTREAM_OPEN,
664*4882a593Smuzhiyun 					HPI_ERROR_INVALID_OBJ);
665*4882a593Smuzhiyun 				memcpy(&rESP_HPI_OSTREAM_OPEN[adapter][i],
666*4882a593Smuzhiyun 					&hr,
667*4882a593Smuzhiyun 					sizeof(rESP_HPI_OSTREAM_OPEN[adapter]
668*4882a593Smuzhiyun 						[i]));
669*4882a593Smuzhiyun 				hpi_init_response(&hr, HPI_OBJ_ISTREAM,
670*4882a593Smuzhiyun 					HPI_ISTREAM_OPEN,
671*4882a593Smuzhiyun 					HPI_ERROR_INVALID_OBJ);
672*4882a593Smuzhiyun 				memcpy(&rESP_HPI_ISTREAM_OPEN[adapter][i],
673*4882a593Smuzhiyun 					&hr,
674*4882a593Smuzhiyun 					sizeof(rESP_HPI_ISTREAM_OPEN[adapter]
675*4882a593Smuzhiyun 						[i]));
676*4882a593Smuzhiyun 			}
677*4882a593Smuzhiyun 		}
678*4882a593Smuzhiyun 	} else if (adapter_index < HPI_MAX_ADAPTERS) {
679*4882a593Smuzhiyun 		rESP_HPI_ADAPTER_OPEN[adapter_index].h.error =
680*4882a593Smuzhiyun 			HPI_ERROR_BAD_ADAPTER;
681*4882a593Smuzhiyun 		rESP_HPI_MIXER_OPEN[adapter_index].h.error =
682*4882a593Smuzhiyun 			HPI_ERROR_INVALID_OBJ;
683*4882a593Smuzhiyun 		for (i = 0; i < HPI_MAX_STREAMS; i++) {
684*4882a593Smuzhiyun 			rESP_HPI_OSTREAM_OPEN[adapter_index][i].h.error =
685*4882a593Smuzhiyun 				HPI_ERROR_INVALID_OBJ;
686*4882a593Smuzhiyun 			rESP_HPI_ISTREAM_OPEN[adapter_index][i].h.error =
687*4882a593Smuzhiyun 				HPI_ERROR_INVALID_OBJ;
688*4882a593Smuzhiyun 		}
689*4882a593Smuzhiyun 	}
690*4882a593Smuzhiyun }
691*4882a593Smuzhiyun 
HPIMSGX__init(struct hpi_message * phm,struct hpi_response * phr)692*4882a593Smuzhiyun static u16 HPIMSGX__init(struct hpi_message *phm,
693*4882a593Smuzhiyun 	/* HPI_SUBSYS_CREATE_ADAPTER structure with */
694*4882a593Smuzhiyun 	/* resource list or NULL=find all */
695*4882a593Smuzhiyun 	struct hpi_response *phr
696*4882a593Smuzhiyun 	/* response from HPI_ADAPTER_GET_INFO */
697*4882a593Smuzhiyun 	)
698*4882a593Smuzhiyun {
699*4882a593Smuzhiyun 	hpi_handler_func *entry_point_func;
700*4882a593Smuzhiyun 	struct hpi_response hr;
701*4882a593Smuzhiyun 
702*4882a593Smuzhiyun 	/* Init response here so we can pass in previous adapter list */
703*4882a593Smuzhiyun 	hpi_init_response(&hr, phm->object, phm->function,
704*4882a593Smuzhiyun 		HPI_ERROR_INVALID_OBJ);
705*4882a593Smuzhiyun 
706*4882a593Smuzhiyun 	entry_point_func =
707*4882a593Smuzhiyun 		hpi_lookup_entry_point_function(phm->u.s.resource.r.pci);
708*4882a593Smuzhiyun 
709*4882a593Smuzhiyun 	if (entry_point_func) {
710*4882a593Smuzhiyun 		HPI_DEBUG_MESSAGE(DEBUG, phm);
711*4882a593Smuzhiyun 		entry_point_func(phm, &hr);
712*4882a593Smuzhiyun 	} else {
713*4882a593Smuzhiyun 		phr->error = HPI_ERROR_PROCESSING_MESSAGE;
714*4882a593Smuzhiyun 		return phr->error;
715*4882a593Smuzhiyun 	}
716*4882a593Smuzhiyun 	if (hr.error == 0) {
717*4882a593Smuzhiyun 		/* the adapter was created successfully
718*4882a593Smuzhiyun 		   save the mapping for future use */
719*4882a593Smuzhiyun 		hpi_entry_points[hr.u.s.adapter_index] = entry_point_func;
720*4882a593Smuzhiyun 		/* prepare adapter (pre-open streams etc.) */
721*4882a593Smuzhiyun 		HPI_DEBUG_LOG(DEBUG,
722*4882a593Smuzhiyun 			"HPI_SUBSYS_CREATE_ADAPTER successful,"
723*4882a593Smuzhiyun 			" preparing adapter\n");
724*4882a593Smuzhiyun 		adapter_prepare(hr.u.s.adapter_index);
725*4882a593Smuzhiyun 	}
726*4882a593Smuzhiyun 	memcpy(phr, &hr, hr.size);
727*4882a593Smuzhiyun 	return phr->error;
728*4882a593Smuzhiyun }
729*4882a593Smuzhiyun 
HPIMSGX__cleanup(u16 adapter_index,void * h_owner)730*4882a593Smuzhiyun static void HPIMSGX__cleanup(u16 adapter_index, void *h_owner)
731*4882a593Smuzhiyun {
732*4882a593Smuzhiyun 	int i, adapter, adapter_limit;
733*4882a593Smuzhiyun 
734*4882a593Smuzhiyun 	if (!h_owner)
735*4882a593Smuzhiyun 		return;
736*4882a593Smuzhiyun 
737*4882a593Smuzhiyun 	if (adapter_index == HPIMSGX_ALLADAPTERS) {
738*4882a593Smuzhiyun 		adapter = 0;
739*4882a593Smuzhiyun 		adapter_limit = HPI_MAX_ADAPTERS;
740*4882a593Smuzhiyun 	} else {
741*4882a593Smuzhiyun 		adapter = adapter_index;
742*4882a593Smuzhiyun 		adapter_limit = adapter + 1;
743*4882a593Smuzhiyun 	}
744*4882a593Smuzhiyun 
745*4882a593Smuzhiyun 	for (; adapter < adapter_limit; adapter++) {
746*4882a593Smuzhiyun 		/*      printk(KERN_INFO "Cleanup adapter #%d\n",wAdapter); */
747*4882a593Smuzhiyun 		for (i = 0; i < HPI_MAX_STREAMS; i++) {
748*4882a593Smuzhiyun 			if (h_owner ==
749*4882a593Smuzhiyun 				outstream_user_open[adapter][i].h_owner) {
750*4882a593Smuzhiyun 				struct hpi_message hm;
751*4882a593Smuzhiyun 				struct hpi_response hr;
752*4882a593Smuzhiyun 
753*4882a593Smuzhiyun 				HPI_DEBUG_LOG(DEBUG,
754*4882a593Smuzhiyun 					"Close adapter %d ostream %d\n",
755*4882a593Smuzhiyun 					adapter, i);
756*4882a593Smuzhiyun 
757*4882a593Smuzhiyun 				hpi_init_message_response(&hm, &hr,
758*4882a593Smuzhiyun 					HPI_OBJ_OSTREAM, HPI_OSTREAM_RESET);
759*4882a593Smuzhiyun 				hm.adapter_index = (u16)adapter;
760*4882a593Smuzhiyun 				hm.obj_index = (u16)i;
761*4882a593Smuzhiyun 				hw_entry_point(&hm, &hr);
762*4882a593Smuzhiyun 
763*4882a593Smuzhiyun 				hm.function = HPI_OSTREAM_HOSTBUFFER_FREE;
764*4882a593Smuzhiyun 				hw_entry_point(&hm, &hr);
765*4882a593Smuzhiyun 
766*4882a593Smuzhiyun 				hm.function = HPI_OSTREAM_GROUP_RESET;
767*4882a593Smuzhiyun 				hw_entry_point(&hm, &hr);
768*4882a593Smuzhiyun 
769*4882a593Smuzhiyun 				outstream_user_open[adapter][i].open_flag = 0;
770*4882a593Smuzhiyun 				outstream_user_open[adapter][i].h_owner =
771*4882a593Smuzhiyun 					NULL;
772*4882a593Smuzhiyun 			}
773*4882a593Smuzhiyun 			if (h_owner == instream_user_open[adapter][i].h_owner) {
774*4882a593Smuzhiyun 				struct hpi_message hm;
775*4882a593Smuzhiyun 				struct hpi_response hr;
776*4882a593Smuzhiyun 
777*4882a593Smuzhiyun 				HPI_DEBUG_LOG(DEBUG,
778*4882a593Smuzhiyun 					"Close adapter %d istream %d\n",
779*4882a593Smuzhiyun 					adapter, i);
780*4882a593Smuzhiyun 
781*4882a593Smuzhiyun 				hpi_init_message_response(&hm, &hr,
782*4882a593Smuzhiyun 					HPI_OBJ_ISTREAM, HPI_ISTREAM_RESET);
783*4882a593Smuzhiyun 				hm.adapter_index = (u16)adapter;
784*4882a593Smuzhiyun 				hm.obj_index = (u16)i;
785*4882a593Smuzhiyun 				hw_entry_point(&hm, &hr);
786*4882a593Smuzhiyun 
787*4882a593Smuzhiyun 				hm.function = HPI_ISTREAM_HOSTBUFFER_FREE;
788*4882a593Smuzhiyun 				hw_entry_point(&hm, &hr);
789*4882a593Smuzhiyun 
790*4882a593Smuzhiyun 				hm.function = HPI_ISTREAM_GROUP_RESET;
791*4882a593Smuzhiyun 				hw_entry_point(&hm, &hr);
792*4882a593Smuzhiyun 
793*4882a593Smuzhiyun 				instream_user_open[adapter][i].open_flag = 0;
794*4882a593Smuzhiyun 				instream_user_open[adapter][i].h_owner = NULL;
795*4882a593Smuzhiyun 			}
796*4882a593Smuzhiyun 		}
797*4882a593Smuzhiyun 	}
798*4882a593Smuzhiyun }
799