ixgbe_82599.c 39 KB

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