Changes in uspace/lib/nic/src/nic_impl.c [9cd8165:00d7e1b] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/nic/src/nic_impl.c
r9cd8165 r00d7e1b 36 36 */ 37 37 38 #include <errno.h>39 38 #include <str_error.h> 40 39 #include <ipc/services.h> 41 40 #include <ns.h> 41 #include <packet_client.h> 42 #include <packet_remote.h> 42 43 #include "nic_driver.h" 43 #include "nic_ev.h"44 44 #include "nic_impl.h" 45 45 … … 87 87 } 88 88 if (state == NIC_STATE_ACTIVE) { 89 if (nic_data->client_session == NULL) { 89 if (nic_data->nil_session == NULL || nic_data->net_session == NULL 90 || nic_data->device_id < 0) { 90 91 fibril_rwlock_write_unlock(&nic_data->main_lock); 91 92 return EINVAL; … … 117 118 if (state == NIC_STATE_STOPPED) { 118 119 /* Notify upper layers that we are reseting the MAC */ 119 int rc = ni c_ev_addr_changed(nic_data->client_session,120 &nic_data->default_mac);120 int rc = nil_addr_changed_msg(nic_data->nil_session, 121 nic_data->device_id, &nic_data->default_mac); 121 122 nic_data->poll_mode = nic_data->default_poll_mode; 122 123 memcpy(&nic_data->poll_period, &nic_data->default_poll_period, … … 150 151 nic_data->state = state; 151 152 152 ni c_ev_device_state(nic_data->client_session, state);153 nil_device_state_msg(nic_data->nil_session, nic_data->device_id, state); 153 154 154 155 fibril_rwlock_write_unlock(&nic_data->main_lock); … … 158 159 159 160 /** 160 * Default implementation of the send_ frame method.161 * Default implementation of the send_message method. 161 162 * Send messages to the network. 162 163 * 163 164 * @param fun 164 * @param data Frame data 165 * @param size Frame size in bytes 165 * @param packet_id ID of the first packet in a queue of sent packets 166 166 * 167 167 * @return EOK If the message was sent 168 * @return EBUSY If the device is not in state when the frame can be sent. 169 */ 170 int nic_send_frame_impl(ddf_fun_t *fun, void *data, size_t size) 171 { 172 nic_t *nic_data = (nic_t *) fun->driver_data; 168 * @return EBUSY If the device is not in state when the packet can be set. 169 * @return EINVAL If the packet ID is invalid 170 */ 171 int nic_send_message_impl(ddf_fun_t *fun, packet_id_t packet_id) 172 { 173 nic_t *nic_data = (nic_t *) fun->driver_data; 174 packet_t *packet, *next; 173 175 174 176 fibril_rwlock_read_lock(&nic_data->main_lock); 175 177 if (nic_data->state != NIC_STATE_ACTIVE || nic_data->tx_busy) { 176 178 fibril_rwlock_read_unlock(&nic_data->main_lock); 179 pq_release_remote(nic_data->net_session, packet_id); 177 180 return EBUSY; 178 181 } 179 182 180 nic_data->send_frame(nic_data, data, size); 181 return EOK; 182 } 183 184 /** 185 * Default implementation of the connect_client method. 186 * Creates callback connection to the client. 183 int rc = packet_translate_remote(nic_data->net_session, &packet, packet_id); 184 185 if (rc != EOK) { 186 fibril_rwlock_read_unlock(&nic_data->main_lock); 187 return EINVAL; 188 } 189 190 /* 191 * Process the packet queue. Each sent packet must be detached from the 192 * queue and destroyed. This is why the cycle differs from loopback's 193 * cycle, where the packets are immediately used in upper layers and 194 * therefore they must not be destroyed (released). 195 */ 196 assert(nic_data->write_packet != NULL); 197 do { 198 next = pq_detach(packet); 199 nic_data->write_packet(nic_data, packet); 200 packet = next; 201 } while (packet); 202 fibril_rwlock_read_unlock(&nic_data->main_lock); 203 return EOK; 204 } 205 206 /** 207 * Default implementation of the connect_to_nil method. 208 * Connects the driver to the NIL service. 187 209 * 188 210 * @param fun 189 * 190 * @return EOK On success, or negative error code. 191 */ 192 int nic_callback_create_impl(ddf_fun_t *fun) 193 { 194 nic_t *nic = (nic_t *) fun->driver_data; 195 fibril_rwlock_write_lock(&nic->main_lock); 211 * @param nil_service ID of the server implementing the NIL service 212 * @param device_id ID of the device as used in higher layers 213 * 214 * @return EOK If the services were bound 215 * @return Negative error code from service_connect_blocking 216 */ 217 int nic_connect_to_nil_impl(ddf_fun_t *fun, services_t nil_service, 218 nic_device_id_t device_id) 219 { 220 nic_t *nic_data = (nic_t *) fun->driver_data; 221 fibril_rwlock_write_lock(&nic_data->main_lock); 196 222 197 nic->client_session = async_callback_receive(EXCHANGE_SERIALIZE); 198 if (nic->client_session == NULL) { 199 fibril_rwlock_write_unlock(&nic->main_lock); 200 return ENOMEM; 201 } 223 nic_data->device_id = device_id; 202 224 203 fibril_rwlock_write_unlock(&nic->main_lock); 204 return EOK; 225 nic_data->nil_session = service_connect_blocking(EXCHANGE_SERIALIZE, 226 nil_service, 0, 0); 227 if (nic_data->nil_session != NULL) { 228 fibril_rwlock_write_unlock(&nic_data->main_lock); 229 return EOK; 230 } 231 232 fibril_rwlock_write_unlock(&nic_data->main_lock); 233 return EHANGUP; 205 234 } 206 235 … … 799 828 } 800 829 830 /** Default implementation of the device_added method 831 * 832 * Just calls nic_ready. 833 * 834 * @param dev 835 * 836 */ 837 void nic_device_added_impl(ddf_dev_t *dev) 838 { 839 nic_ready((nic_t *) dev->driver_data); 840 } 841 801 842 /** 802 843 * Default handler for unknown methods (outside of the NIC interface).
Note:
See TracChangeset
for help on using the changeset viewer.