ixgbe_82599.c 65 KB

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