idpf_ethtool.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* Copyright (C) 2023 Intel Corporation */
  3. #include "idpf.h"
  4. /**
  5. * idpf_get_rxnfc - command to get RX flow classification rules
  6. * @netdev: network interface device structure
  7. * @cmd: ethtool rxnfc command
  8. * @rule_locs: pointer to store rule locations
  9. *
  10. * Returns Success if the command is supported.
  11. */
  12. static int idpf_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
  13. u32 __always_unused *rule_locs)
  14. {
  15. struct idpf_vport *vport;
  16. idpf_vport_ctrl_lock(netdev);
  17. vport = idpf_netdev_to_vport(netdev);
  18. switch (cmd->cmd) {
  19. case ETHTOOL_GRXRINGS:
  20. cmd->data = vport->num_rxq;
  21. idpf_vport_ctrl_unlock(netdev);
  22. return 0;
  23. default:
  24. break;
  25. }
  26. idpf_vport_ctrl_unlock(netdev);
  27. return -EOPNOTSUPP;
  28. }
  29. /**
  30. * idpf_get_rxfh_key_size - get the RSS hash key size
  31. * @netdev: network interface device structure
  32. *
  33. * Returns the key size on success, error value on failure.
  34. */
  35. static u32 idpf_get_rxfh_key_size(struct net_device *netdev)
  36. {
  37. struct idpf_netdev_priv *np = netdev_priv(netdev);
  38. struct idpf_vport_user_config_data *user_config;
  39. if (!idpf_is_cap_ena_all(np->adapter, IDPF_RSS_CAPS, IDPF_CAP_RSS))
  40. return 0;
  41. user_config = &np->adapter->vport_config[np->vport_idx]->user_config;
  42. return user_config->rss_data.rss_key_size;
  43. }
  44. /**
  45. * idpf_get_rxfh_indir_size - get the rx flow hash indirection table size
  46. * @netdev: network interface device structure
  47. *
  48. * Returns the table size on success, error value on failure.
  49. */
  50. static u32 idpf_get_rxfh_indir_size(struct net_device *netdev)
  51. {
  52. struct idpf_netdev_priv *np = netdev_priv(netdev);
  53. struct idpf_vport_user_config_data *user_config;
  54. if (!idpf_is_cap_ena_all(np->adapter, IDPF_RSS_CAPS, IDPF_CAP_RSS))
  55. return 0;
  56. user_config = &np->adapter->vport_config[np->vport_idx]->user_config;
  57. return user_config->rss_data.rss_lut_size;
  58. }
  59. /**
  60. * idpf_get_rxfh - get the rx flow hash indirection table
  61. * @netdev: network interface device structure
  62. * @rxfh: pointer to param struct (indir, key, hfunc)
  63. *
  64. * Reads the indirection table directly from the hardware. Always returns 0.
  65. */
  66. static int idpf_get_rxfh(struct net_device *netdev,
  67. struct ethtool_rxfh_param *rxfh)
  68. {
  69. struct idpf_netdev_priv *np = netdev_priv(netdev);
  70. struct idpf_rss_data *rss_data;
  71. struct idpf_adapter *adapter;
  72. int err = 0;
  73. u16 i;
  74. idpf_vport_ctrl_lock(netdev);
  75. adapter = np->adapter;
  76. if (!idpf_is_cap_ena_all(adapter, IDPF_RSS_CAPS, IDPF_CAP_RSS)) {
  77. err = -EOPNOTSUPP;
  78. goto unlock_mutex;
  79. }
  80. rss_data = &adapter->vport_config[np->vport_idx]->user_config.rss_data;
  81. if (np->state != __IDPF_VPORT_UP)
  82. goto unlock_mutex;
  83. rxfh->hfunc = ETH_RSS_HASH_TOP;
  84. if (rxfh->key)
  85. memcpy(rxfh->key, rss_data->rss_key, rss_data->rss_key_size);
  86. if (rxfh->indir) {
  87. for (i = 0; i < rss_data->rss_lut_size; i++)
  88. rxfh->indir[i] = rss_data->rss_lut[i];
  89. }
  90. unlock_mutex:
  91. idpf_vport_ctrl_unlock(netdev);
  92. return err;
  93. }
  94. /**
  95. * idpf_set_rxfh - set the rx flow hash indirection table
  96. * @netdev: network interface device structure
  97. * @rxfh: pointer to param struct (indir, key, hfunc)
  98. * @extack: extended ACK from the Netlink message
  99. *
  100. * Returns -EINVAL if the table specifies an invalid queue id, otherwise
  101. * returns 0 after programming the table.
  102. */
  103. static int idpf_set_rxfh(struct net_device *netdev,
  104. struct ethtool_rxfh_param *rxfh,
  105. struct netlink_ext_ack *extack)
  106. {
  107. struct idpf_netdev_priv *np = netdev_priv(netdev);
  108. struct idpf_rss_data *rss_data;
  109. struct idpf_adapter *adapter;
  110. struct idpf_vport *vport;
  111. int err = 0;
  112. u16 lut;
  113. idpf_vport_ctrl_lock(netdev);
  114. vport = idpf_netdev_to_vport(netdev);
  115. adapter = vport->adapter;
  116. if (!idpf_is_cap_ena_all(adapter, IDPF_RSS_CAPS, IDPF_CAP_RSS)) {
  117. err = -EOPNOTSUPP;
  118. goto unlock_mutex;
  119. }
  120. rss_data = &adapter->vport_config[vport->idx]->user_config.rss_data;
  121. if (np->state != __IDPF_VPORT_UP)
  122. goto unlock_mutex;
  123. if (rxfh->hfunc != ETH_RSS_HASH_NO_CHANGE &&
  124. rxfh->hfunc != ETH_RSS_HASH_TOP) {
  125. err = -EOPNOTSUPP;
  126. goto unlock_mutex;
  127. }
  128. if (rxfh->key)
  129. memcpy(rss_data->rss_key, rxfh->key, rss_data->rss_key_size);
  130. if (rxfh->indir) {
  131. for (lut = 0; lut < rss_data->rss_lut_size; lut++)
  132. rss_data->rss_lut[lut] = rxfh->indir[lut];
  133. }
  134. err = idpf_config_rss(vport);
  135. unlock_mutex:
  136. idpf_vport_ctrl_unlock(netdev);
  137. return err;
  138. }
  139. /**
  140. * idpf_get_channels: get the number of channels supported by the device
  141. * @netdev: network interface device structure
  142. * @ch: channel information structure
  143. *
  144. * Report maximum of TX and RX. Report one extra channel to match our MailBox
  145. * Queue.
  146. */
  147. static void idpf_get_channels(struct net_device *netdev,
  148. struct ethtool_channels *ch)
  149. {
  150. struct idpf_netdev_priv *np = netdev_priv(netdev);
  151. struct idpf_vport_config *vport_config;
  152. u16 num_txq, num_rxq;
  153. u16 combined;
  154. vport_config = np->adapter->vport_config[np->vport_idx];
  155. num_txq = vport_config->user_config.num_req_tx_qs;
  156. num_rxq = vport_config->user_config.num_req_rx_qs;
  157. combined = min(num_txq, num_rxq);
  158. /* Report maximum channels */
  159. ch->max_combined = min_t(u16, vport_config->max_q.max_txq,
  160. vport_config->max_q.max_rxq);
  161. ch->max_rx = vport_config->max_q.max_rxq;
  162. ch->max_tx = vport_config->max_q.max_txq;
  163. ch->max_other = IDPF_MAX_MBXQ;
  164. ch->other_count = IDPF_MAX_MBXQ;
  165. ch->combined_count = combined;
  166. ch->rx_count = num_rxq - combined;
  167. ch->tx_count = num_txq - combined;
  168. }
  169. /**
  170. * idpf_set_channels: set the new channel count
  171. * @netdev: network interface device structure
  172. * @ch: channel information structure
  173. *
  174. * Negotiate a new number of channels with CP. Returns 0 on success, negative
  175. * on failure.
  176. */
  177. static int idpf_set_channels(struct net_device *netdev,
  178. struct ethtool_channels *ch)
  179. {
  180. struct idpf_vport_config *vport_config;
  181. unsigned int num_req_tx_q;
  182. unsigned int num_req_rx_q;
  183. struct idpf_vport *vport;
  184. u16 num_txq, num_rxq;
  185. struct device *dev;
  186. int err = 0;
  187. u16 idx;
  188. if (ch->rx_count && ch->tx_count) {
  189. netdev_err(netdev, "Dedicated RX or TX channels cannot be used simultaneously\n");
  190. return -EINVAL;
  191. }
  192. idpf_vport_ctrl_lock(netdev);
  193. vport = idpf_netdev_to_vport(netdev);
  194. idx = vport->idx;
  195. vport_config = vport->adapter->vport_config[idx];
  196. num_txq = vport_config->user_config.num_req_tx_qs;
  197. num_rxq = vport_config->user_config.num_req_rx_qs;
  198. num_req_tx_q = ch->combined_count + ch->tx_count;
  199. num_req_rx_q = ch->combined_count + ch->rx_count;
  200. dev = &vport->adapter->pdev->dev;
  201. /* It's possible to specify number of queues that exceeds max.
  202. * Stack checks max combined_count and max [tx|rx]_count but not the
  203. * max combined_count + [tx|rx]_count. These checks should catch that.
  204. */
  205. if (num_req_tx_q > vport_config->max_q.max_txq) {
  206. dev_info(dev, "Maximum TX queues is %d\n",
  207. vport_config->max_q.max_txq);
  208. err = -EINVAL;
  209. goto unlock_mutex;
  210. }
  211. if (num_req_rx_q > vport_config->max_q.max_rxq) {
  212. dev_info(dev, "Maximum RX queues is %d\n",
  213. vport_config->max_q.max_rxq);
  214. err = -EINVAL;
  215. goto unlock_mutex;
  216. }
  217. if (num_req_tx_q == num_txq && num_req_rx_q == num_rxq)
  218. goto unlock_mutex;
  219. vport_config->user_config.num_req_tx_qs = num_req_tx_q;
  220. vport_config->user_config.num_req_rx_qs = num_req_rx_q;
  221. err = idpf_initiate_soft_reset(vport, IDPF_SR_Q_CHANGE);
  222. if (err) {
  223. /* roll back queue change */
  224. vport_config->user_config.num_req_tx_qs = num_txq;
  225. vport_config->user_config.num_req_rx_qs = num_rxq;
  226. }
  227. unlock_mutex:
  228. idpf_vport_ctrl_unlock(netdev);
  229. return err;
  230. }
  231. /**
  232. * idpf_get_ringparam - Get ring parameters
  233. * @netdev: network interface device structure
  234. * @ring: ethtool ringparam structure
  235. * @kring: unused
  236. * @ext_ack: unused
  237. *
  238. * Returns current ring parameters. TX and RX rings are reported separately,
  239. * but the number of rings is not reported.
  240. */
  241. static void idpf_get_ringparam(struct net_device *netdev,
  242. struct ethtool_ringparam *ring,
  243. struct kernel_ethtool_ringparam *kring,
  244. struct netlink_ext_ack *ext_ack)
  245. {
  246. struct idpf_vport *vport;
  247. idpf_vport_ctrl_lock(netdev);
  248. vport = idpf_netdev_to_vport(netdev);
  249. ring->rx_max_pending = IDPF_MAX_RXQ_DESC;
  250. ring->tx_max_pending = IDPF_MAX_TXQ_DESC;
  251. ring->rx_pending = vport->rxq_desc_count;
  252. ring->tx_pending = vport->txq_desc_count;
  253. kring->tcp_data_split = idpf_vport_get_hsplit(vport);
  254. idpf_vport_ctrl_unlock(netdev);
  255. }
  256. /**
  257. * idpf_set_ringparam - Set ring parameters
  258. * @netdev: network interface device structure
  259. * @ring: ethtool ringparam structure
  260. * @kring: unused
  261. * @ext_ack: unused
  262. *
  263. * Sets ring parameters. TX and RX rings are controlled separately, but the
  264. * number of rings is not specified, so all rings get the same settings.
  265. */
  266. static int idpf_set_ringparam(struct net_device *netdev,
  267. struct ethtool_ringparam *ring,
  268. struct kernel_ethtool_ringparam *kring,
  269. struct netlink_ext_ack *ext_ack)
  270. {
  271. struct idpf_vport_user_config_data *config_data;
  272. u32 new_rx_count, new_tx_count;
  273. struct idpf_vport *vport;
  274. int i, err = 0;
  275. u16 idx;
  276. idpf_vport_ctrl_lock(netdev);
  277. vport = idpf_netdev_to_vport(netdev);
  278. idx = vport->idx;
  279. if (ring->tx_pending < IDPF_MIN_TXQ_DESC) {
  280. netdev_err(netdev, "Descriptors requested (Tx: %u) is less than min supported (%u)\n",
  281. ring->tx_pending,
  282. IDPF_MIN_TXQ_DESC);
  283. err = -EINVAL;
  284. goto unlock_mutex;
  285. }
  286. if (ring->rx_pending < IDPF_MIN_RXQ_DESC) {
  287. netdev_err(netdev, "Descriptors requested (Rx: %u) is less than min supported (%u)\n",
  288. ring->rx_pending,
  289. IDPF_MIN_RXQ_DESC);
  290. err = -EINVAL;
  291. goto unlock_mutex;
  292. }
  293. new_rx_count = ALIGN(ring->rx_pending, IDPF_REQ_RXQ_DESC_MULTIPLE);
  294. if (new_rx_count != ring->rx_pending)
  295. netdev_info(netdev, "Requested Rx descriptor count rounded up to %u\n",
  296. new_rx_count);
  297. new_tx_count = ALIGN(ring->tx_pending, IDPF_REQ_DESC_MULTIPLE);
  298. if (new_tx_count != ring->tx_pending)
  299. netdev_info(netdev, "Requested Tx descriptor count rounded up to %u\n",
  300. new_tx_count);
  301. if (new_tx_count == vport->txq_desc_count &&
  302. new_rx_count == vport->rxq_desc_count &&
  303. kring->tcp_data_split == idpf_vport_get_hsplit(vport))
  304. goto unlock_mutex;
  305. if (!idpf_vport_set_hsplit(vport, kring->tcp_data_split)) {
  306. NL_SET_ERR_MSG_MOD(ext_ack,
  307. "setting TCP data split is not supported");
  308. err = -EOPNOTSUPP;
  309. goto unlock_mutex;
  310. }
  311. config_data = &vport->adapter->vport_config[idx]->user_config;
  312. config_data->num_req_txq_desc = new_tx_count;
  313. config_data->num_req_rxq_desc = new_rx_count;
  314. /* Since we adjusted the RX completion queue count, the RX buffer queue
  315. * descriptor count needs to be adjusted as well
  316. */
  317. for (i = 0; i < vport->num_bufqs_per_qgrp; i++)
  318. vport->bufq_desc_count[i] =
  319. IDPF_RX_BUFQ_DESC_COUNT(new_rx_count,
  320. vport->num_bufqs_per_qgrp);
  321. err = idpf_initiate_soft_reset(vport, IDPF_SR_Q_DESC_CHANGE);
  322. unlock_mutex:
  323. idpf_vport_ctrl_unlock(netdev);
  324. return err;
  325. }
  326. /**
  327. * struct idpf_stats - definition for an ethtool statistic
  328. * @stat_string: statistic name to display in ethtool -S output
  329. * @sizeof_stat: the sizeof() the stat, must be no greater than sizeof(u64)
  330. * @stat_offset: offsetof() the stat from a base pointer
  331. *
  332. * This structure defines a statistic to be added to the ethtool stats buffer.
  333. * It defines a statistic as offset from a common base pointer. Stats should
  334. * be defined in constant arrays using the IDPF_STAT macro, with every element
  335. * of the array using the same _type for calculating the sizeof_stat and
  336. * stat_offset.
  337. *
  338. * The @sizeof_stat is expected to be sizeof(u8), sizeof(u16), sizeof(u32) or
  339. * sizeof(u64). Other sizes are not expected and will produce a WARN_ONCE from
  340. * the idpf_add_ethtool_stat() helper function.
  341. *
  342. * The @stat_string is interpreted as a format string, allowing formatted
  343. * values to be inserted while looping over multiple structures for a given
  344. * statistics array. Thus, every statistic string in an array should have the
  345. * same type and number of format specifiers, to be formatted by variadic
  346. * arguments to the idpf_add_stat_string() helper function.
  347. */
  348. struct idpf_stats {
  349. char stat_string[ETH_GSTRING_LEN];
  350. int sizeof_stat;
  351. int stat_offset;
  352. };
  353. /* Helper macro to define an idpf_stat structure with proper size and type.
  354. * Use this when defining constant statistics arrays. Note that @_type expects
  355. * only a type name and is used multiple times.
  356. */
  357. #define IDPF_STAT(_type, _name, _stat) { \
  358. .stat_string = _name, \
  359. .sizeof_stat = sizeof_field(_type, _stat), \
  360. .stat_offset = offsetof(_type, _stat) \
  361. }
  362. /* Helper macros for defining some statistics related to queues */
  363. #define IDPF_RX_QUEUE_STAT(_name, _stat) \
  364. IDPF_STAT(struct idpf_rx_queue, _name, _stat)
  365. #define IDPF_TX_QUEUE_STAT(_name, _stat) \
  366. IDPF_STAT(struct idpf_tx_queue, _name, _stat)
  367. /* Stats associated with a Tx queue */
  368. static const struct idpf_stats idpf_gstrings_tx_queue_stats[] = {
  369. IDPF_TX_QUEUE_STAT("pkts", q_stats.packets),
  370. IDPF_TX_QUEUE_STAT("bytes", q_stats.bytes),
  371. IDPF_TX_QUEUE_STAT("lso_pkts", q_stats.lso_pkts),
  372. };
  373. /* Stats associated with an Rx queue */
  374. static const struct idpf_stats idpf_gstrings_rx_queue_stats[] = {
  375. IDPF_RX_QUEUE_STAT("pkts", q_stats.packets),
  376. IDPF_RX_QUEUE_STAT("bytes", q_stats.bytes),
  377. IDPF_RX_QUEUE_STAT("rx_gro_hw_pkts", q_stats.rsc_pkts),
  378. };
  379. #define IDPF_TX_QUEUE_STATS_LEN ARRAY_SIZE(idpf_gstrings_tx_queue_stats)
  380. #define IDPF_RX_QUEUE_STATS_LEN ARRAY_SIZE(idpf_gstrings_rx_queue_stats)
  381. #define IDPF_PORT_STAT(_name, _stat) \
  382. IDPF_STAT(struct idpf_vport, _name, _stat)
  383. static const struct idpf_stats idpf_gstrings_port_stats[] = {
  384. IDPF_PORT_STAT("rx-csum_errors", port_stats.rx_hw_csum_err),
  385. IDPF_PORT_STAT("rx-hsplit", port_stats.rx_hsplit),
  386. IDPF_PORT_STAT("rx-hsplit_hbo", port_stats.rx_hsplit_hbo),
  387. IDPF_PORT_STAT("rx-bad_descs", port_stats.rx_bad_descs),
  388. IDPF_PORT_STAT("tx-skb_drops", port_stats.tx_drops),
  389. IDPF_PORT_STAT("tx-dma_map_errs", port_stats.tx_dma_map_errs),
  390. IDPF_PORT_STAT("tx-linearized_pkts", port_stats.tx_linearize),
  391. IDPF_PORT_STAT("tx-busy_events", port_stats.tx_busy),
  392. IDPF_PORT_STAT("rx-unicast_pkts", port_stats.vport_stats.rx_unicast),
  393. IDPF_PORT_STAT("rx-multicast_pkts", port_stats.vport_stats.rx_multicast),
  394. IDPF_PORT_STAT("rx-broadcast_pkts", port_stats.vport_stats.rx_broadcast),
  395. IDPF_PORT_STAT("rx-unknown_protocol", port_stats.vport_stats.rx_unknown_protocol),
  396. IDPF_PORT_STAT("tx-unicast_pkts", port_stats.vport_stats.tx_unicast),
  397. IDPF_PORT_STAT("tx-multicast_pkts", port_stats.vport_stats.tx_multicast),
  398. IDPF_PORT_STAT("tx-broadcast_pkts", port_stats.vport_stats.tx_broadcast),
  399. };
  400. #define IDPF_PORT_STATS_LEN ARRAY_SIZE(idpf_gstrings_port_stats)
  401. /**
  402. * __idpf_add_qstat_strings - copy stat strings into ethtool buffer
  403. * @p: ethtool supplied buffer
  404. * @stats: stat definitions array
  405. * @size: size of the stats array
  406. * @type: stat type
  407. * @idx: stat index
  408. *
  409. * Format and copy the strings described by stats into the buffer pointed at
  410. * by p.
  411. */
  412. static void __idpf_add_qstat_strings(u8 **p, const struct idpf_stats *stats,
  413. const unsigned int size, const char *type,
  414. unsigned int idx)
  415. {
  416. unsigned int i;
  417. for (i = 0; i < size; i++)
  418. ethtool_sprintf(p, "%s_q-%u_%s",
  419. type, idx, stats[i].stat_string);
  420. }
  421. /**
  422. * idpf_add_qstat_strings - Copy queue stat strings into ethtool buffer
  423. * @p: ethtool supplied buffer
  424. * @stats: stat definitions array
  425. * @type: stat type
  426. * @idx: stat idx
  427. *
  428. * Format and copy the strings described by the const static stats value into
  429. * the buffer pointed at by p.
  430. *
  431. * The parameter @stats is evaluated twice, so parameters with side effects
  432. * should be avoided. Additionally, stats must be an array such that
  433. * ARRAY_SIZE can be called on it.
  434. */
  435. #define idpf_add_qstat_strings(p, stats, type, idx) \
  436. __idpf_add_qstat_strings(p, stats, ARRAY_SIZE(stats), type, idx)
  437. /**
  438. * idpf_add_stat_strings - Copy port stat strings into ethtool buffer
  439. * @p: ethtool buffer
  440. * @stats: struct to copy from
  441. * @size: size of stats array to copy from
  442. */
  443. static void idpf_add_stat_strings(u8 **p, const struct idpf_stats *stats,
  444. const unsigned int size)
  445. {
  446. unsigned int i;
  447. for (i = 0; i < size; i++)
  448. ethtool_puts(p, stats[i].stat_string);
  449. }
  450. /**
  451. * idpf_get_stat_strings - Get stat strings
  452. * @netdev: network interface device structure
  453. * @data: buffer for string data
  454. *
  455. * Builds the statistics string table
  456. */
  457. static void idpf_get_stat_strings(struct net_device *netdev, u8 *data)
  458. {
  459. struct idpf_netdev_priv *np = netdev_priv(netdev);
  460. struct idpf_vport_config *vport_config;
  461. unsigned int i;
  462. idpf_add_stat_strings(&data, idpf_gstrings_port_stats,
  463. IDPF_PORT_STATS_LEN);
  464. vport_config = np->adapter->vport_config[np->vport_idx];
  465. /* It's critical that we always report a constant number of strings and
  466. * that the strings are reported in the same order regardless of how
  467. * many queues are actually in use.
  468. */
  469. for (i = 0; i < vport_config->max_q.max_txq; i++)
  470. idpf_add_qstat_strings(&data, idpf_gstrings_tx_queue_stats,
  471. "tx", i);
  472. for (i = 0; i < vport_config->max_q.max_rxq; i++)
  473. idpf_add_qstat_strings(&data, idpf_gstrings_rx_queue_stats,
  474. "rx", i);
  475. }
  476. /**
  477. * idpf_get_strings - Get string set
  478. * @netdev: network interface device structure
  479. * @sset: id of string set
  480. * @data: buffer for string data
  481. *
  482. * Builds string tables for various string sets
  483. */
  484. static void idpf_get_strings(struct net_device *netdev, u32 sset, u8 *data)
  485. {
  486. switch (sset) {
  487. case ETH_SS_STATS:
  488. idpf_get_stat_strings(netdev, data);
  489. break;
  490. default:
  491. break;
  492. }
  493. }
  494. /**
  495. * idpf_get_sset_count - Get length of string set
  496. * @netdev: network interface device structure
  497. * @sset: id of string set
  498. *
  499. * Reports size of various string tables.
  500. */
  501. static int idpf_get_sset_count(struct net_device *netdev, int sset)
  502. {
  503. struct idpf_netdev_priv *np = netdev_priv(netdev);
  504. struct idpf_vport_config *vport_config;
  505. u16 max_txq, max_rxq;
  506. if (sset != ETH_SS_STATS)
  507. return -EINVAL;
  508. vport_config = np->adapter->vport_config[np->vport_idx];
  509. /* This size reported back here *must* be constant throughout the
  510. * lifecycle of the netdevice, i.e. we must report the maximum length
  511. * even for queues that don't technically exist. This is due to the
  512. * fact that this userspace API uses three separate ioctl calls to get
  513. * stats data but has no way to communicate back to userspace when that
  514. * size has changed, which can typically happen as a result of changing
  515. * number of queues. If the number/order of stats change in the middle
  516. * of this call chain it will lead to userspace crashing/accessing bad
  517. * data through buffer under/overflow.
  518. */
  519. max_txq = vport_config->max_q.max_txq;
  520. max_rxq = vport_config->max_q.max_rxq;
  521. return IDPF_PORT_STATS_LEN + (IDPF_TX_QUEUE_STATS_LEN * max_txq) +
  522. (IDPF_RX_QUEUE_STATS_LEN * max_rxq);
  523. }
  524. /**
  525. * idpf_add_one_ethtool_stat - copy the stat into the supplied buffer
  526. * @data: location to store the stat value
  527. * @pstat: old stat pointer to copy from
  528. * @stat: the stat definition
  529. *
  530. * Copies the stat data defined by the pointer and stat structure pair into
  531. * the memory supplied as data. If the pointer is null, data will be zero'd.
  532. */
  533. static void idpf_add_one_ethtool_stat(u64 *data, const void *pstat,
  534. const struct idpf_stats *stat)
  535. {
  536. char *p;
  537. if (!pstat) {
  538. /* Ensure that the ethtool data buffer is zero'd for any stats
  539. * which don't have a valid pointer.
  540. */
  541. *data = 0;
  542. return;
  543. }
  544. p = (char *)pstat + stat->stat_offset;
  545. switch (stat->sizeof_stat) {
  546. case sizeof(u64):
  547. *data = *((u64 *)p);
  548. break;
  549. case sizeof(u32):
  550. *data = *((u32 *)p);
  551. break;
  552. case sizeof(u16):
  553. *data = *((u16 *)p);
  554. break;
  555. case sizeof(u8):
  556. *data = *((u8 *)p);
  557. break;
  558. default:
  559. WARN_ONCE(1, "unexpected stat size for %s",
  560. stat->stat_string);
  561. *data = 0;
  562. }
  563. }
  564. /**
  565. * idpf_add_queue_stats - copy queue statistics into supplied buffer
  566. * @data: ethtool stats buffer
  567. * @q: the queue to copy
  568. * @type: type of the queue
  569. *
  570. * Queue statistics must be copied while protected by u64_stats_fetch_begin,
  571. * so we can't directly use idpf_add_ethtool_stats. Assumes that queue stats
  572. * are defined in idpf_gstrings_queue_stats. If the queue pointer is null,
  573. * zero out the queue stat values and update the data pointer. Otherwise
  574. * safely copy the stats from the queue into the supplied buffer and update
  575. * the data pointer when finished.
  576. *
  577. * This function expects to be called while under rcu_read_lock().
  578. */
  579. static void idpf_add_queue_stats(u64 **data, const void *q,
  580. enum virtchnl2_queue_type type)
  581. {
  582. const struct u64_stats_sync *stats_sync;
  583. const struct idpf_stats *stats;
  584. unsigned int start;
  585. unsigned int size;
  586. unsigned int i;
  587. if (type == VIRTCHNL2_QUEUE_TYPE_RX) {
  588. size = IDPF_RX_QUEUE_STATS_LEN;
  589. stats = idpf_gstrings_rx_queue_stats;
  590. stats_sync = &((const struct idpf_rx_queue *)q)->stats_sync;
  591. } else {
  592. size = IDPF_TX_QUEUE_STATS_LEN;
  593. stats = idpf_gstrings_tx_queue_stats;
  594. stats_sync = &((const struct idpf_tx_queue *)q)->stats_sync;
  595. }
  596. /* To avoid invalid statistics values, ensure that we keep retrying
  597. * the copy until we get a consistent value according to
  598. * u64_stats_fetch_retry.
  599. */
  600. do {
  601. start = u64_stats_fetch_begin(stats_sync);
  602. for (i = 0; i < size; i++)
  603. idpf_add_one_ethtool_stat(&(*data)[i], q, &stats[i]);
  604. } while (u64_stats_fetch_retry(stats_sync, start));
  605. /* Once we successfully copy the stats in, update the data pointer */
  606. *data += size;
  607. }
  608. /**
  609. * idpf_add_empty_queue_stats - Add stats for a non-existent queue
  610. * @data: pointer to data buffer
  611. * @qtype: type of data queue
  612. *
  613. * We must report a constant length of stats back to userspace regardless of
  614. * how many queues are actually in use because stats collection happens over
  615. * three separate ioctls and there's no way to notify userspace the size
  616. * changed between those calls. This adds empty to data to the stats since we
  617. * don't have a real queue to refer to for this stats slot.
  618. */
  619. static void idpf_add_empty_queue_stats(u64 **data, u16 qtype)
  620. {
  621. unsigned int i;
  622. int stats_len;
  623. if (qtype == VIRTCHNL2_QUEUE_TYPE_RX)
  624. stats_len = IDPF_RX_QUEUE_STATS_LEN;
  625. else
  626. stats_len = IDPF_TX_QUEUE_STATS_LEN;
  627. for (i = 0; i < stats_len; i++)
  628. (*data)[i] = 0;
  629. *data += stats_len;
  630. }
  631. /**
  632. * idpf_add_port_stats - Copy port stats into ethtool buffer
  633. * @vport: virtual port struct
  634. * @data: ethtool buffer to copy into
  635. */
  636. static void idpf_add_port_stats(struct idpf_vport *vport, u64 **data)
  637. {
  638. unsigned int size = IDPF_PORT_STATS_LEN;
  639. unsigned int start;
  640. unsigned int i;
  641. do {
  642. start = u64_stats_fetch_begin(&vport->port_stats.stats_sync);
  643. for (i = 0; i < size; i++)
  644. idpf_add_one_ethtool_stat(&(*data)[i], vport,
  645. &idpf_gstrings_port_stats[i]);
  646. } while (u64_stats_fetch_retry(&vport->port_stats.stats_sync, start));
  647. *data += size;
  648. }
  649. /**
  650. * idpf_collect_queue_stats - accumulate various per queue stats
  651. * into port level stats
  652. * @vport: pointer to vport struct
  653. **/
  654. static void idpf_collect_queue_stats(struct idpf_vport *vport)
  655. {
  656. struct idpf_port_stats *pstats = &vport->port_stats;
  657. int i, j;
  658. /* zero out port stats since they're actually tracked in per
  659. * queue stats; this is only for reporting
  660. */
  661. u64_stats_update_begin(&pstats->stats_sync);
  662. u64_stats_set(&pstats->rx_hw_csum_err, 0);
  663. u64_stats_set(&pstats->rx_hsplit, 0);
  664. u64_stats_set(&pstats->rx_hsplit_hbo, 0);
  665. u64_stats_set(&pstats->rx_bad_descs, 0);
  666. u64_stats_set(&pstats->tx_linearize, 0);
  667. u64_stats_set(&pstats->tx_busy, 0);
  668. u64_stats_set(&pstats->tx_drops, 0);
  669. u64_stats_set(&pstats->tx_dma_map_errs, 0);
  670. u64_stats_update_end(&pstats->stats_sync);
  671. for (i = 0; i < vport->num_rxq_grp; i++) {
  672. struct idpf_rxq_group *rxq_grp = &vport->rxq_grps[i];
  673. u16 num_rxq;
  674. if (idpf_is_queue_model_split(vport->rxq_model))
  675. num_rxq = rxq_grp->splitq.num_rxq_sets;
  676. else
  677. num_rxq = rxq_grp->singleq.num_rxq;
  678. for (j = 0; j < num_rxq; j++) {
  679. u64 hw_csum_err, hsplit, hsplit_hbo, bad_descs;
  680. struct idpf_rx_queue_stats *stats;
  681. struct idpf_rx_queue *rxq;
  682. unsigned int start;
  683. if (idpf_is_queue_model_split(vport->rxq_model))
  684. rxq = &rxq_grp->splitq.rxq_sets[j]->rxq;
  685. else
  686. rxq = rxq_grp->singleq.rxqs[j];
  687. if (!rxq)
  688. continue;
  689. do {
  690. start = u64_stats_fetch_begin(&rxq->stats_sync);
  691. stats = &rxq->q_stats;
  692. hw_csum_err = u64_stats_read(&stats->hw_csum_err);
  693. hsplit = u64_stats_read(&stats->hsplit_pkts);
  694. hsplit_hbo = u64_stats_read(&stats->hsplit_buf_ovf);
  695. bad_descs = u64_stats_read(&stats->bad_descs);
  696. } while (u64_stats_fetch_retry(&rxq->stats_sync, start));
  697. u64_stats_update_begin(&pstats->stats_sync);
  698. u64_stats_add(&pstats->rx_hw_csum_err, hw_csum_err);
  699. u64_stats_add(&pstats->rx_hsplit, hsplit);
  700. u64_stats_add(&pstats->rx_hsplit_hbo, hsplit_hbo);
  701. u64_stats_add(&pstats->rx_bad_descs, bad_descs);
  702. u64_stats_update_end(&pstats->stats_sync);
  703. }
  704. }
  705. for (i = 0; i < vport->num_txq_grp; i++) {
  706. struct idpf_txq_group *txq_grp = &vport->txq_grps[i];
  707. for (j = 0; j < txq_grp->num_txq; j++) {
  708. u64 linearize, qbusy, skb_drops, dma_map_errs;
  709. struct idpf_tx_queue *txq = txq_grp->txqs[j];
  710. struct idpf_tx_queue_stats *stats;
  711. unsigned int start;
  712. if (!txq)
  713. continue;
  714. do {
  715. start = u64_stats_fetch_begin(&txq->stats_sync);
  716. stats = &txq->q_stats;
  717. linearize = u64_stats_read(&stats->linearize);
  718. qbusy = u64_stats_read(&stats->q_busy);
  719. skb_drops = u64_stats_read(&stats->skb_drops);
  720. dma_map_errs = u64_stats_read(&stats->dma_map_errs);
  721. } while (u64_stats_fetch_retry(&txq->stats_sync, start));
  722. u64_stats_update_begin(&pstats->stats_sync);
  723. u64_stats_add(&pstats->tx_linearize, linearize);
  724. u64_stats_add(&pstats->tx_busy, qbusy);
  725. u64_stats_add(&pstats->tx_drops, skb_drops);
  726. u64_stats_add(&pstats->tx_dma_map_errs, dma_map_errs);
  727. u64_stats_update_end(&pstats->stats_sync);
  728. }
  729. }
  730. }
  731. /**
  732. * idpf_get_ethtool_stats - report device statistics
  733. * @netdev: network interface device structure
  734. * @stats: ethtool statistics structure
  735. * @data: pointer to data buffer
  736. *
  737. * All statistics are added to the data buffer as an array of u64.
  738. */
  739. static void idpf_get_ethtool_stats(struct net_device *netdev,
  740. struct ethtool_stats __always_unused *stats,
  741. u64 *data)
  742. {
  743. struct idpf_netdev_priv *np = netdev_priv(netdev);
  744. struct idpf_vport_config *vport_config;
  745. struct idpf_vport *vport;
  746. unsigned int total = 0;
  747. unsigned int i, j;
  748. bool is_splitq;
  749. u16 qtype;
  750. idpf_vport_ctrl_lock(netdev);
  751. vport = idpf_netdev_to_vport(netdev);
  752. if (np->state != __IDPF_VPORT_UP) {
  753. idpf_vport_ctrl_unlock(netdev);
  754. return;
  755. }
  756. rcu_read_lock();
  757. idpf_collect_queue_stats(vport);
  758. idpf_add_port_stats(vport, &data);
  759. for (i = 0; i < vport->num_txq_grp; i++) {
  760. struct idpf_txq_group *txq_grp = &vport->txq_grps[i];
  761. qtype = VIRTCHNL2_QUEUE_TYPE_TX;
  762. for (j = 0; j < txq_grp->num_txq; j++, total++) {
  763. struct idpf_tx_queue *txq = txq_grp->txqs[j];
  764. if (!txq)
  765. idpf_add_empty_queue_stats(&data, qtype);
  766. else
  767. idpf_add_queue_stats(&data, txq, qtype);
  768. }
  769. }
  770. vport_config = vport->adapter->vport_config[vport->idx];
  771. /* It is critical we provide a constant number of stats back to
  772. * userspace regardless of how many queues are actually in use because
  773. * there is no way to inform userspace the size has changed between
  774. * ioctl calls. This will fill in any missing stats with zero.
  775. */
  776. for (; total < vport_config->max_q.max_txq; total++)
  777. idpf_add_empty_queue_stats(&data, VIRTCHNL2_QUEUE_TYPE_TX);
  778. total = 0;
  779. is_splitq = idpf_is_queue_model_split(vport->rxq_model);
  780. for (i = 0; i < vport->num_rxq_grp; i++) {
  781. struct idpf_rxq_group *rxq_grp = &vport->rxq_grps[i];
  782. u16 num_rxq;
  783. qtype = VIRTCHNL2_QUEUE_TYPE_RX;
  784. if (is_splitq)
  785. num_rxq = rxq_grp->splitq.num_rxq_sets;
  786. else
  787. num_rxq = rxq_grp->singleq.num_rxq;
  788. for (j = 0; j < num_rxq; j++, total++) {
  789. struct idpf_rx_queue *rxq;
  790. if (is_splitq)
  791. rxq = &rxq_grp->splitq.rxq_sets[j]->rxq;
  792. else
  793. rxq = rxq_grp->singleq.rxqs[j];
  794. if (!rxq)
  795. idpf_add_empty_queue_stats(&data, qtype);
  796. else
  797. idpf_add_queue_stats(&data, rxq, qtype);
  798. }
  799. }
  800. for (; total < vport_config->max_q.max_rxq; total++)
  801. idpf_add_empty_queue_stats(&data, VIRTCHNL2_QUEUE_TYPE_RX);
  802. rcu_read_unlock();
  803. idpf_vport_ctrl_unlock(netdev);
  804. }
  805. /**
  806. * idpf_find_rxq_vec - find rxq vector from q index
  807. * @vport: virtual port associated to queue
  808. * @q_num: q index used to find queue
  809. *
  810. * returns pointer to rx vector
  811. */
  812. static struct idpf_q_vector *idpf_find_rxq_vec(const struct idpf_vport *vport,
  813. int q_num)
  814. {
  815. int q_grp, q_idx;
  816. if (!idpf_is_queue_model_split(vport->rxq_model))
  817. return vport->rxq_grps->singleq.rxqs[q_num]->q_vector;
  818. q_grp = q_num / IDPF_DFLT_SPLITQ_RXQ_PER_GROUP;
  819. q_idx = q_num % IDPF_DFLT_SPLITQ_RXQ_PER_GROUP;
  820. return vport->rxq_grps[q_grp].splitq.rxq_sets[q_idx]->rxq.q_vector;
  821. }
  822. /**
  823. * idpf_find_txq_vec - find txq vector from q index
  824. * @vport: virtual port associated to queue
  825. * @q_num: q index used to find queue
  826. *
  827. * returns pointer to tx vector
  828. */
  829. static struct idpf_q_vector *idpf_find_txq_vec(const struct idpf_vport *vport,
  830. int q_num)
  831. {
  832. int q_grp;
  833. if (!idpf_is_queue_model_split(vport->txq_model))
  834. return vport->txqs[q_num]->q_vector;
  835. q_grp = q_num / IDPF_DFLT_SPLITQ_TXQ_PER_GROUP;
  836. return vport->txq_grps[q_grp].complq->q_vector;
  837. }
  838. /**
  839. * __idpf_get_q_coalesce - get ITR values for specific queue
  840. * @ec: ethtool structure to fill with driver's coalesce settings
  841. * @q_vector: queue vector corresponding to this queue
  842. * @type: queue type
  843. */
  844. static void __idpf_get_q_coalesce(struct ethtool_coalesce *ec,
  845. const struct idpf_q_vector *q_vector,
  846. enum virtchnl2_queue_type type)
  847. {
  848. if (type == VIRTCHNL2_QUEUE_TYPE_RX) {
  849. ec->use_adaptive_rx_coalesce =
  850. IDPF_ITR_IS_DYNAMIC(q_vector->rx_intr_mode);
  851. ec->rx_coalesce_usecs = q_vector->rx_itr_value;
  852. } else {
  853. ec->use_adaptive_tx_coalesce =
  854. IDPF_ITR_IS_DYNAMIC(q_vector->tx_intr_mode);
  855. ec->tx_coalesce_usecs = q_vector->tx_itr_value;
  856. }
  857. }
  858. /**
  859. * idpf_get_q_coalesce - get ITR values for specific queue
  860. * @netdev: pointer to the netdev associated with this query
  861. * @ec: coalesce settings to program the device with
  862. * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index
  863. *
  864. * Return 0 on success, and negative on failure
  865. */
  866. static int idpf_get_q_coalesce(struct net_device *netdev,
  867. struct ethtool_coalesce *ec,
  868. u32 q_num)
  869. {
  870. const struct idpf_netdev_priv *np = netdev_priv(netdev);
  871. const struct idpf_vport *vport;
  872. int err = 0;
  873. idpf_vport_ctrl_lock(netdev);
  874. vport = idpf_netdev_to_vport(netdev);
  875. if (np->state != __IDPF_VPORT_UP)
  876. goto unlock_mutex;
  877. if (q_num >= vport->num_rxq && q_num >= vport->num_txq) {
  878. err = -EINVAL;
  879. goto unlock_mutex;
  880. }
  881. if (q_num < vport->num_rxq)
  882. __idpf_get_q_coalesce(ec, idpf_find_rxq_vec(vport, q_num),
  883. VIRTCHNL2_QUEUE_TYPE_RX);
  884. if (q_num < vport->num_txq)
  885. __idpf_get_q_coalesce(ec, idpf_find_txq_vec(vport, q_num),
  886. VIRTCHNL2_QUEUE_TYPE_TX);
  887. unlock_mutex:
  888. idpf_vport_ctrl_unlock(netdev);
  889. return err;
  890. }
  891. /**
  892. * idpf_get_coalesce - get ITR values as requested by user
  893. * @netdev: pointer to the netdev associated with this query
  894. * @ec: coalesce settings to be filled
  895. * @kec: unused
  896. * @extack: unused
  897. *
  898. * Return 0 on success, and negative on failure
  899. */
  900. static int idpf_get_coalesce(struct net_device *netdev,
  901. struct ethtool_coalesce *ec,
  902. struct kernel_ethtool_coalesce *kec,
  903. struct netlink_ext_ack *extack)
  904. {
  905. /* Return coalesce based on queue number zero */
  906. return idpf_get_q_coalesce(netdev, ec, 0);
  907. }
  908. /**
  909. * idpf_get_per_q_coalesce - get ITR values as requested by user
  910. * @netdev: pointer to the netdev associated with this query
  911. * @q_num: queue for which the itr values has to retrieved
  912. * @ec: coalesce settings to be filled
  913. *
  914. * Return 0 on success, and negative on failure
  915. */
  916. static int idpf_get_per_q_coalesce(struct net_device *netdev, u32 q_num,
  917. struct ethtool_coalesce *ec)
  918. {
  919. return idpf_get_q_coalesce(netdev, ec, q_num);
  920. }
  921. /**
  922. * __idpf_set_q_coalesce - set ITR values for specific queue
  923. * @ec: ethtool structure from user to update ITR settings
  924. * @q_coal: per queue coalesce settings
  925. * @qv: queue vector for which itr values has to be set
  926. * @is_rxq: is queue type rx
  927. *
  928. * Returns 0 on success, negative otherwise.
  929. */
  930. static int __idpf_set_q_coalesce(const struct ethtool_coalesce *ec,
  931. struct idpf_q_coalesce *q_coal,
  932. struct idpf_q_vector *qv, bool is_rxq)
  933. {
  934. u32 use_adaptive_coalesce, coalesce_usecs;
  935. bool is_dim_ena = false;
  936. u16 itr_val;
  937. if (is_rxq) {
  938. is_dim_ena = IDPF_ITR_IS_DYNAMIC(qv->rx_intr_mode);
  939. use_adaptive_coalesce = ec->use_adaptive_rx_coalesce;
  940. coalesce_usecs = ec->rx_coalesce_usecs;
  941. itr_val = qv->rx_itr_value;
  942. } else {
  943. is_dim_ena = IDPF_ITR_IS_DYNAMIC(qv->tx_intr_mode);
  944. use_adaptive_coalesce = ec->use_adaptive_tx_coalesce;
  945. coalesce_usecs = ec->tx_coalesce_usecs;
  946. itr_val = qv->tx_itr_value;
  947. }
  948. if (coalesce_usecs != itr_val && use_adaptive_coalesce) {
  949. netdev_err(qv->vport->netdev, "Cannot set coalesce usecs if adaptive enabled\n");
  950. return -EINVAL;
  951. }
  952. if (is_dim_ena && use_adaptive_coalesce)
  953. return 0;
  954. if (coalesce_usecs > IDPF_ITR_MAX) {
  955. netdev_err(qv->vport->netdev,
  956. "Invalid value, %d-usecs range is 0-%d\n",
  957. coalesce_usecs, IDPF_ITR_MAX);
  958. return -EINVAL;
  959. }
  960. if (coalesce_usecs % 2) {
  961. coalesce_usecs--;
  962. netdev_info(qv->vport->netdev,
  963. "HW only supports even ITR values, ITR rounded to %d\n",
  964. coalesce_usecs);
  965. }
  966. if (is_rxq) {
  967. qv->rx_itr_value = coalesce_usecs;
  968. q_coal->rx_coalesce_usecs = coalesce_usecs;
  969. if (use_adaptive_coalesce) {
  970. qv->rx_intr_mode = IDPF_ITR_DYNAMIC;
  971. q_coal->rx_intr_mode = IDPF_ITR_DYNAMIC;
  972. } else {
  973. qv->rx_intr_mode = !IDPF_ITR_DYNAMIC;
  974. q_coal->rx_intr_mode = !IDPF_ITR_DYNAMIC;
  975. idpf_vport_intr_write_itr(qv, coalesce_usecs, false);
  976. }
  977. } else {
  978. qv->tx_itr_value = coalesce_usecs;
  979. q_coal->tx_coalesce_usecs = coalesce_usecs;
  980. if (use_adaptive_coalesce) {
  981. qv->tx_intr_mode = IDPF_ITR_DYNAMIC;
  982. q_coal->tx_intr_mode = IDPF_ITR_DYNAMIC;
  983. } else {
  984. qv->tx_intr_mode = !IDPF_ITR_DYNAMIC;
  985. q_coal->tx_intr_mode = !IDPF_ITR_DYNAMIC;
  986. idpf_vport_intr_write_itr(qv, coalesce_usecs, true);
  987. }
  988. }
  989. /* Update of static/dynamic itr will be taken care when interrupt is
  990. * fired
  991. */
  992. return 0;
  993. }
  994. /**
  995. * idpf_set_q_coalesce - set ITR values for specific queue
  996. * @vport: vport associated to the queue that need updating
  997. * @q_coal: per queue coalesce settings
  998. * @ec: coalesce settings to program the device with
  999. * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index
  1000. * @is_rxq: is queue type rx
  1001. *
  1002. * Return 0 on success, and negative on failure
  1003. */
  1004. static int idpf_set_q_coalesce(const struct idpf_vport *vport,
  1005. struct idpf_q_coalesce *q_coal,
  1006. const struct ethtool_coalesce *ec,
  1007. int q_num, bool is_rxq)
  1008. {
  1009. struct idpf_q_vector *qv;
  1010. qv = is_rxq ? idpf_find_rxq_vec(vport, q_num) :
  1011. idpf_find_txq_vec(vport, q_num);
  1012. if (qv && __idpf_set_q_coalesce(ec, q_coal, qv, is_rxq))
  1013. return -EINVAL;
  1014. return 0;
  1015. }
  1016. /**
  1017. * idpf_set_coalesce - set ITR values as requested by user
  1018. * @netdev: pointer to the netdev associated with this query
  1019. * @ec: coalesce settings to program the device with
  1020. * @kec: unused
  1021. * @extack: unused
  1022. *
  1023. * Return 0 on success, and negative on failure
  1024. */
  1025. static int idpf_set_coalesce(struct net_device *netdev,
  1026. struct ethtool_coalesce *ec,
  1027. struct kernel_ethtool_coalesce *kec,
  1028. struct netlink_ext_ack *extack)
  1029. {
  1030. struct idpf_netdev_priv *np = netdev_priv(netdev);
  1031. struct idpf_vport_user_config_data *user_config;
  1032. struct idpf_q_coalesce *q_coal;
  1033. struct idpf_vport *vport;
  1034. int i, err = 0;
  1035. user_config = &np->adapter->vport_config[np->vport_idx]->user_config;
  1036. idpf_vport_ctrl_lock(netdev);
  1037. vport = idpf_netdev_to_vport(netdev);
  1038. if (np->state != __IDPF_VPORT_UP)
  1039. goto unlock_mutex;
  1040. for (i = 0; i < vport->num_txq; i++) {
  1041. q_coal = &user_config->q_coalesce[i];
  1042. err = idpf_set_q_coalesce(vport, q_coal, ec, i, false);
  1043. if (err)
  1044. goto unlock_mutex;
  1045. }
  1046. for (i = 0; i < vport->num_rxq; i++) {
  1047. q_coal = &user_config->q_coalesce[i];
  1048. err = idpf_set_q_coalesce(vport, q_coal, ec, i, true);
  1049. if (err)
  1050. goto unlock_mutex;
  1051. }
  1052. unlock_mutex:
  1053. idpf_vport_ctrl_unlock(netdev);
  1054. return err;
  1055. }
  1056. /**
  1057. * idpf_set_per_q_coalesce - set ITR values as requested by user
  1058. * @netdev: pointer to the netdev associated with this query
  1059. * @q_num: queue for which the itr values has to be set
  1060. * @ec: coalesce settings to program the device with
  1061. *
  1062. * Return 0 on success, and negative on failure
  1063. */
  1064. static int idpf_set_per_q_coalesce(struct net_device *netdev, u32 q_num,
  1065. struct ethtool_coalesce *ec)
  1066. {
  1067. struct idpf_netdev_priv *np = netdev_priv(netdev);
  1068. struct idpf_vport_user_config_data *user_config;
  1069. struct idpf_q_coalesce *q_coal;
  1070. struct idpf_vport *vport;
  1071. int err;
  1072. idpf_vport_ctrl_lock(netdev);
  1073. vport = idpf_netdev_to_vport(netdev);
  1074. user_config = &np->adapter->vport_config[np->vport_idx]->user_config;
  1075. q_coal = &user_config->q_coalesce[q_num];
  1076. err = idpf_set_q_coalesce(vport, q_coal, ec, q_num, false);
  1077. if (err) {
  1078. idpf_vport_ctrl_unlock(netdev);
  1079. return err;
  1080. }
  1081. err = idpf_set_q_coalesce(vport, q_coal, ec, q_num, true);
  1082. idpf_vport_ctrl_unlock(netdev);
  1083. return err;
  1084. }
  1085. /**
  1086. * idpf_get_msglevel - Get debug message level
  1087. * @netdev: network interface device structure
  1088. *
  1089. * Returns current debug message level.
  1090. */
  1091. static u32 idpf_get_msglevel(struct net_device *netdev)
  1092. {
  1093. struct idpf_adapter *adapter = idpf_netdev_to_adapter(netdev);
  1094. return adapter->msg_enable;
  1095. }
  1096. /**
  1097. * idpf_set_msglevel - Set debug message level
  1098. * @netdev: network interface device structure
  1099. * @data: message level
  1100. *
  1101. * Set current debug message level. Higher values cause the driver to
  1102. * be noisier.
  1103. */
  1104. static void idpf_set_msglevel(struct net_device *netdev, u32 data)
  1105. {
  1106. struct idpf_adapter *adapter = idpf_netdev_to_adapter(netdev);
  1107. adapter->msg_enable = data;
  1108. }
  1109. /**
  1110. * idpf_get_link_ksettings - Get Link Speed and Duplex settings
  1111. * @netdev: network interface device structure
  1112. * @cmd: ethtool command
  1113. *
  1114. * Reports speed/duplex settings.
  1115. **/
  1116. static int idpf_get_link_ksettings(struct net_device *netdev,
  1117. struct ethtool_link_ksettings *cmd)
  1118. {
  1119. struct idpf_netdev_priv *np = netdev_priv(netdev);
  1120. ethtool_link_ksettings_zero_link_mode(cmd, supported);
  1121. cmd->base.autoneg = AUTONEG_DISABLE;
  1122. cmd->base.port = PORT_NONE;
  1123. if (netif_carrier_ok(netdev)) {
  1124. cmd->base.duplex = DUPLEX_FULL;
  1125. cmd->base.speed = np->link_speed_mbps;
  1126. } else {
  1127. cmd->base.duplex = DUPLEX_UNKNOWN;
  1128. cmd->base.speed = SPEED_UNKNOWN;
  1129. }
  1130. return 0;
  1131. }
  1132. static const struct ethtool_ops idpf_ethtool_ops = {
  1133. .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
  1134. ETHTOOL_COALESCE_USE_ADAPTIVE,
  1135. .supported_ring_params = ETHTOOL_RING_USE_TCP_DATA_SPLIT,
  1136. .get_msglevel = idpf_get_msglevel,
  1137. .set_msglevel = idpf_set_msglevel,
  1138. .get_link = ethtool_op_get_link,
  1139. .get_coalesce = idpf_get_coalesce,
  1140. .set_coalesce = idpf_set_coalesce,
  1141. .get_per_queue_coalesce = idpf_get_per_q_coalesce,
  1142. .set_per_queue_coalesce = idpf_set_per_q_coalesce,
  1143. .get_ethtool_stats = idpf_get_ethtool_stats,
  1144. .get_strings = idpf_get_strings,
  1145. .get_sset_count = idpf_get_sset_count,
  1146. .get_channels = idpf_get_channels,
  1147. .get_rxnfc = idpf_get_rxnfc,
  1148. .get_rxfh_key_size = idpf_get_rxfh_key_size,
  1149. .get_rxfh_indir_size = idpf_get_rxfh_indir_size,
  1150. .get_rxfh = idpf_get_rxfh,
  1151. .set_rxfh = idpf_set_rxfh,
  1152. .set_channels = idpf_set_channels,
  1153. .get_ringparam = idpf_get_ringparam,
  1154. .set_ringparam = idpf_set_ringparam,
  1155. .get_link_ksettings = idpf_get_link_ksettings,
  1156. };
  1157. /**
  1158. * idpf_set_ethtool_ops - Initialize ethtool ops struct
  1159. * @netdev: network interface device structure
  1160. *
  1161. * Sets ethtool ops struct in our netdev so that ethtool can call
  1162. * our functions.
  1163. */
  1164. void idpf_set_ethtool_ops(struct net_device *netdev)
  1165. {
  1166. netdev->ethtool_ops = &idpf_ethtool_ops;
  1167. }