Changes in uspace/lib/nic/src/nic_impl.c [00d7e1b:9cd8165] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/nic/src/nic_impl.c
r00d7e1b r9cd8165 36 36 */ 37 37 38 #include <errno.h> 38 39 #include <str_error.h> 39 40 #include <ipc/services.h> 40 41 #include <ns.h> 41 #include <packet_client.h>42 #include <packet_remote.h>43 42 #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->nil_session == NULL || nic_data->net_session == NULL 90 || nic_data->device_id < 0) { 89 if (nic_data->client_session == NULL) { 91 90 fibril_rwlock_write_unlock(&nic_data->main_lock); 92 91 return EINVAL; … … 118 117 if (state == NIC_STATE_STOPPED) { 119 118 /* Notify upper layers that we are reseting the MAC */ 120 int rc = ni l_addr_changed_msg(nic_data->nil_session,121 nic_data->device_id,&nic_data->default_mac);119 int rc = nic_ev_addr_changed(nic_data->client_session, 120 &nic_data->default_mac); 122 121 nic_data->poll_mode = nic_data->default_poll_mode; 123 122 memcpy(&nic_data->poll_period, &nic_data->default_poll_period, … … 151 150 nic_data->state = state; 152 151 153 ni l_device_state_msg(nic_data->nil_session, nic_data->device_id, state);152 nic_ev_device_state(nic_data->client_session, state); 154 153 155 154 fibril_rwlock_write_unlock(&nic_data->main_lock); … … 159 158 160 159 /** 161 * Default implementation of the send_ message method.160 * Default implementation of the send_frame method. 162 161 * Send messages to the network. 163 162 * 164 163 * @param fun 165 * @param packet_id ID of the first packet in a queue of sent packets 164 * @param data Frame data 165 * @param size Frame size in bytes 166 166 * 167 167 * @return EOK If the message was sent 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; 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; 175 173 176 174 fibril_rwlock_read_lock(&nic_data->main_lock); 177 175 if (nic_data->state != NIC_STATE_ACTIVE || nic_data->tx_busy) { 178 176 fibril_rwlock_read_unlock(&nic_data->main_lock); 179 pq_release_remote(nic_data->net_session, packet_id);180 177 return EBUSY; 181 178 } 182 179 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. 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. 209 187 * 210 188 * @param fun 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); 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); 222 196 223 nic_data->device_id = device_id; 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 } 224 202 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; 203 fibril_rwlock_write_unlock(&nic->main_lock); 204 return EOK; 234 205 } 235 206 … … 828 799 } 829 800 830 /** Default implementation of the device_added method831 *832 * Just calls nic_ready.833 *834 * @param dev835 *836 */837 void nic_device_added_impl(ddf_dev_t *dev)838 {839 nic_ready((nic_t *) dev->driver_data);840 }841 842 801 /** 843 802 * Default handler for unknown methods (outside of the NIC interface).
Note:
See TracChangeset
for help on using the changeset viewer.