i40e_ethtool.c 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 - 2015 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. };
  83. static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
  84. struct ethtool_rxnfc *cmd);
  85. /* These PF_STATs might look like duplicates of some NETDEV_STATs,
  86. * but they are separate. This device supports Virtualization, and
  87. * as such might have several netdevs supporting VMDq and FCoE going
  88. * through a single port. The NETDEV_STATs are for individual netdevs
  89. * seen at the top of the stack, and the PF_STATs are for the physical
  90. * function at the bottom of the stack hosting those netdevs.
  91. *
  92. * The PF_STATs are appended to the netdev stats only when ethtool -S
  93. * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
  94. */
  95. static struct i40e_stats i40e_gstrings_stats[] = {
  96. I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
  97. I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
  98. I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
  99. I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
  100. I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
  101. I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
  102. I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
  103. I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
  104. I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
  105. I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
  106. I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
  107. I40E_PF_STAT("crc_errors", stats.crc_errors),
  108. I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
  109. I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
  110. I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
  111. I40E_PF_STAT("tx_timeout", tx_timeout_count),
  112. I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
  113. I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
  114. I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
  115. I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
  116. I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
  117. I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
  118. I40E_PF_STAT("rx_size_64", stats.rx_size_64),
  119. I40E_PF_STAT("rx_size_127", stats.rx_size_127),
  120. I40E_PF_STAT("rx_size_255", stats.rx_size_255),
  121. I40E_PF_STAT("rx_size_511", stats.rx_size_511),
  122. I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
  123. I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
  124. I40E_PF_STAT("rx_size_big", stats.rx_size_big),
  125. I40E_PF_STAT("tx_size_64", stats.tx_size_64),
  126. I40E_PF_STAT("tx_size_127", stats.tx_size_127),
  127. I40E_PF_STAT("tx_size_255", stats.tx_size_255),
  128. I40E_PF_STAT("tx_size_511", stats.tx_size_511),
  129. I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
  130. I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
  131. I40E_PF_STAT("tx_size_big", stats.tx_size_big),
  132. I40E_PF_STAT("rx_undersize", stats.rx_undersize),
  133. I40E_PF_STAT("rx_fragments", stats.rx_fragments),
  134. I40E_PF_STAT("rx_oversize", stats.rx_oversize),
  135. I40E_PF_STAT("rx_jabber", stats.rx_jabber),
  136. I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
  137. I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
  138. I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
  139. I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
  140. I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
  141. /* LPI stats */
  142. I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
  143. I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
  144. I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
  145. I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
  146. };
  147. #ifdef I40E_FCOE
  148. static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
  149. I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
  150. I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
  151. I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
  152. I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
  153. I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
  154. I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
  155. I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
  156. I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
  157. };
  158. #endif /* I40E_FCOE */
  159. #define I40E_QUEUE_STATS_LEN(n) \
  160. (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
  161. * 2 /* Tx and Rx together */ \
  162. * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
  163. #define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
  164. #define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
  165. #define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
  166. #ifdef I40E_FCOE
  167. #define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
  168. #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
  169. I40E_FCOE_STATS_LEN + \
  170. I40E_MISC_STATS_LEN + \
  171. I40E_QUEUE_STATS_LEN((n)))
  172. #else
  173. #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
  174. I40E_MISC_STATS_LEN + \
  175. I40E_QUEUE_STATS_LEN((n)))
  176. #endif /* I40E_FCOE */
  177. #define I40E_PFC_STATS_LEN ( \
  178. (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
  179. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
  180. FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
  181. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
  182. FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
  183. / sizeof(u64))
  184. #define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
  185. #define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
  186. I40E_PFC_STATS_LEN + \
  187. I40E_VSI_STATS_LEN((n)))
  188. enum i40e_ethtool_test_id {
  189. I40E_ETH_TEST_REG = 0,
  190. I40E_ETH_TEST_EEPROM,
  191. I40E_ETH_TEST_INTR,
  192. I40E_ETH_TEST_LOOPBACK,
  193. I40E_ETH_TEST_LINK,
  194. };
  195. static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
  196. "Register test (offline)",
  197. "Eeprom test (offline)",
  198. "Interrupt test (offline)",
  199. "Loopback test (offline)",
  200. "Link test (on/offline)"
  201. };
  202. #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
  203. static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
  204. "NPAR",
  205. };
  206. #define I40E_PRIV_FLAGS_STR_LEN \
  207. (sizeof(i40e_priv_flags_strings) / ETH_GSTRING_LEN)
  208. /**
  209. * i40e_partition_setting_complaint - generic complaint for MFP restriction
  210. * @pf: the PF struct
  211. **/
  212. static void i40e_partition_setting_complaint(struct i40e_pf *pf)
  213. {
  214. dev_info(&pf->pdev->dev,
  215. "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");
  216. }
  217. /**
  218. * i40e_get_settings_link_up - Get the Link settings for when link is up
  219. * @hw: hw structure
  220. * @ecmd: ethtool command to fill in
  221. * @netdev: network interface device structure
  222. *
  223. **/
  224. static void i40e_get_settings_link_up(struct i40e_hw *hw,
  225. struct ethtool_cmd *ecmd,
  226. struct net_device *netdev)
  227. {
  228. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  229. u32 link_speed = hw_link_info->link_speed;
  230. /* Initialize supported and advertised settings based on phy settings */
  231. switch (hw_link_info->phy_type) {
  232. case I40E_PHY_TYPE_40GBASE_CR4:
  233. case I40E_PHY_TYPE_40GBASE_CR4_CU:
  234. ecmd->supported = SUPPORTED_Autoneg |
  235. SUPPORTED_40000baseCR4_Full;
  236. ecmd->advertising = ADVERTISED_Autoneg |
  237. ADVERTISED_40000baseCR4_Full;
  238. break;
  239. case I40E_PHY_TYPE_XLAUI:
  240. case I40E_PHY_TYPE_XLPPI:
  241. case I40E_PHY_TYPE_40GBASE_AOC:
  242. ecmd->supported = SUPPORTED_40000baseCR4_Full;
  243. break;
  244. case I40E_PHY_TYPE_40GBASE_KR4:
  245. ecmd->supported = SUPPORTED_Autoneg |
  246. SUPPORTED_40000baseKR4_Full;
  247. ecmd->advertising = ADVERTISED_Autoneg |
  248. ADVERTISED_40000baseKR4_Full;
  249. break;
  250. case I40E_PHY_TYPE_40GBASE_SR4:
  251. ecmd->supported = SUPPORTED_40000baseSR4_Full;
  252. break;
  253. case I40E_PHY_TYPE_40GBASE_LR4:
  254. ecmd->supported = SUPPORTED_40000baseLR4_Full;
  255. break;
  256. case I40E_PHY_TYPE_20GBASE_KR2:
  257. ecmd->supported = SUPPORTED_Autoneg |
  258. SUPPORTED_20000baseKR2_Full;
  259. ecmd->advertising = ADVERTISED_Autoneg |
  260. ADVERTISED_20000baseKR2_Full;
  261. break;
  262. case I40E_PHY_TYPE_10GBASE_KX4:
  263. ecmd->supported = SUPPORTED_Autoneg |
  264. SUPPORTED_10000baseKX4_Full;
  265. ecmd->advertising = ADVERTISED_Autoneg |
  266. ADVERTISED_10000baseKX4_Full;
  267. break;
  268. case I40E_PHY_TYPE_10GBASE_KR:
  269. ecmd->supported = SUPPORTED_Autoneg |
  270. SUPPORTED_10000baseKR_Full;
  271. ecmd->advertising = ADVERTISED_Autoneg |
  272. ADVERTISED_10000baseKR_Full;
  273. break;
  274. case I40E_PHY_TYPE_10GBASE_SR:
  275. case I40E_PHY_TYPE_10GBASE_LR:
  276. case I40E_PHY_TYPE_1000BASE_SX:
  277. case I40E_PHY_TYPE_1000BASE_LX:
  278. ecmd->supported = SUPPORTED_10000baseT_Full |
  279. SUPPORTED_1000baseT_Full;
  280. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  281. ecmd->advertising |= ADVERTISED_10000baseT_Full;
  282. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  283. ecmd->advertising |= ADVERTISED_1000baseT_Full;
  284. break;
  285. case I40E_PHY_TYPE_1000BASE_KX:
  286. ecmd->supported = SUPPORTED_Autoneg |
  287. SUPPORTED_1000baseKX_Full;
  288. ecmd->advertising = ADVERTISED_Autoneg |
  289. ADVERTISED_1000baseKX_Full;
  290. break;
  291. case I40E_PHY_TYPE_10GBASE_T:
  292. case I40E_PHY_TYPE_1000BASE_T:
  293. case I40E_PHY_TYPE_100BASE_TX:
  294. ecmd->supported = SUPPORTED_Autoneg |
  295. SUPPORTED_10000baseT_Full |
  296. SUPPORTED_1000baseT_Full |
  297. SUPPORTED_100baseT_Full;
  298. ecmd->advertising = ADVERTISED_Autoneg;
  299. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  300. ecmd->advertising |= ADVERTISED_10000baseT_Full;
  301. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  302. ecmd->advertising |= ADVERTISED_1000baseT_Full;
  303. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
  304. ecmd->advertising |= ADVERTISED_100baseT_Full;
  305. break;
  306. case I40E_PHY_TYPE_10GBASE_CR1_CU:
  307. case I40E_PHY_TYPE_10GBASE_CR1:
  308. ecmd->supported = SUPPORTED_Autoneg |
  309. SUPPORTED_10000baseT_Full;
  310. ecmd->advertising = ADVERTISED_Autoneg |
  311. ADVERTISED_10000baseT_Full;
  312. break;
  313. case I40E_PHY_TYPE_XAUI:
  314. case I40E_PHY_TYPE_XFI:
  315. case I40E_PHY_TYPE_SFI:
  316. case I40E_PHY_TYPE_10GBASE_SFPP_CU:
  317. case I40E_PHY_TYPE_10GBASE_AOC:
  318. ecmd->supported = SUPPORTED_10000baseT_Full;
  319. break;
  320. case I40E_PHY_TYPE_SGMII:
  321. ecmd->supported = SUPPORTED_Autoneg |
  322. SUPPORTED_1000baseT_Full |
  323. SUPPORTED_100baseT_Full;
  324. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  325. ecmd->advertising |= ADVERTISED_1000baseT_Full;
  326. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
  327. ecmd->advertising |= ADVERTISED_100baseT_Full;
  328. break;
  329. default:
  330. /* if we got here and link is up something bad is afoot */
  331. netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
  332. hw_link_info->phy_type);
  333. }
  334. /* Set speed and duplex */
  335. switch (link_speed) {
  336. case I40E_LINK_SPEED_40GB:
  337. ethtool_cmd_speed_set(ecmd, SPEED_40000);
  338. break;
  339. case I40E_LINK_SPEED_20GB:
  340. ethtool_cmd_speed_set(ecmd, SPEED_20000);
  341. break;
  342. case I40E_LINK_SPEED_10GB:
  343. ethtool_cmd_speed_set(ecmd, SPEED_10000);
  344. break;
  345. case I40E_LINK_SPEED_1GB:
  346. ethtool_cmd_speed_set(ecmd, SPEED_1000);
  347. break;
  348. case I40E_LINK_SPEED_100MB:
  349. ethtool_cmd_speed_set(ecmd, SPEED_100);
  350. break;
  351. default:
  352. break;
  353. }
  354. ecmd->duplex = DUPLEX_FULL;
  355. }
  356. /**
  357. * i40e_get_settings_link_down - Get the Link settings for when link is down
  358. * @hw: hw structure
  359. * @ecmd: ethtool command to fill in
  360. *
  361. * Reports link settings that can be determined when link is down
  362. **/
  363. static void i40e_get_settings_link_down(struct i40e_hw *hw,
  364. struct ethtool_cmd *ecmd)
  365. {
  366. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  367. /* link is down and the driver needs to fall back on
  368. * device ID to determine what kinds of info to display,
  369. * it's mostly a guess that may change when link is up
  370. */
  371. switch (hw->device_id) {
  372. case I40E_DEV_ID_QSFP_A:
  373. case I40E_DEV_ID_QSFP_B:
  374. case I40E_DEV_ID_QSFP_C:
  375. /* pluggable QSFP */
  376. ecmd->supported = SUPPORTED_40000baseSR4_Full |
  377. SUPPORTED_40000baseCR4_Full |
  378. SUPPORTED_40000baseLR4_Full;
  379. ecmd->advertising = ADVERTISED_40000baseSR4_Full |
  380. ADVERTISED_40000baseCR4_Full |
  381. ADVERTISED_40000baseLR4_Full;
  382. break;
  383. case I40E_DEV_ID_KX_B:
  384. /* backplane 40G */
  385. ecmd->supported = SUPPORTED_40000baseKR4_Full;
  386. ecmd->advertising = ADVERTISED_40000baseKR4_Full;
  387. break;
  388. case I40E_DEV_ID_KX_C:
  389. /* backplane 10G */
  390. ecmd->supported = SUPPORTED_10000baseKR_Full;
  391. ecmd->advertising = ADVERTISED_10000baseKR_Full;
  392. break;
  393. case I40E_DEV_ID_10G_BASE_T:
  394. ecmd->supported = SUPPORTED_10000baseT_Full |
  395. SUPPORTED_1000baseT_Full |
  396. SUPPORTED_100baseT_Full;
  397. /* Figure out what has been requested */
  398. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  399. ecmd->advertising |= ADVERTISED_10000baseT_Full;
  400. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  401. ecmd->advertising |= ADVERTISED_1000baseT_Full;
  402. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
  403. ecmd->advertising |= ADVERTISED_100baseT_Full;
  404. break;
  405. case I40E_DEV_ID_20G_KR2:
  406. /* backplane 20G */
  407. ecmd->supported = SUPPORTED_20000baseKR2_Full;
  408. ecmd->advertising = ADVERTISED_20000baseKR2_Full;
  409. break;
  410. default:
  411. /* all the rest are 10G/1G */
  412. ecmd->supported = SUPPORTED_10000baseT_Full |
  413. SUPPORTED_1000baseT_Full;
  414. /* Figure out what has been requested */
  415. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
  416. ecmd->advertising |= ADVERTISED_10000baseT_Full;
  417. if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
  418. ecmd->advertising |= ADVERTISED_1000baseT_Full;
  419. break;
  420. }
  421. /* With no link speed and duplex are unknown */
  422. ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
  423. ecmd->duplex = DUPLEX_UNKNOWN;
  424. }
  425. /**
  426. * i40e_get_settings - Get Link Speed and Duplex settings
  427. * @netdev: network interface device structure
  428. * @ecmd: ethtool command
  429. *
  430. * Reports speed/duplex settings based on media_type
  431. **/
  432. static int i40e_get_settings(struct net_device *netdev,
  433. struct ethtool_cmd *ecmd)
  434. {
  435. struct i40e_netdev_priv *np = netdev_priv(netdev);
  436. struct i40e_pf *pf = np->vsi->back;
  437. struct i40e_hw *hw = &pf->hw;
  438. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  439. bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
  440. if (link_up)
  441. i40e_get_settings_link_up(hw, ecmd, netdev);
  442. else
  443. i40e_get_settings_link_down(hw, ecmd);
  444. /* Now set the settings that don't rely on link being up/down */
  445. /* Set autoneg settings */
  446. ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  447. AUTONEG_ENABLE : AUTONEG_DISABLE);
  448. switch (hw->phy.media_type) {
  449. case I40E_MEDIA_TYPE_BACKPLANE:
  450. ecmd->supported |= SUPPORTED_Autoneg |
  451. SUPPORTED_Backplane;
  452. ecmd->advertising |= ADVERTISED_Autoneg |
  453. ADVERTISED_Backplane;
  454. ecmd->port = PORT_NONE;
  455. break;
  456. case I40E_MEDIA_TYPE_BASET:
  457. ecmd->supported |= SUPPORTED_TP;
  458. ecmd->advertising |= ADVERTISED_TP;
  459. ecmd->port = PORT_TP;
  460. break;
  461. case I40E_MEDIA_TYPE_DA:
  462. case I40E_MEDIA_TYPE_CX4:
  463. ecmd->supported |= SUPPORTED_FIBRE;
  464. ecmd->advertising |= ADVERTISED_FIBRE;
  465. ecmd->port = PORT_DA;
  466. break;
  467. case I40E_MEDIA_TYPE_FIBER:
  468. ecmd->supported |= SUPPORTED_FIBRE;
  469. ecmd->port = PORT_FIBRE;
  470. break;
  471. case I40E_MEDIA_TYPE_UNKNOWN:
  472. default:
  473. ecmd->port = PORT_OTHER;
  474. break;
  475. }
  476. /* Set transceiver */
  477. ecmd->transceiver = XCVR_EXTERNAL;
  478. /* Set flow control settings */
  479. ecmd->supported |= SUPPORTED_Pause;
  480. switch (hw->fc.requested_mode) {
  481. case I40E_FC_FULL:
  482. ecmd->advertising |= ADVERTISED_Pause;
  483. break;
  484. case I40E_FC_TX_PAUSE:
  485. ecmd->advertising |= ADVERTISED_Asym_Pause;
  486. break;
  487. case I40E_FC_RX_PAUSE:
  488. ecmd->advertising |= (ADVERTISED_Pause |
  489. ADVERTISED_Asym_Pause);
  490. break;
  491. default:
  492. ecmd->advertising &= ~(ADVERTISED_Pause |
  493. ADVERTISED_Asym_Pause);
  494. break;
  495. }
  496. return 0;
  497. }
  498. /**
  499. * i40e_set_settings - Set Speed and Duplex
  500. * @netdev: network interface device structure
  501. * @ecmd: ethtool command
  502. *
  503. * Set speed/duplex per media_types advertised/forced
  504. **/
  505. static int i40e_set_settings(struct net_device *netdev,
  506. struct ethtool_cmd *ecmd)
  507. {
  508. struct i40e_netdev_priv *np = netdev_priv(netdev);
  509. struct i40e_aq_get_phy_abilities_resp abilities;
  510. struct i40e_aq_set_phy_config config;
  511. struct i40e_pf *pf = np->vsi->back;
  512. struct i40e_vsi *vsi = np->vsi;
  513. struct i40e_hw *hw = &pf->hw;
  514. struct ethtool_cmd safe_ecmd;
  515. i40e_status status = 0;
  516. bool change = false;
  517. int err = 0;
  518. u8 autoneg;
  519. u32 advertise;
  520. /* Changing port settings is not supported if this isn't the
  521. * port's controlling PF
  522. */
  523. if (hw->partition_id != 1) {
  524. i40e_partition_setting_complaint(pf);
  525. return -EOPNOTSUPP;
  526. }
  527. if (vsi != pf->vsi[pf->lan_vsi])
  528. return -EOPNOTSUPP;
  529. if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
  530. hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
  531. hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
  532. hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
  533. return -EOPNOTSUPP;
  534. /* get our own copy of the bits to check against */
  535. memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
  536. i40e_get_settings(netdev, &safe_ecmd);
  537. /* save autoneg and speed out of ecmd */
  538. autoneg = ecmd->autoneg;
  539. advertise = ecmd->advertising;
  540. /* set autoneg and speed back to what they currently are */
  541. ecmd->autoneg = safe_ecmd.autoneg;
  542. ecmd->advertising = safe_ecmd.advertising;
  543. ecmd->cmd = safe_ecmd.cmd;
  544. /* If ecmd and safe_ecmd are not the same now, then they are
  545. * trying to set something that we do not support
  546. */
  547. if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
  548. return -EOPNOTSUPP;
  549. while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
  550. usleep_range(1000, 2000);
  551. /* Get the current phy config */
  552. status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
  553. NULL);
  554. if (status)
  555. return -EAGAIN;
  556. /* Copy abilities to config in case autoneg is not
  557. * set below
  558. */
  559. memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
  560. config.abilities = abilities.abilities;
  561. /* Check autoneg */
  562. if (autoneg == AUTONEG_ENABLE) {
  563. /* If autoneg is not supported, return error */
  564. if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
  565. netdev_info(netdev, "Autoneg not supported on this phy\n");
  566. return -EINVAL;
  567. }
  568. /* If autoneg was not already enabled */
  569. if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
  570. config.abilities = abilities.abilities |
  571. I40E_AQ_PHY_ENABLE_AN;
  572. change = true;
  573. }
  574. } else {
  575. /* If autoneg is supported 10GBASE_T is the only phy that
  576. * can disable it, so otherwise return error
  577. */
  578. if (safe_ecmd.supported & SUPPORTED_Autoneg &&
  579. hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
  580. netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
  581. return -EINVAL;
  582. }
  583. /* If autoneg is currently enabled */
  584. if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
  585. config.abilities = abilities.abilities &
  586. ~I40E_AQ_PHY_ENABLE_AN;
  587. change = true;
  588. }
  589. }
  590. if (advertise & ~safe_ecmd.supported)
  591. return -EINVAL;
  592. if (advertise & ADVERTISED_100baseT_Full)
  593. config.link_speed |= I40E_LINK_SPEED_100MB;
  594. if (advertise & ADVERTISED_1000baseT_Full ||
  595. advertise & ADVERTISED_1000baseKX_Full)
  596. config.link_speed |= I40E_LINK_SPEED_1GB;
  597. if (advertise & ADVERTISED_10000baseT_Full ||
  598. advertise & ADVERTISED_10000baseKX4_Full ||
  599. advertise & ADVERTISED_10000baseKR_Full)
  600. config.link_speed |= I40E_LINK_SPEED_10GB;
  601. if (advertise & ADVERTISED_20000baseKR2_Full)
  602. config.link_speed |= I40E_LINK_SPEED_20GB;
  603. if (advertise & ADVERTISED_40000baseKR4_Full ||
  604. advertise & ADVERTISED_40000baseCR4_Full ||
  605. advertise & ADVERTISED_40000baseSR4_Full ||
  606. advertise & ADVERTISED_40000baseLR4_Full)
  607. config.link_speed |= I40E_LINK_SPEED_40GB;
  608. if (change || (abilities.link_speed != config.link_speed)) {
  609. /* copy over the rest of the abilities */
  610. config.phy_type = abilities.phy_type;
  611. config.eee_capability = abilities.eee_capability;
  612. config.eeer = abilities.eeer_val;
  613. config.low_power_ctrl = abilities.d3_lpan;
  614. /* save the requested speeds */
  615. hw->phy.link_info.requested_speeds = config.link_speed;
  616. /* set link and auto negotiation so changes take effect */
  617. config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
  618. /* If link is up put link down */
  619. if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
  620. /* Tell the OS link is going down, the link will go
  621. * back up when fw says it is ready asynchronously
  622. */
  623. netdev_info(netdev, "PHY settings change requested, NIC Link is going down.\n");
  624. netif_carrier_off(netdev);
  625. netif_tx_stop_all_queues(netdev);
  626. }
  627. /* make the aq call */
  628. status = i40e_aq_set_phy_config(hw, &config, NULL);
  629. if (status) {
  630. netdev_info(netdev, "Set phy config failed with error %d.\n",
  631. status);
  632. return -EAGAIN;
  633. }
  634. status = i40e_aq_get_link_info(hw, true, NULL, NULL);
  635. if (status)
  636. netdev_info(netdev, "Updating link info failed with error %d\n",
  637. status);
  638. } else {
  639. netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
  640. }
  641. return err;
  642. }
  643. static int i40e_nway_reset(struct net_device *netdev)
  644. {
  645. /* restart autonegotiation */
  646. struct i40e_netdev_priv *np = netdev_priv(netdev);
  647. struct i40e_pf *pf = np->vsi->back;
  648. struct i40e_hw *hw = &pf->hw;
  649. bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
  650. i40e_status ret = 0;
  651. ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
  652. if (ret) {
  653. netdev_info(netdev, "link restart failed, aq_err=%d\n",
  654. pf->hw.aq.asq_last_status);
  655. return -EIO;
  656. }
  657. return 0;
  658. }
  659. /**
  660. * i40e_get_pauseparam - Get Flow Control status
  661. * Return tx/rx-pause status
  662. **/
  663. static void i40e_get_pauseparam(struct net_device *netdev,
  664. struct ethtool_pauseparam *pause)
  665. {
  666. struct i40e_netdev_priv *np = netdev_priv(netdev);
  667. struct i40e_pf *pf = np->vsi->back;
  668. struct i40e_hw *hw = &pf->hw;
  669. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  670. struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
  671. pause->autoneg =
  672. ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  673. AUTONEG_ENABLE : AUTONEG_DISABLE);
  674. /* PFC enabled so report LFC as off */
  675. if (dcbx_cfg->pfc.pfcenable) {
  676. pause->rx_pause = 0;
  677. pause->tx_pause = 0;
  678. return;
  679. }
  680. if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
  681. pause->rx_pause = 1;
  682. } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
  683. pause->tx_pause = 1;
  684. } else if (hw->fc.current_mode == I40E_FC_FULL) {
  685. pause->rx_pause = 1;
  686. pause->tx_pause = 1;
  687. }
  688. }
  689. /**
  690. * i40e_set_pauseparam - Set Flow Control parameter
  691. * @netdev: network interface device structure
  692. * @pause: return tx/rx flow control status
  693. **/
  694. static int i40e_set_pauseparam(struct net_device *netdev,
  695. struct ethtool_pauseparam *pause)
  696. {
  697. struct i40e_netdev_priv *np = netdev_priv(netdev);
  698. struct i40e_pf *pf = np->vsi->back;
  699. struct i40e_vsi *vsi = np->vsi;
  700. struct i40e_hw *hw = &pf->hw;
  701. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  702. struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
  703. bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
  704. i40e_status status;
  705. u8 aq_failures;
  706. int err = 0;
  707. /* Changing the port's flow control is not supported if this isn't the
  708. * port's controlling PF
  709. */
  710. if (hw->partition_id != 1) {
  711. i40e_partition_setting_complaint(pf);
  712. return -EOPNOTSUPP;
  713. }
  714. if (vsi != pf->vsi[pf->lan_vsi])
  715. return -EOPNOTSUPP;
  716. if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
  717. AUTONEG_ENABLE : AUTONEG_DISABLE)) {
  718. netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
  719. return -EOPNOTSUPP;
  720. }
  721. /* If we have link and don't have autoneg */
  722. if (!test_bit(__I40E_DOWN, &pf->state) &&
  723. !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
  724. /* Send message that it might not necessarily work*/
  725. netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
  726. }
  727. if (dcbx_cfg->pfc.pfcenable) {
  728. netdev_info(netdev,
  729. "Priority flow control enabled. Cannot set link flow control.\n");
  730. return -EOPNOTSUPP;
  731. }
  732. if (pause->rx_pause && pause->tx_pause)
  733. hw->fc.requested_mode = I40E_FC_FULL;
  734. else if (pause->rx_pause && !pause->tx_pause)
  735. hw->fc.requested_mode = I40E_FC_RX_PAUSE;
  736. else if (!pause->rx_pause && pause->tx_pause)
  737. hw->fc.requested_mode = I40E_FC_TX_PAUSE;
  738. else if (!pause->rx_pause && !pause->tx_pause)
  739. hw->fc.requested_mode = I40E_FC_NONE;
  740. else
  741. return -EINVAL;
  742. /* Tell the OS link is going down, the link will go back up when fw
  743. * says it is ready asynchronously
  744. */
  745. netdev_info(netdev, "Flow control settings change requested, NIC Link is going down.\n");
  746. netif_carrier_off(netdev);
  747. netif_tx_stop_all_queues(netdev);
  748. /* Set the fc mode and only restart an if link is up*/
  749. status = i40e_set_fc(hw, &aq_failures, link_up);
  750. if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
  751. netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with error %d and status %d\n",
  752. status, hw->aq.asq_last_status);
  753. err = -EAGAIN;
  754. }
  755. if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
  756. netdev_info(netdev, "Set fc failed on the set_phy_config call with error %d and status %d\n",
  757. status, hw->aq.asq_last_status);
  758. err = -EAGAIN;
  759. }
  760. if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
  761. netdev_info(netdev, "Set fc failed on the get_link_info call with error %d and status %d\n",
  762. status, hw->aq.asq_last_status);
  763. err = -EAGAIN;
  764. }
  765. if (!test_bit(__I40E_DOWN, &pf->state)) {
  766. /* Give it a little more time to try to come back */
  767. msleep(75);
  768. if (!test_bit(__I40E_DOWN, &pf->state))
  769. return i40e_nway_reset(netdev);
  770. }
  771. return err;
  772. }
  773. static u32 i40e_get_msglevel(struct net_device *netdev)
  774. {
  775. struct i40e_netdev_priv *np = netdev_priv(netdev);
  776. struct i40e_pf *pf = np->vsi->back;
  777. return pf->msg_enable;
  778. }
  779. static void i40e_set_msglevel(struct net_device *netdev, u32 data)
  780. {
  781. struct i40e_netdev_priv *np = netdev_priv(netdev);
  782. struct i40e_pf *pf = np->vsi->back;
  783. if (I40E_DEBUG_USER & data)
  784. pf->hw.debug_mask = data;
  785. pf->msg_enable = data;
  786. }
  787. static int i40e_get_regs_len(struct net_device *netdev)
  788. {
  789. int reg_count = 0;
  790. int i;
  791. for (i = 0; i40e_reg_list[i].offset != 0; i++)
  792. reg_count += i40e_reg_list[i].elements;
  793. return reg_count * sizeof(u32);
  794. }
  795. static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
  796. void *p)
  797. {
  798. struct i40e_netdev_priv *np = netdev_priv(netdev);
  799. struct i40e_pf *pf = np->vsi->back;
  800. struct i40e_hw *hw = &pf->hw;
  801. u32 *reg_buf = p;
  802. int i, j, ri;
  803. u32 reg;
  804. /* Tell ethtool which driver-version-specific regs output we have.
  805. *
  806. * At some point, if we have ethtool doing special formatting of
  807. * this data, it will rely on this version number to know how to
  808. * interpret things. Hence, this needs to be updated if/when the
  809. * diags register table is changed.
  810. */
  811. regs->version = 1;
  812. /* loop through the diags reg table for what to print */
  813. ri = 0;
  814. for (i = 0; i40e_reg_list[i].offset != 0; i++) {
  815. for (j = 0; j < i40e_reg_list[i].elements; j++) {
  816. reg = i40e_reg_list[i].offset
  817. + (j * i40e_reg_list[i].stride);
  818. reg_buf[ri++] = rd32(hw, reg);
  819. }
  820. }
  821. }
  822. static int i40e_get_eeprom(struct net_device *netdev,
  823. struct ethtool_eeprom *eeprom, u8 *bytes)
  824. {
  825. struct i40e_netdev_priv *np = netdev_priv(netdev);
  826. struct i40e_hw *hw = &np->vsi->back->hw;
  827. struct i40e_pf *pf = np->vsi->back;
  828. int ret_val = 0, len, offset;
  829. u8 *eeprom_buff;
  830. u16 i, sectors;
  831. bool last;
  832. u32 magic;
  833. #define I40E_NVM_SECTOR_SIZE 4096
  834. if (eeprom->len == 0)
  835. return -EINVAL;
  836. /* check for NVMUpdate access method */
  837. magic = hw->vendor_id | (hw->device_id << 16);
  838. if (eeprom->magic && eeprom->magic != magic) {
  839. struct i40e_nvm_access *cmd;
  840. int errno;
  841. /* make sure it is the right magic for NVMUpdate */
  842. if ((eeprom->magic >> 16) != hw->device_id)
  843. return -EINVAL;
  844. cmd = (struct i40e_nvm_access *)eeprom;
  845. ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
  846. if (ret_val &&
  847. ((hw->aq.asq_last_status != I40E_AQ_RC_EACCES) ||
  848. (hw->debug_mask & I40E_DEBUG_NVM)))
  849. dev_info(&pf->pdev->dev,
  850. "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
  851. ret_val, hw->aq.asq_last_status, errno,
  852. (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
  853. cmd->offset, cmd->data_size);
  854. return errno;
  855. }
  856. /* normal ethtool get_eeprom support */
  857. eeprom->magic = hw->vendor_id | (hw->device_id << 16);
  858. eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
  859. if (!eeprom_buff)
  860. return -ENOMEM;
  861. ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
  862. if (ret_val) {
  863. dev_info(&pf->pdev->dev,
  864. "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
  865. ret_val, hw->aq.asq_last_status);
  866. goto free_buff;
  867. }
  868. sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
  869. sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
  870. len = I40E_NVM_SECTOR_SIZE;
  871. last = false;
  872. for (i = 0; i < sectors; i++) {
  873. if (i == (sectors - 1)) {
  874. len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
  875. last = true;
  876. }
  877. offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
  878. ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
  879. (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
  880. last, NULL);
  881. if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
  882. dev_info(&pf->pdev->dev,
  883. "read NVM failed, invalid offset 0x%x\n",
  884. offset);
  885. break;
  886. } else if (ret_val &&
  887. hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
  888. dev_info(&pf->pdev->dev,
  889. "read NVM failed, access, offset 0x%x\n",
  890. offset);
  891. break;
  892. } else if (ret_val) {
  893. dev_info(&pf->pdev->dev,
  894. "read NVM failed offset %d err=%d status=0x%x\n",
  895. offset, ret_val, hw->aq.asq_last_status);
  896. break;
  897. }
  898. }
  899. i40e_release_nvm(hw);
  900. memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
  901. free_buff:
  902. kfree(eeprom_buff);
  903. return ret_val;
  904. }
  905. static int i40e_get_eeprom_len(struct net_device *netdev)
  906. {
  907. struct i40e_netdev_priv *np = netdev_priv(netdev);
  908. struct i40e_hw *hw = &np->vsi->back->hw;
  909. u32 val;
  910. val = (rd32(hw, I40E_GLPCI_LBARCTRL)
  911. & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
  912. >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
  913. /* register returns value in power of 2, 64Kbyte chunks. */
  914. val = (64 * 1024) * (1 << val);
  915. return val;
  916. }
  917. static int i40e_set_eeprom(struct net_device *netdev,
  918. struct ethtool_eeprom *eeprom, u8 *bytes)
  919. {
  920. struct i40e_netdev_priv *np = netdev_priv(netdev);
  921. struct i40e_hw *hw = &np->vsi->back->hw;
  922. struct i40e_pf *pf = np->vsi->back;
  923. struct i40e_nvm_access *cmd;
  924. int ret_val = 0;
  925. int errno;
  926. u32 magic;
  927. /* normal ethtool set_eeprom is not supported */
  928. magic = hw->vendor_id | (hw->device_id << 16);
  929. if (eeprom->magic == magic)
  930. return -EOPNOTSUPP;
  931. /* check for NVMUpdate access method */
  932. if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
  933. return -EINVAL;
  934. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  935. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  936. return -EBUSY;
  937. cmd = (struct i40e_nvm_access *)eeprom;
  938. ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
  939. if (ret_val &&
  940. ((hw->aq.asq_last_status != I40E_AQ_RC_EPERM &&
  941. hw->aq.asq_last_status != I40E_AQ_RC_EBUSY) ||
  942. (hw->debug_mask & I40E_DEBUG_NVM)))
  943. dev_info(&pf->pdev->dev,
  944. "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
  945. ret_val, hw->aq.asq_last_status, errno,
  946. (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
  947. cmd->offset, cmd->data_size);
  948. return errno;
  949. }
  950. static void i40e_get_drvinfo(struct net_device *netdev,
  951. struct ethtool_drvinfo *drvinfo)
  952. {
  953. struct i40e_netdev_priv *np = netdev_priv(netdev);
  954. struct i40e_vsi *vsi = np->vsi;
  955. struct i40e_pf *pf = vsi->back;
  956. strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
  957. strlcpy(drvinfo->version, i40e_driver_version_str,
  958. sizeof(drvinfo->version));
  959. strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
  960. sizeof(drvinfo->fw_version));
  961. strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
  962. sizeof(drvinfo->bus_info));
  963. drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
  964. }
  965. static void i40e_get_ringparam(struct net_device *netdev,
  966. struct ethtool_ringparam *ring)
  967. {
  968. struct i40e_netdev_priv *np = netdev_priv(netdev);
  969. struct i40e_pf *pf = np->vsi->back;
  970. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  971. ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
  972. ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
  973. ring->rx_mini_max_pending = 0;
  974. ring->rx_jumbo_max_pending = 0;
  975. ring->rx_pending = vsi->rx_rings[0]->count;
  976. ring->tx_pending = vsi->tx_rings[0]->count;
  977. ring->rx_mini_pending = 0;
  978. ring->rx_jumbo_pending = 0;
  979. }
  980. static int i40e_set_ringparam(struct net_device *netdev,
  981. struct ethtool_ringparam *ring)
  982. {
  983. struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
  984. struct i40e_netdev_priv *np = netdev_priv(netdev);
  985. struct i40e_vsi *vsi = np->vsi;
  986. struct i40e_pf *pf = vsi->back;
  987. u32 new_rx_count, new_tx_count;
  988. int i, err = 0;
  989. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  990. return -EINVAL;
  991. if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
  992. ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
  993. ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
  994. ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
  995. netdev_info(netdev,
  996. "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
  997. ring->tx_pending, ring->rx_pending,
  998. I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
  999. return -EINVAL;
  1000. }
  1001. new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
  1002. new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
  1003. /* if nothing to do return success */
  1004. if ((new_tx_count == vsi->tx_rings[0]->count) &&
  1005. (new_rx_count == vsi->rx_rings[0]->count))
  1006. return 0;
  1007. while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
  1008. usleep_range(1000, 2000);
  1009. if (!netif_running(vsi->netdev)) {
  1010. /* simple case - set for the next time the netdev is started */
  1011. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1012. vsi->tx_rings[i]->count = new_tx_count;
  1013. vsi->rx_rings[i]->count = new_rx_count;
  1014. }
  1015. goto done;
  1016. }
  1017. /* We can't just free everything and then setup again,
  1018. * because the ISRs in MSI-X mode get passed pointers
  1019. * to the Tx and Rx ring structs.
  1020. */
  1021. /* alloc updated Tx resources */
  1022. if (new_tx_count != vsi->tx_rings[0]->count) {
  1023. netdev_info(netdev,
  1024. "Changing Tx descriptor count from %d to %d.\n",
  1025. vsi->tx_rings[0]->count, new_tx_count);
  1026. tx_rings = kcalloc(vsi->alloc_queue_pairs,
  1027. sizeof(struct i40e_ring), GFP_KERNEL);
  1028. if (!tx_rings) {
  1029. err = -ENOMEM;
  1030. goto done;
  1031. }
  1032. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1033. /* clone ring and setup updated count */
  1034. tx_rings[i] = *vsi->tx_rings[i];
  1035. tx_rings[i].count = new_tx_count;
  1036. err = i40e_setup_tx_descriptors(&tx_rings[i]);
  1037. if (err) {
  1038. while (i) {
  1039. i--;
  1040. i40e_free_tx_resources(&tx_rings[i]);
  1041. }
  1042. kfree(tx_rings);
  1043. tx_rings = NULL;
  1044. goto done;
  1045. }
  1046. }
  1047. }
  1048. /* alloc updated Rx resources */
  1049. if (new_rx_count != vsi->rx_rings[0]->count) {
  1050. netdev_info(netdev,
  1051. "Changing Rx descriptor count from %d to %d\n",
  1052. vsi->rx_rings[0]->count, new_rx_count);
  1053. rx_rings = kcalloc(vsi->alloc_queue_pairs,
  1054. sizeof(struct i40e_ring), GFP_KERNEL);
  1055. if (!rx_rings) {
  1056. err = -ENOMEM;
  1057. goto free_tx;
  1058. }
  1059. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1060. /* clone ring and setup updated count */
  1061. rx_rings[i] = *vsi->rx_rings[i];
  1062. rx_rings[i].count = new_rx_count;
  1063. err = i40e_setup_rx_descriptors(&rx_rings[i]);
  1064. if (err) {
  1065. while (i) {
  1066. i--;
  1067. i40e_free_rx_resources(&rx_rings[i]);
  1068. }
  1069. kfree(rx_rings);
  1070. rx_rings = NULL;
  1071. goto free_tx;
  1072. }
  1073. }
  1074. }
  1075. /* Bring interface down, copy in the new ring info,
  1076. * then restore the interface
  1077. */
  1078. i40e_down(vsi);
  1079. if (tx_rings) {
  1080. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1081. i40e_free_tx_resources(vsi->tx_rings[i]);
  1082. *vsi->tx_rings[i] = tx_rings[i];
  1083. }
  1084. kfree(tx_rings);
  1085. tx_rings = NULL;
  1086. }
  1087. if (rx_rings) {
  1088. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1089. i40e_free_rx_resources(vsi->rx_rings[i]);
  1090. *vsi->rx_rings[i] = rx_rings[i];
  1091. }
  1092. kfree(rx_rings);
  1093. rx_rings = NULL;
  1094. }
  1095. i40e_up(vsi);
  1096. free_tx:
  1097. /* error cleanup if the Rx allocations failed after getting Tx */
  1098. if (tx_rings) {
  1099. for (i = 0; i < vsi->num_queue_pairs; i++)
  1100. i40e_free_tx_resources(&tx_rings[i]);
  1101. kfree(tx_rings);
  1102. tx_rings = NULL;
  1103. }
  1104. done:
  1105. clear_bit(__I40E_CONFIG_BUSY, &pf->state);
  1106. return err;
  1107. }
  1108. static int i40e_get_sset_count(struct net_device *netdev, int sset)
  1109. {
  1110. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1111. struct i40e_vsi *vsi = np->vsi;
  1112. struct i40e_pf *pf = vsi->back;
  1113. switch (sset) {
  1114. case ETH_SS_TEST:
  1115. return I40E_TEST_LEN;
  1116. case ETH_SS_STATS:
  1117. if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
  1118. int len = I40E_PF_STATS_LEN(netdev);
  1119. if (pf->lan_veb != I40E_NO_VEB)
  1120. len += I40E_VEB_STATS_LEN;
  1121. return len;
  1122. } else {
  1123. return I40E_VSI_STATS_LEN(netdev);
  1124. }
  1125. case ETH_SS_PRIV_FLAGS:
  1126. return I40E_PRIV_FLAGS_STR_LEN;
  1127. default:
  1128. return -EOPNOTSUPP;
  1129. }
  1130. }
  1131. static void i40e_get_ethtool_stats(struct net_device *netdev,
  1132. struct ethtool_stats *stats, u64 *data)
  1133. {
  1134. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1135. struct i40e_ring *tx_ring, *rx_ring;
  1136. struct i40e_vsi *vsi = np->vsi;
  1137. struct i40e_pf *pf = vsi->back;
  1138. int i = 0;
  1139. char *p;
  1140. int j;
  1141. struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
  1142. unsigned int start;
  1143. i40e_update_stats(vsi);
  1144. for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
  1145. p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
  1146. data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
  1147. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1148. }
  1149. for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
  1150. p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
  1151. data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
  1152. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1153. }
  1154. #ifdef I40E_FCOE
  1155. for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
  1156. p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
  1157. data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
  1158. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1159. }
  1160. #endif
  1161. rcu_read_lock();
  1162. for (j = 0; j < vsi->num_queue_pairs; j++) {
  1163. tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
  1164. if (!tx_ring)
  1165. continue;
  1166. /* process Tx ring statistics */
  1167. do {
  1168. start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
  1169. data[i] = tx_ring->stats.packets;
  1170. data[i + 1] = tx_ring->stats.bytes;
  1171. } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
  1172. i += 2;
  1173. /* Rx ring is the 2nd half of the queue pair */
  1174. rx_ring = &tx_ring[1];
  1175. do {
  1176. start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
  1177. data[i] = rx_ring->stats.packets;
  1178. data[i + 1] = rx_ring->stats.bytes;
  1179. } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
  1180. i += 2;
  1181. }
  1182. rcu_read_unlock();
  1183. if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
  1184. return;
  1185. if (pf->lan_veb != I40E_NO_VEB) {
  1186. struct i40e_veb *veb = pf->veb[pf->lan_veb];
  1187. for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
  1188. p = (char *)veb;
  1189. p += i40e_gstrings_veb_stats[j].stat_offset;
  1190. data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
  1191. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1192. }
  1193. }
  1194. for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
  1195. p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
  1196. data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
  1197. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  1198. }
  1199. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
  1200. data[i++] = pf->stats.priority_xon_tx[j];
  1201. data[i++] = pf->stats.priority_xoff_tx[j];
  1202. }
  1203. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
  1204. data[i++] = pf->stats.priority_xon_rx[j];
  1205. data[i++] = pf->stats.priority_xoff_rx[j];
  1206. }
  1207. for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
  1208. data[i++] = pf->stats.priority_xon_2_xoff[j];
  1209. }
  1210. static void i40e_get_strings(struct net_device *netdev, u32 stringset,
  1211. u8 *data)
  1212. {
  1213. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1214. struct i40e_vsi *vsi = np->vsi;
  1215. struct i40e_pf *pf = vsi->back;
  1216. char *p = (char *)data;
  1217. int i;
  1218. switch (stringset) {
  1219. case ETH_SS_TEST:
  1220. for (i = 0; i < I40E_TEST_LEN; i++) {
  1221. memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
  1222. data += ETH_GSTRING_LEN;
  1223. }
  1224. break;
  1225. case ETH_SS_STATS:
  1226. for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
  1227. snprintf(p, ETH_GSTRING_LEN, "%s",
  1228. i40e_gstrings_net_stats[i].stat_string);
  1229. p += ETH_GSTRING_LEN;
  1230. }
  1231. for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
  1232. snprintf(p, ETH_GSTRING_LEN, "%s",
  1233. i40e_gstrings_misc_stats[i].stat_string);
  1234. p += ETH_GSTRING_LEN;
  1235. }
  1236. #ifdef I40E_FCOE
  1237. for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
  1238. snprintf(p, ETH_GSTRING_LEN, "%s",
  1239. i40e_gstrings_fcoe_stats[i].stat_string);
  1240. p += ETH_GSTRING_LEN;
  1241. }
  1242. #endif
  1243. for (i = 0; i < vsi->num_queue_pairs; i++) {
  1244. snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
  1245. p += ETH_GSTRING_LEN;
  1246. snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
  1247. p += ETH_GSTRING_LEN;
  1248. snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
  1249. p += ETH_GSTRING_LEN;
  1250. snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
  1251. p += ETH_GSTRING_LEN;
  1252. }
  1253. if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
  1254. return;
  1255. if (pf->lan_veb != I40E_NO_VEB) {
  1256. for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
  1257. snprintf(p, ETH_GSTRING_LEN, "veb.%s",
  1258. i40e_gstrings_veb_stats[i].stat_string);
  1259. p += ETH_GSTRING_LEN;
  1260. }
  1261. }
  1262. for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
  1263. snprintf(p, ETH_GSTRING_LEN, "port.%s",
  1264. i40e_gstrings_stats[i].stat_string);
  1265. p += ETH_GSTRING_LEN;
  1266. }
  1267. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  1268. snprintf(p, ETH_GSTRING_LEN,
  1269. "port.tx_priority_%u_xon", i);
  1270. p += ETH_GSTRING_LEN;
  1271. snprintf(p, ETH_GSTRING_LEN,
  1272. "port.tx_priority_%u_xoff", i);
  1273. p += ETH_GSTRING_LEN;
  1274. }
  1275. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  1276. snprintf(p, ETH_GSTRING_LEN,
  1277. "port.rx_priority_%u_xon", i);
  1278. p += ETH_GSTRING_LEN;
  1279. snprintf(p, ETH_GSTRING_LEN,
  1280. "port.rx_priority_%u_xoff", i);
  1281. p += ETH_GSTRING_LEN;
  1282. }
  1283. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  1284. snprintf(p, ETH_GSTRING_LEN,
  1285. "port.rx_priority_%u_xon_2_xoff", i);
  1286. p += ETH_GSTRING_LEN;
  1287. }
  1288. /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
  1289. break;
  1290. case ETH_SS_PRIV_FLAGS:
  1291. for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
  1292. memcpy(data, i40e_priv_flags_strings[i],
  1293. ETH_GSTRING_LEN);
  1294. data += ETH_GSTRING_LEN;
  1295. }
  1296. break;
  1297. default:
  1298. break;
  1299. }
  1300. }
  1301. static int i40e_get_ts_info(struct net_device *dev,
  1302. struct ethtool_ts_info *info)
  1303. {
  1304. struct i40e_pf *pf = i40e_netdev_to_pf(dev);
  1305. /* only report HW timestamping if PTP is enabled */
  1306. if (!(pf->flags & I40E_FLAG_PTP))
  1307. return ethtool_op_get_ts_info(dev, info);
  1308. info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
  1309. SOF_TIMESTAMPING_RX_SOFTWARE |
  1310. SOF_TIMESTAMPING_SOFTWARE |
  1311. SOF_TIMESTAMPING_TX_HARDWARE |
  1312. SOF_TIMESTAMPING_RX_HARDWARE |
  1313. SOF_TIMESTAMPING_RAW_HARDWARE;
  1314. if (pf->ptp_clock)
  1315. info->phc_index = ptp_clock_index(pf->ptp_clock);
  1316. else
  1317. info->phc_index = -1;
  1318. info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
  1319. info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
  1320. (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
  1321. (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
  1322. (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
  1323. (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
  1324. (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
  1325. (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
  1326. (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
  1327. (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
  1328. (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
  1329. (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
  1330. (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
  1331. return 0;
  1332. }
  1333. static int i40e_link_test(struct net_device *netdev, u64 *data)
  1334. {
  1335. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1336. struct i40e_pf *pf = np->vsi->back;
  1337. netif_info(pf, hw, netdev, "link test\n");
  1338. if (i40e_get_link_status(&pf->hw))
  1339. *data = 0;
  1340. else
  1341. *data = 1;
  1342. return *data;
  1343. }
  1344. static int i40e_reg_test(struct net_device *netdev, u64 *data)
  1345. {
  1346. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1347. struct i40e_pf *pf = np->vsi->back;
  1348. netif_info(pf, hw, netdev, "register test\n");
  1349. *data = i40e_diag_reg_test(&pf->hw);
  1350. return *data;
  1351. }
  1352. static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
  1353. {
  1354. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1355. struct i40e_pf *pf = np->vsi->back;
  1356. netif_info(pf, hw, netdev, "eeprom test\n");
  1357. *data = i40e_diag_eeprom_test(&pf->hw);
  1358. /* forcebly clear the NVM Update state machine */
  1359. pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
  1360. return *data;
  1361. }
  1362. static int i40e_intr_test(struct net_device *netdev, u64 *data)
  1363. {
  1364. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1365. struct i40e_pf *pf = np->vsi->back;
  1366. u16 swc_old = pf->sw_int_count;
  1367. netif_info(pf, hw, netdev, "interrupt test\n");
  1368. wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
  1369. (I40E_PFINT_DYN_CTL0_INTENA_MASK |
  1370. I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
  1371. I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
  1372. I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
  1373. I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
  1374. usleep_range(1000, 2000);
  1375. *data = (swc_old == pf->sw_int_count);
  1376. return *data;
  1377. }
  1378. static int i40e_loopback_test(struct net_device *netdev, u64 *data)
  1379. {
  1380. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1381. struct i40e_pf *pf = np->vsi->back;
  1382. netif_info(pf, hw, netdev, "loopback test not implemented\n");
  1383. *data = 0;
  1384. return *data;
  1385. }
  1386. static void i40e_diag_test(struct net_device *netdev,
  1387. struct ethtool_test *eth_test, u64 *data)
  1388. {
  1389. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1390. bool if_running = netif_running(netdev);
  1391. struct i40e_pf *pf = np->vsi->back;
  1392. if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
  1393. /* Offline tests */
  1394. netif_info(pf, drv, netdev, "offline testing starting\n");
  1395. set_bit(__I40E_TESTING, &pf->state);
  1396. /* If the device is online then take it offline */
  1397. if (if_running)
  1398. /* indicate we're in test mode */
  1399. dev_close(netdev);
  1400. else
  1401. i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
  1402. /* Link test performed before hardware reset
  1403. * so autoneg doesn't interfere with test result
  1404. */
  1405. if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
  1406. eth_test->flags |= ETH_TEST_FL_FAILED;
  1407. if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
  1408. eth_test->flags |= ETH_TEST_FL_FAILED;
  1409. if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
  1410. eth_test->flags |= ETH_TEST_FL_FAILED;
  1411. if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
  1412. eth_test->flags |= ETH_TEST_FL_FAILED;
  1413. /* run reg test last, a reset is required after it */
  1414. if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
  1415. eth_test->flags |= ETH_TEST_FL_FAILED;
  1416. clear_bit(__I40E_TESTING, &pf->state);
  1417. i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
  1418. if (if_running)
  1419. dev_open(netdev);
  1420. } else {
  1421. /* Online tests */
  1422. netif_info(pf, drv, netdev, "online testing starting\n");
  1423. if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
  1424. eth_test->flags |= ETH_TEST_FL_FAILED;
  1425. /* Offline only tests, not run in online; pass by default */
  1426. data[I40E_ETH_TEST_REG] = 0;
  1427. data[I40E_ETH_TEST_EEPROM] = 0;
  1428. data[I40E_ETH_TEST_INTR] = 0;
  1429. data[I40E_ETH_TEST_LOOPBACK] = 0;
  1430. }
  1431. netif_info(pf, drv, netdev, "testing finished\n");
  1432. }
  1433. static void i40e_get_wol(struct net_device *netdev,
  1434. struct ethtool_wolinfo *wol)
  1435. {
  1436. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1437. struct i40e_pf *pf = np->vsi->back;
  1438. struct i40e_hw *hw = &pf->hw;
  1439. u16 wol_nvm_bits;
  1440. /* NVM bit on means WoL disabled for the port */
  1441. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  1442. if ((1 << hw->port) & wol_nvm_bits || hw->partition_id != 1) {
  1443. wol->supported = 0;
  1444. wol->wolopts = 0;
  1445. } else {
  1446. wol->supported = WAKE_MAGIC;
  1447. wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
  1448. }
  1449. }
  1450. /**
  1451. * i40e_set_wol - set the WakeOnLAN configuration
  1452. * @netdev: the netdev in question
  1453. * @wol: the ethtool WoL setting data
  1454. **/
  1455. static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  1456. {
  1457. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1458. struct i40e_pf *pf = np->vsi->back;
  1459. struct i40e_vsi *vsi = np->vsi;
  1460. struct i40e_hw *hw = &pf->hw;
  1461. u16 wol_nvm_bits;
  1462. /* WoL not supported if this isn't the controlling PF on the port */
  1463. if (hw->partition_id != 1) {
  1464. i40e_partition_setting_complaint(pf);
  1465. return -EOPNOTSUPP;
  1466. }
  1467. if (vsi != pf->vsi[pf->lan_vsi])
  1468. return -EOPNOTSUPP;
  1469. /* NVM bit on means WoL disabled for the port */
  1470. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  1471. if (((1 << hw->port) & wol_nvm_bits))
  1472. return -EOPNOTSUPP;
  1473. /* only magic packet is supported */
  1474. if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
  1475. return -EOPNOTSUPP;
  1476. /* is this a new value? */
  1477. if (pf->wol_en != !!wol->wolopts) {
  1478. pf->wol_en = !!wol->wolopts;
  1479. device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
  1480. }
  1481. return 0;
  1482. }
  1483. static int i40e_set_phys_id(struct net_device *netdev,
  1484. enum ethtool_phys_id_state state)
  1485. {
  1486. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1487. struct i40e_pf *pf = np->vsi->back;
  1488. struct i40e_hw *hw = &pf->hw;
  1489. int blink_freq = 2;
  1490. switch (state) {
  1491. case ETHTOOL_ID_ACTIVE:
  1492. pf->led_status = i40e_led_get(hw);
  1493. return blink_freq;
  1494. case ETHTOOL_ID_ON:
  1495. i40e_led_set(hw, 0xF, false);
  1496. break;
  1497. case ETHTOOL_ID_OFF:
  1498. i40e_led_set(hw, 0x0, false);
  1499. break;
  1500. case ETHTOOL_ID_INACTIVE:
  1501. i40e_led_set(hw, pf->led_status, false);
  1502. break;
  1503. default:
  1504. break;
  1505. }
  1506. return 0;
  1507. }
  1508. /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
  1509. * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
  1510. * 125us (8000 interrupts per second) == ITR(62)
  1511. */
  1512. static int i40e_get_coalesce(struct net_device *netdev,
  1513. struct ethtool_coalesce *ec)
  1514. {
  1515. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1516. struct i40e_vsi *vsi = np->vsi;
  1517. ec->tx_max_coalesced_frames_irq = vsi->work_limit;
  1518. ec->rx_max_coalesced_frames_irq = vsi->work_limit;
  1519. if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
  1520. ec->use_adaptive_rx_coalesce = 1;
  1521. if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
  1522. ec->use_adaptive_tx_coalesce = 1;
  1523. ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
  1524. ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
  1525. return 0;
  1526. }
  1527. static int i40e_set_coalesce(struct net_device *netdev,
  1528. struct ethtool_coalesce *ec)
  1529. {
  1530. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1531. struct i40e_q_vector *q_vector;
  1532. struct i40e_vsi *vsi = np->vsi;
  1533. struct i40e_pf *pf = vsi->back;
  1534. struct i40e_hw *hw = &pf->hw;
  1535. u16 vector;
  1536. int i;
  1537. if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
  1538. vsi->work_limit = ec->tx_max_coalesced_frames_irq;
  1539. vector = vsi->base_vector;
  1540. if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
  1541. (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
  1542. vsi->rx_itr_setting = ec->rx_coalesce_usecs;
  1543. } else if (ec->rx_coalesce_usecs == 0) {
  1544. vsi->rx_itr_setting = ec->rx_coalesce_usecs;
  1545. if (ec->use_adaptive_rx_coalesce)
  1546. netif_info(pf, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
  1547. } else {
  1548. netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
  1549. return -EINVAL;
  1550. }
  1551. if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
  1552. (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
  1553. vsi->tx_itr_setting = ec->tx_coalesce_usecs;
  1554. } else if (ec->tx_coalesce_usecs == 0) {
  1555. vsi->tx_itr_setting = ec->tx_coalesce_usecs;
  1556. if (ec->use_adaptive_tx_coalesce)
  1557. netif_info(pf, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
  1558. } else {
  1559. netif_info(pf, drv, netdev,
  1560. "Invalid value, tx-usecs range is 0-8160\n");
  1561. return -EINVAL;
  1562. }
  1563. if (ec->use_adaptive_rx_coalesce)
  1564. vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
  1565. else
  1566. vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
  1567. if (ec->use_adaptive_tx_coalesce)
  1568. vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
  1569. else
  1570. vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
  1571. for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
  1572. q_vector = vsi->q_vectors[i];
  1573. q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
  1574. wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
  1575. q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
  1576. wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
  1577. i40e_flush(hw);
  1578. }
  1579. return 0;
  1580. }
  1581. /**
  1582. * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
  1583. * @pf: pointer to the physical function struct
  1584. * @cmd: ethtool rxnfc command
  1585. *
  1586. * Returns Success if the flow is supported, else Invalid Input.
  1587. **/
  1588. static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
  1589. {
  1590. cmd->data = 0;
  1591. if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
  1592. cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
  1593. cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
  1594. return 0;
  1595. }
  1596. /* Report default options for RSS on i40e */
  1597. switch (cmd->flow_type) {
  1598. case TCP_V4_FLOW:
  1599. case UDP_V4_FLOW:
  1600. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1601. /* fall through to add IP fields */
  1602. case SCTP_V4_FLOW:
  1603. case AH_ESP_V4_FLOW:
  1604. case AH_V4_FLOW:
  1605. case ESP_V4_FLOW:
  1606. case IPV4_FLOW:
  1607. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  1608. break;
  1609. case TCP_V6_FLOW:
  1610. case UDP_V6_FLOW:
  1611. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1612. /* fall through to add IP fields */
  1613. case SCTP_V6_FLOW:
  1614. case AH_ESP_V6_FLOW:
  1615. case AH_V6_FLOW:
  1616. case ESP_V6_FLOW:
  1617. case IPV6_FLOW:
  1618. cmd->data |= RXH_IP_SRC | RXH_IP_DST;
  1619. break;
  1620. default:
  1621. return -EINVAL;
  1622. }
  1623. return 0;
  1624. }
  1625. /**
  1626. * i40e_get_ethtool_fdir_all - Populates the rule count of a command
  1627. * @pf: Pointer to the physical function struct
  1628. * @cmd: The command to get or set Rx flow classification rules
  1629. * @rule_locs: Array of used rule locations
  1630. *
  1631. * This function populates both the total and actual rule count of
  1632. * the ethtool flow classification command
  1633. *
  1634. * Returns 0 on success or -EMSGSIZE if entry not found
  1635. **/
  1636. static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
  1637. struct ethtool_rxnfc *cmd,
  1638. u32 *rule_locs)
  1639. {
  1640. struct i40e_fdir_filter *rule;
  1641. struct hlist_node *node2;
  1642. int cnt = 0;
  1643. /* report total rule count */
  1644. cmd->data = i40e_get_fd_cnt_all(pf);
  1645. hlist_for_each_entry_safe(rule, node2,
  1646. &pf->fdir_filter_list, fdir_node) {
  1647. if (cnt == cmd->rule_cnt)
  1648. return -EMSGSIZE;
  1649. rule_locs[cnt] = rule->fd_id;
  1650. cnt++;
  1651. }
  1652. cmd->rule_cnt = cnt;
  1653. return 0;
  1654. }
  1655. /**
  1656. * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
  1657. * @pf: Pointer to the physical function struct
  1658. * @cmd: The command to get or set Rx flow classification rules
  1659. *
  1660. * This function looks up a filter based on the Rx flow classification
  1661. * command and fills the flow spec info for it if found
  1662. *
  1663. * Returns 0 on success or -EINVAL if filter not found
  1664. **/
  1665. static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
  1666. struct ethtool_rxnfc *cmd)
  1667. {
  1668. struct ethtool_rx_flow_spec *fsp =
  1669. (struct ethtool_rx_flow_spec *)&cmd->fs;
  1670. struct i40e_fdir_filter *rule = NULL;
  1671. struct hlist_node *node2;
  1672. hlist_for_each_entry_safe(rule, node2,
  1673. &pf->fdir_filter_list, fdir_node) {
  1674. if (fsp->location <= rule->fd_id)
  1675. break;
  1676. }
  1677. if (!rule || fsp->location != rule->fd_id)
  1678. return -EINVAL;
  1679. fsp->flow_type = rule->flow_type;
  1680. if (fsp->flow_type == IP_USER_FLOW) {
  1681. fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
  1682. fsp->h_u.usr_ip4_spec.proto = 0;
  1683. fsp->m_u.usr_ip4_spec.proto = 0;
  1684. }
  1685. /* Reverse the src and dest notion, since the HW views them from
  1686. * Tx perspective where as the user expects it from Rx filter view.
  1687. */
  1688. fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
  1689. fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
  1690. fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
  1691. fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
  1692. if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
  1693. fsp->ring_cookie = RX_CLS_FLOW_DISC;
  1694. else
  1695. fsp->ring_cookie = rule->q_index;
  1696. if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
  1697. struct i40e_vsi *vsi;
  1698. vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
  1699. if (vsi && vsi->type == I40E_VSI_SRIOV) {
  1700. fsp->h_ext.data[1] = htonl(vsi->vf_id);
  1701. fsp->m_ext.data[1] = htonl(0x1);
  1702. }
  1703. }
  1704. return 0;
  1705. }
  1706. /**
  1707. * i40e_get_rxnfc - command to get RX flow classification rules
  1708. * @netdev: network interface device structure
  1709. * @cmd: ethtool rxnfc command
  1710. *
  1711. * Returns Success if the command is supported.
  1712. **/
  1713. static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
  1714. u32 *rule_locs)
  1715. {
  1716. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1717. struct i40e_vsi *vsi = np->vsi;
  1718. struct i40e_pf *pf = vsi->back;
  1719. int ret = -EOPNOTSUPP;
  1720. switch (cmd->cmd) {
  1721. case ETHTOOL_GRXRINGS:
  1722. cmd->data = vsi->alloc_queue_pairs;
  1723. ret = 0;
  1724. break;
  1725. case ETHTOOL_GRXFH:
  1726. ret = i40e_get_rss_hash_opts(pf, cmd);
  1727. break;
  1728. case ETHTOOL_GRXCLSRLCNT:
  1729. cmd->rule_cnt = pf->fdir_pf_active_filters;
  1730. /* report total rule count */
  1731. cmd->data = i40e_get_fd_cnt_all(pf);
  1732. ret = 0;
  1733. break;
  1734. case ETHTOOL_GRXCLSRULE:
  1735. ret = i40e_get_ethtool_fdir_entry(pf, cmd);
  1736. break;
  1737. case ETHTOOL_GRXCLSRLALL:
  1738. ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
  1739. break;
  1740. default:
  1741. break;
  1742. }
  1743. return ret;
  1744. }
  1745. /**
  1746. * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
  1747. * @pf: pointer to the physical function struct
  1748. * @cmd: ethtool rxnfc command
  1749. *
  1750. * Returns Success if the flow input set is supported.
  1751. **/
  1752. static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
  1753. {
  1754. struct i40e_hw *hw = &pf->hw;
  1755. u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
  1756. ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
  1757. /* RSS does not support anything other than hashing
  1758. * to queues on src and dst IPs and ports
  1759. */
  1760. if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
  1761. RXH_L4_B_0_1 | RXH_L4_B_2_3))
  1762. return -EINVAL;
  1763. /* We need at least the IP SRC and DEST fields for hashing */
  1764. if (!(nfc->data & RXH_IP_SRC) ||
  1765. !(nfc->data & RXH_IP_DST))
  1766. return -EINVAL;
  1767. switch (nfc->flow_type) {
  1768. case TCP_V4_FLOW:
  1769. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  1770. case 0:
  1771. hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
  1772. break;
  1773. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  1774. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
  1775. break;
  1776. default:
  1777. return -EINVAL;
  1778. }
  1779. break;
  1780. case TCP_V6_FLOW:
  1781. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  1782. case 0:
  1783. hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
  1784. break;
  1785. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  1786. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
  1787. break;
  1788. default:
  1789. return -EINVAL;
  1790. }
  1791. break;
  1792. case UDP_V4_FLOW:
  1793. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  1794. case 0:
  1795. hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
  1796. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
  1797. break;
  1798. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  1799. hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
  1800. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
  1801. break;
  1802. default:
  1803. return -EINVAL;
  1804. }
  1805. break;
  1806. case UDP_V6_FLOW:
  1807. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  1808. case 0:
  1809. hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
  1810. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
  1811. break;
  1812. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  1813. hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
  1814. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
  1815. break;
  1816. default:
  1817. return -EINVAL;
  1818. }
  1819. break;
  1820. case AH_ESP_V4_FLOW:
  1821. case AH_V4_FLOW:
  1822. case ESP_V4_FLOW:
  1823. case SCTP_V4_FLOW:
  1824. if ((nfc->data & RXH_L4_B_0_1) ||
  1825. (nfc->data & RXH_L4_B_2_3))
  1826. return -EINVAL;
  1827. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
  1828. break;
  1829. case AH_ESP_V6_FLOW:
  1830. case AH_V6_FLOW:
  1831. case ESP_V6_FLOW:
  1832. case SCTP_V6_FLOW:
  1833. if ((nfc->data & RXH_L4_B_0_1) ||
  1834. (nfc->data & RXH_L4_B_2_3))
  1835. return -EINVAL;
  1836. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
  1837. break;
  1838. case IPV4_FLOW:
  1839. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
  1840. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
  1841. break;
  1842. case IPV6_FLOW:
  1843. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
  1844. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
  1845. break;
  1846. default:
  1847. return -EINVAL;
  1848. }
  1849. wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
  1850. wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
  1851. i40e_flush(hw);
  1852. /* Save setting for future output/update */
  1853. pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
  1854. return 0;
  1855. }
  1856. /**
  1857. * i40e_match_fdir_input_set - Match a new filter against an existing one
  1858. * @rule: The filter already added
  1859. * @input: The new filter to comapre against
  1860. *
  1861. * Returns true if the two input set match
  1862. **/
  1863. static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
  1864. struct i40e_fdir_filter *input)
  1865. {
  1866. if ((rule->dst_ip[0] != input->dst_ip[0]) ||
  1867. (rule->src_ip[0] != input->src_ip[0]) ||
  1868. (rule->dst_port != input->dst_port) ||
  1869. (rule->src_port != input->src_port))
  1870. return false;
  1871. return true;
  1872. }
  1873. /**
  1874. * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
  1875. * @vsi: Pointer to the targeted VSI
  1876. * @input: The filter to update or NULL to indicate deletion
  1877. * @sw_idx: Software index to the filter
  1878. * @cmd: The command to get or set Rx flow classification rules
  1879. *
  1880. * This function updates (or deletes) a Flow Director entry from
  1881. * the hlist of the corresponding PF
  1882. *
  1883. * Returns 0 on success
  1884. **/
  1885. static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
  1886. struct i40e_fdir_filter *input,
  1887. u16 sw_idx,
  1888. struct ethtool_rxnfc *cmd)
  1889. {
  1890. struct i40e_fdir_filter *rule, *parent;
  1891. struct i40e_pf *pf = vsi->back;
  1892. struct hlist_node *node2;
  1893. int err = -EINVAL;
  1894. parent = NULL;
  1895. rule = NULL;
  1896. hlist_for_each_entry_safe(rule, node2,
  1897. &pf->fdir_filter_list, fdir_node) {
  1898. /* hash found, or no matching entry */
  1899. if (rule->fd_id >= sw_idx)
  1900. break;
  1901. parent = rule;
  1902. }
  1903. /* if there is an old rule occupying our place remove it */
  1904. if (rule && (rule->fd_id == sw_idx)) {
  1905. if (input && !i40e_match_fdir_input_set(rule, input))
  1906. err = i40e_add_del_fdir(vsi, rule, false);
  1907. else if (!input)
  1908. err = i40e_add_del_fdir(vsi, rule, false);
  1909. hlist_del(&rule->fdir_node);
  1910. kfree(rule);
  1911. pf->fdir_pf_active_filters--;
  1912. }
  1913. /* If no input this was a delete, err should be 0 if a rule was
  1914. * successfully found and removed from the list else -EINVAL
  1915. */
  1916. if (!input)
  1917. return err;
  1918. /* initialize node and set software index */
  1919. INIT_HLIST_NODE(&input->fdir_node);
  1920. /* add filter to the list */
  1921. if (parent)
  1922. hlist_add_behind(&input->fdir_node, &parent->fdir_node);
  1923. else
  1924. hlist_add_head(&input->fdir_node,
  1925. &pf->fdir_filter_list);
  1926. /* update counts */
  1927. pf->fdir_pf_active_filters++;
  1928. return 0;
  1929. }
  1930. /**
  1931. * i40e_del_fdir_entry - Deletes a Flow Director filter entry
  1932. * @vsi: Pointer to the targeted VSI
  1933. * @cmd: The command to get or set Rx flow classification rules
  1934. *
  1935. * The function removes a Flow Director filter entry from the
  1936. * hlist of the corresponding PF
  1937. *
  1938. * Returns 0 on success
  1939. */
  1940. static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
  1941. struct ethtool_rxnfc *cmd)
  1942. {
  1943. struct ethtool_rx_flow_spec *fsp =
  1944. (struct ethtool_rx_flow_spec *)&cmd->fs;
  1945. struct i40e_pf *pf = vsi->back;
  1946. int ret = 0;
  1947. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  1948. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  1949. return -EBUSY;
  1950. if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
  1951. return -EBUSY;
  1952. ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
  1953. i40e_fdir_check_and_reenable(pf);
  1954. return ret;
  1955. }
  1956. /**
  1957. * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
  1958. * @vsi: pointer to the targeted VSI
  1959. * @cmd: command to get or set RX flow classification rules
  1960. *
  1961. * Add Flow Director filters for a specific flow spec based on their
  1962. * protocol. Returns 0 if the filters were successfully added.
  1963. **/
  1964. static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
  1965. struct ethtool_rxnfc *cmd)
  1966. {
  1967. struct ethtool_rx_flow_spec *fsp;
  1968. struct i40e_fdir_filter *input;
  1969. struct i40e_pf *pf;
  1970. int ret = -EINVAL;
  1971. u16 vf_id;
  1972. if (!vsi)
  1973. return -EINVAL;
  1974. pf = vsi->back;
  1975. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  1976. return -EOPNOTSUPP;
  1977. if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
  1978. return -ENOSPC;
  1979. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
  1980. test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
  1981. return -EBUSY;
  1982. if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
  1983. return -EBUSY;
  1984. fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
  1985. if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
  1986. pf->hw.func_caps.fd_filters_guaranteed)) {
  1987. return -EINVAL;
  1988. }
  1989. if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
  1990. (fsp->ring_cookie >= vsi->num_queue_pairs))
  1991. return -EINVAL;
  1992. input = kzalloc(sizeof(*input), GFP_KERNEL);
  1993. if (!input)
  1994. return -ENOMEM;
  1995. input->fd_id = fsp->location;
  1996. if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
  1997. input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
  1998. else
  1999. input->dest_ctl =
  2000. I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
  2001. input->q_index = fsp->ring_cookie;
  2002. input->flex_off = 0;
  2003. input->pctype = 0;
  2004. input->dest_vsi = vsi->id;
  2005. input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
  2006. input->cnt_index = pf->fd_sb_cnt_idx;
  2007. input->flow_type = fsp->flow_type;
  2008. input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
  2009. /* Reverse the src and dest notion, since the HW expects them to be from
  2010. * Tx perspective where as the input from user is from Rx filter view.
  2011. */
  2012. input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
  2013. input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
  2014. input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
  2015. input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
  2016. if (ntohl(fsp->m_ext.data[1])) {
  2017. if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
  2018. netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
  2019. goto free_input;
  2020. }
  2021. vf_id = ntohl(fsp->h_ext.data[1]);
  2022. /* Find vsi id from vf id and override dest vsi */
  2023. input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
  2024. if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
  2025. netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
  2026. goto free_input;
  2027. }
  2028. }
  2029. ret = i40e_add_del_fdir(vsi, input, true);
  2030. free_input:
  2031. if (ret)
  2032. kfree(input);
  2033. else
  2034. i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
  2035. return ret;
  2036. }
  2037. /**
  2038. * i40e_set_rxnfc - command to set RX flow classification rules
  2039. * @netdev: network interface device structure
  2040. * @cmd: ethtool rxnfc command
  2041. *
  2042. * Returns Success if the command is supported.
  2043. **/
  2044. static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
  2045. {
  2046. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2047. struct i40e_vsi *vsi = np->vsi;
  2048. struct i40e_pf *pf = vsi->back;
  2049. int ret = -EOPNOTSUPP;
  2050. switch (cmd->cmd) {
  2051. case ETHTOOL_SRXFH:
  2052. ret = i40e_set_rss_hash_opt(pf, cmd);
  2053. break;
  2054. case ETHTOOL_SRXCLSRLINS:
  2055. ret = i40e_add_fdir_ethtool(vsi, cmd);
  2056. break;
  2057. case ETHTOOL_SRXCLSRLDEL:
  2058. ret = i40e_del_fdir_entry(vsi, cmd);
  2059. break;
  2060. default:
  2061. break;
  2062. }
  2063. return ret;
  2064. }
  2065. /**
  2066. * i40e_max_channels - get Max number of combined channels supported
  2067. * @vsi: vsi pointer
  2068. **/
  2069. static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
  2070. {
  2071. /* TODO: This code assumes DCB and FD is disabled for now. */
  2072. return vsi->alloc_queue_pairs;
  2073. }
  2074. /**
  2075. * i40e_get_channels - Get the current channels enabled and max supported etc.
  2076. * @netdev: network interface device structure
  2077. * @ch: ethtool channels structure
  2078. *
  2079. * We don't support separate tx and rx queues as channels. The other count
  2080. * represents how many queues are being used for control. max_combined counts
  2081. * how many queue pairs we can support. They may not be mapped 1 to 1 with
  2082. * q_vectors since we support a lot more queue pairs than q_vectors.
  2083. **/
  2084. static void i40e_get_channels(struct net_device *dev,
  2085. struct ethtool_channels *ch)
  2086. {
  2087. struct i40e_netdev_priv *np = netdev_priv(dev);
  2088. struct i40e_vsi *vsi = np->vsi;
  2089. struct i40e_pf *pf = vsi->back;
  2090. /* report maximum channels */
  2091. ch->max_combined = i40e_max_channels(vsi);
  2092. /* report info for other vector */
  2093. ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
  2094. ch->max_other = ch->other_count;
  2095. /* Note: This code assumes DCB is disabled for now. */
  2096. ch->combined_count = vsi->num_queue_pairs;
  2097. }
  2098. /**
  2099. * i40e_set_channels - Set the new channels count.
  2100. * @netdev: network interface device structure
  2101. * @ch: ethtool channels structure
  2102. *
  2103. * The new channels count may not be the same as requested by the user
  2104. * since it gets rounded down to a power of 2 value.
  2105. **/
  2106. static int i40e_set_channels(struct net_device *dev,
  2107. struct ethtool_channels *ch)
  2108. {
  2109. struct i40e_netdev_priv *np = netdev_priv(dev);
  2110. unsigned int count = ch->combined_count;
  2111. struct i40e_vsi *vsi = np->vsi;
  2112. struct i40e_pf *pf = vsi->back;
  2113. int new_count;
  2114. /* We do not support setting channels for any other VSI at present */
  2115. if (vsi->type != I40E_VSI_MAIN)
  2116. return -EINVAL;
  2117. /* verify they are not requesting separate vectors */
  2118. if (!count || ch->rx_count || ch->tx_count)
  2119. return -EINVAL;
  2120. /* verify other_count has not changed */
  2121. if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
  2122. return -EINVAL;
  2123. /* verify the number of channels does not exceed hardware limits */
  2124. if (count > i40e_max_channels(vsi))
  2125. return -EINVAL;
  2126. /* update feature limits from largest to smallest supported values */
  2127. /* TODO: Flow director limit, DCB etc */
  2128. /* use rss_reconfig to rebuild with new queue count and update traffic
  2129. * class queue mapping
  2130. */
  2131. new_count = i40e_reconfig_rss_queues(pf, count);
  2132. if (new_count > 0)
  2133. return 0;
  2134. else
  2135. return -EINVAL;
  2136. }
  2137. #define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
  2138. /**
  2139. * i40e_get_rxfh_key_size - get the RSS hash key size
  2140. * @netdev: network interface device structure
  2141. *
  2142. * Returns the table size.
  2143. **/
  2144. static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
  2145. {
  2146. return I40E_HKEY_ARRAY_SIZE;
  2147. }
  2148. /**
  2149. * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
  2150. * @netdev: network interface device structure
  2151. *
  2152. * Returns the table size.
  2153. **/
  2154. static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
  2155. {
  2156. return I40E_HLUT_ARRAY_SIZE;
  2157. }
  2158. static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
  2159. u8 *hfunc)
  2160. {
  2161. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2162. struct i40e_vsi *vsi = np->vsi;
  2163. struct i40e_pf *pf = vsi->back;
  2164. struct i40e_hw *hw = &pf->hw;
  2165. u32 reg_val;
  2166. int i, j;
  2167. if (hfunc)
  2168. *hfunc = ETH_RSS_HASH_TOP;
  2169. if (!indir)
  2170. return 0;
  2171. for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
  2172. reg_val = rd32(hw, I40E_PFQF_HLUT(i));
  2173. indir[j++] = reg_val & 0xff;
  2174. indir[j++] = (reg_val >> 8) & 0xff;
  2175. indir[j++] = (reg_val >> 16) & 0xff;
  2176. indir[j++] = (reg_val >> 24) & 0xff;
  2177. }
  2178. if (key) {
  2179. for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
  2180. reg_val = rd32(hw, I40E_PFQF_HKEY(i));
  2181. key[j++] = (u8)(reg_val & 0xff);
  2182. key[j++] = (u8)((reg_val >> 8) & 0xff);
  2183. key[j++] = (u8)((reg_val >> 16) & 0xff);
  2184. key[j++] = (u8)((reg_val >> 24) & 0xff);
  2185. }
  2186. }
  2187. return 0;
  2188. }
  2189. /**
  2190. * i40e_set_rxfh - set the rx flow hash indirection table
  2191. * @netdev: network interface device structure
  2192. * @indir: indirection table
  2193. * @key: hash key
  2194. *
  2195. * Returns -EINVAL if the table specifies an inavlid queue id, otherwise
  2196. * returns 0 after programming the table.
  2197. **/
  2198. static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
  2199. const u8 *key, const u8 hfunc)
  2200. {
  2201. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2202. struct i40e_vsi *vsi = np->vsi;
  2203. struct i40e_pf *pf = vsi->back;
  2204. struct i40e_hw *hw = &pf->hw;
  2205. u32 reg_val;
  2206. int i, j;
  2207. if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
  2208. return -EOPNOTSUPP;
  2209. if (!indir)
  2210. return 0;
  2211. for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
  2212. reg_val = indir[j++];
  2213. reg_val |= indir[j++] << 8;
  2214. reg_val |= indir[j++] << 16;
  2215. reg_val |= indir[j++] << 24;
  2216. wr32(hw, I40E_PFQF_HLUT(i), reg_val);
  2217. }
  2218. if (key) {
  2219. for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
  2220. reg_val = key[j++];
  2221. reg_val |= key[j++] << 8;
  2222. reg_val |= key[j++] << 16;
  2223. reg_val |= key[j++] << 24;
  2224. wr32(hw, I40E_PFQF_HKEY(i), reg_val);
  2225. }
  2226. }
  2227. return 0;
  2228. }
  2229. /**
  2230. * i40e_get_priv_flags - report device private flags
  2231. * @dev: network interface device structure
  2232. *
  2233. * The get string set count and the string set should be matched for each
  2234. * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
  2235. * array.
  2236. *
  2237. * Returns a u32 bitmap of flags.
  2238. **/
  2239. static u32 i40e_get_priv_flags(struct net_device *dev)
  2240. {
  2241. struct i40e_netdev_priv *np = netdev_priv(dev);
  2242. struct i40e_vsi *vsi = np->vsi;
  2243. struct i40e_pf *pf = vsi->back;
  2244. u32 ret_flags = 0;
  2245. ret_flags |= pf->hw.func_caps.npar_enable ?
  2246. I40E_PRIV_FLAGS_NPAR_FLAG : 0;
  2247. return ret_flags;
  2248. }
  2249. static const struct ethtool_ops i40e_ethtool_ops = {
  2250. .get_settings = i40e_get_settings,
  2251. .set_settings = i40e_set_settings,
  2252. .get_drvinfo = i40e_get_drvinfo,
  2253. .get_regs_len = i40e_get_regs_len,
  2254. .get_regs = i40e_get_regs,
  2255. .nway_reset = i40e_nway_reset,
  2256. .get_link = ethtool_op_get_link,
  2257. .get_wol = i40e_get_wol,
  2258. .set_wol = i40e_set_wol,
  2259. .set_eeprom = i40e_set_eeprom,
  2260. .get_eeprom_len = i40e_get_eeprom_len,
  2261. .get_eeprom = i40e_get_eeprom,
  2262. .get_ringparam = i40e_get_ringparam,
  2263. .set_ringparam = i40e_set_ringparam,
  2264. .get_pauseparam = i40e_get_pauseparam,
  2265. .set_pauseparam = i40e_set_pauseparam,
  2266. .get_msglevel = i40e_get_msglevel,
  2267. .set_msglevel = i40e_set_msglevel,
  2268. .get_rxnfc = i40e_get_rxnfc,
  2269. .set_rxnfc = i40e_set_rxnfc,
  2270. .self_test = i40e_diag_test,
  2271. .get_strings = i40e_get_strings,
  2272. .set_phys_id = i40e_set_phys_id,
  2273. .get_sset_count = i40e_get_sset_count,
  2274. .get_ethtool_stats = i40e_get_ethtool_stats,
  2275. .get_coalesce = i40e_get_coalesce,
  2276. .set_coalesce = i40e_set_coalesce,
  2277. .get_rxfh_key_size = i40e_get_rxfh_key_size,
  2278. .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
  2279. .get_rxfh = i40e_get_rxfh,
  2280. .set_rxfh = i40e_set_rxfh,
  2281. .get_channels = i40e_get_channels,
  2282. .set_channels = i40e_set_channels,
  2283. .get_ts_info = i40e_get_ts_info,
  2284. .get_priv_flags = i40e_get_priv_flags,
  2285. };
  2286. void i40e_set_ethtool_ops(struct net_device *netdev)
  2287. {
  2288. netdev->ethtool_ops = &i40e_ethtool_ops;
  2289. }