ixgbe_82599.c 38 KB

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