Changeset ea788701 in mainline for uspace/lib/nic/src/nic_driver.c
- Timestamp:
- 2012-01-19T18:14:48Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 321052f7
- Parents:
- d8da56b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/nic/src/nic_driver.c
rd8da56b rea788701 51 51 #include <net_interface.h> 52 52 #include <ops/nic.h> 53 #include <packet_client.h>54 #include <packet_remote.h>55 #include <net/packet_header.h>56 53 #include <errno.h> 57 54 … … 64 61 65 62 /** 66 * Initializes libraries required for NIC framework - logger , packet manager63 * Initializes libraries required for NIC framework - logger 67 64 * 68 65 * @param name Name of the device/driver (used in logging) … … 79 76 snprintf(buffer, 256, "drv/" DEVICE_CATEGORY_NIC "/%s", name); 80 77 81 /* Initialize packet manager */ 82 return pm_init(); 78 return EOK; 83 79 } 84 80 … … 162 158 163 159 /** 164 * Setup write packethandler. This MUST be called in the add_device handler160 * Setup send frame handler. This MUST be called in the add_device handler 165 161 * if the nic_send_message_impl function is used for sending messages (filled 166 162 * as send_message member of the nic_iface_t structure). The function must not … … 270 266 } 271 267 272 /** 273 * Just a wrapper over the packet_get_1_remote function 274 */ 275 packet_t *nic_alloc_packet(nic_t *nic_data, size_t data_size) 276 { 277 return packet_get_1_remote(nic_data->net_session, data_size); 278 } 279 280 281 /** 282 * Just a wrapper over the pq_release_remote function 283 */ 284 void nic_release_packet(nic_t *nic_data, packet_t *packet) 285 { 286 pq_release_remote(nic_data->net_session, packet_get_id(packet)); 287 } 288 289 /** Allocate frame and packet 268 /** Allocate frame 290 269 * 291 270 * @param nic_data The NIC driver data … … 607 586 608 587 /** 609 * The busy flag can be set to 1 only in the write_packethandler, to 0 it can588 * The busy flag can be set to 1 only in the send_frame handler, to 0 it can 610 589 * be set anywhere. 611 590 * … … 616 595 { 617 596 /* 618 * When the function is called in write_packethandler the main lock is597 * When the function is called in send_frame handler the main lock is 619 598 * locked so no race can happen. 620 599 * Otherwise, when it is unexpectedly set to 0 (even with main lock held … … 635 614 { 636 615 /* Note: this function must not lock main lock, because loopback driver 637 * calls it inside write_packethandler (with locked main lock) */616 * calls it inside send_frame handler (with locked main lock) */ 638 617 fibril_rwlock_read_lock(&nic_data->rxc_lock); 639 618 nic_frame_type_t frame_type; … … 643 622 /* Update statistics */ 644 623 fibril_rwlock_write_lock(&nic_data->stats_lock); 645 /* Both sending message up and releasing packet are atomic IPC calls */ 624 646 625 if (nic_data->state == NIC_STATE_ACTIVE && check) { 647 626 nic_data->stats.receive_packets++; … … 679 658 /** 680 659 * This function is to be used only in the loopback driver. It's workaround 681 * for the situation when the packetdoes not contain ethernet address.660 * for the situation when the frame does not contain ethernet address. 682 661 * The filtering is therefore not applied here. 683 662 * 684 663 * @param nic_data 685 * @param packet 686 */ 687 void nic_received_noneth_packet(nic_t *nic_data, packet_t *packet) 664 * @param data Frame data 665 * @param size Frame size in bytes 666 */ 667 void nic_received_noneth_frame(nic_t *nic_data, void *data, size_t size) 688 668 { 689 669 fibril_rwlock_write_lock(&nic_data->stats_lock); 690 670 nic_data->stats.receive_packets++; 691 nic_data->stats.receive_bytes += packet_get_data_length(packet);671 nic_data->stats.receive_bytes += size; 692 672 fibril_rwlock_write_unlock(&nic_data->stats_lock); 693 673 694 674 nil_received_msg(nic_data->nil_session, nic_data->device_id, 695 packet_get_data(packet), packet_get_data_length(packet));696 } 697 698 /** 699 * Some NICs can receive multiple packets during single interrupt. These can675 data, size); 676 } 677 678 /** 679 * Some NICs can receive multiple frames during single interrupt. These can 700 680 * send them in whole list of frames (actually nic_frame_t structures), then 701 * the list is deallocated and each packetis passed to the681 * the list is deallocated and each frame is passed to the 702 682 * nic_received_packet function. 703 683 * … … 1315 1295 } 1316 1296 1317 /** Lock packet for DMA usage1318 *1319 * @param packet1320 * @return physical address of packet1321 */1322 int nic_dma_lock_packet(packet_t *packet, size_t size, void **phys)1323 {1324 return dmamem_map(packet, SIZE2PAGES(size), 0, 0, phys);1325 }1326 1327 /** Unlock packet after DMA usage1328 *1329 * @param packet1330 */1331 int nic_dma_unlock_packet(packet_t *packet, size_t size)1332 {1333 return dmamem_unmap(packet, size);1334 }1335 1336 1297 /** @} 1337 1298 */
Note:
See TracChangeset
for help on using the changeset viewer.