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.

mt25218.c 6.2KB

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