You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

legacy.c 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. pad_len = ( ETH_ZLEN - pkb_len ( pkb ) );
  26. if ( pad_len > 0 )
  27. memset ( pkb_put ( pkb, pad_len ), 0, pad_len );
  28. pkb_pull ( pkb, sizeof ( *ethhdr ) );
  29. nic->nic_op->transmit ( nic, ( const char * ) ethhdr->h_dest,
  30. ntohs ( ethhdr->h_protocol ),
  31. pkb_len ( pkb ), pkb->data );
  32. netdev_tx_complete ( netdev, pkb );
  33. return 0;
  34. }
  35. static void legacy_poll ( struct net_device *netdev, unsigned int rx_quota ) {
  36. struct nic *nic = netdev->priv;
  37. struct pk_buff *pkb;
  38. if ( ! rx_quota )
  39. return;
  40. pkb = alloc_pkb ( ETH_FRAME_LEN );
  41. if ( ! pkb )
  42. return;
  43. nic->packet = pkb->data;
  44. if ( nic->nic_op->poll ( nic, 1 ) ) {
  45. DBG ( "Received %d bytes\n", nic->packetlen );
  46. pkb_put ( pkb, nic->packetlen );
  47. netdev_rx ( netdev, pkb );
  48. } else {
  49. free_pkb ( pkb );
  50. }
  51. }
  52. static int legacy_open ( struct net_device *netdev __unused ) {
  53. return 0;
  54. }
  55. static void legacy_close ( struct net_device *netdev __unused ) {
  56. /* Nothing to do */
  57. }
  58. int legacy_probe ( struct pci_device *pci,
  59. const struct pci_device_id *id __unused,
  60. int ( * probe ) ( struct nic *nic,
  61. struct pci_device *pci ),
  62. void ( * disable ) ( struct nic *nic ) ) {
  63. struct net_device *netdev;
  64. int rc;
  65. if ( legacy_registered )
  66. return -EBUSY;
  67. netdev = alloc_etherdev ( 0 );
  68. if ( ! netdev )
  69. return -ENOMEM;
  70. netdev->priv = &nic;
  71. memset ( &nic, 0, sizeof ( nic ) );
  72. pci_set_drvdata ( pci, netdev );
  73. netdev->dev = &pci->dev;
  74. netdev->open = legacy_open;
  75. netdev->close = legacy_close;
  76. netdev->transmit = legacy_transmit;
  77. netdev->poll = legacy_poll;
  78. nic.node_addr = netdev->ll_addr;
  79. if ( ! probe ( &nic, pci ) ) {
  80. free_netdev ( netdev );
  81. return -ENODEV;
  82. }
  83. if ( ( rc = register_netdev ( netdev ) ) != 0 ) {
  84. disable ( &nic );
  85. free_netdev ( netdev );
  86. return rc;
  87. }
  88. /* Do not remove this message */
  89. printf ( "WARNING: Using legacy NIC wrapper on %s\n",
  90. ethernet_protocol.ntoa ( nic.node_addr ) );
  91. legacy_registered = 1;
  92. return 0;
  93. }
  94. void legacy_remove ( struct pci_device *pci,
  95. void ( * disable ) ( struct nic *nic ) ) {
  96. struct net_device *netdev = pci_get_drvdata ( pci );
  97. struct nic *nic = netdev->priv;
  98. unregister_netdev ( netdev );
  99. disable ( nic );
  100. free_netdev ( netdev );
  101. legacy_registered = 0;
  102. }
  103. void pci_fill_nic ( struct nic *nic, struct pci_device *pci ) {
  104. nic->ioaddr = pci->ioaddr;
  105. nic->irqno = pci->irq;
  106. }
  107. int dummy_connect ( struct nic *nic __unused ) {
  108. return 1;
  109. }
  110. void dummy_irq ( struct nic *nic __unused, irq_action_t irq_action __unused ) {
  111. return;
  112. }
  113. REQUIRE_OBJECT ( pci );