ixgbe_82599.c 68 KB

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