ixgbe_82598.c 34 KB

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