您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

legacy.c 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #include <stdint.h>
  2. #include <stdio.h>
  3. #include <errno.h>
  4. #include <gpxe/if_ether.h>
  5. #include <gpxe/netdevice.h>
  6. #include <gpxe/ethernet.h>
  7. #include <gpxe/pkbuff.h>
  8. #include <nic.h>
  9. /*
  10. * Quick and dirty compatibility layer
  11. *
  12. * This should allow old-API PCI drivers to at least function until
  13. * they are updated. It will not help non-PCI drivers.
  14. *
  15. * No drivers should rely on this code. It will be removed asap.
  16. *
  17. */
  18. struct nic nic;
  19. static int legacy_registered = 0;
  20. static int legacy_transmit ( struct net_device *netdev, struct pk_buff *pkb ) {
  21. struct nic *nic = netdev->priv;
  22. struct ethhdr *ethhdr = pkb->data;
  23. int pad_len;
  24. DBG ( "Transmitting %d bytes\n", pkb_len ( pkb ) );
  25. pkb_pad ( pkb, ETH_ZLEN );
  26. pkb_pull ( pkb, sizeof ( *ethhdr ) );
  27. nic->nic_op->transmit ( nic, ( const char * ) ethhdr->h_dest,
  28. ntohs ( ethhdr->h_protocol ),
  29. pkb_len ( pkb ), pkb->data );
  30. netdev_tx_complete ( netdev, pkb );
  31. return 0;
  32. }
  33. static void legacy_poll ( struct net_device *netdev, unsigned int rx_quota ) {
  34. struct nic *nic = netdev->priv;
  35. struct pk_buff *pkb;
  36. if ( ! rx_quota )
  37. return;
  38. pkb = alloc_pkb ( ETH_FRAME_LEN );
  39. if ( ! pkb )
  40. return;
  41. nic->packet = pkb->data;
  42. if ( nic->nic_op->poll ( nic, 1 ) ) {
  43. DBG ( "Received %d bytes\n", nic->packetlen );
  44. pkb_put ( pkb, nic->packetlen );
  45. netdev_rx ( netdev, pkb );
  46. } else {
  47. free_pkb ( pkb );
  48. }
  49. }
  50. static int legacy_open ( struct net_device *netdev __unused ) {
  51. return 0;
  52. }
  53. static void legacy_close ( struct net_device *netdev __unused ) {
  54. /* Nothing to do */
  55. }
  56. int legacy_probe ( struct pci_device *pci,
  57. const struct pci_device_id *id __unused,
  58. int ( * probe ) ( struct nic *nic,
  59. struct pci_device *pci ),
  60. void ( * disable ) ( struct nic *nic ) ) {
  61. struct net_device *netdev;
  62. int rc;
  63. if ( legacy_registered )
  64. return -EBUSY;
  65. netdev = alloc_etherdev ( 0 );
  66. if ( ! netdev )
  67. return -ENOMEM;
  68. netdev->priv = &nic;
  69. memset ( &nic, 0, sizeof ( nic ) );
  70. pci_set_drvdata ( pci, netdev );
  71. netdev->dev = &pci->dev;
  72. netdev->open = legacy_open;
  73. netdev->close = legacy_close;
  74. netdev->transmit = legacy_transmit;
  75. netdev->poll = legacy_poll;
  76. nic.node_addr = netdev->ll_addr;
  77. if ( ! probe ( &nic, pci ) ) {
  78. free_netdev ( netdev );
  79. return -ENODEV;
  80. }
  81. if ( ( rc = register_netdev ( netdev ) ) != 0 ) {
  82. disable ( &nic );
  83. free_netdev ( netdev );
  84. return rc;
  85. }
  86. /* Do not remove this message */
  87. printf ( "WARNING: Using legacy NIC wrapper on %s\n",
  88. ethernet_protocol.ntoa ( nic.node_addr ) );
  89. legacy_registered = 1;
  90. return 0;
  91. }
  92. void legacy_remove ( struct pci_device *pci,
  93. void ( * disable ) ( struct nic *nic ) ) {
  94. struct net_device *netdev = pci_get_drvdata ( pci );
  95. struct nic *nic = netdev->priv;
  96. unregister_netdev ( netdev );
  97. disable ( nic );
  98. free_netdev ( netdev );
  99. legacy_registered = 0;
  100. }
  101. void pci_fill_nic ( struct nic *nic, struct pci_device *pci ) {
  102. nic->ioaddr = pci->ioaddr;
  103. nic->irqno = pci->irq;
  104. }
  105. int dummy_connect ( struct nic *nic __unused ) {
  106. return 1;
  107. }
  108. void dummy_irq ( struct nic *nic __unused, irq_action_t irq_action __unused ) {
  109. return;
  110. }
  111. REQUIRE_OBJECT ( pci );