qede_ethtool.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600
  1. /* QLogic qede NIC Driver
  2. * Copyright (c) 2015 QLogic Corporation
  3. *
  4. * This software is available under the terms of the GNU General Public License
  5. * (GPL) Version 2, available from the file COPYING in the main directory of
  6. * this source tree.
  7. */
  8. #include <linux/version.h>
  9. #include <linux/types.h>
  10. #include <linux/netdevice.h>
  11. #include <linux/etherdevice.h>
  12. #include <linux/ethtool.h>
  13. #include <linux/string.h>
  14. #include <linux/pci.h>
  15. #include <linux/capability.h>
  16. #include "qede.h"
  17. #define QEDE_RQSTAT_OFFSET(stat_name) \
  18. (offsetof(struct qede_rx_queue, stat_name))
  19. #define QEDE_RQSTAT_STRING(stat_name) (#stat_name)
  20. #define QEDE_RQSTAT(stat_name) \
  21. {QEDE_RQSTAT_OFFSET(stat_name), QEDE_RQSTAT_STRING(stat_name)}
  22. #define QEDE_SELFTEST_POLL_COUNT 100
  23. static const struct {
  24. u64 offset;
  25. char string[ETH_GSTRING_LEN];
  26. } qede_rqstats_arr[] = {
  27. QEDE_RQSTAT(rcv_pkts),
  28. QEDE_RQSTAT(rx_hw_errors),
  29. QEDE_RQSTAT(rx_alloc_errors),
  30. QEDE_RQSTAT(rx_ip_frags),
  31. QEDE_RQSTAT(xdp_no_pass),
  32. };
  33. #define QEDE_NUM_RQSTATS ARRAY_SIZE(qede_rqstats_arr)
  34. #define QEDE_TQSTAT_OFFSET(stat_name) \
  35. (offsetof(struct qede_tx_queue, stat_name))
  36. #define QEDE_TQSTAT_STRING(stat_name) (#stat_name)
  37. #define QEDE_TQSTAT(stat_name) \
  38. {QEDE_TQSTAT_OFFSET(stat_name), QEDE_TQSTAT_STRING(stat_name)}
  39. #define QEDE_NUM_TQSTATS ARRAY_SIZE(qede_tqstats_arr)
  40. static const struct {
  41. u64 offset;
  42. char string[ETH_GSTRING_LEN];
  43. } qede_tqstats_arr[] = {
  44. QEDE_TQSTAT(xmit_pkts),
  45. QEDE_TQSTAT(stopped_cnt),
  46. };
  47. #define QEDE_STAT_OFFSET(stat_name) (offsetof(struct qede_stats, stat_name))
  48. #define QEDE_STAT_STRING(stat_name) (#stat_name)
  49. #define _QEDE_STAT(stat_name, pf_only) \
  50. {QEDE_STAT_OFFSET(stat_name), QEDE_STAT_STRING(stat_name), pf_only}
  51. #define QEDE_PF_STAT(stat_name) _QEDE_STAT(stat_name, true)
  52. #define QEDE_STAT(stat_name) _QEDE_STAT(stat_name, false)
  53. static const struct {
  54. u64 offset;
  55. char string[ETH_GSTRING_LEN];
  56. bool pf_only;
  57. } qede_stats_arr[] = {
  58. QEDE_STAT(rx_ucast_bytes),
  59. QEDE_STAT(rx_mcast_bytes),
  60. QEDE_STAT(rx_bcast_bytes),
  61. QEDE_STAT(rx_ucast_pkts),
  62. QEDE_STAT(rx_mcast_pkts),
  63. QEDE_STAT(rx_bcast_pkts),
  64. QEDE_STAT(tx_ucast_bytes),
  65. QEDE_STAT(tx_mcast_bytes),
  66. QEDE_STAT(tx_bcast_bytes),
  67. QEDE_STAT(tx_ucast_pkts),
  68. QEDE_STAT(tx_mcast_pkts),
  69. QEDE_STAT(tx_bcast_pkts),
  70. QEDE_PF_STAT(rx_64_byte_packets),
  71. QEDE_PF_STAT(rx_65_to_127_byte_packets),
  72. QEDE_PF_STAT(rx_128_to_255_byte_packets),
  73. QEDE_PF_STAT(rx_256_to_511_byte_packets),
  74. QEDE_PF_STAT(rx_512_to_1023_byte_packets),
  75. QEDE_PF_STAT(rx_1024_to_1518_byte_packets),
  76. QEDE_PF_STAT(rx_1519_to_1522_byte_packets),
  77. QEDE_PF_STAT(rx_1519_to_2047_byte_packets),
  78. QEDE_PF_STAT(rx_2048_to_4095_byte_packets),
  79. QEDE_PF_STAT(rx_4096_to_9216_byte_packets),
  80. QEDE_PF_STAT(rx_9217_to_16383_byte_packets),
  81. QEDE_PF_STAT(tx_64_byte_packets),
  82. QEDE_PF_STAT(tx_65_to_127_byte_packets),
  83. QEDE_PF_STAT(tx_128_to_255_byte_packets),
  84. QEDE_PF_STAT(tx_256_to_511_byte_packets),
  85. QEDE_PF_STAT(tx_512_to_1023_byte_packets),
  86. QEDE_PF_STAT(tx_1024_to_1518_byte_packets),
  87. QEDE_PF_STAT(tx_1519_to_2047_byte_packets),
  88. QEDE_PF_STAT(tx_2048_to_4095_byte_packets),
  89. QEDE_PF_STAT(tx_4096_to_9216_byte_packets),
  90. QEDE_PF_STAT(tx_9217_to_16383_byte_packets),
  91. QEDE_PF_STAT(rx_mac_crtl_frames),
  92. QEDE_PF_STAT(tx_mac_ctrl_frames),
  93. QEDE_PF_STAT(rx_pause_frames),
  94. QEDE_PF_STAT(tx_pause_frames),
  95. QEDE_PF_STAT(rx_pfc_frames),
  96. QEDE_PF_STAT(tx_pfc_frames),
  97. QEDE_PF_STAT(rx_crc_errors),
  98. QEDE_PF_STAT(rx_align_errors),
  99. QEDE_PF_STAT(rx_carrier_errors),
  100. QEDE_PF_STAT(rx_oversize_packets),
  101. QEDE_PF_STAT(rx_jabbers),
  102. QEDE_PF_STAT(rx_undersize_packets),
  103. QEDE_PF_STAT(rx_fragments),
  104. QEDE_PF_STAT(tx_lpi_entry_count),
  105. QEDE_PF_STAT(tx_total_collisions),
  106. QEDE_PF_STAT(brb_truncates),
  107. QEDE_PF_STAT(brb_discards),
  108. QEDE_STAT(no_buff_discards),
  109. QEDE_PF_STAT(mftag_filter_discards),
  110. QEDE_PF_STAT(mac_filter_discards),
  111. QEDE_STAT(tx_err_drop_pkts),
  112. QEDE_STAT(ttl0_discard),
  113. QEDE_STAT(packet_too_big_discard),
  114. QEDE_STAT(coalesced_pkts),
  115. QEDE_STAT(coalesced_events),
  116. QEDE_STAT(coalesced_aborts_num),
  117. QEDE_STAT(non_coalesced_pkts),
  118. QEDE_STAT(coalesced_bytes),
  119. };
  120. #define QEDE_NUM_STATS ARRAY_SIZE(qede_stats_arr)
  121. enum {
  122. QEDE_PRI_FLAG_CMT,
  123. QEDE_PRI_FLAG_LEN,
  124. };
  125. static const char qede_private_arr[QEDE_PRI_FLAG_LEN][ETH_GSTRING_LEN] = {
  126. "Coupled-Function",
  127. };
  128. enum qede_ethtool_tests {
  129. QEDE_ETHTOOL_INT_LOOPBACK,
  130. QEDE_ETHTOOL_INTERRUPT_TEST,
  131. QEDE_ETHTOOL_MEMORY_TEST,
  132. QEDE_ETHTOOL_REGISTER_TEST,
  133. QEDE_ETHTOOL_CLOCK_TEST,
  134. QEDE_ETHTOOL_NVRAM_TEST,
  135. QEDE_ETHTOOL_TEST_MAX
  136. };
  137. static const char qede_tests_str_arr[QEDE_ETHTOOL_TEST_MAX][ETH_GSTRING_LEN] = {
  138. "Internal loopback (offline)",
  139. "Interrupt (online)\t",
  140. "Memory (online)\t\t",
  141. "Register (online)\t",
  142. "Clock (online)\t\t",
  143. "Nvram (online)\t\t",
  144. };
  145. static void qede_get_strings_stats_txq(struct qede_dev *edev,
  146. struct qede_tx_queue *txq, u8 **buf)
  147. {
  148. int i;
  149. for (i = 0; i < QEDE_NUM_TQSTATS; i++) {
  150. if (txq->is_xdp)
  151. sprintf(*buf, "%d [XDP]: %s",
  152. QEDE_TXQ_XDP_TO_IDX(edev, txq),
  153. qede_tqstats_arr[i].string);
  154. else
  155. sprintf(*buf, "%d: %s", txq->index,
  156. qede_tqstats_arr[i].string);
  157. *buf += ETH_GSTRING_LEN;
  158. }
  159. }
  160. static void qede_get_strings_stats_rxq(struct qede_dev *edev,
  161. struct qede_rx_queue *rxq, u8 **buf)
  162. {
  163. int i;
  164. for (i = 0; i < QEDE_NUM_RQSTATS; i++) {
  165. sprintf(*buf, "%d: %s", rxq->rxq_id,
  166. qede_rqstats_arr[i].string);
  167. *buf += ETH_GSTRING_LEN;
  168. }
  169. }
  170. static void qede_get_strings_stats(struct qede_dev *edev, u8 *buf)
  171. {
  172. struct qede_fastpath *fp;
  173. int i;
  174. /* Account for queue statistics */
  175. for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
  176. fp = &edev->fp_array[i];
  177. if (fp->type & QEDE_FASTPATH_RX)
  178. qede_get_strings_stats_rxq(edev, fp->rxq, &buf);
  179. if (fp->type & QEDE_FASTPATH_XDP)
  180. qede_get_strings_stats_txq(edev, fp->xdp_tx, &buf);
  181. if (fp->type & QEDE_FASTPATH_TX)
  182. qede_get_strings_stats_txq(edev, fp->txq, &buf);
  183. }
  184. /* Account for non-queue statistics */
  185. for (i = 0; i < QEDE_NUM_STATS; i++) {
  186. if (IS_VF(edev) && qede_stats_arr[i].pf_only)
  187. continue;
  188. strcpy(buf, qede_stats_arr[i].string);
  189. buf += ETH_GSTRING_LEN;
  190. }
  191. }
  192. static void qede_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
  193. {
  194. struct qede_dev *edev = netdev_priv(dev);
  195. switch (stringset) {
  196. case ETH_SS_STATS:
  197. qede_get_strings_stats(edev, buf);
  198. break;
  199. case ETH_SS_PRIV_FLAGS:
  200. memcpy(buf, qede_private_arr,
  201. ETH_GSTRING_LEN * QEDE_PRI_FLAG_LEN);
  202. break;
  203. case ETH_SS_TEST:
  204. memcpy(buf, qede_tests_str_arr,
  205. ETH_GSTRING_LEN * QEDE_ETHTOOL_TEST_MAX);
  206. break;
  207. default:
  208. DP_VERBOSE(edev, QED_MSG_DEBUG,
  209. "Unsupported stringset 0x%08x\n", stringset);
  210. }
  211. }
  212. static void qede_get_ethtool_stats_txq(struct qede_tx_queue *txq, u64 **buf)
  213. {
  214. int i;
  215. for (i = 0; i < QEDE_NUM_TQSTATS; i++) {
  216. **buf = *((u64 *)(((void *)txq) + qede_tqstats_arr[i].offset));
  217. (*buf)++;
  218. }
  219. }
  220. static void qede_get_ethtool_stats_rxq(struct qede_rx_queue *rxq, u64 **buf)
  221. {
  222. int i;
  223. for (i = 0; i < QEDE_NUM_RQSTATS; i++) {
  224. **buf = *((u64 *)(((void *)rxq) + qede_rqstats_arr[i].offset));
  225. (*buf)++;
  226. }
  227. }
  228. static void qede_get_ethtool_stats(struct net_device *dev,
  229. struct ethtool_stats *stats, u64 *buf)
  230. {
  231. struct qede_dev *edev = netdev_priv(dev);
  232. struct qede_fastpath *fp;
  233. int i;
  234. qede_fill_by_demand_stats(edev);
  235. /* Need to protect the access to the fastpath array */
  236. __qede_lock(edev);
  237. for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
  238. fp = &edev->fp_array[i];
  239. if (fp->type & QEDE_FASTPATH_RX)
  240. qede_get_ethtool_stats_rxq(fp->rxq, &buf);
  241. if (fp->type & QEDE_FASTPATH_XDP)
  242. qede_get_ethtool_stats_txq(fp->xdp_tx, &buf);
  243. if (fp->type & QEDE_FASTPATH_TX)
  244. qede_get_ethtool_stats_txq(fp->txq, &buf);
  245. }
  246. for (i = 0; i < QEDE_NUM_STATS; i++) {
  247. if (IS_VF(edev) && qede_stats_arr[i].pf_only)
  248. continue;
  249. *buf = *((u64 *)(((void *)&edev->stats) +
  250. qede_stats_arr[i].offset));
  251. buf++;
  252. }
  253. __qede_unlock(edev);
  254. }
  255. static int qede_get_sset_count(struct net_device *dev, int stringset)
  256. {
  257. struct qede_dev *edev = netdev_priv(dev);
  258. int num_stats = QEDE_NUM_STATS;
  259. switch (stringset) {
  260. case ETH_SS_STATS:
  261. if (IS_VF(edev)) {
  262. int i;
  263. for (i = 0; i < QEDE_NUM_STATS; i++)
  264. if (qede_stats_arr[i].pf_only)
  265. num_stats--;
  266. }
  267. /* Account for the Regular Tx statistics */
  268. num_stats += QEDE_TSS_COUNT(edev) * QEDE_NUM_TQSTATS;
  269. /* Account for the Regular Rx statistics */
  270. num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_RQSTATS;
  271. /* Account for XDP statistics [if needed] */
  272. if (edev->xdp_prog)
  273. num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_TQSTATS;
  274. return num_stats;
  275. case ETH_SS_PRIV_FLAGS:
  276. return QEDE_PRI_FLAG_LEN;
  277. case ETH_SS_TEST:
  278. if (!IS_VF(edev))
  279. return QEDE_ETHTOOL_TEST_MAX;
  280. else
  281. return 0;
  282. default:
  283. DP_VERBOSE(edev, QED_MSG_DEBUG,
  284. "Unsupported stringset 0x%08x\n", stringset);
  285. return -EINVAL;
  286. }
  287. }
  288. static u32 qede_get_priv_flags(struct net_device *dev)
  289. {
  290. struct qede_dev *edev = netdev_priv(dev);
  291. return (!!(edev->dev_info.common.num_hwfns > 1)) << QEDE_PRI_FLAG_CMT;
  292. }
  293. struct qede_link_mode_mapping {
  294. u32 qed_link_mode;
  295. u32 ethtool_link_mode;
  296. };
  297. static const struct qede_link_mode_mapping qed_lm_map[] = {
  298. {QED_LM_FIBRE_BIT, ETHTOOL_LINK_MODE_FIBRE_BIT},
  299. {QED_LM_Autoneg_BIT, ETHTOOL_LINK_MODE_Autoneg_BIT},
  300. {QED_LM_Asym_Pause_BIT, ETHTOOL_LINK_MODE_Asym_Pause_BIT},
  301. {QED_LM_Pause_BIT, ETHTOOL_LINK_MODE_Pause_BIT},
  302. {QED_LM_1000baseT_Half_BIT, ETHTOOL_LINK_MODE_1000baseT_Half_BIT},
  303. {QED_LM_1000baseT_Full_BIT, ETHTOOL_LINK_MODE_1000baseT_Full_BIT},
  304. {QED_LM_10000baseKR_Full_BIT, ETHTOOL_LINK_MODE_10000baseKR_Full_BIT},
  305. {QED_LM_25000baseKR_Full_BIT, ETHTOOL_LINK_MODE_25000baseKR_Full_BIT},
  306. {QED_LM_40000baseLR4_Full_BIT, ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT},
  307. {QED_LM_50000baseKR2_Full_BIT, ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT},
  308. {QED_LM_100000baseKR4_Full_BIT,
  309. ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT},
  310. };
  311. #define QEDE_DRV_TO_ETHTOOL_CAPS(caps, lk_ksettings, name) \
  312. { \
  313. int i; \
  314. \
  315. for (i = 0; i < ARRAY_SIZE(qed_lm_map); i++) { \
  316. if ((caps) & (qed_lm_map[i].qed_link_mode)) \
  317. __set_bit(qed_lm_map[i].ethtool_link_mode,\
  318. lk_ksettings->link_modes.name); \
  319. } \
  320. }
  321. #define QEDE_ETHTOOL_TO_DRV_CAPS(caps, lk_ksettings, name) \
  322. { \
  323. int i; \
  324. \
  325. for (i = 0; i < ARRAY_SIZE(qed_lm_map); i++) { \
  326. if (test_bit(qed_lm_map[i].ethtool_link_mode, \
  327. lk_ksettings->link_modes.name)) \
  328. caps |= qed_lm_map[i].qed_link_mode; \
  329. } \
  330. }
  331. static int qede_get_link_ksettings(struct net_device *dev,
  332. struct ethtool_link_ksettings *cmd)
  333. {
  334. struct ethtool_link_settings *base = &cmd->base;
  335. struct qede_dev *edev = netdev_priv(dev);
  336. struct qed_link_output current_link;
  337. __qede_lock(edev);
  338. memset(&current_link, 0, sizeof(current_link));
  339. edev->ops->common->get_link(edev->cdev, &current_link);
  340. ethtool_link_ksettings_zero_link_mode(cmd, supported);
  341. QEDE_DRV_TO_ETHTOOL_CAPS(current_link.supported_caps, cmd, supported)
  342. ethtool_link_ksettings_zero_link_mode(cmd, advertising);
  343. QEDE_DRV_TO_ETHTOOL_CAPS(current_link.advertised_caps, cmd, advertising)
  344. ethtool_link_ksettings_zero_link_mode(cmd, lp_advertising);
  345. QEDE_DRV_TO_ETHTOOL_CAPS(current_link.lp_caps, cmd, lp_advertising)
  346. if ((edev->state == QEDE_STATE_OPEN) && (current_link.link_up)) {
  347. base->speed = current_link.speed;
  348. base->duplex = current_link.duplex;
  349. } else {
  350. base->speed = SPEED_UNKNOWN;
  351. base->duplex = DUPLEX_UNKNOWN;
  352. }
  353. __qede_unlock(edev);
  354. base->port = current_link.port;
  355. base->autoneg = (current_link.autoneg) ? AUTONEG_ENABLE :
  356. AUTONEG_DISABLE;
  357. return 0;
  358. }
  359. static int qede_set_link_ksettings(struct net_device *dev,
  360. const struct ethtool_link_ksettings *cmd)
  361. {
  362. const struct ethtool_link_settings *base = &cmd->base;
  363. struct qede_dev *edev = netdev_priv(dev);
  364. struct qed_link_output current_link;
  365. struct qed_link_params params;
  366. if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
  367. DP_INFO(edev, "Link settings are not allowed to be changed\n");
  368. return -EOPNOTSUPP;
  369. }
  370. memset(&current_link, 0, sizeof(current_link));
  371. memset(&params, 0, sizeof(params));
  372. edev->ops->common->get_link(edev->cdev, &current_link);
  373. params.override_flags |= QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS;
  374. params.override_flags |= QED_LINK_OVERRIDE_SPEED_AUTONEG;
  375. if (base->autoneg == AUTONEG_ENABLE) {
  376. params.autoneg = true;
  377. params.forced_speed = 0;
  378. QEDE_ETHTOOL_TO_DRV_CAPS(params.adv_speeds, cmd, advertising)
  379. } else { /* forced speed */
  380. params.override_flags |= QED_LINK_OVERRIDE_SPEED_FORCED_SPEED;
  381. params.autoneg = false;
  382. params.forced_speed = base->speed;
  383. switch (base->speed) {
  384. case SPEED_10000:
  385. if (!(current_link.supported_caps &
  386. QED_LM_10000baseKR_Full_BIT)) {
  387. DP_INFO(edev, "10G speed not supported\n");
  388. return -EINVAL;
  389. }
  390. params.adv_speeds = QED_LM_10000baseKR_Full_BIT;
  391. break;
  392. case SPEED_25000:
  393. if (!(current_link.supported_caps &
  394. QED_LM_25000baseKR_Full_BIT)) {
  395. DP_INFO(edev, "25G speed not supported\n");
  396. return -EINVAL;
  397. }
  398. params.adv_speeds = QED_LM_25000baseKR_Full_BIT;
  399. break;
  400. case SPEED_40000:
  401. if (!(current_link.supported_caps &
  402. QED_LM_40000baseLR4_Full_BIT)) {
  403. DP_INFO(edev, "40G speed not supported\n");
  404. return -EINVAL;
  405. }
  406. params.adv_speeds = QED_LM_40000baseLR4_Full_BIT;
  407. break;
  408. case SPEED_50000:
  409. if (!(current_link.supported_caps &
  410. QED_LM_50000baseKR2_Full_BIT)) {
  411. DP_INFO(edev, "50G speed not supported\n");
  412. return -EINVAL;
  413. }
  414. params.adv_speeds = QED_LM_50000baseKR2_Full_BIT;
  415. break;
  416. case SPEED_100000:
  417. if (!(current_link.supported_caps &
  418. QED_LM_100000baseKR4_Full_BIT)) {
  419. DP_INFO(edev, "100G speed not supported\n");
  420. return -EINVAL;
  421. }
  422. params.adv_speeds = QED_LM_100000baseKR4_Full_BIT;
  423. break;
  424. default:
  425. DP_INFO(edev, "Unsupported speed %u\n", base->speed);
  426. return -EINVAL;
  427. }
  428. }
  429. params.link_up = true;
  430. edev->ops->common->set_link(edev->cdev, &params);
  431. return 0;
  432. }
  433. static void qede_get_drvinfo(struct net_device *ndev,
  434. struct ethtool_drvinfo *info)
  435. {
  436. char mfw[ETHTOOL_FWVERS_LEN], storm[ETHTOOL_FWVERS_LEN];
  437. struct qede_dev *edev = netdev_priv(ndev);
  438. strlcpy(info->driver, "qede", sizeof(info->driver));
  439. strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
  440. snprintf(storm, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
  441. edev->dev_info.common.fw_major,
  442. edev->dev_info.common.fw_minor,
  443. edev->dev_info.common.fw_rev,
  444. edev->dev_info.common.fw_eng);
  445. snprintf(mfw, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
  446. (edev->dev_info.common.mfw_rev >> 24) & 0xFF,
  447. (edev->dev_info.common.mfw_rev >> 16) & 0xFF,
  448. (edev->dev_info.common.mfw_rev >> 8) & 0xFF,
  449. edev->dev_info.common.mfw_rev & 0xFF);
  450. if ((strlen(storm) + strlen(mfw) + strlen("mfw storm ")) <
  451. sizeof(info->fw_version)) {
  452. snprintf(info->fw_version, sizeof(info->fw_version),
  453. "mfw %s storm %s", mfw, storm);
  454. } else {
  455. snprintf(info->fw_version, sizeof(info->fw_version),
  456. "%s %s", mfw, storm);
  457. }
  458. strlcpy(info->bus_info, pci_name(edev->pdev), sizeof(info->bus_info));
  459. }
  460. static void qede_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
  461. {
  462. struct qede_dev *edev = netdev_priv(ndev);
  463. if (edev->dev_info.common.wol_support) {
  464. wol->supported = WAKE_MAGIC;
  465. wol->wolopts = edev->wol_enabled ? WAKE_MAGIC : 0;
  466. }
  467. }
  468. static int qede_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
  469. {
  470. struct qede_dev *edev = netdev_priv(ndev);
  471. bool wol_requested;
  472. int rc;
  473. if (wol->wolopts & ~WAKE_MAGIC) {
  474. DP_INFO(edev,
  475. "Can't support WoL options other than magic-packet\n");
  476. return -EINVAL;
  477. }
  478. wol_requested = !!(wol->wolopts & WAKE_MAGIC);
  479. if (wol_requested == edev->wol_enabled)
  480. return 0;
  481. /* Need to actually change configuration */
  482. if (!edev->dev_info.common.wol_support) {
  483. DP_INFO(edev, "Device doesn't support WoL\n");
  484. return -EINVAL;
  485. }
  486. rc = edev->ops->common->update_wol(edev->cdev, wol_requested);
  487. if (!rc)
  488. edev->wol_enabled = wol_requested;
  489. return rc;
  490. }
  491. static u32 qede_get_msglevel(struct net_device *ndev)
  492. {
  493. struct qede_dev *edev = netdev_priv(ndev);
  494. return ((u32)edev->dp_level << QED_LOG_LEVEL_SHIFT) | edev->dp_module;
  495. }
  496. static void qede_set_msglevel(struct net_device *ndev, u32 level)
  497. {
  498. struct qede_dev *edev = netdev_priv(ndev);
  499. u32 dp_module = 0;
  500. u8 dp_level = 0;
  501. qede_config_debug(level, &dp_module, &dp_level);
  502. edev->dp_level = dp_level;
  503. edev->dp_module = dp_module;
  504. edev->ops->common->update_msglvl(edev->cdev,
  505. dp_module, dp_level);
  506. }
  507. static int qede_nway_reset(struct net_device *dev)
  508. {
  509. struct qede_dev *edev = netdev_priv(dev);
  510. struct qed_link_output current_link;
  511. struct qed_link_params link_params;
  512. if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
  513. DP_INFO(edev, "Link settings are not allowed to be changed\n");
  514. return -EOPNOTSUPP;
  515. }
  516. if (!netif_running(dev))
  517. return 0;
  518. memset(&current_link, 0, sizeof(current_link));
  519. edev->ops->common->get_link(edev->cdev, &current_link);
  520. if (!current_link.link_up)
  521. return 0;
  522. /* Toggle the link */
  523. memset(&link_params, 0, sizeof(link_params));
  524. link_params.link_up = false;
  525. edev->ops->common->set_link(edev->cdev, &link_params);
  526. link_params.link_up = true;
  527. edev->ops->common->set_link(edev->cdev, &link_params);
  528. return 0;
  529. }
  530. static u32 qede_get_link(struct net_device *dev)
  531. {
  532. struct qede_dev *edev = netdev_priv(dev);
  533. struct qed_link_output current_link;
  534. memset(&current_link, 0, sizeof(current_link));
  535. edev->ops->common->get_link(edev->cdev, &current_link);
  536. return current_link.link_up;
  537. }
  538. static int qede_get_coalesce(struct net_device *dev,
  539. struct ethtool_coalesce *coal)
  540. {
  541. struct qede_dev *edev = netdev_priv(dev);
  542. u16 rxc, txc;
  543. memset(coal, 0, sizeof(struct ethtool_coalesce));
  544. edev->ops->common->get_coalesce(edev->cdev, &rxc, &txc);
  545. coal->rx_coalesce_usecs = rxc;
  546. coal->tx_coalesce_usecs = txc;
  547. return 0;
  548. }
  549. static int qede_set_coalesce(struct net_device *dev,
  550. struct ethtool_coalesce *coal)
  551. {
  552. struct qede_dev *edev = netdev_priv(dev);
  553. int i, rc = 0;
  554. u16 rxc, txc;
  555. u8 sb_id;
  556. if (!netif_running(dev)) {
  557. DP_INFO(edev, "Interface is down\n");
  558. return -EINVAL;
  559. }
  560. if (coal->rx_coalesce_usecs > QED_COALESCE_MAX ||
  561. coal->tx_coalesce_usecs > QED_COALESCE_MAX) {
  562. DP_INFO(edev,
  563. "Can't support requested %s coalesce value [max supported value %d]\n",
  564. coal->rx_coalesce_usecs > QED_COALESCE_MAX ? "rx"
  565. : "tx",
  566. QED_COALESCE_MAX);
  567. return -EINVAL;
  568. }
  569. rxc = (u16)coal->rx_coalesce_usecs;
  570. txc = (u16)coal->tx_coalesce_usecs;
  571. for_each_queue(i) {
  572. sb_id = edev->fp_array[i].sb_info->igu_sb_id;
  573. rc = edev->ops->common->set_coalesce(edev->cdev, rxc, txc,
  574. (u8)i, sb_id);
  575. if (rc) {
  576. DP_INFO(edev, "Set coalesce error, rc = %d\n", rc);
  577. return rc;
  578. }
  579. }
  580. return rc;
  581. }
  582. static void qede_get_ringparam(struct net_device *dev,
  583. struct ethtool_ringparam *ering)
  584. {
  585. struct qede_dev *edev = netdev_priv(dev);
  586. ering->rx_max_pending = NUM_RX_BDS_MAX;
  587. ering->rx_pending = edev->q_num_rx_buffers;
  588. ering->tx_max_pending = NUM_TX_BDS_MAX;
  589. ering->tx_pending = edev->q_num_tx_buffers;
  590. }
  591. static int qede_set_ringparam(struct net_device *dev,
  592. struct ethtool_ringparam *ering)
  593. {
  594. struct qede_dev *edev = netdev_priv(dev);
  595. DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
  596. "Set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
  597. ering->rx_pending, ering->tx_pending);
  598. /* Validate legality of configuration */
  599. if (ering->rx_pending > NUM_RX_BDS_MAX ||
  600. ering->rx_pending < NUM_RX_BDS_MIN ||
  601. ering->tx_pending > NUM_TX_BDS_MAX ||
  602. ering->tx_pending < NUM_TX_BDS_MIN) {
  603. DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
  604. "Can only support Rx Buffer size [0%08x,...,0x%08x] and Tx Buffer size [0x%08x,...,0x%08x]\n",
  605. NUM_RX_BDS_MIN, NUM_RX_BDS_MAX,
  606. NUM_TX_BDS_MIN, NUM_TX_BDS_MAX);
  607. return -EINVAL;
  608. }
  609. /* Change ring size and re-load */
  610. edev->q_num_rx_buffers = ering->rx_pending;
  611. edev->q_num_tx_buffers = ering->tx_pending;
  612. qede_reload(edev, NULL, false);
  613. return 0;
  614. }
  615. static void qede_get_pauseparam(struct net_device *dev,
  616. struct ethtool_pauseparam *epause)
  617. {
  618. struct qede_dev *edev = netdev_priv(dev);
  619. struct qed_link_output current_link;
  620. memset(&current_link, 0, sizeof(current_link));
  621. edev->ops->common->get_link(edev->cdev, &current_link);
  622. if (current_link.pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
  623. epause->autoneg = true;
  624. if (current_link.pause_config & QED_LINK_PAUSE_RX_ENABLE)
  625. epause->rx_pause = true;
  626. if (current_link.pause_config & QED_LINK_PAUSE_TX_ENABLE)
  627. epause->tx_pause = true;
  628. DP_VERBOSE(edev, QED_MSG_DEBUG,
  629. "ethtool_pauseparam: cmd %d autoneg %d rx_pause %d tx_pause %d\n",
  630. epause->cmd, epause->autoneg, epause->rx_pause,
  631. epause->tx_pause);
  632. }
  633. static int qede_set_pauseparam(struct net_device *dev,
  634. struct ethtool_pauseparam *epause)
  635. {
  636. struct qede_dev *edev = netdev_priv(dev);
  637. struct qed_link_params params;
  638. struct qed_link_output current_link;
  639. if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
  640. DP_INFO(edev,
  641. "Pause settings are not allowed to be changed\n");
  642. return -EOPNOTSUPP;
  643. }
  644. memset(&current_link, 0, sizeof(current_link));
  645. edev->ops->common->get_link(edev->cdev, &current_link);
  646. memset(&params, 0, sizeof(params));
  647. params.override_flags |= QED_LINK_OVERRIDE_PAUSE_CONFIG;
  648. if (epause->autoneg) {
  649. if (!(current_link.supported_caps & QED_LM_Autoneg_BIT)) {
  650. DP_INFO(edev, "autoneg not supported\n");
  651. return -EINVAL;
  652. }
  653. params.pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
  654. }
  655. if (epause->rx_pause)
  656. params.pause_config |= QED_LINK_PAUSE_RX_ENABLE;
  657. if (epause->tx_pause)
  658. params.pause_config |= QED_LINK_PAUSE_TX_ENABLE;
  659. params.link_up = true;
  660. edev->ops->common->set_link(edev->cdev, &params);
  661. return 0;
  662. }
  663. static void qede_get_regs(struct net_device *ndev,
  664. struct ethtool_regs *regs, void *buffer)
  665. {
  666. struct qede_dev *edev = netdev_priv(ndev);
  667. regs->version = 0;
  668. memset(buffer, 0, regs->len);
  669. if (edev->ops && edev->ops->common)
  670. edev->ops->common->dbg_all_data(edev->cdev, buffer);
  671. }
  672. static int qede_get_regs_len(struct net_device *ndev)
  673. {
  674. struct qede_dev *edev = netdev_priv(ndev);
  675. if (edev->ops && edev->ops->common)
  676. return edev->ops->common->dbg_all_data_size(edev->cdev);
  677. else
  678. return -EINVAL;
  679. }
  680. static void qede_update_mtu(struct qede_dev *edev,
  681. struct qede_reload_args *args)
  682. {
  683. edev->ndev->mtu = args->u.mtu;
  684. }
  685. /* Netdevice NDOs */
  686. int qede_change_mtu(struct net_device *ndev, int new_mtu)
  687. {
  688. struct qede_dev *edev = netdev_priv(ndev);
  689. struct qede_reload_args args;
  690. DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
  691. "Configuring MTU size of %d\n", new_mtu);
  692. /* Set the mtu field and re-start the interface if needed */
  693. args.u.mtu = new_mtu;
  694. args.func = &qede_update_mtu;
  695. qede_reload(edev, &args, false);
  696. edev->ops->common->update_mtu(edev->cdev, new_mtu);
  697. return 0;
  698. }
  699. static void qede_get_channels(struct net_device *dev,
  700. struct ethtool_channels *channels)
  701. {
  702. struct qede_dev *edev = netdev_priv(dev);
  703. channels->max_combined = QEDE_MAX_RSS_CNT(edev);
  704. channels->max_rx = QEDE_MAX_RSS_CNT(edev);
  705. channels->max_tx = QEDE_MAX_RSS_CNT(edev);
  706. channels->combined_count = QEDE_QUEUE_CNT(edev) - edev->fp_num_tx -
  707. edev->fp_num_rx;
  708. channels->tx_count = edev->fp_num_tx;
  709. channels->rx_count = edev->fp_num_rx;
  710. }
  711. static int qede_set_channels(struct net_device *dev,
  712. struct ethtool_channels *channels)
  713. {
  714. struct qede_dev *edev = netdev_priv(dev);
  715. u32 count;
  716. DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
  717. "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n",
  718. channels->rx_count, channels->tx_count,
  719. channels->other_count, channels->combined_count);
  720. count = channels->rx_count + channels->tx_count +
  721. channels->combined_count;
  722. /* We don't support `other' channels */
  723. if (channels->other_count) {
  724. DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
  725. "command parameters not supported\n");
  726. return -EINVAL;
  727. }
  728. if (!(channels->combined_count || (channels->rx_count &&
  729. channels->tx_count))) {
  730. DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
  731. "need to request at least one transmit and one receive channel\n");
  732. return -EINVAL;
  733. }
  734. if (count > QEDE_MAX_RSS_CNT(edev)) {
  735. DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
  736. "requested channels = %d max supported channels = %d\n",
  737. count, QEDE_MAX_RSS_CNT(edev));
  738. return -EINVAL;
  739. }
  740. /* Check if there was a change in the active parameters */
  741. if ((count == QEDE_QUEUE_CNT(edev)) &&
  742. (channels->tx_count == edev->fp_num_tx) &&
  743. (channels->rx_count == edev->fp_num_rx)) {
  744. DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
  745. "No change in active parameters\n");
  746. return 0;
  747. }
  748. /* We need the number of queues to be divisible between the hwfns */
  749. if ((count % edev->dev_info.common.num_hwfns) ||
  750. (channels->tx_count % edev->dev_info.common.num_hwfns) ||
  751. (channels->rx_count % edev->dev_info.common.num_hwfns)) {
  752. DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
  753. "Number of channels must be divisible by %04x\n",
  754. edev->dev_info.common.num_hwfns);
  755. return -EINVAL;
  756. }
  757. /* Set number of queues and reload if necessary */
  758. edev->req_queues = count;
  759. edev->req_num_tx = channels->tx_count;
  760. edev->req_num_rx = channels->rx_count;
  761. /* Reset the indirection table if rx queue count is updated */
  762. if ((edev->req_queues - edev->req_num_tx) != QEDE_RSS_COUNT(edev)) {
  763. edev->rss_params_inited &= ~QEDE_RSS_INDIR_INITED;
  764. memset(&edev->rss_params.rss_ind_table, 0,
  765. sizeof(edev->rss_params.rss_ind_table));
  766. }
  767. qede_reload(edev, NULL, false);
  768. return 0;
  769. }
  770. static int qede_set_phys_id(struct net_device *dev,
  771. enum ethtool_phys_id_state state)
  772. {
  773. struct qede_dev *edev = netdev_priv(dev);
  774. u8 led_state = 0;
  775. switch (state) {
  776. case ETHTOOL_ID_ACTIVE:
  777. return 1; /* cycle on/off once per second */
  778. case ETHTOOL_ID_ON:
  779. led_state = QED_LED_MODE_ON;
  780. break;
  781. case ETHTOOL_ID_OFF:
  782. led_state = QED_LED_MODE_OFF;
  783. break;
  784. case ETHTOOL_ID_INACTIVE:
  785. led_state = QED_LED_MODE_RESTORE;
  786. break;
  787. }
  788. edev->ops->common->set_led(edev->cdev, led_state);
  789. return 0;
  790. }
  791. static int qede_get_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
  792. {
  793. info->data = RXH_IP_SRC | RXH_IP_DST;
  794. switch (info->flow_type) {
  795. case TCP_V4_FLOW:
  796. case TCP_V6_FLOW:
  797. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  798. break;
  799. case UDP_V4_FLOW:
  800. if (edev->rss_params.rss_caps & QED_RSS_IPV4_UDP)
  801. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  802. break;
  803. case UDP_V6_FLOW:
  804. if (edev->rss_params.rss_caps & QED_RSS_IPV6_UDP)
  805. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  806. break;
  807. case IPV4_FLOW:
  808. case IPV6_FLOW:
  809. break;
  810. default:
  811. info->data = 0;
  812. break;
  813. }
  814. return 0;
  815. }
  816. static int qede_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
  817. u32 *rules __always_unused)
  818. {
  819. struct qede_dev *edev = netdev_priv(dev);
  820. switch (info->cmd) {
  821. case ETHTOOL_GRXRINGS:
  822. info->data = QEDE_RSS_COUNT(edev);
  823. return 0;
  824. case ETHTOOL_GRXFH:
  825. return qede_get_rss_flags(edev, info);
  826. default:
  827. DP_ERR(edev, "Command parameters not supported\n");
  828. return -EOPNOTSUPP;
  829. }
  830. }
  831. static int qede_set_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
  832. {
  833. struct qed_update_vport_params vport_update_params;
  834. u8 set_caps = 0, clr_caps = 0;
  835. DP_VERBOSE(edev, QED_MSG_DEBUG,
  836. "Set rss flags command parameters: flow type = %d, data = %llu\n",
  837. info->flow_type, info->data);
  838. switch (info->flow_type) {
  839. case TCP_V4_FLOW:
  840. case TCP_V6_FLOW:
  841. /* For TCP only 4-tuple hash is supported */
  842. if (info->data ^ (RXH_IP_SRC | RXH_IP_DST |
  843. RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  844. DP_INFO(edev, "Command parameters not supported\n");
  845. return -EINVAL;
  846. }
  847. return 0;
  848. case UDP_V4_FLOW:
  849. /* For UDP either 2-tuple hash or 4-tuple hash is supported */
  850. if (info->data == (RXH_IP_SRC | RXH_IP_DST |
  851. RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  852. set_caps = QED_RSS_IPV4_UDP;
  853. DP_VERBOSE(edev, QED_MSG_DEBUG,
  854. "UDP 4-tuple enabled\n");
  855. } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
  856. clr_caps = QED_RSS_IPV4_UDP;
  857. DP_VERBOSE(edev, QED_MSG_DEBUG,
  858. "UDP 4-tuple disabled\n");
  859. } else {
  860. return -EINVAL;
  861. }
  862. break;
  863. case UDP_V6_FLOW:
  864. /* For UDP either 2-tuple hash or 4-tuple hash is supported */
  865. if (info->data == (RXH_IP_SRC | RXH_IP_DST |
  866. RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  867. set_caps = QED_RSS_IPV6_UDP;
  868. DP_VERBOSE(edev, QED_MSG_DEBUG,
  869. "UDP 4-tuple enabled\n");
  870. } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
  871. clr_caps = QED_RSS_IPV6_UDP;
  872. DP_VERBOSE(edev, QED_MSG_DEBUG,
  873. "UDP 4-tuple disabled\n");
  874. } else {
  875. return -EINVAL;
  876. }
  877. break;
  878. case IPV4_FLOW:
  879. case IPV6_FLOW:
  880. /* For IP only 2-tuple hash is supported */
  881. if (info->data ^ (RXH_IP_SRC | RXH_IP_DST)) {
  882. DP_INFO(edev, "Command parameters not supported\n");
  883. return -EINVAL;
  884. }
  885. return 0;
  886. case SCTP_V4_FLOW:
  887. case AH_ESP_V4_FLOW:
  888. case AH_V4_FLOW:
  889. case ESP_V4_FLOW:
  890. case SCTP_V6_FLOW:
  891. case AH_ESP_V6_FLOW:
  892. case AH_V6_FLOW:
  893. case ESP_V6_FLOW:
  894. case IP_USER_FLOW:
  895. case ETHER_FLOW:
  896. /* RSS is not supported for these protocols */
  897. if (info->data) {
  898. DP_INFO(edev, "Command parameters not supported\n");
  899. return -EINVAL;
  900. }
  901. return 0;
  902. default:
  903. return -EINVAL;
  904. }
  905. /* No action is needed if there is no change in the rss capability */
  906. if (edev->rss_params.rss_caps == ((edev->rss_params.rss_caps &
  907. ~clr_caps) | set_caps))
  908. return 0;
  909. /* Update internal configuration */
  910. edev->rss_params.rss_caps = (edev->rss_params.rss_caps & ~clr_caps) |
  911. set_caps;
  912. edev->rss_params_inited |= QEDE_RSS_CAPS_INITED;
  913. /* Re-configure if possible */
  914. if (netif_running(edev->ndev)) {
  915. memset(&vport_update_params, 0, sizeof(vport_update_params));
  916. vport_update_params.update_rss_flg = 1;
  917. vport_update_params.vport_id = 0;
  918. memcpy(&vport_update_params.rss_params, &edev->rss_params,
  919. sizeof(vport_update_params.rss_params));
  920. return edev->ops->vport_update(edev->cdev,
  921. &vport_update_params);
  922. }
  923. return 0;
  924. }
  925. static int qede_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
  926. {
  927. struct qede_dev *edev = netdev_priv(dev);
  928. switch (info->cmd) {
  929. case ETHTOOL_SRXFH:
  930. return qede_set_rss_flags(edev, info);
  931. default:
  932. DP_INFO(edev, "Command parameters not supported\n");
  933. return -EOPNOTSUPP;
  934. }
  935. }
  936. static u32 qede_get_rxfh_indir_size(struct net_device *dev)
  937. {
  938. return QED_RSS_IND_TABLE_SIZE;
  939. }
  940. static u32 qede_get_rxfh_key_size(struct net_device *dev)
  941. {
  942. struct qede_dev *edev = netdev_priv(dev);
  943. return sizeof(edev->rss_params.rss_key);
  944. }
  945. static int qede_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, u8 *hfunc)
  946. {
  947. struct qede_dev *edev = netdev_priv(dev);
  948. int i;
  949. if (hfunc)
  950. *hfunc = ETH_RSS_HASH_TOP;
  951. if (!indir)
  952. return 0;
  953. for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
  954. indir[i] = edev->rss_params.rss_ind_table[i];
  955. if (key)
  956. memcpy(key, edev->rss_params.rss_key,
  957. qede_get_rxfh_key_size(dev));
  958. return 0;
  959. }
  960. static int qede_set_rxfh(struct net_device *dev, const u32 *indir,
  961. const u8 *key, const u8 hfunc)
  962. {
  963. struct qed_update_vport_params vport_update_params;
  964. struct qede_dev *edev = netdev_priv(dev);
  965. int i;
  966. if (edev->dev_info.common.num_hwfns > 1) {
  967. DP_INFO(edev,
  968. "RSS configuration is not supported for 100G devices\n");
  969. return -EOPNOTSUPP;
  970. }
  971. if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
  972. return -EOPNOTSUPP;
  973. if (!indir && !key)
  974. return 0;
  975. if (indir) {
  976. for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
  977. edev->rss_params.rss_ind_table[i] = indir[i];
  978. edev->rss_params_inited |= QEDE_RSS_INDIR_INITED;
  979. }
  980. if (key) {
  981. memcpy(&edev->rss_params.rss_key, key,
  982. qede_get_rxfh_key_size(dev));
  983. edev->rss_params_inited |= QEDE_RSS_KEY_INITED;
  984. }
  985. if (netif_running(edev->ndev)) {
  986. memset(&vport_update_params, 0, sizeof(vport_update_params));
  987. vport_update_params.update_rss_flg = 1;
  988. vport_update_params.vport_id = 0;
  989. memcpy(&vport_update_params.rss_params, &edev->rss_params,
  990. sizeof(vport_update_params.rss_params));
  991. return edev->ops->vport_update(edev->cdev,
  992. &vport_update_params);
  993. }
  994. return 0;
  995. }
  996. /* This function enables the interrupt generation and the NAPI on the device */
  997. static void qede_netif_start(struct qede_dev *edev)
  998. {
  999. int i;
  1000. if (!netif_running(edev->ndev))
  1001. return;
  1002. for_each_queue(i) {
  1003. /* Update and reenable interrupts */
  1004. qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_ENABLE, 1);
  1005. napi_enable(&edev->fp_array[i].napi);
  1006. }
  1007. }
  1008. /* This function disables the NAPI and the interrupt generation on the device */
  1009. static void qede_netif_stop(struct qede_dev *edev)
  1010. {
  1011. int i;
  1012. for_each_queue(i) {
  1013. napi_disable(&edev->fp_array[i].napi);
  1014. /* Disable interrupts */
  1015. qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_DISABLE, 0);
  1016. }
  1017. }
  1018. static int qede_selftest_transmit_traffic(struct qede_dev *edev,
  1019. struct sk_buff *skb)
  1020. {
  1021. struct qede_tx_queue *txq = NULL;
  1022. struct eth_tx_1st_bd *first_bd;
  1023. dma_addr_t mapping;
  1024. int i, idx, val;
  1025. for_each_queue(i) {
  1026. if (edev->fp_array[i].type & QEDE_FASTPATH_TX) {
  1027. txq = edev->fp_array[i].txq;
  1028. break;
  1029. }
  1030. }
  1031. if (!txq) {
  1032. DP_NOTICE(edev, "Tx path is not available\n");
  1033. return -1;
  1034. }
  1035. /* Fill the entry in the SW ring and the BDs in the FW ring */
  1036. idx = txq->sw_tx_prod & NUM_TX_BDS_MAX;
  1037. txq->sw_tx_ring.skbs[idx].skb = skb;
  1038. first_bd = qed_chain_produce(&txq->tx_pbl);
  1039. memset(first_bd, 0, sizeof(*first_bd));
  1040. val = 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT;
  1041. first_bd->data.bd_flags.bitfields = val;
  1042. val = skb->len & ETH_TX_DATA_1ST_BD_PKT_LEN_MASK;
  1043. first_bd->data.bitfields |= (val << ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT);
  1044. /* Map skb linear data for DMA and set in the first BD */
  1045. mapping = dma_map_single(&edev->pdev->dev, skb->data,
  1046. skb_headlen(skb), DMA_TO_DEVICE);
  1047. if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) {
  1048. DP_NOTICE(edev, "SKB mapping failed\n");
  1049. return -ENOMEM;
  1050. }
  1051. BD_SET_UNMAP_ADDR_LEN(first_bd, mapping, skb_headlen(skb));
  1052. /* update the first BD with the actual num BDs */
  1053. first_bd->data.nbds = 1;
  1054. txq->sw_tx_prod++;
  1055. /* 'next page' entries are counted in the producer value */
  1056. val = cpu_to_le16(qed_chain_get_prod_idx(&txq->tx_pbl));
  1057. txq->tx_db.data.bd_prod = val;
  1058. /* wmb makes sure that the BDs data is updated before updating the
  1059. * producer, otherwise FW may read old data from the BDs.
  1060. */
  1061. wmb();
  1062. barrier();
  1063. writel(txq->tx_db.raw, txq->doorbell_addr);
  1064. /* mmiowb is needed to synchronize doorbell writes from more than one
  1065. * processor. It guarantees that the write arrives to the device before
  1066. * the queue lock is released and another start_xmit is called (possibly
  1067. * on another CPU). Without this barrier, the next doorbell can bypass
  1068. * this doorbell. This is applicable to IA64/Altix systems.
  1069. */
  1070. mmiowb();
  1071. for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
  1072. if (qede_txq_has_work(txq))
  1073. break;
  1074. usleep_range(100, 200);
  1075. }
  1076. if (!qede_txq_has_work(txq)) {
  1077. DP_NOTICE(edev, "Tx completion didn't happen\n");
  1078. return -1;
  1079. }
  1080. first_bd = (struct eth_tx_1st_bd *)qed_chain_consume(&txq->tx_pbl);
  1081. dma_unmap_single(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd),
  1082. BD_UNMAP_LEN(first_bd), DMA_TO_DEVICE);
  1083. txq->sw_tx_cons++;
  1084. txq->sw_tx_ring.skbs[idx].skb = NULL;
  1085. return 0;
  1086. }
  1087. static int qede_selftest_receive_traffic(struct qede_dev *edev)
  1088. {
  1089. u16 hw_comp_cons, sw_comp_cons, sw_rx_index, len;
  1090. struct eth_fast_path_rx_reg_cqe *fp_cqe;
  1091. struct qede_rx_queue *rxq = NULL;
  1092. struct sw_rx_data *sw_rx_data;
  1093. union eth_rx_cqe *cqe;
  1094. int i, rc = 0;
  1095. u8 *data_ptr;
  1096. for_each_queue(i) {
  1097. if (edev->fp_array[i].type & QEDE_FASTPATH_RX) {
  1098. rxq = edev->fp_array[i].rxq;
  1099. break;
  1100. }
  1101. }
  1102. if (!rxq) {
  1103. DP_NOTICE(edev, "Rx path is not available\n");
  1104. return -1;
  1105. }
  1106. /* The packet is expected to receive on rx-queue 0 even though RSS is
  1107. * enabled. This is because the queue 0 is configured as the default
  1108. * queue and that the loopback traffic is not IP.
  1109. */
  1110. for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
  1111. if (!qede_has_rx_work(rxq)) {
  1112. usleep_range(100, 200);
  1113. continue;
  1114. }
  1115. hw_comp_cons = le16_to_cpu(*rxq->hw_cons_ptr);
  1116. sw_comp_cons = qed_chain_get_cons_idx(&rxq->rx_comp_ring);
  1117. /* Memory barrier to prevent the CPU from doing speculative
  1118. * reads of CQE/BD before reading hw_comp_cons. If the CQE is
  1119. * read before it is written by FW, then FW writes CQE and SB,
  1120. * and then the CPU reads the hw_comp_cons, it will use an old
  1121. * CQE.
  1122. */
  1123. rmb();
  1124. /* Get the CQE from the completion ring */
  1125. cqe = (union eth_rx_cqe *)qed_chain_consume(&rxq->rx_comp_ring);
  1126. /* Get the data from the SW ring */
  1127. sw_rx_index = rxq->sw_rx_cons & NUM_RX_BDS_MAX;
  1128. sw_rx_data = &rxq->sw_rx_ring[sw_rx_index];
  1129. fp_cqe = &cqe->fast_path_regular;
  1130. len = le16_to_cpu(fp_cqe->len_on_first_bd);
  1131. data_ptr = (u8 *)(page_address(sw_rx_data->data) +
  1132. fp_cqe->placement_offset +
  1133. sw_rx_data->page_offset);
  1134. if (ether_addr_equal(data_ptr, edev->ndev->dev_addr) &&
  1135. ether_addr_equal(data_ptr + ETH_ALEN,
  1136. edev->ndev->dev_addr)) {
  1137. for (i = ETH_HLEN; i < len; i++)
  1138. if (data_ptr[i] != (unsigned char)(i & 0xff)) {
  1139. rc = -1;
  1140. break;
  1141. }
  1142. qede_recycle_rx_bd_ring(rxq, 1);
  1143. qed_chain_recycle_consumed(&rxq->rx_comp_ring);
  1144. break;
  1145. }
  1146. DP_INFO(edev, "Not the transmitted packet\n");
  1147. qede_recycle_rx_bd_ring(rxq, 1);
  1148. qed_chain_recycle_consumed(&rxq->rx_comp_ring);
  1149. }
  1150. if (i == QEDE_SELFTEST_POLL_COUNT) {
  1151. DP_NOTICE(edev, "Failed to receive the traffic\n");
  1152. return -1;
  1153. }
  1154. qede_update_rx_prod(edev, rxq);
  1155. return rc;
  1156. }
  1157. static int qede_selftest_run_loopback(struct qede_dev *edev, u32 loopback_mode)
  1158. {
  1159. struct qed_link_params link_params;
  1160. struct sk_buff *skb = NULL;
  1161. int rc = 0, i;
  1162. u32 pkt_size;
  1163. u8 *packet;
  1164. if (!netif_running(edev->ndev)) {
  1165. DP_NOTICE(edev, "Interface is down\n");
  1166. return -EINVAL;
  1167. }
  1168. qede_netif_stop(edev);
  1169. /* Bring up the link in Loopback mode */
  1170. memset(&link_params, 0, sizeof(link_params));
  1171. link_params.link_up = true;
  1172. link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
  1173. link_params.loopback_mode = loopback_mode;
  1174. edev->ops->common->set_link(edev->cdev, &link_params);
  1175. /* Wait for loopback configuration to apply */
  1176. msleep_interruptible(500);
  1177. /* prepare the loopback packet */
  1178. pkt_size = edev->ndev->mtu + ETH_HLEN;
  1179. skb = netdev_alloc_skb(edev->ndev, pkt_size);
  1180. if (!skb) {
  1181. DP_INFO(edev, "Can't allocate skb\n");
  1182. rc = -ENOMEM;
  1183. goto test_loopback_exit;
  1184. }
  1185. packet = skb_put(skb, pkt_size);
  1186. ether_addr_copy(packet, edev->ndev->dev_addr);
  1187. ether_addr_copy(packet + ETH_ALEN, edev->ndev->dev_addr);
  1188. memset(packet + (2 * ETH_ALEN), 0x77, (ETH_HLEN - (2 * ETH_ALEN)));
  1189. for (i = ETH_HLEN; i < pkt_size; i++)
  1190. packet[i] = (unsigned char)(i & 0xff);
  1191. rc = qede_selftest_transmit_traffic(edev, skb);
  1192. if (rc)
  1193. goto test_loopback_exit;
  1194. rc = qede_selftest_receive_traffic(edev);
  1195. if (rc)
  1196. goto test_loopback_exit;
  1197. DP_VERBOSE(edev, NETIF_MSG_RX_STATUS, "Loopback test successful\n");
  1198. test_loopback_exit:
  1199. dev_kfree_skb(skb);
  1200. /* Bring up the link in Normal mode */
  1201. memset(&link_params, 0, sizeof(link_params));
  1202. link_params.link_up = true;
  1203. link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
  1204. link_params.loopback_mode = QED_LINK_LOOPBACK_NONE;
  1205. edev->ops->common->set_link(edev->cdev, &link_params);
  1206. /* Wait for loopback configuration to apply */
  1207. msleep_interruptible(500);
  1208. qede_netif_start(edev);
  1209. return rc;
  1210. }
  1211. static void qede_self_test(struct net_device *dev,
  1212. struct ethtool_test *etest, u64 *buf)
  1213. {
  1214. struct qede_dev *edev = netdev_priv(dev);
  1215. DP_VERBOSE(edev, QED_MSG_DEBUG,
  1216. "Self-test command parameters: offline = %d, external_lb = %d\n",
  1217. (etest->flags & ETH_TEST_FL_OFFLINE),
  1218. (etest->flags & ETH_TEST_FL_EXTERNAL_LB) >> 2);
  1219. memset(buf, 0, sizeof(u64) * QEDE_ETHTOOL_TEST_MAX);
  1220. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  1221. if (qede_selftest_run_loopback(edev,
  1222. QED_LINK_LOOPBACK_INT_PHY)) {
  1223. buf[QEDE_ETHTOOL_INT_LOOPBACK] = 1;
  1224. etest->flags |= ETH_TEST_FL_FAILED;
  1225. }
  1226. }
  1227. if (edev->ops->common->selftest->selftest_interrupt(edev->cdev)) {
  1228. buf[QEDE_ETHTOOL_INTERRUPT_TEST] = 1;
  1229. etest->flags |= ETH_TEST_FL_FAILED;
  1230. }
  1231. if (edev->ops->common->selftest->selftest_memory(edev->cdev)) {
  1232. buf[QEDE_ETHTOOL_MEMORY_TEST] = 1;
  1233. etest->flags |= ETH_TEST_FL_FAILED;
  1234. }
  1235. if (edev->ops->common->selftest->selftest_register(edev->cdev)) {
  1236. buf[QEDE_ETHTOOL_REGISTER_TEST] = 1;
  1237. etest->flags |= ETH_TEST_FL_FAILED;
  1238. }
  1239. if (edev->ops->common->selftest->selftest_clock(edev->cdev)) {
  1240. buf[QEDE_ETHTOOL_CLOCK_TEST] = 1;
  1241. etest->flags |= ETH_TEST_FL_FAILED;
  1242. }
  1243. if (edev->ops->common->selftest->selftest_nvram(edev->cdev)) {
  1244. buf[QEDE_ETHTOOL_NVRAM_TEST] = 1;
  1245. etest->flags |= ETH_TEST_FL_FAILED;
  1246. }
  1247. }
  1248. static int qede_set_tunable(struct net_device *dev,
  1249. const struct ethtool_tunable *tuna,
  1250. const void *data)
  1251. {
  1252. struct qede_dev *edev = netdev_priv(dev);
  1253. u32 val;
  1254. switch (tuna->id) {
  1255. case ETHTOOL_RX_COPYBREAK:
  1256. val = *(u32 *)data;
  1257. if (val < QEDE_MIN_PKT_LEN || val > QEDE_RX_HDR_SIZE) {
  1258. DP_VERBOSE(edev, QED_MSG_DEBUG,
  1259. "Invalid rx copy break value, range is [%u, %u]",
  1260. QEDE_MIN_PKT_LEN, QEDE_RX_HDR_SIZE);
  1261. return -EINVAL;
  1262. }
  1263. edev->rx_copybreak = *(u32 *)data;
  1264. break;
  1265. default:
  1266. return -EOPNOTSUPP;
  1267. }
  1268. return 0;
  1269. }
  1270. static int qede_get_tunable(struct net_device *dev,
  1271. const struct ethtool_tunable *tuna, void *data)
  1272. {
  1273. struct qede_dev *edev = netdev_priv(dev);
  1274. switch (tuna->id) {
  1275. case ETHTOOL_RX_COPYBREAK:
  1276. *(u32 *)data = edev->rx_copybreak;
  1277. break;
  1278. default:
  1279. return -EOPNOTSUPP;
  1280. }
  1281. return 0;
  1282. }
  1283. static const struct ethtool_ops qede_ethtool_ops = {
  1284. .get_link_ksettings = qede_get_link_ksettings,
  1285. .set_link_ksettings = qede_set_link_ksettings,
  1286. .get_drvinfo = qede_get_drvinfo,
  1287. .get_regs_len = qede_get_regs_len,
  1288. .get_regs = qede_get_regs,
  1289. .get_wol = qede_get_wol,
  1290. .set_wol = qede_set_wol,
  1291. .get_msglevel = qede_get_msglevel,
  1292. .set_msglevel = qede_set_msglevel,
  1293. .nway_reset = qede_nway_reset,
  1294. .get_link = qede_get_link,
  1295. .get_coalesce = qede_get_coalesce,
  1296. .set_coalesce = qede_set_coalesce,
  1297. .get_ringparam = qede_get_ringparam,
  1298. .set_ringparam = qede_set_ringparam,
  1299. .get_pauseparam = qede_get_pauseparam,
  1300. .set_pauseparam = qede_set_pauseparam,
  1301. .get_strings = qede_get_strings,
  1302. .set_phys_id = qede_set_phys_id,
  1303. .get_ethtool_stats = qede_get_ethtool_stats,
  1304. .get_priv_flags = qede_get_priv_flags,
  1305. .get_sset_count = qede_get_sset_count,
  1306. .get_rxnfc = qede_get_rxnfc,
  1307. .set_rxnfc = qede_set_rxnfc,
  1308. .get_rxfh_indir_size = qede_get_rxfh_indir_size,
  1309. .get_rxfh_key_size = qede_get_rxfh_key_size,
  1310. .get_rxfh = qede_get_rxfh,
  1311. .set_rxfh = qede_set_rxfh,
  1312. .get_channels = qede_get_channels,
  1313. .set_channels = qede_set_channels,
  1314. .self_test = qede_self_test,
  1315. .get_tunable = qede_get_tunable,
  1316. .set_tunable = qede_set_tunable,
  1317. };
  1318. static const struct ethtool_ops qede_vf_ethtool_ops = {
  1319. .get_link_ksettings = qede_get_link_ksettings,
  1320. .get_drvinfo = qede_get_drvinfo,
  1321. .get_msglevel = qede_get_msglevel,
  1322. .set_msglevel = qede_set_msglevel,
  1323. .get_link = qede_get_link,
  1324. .get_ringparam = qede_get_ringparam,
  1325. .set_ringparam = qede_set_ringparam,
  1326. .get_strings = qede_get_strings,
  1327. .get_ethtool_stats = qede_get_ethtool_stats,
  1328. .get_priv_flags = qede_get_priv_flags,
  1329. .get_sset_count = qede_get_sset_count,
  1330. .get_rxnfc = qede_get_rxnfc,
  1331. .set_rxnfc = qede_set_rxnfc,
  1332. .get_rxfh_indir_size = qede_get_rxfh_indir_size,
  1333. .get_rxfh_key_size = qede_get_rxfh_key_size,
  1334. .get_rxfh = qede_get_rxfh,
  1335. .set_rxfh = qede_set_rxfh,
  1336. .get_channels = qede_get_channels,
  1337. .set_channels = qede_set_channels,
  1338. .get_tunable = qede_get_tunable,
  1339. .set_tunable = qede_set_tunable,
  1340. };
  1341. void qede_set_ethtool_ops(struct net_device *dev)
  1342. {
  1343. struct qede_dev *edev = netdev_priv(dev);
  1344. if (IS_VF(edev))
  1345. dev->ethtool_ops = &qede_vf_ethtool_ops;
  1346. else
  1347. dev->ethtool_ops = &qede_ethtool_ops;
  1348. }