cxgb4_ethtool.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  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. #define EEPROM_MAGIC 0x38E2F10C
  23. static u32 get_msglevel(struct net_device *dev)
  24. {
  25. return netdev2adap(dev)->msg_enable;
  26. }
  27. static void set_msglevel(struct net_device *dev, u32 val)
  28. {
  29. netdev2adap(dev)->msg_enable = val;
  30. }
  31. static const char stats_strings[][ETH_GSTRING_LEN] = {
  32. "tx_octets_ok ",
  33. "tx_frames_ok ",
  34. "tx_broadcast_frames ",
  35. "tx_multicast_frames ",
  36. "tx_unicast_frames ",
  37. "tx_error_frames ",
  38. "tx_frames_64 ",
  39. "tx_frames_65_to_127 ",
  40. "tx_frames_128_to_255 ",
  41. "tx_frames_256_to_511 ",
  42. "tx_frames_512_to_1023 ",
  43. "tx_frames_1024_to_1518 ",
  44. "tx_frames_1519_to_max ",
  45. "tx_frames_dropped ",
  46. "tx_pause_frames ",
  47. "tx_ppp0_frames ",
  48. "tx_ppp1_frames ",
  49. "tx_ppp2_frames ",
  50. "tx_ppp3_frames ",
  51. "tx_ppp4_frames ",
  52. "tx_ppp5_frames ",
  53. "tx_ppp6_frames ",
  54. "tx_ppp7_frames ",
  55. "rx_octets_ok ",
  56. "rx_frames_ok ",
  57. "rx_broadcast_frames ",
  58. "rx_multicast_frames ",
  59. "rx_unicast_frames ",
  60. "rx_frames_too_long ",
  61. "rx_jabber_errors ",
  62. "rx_fcs_errors ",
  63. "rx_length_errors ",
  64. "rx_symbol_errors ",
  65. "rx_runt_frames ",
  66. "rx_frames_64 ",
  67. "rx_frames_65_to_127 ",
  68. "rx_frames_128_to_255 ",
  69. "rx_frames_256_to_511 ",
  70. "rx_frames_512_to_1023 ",
  71. "rx_frames_1024_to_1518 ",
  72. "rx_frames_1519_to_max ",
  73. "rx_pause_frames ",
  74. "rx_ppp0_frames ",
  75. "rx_ppp1_frames ",
  76. "rx_ppp2_frames ",
  77. "rx_ppp3_frames ",
  78. "rx_ppp4_frames ",
  79. "rx_ppp5_frames ",
  80. "rx_ppp6_frames ",
  81. "rx_ppp7_frames ",
  82. "rx_bg0_frames_dropped ",
  83. "rx_bg1_frames_dropped ",
  84. "rx_bg2_frames_dropped ",
  85. "rx_bg3_frames_dropped ",
  86. "rx_bg0_frames_trunc ",
  87. "rx_bg1_frames_trunc ",
  88. "rx_bg2_frames_trunc ",
  89. "rx_bg3_frames_trunc ",
  90. "tso ",
  91. "tx_csum_offload ",
  92. "rx_csum_good ",
  93. "vlan_extractions ",
  94. "vlan_insertions ",
  95. "gro_packets ",
  96. "gro_merged ",
  97. };
  98. static char adapter_stats_strings[][ETH_GSTRING_LEN] = {
  99. "db_drop ",
  100. "db_full ",
  101. "db_empty ",
  102. "tcp_ipv4_out_rsts ",
  103. "tcp_ipv4_in_segs ",
  104. "tcp_ipv4_out_segs ",
  105. "tcp_ipv4_retrans_segs ",
  106. "tcp_ipv6_out_rsts ",
  107. "tcp_ipv6_in_segs ",
  108. "tcp_ipv6_out_segs ",
  109. "tcp_ipv6_retrans_segs ",
  110. "usm_ddp_frames ",
  111. "usm_ddp_octets ",
  112. "usm_ddp_drops ",
  113. "rdma_no_rqe_mod_defer ",
  114. "rdma_no_rqe_pkt_defer ",
  115. "tp_err_ofld_no_neigh ",
  116. "tp_err_ofld_cong_defer ",
  117. "write_coal_success ",
  118. "write_coal_fail ",
  119. };
  120. static char channel_stats_strings[][ETH_GSTRING_LEN] = {
  121. "--------Channel--------- ",
  122. "tp_cpl_requests ",
  123. "tp_cpl_responses ",
  124. "tp_mac_in_errs ",
  125. "tp_hdr_in_errs ",
  126. "tp_tcp_in_errs ",
  127. "tp_tcp6_in_errs ",
  128. "tp_tnl_cong_drops ",
  129. "tp_tnl_tx_drops ",
  130. "tp_ofld_vlan_drops ",
  131. "tp_ofld_chan_drops ",
  132. "fcoe_octets_ddp ",
  133. "fcoe_frames_ddp ",
  134. "fcoe_frames_drop ",
  135. };
  136. static char loopback_stats_strings[][ETH_GSTRING_LEN] = {
  137. "-------Loopback----------- ",
  138. "octets_ok ",
  139. "frames_ok ",
  140. "bcast_frames ",
  141. "mcast_frames ",
  142. "ucast_frames ",
  143. "error_frames ",
  144. "frames_64 ",
  145. "frames_65_to_127 ",
  146. "frames_128_to_255 ",
  147. "frames_256_to_511 ",
  148. "frames_512_to_1023 ",
  149. "frames_1024_to_1518 ",
  150. "frames_1519_to_max ",
  151. "frames_dropped ",
  152. "bg0_frames_dropped ",
  153. "bg1_frames_dropped ",
  154. "bg2_frames_dropped ",
  155. "bg3_frames_dropped ",
  156. "bg0_frames_trunc ",
  157. "bg1_frames_trunc ",
  158. "bg2_frames_trunc ",
  159. "bg3_frames_trunc ",
  160. };
  161. static int get_sset_count(struct net_device *dev, int sset)
  162. {
  163. switch (sset) {
  164. case ETH_SS_STATS:
  165. return ARRAY_SIZE(stats_strings) +
  166. ARRAY_SIZE(adapter_stats_strings) +
  167. ARRAY_SIZE(channel_stats_strings) +
  168. ARRAY_SIZE(loopback_stats_strings);
  169. default:
  170. return -EOPNOTSUPP;
  171. }
  172. }
  173. static int get_regs_len(struct net_device *dev)
  174. {
  175. struct adapter *adap = netdev2adap(dev);
  176. return t4_get_regs_len(adap);
  177. }
  178. static int get_eeprom_len(struct net_device *dev)
  179. {
  180. return EEPROMSIZE;
  181. }
  182. static void get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  183. {
  184. struct adapter *adapter = netdev2adap(dev);
  185. u32 exprom_vers;
  186. strlcpy(info->driver, cxgb4_driver_name, sizeof(info->driver));
  187. strlcpy(info->version, cxgb4_driver_version,
  188. sizeof(info->version));
  189. strlcpy(info->bus_info, pci_name(adapter->pdev),
  190. sizeof(info->bus_info));
  191. info->regdump_len = get_regs_len(dev);
  192. if (!adapter->params.fw_vers)
  193. strcpy(info->fw_version, "N/A");
  194. else
  195. snprintf(info->fw_version, sizeof(info->fw_version),
  196. "%u.%u.%u.%u, TP %u.%u.%u.%u",
  197. FW_HDR_FW_VER_MAJOR_G(adapter->params.fw_vers),
  198. FW_HDR_FW_VER_MINOR_G(adapter->params.fw_vers),
  199. FW_HDR_FW_VER_MICRO_G(adapter->params.fw_vers),
  200. FW_HDR_FW_VER_BUILD_G(adapter->params.fw_vers),
  201. FW_HDR_FW_VER_MAJOR_G(adapter->params.tp_vers),
  202. FW_HDR_FW_VER_MINOR_G(adapter->params.tp_vers),
  203. FW_HDR_FW_VER_MICRO_G(adapter->params.tp_vers),
  204. FW_HDR_FW_VER_BUILD_G(adapter->params.tp_vers));
  205. if (!t4_get_exprom_version(adapter, &exprom_vers))
  206. snprintf(info->erom_version, sizeof(info->erom_version),
  207. "%u.%u.%u.%u",
  208. FW_HDR_FW_VER_MAJOR_G(exprom_vers),
  209. FW_HDR_FW_VER_MINOR_G(exprom_vers),
  210. FW_HDR_FW_VER_MICRO_G(exprom_vers),
  211. FW_HDR_FW_VER_BUILD_G(exprom_vers));
  212. }
  213. static void get_strings(struct net_device *dev, u32 stringset, u8 *data)
  214. {
  215. if (stringset == ETH_SS_STATS) {
  216. memcpy(data, stats_strings, sizeof(stats_strings));
  217. data += sizeof(stats_strings);
  218. memcpy(data, adapter_stats_strings,
  219. sizeof(adapter_stats_strings));
  220. data += sizeof(adapter_stats_strings);
  221. memcpy(data, channel_stats_strings,
  222. sizeof(channel_stats_strings));
  223. data += sizeof(channel_stats_strings);
  224. memcpy(data, loopback_stats_strings,
  225. sizeof(loopback_stats_strings));
  226. }
  227. }
  228. /* port stats maintained per queue of the port. They should be in the same
  229. * order as in stats_strings above.
  230. */
  231. struct queue_port_stats {
  232. u64 tso;
  233. u64 tx_csum;
  234. u64 rx_csum;
  235. u64 vlan_ex;
  236. u64 vlan_ins;
  237. u64 gro_pkts;
  238. u64 gro_merged;
  239. };
  240. struct adapter_stats {
  241. u64 db_drop;
  242. u64 db_full;
  243. u64 db_empty;
  244. u64 tcp_v4_out_rsts;
  245. u64 tcp_v4_in_segs;
  246. u64 tcp_v4_out_segs;
  247. u64 tcp_v4_retrans_segs;
  248. u64 tcp_v6_out_rsts;
  249. u64 tcp_v6_in_segs;
  250. u64 tcp_v6_out_segs;
  251. u64 tcp_v6_retrans_segs;
  252. u64 frames;
  253. u64 octets;
  254. u64 drops;
  255. u64 rqe_dfr_mod;
  256. u64 rqe_dfr_pkt;
  257. u64 ofld_no_neigh;
  258. u64 ofld_cong_defer;
  259. u64 wc_success;
  260. u64 wc_fail;
  261. };
  262. struct channel_stats {
  263. u64 cpl_req;
  264. u64 cpl_rsp;
  265. u64 mac_in_errs;
  266. u64 hdr_in_errs;
  267. u64 tcp_in_errs;
  268. u64 tcp6_in_errs;
  269. u64 tnl_cong_drops;
  270. u64 tnl_tx_drops;
  271. u64 ofld_vlan_drops;
  272. u64 ofld_chan_drops;
  273. u64 octets_ddp;
  274. u64 frames_ddp;
  275. u64 frames_drop;
  276. };
  277. static void collect_sge_port_stats(const struct adapter *adap,
  278. const struct port_info *p,
  279. struct queue_port_stats *s)
  280. {
  281. int i;
  282. const struct sge_eth_txq *tx = &adap->sge.ethtxq[p->first_qset];
  283. const struct sge_eth_rxq *rx = &adap->sge.ethrxq[p->first_qset];
  284. memset(s, 0, sizeof(*s));
  285. for (i = 0; i < p->nqsets; i++, rx++, tx++) {
  286. s->tso += tx->tso;
  287. s->tx_csum += tx->tx_cso;
  288. s->rx_csum += rx->stats.rx_cso;
  289. s->vlan_ex += rx->stats.vlan_ex;
  290. s->vlan_ins += tx->vlan_ins;
  291. s->gro_pkts += rx->stats.lro_pkts;
  292. s->gro_merged += rx->stats.lro_merged;
  293. }
  294. }
  295. static void collect_adapter_stats(struct adapter *adap, struct adapter_stats *s)
  296. {
  297. struct tp_tcp_stats v4, v6;
  298. struct tp_rdma_stats rdma_stats;
  299. struct tp_err_stats err_stats;
  300. struct tp_usm_stats usm_stats;
  301. u64 val1, val2;
  302. memset(s, 0, sizeof(*s));
  303. spin_lock(&adap->stats_lock);
  304. t4_tp_get_tcp_stats(adap, &v4, &v6);
  305. t4_tp_get_rdma_stats(adap, &rdma_stats);
  306. t4_get_usm_stats(adap, &usm_stats);
  307. t4_tp_get_err_stats(adap, &err_stats);
  308. spin_unlock(&adap->stats_lock);
  309. s->db_drop = adap->db_stats.db_drop;
  310. s->db_full = adap->db_stats.db_full;
  311. s->db_empty = adap->db_stats.db_empty;
  312. s->tcp_v4_out_rsts = v4.tcp_out_rsts;
  313. s->tcp_v4_in_segs = v4.tcp_in_segs;
  314. s->tcp_v4_out_segs = v4.tcp_out_segs;
  315. s->tcp_v4_retrans_segs = v4.tcp_retrans_segs;
  316. s->tcp_v6_out_rsts = v6.tcp_out_rsts;
  317. s->tcp_v6_in_segs = v6.tcp_in_segs;
  318. s->tcp_v6_out_segs = v6.tcp_out_segs;
  319. s->tcp_v6_retrans_segs = v6.tcp_retrans_segs;
  320. if (is_offload(adap)) {
  321. s->frames = usm_stats.frames;
  322. s->octets = usm_stats.octets;
  323. s->drops = usm_stats.drops;
  324. s->rqe_dfr_mod = rdma_stats.rqe_dfr_mod;
  325. s->rqe_dfr_pkt = rdma_stats.rqe_dfr_pkt;
  326. }
  327. s->ofld_no_neigh = err_stats.ofld_no_neigh;
  328. s->ofld_cong_defer = err_stats.ofld_cong_defer;
  329. if (!is_t4(adap->params.chip)) {
  330. int v;
  331. v = t4_read_reg(adap, SGE_STAT_CFG_A);
  332. if (STATSOURCE_T5_G(v) == 7) {
  333. val2 = t4_read_reg(adap, SGE_STAT_MATCH_A);
  334. val1 = t4_read_reg(adap, SGE_STAT_TOTAL_A);
  335. s->wc_success = val1 - val2;
  336. s->wc_fail = val2;
  337. }
  338. }
  339. }
  340. static void collect_channel_stats(struct adapter *adap, struct channel_stats *s,
  341. u8 i)
  342. {
  343. struct tp_cpl_stats cpl_stats;
  344. struct tp_err_stats err_stats;
  345. struct tp_fcoe_stats fcoe_stats;
  346. memset(s, 0, sizeof(*s));
  347. spin_lock(&adap->stats_lock);
  348. t4_tp_get_cpl_stats(adap, &cpl_stats);
  349. t4_tp_get_err_stats(adap, &err_stats);
  350. t4_get_fcoe_stats(adap, i, &fcoe_stats);
  351. spin_unlock(&adap->stats_lock);
  352. s->cpl_req = cpl_stats.req[i];
  353. s->cpl_rsp = cpl_stats.rsp[i];
  354. s->mac_in_errs = err_stats.mac_in_errs[i];
  355. s->hdr_in_errs = err_stats.hdr_in_errs[i];
  356. s->tcp_in_errs = err_stats.tcp_in_errs[i];
  357. s->tcp6_in_errs = err_stats.tcp6_in_errs[i];
  358. s->tnl_cong_drops = err_stats.tnl_cong_drops[i];
  359. s->tnl_tx_drops = err_stats.tnl_tx_drops[i];
  360. s->ofld_vlan_drops = err_stats.ofld_vlan_drops[i];
  361. s->ofld_chan_drops = err_stats.ofld_chan_drops[i];
  362. s->octets_ddp = fcoe_stats.octets_ddp;
  363. s->frames_ddp = fcoe_stats.frames_ddp;
  364. s->frames_drop = fcoe_stats.frames_drop;
  365. }
  366. static void get_stats(struct net_device *dev, struct ethtool_stats *stats,
  367. u64 *data)
  368. {
  369. struct port_info *pi = netdev_priv(dev);
  370. struct adapter *adapter = pi->adapter;
  371. struct lb_port_stats s;
  372. int i;
  373. u64 *p0;
  374. t4_get_port_stats_offset(adapter, pi->tx_chan,
  375. (struct port_stats *)data,
  376. &pi->stats_base);
  377. data += sizeof(struct port_stats) / sizeof(u64);
  378. collect_sge_port_stats(adapter, pi, (struct queue_port_stats *)data);
  379. data += sizeof(struct queue_port_stats) / sizeof(u64);
  380. collect_adapter_stats(adapter, (struct adapter_stats *)data);
  381. data += sizeof(struct adapter_stats) / sizeof(u64);
  382. *data++ = (u64)pi->port_id;
  383. collect_channel_stats(adapter, (struct channel_stats *)data,
  384. pi->port_id);
  385. data += sizeof(struct channel_stats) / sizeof(u64);
  386. *data++ = (u64)pi->port_id;
  387. memset(&s, 0, sizeof(s));
  388. t4_get_lb_stats(adapter, pi->port_id, &s);
  389. p0 = &s.octets;
  390. for (i = 0; i < ARRAY_SIZE(loopback_stats_strings) - 1; i++)
  391. *data++ = (unsigned long long)*p0++;
  392. }
  393. static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
  394. void *buf)
  395. {
  396. struct adapter *adap = netdev2adap(dev);
  397. size_t buf_size;
  398. buf_size = t4_get_regs_len(adap);
  399. regs->version = mk_adap_vers(adap);
  400. t4_get_regs(adap, buf, buf_size);
  401. }
  402. static int restart_autoneg(struct net_device *dev)
  403. {
  404. struct port_info *p = netdev_priv(dev);
  405. if (!netif_running(dev))
  406. return -EAGAIN;
  407. if (p->link_cfg.autoneg != AUTONEG_ENABLE)
  408. return -EINVAL;
  409. t4_restart_aneg(p->adapter, p->adapter->pf, p->tx_chan);
  410. return 0;
  411. }
  412. static int identify_port(struct net_device *dev,
  413. enum ethtool_phys_id_state state)
  414. {
  415. unsigned int val;
  416. struct adapter *adap = netdev2adap(dev);
  417. if (state == ETHTOOL_ID_ACTIVE)
  418. val = 0xffff;
  419. else if (state == ETHTOOL_ID_INACTIVE)
  420. val = 0;
  421. else
  422. return -EINVAL;
  423. return t4_identify_port(adap, adap->pf, netdev2pinfo(dev)->viid, val);
  424. }
  425. /**
  426. * from_fw_port_mod_type - translate Firmware Port/Module type to Ethtool
  427. * @port_type: Firmware Port Type
  428. * @mod_type: Firmware Module Type
  429. *
  430. * Translate Firmware Port/Module type to Ethtool Port Type.
  431. */
  432. static int from_fw_port_mod_type(enum fw_port_type port_type,
  433. enum fw_port_module_type mod_type)
  434. {
  435. if (port_type == FW_PORT_TYPE_BT_SGMII ||
  436. port_type == FW_PORT_TYPE_BT_XFI ||
  437. port_type == FW_PORT_TYPE_BT_XAUI) {
  438. return PORT_TP;
  439. } else if (port_type == FW_PORT_TYPE_FIBER_XFI ||
  440. port_type == FW_PORT_TYPE_FIBER_XAUI) {
  441. return PORT_FIBRE;
  442. } else if (port_type == FW_PORT_TYPE_SFP ||
  443. port_type == FW_PORT_TYPE_QSFP_10G ||
  444. port_type == FW_PORT_TYPE_QSA ||
  445. port_type == FW_PORT_TYPE_QSFP) {
  446. if (mod_type == FW_PORT_MOD_TYPE_LR ||
  447. mod_type == FW_PORT_MOD_TYPE_SR ||
  448. mod_type == FW_PORT_MOD_TYPE_ER ||
  449. mod_type == FW_PORT_MOD_TYPE_LRM)
  450. return PORT_FIBRE;
  451. else if (mod_type == FW_PORT_MOD_TYPE_TWINAX_PASSIVE ||
  452. mod_type == FW_PORT_MOD_TYPE_TWINAX_ACTIVE)
  453. return PORT_DA;
  454. else
  455. return PORT_OTHER;
  456. }
  457. return PORT_OTHER;
  458. }
  459. /**
  460. * speed_to_fw_caps - translate Port Speed to Firmware Port Capabilities
  461. * @speed: speed in Kb/s
  462. *
  463. * Translates a specific Port Speed into a Firmware Port Capabilities
  464. * value.
  465. */
  466. static unsigned int speed_to_fw_caps(int speed)
  467. {
  468. if (speed == 100)
  469. return FW_PORT_CAP_SPEED_100M;
  470. if (speed == 1000)
  471. return FW_PORT_CAP_SPEED_1G;
  472. if (speed == 10000)
  473. return FW_PORT_CAP_SPEED_10G;
  474. if (speed == 25000)
  475. return FW_PORT_CAP_SPEED_25G;
  476. if (speed == 40000)
  477. return FW_PORT_CAP_SPEED_40G;
  478. if (speed == 100000)
  479. return FW_PORT_CAP_SPEED_100G;
  480. return 0;
  481. }
  482. /**
  483. * fw_caps_to_lmm - translate Firmware to ethtool Link Mode Mask
  484. * @port_type: Firmware Port Type
  485. * @fw_caps: Firmware Port Capabilities
  486. * @link_mode_mask: ethtool Link Mode Mask
  487. *
  488. * Translate a Firmware Port Capabilities specification to an ethtool
  489. * Link Mode Mask.
  490. */
  491. static void fw_caps_to_lmm(enum fw_port_type port_type,
  492. unsigned int fw_caps,
  493. unsigned long *link_mode_mask)
  494. {
  495. #define SET_LMM(__lmm_name) __set_bit(ETHTOOL_LINK_MODE_ ## __lmm_name \
  496. ## _BIT, link_mode_mask)
  497. #define FW_CAPS_TO_LMM(__fw_name, __lmm_name) \
  498. do { \
  499. if (fw_caps & FW_PORT_CAP_ ## __fw_name) \
  500. SET_LMM(__lmm_name); \
  501. } while (0)
  502. switch (port_type) {
  503. case FW_PORT_TYPE_BT_SGMII:
  504. case FW_PORT_TYPE_BT_XFI:
  505. case FW_PORT_TYPE_BT_XAUI:
  506. SET_LMM(TP);
  507. FW_CAPS_TO_LMM(SPEED_100M, 100baseT_Full);
  508. FW_CAPS_TO_LMM(SPEED_1G, 1000baseT_Full);
  509. FW_CAPS_TO_LMM(SPEED_10G, 10000baseT_Full);
  510. break;
  511. case FW_PORT_TYPE_KX4:
  512. case FW_PORT_TYPE_KX:
  513. SET_LMM(Backplane);
  514. FW_CAPS_TO_LMM(SPEED_1G, 1000baseKX_Full);
  515. FW_CAPS_TO_LMM(SPEED_10G, 10000baseKX4_Full);
  516. break;
  517. case FW_PORT_TYPE_KR:
  518. SET_LMM(Backplane);
  519. SET_LMM(10000baseKR_Full);
  520. break;
  521. case FW_PORT_TYPE_BP_AP:
  522. SET_LMM(Backplane);
  523. SET_LMM(10000baseR_FEC);
  524. SET_LMM(10000baseKR_Full);
  525. SET_LMM(1000baseKX_Full);
  526. break;
  527. case FW_PORT_TYPE_BP4_AP:
  528. SET_LMM(Backplane);
  529. SET_LMM(10000baseR_FEC);
  530. SET_LMM(10000baseKR_Full);
  531. SET_LMM(1000baseKX_Full);
  532. SET_LMM(10000baseKX4_Full);
  533. break;
  534. case FW_PORT_TYPE_FIBER_XFI:
  535. case FW_PORT_TYPE_FIBER_XAUI:
  536. case FW_PORT_TYPE_SFP:
  537. case FW_PORT_TYPE_QSFP_10G:
  538. case FW_PORT_TYPE_QSA:
  539. SET_LMM(FIBRE);
  540. FW_CAPS_TO_LMM(SPEED_1G, 1000baseT_Full);
  541. FW_CAPS_TO_LMM(SPEED_10G, 10000baseT_Full);
  542. break;
  543. case FW_PORT_TYPE_BP40_BA:
  544. case FW_PORT_TYPE_QSFP:
  545. SET_LMM(FIBRE);
  546. SET_LMM(40000baseSR4_Full);
  547. break;
  548. case FW_PORT_TYPE_CR_QSFP:
  549. case FW_PORT_TYPE_SFP28:
  550. SET_LMM(FIBRE);
  551. SET_LMM(25000baseCR_Full);
  552. break;
  553. case FW_PORT_TYPE_KR4_100G:
  554. case FW_PORT_TYPE_CR4_QSFP:
  555. SET_LMM(FIBRE);
  556. SET_LMM(100000baseCR4_Full);
  557. break;
  558. default:
  559. break;
  560. }
  561. FW_CAPS_TO_LMM(ANEG, Autoneg);
  562. FW_CAPS_TO_LMM(802_3_PAUSE, Pause);
  563. FW_CAPS_TO_LMM(802_3_ASM_DIR, Asym_Pause);
  564. #undef FW_CAPS_TO_LMM
  565. #undef SET_LMM
  566. }
  567. /**
  568. * lmm_to_fw_caps - translate ethtool Link Mode Mask to Firmware
  569. * capabilities
  570. *
  571. * @link_mode_mask: ethtool Link Mode Mask
  572. *
  573. * Translate ethtool Link Mode Mask into a Firmware Port capabilities
  574. * value.
  575. */
  576. static unsigned int lmm_to_fw_caps(const unsigned long *link_mode_mask)
  577. {
  578. unsigned int fw_caps = 0;
  579. #define LMM_TO_FW_CAPS(__lmm_name, __fw_name) \
  580. do { \
  581. if (test_bit(ETHTOOL_LINK_MODE_ ## __lmm_name ## _BIT, \
  582. link_mode_mask)) \
  583. fw_caps |= FW_PORT_CAP_ ## __fw_name; \
  584. } while (0)
  585. LMM_TO_FW_CAPS(100baseT_Full, SPEED_100M);
  586. LMM_TO_FW_CAPS(1000baseT_Full, SPEED_1G);
  587. LMM_TO_FW_CAPS(10000baseT_Full, SPEED_10G);
  588. LMM_TO_FW_CAPS(40000baseSR4_Full, SPEED_40G);
  589. LMM_TO_FW_CAPS(25000baseCR_Full, SPEED_25G);
  590. LMM_TO_FW_CAPS(100000baseCR4_Full, SPEED_100G);
  591. #undef LMM_TO_FW_CAPS
  592. return fw_caps;
  593. }
  594. static int get_link_ksettings(struct net_device *dev,
  595. struct ethtool_link_ksettings *link_ksettings)
  596. {
  597. const struct port_info *pi = netdev_priv(dev);
  598. struct ethtool_link_settings *base = &link_ksettings->base;
  599. ethtool_link_ksettings_zero_link_mode(link_ksettings, supported);
  600. ethtool_link_ksettings_zero_link_mode(link_ksettings, advertising);
  601. ethtool_link_ksettings_zero_link_mode(link_ksettings, lp_advertising);
  602. base->port = from_fw_port_mod_type(pi->port_type, pi->mod_type);
  603. if (pi->mdio_addr >= 0) {
  604. base->phy_address = pi->mdio_addr;
  605. base->mdio_support = (pi->port_type == FW_PORT_TYPE_BT_SGMII
  606. ? ETH_MDIO_SUPPORTS_C22
  607. : ETH_MDIO_SUPPORTS_C45);
  608. } else {
  609. base->phy_address = 255;
  610. base->mdio_support = 0;
  611. }
  612. fw_caps_to_lmm(pi->port_type, pi->link_cfg.supported,
  613. link_ksettings->link_modes.supported);
  614. fw_caps_to_lmm(pi->port_type, pi->link_cfg.advertising,
  615. link_ksettings->link_modes.advertising);
  616. fw_caps_to_lmm(pi->port_type, pi->link_cfg.lp_advertising,
  617. link_ksettings->link_modes.lp_advertising);
  618. if (netif_carrier_ok(dev)) {
  619. base->speed = pi->link_cfg.speed;
  620. base->duplex = DUPLEX_FULL;
  621. } else {
  622. base->speed = SPEED_UNKNOWN;
  623. base->duplex = DUPLEX_UNKNOWN;
  624. }
  625. base->autoneg = pi->link_cfg.autoneg;
  626. if (pi->link_cfg.supported & FW_PORT_CAP_ANEG)
  627. ethtool_link_ksettings_add_link_mode(link_ksettings,
  628. supported, Autoneg);
  629. if (pi->link_cfg.autoneg)
  630. ethtool_link_ksettings_add_link_mode(link_ksettings,
  631. advertising, Autoneg);
  632. return 0;
  633. }
  634. static int set_link_ksettings(struct net_device *dev,
  635. const struct ethtool_link_ksettings
  636. *link_ksettings)
  637. {
  638. struct port_info *pi = netdev_priv(dev);
  639. struct link_config *lc = &pi->link_cfg;
  640. const struct ethtool_link_settings *base = &link_ksettings->base;
  641. struct link_config old_lc;
  642. unsigned int fw_caps;
  643. int ret = 0;
  644. /* only full-duplex supported */
  645. if (base->duplex != DUPLEX_FULL)
  646. return -EINVAL;
  647. if (!(lc->supported & FW_PORT_CAP_ANEG)) {
  648. /* PHY offers a single speed. See if that's what's
  649. * being requested.
  650. */
  651. if (base->autoneg == AUTONEG_DISABLE &&
  652. (lc->supported & speed_to_fw_caps(base->speed)))
  653. return 0;
  654. return -EINVAL;
  655. }
  656. old_lc = *lc;
  657. if (base->autoneg == AUTONEG_DISABLE) {
  658. fw_caps = speed_to_fw_caps(base->speed);
  659. if (!(lc->supported & fw_caps))
  660. return -EINVAL;
  661. lc->requested_speed = fw_caps;
  662. lc->advertising = 0;
  663. } else {
  664. fw_caps =
  665. lmm_to_fw_caps(link_ksettings->link_modes.advertising);
  666. if (!(lc->supported & fw_caps))
  667. return -EINVAL;
  668. lc->requested_speed = 0;
  669. lc->advertising = fw_caps | FW_PORT_CAP_ANEG;
  670. }
  671. lc->autoneg = base->autoneg;
  672. /* If the firmware rejects the Link Configuration request, back out
  673. * the changes and report the error.
  674. */
  675. ret = t4_link_l1cfg(pi->adapter, pi->adapter->mbox, pi->tx_chan, lc);
  676. if (ret)
  677. *lc = old_lc;
  678. return ret;
  679. }
  680. static void get_pauseparam(struct net_device *dev,
  681. struct ethtool_pauseparam *epause)
  682. {
  683. struct port_info *p = netdev_priv(dev);
  684. epause->autoneg = (p->link_cfg.requested_fc & PAUSE_AUTONEG) != 0;
  685. epause->rx_pause = (p->link_cfg.fc & PAUSE_RX) != 0;
  686. epause->tx_pause = (p->link_cfg.fc & PAUSE_TX) != 0;
  687. }
  688. static int set_pauseparam(struct net_device *dev,
  689. struct ethtool_pauseparam *epause)
  690. {
  691. struct port_info *p = netdev_priv(dev);
  692. struct link_config *lc = &p->link_cfg;
  693. if (epause->autoneg == AUTONEG_DISABLE)
  694. lc->requested_fc = 0;
  695. else if (lc->supported & FW_PORT_CAP_ANEG)
  696. lc->requested_fc = PAUSE_AUTONEG;
  697. else
  698. return -EINVAL;
  699. if (epause->rx_pause)
  700. lc->requested_fc |= PAUSE_RX;
  701. if (epause->tx_pause)
  702. lc->requested_fc |= PAUSE_TX;
  703. if (netif_running(dev))
  704. return t4_link_l1cfg(p->adapter, p->adapter->mbox, p->tx_chan,
  705. lc);
  706. return 0;
  707. }
  708. static void get_sge_param(struct net_device *dev, struct ethtool_ringparam *e)
  709. {
  710. const struct port_info *pi = netdev_priv(dev);
  711. const struct sge *s = &pi->adapter->sge;
  712. e->rx_max_pending = MAX_RX_BUFFERS;
  713. e->rx_mini_max_pending = MAX_RSPQ_ENTRIES;
  714. e->rx_jumbo_max_pending = 0;
  715. e->tx_max_pending = MAX_TXQ_ENTRIES;
  716. e->rx_pending = s->ethrxq[pi->first_qset].fl.size - 8;
  717. e->rx_mini_pending = s->ethrxq[pi->first_qset].rspq.size;
  718. e->rx_jumbo_pending = 0;
  719. e->tx_pending = s->ethtxq[pi->first_qset].q.size;
  720. }
  721. static int set_sge_param(struct net_device *dev, struct ethtool_ringparam *e)
  722. {
  723. int i;
  724. const struct port_info *pi = netdev_priv(dev);
  725. struct adapter *adapter = pi->adapter;
  726. struct sge *s = &adapter->sge;
  727. if (e->rx_pending > MAX_RX_BUFFERS || e->rx_jumbo_pending ||
  728. e->tx_pending > MAX_TXQ_ENTRIES ||
  729. e->rx_mini_pending > MAX_RSPQ_ENTRIES ||
  730. e->rx_mini_pending < MIN_RSPQ_ENTRIES ||
  731. e->rx_pending < MIN_FL_ENTRIES || e->tx_pending < MIN_TXQ_ENTRIES)
  732. return -EINVAL;
  733. if (adapter->flags & FULL_INIT_DONE)
  734. return -EBUSY;
  735. for (i = 0; i < pi->nqsets; ++i) {
  736. s->ethtxq[pi->first_qset + i].q.size = e->tx_pending;
  737. s->ethrxq[pi->first_qset + i].fl.size = e->rx_pending + 8;
  738. s->ethrxq[pi->first_qset + i].rspq.size = e->rx_mini_pending;
  739. }
  740. return 0;
  741. }
  742. /**
  743. * set_rx_intr_params - set a net devices's RX interrupt holdoff paramete!
  744. * @dev: the network device
  745. * @us: the hold-off time in us, or 0 to disable timer
  746. * @cnt: the hold-off packet count, or 0 to disable counter
  747. *
  748. * Set the RX interrupt hold-off parameters for a network device.
  749. */
  750. static int set_rx_intr_params(struct net_device *dev,
  751. unsigned int us, unsigned int cnt)
  752. {
  753. int i, err;
  754. struct port_info *pi = netdev_priv(dev);
  755. struct adapter *adap = pi->adapter;
  756. struct sge_eth_rxq *q = &adap->sge.ethrxq[pi->first_qset];
  757. for (i = 0; i < pi->nqsets; i++, q++) {
  758. err = cxgb4_set_rspq_intr_params(&q->rspq, us, cnt);
  759. if (err)
  760. return err;
  761. }
  762. return 0;
  763. }
  764. static int set_adaptive_rx_setting(struct net_device *dev, int adaptive_rx)
  765. {
  766. int i;
  767. struct port_info *pi = netdev_priv(dev);
  768. struct adapter *adap = pi->adapter;
  769. struct sge_eth_rxq *q = &adap->sge.ethrxq[pi->first_qset];
  770. for (i = 0; i < pi->nqsets; i++, q++)
  771. q->rspq.adaptive_rx = adaptive_rx;
  772. return 0;
  773. }
  774. static int get_adaptive_rx_setting(struct net_device *dev)
  775. {
  776. struct port_info *pi = netdev_priv(dev);
  777. struct adapter *adap = pi->adapter;
  778. struct sge_eth_rxq *q = &adap->sge.ethrxq[pi->first_qset];
  779. return q->rspq.adaptive_rx;
  780. }
  781. static int set_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
  782. {
  783. set_adaptive_rx_setting(dev, c->use_adaptive_rx_coalesce);
  784. return set_rx_intr_params(dev, c->rx_coalesce_usecs,
  785. c->rx_max_coalesced_frames);
  786. }
  787. static int get_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
  788. {
  789. const struct port_info *pi = netdev_priv(dev);
  790. const struct adapter *adap = pi->adapter;
  791. const struct sge_rspq *rq = &adap->sge.ethrxq[pi->first_qset].rspq;
  792. c->rx_coalesce_usecs = qtimer_val(adap, rq);
  793. c->rx_max_coalesced_frames = (rq->intr_params & QINTR_CNT_EN_F) ?
  794. adap->sge.counter_val[rq->pktcnt_idx] : 0;
  795. c->use_adaptive_rx_coalesce = get_adaptive_rx_setting(dev);
  796. return 0;
  797. }
  798. /**
  799. * eeprom_ptov - translate a physical EEPROM address to virtual
  800. * @phys_addr: the physical EEPROM address
  801. * @fn: the PCI function number
  802. * @sz: size of function-specific area
  803. *
  804. * Translate a physical EEPROM address to virtual. The first 1K is
  805. * accessed through virtual addresses starting at 31K, the rest is
  806. * accessed through virtual addresses starting at 0.
  807. *
  808. * The mapping is as follows:
  809. * [0..1K) -> [31K..32K)
  810. * [1K..1K+A) -> [31K-A..31K)
  811. * [1K+A..ES) -> [0..ES-A-1K)
  812. *
  813. * where A = @fn * @sz, and ES = EEPROM size.
  814. */
  815. static int eeprom_ptov(unsigned int phys_addr, unsigned int fn, unsigned int sz)
  816. {
  817. fn *= sz;
  818. if (phys_addr < 1024)
  819. return phys_addr + (31 << 10);
  820. if (phys_addr < 1024 + fn)
  821. return 31744 - fn + phys_addr - 1024;
  822. if (phys_addr < EEPROMSIZE)
  823. return phys_addr - 1024 - fn;
  824. return -EINVAL;
  825. }
  826. /* The next two routines implement eeprom read/write from physical addresses.
  827. */
  828. static int eeprom_rd_phys(struct adapter *adap, unsigned int phys_addr, u32 *v)
  829. {
  830. int vaddr = eeprom_ptov(phys_addr, adap->pf, EEPROMPFSIZE);
  831. if (vaddr >= 0)
  832. vaddr = pci_read_vpd(adap->pdev, vaddr, sizeof(u32), v);
  833. return vaddr < 0 ? vaddr : 0;
  834. }
  835. static int eeprom_wr_phys(struct adapter *adap, unsigned int phys_addr, u32 v)
  836. {
  837. int vaddr = eeprom_ptov(phys_addr, adap->pf, EEPROMPFSIZE);
  838. if (vaddr >= 0)
  839. vaddr = pci_write_vpd(adap->pdev, vaddr, sizeof(u32), &v);
  840. return vaddr < 0 ? vaddr : 0;
  841. }
  842. #define EEPROM_MAGIC 0x38E2F10C
  843. static int get_eeprom(struct net_device *dev, struct ethtool_eeprom *e,
  844. u8 *data)
  845. {
  846. int i, err = 0;
  847. struct adapter *adapter = netdev2adap(dev);
  848. u8 *buf = t4_alloc_mem(EEPROMSIZE);
  849. if (!buf)
  850. return -ENOMEM;
  851. e->magic = EEPROM_MAGIC;
  852. for (i = e->offset & ~3; !err && i < e->offset + e->len; i += 4)
  853. err = eeprom_rd_phys(adapter, i, (u32 *)&buf[i]);
  854. if (!err)
  855. memcpy(data, buf + e->offset, e->len);
  856. t4_free_mem(buf);
  857. return err;
  858. }
  859. static int set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  860. u8 *data)
  861. {
  862. u8 *buf;
  863. int err = 0;
  864. u32 aligned_offset, aligned_len, *p;
  865. struct adapter *adapter = netdev2adap(dev);
  866. if (eeprom->magic != EEPROM_MAGIC)
  867. return -EINVAL;
  868. aligned_offset = eeprom->offset & ~3;
  869. aligned_len = (eeprom->len + (eeprom->offset & 3) + 3) & ~3;
  870. if (adapter->pf > 0) {
  871. u32 start = 1024 + adapter->pf * EEPROMPFSIZE;
  872. if (aligned_offset < start ||
  873. aligned_offset + aligned_len > start + EEPROMPFSIZE)
  874. return -EPERM;
  875. }
  876. if (aligned_offset != eeprom->offset || aligned_len != eeprom->len) {
  877. /* RMW possibly needed for first or last words.
  878. */
  879. buf = t4_alloc_mem(aligned_len);
  880. if (!buf)
  881. return -ENOMEM;
  882. err = eeprom_rd_phys(adapter, aligned_offset, (u32 *)buf);
  883. if (!err && aligned_len > 4)
  884. err = eeprom_rd_phys(adapter,
  885. aligned_offset + aligned_len - 4,
  886. (u32 *)&buf[aligned_len - 4]);
  887. if (err)
  888. goto out;
  889. memcpy(buf + (eeprom->offset & 3), data, eeprom->len);
  890. } else {
  891. buf = data;
  892. }
  893. err = t4_seeprom_wp(adapter, false);
  894. if (err)
  895. goto out;
  896. for (p = (u32 *)buf; !err && aligned_len; aligned_len -= 4, p++) {
  897. err = eeprom_wr_phys(adapter, aligned_offset, *p);
  898. aligned_offset += 4;
  899. }
  900. if (!err)
  901. err = t4_seeprom_wp(adapter, true);
  902. out:
  903. if (buf != data)
  904. t4_free_mem(buf);
  905. return err;
  906. }
  907. static int set_flash(struct net_device *netdev, struct ethtool_flash *ef)
  908. {
  909. int ret;
  910. const struct firmware *fw;
  911. struct adapter *adap = netdev2adap(netdev);
  912. unsigned int mbox = PCIE_FW_MASTER_M + 1;
  913. u32 pcie_fw;
  914. unsigned int master;
  915. u8 master_vld = 0;
  916. pcie_fw = t4_read_reg(adap, PCIE_FW_A);
  917. master = PCIE_FW_MASTER_G(pcie_fw);
  918. if (pcie_fw & PCIE_FW_MASTER_VLD_F)
  919. master_vld = 1;
  920. /* if csiostor is the master return */
  921. if (master_vld && (master != adap->pf)) {
  922. dev_warn(adap->pdev_dev,
  923. "cxgb4 driver needs to be loaded as MASTER to support FW flash\n");
  924. return -EOPNOTSUPP;
  925. }
  926. ef->data[sizeof(ef->data) - 1] = '\0';
  927. ret = request_firmware(&fw, ef->data, adap->pdev_dev);
  928. if (ret < 0)
  929. return ret;
  930. /* If the adapter has been fully initialized then we'll go ahead and
  931. * try to get the firmware's cooperation in upgrading to the new
  932. * firmware image otherwise we'll try to do the entire job from the
  933. * host ... and we always "force" the operation in this path.
  934. */
  935. if (adap->flags & FULL_INIT_DONE)
  936. mbox = adap->mbox;
  937. ret = t4_fw_upgrade(adap, mbox, fw->data, fw->size, 1);
  938. release_firmware(fw);
  939. if (!ret)
  940. dev_info(adap->pdev_dev,
  941. "loaded firmware %s, reload cxgb4 driver\n", ef->data);
  942. return ret;
  943. }
  944. static int get_ts_info(struct net_device *dev, struct ethtool_ts_info *ts_info)
  945. {
  946. ts_info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
  947. SOF_TIMESTAMPING_RX_SOFTWARE |
  948. SOF_TIMESTAMPING_SOFTWARE;
  949. ts_info->so_timestamping |= SOF_TIMESTAMPING_RX_HARDWARE |
  950. SOF_TIMESTAMPING_RAW_HARDWARE;
  951. ts_info->phc_index = -1;
  952. return 0;
  953. }
  954. static u32 get_rss_table_size(struct net_device *dev)
  955. {
  956. const struct port_info *pi = netdev_priv(dev);
  957. return pi->rss_size;
  958. }
  959. static int get_rss_table(struct net_device *dev, u32 *p, u8 *key, u8 *hfunc)
  960. {
  961. const struct port_info *pi = netdev_priv(dev);
  962. unsigned int n = pi->rss_size;
  963. if (hfunc)
  964. *hfunc = ETH_RSS_HASH_TOP;
  965. if (!p)
  966. return 0;
  967. while (n--)
  968. p[n] = pi->rss[n];
  969. return 0;
  970. }
  971. static int set_rss_table(struct net_device *dev, const u32 *p, const u8 *key,
  972. const u8 hfunc)
  973. {
  974. unsigned int i;
  975. struct port_info *pi = netdev_priv(dev);
  976. /* We require at least one supported parameter to be changed and no
  977. * change in any of the unsupported parameters
  978. */
  979. if (key ||
  980. (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
  981. return -EOPNOTSUPP;
  982. if (!p)
  983. return 0;
  984. /* Interface must be brought up atleast once */
  985. if (pi->adapter->flags & FULL_INIT_DONE) {
  986. for (i = 0; i < pi->rss_size; i++)
  987. pi->rss[i] = p[i];
  988. return cxgb4_write_rss(pi, pi->rss);
  989. }
  990. return -EPERM;
  991. }
  992. static int get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
  993. u32 *rules)
  994. {
  995. const struct port_info *pi = netdev_priv(dev);
  996. switch (info->cmd) {
  997. case ETHTOOL_GRXFH: {
  998. unsigned int v = pi->rss_mode;
  999. info->data = 0;
  1000. switch (info->flow_type) {
  1001. case TCP_V4_FLOW:
  1002. if (v & FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN_F)
  1003. info->data = RXH_IP_SRC | RXH_IP_DST |
  1004. RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1005. else if (v & FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN_F)
  1006. info->data = RXH_IP_SRC | RXH_IP_DST;
  1007. break;
  1008. case UDP_V4_FLOW:
  1009. if ((v & FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN_F) &&
  1010. (v & FW_RSS_VI_CONFIG_CMD_UDPEN_F))
  1011. info->data = RXH_IP_SRC | RXH_IP_DST |
  1012. RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1013. else if (v & FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN_F)
  1014. info->data = RXH_IP_SRC | RXH_IP_DST;
  1015. break;
  1016. case SCTP_V4_FLOW:
  1017. case AH_ESP_V4_FLOW:
  1018. case IPV4_FLOW:
  1019. if (v & FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN_F)
  1020. info->data = RXH_IP_SRC | RXH_IP_DST;
  1021. break;
  1022. case TCP_V6_FLOW:
  1023. if (v & FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN_F)
  1024. info->data = RXH_IP_SRC | RXH_IP_DST |
  1025. RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1026. else if (v & FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN_F)
  1027. info->data = RXH_IP_SRC | RXH_IP_DST;
  1028. break;
  1029. case UDP_V6_FLOW:
  1030. if ((v & FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN_F) &&
  1031. (v & FW_RSS_VI_CONFIG_CMD_UDPEN_F))
  1032. info->data = RXH_IP_SRC | RXH_IP_DST |
  1033. RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1034. else if (v & FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN_F)
  1035. info->data = RXH_IP_SRC | RXH_IP_DST;
  1036. break;
  1037. case SCTP_V6_FLOW:
  1038. case AH_ESP_V6_FLOW:
  1039. case IPV6_FLOW:
  1040. if (v & FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN_F)
  1041. info->data = RXH_IP_SRC | RXH_IP_DST;
  1042. break;
  1043. }
  1044. return 0;
  1045. }
  1046. case ETHTOOL_GRXRINGS:
  1047. info->data = pi->nqsets;
  1048. return 0;
  1049. }
  1050. return -EOPNOTSUPP;
  1051. }
  1052. static const struct ethtool_ops cxgb_ethtool_ops = {
  1053. .get_link_ksettings = get_link_ksettings,
  1054. .set_link_ksettings = set_link_ksettings,
  1055. .get_drvinfo = get_drvinfo,
  1056. .get_msglevel = get_msglevel,
  1057. .set_msglevel = set_msglevel,
  1058. .get_ringparam = get_sge_param,
  1059. .set_ringparam = set_sge_param,
  1060. .get_coalesce = get_coalesce,
  1061. .set_coalesce = set_coalesce,
  1062. .get_eeprom_len = get_eeprom_len,
  1063. .get_eeprom = get_eeprom,
  1064. .set_eeprom = set_eeprom,
  1065. .get_pauseparam = get_pauseparam,
  1066. .set_pauseparam = set_pauseparam,
  1067. .get_link = ethtool_op_get_link,
  1068. .get_strings = get_strings,
  1069. .set_phys_id = identify_port,
  1070. .nway_reset = restart_autoneg,
  1071. .get_sset_count = get_sset_count,
  1072. .get_ethtool_stats = get_stats,
  1073. .get_regs_len = get_regs_len,
  1074. .get_regs = get_regs,
  1075. .get_rxnfc = get_rxnfc,
  1076. .get_rxfh_indir_size = get_rss_table_size,
  1077. .get_rxfh = get_rss_table,
  1078. .set_rxfh = set_rss_table,
  1079. .flash_device = set_flash,
  1080. .get_ts_info = get_ts_info
  1081. };
  1082. void cxgb4_set_ethtool_ops(struct net_device *netdev)
  1083. {
  1084. netdev->ethtool_ops = &cxgb_ethtool_ops;
  1085. }