ixgbe_82599.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2009 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/pci.h>
  21. #include <linux/delay.h>
  22. #include <linux/sched.h>
  23. #include "ixgbe.h"
  24. #include "ixgbe_phy.h"
  25. #define IXGBE_82599_MAX_TX_QUEUES 128
  26. #define IXGBE_82599_MAX_RX_QUEUES 128
  27. #define IXGBE_82599_RAR_ENTRIES 128
  28. #define IXGBE_82599_MC_TBL_SIZE 128
  29. #define IXGBE_82599_VFT_TBL_SIZE 128
  30. s32 ixgbe_get_link_capabilities_82599(struct ixgbe_hw *hw,
  31. ixgbe_link_speed *speed,
  32. bool *autoneg);
  33. enum ixgbe_media_type ixgbe_get_media_type_82599(struct ixgbe_hw *hw);
  34. s32 ixgbe_setup_mac_link_multispeed_fiber(struct ixgbe_hw *hw);
  35. s32 ixgbe_setup_mac_link_speed_multispeed_fiber(struct ixgbe_hw *hw,
  36. ixgbe_link_speed speed, bool autoneg,
  37. bool autoneg_wait_to_complete);
  38. s32 ixgbe_setup_mac_link_82599(struct ixgbe_hw *hw);
  39. s32 ixgbe_check_mac_link_82599(struct ixgbe_hw *hw,
  40. ixgbe_link_speed *speed,
  41. bool *link_up, bool link_up_wait_to_complete);
  42. s32 ixgbe_setup_mac_link_speed_82599(struct ixgbe_hw *hw,
  43. ixgbe_link_speed speed,
  44. bool autoneg,
  45. bool autoneg_wait_to_complete);
  46. static s32 ixgbe_get_copper_link_capabilities_82599(struct ixgbe_hw *hw,
  47. ixgbe_link_speed *speed,
  48. bool *autoneg);
  49. static s32 ixgbe_setup_copper_link_82599(struct ixgbe_hw *hw);
  50. static s32 ixgbe_setup_copper_link_speed_82599(struct ixgbe_hw *hw,
  51. ixgbe_link_speed speed,
  52. bool autoneg,
  53. bool autoneg_wait_to_complete);
  54. s32 ixgbe_reset_hw_82599(struct ixgbe_hw *hw);
  55. s32 ixgbe_set_vmdq_82599(struct ixgbe_hw *hw, u32 rar, u32 vmdq);
  56. s32 ixgbe_clear_vmdq_82599(struct ixgbe_hw *hw, u32 rar, u32 vmdq);
  57. s32 ixgbe_set_vfta_82599(struct ixgbe_hw *hw, u32 vlan,
  58. u32 vind, bool vlan_on);
  59. s32 ixgbe_clear_vfta_82599(struct ixgbe_hw *hw);
  60. s32 ixgbe_blink_led_stop_82599(struct ixgbe_hw *hw, u32 index);
  61. s32 ixgbe_blink_led_start_82599(struct ixgbe_hw *hw, u32 index);
  62. s32 ixgbe_init_uta_tables_82599(struct ixgbe_hw *hw);
  63. s32 ixgbe_read_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 *val);
  64. s32 ixgbe_write_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 val);
  65. s32 ixgbe_start_hw_rev_0_82599(struct ixgbe_hw *hw);
  66. s32 ixgbe_identify_phy_82599(struct ixgbe_hw *hw);
  67. s32 ixgbe_start_hw_82599(struct ixgbe_hw *hw);
  68. u32 ixgbe_get_supported_physical_layer_82599(struct ixgbe_hw *hw);
  69. void ixgbe_init_mac_link_ops_82599(struct ixgbe_hw *hw)
  70. {
  71. struct ixgbe_mac_info *mac = &hw->mac;
  72. if (hw->phy.multispeed_fiber) {
  73. /* Set up dual speed SFP+ support */
  74. mac->ops.setup_link =
  75. &ixgbe_setup_mac_link_multispeed_fiber;
  76. mac->ops.setup_link_speed =
  77. &ixgbe_setup_mac_link_speed_multispeed_fiber;
  78. } else {
  79. mac->ops.setup_link =
  80. &ixgbe_setup_mac_link_82599;
  81. mac->ops.setup_link_speed =
  82. &ixgbe_setup_mac_link_speed_82599;
  83. }
  84. }
  85. s32 ixgbe_setup_sfp_modules_82599(struct ixgbe_hw *hw)
  86. {
  87. s32 ret_val = 0;
  88. u16 list_offset, data_offset, data_value;
  89. if (hw->phy.sfp_type != ixgbe_sfp_type_unknown) {
  90. ixgbe_init_mac_link_ops_82599(hw);
  91. ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
  92. &data_offset);
  93. if (ret_val != 0)
  94. goto setup_sfp_out;
  95. hw->eeprom.ops.read(hw, ++data_offset, &data_value);
  96. while (data_value != 0xffff) {
  97. IXGBE_WRITE_REG(hw, IXGBE_CORECTL, data_value);
  98. IXGBE_WRITE_FLUSH(hw);
  99. hw->eeprom.ops.read(hw, ++data_offset, &data_value);
  100. }
  101. /* Now restart DSP */
  102. IXGBE_WRITE_REG(hw, IXGBE_CORECTL, 0x00000102);
  103. IXGBE_WRITE_REG(hw, IXGBE_CORECTL, 0x00000b1d);
  104. IXGBE_WRITE_FLUSH(hw);
  105. }
  106. setup_sfp_out:
  107. return ret_val;
  108. }
  109. /**
  110. * ixgbe_get_pcie_msix_count_82599 - Gets MSI-X vector count
  111. * @hw: pointer to hardware structure
  112. *
  113. * Read PCIe configuration space, and get the MSI-X vector count from
  114. * the capabilities table.
  115. **/
  116. u32 ixgbe_get_pcie_msix_count_82599(struct ixgbe_hw *hw)
  117. {
  118. struct ixgbe_adapter *adapter = hw->back;
  119. u16 msix_count;
  120. pci_read_config_word(adapter->pdev, IXGBE_PCIE_MSIX_82599_CAPS,
  121. &msix_count);
  122. msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK;
  123. /* MSI-X count is zero-based in HW, so increment to give proper value */
  124. msix_count++;
  125. return msix_count;
  126. }
  127. static s32 ixgbe_get_invariants_82599(struct ixgbe_hw *hw)
  128. {
  129. struct ixgbe_mac_info *mac = &hw->mac;
  130. ixgbe_init_mac_link_ops_82599(hw);
  131. mac->mcft_size = IXGBE_82599_MC_TBL_SIZE;
  132. mac->vft_size = IXGBE_82599_VFT_TBL_SIZE;
  133. mac->num_rar_entries = IXGBE_82599_RAR_ENTRIES;
  134. mac->max_rx_queues = IXGBE_82599_MAX_RX_QUEUES;
  135. mac->max_tx_queues = IXGBE_82599_MAX_TX_QUEUES;
  136. mac->max_msix_vectors = ixgbe_get_pcie_msix_count_82599(hw);
  137. return 0;
  138. }
  139. /**
  140. * ixgbe_init_phy_ops_82599 - PHY/SFP specific init
  141. * @hw: pointer to hardware structure
  142. *
  143. * Initialize any function pointers that were not able to be
  144. * set during get_invariants because the PHY/SFP type was
  145. * not known. Perform the SFP init if necessary.
  146. *
  147. **/
  148. s32 ixgbe_init_phy_ops_82599(struct ixgbe_hw *hw)
  149. {
  150. struct ixgbe_mac_info *mac = &hw->mac;
  151. struct ixgbe_phy_info *phy = &hw->phy;
  152. s32 ret_val = 0;
  153. /* Identify the PHY or SFP module */
  154. ret_val = phy->ops.identify(hw);
  155. /* Setup function pointers based on detected SFP module and speeds */
  156. ixgbe_init_mac_link_ops_82599(hw);
  157. /* If copper media, overwrite with copper function pointers */
  158. if (mac->ops.get_media_type(hw) == ixgbe_media_type_copper) {
  159. mac->ops.setup_link = &ixgbe_setup_copper_link_82599;
  160. mac->ops.setup_link_speed =
  161. &ixgbe_setup_copper_link_speed_82599;
  162. mac->ops.get_link_capabilities =
  163. &ixgbe_get_copper_link_capabilities_82599;
  164. }
  165. /* Set necessary function pointers based on phy type */
  166. switch (hw->phy.type) {
  167. case ixgbe_phy_tn:
  168. phy->ops.check_link = &ixgbe_check_phy_link_tnx;
  169. phy->ops.get_firmware_version =
  170. &ixgbe_get_phy_firmware_version_tnx;
  171. break;
  172. default:
  173. break;
  174. }
  175. return ret_val;
  176. }
  177. /**
  178. * ixgbe_get_link_capabilities_82599 - Determines link capabilities
  179. * @hw: pointer to hardware structure
  180. * @speed: pointer to link speed
  181. * @negotiation: true when autoneg or autotry is enabled
  182. *
  183. * Determines the link capabilities by reading the AUTOC register.
  184. **/
  185. s32 ixgbe_get_link_capabilities_82599(struct ixgbe_hw *hw,
  186. ixgbe_link_speed *speed,
  187. bool *negotiation)
  188. {
  189. s32 status = 0;
  190. switch (hw->mac.orig_autoc & IXGBE_AUTOC_LMS_MASK) {
  191. case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
  192. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  193. *negotiation = false;
  194. break;
  195. case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
  196. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  197. *negotiation = false;
  198. break;
  199. case IXGBE_AUTOC_LMS_1G_AN:
  200. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  201. *negotiation = true;
  202. break;
  203. case IXGBE_AUTOC_LMS_10G_SERIAL:
  204. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  205. *negotiation = false;
  206. break;
  207. case IXGBE_AUTOC_LMS_KX4_KX_KR:
  208. case IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN:
  209. *speed = IXGBE_LINK_SPEED_UNKNOWN;
  210. if (hw->mac.orig_autoc & IXGBE_AUTOC_KR_SUPP)
  211. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  212. if (hw->mac.orig_autoc & IXGBE_AUTOC_KX4_SUPP)
  213. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  214. if (hw->mac.orig_autoc & IXGBE_AUTOC_KX_SUPP)
  215. *speed |= IXGBE_LINK_SPEED_1GB_FULL;
  216. *negotiation = true;
  217. break;
  218. case IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII:
  219. *speed = IXGBE_LINK_SPEED_100_FULL;
  220. if (hw->mac.orig_autoc & IXGBE_AUTOC_KR_SUPP)
  221. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  222. if (hw->mac.orig_autoc & IXGBE_AUTOC_KX4_SUPP)
  223. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  224. if (hw->mac.orig_autoc & IXGBE_AUTOC_KX_SUPP)
  225. *speed |= IXGBE_LINK_SPEED_1GB_FULL;
  226. *negotiation = true;
  227. break;
  228. case IXGBE_AUTOC_LMS_SGMII_1G_100M:
  229. *speed = IXGBE_LINK_SPEED_1GB_FULL | IXGBE_LINK_SPEED_100_FULL;
  230. *negotiation = false;
  231. break;
  232. default:
  233. status = IXGBE_ERR_LINK_SETUP;
  234. goto out;
  235. break;
  236. }
  237. if (hw->phy.multispeed_fiber) {
  238. *speed |= IXGBE_LINK_SPEED_10GB_FULL |
  239. IXGBE_LINK_SPEED_1GB_FULL;
  240. *negotiation = true;
  241. }
  242. out:
  243. return status;
  244. }
  245. /**
  246. * ixgbe_get_copper_link_capabilities_82599 - Determines link capabilities
  247. * @hw: pointer to hardware structure
  248. * @speed: pointer to link speed
  249. * @autoneg: boolean auto-negotiation value
  250. *
  251. * Determines the link capabilities by reading the AUTOC register.
  252. **/
  253. static s32 ixgbe_get_copper_link_capabilities_82599(struct ixgbe_hw *hw,
  254. ixgbe_link_speed *speed,
  255. bool *autoneg)
  256. {
  257. s32 status = IXGBE_ERR_LINK_SETUP;
  258. u16 speed_ability;
  259. *speed = 0;
  260. *autoneg = true;
  261. status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_SPEED_ABILITY,
  262. IXGBE_MDIO_PMA_PMD_DEV_TYPE,
  263. &speed_ability);
  264. if (status == 0) {
  265. if (speed_ability & IXGBE_MDIO_PHY_SPEED_10G)
  266. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  267. if (speed_ability & IXGBE_MDIO_PHY_SPEED_1G)
  268. *speed |= IXGBE_LINK_SPEED_1GB_FULL;
  269. }
  270. return status;
  271. }
  272. /**
  273. * ixgbe_get_media_type_82599 - Get media type
  274. * @hw: pointer to hardware structure
  275. *
  276. * Returns the media type (fiber, copper, backplane)
  277. **/
  278. enum ixgbe_media_type ixgbe_get_media_type_82599(struct ixgbe_hw *hw)
  279. {
  280. enum ixgbe_media_type media_type;
  281. /* Detect if there is a copper PHY attached. */
  282. if (hw->phy.type == ixgbe_phy_cu_unknown ||
  283. hw->phy.type == ixgbe_phy_tn) {
  284. media_type = ixgbe_media_type_copper;
  285. goto out;
  286. }
  287. switch (hw->device_id) {
  288. case IXGBE_DEV_ID_82599:
  289. case IXGBE_DEV_ID_82599_KX4:
  290. /* Default device ID is mezzanine card KX/KX4 */
  291. media_type = ixgbe_media_type_backplane;
  292. break;
  293. case IXGBE_DEV_ID_82599_SFP:
  294. media_type = ixgbe_media_type_fiber;
  295. break;
  296. default:
  297. media_type = ixgbe_media_type_unknown;
  298. break;
  299. }
  300. out:
  301. return media_type;
  302. }
  303. /**
  304. * ixgbe_setup_mac_link_82599 - Setup MAC link settings
  305. * @hw: pointer to hardware structure
  306. *
  307. * Configures link settings based on values in the ixgbe_hw struct.
  308. * Restarts the link. Performs autonegotiation if needed.
  309. **/
  310. s32 ixgbe_setup_mac_link_82599(struct ixgbe_hw *hw)
  311. {
  312. u32 autoc_reg;
  313. u32 links_reg;
  314. u32 i;
  315. s32 status = 0;
  316. /* Restart link */
  317. autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  318. autoc_reg |= IXGBE_AUTOC_AN_RESTART;
  319. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
  320. /* Only poll for autoneg to complete if specified to do so */
  321. if (hw->phy.autoneg_wait_to_complete) {
  322. if ((autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
  323. IXGBE_AUTOC_LMS_KX4_KX_KR ||
  324. (autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
  325. IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
  326. (autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
  327. IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
  328. links_reg = 0; /* Just in case Autoneg time = 0 */
  329. for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
  330. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  331. if (links_reg & IXGBE_LINKS_KX_AN_COMP)
  332. break;
  333. msleep(100);
  334. }
  335. if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
  336. status = IXGBE_ERR_AUTONEG_NOT_COMPLETE;
  337. hw_dbg(hw, "Autoneg did not complete.\n");
  338. }
  339. }
  340. }
  341. /* Set up flow control */
  342. status = ixgbe_setup_fc_generic(hw, 0);
  343. /* Add delay to filter out noises during initial link setup */
  344. msleep(50);
  345. return status;
  346. }
  347. /**
  348. * ixgbe_setup_mac_link_multispeed_fiber - Setup MAC link settings
  349. * @hw: pointer to hardware structure
  350. *
  351. * Configures link settings based on values in the ixgbe_hw struct.
  352. * Restarts the link for multi-speed fiber at 1G speed, if link
  353. * fails at 10G.
  354. * Performs autonegotiation if needed.
  355. **/
  356. s32 ixgbe_setup_mac_link_multispeed_fiber(struct ixgbe_hw *hw)
  357. {
  358. s32 status = 0;
  359. ixgbe_link_speed link_speed = IXGBE_LINK_SPEED_82599_AUTONEG;
  360. status = ixgbe_setup_mac_link_speed_multispeed_fiber(hw, link_speed,
  361. true, true);
  362. return status;
  363. }
  364. /**
  365. * ixgbe_setup_mac_link_speed_multispeed_fiber - Set MAC link speed
  366. * @hw: pointer to hardware structure
  367. * @speed: new link speed
  368. * @autoneg: true if autonegotiation enabled
  369. * @autoneg_wait_to_complete: true when waiting for completion is needed
  370. *
  371. * Set the link speed in the AUTOC register and restarts link.
  372. **/
  373. s32 ixgbe_setup_mac_link_speed_multispeed_fiber(struct ixgbe_hw *hw,
  374. ixgbe_link_speed speed,
  375. bool autoneg,
  376. bool autoneg_wait_to_complete)
  377. {
  378. s32 status = 0;
  379. ixgbe_link_speed phy_link_speed;
  380. ixgbe_link_speed highest_link_speed = IXGBE_LINK_SPEED_UNKNOWN;
  381. u32 speedcnt = 0;
  382. u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
  383. bool link_up = false;
  384. bool negotiation;
  385. /* Mask off requested but non-supported speeds */
  386. hw->mac.ops.get_link_capabilities(hw, &phy_link_speed, &negotiation);
  387. speed &= phy_link_speed;
  388. /*
  389. * Try each speed one by one, highest priority first. We do this in
  390. * software because 10gb fiber doesn't support speed autonegotiation.
  391. */
  392. if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
  393. speedcnt++;
  394. highest_link_speed = IXGBE_LINK_SPEED_10GB_FULL;
  395. /* Set hardware SDP's */
  396. esdp_reg |= (IXGBE_ESDP_SDP5_DIR | IXGBE_ESDP_SDP5);
  397. IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
  398. ixgbe_setup_mac_link_speed_82599(hw,
  399. IXGBE_LINK_SPEED_10GB_FULL,
  400. autoneg,
  401. autoneg_wait_to_complete);
  402. msleep(50);
  403. /* If we have link, just jump out */
  404. hw->mac.ops.check_link(hw, &phy_link_speed, &link_up, false);
  405. if (link_up)
  406. goto out;
  407. }
  408. if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
  409. speedcnt++;
  410. if (highest_link_speed == IXGBE_LINK_SPEED_UNKNOWN)
  411. highest_link_speed = IXGBE_LINK_SPEED_1GB_FULL;
  412. /* Set hardware SDP's */
  413. esdp_reg &= ~IXGBE_ESDP_SDP5;
  414. esdp_reg |= IXGBE_ESDP_SDP5_DIR;
  415. IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
  416. ixgbe_setup_mac_link_speed_82599(
  417. hw, IXGBE_LINK_SPEED_1GB_FULL, autoneg,
  418. autoneg_wait_to_complete);
  419. msleep(50);
  420. /* If we have link, just jump out */
  421. hw->mac.ops.check_link(hw, &phy_link_speed, &link_up, false);
  422. if (link_up)
  423. goto out;
  424. }
  425. /*
  426. * We didn't get link. Configure back to the highest speed we tried,
  427. * (if there was more than one). We call ourselves back with just the
  428. * single highest speed that the user requested.
  429. */
  430. if (speedcnt > 1)
  431. status = ixgbe_setup_mac_link_speed_multispeed_fiber(hw,
  432. highest_link_speed,
  433. autoneg,
  434. autoneg_wait_to_complete);
  435. out:
  436. return status;
  437. }
  438. /**
  439. * ixgbe_check_mac_link_82599 - Determine link and speed status
  440. * @hw: pointer to hardware structure
  441. * @speed: pointer to link speed
  442. * @link_up: true when link is up
  443. * @link_up_wait_to_complete: bool used to wait for link up or not
  444. *
  445. * Reads the links register to determine if link is up and the current speed
  446. **/
  447. s32 ixgbe_check_mac_link_82599(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
  448. bool *link_up, bool link_up_wait_to_complete)
  449. {
  450. u32 links_reg;
  451. u32 i;
  452. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  453. if (link_up_wait_to_complete) {
  454. for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
  455. if (links_reg & IXGBE_LINKS_UP) {
  456. *link_up = true;
  457. break;
  458. } else {
  459. *link_up = false;
  460. }
  461. msleep(100);
  462. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  463. }
  464. } else {
  465. if (links_reg & IXGBE_LINKS_UP)
  466. *link_up = true;
  467. else
  468. *link_up = false;
  469. }
  470. if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
  471. IXGBE_LINKS_SPEED_10G_82599)
  472. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  473. else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
  474. IXGBE_LINKS_SPEED_1G_82599)
  475. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  476. else
  477. *speed = IXGBE_LINK_SPEED_100_FULL;
  478. return 0;
  479. }
  480. /**
  481. * ixgbe_setup_mac_link_speed_82599 - Set MAC link speed
  482. * @hw: pointer to hardware structure
  483. * @speed: new link speed
  484. * @autoneg: true if autonegotiation enabled
  485. * @autoneg_wait_to_complete: true when waiting for completion is needed
  486. *
  487. * Set the link speed in the AUTOC register and restarts link.
  488. **/
  489. s32 ixgbe_setup_mac_link_speed_82599(struct ixgbe_hw *hw,
  490. ixgbe_link_speed speed, bool autoneg,
  491. bool autoneg_wait_to_complete)
  492. {
  493. s32 status = 0;
  494. u32 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  495. u32 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
  496. u32 link_mode = autoc & IXGBE_AUTOC_LMS_MASK;
  497. u32 pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK;
  498. u32 pma_pmd_10g_serial = autoc2 & IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_MASK;
  499. u32 links_reg;
  500. u32 i;
  501. ixgbe_link_speed link_capabilities = IXGBE_LINK_SPEED_UNKNOWN;
  502. /* Check to see if speed passed in is supported. */
  503. hw->mac.ops.get_link_capabilities(hw, &link_capabilities, &autoneg);
  504. speed &= link_capabilities;
  505. if (speed == IXGBE_LINK_SPEED_UNKNOWN) {
  506. status = IXGBE_ERR_LINK_SETUP;
  507. } else if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR ||
  508. link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
  509. link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
  510. /* Set KX4/KX/KR support according to speed requested */
  511. autoc &= ~(IXGBE_AUTOC_KX4_KX_SUPP_MASK | IXGBE_AUTOC_KR_SUPP);
  512. if (speed & IXGBE_LINK_SPEED_10GB_FULL)
  513. if (hw->mac.orig_autoc & IXGBE_AUTOC_KX4_SUPP)
  514. autoc |= IXGBE_AUTOC_KX4_SUPP;
  515. if (hw->mac.orig_autoc & IXGBE_AUTOC_KR_SUPP)
  516. autoc |= IXGBE_AUTOC_KR_SUPP;
  517. if (speed & IXGBE_LINK_SPEED_1GB_FULL)
  518. autoc |= IXGBE_AUTOC_KX_SUPP;
  519. } else if ((pma_pmd_1g == IXGBE_AUTOC_1G_SFI) &&
  520. (link_mode == IXGBE_AUTOC_LMS_1G_LINK_NO_AN ||
  521. link_mode == IXGBE_AUTOC_LMS_1G_AN)) {
  522. /* Switch from 1G SFI to 10G SFI if requested */
  523. if ((speed == IXGBE_LINK_SPEED_10GB_FULL) &&
  524. (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI)) {
  525. autoc &= ~IXGBE_AUTOC_LMS_MASK;
  526. autoc |= IXGBE_AUTOC_LMS_10G_SERIAL;
  527. }
  528. } else if ((pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI) &&
  529. (link_mode == IXGBE_AUTOC_LMS_10G_SERIAL)) {
  530. /* Switch from 10G SFI to 1G SFI if requested */
  531. if ((speed == IXGBE_LINK_SPEED_1GB_FULL) &&
  532. (pma_pmd_1g == IXGBE_AUTOC_1G_SFI)) {
  533. autoc &= ~IXGBE_AUTOC_LMS_MASK;
  534. if (autoneg)
  535. autoc |= IXGBE_AUTOC_LMS_1G_AN;
  536. else
  537. autoc |= IXGBE_AUTOC_LMS_1G_LINK_NO_AN;
  538. }
  539. }
  540. if (status == 0) {
  541. /* Restart link */
  542. autoc |= IXGBE_AUTOC_AN_RESTART;
  543. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc);
  544. /* Only poll for autoneg to complete if specified to do so */
  545. if (autoneg_wait_to_complete) {
  546. if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR ||
  547. link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
  548. link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
  549. links_reg = 0; /*Just in case Autoneg time=0*/
  550. for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
  551. links_reg =
  552. IXGBE_READ_REG(hw, IXGBE_LINKS);
  553. if (links_reg & IXGBE_LINKS_KX_AN_COMP)
  554. break;
  555. msleep(100);
  556. }
  557. if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
  558. status =
  559. IXGBE_ERR_AUTONEG_NOT_COMPLETE;
  560. hw_dbg(hw, "Autoneg did not "
  561. "complete.\n");
  562. }
  563. }
  564. }
  565. /* Set up flow control */
  566. status = ixgbe_setup_fc_generic(hw, 0);
  567. /* Add delay to filter out noises during initial link setup */
  568. msleep(50);
  569. }
  570. return status;
  571. }
  572. /**
  573. * ixgbe_setup_copper_link_82599 - Setup copper link settings
  574. * @hw: pointer to hardware structure
  575. *
  576. * Restarts the link on PHY and then MAC. Performs autonegotiation if needed.
  577. **/
  578. static s32 ixgbe_setup_copper_link_82599(struct ixgbe_hw *hw)
  579. {
  580. s32 status;
  581. /* Restart autonegotiation on PHY */
  582. status = hw->phy.ops.setup_link(hw);
  583. /* Set up MAC */
  584. ixgbe_setup_mac_link_82599(hw);
  585. return status;
  586. }
  587. /**
  588. * ixgbe_setup_copper_link_speed_82599 - Set the PHY autoneg advertised field
  589. * @hw: pointer to hardware structure
  590. * @speed: new link speed
  591. * @autoneg: true if autonegotiation enabled
  592. * @autoneg_wait_to_complete: true if waiting is needed to complete
  593. *
  594. * Restarts link on PHY and MAC based on settings passed in.
  595. **/
  596. static s32 ixgbe_setup_copper_link_speed_82599(struct ixgbe_hw *hw,
  597. ixgbe_link_speed speed,
  598. bool autoneg,
  599. bool autoneg_wait_to_complete)
  600. {
  601. s32 status;
  602. /* Setup the PHY according to input speed */
  603. status = hw->phy.ops.setup_link_speed(hw, speed, autoneg,
  604. autoneg_wait_to_complete);
  605. /* Set up MAC */
  606. ixgbe_setup_mac_link_82599(hw);
  607. return status;
  608. }
  609. /**
  610. * ixgbe_reset_hw_82599 - Perform hardware reset
  611. * @hw: pointer to hardware structure
  612. *
  613. * Resets the hardware by resetting the transmit and receive units, masks
  614. * and clears all interrupts, perform a PHY reset, and perform a link (MAC)
  615. * reset.
  616. **/
  617. s32 ixgbe_reset_hw_82599(struct ixgbe_hw *hw)
  618. {
  619. s32 status = 0;
  620. u32 ctrl, ctrl_ext;
  621. u32 i;
  622. u32 autoc;
  623. u32 autoc2;
  624. /* Call adapter stop to disable tx/rx and clear interrupts */
  625. hw->mac.ops.stop_adapter(hw);
  626. /* Reset PHY */
  627. if (hw->phy.reset_disable == false) {
  628. /* PHY ops must be identified and initialized prior to reset */
  629. /* Init PHY and function pointers, perform SFP setup */
  630. status = hw->phy.ops.init(hw);
  631. if (status == IXGBE_ERR_SFP_NOT_SUPPORTED)
  632. goto reset_hw_out;
  633. hw->phy.ops.reset(hw);
  634. }
  635. /*
  636. * Prevent the PCI-E bus from from hanging by disabling PCI-E master
  637. * access and verify no pending requests before reset
  638. */
  639. status = ixgbe_disable_pcie_master(hw);
  640. if (status != 0) {
  641. status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
  642. hw_dbg(hw, "PCI-E Master disable polling has failed.\n");
  643. }
  644. /*
  645. * Issue global reset to the MAC. This needs to be a SW reset.
  646. * If link reset is used, it might reset the MAC when mng is using it
  647. */
  648. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  649. IXGBE_WRITE_REG(hw, IXGBE_CTRL, (ctrl | IXGBE_CTRL_RST));
  650. IXGBE_WRITE_FLUSH(hw);
  651. /* Poll for reset bit to self-clear indicating reset is complete */
  652. for (i = 0; i < 10; i++) {
  653. udelay(1);
  654. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  655. if (!(ctrl & IXGBE_CTRL_RST))
  656. break;
  657. }
  658. if (ctrl & IXGBE_CTRL_RST) {
  659. status = IXGBE_ERR_RESET_FAILED;
  660. hw_dbg(hw, "Reset polling failed to complete.\n");
  661. }
  662. /* Clear PF Reset Done bit so PF/VF Mail Ops can work */
  663. ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
  664. ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
  665. IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
  666. msleep(50);
  667. /*
  668. * Store the original AUTOC/AUTOC2 values if they have not been
  669. * stored off yet. Otherwise restore the stored original
  670. * values since the reset operation sets back to defaults.
  671. */
  672. autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  673. autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
  674. if (hw->mac.orig_link_settings_stored == false) {
  675. hw->mac.orig_autoc = autoc;
  676. hw->mac.orig_autoc2 = autoc2;
  677. hw->mac.orig_link_settings_stored = true;
  678. } else {
  679. if (autoc != hw->mac.orig_autoc)
  680. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, (hw->mac.orig_autoc |
  681. IXGBE_AUTOC_AN_RESTART));
  682. if ((autoc2 & IXGBE_AUTOC2_UPPER_MASK) !=
  683. (hw->mac.orig_autoc2 & IXGBE_AUTOC2_UPPER_MASK)) {
  684. autoc2 &= ~IXGBE_AUTOC2_UPPER_MASK;
  685. autoc2 |= (hw->mac.orig_autoc2 &
  686. IXGBE_AUTOC2_UPPER_MASK);
  687. IXGBE_WRITE_REG(hw, IXGBE_AUTOC2, autoc2);
  688. }
  689. }
  690. /* Store the permanent mac address */
  691. hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
  692. reset_hw_out:
  693. return status;
  694. }
  695. /**
  696. * ixgbe_clear_vmdq_82599 - Disassociate a VMDq pool index from a rx address
  697. * @hw: pointer to hardware struct
  698. * @rar: receive address register index to disassociate
  699. * @vmdq: VMDq pool index to remove from the rar
  700. **/
  701. s32 ixgbe_clear_vmdq_82599(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
  702. {
  703. u32 mpsar_lo, mpsar_hi;
  704. u32 rar_entries = hw->mac.num_rar_entries;
  705. if (rar < rar_entries) {
  706. mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
  707. mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
  708. if (!mpsar_lo && !mpsar_hi)
  709. goto done;
  710. if (vmdq == IXGBE_CLEAR_VMDQ_ALL) {
  711. if (mpsar_lo) {
  712. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
  713. mpsar_lo = 0;
  714. }
  715. if (mpsar_hi) {
  716. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
  717. mpsar_hi = 0;
  718. }
  719. } else if (vmdq < 32) {
  720. mpsar_lo &= ~(1 << vmdq);
  721. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar_lo);
  722. } else {
  723. mpsar_hi &= ~(1 << (vmdq - 32));
  724. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar_hi);
  725. }
  726. /* was that the last pool using this rar? */
  727. if (mpsar_lo == 0 && mpsar_hi == 0 && rar != 0)
  728. hw->mac.ops.clear_rar(hw, rar);
  729. } else {
  730. hw_dbg(hw, "RAR index %d is out of range.\n", rar);
  731. }
  732. done:
  733. return 0;
  734. }
  735. /**
  736. * ixgbe_set_vmdq_82599 - Associate a VMDq pool index with a rx address
  737. * @hw: pointer to hardware struct
  738. * @rar: receive address register index to associate with a VMDq index
  739. * @vmdq: VMDq pool index
  740. **/
  741. s32 ixgbe_set_vmdq_82599(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
  742. {
  743. u32 mpsar;
  744. u32 rar_entries = hw->mac.num_rar_entries;
  745. if (rar < rar_entries) {
  746. if (vmdq < 32) {
  747. mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
  748. mpsar |= 1 << vmdq;
  749. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar);
  750. } else {
  751. mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
  752. mpsar |= 1 << (vmdq - 32);
  753. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar);
  754. }
  755. } else {
  756. hw_dbg(hw, "RAR index %d is out of range.\n", rar);
  757. }
  758. return 0;
  759. }
  760. /**
  761. * ixgbe_set_vfta_82599 - Set VLAN filter table
  762. * @hw: pointer to hardware structure
  763. * @vlan: VLAN id to write to VLAN filter
  764. * @vind: VMDq output index that maps queue to VLAN id in VFVFB
  765. * @vlan_on: boolean flag to turn on/off VLAN in VFVF
  766. *
  767. * Turn on/off specified VLAN in the VLAN filter table.
  768. **/
  769. s32 ixgbe_set_vfta_82599(struct ixgbe_hw *hw, u32 vlan, u32 vind,
  770. bool vlan_on)
  771. {
  772. u32 regindex;
  773. u32 bitindex;
  774. u32 bits;
  775. u32 first_empty_slot;
  776. if (vlan > 4095)
  777. return IXGBE_ERR_PARAM;
  778. /*
  779. * this is a 2 part operation - first the VFTA, then the
  780. * VLVF and VLVFB if vind is set
  781. */
  782. /* Part 1
  783. * The VFTA is a bitstring made up of 128 32-bit registers
  784. * that enable the particular VLAN id, much like the MTA:
  785. * bits[11-5]: which register
  786. * bits[4-0]: which bit in the register
  787. */
  788. regindex = (vlan >> 5) & 0x7F;
  789. bitindex = vlan & 0x1F;
  790. bits = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
  791. if (vlan_on)
  792. bits |= (1 << bitindex);
  793. else
  794. bits &= ~(1 << bitindex);
  795. IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), bits);
  796. /* Part 2
  797. * If the vind is set
  798. * Either vlan_on
  799. * make sure the vlan is in VLVF
  800. * set the vind bit in the matching VLVFB
  801. * Or !vlan_on
  802. * clear the pool bit and possibly the vind
  803. */
  804. if (vind) {
  805. /* find the vlanid or the first empty slot */
  806. first_empty_slot = 0;
  807. for (regindex = 1; regindex < IXGBE_VLVF_ENTRIES; regindex++) {
  808. bits = IXGBE_READ_REG(hw, IXGBE_VLVF(regindex));
  809. if (!bits && !first_empty_slot)
  810. first_empty_slot = regindex;
  811. else if ((bits & 0x0FFF) == vlan)
  812. break;
  813. }
  814. if (regindex >= IXGBE_VLVF_ENTRIES) {
  815. if (first_empty_slot)
  816. regindex = first_empty_slot;
  817. else {
  818. hw_dbg(hw, "No space in VLVF.\n");
  819. goto out;
  820. }
  821. }
  822. if (vlan_on) {
  823. /* set the pool bit */
  824. if (vind < 32) {
  825. bits = IXGBE_READ_REG(hw,
  826. IXGBE_VLVFB(regindex * 2));
  827. bits |= (1 << vind);
  828. IXGBE_WRITE_REG(hw,
  829. IXGBE_VLVFB(regindex * 2), bits);
  830. } else {
  831. bits = IXGBE_READ_REG(hw,
  832. IXGBE_VLVFB((regindex * 2) + 1));
  833. bits |= (1 << vind);
  834. IXGBE_WRITE_REG(hw,
  835. IXGBE_VLVFB((regindex * 2) + 1), bits);
  836. }
  837. } else {
  838. /* clear the pool bit */
  839. if (vind < 32) {
  840. bits = IXGBE_READ_REG(hw,
  841. IXGBE_VLVFB(regindex * 2));
  842. bits &= ~(1 << vind);
  843. IXGBE_WRITE_REG(hw,
  844. IXGBE_VLVFB(regindex * 2), bits);
  845. bits |= IXGBE_READ_REG(hw,
  846. IXGBE_VLVFB((regindex * 2) + 1));
  847. } else {
  848. bits = IXGBE_READ_REG(hw,
  849. IXGBE_VLVFB((regindex * 2) + 1));
  850. bits &= ~(1 << vind);
  851. IXGBE_WRITE_REG(hw,
  852. IXGBE_VLVFB((regindex * 2) + 1), bits);
  853. bits |= IXGBE_READ_REG(hw,
  854. IXGBE_VLVFB(regindex * 2));
  855. }
  856. }
  857. if (bits)
  858. IXGBE_WRITE_REG(hw, IXGBE_VLVF(regindex),
  859. (IXGBE_VLVF_VIEN | vlan));
  860. else
  861. IXGBE_WRITE_REG(hw, IXGBE_VLVF(regindex), 0);
  862. }
  863. out:
  864. return 0;
  865. }
  866. /**
  867. * ixgbe_clear_vfta_82599 - Clear VLAN filter table
  868. * @hw: pointer to hardware structure
  869. *
  870. * Clears the VLAN filer table, and the VMDq index associated with the filter
  871. **/
  872. s32 ixgbe_clear_vfta_82599(struct ixgbe_hw *hw)
  873. {
  874. u32 offset;
  875. for (offset = 0; offset < hw->mac.vft_size; offset++)
  876. IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
  877. for (offset = 0; offset < IXGBE_VLVF_ENTRIES; offset++) {
  878. IXGBE_WRITE_REG(hw, IXGBE_VLVF(offset), 0);
  879. IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset * 2), 0);
  880. IXGBE_WRITE_REG(hw, IXGBE_VLVFB((offset * 2) + 1), 0);
  881. }
  882. return 0;
  883. }
  884. /**
  885. * ixgbe_blink_led_start_82599 - Blink LED based on index.
  886. * @hw: pointer to hardware structure
  887. * @index: led number to blink
  888. **/
  889. s32 ixgbe_blink_led_start_82599(struct ixgbe_hw *hw, u32 index)
  890. {
  891. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  892. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  893. led_reg |= IXGBE_LED_BLINK(index);
  894. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  895. IXGBE_WRITE_FLUSH(hw);
  896. return 0;
  897. }
  898. /**
  899. * ixgbe_blink_led_stop_82599 - Stop blinking LED based on index.
  900. * @hw: pointer to hardware structure
  901. * @index: led number to stop blinking
  902. **/
  903. s32 ixgbe_blink_led_stop_82599(struct ixgbe_hw *hw, u32 index)
  904. {
  905. u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
  906. led_reg &= ~IXGBE_LED_MODE_MASK(index);
  907. led_reg &= ~IXGBE_LED_BLINK(index);
  908. IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
  909. IXGBE_WRITE_FLUSH(hw);
  910. return 0;
  911. }
  912. /**
  913. * ixgbe_init_uta_tables_82599 - Initialize the Unicast Table Array
  914. * @hw: pointer to hardware structure
  915. **/
  916. s32 ixgbe_init_uta_tables_82599(struct ixgbe_hw *hw)
  917. {
  918. int i;
  919. hw_dbg(hw, " Clearing UTA\n");
  920. for (i = 0; i < 128; i++)
  921. IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
  922. return 0;
  923. }
  924. /**
  925. * ixgbe_read_analog_reg8_82599 - Reads 8 bit Omer analog register
  926. * @hw: pointer to hardware structure
  927. * @reg: analog register to read
  928. * @val: read value
  929. *
  930. * Performs read operation to Omer analog register specified.
  931. **/
  932. s32 ixgbe_read_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 *val)
  933. {
  934. u32 core_ctl;
  935. IXGBE_WRITE_REG(hw, IXGBE_CORECTL, IXGBE_CORECTL_WRITE_CMD |
  936. (reg << 8));
  937. IXGBE_WRITE_FLUSH(hw);
  938. udelay(10);
  939. core_ctl = IXGBE_READ_REG(hw, IXGBE_CORECTL);
  940. *val = (u8)core_ctl;
  941. return 0;
  942. }
  943. /**
  944. * ixgbe_write_analog_reg8_82599 - Writes 8 bit Omer analog register
  945. * @hw: pointer to hardware structure
  946. * @reg: atlas register to write
  947. * @val: value to write
  948. *
  949. * Performs write operation to Omer analog register specified.
  950. **/
  951. s32 ixgbe_write_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 val)
  952. {
  953. u32 core_ctl;
  954. core_ctl = (reg << 8) | val;
  955. IXGBE_WRITE_REG(hw, IXGBE_CORECTL, core_ctl);
  956. IXGBE_WRITE_FLUSH(hw);
  957. udelay(10);
  958. return 0;
  959. }
  960. /**
  961. * ixgbe_start_hw_82599 - Prepare hardware for Tx/Rx
  962. * @hw: pointer to hardware structure
  963. *
  964. * Starts the hardware using the generic start_hw function.
  965. * Then performs device-specific:
  966. * Clears the rate limiter registers.
  967. **/
  968. s32 ixgbe_start_hw_82599(struct ixgbe_hw *hw)
  969. {
  970. u32 q_num;
  971. ixgbe_start_hw_generic(hw);
  972. /* Clear the rate limiters */
  973. for (q_num = 0; q_num < hw->mac.max_tx_queues; q_num++) {
  974. IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, q_num);
  975. IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, 0);
  976. }
  977. IXGBE_WRITE_FLUSH(hw);
  978. return 0;
  979. }
  980. /**
  981. * ixgbe_identify_phy_82599 - Get physical layer module
  982. * @hw: pointer to hardware structure
  983. *
  984. * Determines the physical layer module found on the current adapter.
  985. **/
  986. s32 ixgbe_identify_phy_82599(struct ixgbe_hw *hw)
  987. {
  988. s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
  989. status = ixgbe_identify_phy_generic(hw);
  990. if (status != 0)
  991. status = ixgbe_identify_sfp_module_generic(hw);
  992. return status;
  993. }
  994. /**
  995. * ixgbe_get_supported_physical_layer_82599 - Returns physical layer type
  996. * @hw: pointer to hardware structure
  997. *
  998. * Determines physical layer capabilities of the current configuration.
  999. **/
  1000. u32 ixgbe_get_supported_physical_layer_82599(struct ixgbe_hw *hw)
  1001. {
  1002. u32 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
  1003. u8 comp_codes_10g = 0;
  1004. switch (hw->device_id) {
  1005. case IXGBE_DEV_ID_82599:
  1006. case IXGBE_DEV_ID_82599_KX4:
  1007. /* Default device ID is mezzanine card KX/KX4 */
  1008. physical_layer = (IXGBE_PHYSICAL_LAYER_10GBASE_KX4 |
  1009. IXGBE_PHYSICAL_LAYER_1000BASE_KX);
  1010. break;
  1011. case IXGBE_DEV_ID_82599_SFP:
  1012. hw->phy.ops.identify_sfp(hw);
  1013. switch (hw->phy.sfp_type) {
  1014. case ixgbe_sfp_type_da_cu:
  1015. case ixgbe_sfp_type_da_cu_core0:
  1016. case ixgbe_sfp_type_da_cu_core1:
  1017. physical_layer = IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU;
  1018. break;
  1019. case ixgbe_sfp_type_sr:
  1020. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_SR;
  1021. break;
  1022. case ixgbe_sfp_type_lr:
  1023. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_LR;
  1024. break;
  1025. case ixgbe_sfp_type_srlr_core0:
  1026. case ixgbe_sfp_type_srlr_core1:
  1027. hw->phy.ops.read_i2c_eeprom(hw,
  1028. IXGBE_SFF_10GBE_COMP_CODES,
  1029. &comp_codes_10g);
  1030. if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
  1031. physical_layer =
  1032. IXGBE_PHYSICAL_LAYER_10GBASE_SR;
  1033. else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
  1034. physical_layer =
  1035. IXGBE_PHYSICAL_LAYER_10GBASE_LR;
  1036. else
  1037. physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
  1038. default:
  1039. physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
  1040. break;
  1041. }
  1042. break;
  1043. default:
  1044. physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
  1045. break;
  1046. }
  1047. return physical_layer;
  1048. }
  1049. /**
  1050. * ixgbe_enable_rx_dma_82599 - Enable the Rx DMA unit on 82599
  1051. * @hw: pointer to hardware structure
  1052. * @regval: register value to write to RXCTRL
  1053. *
  1054. * Enables the Rx DMA unit for 82599
  1055. **/
  1056. s32 ixgbe_enable_rx_dma_82599(struct ixgbe_hw *hw, u32 regval)
  1057. {
  1058. #define IXGBE_MAX_SECRX_POLL 30
  1059. int i;
  1060. int secrxreg;
  1061. /*
  1062. * Workaround for 82599 silicon errata when enabling the Rx datapath.
  1063. * If traffic is incoming before we enable the Rx unit, it could hang
  1064. * the Rx DMA unit. Therefore, make sure the security engine is
  1065. * completely disabled prior to enabling the Rx unit.
  1066. */
  1067. secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
  1068. secrxreg |= IXGBE_SECRXCTRL_RX_DIS;
  1069. IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
  1070. for (i = 0; i < IXGBE_MAX_SECRX_POLL; i++) {
  1071. secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXSTAT);
  1072. if (secrxreg & IXGBE_SECRXSTAT_SECRX_RDY)
  1073. break;
  1074. else
  1075. udelay(10);
  1076. }
  1077. /* For informational purposes only */
  1078. if (i >= IXGBE_MAX_SECRX_POLL)
  1079. hw_dbg(hw, "Rx unit being enabled before security "
  1080. "path fully disabled. Continuing with init.\n");
  1081. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval);
  1082. secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
  1083. secrxreg &= ~IXGBE_SECRXCTRL_RX_DIS;
  1084. IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
  1085. IXGBE_WRITE_FLUSH(hw);
  1086. return 0;
  1087. }
  1088. static struct ixgbe_mac_operations mac_ops_82599 = {
  1089. .init_hw = &ixgbe_init_hw_generic,
  1090. .reset_hw = &ixgbe_reset_hw_82599,
  1091. .start_hw = &ixgbe_start_hw_82599,
  1092. .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic,
  1093. .get_media_type = &ixgbe_get_media_type_82599,
  1094. .get_supported_physical_layer = &ixgbe_get_supported_physical_layer_82599,
  1095. .enable_rx_dma = &ixgbe_enable_rx_dma_82599,
  1096. .get_mac_addr = &ixgbe_get_mac_addr_generic,
  1097. .stop_adapter = &ixgbe_stop_adapter_generic,
  1098. .get_bus_info = &ixgbe_get_bus_info_generic,
  1099. .set_lan_id = &ixgbe_set_lan_id_multi_port_pcie,
  1100. .read_analog_reg8 = &ixgbe_read_analog_reg8_82599,
  1101. .write_analog_reg8 = &ixgbe_write_analog_reg8_82599,
  1102. .setup_link = &ixgbe_setup_mac_link_82599,
  1103. .setup_link_speed = &ixgbe_setup_mac_link_speed_82599,
  1104. .check_link = &ixgbe_check_mac_link_82599,
  1105. .get_link_capabilities = &ixgbe_get_link_capabilities_82599,
  1106. .led_on = &ixgbe_led_on_generic,
  1107. .led_off = &ixgbe_led_off_generic,
  1108. .blink_led_start = &ixgbe_blink_led_start_82599,
  1109. .blink_led_stop = &ixgbe_blink_led_stop_82599,
  1110. .set_rar = &ixgbe_set_rar_generic,
  1111. .clear_rar = &ixgbe_clear_rar_generic,
  1112. .set_vmdq = &ixgbe_set_vmdq_82599,
  1113. .clear_vmdq = &ixgbe_clear_vmdq_82599,
  1114. .init_rx_addrs = &ixgbe_init_rx_addrs_generic,
  1115. .update_uc_addr_list = &ixgbe_update_uc_addr_list_generic,
  1116. .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic,
  1117. .enable_mc = &ixgbe_enable_mc_generic,
  1118. .disable_mc = &ixgbe_disable_mc_generic,
  1119. .clear_vfta = &ixgbe_clear_vfta_82599,
  1120. .set_vfta = &ixgbe_set_vfta_82599,
  1121. .setup_fc = &ixgbe_setup_fc_generic,
  1122. .init_uta_tables = &ixgbe_init_uta_tables_82599,
  1123. .setup_sfp = &ixgbe_setup_sfp_modules_82599,
  1124. };
  1125. static struct ixgbe_eeprom_operations eeprom_ops_82599 = {
  1126. .init_params = &ixgbe_init_eeprom_params_generic,
  1127. .read = &ixgbe_read_eeprom_generic,
  1128. .write = &ixgbe_write_eeprom_generic,
  1129. .validate_checksum = &ixgbe_validate_eeprom_checksum_generic,
  1130. .update_checksum = &ixgbe_update_eeprom_checksum_generic,
  1131. };
  1132. static struct ixgbe_phy_operations phy_ops_82599 = {
  1133. .identify = &ixgbe_identify_phy_82599,
  1134. .identify_sfp = &ixgbe_identify_sfp_module_generic,
  1135. .init = &ixgbe_init_phy_ops_82599,
  1136. .reset = &ixgbe_reset_phy_generic,
  1137. .read_reg = &ixgbe_read_phy_reg_generic,
  1138. .write_reg = &ixgbe_write_phy_reg_generic,
  1139. .setup_link = &ixgbe_setup_phy_link_generic,
  1140. .setup_link_speed = &ixgbe_setup_phy_link_speed_generic,
  1141. .read_i2c_byte = &ixgbe_read_i2c_byte_generic,
  1142. .write_i2c_byte = &ixgbe_write_i2c_byte_generic,
  1143. .read_i2c_eeprom = &ixgbe_read_i2c_eeprom_generic,
  1144. .write_i2c_eeprom = &ixgbe_write_i2c_eeprom_generic,
  1145. };
  1146. struct ixgbe_info ixgbe_82599_info = {
  1147. .mac = ixgbe_mac_82599EB,
  1148. .get_invariants = &ixgbe_get_invariants_82599,
  1149. .mac_ops = &mac_ops_82599,
  1150. .eeprom_ops = &eeprom_ops_82599,
  1151. .phy_ops = &phy_ops_82599,
  1152. };