ixgbe_82599.c 68 KB

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