e1000_mac.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503
  1. /*******************************************************************************
  2. Intel(R) Gigabit Ethernet Linux driver
  3. Copyright(c) 2007 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  18. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. *******************************************************************************/
  20. #include <linux/if_ether.h>
  21. #include <linux/delay.h>
  22. #include <linux/pci.h>
  23. #include <linux/netdevice.h>
  24. #include "e1000_mac.h"
  25. #include "igb.h"
  26. static s32 igb_set_default_fc(struct e1000_hw *hw);
  27. static s32 igb_set_fc_watermarks(struct e1000_hw *hw);
  28. /**
  29. * igb_remove_device - Free device specific structure
  30. * @hw: pointer to the HW structure
  31. *
  32. * If a device specific structure was allocated, this function will
  33. * free it.
  34. **/
  35. void igb_remove_device(struct e1000_hw *hw)
  36. {
  37. /* Freeing the dev_spec member of e1000_hw structure */
  38. kfree(hw->dev_spec);
  39. }
  40. static void igb_read_pci_cfg(struct e1000_hw *hw, u32 reg, u16 *value)
  41. {
  42. struct igb_adapter *adapter = hw->back;
  43. pci_read_config_word(adapter->pdev, reg, value);
  44. }
  45. static s32 igb_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
  46. {
  47. struct igb_adapter *adapter = hw->back;
  48. u16 cap_offset;
  49. cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
  50. if (!cap_offset)
  51. return -E1000_ERR_CONFIG;
  52. pci_read_config_word(adapter->pdev, cap_offset + reg, value);
  53. return 0;
  54. }
  55. /**
  56. * igb_get_bus_info_pcie - Get PCIe bus information
  57. * @hw: pointer to the HW structure
  58. *
  59. * Determines and stores the system bus information for a particular
  60. * network interface. The following bus information is determined and stored:
  61. * bus speed, bus width, type (PCIe), and PCIe function.
  62. **/
  63. s32 igb_get_bus_info_pcie(struct e1000_hw *hw)
  64. {
  65. struct e1000_bus_info *bus = &hw->bus;
  66. s32 ret_val;
  67. u32 status;
  68. u16 pcie_link_status, pci_header_type;
  69. bus->type = e1000_bus_type_pci_express;
  70. bus->speed = e1000_bus_speed_2500;
  71. ret_val = igb_read_pcie_cap_reg(hw,
  72. PCIE_LINK_STATUS,
  73. &pcie_link_status);
  74. if (ret_val)
  75. bus->width = e1000_bus_width_unknown;
  76. else
  77. bus->width = (enum e1000_bus_width)((pcie_link_status &
  78. PCIE_LINK_WIDTH_MASK) >>
  79. PCIE_LINK_WIDTH_SHIFT);
  80. igb_read_pci_cfg(hw, PCI_HEADER_TYPE_REGISTER, &pci_header_type);
  81. if (pci_header_type & PCI_HEADER_TYPE_MULTIFUNC) {
  82. status = rd32(E1000_STATUS);
  83. bus->func = (status & E1000_STATUS_FUNC_MASK)
  84. >> E1000_STATUS_FUNC_SHIFT;
  85. } else {
  86. bus->func = 0;
  87. }
  88. return 0;
  89. }
  90. /**
  91. * igb_clear_vfta - Clear VLAN filter table
  92. * @hw: pointer to the HW structure
  93. *
  94. * Clears the register array which contains the VLAN filter table by
  95. * setting all the values to 0.
  96. **/
  97. void igb_clear_vfta(struct e1000_hw *hw)
  98. {
  99. u32 offset;
  100. for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
  101. array_wr32(E1000_VFTA, offset, 0);
  102. wrfl();
  103. }
  104. }
  105. /**
  106. * igb_write_vfta - Write value to VLAN filter table
  107. * @hw: pointer to the HW structure
  108. * @offset: register offset in VLAN filter table
  109. * @value: register value written to VLAN filter table
  110. *
  111. * Writes value at the given offset in the register array which stores
  112. * the VLAN filter table.
  113. **/
  114. void igb_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
  115. {
  116. array_wr32(E1000_VFTA, offset, value);
  117. wrfl();
  118. }
  119. /**
  120. * igb_init_rx_addrs - Initialize receive address's
  121. * @hw: pointer to the HW structure
  122. * @rar_count: receive address registers
  123. *
  124. * Setups the receive address registers by setting the base receive address
  125. * register to the devices MAC address and clearing all the other receive
  126. * address registers to 0.
  127. **/
  128. void igb_init_rx_addrs(struct e1000_hw *hw, u16 rar_count)
  129. {
  130. u32 i;
  131. /* Setup the receive address */
  132. hw_dbg("Programming MAC Address into RAR[0]\n");
  133. hw->mac.ops.rar_set(hw, hw->mac.addr, 0);
  134. /* Zero out the other (rar_entry_count - 1) receive addresses */
  135. hw_dbg("Clearing RAR[1-%u]\n", rar_count-1);
  136. for (i = 1; i < rar_count; i++) {
  137. array_wr32(E1000_RA, (i << 1), 0);
  138. wrfl();
  139. array_wr32(E1000_RA, ((i << 1) + 1), 0);
  140. wrfl();
  141. }
  142. }
  143. /**
  144. * igb_check_alt_mac_addr - Check for alternate MAC addr
  145. * @hw: pointer to the HW structure
  146. *
  147. * Checks the nvm for an alternate MAC address. An alternate MAC address
  148. * can be setup by pre-boot software and must be treated like a permanent
  149. * address and must override the actual permanent MAC address. If an
  150. * alternate MAC address is fopund it is saved in the hw struct and
  151. * prgrammed into RAR0 and the cuntion returns success, otherwise the
  152. * fucntion returns an error.
  153. **/
  154. s32 igb_check_alt_mac_addr(struct e1000_hw *hw)
  155. {
  156. u32 i;
  157. s32 ret_val = 0;
  158. u16 offset, nvm_alt_mac_addr_offset, nvm_data;
  159. u8 alt_mac_addr[ETH_ALEN];
  160. ret_val = hw->nvm.ops.read_nvm(hw, NVM_ALT_MAC_ADDR_PTR, 1,
  161. &nvm_alt_mac_addr_offset);
  162. if (ret_val) {
  163. hw_dbg("NVM Read Error\n");
  164. goto out;
  165. }
  166. if (nvm_alt_mac_addr_offset == 0xFFFF) {
  167. ret_val = -(E1000_NOT_IMPLEMENTED);
  168. goto out;
  169. }
  170. if (hw->bus.func == E1000_FUNC_1)
  171. nvm_alt_mac_addr_offset += ETH_ALEN/sizeof(u16);
  172. for (i = 0; i < ETH_ALEN; i += 2) {
  173. offset = nvm_alt_mac_addr_offset + (i >> 1);
  174. ret_val = hw->nvm.ops.read_nvm(hw, offset, 1, &nvm_data);
  175. if (ret_val) {
  176. hw_dbg("NVM Read Error\n");
  177. goto out;
  178. }
  179. alt_mac_addr[i] = (u8)(nvm_data & 0xFF);
  180. alt_mac_addr[i + 1] = (u8)(nvm_data >> 8);
  181. }
  182. /* if multicast bit is set, the alternate address will not be used */
  183. if (alt_mac_addr[0] & 0x01) {
  184. ret_val = -(E1000_NOT_IMPLEMENTED);
  185. goto out;
  186. }
  187. for (i = 0; i < ETH_ALEN; i++)
  188. hw->mac.addr[i] = hw->mac.perm_addr[i] = alt_mac_addr[i];
  189. hw->mac.ops.rar_set(hw, hw->mac.perm_addr, 0);
  190. out:
  191. return ret_val;
  192. }
  193. /**
  194. * igb_rar_set - Set receive address register
  195. * @hw: pointer to the HW structure
  196. * @addr: pointer to the receive address
  197. * @index: receive address array register
  198. *
  199. * Sets the receive address array register at index to the address passed
  200. * in by addr.
  201. **/
  202. void igb_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
  203. {
  204. u32 rar_low, rar_high;
  205. /*
  206. * HW expects these in little endian so we reverse the byte order
  207. * from network order (big endian) to little endian
  208. */
  209. rar_low = ((u32) addr[0] |
  210. ((u32) addr[1] << 8) |
  211. ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
  212. rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
  213. if (!hw->mac.disable_av)
  214. rar_high |= E1000_RAH_AV;
  215. array_wr32(E1000_RA, (index << 1), rar_low);
  216. array_wr32(E1000_RA, ((index << 1) + 1), rar_high);
  217. }
  218. /**
  219. * igb_mta_set - Set multicast filter table address
  220. * @hw: pointer to the HW structure
  221. * @hash_value: determines the MTA register and bit to set
  222. *
  223. * The multicast table address is a register array of 32-bit registers.
  224. * The hash_value is used to determine what register the bit is in, the
  225. * current value is read, the new bit is OR'd in and the new value is
  226. * written back into the register.
  227. **/
  228. static void igb_mta_set(struct e1000_hw *hw, u32 hash_value)
  229. {
  230. u32 hash_bit, hash_reg, mta;
  231. /*
  232. * The MTA is a register array of 32-bit registers. It is
  233. * treated like an array of (32*mta_reg_count) bits. We want to
  234. * set bit BitArray[hash_value]. So we figure out what register
  235. * the bit is in, read it, OR in the new bit, then write
  236. * back the new value. The (hw->mac.mta_reg_count - 1) serves as a
  237. * mask to bits 31:5 of the hash value which gives us the
  238. * register we're modifying. The hash bit within that register
  239. * is determined by the lower 5 bits of the hash value.
  240. */
  241. hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
  242. hash_bit = hash_value & 0x1F;
  243. mta = array_rd32(E1000_MTA, hash_reg);
  244. mta |= (1 << hash_bit);
  245. array_wr32(E1000_MTA, hash_reg, mta);
  246. wrfl();
  247. }
  248. /**
  249. * igb_update_mc_addr_list - Update Multicast addresses
  250. * @hw: pointer to the HW structure
  251. * @mc_addr_list: array of multicast addresses to program
  252. * @mc_addr_count: number of multicast addresses to program
  253. * @rar_used_count: the first RAR register free to program
  254. * @rar_count: total number of supported Receive Address Registers
  255. *
  256. * Updates the Receive Address Registers and Multicast Table Array.
  257. * The caller must have a packed mc_addr_list of multicast addresses.
  258. * The parameter rar_count will usually be hw->mac.rar_entry_count
  259. * unless there are workarounds that change this.
  260. **/
  261. void igb_update_mc_addr_list(struct e1000_hw *hw,
  262. u8 *mc_addr_list, u32 mc_addr_count,
  263. u32 rar_used_count, u32 rar_count)
  264. {
  265. u32 hash_value;
  266. u32 i;
  267. /*
  268. * Load the first set of multicast addresses into the exact
  269. * filters (RAR). If there are not enough to fill the RAR
  270. * array, clear the filters.
  271. */
  272. for (i = rar_used_count; i < rar_count; i++) {
  273. if (mc_addr_count) {
  274. hw->mac.ops.rar_set(hw, mc_addr_list, i);
  275. mc_addr_count--;
  276. mc_addr_list += ETH_ALEN;
  277. } else {
  278. array_wr32(E1000_RA, i << 1, 0);
  279. wrfl();
  280. array_wr32(E1000_RA, (i << 1) + 1, 0);
  281. wrfl();
  282. }
  283. }
  284. /* Clear the old settings from the MTA */
  285. hw_dbg("Clearing MTA\n");
  286. for (i = 0; i < hw->mac.mta_reg_count; i++) {
  287. array_wr32(E1000_MTA, i, 0);
  288. wrfl();
  289. }
  290. /* Load any remaining multicast addresses into the hash table. */
  291. for (; mc_addr_count > 0; mc_addr_count--) {
  292. hash_value = igb_hash_mc_addr(hw, mc_addr_list);
  293. hw_dbg("Hash value = 0x%03X\n", hash_value);
  294. igb_mta_set(hw, hash_value);
  295. mc_addr_list += ETH_ALEN;
  296. }
  297. }
  298. /**
  299. * igb_hash_mc_addr - Generate a multicast hash value
  300. * @hw: pointer to the HW structure
  301. * @mc_addr: pointer to a multicast address
  302. *
  303. * Generates a multicast address hash value which is used to determine
  304. * the multicast filter table array address and new table value. See
  305. * igb_mta_set()
  306. **/
  307. u32 igb_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
  308. {
  309. u32 hash_value, hash_mask;
  310. u8 bit_shift = 0;
  311. /* Register count multiplied by bits per register */
  312. hash_mask = (hw->mac.mta_reg_count * 32) - 1;
  313. /*
  314. * For a mc_filter_type of 0, bit_shift is the number of left-shifts
  315. * where 0xFF would still fall within the hash mask.
  316. */
  317. while (hash_mask >> bit_shift != 0xFF)
  318. bit_shift++;
  319. /*
  320. * The portion of the address that is used for the hash table
  321. * is determined by the mc_filter_type setting.
  322. * The algorithm is such that there is a total of 8 bits of shifting.
  323. * The bit_shift for a mc_filter_type of 0 represents the number of
  324. * left-shifts where the MSB of mc_addr[5] would still fall within
  325. * the hash_mask. Case 0 does this exactly. Since there are a total
  326. * of 8 bits of shifting, then mc_addr[4] will shift right the
  327. * remaining number of bits. Thus 8 - bit_shift. The rest of the
  328. * cases are a variation of this algorithm...essentially raising the
  329. * number of bits to shift mc_addr[5] left, while still keeping the
  330. * 8-bit shifting total.
  331. *
  332. * For example, given the following Destination MAC Address and an
  333. * mta register count of 128 (thus a 4096-bit vector and 0xFFF mask),
  334. * we can see that the bit_shift for case 0 is 4. These are the hash
  335. * values resulting from each mc_filter_type...
  336. * [0] [1] [2] [3] [4] [5]
  337. * 01 AA 00 12 34 56
  338. * LSB MSB
  339. *
  340. * case 0: hash_value = ((0x34 >> 4) | (0x56 << 4)) & 0xFFF = 0x563
  341. * case 1: hash_value = ((0x34 >> 3) | (0x56 << 5)) & 0xFFF = 0xAC6
  342. * case 2: hash_value = ((0x34 >> 2) | (0x56 << 6)) & 0xFFF = 0x163
  343. * case 3: hash_value = ((0x34 >> 0) | (0x56 << 8)) & 0xFFF = 0x634
  344. */
  345. switch (hw->mac.mc_filter_type) {
  346. default:
  347. case 0:
  348. break;
  349. case 1:
  350. bit_shift += 1;
  351. break;
  352. case 2:
  353. bit_shift += 2;
  354. break;
  355. case 3:
  356. bit_shift += 4;
  357. break;
  358. }
  359. hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
  360. (((u16) mc_addr[5]) << bit_shift)));
  361. return hash_value;
  362. }
  363. /**
  364. * igb_clear_hw_cntrs_base - Clear base hardware counters
  365. * @hw: pointer to the HW structure
  366. *
  367. * Clears the base hardware counters by reading the counter registers.
  368. **/
  369. void igb_clear_hw_cntrs_base(struct e1000_hw *hw)
  370. {
  371. u32 temp;
  372. temp = rd32(E1000_CRCERRS);
  373. temp = rd32(E1000_SYMERRS);
  374. temp = rd32(E1000_MPC);
  375. temp = rd32(E1000_SCC);
  376. temp = rd32(E1000_ECOL);
  377. temp = rd32(E1000_MCC);
  378. temp = rd32(E1000_LATECOL);
  379. temp = rd32(E1000_COLC);
  380. temp = rd32(E1000_DC);
  381. temp = rd32(E1000_SEC);
  382. temp = rd32(E1000_RLEC);
  383. temp = rd32(E1000_XONRXC);
  384. temp = rd32(E1000_XONTXC);
  385. temp = rd32(E1000_XOFFRXC);
  386. temp = rd32(E1000_XOFFTXC);
  387. temp = rd32(E1000_FCRUC);
  388. temp = rd32(E1000_GPRC);
  389. temp = rd32(E1000_BPRC);
  390. temp = rd32(E1000_MPRC);
  391. temp = rd32(E1000_GPTC);
  392. temp = rd32(E1000_GORCL);
  393. temp = rd32(E1000_GORCH);
  394. temp = rd32(E1000_GOTCL);
  395. temp = rd32(E1000_GOTCH);
  396. temp = rd32(E1000_RNBC);
  397. temp = rd32(E1000_RUC);
  398. temp = rd32(E1000_RFC);
  399. temp = rd32(E1000_ROC);
  400. temp = rd32(E1000_RJC);
  401. temp = rd32(E1000_TORL);
  402. temp = rd32(E1000_TORH);
  403. temp = rd32(E1000_TOTL);
  404. temp = rd32(E1000_TOTH);
  405. temp = rd32(E1000_TPR);
  406. temp = rd32(E1000_TPT);
  407. temp = rd32(E1000_MPTC);
  408. temp = rd32(E1000_BPTC);
  409. }
  410. /**
  411. * igb_check_for_copper_link - Check for link (Copper)
  412. * @hw: pointer to the HW structure
  413. *
  414. * Checks to see of the link status of the hardware has changed. If a
  415. * change in link status has been detected, then we read the PHY registers
  416. * to get the current speed/duplex if link exists.
  417. **/
  418. s32 igb_check_for_copper_link(struct e1000_hw *hw)
  419. {
  420. struct e1000_mac_info *mac = &hw->mac;
  421. s32 ret_val;
  422. bool link;
  423. /*
  424. * We only want to go out to the PHY registers to see if Auto-Neg
  425. * has completed and/or if our link status has changed. The
  426. * get_link_status flag is set upon receiving a Link Status
  427. * Change or Rx Sequence Error interrupt.
  428. */
  429. if (!mac->get_link_status) {
  430. ret_val = 0;
  431. goto out;
  432. }
  433. /*
  434. * First we want to see if the MII Status Register reports
  435. * link. If so, then we want to get the current speed/duplex
  436. * of the PHY.
  437. */
  438. ret_val = igb_phy_has_link(hw, 1, 0, &link);
  439. if (ret_val)
  440. goto out;
  441. if (!link)
  442. goto out; /* No link detected */
  443. mac->get_link_status = false;
  444. /*
  445. * Check if there was DownShift, must be checked
  446. * immediately after link-up
  447. */
  448. igb_check_downshift(hw);
  449. /*
  450. * If we are forcing speed/duplex, then we simply return since
  451. * we have already determined whether we have link or not.
  452. */
  453. if (!mac->autoneg) {
  454. ret_val = -E1000_ERR_CONFIG;
  455. goto out;
  456. }
  457. /*
  458. * Auto-Neg is enabled. Auto Speed Detection takes care
  459. * of MAC speed/duplex configuration. So we only need to
  460. * configure Collision Distance in the MAC.
  461. */
  462. igb_config_collision_dist(hw);
  463. /*
  464. * Configure Flow Control now that Auto-Neg has completed.
  465. * First, we need to restore the desired flow control
  466. * settings because we may have had to re-autoneg with a
  467. * different link partner.
  468. */
  469. ret_val = igb_config_fc_after_link_up(hw);
  470. if (ret_val)
  471. hw_dbg("Error configuring flow control\n");
  472. out:
  473. return ret_val;
  474. }
  475. /**
  476. * igb_setup_link - Setup flow control and link settings
  477. * @hw: pointer to the HW structure
  478. *
  479. * Determines which flow control settings to use, then configures flow
  480. * control. Calls the appropriate media-specific link configuration
  481. * function. Assuming the adapter has a valid link partner, a valid link
  482. * should be established. Assumes the hardware has previously been reset
  483. * and the transmitter and receiver are not enabled.
  484. **/
  485. s32 igb_setup_link(struct e1000_hw *hw)
  486. {
  487. s32 ret_val = 0;
  488. /*
  489. * In the case of the phy reset being blocked, we already have a link.
  490. * We do not need to set it up again.
  491. */
  492. if (igb_check_reset_block(hw))
  493. goto out;
  494. ret_val = igb_set_default_fc(hw);
  495. if (ret_val)
  496. goto out;
  497. /*
  498. * We want to save off the original Flow Control configuration just
  499. * in case we get disconnected and then reconnected into a different
  500. * hub or switch with different Flow Control capabilities.
  501. */
  502. hw->fc.original_type = hw->fc.type;
  503. hw_dbg("After fix-ups FlowControl is now = %x\n", hw->fc.type);
  504. /* Call the necessary media_type subroutine to configure the link. */
  505. ret_val = hw->mac.ops.setup_physical_interface(hw);
  506. if (ret_val)
  507. goto out;
  508. /*
  509. * Initialize the flow control address, type, and PAUSE timer
  510. * registers to their default values. This is done even if flow
  511. * control is disabled, because it does not hurt anything to
  512. * initialize these registers.
  513. */
  514. hw_dbg("Initializing the Flow Control address, type and timer regs\n");
  515. wr32(E1000_FCT, FLOW_CONTROL_TYPE);
  516. wr32(E1000_FCAH, FLOW_CONTROL_ADDRESS_HIGH);
  517. wr32(E1000_FCAL, FLOW_CONTROL_ADDRESS_LOW);
  518. wr32(E1000_FCTTV, hw->fc.pause_time);
  519. ret_val = igb_set_fc_watermarks(hw);
  520. out:
  521. return ret_val;
  522. }
  523. /**
  524. * igb_config_collision_dist - Configure collision distance
  525. * @hw: pointer to the HW structure
  526. *
  527. * Configures the collision distance to the default value and is used
  528. * during link setup. Currently no func pointer exists and all
  529. * implementations are handled in the generic version of this function.
  530. **/
  531. void igb_config_collision_dist(struct e1000_hw *hw)
  532. {
  533. u32 tctl;
  534. tctl = rd32(E1000_TCTL);
  535. tctl &= ~E1000_TCTL_COLD;
  536. tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
  537. wr32(E1000_TCTL, tctl);
  538. wrfl();
  539. }
  540. /**
  541. * igb_set_fc_watermarks - Set flow control high/low watermarks
  542. * @hw: pointer to the HW structure
  543. *
  544. * Sets the flow control high/low threshold (watermark) registers. If
  545. * flow control XON frame transmission is enabled, then set XON frame
  546. * tansmission as well.
  547. **/
  548. static s32 igb_set_fc_watermarks(struct e1000_hw *hw)
  549. {
  550. s32 ret_val = 0;
  551. u32 fcrtl = 0, fcrth = 0;
  552. /*
  553. * Set the flow control receive threshold registers. Normally,
  554. * these registers will be set to a default threshold that may be
  555. * adjusted later by the driver's runtime code. However, if the
  556. * ability to transmit pause frames is not enabled, then these
  557. * registers will be set to 0.
  558. */
  559. if (hw->fc.type & e1000_fc_tx_pause) {
  560. /*
  561. * We need to set up the Receive Threshold high and low water
  562. * marks as well as (optionally) enabling the transmission of
  563. * XON frames.
  564. */
  565. fcrtl = hw->fc.low_water;
  566. if (hw->fc.send_xon)
  567. fcrtl |= E1000_FCRTL_XONE;
  568. fcrth = hw->fc.high_water;
  569. }
  570. wr32(E1000_FCRTL, fcrtl);
  571. wr32(E1000_FCRTH, fcrth);
  572. return ret_val;
  573. }
  574. /**
  575. * igb_set_default_fc - Set flow control default values
  576. * @hw: pointer to the HW structure
  577. *
  578. * Read the EEPROM for the default values for flow control and store the
  579. * values.
  580. **/
  581. static s32 igb_set_default_fc(struct e1000_hw *hw)
  582. {
  583. s32 ret_val = 0;
  584. u16 nvm_data;
  585. /*
  586. * Read and store word 0x0F of the EEPROM. This word contains bits
  587. * that determine the hardware's default PAUSE (flow control) mode,
  588. * a bit that determines whether the HW defaults to enabling or
  589. * disabling auto-negotiation, and the direction of the
  590. * SW defined pins. If there is no SW over-ride of the flow
  591. * control setting, then the variable hw->fc will
  592. * be initialized based on a value in the EEPROM.
  593. */
  594. ret_val = hw->nvm.ops.read_nvm(hw, NVM_INIT_CONTROL2_REG, 1,
  595. &nvm_data);
  596. if (ret_val) {
  597. hw_dbg("NVM Read Error\n");
  598. goto out;
  599. }
  600. if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == 0)
  601. hw->fc.type = e1000_fc_none;
  602. else if ((nvm_data & NVM_WORD0F_PAUSE_MASK) ==
  603. NVM_WORD0F_ASM_DIR)
  604. hw->fc.type = e1000_fc_tx_pause;
  605. else
  606. hw->fc.type = e1000_fc_full;
  607. out:
  608. return ret_val;
  609. }
  610. /**
  611. * igb_force_mac_fc - Force the MAC's flow control settings
  612. * @hw: pointer to the HW structure
  613. *
  614. * Force the MAC's flow control settings. Sets the TFCE and RFCE bits in the
  615. * device control register to reflect the adapter settings. TFCE and RFCE
  616. * need to be explicitly set by software when a copper PHY is used because
  617. * autonegotiation is managed by the PHY rather than the MAC. Software must
  618. * also configure these bits when link is forced on a fiber connection.
  619. **/
  620. s32 igb_force_mac_fc(struct e1000_hw *hw)
  621. {
  622. u32 ctrl;
  623. s32 ret_val = 0;
  624. ctrl = rd32(E1000_CTRL);
  625. /*
  626. * Because we didn't get link via the internal auto-negotiation
  627. * mechanism (we either forced link or we got link via PHY
  628. * auto-neg), we have to manually enable/disable transmit an
  629. * receive flow control.
  630. *
  631. * The "Case" statement below enables/disable flow control
  632. * according to the "hw->fc.type" parameter.
  633. *
  634. * The possible values of the "fc" parameter are:
  635. * 0: Flow control is completely disabled
  636. * 1: Rx flow control is enabled (we can receive pause
  637. * frames but not send pause frames).
  638. * 2: Tx flow control is enabled (we can send pause frames
  639. * frames but we do not receive pause frames).
  640. * 3: Both Rx and TX flow control (symmetric) is enabled.
  641. * other: No other values should be possible at this point.
  642. */
  643. hw_dbg("hw->fc.type = %u\n", hw->fc.type);
  644. switch (hw->fc.type) {
  645. case e1000_fc_none:
  646. ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
  647. break;
  648. case e1000_fc_rx_pause:
  649. ctrl &= (~E1000_CTRL_TFCE);
  650. ctrl |= E1000_CTRL_RFCE;
  651. break;
  652. case e1000_fc_tx_pause:
  653. ctrl &= (~E1000_CTRL_RFCE);
  654. ctrl |= E1000_CTRL_TFCE;
  655. break;
  656. case e1000_fc_full:
  657. ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
  658. break;
  659. default:
  660. hw_dbg("Flow control param set incorrectly\n");
  661. ret_val = -E1000_ERR_CONFIG;
  662. goto out;
  663. }
  664. wr32(E1000_CTRL, ctrl);
  665. out:
  666. return ret_val;
  667. }
  668. /**
  669. * igb_config_fc_after_link_up - Configures flow control after link
  670. * @hw: pointer to the HW structure
  671. *
  672. * Checks the status of auto-negotiation after link up to ensure that the
  673. * speed and duplex were not forced. If the link needed to be forced, then
  674. * flow control needs to be forced also. If auto-negotiation is enabled
  675. * and did not fail, then we configure flow control based on our link
  676. * partner.
  677. **/
  678. s32 igb_config_fc_after_link_up(struct e1000_hw *hw)
  679. {
  680. struct e1000_mac_info *mac = &hw->mac;
  681. s32 ret_val = 0;
  682. u16 mii_status_reg, mii_nway_adv_reg, mii_nway_lp_ability_reg;
  683. u16 speed, duplex;
  684. /*
  685. * Check for the case where we have fiber media and auto-neg failed
  686. * so we had to force link. In this case, we need to force the
  687. * configuration of the MAC to match the "fc" parameter.
  688. */
  689. if (mac->autoneg_failed) {
  690. if (hw->phy.media_type == e1000_media_type_fiber ||
  691. hw->phy.media_type == e1000_media_type_internal_serdes)
  692. ret_val = igb_force_mac_fc(hw);
  693. } else {
  694. if (hw->phy.media_type == e1000_media_type_copper)
  695. ret_val = igb_force_mac_fc(hw);
  696. }
  697. if (ret_val) {
  698. hw_dbg("Error forcing flow control settings\n");
  699. goto out;
  700. }
  701. /*
  702. * Check for the case where we have copper media and auto-neg is
  703. * enabled. In this case, we need to check and see if Auto-Neg
  704. * has completed, and if so, how the PHY and link partner has
  705. * flow control configured.
  706. */
  707. if ((hw->phy.media_type == e1000_media_type_copper) && mac->autoneg) {
  708. /*
  709. * Read the MII Status Register and check to see if AutoNeg
  710. * has completed. We read this twice because this reg has
  711. * some "sticky" (latched) bits.
  712. */
  713. ret_val = hw->phy.ops.read_phy_reg(hw, PHY_STATUS,
  714. &mii_status_reg);
  715. if (ret_val)
  716. goto out;
  717. ret_val = hw->phy.ops.read_phy_reg(hw, PHY_STATUS,
  718. &mii_status_reg);
  719. if (ret_val)
  720. goto out;
  721. if (!(mii_status_reg & MII_SR_AUTONEG_COMPLETE)) {
  722. hw_dbg("Copper PHY and Auto Neg "
  723. "has not completed.\n");
  724. goto out;
  725. }
  726. /*
  727. * The AutoNeg process has completed, so we now need to
  728. * read both the Auto Negotiation Advertisement
  729. * Register (Address 4) and the Auto_Negotiation Base
  730. * Page Ability Register (Address 5) to determine how
  731. * flow control was negotiated.
  732. */
  733. ret_val = hw->phy.ops.read_phy_reg(hw, PHY_AUTONEG_ADV,
  734. &mii_nway_adv_reg);
  735. if (ret_val)
  736. goto out;
  737. ret_val = hw->phy.ops.read_phy_reg(hw, PHY_LP_ABILITY,
  738. &mii_nway_lp_ability_reg);
  739. if (ret_val)
  740. goto out;
  741. /*
  742. * Two bits in the Auto Negotiation Advertisement Register
  743. * (Address 4) and two bits in the Auto Negotiation Base
  744. * Page Ability Register (Address 5) determine flow control
  745. * for both the PHY and the link partner. The following
  746. * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
  747. * 1999, describes these PAUSE resolution bits and how flow
  748. * control is determined based upon these settings.
  749. * NOTE: DC = Don't Care
  750. *
  751. * LOCAL DEVICE | LINK PARTNER
  752. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
  753. *-------|---------|-------|---------|--------------------
  754. * 0 | 0 | DC | DC | e1000_fc_none
  755. * 0 | 1 | 0 | DC | e1000_fc_none
  756. * 0 | 1 | 1 | 0 | e1000_fc_none
  757. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  758. * 1 | 0 | 0 | DC | e1000_fc_none
  759. * 1 | DC | 1 | DC | e1000_fc_full
  760. * 1 | 1 | 0 | 0 | e1000_fc_none
  761. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  762. *
  763. * Are both PAUSE bits set to 1? If so, this implies
  764. * Symmetric Flow Control is enabled at both ends. The
  765. * ASM_DIR bits are irrelevant per the spec.
  766. *
  767. * For Symmetric Flow Control:
  768. *
  769. * LOCAL DEVICE | LINK PARTNER
  770. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  771. *-------|---------|-------|---------|--------------------
  772. * 1 | DC | 1 | DC | E1000_fc_full
  773. *
  774. */
  775. if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  776. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
  777. /*
  778. * Now we need to check if the user selected RX ONLY
  779. * of pause frames. In this case, we had to advertise
  780. * FULL flow control because we could not advertise RX
  781. * ONLY. Hence, we must now check to see if we need to
  782. * turn OFF the TRANSMISSION of PAUSE frames.
  783. */
  784. if (hw->fc.original_type == e1000_fc_full) {
  785. hw->fc.type = e1000_fc_full;
  786. hw_dbg("Flow Control = FULL.\r\n");
  787. } else {
  788. hw->fc.type = e1000_fc_rx_pause;
  789. hw_dbg("Flow Control = "
  790. "RX PAUSE frames only.\r\n");
  791. }
  792. }
  793. /*
  794. * For receiving PAUSE frames ONLY.
  795. *
  796. * LOCAL DEVICE | LINK PARTNER
  797. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  798. *-------|---------|-------|---------|--------------------
  799. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  800. */
  801. else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  802. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  803. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  804. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
  805. hw->fc.type = e1000_fc_tx_pause;
  806. hw_dbg("Flow Control = TX PAUSE frames only.\r\n");
  807. }
  808. /*
  809. * For transmitting PAUSE frames ONLY.
  810. *
  811. * LOCAL DEVICE | LINK PARTNER
  812. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  813. *-------|---------|-------|---------|--------------------
  814. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  815. */
  816. else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  817. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  818. !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  819. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
  820. hw->fc.type = e1000_fc_rx_pause;
  821. hw_dbg("Flow Control = RX PAUSE frames only.\r\n");
  822. }
  823. /*
  824. * Per the IEEE spec, at this point flow control should be
  825. * disabled. However, we want to consider that we could
  826. * be connected to a legacy switch that doesn't advertise
  827. * desired flow control, but can be forced on the link
  828. * partner. So if we advertised no flow control, that is
  829. * what we will resolve to. If we advertised some kind of
  830. * receive capability (Rx Pause Only or Full Flow Control)
  831. * and the link partner advertised none, we will configure
  832. * ourselves to enable Rx Flow Control only. We can do
  833. * this safely for two reasons: If the link partner really
  834. * didn't want flow control enabled, and we enable Rx, no
  835. * harm done since we won't be receiving any PAUSE frames
  836. * anyway. If the intent on the link partner was to have
  837. * flow control enabled, then by us enabling RX only, we
  838. * can at least receive pause frames and process them.
  839. * This is a good idea because in most cases, since we are
  840. * predominantly a server NIC, more times than not we will
  841. * be asked to delay transmission of packets than asking
  842. * our link partner to pause transmission of frames.
  843. */
  844. else if ((hw->fc.original_type == e1000_fc_none ||
  845. hw->fc.original_type == e1000_fc_tx_pause) ||
  846. hw->fc.strict_ieee) {
  847. hw->fc.type = e1000_fc_none;
  848. hw_dbg("Flow Control = NONE.\r\n");
  849. } else {
  850. hw->fc.type = e1000_fc_rx_pause;
  851. hw_dbg("Flow Control = RX PAUSE frames only.\r\n");
  852. }
  853. /*
  854. * Now we need to do one last check... If we auto-
  855. * negotiated to HALF DUPLEX, flow control should not be
  856. * enabled per IEEE 802.3 spec.
  857. */
  858. ret_val = hw->mac.ops.get_speed_and_duplex(hw, &speed, &duplex);
  859. if (ret_val) {
  860. hw_dbg("Error getting link speed and duplex\n");
  861. goto out;
  862. }
  863. if (duplex == HALF_DUPLEX)
  864. hw->fc.type = e1000_fc_none;
  865. /*
  866. * Now we call a subroutine to actually force the MAC
  867. * controller to use the correct flow control settings.
  868. */
  869. ret_val = igb_force_mac_fc(hw);
  870. if (ret_val) {
  871. hw_dbg("Error forcing flow control settings\n");
  872. goto out;
  873. }
  874. }
  875. out:
  876. return ret_val;
  877. }
  878. /**
  879. * igb_get_speed_and_duplex_copper - Retreive current speed/duplex
  880. * @hw: pointer to the HW structure
  881. * @speed: stores the current speed
  882. * @duplex: stores the current duplex
  883. *
  884. * Read the status register for the current speed/duplex and store the current
  885. * speed and duplex for copper connections.
  886. **/
  887. s32 igb_get_speed_and_duplex_copper(struct e1000_hw *hw, u16 *speed,
  888. u16 *duplex)
  889. {
  890. u32 status;
  891. status = rd32(E1000_STATUS);
  892. if (status & E1000_STATUS_SPEED_1000) {
  893. *speed = SPEED_1000;
  894. hw_dbg("1000 Mbs, ");
  895. } else if (status & E1000_STATUS_SPEED_100) {
  896. *speed = SPEED_100;
  897. hw_dbg("100 Mbs, ");
  898. } else {
  899. *speed = SPEED_10;
  900. hw_dbg("10 Mbs, ");
  901. }
  902. if (status & E1000_STATUS_FD) {
  903. *duplex = FULL_DUPLEX;
  904. hw_dbg("Full Duplex\n");
  905. } else {
  906. *duplex = HALF_DUPLEX;
  907. hw_dbg("Half Duplex\n");
  908. }
  909. return 0;
  910. }
  911. /**
  912. * igb_get_hw_semaphore - Acquire hardware semaphore
  913. * @hw: pointer to the HW structure
  914. *
  915. * Acquire the HW semaphore to access the PHY or NVM
  916. **/
  917. s32 igb_get_hw_semaphore(struct e1000_hw *hw)
  918. {
  919. u32 swsm;
  920. s32 ret_val = 0;
  921. s32 timeout = hw->nvm.word_size + 1;
  922. s32 i = 0;
  923. /* Get the SW semaphore */
  924. while (i < timeout) {
  925. swsm = rd32(E1000_SWSM);
  926. if (!(swsm & E1000_SWSM_SMBI))
  927. break;
  928. udelay(50);
  929. i++;
  930. }
  931. if (i == timeout) {
  932. hw_dbg("Driver can't access device - SMBI bit is set.\n");
  933. ret_val = -E1000_ERR_NVM;
  934. goto out;
  935. }
  936. /* Get the FW semaphore. */
  937. for (i = 0; i < timeout; i++) {
  938. swsm = rd32(E1000_SWSM);
  939. wr32(E1000_SWSM, swsm | E1000_SWSM_SWESMBI);
  940. /* Semaphore acquired if bit latched */
  941. if (rd32(E1000_SWSM) & E1000_SWSM_SWESMBI)
  942. break;
  943. udelay(50);
  944. }
  945. if (i == timeout) {
  946. /* Release semaphores */
  947. igb_put_hw_semaphore(hw);
  948. hw_dbg("Driver can't access the NVM\n");
  949. ret_val = -E1000_ERR_NVM;
  950. goto out;
  951. }
  952. out:
  953. return ret_val;
  954. }
  955. /**
  956. * igb_put_hw_semaphore - Release hardware semaphore
  957. * @hw: pointer to the HW structure
  958. *
  959. * Release hardware semaphore used to access the PHY or NVM
  960. **/
  961. void igb_put_hw_semaphore(struct e1000_hw *hw)
  962. {
  963. u32 swsm;
  964. swsm = rd32(E1000_SWSM);
  965. swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
  966. wr32(E1000_SWSM, swsm);
  967. }
  968. /**
  969. * igb_get_auto_rd_done - Check for auto read completion
  970. * @hw: pointer to the HW structure
  971. *
  972. * Check EEPROM for Auto Read done bit.
  973. **/
  974. s32 igb_get_auto_rd_done(struct e1000_hw *hw)
  975. {
  976. s32 i = 0;
  977. s32 ret_val = 0;
  978. while (i < AUTO_READ_DONE_TIMEOUT) {
  979. if (rd32(E1000_EECD) & E1000_EECD_AUTO_RD)
  980. break;
  981. msleep(1);
  982. i++;
  983. }
  984. if (i == AUTO_READ_DONE_TIMEOUT) {
  985. hw_dbg("Auto read by HW from NVM has not completed.\n");
  986. ret_val = -E1000_ERR_RESET;
  987. goto out;
  988. }
  989. out:
  990. return ret_val;
  991. }
  992. /**
  993. * igb_valid_led_default - Verify a valid default LED config
  994. * @hw: pointer to the HW structure
  995. * @data: pointer to the NVM (EEPROM)
  996. *
  997. * Read the EEPROM for the current default LED configuration. If the
  998. * LED configuration is not valid, set to a valid LED configuration.
  999. **/
  1000. static s32 igb_valid_led_default(struct e1000_hw *hw, u16 *data)
  1001. {
  1002. s32 ret_val;
  1003. ret_val = hw->nvm.ops.read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
  1004. if (ret_val) {
  1005. hw_dbg("NVM Read Error\n");
  1006. goto out;
  1007. }
  1008. if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF)
  1009. *data = ID_LED_DEFAULT;
  1010. out:
  1011. return ret_val;
  1012. }
  1013. /**
  1014. * igb_id_led_init -
  1015. * @hw: pointer to the HW structure
  1016. *
  1017. **/
  1018. s32 igb_id_led_init(struct e1000_hw *hw)
  1019. {
  1020. struct e1000_mac_info *mac = &hw->mac;
  1021. s32 ret_val;
  1022. const u32 ledctl_mask = 0x000000FF;
  1023. const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
  1024. const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
  1025. u16 data, i, temp;
  1026. const u16 led_mask = 0x0F;
  1027. ret_val = igb_valid_led_default(hw, &data);
  1028. if (ret_val)
  1029. goto out;
  1030. mac->ledctl_default = rd32(E1000_LEDCTL);
  1031. mac->ledctl_mode1 = mac->ledctl_default;
  1032. mac->ledctl_mode2 = mac->ledctl_default;
  1033. for (i = 0; i < 4; i++) {
  1034. temp = (data >> (i << 2)) & led_mask;
  1035. switch (temp) {
  1036. case ID_LED_ON1_DEF2:
  1037. case ID_LED_ON1_ON2:
  1038. case ID_LED_ON1_OFF2:
  1039. mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
  1040. mac->ledctl_mode1 |= ledctl_on << (i << 3);
  1041. break;
  1042. case ID_LED_OFF1_DEF2:
  1043. case ID_LED_OFF1_ON2:
  1044. case ID_LED_OFF1_OFF2:
  1045. mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
  1046. mac->ledctl_mode1 |= ledctl_off << (i << 3);
  1047. break;
  1048. default:
  1049. /* Do nothing */
  1050. break;
  1051. }
  1052. switch (temp) {
  1053. case ID_LED_DEF1_ON2:
  1054. case ID_LED_ON1_ON2:
  1055. case ID_LED_OFF1_ON2:
  1056. mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
  1057. mac->ledctl_mode2 |= ledctl_on << (i << 3);
  1058. break;
  1059. case ID_LED_DEF1_OFF2:
  1060. case ID_LED_ON1_OFF2:
  1061. case ID_LED_OFF1_OFF2:
  1062. mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
  1063. mac->ledctl_mode2 |= ledctl_off << (i << 3);
  1064. break;
  1065. default:
  1066. /* Do nothing */
  1067. break;
  1068. }
  1069. }
  1070. out:
  1071. return ret_val;
  1072. }
  1073. /**
  1074. * igb_cleanup_led - Set LED config to default operation
  1075. * @hw: pointer to the HW structure
  1076. *
  1077. * Remove the current LED configuration and set the LED configuration
  1078. * to the default value, saved from the EEPROM.
  1079. **/
  1080. s32 igb_cleanup_led(struct e1000_hw *hw)
  1081. {
  1082. wr32(E1000_LEDCTL, hw->mac.ledctl_default);
  1083. return 0;
  1084. }
  1085. /**
  1086. * igb_blink_led - Blink LED
  1087. * @hw: pointer to the HW structure
  1088. *
  1089. * Blink the led's which are set to be on.
  1090. **/
  1091. s32 igb_blink_led(struct e1000_hw *hw)
  1092. {
  1093. u32 ledctl_blink = 0;
  1094. u32 i;
  1095. if (hw->phy.media_type == e1000_media_type_fiber) {
  1096. /* always blink LED0 for PCI-E fiber */
  1097. ledctl_blink = E1000_LEDCTL_LED0_BLINK |
  1098. (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
  1099. } else {
  1100. /*
  1101. * set the blink bit for each LED that's "on" (0x0E)
  1102. * in ledctl_mode2
  1103. */
  1104. ledctl_blink = hw->mac.ledctl_mode2;
  1105. for (i = 0; i < 4; i++)
  1106. if (((hw->mac.ledctl_mode2 >> (i * 8)) & 0xFF) ==
  1107. E1000_LEDCTL_MODE_LED_ON)
  1108. ledctl_blink |= (E1000_LEDCTL_LED0_BLINK <<
  1109. (i * 8));
  1110. }
  1111. wr32(E1000_LEDCTL, ledctl_blink);
  1112. return 0;
  1113. }
  1114. /**
  1115. * igb_led_off - Turn LED off
  1116. * @hw: pointer to the HW structure
  1117. *
  1118. * Turn LED off.
  1119. **/
  1120. s32 igb_led_off(struct e1000_hw *hw)
  1121. {
  1122. u32 ctrl;
  1123. switch (hw->phy.media_type) {
  1124. case e1000_media_type_fiber:
  1125. ctrl = rd32(E1000_CTRL);
  1126. ctrl |= E1000_CTRL_SWDPIN0;
  1127. ctrl |= E1000_CTRL_SWDPIO0;
  1128. wr32(E1000_CTRL, ctrl);
  1129. break;
  1130. case e1000_media_type_copper:
  1131. wr32(E1000_LEDCTL, hw->mac.ledctl_mode1);
  1132. break;
  1133. default:
  1134. break;
  1135. }
  1136. return 0;
  1137. }
  1138. /**
  1139. * igb_disable_pcie_master - Disables PCI-express master access
  1140. * @hw: pointer to the HW structure
  1141. *
  1142. * Returns 0 (0) if successful, else returns -10
  1143. * (-E1000_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not casued
  1144. * the master requests to be disabled.
  1145. *
  1146. * Disables PCI-Express master access and verifies there are no pending
  1147. * requests.
  1148. **/
  1149. s32 igb_disable_pcie_master(struct e1000_hw *hw)
  1150. {
  1151. u32 ctrl;
  1152. s32 timeout = MASTER_DISABLE_TIMEOUT;
  1153. s32 ret_val = 0;
  1154. if (hw->bus.type != e1000_bus_type_pci_express)
  1155. goto out;
  1156. ctrl = rd32(E1000_CTRL);
  1157. ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
  1158. wr32(E1000_CTRL, ctrl);
  1159. while (timeout) {
  1160. if (!(rd32(E1000_STATUS) &
  1161. E1000_STATUS_GIO_MASTER_ENABLE))
  1162. break;
  1163. udelay(100);
  1164. timeout--;
  1165. }
  1166. if (!timeout) {
  1167. hw_dbg("Master requests are pending.\n");
  1168. ret_val = -E1000_ERR_MASTER_REQUESTS_PENDING;
  1169. goto out;
  1170. }
  1171. out:
  1172. return ret_val;
  1173. }
  1174. /**
  1175. * igb_reset_adaptive - Reset Adaptive Interframe Spacing
  1176. * @hw: pointer to the HW structure
  1177. *
  1178. * Reset the Adaptive Interframe Spacing throttle to default values.
  1179. **/
  1180. void igb_reset_adaptive(struct e1000_hw *hw)
  1181. {
  1182. struct e1000_mac_info *mac = &hw->mac;
  1183. if (!mac->adaptive_ifs) {
  1184. hw_dbg("Not in Adaptive IFS mode!\n");
  1185. goto out;
  1186. }
  1187. if (!mac->ifs_params_forced) {
  1188. mac->current_ifs_val = 0;
  1189. mac->ifs_min_val = IFS_MIN;
  1190. mac->ifs_max_val = IFS_MAX;
  1191. mac->ifs_step_size = IFS_STEP;
  1192. mac->ifs_ratio = IFS_RATIO;
  1193. }
  1194. mac->in_ifs_mode = false;
  1195. wr32(E1000_AIT, 0);
  1196. out:
  1197. return;
  1198. }
  1199. /**
  1200. * igb_update_adaptive - Update Adaptive Interframe Spacing
  1201. * @hw: pointer to the HW structure
  1202. *
  1203. * Update the Adaptive Interframe Spacing Throttle value based on the
  1204. * time between transmitted packets and time between collisions.
  1205. **/
  1206. void igb_update_adaptive(struct e1000_hw *hw)
  1207. {
  1208. struct e1000_mac_info *mac = &hw->mac;
  1209. if (!mac->adaptive_ifs) {
  1210. hw_dbg("Not in Adaptive IFS mode!\n");
  1211. goto out;
  1212. }
  1213. if ((mac->collision_delta * mac->ifs_ratio) > mac->tx_packet_delta) {
  1214. if (mac->tx_packet_delta > MIN_NUM_XMITS) {
  1215. mac->in_ifs_mode = true;
  1216. if (mac->current_ifs_val < mac->ifs_max_val) {
  1217. if (!mac->current_ifs_val)
  1218. mac->current_ifs_val = mac->ifs_min_val;
  1219. else
  1220. mac->current_ifs_val +=
  1221. mac->ifs_step_size;
  1222. wr32(E1000_AIT,
  1223. mac->current_ifs_val);
  1224. }
  1225. }
  1226. } else {
  1227. if (mac->in_ifs_mode &&
  1228. (mac->tx_packet_delta <= MIN_NUM_XMITS)) {
  1229. mac->current_ifs_val = 0;
  1230. mac->in_ifs_mode = false;
  1231. wr32(E1000_AIT, 0);
  1232. }
  1233. }
  1234. out:
  1235. return;
  1236. }
  1237. /**
  1238. * igb_validate_mdi_setting - Verify MDI/MDIx settings
  1239. * @hw: pointer to the HW structure
  1240. *
  1241. * Verify that when not using auto-negotitation that MDI/MDIx is correctly
  1242. * set, which is forced to MDI mode only.
  1243. **/
  1244. s32 igb_validate_mdi_setting(struct e1000_hw *hw)
  1245. {
  1246. s32 ret_val = 0;
  1247. if (!hw->mac.autoneg && (hw->phy.mdix == 0 || hw->phy.mdix == 3)) {
  1248. hw_dbg("Invalid MDI setting detected\n");
  1249. hw->phy.mdix = 1;
  1250. ret_val = -E1000_ERR_CONFIG;
  1251. goto out;
  1252. }
  1253. out:
  1254. return ret_val;
  1255. }
  1256. /**
  1257. * igb_write_8bit_ctrl_reg - Write a 8bit CTRL register
  1258. * @hw: pointer to the HW structure
  1259. * @reg: 32bit register offset such as E1000_SCTL
  1260. * @offset: register offset to write to
  1261. * @data: data to write at register offset
  1262. *
  1263. * Writes an address/data control type register. There are several of these
  1264. * and they all have the format address << 8 | data and bit 31 is polled for
  1265. * completion.
  1266. **/
  1267. s32 igb_write_8bit_ctrl_reg(struct e1000_hw *hw, u32 reg,
  1268. u32 offset, u8 data)
  1269. {
  1270. u32 i, regvalue = 0;
  1271. s32 ret_val = 0;
  1272. /* Set up the address and data */
  1273. regvalue = ((u32)data) | (offset << E1000_GEN_CTL_ADDRESS_SHIFT);
  1274. wr32(reg, regvalue);
  1275. /* Poll the ready bit to see if the MDI read completed */
  1276. for (i = 0; i < E1000_GEN_POLL_TIMEOUT; i++) {
  1277. udelay(5);
  1278. regvalue = rd32(reg);
  1279. if (regvalue & E1000_GEN_CTL_READY)
  1280. break;
  1281. }
  1282. if (!(regvalue & E1000_GEN_CTL_READY)) {
  1283. hw_dbg("Reg %08x did not indicate ready\n", reg);
  1284. ret_val = -E1000_ERR_PHY;
  1285. goto out;
  1286. }
  1287. out:
  1288. return ret_val;
  1289. }
  1290. /**
  1291. * igb_enable_mng_pass_thru - Enable processing of ARP's
  1292. * @hw: pointer to the HW structure
  1293. *
  1294. * Verifies the hardware needs to allow ARPs to be processed by the host.
  1295. **/
  1296. bool igb_enable_mng_pass_thru(struct e1000_hw *hw)
  1297. {
  1298. u32 manc;
  1299. u32 fwsm, factps;
  1300. bool ret_val = false;
  1301. if (!hw->mac.asf_firmware_present)
  1302. goto out;
  1303. manc = rd32(E1000_MANC);
  1304. if (!(manc & E1000_MANC_RCV_TCO_EN) ||
  1305. !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
  1306. goto out;
  1307. if (hw->mac.arc_subsystem_valid) {
  1308. fwsm = rd32(E1000_FWSM);
  1309. factps = rd32(E1000_FACTPS);
  1310. if (!(factps & E1000_FACTPS_MNGCG) &&
  1311. ((fwsm & E1000_FWSM_MODE_MASK) ==
  1312. (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT))) {
  1313. ret_val = true;
  1314. goto out;
  1315. }
  1316. } else {
  1317. if ((manc & E1000_MANC_SMBUS_EN) &&
  1318. !(manc & E1000_MANC_ASF_EN)) {
  1319. ret_val = true;
  1320. goto out;
  1321. }
  1322. }
  1323. out:
  1324. return ret_val;
  1325. }