00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <l4/sys/types.h>
00018 #include <l4/sys/syscalls.h>
00019 #include <l4/env/errno.h>
00020 #include <l4/util/atomic.h>
00021 #include <l4/util/macros.h>
00022 #include <l4/thread/thread.h>
00023
00024
00025 #include <l4/dsi/dsi.h>
00026 #include "__packet.h"
00027 #include "__sync.h"
00028 #include "__socket.h"
00029 #include "__debug.h"
00030 #include "__config.h"
00031
00032
00033 #define DO_PACKET_NUMBERING 0
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 static inline int
00051 __is_valid_packet(dsi_socket_t * socket, dsi_packet_t * packet)
00052 {
00053 return ((packet >= socket->packets) &&
00054 ((l4_addr_t)packet <
00055 ((l4_addr_t)socket->packets +
00056 socket->header->num_packets * sizeof(dsi_packet_t))));
00057 }
00058
00059
00060 #define set_socket_flag(s, f) \
00061 __asm__ __volatile__ ( \
00062 "orl %1,%0 \n\t" \
00063 : \
00064 :"m" ((s)->flags), "g" (f) \
00065 :"memory" \
00066 )
00067
00068 #define reset_socket_flag(s, f) \
00069 __asm__ __volatile__ ( \
00070 "andl %1,%0 \n\t" \
00071 : \
00072 :"m" ((s)->flags), "g" (~f) \
00073 :"memory" \
00074 )
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 static inline int
00091 __get_packet_index(dsi_socket_t * socket, dsi_packet_t * packet)
00092 {
00093 return (int)(((l4_addr_t)packet - (l4_addr_t)socket->packets) /
00094 sizeof(dsi_packet_t));
00095 }
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 static inline int
00110 __send_release_notification(dsi_socket_t * socket, dsi_packet_t * packet)
00111 {
00112 int ret;
00113 l4_msgdope_t result;
00114 l4_uint32_t p;
00115 #if RELEASE_DO_CALL
00116 l4_umword_t dummy;
00117 #endif
00118
00119 LOGdL(DEBUG_RECEIVE_PACKET,"packet %d",packet->no);
00120 LOGdL(DEBUG_RECEIVE_PACKET,"remote sync "l4util_idfmt,
00121 l4util_idstr(socket->remote_socket.sync_th));
00122
00123
00124 p = __get_packet_index(socket,packet);
00125
00126
00127 do
00128 {
00129
00130 #if RELEASE_DO_CALL
00131 ret = l4_ipc_call(socket->remote_socket.sync_th,L4_IPC_SHORT_MSG,
00132 DSI_SYNC_RELEASE,p,L4_IPC_SHORT_MSG,&dummy,
00133 &dummy,L4_IPC_NEVER,&result);
00134 #else
00135 ret = l4_ipc_send(socket->remote_socket.sync_th,L4_IPC_SHORT_MSG,
00136 DSI_SYNC_RELEASE,p,L4_IPC_NEVER,&result);
00137 #endif
00138
00139 if (ret == L4_IPC_SETIMEOUT)
00140 {
00141 #if 0
00142 LOG_Error("DSI: send timeout calling sender, ignored.");
00143 #endif
00144 l4thread_sleep(1);
00145 }
00146 }
00147 while (ret == L4_IPC_SETIMEOUT);
00148
00149 if (ret)
00150 {
00151 LOG_Error("DSI: error sending release notification (0x%02x)!", ret);
00152 return -L4_EIPC;
00153 }
00154
00155
00156 return 0;
00157 }
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 static inline int
00175 __get_sg_elem(dsi_socket_t * socket, int * sg_elem)
00176 {
00177 int i = socket->next_sg_elem;
00178
00179 *sg_elem = -1;
00180
00181
00182 do
00183 {
00184 if (l4util_cmpxchg32(&socket->sg_lists[i].flags,
00185 DSI_SG_ELEM_UNUSED,DSI_SG_ELEM_USED))
00186 {
00187
00188 socket->next_sg_elem = (i + 1) % socket->header->num_sg_elems;
00189 break;
00190 }
00191
00192 i = (i + 1) % socket->header->num_sg_elems;
00193 }
00194 while (i != socket->next_sg_elem);
00195
00196 if (i == socket->next_sg_elem)
00197 {
00198
00199 Panic("DSI: no scatter gather list element available!");
00200 return -DSI_ENOSGELEM;
00201 }
00202 else
00203 {
00204 *sg_elem = i;
00205 return 0;
00206 }
00207 }
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230 static inline int
00231 __get_send_packet(dsi_socket_t * socket, int * packet)
00232 {
00233 dsi_sync_msg_t msg;
00234 dsi_packet_t * p = &socket->packets[socket->next_packet];
00235 int err;
00236
00237 LOGdL(DEBUG_SEND_PACKET,"trying to get packet %d",socket->next_packet);
00238
00239
00240 if(socket->flags & DSI_SOCKET_BLOCK_ABORT) goto e_eeos;
00241 if (!dsi_trylock(&p->tx_sem)){
00242
00243 if (SOCKET_BLOCK(socket)) {
00244
00245
00246
00247
00248
00249
00250
00251 if(l4_thread_setjmp(socket->packet_get_abort_env)) goto e_eeos;
00252
00253
00254 set_socket_flag(socket, DSI_SOCKET_BLOCKING_IN_GET);
00255
00256
00257
00258 if(socket->flags & DSI_SOCKET_BLOCK_ABORT) goto e_eeos;
00259
00260 if (SOCKET_SYNC_CALLBACK(socket)){
00261
00262 socket->sync_callback(socket,socket->packet_count,
00263 DSI_SYNC_NO_SEND_PACKET);
00264 }
00265
00266
00267 msg.sync_th = socket->remote_socket.sync_th;
00268 msg.packet = socket->next_packet;
00269 msg.rcv = L4_IPC_SHORT_MSG;
00270 err = dsi_down(&p->tx_sem,msg);
00271
00272
00273 reset_socket_flag(socket, DSI_SOCKET_BLOCKING_IN_GET);
00274
00275 if(err!=-1 && err){
00276 return ((err & L4_IPC_ERROR_MASK) == L4_IPC_ENOT_EXISTENT)?
00277 -DSI_ECONNECT:-DSI_ENOPACKET;
00278 }
00279 }
00280 else {
00281
00282
00283 return -DSI_ENOPACKET;
00284 }
00285 }
00286
00287
00288 *packet = socket->next_packet;
00289 socket->next_packet =
00290 (socket->next_packet + 1) % socket->header->num_packets;
00291
00292
00293 #if DO_PACKET_NUMBERING
00294 p->no = socket->packet_count++;
00295 #endif
00296 p->flags &= (~DSI_PACKETS_USER_MASK);
00297 p->sg_len = 0;
00298 p->sg_list = DSI_SG_ELEM_LAST;
00299
00300 return 0;
00301
00302 e_eeos:
00303 reset_socket_flag(socket,
00304 DSI_SOCKET_BLOCKING_IN_GET |
00305 DSI_SOCKET_BLOCK_ABORT);
00306 return -DSI_EEOS;
00307 }
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320 static inline void
00321 __map_receive_data(dsi_socket_t * socket, int packet_idx)
00322 {
00323 int ret;
00324 l4_umword_t dummy;
00325 l4_msgdope_t result;
00326
00327 LOGdL(DEBUG_MAP_PACKET,"map packet %d",packet_idx);
00328
00329
00330 ret = l4_ipc_call(socket->remote_socket.sync_th,
00331 L4_IPC_SHORT_MSG,DSI_SYNC_MAP,packet_idx,
00332 L4_IPC_MAPMSG((l4_addr_t)socket->data_area,
00333 socket->data_map_size),
00334 &dummy,&dummy,L4_IPC_NEVER,&result);
00335 if (ret || !l4_ipc_fpage_received(result))
00336 Panic("DSI: map message IPC error (0x%08x)!",ret);
00337 }
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349 static inline void
00350 __copy_receive_data(dsi_socket_t * socket, int packet_idx)
00351 {
00352 int ret;
00353 struct {
00354 l4_umword_t rcv_fpage;
00355 l4_msgdope_t size_dope;
00356 l4_msgdope_t send_dope;
00357 l4_umword_t dw0;
00358 l4_umword_t dw1;
00359 l4_strdope_t buf;
00360 } msg_buf;
00361 l4_umword_t dummy;
00362 l4_msgdope_t result;
00363
00364 LOGdL(DEBUG_COPY_PACKET,"copy packet %d",packet_idx);
00365
00366
00367 msg_buf.rcv_fpage = 0;
00368 msg_buf.size_dope = L4_IPC_DOPE(2,1);
00369 msg_buf.send_dope = L4_IPC_DOPE(2,0);
00370 msg_buf.buf.rcv_str = (l4_addr_t)socket->data_area;
00371 msg_buf.buf.rcv_size = socket->data_size;
00372
00373 ret = l4_ipc_call(socket->remote_socket.sync_th,
00374 L4_IPC_SHORT_MSG,DSI_SYNC_COPY,packet_idx,
00375 &msg_buf,&dummy,&dummy,L4_IPC_NEVER,&result);
00376 if (ret || (result.md.strings != 1))
00377 Panic("DSI: copy message IPC error (0x%08x)!",ret);
00378 }
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409 static inline int
00410 __get_receive_packet(dsi_socket_t * socket, int * packet)
00411 {
00412 dsi_sync_msg_t msg;
00413 int result = -1;
00414 l4_msgdope_t dope;
00415 struct {
00416 l4_umword_t rcv_fpage;
00417 l4_msgdope_t size_dope;
00418 l4_msgdope_t send_dope;
00419 l4_umword_t dw0;
00420 l4_umword_t dw1;
00421 l4_strdope_t buf;
00422 } msg_buf;
00423
00424 LOGdL(DEBUG_RECEIVE_PACKET,"trying to get packet %d",socket->next_packet);
00425
00426
00427 if(socket->flags & DSI_SOCKET_BLOCK_ABORT) goto e_eeos;
00428 if(!dsi_trylock(&socket->packets[socket->next_packet].rx_sem)){
00429 if (SOCKET_BLOCK(socket)) {
00430
00431
00432
00433 msg.sync_th = socket->remote_socket.sync_th;
00434 msg.packet = socket->next_packet;
00435 if (socket->flags & DSI_SOCKET_MAP)
00436 {
00437
00438 msg.rcv = L4_IPC_MAPMSG((l4_addr_t)socket->data_area,
00439 socket->data_map_size);
00440
00441 LOGdL(DEBUG_MAP_PACKET,"rcv fpage 0x%08x",(unsigned)msg.rcv);
00442 }
00443 else if (socket->flags & DSI_SOCKET_COPY)
00444 {
00445
00446 msg_buf.rcv_fpage = 0;
00447 msg_buf.size_dope = L4_IPC_DOPE(2,1);
00448 msg_buf.send_dope = L4_IPC_DOPE(2,0);
00449 msg_buf.buf.rcv_str = (l4_addr_t)socket->data_area;
00450 msg_buf.buf.rcv_size = socket->data_size;
00451
00452 LOGdL(DEBUG_COPY_PACKET,"rcv str at 0x%08lx",msg_buf.buf.rcv_str);
00453 LOGdL(DEBUG_COPY_PACKET,"size %u",socket->data_size);
00454
00455 msg.rcv = &msg_buf;
00456 }
00457 else
00458 msg.rcv = L4_IPC_SHORT_MSG;
00459
00460 if(l4_thread_setjmp(socket->packet_get_abort_env)) goto e_eeos;
00461
00462
00463 set_socket_flag(socket, DSI_SOCKET_BLOCKING_IN_GET);
00464
00465
00466
00467 if(socket->flags & DSI_SOCKET_BLOCK_ABORT) goto e_eeos;
00468
00469 if (SOCKET_SYNC_CALLBACK(socket)) {
00470 socket->sync_callback(socket,
00471 socket->packets[socket->next_packet].no,
00472 DSI_SYNC_NO_RECEIVE_PACKET);
00473 }
00474
00475
00476 result = dsi_down(&socket->packets[socket->next_packet].rx_sem,msg);
00477
00478
00479 reset_socket_flag(socket, DSI_SOCKET_BLOCKING_IN_GET);
00480
00481 if(result!=-1 && result)
00482 return ((result & L4_IPC_ERROR_MASK)==L4_IPC_ENOT_EXISTENT)?
00483 -DSI_ECONNECT:-DSI_ENOPACKET;
00484
00485 } else {
00486
00487
00488 return -DSI_ENOPACKET;
00489 }
00490 }
00491
00492 LOGdL(DEBUG_RECEIVE_PACKET,"got packet %d",socket->next_packet);
00493
00494
00495 *packet = socket->next_packet;
00496
00497 socket->next_packet =
00498 (socket->next_packet + 1) % socket->header->num_packets;
00499
00500
00501 if (socket->flags & DSI_SOCKET_MAP)
00502 {
00503 if (result == -1)
00504
00505 __map_receive_data(socket,*packet);
00506 else
00507 {
00508
00509 dope.msgdope = result;
00510 if (!dope.md.fpage_received)
00511 {
00512 LOG_Error("DSI: packet data not mapped!");
00513 __map_receive_data(socket,*packet);
00514 }
00515 }
00516 }
00517 else if (socket->flags & DSI_SOCKET_COPY)
00518 {
00519 if (result == -1)
00520
00521 __copy_receive_data(socket,*packet);
00522 else
00523 {
00524
00525 dope.msgdope = result;
00526 if (dope.md.strings != 1)
00527 {
00528 LOG_Error("DSI: packet data not copied!");
00529 __copy_receive_data(socket,*packet);
00530 }
00531 }
00532 }
00533
00534
00535 return 0;
00536
00537 e_eeos:
00538 reset_socket_flag(socket,
00539 DSI_SOCKET_BLOCKING_IN_GET |
00540 DSI_SOCKET_BLOCK_ABORT);
00541 return -DSI_EEOS;
00542 }
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562 static inline int
00563 __commit_send_packet(dsi_socket_t * socket, dsi_packet_t * packet)
00564 {
00565 dsi_sync_msg_t msg;
00566
00567 #if DO_SANITY
00568
00569 if (!__is_valid_packet(socket,packet))
00570 return -L4_EINVAL;
00571 #endif
00572
00573 if (packet->sg_len == 0)
00574 return -DSI_ENODATA;
00575
00576
00577 if (SOCKET_RELEASE_CALLBACK(socket))
00578 packet->flags |= DSI_PACKET_RELEASE_CALLBACK;
00579
00580
00581 msg.sync_th = socket->sync_th;
00582 msg.packet = __get_packet_index(socket,packet);
00583
00584 LOGdL(DEBUG_SEND_PACKET,"commiting packet %d",msg.packet);
00585 LOGdL(DEBUG_SEND_PACKET,"message to "l4util_idfmt,
00586 l4util_idstr(msg.sync_th));
00587
00588 socket->header->packets_committed++;
00589
00590
00591
00592 if(dsi_up(&packet->rx_sem,msg))
00593 return -DSI_ENOPACKET;
00594
00595
00596 return 0;
00597 }
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618 static inline int
00619 __commit_receive_packet(dsi_socket_t * socket, dsi_packet_t * packet)
00620 {
00621 dsi_sync_msg_t msg;
00622 int i,j,sg_elem,a;
00623 int ret = 0;
00624 int do_unmap = socket->flags & DSI_SOCKET_MAP;
00625 void *addr = socket->data_area;
00626
00627 #if DO_SANITY
00628
00629 if (!__is_valid_packet(socket,packet))
00630 return -L4_EINVAL;
00631 #endif
00632
00633
00634
00635 packet->sg_idx = packet->sg_list;
00636
00637
00638 if (do_unmap)
00639 {
00640 sg_elem = packet->sg_list;
00641 while (sg_elem != DSI_SG_ELEM_LAST)
00642 {
00643
00644 LOGdL(DEBUG_MAP_PACKET,"unmap packet %u",packet->no);
00645
00646 a = 12;
00647 while (socket->sg_lists[sg_elem].size > (1U << a))
00648 a++;
00649
00650
00651 l4_fpage_unmap(l4_fpage((l4_addr_t)addr +
00652 socket->sg_lists[sg_elem].addr,
00653 a,0,0),
00654 L4_FP_FLUSH_PAGE | L4_FP_ALL_SPACES);
00655
00656 sg_elem = socket->sg_lists[sg_elem].next;
00657 }
00658 }
00659
00660
00661 if (PACKET_RELEASE_CALLBACK(packet))
00662
00663 ret = __send_release_notification(socket,packet);
00664
00665
00666 msg.sync_th = socket->sync_th;
00667 msg.packet = __get_packet_index(socket,packet);
00668
00669 socket->header->packets_committed--;
00670
00671
00672 sg_elem = packet->sg_list;
00673 for (i = 0; i < packet->sg_len; i++)
00674 {
00675 if (sg_elem == DSI_SG_ELEM_LAST)
00676 {
00677 Panic("DSI: corrupted sgatter gather list");
00678 return -L4_EINVAL;
00679 }
00680
00681 j = sg_elem;
00682 sg_elem = socket->sg_lists[j].next;
00683 socket->sg_lists[j].flags = DSI_SG_ELEM_UNUSED;
00684 }
00685
00686 if (sg_elem != DSI_SG_ELEM_LAST)
00687 {
00688 Panic("DSI: corrupted sgatter gather list");
00689 return -L4_EINVAL;
00690 }
00691
00692
00693
00694 if(dsi_up(&packet->tx_sem,msg)) return -DSI_ENOPACKET;
00695
00696
00697 return ret;
00698 }
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722 int
00723 dsi_packet_get(dsi_socket_t * socket, dsi_packet_t ** packet)
00724 {
00725 int ret,i;
00726
00727 #if DO_SANITY
00728
00729 if (!dsi_is_valid_socket(socket))
00730 return -L4_EINVAL;
00731 #endif
00732
00733
00734 if (IS_SEND_SOCKET(socket))
00735 ret = __get_send_packet(socket,&i);
00736 else if (IS_RECEIVE_SOCKET(socket))
00737 ret = __get_receive_packet(socket,&i);
00738 else
00739 {
00740 Panic("DSI: invalid socket");
00741 return -L4_EINVAL;
00742 }
00743
00744 if (ret && (ret != -DSI_ENOPACKET) && ret!=-DSI_EEOS)
00745 {
00746 LOG_Error("DSI: get packet failed: %s (%d)\n", l4env_errstr(ret), ret);
00747 return ret;
00748 }
00749
00750 if (ret) return ret;
00751
00752 #if (DEBUG_SEND_PACKET || DEBUG_RECEIVE_PACKET)
00753 LOGL("got packet %d",i);
00754 #endif
00755
00756
00757 *packet = &socket->packets[i];
00758 if (IS_SEND_SOCKET(socket))
00759 (*packet)->sg_idx = DSI_SG_ELEM_LAST;
00760 else
00761 (*packet)->sg_idx = (*packet)->sg_list;
00762
00763
00764 return 0;
00765 }
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797 int
00798 dsi_packet_get_abort(dsi_socket_t * socket)
00799 {
00800 #if DO_SANITY
00801
00802 if (!dsi_is_valid_socket(socket))
00803 return -L4_EINVAL;
00804 #endif
00805
00806 set_socket_flag(socket, DSI_SOCKET_BLOCK_ABORT);
00807
00808 if(socket->flags & DSI_SOCKET_BLOCKING_IN_GET){
00809
00810
00811 l4_thread_longjmp(socket->work_th, socket->packet_get_abort_env, 1);
00812 return 0;
00813 }
00814
00815 return -DSI_ENOPACKET;
00816 }
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851 int
00852 dsi_packet_get_nr(dsi_socket_t * socket, unsigned nr, dsi_packet_t ** packet)
00853 {
00854
00855 return 0;
00856 }
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873 int
00874 dsi_packet_commit(dsi_socket_t * socket, dsi_packet_t * packet)
00875 {
00876 int ret;
00877
00878 #if DO_SANITY
00879
00880 if (!dsi_is_valid_socket(socket))
00881 return -L4_EINVAL;
00882 #endif
00883
00884
00885 if (IS_SEND_SOCKET(socket))
00886 ret = __commit_send_packet(socket,packet);
00887 else if (IS_RECEIVE_SOCKET(socket))
00888 ret = __commit_receive_packet(socket,packet);
00889 else
00890 {
00891 LOG_Error("DSI: invalid socket");
00892 return -L4_EINVAL;
00893 }
00894
00895 if (ret)
00896 {
00897 LOG_Error("DSI: commit packet failed: %s (%d)", l4env_errstr(ret), ret);
00898 return ret;
00899 }
00900
00901
00902 return 0;
00903 }
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927 int
00928 dsi_packet_add_data(dsi_socket_t * socket, dsi_packet_t * packet,
00929 void * addr, l4_size_t size,
00930 l4_uint32_t flags)
00931 {
00932 l4_addr_t offs;
00933 int ret,sg_elem;
00934
00935 #if DO_SANITY
00936
00937 if (!dsi_is_valid_socket(socket))
00938 return -L4_EINVAL;
00939
00940
00941 if (!__is_valid_packet(socket,packet))
00942 return -L4_EINVAL;
00943
00944
00945 if (!IS_SEND_SOCKET(socket))
00946 return -L4_EINVAL;
00947 #endif
00948
00949
00950 if (packet->sg_len >= socket->header->max_sg_len)
00951 {
00952
00953 LOG_Error("DSI: scatter gather list too long (%d)", packet->sg_len + 1);
00954 return -DSI_ESGLIST;
00955 }
00956
00957
00958
00959 if (!(flags & DSI_DATA_AREA_GAP) &&
00960 !(flags & DSI_DATA_AREA_EOS) &&
00961 !(flags & DSI_DATA_AREA_PHYS))
00962 {
00963
00964 offs = addr - socket->data_area;
00965 if ((offs > socket->data_size) ||
00966 ((offs + size) > socket->data_size) ||
00967 (size == 0))
00968 {
00969
00970 LOG_Error ("DSI: invalid data area (addr 0x%08lx, size %u)",
00971 (l4_addr_t)addr, size);
00972 return -L4_EINVAL;
00973 }
00974 }
00975 else if(flags & DSI_DATA_AREA_PHYS) {
00976 offs = (l4_addr_t)addr;
00977 } else
00978
00979 offs = 0;
00980
00981
00982 ret = __get_sg_elem(socket,&sg_elem);
00983 if (ret)
00984 return -DSI_ENOSGELEM;
00985
00986 socket->sg_lists[sg_elem].addr = offs;
00987 socket->sg_lists[sg_elem].size = size;
00988 socket->sg_lists[sg_elem].flags |= (flags & DSI_SG_ELEM_USER_MASK);
00989 socket->sg_lists[sg_elem].next = DSI_SG_ELEM_LAST;
00990
00991 if (packet->sg_len == 0)
00992 {
00993
00994 packet->sg_list = sg_elem;
00995 packet->sg_idx = sg_elem;
00996 packet->sg_len = 1;
00997 }
00998 else
00999 {
01000
01001 socket->sg_lists[packet->sg_idx].next = sg_elem;
01002 packet->sg_idx = sg_elem;
01003 packet->sg_len++;
01004 }
01005
01006
01007 return 0;
01008 }
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036 int
01037 dsi_packet_get_data(dsi_socket_t * socket, dsi_packet_t * packet,
01038 void **addr, l4_size_t * size)
01039 {
01040 l4_uint32_t nr;
01041
01042 #if DO_SANITY
01043
01044 if (!dsi_is_valid_socket(socket))
01045 return -L4_EINVAL;
01046
01047
01048 if (!__is_valid_packet(socket,packet))
01049 return -L4_EINVAL;
01050 #endif
01051
01052 nr = packet->sg_idx;
01053
01054
01055 if(nr < socket->num_sg_elems){
01056 l4_uint32_t flags;
01057
01058
01059
01060 *size = socket->sg_lists[nr].size;
01061 packet->sg_idx = socket->sg_lists[nr].next;
01062
01063 flags = socket->sg_lists[nr].flags & (DSI_DATA_AREA_GAP |
01064 DSI_DATA_AREA_EOS |
01065 DSI_DATA_AREA_PHYS);
01066 if(flags & DSI_DATA_AREA_PHYS)
01067 {
01068 *addr = (void*)socket->sg_lists[nr].addr;
01069 return -DSI_EPHYS;
01070 }
01071 else
01072 {
01073 *addr = socket->data_area + socket->sg_lists[nr].addr;
01074 if(!flags) return 0;
01075 if(flags & DSI_DATA_AREA_GAP) return -DSI_EGAP;
01076 return -DSI_EEOS;
01077 }
01078 }
01079
01080
01081 if (packet->sg_idx == DSI_SG_ELEM_LAST)
01082 return -DSI_ENODATA;
01083 return -L4_EINVAL;
01084 }
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102 int
01103 dsi_packet_set_no(dsi_socket_t * socket, dsi_packet_t * packet,
01104 l4_uint32_t no)
01105 {
01106 #if DO_SANITY
01107
01108 if (!dsi_is_valid_socket(socket))
01109 return -L4_EINVAL;
01110
01111
01112 if (!__is_valid_packet(socket,packet))
01113 return -L4_EINVAL;
01114
01115
01116 if (!IS_SEND_SOCKET(socket))
01117 return -L4_EINVAL;
01118 #endif
01119
01120
01121 packet->no = no;
01122
01123
01124 return 0;
01125 }
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140 int
01141 dsi_packet_get_no(dsi_socket_t * socket, dsi_packet_t * packet,
01142 l4_uint32_t * no)
01143 {
01144 #if DO_SANITY
01145
01146 if (!dsi_is_valid_socket(socket))
01147 return -L4_EINVAL;
01148
01149
01150 if (!__is_valid_packet(socket,packet))
01151 return -L4_EINVAL;
01152 #endif
01153
01154 *no = packet->no;
01155
01156
01157 return 0;
01158 }