Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

mt23108_imp.c 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. typedef uint32_t __u32;
  2. typedef uint16_t __u16;
  3. typedef uint8_t __u8;
  4. static int verbose_messages=0;
  5. static int print_info=0;
  6. static int fatal_condition=0;
  7. static int fw_fatal;
  8. #define tprintf(fmt, a...) \
  9. do { \
  10. if ( verbose_messages ) { \
  11. printf("%s:%d: " fmt "\n", __func__, __LINE__, ##a); \
  12. } \
  13. } \
  14. while(0)
  15. #define eprintf(fmt, a...) \
  16. printf("%s:%d: " fmt "\n", __func__, __LINE__, ##a)
  17. static void cpu_to_be_buf(void *buf, int size)
  18. {
  19. int dw_sz = size >> 2, i;
  20. for (i = 0; i < dw_sz; ++i) {
  21. ((__u32 *) buf)[i] = cpu_to_be32(((__u32 *) buf)[i]);
  22. }
  23. }
  24. static void be_to_cpu_buf(void *buf, int size)
  25. {
  26. int dw_sz = size >> 2, i;
  27. u32 *p = buf;
  28. for (i = 0; i < dw_sz; ++i) {
  29. p[i] = be32_to_cpu(p[i]);
  30. }
  31. }
  32. #include "cmdif_mt23108.c"
  33. #include "cmdif_comm.c"
  34. #include "ib_mt23108.c"
  35. #include "ib_mad.c"
  36. #include "ib_driver.c"
  37. #include "ipoib.c"
  38. static int probe_imp(struct pci_device *pci, struct nic *nic)
  39. {
  40. int rc;
  41. if (0 && nic) { /* just to supress warning */
  42. return 0;
  43. }
  44. fatal_condition= 0;
  45. fw_fatal= 0;
  46. tprintf("");
  47. rc = ipoib_init(pci);
  48. if (rc)
  49. return rc;
  50. tprintf("");
  51. return rc;
  52. }
  53. static int disable_imp(void)
  54. {
  55. int rc;
  56. rc = ipoib_close(fw_fatal);
  57. return rc;
  58. }
  59. static int transmit_imp(const char *dest, /* Destination */
  60. unsigned int type, /* Type */
  61. const char *packet, /* Packet */
  62. unsigned int size)
  63. { /* size */
  64. int rc;
  65. if (fatal_condition) {
  66. /* since the transmit function does not return a value
  67. we return success but do nothing to suppress error messages */
  68. return 0;
  69. }
  70. rc = ipoib_send_packet(dest, type, packet, size);
  71. if (rc) {
  72. printf("*** ERROR IN SEND FLOW ***\n");
  73. printf("restarting Etherboot\n");
  74. sleep(1);
  75. longjmp(restart_etherboot, -1);
  76. /* we should not be here ... */
  77. return -1;
  78. }
  79. return rc;
  80. }
  81. static void hd(void *where, int n)
  82. {
  83. int i;
  84. while (n > 0) {
  85. printf("%X ", where);
  86. for (i = 0; i < ((n > 16) ? 16 : n); i++)
  87. printf(" %hhX", ((char *)where)[i]);
  88. printf("\n");
  89. n -= 16;
  90. where += 16;
  91. }
  92. }
  93. static int poll_imp(struct nic *nic, int retrieve, unsigned int *size_p)
  94. {
  95. static char packet[2048];
  96. static char *last_packet_p = NULL;
  97. static unsigned long last_packet_size;
  98. char *packet_p;
  99. const int eth_header_len = 14;
  100. unsigned int packet_len;
  101. int is_bcast = 0;
  102. __u16 prot, *ptr;
  103. int rc;
  104. if (0 && nic) { /* just to supress warning */
  105. return -1;
  106. }
  107. if (fatal_condition) {
  108. *size_p = 0;
  109. return 0;
  110. }
  111. if (poll_error_buf()) {
  112. fatal_condition= 1;
  113. fw_fatal= 1;
  114. printf("\n *** DEVICE FATAL ERROR ***\n");
  115. goto fatal_handling;
  116. }
  117. else if (drain_eq()) {
  118. fatal_condition= 1;
  119. printf("\n *** FATAL ERROR ***\n");
  120. goto fatal_handling;
  121. }
  122. if (retrieve) {
  123. /* we actually want to read the packet */
  124. if (last_packet_p) {
  125. eprintf("");
  126. /* there is already a packet that was previously read */
  127. memcpy(nic->packet, last_packet_p, last_packet_size);
  128. *size_p = last_packet_size;
  129. last_packet_p = NULL;
  130. return 0;
  131. }
  132. packet_p = nic->packet;
  133. } else {
  134. /* we don't want to read the packet,
  135. just know if there is one. so we
  136. read the packet to a local buffer and
  137. we will return that buffer when the ip layer wants
  138. another packet */
  139. if (last_packet_p) {
  140. /* there is already a packet that
  141. was not consumend */
  142. eprintf("overflow receive packets");
  143. return -1;
  144. }
  145. packet_p = packet;
  146. }
  147. rc = ipoib_read_packet(&prot, packet_p + eth_header_len, &packet_len,
  148. &is_bcast);
  149. if (rc) {
  150. printf("*** FATAL IN RECEIVE FLOW ****\n");
  151. goto fatal_handling;
  152. }
  153. if (packet_len == 0) {
  154. *size_p = 0;
  155. return 0;
  156. }
  157. if (is_bcast) {
  158. int i;
  159. for (i = 0; i < 6; ++i) {
  160. packet_p[i] = 0xff;
  161. }
  162. } else {
  163. packet_p[0] = MLX_ETH_BYTE0;
  164. packet_p[1] = MLX_ETH_BYTE1;
  165. packet_p[2] = MLX_ETH_BYTE2;
  166. packet_p[3] = 0;
  167. packet_p[4] = 0;
  168. packet_p[5] = 0;
  169. }
  170. memset(packet_p + 6, 0, 6);
  171. ptr = (__u16 *) (packet_p + 12);
  172. *ptr = htons(prot);
  173. if (!retrieve) {
  174. last_packet_p = packet;
  175. last_packet_size = packet_len + eth_header_len;
  176. *size_p = 0;
  177. }
  178. *size_p = packet_len + eth_header_len;
  179. tprintf("packet size=%d, prot=%x\n", *size_p, prot);
  180. if (0) {
  181. hd(nic->packet, 42);
  182. }
  183. return 0;
  184. fatal_handling:
  185. printf("restarting Etherboot\n");
  186. sleep(1);
  187. longjmp(restart_etherboot, -1);
  188. /* we should not be here ... */
  189. return -1;
  190. }