aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/asihpi/hpifunc.c
diff options
context:
space:
mode:
authorEliot Blennerhassett <eblennerhassett@audioscience.com>2011-02-09 23:25:58 -0500
committerTakashi Iwai <tiwai@suse.de>2011-02-10 12:22:40 -0500
commit3285ea10e9b09d68da18d2f805980246ec53523a (patch)
treef6c7ccc09d07fd808357b50ddad25e5f5b4fa3c9 /sound/pci/asihpi/hpifunc.c
parentad210ad10ec96e32d32459545f54e4d3d9c6a088 (diff)
ALSA: asihpi - Interrelated HPI tidy up.
Remove many unused functions. Update some message and cache structs. Use pci info directly from pci_dev. Allow control cache elements with variable size, and handle large message/response from dsp. hpi6000 and hpi6205: fix error path when adapter bootload fails. hpimsgx.c get rid of code duplicated in hpicmn.c Signed-off-by: Eliot Blennerhassett <eblennerhassett@audioscience.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci/asihpi/hpifunc.c')
-rw-r--r--sound/pci/asihpi/hpifunc.c985
1 files changed, 65 insertions, 920 deletions
diff --git a/sound/pci/asihpi/hpifunc.c b/sound/pci/asihpi/hpifunc.c
index 1e92eb6dd509..aafb76955f69 100644
--- a/sound/pci/asihpi/hpifunc.c
+++ b/sound/pci/asihpi/hpifunc.c
@@ -98,21 +98,7 @@ static struct hpi_hsubsys gh_subsys;
98 98
99struct hpi_hsubsys *hpi_subsys_create(void) 99struct hpi_hsubsys *hpi_subsys_create(void)
100{ 100{
101 struct hpi_message hm; 101 return &gh_subsys;
102 struct hpi_response hr;
103
104 memset(&gh_subsys, 0, sizeof(struct hpi_hsubsys));
105
106 {
107 hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
108 HPI_SUBSYS_OPEN);
109 hpi_send_recv(&hm, &hr);
110
111 if (hr.error == 0)
112 return &gh_subsys;
113
114 }
115 return NULL;
116} 102}
117 103
118void hpi_subsys_free(const struct hpi_hsubsys *ph_subsys) 104void hpi_subsys_free(const struct hpi_hsubsys *ph_subsys)
@@ -126,18 +112,6 @@ void hpi_subsys_free(const struct hpi_hsubsys *ph_subsys)
126 112
127} 113}
128 114
129u16 hpi_subsys_get_version(const struct hpi_hsubsys *ph_subsys, u32 *pversion)
130{
131 struct hpi_message hm;
132 struct hpi_response hr;
133
134 hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
135 HPI_SUBSYS_GET_VERSION);
136 hpi_send_recv(&hm, &hr);
137 *pversion = hr.u.s.version;
138 return hr.error;
139}
140
141u16 hpi_subsys_get_version_ex(const struct hpi_hsubsys *ph_subsys, 115u16 hpi_subsys_get_version_ex(const struct hpi_hsubsys *ph_subsys,
142 u32 *pversion_ex) 116 u32 *pversion_ex)
143{ 117{
@@ -151,49 +125,6 @@ u16 hpi_subsys_get_version_ex(const struct hpi_hsubsys *ph_subsys,
151 return hr.error; 125 return hr.error;
152} 126}
153 127
154u16 hpi_subsys_get_info(const struct hpi_hsubsys *ph_subsys, u32 *pversion,
155 u16 *pw_num_adapters, u16 aw_adapter_list[], u16 list_length)
156{
157 struct hpi_message hm;
158 struct hpi_response hr;
159 hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
160 HPI_SUBSYS_GET_INFO);
161
162 hpi_send_recv(&hm, &hr);
163
164 *pversion = hr.u.s.version;
165 if (list_length > HPI_MAX_ADAPTERS)
166 memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list,
167 HPI_MAX_ADAPTERS);
168 else
169 memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list, list_length);
170 *pw_num_adapters = hr.u.s.num_adapters;
171 return hr.error;
172}
173
174u16 hpi_subsys_find_adapters(const struct hpi_hsubsys *ph_subsys,
175 u16 *pw_num_adapters, u16 aw_adapter_list[], u16 list_length)
176{
177 struct hpi_message hm;
178 struct hpi_response hr;
179 hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
180 HPI_SUBSYS_FIND_ADAPTERS);
181
182 hpi_send_recv(&hm, &hr);
183
184 if (list_length > HPI_MAX_ADAPTERS) {
185 memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list,
186 HPI_MAX_ADAPTERS * sizeof(u16));
187 memset(&aw_adapter_list[HPI_MAX_ADAPTERS], 0,
188 (list_length - HPI_MAX_ADAPTERS) * sizeof(u16));
189 } else
190 memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list,
191 list_length * sizeof(u16));
192 *pw_num_adapters = hr.u.s.num_adapters;
193
194 return hr.error;
195}
196
197u16 hpi_subsys_create_adapter(const struct hpi_hsubsys *ph_subsys, 128u16 hpi_subsys_create_adapter(const struct hpi_hsubsys *ph_subsys,
198 const struct hpi_resource *p_resource, u16 *pw_adapter_index) 129 const struct hpi_resource *p_resource, u16 *pw_adapter_index)
199{ 130{
@@ -217,7 +148,7 @@ u16 hpi_subsys_delete_adapter(const struct hpi_hsubsys *ph_subsys,
217 struct hpi_response hr; 148 struct hpi_response hr;
218 hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM, 149 hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
219 HPI_SUBSYS_DELETE_ADAPTER); 150 HPI_SUBSYS_DELETE_ADAPTER);
220 hm.adapter_index = adapter_index; 151 hm.obj_index = adapter_index;
221 hpi_send_recv(&hm, &hr); 152 hpi_send_recv(&hm, &hr);
222 return hr.error; 153 return hr.error;
223} 154}
@@ -241,27 +172,13 @@ u16 hpi_subsys_get_adapter(const struct hpi_hsubsys *ph_subsys, int iterator,
241 struct hpi_response hr; 172 struct hpi_response hr;
242 hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM, 173 hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
243 HPI_SUBSYS_GET_ADAPTER); 174 HPI_SUBSYS_GET_ADAPTER);
244 hm.adapter_index = (u16)iterator; 175 hm.obj_index = (u16)iterator;
245 hpi_send_recv(&hm, &hr); 176 hpi_send_recv(&hm, &hr);
246 *padapter_index = (int)hr.u.s.adapter_index; 177 *padapter_index = (int)hr.u.s.adapter_index;
247 *pw_adapter_type = hr.u.s.aw_adapter_list[0]; 178 *pw_adapter_type = hr.u.s.aw_adapter_list[0];
248 return hr.error; 179 return hr.error;
249} 180}
250 181
251u16 hpi_subsys_set_host_network_interface(const struct hpi_hsubsys *ph_subsys,
252 const char *sz_interface)
253{
254 struct hpi_message hm;
255 struct hpi_response hr;
256 hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
257 HPI_SUBSYS_SET_NETWORK_INTERFACE);
258 if (sz_interface == NULL)
259 return HPI_ERROR_INVALID_RESOURCE;
260 hm.u.s.resource.r.net_if = sz_interface;
261 hpi_send_recv(&hm, &hr);
262 return hr.error;
263}
264
265u16 hpi_adapter_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index) 182u16 hpi_adapter_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index)
266{ 183{
267 struct hpi_message hm; 184 struct hpi_message hm;
@@ -305,8 +222,8 @@ u16 hpi_adapter_set_mode_ex(const struct hpi_hsubsys *ph_subsys,
305 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER, 222 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
306 HPI_ADAPTER_SET_MODE); 223 HPI_ADAPTER_SET_MODE);
307 hm.adapter_index = adapter_index; 224 hm.adapter_index = adapter_index;
308 hm.u.a.adapter_mode = adapter_mode; 225 hm.u.ax.mode.adapter_mode = adapter_mode;
309 hm.u.a.assert_id = query_or_set; 226 hm.u.ax.mode.query_or_set = query_or_set;
310 hpi_send_recv(&hm, &hr); 227 hpi_send_recv(&hm, &hr);
311 return hr.error; 228 return hr.error;
312} 229}
@@ -321,7 +238,7 @@ u16 hpi_adapter_get_mode(const struct hpi_hsubsys *ph_subsys,
321 hm.adapter_index = adapter_index; 238 hm.adapter_index = adapter_index;
322 hpi_send_recv(&hm, &hr); 239 hpi_send_recv(&hm, &hr);
323 if (padapter_mode) 240 if (padapter_mode)
324 *padapter_mode = hr.u.a.serial_number; 241 *padapter_mode = hr.u.ax.mode.adapter_mode;
325 return hr.error; 242 return hr.error;
326} 243}
327 244
@@ -337,11 +254,11 @@ u16 hpi_adapter_get_info(const struct hpi_hsubsys *ph_subsys,
337 254
338 hpi_send_recv(&hm, &hr); 255 hpi_send_recv(&hm, &hr);
339 256
340 *pw_adapter_type = hr.u.a.adapter_type; 257 *pw_adapter_type = hr.u.ax.info.adapter_type;
341 *pw_num_outstreams = hr.u.a.num_outstreams; 258 *pw_num_outstreams = hr.u.ax.info.num_outstreams;
342 *pw_num_instreams = hr.u.a.num_instreams; 259 *pw_num_instreams = hr.u.ax.info.num_instreams;
343 *pw_version = hr.u.a.version; 260 *pw_version = hr.u.ax.info.version;
344 *pserial_number = hr.u.a.serial_number; 261 *pserial_number = hr.u.ax.info.serial_number;
345 return hr.error; 262 return hr.error;
346} 263}
347 264
@@ -360,56 +277,20 @@ u16 hpi_adapter_get_module_by_index(const struct hpi_hsubsys *ph_subsys,
360 277
361 hpi_send_recv(&hm, &hr); 278 hpi_send_recv(&hm, &hr);
362 279
363 *pw_module_type = hr.u.a.adapter_type; 280 *pw_module_type = hr.u.ax.info.adapter_type;
364 *pw_num_outputs = hr.u.a.num_outstreams; 281 *pw_num_outputs = hr.u.ax.info.num_outstreams;
365 *pw_num_inputs = hr.u.a.num_instreams; 282 *pw_num_inputs = hr.u.ax.info.num_instreams;
366 *pw_version = hr.u.a.version; 283 *pw_version = hr.u.ax.info.version;
367 *pserial_number = hr.u.a.serial_number; 284 *pserial_number = hr.u.ax.info.serial_number;
368 *ph_module = 0; 285 *ph_module = 0;
369 286
370 return hr.error; 287 return hr.error;
371} 288}
372 289
373u16 hpi_adapter_get_assert(const struct hpi_hsubsys *ph_subsys, 290u16 hpi_adapter_get_assert2(const struct hpi_hsubsys *ph_subsys,
374 u16 adapter_index, u16 *assert_present, char *psz_assert, 291 u16 adapter_index, u16 *p_assert_count, char *psz_assert,
375 u16 *pw_line_number) 292 u32 *p_param1, u32 *p_param2, u32 *p_dsp_string_addr,
376{ 293 u16 *p_processor_id)
377 struct hpi_message hm;
378 struct hpi_response hr;
379 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
380 HPI_ADAPTER_GET_ASSERT);
381 hm.adapter_index = adapter_index;
382 hpi_send_recv(&hm, &hr);
383
384 *assert_present = 0;
385
386 if (!hr.error) {
387
388 *pw_line_number = (u16)hr.u.a.serial_number;
389 if (*pw_line_number) {
390
391 int i;
392 char *src = (char *)hr.u.a.sz_adapter_assert;
393 char *dst = psz_assert;
394
395 *assert_present = 1;
396
397 for (i = 0; i < HPI_STRING_LEN; i++) {
398 char c;
399 c = *src++;
400 *dst++ = c;
401 if (c == 0)
402 break;
403 }
404
405 }
406 }
407 return hr.error;
408}
409
410u16 hpi_adapter_get_assert_ex(const struct hpi_hsubsys *ph_subsys,
411 u16 adapter_index, u16 *assert_present, char *psz_assert,
412 u32 *pline_number, u16 *pw_assert_on_dsp)
413{ 294{
414 struct hpi_message hm; 295 struct hpi_message hm;
415 struct hpi_response hr; 296 struct hpi_response hr;
@@ -419,34 +300,18 @@ u16 hpi_adapter_get_assert_ex(const struct hpi_hsubsys *ph_subsys,
419 300
420 hpi_send_recv(&hm, &hr); 301 hpi_send_recv(&hm, &hr);
421 302
422 *assert_present = 0; 303 *p_assert_count = 0;
423 304
424 if (!hr.error) { 305 if (!hr.error) {
425 306 *p_assert_count = hr.u.ax.assert.count;
426 *pline_number = hr.u.a.serial_number; 307
427 308 if (*p_assert_count) {
428 *assert_present = hr.u.a.adapter_type; 309 *p_param1 = hr.u.ax.assert.p1;
429 310 *p_param2 = hr.u.ax.assert.p2;
430 *pw_assert_on_dsp = hr.u.a.adapter_index; 311 *p_processor_id = hr.u.ax.assert.dsp_index;
431 312 *p_dsp_string_addr = hr.u.ax.assert.dsp_msg_addr;
432 if (!*assert_present && *pline_number) 313 memcpy(psz_assert, hr.u.ax.assert.sz_message,
433 314 HPI_STRING_LEN);
434 *assert_present = 1;
435
436 if (*assert_present) {
437
438 int i;
439 char *src = (char *)hr.u.a.sz_adapter_assert;
440 char *dst = psz_assert;
441
442 for (i = 0; i < HPI_STRING_LEN; i++) {
443 char c;
444 c = *src++;
445 *dst++ = c;
446 if (c == 0)
447 break;
448 }
449
450 } else { 315 } else {
451 *psz_assert = 0; 316 *psz_assert = 0;
452 } 317 }
@@ -462,7 +327,7 @@ u16 hpi_adapter_test_assert(const struct hpi_hsubsys *ph_subsys,
462 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER, 327 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
463 HPI_ADAPTER_TEST_ASSERT); 328 HPI_ADAPTER_TEST_ASSERT);
464 hm.adapter_index = adapter_index; 329 hm.adapter_index = adapter_index;
465 hm.u.a.assert_id = assert_id; 330 hm.u.ax.test_assert.value = assert_id;
466 331
467 hpi_send_recv(&hm, &hr); 332 hpi_send_recv(&hm, &hr);
468 333
@@ -472,17 +337,21 @@ u16 hpi_adapter_test_assert(const struct hpi_hsubsys *ph_subsys,
472u16 hpi_adapter_enable_capability(const struct hpi_hsubsys *ph_subsys, 337u16 hpi_adapter_enable_capability(const struct hpi_hsubsys *ph_subsys,
473 u16 adapter_index, u16 capability, u32 key) 338 u16 adapter_index, u16 capability, u32 key)
474{ 339{
340#if 1
341 return HPI_ERROR_UNIMPLEMENTED;
342#else
475 struct hpi_message hm; 343 struct hpi_message hm;
476 struct hpi_response hr; 344 struct hpi_response hr;
477 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER, 345 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
478 HPI_ADAPTER_ENABLE_CAPABILITY); 346 HPI_ADAPTER_ENABLE_CAPABILITY);
479 hm.adapter_index = adapter_index; 347 hm.adapter_index = adapter_index;
480 hm.u.a.assert_id = capability; 348 hm.u.ax.enable_cap.cap = capability;
481 hm.u.a.adapter_mode = key; 349 hm.u.ax.enable_cap.key = key;
482 350
483 hpi_send_recv(&hm, &hr); 351 hpi_send_recv(&hm, &hr);
484 352
485 return hr.error; 353 return hr.error;
354#endif
486} 355}
487 356
488u16 hpi_adapter_self_test(const struct hpi_hsubsys *ph_subsys, 357u16 hpi_adapter_self_test(const struct hpi_hsubsys *ph_subsys,
@@ -500,29 +369,32 @@ u16 hpi_adapter_self_test(const struct hpi_hsubsys *ph_subsys,
500u16 hpi_adapter_debug_read(const struct hpi_hsubsys *ph_subsys, 369u16 hpi_adapter_debug_read(const struct hpi_hsubsys *ph_subsys,
501 u16 adapter_index, u32 dsp_address, char *p_buffer, int *count_bytes) 370 u16 adapter_index, u32 dsp_address, char *p_buffer, int *count_bytes)
502{ 371{
503 struct hpi_message hm; 372 struct hpi_msg_adapter_debug_read hm;
504 struct hpi_response hr; 373 struct hpi_res_adapter_debug_read hr;
505 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
506 HPI_ADAPTER_DEBUG_READ);
507 374
508 hr.size = sizeof(hr); 375 hpi_init_message_responseV1(&hm.h, sizeof(hm), &hr.h, sizeof(hr),
376 HPI_OBJ_ADAPTER, HPI_ADAPTER_DEBUG_READ);
509 377
510 hm.adapter_index = adapter_index; 378 hm.h.adapter_index = adapter_index;
511 hm.u.ax.debug_read.dsp_address = dsp_address; 379 hm.dsp_address = dsp_address;
512 380
513 if (*count_bytes > (int)sizeof(hr.u.bytes)) 381 if (*count_bytes > (int)sizeof(hr.bytes))
514 *count_bytes = sizeof(hr.u.bytes); 382 *count_bytes = (int)sizeof(hr.bytes);
515 383
516 hm.u.ax.debug_read.count_bytes = *count_bytes; 384 hm.count_bytes = *count_bytes;
517 385
518 hpi_send_recv(&hm, &hr); 386 hpi_send_recv((struct hpi_message *)&hm, (struct hpi_response *)&hr);
519 387
520 if (!hr.error) { 388 if (!hr.h.error) {
521 *count_bytes = hr.size - 12; 389 int res_bytes = hr.h.size - sizeof(hr.h);
522 memcpy(p_buffer, &hr.u.bytes, *count_bytes); 390 if (res_bytes > *count_bytes)
391 res_bytes = *count_bytes;
392 *count_bytes = res_bytes;
393 memcpy(p_buffer, &hr.bytes, res_bytes);
523 } else 394 } else
524 *count_bytes = 0; 395 *count_bytes = 0;
525 return hr.error; 396
397 return hr.h.error;
526} 398}
527 399
528u16 hpi_adapter_set_property(const struct hpi_hsubsys *ph_subsys, 400u16 hpi_adapter_set_property(const struct hpi_hsubsys *ph_subsys,
@@ -1682,7 +1554,7 @@ static u16 hpi_control_get_string(const u32 h_control, const u16 attribute,
1682 unsigned int sub_string_index = 0, j = 0; 1554 unsigned int sub_string_index = 0, j = 0;
1683 char c = 0; 1555 char c = 0;
1684 unsigned int n = 0; 1556 unsigned int n = 0;
1685 u16 hE = 0; 1557 u16 err = 0;
1686 1558
1687 if ((string_length < 1) || (string_length > 256)) 1559 if ((string_length < 1) || (string_length > 256))
1688 return HPI_ERROR_INVALID_CONTROL_VALUE; 1560 return HPI_ERROR_INVALID_CONTROL_VALUE;
@@ -1705,7 +1577,7 @@ static u16 hpi_control_get_string(const u32 h_control, const u16 attribute,
1705 return HPI_ERROR_INVALID_CONTROL_VALUE; 1577 return HPI_ERROR_INVALID_CONTROL_VALUE;
1706 1578
1707 if (hr.error) { 1579 if (hr.error) {
1708 hE = hr.error; 1580 err = hr.error;
1709 break; 1581 break;
1710 } 1582 }
1711 for (j = 0; j < 8; j++) { 1583 for (j = 0; j < 8; j++) {
@@ -1714,7 +1586,7 @@ static u16 hpi_control_get_string(const u32 h_control, const u16 attribute,
1714 n++; 1586 n++;
1715 if (n >= string_length) { 1587 if (n >= string_length) {
1716 psz_string[string_length - 1] = 0; 1588 psz_string[string_length - 1] = 0;
1717 hE = HPI_ERROR_INVALID_CONTROL_VALUE; 1589 err = HPI_ERROR_INVALID_CONTROL_VALUE;
1718 break; 1590 break;
1719 } 1591 }
1720 if (c == 0) 1592 if (c == 0)
@@ -1730,7 +1602,7 @@ static u16 hpi_control_get_string(const u32 h_control, const u16 attribute,
1730 if (c == 0) 1602 if (c == 0)
1731 break; 1603 break;
1732 } 1604 }
1733 return hE; 1605 return err;
1734} 1606}
1735 1607
1736u16 HPI_AESEBU__receiver_query_format(const struct hpi_hsubsys *ph_subsys, 1608u16 HPI_AESEBU__receiver_query_format(const struct hpi_hsubsys *ph_subsys,
@@ -2709,7 +2581,7 @@ u16 hpi_tone_detector_set_enable(const struct hpi_hsubsys *ph_subsys,
2709 u32 h_control, u32 enable) 2581 u32 h_control, u32 enable)
2710{ 2582{
2711 return hpi_control_param_set(ph_subsys, h_control, HPI_GENERIC_ENABLE, 2583 return hpi_control_param_set(ph_subsys, h_control, HPI_GENERIC_ENABLE,
2712 (u32)enable, 0); 2584 enable, 0);
2713} 2585}
2714 2586
2715u16 hpi_tone_detector_get_enable(const struct hpi_hsubsys *ph_subsys, 2587u16 hpi_tone_detector_get_enable(const struct hpi_hsubsys *ph_subsys,
@@ -2758,7 +2630,7 @@ u16 hpi_silence_detector_set_enable(const struct hpi_hsubsys *ph_subsys,
2758 u32 h_control, u32 enable) 2630 u32 h_control, u32 enable)
2759{ 2631{
2760 return hpi_control_param_set(ph_subsys, h_control, HPI_GENERIC_ENABLE, 2632 return hpi_control_param_set(ph_subsys, h_control, HPI_GENERIC_ENABLE,
2761 (u32)enable, 0); 2633 enable, 0);
2762} 2634}
2763 2635
2764u16 hpi_silence_detector_get_enable(const struct hpi_hsubsys *ph_subsys, 2636u16 hpi_silence_detector_get_enable(const struct hpi_hsubsys *ph_subsys,
@@ -2904,11 +2776,10 @@ u16 hpi_tuner_getRF_level(const struct hpi_hsubsys *ph_subsys, u32 h_control,
2904 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL, 2776 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2905 HPI_CONTROL_GET_STATE); 2777 HPI_CONTROL_GET_STATE);
2906 u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); 2778 u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
2907 hm.u.c.attribute = HPI_TUNER_LEVEL; 2779 hm.u.cu.attribute = HPI_TUNER_LEVEL_AVG;
2908 hm.u.c.param1 = HPI_TUNER_LEVEL_AVERAGE;
2909 hpi_send_recv(&hm, &hr); 2780 hpi_send_recv(&hm, &hr);
2910 if (pw_level) 2781 if (pw_level)
2911 *pw_level = (short)hr.u.c.param1; 2782 *pw_level = hr.u.cu.tuner.s_level;
2912 return hr.error; 2783 return hr.error;
2913} 2784}
2914 2785
@@ -2921,11 +2792,10 @@ u16 hpi_tuner_get_rawRF_level(const struct hpi_hsubsys *ph_subsys,
2921 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL, 2792 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2922 HPI_CONTROL_GET_STATE); 2793 HPI_CONTROL_GET_STATE);
2923 u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index); 2794 u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
2924 hm.u.c.attribute = HPI_TUNER_LEVEL; 2795 hm.u.cu.attribute = HPI_TUNER_LEVEL_RAW;
2925 hm.u.c.param1 = HPI_TUNER_LEVEL_RAW;
2926 hpi_send_recv(&hm, &hr); 2796 hpi_send_recv(&hm, &hr);
2927 if (pw_level) 2797 if (pw_level)
2928 *pw_level = (short)hr.u.c.param1; 2798 *pw_level = hr.u.cu.tuner.s_level;
2929 return hr.error; 2799 return hr.error;
2930} 2800}
2931 2801
@@ -3213,728 +3083,3 @@ u16 hpi_vox_get_threshold(const struct hpi_hsubsys *ph_subsys, u32 h_control,
3213 3083
3214 return hr.error; 3084 return hr.error;
3215} 3085}
3216
3217static size_t strv_packet_size = MIN_STRV_PACKET_SIZE;
3218
3219static size_t entity_type_to_size[LAST_ENTITY_TYPE] = {
3220 0,
3221 sizeof(struct hpi_entity),
3222 sizeof(void *),
3223
3224 sizeof(int),
3225 sizeof(float),
3226 sizeof(double),
3227
3228 sizeof(char),
3229 sizeof(char),
3230
3231 4 * sizeof(char),
3232 16 * sizeof(char),
3233 6 * sizeof(char),
3234};
3235
3236static inline size_t hpi_entity_size(struct hpi_entity *entity_ptr)
3237{
3238 return entity_ptr->header.size;
3239}
3240
3241static inline size_t hpi_entity_header_size(struct hpi_entity *entity_ptr)
3242{
3243 return sizeof(entity_ptr->header);
3244}
3245
3246static inline size_t hpi_entity_value_size(struct hpi_entity *entity_ptr)
3247{
3248 return hpi_entity_size(entity_ptr) -
3249 hpi_entity_header_size(entity_ptr);
3250}
3251
3252static inline size_t hpi_entity_item_count(struct hpi_entity *entity_ptr)
3253{
3254 return hpi_entity_value_size(entity_ptr) /
3255 entity_type_to_size[entity_ptr->header.type];
3256}
3257
3258static inline struct hpi_entity *hpi_entity_ptr_to_next(struct hpi_entity
3259 *entity_ptr)
3260{
3261 return (void *)(((u8 *)entity_ptr) + hpi_entity_size(entity_ptr));
3262}
3263
3264static inline u16 hpi_entity_check_type(const enum e_entity_type t)
3265{
3266 if (t >= 0 && t < STR_TYPE_FIELD_MAX)
3267 return 0;
3268 return HPI_ERROR_ENTITY_TYPE_INVALID;
3269}
3270
3271static inline u16 hpi_entity_check_role(const enum e_entity_role r)
3272{
3273 if (r >= 0 && r < STR_ROLE_FIELD_MAX)
3274 return 0;
3275 return HPI_ERROR_ENTITY_ROLE_INVALID;
3276}
3277
3278static u16 hpi_entity_get_next(struct hpi_entity *entity, int recursive_flag,
3279 void *guard_p, struct hpi_entity **next)
3280{
3281 HPI_DEBUG_ASSERT(entity != NULL);
3282 HPI_DEBUG_ASSERT(next != NULL);
3283 HPI_DEBUG_ASSERT(hpi_entity_size(entity) != 0);
3284
3285 if (guard_p <= (void *)entity) {
3286 *next = NULL;
3287 return 0;
3288 }
3289
3290 if (recursive_flag && entity->header.type == entity_type_sequence)
3291 *next = (struct hpi_entity *)entity->value;
3292 else
3293 *next = (struct hpi_entity *)hpi_entity_ptr_to_next(entity);
3294
3295 if (guard_p <= (void *)*next) {
3296 *next = NULL;
3297 return 0;
3298 }
3299
3300 HPI_DEBUG_ASSERT(guard_p >= (void *)hpi_entity_ptr_to_next(*next));
3301 return 0;
3302}
3303
3304u16 hpi_entity_find_next(struct hpi_entity *container_entity,
3305 enum e_entity_type type, enum e_entity_role role, int recursive_flag,
3306 struct hpi_entity **current_match)
3307{
3308 struct hpi_entity *tmp = NULL;
3309 void *guard_p = NULL;
3310
3311 HPI_DEBUG_ASSERT(container_entity != NULL);
3312 guard_p = hpi_entity_ptr_to_next(container_entity);
3313
3314 if (*current_match != NULL)
3315 hpi_entity_get_next(*current_match, recursive_flag, guard_p,
3316 &tmp);
3317 else
3318 hpi_entity_get_next(container_entity, 1, guard_p, &tmp);
3319
3320 while (tmp) {
3321 u16 err;
3322
3323 HPI_DEBUG_ASSERT((void *)tmp >= (void *)container_entity);
3324
3325 if ((!type || tmp->header.type == type) && (!role
3326 || tmp->header.role == role)) {
3327 *current_match = tmp;
3328 return 0;
3329 }
3330
3331 err = hpi_entity_get_next(tmp, recursive_flag, guard_p,
3332 current_match);
3333 if (err)
3334 return err;
3335
3336 tmp = *current_match;
3337 }
3338
3339 *current_match = NULL;
3340 return 0;
3341}
3342
3343void hpi_entity_free(struct hpi_entity *entity)
3344{
3345 kfree(entity);
3346}
3347
3348static u16 hpi_entity_alloc_and_copy(struct hpi_entity *src,
3349 struct hpi_entity **dst)
3350{
3351 size_t buf_size;
3352 HPI_DEBUG_ASSERT(dst != NULL);
3353 HPI_DEBUG_ASSERT(src != NULL);
3354
3355 buf_size = hpi_entity_size(src);
3356 *dst = kmalloc(buf_size, GFP_KERNEL);
3357 if (*dst == NULL)
3358 return HPI_ERROR_MEMORY_ALLOC;
3359 memcpy(*dst, src, buf_size);
3360 return 0;
3361}
3362
3363u16 hpi_universal_info(const struct hpi_hsubsys *ph_subsys, u32 hC,
3364 struct hpi_entity **info)
3365{
3366 struct hpi_msg_strv hm;
3367 struct hpi_res_strv *phr;
3368 u16 hpi_err;
3369 int remaining_attempts = 2;
3370 size_t resp_packet_size = 1024;
3371
3372 *info = NULL;
3373
3374 while (remaining_attempts--) {
3375 phr = kmalloc(resp_packet_size, GFP_KERNEL);
3376 HPI_DEBUG_ASSERT(phr != NULL);
3377
3378 hpi_init_message_responseV1(&hm.h, (u16)sizeof(hm), &phr->h,
3379 (u16)resp_packet_size, HPI_OBJ_CONTROL,
3380 HPI_CONTROL_GET_INFO);
3381 u32TOINDEXES(hC, &hm.h.adapter_index, &hm.h.obj_index);
3382
3383 hm.strv.header.size = sizeof(hm.strv);
3384 phr->strv.header.size = resp_packet_size - sizeof(phr->h);
3385
3386 hpi_send_recv((struct hpi_message *)&hm.h,
3387 (struct hpi_response *)&phr->h);
3388 if (phr->h.error == HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL) {
3389
3390 HPI_DEBUG_ASSERT(phr->h.specific_error >
3391 MIN_STRV_PACKET_SIZE
3392 && phr->h.specific_error < 1500);
3393 resp_packet_size = phr->h.specific_error;
3394 } else {
3395 remaining_attempts = 0;
3396 if (!phr->h.error)
3397 hpi_entity_alloc_and_copy(&phr->strv, info);
3398 }
3399
3400 hpi_err = phr->h.error;
3401 kfree(phr);
3402 }
3403
3404 return hpi_err;
3405}
3406
3407u16 hpi_universal_get(const struct hpi_hsubsys *ph_subsys, u32 hC,
3408 struct hpi_entity **value)
3409{
3410 struct hpi_msg_strv hm;
3411 struct hpi_res_strv *phr;
3412 u16 hpi_err;
3413 int remaining_attempts = 2;
3414
3415 *value = NULL;
3416
3417 while (remaining_attempts--) {
3418 phr = kmalloc(strv_packet_size, GFP_KERNEL);
3419 if (!phr)
3420 return HPI_ERROR_MEMORY_ALLOC;
3421
3422 hpi_init_message_responseV1(&hm.h, (u16)sizeof(hm), &phr->h,
3423 (u16)strv_packet_size, HPI_OBJ_CONTROL,
3424 HPI_CONTROL_GET_STATE);
3425 u32TOINDEXES(hC, &hm.h.adapter_index, &hm.h.obj_index);
3426
3427 hm.strv.header.size = sizeof(hm.strv);
3428 phr->strv.header.size = strv_packet_size - sizeof(phr->h);
3429
3430 hpi_send_recv((struct hpi_message *)&hm.h,
3431 (struct hpi_response *)&phr->h);
3432 if (phr->h.error == HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL) {
3433
3434 HPI_DEBUG_ASSERT(phr->h.specific_error >
3435 MIN_STRV_PACKET_SIZE
3436 && phr->h.specific_error < 1000);
3437 strv_packet_size = phr->h.specific_error;
3438 } else {
3439 remaining_attempts = 0;
3440 if (!phr->h.error)
3441 hpi_entity_alloc_and_copy(&phr->strv, value);
3442 }
3443
3444 hpi_err = phr->h.error;
3445 kfree(phr);
3446 }
3447
3448 return hpi_err;
3449}
3450
3451u16 hpi_universal_set(const struct hpi_hsubsys *ph_subsys, u32 hC,
3452 struct hpi_entity *value)
3453{
3454 struct hpi_msg_strv *phm;
3455 struct hpi_res_strv hr;
3456
3457 phm = kmalloc(sizeof(phm->h) + value->header.size, GFP_KERNEL);
3458 HPI_DEBUG_ASSERT(phm != NULL);
3459
3460 hpi_init_message_responseV1(&phm->h,
3461 sizeof(phm->h) + value->header.size, &hr.h, sizeof(hr),
3462 HPI_OBJ_CONTROL, HPI_CONTROL_SET_STATE);
3463 u32TOINDEXES(hC, &phm->h.adapter_index, &phm->h.obj_index);
3464 hr.strv.header.size = sizeof(hr.strv);
3465
3466 memcpy(&phm->strv, value, value->header.size);
3467 hpi_send_recv((struct hpi_message *)&phm->h,
3468 (struct hpi_response *)&hr.h);
3469
3470 return hr.h.error;
3471}
3472
3473u16 hpi_entity_alloc_and_pack(const enum e_entity_type type,
3474 const size_t item_count, const enum e_entity_role role, void *value,
3475 struct hpi_entity **entity)
3476{
3477 size_t bytes_to_copy, total_size;
3478 u16 hE = 0;
3479 *entity = NULL;
3480
3481 hE = hpi_entity_check_type(type);
3482 if (hE)
3483 return hE;
3484
3485 HPI_DEBUG_ASSERT(role > entity_role_null && type < LAST_ENTITY_TYPE);
3486
3487 bytes_to_copy = entity_type_to_size[type] * item_count;
3488 total_size = hpi_entity_header_size(*entity) + bytes_to_copy;
3489
3490 HPI_DEBUG_ASSERT(total_size >= hpi_entity_header_size(*entity)
3491 && total_size < STR_SIZE_FIELD_MAX);
3492
3493 *entity = kmalloc(total_size, GFP_KERNEL);
3494 if (*entity == NULL)
3495 return HPI_ERROR_MEMORY_ALLOC;
3496 memcpy((*entity)->value, value, bytes_to_copy);
3497 (*entity)->header.size =
3498 hpi_entity_header_size(*entity) + bytes_to_copy;
3499 (*entity)->header.type = type;
3500 (*entity)->header.role = role;
3501 return 0;
3502}
3503
3504u16 hpi_entity_copy_value_from(struct hpi_entity *entity,
3505 enum e_entity_type type, size_t item_count, void *value_dst_p)
3506{
3507 size_t bytes_to_copy;
3508
3509 if (entity->header.type != type)
3510 return HPI_ERROR_ENTITY_TYPE_MISMATCH;
3511
3512 if (hpi_entity_item_count(entity) != item_count)
3513 return HPI_ERROR_ENTITY_ITEM_COUNT;
3514
3515 bytes_to_copy = entity_type_to_size[type] * item_count;
3516 memcpy(value_dst_p, entity->value, bytes_to_copy);
3517 return 0;
3518}
3519
3520u16 hpi_entity_unpack(struct hpi_entity *entity, enum e_entity_type *type,
3521 size_t *item_count, enum e_entity_role *role, void **value)
3522{
3523 u16 err = 0;
3524 HPI_DEBUG_ASSERT(entity != NULL);
3525
3526 if (type)
3527 *type = entity->header.type;
3528
3529 if (role)
3530 *role = entity->header.role;
3531
3532 if (value)
3533 *value = entity->value;
3534
3535 if (item_count != NULL) {
3536 if (entity->header.type == entity_type_sequence) {
3537 void *guard_p = hpi_entity_ptr_to_next(entity);
3538 struct hpi_entity *next = NULL;
3539 void *contents = entity->value;
3540
3541 *item_count = 0;
3542 while (contents < guard_p) {
3543 (*item_count)++;
3544 err = hpi_entity_get_next(contents, 0,
3545 guard_p, &next);
3546 if (next == NULL || err)
3547 break;
3548 contents = next;
3549 }
3550 } else {
3551 *item_count = hpi_entity_item_count(entity);
3552 }
3553 }
3554 return err;
3555}
3556
3557u16 hpi_gpio_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
3558 u32 *ph_gpio, u16 *pw_number_input_bits, u16 *pw_number_output_bits)
3559{
3560 struct hpi_message hm;
3561 struct hpi_response hr;
3562 hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_OPEN);
3563 hm.adapter_index = adapter_index;
3564
3565 hpi_send_recv(&hm, &hr);
3566
3567 if (hr.error == 0) {
3568 *ph_gpio =
3569 hpi_indexes_to_handle(HPI_OBJ_GPIO, adapter_index, 0);
3570 if (pw_number_input_bits)
3571 *pw_number_input_bits = hr.u.l.number_input_bits;
3572 if (pw_number_output_bits)
3573 *pw_number_output_bits = hr.u.l.number_output_bits;
3574 } else
3575 *ph_gpio = 0;
3576 return hr.error;
3577}
3578
3579u16 hpi_gpio_read_bit(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
3580 u16 bit_index, u16 *pw_bit_data)
3581{
3582 struct hpi_message hm;
3583 struct hpi_response hr;
3584 hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_READ_BIT);
3585 u32TOINDEX(h_gpio, &hm.adapter_index);
3586 hm.u.l.bit_index = bit_index;
3587
3588 hpi_send_recv(&hm, &hr);
3589
3590 *pw_bit_data = hr.u.l.bit_data[0];
3591 return hr.error;
3592}
3593
3594u16 hpi_gpio_read_all_bits(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
3595 u16 aw_all_bit_data[4]
3596 )
3597{
3598 struct hpi_message hm;
3599 struct hpi_response hr;
3600 hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_READ_ALL);
3601 u32TOINDEX(h_gpio, &hm.adapter_index);
3602
3603 hpi_send_recv(&hm, &hr);
3604
3605 if (aw_all_bit_data) {
3606 aw_all_bit_data[0] = hr.u.l.bit_data[0];
3607 aw_all_bit_data[1] = hr.u.l.bit_data[1];
3608 aw_all_bit_data[2] = hr.u.l.bit_data[2];
3609 aw_all_bit_data[3] = hr.u.l.bit_data[3];
3610 }
3611 return hr.error;
3612}
3613
3614u16 hpi_gpio_write_bit(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
3615 u16 bit_index, u16 bit_data)
3616{
3617 struct hpi_message hm;
3618 struct hpi_response hr;
3619 hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_WRITE_BIT);
3620 u32TOINDEX(h_gpio, &hm.adapter_index);
3621 hm.u.l.bit_index = bit_index;
3622 hm.u.l.bit_data = bit_data;
3623
3624 hpi_send_recv(&hm, &hr);
3625
3626 return hr.error;
3627}
3628
3629u16 hpi_gpio_write_status(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
3630 u16 aw_all_bit_data[4]
3631 )
3632{
3633 struct hpi_message hm;
3634 struct hpi_response hr;
3635 hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO,
3636 HPI_GPIO_WRITE_STATUS);
3637 u32TOINDEX(h_gpio, &hm.adapter_index);
3638
3639 hpi_send_recv(&hm, &hr);
3640
3641 if (aw_all_bit_data) {
3642 aw_all_bit_data[0] = hr.u.l.bit_data[0];
3643 aw_all_bit_data[1] = hr.u.l.bit_data[1];
3644 aw_all_bit_data[2] = hr.u.l.bit_data[2];
3645 aw_all_bit_data[3] = hr.u.l.bit_data[3];
3646 }
3647 return hr.error;
3648}
3649
3650u16 hpi_async_event_open(const struct hpi_hsubsys *ph_subsys,
3651 u16 adapter_index, u32 *ph_async)
3652{
3653 struct hpi_message hm;
3654 struct hpi_response hr;
3655 hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
3656 HPI_ASYNCEVENT_OPEN);
3657 hm.adapter_index = adapter_index;
3658
3659 hpi_send_recv(&hm, &hr);
3660
3661 if (hr.error == 0)
3662
3663 *ph_async =
3664 hpi_indexes_to_handle(HPI_OBJ_ASYNCEVENT,
3665 adapter_index, 0);
3666 else
3667 *ph_async = 0;
3668 return hr.error;
3669
3670}
3671
3672u16 hpi_async_event_close(const struct hpi_hsubsys *ph_subsys, u32 h_async)
3673{
3674 struct hpi_message hm;
3675 struct hpi_response hr;
3676 hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
3677 HPI_ASYNCEVENT_OPEN);
3678 u32TOINDEX(h_async, &hm.adapter_index);
3679
3680 hpi_send_recv(&hm, &hr);
3681
3682 return hr.error;
3683}
3684
3685u16 hpi_async_event_wait(const struct hpi_hsubsys *ph_subsys, u32 h_async,
3686 u16 maximum_events, struct hpi_async_event *p_events,
3687 u16 *pw_number_returned)
3688{
3689
3690 return 0;
3691}
3692
3693u16 hpi_async_event_get_count(const struct hpi_hsubsys *ph_subsys,
3694 u32 h_async, u16 *pw_count)
3695{
3696 struct hpi_message hm;
3697 struct hpi_response hr;
3698 hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
3699 HPI_ASYNCEVENT_GETCOUNT);
3700 u32TOINDEX(h_async, &hm.adapter_index);
3701
3702 hpi_send_recv(&hm, &hr);
3703
3704 if (hr.error == 0)
3705 if (pw_count)
3706 *pw_count = hr.u.as.u.count.count;
3707
3708 return hr.error;
3709}
3710
3711u16 hpi_async_event_get(const struct hpi_hsubsys *ph_subsys, u32 h_async,
3712 u16 maximum_events, struct hpi_async_event *p_events,
3713 u16 *pw_number_returned)
3714{
3715 struct hpi_message hm;
3716 struct hpi_response hr;
3717 hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
3718 HPI_ASYNCEVENT_GET);
3719 u32TOINDEX(h_async, &hm.adapter_index);
3720
3721 hpi_send_recv(&hm, &hr);
3722 if (!hr.error) {
3723 memcpy(p_events, &hr.u.as.u.event,
3724 sizeof(struct hpi_async_event));
3725 *pw_number_returned = 1;
3726 }
3727
3728 return hr.error;
3729}
3730
3731u16 hpi_nv_memory_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
3732 u32 *ph_nv_memory, u16 *pw_size_in_bytes)
3733{
3734 struct hpi_message hm;
3735 struct hpi_response hr;
3736 hpi_init_message_response(&hm, &hr, HPI_OBJ_NVMEMORY,
3737 HPI_NVMEMORY_OPEN);
3738 hm.adapter_index = adapter_index;
3739
3740 hpi_send_recv(&hm, &hr);
3741
3742 if (hr.error == 0) {
3743 *ph_nv_memory =
3744 hpi_indexes_to_handle(HPI_OBJ_NVMEMORY, adapter_index,
3745 0);
3746 if (pw_size_in_bytes)
3747 *pw_size_in_bytes = hr.u.n.size_in_bytes;
3748 } else
3749 *ph_nv_memory = 0;
3750 return hr.error;
3751}
3752
3753u16 hpi_nv_memory_read_byte(const struct hpi_hsubsys *ph_subsys,
3754 u32 h_nv_memory, u16 index, u16 *pw_data)
3755{
3756 struct hpi_message hm;
3757 struct hpi_response hr;
3758 hpi_init_message_response(&hm, &hr, HPI_OBJ_NVMEMORY,
3759 HPI_NVMEMORY_READ_BYTE);
3760 u32TOINDEX(h_nv_memory, &hm.adapter_index);
3761 hm.u.n.address = index;
3762
3763 hpi_send_recv(&hm, &hr);
3764
3765 *pw_data = hr.u.n.data;
3766 return hr.error;
3767}
3768
3769u16 hpi_nv_memory_write_byte(const struct hpi_hsubsys *ph_subsys,
3770 u32 h_nv_memory, u16 index, u16 data)
3771{
3772 struct hpi_message hm;
3773 struct hpi_response hr;
3774 hpi_init_message_response(&hm, &hr, HPI_OBJ_NVMEMORY,
3775 HPI_NVMEMORY_WRITE_BYTE);
3776 u32TOINDEX(h_nv_memory, &hm.adapter_index);
3777 hm.u.n.address = index;
3778 hm.u.n.data = data;
3779
3780 hpi_send_recv(&hm, &hr);
3781
3782 return hr.error;
3783}
3784
3785u16 hpi_profile_open_all(const struct hpi_hsubsys *ph_subsys,
3786 u16 adapter_index, u16 profile_index, u32 *ph_profile,
3787 u16 *pw_max_profiles)
3788{
3789 struct hpi_message hm;
3790 struct hpi_response hr;
3791 hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
3792 HPI_PROFILE_OPEN_ALL);
3793 hm.adapter_index = adapter_index;
3794 hm.obj_index = profile_index;
3795 hpi_send_recv(&hm, &hr);
3796
3797 *pw_max_profiles = hr.u.p.u.o.max_profiles;
3798 if (hr.error == 0)
3799 *ph_profile =
3800 hpi_indexes_to_handle(HPI_OBJ_PROFILE, adapter_index,
3801 profile_index);
3802 else
3803 *ph_profile = 0;
3804 return hr.error;
3805}
3806
3807u16 hpi_profile_get(const struct hpi_hsubsys *ph_subsys, u32 h_profile,
3808 u16 bin_index, u16 *pw_seconds, u32 *pmicro_seconds, u32 *pcall_count,
3809 u32 *pmax_micro_seconds, u32 *pmin_micro_seconds)
3810{
3811 struct hpi_message hm;
3812 struct hpi_response hr;
3813 hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE, HPI_PROFILE_GET);
3814 u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
3815 hm.u.p.bin_index = bin_index;
3816 hpi_send_recv(&hm, &hr);
3817 if (pw_seconds)
3818 *pw_seconds = hr.u.p.u.t.seconds;
3819 if (pmicro_seconds)
3820 *pmicro_seconds = hr.u.p.u.t.micro_seconds;
3821 if (pcall_count)
3822 *pcall_count = hr.u.p.u.t.call_count;
3823 if (pmax_micro_seconds)
3824 *pmax_micro_seconds = hr.u.p.u.t.max_micro_seconds;
3825 if (pmin_micro_seconds)
3826 *pmin_micro_seconds = hr.u.p.u.t.min_micro_seconds;
3827 return hr.error;
3828}
3829
3830u16 hpi_profile_get_utilization(const struct hpi_hsubsys *ph_subsys,
3831 u32 h_profile, u32 *putilization)
3832{
3833 struct hpi_message hm;
3834 struct hpi_response hr;
3835 hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
3836 HPI_PROFILE_GET_UTILIZATION);
3837 u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
3838 hpi_send_recv(&hm, &hr);
3839 if (hr.error) {
3840 if (putilization)
3841 *putilization = 0;
3842 } else {
3843 if (putilization)
3844 *putilization = hr.u.p.u.t.call_count;
3845 }
3846 return hr.error;
3847}
3848
3849u16 hpi_profile_get_name(const struct hpi_hsubsys *ph_subsys, u32 h_profile,
3850 u16 bin_index, char *sz_name, u16 name_length)
3851{
3852 struct hpi_message hm;
3853 struct hpi_response hr;
3854 hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
3855 HPI_PROFILE_GET_NAME);
3856 u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
3857 hm.u.p.bin_index = bin_index;
3858 hpi_send_recv(&hm, &hr);
3859 if (hr.error) {
3860 if (sz_name)
3861 strcpy(sz_name, "??");
3862 } else {
3863 if (sz_name)
3864 memcpy(sz_name, (char *)hr.u.p.u.n.sz_name,
3865 name_length);
3866 }
3867 return hr.error;
3868}
3869
3870u16 hpi_profile_start_all(const struct hpi_hsubsys *ph_subsys, u32 h_profile)
3871{
3872 struct hpi_message hm;
3873 struct hpi_response hr;
3874 hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
3875 HPI_PROFILE_START_ALL);
3876 u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
3877 hpi_send_recv(&hm, &hr);
3878
3879 return hr.error;
3880}
3881
3882u16 hpi_profile_stop_all(const struct hpi_hsubsys *ph_subsys, u32 h_profile)
3883{
3884 struct hpi_message hm;
3885 struct hpi_response hr;
3886 hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
3887 HPI_PROFILE_STOP_ALL);
3888 u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
3889 hpi_send_recv(&hm, &hr);
3890
3891 return hr.error;
3892}
3893
3894u16 hpi_watchdog_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
3895 u32 *ph_watchdog)
3896{
3897 struct hpi_message hm;
3898 struct hpi_response hr;
3899 hpi_init_message_response(&hm, &hr, HPI_OBJ_WATCHDOG,
3900 HPI_WATCHDOG_OPEN);
3901 hm.adapter_index = adapter_index;
3902
3903 hpi_send_recv(&hm, &hr);
3904
3905 if (hr.error == 0)
3906 *ph_watchdog =
3907 hpi_indexes_to_handle(HPI_OBJ_WATCHDOG, adapter_index,
3908 0);
3909 else
3910 *ph_watchdog = 0;
3911 return hr.error;
3912}
3913
3914u16 hpi_watchdog_set_time(const struct hpi_hsubsys *ph_subsys, u32 h_watchdog,
3915 u32 time_millisec)
3916{
3917 struct hpi_message hm;
3918 struct hpi_response hr;
3919 hpi_init_message_response(&hm, &hr, HPI_OBJ_WATCHDOG,
3920 HPI_WATCHDOG_SET_TIME);
3921 u32TOINDEX(h_watchdog, &hm.adapter_index);
3922 hm.u.w.time_ms = time_millisec;
3923
3924 hpi_send_recv(&hm, &hr);
3925
3926 return hr.error;
3927}
3928
3929u16 hpi_watchdog_ping(const struct hpi_hsubsys *ph_subsys, u32 h_watchdog)
3930{
3931 struct hpi_message hm;
3932 struct hpi_response hr;
3933 hpi_init_message_response(&hm, &hr, HPI_OBJ_WATCHDOG,
3934 HPI_WATCHDOG_PING);
3935 u32TOINDEX(h_watchdog, &hm.adapter_index);
3936
3937 hpi_send_recv(&hm, &hr);
3938
3939 return hr.error;
3940}