選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

e1000_82543.c 47KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635
  1. /*******************************************************************************
  2. Intel PRO/1000 Linux driver
  3. Copyright(c) 1999 - 2008 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. Linux NICS <linux.nics@intel.com>
  18. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. *******************************************************************************/
  21. FILE_LICENCE ( GPL2_OR_LATER );
  22. /*
  23. * 82543GC Gigabit Ethernet Controller (Fiber)
  24. * 82543GC Gigabit Ethernet Controller (Copper)
  25. * 82544EI Gigabit Ethernet Controller (Copper)
  26. * 82544EI Gigabit Ethernet Controller (Fiber)
  27. * 82544GC Gigabit Ethernet Controller (Copper)
  28. * 82544GC Gigabit Ethernet Controller (LOM)
  29. */
  30. #include "e1000_api.h"
  31. static s32 e1000_init_phy_params_82543(struct e1000_hw *hw);
  32. static s32 e1000_init_nvm_params_82543(struct e1000_hw *hw);
  33. static s32 e1000_init_mac_params_82543(struct e1000_hw *hw);
  34. static s32 e1000_read_phy_reg_82543(struct e1000_hw *hw, u32 offset,
  35. u16 *data);
  36. static s32 e1000_write_phy_reg_82543(struct e1000_hw *hw, u32 offset,
  37. u16 data);
  38. #if 0
  39. static s32 e1000_phy_force_speed_duplex_82543(struct e1000_hw *hw);
  40. #endif
  41. static s32 e1000_phy_hw_reset_82543(struct e1000_hw *hw);
  42. static s32 e1000_reset_hw_82543(struct e1000_hw *hw);
  43. static s32 e1000_init_hw_82543(struct e1000_hw *hw);
  44. static s32 e1000_setup_link_82543(struct e1000_hw *hw);
  45. static s32 e1000_setup_copper_link_82543(struct e1000_hw *hw);
  46. static s32 e1000_setup_fiber_link_82543(struct e1000_hw *hw);
  47. static s32 e1000_check_for_copper_link_82543(struct e1000_hw *hw);
  48. static s32 e1000_check_for_fiber_link_82543(struct e1000_hw *hw);
  49. static s32 e1000_led_on_82543(struct e1000_hw *hw);
  50. static s32 e1000_led_off_82543(struct e1000_hw *hw);
  51. static void e1000_write_vfta_82543(struct e1000_hw *hw, u32 offset,
  52. u32 value);
  53. static void e1000_mta_set_82543(struct e1000_hw *hw, u32 hash_value);
  54. static void e1000_clear_hw_cntrs_82543(struct e1000_hw *hw);
  55. static s32 e1000_config_mac_to_phy_82543(struct e1000_hw *hw);
  56. static bool e1000_init_phy_disabled_82543(struct e1000_hw *hw);
  57. static void e1000_lower_mdi_clk_82543(struct e1000_hw *hw, u32 *ctrl);
  58. static s32 e1000_polarity_reversal_workaround_82543(struct e1000_hw *hw);
  59. static void e1000_raise_mdi_clk_82543(struct e1000_hw *hw, u32 *ctrl);
  60. static u16 e1000_shift_in_mdi_bits_82543(struct e1000_hw *hw);
  61. static void e1000_shift_out_mdi_bits_82543(struct e1000_hw *hw, u32 data,
  62. u16 count);
  63. static bool e1000_tbi_compatibility_enabled_82543(struct e1000_hw *hw);
  64. static void e1000_set_tbi_compatibility_82543(struct e1000_hw *hw, bool state);
  65. static void e1000_set_tbi_sbp_82543(struct e1000_hw *hw, bool state);
  66. /**
  67. * e1000_init_phy_params_82543 - Init PHY func ptrs.
  68. * @hw: pointer to the HW structure
  69. **/
  70. static s32 e1000_init_phy_params_82543(struct e1000_hw *hw)
  71. {
  72. struct e1000_phy_info *phy = &hw->phy;
  73. s32 ret_val = E1000_SUCCESS;
  74. DEBUGFUNC("e1000_init_phy_params_82543");
  75. if (hw->phy.media_type != e1000_media_type_copper) {
  76. phy->type = e1000_phy_none;
  77. goto out;
  78. } else {
  79. phy->ops.power_up = e1000_power_up_phy_copper;
  80. phy->ops.power_down = e1000_power_down_phy_copper;
  81. }
  82. phy->addr = 1;
  83. phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  84. phy->reset_delay_us = 10000;
  85. phy->type = e1000_phy_m88;
  86. /* Function Pointers */
  87. phy->ops.check_polarity = e1000_check_polarity_m88;
  88. phy->ops.commit = e1000_phy_sw_reset_generic;
  89. #if 0
  90. phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_82543;
  91. #endif
  92. #if 0
  93. phy->ops.get_cable_length = e1000_get_cable_length_m88;
  94. #endif
  95. phy->ops.get_cfg_done = e1000_get_cfg_done_generic;
  96. phy->ops.read_reg = (hw->mac.type == e1000_82543)
  97. ? e1000_read_phy_reg_82543
  98. : e1000_read_phy_reg_m88;
  99. phy->ops.reset = (hw->mac.type == e1000_82543)
  100. ? e1000_phy_hw_reset_82543
  101. : e1000_phy_hw_reset_generic;
  102. phy->ops.write_reg = (hw->mac.type == e1000_82543)
  103. ? e1000_write_phy_reg_82543
  104. : e1000_write_phy_reg_m88;
  105. phy->ops.get_info = e1000_get_phy_info_m88;
  106. /*
  107. * The external PHY of the 82543 can be in a funky state.
  108. * Resetting helps us read the PHY registers for acquiring
  109. * the PHY ID.
  110. */
  111. if (!e1000_init_phy_disabled_82543(hw)) {
  112. ret_val = phy->ops.reset(hw);
  113. if (ret_val) {
  114. DEBUGOUT("Resetting PHY during init failed.\n");
  115. goto out;
  116. }
  117. msec_delay(20);
  118. }
  119. ret_val = e1000_get_phy_id(hw);
  120. if (ret_val)
  121. goto out;
  122. /* Verify phy id */
  123. switch (hw->mac.type) {
  124. case e1000_82543:
  125. if (phy->id != M88E1000_E_PHY_ID) {
  126. ret_val = -E1000_ERR_PHY;
  127. goto out;
  128. }
  129. break;
  130. case e1000_82544:
  131. if (phy->id != M88E1000_I_PHY_ID) {
  132. ret_val = -E1000_ERR_PHY;
  133. goto out;
  134. }
  135. break;
  136. default:
  137. ret_val = -E1000_ERR_PHY;
  138. goto out;
  139. break;
  140. }
  141. out:
  142. return ret_val;
  143. }
  144. /**
  145. * e1000_init_nvm_params_82543 - Init NVM func ptrs.
  146. * @hw: pointer to the HW structure
  147. **/
  148. static s32 e1000_init_nvm_params_82543(struct e1000_hw *hw)
  149. {
  150. struct e1000_nvm_info *nvm = &hw->nvm;
  151. DEBUGFUNC("e1000_init_nvm_params_82543");
  152. nvm->type = e1000_nvm_eeprom_microwire;
  153. nvm->word_size = 64;
  154. nvm->delay_usec = 50;
  155. nvm->address_bits = 6;
  156. nvm->opcode_bits = 3;
  157. /* Function Pointers */
  158. nvm->ops.read = e1000_read_nvm_microwire;
  159. nvm->ops.update = e1000_update_nvm_checksum_generic;
  160. nvm->ops.valid_led_default = e1000_valid_led_default_generic;
  161. nvm->ops.validate = e1000_validate_nvm_checksum_generic;
  162. nvm->ops.write = e1000_write_nvm_microwire;
  163. return E1000_SUCCESS;
  164. }
  165. /**
  166. * e1000_init_mac_params_82543 - Init MAC func ptrs.
  167. * @hw: pointer to the HW structure
  168. **/
  169. static s32 e1000_init_mac_params_82543(struct e1000_hw *hw)
  170. {
  171. struct e1000_mac_info *mac = &hw->mac;
  172. DEBUGFUNC("e1000_init_mac_params_82543");
  173. /* Set media type */
  174. switch (hw->device_id) {
  175. case E1000_DEV_ID_82543GC_FIBER:
  176. case E1000_DEV_ID_82544EI_FIBER:
  177. hw->phy.media_type = e1000_media_type_fiber;
  178. break;
  179. default:
  180. hw->phy.media_type = e1000_media_type_copper;
  181. break;
  182. }
  183. /* Set mta register count */
  184. mac->mta_reg_count = 128;
  185. /* Set rar entry count */
  186. mac->rar_entry_count = E1000_RAR_ENTRIES;
  187. /* Function pointers */
  188. /* bus type/speed/width */
  189. mac->ops.get_bus_info = e1000_get_bus_info_pci_generic;
  190. /* function id */
  191. mac->ops.set_lan_id = e1000_set_lan_id_multi_port_pci;
  192. /* reset */
  193. mac->ops.reset_hw = e1000_reset_hw_82543;
  194. /* hw initialization */
  195. mac->ops.init_hw = e1000_init_hw_82543;
  196. /* link setup */
  197. mac->ops.setup_link = e1000_setup_link_82543;
  198. /* physical interface setup */
  199. mac->ops.setup_physical_interface =
  200. (hw->phy.media_type == e1000_media_type_copper)
  201. ? e1000_setup_copper_link_82543
  202. : e1000_setup_fiber_link_82543;
  203. /* check for link */
  204. mac->ops.check_for_link =
  205. (hw->phy.media_type == e1000_media_type_copper)
  206. ? e1000_check_for_copper_link_82543
  207. : e1000_check_for_fiber_link_82543;
  208. /* link info */
  209. mac->ops.get_link_up_info =
  210. (hw->phy.media_type == e1000_media_type_copper)
  211. ? e1000_get_speed_and_duplex_copper_generic
  212. : e1000_get_speed_and_duplex_fiber_serdes_generic;
  213. /* multicast address update */
  214. mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_generic;
  215. /* writing VFTA */
  216. mac->ops.write_vfta = e1000_write_vfta_82543;
  217. /* clearing VFTA */
  218. mac->ops.clear_vfta = e1000_clear_vfta_generic;
  219. /* setting MTA */
  220. mac->ops.mta_set = e1000_mta_set_82543;
  221. /* turn on/off LED */
  222. mac->ops.led_on = e1000_led_on_82543;
  223. mac->ops.led_off = e1000_led_off_82543;
  224. /* clear hardware counters */
  225. mac->ops.clear_hw_cntrs = e1000_clear_hw_cntrs_82543;
  226. /* Set tbi compatibility */
  227. if ((hw->mac.type != e1000_82543) ||
  228. (hw->phy.media_type == e1000_media_type_fiber))
  229. e1000_set_tbi_compatibility_82543(hw, false);
  230. return E1000_SUCCESS;
  231. }
  232. /**
  233. * e1000_init_function_pointers_82543 - Init func ptrs.
  234. * @hw: pointer to the HW structure
  235. *
  236. * Called to initialize all function pointers and parameters.
  237. **/
  238. void e1000_init_function_pointers_82543(struct e1000_hw *hw)
  239. {
  240. DEBUGFUNC("e1000_init_function_pointers_82543");
  241. hw->mac.ops.init_params = e1000_init_mac_params_82543;
  242. hw->nvm.ops.init_params = e1000_init_nvm_params_82543;
  243. hw->phy.ops.init_params = e1000_init_phy_params_82543;
  244. }
  245. /**
  246. * e1000_tbi_compatibility_enabled_82543 - Returns TBI compat status
  247. * @hw: pointer to the HW structure
  248. *
  249. * Returns the current status of 10-bit Interface (TBI) compatibility
  250. * (enabled/disabled).
  251. **/
  252. static bool e1000_tbi_compatibility_enabled_82543(struct e1000_hw *hw)
  253. {
  254. struct e1000_dev_spec_82543 *dev_spec = &hw->dev_spec._82543;
  255. bool state = false;
  256. DEBUGFUNC("e1000_tbi_compatibility_enabled_82543");
  257. if (hw->mac.type != e1000_82543) {
  258. DEBUGOUT("TBI compatibility workaround for 82543 only.\n");
  259. goto out;
  260. }
  261. state = (dev_spec->tbi_compatibility & TBI_COMPAT_ENABLED)
  262. ? true : false;
  263. out:
  264. return state;
  265. }
  266. /**
  267. * e1000_set_tbi_compatibility_82543 - Set TBI compatibility
  268. * @hw: pointer to the HW structure
  269. * @state: enable/disable TBI compatibility
  270. *
  271. * Enables or disabled 10-bit Interface (TBI) compatibility.
  272. **/
  273. static void e1000_set_tbi_compatibility_82543(struct e1000_hw *hw, bool state)
  274. {
  275. struct e1000_dev_spec_82543 *dev_spec = &hw->dev_spec._82543;
  276. DEBUGFUNC("e1000_set_tbi_compatibility_82543");
  277. if (hw->mac.type != e1000_82543) {
  278. DEBUGOUT("TBI compatibility workaround for 82543 only.\n");
  279. goto out;
  280. }
  281. if (state)
  282. dev_spec->tbi_compatibility |= TBI_COMPAT_ENABLED;
  283. else
  284. dev_spec->tbi_compatibility &= ~TBI_COMPAT_ENABLED;
  285. out:
  286. return;
  287. }
  288. /**
  289. * e1000_tbi_sbp_enabled_82543 - Returns TBI SBP status
  290. * @hw: pointer to the HW structure
  291. *
  292. * Returns the current status of 10-bit Interface (TBI) store bad packet (SBP)
  293. * (enabled/disabled).
  294. **/
  295. bool e1000_tbi_sbp_enabled_82543(struct e1000_hw *hw)
  296. {
  297. struct e1000_dev_spec_82543 *dev_spec = &hw->dev_spec._82543;
  298. bool state = false;
  299. DEBUGFUNC("e1000_tbi_sbp_enabled_82543");
  300. if (hw->mac.type != e1000_82543) {
  301. DEBUGOUT("TBI compatibility workaround for 82543 only.\n");
  302. goto out;
  303. }
  304. state = (dev_spec->tbi_compatibility & TBI_SBP_ENABLED)
  305. ? true : false;
  306. out:
  307. return state;
  308. }
  309. /**
  310. * e1000_set_tbi_sbp_82543 - Set TBI SBP
  311. * @hw: pointer to the HW structure
  312. * @state: enable/disable TBI store bad packet
  313. *
  314. * Enables or disabled 10-bit Interface (TBI) store bad packet (SBP).
  315. **/
  316. static void e1000_set_tbi_sbp_82543(struct e1000_hw *hw, bool state)
  317. {
  318. struct e1000_dev_spec_82543 *dev_spec = &hw->dev_spec._82543;
  319. DEBUGFUNC("e1000_set_tbi_sbp_82543");
  320. if (state && e1000_tbi_compatibility_enabled_82543(hw))
  321. dev_spec->tbi_compatibility |= TBI_SBP_ENABLED;
  322. else
  323. dev_spec->tbi_compatibility &= ~TBI_SBP_ENABLED;
  324. return;
  325. }
  326. /**
  327. * e1000_init_phy_disabled_82543 - Returns init PHY status
  328. * @hw: pointer to the HW structure
  329. *
  330. * Returns the current status of whether PHY initialization is disabled.
  331. * True if PHY initialization is disabled else false.
  332. **/
  333. static bool e1000_init_phy_disabled_82543(struct e1000_hw *hw)
  334. {
  335. struct e1000_dev_spec_82543 *dev_spec = &hw->dev_spec._82543;
  336. bool ret_val;
  337. DEBUGFUNC("e1000_init_phy_disabled_82543");
  338. if (hw->mac.type != e1000_82543) {
  339. ret_val = false;
  340. goto out;
  341. }
  342. ret_val = dev_spec->init_phy_disabled;
  343. out:
  344. return ret_val;
  345. }
  346. #if 0
  347. /**
  348. * e1000_tbi_adjust_stats_82543 - Adjust stats when TBI enabled
  349. * @hw: pointer to the HW structure
  350. * @stats: Struct containing statistic register values
  351. * @frame_len: The length of the frame in question
  352. * @mac_addr: The Ethernet destination address of the frame in question
  353. * @max_frame_size: The maximum frame size
  354. *
  355. * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
  356. **/
  357. void e1000_tbi_adjust_stats_82543(struct e1000_hw *hw,
  358. struct e1000_hw_stats *stats, u32 frame_len,
  359. u8 *mac_addr, u32 max_frame_size)
  360. {
  361. if (!(e1000_tbi_sbp_enabled_82543(hw)))
  362. goto out;
  363. /* First adjust the frame length. */
  364. frame_len--;
  365. /*
  366. * We need to adjust the statistics counters, since the hardware
  367. * counters overcount this packet as a CRC error and undercount
  368. * the packet as a good packet
  369. */
  370. /* This packet should not be counted as a CRC error. */
  371. stats->crcerrs--;
  372. /* This packet does count as a Good Packet Received. */
  373. stats->gprc++;
  374. /* Adjust the Good Octets received counters */
  375. stats->gorc += frame_len;
  376. /*
  377. * Is this a broadcast or multicast? Check broadcast first,
  378. * since the test for a multicast frame will test positive on
  379. * a broadcast frame.
  380. */
  381. if ((mac_addr[0] == 0xff) && (mac_addr[1] == 0xff))
  382. /* Broadcast packet */
  383. stats->bprc++;
  384. else if (*mac_addr & 0x01)
  385. /* Multicast packet */
  386. stats->mprc++;
  387. /*
  388. * In this case, the hardware has overcounted the number of
  389. * oversize frames.
  390. */
  391. if ((frame_len == max_frame_size) && (stats->roc > 0))
  392. stats->roc--;
  393. /*
  394. * Adjust the bin counters when the extra byte put the frame in the
  395. * wrong bin. Remember that the frame_len was adjusted above.
  396. */
  397. if (frame_len == 64) {
  398. stats->prc64++;
  399. stats->prc127--;
  400. } else if (frame_len == 127) {
  401. stats->prc127++;
  402. stats->prc255--;
  403. } else if (frame_len == 255) {
  404. stats->prc255++;
  405. stats->prc511--;
  406. } else if (frame_len == 511) {
  407. stats->prc511++;
  408. stats->prc1023--;
  409. } else if (frame_len == 1023) {
  410. stats->prc1023++;
  411. stats->prc1522--;
  412. } else if (frame_len == 1522) {
  413. stats->prc1522++;
  414. }
  415. out:
  416. return;
  417. }
  418. #endif
  419. /**
  420. * e1000_read_phy_reg_82543 - Read PHY register
  421. * @hw: pointer to the HW structure
  422. * @offset: register offset to be read
  423. * @data: pointer to the read data
  424. *
  425. * Reads the PHY at offset and stores the information read to data.
  426. **/
  427. static s32 e1000_read_phy_reg_82543(struct e1000_hw *hw, u32 offset, u16 *data)
  428. {
  429. u32 mdic;
  430. s32 ret_val = E1000_SUCCESS;
  431. DEBUGFUNC("e1000_read_phy_reg_82543");
  432. if (offset > MAX_PHY_REG_ADDRESS) {
  433. DEBUGOUT1("PHY Address %d is out of range\n", offset);
  434. ret_val = -E1000_ERR_PARAM;
  435. goto out;
  436. }
  437. /*
  438. * We must first send a preamble through the MDIO pin to signal the
  439. * beginning of an MII instruction. This is done by sending 32
  440. * consecutive "1" bits.
  441. */
  442. e1000_shift_out_mdi_bits_82543(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
  443. /*
  444. * Now combine the next few fields that are required for a read
  445. * operation. We use this method instead of calling the
  446. * e1000_shift_out_mdi_bits routine five different times. The format
  447. * of an MII read instruction consists of a shift out of 14 bits and
  448. * is defined as follows:
  449. * <Preamble><SOF><Op Code><Phy Addr><Offset>
  450. * followed by a shift in of 18 bits. This first two bits shifted in
  451. * are TurnAround bits used to avoid contention on the MDIO pin when a
  452. * READ operation is performed. These two bits are thrown away
  453. * followed by a shift in of 16 bits which contains the desired data.
  454. */
  455. mdic = (offset | (hw->phy.addr << 5) |
  456. (PHY_OP_READ << 10) | (PHY_SOF << 12));
  457. e1000_shift_out_mdi_bits_82543(hw, mdic, 14);
  458. /*
  459. * Now that we've shifted out the read command to the MII, we need to
  460. * "shift in" the 16-bit value (18 total bits) of the requested PHY
  461. * register address.
  462. */
  463. *data = e1000_shift_in_mdi_bits_82543(hw);
  464. out:
  465. return ret_val;
  466. }
  467. /**
  468. * e1000_write_phy_reg_82543 - Write PHY register
  469. * @hw: pointer to the HW structure
  470. * @offset: register offset to be written
  471. * @data: pointer to the data to be written at offset
  472. *
  473. * Writes data to the PHY at offset.
  474. **/
  475. static s32 e1000_write_phy_reg_82543(struct e1000_hw *hw, u32 offset, u16 data)
  476. {
  477. u32 mdic;
  478. s32 ret_val = E1000_SUCCESS;
  479. DEBUGFUNC("e1000_write_phy_reg_82543");
  480. if (offset > MAX_PHY_REG_ADDRESS) {
  481. DEBUGOUT1("PHY Address %d is out of range\n", offset);
  482. ret_val = -E1000_ERR_PARAM;
  483. goto out;
  484. }
  485. /*
  486. * We'll need to use the SW defined pins to shift the write command
  487. * out to the PHY. We first send a preamble to the PHY to signal the
  488. * beginning of the MII instruction. This is done by sending 32
  489. * consecutive "1" bits.
  490. */
  491. e1000_shift_out_mdi_bits_82543(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
  492. /*
  493. * Now combine the remaining required fields that will indicate a
  494. * write operation. We use this method instead of calling the
  495. * e1000_shift_out_mdi_bits routine for each field in the command. The
  496. * format of a MII write instruction is as follows:
  497. * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
  498. */
  499. mdic = ((PHY_TURNAROUND) | (offset << 2) | (hw->phy.addr << 7) |
  500. (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
  501. mdic <<= 16;
  502. mdic |= (u32) data;
  503. e1000_shift_out_mdi_bits_82543(hw, mdic, 32);
  504. out:
  505. return ret_val;
  506. }
  507. /**
  508. * e1000_raise_mdi_clk_82543 - Raise Management Data Input clock
  509. * @hw: pointer to the HW structure
  510. * @ctrl: pointer to the control register
  511. *
  512. * Raise the management data input clock by setting the MDC bit in the control
  513. * register.
  514. **/
  515. static void e1000_raise_mdi_clk_82543(struct e1000_hw *hw, u32 *ctrl)
  516. {
  517. /*
  518. * Raise the clock input to the Management Data Clock (by setting the
  519. * MDC bit), and then delay a sufficient amount of time.
  520. */
  521. E1000_WRITE_REG(hw, E1000_CTRL, (*ctrl | E1000_CTRL_MDC));
  522. E1000_WRITE_FLUSH(hw);
  523. usec_delay(10);
  524. }
  525. /**
  526. * e1000_lower_mdi_clk_82543 - Lower Management Data Input clock
  527. * @hw: pointer to the HW structure
  528. * @ctrl: pointer to the control register
  529. *
  530. * Lower the management data input clock by clearing the MDC bit in the
  531. * control register.
  532. **/
  533. static void e1000_lower_mdi_clk_82543(struct e1000_hw *hw, u32 *ctrl)
  534. {
  535. /*
  536. * Lower the clock input to the Management Data Clock (by clearing the
  537. * MDC bit), and then delay a sufficient amount of time.
  538. */
  539. E1000_WRITE_REG(hw, E1000_CTRL, (*ctrl & ~E1000_CTRL_MDC));
  540. E1000_WRITE_FLUSH(hw);
  541. usec_delay(10);
  542. }
  543. /**
  544. * e1000_shift_out_mdi_bits_82543 - Shift data bits our to the PHY
  545. * @hw: pointer to the HW structure
  546. * @data: data to send to the PHY
  547. * @count: number of bits to shift out
  548. *
  549. * We need to shift 'count' bits out to the PHY. So, the value in the
  550. * "data" parameter will be shifted out to the PHY one bit at a time.
  551. * In order to do this, "data" must be broken down into bits.
  552. **/
  553. static void e1000_shift_out_mdi_bits_82543(struct e1000_hw *hw, u32 data,
  554. u16 count)
  555. {
  556. u32 ctrl, mask;
  557. /*
  558. * We need to shift "count" number of bits out to the PHY. So, the
  559. * value in the "data" parameter will be shifted out to the PHY one
  560. * bit at a time. In order to do this, "data" must be broken down
  561. * into bits.
  562. */
  563. mask = 0x01;
  564. mask <<= (count -1);
  565. ctrl = E1000_READ_REG(hw, E1000_CTRL);
  566. /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
  567. ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
  568. while (mask) {
  569. /*
  570. * A "1" is shifted out to the PHY by setting the MDIO bit to
  571. * "1" and then raising and lowering the Management Data Clock.
  572. * A "0" is shifted out to the PHY by setting the MDIO bit to
  573. * "0" and then raising and lowering the clock.
  574. */
  575. if (data & mask) ctrl |= E1000_CTRL_MDIO;
  576. else ctrl &= ~E1000_CTRL_MDIO;
  577. E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
  578. E1000_WRITE_FLUSH(hw);
  579. usec_delay(10);
  580. e1000_raise_mdi_clk_82543(hw, &ctrl);
  581. e1000_lower_mdi_clk_82543(hw, &ctrl);
  582. mask >>= 1;
  583. }
  584. }
  585. /**
  586. * e1000_shift_in_mdi_bits_82543 - Shift data bits in from the PHY
  587. * @hw: pointer to the HW structure
  588. *
  589. * In order to read a register from the PHY, we need to shift 18 bits
  590. * in from the PHY. Bits are "shifted in" by raising the clock input to
  591. * the PHY (setting the MDC bit), and then reading the value of the data out
  592. * MDIO bit.
  593. **/
  594. static u16 e1000_shift_in_mdi_bits_82543(struct e1000_hw *hw)
  595. {
  596. u32 ctrl;
  597. u16 data = 0;
  598. u8 i;
  599. /*
  600. * In order to read a register from the PHY, we need to shift in a
  601. * total of 18 bits from the PHY. The first two bit (turnaround)
  602. * times are used to avoid contention on the MDIO pin when a read
  603. * operation is performed. These two bits are ignored by us and
  604. * thrown away. Bits are "shifted in" by raising the input to the
  605. * Management Data Clock (setting the MDC bit) and then reading the
  606. * value of the MDIO bit.
  607. */
  608. ctrl = E1000_READ_REG(hw, E1000_CTRL);
  609. /*
  610. * Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as
  611. * input.
  612. */
  613. ctrl &= ~E1000_CTRL_MDIO_DIR;
  614. ctrl &= ~E1000_CTRL_MDIO;
  615. E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
  616. E1000_WRITE_FLUSH(hw);
  617. /*
  618. * Raise and lower the clock before reading in the data. This accounts
  619. * for the turnaround bits. The first clock occurred when we clocked
  620. * out the last bit of the Register Address.
  621. */
  622. e1000_raise_mdi_clk_82543(hw, &ctrl);
  623. e1000_lower_mdi_clk_82543(hw, &ctrl);
  624. for (data = 0, i = 0; i < 16; i++) {
  625. data <<= 1;
  626. e1000_raise_mdi_clk_82543(hw, &ctrl);
  627. ctrl = E1000_READ_REG(hw, E1000_CTRL);
  628. /* Check to see if we shifted in a "1". */
  629. if (ctrl & E1000_CTRL_MDIO)
  630. data |= 1;
  631. e1000_lower_mdi_clk_82543(hw, &ctrl);
  632. }
  633. e1000_raise_mdi_clk_82543(hw, &ctrl);
  634. e1000_lower_mdi_clk_82543(hw, &ctrl);
  635. return data;
  636. }
  637. #if 0
  638. /**
  639. * e1000_phy_force_speed_duplex_82543 - Force speed/duplex for PHY
  640. * @hw: pointer to the HW structure
  641. *
  642. * Calls the function to force speed and duplex for the m88 PHY, and
  643. * if the PHY is not auto-negotiating and the speed is forced to 10Mbit,
  644. * then call the function for polarity reversal workaround.
  645. **/
  646. static s32 e1000_phy_force_speed_duplex_82543(struct e1000_hw *hw)
  647. {
  648. s32 ret_val;
  649. DEBUGFUNC("e1000_phy_force_speed_duplex_82543");
  650. ret_val = e1000_phy_force_speed_duplex_m88(hw);
  651. if (ret_val)
  652. goto out;
  653. if (!hw->mac.autoneg &&
  654. (hw->mac.forced_speed_duplex & E1000_ALL_10_SPEED))
  655. ret_val = e1000_polarity_reversal_workaround_82543(hw);
  656. out:
  657. return ret_val;
  658. }
  659. #endif
  660. /**
  661. * e1000_polarity_reversal_workaround_82543 - Workaround polarity reversal
  662. * @hw: pointer to the HW structure
  663. *
  664. * When forcing link to 10 Full or 10 Half, the PHY can reverse the polarity
  665. * inadvertently. To workaround the issue, we disable the transmitter on
  666. * the PHY until we have established the link partner's link parameters.
  667. **/
  668. static s32 e1000_polarity_reversal_workaround_82543(struct e1000_hw *hw)
  669. {
  670. s32 ret_val = E1000_SUCCESS;
  671. u16 mii_status_reg;
  672. u16 i;
  673. bool link;
  674. if (!(hw->phy.ops.write_reg))
  675. goto out;
  676. /* Polarity reversal workaround for forced 10F/10H links. */
  677. /* Disable the transmitter on the PHY */
  678. ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
  679. if (ret_val)
  680. goto out;
  681. ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
  682. if (ret_val)
  683. goto out;
  684. ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
  685. if (ret_val)
  686. goto out;
  687. /*
  688. * This loop will early-out if the NO link condition has been met.
  689. * In other words, DO NOT use e1000_phy_has_link_generic() here.
  690. */
  691. for (i = PHY_FORCE_TIME; i > 0; i--) {
  692. /*
  693. * Read the MII Status Register and wait for Link Status bit
  694. * to be clear.
  695. */
  696. ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &mii_status_reg);
  697. if (ret_val)
  698. goto out;
  699. ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &mii_status_reg);
  700. if (ret_val)
  701. goto out;
  702. if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0)
  703. break;
  704. msec_delay_irq(100);
  705. }
  706. /* Recommended delay time after link has been lost */
  707. msec_delay_irq(1000);
  708. /* Now we will re-enable the transmitter on the PHY */
  709. ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
  710. if (ret_val)
  711. goto out;
  712. msec_delay_irq(50);
  713. ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
  714. if (ret_val)
  715. goto out;
  716. msec_delay_irq(50);
  717. ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
  718. if (ret_val)
  719. goto out;
  720. msec_delay_irq(50);
  721. ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
  722. if (ret_val)
  723. goto out;
  724. ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
  725. if (ret_val)
  726. goto out;
  727. /*
  728. * Read the MII Status Register and wait for Link Status bit
  729. * to be set.
  730. */
  731. ret_val = e1000_phy_has_link_generic(hw, PHY_FORCE_TIME, 100000, &link);
  732. if (ret_val)
  733. goto out;
  734. out:
  735. return ret_val;
  736. }
  737. /**
  738. * e1000_phy_hw_reset_82543 - PHY hardware reset
  739. * @hw: pointer to the HW structure
  740. *
  741. * Sets the PHY_RESET_DIR bit in the extended device control register
  742. * to put the PHY into a reset and waits for completion. Once the reset
  743. * has been accomplished, clear the PHY_RESET_DIR bit to take the PHY out
  744. * of reset.
  745. **/
  746. static s32 e1000_phy_hw_reset_82543(struct e1000_hw *hw)
  747. {
  748. u32 ctrl_ext;
  749. s32 ret_val;
  750. DEBUGFUNC("e1000_phy_hw_reset_82543");
  751. /*
  752. * Read the Extended Device Control Register, assert the PHY_RESET_DIR
  753. * bit to put the PHY into reset...
  754. */
  755. ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
  756. ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
  757. ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
  758. E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
  759. E1000_WRITE_FLUSH(hw);
  760. msec_delay(10);
  761. /* ...then take it out of reset. */
  762. ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
  763. E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
  764. E1000_WRITE_FLUSH(hw);
  765. usec_delay(150);
  766. if (!(hw->phy.ops.get_cfg_done))
  767. return E1000_SUCCESS;
  768. ret_val = hw->phy.ops.get_cfg_done(hw);
  769. return ret_val;
  770. }
  771. /**
  772. * e1000_reset_hw_82543 - Reset hardware
  773. * @hw: pointer to the HW structure
  774. *
  775. * This resets the hardware into a known state.
  776. **/
  777. static s32 e1000_reset_hw_82543(struct e1000_hw *hw)
  778. {
  779. u32 ctrl;
  780. s32 ret_val = E1000_SUCCESS;
  781. DEBUGFUNC("e1000_reset_hw_82543");
  782. DEBUGOUT("Masking off all interrupts\n");
  783. E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
  784. E1000_WRITE_REG(hw, E1000_RCTL, 0);
  785. E1000_WRITE_REG(hw, E1000_TCTL, E1000_TCTL_PSP);
  786. E1000_WRITE_FLUSH(hw);
  787. e1000_set_tbi_sbp_82543(hw, false);
  788. /*
  789. * Delay to allow any outstanding PCI transactions to complete before
  790. * resetting the device
  791. */
  792. msec_delay(10);
  793. ctrl = E1000_READ_REG(hw, E1000_CTRL);
  794. DEBUGOUT("Issuing a global reset to 82543/82544 MAC\n");
  795. if (hw->mac.type == e1000_82543) {
  796. E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_RST);
  797. } else {
  798. /*
  799. * The 82544 can't ACK the 64-bit write when issuing the
  800. * reset, so use IO-mapping as a workaround.
  801. */
  802. E1000_WRITE_REG_IO(hw, E1000_CTRL, ctrl | E1000_CTRL_RST);
  803. }
  804. /*
  805. * After MAC reset, force reload of NVM to restore power-on
  806. * settings to device.
  807. */
  808. hw->nvm.ops.reload(hw);
  809. msec_delay(2);
  810. /* Masking off and clearing any pending interrupts */
  811. E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
  812. E1000_READ_REG(hw, E1000_ICR);
  813. return ret_val;
  814. }
  815. /**
  816. * e1000_init_hw_82543 - Initialize hardware
  817. * @hw: pointer to the HW structure
  818. *
  819. * This inits the hardware readying it for operation.
  820. **/
  821. static s32 e1000_init_hw_82543(struct e1000_hw *hw)
  822. {
  823. struct e1000_mac_info *mac = &hw->mac;
  824. struct e1000_dev_spec_82543 *dev_spec = &hw->dev_spec._82543;
  825. u32 ctrl;
  826. s32 ret_val;
  827. u16 i;
  828. DEBUGFUNC("e1000_init_hw_82543");
  829. /* Disabling VLAN filtering */
  830. E1000_WRITE_REG(hw, E1000_VET, 0);
  831. mac->ops.clear_vfta(hw);
  832. /* Setup the receive address. */
  833. e1000_init_rx_addrs_generic(hw, mac->rar_entry_count);
  834. /* Zero out the Multicast HASH table */
  835. DEBUGOUT("Zeroing the MTA\n");
  836. for (i = 0; i < mac->mta_reg_count; i++) {
  837. E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
  838. E1000_WRITE_FLUSH(hw);
  839. }
  840. /*
  841. * Set the PCI priority bit correctly in the CTRL register. This
  842. * determines if the adapter gives priority to receives, or if it
  843. * gives equal priority to transmits and receives.
  844. */
  845. if (hw->mac.type == e1000_82543 && dev_spec->dma_fairness) {
  846. ctrl = E1000_READ_REG(hw, E1000_CTRL);
  847. E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_PRIOR);
  848. }
  849. e1000_pcix_mmrbc_workaround_generic(hw);
  850. /* Setup link and flow control */
  851. ret_val = mac->ops.setup_link(hw);
  852. /*
  853. * Clear all of the statistics registers (clear on read). It is
  854. * important that we do this after we have tried to establish link
  855. * because the symbol error count will increment wildly if there
  856. * is no link.
  857. */
  858. e1000_clear_hw_cntrs_82543(hw);
  859. return ret_val;
  860. }
  861. /**
  862. * e1000_setup_link_82543 - Setup flow control and link settings
  863. * @hw: pointer to the HW structure
  864. *
  865. * Read the EEPROM to determine the initial polarity value and write the
  866. * extended device control register with the information before calling
  867. * the generic setup link function, which does the following:
  868. * Determines which flow control settings to use, then configures flow
  869. * control. Calls the appropriate media-specific link configuration
  870. * function. Assuming the adapter has a valid link partner, a valid link
  871. * should be established. Assumes the hardware has previously been reset
  872. * and the transmitter and receiver are not enabled.
  873. **/
  874. static s32 e1000_setup_link_82543(struct e1000_hw *hw)
  875. {
  876. u32 ctrl_ext;
  877. s32 ret_val;
  878. u16 data;
  879. DEBUGFUNC("e1000_setup_link_82543");
  880. /*
  881. * Take the 4 bits from NVM word 0xF that determine the initial
  882. * polarity value for the SW controlled pins, and setup the
  883. * Extended Device Control reg with that info.
  884. * This is needed because one of the SW controlled pins is used for
  885. * signal detection. So this should be done before phy setup.
  886. */
  887. if (hw->mac.type == e1000_82543) {
  888. ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL2_REG, 1, &data);
  889. if (ret_val) {
  890. DEBUGOUT("NVM Read Error\n");
  891. ret_val = -E1000_ERR_NVM;
  892. goto out;
  893. }
  894. ctrl_ext = ((data & NVM_WORD0F_SWPDIO_EXT_MASK) <<
  895. NVM_SWDPIO_EXT_SHIFT);
  896. E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
  897. }
  898. ret_val = e1000_setup_link_generic(hw);
  899. out:
  900. return ret_val;
  901. }
  902. /**
  903. * e1000_setup_copper_link_82543 - Configure copper link settings
  904. * @hw: pointer to the HW structure
  905. *
  906. * Configures the link for auto-neg or forced speed and duplex. Then we check
  907. * for link, once link is established calls to configure collision distance
  908. * and flow control are called.
  909. **/
  910. static s32 e1000_setup_copper_link_82543(struct e1000_hw *hw)
  911. {
  912. u32 ctrl;
  913. s32 ret_val;
  914. bool link;
  915. DEBUGFUNC("e1000_setup_copper_link_82543");
  916. ctrl = E1000_READ_REG(hw, E1000_CTRL) | E1000_CTRL_SLU;
  917. /*
  918. * With 82543, we need to force speed and duplex on the MAC
  919. * equal to what the PHY speed and duplex configuration is.
  920. * In addition, we need to perform a hardware reset on the
  921. * PHY to take it out of reset.
  922. */
  923. if (hw->mac.type == e1000_82543) {
  924. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  925. E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
  926. ret_val = hw->phy.ops.reset(hw);
  927. if (ret_val)
  928. goto out;
  929. hw->phy.reset_disable = false;
  930. } else {
  931. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  932. E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
  933. }
  934. /* Set MDI/MDI-X, Polarity Reversal, and downshift settings */
  935. ret_val = e1000_copper_link_setup_m88(hw);
  936. if (ret_val)
  937. goto out;
  938. if (hw->mac.autoneg) {
  939. /*
  940. * Setup autoneg and flow control advertisement and perform
  941. * autonegotiation.
  942. */
  943. ret_val = e1000_copper_link_autoneg(hw);
  944. if (ret_val)
  945. goto out;
  946. } else {
  947. /*
  948. * PHY will be set to 10H, 10F, 100H or 100F
  949. * depending on user settings.
  950. */
  951. #if 0
  952. DEBUGOUT("Forcing Speed and Duplex\n");
  953. ret_val = e1000_phy_force_speed_duplex_82543(hw);
  954. if (ret_val) {
  955. DEBUGOUT("Error Forcing Speed and Duplex\n");
  956. goto out;
  957. }
  958. #endif
  959. }
  960. /*
  961. * Check link status. Wait up to 100 microseconds for link to become
  962. * valid.
  963. */
  964. ret_val = e1000_phy_has_link_generic(hw,
  965. COPPER_LINK_UP_LIMIT,
  966. 10,
  967. &link);
  968. if (ret_val)
  969. goto out;
  970. if (link) {
  971. DEBUGOUT("Valid link established!!!\n");
  972. /* Config the MAC and PHY after link is up */
  973. if (hw->mac.type == e1000_82544) {
  974. e1000_config_collision_dist_generic(hw);
  975. } else {
  976. ret_val = e1000_config_mac_to_phy_82543(hw);
  977. if (ret_val)
  978. goto out;
  979. }
  980. ret_val = e1000_config_fc_after_link_up_generic(hw);
  981. } else {
  982. DEBUGOUT("Unable to establish link!!!\n");
  983. }
  984. out:
  985. return ret_val;
  986. }
  987. /**
  988. * e1000_setup_fiber_link_82543 - Setup link for fiber
  989. * @hw: pointer to the HW structure
  990. *
  991. * Configures collision distance and flow control for fiber links. Upon
  992. * successful setup, poll for link.
  993. **/
  994. static s32 e1000_setup_fiber_link_82543(struct e1000_hw *hw)
  995. {
  996. u32 ctrl;
  997. s32 ret_val;
  998. DEBUGFUNC("e1000_setup_fiber_link_82543");
  999. ctrl = E1000_READ_REG(hw, E1000_CTRL);
  1000. /* Take the link out of reset */
  1001. ctrl &= ~E1000_CTRL_LRST;
  1002. e1000_config_collision_dist_generic(hw);
  1003. ret_val = e1000_commit_fc_settings_generic(hw);
  1004. if (ret_val)
  1005. goto out;
  1006. DEBUGOUT("Auto-negotiation enabled\n");
  1007. E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
  1008. E1000_WRITE_FLUSH(hw);
  1009. msec_delay(1);
  1010. /*
  1011. * For these adapters, the SW definable pin 1 is cleared when the
  1012. * optics detect a signal. If we have a signal, then poll for a
  1013. * "Link-Up" indication.
  1014. */
  1015. if (!(E1000_READ_REG(hw, E1000_CTRL) & E1000_CTRL_SWDPIN1)) {
  1016. ret_val = e1000_poll_fiber_serdes_link_generic(hw);
  1017. } else {
  1018. DEBUGOUT("No signal detected\n");
  1019. }
  1020. out:
  1021. return ret_val;
  1022. }
  1023. /**
  1024. * e1000_check_for_copper_link_82543 - Check for link (Copper)
  1025. * @hw: pointer to the HW structure
  1026. *
  1027. * Checks the phy for link, if link exists, do the following:
  1028. * - check for downshift
  1029. * - do polarity workaround (if necessary)
  1030. * - configure collision distance
  1031. * - configure flow control after link up
  1032. * - configure tbi compatibility
  1033. **/
  1034. static s32 e1000_check_for_copper_link_82543(struct e1000_hw *hw)
  1035. {
  1036. struct e1000_mac_info *mac = &hw->mac;
  1037. u32 icr, rctl;
  1038. s32 ret_val;
  1039. u16 speed, duplex;
  1040. bool link;
  1041. DEBUGFUNC("e1000_check_for_copper_link_82543");
  1042. if (!mac->get_link_status) {
  1043. ret_val = E1000_SUCCESS;
  1044. goto out;
  1045. }
  1046. ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
  1047. if (ret_val)
  1048. goto out;
  1049. if (!link)
  1050. goto out; /* No link detected */
  1051. mac->get_link_status = false;
  1052. e1000_check_downshift_generic(hw);
  1053. /*
  1054. * If we are forcing speed/duplex, then we can return since
  1055. * we have already determined whether we have link or not.
  1056. */
  1057. if (!mac->autoneg) {
  1058. /*
  1059. * If speed and duplex are forced to 10H or 10F, then we will
  1060. * implement the polarity reversal workaround. We disable
  1061. * interrupts first, and upon returning, place the devices
  1062. * interrupt state to its previous value except for the link
  1063. * status change interrupt which will happened due to the
  1064. * execution of this workaround.
  1065. */
  1066. if (mac->forced_speed_duplex & E1000_ALL_10_SPEED) {
  1067. E1000_WRITE_REG(hw, E1000_IMC, 0xFFFFFFFF);
  1068. ret_val = e1000_polarity_reversal_workaround_82543(hw);
  1069. icr = E1000_READ_REG(hw, E1000_ICR);
  1070. E1000_WRITE_REG(hw, E1000_ICS, (icr & ~E1000_ICS_LSC));
  1071. E1000_WRITE_REG(hw, E1000_IMS, IMS_ENABLE_MASK);
  1072. }
  1073. ret_val = -E1000_ERR_CONFIG;
  1074. goto out;
  1075. }
  1076. /*
  1077. * We have a M88E1000 PHY and Auto-Neg is enabled. If we
  1078. * have Si on board that is 82544 or newer, Auto
  1079. * Speed Detection takes care of MAC speed/duplex
  1080. * configuration. So we only need to configure Collision
  1081. * Distance in the MAC. Otherwise, we need to force
  1082. * speed/duplex on the MAC to the current PHY speed/duplex
  1083. * settings.
  1084. */
  1085. if (mac->type == e1000_82544)
  1086. e1000_config_collision_dist_generic(hw);
  1087. else {
  1088. ret_val = e1000_config_mac_to_phy_82543(hw);
  1089. if (ret_val) {
  1090. DEBUGOUT("Error configuring MAC to PHY settings\n");
  1091. goto out;
  1092. }
  1093. }
  1094. /*
  1095. * Configure Flow Control now that Auto-Neg has completed.
  1096. * First, we need to restore the desired flow control
  1097. * settings because we may have had to re-autoneg with a
  1098. * different link partner.
  1099. */
  1100. ret_val = e1000_config_fc_after_link_up_generic(hw);
  1101. if (ret_val) {
  1102. DEBUGOUT("Error configuring flow control\n");
  1103. }
  1104. /*
  1105. * At this point we know that we are on copper and we have
  1106. * auto-negotiated link. These are conditions for checking the link
  1107. * partner capability register. We use the link speed to determine if
  1108. * TBI compatibility needs to be turned on or off. If the link is not
  1109. * at gigabit speed, then TBI compatibility is not needed. If we are
  1110. * at gigabit speed, we turn on TBI compatibility.
  1111. */
  1112. if (e1000_tbi_compatibility_enabled_82543(hw)) {
  1113. ret_val = mac->ops.get_link_up_info(hw, &speed, &duplex);
  1114. if (ret_val) {
  1115. DEBUGOUT("Error getting link speed and duplex\n");
  1116. return ret_val;
  1117. }
  1118. if (speed != SPEED_1000) {
  1119. /*
  1120. * If link speed is not set to gigabit speed,
  1121. * we do not need to enable TBI compatibility.
  1122. */
  1123. if (e1000_tbi_sbp_enabled_82543(hw)) {
  1124. /*
  1125. * If we previously were in the mode,
  1126. * turn it off.
  1127. */
  1128. e1000_set_tbi_sbp_82543(hw, false);
  1129. rctl = E1000_READ_REG(hw, E1000_RCTL);
  1130. rctl &= ~E1000_RCTL_SBP;
  1131. E1000_WRITE_REG(hw, E1000_RCTL, rctl);
  1132. }
  1133. } else {
  1134. /*
  1135. * If TBI compatibility is was previously off,
  1136. * turn it on. For compatibility with a TBI link
  1137. * partner, we will store bad packets. Some
  1138. * frames have an additional byte on the end and
  1139. * will look like CRC errors to to the hardware.
  1140. */
  1141. if (!e1000_tbi_sbp_enabled_82543(hw)) {
  1142. e1000_set_tbi_sbp_82543(hw, true);
  1143. rctl = E1000_READ_REG(hw, E1000_RCTL);
  1144. rctl |= E1000_RCTL_SBP;
  1145. E1000_WRITE_REG(hw, E1000_RCTL, rctl);
  1146. }
  1147. }
  1148. }
  1149. out:
  1150. return ret_val;
  1151. }
  1152. /**
  1153. * e1000_check_for_fiber_link_82543 - Check for link (Fiber)
  1154. * @hw: pointer to the HW structure
  1155. *
  1156. * Checks for link up on the hardware. If link is not up and we have
  1157. * a signal, then we need to force link up.
  1158. **/
  1159. static s32 e1000_check_for_fiber_link_82543(struct e1000_hw *hw)
  1160. {
  1161. struct e1000_mac_info *mac = &hw->mac;
  1162. u32 rxcw, ctrl, status;
  1163. s32 ret_val = E1000_SUCCESS;
  1164. DEBUGFUNC("e1000_check_for_fiber_link_82543");
  1165. ctrl = E1000_READ_REG(hw, E1000_CTRL);
  1166. status = E1000_READ_REG(hw, E1000_STATUS);
  1167. rxcw = E1000_READ_REG(hw, E1000_RXCW);
  1168. /*
  1169. * If we don't have link (auto-negotiation failed or link partner
  1170. * cannot auto-negotiate), the cable is plugged in (we have signal),
  1171. * and our link partner is not trying to auto-negotiate with us (we
  1172. * are receiving idles or data), we need to force link up. We also
  1173. * need to give auto-negotiation time to complete, in case the cable
  1174. * was just plugged in. The autoneg_failed flag does this.
  1175. */
  1176. /* (ctrl & E1000_CTRL_SWDPIN1) == 0 == have signal */
  1177. if ((!(ctrl & E1000_CTRL_SWDPIN1)) &&
  1178. (!(status & E1000_STATUS_LU)) &&
  1179. (!(rxcw & E1000_RXCW_C))) {
  1180. if (mac->autoneg_failed == 0) {
  1181. mac->autoneg_failed = 1;
  1182. ret_val = 0;
  1183. goto out;
  1184. }
  1185. DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
  1186. /* Disable auto-negotiation in the TXCW register */
  1187. E1000_WRITE_REG(hw, E1000_TXCW, (mac->txcw & ~E1000_TXCW_ANE));
  1188. /* Force link-up and also force full-duplex. */
  1189. ctrl = E1000_READ_REG(hw, E1000_CTRL);
  1190. ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
  1191. E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
  1192. /* Configure Flow Control after forcing link up. */
  1193. ret_val = e1000_config_fc_after_link_up_generic(hw);
  1194. if (ret_val) {
  1195. DEBUGOUT("Error configuring flow control\n");
  1196. goto out;
  1197. }
  1198. } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
  1199. /*
  1200. * If we are forcing link and we are receiving /C/ ordered
  1201. * sets, re-enable auto-negotiation in the TXCW register
  1202. * and disable forced link in the Device Control register
  1203. * in an attempt to auto-negotiate with our link partner.
  1204. */
  1205. DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
  1206. E1000_WRITE_REG(hw, E1000_TXCW, mac->txcw);
  1207. E1000_WRITE_REG(hw, E1000_CTRL, (ctrl & ~E1000_CTRL_SLU));
  1208. mac->serdes_has_link = true;
  1209. }
  1210. out:
  1211. return ret_val;
  1212. }
  1213. /**
  1214. * e1000_config_mac_to_phy_82543 - Configure MAC to PHY settings
  1215. * @hw: pointer to the HW structure
  1216. *
  1217. * For the 82543 silicon, we need to set the MAC to match the settings
  1218. * of the PHY, even if the PHY is auto-negotiating.
  1219. **/
  1220. static s32 e1000_config_mac_to_phy_82543(struct e1000_hw *hw)
  1221. {
  1222. u32 ctrl;
  1223. s32 ret_val = E1000_SUCCESS;
  1224. u16 phy_data;
  1225. DEBUGFUNC("e1000_config_mac_to_phy_82543");
  1226. if (!(hw->phy.ops.read_reg))
  1227. goto out;
  1228. /* Set the bits to force speed and duplex */
  1229. ctrl = E1000_READ_REG(hw, E1000_CTRL);
  1230. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  1231. ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
  1232. /*
  1233. * Set up duplex in the Device Control and Transmit Control
  1234. * registers depending on negotiated values.
  1235. */
  1236. ret_val = hw->phy.ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
  1237. if (ret_val)
  1238. goto out;
  1239. ctrl &= ~E1000_CTRL_FD;
  1240. if (phy_data & M88E1000_PSSR_DPLX)
  1241. ctrl |= E1000_CTRL_FD;
  1242. e1000_config_collision_dist_generic(hw);
  1243. /*
  1244. * Set up speed in the Device Control register depending on
  1245. * negotiated values.
  1246. */
  1247. if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
  1248. ctrl |= E1000_CTRL_SPD_1000;
  1249. else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
  1250. ctrl |= E1000_CTRL_SPD_100;
  1251. E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
  1252. out:
  1253. return ret_val;
  1254. }
  1255. /**
  1256. * e1000_write_vfta_82543 - Write value to VLAN filter table
  1257. * @hw: pointer to the HW structure
  1258. * @offset: the 32-bit offset in which to write the value to.
  1259. * @value: the 32-bit value to write at location offset.
  1260. *
  1261. * This writes a 32-bit value to a 32-bit offset in the VLAN filter
  1262. * table.
  1263. **/
  1264. static void e1000_write_vfta_82543(struct e1000_hw *hw, u32 offset, u32 value)
  1265. {
  1266. u32 temp;
  1267. DEBUGFUNC("e1000_write_vfta_82543");
  1268. if ((hw->mac.type == e1000_82544) && (offset & 1)) {
  1269. temp = E1000_READ_REG_ARRAY(hw, E1000_VFTA, offset - 1);
  1270. E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, value);
  1271. E1000_WRITE_FLUSH(hw);
  1272. E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset - 1, temp);
  1273. E1000_WRITE_FLUSH(hw);
  1274. } else {
  1275. e1000_write_vfta_generic(hw, offset, value);
  1276. }
  1277. }
  1278. /**
  1279. * e1000_mta_set_82543 - Set multicast filter table address
  1280. * @hw: pointer to the HW structure
  1281. * @hash_value: determines the MTA register and bit to set
  1282. *
  1283. * The multicast table address is a register array of 32-bit registers.
  1284. * The hash_value is used to determine what register the bit is in, the
  1285. * current value is read, the new bit is OR'd in and the new value is
  1286. * written back into the register.
  1287. **/
  1288. static void e1000_mta_set_82543(struct e1000_hw *hw, u32 hash_value)
  1289. {
  1290. u32 hash_bit, hash_reg, mta, temp;
  1291. DEBUGFUNC("e1000_mta_set_82543");
  1292. hash_reg = (hash_value >> 5);
  1293. /*
  1294. * If we are on an 82544 and we are trying to write an odd offset
  1295. * in the MTA, save off the previous entry before writing and
  1296. * restore the old value after writing.
  1297. */
  1298. if ((hw->mac.type == e1000_82544) && (hash_reg & 1)) {
  1299. hash_reg &= (hw->mac.mta_reg_count - 1);
  1300. hash_bit = hash_value & 0x1F;
  1301. mta = E1000_READ_REG_ARRAY(hw, E1000_MTA, hash_reg);
  1302. mta |= (1 << hash_bit);
  1303. temp = E1000_READ_REG_ARRAY(hw, E1000_MTA, hash_reg - 1);
  1304. E1000_WRITE_REG_ARRAY(hw, E1000_MTA, hash_reg, mta);
  1305. E1000_WRITE_FLUSH(hw);
  1306. E1000_WRITE_REG_ARRAY(hw, E1000_MTA, hash_reg - 1, temp);
  1307. E1000_WRITE_FLUSH(hw);
  1308. } else {
  1309. e1000_mta_set_generic(hw, hash_value);
  1310. }
  1311. }
  1312. /**
  1313. * e1000_led_on_82543 - Turn on SW controllable LED
  1314. * @hw: pointer to the HW structure
  1315. *
  1316. * Turns the SW defined LED on.
  1317. **/
  1318. static s32 e1000_led_on_82543(struct e1000_hw *hw __unused)
  1319. {
  1320. #if 0
  1321. u32 ctrl = E1000_READ_REG(hw, E1000_CTRL);
  1322. DEBUGFUNC("e1000_led_on_82543");
  1323. if (hw->mac.type == e1000_82544 &&
  1324. hw->phy.media_type == e1000_media_type_copper) {
  1325. /* Clear SW-definable Pin 0 to turn on the LED */
  1326. ctrl &= ~E1000_CTRL_SWDPIN0;
  1327. ctrl |= E1000_CTRL_SWDPIO0;
  1328. } else {
  1329. /* Fiber 82544 and all 82543 use this method */
  1330. ctrl |= E1000_CTRL_SWDPIN0;
  1331. ctrl |= E1000_CTRL_SWDPIO0;
  1332. }
  1333. E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
  1334. return E1000_SUCCESS;
  1335. #endif
  1336. return 0;
  1337. }
  1338. /**
  1339. * e1000_led_off_82543 - Turn off SW controllable LED
  1340. * @hw: pointer to the HW structure
  1341. *
  1342. * Turns the SW defined LED off.
  1343. **/
  1344. static s32 e1000_led_off_82543(struct e1000_hw *hw __unused)
  1345. {
  1346. #if 0
  1347. u32 ctrl = E1000_READ_REG(hw, E1000_CTRL);
  1348. DEBUGFUNC("e1000_led_off_82543");
  1349. if (hw->mac.type == e1000_82544 &&
  1350. hw->phy.media_type == e1000_media_type_copper) {
  1351. /* Set SW-definable Pin 0 to turn off the LED */
  1352. ctrl |= E1000_CTRL_SWDPIN0;
  1353. ctrl |= E1000_CTRL_SWDPIO0;
  1354. } else {
  1355. ctrl &= ~E1000_CTRL_SWDPIN0;
  1356. ctrl |= E1000_CTRL_SWDPIO0;
  1357. }
  1358. E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
  1359. return E1000_SUCCESS;
  1360. #endif
  1361. return 0;
  1362. }
  1363. /**
  1364. * e1000_clear_hw_cntrs_82543 - Clear device specific hardware counters
  1365. * @hw: pointer to the HW structure
  1366. *
  1367. * Clears the hardware counters by reading the counter registers.
  1368. **/
  1369. static void e1000_clear_hw_cntrs_82543(struct e1000_hw *hw)
  1370. {
  1371. DEBUGFUNC("e1000_clear_hw_cntrs_82543");
  1372. e1000_clear_hw_cntrs_base_generic(hw);
  1373. #if 0
  1374. E1000_READ_REG(hw, E1000_PRC64);
  1375. E1000_READ_REG(hw, E1000_PRC127);
  1376. E1000_READ_REG(hw, E1000_PRC255);
  1377. E1000_READ_REG(hw, E1000_PRC511);
  1378. E1000_READ_REG(hw, E1000_PRC1023);
  1379. E1000_READ_REG(hw, E1000_PRC1522);
  1380. E1000_READ_REG(hw, E1000_PTC64);
  1381. E1000_READ_REG(hw, E1000_PTC127);
  1382. E1000_READ_REG(hw, E1000_PTC255);
  1383. E1000_READ_REG(hw, E1000_PTC511);
  1384. E1000_READ_REG(hw, E1000_PTC1023);
  1385. E1000_READ_REG(hw, E1000_PTC1522);
  1386. E1000_READ_REG(hw, E1000_ALGNERRC);
  1387. E1000_READ_REG(hw, E1000_RXERRC);
  1388. E1000_READ_REG(hw, E1000_TNCRS);
  1389. E1000_READ_REG(hw, E1000_CEXTERR);
  1390. E1000_READ_REG(hw, E1000_TSCTC);
  1391. E1000_READ_REG(hw, E1000_TSCTFC);
  1392. #endif
  1393. }
  1394. static struct pci_device_id e1000_82543_nics[] = {
  1395. PCI_ROM(0x8086, 0x1001, "E1000_DEV_ID_82543GC_FIBER", "E1000_DEV_ID_82543GC_FIBER", e1000_82543),
  1396. PCI_ROM(0x8086, 0x1004, "E1000_DEV_ID_82543GC_COPPER", "E1000_DEV_ID_82543GC_COPPER", e1000_82543),
  1397. PCI_ROM(0x8086, 0x1008, "E1000_DEV_ID_82544EI_COPPER", "E1000_DEV_ID_82544EI_COPPER", e1000_82544),
  1398. PCI_ROM(0x8086, 0x1009, "E1000_DEV_ID_82544EI_FIBER", "E1000_DEV_ID_82544EI_FIBER", e1000_82544),
  1399. PCI_ROM(0x8086, 0x100C, "E1000_DEV_ID_82544GC_COPPER", "E1000_DEV_ID_82544GC_COPPER", e1000_82544),
  1400. PCI_ROM(0x8086, 0x100D, "E1000_DEV_ID_82544GC_LOM", "E1000_DEV_ID_82544GC_LOM", e1000_82544),
  1401. };
  1402. struct pci_driver e1000_82543_driver __pci_driver = {
  1403. .ids = e1000_82543_nics,
  1404. .id_count = (sizeof (e1000_82543_nics) / sizeof (e1000_82543_nics[0])),
  1405. .probe = e1000_probe,
  1406. .remove = e1000_remove,
  1407. };