e1000e.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208
  1. /* Intel e1000/e1000e network driver.
  2. *
  3. * Targets the PCH LAN controllers used in Arrandale/Clarkdale laptops
  4. * (82577LM/82577LC, plus the 82578/82579 relations) and the plain e1000
  5. * (82540EM) that QEMU emulates. The MAC/DMA path is the classic e1000
  6. * register set with legacy 16-byte descriptors; the PHY is reached through
  7. * MDIC. Everything is polled: interrupts are masked and the ring status
  8. * bits are checked directly, like the other nebos NIC drivers.
  9. *
  10. * Mapped BAR0 (128 KB on the 82577LM) is above the 128 MB identity map, so
  11. * process_map_mmio_all() installs it in every process page directory: kernel
  12. * code runs with the current process's CR3 and the network syscalls follow
  13. * the user process.
  14. */
  15. #include "e1000e.h"
  16. #include "io.h"
  17. #include "mm.h"
  18. #include "netdev.h"
  19. #include "paging.h"
  20. #include "pci.h"
  21. #include "process.h"
  22. #include "serial.h"
  23. #include "timer.h"
  24. /* ---- register offsets (BAR0) ---- */
  25. #define REG_CTRL 0x00000
  26. #define REG_STATUS 0x00008
  27. #define REG_EERD 0x00014
  28. #define REG_CTRL_EXT 0x00018
  29. #define REG_MDIC 0x00020
  30. #define REG_PBA 0x01000
  31. #define REG_WUC 0x05800
  32. #define REG_VET 0x00038
  33. #define REG_ICR 0x000C0
  34. #define REG_IMC 0x000D8
  35. #define REG_RCTL 0x00100
  36. #define REG_TCTL 0x00400
  37. #define REG_TIPG 0x00410
  38. #define REG_RDBAL 0x02800
  39. #define REG_RDBAH 0x02804
  40. #define REG_RDLEN 0x02808
  41. #define REG_RDH 0x02810
  42. #define REG_RDT 0x02818
  43. #define REG_TDBAL 0x03800
  44. #define REG_TDBAH 0x03804
  45. #define REG_TDLEN 0x03808
  46. #define REG_TDH 0x03810
  47. #define REG_TDT 0x03818
  48. #define REG_TXDCTL0 0x03828
  49. #define REG_TXDCTL1 0x03928
  50. #define REG_TARC0 0x03840
  51. #define REG_TARC1 0x03940
  52. #define REG_RAL0 0x05400
  53. #define REG_RAH0 0x05404
  54. #define REG_GCR 0x05B00
  55. /* GCR no-snoop enables: 1 = the NIC bypasses the CPU cache for that DMA
  56. * type. A firmware that leaves the TX bits set makes the NIC read freshly
  57. * written TX descriptors from stale DRAM, so TX never completes (RX still
  58. * works because its descriptor lines were evicted long before the traffic).
  59. * Linux clears these on every ich8/pch part. */
  60. #define GCR_NO_SNOOP 0x0000003Fu
  61. /* ---- CTRL ---- */
  62. #define CTRL_RST 0x04000000u
  63. #define CTRL_GIO_MASTER_DISABLE 0x00000004u
  64. /* ---- STATUS ---- */
  65. #define STATUS_FD 0x00000001u
  66. #define STATUS_LU 0x00000002u
  67. #define STATUS_SPEED 0x000000C0u
  68. #define STATUS_LAN_INIT_DONE 0x00000200u
  69. #define STATUS_GIO_MASTER_ENABLE 0x00080000u
  70. /* ---- RCTL ---- */
  71. #define RCTL_EN 0x00000002u
  72. #define RCTL_UPE 0x00000008u
  73. #define RCTL_MPE 0x00000010u
  74. #define RCTL_LPE 0x00000020u
  75. #define RCTL_BAM 0x00008000u
  76. #define RCTL_SECRC 0x04000000u
  77. /* ---- TCTL ---- */
  78. #define TCTL_EN 0x00000002u
  79. #define TCTL_PSP 0x00000008u
  80. #define TCTL_RTLC 0x01000000u
  81. #define TCTL_CT_SHIFT 4
  82. #define TCTL_COLD_SHIFT 8
  83. #define TCTL_CT 0x10u
  84. #define TCTL_COLD 0x40u
  85. /* ---- TXDCTL (PCH LAN: descriptor write-back policy) ---- */
  86. #define TXDCTL_PTHRESH 0x0000003Fu
  87. #define TXDCTL_WTHRESH 0x003F0000u
  88. #define TXDCTL_COUNT_DESC 0x00400000u
  89. #define TXDCTL_GRAN 0x01000000u
  90. #define TXDCTL_WB_ONE 0x01010000u /* GRAN | WTHRESH=1 */
  91. #define TXDCTL_PREFETCH 0x0100001Fu /* GRAN | PTHRESH=31 */
  92. #define TXDCTL_HTHRESH 0x00000100u /* host threshold = 1 */
  93. /* ---- MDIC ---- */
  94. #define MDIC_DATA_MASK 0x0000FFFFu
  95. #define MDIC_REG_SHIFT 16
  96. #define MDIC_PHY_SHIFT 21
  97. #define MDIC_OP_WRITE 0x04000000u
  98. #define MDIC_OP_READ 0x08000000u
  99. #define MDIC_READY 0x10000000u
  100. #define MDIC_ERROR 0x40000000u
  101. /* ---- EERD ---- */
  102. #define EERD_START 0x00000001u
  103. #define EERD_DONE 0x00000010u
  104. #define EERD_ADDR_SHIFT 8
  105. #define EERD_DATA_SHIFT 16
  106. /* ---- descriptor status ---- */
  107. #define RX_DD 0x01
  108. #define RX_EOP 0x02
  109. #define TX_DD 0x01
  110. #define TX_CMD (0x01u | 0x02u | 0x08u) /* EOP | IFCS | RS */
  111. /* ---- rings ---- */
  112. #define E1000E_NRX 64
  113. #define E1000E_NTX 16
  114. #define E1000E_BUF 2048
  115. #define E1000E_TX_TIMEOUT_MS 20
  116. #define E1000E_TX_FAIL_MAX 32
  117. /* ---- PHY / MII ---- */
  118. #define MII_BMCR 0
  119. #define MII_BMSR 1
  120. #define MII_PHYID1 2
  121. #define MII_PHYID2 3
  122. #define MII_ANAR 4
  123. #define MII_GBSR 9
  124. #define BMCR_ANENABLE 0x1000
  125. #define BMCR_ANRESTART 0x0200
  126. /* ---- PCI ---- */
  127. #define E1000E_VENDOR 0x8086u
  128. struct e1000e_rx_desc {
  129. volatile unsigned int addr_lo;
  130. volatile unsigned int addr_hi;
  131. volatile unsigned short length;
  132. volatile unsigned short csum;
  133. volatile unsigned char status;
  134. volatile unsigned char errors;
  135. volatile unsigned short special;
  136. } __attribute__((packed));
  137. struct e1000e_tx_desc {
  138. volatile unsigned int addr_lo;
  139. volatile unsigned int addr_hi;
  140. volatile unsigned int lower;
  141. volatile unsigned int upper;
  142. } __attribute__((packed));
  143. static unsigned char *mmio;
  144. static int present;
  145. static int inited;
  146. static unsigned char mac[6];
  147. static unsigned int bar_base, bar_size;
  148. static unsigned int pci_bus, pci_dev, pci_func;
  149. static unsigned int device_id;
  150. static const char *detected_chip = "Intel e1000e";
  151. static struct e1000e_rx_desc *rx_ring;
  152. static struct e1000e_tx_desc *tx_ring;
  153. static unsigned char *rx_bufs;
  154. static unsigned char *tx_bufs;
  155. static unsigned int rx_cur;
  156. static unsigned int tx_cur;
  157. static unsigned int tx_pending; /* bitmask: submitted, DD not seen yet */
  158. static unsigned int tx_fail_run; /* consecutive TX timeouts */
  159. static int tx_broken; /* stop stalling the system on a dead TX */
  160. static unsigned int tctl_fixes; /* TCTL.EN re-asserts */
  161. static void tx_queue_restart(void);
  162. static int tx_ensure_enabled(void);
  163. static int phy_addr = -1;
  164. static int phy_id1 = -1, phy_id2 = -1;
  165. static int pch_lan; /* 82577/82578/82579: keep the PHY as-is */
  166. /* Counters (also reported by `netregs`). */
  167. static unsigned int tx_ok, tx_err, rx_ok, rx_err, rx_drop;
  168. static unsigned int last_tx_status, last_rx_status, last_rx_errors;
  169. static unsigned int reset_count;
  170. static int timed_out(unsigned int start_ms, unsigned int ms)
  171. {
  172. return get_ticks_ms() - start_ms > ms;
  173. }
  174. static void delay_ms(unsigned int ms)
  175. {
  176. unsigned int t0 = get_ticks_ms();
  177. while (get_ticks_ms() - t0 < ms)
  178. ;
  179. }
  180. /* ---- serial debug trail (the netlog mirror carries it to `make netmon`) ---- */
  181. static void dbg(const char *s)
  182. {
  183. serial_puts(SERIAL_COM1, "e1000e: ");
  184. serial_puts(SERIAL_COM1, s);
  185. serial_puts(SERIAL_COM1, "\n");
  186. }
  187. static void put_dec(unsigned int v)
  188. {
  189. char b[12];
  190. int i = 0;
  191. if (v == 0) {
  192. io_putchar('0');
  193. return;
  194. }
  195. while (v) {
  196. b[i++] = (char)('0' + v % 10);
  197. v /= 10;
  198. }
  199. while (i)
  200. io_putchar(b[--i]);
  201. }
  202. static void put_hex2(unsigned int v)
  203. {
  204. static const char hx[] = "0123456789ABCDEF";
  205. io_putchar(hx[(v >> 4) & 0xF]);
  206. io_putchar(hx[v & 0xF]);
  207. }
  208. static void put_mac(const unsigned char *m)
  209. {
  210. unsigned int i;
  211. for (i = 0; i < 6; i++) {
  212. put_hex2(m[i]);
  213. if (i != 5)
  214. io_putchar(':');
  215. }
  216. }
  217. /* ---- MMIO accessors (uncacheable mapping) ---- */
  218. static inline unsigned int r32(unsigned int reg)
  219. {
  220. return *(volatile unsigned int *)(mmio + reg);
  221. }
  222. static inline void w32(unsigned int reg, unsigned int v)
  223. {
  224. *(volatile unsigned int *)(mmio + reg) = v;
  225. }
  226. /* ---- PCI discovery ---- */
  227. static int supported_device(unsigned int dev)
  228. {
  229. switch (dev) {
  230. case 0x100E: /* 82540EM: QEMU's e1000 */
  231. case 0x10D3: /* 82574L: QEMU's e1000e */
  232. case 0x10EA: /* 82577LM: ThinkPad X201 */
  233. case 0x10EB: /* 82577LC */
  234. case 0x10EF: /* 82578DM */
  235. case 0x10F0: /* 82578DC */
  236. case 0x1502: /* 82579LM */
  237. case 0x1503: /* 82579V */
  238. return 1;
  239. default:
  240. return 0;
  241. }
  242. }
  243. static const char *chip_name(unsigned int dev)
  244. {
  245. switch (dev) {
  246. case 0x100E: return "Intel 82540EM (QEMU e1000)";
  247. case 0x10D3: return "Intel 82574L";
  248. case 0x10EA: return "Intel 82577LM";
  249. case 0x10EB: return "Intel 82577LC";
  250. case 0x10EF: return "Intel 82578DM";
  251. case 0x10F0: return "Intel 82578DC";
  252. case 0x1502: return "Intel 82579LM";
  253. case 0x1503: return "Intel 82579V";
  254. default: return "Intel e1000e";
  255. }
  256. }
  257. /* PCH-integrated LAN: the PHY sits behind the Kumeran interface and needs a
  258. * large set of PHY/Kumeran workarounds after a full-chip reset. Booting the
  259. * firmware has already configured it, so the driver deliberately does a warm
  260. * init on these parts (stop our RX/TX, leave CTRL.PHY_RST alone) and only
  261. * restarts autoneg if the link is down. */
  262. static int is_pch_lan(unsigned int dev)
  263. {
  264. switch (dev) {
  265. case 0x10EA: case 0x10EB: case 0x10EF: case 0x10F0:
  266. case 0x1502: case 0x1503:
  267. return 1;
  268. default:
  269. return 0;
  270. }
  271. }
  272. /* BAR0 is the 128 KB register window on every supported part. Handle a
  273. * 64-bit BAR and probe its size with the usual all-ones trick. */
  274. static int probe_bar0(unsigned int bus, unsigned int dev, unsigned int func,
  275. unsigned int *base, unsigned int *size)
  276. {
  277. unsigned int val = pci_cfg_read32(bus, dev, func, 0x10);
  278. unsigned int hi = 0, mask, len;
  279. if (!val || val == 0xFFFFFFFFu || (val & 1u))
  280. return -1;
  281. if (val & 4u) {
  282. hi = pci_cfg_read32(bus, dev, func, 0x14);
  283. pci_cfg_write32(bus, dev, func, 0x14, 0xFFFFFFFFu);
  284. }
  285. pci_cfg_write32(bus, dev, func, 0x10, 0xFFFFFFFFu);
  286. mask = pci_cfg_read32(bus, dev, func, 0x10) & 0xFFFFFFF0u;
  287. pci_cfg_write32(bus, dev, func, 0x10, val);
  288. if (val & 4u)
  289. pci_cfg_write32(bus, dev, func, 0x14, hi);
  290. if (!mask || mask == 0xFFFFFFF0u)
  291. return -1;
  292. len = ~mask + 1u;
  293. if (len < 0x1000)
  294. len = 0x1000;
  295. if (len > 0x100000)
  296. len = 0x100000; /* sanity: all supported BARs are 128 KB */
  297. *base = val & 0xFFFFFFF0u;
  298. *size = len;
  299. return 0;
  300. }
  301. static int probe_pci(void)
  302. {
  303. unsigned int bus, dev, func;
  304. for (bus = 0; bus < 256; bus++) {
  305. for (dev = 0; dev < 32; dev++) {
  306. unsigned int id = pci_cfg_read32(bus, dev, 0, 0x00);
  307. unsigned int htype, nfunc;
  308. if (id == 0xFFFFFFFFu || id == 0)
  309. continue;
  310. htype = (pci_cfg_read32(bus, dev, 0, 0x0C) >> 16) & 0xFFu;
  311. nfunc = (htype & 0x80u) ? 8u : 1u;
  312. for (func = 0; func < nfunc; func++) {
  313. unsigned int idf, cmd;
  314. idf = pci_cfg_read32(bus, dev, func, 0x00);
  315. if (idf == 0xFFFFFFFFu || idf == 0)
  316. continue;
  317. if ((idf & 0xFFFFu) != E1000E_VENDOR)
  318. continue;
  319. if (!supported_device((idf >> 16) & 0xFFFFu))
  320. continue;
  321. /* Memory space + bus master. */
  322. cmd = pci_cfg_read32(bus, dev, func, 0x04);
  323. pci_cfg_write32(bus, dev, func, 0x04,
  324. cmd | 0x0006u);
  325. if (probe_bar0(bus, dev, func,
  326. &bar_base, &bar_size) != 0)
  327. continue;
  328. pci_bus = bus;
  329. pci_dev = dev;
  330. pci_func = func;
  331. device_id = (idf >> 16) & 0xFFFFu;
  332. detected_chip = chip_name(device_id);
  333. pch_lan = is_pch_lan(device_id);
  334. return 0;
  335. }
  336. }
  337. }
  338. return -1;
  339. }
  340. /* ---- MAC address ---- */
  341. /* Classic EERD word read; used only when RAL/RAH came back invalid. */
  342. static int eeprom_read16(unsigned int addr, unsigned short *out)
  343. {
  344. unsigned int t0, v;
  345. w32(REG_EERD, (addr << EERD_ADDR_SHIFT) | EERD_START);
  346. t0 = get_ticks_ms();
  347. for (;;) {
  348. v = r32(REG_EERD);
  349. if (v & EERD_DONE) {
  350. *out = (unsigned short)(v >> EERD_DATA_SHIFT);
  351. return 0;
  352. }
  353. if (timed_out(t0, 5))
  354. return -1;
  355. }
  356. }
  357. static int mac_valid(const unsigned char *m)
  358. {
  359. unsigned int i;
  360. int zero = 1, ones = 1;
  361. for (i = 0; i < 6; i++) {
  362. if (m[i] != 0x00)
  363. zero = 0;
  364. if (m[i] != 0xFF)
  365. ones = 0;
  366. }
  367. return !zero && !ones;
  368. }
  369. static void read_mac(void)
  370. {
  371. unsigned int ral = r32(REG_RAL0);
  372. unsigned int rah = r32(REG_RAH0);
  373. mac[0] = (unsigned char)(ral & 0xFF);
  374. mac[1] = (unsigned char)((ral >> 8) & 0xFF);
  375. mac[2] = (unsigned char)((ral >> 16) & 0xFF);
  376. mac[3] = (unsigned char)((ral >> 24) & 0xFF);
  377. mac[4] = (unsigned char)(rah & 0xFF);
  378. mac[5] = (unsigned char)((rah >> 8) & 0xFF);
  379. if (!mac_valid(mac)) {
  380. unsigned short w0 = 0, w1 = 0, w2 = 0;
  381. if (eeprom_read16(0, &w0) == 0 &&
  382. eeprom_read16(1, &w1) == 0 &&
  383. eeprom_read16(2, &w2) == 0) {
  384. mac[0] = (unsigned char)(w0 & 0xFF);
  385. mac[1] = (unsigned char)(w0 >> 8);
  386. mac[2] = (unsigned char)(w1 & 0xFF);
  387. mac[3] = (unsigned char)(w1 >> 8);
  388. mac[4] = (unsigned char)(w2 & 0xFF);
  389. mac[5] = (unsigned char)(w2 >> 8);
  390. }
  391. }
  392. /* Program the unicast filter (RAH first, then RAL on these parts).
  393. * Promiscuous mode is on as well for bring-up, but a valid RAL/RAH
  394. * keeps the hardware filter sane if UPE is ever turned off. */
  395. w32(REG_RAH0, ((unsigned int)mac[5] << 8) | mac[4]);
  396. w32(REG_RAL0, (unsigned int)mac[0] | ((unsigned int)mac[1] << 8) |
  397. ((unsigned int)mac[2] << 16) | ((unsigned int)mac[3] << 24));
  398. }
  399. /* ---- PHY access via MDIC ---- */
  400. static int mdic_read(unsigned int phy, unsigned int reg)
  401. {
  402. unsigned int t0, v;
  403. w32(REG_MDIC, (reg << MDIC_REG_SHIFT) | (phy << MDIC_PHY_SHIFT) |
  404. MDIC_OP_READ);
  405. t0 = get_ticks_ms();
  406. for (;;) {
  407. v = r32(REG_MDIC);
  408. if (v & MDIC_READY)
  409. return (v & MDIC_ERROR) ? -1 : (int)(v & MDIC_DATA_MASK);
  410. if (timed_out(t0, 10))
  411. return -1;
  412. }
  413. }
  414. static int mdic_write(unsigned int phy, unsigned int reg, unsigned int data)
  415. {
  416. unsigned int t0, v;
  417. w32(REG_MDIC, (data & MDIC_DATA_MASK) | (reg << MDIC_REG_SHIFT) |
  418. (phy << MDIC_PHY_SHIFT) | MDIC_OP_WRITE);
  419. t0 = get_ticks_ms();
  420. for (;;) {
  421. v = r32(REG_MDIC);
  422. if (v & MDIC_READY)
  423. return (v & MDIC_ERROR) ? -1 : 0;
  424. if (timed_out(t0, 10))
  425. return -1;
  426. }
  427. }
  428. static void phy_probe(void)
  429. {
  430. unsigned int phy;
  431. phy_addr = -1;
  432. phy_id1 = phy_id2 = -1;
  433. for (phy = 0; phy < 4; phy++) {
  434. int id1 = mdic_read(phy, MII_PHYID1);
  435. int id2 = mdic_read(phy, MII_PHYID2);
  436. if (id1 < 0 || id2 < 0)
  437. continue;
  438. if ((id1 & 0xFFFF) == 0 && (id2 & 0xFFFF) == 0)
  439. continue;
  440. if ((id1 & 0xFFFF) == 0xFFFF)
  441. continue;
  442. phy_addr = (int)phy;
  443. phy_id1 = id1;
  444. phy_id2 = id2;
  445. break;
  446. }
  447. }
  448. static void phy_autoneg(void)
  449. {
  450. if (phy_addr < 0)
  451. return;
  452. mdic_write(phy_addr, MII_ANAR, 0x01E1); /* 10/100 half+full */
  453. mdic_write(phy_addr, MII_GBSR, 0x0300); /* 1000 half+full */
  454. mdic_write(phy_addr, MII_BMCR, BMCR_ANENABLE | BMCR_ANRESTART);
  455. }
  456. /* ---- hardware bring-up ---- */
  457. /* Quiesce the MAC without touching the PHY: mask interrupts, stop RX/TX and
  458. * let any in-flight DMA finish. This is the "reset" path on PCH LAN parts. */
  459. static void hw_stop(void)
  460. {
  461. w32(REG_IMC, 0xFFFFFFFFu);
  462. (void)r32(REG_ICR);
  463. w32(REG_RCTL, 0);
  464. w32(REG_TCTL, TCTL_PSP);
  465. (void)r32(REG_STATUS); /* flush posted writes */
  466. delay_ms(10);
  467. }
  468. /* PCH LAN with AMT: the firmware (ME) must be told that the OS driver owns
  469. * the network interface, otherwise it can keep the LAN - notably the TX
  470. * path - to itself. e1000e's e1000e_get_hw_control() sets
  471. * CTRL_EXT.DRV_LOAD for parts with FLAG_HAS_CTRLEXT_ON_LOAD (the pch_info
  472. * used by the 82577LM/82578/82579). Do it right after the MAC reset, before
  473. * the rings are programmed, exactly where e1000e calls it. */
  474. static void pch_claim(void)
  475. {
  476. unsigned int ctrl_ext;
  477. if (!pch_lan)
  478. return;
  479. ctrl_ext = r32(REG_CTRL_EXT);
  480. if (!(ctrl_ext & 0x10000000u)) {
  481. w32(REG_CTRL_EXT, ctrl_ext | 0x10000000u);
  482. dbg("AMT handshake: CTRL_EXT.DRV_LOAD set");
  483. }
  484. /* e1000e_reset(): clear wake-up control and enable VLAN EtherType.
  485. * PBA is only read/reported: writing the generic PCH default of 26
  486. * would set the TX half to zero on split-PBA parts (verified on
  487. * QEMU's 82540: 0x00100030 -> 0x0000001A). */
  488. w32(REG_WUC, 0);
  489. w32(REG_VET, 0x8100);
  490. serial_puts(SERIAL_COM1, "e1000e: pba ");
  491. serial_puthex(SERIAL_COM1, r32(REG_PBA));
  492. serial_puts(SERIAL_COM1, "\n");
  493. }
  494. static int hw_reset(void)
  495. {
  496. unsigned int t0, ctrl;
  497. hw_stop();
  498. /* Block new DMA requests and wait for the last TLP to finish before
  499. * hitting the MAC with a global reset (same order as e1000e). */
  500. ctrl = r32(REG_CTRL);
  501. w32(REG_CTRL, ctrl | CTRL_GIO_MASTER_DISABLE);
  502. t0 = get_ticks_ms();
  503. while ((r32(REG_STATUS) & STATUS_GIO_MASTER_ENABLE) &&
  504. !timed_out(t0, 1000))
  505. ;
  506. w32(REG_CTRL, r32(REG_CTRL) | CTRL_RST);
  507. t0 = get_ticks_ms();
  508. while (r32(REG_CTRL) & CTRL_RST) {
  509. if (timed_out(t0, 1000))
  510. return -1;
  511. }
  512. delay_ms(20); /* NVM auto-read after reset */
  513. /* Wait for the NVM auto-read to finish and clear the done bit. */
  514. t0 = get_ticks_ms();
  515. while (!(r32(REG_STATUS) & STATUS_LAN_INIT_DONE) &&
  516. !timed_out(t0, 200))
  517. ;
  518. w32(REG_STATUS, r32(REG_STATUS) & ~STATUS_LAN_INIT_DONE);
  519. reset_count++;
  520. return 0;
  521. }
  522. static void setup_rings(void)
  523. {
  524. unsigned int i;
  525. for (i = 0; i < E1000E_NRX; i++) {
  526. rx_ring[i].addr_lo = (unsigned int)(rx_bufs + i * E1000E_BUF);
  527. rx_ring[i].addr_hi = 0;
  528. rx_ring[i].length = 0;
  529. rx_ring[i].csum = 0;
  530. rx_ring[i].status = 0;
  531. rx_ring[i].errors = 0;
  532. rx_ring[i].special = 0;
  533. }
  534. for (i = 0; i < E1000E_NTX; i++) {
  535. tx_ring[i].addr_lo = (unsigned int)(tx_bufs + i * E1000E_BUF);
  536. tx_ring[i].addr_hi = 0;
  537. tx_ring[i].lower = 0;
  538. tx_ring[i].upper = 0;
  539. }
  540. __sync_synchronize();
  541. w32(REG_RDBAL, (unsigned int)rx_ring);
  542. w32(REG_RDBAH, 0);
  543. w32(REG_RDLEN, E1000E_NRX * (unsigned int)sizeof(struct e1000e_rx_desc));
  544. w32(REG_RDH, 0);
  545. w32(REG_RDT, E1000E_NRX - 1);
  546. w32(REG_TDBAL, (unsigned int)tx_ring);
  547. w32(REG_TDBAH, 0);
  548. w32(REG_TDLEN, E1000E_NTX * (unsigned int)sizeof(struct e1000e_tx_desc));
  549. w32(REG_TDH, 0);
  550. w32(REG_TDT, 0);
  551. rx_cur = 0;
  552. tx_cur = 0;
  553. tx_pending = 0;
  554. tx_fail_run = 0;
  555. tx_broken = 0;
  556. }
  557. /* PCH LAN: program the TX descriptor write-back policy and arbitration bits
  558. * that e1000e's ich8lan init sets. Without WTHRESH/COUNT_DESC the 82577 was
  559. * observed to never report TX descriptor completion (tx_ok stayed 0), while
  560. * RX worked. */
  561. static void tx_desc_config(void)
  562. {
  563. unsigned int v, gcr;
  564. /* Enable snooping for TX/RX DMA (see GCR_NO_SNOOP). */
  565. gcr = r32(REG_GCR);
  566. w32(REG_GCR, gcr & ~GCR_NO_SNOOP);
  567. serial_puts(SERIAL_COM1, "e1000e: gcr ");
  568. serial_puthex(SERIAL_COM1, gcr);
  569. serial_puts(SERIAL_COM1, " -> ");
  570. serial_puthex(SERIAL_COM1, gcr & ~GCR_NO_SNOOP);
  571. serial_puts(SERIAL_COM1, "\n");
  572. /* CTRL_EXT bits e1000e's ich8 init sets: relaxed-ordering disable,
  573. * the always-set bit 22, and PHY power-down in D3. */
  574. v = r32(REG_CTRL_EXT);
  575. v |= 0x00020000u | 0x00400000u | 0x00100000u;
  576. w32(REG_CTRL_EXT, v);
  577. v = r32(REG_TXDCTL0);
  578. v |= TXDCTL_COUNT_DESC;
  579. v = (v & ~TXDCTL_WTHRESH) | TXDCTL_WB_ONE;
  580. v = (v & ~TXDCTL_PTHRESH) | TXDCTL_PREFETCH;
  581. v |= TXDCTL_HTHRESH;
  582. w32(REG_TXDCTL0, v);
  583. v = r32(REG_TXDCTL1);
  584. v |= TXDCTL_COUNT_DESC;
  585. v = (v & ~TXDCTL_WTHRESH) | TXDCTL_WB_ONE;
  586. v = (v & ~TXDCTL_PTHRESH) | TXDCTL_PREFETCH;
  587. v |= TXDCTL_HTHRESH;
  588. w32(REG_TXDCTL1, v);
  589. /* TARC queue arbitration workarounds from the PCH init. */
  590. w32(REG_TARC0, r32(REG_TARC0) | 0x0D800000u);
  591. w32(REG_TARC1, r32(REG_TARC1) | 0x51000000u);
  592. }
  593. static void hw_start(void)
  594. {
  595. setup_rings();
  596. w32(REG_RCTL, RCTL_EN | RCTL_UPE | RCTL_MPE | RCTL_BAM | RCTL_SECRC);
  597. if (pch_lan)
  598. tx_desc_config();
  599. w32(REG_TCTL, TCTL_EN | TCTL_PSP | TCTL_RTLC |
  600. (TCTL_CT << TCTL_CT_SHIFT) |
  601. (TCTL_COLD << TCTL_COLD_SHIFT));
  602. w32(REG_TIPG, 10u | (8u << 10) | (6u << 20));
  603. __sync_synchronize();
  604. }
  605. /* ---- netdev interface ---- */
  606. static int e1000e_init(void)
  607. {
  608. char buf[64];
  609. unsigned int i;
  610. if (inited)
  611. return present ? 0 : -1;
  612. inited = 1;
  613. if (probe_pci() != 0) {
  614. dbg("no supported Intel NIC");
  615. return -1;
  616. }
  617. process_map_mmio_all(bar_base, bar_size);
  618. mmio = (unsigned char *)(unsigned long)bar_base;
  619. if (r32(REG_STATUS) == 0xFFFFFFFFu) {
  620. dbg("MMIO read failed");
  621. mmio = 0;
  622. return -1;
  623. }
  624. i = 0;
  625. /* "PCI 00:19.0 f2500000 128K" */
  626. {
  627. static const char hx[] = "0123456789ABCDEF";
  628. unsigned int n = 0;
  629. buf[i++] = 'P'; buf[i++] = 'C'; buf[i++] = 'I'; buf[i++] = ' ';
  630. for (n = 0; n < 2; n++)
  631. buf[i++] = hx[(pci_bus >> (4 * (1 - n))) & 0xF];
  632. buf[i++] = ':';
  633. for (n = 0; n < 2; n++)
  634. buf[i++] = hx[(pci_dev >> (4 * (1 - n))) & 0xF];
  635. buf[i++] = '.';
  636. buf[i++] = (char)('0' + pci_func);
  637. buf[i++] = ' ';
  638. for (n = 0; n < 8; n++)
  639. buf[i++] = hx[(bar_base >> (4 * (7 - n))) & 0xF];
  640. buf[i++] = ' ';
  641. buf[i] = '\0';
  642. }
  643. dbg(buf);
  644. /* MAC-only reset: CTRL.PHY_RST is deliberately never set, so the
  645. * firmware's PHY/Kumeran setup (and the link) survives, while the MAC
  646. * registers - including whatever TX queue state the BIOS UNDI left
  647. * behind - go back to their defaults. e1000e does the same on parts
  648. * where the ME owns the PHY. */
  649. if (hw_reset() != 0) {
  650. dbg("MAC reset timeout");
  651. mmio = 0;
  652. return -1;
  653. }
  654. dbg("reset ok");
  655. pch_claim();
  656. read_mac();
  657. /* All ring and buffer memory in one allocation: the page allocator is
  658. * IRQ-safe but not cross-CPU locked, so two separate calls can (and
  659. * once did) hand out the same page under boot-time concurrency. A
  660. * single contiguous run cannot alias itself. */
  661. {
  662. unsigned int pages = 2 +
  663. (E1000E_NRX * E1000E_BUF) / PAGE_SIZE +
  664. (E1000E_NTX * E1000E_BUF) / PAGE_SIZE;
  665. unsigned int mem = mm_alloc_pages(pages);
  666. if (mem) {
  667. rx_ring = (struct e1000e_rx_desc *)mem;
  668. tx_ring = (struct e1000e_tx_desc *)(mem + PAGE_SIZE);
  669. rx_bufs = (unsigned char *)(mem + 2 * PAGE_SIZE);
  670. tx_bufs = rx_bufs + E1000E_NRX * E1000E_BUF;
  671. }
  672. }
  673. serial_puts(SERIAL_COM1, "e1000e: ring mem rx=");
  674. serial_puthex(SERIAL_COM1, (unsigned int)rx_ring);
  675. serial_puts(SERIAL_COM1, " tx=");
  676. serial_puthex(SERIAL_COM1, (unsigned int)tx_ring);
  677. serial_puts(SERIAL_COM1, " rxb=");
  678. serial_puthex(SERIAL_COM1, (unsigned int)rx_bufs);
  679. serial_puts(SERIAL_COM1, " txb=");
  680. serial_puthex(SERIAL_COM1, (unsigned int)tx_bufs);
  681. serial_puts(SERIAL_COM1, "\n");
  682. if (!rx_ring || !tx_ring || !rx_bufs || !tx_bufs) {
  683. dbg("no memory for rings");
  684. mmio = 0;
  685. return -1;
  686. }
  687. phy_probe();
  688. /* The 82577 PHY is at MDIC address 1 even when the probe could not
  689. * read its ID (the PCH needs a slow-MDIO mode we do not program); keep
  690. * the address so a link-down autoneg attempt can still go out. */
  691. if (pch_lan && phy_addr < 0)
  692. phy_addr = 1;
  693. hw_start();
  694. {
  695. unsigned int st = r32(REG_STATUS);
  696. dbg(st & STATUS_LU ? "link up" : "link started");
  697. }
  698. present = 1;
  699. /* "<chip> <mac>" */
  700. i = 0;
  701. for (const char *p = detected_chip; *p && i + 1 < sizeof(buf); p++)
  702. buf[i++] = *p;
  703. buf[i++] = ' ';
  704. for (unsigned int j = 0; j < 6 && i + 4 < sizeof(buf); j++) {
  705. static const char hx[] = "0123456789ABCDEF";
  706. buf[i++] = hx[(mac[j] >> 4) & 0xF];
  707. buf[i++] = hx[mac[j] & 0xF];
  708. if (j != 5)
  709. buf[i++] = ':';
  710. }
  711. buf[i] = '\0';
  712. dbg(buf);
  713. if (!(r32(REG_STATUS) & STATUS_LU))
  714. phy_autoneg();
  715. tx_ensure_enabled();
  716. return 0;
  717. }
  718. static void e1000e_get_mac(unsigned char out[6])
  719. {
  720. unsigned int i;
  721. for (i = 0; i < 6; i++)
  722. out[i] = mac[i];
  723. }
  724. static int e1000e_rx(unsigned char *buf, unsigned int maxlen)
  725. {
  726. unsigned int guard = 0;
  727. if (!present || !mmio)
  728. return -1;
  729. while (guard++ < 8) {
  730. unsigned int entry = rx_cur;
  731. struct e1000e_rx_desc *d = &rx_ring[entry];
  732. unsigned int status = d->status;
  733. unsigned int len;
  734. if (!(status & RX_DD))
  735. return -1; /* nothing pending */
  736. __sync_synchronize();
  737. last_rx_status = status;
  738. last_rx_errors = d->errors;
  739. if ((status & RX_EOP) && d->errors == 0) {
  740. len = d->length;
  741. if (len >= 14 && len <= maxlen) {
  742. unsigned char *src = rx_bufs +
  743. entry * E1000E_BUF;
  744. unsigned int i;
  745. for (i = 0; i < len; i++)
  746. buf[i] = src[i];
  747. rx_ok++;
  748. d->status = 0;
  749. __sync_synchronize();
  750. w32(REG_RDT, entry);
  751. rx_cur = (entry + 1) % E1000E_NRX;
  752. return (int)len;
  753. }
  754. rx_drop++;
  755. } else {
  756. rx_err++;
  757. }
  758. /* Drop this descriptor and give it back to the hardware. */
  759. d->status = 0;
  760. __sync_synchronize();
  761. w32(REG_RDT, entry);
  762. rx_cur = (entry + 1) % E1000E_NRX;
  763. }
  764. return -1;
  765. }
  766. static int tx_timeout(void)
  767. {
  768. tx_err++;
  769. if (++tx_fail_run >= E1000E_TX_FAIL_MAX)
  770. tx_broken = 1;
  771. return -1;
  772. }
  773. /* The TX engine is not moving (TDH stuck): toggle TCTL.EN and re-arm the
  774. * ring. Any descriptor the hardware never retired is simply dropped; the
  775. * network stack retries the frame. This also makes the next TDT write a
  776. * real 0 -> 1 transition again, in case the first doorbell was lost while
  777. * the queue was disabled. */
  778. static void tx_queue_restart(void)
  779. {
  780. unsigned int tctl = r32(REG_TCTL);
  781. w32(REG_TCTL, tctl & ~TCTL_EN);
  782. delay_ms(1);
  783. w32(REG_TDBAL, (unsigned int)tx_ring);
  784. w32(REG_TDBAH, 0);
  785. w32(REG_TDLEN, (unsigned int)(E1000E_NTX *
  786. sizeof(struct e1000e_tx_desc)));
  787. w32(REG_TDH, 0);
  788. w32(REG_TDT, 0);
  789. w32(REG_TCTL, tctl | TCTL_EN);
  790. __sync_synchronize();
  791. tx_cur = 0;
  792. tx_pending = 0;
  793. }
  794. /* The MAC may clear TCTL.EN on a link transition; make sure it is set before
  795. * a send. Returns 1 when it had to be re-enabled. */
  796. static int tx_ensure_enabled(void)
  797. {
  798. unsigned int tctl = r32(REG_TCTL);
  799. if (tctl & TCTL_EN)
  800. return 0;
  801. w32(REG_TCTL, tctl | TCTL_EN);
  802. tctl_fixes++;
  803. return 1;
  804. }
  805. static int e1000e_tx(const unsigned char *buf, unsigned int len)
  806. {
  807. static unsigned char pad[60];
  808. struct e1000e_tx_desc *d;
  809. unsigned int entry, t0;
  810. const unsigned char *p = buf;
  811. unsigned int txlen = len;
  812. if (!present || !mmio)
  813. return -1;
  814. /* Once TX has failed repeatedly, fail instantly: the netlog flush and
  815. * the DHCP/ping loops must not hold the BKL for 100 ms per frame on a
  816. * NIC whose TX does not complete. `netreset` clears this. */
  817. if (tx_broken)
  818. return -1;
  819. if (len < 14 || len > 1514)
  820. return -1;
  821. tx_ensure_enabled();
  822. if (len < 60) {
  823. unsigned int i;
  824. for (i = 0; i < len; i++)
  825. pad[i] = buf[i];
  826. for (i = len; i < 60; i++)
  827. pad[i] = 0;
  828. p = pad;
  829. txlen = 60;
  830. }
  831. entry = tx_cur;
  832. d = &tx_ring[entry];
  833. /* A previous command on this slot that timed out may still be in
  834. * flight; wait for it before reuse. */
  835. if (tx_pending & (1u << entry)) {
  836. t0 = get_ticks_ms();
  837. while (!(d->upper & TX_DD)) {
  838. if (timed_out(t0, E1000E_TX_TIMEOUT_MS)) {
  839. /* The hardware never retired this
  840. * descriptor: restart the TX queue and
  841. * drop the slot. */
  842. tx_queue_restart();
  843. return tx_timeout();
  844. }
  845. }
  846. tx_pending &= ~(1u << entry);
  847. }
  848. {
  849. unsigned char *dst = tx_bufs + entry * E1000E_BUF;
  850. unsigned int i;
  851. for (i = 0; i < txlen; i++)
  852. dst[i] = p[i];
  853. }
  854. d->addr_lo = (unsigned int)(tx_bufs + entry * E1000E_BUF);
  855. d->addr_hi = 0;
  856. d->lower = txlen | (TX_CMD << 24);
  857. d->upper = 0;
  858. __sync_synchronize();
  859. tx_pending |= 1u << entry;
  860. w32(REG_TDT, (entry + 1) % E1000E_NTX);
  861. t0 = get_ticks_ms();
  862. while (!(d->upper & TX_DD)) {
  863. if (timed_out(t0, E1000E_TX_TIMEOUT_MS)) {
  864. /* Leave the pending bit set: the next TX on this slot
  865. * waits for it before reuse. */
  866. return tx_timeout();
  867. }
  868. }
  869. last_tx_status = d->upper;
  870. tx_pending &= ~(1u << entry);
  871. tx_fail_run = 0;
  872. tx_ok++;
  873. tx_cur = (entry + 1) % E1000E_NTX;
  874. return 0;
  875. }
  876. static void e1000e_print_info(void)
  877. {
  878. unsigned int st, bmcr = 0, bmsr = 0;
  879. if (!present || !mmio) {
  880. io_putstr("e1000e: no NIC\n");
  881. return;
  882. }
  883. st = r32(REG_STATUS);
  884. io_putstr("chip: ");
  885. io_putstr(detected_chip);
  886. io_putstr("\npci ");
  887. put_dec(pci_bus); io_putchar(':');
  888. put_dec(pci_dev); io_putchar('.');
  889. put_dec(pci_func);
  890. io_putstr(" bar0=0x");
  891. {
  892. static const char hx[] = "0123456789ABCDEF";
  893. unsigned int i;
  894. for (i = 0; i < 8; i++)
  895. io_putchar(hx[(bar_base >> (4 * (7 - i))) & 0xF]);
  896. }
  897. io_putstr(" mac ");
  898. put_mac(mac);
  899. io_putstr("\nlink ");
  900. if (st & STATUS_LU) {
  901. io_putstr((st & STATUS_FD) ? "up full" : "up half");
  902. io_putstr(" ");
  903. switch (st & STATUS_SPEED) {
  904. case 0x00: io_putstr("10M"); break;
  905. case 0x40: io_putstr("100M"); break;
  906. case 0x80: io_putstr("1000M"); break;
  907. default: io_putstr("?M"); break;
  908. }
  909. } else {
  910. io_putstr("down");
  911. }
  912. io_putstr(" status=0x");
  913. io_puthex(st);
  914. io_putstr("\nphy ");
  915. if (phy_addr >= 0) {
  916. put_dec((unsigned int)phy_addr);
  917. io_putstr(" id ");
  918. put_hex2((unsigned int)(phy_id1 >> 8) & 0xFF);
  919. put_hex2((unsigned int)phy_id1 & 0xFF);
  920. io_putchar(':');
  921. put_hex2((unsigned int)(phy_id2 >> 8) & 0xFF);
  922. put_hex2((unsigned int)phy_id2 & 0xFF);
  923. bmcr = (unsigned int)mdic_read((unsigned int)phy_addr, MII_BMCR);
  924. bmsr = (unsigned int)mdic_read((unsigned int)phy_addr, MII_BMSR);
  925. io_putstr(" bmcr=0x");
  926. io_puthex(bmcr);
  927. io_putstr(" bmsr=0x");
  928. io_puthex(bmsr);
  929. } else {
  930. io_putstr("none");
  931. }
  932. io_putstr("txdctl=0x");
  933. io_puthex(r32(REG_TXDCTL0));
  934. io_putstr(" tarc=0x");
  935. io_puthex(r32(REG_TARC0));
  936. io_putstr(" gcr=0x");
  937. io_puthex(r32(REG_GCR));
  938. io_putstr(" pba=0x");
  939. io_puthex(r32(REG_PBA));
  940. io_putstr(" tdh=0x");
  941. io_puthex(r32(REG_TDH));
  942. io_putstr(" tdt=0x");
  943. io_puthex(r32(REG_TDT));
  944. io_putchar('\n');
  945. io_putstr("rx ok ");
  946. put_dec(rx_ok);
  947. io_putstr(" err ");
  948. put_dec(rx_err);
  949. io_putstr(" drop ");
  950. put_dec(rx_drop);
  951. io_putstr(" tx ok ");
  952. put_dec(tx_ok);
  953. io_putstr(" err ");
  954. put_dec(tx_err);
  955. io_putstr(" broken ");
  956. put_dec((unsigned int)tx_broken);
  957. io_putstr(" tctl_fix ");
  958. put_dec(tctl_fixes);
  959. io_putstr(" resets ");
  960. put_dec(reset_count);
  961. io_putchar('\n');
  962. }
  963. static void e1000e_dump_regs(void)
  964. {
  965. static const struct {
  966. const char *name;
  967. unsigned int reg;
  968. } regs[] = {
  969. { "CTRL", REG_CTRL }, { "STATUS", REG_STATUS },
  970. { "CTRL_EXT", REG_CTRL_EXT }, { "EERD", REG_EERD },
  971. { "MDIC", REG_MDIC }, { "ICR", REG_ICR },
  972. { "PBA", REG_PBA }, { "WUC", REG_WUC },
  973. { "RCTL", REG_RCTL }, { "TCTL", REG_TCTL },
  974. { "TIPG", REG_TIPG }, { "RAL0", REG_RAL0 },
  975. { "RAH0", REG_RAH0 }, { "RDBAL", REG_RDBAL },
  976. { "RDLEN", REG_RDLEN }, { "RDH", REG_RDH },
  977. { "RDT", REG_RDT }, { "TDBAL", REG_TDBAL },
  978. { "TDLEN", REG_TDLEN }, { "TDH", REG_TDH },
  979. { "TDT", REG_TDT }, { "TXDCTL0", REG_TXDCTL0 },
  980. { "TXDCTL1", REG_TXDCTL1 }, { "TARC0", REG_TARC0 },
  981. { "TARC1", REG_TARC1 }, { "GCR", REG_GCR },
  982. };
  983. unsigned int i;
  984. if (!present || !mmio) {
  985. io_putstr("e1000e: no NIC\n");
  986. return;
  987. }
  988. for (i = 0; i < sizeof(regs) / sizeof(regs[0]); i++) {
  989. io_putstr(regs[i].name);
  990. io_putchar('=');
  991. io_puthex(r32(regs[i].reg));
  992. if ((i & 1) == 1)
  993. io_putchar('\n');
  994. else
  995. io_putstr(" ");
  996. }
  997. if (i & 1)
  998. io_putchar('\n');
  999. io_putstr("rings rx=0x");
  1000. io_puthex((unsigned int)rx_ring);
  1001. io_putstr(" tx=0x");
  1002. io_puthex((unsigned int)tx_ring);
  1003. io_putstr(" rx_cur=");
  1004. put_dec(rx_cur);
  1005. io_putstr(" tx_cur=");
  1006. put_dec(tx_cur);
  1007. io_putstr(" tx_pending=0x");
  1008. io_puthex(tx_pending);
  1009. io_putchar('\n');
  1010. io_putstr("state rx_ok=");
  1011. put_dec(rx_ok);
  1012. io_putstr(" rx_err=");
  1013. put_dec(rx_err);
  1014. io_putstr(" rx_drop=");
  1015. put_dec(rx_drop);
  1016. io_putstr(" tx_ok=");
  1017. put_dec(tx_ok);
  1018. io_putstr(" tx_err=");
  1019. put_dec(tx_err);
  1020. io_putstr(" tx_broken=");
  1021. put_dec((unsigned int)tx_broken);
  1022. io_putstr(" tx_fail_run=");
  1023. put_dec(tx_fail_run);
  1024. io_putstr(" tctl_fix=");
  1025. put_dec(tctl_fixes);
  1026. io_putstr(" reset=");
  1027. put_dec(reset_count);
  1028. io_putchar('\n');
  1029. io_putstr("last rx status=0x");
  1030. io_puthex(last_rx_status);
  1031. io_putstr(" errors=0x");
  1032. io_puthex(last_rx_errors);
  1033. io_putstr(" tx status=0x");
  1034. io_puthex(last_tx_status);
  1035. io_putchar('\n');
  1036. if (tx_ring) {
  1037. io_putstr("tx0 addr=0x");
  1038. io_puthex(tx_ring[0].addr_lo);
  1039. io_putstr(" lower=0x");
  1040. io_puthex(tx_ring[0].lower);
  1041. io_putstr(" upper=0x");
  1042. io_puthex(tx_ring[0].upper);
  1043. io_putchar('\n');
  1044. }
  1045. }
  1046. static void e1000e_reset(void)
  1047. {
  1048. if (!present || !mmio || !rx_ring) {
  1049. io_putstr("e1000e: reset: not initialized\n");
  1050. return;
  1051. }
  1052. if (hw_reset() != 0) {
  1053. io_putstr("e1000e: reset timeout\n");
  1054. return;
  1055. }
  1056. pch_claim();
  1057. read_mac();
  1058. hw_start();
  1059. if (!(r32(REG_STATUS) & STATUS_LU))
  1060. phy_autoneg();
  1061. tx_ensure_enabled();
  1062. io_putstr("e1000e: netreset done\n");
  1063. }
  1064. const struct netdev e1000e_netdev = {
  1065. "e1000e", "Intel e1000e",
  1066. e1000e_init, e1000e_get_mac, e1000e_rx, e1000e_tx, e1000e_print_info,
  1067. e1000e_dump_regs, 0, e1000e_reset,
  1068. };