Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/net/generic/packet_remote.c

    r49bd793b rffa2c8ef  
    5151 * Create the local packet mapping as well.
    5252 *
    53  * @param[in]  sess      Packet server module session.
    54  * @param[out] packet    Packet reference pointer to store the received
     53 * @param[in]  phone     The packet server module phone.
     54 * @param[out] packet    The packet reference pointer to store the received
    5555 *                       packet reference.
    56  * @param[in]  packet_id Packet identifier.
    57  * @param[in]  size      Packet total size in bytes.
     56 * @param[in]  packet_id The packet identifier.
     57 * @param[in]  size      The packet total size in bytes.
    5858 *
    5959 * @return EOK on success.
    6060 * @return Other error codes as defined for the pm_add() function.
    61  * @return Other error codes as defined for the async_share_in_start()
    62  *         function.
    63  *
    64  */
    65 static int packet_return(async_sess_t *sess, packet_t **packet,
    66     packet_id_t packet_id, size_t size)
    67 {
     61 * @return Other error codes as defined for the async_share_in_start() function.
     62 *
     63 */
     64static int
     65packet_return(int phone, packet_t **packet, packet_id_t packet_id, size_t size)
     66{
     67        ipc_call_t answer;
     68        aid_t message;
     69        int rc;
     70       
     71        message = async_send_1(phone, NET_PACKET_GET, packet_id, &answer);
     72
    6873        *packet = (packet_t *) as_get_mappable_page(size);
    69        
    70         async_exch_t *exch = async_exchange_begin(sess);
    71         ipc_call_t answer;
    72         aid_t message = async_send_1(exch, NET_PACKET_GET, packet_id, &answer);
    73         int rc = async_share_in_start_0_0(exch, *packet, size);
    74         async_exchange_end(exch);
    75        
    76         sysarg_t result;
    77         async_wait_for(message, &result);
    78        
     74        rc = async_share_in_start_0_0(phone, *packet, size);
    7975        if (rc != EOK) {
    8076                munmap(*packet, size);
     77                async_wait_for(message, NULL);
    8178                return rc;
    8279        }
    83        
    8480        rc = pm_add(*packet);
    8581        if (rc != EOK) {
    8682                munmap(*packet, size);
     83                async_wait_for(message, NULL);
    8784                return rc;
    8885        }
    8986       
     87        sysarg_t result;
     88        async_wait_for(message, &result);
     89       
    9090        return result;
    9191}
    9292
    93 /** Translate the packet identifier to the packet reference.
    94  *
    95  * Try to find mapping first. The packet server is asked to share
    96  * the packet if the mapping is not present.
    97  *
    98  * @param[in]  sess      Packet server module session.
    99  * @param[out] packet    Packet reference.
    100  * @param[in]  packet_id Packet identifier.
    101  *
    102  * @return EOK on success.
    103  * @return EINVAL if the packet parameter is NULL.
    104  * @return Other error codes as defined for the NET_PACKET_GET_SIZE
    105  *         message.
    106  * @return Other error codes as defined for the packet_return()
    107  *         function.
    108  *
    109  */
    110 int packet_translate_remote(async_sess_t *sess, packet_t **packet,
    111     packet_id_t packet_id)
    112 {
     93/** Translates the packet identifier to the packet reference.
     94 *
     95 * Tries to find mapping first.
     96 * Contacts the packet server to share the packet if the mapping is not present.
     97 *
     98 * @param[in] phone     The packet server module phone.
     99 * @param[out] packet   The packet reference.
     100 * @param[in] packet_id The packet identifier.
     101 * @return              EOK on success.
     102 * @return              EINVAL if the packet parameter is NULL.
     103 * @return              Other error codes as defined for the NET_PACKET_GET_SIZE
     104 *                      message.
     105 * @return              Other error codes as defined for the packet_return()
     106 *                      function.
     107 */
     108int packet_translate_remote(int phone, packet_t **packet, packet_id_t packet_id)
     109{
     110        int rc;
     111       
    113112        if (!packet)
    114113                return EINVAL;
    115114       
    116115        *packet = pm_find(packet_id);
    117         if (*packet == NULL) {
    118                 async_exch_t *exch = async_exchange_begin(sess);
     116        if (!*packet) {
    119117                sysarg_t size;
    120                 int rc = async_req_1_1(exch, NET_PACKET_GET_SIZE, packet_id,
     118               
     119                rc = async_req_1_1(phone, NET_PACKET_GET_SIZE, packet_id,
    121120                    &size);
    122                 async_exchange_end(exch);
     121                if (rc != EOK)
     122                        return rc;
     123                rc = packet_return(phone, packet, packet_id, size);
     124                if (rc != EOK)
     125                        return rc;
     126        }
     127        if ((*packet)->next) {
     128                packet_t *next;
    123129               
    124                 if (rc != EOK)
    125                         return rc;
    126                
    127                 rc = packet_return(sess, packet, packet_id, size);
    128                 if (rc != EOK)
    129                         return rc;
    130         }
    131        
    132         if ((*packet != NULL) && ((*packet)->next)) {
    133                 packet_t *next;
    134                 return packet_translate_remote(sess, &next, (*packet)->next);
     130                return packet_translate_remote(phone, &next, (*packet)->next);
    135131        }
    136132       
     
    138134}
    139135
    140 /** Obtain the packet of given dimensions.
    141  *
    142  * Contact the packet server to return the appropriate packet.
    143  *
    144  * @param[in] sess        Packet server module session.
    145  * @param[in] addr_len    Source and destination addresses maximal length
    146  *                        in bytes.
    147  * @param[in] max_prefix  Maximal prefix length in bytes.
    148  * @param[in] max_content Maximal content length in bytes.
    149  * @param[in] max_suffix  Maximal suffix length in bytes.
    150  *
    151  * @return The packet reference.
    152  * @return NULL on error.
    153  *
    154  */
    155 packet_t *packet_get_4_remote(async_sess_t *sess, size_t max_content,
    156     size_t addr_len, size_t max_prefix, size_t max_suffix)
    157 {
    158         async_exch_t *exch = async_exchange_begin(sess);
     136/** Obtains the packet of the given dimensions.
     137 *
     138 * Contacts the packet server to return the appropriate packet.
     139 *
     140 * @param[in] phone     The packet server module phone.
     141 * @param[in] addr_len  The source and destination addresses maximal length in
     142 *                      bytes.
     143 * @param[in] max_prefix The maximal prefix length in bytes.
     144 * @param[in] max_content The maximal content length in bytes.
     145 * @param[in] max_suffix The maximal suffix length in bytes.
     146 * @return              The packet reference.
     147 * @return              NULL on error.
     148 */
     149packet_t *packet_get_4_remote(int phone, size_t max_content, size_t addr_len,
     150    size_t max_prefix, size_t max_suffix)
     151{
    159152        sysarg_t packet_id;
    160153        sysarg_t size;
    161         int rc = async_req_4_2(exch, NET_PACKET_CREATE_4, max_content, addr_len,
     154        int rc;
     155       
     156        rc = async_req_4_2(phone, NET_PACKET_CREATE_4, max_content, addr_len,
    162157            max_prefix, max_suffix, &packet_id, &size);
    163         async_exchange_end(exch);
    164        
    165158        if (rc != EOK)
    166159                return NULL;
    167160       
     161       
    168162        packet_t *packet = pm_find(packet_id);
    169163        if (!packet) {
    170                 rc = packet_return(sess, &packet, packet_id, size);
     164                rc = packet_return(phone, &packet, packet_id, size);
    171165                if (rc != EOK)
    172166                        return NULL;
     
    176170}
    177171
    178 /** Obtain the packet of given content size.
    179  *
    180  * Contact the packet server to return the appropriate packet.
    181  *
    182  * @param[in] sess    Packet server module session.
    183  * @param[in] content Maximal content length in bytes.
    184  *
    185  * @return The packet reference.
    186  * @return NULL on error.
    187  *
    188  */
    189 packet_t *packet_get_1_remote(async_sess_t *sess, size_t content)
    190 {
    191         async_exch_t *exch = async_exchange_begin(sess);
     172/** Obtains the packet of the given content size.
     173 *
     174 * Contacts the packet server to return the appropriate packet.
     175 *
     176 * @param[in] phone     The packet server module phone.
     177 * @param[in] content   The maximal content length in bytes.
     178 * @return              The packet reference.
     179 * @return              NULL on error.
     180 */
     181packet_t *packet_get_1_remote(int phone, size_t content)
     182{
    192183        sysarg_t packet_id;
    193184        sysarg_t size;
    194         int rc = async_req_1_2(exch, NET_PACKET_CREATE_1, content, &packet_id,
     185        int rc;
     186       
     187        rc = async_req_1_2(phone, NET_PACKET_CREATE_1, content, &packet_id,
    195188            &size);
    196         async_exchange_end(exch);
    197        
    198189        if (rc != EOK)
    199190                return NULL;
     
    201192        packet_t *packet = pm_find(packet_id);
    202193        if (!packet) {
    203                 rc = packet_return(sess, &packet, packet_id, size);
     194                rc = packet_return(phone, &packet, packet_id, size);
    204195                if (rc != EOK)
    205196                        return NULL;
     
    209200}
    210201
    211 /** Release the packet queue.
     202/** Releases the packet queue.
    212203 *
    213204 * All packets in the queue are marked as free for use.
     
    216207 * received or obtained again.
    217208 *
    218  * @param[in] sess      Packet server module session.
    219  * @param[in] packet_id Packet identifier.
    220  *
    221  */
    222 void pq_release_remote(async_sess_t *sess, packet_id_t packet_id)
    223 {
    224         async_exch_t *exch = async_exchange_begin(sess);
    225         async_msg_1(exch, NET_PACKET_RELEASE, packet_id);
    226         async_exchange_end(exch);
     209 * @param[in] phone     The packet server module phone.
     210 * @param[in] packet_id The packet identifier.
     211 */
     212void pq_release_remote(int phone, packet_id_t packet_id)
     213{
     214        async_msg_1(phone, NET_PACKET_RELEASE, packet_id);
    227215}
    228216
Note: See TracChangeset for help on using the changeset viewer.