ixgbe_82599.c 40 KB

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