cxgb4_ethtool.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543
  1. /*
  2. * Copyright (C) 2013-2015 Chelsio Communications. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * The full GNU General Public License is included in this distribution in
  14. * the file called "COPYING".
  15. *
  16. */
  17. #include <linux/firmware.h>
  18. #include <linux/mdio.h>
  19. #include "cxgb4.h"
  20. #include "t4_regs.h"
  21. #include "t4fw_api.h"
  22. #include "cxgb4_cudbg.h"
  23. #define EEPROM_MAGIC 0x38E2F10C
  24. static u32 get_msglevel(struct net_device *dev)
  25. {
  26. return netdev2adap(dev)->msg_enable;
  27. }
  28. static void set_msglevel(struct net_device *dev, u32 val)
  29. {
  30. netdev2adap(dev)->msg_enable = val;
  31. }
  32. static const char stats_strings[][ETH_GSTRING_LEN] = {
  33. "tx_octets_ok ",
  34. "tx_frames_ok ",
  35. "tx_broadcast_frames ",
  36. "tx_multicast_frames ",
  37. "tx_unicast_frames ",
  38. "tx_error_frames ",
  39. "tx_frames_64 ",
  40. "tx_frames_65_to_127 ",
  41. "tx_frames_128_to_255 ",
  42. "tx_frames_256_to_511 ",
  43. "tx_frames_512_to_1023 ",
  44. "tx_frames_1024_to_1518 ",
  45. "tx_frames_1519_to_max ",
  46. "tx_frames_dropped ",
  47. "tx_pause_frames ",
  48. "tx_ppp0_frames ",
  49. "tx_ppp1_frames ",
  50. "tx_ppp2_frames ",
  51. "tx_ppp3_frames ",
  52. "tx_ppp4_frames ",
  53. "tx_ppp5_frames ",
  54. "tx_ppp6_frames ",
  55. "tx_ppp7_frames ",
  56. "rx_octets_ok ",
  57. "rx_frames_ok ",
  58. "rx_broadcast_frames ",
  59. "rx_multicast_frames ",
  60. "rx_unicast_frames ",
  61. "rx_frames_too_long ",
  62. "rx_jabber_errors ",
  63. "rx_fcs_errors ",
  64. "rx_length_errors ",
  65. "rx_symbol_errors ",
  66. "rx_runt_frames ",
  67. "rx_frames_64 ",
  68. "rx_frames_65_to_127 ",
  69. "rx_frames_128_to_255 ",
  70. "rx_frames_256_to_511 ",
  71. "rx_frames_512_to_1023 ",
  72. "rx_frames_1024_to_1518 ",
  73. "rx_frames_1519_to_max ",
  74. "rx_pause_frames ",
  75. "rx_ppp0_frames ",
  76. "rx_ppp1_frames ",
  77. "rx_ppp2_frames ",
  78. "rx_ppp3_frames ",
  79. "rx_ppp4_frames ",
  80. "rx_ppp5_frames ",
  81. "rx_ppp6_frames ",
  82. "rx_ppp7_frames ",
  83. "rx_bg0_frames_dropped ",
  84. "rx_bg1_frames_dropped ",
  85. "rx_bg2_frames_dropped ",
  86. "rx_bg3_frames_dropped ",
  87. "rx_bg0_frames_trunc ",
  88. "rx_bg1_frames_trunc ",
  89. "rx_bg2_frames_trunc ",
  90. "rx_bg3_frames_trunc ",
  91. "tso ",
  92. "tx_csum_offload ",
  93. "rx_csum_good ",
  94. "vlan_extractions ",
  95. "vlan_insertions ",
  96. "gro_packets ",
  97. "gro_merged ",
  98. };
  99. static char adapter_stats_strings[][ETH_GSTRING_LEN] = {
  100. "db_drop ",
  101. "db_full ",
  102. "db_empty ",
  103. "tcp_ipv4_out_rsts ",
  104. "tcp_ipv4_in_segs ",
  105. "tcp_ipv4_out_segs ",
  106. "tcp_ipv4_retrans_segs ",
  107. "tcp_ipv6_out_rsts ",
  108. "tcp_ipv6_in_segs ",
  109. "tcp_ipv6_out_segs ",
  110. "tcp_ipv6_retrans_segs ",
  111. "usm_ddp_frames ",
  112. "usm_ddp_octets ",
  113. "usm_ddp_drops ",
  114. "rdma_no_rqe_mod_defer ",
  115. "rdma_no_rqe_pkt_defer ",
  116. "tp_err_ofld_no_neigh ",
  117. "tp_err_ofld_cong_defer ",
  118. "write_coal_success ",
  119. "write_coal_fail ",
  120. };
  121. static char channel_stats_strings[][ETH_GSTRING_LEN] = {
  122. "--------Channel--------- ",
  123. "tp_cpl_requests ",
  124. "tp_cpl_responses ",
  125. "tp_mac_in_errs ",
  126. "tp_hdr_in_errs ",
  127. "tp_tcp_in_errs ",
  128. "tp_tcp6_in_errs ",
  129. "tp_tnl_cong_drops ",
  130. "tp_tnl_tx_drops ",
  131. "tp_ofld_vlan_drops ",
  132. "tp_ofld_chan_drops ",
  133. "fcoe_octets_ddp ",
  134. "fcoe_frames_ddp ",
  135. "fcoe_frames_drop ",
  136. };
  137. static char loopback_stats_strings[][ETH_GSTRING_LEN] = {
  138. "-------Loopback----------- ",
  139. "octets_ok ",
  140. "frames_ok ",
  141. "bcast_frames ",
  142. "mcast_frames ",
  143. "ucast_frames ",
  144. "error_frames ",
  145. "frames_64 ",
  146. "frames_65_to_127 ",
  147. "frames_128_to_255 ",
  148. "frames_256_to_511 ",
  149. "frames_512_to_1023 ",
  150. "frames_1024_to_1518 ",
  151. "frames_1519_to_max ",
  152. "frames_dropped ",
  153. "bg0_frames_dropped ",
  154. "bg1_frames_dropped ",
  155. "bg2_frames_dropped ",
  156. "bg3_frames_dropped ",
  157. "bg0_frames_trunc ",
  158. "bg1_frames_trunc ",
  159. "bg2_frames_trunc ",
  160. "bg3_frames_trunc ",
  161. };
  162. static int get_sset_count(struct net_device *dev, int sset)
  163. {
  164. switch (sset) {
  165. case ETH_SS_STATS:
  166. return ARRAY_SIZE(stats_strings) +
  167. ARRAY_SIZE(adapter_stats_strings) +
  168. ARRAY_SIZE(channel_stats_strings) +
  169. ARRAY_SIZE(loopback_stats_strings);
  170. default:
  171. return -EOPNOTSUPP;
  172. }
  173. }
  174. static int get_regs_len(struct net_device *dev)
  175. {
  176. struct adapter *adap = netdev2adap(dev);
  177. return t4_get_regs_len(adap);
  178. }
  179. static int get_eeprom_len(struct net_device *dev)
  180. {
  181. return EEPROMSIZE;
  182. }
  183. static void get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  184. {
  185. struct adapter *adapter = netdev2adap(dev);
  186. u32 exprom_vers;
  187. strlcpy(info->driver, cxgb4_driver_name, sizeof(info->driver));
  188. strlcpy(info->version, cxgb4_driver_version,
  189. sizeof(info->version));
  190. strlcpy(info->bus_info, pci_name(adapter->pdev),
  191. sizeof(info->bus_info));
  192. info->regdump_len = get_regs_len(dev);
  193. if (!adapter->params.fw_vers)
  194. strcpy(info->fw_version, "N/A");
  195. else
  196. snprintf(info->fw_version, sizeof(info->fw_version),
  197. "%u.%u.%u.%u, TP %u.%u.%u.%u",
  198. FW_HDR_FW_VER_MAJOR_G(adapter->params.fw_vers),
  199. FW_HDR_FW_VER_MINOR_G(adapter->params.fw_vers),
  200. FW_HDR_FW_VER_MICRO_G(adapter->params.fw_vers),
  201. FW_HDR_FW_VER_BUILD_G(adapter->params.fw_vers),
  202. FW_HDR_FW_VER_MAJOR_G(adapter->params.tp_vers),
  203. FW_HDR_FW_VER_MINOR_G(adapter->params.tp_vers),
  204. FW_HDR_FW_VER_MICRO_G(adapter->params.tp_vers),
  205. FW_HDR_FW_VER_BUILD_G(adapter->params.tp_vers));
  206. if (!t4_get_exprom_version(adapter, &exprom_vers))
  207. snprintf(info->erom_version, sizeof(info->erom_version),
  208. "%u.%u.%u.%u",
  209. FW_HDR_FW_VER_MAJOR_G(exprom_vers),
  210. FW_HDR_FW_VER_MINOR_G(exprom_vers),
  211. FW_HDR_FW_VER_MICRO_G(exprom_vers),
  212. FW_HDR_FW_VER_BUILD_G(exprom_vers));
  213. }
  214. static void get_strings(struct net_device *dev, u32 stringset, u8 *data)
  215. {
  216. if (stringset == ETH_SS_STATS) {
  217. memcpy(data, stats_strings, sizeof(stats_strings));
  218. data += sizeof(stats_strings);
  219. memcpy(data, adapter_stats_strings,
  220. sizeof(adapter_stats_strings));
  221. data += sizeof(adapter_stats_strings);
  222. memcpy(data, channel_stats_strings,
  223. sizeof(channel_stats_strings));
  224. data += sizeof(channel_stats_strings);
  225. memcpy(data, loopback_stats_strings,
  226. sizeof(loopback_stats_strings));
  227. }
  228. }
  229. /* port stats maintained per queue of the port. They should be in the same
  230. * order as in stats_strings above.
  231. */
  232. struct queue_port_stats {
  233. u64 tso;
  234. u64 tx_csum;
  235. u64 rx_csum;
  236. u64 vlan_ex;
  237. u64 vlan_ins;
  238. u64 gro_pkts;
  239. u64 gro_merged;
  240. };
  241. struct adapter_stats {
  242. u64 db_drop;
  243. u64 db_full;
  244. u64 db_empty;
  245. u64 tcp_v4_out_rsts;
  246. u64 tcp_v4_in_segs;
  247. u64 tcp_v4_out_segs;
  248. u64 tcp_v4_retrans_segs;
  249. u64 tcp_v6_out_rsts;
  250. u64 tcp_v6_in_segs;
  251. u64 tcp_v6_out_segs;
  252. u64 tcp_v6_retrans_segs;
  253. u64 frames;
  254. u64 octets;
  255. u64 drops;
  256. u64 rqe_dfr_mod;
  257. u64 rqe_dfr_pkt;
  258. u64 ofld_no_neigh;
  259. u64 ofld_cong_defer;
  260. u64 wc_success;
  261. u64 wc_fail;
  262. };
  263. struct channel_stats {
  264. u64 cpl_req;
  265. u64 cpl_rsp;
  266. u64 mac_in_errs;
  267. u64 hdr_in_errs;
  268. u64 tcp_in_errs;
  269. u64 tcp6_in_errs;
  270. u64 tnl_cong_drops;
  271. u64 tnl_tx_drops;
  272. u64 ofld_vlan_drops;
  273. u64 ofld_chan_drops;
  274. u64 octets_ddp;
  275. u64 frames_ddp;
  276. u64 frames_drop;
  277. };
  278. static void collect_sge_port_stats(const struct adapter *adap,
  279. const struct port_info *p,
  280. struct queue_port_stats *s)
  281. {
  282. int i;
  283. const struct sge_eth_txq *tx = &adap->sge.ethtxq[p->first_qset];
  284. const struct sge_eth_rxq *rx = &adap->sge.ethrxq[p->first_qset];
  285. memset(s, 0, sizeof(*s));
  286. for (i = 0; i < p->nqsets; i++, rx++, tx++) {
  287. s->tso += tx->tso;
  288. s->tx_csum += tx->tx_cso;
  289. s->rx_csum += rx->stats.rx_cso;
  290. s->vlan_ex += rx->stats.vlan_ex;
  291. s->vlan_ins += tx->vlan_ins;
  292. s->gro_pkts += rx->stats.lro_pkts;
  293. s->gro_merged += rx->stats.lro_merged;
  294. }
  295. }
  296. static void collect_adapter_stats(struct adapter *adap, struct adapter_stats *s)
  297. {
  298. struct tp_tcp_stats v4, v6;
  299. struct tp_rdma_stats rdma_stats;
  300. struct tp_err_stats err_stats;
  301. struct tp_usm_stats usm_stats;
  302. u64 val1, val2;
  303. memset(s, 0, sizeof(*s));
  304. spin_lock(&adap->stats_lock);
  305. t4_tp_get_tcp_stats(adap, &v4, &v6, false);
  306. t4_tp_get_rdma_stats(adap, &rdma_stats, false);
  307. t4_get_usm_stats(adap, &usm_stats, false);
  308. t4_tp_get_err_stats(adap, &err_stats, false);
  309. spin_unlock(&adap->stats_lock);
  310. s->db_drop = adap->db_stats.db_drop;
  311. s->db_full = adap->db_stats.db_full;
  312. s->db_empty = adap->db_stats.db_empty;
  313. s->tcp_v4_out_rsts = v4.tcp_out_rsts;
  314. s->tcp_v4_in_segs = v4.tcp_in_segs;
  315. s->tcp_v4_out_segs = v4.tcp_out_segs;
  316. s->tcp_v4_retrans_segs = v4.tcp_retrans_segs;
  317. s->tcp_v6_out_rsts = v6.tcp_out_rsts;
  318. s->tcp_v6_in_segs = v6.tcp_in_segs;
  319. s->tcp_v6_out_segs = v6.tcp_out_segs;
  320. s->tcp_v6_retrans_segs = v6.tcp_retrans_segs;
  321. if (is_offload(adap)) {
  322. s->frames = usm_stats.frames;
  323. s->octets = usm_stats.octets;
  324. s->drops = usm_stats.drops;
  325. s->rqe_dfr_mod = rdma_stats.rqe_dfr_mod;
  326. s->rqe_dfr_pkt = rdma_stats.rqe_dfr_pkt;
  327. }
  328. s->ofld_no_neigh = err_stats.ofld_no_neigh;
  329. s->ofld_cong_defer = err_stats.ofld_cong_defer;
  330. if (!is_t4(adap->params.chip)) {
  331. int v;
  332. v = t4_read_reg(adap, SGE_STAT_CFG_A);
  333. if (STATSOURCE_T5_G(v) == 7) {
  334. val2 = t4_read_reg(adap, SGE_STAT_MATCH_A);
  335. val1 = t4_read_reg(adap, SGE_STAT_TOTAL_A);
  336. s->wc_success = val1 - val2;
  337. s->wc_fail = val2;
  338. }
  339. }
  340. }
  341. static void collect_channel_stats(struct adapter *adap, struct channel_stats *s,
  342. u8 i)
  343. {
  344. struct tp_cpl_stats cpl_stats;
  345. struct tp_err_stats err_stats;
  346. struct tp_fcoe_stats fcoe_stats;
  347. memset(s, 0, sizeof(*s));
  348. spin_lock(&adap->stats_lock);
  349. t4_tp_get_cpl_stats(adap, &cpl_stats, false);
  350. t4_tp_get_err_stats(adap, &err_stats, false);
  351. t4_get_fcoe_stats(adap, i, &fcoe_stats, false);
  352. spin_unlock(&adap->stats_lock);
  353. s->cpl_req = cpl_stats.req[i];
  354. s->cpl_rsp = cpl_stats.rsp[i];
  355. s->mac_in_errs = err_stats.mac_in_errs[i];
  356. s->hdr_in_errs = err_stats.hdr_in_errs[i];
  357. s->tcp_in_errs = err_stats.tcp_in_errs[i];
  358. s->tcp6_in_errs = err_stats.tcp6_in_errs[i];
  359. s->tnl_cong_drops = err_stats.tnl_cong_drops[i];
  360. s->tnl_tx_drops = err_stats.tnl_tx_drops[i];
  361. s->ofld_vlan_drops = err_stats.ofld_vlan_drops[i];
  362. s->ofld_chan_drops = err_stats.ofld_chan_drops[i];
  363. s->octets_ddp = fcoe_stats.octets_ddp;
  364. s->frames_ddp = fcoe_stats.frames_ddp;
  365. s->frames_drop = fcoe_stats.frames_drop;
  366. }
  367. static void get_stats(struct net_device *dev, struct ethtool_stats *stats,
  368. u64 *data)
  369. {
  370. struct port_info *pi = netdev_priv(dev);
  371. struct adapter *adapter = pi->adapter;
  372. struct lb_port_stats s;
  373. int i;
  374. u64 *p0;
  375. t4_get_port_stats_offset(adapter, pi->tx_chan,
  376. (struct port_stats *)data,
  377. &pi->stats_base);
  378. data += sizeof(struct port_stats) / sizeof(u64);
  379. collect_sge_port_stats(adapter, pi, (struct queue_port_stats *)data);
  380. data += sizeof(struct queue_port_stats) / sizeof(u64);
  381. collect_adapter_stats(adapter, (struct adapter_stats *)data);
  382. data += sizeof(struct adapter_stats) / sizeof(u64);
  383. *data++ = (u64)pi->port_id;
  384. collect_channel_stats(adapter, (struct channel_stats *)data,
  385. pi->port_id);
  386. data += sizeof(struct channel_stats) / sizeof(u64);
  387. *data++ = (u64)pi->port_id;
  388. memset(&s, 0, sizeof(s));
  389. t4_get_lb_stats(adapter, pi->port_id, &s);
  390. p0 = &s.octets;
  391. for (i = 0; i < ARRAY_SIZE(loopback_stats_strings) - 1; i++)
  392. *data++ = (unsigned long long)*p0++;
  393. }
  394. static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
  395. void *buf)
  396. {
  397. struct adapter *adap = netdev2adap(dev);
  398. size_t buf_size;
  399. buf_size = t4_get_regs_len(adap);
  400. regs->version = mk_adap_vers(adap);
  401. t4_get_regs(adap, buf, buf_size);
  402. }
  403. static int restart_autoneg(struct net_device *dev)
  404. {
  405. struct port_info *p = netdev_priv(dev);
  406. if (!netif_running(dev))
  407. return -EAGAIN;
  408. if (p->link_cfg.autoneg != AUTONEG_ENABLE)
  409. return -EINVAL;
  410. t4_restart_aneg(p->adapter, p->adapter->pf, p->tx_chan);
  411. return 0;
  412. }
  413. static int identify_port(struct net_device *dev,
  414. enum ethtool_phys_id_state state)
  415. {
  416. unsigned int val;
  417. struct adapter *adap = netdev2adap(dev);
  418. if (state == ETHTOOL_ID_ACTIVE)
  419. val = 0xffff;
  420. else if (state == ETHTOOL_ID_INACTIVE)
  421. val = 0;
  422. else
  423. return -EINVAL;
  424. return t4_identify_port(adap, adap->pf, netdev2pinfo(dev)->viid, val);
  425. }
  426. /**
  427. * from_fw_port_mod_type - translate Firmware Port/Module type to Ethtool
  428. * @port_type: Firmware Port Type
  429. * @mod_type: Firmware Module Type
  430. *
  431. * Translate Firmware Port/Module type to Ethtool Port Type.
  432. */
  433. static int from_fw_port_mod_type(enum fw_port_type port_type,
  434. enum fw_port_module_type mod_type)
  435. {
  436. if (port_type == FW_PORT_TYPE_BT_SGMII ||
  437. port_type == FW_PORT_TYPE_BT_XFI ||
  438. port_type == FW_PORT_TYPE_BT_XAUI) {
  439. return PORT_TP;
  440. } else if (port_type == FW_PORT_TYPE_FIBER_XFI ||
  441. port_type == FW_PORT_TYPE_FIBER_XAUI) {
  442. return PORT_FIBRE;
  443. } else if (port_type == FW_PORT_TYPE_SFP ||
  444. port_type == FW_PORT_TYPE_QSFP_10G ||
  445. port_type == FW_PORT_TYPE_QSA ||
  446. port_type == FW_PORT_TYPE_QSFP ||
  447. port_type == FW_PORT_TYPE_CR4_QSFP ||
  448. port_type == FW_PORT_TYPE_CR_QSFP ||
  449. port_type == FW_PORT_TYPE_CR2_QSFP ||
  450. port_type == FW_PORT_TYPE_SFP28) {
  451. if (mod_type == FW_PORT_MOD_TYPE_LR ||
  452. mod_type == FW_PORT_MOD_TYPE_SR ||
  453. mod_type == FW_PORT_MOD_TYPE_ER ||
  454. mod_type == FW_PORT_MOD_TYPE_LRM)
  455. return PORT_FIBRE;
  456. else if (mod_type == FW_PORT_MOD_TYPE_TWINAX_PASSIVE ||
  457. mod_type == FW_PORT_MOD_TYPE_TWINAX_ACTIVE)
  458. return PORT_DA;
  459. else
  460. return PORT_OTHER;
  461. } else if (port_type == FW_PORT_TYPE_KR4_100G ||
  462. port_type == FW_PORT_TYPE_KR_SFP28 ||
  463. port_type == FW_PORT_TYPE_KR_XLAUI) {
  464. return PORT_NONE;
  465. }
  466. return PORT_OTHER;
  467. }
  468. /**
  469. * speed_to_fw_caps - translate Port Speed to Firmware Port Capabilities
  470. * @speed: speed in Kb/s
  471. *
  472. * Translates a specific Port Speed into a Firmware Port Capabilities
  473. * value.
  474. */
  475. static unsigned int speed_to_fw_caps(int speed)
  476. {
  477. if (speed == 100)
  478. return FW_PORT_CAP32_SPEED_100M;
  479. if (speed == 1000)
  480. return FW_PORT_CAP32_SPEED_1G;
  481. if (speed == 10000)
  482. return FW_PORT_CAP32_SPEED_10G;
  483. if (speed == 25000)
  484. return FW_PORT_CAP32_SPEED_25G;
  485. if (speed == 40000)
  486. return FW_PORT_CAP32_SPEED_40G;
  487. if (speed == 50000)
  488. return FW_PORT_CAP32_SPEED_50G;
  489. if (speed == 100000)
  490. return FW_PORT_CAP32_SPEED_100G;
  491. if (speed == 200000)
  492. return FW_PORT_CAP32_SPEED_200G;
  493. if (speed == 400000)
  494. return FW_PORT_CAP32_SPEED_400G;
  495. return 0;
  496. }
  497. /**
  498. * fw_caps_to_lmm - translate Firmware to ethtool Link Mode Mask
  499. * @port_type: Firmware Port Type
  500. * @fw_caps: Firmware Port Capabilities
  501. * @link_mode_mask: ethtool Link Mode Mask
  502. *
  503. * Translate a Firmware Port Capabilities specification to an ethtool
  504. * Link Mode Mask.
  505. */
  506. static void fw_caps_to_lmm(enum fw_port_type port_type,
  507. unsigned int fw_caps,
  508. unsigned long *link_mode_mask)
  509. {
  510. #define SET_LMM(__lmm_name) \
  511. __set_bit(ETHTOOL_LINK_MODE_ ## __lmm_name ## _BIT, \
  512. link_mode_mask)
  513. #define FW_CAPS_TO_LMM(__fw_name, __lmm_name) \
  514. do { \
  515. if (fw_caps & FW_PORT_CAP32_ ## __fw_name) \
  516. SET_LMM(__lmm_name); \
  517. } while (0)
  518. switch (port_type) {
  519. case FW_PORT_TYPE_BT_SGMII:
  520. case FW_PORT_TYPE_BT_XFI:
  521. case FW_PORT_TYPE_BT_XAUI:
  522. SET_LMM(TP);
  523. FW_CAPS_TO_LMM(SPEED_100M, 100baseT_Full);
  524. FW_CAPS_TO_LMM(SPEED_1G, 1000baseT_Full);
  525. FW_CAPS_TO_LMM(SPEED_10G, 10000baseT_Full);
  526. break;
  527. case FW_PORT_TYPE_KX4:
  528. case FW_PORT_TYPE_KX:
  529. SET_LMM(Backplane);
  530. FW_CAPS_TO_LMM(SPEED_1G, 1000baseKX_Full);
  531. FW_CAPS_TO_LMM(SPEED_10G, 10000baseKX4_Full);
  532. break;
  533. case FW_PORT_TYPE_KR:
  534. SET_LMM(Backplane);
  535. FW_CAPS_TO_LMM(SPEED_10G, 10000baseKR_Full);
  536. break;
  537. case FW_PORT_TYPE_BP_AP:
  538. SET_LMM(Backplane);
  539. FW_CAPS_TO_LMM(SPEED_1G, 1000baseKX_Full);
  540. FW_CAPS_TO_LMM(SPEED_10G, 10000baseR_FEC);
  541. FW_CAPS_TO_LMM(SPEED_10G, 10000baseKR_Full);
  542. break;
  543. case FW_PORT_TYPE_BP4_AP:
  544. SET_LMM(Backplane);
  545. FW_CAPS_TO_LMM(SPEED_1G, 1000baseKX_Full);
  546. FW_CAPS_TO_LMM(SPEED_10G, 10000baseR_FEC);
  547. FW_CAPS_TO_LMM(SPEED_10G, 10000baseKR_Full);
  548. FW_CAPS_TO_LMM(SPEED_10G, 10000baseKX4_Full);
  549. break;
  550. case FW_PORT_TYPE_FIBER_XFI:
  551. case FW_PORT_TYPE_FIBER_XAUI:
  552. case FW_PORT_TYPE_SFP:
  553. case FW_PORT_TYPE_QSFP_10G:
  554. case FW_PORT_TYPE_QSA:
  555. SET_LMM(FIBRE);
  556. FW_CAPS_TO_LMM(SPEED_1G, 1000baseT_Full);
  557. FW_CAPS_TO_LMM(SPEED_10G, 10000baseT_Full);
  558. break;
  559. case FW_PORT_TYPE_BP40_BA:
  560. case FW_PORT_TYPE_QSFP:
  561. SET_LMM(FIBRE);
  562. FW_CAPS_TO_LMM(SPEED_1G, 1000baseT_Full);
  563. FW_CAPS_TO_LMM(SPEED_10G, 10000baseT_Full);
  564. FW_CAPS_TO_LMM(SPEED_40G, 40000baseSR4_Full);
  565. break;
  566. case FW_PORT_TYPE_CR_QSFP:
  567. case FW_PORT_TYPE_SFP28:
  568. SET_LMM(FIBRE);
  569. FW_CAPS_TO_LMM(SPEED_1G, 1000baseT_Full);
  570. FW_CAPS_TO_LMM(SPEED_10G, 10000baseT_Full);
  571. FW_CAPS_TO_LMM(SPEED_25G, 25000baseCR_Full);
  572. break;
  573. case FW_PORT_TYPE_KR_SFP28:
  574. SET_LMM(Backplane);
  575. FW_CAPS_TO_LMM(SPEED_1G, 1000baseT_Full);
  576. FW_CAPS_TO_LMM(SPEED_10G, 10000baseKR_Full);
  577. FW_CAPS_TO_LMM(SPEED_25G, 25000baseKR_Full);
  578. break;
  579. case FW_PORT_TYPE_KR_XLAUI:
  580. SET_LMM(Backplane);
  581. FW_CAPS_TO_LMM(SPEED_1G, 1000baseKX_Full);
  582. FW_CAPS_TO_LMM(SPEED_10G, 10000baseKR_Full);
  583. FW_CAPS_TO_LMM(SPEED_40G, 40000baseKR4_Full);
  584. break;
  585. case FW_PORT_TYPE_CR2_QSFP:
  586. SET_LMM(FIBRE);
  587. FW_CAPS_TO_LMM(SPEED_50G, 50000baseSR2_Full);
  588. break;
  589. case FW_PORT_TYPE_KR4_100G:
  590. case FW_PORT_TYPE_CR4_QSFP:
  591. SET_LMM(FIBRE);
  592. FW_CAPS_TO_LMM(SPEED_1G, 1000baseT_Full);
  593. FW_CAPS_TO_LMM(SPEED_10G, 10000baseSR_Full);
  594. FW_CAPS_TO_LMM(SPEED_40G, 40000baseSR4_Full);
  595. FW_CAPS_TO_LMM(SPEED_25G, 25000baseCR_Full);
  596. FW_CAPS_TO_LMM(SPEED_50G, 50000baseCR2_Full);
  597. FW_CAPS_TO_LMM(SPEED_100G, 100000baseCR4_Full);
  598. break;
  599. default:
  600. break;
  601. }
  602. FW_CAPS_TO_LMM(ANEG, Autoneg);
  603. FW_CAPS_TO_LMM(802_3_PAUSE, Pause);
  604. FW_CAPS_TO_LMM(802_3_ASM_DIR, Asym_Pause);
  605. #undef FW_CAPS_TO_LMM
  606. #undef SET_LMM
  607. }
  608. /**
  609. * lmm_to_fw_caps - translate ethtool Link Mode Mask to Firmware
  610. * capabilities
  611. * @et_lmm: ethtool Link Mode Mask
  612. *
  613. * Translate ethtool Link Mode Mask into a Firmware Port capabilities
  614. * value.
  615. */
  616. static unsigned int lmm_to_fw_caps(const unsigned long *link_mode_mask)
  617. {
  618. unsigned int fw_caps = 0;
  619. #define LMM_TO_FW_CAPS(__lmm_name, __fw_name) \
  620. do { \
  621. if (test_bit(ETHTOOL_LINK_MODE_ ## __lmm_name ## _BIT, \
  622. link_mode_mask)) \
  623. fw_caps |= FW_PORT_CAP32_ ## __fw_name; \
  624. } while (0)
  625. LMM_TO_FW_CAPS(100baseT_Full, SPEED_100M);
  626. LMM_TO_FW_CAPS(1000baseT_Full, SPEED_1G);
  627. LMM_TO_FW_CAPS(10000baseT_Full, SPEED_10G);
  628. LMM_TO_FW_CAPS(40000baseSR4_Full, SPEED_40G);
  629. LMM_TO_FW_CAPS(25000baseCR_Full, SPEED_25G);
  630. LMM_TO_FW_CAPS(50000baseCR2_Full, SPEED_50G);
  631. LMM_TO_FW_CAPS(100000baseCR4_Full, SPEED_100G);
  632. #undef LMM_TO_FW_CAPS
  633. return fw_caps;
  634. }
  635. static int get_link_ksettings(struct net_device *dev,
  636. struct ethtool_link_ksettings *link_ksettings)
  637. {
  638. struct port_info *pi = netdev_priv(dev);
  639. struct ethtool_link_settings *base = &link_ksettings->base;
  640. /* For the nonce, the Firmware doesn't send up Port State changes
  641. * when the Virtual Interface attached to the Port is down. So
  642. * if it's down, let's grab any changes.
  643. */
  644. if (!netif_running(dev))
  645. (void)t4_update_port_info(pi);
  646. ethtool_link_ksettings_zero_link_mode(link_ksettings, supported);
  647. ethtool_link_ksettings_zero_link_mode(link_ksettings, advertising);
  648. ethtool_link_ksettings_zero_link_mode(link_ksettings, lp_advertising);
  649. base->port = from_fw_port_mod_type(pi->port_type, pi->mod_type);
  650. if (pi->mdio_addr >= 0) {
  651. base->phy_address = pi->mdio_addr;
  652. base->mdio_support = (pi->port_type == FW_PORT_TYPE_BT_SGMII
  653. ? ETH_MDIO_SUPPORTS_C22
  654. : ETH_MDIO_SUPPORTS_C45);
  655. } else {
  656. base->phy_address = 255;
  657. base->mdio_support = 0;
  658. }
  659. fw_caps_to_lmm(pi->port_type, pi->link_cfg.pcaps,
  660. link_ksettings->link_modes.supported);
  661. fw_caps_to_lmm(pi->port_type, pi->link_cfg.acaps,
  662. link_ksettings->link_modes.advertising);
  663. fw_caps_to_lmm(pi->port_type, pi->link_cfg.lpacaps,
  664. link_ksettings->link_modes.lp_advertising);
  665. if (netif_carrier_ok(dev)) {
  666. base->speed = pi->link_cfg.speed;
  667. base->duplex = DUPLEX_FULL;
  668. } else {
  669. base->speed = SPEED_UNKNOWN;
  670. base->duplex = DUPLEX_UNKNOWN;
  671. }
  672. if (pi->link_cfg.fc & PAUSE_RX) {
  673. if (pi->link_cfg.fc & PAUSE_TX) {
  674. ethtool_link_ksettings_add_link_mode(link_ksettings,
  675. advertising,
  676. Pause);
  677. } else {
  678. ethtool_link_ksettings_add_link_mode(link_ksettings,
  679. advertising,
  680. Asym_Pause);
  681. }
  682. } else if (pi->link_cfg.fc & PAUSE_TX) {
  683. ethtool_link_ksettings_add_link_mode(link_ksettings,
  684. advertising,
  685. Asym_Pause);
  686. }
  687. base->autoneg = pi->link_cfg.autoneg;
  688. if (pi->link_cfg.pcaps & FW_PORT_CAP32_ANEG)
  689. ethtool_link_ksettings_add_link_mode(link_ksettings,
  690. supported, Autoneg);
  691. if (pi->link_cfg.autoneg)
  692. ethtool_link_ksettings_add_link_mode(link_ksettings,
  693. advertising, Autoneg);
  694. return 0;
  695. }
  696. static int set_link_ksettings(struct net_device *dev,
  697. const struct ethtool_link_ksettings *link_ksettings)
  698. {
  699. struct port_info *pi = netdev_priv(dev);
  700. struct link_config *lc = &pi->link_cfg;
  701. const struct ethtool_link_settings *base = &link_ksettings->base;
  702. struct link_config old_lc;
  703. unsigned int fw_caps;
  704. int ret = 0;
  705. /* only full-duplex supported */
  706. if (base->duplex != DUPLEX_FULL)
  707. return -EINVAL;
  708. old_lc = *lc;
  709. if (!(lc->pcaps & FW_PORT_CAP32_ANEG) ||
  710. base->autoneg == AUTONEG_DISABLE) {
  711. fw_caps = speed_to_fw_caps(base->speed);
  712. /* Must only specify a single speed which must be supported
  713. * as part of the Physical Port Capabilities.
  714. */
  715. if ((fw_caps & (fw_caps - 1)) != 0 ||
  716. !(lc->pcaps & fw_caps))
  717. return -EINVAL;
  718. lc->speed_caps = fw_caps;
  719. lc->acaps = fw_caps;
  720. } else {
  721. fw_caps =
  722. lmm_to_fw_caps(link_ksettings->link_modes.advertising);
  723. if (!(lc->pcaps & fw_caps))
  724. return -EINVAL;
  725. lc->speed_caps = 0;
  726. lc->acaps = fw_caps | FW_PORT_CAP32_ANEG;
  727. }
  728. lc->autoneg = base->autoneg;
  729. /* If the firmware rejects the Link Configuration request, back out
  730. * the changes and report the error.
  731. */
  732. ret = t4_link_l1cfg(pi->adapter, pi->adapter->mbox, pi->tx_chan, lc);
  733. if (ret)
  734. *lc = old_lc;
  735. return ret;
  736. }
  737. /* Translate the Firmware FEC value into the ethtool value. */
  738. static inline unsigned int fwcap_to_eth_fec(unsigned int fw_fec)
  739. {
  740. unsigned int eth_fec = 0;
  741. if (fw_fec & FW_PORT_CAP32_FEC_RS)
  742. eth_fec |= ETHTOOL_FEC_RS;
  743. if (fw_fec & FW_PORT_CAP32_FEC_BASER_RS)
  744. eth_fec |= ETHTOOL_FEC_BASER;
  745. /* if nothing is set, then FEC is off */
  746. if (!eth_fec)
  747. eth_fec = ETHTOOL_FEC_OFF;
  748. return eth_fec;
  749. }
  750. /* Translate Common Code FEC value into ethtool value. */
  751. static inline unsigned int cc_to_eth_fec(unsigned int cc_fec)
  752. {
  753. unsigned int eth_fec = 0;
  754. if (cc_fec & FEC_AUTO)
  755. eth_fec |= ETHTOOL_FEC_AUTO;
  756. if (cc_fec & FEC_RS)
  757. eth_fec |= ETHTOOL_FEC_RS;
  758. if (cc_fec & FEC_BASER_RS)
  759. eth_fec |= ETHTOOL_FEC_BASER;
  760. /* if nothing is set, then FEC is off */
  761. if (!eth_fec)
  762. eth_fec = ETHTOOL_FEC_OFF;
  763. return eth_fec;
  764. }
  765. /* Translate ethtool FEC value into Common Code value. */
  766. static inline unsigned int eth_to_cc_fec(unsigned int eth_fec)
  767. {
  768. unsigned int cc_fec = 0;
  769. if (eth_fec & ETHTOOL_FEC_OFF)
  770. return cc_fec;
  771. if (eth_fec & ETHTOOL_FEC_AUTO)
  772. cc_fec |= FEC_AUTO;
  773. if (eth_fec & ETHTOOL_FEC_RS)
  774. cc_fec |= FEC_RS;
  775. if (eth_fec & ETHTOOL_FEC_BASER)
  776. cc_fec |= FEC_BASER_RS;
  777. return cc_fec;
  778. }
  779. static int get_fecparam(struct net_device *dev, struct ethtool_fecparam *fec)
  780. {
  781. const struct port_info *pi = netdev_priv(dev);
  782. const struct link_config *lc = &pi->link_cfg;
  783. /* Translate the Firmware FEC Support into the ethtool value. We
  784. * always support IEEE 802.3 "automatic" selection of Link FEC type if
  785. * any FEC is supported.
  786. */
  787. fec->fec = fwcap_to_eth_fec(lc->pcaps);
  788. if (fec->fec != ETHTOOL_FEC_OFF)
  789. fec->fec |= ETHTOOL_FEC_AUTO;
  790. /* Translate the current internal FEC parameters into the
  791. * ethtool values.
  792. */
  793. fec->active_fec = cc_to_eth_fec(lc->fec);
  794. return 0;
  795. }
  796. static int set_fecparam(struct net_device *dev, struct ethtool_fecparam *fec)
  797. {
  798. struct port_info *pi = netdev_priv(dev);
  799. struct link_config *lc = &pi->link_cfg;
  800. struct link_config old_lc;
  801. int ret;
  802. /* Save old Link Configuration in case the L1 Configure below
  803. * fails.
  804. */
  805. old_lc = *lc;
  806. /* Try to perform the L1 Configure and return the result of that
  807. * effort. If it fails, revert the attempted change.
  808. */
  809. lc->requested_fec = eth_to_cc_fec(fec->fec);
  810. ret = t4_link_l1cfg(pi->adapter, pi->adapter->mbox,
  811. pi->tx_chan, lc);
  812. if (ret)
  813. *lc = old_lc;
  814. return ret;
  815. }
  816. static void get_pauseparam(struct net_device *dev,
  817. struct ethtool_pauseparam *epause)
  818. {
  819. struct port_info *p = netdev_priv(dev);
  820. epause->autoneg = (p->link_cfg.requested_fc & PAUSE_AUTONEG) != 0;
  821. epause->rx_pause = (p->link_cfg.fc & PAUSE_RX) != 0;
  822. epause->tx_pause = (p->link_cfg.fc & PAUSE_TX) != 0;
  823. }
  824. static int set_pauseparam(struct net_device *dev,
  825. struct ethtool_pauseparam *epause)
  826. {
  827. struct port_info *p = netdev_priv(dev);
  828. struct link_config *lc = &p->link_cfg;
  829. if (epause->autoneg == AUTONEG_DISABLE)
  830. lc->requested_fc = 0;
  831. else if (lc->pcaps & FW_PORT_CAP32_ANEG)
  832. lc->requested_fc = PAUSE_AUTONEG;
  833. else
  834. return -EINVAL;
  835. if (epause->rx_pause)
  836. lc->requested_fc |= PAUSE_RX;
  837. if (epause->tx_pause)
  838. lc->requested_fc |= PAUSE_TX;
  839. if (netif_running(dev))
  840. return t4_link_l1cfg(p->adapter, p->adapter->mbox, p->tx_chan,
  841. lc);
  842. return 0;
  843. }
  844. static void get_sge_param(struct net_device *dev, struct ethtool_ringparam *e)
  845. {
  846. const struct port_info *pi = netdev_priv(dev);
  847. const struct sge *s = &pi->adapter->sge;
  848. e->rx_max_pending = MAX_RX_BUFFERS;
  849. e->rx_mini_max_pending = MAX_RSPQ_ENTRIES;
  850. e->rx_jumbo_max_pending = 0;
  851. e->tx_max_pending = MAX_TXQ_ENTRIES;
  852. e->rx_pending = s->ethrxq[pi->first_qset].fl.size - 8;
  853. e->rx_mini_pending = s->ethrxq[pi->first_qset].rspq.size;
  854. e->rx_jumbo_pending = 0;
  855. e->tx_pending = s->ethtxq[pi->first_qset].q.size;
  856. }
  857. static int set_sge_param(struct net_device *dev, struct ethtool_ringparam *e)
  858. {
  859. int i;
  860. const struct port_info *pi = netdev_priv(dev);
  861. struct adapter *adapter = pi->adapter;
  862. struct sge *s = &adapter->sge;
  863. if (e->rx_pending > MAX_RX_BUFFERS || e->rx_jumbo_pending ||
  864. e->tx_pending > MAX_TXQ_ENTRIES ||
  865. e->rx_mini_pending > MAX_RSPQ_ENTRIES ||
  866. e->rx_mini_pending < MIN_RSPQ_ENTRIES ||
  867. e->rx_pending < MIN_FL_ENTRIES || e->tx_pending < MIN_TXQ_ENTRIES)
  868. return -EINVAL;
  869. if (adapter->flags & FULL_INIT_DONE)
  870. return -EBUSY;
  871. for (i = 0; i < pi->nqsets; ++i) {
  872. s->ethtxq[pi->first_qset + i].q.size = e->tx_pending;
  873. s->ethrxq[pi->first_qset + i].fl.size = e->rx_pending + 8;
  874. s->ethrxq[pi->first_qset + i].rspq.size = e->rx_mini_pending;
  875. }
  876. return 0;
  877. }
  878. /**
  879. * set_rx_intr_params - set a net devices's RX interrupt holdoff paramete!
  880. * @dev: the network device
  881. * @us: the hold-off time in us, or 0 to disable timer
  882. * @cnt: the hold-off packet count, or 0 to disable counter
  883. *
  884. * Set the RX interrupt hold-off parameters for a network device.
  885. */
  886. static int set_rx_intr_params(struct net_device *dev,
  887. unsigned int us, unsigned int cnt)
  888. {
  889. int i, err;
  890. struct port_info *pi = netdev_priv(dev);
  891. struct adapter *adap = pi->adapter;
  892. struct sge_eth_rxq *q = &adap->sge.ethrxq[pi->first_qset];
  893. for (i = 0; i < pi->nqsets; i++, q++) {
  894. err = cxgb4_set_rspq_intr_params(&q->rspq, us, cnt);
  895. if (err)
  896. return err;
  897. }
  898. return 0;
  899. }
  900. static int set_adaptive_rx_setting(struct net_device *dev, int adaptive_rx)
  901. {
  902. int i;
  903. struct port_info *pi = netdev_priv(dev);
  904. struct adapter *adap = pi->adapter;
  905. struct sge_eth_rxq *q = &adap->sge.ethrxq[pi->first_qset];
  906. for (i = 0; i < pi->nqsets; i++, q++)
  907. q->rspq.adaptive_rx = adaptive_rx;
  908. return 0;
  909. }
  910. static int get_adaptive_rx_setting(struct net_device *dev)
  911. {
  912. struct port_info *pi = netdev_priv(dev);
  913. struct adapter *adap = pi->adapter;
  914. struct sge_eth_rxq *q = &adap->sge.ethrxq[pi->first_qset];
  915. return q->rspq.adaptive_rx;
  916. }
  917. static int set_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
  918. {
  919. set_adaptive_rx_setting(dev, c->use_adaptive_rx_coalesce);
  920. return set_rx_intr_params(dev, c->rx_coalesce_usecs,
  921. c->rx_max_coalesced_frames);
  922. }
  923. static int get_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
  924. {
  925. const struct port_info *pi = netdev_priv(dev);
  926. const struct adapter *adap = pi->adapter;
  927. const struct sge_rspq *rq = &adap->sge.ethrxq[pi->first_qset].rspq;
  928. c->rx_coalesce_usecs = qtimer_val(adap, rq);
  929. c->rx_max_coalesced_frames = (rq->intr_params & QINTR_CNT_EN_F) ?
  930. adap->sge.counter_val[rq->pktcnt_idx] : 0;
  931. c->use_adaptive_rx_coalesce = get_adaptive_rx_setting(dev);
  932. return 0;
  933. }
  934. /* The next two routines implement eeprom read/write from physical addresses.
  935. */
  936. static int eeprom_rd_phys(struct adapter *adap, unsigned int phys_addr, u32 *v)
  937. {
  938. int vaddr = t4_eeprom_ptov(phys_addr, adap->pf, EEPROMPFSIZE);
  939. if (vaddr >= 0)
  940. vaddr = pci_read_vpd(adap->pdev, vaddr, sizeof(u32), v);
  941. return vaddr < 0 ? vaddr : 0;
  942. }
  943. static int eeprom_wr_phys(struct adapter *adap, unsigned int phys_addr, u32 v)
  944. {
  945. int vaddr = t4_eeprom_ptov(phys_addr, adap->pf, EEPROMPFSIZE);
  946. if (vaddr >= 0)
  947. vaddr = pci_write_vpd(adap->pdev, vaddr, sizeof(u32), &v);
  948. return vaddr < 0 ? vaddr : 0;
  949. }
  950. #define EEPROM_MAGIC 0x38E2F10C
  951. static int get_eeprom(struct net_device *dev, struct ethtool_eeprom *e,
  952. u8 *data)
  953. {
  954. int i, err = 0;
  955. struct adapter *adapter = netdev2adap(dev);
  956. u8 *buf = kvzalloc(EEPROMSIZE, GFP_KERNEL);
  957. if (!buf)
  958. return -ENOMEM;
  959. e->magic = EEPROM_MAGIC;
  960. for (i = e->offset & ~3; !err && i < e->offset + e->len; i += 4)
  961. err = eeprom_rd_phys(adapter, i, (u32 *)&buf[i]);
  962. if (!err)
  963. memcpy(data, buf + e->offset, e->len);
  964. kvfree(buf);
  965. return err;
  966. }
  967. static int set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  968. u8 *data)
  969. {
  970. u8 *buf;
  971. int err = 0;
  972. u32 aligned_offset, aligned_len, *p;
  973. struct adapter *adapter = netdev2adap(dev);
  974. if (eeprom->magic != EEPROM_MAGIC)
  975. return -EINVAL;
  976. aligned_offset = eeprom->offset & ~3;
  977. aligned_len = (eeprom->len + (eeprom->offset & 3) + 3) & ~3;
  978. if (adapter->pf > 0) {
  979. u32 start = 1024 + adapter->pf * EEPROMPFSIZE;
  980. if (aligned_offset < start ||
  981. aligned_offset + aligned_len > start + EEPROMPFSIZE)
  982. return -EPERM;
  983. }
  984. if (aligned_offset != eeprom->offset || aligned_len != eeprom->len) {
  985. /* RMW possibly needed for first or last words.
  986. */
  987. buf = kvzalloc(aligned_len, GFP_KERNEL);
  988. if (!buf)
  989. return -ENOMEM;
  990. err = eeprom_rd_phys(adapter, aligned_offset, (u32 *)buf);
  991. if (!err && aligned_len > 4)
  992. err = eeprom_rd_phys(adapter,
  993. aligned_offset + aligned_len - 4,
  994. (u32 *)&buf[aligned_len - 4]);
  995. if (err)
  996. goto out;
  997. memcpy(buf + (eeprom->offset & 3), data, eeprom->len);
  998. } else {
  999. buf = data;
  1000. }
  1001. err = t4_seeprom_wp(adapter, false);
  1002. if (err)
  1003. goto out;
  1004. for (p = (u32 *)buf; !err && aligned_len; aligned_len -= 4, p++) {
  1005. err = eeprom_wr_phys(adapter, aligned_offset, *p);
  1006. aligned_offset += 4;
  1007. }
  1008. if (!err)
  1009. err = t4_seeprom_wp(adapter, true);
  1010. out:
  1011. if (buf != data)
  1012. kvfree(buf);
  1013. return err;
  1014. }
  1015. static int set_flash(struct net_device *netdev, struct ethtool_flash *ef)
  1016. {
  1017. int ret;
  1018. const struct firmware *fw;
  1019. struct adapter *adap = netdev2adap(netdev);
  1020. unsigned int mbox = PCIE_FW_MASTER_M + 1;
  1021. u32 pcie_fw;
  1022. unsigned int master;
  1023. u8 master_vld = 0;
  1024. pcie_fw = t4_read_reg(adap, PCIE_FW_A);
  1025. master = PCIE_FW_MASTER_G(pcie_fw);
  1026. if (pcie_fw & PCIE_FW_MASTER_VLD_F)
  1027. master_vld = 1;
  1028. /* if csiostor is the master return */
  1029. if (master_vld && (master != adap->pf)) {
  1030. dev_warn(adap->pdev_dev,
  1031. "cxgb4 driver needs to be loaded as MASTER to support FW flash\n");
  1032. return -EOPNOTSUPP;
  1033. }
  1034. ef->data[sizeof(ef->data) - 1] = '\0';
  1035. ret = request_firmware(&fw, ef->data, adap->pdev_dev);
  1036. if (ret < 0)
  1037. return ret;
  1038. /* If the adapter has been fully initialized then we'll go ahead and
  1039. * try to get the firmware's cooperation in upgrading to the new
  1040. * firmware image otherwise we'll try to do the entire job from the
  1041. * host ... and we always "force" the operation in this path.
  1042. */
  1043. if (adap->flags & FULL_INIT_DONE)
  1044. mbox = adap->mbox;
  1045. ret = t4_fw_upgrade(adap, mbox, fw->data, fw->size, 1);
  1046. release_firmware(fw);
  1047. if (!ret)
  1048. dev_info(adap->pdev_dev,
  1049. "loaded firmware %s, reload cxgb4 driver\n", ef->data);
  1050. return ret;
  1051. }
  1052. static int get_ts_info(struct net_device *dev, struct ethtool_ts_info *ts_info)
  1053. {
  1054. struct port_info *pi = netdev_priv(dev);
  1055. struct adapter *adapter = pi->adapter;
  1056. ts_info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
  1057. SOF_TIMESTAMPING_RX_SOFTWARE |
  1058. SOF_TIMESTAMPING_SOFTWARE;
  1059. ts_info->so_timestamping |= SOF_TIMESTAMPING_RX_HARDWARE |
  1060. SOF_TIMESTAMPING_TX_HARDWARE |
  1061. SOF_TIMESTAMPING_RAW_HARDWARE;
  1062. ts_info->tx_types = (1 << HWTSTAMP_TX_OFF) |
  1063. (1 << HWTSTAMP_TX_ON);
  1064. ts_info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
  1065. (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
  1066. (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
  1067. (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
  1068. (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
  1069. (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
  1070. if (adapter->ptp_clock)
  1071. ts_info->phc_index = ptp_clock_index(adapter->ptp_clock);
  1072. else
  1073. ts_info->phc_index = -1;
  1074. return 0;
  1075. }
  1076. static u32 get_rss_table_size(struct net_device *dev)
  1077. {
  1078. const struct port_info *pi = netdev_priv(dev);
  1079. return pi->rss_size;
  1080. }
  1081. static int get_rss_table(struct net_device *dev, u32 *p, u8 *key, u8 *hfunc)
  1082. {
  1083. const struct port_info *pi = netdev_priv(dev);
  1084. unsigned int n = pi->rss_size;
  1085. if (hfunc)
  1086. *hfunc = ETH_RSS_HASH_TOP;
  1087. if (!p)
  1088. return 0;
  1089. while (n--)
  1090. p[n] = pi->rss[n];
  1091. return 0;
  1092. }
  1093. static int set_rss_table(struct net_device *dev, const u32 *p, const u8 *key,
  1094. const u8 hfunc)
  1095. {
  1096. unsigned int i;
  1097. struct port_info *pi = netdev_priv(dev);
  1098. /* We require at least one supported parameter to be changed and no
  1099. * change in any of the unsupported parameters
  1100. */
  1101. if (key ||
  1102. (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
  1103. return -EOPNOTSUPP;
  1104. if (!p)
  1105. return 0;
  1106. /* Interface must be brought up atleast once */
  1107. if (pi->adapter->flags & FULL_INIT_DONE) {
  1108. for (i = 0; i < pi->rss_size; i++)
  1109. pi->rss[i] = p[i];
  1110. return cxgb4_write_rss(pi, pi->rss);
  1111. }
  1112. return -EPERM;
  1113. }
  1114. static int get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
  1115. u32 *rules)
  1116. {
  1117. const struct port_info *pi = netdev_priv(dev);
  1118. switch (info->cmd) {
  1119. case ETHTOOL_GRXFH: {
  1120. unsigned int v = pi->rss_mode;
  1121. info->data = 0;
  1122. switch (info->flow_type) {
  1123. case TCP_V4_FLOW:
  1124. if (v & FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN_F)
  1125. info->data = RXH_IP_SRC | RXH_IP_DST |
  1126. RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1127. else if (v & FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN_F)
  1128. info->data = RXH_IP_SRC | RXH_IP_DST;
  1129. break;
  1130. case UDP_V4_FLOW:
  1131. if ((v & FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN_F) &&
  1132. (v & FW_RSS_VI_CONFIG_CMD_UDPEN_F))
  1133. info->data = RXH_IP_SRC | RXH_IP_DST |
  1134. RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1135. else if (v & FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN_F)
  1136. info->data = RXH_IP_SRC | RXH_IP_DST;
  1137. break;
  1138. case SCTP_V4_FLOW:
  1139. case AH_ESP_V4_FLOW:
  1140. case IPV4_FLOW:
  1141. if (v & FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN_F)
  1142. info->data = RXH_IP_SRC | RXH_IP_DST;
  1143. break;
  1144. case TCP_V6_FLOW:
  1145. if (v & FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN_F)
  1146. info->data = RXH_IP_SRC | RXH_IP_DST |
  1147. RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1148. else if (v & FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN_F)
  1149. info->data = RXH_IP_SRC | RXH_IP_DST;
  1150. break;
  1151. case UDP_V6_FLOW:
  1152. if ((v & FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN_F) &&
  1153. (v & FW_RSS_VI_CONFIG_CMD_UDPEN_F))
  1154. info->data = RXH_IP_SRC | RXH_IP_DST |
  1155. RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1156. else if (v & FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN_F)
  1157. info->data = RXH_IP_SRC | RXH_IP_DST;
  1158. break;
  1159. case SCTP_V6_FLOW:
  1160. case AH_ESP_V6_FLOW:
  1161. case IPV6_FLOW:
  1162. if (v & FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN_F)
  1163. info->data = RXH_IP_SRC | RXH_IP_DST;
  1164. break;
  1165. }
  1166. return 0;
  1167. }
  1168. case ETHTOOL_GRXRINGS:
  1169. info->data = pi->nqsets;
  1170. return 0;
  1171. }
  1172. return -EOPNOTSUPP;
  1173. }
  1174. static int set_dump(struct net_device *dev, struct ethtool_dump *eth_dump)
  1175. {
  1176. struct adapter *adapter = netdev2adap(dev);
  1177. u32 len = 0;
  1178. len = sizeof(struct cudbg_hdr) +
  1179. sizeof(struct cudbg_entity_hdr) * CUDBG_MAX_ENTITY;
  1180. len += cxgb4_get_dump_length(adapter, eth_dump->flag);
  1181. adapter->eth_dump.flag = eth_dump->flag;
  1182. adapter->eth_dump.len = len;
  1183. return 0;
  1184. }
  1185. static int get_dump_flag(struct net_device *dev, struct ethtool_dump *eth_dump)
  1186. {
  1187. struct adapter *adapter = netdev2adap(dev);
  1188. eth_dump->flag = adapter->eth_dump.flag;
  1189. eth_dump->len = adapter->eth_dump.len;
  1190. eth_dump->version = adapter->eth_dump.version;
  1191. return 0;
  1192. }
  1193. static int get_dump_data(struct net_device *dev, struct ethtool_dump *eth_dump,
  1194. void *buf)
  1195. {
  1196. struct adapter *adapter = netdev2adap(dev);
  1197. u32 len = 0;
  1198. int ret = 0;
  1199. if (adapter->eth_dump.flag == CXGB4_ETH_DUMP_NONE)
  1200. return -ENOENT;
  1201. len = sizeof(struct cudbg_hdr) +
  1202. sizeof(struct cudbg_entity_hdr) * CUDBG_MAX_ENTITY;
  1203. len += cxgb4_get_dump_length(adapter, adapter->eth_dump.flag);
  1204. if (eth_dump->len < len)
  1205. return -ENOMEM;
  1206. ret = cxgb4_cudbg_collect(adapter, buf, &len, adapter->eth_dump.flag);
  1207. if (ret)
  1208. return ret;
  1209. eth_dump->flag = adapter->eth_dump.flag;
  1210. eth_dump->len = len;
  1211. eth_dump->version = adapter->eth_dump.version;
  1212. return 0;
  1213. }
  1214. static int cxgb4_get_module_info(struct net_device *dev,
  1215. struct ethtool_modinfo *modinfo)
  1216. {
  1217. struct port_info *pi = netdev_priv(dev);
  1218. u8 sff8472_comp, sff_diag_type, sff_rev;
  1219. struct adapter *adapter = pi->adapter;
  1220. int ret;
  1221. if (!t4_is_inserted_mod_type(pi->mod_type))
  1222. return -EINVAL;
  1223. switch (pi->port_type) {
  1224. case FW_PORT_TYPE_SFP:
  1225. case FW_PORT_TYPE_QSA:
  1226. case FW_PORT_TYPE_SFP28:
  1227. ret = t4_i2c_rd(adapter, adapter->mbox, pi->tx_chan,
  1228. I2C_DEV_ADDR_A0, SFF_8472_COMP_ADDR,
  1229. SFF_8472_COMP_LEN, &sff8472_comp);
  1230. if (ret)
  1231. return ret;
  1232. ret = t4_i2c_rd(adapter, adapter->mbox, pi->tx_chan,
  1233. I2C_DEV_ADDR_A0, SFP_DIAG_TYPE_ADDR,
  1234. SFP_DIAG_TYPE_LEN, &sff_diag_type);
  1235. if (ret)
  1236. return ret;
  1237. if (!sff8472_comp || (sff_diag_type & 4)) {
  1238. modinfo->type = ETH_MODULE_SFF_8079;
  1239. modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
  1240. } else {
  1241. modinfo->type = ETH_MODULE_SFF_8472;
  1242. modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
  1243. }
  1244. break;
  1245. case FW_PORT_TYPE_QSFP:
  1246. case FW_PORT_TYPE_QSFP_10G:
  1247. case FW_PORT_TYPE_CR_QSFP:
  1248. case FW_PORT_TYPE_CR2_QSFP:
  1249. case FW_PORT_TYPE_CR4_QSFP:
  1250. ret = t4_i2c_rd(adapter, adapter->mbox, pi->tx_chan,
  1251. I2C_DEV_ADDR_A0, SFF_REV_ADDR,
  1252. SFF_REV_LEN, &sff_rev);
  1253. /* For QSFP type ports, revision value >= 3
  1254. * means the SFP is 8636 compliant.
  1255. */
  1256. if (ret)
  1257. return ret;
  1258. if (sff_rev >= 0x3) {
  1259. modinfo->type = ETH_MODULE_SFF_8636;
  1260. modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN;
  1261. } else {
  1262. modinfo->type = ETH_MODULE_SFF_8436;
  1263. modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
  1264. }
  1265. break;
  1266. default:
  1267. return -EINVAL;
  1268. }
  1269. return 0;
  1270. }
  1271. static int cxgb4_get_module_eeprom(struct net_device *dev,
  1272. struct ethtool_eeprom *eprom, u8 *data)
  1273. {
  1274. int ret = 0, offset = eprom->offset, len = eprom->len;
  1275. struct port_info *pi = netdev_priv(dev);
  1276. struct adapter *adapter = pi->adapter;
  1277. memset(data, 0, eprom->len);
  1278. if (offset + len <= I2C_PAGE_SIZE)
  1279. return t4_i2c_rd(adapter, adapter->mbox, pi->tx_chan,
  1280. I2C_DEV_ADDR_A0, offset, len, data);
  1281. /* offset + len spans 0xa0 and 0xa1 pages */
  1282. if (offset <= I2C_PAGE_SIZE) {
  1283. /* read 0xa0 page */
  1284. len = I2C_PAGE_SIZE - offset;
  1285. ret = t4_i2c_rd(adapter, adapter->mbox, pi->tx_chan,
  1286. I2C_DEV_ADDR_A0, offset, len, data);
  1287. if (ret)
  1288. return ret;
  1289. offset = I2C_PAGE_SIZE;
  1290. /* Remaining bytes to be read from second page =
  1291. * Total length - bytes read from first page
  1292. */
  1293. len = eprom->len - len;
  1294. }
  1295. /* Read additional optical diagnostics from page 0xa2 if supported */
  1296. return t4_i2c_rd(adapter, adapter->mbox, pi->tx_chan, I2C_DEV_ADDR_A2,
  1297. offset, len, &data[eprom->len - len]);
  1298. }
  1299. static const struct ethtool_ops cxgb_ethtool_ops = {
  1300. .get_link_ksettings = get_link_ksettings,
  1301. .set_link_ksettings = set_link_ksettings,
  1302. .get_fecparam = get_fecparam,
  1303. .set_fecparam = set_fecparam,
  1304. .get_drvinfo = get_drvinfo,
  1305. .get_msglevel = get_msglevel,
  1306. .set_msglevel = set_msglevel,
  1307. .get_ringparam = get_sge_param,
  1308. .set_ringparam = set_sge_param,
  1309. .get_coalesce = get_coalesce,
  1310. .set_coalesce = set_coalesce,
  1311. .get_eeprom_len = get_eeprom_len,
  1312. .get_eeprom = get_eeprom,
  1313. .set_eeprom = set_eeprom,
  1314. .get_pauseparam = get_pauseparam,
  1315. .set_pauseparam = set_pauseparam,
  1316. .get_link = ethtool_op_get_link,
  1317. .get_strings = get_strings,
  1318. .set_phys_id = identify_port,
  1319. .nway_reset = restart_autoneg,
  1320. .get_sset_count = get_sset_count,
  1321. .get_ethtool_stats = get_stats,
  1322. .get_regs_len = get_regs_len,
  1323. .get_regs = get_regs,
  1324. .get_rxnfc = get_rxnfc,
  1325. .get_rxfh_indir_size = get_rss_table_size,
  1326. .get_rxfh = get_rss_table,
  1327. .set_rxfh = set_rss_table,
  1328. .flash_device = set_flash,
  1329. .get_ts_info = get_ts_info,
  1330. .set_dump = set_dump,
  1331. .get_dump_flag = get_dump_flag,
  1332. .get_dump_data = get_dump_data,
  1333. .get_module_info = cxgb4_get_module_info,
  1334. .get_module_eeprom = cxgb4_get_module_eeprom,
  1335. };
  1336. void cxgb4_set_ethtool_ops(struct net_device *netdev)
  1337. {
  1338. netdev->ethtool_ops = &cxgb_ethtool_ops;
  1339. }