i40e_ethtool.c 70 KB

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