2 * Copyright (c) 2013 Qualcomm Atheros, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted (subject to the limitations in the
7 * disclaimer below) provided that the following conditions are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the
17 * * Neither the name of Qualcomm Atheros nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
22 * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
23 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <OTUS/OTUS_soc.h>
36 #include <cmnos_api.h>
38 #include <Magpie_api.h>
45 fwd_tgt_softc_t fwd_sc;
47 void fwd_tgt_recv(VBUF *hdr_buf, VBUF *buf, void *ctx );
48 void fwd_retbuf_handler(VBUF *buf, void *ServiceCtx);
50 hif_handle_t fwd_init()
52 HIF_CALLBACK hifconfig;
53 A_UINT32 size, res_headroom;
55 hifconfig.send_buf_done = fwd_retbuf_handler;
56 hifconfig.recv_buf = fwd_tgt_recv;
57 hifconfig.context = &fwd_sc;
59 res_headroom = HIF_get_reserved_headroom(NULL);
61 size = sizeof(fwd_rsp_t) + res_headroom;
63 HIF_register_callback(NULL, &hifconfig);
65 HIF_get_default_pipe(NULL, &fwd_sc.rx_pipe, &fwd_sc.tx_pipe);
71 fwd_retbuf_handler(VBUF *buf, void *ServiceCtx)
73 HIF_return_recv_buf(fwd_sc.hif_handle, fwd_sc.rx_pipe, buf);
77 fwd_tgt_process_last(A_UINT32 size, A_UINT32 cksum)
80 A_UINT32 *image = (A_UINT32 *)fwd_sc.addr;
82 for (i = 0 ; i < size; i += 4, image++)
83 checksum = checksum ^ *image;
85 if (checksum == cksum)
88 return A_STATUS_FAILED;
94 fwd_tgt_recv(VBUF *hdr_buf, VBUF *buf, void *ctx )
96 volatile a_uint8_t *data;
97 A_UINT32 len, seglen, offset, i, more, eloc;
98 volatile A_UINT32 *image, *daddr;
99 volatile fwd_cmd_t *c;
100 volatile fwd_rsp_t *r;
105 data = buf->desc_list->buf_addr + buf->desc_list->data_offset;
106 seglen = buf->desc_list->data_size;
108 c = (fwd_cmd_t *)data;
112 image = (A_UINT32 *)(c + 1);
115 fwd_sc.addr = (A_UINT32)(*image);
119 daddr = (A_UINT32 *)(fwd_sc.addr + offset);
125 for (i = 0 ; i < len; i += 4) {
131 desc = buf->desc_list;
132 while(desc->next_desc != NULL)
133 desc = desc->next_desc;
134 desc->data_size -= seglen;
135 buf->buf_length -= seglen;
137 r = (fwd_rsp_t *)(desc->buf_addr + desc->data_offset + desc->data_size);
138 desc->data_size += sizeof(fwd_rsp_t);
139 buf->buf_length += sizeof(fwd_rsp_t);
141 r->offset = c->offset;
144 r->rsp = FWD_RSP_ACK;
148 status = fwd_tgt_process_last(offset + len, *image);
150 /* reach to the jump location */
154 if (status == A_STATUS_OK)
155 r->rsp = FWD_RSP_SUCCESS;
157 r->rsp = FWD_RSP_FAILED;
161 HIF_send_buffer(fwd_sc.hif_handle, fwd_sc.tx_pipe, buf);
163 if (!more && (status == A_STATUS_OK)) {
164 funcptr = (jmp_func)eloc;