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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /**************************************************************************
  2. Etherboot - BOOTP/TFTP Bootstrap Program
  3. Skeleton NIC driver for Etherboot
  4. ***************************************************************************/
  5. /*
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2, or (at
  9. * your option) any later version.
  10. */
  11. /* to get some global routines like printf */
  12. #include "etherboot.h"
  13. /* to get the interface to the body of the program */
  14. #include "nic.h"
  15. /* to get the PCI support functions, if this is a PCI NIC */
  16. #include "pci.h"
  17. /* to get the ISA support functions, if this is an ISA NIC */
  18. #include "isa.h"
  19. /* NIC specific static variables go here */
  20. /**************************************************************************
  21. POLL - Wait for a frame
  22. ***************************************************************************/
  23. static int skel_poll(struct nic *nic, int retrieve)
  24. {
  25. /* Work out whether or not there's an ethernet packet ready to
  26. * read. Return 0 if not.
  27. */
  28. /*
  29. if ( ! <packet_ready> ) return 0;
  30. */
  31. /* retrieve==0 indicates that we are just checking for the
  32. * presence of a packet but don't want to read it just yet.
  33. */
  34. /*
  35. if ( ! retrieve ) return 1;
  36. */
  37. /* Copy data to nic->packet. Data should include the
  38. * link-layer header (dest MAC, source MAC, type).
  39. * Store length of data in nic->packetlen.
  40. * Return true to indicate a packet has been read.
  41. */
  42. /*
  43. nic->packetlen = <packet_length>;
  44. memcpy ( nic->packet, <packet_data>, <packet_length> );
  45. return 1;
  46. */
  47. return 0; /* Remove this line once this method is implemented */
  48. }
  49. /**************************************************************************
  50. TRANSMIT - Transmit a frame
  51. ***************************************************************************/
  52. static void skel_transmit(
  53. struct nic *nic,
  54. const char *dest, /* Destination */
  55. unsigned int type, /* Type */
  56. unsigned int size, /* size */
  57. const char *packet) /* Packet */
  58. {
  59. /* Transmit packet to dest MAC address. You will need to
  60. * construct the link-layer header (dest MAC, source MAC,
  61. * type).
  62. */
  63. /*
  64. unsigned int nstype = htons ( type );
  65. memcpy ( <tx_buffer>, dest, ETH_ALEN );
  66. memcpy ( <tx_buffer> + ETH_ALEN, nic->node_addr, ETH_ALEN );
  67. memcpy ( <tx_buffer> + 2 * ETH_ALEN, &nstype, 2 );
  68. memcpy ( <tx_buffer> + ETH_HLEN, data, size );
  69. <transmit_data> ( <tx_buffer>, size + ETH_HLEN );
  70. */
  71. }
  72. /**************************************************************************
  73. DISABLE - Turn off ethernet interface
  74. ***************************************************************************/
  75. static void skel_disable(struct dev *dev)
  76. {
  77. /* put the card in its initial state */
  78. /* This function serves 3 purposes.
  79. * This disables DMA and interrupts so we don't receive
  80. * unexpected packets or interrupts from the card after
  81. * etherboot has finished.
  82. * This frees resources so etherboot may use
  83. * this driver on another interface
  84. * This allows etherboot to reinitialize the interface
  85. * if something is something goes wrong.
  86. */
  87. }
  88. /**************************************************************************
  89. IRQ - handle interrupts
  90. ***************************************************************************/
  91. static void skel_irq(struct nic *nic, irq_action_t action)
  92. {
  93. /* This routine is somewhat optional. Etherboot itself
  94. * doesn't use interrupts, but they are required under some
  95. * circumstances when we're acting as a PXE stack.
  96. *
  97. * If you don't implement this routine, the only effect will
  98. * be that your driver cannot be used via Etherboot's UNDI
  99. * API. This won't affect programs that use only the UDP
  100. * portion of the PXE API, such as pxelinux.
  101. */
  102. switch ( action ) {
  103. case DISABLE :
  104. case ENABLE :
  105. /* Set receive interrupt enabled/disabled state */
  106. /*
  107. outb ( action == ENABLE ? IntrMaskEnabled : IntrMaskDisabled,
  108. nic->ioaddr + IntrMaskRegister );
  109. */
  110. break;
  111. case FORCE :
  112. /* Force NIC to generate a receive interrupt */
  113. /*
  114. outb ( ForceInterrupt, nic->ioaddr + IntrForceRegister );
  115. */
  116. break;
  117. }
  118. }
  119. /**************************************************************************
  120. PROBE - Look for an adapter, this routine's visible to the outside
  121. ***************************************************************************/
  122. #define board_found 1
  123. #define valid_link 0
  124. static int skel_probe ( struct dev *dev ) {
  125. struct nic *nic = nic_device ( dev );
  126. struct pci_device *pci = pci_device ( dev );
  127. if (board_found && valid_link)
  128. {
  129. /* store NIC parameters */
  130. nic->ioaddr = pci->ioaddr & ~3;
  131. nic->irqno = pci->irq;
  132. /* point to NIC specific routines */
  133. dev->disable = skel_disable;
  134. nic->poll = skel_poll;
  135. nic->transmit = skel_transmit;
  136. nic->irq = skel_irq;
  137. return 1;
  138. }
  139. /* else */
  140. return 0;
  141. }
  142. static struct pci_id skel_nics[] = {
  143. PCI_ROM(0x0000, 0x0000, "skel-pci", "Skeleton PCI Adaptor"),
  144. };
  145. static struct pci_driver skel_driver =
  146. PCI_DRIVER ( "SKELETON/PCI", skel_nics, PCI_NO_CLASS );
  147. BOOT_DRIVER ( "SKELETON/PCI", skel_probe );
  148. /**************************************************************************
  149. PROBE - Look for an adapter, this routine's visible to the outside
  150. ***************************************************************************/
  151. static int skel_isa_probe(struct dev *dev, unsigned short *probe_addrs)
  152. {
  153. struct nic *nic = (struct nic *)dev;
  154. /* if probe_addrs is 0, then routine can use a hardwired default */
  155. if (board_found && valid_link)
  156. {
  157. /* point to NIC specific routines */
  158. dev->disable = skel_disable;
  159. nic->poll = skel_poll;
  160. nic->transmit = skel_transmit;
  161. /* Report the ISA pnp id of the board */
  162. dev->devid.vendor_id = htons(GENERIC_ISAPNP_VENDOR);
  163. dev->devid.vendor_id = htons(0x1234);
  164. return 1;
  165. }
  166. /* else */
  167. return 0;
  168. }
  169. ISA_ROM("skel-isa", "Skeleton ISA driver")
  170. static struct isa_driver skel_isa_driver __isa_driver = {
  171. .type = NIC_DRIVER,
  172. .name = "SKELETON/ISA",
  173. .probe = skel_isa_probe,
  174. .ioaddrs = 0,
  175. };