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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. /* Drag in support for whichever bus(es) we want for this NIC */
  16. #include "pci.h"
  17. #include "isa.h"
  18. #include "eisa.h"
  19. #include "isapnp.h"
  20. #include "mca.h"
  21. /* NIC specific static variables go here. Try to avoid using static
  22. * variables wherever possible. In particular, the I/O address can
  23. * always be accessed via nic->ioaddr.
  24. */
  25. /*
  26. * Don't forget to remove "__unused" from all the function parameters!
  27. *
  28. */
  29. /**************************************************************************
  30. * CONNECT - Connect to the network
  31. **************************************************************************
  32. */
  33. static int skel_connect ( struct nic *nic __unused ) {
  34. /*
  35. * Connect to the network. For most NICs, this will probably
  36. * be a no-op. For wireless NICs, this should be the point at
  37. * which you attempt to join to an access point.
  38. *
  39. * Return 0 if the connection failed (e.g. no cable plugged
  40. * in), 1 for success.
  41. *
  42. */
  43. return 1;
  44. }
  45. /**************************************************************************
  46. * POLL - Wait for a frame
  47. **************************************************************************
  48. */
  49. static int skel_poll ( struct nic *nic __unused, int retrieve __unused ) {
  50. /* Work out whether or not there's an ethernet packet ready to
  51. * read. Return 0 if not.
  52. */
  53. /*
  54. if ( ! <packet_ready> ) return 0;
  55. */
  56. /* retrieve==0 indicates that we are just checking for the
  57. * presence of a packet but don't want to read it just yet.
  58. */
  59. /*
  60. if ( ! retrieve ) return 1;
  61. */
  62. /* Copy data to nic->packet. Data should include the
  63. * link-layer header (dest MAC, source MAC, type).
  64. * Store length of data in nic->packetlen.
  65. * Return true to indicate a packet has been read.
  66. */
  67. /*
  68. nic->packetlen = <packet_length>;
  69. memcpy ( nic->packet, <packet_data>, <packet_length> );
  70. return 1;
  71. */
  72. return 0; /* Remove this line once this method is implemented */
  73. }
  74. /**************************************************************************
  75. * TRANSMIT - Transmit a frame
  76. **************************************************************************
  77. */
  78. static void skel_transmit ( struct nic *nic __unused,
  79. const char *dest __unused,
  80. unsigned int type __unused,
  81. unsigned int size __unused,
  82. const char *packet __unused ) {
  83. /* Transmit packet to dest MAC address. You will need to
  84. * construct the link-layer header (dest MAC, source MAC,
  85. * type).
  86. */
  87. /*
  88. unsigned int nstype = htons ( type );
  89. memcpy ( <tx_buffer>, dest, ETH_ALEN );
  90. memcpy ( <tx_buffer> + ETH_ALEN, nic->node_addr, ETH_ALEN );
  91. memcpy ( <tx_buffer> + 2 * ETH_ALEN, &nstype, 2 );
  92. memcpy ( <tx_buffer> + ETH_HLEN, data, size );
  93. <transmit_data> ( <tx_buffer>, size + ETH_HLEN );
  94. */
  95. }
  96. /**************************************************************************
  97. * DISABLE - Turn off ethernet interface
  98. **************************************************************************
  99. */
  100. static void skel_disable ( struct nic *nic __unused ) {
  101. /* put the card in its initial state */
  102. /* This function serves 3 purposes.
  103. * This disables DMA and interrupts so we don't receive
  104. * unexpected packets or interrupts from the card after
  105. * etherboot has finished.
  106. * This frees resources so etherboot may use
  107. * this driver on another interface
  108. * This allows etherboot to reinitialize the interface
  109. * if something is something goes wrong.
  110. */
  111. }
  112. /**************************************************************************
  113. * IRQ - handle interrupts
  114. **************************************************************************
  115. */
  116. static void skel_irq ( struct nic *nic __unused, irq_action_t action ) {
  117. /* This routine is somewhat optional. Etherboot itself
  118. * doesn't use interrupts, but they are required under some
  119. * circumstances when we're acting as a PXE stack.
  120. *
  121. * If you don't implement this routine, the only effect will
  122. * be that your driver cannot be used via Etherboot's UNDI
  123. * API. This won't affect programs that use only the UDP
  124. * portion of the PXE API, such as pxelinux.
  125. */
  126. switch ( action ) {
  127. case DISABLE :
  128. case ENABLE :
  129. /* Set receive interrupt enabled/disabled state */
  130. /*
  131. outb ( action == ENABLE ? IntrMaskEnabled : IntrMaskDisabled,
  132. nic->ioaddr + IntrMaskRegister );
  133. */
  134. break;
  135. case FORCE :
  136. /* Force NIC to generate a receive interrupt */
  137. /*
  138. outb ( ForceInterrupt, nic->ioaddr + IntrForceRegister );
  139. */
  140. break;
  141. }
  142. }
  143. /**************************************************************************
  144. * OPERATIONS TABLE - Pointers to all the above methods
  145. **************************************************************************
  146. */
  147. static struct nic_operations skel_operations = {
  148. .connect = skel_connect,
  149. .poll = skel_poll,
  150. .transmit = skel_transmit,
  151. .irq = skel_irq,
  152. .disable = skel_disable,
  153. };
  154. /**************************************************************************
  155. * PROBE - Look for an adapter
  156. *
  157. * You need to define a probe routine for each bus type that your
  158. * driver supports, together with tables that enable Etherboot to
  159. * identify that your driver should be used for a particular device.
  160. *
  161. * Delete whichever of the following sections you don't need. For
  162. * example, most PCI devices will only need the PCI probing section;
  163. * ISAPnP, EISA, etc. can all be deleted.
  164. *
  165. **************************************************************************
  166. */
  167. /**************************************************************************
  168. * PCI PROBE - Look for an adapter
  169. **************************************************************************
  170. */
  171. static int skel_pci_probe ( struct dev *dev, struct pci_device *pci ) {
  172. struct nic *nic = nic_device ( dev );
  173. /* store NIC parameters */
  174. nic->ioaddr = pci->ioaddr;
  175. nic->irqno = pci->irq;
  176. /* Test for physical presence of NIC */
  177. /*
  178. if ( ! my_tests ) {
  179. DBG ( "Could not find NIC: my explanation\n" );
  180. return 0;
  181. }
  182. */
  183. /* point to NIC specific routines */
  184. nic->nic_op = &skel_operations;
  185. return 1;
  186. }
  187. static struct pci_id skel_pci_nics[] = {
  188. PCI_ROM ( 0x0000, 0x0000, "skel-pci", "Skeleton PCI Adaptor" ),
  189. };
  190. static struct pci_driver skel_pci_driver =
  191. PCI_DRIVER ( "SKELETON/PCI", skel_pci_nics, PCI_NO_CLASS );
  192. BOOT_DRIVER ( "SKELETON/PCI", find_pci_boot_device,
  193. skel_pci_driver, skel_pci_probe );