cxgb4_ethtool.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547
  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. if (!(lc->pcaps & FW_PORT_CAP32_ANEG)) {
  709. /* PHY offers a single speed. See if that's what's
  710. * being requested.
  711. */
  712. if (base->autoneg == AUTONEG_DISABLE &&
  713. (lc->pcaps & speed_to_fw_caps(base->speed)))
  714. return 0;
  715. return -EINVAL;
  716. }
  717. old_lc = *lc;
  718. if (base->autoneg == AUTONEG_DISABLE) {
  719. fw_caps = speed_to_fw_caps(base->speed);
  720. if (!(lc->pcaps & fw_caps))
  721. return -EINVAL;
  722. lc->speed_caps = fw_caps;
  723. lc->acaps = 0;
  724. } else {
  725. fw_caps =
  726. lmm_to_fw_caps(link_ksettings->link_modes.advertising);
  727. if (!(lc->pcaps & fw_caps))
  728. return -EINVAL;
  729. lc->speed_caps = 0;
  730. lc->acaps = fw_caps | FW_PORT_CAP32_ANEG;
  731. }
  732. lc->autoneg = base->autoneg;
  733. /* If the firmware rejects the Link Configuration request, back out
  734. * the changes and report the error.
  735. */
  736. ret = t4_link_l1cfg(pi->adapter, pi->adapter->mbox, pi->tx_chan, lc);
  737. if (ret)
  738. *lc = old_lc;
  739. return ret;
  740. }
  741. /* Translate the Firmware FEC value into the ethtool value. */
  742. static inline unsigned int fwcap_to_eth_fec(unsigned int fw_fec)
  743. {
  744. unsigned int eth_fec = 0;
  745. if (fw_fec & FW_PORT_CAP32_FEC_RS)
  746. eth_fec |= ETHTOOL_FEC_RS;
  747. if (fw_fec & FW_PORT_CAP32_FEC_BASER_RS)
  748. eth_fec |= ETHTOOL_FEC_BASER;
  749. /* if nothing is set, then FEC is off */
  750. if (!eth_fec)
  751. eth_fec = ETHTOOL_FEC_OFF;
  752. return eth_fec;
  753. }
  754. /* Translate Common Code FEC value into ethtool value. */
  755. static inline unsigned int cc_to_eth_fec(unsigned int cc_fec)
  756. {
  757. unsigned int eth_fec = 0;
  758. if (cc_fec & FEC_AUTO)
  759. eth_fec |= ETHTOOL_FEC_AUTO;
  760. if (cc_fec & FEC_RS)
  761. eth_fec |= ETHTOOL_FEC_RS;
  762. if (cc_fec & FEC_BASER_RS)
  763. eth_fec |= ETHTOOL_FEC_BASER;
  764. /* if nothing is set, then FEC is off */
  765. if (!eth_fec)
  766. eth_fec = ETHTOOL_FEC_OFF;
  767. return eth_fec;
  768. }
  769. /* Translate ethtool FEC value into Common Code value. */
  770. static inline unsigned int eth_to_cc_fec(unsigned int eth_fec)
  771. {
  772. unsigned int cc_fec = 0;
  773. if (eth_fec & ETHTOOL_FEC_OFF)
  774. return cc_fec;
  775. if (eth_fec & ETHTOOL_FEC_AUTO)
  776. cc_fec |= FEC_AUTO;
  777. if (eth_fec & ETHTOOL_FEC_RS)
  778. cc_fec |= FEC_RS;
  779. if (eth_fec & ETHTOOL_FEC_BASER)
  780. cc_fec |= FEC_BASER_RS;
  781. return cc_fec;
  782. }
  783. static int get_fecparam(struct net_device *dev, struct ethtool_fecparam *fec)
  784. {
  785. const struct port_info *pi = netdev_priv(dev);
  786. const struct link_config *lc = &pi->link_cfg;
  787. /* Translate the Firmware FEC Support into the ethtool value. We
  788. * always support IEEE 802.3 "automatic" selection of Link FEC type if
  789. * any FEC is supported.
  790. */
  791. fec->fec = fwcap_to_eth_fec(lc->pcaps);
  792. if (fec->fec != ETHTOOL_FEC_OFF)
  793. fec->fec |= ETHTOOL_FEC_AUTO;
  794. /* Translate the current internal FEC parameters into the
  795. * ethtool values.
  796. */
  797. fec->active_fec = cc_to_eth_fec(lc->fec);
  798. return 0;
  799. }
  800. static int set_fecparam(struct net_device *dev, struct ethtool_fecparam *fec)
  801. {
  802. struct port_info *pi = netdev_priv(dev);
  803. struct link_config *lc = &pi->link_cfg;
  804. struct link_config old_lc;
  805. int ret;
  806. /* Save old Link Configuration in case the L1 Configure below
  807. * fails.
  808. */
  809. old_lc = *lc;
  810. /* Try to perform the L1 Configure and return the result of that
  811. * effort. If it fails, revert the attempted change.
  812. */
  813. lc->requested_fec = eth_to_cc_fec(fec->fec);
  814. ret = t4_link_l1cfg(pi->adapter, pi->adapter->mbox,
  815. pi->tx_chan, lc);
  816. if (ret)
  817. *lc = old_lc;
  818. return ret;
  819. }
  820. static void get_pauseparam(struct net_device *dev,
  821. struct ethtool_pauseparam *epause)
  822. {
  823. struct port_info *p = netdev_priv(dev);
  824. epause->autoneg = (p->link_cfg.requested_fc & PAUSE_AUTONEG) != 0;
  825. epause->rx_pause = (p->link_cfg.fc & PAUSE_RX) != 0;
  826. epause->tx_pause = (p->link_cfg.fc & PAUSE_TX) != 0;
  827. }
  828. static int set_pauseparam(struct net_device *dev,
  829. struct ethtool_pauseparam *epause)
  830. {
  831. struct port_info *p = netdev_priv(dev);
  832. struct link_config *lc = &p->link_cfg;
  833. if (epause->autoneg == AUTONEG_DISABLE)
  834. lc->requested_fc = 0;
  835. else if (lc->pcaps & FW_PORT_CAP32_ANEG)
  836. lc->requested_fc = PAUSE_AUTONEG;
  837. else
  838. return -EINVAL;
  839. if (epause->rx_pause)
  840. lc->requested_fc |= PAUSE_RX;
  841. if (epause->tx_pause)
  842. lc->requested_fc |= PAUSE_TX;
  843. if (netif_running(dev))
  844. return t4_link_l1cfg(p->adapter, p->adapter->mbox, p->tx_chan,
  845. lc);
  846. return 0;
  847. }
  848. static void get_sge_param(struct net_device *dev, struct ethtool_ringparam *e)
  849. {
  850. const struct port_info *pi = netdev_priv(dev);
  851. const struct sge *s = &pi->adapter->sge;
  852. e->rx_max_pending = MAX_RX_BUFFERS;
  853. e->rx_mini_max_pending = MAX_RSPQ_ENTRIES;
  854. e->rx_jumbo_max_pending = 0;
  855. e->tx_max_pending = MAX_TXQ_ENTRIES;
  856. e->rx_pending = s->ethrxq[pi->first_qset].fl.size - 8;
  857. e->rx_mini_pending = s->ethrxq[pi->first_qset].rspq.size;
  858. e->rx_jumbo_pending = 0;
  859. e->tx_pending = s->ethtxq[pi->first_qset].q.size;
  860. }
  861. static int set_sge_param(struct net_device *dev, struct ethtool_ringparam *e)
  862. {
  863. int i;
  864. const struct port_info *pi = netdev_priv(dev);
  865. struct adapter *adapter = pi->adapter;
  866. struct sge *s = &adapter->sge;
  867. if (e->rx_pending > MAX_RX_BUFFERS || e->rx_jumbo_pending ||
  868. e->tx_pending > MAX_TXQ_ENTRIES ||
  869. e->rx_mini_pending > MAX_RSPQ_ENTRIES ||
  870. e->rx_mini_pending < MIN_RSPQ_ENTRIES ||
  871. e->rx_pending < MIN_FL_ENTRIES || e->tx_pending < MIN_TXQ_ENTRIES)
  872. return -EINVAL;
  873. if (adapter->flags & FULL_INIT_DONE)
  874. return -EBUSY;
  875. for (i = 0; i < pi->nqsets; ++i) {
  876. s->ethtxq[pi->first_qset + i].q.size = e->tx_pending;
  877. s->ethrxq[pi->first_qset + i].fl.size = e->rx_pending + 8;
  878. s->ethrxq[pi->first_qset + i].rspq.size = e->rx_mini_pending;
  879. }
  880. return 0;
  881. }
  882. /**
  883. * set_rx_intr_params - set a net devices's RX interrupt holdoff paramete!
  884. * @dev: the network device
  885. * @us: the hold-off time in us, or 0 to disable timer
  886. * @cnt: the hold-off packet count, or 0 to disable counter
  887. *
  888. * Set the RX interrupt hold-off parameters for a network device.
  889. */
  890. static int set_rx_intr_params(struct net_device *dev,
  891. unsigned int us, unsigned int cnt)
  892. {
  893. int i, err;
  894. struct port_info *pi = netdev_priv(dev);
  895. struct adapter *adap = pi->adapter;
  896. struct sge_eth_rxq *q = &adap->sge.ethrxq[pi->first_qset];
  897. for (i = 0; i < pi->nqsets; i++, q++) {
  898. err = cxgb4_set_rspq_intr_params(&q->rspq, us, cnt);
  899. if (err)
  900. return err;
  901. }
  902. return 0;
  903. }
  904. static int set_adaptive_rx_setting(struct net_device *dev, int adaptive_rx)
  905. {
  906. int i;
  907. struct port_info *pi = netdev_priv(dev);
  908. struct adapter *adap = pi->adapter;
  909. struct sge_eth_rxq *q = &adap->sge.ethrxq[pi->first_qset];
  910. for (i = 0; i < pi->nqsets; i++, q++)
  911. q->rspq.adaptive_rx = adaptive_rx;
  912. return 0;
  913. }
  914. static int get_adaptive_rx_setting(struct net_device *dev)
  915. {
  916. struct port_info *pi = netdev_priv(dev);
  917. struct adapter *adap = pi->adapter;
  918. struct sge_eth_rxq *q = &adap->sge.ethrxq[pi->first_qset];
  919. return q->rspq.adaptive_rx;
  920. }
  921. static int set_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
  922. {
  923. set_adaptive_rx_setting(dev, c->use_adaptive_rx_coalesce);
  924. return set_rx_intr_params(dev, c->rx_coalesce_usecs,
  925. c->rx_max_coalesced_frames);
  926. }
  927. static int get_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
  928. {
  929. const struct port_info *pi = netdev_priv(dev);
  930. const struct adapter *adap = pi->adapter;
  931. const struct sge_rspq *rq = &adap->sge.ethrxq[pi->first_qset].rspq;
  932. c->rx_coalesce_usecs = qtimer_val(adap, rq);
  933. c->rx_max_coalesced_frames = (rq->intr_params & QINTR_CNT_EN_F) ?
  934. adap->sge.counter_val[rq->pktcnt_idx] : 0;
  935. c->use_adaptive_rx_coalesce = get_adaptive_rx_setting(dev);
  936. return 0;
  937. }
  938. /* The next two routines implement eeprom read/write from physical addresses.
  939. */
  940. static int eeprom_rd_phys(struct adapter *adap, unsigned int phys_addr, u32 *v)
  941. {
  942. int vaddr = t4_eeprom_ptov(phys_addr, adap->pf, EEPROMPFSIZE);
  943. if (vaddr >= 0)
  944. vaddr = pci_read_vpd(adap->pdev, vaddr, sizeof(u32), v);
  945. return vaddr < 0 ? vaddr : 0;
  946. }
  947. static int eeprom_wr_phys(struct adapter *adap, unsigned int phys_addr, u32 v)
  948. {
  949. int vaddr = t4_eeprom_ptov(phys_addr, adap->pf, EEPROMPFSIZE);
  950. if (vaddr >= 0)
  951. vaddr = pci_write_vpd(adap->pdev, vaddr, sizeof(u32), &v);
  952. return vaddr < 0 ? vaddr : 0;
  953. }
  954. #define EEPROM_MAGIC 0x38E2F10C
  955. static int get_eeprom(struct net_device *dev, struct ethtool_eeprom *e,
  956. u8 *data)
  957. {
  958. int i, err = 0;
  959. struct adapter *adapter = netdev2adap(dev);
  960. u8 *buf = kvzalloc(EEPROMSIZE, GFP_KERNEL);
  961. if (!buf)
  962. return -ENOMEM;
  963. e->magic = EEPROM_MAGIC;
  964. for (i = e->offset & ~3; !err && i < e->offset + e->len; i += 4)
  965. err = eeprom_rd_phys(adapter, i, (u32 *)&buf[i]);
  966. if (!err)
  967. memcpy(data, buf + e->offset, e->len);
  968. kvfree(buf);
  969. return err;
  970. }
  971. static int set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  972. u8 *data)
  973. {
  974. u8 *buf;
  975. int err = 0;
  976. u32 aligned_offset, aligned_len, *p;
  977. struct adapter *adapter = netdev2adap(dev);
  978. if (eeprom->magic != EEPROM_MAGIC)
  979. return -EINVAL;
  980. aligned_offset = eeprom->offset & ~3;
  981. aligned_len = (eeprom->len + (eeprom->offset & 3) + 3) & ~3;
  982. if (adapter->pf > 0) {
  983. u32 start = 1024 + adapter->pf * EEPROMPFSIZE;
  984. if (aligned_offset < start ||
  985. aligned_offset + aligned_len > start + EEPROMPFSIZE)
  986. return -EPERM;
  987. }
  988. if (aligned_offset != eeprom->offset || aligned_len != eeprom->len) {
  989. /* RMW possibly needed for first or last words.
  990. */
  991. buf = kvzalloc(aligned_len, GFP_KERNEL);
  992. if (!buf)
  993. return -ENOMEM;
  994. err = eeprom_rd_phys(adapter, aligned_offset, (u32 *)buf);
  995. if (!err && aligned_len > 4)
  996. err = eeprom_rd_phys(adapter,
  997. aligned_offset + aligned_len - 4,
  998. (u32 *)&buf[aligned_len - 4]);
  999. if (err)
  1000. goto out;
  1001. memcpy(buf + (eeprom->offset & 3), data, eeprom->len);
  1002. } else {
  1003. buf = data;
  1004. }
  1005. err = t4_seeprom_wp(adapter, false);
  1006. if (err)
  1007. goto out;
  1008. for (p = (u32 *)buf; !err && aligned_len; aligned_len -= 4, p++) {
  1009. err = eeprom_wr_phys(adapter, aligned_offset, *p);
  1010. aligned_offset += 4;
  1011. }
  1012. if (!err)
  1013. err = t4_seeprom_wp(adapter, true);
  1014. out:
  1015. if (buf != data)
  1016. kvfree(buf);
  1017. return err;
  1018. }
  1019. static int set_flash(struct net_device *netdev, struct ethtool_flash *ef)
  1020. {
  1021. int ret;
  1022. const struct firmware *fw;
  1023. struct adapter *adap = netdev2adap(netdev);
  1024. unsigned int mbox = PCIE_FW_MASTER_M + 1;
  1025. u32 pcie_fw;
  1026. unsigned int master;
  1027. u8 master_vld = 0;
  1028. pcie_fw = t4_read_reg(adap, PCIE_FW_A);
  1029. master = PCIE_FW_MASTER_G(pcie_fw);
  1030. if (pcie_fw & PCIE_FW_MASTER_VLD_F)
  1031. master_vld = 1;
  1032. /* if csiostor is the master return */
  1033. if (master_vld && (master != adap->pf)) {
  1034. dev_warn(adap->pdev_dev,
  1035. "cxgb4 driver needs to be loaded as MASTER to support FW flash\n");
  1036. return -EOPNOTSUPP;
  1037. }
  1038. ef->data[sizeof(ef->data) - 1] = '\0';
  1039. ret = request_firmware(&fw, ef->data, adap->pdev_dev);
  1040. if (ret < 0)
  1041. return ret;
  1042. /* If the adapter has been fully initialized then we'll go ahead and
  1043. * try to get the firmware's cooperation in upgrading to the new
  1044. * firmware image otherwise we'll try to do the entire job from the
  1045. * host ... and we always "force" the operation in this path.
  1046. */
  1047. if (adap->flags & FULL_INIT_DONE)
  1048. mbox = adap->mbox;
  1049. ret = t4_fw_upgrade(adap, mbox, fw->data, fw->size, 1);
  1050. release_firmware(fw);
  1051. if (!ret)
  1052. dev_info(adap->pdev_dev,
  1053. "loaded firmware %s, reload cxgb4 driver\n", ef->data);
  1054. return ret;
  1055. }
  1056. static int get_ts_info(struct net_device *dev, struct ethtool_ts_info *ts_info)
  1057. {
  1058. struct port_info *pi = netdev_priv(dev);
  1059. struct adapter *adapter = pi->adapter;
  1060. ts_info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
  1061. SOF_TIMESTAMPING_RX_SOFTWARE |
  1062. SOF_TIMESTAMPING_SOFTWARE;
  1063. ts_info->so_timestamping |= SOF_TIMESTAMPING_RX_HARDWARE |
  1064. SOF_TIMESTAMPING_TX_HARDWARE |
  1065. SOF_TIMESTAMPING_RAW_HARDWARE;
  1066. ts_info->tx_types = (1 << HWTSTAMP_TX_OFF) |
  1067. (1 << HWTSTAMP_TX_ON);
  1068. ts_info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
  1069. (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
  1070. (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
  1071. (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
  1072. (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
  1073. (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
  1074. if (adapter->ptp_clock)
  1075. ts_info->phc_index = ptp_clock_index(adapter->ptp_clock);
  1076. else
  1077. ts_info->phc_index = -1;
  1078. return 0;
  1079. }
  1080. static u32 get_rss_table_size(struct net_device *dev)
  1081. {
  1082. const struct port_info *pi = netdev_priv(dev);
  1083. return pi->rss_size;
  1084. }
  1085. static int get_rss_table(struct net_device *dev, u32 *p, u8 *key, u8 *hfunc)
  1086. {
  1087. const struct port_info *pi = netdev_priv(dev);
  1088. unsigned int n = pi->rss_size;
  1089. if (hfunc)
  1090. *hfunc = ETH_RSS_HASH_TOP;
  1091. if (!p)
  1092. return 0;
  1093. while (n--)
  1094. p[n] = pi->rss[n];
  1095. return 0;
  1096. }
  1097. static int set_rss_table(struct net_device *dev, const u32 *p, const u8 *key,
  1098. const u8 hfunc)
  1099. {
  1100. unsigned int i;
  1101. struct port_info *pi = netdev_priv(dev);
  1102. /* We require at least one supported parameter to be changed and no
  1103. * change in any of the unsupported parameters
  1104. */
  1105. if (key ||
  1106. (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
  1107. return -EOPNOTSUPP;
  1108. if (!p)
  1109. return 0;
  1110. /* Interface must be brought up atleast once */
  1111. if (pi->adapter->flags & FULL_INIT_DONE) {
  1112. for (i = 0; i < pi->rss_size; i++)
  1113. pi->rss[i] = p[i];
  1114. return cxgb4_write_rss(pi, pi->rss);
  1115. }
  1116. return -EPERM;
  1117. }
  1118. static int get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
  1119. u32 *rules)
  1120. {
  1121. const struct port_info *pi = netdev_priv(dev);
  1122. switch (info->cmd) {
  1123. case ETHTOOL_GRXFH: {
  1124. unsigned int v = pi->rss_mode;
  1125. info->data = 0;
  1126. switch (info->flow_type) {
  1127. case TCP_V4_FLOW:
  1128. if (v & FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN_F)
  1129. info->data = RXH_IP_SRC | RXH_IP_DST |
  1130. RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1131. else if (v & FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN_F)
  1132. info->data = RXH_IP_SRC | RXH_IP_DST;
  1133. break;
  1134. case UDP_V4_FLOW:
  1135. if ((v & FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN_F) &&
  1136. (v & FW_RSS_VI_CONFIG_CMD_UDPEN_F))
  1137. info->data = RXH_IP_SRC | RXH_IP_DST |
  1138. RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1139. else if (v & FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN_F)
  1140. info->data = RXH_IP_SRC | RXH_IP_DST;
  1141. break;
  1142. case SCTP_V4_FLOW:
  1143. case AH_ESP_V4_FLOW:
  1144. case IPV4_FLOW:
  1145. if (v & FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN_F)
  1146. info->data = RXH_IP_SRC | RXH_IP_DST;
  1147. break;
  1148. case TCP_V6_FLOW:
  1149. if (v & FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN_F)
  1150. info->data = RXH_IP_SRC | RXH_IP_DST |
  1151. RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1152. else if (v & FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN_F)
  1153. info->data = RXH_IP_SRC | RXH_IP_DST;
  1154. break;
  1155. case UDP_V6_FLOW:
  1156. if ((v & FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN_F) &&
  1157. (v & FW_RSS_VI_CONFIG_CMD_UDPEN_F))
  1158. info->data = RXH_IP_SRC | RXH_IP_DST |
  1159. RXH_L4_B_0_1 | RXH_L4_B_2_3;
  1160. else if (v & FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN_F)
  1161. info->data = RXH_IP_SRC | RXH_IP_DST;
  1162. break;
  1163. case SCTP_V6_FLOW:
  1164. case AH_ESP_V6_FLOW:
  1165. case IPV6_FLOW:
  1166. if (v & FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN_F)
  1167. info->data = RXH_IP_SRC | RXH_IP_DST;
  1168. break;
  1169. }
  1170. return 0;
  1171. }
  1172. case ETHTOOL_GRXRINGS:
  1173. info->data = pi->nqsets;
  1174. return 0;
  1175. }
  1176. return -EOPNOTSUPP;
  1177. }
  1178. static int set_dump(struct net_device *dev, struct ethtool_dump *eth_dump)
  1179. {
  1180. struct adapter *adapter = netdev2adap(dev);
  1181. u32 len = 0;
  1182. len = sizeof(struct cudbg_hdr) +
  1183. sizeof(struct cudbg_entity_hdr) * CUDBG_MAX_ENTITY;
  1184. len += cxgb4_get_dump_length(adapter, eth_dump->flag);
  1185. adapter->eth_dump.flag = eth_dump->flag;
  1186. adapter->eth_dump.len = len;
  1187. return 0;
  1188. }
  1189. static int get_dump_flag(struct net_device *dev, struct ethtool_dump *eth_dump)
  1190. {
  1191. struct adapter *adapter = netdev2adap(dev);
  1192. eth_dump->flag = adapter->eth_dump.flag;
  1193. eth_dump->len = adapter->eth_dump.len;
  1194. eth_dump->version = adapter->eth_dump.version;
  1195. return 0;
  1196. }
  1197. static int get_dump_data(struct net_device *dev, struct ethtool_dump *eth_dump,
  1198. void *buf)
  1199. {
  1200. struct adapter *adapter = netdev2adap(dev);
  1201. u32 len = 0;
  1202. int ret = 0;
  1203. if (adapter->eth_dump.flag == CXGB4_ETH_DUMP_NONE)
  1204. return -ENOENT;
  1205. len = sizeof(struct cudbg_hdr) +
  1206. sizeof(struct cudbg_entity_hdr) * CUDBG_MAX_ENTITY;
  1207. len += cxgb4_get_dump_length(adapter, adapter->eth_dump.flag);
  1208. if (eth_dump->len < len)
  1209. return -ENOMEM;
  1210. ret = cxgb4_cudbg_collect(adapter, buf, &len, adapter->eth_dump.flag);
  1211. if (ret)
  1212. return ret;
  1213. eth_dump->flag = adapter->eth_dump.flag;
  1214. eth_dump->len = len;
  1215. eth_dump->version = adapter->eth_dump.version;
  1216. return 0;
  1217. }
  1218. static int cxgb4_get_module_info(struct net_device *dev,
  1219. struct ethtool_modinfo *modinfo)
  1220. {
  1221. struct port_info *pi = netdev_priv(dev);
  1222. u8 sff8472_comp, sff_diag_type, sff_rev;
  1223. struct adapter *adapter = pi->adapter;
  1224. int ret;
  1225. if (!t4_is_inserted_mod_type(pi->mod_type))
  1226. return -EINVAL;
  1227. switch (pi->port_type) {
  1228. case FW_PORT_TYPE_SFP:
  1229. case FW_PORT_TYPE_QSA:
  1230. case FW_PORT_TYPE_SFP28:
  1231. ret = t4_i2c_rd(adapter, adapter->mbox, pi->tx_chan,
  1232. I2C_DEV_ADDR_A0, SFF_8472_COMP_ADDR,
  1233. SFF_8472_COMP_LEN, &sff8472_comp);
  1234. if (ret)
  1235. return ret;
  1236. ret = t4_i2c_rd(adapter, adapter->mbox, pi->tx_chan,
  1237. I2C_DEV_ADDR_A0, SFP_DIAG_TYPE_ADDR,
  1238. SFP_DIAG_TYPE_LEN, &sff_diag_type);
  1239. if (ret)
  1240. return ret;
  1241. if (!sff8472_comp || (sff_diag_type & 4)) {
  1242. modinfo->type = ETH_MODULE_SFF_8079;
  1243. modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
  1244. } else {
  1245. modinfo->type = ETH_MODULE_SFF_8472;
  1246. modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
  1247. }
  1248. break;
  1249. case FW_PORT_TYPE_QSFP:
  1250. case FW_PORT_TYPE_QSFP_10G:
  1251. case FW_PORT_TYPE_CR_QSFP:
  1252. case FW_PORT_TYPE_CR2_QSFP:
  1253. case FW_PORT_TYPE_CR4_QSFP:
  1254. ret = t4_i2c_rd(adapter, adapter->mbox, pi->tx_chan,
  1255. I2C_DEV_ADDR_A0, SFF_REV_ADDR,
  1256. SFF_REV_LEN, &sff_rev);
  1257. /* For QSFP type ports, revision value >= 3
  1258. * means the SFP is 8636 compliant.
  1259. */
  1260. if (ret)
  1261. return ret;
  1262. if (sff_rev >= 0x3) {
  1263. modinfo->type = ETH_MODULE_SFF_8636;
  1264. modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN;
  1265. } else {
  1266. modinfo->type = ETH_MODULE_SFF_8436;
  1267. modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
  1268. }
  1269. break;
  1270. default:
  1271. return -EINVAL;
  1272. }
  1273. return 0;
  1274. }
  1275. static int cxgb4_get_module_eeprom(struct net_device *dev,
  1276. struct ethtool_eeprom *eprom, u8 *data)
  1277. {
  1278. int ret = 0, offset = eprom->offset, len = eprom->len;
  1279. struct port_info *pi = netdev_priv(dev);
  1280. struct adapter *adapter = pi->adapter;
  1281. memset(data, 0, eprom->len);
  1282. if (offset + len <= I2C_PAGE_SIZE)
  1283. return t4_i2c_rd(adapter, adapter->mbox, pi->tx_chan,
  1284. I2C_DEV_ADDR_A0, offset, len, data);
  1285. /* offset + len spans 0xa0 and 0xa1 pages */
  1286. if (offset <= I2C_PAGE_SIZE) {
  1287. /* read 0xa0 page */
  1288. len = I2C_PAGE_SIZE - offset;
  1289. ret = t4_i2c_rd(adapter, adapter->mbox, pi->tx_chan,
  1290. I2C_DEV_ADDR_A0, offset, len, data);
  1291. if (ret)
  1292. return ret;
  1293. offset = I2C_PAGE_SIZE;
  1294. /* Remaining bytes to be read from second page =
  1295. * Total length - bytes read from first page
  1296. */
  1297. len = eprom->len - len;
  1298. }
  1299. /* Read additional optical diagnostics from page 0xa2 if supported */
  1300. return t4_i2c_rd(adapter, adapter->mbox, pi->tx_chan, I2C_DEV_ADDR_A2,
  1301. offset, len, &data[eprom->len - len]);
  1302. }
  1303. static const struct ethtool_ops cxgb_ethtool_ops = {
  1304. .get_link_ksettings = get_link_ksettings,
  1305. .set_link_ksettings = set_link_ksettings,
  1306. .get_fecparam = get_fecparam,
  1307. .set_fecparam = set_fecparam,
  1308. .get_drvinfo = get_drvinfo,
  1309. .get_msglevel = get_msglevel,
  1310. .set_msglevel = set_msglevel,
  1311. .get_ringparam = get_sge_param,
  1312. .set_ringparam = set_sge_param,
  1313. .get_coalesce = get_coalesce,
  1314. .set_coalesce = set_coalesce,
  1315. .get_eeprom_len = get_eeprom_len,
  1316. .get_eeprom = get_eeprom,
  1317. .set_eeprom = set_eeprom,
  1318. .get_pauseparam = get_pauseparam,
  1319. .set_pauseparam = set_pauseparam,
  1320. .get_link = ethtool_op_get_link,
  1321. .get_strings = get_strings,
  1322. .set_phys_id = identify_port,
  1323. .nway_reset = restart_autoneg,
  1324. .get_sset_count = get_sset_count,
  1325. .get_ethtool_stats = get_stats,
  1326. .get_regs_len = get_regs_len,
  1327. .get_regs = get_regs,
  1328. .get_rxnfc = get_rxnfc,
  1329. .get_rxfh_indir_size = get_rss_table_size,
  1330. .get_rxfh = get_rss_table,
  1331. .set_rxfh = set_rss_table,
  1332. .flash_device = set_flash,
  1333. .get_ts_info = get_ts_info,
  1334. .set_dump = set_dump,
  1335. .get_dump_flag = get_dump_flag,
  1336. .get_dump_data = get_dump_data,
  1337. .get_module_info = cxgb4_get_module_info,
  1338. .get_module_eeprom = cxgb4_get_module_eeprom,
  1339. };
  1340. void cxgb4_set_ethtool_ops(struct net_device *netdev)
  1341. {
  1342. netdev->ethtool_ops = &cxgb_ethtool_ops;
  1343. }