ixgbe_82599.c 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2013 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. #include "ixgbe_mbx.h"
  26. #define IXGBE_82599_MAX_TX_QUEUES 128
  27. #define IXGBE_82599_MAX_RX_QUEUES 128
  28. #define IXGBE_82599_RAR_ENTRIES 128
  29. #define IXGBE_82599_MC_TBL_SIZE 128
  30. #define IXGBE_82599_VFT_TBL_SIZE 128
  31. #define IXGBE_82599_RX_PB_SIZE 512
  32. static void ixgbe_disable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw);
  33. static void ixgbe_enable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw);
  34. static void ixgbe_flap_tx_laser_multispeed_fiber(struct ixgbe_hw *hw);
  35. static s32 ixgbe_setup_mac_link_multispeed_fiber(struct ixgbe_hw *hw,
  36. ixgbe_link_speed speed,
  37. bool autoneg_wait_to_complete);
  38. static s32 ixgbe_setup_mac_link_smartspeed(struct ixgbe_hw *hw,
  39. ixgbe_link_speed speed,
  40. bool autoneg_wait_to_complete);
  41. static s32 ixgbe_start_mac_link_82599(struct ixgbe_hw *hw,
  42. bool autoneg_wait_to_complete);
  43. static s32 ixgbe_setup_mac_link_82599(struct ixgbe_hw *hw,
  44. ixgbe_link_speed speed,
  45. bool autoneg_wait_to_complete);
  46. static s32 ixgbe_setup_copper_link_82599(struct ixgbe_hw *hw,
  47. ixgbe_link_speed speed,
  48. bool autoneg_wait_to_complete);
  49. static s32 ixgbe_verify_fw_version_82599(struct ixgbe_hw *hw);
  50. static bool ixgbe_mng_enabled(struct ixgbe_hw *hw)
  51. {
  52. u32 fwsm, manc, factps;
  53. fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM);
  54. if ((fwsm & IXGBE_FWSM_MODE_MASK) != IXGBE_FWSM_FW_MODE_PT)
  55. return false;
  56. manc = IXGBE_READ_REG(hw, IXGBE_MANC);
  57. if (!(manc & IXGBE_MANC_RCV_TCO_EN))
  58. return false;
  59. factps = IXGBE_READ_REG(hw, IXGBE_FACTPS);
  60. if (factps & IXGBE_FACTPS_MNGCG)
  61. return false;
  62. return true;
  63. }
  64. static void ixgbe_init_mac_link_ops_82599(struct ixgbe_hw *hw)
  65. {
  66. struct ixgbe_mac_info *mac = &hw->mac;
  67. /* enable the laser control functions for SFP+ fiber
  68. * and MNG not enabled
  69. */
  70. if ((mac->ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
  71. !hw->mng_fw_enabled) {
  72. mac->ops.disable_tx_laser =
  73. &ixgbe_disable_tx_laser_multispeed_fiber;
  74. mac->ops.enable_tx_laser =
  75. &ixgbe_enable_tx_laser_multispeed_fiber;
  76. mac->ops.flap_tx_laser = &ixgbe_flap_tx_laser_multispeed_fiber;
  77. } else {
  78. mac->ops.disable_tx_laser = NULL;
  79. mac->ops.enable_tx_laser = NULL;
  80. mac->ops.flap_tx_laser = NULL;
  81. }
  82. if (hw->phy.multispeed_fiber) {
  83. /* Set up dual speed SFP+ support */
  84. mac->ops.setup_link = &ixgbe_setup_mac_link_multispeed_fiber;
  85. } else {
  86. if ((mac->ops.get_media_type(hw) ==
  87. ixgbe_media_type_backplane) &&
  88. (hw->phy.smart_speed == ixgbe_smart_speed_auto ||
  89. hw->phy.smart_speed == ixgbe_smart_speed_on) &&
  90. !ixgbe_verify_lesm_fw_enabled_82599(hw))
  91. mac->ops.setup_link = &ixgbe_setup_mac_link_smartspeed;
  92. else
  93. mac->ops.setup_link = &ixgbe_setup_mac_link_82599;
  94. }
  95. }
  96. static s32 ixgbe_setup_sfp_modules_82599(struct ixgbe_hw *hw)
  97. {
  98. s32 ret_val = 0;
  99. u16 list_offset, data_offset, data_value;
  100. bool got_lock = false;
  101. if (hw->phy.sfp_type != ixgbe_sfp_type_unknown) {
  102. ixgbe_init_mac_link_ops_82599(hw);
  103. hw->phy.ops.reset = NULL;
  104. ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
  105. &data_offset);
  106. if (ret_val != 0)
  107. goto setup_sfp_out;
  108. /* PHY config will finish before releasing the semaphore */
  109. ret_val = hw->mac.ops.acquire_swfw_sync(hw,
  110. IXGBE_GSSR_MAC_CSR_SM);
  111. if (ret_val != 0) {
  112. ret_val = IXGBE_ERR_SWFW_SYNC;
  113. goto setup_sfp_out;
  114. }
  115. hw->eeprom.ops.read(hw, ++data_offset, &data_value);
  116. while (data_value != 0xffff) {
  117. IXGBE_WRITE_REG(hw, IXGBE_CORECTL, data_value);
  118. IXGBE_WRITE_FLUSH(hw);
  119. hw->eeprom.ops.read(hw, ++data_offset, &data_value);
  120. }
  121. /* Release the semaphore */
  122. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
  123. /*
  124. * Delay obtaining semaphore again to allow FW access,
  125. * semaphore_delay is in ms usleep_range needs us.
  126. */
  127. usleep_range(hw->eeprom.semaphore_delay * 1000,
  128. hw->eeprom.semaphore_delay * 2000);
  129. /* Need SW/FW semaphore around AUTOC writes if LESM on,
  130. * likewise reset_pipeline requires lock as it also writes
  131. * AUTOC.
  132. */
  133. if (ixgbe_verify_lesm_fw_enabled_82599(hw)) {
  134. ret_val = hw->mac.ops.acquire_swfw_sync(hw,
  135. IXGBE_GSSR_MAC_CSR_SM);
  136. if (ret_val)
  137. goto setup_sfp_out;
  138. got_lock = true;
  139. }
  140. /* Restart DSP and set SFI mode */
  141. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, ((hw->mac.orig_autoc) |
  142. IXGBE_AUTOC_LMS_10G_SERIAL));
  143. hw->mac.cached_autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  144. ret_val = ixgbe_reset_pipeline_82599(hw);
  145. if (got_lock) {
  146. hw->mac.ops.release_swfw_sync(hw,
  147. IXGBE_GSSR_MAC_CSR_SM);
  148. got_lock = false;
  149. }
  150. if (ret_val) {
  151. hw_dbg(hw, " sfp module setup not complete\n");
  152. ret_val = IXGBE_ERR_SFP_SETUP_NOT_COMPLETE;
  153. goto setup_sfp_out;
  154. }
  155. }
  156. setup_sfp_out:
  157. return ret_val;
  158. }
  159. static s32 ixgbe_get_invariants_82599(struct ixgbe_hw *hw)
  160. {
  161. struct ixgbe_mac_info *mac = &hw->mac;
  162. ixgbe_init_mac_link_ops_82599(hw);
  163. mac->mcft_size = IXGBE_82599_MC_TBL_SIZE;
  164. mac->vft_size = IXGBE_82599_VFT_TBL_SIZE;
  165. mac->num_rar_entries = IXGBE_82599_RAR_ENTRIES;
  166. mac->max_rx_queues = IXGBE_82599_MAX_RX_QUEUES;
  167. mac->max_tx_queues = IXGBE_82599_MAX_TX_QUEUES;
  168. mac->max_msix_vectors = ixgbe_get_pcie_msix_count_generic(hw);
  169. return 0;
  170. }
  171. /**
  172. * ixgbe_init_phy_ops_82599 - PHY/SFP specific init
  173. * @hw: pointer to hardware structure
  174. *
  175. * Initialize any function pointers that were not able to be
  176. * set during get_invariants because the PHY/SFP type was
  177. * not known. Perform the SFP init if necessary.
  178. *
  179. **/
  180. static s32 ixgbe_init_phy_ops_82599(struct ixgbe_hw *hw)
  181. {
  182. struct ixgbe_mac_info *mac = &hw->mac;
  183. struct ixgbe_phy_info *phy = &hw->phy;
  184. s32 ret_val = 0;
  185. /* Identify the PHY or SFP module */
  186. ret_val = phy->ops.identify(hw);
  187. /* Setup function pointers based on detected SFP module and speeds */
  188. ixgbe_init_mac_link_ops_82599(hw);
  189. /* If copper media, overwrite with copper function pointers */
  190. if (mac->ops.get_media_type(hw) == ixgbe_media_type_copper) {
  191. mac->ops.setup_link = &ixgbe_setup_copper_link_82599;
  192. mac->ops.get_link_capabilities =
  193. &ixgbe_get_copper_link_capabilities_generic;
  194. }
  195. /* Set necessary function pointers based on phy type */
  196. switch (hw->phy.type) {
  197. case ixgbe_phy_tn:
  198. phy->ops.check_link = &ixgbe_check_phy_link_tnx;
  199. phy->ops.setup_link = &ixgbe_setup_phy_link_tnx;
  200. phy->ops.get_firmware_version =
  201. &ixgbe_get_phy_firmware_version_tnx;
  202. break;
  203. default:
  204. break;
  205. }
  206. return ret_val;
  207. }
  208. /**
  209. * ixgbe_get_link_capabilities_82599 - Determines link capabilities
  210. * @hw: pointer to hardware structure
  211. * @speed: pointer to link speed
  212. * @autoneg: true when autoneg or autotry is enabled
  213. *
  214. * Determines the link capabilities by reading the AUTOC register.
  215. **/
  216. static s32 ixgbe_get_link_capabilities_82599(struct ixgbe_hw *hw,
  217. ixgbe_link_speed *speed,
  218. bool *autoneg)
  219. {
  220. s32 status = 0;
  221. u32 autoc = 0;
  222. /* Determine 1G link capabilities off of SFP+ type */
  223. if (hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
  224. hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
  225. hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
  226. hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
  227. hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
  228. hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1) {
  229. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  230. *autoneg = true;
  231. goto out;
  232. }
  233. /*
  234. * Determine link capabilities based on the stored value of AUTOC,
  235. * which represents EEPROM defaults. If AUTOC value has not been
  236. * stored, use the current register value.
  237. */
  238. if (hw->mac.orig_link_settings_stored)
  239. autoc = hw->mac.orig_autoc;
  240. else
  241. autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  242. switch (autoc & IXGBE_AUTOC_LMS_MASK) {
  243. case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
  244. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  245. *autoneg = false;
  246. break;
  247. case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
  248. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  249. *autoneg = false;
  250. break;
  251. case IXGBE_AUTOC_LMS_1G_AN:
  252. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  253. *autoneg = true;
  254. break;
  255. case IXGBE_AUTOC_LMS_10G_SERIAL:
  256. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  257. *autoneg = false;
  258. break;
  259. case IXGBE_AUTOC_LMS_KX4_KX_KR:
  260. case IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN:
  261. *speed = IXGBE_LINK_SPEED_UNKNOWN;
  262. if (autoc & IXGBE_AUTOC_KR_SUPP)
  263. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  264. if (autoc & IXGBE_AUTOC_KX4_SUPP)
  265. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  266. if (autoc & IXGBE_AUTOC_KX_SUPP)
  267. *speed |= IXGBE_LINK_SPEED_1GB_FULL;
  268. *autoneg = true;
  269. break;
  270. case IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII:
  271. *speed = IXGBE_LINK_SPEED_100_FULL;
  272. if (autoc & IXGBE_AUTOC_KR_SUPP)
  273. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  274. if (autoc & IXGBE_AUTOC_KX4_SUPP)
  275. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  276. if (autoc & IXGBE_AUTOC_KX_SUPP)
  277. *speed |= IXGBE_LINK_SPEED_1GB_FULL;
  278. *autoneg = true;
  279. break;
  280. case IXGBE_AUTOC_LMS_SGMII_1G_100M:
  281. *speed = IXGBE_LINK_SPEED_1GB_FULL | IXGBE_LINK_SPEED_100_FULL;
  282. *autoneg = false;
  283. break;
  284. default:
  285. status = IXGBE_ERR_LINK_SETUP;
  286. goto out;
  287. break;
  288. }
  289. if (hw->phy.multispeed_fiber) {
  290. *speed |= IXGBE_LINK_SPEED_10GB_FULL |
  291. IXGBE_LINK_SPEED_1GB_FULL;
  292. *autoneg = true;
  293. }
  294. out:
  295. return status;
  296. }
  297. /**
  298. * ixgbe_get_media_type_82599 - Get media type
  299. * @hw: pointer to hardware structure
  300. *
  301. * Returns the media type (fiber, copper, backplane)
  302. **/
  303. static enum ixgbe_media_type ixgbe_get_media_type_82599(struct ixgbe_hw *hw)
  304. {
  305. enum ixgbe_media_type media_type;
  306. /* Detect if there is a copper PHY attached. */
  307. switch (hw->phy.type) {
  308. case ixgbe_phy_cu_unknown:
  309. case ixgbe_phy_tn:
  310. media_type = ixgbe_media_type_copper;
  311. goto out;
  312. default:
  313. break;
  314. }
  315. switch (hw->device_id) {
  316. case IXGBE_DEV_ID_82599_KX4:
  317. case IXGBE_DEV_ID_82599_KX4_MEZZ:
  318. case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
  319. case IXGBE_DEV_ID_82599_KR:
  320. case IXGBE_DEV_ID_82599_BACKPLANE_FCOE:
  321. case IXGBE_DEV_ID_82599_XAUI_LOM:
  322. /* Default device ID is mezzanine card KX/KX4 */
  323. media_type = ixgbe_media_type_backplane;
  324. break;
  325. case IXGBE_DEV_ID_82599_SFP:
  326. case IXGBE_DEV_ID_82599_SFP_FCOE:
  327. case IXGBE_DEV_ID_82599_SFP_EM:
  328. case IXGBE_DEV_ID_82599_SFP_SF2:
  329. case IXGBE_DEV_ID_82599_SFP_SF_QP:
  330. case IXGBE_DEV_ID_82599EN_SFP:
  331. media_type = ixgbe_media_type_fiber;
  332. break;
  333. case IXGBE_DEV_ID_82599_CX4:
  334. media_type = ixgbe_media_type_cx4;
  335. break;
  336. case IXGBE_DEV_ID_82599_T3_LOM:
  337. media_type = ixgbe_media_type_copper;
  338. break;
  339. case IXGBE_DEV_ID_82599_LS:
  340. media_type = ixgbe_media_type_fiber_lco;
  341. break;
  342. default:
  343. media_type = ixgbe_media_type_unknown;
  344. break;
  345. }
  346. out:
  347. return media_type;
  348. }
  349. /**
  350. * ixgbe_start_mac_link_82599 - Setup MAC link settings
  351. * @hw: pointer to hardware structure
  352. * @autoneg_wait_to_complete: true when waiting for completion is needed
  353. *
  354. * Configures link settings based on values in the ixgbe_hw struct.
  355. * Restarts the link. Performs autonegotiation if needed.
  356. **/
  357. static s32 ixgbe_start_mac_link_82599(struct ixgbe_hw *hw,
  358. bool autoneg_wait_to_complete)
  359. {
  360. u32 autoc_reg;
  361. u32 links_reg;
  362. u32 i;
  363. s32 status = 0;
  364. bool got_lock = false;
  365. if (ixgbe_verify_lesm_fw_enabled_82599(hw)) {
  366. status = hw->mac.ops.acquire_swfw_sync(hw,
  367. IXGBE_GSSR_MAC_CSR_SM);
  368. if (status)
  369. goto out;
  370. got_lock = true;
  371. }
  372. /* Restart link */
  373. ixgbe_reset_pipeline_82599(hw);
  374. if (got_lock)
  375. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
  376. /* Only poll for autoneg to complete if specified to do so */
  377. if (autoneg_wait_to_complete) {
  378. autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  379. if ((autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
  380. IXGBE_AUTOC_LMS_KX4_KX_KR ||
  381. (autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
  382. IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
  383. (autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
  384. IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
  385. links_reg = 0; /* Just in case Autoneg time = 0 */
  386. for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
  387. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  388. if (links_reg & IXGBE_LINKS_KX_AN_COMP)
  389. break;
  390. msleep(100);
  391. }
  392. if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
  393. status = IXGBE_ERR_AUTONEG_NOT_COMPLETE;
  394. hw_dbg(hw, "Autoneg did not complete.\n");
  395. }
  396. }
  397. }
  398. /* Add delay to filter out noises during initial link setup */
  399. msleep(50);
  400. out:
  401. return status;
  402. }
  403. /**
  404. * ixgbe_disable_tx_laser_multispeed_fiber - Disable Tx laser
  405. * @hw: pointer to hardware structure
  406. *
  407. * The base drivers may require better control over SFP+ module
  408. * PHY states. This includes selectively shutting down the Tx
  409. * laser on the PHY, effectively halting physical link.
  410. **/
  411. static void ixgbe_disable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw)
  412. {
  413. u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
  414. /* Disable tx laser; allow 100us to go dark per spec */
  415. esdp_reg |= IXGBE_ESDP_SDP3;
  416. IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
  417. IXGBE_WRITE_FLUSH(hw);
  418. udelay(100);
  419. }
  420. /**
  421. * ixgbe_enable_tx_laser_multispeed_fiber - Enable Tx laser
  422. * @hw: pointer to hardware structure
  423. *
  424. * The base drivers may require better control over SFP+ module
  425. * PHY states. This includes selectively turning on the Tx
  426. * laser on the PHY, effectively starting physical link.
  427. **/
  428. static void ixgbe_enable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw)
  429. {
  430. u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
  431. /* Enable tx laser; allow 100ms to light up */
  432. esdp_reg &= ~IXGBE_ESDP_SDP3;
  433. IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
  434. IXGBE_WRITE_FLUSH(hw);
  435. msleep(100);
  436. }
  437. /**
  438. * ixgbe_flap_tx_laser_multispeed_fiber - Flap Tx laser
  439. * @hw: pointer to hardware structure
  440. *
  441. * When the driver changes the link speeds that it can support,
  442. * it sets autotry_restart to true to indicate that we need to
  443. * initiate a new autotry session with the link partner. To do
  444. * so, we set the speed then disable and re-enable the tx laser, to
  445. * alert the link partner that it also needs to restart autotry on its
  446. * end. This is consistent with true clause 37 autoneg, which also
  447. * involves a loss of signal.
  448. **/
  449. static void ixgbe_flap_tx_laser_multispeed_fiber(struct ixgbe_hw *hw)
  450. {
  451. if (hw->mac.autotry_restart) {
  452. ixgbe_disable_tx_laser_multispeed_fiber(hw);
  453. ixgbe_enable_tx_laser_multispeed_fiber(hw);
  454. hw->mac.autotry_restart = false;
  455. }
  456. }
  457. /**
  458. * ixgbe_setup_mac_link_multispeed_fiber - Set MAC link speed
  459. * @hw: pointer to hardware structure
  460. * @speed: new link speed
  461. * @autoneg_wait_to_complete: true when waiting for completion is needed
  462. *
  463. * Set the link speed in the AUTOC register and restarts link.
  464. **/
  465. static s32 ixgbe_setup_mac_link_multispeed_fiber(struct ixgbe_hw *hw,
  466. ixgbe_link_speed speed,
  467. bool autoneg_wait_to_complete)
  468. {
  469. s32 status = 0;
  470. ixgbe_link_speed link_speed = IXGBE_LINK_SPEED_UNKNOWN;
  471. ixgbe_link_speed highest_link_speed = IXGBE_LINK_SPEED_UNKNOWN;
  472. u32 speedcnt = 0;
  473. u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
  474. u32 i = 0;
  475. bool link_up = false;
  476. bool autoneg = false;
  477. /* Mask off requested but non-supported speeds */
  478. status = hw->mac.ops.get_link_capabilities(hw, &link_speed,
  479. &autoneg);
  480. if (status != 0)
  481. return status;
  482. speed &= link_speed;
  483. /*
  484. * Try each speed one by one, highest priority first. We do this in
  485. * software because 10gb fiber doesn't support speed autonegotiation.
  486. */
  487. if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
  488. speedcnt++;
  489. highest_link_speed = IXGBE_LINK_SPEED_10GB_FULL;
  490. /* If we already have link at this speed, just jump out */
  491. status = hw->mac.ops.check_link(hw, &link_speed, &link_up,
  492. false);
  493. if (status != 0)
  494. return status;
  495. if ((link_speed == IXGBE_LINK_SPEED_10GB_FULL) && link_up)
  496. goto out;
  497. /* Set the module link speed */
  498. esdp_reg |= (IXGBE_ESDP_SDP5_DIR | IXGBE_ESDP_SDP5);
  499. IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
  500. IXGBE_WRITE_FLUSH(hw);
  501. /* Allow module to change analog characteristics (1G->10G) */
  502. msleep(40);
  503. status = ixgbe_setup_mac_link_82599(hw,
  504. IXGBE_LINK_SPEED_10GB_FULL,
  505. autoneg_wait_to_complete);
  506. if (status != 0)
  507. return status;
  508. /* Flap the tx laser if it has not already been done */
  509. if (hw->mac.ops.flap_tx_laser)
  510. hw->mac.ops.flap_tx_laser(hw);
  511. /*
  512. * Wait for the controller to acquire link. Per IEEE 802.3ap,
  513. * Section 73.10.2, we may have to wait up to 500ms if KR is
  514. * attempted. 82599 uses the same timing for 10g SFI.
  515. */
  516. for (i = 0; i < 5; i++) {
  517. /* Wait for the link partner to also set speed */
  518. msleep(100);
  519. /* If we have link, just jump out */
  520. status = hw->mac.ops.check_link(hw, &link_speed,
  521. &link_up, false);
  522. if (status != 0)
  523. return status;
  524. if (link_up)
  525. goto out;
  526. }
  527. }
  528. if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
  529. speedcnt++;
  530. if (highest_link_speed == IXGBE_LINK_SPEED_UNKNOWN)
  531. highest_link_speed = IXGBE_LINK_SPEED_1GB_FULL;
  532. /* If we already have link at this speed, just jump out */
  533. status = hw->mac.ops.check_link(hw, &link_speed, &link_up,
  534. false);
  535. if (status != 0)
  536. return status;
  537. if ((link_speed == IXGBE_LINK_SPEED_1GB_FULL) && link_up)
  538. goto out;
  539. /* Set the module link speed */
  540. esdp_reg &= ~IXGBE_ESDP_SDP5;
  541. esdp_reg |= IXGBE_ESDP_SDP5_DIR;
  542. IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
  543. IXGBE_WRITE_FLUSH(hw);
  544. /* Allow module to change analog characteristics (10G->1G) */
  545. msleep(40);
  546. status = ixgbe_setup_mac_link_82599(hw,
  547. IXGBE_LINK_SPEED_1GB_FULL,
  548. autoneg_wait_to_complete);
  549. if (status != 0)
  550. return status;
  551. /* Flap the tx laser if it has not already been done */
  552. if (hw->mac.ops.flap_tx_laser)
  553. hw->mac.ops.flap_tx_laser(hw);
  554. /* Wait for the link partner to also set speed */
  555. msleep(100);
  556. /* If we have link, just jump out */
  557. status = hw->mac.ops.check_link(hw, &link_speed, &link_up,
  558. false);
  559. if (status != 0)
  560. return status;
  561. if (link_up)
  562. goto out;
  563. }
  564. /*
  565. * We didn't get link. Configure back to the highest speed we tried,
  566. * (if there was more than one). We call ourselves back with just the
  567. * single highest speed that the user requested.
  568. */
  569. if (speedcnt > 1)
  570. status = ixgbe_setup_mac_link_multispeed_fiber(hw,
  571. highest_link_speed,
  572. autoneg_wait_to_complete);
  573. out:
  574. /* Set autoneg_advertised value based on input link speed */
  575. hw->phy.autoneg_advertised = 0;
  576. if (speed & IXGBE_LINK_SPEED_10GB_FULL)
  577. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
  578. if (speed & IXGBE_LINK_SPEED_1GB_FULL)
  579. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
  580. return status;
  581. }
  582. /**
  583. * ixgbe_setup_mac_link_smartspeed - Set MAC link speed using SmartSpeed
  584. * @hw: pointer to hardware structure
  585. * @speed: new link speed
  586. * @autoneg_wait_to_complete: true when waiting for completion is needed
  587. *
  588. * Implements the Intel SmartSpeed algorithm.
  589. **/
  590. static s32 ixgbe_setup_mac_link_smartspeed(struct ixgbe_hw *hw,
  591. ixgbe_link_speed speed,
  592. bool autoneg_wait_to_complete)
  593. {
  594. s32 status = 0;
  595. ixgbe_link_speed link_speed = IXGBE_LINK_SPEED_UNKNOWN;
  596. s32 i, j;
  597. bool link_up = false;
  598. u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  599. /* Set autoneg_advertised value based on input link speed */
  600. hw->phy.autoneg_advertised = 0;
  601. if (speed & IXGBE_LINK_SPEED_10GB_FULL)
  602. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
  603. if (speed & IXGBE_LINK_SPEED_1GB_FULL)
  604. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
  605. if (speed & IXGBE_LINK_SPEED_100_FULL)
  606. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
  607. /*
  608. * Implement Intel SmartSpeed algorithm. SmartSpeed will reduce the
  609. * autoneg advertisement if link is unable to be established at the
  610. * highest negotiated rate. This can sometimes happen due to integrity
  611. * issues with the physical media connection.
  612. */
  613. /* First, try to get link with full advertisement */
  614. hw->phy.smart_speed_active = false;
  615. for (j = 0; j < IXGBE_SMARTSPEED_MAX_RETRIES; j++) {
  616. status = ixgbe_setup_mac_link_82599(hw, speed,
  617. autoneg_wait_to_complete);
  618. if (status != 0)
  619. goto out;
  620. /*
  621. * Wait for the controller to acquire link. Per IEEE 802.3ap,
  622. * Section 73.10.2, we may have to wait up to 500ms if KR is
  623. * attempted, or 200ms if KX/KX4/BX/BX4 is attempted, per
  624. * Table 9 in the AN MAS.
  625. */
  626. for (i = 0; i < 5; i++) {
  627. mdelay(100);
  628. /* If we have link, just jump out */
  629. status = hw->mac.ops.check_link(hw, &link_speed,
  630. &link_up, false);
  631. if (status != 0)
  632. goto out;
  633. if (link_up)
  634. goto out;
  635. }
  636. }
  637. /*
  638. * We didn't get link. If we advertised KR plus one of KX4/KX
  639. * (or BX4/BX), then disable KR and try again.
  640. */
  641. if (((autoc_reg & IXGBE_AUTOC_KR_SUPP) == 0) ||
  642. ((autoc_reg & IXGBE_AUTOC_KX4_KX_SUPP_MASK) == 0))
  643. goto out;
  644. /* Turn SmartSpeed on to disable KR support */
  645. hw->phy.smart_speed_active = true;
  646. status = ixgbe_setup_mac_link_82599(hw, speed,
  647. autoneg_wait_to_complete);
  648. if (status != 0)
  649. goto out;
  650. /*
  651. * Wait for the controller to acquire link. 600ms will allow for
  652. * the AN link_fail_inhibit_timer as well for multiple cycles of
  653. * parallel detect, both 10g and 1g. This allows for the maximum
  654. * connect attempts as defined in the AN MAS table 73-7.
  655. */
  656. for (i = 0; i < 6; i++) {
  657. mdelay(100);
  658. /* If we have link, just jump out */
  659. status = hw->mac.ops.check_link(hw, &link_speed,
  660. &link_up, false);
  661. if (status != 0)
  662. goto out;
  663. if (link_up)
  664. goto out;
  665. }
  666. /* We didn't get link. Turn SmartSpeed back off. */
  667. hw->phy.smart_speed_active = false;
  668. status = ixgbe_setup_mac_link_82599(hw, speed,
  669. autoneg_wait_to_complete);
  670. out:
  671. if (link_up && (link_speed == IXGBE_LINK_SPEED_1GB_FULL))
  672. hw_dbg(hw, "Smartspeed has downgraded the link speed from "
  673. "the maximum advertised\n");
  674. return status;
  675. }
  676. /**
  677. * ixgbe_setup_mac_link_82599 - Set MAC link speed
  678. * @hw: pointer to hardware structure
  679. * @speed: new link speed
  680. * @autoneg_wait_to_complete: true when waiting for completion is needed
  681. *
  682. * Set the link speed in the AUTOC register and restarts link.
  683. **/
  684. static s32 ixgbe_setup_mac_link_82599(struct ixgbe_hw *hw,
  685. ixgbe_link_speed speed,
  686. bool autoneg_wait_to_complete)
  687. {
  688. s32 status = 0;
  689. u32 autoc, pma_pmd_1g, link_mode, start_autoc;
  690. u32 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
  691. u32 orig_autoc = 0;
  692. u32 pma_pmd_10g_serial = autoc2 & IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_MASK;
  693. u32 links_reg;
  694. u32 i;
  695. ixgbe_link_speed link_capabilities = IXGBE_LINK_SPEED_UNKNOWN;
  696. bool got_lock = false;
  697. bool autoneg = false;
  698. /* Check to see if speed passed in is supported. */
  699. status = hw->mac.ops.get_link_capabilities(hw, &link_capabilities,
  700. &autoneg);
  701. if (status != 0)
  702. goto out;
  703. speed &= link_capabilities;
  704. if (speed == IXGBE_LINK_SPEED_UNKNOWN) {
  705. status = IXGBE_ERR_LINK_SETUP;
  706. goto out;
  707. }
  708. /* Use stored value (EEPROM defaults) of AUTOC to find KR/KX4 support*/
  709. if (hw->mac.orig_link_settings_stored)
  710. autoc = hw->mac.orig_autoc;
  711. else
  712. autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  713. orig_autoc = autoc;
  714. start_autoc = hw->mac.cached_autoc;
  715. link_mode = autoc & IXGBE_AUTOC_LMS_MASK;
  716. pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK;
  717. if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR ||
  718. link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
  719. link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
  720. /* Set KX4/KX/KR support according to speed requested */
  721. autoc &= ~(IXGBE_AUTOC_KX4_KX_SUPP_MASK | IXGBE_AUTOC_KR_SUPP);
  722. if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
  723. if (orig_autoc & IXGBE_AUTOC_KX4_SUPP)
  724. autoc |= IXGBE_AUTOC_KX4_SUPP;
  725. if ((orig_autoc & IXGBE_AUTOC_KR_SUPP) &&
  726. (hw->phy.smart_speed_active == false))
  727. autoc |= IXGBE_AUTOC_KR_SUPP;
  728. }
  729. if (speed & IXGBE_LINK_SPEED_1GB_FULL)
  730. autoc |= IXGBE_AUTOC_KX_SUPP;
  731. } else if ((pma_pmd_1g == IXGBE_AUTOC_1G_SFI) &&
  732. (link_mode == IXGBE_AUTOC_LMS_1G_LINK_NO_AN ||
  733. link_mode == IXGBE_AUTOC_LMS_1G_AN)) {
  734. /* Switch from 1G SFI to 10G SFI if requested */
  735. if ((speed == IXGBE_LINK_SPEED_10GB_FULL) &&
  736. (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI)) {
  737. autoc &= ~IXGBE_AUTOC_LMS_MASK;
  738. autoc |= IXGBE_AUTOC_LMS_10G_SERIAL;
  739. }
  740. } else if ((pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI) &&
  741. (link_mode == IXGBE_AUTOC_LMS_10G_SERIAL)) {
  742. /* Switch from 10G SFI to 1G SFI if requested */
  743. if ((speed == IXGBE_LINK_SPEED_1GB_FULL) &&
  744. (pma_pmd_1g == IXGBE_AUTOC_1G_SFI)) {
  745. autoc &= ~IXGBE_AUTOC_LMS_MASK;
  746. if (autoneg)
  747. autoc |= IXGBE_AUTOC_LMS_1G_AN;
  748. else
  749. autoc |= IXGBE_AUTOC_LMS_1G_LINK_NO_AN;
  750. }
  751. }
  752. if (autoc != start_autoc) {
  753. /* Need SW/FW semaphore around AUTOC writes if LESM is on,
  754. * likewise reset_pipeline requires us to hold this lock as
  755. * it also writes to AUTOC.
  756. */
  757. if (ixgbe_verify_lesm_fw_enabled_82599(hw)) {
  758. status = hw->mac.ops.acquire_swfw_sync(hw,
  759. IXGBE_GSSR_MAC_CSR_SM);
  760. if (status != 0)
  761. goto out;
  762. got_lock = true;
  763. }
  764. /* Restart link */
  765. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc);
  766. hw->mac.cached_autoc = autoc;
  767. ixgbe_reset_pipeline_82599(hw);
  768. if (got_lock)
  769. hw->mac.ops.release_swfw_sync(hw,
  770. IXGBE_GSSR_MAC_CSR_SM);
  771. /* Only poll for autoneg to complete if specified to do so */
  772. if (autoneg_wait_to_complete) {
  773. if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR ||
  774. link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
  775. link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
  776. links_reg = 0; /*Just in case Autoneg time=0*/
  777. for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
  778. links_reg =
  779. IXGBE_READ_REG(hw, IXGBE_LINKS);
  780. if (links_reg & IXGBE_LINKS_KX_AN_COMP)
  781. break;
  782. msleep(100);
  783. }
  784. if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
  785. status =
  786. IXGBE_ERR_AUTONEG_NOT_COMPLETE;
  787. hw_dbg(hw, "Autoneg did not "
  788. "complete.\n");
  789. }
  790. }
  791. }
  792. /* Add delay to filter out noises during initial link setup */
  793. msleep(50);
  794. }
  795. out:
  796. return status;
  797. }
  798. /**
  799. * ixgbe_setup_copper_link_82599 - Set the PHY autoneg advertised field
  800. * @hw: pointer to hardware structure
  801. * @speed: new link speed
  802. * @autoneg_wait_to_complete: true if waiting is needed to complete
  803. *
  804. * Restarts link on PHY and MAC based on settings passed in.
  805. **/
  806. static s32 ixgbe_setup_copper_link_82599(struct ixgbe_hw *hw,
  807. ixgbe_link_speed speed,
  808. bool autoneg_wait_to_complete)
  809. {
  810. s32 status;
  811. /* Setup the PHY according to input speed */
  812. status = hw->phy.ops.setup_link_speed(hw, speed,
  813. autoneg_wait_to_complete);
  814. /* Set up MAC */
  815. ixgbe_start_mac_link_82599(hw, autoneg_wait_to_complete);
  816. return status;
  817. }
  818. /**
  819. * ixgbe_reset_hw_82599 - Perform hardware reset
  820. * @hw: pointer to hardware structure
  821. *
  822. * Resets the hardware by resetting the transmit and receive units, masks
  823. * and clears all interrupts, perform a PHY reset, and perform a link (MAC)
  824. * reset.
  825. **/
  826. static s32 ixgbe_reset_hw_82599(struct ixgbe_hw *hw)
  827. {
  828. ixgbe_link_speed link_speed;
  829. s32 status;
  830. u32 ctrl, i, autoc2;
  831. u32 curr_lms;
  832. bool link_up = false;
  833. /* Call adapter stop to disable tx/rx and clear interrupts */
  834. status = hw->mac.ops.stop_adapter(hw);
  835. if (status != 0)
  836. goto reset_hw_out;
  837. /* flush pending Tx transactions */
  838. ixgbe_clear_tx_pending(hw);
  839. /* PHY ops must be identified and initialized prior to reset */
  840. /* Identify PHY and related function pointers */
  841. status = hw->phy.ops.init(hw);
  842. if (status == IXGBE_ERR_SFP_NOT_SUPPORTED)
  843. goto reset_hw_out;
  844. /* Setup SFP module if there is one present. */
  845. if (hw->phy.sfp_setup_needed) {
  846. status = hw->mac.ops.setup_sfp(hw);
  847. hw->phy.sfp_setup_needed = false;
  848. }
  849. if (status == IXGBE_ERR_SFP_NOT_SUPPORTED)
  850. goto reset_hw_out;
  851. /* Reset PHY */
  852. if (hw->phy.reset_disable == false && hw->phy.ops.reset != NULL)
  853. hw->phy.ops.reset(hw);
  854. /* remember AUTOC from before we reset */
  855. if (hw->mac.cached_autoc)
  856. curr_lms = hw->mac.cached_autoc & IXGBE_AUTOC_LMS_MASK;
  857. else
  858. curr_lms = IXGBE_READ_REG(hw, IXGBE_AUTOC) &
  859. IXGBE_AUTOC_LMS_MASK;
  860. mac_reset_top:
  861. /*
  862. * Issue global reset to the MAC. Needs to be SW reset if link is up.
  863. * If link reset is used when link is up, it might reset the PHY when
  864. * mng is using it. If link is down or the flag to force full link
  865. * reset is set, then perform link reset.
  866. */
  867. ctrl = IXGBE_CTRL_LNK_RST;
  868. if (!hw->force_full_reset) {
  869. hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
  870. if (link_up)
  871. ctrl = IXGBE_CTRL_RST;
  872. }
  873. ctrl |= IXGBE_READ_REG(hw, IXGBE_CTRL);
  874. IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
  875. IXGBE_WRITE_FLUSH(hw);
  876. /* Poll for reset bit to self-clear indicating reset is complete */
  877. for (i = 0; i < 10; i++) {
  878. udelay(1);
  879. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  880. if (!(ctrl & IXGBE_CTRL_RST_MASK))
  881. break;
  882. }
  883. if (ctrl & IXGBE_CTRL_RST_MASK) {
  884. status = IXGBE_ERR_RESET_FAILED;
  885. hw_dbg(hw, "Reset polling failed to complete.\n");
  886. }
  887. msleep(50);
  888. /*
  889. * Double resets are required for recovery from certain error
  890. * conditions. Between resets, it is necessary to stall to allow time
  891. * for any pending HW events to complete.
  892. */
  893. if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
  894. hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
  895. goto mac_reset_top;
  896. }
  897. /*
  898. * Store the original AUTOC/AUTOC2 values if they have not been
  899. * stored off yet. Otherwise restore the stored original
  900. * values since the reset operation sets back to defaults.
  901. */
  902. hw->mac.cached_autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  903. autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
  904. /* Enable link if disabled in NVM */
  905. if (autoc2 & IXGBE_AUTOC2_LINK_DISABLE_MASK) {
  906. autoc2 &= ~IXGBE_AUTOC2_LINK_DISABLE_MASK;
  907. IXGBE_WRITE_REG(hw, IXGBE_AUTOC2, autoc2);
  908. IXGBE_WRITE_FLUSH(hw);
  909. }
  910. if (hw->mac.orig_link_settings_stored == false) {
  911. hw->mac.orig_autoc = hw->mac.cached_autoc;
  912. hw->mac.orig_autoc2 = autoc2;
  913. hw->mac.orig_link_settings_stored = true;
  914. } else {
  915. /* If MNG FW is running on a multi-speed device that
  916. * doesn't autoneg with out driver support we need to
  917. * leave LMS in the state it was before we MAC reset.
  918. * Likewise if we support WoL we don't want change the
  919. * LMS state either.
  920. */
  921. if ((hw->phy.multispeed_fiber && hw->mng_fw_enabled) ||
  922. hw->wol_enabled)
  923. hw->mac.orig_autoc =
  924. (hw->mac.orig_autoc & ~IXGBE_AUTOC_LMS_MASK) |
  925. curr_lms;
  926. if (hw->mac.cached_autoc != hw->mac.orig_autoc) {
  927. /* Need SW/FW semaphore around AUTOC writes if LESM is
  928. * on, likewise reset_pipeline requires us to hold
  929. * this lock as it also writes to AUTOC.
  930. */
  931. bool got_lock = false;
  932. if (ixgbe_verify_lesm_fw_enabled_82599(hw)) {
  933. status = hw->mac.ops.acquire_swfw_sync(hw,
  934. IXGBE_GSSR_MAC_CSR_SM);
  935. if (status)
  936. goto reset_hw_out;
  937. got_lock = true;
  938. }
  939. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, hw->mac.orig_autoc);
  940. hw->mac.cached_autoc = hw->mac.orig_autoc;
  941. ixgbe_reset_pipeline_82599(hw);
  942. if (got_lock)
  943. hw->mac.ops.release_swfw_sync(hw,
  944. IXGBE_GSSR_MAC_CSR_SM);
  945. }
  946. if ((autoc2 & IXGBE_AUTOC2_UPPER_MASK) !=
  947. (hw->mac.orig_autoc2 & IXGBE_AUTOC2_UPPER_MASK)) {
  948. autoc2 &= ~IXGBE_AUTOC2_UPPER_MASK;
  949. autoc2 |= (hw->mac.orig_autoc2 &
  950. IXGBE_AUTOC2_UPPER_MASK);
  951. IXGBE_WRITE_REG(hw, IXGBE_AUTOC2, autoc2);
  952. }
  953. }
  954. /* Store the permanent mac address */
  955. hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
  956. /*
  957. * Store MAC address from RAR0, clear receive address registers, and
  958. * clear the multicast table. Also reset num_rar_entries to 128,
  959. * since we modify this value when programming the SAN MAC address.
  960. */
  961. hw->mac.num_rar_entries = 128;
  962. hw->mac.ops.init_rx_addrs(hw);
  963. /* Store the permanent SAN mac address */
  964. hw->mac.ops.get_san_mac_addr(hw, hw->mac.san_addr);
  965. /* Add the SAN MAC address to the RAR only if it's a valid address */
  966. if (is_valid_ether_addr(hw->mac.san_addr)) {
  967. hw->mac.ops.set_rar(hw, hw->mac.num_rar_entries - 1,
  968. hw->mac.san_addr, 0, IXGBE_RAH_AV);
  969. /* Save the SAN MAC RAR index */
  970. hw->mac.san_mac_rar_index = hw->mac.num_rar_entries - 1;
  971. /* Reserve the last RAR for the SAN MAC address */
  972. hw->mac.num_rar_entries--;
  973. }
  974. /* Store the alternative WWNN/WWPN prefix */
  975. hw->mac.ops.get_wwn_prefix(hw, &hw->mac.wwnn_prefix,
  976. &hw->mac.wwpn_prefix);
  977. reset_hw_out:
  978. return status;
  979. }
  980. /**
  981. * ixgbe_reinit_fdir_tables_82599 - Reinitialize Flow Director tables.
  982. * @hw: pointer to hardware structure
  983. **/
  984. s32 ixgbe_reinit_fdir_tables_82599(struct ixgbe_hw *hw)
  985. {
  986. int i;
  987. u32 fdirctrl = IXGBE_READ_REG(hw, IXGBE_FDIRCTRL);
  988. fdirctrl &= ~IXGBE_FDIRCTRL_INIT_DONE;
  989. /*
  990. * Before starting reinitialization process,
  991. * FDIRCMD.CMD must be zero.
  992. */
  993. for (i = 0; i < IXGBE_FDIRCMD_CMD_POLL; i++) {
  994. if (!(IXGBE_READ_REG(hw, IXGBE_FDIRCMD) &
  995. IXGBE_FDIRCMD_CMD_MASK))
  996. break;
  997. udelay(10);
  998. }
  999. if (i >= IXGBE_FDIRCMD_CMD_POLL) {
  1000. hw_dbg(hw, "Flow Director previous command isn't complete, "
  1001. "aborting table re-initialization.\n");
  1002. return IXGBE_ERR_FDIR_REINIT_FAILED;
  1003. }
  1004. IXGBE_WRITE_REG(hw, IXGBE_FDIRFREE, 0);
  1005. IXGBE_WRITE_FLUSH(hw);
  1006. /*
  1007. * 82599 adapters flow director init flow cannot be restarted,
  1008. * Workaround 82599 silicon errata by performing the following steps
  1009. * before re-writing the FDIRCTRL control register with the same value.
  1010. * - write 1 to bit 8 of FDIRCMD register &
  1011. * - write 0 to bit 8 of FDIRCMD register
  1012. */
  1013. IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
  1014. (IXGBE_READ_REG(hw, IXGBE_FDIRCMD) |
  1015. IXGBE_FDIRCMD_CLEARHT));
  1016. IXGBE_WRITE_FLUSH(hw);
  1017. IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
  1018. (IXGBE_READ_REG(hw, IXGBE_FDIRCMD) &
  1019. ~IXGBE_FDIRCMD_CLEARHT));
  1020. IXGBE_WRITE_FLUSH(hw);
  1021. /*
  1022. * Clear FDIR Hash register to clear any leftover hashes
  1023. * waiting to be programmed.
  1024. */
  1025. IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, 0x00);
  1026. IXGBE_WRITE_FLUSH(hw);
  1027. IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl);
  1028. IXGBE_WRITE_FLUSH(hw);
  1029. /* Poll init-done after we write FDIRCTRL register */
  1030. for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) {
  1031. if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) &
  1032. IXGBE_FDIRCTRL_INIT_DONE)
  1033. break;
  1034. usleep_range(1000, 2000);
  1035. }
  1036. if (i >= IXGBE_FDIR_INIT_DONE_POLL) {
  1037. hw_dbg(hw, "Flow Director Signature poll time exceeded!\n");
  1038. return IXGBE_ERR_FDIR_REINIT_FAILED;
  1039. }
  1040. /* Clear FDIR statistics registers (read to clear) */
  1041. IXGBE_READ_REG(hw, IXGBE_FDIRUSTAT);
  1042. IXGBE_READ_REG(hw, IXGBE_FDIRFSTAT);
  1043. IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
  1044. IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
  1045. IXGBE_READ_REG(hw, IXGBE_FDIRLEN);
  1046. return 0;
  1047. }
  1048. /**
  1049. * ixgbe_fdir_enable_82599 - Initialize Flow Director control registers
  1050. * @hw: pointer to hardware structure
  1051. * @fdirctrl: value to write to flow director control register
  1052. **/
  1053. static void ixgbe_fdir_enable_82599(struct ixgbe_hw *hw, u32 fdirctrl)
  1054. {
  1055. int i;
  1056. /* Prime the keys for hashing */
  1057. IXGBE_WRITE_REG(hw, IXGBE_FDIRHKEY, IXGBE_ATR_BUCKET_HASH_KEY);
  1058. IXGBE_WRITE_REG(hw, IXGBE_FDIRSKEY, IXGBE_ATR_SIGNATURE_HASH_KEY);
  1059. /*
  1060. * Poll init-done after we write the register. Estimated times:
  1061. * 10G: PBALLOC = 11b, timing is 60us
  1062. * 1G: PBALLOC = 11b, timing is 600us
  1063. * 100M: PBALLOC = 11b, timing is 6ms
  1064. *
  1065. * Multiple these timings by 4 if under full Rx load
  1066. *
  1067. * So we'll poll for IXGBE_FDIR_INIT_DONE_POLL times, sleeping for
  1068. * 1 msec per poll time. If we're at line rate and drop to 100M, then
  1069. * this might not finish in our poll time, but we can live with that
  1070. * for now.
  1071. */
  1072. IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl);
  1073. IXGBE_WRITE_FLUSH(hw);
  1074. for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) {
  1075. if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) &
  1076. IXGBE_FDIRCTRL_INIT_DONE)
  1077. break;
  1078. usleep_range(1000, 2000);
  1079. }
  1080. if (i >= IXGBE_FDIR_INIT_DONE_POLL)
  1081. hw_dbg(hw, "Flow Director poll time exceeded!\n");
  1082. }
  1083. /**
  1084. * ixgbe_init_fdir_signature_82599 - Initialize Flow Director signature filters
  1085. * @hw: pointer to hardware structure
  1086. * @fdirctrl: value to write to flow director control register, initially
  1087. * contains just the value of the Rx packet buffer allocation
  1088. **/
  1089. s32 ixgbe_init_fdir_signature_82599(struct ixgbe_hw *hw, u32 fdirctrl)
  1090. {
  1091. /*
  1092. * Continue setup of fdirctrl register bits:
  1093. * Move the flexible bytes to use the ethertype - shift 6 words
  1094. * Set the maximum length per hash bucket to 0xA filters
  1095. * Send interrupt when 64 filters are left
  1096. */
  1097. fdirctrl |= (0x6 << IXGBE_FDIRCTRL_FLEX_SHIFT) |
  1098. (0xA << IXGBE_FDIRCTRL_MAX_LENGTH_SHIFT) |
  1099. (4 << IXGBE_FDIRCTRL_FULL_THRESH_SHIFT);
  1100. /* write hashes and fdirctrl register, poll for completion */
  1101. ixgbe_fdir_enable_82599(hw, fdirctrl);
  1102. return 0;
  1103. }
  1104. /**
  1105. * ixgbe_init_fdir_perfect_82599 - Initialize Flow Director perfect filters
  1106. * @hw: pointer to hardware structure
  1107. * @fdirctrl: value to write to flow director control register, initially
  1108. * contains just the value of the Rx packet buffer allocation
  1109. **/
  1110. s32 ixgbe_init_fdir_perfect_82599(struct ixgbe_hw *hw, u32 fdirctrl)
  1111. {
  1112. /*
  1113. * Continue setup of fdirctrl register bits:
  1114. * Turn perfect match filtering on
  1115. * Report hash in RSS field of Rx wb descriptor
  1116. * Initialize the drop queue
  1117. * Move the flexible bytes to use the ethertype - shift 6 words
  1118. * Set the maximum length per hash bucket to 0xA filters
  1119. * Send interrupt when 64 (0x4 * 16) filters are left
  1120. */
  1121. fdirctrl |= IXGBE_FDIRCTRL_PERFECT_MATCH |
  1122. IXGBE_FDIRCTRL_REPORT_STATUS |
  1123. (IXGBE_FDIR_DROP_QUEUE << IXGBE_FDIRCTRL_DROP_Q_SHIFT) |
  1124. (0x6 << IXGBE_FDIRCTRL_FLEX_SHIFT) |
  1125. (0xA << IXGBE_FDIRCTRL_MAX_LENGTH_SHIFT) |
  1126. (4 << IXGBE_FDIRCTRL_FULL_THRESH_SHIFT);
  1127. /* write hashes and fdirctrl register, poll for completion */
  1128. ixgbe_fdir_enable_82599(hw, fdirctrl);
  1129. return 0;
  1130. }
  1131. /*
  1132. * These defines allow us to quickly generate all of the necessary instructions
  1133. * in the function below by simply calling out IXGBE_COMPUTE_SIG_HASH_ITERATION
  1134. * for values 0 through 15
  1135. */
  1136. #define IXGBE_ATR_COMMON_HASH_KEY \
  1137. (IXGBE_ATR_BUCKET_HASH_KEY & IXGBE_ATR_SIGNATURE_HASH_KEY)
  1138. #define IXGBE_COMPUTE_SIG_HASH_ITERATION(_n) \
  1139. do { \
  1140. u32 n = (_n); \
  1141. if (IXGBE_ATR_COMMON_HASH_KEY & (0x01 << n)) \
  1142. common_hash ^= lo_hash_dword >> n; \
  1143. else if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << n)) \
  1144. bucket_hash ^= lo_hash_dword >> n; \
  1145. else if (IXGBE_ATR_SIGNATURE_HASH_KEY & (0x01 << n)) \
  1146. sig_hash ^= lo_hash_dword << (16 - n); \
  1147. if (IXGBE_ATR_COMMON_HASH_KEY & (0x01 << (n + 16))) \
  1148. common_hash ^= hi_hash_dword >> n; \
  1149. else if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << (n + 16))) \
  1150. bucket_hash ^= hi_hash_dword >> n; \
  1151. else if (IXGBE_ATR_SIGNATURE_HASH_KEY & (0x01 << (n + 16))) \
  1152. sig_hash ^= hi_hash_dword << (16 - n); \
  1153. } while (0);
  1154. /**
  1155. * ixgbe_atr_compute_sig_hash_82599 - Compute the signature hash
  1156. * @stream: input bitstream to compute the hash on
  1157. *
  1158. * This function is almost identical to the function above but contains
  1159. * several optomizations such as unwinding all of the loops, letting the
  1160. * compiler work out all of the conditional ifs since the keys are static
  1161. * defines, and computing two keys at once since the hashed dword stream
  1162. * will be the same for both keys.
  1163. **/
  1164. static u32 ixgbe_atr_compute_sig_hash_82599(union ixgbe_atr_hash_dword input,
  1165. union ixgbe_atr_hash_dword common)
  1166. {
  1167. u32 hi_hash_dword, lo_hash_dword, flow_vm_vlan;
  1168. u32 sig_hash = 0, bucket_hash = 0, common_hash = 0;
  1169. /* record the flow_vm_vlan bits as they are a key part to the hash */
  1170. flow_vm_vlan = ntohl(input.dword);
  1171. /* generate common hash dword */
  1172. hi_hash_dword = ntohl(common.dword);
  1173. /* low dword is word swapped version of common */
  1174. lo_hash_dword = (hi_hash_dword >> 16) | (hi_hash_dword << 16);
  1175. /* apply flow ID/VM pool/VLAN ID bits to hash words */
  1176. hi_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan >> 16);
  1177. /* Process bits 0 and 16 */
  1178. IXGBE_COMPUTE_SIG_HASH_ITERATION(0);
  1179. /*
  1180. * apply flow ID/VM pool/VLAN ID bits to lo hash dword, we had to
  1181. * delay this because bit 0 of the stream should not be processed
  1182. * so we do not add the vlan until after bit 0 was processed
  1183. */
  1184. lo_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan << 16);
  1185. /* Process remaining 30 bit of the key */
  1186. IXGBE_COMPUTE_SIG_HASH_ITERATION(1);
  1187. IXGBE_COMPUTE_SIG_HASH_ITERATION(2);
  1188. IXGBE_COMPUTE_SIG_HASH_ITERATION(3);
  1189. IXGBE_COMPUTE_SIG_HASH_ITERATION(4);
  1190. IXGBE_COMPUTE_SIG_HASH_ITERATION(5);
  1191. IXGBE_COMPUTE_SIG_HASH_ITERATION(6);
  1192. IXGBE_COMPUTE_SIG_HASH_ITERATION(7);
  1193. IXGBE_COMPUTE_SIG_HASH_ITERATION(8);
  1194. IXGBE_COMPUTE_SIG_HASH_ITERATION(9);
  1195. IXGBE_COMPUTE_SIG_HASH_ITERATION(10);
  1196. IXGBE_COMPUTE_SIG_HASH_ITERATION(11);
  1197. IXGBE_COMPUTE_SIG_HASH_ITERATION(12);
  1198. IXGBE_COMPUTE_SIG_HASH_ITERATION(13);
  1199. IXGBE_COMPUTE_SIG_HASH_ITERATION(14);
  1200. IXGBE_COMPUTE_SIG_HASH_ITERATION(15);
  1201. /* combine common_hash result with signature and bucket hashes */
  1202. bucket_hash ^= common_hash;
  1203. bucket_hash &= IXGBE_ATR_HASH_MASK;
  1204. sig_hash ^= common_hash << 16;
  1205. sig_hash &= IXGBE_ATR_HASH_MASK << 16;
  1206. /* return completed signature hash */
  1207. return sig_hash ^ bucket_hash;
  1208. }
  1209. /**
  1210. * ixgbe_atr_add_signature_filter_82599 - Adds a signature hash filter
  1211. * @hw: pointer to hardware structure
  1212. * @input: unique input dword
  1213. * @common: compressed common input dword
  1214. * @queue: queue index to direct traffic to
  1215. **/
  1216. s32 ixgbe_fdir_add_signature_filter_82599(struct ixgbe_hw *hw,
  1217. union ixgbe_atr_hash_dword input,
  1218. union ixgbe_atr_hash_dword common,
  1219. u8 queue)
  1220. {
  1221. u64 fdirhashcmd;
  1222. u32 fdircmd;
  1223. /*
  1224. * Get the flow_type in order to program FDIRCMD properly
  1225. * lowest 2 bits are FDIRCMD.L4TYPE, third lowest bit is FDIRCMD.IPV6
  1226. */
  1227. switch (input.formatted.flow_type) {
  1228. case IXGBE_ATR_FLOW_TYPE_TCPV4:
  1229. case IXGBE_ATR_FLOW_TYPE_UDPV4:
  1230. case IXGBE_ATR_FLOW_TYPE_SCTPV4:
  1231. case IXGBE_ATR_FLOW_TYPE_TCPV6:
  1232. case IXGBE_ATR_FLOW_TYPE_UDPV6:
  1233. case IXGBE_ATR_FLOW_TYPE_SCTPV6:
  1234. break;
  1235. default:
  1236. hw_dbg(hw, " Error on flow type input\n");
  1237. return IXGBE_ERR_CONFIG;
  1238. }
  1239. /* configure FDIRCMD register */
  1240. fdircmd = IXGBE_FDIRCMD_CMD_ADD_FLOW | IXGBE_FDIRCMD_FILTER_UPDATE |
  1241. IXGBE_FDIRCMD_LAST | IXGBE_FDIRCMD_QUEUE_EN;
  1242. fdircmd |= input.formatted.flow_type << IXGBE_FDIRCMD_FLOW_TYPE_SHIFT;
  1243. fdircmd |= (u32)queue << IXGBE_FDIRCMD_RX_QUEUE_SHIFT;
  1244. /*
  1245. * The lower 32-bits of fdirhashcmd is for FDIRHASH, the upper 32-bits
  1246. * is for FDIRCMD. Then do a 64-bit register write from FDIRHASH.
  1247. */
  1248. fdirhashcmd = (u64)fdircmd << 32;
  1249. fdirhashcmd |= ixgbe_atr_compute_sig_hash_82599(input, common);
  1250. IXGBE_WRITE_REG64(hw, IXGBE_FDIRHASH, fdirhashcmd);
  1251. hw_dbg(hw, "Tx Queue=%x hash=%x\n", queue, (u32)fdirhashcmd);
  1252. return 0;
  1253. }
  1254. #define IXGBE_COMPUTE_BKT_HASH_ITERATION(_n) \
  1255. do { \
  1256. u32 n = (_n); \
  1257. if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << n)) \
  1258. bucket_hash ^= lo_hash_dword >> n; \
  1259. if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << (n + 16))) \
  1260. bucket_hash ^= hi_hash_dword >> n; \
  1261. } while (0);
  1262. /**
  1263. * ixgbe_atr_compute_perfect_hash_82599 - Compute the perfect filter hash
  1264. * @atr_input: input bitstream to compute the hash on
  1265. * @input_mask: mask for the input bitstream
  1266. *
  1267. * This function serves two main purposes. First it applys the input_mask
  1268. * to the atr_input resulting in a cleaned up atr_input data stream.
  1269. * Secondly it computes the hash and stores it in the bkt_hash field at
  1270. * the end of the input byte stream. This way it will be available for
  1271. * future use without needing to recompute the hash.
  1272. **/
  1273. void ixgbe_atr_compute_perfect_hash_82599(union ixgbe_atr_input *input,
  1274. union ixgbe_atr_input *input_mask)
  1275. {
  1276. u32 hi_hash_dword, lo_hash_dword, flow_vm_vlan;
  1277. u32 bucket_hash = 0;
  1278. /* Apply masks to input data */
  1279. input->dword_stream[0] &= input_mask->dword_stream[0];
  1280. input->dword_stream[1] &= input_mask->dword_stream[1];
  1281. input->dword_stream[2] &= input_mask->dword_stream[2];
  1282. input->dword_stream[3] &= input_mask->dword_stream[3];
  1283. input->dword_stream[4] &= input_mask->dword_stream[4];
  1284. input->dword_stream[5] &= input_mask->dword_stream[5];
  1285. input->dword_stream[6] &= input_mask->dword_stream[6];
  1286. input->dword_stream[7] &= input_mask->dword_stream[7];
  1287. input->dword_stream[8] &= input_mask->dword_stream[8];
  1288. input->dword_stream[9] &= input_mask->dword_stream[9];
  1289. input->dword_stream[10] &= input_mask->dword_stream[10];
  1290. /* record the flow_vm_vlan bits as they are a key part to the hash */
  1291. flow_vm_vlan = ntohl(input->dword_stream[0]);
  1292. /* generate common hash dword */
  1293. hi_hash_dword = ntohl(input->dword_stream[1] ^
  1294. input->dword_stream[2] ^
  1295. input->dword_stream[3] ^
  1296. input->dword_stream[4] ^
  1297. input->dword_stream[5] ^
  1298. input->dword_stream[6] ^
  1299. input->dword_stream[7] ^
  1300. input->dword_stream[8] ^
  1301. input->dword_stream[9] ^
  1302. input->dword_stream[10]);
  1303. /* low dword is word swapped version of common */
  1304. lo_hash_dword = (hi_hash_dword >> 16) | (hi_hash_dword << 16);
  1305. /* apply flow ID/VM pool/VLAN ID bits to hash words */
  1306. hi_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan >> 16);
  1307. /* Process bits 0 and 16 */
  1308. IXGBE_COMPUTE_BKT_HASH_ITERATION(0);
  1309. /*
  1310. * apply flow ID/VM pool/VLAN ID bits to lo hash dword, we had to
  1311. * delay this because bit 0 of the stream should not be processed
  1312. * so we do not add the vlan until after bit 0 was processed
  1313. */
  1314. lo_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan << 16);
  1315. /* Process remaining 30 bit of the key */
  1316. IXGBE_COMPUTE_BKT_HASH_ITERATION(1);
  1317. IXGBE_COMPUTE_BKT_HASH_ITERATION(2);
  1318. IXGBE_COMPUTE_BKT_HASH_ITERATION(3);
  1319. IXGBE_COMPUTE_BKT_HASH_ITERATION(4);
  1320. IXGBE_COMPUTE_BKT_HASH_ITERATION(5);
  1321. IXGBE_COMPUTE_BKT_HASH_ITERATION(6);
  1322. IXGBE_COMPUTE_BKT_HASH_ITERATION(7);
  1323. IXGBE_COMPUTE_BKT_HASH_ITERATION(8);
  1324. IXGBE_COMPUTE_BKT_HASH_ITERATION(9);
  1325. IXGBE_COMPUTE_BKT_HASH_ITERATION(10);
  1326. IXGBE_COMPUTE_BKT_HASH_ITERATION(11);
  1327. IXGBE_COMPUTE_BKT_HASH_ITERATION(12);
  1328. IXGBE_COMPUTE_BKT_HASH_ITERATION(13);
  1329. IXGBE_COMPUTE_BKT_HASH_ITERATION(14);
  1330. IXGBE_COMPUTE_BKT_HASH_ITERATION(15);
  1331. /*
  1332. * Limit hash to 13 bits since max bucket count is 8K.
  1333. * Store result at the end of the input stream.
  1334. */
  1335. input->formatted.bkt_hash = bucket_hash & 0x1FFF;
  1336. }
  1337. /**
  1338. * ixgbe_get_fdirtcpm_82599 - generate a tcp port from atr_input_masks
  1339. * @input_mask: mask to be bit swapped
  1340. *
  1341. * The source and destination port masks for flow director are bit swapped
  1342. * in that bit 15 effects bit 0, 14 effects 1, 13, 2 etc. In order to
  1343. * generate a correctly swapped value we need to bit swap the mask and that
  1344. * is what is accomplished by this function.
  1345. **/
  1346. static u32 ixgbe_get_fdirtcpm_82599(union ixgbe_atr_input *input_mask)
  1347. {
  1348. u32 mask = ntohs(input_mask->formatted.dst_port);
  1349. mask <<= IXGBE_FDIRTCPM_DPORTM_SHIFT;
  1350. mask |= ntohs(input_mask->formatted.src_port);
  1351. mask = ((mask & 0x55555555) << 1) | ((mask & 0xAAAAAAAA) >> 1);
  1352. mask = ((mask & 0x33333333) << 2) | ((mask & 0xCCCCCCCC) >> 2);
  1353. mask = ((mask & 0x0F0F0F0F) << 4) | ((mask & 0xF0F0F0F0) >> 4);
  1354. return ((mask & 0x00FF00FF) << 8) | ((mask & 0xFF00FF00) >> 8);
  1355. }
  1356. /*
  1357. * These two macros are meant to address the fact that we have registers
  1358. * that are either all or in part big-endian. As a result on big-endian
  1359. * systems we will end up byte swapping the value to little-endian before
  1360. * it is byte swapped again and written to the hardware in the original
  1361. * big-endian format.
  1362. */
  1363. #define IXGBE_STORE_AS_BE32(_value) \
  1364. (((u32)(_value) >> 24) | (((u32)(_value) & 0x00FF0000) >> 8) | \
  1365. (((u32)(_value) & 0x0000FF00) << 8) | ((u32)(_value) << 24))
  1366. #define IXGBE_WRITE_REG_BE32(a, reg, value) \
  1367. IXGBE_WRITE_REG((a), (reg), IXGBE_STORE_AS_BE32(ntohl(value)))
  1368. #define IXGBE_STORE_AS_BE16(_value) \
  1369. ntohs(((u16)(_value) >> 8) | ((u16)(_value) << 8))
  1370. s32 ixgbe_fdir_set_input_mask_82599(struct ixgbe_hw *hw,
  1371. union ixgbe_atr_input *input_mask)
  1372. {
  1373. /* mask IPv6 since it is currently not supported */
  1374. u32 fdirm = IXGBE_FDIRM_DIPv6;
  1375. u32 fdirtcpm;
  1376. /*
  1377. * Program the relevant mask registers. If src/dst_port or src/dst_addr
  1378. * are zero, then assume a full mask for that field. Also assume that
  1379. * a VLAN of 0 is unspecified, so mask that out as well. L4type
  1380. * cannot be masked out in this implementation.
  1381. *
  1382. * This also assumes IPv4 only. IPv6 masking isn't supported at this
  1383. * point in time.
  1384. */
  1385. /* verify bucket hash is cleared on hash generation */
  1386. if (input_mask->formatted.bkt_hash)
  1387. hw_dbg(hw, " bucket hash should always be 0 in mask\n");
  1388. /* Program FDIRM and verify partial masks */
  1389. switch (input_mask->formatted.vm_pool & 0x7F) {
  1390. case 0x0:
  1391. fdirm |= IXGBE_FDIRM_POOL;
  1392. case 0x7F:
  1393. break;
  1394. default:
  1395. hw_dbg(hw, " Error on vm pool mask\n");
  1396. return IXGBE_ERR_CONFIG;
  1397. }
  1398. switch (input_mask->formatted.flow_type & IXGBE_ATR_L4TYPE_MASK) {
  1399. case 0x0:
  1400. fdirm |= IXGBE_FDIRM_L4P;
  1401. if (input_mask->formatted.dst_port ||
  1402. input_mask->formatted.src_port) {
  1403. hw_dbg(hw, " Error on src/dst port mask\n");
  1404. return IXGBE_ERR_CONFIG;
  1405. }
  1406. case IXGBE_ATR_L4TYPE_MASK:
  1407. break;
  1408. default:
  1409. hw_dbg(hw, " Error on flow type mask\n");
  1410. return IXGBE_ERR_CONFIG;
  1411. }
  1412. switch (ntohs(input_mask->formatted.vlan_id) & 0xEFFF) {
  1413. case 0x0000:
  1414. /* mask VLAN ID, fall through to mask VLAN priority */
  1415. fdirm |= IXGBE_FDIRM_VLANID;
  1416. case 0x0FFF:
  1417. /* mask VLAN priority */
  1418. fdirm |= IXGBE_FDIRM_VLANP;
  1419. break;
  1420. case 0xE000:
  1421. /* mask VLAN ID only, fall through */
  1422. fdirm |= IXGBE_FDIRM_VLANID;
  1423. case 0xEFFF:
  1424. /* no VLAN fields masked */
  1425. break;
  1426. default:
  1427. hw_dbg(hw, " Error on VLAN mask\n");
  1428. return IXGBE_ERR_CONFIG;
  1429. }
  1430. switch (input_mask->formatted.flex_bytes & 0xFFFF) {
  1431. case 0x0000:
  1432. /* Mask Flex Bytes, fall through */
  1433. fdirm |= IXGBE_FDIRM_FLEX;
  1434. case 0xFFFF:
  1435. break;
  1436. default:
  1437. hw_dbg(hw, " Error on flexible byte mask\n");
  1438. return IXGBE_ERR_CONFIG;
  1439. }
  1440. /* Now mask VM pool and destination IPv6 - bits 5 and 2 */
  1441. IXGBE_WRITE_REG(hw, IXGBE_FDIRM, fdirm);
  1442. /* store the TCP/UDP port masks, bit reversed from port layout */
  1443. fdirtcpm = ixgbe_get_fdirtcpm_82599(input_mask);
  1444. /* write both the same so that UDP and TCP use the same mask */
  1445. IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM, ~fdirtcpm);
  1446. IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM, ~fdirtcpm);
  1447. /* store source and destination IP masks (big-enian) */
  1448. IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIP4M,
  1449. ~input_mask->formatted.src_ip[0]);
  1450. IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRDIP4M,
  1451. ~input_mask->formatted.dst_ip[0]);
  1452. return 0;
  1453. }
  1454. s32 ixgbe_fdir_write_perfect_filter_82599(struct ixgbe_hw *hw,
  1455. union ixgbe_atr_input *input,
  1456. u16 soft_id, u8 queue)
  1457. {
  1458. u32 fdirport, fdirvlan, fdirhash, fdircmd;
  1459. /* currently IPv6 is not supported, must be programmed with 0 */
  1460. IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIPv6(0),
  1461. input->formatted.src_ip[0]);
  1462. IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIPv6(1),
  1463. input->formatted.src_ip[1]);
  1464. IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIPv6(2),
  1465. input->formatted.src_ip[2]);
  1466. /* record the source address (big-endian) */
  1467. IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRIPSA, input->formatted.src_ip[0]);
  1468. /* record the first 32 bits of the destination address (big-endian) */
  1469. IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRIPDA, input->formatted.dst_ip[0]);
  1470. /* record source and destination port (little-endian)*/
  1471. fdirport = ntohs(input->formatted.dst_port);
  1472. fdirport <<= IXGBE_FDIRPORT_DESTINATION_SHIFT;
  1473. fdirport |= ntohs(input->formatted.src_port);
  1474. IXGBE_WRITE_REG(hw, IXGBE_FDIRPORT, fdirport);
  1475. /* record vlan (little-endian) and flex_bytes(big-endian) */
  1476. fdirvlan = IXGBE_STORE_AS_BE16(input->formatted.flex_bytes);
  1477. fdirvlan <<= IXGBE_FDIRVLAN_FLEX_SHIFT;
  1478. fdirvlan |= ntohs(input->formatted.vlan_id);
  1479. IXGBE_WRITE_REG(hw, IXGBE_FDIRVLAN, fdirvlan);
  1480. /* configure FDIRHASH register */
  1481. fdirhash = input->formatted.bkt_hash;
  1482. fdirhash |= soft_id << IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT;
  1483. IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash);
  1484. /*
  1485. * flush all previous writes to make certain registers are
  1486. * programmed prior to issuing the command
  1487. */
  1488. IXGBE_WRITE_FLUSH(hw);
  1489. /* configure FDIRCMD register */
  1490. fdircmd = IXGBE_FDIRCMD_CMD_ADD_FLOW | IXGBE_FDIRCMD_FILTER_UPDATE |
  1491. IXGBE_FDIRCMD_LAST | IXGBE_FDIRCMD_QUEUE_EN;
  1492. if (queue == IXGBE_FDIR_DROP_QUEUE)
  1493. fdircmd |= IXGBE_FDIRCMD_DROP;
  1494. fdircmd |= input->formatted.flow_type << IXGBE_FDIRCMD_FLOW_TYPE_SHIFT;
  1495. fdircmd |= (u32)queue << IXGBE_FDIRCMD_RX_QUEUE_SHIFT;
  1496. fdircmd |= (u32)input->formatted.vm_pool << IXGBE_FDIRCMD_VT_POOL_SHIFT;
  1497. IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, fdircmd);
  1498. return 0;
  1499. }
  1500. s32 ixgbe_fdir_erase_perfect_filter_82599(struct ixgbe_hw *hw,
  1501. union ixgbe_atr_input *input,
  1502. u16 soft_id)
  1503. {
  1504. u32 fdirhash;
  1505. u32 fdircmd = 0;
  1506. u32 retry_count;
  1507. s32 err = 0;
  1508. /* configure FDIRHASH register */
  1509. fdirhash = input->formatted.bkt_hash;
  1510. fdirhash |= soft_id << IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT;
  1511. IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash);
  1512. /* flush hash to HW */
  1513. IXGBE_WRITE_FLUSH(hw);
  1514. /* Query if filter is present */
  1515. IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, IXGBE_FDIRCMD_CMD_QUERY_REM_FILT);
  1516. for (retry_count = 10; retry_count; retry_count--) {
  1517. /* allow 10us for query to process */
  1518. udelay(10);
  1519. /* verify query completed successfully */
  1520. fdircmd = IXGBE_READ_REG(hw, IXGBE_FDIRCMD);
  1521. if (!(fdircmd & IXGBE_FDIRCMD_CMD_MASK))
  1522. break;
  1523. }
  1524. if (!retry_count)
  1525. err = IXGBE_ERR_FDIR_REINIT_FAILED;
  1526. /* if filter exists in hardware then remove it */
  1527. if (fdircmd & IXGBE_FDIRCMD_FILTER_VALID) {
  1528. IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash);
  1529. IXGBE_WRITE_FLUSH(hw);
  1530. IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
  1531. IXGBE_FDIRCMD_CMD_REMOVE_FLOW);
  1532. }
  1533. return err;
  1534. }
  1535. /**
  1536. * ixgbe_read_analog_reg8_82599 - Reads 8 bit Omer analog register
  1537. * @hw: pointer to hardware structure
  1538. * @reg: analog register to read
  1539. * @val: read value
  1540. *
  1541. * Performs read operation to Omer analog register specified.
  1542. **/
  1543. static s32 ixgbe_read_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 *val)
  1544. {
  1545. u32 core_ctl;
  1546. IXGBE_WRITE_REG(hw, IXGBE_CORECTL, IXGBE_CORECTL_WRITE_CMD |
  1547. (reg << 8));
  1548. IXGBE_WRITE_FLUSH(hw);
  1549. udelay(10);
  1550. core_ctl = IXGBE_READ_REG(hw, IXGBE_CORECTL);
  1551. *val = (u8)core_ctl;
  1552. return 0;
  1553. }
  1554. /**
  1555. * ixgbe_write_analog_reg8_82599 - Writes 8 bit Omer analog register
  1556. * @hw: pointer to hardware structure
  1557. * @reg: atlas register to write
  1558. * @val: value to write
  1559. *
  1560. * Performs write operation to Omer analog register specified.
  1561. **/
  1562. static s32 ixgbe_write_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 val)
  1563. {
  1564. u32 core_ctl;
  1565. core_ctl = (reg << 8) | val;
  1566. IXGBE_WRITE_REG(hw, IXGBE_CORECTL, core_ctl);
  1567. IXGBE_WRITE_FLUSH(hw);
  1568. udelay(10);
  1569. return 0;
  1570. }
  1571. /**
  1572. * ixgbe_start_hw_82599 - Prepare hardware for Tx/Rx
  1573. * @hw: pointer to hardware structure
  1574. *
  1575. * Starts the hardware using the generic start_hw function
  1576. * and the generation start_hw function.
  1577. * Then performs revision-specific operations, if any.
  1578. **/
  1579. static s32 ixgbe_start_hw_82599(struct ixgbe_hw *hw)
  1580. {
  1581. s32 ret_val = 0;
  1582. ret_val = ixgbe_start_hw_generic(hw);
  1583. if (ret_val != 0)
  1584. goto out;
  1585. ret_val = ixgbe_start_hw_gen2(hw);
  1586. if (ret_val != 0)
  1587. goto out;
  1588. /* We need to run link autotry after the driver loads */
  1589. hw->mac.autotry_restart = true;
  1590. hw->mac.rx_pb_size = IXGBE_82599_RX_PB_SIZE;
  1591. if (ret_val == 0)
  1592. ret_val = ixgbe_verify_fw_version_82599(hw);
  1593. out:
  1594. return ret_val;
  1595. }
  1596. /**
  1597. * ixgbe_identify_phy_82599 - Get physical layer module
  1598. * @hw: pointer to hardware structure
  1599. *
  1600. * Determines the physical layer module found on the current adapter.
  1601. * If PHY already detected, maintains current PHY type in hw struct,
  1602. * otherwise executes the PHY detection routine.
  1603. **/
  1604. static s32 ixgbe_identify_phy_82599(struct ixgbe_hw *hw)
  1605. {
  1606. s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
  1607. /* Detect PHY if not unknown - returns success if already detected. */
  1608. status = ixgbe_identify_phy_generic(hw);
  1609. if (status != 0) {
  1610. /* 82599 10GBASE-T requires an external PHY */
  1611. if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper)
  1612. goto out;
  1613. else
  1614. status = ixgbe_identify_sfp_module_generic(hw);
  1615. }
  1616. /* Set PHY type none if no PHY detected */
  1617. if (hw->phy.type == ixgbe_phy_unknown) {
  1618. hw->phy.type = ixgbe_phy_none;
  1619. status = 0;
  1620. }
  1621. /* Return error if SFP module has been detected but is not supported */
  1622. if (hw->phy.type == ixgbe_phy_sfp_unsupported)
  1623. status = IXGBE_ERR_SFP_NOT_SUPPORTED;
  1624. out:
  1625. return status;
  1626. }
  1627. /**
  1628. * ixgbe_get_supported_physical_layer_82599 - Returns physical layer type
  1629. * @hw: pointer to hardware structure
  1630. *
  1631. * Determines physical layer capabilities of the current configuration.
  1632. **/
  1633. static u32 ixgbe_get_supported_physical_layer_82599(struct ixgbe_hw *hw)
  1634. {
  1635. u32 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
  1636. u32 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  1637. u32 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
  1638. u32 pma_pmd_10g_serial = autoc2 & IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_MASK;
  1639. u32 pma_pmd_10g_parallel = autoc & IXGBE_AUTOC_10G_PMA_PMD_MASK;
  1640. u32 pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK;
  1641. u16 ext_ability = 0;
  1642. u8 comp_codes_10g = 0;
  1643. u8 comp_codes_1g = 0;
  1644. hw->phy.ops.identify(hw);
  1645. switch (hw->phy.type) {
  1646. case ixgbe_phy_tn:
  1647. case ixgbe_phy_cu_unknown:
  1648. hw->phy.ops.read_reg(hw, MDIO_PMA_EXTABLE, MDIO_MMD_PMAPMD,
  1649. &ext_ability);
  1650. if (ext_ability & MDIO_PMA_EXTABLE_10GBT)
  1651. physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_T;
  1652. if (ext_ability & MDIO_PMA_EXTABLE_1000BT)
  1653. physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_T;
  1654. if (ext_ability & MDIO_PMA_EXTABLE_100BTX)
  1655. physical_layer |= IXGBE_PHYSICAL_LAYER_100BASE_TX;
  1656. goto out;
  1657. default:
  1658. break;
  1659. }
  1660. switch (autoc & IXGBE_AUTOC_LMS_MASK) {
  1661. case IXGBE_AUTOC_LMS_1G_AN:
  1662. case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
  1663. if (pma_pmd_1g == IXGBE_AUTOC_1G_KX_BX) {
  1664. physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_KX |
  1665. IXGBE_PHYSICAL_LAYER_1000BASE_BX;
  1666. goto out;
  1667. } else
  1668. /* SFI mode so read SFP module */
  1669. goto sfp_check;
  1670. break;
  1671. case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
  1672. if (pma_pmd_10g_parallel == IXGBE_AUTOC_10G_CX4)
  1673. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_CX4;
  1674. else if (pma_pmd_10g_parallel == IXGBE_AUTOC_10G_KX4)
  1675. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_KX4;
  1676. else if (pma_pmd_10g_parallel == IXGBE_AUTOC_10G_XAUI)
  1677. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_XAUI;
  1678. goto out;
  1679. break;
  1680. case IXGBE_AUTOC_LMS_10G_SERIAL:
  1681. if (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_KR) {
  1682. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_KR;
  1683. goto out;
  1684. } else if (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI)
  1685. goto sfp_check;
  1686. break;
  1687. case IXGBE_AUTOC_LMS_KX4_KX_KR:
  1688. case IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN:
  1689. if (autoc & IXGBE_AUTOC_KX_SUPP)
  1690. physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_KX;
  1691. if (autoc & IXGBE_AUTOC_KX4_SUPP)
  1692. physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_KX4;
  1693. if (autoc & IXGBE_AUTOC_KR_SUPP)
  1694. physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_KR;
  1695. goto out;
  1696. break;
  1697. default:
  1698. goto out;
  1699. break;
  1700. }
  1701. sfp_check:
  1702. /* SFP check must be done last since DA modules are sometimes used to
  1703. * test KR mode - we need to id KR mode correctly before SFP module.
  1704. * Call identify_sfp because the pluggable module may have changed */
  1705. hw->phy.ops.identify_sfp(hw);
  1706. if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
  1707. goto out;
  1708. switch (hw->phy.type) {
  1709. case ixgbe_phy_sfp_passive_tyco:
  1710. case ixgbe_phy_sfp_passive_unknown:
  1711. physical_layer = IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU;
  1712. break;
  1713. case ixgbe_phy_sfp_ftl_active:
  1714. case ixgbe_phy_sfp_active_unknown:
  1715. physical_layer = IXGBE_PHYSICAL_LAYER_SFP_ACTIVE_DA;
  1716. break;
  1717. case ixgbe_phy_sfp_avago:
  1718. case ixgbe_phy_sfp_ftl:
  1719. case ixgbe_phy_sfp_intel:
  1720. case ixgbe_phy_sfp_unknown:
  1721. hw->phy.ops.read_i2c_eeprom(hw,
  1722. IXGBE_SFF_1GBE_COMP_CODES, &comp_codes_1g);
  1723. hw->phy.ops.read_i2c_eeprom(hw,
  1724. IXGBE_SFF_10GBE_COMP_CODES, &comp_codes_10g);
  1725. if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
  1726. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_SR;
  1727. else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
  1728. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_LR;
  1729. else if (comp_codes_1g & IXGBE_SFF_1GBASET_CAPABLE)
  1730. physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_T;
  1731. break;
  1732. default:
  1733. break;
  1734. }
  1735. out:
  1736. return physical_layer;
  1737. }
  1738. /**
  1739. * ixgbe_enable_rx_dma_82599 - Enable the Rx DMA unit on 82599
  1740. * @hw: pointer to hardware structure
  1741. * @regval: register value to write to RXCTRL
  1742. *
  1743. * Enables the Rx DMA unit for 82599
  1744. **/
  1745. static s32 ixgbe_enable_rx_dma_82599(struct ixgbe_hw *hw, u32 regval)
  1746. {
  1747. /*
  1748. * Workaround for 82599 silicon errata when enabling the Rx datapath.
  1749. * If traffic is incoming before we enable the Rx unit, it could hang
  1750. * the Rx DMA unit. Therefore, make sure the security engine is
  1751. * completely disabled prior to enabling the Rx unit.
  1752. */
  1753. hw->mac.ops.disable_rx_buff(hw);
  1754. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval);
  1755. hw->mac.ops.enable_rx_buff(hw);
  1756. return 0;
  1757. }
  1758. /**
  1759. * ixgbe_verify_fw_version_82599 - verify fw version for 82599
  1760. * @hw: pointer to hardware structure
  1761. *
  1762. * Verifies that installed the firmware version is 0.6 or higher
  1763. * for SFI devices. All 82599 SFI devices should have version 0.6 or higher.
  1764. *
  1765. * Returns IXGBE_ERR_EEPROM_VERSION if the FW is not present or
  1766. * if the FW version is not supported.
  1767. **/
  1768. static s32 ixgbe_verify_fw_version_82599(struct ixgbe_hw *hw)
  1769. {
  1770. s32 status = IXGBE_ERR_EEPROM_VERSION;
  1771. u16 fw_offset, fw_ptp_cfg_offset;
  1772. u16 fw_version = 0;
  1773. /* firmware check is only necessary for SFI devices */
  1774. if (hw->phy.media_type != ixgbe_media_type_fiber) {
  1775. status = 0;
  1776. goto fw_version_out;
  1777. }
  1778. /* get the offset to the Firmware Module block */
  1779. hw->eeprom.ops.read(hw, IXGBE_FW_PTR, &fw_offset);
  1780. if ((fw_offset == 0) || (fw_offset == 0xFFFF))
  1781. goto fw_version_out;
  1782. /* get the offset to the Pass Through Patch Configuration block */
  1783. hw->eeprom.ops.read(hw, (fw_offset +
  1784. IXGBE_FW_PASSTHROUGH_PATCH_CONFIG_PTR),
  1785. &fw_ptp_cfg_offset);
  1786. if ((fw_ptp_cfg_offset == 0) || (fw_ptp_cfg_offset == 0xFFFF))
  1787. goto fw_version_out;
  1788. /* get the firmware version */
  1789. hw->eeprom.ops.read(hw, (fw_ptp_cfg_offset +
  1790. IXGBE_FW_PATCH_VERSION_4),
  1791. &fw_version);
  1792. if (fw_version > 0x5)
  1793. status = 0;
  1794. fw_version_out:
  1795. return status;
  1796. }
  1797. /**
  1798. * ixgbe_verify_lesm_fw_enabled_82599 - Checks LESM FW module state.
  1799. * @hw: pointer to hardware structure
  1800. *
  1801. * Returns true if the LESM FW module is present and enabled. Otherwise
  1802. * returns false. Smart Speed must be disabled if LESM FW module is enabled.
  1803. **/
  1804. bool ixgbe_verify_lesm_fw_enabled_82599(struct ixgbe_hw *hw)
  1805. {
  1806. bool lesm_enabled = false;
  1807. u16 fw_offset, fw_lesm_param_offset, fw_lesm_state;
  1808. s32 status;
  1809. /* get the offset to the Firmware Module block */
  1810. status = hw->eeprom.ops.read(hw, IXGBE_FW_PTR, &fw_offset);
  1811. if ((status != 0) ||
  1812. (fw_offset == 0) || (fw_offset == 0xFFFF))
  1813. goto out;
  1814. /* get the offset to the LESM Parameters block */
  1815. status = hw->eeprom.ops.read(hw, (fw_offset +
  1816. IXGBE_FW_LESM_PARAMETERS_PTR),
  1817. &fw_lesm_param_offset);
  1818. if ((status != 0) ||
  1819. (fw_lesm_param_offset == 0) || (fw_lesm_param_offset == 0xFFFF))
  1820. goto out;
  1821. /* get the lesm state word */
  1822. status = hw->eeprom.ops.read(hw, (fw_lesm_param_offset +
  1823. IXGBE_FW_LESM_STATE_1),
  1824. &fw_lesm_state);
  1825. if ((status == 0) &&
  1826. (fw_lesm_state & IXGBE_FW_LESM_STATE_ENABLED))
  1827. lesm_enabled = true;
  1828. out:
  1829. return lesm_enabled;
  1830. }
  1831. /**
  1832. * ixgbe_read_eeprom_buffer_82599 - Read EEPROM word(s) using
  1833. * fastest available method
  1834. *
  1835. * @hw: pointer to hardware structure
  1836. * @offset: offset of word in EEPROM to read
  1837. * @words: number of words
  1838. * @data: word(s) read from the EEPROM
  1839. *
  1840. * Retrieves 16 bit word(s) read from EEPROM
  1841. **/
  1842. static s32 ixgbe_read_eeprom_buffer_82599(struct ixgbe_hw *hw, u16 offset,
  1843. u16 words, u16 *data)
  1844. {
  1845. struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
  1846. s32 ret_val = IXGBE_ERR_CONFIG;
  1847. /*
  1848. * If EEPROM is detected and can be addressed using 14 bits,
  1849. * use EERD otherwise use bit bang
  1850. */
  1851. if ((eeprom->type == ixgbe_eeprom_spi) &&
  1852. (offset + (words - 1) <= IXGBE_EERD_MAX_ADDR))
  1853. ret_val = ixgbe_read_eerd_buffer_generic(hw, offset, words,
  1854. data);
  1855. else
  1856. ret_val = ixgbe_read_eeprom_buffer_bit_bang_generic(hw, offset,
  1857. words,
  1858. data);
  1859. return ret_val;
  1860. }
  1861. /**
  1862. * ixgbe_read_eeprom_82599 - Read EEPROM word using
  1863. * fastest available method
  1864. *
  1865. * @hw: pointer to hardware structure
  1866. * @offset: offset of word in the EEPROM to read
  1867. * @data: word read from the EEPROM
  1868. *
  1869. * Reads a 16 bit word from the EEPROM
  1870. **/
  1871. static s32 ixgbe_read_eeprom_82599(struct ixgbe_hw *hw,
  1872. u16 offset, u16 *data)
  1873. {
  1874. struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
  1875. s32 ret_val = IXGBE_ERR_CONFIG;
  1876. /*
  1877. * If EEPROM is detected and can be addressed using 14 bits,
  1878. * use EERD otherwise use bit bang
  1879. */
  1880. if ((eeprom->type == ixgbe_eeprom_spi) &&
  1881. (offset <= IXGBE_EERD_MAX_ADDR))
  1882. ret_val = ixgbe_read_eerd_generic(hw, offset, data);
  1883. else
  1884. ret_val = ixgbe_read_eeprom_bit_bang_generic(hw, offset, data);
  1885. return ret_val;
  1886. }
  1887. /**
  1888. * ixgbe_reset_pipeline_82599 - perform pipeline reset
  1889. *
  1890. * @hw: pointer to hardware structure
  1891. *
  1892. * Reset pipeline by asserting Restart_AN together with LMS change to ensure
  1893. * full pipeline reset. Note - We must hold the SW/FW semaphore before writing
  1894. * to AUTOC, so this function assumes the semaphore is held.
  1895. **/
  1896. s32 ixgbe_reset_pipeline_82599(struct ixgbe_hw *hw)
  1897. {
  1898. s32 ret_val;
  1899. u32 anlp1_reg = 0;
  1900. u32 i, autoc_reg, autoc2_reg;
  1901. /* Enable link if disabled in NVM */
  1902. autoc2_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
  1903. if (autoc2_reg & IXGBE_AUTOC2_LINK_DISABLE_MASK) {
  1904. autoc2_reg &= ~IXGBE_AUTOC2_LINK_DISABLE_MASK;
  1905. IXGBE_WRITE_REG(hw, IXGBE_AUTOC2, autoc2_reg);
  1906. IXGBE_WRITE_FLUSH(hw);
  1907. }
  1908. autoc_reg = hw->mac.cached_autoc;
  1909. autoc_reg |= IXGBE_AUTOC_AN_RESTART;
  1910. /* Write AUTOC register with toggled LMS[2] bit and Restart_AN */
  1911. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg ^ IXGBE_AUTOC_LMS_1G_AN);
  1912. /* Wait for AN to leave state 0 */
  1913. for (i = 0; i < 10; i++) {
  1914. usleep_range(4000, 8000);
  1915. anlp1_reg = IXGBE_READ_REG(hw, IXGBE_ANLP1);
  1916. if (anlp1_reg & IXGBE_ANLP1_AN_STATE_MASK)
  1917. break;
  1918. }
  1919. if (!(anlp1_reg & IXGBE_ANLP1_AN_STATE_MASK)) {
  1920. hw_dbg(hw, "auto negotiation not completed\n");
  1921. ret_val = IXGBE_ERR_RESET_FAILED;
  1922. goto reset_pipeline_out;
  1923. }
  1924. ret_val = 0;
  1925. reset_pipeline_out:
  1926. /* Write AUTOC register with original LMS field and Restart_AN */
  1927. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
  1928. IXGBE_WRITE_FLUSH(hw);
  1929. return ret_val;
  1930. }
  1931. static struct ixgbe_mac_operations mac_ops_82599 = {
  1932. .init_hw = &ixgbe_init_hw_generic,
  1933. .reset_hw = &ixgbe_reset_hw_82599,
  1934. .start_hw = &ixgbe_start_hw_82599,
  1935. .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic,
  1936. .get_media_type = &ixgbe_get_media_type_82599,
  1937. .get_supported_physical_layer = &ixgbe_get_supported_physical_layer_82599,
  1938. .enable_rx_dma = &ixgbe_enable_rx_dma_82599,
  1939. .disable_rx_buff = &ixgbe_disable_rx_buff_generic,
  1940. .enable_rx_buff = &ixgbe_enable_rx_buff_generic,
  1941. .get_mac_addr = &ixgbe_get_mac_addr_generic,
  1942. .get_san_mac_addr = &ixgbe_get_san_mac_addr_generic,
  1943. .get_device_caps = &ixgbe_get_device_caps_generic,
  1944. .get_wwn_prefix = &ixgbe_get_wwn_prefix_generic,
  1945. .stop_adapter = &ixgbe_stop_adapter_generic,
  1946. .get_bus_info = &ixgbe_get_bus_info_generic,
  1947. .set_lan_id = &ixgbe_set_lan_id_multi_port_pcie,
  1948. .read_analog_reg8 = &ixgbe_read_analog_reg8_82599,
  1949. .write_analog_reg8 = &ixgbe_write_analog_reg8_82599,
  1950. .setup_link = &ixgbe_setup_mac_link_82599,
  1951. .set_rxpba = &ixgbe_set_rxpba_generic,
  1952. .check_link = &ixgbe_check_mac_link_generic,
  1953. .get_link_capabilities = &ixgbe_get_link_capabilities_82599,
  1954. .led_on = &ixgbe_led_on_generic,
  1955. .led_off = &ixgbe_led_off_generic,
  1956. .blink_led_start = &ixgbe_blink_led_start_generic,
  1957. .blink_led_stop = &ixgbe_blink_led_stop_generic,
  1958. .set_rar = &ixgbe_set_rar_generic,
  1959. .clear_rar = &ixgbe_clear_rar_generic,
  1960. .set_vmdq = &ixgbe_set_vmdq_generic,
  1961. .set_vmdq_san_mac = &ixgbe_set_vmdq_san_mac_generic,
  1962. .clear_vmdq = &ixgbe_clear_vmdq_generic,
  1963. .init_rx_addrs = &ixgbe_init_rx_addrs_generic,
  1964. .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic,
  1965. .enable_mc = &ixgbe_enable_mc_generic,
  1966. .disable_mc = &ixgbe_disable_mc_generic,
  1967. .clear_vfta = &ixgbe_clear_vfta_generic,
  1968. .set_vfta = &ixgbe_set_vfta_generic,
  1969. .fc_enable = &ixgbe_fc_enable_generic,
  1970. .set_fw_drv_ver = &ixgbe_set_fw_drv_ver_generic,
  1971. .init_uta_tables = &ixgbe_init_uta_tables_generic,
  1972. .setup_sfp = &ixgbe_setup_sfp_modules_82599,
  1973. .set_mac_anti_spoofing = &ixgbe_set_mac_anti_spoofing,
  1974. .set_vlan_anti_spoofing = &ixgbe_set_vlan_anti_spoofing,
  1975. .acquire_swfw_sync = &ixgbe_acquire_swfw_sync,
  1976. .release_swfw_sync = &ixgbe_release_swfw_sync,
  1977. .get_thermal_sensor_data = &ixgbe_get_thermal_sensor_data_generic,
  1978. .init_thermal_sensor_thresh = &ixgbe_init_thermal_sensor_thresh_generic,
  1979. .mng_fw_enabled = &ixgbe_mng_enabled,
  1980. };
  1981. static struct ixgbe_eeprom_operations eeprom_ops_82599 = {
  1982. .init_params = &ixgbe_init_eeprom_params_generic,
  1983. .read = &ixgbe_read_eeprom_82599,
  1984. .read_buffer = &ixgbe_read_eeprom_buffer_82599,
  1985. .write = &ixgbe_write_eeprom_generic,
  1986. .write_buffer = &ixgbe_write_eeprom_buffer_bit_bang_generic,
  1987. .calc_checksum = &ixgbe_calc_eeprom_checksum_generic,
  1988. .validate_checksum = &ixgbe_validate_eeprom_checksum_generic,
  1989. .update_checksum = &ixgbe_update_eeprom_checksum_generic,
  1990. };
  1991. static struct ixgbe_phy_operations phy_ops_82599 = {
  1992. .identify = &ixgbe_identify_phy_82599,
  1993. .identify_sfp = &ixgbe_identify_sfp_module_generic,
  1994. .init = &ixgbe_init_phy_ops_82599,
  1995. .reset = &ixgbe_reset_phy_generic,
  1996. .read_reg = &ixgbe_read_phy_reg_generic,
  1997. .write_reg = &ixgbe_write_phy_reg_generic,
  1998. .setup_link = &ixgbe_setup_phy_link_generic,
  1999. .setup_link_speed = &ixgbe_setup_phy_link_speed_generic,
  2000. .read_i2c_byte = &ixgbe_read_i2c_byte_generic,
  2001. .write_i2c_byte = &ixgbe_write_i2c_byte_generic,
  2002. .read_i2c_sff8472 = &ixgbe_read_i2c_sff8472_generic,
  2003. .read_i2c_eeprom = &ixgbe_read_i2c_eeprom_generic,
  2004. .write_i2c_eeprom = &ixgbe_write_i2c_eeprom_generic,
  2005. .check_overtemp = &ixgbe_tn_check_overtemp,
  2006. };
  2007. struct ixgbe_info ixgbe_82599_info = {
  2008. .mac = ixgbe_mac_82599EB,
  2009. .get_invariants = &ixgbe_get_invariants_82599,
  2010. .mac_ops = &mac_ops_82599,
  2011. .eeprom_ops = &eeprom_ops_82599,
  2012. .phy_ops = &phy_ops_82599,
  2013. .mbx_ops = &mbx_ops_generic,
  2014. };