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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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, struct pci_device *pci ) {
  124. struct nic *nic = nic_device ( dev );
  125. if (board_found && valid_link)
  126. {
  127. /* store NIC parameters */
  128. nic->ioaddr = pci->ioaddr & ~3;
  129. nic->irqno = pci->irq;
  130. /* point to NIC specific routines */
  131. static struct nic_operations skel_operations;
  132. static struct nic_operations skel_operations = {
  133. .connect = dummy_connect,
  134. .poll = skel_poll,
  135. .transmit = skel_transmit,
  136. .irq = skel_irq,
  137. .disable = skel_disable,
  138. }; nic->nic_op = &skel_operations;
  139. return 1;
  140. }
  141. /* else */
  142. return 0;
  143. }
  144. static struct pci_id skel_nics[] = {
  145. PCI_ROM(0x0000, 0x0000, "skel-pci", "Skeleton PCI Adaptor"),
  146. };
  147. static struct pci_driver skel_driver =
  148. PCI_DRIVER ( "SKELETON/PCI", skel_nics, PCI_NO_CLASS );
  149. BOOT_DRIVER ( "SKELETON/PCI", skel_probe );
  150. /**************************************************************************
  151. PROBE - Look for an adapter, this routine's visible to the outside
  152. ***************************************************************************/
  153. static int skel_isa_probe(struct dev *dev, unsigned short *probe_addrs)
  154. {
  155. struct nic *nic = (struct nic *)dev;
  156. /* if probe_addrs is 0, then routine can use a hardwired default */
  157. if (board_found && valid_link)
  158. {
  159. /* point to NIC specific routines */
  160. static struct nic_operations skel_operations;
  161. static struct nic_operations skel_operations = {
  162. .connect = dummy_connect,
  163. .poll = skel_poll,
  164. .transmit = skel_transmit,
  165. .irq = skel_irq,
  166. .disable = skel_disable,
  167. }; nic->nic_op = &skel_operations;
  168. /* Report the ISA pnp id of the board */
  169. dev->devid.vendor_id = htons(GENERIC_ISAPNP_VENDOR);
  170. dev->devid.vendor_id = htons(0x1234);
  171. return 1;
  172. }
  173. /* else */
  174. return 0;
  175. }
  176. ISA_ROM("skel-isa", "Skeleton ISA driver")
  177. static struct isa_driver skel_isa_driver __isa_driver = {
  178. .type = NIC_DRIVER,
  179. .name = "SKELETON/ISA",
  180. .probe = skel_isa_probe,
  181. .ioaddrs = 0,
  182. };