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.

skel.c 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 nic *nic ) {
  76. /* put the card in its initial state */
  77. /* This function serves 3 purposes.
  78. * This disables DMA and interrupts so we don't receive
  79. * unexpected packets or interrupts from the card after
  80. * etherboot has finished.
  81. * This frees resources so etherboot may use
  82. * this driver on another interface
  83. * This allows etherboot to reinitialize the interface
  84. * if something is something goes wrong.
  85. */
  86. }
  87. /**************************************************************************
  88. IRQ - handle interrupts
  89. ***************************************************************************/
  90. static void skel_irq(struct nic *nic, irq_action_t action)
  91. {
  92. /* This routine is somewhat optional. Etherboot itself
  93. * doesn't use interrupts, but they are required under some
  94. * circumstances when we're acting as a PXE stack.
  95. *
  96. * If you don't implement this routine, the only effect will
  97. * be that your driver cannot be used via Etherboot's UNDI
  98. * API. This won't affect programs that use only the UDP
  99. * portion of the PXE API, such as pxelinux.
  100. */
  101. switch ( action ) {
  102. case DISABLE :
  103. case ENABLE :
  104. /* Set receive interrupt enabled/disabled state */
  105. /*
  106. outb ( action == ENABLE ? IntrMaskEnabled : IntrMaskDisabled,
  107. nic->ioaddr + IntrMaskRegister );
  108. */
  109. break;
  110. case FORCE :
  111. /* Force NIC to generate a receive interrupt */
  112. /*
  113. outb ( ForceInterrupt, nic->ioaddr + IntrForceRegister );
  114. */
  115. break;
  116. }
  117. }
  118. /**************************************************************************
  119. PROBE - Look for an adapter, this routine's visible to the outside
  120. ***************************************************************************/
  121. #define board_found 1
  122. #define valid_link 0
  123. static int skel_probe ( struct dev *dev ) {
  124. struct nic *nic = nic_device ( dev );
  125. struct pci_device *pci = pci_device ( dev );
  126. if (board_found && valid_link)
  127. {
  128. /* store NIC parameters */
  129. nic->ioaddr = pci->ioaddr & ~3;
  130. nic->irqno = pci->irq;
  131. /* point to NIC specific routines */
  132. dev->disable = skel_disable;
  133. nic->poll = skel_poll;
  134. nic->transmit = skel_transmit;
  135. nic->irq = skel_irq;
  136. return 1;
  137. }
  138. /* else */
  139. return 0;
  140. }
  141. static struct pci_id skel_nics[] = {
  142. PCI_ROM(0x0000, 0x0000, "skel-pci", "Skeleton PCI Adaptor"),
  143. };
  144. static struct pci_driver skel_driver =
  145. PCI_DRIVER ( "SKELETON/PCI", skel_nics, PCI_NO_CLASS );
  146. BOOT_DRIVER ( "SKELETON/PCI", skel_probe );
  147. /**************************************************************************
  148. PROBE - Look for an adapter, this routine's visible to the outside
  149. ***************************************************************************/
  150. static int skel_isa_probe(struct dev *dev, unsigned short *probe_addrs)
  151. {
  152. struct nic *nic = (struct nic *)dev;
  153. /* if probe_addrs is 0, then routine can use a hardwired default */
  154. if (board_found && valid_link)
  155. {
  156. /* point to NIC specific routines */
  157. dev->disable = skel_disable;
  158. nic->poll = skel_poll;
  159. nic->transmit = skel_transmit;
  160. /* Report the ISA pnp id of the board */
  161. dev->devid.vendor_id = htons(GENERIC_ISAPNP_VENDOR);
  162. dev->devid.vendor_id = htons(0x1234);
  163. return 1;
  164. }
  165. /* else */
  166. return 0;
  167. }
  168. ISA_ROM("skel-isa", "Skeleton ISA driver")
  169. static struct isa_driver skel_isa_driver __isa_driver = {
  170. .type = NIC_DRIVER,
  171. .name = "SKELETON/ISA",
  172. .probe = skel_isa_probe,
  173. .ioaddrs = 0,
  174. };