nic.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2006-2009 Solarflare Communications Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation, incorporated herein by reference.
  9. */
  10. #include <linux/bitops.h>
  11. #include <linux/delay.h>
  12. #include <linux/pci.h>
  13. #include <linux/module.h>
  14. #include <linux/seq_file.h>
  15. #include "net_driver.h"
  16. #include "bitfield.h"
  17. #include "efx.h"
  18. #include "nic.h"
  19. #include "regs.h"
  20. #include "io.h"
  21. #include "workarounds.h"
  22. /**************************************************************************
  23. *
  24. * Configurable values
  25. *
  26. **************************************************************************
  27. */
  28. /* This is set to 16 for a good reason. In summary, if larger than
  29. * 16, the descriptor cache holds more than a default socket
  30. * buffer's worth of packets (for UDP we can only have at most one
  31. * socket buffer's worth outstanding). This combined with the fact
  32. * that we only get 1 TX event per descriptor cache means the NIC
  33. * goes idle.
  34. */
  35. #define TX_DC_ENTRIES 16
  36. #define TX_DC_ENTRIES_ORDER 1
  37. #define RX_DC_ENTRIES 64
  38. #define RX_DC_ENTRIES_ORDER 3
  39. /* RX FIFO XOFF watermark
  40. *
  41. * When the amount of the RX FIFO increases used increases past this
  42. * watermark send XOFF. Only used if RX flow control is enabled (ethtool -A)
  43. * This also has an effect on RX/TX arbitration
  44. */
  45. int efx_nic_rx_xoff_thresh = -1;
  46. module_param_named(rx_xoff_thresh_bytes, efx_nic_rx_xoff_thresh, int, 0644);
  47. MODULE_PARM_DESC(rx_xoff_thresh_bytes, "RX fifo XOFF threshold");
  48. /* RX FIFO XON watermark
  49. *
  50. * When the amount of the RX FIFO used decreases below this
  51. * watermark send XON. Only used if TX flow control is enabled (ethtool -A)
  52. * This also has an effect on RX/TX arbitration
  53. */
  54. int efx_nic_rx_xon_thresh = -1;
  55. module_param_named(rx_xon_thresh_bytes, efx_nic_rx_xon_thresh, int, 0644);
  56. MODULE_PARM_DESC(rx_xon_thresh_bytes, "RX fifo XON threshold");
  57. /* If EFX_MAX_INT_ERRORS internal errors occur within
  58. * EFX_INT_ERROR_EXPIRE seconds, we consider the NIC broken and
  59. * disable it.
  60. */
  61. #define EFX_INT_ERROR_EXPIRE 3600
  62. #define EFX_MAX_INT_ERRORS 5
  63. /* We poll for events every FLUSH_INTERVAL ms, and check FLUSH_POLL_COUNT times
  64. */
  65. #define EFX_FLUSH_INTERVAL 10
  66. #define EFX_FLUSH_POLL_COUNT 100
  67. /* Size and alignment of special buffers (4KB) */
  68. #define EFX_BUF_SIZE 4096
  69. /* Depth of RX flush request fifo */
  70. #define EFX_RX_FLUSH_COUNT 4
  71. /**************************************************************************
  72. *
  73. * Solarstorm hardware access
  74. *
  75. **************************************************************************/
  76. static inline void efx_write_buf_tbl(struct efx_nic *efx, efx_qword_t *value,
  77. unsigned int index)
  78. {
  79. efx_sram_writeq(efx, efx->membase + efx->type->buf_tbl_base,
  80. value, index);
  81. }
  82. /* Read the current event from the event queue */
  83. static inline efx_qword_t *efx_event(struct efx_channel *channel,
  84. unsigned int index)
  85. {
  86. return (((efx_qword_t *) (channel->eventq.addr)) + index);
  87. }
  88. /* See if an event is present
  89. *
  90. * We check both the high and low dword of the event for all ones. We
  91. * wrote all ones when we cleared the event, and no valid event can
  92. * have all ones in either its high or low dwords. This approach is
  93. * robust against reordering.
  94. *
  95. * Note that using a single 64-bit comparison is incorrect; even
  96. * though the CPU read will be atomic, the DMA write may not be.
  97. */
  98. static inline int efx_event_present(efx_qword_t *event)
  99. {
  100. return (!(EFX_DWORD_IS_ALL_ONES(event->dword[0]) |
  101. EFX_DWORD_IS_ALL_ONES(event->dword[1])));
  102. }
  103. static bool efx_masked_compare_oword(const efx_oword_t *a, const efx_oword_t *b,
  104. const efx_oword_t *mask)
  105. {
  106. return ((a->u64[0] ^ b->u64[0]) & mask->u64[0]) ||
  107. ((a->u64[1] ^ b->u64[1]) & mask->u64[1]);
  108. }
  109. int efx_nic_test_registers(struct efx_nic *efx,
  110. const struct efx_nic_register_test *regs,
  111. size_t n_regs)
  112. {
  113. unsigned address = 0, i, j;
  114. efx_oword_t mask, imask, original, reg, buf;
  115. /* Falcon should be in loopback to isolate the XMAC from the PHY */
  116. WARN_ON(!LOOPBACK_INTERNAL(efx));
  117. for (i = 0; i < n_regs; ++i) {
  118. address = regs[i].address;
  119. mask = imask = regs[i].mask;
  120. EFX_INVERT_OWORD(imask);
  121. efx_reado(efx, &original, address);
  122. /* bit sweep on and off */
  123. for (j = 0; j < 128; j++) {
  124. if (!EFX_EXTRACT_OWORD32(mask, j, j))
  125. continue;
  126. /* Test this testable bit can be set in isolation */
  127. EFX_AND_OWORD(reg, original, mask);
  128. EFX_SET_OWORD32(reg, j, j, 1);
  129. efx_writeo(efx, &reg, address);
  130. efx_reado(efx, &buf, address);
  131. if (efx_masked_compare_oword(&reg, &buf, &mask))
  132. goto fail;
  133. /* Test this testable bit can be cleared in isolation */
  134. EFX_OR_OWORD(reg, original, mask);
  135. EFX_SET_OWORD32(reg, j, j, 0);
  136. efx_writeo(efx, &reg, address);
  137. efx_reado(efx, &buf, address);
  138. if (efx_masked_compare_oword(&reg, &buf, &mask))
  139. goto fail;
  140. }
  141. efx_writeo(efx, &original, address);
  142. }
  143. return 0;
  144. fail:
  145. EFX_ERR(efx, "wrote "EFX_OWORD_FMT" read "EFX_OWORD_FMT
  146. " at address 0x%x mask "EFX_OWORD_FMT"\n", EFX_OWORD_VAL(reg),
  147. EFX_OWORD_VAL(buf), address, EFX_OWORD_VAL(mask));
  148. return -EIO;
  149. }
  150. /**************************************************************************
  151. *
  152. * Special buffer handling
  153. * Special buffers are used for event queues and the TX and RX
  154. * descriptor rings.
  155. *
  156. *************************************************************************/
  157. /*
  158. * Initialise a special buffer
  159. *
  160. * This will define a buffer (previously allocated via
  161. * efx_alloc_special_buffer()) in the buffer table, allowing
  162. * it to be used for event queues, descriptor rings etc.
  163. */
  164. static void
  165. efx_init_special_buffer(struct efx_nic *efx, struct efx_special_buffer *buffer)
  166. {
  167. efx_qword_t buf_desc;
  168. int index;
  169. dma_addr_t dma_addr;
  170. int i;
  171. EFX_BUG_ON_PARANOID(!buffer->addr);
  172. /* Write buffer descriptors to NIC */
  173. for (i = 0; i < buffer->entries; i++) {
  174. index = buffer->index + i;
  175. dma_addr = buffer->dma_addr + (i * 4096);
  176. EFX_LOG(efx, "mapping special buffer %d at %llx\n",
  177. index, (unsigned long long)dma_addr);
  178. EFX_POPULATE_QWORD_3(buf_desc,
  179. FRF_AZ_BUF_ADR_REGION, 0,
  180. FRF_AZ_BUF_ADR_FBUF, dma_addr >> 12,
  181. FRF_AZ_BUF_OWNER_ID_FBUF, 0);
  182. efx_write_buf_tbl(efx, &buf_desc, index);
  183. }
  184. }
  185. /* Unmaps a buffer and clears the buffer table entries */
  186. static void
  187. efx_fini_special_buffer(struct efx_nic *efx, struct efx_special_buffer *buffer)
  188. {
  189. efx_oword_t buf_tbl_upd;
  190. unsigned int start = buffer->index;
  191. unsigned int end = (buffer->index + buffer->entries - 1);
  192. if (!buffer->entries)
  193. return;
  194. EFX_LOG(efx, "unmapping special buffers %d-%d\n",
  195. buffer->index, buffer->index + buffer->entries - 1);
  196. EFX_POPULATE_OWORD_4(buf_tbl_upd,
  197. FRF_AZ_BUF_UPD_CMD, 0,
  198. FRF_AZ_BUF_CLR_CMD, 1,
  199. FRF_AZ_BUF_CLR_END_ID, end,
  200. FRF_AZ_BUF_CLR_START_ID, start);
  201. efx_writeo(efx, &buf_tbl_upd, FR_AZ_BUF_TBL_UPD);
  202. }
  203. /*
  204. * Allocate a new special buffer
  205. *
  206. * This allocates memory for a new buffer, clears it and allocates a
  207. * new buffer ID range. It does not write into the buffer table.
  208. *
  209. * This call will allocate 4KB buffers, since 8KB buffers can't be
  210. * used for event queues and descriptor rings.
  211. */
  212. static int efx_alloc_special_buffer(struct efx_nic *efx,
  213. struct efx_special_buffer *buffer,
  214. unsigned int len)
  215. {
  216. len = ALIGN(len, EFX_BUF_SIZE);
  217. buffer->addr = pci_alloc_consistent(efx->pci_dev, len,
  218. &buffer->dma_addr);
  219. if (!buffer->addr)
  220. return -ENOMEM;
  221. buffer->len = len;
  222. buffer->entries = len / EFX_BUF_SIZE;
  223. BUG_ON(buffer->dma_addr & (EFX_BUF_SIZE - 1));
  224. /* All zeros is a potentially valid event so memset to 0xff */
  225. memset(buffer->addr, 0xff, len);
  226. /* Select new buffer ID */
  227. buffer->index = efx->next_buffer_table;
  228. efx->next_buffer_table += buffer->entries;
  229. EFX_LOG(efx, "allocating special buffers %d-%d at %llx+%x "
  230. "(virt %p phys %llx)\n", buffer->index,
  231. buffer->index + buffer->entries - 1,
  232. (u64)buffer->dma_addr, len,
  233. buffer->addr, (u64)virt_to_phys(buffer->addr));
  234. return 0;
  235. }
  236. static void
  237. efx_free_special_buffer(struct efx_nic *efx, struct efx_special_buffer *buffer)
  238. {
  239. if (!buffer->addr)
  240. return;
  241. EFX_LOG(efx, "deallocating special buffers %d-%d at %llx+%x "
  242. "(virt %p phys %llx)\n", buffer->index,
  243. buffer->index + buffer->entries - 1,
  244. (u64)buffer->dma_addr, buffer->len,
  245. buffer->addr, (u64)virt_to_phys(buffer->addr));
  246. pci_free_consistent(efx->pci_dev, buffer->len, buffer->addr,
  247. buffer->dma_addr);
  248. buffer->addr = NULL;
  249. buffer->entries = 0;
  250. }
  251. /**************************************************************************
  252. *
  253. * Generic buffer handling
  254. * These buffers are used for interrupt status and MAC stats
  255. *
  256. **************************************************************************/
  257. int efx_nic_alloc_buffer(struct efx_nic *efx, struct efx_buffer *buffer,
  258. unsigned int len)
  259. {
  260. buffer->addr = pci_alloc_consistent(efx->pci_dev, len,
  261. &buffer->dma_addr);
  262. if (!buffer->addr)
  263. return -ENOMEM;
  264. buffer->len = len;
  265. memset(buffer->addr, 0, len);
  266. return 0;
  267. }
  268. void efx_nic_free_buffer(struct efx_nic *efx, struct efx_buffer *buffer)
  269. {
  270. if (buffer->addr) {
  271. pci_free_consistent(efx->pci_dev, buffer->len,
  272. buffer->addr, buffer->dma_addr);
  273. buffer->addr = NULL;
  274. }
  275. }
  276. /**************************************************************************
  277. *
  278. * TX path
  279. *
  280. **************************************************************************/
  281. /* Returns a pointer to the specified transmit descriptor in the TX
  282. * descriptor queue belonging to the specified channel.
  283. */
  284. static inline efx_qword_t *
  285. efx_tx_desc(struct efx_tx_queue *tx_queue, unsigned int index)
  286. {
  287. return (((efx_qword_t *) (tx_queue->txd.addr)) + index);
  288. }
  289. /* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
  290. static inline void efx_notify_tx_desc(struct efx_tx_queue *tx_queue)
  291. {
  292. unsigned write_ptr;
  293. efx_dword_t reg;
  294. write_ptr = tx_queue->write_count & EFX_TXQ_MASK;
  295. EFX_POPULATE_DWORD_1(reg, FRF_AZ_TX_DESC_WPTR_DWORD, write_ptr);
  296. efx_writed_page(tx_queue->efx, &reg,
  297. FR_AZ_TX_DESC_UPD_DWORD_P0, tx_queue->queue);
  298. }
  299. /* For each entry inserted into the software descriptor ring, create a
  300. * descriptor in the hardware TX descriptor ring (in host memory), and
  301. * write a doorbell.
  302. */
  303. void efx_nic_push_buffers(struct efx_tx_queue *tx_queue)
  304. {
  305. struct efx_tx_buffer *buffer;
  306. efx_qword_t *txd;
  307. unsigned write_ptr;
  308. BUG_ON(tx_queue->write_count == tx_queue->insert_count);
  309. do {
  310. write_ptr = tx_queue->write_count & EFX_TXQ_MASK;
  311. buffer = &tx_queue->buffer[write_ptr];
  312. txd = efx_tx_desc(tx_queue, write_ptr);
  313. ++tx_queue->write_count;
  314. /* Create TX descriptor ring entry */
  315. EFX_POPULATE_QWORD_4(*txd,
  316. FSF_AZ_TX_KER_CONT, buffer->continuation,
  317. FSF_AZ_TX_KER_BYTE_COUNT, buffer->len,
  318. FSF_AZ_TX_KER_BUF_REGION, 0,
  319. FSF_AZ_TX_KER_BUF_ADDR, buffer->dma_addr);
  320. } while (tx_queue->write_count != tx_queue->insert_count);
  321. wmb(); /* Ensure descriptors are written before they are fetched */
  322. efx_notify_tx_desc(tx_queue);
  323. }
  324. /* Allocate hardware resources for a TX queue */
  325. int efx_nic_probe_tx(struct efx_tx_queue *tx_queue)
  326. {
  327. struct efx_nic *efx = tx_queue->efx;
  328. BUILD_BUG_ON(EFX_TXQ_SIZE < 512 || EFX_TXQ_SIZE > 4096 ||
  329. EFX_TXQ_SIZE & EFX_TXQ_MASK);
  330. return efx_alloc_special_buffer(efx, &tx_queue->txd,
  331. EFX_TXQ_SIZE * sizeof(efx_qword_t));
  332. }
  333. void efx_nic_init_tx(struct efx_tx_queue *tx_queue)
  334. {
  335. efx_oword_t tx_desc_ptr;
  336. struct efx_nic *efx = tx_queue->efx;
  337. tx_queue->flushed = FLUSH_NONE;
  338. /* Pin TX descriptor ring */
  339. efx_init_special_buffer(efx, &tx_queue->txd);
  340. /* Push TX descriptor ring to card */
  341. EFX_POPULATE_OWORD_10(tx_desc_ptr,
  342. FRF_AZ_TX_DESCQ_EN, 1,
  343. FRF_AZ_TX_ISCSI_DDIG_EN, 0,
  344. FRF_AZ_TX_ISCSI_HDIG_EN, 0,
  345. FRF_AZ_TX_DESCQ_BUF_BASE_ID, tx_queue->txd.index,
  346. FRF_AZ_TX_DESCQ_EVQ_ID,
  347. tx_queue->channel->channel,
  348. FRF_AZ_TX_DESCQ_OWNER_ID, 0,
  349. FRF_AZ_TX_DESCQ_LABEL, tx_queue->queue,
  350. FRF_AZ_TX_DESCQ_SIZE,
  351. __ffs(tx_queue->txd.entries),
  352. FRF_AZ_TX_DESCQ_TYPE, 0,
  353. FRF_BZ_TX_NON_IP_DROP_DIS, 1);
  354. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) {
  355. int csum = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD;
  356. EFX_SET_OWORD_FIELD(tx_desc_ptr, FRF_BZ_TX_IP_CHKSM_DIS, !csum);
  357. EFX_SET_OWORD_FIELD(tx_desc_ptr, FRF_BZ_TX_TCP_CHKSM_DIS,
  358. !csum);
  359. }
  360. efx_writeo_table(efx, &tx_desc_ptr, efx->type->txd_ptr_tbl_base,
  361. tx_queue->queue);
  362. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0) {
  363. efx_oword_t reg;
  364. /* Only 128 bits in this register */
  365. BUILD_BUG_ON(EFX_MAX_TX_QUEUES > 128);
  366. efx_reado(efx, &reg, FR_AA_TX_CHKSM_CFG);
  367. if (tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD)
  368. clear_bit_le(tx_queue->queue, (void *)&reg);
  369. else
  370. set_bit_le(tx_queue->queue, (void *)&reg);
  371. efx_writeo(efx, &reg, FR_AA_TX_CHKSM_CFG);
  372. }
  373. }
  374. static void efx_flush_tx_queue(struct efx_tx_queue *tx_queue)
  375. {
  376. struct efx_nic *efx = tx_queue->efx;
  377. efx_oword_t tx_flush_descq;
  378. tx_queue->flushed = FLUSH_PENDING;
  379. /* Post a flush command */
  380. EFX_POPULATE_OWORD_2(tx_flush_descq,
  381. FRF_AZ_TX_FLUSH_DESCQ_CMD, 1,
  382. FRF_AZ_TX_FLUSH_DESCQ, tx_queue->queue);
  383. efx_writeo(efx, &tx_flush_descq, FR_AZ_TX_FLUSH_DESCQ);
  384. }
  385. void efx_nic_fini_tx(struct efx_tx_queue *tx_queue)
  386. {
  387. struct efx_nic *efx = tx_queue->efx;
  388. efx_oword_t tx_desc_ptr;
  389. /* The queue should have been flushed */
  390. WARN_ON(tx_queue->flushed != FLUSH_DONE);
  391. /* Remove TX descriptor ring from card */
  392. EFX_ZERO_OWORD(tx_desc_ptr);
  393. efx_writeo_table(efx, &tx_desc_ptr, efx->type->txd_ptr_tbl_base,
  394. tx_queue->queue);
  395. /* Unpin TX descriptor ring */
  396. efx_fini_special_buffer(efx, &tx_queue->txd);
  397. }
  398. /* Free buffers backing TX queue */
  399. void efx_nic_remove_tx(struct efx_tx_queue *tx_queue)
  400. {
  401. efx_free_special_buffer(tx_queue->efx, &tx_queue->txd);
  402. }
  403. /**************************************************************************
  404. *
  405. * RX path
  406. *
  407. **************************************************************************/
  408. /* Returns a pointer to the specified descriptor in the RX descriptor queue */
  409. static inline efx_qword_t *
  410. efx_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
  411. {
  412. return (((efx_qword_t *) (rx_queue->rxd.addr)) + index);
  413. }
  414. /* This creates an entry in the RX descriptor queue */
  415. static inline void
  416. efx_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned index)
  417. {
  418. struct efx_rx_buffer *rx_buf;
  419. efx_qword_t *rxd;
  420. rxd = efx_rx_desc(rx_queue, index);
  421. rx_buf = efx_rx_buffer(rx_queue, index);
  422. EFX_POPULATE_QWORD_3(*rxd,
  423. FSF_AZ_RX_KER_BUF_SIZE,
  424. rx_buf->len -
  425. rx_queue->efx->type->rx_buffer_padding,
  426. FSF_AZ_RX_KER_BUF_REGION, 0,
  427. FSF_AZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
  428. }
  429. /* This writes to the RX_DESC_WPTR register for the specified receive
  430. * descriptor ring.
  431. */
  432. void efx_nic_notify_rx_desc(struct efx_rx_queue *rx_queue)
  433. {
  434. efx_dword_t reg;
  435. unsigned write_ptr;
  436. while (rx_queue->notified_count != rx_queue->added_count) {
  437. efx_build_rx_desc(rx_queue,
  438. rx_queue->notified_count &
  439. EFX_RXQ_MASK);
  440. ++rx_queue->notified_count;
  441. }
  442. wmb();
  443. write_ptr = rx_queue->added_count & EFX_RXQ_MASK;
  444. EFX_POPULATE_DWORD_1(reg, FRF_AZ_RX_DESC_WPTR_DWORD, write_ptr);
  445. efx_writed_page(rx_queue->efx, &reg,
  446. FR_AZ_RX_DESC_UPD_DWORD_P0, rx_queue->queue);
  447. }
  448. int efx_nic_probe_rx(struct efx_rx_queue *rx_queue)
  449. {
  450. struct efx_nic *efx = rx_queue->efx;
  451. BUILD_BUG_ON(EFX_RXQ_SIZE < 512 || EFX_RXQ_SIZE > 4096 ||
  452. EFX_RXQ_SIZE & EFX_RXQ_MASK);
  453. return efx_alloc_special_buffer(efx, &rx_queue->rxd,
  454. EFX_RXQ_SIZE * sizeof(efx_qword_t));
  455. }
  456. void efx_nic_init_rx(struct efx_rx_queue *rx_queue)
  457. {
  458. efx_oword_t rx_desc_ptr;
  459. struct efx_nic *efx = rx_queue->efx;
  460. bool is_b0 = efx_nic_rev(efx) >= EFX_REV_FALCON_B0;
  461. bool iscsi_digest_en = is_b0;
  462. EFX_LOG(efx, "RX queue %d ring in special buffers %d-%d\n",
  463. rx_queue->queue, rx_queue->rxd.index,
  464. rx_queue->rxd.index + rx_queue->rxd.entries - 1);
  465. rx_queue->flushed = FLUSH_NONE;
  466. /* Pin RX descriptor ring */
  467. efx_init_special_buffer(efx, &rx_queue->rxd);
  468. /* Push RX descriptor ring to card */
  469. EFX_POPULATE_OWORD_10(rx_desc_ptr,
  470. FRF_AZ_RX_ISCSI_DDIG_EN, iscsi_digest_en,
  471. FRF_AZ_RX_ISCSI_HDIG_EN, iscsi_digest_en,
  472. FRF_AZ_RX_DESCQ_BUF_BASE_ID, rx_queue->rxd.index,
  473. FRF_AZ_RX_DESCQ_EVQ_ID,
  474. rx_queue->channel->channel,
  475. FRF_AZ_RX_DESCQ_OWNER_ID, 0,
  476. FRF_AZ_RX_DESCQ_LABEL, rx_queue->queue,
  477. FRF_AZ_RX_DESCQ_SIZE,
  478. __ffs(rx_queue->rxd.entries),
  479. FRF_AZ_RX_DESCQ_TYPE, 0 /* kernel queue */ ,
  480. /* For >=B0 this is scatter so disable */
  481. FRF_AZ_RX_DESCQ_JUMBO, !is_b0,
  482. FRF_AZ_RX_DESCQ_EN, 1);
  483. efx_writeo_table(efx, &rx_desc_ptr, efx->type->rxd_ptr_tbl_base,
  484. rx_queue->queue);
  485. }
  486. static void efx_flush_rx_queue(struct efx_rx_queue *rx_queue)
  487. {
  488. struct efx_nic *efx = rx_queue->efx;
  489. efx_oword_t rx_flush_descq;
  490. rx_queue->flushed = FLUSH_PENDING;
  491. /* Post a flush command */
  492. EFX_POPULATE_OWORD_2(rx_flush_descq,
  493. FRF_AZ_RX_FLUSH_DESCQ_CMD, 1,
  494. FRF_AZ_RX_FLUSH_DESCQ, rx_queue->queue);
  495. efx_writeo(efx, &rx_flush_descq, FR_AZ_RX_FLUSH_DESCQ);
  496. }
  497. void efx_nic_fini_rx(struct efx_rx_queue *rx_queue)
  498. {
  499. efx_oword_t rx_desc_ptr;
  500. struct efx_nic *efx = rx_queue->efx;
  501. /* The queue should already have been flushed */
  502. WARN_ON(rx_queue->flushed != FLUSH_DONE);
  503. /* Remove RX descriptor ring from card */
  504. EFX_ZERO_OWORD(rx_desc_ptr);
  505. efx_writeo_table(efx, &rx_desc_ptr, efx->type->rxd_ptr_tbl_base,
  506. rx_queue->queue);
  507. /* Unpin RX descriptor ring */
  508. efx_fini_special_buffer(efx, &rx_queue->rxd);
  509. }
  510. /* Free buffers backing RX queue */
  511. void efx_nic_remove_rx(struct efx_rx_queue *rx_queue)
  512. {
  513. efx_free_special_buffer(rx_queue->efx, &rx_queue->rxd);
  514. }
  515. /**************************************************************************
  516. *
  517. * Event queue processing
  518. * Event queues are processed by per-channel tasklets.
  519. *
  520. **************************************************************************/
  521. /* Update a channel's event queue's read pointer (RPTR) register
  522. *
  523. * This writes the EVQ_RPTR_REG register for the specified channel's
  524. * event queue.
  525. */
  526. void efx_nic_eventq_read_ack(struct efx_channel *channel)
  527. {
  528. efx_dword_t reg;
  529. struct efx_nic *efx = channel->efx;
  530. EFX_POPULATE_DWORD_1(reg, FRF_AZ_EVQ_RPTR, channel->eventq_read_ptr);
  531. efx_writed_table(efx, &reg, efx->type->evq_rptr_tbl_base,
  532. channel->channel);
  533. }
  534. /* Use HW to insert a SW defined event */
  535. void efx_generate_event(struct efx_channel *channel, efx_qword_t *event)
  536. {
  537. efx_oword_t drv_ev_reg;
  538. BUILD_BUG_ON(FRF_AZ_DRV_EV_DATA_LBN != 0 ||
  539. FRF_AZ_DRV_EV_DATA_WIDTH != 64);
  540. drv_ev_reg.u32[0] = event->u32[0];
  541. drv_ev_reg.u32[1] = event->u32[1];
  542. drv_ev_reg.u32[2] = 0;
  543. drv_ev_reg.u32[3] = 0;
  544. EFX_SET_OWORD_FIELD(drv_ev_reg, FRF_AZ_DRV_EV_QID, channel->channel);
  545. efx_writeo(channel->efx, &drv_ev_reg, FR_AZ_DRV_EV);
  546. }
  547. /* Handle a transmit completion event
  548. *
  549. * The NIC batches TX completion events; the message we receive is of
  550. * the form "complete all TX events up to this index".
  551. */
  552. static int
  553. efx_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
  554. {
  555. unsigned int tx_ev_desc_ptr;
  556. unsigned int tx_ev_q_label;
  557. struct efx_tx_queue *tx_queue;
  558. struct efx_nic *efx = channel->efx;
  559. int tx_packets = 0;
  560. if (likely(EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_COMP))) {
  561. /* Transmit completion */
  562. tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_DESC_PTR);
  563. tx_ev_q_label = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_Q_LABEL);
  564. tx_queue = &efx->tx_queue[tx_ev_q_label];
  565. tx_packets = ((tx_ev_desc_ptr - tx_queue->read_count) &
  566. EFX_TXQ_MASK);
  567. channel->irq_mod_score += tx_packets;
  568. efx_xmit_done(tx_queue, tx_ev_desc_ptr);
  569. } else if (EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_WQ_FF_FULL)) {
  570. /* Rewrite the FIFO write pointer */
  571. tx_ev_q_label = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_Q_LABEL);
  572. tx_queue = &efx->tx_queue[tx_ev_q_label];
  573. if (efx_dev_registered(efx))
  574. netif_tx_lock(efx->net_dev);
  575. efx_notify_tx_desc(tx_queue);
  576. if (efx_dev_registered(efx))
  577. netif_tx_unlock(efx->net_dev);
  578. } else if (EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_PKT_ERR) &&
  579. EFX_WORKAROUND_10727(efx)) {
  580. efx_schedule_reset(efx, RESET_TYPE_TX_DESC_FETCH);
  581. } else {
  582. EFX_ERR(efx, "channel %d unexpected TX event "
  583. EFX_QWORD_FMT"\n", channel->channel,
  584. EFX_QWORD_VAL(*event));
  585. }
  586. return tx_packets;
  587. }
  588. /* Detect errors included in the rx_evt_pkt_ok bit. */
  589. static void efx_handle_rx_not_ok(struct efx_rx_queue *rx_queue,
  590. const efx_qword_t *event,
  591. bool *rx_ev_pkt_ok,
  592. bool *discard)
  593. {
  594. struct efx_nic *efx = rx_queue->efx;
  595. bool rx_ev_buf_owner_id_err, rx_ev_ip_hdr_chksum_err;
  596. bool rx_ev_tcp_udp_chksum_err, rx_ev_eth_crc_err;
  597. bool rx_ev_frm_trunc, rx_ev_drib_nib, rx_ev_tobe_disc;
  598. bool rx_ev_other_err, rx_ev_pause_frm;
  599. bool rx_ev_hdr_type, rx_ev_mcast_pkt;
  600. unsigned rx_ev_pkt_type;
  601. rx_ev_hdr_type = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_HDR_TYPE);
  602. rx_ev_mcast_pkt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_PKT);
  603. rx_ev_tobe_disc = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_TOBE_DISC);
  604. rx_ev_pkt_type = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_PKT_TYPE);
  605. rx_ev_buf_owner_id_err = EFX_QWORD_FIELD(*event,
  606. FSF_AZ_RX_EV_BUF_OWNER_ID_ERR);
  607. rx_ev_ip_hdr_chksum_err = EFX_QWORD_FIELD(*event,
  608. FSF_AZ_RX_EV_IP_HDR_CHKSUM_ERR);
  609. rx_ev_tcp_udp_chksum_err = EFX_QWORD_FIELD(*event,
  610. FSF_AZ_RX_EV_TCP_UDP_CHKSUM_ERR);
  611. rx_ev_eth_crc_err = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_ETH_CRC_ERR);
  612. rx_ev_frm_trunc = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_FRM_TRUNC);
  613. rx_ev_drib_nib = ((efx_nic_rev(efx) >= EFX_REV_FALCON_B0) ?
  614. 0 : EFX_QWORD_FIELD(*event, FSF_AA_RX_EV_DRIB_NIB));
  615. rx_ev_pause_frm = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_PAUSE_FRM_ERR);
  616. /* Every error apart from tobe_disc and pause_frm */
  617. rx_ev_other_err = (rx_ev_drib_nib | rx_ev_tcp_udp_chksum_err |
  618. rx_ev_buf_owner_id_err | rx_ev_eth_crc_err |
  619. rx_ev_frm_trunc | rx_ev_ip_hdr_chksum_err);
  620. /* Count errors that are not in MAC stats. Ignore expected
  621. * checksum errors during self-test. */
  622. if (rx_ev_frm_trunc)
  623. ++rx_queue->channel->n_rx_frm_trunc;
  624. else if (rx_ev_tobe_disc)
  625. ++rx_queue->channel->n_rx_tobe_disc;
  626. else if (!efx->loopback_selftest) {
  627. if (rx_ev_ip_hdr_chksum_err)
  628. ++rx_queue->channel->n_rx_ip_hdr_chksum_err;
  629. else if (rx_ev_tcp_udp_chksum_err)
  630. ++rx_queue->channel->n_rx_tcp_udp_chksum_err;
  631. }
  632. /* The frame must be discarded if any of these are true. */
  633. *discard = (rx_ev_eth_crc_err | rx_ev_frm_trunc | rx_ev_drib_nib |
  634. rx_ev_tobe_disc | rx_ev_pause_frm);
  635. /* TOBE_DISC is expected on unicast mismatches; don't print out an
  636. * error message. FRM_TRUNC indicates RXDP dropped the packet due
  637. * to a FIFO overflow.
  638. */
  639. #ifdef EFX_ENABLE_DEBUG
  640. if (rx_ev_other_err) {
  641. EFX_INFO_RL(efx, " RX queue %d unexpected RX event "
  642. EFX_QWORD_FMT "%s%s%s%s%s%s%s%s\n",
  643. rx_queue->queue, EFX_QWORD_VAL(*event),
  644. rx_ev_buf_owner_id_err ? " [OWNER_ID_ERR]" : "",
  645. rx_ev_ip_hdr_chksum_err ?
  646. " [IP_HDR_CHKSUM_ERR]" : "",
  647. rx_ev_tcp_udp_chksum_err ?
  648. " [TCP_UDP_CHKSUM_ERR]" : "",
  649. rx_ev_eth_crc_err ? " [ETH_CRC_ERR]" : "",
  650. rx_ev_frm_trunc ? " [FRM_TRUNC]" : "",
  651. rx_ev_drib_nib ? " [DRIB_NIB]" : "",
  652. rx_ev_tobe_disc ? " [TOBE_DISC]" : "",
  653. rx_ev_pause_frm ? " [PAUSE]" : "");
  654. }
  655. #endif
  656. }
  657. /* Handle receive events that are not in-order. */
  658. static void
  659. efx_handle_rx_bad_index(struct efx_rx_queue *rx_queue, unsigned index)
  660. {
  661. struct efx_nic *efx = rx_queue->efx;
  662. unsigned expected, dropped;
  663. expected = rx_queue->removed_count & EFX_RXQ_MASK;
  664. dropped = (index - expected) & EFX_RXQ_MASK;
  665. EFX_INFO(efx, "dropped %d events (index=%d expected=%d)\n",
  666. dropped, index, expected);
  667. efx_schedule_reset(efx, EFX_WORKAROUND_5676(efx) ?
  668. RESET_TYPE_RX_RECOVERY : RESET_TYPE_DISABLE);
  669. }
  670. /* Handle a packet received event
  671. *
  672. * The NIC gives a "discard" flag if it's a unicast packet with the
  673. * wrong destination address
  674. * Also "is multicast" and "matches multicast filter" flags can be used to
  675. * discard non-matching multicast packets.
  676. */
  677. static void
  678. efx_handle_rx_event(struct efx_channel *channel, const efx_qword_t *event)
  679. {
  680. unsigned int rx_ev_desc_ptr, rx_ev_byte_cnt;
  681. unsigned int rx_ev_hdr_type, rx_ev_mcast_pkt;
  682. unsigned expected_ptr;
  683. bool rx_ev_pkt_ok, discard = false, checksummed;
  684. struct efx_rx_queue *rx_queue;
  685. struct efx_nic *efx = channel->efx;
  686. /* Basic packet information */
  687. rx_ev_byte_cnt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_BYTE_CNT);
  688. rx_ev_pkt_ok = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_PKT_OK);
  689. rx_ev_hdr_type = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_HDR_TYPE);
  690. WARN_ON(EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_JUMBO_CONT));
  691. WARN_ON(EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_SOP) != 1);
  692. WARN_ON(EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_Q_LABEL) !=
  693. channel->channel);
  694. rx_queue = &efx->rx_queue[channel->channel];
  695. rx_ev_desc_ptr = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_DESC_PTR);
  696. expected_ptr = rx_queue->removed_count & EFX_RXQ_MASK;
  697. if (unlikely(rx_ev_desc_ptr != expected_ptr))
  698. efx_handle_rx_bad_index(rx_queue, rx_ev_desc_ptr);
  699. if (likely(rx_ev_pkt_ok)) {
  700. /* If packet is marked as OK and packet type is TCP/IP or
  701. * UDP/IP, then we can rely on the hardware checksum.
  702. */
  703. checksummed =
  704. likely(efx->rx_checksum_enabled) &&
  705. (rx_ev_hdr_type == FSE_CZ_RX_EV_HDR_TYPE_IPV4V6_TCP ||
  706. rx_ev_hdr_type == FSE_CZ_RX_EV_HDR_TYPE_IPV4V6_UDP);
  707. } else {
  708. efx_handle_rx_not_ok(rx_queue, event, &rx_ev_pkt_ok, &discard);
  709. checksummed = false;
  710. }
  711. /* Detect multicast packets that didn't match the filter */
  712. rx_ev_mcast_pkt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_PKT);
  713. if (rx_ev_mcast_pkt) {
  714. unsigned int rx_ev_mcast_hash_match =
  715. EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_HASH_MATCH);
  716. if (unlikely(!rx_ev_mcast_hash_match)) {
  717. ++channel->n_rx_mcast_mismatch;
  718. discard = true;
  719. }
  720. }
  721. channel->irq_mod_score += 2;
  722. /* Handle received packet */
  723. efx_rx_packet(rx_queue, rx_ev_desc_ptr, rx_ev_byte_cnt,
  724. checksummed, discard);
  725. }
  726. /* Global events are basically PHY events */
  727. static void
  728. efx_handle_global_event(struct efx_channel *channel, efx_qword_t *event)
  729. {
  730. struct efx_nic *efx = channel->efx;
  731. bool handled = false;
  732. if (EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_G_PHY0_INTR) ||
  733. EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XG_PHY0_INTR) ||
  734. EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XFP_PHY0_INTR)) {
  735. /* Ignored */
  736. handled = true;
  737. }
  738. if ((efx_nic_rev(efx) >= EFX_REV_FALCON_B0) &&
  739. EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_XG_MGT_INTR)) {
  740. efx->xmac_poll_required = true;
  741. handled = true;
  742. }
  743. if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1 ?
  744. EFX_QWORD_FIELD(*event, FSF_AA_GLB_EV_RX_RECOVERY) :
  745. EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_RX_RECOVERY)) {
  746. EFX_ERR(efx, "channel %d seen global RX_RESET "
  747. "event. Resetting.\n", channel->channel);
  748. atomic_inc(&efx->rx_reset);
  749. efx_schedule_reset(efx, EFX_WORKAROUND_6555(efx) ?
  750. RESET_TYPE_RX_RECOVERY : RESET_TYPE_DISABLE);
  751. handled = true;
  752. }
  753. if (!handled)
  754. EFX_ERR(efx, "channel %d unknown global event "
  755. EFX_QWORD_FMT "\n", channel->channel,
  756. EFX_QWORD_VAL(*event));
  757. }
  758. static void
  759. efx_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
  760. {
  761. struct efx_nic *efx = channel->efx;
  762. unsigned int ev_sub_code;
  763. unsigned int ev_sub_data;
  764. ev_sub_code = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBCODE);
  765. ev_sub_data = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBDATA);
  766. switch (ev_sub_code) {
  767. case FSE_AZ_TX_DESCQ_FLS_DONE_EV:
  768. EFX_TRACE(efx, "channel %d TXQ %d flushed\n",
  769. channel->channel, ev_sub_data);
  770. break;
  771. case FSE_AZ_RX_DESCQ_FLS_DONE_EV:
  772. EFX_TRACE(efx, "channel %d RXQ %d flushed\n",
  773. channel->channel, ev_sub_data);
  774. break;
  775. case FSE_AZ_EVQ_INIT_DONE_EV:
  776. EFX_LOG(efx, "channel %d EVQ %d initialised\n",
  777. channel->channel, ev_sub_data);
  778. break;
  779. case FSE_AZ_SRM_UPD_DONE_EV:
  780. EFX_TRACE(efx, "channel %d SRAM update done\n",
  781. channel->channel);
  782. break;
  783. case FSE_AZ_WAKE_UP_EV:
  784. EFX_TRACE(efx, "channel %d RXQ %d wakeup event\n",
  785. channel->channel, ev_sub_data);
  786. break;
  787. case FSE_AZ_TIMER_EV:
  788. EFX_TRACE(efx, "channel %d RX queue %d timer expired\n",
  789. channel->channel, ev_sub_data);
  790. break;
  791. case FSE_AA_RX_RECOVER_EV:
  792. EFX_ERR(efx, "channel %d seen DRIVER RX_RESET event. "
  793. "Resetting.\n", channel->channel);
  794. atomic_inc(&efx->rx_reset);
  795. efx_schedule_reset(efx,
  796. EFX_WORKAROUND_6555(efx) ?
  797. RESET_TYPE_RX_RECOVERY :
  798. RESET_TYPE_DISABLE);
  799. break;
  800. case FSE_BZ_RX_DSC_ERROR_EV:
  801. EFX_ERR(efx, "RX DMA Q %d reports descriptor fetch error."
  802. " RX Q %d is disabled.\n", ev_sub_data, ev_sub_data);
  803. efx_schedule_reset(efx, RESET_TYPE_RX_DESC_FETCH);
  804. break;
  805. case FSE_BZ_TX_DSC_ERROR_EV:
  806. EFX_ERR(efx, "TX DMA Q %d reports descriptor fetch error."
  807. " TX Q %d is disabled.\n", ev_sub_data, ev_sub_data);
  808. efx_schedule_reset(efx, RESET_TYPE_TX_DESC_FETCH);
  809. break;
  810. default:
  811. EFX_TRACE(efx, "channel %d unknown driver event code %d "
  812. "data %04x\n", channel->channel, ev_sub_code,
  813. ev_sub_data);
  814. break;
  815. }
  816. }
  817. int efx_nic_process_eventq(struct efx_channel *channel, int budget)
  818. {
  819. unsigned int read_ptr;
  820. efx_qword_t event, *p_event;
  821. int ev_code;
  822. int tx_packets = 0;
  823. int spent = 0;
  824. read_ptr = channel->eventq_read_ptr;
  825. for (;;) {
  826. p_event = efx_event(channel, read_ptr);
  827. event = *p_event;
  828. if (!efx_event_present(&event))
  829. /* End of events */
  830. break;
  831. EFX_TRACE(channel->efx, "channel %d event is "EFX_QWORD_FMT"\n",
  832. channel->channel, EFX_QWORD_VAL(event));
  833. /* Clear this event by marking it all ones */
  834. EFX_SET_QWORD(*p_event);
  835. /* Increment read pointer */
  836. read_ptr = (read_ptr + 1) & EFX_EVQ_MASK;
  837. ev_code = EFX_QWORD_FIELD(event, FSF_AZ_EV_CODE);
  838. switch (ev_code) {
  839. case FSE_AZ_EV_CODE_RX_EV:
  840. efx_handle_rx_event(channel, &event);
  841. if (++spent == budget)
  842. goto out;
  843. break;
  844. case FSE_AZ_EV_CODE_TX_EV:
  845. tx_packets += efx_handle_tx_event(channel, &event);
  846. if (tx_packets >= EFX_TXQ_SIZE) {
  847. spent = budget;
  848. goto out;
  849. }
  850. break;
  851. case FSE_AZ_EV_CODE_DRV_GEN_EV:
  852. channel->eventq_magic = EFX_QWORD_FIELD(
  853. event, FSF_AZ_DRV_GEN_EV_MAGIC);
  854. EFX_LOG(channel->efx, "channel %d received generated "
  855. "event "EFX_QWORD_FMT"\n", channel->channel,
  856. EFX_QWORD_VAL(event));
  857. break;
  858. case FSE_AZ_EV_CODE_GLOBAL_EV:
  859. efx_handle_global_event(channel, &event);
  860. break;
  861. case FSE_AZ_EV_CODE_DRIVER_EV:
  862. efx_handle_driver_event(channel, &event);
  863. break;
  864. case FSE_CZ_EV_CODE_MCDI_EV:
  865. efx_mcdi_process_event(channel, &event);
  866. break;
  867. default:
  868. EFX_ERR(channel->efx, "channel %d unknown event type %d"
  869. " (data " EFX_QWORD_FMT ")\n", channel->channel,
  870. ev_code, EFX_QWORD_VAL(event));
  871. }
  872. }
  873. out:
  874. channel->eventq_read_ptr = read_ptr;
  875. return spent;
  876. }
  877. /* Allocate buffer table entries for event queue */
  878. int efx_nic_probe_eventq(struct efx_channel *channel)
  879. {
  880. struct efx_nic *efx = channel->efx;
  881. BUILD_BUG_ON(EFX_EVQ_SIZE < 512 || EFX_EVQ_SIZE > 32768 ||
  882. EFX_EVQ_SIZE & EFX_EVQ_MASK);
  883. return efx_alloc_special_buffer(efx, &channel->eventq,
  884. EFX_EVQ_SIZE * sizeof(efx_qword_t));
  885. }
  886. void efx_nic_init_eventq(struct efx_channel *channel)
  887. {
  888. efx_oword_t reg;
  889. struct efx_nic *efx = channel->efx;
  890. EFX_LOG(efx, "channel %d event queue in special buffers %d-%d\n",
  891. channel->channel, channel->eventq.index,
  892. channel->eventq.index + channel->eventq.entries - 1);
  893. if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0) {
  894. EFX_POPULATE_OWORD_3(reg,
  895. FRF_CZ_TIMER_Q_EN, 1,
  896. FRF_CZ_HOST_NOTIFY_MODE, 0,
  897. FRF_CZ_TIMER_MODE, FFE_CZ_TIMER_MODE_DIS);
  898. efx_writeo_table(efx, &reg, FR_BZ_TIMER_TBL, channel->channel);
  899. }
  900. /* Pin event queue buffer */
  901. efx_init_special_buffer(efx, &channel->eventq);
  902. /* Fill event queue with all ones (i.e. empty events) */
  903. memset(channel->eventq.addr, 0xff, channel->eventq.len);
  904. /* Push event queue to card */
  905. EFX_POPULATE_OWORD_3(reg,
  906. FRF_AZ_EVQ_EN, 1,
  907. FRF_AZ_EVQ_SIZE, __ffs(channel->eventq.entries),
  908. FRF_AZ_EVQ_BUF_BASE_ID, channel->eventq.index);
  909. efx_writeo_table(efx, &reg, efx->type->evq_ptr_tbl_base,
  910. channel->channel);
  911. efx->type->push_irq_moderation(channel);
  912. }
  913. void efx_nic_fini_eventq(struct efx_channel *channel)
  914. {
  915. efx_oword_t reg;
  916. struct efx_nic *efx = channel->efx;
  917. /* Remove event queue from card */
  918. EFX_ZERO_OWORD(reg);
  919. efx_writeo_table(efx, &reg, efx->type->evq_ptr_tbl_base,
  920. channel->channel);
  921. if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0)
  922. efx_writeo_table(efx, &reg, FR_BZ_TIMER_TBL, channel->channel);
  923. /* Unpin event queue */
  924. efx_fini_special_buffer(efx, &channel->eventq);
  925. }
  926. /* Free buffers backing event queue */
  927. void efx_nic_remove_eventq(struct efx_channel *channel)
  928. {
  929. efx_free_special_buffer(channel->efx, &channel->eventq);
  930. }
  931. /* Generates a test event on the event queue. A subsequent call to
  932. * process_eventq() should pick up the event and place the value of
  933. * "magic" into channel->eventq_magic;
  934. */
  935. void efx_nic_generate_test_event(struct efx_channel *channel, unsigned int magic)
  936. {
  937. efx_qword_t test_event;
  938. EFX_POPULATE_QWORD_2(test_event, FSF_AZ_EV_CODE,
  939. FSE_AZ_EV_CODE_DRV_GEN_EV,
  940. FSF_AZ_DRV_GEN_EV_MAGIC, magic);
  941. efx_generate_event(channel, &test_event);
  942. }
  943. /**************************************************************************
  944. *
  945. * Flush handling
  946. *
  947. **************************************************************************/
  948. static void efx_poll_flush_events(struct efx_nic *efx)
  949. {
  950. struct efx_channel *channel = &efx->channel[0];
  951. struct efx_tx_queue *tx_queue;
  952. struct efx_rx_queue *rx_queue;
  953. unsigned int read_ptr = channel->eventq_read_ptr;
  954. unsigned int end_ptr = (read_ptr - 1) & EFX_EVQ_MASK;
  955. do {
  956. efx_qword_t *event = efx_event(channel, read_ptr);
  957. int ev_code, ev_sub_code, ev_queue;
  958. bool ev_failed;
  959. if (!efx_event_present(event))
  960. break;
  961. ev_code = EFX_QWORD_FIELD(*event, FSF_AZ_EV_CODE);
  962. ev_sub_code = EFX_QWORD_FIELD(*event,
  963. FSF_AZ_DRIVER_EV_SUBCODE);
  964. if (ev_code == FSE_AZ_EV_CODE_DRIVER_EV &&
  965. ev_sub_code == FSE_AZ_TX_DESCQ_FLS_DONE_EV) {
  966. ev_queue = EFX_QWORD_FIELD(*event,
  967. FSF_AZ_DRIVER_EV_SUBDATA);
  968. if (ev_queue < EFX_TXQ_TYPES * efx->n_tx_channels) {
  969. tx_queue = efx->tx_queue + ev_queue;
  970. tx_queue->flushed = FLUSH_DONE;
  971. }
  972. } else if (ev_code == FSE_AZ_EV_CODE_DRIVER_EV &&
  973. ev_sub_code == FSE_AZ_RX_DESCQ_FLS_DONE_EV) {
  974. ev_queue = EFX_QWORD_FIELD(
  975. *event, FSF_AZ_DRIVER_EV_RX_DESCQ_ID);
  976. ev_failed = EFX_QWORD_FIELD(
  977. *event, FSF_AZ_DRIVER_EV_RX_FLUSH_FAIL);
  978. if (ev_queue < efx->n_rx_channels) {
  979. rx_queue = efx->rx_queue + ev_queue;
  980. rx_queue->flushed =
  981. ev_failed ? FLUSH_FAILED : FLUSH_DONE;
  982. }
  983. }
  984. /* We're about to destroy the queue anyway, so
  985. * it's ok to throw away every non-flush event */
  986. EFX_SET_QWORD(*event);
  987. read_ptr = (read_ptr + 1) & EFX_EVQ_MASK;
  988. } while (read_ptr != end_ptr);
  989. channel->eventq_read_ptr = read_ptr;
  990. }
  991. /* Handle tx and rx flushes at the same time, since they run in
  992. * parallel in the hardware and there's no reason for us to
  993. * serialise them */
  994. int efx_nic_flush_queues(struct efx_nic *efx)
  995. {
  996. struct efx_rx_queue *rx_queue;
  997. struct efx_tx_queue *tx_queue;
  998. int i, tx_pending, rx_pending;
  999. /* If necessary prepare the hardware for flushing */
  1000. efx->type->prepare_flush(efx);
  1001. /* Flush all tx queues in parallel */
  1002. efx_for_each_tx_queue(tx_queue, efx)
  1003. efx_flush_tx_queue(tx_queue);
  1004. /* The hardware supports four concurrent rx flushes, each of which may
  1005. * need to be retried if there is an outstanding descriptor fetch */
  1006. for (i = 0; i < EFX_FLUSH_POLL_COUNT; ++i) {
  1007. rx_pending = tx_pending = 0;
  1008. efx_for_each_rx_queue(rx_queue, efx) {
  1009. if (rx_queue->flushed == FLUSH_PENDING)
  1010. ++rx_pending;
  1011. }
  1012. efx_for_each_rx_queue(rx_queue, efx) {
  1013. if (rx_pending == EFX_RX_FLUSH_COUNT)
  1014. break;
  1015. if (rx_queue->flushed == FLUSH_FAILED ||
  1016. rx_queue->flushed == FLUSH_NONE) {
  1017. efx_flush_rx_queue(rx_queue);
  1018. ++rx_pending;
  1019. }
  1020. }
  1021. efx_for_each_tx_queue(tx_queue, efx) {
  1022. if (tx_queue->flushed != FLUSH_DONE)
  1023. ++tx_pending;
  1024. }
  1025. if (rx_pending == 0 && tx_pending == 0)
  1026. return 0;
  1027. msleep(EFX_FLUSH_INTERVAL);
  1028. efx_poll_flush_events(efx);
  1029. }
  1030. /* Mark the queues as all flushed. We're going to return failure
  1031. * leading to a reset, or fake up success anyway */
  1032. efx_for_each_tx_queue(tx_queue, efx) {
  1033. if (tx_queue->flushed != FLUSH_DONE)
  1034. EFX_ERR(efx, "tx queue %d flush command timed out\n",
  1035. tx_queue->queue);
  1036. tx_queue->flushed = FLUSH_DONE;
  1037. }
  1038. efx_for_each_rx_queue(rx_queue, efx) {
  1039. if (rx_queue->flushed != FLUSH_DONE)
  1040. EFX_ERR(efx, "rx queue %d flush command timed out\n",
  1041. rx_queue->queue);
  1042. rx_queue->flushed = FLUSH_DONE;
  1043. }
  1044. if (EFX_WORKAROUND_7803(efx))
  1045. return 0;
  1046. return -ETIMEDOUT;
  1047. }
  1048. /**************************************************************************
  1049. *
  1050. * Hardware interrupts
  1051. * The hardware interrupt handler does very little work; all the event
  1052. * queue processing is carried out by per-channel tasklets.
  1053. *
  1054. **************************************************************************/
  1055. /* Enable/disable/generate interrupts */
  1056. static inline void efx_nic_interrupts(struct efx_nic *efx,
  1057. bool enabled, bool force)
  1058. {
  1059. efx_oword_t int_en_reg_ker;
  1060. EFX_POPULATE_OWORD_3(int_en_reg_ker,
  1061. FRF_AZ_KER_INT_LEVE_SEL, efx->fatal_irq_level,
  1062. FRF_AZ_KER_INT_KER, force,
  1063. FRF_AZ_DRV_INT_EN_KER, enabled);
  1064. efx_writeo(efx, &int_en_reg_ker, FR_AZ_INT_EN_KER);
  1065. }
  1066. void efx_nic_enable_interrupts(struct efx_nic *efx)
  1067. {
  1068. struct efx_channel *channel;
  1069. EFX_ZERO_OWORD(*((efx_oword_t *) efx->irq_status.addr));
  1070. wmb(); /* Ensure interrupt vector is clear before interrupts enabled */
  1071. /* Enable interrupts */
  1072. efx_nic_interrupts(efx, true, false);
  1073. /* Force processing of all the channels to get the EVQ RPTRs up to
  1074. date */
  1075. efx_for_each_channel(channel, efx)
  1076. efx_schedule_channel(channel);
  1077. }
  1078. void efx_nic_disable_interrupts(struct efx_nic *efx)
  1079. {
  1080. /* Disable interrupts */
  1081. efx_nic_interrupts(efx, false, false);
  1082. }
  1083. /* Generate a test interrupt
  1084. * Interrupt must already have been enabled, otherwise nasty things
  1085. * may happen.
  1086. */
  1087. void efx_nic_generate_interrupt(struct efx_nic *efx)
  1088. {
  1089. efx_nic_interrupts(efx, true, true);
  1090. }
  1091. /* Process a fatal interrupt
  1092. * Disable bus mastering ASAP and schedule a reset
  1093. */
  1094. irqreturn_t efx_nic_fatal_interrupt(struct efx_nic *efx)
  1095. {
  1096. struct falcon_nic_data *nic_data = efx->nic_data;
  1097. efx_oword_t *int_ker = efx->irq_status.addr;
  1098. efx_oword_t fatal_intr;
  1099. int error, mem_perr;
  1100. efx_reado(efx, &fatal_intr, FR_AZ_FATAL_INTR_KER);
  1101. error = EFX_OWORD_FIELD(fatal_intr, FRF_AZ_FATAL_INTR);
  1102. EFX_ERR(efx, "SYSTEM ERROR " EFX_OWORD_FMT " status "
  1103. EFX_OWORD_FMT ": %s\n", EFX_OWORD_VAL(*int_ker),
  1104. EFX_OWORD_VAL(fatal_intr),
  1105. error ? "disabling bus mastering" : "no recognised error");
  1106. /* If this is a memory parity error dump which blocks are offending */
  1107. mem_perr = (EFX_OWORD_FIELD(fatal_intr, FRF_AZ_MEM_PERR_INT_KER) ||
  1108. EFX_OWORD_FIELD(fatal_intr, FRF_AZ_SRM_PERR_INT_KER));
  1109. if (mem_perr) {
  1110. efx_oword_t reg;
  1111. efx_reado(efx, &reg, FR_AZ_MEM_STAT);
  1112. EFX_ERR(efx, "SYSTEM ERROR: memory parity error "
  1113. EFX_OWORD_FMT "\n", EFX_OWORD_VAL(reg));
  1114. }
  1115. /* Disable both devices */
  1116. pci_clear_master(efx->pci_dev);
  1117. if (efx_nic_is_dual_func(efx))
  1118. pci_clear_master(nic_data->pci_dev2);
  1119. efx_nic_disable_interrupts(efx);
  1120. /* Count errors and reset or disable the NIC accordingly */
  1121. if (efx->int_error_count == 0 ||
  1122. time_after(jiffies, efx->int_error_expire)) {
  1123. efx->int_error_count = 0;
  1124. efx->int_error_expire =
  1125. jiffies + EFX_INT_ERROR_EXPIRE * HZ;
  1126. }
  1127. if (++efx->int_error_count < EFX_MAX_INT_ERRORS) {
  1128. EFX_ERR(efx, "SYSTEM ERROR - reset scheduled\n");
  1129. efx_schedule_reset(efx, RESET_TYPE_INT_ERROR);
  1130. } else {
  1131. EFX_ERR(efx, "SYSTEM ERROR - max number of errors seen."
  1132. "NIC will be disabled\n");
  1133. efx_schedule_reset(efx, RESET_TYPE_DISABLE);
  1134. }
  1135. return IRQ_HANDLED;
  1136. }
  1137. /* Handle a legacy interrupt
  1138. * Acknowledges the interrupt and schedule event queue processing.
  1139. */
  1140. static irqreturn_t efx_legacy_interrupt(int irq, void *dev_id)
  1141. {
  1142. struct efx_nic *efx = dev_id;
  1143. efx_oword_t *int_ker = efx->irq_status.addr;
  1144. irqreturn_t result = IRQ_NONE;
  1145. struct efx_channel *channel;
  1146. efx_dword_t reg;
  1147. u32 queues;
  1148. int syserr;
  1149. /* Read the ISR which also ACKs the interrupts */
  1150. efx_readd(efx, &reg, FR_BZ_INT_ISR0);
  1151. queues = EFX_EXTRACT_DWORD(reg, 0, 31);
  1152. /* Check to see if we have a serious error condition */
  1153. if (queues & (1U << efx->fatal_irq_level)) {
  1154. syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT);
  1155. if (unlikely(syserr))
  1156. return efx_nic_fatal_interrupt(efx);
  1157. }
  1158. if (queues != 0) {
  1159. if (EFX_WORKAROUND_15783(efx))
  1160. efx->irq_zero_count = 0;
  1161. /* Schedule processing of any interrupting queues */
  1162. efx_for_each_channel(channel, efx) {
  1163. if (queues & 1)
  1164. efx_schedule_channel(channel);
  1165. queues >>= 1;
  1166. }
  1167. result = IRQ_HANDLED;
  1168. } else if (EFX_WORKAROUND_15783(efx)) {
  1169. efx_qword_t *event;
  1170. /* We can't return IRQ_HANDLED more than once on seeing ISR=0
  1171. * because this might be a shared interrupt. */
  1172. if (efx->irq_zero_count++ == 0)
  1173. result = IRQ_HANDLED;
  1174. /* Ensure we schedule or rearm all event queues */
  1175. efx_for_each_channel(channel, efx) {
  1176. event = efx_event(channel, channel->eventq_read_ptr);
  1177. if (efx_event_present(event))
  1178. efx_schedule_channel(channel);
  1179. else
  1180. efx_nic_eventq_read_ack(channel);
  1181. }
  1182. }
  1183. if (result == IRQ_HANDLED) {
  1184. efx->last_irq_cpu = raw_smp_processor_id();
  1185. EFX_TRACE(efx, "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
  1186. irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
  1187. }
  1188. return result;
  1189. }
  1190. /* Handle an MSI interrupt
  1191. *
  1192. * Handle an MSI hardware interrupt. This routine schedules event
  1193. * queue processing. No interrupt acknowledgement cycle is necessary.
  1194. * Also, we never need to check that the interrupt is for us, since
  1195. * MSI interrupts cannot be shared.
  1196. */
  1197. static irqreturn_t efx_msi_interrupt(int irq, void *dev_id)
  1198. {
  1199. struct efx_channel *channel = dev_id;
  1200. struct efx_nic *efx = channel->efx;
  1201. efx_oword_t *int_ker = efx->irq_status.addr;
  1202. int syserr;
  1203. efx->last_irq_cpu = raw_smp_processor_id();
  1204. EFX_TRACE(efx, "IRQ %d on CPU %d status " EFX_OWORD_FMT "\n",
  1205. irq, raw_smp_processor_id(), EFX_OWORD_VAL(*int_ker));
  1206. /* Check to see if we have a serious error condition */
  1207. if (channel->channel == efx->fatal_irq_level) {
  1208. syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT);
  1209. if (unlikely(syserr))
  1210. return efx_nic_fatal_interrupt(efx);
  1211. }
  1212. /* Schedule processing of the channel */
  1213. efx_schedule_channel(channel);
  1214. return IRQ_HANDLED;
  1215. }
  1216. /* Setup RSS indirection table.
  1217. * This maps from the hash value of the packet to RXQ
  1218. */
  1219. static void efx_setup_rss_indir_table(struct efx_nic *efx)
  1220. {
  1221. int i = 0;
  1222. unsigned long offset;
  1223. efx_dword_t dword;
  1224. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0)
  1225. return;
  1226. for (offset = FR_BZ_RX_INDIRECTION_TBL;
  1227. offset < FR_BZ_RX_INDIRECTION_TBL + 0x800;
  1228. offset += 0x10) {
  1229. EFX_POPULATE_DWORD_1(dword, FRF_BZ_IT_QUEUE,
  1230. i % efx->n_rx_channels);
  1231. efx_writed(efx, &dword, offset);
  1232. i++;
  1233. }
  1234. }
  1235. /* Hook interrupt handler(s)
  1236. * Try MSI and then legacy interrupts.
  1237. */
  1238. int efx_nic_init_interrupt(struct efx_nic *efx)
  1239. {
  1240. struct efx_channel *channel;
  1241. int rc;
  1242. if (!EFX_INT_MODE_USE_MSI(efx)) {
  1243. irq_handler_t handler;
  1244. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
  1245. handler = efx_legacy_interrupt;
  1246. else
  1247. handler = falcon_legacy_interrupt_a1;
  1248. rc = request_irq(efx->legacy_irq, handler, IRQF_SHARED,
  1249. efx->name, efx);
  1250. if (rc) {
  1251. EFX_ERR(efx, "failed to hook legacy IRQ %d\n",
  1252. efx->pci_dev->irq);
  1253. goto fail1;
  1254. }
  1255. return 0;
  1256. }
  1257. /* Hook MSI or MSI-X interrupt */
  1258. efx_for_each_channel(channel, efx) {
  1259. rc = request_irq(channel->irq, efx_msi_interrupt,
  1260. IRQF_PROBE_SHARED, /* Not shared */
  1261. channel->name, channel);
  1262. if (rc) {
  1263. EFX_ERR(efx, "failed to hook IRQ %d\n", channel->irq);
  1264. goto fail2;
  1265. }
  1266. }
  1267. return 0;
  1268. fail2:
  1269. efx_for_each_channel(channel, efx)
  1270. free_irq(channel->irq, channel);
  1271. fail1:
  1272. return rc;
  1273. }
  1274. void efx_nic_fini_interrupt(struct efx_nic *efx)
  1275. {
  1276. struct efx_channel *channel;
  1277. efx_oword_t reg;
  1278. /* Disable MSI/MSI-X interrupts */
  1279. efx_for_each_channel(channel, efx) {
  1280. if (channel->irq)
  1281. free_irq(channel->irq, channel);
  1282. }
  1283. /* ACK legacy interrupt */
  1284. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
  1285. efx_reado(efx, &reg, FR_BZ_INT_ISR0);
  1286. else
  1287. falcon_irq_ack_a1(efx);
  1288. /* Disable legacy interrupt */
  1289. if (efx->legacy_irq)
  1290. free_irq(efx->legacy_irq, efx);
  1291. }
  1292. u32 efx_nic_fpga_ver(struct efx_nic *efx)
  1293. {
  1294. efx_oword_t altera_build;
  1295. efx_reado(efx, &altera_build, FR_AZ_ALTERA_BUILD);
  1296. return EFX_OWORD_FIELD(altera_build, FRF_AZ_ALTERA_BUILD_VER);
  1297. }
  1298. void efx_nic_init_common(struct efx_nic *efx)
  1299. {
  1300. efx_oword_t temp;
  1301. /* Set positions of descriptor caches in SRAM. */
  1302. EFX_POPULATE_OWORD_1(temp, FRF_AZ_SRM_TX_DC_BASE_ADR,
  1303. efx->type->tx_dc_base / 8);
  1304. efx_writeo(efx, &temp, FR_AZ_SRM_TX_DC_CFG);
  1305. EFX_POPULATE_OWORD_1(temp, FRF_AZ_SRM_RX_DC_BASE_ADR,
  1306. efx->type->rx_dc_base / 8);
  1307. efx_writeo(efx, &temp, FR_AZ_SRM_RX_DC_CFG);
  1308. /* Set TX descriptor cache size. */
  1309. BUILD_BUG_ON(TX_DC_ENTRIES != (8 << TX_DC_ENTRIES_ORDER));
  1310. EFX_POPULATE_OWORD_1(temp, FRF_AZ_TX_DC_SIZE, TX_DC_ENTRIES_ORDER);
  1311. efx_writeo(efx, &temp, FR_AZ_TX_DC_CFG);
  1312. /* Set RX descriptor cache size. Set low watermark to size-8, as
  1313. * this allows most efficient prefetching.
  1314. */
  1315. BUILD_BUG_ON(RX_DC_ENTRIES != (8 << RX_DC_ENTRIES_ORDER));
  1316. EFX_POPULATE_OWORD_1(temp, FRF_AZ_RX_DC_SIZE, RX_DC_ENTRIES_ORDER);
  1317. efx_writeo(efx, &temp, FR_AZ_RX_DC_CFG);
  1318. EFX_POPULATE_OWORD_1(temp, FRF_AZ_RX_DC_PF_LWM, RX_DC_ENTRIES - 8);
  1319. efx_writeo(efx, &temp, FR_AZ_RX_DC_PF_WM);
  1320. /* Program INT_KER address */
  1321. EFX_POPULATE_OWORD_2(temp,
  1322. FRF_AZ_NORM_INT_VEC_DIS_KER,
  1323. EFX_INT_MODE_USE_MSI(efx),
  1324. FRF_AZ_INT_ADR_KER, efx->irq_status.dma_addr);
  1325. efx_writeo(efx, &temp, FR_AZ_INT_ADR_KER);
  1326. if (EFX_WORKAROUND_17213(efx) && !EFX_INT_MODE_USE_MSI(efx))
  1327. /* Use an interrupt level unused by event queues */
  1328. efx->fatal_irq_level = 0x1f;
  1329. else
  1330. /* Use a valid MSI-X vector */
  1331. efx->fatal_irq_level = 0;
  1332. /* Enable all the genuinely fatal interrupts. (They are still
  1333. * masked by the overall interrupt mask, controlled by
  1334. * falcon_interrupts()).
  1335. *
  1336. * Note: All other fatal interrupts are enabled
  1337. */
  1338. EFX_POPULATE_OWORD_3(temp,
  1339. FRF_AZ_ILL_ADR_INT_KER_EN, 1,
  1340. FRF_AZ_RBUF_OWN_INT_KER_EN, 1,
  1341. FRF_AZ_TBUF_OWN_INT_KER_EN, 1);
  1342. if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0)
  1343. EFX_SET_OWORD_FIELD(temp, FRF_CZ_SRAM_PERR_INT_P_KER_EN, 1);
  1344. EFX_INVERT_OWORD(temp);
  1345. efx_writeo(efx, &temp, FR_AZ_FATAL_INTR_KER);
  1346. efx_setup_rss_indir_table(efx);
  1347. /* Disable the ugly timer-based TX DMA backoff and allow TX DMA to be
  1348. * controlled by the RX FIFO fill level. Set arbitration to one pkt/Q.
  1349. */
  1350. efx_reado(efx, &temp, FR_AZ_TX_RESERVED);
  1351. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_RX_SPACER, 0xfe);
  1352. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_RX_SPACER_EN, 1);
  1353. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_ONE_PKT_PER_Q, 1);
  1354. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PUSH_EN, 0);
  1355. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_DIS_NON_IP_EV, 1);
  1356. /* Enable SW_EV to inherit in char driver - assume harmless here */
  1357. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_SOFT_EVT_EN, 1);
  1358. /* Prefetch threshold 2 => fetch when descriptor cache half empty */
  1359. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PREF_THRESHOLD, 2);
  1360. /* Disable hardware watchdog which can misfire */
  1361. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PREF_WD_TMR, 0x3fffff);
  1362. /* Squash TX of packets of 16 bytes or less */
  1363. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
  1364. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TX_FLUSH_MIN_LEN_EN, 1);
  1365. efx_writeo(efx, &temp, FR_AZ_TX_RESERVED);
  1366. }