ixgbe_82599.c 44 KB

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