ixgbe_82599.c 87 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779
  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. void ixgbe_disable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw);
  32. void ixgbe_enable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw);
  33. void ixgbe_flap_tx_laser_multispeed_fiber(struct ixgbe_hw *hw);
  34. 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. s32 ixgbe_start_mac_link_82599(struct ixgbe_hw *hw,
  43. bool autoneg_wait_to_complete);
  44. 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_get_copper_link_capabilities_82599(struct ixgbe_hw *hw,
  49. ixgbe_link_speed *speed,
  50. bool *autoneg);
  51. static s32 ixgbe_setup_copper_link_82599(struct ixgbe_hw *hw,
  52. ixgbe_link_speed speed,
  53. bool autoneg,
  54. bool autoneg_wait_to_complete);
  55. static s32 ixgbe_verify_fw_version_82599(struct ixgbe_hw *hw);
  56. static void ixgbe_init_mac_link_ops_82599(struct ixgbe_hw *hw)
  57. {
  58. struct ixgbe_mac_info *mac = &hw->mac;
  59. if (hw->phy.multispeed_fiber) {
  60. /* Set up dual speed SFP+ support */
  61. mac->ops.setup_link = &ixgbe_setup_mac_link_multispeed_fiber;
  62. mac->ops.disable_tx_laser =
  63. &ixgbe_disable_tx_laser_multispeed_fiber;
  64. mac->ops.enable_tx_laser =
  65. &ixgbe_enable_tx_laser_multispeed_fiber;
  66. mac->ops.flap_tx_laser = &ixgbe_flap_tx_laser_multispeed_fiber;
  67. } else {
  68. mac->ops.disable_tx_laser = NULL;
  69. mac->ops.enable_tx_laser = NULL;
  70. mac->ops.flap_tx_laser = NULL;
  71. if ((mac->ops.get_media_type(hw) ==
  72. ixgbe_media_type_backplane) &&
  73. (hw->phy.smart_speed == ixgbe_smart_speed_auto ||
  74. hw->phy.smart_speed == ixgbe_smart_speed_on))
  75. mac->ops.setup_link = &ixgbe_setup_mac_link_smartspeed;
  76. else
  77. mac->ops.setup_link = &ixgbe_setup_mac_link_82599;
  78. }
  79. }
  80. static s32 ixgbe_setup_sfp_modules_82599(struct ixgbe_hw *hw)
  81. {
  82. s32 ret_val = 0;
  83. u16 list_offset, data_offset, data_value;
  84. if (hw->phy.sfp_type != ixgbe_sfp_type_unknown) {
  85. ixgbe_init_mac_link_ops_82599(hw);
  86. hw->phy.ops.reset = NULL;
  87. ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
  88. &data_offset);
  89. if (ret_val != 0)
  90. goto setup_sfp_out;
  91. /* PHY config will finish before releasing the semaphore */
  92. ret_val = ixgbe_acquire_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
  93. if (ret_val != 0) {
  94. ret_val = IXGBE_ERR_SWFW_SYNC;
  95. goto setup_sfp_out;
  96. }
  97. hw->eeprom.ops.read(hw, ++data_offset, &data_value);
  98. while (data_value != 0xffff) {
  99. IXGBE_WRITE_REG(hw, IXGBE_CORECTL, data_value);
  100. IXGBE_WRITE_FLUSH(hw);
  101. hw->eeprom.ops.read(hw, ++data_offset, &data_value);
  102. }
  103. /* Now restart DSP by setting Restart_AN */
  104. IXGBE_WRITE_REG(hw, IXGBE_AUTOC,
  105. (IXGBE_READ_REG(hw, IXGBE_AUTOC) | IXGBE_AUTOC_AN_RESTART));
  106. /* Release the semaphore */
  107. ixgbe_release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
  108. /* Delay obtaining semaphore again to allow FW access */
  109. msleep(hw->eeprom.semaphore_delay);
  110. }
  111. setup_sfp_out:
  112. return ret_val;
  113. }
  114. /**
  115. * ixgbe_get_pcie_msix_count_82599 - Gets MSI-X vector count
  116. * @hw: pointer to hardware structure
  117. *
  118. * Read PCIe configuration space, and get the MSI-X vector count from
  119. * the capabilities table.
  120. **/
  121. static u32 ixgbe_get_pcie_msix_count_82599(struct ixgbe_hw *hw)
  122. {
  123. struct ixgbe_adapter *adapter = hw->back;
  124. u16 msix_count;
  125. pci_read_config_word(adapter->pdev, IXGBE_PCIE_MSIX_82599_CAPS,
  126. &msix_count);
  127. msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK;
  128. /* MSI-X count is zero-based in HW, so increment to give proper value */
  129. msix_count++;
  130. return msix_count;
  131. }
  132. static s32 ixgbe_get_invariants_82599(struct ixgbe_hw *hw)
  133. {
  134. struct ixgbe_mac_info *mac = &hw->mac;
  135. ixgbe_init_mac_link_ops_82599(hw);
  136. mac->mcft_size = IXGBE_82599_MC_TBL_SIZE;
  137. mac->vft_size = IXGBE_82599_VFT_TBL_SIZE;
  138. mac->num_rar_entries = IXGBE_82599_RAR_ENTRIES;
  139. mac->max_rx_queues = IXGBE_82599_MAX_RX_QUEUES;
  140. mac->max_tx_queues = IXGBE_82599_MAX_TX_QUEUES;
  141. mac->max_msix_vectors = ixgbe_get_pcie_msix_count_82599(hw);
  142. return 0;
  143. }
  144. /**
  145. * ixgbe_init_phy_ops_82599 - PHY/SFP specific init
  146. * @hw: pointer to hardware structure
  147. *
  148. * Initialize any function pointers that were not able to be
  149. * set during get_invariants because the PHY/SFP type was
  150. * not known. Perform the SFP init if necessary.
  151. *
  152. **/
  153. static s32 ixgbe_init_phy_ops_82599(struct ixgbe_hw *hw)
  154. {
  155. struct ixgbe_mac_info *mac = &hw->mac;
  156. struct ixgbe_phy_info *phy = &hw->phy;
  157. s32 ret_val = 0;
  158. /* Identify the PHY or SFP module */
  159. ret_val = phy->ops.identify(hw);
  160. /* Setup function pointers based on detected SFP module and speeds */
  161. ixgbe_init_mac_link_ops_82599(hw);
  162. /* If copper media, overwrite with copper function pointers */
  163. if (mac->ops.get_media_type(hw) == ixgbe_media_type_copper) {
  164. mac->ops.setup_link = &ixgbe_setup_copper_link_82599;
  165. mac->ops.get_link_capabilities =
  166. &ixgbe_get_copper_link_capabilities_82599;
  167. }
  168. /* Set necessary function pointers based on phy type */
  169. switch (hw->phy.type) {
  170. case ixgbe_phy_tn:
  171. phy->ops.check_link = &ixgbe_check_phy_link_tnx;
  172. phy->ops.get_firmware_version =
  173. &ixgbe_get_phy_firmware_version_tnx;
  174. break;
  175. default:
  176. break;
  177. }
  178. return ret_val;
  179. }
  180. /**
  181. * ixgbe_get_link_capabilities_82599 - Determines link capabilities
  182. * @hw: pointer to hardware structure
  183. * @speed: pointer to link speed
  184. * @negotiation: true when autoneg or autotry is enabled
  185. *
  186. * Determines the link capabilities by reading the AUTOC register.
  187. **/
  188. static s32 ixgbe_get_link_capabilities_82599(struct ixgbe_hw *hw,
  189. ixgbe_link_speed *speed,
  190. bool *negotiation)
  191. {
  192. s32 status = 0;
  193. u32 autoc = 0;
  194. /*
  195. * Determine link capabilities based on the stored value of AUTOC,
  196. * which represents EEPROM defaults. If AUTOC value has not been
  197. * stored, use the current register value.
  198. */
  199. if (hw->mac.orig_link_settings_stored)
  200. autoc = hw->mac.orig_autoc;
  201. else
  202. autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  203. switch (autoc & IXGBE_AUTOC_LMS_MASK) {
  204. case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
  205. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  206. *negotiation = false;
  207. break;
  208. case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
  209. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  210. *negotiation = false;
  211. break;
  212. case IXGBE_AUTOC_LMS_1G_AN:
  213. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  214. *negotiation = true;
  215. break;
  216. case IXGBE_AUTOC_LMS_10G_SERIAL:
  217. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  218. *negotiation = false;
  219. break;
  220. case IXGBE_AUTOC_LMS_KX4_KX_KR:
  221. case IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN:
  222. *speed = IXGBE_LINK_SPEED_UNKNOWN;
  223. if (autoc & IXGBE_AUTOC_KR_SUPP)
  224. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  225. if (autoc & IXGBE_AUTOC_KX4_SUPP)
  226. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  227. if (autoc & IXGBE_AUTOC_KX_SUPP)
  228. *speed |= IXGBE_LINK_SPEED_1GB_FULL;
  229. *negotiation = true;
  230. break;
  231. case IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII:
  232. *speed = IXGBE_LINK_SPEED_100_FULL;
  233. if (autoc & IXGBE_AUTOC_KR_SUPP)
  234. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  235. if (autoc & IXGBE_AUTOC_KX4_SUPP)
  236. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  237. if (autoc & IXGBE_AUTOC_KX_SUPP)
  238. *speed |= IXGBE_LINK_SPEED_1GB_FULL;
  239. *negotiation = true;
  240. break;
  241. case IXGBE_AUTOC_LMS_SGMII_1G_100M:
  242. *speed = IXGBE_LINK_SPEED_1GB_FULL | IXGBE_LINK_SPEED_100_FULL;
  243. *negotiation = false;
  244. break;
  245. default:
  246. status = IXGBE_ERR_LINK_SETUP;
  247. goto out;
  248. break;
  249. }
  250. if (hw->phy.multispeed_fiber) {
  251. *speed |= IXGBE_LINK_SPEED_10GB_FULL |
  252. IXGBE_LINK_SPEED_1GB_FULL;
  253. *negotiation = true;
  254. }
  255. out:
  256. return status;
  257. }
  258. /**
  259. * ixgbe_get_copper_link_capabilities_82599 - Determines link capabilities
  260. * @hw: pointer to hardware structure
  261. * @speed: pointer to link speed
  262. * @autoneg: boolean auto-negotiation value
  263. *
  264. * Determines the link capabilities by reading the AUTOC register.
  265. **/
  266. static s32 ixgbe_get_copper_link_capabilities_82599(struct ixgbe_hw *hw,
  267. ixgbe_link_speed *speed,
  268. bool *autoneg)
  269. {
  270. s32 status = IXGBE_ERR_LINK_SETUP;
  271. u16 speed_ability;
  272. *speed = 0;
  273. *autoneg = true;
  274. status = hw->phy.ops.read_reg(hw, MDIO_SPEED, MDIO_MMD_PMAPMD,
  275. &speed_ability);
  276. if (status == 0) {
  277. if (speed_ability & MDIO_SPEED_10G)
  278. *speed |= IXGBE_LINK_SPEED_10GB_FULL;
  279. if (speed_ability & MDIO_PMA_SPEED_1000)
  280. *speed |= IXGBE_LINK_SPEED_1GB_FULL;
  281. }
  282. return status;
  283. }
  284. /**
  285. * ixgbe_get_media_type_82599 - Get media type
  286. * @hw: pointer to hardware structure
  287. *
  288. * Returns the media type (fiber, copper, backplane)
  289. **/
  290. static enum ixgbe_media_type ixgbe_get_media_type_82599(struct ixgbe_hw *hw)
  291. {
  292. enum ixgbe_media_type media_type;
  293. /* Detect if there is a copper PHY attached. */
  294. if (hw->phy.type == ixgbe_phy_cu_unknown ||
  295. hw->phy.type == ixgbe_phy_tn) {
  296. media_type = ixgbe_media_type_copper;
  297. goto out;
  298. }
  299. switch (hw->device_id) {
  300. case IXGBE_DEV_ID_82599_KX4:
  301. case IXGBE_DEV_ID_82599_KX4_MEZZ:
  302. case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
  303. case IXGBE_DEV_ID_82599_KR:
  304. case IXGBE_DEV_ID_82599_XAUI_LOM:
  305. /* Default device ID is mezzanine card KX/KX4 */
  306. media_type = ixgbe_media_type_backplane;
  307. break;
  308. case IXGBE_DEV_ID_82599_SFP:
  309. case IXGBE_DEV_ID_82599_SFP_EM:
  310. media_type = ixgbe_media_type_fiber;
  311. break;
  312. case IXGBE_DEV_ID_82599_CX4:
  313. media_type = ixgbe_media_type_cx4;
  314. break;
  315. default:
  316. media_type = ixgbe_media_type_unknown;
  317. break;
  318. }
  319. out:
  320. return media_type;
  321. }
  322. /**
  323. * ixgbe_start_mac_link_82599 - Setup MAC link settings
  324. * @hw: pointer to hardware structure
  325. * @autoneg_wait_to_complete: true when waiting for completion is needed
  326. *
  327. * Configures link settings based on values in the ixgbe_hw struct.
  328. * Restarts the link. Performs autonegotiation if needed.
  329. **/
  330. s32 ixgbe_start_mac_link_82599(struct ixgbe_hw *hw,
  331. bool autoneg_wait_to_complete)
  332. {
  333. u32 autoc_reg;
  334. u32 links_reg;
  335. u32 i;
  336. s32 status = 0;
  337. /* Restart link */
  338. autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  339. autoc_reg |= IXGBE_AUTOC_AN_RESTART;
  340. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
  341. /* Only poll for autoneg to complete if specified to do so */
  342. if (autoneg_wait_to_complete) {
  343. if ((autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
  344. IXGBE_AUTOC_LMS_KX4_KX_KR ||
  345. (autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
  346. IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
  347. (autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
  348. IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
  349. links_reg = 0; /* Just in case Autoneg time = 0 */
  350. for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
  351. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  352. if (links_reg & IXGBE_LINKS_KX_AN_COMP)
  353. break;
  354. msleep(100);
  355. }
  356. if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
  357. status = IXGBE_ERR_AUTONEG_NOT_COMPLETE;
  358. hw_dbg(hw, "Autoneg did not complete.\n");
  359. }
  360. }
  361. }
  362. /* Add delay to filter out noises during initial link setup */
  363. msleep(50);
  364. return status;
  365. }
  366. /**
  367. * ixgbe_disable_tx_laser_multispeed_fiber - Disable Tx laser
  368. * @hw: pointer to hardware structure
  369. *
  370. * The base drivers may require better control over SFP+ module
  371. * PHY states. This includes selectively shutting down the Tx
  372. * laser on the PHY, effectively halting physical link.
  373. **/
  374. void ixgbe_disable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw)
  375. {
  376. u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
  377. /* Disable tx laser; allow 100us to go dark per spec */
  378. esdp_reg |= IXGBE_ESDP_SDP3;
  379. IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
  380. IXGBE_WRITE_FLUSH(hw);
  381. udelay(100);
  382. }
  383. /**
  384. * ixgbe_enable_tx_laser_multispeed_fiber - Enable Tx laser
  385. * @hw: pointer to hardware structure
  386. *
  387. * The base drivers may require better control over SFP+ module
  388. * PHY states. This includes selectively turning on the Tx
  389. * laser on the PHY, effectively starting physical link.
  390. **/
  391. void ixgbe_enable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw)
  392. {
  393. u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
  394. /* Enable tx laser; allow 100ms to light up */
  395. esdp_reg &= ~IXGBE_ESDP_SDP3;
  396. IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
  397. IXGBE_WRITE_FLUSH(hw);
  398. msleep(100);
  399. }
  400. /**
  401. * ixgbe_flap_tx_laser_multispeed_fiber - Flap Tx laser
  402. * @hw: pointer to hardware structure
  403. *
  404. * When the driver changes the link speeds that it can support,
  405. * it sets autotry_restart to true to indicate that we need to
  406. * initiate a new autotry session with the link partner. To do
  407. * so, we set the speed then disable and re-enable the tx laser, to
  408. * alert the link partner that it also needs to restart autotry on its
  409. * end. This is consistent with true clause 37 autoneg, which also
  410. * involves a loss of signal.
  411. **/
  412. void ixgbe_flap_tx_laser_multispeed_fiber(struct ixgbe_hw *hw)
  413. {
  414. hw_dbg(hw, "ixgbe_flap_tx_laser_multispeed_fiber\n");
  415. if (hw->mac.autotry_restart) {
  416. ixgbe_disable_tx_laser_multispeed_fiber(hw);
  417. ixgbe_enable_tx_laser_multispeed_fiber(hw);
  418. hw->mac.autotry_restart = false;
  419. }
  420. }
  421. /**
  422. * ixgbe_setup_mac_link_multispeed_fiber - Set MAC link speed
  423. * @hw: pointer to hardware structure
  424. * @speed: new link speed
  425. * @autoneg: true if autonegotiation enabled
  426. * @autoneg_wait_to_complete: true when waiting for completion is needed
  427. *
  428. * Set the link speed in the AUTOC register and restarts link.
  429. **/
  430. s32 ixgbe_setup_mac_link_multispeed_fiber(struct ixgbe_hw *hw,
  431. ixgbe_link_speed speed,
  432. bool autoneg,
  433. bool autoneg_wait_to_complete)
  434. {
  435. s32 status = 0;
  436. ixgbe_link_speed phy_link_speed;
  437. ixgbe_link_speed highest_link_speed = IXGBE_LINK_SPEED_UNKNOWN;
  438. u32 speedcnt = 0;
  439. u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
  440. bool link_up = false;
  441. bool negotiation;
  442. int i;
  443. /* Mask off requested but non-supported speeds */
  444. hw->mac.ops.get_link_capabilities(hw, &phy_link_speed, &negotiation);
  445. speed &= phy_link_speed;
  446. /*
  447. * Try each speed one by one, highest priority first. We do this in
  448. * software because 10gb fiber doesn't support speed autonegotiation.
  449. */
  450. if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
  451. speedcnt++;
  452. highest_link_speed = IXGBE_LINK_SPEED_10GB_FULL;
  453. /* If we already have link at this speed, just jump out */
  454. hw->mac.ops.check_link(hw, &phy_link_speed, &link_up, false);
  455. if ((phy_link_speed == IXGBE_LINK_SPEED_10GB_FULL) && link_up)
  456. goto out;
  457. /* Set the module link speed */
  458. esdp_reg |= (IXGBE_ESDP_SDP5_DIR | IXGBE_ESDP_SDP5);
  459. IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
  460. IXGBE_WRITE_FLUSH(hw);
  461. /* Allow module to change analog characteristics (1G->10G) */
  462. msleep(40);
  463. status = ixgbe_setup_mac_link_82599(hw,
  464. IXGBE_LINK_SPEED_10GB_FULL,
  465. autoneg,
  466. autoneg_wait_to_complete);
  467. if (status != 0)
  468. return status;
  469. /* Flap the tx laser if it has not already been done */
  470. hw->mac.ops.flap_tx_laser(hw);
  471. /*
  472. * Wait for the controller to acquire link. Per IEEE 802.3ap,
  473. * Section 73.10.2, we may have to wait up to 500ms if KR is
  474. * attempted. 82599 uses the same timing for 10g SFI.
  475. */
  476. for (i = 0; i < 5; i++) {
  477. /* Wait for the link partner to also set speed */
  478. msleep(100);
  479. /* If we have link, just jump out */
  480. hw->mac.ops.check_link(hw, &phy_link_speed,
  481. &link_up, false);
  482. if (link_up)
  483. goto out;
  484. }
  485. }
  486. if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
  487. speedcnt++;
  488. if (highest_link_speed == IXGBE_LINK_SPEED_UNKNOWN)
  489. highest_link_speed = IXGBE_LINK_SPEED_1GB_FULL;
  490. /* If we already have link at this speed, just jump out */
  491. hw->mac.ops.check_link(hw, &phy_link_speed, &link_up, false);
  492. if ((phy_link_speed == IXGBE_LINK_SPEED_1GB_FULL) && link_up)
  493. goto out;
  494. /* Set the module link speed */
  495. esdp_reg &= ~IXGBE_ESDP_SDP5;
  496. esdp_reg |= IXGBE_ESDP_SDP5_DIR;
  497. IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
  498. IXGBE_WRITE_FLUSH(hw);
  499. /* Allow module to change analog characteristics (10G->1G) */
  500. msleep(40);
  501. status = ixgbe_setup_mac_link_82599(hw,
  502. IXGBE_LINK_SPEED_1GB_FULL,
  503. autoneg,
  504. autoneg_wait_to_complete);
  505. if (status != 0)
  506. return status;
  507. /* Flap the tx laser if it has not already been done */
  508. hw->mac.ops.flap_tx_laser(hw);
  509. /* Wait for the link partner to also set speed */
  510. msleep(100);
  511. /* If we have link, just jump out */
  512. hw->mac.ops.check_link(hw, &phy_link_speed, &link_up, false);
  513. if (link_up)
  514. goto out;
  515. }
  516. /*
  517. * We didn't get link. Configure back to the highest speed we tried,
  518. * (if there was more than one). We call ourselves back with just the
  519. * single highest speed that the user requested.
  520. */
  521. if (speedcnt > 1)
  522. status = ixgbe_setup_mac_link_multispeed_fiber(hw,
  523. highest_link_speed,
  524. autoneg,
  525. autoneg_wait_to_complete);
  526. out:
  527. /* Set autoneg_advertised value based on input link speed */
  528. hw->phy.autoneg_advertised = 0;
  529. if (speed & IXGBE_LINK_SPEED_10GB_FULL)
  530. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
  531. if (speed & IXGBE_LINK_SPEED_1GB_FULL)
  532. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
  533. return status;
  534. }
  535. /**
  536. * ixgbe_setup_mac_link_smartspeed - Set MAC link speed using SmartSpeed
  537. * @hw: pointer to hardware structure
  538. * @speed: new link speed
  539. * @autoneg: true if autonegotiation enabled
  540. * @autoneg_wait_to_complete: true when waiting for completion is needed
  541. *
  542. * Implements the Intel SmartSpeed algorithm.
  543. **/
  544. static s32 ixgbe_setup_mac_link_smartspeed(struct ixgbe_hw *hw,
  545. ixgbe_link_speed speed, bool autoneg,
  546. bool autoneg_wait_to_complete)
  547. {
  548. s32 status = 0;
  549. ixgbe_link_speed link_speed;
  550. s32 i, j;
  551. bool link_up = false;
  552. u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  553. hw_dbg(hw, "ixgbe_setup_mac_link_smartspeed.\n");
  554. /* Set autoneg_advertised value based on input link speed */
  555. hw->phy.autoneg_advertised = 0;
  556. if (speed & IXGBE_LINK_SPEED_10GB_FULL)
  557. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
  558. if (speed & IXGBE_LINK_SPEED_1GB_FULL)
  559. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
  560. if (speed & IXGBE_LINK_SPEED_100_FULL)
  561. hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
  562. /*
  563. * Implement Intel SmartSpeed algorithm. SmartSpeed will reduce the
  564. * autoneg advertisement if link is unable to be established at the
  565. * highest negotiated rate. This can sometimes happen due to integrity
  566. * issues with the physical media connection.
  567. */
  568. /* First, try to get link with full advertisement */
  569. hw->phy.smart_speed_active = false;
  570. for (j = 0; j < IXGBE_SMARTSPEED_MAX_RETRIES; j++) {
  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. Per IEEE 802.3ap,
  577. * Section 73.10.2, we may have to wait up to 500ms if KR is
  578. * attempted, or 200ms if KX/KX4/BX/BX4 is attempted, per
  579. * Table 9 in the AN MAS.
  580. */
  581. for (i = 0; i < 5; 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. }
  590. /*
  591. * We didn't get link. If we advertised KR plus one of KX4/KX
  592. * (or BX4/BX), then disable KR and try again.
  593. */
  594. if (((autoc_reg & IXGBE_AUTOC_KR_SUPP) == 0) ||
  595. ((autoc_reg & IXGBE_AUTOC_KX4_KX_SUPP_MASK) == 0))
  596. goto out;
  597. /* Turn SmartSpeed on to disable KR support */
  598. hw->phy.smart_speed_active = true;
  599. status = ixgbe_setup_mac_link_82599(hw, speed, autoneg,
  600. autoneg_wait_to_complete);
  601. if (status)
  602. goto out;
  603. /*
  604. * Wait for the controller to acquire link. 600ms will allow for
  605. * the AN link_fail_inhibit_timer as well for multiple cycles of
  606. * parallel detect, both 10g and 1g. This allows for the maximum
  607. * connect attempts as defined in the AN MAS table 73-7.
  608. */
  609. for (i = 0; i < 6; i++) {
  610. mdelay(100);
  611. /* If we have link, just jump out */
  612. hw->mac.ops.check_link(hw, &link_speed,
  613. &link_up, false);
  614. if (link_up)
  615. goto out;
  616. }
  617. /* We didn't get link. Turn SmartSpeed back off. */
  618. hw->phy.smart_speed_active = false;
  619. status = ixgbe_setup_mac_link_82599(hw, speed, autoneg,
  620. autoneg_wait_to_complete);
  621. out:
  622. return status;
  623. }
  624. /**
  625. * ixgbe_check_mac_link_82599 - Determine link and speed status
  626. * @hw: pointer to hardware structure
  627. * @speed: pointer to link speed
  628. * @link_up: true when link is up
  629. * @link_up_wait_to_complete: bool used to wait for link up or not
  630. *
  631. * Reads the links register to determine if link is up and the current speed
  632. **/
  633. static s32 ixgbe_check_mac_link_82599(struct ixgbe_hw *hw,
  634. ixgbe_link_speed *speed,
  635. bool *link_up,
  636. bool link_up_wait_to_complete)
  637. {
  638. u32 links_reg;
  639. u32 i;
  640. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  641. if (link_up_wait_to_complete) {
  642. for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
  643. if (links_reg & IXGBE_LINKS_UP) {
  644. *link_up = true;
  645. break;
  646. } else {
  647. *link_up = false;
  648. }
  649. msleep(100);
  650. links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
  651. }
  652. } else {
  653. if (links_reg & IXGBE_LINKS_UP)
  654. *link_up = true;
  655. else
  656. *link_up = false;
  657. }
  658. if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
  659. IXGBE_LINKS_SPEED_10G_82599)
  660. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  661. else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
  662. IXGBE_LINKS_SPEED_1G_82599)
  663. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  664. else
  665. *speed = IXGBE_LINK_SPEED_100_FULL;
  666. /* if link is down, zero out the current_mode */
  667. if (*link_up == false) {
  668. hw->fc.current_mode = ixgbe_fc_none;
  669. hw->fc.fc_was_autonegged = false;
  670. }
  671. return 0;
  672. }
  673. /**
  674. * ixgbe_setup_mac_link_82599 - Set MAC link speed
  675. * @hw: pointer to hardware structure
  676. * @speed: new link speed
  677. * @autoneg: true if autonegotiation enabled
  678. * @autoneg_wait_to_complete: true when waiting for completion is needed
  679. *
  680. * Set the link speed in the AUTOC register and restarts link.
  681. **/
  682. s32 ixgbe_setup_mac_link_82599(struct ixgbe_hw *hw,
  683. ixgbe_link_speed speed, bool autoneg,
  684. bool autoneg_wait_to_complete)
  685. {
  686. s32 status = 0;
  687. u32 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  688. u32 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
  689. u32 start_autoc = autoc;
  690. u32 orig_autoc = 0;
  691. u32 link_mode = autoc & IXGBE_AUTOC_LMS_MASK;
  692. u32 pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK;
  693. u32 pma_pmd_10g_serial = autoc2 & IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_MASK;
  694. u32 links_reg;
  695. u32 i;
  696. ixgbe_link_speed link_capabilities = IXGBE_LINK_SPEED_UNKNOWN;
  697. /* Check to see if speed passed in is supported. */
  698. hw->mac.ops.get_link_capabilities(hw, &link_capabilities, &autoneg);
  699. speed &= link_capabilities;
  700. if (speed == IXGBE_LINK_SPEED_UNKNOWN) {
  701. status = IXGBE_ERR_LINK_SETUP;
  702. goto out;
  703. }
  704. /* Use stored value (EEPROM defaults) of AUTOC to find KR/KX4 support*/
  705. if (hw->mac.orig_link_settings_stored)
  706. orig_autoc = hw->mac.orig_autoc;
  707. else
  708. orig_autoc = autoc;
  709. if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR ||
  710. link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
  711. link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
  712. /* Set KX4/KX/KR support according to speed requested */
  713. autoc &= ~(IXGBE_AUTOC_KX4_KX_SUPP_MASK | IXGBE_AUTOC_KR_SUPP);
  714. if (speed & IXGBE_LINK_SPEED_10GB_FULL)
  715. if (orig_autoc & IXGBE_AUTOC_KX4_SUPP)
  716. autoc |= IXGBE_AUTOC_KX4_SUPP;
  717. if ((orig_autoc & IXGBE_AUTOC_KR_SUPP) &&
  718. (hw->phy.smart_speed_active == false))
  719. autoc |= IXGBE_AUTOC_KR_SUPP;
  720. if (speed & IXGBE_LINK_SPEED_1GB_FULL)
  721. autoc |= IXGBE_AUTOC_KX_SUPP;
  722. } else if ((pma_pmd_1g == IXGBE_AUTOC_1G_SFI) &&
  723. (link_mode == IXGBE_AUTOC_LMS_1G_LINK_NO_AN ||
  724. link_mode == IXGBE_AUTOC_LMS_1G_AN)) {
  725. /* Switch from 1G SFI to 10G SFI if requested */
  726. if ((speed == IXGBE_LINK_SPEED_10GB_FULL) &&
  727. (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI)) {
  728. autoc &= ~IXGBE_AUTOC_LMS_MASK;
  729. autoc |= IXGBE_AUTOC_LMS_10G_SERIAL;
  730. }
  731. } else if ((pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI) &&
  732. (link_mode == IXGBE_AUTOC_LMS_10G_SERIAL)) {
  733. /* Switch from 10G SFI to 1G SFI if requested */
  734. if ((speed == IXGBE_LINK_SPEED_1GB_FULL) &&
  735. (pma_pmd_1g == IXGBE_AUTOC_1G_SFI)) {
  736. autoc &= ~IXGBE_AUTOC_LMS_MASK;
  737. if (autoneg)
  738. autoc |= IXGBE_AUTOC_LMS_1G_AN;
  739. else
  740. autoc |= IXGBE_AUTOC_LMS_1G_LINK_NO_AN;
  741. }
  742. }
  743. if (autoc != start_autoc) {
  744. /* Restart link */
  745. autoc |= IXGBE_AUTOC_AN_RESTART;
  746. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc);
  747. /* Only poll for autoneg to complete if specified to do so */
  748. if (autoneg_wait_to_complete) {
  749. if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR ||
  750. link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
  751. link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
  752. links_reg = 0; /*Just in case Autoneg time=0*/
  753. for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
  754. links_reg =
  755. IXGBE_READ_REG(hw, IXGBE_LINKS);
  756. if (links_reg & IXGBE_LINKS_KX_AN_COMP)
  757. break;
  758. msleep(100);
  759. }
  760. if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
  761. status =
  762. IXGBE_ERR_AUTONEG_NOT_COMPLETE;
  763. hw_dbg(hw, "Autoneg did not "
  764. "complete.\n");
  765. }
  766. }
  767. }
  768. /* Add delay to filter out noises during initial link setup */
  769. msleep(50);
  770. }
  771. out:
  772. return status;
  773. }
  774. /**
  775. * ixgbe_setup_copper_link_82599 - Set the PHY autoneg advertised field
  776. * @hw: pointer to hardware structure
  777. * @speed: new link speed
  778. * @autoneg: true if autonegotiation enabled
  779. * @autoneg_wait_to_complete: true if waiting is needed to complete
  780. *
  781. * Restarts link on PHY and MAC based on settings passed in.
  782. **/
  783. static s32 ixgbe_setup_copper_link_82599(struct ixgbe_hw *hw,
  784. ixgbe_link_speed speed,
  785. bool autoneg,
  786. bool autoneg_wait_to_complete)
  787. {
  788. s32 status;
  789. /* Setup the PHY according to input speed */
  790. status = hw->phy.ops.setup_link_speed(hw, speed, autoneg,
  791. autoneg_wait_to_complete);
  792. /* Set up MAC */
  793. ixgbe_start_mac_link_82599(hw, autoneg_wait_to_complete);
  794. return status;
  795. }
  796. /**
  797. * ixgbe_reset_hw_82599 - Perform hardware reset
  798. * @hw: pointer to hardware structure
  799. *
  800. * Resets the hardware by resetting the transmit and receive units, masks
  801. * and clears all interrupts, perform a PHY reset, and perform a link (MAC)
  802. * reset.
  803. **/
  804. static s32 ixgbe_reset_hw_82599(struct ixgbe_hw *hw)
  805. {
  806. s32 status = 0;
  807. u32 ctrl;
  808. u32 i;
  809. u32 autoc;
  810. u32 autoc2;
  811. /* Call adapter stop to disable tx/rx and clear interrupts */
  812. hw->mac.ops.stop_adapter(hw);
  813. /* PHY ops must be identified and initialized prior to reset */
  814. /* Init PHY and function pointers, perform SFP setup */
  815. status = hw->phy.ops.init(hw);
  816. if (status == IXGBE_ERR_SFP_NOT_SUPPORTED)
  817. goto reset_hw_out;
  818. /* Setup SFP module if there is one present. */
  819. if (hw->phy.sfp_setup_needed) {
  820. status = hw->mac.ops.setup_sfp(hw);
  821. hw->phy.sfp_setup_needed = false;
  822. }
  823. /* Reset PHY */
  824. if (hw->phy.reset_disable == false && hw->phy.ops.reset != NULL)
  825. hw->phy.ops.reset(hw);
  826. /*
  827. * Prevent the PCI-E bus from from hanging by disabling PCI-E master
  828. * access and verify no pending requests before reset
  829. */
  830. status = ixgbe_disable_pcie_master(hw);
  831. if (status != 0) {
  832. status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
  833. hw_dbg(hw, "PCI-E Master disable polling has failed.\n");
  834. }
  835. /*
  836. * Issue global reset to the MAC. This needs to be a SW reset.
  837. * If link reset is used, it might reset the MAC when mng is using it
  838. */
  839. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  840. IXGBE_WRITE_REG(hw, IXGBE_CTRL, (ctrl | IXGBE_CTRL_RST));
  841. IXGBE_WRITE_FLUSH(hw);
  842. /* Poll for reset bit to self-clear indicating reset is complete */
  843. for (i = 0; i < 10; i++) {
  844. udelay(1);
  845. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  846. if (!(ctrl & IXGBE_CTRL_RST))
  847. break;
  848. }
  849. if (ctrl & IXGBE_CTRL_RST) {
  850. status = IXGBE_ERR_RESET_FAILED;
  851. hw_dbg(hw, "Reset polling failed to complete.\n");
  852. }
  853. msleep(50);
  854. /*
  855. * Store the original AUTOC/AUTOC2 values if they have not been
  856. * stored off yet. Otherwise restore the stored original
  857. * values since the reset operation sets back to defaults.
  858. */
  859. autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  860. autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
  861. if (hw->mac.orig_link_settings_stored == false) {
  862. hw->mac.orig_autoc = autoc;
  863. hw->mac.orig_autoc2 = autoc2;
  864. hw->mac.orig_link_settings_stored = true;
  865. } else {
  866. if (autoc != hw->mac.orig_autoc)
  867. IXGBE_WRITE_REG(hw, IXGBE_AUTOC, (hw->mac.orig_autoc |
  868. IXGBE_AUTOC_AN_RESTART));
  869. if ((autoc2 & IXGBE_AUTOC2_UPPER_MASK) !=
  870. (hw->mac.orig_autoc2 & IXGBE_AUTOC2_UPPER_MASK)) {
  871. autoc2 &= ~IXGBE_AUTOC2_UPPER_MASK;
  872. autoc2 |= (hw->mac.orig_autoc2 &
  873. IXGBE_AUTOC2_UPPER_MASK);
  874. IXGBE_WRITE_REG(hw, IXGBE_AUTOC2, autoc2);
  875. }
  876. }
  877. /*
  878. * Store MAC address from RAR0, clear receive address registers, and
  879. * clear the multicast table. Also reset num_rar_entries to 128,
  880. * since we modify this value when programming the SAN MAC address.
  881. */
  882. hw->mac.num_rar_entries = 128;
  883. hw->mac.ops.init_rx_addrs(hw);
  884. /* Store the permanent mac address */
  885. hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
  886. /* Store the permanent SAN mac address */
  887. hw->mac.ops.get_san_mac_addr(hw, hw->mac.san_addr);
  888. /* Add the SAN MAC address to the RAR only if it's a valid address */
  889. if (ixgbe_validate_mac_addr(hw->mac.san_addr) == 0) {
  890. hw->mac.ops.set_rar(hw, hw->mac.num_rar_entries - 1,
  891. hw->mac.san_addr, 0, IXGBE_RAH_AV);
  892. /* Reserve the last RAR for the SAN MAC address */
  893. hw->mac.num_rar_entries--;
  894. }
  895. /* Store the alternative WWNN/WWPN prefix */
  896. hw->mac.ops.get_wwn_prefix(hw, &hw->mac.wwnn_prefix,
  897. &hw->mac.wwpn_prefix);
  898. reset_hw_out:
  899. return status;
  900. }
  901. /**
  902. * ixgbe_clear_vmdq_82599 - Disassociate a VMDq pool index from a rx address
  903. * @hw: pointer to hardware struct
  904. * @rar: receive address register index to disassociate
  905. * @vmdq: VMDq pool index to remove from the rar
  906. **/
  907. static s32 ixgbe_clear_vmdq_82599(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
  908. {
  909. u32 mpsar_lo, mpsar_hi;
  910. u32 rar_entries = hw->mac.num_rar_entries;
  911. if (rar < rar_entries) {
  912. mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
  913. mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
  914. if (!mpsar_lo && !mpsar_hi)
  915. goto done;
  916. if (vmdq == IXGBE_CLEAR_VMDQ_ALL) {
  917. if (mpsar_lo) {
  918. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
  919. mpsar_lo = 0;
  920. }
  921. if (mpsar_hi) {
  922. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
  923. mpsar_hi = 0;
  924. }
  925. } else if (vmdq < 32) {
  926. mpsar_lo &= ~(1 << vmdq);
  927. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar_lo);
  928. } else {
  929. mpsar_hi &= ~(1 << (vmdq - 32));
  930. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar_hi);
  931. }
  932. /* was that the last pool using this rar? */
  933. if (mpsar_lo == 0 && mpsar_hi == 0 && rar != 0)
  934. hw->mac.ops.clear_rar(hw, rar);
  935. } else {
  936. hw_dbg(hw, "RAR index %d is out of range.\n", rar);
  937. }
  938. done:
  939. return 0;
  940. }
  941. /**
  942. * ixgbe_set_vmdq_82599 - Associate a VMDq pool index with a rx address
  943. * @hw: pointer to hardware struct
  944. * @rar: receive address register index to associate with a VMDq index
  945. * @vmdq: VMDq pool index
  946. **/
  947. static s32 ixgbe_set_vmdq_82599(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
  948. {
  949. u32 mpsar;
  950. u32 rar_entries = hw->mac.num_rar_entries;
  951. if (rar < rar_entries) {
  952. if (vmdq < 32) {
  953. mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
  954. mpsar |= 1 << vmdq;
  955. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar);
  956. } else {
  957. mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
  958. mpsar |= 1 << (vmdq - 32);
  959. IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar);
  960. }
  961. } else {
  962. hw_dbg(hw, "RAR index %d is out of range.\n", rar);
  963. }
  964. return 0;
  965. }
  966. /**
  967. * ixgbe_set_vfta_82599 - Set VLAN filter table
  968. * @hw: pointer to hardware structure
  969. * @vlan: VLAN id to write to VLAN filter
  970. * @vind: VMDq output index that maps queue to VLAN id in VFVFB
  971. * @vlan_on: boolean flag to turn on/off VLAN in VFVF
  972. *
  973. * Turn on/off specified VLAN in the VLAN filter table.
  974. **/
  975. static s32 ixgbe_set_vfta_82599(struct ixgbe_hw *hw, u32 vlan, u32 vind,
  976. bool vlan_on)
  977. {
  978. u32 regindex;
  979. u32 vlvf_index;
  980. u32 bitindex;
  981. u32 bits;
  982. u32 first_empty_slot;
  983. u32 vt_ctl;
  984. if (vlan > 4095)
  985. return IXGBE_ERR_PARAM;
  986. /*
  987. * this is a 2 part operation - first the VFTA, then the
  988. * VLVF and VLVFB if vind is set
  989. */
  990. /* Part 1
  991. * The VFTA is a bitstring made up of 128 32-bit registers
  992. * that enable the particular VLAN id, much like the MTA:
  993. * bits[11-5]: which register
  994. * bits[4-0]: which bit in the register
  995. */
  996. regindex = (vlan >> 5) & 0x7F;
  997. bitindex = vlan & 0x1F;
  998. bits = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
  999. if (vlan_on)
  1000. bits |= (1 << bitindex);
  1001. else
  1002. bits &= ~(1 << bitindex);
  1003. IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), bits);
  1004. /* Part 2
  1005. * If VT mode is set
  1006. * Either vlan_on
  1007. * make sure the vlan is in VLVF
  1008. * set the vind bit in the matching VLVFB
  1009. * Or !vlan_on
  1010. * clear the pool bit and possibly the vind
  1011. */
  1012. vt_ctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
  1013. if (!(vt_ctl & IXGBE_VT_CTL_VT_ENABLE))
  1014. goto out;
  1015. /* find the vlanid or the first empty slot */
  1016. first_empty_slot = 0;
  1017. for (vlvf_index = 1; vlvf_index < IXGBE_VLVF_ENTRIES; vlvf_index++) {
  1018. bits = IXGBE_READ_REG(hw, IXGBE_VLVF(vlvf_index));
  1019. if (!bits && !first_empty_slot)
  1020. first_empty_slot = vlvf_index;
  1021. else if ((bits & 0x0FFF) == vlan)
  1022. break;
  1023. }
  1024. if (vlvf_index >= IXGBE_VLVF_ENTRIES) {
  1025. if (first_empty_slot)
  1026. vlvf_index = first_empty_slot;
  1027. else {
  1028. hw_dbg(hw, "No space in VLVF.\n");
  1029. goto out;
  1030. }
  1031. }
  1032. if (vlan_on) {
  1033. /* set the pool bit */
  1034. if (vind < 32) {
  1035. bits = IXGBE_READ_REG(hw,
  1036. IXGBE_VLVFB(vlvf_index * 2));
  1037. bits |= (1 << vind);
  1038. IXGBE_WRITE_REG(hw,
  1039. IXGBE_VLVFB(vlvf_index * 2), bits);
  1040. } else {
  1041. bits = IXGBE_READ_REG(hw,
  1042. IXGBE_VLVFB((vlvf_index * 2) + 1));
  1043. bits |= (1 << (vind - 32));
  1044. IXGBE_WRITE_REG(hw,
  1045. IXGBE_VLVFB((vlvf_index * 2) + 1), bits);
  1046. }
  1047. } else {
  1048. /* clear the pool bit */
  1049. if (vind < 32) {
  1050. bits = IXGBE_READ_REG(hw,
  1051. IXGBE_VLVFB(vlvf_index * 2));
  1052. bits &= ~(1 << vind);
  1053. IXGBE_WRITE_REG(hw,
  1054. IXGBE_VLVFB(vlvf_index * 2), bits);
  1055. bits |= IXGBE_READ_REG(hw,
  1056. IXGBE_VLVFB((vlvf_index * 2) + 1));
  1057. } else {
  1058. bits = IXGBE_READ_REG(hw,
  1059. IXGBE_VLVFB((vlvf_index * 2) + 1));
  1060. bits &= ~(1 << (vind - 32));
  1061. IXGBE_WRITE_REG(hw,
  1062. IXGBE_VLVFB((vlvf_index * 2) + 1), bits);
  1063. bits |= IXGBE_READ_REG(hw,
  1064. IXGBE_VLVFB(vlvf_index * 2));
  1065. }
  1066. }
  1067. if (bits) {
  1068. IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index),
  1069. (IXGBE_VLVF_VIEN | vlan));
  1070. /* if bits is non-zero then some pools/VFs are still
  1071. * using this VLAN ID. Force the VFTA entry to on */
  1072. bits = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
  1073. bits |= (1 << bitindex);
  1074. IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), bits);
  1075. }
  1076. else
  1077. IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), 0);
  1078. out:
  1079. return 0;
  1080. }
  1081. /**
  1082. * ixgbe_clear_vfta_82599 - Clear VLAN filter table
  1083. * @hw: pointer to hardware structure
  1084. *
  1085. * Clears the VLAN filer table, and the VMDq index associated with the filter
  1086. **/
  1087. static s32 ixgbe_clear_vfta_82599(struct ixgbe_hw *hw)
  1088. {
  1089. u32 offset;
  1090. for (offset = 0; offset < hw->mac.vft_size; offset++)
  1091. IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
  1092. for (offset = 0; offset < IXGBE_VLVF_ENTRIES; offset++) {
  1093. IXGBE_WRITE_REG(hw, IXGBE_VLVF(offset), 0);
  1094. IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset * 2), 0);
  1095. IXGBE_WRITE_REG(hw, IXGBE_VLVFB((offset * 2) + 1), 0);
  1096. }
  1097. return 0;
  1098. }
  1099. /**
  1100. * ixgbe_init_uta_tables_82599 - Initialize the Unicast Table Array
  1101. * @hw: pointer to hardware structure
  1102. **/
  1103. static s32 ixgbe_init_uta_tables_82599(struct ixgbe_hw *hw)
  1104. {
  1105. int i;
  1106. hw_dbg(hw, " Clearing UTA\n");
  1107. for (i = 0; i < 128; i++)
  1108. IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
  1109. return 0;
  1110. }
  1111. /**
  1112. * ixgbe_reinit_fdir_tables_82599 - Reinitialize Flow Director tables.
  1113. * @hw: pointer to hardware structure
  1114. **/
  1115. s32 ixgbe_reinit_fdir_tables_82599(struct ixgbe_hw *hw)
  1116. {
  1117. int i;
  1118. u32 fdirctrl = IXGBE_READ_REG(hw, IXGBE_FDIRCTRL);
  1119. fdirctrl &= ~IXGBE_FDIRCTRL_INIT_DONE;
  1120. /*
  1121. * Before starting reinitialization process,
  1122. * FDIRCMD.CMD must be zero.
  1123. */
  1124. for (i = 0; i < IXGBE_FDIRCMD_CMD_POLL; i++) {
  1125. if (!(IXGBE_READ_REG(hw, IXGBE_FDIRCMD) &
  1126. IXGBE_FDIRCMD_CMD_MASK))
  1127. break;
  1128. udelay(10);
  1129. }
  1130. if (i >= IXGBE_FDIRCMD_CMD_POLL) {
  1131. hw_dbg(hw ,"Flow Director previous command isn't complete, "
  1132. "aborting table re-initialization. \n");
  1133. return IXGBE_ERR_FDIR_REINIT_FAILED;
  1134. }
  1135. IXGBE_WRITE_REG(hw, IXGBE_FDIRFREE, 0);
  1136. IXGBE_WRITE_FLUSH(hw);
  1137. /*
  1138. * 82599 adapters flow director init flow cannot be restarted,
  1139. * Workaround 82599 silicon errata by performing the following steps
  1140. * before re-writing the FDIRCTRL control register with the same value.
  1141. * - write 1 to bit 8 of FDIRCMD register &
  1142. * - write 0 to bit 8 of FDIRCMD register
  1143. */
  1144. IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
  1145. (IXGBE_READ_REG(hw, IXGBE_FDIRCMD) |
  1146. IXGBE_FDIRCMD_CLEARHT));
  1147. IXGBE_WRITE_FLUSH(hw);
  1148. IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
  1149. (IXGBE_READ_REG(hw, IXGBE_FDIRCMD) &
  1150. ~IXGBE_FDIRCMD_CLEARHT));
  1151. IXGBE_WRITE_FLUSH(hw);
  1152. /*
  1153. * Clear FDIR Hash register to clear any leftover hashes
  1154. * waiting to be programmed.
  1155. */
  1156. IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, 0x00);
  1157. IXGBE_WRITE_FLUSH(hw);
  1158. IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl);
  1159. IXGBE_WRITE_FLUSH(hw);
  1160. /* Poll init-done after we write FDIRCTRL register */
  1161. for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) {
  1162. if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) &
  1163. IXGBE_FDIRCTRL_INIT_DONE)
  1164. break;
  1165. udelay(10);
  1166. }
  1167. if (i >= IXGBE_FDIR_INIT_DONE_POLL) {
  1168. hw_dbg(hw, "Flow Director Signature poll time exceeded!\n");
  1169. return IXGBE_ERR_FDIR_REINIT_FAILED;
  1170. }
  1171. /* Clear FDIR statistics registers (read to clear) */
  1172. IXGBE_READ_REG(hw, IXGBE_FDIRUSTAT);
  1173. IXGBE_READ_REG(hw, IXGBE_FDIRFSTAT);
  1174. IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
  1175. IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
  1176. IXGBE_READ_REG(hw, IXGBE_FDIRLEN);
  1177. return 0;
  1178. }
  1179. /**
  1180. * ixgbe_init_fdir_signature_82599 - Initialize Flow Director signature filters
  1181. * @hw: pointer to hardware structure
  1182. * @pballoc: which mode to allocate filters with
  1183. **/
  1184. s32 ixgbe_init_fdir_signature_82599(struct ixgbe_hw *hw, u32 pballoc)
  1185. {
  1186. u32 fdirctrl = 0;
  1187. u32 pbsize;
  1188. int i;
  1189. /*
  1190. * Before enabling Flow Director, the Rx Packet Buffer size
  1191. * must be reduced. The new value is the current size minus
  1192. * flow director memory usage size.
  1193. */
  1194. pbsize = (1 << (IXGBE_FDIR_PBALLOC_SIZE_SHIFT + pballoc));
  1195. IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(0),
  1196. (IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(0)) - pbsize));
  1197. /*
  1198. * The defaults in the HW for RX PB 1-7 are not zero and so should be
  1199. * intialized to zero for non DCB mode otherwise actual total RX PB
  1200. * would be bigger than programmed and filter space would run into
  1201. * the PB 0 region.
  1202. */
  1203. for (i = 1; i < 8; i++)
  1204. IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), 0);
  1205. /* Send interrupt when 64 filters are left */
  1206. fdirctrl |= 4 << IXGBE_FDIRCTRL_FULL_THRESH_SHIFT;
  1207. /* Set the maximum length per hash bucket to 0xA filters */
  1208. fdirctrl |= 0xA << IXGBE_FDIRCTRL_MAX_LENGTH_SHIFT;
  1209. switch (pballoc) {
  1210. case IXGBE_FDIR_PBALLOC_64K:
  1211. /* 8k - 1 signature filters */
  1212. fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_64K;
  1213. break;
  1214. case IXGBE_FDIR_PBALLOC_128K:
  1215. /* 16k - 1 signature filters */
  1216. fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_128K;
  1217. break;
  1218. case IXGBE_FDIR_PBALLOC_256K:
  1219. /* 32k - 1 signature filters */
  1220. fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_256K;
  1221. break;
  1222. default:
  1223. /* bad value */
  1224. return IXGBE_ERR_CONFIG;
  1225. };
  1226. /* Move the flexible bytes to use the ethertype - shift 6 words */
  1227. fdirctrl |= (0x6 << IXGBE_FDIRCTRL_FLEX_SHIFT);
  1228. fdirctrl |= IXGBE_FDIRCTRL_REPORT_STATUS;
  1229. /* Prime the keys for hashing */
  1230. IXGBE_WRITE_REG(hw, IXGBE_FDIRHKEY,
  1231. htonl(IXGBE_ATR_BUCKET_HASH_KEY));
  1232. IXGBE_WRITE_REG(hw, IXGBE_FDIRSKEY,
  1233. htonl(IXGBE_ATR_SIGNATURE_HASH_KEY));
  1234. /*
  1235. * Poll init-done after we write the register. Estimated times:
  1236. * 10G: PBALLOC = 11b, timing is 60us
  1237. * 1G: PBALLOC = 11b, timing is 600us
  1238. * 100M: PBALLOC = 11b, timing is 6ms
  1239. *
  1240. * Multiple these timings by 4 if under full Rx load
  1241. *
  1242. * So we'll poll for IXGBE_FDIR_INIT_DONE_POLL times, sleeping for
  1243. * 1 msec per poll time. If we're at line rate and drop to 100M, then
  1244. * this might not finish in our poll time, but we can live with that
  1245. * for now.
  1246. */
  1247. IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl);
  1248. IXGBE_WRITE_FLUSH(hw);
  1249. for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) {
  1250. if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) &
  1251. IXGBE_FDIRCTRL_INIT_DONE)
  1252. break;
  1253. msleep(1);
  1254. }
  1255. if (i >= IXGBE_FDIR_INIT_DONE_POLL)
  1256. hw_dbg(hw, "Flow Director Signature poll time exceeded!\n");
  1257. return 0;
  1258. }
  1259. /**
  1260. * ixgbe_init_fdir_perfect_82599 - Initialize Flow Director perfect filters
  1261. * @hw: pointer to hardware structure
  1262. * @pballoc: which mode to allocate filters with
  1263. **/
  1264. s32 ixgbe_init_fdir_perfect_82599(struct ixgbe_hw *hw, u32 pballoc)
  1265. {
  1266. u32 fdirctrl = 0;
  1267. u32 pbsize;
  1268. int i;
  1269. /*
  1270. * Before enabling Flow Director, the Rx Packet Buffer size
  1271. * must be reduced. The new value is the current size minus
  1272. * flow director memory usage size.
  1273. */
  1274. pbsize = (1 << (IXGBE_FDIR_PBALLOC_SIZE_SHIFT + pballoc));
  1275. IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(0),
  1276. (IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(0)) - pbsize));
  1277. /*
  1278. * The defaults in the HW for RX PB 1-7 are not zero and so should be
  1279. * intialized to zero for non DCB mode otherwise actual total RX PB
  1280. * would be bigger than programmed and filter space would run into
  1281. * the PB 0 region.
  1282. */
  1283. for (i = 1; i < 8; i++)
  1284. IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), 0);
  1285. /* Send interrupt when 64 filters are left */
  1286. fdirctrl |= 4 << IXGBE_FDIRCTRL_FULL_THRESH_SHIFT;
  1287. /* Initialize the drop queue to Rx queue 127 */
  1288. fdirctrl |= (127 << IXGBE_FDIRCTRL_DROP_Q_SHIFT);
  1289. switch (pballoc) {
  1290. case IXGBE_FDIR_PBALLOC_64K:
  1291. /* 2k - 1 perfect filters */
  1292. fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_64K;
  1293. break;
  1294. case IXGBE_FDIR_PBALLOC_128K:
  1295. /* 4k - 1 perfect filters */
  1296. fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_128K;
  1297. break;
  1298. case IXGBE_FDIR_PBALLOC_256K:
  1299. /* 8k - 1 perfect filters */
  1300. fdirctrl |= IXGBE_FDIRCTRL_PBALLOC_256K;
  1301. break;
  1302. default:
  1303. /* bad value */
  1304. return IXGBE_ERR_CONFIG;
  1305. };
  1306. /* Turn perfect match filtering on */
  1307. fdirctrl |= IXGBE_FDIRCTRL_PERFECT_MATCH;
  1308. fdirctrl |= IXGBE_FDIRCTRL_REPORT_STATUS;
  1309. /* Move the flexible bytes to use the ethertype - shift 6 words */
  1310. fdirctrl |= (0x6 << IXGBE_FDIRCTRL_FLEX_SHIFT);
  1311. /* Prime the keys for hashing */
  1312. IXGBE_WRITE_REG(hw, IXGBE_FDIRHKEY,
  1313. htonl(IXGBE_ATR_BUCKET_HASH_KEY));
  1314. IXGBE_WRITE_REG(hw, IXGBE_FDIRSKEY,
  1315. htonl(IXGBE_ATR_SIGNATURE_HASH_KEY));
  1316. /*
  1317. * Poll init-done after we write the register. Estimated times:
  1318. * 10G: PBALLOC = 11b, timing is 60us
  1319. * 1G: PBALLOC = 11b, timing is 600us
  1320. * 100M: PBALLOC = 11b, timing is 6ms
  1321. *
  1322. * Multiple these timings by 4 if under full Rx load
  1323. *
  1324. * So we'll poll for IXGBE_FDIR_INIT_DONE_POLL times, sleeping for
  1325. * 1 msec per poll time. If we're at line rate and drop to 100M, then
  1326. * this might not finish in our poll time, but we can live with that
  1327. * for now.
  1328. */
  1329. /* Set the maximum length per hash bucket to 0xA filters */
  1330. fdirctrl |= (0xA << IXGBE_FDIRCTRL_MAX_LENGTH_SHIFT);
  1331. IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl);
  1332. IXGBE_WRITE_FLUSH(hw);
  1333. for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) {
  1334. if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) &
  1335. IXGBE_FDIRCTRL_INIT_DONE)
  1336. break;
  1337. msleep(1);
  1338. }
  1339. if (i >= IXGBE_FDIR_INIT_DONE_POLL)
  1340. hw_dbg(hw, "Flow Director Perfect poll time exceeded!\n");
  1341. return 0;
  1342. }
  1343. /**
  1344. * ixgbe_atr_compute_hash_82599 - Compute the hashes for SW ATR
  1345. * @stream: input bitstream to compute the hash on
  1346. * @key: 32-bit hash key
  1347. **/
  1348. static u16 ixgbe_atr_compute_hash_82599(struct ixgbe_atr_input *atr_input,
  1349. u32 key)
  1350. {
  1351. /*
  1352. * The algorithm is as follows:
  1353. * Hash[15:0] = Sum { S[n] x K[n+16] }, n = 0...350
  1354. * where Sum {A[n]}, n = 0...n is bitwise XOR of A[0], A[1]...A[n]
  1355. * and A[n] x B[n] is bitwise AND between same length strings
  1356. *
  1357. * K[n] is 16 bits, defined as:
  1358. * for n modulo 32 >= 15, K[n] = K[n % 32 : (n % 32) - 15]
  1359. * for n modulo 32 < 15, K[n] =
  1360. * K[(n % 32:0) | (31:31 - (14 - (n % 32)))]
  1361. *
  1362. * S[n] is 16 bits, defined as:
  1363. * for n >= 15, S[n] = S[n:n - 15]
  1364. * for n < 15, S[n] = S[(n:0) | (350:350 - (14 - n))]
  1365. *
  1366. * To simplify for programming, the algorithm is implemented
  1367. * in software this way:
  1368. *
  1369. * Key[31:0], Stream[335:0]
  1370. *
  1371. * tmp_key[11 * 32 - 1:0] = 11{Key[31:0] = key concatenated 11 times
  1372. * int_key[350:0] = tmp_key[351:1]
  1373. * int_stream[365:0] = Stream[14:0] | Stream[335:0] | Stream[335:321]
  1374. *
  1375. * hash[15:0] = 0;
  1376. * for (i = 0; i < 351; i++) {
  1377. * if (int_key[i])
  1378. * hash ^= int_stream[(i + 15):i];
  1379. * }
  1380. */
  1381. union {
  1382. u64 fill[6];
  1383. u32 key[11];
  1384. u8 key_stream[44];
  1385. } tmp_key;
  1386. u8 *stream = (u8 *)atr_input;
  1387. u8 int_key[44]; /* upper-most bit unused */
  1388. u8 hash_str[46]; /* upper-most 2 bits unused */
  1389. u16 hash_result = 0;
  1390. int i, j, k, h;
  1391. /*
  1392. * Initialize the fill member to prevent warnings
  1393. * on some compilers
  1394. */
  1395. tmp_key.fill[0] = 0;
  1396. /* First load the temporary key stream */
  1397. for (i = 0; i < 6; i++) {
  1398. u64 fillkey = ((u64)key << 32) | key;
  1399. tmp_key.fill[i] = fillkey;
  1400. }
  1401. /*
  1402. * Set the interim key for the hashing. Bit 352 is unused, so we must
  1403. * shift and compensate when building the key.
  1404. */
  1405. int_key[0] = tmp_key.key_stream[0] >> 1;
  1406. for (i = 1, j = 0; i < 44; i++) {
  1407. unsigned int this_key = tmp_key.key_stream[j] << 7;
  1408. j++;
  1409. int_key[i] = (u8)(this_key | (tmp_key.key_stream[j] >> 1));
  1410. }
  1411. /*
  1412. * Set the interim bit string for the hashing. Bits 368 and 367 are
  1413. * unused, so shift and compensate when building the string.
  1414. */
  1415. hash_str[0] = (stream[40] & 0x7f) >> 1;
  1416. for (i = 1, j = 40; i < 46; i++) {
  1417. unsigned int this_str = stream[j] << 7;
  1418. j++;
  1419. if (j > 41)
  1420. j = 0;
  1421. hash_str[i] = (u8)(this_str | (stream[j] >> 1));
  1422. }
  1423. /*
  1424. * Now compute the hash. i is the index into hash_str, j is into our
  1425. * key stream, k is counting the number of bits, and h interates within
  1426. * each byte.
  1427. */
  1428. for (i = 45, j = 43, k = 0; k < 351 && i >= 2 && j >= 0; i--, j--) {
  1429. for (h = 0; h < 8 && k < 351; h++, k++) {
  1430. if (int_key[j] & (1 << h)) {
  1431. /*
  1432. * Key bit is set, XOR in the current 16-bit
  1433. * string. Example of processing:
  1434. * h = 0,
  1435. * tmp = (hash_str[i - 2] & 0 << 16) |
  1436. * (hash_str[i - 1] & 0xff << 8) |
  1437. * (hash_str[i] & 0xff >> 0)
  1438. * So tmp = hash_str[15 + k:k], since the
  1439. * i + 2 clause rolls off the 16-bit value
  1440. * h = 7,
  1441. * tmp = (hash_str[i - 2] & 0x7f << 9) |
  1442. * (hash_str[i - 1] & 0xff << 1) |
  1443. * (hash_str[i] & 0x80 >> 7)
  1444. */
  1445. int tmp = (hash_str[i] >> h);
  1446. tmp |= (hash_str[i - 1] << (8 - h));
  1447. tmp |= (int)(hash_str[i - 2] & ((1 << h) - 1))
  1448. << (16 - h);
  1449. hash_result ^= (u16)tmp;
  1450. }
  1451. }
  1452. }
  1453. return hash_result;
  1454. }
  1455. /**
  1456. * ixgbe_atr_set_vlan_id_82599 - Sets the VLAN id in the ATR input stream
  1457. * @input: input stream to modify
  1458. * @vlan: the VLAN id to load
  1459. **/
  1460. s32 ixgbe_atr_set_vlan_id_82599(struct ixgbe_atr_input *input, u16 vlan)
  1461. {
  1462. input->byte_stream[IXGBE_ATR_VLAN_OFFSET + 1] = vlan >> 8;
  1463. input->byte_stream[IXGBE_ATR_VLAN_OFFSET] = vlan & 0xff;
  1464. return 0;
  1465. }
  1466. /**
  1467. * ixgbe_atr_set_src_ipv4_82599 - Sets the source IPv4 address
  1468. * @input: input stream to modify
  1469. * @src_addr: the IP address to load
  1470. **/
  1471. s32 ixgbe_atr_set_src_ipv4_82599(struct ixgbe_atr_input *input, u32 src_addr)
  1472. {
  1473. input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET + 3] = src_addr >> 24;
  1474. input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET + 2] =
  1475. (src_addr >> 16) & 0xff;
  1476. input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET + 1] =
  1477. (src_addr >> 8) & 0xff;
  1478. input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET] = src_addr & 0xff;
  1479. return 0;
  1480. }
  1481. /**
  1482. * ixgbe_atr_set_dst_ipv4_82599 - Sets the destination IPv4 address
  1483. * @input: input stream to modify
  1484. * @dst_addr: the IP address to load
  1485. **/
  1486. s32 ixgbe_atr_set_dst_ipv4_82599(struct ixgbe_atr_input *input, u32 dst_addr)
  1487. {
  1488. input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET + 3] = dst_addr >> 24;
  1489. input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET + 2] =
  1490. (dst_addr >> 16) & 0xff;
  1491. input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET + 1] =
  1492. (dst_addr >> 8) & 0xff;
  1493. input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET] = dst_addr & 0xff;
  1494. return 0;
  1495. }
  1496. /**
  1497. * ixgbe_atr_set_src_ipv6_82599 - Sets the source IPv6 address
  1498. * @input: input stream to modify
  1499. * @src_addr_1: the first 4 bytes of the IP address to load
  1500. * @src_addr_2: the second 4 bytes of the IP address to load
  1501. * @src_addr_3: the third 4 bytes of the IP address to load
  1502. * @src_addr_4: the fourth 4 bytes of the IP address to load
  1503. **/
  1504. s32 ixgbe_atr_set_src_ipv6_82599(struct ixgbe_atr_input *input,
  1505. u32 src_addr_1, u32 src_addr_2,
  1506. u32 src_addr_3, u32 src_addr_4)
  1507. {
  1508. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET] = src_addr_4 & 0xff;
  1509. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 1] =
  1510. (src_addr_4 >> 8) & 0xff;
  1511. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 2] =
  1512. (src_addr_4 >> 16) & 0xff;
  1513. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 3] = src_addr_4 >> 24;
  1514. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 4] = src_addr_3 & 0xff;
  1515. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 5] =
  1516. (src_addr_3 >> 8) & 0xff;
  1517. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 6] =
  1518. (src_addr_3 >> 16) & 0xff;
  1519. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 7] = src_addr_3 >> 24;
  1520. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 8] = src_addr_2 & 0xff;
  1521. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 9] =
  1522. (src_addr_2 >> 8) & 0xff;
  1523. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 10] =
  1524. (src_addr_2 >> 16) & 0xff;
  1525. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 11] = src_addr_2 >> 24;
  1526. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 12] = src_addr_1 & 0xff;
  1527. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 13] =
  1528. (src_addr_1 >> 8) & 0xff;
  1529. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 14] =
  1530. (src_addr_1 >> 16) & 0xff;
  1531. input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 15] = src_addr_1 >> 24;
  1532. return 0;
  1533. }
  1534. /**
  1535. * ixgbe_atr_set_dst_ipv6_82599 - Sets the destination IPv6 address
  1536. * @input: input stream to modify
  1537. * @dst_addr_1: the first 4 bytes of the IP address to load
  1538. * @dst_addr_2: the second 4 bytes of the IP address to load
  1539. * @dst_addr_3: the third 4 bytes of the IP address to load
  1540. * @dst_addr_4: the fourth 4 bytes of the IP address to load
  1541. **/
  1542. s32 ixgbe_atr_set_dst_ipv6_82599(struct ixgbe_atr_input *input,
  1543. u32 dst_addr_1, u32 dst_addr_2,
  1544. u32 dst_addr_3, u32 dst_addr_4)
  1545. {
  1546. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET] = dst_addr_4 & 0xff;
  1547. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 1] =
  1548. (dst_addr_4 >> 8) & 0xff;
  1549. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 2] =
  1550. (dst_addr_4 >> 16) & 0xff;
  1551. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 3] = dst_addr_4 >> 24;
  1552. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 4] = dst_addr_3 & 0xff;
  1553. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 5] =
  1554. (dst_addr_3 >> 8) & 0xff;
  1555. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 6] =
  1556. (dst_addr_3 >> 16) & 0xff;
  1557. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 7] = dst_addr_3 >> 24;
  1558. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 8] = dst_addr_2 & 0xff;
  1559. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 9] =
  1560. (dst_addr_2 >> 8) & 0xff;
  1561. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 10] =
  1562. (dst_addr_2 >> 16) & 0xff;
  1563. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 11] = dst_addr_2 >> 24;
  1564. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 12] = dst_addr_1 & 0xff;
  1565. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 13] =
  1566. (dst_addr_1 >> 8) & 0xff;
  1567. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 14] =
  1568. (dst_addr_1 >> 16) & 0xff;
  1569. input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 15] = dst_addr_1 >> 24;
  1570. return 0;
  1571. }
  1572. /**
  1573. * ixgbe_atr_set_src_port_82599 - Sets the source port
  1574. * @input: input stream to modify
  1575. * @src_port: the source port to load
  1576. **/
  1577. s32 ixgbe_atr_set_src_port_82599(struct ixgbe_atr_input *input, u16 src_port)
  1578. {
  1579. input->byte_stream[IXGBE_ATR_SRC_PORT_OFFSET + 1] = src_port >> 8;
  1580. input->byte_stream[IXGBE_ATR_SRC_PORT_OFFSET] = src_port & 0xff;
  1581. return 0;
  1582. }
  1583. /**
  1584. * ixgbe_atr_set_dst_port_82599 - Sets the destination port
  1585. * @input: input stream to modify
  1586. * @dst_port: the destination port to load
  1587. **/
  1588. s32 ixgbe_atr_set_dst_port_82599(struct ixgbe_atr_input *input, u16 dst_port)
  1589. {
  1590. input->byte_stream[IXGBE_ATR_DST_PORT_OFFSET + 1] = dst_port >> 8;
  1591. input->byte_stream[IXGBE_ATR_DST_PORT_OFFSET] = dst_port & 0xff;
  1592. return 0;
  1593. }
  1594. /**
  1595. * ixgbe_atr_set_flex_byte_82599 - Sets the flexible bytes
  1596. * @input: input stream to modify
  1597. * @flex_bytes: the flexible bytes to load
  1598. **/
  1599. s32 ixgbe_atr_set_flex_byte_82599(struct ixgbe_atr_input *input, u16 flex_byte)
  1600. {
  1601. input->byte_stream[IXGBE_ATR_FLEX_BYTE_OFFSET + 1] = flex_byte >> 8;
  1602. input->byte_stream[IXGBE_ATR_FLEX_BYTE_OFFSET] = flex_byte & 0xff;
  1603. return 0;
  1604. }
  1605. /**
  1606. * ixgbe_atr_set_vm_pool_82599 - Sets the Virtual Machine pool
  1607. * @input: input stream to modify
  1608. * @vm_pool: the Virtual Machine pool to load
  1609. **/
  1610. s32 ixgbe_atr_set_vm_pool_82599(struct ixgbe_atr_input *input,
  1611. u8 vm_pool)
  1612. {
  1613. input->byte_stream[IXGBE_ATR_VM_POOL_OFFSET] = vm_pool;
  1614. return 0;
  1615. }
  1616. /**
  1617. * ixgbe_atr_set_l4type_82599 - Sets the layer 4 packet type
  1618. * @input: input stream to modify
  1619. * @l4type: the layer 4 type value to load
  1620. **/
  1621. s32 ixgbe_atr_set_l4type_82599(struct ixgbe_atr_input *input, u8 l4type)
  1622. {
  1623. input->byte_stream[IXGBE_ATR_L4TYPE_OFFSET] = l4type;
  1624. return 0;
  1625. }
  1626. /**
  1627. * ixgbe_atr_get_vlan_id_82599 - Gets the VLAN id from the ATR input stream
  1628. * @input: input stream to search
  1629. * @vlan: the VLAN id to load
  1630. **/
  1631. static s32 ixgbe_atr_get_vlan_id_82599(struct ixgbe_atr_input *input, u16 *vlan)
  1632. {
  1633. *vlan = input->byte_stream[IXGBE_ATR_VLAN_OFFSET];
  1634. *vlan |= input->byte_stream[IXGBE_ATR_VLAN_OFFSET + 1] << 8;
  1635. return 0;
  1636. }
  1637. /**
  1638. * ixgbe_atr_get_src_ipv4_82599 - Gets the source IPv4 address
  1639. * @input: input stream to search
  1640. * @src_addr: the IP address to load
  1641. **/
  1642. static s32 ixgbe_atr_get_src_ipv4_82599(struct ixgbe_atr_input *input,
  1643. u32 *src_addr)
  1644. {
  1645. *src_addr = input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET];
  1646. *src_addr |= input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET + 1] << 8;
  1647. *src_addr |= input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET + 2] << 16;
  1648. *src_addr |= input->byte_stream[IXGBE_ATR_SRC_IPV4_OFFSET + 3] << 24;
  1649. return 0;
  1650. }
  1651. /**
  1652. * ixgbe_atr_get_dst_ipv4_82599 - Gets the destination IPv4 address
  1653. * @input: input stream to search
  1654. * @dst_addr: the IP address to load
  1655. **/
  1656. static s32 ixgbe_atr_get_dst_ipv4_82599(struct ixgbe_atr_input *input,
  1657. u32 *dst_addr)
  1658. {
  1659. *dst_addr = input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET];
  1660. *dst_addr |= input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET + 1] << 8;
  1661. *dst_addr |= input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET + 2] << 16;
  1662. *dst_addr |= input->byte_stream[IXGBE_ATR_DST_IPV4_OFFSET + 3] << 24;
  1663. return 0;
  1664. }
  1665. /**
  1666. * ixgbe_atr_get_src_ipv6_82599 - Gets the source IPv6 address
  1667. * @input: input stream to search
  1668. * @src_addr_1: the first 4 bytes of the IP address to load
  1669. * @src_addr_2: the second 4 bytes of the IP address to load
  1670. * @src_addr_3: the third 4 bytes of the IP address to load
  1671. * @src_addr_4: the fourth 4 bytes of the IP address to load
  1672. **/
  1673. static s32 ixgbe_atr_get_src_ipv6_82599(struct ixgbe_atr_input *input,
  1674. u32 *src_addr_1, u32 *src_addr_2,
  1675. u32 *src_addr_3, u32 *src_addr_4)
  1676. {
  1677. *src_addr_1 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 12];
  1678. *src_addr_1 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 13] << 8;
  1679. *src_addr_1 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 14] << 16;
  1680. *src_addr_1 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 15] << 24;
  1681. *src_addr_2 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 8];
  1682. *src_addr_2 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 9] << 8;
  1683. *src_addr_2 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 10] << 16;
  1684. *src_addr_2 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 11] << 24;
  1685. *src_addr_3 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 4];
  1686. *src_addr_3 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 5] << 8;
  1687. *src_addr_3 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 6] << 16;
  1688. *src_addr_3 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 7] << 24;
  1689. *src_addr_4 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET];
  1690. *src_addr_4 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 1] << 8;
  1691. *src_addr_4 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 2] << 16;
  1692. *src_addr_4 = input->byte_stream[IXGBE_ATR_SRC_IPV6_OFFSET + 3] << 24;
  1693. return 0;
  1694. }
  1695. /**
  1696. * ixgbe_atr_get_dst_ipv6_82599 - Gets the destination IPv6 address
  1697. * @input: input stream to search
  1698. * @dst_addr_1: the first 4 bytes of the IP address to load
  1699. * @dst_addr_2: the second 4 bytes of the IP address to load
  1700. * @dst_addr_3: the third 4 bytes of the IP address to load
  1701. * @dst_addr_4: the fourth 4 bytes of the IP address to load
  1702. **/
  1703. s32 ixgbe_atr_get_dst_ipv6_82599(struct ixgbe_atr_input *input,
  1704. u32 *dst_addr_1, u32 *dst_addr_2,
  1705. u32 *dst_addr_3, u32 *dst_addr_4)
  1706. {
  1707. *dst_addr_1 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 12];
  1708. *dst_addr_1 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 13] << 8;
  1709. *dst_addr_1 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 14] << 16;
  1710. *dst_addr_1 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 15] << 24;
  1711. *dst_addr_2 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 8];
  1712. *dst_addr_2 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 9] << 8;
  1713. *dst_addr_2 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 10] << 16;
  1714. *dst_addr_2 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 11] << 24;
  1715. *dst_addr_3 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 4];
  1716. *dst_addr_3 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 5] << 8;
  1717. *dst_addr_3 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 6] << 16;
  1718. *dst_addr_3 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 7] << 24;
  1719. *dst_addr_4 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET];
  1720. *dst_addr_4 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 1] << 8;
  1721. *dst_addr_4 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 2] << 16;
  1722. *dst_addr_4 = input->byte_stream[IXGBE_ATR_DST_IPV6_OFFSET + 3] << 24;
  1723. return 0;
  1724. }
  1725. /**
  1726. * ixgbe_atr_get_src_port_82599 - Gets the source port
  1727. * @input: input stream to modify
  1728. * @src_port: the source port to load
  1729. *
  1730. * Even though the input is given in big-endian, the FDIRPORT registers
  1731. * expect the ports to be programmed in little-endian. Hence the need to swap
  1732. * endianness when retrieving the data. This can be confusing since the
  1733. * internal hash engine expects it to be big-endian.
  1734. **/
  1735. static s32 ixgbe_atr_get_src_port_82599(struct ixgbe_atr_input *input,
  1736. u16 *src_port)
  1737. {
  1738. *src_port = input->byte_stream[IXGBE_ATR_SRC_PORT_OFFSET] << 8;
  1739. *src_port |= input->byte_stream[IXGBE_ATR_SRC_PORT_OFFSET + 1];
  1740. return 0;
  1741. }
  1742. /**
  1743. * ixgbe_atr_get_dst_port_82599 - Gets the destination port
  1744. * @input: input stream to modify
  1745. * @dst_port: the destination port to load
  1746. *
  1747. * Even though the input is given in big-endian, the FDIRPORT registers
  1748. * expect the ports to be programmed in little-endian. Hence the need to swap
  1749. * endianness when retrieving the data. This can be confusing since the
  1750. * internal hash engine expects it to be big-endian.
  1751. **/
  1752. static s32 ixgbe_atr_get_dst_port_82599(struct ixgbe_atr_input *input,
  1753. u16 *dst_port)
  1754. {
  1755. *dst_port = input->byte_stream[IXGBE_ATR_DST_PORT_OFFSET] << 8;
  1756. *dst_port |= input->byte_stream[IXGBE_ATR_DST_PORT_OFFSET + 1];
  1757. return 0;
  1758. }
  1759. /**
  1760. * ixgbe_atr_get_flex_byte_82599 - Gets the flexible bytes
  1761. * @input: input stream to modify
  1762. * @flex_bytes: the flexible bytes to load
  1763. **/
  1764. static s32 ixgbe_atr_get_flex_byte_82599(struct ixgbe_atr_input *input,
  1765. u16 *flex_byte)
  1766. {
  1767. *flex_byte = input->byte_stream[IXGBE_ATR_FLEX_BYTE_OFFSET];
  1768. *flex_byte |= input->byte_stream[IXGBE_ATR_FLEX_BYTE_OFFSET + 1] << 8;
  1769. return 0;
  1770. }
  1771. /**
  1772. * ixgbe_atr_get_vm_pool_82599 - Gets the Virtual Machine pool
  1773. * @input: input stream to modify
  1774. * @vm_pool: the Virtual Machine pool to load
  1775. **/
  1776. s32 ixgbe_atr_get_vm_pool_82599(struct ixgbe_atr_input *input,
  1777. u8 *vm_pool)
  1778. {
  1779. *vm_pool = input->byte_stream[IXGBE_ATR_VM_POOL_OFFSET];
  1780. return 0;
  1781. }
  1782. /**
  1783. * ixgbe_atr_get_l4type_82599 - Gets the layer 4 packet type
  1784. * @input: input stream to modify
  1785. * @l4type: the layer 4 type value to load
  1786. **/
  1787. static s32 ixgbe_atr_get_l4type_82599(struct ixgbe_atr_input *input,
  1788. u8 *l4type)
  1789. {
  1790. *l4type = input->byte_stream[IXGBE_ATR_L4TYPE_OFFSET];
  1791. return 0;
  1792. }
  1793. /**
  1794. * ixgbe_atr_add_signature_filter_82599 - Adds a signature hash filter
  1795. * @hw: pointer to hardware structure
  1796. * @stream: input bitstream
  1797. * @queue: queue index to direct traffic to
  1798. **/
  1799. s32 ixgbe_fdir_add_signature_filter_82599(struct ixgbe_hw *hw,
  1800. struct ixgbe_atr_input *input,
  1801. u8 queue)
  1802. {
  1803. u64 fdirhashcmd;
  1804. u64 fdircmd;
  1805. u32 fdirhash;
  1806. u16 bucket_hash, sig_hash;
  1807. u8 l4type;
  1808. bucket_hash = ixgbe_atr_compute_hash_82599(input,
  1809. IXGBE_ATR_BUCKET_HASH_KEY);
  1810. /* bucket_hash is only 15 bits */
  1811. bucket_hash &= IXGBE_ATR_HASH_MASK;
  1812. sig_hash = ixgbe_atr_compute_hash_82599(input,
  1813. IXGBE_ATR_SIGNATURE_HASH_KEY);
  1814. /* Get the l4type in order to program FDIRCMD properly */
  1815. /* lowest 2 bits are FDIRCMD.L4TYPE, third lowest bit is FDIRCMD.IPV6 */
  1816. ixgbe_atr_get_l4type_82599(input, &l4type);
  1817. /*
  1818. * The lower 32-bits of fdirhashcmd is for FDIRHASH, the upper 32-bits
  1819. * is for FDIRCMD. Then do a 64-bit register write from FDIRHASH.
  1820. */
  1821. fdirhash = sig_hash << IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT | bucket_hash;
  1822. fdircmd = (IXGBE_FDIRCMD_CMD_ADD_FLOW | IXGBE_FDIRCMD_FILTER_UPDATE |
  1823. IXGBE_FDIRCMD_LAST | IXGBE_FDIRCMD_QUEUE_EN);
  1824. switch (l4type & IXGBE_ATR_L4TYPE_MASK) {
  1825. case IXGBE_ATR_L4TYPE_TCP:
  1826. fdircmd |= IXGBE_FDIRCMD_L4TYPE_TCP;
  1827. break;
  1828. case IXGBE_ATR_L4TYPE_UDP:
  1829. fdircmd |= IXGBE_FDIRCMD_L4TYPE_UDP;
  1830. break;
  1831. case IXGBE_ATR_L4TYPE_SCTP:
  1832. fdircmd |= IXGBE_FDIRCMD_L4TYPE_SCTP;
  1833. break;
  1834. default:
  1835. hw_dbg(hw, "Error on l4type input\n");
  1836. return IXGBE_ERR_CONFIG;
  1837. }
  1838. if (l4type & IXGBE_ATR_L4TYPE_IPV6_MASK)
  1839. fdircmd |= IXGBE_FDIRCMD_IPV6;
  1840. fdircmd |= ((u64)queue << IXGBE_FDIRCMD_RX_QUEUE_SHIFT);
  1841. fdirhashcmd = ((fdircmd << 32) | fdirhash);
  1842. IXGBE_WRITE_REG64(hw, IXGBE_FDIRHASH, fdirhashcmd);
  1843. return 0;
  1844. }
  1845. /**
  1846. * ixgbe_fdir_add_perfect_filter_82599 - Adds a perfect filter
  1847. * @hw: pointer to hardware structure
  1848. * @input: input bitstream
  1849. * @input_masks: bitwise masks for relevant fields
  1850. * @soft_id: software index into the silicon hash tables for filter storage
  1851. * @queue: queue index to direct traffic to
  1852. *
  1853. * Note that the caller to this function must lock before calling, since the
  1854. * hardware writes must be protected from one another.
  1855. **/
  1856. s32 ixgbe_fdir_add_perfect_filter_82599(struct ixgbe_hw *hw,
  1857. struct ixgbe_atr_input *input,
  1858. struct ixgbe_atr_input_masks *input_masks,
  1859. u16 soft_id, u8 queue)
  1860. {
  1861. u32 fdircmd = 0;
  1862. u32 fdirhash;
  1863. u32 src_ipv4 = 0, dst_ipv4 = 0;
  1864. u32 src_ipv6_1, src_ipv6_2, src_ipv6_3, src_ipv6_4;
  1865. u16 src_port, dst_port, vlan_id, flex_bytes;
  1866. u16 bucket_hash;
  1867. u8 l4type;
  1868. u8 fdirm = 0;
  1869. /* Get our input values */
  1870. ixgbe_atr_get_l4type_82599(input, &l4type);
  1871. /*
  1872. * Check l4type formatting, and bail out before we touch the hardware
  1873. * if there's a configuration issue
  1874. */
  1875. switch (l4type & IXGBE_ATR_L4TYPE_MASK) {
  1876. case IXGBE_ATR_L4TYPE_TCP:
  1877. fdircmd |= IXGBE_FDIRCMD_L4TYPE_TCP;
  1878. break;
  1879. case IXGBE_ATR_L4TYPE_UDP:
  1880. fdircmd |= IXGBE_FDIRCMD_L4TYPE_UDP;
  1881. break;
  1882. case IXGBE_ATR_L4TYPE_SCTP:
  1883. fdircmd |= IXGBE_FDIRCMD_L4TYPE_SCTP;
  1884. break;
  1885. default:
  1886. hw_dbg(hw, "Error on l4type input\n");
  1887. return IXGBE_ERR_CONFIG;
  1888. }
  1889. bucket_hash = ixgbe_atr_compute_hash_82599(input,
  1890. IXGBE_ATR_BUCKET_HASH_KEY);
  1891. /* bucket_hash is only 15 bits */
  1892. bucket_hash &= IXGBE_ATR_HASH_MASK;
  1893. ixgbe_atr_get_vlan_id_82599(input, &vlan_id);
  1894. ixgbe_atr_get_src_port_82599(input, &src_port);
  1895. ixgbe_atr_get_dst_port_82599(input, &dst_port);
  1896. ixgbe_atr_get_flex_byte_82599(input, &flex_bytes);
  1897. fdirhash = soft_id << IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT | bucket_hash;
  1898. /* Now figure out if we're IPv4 or IPv6 */
  1899. if (l4type & IXGBE_ATR_L4TYPE_IPV6_MASK) {
  1900. /* IPv6 */
  1901. ixgbe_atr_get_src_ipv6_82599(input, &src_ipv6_1, &src_ipv6_2,
  1902. &src_ipv6_3, &src_ipv6_4);
  1903. IXGBE_WRITE_REG(hw, IXGBE_FDIRSIPv6(0), src_ipv6_1);
  1904. IXGBE_WRITE_REG(hw, IXGBE_FDIRSIPv6(1), src_ipv6_2);
  1905. IXGBE_WRITE_REG(hw, IXGBE_FDIRSIPv6(2), src_ipv6_3);
  1906. /* The last 4 bytes is the same register as IPv4 */
  1907. IXGBE_WRITE_REG(hw, IXGBE_FDIRIPSA, src_ipv6_4);
  1908. fdircmd |= IXGBE_FDIRCMD_IPV6;
  1909. fdircmd |= IXGBE_FDIRCMD_IPv6DMATCH;
  1910. } else {
  1911. /* IPv4 */
  1912. ixgbe_atr_get_src_ipv4_82599(input, &src_ipv4);
  1913. IXGBE_WRITE_REG(hw, IXGBE_FDIRIPSA, src_ipv4);
  1914. }
  1915. ixgbe_atr_get_dst_ipv4_82599(input, &dst_ipv4);
  1916. IXGBE_WRITE_REG(hw, IXGBE_FDIRIPDA, dst_ipv4);
  1917. IXGBE_WRITE_REG(hw, IXGBE_FDIRVLAN, (vlan_id |
  1918. (flex_bytes << IXGBE_FDIRVLAN_FLEX_SHIFT)));
  1919. IXGBE_WRITE_REG(hw, IXGBE_FDIRPORT, (src_port |
  1920. (dst_port << IXGBE_FDIRPORT_DESTINATION_SHIFT)));
  1921. /*
  1922. * Program the relevant mask registers. If src/dst_port or src/dst_addr
  1923. * are zero, then assume a full mask for that field. Also assume that
  1924. * a VLAN of 0 is unspecified, so mask that out as well. L4type
  1925. * cannot be masked out in this implementation.
  1926. *
  1927. * This also assumes IPv4 only. IPv6 masking isn't supported at this
  1928. * point in time.
  1929. */
  1930. if (src_ipv4 == 0)
  1931. IXGBE_WRITE_REG(hw, IXGBE_FDIRSIP4M, 0xffffffff);
  1932. else
  1933. IXGBE_WRITE_REG(hw, IXGBE_FDIRSIP4M, input_masks->src_ip_mask);
  1934. if (dst_ipv4 == 0)
  1935. IXGBE_WRITE_REG(hw, IXGBE_FDIRDIP4M, 0xffffffff);
  1936. else
  1937. IXGBE_WRITE_REG(hw, IXGBE_FDIRDIP4M, input_masks->dst_ip_mask);
  1938. switch (l4type & IXGBE_ATR_L4TYPE_MASK) {
  1939. case IXGBE_ATR_L4TYPE_TCP:
  1940. if (src_port == 0)
  1941. IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM, 0xffff);
  1942. else
  1943. IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM,
  1944. input_masks->src_port_mask);
  1945. if (dst_port == 0)
  1946. IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM,
  1947. (IXGBE_READ_REG(hw, IXGBE_FDIRTCPM) |
  1948. (0xffff << 16)));
  1949. else
  1950. IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM,
  1951. (IXGBE_READ_REG(hw, IXGBE_FDIRTCPM) |
  1952. (input_masks->dst_port_mask << 16)));
  1953. break;
  1954. case IXGBE_ATR_L4TYPE_UDP:
  1955. if (src_port == 0)
  1956. IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM, 0xffff);
  1957. else
  1958. IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM,
  1959. input_masks->src_port_mask);
  1960. if (dst_port == 0)
  1961. IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM,
  1962. (IXGBE_READ_REG(hw, IXGBE_FDIRUDPM) |
  1963. (0xffff << 16)));
  1964. else
  1965. IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM,
  1966. (IXGBE_READ_REG(hw, IXGBE_FDIRUDPM) |
  1967. (input_masks->src_port_mask << 16)));
  1968. break;
  1969. default:
  1970. /* this already would have failed above */
  1971. break;
  1972. }
  1973. /* Program the last mask register, FDIRM */
  1974. if (input_masks->vlan_id_mask || !vlan_id)
  1975. /* Mask both VLAN and VLANP - bits 0 and 1 */
  1976. fdirm |= 0x3;
  1977. if (input_masks->data_mask || !flex_bytes)
  1978. /* Flex bytes need masking, so mask the whole thing - bit 4 */
  1979. fdirm |= 0x10;
  1980. /* Now mask VM pool and destination IPv6 - bits 5 and 2 */
  1981. fdirm |= 0x24;
  1982. IXGBE_WRITE_REG(hw, IXGBE_FDIRM, fdirm);
  1983. fdircmd |= IXGBE_FDIRCMD_CMD_ADD_FLOW;
  1984. fdircmd |= IXGBE_FDIRCMD_FILTER_UPDATE;
  1985. fdircmd |= IXGBE_FDIRCMD_LAST;
  1986. fdircmd |= IXGBE_FDIRCMD_QUEUE_EN;
  1987. fdircmd |= queue << IXGBE_FDIRCMD_RX_QUEUE_SHIFT;
  1988. IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash);
  1989. IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, fdircmd);
  1990. return 0;
  1991. }
  1992. /**
  1993. * ixgbe_read_analog_reg8_82599 - Reads 8 bit Omer analog register
  1994. * @hw: pointer to hardware structure
  1995. * @reg: analog register to read
  1996. * @val: read value
  1997. *
  1998. * Performs read operation to Omer analog register specified.
  1999. **/
  2000. static s32 ixgbe_read_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 *val)
  2001. {
  2002. u32 core_ctl;
  2003. IXGBE_WRITE_REG(hw, IXGBE_CORECTL, IXGBE_CORECTL_WRITE_CMD |
  2004. (reg << 8));
  2005. IXGBE_WRITE_FLUSH(hw);
  2006. udelay(10);
  2007. core_ctl = IXGBE_READ_REG(hw, IXGBE_CORECTL);
  2008. *val = (u8)core_ctl;
  2009. return 0;
  2010. }
  2011. /**
  2012. * ixgbe_write_analog_reg8_82599 - Writes 8 bit Omer analog register
  2013. * @hw: pointer to hardware structure
  2014. * @reg: atlas register to write
  2015. * @val: value to write
  2016. *
  2017. * Performs write operation to Omer analog register specified.
  2018. **/
  2019. static s32 ixgbe_write_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 val)
  2020. {
  2021. u32 core_ctl;
  2022. core_ctl = (reg << 8) | val;
  2023. IXGBE_WRITE_REG(hw, IXGBE_CORECTL, core_ctl);
  2024. IXGBE_WRITE_FLUSH(hw);
  2025. udelay(10);
  2026. return 0;
  2027. }
  2028. /**
  2029. * ixgbe_start_hw_82599 - Prepare hardware for Tx/Rx
  2030. * @hw: pointer to hardware structure
  2031. *
  2032. * Starts the hardware using the generic start_hw function.
  2033. * Then performs device-specific:
  2034. * Clears the rate limiter registers.
  2035. **/
  2036. static s32 ixgbe_start_hw_82599(struct ixgbe_hw *hw)
  2037. {
  2038. u32 q_num;
  2039. s32 ret_val;
  2040. ret_val = ixgbe_start_hw_generic(hw);
  2041. /* Clear the rate limiters */
  2042. for (q_num = 0; q_num < hw->mac.max_tx_queues; q_num++) {
  2043. IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, q_num);
  2044. IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, 0);
  2045. }
  2046. IXGBE_WRITE_FLUSH(hw);
  2047. /* We need to run link autotry after the driver loads */
  2048. hw->mac.autotry_restart = true;
  2049. if (ret_val == 0)
  2050. ret_val = ixgbe_verify_fw_version_82599(hw);
  2051. return ret_val;
  2052. }
  2053. /**
  2054. * ixgbe_identify_phy_82599 - Get physical layer module
  2055. * @hw: pointer to hardware structure
  2056. *
  2057. * Determines the physical layer module found on the current adapter.
  2058. **/
  2059. static s32 ixgbe_identify_phy_82599(struct ixgbe_hw *hw)
  2060. {
  2061. s32 status = IXGBE_ERR_PHY_ADDR_INVALID;
  2062. status = ixgbe_identify_phy_generic(hw);
  2063. if (status != 0)
  2064. status = ixgbe_identify_sfp_module_generic(hw);
  2065. return status;
  2066. }
  2067. /**
  2068. * ixgbe_get_supported_physical_layer_82599 - Returns physical layer type
  2069. * @hw: pointer to hardware structure
  2070. *
  2071. * Determines physical layer capabilities of the current configuration.
  2072. **/
  2073. static u32 ixgbe_get_supported_physical_layer_82599(struct ixgbe_hw *hw)
  2074. {
  2075. u32 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
  2076. u32 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
  2077. u32 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
  2078. u32 pma_pmd_10g_serial = autoc2 & IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_MASK;
  2079. u32 pma_pmd_10g_parallel = autoc & IXGBE_AUTOC_10G_PMA_PMD_MASK;
  2080. u32 pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK;
  2081. u16 ext_ability = 0;
  2082. u8 comp_codes_10g = 0;
  2083. hw->phy.ops.identify(hw);
  2084. if (hw->phy.type == ixgbe_phy_tn ||
  2085. hw->phy.type == ixgbe_phy_cu_unknown) {
  2086. hw->phy.ops.read_reg(hw, MDIO_PMA_EXTABLE, MDIO_MMD_PMAPMD,
  2087. &ext_ability);
  2088. if (ext_ability & MDIO_PMA_EXTABLE_10GBT)
  2089. physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_T;
  2090. if (ext_ability & MDIO_PMA_EXTABLE_1000BT)
  2091. physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_T;
  2092. if (ext_ability & MDIO_PMA_EXTABLE_100BTX)
  2093. physical_layer |= IXGBE_PHYSICAL_LAYER_100BASE_TX;
  2094. goto out;
  2095. }
  2096. switch (autoc & IXGBE_AUTOC_LMS_MASK) {
  2097. case IXGBE_AUTOC_LMS_1G_AN:
  2098. case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
  2099. if (pma_pmd_1g == IXGBE_AUTOC_1G_KX_BX) {
  2100. physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_KX |
  2101. IXGBE_PHYSICAL_LAYER_1000BASE_BX;
  2102. goto out;
  2103. } else
  2104. /* SFI mode so read SFP module */
  2105. goto sfp_check;
  2106. break;
  2107. case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
  2108. if (pma_pmd_10g_parallel == IXGBE_AUTOC_10G_CX4)
  2109. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_CX4;
  2110. else if (pma_pmd_10g_parallel == IXGBE_AUTOC_10G_KX4)
  2111. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_KX4;
  2112. else if (pma_pmd_10g_parallel == IXGBE_AUTOC_10G_XAUI)
  2113. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_XAUI;
  2114. goto out;
  2115. break;
  2116. case IXGBE_AUTOC_LMS_10G_SERIAL:
  2117. if (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_KR) {
  2118. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_KR;
  2119. goto out;
  2120. } else if (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI)
  2121. goto sfp_check;
  2122. break;
  2123. case IXGBE_AUTOC_LMS_KX4_KX_KR:
  2124. case IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN:
  2125. if (autoc & IXGBE_AUTOC_KX_SUPP)
  2126. physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_KX;
  2127. if (autoc & IXGBE_AUTOC_KX4_SUPP)
  2128. physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_KX4;
  2129. if (autoc & IXGBE_AUTOC_KR_SUPP)
  2130. physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_KR;
  2131. goto out;
  2132. break;
  2133. default:
  2134. goto out;
  2135. break;
  2136. }
  2137. sfp_check:
  2138. /* SFP check must be done last since DA modules are sometimes used to
  2139. * test KR mode - we need to id KR mode correctly before SFP module.
  2140. * Call identify_sfp because the pluggable module may have changed */
  2141. hw->phy.ops.identify_sfp(hw);
  2142. if (hw->phy.sfp_type == ixgbe_sfp_type_not_present)
  2143. goto out;
  2144. switch (hw->phy.type) {
  2145. case ixgbe_phy_tw_tyco:
  2146. case ixgbe_phy_tw_unknown:
  2147. physical_layer = IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU;
  2148. break;
  2149. case ixgbe_phy_sfp_avago:
  2150. case ixgbe_phy_sfp_ftl:
  2151. case ixgbe_phy_sfp_intel:
  2152. case ixgbe_phy_sfp_unknown:
  2153. hw->phy.ops.read_i2c_eeprom(hw,
  2154. IXGBE_SFF_10GBE_COMP_CODES, &comp_codes_10g);
  2155. if (comp_codes_10g & IXGBE_SFF_10GBASESR_CAPABLE)
  2156. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_SR;
  2157. else if (comp_codes_10g & IXGBE_SFF_10GBASELR_CAPABLE)
  2158. physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_LR;
  2159. break;
  2160. default:
  2161. break;
  2162. }
  2163. out:
  2164. return physical_layer;
  2165. }
  2166. /**
  2167. * ixgbe_enable_rx_dma_82599 - Enable the Rx DMA unit on 82599
  2168. * @hw: pointer to hardware structure
  2169. * @regval: register value to write to RXCTRL
  2170. *
  2171. * Enables the Rx DMA unit for 82599
  2172. **/
  2173. static s32 ixgbe_enable_rx_dma_82599(struct ixgbe_hw *hw, u32 regval)
  2174. {
  2175. #define IXGBE_MAX_SECRX_POLL 30
  2176. int i;
  2177. int secrxreg;
  2178. /*
  2179. * Workaround for 82599 silicon errata when enabling the Rx datapath.
  2180. * If traffic is incoming before we enable the Rx unit, it could hang
  2181. * the Rx DMA unit. Therefore, make sure the security engine is
  2182. * completely disabled prior to enabling the Rx unit.
  2183. */
  2184. secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
  2185. secrxreg |= IXGBE_SECRXCTRL_RX_DIS;
  2186. IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
  2187. for (i = 0; i < IXGBE_MAX_SECRX_POLL; i++) {
  2188. secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXSTAT);
  2189. if (secrxreg & IXGBE_SECRXSTAT_SECRX_RDY)
  2190. break;
  2191. else
  2192. udelay(10);
  2193. }
  2194. /* For informational purposes only */
  2195. if (i >= IXGBE_MAX_SECRX_POLL)
  2196. hw_dbg(hw, "Rx unit being enabled before security "
  2197. "path fully disabled. Continuing with init.\n");
  2198. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval);
  2199. secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
  2200. secrxreg &= ~IXGBE_SECRXCTRL_RX_DIS;
  2201. IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
  2202. IXGBE_WRITE_FLUSH(hw);
  2203. return 0;
  2204. }
  2205. /**
  2206. * ixgbe_get_device_caps_82599 - Get additional device capabilities
  2207. * @hw: pointer to hardware structure
  2208. * @device_caps: the EEPROM word with the extra device capabilities
  2209. *
  2210. * This function will read the EEPROM location for the device capabilities,
  2211. * and return the word through device_caps.
  2212. **/
  2213. static s32 ixgbe_get_device_caps_82599(struct ixgbe_hw *hw, u16 *device_caps)
  2214. {
  2215. hw->eeprom.ops.read(hw, IXGBE_DEVICE_CAPS, device_caps);
  2216. return 0;
  2217. }
  2218. /**
  2219. * ixgbe_get_san_mac_addr_offset_82599 - SAN MAC address offset for 82599
  2220. * @hw: pointer to hardware structure
  2221. * @san_mac_offset: SAN MAC address offset
  2222. *
  2223. * This function will read the EEPROM location for the SAN MAC address
  2224. * pointer, and returns the value at that location. This is used in both
  2225. * get and set mac_addr routines.
  2226. **/
  2227. static s32 ixgbe_get_san_mac_addr_offset_82599(struct ixgbe_hw *hw,
  2228. u16 *san_mac_offset)
  2229. {
  2230. /*
  2231. * First read the EEPROM pointer to see if the MAC addresses are
  2232. * available.
  2233. */
  2234. hw->eeprom.ops.read(hw, IXGBE_SAN_MAC_ADDR_PTR, san_mac_offset);
  2235. return 0;
  2236. }
  2237. /**
  2238. * ixgbe_get_san_mac_addr_82599 - SAN MAC address retrieval for 82599
  2239. * @hw: pointer to hardware structure
  2240. * @san_mac_addr: SAN MAC address
  2241. *
  2242. * Reads the SAN MAC address from the EEPROM, if it's available. This is
  2243. * per-port, so set_lan_id() must be called before reading the addresses.
  2244. * set_lan_id() is called by identify_sfp(), but this cannot be relied
  2245. * upon for non-SFP connections, so we must call it here.
  2246. **/
  2247. static s32 ixgbe_get_san_mac_addr_82599(struct ixgbe_hw *hw, u8 *san_mac_addr)
  2248. {
  2249. u16 san_mac_data, san_mac_offset;
  2250. u8 i;
  2251. /*
  2252. * First read the EEPROM pointer to see if the MAC addresses are
  2253. * available. If they're not, no point in calling set_lan_id() here.
  2254. */
  2255. ixgbe_get_san_mac_addr_offset_82599(hw, &san_mac_offset);
  2256. if ((san_mac_offset == 0) || (san_mac_offset == 0xFFFF)) {
  2257. /*
  2258. * No addresses available in this EEPROM. It's not an
  2259. * error though, so just wipe the local address and return.
  2260. */
  2261. for (i = 0; i < 6; i++)
  2262. san_mac_addr[i] = 0xFF;
  2263. goto san_mac_addr_out;
  2264. }
  2265. /* make sure we know which port we need to program */
  2266. hw->mac.ops.set_lan_id(hw);
  2267. /* apply the port offset to the address offset */
  2268. (hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
  2269. (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
  2270. for (i = 0; i < 3; i++) {
  2271. hw->eeprom.ops.read(hw, san_mac_offset, &san_mac_data);
  2272. san_mac_addr[i * 2] = (u8)(san_mac_data);
  2273. san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8);
  2274. san_mac_offset++;
  2275. }
  2276. san_mac_addr_out:
  2277. return 0;
  2278. }
  2279. /**
  2280. * ixgbe_verify_fw_version_82599 - verify fw version for 82599
  2281. * @hw: pointer to hardware structure
  2282. *
  2283. * Verifies that installed the firmware version is 0.6 or higher
  2284. * for SFI devices. All 82599 SFI devices should have version 0.6 or higher.
  2285. *
  2286. * Returns IXGBE_ERR_EEPROM_VERSION if the FW is not present or
  2287. * if the FW version is not supported.
  2288. **/
  2289. static s32 ixgbe_verify_fw_version_82599(struct ixgbe_hw *hw)
  2290. {
  2291. s32 status = IXGBE_ERR_EEPROM_VERSION;
  2292. u16 fw_offset, fw_ptp_cfg_offset;
  2293. u16 fw_version = 0;
  2294. /* firmware check is only necessary for SFI devices */
  2295. if (hw->phy.media_type != ixgbe_media_type_fiber) {
  2296. status = 0;
  2297. goto fw_version_out;
  2298. }
  2299. /* get the offset to the Firmware Module block */
  2300. hw->eeprom.ops.read(hw, IXGBE_FW_PTR, &fw_offset);
  2301. if ((fw_offset == 0) || (fw_offset == 0xFFFF))
  2302. goto fw_version_out;
  2303. /* get the offset to the Pass Through Patch Configuration block */
  2304. hw->eeprom.ops.read(hw, (fw_offset +
  2305. IXGBE_FW_PASSTHROUGH_PATCH_CONFIG_PTR),
  2306. &fw_ptp_cfg_offset);
  2307. if ((fw_ptp_cfg_offset == 0) || (fw_ptp_cfg_offset == 0xFFFF))
  2308. goto fw_version_out;
  2309. /* get the firmware version */
  2310. hw->eeprom.ops.read(hw, (fw_ptp_cfg_offset +
  2311. IXGBE_FW_PATCH_VERSION_4),
  2312. &fw_version);
  2313. if (fw_version > 0x5)
  2314. status = 0;
  2315. fw_version_out:
  2316. return status;
  2317. }
  2318. /**
  2319. * ixgbe_get_wwn_prefix_82599 - Get alternative WWNN/WWPN prefix from
  2320. * the EEPROM
  2321. * @hw: pointer to hardware structure
  2322. * @wwnn_prefix: the alternative WWNN prefix
  2323. * @wwpn_prefix: the alternative WWPN prefix
  2324. *
  2325. * This function will read the EEPROM from the alternative SAN MAC address
  2326. * block to check the support for the alternative WWNN/WWPN prefix support.
  2327. **/
  2328. static s32 ixgbe_get_wwn_prefix_82599(struct ixgbe_hw *hw, u16 *wwnn_prefix,
  2329. u16 *wwpn_prefix)
  2330. {
  2331. u16 offset, caps;
  2332. u16 alt_san_mac_blk_offset;
  2333. /* clear output first */
  2334. *wwnn_prefix = 0xFFFF;
  2335. *wwpn_prefix = 0xFFFF;
  2336. /* check if alternative SAN MAC is supported */
  2337. hw->eeprom.ops.read(hw, IXGBE_ALT_SAN_MAC_ADDR_BLK_PTR,
  2338. &alt_san_mac_blk_offset);
  2339. if ((alt_san_mac_blk_offset == 0) ||
  2340. (alt_san_mac_blk_offset == 0xFFFF))
  2341. goto wwn_prefix_out;
  2342. /* check capability in alternative san mac address block */
  2343. offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET;
  2344. hw->eeprom.ops.read(hw, offset, &caps);
  2345. if (!(caps & IXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN))
  2346. goto wwn_prefix_out;
  2347. /* get the corresponding prefix for WWNN/WWPN */
  2348. offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET;
  2349. hw->eeprom.ops.read(hw, offset, wwnn_prefix);
  2350. offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET;
  2351. hw->eeprom.ops.read(hw, offset, wwpn_prefix);
  2352. wwn_prefix_out:
  2353. return 0;
  2354. }
  2355. static struct ixgbe_mac_operations mac_ops_82599 = {
  2356. .init_hw = &ixgbe_init_hw_generic,
  2357. .reset_hw = &ixgbe_reset_hw_82599,
  2358. .start_hw = &ixgbe_start_hw_82599,
  2359. .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic,
  2360. .get_media_type = &ixgbe_get_media_type_82599,
  2361. .get_supported_physical_layer = &ixgbe_get_supported_physical_layer_82599,
  2362. .enable_rx_dma = &ixgbe_enable_rx_dma_82599,
  2363. .get_mac_addr = &ixgbe_get_mac_addr_generic,
  2364. .get_san_mac_addr = &ixgbe_get_san_mac_addr_82599,
  2365. .get_device_caps = &ixgbe_get_device_caps_82599,
  2366. .get_wwn_prefix = &ixgbe_get_wwn_prefix_82599,
  2367. .stop_adapter = &ixgbe_stop_adapter_generic,
  2368. .get_bus_info = &ixgbe_get_bus_info_generic,
  2369. .set_lan_id = &ixgbe_set_lan_id_multi_port_pcie,
  2370. .read_analog_reg8 = &ixgbe_read_analog_reg8_82599,
  2371. .write_analog_reg8 = &ixgbe_write_analog_reg8_82599,
  2372. .setup_link = &ixgbe_setup_mac_link_82599,
  2373. .check_link = &ixgbe_check_mac_link_82599,
  2374. .get_link_capabilities = &ixgbe_get_link_capabilities_82599,
  2375. .led_on = &ixgbe_led_on_generic,
  2376. .led_off = &ixgbe_led_off_generic,
  2377. .blink_led_start = &ixgbe_blink_led_start_generic,
  2378. .blink_led_stop = &ixgbe_blink_led_stop_generic,
  2379. .set_rar = &ixgbe_set_rar_generic,
  2380. .clear_rar = &ixgbe_clear_rar_generic,
  2381. .set_vmdq = &ixgbe_set_vmdq_82599,
  2382. .clear_vmdq = &ixgbe_clear_vmdq_82599,
  2383. .init_rx_addrs = &ixgbe_init_rx_addrs_generic,
  2384. .update_uc_addr_list = &ixgbe_update_uc_addr_list_generic,
  2385. .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic,
  2386. .enable_mc = &ixgbe_enable_mc_generic,
  2387. .disable_mc = &ixgbe_disable_mc_generic,
  2388. .clear_vfta = &ixgbe_clear_vfta_82599,
  2389. .set_vfta = &ixgbe_set_vfta_82599,
  2390. .fc_enable = &ixgbe_fc_enable_generic,
  2391. .init_uta_tables = &ixgbe_init_uta_tables_82599,
  2392. .setup_sfp = &ixgbe_setup_sfp_modules_82599,
  2393. };
  2394. static struct ixgbe_eeprom_operations eeprom_ops_82599 = {
  2395. .init_params = &ixgbe_init_eeprom_params_generic,
  2396. .read = &ixgbe_read_eeprom_generic,
  2397. .write = &ixgbe_write_eeprom_generic,
  2398. .validate_checksum = &ixgbe_validate_eeprom_checksum_generic,
  2399. .update_checksum = &ixgbe_update_eeprom_checksum_generic,
  2400. };
  2401. static struct ixgbe_phy_operations phy_ops_82599 = {
  2402. .identify = &ixgbe_identify_phy_82599,
  2403. .identify_sfp = &ixgbe_identify_sfp_module_generic,
  2404. .init = &ixgbe_init_phy_ops_82599,
  2405. .reset = &ixgbe_reset_phy_generic,
  2406. .read_reg = &ixgbe_read_phy_reg_generic,
  2407. .write_reg = &ixgbe_write_phy_reg_generic,
  2408. .setup_link = &ixgbe_setup_phy_link_generic,
  2409. .setup_link_speed = &ixgbe_setup_phy_link_speed_generic,
  2410. .read_i2c_byte = &ixgbe_read_i2c_byte_generic,
  2411. .write_i2c_byte = &ixgbe_write_i2c_byte_generic,
  2412. .read_i2c_eeprom = &ixgbe_read_i2c_eeprom_generic,
  2413. .write_i2c_eeprom = &ixgbe_write_i2c_eeprom_generic,
  2414. };
  2415. struct ixgbe_info ixgbe_82599_info = {
  2416. .mac = ixgbe_mac_82599EB,
  2417. .get_invariants = &ixgbe_get_invariants_82599,
  2418. .mac_ops = &mac_ops_82599,
  2419. .eeprom_ops = &eeprom_ops_82599,
  2420. .phy_ops = &phy_ops_82599,
  2421. .mbx_ops = &mbx_ops_82599,
  2422. };