Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

legacy.c 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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/iobuf.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 io_buffer *iobuf ) {
  21. struct nic *nic = netdev->priv;
  22. struct ethhdr *ethhdr;
  23. DBG ( "Transmitting %zd bytes\n", iob_len ( iobuf ) );
  24. iob_pad ( iobuf, ETH_ZLEN );
  25. ethhdr = iobuf->data;
  26. iob_pull ( iobuf, sizeof ( *ethhdr ) );
  27. nic->nic_op->transmit ( nic, ( const char * ) ethhdr->h_dest,
  28. ntohs ( ethhdr->h_protocol ),
  29. iob_len ( iobuf ), iobuf->data );
  30. netdev_tx_complete ( netdev, iobuf );
  31. return 0;
  32. }
  33. static void legacy_poll ( struct net_device *netdev ) {
  34. struct nic *nic = netdev->priv;
  35. struct io_buffer *iobuf;
  36. iobuf = alloc_iob ( ETH_FRAME_LEN );
  37. if ( ! iobuf )
  38. return;
  39. nic->packet = iobuf->data;
  40. if ( nic->nic_op->poll ( nic, 1 ) ) {
  41. DBG ( "Received %d bytes\n", nic->packetlen );
  42. iob_put ( iobuf, nic->packetlen );
  43. netdev_rx ( netdev, iobuf );
  44. } else {
  45. free_iob ( iobuf );
  46. }
  47. }
  48. static int legacy_open ( struct net_device *netdev __unused ) {
  49. /* Nothing to do */
  50. return 0;
  51. }
  52. static void legacy_close ( struct net_device *netdev __unused ) {
  53. /* Nothing to do */
  54. }
  55. static void legacy_irq ( struct net_device *netdev __unused, int enable ) {
  56. struct nic *nic = netdev->priv;
  57. nic->nic_op->irq ( nic, ( enable ? ENABLE : DISABLE ) );
  58. }
  59. static struct net_device_operations legacy_operations = {
  60. .open = legacy_open,
  61. .close = legacy_close,
  62. .transmit = legacy_transmit,
  63. .poll = legacy_poll,
  64. .irq = legacy_irq,
  65. };
  66. int legacy_probe ( void *hwdev,
  67. void ( * set_drvdata ) ( void *hwdev, void *priv ),
  68. struct device *dev,
  69. int ( * probe ) ( struct nic *nic, void *hwdev ),
  70. void ( * disable ) ( struct nic *nic, void *hwdev ) ) {
  71. struct net_device *netdev;
  72. int rc;
  73. if ( legacy_registered )
  74. return -EBUSY;
  75. netdev = alloc_etherdev ( 0 );
  76. if ( ! netdev )
  77. return -ENOMEM;
  78. netdev_init ( netdev, &legacy_operations );
  79. netdev->priv = &nic;
  80. memset ( &nic, 0, sizeof ( nic ) );
  81. set_drvdata ( hwdev, netdev );
  82. netdev->dev = dev;
  83. nic.node_addr = netdev->ll_addr;
  84. if ( ! probe ( &nic, hwdev ) ) {
  85. rc = -ENODEV;
  86. goto err_probe;
  87. }
  88. if ( ( rc = register_netdev ( netdev ) ) != 0 )
  89. goto err_register;
  90. /* Do not remove this message */
  91. printf ( "WARNING: Using legacy NIC wrapper on %s\n",
  92. ethernet_protocol.ntoa ( nic.node_addr ) );
  93. legacy_registered = 1;
  94. return 0;
  95. err_register:
  96. disable ( &nic, hwdev );
  97. err_probe:
  98. netdev_nullify ( netdev );
  99. netdev_put ( netdev );
  100. return rc;
  101. }
  102. void legacy_remove ( void *hwdev,
  103. void * ( * get_drvdata ) ( void *hwdev ),
  104. void ( * disable ) ( struct nic *nic, void *hwdev ) ) {
  105. struct net_device *netdev = get_drvdata ( hwdev );
  106. struct nic *nic = netdev->priv;
  107. unregister_netdev ( netdev );
  108. disable ( nic, hwdev );
  109. netdev_nullify ( netdev );
  110. netdev_put ( netdev );
  111. legacy_registered = 0;
  112. }
  113. int dummy_connect ( struct nic *nic __unused ) {
  114. return 1;
  115. }
  116. void dummy_irq ( struct nic *nic __unused, irq_action_t irq_action __unused ) {
  117. return;
  118. }