i40e_ethtool.c 95 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 - 2016 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. * Contact Information:
  22. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. ******************************************************************************/
  26. /* ethtool support for i40e */
  27. #include "i40e.h"
  28. #include "i40e_diag.h"
  29. struct i40e_stats {
  30. char stat_string[ETH_GSTRING_LEN];
  31. int sizeof_stat;
  32. int stat_offset;
  33. };
  34. #define I40E_STAT(_type, _name, _stat) { \
  35. .stat_string = _name, \
  36. .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
  37. .stat_offset = offsetof(_type, _stat) \
  38. }
  39. #define I40E_NETDEV_STAT(_net_stat) \
  40. I40E_STAT(struct rtnl_link_stats64, #_net_stat, _net_stat)
  41. #define I40E_PF_STAT(_name, _stat) \
  42. I40E_STAT(struct i40e_pf, _name, _stat)
  43. #define I40E_VSI_STAT(_name, _stat) \
  44. I40E_STAT(struct i40e_vsi, _name, _stat)
  45. #define I40E_VEB_STAT(_name, _stat) \
  46. I40E_STAT(struct i40e_veb, _name, _stat)
  47. static const struct i40e_stats i40e_gstrings_net_stats[] = {
  48. I40E_NETDEV_STAT(rx_packets),
  49. I40E_NETDEV_STAT(tx_packets),
  50. I40E_NETDEV_STAT(rx_bytes),
  51. I40E_NETDEV_STAT(tx_bytes),
  52. I40E_NETDEV_STAT(rx_errors),
  53. I40E_NETDEV_STAT(tx_errors),
  54. I40E_NETDEV_STAT(rx_dropped),
  55. I40E_NETDEV_STAT(tx_dropped),
  56. I40E_NETDEV_STAT(collisions),
  57. I40E_NETDEV_STAT(rx_length_errors),
  58. I40E_NETDEV_STAT(rx_crc_errors),
  59. };
  60. static const struct i40e_stats i40e_gstrings_veb_stats[] = {
  61. I40E_VEB_STAT("rx_bytes", stats.rx_bytes),
  62. I40E_VEB_STAT("tx_bytes", stats.tx_bytes),
  63. I40E_VEB_STAT("rx_unicast", stats.rx_unicast),
  64. I40E_VEB_STAT("tx_unicast", stats.tx_unicast),
  65. I40E_VEB_STAT("rx_multicast", stats.rx_multicast),
  66. I40E_VEB_STAT("tx_multicast", stats.tx_multicast),
  67. I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast),
  68. I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast),
  69. I40E_VEB_STAT("rx_discards", stats.rx_discards),
  70. I40E_VEB_STAT("tx_discards", stats.tx_discards),
  71. I40E_VEB_STAT("tx_errors", stats.tx_errors),
  72. I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol),
  73. };
  74. static const struct i40e_stats i40e_gstrings_misc_stats[] = {
  75. I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
  76. I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
  77. I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
  78. I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
  79. I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
  80. I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
  81. I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
  82. I40E_VSI_STAT("tx_linearize", tx_linearize),
  83. I40E_VSI_STAT("tx_force_wb", tx_force_wb),
  84. I40E_VSI_STAT("tx_lost_interrupt", tx_lost_interrupt),
  85. I40E_VSI_STAT("rx_alloc_fail", rx_buf_failed),
  86. I40E_VSI_STAT("rx_pg_alloc_fail", rx_page_failed),
  87. };
  88. /* These PF_STATs might look like duplicates of some NETDEV_STATs,
  89. * but they are separate. This device supports Virtualization, and
  90. * as such might have several netdevs supporting VMDq and FCoE going
  91. * through a single port. The NETDEV_STATs are for individual netdevs
  92. * seen at the top of the stack, and the PF_STATs are for the physical
  93. * function at the bottom of the stack hosting those netdevs.
  94. *
  95. * The PF_STATs are appended to the netdev stats only when ethtool -S
  96. * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
  97. */
  98. static const struct i40e_stats i40e_gstrings_stats[] = {
  99. I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
  100. I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
  101. I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
  102. I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
  103. I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
  104. I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
  105. I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
  106. I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
  107. I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
  108. I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
  109. I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
  110. I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
  111. I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
  112. I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
  113. I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
  114. I40E_PF_STAT("tx_timeout", tx_timeout_count),
  115. I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
  116. I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
  117. I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
  118. I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
  119. I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
  120. I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
  121. I40E_PF_STAT("rx_size_64", stats.rx_size_64),
  122. I40E_PF_STAT("rx_size_127", stats.rx_size_127),
  123. I40E_PF_STAT("rx_size_255", stats.rx_size_255),
  124. I40E_PF_STAT("rx_size_511", stats.rx_size_511),
  125. I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
  126. I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
  127. I40E_PF_STAT("rx_size_big", stats.rx_size_big),
  128. I40E_PF_STAT("tx_size_64", stats.tx_size_64),
  129. I40E_PF_STAT("tx_size_127", stats.tx_size_127),
  130. I40E_PF_STAT("tx_size_255", stats.tx_size_255),
  131. I40E_PF_STAT("tx_size_511", stats.tx_size_511),
  132. I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
  133. I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
  134. I40E_PF_STAT("tx_size_big", stats.tx_size_big),
  135. I40E_PF_STAT("rx_undersize", stats.rx_undersize),
  136. I40E_PF_STAT("rx_fragments", stats.rx_fragments),
  137. I40E_PF_STAT("rx_oversize", stats.rx_oversize),
  138. I40E_PF_STAT("rx_jabber", stats.rx_jabber),
  139. I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
  140. I40E_PF_STAT("arq_overflows", arq_overflows),
  141. I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
  142. I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
  143. I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
  144. I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
  145. I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
  146. I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
  147. I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
  148. /* LPI stats */
  149. I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
  150. I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
  151. I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
  152. I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
  153. };
  154. #ifdef I40E_FCOE
  155. static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
  156. I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
  157. I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
  158. I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
  159. I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
  160. I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
  161. I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
  162. I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
  163. I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
  164. };
  165. #endif /* I40E_FCOE */
  166. #define I40E_QUEUE_STATS_LEN(n) \
  167. (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
  168. * 2 /* Tx and Rx together */ \
  169. * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
  170. #define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
  171. #define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
  172. #define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
  173. #ifdef I40E_FCOE
  174. #define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
  175. #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
  176. I40E_FCOE_STATS_LEN + \
  177. I40E_MISC_STATS_LEN + \
  178. I40E_QUEUE_STATS_LEN((n)))
  179. #else
  180. #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
  181. I40E_MISC_STATS_LEN + \
  182. I40E_QUEUE_STATS_LEN((n)))
  183. #endif /* I40E_FCOE */
  184. #define I40E_PFC_STATS_LEN ( \
  185. (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
  186. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
  187. FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
  188. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
  189. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
  190. / sizeof(u64))
  191. #define I40E_VEB_TC_STATS_LEN ( \
  192. (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
  193. FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
  194. FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
  195. FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
  196. / sizeof(u64))
  197. #define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
  198. #define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
  199. #define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
  200. I40E_PFC_STATS_LEN + \
  201. I40E_VSI_STATS_LEN((n)))
  202. enum i40e_ethtool_test_id {
  203. I40E_ETH_TEST_REG = 0,
  204. I40E_ETH_TEST_EEPROM,
  205. I40E_ETH_TEST_INTR,
  206. I40E_ETH_TEST_LINK,
  207. };
  208. static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
  209. "Register test (offline)",
  210. "Eeprom test (offline)",
  211. "Interrupt test (offline)",
  212. "Link test (on/offline)"
  213. };
  214. #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
  215. static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
  216. "MFP",
  217. "LinkPolling",
  218. "flow-director-atr",
  219. "veb-stats",
  220. "hw-atr-eviction",
  221. };
  222. #define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings)
  223. /* Private flags with a global effect, restricted to PF 0 */
  224. static const char i40e_gl_priv_flags_strings[][ETH_GSTRING_LEN] = {
  225. "vf-true-promisc-support",
  226. };
  227. #define I40E_GL_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gl_priv_flags_strings)
  228. /**
  229. * i40e_partition_setting_complaint - generic complaint for MFP restriction
  230. * @pf: the PF struct
  231. **/
  232. static void i40e_partition_setting_complaint(struct i40e_pf *pf)
  233. {
  234. dev_info(&pf->pdev->dev,
  235. "The link settings are allowed to be changed only from the first partition of a given port. Please switch to the first partition in order to change the setting.\n");
  236. }
  237. /**
  238. * i40e_phy_type_to_ethtool - convert the phy_types to ethtool link modes
  239. * @phy_types: PHY types to convert
  240. * @supported: pointer to the ethtool supported variable to fill in
  241. * @advertising: pointer to the ethtool advertising variable to fill in
  242. *
  243. **/
  244. static void i40e_phy_type_to_ethtool(struct i40e_pf *pf, u32 *supported,
  245. u32 *advertising)
  246. {
  247. struct i40e_link_status *hw_link_info = &pf->hw.phy.link_info;
  248. u64 phy_types = pf->hw.phy.phy_types;
  249. *supported = 0x0;
  250. *advertising = 0x0;
  251. if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
  252. *supported |= SUPPORTED_Autoneg |
  253. SUPPORTED_1000baseT_Full;
  254. *advertising |= ADVERTISED_Autoneg;
  255. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  256. *advertising |= ADVERTISED_1000baseT_Full;
  257. if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
  258. *supported |= SUPPORTED_100baseT_Full;
  259. *advertising |= ADVERTISED_100baseT_Full;
  260. }
  261. }
  262. if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
  263. phy_types & I40E_CAP_PHY_TYPE_XFI ||
  264. phy_types & I40E_CAP_PHY_TYPE_SFI ||
  265. phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
  266. phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
  267. *supported |= SUPPORTED_10000baseT_Full;
  268. if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
  269. phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
  270. phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
  271. phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
  272. phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
  273. *supported |= SUPPORTED_Autoneg |
  274. SUPPORTED_10000baseT_Full;
  275. *advertising |= ADVERTISED_Autoneg;
  276. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  277. *advertising |= ADVERTISED_10000baseT_Full;
  278. }
  279. if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
  280. phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
  281. phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
  282. *supported |= SUPPORTED_40000baseCR4_Full;
  283. if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
  284. phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
  285. *supported |= SUPPORTED_Autoneg |
  286. SUPPORTED_40000baseCR4_Full;
  287. *advertising |= ADVERTISED_Autoneg;
  288. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_40GB)
  289. *advertising |= ADVERTISED_40000baseCR4_Full;
  290. }
  291. if (phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
  292. *supported |= SUPPORTED_Autoneg |
  293. SUPPORTED_100baseT_Full;
  294. *advertising |= ADVERTISED_Autoneg;
  295. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
  296. *advertising |= ADVERTISED_100baseT_Full;
  297. }
  298. if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
  299. phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
  300. phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
  301. phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
  302. *supported |= SUPPORTED_Autoneg |
  303. SUPPORTED_1000baseT_Full;
  304. *advertising |= ADVERTISED_Autoneg;
  305. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  306. *advertising |= ADVERTISED_1000baseT_Full;
  307. }
  308. if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
  309. *supported |= SUPPORTED_40000baseSR4_Full;
  310. if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
  311. *supported |= SUPPORTED_40000baseLR4_Full;
  312. if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
  313. *supported |= SUPPORTED_40000baseKR4_Full |
  314. SUPPORTED_Autoneg;
  315. *advertising |= ADVERTISED_40000baseKR4_Full |
  316. ADVERTISED_Autoneg;
  317. }
  318. if (phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
  319. *supported |= SUPPORTED_20000baseKR2_Full |
  320. SUPPORTED_Autoneg;
  321. *advertising |= ADVERTISED_Autoneg;
  322. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_20GB)
  323. *advertising |= ADVERTISED_20000baseKR2_Full;
  324. }
  325. if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
  326. if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER))
  327. *supported |= SUPPORTED_10000baseKR_Full |
  328. SUPPORTED_Autoneg;
  329. *advertising |= ADVERTISED_Autoneg;
  330. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  331. if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER))
  332. *advertising |= ADVERTISED_10000baseKR_Full;
  333. }
  334. if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
  335. *supported |= SUPPORTED_10000baseKX4_Full |
  336. SUPPORTED_Autoneg;
  337. *advertising |= ADVERTISED_Autoneg;
  338. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  339. *advertising |= ADVERTISED_10000baseKX4_Full;
  340. }
  341. if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
  342. if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER))
  343. *supported |= SUPPORTED_1000baseKX_Full |
  344. SUPPORTED_Autoneg;
  345. *advertising |= ADVERTISED_Autoneg;
  346. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  347. if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER))
  348. *advertising |= ADVERTISED_1000baseKX_Full;
  349. }
  350. if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR ||
  351. phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR ||
  352. phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR ||
  353. phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR) {
  354. *supported |= SUPPORTED_Autoneg;
  355. *advertising |= ADVERTISED_Autoneg;
  356. }
  357. }
  358. /**
  359. * i40e_get_settings_link_up - Get the Link settings for when link is up
  360. * @hw: hw structure
  361. * @ecmd: ethtool command to fill in
  362. * @netdev: network interface device structure
  363. *
  364. **/
  365. static void i40e_get_settings_link_up(struct i40e_hw *hw,
  366. struct ethtool_cmd *ecmd,
  367. struct net_device *netdev,
  368. struct i40e_pf *pf)
  369. {
  370. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  371. u32 link_speed = hw_link_info->link_speed;
  372. u32 e_advertising = 0x0;
  373. u32 e_supported = 0x0;
  374. /* Initialize supported and advertised settings based on phy settings */
  375. switch (hw_link_info->phy_type) {
  376. case I40E_PHY_TYPE_40GBASE_CR4:
  377. case I40E_PHY_TYPE_40GBASE_CR4_CU:
  378. ecmd->supported = SUPPORTED_Autoneg |
  379. SUPPORTED_40000baseCR4_Full;
  380. ecmd->advertising = ADVERTISED_Autoneg |
  381. ADVERTISED_40000baseCR4_Full;
  382. break;
  383. case I40E_PHY_TYPE_XLAUI:
  384. case I40E_PHY_TYPE_XLPPI:
  385. case I40E_PHY_TYPE_40GBASE_AOC:
  386. ecmd->supported = SUPPORTED_40000baseCR4_Full;
  387. break;
  388. case I40E_PHY_TYPE_40GBASE_SR4:
  389. ecmd->supported = SUPPORTED_40000baseSR4_Full;
  390. break;
  391. case I40E_PHY_TYPE_40GBASE_LR4:
  392. ecmd->supported = SUPPORTED_40000baseLR4_Full;
  393. break;
  394. case I40E_PHY_TYPE_10GBASE_SR:
  395. case I40E_PHY_TYPE_10GBASE_LR:
  396. case I40E_PHY_TYPE_1000BASE_SX:
  397. case I40E_PHY_TYPE_1000BASE_LX:
  398. ecmd->supported = SUPPORTED_10000baseT_Full;
  399. if (hw_link_info->module_type[2] &
  400. I40E_MODULE_TYPE_1000BASE_SX ||
  401. hw_link_info->module_type[2] &
  402. I40E_MODULE_TYPE_1000BASE_LX) {
  403. ecmd->supported |= SUPPORTED_1000baseT_Full;
  404. if (hw_link_info->requested_speeds &
  405. I40E_LINK_SPEED_1GB)
  406. ecmd->advertising |= ADVERTISED_1000baseT_Full;
  407. }
  408. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  409. ecmd->advertising |= ADVERTISED_10000baseT_Full;
  410. break;
  411. case I40E_PHY_TYPE_10GBASE_T:
  412. case I40E_PHY_TYPE_1000BASE_T:
  413. case I40E_PHY_TYPE_100BASE_TX:
  414. ecmd->supported = SUPPORTED_Autoneg |
  415. SUPPORTED_10000baseT_Full |
  416. SUPPORTED_1000baseT_Full |
  417. SUPPORTED_100baseT_Full;
  418. ecmd->advertising = ADVERTISED_Autoneg;
  419. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  420. ecmd->advertising |= ADVERTISED_10000baseT_Full;
  421. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  422. ecmd->advertising |= ADVERTISED_1000baseT_Full;
  423. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
  424. ecmd->advertising |= ADVERTISED_100baseT_Full;
  425. break;
  426. case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
  427. ecmd->supported = SUPPORTED_Autoneg |
  428. SUPPORTED_1000baseT_Full;
  429. ecmd->advertising = ADVERTISED_Autoneg |
  430. ADVERTISED_1000baseT_Full;
  431. break;
  432. case I40E_PHY_TYPE_10GBASE_CR1_CU:
  433. case I40E_PHY_TYPE_10GBASE_CR1:
  434. ecmd->supported = SUPPORTED_Autoneg |
  435. SUPPORTED_10000baseT_Full;
  436. ecmd->advertising = ADVERTISED_Autoneg |
  437. ADVERTISED_10000baseT_Full;
  438. break;
  439. case I40E_PHY_TYPE_XAUI:
  440. case I40E_PHY_TYPE_XFI:
  441. case I40E_PHY_TYPE_SFI:
  442. case I40E_PHY_TYPE_10GBASE_SFPP_CU:
  443. case I40E_PHY_TYPE_10GBASE_AOC:
  444. ecmd->supported = SUPPORTED_10000baseT_Full;
  445. ecmd->advertising = SUPPORTED_10000baseT_Full;
  446. break;
  447. case I40E_PHY_TYPE_SGMII:
  448. ecmd->supported = SUPPORTED_Autoneg |
  449. SUPPORTED_1000baseT_Full;
  450. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  451. ecmd->advertising |= ADVERTISED_1000baseT_Full;
  452. if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
  453. ecmd->supported |= SUPPORTED_100baseT_Full;
  454. if (hw_link_info->requested_speeds &
  455. I40E_LINK_SPEED_100MB)
  456. ecmd->advertising |= ADVERTISED_100baseT_Full;
  457. }
  458. break;
  459. case I40E_PHY_TYPE_40GBASE_KR4:
  460. case I40E_PHY_TYPE_20GBASE_KR2:
  461. case I40E_PHY_TYPE_10GBASE_KR:
  462. case I40E_PHY_TYPE_10GBASE_KX4:
  463. case I40E_PHY_TYPE_1000BASE_KX:
  464. ecmd->supported |= SUPPORTED_40000baseKR4_Full |
  465. SUPPORTED_20000baseKR2_Full |
  466. SUPPORTED_10000baseKR_Full |
  467. SUPPORTED_10000baseKX4_Full |
  468. SUPPORTED_1000baseKX_Full |
  469. SUPPORTED_Autoneg;
  470. ecmd->advertising |= ADVERTISED_40000baseKR4_Full |
  471. ADVERTISED_20000baseKR2_Full |
  472. ADVERTISED_10000baseKR_Full |
  473. ADVERTISED_10000baseKX4_Full |
  474. ADVERTISED_1000baseKX_Full |
  475. ADVERTISED_Autoneg;
  476. break;
  477. case I40E_PHY_TYPE_25GBASE_KR:
  478. case I40E_PHY_TYPE_25GBASE_CR:
  479. case I40E_PHY_TYPE_25GBASE_SR:
  480. case I40E_PHY_TYPE_25GBASE_LR:
  481. ecmd->supported = SUPPORTED_Autoneg;
  482. ecmd->advertising = ADVERTISED_Autoneg;
  483. /* TODO: add speeds when ethtool is ready to support*/
  484. break;
  485. default:
  486. /* if we got here and link is up something bad is afoot */
  487. netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
  488. hw_link_info->phy_type);
  489. }
  490. /* Now that we've worked out everything that could be supported by the
  491. * current PHY type, get what is supported by the NVM and them to
  492. * get what is truly supported
  493. */
  494. i40e_phy_type_to_ethtool(pf, &e_supported,
  495. &e_advertising);
  496. ecmd->supported = ecmd->supported & e_supported;
  497. ecmd->advertising = ecmd->advertising & e_advertising;
  498. /* Set speed and duplex */
  499. switch (link_speed) {
  500. case I40E_LINK_SPEED_40GB:
  501. ethtool_cmd_speed_set(ecmd, SPEED_40000);
  502. break;
  503. case I40E_LINK_SPEED_25GB:
  504. #ifdef SPEED_25000
  505. ethtool_cmd_speed_set(ecmd, SPEED_25000);
  506. #else
  507. netdev_info(netdev,
  508. "Speed is 25G, display not supported by this version of ethtool.\n");
  509. #endif
  510. break;
  511. case I40E_LINK_SPEED_20GB:
  512. ethtool_cmd_speed_set(ecmd, SPEED_20000);
  513. break;
  514. case I40E_LINK_SPEED_10GB:
  515. ethtool_cmd_speed_set(ecmd, SPEED_10000);
  516. break;
  517. case I40E_LINK_SPEED_1GB:
  518. ethtool_cmd_speed_set(ecmd, SPEED_1000);
  519. break;
  520. case I40E_LINK_SPEED_100MB:
  521. ethtool_cmd_speed_set(ecmd, SPEED_100);
  522. break;
  523. default:
  524. break;
  525. }
  526. ecmd->duplex = DUPLEX_FULL;
  527. }
  528. /**
  529. * i40e_get_settings_link_down - Get the Link settings for when link is down
  530. * @hw: hw structure
  531. * @ecmd: ethtool command to fill in
  532. *
  533. * Reports link settings that can be determined when link is down
  534. **/
  535. static void i40e_get_settings_link_down(struct i40e_hw *hw,
  536. struct ethtool_cmd *ecmd,
  537. struct i40e_pf *pf)
  538. {
  539. /* link is down and the driver needs to fall back on
  540. * supported phy types to figure out what info to display
  541. */
  542. i40e_phy_type_to_ethtool(pf, &ecmd->supported,
  543. &ecmd->advertising);
  544. /* With no link speed and duplex are unknown */
  545. ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
  546. ecmd->duplex = DUPLEX_UNKNOWN;
  547. }
  548. /**
  549. * i40e_get_settings - Get Link Speed and Duplex settings
  550. * @netdev: network interface device structure
  551. * @ecmd: ethtool command
  552. *
  553. * Reports speed/duplex settings based on media_type
  554. **/
  555. static int i40e_get_settings(struct net_device *netdev,
  556. struct ethtool_cmd *ecmd)
  557. {
  558. struct i40e_netdev_priv *np = netdev_priv(netdev);
  559. struct i40e_pf *pf = np->vsi->back;
  560. struct i40e_hw *hw = &pf->hw;
  561. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  562. bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
  563. if (link_up)
  564. i40e_get_settings_link_up(hw, ecmd, netdev, pf);
  565. else
  566. i40e_get_settings_link_down(hw, ecmd, pf);
  567. /* Now set the settings that don't rely on link being up/down */
  568. /* Set autoneg settings */
  569. ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  570. AUTONEG_ENABLE : AUTONEG_DISABLE);
  571. switch (hw->phy.media_type) {
  572. case I40E_MEDIA_TYPE_BACKPLANE:
  573. ecmd->supported |= SUPPORTED_Autoneg |
  574. SUPPORTED_Backplane;
  575. ecmd->advertising |= ADVERTISED_Autoneg |
  576. ADVERTISED_Backplane;
  577. ecmd->port = PORT_NONE;
  578. break;
  579. case I40E_MEDIA_TYPE_BASET:
  580. ecmd->supported |= SUPPORTED_TP;
  581. ecmd->advertising |= ADVERTISED_TP;
  582. ecmd->port = PORT_TP;
  583. break;
  584. case I40E_MEDIA_TYPE_DA:
  585. case I40E_MEDIA_TYPE_CX4:
  586. ecmd->supported |= SUPPORTED_FIBRE;
  587. ecmd->advertising |= ADVERTISED_FIBRE;
  588. ecmd->port = PORT_DA;
  589. break;
  590. case I40E_MEDIA_TYPE_FIBER:
  591. ecmd->supported |= SUPPORTED_FIBRE;
  592. ecmd->port = PORT_FIBRE;
  593. break;
  594. case I40E_MEDIA_TYPE_UNKNOWN:
  595. default:
  596. ecmd->port = PORT_OTHER;
  597. break;
  598. }
  599. /* Set transceiver */
  600. ecmd->transceiver = XCVR_EXTERNAL;
  601. /* Set flow control settings */
  602. ecmd->supported |= SUPPORTED_Pause;
  603. switch (hw->fc.requested_mode) {
  604. case I40E_FC_FULL:
  605. ecmd->advertising |= ADVERTISED_Pause;
  606. break;
  607. case I40E_FC_TX_PAUSE:
  608. ecmd->advertising |= ADVERTISED_Asym_Pause;
  609. break;
  610. case I40E_FC_RX_PAUSE:
  611. ecmd->advertising |= (ADVERTISED_Pause |
  612. ADVERTISED_Asym_Pause);
  613. break;
  614. default:
  615. ecmd->advertising &= ~(ADVERTISED_Pause |
  616. ADVERTISED_Asym_Pause);
  617. break;
  618. }
  619. return 0;
  620. }
  621. /**
  622. * i40e_set_settings - Set Speed and Duplex
  623. * @netdev: network interface device structure
  624. * @ecmd: ethtool command
  625. *
  626. * Set speed/duplex per media_types advertised/forced
  627. **/
  628. static int i40e_set_settings(struct net_device *netdev,
  629. struct ethtool_cmd *ecmd)
  630. {
  631. struct i40e_netdev_priv *np = netdev_priv(netdev);
  632. struct i40e_aq_get_phy_abilities_resp abilities;
  633. struct i40e_aq_set_phy_config config;
  634. struct i40e_pf *pf = np->vsi->back;
  635. struct i40e_vsi *vsi = np->vsi;
  636. struct i40e_hw *hw = &pf->hw;
  637. struct ethtool_cmd safe_ecmd;
  638. i40e_status status = 0;
  639. bool change = false;
  640. int err = 0;
  641. u8 autoneg;
  642. u32 advertise;
  643. /* Changing port settings is not supported if this isn't the
  644. * port's controlling PF
  645. */
  646. if (hw->partition_id != 1) {
  647. i40e_partition_setting_complaint(pf);
  648. return -EOPNOTSUPP;
  649. }
  650. if (vsi != pf->vsi[pf->lan_vsi])
  651. return -EOPNOTSUPP;
  652. if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
  653. hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
  654. hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
  655. hw->phy.media_type != I40E_MEDIA_TYPE_DA &&
  656. hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
  657. return -EOPNOTSUPP;
  658. if (hw->device_id == I40E_DEV_ID_KX_B ||
  659. hw->device_id == I40E_DEV_ID_KX_C ||
  660. hw->device_id == I40E_DEV_ID_20G_KR2 ||
  661. hw->device_id == I40E_DEV_ID_20G_KR2_A) {
  662. netdev_info(netdev, "Changing settings is not supported on backplane.\n");
  663. return -EOPNOTSUPP;
  664. }
  665. /* get our own copy of the bits to check against */
  666. memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
  667. i40e_get_settings(netdev, &safe_ecmd);
  668. /* save autoneg and speed out of ecmd */
  669. autoneg = ecmd->autoneg;
  670. advertise = ecmd->advertising;
  671. /* set autoneg and speed back to what they currently are */
  672. ecmd->autoneg = safe_ecmd.autoneg;
  673. ecmd->advertising = safe_ecmd.advertising;
  674. ecmd->cmd = safe_ecmd.cmd;
  675. /* If ecmd and safe_ecmd are not the same now, then they are
  676. * trying to set something that we do not support
  677. */
  678. if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
  679. return -EOPNOTSUPP;
  680. while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
  681. usleep_range(1000, 2000);
  682. /* Get the current phy config */
  683. status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
  684. NULL);
  685. if (status)
  686. return -EAGAIN;
  687. /* Copy abilities to config in case autoneg is not
  688. * set below
  689. */
  690. memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
  691. config.abilities = abilities.abilities;
  692. /* Check autoneg */
  693. if (autoneg == AUTONEG_ENABLE) {
  694. /* If autoneg was not already enabled */
  695. if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
  696. /* If autoneg is not supported, return error */
  697. if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
  698. netdev_info(netdev, "Autoneg not supported on this phy\n");
  699. return -EINVAL;
  700. }
  701. /* Autoneg is allowed to change */
  702. config.abilities = abilities.abilities |
  703. I40E_AQ_PHY_ENABLE_AN;
  704. change = true;
  705. }
  706. } else {
  707. /* If autoneg is currently enabled */
  708. if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
  709. /* If autoneg is supported 10GBASE_T is the only PHY
  710. * that can disable it, so otherwise return error
  711. */
  712. if (safe_ecmd.supported & SUPPORTED_Autoneg &&
  713. hw->phy.link_info.phy_type !=
  714. I40E_PHY_TYPE_10GBASE_T) {
  715. netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
  716. return -EINVAL;
  717. }
  718. /* Autoneg is allowed to change */
  719. config.abilities = abilities.abilities &
  720. ~I40E_AQ_PHY_ENABLE_AN;
  721. change = true;
  722. }
  723. }
  724. if (advertise & ~safe_ecmd.supported)
  725. return -EINVAL;
  726. if (advertise & ADVERTISED_100baseT_Full)
  727. config.link_speed |= I40E_LINK_SPEED_100MB;
  728. if (advertise & ADVERTISED_1000baseT_Full ||
  729. advertise & ADVERTISED_1000baseKX_Full)
  730. config.link_speed |= I40E_LINK_SPEED_1GB;
  731. if (advertise & ADVERTISED_10000baseT_Full ||
  732. advertise & ADVERTISED_10000baseKX4_Full ||
  733. advertise & ADVERTISED_10000baseKR_Full)
  734. config.link_speed |= I40E_LINK_SPEED_10GB;
  735. if (advertise & ADVERTISED_20000baseKR2_Full)
  736. config.link_speed |= I40E_LINK_SPEED_20GB;
  737. if (advertise & ADVERTISED_40000baseKR4_Full ||
  738. advertise & ADVERTISED_40000baseCR4_Full ||
  739. advertise & ADVERTISED_40000baseSR4_Full ||
  740. advertise & ADVERTISED_40000baseLR4_Full)
  741. config.link_speed |= I40E_LINK_SPEED_40GB;
  742. /* If speed didn't get set, set it to what it currently is.
  743. * This is needed because if advertise is 0 (as it is when autoneg
  744. * is disabled) then speed won't get set.
  745. */
  746. if (!config.link_speed)
  747. config.link_speed = abilities.link_speed;
  748. if (change || (abilities.link_speed != config.link_speed)) {
  749. /* copy over the rest of the abilities */
  750. config.phy_type = abilities.phy_type;
  751. config.eee_capability = abilities.eee_capability;
  752. config.eeer = abilities.eeer_val;
  753. config.low_power_ctrl = abilities.d3_lpan;
  754. /* save the requested speeds */
  755. hw->phy.link_info.requested_speeds = config.link_speed;
  756. /* set link and auto negotiation so changes take effect */
  757. config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
  758. /* If link is up put link down */
  759. if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
  760. /* Tell the OS link is going down, the link will go
  761. * back up when fw says it is ready asynchronously
  762. */
  763. i40e_print_link_message(vsi, false);
  764. netif_carrier_off(netdev);
  765. netif_tx_stop_all_queues(netdev);
  766. }
  767. /* make the aq call */
  768. status = i40e_aq_set_phy_config(hw, &config, NULL);
  769. if (status) {
  770. netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
  771. i40e_stat_str(hw, status),
  772. i40e_aq_str(hw, hw->aq.asq_last_status));
  773. return -EAGAIN;
  774. }
  775. status = i40e_update_link_info(hw);
  776. if (status)
  777. netdev_dbg(netdev, "Updating link info failed with err %s aq_err %s\n",
  778. i40e_stat_str(hw, status),
  779. i40e_aq_str(hw, hw->aq.asq_last_status));
  780. } else {
  781. netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
  782. }
  783. return err;
  784. }
  785. static int i40e_nway_reset(struct net_device *netdev)
  786. {
  787. /* restart autonegotiation */
  788. struct i40e_netdev_priv *np = netdev_priv(netdev);
  789. struct i40e_pf *pf = np->vsi->back;
  790. struct i40e_hw *hw = &pf->hw;
  791. bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
  792. i40e_status ret = 0;
  793. ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
  794. if (ret) {
  795. netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
  796. i40e_stat_str(hw, ret),
  797. i40e_aq_str(hw, hw->aq.asq_last_status));
  798. return -EIO;
  799. }
  800. return 0;
  801. }
  802. /**
  803. * i40e_get_pauseparam - Get Flow Control status
  804. * Return tx/rx-pause status
  805. **/
  806. static void i40e_get_pauseparam(struct net_device *netdev,
  807. struct ethtool_pauseparam *pause)
  808. {
  809. struct i40e_netdev_priv *np = netdev_priv(netdev);
  810. struct i40e_pf *pf = np->vsi->back;
  811. struct i40e_hw *hw = &pf->hw;
  812. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  813. struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
  814. pause->autoneg =
  815. ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  816. AUTONEG_ENABLE : AUTONEG_DISABLE);
  817. /* PFC enabled so report LFC as off */
  818. if (dcbx_cfg->pfc.pfcenable) {
  819. pause->rx_pause = 0;
  820. pause->tx_pause = 0;
  821. return;
  822. }
  823. if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
  824. pause->rx_pause = 1;
  825. } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
  826. pause->tx_pause = 1;
  827. } else if (hw->fc.current_mode == I40E_FC_FULL) {
  828. pause->rx_pause = 1;
  829. pause->tx_pause = 1;
  830. }
  831. }
  832. /**
  833. * i40e_set_pauseparam - Set Flow Control parameter
  834. * @netdev: network interface device structure
  835. * @pause: return tx/rx flow control status
  836. **/
  837. static int i40e_set_pauseparam(struct net_device *netdev,
  838. struct ethtool_pauseparam *pause)
  839. {
  840. struct i40e_netdev_priv *np = netdev_priv(netdev);
  841. struct i40e_pf *pf = np->vsi->back;
  842. struct i40e_vsi *vsi = np->vsi;
  843. struct i40e_hw *hw = &pf->hw;
  844. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  845. struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
  846. bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
  847. i40e_status status;
  848. u8 aq_failures;
  849. int err = 0;
  850. /* Changing the port's flow control is not supported if this isn't the
  851. * port's controlling PF
  852. */
  853. if (hw->partition_id != 1) {
  854. i40e_partition_setting_complaint(pf);
  855. return -EOPNOTSUPP;
  856. }
  857. if (vsi != pf->vsi[pf->lan_vsi])
  858. return -EOPNOTSUPP;
  859. if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  860. AUTONEG_ENABLE : AUTONEG_DISABLE)) {
  861. netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
  862. return -EOPNOTSUPP;
  863. }
  864. /* If we have link and don't have autoneg */
  865. if (!test_bit(__I40E_DOWN, &pf->state) &&
  866. !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
  867. /* Send message that it might not necessarily work*/
  868. netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
  869. }
  870. if (dcbx_cfg->pfc.pfcenable) {
  871. netdev_info(netdev,
  872. "Priority flow control enabled. Cannot set link flow control.\n");
  873. return -EOPNOTSUPP;
  874. }
  875. if (pause->rx_pause && pause->tx_pause)
  876. hw->fc.requested_mode = I40E_FC_FULL;
  877. else if (pause->rx_pause && !pause->tx_pause)
  878. hw->fc.requested_mode = I40E_FC_RX_PAUSE;
  879. else if (!pause->rx_pause && pause->tx_pause)
  880. hw->fc.requested_mode = I40E_FC_TX_PAUSE;
  881. else if (!pause->rx_pause && !pause->tx_pause)
  882. hw->fc.requested_mode = I40E_FC_NONE;
  883. else
  884. return -EINVAL;
  885. /* Tell the OS link is going down, the link will go back up when fw
  886. * says it is ready asynchronously
  887. */
  888. i40e_print_link_message(vsi, false);
  889. netif_carrier_off(netdev);
  890. netif_tx_stop_all_queues(netdev);
  891. /* Set the fc mode and only restart an if link is up*/
  892. status = i40e_set_fc(hw, &aq_failures, link_up);
  893. if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
  894. netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
  895. i40e_stat_str(hw, status),
  896. i40e_aq_str(hw, hw->aq.asq_last_status));
  897. err = -EAGAIN;
  898. }
  899. if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
  900. netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
  901. i40e_stat_str(hw, status),
  902. i40e_aq_str(hw, hw->aq.asq_last_status));
  903. err = -EAGAIN;
  904. }
  905. if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
  906. netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
  907. i40e_stat_str(hw, status),
  908. i40e_aq_str(hw, hw->aq.asq_last_status));
  909. err = -EAGAIN;
  910. }
  911. if (!test_bit(__I40E_DOWN, &pf->state)) {
  912. /* Give it a little more time to try to come back */
  913. msleep(75);
  914. if (!test_bit(__I40E_DOWN, &pf->state))
  915. return i40e_nway_reset(netdev);
  916. }
  917. return err;
  918. }
  919. static u32 i40e_get_msglevel(struct net_device *netdev)
  920. {
  921. struct i40e_netdev_priv *np = netdev_priv(netdev);
  922. struct i40e_pf *pf = np->vsi->back;
  923. u32 debug_mask = pf->hw.debug_mask;
  924. if (debug_mask)
  925. netdev_info(netdev, "i40e debug_mask: 0x%08X\n", debug_mask);
  926. return pf->msg_enable;
  927. }
  928. static void i40e_set_msglevel(struct net_device *netdev, u32 data)
  929. {
  930. struct i40e_netdev_priv *np = netdev_priv(netdev);
  931. struct i40e_pf *pf = np->vsi->back;
  932. if (I40E_DEBUG_USER & data)
  933. pf->hw.debug_mask = data;
  934. else
  935. pf->msg_enable = data;
  936. }
  937. static int i40e_get_regs_len(struct net_device *netdev)
  938. {
  939. int reg_count = 0;
  940. int i;
  941. for (i = 0; i40e_reg_list[i].offset != 0; i++)
  942. reg_count += i40e_reg_list[i].elements;
  943. return reg_count * sizeof(u32);
  944. }
  945. static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
  946. void *p)
  947. {
  948. struct i40e_netdev_priv *np = netdev_priv(netdev);
  949. struct i40e_pf *pf = np->vsi->back;
  950. struct i40e_hw *hw = &pf->hw;
  951. u32 *reg_buf = p;
  952. int i, j, ri;
  953. u32 reg;
  954. /* Tell ethtool which driver-version-specific regs output we have.
  955. *
  956. * At some point, if we have ethtool doing special formatting of
  957. * this data, it will rely on this version number to know how to
  958. * interpret things. Hence, this needs to be updated if/when the
  959. * diags register table is changed.
  960. */
  961. regs->version = 1;
  962. /* loop through the diags reg table for what to print */
  963. ri = 0;
  964. for (i = 0; i40e_reg_list[i].offset != 0; i++) {
  965. for (j = 0; j < i40e_reg_list[i].elements; j++) {
  966. reg = i40e_reg_list[i].offset
  967. + (j * i40e_reg_list[i].stride);
  968. reg_buf[ri++] = rd32(hw, reg);
  969. }
  970. }
  971. }
  972. static int i40e_get_eeprom(struct net_device *netdev,
  973. struct ethtool_eeprom *eeprom, u8 *bytes)
  974. {
  975. struct i40e_netdev_priv *np = netdev_priv(netdev);
  976. struct i40e_hw *hw = &np->vsi->back->hw;
  977. struct i40e_pf *pf = np->vsi->back;
  978. int ret_val = 0, len, offset;
  979. u8 *eeprom_buff;
  980. u16 i, sectors;
  981. bool last;
  982. u32 magic;
  983. #define I40E_NVM_SECTOR_SIZE 4096
  984. if (eeprom->len == 0)
  985. return -EINVAL;
  986. /* check for NVMUpdate access method */
  987. magic = hw->vendor_id | (hw->device_id << 16);
  988. if (eeprom->magic && eeprom->magic != magic) {
  989. struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
  990. int errno = 0;
  991. /* make sure it is the right magic for NVMUpdate */
  992. if ((eeprom->magic >> 16) != hw->device_id)
  993. errno = -EINVAL;
  994. else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  995. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  996. errno = -EBUSY;
  997. else
  998. ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
  999. if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
  1000. dev_info(&pf->pdev->dev,
  1001. "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
  1002. ret_val, hw->aq.asq_last_status, errno,
  1003. (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
  1004. cmd->offset, cmd->data_size);
  1005. return errno;
  1006. }
  1007. /* normal ethtool get_eeprom support */
  1008. eeprom->magic = hw->vendor_id | (hw->device_id << 16);
  1009. eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
  1010. if (!eeprom_buff)
  1011. return -ENOMEM;
  1012. ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
  1013. if (ret_val) {
  1014. dev_info(&pf->pdev->dev,
  1015. "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
  1016. ret_val, hw->aq.asq_last_status);
  1017. goto free_buff;
  1018. }
  1019. sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
  1020. sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
  1021. len = I40E_NVM_SECTOR_SIZE;
  1022. last = false;
  1023. for (i = 0; i < sectors; i++) {
  1024. if (i == (sectors - 1)) {
  1025. len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
  1026. last = true;
  1027. }
  1028. offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
  1029. ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
  1030. (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
  1031. last, NULL);
  1032. if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
  1033. dev_info(&pf->pdev->dev,
  1034. "read NVM failed, invalid offset 0x%x\n",
  1035. offset);
  1036. break;
  1037. } else if (ret_val &&
  1038. hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
  1039. dev_info(&pf->pdev->dev,
  1040. "read NVM failed, access, offset 0x%x\n",
  1041. offset);
  1042. break;
  1043. } else if (ret_val) {
  1044. dev_info(&pf->pdev->dev,
  1045. "read NVM failed offset %d err=%d status=0x%x\n",
  1046. offset, ret_val, hw->aq.asq_last_status);
  1047. break;
  1048. }
  1049. }
  1050. i40e_release_nvm(hw);
  1051. memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
  1052. free_buff:
  1053. kfree(eeprom_buff);
  1054. return ret_val;
  1055. }
  1056. static int i40e_get_eeprom_len(struct net_device *netdev)
  1057. {
  1058. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1059. struct i40e_hw *hw = &np->vsi->back->hw;
  1060. u32 val;
  1061. val = (rd32(hw, I40E_GLPCI_LBARCTRL)
  1062. & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
  1063. >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
  1064. /* register returns value in power of 2, 64Kbyte chunks. */
  1065. val = (64 * 1024) * BIT(val);
  1066. return val;
  1067. }
  1068. static int i40e_set_eeprom(struct net_device *netdev,
  1069. struct ethtool_eeprom *eeprom, u8 *bytes)
  1070. {
  1071. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1072. struct i40e_hw *hw = &np->vsi->back->hw;
  1073. struct i40e_pf *pf = np->vsi->back;
  1074. struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
  1075. int ret_val = 0;
  1076. int errno = 0;
  1077. u32 magic;
  1078. /* normal ethtool set_eeprom is not supported */
  1079. magic = hw->vendor_id | (hw->device_id << 16);
  1080. if (eeprom->magic == magic)
  1081. errno = -EOPNOTSUPP;
  1082. /* check for NVMUpdate access method */
  1083. else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
  1084. errno = -EINVAL;
  1085. else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  1086. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  1087. errno = -EBUSY;
  1088. else
  1089. ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
  1090. if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
  1091. dev_info(&pf->pdev->dev,
  1092. "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
  1093. ret_val, hw->aq.asq_last_status, errno,
  1094. (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
  1095. cmd->offset, cmd->data_size);
  1096. return errno;
  1097. }
  1098. static void i40e_get_drvinfo(struct net_device *netdev,
  1099. struct ethtool_drvinfo *drvinfo)
  1100. {
  1101. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1102. struct i40e_vsi *vsi = np->vsi;
  1103. struct i40e_pf *pf = vsi->back;
  1104. strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
  1105. strlcpy(drvinfo->version, i40e_driver_version_str,
  1106. sizeof(drvinfo->version));
  1107. strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
  1108. sizeof(drvinfo->fw_version));
  1109. strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
  1110. sizeof(drvinfo->bus_info));
  1111. drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
  1112. if (pf->hw.pf_id == 0)
  1113. drvinfo->n_priv_flags += I40E_GL_PRIV_FLAGS_STR_LEN;
  1114. }
  1115. static void i40e_get_ringparam(struct net_device *netdev,
  1116. struct ethtool_ringparam *ring)
  1117. {
  1118. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1119. struct i40e_pf *pf = np->vsi->back;
  1120. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  1121. ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
  1122. ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
  1123. ring->rx_mini_max_pending = 0;
  1124. ring->rx_jumbo_max_pending = 0;
  1125. ring->rx_pending = vsi->rx_rings[0]->count;
  1126. ring->tx_pending = vsi->tx_rings[0]->count;
  1127. ring->rx_mini_pending = 0;
  1128. ring->rx_jumbo_pending = 0;
  1129. }
  1130. static int i40e_set_ringparam(struct net_device *netdev,
  1131. struct ethtool_ringparam *ring)
  1132. {
  1133. struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
  1134. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1135. struct i40e_hw *hw = &np->vsi->back->hw;
  1136. struct i40e_vsi *vsi = np->vsi;
  1137. struct i40e_pf *pf = vsi->back;
  1138. u32 new_rx_count, new_tx_count;
  1139. int i, err = 0;
  1140. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  1141. return -EINVAL;
  1142. if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
  1143. ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
  1144. ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
  1145. ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
  1146. netdev_info(netdev,
  1147. "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
  1148. ring->tx_pending, ring->rx_pending,
  1149. I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
  1150. return -EINVAL;
  1151. }
  1152. new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
  1153. new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
  1154. /* if nothing to do return success */
  1155. if ((new_tx_count == vsi->tx_rings[0]->count) &&
  1156. (new_rx_count == vsi->rx_rings[0]->count))
  1157. return 0;
  1158. while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
  1159. usleep_range(1000, 2000);
  1160. if (!netif_running(vsi->netdev)) {
  1161. /* simple case - set for the next time the netdev is started */
  1162. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1163. vsi->tx_rings[i]->count = new_tx_count;
  1164. vsi->rx_rings[i]->count = new_rx_count;
  1165. }
  1166. goto done;
  1167. }
  1168. /* We can't just free everything and then setup again,
  1169. * because the ISRs in MSI-X mode get passed pointers
  1170. * to the Tx and Rx ring structs.
  1171. */
  1172. /* alloc updated Tx resources */
  1173. if (new_tx_count != vsi->tx_rings[0]->count) {
  1174. netdev_info(netdev,
  1175. "Changing Tx descriptor count from %d to %d.\n",
  1176. vsi->tx_rings[0]->count, new_tx_count);
  1177. tx_rings = kcalloc(vsi->alloc_queue_pairs,
  1178. sizeof(struct i40e_ring), GFP_KERNEL);
  1179. if (!tx_rings) {
  1180. err = -ENOMEM;
  1181. goto done;
  1182. }
  1183. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1184. /* clone ring and setup updated count */
  1185. tx_rings[i] = *vsi->tx_rings[i];
  1186. tx_rings[i].count = new_tx_count;
  1187. /* the desc and bi pointers will be reallocated in the
  1188. * setup call
  1189. */
  1190. tx_rings[i].desc = NULL;
  1191. tx_rings[i].rx_bi = NULL;
  1192. err = i40e_setup_tx_descriptors(&tx_rings[i]);
  1193. if (err) {
  1194. while (i) {
  1195. i--;
  1196. i40e_free_tx_resources(&tx_rings[i]);
  1197. }
  1198. kfree(tx_rings);
  1199. tx_rings = NULL;
  1200. goto done;
  1201. }
  1202. }
  1203. }
  1204. /* alloc updated Rx resources */
  1205. if (new_rx_count != vsi->rx_rings[0]->count) {
  1206. netdev_info(netdev,
  1207. "Changing Rx descriptor count from %d to %d\n",
  1208. vsi->rx_rings[0]->count, new_rx_count);
  1209. rx_rings = kcalloc(vsi->alloc_queue_pairs,
  1210. sizeof(struct i40e_ring), GFP_KERNEL);
  1211. if (!rx_rings) {
  1212. err = -ENOMEM;
  1213. goto free_tx;
  1214. }
  1215. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1216. struct i40e_ring *ring;
  1217. u16 unused;
  1218. /* clone ring and setup updated count */
  1219. rx_rings[i] = *vsi->rx_rings[i];
  1220. rx_rings[i].count = new_rx_count;
  1221. /* the desc and bi pointers will be reallocated in the
  1222. * setup call
  1223. */
  1224. rx_rings[i].desc = NULL;
  1225. rx_rings[i].rx_bi = NULL;
  1226. /* this is to allow wr32 to have something to write to
  1227. * during early allocation of Rx buffers
  1228. */
  1229. rx_rings[i].tail = hw->hw_addr + I40E_PRTGEN_STATUS;
  1230. err = i40e_setup_rx_descriptors(&rx_rings[i]);
  1231. if (err)
  1232. goto rx_unwind;
  1233. /* now allocate the Rx buffers to make sure the OS
  1234. * has enough memory, any failure here means abort
  1235. */
  1236. ring = &rx_rings[i];
  1237. unused = I40E_DESC_UNUSED(ring);
  1238. err = i40e_alloc_rx_buffers(ring, unused);
  1239. rx_unwind:
  1240. if (err) {
  1241. do {
  1242. i40e_free_rx_resources(&rx_rings[i]);
  1243. } while (i--);
  1244. kfree(rx_rings);
  1245. rx_rings = NULL;
  1246. goto free_tx;
  1247. }
  1248. }
  1249. }
  1250. /* Bring interface down, copy in the new ring info,
  1251. * then restore the interface
  1252. */
  1253. i40e_down(vsi);
  1254. if (tx_rings) {
  1255. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1256. i40e_free_tx_resources(vsi->tx_rings[i]);
  1257. *vsi->tx_rings[i] = tx_rings[i];
  1258. }
  1259. kfree(tx_rings);
  1260. tx_rings = NULL;
  1261. }
  1262. if (rx_rings) {
  1263. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1264. i40e_free_rx_resources(vsi->rx_rings[i]);
  1265. /* get the real tail offset */
  1266. rx_rings[i].tail = vsi->rx_rings[i]->tail;
  1267. /* this is to fake out the allocation routine
  1268. * into thinking it has to realloc everything
  1269. * but the recycling logic will let us re-use
  1270. * the buffers allocated above
  1271. */
  1272. rx_rings[i].next_to_use = 0;
  1273. rx_rings[i].next_to_clean = 0;
  1274. rx_rings[i].next_to_alloc = 0;
  1275. /* do a struct copy */
  1276. *vsi->rx_rings[i] = rx_rings[i];
  1277. }
  1278. kfree(rx_rings);
  1279. rx_rings = NULL;
  1280. }
  1281. i40e_up(vsi);
  1282. free_tx:
  1283. /* error cleanup if the Rx allocations failed after getting Tx */
  1284. if (tx_rings) {
  1285. for (i = 0; i < vsi->num_queue_pairs; i++)
  1286. i40e_free_tx_resources(&tx_rings[i]);
  1287. kfree(tx_rings);
  1288. tx_rings = NULL;
  1289. }
  1290. done:
  1291. clear_bit(__I40E_CONFIG_BUSY, &pf->state);
  1292. return err;
  1293. }
  1294. static int i40e_get_sset_count(struct net_device *netdev, int sset)
  1295. {
  1296. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1297. struct i40e_vsi *vsi = np->vsi;
  1298. struct i40e_pf *pf = vsi->back;
  1299. switch (sset) {
  1300. case ETH_SS_TEST:
  1301. return I40E_TEST_LEN;
  1302. case ETH_SS_STATS:
  1303. if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
  1304. int len = I40E_PF_STATS_LEN(netdev);
  1305. if ((pf->lan_veb != I40E_NO_VEB) &&
  1306. (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
  1307. len += I40E_VEB_STATS_TOTAL;
  1308. return len;
  1309. } else {
  1310. return I40E_VSI_STATS_LEN(netdev);
  1311. }
  1312. case ETH_SS_PRIV_FLAGS:
  1313. return I40E_PRIV_FLAGS_STR_LEN +
  1314. (pf->hw.pf_id == 0 ? I40E_GL_PRIV_FLAGS_STR_LEN : 0);
  1315. default:
  1316. return -EOPNOTSUPP;
  1317. }
  1318. }
  1319. static void i40e_get_ethtool_stats(struct net_device *netdev,
  1320. struct ethtool_stats *stats, u64 *data)
  1321. {
  1322. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1323. struct i40e_ring *tx_ring, *rx_ring;
  1324. struct i40e_vsi *vsi = np->vsi;
  1325. struct i40e_pf *pf = vsi->back;
  1326. int i = 0;
  1327. char *p;
  1328. int j;
  1329. struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
  1330. unsigned int start;
  1331. i40e_update_stats(vsi);
  1332. for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
  1333. p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
  1334. data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
  1335. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1336. }
  1337. for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
  1338. p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
  1339. data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
  1340. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1341. }
  1342. #ifdef I40E_FCOE
  1343. for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
  1344. p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
  1345. data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
  1346. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1347. }
  1348. #endif
  1349. rcu_read_lock();
  1350. for (j = 0; j < vsi->num_queue_pairs; j++) {
  1351. tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
  1352. if (!tx_ring)
  1353. continue;
  1354. /* process Tx ring statistics */
  1355. do {
  1356. start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
  1357. data[i] = tx_ring->stats.packets;
  1358. data[i + 1] = tx_ring->stats.bytes;
  1359. } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
  1360. i += 2;
  1361. /* Rx ring is the 2nd half of the queue pair */
  1362. rx_ring = &tx_ring[1];
  1363. do {
  1364. start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
  1365. data[i] = rx_ring->stats.packets;
  1366. data[i + 1] = rx_ring->stats.bytes;
  1367. } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
  1368. i += 2;
  1369. }
  1370. rcu_read_unlock();
  1371. if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
  1372. return;
  1373. if ((pf->lan_veb != I40E_NO_VEB) &&
  1374. (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
  1375. struct i40e_veb *veb = pf->veb[pf->lan_veb];
  1376. for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
  1377. p = (char *)veb;
  1378. p += i40e_gstrings_veb_stats[j].stat_offset;
  1379. data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
  1380. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1381. }
  1382. for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
  1383. data[i++] = veb->tc_stats.tc_tx_packets[j];
  1384. data[i++] = veb->tc_stats.tc_tx_bytes[j];
  1385. data[i++] = veb->tc_stats.tc_rx_packets[j];
  1386. data[i++] = veb->tc_stats.tc_rx_bytes[j];
  1387. }
  1388. }
  1389. for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
  1390. p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
  1391. data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
  1392. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1393. }
  1394. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
  1395. data[i++] = pf->stats.priority_xon_tx[j];
  1396. data[i++] = pf->stats.priority_xoff_tx[j];
  1397. }
  1398. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
  1399. data[i++] = pf->stats.priority_xon_rx[j];
  1400. data[i++] = pf->stats.priority_xoff_rx[j];
  1401. }
  1402. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
  1403. data[i++] = pf->stats.priority_xon_2_xoff[j];
  1404. }
  1405. static void i40e_get_strings(struct net_device *netdev, u32 stringset,
  1406. u8 *data)
  1407. {
  1408. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1409. struct i40e_vsi *vsi = np->vsi;
  1410. struct i40e_pf *pf = vsi->back;
  1411. char *p = (char *)data;
  1412. int i;
  1413. switch (stringset) {
  1414. case ETH_SS_TEST:
  1415. memcpy(data, i40e_gstrings_test,
  1416. I40E_TEST_LEN * ETH_GSTRING_LEN);
  1417. break;
  1418. case ETH_SS_STATS:
  1419. for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
  1420. snprintf(p, ETH_GSTRING_LEN, "%s",
  1421. i40e_gstrings_net_stats[i].stat_string);
  1422. p += ETH_GSTRING_LEN;
  1423. }
  1424. for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
  1425. snprintf(p, ETH_GSTRING_LEN, "%s",
  1426. i40e_gstrings_misc_stats[i].stat_string);
  1427. p += ETH_GSTRING_LEN;
  1428. }
  1429. #ifdef I40E_FCOE
  1430. for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
  1431. snprintf(p, ETH_GSTRING_LEN, "%s",
  1432. i40e_gstrings_fcoe_stats[i].stat_string);
  1433. p += ETH_GSTRING_LEN;
  1434. }
  1435. #endif
  1436. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1437. snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_packets", i);
  1438. p += ETH_GSTRING_LEN;
  1439. snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_bytes", i);
  1440. p += ETH_GSTRING_LEN;
  1441. snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_packets", i);
  1442. p += ETH_GSTRING_LEN;
  1443. snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_bytes", i);
  1444. p += ETH_GSTRING_LEN;
  1445. }
  1446. if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
  1447. return;
  1448. if ((pf->lan_veb != I40E_NO_VEB) &&
  1449. (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
  1450. for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
  1451. snprintf(p, ETH_GSTRING_LEN, "veb.%s",
  1452. i40e_gstrings_veb_stats[i].stat_string);
  1453. p += ETH_GSTRING_LEN;
  1454. }
  1455. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1456. snprintf(p, ETH_GSTRING_LEN,
  1457. "veb.tc_%d_tx_packets", i);
  1458. p += ETH_GSTRING_LEN;
  1459. snprintf(p, ETH_GSTRING_LEN,
  1460. "veb.tc_%d_tx_bytes", i);
  1461. p += ETH_GSTRING_LEN;
  1462. snprintf(p, ETH_GSTRING_LEN,
  1463. "veb.tc_%d_rx_packets", i);
  1464. p += ETH_GSTRING_LEN;
  1465. snprintf(p, ETH_GSTRING_LEN,
  1466. "veb.tc_%d_rx_bytes", i);
  1467. p += ETH_GSTRING_LEN;
  1468. }
  1469. }
  1470. for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
  1471. snprintf(p, ETH_GSTRING_LEN, "port.%s",
  1472. i40e_gstrings_stats[i].stat_string);
  1473. p += ETH_GSTRING_LEN;
  1474. }
  1475. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  1476. snprintf(p, ETH_GSTRING_LEN,
  1477. "port.tx_priority_%d_xon", i);
  1478. p += ETH_GSTRING_LEN;
  1479. snprintf(p, ETH_GSTRING_LEN,
  1480. "port.tx_priority_%d_xoff", i);
  1481. p += ETH_GSTRING_LEN;
  1482. }
  1483. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  1484. snprintf(p, ETH_GSTRING_LEN,
  1485. "port.rx_priority_%d_xon", i);
  1486. p += ETH_GSTRING_LEN;
  1487. snprintf(p, ETH_GSTRING_LEN,
  1488. "port.rx_priority_%d_xoff", i);
  1489. p += ETH_GSTRING_LEN;
  1490. }
  1491. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  1492. snprintf(p, ETH_GSTRING_LEN,
  1493. "port.rx_priority_%d_xon_2_xoff", i);
  1494. p += ETH_GSTRING_LEN;
  1495. }
  1496. /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
  1497. break;
  1498. case ETH_SS_PRIV_FLAGS:
  1499. memcpy(data, i40e_priv_flags_strings,
  1500. I40E_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN);
  1501. data += I40E_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN;
  1502. if (pf->hw.pf_id == 0)
  1503. memcpy(data, i40e_gl_priv_flags_strings,
  1504. I40E_GL_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN);
  1505. break;
  1506. default:
  1507. break;
  1508. }
  1509. }
  1510. static int i40e_get_ts_info(struct net_device *dev,
  1511. struct ethtool_ts_info *info)
  1512. {
  1513. struct i40e_pf *pf = i40e_netdev_to_pf(dev);
  1514. /* only report HW timestamping if PTP is enabled */
  1515. if (!(pf->flags & I40E_FLAG_PTP))
  1516. return ethtool_op_get_ts_info(dev, info);
  1517. info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
  1518. SOF_TIMESTAMPING_RX_SOFTWARE |
  1519. SOF_TIMESTAMPING_SOFTWARE |
  1520. SOF_TIMESTAMPING_TX_HARDWARE |
  1521. SOF_TIMESTAMPING_RX_HARDWARE |
  1522. SOF_TIMESTAMPING_RAW_HARDWARE;
  1523. if (pf->ptp_clock)
  1524. info->phc_index = ptp_clock_index(pf->ptp_clock);
  1525. else
  1526. info->phc_index = -1;
  1527. info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
  1528. info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
  1529. BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
  1530. BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
  1531. BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ);
  1532. if (pf->flags & I40E_FLAG_PTP_L4_CAPABLE)
  1533. info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
  1534. BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
  1535. BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
  1536. BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
  1537. BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
  1538. BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
  1539. BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
  1540. BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
  1541. return 0;
  1542. }
  1543. static int i40e_link_test(struct net_device *netdev, u64 *data)
  1544. {
  1545. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1546. struct i40e_pf *pf = np->vsi->back;
  1547. i40e_status status;
  1548. bool link_up = false;
  1549. netif_info(pf, hw, netdev, "link test\n");
  1550. status = i40e_get_link_status(&pf->hw, &link_up);
  1551. if (status) {
  1552. netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
  1553. *data = 1;
  1554. return *data;
  1555. }
  1556. if (link_up)
  1557. *data = 0;
  1558. else
  1559. *data = 1;
  1560. return *data;
  1561. }
  1562. static int i40e_reg_test(struct net_device *netdev, u64 *data)
  1563. {
  1564. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1565. struct i40e_pf *pf = np->vsi->back;
  1566. netif_info(pf, hw, netdev, "register test\n");
  1567. *data = i40e_diag_reg_test(&pf->hw);
  1568. return *data;
  1569. }
  1570. static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
  1571. {
  1572. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1573. struct i40e_pf *pf = np->vsi->back;
  1574. netif_info(pf, hw, netdev, "eeprom test\n");
  1575. *data = i40e_diag_eeprom_test(&pf->hw);
  1576. /* forcebly clear the NVM Update state machine */
  1577. pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
  1578. return *data;
  1579. }
  1580. static int i40e_intr_test(struct net_device *netdev, u64 *data)
  1581. {
  1582. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1583. struct i40e_pf *pf = np->vsi->back;
  1584. u16 swc_old = pf->sw_int_count;
  1585. netif_info(pf, hw, netdev, "interrupt test\n");
  1586. wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
  1587. (I40E_PFINT_DYN_CTL0_INTENA_MASK |
  1588. I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
  1589. I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
  1590. I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
  1591. I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
  1592. usleep_range(1000, 2000);
  1593. *data = (swc_old == pf->sw_int_count);
  1594. return *data;
  1595. }
  1596. static inline bool i40e_active_vfs(struct i40e_pf *pf)
  1597. {
  1598. struct i40e_vf *vfs = pf->vf;
  1599. int i;
  1600. for (i = 0; i < pf->num_alloc_vfs; i++)
  1601. if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
  1602. return true;
  1603. return false;
  1604. }
  1605. static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
  1606. {
  1607. return !!i40e_find_vsi_by_type(pf, I40E_VSI_VMDQ2);
  1608. }
  1609. static void i40e_diag_test(struct net_device *netdev,
  1610. struct ethtool_test *eth_test, u64 *data)
  1611. {
  1612. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1613. bool if_running = netif_running(netdev);
  1614. struct i40e_pf *pf = np->vsi->back;
  1615. if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
  1616. /* Offline tests */
  1617. netif_info(pf, drv, netdev, "offline testing starting\n");
  1618. set_bit(__I40E_TESTING, &pf->state);
  1619. if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
  1620. dev_warn(&pf->pdev->dev,
  1621. "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
  1622. data[I40E_ETH_TEST_REG] = 1;
  1623. data[I40E_ETH_TEST_EEPROM] = 1;
  1624. data[I40E_ETH_TEST_INTR] = 1;
  1625. data[I40E_ETH_TEST_LINK] = 1;
  1626. eth_test->flags |= ETH_TEST_FL_FAILED;
  1627. clear_bit(__I40E_TESTING, &pf->state);
  1628. goto skip_ol_tests;
  1629. }
  1630. /* If the device is online then take it offline */
  1631. if (if_running)
  1632. /* indicate we're in test mode */
  1633. i40e_close(netdev);
  1634. else
  1635. /* This reset does not affect link - if it is
  1636. * changed to a type of reset that does affect
  1637. * link then the following link test would have
  1638. * to be moved to before the reset
  1639. */
  1640. i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
  1641. if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
  1642. eth_test->flags |= ETH_TEST_FL_FAILED;
  1643. if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
  1644. eth_test->flags |= ETH_TEST_FL_FAILED;
  1645. if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
  1646. eth_test->flags |= ETH_TEST_FL_FAILED;
  1647. /* run reg test last, a reset is required after it */
  1648. if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
  1649. eth_test->flags |= ETH_TEST_FL_FAILED;
  1650. clear_bit(__I40E_TESTING, &pf->state);
  1651. i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
  1652. if (if_running)
  1653. i40e_open(netdev);
  1654. } else {
  1655. /* Online tests */
  1656. netif_info(pf, drv, netdev, "online testing starting\n");
  1657. if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
  1658. eth_test->flags |= ETH_TEST_FL_FAILED;
  1659. /* Offline only tests, not run in online; pass by default */
  1660. data[I40E_ETH_TEST_REG] = 0;
  1661. data[I40E_ETH_TEST_EEPROM] = 0;
  1662. data[I40E_ETH_TEST_INTR] = 0;
  1663. }
  1664. skip_ol_tests:
  1665. netif_info(pf, drv, netdev, "testing finished\n");
  1666. }
  1667. static void i40e_get_wol(struct net_device *netdev,
  1668. struct ethtool_wolinfo *wol)
  1669. {
  1670. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1671. struct i40e_pf *pf = np->vsi->back;
  1672. struct i40e_hw *hw = &pf->hw;
  1673. u16 wol_nvm_bits;
  1674. /* NVM bit on means WoL disabled for the port */
  1675. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  1676. if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
  1677. wol->supported = 0;
  1678. wol->wolopts = 0;
  1679. } else {
  1680. wol->supported = WAKE_MAGIC;
  1681. wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
  1682. }
  1683. }
  1684. /**
  1685. * i40e_set_wol - set the WakeOnLAN configuration
  1686. * @netdev: the netdev in question
  1687. * @wol: the ethtool WoL setting data
  1688. **/
  1689. static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  1690. {
  1691. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1692. struct i40e_pf *pf = np->vsi->back;
  1693. struct i40e_vsi *vsi = np->vsi;
  1694. struct i40e_hw *hw = &pf->hw;
  1695. u16 wol_nvm_bits;
  1696. /* WoL not supported if this isn't the controlling PF on the port */
  1697. if (hw->partition_id != 1) {
  1698. i40e_partition_setting_complaint(pf);
  1699. return -EOPNOTSUPP;
  1700. }
  1701. if (vsi != pf->vsi[pf->lan_vsi])
  1702. return -EOPNOTSUPP;
  1703. /* NVM bit on means WoL disabled for the port */
  1704. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  1705. if (BIT(hw->port) & wol_nvm_bits)
  1706. return -EOPNOTSUPP;
  1707. /* only magic packet is supported */
  1708. if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
  1709. return -EOPNOTSUPP;
  1710. /* is this a new value? */
  1711. if (pf->wol_en != !!wol->wolopts) {
  1712. pf->wol_en = !!wol->wolopts;
  1713. device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
  1714. }
  1715. return 0;
  1716. }
  1717. static int i40e_set_phys_id(struct net_device *netdev,
  1718. enum ethtool_phys_id_state state)
  1719. {
  1720. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1721. i40e_status ret = 0;
  1722. struct i40e_pf *pf = np->vsi->back;
  1723. struct i40e_hw *hw = &pf->hw;
  1724. int blink_freq = 2;
  1725. u16 temp_status;
  1726. switch (state) {
  1727. case ETHTOOL_ID_ACTIVE:
  1728. if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS)) {
  1729. pf->led_status = i40e_led_get(hw);
  1730. } else {
  1731. i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL, NULL);
  1732. ret = i40e_led_get_phy(hw, &temp_status,
  1733. &pf->phy_led_val);
  1734. pf->led_status = temp_status;
  1735. }
  1736. return blink_freq;
  1737. case ETHTOOL_ID_ON:
  1738. if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS))
  1739. i40e_led_set(hw, 0xf, false);
  1740. else
  1741. ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
  1742. break;
  1743. case ETHTOOL_ID_OFF:
  1744. if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS))
  1745. i40e_led_set(hw, 0x0, false);
  1746. else
  1747. ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
  1748. break;
  1749. case ETHTOOL_ID_INACTIVE:
  1750. if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS)) {
  1751. i40e_led_set(hw, pf->led_status, false);
  1752. } else {
  1753. ret = i40e_led_set_phy(hw, false, pf->led_status,
  1754. (pf->phy_led_val |
  1755. I40E_PHY_LED_MODE_ORIG));
  1756. i40e_aq_set_phy_debug(hw, 0, NULL);
  1757. }
  1758. break;
  1759. default:
  1760. break;
  1761. }
  1762. if (ret)
  1763. return -ENOENT;
  1764. else
  1765. return 0;
  1766. }
  1767. /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
  1768. * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
  1769. * 125us (8000 interrupts per second) == ITR(62)
  1770. */
  1771. /**
  1772. * __i40e_get_coalesce - get per-queue coalesce settings
  1773. * @netdev: the netdev to check
  1774. * @ec: ethtool coalesce data structure
  1775. * @queue: which queue to pick
  1776. *
  1777. * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
  1778. * are per queue. If queue is <0 then we default to queue 0 as the
  1779. * representative value.
  1780. **/
  1781. static int __i40e_get_coalesce(struct net_device *netdev,
  1782. struct ethtool_coalesce *ec,
  1783. int queue)
  1784. {
  1785. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1786. struct i40e_ring *rx_ring, *tx_ring;
  1787. struct i40e_vsi *vsi = np->vsi;
  1788. ec->tx_max_coalesced_frames_irq = vsi->work_limit;
  1789. ec->rx_max_coalesced_frames_irq = vsi->work_limit;
  1790. /* rx and tx usecs has per queue value. If user doesn't specify the queue,
  1791. * return queue 0's value to represent.
  1792. */
  1793. if (queue < 0) {
  1794. queue = 0;
  1795. } else if (queue >= vsi->num_queue_pairs) {
  1796. return -EINVAL;
  1797. }
  1798. rx_ring = vsi->rx_rings[queue];
  1799. tx_ring = vsi->tx_rings[queue];
  1800. if (ITR_IS_DYNAMIC(rx_ring->rx_itr_setting))
  1801. ec->use_adaptive_rx_coalesce = 1;
  1802. if (ITR_IS_DYNAMIC(tx_ring->tx_itr_setting))
  1803. ec->use_adaptive_tx_coalesce = 1;
  1804. ec->rx_coalesce_usecs = rx_ring->rx_itr_setting & ~I40E_ITR_DYNAMIC;
  1805. ec->tx_coalesce_usecs = tx_ring->tx_itr_setting & ~I40E_ITR_DYNAMIC;
  1806. /* we use the _usecs_high to store/set the interrupt rate limit
  1807. * that the hardware supports, that almost but not quite
  1808. * fits the original intent of the ethtool variable,
  1809. * the rx_coalesce_usecs_high limits total interrupts
  1810. * per second from both tx/rx sources.
  1811. */
  1812. ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
  1813. ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
  1814. return 0;
  1815. }
  1816. /**
  1817. * i40e_get_coalesce - get a netdev's coalesce settings
  1818. * @netdev: the netdev to check
  1819. * @ec: ethtool coalesce data structure
  1820. *
  1821. * Gets the coalesce settings for a particular netdev. Note that if user has
  1822. * modified per-queue settings, this only guarantees to represent queue 0. See
  1823. * __i40e_get_coalesce for more details.
  1824. **/
  1825. static int i40e_get_coalesce(struct net_device *netdev,
  1826. struct ethtool_coalesce *ec)
  1827. {
  1828. return __i40e_get_coalesce(netdev, ec, -1);
  1829. }
  1830. /**
  1831. * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue
  1832. * @netdev: netdev structure
  1833. * @ec: ethtool's coalesce settings
  1834. * @queue: the particular queue to read
  1835. *
  1836. * Will read a specific queue's coalesce settings
  1837. **/
  1838. static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
  1839. struct ethtool_coalesce *ec)
  1840. {
  1841. return __i40e_get_coalesce(netdev, ec, queue);
  1842. }
  1843. /**
  1844. * i40e_set_itr_per_queue - set ITR values for specific queue
  1845. * @vsi: the VSI to set values for
  1846. * @ec: coalesce settings from ethtool
  1847. * @queue: the queue to modify
  1848. *
  1849. * Change the ITR settings for a specific queue.
  1850. **/
  1851. static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
  1852. struct ethtool_coalesce *ec,
  1853. int queue)
  1854. {
  1855. struct i40e_pf *pf = vsi->back;
  1856. struct i40e_hw *hw = &pf->hw;
  1857. struct i40e_q_vector *q_vector;
  1858. u16 vector, intrl;
  1859. intrl = INTRL_USEC_TO_REG(vsi->int_rate_limit);
  1860. vsi->rx_rings[queue]->rx_itr_setting = ec->rx_coalesce_usecs;
  1861. vsi->tx_rings[queue]->tx_itr_setting = ec->tx_coalesce_usecs;
  1862. if (ec->use_adaptive_rx_coalesce)
  1863. vsi->rx_rings[queue]->rx_itr_setting |= I40E_ITR_DYNAMIC;
  1864. else
  1865. vsi->rx_rings[queue]->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
  1866. if (ec->use_adaptive_tx_coalesce)
  1867. vsi->tx_rings[queue]->tx_itr_setting |= I40E_ITR_DYNAMIC;
  1868. else
  1869. vsi->tx_rings[queue]->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
  1870. q_vector = vsi->rx_rings[queue]->q_vector;
  1871. q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[queue]->rx_itr_setting);
  1872. vector = vsi->base_vector + q_vector->v_idx;
  1873. wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), q_vector->rx.itr);
  1874. q_vector = vsi->tx_rings[queue]->q_vector;
  1875. q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[queue]->tx_itr_setting);
  1876. vector = vsi->base_vector + q_vector->v_idx;
  1877. wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), q_vector->tx.itr);
  1878. wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
  1879. i40e_flush(hw);
  1880. }
  1881. /**
  1882. * __i40e_set_coalesce - set coalesce settings for particular queue
  1883. * @netdev: the netdev to change
  1884. * @ec: ethtool coalesce settings
  1885. * @queue: the queue to change
  1886. *
  1887. * Sets the coalesce settings for a particular queue.
  1888. **/
  1889. static int __i40e_set_coalesce(struct net_device *netdev,
  1890. struct ethtool_coalesce *ec,
  1891. int queue)
  1892. {
  1893. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1894. struct i40e_vsi *vsi = np->vsi;
  1895. struct i40e_pf *pf = vsi->back;
  1896. int i;
  1897. if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
  1898. vsi->work_limit = ec->tx_max_coalesced_frames_irq;
  1899. /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
  1900. if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
  1901. netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
  1902. return -EINVAL;
  1903. }
  1904. if (ec->rx_coalesce_usecs_high >= INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
  1905. netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-235\n");
  1906. return -EINVAL;
  1907. }
  1908. if (ec->rx_coalesce_usecs == 0) {
  1909. if (ec->use_adaptive_rx_coalesce)
  1910. netif_info(pf, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
  1911. } else if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
  1912. (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
  1913. netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
  1914. return -EINVAL;
  1915. }
  1916. vsi->int_rate_limit = ec->rx_coalesce_usecs_high;
  1917. if (ec->tx_coalesce_usecs == 0) {
  1918. if (ec->use_adaptive_tx_coalesce)
  1919. netif_info(pf, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
  1920. } else if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
  1921. (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
  1922. netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
  1923. return -EINVAL;
  1924. }
  1925. /* rx and tx usecs has per queue value. If user doesn't specify the queue,
  1926. * apply to all queues.
  1927. */
  1928. if (queue < 0) {
  1929. for (i = 0; i < vsi->num_queue_pairs; i++)
  1930. i40e_set_itr_per_queue(vsi, ec, i);
  1931. } else if (queue < vsi->num_queue_pairs) {
  1932. i40e_set_itr_per_queue(vsi, ec, queue);
  1933. } else {
  1934. netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
  1935. vsi->num_queue_pairs - 1);
  1936. return -EINVAL;
  1937. }
  1938. return 0;
  1939. }
  1940. /**
  1941. * i40e_set_coalesce - set coalesce settings for every queue on the netdev
  1942. * @netdev: the netdev to change
  1943. * @ec: ethtool coalesce settings
  1944. *
  1945. * This will set each queue to the same coalesce settings.
  1946. **/
  1947. static int i40e_set_coalesce(struct net_device *netdev,
  1948. struct ethtool_coalesce *ec)
  1949. {
  1950. return __i40e_set_coalesce(netdev, ec, -1);
  1951. }
  1952. /**
  1953. * i40e_set_per_queue_coalesce - set specific queue's coalesce settings
  1954. * @netdev: the netdev to change
  1955. * @ec: ethtool's coalesce settings
  1956. * @queue: the queue to change
  1957. *
  1958. * Sets the specified queue's coalesce settings.
  1959. **/
  1960. static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
  1961. struct ethtool_coalesce *ec)
  1962. {
  1963. return __i40e_set_coalesce(netdev, ec, queue);
  1964. }
  1965. /**
  1966. * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
  1967. * @pf: pointer to the physical function struct
  1968. * @cmd: ethtool rxnfc command
  1969. *
  1970. * Returns Success if the flow is supported, else Invalid Input.
  1971. **/
  1972. static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
  1973. {
  1974. struct i40e_hw *hw = &pf->hw;
  1975. u8 flow_pctype = 0;
  1976. u64 i_set = 0;
  1977. cmd->data = 0;
  1978. switch (cmd->flow_type) {
  1979. case TCP_V4_FLOW:
  1980. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
  1981. break;
  1982. case UDP_V4_FLOW:
  1983. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
  1984. break;
  1985. case TCP_V6_FLOW:
  1986. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
  1987. break;
  1988. case UDP_V6_FLOW:
  1989. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
  1990. break;
  1991. case SCTP_V4_FLOW:
  1992. case AH_ESP_V4_FLOW:
  1993. case AH_V4_FLOW:
  1994. case ESP_V4_FLOW:
  1995. case IPV4_FLOW:
  1996. case SCTP_V6_FLOW:
  1997. case AH_ESP_V6_FLOW:
  1998. case AH_V6_FLOW:
  1999. case ESP_V6_FLOW:
  2000. case IPV6_FLOW:
  2001. /* Default is src/dest for IP, no matter the L4 hashing */
  2002. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  2003. break;
  2004. default:
  2005. return -EINVAL;
  2006. }
  2007. /* Read flow based hash input set register */
  2008. if (flow_pctype) {
  2009. i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
  2010. flow_pctype)) |
  2011. ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
  2012. flow_pctype)) << 32);
  2013. }
  2014. /* Process bits of hash input set */
  2015. if (i_set) {
  2016. if (i_set & I40E_L4_SRC_MASK)
  2017. cmd->data |= RXH_L4_B_0_1;
  2018. if (i_set & I40E_L4_DST_MASK)
  2019. cmd->data |= RXH_L4_B_2_3;
  2020. if (cmd->flow_type == TCP_V4_FLOW ||
  2021. cmd->flow_type == UDP_V4_FLOW) {
  2022. if (i_set & I40E_L3_SRC_MASK)
  2023. cmd->data |= RXH_IP_SRC;
  2024. if (i_set & I40E_L3_DST_MASK)
  2025. cmd->data |= RXH_IP_DST;
  2026. } else if (cmd->flow_type == TCP_V6_FLOW ||
  2027. cmd->flow_type == UDP_V6_FLOW) {
  2028. if (i_set & I40E_L3_V6_SRC_MASK)
  2029. cmd->data |= RXH_IP_SRC;
  2030. if (i_set & I40E_L3_V6_DST_MASK)
  2031. cmd->data |= RXH_IP_DST;
  2032. }
  2033. }
  2034. return 0;
  2035. }
  2036. /**
  2037. * i40e_get_ethtool_fdir_all - Populates the rule count of a command
  2038. * @pf: Pointer to the physical function struct
  2039. * @cmd: The command to get or set Rx flow classification rules
  2040. * @rule_locs: Array of used rule locations
  2041. *
  2042. * This function populates both the total and actual rule count of
  2043. * the ethtool flow classification command
  2044. *
  2045. * Returns 0 on success or -EMSGSIZE if entry not found
  2046. **/
  2047. static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
  2048. struct ethtool_rxnfc *cmd,
  2049. u32 *rule_locs)
  2050. {
  2051. struct i40e_fdir_filter *rule;
  2052. struct hlist_node *node2;
  2053. int cnt = 0;
  2054. /* report total rule count */
  2055. cmd->data = i40e_get_fd_cnt_all(pf);
  2056. hlist_for_each_entry_safe(rule, node2,
  2057. &pf->fdir_filter_list, fdir_node) {
  2058. if (cnt == cmd->rule_cnt)
  2059. return -EMSGSIZE;
  2060. rule_locs[cnt] = rule->fd_id;
  2061. cnt++;
  2062. }
  2063. cmd->rule_cnt = cnt;
  2064. return 0;
  2065. }
  2066. /**
  2067. * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
  2068. * @pf: Pointer to the physical function struct
  2069. * @cmd: The command to get or set Rx flow classification rules
  2070. *
  2071. * This function looks up a filter based on the Rx flow classification
  2072. * command and fills the flow spec info for it if found
  2073. *
  2074. * Returns 0 on success or -EINVAL if filter not found
  2075. **/
  2076. static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
  2077. struct ethtool_rxnfc *cmd)
  2078. {
  2079. struct ethtool_rx_flow_spec *fsp =
  2080. (struct ethtool_rx_flow_spec *)&cmd->fs;
  2081. struct i40e_fdir_filter *rule = NULL;
  2082. struct hlist_node *node2;
  2083. hlist_for_each_entry_safe(rule, node2,
  2084. &pf->fdir_filter_list, fdir_node) {
  2085. if (fsp->location <= rule->fd_id)
  2086. break;
  2087. }
  2088. if (!rule || fsp->location != rule->fd_id)
  2089. return -EINVAL;
  2090. fsp->flow_type = rule->flow_type;
  2091. if (fsp->flow_type == IP_USER_FLOW) {
  2092. fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
  2093. fsp->h_u.usr_ip4_spec.proto = 0;
  2094. fsp->m_u.usr_ip4_spec.proto = 0;
  2095. }
  2096. /* Reverse the src and dest notion, since the HW views them from
  2097. * Tx perspective where as the user expects it from Rx filter view.
  2098. */
  2099. fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
  2100. fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
  2101. fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
  2102. fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
  2103. if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
  2104. fsp->ring_cookie = RX_CLS_FLOW_DISC;
  2105. else
  2106. fsp->ring_cookie = rule->q_index;
  2107. if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
  2108. struct i40e_vsi *vsi;
  2109. vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
  2110. if (vsi && vsi->type == I40E_VSI_SRIOV) {
  2111. fsp->h_ext.data[1] = htonl(vsi->vf_id);
  2112. fsp->m_ext.data[1] = htonl(0x1);
  2113. }
  2114. }
  2115. return 0;
  2116. }
  2117. /**
  2118. * i40e_get_rxnfc - command to get RX flow classification rules
  2119. * @netdev: network interface device structure
  2120. * @cmd: ethtool rxnfc command
  2121. *
  2122. * Returns Success if the command is supported.
  2123. **/
  2124. static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
  2125. u32 *rule_locs)
  2126. {
  2127. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2128. struct i40e_vsi *vsi = np->vsi;
  2129. struct i40e_pf *pf = vsi->back;
  2130. int ret = -EOPNOTSUPP;
  2131. switch (cmd->cmd) {
  2132. case ETHTOOL_GRXRINGS:
  2133. cmd->data = vsi->num_queue_pairs;
  2134. ret = 0;
  2135. break;
  2136. case ETHTOOL_GRXFH:
  2137. ret = i40e_get_rss_hash_opts(pf, cmd);
  2138. break;
  2139. case ETHTOOL_GRXCLSRLCNT:
  2140. cmd->rule_cnt = pf->fdir_pf_active_filters;
  2141. /* report total rule count */
  2142. cmd->data = i40e_get_fd_cnt_all(pf);
  2143. ret = 0;
  2144. break;
  2145. case ETHTOOL_GRXCLSRULE:
  2146. ret = i40e_get_ethtool_fdir_entry(pf, cmd);
  2147. break;
  2148. case ETHTOOL_GRXCLSRLALL:
  2149. ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
  2150. break;
  2151. default:
  2152. break;
  2153. }
  2154. return ret;
  2155. }
  2156. /**
  2157. * i40e_get_rss_hash_bits - Read RSS Hash bits from register
  2158. * @nfc: pointer to user request
  2159. * @i_setc bits currently set
  2160. *
  2161. * Returns value of bits to be set per user request
  2162. **/
  2163. static u64 i40e_get_rss_hash_bits(struct ethtool_rxnfc *nfc, u64 i_setc)
  2164. {
  2165. u64 i_set = i_setc;
  2166. u64 src_l3 = 0, dst_l3 = 0;
  2167. if (nfc->data & RXH_L4_B_0_1)
  2168. i_set |= I40E_L4_SRC_MASK;
  2169. else
  2170. i_set &= ~I40E_L4_SRC_MASK;
  2171. if (nfc->data & RXH_L4_B_2_3)
  2172. i_set |= I40E_L4_DST_MASK;
  2173. else
  2174. i_set &= ~I40E_L4_DST_MASK;
  2175. if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) {
  2176. src_l3 = I40E_L3_V6_SRC_MASK;
  2177. dst_l3 = I40E_L3_V6_DST_MASK;
  2178. } else if (nfc->flow_type == TCP_V4_FLOW ||
  2179. nfc->flow_type == UDP_V4_FLOW) {
  2180. src_l3 = I40E_L3_SRC_MASK;
  2181. dst_l3 = I40E_L3_DST_MASK;
  2182. } else {
  2183. /* Any other flow type are not supported here */
  2184. return i_set;
  2185. }
  2186. if (nfc->data & RXH_IP_SRC)
  2187. i_set |= src_l3;
  2188. else
  2189. i_set &= ~src_l3;
  2190. if (nfc->data & RXH_IP_DST)
  2191. i_set |= dst_l3;
  2192. else
  2193. i_set &= ~dst_l3;
  2194. return i_set;
  2195. }
  2196. /**
  2197. * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
  2198. * @pf: pointer to the physical function struct
  2199. * @cmd: ethtool rxnfc command
  2200. *
  2201. * Returns Success if the flow input set is supported.
  2202. **/
  2203. static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
  2204. {
  2205. struct i40e_hw *hw = &pf->hw;
  2206. u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
  2207. ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
  2208. u8 flow_pctype = 0;
  2209. u64 i_set, i_setc;
  2210. /* RSS does not support anything other than hashing
  2211. * to queues on src and dst IPs and ports
  2212. */
  2213. if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
  2214. RXH_L4_B_0_1 | RXH_L4_B_2_3))
  2215. return -EINVAL;
  2216. switch (nfc->flow_type) {
  2217. case TCP_V4_FLOW:
  2218. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
  2219. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2220. hena |=
  2221. BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
  2222. break;
  2223. case TCP_V6_FLOW:
  2224. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
  2225. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2226. hena |=
  2227. BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
  2228. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2229. hena |=
  2230. BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
  2231. break;
  2232. case UDP_V4_FLOW:
  2233. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
  2234. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2235. hena |=
  2236. BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
  2237. BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
  2238. hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
  2239. break;
  2240. case UDP_V6_FLOW:
  2241. flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
  2242. if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
  2243. hena |=
  2244. BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
  2245. BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
  2246. hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
  2247. break;
  2248. case AH_ESP_V4_FLOW:
  2249. case AH_V4_FLOW:
  2250. case ESP_V4_FLOW:
  2251. case SCTP_V4_FLOW:
  2252. if ((nfc->data & RXH_L4_B_0_1) ||
  2253. (nfc->data & RXH_L4_B_2_3))
  2254. return -EINVAL;
  2255. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
  2256. break;
  2257. case AH_ESP_V6_FLOW:
  2258. case AH_V6_FLOW:
  2259. case ESP_V6_FLOW:
  2260. case SCTP_V6_FLOW:
  2261. if ((nfc->data & RXH_L4_B_0_1) ||
  2262. (nfc->data & RXH_L4_B_2_3))
  2263. return -EINVAL;
  2264. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
  2265. break;
  2266. case IPV4_FLOW:
  2267. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
  2268. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
  2269. break;
  2270. case IPV6_FLOW:
  2271. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
  2272. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
  2273. break;
  2274. default:
  2275. return -EINVAL;
  2276. }
  2277. if (flow_pctype) {
  2278. i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
  2279. flow_pctype)) |
  2280. ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
  2281. flow_pctype)) << 32);
  2282. i_set = i40e_get_rss_hash_bits(nfc, i_setc);
  2283. i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_pctype),
  2284. (u32)i_set);
  2285. i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_pctype),
  2286. (u32)(i_set >> 32));
  2287. hena |= BIT_ULL(flow_pctype);
  2288. }
  2289. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
  2290. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
  2291. i40e_flush(hw);
  2292. return 0;
  2293. }
  2294. /**
  2295. * i40e_match_fdir_input_set - Match a new filter against an existing one
  2296. * @rule: The filter already added
  2297. * @input: The new filter to comapre against
  2298. *
  2299. * Returns true if the two input set match
  2300. **/
  2301. static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
  2302. struct i40e_fdir_filter *input)
  2303. {
  2304. if ((rule->dst_ip[0] != input->dst_ip[0]) ||
  2305. (rule->src_ip[0] != input->src_ip[0]) ||
  2306. (rule->dst_port != input->dst_port) ||
  2307. (rule->src_port != input->src_port))
  2308. return false;
  2309. return true;
  2310. }
  2311. /**
  2312. * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
  2313. * @vsi: Pointer to the targeted VSI
  2314. * @input: The filter to update or NULL to indicate deletion
  2315. * @sw_idx: Software index to the filter
  2316. * @cmd: The command to get or set Rx flow classification rules
  2317. *
  2318. * This function updates (or deletes) a Flow Director entry from
  2319. * the hlist of the corresponding PF
  2320. *
  2321. * Returns 0 on success
  2322. **/
  2323. static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
  2324. struct i40e_fdir_filter *input,
  2325. u16 sw_idx,
  2326. struct ethtool_rxnfc *cmd)
  2327. {
  2328. struct i40e_fdir_filter *rule, *parent;
  2329. struct i40e_pf *pf = vsi->back;
  2330. struct hlist_node *node2;
  2331. int err = -EINVAL;
  2332. parent = NULL;
  2333. rule = NULL;
  2334. hlist_for_each_entry_safe(rule, node2,
  2335. &pf->fdir_filter_list, fdir_node) {
  2336. /* hash found, or no matching entry */
  2337. if (rule->fd_id >= sw_idx)
  2338. break;
  2339. parent = rule;
  2340. }
  2341. /* if there is an old rule occupying our place remove it */
  2342. if (rule && (rule->fd_id == sw_idx)) {
  2343. if (input && !i40e_match_fdir_input_set(rule, input))
  2344. err = i40e_add_del_fdir(vsi, rule, false);
  2345. else if (!input)
  2346. err = i40e_add_del_fdir(vsi, rule, false);
  2347. hlist_del(&rule->fdir_node);
  2348. kfree(rule);
  2349. pf->fdir_pf_active_filters--;
  2350. }
  2351. /* If no input this was a delete, err should be 0 if a rule was
  2352. * successfully found and removed from the list else -EINVAL
  2353. */
  2354. if (!input)
  2355. return err;
  2356. /* initialize node and set software index */
  2357. INIT_HLIST_NODE(&input->fdir_node);
  2358. /* add filter to the list */
  2359. if (parent)
  2360. hlist_add_behind(&input->fdir_node, &parent->fdir_node);
  2361. else
  2362. hlist_add_head(&input->fdir_node,
  2363. &pf->fdir_filter_list);
  2364. /* update counts */
  2365. pf->fdir_pf_active_filters++;
  2366. return 0;
  2367. }
  2368. /**
  2369. * i40e_del_fdir_entry - Deletes a Flow Director filter entry
  2370. * @vsi: Pointer to the targeted VSI
  2371. * @cmd: The command to get or set Rx flow classification rules
  2372. *
  2373. * The function removes a Flow Director filter entry from the
  2374. * hlist of the corresponding PF
  2375. *
  2376. * Returns 0 on success
  2377. */
  2378. static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
  2379. struct ethtool_rxnfc *cmd)
  2380. {
  2381. struct ethtool_rx_flow_spec *fsp =
  2382. (struct ethtool_rx_flow_spec *)&cmd->fs;
  2383. struct i40e_pf *pf = vsi->back;
  2384. int ret = 0;
  2385. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  2386. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  2387. return -EBUSY;
  2388. if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
  2389. return -EBUSY;
  2390. ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
  2391. i40e_fdir_check_and_reenable(pf);
  2392. return ret;
  2393. }
  2394. /**
  2395. * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
  2396. * @vsi: pointer to the targeted VSI
  2397. * @cmd: command to get or set RX flow classification rules
  2398. *
  2399. * Add Flow Director filters for a specific flow spec based on their
  2400. * protocol. Returns 0 if the filters were successfully added.
  2401. **/
  2402. static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
  2403. struct ethtool_rxnfc *cmd)
  2404. {
  2405. struct ethtool_rx_flow_spec *fsp;
  2406. struct i40e_fdir_filter *input;
  2407. struct i40e_pf *pf;
  2408. int ret = -EINVAL;
  2409. u16 vf_id;
  2410. if (!vsi)
  2411. return -EINVAL;
  2412. pf = vsi->back;
  2413. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  2414. return -EOPNOTSUPP;
  2415. if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
  2416. return -ENOSPC;
  2417. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  2418. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  2419. return -EBUSY;
  2420. if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
  2421. return -EBUSY;
  2422. fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
  2423. if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
  2424. pf->hw.func_caps.fd_filters_guaranteed)) {
  2425. return -EINVAL;
  2426. }
  2427. if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
  2428. (fsp->ring_cookie >= vsi->num_queue_pairs))
  2429. return -EINVAL;
  2430. input = kzalloc(sizeof(*input), GFP_KERNEL);
  2431. if (!input)
  2432. return -ENOMEM;
  2433. input->fd_id = fsp->location;
  2434. if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
  2435. input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
  2436. else
  2437. input->dest_ctl =
  2438. I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
  2439. input->q_index = fsp->ring_cookie;
  2440. input->flex_off = 0;
  2441. input->pctype = 0;
  2442. input->dest_vsi = vsi->id;
  2443. input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
  2444. input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
  2445. input->flow_type = fsp->flow_type;
  2446. input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
  2447. /* Reverse the src and dest notion, since the HW expects them to be from
  2448. * Tx perspective where as the input from user is from Rx filter view.
  2449. */
  2450. input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
  2451. input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
  2452. input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
  2453. input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
  2454. if (ntohl(fsp->m_ext.data[1])) {
  2455. vf_id = ntohl(fsp->h_ext.data[1]);
  2456. if (vf_id >= pf->num_alloc_vfs) {
  2457. netif_info(pf, drv, vsi->netdev,
  2458. "Invalid VF id %d\n", vf_id);
  2459. goto free_input;
  2460. }
  2461. /* Find vsi id from vf id and override dest vsi */
  2462. input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
  2463. if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
  2464. netif_info(pf, drv, vsi->netdev,
  2465. "Invalid queue id %d for VF %d\n",
  2466. input->q_index, vf_id);
  2467. goto free_input;
  2468. }
  2469. }
  2470. ret = i40e_add_del_fdir(vsi, input, true);
  2471. free_input:
  2472. if (ret)
  2473. kfree(input);
  2474. else
  2475. i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
  2476. return ret;
  2477. }
  2478. /**
  2479. * i40e_set_rxnfc - command to set RX flow classification rules
  2480. * @netdev: network interface device structure
  2481. * @cmd: ethtool rxnfc command
  2482. *
  2483. * Returns Success if the command is supported.
  2484. **/
  2485. static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
  2486. {
  2487. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2488. struct i40e_vsi *vsi = np->vsi;
  2489. struct i40e_pf *pf = vsi->back;
  2490. int ret = -EOPNOTSUPP;
  2491. switch (cmd->cmd) {
  2492. case ETHTOOL_SRXFH:
  2493. ret = i40e_set_rss_hash_opt(pf, cmd);
  2494. break;
  2495. case ETHTOOL_SRXCLSRLINS:
  2496. ret = i40e_add_fdir_ethtool(vsi, cmd);
  2497. break;
  2498. case ETHTOOL_SRXCLSRLDEL:
  2499. ret = i40e_del_fdir_entry(vsi, cmd);
  2500. break;
  2501. default:
  2502. break;
  2503. }
  2504. return ret;
  2505. }
  2506. /**
  2507. * i40e_max_channels - get Max number of combined channels supported
  2508. * @vsi: vsi pointer
  2509. **/
  2510. static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
  2511. {
  2512. /* TODO: This code assumes DCB and FD is disabled for now. */
  2513. return vsi->alloc_queue_pairs;
  2514. }
  2515. /**
  2516. * i40e_get_channels - Get the current channels enabled and max supported etc.
  2517. * @netdev: network interface device structure
  2518. * @ch: ethtool channels structure
  2519. *
  2520. * We don't support separate tx and rx queues as channels. The other count
  2521. * represents how many queues are being used for control. max_combined counts
  2522. * how many queue pairs we can support. They may not be mapped 1 to 1 with
  2523. * q_vectors since we support a lot more queue pairs than q_vectors.
  2524. **/
  2525. static void i40e_get_channels(struct net_device *dev,
  2526. struct ethtool_channels *ch)
  2527. {
  2528. struct i40e_netdev_priv *np = netdev_priv(dev);
  2529. struct i40e_vsi *vsi = np->vsi;
  2530. struct i40e_pf *pf = vsi->back;
  2531. /* report maximum channels */
  2532. ch->max_combined = i40e_max_channels(vsi);
  2533. /* report info for other vector */
  2534. ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
  2535. ch->max_other = ch->other_count;
  2536. /* Note: This code assumes DCB is disabled for now. */
  2537. ch->combined_count = vsi->num_queue_pairs;
  2538. }
  2539. /**
  2540. * i40e_set_channels - Set the new channels count.
  2541. * @netdev: network interface device structure
  2542. * @ch: ethtool channels structure
  2543. *
  2544. * The new channels count may not be the same as requested by the user
  2545. * since it gets rounded down to a power of 2 value.
  2546. **/
  2547. static int i40e_set_channels(struct net_device *dev,
  2548. struct ethtool_channels *ch)
  2549. {
  2550. const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
  2551. struct i40e_netdev_priv *np = netdev_priv(dev);
  2552. unsigned int count = ch->combined_count;
  2553. struct i40e_vsi *vsi = np->vsi;
  2554. struct i40e_pf *pf = vsi->back;
  2555. struct i40e_fdir_filter *rule;
  2556. struct hlist_node *node2;
  2557. int new_count;
  2558. int err = 0;
  2559. /* We do not support setting channels for any other VSI at present */
  2560. if (vsi->type != I40E_VSI_MAIN)
  2561. return -EINVAL;
  2562. /* verify they are not requesting separate vectors */
  2563. if (!count || ch->rx_count || ch->tx_count)
  2564. return -EINVAL;
  2565. /* verify other_count has not changed */
  2566. if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
  2567. return -EINVAL;
  2568. /* verify the number of channels does not exceed hardware limits */
  2569. if (count > i40e_max_channels(vsi))
  2570. return -EINVAL;
  2571. /* verify that the number of channels does not invalidate any current
  2572. * flow director rules
  2573. */
  2574. hlist_for_each_entry_safe(rule, node2,
  2575. &pf->fdir_filter_list, fdir_node) {
  2576. if (rule->dest_ctl != drop && count <= rule->q_index) {
  2577. dev_warn(&pf->pdev->dev,
  2578. "Existing user defined filter %d assigns flow to queue %d\n",
  2579. rule->fd_id, rule->q_index);
  2580. err = -EINVAL;
  2581. }
  2582. }
  2583. if (err) {
  2584. dev_err(&pf->pdev->dev,
  2585. "Existing filter rules must be deleted to reduce combined channel count to %d\n",
  2586. count);
  2587. return err;
  2588. }
  2589. /* update feature limits from largest to smallest supported values */
  2590. /* TODO: Flow director limit, DCB etc */
  2591. /* use rss_reconfig to rebuild with new queue count and update traffic
  2592. * class queue mapping
  2593. */
  2594. new_count = i40e_reconfig_rss_queues(pf, count);
  2595. if (new_count > 0)
  2596. return 0;
  2597. else
  2598. return -EINVAL;
  2599. }
  2600. /**
  2601. * i40e_get_rxfh_key_size - get the RSS hash key size
  2602. * @netdev: network interface device structure
  2603. *
  2604. * Returns the table size.
  2605. **/
  2606. static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
  2607. {
  2608. return I40E_HKEY_ARRAY_SIZE;
  2609. }
  2610. /**
  2611. * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
  2612. * @netdev: network interface device structure
  2613. *
  2614. * Returns the table size.
  2615. **/
  2616. static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
  2617. {
  2618. return I40E_HLUT_ARRAY_SIZE;
  2619. }
  2620. static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
  2621. u8 *hfunc)
  2622. {
  2623. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2624. struct i40e_vsi *vsi = np->vsi;
  2625. u8 *lut, *seed = NULL;
  2626. int ret;
  2627. u16 i;
  2628. if (hfunc)
  2629. *hfunc = ETH_RSS_HASH_TOP;
  2630. if (!indir)
  2631. return 0;
  2632. seed = key;
  2633. lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
  2634. if (!lut)
  2635. return -ENOMEM;
  2636. ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
  2637. if (ret)
  2638. goto out;
  2639. for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
  2640. indir[i] = (u32)(lut[i]);
  2641. out:
  2642. kfree(lut);
  2643. return ret;
  2644. }
  2645. /**
  2646. * i40e_set_rxfh - set the rx flow hash indirection table
  2647. * @netdev: network interface device structure
  2648. * @indir: indirection table
  2649. * @key: hash key
  2650. *
  2651. * Returns -EINVAL if the table specifies an invalid queue id, otherwise
  2652. * returns 0 after programming the table.
  2653. **/
  2654. static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
  2655. const u8 *key, const u8 hfunc)
  2656. {
  2657. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2658. struct i40e_vsi *vsi = np->vsi;
  2659. struct i40e_pf *pf = vsi->back;
  2660. u8 *seed = NULL;
  2661. u16 i;
  2662. if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
  2663. return -EOPNOTSUPP;
  2664. if (key) {
  2665. if (!vsi->rss_hkey_user) {
  2666. vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
  2667. GFP_KERNEL);
  2668. if (!vsi->rss_hkey_user)
  2669. return -ENOMEM;
  2670. }
  2671. memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
  2672. seed = vsi->rss_hkey_user;
  2673. }
  2674. if (!vsi->rss_lut_user) {
  2675. vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
  2676. if (!vsi->rss_lut_user)
  2677. return -ENOMEM;
  2678. }
  2679. /* Each 32 bits pointed by 'indir' is stored with a lut entry */
  2680. if (indir)
  2681. for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
  2682. vsi->rss_lut_user[i] = (u8)(indir[i]);
  2683. else
  2684. i40e_fill_rss_lut(pf, vsi->rss_lut_user, I40E_HLUT_ARRAY_SIZE,
  2685. vsi->rss_size);
  2686. return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
  2687. I40E_HLUT_ARRAY_SIZE);
  2688. }
  2689. /**
  2690. * i40e_get_priv_flags - report device private flags
  2691. * @dev: network interface device structure
  2692. *
  2693. * The get string set count and the string set should be matched for each
  2694. * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
  2695. * array.
  2696. *
  2697. * Returns a u32 bitmap of flags.
  2698. **/
  2699. static u32 i40e_get_priv_flags(struct net_device *dev)
  2700. {
  2701. struct i40e_netdev_priv *np = netdev_priv(dev);
  2702. struct i40e_vsi *vsi = np->vsi;
  2703. struct i40e_pf *pf = vsi->back;
  2704. u32 ret_flags = 0;
  2705. ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
  2706. I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
  2707. ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ?
  2708. I40E_PRIV_FLAGS_FD_ATR : 0;
  2709. ret_flags |= pf->flags & I40E_FLAG_VEB_STATS_ENABLED ?
  2710. I40E_PRIV_FLAGS_VEB_STATS : 0;
  2711. ret_flags |= pf->auto_disable_flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE ?
  2712. 0 : I40E_PRIV_FLAGS_HW_ATR_EVICT;
  2713. if (pf->hw.pf_id == 0) {
  2714. ret_flags |= pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT ?
  2715. I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT : 0;
  2716. }
  2717. return ret_flags;
  2718. }
  2719. /**
  2720. * i40e_set_priv_flags - set private flags
  2721. * @dev: network interface device structure
  2722. * @flags: bit flags to be set
  2723. **/
  2724. static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
  2725. {
  2726. struct i40e_netdev_priv *np = netdev_priv(dev);
  2727. struct i40e_vsi *vsi = np->vsi;
  2728. struct i40e_pf *pf = vsi->back;
  2729. u16 sw_flags = 0, valid_flags = 0;
  2730. bool reset_required = false;
  2731. bool promisc_change = false;
  2732. int ret;
  2733. /* NOTE: MFP is not settable */
  2734. if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
  2735. pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
  2736. else
  2737. pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
  2738. /* allow the user to control the state of the Flow
  2739. * Director ATR (Application Targeted Routing) feature
  2740. * of the driver
  2741. */
  2742. if (flags & I40E_PRIV_FLAGS_FD_ATR) {
  2743. pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
  2744. } else {
  2745. pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  2746. pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
  2747. /* flush current ATR settings */
  2748. set_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state);
  2749. }
  2750. if ((flags & I40E_PRIV_FLAGS_VEB_STATS) &&
  2751. !(pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
  2752. pf->flags |= I40E_FLAG_VEB_STATS_ENABLED;
  2753. reset_required = true;
  2754. } else if (!(flags & I40E_PRIV_FLAGS_VEB_STATS) &&
  2755. (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
  2756. pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
  2757. reset_required = true;
  2758. }
  2759. if (pf->hw.pf_id == 0) {
  2760. if ((flags & I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT) &&
  2761. !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
  2762. pf->flags |= I40E_FLAG_TRUE_PROMISC_SUPPORT;
  2763. promisc_change = true;
  2764. } else if (!(flags & I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT) &&
  2765. (pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
  2766. pf->flags &= ~I40E_FLAG_TRUE_PROMISC_SUPPORT;
  2767. promisc_change = true;
  2768. }
  2769. }
  2770. if (promisc_change) {
  2771. if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
  2772. sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  2773. valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  2774. ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
  2775. NULL);
  2776. if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
  2777. dev_info(&pf->pdev->dev,
  2778. "couldn't set switch config bits, err %s aq_err %s\n",
  2779. i40e_stat_str(&pf->hw, ret),
  2780. i40e_aq_str(&pf->hw,
  2781. pf->hw.aq.asq_last_status));
  2782. /* not a fatal problem, just keep going */
  2783. }
  2784. }
  2785. if ((flags & I40E_PRIV_FLAGS_HW_ATR_EVICT) &&
  2786. (pf->flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE))
  2787. pf->auto_disable_flags &= ~I40E_FLAG_HW_ATR_EVICT_CAPABLE;
  2788. else
  2789. pf->auto_disable_flags |= I40E_FLAG_HW_ATR_EVICT_CAPABLE;
  2790. /* if needed, issue reset to cause things to take effect */
  2791. if (reset_required)
  2792. i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
  2793. return 0;
  2794. }
  2795. static const struct ethtool_ops i40e_ethtool_ops = {
  2796. .get_settings = i40e_get_settings,
  2797. .set_settings = i40e_set_settings,
  2798. .get_drvinfo = i40e_get_drvinfo,
  2799. .get_regs_len = i40e_get_regs_len,
  2800. .get_regs = i40e_get_regs,
  2801. .nway_reset = i40e_nway_reset,
  2802. .get_link = ethtool_op_get_link,
  2803. .get_wol = i40e_get_wol,
  2804. .set_wol = i40e_set_wol,
  2805. .set_eeprom = i40e_set_eeprom,
  2806. .get_eeprom_len = i40e_get_eeprom_len,
  2807. .get_eeprom = i40e_get_eeprom,
  2808. .get_ringparam = i40e_get_ringparam,
  2809. .set_ringparam = i40e_set_ringparam,
  2810. .get_pauseparam = i40e_get_pauseparam,
  2811. .set_pauseparam = i40e_set_pauseparam,
  2812. .get_msglevel = i40e_get_msglevel,
  2813. .set_msglevel = i40e_set_msglevel,
  2814. .get_rxnfc = i40e_get_rxnfc,
  2815. .set_rxnfc = i40e_set_rxnfc,
  2816. .self_test = i40e_diag_test,
  2817. .get_strings = i40e_get_strings,
  2818. .set_phys_id = i40e_set_phys_id,
  2819. .get_sset_count = i40e_get_sset_count,
  2820. .get_ethtool_stats = i40e_get_ethtool_stats,
  2821. .get_coalesce = i40e_get_coalesce,
  2822. .set_coalesce = i40e_set_coalesce,
  2823. .get_rxfh_key_size = i40e_get_rxfh_key_size,
  2824. .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
  2825. .get_rxfh = i40e_get_rxfh,
  2826. .set_rxfh = i40e_set_rxfh,
  2827. .get_channels = i40e_get_channels,
  2828. .set_channels = i40e_set_channels,
  2829. .get_ts_info = i40e_get_ts_info,
  2830. .get_priv_flags = i40e_get_priv_flags,
  2831. .set_priv_flags = i40e_set_priv_flags,
  2832. .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
  2833. .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
  2834. };
  2835. void i40e_set_ethtool_ops(struct net_device *netdev)
  2836. {
  2837. netdev->ethtool_ops = &i40e_ethtool_ops;
  2838. }