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 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #include <stdint.h>
  2. #include <errno.h>
  3. #include <vsprintf.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. free_pkb ( pkb );
  33. return 0;
  34. }
  35. static void legacy_poll ( struct net_device *netdev ) {
  36. struct nic *nic = netdev->priv;
  37. struct pk_buff *pkb;
  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. int legacy_probe ( struct pci_device *pci,
  51. const struct pci_device_id *id __unused,
  52. int ( * probe ) ( struct nic *nic,
  53. struct pci_device *pci ),
  54. void ( * disable ) ( struct nic *nic ) ) {
  55. struct net_device *netdev;
  56. int rc;
  57. if ( legacy_registered )
  58. return -EBUSY;
  59. netdev = alloc_etherdev ( 0 );
  60. if ( ! netdev )
  61. return -ENOMEM;
  62. netdev->priv = &nic;
  63. memset ( &nic, 0, sizeof ( nic ) );
  64. pci_set_drvdata ( pci, netdev );
  65. netdev->transmit = legacy_transmit;
  66. netdev->poll = legacy_poll;
  67. nic.node_addr = netdev->ll_addr;
  68. if ( ! probe ( &nic, pci ) ) {
  69. free_netdev ( netdev );
  70. return -ENODEV;
  71. }
  72. if ( ( rc = register_netdev ( netdev ) ) != 0 ) {
  73. disable ( &nic );
  74. free_netdev ( netdev );
  75. return rc;
  76. }
  77. /* Do not remove this message */
  78. printf ( "WARNING: Using legacy NIC wrapper on %s\n",
  79. ethernet_protocol.ntoa ( nic.node_addr ) );
  80. legacy_registered = 1;
  81. return 0;
  82. }
  83. void legacy_remove ( struct pci_device *pci,
  84. void ( * disable ) ( struct nic *nic ) ) {
  85. struct net_device *netdev = pci_get_drvdata ( pci );
  86. struct nic *nic = netdev->priv;
  87. unregister_netdev ( netdev );
  88. disable ( nic );
  89. free_netdev ( netdev );
  90. legacy_registered = 0;
  91. }
  92. void pci_fill_nic ( struct nic *nic, struct pci_device *pci ) {
  93. nic->ioaddr = pci->ioaddr;
  94. nic->irqno = pci->irq;
  95. }
  96. int dummy_connect ( struct nic *nic __unused ) {
  97. return 1;
  98. }
  99. void dummy_irq ( struct nic *nic __unused, irq_action_t irq_action __unused ) {
  100. return;
  101. }
  102. REQUIRE_OBJECT ( pci );