1/**
2 * \file
3 * \brief Unidirectional bulk data transfer via shared memory
4 */
5
6/*
7 * Copyright (c) 2009, 2010, 2011, 2012, ETH Zurich.
8 * All rights reserved.
9 *
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
13 */
14
15#include <barrelfish/barrelfish.h>
16
17#include <bulk_transfer/bulk_transfer.h>
18#include <bulk_transfer/bulk_net.h>
19
20#include "bulk_net_backend.h"
21
22static char *default_cardname = "e10k";
23
24/**
25 * Creates a new bulk endpoint which uses the network backend
26 *
27 * @param ep_desc   memory location to create the endpoint in
28 * @param setup     the setup parameters for the endpoint
29 *
30 * This function is intended to be used by the creator.
31 */
32errval_t bulk_net_ep_create(struct bulk_net_endpoint_descriptor *ep_desc,
33                            struct bulk_net_ep_setup            *setup)
34{
35    assert(ep_desc);
36
37    if (setup->port == 0 || setup->queue == 0) {
38        return BULK_TRANSFER_INVALID_ARGUMENT;
39    }
40
41    ep_desc->ip.addr = htonl(setup->ip.addr);
42    ep_desc->port = setup->port;
43    ep_desc->queue = setup->queue;
44
45    if (setup->cardname) {
46        ep_desc->cardname = setup->cardname;
47    } else {
48        ep_desc->cardname = default_cardname;
49    }
50
51    if (setup->buffer_size == 0) {
52        ep_desc->buffer_size = BULK_NET_DEFAULT_BUFFER_SIZE;
53    } else {
54        ep_desc->buffer_size = setup->buffer_size;
55    }
56
57    if (setup->buffer_count == 0) {
58        ep_desc->buffer_count = BULK_NET_DEFAULT_BUFFER_COUNT;
59    } else {
60        ep_desc->buffer_count = setup->buffer_count;
61    }
62
63    if (setup->max_queues == 0) {
64        ep_desc->max_queues = BULK_NET_DEFAULT_QUEUES;
65    } else {
66        ep_desc->max_queues = setup->max_queues;
67    }
68
69
70    if(setup->no_copy) {
71        ep_desc->ep_generic.f = bulk_net_get_impl_no_copy();
72    } else {
73        ep_desc->ep_generic.f = bulk_net_get_impl();
74    }
75
76    return SYS_ERR_OK;
77}
78
79/**
80 * Destroys the given endpoint
81 *
82 * @param   ep_desc the endpoint to be destroyed
83 */
84errval_t bulk_net_ep_destroy(struct bulk_net_endpoint_descriptor *ep_desc)
85{
86    assert(ep_desc);
87
88    /*
89     * TODO: free up potential resources e.g. tcp, rx/tx queues etc
90     *       only if resources are created upon endpoint create
91     *       otherwise this is a no-op
92     */
93
94
95    return SYS_ERR_OK;
96}
97
98/**
99 * Explicitly creates a specific remote endpoint
100 *
101 * @param ep_desc   memory location to create the endpoint
102 * @param ip        the ip of the server machine
103 * @param port      the port where the otherside listens to
104 *
105 * This is used to explicitly specify an endpoint to connect to. In the end,
106 * a nameservice like lookup should return the correct endpoint descriptor.
107 */
108errval_t bulk_net_ep_create_remote(struct bulk_net_endpoint_descriptor *ep_desc,
109                                   struct bulk_net_ep_setup            *setup)
110{
111    assert(ep_desc);
112
113
114    assert(ep_desc);
115
116      if (setup->port == 0 || setup->queue == 0) {
117          return BULK_TRANSFER_INVALID_ARGUMENT;
118      }
119
120      ep_desc->ip.addr = htonl(setup->ip.addr);
121      ep_desc->port = setup->port;
122      ep_desc->queue = setup->queue;
123
124      if (setup->cardname) {
125          ep_desc->cardname = setup->cardname;
126      } else {
127          ep_desc->cardname = default_cardname;
128      }
129
130      if (setup->buffer_size == 0) {
131          ep_desc->buffer_size = BULK_NET_DEFAULT_BUFFER_SIZE;
132      } else {
133          ep_desc->buffer_size = setup->buffer_size;
134      }
135
136      if (setup->buffer_count == 0) {
137          ep_desc->buffer_count = BULK_NET_DEFAULT_BUFFER_COUNT;
138      } else {
139          ep_desc->buffer_count = setup->buffer_count;
140      }
141
142
143      if(setup->no_copy) {
144          ep_desc->ep_generic.f = bulk_net_get_impl_no_copy();
145      } else {
146          ep_desc->ep_generic.f = bulk_net_get_impl();
147      }
148
149
150    return SYS_ERR_OK;
151}
152