Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

skeleton.c 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*
  2. * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. *
  19. * You can also choose to distribute this program under the terms of
  20. * the Unmodified Binary Distribution Licence (as given in the file
  21. * COPYING.UBDL), provided that you have satisfied its requirements.
  22. */
  23. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. #include <stdint.h>
  25. #include <string.h>
  26. #include <unistd.h>
  27. #include <errno.h>
  28. #include <byteswap.h>
  29. #include <ipxe/netdevice.h>
  30. #include <ipxe/ethernet.h>
  31. #include <ipxe/if_ether.h>
  32. #include <ipxe/iobuf.h>
  33. #include <ipxe/malloc.h>
  34. #include <ipxe/pci.h>
  35. #include "skeleton.h"
  36. /** @file
  37. *
  38. * Skeleton network driver
  39. *
  40. */
  41. /******************************************************************************
  42. *
  43. * Device reset
  44. *
  45. ******************************************************************************
  46. */
  47. /**
  48. * Reset hardware
  49. *
  50. * @v skel Skeleton device
  51. * @ret rc Return status code
  52. */
  53. static int skeleton_reset ( struct skeleton_nic *skel ) {
  54. DBGC ( skel, "SKELETON %p does not yet support reset\n", skel );
  55. return -ENOTSUP;
  56. }
  57. /******************************************************************************
  58. *
  59. * Link state
  60. *
  61. ******************************************************************************
  62. */
  63. /**
  64. * Check link state
  65. *
  66. * @v netdev Network device
  67. */
  68. static void skeleton_check_link ( struct net_device *netdev ) {
  69. struct skeleton_nic *skel = netdev->priv;
  70. DBGC ( skel, "SKELETON %p does not yet support link state\n", skel );
  71. netdev_link_err ( netdev, -ENOTSUP );
  72. }
  73. /******************************************************************************
  74. *
  75. * Network device interface
  76. *
  77. ******************************************************************************
  78. */
  79. /**
  80. * Open network device
  81. *
  82. * @v netdev Network device
  83. * @ret rc Return status code
  84. */
  85. static int skeleton_open ( struct net_device *netdev ) {
  86. struct skeleton_nic *skel = netdev->priv;
  87. DBGC ( skel, "SKELETON %p does not yet support open\n", skel );
  88. return -ENOTSUP;
  89. }
  90. /**
  91. * Close network device
  92. *
  93. * @v netdev Network device
  94. */
  95. static void skeleton_close ( struct net_device *netdev ) {
  96. struct skeleton_nic *skel = netdev->priv;
  97. DBGC ( skel, "SKELETON %p does not yet support close\n", skel );
  98. }
  99. /**
  100. * Transmit packet
  101. *
  102. * @v netdev Network device
  103. * @v iobuf I/O buffer
  104. * @ret rc Return status code
  105. */
  106. static int skeleton_transmit ( struct net_device *netdev,
  107. struct io_buffer *iobuf ) {
  108. struct skeleton_nic *skel = netdev->priv;
  109. DBGC ( skel, "SKELETON %p does not yet support transmit\n", skel );
  110. ( void ) iobuf;
  111. return -ENOTSUP;
  112. }
  113. /**
  114. * Poll for completed and received packets
  115. *
  116. * @v netdev Network device
  117. */
  118. static void skeleton_poll ( struct net_device *netdev ) {
  119. struct skeleton_nic *skel = netdev->priv;
  120. /* Not yet implemented */
  121. ( void ) skel;
  122. }
  123. /**
  124. * Enable or disable interrupts
  125. *
  126. * @v netdev Network device
  127. * @v enable Interrupts should be enabled
  128. */
  129. static void skeleton_irq ( struct net_device *netdev, int enable ) {
  130. struct skeleton_nic *skel = netdev->priv;
  131. DBGC ( skel, "SKELETON %p does not yet support interrupts\n", skel );
  132. ( void ) enable;
  133. }
  134. /** Skeleton network device operations */
  135. static struct net_device_operations skeleton_operations = {
  136. .open = skeleton_open,
  137. .close = skeleton_close,
  138. .transmit = skeleton_transmit,
  139. .poll = skeleton_poll,
  140. .irq = skeleton_irq,
  141. };
  142. /******************************************************************************
  143. *
  144. * PCI interface
  145. *
  146. ******************************************************************************
  147. */
  148. /**
  149. * Probe PCI device
  150. *
  151. * @v pci PCI device
  152. * @ret rc Return status code
  153. */
  154. static int skeleton_probe ( struct pci_device *pci ) {
  155. struct net_device *netdev;
  156. struct skeleton_nic *skel;
  157. int rc;
  158. /* Allocate and initialise net device */
  159. netdev = alloc_etherdev ( sizeof ( *skel ) );
  160. if ( ! netdev ) {
  161. rc = -ENOMEM;
  162. goto err_alloc;
  163. }
  164. netdev_init ( netdev, &skeleton_operations );
  165. skel = netdev->priv;
  166. pci_set_drvdata ( pci, netdev );
  167. netdev->dev = &pci->dev;
  168. memset ( skel, 0, sizeof ( *skel ) );
  169. /* Fix up PCI device */
  170. adjust_pci_device ( pci );
  171. /* Map registers */
  172. skel->regs = ioremap ( pci->membase, SKELETON_BAR_SIZE );
  173. if ( ! skel->regs ) {
  174. rc = -ENODEV;
  175. goto err_ioremap;
  176. }
  177. /* Reset the NIC */
  178. if ( ( rc = skeleton_reset ( skel ) ) != 0 )
  179. goto err_reset;
  180. /* Register network device */
  181. if ( ( rc = register_netdev ( netdev ) ) != 0 )
  182. goto err_register_netdev;
  183. /* Set initial link state */
  184. skeleton_check_link ( netdev );
  185. return 0;
  186. unregister_netdev ( netdev );
  187. err_register_netdev:
  188. skeleton_reset ( skel );
  189. err_reset:
  190. iounmap ( skel->regs );
  191. err_ioremap:
  192. netdev_nullify ( netdev );
  193. netdev_put ( netdev );
  194. err_alloc:
  195. return rc;
  196. }
  197. /**
  198. * Remove PCI device
  199. *
  200. * @v pci PCI device
  201. */
  202. static void skeleton_remove ( struct pci_device *pci ) {
  203. struct net_device *netdev = pci_get_drvdata ( pci );
  204. struct skeleton_nic *skel = netdev->priv;
  205. /* Unregister network device */
  206. unregister_netdev ( netdev );
  207. /* Reset card */
  208. skeleton_reset ( skel );
  209. /* Free network device */
  210. iounmap ( skel->regs );
  211. netdev_nullify ( netdev );
  212. netdev_put ( netdev );
  213. }
  214. /** Skeleton PCI device IDs */
  215. static struct pci_device_id skeleton_nics[] = {
  216. PCI_ROM ( 0x5ce1, 0x5ce1, "skel", "Skeleton", 0 ),
  217. };
  218. /** Skeleton PCI driver */
  219. struct pci_driver skeleton_driver __pci_driver = {
  220. .ids = skeleton_nics,
  221. .id_count = ( sizeof ( skeleton_nics ) / sizeof ( skeleton_nics[0] ) ),
  222. .probe = skeleton_probe,
  223. .remove = skeleton_remove,
  224. };