ef100_nic.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386
  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_obj(struct efx_mcdi_phy_data);
  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. pci_err(efx->pci_dev, "TSO_MAX_HDR_NUM_SEGS < 1\n");
  756. return -EOPNOTSUPP;
  757. }
  758. return 0;
  759. case ESE_EF100_DP_GZ_RXQ_SIZE_GRANULARITY:
  760. case ESE_EF100_DP_GZ_TXQ_SIZE_GRANULARITY:
  761. /* Our TXQ and RXQ sizes are always power-of-two and thus divisible by
  762. * EFX_MIN_DMAQ_SIZE, so we just need to check that
  763. * EFX_MIN_DMAQ_SIZE is divisible by GRANULARITY.
  764. * This is very unlikely to fail.
  765. */
  766. if (!reader->value || reader->value > EFX_MIN_DMAQ_SIZE ||
  767. EFX_MIN_DMAQ_SIZE % (u32)reader->value) {
  768. pci_err(efx->pci_dev,
  769. "%s size granularity is %llu, can't guarantee safety\n",
  770. reader->type == ESE_EF100_DP_GZ_RXQ_SIZE_GRANULARITY ? "RXQ" : "TXQ",
  771. reader->value);
  772. return -EOPNOTSUPP;
  773. }
  774. return 0;
  775. case ESE_EF100_DP_GZ_TSO_MAX_PAYLOAD_LEN:
  776. nic_data->tso_max_payload_len = min_t(u64, reader->value,
  777. GSO_LEGACY_MAX_SIZE);
  778. return 0;
  779. case ESE_EF100_DP_GZ_TSO_MAX_PAYLOAD_NUM_SEGS:
  780. nic_data->tso_max_payload_num_segs = min_t(u64, reader->value, 0xffff);
  781. return 0;
  782. case ESE_EF100_DP_GZ_TSO_MAX_NUM_FRAMES:
  783. nic_data->tso_max_frames = min_t(u64, reader->value, 0xffff);
  784. return 0;
  785. case ESE_EF100_DP_GZ_COMPAT:
  786. if (reader->value) {
  787. pci_err(efx->pci_dev,
  788. "DP_COMPAT has unknown bits %#llx, driver not compatible with this hw\n",
  789. reader->value);
  790. return -EOPNOTSUPP;
  791. }
  792. return 0;
  793. case ESE_EF100_DP_GZ_MEM2MEM_MAX_LEN:
  794. /* Driver doesn't use mem2mem transfers */
  795. return 0;
  796. case ESE_EF100_DP_GZ_EVQ_TIMER_TICK_NANOS:
  797. /* Driver doesn't currently use EVQ_TIMER */
  798. return 0;
  799. case ESE_EF100_DP_GZ_NMMU_PAGE_SIZES:
  800. /* Driver doesn't manage the NMMU (so we don't care) */
  801. return 0;
  802. case ESE_EF100_DP_GZ_VI_STRIDES:
  803. /* We never try to set the VI stride, and we don't rely on
  804. * being able to find VIs past VI 0 until after we've learned
  805. * the current stride from MC_CMD_GET_CAPABILITIES.
  806. * So the value of this shouldn't matter.
  807. */
  808. if (reader->value != ESE_EF100_DP_GZ_VI_STRIDES_DEFAULT)
  809. pci_dbg(efx->pci_dev,
  810. "NIC has other than default VI_STRIDES (mask "
  811. "%#llx), early probing might use wrong one\n",
  812. reader->value);
  813. return 0;
  814. case ESE_EF100_DP_GZ_RX_MAX_RUNT:
  815. /* Driver doesn't look at L2_STATUS:LEN_ERR bit, so we don't
  816. * care whether it indicates runt or overlength for any given
  817. * packet, so we don't care about this parameter.
  818. */
  819. return 0;
  820. default:
  821. /* Host interface says "Drivers should ignore design parameters
  822. * that they do not recognise."
  823. */
  824. pci_dbg(efx->pci_dev,
  825. "Ignoring unrecognised design parameter %u\n",
  826. reader->type);
  827. return 0;
  828. }
  829. }
  830. static int ef100_check_design_params(struct efx_nic *efx)
  831. {
  832. struct ef100_tlv_state reader = {};
  833. u32 total_len, offset = 0;
  834. efx_dword_t reg;
  835. int rc = 0, i;
  836. u32 data;
  837. efx_readd(efx, &reg, ER_GZ_PARAMS_TLV_LEN);
  838. total_len = EFX_DWORD_FIELD(reg, EFX_DWORD_0);
  839. pci_dbg(efx->pci_dev, "%u bytes of design parameters\n", total_len);
  840. while (offset < total_len) {
  841. efx_readd(efx, &reg, ER_GZ_PARAMS_TLV + offset);
  842. data = EFX_DWORD_FIELD(reg, EFX_DWORD_0);
  843. for (i = 0; i < sizeof(data); i++) {
  844. rc = ef100_tlv_feed(&reader, data);
  845. /* Got a complete value? */
  846. if (!rc && reader.state == EF100_TLV_TYPE)
  847. rc = ef100_process_design_param(efx, &reader);
  848. if (rc)
  849. goto out;
  850. data >>= 8;
  851. offset++;
  852. }
  853. }
  854. /* Check we didn't end halfway through a TLV entry, which could either
  855. * mean that the TLV stream is truncated or just that it's corrupted
  856. * and our state machine is out of sync.
  857. */
  858. if (reader.state != EF100_TLV_TYPE) {
  859. if (reader.state == EF100_TLV_TYPE_CONT)
  860. pci_err(efx->pci_dev,
  861. "truncated design parameter (incomplete type %u)\n",
  862. reader.type);
  863. else
  864. pci_err(efx->pci_dev,
  865. "truncated design parameter %u\n",
  866. reader.type);
  867. rc = -EIO;
  868. }
  869. out:
  870. return rc;
  871. }
  872. /* NIC probe and remove
  873. */
  874. static int ef100_probe_main(struct efx_nic *efx)
  875. {
  876. unsigned int bar_size = resource_size(&efx->pci_dev->resource[efx->mem_bar]);
  877. struct ef100_nic_data *nic_data;
  878. char fw_version[32];
  879. u32 priv_mask = 0;
  880. int i, rc;
  881. if (WARN_ON(bar_size == 0))
  882. return -EIO;
  883. nic_data = kzalloc_obj(*nic_data);
  884. if (!nic_data)
  885. return -ENOMEM;
  886. efx->nic_data = nic_data;
  887. nic_data->efx = efx;
  888. efx->max_vis = EF100_MAX_VIS;
  889. /* Populate design-parameter defaults */
  890. nic_data->tso_max_hdr_len = ESE_EF100_DP_GZ_TSO_MAX_HDR_LEN_DEFAULT;
  891. nic_data->tso_max_frames = ESE_EF100_DP_GZ_TSO_MAX_NUM_FRAMES_DEFAULT;
  892. nic_data->tso_max_payload_num_segs = ESE_EF100_DP_GZ_TSO_MAX_PAYLOAD_NUM_SEGS_DEFAULT;
  893. nic_data->tso_max_payload_len = ESE_EF100_DP_GZ_TSO_MAX_PAYLOAD_LEN_DEFAULT;
  894. /* Read design parameters */
  895. rc = ef100_check_design_params(efx);
  896. if (rc) {
  897. pci_err(efx->pci_dev, "Unsupported design parameters\n");
  898. goto fail;
  899. }
  900. /* we assume later that we can copy from this buffer in dwords */
  901. BUILD_BUG_ON(MCDI_CTL_SDU_LEN_MAX_V2 % 4);
  902. /* MCDI buffers must be 256 byte aligned. */
  903. rc = efx_nic_alloc_buffer(efx, &nic_data->mcdi_buf, MCDI_BUF_LEN,
  904. GFP_KERNEL);
  905. if (rc)
  906. goto fail;
  907. /* Get the MC's warm boot count. In case it's rebooting right
  908. * now, be prepared to retry.
  909. */
  910. i = 0;
  911. for (;;) {
  912. rc = ef100_get_warm_boot_count(efx);
  913. if (rc >= 0)
  914. break;
  915. if (++i == 5)
  916. goto fail;
  917. ssleep(1);
  918. }
  919. nic_data->warm_boot_count = rc;
  920. /* In case we're recovering from a crash (kexec), we want to
  921. * cancel any outstanding request by the previous user of this
  922. * function. We send a special message using the least
  923. * significant bits of the 'high' (doorbell) register.
  924. */
  925. _efx_writed(efx, cpu_to_le32(1), efx_reg(efx, ER_GZ_MC_DB_HWRD));
  926. /* Post-IO section. */
  927. rc = efx_mcdi_init(efx);
  928. if (rc)
  929. goto fail;
  930. /* Reset (most) configuration for this function */
  931. rc = efx_mcdi_reset(efx, RESET_TYPE_ALL);
  932. if (rc)
  933. goto fail;
  934. /* Enable event logging */
  935. rc = efx_mcdi_log_ctrl(efx, true, false, 0);
  936. if (rc)
  937. goto fail;
  938. rc = efx_get_pf_index(efx, &nic_data->pf_index);
  939. if (rc)
  940. goto fail;
  941. rc = efx_mcdi_port_get_number(efx);
  942. if (rc < 0)
  943. goto fail;
  944. efx->port_num = rc;
  945. efx_mcdi_print_fwver(efx, fw_version, sizeof(fw_version));
  946. pci_dbg(efx->pci_dev, "Firmware version %s\n", fw_version);
  947. rc = efx_mcdi_get_privilege_mask(efx, &priv_mask);
  948. if (rc) /* non-fatal, and priv_mask will still be 0 */
  949. pci_info(efx->pci_dev,
  950. "Failed to get privilege mask from FW, rc %d\n", rc);
  951. nic_data->grp_mae = !!(priv_mask & MC_CMD_PRIVILEGE_MASK_IN_GRP_MAE);
  952. if (compare_versions(fw_version, "1.1.0.1000") < 0) {
  953. pci_info(efx->pci_dev, "Firmware uses old event descriptors\n");
  954. rc = -EINVAL;
  955. goto fail;
  956. }
  957. if (efx_has_cap(efx, UNSOL_EV_CREDIT_SUPPORTED)) {
  958. pci_info(efx->pci_dev, "Firmware uses unsolicited-event credits\n");
  959. rc = -EINVAL;
  960. goto fail;
  961. }
  962. return 0;
  963. fail:
  964. return rc;
  965. }
  966. /* MCDI commands are related to the same device issuing them. This function
  967. * allows to do an MCDI command on behalf of another device, mainly PFs setting
  968. * things for VFs.
  969. */
  970. int efx_ef100_lookup_client_id(struct efx_nic *efx, efx_qword_t pciefn, u32 *id)
  971. {
  972. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLIENT_HANDLE_OUT_LEN);
  973. MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_CLIENT_HANDLE_IN_LEN);
  974. u64 pciefn_flat = le64_to_cpu(pciefn.u64[0]);
  975. size_t outlen;
  976. int rc;
  977. MCDI_SET_DWORD(inbuf, GET_CLIENT_HANDLE_IN_TYPE,
  978. MC_CMD_GET_CLIENT_HANDLE_IN_TYPE_FUNC);
  979. MCDI_SET_QWORD(inbuf, GET_CLIENT_HANDLE_IN_FUNC,
  980. pciefn_flat);
  981. rc = efx_mcdi_rpc(efx, MC_CMD_GET_CLIENT_HANDLE, inbuf, sizeof(inbuf),
  982. outbuf, sizeof(outbuf), &outlen);
  983. if (rc)
  984. return rc;
  985. if (outlen < sizeof(outbuf))
  986. return -EIO;
  987. *id = MCDI_DWORD(outbuf, GET_CLIENT_HANDLE_OUT_HANDLE);
  988. return 0;
  989. }
  990. int ef100_probe_netdev_pf(struct efx_nic *efx)
  991. {
  992. struct ef100_nic_data *nic_data = efx->nic_data;
  993. struct net_device *net_dev = efx->net_dev;
  994. int rc;
  995. if (!IS_ENABLED(CONFIG_SFC_SRIOV) || !nic_data->grp_mae)
  996. return 0;
  997. rc = efx_init_struct_tc(efx);
  998. if (rc)
  999. return rc;
  1000. rc = efx_ef100_get_base_mport(efx);
  1001. if (rc) {
  1002. netif_warn(efx, probe, net_dev,
  1003. "Failed to probe base mport rc %d; representors will not function\n",
  1004. rc);
  1005. }
  1006. rc = efx_init_mae(efx);
  1007. if (rc)
  1008. netif_warn(efx, probe, net_dev,
  1009. "Failed to init MAE rc %d; representors will not function\n",
  1010. rc);
  1011. else
  1012. efx_ef100_init_reps(efx);
  1013. rc = efx_init_tc(efx);
  1014. if (rc) {
  1015. /* Either we don't have an MAE at all (i.e. legacy v-switching),
  1016. * or we do but we failed to probe it. In the latter case, we
  1017. * may not have set up default rules, in which case we won't be
  1018. * able to pass any traffic. However, we don't fail the probe,
  1019. * because the user might need to use the netdevice to apply
  1020. * configuration changes to fix whatever's wrong with the MAE.
  1021. */
  1022. netif_warn(efx, probe, net_dev, "Failed to probe MAE rc %d\n",
  1023. rc);
  1024. } else {
  1025. net_dev->features |= NETIF_F_HW_TC;
  1026. efx->fixed_features |= NETIF_F_HW_TC;
  1027. }
  1028. return 0;
  1029. }
  1030. int ef100_probe_vf(struct efx_nic *efx)
  1031. {
  1032. return ef100_probe_main(efx);
  1033. }
  1034. void ef100_remove(struct efx_nic *efx)
  1035. {
  1036. struct ef100_nic_data *nic_data = efx->nic_data;
  1037. if (IS_ENABLED(CONFIG_SFC_SRIOV) && efx->mae) {
  1038. efx_ef100_fini_reps(efx);
  1039. efx_fini_mae(efx);
  1040. }
  1041. efx_mcdi_detach(efx);
  1042. efx_mcdi_fini(efx);
  1043. if (nic_data)
  1044. efx_nic_free_buffer(efx, &nic_data->mcdi_buf);
  1045. kfree(nic_data);
  1046. efx->nic_data = NULL;
  1047. }
  1048. /* NIC level access functions
  1049. */
  1050. #define EF100_OFFLOAD_FEATURES (NETIF_F_HW_CSUM | NETIF_F_RXCSUM | \
  1051. NETIF_F_HIGHDMA | NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_NTUPLE | \
  1052. NETIF_F_RXHASH | NETIF_F_RXFCS | NETIF_F_TSO_ECN | NETIF_F_RXALL | \
  1053. NETIF_F_HW_VLAN_CTAG_TX)
  1054. const struct efx_nic_type ef100_pf_nic_type = {
  1055. .revision = EFX_REV_EF100,
  1056. .is_vf = false,
  1057. .probe = ef100_probe_main,
  1058. .offload_features = EF100_OFFLOAD_FEATURES,
  1059. .mcdi_max_ver = 2,
  1060. .mcdi_request = ef100_mcdi_request,
  1061. .mcdi_poll_response = ef100_mcdi_poll_response,
  1062. .mcdi_read_response = ef100_mcdi_read_response,
  1063. .mcdi_poll_reboot = ef100_mcdi_poll_reboot,
  1064. .mcdi_reboot_detected = ef100_mcdi_reboot_detected,
  1065. .irq_enable_master = efx_port_dummy_op_void,
  1066. .irq_test_generate = efx_ef100_irq_test_generate,
  1067. .irq_disable_non_ev = efx_port_dummy_op_void,
  1068. .push_irq_moderation = efx_channel_dummy_op_void,
  1069. .min_interrupt_mode = EFX_INT_MODE_MSIX,
  1070. .map_reset_reason = ef100_map_reset_reason,
  1071. .map_reset_flags = ef100_map_reset_flags,
  1072. .reset = ef100_reset,
  1073. .check_caps = ef100_check_caps,
  1074. .ev_probe = ef100_ev_probe,
  1075. .ev_init = ef100_ev_init,
  1076. .ev_fini = efx_mcdi_ev_fini,
  1077. .ev_remove = efx_mcdi_ev_remove,
  1078. .irq_handle_msi = ef100_msi_interrupt,
  1079. .ev_process = ef100_ev_process,
  1080. .ev_read_ack = ef100_ev_read_ack,
  1081. .ev_test_generate = efx_ef100_ev_test_generate,
  1082. .tx_probe = ef100_tx_probe,
  1083. .tx_init = ef100_tx_init,
  1084. .tx_write = ef100_tx_write,
  1085. .tx_enqueue = ef100_enqueue_skb,
  1086. .rx_probe = efx_mcdi_rx_probe,
  1087. .rx_init = efx_mcdi_rx_init,
  1088. .rx_remove = efx_mcdi_rx_remove,
  1089. .rx_write = ef100_rx_write,
  1090. .rx_packet = __ef100_rx_packet,
  1091. .rx_buf_hash_valid = ef100_rx_buf_hash_valid,
  1092. .fini_dmaq = efx_fini_dmaq,
  1093. .max_rx_ip_filters = EFX_MCDI_FILTER_TBL_ROWS,
  1094. .filter_table_probe = ef100_filter_table_up,
  1095. .filter_table_restore = efx_mcdi_filter_table_restore,
  1096. .filter_table_remove = ef100_filter_table_down,
  1097. .filter_insert = efx_mcdi_filter_insert,
  1098. .filter_remove_safe = efx_mcdi_filter_remove_safe,
  1099. .filter_get_safe = efx_mcdi_filter_get_safe,
  1100. .filter_clear_rx = efx_mcdi_filter_clear_rx,
  1101. .filter_count_rx_used = efx_mcdi_filter_count_rx_used,
  1102. .filter_get_rx_id_limit = efx_mcdi_filter_get_rx_id_limit,
  1103. .filter_get_rx_ids = efx_mcdi_filter_get_rx_ids,
  1104. #ifdef CONFIG_RFS_ACCEL
  1105. .filter_rfs_expire_one = efx_mcdi_filter_rfs_expire_one,
  1106. #endif
  1107. .get_phys_port_id = efx_ef100_get_phys_port_id,
  1108. .rx_prefix_size = ESE_GZ_RX_PKT_PREFIX_LEN,
  1109. .rx_hash_offset = ESF_GZ_RX_PREFIX_RSS_HASH_LBN / 8,
  1110. .rx_ts_offset = ESF_GZ_RX_PREFIX_PARTIAL_TSTAMP_LBN / 8,
  1111. .rx_hash_key_size = 40,
  1112. .rx_pull_rss_config = efx_mcdi_rx_pull_rss_config,
  1113. .rx_push_rss_config = efx_mcdi_pf_rx_push_rss_config,
  1114. .rx_push_rss_context_config = efx_mcdi_rx_push_rss_context_config,
  1115. .rx_pull_rss_context_config = efx_mcdi_rx_pull_rss_context_config,
  1116. .rx_restore_rss_contexts = efx_mcdi_rx_restore_rss_contexts,
  1117. .rx_recycle_ring_size = efx_ef100_recycle_ring_size,
  1118. .reconfigure_mac = ef100_reconfigure_mac,
  1119. .reconfigure_port = efx_mcdi_port_reconfigure,
  1120. .test_nvram = efx_new_mcdi_nvram_test_all,
  1121. .describe_stats = ef100_describe_stats,
  1122. .start_stats = efx_mcdi_mac_start_stats,
  1123. .update_stats = ef100_update_stats,
  1124. .pull_stats = efx_mcdi_mac_pull_stats,
  1125. .stop_stats = efx_mcdi_mac_stop_stats,
  1126. .sriov_configure = IS_ENABLED(CONFIG_SFC_SRIOV) ?
  1127. efx_ef100_sriov_configure : NULL,
  1128. /* Per-type bar/size configuration not used on ef100. Location of
  1129. * registers is defined by extended capabilities.
  1130. */
  1131. .mem_bar = NULL,
  1132. .mem_map_size = NULL,
  1133. };
  1134. const struct efx_nic_type ef100_vf_nic_type = {
  1135. .revision = EFX_REV_EF100,
  1136. .is_vf = true,
  1137. .probe = ef100_probe_vf,
  1138. .offload_features = EF100_OFFLOAD_FEATURES,
  1139. .mcdi_max_ver = 2,
  1140. .mcdi_request = ef100_mcdi_request,
  1141. .mcdi_poll_response = ef100_mcdi_poll_response,
  1142. .mcdi_read_response = ef100_mcdi_read_response,
  1143. .mcdi_poll_reboot = ef100_mcdi_poll_reboot,
  1144. .mcdi_reboot_detected = ef100_mcdi_reboot_detected,
  1145. .irq_enable_master = efx_port_dummy_op_void,
  1146. .irq_test_generate = efx_ef100_irq_test_generate,
  1147. .irq_disable_non_ev = efx_port_dummy_op_void,
  1148. .push_irq_moderation = efx_channel_dummy_op_void,
  1149. .min_interrupt_mode = EFX_INT_MODE_MSIX,
  1150. .map_reset_reason = ef100_map_reset_reason,
  1151. .map_reset_flags = ef100_map_reset_flags,
  1152. .reset = ef100_reset,
  1153. .check_caps = ef100_check_caps,
  1154. .ev_probe = ef100_ev_probe,
  1155. .ev_init = ef100_ev_init,
  1156. .ev_fini = efx_mcdi_ev_fini,
  1157. .ev_remove = efx_mcdi_ev_remove,
  1158. .irq_handle_msi = ef100_msi_interrupt,
  1159. .ev_process = ef100_ev_process,
  1160. .ev_read_ack = ef100_ev_read_ack,
  1161. .ev_test_generate = efx_ef100_ev_test_generate,
  1162. .tx_probe = ef100_tx_probe,
  1163. .tx_init = ef100_tx_init,
  1164. .tx_write = ef100_tx_write,
  1165. .tx_enqueue = ef100_enqueue_skb,
  1166. .rx_probe = efx_mcdi_rx_probe,
  1167. .rx_init = efx_mcdi_rx_init,
  1168. .rx_remove = efx_mcdi_rx_remove,
  1169. .rx_write = ef100_rx_write,
  1170. .rx_packet = __ef100_rx_packet,
  1171. .rx_buf_hash_valid = ef100_rx_buf_hash_valid,
  1172. .fini_dmaq = efx_fini_dmaq,
  1173. .max_rx_ip_filters = EFX_MCDI_FILTER_TBL_ROWS,
  1174. .filter_table_probe = ef100_filter_table_up,
  1175. .filter_table_restore = efx_mcdi_filter_table_restore,
  1176. .filter_table_remove = ef100_filter_table_down,
  1177. .filter_insert = efx_mcdi_filter_insert,
  1178. .filter_remove_safe = efx_mcdi_filter_remove_safe,
  1179. .filter_get_safe = efx_mcdi_filter_get_safe,
  1180. .filter_clear_rx = efx_mcdi_filter_clear_rx,
  1181. .filter_count_rx_used = efx_mcdi_filter_count_rx_used,
  1182. .filter_get_rx_id_limit = efx_mcdi_filter_get_rx_id_limit,
  1183. .filter_get_rx_ids = efx_mcdi_filter_get_rx_ids,
  1184. #ifdef CONFIG_RFS_ACCEL
  1185. .filter_rfs_expire_one = efx_mcdi_filter_rfs_expire_one,
  1186. #endif
  1187. .rx_prefix_size = ESE_GZ_RX_PKT_PREFIX_LEN,
  1188. .rx_hash_offset = ESF_GZ_RX_PREFIX_RSS_HASH_LBN / 8,
  1189. .rx_ts_offset = ESF_GZ_RX_PREFIX_PARTIAL_TSTAMP_LBN / 8,
  1190. .rx_hash_key_size = 40,
  1191. .rx_pull_rss_config = efx_mcdi_rx_pull_rss_config,
  1192. .rx_push_rss_config = efx_mcdi_pf_rx_push_rss_config,
  1193. .rx_restore_rss_contexts = efx_mcdi_rx_restore_rss_contexts,
  1194. .rx_recycle_ring_size = efx_ef100_recycle_ring_size,
  1195. .reconfigure_mac = ef100_reconfigure_mac,
  1196. .test_nvram = efx_new_mcdi_nvram_test_all,
  1197. .describe_stats = ef100_describe_stats,
  1198. .start_stats = efx_mcdi_mac_start_stats,
  1199. .update_stats = ef100_update_stats,
  1200. .pull_stats = efx_mcdi_mac_pull_stats,
  1201. .stop_stats = efx_mcdi_mac_stop_stats,
  1202. .mem_bar = NULL,
  1203. .mem_map_size = NULL,
  1204. };