atl1_hw.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. /*
  2. * Copyright(c) 2005 - 2006 Attansic Corporation. All rights reserved.
  3. * Copyright(c) 2006 Chris Snook <csnook@redhat.com>
  4. * Copyright(c) 2006 Jay Cliburn <jcliburn@gmail.com>
  5. *
  6. * Derived from Intel e1000 driver
  7. * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the Free
  11. * Software Foundation; either version 2 of the License, or (at your option)
  12. * any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  17. * more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along with
  20. * this program; if not, write to the Free Software Foundation, Inc., 59
  21. * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. */
  23. #include <linux/types.h>
  24. #include <linux/pci.h>
  25. #include <linux/delay.h>
  26. #include <linux/if_vlan.h>
  27. #include <linux/etherdevice.h>
  28. #include <linux/crc32.h>
  29. #include <asm/byteorder.h>
  30. #include "atl1.h"
  31. /*
  32. * Reset the transmit and receive units; mask and clear all interrupts.
  33. * hw - Struct containing variables accessed by shared code
  34. * return : ATL1_SUCCESS or idle status (if error)
  35. */
  36. s32 atl1_reset_hw(struct atl1_hw *hw)
  37. {
  38. struct pci_dev *pdev = hw->back->pdev;
  39. u32 icr;
  40. int i;
  41. /*
  42. * Clear Interrupt mask to stop board from generating
  43. * interrupts & Clear any pending interrupt events
  44. */
  45. /*
  46. * iowrite32(0, hw->hw_addr + REG_IMR);
  47. * iowrite32(0xffffffff, hw->hw_addr + REG_ISR);
  48. */
  49. /*
  50. * Issue Soft Reset to the MAC. This will reset the chip's
  51. * transmit, receive, DMA. It will not effect
  52. * the current PCI configuration. The global reset bit is self-
  53. * clearing, and should clear within a microsecond.
  54. */
  55. iowrite32(MASTER_CTRL_SOFT_RST, hw->hw_addr + REG_MASTER_CTRL);
  56. ioread32(hw->hw_addr + REG_MASTER_CTRL);
  57. iowrite16(1, hw->hw_addr + REG_GPHY_ENABLE);
  58. ioread16(hw->hw_addr + REG_GPHY_ENABLE);
  59. msleep(1); /* delay about 1ms */
  60. /* Wait at least 10ms for All module to be Idle */
  61. for (i = 0; i < 10; i++) {
  62. icr = ioread32(hw->hw_addr + REG_IDLE_STATUS);
  63. if (!icr)
  64. break;
  65. msleep(1); /* delay 1 ms */
  66. cpu_relax(); /* FIXME: is this still the right way to do this? */
  67. }
  68. if (icr) {
  69. dev_dbg(&pdev->dev, "ICR = 0x%x\n", icr);
  70. return icr;
  71. }
  72. return ATL1_SUCCESS;
  73. }
  74. /* function about EEPROM
  75. *
  76. * check_eeprom_exist
  77. * return 0 if eeprom exist
  78. */
  79. static int atl1_check_eeprom_exist(struct atl1_hw *hw)
  80. {
  81. u32 value;
  82. value = ioread32(hw->hw_addr + REG_SPI_FLASH_CTRL);
  83. if (value & SPI_FLASH_CTRL_EN_VPD) {
  84. value &= ~SPI_FLASH_CTRL_EN_VPD;
  85. iowrite32(value, hw->hw_addr + REG_SPI_FLASH_CTRL);
  86. }
  87. value = ioread16(hw->hw_addr + REG_PCIE_CAP_LIST);
  88. return ((value & 0xFF00) == 0x6C00) ? 0 : 1;
  89. }
  90. static bool atl1_read_eeprom(struct atl1_hw *hw, u32 offset, u32 *p_value)
  91. {
  92. int i;
  93. u32 control;
  94. if (offset & 3)
  95. return false; /* address do not align */
  96. iowrite32(0, hw->hw_addr + REG_VPD_DATA);
  97. control = (offset & VPD_CAP_VPD_ADDR_MASK) << VPD_CAP_VPD_ADDR_SHIFT;
  98. iowrite32(control, hw->hw_addr + REG_VPD_CAP);
  99. ioread32(hw->hw_addr + REG_VPD_CAP);
  100. for (i = 0; i < 10; i++) {
  101. msleep(2);
  102. control = ioread32(hw->hw_addr + REG_VPD_CAP);
  103. if (control & VPD_CAP_VPD_FLAG)
  104. break;
  105. }
  106. if (control & VPD_CAP_VPD_FLAG) {
  107. *p_value = ioread32(hw->hw_addr + REG_VPD_DATA);
  108. return true;
  109. }
  110. return false; /* timeout */
  111. }
  112. /*
  113. * Reads the value from a PHY register
  114. * hw - Struct containing variables accessed by shared code
  115. * reg_addr - address of the PHY register to read
  116. */
  117. s32 atl1_read_phy_reg(struct atl1_hw *hw, u16 reg_addr, u16 *phy_data)
  118. {
  119. u32 val;
  120. int i;
  121. val = ((u32) (reg_addr & MDIO_REG_ADDR_MASK)) << MDIO_REG_ADDR_SHIFT |
  122. MDIO_START | MDIO_SUP_PREAMBLE | MDIO_RW | MDIO_CLK_25_4 <<
  123. MDIO_CLK_SEL_SHIFT;
  124. iowrite32(val, hw->hw_addr + REG_MDIO_CTRL);
  125. ioread32(hw->hw_addr + REG_MDIO_CTRL);
  126. for (i = 0; i < MDIO_WAIT_TIMES; i++) {
  127. udelay(2);
  128. val = ioread32(hw->hw_addr + REG_MDIO_CTRL);
  129. if (!(val & (MDIO_START | MDIO_BUSY)))
  130. break;
  131. }
  132. if (!(val & (MDIO_START | MDIO_BUSY))) {
  133. *phy_data = (u16) val;
  134. return ATL1_SUCCESS;
  135. }
  136. return ATL1_ERR_PHY;
  137. }
  138. #define CUSTOM_SPI_CS_SETUP 2
  139. #define CUSTOM_SPI_CLK_HI 2
  140. #define CUSTOM_SPI_CLK_LO 2
  141. #define CUSTOM_SPI_CS_HOLD 2
  142. #define CUSTOM_SPI_CS_HI 3
  143. static bool atl1_spi_read(struct atl1_hw *hw, u32 addr, u32 *buf)
  144. {
  145. int i;
  146. u32 value;
  147. iowrite32(0, hw->hw_addr + REG_SPI_DATA);
  148. iowrite32(addr, hw->hw_addr + REG_SPI_ADDR);
  149. value = SPI_FLASH_CTRL_WAIT_READY |
  150. (CUSTOM_SPI_CS_SETUP & SPI_FLASH_CTRL_CS_SETUP_MASK) <<
  151. SPI_FLASH_CTRL_CS_SETUP_SHIFT | (CUSTOM_SPI_CLK_HI &
  152. SPI_FLASH_CTRL_CLK_HI_MASK) <<
  153. SPI_FLASH_CTRL_CLK_HI_SHIFT | (CUSTOM_SPI_CLK_LO &
  154. SPI_FLASH_CTRL_CLK_LO_MASK) <<
  155. SPI_FLASH_CTRL_CLK_LO_SHIFT | (CUSTOM_SPI_CS_HOLD &
  156. SPI_FLASH_CTRL_CS_HOLD_MASK) <<
  157. SPI_FLASH_CTRL_CS_HOLD_SHIFT | (CUSTOM_SPI_CS_HI &
  158. SPI_FLASH_CTRL_CS_HI_MASK) <<
  159. SPI_FLASH_CTRL_CS_HI_SHIFT | (1 & SPI_FLASH_CTRL_INS_MASK) <<
  160. SPI_FLASH_CTRL_INS_SHIFT;
  161. iowrite32(value, hw->hw_addr + REG_SPI_FLASH_CTRL);
  162. value |= SPI_FLASH_CTRL_START;
  163. iowrite32(value, hw->hw_addr + REG_SPI_FLASH_CTRL);
  164. ioread32(hw->hw_addr + REG_SPI_FLASH_CTRL);
  165. for (i = 0; i < 10; i++) {
  166. msleep(1); /* 1ms */
  167. value = ioread32(hw->hw_addr + REG_SPI_FLASH_CTRL);
  168. if (!(value & SPI_FLASH_CTRL_START))
  169. break;
  170. }
  171. if (value & SPI_FLASH_CTRL_START)
  172. return false;
  173. *buf = ioread32(hw->hw_addr + REG_SPI_DATA);
  174. return true;
  175. }
  176. /*
  177. * get_permanent_address
  178. * return 0 if get valid mac address,
  179. */
  180. static int atl1_get_permanent_address(struct atl1_hw *hw)
  181. {
  182. u32 addr[2];
  183. u32 i, control;
  184. u16 reg;
  185. u8 eth_addr[ETH_ALEN];
  186. bool key_valid;
  187. if (is_valid_ether_addr(hw->perm_mac_addr))
  188. return 0;
  189. /* init */
  190. addr[0] = addr[1] = 0;
  191. if (!atl1_check_eeprom_exist(hw)) { /* eeprom exist */
  192. reg = 0;
  193. key_valid = false;
  194. /* Read out all EEPROM content */
  195. i = 0;
  196. while (1) {
  197. if (atl1_read_eeprom(hw, i + 0x100, &control)) {
  198. if (key_valid) {
  199. if (reg == REG_MAC_STA_ADDR)
  200. addr[0] = control;
  201. else if (reg == (REG_MAC_STA_ADDR + 4))
  202. addr[1] = control;
  203. key_valid = false;
  204. } else if ((control & 0xff) == 0x5A) {
  205. key_valid = true;
  206. reg = (u16) (control >> 16);
  207. } else
  208. break; /* assume data end while encount an invalid KEYWORD */
  209. } else
  210. break; /* read error */
  211. i += 4;
  212. }
  213. *(u32 *) &eth_addr[2] = swab32(addr[0]);
  214. *(u16 *) &eth_addr[0] = swab16(*(u16 *) &addr[1]);
  215. if (is_valid_ether_addr(eth_addr)) {
  216. memcpy(hw->perm_mac_addr, eth_addr, ETH_ALEN);
  217. return 0;
  218. }
  219. return 1;
  220. }
  221. /* see if SPI FLAGS exist ? */
  222. addr[0] = addr[1] = 0;
  223. reg = 0;
  224. key_valid = false;
  225. i = 0;
  226. while (1) {
  227. if (atl1_spi_read(hw, i + 0x1f000, &control)) {
  228. if (key_valid) {
  229. if (reg == REG_MAC_STA_ADDR)
  230. addr[0] = control;
  231. else if (reg == (REG_MAC_STA_ADDR + 4))
  232. addr[1] = control;
  233. key_valid = false;
  234. } else if ((control & 0xff) == 0x5A) {
  235. key_valid = true;
  236. reg = (u16) (control >> 16);
  237. } else
  238. break; /* data end */
  239. } else
  240. break; /* read error */
  241. i += 4;
  242. }
  243. *(u32 *) &eth_addr[2] = swab32(addr[0]);
  244. *(u16 *) &eth_addr[0] = swab16(*(u16 *) &addr[1]);
  245. if (is_valid_ether_addr(eth_addr)) {
  246. memcpy(hw->perm_mac_addr, eth_addr, ETH_ALEN);
  247. return 0;
  248. }
  249. /*
  250. * On some motherboards, the MAC address is written by the
  251. * BIOS directly to the MAC register during POST, and is
  252. * not stored in eeprom. If all else thus far has failed
  253. * to fetch the permanent MAC address, try reading it directly.
  254. */
  255. addr[0] = ioread32(hw->hw_addr + REG_MAC_STA_ADDR);
  256. addr[1] = ioread16(hw->hw_addr + (REG_MAC_STA_ADDR + 4));
  257. *(u32 *) &eth_addr[2] = swab32(addr[0]);
  258. *(u16 *) &eth_addr[0] = swab16(*(u16 *) &addr[1]);
  259. if (is_valid_ether_addr(eth_addr)) {
  260. memcpy(hw->perm_mac_addr, eth_addr, ETH_ALEN);
  261. return 0;
  262. }
  263. return 1;
  264. }
  265. /*
  266. * Reads the adapter's MAC address from the EEPROM
  267. * hw - Struct containing variables accessed by shared code
  268. */
  269. s32 atl1_read_mac_addr(struct atl1_hw *hw)
  270. {
  271. u16 i;
  272. if (atl1_get_permanent_address(hw))
  273. random_ether_addr(hw->perm_mac_addr);
  274. for (i = 0; i < ETH_ALEN; i++)
  275. hw->mac_addr[i] = hw->perm_mac_addr[i];
  276. return ATL1_SUCCESS;
  277. }
  278. /*
  279. * Hashes an address to determine its location in the multicast table
  280. * hw - Struct containing variables accessed by shared code
  281. * mc_addr - the multicast address to hash
  282. *
  283. * atl1_hash_mc_addr
  284. * purpose
  285. * set hash value for a multicast address
  286. * hash calcu processing :
  287. * 1. calcu 32bit CRC for multicast address
  288. * 2. reverse crc with MSB to LSB
  289. */
  290. u32 atl1_hash_mc_addr(struct atl1_hw *hw, u8 *mc_addr)
  291. {
  292. u32 crc32, value = 0;
  293. int i;
  294. crc32 = ether_crc_le(6, mc_addr);
  295. for (i = 0; i < 32; i++)
  296. value |= (((crc32 >> i) & 1) << (31 - i));
  297. return value;
  298. }
  299. /*
  300. * Sets the bit in the multicast table corresponding to the hash value.
  301. * hw - Struct containing variables accessed by shared code
  302. * hash_value - Multicast address hash value
  303. */
  304. void atl1_hash_set(struct atl1_hw *hw, u32 hash_value)
  305. {
  306. u32 hash_bit, hash_reg;
  307. u32 mta;
  308. /*
  309. * The HASH Table is a register array of 2 32-bit registers.
  310. * It is treated like an array of 64 bits. We want to set
  311. * bit BitArray[hash_value]. So we figure out what register
  312. * the bit is in, read it, OR in the new bit, then write
  313. * back the new value. The register is determined by the
  314. * upper 7 bits of the hash value and the bit within that
  315. * register are determined by the lower 5 bits of the value.
  316. */
  317. hash_reg = (hash_value >> 31) & 0x1;
  318. hash_bit = (hash_value >> 26) & 0x1F;
  319. mta = ioread32((hw->hw_addr + REG_RX_HASH_TABLE) + (hash_reg << 2));
  320. mta |= (1 << hash_bit);
  321. iowrite32(mta, (hw->hw_addr + REG_RX_HASH_TABLE) + (hash_reg << 2));
  322. }
  323. /*
  324. * Writes a value to a PHY register
  325. * hw - Struct containing variables accessed by shared code
  326. * reg_addr - address of the PHY register to write
  327. * data - data to write to the PHY
  328. */
  329. s32 atl1_write_phy_reg(struct atl1_hw *hw, u32 reg_addr, u16 phy_data)
  330. {
  331. int i;
  332. u32 val;
  333. val = ((u32) (phy_data & MDIO_DATA_MASK)) << MDIO_DATA_SHIFT |
  334. (reg_addr & MDIO_REG_ADDR_MASK) << MDIO_REG_ADDR_SHIFT |
  335. MDIO_SUP_PREAMBLE |
  336. MDIO_START | MDIO_CLK_25_4 << MDIO_CLK_SEL_SHIFT;
  337. iowrite32(val, hw->hw_addr + REG_MDIO_CTRL);
  338. ioread32(hw->hw_addr + REG_MDIO_CTRL);
  339. for (i = 0; i < MDIO_WAIT_TIMES; i++) {
  340. udelay(2);
  341. val = ioread32(hw->hw_addr + REG_MDIO_CTRL);
  342. if (!(val & (MDIO_START | MDIO_BUSY)))
  343. break;
  344. }
  345. if (!(val & (MDIO_START | MDIO_BUSY)))
  346. return ATL1_SUCCESS;
  347. return ATL1_ERR_PHY;
  348. }
  349. /*
  350. * Make L001's PHY out of Power Saving State (bug)
  351. * hw - Struct containing variables accessed by shared code
  352. * when power on, L001's PHY always on Power saving State
  353. * (Gigabit Link forbidden)
  354. */
  355. static s32 atl1_phy_leave_power_saving(struct atl1_hw *hw)
  356. {
  357. s32 ret;
  358. ret = atl1_write_phy_reg(hw, 29, 0x0029);
  359. if (ret)
  360. return ret;
  361. return atl1_write_phy_reg(hw, 30, 0);
  362. }
  363. /*
  364. *TODO: do something or get rid of this
  365. */
  366. s32 atl1_phy_enter_power_saving(struct atl1_hw *hw)
  367. {
  368. /* s32 ret_val;
  369. * u16 phy_data;
  370. */
  371. /*
  372. ret_val = atl1_write_phy_reg(hw, ...);
  373. ret_val = atl1_write_phy_reg(hw, ...);
  374. ....
  375. */
  376. return ATL1_SUCCESS;
  377. }
  378. /*
  379. * Resets the PHY and make all config validate
  380. * hw - Struct containing variables accessed by shared code
  381. *
  382. * Sets bit 15 and 12 of the MII Control regiser (for F001 bug)
  383. */
  384. static s32 atl1_phy_reset(struct atl1_hw *hw)
  385. {
  386. struct pci_dev *pdev = hw->back->pdev;
  387. s32 ret_val;
  388. u16 phy_data;
  389. if (hw->media_type == MEDIA_TYPE_AUTO_SENSOR ||
  390. hw->media_type == MEDIA_TYPE_1000M_FULL)
  391. phy_data = MII_CR_RESET | MII_CR_AUTO_NEG_EN;
  392. else {
  393. switch (hw->media_type) {
  394. case MEDIA_TYPE_100M_FULL:
  395. phy_data =
  396. MII_CR_FULL_DUPLEX | MII_CR_SPEED_100 |
  397. MII_CR_RESET;
  398. break;
  399. case MEDIA_TYPE_100M_HALF:
  400. phy_data = MII_CR_SPEED_100 | MII_CR_RESET;
  401. break;
  402. case MEDIA_TYPE_10M_FULL:
  403. phy_data =
  404. MII_CR_FULL_DUPLEX | MII_CR_SPEED_10 | MII_CR_RESET;
  405. break;
  406. default: /* MEDIA_TYPE_10M_HALF: */
  407. phy_data = MII_CR_SPEED_10 | MII_CR_RESET;
  408. break;
  409. }
  410. }
  411. ret_val = atl1_write_phy_reg(hw, MII_BMCR, phy_data);
  412. if (ret_val) {
  413. u32 val;
  414. int i;
  415. /* pcie serdes link may be down! */
  416. dev_dbg(&pdev->dev, "pcie phy link down\n");
  417. for (i = 0; i < 25; i++) {
  418. msleep(1);
  419. val = ioread32(hw->hw_addr + REG_MDIO_CTRL);
  420. if (!(val & (MDIO_START | MDIO_BUSY)))
  421. break;
  422. }
  423. if ((val & (MDIO_START | MDIO_BUSY)) != 0) {
  424. dev_warn(&pdev->dev, "pcie link down at least 25ms\n");
  425. return ret_val;
  426. }
  427. }
  428. return ATL1_SUCCESS;
  429. }
  430. /*
  431. * Configures PHY autoneg and flow control advertisement settings
  432. * hw - Struct containing variables accessed by shared code
  433. */
  434. s32 atl1_phy_setup_autoneg_adv(struct atl1_hw *hw)
  435. {
  436. s32 ret_val;
  437. s16 mii_autoneg_adv_reg;
  438. s16 mii_1000t_ctrl_reg;
  439. /* Read the MII Auto-Neg Advertisement Register (Address 4). */
  440. mii_autoneg_adv_reg = MII_AR_DEFAULT_CAP_MASK;
  441. /* Read the MII 1000Base-T Control Register (Address 9). */
  442. mii_1000t_ctrl_reg = MII_AT001_CR_1000T_DEFAULT_CAP_MASK;
  443. /*
  444. * First we clear all the 10/100 mb speed bits in the Auto-Neg
  445. * Advertisement Register (Address 4) and the 1000 mb speed bits in
  446. * the 1000Base-T Control Register (Address 9).
  447. */
  448. mii_autoneg_adv_reg &= ~MII_AR_SPEED_MASK;
  449. mii_1000t_ctrl_reg &= ~MII_AT001_CR_1000T_SPEED_MASK;
  450. /*
  451. * Need to parse media_type and set up
  452. * the appropriate PHY registers.
  453. */
  454. switch (hw->media_type) {
  455. case MEDIA_TYPE_AUTO_SENSOR:
  456. mii_autoneg_adv_reg |= (MII_AR_10T_HD_CAPS |
  457. MII_AR_10T_FD_CAPS |
  458. MII_AR_100TX_HD_CAPS |
  459. MII_AR_100TX_FD_CAPS);
  460. mii_1000t_ctrl_reg |= MII_AT001_CR_1000T_FD_CAPS;
  461. break;
  462. case MEDIA_TYPE_1000M_FULL:
  463. mii_1000t_ctrl_reg |= MII_AT001_CR_1000T_FD_CAPS;
  464. break;
  465. case MEDIA_TYPE_100M_FULL:
  466. mii_autoneg_adv_reg |= MII_AR_100TX_FD_CAPS;
  467. break;
  468. case MEDIA_TYPE_100M_HALF:
  469. mii_autoneg_adv_reg |= MII_AR_100TX_HD_CAPS;
  470. break;
  471. case MEDIA_TYPE_10M_FULL:
  472. mii_autoneg_adv_reg |= MII_AR_10T_FD_CAPS;
  473. break;
  474. default:
  475. mii_autoneg_adv_reg |= MII_AR_10T_HD_CAPS;
  476. break;
  477. }
  478. /* flow control fixed to enable all */
  479. mii_autoneg_adv_reg |= (MII_AR_ASM_DIR | MII_AR_PAUSE);
  480. hw->mii_autoneg_adv_reg = mii_autoneg_adv_reg;
  481. hw->mii_1000t_ctrl_reg = mii_1000t_ctrl_reg;
  482. ret_val = atl1_write_phy_reg(hw, MII_ADVERTISE, mii_autoneg_adv_reg);
  483. if (ret_val)
  484. return ret_val;
  485. ret_val = atl1_write_phy_reg(hw, MII_AT001_CR, mii_1000t_ctrl_reg);
  486. if (ret_val)
  487. return ret_val;
  488. return ATL1_SUCCESS;
  489. }
  490. /*
  491. * Configures link settings.
  492. * hw - Struct containing variables accessed by shared code
  493. * Assumes the hardware has previously been reset and the
  494. * transmitter and receiver are not enabled.
  495. */
  496. static s32 atl1_setup_link(struct atl1_hw *hw)
  497. {
  498. struct pci_dev *pdev = hw->back->pdev;
  499. s32 ret_val;
  500. /*
  501. * Options:
  502. * PHY will advertise value(s) parsed from
  503. * autoneg_advertised and fc
  504. * no matter what autoneg is , We will not wait link result.
  505. */
  506. ret_val = atl1_phy_setup_autoneg_adv(hw);
  507. if (ret_val) {
  508. dev_dbg(&pdev->dev, "error setting up autonegotiation\n");
  509. return ret_val;
  510. }
  511. /* SW.Reset , En-Auto-Neg if needed */
  512. ret_val = atl1_phy_reset(hw);
  513. if (ret_val) {
  514. dev_dbg(&pdev->dev, "error resetting phy\n");
  515. return ret_val;
  516. }
  517. hw->phy_configured = true;
  518. return ret_val;
  519. }
  520. static struct atl1_spi_flash_dev flash_table[] = {
  521. /* MFR_NAME WRSR READ PRGM WREN WRDI RDSR RDID SECTOR_ERASE CHIP_ERASE */
  522. {"Atmel", 0x00, 0x03, 0x02, 0x06, 0x04, 0x05, 0x15, 0x52, 0x62},
  523. {"SST", 0x01, 0x03, 0x02, 0x06, 0x04, 0x05, 0x90, 0x20, 0x60},
  524. {"ST", 0x01, 0x03, 0x02, 0x06, 0x04, 0x05, 0xAB, 0xD8, 0xC7},
  525. };
  526. static void atl1_init_flash_opcode(struct atl1_hw *hw)
  527. {
  528. if (hw->flash_vendor >= sizeof(flash_table) / sizeof(flash_table[0]))
  529. hw->flash_vendor = 0; /* ATMEL */
  530. /* Init OP table */
  531. iowrite8(flash_table[hw->flash_vendor].cmd_program,
  532. hw->hw_addr + REG_SPI_FLASH_OP_PROGRAM);
  533. iowrite8(flash_table[hw->flash_vendor].cmd_sector_erase,
  534. hw->hw_addr + REG_SPI_FLASH_OP_SC_ERASE);
  535. iowrite8(flash_table[hw->flash_vendor].cmd_chip_erase,
  536. hw->hw_addr + REG_SPI_FLASH_OP_CHIP_ERASE);
  537. iowrite8(flash_table[hw->flash_vendor].cmd_rdid,
  538. hw->hw_addr + REG_SPI_FLASH_OP_RDID);
  539. iowrite8(flash_table[hw->flash_vendor].cmd_wren,
  540. hw->hw_addr + REG_SPI_FLASH_OP_WREN);
  541. iowrite8(flash_table[hw->flash_vendor].cmd_rdsr,
  542. hw->hw_addr + REG_SPI_FLASH_OP_RDSR);
  543. iowrite8(flash_table[hw->flash_vendor].cmd_wrsr,
  544. hw->hw_addr + REG_SPI_FLASH_OP_WRSR);
  545. iowrite8(flash_table[hw->flash_vendor].cmd_read,
  546. hw->hw_addr + REG_SPI_FLASH_OP_READ);
  547. }
  548. /*
  549. * Performs basic configuration of the adapter.
  550. * hw - Struct containing variables accessed by shared code
  551. * Assumes that the controller has previously been reset and is in a
  552. * post-reset uninitialized state. Initializes multicast table,
  553. * and Calls routines to setup link
  554. * Leaves the transmit and receive units disabled and uninitialized.
  555. */
  556. s32 atl1_init_hw(struct atl1_hw *hw)
  557. {
  558. u32 ret_val = 0;
  559. /* Zero out the Multicast HASH table */
  560. iowrite32(0, hw->hw_addr + REG_RX_HASH_TABLE);
  561. /* clear the old settings from the multicast hash table */
  562. iowrite32(0, (hw->hw_addr + REG_RX_HASH_TABLE) + (1 << 2));
  563. atl1_init_flash_opcode(hw);
  564. if (!hw->phy_configured) {
  565. /* enable GPHY LinkChange Interrrupt */
  566. ret_val = atl1_write_phy_reg(hw, 18, 0xC00);
  567. if (ret_val)
  568. return ret_val;
  569. /* make PHY out of power-saving state */
  570. ret_val = atl1_phy_leave_power_saving(hw);
  571. if (ret_val)
  572. return ret_val;
  573. /* Call a subroutine to configure the link */
  574. ret_val = atl1_setup_link(hw);
  575. }
  576. return ret_val;
  577. }
  578. /*
  579. * Detects the current speed and duplex settings of the hardware.
  580. * hw - Struct containing variables accessed by shared code
  581. * speed - Speed of the connection
  582. * duplex - Duplex setting of the connection
  583. */
  584. s32 atl1_get_speed_and_duplex(struct atl1_hw *hw, u16 *speed, u16 *duplex)
  585. {
  586. struct pci_dev *pdev = hw->back->pdev;
  587. s32 ret_val;
  588. u16 phy_data;
  589. /* ; --- Read PHY Specific Status Register (17) */
  590. ret_val = atl1_read_phy_reg(hw, MII_AT001_PSSR, &phy_data);
  591. if (ret_val)
  592. return ret_val;
  593. if (!(phy_data & MII_AT001_PSSR_SPD_DPLX_RESOLVED))
  594. return ATL1_ERR_PHY_RES;
  595. switch (phy_data & MII_AT001_PSSR_SPEED) {
  596. case MII_AT001_PSSR_1000MBS:
  597. *speed = SPEED_1000;
  598. break;
  599. case MII_AT001_PSSR_100MBS:
  600. *speed = SPEED_100;
  601. break;
  602. case MII_AT001_PSSR_10MBS:
  603. *speed = SPEED_10;
  604. break;
  605. default:
  606. dev_dbg(&pdev->dev, "error getting speed\n");
  607. return ATL1_ERR_PHY_SPEED;
  608. break;
  609. }
  610. if (phy_data & MII_AT001_PSSR_DPLX)
  611. *duplex = FULL_DUPLEX;
  612. else
  613. *duplex = HALF_DUPLEX;
  614. return ATL1_SUCCESS;
  615. }
  616. void atl1_set_mac_addr(struct atl1_hw *hw)
  617. {
  618. u32 value;
  619. /*
  620. * 00-0B-6A-F6-00-DC
  621. * 0: 6AF600DC 1: 000B
  622. * low dword
  623. */
  624. value = (((u32) hw->mac_addr[2]) << 24) |
  625. (((u32) hw->mac_addr[3]) << 16) |
  626. (((u32) hw->mac_addr[4]) << 8) | (((u32) hw->mac_addr[5]));
  627. iowrite32(value, hw->hw_addr + REG_MAC_STA_ADDR);
  628. /* high dword */
  629. value = (((u32) hw->mac_addr[0]) << 8) | (((u32) hw->mac_addr[1]));
  630. iowrite32(value, (hw->hw_addr + REG_MAC_STA_ADDR) + (1 << 2));
  631. }