PageRenderTime 65ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/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

Large files files are truncated, but you can click here to view the full file

  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. ************************************…

Large files files are truncated, but you can click here to view the full file