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 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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. * Some devices will need custom bus logic. The ISA 3c509 is a good
  166. * example of this; it has a contention-resolution mechanism that is
  167. * similar to ISAPnP, but not close enough to use the generic ISAPnP
  168. * code. Look at 3c509.c to see how it works.
  169. *
  170. **************************************************************************
  171. */
  172. /**************************************************************************
  173. * PCI PROBE - Look for an adapter
  174. **************************************************************************
  175. */
  176. static int skel_pci_probe ( struct dev *dev, struct pci_device *pci ) {
  177. struct nic *nic = nic_device ( dev );
  178. nic->ioaddr = pci->ioaddr;
  179. nic->irqno = pci->irq;
  180. /* Test for physical presence of NIC */
  181. /*
  182. if ( ! my_tests ) {
  183. DBG ( "Could not find NIC: my explanation\n" );
  184. return 0;
  185. }
  186. */
  187. /* point to NIC specific routines */
  188. nic->nic_op = &skel_operations;
  189. return 1;
  190. }
  191. static struct pci_id skel_pci_nics[] = {
  192. PCI_ROM ( 0x0000, 0x0000, "skel-pci", "Skeleton PCI Adapter" ),
  193. };
  194. static struct pci_driver skel_pci_driver =
  195. PCI_DRIVER ( "SKEL/PCI", skel_pci_nics, PCI_NO_CLASS );
  196. BOOT_DRIVER ( "SKEL/PCI", find_pci_boot_device,
  197. skel_pci_driver, skel_pci_probe );
  198. /**************************************************************************
  199. * ISAPnP PROBE - Look for an adapter
  200. **************************************************************************
  201. */
  202. static int skel_eisa_probe ( struct dev *dev, struct eisa_device *eisa ) {
  203. struct nic *nic = nic_device ( dev );
  204. enable_eisa_device ( eisa );
  205. nic->ioaddr = eisa->ioaddr;
  206. nic->irqno = 0;
  207. /* Test for physical presence of NIC */
  208. /*
  209. if ( ! my_tests ) {
  210. DBG ( "Could not find NIC: my explanation\n" );
  211. return 0;
  212. }
  213. */
  214. /* point to NIC specific routines */
  215. nic->nic_op = &skel_operations;
  216. return 1;
  217. }
  218. static struct eisa_id skel_eisa_nics[] = {
  219. { "Skeleton EISA Adapter", EISA_VENDOR('S','K','L'), 0x0000 },
  220. };
  221. static struct eisa_driver skel_eisa_driver =
  222. EISA_DRIVER ( "SKEL/EISA", skel_eisa_nics );
  223. BOOT_DRIVER ( "SKEL/EISA", find_eisa_boot_device,
  224. skel_eisa_driver, skel_eisa_probe );
  225. ISA_ROM ( "skel-eisa", "Skeleton EISA Adapter" );
  226. /**************************************************************************
  227. * ISAPnP PROBE - Look for an adapter
  228. **************************************************************************
  229. */
  230. static int skel_isapnp_probe ( struct dev *dev,
  231. struct isapnp_device *isapnp ) {
  232. struct nic *nic = nic_device ( dev );
  233. nic->ioaddr = isapnp->ioaddr;
  234. nic->irqno = isapnp->irqno;
  235. /* Test for physical presence of NIC */
  236. /*
  237. if ( ! my_tests ) {
  238. DBG ( "Could not find NIC: my explanation\n" );
  239. return 0;
  240. }
  241. */
  242. /* point to NIC specific routines */
  243. nic->nic_op = &skel_operations;
  244. return 1;
  245. }
  246. static struct isapnp_id skel_isapnp_nics[] = {
  247. { "Skeleton ISAPnP Adapter", ISAPNP_VENDOR('S','K','L'), 0x0000 },
  248. };
  249. static struct isapnp_driver skel_isapnp_driver =
  250. ISAPNP_DRIVER ( "SKEL/ISAPnP", skel_isapnp_nics );
  251. BOOT_DRIVER ( "SKEL/ISAPnP", find_isapnp_boot_device,
  252. skel_isapnp_driver, skel_isapnp_probe );
  253. ISA_ROM ( "skel-isapnp", "Skeleton ISAPnP Adapter" );
  254. /**************************************************************************
  255. * MCA PROBE - Look for an adapter
  256. **************************************************************************
  257. */
  258. static int skel_mca_probe ( struct dev *dev,
  259. struct mca_device *mca __unused ) {
  260. struct nic *nic = nic_device ( dev );
  261. /* MCA parameters are available in the mca->pos[] array */
  262. /*
  263. nic->ioaddr = ( mca->pos[xxx] << 8 ) + mca->pos[yyy];
  264. nic->irqno = mca->pos[zzz] & 0x0f;
  265. */
  266. /* Test for physical presence of NIC */
  267. /*
  268. if ( ! my_tests ) {
  269. DBG ( "Could not find NIC: my explanation\n" );
  270. return 0;
  271. }
  272. */
  273. /* point to NIC specific routines */
  274. nic->nic_op = &skel_operations;
  275. return 1;
  276. }
  277. static struct mca_id skel_mca_nics[] = {
  278. { "Skeleton MCA Adapter", 0x0000 },
  279. };
  280. static struct mca_driver skel_mca_driver =
  281. MCA_DRIVER ( "SKEL/MCA", skel_mca_nics );
  282. BOOT_DRIVER ( "SKEL/MCA", find_mca_boot_device,
  283. skel_mca_driver, skel_mca_probe );
  284. ISA_ROM ( "skel-mca", "Skeleton MCA Adapter" );
  285. /**************************************************************************
  286. * ISA PROBE - Look for an adapter
  287. *
  288. * The "classical" ISA probe is split into two stages: trying a list
  289. * of I/O addresses to see if there's anything listening, and then
  290. * using that I/O address to fill in the information in the nic
  291. * structure.
  292. *
  293. * The list of probe addresses defined in skel_isa_probe_addrs[] will
  294. * be passed to skel_isa_probe_addr(). If skel_isa_probe_addr()
  295. * returns true, a struct isa_device will be created with isa->ioaddr
  296. * set to the working I/O address, and skel_isa_probe() will be
  297. * called.
  298. *
  299. * There is a standard mechanism for overriding the probe address list
  300. * using ISA_PROBE_ADDRS. Do not implement any custom code to
  301. * override the probe address list.
  302. *
  303. **************************************************************************
  304. */
  305. static int skel_isa_probe_addr ( uint16_t ioaddr __unused ) {
  306. return 0;
  307. }
  308. static int skel_isa_probe ( struct dev *dev, struct isa_device *isa ) {
  309. struct nic *nic = nic_device ( dev );
  310. nic->ioaddr = isa->ioaddr;
  311. nic->irqno = 0;
  312. /* Test for physical presence of NIC */
  313. /*
  314. if ( ! my_tests ) {
  315. DBG ( "Could not find NIC: my explanation\n" );
  316. return 0;
  317. }
  318. */
  319. /* point to NIC specific routines */
  320. nic->nic_op = &skel_operations;
  321. return 1;
  322. }
  323. static struct isa_probe_addr skel_isa_probe_addrs[] = {
  324. /*
  325. { 0x200 }, { 0x240 },
  326. */
  327. };
  328. static struct isa_driver skel_isa_driver =
  329. ISA_DRIVER ( "SKEL/ISA", skel_isa_probe_addrs, skel_isa_probe_addr,
  330. ISA_VENDOR('S','K','L'), 0x0000 );
  331. BOOT_DRIVER ( "SKEL/ISA", find_isa_boot_device,
  332. skel_isa_driver, skel_isa_probe );
  333. ISA_ROM ( "skel-isa", "Skeleton ISA Adapter" );