i40e_ethtool.c 64 KB

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