PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/e1000-2.x/e1000_main.c

https://github.com/bhesmans/click
C | 4185 lines | 2319 code | 577 blank | 1289 comment | 491 complexity | c752713a14b002fc5251b0bcf6b65467 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause
  1. /*****************************************************************************
  2. *****************************************************************************
  3. Copyright (c) 1999 - 2000, Intel Corporation
  4. All rights reserved.
  5. Redistribution and use in source and binary forms, with or without
  6. modification, are permitted provided that the following conditions are met:
  7. 1. Redistributions of source code must retain the above copyright notice,
  8. this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above copyright notice,
  10. this list of conditions and the following disclaimer in the documentation
  11. and/or other materials provided with the distribution.
  12. 3. Neither the name of Intel Corporation nor the names of its contributors
  13. may be used to endorse or promote products derived from this software
  14. without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
  16. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  19. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  20. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  22. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  24. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. *****************************************************************************
  26. ****************************************************************************/
  27. /**********************************************************************
  28. * *
  29. * INTEL CORPORATION *
  30. * *
  31. * This software is supplied under the terms of the license included *
  32. * above. All use of this driver must be in accordance with the terms *
  33. * of that license. *
  34. * *
  35. * Module Name: e1000.c *
  36. * *
  37. * Abstract: Functions for the driver entry points like load, *
  38. * unload, open and close. All board specific calls made *
  39. * by the network interface section of the driver. *
  40. * *
  41. * Environment: This file is intended to be specific to the Linux *
  42. * operating system. *
  43. * *
  44. **********************************************************************/
  45. /* This first section contains the setable parametes for configuring the
  46. * driver into the kernel.
  47. */
  48. #define E1000_DEBUG_DEFAULT 0
  49. static int e1000_debug_level = E1000_DEBUG_DEFAULT;
  50. /* global defines */
  51. #define MAX_TCB 256 /* number of transmit descriptors */
  52. #define MAX_RFD 256 /* number of receive descriptors */
  53. /* includes */
  54. #ifdef MODULE
  55. #ifdef MODVERSIONS
  56. #include <linux/modversions.h>
  57. #endif
  58. #include <linux/module.h>
  59. #endif
  60. #define E1000_MAIN_STATIC
  61. #ifdef IANS
  62. #define _IANS_MAIN_MODULE_C_
  63. #endif
  64. #include "e1000.h"
  65. #include "e1000_vendor_info.h"
  66. #include "e1000_proc.h"
  67. /* Global Data structures and variables */
  68. static const char *version =
  69. "Intel(R) PRO/1000 Gigabit Ethernet Adapter - Loadable driver, ver. 2.5.11\n";
  70. static char e1000_copyright[] = " Copyright (c) 1999-2000 Intel Corporation\n";
  71. static char e1000id_string[128] = "Intel(R) PRO/1000 Gigabit Server Adapter";
  72. static char e1000_driver[] = "e1000";
  73. static char e1000_version[] = "2.5.11";
  74. static bd_config_t *e1000first = NULL;
  75. static int e1000boards = 0;
  76. static int e1000_rxfree_cnt = 0;
  77. /* Driver performance tuning variables */
  78. static uint_t e1000_pcimlt_override = 0;
  79. static uint_t e1000_pcimwi_enable = 1;
  80. static uint_t e1000_txint_delay = 128;
  81. #if 1
  82. static uint_t e1000_rxint_delay = 128; /* RTM turn on rcv intr coalescing? microseconds? */
  83. #else
  84. static uint_t e1000_rxint_delay = 0;
  85. #endif
  86. #if 1
  87. static int e1000_flow_ctrl = 0; /* RTM turn off flow control */
  88. #else
  89. static int e1000_flow_ctrl = 3;
  90. #endif
  91. static int e1000_rxpci_priority = 0;
  92. static uint_t e1000_maxdpc_count = 5;
  93. static int TxDescriptors[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
  94. static int RxDescriptors[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
  95. /* Feature enable/disable */
  96. static int Jumbo[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
  97. static int WaitForLink[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
  98. static int SBP[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
  99. /* Speed and Duplex Settings */
  100. static int AutoNeg[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
  101. static int Speed[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
  102. static int ForceDuplex[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
  103. /* This parameter determines whether the driver sets the RS bit or the
  104. * RPS bit in a transmit packet. These are the possible values for this
  105. * parameter:
  106. * e1000_ReportTxEarly = 0 ==> set the RPS bit
  107. * = 1 ==> set the RS bit
  108. * = 2 ==> (default) let the driver auto-detect
  109. *
  110. * If the RS bit is set in a packet, an interrupts is generated as soon
  111. * as the packet is DMAed from host memory to the FIFO. If the RPS bit
  112. * is set, an interrupt is generated after the packet has been transmitted
  113. * on the wire.
  114. */
  115. static uchar_t e1000_ReportTxEarly = 2; /* let the driver auto-detect */
  116. /* these next ones are for Linux specific things */
  117. static int probed = 0;
  118. static int e1000_tx_queue(struct device *dev, struct sk_buff *skb);
  119. static int e1000_tx_start(struct device *dev);
  120. static int e1000_rx_refill(struct device *dev, struct sk_buff **);
  121. static int e1000_tx_eob(struct device *dev);
  122. static struct sk_buff *e1000_tx_clean(struct device *dev);
  123. static struct sk_buff *e1000_rx_poll(struct device *dev, int *want);
  124. static int e1000_poll_on(struct device *dev);
  125. static int e1000_poll_off(struct device *dev);
  126. /* The system interface routines */
  127. /****************************************************************************
  128. * Name: e1000_probe
  129. *
  130. * Description: This routine is called when the dynamic driver module
  131. * "e1000" is loaded using the command "insmod".
  132. *
  133. * This is a Linux required routine.
  134. *
  135. * Author: IntelCorporation
  136. *
  137. * Born on Date: 07/11/99
  138. *
  139. * Arguments:
  140. * NONE
  141. *
  142. * Returns:
  143. *
  144. * Modification log:
  145. * Date Who Description
  146. * -------- --- --------------------------------------------------------
  147. *
  148. ****************************************************************************/
  149. int
  150. e1000_probe()
  151. {
  152. device_t *dev;
  153. bd_config_t *bdp;
  154. PADAPTER_STRUCT Adapter;
  155. pci_dev_t *pcid = NULL;
  156. int num_boards = 0;
  157. int first_time = 0, loop_cnt = 0;
  158. if (e1000_debug_level >= 1)
  159. printk("e1000_probe()\n");
  160. /* Has the probe routine been called before? The driver can be probed only
  161. * once.
  162. */
  163. if (probed)
  164. return (0);
  165. else
  166. probed++;
  167. /* does the system support pci? */
  168. if ((!CONFIG_PCI) || (!pci_present()))
  169. return (0);
  170. #ifdef CONFIG_PROC_FS
  171. {
  172. int len;
  173. /* first check if e1000_proc_dir already exists */
  174. len = strlen(ADAPTERS_PROC_DIR);
  175. for (e1000_proc_dir=proc_net->subdir;e1000_proc_dir;
  176. e1000_proc_dir=e1000_proc_dir->next) {
  177. if ((e1000_proc_dir->namelen == len) &&
  178. (!memcmp(e1000_proc_dir->name, ADAPTERS_PROC_DIR, len)))
  179. break;
  180. }
  181. if (!e1000_proc_dir)
  182. e1000_proc_dir =
  183. create_proc_entry(ADAPTERS_PROC_DIR, S_IFDIR, proc_net);
  184. if (!e1000_proc_dir) return -ENODEV;
  185. }
  186. #endif
  187. /* loop through all of the ethernet PCI devices looking for ours */
  188. while ((pcid = pci_find_class(PCI_CLASS_NETWORK_ETHERNET << 8, pcid))) {
  189. dev = NULL;
  190. if (e1000_debug_level >= 2)
  191. printk("e1000_probe: vendor = 0x%x, device = 0x%x \n",
  192. pcid->vendor, pcid->device);
  193. /* is the device ours? */
  194. if ((pcid->vendor != E1000_VENDOR_ID) ||
  195. !((pcid->device == WISEMAN_DEVICE_ID) ||
  196. (pcid->device == LIVENGOOD_FIBER_DEVICE_ID) ||
  197. (pcid->device == LIVENGOOD_COPPER_DEVICE_ID))) continue; /* No, continue */
  198. if (!first_time) {
  199. /* only display the version message one time */
  200. first_time = 1;
  201. /* print out the version */
  202. printk("%s", version);
  203. printk("%s\n", e1000_copyright);
  204. }
  205. /* register the net device, but don't allocate a private structure yet */
  206. dev = init_etherdev(dev, 0);
  207. if (dev == NULL) {
  208. printk(KERN_ERR "Not able to alloc etherdev struct\n");
  209. break;
  210. }
  211. /* Allocate all the memory that the driver will need */
  212. if (!(bdp = e1000_alloc_space())) {
  213. printk("%s - Failed to allocate memory\n", e1000_driver);
  214. e1000_dealloc_space(bdp);
  215. return 0;
  216. }
  217. bdp->device = dev;
  218. #ifdef CONFIG_PROC_FS
  219. if (e1000_create_proc_dev(bdp) < 0) {
  220. e1000_remove_proc_dev(dev);
  221. e1000_dealloc_space(bdp);
  222. continue; /*return e100nics;*/
  223. }
  224. #endif
  225. /* init the timer */
  226. bdp->timer_val = -1;
  227. /* point the Adapter to the bddp */
  228. Adapter = (PADAPTER_STRUCT) bdp->bddp;
  229. #ifdef IANS
  230. bdp->iANSdata = kmalloc(sizeof(iANSsupport_t), GFP_KERNEL);
  231. memset((PVOID) bdp->iANSdata, 0, sizeof(iANSsupport_t));
  232. bd_ans_drv_InitANS(bdp, bdp->iANSdata);
  233. #endif
  234. /*
  235. * Obtain the PCI specific information about the driver.
  236. */
  237. if (e1000_find_pci_device(pcid, Adapter) == 0) {
  238. printk("%s - Failed to find PCI device\n", e1000_driver);
  239. return (0);
  240. }
  241. /* range check the command line parameters for this board */
  242. if(!e1000_GetBrandingMesg(Adapter->DeviceId, Adapter->SubVendorId, Adapter->SubSystemId)) {
  243. continue;
  244. }
  245. printk("%s\n", e1000id_string);
  246. e1000_check_options(loop_cnt);
  247. switch (Speed[loop_cnt]) {
  248. case SPEED_10:
  249. switch(ForceDuplex[loop_cnt]) {
  250. case HALF_DUPLEX:
  251. Adapter->AutoNeg = 0;
  252. Adapter->ForcedSpeedDuplex = HALF_10;
  253. break;
  254. case FULL_DUPLEX:
  255. Adapter->AutoNeg = 0;
  256. Adapter->ForcedSpeedDuplex = FULL_10;
  257. break;
  258. default:
  259. Adapter->AutoNeg = 1;
  260. Adapter->AutoNegAdvertised =
  261. ADVERTISE_10_HALF | ADVERTISE_10_FULL;
  262. }
  263. break;
  264. case SPEED_100:
  265. switch(ForceDuplex[loop_cnt]) {
  266. case HALF_DUPLEX:
  267. Adapter->AutoNeg = 0;
  268. Adapter->ForcedSpeedDuplex = HALF_100;
  269. break;
  270. case FULL_DUPLEX:
  271. Adapter->AutoNeg = 0;
  272. Adapter->ForcedSpeedDuplex = FULL_100;
  273. break;
  274. default:
  275. Adapter->AutoNeg = 1;
  276. Adapter->AutoNegAdvertised =
  277. ADVERTISE_100_HALF | ADVERTISE_100_FULL;
  278. }
  279. break;
  280. case SPEED_1000:
  281. Adapter->AutoNeg = 1;
  282. Adapter->AutoNegAdvertised = ADVERTISE_1000_FULL;
  283. break;
  284. default:
  285. Adapter->AutoNeg = 1;
  286. switch(ForceDuplex[loop_cnt]) {
  287. case HALF_DUPLEX:
  288. Adapter->AutoNegAdvertised =
  289. ADVERTISE_10_HALF | ADVERTISE_100_HALF;
  290. break;
  291. case FULL_DUPLEX:
  292. Adapter->AutoNegAdvertised =
  293. ADVERTISE_10_FULL | ADVERTISE_100_FULL | ADVERTISE_1000_FULL;
  294. break;
  295. default:
  296. Adapter->AutoNegAdvertised = AutoNeg[loop_cnt];
  297. }
  298. }
  299. Adapter->WaitAutoNegComplete = WaitForLink[loop_cnt];
  300. /* Set Adapter->MacType */
  301. switch (pcid->device) {
  302. case WISEMAN_DEVICE_ID:
  303. if (Adapter->RevID == WISEMAN_2_0_REV_ID)
  304. Adapter->MacType = MAC_WISEMAN_2_0;
  305. else {
  306. if (Adapter->RevID == WISEMAN_2_1_REV_ID)
  307. Adapter->MacType = MAC_WISEMAN_2_1;
  308. else {
  309. Adapter->MacType = MAC_WISEMAN_2_0;
  310. printk(KERN_ERR
  311. "Could not identify hardware revision\n");
  312. }
  313. }
  314. break;
  315. case LIVENGOOD_FIBER_DEVICE_ID:
  316. case LIVENGOOD_COPPER_DEVICE_ID:
  317. Adapter->MacType = MAC_LIVENGOOD;
  318. break;
  319. default:
  320. Adapter->MacType = MAC_WISEMAN_2_0;
  321. printk(KERN_ERR "Could not identify hardware revision\n");
  322. break;
  323. }
  324. /* save off the needed information */
  325. bdp->device = dev;
  326. dev->priv = bdp;
  327. Adapter = bdp->bddp;
  328. /* save off the pci device structure pointer */
  329. Adapter->pci_dev = pcid;
  330. bdp->vendor = pcid->vendor;
  331. /* set the irq into the dev and bdp structures */
  332. dev->irq = pcid->irq;
  333. bdp->irq_level = pcid->irq;
  334. /* point to all of our entry point to let the system know where we are */
  335. dev->open = &e1000_open;
  336. dev->hard_start_xmit = &e1000_xmit_frame;
  337. dev->stop = &e1000_close;
  338. dev->get_stats = &e1000_get_stats;
  339. dev->set_multicast_list = &e1000_set_multi;
  340. dev->set_mac_address = &e1000_set_mac;
  341. dev->change_mtu = &e1000_change_mtu;
  342. #ifdef IANS
  343. dev->do_ioctl = &bd_ans_os_Ioctl;
  344. #endif
  345. /* set memory base addr */
  346. dev->base_addr = pci_resource_start(pcid, 0);
  347. #ifdef CLICK_POLLING
  348. /* Click - polling extensions */
  349. dev->polling = 0;
  350. dev->rx_poll = e1000_rx_poll;
  351. dev->rx_refill = e1000_rx_refill;
  352. dev->tx_eob = e1000_tx_eob;
  353. dev->tx_clean = e1000_tx_clean;
  354. dev->tx_queue = e1000_tx_queue;
  355. dev->tx_start = e1000_tx_start;
  356. dev->poll_off = e1000_poll_off;
  357. dev->poll_on = e1000_poll_on;
  358. #endif
  359. /* now map the phys addr into system space... */
  360. /*
  361. * Map the PCI memory base address to a virtual address that can be used
  362. * for access by the driver. The amount of memory to be mapped will be
  363. * the E1000 register area.
  364. */
  365. Adapter->HardwareVirtualAddress =
  366. (PE1000_REGISTERS) ioremap(pci_resource_start(pcid, 0),
  367. sizeof(E1000_REGISTERS));
  368. if (Adapter->HardwareVirtualAddress == NULL) {
  369. /*
  370. * If the hardware register space can not be allocated, the driver
  371. * must fail to load.
  372. */
  373. printk("e1000_probe ioremap failed\n");
  374. /* this is a problem, if the first one inits OK but a secondary one
  375. * fails, what should you return? Now it will say the load was OK
  376. * but one or more boards may have failed to come up
  377. */
  378. break;
  379. }
  380. bdp->mem_start = pci_resource_start(pcid, 0);
  381. if (e1000_debug_level >= 2)
  382. printk("memstart = 0x%p, virt_addr = 0x%p\n",
  383. (void *) bdp->mem_start,
  384. (void *) Adapter->HardwareVirtualAddress);
  385. e1000_init(bdp);
  386. /* Printout the board configuration */
  387. e1000_print_brd_conf(bdp);
  388. /* init the basic stats stuff */
  389. ClearHwStatsCounters(Adapter);
  390. /* Update the statistics needed by the upper */
  391. UpdateStatsCounters(bdp);
  392. /* up the loop count( it's also the number of our boards found) */
  393. loop_cnt++;
  394. if (e1000_debug_level >= 2) {
  395. printk("dev = 0x%p ", dev);
  396. printk(" priv = 0x%p\n", dev->priv);
  397. printk(" irq = 0x%x ", dev->irq);
  398. printk(" next = 0x%p ", dev->next);
  399. printk(" flags = 0x%x\n", dev->flags);
  400. printk(" bdp = 0x%p\n", bdp);
  401. printk(" irq_level = 0x%x\n", bdp->irq_level);
  402. }
  403. } /* end of pci_find_class while loop */
  404. e1000boards = num_boards = loop_cnt;
  405. if (num_boards)
  406. return (0);
  407. else
  408. return (-ENODEV);
  409. }
  410. /* register e1000_probe as our initilization routine */
  411. module_init(e1000_probe);
  412. /* set some of the modules specific things here */
  413. #ifdef MODULE
  414. MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
  415. MODULE_DESCRIPTION("Intel(R) PRO/1000 Gigabit Ethernet driver");
  416. MODULE_PARM(TxDescriptors, "1-8i");
  417. MODULE_PARM(RxDescriptors, "1-8i");
  418. MODULE_PARM(Jumbo, "1-8i");
  419. MODULE_PARM(WaitForLink, "1-8i");
  420. MODULE_PARM(AutoNeg, "1-8i");
  421. MODULE_PARM(Speed, "1-8i");
  422. MODULE_PARM(ForceDuplex, "1-8i");
  423. MODULE_PARM(SBP, "1-8i");
  424. #endif
  425. /****************************************************************************
  426. * Name: cleanup_module
  427. *
  428. * Description: This routine is an entry point into the driver.
  429. *
  430. * This is a Linux required routine.
  431. *
  432. * Author: IntelCorporation
  433. *
  434. * Born on Date: 07/11/99
  435. *
  436. * Arguments:
  437. * NONE
  438. *
  439. * Returns:
  440. * It returns 0 and can not fail
  441. *
  442. * Modification log:
  443. * Date Who Description
  444. * -------- --- --------------------------------------------------------
  445. *
  446. ****************************************************************************/
  447. int
  448. cleanup_module(void)
  449. {
  450. bd_config_t *bdp, *next_bdp;
  451. PADAPTER_STRUCT Adapter;
  452. device_t *dev, *next_dev;
  453. /* start looking at the first device */
  454. if (e1000first)
  455. dev = e1000first->device;
  456. else
  457. return 0;
  458. if (e1000_debug_level >= 1)
  459. printk("cleanup_module: SOR, dev = 0x%p \n\n\n", dev);
  460. while (dev) {
  461. #ifdef CONFIG_PROC_FS
  462. e1000_remove_proc_dev(dev);
  463. #endif
  464. bdp = (bd_config_t *) dev->priv;
  465. next_bdp = bdp->bd_next;
  466. if (next_bdp)
  467. next_dev = next_bdp->device;
  468. else
  469. next_dev = NULL;
  470. Adapter = bdp->bddp;
  471. /* unregister this instance of the module */
  472. if (e1000_debug_level >= 2)
  473. printk("--Cleanup, unreg_netdev\n");
  474. unregister_netdev(dev);
  475. /*
  476. * Free the memory mapped area that is allocated to the E1000 hardware
  477. * registers
  478. */
  479. if (e1000_debug_level >= 2)
  480. printk("--Cleanup, iounmap\n");
  481. iounmap(Adapter->HardwareVirtualAddress);
  482. /* free the irq back to the system */
  483. #ifdef IANS
  484. kfree(bdp->iANSdata);
  485. #endif
  486. /* free up any memory here */
  487. if (e1000_debug_level >= 2)
  488. printk("--Cleanup, e1000_dealloc_space\n");
  489. e1000_dealloc_space(bdp);
  490. dev = next_dev;
  491. }
  492. #ifdef CONFIG_PROC_FS
  493. {
  494. struct proc_dir_entry *de;
  495. /* check if the subdir list is empty before removing e1000_proc_dir */
  496. for (de = e1000_proc_dir->subdir; de; de = de->next) {
  497. /* ignore . and .. */
  498. if (*(de->name) == '.') continue;
  499. break;
  500. }
  501. if (de) return 0;
  502. remove_proc_entry(ADAPTERS_PROC_DIR, proc_net);
  503. }
  504. #endif
  505. return (0);
  506. }
  507. /****************************************************************************
  508. * Name: e1000_check_options
  509. *
  510. * Description: This routine does range checking on command line options.
  511. *
  512. * Author: IntelCorporation
  513. *
  514. * Born on Date: 03/28/2000
  515. *
  516. * Arguments:
  517. * int board - board number to check values for
  518. *
  519. * Returns:
  520. * None
  521. *
  522. ****************************************************************************/
  523. static void
  524. e1000_check_options(int board)
  525. {
  526. /* Transmit Descriptor Count */
  527. if (TxDescriptors[board] == -1) {
  528. TxDescriptors[board] = MAX_TCB;
  529. } else if ((TxDescriptors[board] > E1000_MAX_TXD) ||
  530. (TxDescriptors[board] < E1000_MIN_TXD)) {
  531. printk("Invalid TxDescriptor count specified (%i),"
  532. " using default of %i\n", TxDescriptors[board], MAX_TCB);
  533. TxDescriptors[board] = MAX_TCB;
  534. } else {
  535. printk("Using specified value of %i TxDescriptors\n",
  536. TxDescriptors[board]);
  537. }
  538. /* Receive Descriptor Count */
  539. if (RxDescriptors[board] == -1) {
  540. RxDescriptors[board] = MAX_RFD;
  541. } else if ((RxDescriptors[board] > E1000_MAX_RXD) ||
  542. (RxDescriptors[board] < E1000_MIN_RXD)) {
  543. printk("Invalid RxDescriptor count specified (%i),"
  544. " using default of %i\n", RxDescriptors[board], MAX_RFD);
  545. RxDescriptors[board] = MAX_RFD;
  546. } else {
  547. printk("Using specified value of %i RxDescriptors\n",
  548. RxDescriptors[board]);
  549. }
  550. /* Jumbo Frame Enable */
  551. if (Jumbo[board] == -1) {
  552. Jumbo[board] = 1;
  553. } else if ((Jumbo[board] > 1) || (Jumbo[board] < 0)) {
  554. printk("Invalid Jumbo specified (%i), using default of %i\n",
  555. Jumbo[board], 1);
  556. Jumbo[board] = 1;
  557. } else {
  558. printk("Jumbo Frames %s\n",
  559. Jumbo[board] == 1 ? "Enabled" : "Disabled");
  560. }
  561. /* Wait for link at driver load */
  562. if (WaitForLink[board] == -1) {
  563. WaitForLink[board] = 1;
  564. } else if ((WaitForLink[board] > 1) || (WaitForLink[board] < 0)) {
  565. printk("Invalid WaitForLink specified (%i), using default of %i\n",
  566. WaitForLink[board], 1);
  567. WaitForLink[board] = 1;
  568. } else {
  569. printk("WaitForLink %s\n",
  570. WaitForLink[board] == 1 ? "Enabled" : "Disabled");
  571. }
  572. /* Forced Speed and Duplex */
  573. switch (Speed[board]) {
  574. case -1:
  575. Speed[board] = 0;
  576. switch (ForceDuplex[board]) {
  577. case -1:
  578. ForceDuplex[board] = 0;
  579. break;
  580. case 0:
  581. printk("Speed and Duplex Autonegotiation Enabled\n");
  582. break;
  583. case 1:
  584. printk("Warning: Half Duplex specified without Speed\n");
  585. printk("Using Autonegotiation at Half Duplex only\n");
  586. break;
  587. case 2:
  588. printk("Warning: Full Duplex specified without Speed\n");
  589. printk("Using Autonegotiation at Full Duplex only\n");
  590. break;
  591. default:
  592. printk("Invalid Duplex Specified (%i), Parameter Ignored\n",
  593. ForceDuplex[board]);
  594. ForceDuplex[board] = 0;
  595. printk("Speed and Duplex Autonegotiation Enabled\n");
  596. }
  597. break;
  598. case 0:
  599. switch (ForceDuplex[board]) {
  600. case -1:
  601. case 0:
  602. printk("Speed and Duplex Autonegotiation Enabled\n");
  603. ForceDuplex[board] = 0;
  604. break;
  605. case 1:
  606. printk("Warning: Half Duplex specified without Speed\n");
  607. printk("Using Autonegotiation at Half Duplex only\n");
  608. break;
  609. case 2:
  610. printk("Warning: Full Duplex specified without Speed\n");
  611. printk("Using Autonegotiation at Full Duplex only\n");
  612. break;
  613. default:
  614. printk("Invalid Duplex Specified (%i), Parameter Ignored\n",
  615. ForceDuplex[board]);
  616. ForceDuplex[board] = 0;
  617. printk("Speed and Duplex Autonegotiation Enabled\n");
  618. }
  619. break;
  620. case 10:
  621. case 100:
  622. switch (ForceDuplex[board]) {
  623. case -1:
  624. case 0:
  625. printk("Warning: %i Mbps Speed specified without Duplex\n",
  626. Speed[board]);
  627. printk("Using Autonegotiation at %i Mbps only\n", Speed[board]);
  628. ForceDuplex[board] = 0;
  629. break;
  630. case 1:
  631. printk("Forcing to %i Mbps Half Duplex\n", Speed[board]);
  632. break;
  633. case 2:
  634. printk("Forcing to %i Mbps Full Duplex\n", Speed[board]);
  635. break;
  636. default:
  637. printk("Invalid Duplex Specified (%i), Parameter Ignored\n",
  638. ForceDuplex[board]);
  639. ForceDuplex[board] = 0;
  640. printk("Warning: %i Mbps Speed specified without Duplex\n",
  641. Speed[board]);
  642. printk("Using Autonegotiation at %i Mbps only\n", Speed[board]);
  643. }
  644. break;
  645. case 1000:
  646. switch (ForceDuplex[board]) {
  647. case -1:
  648. case 0:
  649. printk("Warning: 1000 Mbps Speed specified without Duplex\n");
  650. printk("Using Autonegotiation at 1000 Mbps Full Duplex only\n");
  651. ForceDuplex[board] = 0;
  652. break;
  653. case 1:
  654. printk("Warning: Half Duplex is not supported at 1000 Mbps\n");
  655. printk("Using Autonegotiation at 1000 Mbps Full Duplex only\n");
  656. break;
  657. case 2:
  658. printk("Using Autonegotiation at 1000 Mbps Full Duplex only\n");
  659. break;
  660. default:
  661. printk("Invalid Duplex Specified (%i), Parameter Ignored\n",
  662. ForceDuplex[board]);
  663. ForceDuplex[board] = 0;
  664. printk("Warning: 1000 Mbps Speed specified without Duplex\n");
  665. printk("Using Autonegotiation at 1000 Mbps Full Duplex only\n");
  666. }
  667. break;
  668. default:
  669. printk("Invalid Speed Specified (%i), Parameter Ignored\n",
  670. Speed[board]);
  671. Speed[board] = 0;
  672. switch (ForceDuplex[board]) {
  673. case -1:
  674. case 0:
  675. printk("Speed and Duplex Autonegotiation Enabled\n");
  676. ForceDuplex[board] = 0;
  677. break;
  678. case 1:
  679. printk("Warning: Half Duplex specified without Speed\n");
  680. printk("Using Autonegotiation at Half Duplex only\n");
  681. break;
  682. case 2:
  683. printk("Warning: Full Duplex specified without Speed\n");
  684. printk("Using Autonegotiation at Full Duplex only\n");
  685. break;
  686. default:
  687. printk("Invalid Duplex Specified (%i), Parameter Ignored\n",
  688. ForceDuplex[board]);
  689. ForceDuplex[board] = 0;
  690. printk("Speed and Duplex Autonegotiation Enabled\n");
  691. }
  692. }
  693. if (AutoNeg[board] == -1) {
  694. AutoNeg[board] = 0x2F;
  695. } else {
  696. if (AutoNeg[board] & ~0x2F) {
  697. printk("Invalid AutoNeg Specified (0x%X)\n", AutoNeg[board]);
  698. AutoNeg[board] = 0x2F;
  699. }
  700. printk("AutoNeg Advertising ");
  701. if(AutoNeg[board] & 0x20) {
  702. printk("1000/FD");
  703. if(AutoNeg[board] & 0x0F)
  704. printk(", ");
  705. }
  706. if(AutoNeg[board] & 0x08) {
  707. printk("100/FD");
  708. if(AutoNeg[board] & 0x07)
  709. printk(", ");
  710. }
  711. if(AutoNeg[board] & 0x04) {
  712. printk("100/HD");
  713. if(AutoNeg[board] & 0x03)
  714. printk(", ");
  715. }
  716. if(AutoNeg[board] & 0x02) {
  717. printk("10/FD");
  718. if(AutoNeg[board] & 0x01)
  719. printk(", ");
  720. }
  721. if(AutoNeg[board] & 0x01)
  722. printk("10/HD");
  723. printk("\n");
  724. }
  725. }
  726. /****************************************************************************
  727. * Name: e1000_open
  728. *
  729. * Description: This routine is the open call for the interface.
  730. *
  731. * This is a Linux required routine.
  732. *
  733. * Author: IntelCorporation
  734. *
  735. * Born on Date: 07/11/99
  736. *
  737. * Arguments:
  738. * NONE
  739. *
  740. * Returns:
  741. * It returns 0 on success
  742. * -EAGAIN on failure
  743. *
  744. * Modification log:
  745. * Date Who Description
  746. * -------- --- --------------------------------------------------------
  747. *
  748. ****************************************************************************/
  749. static int
  750. e1000_open(device_t * dev)
  751. {
  752. bd_config_t *bdp;
  753. PADAPTER_STRUCT Adapter = 0;
  754. int ret_val;
  755. printk("v0 e1000 Alignment: %p %p\n",
  756. &(Adapter->FirstTxDescriptor), &(Adapter->NumRxDescriptors));
  757. bdp = dev->priv;
  758. Adapter = bdp->bddp;
  759. if (e1000_debug_level >= 1)
  760. printk("open: SOR, bdp = 0x%p\n", bdp);
  761. /* make sure we have not already opened this interface */
  762. if(bdp->flags & BOARD_OPEN)
  763. return -EBUSY;
  764. if (e1000_init(bdp)) {
  765. return -ENOMEM;
  766. }
  767. if (e1000_runtime_init(bdp)) {
  768. return -ENOMEM;
  769. }
  770. Adapter->AdapterStopped = FALSE;
  771. #ifdef IANS_BASE_VLAN_TAGGING
  772. /* on a close a global reset is issued to the hardware,
  773. * so VLAN settings are lost and need to be re-set on open */
  774. if((IANS_BD_TAGGING_MODE)ANS_PRIVATE_DATA_FIELD(bdp)->tag_mode != IANS_BD_TAGGING_NONE)
  775. bd_ans_hw_EnableVLAN(bdp);
  776. #endif
  777. if (request_irq(dev->irq, &e1000_intr, SA_SHIRQ, "e1000", dev)) {
  778. if (e1000_debug_level >= 1)
  779. printk("open: request_irq failed");
  780. return (-EAGAIN);
  781. }
  782. /* Check to see if promiscuous mode needs to be turned on */
  783. if (dev->flags & IFF_PROMISC) {
  784. /* turn promisc mode on */
  785. ret_val = e1000_set_promisc(bdp, B_TRUE);
  786. bdp->flags |= PROMISCUOUS;
  787. } else {
  788. /* turn promisc mode off */
  789. ret_val = e1000_set_promisc(bdp, B_FALSE);
  790. bdp->flags &= ~PROMISCUOUS;
  791. }
  792. #ifdef MODULE
  793. /* up the mod use count used by the system */
  794. MOD_INC_USE_COUNT;
  795. #endif
  796. /* setup and start the watchdog timer */
  797. init_timer(&bdp->timer_id);
  798. /* set the timer value for 2 sec( i.e. 200 10msec tics )
  799. * jiffies are mesured in tics and is equiv. to LBOLTS in Unix
  800. */
  801. bdp->timer_id.expires = bdp->timer_val = jiffies + 200;
  802. bdp->timer_id.data = (ulong_t) dev;
  803. bdp->timer_id.function = (void *) &e1000_watchdog;
  804. /* start the timer */
  805. add_timer(&bdp->timer_id);
  806. /* set the device flags */
  807. netif_start_queue(dev);
  808. /* enable interrupts */
  809. e1000EnableInterrupt(Adapter);
  810. /* init the basic stats stuff */
  811. ClearHwStatsCounters(Adapter);
  812. bdp->flags |= BOARD_OPEN;
  813. return (0);
  814. }
  815. /****************************************************************************
  816. * Name: e1000_close
  817. *
  818. * Description: This routine is an entry point into the driver.
  819. *
  820. * This is a Linux required routine.
  821. *
  822. * Author: IntelCorporation
  823. *
  824. * Born on Date: 07/11/99
  825. *
  826. * Arguments:
  827. * device_t pointer
  828. *
  829. * Returns:
  830. * It returns 0 and can not fail.
  831. *
  832. * Modification log:
  833. * Date Who Description
  834. * -------- --- --------------------------------------------------------
  835. *
  836. ****************************************************************************/
  837. static int
  838. e1000_close(device_t * dev)
  839. {
  840. bd_config_t *bdp;
  841. PADAPTER_STRUCT Adapter;
  842. ushort_t status;
  843. int j;
  844. bdp = dev->priv;
  845. Adapter = bdp->bddp;
  846. /* set the device to not started */
  847. netif_stop_queue(dev);
  848. /* stop the hardware */
  849. /* Disable all possible interrupts */
  850. E1000_WRITE_REG(Imc, (0xffffffff));
  851. status = E1000_READ_REG(Icr);
  852. /* Reset the chip */
  853. AdapterStop(Adapter);
  854. /* kill the timer */
  855. del_timer(&bdp->timer_id);
  856. /* free the irq back to the system */
  857. if (e1000_debug_level >= 1)
  858. printk("E1000: close: free_irq\n");
  859. free_irq(dev->irq, dev);
  860. /*
  861. * Free up the transmit descriptor area
  862. */
  863. if (e1000_debug_level >= 2)
  864. printk("--Cleanup, free tx descriptor area\n");
  865. free_contig(bdp->base_tx_tbds);
  866. bdp->base_tx_tbds = NULL;
  867. if(Adapter->TxSkBuffs)
  868. free_contig(Adapter->TxSkBuffs);
  869. /*
  870. * Free up the RX_SW_PACKET area also free any allocated
  871. * receive buffers
  872. */
  873. if (e1000_debug_level >= 2)
  874. printk("--Cleanup, free rx packet area + skbuffs\n");
  875. if(Adapter->RxSkBuffs){
  876. for (j = 0; j < Adapter->NumRxDescriptors; j++) {
  877. if (Adapter->RxSkBuffs[j]){
  878. if (e1000_debug_level >= 2)
  879. printk(" -- kfree_skb\n");
  880. dev_kfree_skb(Adapter->RxSkBuffs[j]);
  881. Adapter->RxSkBuffs[j] = 0;
  882. }
  883. }
  884. free_contig(Adapter->RxSkBuffs);
  885. }
  886. /*
  887. * Free the receive descriptor area
  888. */
  889. if (e1000_debug_level >= 2)
  890. printk("--Cleanup, free rx descriptor area\n");
  891. /* free_contig( Adapter->e1000_rbd_data ); */
  892. free_contig(bdp->base_rx_rbds);
  893. bdp->base_rx_rbds = NULL;
  894. bdp->flags &= ~BOARD_OPEN;
  895. #ifdef MODULE
  896. /* adjust the mod use count */
  897. MOD_DEC_USE_COUNT;
  898. #endif
  899. return (0);
  900. }
  901. /*
  902. * the send a packet, may poke at e1000 to force it to start tx
  903. */
  904. static int
  905. e1000_xmit_frame_aux(struct sk_buff *skb, device_t * dev, int poke)
  906. {
  907. bd_config_t *bdp;
  908. PADAPTER_STRUCT Adapter;
  909. int lock_flag;
  910. int ret;
  911. bdp = dev->priv;
  912. Adapter = (PADAPTER_STRUCT) bdp->bddp;
  913. if (test_and_set_bit(0, (void*)&dev->tbusy) != 0) {
  914. return 1;
  915. }
  916. if (e1000_debug_level >= 3)
  917. printk("e1000_tx_frame\n");
  918. /* call the transmit routine */
  919. #ifdef CLICK_POLLING
  920. if(SendBuffer(skb, bdp, poke, dev->polling)){
  921. #else
  922. if(SendBuffer(skb, bdp, poke, 0)){
  923. #endif
  924. ret = 0;
  925. } else {
  926. #ifdef IANS
  927. if(bdp->iANSdata->iANS_status == IANS_COMMUNICATION_UP) {
  928. ans_notify(dev, IANS_IND_XMIT_QUEUE_FULL);
  929. }
  930. #endif
  931. ret = 1;
  932. }
  933. if(bdp->tx_out_res == 0)
  934. clear_bit(0, (void*)&dev->tbusy);
  935. return (ret);
  936. }
  937. /****************************************************************************
  938. * Name: e1000_xmit_frame
  939. *
  940. * Description: This routine is called to transmit a frame.
  941. *
  942. *
  943. * Author: IntelCorporation
  944. *
  945. * Born on Date: 07/11/99
  946. *
  947. * Arguments:
  948. * sb_buff pointer
  949. * device_t pointer
  950. *
  951. * Returns:
  952. * It returns B_FALSE on success
  953. * B_TRUE on failure
  954. *
  955. * Modification log:
  956. * Date Who Description
  957. * -------- --- --------------------------------------------------------
  958. *
  959. ****************************************************************************/
  960. static int
  961. e1000_xmit_frame(struct sk_buff *skb, device_t * dev)
  962. {
  963. return e1000_xmit_frame_aux(skb, dev, 1);
  964. }
  965. /****************************************************************************
  966. * Name: SendBuffer
  967. *
  968. * Description: This routine physically sends the packet to the nic controller.
  969. *
  970. *
  971. * Author: IntelCorporation
  972. *
  973. * Born on Date: 07/11/99
  974. *
  975. * Arguments:
  976. * TX_SW_PACKET pointer
  977. * bd_config_t pointer
  978. *
  979. * Returns:
  980. * It returns B_TRUE always and can not fail.
  981. *
  982. * Modification log:
  983. * Date Who Description
  984. * -------- --- --------------------------------------------------------
  985. *
  986. ****************************************************************************/
  987. static UINT
  988. SendBuffer(struct sk_buff *skb, bd_config_t * bdp, int poke, int polling)
  989. {
  990. PADAPTER_STRUCT Adapter;
  991. PE1000_TRANSMIT_DESCRIPTOR CurrentTxDescriptor, nxt;
  992. // net_device_stats_t *stats;
  993. int di;
  994. Adapter = bdp->bddp;
  995. // stats = &bdp->net_stats;
  996. CurrentTxDescriptor = Adapter->NextAvailTxDescriptor;
  997. /* Don't use the last descriptor! */
  998. if (CurrentTxDescriptor == Adapter->LastTxDescriptor)
  999. nxt = Adapter->FirstTxDescriptor;
  1000. else
  1001. nxt = CurrentTxDescriptor + 1;
  1002. if(nxt == Adapter->OldestUsedTxDescriptor){
  1003. printk("e1000: out of descs in Sendbuffer\n");
  1004. return(0);
  1005. }
  1006. di = CurrentTxDescriptor - Adapter->FirstTxDescriptor;
  1007. if(Adapter->TxSkBuffs[di])
  1008. printk("e1000 oops di %d TxSkBuffs[di] %x\n",
  1009. di,
  1010. (di >= 0 && di < 80) ? Adapter->TxSkBuffs[di] : 0);
  1011. Adapter->TxSkBuffs[di] = skb;
  1012. CurrentTxDescriptor->BufferAddress = virt_to_bus(skb->data);
  1013. CurrentTxDescriptor->Lower.DwordData = skb->len;
  1014. /* zero out the status field in the descriptor. */
  1015. CurrentTxDescriptor->Upper.DwordData = 0;
  1016. #ifdef IANS
  1017. if(bdp->iANSdata->iANS_status == IANS_COMMUNICATION_UP) {
  1018. if(bd_ans_os_Transmit(bdp, CurrentTxDescriptor, &skb)==BD_ANS_FAILURE) {
  1019. dev_kfree_skb(skb);
  1020. return B_FALSE;
  1021. }
  1022. }
  1023. #endif
  1024. Adapter->NextAvailTxDescriptor = nxt;
  1025. CurrentTxDescriptor->Lower.DwordData |=
  1026. (E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS);
  1027. #if 1
  1028. /*
  1029. * If there is a valid value for the transmit interrupt delay, set up the
  1030. * delay in the descriptor field
  1031. */
  1032. if (Adapter->TxIntDelay)
  1033. CurrentTxDescriptor->Lower.DwordData |= E1000_TXD_CMD_IDE;
  1034. #else
  1035. /*
  1036. * Ask for a transmit complete interrupt every 60 packets. RTM
  1037. * This seems to be broken -- sometimes the tx complete
  1038. * interrupts never happen -- sending waits until a receive
  1039. * packet arrives. RTM Dec 22 2000.
  1040. */
  1041. if(polling==0 && Adapter->TxIntDelay){
  1042. static int dctr;
  1043. if(dctr++ > 60){
  1044. dctr = 0;
  1045. /* Don't delay for this packet! */
  1046. } else {
  1047. /* Delay tx complete interrupt for most packets. */
  1048. CurrentTxDescriptor->Lower.DwordData |= E1000_TXD_CMD_IDE;
  1049. }
  1050. }
  1051. #endif
  1052. /* Set the RS or the RPS bit by looking at the ReportTxEarly setting */
  1053. if (Adapter->ReportTxEarly == 1)
  1054. CurrentTxDescriptor->Lower.DwordData |= E1000_TXD_CMD_RS;
  1055. else
  1056. CurrentTxDescriptor->Lower.DwordData |= E1000_TXD_CMD_RPS;
  1057. if (poke)
  1058. /* Advance the Transmit Descriptor Tail (Tdt), this tells the
  1059. * E1000 that this frame is available to transmit.
  1060. */
  1061. E1000_WRITE_REG(Tdt, (((unsigned long) Adapter->NextAvailTxDescriptor -
  1062. (unsigned long) Adapter->FirstTxDescriptor) >> 4));
  1063. /* Could we queue another packet? */
  1064. if (Adapter->NextAvailTxDescriptor == Adapter->LastTxDescriptor)
  1065. nxt = Adapter->FirstTxDescriptor;
  1066. else
  1067. nxt = Adapter->NextAvailTxDescriptor + 1;
  1068. if(nxt == Adapter->OldestUsedTxDescriptor)
  1069. bdp->tx_out_res = 1;
  1070. return(1);
  1071. }
  1072. /****************************************************************************
  1073. * Name: e1000_get_stats
  1074. *
  1075. * Description: This routine is called when the OS wants the nic stats returned
  1076. *
  1077. * Author: IntelCorporation
  1078. *
  1079. * Born on Date: 7/12/99
  1080. *
  1081. * Arguments:
  1082. * device_t dev - the device stucture to return stats on
  1083. *
  1084. * Returns:
  1085. * the address of the net_device_stats stucture for the device
  1086. *
  1087. * Modification log:
  1088. * Date Who Description
  1089. * -------- --- --------------------------------------------------------
  1090. *
  1091. ****************************************************************************/
  1092. static struct net_device_stats *
  1093. e1000_get_stats(device_t * dev)
  1094. {
  1095. bd_config_t *bdp = dev->priv;
  1096. /* Statistics are updated from the watchdog - so just return them now */
  1097. return (&bdp->net_stats);
  1098. }
  1099. /* this routine is to change the MTU size for jumbo frames */
  1100. /****************************************************************************
  1101. * Name: e1000_change_mtu
  1102. *
  1103. * Description: This routine is called when the OS would like the driver to
  1104. * change the MTU size. This is used for jumbo frame support.
  1105. *
  1106. * Author: IntelCorporation
  1107. *
  1108. * Born on Date: 7/12/98
  1109. *
  1110. * Arguments:
  1111. * device_t pointer - pointer to the device
  1112. * int - the new MTU size
  1113. *
  1114. * Returns:
  1115. * ????
  1116. *
  1117. * Modification log:
  1118. * Date Who Description
  1119. * -------- --- --------------------------------------------------------
  1120. *
  1121. ****************************************************************************/
  1122. static int
  1123. e1000_change_mtu(device_t * dev, int new_mtu)
  1124. {
  1125. bd_config_t *bdp;
  1126. PADAPTER_STRUCT Adapter;
  1127. bdp = (bd_config_t *) dev->priv;
  1128. Adapter = bdp->bddp;
  1129. if ((new_mtu < MINIMUM_ETHERNET_PACKET_SIZE - ENET_HEADER_SIZE) ||
  1130. (new_mtu > MAX_JUMBO_FRAME_SIZE - ENET_HEADER_SIZE))
  1131. return -EINVAL;
  1132. if (new_mtu <= MAXIMUM_ETHERNET_PACKET_SIZE - ENET_HEADER_SIZE) {
  1133. /* 802.x legal frame sizes */
  1134. Adapter->LongPacket = FALSE;
  1135. if (Adapter->RxBufferLen != E1000_RXBUFFER_2048) {
  1136. Adapter->RxBufferLen = E1000_RXBUFFER_2048;
  1137. if (dev->flags & IFF_UP) {
  1138. e1000_close(dev);
  1139. e1000_open(dev);
  1140. }
  1141. }
  1142. } else if (Adapter->MacType < MAC_LIVENGOOD) {
  1143. /* Jumbo frames not supported on 82542 hardware */
  1144. printk("e1000: Jumbo frames not supported on 82542\n");
  1145. return -EINVAL;
  1146. } else if (Jumbo[Adapter->bd_number] != 1) {
  1147. printk("e1000: Jumbo frames disabled\n");
  1148. return -EINVAL;
  1149. } else if (new_mtu <= (4096 - 256) - ENET_HEADER_SIZE) {
  1150. /* 4k buffers */
  1151. Adapter->LongPacket = TRUE;
  1152. if (Adapter->RxBufferLen != E1000_RXBUFFER_4096) {
  1153. Adapter->RxBufferLen = E1000_RXBUFFER_4096;
  1154. if (dev->flags & IFF_UP) {
  1155. e1000_close(dev);
  1156. e1000_open(dev);
  1157. }
  1158. }
  1159. } else if (new_mtu <= (8192 - 256) - ENET_HEADER_SIZE) {
  1160. /* 8k buffers */
  1161. Adapter->LongPacket = TRUE;
  1162. if (Adapter->RxBufferLen != E1000_RXBUFFER_8192) {
  1163. Adapter->RxBufferLen = E1000_RXBUFFER_8192;
  1164. if (dev->flags & IFF_UP) {
  1165. e1000_close(dev);
  1166. e1000_open(dev);
  1167. }
  1168. }
  1169. } else {
  1170. /* 16k buffers */
  1171. Adapter->LongPacket = TRUE;
  1172. if (Adapter->RxBufferLen != E1000_RXBUFFER_16384) {
  1173. Adapter->RxBufferLen = E1000_RXBUFFER_16384;
  1174. if (dev->flags & IFF_UP) {
  1175. e1000_close(dev);
  1176. e1000_open(dev);
  1177. }
  1178. }
  1179. }
  1180. dev->mtu = new_mtu;
  1181. return 0;
  1182. }
  1183. /****************************************************************************
  1184. * Name: e1000_init
  1185. *
  1186. * Description: This routine is called when this driver is loaded. This is
  1187. * the initialization routine which allocates memory, starts the
  1188. * watchdog, & configures the adapter, determines the system
  1189. * resources.
  1190. *
  1191. * Author: IntelCorporation
  1192. *
  1193. * Born on Date: 1/18/98
  1194. *
  1195. * Arguments:
  1196. * NONE
  1197. *
  1198. * Returns:
  1199. * NONE
  1200. *
  1201. * Modification log:
  1202. * Date Who Description
  1203. * -------- --- --------------------------------------------------------
  1204. *
  1205. ****************************************************************************/
  1206. static int
  1207. e1000_init(bd_config_t * bdp)
  1208. {
  1209. PADAPTER_STRUCT Adapter;
  1210. device_t *dev;
  1211. uint16_t LineSpeed, FullDuplex;
  1212. if (e1000_debug_level >= 1)
  1213. printk("e1000_init()\n");
  1214. dev = bdp->device;
  1215. Adapter = (PADAPTER_STRUCT) bdp->bddp;
  1216. /*
  1217. * Disable interrupts on the E1000 card
  1218. */
  1219. e1000DisableInterrupt(Adapter);
  1220. /**** Reset and Initialize the E1000 *******/
  1221. AdapterStop(Adapter);
  1222. Adapter->AdapterStopped = FALSE;
  1223. /* Validate the EEPROM */
  1224. if (!ValidateEepromChecksum(Adapter)) {
  1225. printk("e1000: The EEPROM checksum is not valid \n");
  1226. return (1);
  1227. }
  1228. /* read the ethernet address from the eprom */
  1229. ReadNodeAddress(Adapter, &Adapter->perm_node_address[0]);
  1230. if (e1000_debug_level >= 2) {
  1231. printk("Node addr is: ");
  1232. printk("%x:", Adapter->perm_node_address[0]);
  1233. printk("%x:", Adapter->perm_node_address[1]);
  1234. printk("%x:", Adapter->perm_node_address[2]);
  1235. printk("%x:", Adapter->perm_node_address[3]);
  1236. printk("%x:", Adapter->perm_node_address[4]);
  1237. printk("%x\n ", Adapter->perm_node_address[5]);
  1238. }
  1239. /* save off the perm node addr in the bdp */
  1240. memcpy(bdp->eaddr.bytes, &Adapter->perm_node_address[0],
  1241. DL_MAC_ADDR_LEN);
  1242. /* tell the system what the address is... */
  1243. memcpy(&dev->dev_addr[0], &Adapter->perm_node_address[0],
  1244. DL_MAC_ADDR_LEN);
  1245. /* Scan the chipset and determine whether to set the RS bit or
  1246. * the RPS bit during transmits. On some systems with a fast chipset
  1247. * (450NX), setting the RS bit may cause data corruption. Check the
  1248. * space.c paratemer to see if the user has forced this setting or
  1249. * has let the software do the detection.
  1250. */
  1251. if ((e1000_ReportTxEarly == 0) || (e1000_ReportTxEarly == 1))
  1252. Adapter->ReportTxEarly = e1000_ReportTxEarly; /* User setting */
  1253. else { /* let the software setect the chipset */
  1254. if(Adapter->MacType < MAC_LIVENGOOD) {
  1255. if (DetectKnownChipset(Adapter) == B_TRUE)
  1256. Adapter->ReportTxEarly = 1; /* Set the RS bit */
  1257. else
  1258. Adapter->ReportTxEarly = 0; /* Set the RPS bit */
  1259. } else
  1260. Adapter->ReportTxEarly = 1;
  1261. }
  1262. Adapter->FlowControl = e1000_flow_ctrl;
  1263. Adapter->RxPciPriority = e1000_rxpci_priority;
  1264. /* Do the adapter initialization */
  1265. if (!InitializeHardware(Adapter)) {
  1266. printk("InitializeHardware Failed\n");
  1267. return (1);
  1268. }
  1269. /* all initialization done, mark board as present */
  1270. bdp->flags = BOARD_PRESENT;
  1271. CheckForLink(Adapter);
  1272. if(E1000_READ_REG(Status) & E1000_STATUS_LU) {
  1273. Adapter->LinkIsActive = TRUE;
  1274. GetSpeedAndDuplex(Adapter, &LineSpeed, &FullDuplex);
  1275. Adapter->cur_line_speed = (uint32_t) LineSpeed;
  1276. Adapter->FullDuplex = (uint32_t) FullDuplex;
  1277. #ifdef IANS
  1278. Adapter->ans_link = IANS_STATUS_LINK_OK;
  1279. Adapter->ans_speed = (uint32_t) LineSpeed;
  1280. Adapter->ans_duplex = FullDuplex == FULL_DUPLEX ?
  1281. BD_ANS_DUPLEX_FULL : BD_ANS_DUPLEX_HALF;
  1282. #endif
  1283. } else {
  1284. Adapter->LinkIsActive = FALSE;
  1285. Adapter->cur_line_speed = 0;
  1286. Adapter->FullDuplex = 0;
  1287. #ifdef IANS
  1288. Adapter->ans_link = IANS_STATUS_LINK_FAIL;
  1289. Adapter->ans_speed = 0;
  1290. Adapter->ans_duplex = 0;
  1291. #endif
  1292. }
  1293. if (e1000_debug_level >= 1)
  1294. printk("e1000_init: end\n");
  1295. return (0);
  1296. }
  1297. static int
  1298. e1000_runtime_init(bd_config_t * bdp)
  1299. {
  1300. PADAPTER_STRUCT Adapter;
  1301. device_t *dev;
  1302. if (e1000_debug_level >= 1)
  1303. printk("e1000_init()\n");
  1304. dev = bdp->device;
  1305. Adapter = (PADAPTER_STRUCT) bdp->bddp; /* Setup Shared Memory Structures */
  1306. /* Make sure RxBufferLen is set to something */
  1307. if (Adapter->RxBufferLen == 0) {
  1308. Adapter->RxBufferLen = E1000_RXBUFFER_2048;
  1309. Adapter->LongPacket = FALSE;
  1310. }
  1311. if (!e1000_sw_init(bdp)) {
  1312. /* Board is disabled because all memory structures
  1313. * could not be allocated
  1314. */
  1315. printk
  1316. ("%s - Could not allocate the software mem structures\n",
  1317. e1000_driver);
  1318. bdp->flags = BOARD_DISABLED;
  1319. return (1);
  1320. }
  1321. /* Setup and initialize the transmit structures. */
  1322. SetupTransmitStructures(Adapter, B_TRUE);
  1323. /* Setup and initialize the receive structures -- we can receive packets
  1324. * off of the wire
  1325. */
  1326. SetupReceiveStructures(bdp, TRUE, TRUE);
  1327. return 0;
  1328. }
  1329. /****************************************************************************
  1330. * Name: e1000_set_mac
  1331. *
  1332. * Description: This routine sets the ethernet address of the board
  1333. *
  1334. * Author: IntelCorporation
  1335. *
  1336. * Born on Date: 07/11/99
  1337. *
  1338. * Arguments:
  1339. * bdp - Ptr to this card's bd_config_t structure
  1340. * eaddrp - Ptr to the new ethernet address
  1341. *
  1342. * Returns:
  1343. * 1 - If successful
  1344. * 0 - If not successful
  1345. *
  1346. * Modification log:
  1347. * Date Who Description
  1348. * -------- --- --------------------------------------------------------
  1349. *
  1350. ****************************************************************************/
  1351. static int
  1352. e1000_set_mac(device_t * dev, void *p)
  1353. {
  1354. bd_config_t *bdp;
  1355. uint32_t HwLowAddress = 0;
  1356. uint32_t HwHighAddress = 0;
  1357. uint32_t RctlRegValue;
  1358. uint16_t PciCommandWord;
  1359. PADAPTER_STRUCT Adapter;
  1360. uint32_t IntMask;
  1361. struct sockaddr *addr = p;
  1362. if (e1000_debug_level >= 1)
  1363. printk("set_eaddr()\n");
  1364. bdp = dev->priv;
  1365. Adapter = bdp->bddp;
  1366. RctlRegValue = E1000_READ_REG(Rctl);
  1367. /*
  1368. * setup the MAC address by writing to RAR0
  1369. */
  1370. if (Adapter->MacType == MAC_WISEMAN_2_0) {
  1371. /* if MWI was enabled then dis able it before issueing the receive
  1372. * reset to the hardware.
  1373. */
  1374. if (Adapter->PciCommandWord && CMD_MEM_WRT_INVALIDATE) {
  1375. PciCommandWord =
  1376. Adapter->PciCommandWord & ~CMD_MEM_WRT_INVALIDATE;
  1377. WritePciConfigWord(PCI_COMMAND_REGISTER, &PciCommandWord);
  1378. }
  1379. /* reset receiver */
  1380. E1000_WRITE_REG(Rctl, E1000_RCTL_RST);
  1381. DelayInMilliseconds(5); /* Allow receiver time to go in to reset */
  1382. }
  1383. memcpy(Adapter->CurrentNetAddress, addr->sa_data, DL_MAC_ADDR_LEN);
  1384. /******************************************************************
  1385. ** Setup the receive address (individual/node/network address).
  1386. ******************************************************************/
  1387. if (e1000_debug_level >= 2)
  1388. printk("Programming IA into RAR[0]\n");
  1389. HwLowAddress = (Adapter->CurrentNetAddress[0] |
  1390. (Adapter->CurrentNetAddress[1] << 8) |
  1391. (Adapter->CurrentNetAddress[2] << 16) |
  1392. (Adapter->CurrentNetAddress[3] << 24));
  1393. HwHighAddress = (Adapter->CurrentNetAddress[4] |
  1394. (Adapter->CurrentNetAddress[5] << 8) | E1000_RAH_AV);
  1395. E1000_WRITE_REG(Rar[0].Low, HwLowAddress);
  1396. E1000_WRITE_REG(Rar[0].High, HwHighAddress);
  1397. memcpy(bdp->eaddr.bytes, addr->sa_data, DL_MAC_ADDR_LEN);
  1398. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  1399. if (Adapter->MacType == MAC_WISEMAN_2_0) {
  1400. /******************************************************************
  1401. ** Take the receiver out of reset.
  1402. ******************************************************************/
  1403. E1000_WRITE_REG(Rctl, 0);
  1404. DelayInMilliseconds(1);
  1405. /* if MWI was enabled then reenable it after issueing the global
  1406. * or receive reset to the hardware.
  1407. */
  1408. if (Adapter->PciCommandWord && CMD_MEM_WRT_INVALIDATE) {
  1409. WritePciConfigWord(PCI_COMMAND_REGISTER,
  1410. &Adapter->PciCommandWord);
  1411. }
  1412. IntMask = E1000_READ_REG(Ims);
  1413. e1000DisableInterrupt(Adapter);
  1414. /* Enable receiver */
  1415. SetupReceiveStructures(bdp, FALSE, FALSE);
  1416. E1000_WRITE_REG(Ims, IntMask);
  1417. /* e1000EnableInterrupt( Adapter ); */
  1418. }
  1419. return (0);
  1420. }
  1421. /****************************************************************************
  1422. * Name: e1000_print_brd_conf
  1423. *
  1424. * Description: This routine printd the board configuration.
  1425. *
  1426. * Author: IntelCorporation
  1427. *
  1428. * Born on Date: 7/24/97
  1429. *
  1430. * Arguments:
  1431. * bdp - Ptr to this card's DL_bdconfig structure
  1432. *
  1433. * Returns:
  1434. * NONE
  1435. *
  1436. * Modification log:
  1437. * Date Who Description
  1438. * -------- --- --------------------------------------------------------
  1439. *
  1440. ****************************************************************************/
  1441. static void
  1442. e1000_print_brd_conf(bd_config_t * bdp)
  1443. {
  1444. PADAPTER_STRUCT Adapter = (PADAPTER_STRUCT) bdp->bddp;
  1445. if(Adapter->LinkIsActive == TRUE)
  1446. printk("%s: Mem:0x%p IRQ:%d Speed:%ld Mbps Dx:%s FlowCtl:%02x\n\n",
  1447. bdp->device->name, (void *) bdp->mem_start,
  1448. bdp->irq_level, Adapter->cur_line_speed,
  1449. Adapter->FullDuplex == FULL_DUPLEX ? "Full" : "Half",
  1450. Adapter->FlowControl);
  1451. else
  1452. printk("%s: Mem:0x%p IRQ:%d Speed:N/A Dx:N/A\n\n",
  1453. bdp->device->name, (void *) bdp->mem_start, bdp->irq_level);
  1454. }
  1455. /*****************************************************************************
  1456. * Name: SetupTransmitStructures
  1457. *
  1458. * Description: This routine initializes all of the transmit related
  1459. * structures. This includes the Transmit descriptors
  1460. * and the TX_SW_PACKETs structures.
  1461. *
  1462. * NOTE -- The device must have been reset before this routine
  1463. * is called.
  1464. *
  1465. * Author: IntelCorporation
  1466. *
  1467. * Born on Date: 6/14/97
  1468. *
  1469. * Arguments:
  1470. * Adapter - A pointer to our context sensitive "Adapter" structure.
  1471. * DebugPrint - print debug or not. ( not used in this driver )
  1472. *
  1473. *
  1474. * Returns:
  1475. * (none)
  1476. *
  1477. * Modification log:
  1478. * Date Who Description
  1479. * -------- --- --------------------------------------------------------
  1480. *
  1481. *****************************************************************************/
  1482. static void
  1483. SetupTransmitStructures(PADAPTER_STRUCT Adapter, boolean_t DebugPrint)
  1484. {
  1485. UINT i;
  1486. if (e1000_debug_level >= 1)
  1487. printk("SetupTransmitStructures\n");
  1488. /**********************************************************************
  1489. * Setup TxSwPackets
  1490. **********************************************************************/
  1491. /*
  1492. * The transmit algorithm parameters like the append size
  1493. * and copy size which are used for the transmit algorithm and
  1494. * are configurable.
  1495. */
  1496. Adapter->TxIntDelay = e1000_txint_delay;
  1497. /**************************************************
  1498. * Setup TX Descriptors
  1499. ***************************************************/
  1500. /* Initialize all of the Tx descriptors to zeros */
  1501. memset((PVOID) Adapter->FirstTxDescriptor, 0,
  1502. (sizeof(E1000_TRANSMIT_DESCRIPTOR)) *
  1503. Adapter->NumTxDescriptors);
  1504. /* Setup TX descriptor pointers */
  1505. Adapter->NextAvailTxDescriptor = Adapter->FirstTxDescriptor;
  1506. Adapter->OldestUsedTxDescriptor = Adapter->FirstTxDescriptor;
  1507. /* Setup the Transmit Control Register (TCTL). */
  1508. if (Adapter->FullDuplex) {
  1509. E1000_WRITE_REG(Tctl, (E1000_TCTL_PSP | E1000_TCTL_EN |
  1510. (E1000_COLLISION_THRESHOLD <<
  1511. E1000_CT_SHIFT) |
  1512. (E1000_FDX_COLLISION_DISTANCE <<
  1513. E1000_COLD_SHIFT)));
  1514. } else {
  1515. E1000_WRITE_REG(Tctl, (E1000_TCTL_PSP | E1000_TCTL_EN |
  1516. (E1000_COLLISION_THRESHOLD <<
  1517. E1000_CT_SHIFT) |
  1518. (E1000_HDX_COLLISION_DISTANCE <<
  1519. E1000_COLD_SHIFT)));
  1520. }
  1521. /***********************************************************
  1522. * Setup Hardware TX Registers
  1523. ************************************************************/
  1524. /* Setup HW Base and Length of Tx descriptor area */
  1525. E1000_WRITE_REG(Tdbal,
  1526. virt_to_bus((void *) Adapter->FirstTxDescriptor));
  1527. E1000_WRITE_REG(Tdbah, 0);
  1528. E1000_WRITE_REG(Tdl, (Adapter->NumTxDescriptors *
  1529. sizeof(E1000_TRANSMIT_DESCRIPTOR)));
  1530. /* Setup our HW Tx Head & Tail descriptor pointers */
  1531. E1000_WRITE_REG(Tdh, 0);
  1532. E1000_WRITE_REG(Tdt, 0);
  1533. /* Zero out the Tx Queue State registers -- we don't use this mechanism. */
  1534. if (Adapter->MacType < MAC_LIVENGOOD) {
  1535. E1000_WRITE_REG(Tqsal, 0);
  1536. E1000_WRITE_REG(Tqsah, 0);
  1537. }
  1538. /* Set the Transmit IPG register with default values.
  1539. * Three values are used to determine when we transmit a packet on the
  1540. * wire: IPGT, IPGR1, & IPGR2. IPGR1 & IPGR2 have no meaning in full
  1541. * duplex. Due to the state machine implimentation all values are
  1542. * effectivly 2 higher i.e. a setting of 10 causes the hardware to
  1543. * behave is if it were set to 1
  1544. * 2. These settigs are in "byte times". For example, an IPGT setting
  1545. * of 10 plus the state machine delay of 2 is 12 byte time = 96 bit
  1546. * times.
  1547. */
  1548. /* Set the Transmit IPG register with default values. */
  1549. switch (Adapter->MacType) {
  1550. case MAC_LIVENGOOD:
  1551. if(Adapter->MediaType == MEDIA_TYPE_FIBER) {
  1552. E1000_WRITE_REG(Tipg, DEFAULT_LVGD_TIPG_IPGT_FIBER |
  1553. (DEFAULT_LVGD_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT) |
  1554. (DEFAULT_LVGD_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT));
  1555. } else {
  1556. E1000_WRITE_REG(Tipg, DEFAULT_LVGD_TIPG_IPGT_COPPER |
  1557. (DEFAULT_LVGD_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT) |
  1558. (DEFAULT_LVGD_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT));
  1559. }
  1560. break;
  1561. case MAC_WISEMAN_2_0:
  1562. case MAC_WISEMAN_2_1:
  1563. default:
  1564. E1000_WRITE_REG(Tipg, DEFAULT_WSMN_TIPG_IPGT |
  1565. (DEFAULT_WSMN_TIPG_IPGR1 << E1000_TIPG_IPGR1_SHIFT) |
  1566. (DEFAULT_WSMN_TIPG_IPGR2 << E1000_TIPG_IPGR2_SHIFT));
  1567. break;
  1568. }
  1569. /*
  1570. * Set the Transmit Interrupt Delay register with the vaule for the
  1571. * transmit interrupt delay
  1572. */
  1573. E1000_WRITE_REG(Tidv, Adapter->TxIntDelay);
  1574. }
  1575. /*****************************************************************************
  1576. * Name: SetupReceiveStructures
  1577. *
  1578. * Description: This routine initializes all of the receive related
  1579. * structures. This includes the receive descriptors, the
  1580. * actual receive buffers, and the RX_SW_PACKET software structures.
  1581. *
  1582. * NOTE -- The device must have been reset before this routine
  1583. * is called.
  1584. *
  1585. * Author: IntelCorporation
  1586. *
  1587. * Born on Date: 6/27/97
  1588. *
  1589. * Arguments:
  1590. * Adapter - A pointer to our context sensitive "Adapter" structure.
  1591. *
  1592. * DebugPrint - A variable that indicates whether a "debug" version of
  1593. * the driver should print debug strings to the terminal.
  1594. *
  1595. * flag - indicates if the driver should indicate link
  1596. * Returns:
  1597. * (none)
  1598. *
  1599. * Modification log:
  1600. * Date Who Description
  1601. * -------- --- --------------------------------------------------------
  1602. *
  1603. *****************************************************************************/
  1604. static int
  1605. SetupReceiveStructures(bd_config_t *bdp, boolean_t DebugPrint,
  1606. boolean_t flag)
  1607. {
  1608. PE1000_RECEIVE_DESCRIPTOR RxDescriptorPtr;
  1609. UINT i;
  1610. PADAPTER_STRUCT Adapter = bdp->bddp;
  1611. uint32_t RegRctl = 0;
  1612. if (e1000_debug_level >= 1)
  1613. printk("SetupReceiveStructures\n");
  1614. /*
  1615. * Set the value of the maximum number of packets that will be processed
  1616. * in the interrupt context from the file space.c
  1617. */
  1618. Adapter->MaxNumReceivePackets = RxDescriptors[Adapter->bd_number];;
  1619. /*
  1620. * Set the Receive interrupt delay and also the maximum number of times
  1621. * the transmit and receive interrupt are going to be processed from the
  1622. * space.c file
  1623. */
  1624. Adapter->RxIntDelay = e1000_rxint_delay;
  1625. Adapter->MaxDpcCount = e1000_maxdpc_count;
  1626. /* Initialize all of the Rx descriptors to zeros */
  1627. memset((PVOID) Adapter->FirstRxDescriptor, 0,
  1628. (sizeof(E1000_RECEIVE_DESCRIPTOR)) * Adapter->NumRxDescriptors);
  1629. for (i = 0, RxDescriptorPtr = Adapter->FirstRxDescriptor;
  1630. i < Adapter->NumRxDescriptors;
  1631. i++, RxDescriptorPtr++) {
  1632. if (Adapter->RxSkBuffs[i] == NULL)
  1633. printk
  1634. ("SetupReceiveStructures rcv buffer memory not allocated");
  1635. else {
  1636. PVOID va = Adapter->RxSkBuffs[i]->tail;
  1637. RxDescriptorPtr->BufferAddress = 0;
  1638. RxDescriptorPtr->BufferAddress += virt_to_bus(va);
  1639. }
  1640. }
  1641. /* Setup our descriptor pointers */
  1642. Adapter->NextRxDescriptorToCheck = Adapter->FirstRxDescriptor;
  1643. Adapter->NextRxIndexToFill = 0;
  1644. /*
  1645. * Set up all the RCTL fields
  1646. */
  1647. E1000_WRITE_REG(Rctl, 0);
  1648. E1000_WRITE_REG(Rdtr0, (Adapter->RxIntDelay | E1000_RDT0_FPDB));
  1649. /* Setup HW Base and Length of Rx descriptor area */
  1650. E1000_WRITE_REG(Rdbal0,
  1651. virt_to_bus((void *) Adapter->FirstRxDescriptor));
  1652. E1000_WRITE_REG(Rdbah0, 0);
  1653. E1000_WRITE_REG(Rdlen0, (Adapter->NumRxDescriptors *
  1654. sizeof(E1000_RECEIVE_DESCRIPTOR)));
  1655. /* Setup our HW Rx Head & Tail descriptor pointers */
  1656. E1000_WRITE_REG(Rdh0, 0);
  1657. E1000_WRITE_REG(Rdt0,
  1658. (((unsigned long) Adapter->LastRxDescriptor -
  1659. (unsigned long) Adapter->FirstRxDescriptor) >> 4));
  1660. /* Zero out the registers associated with the second receive descriptor
  1661. * ring, because we don't use that ring.
  1662. */
  1663. if (Adapter->MacType < MAC_LIVENGOOD) {
  1664. E1000_WRITE_REG(Rdbal1, 0);
  1665. E1000_WRITE_REG(Rdbah1, 0);
  1666. E1000_WRITE_REG(Rdlen1, 0);
  1667. E1000_WRITE_REG(Rdh1, 0);
  1668. E1000_WRITE_REG(Rdt1, 0);
  1669. }
  1670. /* Setup the Receive Control Register (RCTL), and ENABLE the receiver.
  1671. * The initial configuration is to: Enable the receiver, accept
  1672. * broadcasts, discard bad packets (and long packets), disable VLAN filter
  1673. * checking, set the receive descriptor minimum threshold size to 1/2,
  1674. * and the receive buffer size to 2k. */
  1675. RegRctl = E1000_RCTL_EN | /* Enable Receive Unit */
  1676. E1000_RCTL_BAM | /* Accept Broadcast Packets */
  1677. (Adapter->MulticastFilterType << E1000_RCTL_MO_SHIFT) |
  1678. E1000_RCTL_RDMTS0_HALF |
  1679. E1000_RCTL_LBM_NO; /* Loopback Mode = none */
  1680. switch (Adapter->RxBufferLen) {
  1681. case E1000_RXBUFFER_2048:
  1682. default:
  1683. RegRctl |= E1000_RCTL_SZ_2048;
  1684. break;
  1685. case E1000_RXBUFFER_4096:
  1686. RegRctl |= E1000_RCTL_SZ_4096 | E1000_RCTL_BSEX | E1000_RCTL_LPE;
  1687. break;
  1688. case E1000_RXBUFFER_8192:
  1689. RegRctl |= E1000_RCTL_SZ_8192 | E1000_RCTL_BSEX | E1000_RCTL_LPE;
  1690. break;
  1691. case E1000_RXBUFFER_16384:
  1692. RegRctl |= E1000_RCTL_SZ_16384 | E1000_RCTL_BSEX | E1000_RCTL_LPE;
  1693. break;
  1694. }
  1695. if(SBP[Adapter->bd_number] > 0) {
  1696. RegRctl |= E1000_RCTL_SBP;
  1697. }
  1698. E1000_WRITE_REG(Rctl, RegRctl);
  1699. /*
  1700. * Check and report the status of the link
  1701. */
  1702. if (!(E1000_READ_REG(Status) & E1000_STATUS_LU) && (flag == TRUE))
  1703. printk("e1000: %s Link is Down\n", bdp->device->name);
  1704. Adapter->DoRxResetFlag = B_FALSE;
  1705. return (0);
  1706. }
  1707. /*****************************************************************************
  1708. * Name: UpdateStatsCounters
  1709. *
  1710. * Description: This routine will dump and reset the E10001000's internal
  1711. * Statistics counters. The current stats dump values will be
  1712. * added to the "Adapter's" overall statistics.
  1713. *
  1714. * Author: IntelCorporation
  1715. *
  1716. * Born on Date: 6/13/97
  1717. *
  1718. * Arguments:
  1719. * Adapter - A pointer to our context sensitive "Adapter" structure.
  1720. *
  1721. * Returns:
  1722. * (none)
  1723. *
  1724. * Modification log:
  1725. * Date Who Description
  1726. * -------- --- --------------------------------------------------------
  1727. *
  1728. *****************************************************************************/
  1729. static VOID
  1730. UpdateStatsCounters(bd_config_t * bdp)
  1731. {
  1732. PADAPTER_STRUCT Adapter;
  1733. net_device_stats_t *stats;
  1734. Adapter = bdp->bddp;
  1735. stats = &bdp->net_stats;
  1736. /* Add the values from the chip's statistics registers to the total values
  1737. * that we keep in software. These registers clear on read.
  1738. */
  1739. Adapter->RcvCrcErrors += E1000_READ_REG(Crcerrs);
  1740. Adapter->RcvSymbolErrors += E1000_READ_REG(Symerrs);
  1741. Adapter->RcvMissedPacketsErrors += E1000_READ_REG(Mpc);
  1742. Adapter->DeferCount += E1000_READ_REG(Dc);
  1743. Adapter->RcvSequenceErrors += E1000_READ_REG(Sec);
  1744. Adapter->RcvLengthErrors += E1000_READ_REG(Rlec);
  1745. Adapter->RcvXonFrame += E1000_READ_REG(Xonrxc);
  1746. Adapter->TxXonFrame += E1000_READ_REG(Xontxc);
  1747. Adapter->RcvXoffFrame += E1000_READ_REG(Xoffrxc);
  1748. Adapter->TxXoffFrame += E1000_READ_REG(Xofftxc);
  1749. Adapter->Rcv64 += E1000_READ_REG(Prc64);
  1750. Adapter->Rcv65 += E1000_READ_REG(Prc127);
  1751. Adapter->Rcv128 += E1000_READ_REG(Prc255);
  1752. Adapter->Rcv256 += E1000_READ_REG(Prc511);
  1753. Adapter->Rcv512 += E1000_READ_REG(Prc1023);
  1754. Adapter->Rcv1024 += E1000_READ_REG(Prc1522);
  1755. Adapter->GoodReceives += E1000_READ_REG(Gprc);
  1756. Adapter->RcvBroadcastPkts += E1000_READ_REG(Bprc);
  1757. Adapter->RcvMulticastPkts += E1000_READ_REG(Mprc);
  1758. Adapter->GoodTransmits += E1000_READ_REG(Gptc);
  1759. Adapter->Rnbc += E1000_READ_REG(Rnbc);
  1760. Adapter->RcvUndersizeCnt += E1000_READ_REG(Ruc);
  1761. Adapter->RcvFragment += E1000_READ_REG(Rfc);
  1762. Adapter->RcvOversizeCnt += E1000_READ_REG(Roc);
  1763. Adapter->RcvJabberCnt += E1000_READ_REG(Rjc);
  1764. Adapter->TotPktRcv += E1000_READ_REG(Tpr);
  1765. Adapter->TotPktTransmit += E1000_READ_REG(Tpt);
  1766. Adapter->TrsPkt64 += E1000_READ_REG(Ptc64);
  1767. Adapter->TrsPkt65 += E1000_READ_REG(Ptc127);
  1768. Adapter->TrsPkt128 += E1000_READ_REG(Ptc255);
  1769. Adapter->TrsPkt256 += E1000_READ_REG(Ptc511);
  1770. Adapter->TrsPkt512 += E1000_READ_REG(Ptc1023);
  1771. Adapter->TrsPkt1024 += E1000_READ_REG(Ptc1522);
  1772. Adapter->TrsMulticastPkt += E1000_READ_REG(Mptc);
  1773. Adapter->TrsBroadcastPkt += E1000_READ_REG(Bptc);
  1774. Adapter->TxAbortExcessCollisions += E1000_READ_REG(Ecol);
  1775. Adapter->TxLateCollisions += E1000_READ_REG(Latecol);
  1776. Adapter->TotalCollisions += E1000_READ_REG(Colc);
  1777. Adapter->SingleCollisions += E1000_READ_REG(Scc);
  1778. Adapter->MultiCollisions += E1000_READ_REG(Mcc);
  1779. Adapter->FCUnsupported += E1000_READ_REG(Fcruc);
  1780. /* The byte count registers are 64-bits, to reduce the chance of overflow
  1781. * The entire 64-bit register clears when the high 32-bits are read, so the
  1782. * lower half must be read first
  1783. */
  1784. Adapter->RcvGoodOct += E1000_READ_REG(Gorl);
  1785. Adapter->RcvGoodOct += ((uint64_t) E1000_READ_REG(Gorh) << 32);
  1786. Adapter->TrsGoodOct += E1000_READ_REG(Gotl);
  1787. Adapter->TrsGoodOct += ((uint64_t) E1000_READ_REG(Goth) << 32);
  1788. Adapter->RcvTotalOct += E1000_READ_REG(Torl);
  1789. Adapter->RcvTotalOct += ((uint64_t) E1000_READ_REG(Torh) << 32);
  1790. Adapter->TrsTotalOct += E1000_READ_REG(Totl);
  1791. Adapter->TrsTotalOct += ((uint64_t) E1000_READ_REG(Toth) << 32);
  1792. /* New statistics registers in the 82543 */
  1793. if (Adapter->MacType >= MAC_LIVENGOOD) {
  1794. Adapter->AlignmentErrors += E1000_READ_REG(Algnerrc);
  1795. Adapter->TotalRcvErrors += E1000_READ_REG(Rxerrc);
  1796. Adapter->TrsUnderRun += E1000_READ_REG(Tuc);
  1797. Adapter->TrsNoCRS += E1000_READ_REG(Tncrs);
  1798. Adapter->CarrierExtErrors += E1000_READ_REG(Cexterr);
  1799. Adapter->RcvDMATooEarly += E1000_READ_REG(Rutec);
  1800. }
  1801. /* Fill out the OS statistics structure */
  1802. stats->rx_packets = Adapter->GoodReceives; /* total pkts received */
  1803. stats->tx_packets = Adapter->GoodTransmits; /* total pkts transmitted */
  1804. stats->rx_bytes = Adapter->RcvGoodOct; /* total bytes reveived */
  1805. stats->tx_bytes = Adapter->TrsGoodOct; /* total bytes transmitted */
  1806. stats->multicast = Adapter->RcvMulticastPkts; /* multicast pkts received */
  1807. stats->collisions = Adapter->TotalCollisions; /* total collision count */
  1808. /* Rx Errors */
  1809. stats->rx_errors = Adapter->TotalRcvErrors + Adapter->RcvCrcErrors +
  1810. Adapter->AlignmentErrors +
  1811. Adapter->RcvLengthErrors +
  1812. Adapter->Rnbc + Adapter->RcvMissedPacketsErrors +
  1813. Adapter->CarrierExtErrors;
  1814. stats->rx_dropped = Adapter->Rnbc;
  1815. stats->rx_length_errors = Adapter->RcvLengthErrors;
  1816. stats->rx_crc_errors = Adapter->RcvCrcErrors;
  1817. stats->rx_frame_errors = Adapter->AlignmentErrors;
  1818. stats->rx_fifo_errors = Adapter->RcvMissedPacketsErrors;
  1819. stats->rx_missed_errors = Adapter->RcvMissedPacketsErrors;
  1820. /* Tx Errors */
  1821. stats->tx_errors = Adapter->TxAbortExcessCollisions +
  1822. Adapter->TrsUnderRun +
  1823. Adapter->TxLateCollisions;
  1824. stats->tx_aborted_errors = Adapter->TxAbortExcessCollisions;
  1825. stats->tx_fifo_errors = Adapter->TrsUnderRun;
  1826. stats->tx_window_errors = Adapter->TxLateCollisions;
  1827. /* Tx Dropped needs to be maintained elsewhere */
  1828. }
  1829. /****************************************************************************
  1830. *
  1831. * Name: ReadNodeAddress
  1832. *
  1833. * Description: Gets the node/Ethernet/Individual Address for this NIC
  1834. * from the EEPROM.
  1835. *
  1836. * Example EEPROM map:
  1837. * Word 0 = AA00
  1838. * Word 1 = 1100
  1839. * Word 2 = 3322
  1840. *
  1841. * Author: IntelCorporation
  1842. *
  1843. * Born on Date: 3/30/98
  1844. *
  1845. * Arguments:
  1846. * Adapter Ptr to this card's adapter data structure
  1847. *
  1848. * Returns:
  1849. * Status RET_STATUS_SUCCESS = read valid address
  1850. * RET_STATUS_FAILURE = unable to read address
  1851. *
  1852. * Modification log:
  1853. * Date Who Description
  1854. * -------- --- --------------------------------------------------------
  1855. ***************************************************************************/
  1856. static int
  1857. ReadNodeAddress(IN PADAPTER_STRUCT Adapter, OUT PUCHAR NodeAddress)
  1858. {
  1859. UINT i;
  1860. USHORT EepromWordValue;
  1861. DL_LOG(strlog(DL_ID, 0, 3, SL_TRACE, "ReadNodeAddress"));
  1862. /* Read our node address from the EEPROM. */
  1863. for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
  1864. /* Get word i from EEPROM */
  1865. EepromWordValue = ReadEepromWord(IN Adapter, IN(USHORT)
  1866. (EEPROM_NODE_ADDRESS_BYTE_0
  1867. + (i / 2)));
  1868. /* Save byte i */
  1869. NodeAddress[i] = (UCHAR) EepromWordValue;
  1870. /* Save byte i+1 */
  1871. NodeAddress[i + 1] = (UCHAR) (EepromWordValue >> 8);
  1872. }
  1873. /* Our IA should not have the Multicast bit set */
  1874. if (NodeAddress[0] & 0x1) {
  1875. return (RET_STATUS_FAILURE);
  1876. }
  1877. memcpy(&Adapter->CurrentNetAddress[0],
  1878. &Adapter->perm_node_address[0], DL_MAC_ADDR_LEN);
  1879. return (RET_STATUS_SUCCESS);
  1880. }
  1881. /*****************************************************************************
  1882. * Name: e1000_set_promisc
  1883. *
  1884. * Description: This routine sets the promiscous mode for receiving packets
  1885. * that it is passed.
  1886. *
  1887. * Author: IntelCorporation
  1888. *
  1889. * Born on Date: 7/7/97
  1890. *
  1891. * Arguments:
  1892. * bd_config_t - board struct
  1893. * flag - turn it on( B_TRUE ) or off ( B_FALSE )
  1894. *
  1895. * Returns:
  1896. * B_FALSE - if successful
  1897. * B_TRUE - if not
  1898. *
  1899. * Modification log:
  1900. * Date Who Description
  1901. * -------- --- --------------------------------------------------------
  1902. *
  1903. *****************************************************************************/
  1904. static int
  1905. e1000_set_promisc(bd_config_t * bdp, int flag)
  1906. {
  1907. uint32_t RctlRegValue;
  1908. uint32_t TempRctlReg;
  1909. uint32_t NewRctlReg;
  1910. PADAPTER_STRUCT Adapter;
  1911. Adapter = (PADAPTER_STRUCT) bdp->bddp;
  1912. /*
  1913. * Save the original value in the RCTL register
  1914. */
  1915. RctlRegValue = E1000_READ_REG(Rctl);
  1916. TempRctlReg = RctlRegValue;
  1917. if (e1000_debug_level >= 1)
  1918. printk("e1000_set_promiscuous, SOR");
  1919. /* Check to see if we should set/clear the "Unicast Promiscuous" bit. */
  1920. if (flag == B_TRUE) {
  1921. /*
  1922. * Since the promiscuous flag is set to TRUE, set both the unicast as
  1923. * well as the multicast promiscuous mode on the RCTL
  1924. */
  1925. TempRctlReg |= (E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_BAM);
  1926. E1000_WRITE_REG(Rctl, TempRctlReg);
  1927. if (e1000_debug_level >= 1)
  1928. printk("Promiscuous mode ON");
  1929. } else {
  1930. /*
  1931. * Turn off both the unicast as well as the multicast promiscuous mode
  1932. */
  1933. TempRctlReg &= (~E1000_RCTL_UPE);
  1934. TempRctlReg &= (~E1000_RCTL_MPE);
  1935. E1000_WRITE_REG(Rctl, TempRctlReg);
  1936. if (e1000_debug_level >= 1)
  1937. printk("Promiscuous mode OFF");
  1938. }
  1939. /* Write the new filter back to the adapter, if it has changed */
  1940. if (TempRctlReg != RctlRegValue) {
  1941. E1000_WRITE_REG(Rctl, TempRctlReg);
  1942. }
  1943. NewRctlReg = E1000_READ_REG(Rctl);
  1944. if (NewRctlReg != TempRctlReg)
  1945. return (B_FALSE);
  1946. else
  1947. return (B_TRUE);
  1948. }
  1949. /*****************************************************************************
  1950. * Name: e1000DisableInterrupt
  1951. *
  1952. * Description: This routine disables (masks) all interrupts on our adapter.
  1953. *
  1954. * Author: IntelCorporation
  1955. *
  1956. * Born on Date: 8/25/97
  1957. *
  1958. * Arguments:
  1959. * pointer to our "Adapter" structure.
  1960. *
  1961. * Returns:
  1962. * (none)
  1963. *
  1964. * Modification log:
  1965. * Date Who Description
  1966. * -------- --- --------------------------------------------------------
  1967. *
  1968. *****************************************************************************/
  1969. static void
  1970. e1000DisableInterrupt(PADAPTER_STRUCT Adapter)
  1971. {
  1972. if (e1000_debug_level >= 1)
  1973. printk("DisableInterrupts: SOR\n");
  1974. /*
  1975. * Mask all adapter interrupts.
  1976. */
  1977. E1000_WRITE_REG(Imc, (0xffffffff & ~E1000_IMC_RXSEQ));
  1978. }
  1979. /*****************************************************************************
  1980. * Name: e1000EnableInterrupt
  1981. *
  1982. * Description: This routine enables (un-masks) all interrupts on our adapter.
  1983. *
  1984. * Author: IntelCorporation
  1985. *
  1986. * Born on Date: 8/25/97
  1987. *
  1988. * Arguments:
  1989. * pointer to our "Adapter" structure.
  1990. *
  1991. * Returns:
  1992. * (none)
  1993. *
  1994. * Modification log:
  1995. * Date Who Description
  1996. * -------- --- --------------------------------------------------------
  1997. *
  1998. *****************************************************************************/
  1999. static void
  2000. e1000EnableInterrupt(PADAPTER_STRUCT Adapter)
  2001. {
  2002. if (e1000_debug_level >= 1)
  2003. printk("EnableInterrupts: SOR\n");
  2004. /* Enable interrupts (SBL -- may want to enable different int bits..) */
  2005. E1000_WRITE_REG(Ims, IMS_ENABLE_MASK);
  2006. }
  2007. /*****************************************************************************
  2008. * Name: e1000_intr
  2009. *
  2010. * Description: This routine is the ISR for the e1000 board. It services
  2011. * the RX & TX queues & starts the RU if it has stopped due
  2012. * to no resources.
  2013. *
  2014. * Author: IntelCorporation
  2015. *
  2016. * Born on Date: 8/25/97
  2017. *
  2018. * Arguments:
  2019. * ivec - The interrupt vector for this board.
  2020. *
  2021. * Returns:
  2022. * (none)
  2023. *
  2024. * Modification log:
  2025. * Date Who Description
  2026. * -------- --- --------------------------------------------------------
  2027. *
  2028. *****************************************************************************/
  2029. static void
  2030. e1000_intr(int irq, void *dev_inst, struct pt_regs *regs)
  2031. {
  2032. /* note - regs is not used but required by the system */
  2033. uint32_t IcrContents;
  2034. PADAPTER_STRUCT Adapter;
  2035. uint32_t CtrlRegValue, TxcwRegValue, RxcwRegValue;
  2036. UINT DpcCount;
  2037. device_t *dev;
  2038. bd_config_t *bdp;
  2039. dev = (device_t *) dev_inst;
  2040. bdp = dev->priv;
  2041. Adapter = (PADAPTER_STRUCT) bdp->bddp;
  2042. if (e1000_debug_level >= 1)
  2043. printk("e1000_intr: bdp = 0x%p\n ", bdp);
  2044. if (!Adapter)
  2045. return;
  2046. /*
  2047. * The board is present but not yet initialized. Since the board is not
  2048. * initialized we do not process the interrupt
  2049. */
  2050. if (!bdp->flags || (bdp->flags & BOARD_DISABLED)) {
  2051. return;
  2052. }
  2053. #ifdef CLICK_POLLING
  2054. if(dev->polling)
  2055. printk("e1000_intr: polling!\n");
  2056. #endif
  2057. /* get board status */
  2058. if ((IcrContents = E1000_READ_REG(Icr))) {
  2059. #ifdef CLICK_POLLING
  2060. if(dev->polling)
  2061. printk("e1000_intr: icr %x\n", IcrContents);
  2062. #endif
  2063. /* This card actually has interrupts to process */
  2064. /* Disable Interrupts from this card */
  2065. e1000DisableInterrupt(Adapter);
  2066. /*
  2067. * The Receive Sequence errors RXSEQ and the link status change LSC
  2068. * are checked to detect that the cable has been pulled out. For
  2069. * the 82542 silicon, the receive sequence errors interrupt
  2070. * are an indication that cable is not connected. If there are
  2071. * sequence errors or if link status has changed, proceed to the
  2072. * cable disconnect workaround
  2073. */
  2074. if (IcrContents & (E1000_ICR_RXSEQ|E1000_ICR_LSC|E1000_ICR_GPI_EN1)) {
  2075. Adapter->GetLinkStatus =
  2076. Adapter->LinkStatusChanged = TRUE;
  2077. /* run the watchdog ASAP */
  2078. mod_timer(&bdp->timer_id, jiffies);
  2079. }
  2080. if(IcrContents & E1000_ICR_GPI_EN1) {
  2081. ReadPhyRegister(Adapter, PXN_INT_STATUS_REG, Adapter->PhyAddress);
  2082. }
  2083. if(Adapter->LinkStatusChanged &&
  2084. Adapter->MediaType == MEDIA_TYPE_FIBER) {
  2085. CtrlRegValue = E1000_READ_REG(Ctrl);
  2086. TxcwRegValue = E1000_READ_REG(Txcw);
  2087. RxcwRegValue = E1000_READ_REG(Rxcw);
  2088. if((CtrlRegValue & E1000_CTRL_SWDPIN1) ||
  2089. ((RxcwRegValue & E1000_RXCW_C) &&
  2090. (TxcwRegValue & E1000_TXCW_ANE))) {
  2091. E1000_WRITE_REG(Txcw, Adapter->TxcwRegValue);
  2092. E1000_WRITE_REG(Ctrl, CtrlRegValue & ~E1000_CTRL_SLU);
  2093. Adapter->AutoNegFailed = 0;
  2094. }
  2095. Adapter->LinkStatusChanged = FALSE;
  2096. }
  2097. if(Adapter->LinkStatusChanged &&
  2098. Adapter->MediaType == MEDIA_TYPE_COPPER) {
  2099. CheckForLink(Adapter);
  2100. }
  2101. DpcCount = Adapter->MaxDpcCount;
  2102. /*
  2103. * Since we are already in the interrupt context, we want to clean up
  2104. * as many transmit and receive packets that have been processed by
  2105. * E1000 since taking interrupts is expensive. We keep a count called
  2106. * the DpcCount which is the maximum number of times that we will try
  2107. * to clean up interrupts from within this interrupt context. If the
  2108. * count is too high, it can lead to interrupt starvation
  2109. */
  2110. while (dev->polling == 0 && DpcCount > 0) {
  2111. /* Process the receive interrupts to clean receive descriptors */
  2112. if (e1000_debug_level >= 3)
  2113. printk("intr: DpcCount = 0x%x\n ", DpcCount);
  2114. ProcessReceiveInterrupts(bdp);
  2115. /*
  2116. * Process and clean up transmit interrupts
  2117. */
  2118. ProcessTransmitInterrupts(bdp, 1);
  2119. DpcCount--;
  2120. if (DpcCount) {
  2121. if (!(E1000_READ_REG(Icr))) {
  2122. break;
  2123. }
  2124. }
  2125. }
  2126. /* Enable Interrupts */
  2127. #ifdef CLICK_POLLING
  2128. if(dev->polling == 0)
  2129. e1000EnableInterrupt(Adapter);
  2130. #else
  2131. e1000EnableInterrupt(Adapter);
  2132. #endif
  2133. /*
  2134. * If there are any frames that have been queued, they are also
  2135. * Processed from this context. ??? We need to verify if there is
  2136. * any benefit of doing this
  2137. */
  2138. }
  2139. return;
  2140. }
  2141. /****************************************************************************
  2142. * Name: ProcessTransmitInterrupts
  2143. *
  2144. * Description: This routine services the TX queues. It reclaims the
  2145. * TCB's & TBD's & other resources used during the transmit
  2146. * of this buffer. It is called from the ISR.
  2147. *
  2148. * Author: IntelCorporation
  2149. *
  2150. * Born on Date: 8/7/97
  2151. *
  2152. * Arguments:
  2153. * bdp - Ptr to this card's DL_bdconfig structure
  2154. *
  2155. * Returns:
  2156. * NONE
  2157. *
  2158. * Modification log:
  2159. * Date Who Description
  2160. * -------- --- --------------------------------------------------------
  2161. *
  2162. ****************************************************************************/
  2163. static struct sk_buff *
  2164. ProcessTransmitInterrupts(bd_config_t * bdp, int clean)
  2165. {
  2166. PE1000_TRANSMIT_DESCRIPTOR td;
  2167. PADAPTER_STRUCT Adapter;
  2168. UINT NumTxSwPacketsCleaned = 0;
  2169. device_t *dev;
  2170. int lock_flag_tx, di, freed_some = 0;
  2171. struct sk_buff *skb_head, *skb_last;
  2172. skb_head = skb_last = 0;
  2173. if (e1000_debug_level >= 3)
  2174. printk("ProcessTransmitInterrupts, SOR\n");
  2175. Adapter = (PADAPTER_STRUCT) bdp->bddp;
  2176. dev = bdp->device;
  2177. while(1){
  2178. td = Adapter->OldestUsedTxDescriptor;
  2179. if (td > Adapter->LastTxDescriptor)
  2180. td -= Adapter->NumTxDescriptors;
  2181. /* Quit if we've caught up with SendBuffer */
  2182. if(td == Adapter->NextAvailTxDescriptor)
  2183. break;
  2184. /* Quit if board hasn't sent this packet. */
  2185. if((td->Upper.Fields.TransmitStatus & E1000_TXD_STAT_DD) == 0)
  2186. break;
  2187. if (td == Adapter->LastTxDescriptor)
  2188. Adapter->OldestUsedTxDescriptor = Adapter->FirstTxDescriptor;
  2189. else
  2190. Adapter->OldestUsedTxDescriptor = (td + 1);
  2191. di = td - Adapter->FirstTxDescriptor;
  2192. if (clean)
  2193. dev_kfree_skb_irq(Adapter->TxSkBuffs[di]);
  2194. else {
  2195. struct sk_buff *skb = Adapter->TxSkBuffs[di];
  2196. if (skb_head == 0) {
  2197. skb_head = skb;
  2198. skb_last = skb;
  2199. skb_last->next = NULL;
  2200. } else {
  2201. skb_last->next = skb;
  2202. skb->next = NULL;
  2203. skb_last = skb;
  2204. }
  2205. #if __i386__ && HAVE_INTEL_CPU
  2206. asm volatile("prefetcht0 %0" :: "m" (skb->head));
  2207. #endif
  2208. }
  2209. Adapter->TxSkBuffs[di] = 0;
  2210. NumTxSwPacketsCleaned++;
  2211. freed_some++;
  2212. }
  2213. /*
  2214. * Clear tbusy if we freed some descriptors.
  2215. */
  2216. if (freed_some && bdp->tx_out_res){
  2217. bdp->tx_out_res = 0;
  2218. #ifdef IANS
  2219. if(bdp->iANSdata->iANS_status == IANS_COMMUNICATION_UP) {
  2220. ans_notify(dev, IANS_IND_XMIT_QUEUE_READY);
  2221. }
  2222. #endif
  2223. clear_bit(0, (void*)&dev->tbusy);
  2224. #ifdef CLICK_POLLING
  2225. if (dev->polling == 0)
  2226. #endif
  2227. netif_wake_queue(dev);
  2228. }
  2229. return skb_head;
  2230. }
  2231. /****************************************************************************
  2232. * Name: e1000_set_multicast
  2233. *
  2234. * Description: This routine sets a list of multicast addresses
  2235. * as requested by the DLPI module in the 128 * 32 MTA
  2236. * vector table. It also calculates the appropriate hash
  2237. * value and sets the bit in the vector table
  2238. *
  2239. * Author: IntelCorporation
  2240. *
  2241. * Born on Date: 1/12/98
  2242. *
  2243. * Arguments:
  2244. * dev - Ptr to this card's dev structure
  2245. *
  2246. * Returns:
  2247. * NONE
  2248. *
  2249. * Modification log:
  2250. * Date Who Description
  2251. * -------- --- --------------------------------------------------------
  2252. *
  2253. ****************************************************************************/
  2254. static void
  2255. e1000_set_multi(device_t * dev)
  2256. {
  2257. bd_config_t *bdp;
  2258. PADAPTER_STRUCT Adapter;
  2259. uint32_t TempRctlReg = 0;
  2260. uint32_t HwLowAddress;
  2261. uint32_t HwHighAddress;
  2262. USHORT i, j;
  2263. UINT HashValue = 0, HashReg, HashBit;
  2264. UINT TempUint;
  2265. int ret_val;
  2266. PUCHAR MulticastBuffer;
  2267. uint16_t PciCommandWord;
  2268. uint32_t IntMask;
  2269. struct dev_mc_list *mc_list;
  2270. uchar_t *mc_buff;
  2271. /* The data must be a multiple of the Ethernet address size. */
  2272. if (e1000_debug_level >= 1)
  2273. printk("e1000_set_multicast\n");
  2274. bdp = dev->priv;
  2275. Adapter = (PADAPTER_STRUCT) bdp->bddp;
  2276. MulticastBuffer = Adapter->pmc_buff->MulticastBuffer;
  2277. /* check to see if promiscuous mode should be enabled */
  2278. if ((dev->flags & IFF_PROMISC) && !(bdp->flags & PROMISCUOUS)) {
  2279. /* turn promisc mode on */
  2280. ret_val = e1000_set_promisc(bdp, B_TRUE);
  2281. bdp->flags |= PROMISCUOUS;
  2282. } else {
  2283. /* turn promisc mode off */
  2284. ret_val = e1000_set_promisc(bdp, B_FALSE);
  2285. bdp->flags &= ~PROMISCUOUS;
  2286. }
  2287. #if 0 /* we should try to enable this feature... */
  2288. /* this is how you turn on receiving ALL multicast addrs */
  2289. if ((dev->flags & IFF_ALLMULTI) && !(bdp->flags & ALL_MULTI)) {
  2290. /* turn on recv all multi addrs */
  2291. TempRctlReg |= E1000_RCTL_MPE;
  2292. E1000_WRITE_REG(Rctl, TempRctlReg);
  2293. bdp->flags |= ALL_MULTI;
  2294. } else {
  2295. /* turn off recv all multi addrs */
  2296. TempRctlReg &= ~E1000_RCTL_MPE;
  2297. /* this next line with hang the load, so be careful... */
  2298. E1000_WRITE_REG(Rctl, TempRctlReg);
  2299. bdp->flags &= ~ALL_MULTI;
  2300. }
  2301. #endif
  2302. mc_buff = Adapter->pmc_buff->MulticastBuffer;
  2303. /* Fill in the multicast addresses. */
  2304. for (i = 0, mc_list = dev->mc_list; i < dev->mc_count;
  2305. i++, mc_list = mc_list->next) {
  2306. memcpy(mc_buff, (u8 *) & mc_list->dmi_addr, DL_MAC_ADDR_LEN);
  2307. mc_buff += DL_MAC_ADDR_LEN;
  2308. }
  2309. /* reset the MulticastBuffer pointer */
  2310. /* set the count in the Adapter struct */
  2311. Adapter->NumberOfMcAddresses = dev->mc_count;
  2312. /* adjust the count on addrs to bytes */
  2313. Adapter->pmc_buff->mc_count = dev->mc_count * DL_MAC_ADDR_LEN;
  2314. /* The E1000 has the ability to do perfect filtering of 16 addresses.
  2315. * The driver uses one of the E1000's 16 receive address registers
  2316. * for its node/network/mac/individual address. So, we have room
  2317. * for up to 15 multicast addresses in the CAM, additional MC
  2318. * addresses are handled by the MTA (Multicast Table Array)
  2319. */
  2320. /* this just needs to be the count of how many addrs
  2321. * there are in the table
  2322. */
  2323. TempUint = dev->mc_count;
  2324. /* If we were using the MTA then it must be cleared */
  2325. if (Adapter->NumberOfMcAddresses > E1000_RAR_ENTRIES - 1) {
  2326. for (i = 0; i < E1000_NUM_MTA_REGISTERS; i++) {
  2327. E1000_WRITE_REG(Mta[i], 0);
  2328. }
  2329. }
  2330. /* If we are given more MC addresses than we can handle, then we'll
  2331. * notify the OS that we can't accept any more MC addresses
  2332. */
  2333. if (TempUint > MAX_NUM_MULTICAST_ADDRESSES) {
  2334. Adapter->NumberOfMcAddresses = MAX_NUM_MULTICAST_ADDRESSES;
  2335. } else {
  2336. /* Set the number of MC addresses that we are being requested to use */
  2337. Adapter->NumberOfMcAddresses = TempUint;
  2338. }
  2339. /* Store the Rctl values to use for restoring */
  2340. TempRctlReg = E1000_READ_REG(Rctl);
  2341. if (Adapter->MacType == MAC_WISEMAN_2_0) {
  2342. /* if MWI was enabled then disable it before issueing the global
  2343. * reset to the hardware.
  2344. */
  2345. if (Adapter->PciCommandWord && CMD_MEM_WRT_INVALIDATE) {
  2346. PciCommandWord =
  2347. Adapter->PciCommandWord & ~CMD_MEM_WRT_INVALIDATE;
  2348. WritePciConfigWord(PCI_COMMAND_REGISTER, &PciCommandWord);
  2349. }
  2350. /* The E1000 must be in reset before changing any RA registers.
  2351. * Reset receive unit. The chip will remain in the reset state
  2352. * until software explicitly restarts it.
  2353. */
  2354. E1000_WRITE_REG(Rctl, E1000_RCTL_RST);
  2355. DelayInMilliseconds(5); /* Allow receiver time to go in to reset */
  2356. }
  2357. /**********************************************************************
  2358. * Copy up to 15 MC addresses into the E1000's receive address
  2359. * registers pairs (Ral Rah). The first pair (Ral0 Rah0) is used
  2360. * for our MAC/Node/Network address/IA. If there are more than 15
  2361. * multicast addresses then the additional addresses will be hashed
  2362. * and the Multicast Table Array (MTA) will be used.
  2363. **********************************************************************/
  2364. for (i = 0, j = 1;
  2365. (i < Adapter->NumberOfMcAddresses && j < E1000_RAR_ENTRIES);
  2366. i++, j++) {
  2367. /* HW expcets these in big endian so we reverse the byte order */
  2368. HwLowAddress =
  2369. (MulticastBuffer[i * ETH_LENGTH_OF_ADDRESS] |
  2370. (MulticastBuffer[i * ETH_LENGTH_OF_ADDRESS + 1] << 8)
  2371. | (MulticastBuffer[i * ETH_LENGTH_OF_ADDRESS + 2] <<
  2372. 16) |
  2373. (MulticastBuffer[i * ETH_LENGTH_OF_ADDRESS + 3] << 24));
  2374. /* HW expcets these in big endian so we reverse the byte order */
  2375. HwHighAddress =
  2376. (MulticastBuffer[i * ETH_LENGTH_OF_ADDRESS + 4] |
  2377. (MulticastBuffer[i * ETH_LENGTH_OF_ADDRESS +
  2378. 5] << 8) | E1000_RAH_AV);
  2379. E1000_WRITE_REG(Rar[j].Low, HwLowAddress);
  2380. E1000_WRITE_REG(Rar[j].High, HwHighAddress);
  2381. }
  2382. /* if the Receive Addresses Registers are not full then
  2383. * Clear the E1000_RAH_AV bit in other Receive Address Registers
  2384. * NOTE: 'j' must be unchanged from the RAL/RAH loop
  2385. */
  2386. while (j < E1000_RAR_ENTRIES) {
  2387. E1000_WRITE_REG(Rar[j].Low, 0);
  2388. E1000_WRITE_REG(Rar[j].High, 0);
  2389. j++;
  2390. }
  2391. /* hash each remaining (if any) MC address into the E1000's receive
  2392. * multicast hash table. NOTE: 'i' must be unchanged from the RAL/RAH loop
  2393. */
  2394. while (i < Adapter->NumberOfMcAddresses) {
  2395. /* The portion of the address that is used for the hash table is
  2396. * determined by the MulticastFilterType setting.
  2397. */
  2398. switch (Adapter->MulticastFilterType) {
  2399. /* [0] [1] [2] [3] [4] [5]
  2400. * 01 AA 00 12 34 56
  2401. * LSB MSB - According to H/W docs
  2402. */
  2403. case 0: /* [47:36] i.e. 0x563 for above example address */
  2404. HashValue =
  2405. ((MulticastBuffer
  2406. [i * ETH_LENGTH_OF_ADDRESS +
  2407. 4] >> 4) | (((USHORT) MulticastBuffer[i *
  2408. ETH_LENGTH_OF_ADDRESS
  2409. + 5]) << 4));
  2410. break;
  2411. case 1: /* [46:35] i.e. 0xAC6 for above example address */
  2412. HashValue =
  2413. ((MulticastBuffer
  2414. [i * ETH_LENGTH_OF_ADDRESS +
  2415. 4] >> 3) | (((USHORT) MulticastBuffer[i *
  2416. ETH_LENGTH_OF_ADDRESS
  2417. + 5]) << 5));
  2418. break;
  2419. case 2: /* [45:34] i.e. 0x5D8 for above example address */
  2420. HashValue =
  2421. ((MulticastBuffer
  2422. [i * ETH_LENGTH_OF_ADDRESS +
  2423. 4] >> 2) | (((USHORT) MulticastBuffer[i *
  2424. ETH_LENGTH_OF_ADDRESS
  2425. + 5]) << 6));
  2426. break;
  2427. case 3: /* [43:32] i.e. 0x634 for above example address */
  2428. HashValue =
  2429. ((MulticastBuffer
  2430. [i * ETH_LENGTH_OF_ADDRESS + 4]) | (((USHORT)
  2431. MulticastBuffer
  2432. [i *
  2433. ETH_LENGTH_OF_ADDRESS
  2434. + 5]) << 8));
  2435. break;
  2436. }
  2437. /**********************************************************
  2438. * Set the corresponding bit in the Multicast Table Array.
  2439. * Mta is treated like a bit vector of 4096 bit split in
  2440. * to 128 registers of 32 bits each. The Register to set
  2441. * is in bits 11:5 of HashValue and the Bit within the
  2442. * register to set is bits 4:0.
  2443. ************************************************************/
  2444. /* Bit number to set is in lower 5 bits */
  2445. HashBit = HashValue & 0x1F;
  2446. /* MTA register number is bits 11:5 */
  2447. HashReg = (HashValue >> 5) & 0x7F;
  2448. /* Read MTA entry */
  2449. TempUint = E1000_READ_REG(Mta[(HashReg)]);
  2450. /* Set hashed bit */
  2451. TempUint |= (1 << HashBit);
  2452. /* Write new value */
  2453. E1000_WRITE_REG(Mta[HashReg], TempUint);
  2454. i++;
  2455. }
  2456. if (Adapter->MacType == MAC_WISEMAN_2_0) {
  2457. /* if WMI was enabled then reenable it after issueing the global
  2458. * or receive reset to the hardware.
  2459. */
  2460. if (Adapter->PciCommandWord && CMD_MEM_WRT_INVALIDATE) {
  2461. WritePciConfigWord(PCI_COMMAND_REGISTER,
  2462. &Adapter->PciCommandWord);
  2463. }
  2464. DelayInMilliseconds(5);
  2465. /* Take receiver out of reset */
  2466. E1000_WRITE_REG(Rctl, 0);
  2467. /* clear E1000_RCTL_RST bit (and all others) */
  2468. IntMask = E1000_READ_REG(Ims);
  2469. e1000DisableInterrupt(Adapter);
  2470. /* Enable receiver */
  2471. SetupReceiveStructures(bdp, FALSE, FALSE);
  2472. /* e1000EnableInterrupt( Adapter ); */
  2473. E1000_WRITE_REG(Ims, IntMask);
  2474. /* Restore Receive Control to state it was in prior to MC add request */
  2475. E1000_WRITE_REG(Rctl, TempRctlReg);
  2476. }
  2477. return;
  2478. }
  2479. /****************************************************************************
  2480. * Name: ProcessReceiveInterrupts
  2481. *
  2482. * Description: This routine processes the RX interrupt & services the
  2483. * RX queues. For each successful RFD, it allocates a
  2484. * msg block & sends the msg upstream. The freed RFD is then
  2485. * put at the end of the free list of RFD's.
  2486. *
  2487. * Author: IntelCorporation
  2488. *
  2489. * Born on Date: 7/19/97
  2490. *
  2491. * Arguments:
  2492. * bdp - Ptr to this card's DL_bdconfig structure
  2493. *
  2494. * Returns:
  2495. * NONE
  2496. *
  2497. * Modification log:
  2498. * Date Who Description
  2499. * -------- --- --------------------------------------------------------
  2500. *
  2501. ****************************************************************************/
  2502. static void
  2503. ProcessReceiveInterrupts(bd_config_t * bdp)
  2504. {
  2505. PADAPTER_STRUCT Adapter;
  2506. device_t *dev;
  2507. int bytes_srvcd; /* # of bytes serviced */
  2508. sk_buff_t *skb, *new_skb;
  2509. /* Pointer to the receive descriptor being examined. */
  2510. PE1000_RECEIVE_DESCRIPTOR CurrentDescriptor;
  2511. PE1000_RECEIVE_DESCRIPTOR LastDescriptorProcessed;
  2512. /* The amount of data received in the RBA (will be PacketSize +
  2513. * 4 for the CRC).
  2514. */
  2515. USHORT Length;
  2516. UINT Count = 0;
  2517. BOOLEAN Status = FALSE;
  2518. // net_device_stats_t *stats;
  2519. if (e1000_debug_level >= 3)
  2520. printk("ProcessReceiveInterrupts, SOR\n");
  2521. Adapter = (PADAPTER_STRUCT) bdp->bddp;
  2522. dev = bdp->device;
  2523. // stats = &bdp->net_stats;
  2524. bytes_srvcd = 0;
  2525. CurrentDescriptor = Adapter->NextRxDescriptorToCheck;
  2526. if (!((CurrentDescriptor->ReceiveStatus) & E1000_RXD_STAT_DD)) {
  2527. if (e1000_debug_level >= 3)
  2528. printk("Proc_rx_ints: Nothing to do!\n");
  2529. /* don't send anything up. just clear the RFD */
  2530. return;
  2531. }
  2532. /* Loop through the receive descriptors starting at the last known
  2533. * descriptor owned by the hardware that begins a packet.
  2534. */
  2535. while ((CurrentDescriptor->ReceiveStatus & E1000_RXD_STAT_DD) &&
  2536. (Count < Adapter->MaxNumReceivePackets)) {
  2537. int di = CurrentDescriptor - Adapter->FirstRxDescriptor;
  2538. /* Make sure this is also the last descriptor in the packet. */
  2539. if (!(CurrentDescriptor->ReceiveStatus & E1000_RXD_STAT_EOP)) {
  2540. /*
  2541. * If the received packet has spanned multiple descriptors, ignore
  2542. * and discard all the packets that do not have EOP set and proceed
  2543. * to the next packet.
  2544. */
  2545. printk("Receive packet consumed mult buffers\n");
  2546. new_skb = Adapter->RxSkBuffs[di];
  2547. } else { /* packet has EOP set - begin */
  2548. /*
  2549. * Store the packet length. Take the CRC lenght out of the length
  2550. * calculation.
  2551. */
  2552. Length = CurrentDescriptor->Length - CRC_LENGTH;
  2553. /*
  2554. * Only the packets that are valid ethernet packets are processed and
  2555. * sent up the stack.Normally, hardware will discard bad packets .
  2556. */
  2557. #ifdef IANS_BASE_VLAN_TAGGING
  2558. if ((Length <= (Adapter->LongPacket == TRUE ? MAX_JUMBO_FRAME_SIZE :
  2559. MAXIMUM_ETHERNET_PACKET_SIZE))
  2560. && (Length >=
  2561. (bdp->iANSdata->tag_mode == IANS_BD_TAGGING_802_3AC ?
  2562. MINIMUM_ETHERNET_PACKET_SIZE - QTAG_SIZE :
  2563. MINIMUM_ETHERNET_PACKET_SIZE))
  2564. && ((CurrentDescriptor->Errors == 0) ||
  2565. (SBP[Adapter->bd_number] > 0 &&
  2566. CurrentDescriptor->Errors == E1000_RXD_ERR_CE))) {
  2567. #else
  2568. if ((Length <= (Adapter->LongPacket == TRUE ? MAX_JUMBO_FRAME_SIZE :
  2569. MAXIMUM_ETHERNET_PACKET_SIZE))
  2570. && (Length >= MINIMUM_ETHERNET_PACKET_SIZE)
  2571. && ((CurrentDescriptor->Errors == 0) ||
  2572. (SBP[Adapter->bd_number] > 0 &&
  2573. CurrentDescriptor->Errors == E1000_RXD_ERR_CE))) {
  2574. #endif
  2575. Status = TRUE;
  2576. /* allocate a mesg buff to copy the msg in */
  2577. skb = Adapter->RxSkBuffs[di];
  2578. if (skb == NULL) {
  2579. printk("ProcessReceiveInterrupts found a NULL skb\n");
  2580. break;
  2581. }
  2582. if (e1000_debug_level >= 3)
  2583. printk
  2584. ("ProcRecInts: skb = 0x%p, skb_data = 0x%p, len = 0x%x\n",
  2585. skb, skb->data, skb->len);
  2586. /*
  2587. * Allocate a new receive buffer to replace the receive buffer that
  2588. * is being sent up the stack.
  2589. */
  2590. #ifdef IANS
  2591. new_skb = alloc_skb(Adapter->RxBufferLen + BD_ANS_INFO_SIZE,
  2592. GFP_ATOMIC);
  2593. #else
  2594. new_skb = alloc_skb(Adapter->RxBufferLen + 2, GFP_ATOMIC);
  2595. #endif
  2596. if (new_skb == NULL) {
  2597. /*
  2598. * If the allob_physreq fails, we then try to copy the received
  2599. * packet into a message block that is allocated using the call
  2600. * allocb.
  2601. */
  2602. printk("!Proc_Rec_Ints cannot alloc_skb memory\n");
  2603. return;
  2604. }
  2605. #ifdef IANS
  2606. skb_reserve(new_skb, BD_ANS_INFO_SIZE);
  2607. #else
  2608. skb_reserve(new_skb, 2);
  2609. #endif
  2610. /*
  2611. * Adjust the skb and send the received packet up the stack
  2612. */
  2613. /* adjust the skb internal pointers */
  2614. /* Modifies skb->tail and skb->len */
  2615. skb_put(skb, Length);
  2616. /* CHECKSUM */
  2617. /* set the checksum info */
  2618. skb->ip_summed = CHECKSUM_NONE;
  2619. #ifdef IANS
  2620. if(bdp->iANSdata->iANS_status == IANS_COMMUNICATION_UP) {
  2621. if(bd_ans_os_Receive(bdp, CurrentDescriptor, skb) ==
  2622. BD_ANS_FAILURE) {
  2623. dev_kfree_skb_irq(skb);
  2624. } else {
  2625. /* pass the packet up the stack */
  2626. netif_rx(skb);
  2627. }
  2628. } else {
  2629. /* set the protocol */
  2630. skb->protocol = eth_type_trans(skb, dev);
  2631. /* pass the packet up the stack */
  2632. netif_rx(skb);
  2633. }
  2634. #else
  2635. /* set the protocol */
  2636. skb->protocol = eth_type_trans(skb, dev);
  2637. /* pass the packet up the stack */
  2638. netif_rx(skb);
  2639. if (e1000_debug_level >= 3)
  2640. printk
  2641. ("ProcRecInts: After skb_put, new_skb = 0x%p\n",
  2642. new_skb);
  2643. #endif
  2644. } else {
  2645. printk("e1000: Bad Packet Length\n");
  2646. skb = Adapter->RxSkBuffs[di];
  2647. new_skb = skb; /* Reuse the same old skb */
  2648. if (e1000_debug_level >= 3)
  2649. printk("e1000: re-using same skb\n");
  2650. } /* packet len is good/bad if */
  2651. } /* packet has EOP set - end */
  2652. /* Zero out the receive descriptors status */
  2653. CurrentDescriptor->ReceiveStatus = 0;
  2654. /* set who this is from */
  2655. new_skb->dev = dev;
  2656. Adapter->RxSkBuffs[di] = new_skb;
  2657. if (new_skb == 0){
  2658. CurrentDescriptor->BufferAddress = 0;
  2659. } else {
  2660. e1000_rxfree_cnt++;
  2661. CurrentDescriptor->BufferAddress = virt_to_bus(new_skb->tail);
  2662. }
  2663. /* Advance our pointers to the next descriptor (checking for wrap). */
  2664. if (CurrentDescriptor == Adapter->LastRxDescriptor)
  2665. Adapter->NextRxDescriptorToCheck = Adapter->FirstRxDescriptor;
  2666. else
  2667. Adapter->NextRxDescriptorToCheck++;
  2668. LastDescriptorProcessed = CurrentDescriptor;
  2669. CurrentDescriptor = Adapter->NextRxDescriptorToCheck;
  2670. if (e1000_debug_level >= 3)
  2671. printk("Next RX Desc to check is 0x%p\n", CurrentDescriptor);
  2672. Count++;
  2673. /* Advance the E1000's Receive Queue #0 "Tail Pointer". */
  2674. E1000_WRITE_REG(Rdt0, (((uintptr_t) LastDescriptorProcessed -
  2675. (uintptr_t) Adapter->FirstRxDescriptor) >> 4));
  2676. if (e1000_debug_level >= 3)
  2677. printk("Rx Tail pointer is now 0x%lX\n",
  2678. (((uintptr_t) CurrentDescriptor -
  2679. (uintptr_t) Adapter->FirstRxDescriptor) >> 4));
  2680. } /* while loop for all packets with DD set */
  2681. if (e1000_debug_level >= 3)
  2682. printk("ProcessReceiveInterrupts: done\n");
  2683. return;
  2684. }
  2685. /****************************************************************************
  2686. * Name: e1000_watchdog
  2687. *
  2688. * Description: This routine monitors the board activity. It also updates the
  2689. * statistics that are used by some tools.
  2690. *
  2691. * Author: IntelCorporation
  2692. *
  2693. * Born on Date: 8/2/97
  2694. *
  2695. * Arguments: NONE
  2696. *
  2697. * Returns: NONE
  2698. *
  2699. * Modification log:
  2700. * Date Who Description
  2701. * -------- --- --------------------------------------------------------
  2702. *
  2703. ****************************************************************************/
  2704. static void
  2705. e1000_watchdog(device_t * dev)
  2706. {
  2707. uint16_t LineSpeed, FullDuplex;
  2708. bd_config_t *bdp;
  2709. PADAPTER_STRUCT Adapter;
  2710. bdp = dev->priv;
  2711. Adapter = (PADAPTER_STRUCT) bdp->bddp;
  2712. /*
  2713. * the routines in the watchdog should only be executed if the board pointer
  2714. * is valid, i.e the adapter is actually present.
  2715. */
  2716. if (bdp->flags & BOARD_PRESENT) {
  2717. if(!Adapter->AdapterStopped) {
  2718. CheckForLink(Adapter);
  2719. }
  2720. if(E1000_READ_REG(Status) & E1000_STATUS_LU) {
  2721. GetSpeedAndDuplex(Adapter, &LineSpeed, &FullDuplex);
  2722. Adapter->cur_line_speed = (uint32_t) LineSpeed;
  2723. Adapter->FullDuplex = (uint32_t) FullDuplex;
  2724. #ifdef IANS
  2725. Adapter->ans_link = IANS_STATUS_LINK_OK;
  2726. Adapter->ans_speed = (uint32_t) LineSpeed;
  2727. Adapter->ans_duplex = FullDuplex == FULL_DUPLEX ?
  2728. BD_ANS_DUPLEX_FULL : BD_ANS_DUPLEX_HALF;
  2729. #endif
  2730. if(Adapter->LinkIsActive == FALSE) {
  2731. printk("e1000: %s %ld Mbps %s Link is Up FlowCtl:%02x\n",
  2732. dev->name,
  2733. Adapter->cur_line_speed,
  2734. Adapter->FullDuplex == FULL_DUPLEX ?
  2735. "Full Duplex" : "Half Duplex",
  2736. Adapter->FlowControl);
  2737. Adapter->LinkIsActive = TRUE;
  2738. }
  2739. } else {
  2740. Adapter->cur_line_speed = 0;
  2741. Adapter->FullDuplex = 0;
  2742. #ifdef IANS
  2743. Adapter->ans_link = IANS_STATUS_LINK_FAIL;
  2744. Adapter->ans_speed = 0;
  2745. Adapter->ans_duplex = 0;
  2746. #endif
  2747. if(Adapter->LinkIsActive == TRUE) {
  2748. printk("e1000: %s Link is Down\n", dev->name);
  2749. Adapter->LinkIsActive = FALSE;
  2750. }
  2751. }
  2752. /* Update the statistics needed by the upper */
  2753. UpdateStatsCounters(bdp);
  2754. }
  2755. #ifdef IANS
  2756. if (bdp->iANSdata->reporting_mode == IANS_STATUS_REPORTING_ON) {
  2757. bd_ans_os_Watchdog(dev, bdp);
  2758. }
  2759. #endif
  2760. /* reset the timer to 2 sec */
  2761. mod_timer(&bdp->timer_id, jiffies + (2 * HZ));
  2762. return;
  2763. }
  2764. /* pci.c */
  2765. /*****************************************************************************
  2766. * Name: e1000_find_pci_device
  2767. *
  2768. * Description: This routine finds all PCI adapters that have the given Device
  2769. * ID and Vendor ID. It will store the IRQ, I/O, mem address,
  2770. * node address, and slot information for each adapter in the
  2771. * CardsFound structure. This routine will also enable the bus
  2772. * master bit on any of our adapters (some BIOS don't do this).
  2773. *
  2774. *
  2775. * Author: IntelCorporation
  2776. *
  2777. * Born on Date: 2/1/98
  2778. *
  2779. * Arguments:
  2780. * vendor_id - Vendor ID of our 82557 based adapter.
  2781. * device_id - Device ID of our 82557 based adapter.
  2782. *
  2783. * Returns:
  2784. * B_TRUE - if found pci devices successfully
  2785. * B_FALSE - if no pci devices found
  2786. *
  2787. * Modification log:
  2788. * Date Who Description
  2789. * -------- --- --------------------------------------------------------
  2790. *
  2791. *****************************************************************************/
  2792. static boolean_t
  2793. e1000_find_pci_device(pci_dev_t * pcid, PADAPTER_STRUCT Adapter)
  2794. {
  2795. ulong_t PciTrdyTimeOut = 0;
  2796. ulong_t PciRetryTimeOut = 0;
  2797. int status = 0;
  2798. uint_t PciCommandWord = 0;
  2799. if (e1000_debug_level >= 1)
  2800. printk("e1000_find_pci_device\n");
  2801. if ((((ushort_t) pcid->vendor) == E1000_VENDOR_ID) &&
  2802. ((((ushort_t) pcid->device) == WISEMAN_DEVICE_ID) ||
  2803. (((ushort_t) pcid->device) == LIVENGOOD_FIBER_DEVICE_ID) ||
  2804. (((ushort_t) pcid->device) == LIVENGOOD_COPPER_DEVICE_ID))) {
  2805. if (e1000_debug_level >= 2)
  2806. printk
  2807. ("pcid is ours, vendor = 0x%x, device = 0x%x\n",
  2808. pcid->vendor, pcid->device);
  2809. /* Read the values of the Trdy timeout and
  2810. * also the retry count register
  2811. */
  2812. pci_read_config_byte(pcid,
  2813. PCI_TRDY_TIMEOUT_REGISTER,
  2814. (uchar_t *) & PciTrdyTimeOut);
  2815. pci_read_config_byte(pcid,
  2816. PCI_RETRY_TIMEOUT_REGISTER,
  2817. (uchar_t *) & PciRetryTimeOut);
  2818. pci_read_config_byte(pcid,
  2819. PCI_REVISION_ID,
  2820. (uchar_t *) & (Adapter->RevID));
  2821. pci_read_config_word(pcid, PCI_SUBSYSTEM_ID,
  2822. (ushort_t *) & (Adapter->SubSystemId));
  2823. pci_read_config_word(pcid,
  2824. PCI_SUBSYSTEM_VENDOR_ID,
  2825. (ushort_t *) & (Adapter->SubVendorId));
  2826. pci_read_config_word(pcid,
  2827. PCI_COMMAND,
  2828. (ushort_t *) & (Adapter->PciCommandWord));
  2829. PciCommandWord = Adapter->PciCommandWord;
  2830. Adapter->DeviceNum = pcid->devfn;
  2831. Adapter->VendorId = pcid->vendor;
  2832. Adapter->DeviceId = pcid->device;
  2833. if (e1000_debug_level >= 2) {
  2834. printk("PciTrdyTimeOut = 0x%x\n", (uchar_t) PciTrdyTimeOut);
  2835. printk("PciRetryTimeOut = 0x%x\n", (uchar_t) PciRetryTimeOut);
  2836. printk("RevID = 0x%x\n", (uchar_t) Adapter->RevID);
  2837. printk("SUBSYSTEM_ID = 0x%x\n", Adapter->SubSystemId);
  2838. printk("SUBSYSTEM_VENDOR_ID = 0x%x\n", Adapter->SubVendorId);
  2839. printk("PciCommandWord = 0x%x\n",
  2840. (ushort_t) Adapter->PciCommandWord);
  2841. printk("DeviceNum = 0x%x\n", Adapter->DeviceNum);
  2842. }
  2843. if (e1000_pcimlt_override)
  2844. pci_write_config_byte(pcid,
  2845. PCI_LATENCY_TIMER,
  2846. e1000_pcimlt_override);
  2847. /* code insp #2 */
  2848. if (!(e1000_pcimwi_enable)) {
  2849. if (Adapter->PciCommandWord & CMD_MEM_WRT_INVALIDATE) {
  2850. PciCommandWord =
  2851. Adapter->PciCommandWord & ~CMD_MEM_WRT_INVALIDATE;
  2852. pci_write_config_word(pcid,
  2853. PCI_COMMAND_REGISTER,
  2854. PciCommandWord);
  2855. }
  2856. }
  2857. /* Set the Trdy timeout to zero if it is not
  2858. * already so
  2859. */
  2860. if (PciTrdyTimeOut) {
  2861. PciTrdyTimeOut = 0;
  2862. pci_write_config_byte(pcid,
  2863. PCI_TRDY_TIMEOUT_REGISTER,
  2864. PciTrdyTimeOut);
  2865. pci_read_config_byte(pcid,
  2866. PCI_TRDY_TIMEOUT_REGISTER,
  2867. (uchar_t *) & PciTrdyTimeOut);
  2868. if (PciTrdyTimeOut)
  2869. status = B_FALSE;
  2870. else
  2871. status = B_TRUE;
  2872. } else
  2873. status = B_TRUE;
  2874. /* Set the retry timeout to zero if it is not
  2875. * already so
  2876. */
  2877. if (PciRetryTimeOut) {
  2878. PciRetryTimeOut = 0;
  2879. pci_write_config_byte(pcid,
  2880. PCI_RETRY_TIMEOUT_REGISTER,
  2881. PciRetryTimeOut);
  2882. pci_read_config_byte(pcid,
  2883. PCI_RETRY_TIMEOUT_REGISTER,
  2884. (uchar_t *) & PciRetryTimeOut);
  2885. if (PciRetryTimeOut)
  2886. status = B_FALSE;
  2887. else
  2888. status = B_TRUE;
  2889. } else
  2890. status = B_TRUE;
  2891. }
  2892. if (e1000_debug_level >= 1)
  2893. printk("find_pci: end, status = 0x%x\n", status);
  2894. return (status);
  2895. }
  2896. /****************************************************************************
  2897. * Name: e1000_sw_init
  2898. *
  2899. * Description : This routine initializes all software structures needed by the
  2900. * driver. Allocates the per board structure for storing adapter
  2901. * information. This routine also allocates all the transmit and
  2902. * and receive related data structures for the driver. The memory-
  2903. * mapped PCI BAR address space is also allocated in this routine.
  2904. *
  2905. * Author: IntelCorporation
  2906. *
  2907. * Born on Date: 7/21/97
  2908. *
  2909. * Arguments:
  2910. * bdp - Pointer to the DLPI board structure.
  2911. *
  2912. * Returns:
  2913. * B_TRUE - if successfully initialized
  2914. * B_FALSE - if S/W initialization failed
  2915. *
  2916. * Modification log:
  2917. * Date Who Description
  2918. * -------- --- --------------------------------------------------------
  2919. *
  2920. ****************************************************************************/
  2921. static boolean_t
  2922. e1000_sw_init(bd_config_t * bdp)
  2923. {
  2924. PADAPTER_STRUCT Adapter; /* stores all adapter specific info */
  2925. ulong_t mem_base; /* Memory base address */
  2926. uint_t bd_no;
  2927. int i;
  2928. if (e1000_debug_level >= 1)
  2929. printk("e1000_sw_init: [brd %d] begin\n", bdp->bd_number);
  2930. Adapter = bdp->bddp;
  2931. mem_base = bdp->mem_start;
  2932. bd_no = bdp->bd_number;
  2933. /*
  2934. * The board specific information like the memory base address, the IO base
  2935. * address and the board number are also stored in the Adapter structure
  2936. */
  2937. Adapter->mem_base = mem_base;
  2938. Adapter->bd_number = bd_no;
  2939. if (e1000_debug_level >= 2)
  2940. printk
  2941. ("e1000 - PR0/1000 board located at memory address 0x%lx\n",
  2942. mem_base);
  2943. /* First we have to check our "NumTxDescriptors" and make sure it is
  2944. * a multiple of 8, because the E1000 requires this...
  2945. */
  2946. TxDescriptors[Adapter->bd_number] += (REQ_TX_DESCRIPTOR_MULTIPLE - 1);
  2947. TxDescriptors[Adapter->bd_number] &=
  2948. (~(REQ_TX_DESCRIPTOR_MULTIPLE - 1));
  2949. Adapter->NumTxDescriptors = TxDescriptors[Adapter->bd_number];
  2950. if(!(Adapter->TxSkBuffs =
  2951. (struct sk_buff **) malloc_contig(sizeof(struct sk_buff *) *
  2952. TxDescriptors
  2953. [Adapter->bd_number]))) {
  2954. printk("e1000_sw_init TxSkBuffs alloc failed\n");
  2955. return(0);
  2956. }
  2957. memset(Adapter->TxSkBuffs, 0,
  2958. sizeof(struct sk_buff *) * TxDescriptors[Adapter->bd_number]);
  2959. /*
  2960. * Allocate memory for the transmit buffer descriptors that are shared
  2961. * between the driver and the E1000. The driver uses these descriptors to
  2962. * give packets to the hardware for transmission and the hardware returns
  2963. * status information in this memory area once the packet has been
  2964. * transmitted.
  2965. */
  2966. bdp->base_tx_tbds = (void *) kmalloc(
  2967. (sizeof
  2968. (E1000_TRANSMIT_DESCRIPTOR) *
  2969. TxDescriptors
  2970. [Adapter->bd_number]) + 4096,
  2971. GFP_KERNEL);
  2972. if (bdp->base_tx_tbds == NULL) {
  2973. printk("e1000_sw_init e1000_rbd_data alloc failed\n");
  2974. return 0;
  2975. }
  2976. Adapter->e1000_tbd_data = (PE1000_TRANSMIT_DESCRIPTOR)
  2977. (((unsigned long) bdp->base_tx_tbds + 4096) & ~4096);
  2978. if (e1000_debug_level >= 2)
  2979. printk("tbd_data = 0x%p\n", Adapter->e1000_tbd_data);
  2980. /*
  2981. * Set the first transmit descriptor to the beginning of the allocated
  2982. * memory area and the last descriptor to the end of the memory area
  2983. */
  2984. Adapter->FirstTxDescriptor = Adapter->e1000_tbd_data;
  2985. Adapter->LastTxDescriptor =
  2986. Adapter->FirstTxDescriptor + (Adapter->NumTxDescriptors - 1);
  2987. /* First we have to check our "NumRxDescriptors" and make sure it is
  2988. * a multiple of 8, because the E10001000 requires this...
  2989. */
  2990. RxDescriptors[Adapter->bd_number] += (REQ_RX_DESCRIPTOR_MULTIPLE - 1);
  2991. RxDescriptors[Adapter->bd_number] &=
  2992. (~(REQ_RX_DESCRIPTOR_MULTIPLE - 1));
  2993. Adapter->NumRxDescriptors = RxDescriptors[Adapter->bd_number];
  2994. printk("adapter: %d rx descriptors\n", Adapter->NumRxDescriptors);
  2995. if(!(Adapter->RxSkBuffs =
  2996. (struct sk_buff **) malloc_contig(sizeof(struct sk_buff *) *
  2997. RxDescriptors
  2998. [Adapter->bd_number]))) {
  2999. printk("e1000_sw_init RxSkBuffs alloc failed\n");
  3000. return(0);
  3001. }
  3002. memset(Adapter->RxSkBuffs, 0,
  3003. sizeof(struct sk_buff *) * RxDescriptors[Adapter->bd_number]);
  3004. /*------------------------------------------------------------------------
  3005. * Allocate memory for the receive descriptors (in shared memory), with
  3006. * enough room left over to make sure that we can properly align the
  3007. * structures.
  3008. *----------------------------------------------------------------------
  3009. */
  3010. bdp->base_rx_rbds = (void *) kmalloc(
  3011. (sizeof
  3012. (E1000_RECEIVE_DESCRIPTOR) *
  3013. RxDescriptors
  3014. [Adapter->bd_number]) + 4096,
  3015. GFP_KERNEL);
  3016. if (bdp->base_rx_rbds == 0) {
  3017. printk("e1000_sw_init e1000_rbd_data alloc failed\n");
  3018. return 0;
  3019. }
  3020. Adapter->e1000_rbd_data = (PE1000_RECEIVE_DESCRIPTOR)
  3021. (((unsigned long) bdp->base_rx_rbds + 4096) & ~4096);
  3022. if (e1000_debug_level >= 2)
  3023. printk("rbd_data = 0x%p\n", Adapter->e1000_rbd_data);
  3024. Adapter->FirstRxDescriptor =
  3025. (PE1000_RECEIVE_DESCRIPTOR) Adapter->e1000_rbd_data;
  3026. Adapter->LastRxDescriptor =
  3027. Adapter->FirstRxDescriptor + (Adapter->NumRxDescriptors - 1);
  3028. /*------------------------------------------------------------------------
  3029. * We've allocated receive buffer pointers, and receive descriptors. Now
  3030. * Allocate a buffer for each descriptor, and zero the buffer.
  3031. *----------------------------------------------------------------------
  3032. */
  3033. /*------------------------------------------------------------------------
  3034. * For each receive buffer, the Physical address will be stored
  3035. * in the RX_SW_PACKET's "PhysicalAddress" field, while the
  3036. * virtual address will be stored in the "VirtualAddress" field.
  3037. *-----------------------------------------------------------------------
  3038. */
  3039. /* allocate a physreq structure for specifying receive buffer DMA
  3040. * requirements.
  3041. */
  3042. /*
  3043. * Allocate an initial set of receive sk_buffs.
  3044. */
  3045. for (i = 0; i < Adapter->NumRxDescriptors; i++) {
  3046. struct sk_buff *skb;
  3047. #ifdef IANS
  3048. skb = alloc_skb(Adapter->RxBufferLen + BD_ANS_INFO_SIZE,
  3049. GFP_ATOMIC);
  3050. #else
  3051. skb = alloc_skb(Adapter->RxBufferLen + 2, GFP_ATOMIC);
  3052. #endif
  3053. if (skb == NULL) {
  3054. printk("e1000_sw_init SetupReceiveStructures BIG PROBLEM\n");
  3055. return 0;
  3056. } else {
  3057. /* make the 14 byte mac header align to 16 */
  3058. #ifdef IANS
  3059. skb_reserve(skb, BD_ANS_INFO_SIZE);
  3060. #else
  3061. skb_reserve(skb, 2);
  3062. #endif
  3063. /* set who this is from - JR 9/10/99 */
  3064. skb->dev = bdp->device;
  3065. Adapter->RxSkBuffs[i] = skb;
  3066. }
  3067. }
  3068. /*
  3069. * Set up the multicast table data area
  3070. */
  3071. /*
  3072. Adapter->pmc_buff->MulticastBuffer =
  3073. ((mltcst_cb_t *)&bdp->mc_data)->MulticastBuffer;
  3074. */
  3075. Adapter->pmc_buff = (mltcst_cb_t *) bdp->mc_data;
  3076. if (e1000_debug_level >= 1)
  3077. printk("pmc_buff = 0x%p\n", Adapter->pmc_buff);
  3078. return 1;
  3079. }
  3080. /****************************************************************************
  3081. * Name: e1000_alloc_space
  3082. *
  3083. * Description : This routine allocates paragraph ( 16 bit ) aligned memory for
  3084. * the driver. Memory allocated is for the following structures
  3085. * - BDP ( the main interface struct between dlpi and the driver )
  3086. * - error count structure for adapter statistics
  3087. *
  3088. * For the MP_VERSION of this driver, each sap structure returned
  3089. * by this routine has a pre allocated synchornize var. Ditto for
  3090. * BDP's allocated ( they have a spin lock in them ).
  3091. *
  3092. * Author: IntelCorporation
  3093. *
  3094. * Born on Date: 7/11/97
  3095. *
  3096. * Arguments:
  3097. * None
  3098. *
  3099. * Returns:
  3100. * TRUE - if successfully allocated
  3101. * FALSE - if S/W allocation failed
  3102. *
  3103. * Modification log:
  3104. * Date Who Description
  3105. * -------- --- --------------------------------------------------------
  3106. *
  3107. ****************************************************************************/
  3108. static bd_config_t *
  3109. e1000_alloc_space(void)
  3110. {
  3111. bd_config_t *bdp, *temp_bd;
  3112. PADAPTER_STRUCT Adapter; /* stores all adapter specific info */
  3113. if (e1000_debug_level >= 1)
  3114. printk("e1000_alloc_space: begin\n");
  3115. /* allocate space for the DL_board_t structures */
  3116. bdp = (bd_config_t *) kmalloc(sizeof(bd_config_t), GFP_KERNEL);
  3117. if (bdp == NULL) {
  3118. if (e1000_debug_level >= 2)
  3119. printk("e1000_alloc_space e1000_config alloc failed\n");
  3120. return NULL;
  3121. }
  3122. /* fill the bdp with zero */
  3123. memset(bdp, 0x00, sizeof(*bdp));
  3124. if (e1000_debug_level >= 2)
  3125. printk("bdp = 0x%p\n", bdp);
  3126. /* if first one, save it, else link it into the chain of bdp's */
  3127. if (e1000first == NULL) {
  3128. e1000first = bdp;
  3129. bdp->bd_number = 0;
  3130. bdp->bd_next = NULL;
  3131. bdp->bd_prev = NULL;
  3132. if (e1000_debug_level >= 2)
  3133. printk("First one\n");
  3134. } else {
  3135. /* No, so find last in list and link the new one in */
  3136. temp_bd = e1000first;
  3137. bdp->bd_number = 1; /* it is at least 1 */
  3138. while (temp_bd->bd_next != NULL) {
  3139. temp_bd = (bd_config_t *) temp_bd->bd_next;
  3140. bdp->bd_number++; /* set the board number */
  3141. }
  3142. temp_bd->bd_next = bdp;
  3143. bdp->bd_next = NULL;
  3144. bdp->bd_prev = temp_bd;
  3145. if (e1000_debug_level >= 2)
  3146. printk("Not first one\n");
  3147. }
  3148. /*
  3149. * Allocate the Adapter sturcuture. The Adapter structure contains all the
  3150. * information that is specific to that board instance. It contains pointers
  3151. * to all the transmit and receive data structures for the board, all the
  3152. * PCI related information for the board, and all the statistical counters
  3153. * associated with the board.
  3154. */
  3155. Adapter =
  3156. (PADAPTER_STRUCT) kmalloc(sizeof(ADAPTER_STRUCT), GFP_KERNEL);
  3157. if (Adapter == NULL) {
  3158. if (e1000_debug_level >= 2)
  3159. printk("e1000_sw_init Adapter structure alloc failed\n");
  3160. return (NULL);
  3161. }
  3162. memset(Adapter, 0x00, sizeof(ADAPTER_STRUCT));
  3163. /*
  3164. * The Adapter pointer is made to point to the bddp ( Board dependent
  3165. * pointer) that is referenced off the bdp ( board ) structure.
  3166. */
  3167. bdp->bddp = Adapter;
  3168. if (e1000_debug_level >= 2)
  3169. printk("bdp->bddp = 0x%p\n", bdp->bddp);
  3170. /* allocate space for multi-cast address space */
  3171. if (!
  3172. (bdp->mc_data =
  3173. (pmltcst_cb_t) malloc_contig(sizeof(mltcst_cb_t)))) {
  3174. if (e1000_debug_level >= 2)
  3175. printk("e1000_alloc_space mc_data alloc failed\n");
  3176. return NULL;
  3177. }
  3178. memset(bdp->mc_data, 0x00, sizeof(mltcst_cb_t));
  3179. if (e1000_debug_level >= 2)
  3180. printk("bdp->mc_data = 0x%p\n", bdp->mc_data);
  3181. if (e1000_debug_level >= 1)
  3182. printk("e1000_alloc_space: end\n");
  3183. return (bdp);
  3184. }
  3185. /****************************************************************************
  3186. * Name: e1000_dealloc_space
  3187. *
  3188. * Description : This routine frees all the memory allocated by "alloc_space".
  3189. *
  3190. * Author: IntelCorporation
  3191. *
  3192. * Born on Date: 7/17/97
  3193. *
  3194. * Arguments:
  3195. * None
  3196. *
  3197. * Returns:
  3198. * none
  3199. *
  3200. * Modification log:
  3201. * Date Who Description
  3202. * -------- --- --------------------------------------------------------
  3203. *
  3204. ****************************************************************************/
  3205. static void
  3206. e1000_dealloc_space(bd_config_t * bdp)
  3207. {
  3208. if (e1000_debug_level >= 1)
  3209. printk("e1000_dealloc_space, bdp = 0x%p\n", bdp);
  3210. if (bdp) {
  3211. free_contig(bdp->mc_data);
  3212. bdp->mc_data = NULL;
  3213. free_contig(bdp->bddp);
  3214. bdp->bddp = NULL;
  3215. /* unlink the bdp from the linked list */
  3216. if (bdp == e1000first) {
  3217. e1000first = (bd_config_t *) bdp->bd_next;
  3218. if (bdp->bd_next)
  3219. ((bd_config_t *) bdp->bd_next)->bd_prev = NULL;
  3220. } else {
  3221. if (bdp->bd_next)
  3222. ((bd_config_t *) bdp->bd_next)->bd_prev = bdp->bd_prev;
  3223. if (bdp->bd_prev)
  3224. ((bd_config_t *) bdp->bd_prev)->bd_next = bdp->bd_next;
  3225. }
  3226. }
  3227. free_contig(bdp);
  3228. bdp = NULL;
  3229. return;
  3230. }
  3231. /****************************************************************************
  3232. * Name: malloc_contig
  3233. *
  3234. * Description : This routine allocates a contigious chunk of memory of
  3235. * specified size.
  3236. *
  3237. * Author: IntelCorporation
  3238. *
  3239. * Born on Date: 7/18/97
  3240. *
  3241. * Arguments:
  3242. * size - Size of contigious memory required.
  3243. *
  3244. * Returns:
  3245. * void ptr - if successfully allocated
  3246. * NULL - if allocation failed
  3247. *
  3248. * Modification log:
  3249. * Date Who Description
  3250. * -------- --- --------------------------------------------------------
  3251. *
  3252. ****************************************************************************/
  3253. static void *
  3254. malloc_contig(int size)
  3255. {
  3256. void *mem;
  3257. /* allocate memory */
  3258. mem = kmalloc(size, GFP_KERNEL);
  3259. if (!mem)
  3260. return (NULL);
  3261. return (mem);
  3262. }
  3263. /****************************************************************************
  3264. * Name: free_contig
  3265. *
  3266. * Description : This routine frees up space previously allocated by
  3267. * malloc_contig.
  3268. *
  3269. * Author: IntelCorporation
  3270. *
  3271. * Born on Date: 1/18/98
  3272. *
  3273. * Arguments:
  3274. * ptr - Pointer to the memory to free.
  3275. * size - Size of memory to free.
  3276. *
  3277. * Returns:
  3278. * TRUE - if successfully initialized
  3279. * FALSE - if S/W initialization failed
  3280. *
  3281. * Modification log:
  3282. * Date Who Description
  3283. * -------- --- --------------------------------------------------------
  3284. *
  3285. ****************************************************************************/
  3286. static void
  3287. free_contig(void *ptr)
  3288. {
  3289. if (ptr)
  3290. kfree(ptr);
  3291. ptr = NULL;
  3292. }
  3293. static int
  3294. e1000_GetBrandingMesg(uint16_t dev, uint16_t sub_ven, uint16_t sub_dev)
  3295. {
  3296. char *mesg = NULL;
  3297. int i = 0;
  3298. /* Go through the list of all valid subsystem IDs */
  3299. while (e1000_vendor_info_array[i].idstr != NULL) {
  3300. /* Look for exact match on sub_dev and sub_ven */
  3301. if ((e1000_vendor_info_array[i].dev == dev) &&
  3302. (e1000_vendor_info_array[i].sub_ven == sub_ven) &&
  3303. (e1000_vendor_info_array[i].sub_dev == sub_dev)) {
  3304. mesg = e1000_vendor_info_array[i].idstr;
  3305. break;
  3306. } else if ((e1000_vendor_info_array[i].dev == dev) &&
  3307. (e1000_vendor_info_array[i].sub_ven == sub_ven) &&
  3308. (e1000_vendor_info_array[i].sub_dev == CATCHALL)) {
  3309. mesg = e1000_vendor_info_array[i].idstr;
  3310. } else if ((e1000_vendor_info_array[i].dev == dev) &&
  3311. (e1000_vendor_info_array[i].sub_ven == CATCHALL) &&
  3312. (mesg == NULL)) {
  3313. mesg = e1000_vendor_info_array[i].idstr;
  3314. }
  3315. i++;
  3316. }
  3317. if (mesg != NULL) {
  3318. strcpy(e1000id_string, mesg);
  3319. return 1;
  3320. } else
  3321. return 0;
  3322. }
  3323. /* fxhw.c */
  3324. static boolean_t
  3325. DetectKnownChipset(PADAPTER_STRUCT Adapter)
  3326. {
  3327. pci_dev_t *pcid;
  3328. ulong_t DataPort;
  3329. uchar_t SaveConfig;
  3330. uchar_t TestConfig;
  3331. SaveConfig = inb(CF2_SPACE_ENABLE_REGISTER);
  3332. outb((uchar_t) CF2_SPACE_ENABLE_REGISTER, 0x0E);
  3333. TestConfig = inb(CF2_SPACE_ENABLE_REGISTER);
  3334. if (TestConfig == 0x0E) {
  3335. outb((uchar_t) CF2_SPACE_ENABLE_REGISTER, SaveConfig);
  3336. return FALSE;
  3337. }
  3338. if (
  3339. (pcid =
  3340. pci_find_device(PCI_VENDOR_ID_INTEL, INTEL_440BX_AGP, NULL))
  3341. || (pcid = pci_find_device(PCI_VENDOR_ID_INTEL, INTEL_440BX, NULL))
  3342. || (pcid = pci_find_device(PCI_VENDOR_ID_INTEL, INTEL_440GX, NULL))
  3343. || (pcid = pci_find_device(PCI_VENDOR_ID_INTEL, INTEL_440FX, NULL))
  3344. || (pcid =
  3345. pci_find_device(PCI_VENDOR_ID_INTEL, INTEL_430TX, NULL))) {
  3346. outb((uchar_t) CF2_SPACE_ENABLE_REGISTER, SaveConfig);
  3347. if (e1000_debug_level >= 3)
  3348. printk
  3349. ("Found a known member of the 430 or 440 chipset family");
  3350. return TRUE;
  3351. }
  3352. if (
  3353. (pcid =
  3354. pci_find_device(PCI_VENDOR_ID_INTEL, INTEL_450NX_PXB, NULL))) {
  3355. pci_read_config_byte(pcid, PCI_REV_ID_REGISTER, (u8 *) & DataPort);
  3356. if (e1000_debug_level >= 3)
  3357. printk
  3358. ("Found a 450NX chipset with PXB rev ID 0x%x\n",
  3359. (uchar_t) DataPort);
  3360. outb((uchar_t) CF2_SPACE_ENABLE_REGISTER, SaveConfig);
  3361. if (((uchar_t) DataPort) >= PXB_C0_REV_ID) {
  3362. if (e1000_debug_level >= 3)
  3363. printk("Found a 450NX chipset with C0 or later PXB");
  3364. return FALSE;
  3365. } else {
  3366. if (e1000_debug_level >= 3)
  3367. printk("Found a 450NX chipset with B1 or earlier PXB");
  3368. return TRUE;
  3369. }
  3370. }
  3371. if (
  3372. (pcid =
  3373. pci_find_device(PCI_VENDOR_ID_INTEL, INTEL_450KX_GX_PB, NULL))) {
  3374. outb((uchar_t) CF2_SPACE_ENABLE_REGISTER, SaveConfig);
  3375. if (e1000_debug_level >= 3)
  3376. printk("Found a 450KX or 450GX chipset");
  3377. return TRUE;
  3378. }
  3379. outb((uchar_t) CF2_SPACE_ENABLE_REGISTER, SaveConfig);
  3380. if (e1000_debug_level >= 3)
  3381. printk("Did not find a known chipset");
  3382. return FALSE;
  3383. }
  3384. static int
  3385. e1000_poll_on(struct device *dev)
  3386. {
  3387. unsigned long flags;
  3388. bd_config_t *bdp = dev->priv;
  3389. PADAPTER_STRUCT Adapter = (PADAPTER_STRUCT) bdp->bddp;
  3390. #ifdef CLICK_POLLING
  3391. if (!dev->polling) {
  3392. printk("e1000_poll_on\n");
  3393. save_flags(flags);
  3394. cli();
  3395. dev->polling = 2;
  3396. e1000DisableInterrupt(Adapter);
  3397. restore_flags(flags);
  3398. Adapter->NextRxIndexToFill =
  3399. Adapter->NextRxDescriptorToCheck - Adapter->FirstRxDescriptor;
  3400. }
  3401. #endif
  3402. return 0;
  3403. }
  3404. static int
  3405. e1000_poll_off(struct device *dev)
  3406. {
  3407. bd_config_t *bdp = dev->priv;
  3408. PADAPTER_STRUCT Adapter = (PADAPTER_STRUCT) bdp->bddp;
  3409. #ifdef CLICK_POLLING
  3410. if(dev->polling > 0){
  3411. dev->polling = 0;
  3412. e1000EnableInterrupt(Adapter);
  3413. printk("e1000_poll_off\n");
  3414. }
  3415. #endif
  3416. return 0;
  3417. }
  3418. static struct sk_buff *
  3419. e1000_rx_poll(struct device *dev, int *want)
  3420. {
  3421. bd_config_t *bdp = dev->priv;
  3422. PADAPTER_STRUCT Adapter = (PADAPTER_STRUCT) bdp->bddp;
  3423. int got = 0, di;
  3424. struct sk_buff *skb_head = 0, *skb_last = 0;
  3425. PE1000_RECEIVE_DESCRIPTOR CurrentDescriptor;
  3426. PE1000_RECEIVE_DESCRIPTOR LastDescriptorProcessed;
  3427. sk_buff_t *skb, *new_skb;
  3428. USHORT Length;
  3429. while(got < *want){
  3430. CurrentDescriptor = Adapter->NextRxDescriptorToCheck;
  3431. di = CurrentDescriptor - Adapter->FirstRxDescriptor;
  3432. skb = Adapter->RxSkBuffs[di];
  3433. #if 1
  3434. {
  3435. PE1000_RECEIVE_DESCRIPTOR PrefetchDescriptor;
  3436. sk_buff_t *next_skb;
  3437. if (CurrentDescriptor == Adapter->LastRxDescriptor)
  3438. PrefetchDescriptor = Adapter->FirstRxDescriptor;
  3439. else
  3440. PrefetchDescriptor = Adapter->NextRxDescriptorToCheck+1;
  3441. next_skb =
  3442. Adapter->RxSkBuffs[PrefetchDescriptor-Adapter->FirstRxDescriptor];
  3443. /* this does not seem to matter much */
  3444. #if __i386__ && HAVE_INTEL_CPU
  3445. asm volatile("prefetcht0 %0" :: "m" (PrefetchDescriptor->ReceiveStatus));
  3446. #endif
  3447. }
  3448. #endif
  3449. if(skb == 0)
  3450. break;
  3451. if((CurrentDescriptor->ReceiveStatus & E1000_RXD_STAT_DD) == 0)
  3452. break;
  3453. if (!(CurrentDescriptor->ReceiveStatus & E1000_RXD_STAT_EOP)) {
  3454. printk("Receive packet consumed mult buffers\n");
  3455. if(skb)
  3456. dev_kfree_skb(skb);
  3457. } else {
  3458. Length = CurrentDescriptor->Length - CRC_LENGTH;
  3459. if ((Length <= (Adapter->LongPacket == TRUE ? MAX_JUMBO_FRAME_SIZE :
  3460. MAXIMUM_ETHERNET_PACKET_SIZE))
  3461. && (Length >= MINIMUM_ETHERNET_PACKET_SIZE)
  3462. && ((CurrentDescriptor->Errors == 0) ||
  3463. (SBP[Adapter->bd_number] > 0 &&
  3464. CurrentDescriptor->Errors == E1000_RXD_ERR_CE))) {
  3465. /* this is cheating: instead of calling skb_put,
  3466. * we just assume we get the right size */
  3467. /* skb_put(skb, Length); */
  3468. {
  3469. unsigned char *tmp = skb->tail;
  3470. skb->tail += Length;
  3471. skb->len += Length;
  3472. }
  3473. skb->ip_summed = CHECKSUM_NONE;
  3474. skb->protocol = eth_type_trans(skb, dev);
  3475. if (got == 0) {
  3476. skb_head = skb;
  3477. skb_last = skb;
  3478. skb_last->next = NULL;
  3479. } else {
  3480. skb_last->next = skb;
  3481. skb->next = NULL;
  3482. skb_last = skb;
  3483. }
  3484. got++;
  3485. } else {
  3486. printk("e1000: Bad Packet Length\n");
  3487. }
  3488. }
  3489. Adapter->RxSkBuffs[di] = 0;
  3490. if (CurrentDescriptor == Adapter->LastRxDescriptor)
  3491. Adapter->NextRxDescriptorToCheck = Adapter->FirstRxDescriptor;
  3492. else
  3493. Adapter->NextRxDescriptorToCheck++;
  3494. LastDescriptorProcessed = CurrentDescriptor;
  3495. CurrentDescriptor = Adapter->NextRxDescriptorToCheck;
  3496. }
  3497. out:
  3498. *want = got;
  3499. return skb_head;
  3500. }
  3501. static int
  3502. e1000_tx_queue(struct device *dev, struct sk_buff *skb)
  3503. {
  3504. int ret;
  3505. #ifdef CLICK_POLLING
  3506. ret = e1000_xmit_frame_aux(skb, dev, dev->polling == 0);
  3507. #else
  3508. ret = e1000_xmit_frame_aux(skb, dev, 1);
  3509. #endif
  3510. return(ret);
  3511. }
  3512. static int
  3513. e1000_tx_start(struct device *dev)
  3514. {
  3515. e1000_tx_eob(dev);
  3516. return 0;
  3517. }
  3518. int
  3519. e1000_rx_refill(struct device *dev, struct sk_buff **skbs)
  3520. {
  3521. bd_config_t *bdp = dev->priv;
  3522. PADAPTER_STRUCT Adapter = (PADAPTER_STRUCT) bdp->bddp;
  3523. int nfilled = 0, di, rtn;
  3524. PE1000_RECEIVE_DESCRIPTOR dp = 0;
  3525. struct sk_buff *skb_list;
  3526. // rtm check
  3527. if (skbs == 0)
  3528. return (Adapter->NextRxDescriptorToCheck >=
  3529. (Adapter->FirstRxDescriptor+Adapter->NextRxIndexToFill))
  3530. ? (Adapter->NextRxDescriptorToCheck -
  3531. (Adapter->FirstRxDescriptor+Adapter->NextRxIndexToFill))
  3532. : ((Adapter->NextRxDescriptorToCheck+Adapter->NumRxDescriptors) -
  3533. (Adapter->FirstRxDescriptor+Adapter->NextRxIndexToFill));
  3534. skb_list = *skbs;
  3535. di = Adapter->NextRxIndexToFill;
  3536. while(Adapter->RxSkBuffs[di] == 0 && skb_list != 0L){
  3537. struct sk_buff *skb = skb_list;
  3538. skb_list = skb_list->next;
  3539. // do not use skb_reserve because click expects
  3540. // packets w/ (4,0) alignment: some net cards, like
  3541. // tulip, cannot transfer data on non-4 byte
  3542. // alignment
  3543. // skb_reserve(skb, 2);
  3544. skb->dev = dev;
  3545. Adapter->RxSkBuffs[di] = skb;
  3546. dp = Adapter->FirstRxDescriptor + di;
  3547. dp->BufferAddress = virt_to_bus(skb->tail);
  3548. dp->ReceiveStatus = 0;
  3549. nfilled++;
  3550. di++;
  3551. if(di >= Adapter->NumRxDescriptors)
  3552. di = 0;
  3553. }
  3554. if (skb_list == 0)
  3555. *skbs = 0;
  3556. else
  3557. *skbs = skb_list;
  3558. Adapter->NextRxIndexToFill = di;
  3559. if(nfilled){
  3560. /* Advance the E1000's Receive Queue #0 "Tail Pointer". */
  3561. E1000_WRITE_REG(Rdt0, (((uintptr_t) dp -
  3562. (uintptr_t) Adapter->FirstRxDescriptor) >> 4));
  3563. }
  3564. // rtm check
  3565. return (Adapter->NextRxDescriptorToCheck >=
  3566. (Adapter->FirstRxDescriptor+Adapter->NextRxIndexToFill))
  3567. ? (Adapter->NextRxDescriptorToCheck -
  3568. (Adapter->FirstRxDescriptor+Adapter->NextRxIndexToFill))
  3569. : ((Adapter->NextRxDescriptorToCheck+Adapter->NumRxDescriptors) -
  3570. (Adapter->FirstRxDescriptor+Adapter->NextRxIndexToFill));
  3571. }
  3572. static struct sk_buff *
  3573. e1000_tx_clean(struct device *dev)
  3574. {
  3575. bd_config_t *bdp = dev->priv;
  3576. return ProcessTransmitInterrupts(bdp, 0);
  3577. }
  3578. static int
  3579. e1000_tx_eob(struct device *dev)
  3580. {
  3581. PADAPTER_STRUCT Adapter;
  3582. bd_config_t *bdp;
  3583. bdp = dev->priv;
  3584. Adapter = bdp->bddp;
  3585. /* Advance the Transmit Descriptor Tail (Tdt), this tells the
  3586. * E1000 that this frame is available to transmit.
  3587. */
  3588. E1000_WRITE_REG(Tdt, (((unsigned long) Adapter->NextAvailTxDescriptor -
  3589. (unsigned long) Adapter->FirstTxDescriptor) >> 4));
  3590. return 0;
  3591. }
  3592. #ifdef MODULE
  3593. /* ENTRY POINTS */
  3594. EXPORT_SYMBOL(e1000_open);
  3595. EXPORT_SYMBOL(e1000_close);
  3596. EXPORT_SYMBOL(e1000_xmit_frame);
  3597. EXPORT_SYMBOL(e1000_probe);
  3598. EXPORT_SYMBOL(e1000_change_mtu);
  3599. EXPORT_SYMBOL(e1000_intr);
  3600. /* DEBUG */
  3601. #endif