Changeset c4be33a in mainline
- Timestamp:
- 2011-12-16T21:15:37Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 792807f
- Parents:
- c8751452
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/Makefile.common
rc8751452 rc4be33a 123 123 test/test3 \ 124 124 nic/lo \ 125 nic/ne2k 125 nic/ne2k \ 126 nic/e1k 126 127 127 128 RD_DRV_CFG = … … 203 204 $(USPACE_PATH)/srv/net/cfg/general \ 204 205 $(USPACE_PATH)/srv/net/cfg/lo.nic \ 205 $(USPACE_PATH)/srv/net/cfg/ne2k.nic 206 $(USPACE_PATH)/srv/net/cfg/ne2k.nic \ 207 $(USPACE_PATH)/srv/net/cfg/e1k.nic 206 208 endif 207 209 -
uspace/drv/nic/e1k/e1k.c
rc8751452 rc4be33a 70 70 71 71 /** nic_driver_data_t* -> e1000_t* cast */ 72 #define DRIVER_DATA_NIC(nic _data) \73 ((e1000_t *) nic_get_specific(nic _data))72 #define DRIVER_DATA_NIC(nic) \ 73 ((e1000_t *) nic_get_specific(nic)) 74 74 75 75 /** device_t* -> nic_driver_data_t* cast */ … … 97 97 #define MEMADDR_TO_PTR(memaddr) ((void *) ((size_t) (memaddr))) 98 98 99 #define E1000_REG_BASE(e1000 _data) \100 ((e1000 _data)->virt_reg_base)101 102 #define E1000_REG_ADDR(e1000 _data, reg) \103 ((uint32_t *) (E1000_REG_BASE(e1000 _data) + reg))104 105 #define E1000_REG_READ(e1000 _data, reg) \106 (pio_read_32(E1000_REG_ADDR(e1000 _data, reg)))107 108 #define E1000_REG_WRITE(e1000 _data, reg, value) \109 (pio_write_32(E1000_REG_ADDR(e1000 _data, reg), value))99 #define E1000_REG_BASE(e1000) \ 100 ((e1000)->reg_base_virt) 101 102 #define E1000_REG_ADDR(e1000, reg) \ 103 ((uint32_t *) (E1000_REG_BASE(e1000) + reg)) 104 105 #define E1000_REG_READ(e1000, reg) \ 106 (pio_read_32(E1000_REG_ADDR(e1000, reg))) 107 108 #define E1000_REG_WRITE(e1000, reg, value) \ 109 (pio_write_32(E1000_REG_ADDR(e1000, reg), value)) 110 110 111 111 /** E1000 device data */ 112 typedef struct e1000_data{112 typedef struct { 113 113 /** Physical registers base address */ 114 void * phys_reg_base;114 void *reg_base_phys; 115 115 /** Virtual registers base address */ 116 void *virt_reg_base; 117 /** Tx ring */ 118 dmamem_t tx_ring; 116 void *reg_base_virt; 117 118 /** Physical tx ring address */ 119 void *tx_ring_phys; 120 /** Virtual tx ring address */ 121 void *tx_ring_virt; 122 119 123 /** Packets in tx ring */ 120 124 packet_t **tx_ring_packets; 121 /** Rx ring */ 122 dmamem_t rx_ring; 125 126 /** Physical rx ring address */ 127 void *rx_ring_phys; 128 /** Virtual rx ring address */ 129 void *rx_ring_virt; 130 123 131 /** Packets in rx ring */ 124 132 packet_t **rx_ring_packets; 133 125 134 /** VLAN tag */ 126 135 uint16_t vlan_tag; 136 127 137 /** Add VLAN tag to packet */ 128 138 bool vlan_tag_add; 139 129 140 /** Used unicast Receive Address count */ 130 141 unsigned int unicast_ra_count; 142 131 143 /** Used milticast Receive addrress count */ 132 144 unsigned int multicast_ra_count; 145 133 146 /** PCI device ID */ 134 147 uint16_t device_id; 148 135 149 /** The irq assigned */ 136 150 int irq; 151 137 152 /** Lock for CTRL register */ 138 153 fibril_mutex_t ctrl_lock; 154 139 155 /** Lock for receiver */ 140 156 fibril_mutex_t rx_lock; 157 141 158 /** Lock for transmitter */ 142 159 fibril_mutex_t tx_lock; 160 143 161 /** Lock for EEPROM access */ 144 162 fibril_mutex_t eeprom_lock; … … 225 243 .cmd = CMD_PIO_WRITE_32, 226 244 .addr = NULL, 227 .value = 0x FFFFFFFF245 .value = 0xffffffff 228 246 }, 229 247 { … … 280 298 assert(state); 281 299 282 e1000_t *e1000 _data= DRIVER_DATA_DEV(dev);283 if (E1000_REG_READ(e1000 _data, E1000_STATUS) & (STATUS_LU))300 e1000_t *e1000 = DRIVER_DATA_DEV(dev); 301 if (E1000_REG_READ(e1000, E1000_STATUS) & (STATUS_LU)) 284 302 *state = NIC_CS_PLUGGED; 285 303 else … … 300 318 nic_channel_mode_t *duplex, nic_role_t *role) 301 319 { 302 e1000_t *e1000 _data= DRIVER_DATA_DEV(dev);303 uint32_t status = E1000_REG_READ(e1000 _data, E1000_STATUS);320 e1000_t *e1000 = DRIVER_DATA_DEV(dev); 321 uint32_t status = E1000_REG_READ(e1000, E1000_STATUS); 304 322 305 323 if (status & STATUS_FD) … … 323 341 } 324 342 325 static void e1000_link_restart(e1000_t * e1000_data)326 { 327 fibril_mutex_lock(&e1000 _data->ctrl_lock);328 329 uint32_t ctrl = E1000_REG_READ(e1000 _data, E1000_CTRL);343 static void e1000_link_restart(e1000_t *e1000) 344 { 345 fibril_mutex_lock(&e1000->ctrl_lock); 346 347 uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL); 330 348 331 349 if (ctrl & CTRL_SLU) { 332 350 ctrl &= ~(CTRL_SLU); 333 fibril_mutex_unlock(&e1000 _data->ctrl_lock);351 fibril_mutex_unlock(&e1000->ctrl_lock); 334 352 usleep(10); 335 fibril_mutex_lock(&e1000 _data->ctrl_lock);353 fibril_mutex_lock(&e1000->ctrl_lock); 336 354 ctrl |= CTRL_SLU; 337 355 } 338 356 339 fibril_mutex_unlock(&e1000 _data->ctrl_lock);340 341 e1000_link_restart(e1000 _data);357 fibril_mutex_unlock(&e1000->ctrl_lock); 358 359 e1000_link_restart(e1000); 342 360 } 343 361 … … 354 372 return EINVAL; 355 373 356 e1000_t *e1000 _data= DRIVER_DATA_DEV(dev);357 358 fibril_mutex_lock(&e1000 _data->ctrl_lock);359 uint32_t ctrl = E1000_REG_READ(e1000 _data, E1000_CTRL);374 e1000_t *e1000 = DRIVER_DATA_DEV(dev); 375 376 fibril_mutex_lock(&e1000->ctrl_lock); 377 uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL); 360 378 361 379 ctrl |= CTRL_FRCSPD; … … 376 394 ctrl |= CTRL_SPEED_10 << CTRL_SPEED_SHIFT; 377 395 378 E1000_REG_WRITE(e1000 _data, E1000_CTRL, ctrl);379 380 fibril_mutex_unlock(&e1000 _data->ctrl_lock);381 382 e1000_link_restart(e1000 _data);396 E1000_REG_WRITE(e1000, E1000_CTRL, ctrl); 397 398 fibril_mutex_unlock(&e1000->ctrl_lock); 399 400 e1000_link_restart(e1000); 383 401 384 402 return EOK; … … 395 413 static int e1000_autoneg_enable(ddf_fun_t *dev, uint32_t advertisement) 396 414 { 397 e1000_t *e1000 _data= DRIVER_DATA_DEV(dev);398 399 fibril_mutex_lock(&e1000 _data->ctrl_lock);400 401 uint32_t ctrl = E1000_REG_READ(e1000 _data, E1000_CTRL);415 e1000_t *e1000 = DRIVER_DATA_DEV(dev); 416 417 fibril_mutex_lock(&e1000->ctrl_lock); 418 419 uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL); 402 420 403 421 ctrl &= ~(CTRL_FRCSPD); … … 405 423 ctrl |= CTRL_ASDE; 406 424 407 E1000_REG_WRITE(e1000 _data, E1000_CTRL, ctrl);408 409 fibril_mutex_unlock(&e1000 _data->ctrl_lock);410 411 e1000_link_restart(e1000 _data);425 E1000_REG_WRITE(e1000, E1000_CTRL, ctrl); 426 427 fibril_mutex_unlock(&e1000->ctrl_lock); 428 429 e1000_link_restart(e1000); 412 430 413 431 return EOK; … … 423 441 static int e1000_autoneg_disable(ddf_fun_t *dev) 424 442 { 425 e1000_t *e1000 _data= DRIVER_DATA_DEV(dev);426 427 fibril_mutex_lock(&e1000 _data->ctrl_lock);428 429 uint32_t ctrl = E1000_REG_READ(e1000 _data, E1000_CTRL);443 e1000_t *e1000 = DRIVER_DATA_DEV(dev); 444 445 fibril_mutex_lock(&e1000->ctrl_lock); 446 447 uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL); 430 448 431 449 ctrl |= CTRL_FRCSPD; … … 433 451 ctrl &= ~(CTRL_ASDE); 434 452 435 E1000_REG_WRITE(e1000 _data, E1000_CTRL, ctrl);436 437 fibril_mutex_unlock(&e1000 _data->ctrl_lock);438 439 e1000_link_restart(e1000 _data);453 E1000_REG_WRITE(e1000, E1000_CTRL, ctrl); 454 455 fibril_mutex_unlock(&e1000->ctrl_lock); 456 457 e1000_link_restart(e1000); 440 458 441 459 return EOK; … … 462 480 static int e1000_defective_get_mode(ddf_fun_t *device, uint32_t *mode) 463 481 { 464 e1000_t *e1000 _data= DRIVER_DATA_DEV(device);482 e1000_t *e1000 = DRIVER_DATA_DEV(device); 465 483 466 484 *mode = 0; 467 uint32_t rctl = E1000_REG_READ(e1000 _data, E1000_RCTL);485 uint32_t rctl = E1000_REG_READ(e1000, E1000_RCTL); 468 486 if (rctl & RCTL_SBP) 469 487 *mode = NIC_DEFECTIVE_BAD_CRC | NIC_DEFECTIVE_SHORT; … … 483 501 static int e1000_defective_set_mode(ddf_fun_t *device, uint32_t mode) 484 502 { 485 e1000_t *e1000 _data= DRIVER_DATA_DEV(device);503 e1000_t *e1000 = DRIVER_DATA_DEV(device); 486 504 int rc = EOK; 487 505 488 fibril_mutex_lock(&e1000 _data->rx_lock);489 490 uint32_t rctl = E1000_REG_READ(e1000 _data, E1000_RCTL);506 fibril_mutex_lock(&e1000->rx_lock); 507 508 uint32_t rctl = E1000_REG_READ(e1000, E1000_RCTL); 491 509 bool short_mode = (mode & NIC_DEFECTIVE_SHORT ? true : false); 492 510 bool bad_mode = (mode & NIC_DEFECTIVE_BAD_CRC ? true : false); … … 499 517 rc = ENOTSUP; 500 518 501 E1000_REG_WRITE(e1000 _data, E1000_RCTL, rctl);502 503 fibril_mutex_unlock(&e1000 _data->rx_lock);519 E1000_REG_WRITE(e1000, E1000_RCTL, rctl); 520 521 fibril_mutex_unlock(&e1000->rx_lock); 504 522 return rc; 505 523 }; … … 507 525 /** Write receive address to RA registr 508 526 * 509 * @param e1000 _dataE1000 data structure527 * @param e1000 E1000 data structure 510 528 * @param position RA register position 511 529 * @param address Ethernet address … … 513 531 * 514 532 */ 515 static void e1000_write_receive_address(e1000_t *e1000_data, 516 unsigned int position, const nic_address_t * address, 517 bool set_av_bit) 533 static void e1000_write_receive_address(e1000_t *e1000, unsigned int position, 534 const nic_address_t * address, bool set_av_bit) 518 535 { 519 536 uint8_t *mac0 = (uint8_t *) address->address; … … 533 550 rah |= RAH_AV; 534 551 else 535 rah |= E1000_REG_READ(e1000_data, E1000_RAH_ARRAY(position)) & 536 RAH_AV; 537 538 E1000_REG_WRITE(e1000_data, E1000_RAH_ARRAY(position), rah); 539 E1000_REG_WRITE(e1000_data, E1000_RAL_ARRAY(position), ral); 552 rah |= E1000_REG_READ(e1000, E1000_RAH_ARRAY(position)) & RAH_AV; 553 554 E1000_REG_WRITE(e1000, E1000_RAH_ARRAY(position), rah); 555 E1000_REG_WRITE(e1000, E1000_RAL_ARRAY(position), ral); 540 556 } 541 557 … … 544 560 * Clear Address Valid bit 545 561 * 546 * @param e1000_data E1000 data structure 547 * @param position RA register position 548 * 549 */ 550 static void e1000_disable_receive_address(e1000_t *e1000_data, 551 unsigned int position) 552 { 553 uint32_t rah = 554 E1000_REG_READ(e1000_data, E1000_RAH_ARRAY(position)); 562 * @param e1000 E1000 data structure 563 * @param position RA register position 564 * 565 */ 566 static void e1000_disable_receive_address(e1000_t *e1000, unsigned int position) 567 { 568 uint32_t rah = E1000_REG_READ(e1000, E1000_RAH_ARRAY(position)); 555 569 rah = rah & ~RAH_AV; 556 E1000_REG_WRITE(e1000 _data, E1000_RAH_ARRAY(position), rah);570 E1000_REG_WRITE(e1000, E1000_RAH_ARRAY(position), rah); 557 571 } 558 572 559 573 /** Clear all unicast addresses from RA registers 560 574 * 561 * @param e1000 _dataE1000 data structure562 * 563 */ 564 static void e1000_clear_unicast_receive_addresses(e1000_t *e1000 _data)575 * @param e1000 E1000 data structure 576 * 577 */ 578 static void e1000_clear_unicast_receive_addresses(e1000_t *e1000) 565 579 { 566 580 for (unsigned int ra_num = 1; 567 ra_num <= e1000 _data->unicast_ra_count;581 ra_num <= e1000->unicast_ra_count; 568 582 ra_num++) 569 e1000_disable_receive_address(e1000 _data, ra_num);570 571 e1000 _data->unicast_ra_count = 0;583 e1000_disable_receive_address(e1000, ra_num); 584 585 e1000->unicast_ra_count = 0; 572 586 } 573 587 574 588 /** Clear all multicast addresses from RA registers 575 589 * 576 * @param e1000 _dataE1000 data structure577 * 578 */ 579 static void e1000_clear_multicast_receive_addresses(e1000_t *e1000 _data)590 * @param e1000 E1000 data structure 591 * 592 */ 593 static void e1000_clear_multicast_receive_addresses(e1000_t *e1000) 580 594 { 581 595 unsigned int first_multicast_ra_num = 582 E1000_RECEIVE_ADDRESS - e1000 _data->multicast_ra_count;596 E1000_RECEIVE_ADDRESS - e1000->multicast_ra_count; 583 597 584 598 for (unsigned int ra_num = E1000_RECEIVE_ADDRESS - 1; 585 599 ra_num >= first_multicast_ra_num; 586 600 ra_num--) 587 e1000_disable_receive_address(e1000 _data, ra_num);588 589 e1000 _data->multicast_ra_count = 0;601 e1000_disable_receive_address(e1000, ra_num); 602 603 e1000->multicast_ra_count = 0; 590 604 } 591 605 592 606 /** Return receive address filter positions count usable for unicast 593 607 * 594 * @param e1000 _dataE1000 data structure608 * @param e1000 E1000 data structure 595 609 * 596 610 * @return receive address filter positions count usable for unicast 597 611 * 598 612 */ 599 static unsigned int get_free_unicast_address_count(e1000_t *e1000 _data)600 { 601 return E1000_RECEIVE_ADDRESS - 1 - e1000 _data->multicast_ra_count;613 static unsigned int get_free_unicast_address_count(e1000_t *e1000) 614 { 615 return E1000_RECEIVE_ADDRESS - 1 - e1000->multicast_ra_count; 602 616 } 603 617 604 618 /** Return receive address filter positions count usable for multicast 605 619 * 606 * @param e1000 _dataE1000 data structure620 * @param e1000 E1000 data structure 607 621 * 608 622 * @return receive address filter positions count usable for multicast 609 623 * 610 624 */ 611 static unsigned int get_free_multicast_address_count(e1000_t *e1000 _data)612 { 613 return E1000_RECEIVE_ADDRESS - 1 - e1000 _data->unicast_ra_count;625 static unsigned int get_free_multicast_address_count(e1000_t *e1000) 626 { 627 return E1000_RECEIVE_ADDRESS - 1 - e1000->unicast_ra_count; 614 628 } 615 629 616 630 /** Write unicast receive addresses to receive address filter registers 617 631 * 618 * @param e1000 _dataE1000 data structure619 * @param addr 620 * @param addr_cnt 621 * 622 */ 623 static void e1000_add_unicast_receive_addresses(e1000_t *e1000 _data,632 * @param e1000 E1000 data structure 633 * @param addr Pointer to address array 634 * @param addr_cnt Address array count 635 * 636 */ 637 static void e1000_add_unicast_receive_addresses(e1000_t *e1000, 624 638 const nic_address_t *addr, size_t addr_cnt) 625 639 { 626 assert(addr_cnt <= get_free_unicast_address_count(e1000 _data));640 assert(addr_cnt <= get_free_unicast_address_count(e1000)); 627 641 628 642 nic_address_t *addr_iterator = (nic_address_t *) addr; … … 632 646 ra_num <= addr_cnt; 633 647 ra_num++) { 634 e1000_write_receive_address(e1000 _data, ra_num, addr_iterator, true);648 e1000_write_receive_address(e1000, ra_num, addr_iterator, true); 635 649 addr_iterator++; 636 650 } … … 639 653 /** Write multicast receive addresses to receive address filter registers 640 654 * 641 * @param e1000 _dataE1000 data structure642 * @param addr 643 * @param addr_cnt 644 * 645 */ 646 static void e1000_add_multicast_receive_addresses(e1000_t *e1000 _data,655 * @param e1000 E1000 data structure 656 * @param addr Pointer to address array 657 * @param addr_cnt Address array count 658 * 659 */ 660 static void e1000_add_multicast_receive_addresses(e1000_t *e1000, 647 661 const nic_address_t *addr, size_t addr_cnt) 648 662 { 649 assert(addr_cnt <= get_free_multicast_address_count(e1000 _data));663 assert(addr_cnt <= get_free_multicast_address_count(e1000)); 650 664 651 665 nic_address_t *addr_iterator = (nic_address_t *) addr; … … 655 669 ra_num >= first_multicast_ra_num; 656 670 ra_num--) { 657 e1000_write_receive_address(e1000 _data, ra_num, addr_iterator, true);671 e1000_write_receive_address(e1000, ra_num, addr_iterator, true); 658 672 addr_iterator++; 659 673 } … … 662 676 /** Disable receiving packets for default address 663 677 * 664 * @param e1000 _dataE1000 data structure665 * 666 */ 667 static void disable_ra0_address_filter(e1000_t *e1000 _data)668 { 669 uint32_t rah0 = E1000_REG_READ(e1000 _data, E1000_RAH_ARRAY(0));678 * @param e1000 E1000 data structure 679 * 680 */ 681 static void disable_ra0_address_filter(e1000_t *e1000) 682 { 683 uint32_t rah0 = E1000_REG_READ(e1000, E1000_RAH_ARRAY(0)); 670 684 rah0 = rah0 & ~RAH_AV; 671 E1000_REG_WRITE(e1000 _data, E1000_RAH_ARRAY(0), rah0);685 E1000_REG_WRITE(e1000, E1000_RAH_ARRAY(0), rah0); 672 686 } 673 687 674 688 /** Enable receiving packets for default address 675 689 * 676 * @param e1000 _dataE1000 data structure677 * 678 */ 679 static void enable_ra0_address_filter(e1000_t *e1000 _data)680 { 681 uint32_t rah0 = E1000_REG_READ(e1000 _data, E1000_RAH_ARRAY(0));690 * @param e1000 E1000 data structure 691 * 692 */ 693 static void enable_ra0_address_filter(e1000_t *e1000) 694 { 695 uint32_t rah0 = E1000_REG_READ(e1000, E1000_RAH_ARRAY(0)); 682 696 rah0 = rah0 | RAH_AV; 683 E1000_REG_WRITE(e1000 _data, E1000_RAH_ARRAY(0), rah0);697 E1000_REG_WRITE(e1000, E1000_RAH_ARRAY(0), rah0); 684 698 } 685 699 686 700 /** Disable unicast promiscuous mode 687 701 * 688 * @param e1000 _dataE1000 data structure689 * 690 */ 691 static void e1000_disable_unicast_promisc(e1000_t *e1000 _data)692 { 693 uint32_t rctl = E1000_REG_READ(e1000 _data, E1000_RCTL);702 * @param e1000 E1000 data structure 703 * 704 */ 705 static void e1000_disable_unicast_promisc(e1000_t *e1000) 706 { 707 uint32_t rctl = E1000_REG_READ(e1000, E1000_RCTL); 694 708 rctl = rctl & ~RCTL_UPE; 695 E1000_REG_WRITE(e1000 _data, E1000_RCTL, rctl);709 E1000_REG_WRITE(e1000, E1000_RCTL, rctl); 696 710 } 697 711 698 712 /** Enable unicast promiscuous mode 699 713 * 700 * @param e1000 _dataE1000 data structure701 * 702 */ 703 static void e1000_enable_unicast_promisc(e1000_t *e1000 _data)704 { 705 uint32_t rctl = E1000_REG_READ(e1000 _data, E1000_RCTL);714 * @param e1000 E1000 data structure 715 * 716 */ 717 static void e1000_enable_unicast_promisc(e1000_t *e1000) 718 { 719 uint32_t rctl = E1000_REG_READ(e1000, E1000_RCTL); 706 720 rctl = rctl | RCTL_UPE; 707 E1000_REG_WRITE(e1000 _data, E1000_RCTL, rctl);721 E1000_REG_WRITE(e1000, E1000_RCTL, rctl); 708 722 } 709 723 710 724 /** Disable multicast promiscuous mode 711 725 * 712 * @param e1000 _dataE1000 data structure713 * 714 */ 715 static void e1000_disable_multicast_promisc(e1000_t *e1000 _data)716 { 717 uint32_t rctl = E1000_REG_READ(e1000 _data, E1000_RCTL);726 * @param e1000 E1000 data structure 727 * 728 */ 729 static void e1000_disable_multicast_promisc(e1000_t *e1000) 730 { 731 uint32_t rctl = E1000_REG_READ(e1000, E1000_RCTL); 718 732 rctl = rctl & ~RCTL_MPE; 719 E1000_REG_WRITE(e1000 _data, E1000_RCTL, rctl);733 E1000_REG_WRITE(e1000, E1000_RCTL, rctl); 720 734 } 721 735 722 736 /** Enable multicast promiscuous mode 723 737 * 724 * @param e1000 _dataE1000 data structure725 * 726 */ 727 static void e1000_enable_multicast_promisc(e1000_t *e1000 _data)728 { 729 uint32_t rctl = E1000_REG_READ(e1000 _data, E1000_RCTL);738 * @param e1000 E1000 data structure 739 * 740 */ 741 static void e1000_enable_multicast_promisc(e1000_t *e1000) 742 { 743 uint32_t rctl = E1000_REG_READ(e1000, E1000_RCTL); 730 744 rctl = rctl | RCTL_MPE; 731 E1000_REG_WRITE(e1000 _data, E1000_RCTL, rctl);745 E1000_REG_WRITE(e1000, E1000_RCTL, rctl); 732 746 } 733 747 734 748 /** Enable accepting of broadcast packets 735 749 * 736 * @param e1000 _dataE1000 data structure737 * 738 */ 739 static void e1000_enable_broadcast_accept(e1000_t *e1000 _data)740 { 741 uint32_t rctl = E1000_REG_READ(e1000 _data, E1000_RCTL);750 * @param e1000 E1000 data structure 751 * 752 */ 753 static void e1000_enable_broadcast_accept(e1000_t *e1000) 754 { 755 uint32_t rctl = E1000_REG_READ(e1000, E1000_RCTL); 742 756 rctl = rctl | RCTL_BAM; 743 E1000_REG_WRITE(e1000 _data, E1000_RCTL, rctl);757 E1000_REG_WRITE(e1000, E1000_RCTL, rctl); 744 758 } 745 759 746 760 /** Disable accepting of broadcast packets 747 761 * 748 * @param e1000 _dataE1000 data structure749 * 750 */ 751 static void e1000_disable_broadcast_accept(e1000_t *e1000 _data)752 { 753 uint32_t rctl = E1000_REG_READ(e1000 _data, E1000_RCTL);762 * @param e1000 E1000 data structure 763 * 764 */ 765 static void e1000_disable_broadcast_accept(e1000_t *e1000) 766 { 767 uint32_t rctl = E1000_REG_READ(e1000, E1000_RCTL); 754 768 rctl = rctl & ~RCTL_BAM; 755 E1000_REG_WRITE(e1000 _data, E1000_RCTL, rctl);769 E1000_REG_WRITE(e1000, E1000_RCTL, rctl); 756 770 } 757 771 758 772 /** Enable VLAN filtering according to VFTA registers 759 773 * 760 * @param e1000 _dataE1000 data structure761 * 762 */ 763 static void e1000_enable_vlan_filter(e1000_t *e1000 _data)764 { 765 uint32_t rctl = E1000_REG_READ(e1000 _data, E1000_RCTL);774 * @param e1000 E1000 data structure 775 * 776 */ 777 static void e1000_enable_vlan_filter(e1000_t *e1000) 778 { 779 uint32_t rctl = E1000_REG_READ(e1000, E1000_RCTL); 766 780 rctl = rctl | RCTL_VFE; 767 E1000_REG_WRITE(e1000 _data, E1000_RCTL, rctl);781 E1000_REG_WRITE(e1000, E1000_RCTL, rctl); 768 782 } 769 783 770 784 /** Disable VLAN filtering 771 785 * 772 * @param e1000 _dataE1000 data structure773 * 774 */ 775 static void e1000_disable_vlan_filter(e1000_t *e1000 _data)776 { 777 uint32_t rctl = E1000_REG_READ(e1000 _data, E1000_RCTL);786 * @param e1000 E1000 data structure 787 * 788 */ 789 static void e1000_disable_vlan_filter(e1000_t *e1000) 790 { 791 uint32_t rctl = E1000_REG_READ(e1000, E1000_RCTL); 778 792 rctl = rctl & ~RCTL_VFE; 779 E1000_REG_WRITE(e1000 _data, E1000_RCTL, rctl);793 E1000_REG_WRITE(e1000, E1000_RCTL, rctl); 780 794 } 781 795 782 796 /** Set multicast packets acceptance mode 783 797 * 784 * @param nic _dataNIC device to update798 * @param nic NIC device to update 785 799 * @param mode Mode to set 786 800 * @param addr Address list (used in mode = NIC_MULTICAST_LIST) … … 790 804 * 791 805 */ 792 static int e1000_on_multicast_mode_change(nic_t *nic _data,793 nic_multicast_mode_t mode,const nic_address_t *addr, size_t addr_cnt)794 { 795 e1000_t *e1000 _data = DRIVER_DATA_NIC(nic_data);806 static int e1000_on_multicast_mode_change(nic_t *nic, nic_multicast_mode_t mode, 807 const nic_address_t *addr, size_t addr_cnt) 808 { 809 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 796 810 int rc = EOK; 797 811 798 fibril_mutex_lock(&e1000 _data->rx_lock);812 fibril_mutex_lock(&e1000->rx_lock); 799 813 800 814 switch (mode) { 801 815 case NIC_MULTICAST_BLOCKED: 802 e1000_clear_multicast_receive_addresses(e1000 _data);803 e1000_disable_multicast_promisc(e1000 _data);804 nic_report_hw_filtering(nic _data, -1, 1, -1);816 e1000_clear_multicast_receive_addresses(e1000); 817 e1000_disable_multicast_promisc(e1000); 818 nic_report_hw_filtering(nic, -1, 1, -1); 805 819 break; 806 820 case NIC_MULTICAST_LIST: 807 e1000_clear_multicast_receive_addresses(e1000 _data);808 if (addr_cnt > get_free_multicast_address_count(e1000 _data)) {821 e1000_clear_multicast_receive_addresses(e1000); 822 if (addr_cnt > get_free_multicast_address_count(e1000)) { 809 823 /* 810 824 * Future work: fill MTA table … … 812 826 * in the NIC library. 813 827 */ 814 e1000_enable_multicast_promisc(e1000 _data);815 nic_report_hw_filtering(nic _data, -1, 0, -1);828 e1000_enable_multicast_promisc(e1000); 829 nic_report_hw_filtering(nic, -1, 0, -1); 816 830 } else { 817 e1000_disable_multicast_promisc(e1000 _data);818 e1000_add_multicast_receive_addresses(e1000 _data, addr, addr_cnt);819 nic_report_hw_filtering(nic _data, -1, 1, -1);831 e1000_disable_multicast_promisc(e1000); 832 e1000_add_multicast_receive_addresses(e1000, addr, addr_cnt); 833 nic_report_hw_filtering(nic, -1, 1, -1); 820 834 } 821 835 break; 822 836 case NIC_MULTICAST_PROMISC: 823 e1000_enable_multicast_promisc(e1000 _data);824 e1000_clear_multicast_receive_addresses(e1000 _data);825 nic_report_hw_filtering(nic _data, -1, 1, -1);837 e1000_enable_multicast_promisc(e1000); 838 e1000_clear_multicast_receive_addresses(e1000); 839 nic_report_hw_filtering(nic, -1, 1, -1); 826 840 break; 827 841 default: … … 830 844 } 831 845 832 fibril_mutex_unlock(&e1000 _data->rx_lock);846 fibril_mutex_unlock(&e1000->rx_lock); 833 847 return rc; 834 848 } … … 836 850 /** Set unicast packets acceptance mode 837 851 * 838 * @param nic _dataNIC device to update852 * @param nic NIC device to update 839 853 * @param mode Mode to set 840 854 * @param addr Address list (used in mode = NIC_MULTICAST_LIST) … … 844 858 * 845 859 */ 846 static int e1000_on_unicast_mode_change(nic_t *nic _data,847 nic_unicast_mode_t mode,const nic_address_t *addr, size_t addr_cnt)848 { 849 e1000_t *e1000 _data = DRIVER_DATA_NIC(nic_data);860 static int e1000_on_unicast_mode_change(nic_t *nic, nic_unicast_mode_t mode, 861 const nic_address_t *addr, size_t addr_cnt) 862 { 863 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 850 864 int rc = EOK; 851 865 852 fibril_mutex_lock(&e1000 _data->rx_lock);866 fibril_mutex_lock(&e1000->rx_lock); 853 867 854 868 switch (mode) { 855 869 case NIC_UNICAST_BLOCKED: 856 disable_ra0_address_filter(e1000 _data);857 e1000_clear_unicast_receive_addresses(e1000 _data);858 e1000_disable_unicast_promisc(e1000 _data);859 nic_report_hw_filtering(nic _data, 1, -1, -1);870 disable_ra0_address_filter(e1000); 871 e1000_clear_unicast_receive_addresses(e1000); 872 e1000_disable_unicast_promisc(e1000); 873 nic_report_hw_filtering(nic, 1, -1, -1); 860 874 break; 861 875 case NIC_UNICAST_DEFAULT: 862 enable_ra0_address_filter(e1000 _data);863 e1000_clear_unicast_receive_addresses(e1000 _data);864 e1000_disable_unicast_promisc(e1000 _data);865 nic_report_hw_filtering(nic _data, 1, -1, -1);876 enable_ra0_address_filter(e1000); 877 e1000_clear_unicast_receive_addresses(e1000); 878 e1000_disable_unicast_promisc(e1000); 879 nic_report_hw_filtering(nic, 1, -1, -1); 866 880 break; 867 881 case NIC_UNICAST_LIST: 868 enable_ra0_address_filter(e1000 _data);869 e1000_clear_unicast_receive_addresses(e1000 _data);870 if (addr_cnt > get_free_unicast_address_count(e1000 _data)) {871 e1000_enable_unicast_promisc(e1000 _data);872 nic_report_hw_filtering(nic _data, 0, -1, -1);882 enable_ra0_address_filter(e1000); 883 e1000_clear_unicast_receive_addresses(e1000); 884 if (addr_cnt > get_free_unicast_address_count(e1000)) { 885 e1000_enable_unicast_promisc(e1000); 886 nic_report_hw_filtering(nic, 0, -1, -1); 873 887 } else { 874 e1000_disable_unicast_promisc(e1000 _data);875 e1000_add_unicast_receive_addresses(e1000 _data, addr, addr_cnt);876 nic_report_hw_filtering(nic _data, 1, -1, -1);888 e1000_disable_unicast_promisc(e1000); 889 e1000_add_unicast_receive_addresses(e1000, addr, addr_cnt); 890 nic_report_hw_filtering(nic, 1, -1, -1); 877 891 } 878 892 break; 879 893 case NIC_UNICAST_PROMISC: 880 e1000_enable_unicast_promisc(e1000 _data);881 enable_ra0_address_filter(e1000 _data);882 e1000_clear_unicast_receive_addresses(e1000 _data);883 nic_report_hw_filtering(nic _data, 1, -1, -1);894 e1000_enable_unicast_promisc(e1000); 895 enable_ra0_address_filter(e1000); 896 e1000_clear_unicast_receive_addresses(e1000); 897 nic_report_hw_filtering(nic, 1, -1, -1); 884 898 break; 885 899 default: … … 888 902 } 889 903 890 fibril_mutex_unlock(&e1000 _data->rx_lock);904 fibril_mutex_unlock(&e1000->rx_lock); 891 905 return rc; 892 906 } … … 894 908 /** Set broadcast packets acceptance mode 895 909 * 896 * @param nic _dataNIC device to update897 * @param mode 910 * @param nic NIC device to update 911 * @param mode Mode to set 898 912 * 899 913 * @return EOK 900 914 * 901 915 */ 902 static int e1000_on_broadcast_mode_change(nic_t *nic_data, 903 nic_broadcast_mode_t mode) 904 { 905 e1000_t *e1000_data = DRIVER_DATA_NIC(nic_data); 916 static int e1000_on_broadcast_mode_change(nic_t *nic, nic_broadcast_mode_t mode) 917 { 918 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 906 919 int rc = EOK; 907 920 908 fibril_mutex_lock(&e1000 _data->rx_lock);921 fibril_mutex_lock(&e1000->rx_lock); 909 922 910 923 switch (mode) { 911 924 case NIC_BROADCAST_BLOCKED: 912 e1000_disable_broadcast_accept(e1000 _data);925 e1000_disable_broadcast_accept(e1000); 913 926 break; 914 927 case NIC_BROADCAST_ACCEPTED: 915 e1000_enable_broadcast_accept(e1000 _data);928 e1000_enable_broadcast_accept(e1000); 916 929 break; 917 930 default: … … 920 933 } 921 934 922 fibril_mutex_unlock(&e1000 _data->rx_lock);935 fibril_mutex_unlock(&e1000->rx_lock); 923 936 return rc; 924 937 } … … 926 939 /** Check if receiving is enabled 927 940 * 928 * @param e1000 _dataE1000 data structure941 * @param e1000 E1000 data structure 929 942 * 930 943 * @return true if receiving is enabled 931 944 * 932 945 */ 933 static bool e1000_is_rx_enabled(e1000_t *e1000 _data)934 { 935 if (E1000_REG_READ(e1000 _data, E1000_RCTL) & (RCTL_EN))946 static bool e1000_is_rx_enabled(e1000_t *e1000) 947 { 948 if (E1000_REG_READ(e1000, E1000_RCTL) & (RCTL_EN)) 936 949 return true; 937 950 … … 941 954 /** Enable receiving 942 955 * 943 * @param e1000 _dataE1000 data structure944 * 945 */ 946 static void e1000_enable_rx(e1000_t *e1000 _data)956 * @param e1000 E1000 data structure 957 * 958 */ 959 static void e1000_enable_rx(e1000_t *e1000) 947 960 { 948 961 /* Set Receive Enable Bit */ 949 E1000_REG_WRITE(e1000 _data, E1000_RCTL,950 E1000_REG_READ(e1000 _data, E1000_RCTL) | (RCTL_EN));962 E1000_REG_WRITE(e1000, E1000_RCTL, 963 E1000_REG_READ(e1000, E1000_RCTL) | (RCTL_EN)); 951 964 } 952 965 953 966 /** Disable receiving 954 967 * 955 * @param e1000 _dataE1000 data structure956 * 957 */ 958 static void e1000_disable_rx(e1000_t *e1000 _data)968 * @param e1000 E1000 data structure 969 * 970 */ 971 static void e1000_disable_rx(e1000_t *e1000) 959 972 { 960 973 /* Clear Receive Enable Bit */ 961 E1000_REG_WRITE(e1000 _data, E1000_RCTL,962 E1000_REG_READ(e1000 _data, E1000_RCTL) & ~(RCTL_EN));974 E1000_REG_WRITE(e1000, E1000_RCTL, 975 E1000_REG_READ(e1000, E1000_RCTL) & ~(RCTL_EN)); 963 976 } 964 977 965 978 /** Set VLAN mask 966 979 * 967 * @param nic _dataNIC device to update980 * @param nic NIC device to update 968 981 * @param vlan_mask VLAN mask 969 982 * 970 983 */ 971 static void e1000_on_vlan_mask_change(nic_t *nic _data,972 const nic_vlan_mask_t *vlan_mask)973 { 974 e1000_t *e1000 _data = DRIVER_DATA_NIC(nic_data);975 976 fibril_mutex_lock(&e1000 _data->rx_lock);984 static void e1000_on_vlan_mask_change(nic_t *nic, 985 const nic_vlan_mask_t *vlan_mask) 986 { 987 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 988 989 fibril_mutex_lock(&e1000->rx_lock); 977 990 978 991 if (vlan_mask) { … … 981 994 * partially written VLAN is not received. 982 995 */ 983 bool rx_enabled = e1000_is_rx_enabled(e1000 _data);996 bool rx_enabled = e1000_is_rx_enabled(e1000); 984 997 if (rx_enabled) 985 e1000_disable_rx(e1000 _data);998 e1000_disable_rx(e1000); 986 999 987 1000 for (unsigned int i = 0; i < NIC_VLAN_BITMAP_SIZE; i += 4) { … … 991 1004 (((uint32_t) vlan_mask->bitmap[i + 2]) << 16) | 992 1005 (((uint32_t) vlan_mask->bitmap[i + 3]) << 24); 993 E1000_REG_WRITE(e1000 _data, E1000_VFTA_ARRAY(i / 4), bitmap_part);1006 E1000_REG_WRITE(e1000, E1000_VFTA_ARRAY(i / 4), bitmap_part); 994 1007 } 995 1008 996 e1000_enable_vlan_filter(e1000 _data);1009 e1000_enable_vlan_filter(e1000); 997 1010 if (rx_enabled) 998 e1000_enable_rx(e1000 _data);1011 e1000_enable_rx(e1000); 999 1012 } else 1000 e1000_disable_vlan_filter(e1000 _data);1001 1002 fibril_mutex_unlock(&e1000 _data->rx_lock);1013 e1000_disable_vlan_filter(e1000); 1014 1015 fibril_mutex_unlock(&e1000->rx_lock); 1003 1016 } 1004 1017 … … 1026 1039 return ENOTSUP; 1027 1040 1028 e1000_t *e1000 _data= DRIVER_DATA_DEV(device);1029 1030 e1000 _data->vlan_tag = tag;1031 e1000 _data->vlan_tag_add = add;1032 1033 fibril_mutex_lock(&e1000 _data->ctrl_lock);1034 1035 uint32_t ctrl = E1000_REG_READ(e1000 _data, E1000_CTRL);1041 e1000_t *e1000 = DRIVER_DATA_DEV(device); 1042 1043 e1000->vlan_tag = tag; 1044 e1000->vlan_tag_add = add; 1045 1046 fibril_mutex_lock(&e1000->ctrl_lock); 1047 1048 uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL); 1036 1049 if (strip) 1037 1050 ctrl |= CTRL_VME; … … 1039 1052 ctrl &= ~CTRL_VME; 1040 1053 1041 E1000_REG_WRITE(e1000 _data, E1000_CTRL, ctrl);1042 1043 fibril_mutex_unlock(&e1000 _data->ctrl_lock);1054 E1000_REG_WRITE(e1000, E1000_CTRL, ctrl); 1055 1056 fibril_mutex_unlock(&e1000->ctrl_lock); 1044 1057 return EOK; 1045 1058 } … … 1047 1060 /** Fill receive descriptor with new empty packet 1048 1061 * 1049 * Store packet in e1000_data->rx_ring_packets 1050 * 1051 * @param nic_data NIC data stricture 1052 * @param offset Receive descriptor offset 1053 * 1054 */ 1055 static void e1000_fill_new_rx_descriptor(nic_t *nic_data, unsigned int offset) 1056 { 1057 e1000_t *e1000_data = DRIVER_DATA_NIC(nic_data); 1058 packet_t *packet = nic_alloc_packet(nic_data, E1000_MAX_RECEIVE_PACKET_SIZE); 1062 * Store packet in e1000->rx_ring_packets 1063 * 1064 * @param nic NIC data stricture 1065 * @param offset Receive descriptor offset 1066 * 1067 */ 1068 static void e1000_fill_new_rx_descriptor(nic_t *nic, size_t offset) 1069 { 1070 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1071 packet_t *packet = 1072 nic_alloc_packet(nic, E1000_MAX_RECEIVE_PACKET_SIZE); 1059 1073 1060 1074 assert(packet); 1061 1075 1062 *(e1000 _data->rx_ring_packets + offset) = packet;1063 e1000_rx_descriptor_t * 1064 (e1000 _data->rx_ring.virt +1065 offset * sizeof(e1000_rx_descriptor_t));1066 1067 void *phys_addr = nic_dma_lock_packet(packet);1068 1069 if (phys_addr) {1070 rx_descriptor->phys_addr =1071 PTR_TO_U64(phys_addr+ packet->data_start);1072 }else1076 *(e1000->rx_ring_packets + offset) = packet; 1077 e1000_rx_descriptor_t *rx_descriptor = (e1000_rx_descriptor_t *) 1078 (e1000->rx_ring_virt + offset * sizeof(e1000_rx_descriptor_t)); 1079 1080 void *phys; 1081 int rc = 1082 nic_dma_lock_packet(packet, E1000_MAX_RECEIVE_PACKET_SIZE, &phys); 1083 1084 if (rc == EOK) 1085 rx_descriptor->phys_addr = PTR_TO_U64(phys + packet->data_start); 1086 else 1073 1087 rx_descriptor->phys_addr = 0; 1074 1088 … … 1082 1096 /** Clear receive descriptor 1083 1097 * 1084 * @param e1000 _dataE1000 data1085 * @param offset 1086 * 1087 */ 1088 static void e1000_clear_rx_descriptor(e1000_t *e1000 _data, unsigned int offset)1098 * @param e1000 E1000 data 1099 * @param offset Receive descriptor offset 1100 * 1101 */ 1102 static void e1000_clear_rx_descriptor(e1000_t *e1000, unsigned int offset) 1089 1103 { 1090 1104 e1000_rx_descriptor_t *rx_descriptor = (e1000_rx_descriptor_t *) 1091 (e1000_data->rx_ring.virt + 1092 offset * sizeof(e1000_rx_descriptor_t)); 1105 (e1000->rx_ring_virt + offset * sizeof(e1000_rx_descriptor_t)); 1093 1106 1094 1107 rx_descriptor->length = 0; … … 1101 1114 /** Clear receive descriptor 1102 1115 * 1103 * @param nic_data NIC data 1104 * @param offset Receive descriptor offset 1105 * 1106 */ 1107 static void e1000_clear_tx_descriptor(nic_t *nic_data, unsigned int offset) 1108 { 1109 e1000_t *e1000_data = DRIVER_DATA_NIC(nic_data); 1110 1111 e1000_tx_descriptor_t * tx_descriptor = (e1000_tx_descriptor_t *) 1112 (e1000_data->tx_ring.virt + 1113 offset * sizeof(e1000_tx_descriptor_t)); 1116 * @param nic NIC data 1117 * @param offset Receive descriptor offset 1118 * 1119 */ 1120 static void e1000_clear_tx_descriptor(nic_t *nic, unsigned int offset) 1121 { 1122 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1123 1124 e1000_tx_descriptor_t *tx_descriptor = (e1000_tx_descriptor_t *) 1125 (e1000->tx_ring_virt + offset * sizeof(e1000_tx_descriptor_t)); 1114 1126 1115 1127 if (tx_descriptor->length) { 1116 packet_t * old_packet = *(e1000_data->tx_ring_packets + offset);1128 packet_t *old_packet = *(e1000->tx_ring_packets + offset); 1117 1129 if (old_packet) 1118 nic_release_packet(nic _data, old_packet);1130 nic_release_packet(nic, old_packet); 1119 1131 } 1120 1132 … … 1146 1158 /** Receive packets 1147 1159 * 1148 * @param nic _dataNIC data1149 * 1150 */ 1151 static void e1000_receive_packets(nic_t *nic _data)1152 { 1153 e1000_t *e1000 _data = DRIVER_DATA_NIC(nic_data);1154 1155 fibril_mutex_lock(&e1000 _data->rx_lock);1156 1157 uint32_t *tail_addr = E1000_REG_ADDR(e1000 _data, E1000_RDT);1160 * @param nic NIC data 1161 * 1162 */ 1163 static void e1000_receive_packets(nic_t *nic) 1164 { 1165 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1166 1167 fibril_mutex_lock(&e1000->rx_lock); 1168 1169 uint32_t *tail_addr = E1000_REG_ADDR(e1000, E1000_RDT); 1158 1170 uint32_t next_tail = e1000_inc_tail(*tail_addr, E1000_RX_PACKETS_COUNT); 1159 1171 1160 1172 e1000_rx_descriptor_t *rx_descriptor = (e1000_rx_descriptor_t *) 1161 (e1000_data->rx_ring.virt + 1162 next_tail * sizeof(e1000_rx_descriptor_t)); 1173 (e1000->rx_ring_virt + next_tail * sizeof(e1000_rx_descriptor_t)); 1163 1174 1164 1175 while (rx_descriptor->status & 0x01) { 1165 1176 uint32_t packet_size = rx_descriptor->length - E1000_CRC_SIZE; 1166 1177 1167 packet_t *packet = *(e1000 _data->rx_ring_packets + next_tail);1178 packet_t *packet = *(e1000->rx_ring_packets + next_tail); 1168 1179 packet_suffix(packet, packet_size); 1169 1180 1170 nic_dma_unlock_packet(packet );1171 nic_received_packet(nic _data, packet);1181 nic_dma_unlock_packet(packet, E1000_MAX_RECEIVE_PACKET_SIZE); 1182 nic_received_packet(nic, packet); 1172 1183 1173 e1000_fill_new_rx_descriptor(nic _data, next_tail);1184 e1000_fill_new_rx_descriptor(nic, next_tail); 1174 1185 1175 1186 *tail_addr = e1000_inc_tail(*tail_addr, E1000_RX_PACKETS_COUNT); … … 1177 1188 1178 1189 rx_descriptor = (e1000_rx_descriptor_t *) 1179 (e1000_data->rx_ring.virt + 1180 next_tail * sizeof(e1000_rx_descriptor_t)); 1190 (e1000->rx_ring_virt + next_tail * sizeof(e1000_rx_descriptor_t)); 1181 1191 } 1182 1192 1183 fibril_mutex_unlock(&e1000 _data->rx_lock);1193 fibril_mutex_unlock(&e1000->rx_lock); 1184 1194 } 1185 1195 1186 1196 /** Enable E1000 interupts 1187 1197 * 1188 * @param e1000 _dataE1000 data structure1189 * 1190 */ 1191 static void e1000_enable_interrupts(e1000_t *e1000 _data)1192 { 1193 E1000_REG_WRITE(e1000 _data, E1000_IMS, ICR_RXT0);1198 * @param e1000 E1000 data structure 1199 * 1200 */ 1201 static void e1000_enable_interrupts(e1000_t *e1000) 1202 { 1203 E1000_REG_WRITE(e1000, E1000_IMS, ICR_RXT0); 1194 1204 } 1195 1205 1196 1206 /** Disable E1000 interupts 1197 1207 * 1198 * @param e1000 _dataE1000 data structure1199 * 1200 */ 1201 static void e1000_disable_interrupts(e1000_t *e1000 _data)1202 { 1203 E1000_REG_WRITE(e1000 _data, E1000_IMS, 0);1208 * @param e1000 E1000 data structure 1209 * 1210 */ 1211 static void e1000_disable_interrupts(e1000_t *e1000) 1212 { 1213 E1000_REG_WRITE(e1000, E1000_IMS, 0); 1204 1214 } 1205 1215 … … 1209 1219 * and e1000_poll() 1210 1220 * 1211 * @param nic _dataNIC data1212 * @param icr 1213 * 1214 */ 1215 static void e1000_interrupt_handler_impl(nic_t *nic _data, uint32_t icr)1221 * @param nic NIC data 1222 * @param icr ICR register value 1223 * 1224 */ 1225 static void e1000_interrupt_handler_impl(nic_t *nic, uint32_t icr) 1216 1226 { 1217 1227 if (icr & ICR_RXT0) 1218 e1000_receive_packets(nic _data);1228 e1000_receive_packets(nic); 1219 1229 } 1220 1230 … … 1230 1240 { 1231 1241 uint32_t icr = (uint32_t) IPC_GET_ARG2(*icall); 1232 nic_t *nic _data= NIC_DATA_DEV(dev);1233 e1000_t *e1000 _data = DRIVER_DATA_NIC(nic_data);1234 1235 e1000_interrupt_handler_impl(nic _data, icr);1236 e1000_enable_interrupts(e1000 _data);1242 nic_t *nic = NIC_DATA_DEV(dev); 1243 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1244 1245 e1000_interrupt_handler_impl(nic, icr); 1246 e1000_enable_interrupts(e1000); 1237 1247 } 1238 1248 … … 1242 1252 * structure. 1243 1253 * 1244 * @param nic _dataDriver data1254 * @param nic Driver data 1245 1255 * 1246 1256 * @return EOK if the handler was registered … … 1248 1258 * 1249 1259 */ 1250 inline static int e1000_register_int_handler(nic_t *nic _data)1251 { 1252 e1000_t *e1000 _data = DRIVER_DATA_NIC(nic_data);1260 inline static int e1000_register_int_handler(nic_t *nic) 1261 { 1262 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1253 1263 1254 1264 /* Lock the mutex in whole driver while working with global structure */ 1255 1265 fibril_mutex_lock(&irq_reg_mutex); 1256 1266 1257 // FIXME: This is not supported in mainline 1258 e1000_irq_code.cmds[0].addr = 1259 0xffff800000000000 + e1000_data->phys_reg_base + E1000_ICR; 1260 e1000_irq_code.cmds[2].addr = 1261 0xffff800000000000 + e1000_data->phys_reg_base + E1000_IMC; 1262 1263 int rc = register_interrupt_handler(nic_get_ddf_dev(nic_data), 1264 e1000_data->irq, e1000_interrupt_handler, &e1000_irq_code); 1267 e1000_irq_code.cmds[0].addr = e1000->reg_base_virt + E1000_ICR; 1268 e1000_irq_code.cmds[2].addr = e1000->reg_base_virt + E1000_IMC; 1269 1270 int rc = register_interrupt_handler(nic_get_ddf_dev(nic), 1271 e1000->irq, e1000_interrupt_handler, &e1000_irq_code); 1265 1272 1266 1273 fibril_mutex_unlock(&irq_reg_mutex); … … 1270 1277 /** Force receiving all packets in the receive buffer 1271 1278 * 1272 * @param nic _dataNIC data1273 * 1274 */ 1275 static void e1000_poll(nic_t *nic _data)1276 { 1277 assert(nic _data);1278 1279 e1000_t *e1000 _data = nic_get_specific(nic_data);1280 assert(e1000 _data);1281 1282 uint32_t icr = E1000_REG_READ(e1000 _data, E1000_ICR);1283 e1000_interrupt_handler_impl(nic _data, icr);1279 * @param nic NIC data 1280 * 1281 */ 1282 static void e1000_poll(nic_t *nic) 1283 { 1284 assert(nic); 1285 1286 e1000_t *e1000 = nic_get_specific(nic); 1287 assert(e1000); 1288 1289 uint32_t icr = E1000_REG_READ(e1000, E1000_ICR); 1290 e1000_interrupt_handler_impl(nic, icr); 1284 1291 } 1285 1292 … … 1305 1312 * 1306 1313 */ 1307 static int e1000_poll_mode_change(nic_t *nic _data, nic_poll_mode_t mode,1314 static int e1000_poll_mode_change(nic_t *nic, nic_poll_mode_t mode, 1308 1315 const struct timeval *period) 1309 1316 { 1310 assert(nic _data);1311 1312 e1000_t *e1000 _data = nic_get_specific(nic_data);1313 assert(e1000 _data);1317 assert(nic); 1318 1319 e1000_t *e1000 = nic_get_specific(nic); 1320 assert(e1000); 1314 1321 1315 1322 switch (mode) { 1316 1323 case NIC_POLL_IMMEDIATE: 1317 E1000_REG_WRITE(e1000 _data, E1000_ITR, 0);1318 e1000_enable_interrupts(e1000 _data);1324 E1000_REG_WRITE(e1000, E1000_ITR, 0); 1325 e1000_enable_interrupts(e1000); 1319 1326 break; 1320 1327 case NIC_POLL_ON_DEMAND: 1321 e1000_disable_interrupts(e1000 _data);1328 e1000_disable_interrupts(e1000); 1322 1329 break; 1323 1330 case NIC_POLL_PERIODIC: 1324 1331 assert(period); 1325 1332 uint16_t itr_interval = e1000_calculate_itr_interval(period); 1326 E1000_REG_WRITE(e1000 _data, E1000_ITR, (uint32_t) itr_interval);1327 e1000_enable_interrupts(e1000 _data);1333 E1000_REG_WRITE(e1000, E1000_ITR, (uint32_t) itr_interval); 1334 e1000_enable_interrupts(e1000); 1328 1335 break; 1329 1336 default: … … 1336 1343 /** Initialize receive registers 1337 1344 * 1338 * @param e1000 _dataE1000 data structure1339 * 1340 */ 1341 static void e1000_initialize_rx_registers(e1000_t * e1000_data)1342 { 1343 E1000_REG_WRITE(e1000 _data, E1000_RDLEN, E1000_RX_PACKETS_COUNT * 16);1344 E1000_REG_WRITE(e1000 _data, E1000_RDH, 0);1345 * @param e1000 E1000 data structure 1346 * 1347 */ 1348 static void e1000_initialize_rx_registers(e1000_t *e1000) 1349 { 1350 E1000_REG_WRITE(e1000, E1000_RDLEN, E1000_RX_PACKETS_COUNT * 16); 1351 E1000_REG_WRITE(e1000, E1000_RDH, 0); 1345 1352 1346 1353 /* It is not posible to let HW use all descriptors */ 1347 E1000_REG_WRITE(e1000 _data, E1000_RDT, E1000_RX_PACKETS_COUNT - 1);1354 E1000_REG_WRITE(e1000, E1000_RDT, E1000_RX_PACKETS_COUNT - 1); 1348 1355 1349 1356 /* Set Broadcast Enable Bit */ 1350 E1000_REG_WRITE(e1000 _data, E1000_RCTL, RCTL_BAM);1357 E1000_REG_WRITE(e1000, E1000_RCTL, RCTL_BAM); 1351 1358 } 1352 1359 1353 1360 /** Initialize receive structure 1354 1361 * 1355 * @param nic _dataNIC data1362 * @param nic NIC data 1356 1363 * 1357 1364 * @return EOK if succeed … … 1359 1366 * 1360 1367 */ 1361 static int e1000_initialize_rx_structure(nic_t *nic_data) 1362 { 1363 e1000_t *e1000_data = DRIVER_DATA_NIC(nic_data); 1364 fibril_mutex_lock(&e1000_data->rx_lock); 1365 1366 int rc = dmamem_map(&e1000_data->rx_ring, 1367 SIZE2PAGES(E1000_RX_PACKETS_COUNT * sizeof(e1000_rx_descriptor_t)), 1368 AS_AREA_READ | AS_AREA_WRITE, 0); 1368 static int e1000_initialize_rx_structure(nic_t *nic) 1369 { 1370 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1371 fibril_mutex_lock(&e1000->rx_lock); 1372 1373 int rc = dmamem_map_anonymous( 1374 E1000_RX_PACKETS_COUNT * sizeof(e1000_rx_descriptor_t), 1375 AS_AREA_READ | AS_AREA_WRITE, 0, &e1000->rx_ring_phys, 1376 &e1000->rx_ring_virt); 1369 1377 if (rc != EOK) 1370 1378 return rc; 1371 1379 1372 E1000_REG_WRITE(e1000 _data, E1000_RDBAH,1373 (uint32_t) (PTR_TO_U64(e1000 _data->rx_ring.phys) >> 32));1374 E1000_REG_WRITE(e1000 _data, E1000_RDBAL,1375 (uint32_t) PTR_TO_U64(e1000 _data->rx_ring.phys));1376 1377 e1000 _data->rx_ring_packets =1380 E1000_REG_WRITE(e1000, E1000_RDBAH, 1381 (uint32_t) (PTR_TO_U64(e1000->rx_ring_phys) >> 32)); 1382 E1000_REG_WRITE(e1000, E1000_RDBAL, 1383 (uint32_t) PTR_TO_U64(e1000->rx_ring_phys)); 1384 1385 e1000->rx_ring_packets = 1378 1386 malloc(E1000_RX_PACKETS_COUNT * sizeof(packet_t *)); 1379 1387 // FIXME: Check return value … … 1383 1391 offset < E1000_RX_PACKETS_COUNT; 1384 1392 offset++) 1385 e1000_fill_new_rx_descriptor(nic _data, offset);1386 1387 e1000_initialize_rx_registers(e1000 _data);1388 1389 fibril_mutex_unlock(&e1000 _data->rx_lock);1393 e1000_fill_new_rx_descriptor(nic, offset); 1394 1395 e1000_initialize_rx_registers(e1000); 1396 1397 fibril_mutex_unlock(&e1000->rx_lock); 1390 1398 return EOK; 1391 1399 } … … 1393 1401 /** Uninitialize receive structure 1394 1402 * 1395 * @param nic _dataNIC data1396 * 1397 */ 1398 static void e1000_uninitialize_rx_structure(nic_t *nic _data)1399 { 1400 e1000_t *e1000 _data = DRIVER_DATA_NIC(nic_data);1403 * @param nic NIC data 1404 * 1405 */ 1406 static void e1000_uninitialize_rx_structure(nic_t *nic) 1407 { 1408 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1401 1409 1402 1410 /* Write descriptor */ … … 1404 1412 offset < E1000_RX_PACKETS_COUNT; 1405 1413 offset++) { 1406 packet_t *packet = *(e1000 _data->rx_ring_packets + offset);1407 nic_dma_unlock_packet(packet );1408 nic_release_packet(nic _data, packet);1414 packet_t *packet = *(e1000->rx_ring_packets + offset); 1415 nic_dma_unlock_packet(packet, E1000_MAX_RECEIVE_PACKET_SIZE); 1416 nic_release_packet(nic, packet); 1409 1417 } 1410 1418 1411 free(e1000 _data->rx_ring_packets);1412 dmamem_unmap (&e1000_data->rx_ring);1419 free(e1000->rx_ring_packets); 1420 dmamem_unmap_anonymous(e1000->rx_ring_virt); 1413 1421 } 1414 1422 1415 1423 /** Clear receive descriptor ring 1416 1424 * 1417 * @param e1000 _dataE1000 data1418 * 1419 */ 1420 static void e1000_clear_rx_ring(e1000_t * e1000_data)1425 * @param e1000 E1000 data 1426 * 1427 */ 1428 static void e1000_clear_rx_ring(e1000_t *e1000) 1421 1429 { 1422 1430 /* Write descriptor */ … … 1424 1432 offset < E1000_RX_PACKETS_COUNT; 1425 1433 offset++) 1426 e1000_clear_rx_descriptor(e1000 _data, offset);1434 e1000_clear_rx_descriptor(e1000, offset); 1427 1435 } 1428 1436 1429 1437 /** Initialize filters 1430 1438 * 1431 * @param e1000 _dataE1000 data1432 * 1433 */ 1434 static void e1000_initialize_filters(e1000_t *e1000 _data)1439 * @param e1000 E1000 data 1440 * 1441 */ 1442 static void e1000_initialize_filters(e1000_t *e1000) 1435 1443 { 1436 1444 /* Initialize address filter */ 1437 e1000 _data->unicast_ra_count = 0;1438 e1000 _data->multicast_ra_count = 0;1439 e1000_clear_unicast_receive_addresses(e1000 _data);1445 e1000->unicast_ra_count = 0; 1446 e1000->multicast_ra_count = 0; 1447 e1000_clear_unicast_receive_addresses(e1000); 1440 1448 } 1441 1449 1442 1450 /** Initialize VLAN 1443 1451 * 1444 * @param e1000 _dataE1000 data1445 * 1446 */ 1447 static void e1000_initialize_vlan(e1000_t *e1000 _data)1448 { 1449 e1000 _data->vlan_tag_add = false;1452 * @param e1000 E1000 data 1453 * 1454 */ 1455 static void e1000_initialize_vlan(e1000_t *e1000) 1456 { 1457 e1000->vlan_tag_add = false; 1450 1458 } 1451 1459 1452 1460 /** Fill MAC address from EEPROM to RA[0] register 1453 1461 * 1454 * @param e1000 _dataE1000 data1455 * 1456 */ 1457 static void e1000_fill_mac_from_eeprom(e1000_t *e1000 _data)1462 * @param e1000 E1000 data 1463 * 1464 */ 1465 static void e1000_fill_mac_from_eeprom(e1000_t *e1000) 1458 1466 { 1459 1467 /* MAC address from eeprom to RA[0] */ 1460 1468 nic_address_t address; 1461 e1000_eeprom_get_address(e1000 _data, &address);1462 e1000_write_receive_address(e1000 _data, 0, &address, true);1469 e1000_eeprom_get_address(e1000, &address); 1470 e1000_write_receive_address(e1000, 0, &address, true); 1463 1471 } 1464 1472 … … 1471 1479 * 1472 1480 */ 1473 static void e1000_initialize_registers(e1000_t *e1000 _data)1474 { 1475 E1000_REG_WRITE(e1000 _data, E1000_ITR,1481 static void e1000_initialize_registers(e1000_t *e1000) 1482 { 1483 E1000_REG_WRITE(e1000, E1000_ITR, 1476 1484 e1000_calculate_itr_interval_from_usecs( 1477 1485 E1000_DEFAULT_INTERRUPT_INTERVAL_USEC)); 1478 E1000_REG_WRITE(e1000 _data, E1000_FCAH, 0);1479 E1000_REG_WRITE(e1000 _data, E1000_FCAL, 0);1480 E1000_REG_WRITE(e1000 _data, E1000_FCT, 0);1481 E1000_REG_WRITE(e1000 _data, E1000_FCTTV, 0);1482 E1000_REG_WRITE(e1000 _data, E1000_VET, VET_VALUE);1483 E1000_REG_WRITE(e1000 _data, E1000_CTRL, CTRL_ASDE);1486 E1000_REG_WRITE(e1000, E1000_FCAH, 0); 1487 E1000_REG_WRITE(e1000, E1000_FCAL, 0); 1488 E1000_REG_WRITE(e1000, E1000_FCT, 0); 1489 E1000_REG_WRITE(e1000, E1000_FCTTV, 0); 1490 E1000_REG_WRITE(e1000, E1000_VET, VET_VALUE); 1491 E1000_REG_WRITE(e1000, E1000_CTRL, CTRL_ASDE); 1484 1492 } 1485 1493 1486 1494 /** Initialize transmit registers 1487 1495 * 1488 * @param e1000 _dataE1000 data.1489 * 1490 */ 1491 static void e1000_initialize_tx_registers(e1000_t *e1000 _data)1492 { 1493 E1000_REG_WRITE(e1000 _data, E1000_TDLEN, E1000_TX_PACKETS_COUNT * 16);1494 E1000_REG_WRITE(e1000 _data, E1000_TDH, 0);1495 E1000_REG_WRITE(e1000 _data, E1000_TDT, 0);1496 1497 E1000_REG_WRITE(e1000 _data, E1000_TIPG,1496 * @param e1000 E1000 data. 1497 * 1498 */ 1499 static void e1000_initialize_tx_registers(e1000_t *e1000) 1500 { 1501 E1000_REG_WRITE(e1000, E1000_TDLEN, E1000_TX_PACKETS_COUNT * 16); 1502 E1000_REG_WRITE(e1000, E1000_TDH, 0); 1503 E1000_REG_WRITE(e1000, E1000_TDT, 0); 1504 1505 E1000_REG_WRITE(e1000, E1000_TIPG, 1498 1506 10 << TIPG_IPGT_SHIFT | 1499 1507 8 << TIPG_IPGR1_SHIFT | 1500 1508 6 << TIPG_IPGR2_SHIFT); 1501 1509 1502 E1000_REG_WRITE(e1000 _data, E1000_TCTL,1510 E1000_REG_WRITE(e1000, E1000_TCTL, 1503 1511 0x0F << TCTL_CT_SHIFT /* Collision Threshold */ | 1504 1512 0x40 << TCTL_COLD_SHIFT /* Collision Distance */ | … … 1508 1516 /** Initialize transmit structure 1509 1517 * 1510 * @param e1000_data E1000 data. 1511 * 1512 */ 1513 static int e1000_initialize_tx_structure(e1000_t *e1000_data) 1514 { 1515 fibril_mutex_lock(&e1000_data->tx_lock); 1516 1517 int rc = dmamem_map(&e1000_data->tx_ring, 1518 SIZE2PAGES(E1000_TX_PACKETS_COUNT * sizeof(e1000_tx_descriptor_t)), 1519 AS_AREA_READ | AS_AREA_WRITE, 0); 1518 * @param e1000 E1000 data. 1519 * 1520 */ 1521 static int e1000_initialize_tx_structure(e1000_t *e1000) 1522 { 1523 fibril_mutex_lock(&e1000->tx_lock); 1524 1525 int rc = dmamem_map_anonymous( 1526 E1000_TX_PACKETS_COUNT * sizeof(e1000_tx_descriptor_t), 1527 AS_AREA_READ | AS_AREA_WRITE, 0, &e1000->tx_ring_phys, 1528 &e1000->tx_ring_virt); 1520 1529 if (rc != EOK) 1521 1530 return rc; 1522 1531 1523 bzero(e1000 _data->tx_ring.virt,1532 bzero(e1000->tx_ring_virt, 1524 1533 E1000_TX_PACKETS_COUNT * sizeof(e1000_tx_descriptor_t)); 1525 1534 1526 E1000_REG_WRITE(e1000 _data, E1000_TDBAH,1527 (uint32_t) (PTR_TO_U64(e1000 _data->tx_ring.phys) >> 32));1528 E1000_REG_WRITE(e1000 _data, E1000_TDBAL,1529 (uint32_t) PTR_TO_U64(e1000 _data->tx_ring.phys));1530 1531 e1000 _data->tx_ring_packets =1535 E1000_REG_WRITE(e1000, E1000_TDBAH, 1536 (uint32_t) (PTR_TO_U64(e1000->tx_ring_phys) >> 32)); 1537 E1000_REG_WRITE(e1000, E1000_TDBAL, 1538 (uint32_t) PTR_TO_U64(e1000->tx_ring_phys)); 1539 1540 e1000->tx_ring_packets = 1532 1541 malloc(E1000_TX_PACKETS_COUNT * sizeof(packet_t *)); 1533 1542 // FIXME: Check return value 1534 1543 1535 e1000_initialize_tx_registers(e1000 _data);1536 1537 fibril_mutex_unlock(&e1000 _data->tx_lock);1544 e1000_initialize_tx_registers(e1000); 1545 1546 fibril_mutex_unlock(&e1000->tx_lock); 1538 1547 return EOK; 1539 1548 } … … 1541 1550 /** Uninitialize transmit structure 1542 1551 * 1543 * @param nic _dataNIC data1544 * 1545 */ 1546 static void e1000_uninitialize_tx_structure(e1000_t *e1000 _data)1547 { 1548 free(e1000 _data->tx_ring_packets);1549 dmamem_unmap (&e1000_data->tx_ring);1552 * @param nic NIC data 1553 * 1554 */ 1555 static void e1000_uninitialize_tx_structure(e1000_t *e1000) 1556 { 1557 free(e1000->tx_ring_packets); 1558 dmamem_unmap_anonymous(e1000->tx_ring_virt); 1550 1559 } 1551 1560 1552 1561 /** Clear transmit descriptor ring 1553 1562 * 1554 * @param nic _dataNIC data1555 * 1556 */ 1557 static void e1000_clear_tx_ring(nic_t *nic _data)1563 * @param nic NIC data 1564 * 1565 */ 1566 static void e1000_clear_tx_ring(nic_t *nic) 1558 1567 { 1559 1568 /* Write descriptor */ … … 1561 1570 offset < E1000_TX_PACKETS_COUNT; 1562 1571 offset++) 1563 e1000_clear_tx_descriptor(nic _data, offset);1572 e1000_clear_tx_descriptor(nic, offset); 1564 1573 } 1565 1574 1566 1575 /** Enable transmit 1567 1576 * 1568 * @param e1000 _dataE1000 data1569 * 1570 */ 1571 static void e1000_enable_tx(e1000_t *e1000 _data)1577 * @param e1000 E1000 data 1578 * 1579 */ 1580 static void e1000_enable_tx(e1000_t *e1000) 1572 1581 { 1573 1582 /* Set Transmit Enable Bit */ 1574 E1000_REG_WRITE(e1000 _data, E1000_TCTL,1575 E1000_REG_READ(e1000 _data, E1000_TCTL) | (TCTL_EN));1583 E1000_REG_WRITE(e1000, E1000_TCTL, 1584 E1000_REG_READ(e1000, E1000_TCTL) | (TCTL_EN)); 1576 1585 } 1577 1586 1578 1587 /** Disable transmit 1579 1588 * 1580 * @param e1000 _dataE1000 data1581 * 1582 */ 1583 static void e1000_disable_tx(e1000_t *e1000 _data)1589 * @param e1000 E1000 data 1590 * 1591 */ 1592 static void e1000_disable_tx(e1000_t *e1000) 1584 1593 { 1585 1594 /* Clear Transmit Enable Bit */ 1586 E1000_REG_WRITE(e1000 _data, E1000_TCTL,1587 E1000_REG_READ(e1000 _data, E1000_TCTL) & ~(TCTL_EN));1595 E1000_REG_WRITE(e1000, E1000_TCTL, 1596 E1000_REG_READ(e1000, E1000_TCTL) & ~(TCTL_EN)); 1588 1597 } 1589 1598 1590 1599 /** Reset E1000 device 1591 1600 * 1592 * @param e1000 _dataThe E1000 data1593 * 1594 */ 1595 static int e1000_reset(nic_t *nic _data)1596 { 1597 e1000_t *e1000 _data = DRIVER_DATA_NIC(nic_data);1598 1599 E1000_REG_WRITE(e1000 _data, E1000_CTRL, CTRL_RST);1601 * @param e1000 The E1000 data 1602 * 1603 */ 1604 static int e1000_reset(nic_t *nic) 1605 { 1606 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1607 1608 E1000_REG_WRITE(e1000, E1000_CTRL, CTRL_RST); 1600 1609 1601 1610 /* Wait for the reset */ … … 1603 1612 1604 1613 /* check if RST_BIT cleared */ 1605 if (E1000_REG_READ(e1000 _data, E1000_CTRL) & (CTRL_RST))1614 if (E1000_REG_READ(e1000, E1000_CTRL) & (CTRL_RST)) 1606 1615 return EINVAL; 1607 1616 1608 e1000_initialize_registers(e1000 _data);1609 e1000_initialize_rx_registers(e1000 _data);1610 e1000_initialize_tx_registers(e1000 _data);1611 e1000_fill_mac_from_eeprom(e1000 _data);1612 e1000_initialize_filters(e1000 _data);1613 e1000_initialize_vlan(e1000 _data);1617 e1000_initialize_registers(e1000); 1618 e1000_initialize_rx_registers(e1000); 1619 e1000_initialize_tx_registers(e1000); 1620 e1000_fill_mac_from_eeprom(e1000); 1621 e1000_initialize_filters(e1000); 1622 e1000_initialize_vlan(e1000); 1614 1623 1615 1624 return EOK; … … 1618 1627 /** Activate the device to receive and transmit packets 1619 1628 * 1620 * @param nic _dataNIC driver data1629 * @param nic NIC driver data 1621 1630 * 1622 1631 * @return EOK if activated successfully … … 1624 1633 * 1625 1634 */ 1626 static int e1000_on_activating(nic_t *nic _data)1627 { 1628 assert(nic _data);1629 1630 e1000_t *e1000 _data = DRIVER_DATA_NIC(nic_data);1631 1632 fibril_mutex_lock(&e1000 _data->rx_lock);1633 fibril_mutex_lock(&e1000 _data->tx_lock);1634 fibril_mutex_lock(&e1000 _data->ctrl_lock);1635 1636 e1000_enable_interrupts(e1000 _data);1637 1638 nic_enable_interrupt(nic _data, e1000_data->irq);1639 1640 e1000_clear_rx_ring(e1000 _data);1641 e1000_enable_rx(e1000 _data);1642 1643 e1000_clear_tx_ring(nic _data);1644 e1000_enable_tx(e1000 _data);1645 1646 uint32_t ctrl = E1000_REG_READ(e1000 _data, E1000_CTRL);1635 static int e1000_on_activating(nic_t *nic) 1636 { 1637 assert(nic); 1638 1639 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1640 1641 fibril_mutex_lock(&e1000->rx_lock); 1642 fibril_mutex_lock(&e1000->tx_lock); 1643 fibril_mutex_lock(&e1000->ctrl_lock); 1644 1645 e1000_enable_interrupts(e1000); 1646 1647 nic_enable_interrupt(nic, e1000->irq); 1648 1649 e1000_clear_rx_ring(e1000); 1650 e1000_enable_rx(e1000); 1651 1652 e1000_clear_tx_ring(nic); 1653 e1000_enable_tx(e1000); 1654 1655 uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL); 1647 1656 ctrl |= CTRL_SLU; 1648 E1000_REG_WRITE(e1000 _data, E1000_CTRL, ctrl);1649 1650 fibril_mutex_unlock(&e1000 _data->ctrl_lock);1651 fibril_mutex_unlock(&e1000 _data->tx_lock);1652 fibril_mutex_unlock(&e1000 _data->rx_lock);1657 E1000_REG_WRITE(e1000, E1000_CTRL, ctrl); 1658 1659 fibril_mutex_unlock(&e1000->ctrl_lock); 1660 fibril_mutex_unlock(&e1000->tx_lock); 1661 fibril_mutex_unlock(&e1000->rx_lock); 1653 1662 1654 1663 return EOK; … … 1657 1666 /** Callback for NIC_STATE_DOWN change 1658 1667 * 1659 * @param nic _dataNIC driver data1668 * @param nic NIC driver data 1660 1669 * 1661 1670 * @return EOK if succeed … … 1663 1672 * 1664 1673 */ 1665 static int e1000_on_down_unlocked(nic_t *nic _data)1666 { 1667 e1000_t *e1000 _data = DRIVER_DATA_NIC(nic_data);1668 1669 uint32_t ctrl = E1000_REG_READ(e1000 _data, E1000_CTRL);1674 static int e1000_on_down_unlocked(nic_t *nic) 1675 { 1676 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1677 1678 uint32_t ctrl = E1000_REG_READ(e1000, E1000_CTRL); 1670 1679 ctrl &= ~CTRL_SLU; 1671 E1000_REG_WRITE(e1000 _data, E1000_CTRL, ctrl);1672 1673 e1000_disable_tx(e1000 _data);1674 e1000_disable_rx(e1000 _data);1675 1676 nic_disable_interrupt(nic _data, e1000_data->irq);1677 e1000_disable_interrupts(e1000 _data);1680 E1000_REG_WRITE(e1000, E1000_CTRL, ctrl); 1681 1682 e1000_disable_tx(e1000); 1683 e1000_disable_rx(e1000); 1684 1685 nic_disable_interrupt(nic, e1000->irq); 1686 e1000_disable_interrupts(e1000); 1678 1687 1679 1688 /* … … 1688 1697 /** Callback for NIC_STATE_DOWN change 1689 1698 * 1690 * @param nic _dataNIC driver data1699 * @param nic NIC driver data 1691 1700 * 1692 1701 * @return EOK if succeed … … 1694 1703 * 1695 1704 */ 1696 static int e1000_on_down(nic_t *nic _data)1697 { 1698 e1000_t *e1000 _data = DRIVER_DATA_NIC(nic_data);1699 1700 fibril_mutex_lock(&e1000 _data->rx_lock);1701 fibril_mutex_lock(&e1000 _data->tx_lock);1702 fibril_mutex_lock(&e1000 _data->ctrl_lock);1703 1704 int rc = e1000_on_down_unlocked(nic _data);1705 1706 fibril_mutex_unlock(&e1000 _data->ctrl_lock);1707 fibril_mutex_unlock(&e1000 _data->tx_lock);1708 fibril_mutex_unlock(&e1000 _data->rx_lock);1705 static int e1000_on_down(nic_t *nic) 1706 { 1707 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1708 1709 fibril_mutex_lock(&e1000->rx_lock); 1710 fibril_mutex_lock(&e1000->tx_lock); 1711 fibril_mutex_lock(&e1000->ctrl_lock); 1712 1713 int rc = e1000_on_down_unlocked(nic); 1714 1715 fibril_mutex_unlock(&e1000->ctrl_lock); 1716 fibril_mutex_unlock(&e1000->tx_lock); 1717 fibril_mutex_unlock(&e1000->rx_lock); 1709 1718 1710 1719 return rc; … … 1713 1722 /** Callback for NIC_STATE_STOPPED change 1714 1723 * 1715 * @param nic _dataNIC driver data1724 * @param nic NIC driver data 1716 1725 * 1717 1726 * @return EOK if succeed … … 1719 1728 * 1720 1729 */ 1721 static int e1000_on_stopping(nic_t *nic _data)1722 { 1723 e1000_t *e1000 _data = DRIVER_DATA_NIC(nic_data);1724 1725 fibril_mutex_lock(&e1000 _data->rx_lock);1726 fibril_mutex_lock(&e1000 _data->tx_lock);1727 fibril_mutex_lock(&e1000 _data->ctrl_lock);1728 1729 int rc = e1000_on_down_unlocked(nic _data);1730 static int e1000_on_stopping(nic_t *nic) 1731 { 1732 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1733 1734 fibril_mutex_lock(&e1000->rx_lock); 1735 fibril_mutex_lock(&e1000->tx_lock); 1736 fibril_mutex_lock(&e1000->ctrl_lock); 1737 1738 int rc = e1000_on_down_unlocked(nic); 1730 1739 if (rc == EOK) 1731 rc = e1000_reset(nic _data);1732 1733 fibril_mutex_unlock(&e1000 _data->ctrl_lock);1734 fibril_mutex_unlock(&e1000 _data->tx_lock);1735 fibril_mutex_unlock(&e1000 _data->rx_lock);1740 rc = e1000_reset(nic); 1741 1742 fibril_mutex_unlock(&e1000->ctrl_lock); 1743 fibril_mutex_unlock(&e1000->tx_lock); 1744 fibril_mutex_unlock(&e1000->rx_lock); 1736 1745 1737 1746 return rc; … … 1748 1757 assert(!dev->driver_data); 1749 1758 1750 nic_t *nic _data= nic_create_and_bind(dev);1751 if (!nic _data)1759 nic_t *nic = nic_create_and_bind(dev); 1760 if (!nic) 1752 1761 return NULL; 1753 1762 1754 e1000_t *e1000 _data= malloc(sizeof(e1000_t));1755 if (!e1000 _data) {1763 e1000_t *e1000 = malloc(sizeof(e1000_t)); 1764 if (!e1000) { 1756 1765 nic_unbind_and_destroy(dev); 1757 1766 return NULL; 1758 1767 } 1759 1768 1760 bzero(e1000 _data, sizeof(e1000_t));1761 1762 nic_set_specific(nic _data, e1000_data);1763 nic_set_write_packet_handler(nic _data, e1000_write_packet);1764 nic_set_state_change_handlers(nic _data, e1000_on_activating,1769 bzero(e1000, sizeof(e1000_t)); 1770 1771 nic_set_specific(nic, e1000); 1772 nic_set_write_packet_handler(nic, e1000_write_packet); 1773 nic_set_state_change_handlers(nic, e1000_on_activating, 1765 1774 e1000_on_down, e1000_on_stopping); 1766 nic_set_filtering_change_handlers(nic _data,1775 nic_set_filtering_change_handlers(nic, 1767 1776 e1000_on_unicast_mode_change, e1000_on_multicast_mode_change, 1768 1777 e1000_on_broadcast_mode_change, NULL, e1000_on_vlan_mask_change); 1769 nic_set_poll_handlers(nic _data, e1000_poll_mode_change, e1000_poll);1770 1771 fibril_mutex_initialize(&e1000 _data->ctrl_lock);1772 fibril_mutex_initialize(&e1000 _data->rx_lock);1773 fibril_mutex_initialize(&e1000 _data->tx_lock);1774 fibril_mutex_initialize(&e1000 _data->eeprom_lock);1775 1776 return e1000 _data;1778 nic_set_poll_handlers(nic, e1000_poll_mode_change, e1000_poll); 1779 1780 fibril_mutex_initialize(&e1000->ctrl_lock); 1781 fibril_mutex_initialize(&e1000->rx_lock); 1782 fibril_mutex_initialize(&e1000->tx_lock); 1783 fibril_mutex_initialize(&e1000->eeprom_lock); 1784 1785 return e1000; 1777 1786 } 1778 1787 … … 1825 1834 assert(dev->driver_data != NULL); 1826 1835 1827 e1000_t *e1000 _data= DRIVER_DATA_DEV(dev);1836 e1000_t *e1000 = DRIVER_DATA_DEV(dev); 1828 1837 1829 1838 if (hw_resources->irqs.count != 1) 1830 1839 return EINVAL; 1831 1840 1832 e1000 _data->irq = hw_resources->irqs.irqs[0];1833 e1000 _data->phys_reg_base=1841 e1000->irq = hw_resources->irqs.irqs[0]; 1842 e1000->reg_base_phys = 1834 1843 MEMADDR_TO_PTR(hw_resources->mem_ranges.ranges[0].address); 1835 1844 … … 1878 1887 { 1879 1888 /* Allocate driver data for the device. */ 1880 e1000_t *e1000 _data= e1000_create_dev_data(dev);1881 if (e1000 _data== NULL)1889 e1000_t *e1000 = e1000_create_dev_data(dev); 1890 if (e1000 == NULL) 1882 1891 return ENOMEM; 1883 1892 … … 1890 1899 1891 1900 rc = pci_config_space_read_16(dev->parent_sess, PCI_DEVICE_ID, 1892 &e1000 _data->device_id);1901 &e1000->device_id); 1893 1902 if (rc != EOK) { 1894 1903 e1000_dev_cleanup(dev); … … 1909 1918 static int e1000_pio_enable(ddf_dev_t *dev) 1910 1919 { 1911 e1000_t *e1000 _data= DRIVER_DATA_DEV(dev);1912 1913 int rc = pio_enable(e1000 _data->phys_reg_base, 8 * PAGE_SIZE,1914 &e1000 _data->virt_reg_base);1920 e1000_t *e1000 = DRIVER_DATA_DEV(dev); 1921 1922 int rc = pio_enable(e1000->reg_base_phys, 8 * PAGE_SIZE, 1923 &e1000->reg_base_virt); 1915 1924 if (rc != EOK) 1916 1925 return EADDRNOTAVAIL; … … 1934 1943 1935 1944 /* Device initialization */ 1936 nic_t *nic _data= dev->driver_data;1937 e1000_t *e1000 _data = DRIVER_DATA_NIC(nic_data);1945 nic_t *nic = dev->driver_data; 1946 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1938 1947 1939 1948 /* Map registers */ … … 1942 1951 goto err_destroy; 1943 1952 1944 e1000_initialize_registers(e1000 _data);1945 rc = e1000_initialize_tx_structure(e1000 _data);1953 e1000_initialize_registers(e1000); 1954 rc = e1000_initialize_tx_structure(e1000); 1946 1955 if (rc != EOK) 1947 1956 goto err_pio; 1948 1957 1949 fibril_mutex_lock(&e1000 _data->rx_lock);1950 1951 e1000_fill_mac_from_eeprom(e1000 _data);1952 e1000_initialize_filters(e1000 _data);1953 1954 fibril_mutex_unlock(&e1000 _data->rx_lock);1955 1956 e1000_initialize_vlan(e1000 _data);1957 1958 rc = nic_register_as_ddf_fun(nic _data, &e1000_dev_ops);1958 fibril_mutex_lock(&e1000->rx_lock); 1959 1960 e1000_fill_mac_from_eeprom(e1000); 1961 e1000_initialize_filters(e1000); 1962 1963 fibril_mutex_unlock(&e1000->rx_lock); 1964 1965 e1000_initialize_vlan(e1000); 1966 1967 rc = nic_register_as_ddf_fun(nic, &e1000_dev_ops); 1959 1968 if (rc != EOK) 1960 1969 goto err_tx_structure; 1961 1970 1962 rc = e1000_register_int_handler(nic _data);1971 rc = e1000_register_int_handler(nic); 1963 1972 if (rc != EOK) 1964 1973 goto err_tx_structure; 1965 1974 1966 rc = nic_connect_to_services(nic _data);1975 rc = nic_connect_to_services(nic); 1967 1976 if (rc != EOK) 1968 1977 goto err_irq; 1969 1978 1970 rc = e1000_initialize_rx_structure(nic _data);1979 rc = e1000_initialize_rx_structure(nic); 1971 1980 if (rc != EOK) 1972 1981 goto err_irq; 1973 1982 1974 1983 nic_address_t e1000_address; 1975 e1000_get_address(e1000 _data, &e1000_address);1976 rc = nic_report_address(nic _data, &e1000_address);1984 e1000_get_address(e1000, &e1000_address); 1985 rc = nic_report_address(nic, &e1000_address); 1977 1986 if (rc != EOK) 1978 1987 goto err_rx_structure; … … 1981 1990 period.tv_sec = 0; 1982 1991 period.tv_usec = E1000_DEFAULT_INTERRUPT_INTERVAL_USEC; 1983 rc = nic_report_poll_mode(nic _data, NIC_POLL_PERIODIC, &period);1992 rc = nic_report_poll_mode(nic, NIC_POLL_PERIODIC, &period); 1984 1993 if (rc != EOK) 1985 1994 goto err_rx_structure; … … 1988 1997 1989 1998 err_rx_structure: 1990 e1000_uninitialize_rx_structure(nic _data);1999 e1000_uninitialize_rx_structure(nic); 1991 2000 err_irq: 1992 2001 unregister_interrupt_handler(dev, DRIVER_DATA_DEV(dev)->irq); 1993 2002 err_tx_structure: 1994 e1000_uninitialize_tx_structure(e1000 _data);2003 e1000_uninitialize_tx_structure(e1000); 1995 2004 err_pio: 1996 2005 // TODO: e1000_pio_disable(dev); … … 2010 2019 * 2011 2020 */ 2012 static uint16_t e1000_eeprom_read(e1000_t *e1000 _data, uint8_t eeprom_address)2013 { 2014 fibril_mutex_lock(&e1000 _data->eeprom_lock);2021 static uint16_t e1000_eeprom_read(e1000_t *e1000, uint8_t eeprom_address) 2022 { 2023 fibril_mutex_lock(&e1000->eeprom_lock); 2015 2024 2016 2025 uint32_t eerd_done; 2017 2026 uint32_t eerd_address_offset; 2018 2027 2019 switch (e1000 _data->device_id) {2028 switch (e1000->device_id) { 2020 2029 case 0x107c: 2021 2030 case 0x1013: … … 2040 2049 uint32_t write_data = EERD_START | 2041 2050 (((uint32_t) eeprom_address) << eerd_address_offset); 2042 E1000_REG_WRITE(e1000 _data, E1000_EERD, write_data);2043 2044 uint32_t eerd = E1000_REG_READ(e1000 _data, E1000_EERD);2051 E1000_REG_WRITE(e1000, E1000_EERD, write_data); 2052 2053 uint32_t eerd = E1000_REG_READ(e1000, E1000_EERD); 2045 2054 while ((eerd & eerd_done) == 0) { 2046 2055 usleep(1); 2047 eerd = E1000_REG_READ(e1000 _data, E1000_EERD);2056 eerd = E1000_REG_READ(e1000, E1000_EERD); 2048 2057 } 2049 2058 2050 fibril_mutex_unlock(&e1000 _data->eeprom_lock);2059 fibril_mutex_unlock(&e1000->eeprom_lock); 2051 2060 2052 2061 return (uint16_t) (eerd >> EERD_DATA_OFFSET); … … 2063 2072 * 2064 2073 */ 2065 static int e1000_get_address(e1000_t *e1000 _data, nic_address_t *address)2066 { 2067 fibril_mutex_lock(&e1000 _data->rx_lock);2074 static int e1000_get_address(e1000_t *e1000, nic_address_t *address) 2075 { 2076 fibril_mutex_lock(&e1000->rx_lock); 2068 2077 2069 2078 uint8_t *mac0_dest = (uint8_t *) address->address; … … 2074 2083 uint8_t *mac5_dest = (uint8_t *) address->address + 5; 2075 2084 2076 uint32_t rah = E1000_REG_READ(e1000 _data, E1000_RAH_ARRAY(0));2077 uint32_t ral = E1000_REG_READ(e1000 _data, E1000_RAL_ARRAY(0));2085 uint32_t rah = E1000_REG_READ(e1000, E1000_RAH_ARRAY(0)); 2086 uint32_t ral = E1000_REG_READ(e1000, E1000_RAL_ARRAY(0)); 2078 2087 2079 2088 *mac0_dest = (uint8_t) ral; … … 2084 2093 *mac5_dest = (uint8_t) (rah >> 8); 2085 2094 2086 fibril_mutex_unlock(&e1000 _data->rx_lock);2095 fibril_mutex_unlock(&e1000->rx_lock); 2087 2096 return EOK; 2088 2097 }; … … 2098 2107 static int e1000_set_addr(ddf_fun_t *dev, const nic_address_t *addr) 2099 2108 { 2100 nic_t *nic _data= NIC_DATA_DEV(dev);2101 e1000_t *e1000 _data = DRIVER_DATA_NIC(nic_data);2102 2103 fibril_mutex_lock(&e1000 _data->rx_lock);2104 fibril_mutex_lock(&e1000 _data->tx_lock);2105 2106 int rc = nic_report_address(nic _data, addr);2109 nic_t *nic = NIC_DATA_DEV(dev); 2110 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 2111 2112 fibril_mutex_lock(&e1000->rx_lock); 2113 fibril_mutex_lock(&e1000->tx_lock); 2114 2115 int rc = nic_report_address(nic, addr); 2107 2116 if (rc == EOK) 2108 e1000_write_receive_address(e1000 _data, 0, addr, false);2109 2110 fibril_mutex_unlock(&e1000 _data->tx_lock);2111 fibril_mutex_unlock(&e1000 _data->rx_lock);2117 e1000_write_receive_address(e1000, 0, addr, false); 2118 2119 fibril_mutex_unlock(&e1000->tx_lock); 2120 fibril_mutex_unlock(&e1000->rx_lock); 2112 2121 2113 2122 return rc; 2114 2123 } 2115 2124 2116 static void e1000_eeprom_get_address(e1000_t *e1000 _data,2125 static void e1000_eeprom_get_address(e1000_t *e1000, 2117 2126 nic_address_t *address) 2118 2127 { … … 2121 2130 uint16_t *mac4_dest = (uint16_t *) (address->address + 4); 2122 2131 2123 *mac0_dest = e1000_eeprom_read(e1000 _data, 0);2124 *mac2_dest = e1000_eeprom_read(e1000 _data, 1);2125 *mac4_dest = e1000_eeprom_read(e1000 _data, 2);2132 *mac0_dest = e1000_eeprom_read(e1000, 0); 2133 *mac2_dest = e1000_eeprom_read(e1000, 1); 2134 *mac4_dest = e1000_eeprom_read(e1000, 2); 2126 2135 } 2127 2136 2128 2137 /** Send packet 2129 2138 * 2130 * @param nic _dataNIC driver data structure2131 * @param packet 2139 * @param nic NIC driver data structure 2140 * @param packet Packet to send 2132 2141 * 2133 2142 * @return EOK if succeed … … 2135 2144 * 2136 2145 */ 2137 static void e1000_write_packet(nic_t *nic _data, packet_t *packet)2138 { 2139 assert(nic _data);2140 2141 e1000_t *e1000 _data = DRIVER_DATA_NIC(nic_data);2142 fibril_mutex_lock(&e1000 _data->tx_lock);2143 2144 uint32_t tdt = E1000_REG_READ(e1000 _data, E1000_TDT);2146 static void e1000_write_packet(nic_t *nic, packet_t *packet) 2147 { 2148 assert(nic); 2149 2150 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 2151 fibril_mutex_lock(&e1000->tx_lock); 2152 2153 uint32_t tdt = E1000_REG_READ(e1000, E1000_TDT); 2145 2154 e1000_tx_descriptor_t *tx_descriptor_addr = (e1000_tx_descriptor_t *) 2146 (e1000 _data->tx_ring.virt + tdt * sizeof(e1000_tx_descriptor_t));2155 (e1000->tx_ring_virt + tdt * sizeof(e1000_tx_descriptor_t)); 2147 2156 2148 2157 bool descriptor_available = false; … … 2155 2164 if (tx_descriptor_addr->status & TXDESCRIPTOR_STATUS_DD) { 2156 2165 descriptor_available = true; 2157 packet_t *old_packet = *(e1000 _data->tx_ring_packets + tdt);2166 packet_t *old_packet = *(e1000->tx_ring_packets + tdt); 2158 2167 if (old_packet) { 2159 nic_dma_unlock_packet(old_packet); 2160 nic_release_packet(nic_data, old_packet); 2168 size_t old_packet_size = packet_get_data_length(old_packet); 2169 nic_dma_unlock_packet(old_packet, old_packet_size); 2170 nic_release_packet(nic, old_packet); 2161 2171 } 2162 2172 } … … 2164 2174 if (!descriptor_available) { 2165 2175 /* Packet lost */ 2166 fibril_mutex_unlock(&e1000 _data->tx_lock);2176 fibril_mutex_unlock(&e1000->tx_lock); 2167 2177 return; 2168 2178 } … … 2170 2180 size_t packet_size = packet_get_data_length(packet); 2171 2181 2172 void *phys_addr = nic_dma_lock_packet(packet); 2173 if (!phys_addr) { 2174 fibril_mutex_unlock(&e1000_data->tx_lock); 2182 void *phys; 2183 int rc = nic_dma_lock_packet(packet, packet_size, &phys); 2184 if (rc != EOK) { 2185 fibril_mutex_unlock(&e1000->tx_lock); 2175 2186 return; 2176 2187 } 2177 2188 2178 *(e1000 _data->tx_ring_packets + tdt) = packet;2189 *(e1000->tx_ring_packets + tdt) = packet; 2179 2190 2180 2191 tx_descriptor_addr->phys_addr = 2181 PTR_TO_U64(phys _addr+ packet->data_start);2192 PTR_TO_U64(phys + packet->data_start); 2182 2193 tx_descriptor_addr->length = packet_size; 2183 2194 … … 2192 2203 tx_descriptor_addr->checksum_offset = 0; 2193 2204 tx_descriptor_addr->status = 0; 2194 if (e1000 _data->vlan_tag_add) {2195 tx_descriptor_addr->special = e1000 _data->vlan_tag;2205 if (e1000->vlan_tag_add) { 2206 tx_descriptor_addr->special = e1000->vlan_tag; 2196 2207 tx_descriptor_addr->command |= TXDESCRIPTOR_COMMAND_VLE; 2197 2208 } else … … 2204 2215 tdt = 0; 2205 2216 2206 E1000_REG_WRITE(e1000 _data, E1000_TDT, tdt);2207 2208 fibril_mutex_unlock(&e1000 _data->tx_lock);2217 E1000_REG_WRITE(e1000, E1000_TDT, tdt); 2218 2219 fibril_mutex_unlock(&e1000->tx_lock); 2209 2220 } 2210 2221 … … 2215 2226 return rc; 2216 2227 2217 nic_driver_implement(&e1000_driver_ops, &e1000_dev_ops, &e1000_nic_iface); 2228 nic_driver_implement(&e1000_driver_ops, &e1000_dev_ops, 2229 &e1000_nic_iface); 2218 2230 return ddf_driver_main(&e1000_driver); 2219 2231 } -
uspace/drv/nic/e1k/e1k.h
rc8751452 rc4be33a 49 49 50 50 /** Receive descriptior */ 51 typedef struct e1000_rx_descriptor{51 typedef struct { 52 52 /** Buffer Address - physical */ 53 53 uint64_t phys_addr; … … 57 57 uint16_t checksum; 58 58 /** Status field */ 59 59 uint8_t status; 60 60 /** Errors field */ 61 61 uint8_t errors; … … 65 65 66 66 /** Legacy transmit descriptior */ 67 typedef struct e1000_tx_descriptor{67 typedef struct { 68 68 /** Buffer Address - physical */ 69 69 uint64_t phys_addr; … … 75 75 uint8_t command; 76 76 /** Status field, upper bits are reserved */ 77 77 uint8_t status; 78 78 /** Checksum Start Field */ 79 79 uint8_t checksum_start_field;
Note:
See TracChangeset
for help on using the changeset viewer.