OpenCores
URL https://opencores.org/ocsvn/funbase_ip_library/funbase_ip_library/trunk

Subversion Repositories funbase_ip_library

[/] [funbase_ip_library/] [trunk/] [TUT/] [ip.swp.api/] [openmcapi/] [1.0/] [test/] [mgmt_svc.c] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
/*
2
 * Copyright (c) 2010, Mentor Graphics Corporation
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 * 1. Redistributions of source code must retain the above copyright notice,
9
 *    this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
11
 *    this list of conditions and the following disclaimer in the documentation
12
 *    and/or other materials provided with the distribution.
13
 * 3. Neither the name of the <ORGANIZATION> nor the names of its contributors
14
 *    may be used to endorse or promote products derived from this software
15
 *    without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
 * POSSIBILITY OF SUCH DAMAGE.
28
 */
29
 
30
/*
31
*   FILENAME
32
*
33
*       mgmt_svc.c
34
*
35
*
36
*************************************************************************/
37
 
38
#include <stdio.h>
39
#include "mgmt_svc.h"
40
#include "support_suite/mcapid_support.h"
41
#include "mcapid.h"
42
 
43
/************************************************************************
44
*
45
*   FUNCTION
46
*
47
*       MCAPID_Mgmt_Service
48
*
49
*   DESCRIPTION
50
*
51
*       This function processes incoming packets instructing the node
52
*       to create an endpoint, delete an endpoint, etc.
53
*
54
*************************************************************************/
55
MCAPI_THREAD_ENTRY(MCAPID_Mgmt_Service)
56
{
57
    size_t                      rx_len;
58
    MCAPID_STRUCT               *mcapi_struct = (MCAPID_STRUCT*)argv;
59
    unsigned char               buffer[MCAPID_MGMT_PKT_LEN];
60
    mcapi_pktchan_send_hndl_t   tx_handle;
61
    mcapi_pktchan_recv_hndl_t   rx_handle;
62
    int                         tx_handle_in_use = MCAPI_FALSE,
63
                                rx_handle_in_use = MCAPI_FALSE;
64
    mcapi_sclchan_send_hndl_t   tx_handle_scl;
65
    mcapi_sclchan_recv_hndl_t   rx_handle_scl;
66
    int                         tx_handle_scl_in_use = MCAPI_FALSE,
67
                                rx_handle_scl_in_use = MCAPI_FALSE;
68
    mcapi_request_t             pkt_tx_request, pkt_rx_request,
69
                                scl_tx_request, scl_rx_request;
70
    mcapi_endpoint_t            endpoint;
71
    mcapi_node_t                this_node;
72
    mcapi_status_t              status;
73
    mcapi_port_t                port;
74
    mcapi_priority_t            prio;
75
    mcapi_boolean_t             complete;
76
    mcapi_request_t             request;
77
    size_t                      size;
78
 
79
    this_node = mcapi_get_node_id(&status);
80
 
81
    for (;;)
82
    {
83
        /* Wait for a message. */
84
        mcapi_msg_recv(mcapi_struct->local_endp, buffer, MCAPID_MGMT_PKT_LEN,
85
                       &rx_len, &mcapi_struct->status);
86
 
87
        if (mcapi_struct->status == MCAPI_SUCCESS)
88
        {
89
            /* Sleep the appropriate amount of time - this gives the other side
90
             * time to issue a command before the management task causes an
91
             * action.
92
             */
93
            MCAPID_Sleep(mcapi_get32(buffer, MCAPID_MGMT_PAUSE_OFFSET));
94
 
95
            /* Determine the type of message. */
96
            switch (mcapi_get32(buffer, MCAPID_MGMT_TYPE_OFFSET))
97
            {
98
                /* Create an endpoint. */
99
                case MCAPID_MGMT_CREATE_ENDP:
100
 
101
                    port = mcapi_get32(buffer, MCAPID_MGMT_FOREIGN_PORT_OFFSET);
102
 
103
                    /* Create the endpoint with specified port ID. */
104
                    mcapi_create_endpoint(port, &mcapi_struct->status);
105
                    if (mcapi_struct->status != MCAPI_SUCCESS)
106
                        printf("error creating endport %d (%d)\n", port,
107
                               mcapi_struct->status);
108
 
109
                    break;
110
 
111
                /* Delete an endpoint. */
112
                case MCAPID_MGMT_DELETE_ENDP:
113
 
114
                    port = mcapi_get32(buffer, MCAPID_MGMT_FOREIGN_PORT_OFFSET);
115
                    mcapi_get_endpoint_i(this_node, port, &endpoint, &request,
116
                                         &status);
117
                    complete = mcapi_wait(&request, &size, &status, 0);
118
 
119
                    if (complete && (status == MCAPI_SUCCESS))
120
                    {
121
                        /* Delete the endpoint. */
122
                        mcapi_delete_endpoint(endpoint, &mcapi_struct->status);
123
                        if (mcapi_struct->status != MCAPI_SUCCESS)
124
                            printf("error deleting endport %d (%d)\n", port,
125
                                   mcapi_struct->status);
126
                    }
127
                    else
128
                    {
129
                        printf("%s: tried to delete a non-existent endpoint!\n",
130
                               __func__);
131
                    }
132
 
133
                    break;
134
 
135
                /* Send a blocking message. */
136
                case MCAPID_MGMT_TX_BLCK_MSG:
137
 
138
                    port = mcapi_get32(buffer, MCAPID_MGMT_FOREIGN_PORT_OFFSET);
139
                    mcapi_get_endpoint_i(this_node, port, &endpoint, &request,
140
                                         &status);
141
                    complete = mcapi_wait(&request, &size, &status, 0);
142
 
143
                    if (complete && (status == MCAPI_SUCCESS))
144
                    {
145
                        prio = mcapi_get32(buffer, MCAPID_MGMT_PRIO_OFFSET);
146
 
147
                        /* Send this packet back to the other side. */
148
                        mcapi_msg_send(endpoint,
149
                                       mcapi_get32(buffer, MCAPID_MGMT_LOCAL_ENDP_OFFSET),
150
                                       buffer, rx_len, prio,
151
                                       &mcapi_struct->status);
152
                    }
153
                    else
154
                    {
155
                        printf("%s: tried to delete a non-existent endpoint!\n",
156
                               __func__);
157
                    }
158
 
159
                    break;
160
 
161
                /* Send a non-blocking message. */
162
                case MCAPID_MGMT_TX_NONBLCK_MSG:
163
 
164
                    port = mcapi_get32(buffer, MCAPID_MGMT_FOREIGN_PORT_OFFSET);
165
                    mcapi_get_endpoint_i(this_node, port, &endpoint, &request,
166
                                         &status);
167
                    complete = mcapi_wait(&request, &size, &status, 0);
168
 
169
                    if (complete && (status == MCAPI_SUCCESS))
170
                    {
171
                        prio = mcapi_get32(buffer, MCAPID_MGMT_PRIO_OFFSET);
172
 
173
                        /* Send this packet back to the other side. */
174
                        mcapi_msg_send_i(endpoint,
175
                                         mcapi_get32(buffer, MCAPID_MGMT_LOCAL_ENDP_OFFSET),
176
                                         buffer, rx_len, prio,
177
                                         &mcapi_struct->request,
178
                                         &mcapi_struct->status);
179
                    }
180
                    else
181
                    {
182
                        printf("%s: tried to send msg to a non-existent "
183
                               "endpoint!\n", __func__);
184
                    }
185
 
186
                    break;
187
 
188
                /* Open a local endpoint as a sender. */
189
                case MCAPID_MGMT_OPEN_TX_SIDE_PKT:
190
 
191
                    /* Only one transmit handle can be open on the
192
                     * management service thread at a time.
193
                     */
194
                    if (tx_handle_in_use == MCAPI_FALSE)
195
                    {
196
                        port = mcapi_get32(buffer,
197
                                           MCAPID_MGMT_FOREIGN_PORT_OFFSET);
198
                        mcapi_get_endpoint_i(this_node, port, &endpoint,
199
                                             &request, &status);
200
                        complete = mcapi_wait(&request, &size, &status, 0);
201
 
202
                        if (complete && (status == MCAPI_SUCCESS))
203
                        {
204
                            mcapi_open_pktchan_send_i(&tx_handle,
205
                                                      endpoint,
206
                                                      &pkt_tx_request,
207
                                                      &mcapi_struct->status);
208
 
209
                            if ( (mcapi_struct->status == MCAPI_SUCCESS) ||
210
                                 (mcapi_struct->status == MGC_MCAPI_ERR_NOT_CONNECTED) )
211
                            {
212
                                tx_handle_in_use = MCAPI_TRUE;
213
                            }
214
                        }
215
                        else
216
                        {
217
                            printf("%s: tried to open a non-existent "
218
                                   "endpoint (for pktchan send)!\n", __func__);
219
                        }
220
                    }
221
 
222
                    else
223
                    {
224
                        mcapi_struct->status = -1;
225
                    }
226
 
227
                    break;
228
 
229
                /* Open a local endpoint as a receiver. */
230
                case MCAPID_MGMT_OPEN_RX_SIDE_PKT:
231
 
232
                    /* Only one receive handle can be open on the management
233
                     * service thread at a time.
234
                     */
235
                    if (rx_handle_in_use == MCAPI_FALSE)
236
                    {
237
                        port = mcapi_get32(buffer,
238
                                           MCAPID_MGMT_FOREIGN_PORT_OFFSET);
239
                        mcapi_get_endpoint_i(this_node, port, &endpoint,
240
                                             &request, &status);
241
                        complete = mcapi_wait(&request, &size, &status, 0);
242
 
243
                        if (status == MCAPI_SUCCESS)
244
                        {
245
                            mcapi_open_pktchan_recv_i(&rx_handle,
246
                                                      endpoint,
247
                                                      &pkt_rx_request,
248
                                                      &mcapi_struct->status);
249
 
250
                            if ( (mcapi_struct->status == MCAPI_SUCCESS) ||
251
                                 (mcapi_struct->status == MGC_MCAPI_ERR_NOT_CONNECTED) )
252
                            {
253
                                rx_handle_in_use = MCAPI_TRUE;
254
                            }
255
                        }
256
                        else
257
                        {
258
                            printf("%s: tried to open a non-existent "
259
                                   "endpoint (for pktchan recv)!\n", __func__);
260
                        }
261
                    }
262
 
263
                    else
264
                    {
265
                        mcapi_struct->status = -1;
266
                    }
267
 
268
                    break;
269
 
270
                /* Close the send side. */
271
                case MCAPID_MGMT_CLOSE_TX_SIDE_PKT:
272
 
273
                    mcapi_packetchan_send_close_i(tx_handle, &mcapi_struct->request,
274
                                                  &mcapi_struct->status);
275
 
276
                    if (mcapi_struct->status == MCAPI_SUCCESS)
277
                    {
278
                        tx_handle_in_use = MCAPI_FALSE;
279
                    }
280
 
281
                    break;
282
 
283
                /* Close the receive side. */
284
                case MCAPID_MGMT_CLOSE_RX_SIDE_PKT:
285
 
286
                    mcapi_packetchan_recv_close_i(rx_handle, &mcapi_struct->request,
287
                                                  &mcapi_struct->status);
288
 
289
                    if (mcapi_struct->status == MCAPI_SUCCESS)
290
                    {
291
                        rx_handle_in_use = MCAPI_FALSE;
292
                    }
293
 
294
                    break;
295
 
296
                case MCAPID_TX_PKT:
297
 
298
                    mcapi_pktchan_send(tx_handle, buffer, MCAPID_MGMT_PKT_LEN,
299
                                       &mcapi_struct->status);
300
 
301
                    break;
302
 
303
                /* Open a local endpoint as a sender. */
304
                case MCAPID_MGMT_OPEN_TX_SIDE_SCL:
305
 
306
                    /* Only one transmit handle can be open on the management
307
                     * service thread at a time.
308
                     */
309
                    if (tx_handle_scl_in_use == MCAPI_FALSE)
310
                    {
311
                        port = mcapi_get32(buffer,
312
                                           MCAPID_MGMT_FOREIGN_PORT_OFFSET);
313
                        mcapi_get_endpoint_i(this_node, port, &endpoint,
314
                                             &request, &status);
315
                        complete = mcapi_wait(&request, &size, &status, 0);
316
 
317
                        if (complete && (status == MCAPI_SUCCESS))
318
                        {
319
                            mcapi_open_sclchan_send_i(&tx_handle_scl,
320
                                                      endpoint,
321
                                                      &scl_tx_request,
322
                                                      &mcapi_struct->status);
323
 
324
                            if ( (mcapi_struct->status == MCAPI_SUCCESS) ||
325
                                 (mcapi_struct->status == MGC_MCAPI_ERR_NOT_CONNECTED) )
326
                            {
327
                                tx_handle_scl_in_use = MCAPI_TRUE;
328
                            }
329
                        }
330
                        else
331
                        {
332
                            printf("%s: tried to open a non-existent "
333
                                   "endpoint (for scalars)!\n", __func__);
334
                        }
335
                    }
336
 
337
                    else
338
                    {
339
                        mcapi_struct->status = -1;
340
                    }
341
 
342
                    break;
343
 
344
                /* Open a local endpoint as a receiver. */
345
                case MCAPID_MGMT_OPEN_RX_SIDE_SCL:
346
 
347
                    /* Only one receive handle can be open on the management
348
                     * service thread at a time.
349
                     */
350
                    if (rx_handle_scl_in_use == MCAPI_FALSE)
351
                    {
352
                        port = mcapi_get32(buffer,
353
                                           MCAPID_MGMT_FOREIGN_PORT_OFFSET);
354
                        mcapi_get_endpoint_i(this_node, port, &endpoint,
355
                                             &request, &status);
356
                        complete = mcapi_wait(&request, &size, &status, 0);
357
 
358
                        if (complete && (status == MCAPI_SUCCESS))
359
                        {
360
                            mcapi_open_sclchan_recv_i(&rx_handle_scl,
361
                                                      endpoint,
362
                                                      &scl_rx_request,
363
                                                      &mcapi_struct->status);
364
 
365
                            if ( (mcapi_struct->status == MCAPI_SUCCESS) ||
366
                                 (mcapi_struct->status == MGC_MCAPI_ERR_NOT_CONNECTED) )
367
                            {
368
                                rx_handle_scl_in_use = MCAPI_TRUE;
369
                            }
370
                        }
371
                        else
372
                        {
373
                            printf("%s: tried to open a non-existent "
374
                                   "endpoint (for scalars)!\n", __func__);
375
                        }
376
                    }
377
 
378
                    else
379
                    {
380
                        mcapi_struct->status = -1;
381
                    }
382
 
383
                    break;
384
 
385
                /* Close the send side. */
386
                case MCAPID_MGMT_CLOSE_TX_SIDE_SCL:
387
 
388
                    mcapi_sclchan_send_close_i(tx_handle_scl, &mcapi_struct->request,
389
                                               &mcapi_struct->status);
390
 
391
                    if (mcapi_struct->status == MCAPI_SUCCESS)
392
                    {
393
                        tx_handle_scl_in_use = MCAPI_FALSE;
394
                    }
395
 
396
                    break;
397
 
398
                /* Close the receive side. */
399
                case MCAPID_MGMT_CLOSE_RX_SIDE_SCL:
400
 
401
                    mcapi_sclchan_recv_close_i(rx_handle_scl, &mcapi_struct->request,
402
                                               &mcapi_struct->status);
403
 
404
                    if (mcapi_struct->status == MCAPI_SUCCESS)
405
                    {
406
                        rx_handle_scl_in_use = MCAPI_FALSE;
407
                    }
408
 
409
                    break;
410
 
411
                /* Send a 64-bit scalar. */
412
                case MCAPID_TX_64_BIT_SCL:
413
 
414
                    mcapi_sclchan_send_uint64(tx_handle_scl, MCAPID_64BIT_SCALAR,
415
                                              &mcapi_struct->status);
416
 
417
                    break;
418
 
419
                /* Send a 32-bit scalar. */
420
                case MCAPID_TX_32_BIT_SCL:
421
 
422
                    mcapi_sclchan_send_uint32(tx_handle_scl, MCAPID_32BIT_SCALAR,
423
                                              &mcapi_struct->status);
424
 
425
                    break;
426
 
427
                /* Send a 16-bit scalar. */
428
                case MCAPID_TX_16_BIT_SCL:
429
 
430
                    mcapi_sclchan_send_uint16(tx_handle_scl, MCAPID_16BIT_SCALAR,
431
                                              &mcapi_struct->status);
432
 
433
                    break;
434
 
435
                /* Send a 8-bit scalar. */
436
                case MCAPID_TX_8_BIT_SCL:
437
 
438
                    mcapi_sclchan_send_uint8(tx_handle_scl, MCAPID_8BIT_SCALAR,
439
                                             &mcapi_struct->status);
440
 
441
                    break;
442
 
443
                case MCAPID_NO_OP:
444
 
445
                    /* NO OP just ACKs back a successful response. */
446
                    mcapi_struct->status = MCAPI_SUCCESS;
447
 
448
                    break;
449
 
450
                default:
451
 
452
                    mcapi_struct->status = -1;
453
                    break;
454
            }
455
 
456
            /* Put the status in the packet. */
457
            mcapi_put32(buffer, MCAPID_MGMT_STATUS_OFFSET, mcapi_struct->status);
458
 
459
            prio = mcapi_get32(buffer, MCAPID_MGMT_PRIO_OFFSET);
460
 
461
            /* Send the response using the specified priority. */
462
            mcapi_msg_send(mcapi_struct->local_endp,
463
                           mcapi_get32(buffer, MCAPID_MGMT_LOCAL_ENDP_OFFSET),
464
                           buffer, rx_len, prio, &mcapi_struct->status);
465
        }
466
 
467
        /* The service has been shut down. */
468
        else
469
        {
470
            /* Terminate this task. */
471
            MCAPI_Cleanup_Task();
472
 
473
            break;
474
        }
475
    }
476
 
477
} /* MCAPID_Mgmt_Service */
478
 
479
/************************************************************************
480
*
481
*   FUNCTION
482
*
483
*       MCAPID_TX_Mgmt_Message
484
*
485
*   DESCRIPTION
486
*
487
*       Transmit a service message to the management endpoint.
488
*
489
*************************************************************************/
490
mcapi_status_t MCAPID_TX_Mgmt_Message(MCAPID_STRUCT *mcapi_struct,
491
                                      mcapi_uint32_t type,
492
                                      mcapi_port_t foreign_port,
493
                                      mcapi_endpoint_t local_endp,
494
                                      mcapi_uint32_t pause,
495
                                      mcapi_uint32_t priority)
496
{
497
    unsigned char   buffer[MCAPID_MGMT_PKT_LEN];
498
    mcapi_status_t  status;
499
 
500
    /* Set the type of service to complete. */
501
    mcapi_put32(buffer, MCAPID_MGMT_TYPE_OFFSET, type);
502
 
503
    /* Set the port of the foreign endpoint to use. */
504
    mcapi_put32(buffer, MCAPID_MGMT_FOREIGN_PORT_OFFSET, foreign_port);
505
 
506
    /* Zero out status. */
507
    mcapi_put32(buffer, MCAPID_MGMT_STATUS_OFFSET, 0);
508
 
509
    /* Set the millisecond pause before performing the service. */
510
    mcapi_put32(buffer, MCAPID_MGMT_PAUSE_OFFSET, pause);
511
 
512
    /* Set the endpoint to respond to on this node. */
513
    mcapi_put32(buffer, MCAPID_MGMT_LOCAL_ENDP_OFFSET, local_endp);
514
 
515
    /* Set the priority the receiver should use when responding. */
516
    mcapi_put32(buffer, MCAPID_MGMT_PRIO_OFFSET, priority);
517
 
518
    /* If this is a cancel or wait request, store the address of the request
519
     * being canceled in the status field of the packet.
520
     */
521
    if ( (type == MCAPID_CANCEL_REQUEST) || (type == MCAPID_WAIT_REQUEST) )
522
    {
523
        mcapi_put32(buffer, MCAPID_MGMT_STATUS_OFFSET,
524
                    (mcapi_uint32_t)&mcapi_struct->request);
525
    }
526
 
527
    /* Send the request. */
528
    mcapi_msg_send(mcapi_struct->local_endp, mcapi_struct->foreign_endp,
529
                   buffer, MCAPID_MGMT_PKT_LEN, priority, &status);
530
 
531
    return (status);
532
 
533
} /* MCAPID_TX_Mgmt_Message */
534
 
535
/************************************************************************
536
*
537
*   FUNCTION
538
*
539
*       MCAPID_RX_Mgmt_Response
540
*
541
*   DESCRIPTION
542
*
543
*       Receives the response to a service message from the management
544
*       endpoint.
545
*
546
*************************************************************************/
547
mcapi_status_t MCAPID_RX_Mgmt_Response(MCAPID_STRUCT *mcapi_struct)
548
{
549
    unsigned char   buffer[MCAPID_MGMT_PKT_LEN];
550
    mcapi_status_t  status, cncl_stat;
551
    mcapi_request_t request;
552
    size_t          rx_len;
553
 
554
    /* Receive the message. */
555
    mcapi_msg_recv_i(mcapi_struct->local_endp, buffer, MCAPID_MGMT_PKT_LEN,
556
                     &request, &status);
557
 
558
    if (status == MCAPI_SUCCESS)
559
    {
560
        mcapi_wait(&request, &rx_len, &status, 5000);
561
 
562
        if (status == MCAPI_SUCCESS)
563
        {
564
            /* Extract the status of the operation. */
565
            status = mcapi_get32(buffer, MCAPID_MGMT_STATUS_OFFSET);
566
        }
567
 
568
        else
569
        {
570
            mcapi_cancel(&request, &cncl_stat);
571
        }
572
    }
573
 
574
    return (status);
575
 
576
} /* MCAPID_RX_Mgmt_Response */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.