Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

mt23108.c 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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 toupper() */
  12. #include <ctype.h>
  13. /* to get some global routines like printf */
  14. #include "etherboot.h"
  15. /* to get the interface to the body of the program */
  16. #include "nic.h"
  17. /* to get the PCI support functions, if this is a PCI NIC */
  18. #include <gpxe/pci.h>
  19. /* to get the ISA support functions, if this is an ISA NIC */
  20. #include <gpxe/isa.h>
  21. #include "mt_version.c"
  22. #include "mt23108_imp.c"
  23. /* NIC specific static variables go here */
  24. int prompt_key(int secs, unsigned char *ch_p)
  25. {
  26. unsigned long tmo;
  27. unsigned char ch;
  28. for (tmo = currticks() + secs * TICKS_PER_SEC; currticks() < tmo;) {
  29. if (iskey()) {
  30. ch = toupper(getchar());
  31. if ((ch=='V') || (ch=='I')) {
  32. *ch_p = ch;
  33. return 1;
  34. }
  35. }
  36. }
  37. return 0;
  38. }
  39. /**************************************************************************
  40. IRQ - handle interrupts
  41. ***************************************************************************/
  42. static void tavor_irq(struct nic *nic, irq_action_t action)
  43. {
  44. /* This routine is somewhat optional. Etherboot itself
  45. * doesn't use interrupts, but they are required under some
  46. * circumstances when we're acting as a PXE stack.
  47. *
  48. * If you don't implement this routine, the only effect will
  49. * be that your driver cannot be used via Etherboot's UNDI
  50. * API. This won't affect programs that use only the UDP
  51. * portion of the PXE API, such as pxelinux.
  52. */
  53. if (0) {
  54. nic = NULL;
  55. }
  56. switch (action) {
  57. case DISABLE:
  58. case ENABLE:
  59. /* Set receive interrupt enabled/disabled state */
  60. /*
  61. outb ( action == ENABLE ? IntrMaskEnabled : IntrMaskDisabled,
  62. nic->ioaddr + IntrMaskRegister );
  63. */
  64. break;
  65. case FORCE:
  66. /* Force NIC to generate a receive interrupt */
  67. /*
  68. outb ( ForceInterrupt, nic->ioaddr + IntrForceRegister );
  69. */
  70. break;
  71. }
  72. }
  73. /**************************************************************************
  74. POLL - Wait for a frame
  75. ***************************************************************************/
  76. static int tavor_poll(struct nic *nic, int retrieve)
  77. {
  78. /* Work out whether or not there's an ethernet packet ready to
  79. * read. Return 0 if not.
  80. */
  81. /*
  82. if ( ! <packet_ready> ) return 0;
  83. */
  84. /* retrieve==0 indicates that we are just checking for the
  85. * presence of a packet but don't want to read it just yet.
  86. */
  87. /*
  88. if ( ! retrieve ) return 1;
  89. */
  90. /* Copy data to nic->packet. Data should include the
  91. * link-layer header (dest MAC, source MAC, type).
  92. * Store length of data in nic->packetlen.
  93. * Return true to indicate a packet has been read.
  94. */
  95. /*
  96. nic->packetlen = <packet_length>;
  97. memcpy ( nic->packet, <packet_data>, <packet_length> );
  98. return 1;
  99. */
  100. unsigned int size;
  101. int rc;
  102. rc = poll_imp(nic, retrieve, &size);
  103. if (rc) {
  104. return 0;
  105. }
  106. if (size == 0) {
  107. return 0;
  108. }
  109. nic->packetlen = size;
  110. return 1;
  111. }
  112. /**************************************************************************
  113. TRANSMIT - Transmit a frame
  114. ***************************************************************************/
  115. static void tavor_transmit(struct nic *nic, const char *dest, /* Destination */
  116. unsigned int type, /* Type */
  117. unsigned int size, /* size */
  118. const char *packet)
  119. { /* Packet */
  120. int rc;
  121. /* Transmit packet to dest MAC address. You will need to
  122. * construct the link-layer header (dest MAC, source MAC,
  123. * type).
  124. */
  125. if (nic) {
  126. rc = transmit_imp(dest, type, packet, size);
  127. if (rc)
  128. eprintf("tranmit error");
  129. }
  130. }
  131. /**************************************************************************
  132. DISABLE - Turn off ethernet interface
  133. ***************************************************************************/
  134. static void tavor_disable(struct dev *dev)
  135. {
  136. /* put the card in its initial state */
  137. /* This function serves 3 purposes.
  138. * This disables DMA and interrupts so we don't receive
  139. * unexpected packets or interrupts from the card after
  140. * etherboot has finished.
  141. * This frees resources so etherboot may use
  142. * this driver on another interface
  143. * This allows etherboot to reinitialize the interface
  144. * if something is something goes wrong.
  145. */
  146. if (dev || 1) { // ????
  147. disable_imp();
  148. }
  149. }
  150. /**************************************************************************
  151. PROBE - Look for an adapter, this routine's visible to the outside
  152. ***************************************************************************/
  153. static int tavor_probe(struct dev *dev, struct pci_device *pci)
  154. {
  155. struct nic *nic = (struct nic *)dev;
  156. int rc;
  157. unsigned char user_request;
  158. if (pci->vendor != MELLANOX_VENDOR_ID) {
  159. eprintf("");
  160. return 0;
  161. }
  162. printf("\n");
  163. printf("Mellanox Technologies LTD - Boot over IB implementaion\n");
  164. printf("Build version = %s\n\n", build_revision);
  165. verbose_messages = 0;
  166. print_info = 0;
  167. printf("Press within 3 seconds:\n");
  168. printf("V - to increase verbosity\n");
  169. printf("I - to print information\n");
  170. if (prompt_key(3, &user_request)) {
  171. if (user_request == 'V') {
  172. printf("User selected verbose messages\n");
  173. verbose_messages = 1;
  174. }
  175. else if (user_request == 'I') {
  176. printf("User selected to print information\n");
  177. print_info = 1;
  178. }
  179. }
  180. printf("\n");
  181. adjust_pci_device(pci);
  182. nic->priv_data = NULL;
  183. rc = probe_imp(pci, nic);
  184. /* give the user a chance to look at the info */
  185. if (print_info)
  186. sleep(5);
  187. if (!rc) {
  188. /* store NIC parameters */
  189. nic->ioaddr = pci->ioaddr & ~3;
  190. nic->irqno = pci->irq;
  191. /* point to NIC specific routines */
  192. dev->disable = tavor_disable;
  193. nic->poll = tavor_poll;
  194. nic->transmit = tavor_transmit;
  195. nic->irq = tavor_irq;
  196. return 1;
  197. }
  198. /* else */
  199. return 0;
  200. }
  201. static struct pci_id tavor_nics[] = {
  202. PCI_ROM(0x15b3, 0x5a44, "MT23108", "MT23108 HCA driver"),
  203. PCI_ROM(0x15b3, 0x6278, "MT25208", "MT25208 HCA driver"),
  204. };
  205. struct pci_driver tavor_driver __pci_driver = {
  206. .type = NIC_DRIVER,
  207. .name = "MT23108/MT25208",
  208. .probe = tavor_probe,
  209. .ids = tavor_nics,
  210. .id_count = sizeof(tavor_nics) / sizeof(tavor_nics[0]),
  211. .class = 0,
  212. };