ixgbe_82598.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2014 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. Linux NICS <linux.nics@intel.com>
  18. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. *******************************************************************************/
  21. #include <linux/pci.h>
  22. #include <linux/delay.h>
  23. #include <linux/sched.h>
  24. #include "ixgbe.h"
  25. #include "ixgbe_phy.h"
  26. #define IXGBE_82598_MAX_TX_QUEUES 32
  27. #define IXGBE_82598_MAX_RX_QUEUES 64
  28. #define IXGBE_82598_RAR_ENTRIES 16
  29. #define IXGBE_82598_MC_TBL_SIZE 128
  30. #define IXGBE_82598_VFT_TBL_SIZE 128
  31. #define IXGBE_82598_RX_PB_SIZE 512
  32. static s32 ixgbe_setup_copper_link_82598(struct ixgbe_hw *hw,
  33. ixgbe_link_speed speed,
  34. bool autoneg_wait_to_complete);
  35. static s32 ixgbe_read_i2c_eeprom_82598(struct ixgbe_hw *hw, u8 byte_offset,
  36. u8 *eeprom_data);
  37. /**
  38. * ixgbe_set_pcie_completion_timeout - set pci-e completion timeout
  39. * @hw: pointer to the HW structure
  40. *
  41. * The defaults for 82598 should be in the range of 50us to 50ms,
  42. * however the hardware default for these parts is 500us to 1ms which is less
  43. * than the 10ms recommended by the pci-e spec. To address this we need to
  44. * increase the value to either 10ms to 250ms for capability version 1 config,
  45. * or 16ms to 55ms for version 2.
  46. **/
  47. static void ixgbe_set_pcie_completion_timeout(struct ixgbe_hw *hw)
  48. {
  49. u32 gcr = IXGBE_READ_REG(hw, IXGBE_GCR);
  50. u16 pcie_devctl2;
  51. if (ixgbe_removed(hw->hw_addr))
  52. return;
  53. /* only take action if timeout value is defaulted to 0 */
  54. if (gcr & IXGBE_GCR_CMPL_TMOUT_MASK)
  55. goto out;
  56. /*
  57. * if capababilities version is type 1 we can write the
  58. * timeout of 10ms to 250ms through the GCR register
  59. */
  60. if (!(gcr & IXGBE_GCR_CAP_VER2)) {
  61. gcr |= IXGBE_GCR_CMPL_TMOUT_10ms;
  62. goto out;
  63. }
  64. /*
  65. * for version 2 capabilities we need to write the config space
  66. * directly in order to set the completion timeout value for
  67. * 16ms to 55ms
  68. */
  69. pcie_devctl2 = ixgbe_read_pci_cfg_word(hw, IXGBE_PCI_DEVICE_CONTROL2);
  70. pcie_devctl2 |= IXGBE_PCI_DEVICE_CONTROL2_16ms;
  71. ixgbe_write_pci_cfg_word(hw, IXGBE_PCI_DEVICE_CONTROL2, pcie_devctl2);
  72. out:
  73. /* disable completion timeout resend */
  74. gcr &= ~IXGBE_GCR_CMPL_TMOUT_RESEND;
  75. IXGBE_WRITE_REG(hw, IXGBE_GCR, gcr);
  76. }
  77. static s32 ixgbe_get_invariants_82598(struct ixgbe_hw *hw)
  78. {
  79. struct ixgbe_mac_info *mac = &hw->mac;
  80. /* Call PHY identify routine to get the phy type */
  81. ixgbe_identify_phy_generic(hw);
  82. mac->mcft_size = IXGBE_82598_MC_TBL_SIZE;
  83. mac->vft_size = IXGBE_82598_VFT_TBL_SIZE;
  84. mac->num_rar_entries = IXGBE_82598_RAR_ENTRIES;
  85. mac->rx_pb_size = IXGBE_82598_RX_PB_SIZE;
  86. mac->max_rx_queues = IXGBE_82598_MAX_RX_QUEUES;
  87. mac->max_tx_queues = IXGBE_82598_MAX_TX_QUEUES;
  88. mac->max_msix_vectors = ixgbe_get_pcie_msix_count_generic(hw);
  89. return 0;
  90. }
  91. /**
  92. * ixgbe_init_phy_ops_82598 - PHY/SFP specific init
  93. * @hw: pointer to hardware structure
  94. *
  95. * Initialize any function pointers that were not able to be
  96. * set during get_invariants because the PHY/SFP type was
  97. * not known. Perform the SFP init if necessary.
  98. *
  99. **/
  100. static s32 ixgbe_init_phy_ops_82598(struct ixgbe_hw *hw)
  101. {
  102. struct ixgbe_mac_info *mac = &hw->mac;
  103. struct ixgbe_phy_info *phy = &hw->phy;
  104. s32 ret_val;
  105. u16 list_offset, data_offset;
  106. /* Identify the PHY */
  107. phy->ops.identify(hw);
  108. /* Overwrite the link function pointers if copper PHY */
  109. if (mac->ops.get_media_type(hw) == ixgbe_media_type_copper) {
  110. mac->ops.setup_link = &ixgbe_setup_copper_link_82598;
  111. mac->ops.get_link_capabilities =
  112. &ixgbe_get_copper_link_capabilities_generic;
  113. }
  114. switch (hw->phy.type) {
  115. case ixgbe_phy_tn:
  116. phy->ops.setup_link = &ixgbe_setup_phy_link_tnx;
  117. phy->ops.check_link = &ixgbe_check_phy_link_tnx;
  118. phy->ops.get_firmware_version =
  119. &ixgbe_get_phy_firmware_version_tnx;
  120. break;
  121. case ixgbe_phy_nl:
  122. phy->ops.reset = &ixgbe_reset_phy_nl;
  123. /* Call SFP+ identify routine to get the SFP+ module type */
  124. ret_val = phy->ops.identify_sfp(hw);
  125. if (ret_val)
  126. return ret_val;
  127. if (hw->phy.sfp_type == ixgbe_sfp_type_unknown)
  128. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  129. /* Check to see if SFP+ module is supported */
  130. ret_val = ixgbe_get_sfp_init_sequence_offsets(hw,
  131. &list_offset,
  132. &data_offset);
  133. if (ret_val)
  134. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  135. break;
  136. default:
  137. break;
  138. }
  139. return 0;
  140. }
  141. /**
  142. * ixgbe_start_hw_82598 - Prepare hardware for Tx/Rx
  143. * @hw: pointer to hardware structure
  144. *
  145. * Starts the hardware using the generic start_hw function.
  146. * Disables relaxed ordering for archs other than SPARC
  147. * Then set pcie completion timeout
  148. *
  149. **/
  150. static s32 ixgbe_start_hw_82598(struct ixgbe_hw *hw)
  151. {
  152. #ifndef CONFIG_SPARC
  153. u32 regval;
  154. u32 i;
  155. #endif
  156. s32 ret_val;
  157. ret_val = ixgbe_start_hw_generic(hw);
  158. #ifndef CONFIG_SPARC
  159. /* Disable relaxed ordering */
  160. for (i = 0; ((i < hw->mac.max_tx_queues) &&
  161. (i < IXGBE_DCA_MAX_QUEUES_82598)); i++) {
  162. regval = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(i));
  163. regval &= ~IXGBE_DCA_TXCTRL_DESC_WRO_EN;
  164. IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(i), regval);
  165. }
  166. for (i = 0; ((i < hw->mac.max_rx_queues) &&
  167. (i < IXGBE_DCA_MAX_QUEUES_82598)); i++) {
  168. regval = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
  169. regval &= ~(IXGBE_DCA_RXCTRL_DATA_WRO_EN |
  170. IXGBE_DCA_RXCTRL_HEAD_WRO_EN);
  171. IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(i), regval);
  172. }
  173. #endif
  174. if (ret_val)
  175. return ret_val;
  176. /* set the completion timeout for interface */
  177. ixgbe_set_pcie_completion_timeout(hw);
  178. return 0;
  179. }
  180. /**
  181. * ixgbe_get_link_capabilities_82598 - Determines link capabilities
  182. * @hw: pointer to hardware structure
  183. * @speed: pointer to link speed
  184. * @autoneg: boolean auto-negotiation value
  185. *
  186. * Determines the link capabilities by reading the AUTOC register.
  187. **/
  188. static s32 ixgbe_get_link_capabilities_82598(struct ixgbe_hw *hw,
  189. ixgbe_link_speed *speed,
  190. bool *autoneg)
  191. {
  192. u32 autoc = 0;
  193. /*
  194. * Determine link capabilities based on the stored value of AUTOC,
  195. * which represents EEPROM defaults. If AUTOC value has not been
  196. * stored, use the current register value.
  197. */
  198. if (hw->mac.orig_link_settings_stored)
  199. autoc = hw->mac.orig_autoc;
  200. else
  201. autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  202. switch (autoc & IXGBE_AUTOC_LMS_MASK) {
  203. case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
  204. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  205. *autoneg = false;
  206. break;
  207. case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
  208. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  209. *autoneg = false;
  210. break;
  211. case IXGBE_AUTOC_LMS_1G_AN:
  212. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  213. *autoneg = true;
  214. break;
  215. case IXGBE_AUTOC_LMS_KX4_AN:
  216. case IXGBE_AUTOC_LMS_KX4_AN_1G_AN:
  217. *speed = IXGBE_LINK_SPEED_UNKNOWN;
  218. if (autoc & IXGBE_AUTOC_KX4_SUPP)
  219. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  220. if (autoc & IXGBE_AUTOC_KX_SUPP)
  221. *speed |= IXGBE_LINK_SPEED_1GB_FULL;
  222. *autoneg = true;
  223. break;
  224. default:
  225. return IXGBE_ERR_LINK_SETUP;
  226. }
  227. return 0;
  228. }
  229. /**
  230. * ixgbe_get_media_type_82598 - Determines media type
  231. * @hw: pointer to hardware structure
  232. *
  233. * Returns the media type (fiber, copper, backplane)
  234. **/
  235. static enum ixgbe_media_type ixgbe_get_media_type_82598(struct ixgbe_hw *hw)
  236. {
  237. /* Detect if there is a copper PHY attached. */
  238. switch (hw->phy.type) {
  239. case ixgbe_phy_cu_unknown:
  240. case ixgbe_phy_tn:
  241. return ixgbe_media_type_copper;
  242. default:
  243. break;
  244. }
  245. /* Media type for I82598 is based on device ID */
  246. switch (hw->device_id) {
  247. case IXGBE_DEV_ID_82598:
  248. case IXGBE_DEV_ID_82598_BX:
  249. /* Default device ID is mezzanine card KX/KX4 */
  250. return ixgbe_media_type_backplane;
  251. case IXGBE_DEV_ID_82598AF_DUAL_PORT:
  252. case IXGBE_DEV_ID_82598AF_SINGLE_PORT:
  253. case IXGBE_DEV_ID_82598_DA_DUAL_PORT:
  254. case IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM:
  255. case IXGBE_DEV_ID_82598EB_XF_LR:
  256. case IXGBE_DEV_ID_82598EB_SFP_LOM:
  257. return ixgbe_media_type_fiber;
  258. case IXGBE_DEV_ID_82598EB_CX4:
  259. case IXGBE_DEV_ID_82598_CX4_DUAL_PORT:
  260. return ixgbe_media_type_cx4;
  261. case IXGBE_DEV_ID_82598AT:
  262. case IXGBE_DEV_ID_82598AT2:
  263. return ixgbe_media_type_copper;
  264. default:
  265. return ixgbe_media_type_unknown;
  266. }
  267. }
  268. /**
  269. * ixgbe_fc_enable_82598 - Enable flow control
  270. * @hw: pointer to hardware structure
  271. *
  272. * Enable flow control according to the current settings.
  273. **/
  274. static s32 ixgbe_fc_enable_82598(struct ixgbe_hw *hw)
  275. {
  276. u32 fctrl_reg;
  277. u32 rmcs_reg;
  278. u32 reg;
  279. u32 fcrtl, fcrth;
  280. u32 link_speed = 0;
  281. int i;
  282. bool link_up;
  283. /* Validate the water mark configuration */
  284. if (!hw->fc.pause_time)
  285. return IXGBE_ERR_INVALID_LINK_SETTINGS;
  286. /* Low water mark of zero causes XOFF floods */
  287. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  288. if ((hw->fc.current_mode & ixgbe_fc_tx_pause) &&
  289. hw->fc.high_water[i]) {
  290. if (!hw->fc.low_water[i] ||
  291. hw->fc.low_water[i] >= hw->fc.high_water[i]) {
  292. hw_dbg(hw, "Invalid water mark configuration\n");
  293. return IXGBE_ERR_INVALID_LINK_SETTINGS;
  294. }
  295. }
  296. }
  297. /*
  298. * On 82598 having Rx FC on causes resets while doing 1G
  299. * so if it's on turn it off once we know link_speed. For
  300. * more details see 82598 Specification update.
  301. */
  302. hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
  303. if (link_up && link_speed == IXGBE_LINK_SPEED_1GB_FULL) {
  304. switch (hw->fc.requested_mode) {
  305. case ixgbe_fc_full:
  306. hw->fc.requested_mode = ixgbe_fc_tx_pause;
  307. break;
  308. case ixgbe_fc_rx_pause:
  309. hw->fc.requested_mode = ixgbe_fc_none;
  310. break;
  311. default:
  312. /* no change */
  313. break;
  314. }
  315. }
  316. /* Negotiate the fc mode to use */
  317. ixgbe_fc_autoneg(hw);
  318. /* Disable any previous flow control settings */
  319. fctrl_reg = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  320. fctrl_reg &= ~(IXGBE_FCTRL_RFCE | IXGBE_FCTRL_RPFCE);
  321. rmcs_reg = IXGBE_READ_REG(hw, IXGBE_RMCS);
  322. rmcs_reg &= ~(IXGBE_RMCS_TFCE_PRIORITY | IXGBE_RMCS_TFCE_802_3X);
  323. /*
  324. * The possible values of fc.current_mode are:
  325. * 0: Flow control is completely disabled
  326. * 1: Rx flow control is enabled (we can receive pause frames,
  327. * but not send pause frames).
  328. * 2: Tx flow control is enabled (we can send pause frames but
  329. * we do not support receiving pause frames).
  330. * 3: Both Rx and Tx flow control (symmetric) are enabled.
  331. * other: Invalid.
  332. */
  333. switch (hw->fc.current_mode) {
  334. case ixgbe_fc_none:
  335. /*
  336. * Flow control is disabled by software override or autoneg.
  337. * The code below will actually disable it in the HW.
  338. */
  339. break;
  340. case ixgbe_fc_rx_pause:
  341. /*
  342. * Rx Flow control is enabled and Tx Flow control is
  343. * disabled by software override. Since there really
  344. * isn't a way to advertise that we are capable of RX
  345. * Pause ONLY, we will advertise that we support both
  346. * symmetric and asymmetric Rx PAUSE. Later, we will
  347. * disable the adapter's ability to send PAUSE frames.
  348. */
  349. fctrl_reg |= IXGBE_FCTRL_RFCE;
  350. break;
  351. case ixgbe_fc_tx_pause:
  352. /*
  353. * Tx Flow control is enabled, and Rx Flow control is
  354. * disabled by software override.
  355. */
  356. rmcs_reg |= IXGBE_RMCS_TFCE_802_3X;
  357. break;
  358. case ixgbe_fc_full:
  359. /* Flow control (both Rx and Tx) is enabled by SW override. */
  360. fctrl_reg |= IXGBE_FCTRL_RFCE;
  361. rmcs_reg |= IXGBE_RMCS_TFCE_802_3X;
  362. break;
  363. default:
  364. hw_dbg(hw, "Flow control param set incorrectly\n");
  365. return IXGBE_ERR_CONFIG;
  366. }
  367. /* Set 802.3x based flow control settings. */
  368. fctrl_reg |= IXGBE_FCTRL_DPF;
  369. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl_reg);
  370. IXGBE_WRITE_REG(hw, IXGBE_RMCS, rmcs_reg);
  371. /* Set up and enable Rx high/low water mark thresholds, enable XON. */
  372. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  373. if ((hw->fc.current_mode & ixgbe_fc_tx_pause) &&
  374. hw->fc.high_water[i]) {
  375. fcrtl = (hw->fc.low_water[i] << 10) | IXGBE_FCRTL_XONE;
  376. fcrth = (hw->fc.high_water[i] << 10) | IXGBE_FCRTH_FCEN;
  377. IXGBE_WRITE_REG(hw, IXGBE_FCRTL(i), fcrtl);
  378. IXGBE_WRITE_REG(hw, IXGBE_FCRTH(i), fcrth);
  379. } else {
  380. IXGBE_WRITE_REG(hw, IXGBE_FCRTL(i), 0);
  381. IXGBE_WRITE_REG(hw, IXGBE_FCRTH(i), 0);
  382. }
  383. }
  384. /* Configure pause time (2 TCs per register) */
  385. reg = hw->fc.pause_time * 0x00010001;
  386. for (i = 0; i < (MAX_TRAFFIC_CLASS / 2); i++)
  387. IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg);
  388. /* Configure flow control refresh threshold value */
  389. IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2);
  390. return 0;
  391. }
  392. /**
  393. * ixgbe_start_mac_link_82598 - Configures MAC link settings
  394. * @hw: pointer to hardware structure
  395. *
  396. * Configures link settings based on values in the ixgbe_hw struct.
  397. * Restarts the link. Performs autonegotiation if needed.
  398. **/
  399. static s32 ixgbe_start_mac_link_82598(struct ixgbe_hw *hw,
  400. bool autoneg_wait_to_complete)
  401. {
  402. u32 autoc_reg;
  403. u32 links_reg;
  404. u32 i;
  405. s32 status = 0;
  406. /* Restart link */
  407. autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  408. autoc_reg |= IXGBE_AUTOC_AN_RESTART;
  409. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
  410. /* Only poll for autoneg to complete if specified to do so */
  411. if (autoneg_wait_to_complete) {
  412. if ((autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
  413. IXGBE_AUTOC_LMS_KX4_AN ||
  414. (autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
  415. IXGBE_AUTOC_LMS_KX4_AN_1G_AN) {
  416. links_reg = 0; /* Just in case Autoneg time = 0 */
  417. for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
  418. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  419. if (links_reg & IXGBE_LINKS_KX_AN_COMP)
  420. break;
  421. msleep(100);
  422. }
  423. if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
  424. status = IXGBE_ERR_AUTONEG_NOT_COMPLETE;
  425. hw_dbg(hw, "Autonegotiation did not complete.\n");
  426. }
  427. }
  428. }
  429. /* Add delay to filter out noises during initial link setup */
  430. msleep(50);
  431. return status;
  432. }
  433. /**
  434. * ixgbe_validate_link_ready - Function looks for phy link
  435. * @hw: pointer to hardware structure
  436. *
  437. * Function indicates success when phy link is available. If phy is not ready
  438. * within 5 seconds of MAC indicating link, the function returns error.
  439. **/
  440. static s32 ixgbe_validate_link_ready(struct ixgbe_hw *hw)
  441. {
  442. u32 timeout;
  443. u16 an_reg;
  444. if (hw->device_id != IXGBE_DEV_ID_82598AT2)
  445. return 0;
  446. for (timeout = 0;
  447. timeout < IXGBE_VALIDATE_LINK_READY_TIMEOUT; timeout++) {
  448. hw->phy.ops.read_reg(hw, MDIO_STAT1, MDIO_MMD_AN, &an_reg);
  449. if ((an_reg & MDIO_AN_STAT1_COMPLETE) &&
  450. (an_reg & MDIO_STAT1_LSTATUS))
  451. break;
  452. msleep(100);
  453. }
  454. if (timeout == IXGBE_VALIDATE_LINK_READY_TIMEOUT) {
  455. hw_dbg(hw, "Link was indicated but link is down\n");
  456. return IXGBE_ERR_LINK_SETUP;
  457. }
  458. return 0;
  459. }
  460. /**
  461. * ixgbe_check_mac_link_82598 - Get link/speed status
  462. * @hw: pointer to hardware structure
  463. * @speed: pointer to link speed
  464. * @link_up: true is link is up, false otherwise
  465. * @link_up_wait_to_complete: bool used to wait for link up or not
  466. *
  467. * Reads the links register to determine if link is up and the current speed
  468. **/
  469. static s32 ixgbe_check_mac_link_82598(struct ixgbe_hw *hw,
  470. ixgbe_link_speed *speed, bool *link_up,
  471. bool link_up_wait_to_complete)
  472. {
  473. u32 links_reg;
  474. u32 i;
  475. u16 link_reg, adapt_comp_reg;
  476. /*
  477. * SERDES PHY requires us to read link status from register 0xC79F.
  478. * Bit 0 set indicates link is up/ready; clear indicates link down.
  479. * 0xC00C is read to check that the XAUI lanes are active. Bit 0
  480. * clear indicates active; set indicates inactive.
  481. */
  482. if (hw->phy.type == ixgbe_phy_nl) {
  483. hw->phy.ops.read_reg(hw, 0xC79F, MDIO_MMD_PMAPMD, &link_reg);
  484. hw->phy.ops.read_reg(hw, 0xC79F, MDIO_MMD_PMAPMD, &link_reg);
  485. hw->phy.ops.read_reg(hw, 0xC00C, MDIO_MMD_PMAPMD,
  486. &adapt_comp_reg);
  487. if (link_up_wait_to_complete) {
  488. for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
  489. if ((link_reg & 1) &&
  490. ((adapt_comp_reg & 1) == 0)) {
  491. *link_up = true;
  492. break;
  493. } else {
  494. *link_up = false;
  495. }
  496. msleep(100);
  497. hw->phy.ops.read_reg(hw, 0xC79F,
  498. MDIO_MMD_PMAPMD,
  499. &link_reg);
  500. hw->phy.ops.read_reg(hw, 0xC00C,
  501. MDIO_MMD_PMAPMD,
  502. &adapt_comp_reg);
  503. }
  504. } else {
  505. if ((link_reg & 1) && ((adapt_comp_reg & 1) == 0))
  506. *link_up = true;
  507. else
  508. *link_up = false;
  509. }
  510. if (!*link_up)
  511. return 0;
  512. }
  513. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  514. if (link_up_wait_to_complete) {
  515. for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
  516. if (links_reg & IXGBE_LINKS_UP) {
  517. *link_up = true;
  518. break;
  519. } else {
  520. *link_up = false;
  521. }
  522. msleep(100);
  523. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  524. }
  525. } else {
  526. if (links_reg & IXGBE_LINKS_UP)
  527. *link_up = true;
  528. else
  529. *link_up = false;
  530. }
  531. if (links_reg & IXGBE_LINKS_SPEED)
  532. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  533. else
  534. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  535. if ((hw->device_id == IXGBE_DEV_ID_82598AT2) && *link_up &&
  536. (ixgbe_validate_link_ready(hw) != 0))
  537. *link_up = false;
  538. return 0;
  539. }
  540. /**
  541. * ixgbe_setup_mac_link_82598 - Set MAC link speed
  542. * @hw: pointer to hardware structure
  543. * @speed: new link speed
  544. * @autoneg_wait_to_complete: true when waiting for completion is needed
  545. *
  546. * Set the link speed in the AUTOC register and restarts link.
  547. **/
  548. static s32 ixgbe_setup_mac_link_82598(struct ixgbe_hw *hw,
  549. ixgbe_link_speed speed,
  550. bool autoneg_wait_to_complete)
  551. {
  552. bool autoneg = false;
  553. ixgbe_link_speed link_capabilities = IXGBE_LINK_SPEED_UNKNOWN;
  554. u32 curr_autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  555. u32 autoc = curr_autoc;
  556. u32 link_mode = autoc & IXGBE_AUTOC_LMS_MASK;
  557. /* Check to see if speed passed in is supported. */
  558. ixgbe_get_link_capabilities_82598(hw, &link_capabilities, &autoneg);
  559. speed &= link_capabilities;
  560. if (speed == IXGBE_LINK_SPEED_UNKNOWN)
  561. return IXGBE_ERR_LINK_SETUP;
  562. /* Set KX4/KX support according to speed requested */
  563. else if (link_mode == IXGBE_AUTOC_LMS_KX4_AN ||
  564. link_mode == IXGBE_AUTOC_LMS_KX4_AN_1G_AN) {
  565. autoc &= ~IXGBE_AUTOC_KX4_KX_SUPP_MASK;
  566. if (speed & IXGBE_LINK_SPEED_10GB_FULL)
  567. autoc |= IXGBE_AUTOC_KX4_SUPP;
  568. if (speed & IXGBE_LINK_SPEED_1GB_FULL)
  569. autoc |= IXGBE_AUTOC_KX_SUPP;
  570. if (autoc != curr_autoc)
  571. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc);
  572. }
  573. /* Setup and restart the link based on the new values in
  574. * ixgbe_hw This will write the AUTOC register based on the new
  575. * stored values
  576. */
  577. return ixgbe_start_mac_link_82598(hw, autoneg_wait_to_complete);
  578. }
  579. /**
  580. * ixgbe_setup_copper_link_82598 - Set the PHY autoneg advertised field
  581. * @hw: pointer to hardware structure
  582. * @speed: new link speed
  583. * @autoneg_wait_to_complete: true if waiting is needed to complete
  584. *
  585. * Sets the link speed in the AUTOC register in the MAC and restarts link.
  586. **/
  587. static s32 ixgbe_setup_copper_link_82598(struct ixgbe_hw *hw,
  588. ixgbe_link_speed speed,
  589. bool autoneg_wait_to_complete)
  590. {
  591. s32 status;
  592. /* Setup the PHY according to input speed */
  593. status = hw->phy.ops.setup_link_speed(hw, speed,
  594. autoneg_wait_to_complete);
  595. /* Set up MAC */
  596. ixgbe_start_mac_link_82598(hw, autoneg_wait_to_complete);
  597. return status;
  598. }
  599. /**
  600. * ixgbe_reset_hw_82598 - Performs hardware reset
  601. * @hw: pointer to hardware structure
  602. *
  603. * Resets the hardware by resetting the transmit and receive units, masks and
  604. * clears all interrupts, performing a PHY reset, and performing a link (MAC)
  605. * reset.
  606. **/
  607. static s32 ixgbe_reset_hw_82598(struct ixgbe_hw *hw)
  608. {
  609. s32 status;
  610. s32 phy_status = 0;
  611. u32 ctrl;
  612. u32 gheccr;
  613. u32 i;
  614. u32 autoc;
  615. u8 analog_val;
  616. /* Call adapter stop to disable tx/rx and clear interrupts */
  617. status = hw->mac.ops.stop_adapter(hw);
  618. if (status)
  619. return status;
  620. /*
  621. * Power up the Atlas Tx lanes if they are currently powered down.
  622. * Atlas Tx lanes are powered down for MAC loopback tests, but
  623. * they are not automatically restored on reset.
  624. */
  625. hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK, &analog_val);
  626. if (analog_val & IXGBE_ATLAS_PDN_TX_REG_EN) {
  627. /* Enable Tx Atlas so packets can be transmitted again */
  628. hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK,
  629. &analog_val);
  630. analog_val &= ~IXGBE_ATLAS_PDN_TX_REG_EN;
  631. hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK,
  632. analog_val);
  633. hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_10G,
  634. &analog_val);
  635. analog_val &= ~IXGBE_ATLAS_PDN_TX_10G_QL_ALL;
  636. hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_10G,
  637. analog_val);
  638. hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_1G,
  639. &analog_val);
  640. analog_val &= ~IXGBE_ATLAS_PDN_TX_1G_QL_ALL;
  641. hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_1G,
  642. analog_val);
  643. hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_AN,
  644. &analog_val);
  645. analog_val &= ~IXGBE_ATLAS_PDN_TX_AN_QL_ALL;
  646. hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_AN,
  647. analog_val);
  648. }
  649. /* Reset PHY */
  650. if (hw->phy.reset_disable == false) {
  651. /* PHY ops must be identified and initialized prior to reset */
  652. /* Init PHY and function pointers, perform SFP setup */
  653. phy_status = hw->phy.ops.init(hw);
  654. if (phy_status == IXGBE_ERR_SFP_NOT_SUPPORTED)
  655. return phy_status;
  656. if (phy_status == IXGBE_ERR_SFP_NOT_PRESENT)
  657. goto mac_reset_top;
  658. hw->phy.ops.reset(hw);
  659. }
  660. mac_reset_top:
  661. /*
  662. * Issue global reset to the MAC. This needs to be a SW reset.
  663. * If link reset is used, it might reset the MAC when mng is using it
  664. */
  665. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL) | IXGBE_CTRL_RST;
  666. IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
  667. IXGBE_WRITE_FLUSH(hw);
  668. /* Poll for reset bit to self-clear indicating reset is complete */
  669. for (i = 0; i < 10; i++) {
  670. udelay(1);
  671. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  672. if (!(ctrl & IXGBE_CTRL_RST))
  673. break;
  674. }
  675. if (ctrl & IXGBE_CTRL_RST) {
  676. status = IXGBE_ERR_RESET_FAILED;
  677. hw_dbg(hw, "Reset polling failed to complete.\n");
  678. }
  679. msleep(50);
  680. /*
  681. * Double resets are required for recovery from certain error
  682. * conditions. Between resets, it is necessary to stall to allow time
  683. * for any pending HW events to complete.
  684. */
  685. if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
  686. hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
  687. goto mac_reset_top;
  688. }
  689. gheccr = IXGBE_READ_REG(hw, IXGBE_GHECCR);
  690. gheccr &= ~((1 << 21) | (1 << 18) | (1 << 9) | (1 << 6));
  691. IXGBE_WRITE_REG(hw, IXGBE_GHECCR, gheccr);
  692. /*
  693. * Store the original AUTOC value if it has not been
  694. * stored off yet. Otherwise restore the stored original
  695. * AUTOC value since the reset operation sets back to deaults.
  696. */
  697. autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  698. if (hw->mac.orig_link_settings_stored == false) {
  699. hw->mac.orig_autoc = autoc;
  700. hw->mac.orig_link_settings_stored = true;
  701. } else if (autoc != hw->mac.orig_autoc) {
  702. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, hw->mac.orig_autoc);
  703. }
  704. /* Store the permanent mac address */
  705. hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
  706. /*
  707. * Store MAC address from RAR0, clear receive address registers, and
  708. * clear the multicast table
  709. */
  710. hw->mac.ops.init_rx_addrs(hw);
  711. if (phy_status)
  712. status = phy_status;
  713. return status;
  714. }
  715. /**
  716. * ixgbe_set_vmdq_82598 - Associate a VMDq set index with a rx address
  717. * @hw: pointer to hardware struct
  718. * @rar: receive address register index to associate with a VMDq index
  719. * @vmdq: VMDq set index
  720. **/
  721. static s32 ixgbe_set_vmdq_82598(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
  722. {
  723. u32 rar_high;
  724. u32 rar_entries = hw->mac.num_rar_entries;
  725. /* Make sure we are using a valid rar index range */
  726. if (rar >= rar_entries) {
  727. hw_dbg(hw, "RAR index %d is out of range.\n", rar);
  728. return IXGBE_ERR_INVALID_ARGUMENT;
  729. }
  730. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(rar));
  731. rar_high &= ~IXGBE_RAH_VIND_MASK;
  732. rar_high |= ((vmdq << IXGBE_RAH_VIND_SHIFT) & IXGBE_RAH_VIND_MASK);
  733. IXGBE_WRITE_REG(hw, IXGBE_RAH(rar), rar_high);
  734. return 0;
  735. }
  736. /**
  737. * ixgbe_clear_vmdq_82598 - Disassociate a VMDq set index from an rx address
  738. * @hw: pointer to hardware struct
  739. * @rar: receive address register index to associate with a VMDq index
  740. * @vmdq: VMDq clear index (not used in 82598, but elsewhere)
  741. **/
  742. static s32 ixgbe_clear_vmdq_82598(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
  743. {
  744. u32 rar_high;
  745. u32 rar_entries = hw->mac.num_rar_entries;
  746. /* Make sure we are using a valid rar index range */
  747. if (rar >= rar_entries) {
  748. hw_dbg(hw, "RAR index %d is out of range.\n", rar);
  749. return IXGBE_ERR_INVALID_ARGUMENT;
  750. }
  751. rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(rar));
  752. if (rar_high & IXGBE_RAH_VIND_MASK) {
  753. rar_high &= ~IXGBE_RAH_VIND_MASK;
  754. IXGBE_WRITE_REG(hw, IXGBE_RAH(rar), rar_high);
  755. }
  756. return 0;
  757. }
  758. /**
  759. * ixgbe_set_vfta_82598 - Set VLAN filter table
  760. * @hw: pointer to hardware structure
  761. * @vlan: VLAN id to write to VLAN filter
  762. * @vind: VMDq output index that maps queue to VLAN id in VFTA
  763. * @vlan_on: boolean flag to turn on/off VLAN in VFTA
  764. *
  765. * Turn on/off specified VLAN in the VLAN filter table.
  766. **/
  767. static s32 ixgbe_set_vfta_82598(struct ixgbe_hw *hw, u32 vlan, u32 vind,
  768. bool vlan_on)
  769. {
  770. u32 regindex;
  771. u32 bitindex;
  772. u32 bits;
  773. u32 vftabyte;
  774. if (vlan > 4095)
  775. return IXGBE_ERR_PARAM;
  776. /* Determine 32-bit word position in array */
  777. regindex = (vlan >> 5) & 0x7F; /* upper seven bits */
  778. /* Determine the location of the (VMD) queue index */
  779. vftabyte = ((vlan >> 3) & 0x03); /* bits (4:3) indicating byte array */
  780. bitindex = (vlan & 0x7) << 2; /* lower 3 bits indicate nibble */
  781. /* Set the nibble for VMD queue index */
  782. bits = IXGBE_READ_REG(hw, IXGBE_VFTAVIND(vftabyte, regindex));
  783. bits &= (~(0x0F << bitindex));
  784. bits |= (vind << bitindex);
  785. IXGBE_WRITE_REG(hw, IXGBE_VFTAVIND(vftabyte, regindex), bits);
  786. /* Determine the location of the bit for this VLAN id */
  787. bitindex = vlan & 0x1F; /* lower five bits */
  788. bits = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
  789. if (vlan_on)
  790. /* Turn on this VLAN id */
  791. bits |= (1 << bitindex);
  792. else
  793. /* Turn off this VLAN id */
  794. bits &= ~(1 << bitindex);
  795. IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), bits);
  796. return 0;
  797. }
  798. /**
  799. * ixgbe_clear_vfta_82598 - Clear VLAN filter table
  800. * @hw: pointer to hardware structure
  801. *
  802. * Clears the VLAN filer table, and the VMDq index associated with the filter
  803. **/
  804. static s32 ixgbe_clear_vfta_82598(struct ixgbe_hw *hw)
  805. {
  806. u32 offset;
  807. u32 vlanbyte;
  808. for (offset = 0; offset < hw->mac.vft_size; offset++)
  809. IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
  810. for (vlanbyte = 0; vlanbyte < 4; vlanbyte++)
  811. for (offset = 0; offset < hw->mac.vft_size; offset++)
  812. IXGBE_WRITE_REG(hw, IXGBE_VFTAVIND(vlanbyte, offset),
  813. 0);
  814. return 0;
  815. }
  816. /**
  817. * ixgbe_read_analog_reg8_82598 - Reads 8 bit Atlas analog register
  818. * @hw: pointer to hardware structure
  819. * @reg: analog register to read
  820. * @val: read value
  821. *
  822. * Performs read operation to Atlas analog register specified.
  823. **/
  824. static s32 ixgbe_read_analog_reg8_82598(struct ixgbe_hw *hw, u32 reg, u8 *val)
  825. {
  826. u32 atlas_ctl;
  827. IXGBE_WRITE_REG(hw, IXGBE_ATLASCTL,
  828. IXGBE_ATLASCTL_WRITE_CMD | (reg << 8));
  829. IXGBE_WRITE_FLUSH(hw);
  830. udelay(10);
  831. atlas_ctl = IXGBE_READ_REG(hw, IXGBE_ATLASCTL);
  832. *val = (u8)atlas_ctl;
  833. return 0;
  834. }
  835. /**
  836. * ixgbe_write_analog_reg8_82598 - Writes 8 bit Atlas analog register
  837. * @hw: pointer to hardware structure
  838. * @reg: atlas register to write
  839. * @val: value to write
  840. *
  841. * Performs write operation to Atlas analog register specified.
  842. **/
  843. static s32 ixgbe_write_analog_reg8_82598(struct ixgbe_hw *hw, u32 reg, u8 val)
  844. {
  845. u32 atlas_ctl;
  846. atlas_ctl = (reg << 8) | val;
  847. IXGBE_WRITE_REG(hw, IXGBE_ATLASCTL, atlas_ctl);
  848. IXGBE_WRITE_FLUSH(hw);
  849. udelay(10);
  850. return 0;
  851. }
  852. /**
  853. * ixgbe_read_i2c_phy_82598 - Reads 8 bit word over I2C interface.
  854. * @hw: pointer to hardware structure
  855. * @dev_addr: address to read from
  856. * @byte_offset: byte offset to read from dev_addr
  857. * @eeprom_data: value read
  858. *
  859. * Performs 8 byte read operation to SFP module's data over I2C interface.
  860. **/
  861. static s32 ixgbe_read_i2c_phy_82598(struct ixgbe_hw *hw, u8 dev_addr,
  862. u8 byte_offset, u8 *eeprom_data)
  863. {
  864. s32 status = 0;
  865. u16 sfp_addr = 0;
  866. u16 sfp_data = 0;
  867. u16 sfp_stat = 0;
  868. u16 gssr;
  869. u32 i;
  870. if (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)
  871. gssr = IXGBE_GSSR_PHY1_SM;
  872. else
  873. gssr = IXGBE_GSSR_PHY0_SM;
  874. if (hw->mac.ops.acquire_swfw_sync(hw, gssr) != 0)
  875. return IXGBE_ERR_SWFW_SYNC;
  876. if (hw->phy.type == ixgbe_phy_nl) {
  877. /*
  878. * phy SDA/SCL registers are at addresses 0xC30A to
  879. * 0xC30D. These registers are used to talk to the SFP+
  880. * module's EEPROM through the SDA/SCL (I2C) interface.
  881. */
  882. sfp_addr = (dev_addr << 8) + byte_offset;
  883. sfp_addr = (sfp_addr | IXGBE_I2C_EEPROM_READ_MASK);
  884. hw->phy.ops.write_reg_mdi(hw,
  885. IXGBE_MDIO_PMA_PMD_SDA_SCL_ADDR,
  886. MDIO_MMD_PMAPMD,
  887. sfp_addr);
  888. /* Poll status */
  889. for (i = 0; i < 100; i++) {
  890. hw->phy.ops.read_reg_mdi(hw,
  891. IXGBE_MDIO_PMA_PMD_SDA_SCL_STAT,
  892. MDIO_MMD_PMAPMD,
  893. &sfp_stat);
  894. sfp_stat = sfp_stat & IXGBE_I2C_EEPROM_STATUS_MASK;
  895. if (sfp_stat != IXGBE_I2C_EEPROM_STATUS_IN_PROGRESS)
  896. break;
  897. usleep_range(10000, 20000);
  898. }
  899. if (sfp_stat != IXGBE_I2C_EEPROM_STATUS_PASS) {
  900. hw_dbg(hw, "EEPROM read did not pass.\n");
  901. status = IXGBE_ERR_SFP_NOT_PRESENT;
  902. goto out;
  903. }
  904. /* Read data */
  905. hw->phy.ops.read_reg_mdi(hw, IXGBE_MDIO_PMA_PMD_SDA_SCL_DATA,
  906. MDIO_MMD_PMAPMD, &sfp_data);
  907. *eeprom_data = (u8)(sfp_data >> 8);
  908. } else {
  909. status = IXGBE_ERR_PHY;
  910. }
  911. out:
  912. hw->mac.ops.release_swfw_sync(hw, gssr);
  913. return status;
  914. }
  915. /**
  916. * ixgbe_read_i2c_eeprom_82598 - Reads 8 bit word over I2C interface.
  917. * @hw: pointer to hardware structure
  918. * @byte_offset: EEPROM byte offset to read
  919. * @eeprom_data: value read
  920. *
  921. * Performs 8 byte read operation to SFP module's EEPROM over I2C interface.
  922. **/
  923. static s32 ixgbe_read_i2c_eeprom_82598(struct ixgbe_hw *hw, u8 byte_offset,
  924. u8 *eeprom_data)
  925. {
  926. return ixgbe_read_i2c_phy_82598(hw, IXGBE_I2C_EEPROM_DEV_ADDR,
  927. byte_offset, eeprom_data);
  928. }
  929. /**
  930. * ixgbe_read_i2c_sff8472_82598 - Reads 8 bit word over I2C interface.
  931. * @hw: pointer to hardware structure
  932. * @byte_offset: byte offset at address 0xA2
  933. * @eeprom_data: value read
  934. *
  935. * Performs 8 byte read operation to SFP module's SFF-8472 data over I2C
  936. **/
  937. static s32 ixgbe_read_i2c_sff8472_82598(struct ixgbe_hw *hw, u8 byte_offset,
  938. u8 *sff8472_data)
  939. {
  940. return ixgbe_read_i2c_phy_82598(hw, IXGBE_I2C_EEPROM_DEV_ADDR2,
  941. byte_offset, sff8472_data);
  942. }
  943. /**
  944. * ixgbe_set_lan_id_multi_port_pcie_82598 - Set LAN id for PCIe multiple
  945. * port devices.
  946. * @hw: pointer to the HW structure
  947. *
  948. * Calls common function and corrects issue with some single port devices
  949. * that enable LAN1 but not LAN0.
  950. **/
  951. static void ixgbe_set_lan_id_multi_port_pcie_82598(struct ixgbe_hw *hw)
  952. {
  953. struct ixgbe_bus_info *bus = &hw->bus;
  954. u16 pci_gen = 0;
  955. u16 pci_ctrl2 = 0;
  956. ixgbe_set_lan_id_multi_port_pcie(hw);
  957. /* check if LAN0 is disabled */
  958. hw->eeprom.ops.read(hw, IXGBE_PCIE_GENERAL_PTR, &pci_gen);
  959. if ((pci_gen != 0) && (pci_gen != 0xFFFF)) {
  960. hw->eeprom.ops.read(hw, pci_gen + IXGBE_PCIE_CTRL2, &pci_ctrl2);
  961. /* if LAN0 is completely disabled force function to 0 */
  962. if ((pci_ctrl2 & IXGBE_PCIE_CTRL2_LAN_DISABLE) &&
  963. !(pci_ctrl2 & IXGBE_PCIE_CTRL2_DISABLE_SELECT) &&
  964. !(pci_ctrl2 & IXGBE_PCIE_CTRL2_DUMMY_ENABLE)) {
  965. bus->func = 0;
  966. }
  967. }
  968. }
  969. /**
  970. * ixgbe_set_rxpba_82598 - Initialize RX packet buffer
  971. * @hw: pointer to hardware structure
  972. * @num_pb: number of packet buffers to allocate
  973. * @headroom: reserve n KB of headroom
  974. * @strategy: packet buffer allocation strategy
  975. **/
  976. static void ixgbe_set_rxpba_82598(struct ixgbe_hw *hw, int num_pb,
  977. u32 headroom, int strategy)
  978. {
  979. u32 rxpktsize = IXGBE_RXPBSIZE_64KB;
  980. u8 i = 0;
  981. if (!num_pb)
  982. return;
  983. /* Setup Rx packet buffer sizes */
  984. switch (strategy) {
  985. case PBA_STRATEGY_WEIGHTED:
  986. /* Setup the first four at 80KB */
  987. rxpktsize = IXGBE_RXPBSIZE_80KB;
  988. for (; i < 4; i++)
  989. IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize);
  990. /* Setup the last four at 48KB...don't re-init i */
  991. rxpktsize = IXGBE_RXPBSIZE_48KB;
  992. /* Fall Through */
  993. case PBA_STRATEGY_EQUAL:
  994. default:
  995. /* Divide the remaining Rx packet buffer evenly among the TCs */
  996. for (; i < IXGBE_MAX_PACKET_BUFFERS; i++)
  997. IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize);
  998. break;
  999. }
  1000. /* Setup Tx packet buffer sizes */
  1001. for (i = 0; i < IXGBE_MAX_PACKET_BUFFERS; i++)
  1002. IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), IXGBE_TXPBSIZE_40KB);
  1003. }
  1004. static struct ixgbe_mac_operations mac_ops_82598 = {
  1005. .init_hw = &ixgbe_init_hw_generic,
  1006. .reset_hw = &ixgbe_reset_hw_82598,
  1007. .start_hw = &ixgbe_start_hw_82598,
  1008. .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic,
  1009. .get_media_type = &ixgbe_get_media_type_82598,
  1010. .enable_rx_dma = &ixgbe_enable_rx_dma_generic,
  1011. .get_mac_addr = &ixgbe_get_mac_addr_generic,
  1012. .stop_adapter = &ixgbe_stop_adapter_generic,
  1013. .get_bus_info = &ixgbe_get_bus_info_generic,
  1014. .set_lan_id = &ixgbe_set_lan_id_multi_port_pcie_82598,
  1015. .read_analog_reg8 = &ixgbe_read_analog_reg8_82598,
  1016. .write_analog_reg8 = &ixgbe_write_analog_reg8_82598,
  1017. .setup_link = &ixgbe_setup_mac_link_82598,
  1018. .set_rxpba = &ixgbe_set_rxpba_82598,
  1019. .check_link = &ixgbe_check_mac_link_82598,
  1020. .get_link_capabilities = &ixgbe_get_link_capabilities_82598,
  1021. .led_on = &ixgbe_led_on_generic,
  1022. .led_off = &ixgbe_led_off_generic,
  1023. .blink_led_start = &ixgbe_blink_led_start_generic,
  1024. .blink_led_stop = &ixgbe_blink_led_stop_generic,
  1025. .set_rar = &ixgbe_set_rar_generic,
  1026. .clear_rar = &ixgbe_clear_rar_generic,
  1027. .set_vmdq = &ixgbe_set_vmdq_82598,
  1028. .clear_vmdq = &ixgbe_clear_vmdq_82598,
  1029. .init_rx_addrs = &ixgbe_init_rx_addrs_generic,
  1030. .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic,
  1031. .enable_mc = &ixgbe_enable_mc_generic,
  1032. .disable_mc = &ixgbe_disable_mc_generic,
  1033. .clear_vfta = &ixgbe_clear_vfta_82598,
  1034. .set_vfta = &ixgbe_set_vfta_82598,
  1035. .fc_enable = &ixgbe_fc_enable_82598,
  1036. .set_fw_drv_ver = NULL,
  1037. .acquire_swfw_sync = &ixgbe_acquire_swfw_sync,
  1038. .release_swfw_sync = &ixgbe_release_swfw_sync,
  1039. .get_thermal_sensor_data = NULL,
  1040. .init_thermal_sensor_thresh = NULL,
  1041. .prot_autoc_read = &prot_autoc_read_generic,
  1042. .prot_autoc_write = &prot_autoc_write_generic,
  1043. .enable_rx = &ixgbe_enable_rx_generic,
  1044. .disable_rx = &ixgbe_disable_rx_generic,
  1045. };
  1046. static struct ixgbe_eeprom_operations eeprom_ops_82598 = {
  1047. .init_params = &ixgbe_init_eeprom_params_generic,
  1048. .read = &ixgbe_read_eerd_generic,
  1049. .write = &ixgbe_write_eeprom_generic,
  1050. .write_buffer = &ixgbe_write_eeprom_buffer_bit_bang_generic,
  1051. .read_buffer = &ixgbe_read_eerd_buffer_generic,
  1052. .calc_checksum = &ixgbe_calc_eeprom_checksum_generic,
  1053. .validate_checksum = &ixgbe_validate_eeprom_checksum_generic,
  1054. .update_checksum = &ixgbe_update_eeprom_checksum_generic,
  1055. };
  1056. static struct ixgbe_phy_operations phy_ops_82598 = {
  1057. .identify = &ixgbe_identify_phy_generic,
  1058. .identify_sfp = &ixgbe_identify_module_generic,
  1059. .init = &ixgbe_init_phy_ops_82598,
  1060. .reset = &ixgbe_reset_phy_generic,
  1061. .read_reg = &ixgbe_read_phy_reg_generic,
  1062. .write_reg = &ixgbe_write_phy_reg_generic,
  1063. .read_reg_mdi = &ixgbe_read_phy_reg_mdi,
  1064. .write_reg_mdi = &ixgbe_write_phy_reg_mdi,
  1065. .setup_link = &ixgbe_setup_phy_link_generic,
  1066. .setup_link_speed = &ixgbe_setup_phy_link_speed_generic,
  1067. .read_i2c_sff8472 = &ixgbe_read_i2c_sff8472_82598,
  1068. .read_i2c_eeprom = &ixgbe_read_i2c_eeprom_82598,
  1069. .check_overtemp = &ixgbe_tn_check_overtemp,
  1070. };
  1071. struct ixgbe_info ixgbe_82598_info = {
  1072. .mac = ixgbe_mac_82598EB,
  1073. .get_invariants = &ixgbe_get_invariants_82598,
  1074. .mac_ops = &mac_ops_82598,
  1075. .eeprom_ops = &eeprom_ops_82598,
  1076. .phy_ops = &phy_ops_82598,
  1077. .mvals = ixgbe_mvals_8259X,
  1078. };