ef100_nic.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /****************************************************************************
  3. * Driver for Solarflare network controllers and boards
  4. * Copyright 2018 Solarflare Communications Inc.
  5. * Copyright 2019-2022 Xilinx Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published
  9. * by the Free Software Foundation, incorporated herein by reference.
  10. */
  11. #include "ef100_nic.h"
  12. #include "efx_common.h"
  13. #include "efx_channels.h"
  14. #include "io.h"
  15. #include "selftest.h"
  16. #include "ef100_regs.h"
  17. #include "mcdi.h"
  18. #include "mcdi_pcol.h"
  19. #include "mcdi_port_common.h"
  20. #include "mcdi_functions.h"
  21. #include "mcdi_filters.h"
  22. #include "ef100_rx.h"
  23. #include "ef100_tx.h"
  24. #include "ef100_sriov.h"
  25. #include "ef100_netdev.h"
  26. #include "tc.h"
  27. #include "mae.h"
  28. #include "rx_common.h"
  29. #define EF100_MAX_VIS 4096
  30. #define EF100_NUM_MCDI_BUFFERS 1
  31. #define MCDI_BUF_LEN (8 + MCDI_CTL_SDU_LEN_MAX)
  32. #define EF100_RESET_PORT ((ETH_RESET_MAC | ETH_RESET_PHY) << ETH_RESET_SHARED_SHIFT)
  33. /* MCDI
  34. */
  35. static u8 *ef100_mcdi_buf(struct efx_nic *efx, u8 bufid, dma_addr_t *dma_addr)
  36. {
  37. struct ef100_nic_data *nic_data = efx->nic_data;
  38. if (dma_addr)
  39. *dma_addr = nic_data->mcdi_buf.dma_addr +
  40. bufid * ALIGN(MCDI_BUF_LEN, 256);
  41. return nic_data->mcdi_buf.addr + bufid * ALIGN(MCDI_BUF_LEN, 256);
  42. }
  43. static int ef100_get_warm_boot_count(struct efx_nic *efx)
  44. {
  45. efx_dword_t reg;
  46. efx_readd(efx, &reg, efx_reg(efx, ER_GZ_MC_SFT_STATUS));
  47. if (EFX_DWORD_FIELD(reg, EFX_DWORD_0) == 0xffffffff) {
  48. netif_err(efx, hw, efx->net_dev, "Hardware unavailable\n");
  49. efx->state = STATE_DISABLED;
  50. return -ENETDOWN;
  51. } else {
  52. return EFX_DWORD_FIELD(reg, EFX_WORD_1) == 0xb007 ?
  53. EFX_DWORD_FIELD(reg, EFX_WORD_0) : -EIO;
  54. }
  55. }
  56. static void ef100_mcdi_request(struct efx_nic *efx,
  57. const efx_dword_t *hdr, size_t hdr_len,
  58. const efx_dword_t *sdu, size_t sdu_len)
  59. {
  60. dma_addr_t dma_addr;
  61. u8 *pdu = ef100_mcdi_buf(efx, 0, &dma_addr);
  62. memcpy(pdu, hdr, hdr_len);
  63. memcpy(pdu + hdr_len, sdu, sdu_len);
  64. wmb();
  65. /* The hardware provides 'low' and 'high' (doorbell) registers
  66. * for passing the 64-bit address of an MCDI request to
  67. * firmware. However the dwords are swapped by firmware. The
  68. * least significant bits of the doorbell are then 0 for all
  69. * MCDI requests due to alignment.
  70. */
  71. _efx_writed(efx, cpu_to_le32((u64)dma_addr >> 32), efx_reg(efx, ER_GZ_MC_DB_LWRD));
  72. _efx_writed(efx, cpu_to_le32((u32)dma_addr), efx_reg(efx, ER_GZ_MC_DB_HWRD));
  73. }
  74. static bool ef100_mcdi_poll_response(struct efx_nic *efx)
  75. {
  76. const efx_dword_t hdr =
  77. *(const efx_dword_t *)(ef100_mcdi_buf(efx, 0, NULL));
  78. rmb();
  79. return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE);
  80. }
  81. static void ef100_mcdi_read_response(struct efx_nic *efx,
  82. efx_dword_t *outbuf, size_t offset,
  83. size_t outlen)
  84. {
  85. const u8 *pdu = ef100_mcdi_buf(efx, 0, NULL);
  86. memcpy(outbuf, pdu + offset, outlen);
  87. }
  88. static int ef100_mcdi_poll_reboot(struct efx_nic *efx)
  89. {
  90. struct ef100_nic_data *nic_data = efx->nic_data;
  91. int rc;
  92. rc = ef100_get_warm_boot_count(efx);
  93. if (rc < 0) {
  94. /* The firmware is presumably in the process of
  95. * rebooting. However, we are supposed to report each
  96. * reboot just once, so we must only do that once we
  97. * can read and store the updated warm boot count.
  98. */
  99. return 0;
  100. }
  101. if (rc == nic_data->warm_boot_count)
  102. return 0;
  103. nic_data->warm_boot_count = rc;
  104. return -EIO;
  105. }
  106. static void ef100_mcdi_reboot_detected(struct efx_nic *efx)
  107. {
  108. }
  109. /* MCDI calls
  110. */
  111. int ef100_get_mac_address(struct efx_nic *efx, u8 *mac_address,
  112. int client_handle, bool empty_ok)
  113. {
  114. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLIENT_MAC_ADDRESSES_OUT_LEN(1));
  115. MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_CLIENT_MAC_ADDRESSES_IN_LEN);
  116. size_t outlen;
  117. int rc;
  118. BUILD_BUG_ON(MC_CMD_GET_MAC_ADDRESSES_IN_LEN != 0);
  119. MCDI_SET_DWORD(inbuf, GET_CLIENT_MAC_ADDRESSES_IN_CLIENT_HANDLE,
  120. client_handle);
  121. rc = efx_mcdi_rpc(efx, MC_CMD_GET_CLIENT_MAC_ADDRESSES, inbuf,
  122. sizeof(inbuf), outbuf, sizeof(outbuf), &outlen);
  123. if (rc)
  124. return rc;
  125. if (outlen >= MC_CMD_GET_CLIENT_MAC_ADDRESSES_OUT_LEN(1)) {
  126. ether_addr_copy(mac_address,
  127. MCDI_PTR(outbuf, GET_CLIENT_MAC_ADDRESSES_OUT_MAC_ADDRS));
  128. } else if (empty_ok) {
  129. pci_warn(efx->pci_dev,
  130. "No MAC address provisioned for client ID %#x.\n",
  131. client_handle);
  132. eth_zero_addr(mac_address);
  133. } else {
  134. return -ENOENT;
  135. }
  136. return 0;
  137. }
  138. int efx_ef100_init_datapath_caps(struct efx_nic *efx)
  139. {
  140. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CAPABILITIES_V7_OUT_LEN);
  141. struct ef100_nic_data *nic_data = efx->nic_data;
  142. u8 vi_window_mode;
  143. size_t outlen;
  144. int rc;
  145. BUILD_BUG_ON(MC_CMD_GET_CAPABILITIES_IN_LEN != 0);
  146. rc = efx_mcdi_rpc(efx, MC_CMD_GET_CAPABILITIES, NULL, 0,
  147. outbuf, sizeof(outbuf), &outlen);
  148. if (rc)
  149. return rc;
  150. if (outlen < MC_CMD_GET_CAPABILITIES_V4_OUT_LEN) {
  151. netif_err(efx, drv, efx->net_dev,
  152. "unable to read datapath firmware capabilities\n");
  153. return -EIO;
  154. }
  155. nic_data->datapath_caps = MCDI_DWORD(outbuf,
  156. GET_CAPABILITIES_OUT_FLAGS1);
  157. nic_data->datapath_caps2 = MCDI_DWORD(outbuf,
  158. GET_CAPABILITIES_V2_OUT_FLAGS2);
  159. if (outlen < MC_CMD_GET_CAPABILITIES_V7_OUT_LEN)
  160. nic_data->datapath_caps3 = 0;
  161. else
  162. nic_data->datapath_caps3 = MCDI_DWORD(outbuf,
  163. GET_CAPABILITIES_V7_OUT_FLAGS3);
  164. vi_window_mode = MCDI_BYTE(outbuf,
  165. GET_CAPABILITIES_V3_OUT_VI_WINDOW_MODE);
  166. rc = efx_mcdi_window_mode_to_stride(efx, vi_window_mode);
  167. if (rc)
  168. return rc;
  169. if (efx_ef100_has_cap(nic_data->datapath_caps2, TX_TSO_V3)) {
  170. struct net_device *net_dev = efx->net_dev;
  171. netdev_features_t tso = NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_GSO_PARTIAL |
  172. NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_UDP_TUNNEL_CSUM |
  173. NETIF_F_GSO_GRE | NETIF_F_GSO_GRE_CSUM;
  174. net_dev->features |= tso;
  175. net_dev->hw_features |= tso;
  176. net_dev->hw_enc_features |= tso;
  177. /* EF100 HW can only offload outer checksums if they are UDP,
  178. * so for GRE_CSUM we have to use GSO_PARTIAL.
  179. */
  180. net_dev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM;
  181. }
  182. efx->num_mac_stats = MCDI_WORD(outbuf,
  183. GET_CAPABILITIES_V4_OUT_MAC_STATS_NUM_STATS);
  184. netif_dbg(efx, probe, efx->net_dev,
  185. "firmware reports num_mac_stats = %u\n",
  186. efx->num_mac_stats);
  187. return 0;
  188. }
  189. /* Event handling
  190. */
  191. static int ef100_ev_probe(struct efx_channel *channel)
  192. {
  193. /* Allocate an extra descriptor for the QMDA status completion entry */
  194. return efx_nic_alloc_buffer(channel->efx, &channel->eventq,
  195. (channel->eventq_mask + 2) *
  196. sizeof(efx_qword_t),
  197. GFP_KERNEL);
  198. }
  199. static int ef100_ev_init(struct efx_channel *channel)
  200. {
  201. struct ef100_nic_data *nic_data = channel->efx->nic_data;
  202. /* initial phase is 0 */
  203. clear_bit(channel->channel, nic_data->evq_phases);
  204. return efx_mcdi_ev_init(channel, false, false);
  205. }
  206. static void ef100_ev_read_ack(struct efx_channel *channel)
  207. {
  208. efx_dword_t evq_prime;
  209. EFX_POPULATE_DWORD_2(evq_prime,
  210. ERF_GZ_EVQ_ID, channel->channel,
  211. ERF_GZ_IDX, channel->eventq_read_ptr &
  212. channel->eventq_mask);
  213. efx_writed(channel->efx, &evq_prime,
  214. efx_reg(channel->efx, ER_GZ_EVQ_INT_PRIME));
  215. }
  216. #define EFX_NAPI_MAX_TX 512
  217. static int ef100_ev_process(struct efx_channel *channel, int quota)
  218. {
  219. struct efx_nic *efx = channel->efx;
  220. struct ef100_nic_data *nic_data;
  221. bool evq_phase, old_evq_phase;
  222. unsigned int read_ptr;
  223. efx_qword_t *p_event;
  224. int spent_tx = 0;
  225. int spent = 0;
  226. bool ev_phase;
  227. int ev_type;
  228. if (unlikely(!channel->enabled))
  229. return 0;
  230. nic_data = efx->nic_data;
  231. evq_phase = test_bit(channel->channel, nic_data->evq_phases);
  232. old_evq_phase = evq_phase;
  233. read_ptr = channel->eventq_read_ptr;
  234. BUILD_BUG_ON(ESF_GZ_EV_RXPKTS_PHASE_LBN != ESF_GZ_EV_TXCMPL_PHASE_LBN);
  235. while (spent < quota) {
  236. p_event = efx_event(channel, read_ptr);
  237. ev_phase = !!EFX_QWORD_FIELD(*p_event, ESF_GZ_EV_RXPKTS_PHASE);
  238. if (ev_phase != evq_phase)
  239. break;
  240. netif_vdbg(efx, drv, efx->net_dev,
  241. "processing event on %d " EFX_QWORD_FMT "\n",
  242. channel->channel, EFX_QWORD_VAL(*p_event));
  243. ev_type = EFX_QWORD_FIELD(*p_event, ESF_GZ_E_TYPE);
  244. switch (ev_type) {
  245. case ESE_GZ_EF100_EV_RX_PKTS:
  246. efx_ef100_ev_rx(channel, p_event);
  247. ++spent;
  248. break;
  249. case ESE_GZ_EF100_EV_MCDI:
  250. efx_mcdi_process_event(channel, p_event);
  251. break;
  252. case ESE_GZ_EF100_EV_TX_COMPLETION:
  253. spent_tx += ef100_ev_tx(channel, p_event);
  254. if (spent_tx >= EFX_NAPI_MAX_TX)
  255. spent = quota;
  256. break;
  257. case ESE_GZ_EF100_EV_DRIVER:
  258. netif_info(efx, drv, efx->net_dev,
  259. "Driver initiated event " EFX_QWORD_FMT "\n",
  260. EFX_QWORD_VAL(*p_event));
  261. break;
  262. default:
  263. netif_info(efx, drv, efx->net_dev,
  264. "Unhandled event " EFX_QWORD_FMT "\n",
  265. EFX_QWORD_VAL(*p_event));
  266. }
  267. ++read_ptr;
  268. if ((read_ptr & channel->eventq_mask) == 0)
  269. evq_phase = !evq_phase;
  270. }
  271. channel->eventq_read_ptr = read_ptr;
  272. if (evq_phase != old_evq_phase)
  273. change_bit(channel->channel, nic_data->evq_phases);
  274. return spent;
  275. }
  276. static irqreturn_t ef100_msi_interrupt(int irq, void *dev_id)
  277. {
  278. struct efx_msi_context *context = dev_id;
  279. struct efx_nic *efx = context->efx;
  280. netif_vdbg(efx, intr, efx->net_dev,
  281. "IRQ %d on CPU %d\n", irq, raw_smp_processor_id());
  282. if (likely(READ_ONCE(efx->irq_soft_enabled))) {
  283. /* Note test interrupts */
  284. if (context->index == efx->irq_level)
  285. efx->last_irq_cpu = raw_smp_processor_id();
  286. /* Schedule processing of the channel */
  287. efx_schedule_channel_irq(efx->channel[context->index]);
  288. }
  289. return IRQ_HANDLED;
  290. }
  291. int ef100_phy_probe(struct efx_nic *efx)
  292. {
  293. struct efx_mcdi_phy_data *phy_data;
  294. int rc;
  295. /* Probe for the PHY */
  296. efx->phy_data = kzalloc(sizeof(struct efx_mcdi_phy_data), GFP_KERNEL);
  297. if (!efx->phy_data)
  298. return -ENOMEM;
  299. rc = efx_mcdi_get_phy_cfg(efx, efx->phy_data);
  300. if (rc)
  301. return rc;
  302. /* Populate driver and ethtool settings */
  303. phy_data = efx->phy_data;
  304. mcdi_to_ethtool_linkset(phy_data->media, phy_data->supported_cap,
  305. efx->link_advertising);
  306. efx->fec_config = mcdi_fec_caps_to_ethtool(phy_data->supported_cap,
  307. false);
  308. /* Default to Autonegotiated flow control if the PHY supports it */
  309. efx->wanted_fc = EFX_FC_RX | EFX_FC_TX;
  310. if (phy_data->supported_cap & (1 << MC_CMD_PHY_CAP_AN_LBN))
  311. efx->wanted_fc |= EFX_FC_AUTO;
  312. efx_link_set_wanted_fc(efx, efx->wanted_fc);
  313. /* Push settings to the PHY. Failure is not fatal, the user can try to
  314. * fix it using ethtool.
  315. */
  316. rc = efx_mcdi_port_reconfigure(efx);
  317. if (rc && rc != -EPERM)
  318. netif_warn(efx, drv, efx->net_dev,
  319. "could not initialise PHY settings\n");
  320. return 0;
  321. }
  322. int ef100_filter_table_probe(struct efx_nic *efx)
  323. {
  324. return efx_mcdi_filter_table_probe(efx, true);
  325. }
  326. static int ef100_filter_table_up(struct efx_nic *efx)
  327. {
  328. int rc;
  329. down_write(&efx->filter_sem);
  330. rc = efx_mcdi_filter_add_vlan(efx, EFX_FILTER_VID_UNSPEC);
  331. if (rc)
  332. goto fail_unspec;
  333. rc = efx_mcdi_filter_add_vlan(efx, 0);
  334. if (rc)
  335. goto fail_vlan0;
  336. /* Drop the lock: we've finished altering table existence, and
  337. * filter insertion will need to take the lock for read.
  338. */
  339. up_write(&efx->filter_sem);
  340. if (IS_ENABLED(CONFIG_SFC_SRIOV))
  341. rc = efx_tc_insert_rep_filters(efx);
  342. /* Rep filter failure is nonfatal */
  343. if (rc)
  344. netif_warn(efx, drv, efx->net_dev,
  345. "Failed to insert representor filters, rc %d\n",
  346. rc);
  347. return 0;
  348. fail_vlan0:
  349. efx_mcdi_filter_del_vlan(efx, EFX_FILTER_VID_UNSPEC);
  350. fail_unspec:
  351. efx_mcdi_filter_table_down(efx);
  352. up_write(&efx->filter_sem);
  353. return rc;
  354. }
  355. static void ef100_filter_table_down(struct efx_nic *efx)
  356. {
  357. if (IS_ENABLED(CONFIG_SFC_SRIOV))
  358. efx_tc_remove_rep_filters(efx);
  359. down_write(&efx->filter_sem);
  360. efx_mcdi_filter_del_vlan(efx, 0);
  361. efx_mcdi_filter_del_vlan(efx, EFX_FILTER_VID_UNSPEC);
  362. efx_mcdi_filter_table_down(efx);
  363. up_write(&efx->filter_sem);
  364. }
  365. /* Other
  366. */
  367. static int ef100_reconfigure_mac(struct efx_nic *efx, bool mtu_only)
  368. {
  369. WARN_ON(!mutex_is_locked(&efx->mac_lock));
  370. efx_mcdi_filter_sync_rx_mode(efx);
  371. if (mtu_only && efx_has_cap(efx, SET_MAC_ENHANCED))
  372. return efx_mcdi_set_mtu(efx);
  373. return efx_mcdi_set_mac(efx);
  374. }
  375. static enum reset_type ef100_map_reset_reason(enum reset_type reason)
  376. {
  377. if (reason == RESET_TYPE_TX_WATCHDOG)
  378. return reason;
  379. return RESET_TYPE_DISABLE;
  380. }
  381. static int ef100_map_reset_flags(u32 *flags)
  382. {
  383. /* Only perform a RESET_TYPE_ALL because we don't support MC_REBOOTs */
  384. if ((*flags & EF100_RESET_PORT)) {
  385. *flags &= ~EF100_RESET_PORT;
  386. return RESET_TYPE_ALL;
  387. }
  388. if (*flags & ETH_RESET_MGMT) {
  389. *flags &= ~ETH_RESET_MGMT;
  390. return RESET_TYPE_DISABLE;
  391. }
  392. return -EINVAL;
  393. }
  394. static int ef100_reset(struct efx_nic *efx, enum reset_type reset_type)
  395. {
  396. int rc;
  397. dev_close(efx->net_dev);
  398. if (reset_type == RESET_TYPE_TX_WATCHDOG) {
  399. netif_device_attach(efx->net_dev);
  400. __clear_bit(reset_type, &efx->reset_pending);
  401. rc = dev_open(efx->net_dev, NULL);
  402. } else if (reset_type == RESET_TYPE_ALL) {
  403. rc = efx_mcdi_reset(efx, reset_type);
  404. if (rc)
  405. return rc;
  406. netif_device_attach(efx->net_dev);
  407. rc = dev_open(efx->net_dev, NULL);
  408. } else {
  409. rc = 1; /* Leave the device closed */
  410. }
  411. return rc;
  412. }
  413. static void ef100_common_stat_mask(unsigned long *mask)
  414. {
  415. __set_bit(EF100_STAT_port_rx_packets, mask);
  416. __set_bit(EF100_STAT_port_tx_packets, mask);
  417. __set_bit(EF100_STAT_port_rx_bytes, mask);
  418. __set_bit(EF100_STAT_port_tx_bytes, mask);
  419. __set_bit(EF100_STAT_port_rx_multicast, mask);
  420. __set_bit(EF100_STAT_port_rx_bad, mask);
  421. __set_bit(EF100_STAT_port_rx_align_error, mask);
  422. __set_bit(EF100_STAT_port_rx_overflow, mask);
  423. }
  424. static void ef100_ethtool_stat_mask(unsigned long *mask)
  425. {
  426. __set_bit(EF100_STAT_port_tx_pause, mask);
  427. __set_bit(EF100_STAT_port_tx_unicast, mask);
  428. __set_bit(EF100_STAT_port_tx_multicast, mask);
  429. __set_bit(EF100_STAT_port_tx_broadcast, mask);
  430. __set_bit(EF100_STAT_port_tx_lt64, mask);
  431. __set_bit(EF100_STAT_port_tx_64, mask);
  432. __set_bit(EF100_STAT_port_tx_65_to_127, mask);
  433. __set_bit(EF100_STAT_port_tx_128_to_255, mask);
  434. __set_bit(EF100_STAT_port_tx_256_to_511, mask);
  435. __set_bit(EF100_STAT_port_tx_512_to_1023, mask);
  436. __set_bit(EF100_STAT_port_tx_1024_to_15xx, mask);
  437. __set_bit(EF100_STAT_port_tx_15xx_to_jumbo, mask);
  438. __set_bit(EF100_STAT_port_rx_good, mask);
  439. __set_bit(EF100_STAT_port_rx_pause, mask);
  440. __set_bit(EF100_STAT_port_rx_unicast, mask);
  441. __set_bit(EF100_STAT_port_rx_broadcast, mask);
  442. __set_bit(EF100_STAT_port_rx_lt64, mask);
  443. __set_bit(EF100_STAT_port_rx_64, mask);
  444. __set_bit(EF100_STAT_port_rx_65_to_127, mask);
  445. __set_bit(EF100_STAT_port_rx_128_to_255, mask);
  446. __set_bit(EF100_STAT_port_rx_256_to_511, mask);
  447. __set_bit(EF100_STAT_port_rx_512_to_1023, mask);
  448. __set_bit(EF100_STAT_port_rx_1024_to_15xx, mask);
  449. __set_bit(EF100_STAT_port_rx_15xx_to_jumbo, mask);
  450. __set_bit(EF100_STAT_port_rx_gtjumbo, mask);
  451. __set_bit(EF100_STAT_port_rx_bad_gtjumbo, mask);
  452. __set_bit(EF100_STAT_port_rx_length_error, mask);
  453. __set_bit(EF100_STAT_port_rx_nodesc_drops, mask);
  454. __set_bit(GENERIC_STAT_rx_nodesc_trunc, mask);
  455. __set_bit(GENERIC_STAT_rx_noskb_drops, mask);
  456. }
  457. #define EF100_DMA_STAT(ext_name, mcdi_name) \
  458. [EF100_STAT_ ## ext_name] = \
  459. { #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name }
  460. static const struct efx_hw_stat_desc ef100_stat_desc[EF100_STAT_COUNT] = {
  461. EF100_DMA_STAT(port_tx_bytes, TX_BYTES),
  462. EF100_DMA_STAT(port_tx_packets, TX_PKTS),
  463. EF100_DMA_STAT(port_tx_pause, TX_PAUSE_PKTS),
  464. EF100_DMA_STAT(port_tx_unicast, TX_UNICAST_PKTS),
  465. EF100_DMA_STAT(port_tx_multicast, TX_MULTICAST_PKTS),
  466. EF100_DMA_STAT(port_tx_broadcast, TX_BROADCAST_PKTS),
  467. EF100_DMA_STAT(port_tx_lt64, TX_LT64_PKTS),
  468. EF100_DMA_STAT(port_tx_64, TX_64_PKTS),
  469. EF100_DMA_STAT(port_tx_65_to_127, TX_65_TO_127_PKTS),
  470. EF100_DMA_STAT(port_tx_128_to_255, TX_128_TO_255_PKTS),
  471. EF100_DMA_STAT(port_tx_256_to_511, TX_256_TO_511_PKTS),
  472. EF100_DMA_STAT(port_tx_512_to_1023, TX_512_TO_1023_PKTS),
  473. EF100_DMA_STAT(port_tx_1024_to_15xx, TX_1024_TO_15XX_PKTS),
  474. EF100_DMA_STAT(port_tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS),
  475. EF100_DMA_STAT(port_rx_bytes, RX_BYTES),
  476. EF100_DMA_STAT(port_rx_packets, RX_PKTS),
  477. EF100_DMA_STAT(port_rx_good, RX_GOOD_PKTS),
  478. EF100_DMA_STAT(port_rx_bad, RX_BAD_FCS_PKTS),
  479. EF100_DMA_STAT(port_rx_pause, RX_PAUSE_PKTS),
  480. EF100_DMA_STAT(port_rx_unicast, RX_UNICAST_PKTS),
  481. EF100_DMA_STAT(port_rx_multicast, RX_MULTICAST_PKTS),
  482. EF100_DMA_STAT(port_rx_broadcast, RX_BROADCAST_PKTS),
  483. EF100_DMA_STAT(port_rx_lt64, RX_UNDERSIZE_PKTS),
  484. EF100_DMA_STAT(port_rx_64, RX_64_PKTS),
  485. EF100_DMA_STAT(port_rx_65_to_127, RX_65_TO_127_PKTS),
  486. EF100_DMA_STAT(port_rx_128_to_255, RX_128_TO_255_PKTS),
  487. EF100_DMA_STAT(port_rx_256_to_511, RX_256_TO_511_PKTS),
  488. EF100_DMA_STAT(port_rx_512_to_1023, RX_512_TO_1023_PKTS),
  489. EF100_DMA_STAT(port_rx_1024_to_15xx, RX_1024_TO_15XX_PKTS),
  490. EF100_DMA_STAT(port_rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS),
  491. EF100_DMA_STAT(port_rx_gtjumbo, RX_GTJUMBO_PKTS),
  492. EF100_DMA_STAT(port_rx_bad_gtjumbo, RX_JABBER_PKTS),
  493. EF100_DMA_STAT(port_rx_align_error, RX_ALIGN_ERROR_PKTS),
  494. EF100_DMA_STAT(port_rx_length_error, RX_LENGTH_ERROR_PKTS),
  495. EF100_DMA_STAT(port_rx_overflow, RX_OVERFLOW_PKTS),
  496. EF100_DMA_STAT(port_rx_nodesc_drops, RX_NODESC_DROPS),
  497. EFX_GENERIC_SW_STAT(rx_nodesc_trunc),
  498. EFX_GENERIC_SW_STAT(rx_noskb_drops),
  499. };
  500. static size_t ef100_describe_stats(struct efx_nic *efx, u8 *names)
  501. {
  502. DECLARE_BITMAP(mask, EF100_STAT_COUNT) = {};
  503. ef100_ethtool_stat_mask(mask);
  504. return efx_nic_describe_stats(ef100_stat_desc, EF100_STAT_COUNT,
  505. mask, names);
  506. }
  507. static size_t ef100_update_stats_common(struct efx_nic *efx, u64 *full_stats,
  508. struct rtnl_link_stats64 *core_stats)
  509. {
  510. struct ef100_nic_data *nic_data = efx->nic_data;
  511. DECLARE_BITMAP(mask, EF100_STAT_COUNT) = {};
  512. size_t stats_count = 0, index;
  513. u64 *stats = nic_data->stats;
  514. ef100_ethtool_stat_mask(mask);
  515. if (full_stats) {
  516. for_each_set_bit(index, mask, EF100_STAT_COUNT) {
  517. if (ef100_stat_desc[index].name) {
  518. *full_stats++ = stats[index];
  519. ++stats_count;
  520. }
  521. }
  522. }
  523. if (!core_stats)
  524. return stats_count;
  525. core_stats->rx_packets = stats[EF100_STAT_port_rx_packets];
  526. core_stats->tx_packets = stats[EF100_STAT_port_tx_packets];
  527. core_stats->rx_bytes = stats[EF100_STAT_port_rx_bytes];
  528. core_stats->tx_bytes = stats[EF100_STAT_port_tx_bytes];
  529. core_stats->rx_dropped = stats[EF100_STAT_port_rx_nodesc_drops] +
  530. stats[GENERIC_STAT_rx_nodesc_trunc] +
  531. stats[GENERIC_STAT_rx_noskb_drops];
  532. core_stats->multicast = stats[EF100_STAT_port_rx_multicast];
  533. core_stats->rx_length_errors =
  534. stats[EF100_STAT_port_rx_gtjumbo] +
  535. stats[EF100_STAT_port_rx_length_error];
  536. core_stats->rx_crc_errors = stats[EF100_STAT_port_rx_bad];
  537. core_stats->rx_frame_errors =
  538. stats[EF100_STAT_port_rx_align_error];
  539. core_stats->rx_fifo_errors = stats[EF100_STAT_port_rx_overflow];
  540. core_stats->rx_errors = (core_stats->rx_length_errors +
  541. core_stats->rx_crc_errors +
  542. core_stats->rx_frame_errors);
  543. return stats_count;
  544. }
  545. static size_t ef100_update_stats(struct efx_nic *efx,
  546. u64 *full_stats,
  547. struct rtnl_link_stats64 *core_stats)
  548. {
  549. __le64 *mc_stats = kmalloc(array_size(efx->num_mac_stats, sizeof(__le64)), GFP_ATOMIC);
  550. struct ef100_nic_data *nic_data = efx->nic_data;
  551. DECLARE_BITMAP(mask, EF100_STAT_COUNT) = {};
  552. u64 *stats = nic_data->stats;
  553. ef100_common_stat_mask(mask);
  554. ef100_ethtool_stat_mask(mask);
  555. if (!mc_stats)
  556. return 0;
  557. efx_nic_copy_stats(efx, mc_stats);
  558. efx_nic_update_stats(ef100_stat_desc, EF100_STAT_COUNT, mask,
  559. stats, mc_stats, false);
  560. kfree(mc_stats);
  561. return ef100_update_stats_common(efx, full_stats, core_stats);
  562. }
  563. static int efx_ef100_get_phys_port_id(struct efx_nic *efx,
  564. struct netdev_phys_item_id *ppid)
  565. {
  566. struct ef100_nic_data *nic_data = efx->nic_data;
  567. if (!is_valid_ether_addr(nic_data->port_id))
  568. return -EOPNOTSUPP;
  569. ppid->id_len = ETH_ALEN;
  570. memcpy(ppid->id, nic_data->port_id, ppid->id_len);
  571. return 0;
  572. }
  573. static int efx_ef100_irq_test_generate(struct efx_nic *efx)
  574. {
  575. MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN);
  576. BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0);
  577. MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level);
  578. return efx_mcdi_rpc_quiet(efx, MC_CMD_TRIGGER_INTERRUPT,
  579. inbuf, sizeof(inbuf), NULL, 0, NULL);
  580. }
  581. #define EFX_EF100_TEST 1
  582. static void efx_ef100_ev_test_generate(struct efx_channel *channel)
  583. {
  584. MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN);
  585. struct efx_nic *efx = channel->efx;
  586. efx_qword_t event;
  587. int rc;
  588. EFX_POPULATE_QWORD_2(event,
  589. ESF_GZ_E_TYPE, ESE_GZ_EF100_EV_DRIVER,
  590. ESF_GZ_DRIVER_DATA, EFX_EF100_TEST);
  591. MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel);
  592. /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has
  593. * already swapped the data to little-endian order.
  594. */
  595. memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0],
  596. sizeof(efx_qword_t));
  597. rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf),
  598. NULL, 0, NULL);
  599. if (rc && (rc != -ENETDOWN))
  600. goto fail;
  601. return;
  602. fail:
  603. WARN_ON(true);
  604. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  605. }
  606. static unsigned int ef100_check_caps(const struct efx_nic *efx,
  607. u8 flag, u32 offset)
  608. {
  609. const struct ef100_nic_data *nic_data = efx->nic_data;
  610. switch (offset) {
  611. case MC_CMD_GET_CAPABILITIES_V8_OUT_FLAGS1_OFST:
  612. return nic_data->datapath_caps & BIT_ULL(flag);
  613. case MC_CMD_GET_CAPABILITIES_V8_OUT_FLAGS2_OFST:
  614. return nic_data->datapath_caps2 & BIT_ULL(flag);
  615. case MC_CMD_GET_CAPABILITIES_V8_OUT_FLAGS3_OFST:
  616. return nic_data->datapath_caps3 & BIT_ULL(flag);
  617. default:
  618. return 0;
  619. }
  620. }
  621. static unsigned int efx_ef100_recycle_ring_size(const struct efx_nic *efx)
  622. {
  623. /* Maximum link speed for Riverhead is 100G */
  624. return 10 * EFX_RECYCLE_RING_SIZE_10G;
  625. }
  626. static int efx_ef100_get_base_mport(struct efx_nic *efx)
  627. {
  628. struct ef100_nic_data *nic_data = efx->nic_data;
  629. u32 selector, id;
  630. int rc;
  631. /* Construct mport selector for "physical network port" */
  632. efx_mae_mport_wire(efx, &selector);
  633. /* Look up actual mport ID */
  634. rc = efx_mae_fw_lookup_mport(efx, selector, &id);
  635. if (rc)
  636. return rc;
  637. /* The ID should always fit in 16 bits, because that's how wide the
  638. * corresponding fields in the RX prefix & TX override descriptor are
  639. */
  640. if (id >> 16)
  641. netif_warn(efx, probe, efx->net_dev, "Bad base m-port id %#x\n",
  642. id);
  643. nic_data->base_mport = id;
  644. nic_data->have_mport = true;
  645. /* Construct mport selector for "calling PF" */
  646. efx_mae_mport_uplink(efx, &selector);
  647. /* Look up actual mport ID */
  648. rc = efx_mae_fw_lookup_mport(efx, selector, &id);
  649. if (rc)
  650. return rc;
  651. if (id >> 16)
  652. netif_warn(efx, probe, efx->net_dev, "Bad own m-port id %#x\n",
  653. id);
  654. nic_data->own_mport = id;
  655. nic_data->have_own_mport = true;
  656. return 0;
  657. }
  658. static int compare_versions(const char *a, const char *b)
  659. {
  660. int a_major, a_minor, a_point, a_patch;
  661. int b_major, b_minor, b_point, b_patch;
  662. int a_matched, b_matched;
  663. a_matched = sscanf(a, "%d.%d.%d.%d", &a_major, &a_minor, &a_point, &a_patch);
  664. b_matched = sscanf(b, "%d.%d.%d.%d", &b_major, &b_minor, &b_point, &b_patch);
  665. if (a_matched == 4 && b_matched != 4)
  666. return +1;
  667. if (a_matched != 4 && b_matched == 4)
  668. return -1;
  669. if (a_matched != 4 && b_matched != 4)
  670. return 0;
  671. if (a_major != b_major)
  672. return a_major - b_major;
  673. if (a_minor != b_minor)
  674. return a_minor - b_minor;
  675. if (a_point != b_point)
  676. return a_point - b_point;
  677. return a_patch - b_patch;
  678. }
  679. enum ef100_tlv_state_machine {
  680. EF100_TLV_TYPE,
  681. EF100_TLV_TYPE_CONT,
  682. EF100_TLV_LENGTH,
  683. EF100_TLV_VALUE
  684. };
  685. struct ef100_tlv_state {
  686. enum ef100_tlv_state_machine state;
  687. u64 value;
  688. u32 value_offset;
  689. u16 type;
  690. u8 len;
  691. };
  692. static int ef100_tlv_feed(struct ef100_tlv_state *state, u8 byte)
  693. {
  694. switch (state->state) {
  695. case EF100_TLV_TYPE:
  696. state->type = byte & 0x7f;
  697. state->state = (byte & 0x80) ? EF100_TLV_TYPE_CONT
  698. : EF100_TLV_LENGTH;
  699. /* Clear ready to read in a new entry */
  700. state->value = 0;
  701. state->value_offset = 0;
  702. return 0;
  703. case EF100_TLV_TYPE_CONT:
  704. state->type |= byte << 7;
  705. state->state = EF100_TLV_LENGTH;
  706. return 0;
  707. case EF100_TLV_LENGTH:
  708. state->len = byte;
  709. /* We only handle TLVs that fit in a u64 */
  710. if (state->len > sizeof(state->value))
  711. return -EOPNOTSUPP;
  712. /* len may be zero, implying a value of zero */
  713. state->state = state->len ? EF100_TLV_VALUE : EF100_TLV_TYPE;
  714. return 0;
  715. case EF100_TLV_VALUE:
  716. state->value |= ((u64)byte) << (state->value_offset * 8);
  717. state->value_offset++;
  718. if (state->value_offset >= state->len)
  719. state->state = EF100_TLV_TYPE;
  720. return 0;
  721. default: /* state machine error, can't happen */
  722. WARN_ON_ONCE(1);
  723. return -EIO;
  724. }
  725. }
  726. static int ef100_process_design_param(struct efx_nic *efx,
  727. const struct ef100_tlv_state *reader)
  728. {
  729. struct ef100_nic_data *nic_data = efx->nic_data;
  730. switch (reader->type) {
  731. case ESE_EF100_DP_GZ_PAD: /* padding, skip it */
  732. return 0;
  733. case ESE_EF100_DP_GZ_PARTIAL_TSTAMP_SUB_NANO_BITS:
  734. /* Driver doesn't support timestamping yet, so we don't care */
  735. return 0;
  736. case ESE_EF100_DP_GZ_EVQ_UNSOL_CREDIT_SEQ_BITS:
  737. /* Driver doesn't support unsolicited-event credits yet, so
  738. * we don't care
  739. */
  740. return 0;
  741. case ESE_EF100_DP_GZ_NMMU_GROUP_SIZE:
  742. /* Driver doesn't manage the NMMU (so we don't care) */
  743. return 0;
  744. case ESE_EF100_DP_GZ_RX_L4_CSUM_PROTOCOLS:
  745. /* Driver uses CHECKSUM_COMPLETE, so we don't care about
  746. * protocol checksum validation
  747. */
  748. return 0;
  749. case ESE_EF100_DP_GZ_TSO_MAX_HDR_LEN:
  750. nic_data->tso_max_hdr_len = min_t(u64, reader->value, 0xffff);
  751. return 0;
  752. case ESE_EF100_DP_GZ_TSO_MAX_HDR_NUM_SEGS:
  753. /* We always put HDR_NUM_SEGS=1 in our TSO descriptors */
  754. if (!reader->value) {
  755. netif_err(efx, probe, efx->net_dev,
  756. "TSO_MAX_HDR_NUM_SEGS < 1\n");
  757. return -EOPNOTSUPP;
  758. }
  759. return 0;
  760. case ESE_EF100_DP_GZ_RXQ_SIZE_GRANULARITY:
  761. case ESE_EF100_DP_GZ_TXQ_SIZE_GRANULARITY:
  762. /* Our TXQ and RXQ sizes are always power-of-two and thus divisible by
  763. * EFX_MIN_DMAQ_SIZE, so we just need to check that
  764. * EFX_MIN_DMAQ_SIZE is divisible by GRANULARITY.
  765. * This is very unlikely to fail.
  766. */
  767. if (!reader->value || reader->value > EFX_MIN_DMAQ_SIZE ||
  768. EFX_MIN_DMAQ_SIZE % (u32)reader->value) {
  769. netif_err(efx, probe, efx->net_dev,
  770. "%s size granularity is %llu, can't guarantee safety\n",
  771. reader->type == ESE_EF100_DP_GZ_RXQ_SIZE_GRANULARITY ? "RXQ" : "TXQ",
  772. reader->value);
  773. return -EOPNOTSUPP;
  774. }
  775. return 0;
  776. case ESE_EF100_DP_GZ_TSO_MAX_PAYLOAD_LEN:
  777. nic_data->tso_max_payload_len = min_t(u64, reader->value,
  778. GSO_LEGACY_MAX_SIZE);
  779. netif_set_tso_max_size(efx->net_dev,
  780. nic_data->tso_max_payload_len);
  781. return 0;
  782. case ESE_EF100_DP_GZ_TSO_MAX_PAYLOAD_NUM_SEGS:
  783. nic_data->tso_max_payload_num_segs = min_t(u64, reader->value, 0xffff);
  784. netif_set_tso_max_segs(efx->net_dev,
  785. nic_data->tso_max_payload_num_segs);
  786. return 0;
  787. case ESE_EF100_DP_GZ_TSO_MAX_NUM_FRAMES:
  788. nic_data->tso_max_frames = min_t(u64, reader->value, 0xffff);
  789. return 0;
  790. case ESE_EF100_DP_GZ_COMPAT:
  791. if (reader->value) {
  792. netif_err(efx, probe, efx->net_dev,
  793. "DP_COMPAT has unknown bits %#llx, driver not compatible with this hw\n",
  794. reader->value);
  795. return -EOPNOTSUPP;
  796. }
  797. return 0;
  798. case ESE_EF100_DP_GZ_MEM2MEM_MAX_LEN:
  799. /* Driver doesn't use mem2mem transfers */
  800. return 0;
  801. case ESE_EF100_DP_GZ_EVQ_TIMER_TICK_NANOS:
  802. /* Driver doesn't currently use EVQ_TIMER */
  803. return 0;
  804. case ESE_EF100_DP_GZ_NMMU_PAGE_SIZES:
  805. /* Driver doesn't manage the NMMU (so we don't care) */
  806. return 0;
  807. case ESE_EF100_DP_GZ_VI_STRIDES:
  808. /* We never try to set the VI stride, and we don't rely on
  809. * being able to find VIs past VI 0 until after we've learned
  810. * the current stride from MC_CMD_GET_CAPABILITIES.
  811. * So the value of this shouldn't matter.
  812. */
  813. if (reader->value != ESE_EF100_DP_GZ_VI_STRIDES_DEFAULT)
  814. netif_dbg(efx, probe, efx->net_dev,
  815. "NIC has other than default VI_STRIDES (mask "
  816. "%#llx), early probing might use wrong one\n",
  817. reader->value);
  818. return 0;
  819. case ESE_EF100_DP_GZ_RX_MAX_RUNT:
  820. /* Driver doesn't look at L2_STATUS:LEN_ERR bit, so we don't
  821. * care whether it indicates runt or overlength for any given
  822. * packet, so we don't care about this parameter.
  823. */
  824. return 0;
  825. default:
  826. /* Host interface says "Drivers should ignore design parameters
  827. * that they do not recognise."
  828. */
  829. netif_dbg(efx, probe, efx->net_dev,
  830. "Ignoring unrecognised design parameter %u\n",
  831. reader->type);
  832. return 0;
  833. }
  834. }
  835. static int ef100_check_design_params(struct efx_nic *efx)
  836. {
  837. struct ef100_tlv_state reader = {};
  838. u32 total_len, offset = 0;
  839. efx_dword_t reg;
  840. int rc = 0, i;
  841. u32 data;
  842. efx_readd(efx, &reg, ER_GZ_PARAMS_TLV_LEN);
  843. total_len = EFX_DWORD_FIELD(reg, EFX_DWORD_0);
  844. pci_dbg(efx->pci_dev, "%u bytes of design parameters\n", total_len);
  845. while (offset < total_len) {
  846. efx_readd(efx, &reg, ER_GZ_PARAMS_TLV + offset);
  847. data = EFX_DWORD_FIELD(reg, EFX_DWORD_0);
  848. for (i = 0; i < sizeof(data); i++) {
  849. rc = ef100_tlv_feed(&reader, data);
  850. /* Got a complete value? */
  851. if (!rc && reader.state == EF100_TLV_TYPE)
  852. rc = ef100_process_design_param(efx, &reader);
  853. if (rc)
  854. goto out;
  855. data >>= 8;
  856. offset++;
  857. }
  858. }
  859. /* Check we didn't end halfway through a TLV entry, which could either
  860. * mean that the TLV stream is truncated or just that it's corrupted
  861. * and our state machine is out of sync.
  862. */
  863. if (reader.state != EF100_TLV_TYPE) {
  864. if (reader.state == EF100_TLV_TYPE_CONT)
  865. netif_err(efx, probe, efx->net_dev,
  866. "truncated design parameter (incomplete type %u)\n",
  867. reader.type);
  868. else
  869. netif_err(efx, probe, efx->net_dev,
  870. "truncated design parameter %u\n",
  871. reader.type);
  872. rc = -EIO;
  873. }
  874. out:
  875. return rc;
  876. }
  877. /* NIC probe and remove
  878. */
  879. static int ef100_probe_main(struct efx_nic *efx)
  880. {
  881. unsigned int bar_size = resource_size(&efx->pci_dev->resource[efx->mem_bar]);
  882. struct ef100_nic_data *nic_data;
  883. char fw_version[32];
  884. u32 priv_mask = 0;
  885. int i, rc;
  886. if (WARN_ON(bar_size == 0))
  887. return -EIO;
  888. nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
  889. if (!nic_data)
  890. return -ENOMEM;
  891. efx->nic_data = nic_data;
  892. nic_data->efx = efx;
  893. efx->max_vis = EF100_MAX_VIS;
  894. /* Populate design-parameter defaults */
  895. nic_data->tso_max_hdr_len = ESE_EF100_DP_GZ_TSO_MAX_HDR_LEN_DEFAULT;
  896. nic_data->tso_max_frames = ESE_EF100_DP_GZ_TSO_MAX_NUM_FRAMES_DEFAULT;
  897. nic_data->tso_max_payload_num_segs = ESE_EF100_DP_GZ_TSO_MAX_PAYLOAD_NUM_SEGS_DEFAULT;
  898. nic_data->tso_max_payload_len = ESE_EF100_DP_GZ_TSO_MAX_PAYLOAD_LEN_DEFAULT;
  899. /* Read design parameters */
  900. rc = ef100_check_design_params(efx);
  901. if (rc) {
  902. pci_err(efx->pci_dev, "Unsupported design parameters\n");
  903. goto fail;
  904. }
  905. /* we assume later that we can copy from this buffer in dwords */
  906. BUILD_BUG_ON(MCDI_CTL_SDU_LEN_MAX_V2 % 4);
  907. /* MCDI buffers must be 256 byte aligned. */
  908. rc = efx_nic_alloc_buffer(efx, &nic_data->mcdi_buf, MCDI_BUF_LEN,
  909. GFP_KERNEL);
  910. if (rc)
  911. goto fail;
  912. /* Get the MC's warm boot count. In case it's rebooting right
  913. * now, be prepared to retry.
  914. */
  915. i = 0;
  916. for (;;) {
  917. rc = ef100_get_warm_boot_count(efx);
  918. if (rc >= 0)
  919. break;
  920. if (++i == 5)
  921. goto fail;
  922. ssleep(1);
  923. }
  924. nic_data->warm_boot_count = rc;
  925. /* In case we're recovering from a crash (kexec), we want to
  926. * cancel any outstanding request by the previous user of this
  927. * function. We send a special message using the least
  928. * significant bits of the 'high' (doorbell) register.
  929. */
  930. _efx_writed(efx, cpu_to_le32(1), efx_reg(efx, ER_GZ_MC_DB_HWRD));
  931. /* Post-IO section. */
  932. rc = efx_mcdi_init(efx);
  933. if (rc)
  934. goto fail;
  935. /* Reset (most) configuration for this function */
  936. rc = efx_mcdi_reset(efx, RESET_TYPE_ALL);
  937. if (rc)
  938. goto fail;
  939. /* Enable event logging */
  940. rc = efx_mcdi_log_ctrl(efx, true, false, 0);
  941. if (rc)
  942. goto fail;
  943. rc = efx_get_pf_index(efx, &nic_data->pf_index);
  944. if (rc)
  945. goto fail;
  946. rc = efx_mcdi_port_get_number(efx);
  947. if (rc < 0)
  948. goto fail;
  949. efx->port_num = rc;
  950. efx_mcdi_print_fwver(efx, fw_version, sizeof(fw_version));
  951. pci_dbg(efx->pci_dev, "Firmware version %s\n", fw_version);
  952. rc = efx_mcdi_get_privilege_mask(efx, &priv_mask);
  953. if (rc) /* non-fatal, and priv_mask will still be 0 */
  954. pci_info(efx->pci_dev,
  955. "Failed to get privilege mask from FW, rc %d\n", rc);
  956. nic_data->grp_mae = !!(priv_mask & MC_CMD_PRIVILEGE_MASK_IN_GRP_MAE);
  957. if (compare_versions(fw_version, "1.1.0.1000") < 0) {
  958. pci_info(efx->pci_dev, "Firmware uses old event descriptors\n");
  959. rc = -EINVAL;
  960. goto fail;
  961. }
  962. if (efx_has_cap(efx, UNSOL_EV_CREDIT_SUPPORTED)) {
  963. pci_info(efx->pci_dev, "Firmware uses unsolicited-event credits\n");
  964. rc = -EINVAL;
  965. goto fail;
  966. }
  967. return 0;
  968. fail:
  969. return rc;
  970. }
  971. /* MCDI commands are related to the same device issuing them. This function
  972. * allows to do an MCDI command on behalf of another device, mainly PFs setting
  973. * things for VFs.
  974. */
  975. int efx_ef100_lookup_client_id(struct efx_nic *efx, efx_qword_t pciefn, u32 *id)
  976. {
  977. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLIENT_HANDLE_OUT_LEN);
  978. MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_CLIENT_HANDLE_IN_LEN);
  979. u64 pciefn_flat = le64_to_cpu(pciefn.u64[0]);
  980. size_t outlen;
  981. int rc;
  982. MCDI_SET_DWORD(inbuf, GET_CLIENT_HANDLE_IN_TYPE,
  983. MC_CMD_GET_CLIENT_HANDLE_IN_TYPE_FUNC);
  984. MCDI_SET_QWORD(inbuf, GET_CLIENT_HANDLE_IN_FUNC,
  985. pciefn_flat);
  986. rc = efx_mcdi_rpc(efx, MC_CMD_GET_CLIENT_HANDLE, inbuf, sizeof(inbuf),
  987. outbuf, sizeof(outbuf), &outlen);
  988. if (rc)
  989. return rc;
  990. if (outlen < sizeof(outbuf))
  991. return -EIO;
  992. *id = MCDI_DWORD(outbuf, GET_CLIENT_HANDLE_OUT_HANDLE);
  993. return 0;
  994. }
  995. int ef100_probe_netdev_pf(struct efx_nic *efx)
  996. {
  997. struct ef100_nic_data *nic_data = efx->nic_data;
  998. struct net_device *net_dev = efx->net_dev;
  999. int rc;
  1000. if (!IS_ENABLED(CONFIG_SFC_SRIOV) || !nic_data->grp_mae)
  1001. return 0;
  1002. rc = efx_init_struct_tc(efx);
  1003. if (rc)
  1004. return rc;
  1005. rc = efx_ef100_get_base_mport(efx);
  1006. if (rc) {
  1007. netif_warn(efx, probe, net_dev,
  1008. "Failed to probe base mport rc %d; representors will not function\n",
  1009. rc);
  1010. }
  1011. rc = efx_init_mae(efx);
  1012. if (rc)
  1013. netif_warn(efx, probe, net_dev,
  1014. "Failed to init MAE rc %d; representors will not function\n",
  1015. rc);
  1016. else
  1017. efx_ef100_init_reps(efx);
  1018. rc = efx_init_tc(efx);
  1019. if (rc) {
  1020. /* Either we don't have an MAE at all (i.e. legacy v-switching),
  1021. * or we do but we failed to probe it. In the latter case, we
  1022. * may not have set up default rules, in which case we won't be
  1023. * able to pass any traffic. However, we don't fail the probe,
  1024. * because the user might need to use the netdevice to apply
  1025. * configuration changes to fix whatever's wrong with the MAE.
  1026. */
  1027. netif_warn(efx, probe, net_dev, "Failed to probe MAE rc %d\n",
  1028. rc);
  1029. } else {
  1030. net_dev->features |= NETIF_F_HW_TC;
  1031. efx->fixed_features |= NETIF_F_HW_TC;
  1032. }
  1033. return 0;
  1034. }
  1035. int ef100_probe_vf(struct efx_nic *efx)
  1036. {
  1037. return ef100_probe_main(efx);
  1038. }
  1039. void ef100_remove(struct efx_nic *efx)
  1040. {
  1041. struct ef100_nic_data *nic_data = efx->nic_data;
  1042. if (IS_ENABLED(CONFIG_SFC_SRIOV) && efx->mae) {
  1043. efx_ef100_fini_reps(efx);
  1044. efx_fini_mae(efx);
  1045. }
  1046. efx_mcdi_detach(efx);
  1047. efx_mcdi_fini(efx);
  1048. if (nic_data)
  1049. efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
  1050. kfree(nic_data);
  1051. efx->nic_data = NULL;
  1052. }
  1053. /* NIC level access functions
  1054. */
  1055. #define EF100_OFFLOAD_FEATURES (NETIF_F_HW_CSUM | NETIF_F_RXCSUM | \
  1056. NETIF_F_HIGHDMA | NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_NTUPLE | \
  1057. NETIF_F_RXHASH | NETIF_F_RXFCS | NETIF_F_TSO_ECN | NETIF_F_RXALL | \
  1058. NETIF_F_HW_VLAN_CTAG_TX)
  1059. const struct efx_nic_type ef100_pf_nic_type = {
  1060. .revision = EFX_REV_EF100,
  1061. .is_vf = false,
  1062. .probe = ef100_probe_main,
  1063. .offload_features = EF100_OFFLOAD_FEATURES,
  1064. .mcdi_max_ver = 2,
  1065. .mcdi_request = ef100_mcdi_request,
  1066. .mcdi_poll_response = ef100_mcdi_poll_response,
  1067. .mcdi_read_response = ef100_mcdi_read_response,
  1068. .mcdi_poll_reboot = ef100_mcdi_poll_reboot,
  1069. .mcdi_reboot_detected = ef100_mcdi_reboot_detected,
  1070. .irq_enable_master = efx_port_dummy_op_void,
  1071. .irq_test_generate = efx_ef100_irq_test_generate,
  1072. .irq_disable_non_ev = efx_port_dummy_op_void,
  1073. .push_irq_moderation = efx_channel_dummy_op_void,
  1074. .min_interrupt_mode = EFX_INT_MODE_MSIX,
  1075. .map_reset_reason = ef100_map_reset_reason,
  1076. .map_reset_flags = ef100_map_reset_flags,
  1077. .reset = ef100_reset,
  1078. .check_caps = ef100_check_caps,
  1079. .ev_probe = ef100_ev_probe,
  1080. .ev_init = ef100_ev_init,
  1081. .ev_fini = efx_mcdi_ev_fini,
  1082. .ev_remove = efx_mcdi_ev_remove,
  1083. .irq_handle_msi = ef100_msi_interrupt,
  1084. .ev_process = ef100_ev_process,
  1085. .ev_read_ack = ef100_ev_read_ack,
  1086. .ev_test_generate = efx_ef100_ev_test_generate,
  1087. .tx_probe = ef100_tx_probe,
  1088. .tx_init = ef100_tx_init,
  1089. .tx_write = ef100_tx_write,
  1090. .tx_enqueue = ef100_enqueue_skb,
  1091. .rx_probe = efx_mcdi_rx_probe,
  1092. .rx_init = efx_mcdi_rx_init,
  1093. .rx_remove = efx_mcdi_rx_remove,
  1094. .rx_write = ef100_rx_write,
  1095. .rx_packet = __ef100_rx_packet,
  1096. .rx_buf_hash_valid = ef100_rx_buf_hash_valid,
  1097. .fini_dmaq = efx_fini_dmaq,
  1098. .max_rx_ip_filters = EFX_MCDI_FILTER_TBL_ROWS,
  1099. .filter_table_probe = ef100_filter_table_up,
  1100. .filter_table_restore = efx_mcdi_filter_table_restore,
  1101. .filter_table_remove = ef100_filter_table_down,
  1102. .filter_insert = efx_mcdi_filter_insert,
  1103. .filter_remove_safe = efx_mcdi_filter_remove_safe,
  1104. .filter_get_safe = efx_mcdi_filter_get_safe,
  1105. .filter_clear_rx = efx_mcdi_filter_clear_rx,
  1106. .filter_count_rx_used = efx_mcdi_filter_count_rx_used,
  1107. .filter_get_rx_id_limit = efx_mcdi_filter_get_rx_id_limit,
  1108. .filter_get_rx_ids = efx_mcdi_filter_get_rx_ids,
  1109. #ifdef CONFIG_RFS_ACCEL
  1110. .filter_rfs_expire_one = efx_mcdi_filter_rfs_expire_one,
  1111. #endif
  1112. .get_phys_port_id = efx_ef100_get_phys_port_id,
  1113. .rx_prefix_size = ESE_GZ_RX_PKT_PREFIX_LEN,
  1114. .rx_hash_offset = ESF_GZ_RX_PREFIX_RSS_HASH_LBN / 8,
  1115. .rx_ts_offset = ESF_GZ_RX_PREFIX_PARTIAL_TSTAMP_LBN / 8,
  1116. .rx_hash_key_size = 40,
  1117. .rx_pull_rss_config = efx_mcdi_rx_pull_rss_config,
  1118. .rx_push_rss_config = efx_mcdi_pf_rx_push_rss_config,
  1119. .rx_push_rss_context_config = efx_mcdi_rx_push_rss_context_config,
  1120. .rx_pull_rss_context_config = efx_mcdi_rx_pull_rss_context_config,
  1121. .rx_restore_rss_contexts = efx_mcdi_rx_restore_rss_contexts,
  1122. .rx_recycle_ring_size = efx_ef100_recycle_ring_size,
  1123. .reconfigure_mac = ef100_reconfigure_mac,
  1124. .reconfigure_port = efx_mcdi_port_reconfigure,
  1125. .test_nvram = efx_new_mcdi_nvram_test_all,
  1126. .describe_stats = ef100_describe_stats,
  1127. .start_stats = efx_mcdi_mac_start_stats,
  1128. .update_stats = ef100_update_stats,
  1129. .pull_stats = efx_mcdi_mac_pull_stats,
  1130. .stop_stats = efx_mcdi_mac_stop_stats,
  1131. .sriov_configure = IS_ENABLED(CONFIG_SFC_SRIOV) ?
  1132. efx_ef100_sriov_configure : NULL,
  1133. /* Per-type bar/size configuration not used on ef100. Location of
  1134. * registers is defined by extended capabilities.
  1135. */
  1136. .mem_bar = NULL,
  1137. .mem_map_size = NULL,
  1138. };
  1139. const struct efx_nic_type ef100_vf_nic_type = {
  1140. .revision = EFX_REV_EF100,
  1141. .is_vf = true,
  1142. .probe = ef100_probe_vf,
  1143. .offload_features = EF100_OFFLOAD_FEATURES,
  1144. .mcdi_max_ver = 2,
  1145. .mcdi_request = ef100_mcdi_request,
  1146. .mcdi_poll_response = ef100_mcdi_poll_response,
  1147. .mcdi_read_response = ef100_mcdi_read_response,
  1148. .mcdi_poll_reboot = ef100_mcdi_poll_reboot,
  1149. .mcdi_reboot_detected = ef100_mcdi_reboot_detected,
  1150. .irq_enable_master = efx_port_dummy_op_void,
  1151. .irq_test_generate = efx_ef100_irq_test_generate,
  1152. .irq_disable_non_ev = efx_port_dummy_op_void,
  1153. .push_irq_moderation = efx_channel_dummy_op_void,
  1154. .min_interrupt_mode = EFX_INT_MODE_MSIX,
  1155. .map_reset_reason = ef100_map_reset_reason,
  1156. .map_reset_flags = ef100_map_reset_flags,
  1157. .reset = ef100_reset,
  1158. .check_caps = ef100_check_caps,
  1159. .ev_probe = ef100_ev_probe,
  1160. .ev_init = ef100_ev_init,
  1161. .ev_fini = efx_mcdi_ev_fini,
  1162. .ev_remove = efx_mcdi_ev_remove,
  1163. .irq_handle_msi = ef100_msi_interrupt,
  1164. .ev_process = ef100_ev_process,
  1165. .ev_read_ack = ef100_ev_read_ack,
  1166. .ev_test_generate = efx_ef100_ev_test_generate,
  1167. .tx_probe = ef100_tx_probe,
  1168. .tx_init = ef100_tx_init,
  1169. .tx_write = ef100_tx_write,
  1170. .tx_enqueue = ef100_enqueue_skb,
  1171. .rx_probe = efx_mcdi_rx_probe,
  1172. .rx_init = efx_mcdi_rx_init,
  1173. .rx_remove = efx_mcdi_rx_remove,
  1174. .rx_write = ef100_rx_write,
  1175. .rx_packet = __ef100_rx_packet,
  1176. .rx_buf_hash_valid = ef100_rx_buf_hash_valid,
  1177. .fini_dmaq = efx_fini_dmaq,
  1178. .max_rx_ip_filters = EFX_MCDI_FILTER_TBL_ROWS,
  1179. .filter_table_probe = ef100_filter_table_up,
  1180. .filter_table_restore = efx_mcdi_filter_table_restore,
  1181. .filter_table_remove = ef100_filter_table_down,
  1182. .filter_insert = efx_mcdi_filter_insert,
  1183. .filter_remove_safe = efx_mcdi_filter_remove_safe,
  1184. .filter_get_safe = efx_mcdi_filter_get_safe,
  1185. .filter_clear_rx = efx_mcdi_filter_clear_rx,
  1186. .filter_count_rx_used = efx_mcdi_filter_count_rx_used,
  1187. .filter_get_rx_id_limit = efx_mcdi_filter_get_rx_id_limit,
  1188. .filter_get_rx_ids = efx_mcdi_filter_get_rx_ids,
  1189. #ifdef CONFIG_RFS_ACCEL
  1190. .filter_rfs_expire_one = efx_mcdi_filter_rfs_expire_one,
  1191. #endif
  1192. .rx_prefix_size = ESE_GZ_RX_PKT_PREFIX_LEN,
  1193. .rx_hash_offset = ESF_GZ_RX_PREFIX_RSS_HASH_LBN / 8,
  1194. .rx_ts_offset = ESF_GZ_RX_PREFIX_PARTIAL_TSTAMP_LBN / 8,
  1195. .rx_hash_key_size = 40,
  1196. .rx_pull_rss_config = efx_mcdi_rx_pull_rss_config,
  1197. .rx_push_rss_config = efx_mcdi_pf_rx_push_rss_config,
  1198. .rx_restore_rss_contexts = efx_mcdi_rx_restore_rss_contexts,
  1199. .rx_recycle_ring_size = efx_ef100_recycle_ring_size,
  1200. .reconfigure_mac = ef100_reconfigure_mac,
  1201. .test_nvram = efx_new_mcdi_nvram_test_all,
  1202. .describe_stats = ef100_describe_stats,
  1203. .start_stats = efx_mcdi_mac_start_stats,
  1204. .update_stats = ef100_update_stats,
  1205. .pull_stats = efx_mcdi_mac_pull_stats,
  1206. .stop_stats = efx_mcdi_mac_stop_stats,
  1207. .mem_bar = NULL,
  1208. .mem_map_size = NULL,
  1209. };