nic.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585
  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_TX_QUEUE_OFFLOAD_CSUM;
  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_TX_QUEUE_COUNT >= 128);
  366. efx_reado(efx, &reg, FR_AA_TX_CHKSM_CFG);
  367. if (tx_queue->queue == EFX_TX_QUEUE_OFFLOAD_CSUM)
  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. * Note that EVQ_RPTR_REG contains the index of the "last read" event,
  527. * whereas channel->eventq_read_ptr contains the index of the "next to
  528. * read" event.
  529. */
  530. void efx_nic_eventq_read_ack(struct efx_channel *channel)
  531. {
  532. efx_dword_t reg;
  533. struct efx_nic *efx = channel->efx;
  534. EFX_POPULATE_DWORD_1(reg, FRF_AZ_EVQ_RPTR, channel->eventq_read_ptr);
  535. efx_writed_table(efx, &reg, efx->type->evq_rptr_tbl_base,
  536. channel->channel);
  537. }
  538. /* Use HW to insert a SW defined event */
  539. void efx_generate_event(struct efx_channel *channel, efx_qword_t *event)
  540. {
  541. efx_oword_t drv_ev_reg;
  542. BUILD_BUG_ON(FRF_AZ_DRV_EV_DATA_LBN != 0 ||
  543. FRF_AZ_DRV_EV_DATA_WIDTH != 64);
  544. drv_ev_reg.u32[0] = event->u32[0];
  545. drv_ev_reg.u32[1] = event->u32[1];
  546. drv_ev_reg.u32[2] = 0;
  547. drv_ev_reg.u32[3] = 0;
  548. EFX_SET_OWORD_FIELD(drv_ev_reg, FRF_AZ_DRV_EV_QID, channel->channel);
  549. efx_writeo(channel->efx, &drv_ev_reg, FR_AZ_DRV_EV);
  550. }
  551. /* Handle a transmit completion event
  552. *
  553. * The NIC batches TX completion events; the message we receive is of
  554. * the form "complete all TX events up to this index".
  555. */
  556. static void
  557. efx_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
  558. {
  559. unsigned int tx_ev_desc_ptr;
  560. unsigned int tx_ev_q_label;
  561. struct efx_tx_queue *tx_queue;
  562. struct efx_nic *efx = channel->efx;
  563. if (likely(EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_COMP))) {
  564. /* Transmit completion */
  565. tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_DESC_PTR);
  566. tx_ev_q_label = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_Q_LABEL);
  567. tx_queue = &efx->tx_queue[tx_ev_q_label];
  568. channel->irq_mod_score +=
  569. (tx_ev_desc_ptr - tx_queue->read_count) &
  570. EFX_TXQ_MASK;
  571. efx_xmit_done(tx_queue, tx_ev_desc_ptr);
  572. } else if (EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_WQ_FF_FULL)) {
  573. /* Rewrite the FIFO write pointer */
  574. tx_ev_q_label = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_Q_LABEL);
  575. tx_queue = &efx->tx_queue[tx_ev_q_label];
  576. if (efx_dev_registered(efx))
  577. netif_tx_lock(efx->net_dev);
  578. efx_notify_tx_desc(tx_queue);
  579. if (efx_dev_registered(efx))
  580. netif_tx_unlock(efx->net_dev);
  581. } else if (EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_PKT_ERR) &&
  582. EFX_WORKAROUND_10727(efx)) {
  583. efx_schedule_reset(efx, RESET_TYPE_TX_DESC_FETCH);
  584. } else {
  585. EFX_ERR(efx, "channel %d unexpected TX event "
  586. EFX_QWORD_FMT"\n", channel->channel,
  587. EFX_QWORD_VAL(*event));
  588. }
  589. }
  590. /* Detect errors included in the rx_evt_pkt_ok bit. */
  591. static void efx_handle_rx_not_ok(struct efx_rx_queue *rx_queue,
  592. const efx_qword_t *event,
  593. bool *rx_ev_pkt_ok,
  594. bool *discard)
  595. {
  596. struct efx_nic *efx = rx_queue->efx;
  597. bool rx_ev_buf_owner_id_err, rx_ev_ip_hdr_chksum_err;
  598. bool rx_ev_tcp_udp_chksum_err, rx_ev_eth_crc_err;
  599. bool rx_ev_frm_trunc, rx_ev_drib_nib, rx_ev_tobe_disc;
  600. bool rx_ev_other_err, rx_ev_pause_frm;
  601. bool rx_ev_hdr_type, rx_ev_mcast_pkt;
  602. unsigned rx_ev_pkt_type;
  603. rx_ev_hdr_type = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_HDR_TYPE);
  604. rx_ev_mcast_pkt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_PKT);
  605. rx_ev_tobe_disc = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_TOBE_DISC);
  606. rx_ev_pkt_type = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_PKT_TYPE);
  607. rx_ev_buf_owner_id_err = EFX_QWORD_FIELD(*event,
  608. FSF_AZ_RX_EV_BUF_OWNER_ID_ERR);
  609. rx_ev_ip_hdr_chksum_err = EFX_QWORD_FIELD(*event,
  610. FSF_AZ_RX_EV_IP_HDR_CHKSUM_ERR);
  611. rx_ev_tcp_udp_chksum_err = EFX_QWORD_FIELD(*event,
  612. FSF_AZ_RX_EV_TCP_UDP_CHKSUM_ERR);
  613. rx_ev_eth_crc_err = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_ETH_CRC_ERR);
  614. rx_ev_frm_trunc = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_FRM_TRUNC);
  615. rx_ev_drib_nib = ((efx_nic_rev(efx) >= EFX_REV_FALCON_B0) ?
  616. 0 : EFX_QWORD_FIELD(*event, FSF_AA_RX_EV_DRIB_NIB));
  617. rx_ev_pause_frm = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_PAUSE_FRM_ERR);
  618. /* Every error apart from tobe_disc and pause_frm */
  619. rx_ev_other_err = (rx_ev_drib_nib | rx_ev_tcp_udp_chksum_err |
  620. rx_ev_buf_owner_id_err | rx_ev_eth_crc_err |
  621. rx_ev_frm_trunc | rx_ev_ip_hdr_chksum_err);
  622. /* Count errors that are not in MAC stats. Ignore expected
  623. * checksum errors during self-test. */
  624. if (rx_ev_frm_trunc)
  625. ++rx_queue->channel->n_rx_frm_trunc;
  626. else if (rx_ev_tobe_disc)
  627. ++rx_queue->channel->n_rx_tobe_disc;
  628. else if (!efx->loopback_selftest) {
  629. if (rx_ev_ip_hdr_chksum_err)
  630. ++rx_queue->channel->n_rx_ip_hdr_chksum_err;
  631. else if (rx_ev_tcp_udp_chksum_err)
  632. ++rx_queue->channel->n_rx_tcp_udp_chksum_err;
  633. }
  634. /* The frame must be discarded if any of these are true. */
  635. *discard = (rx_ev_eth_crc_err | rx_ev_frm_trunc | rx_ev_drib_nib |
  636. rx_ev_tobe_disc | rx_ev_pause_frm);
  637. /* TOBE_DISC is expected on unicast mismatches; don't print out an
  638. * error message. FRM_TRUNC indicates RXDP dropped the packet due
  639. * to a FIFO overflow.
  640. */
  641. #ifdef EFX_ENABLE_DEBUG
  642. if (rx_ev_other_err) {
  643. EFX_INFO_RL(efx, " RX queue %d unexpected RX event "
  644. EFX_QWORD_FMT "%s%s%s%s%s%s%s%s\n",
  645. rx_queue->queue, EFX_QWORD_VAL(*event),
  646. rx_ev_buf_owner_id_err ? " [OWNER_ID_ERR]" : "",
  647. rx_ev_ip_hdr_chksum_err ?
  648. " [IP_HDR_CHKSUM_ERR]" : "",
  649. rx_ev_tcp_udp_chksum_err ?
  650. " [TCP_UDP_CHKSUM_ERR]" : "",
  651. rx_ev_eth_crc_err ? " [ETH_CRC_ERR]" : "",
  652. rx_ev_frm_trunc ? " [FRM_TRUNC]" : "",
  653. rx_ev_drib_nib ? " [DRIB_NIB]" : "",
  654. rx_ev_tobe_disc ? " [TOBE_DISC]" : "",
  655. rx_ev_pause_frm ? " [PAUSE]" : "");
  656. }
  657. #endif
  658. }
  659. /* Handle receive events that are not in-order. */
  660. static void
  661. efx_handle_rx_bad_index(struct efx_rx_queue *rx_queue, unsigned index)
  662. {
  663. struct efx_nic *efx = rx_queue->efx;
  664. unsigned expected, dropped;
  665. expected = rx_queue->removed_count & EFX_RXQ_MASK;
  666. dropped = (index - expected) & EFX_RXQ_MASK;
  667. EFX_INFO(efx, "dropped %d events (index=%d expected=%d)\n",
  668. dropped, index, expected);
  669. efx_schedule_reset(efx, EFX_WORKAROUND_5676(efx) ?
  670. RESET_TYPE_RX_RECOVERY : RESET_TYPE_DISABLE);
  671. }
  672. /* Handle a packet received event
  673. *
  674. * The NIC gives a "discard" flag if it's a unicast packet with the
  675. * wrong destination address
  676. * Also "is multicast" and "matches multicast filter" flags can be used to
  677. * discard non-matching multicast packets.
  678. */
  679. static void
  680. efx_handle_rx_event(struct efx_channel *channel, const efx_qword_t *event)
  681. {
  682. unsigned int rx_ev_desc_ptr, rx_ev_byte_cnt;
  683. unsigned int rx_ev_hdr_type, rx_ev_mcast_pkt;
  684. unsigned expected_ptr;
  685. bool rx_ev_pkt_ok, discard = false, checksummed;
  686. struct efx_rx_queue *rx_queue;
  687. struct efx_nic *efx = channel->efx;
  688. /* Basic packet information */
  689. rx_ev_byte_cnt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_BYTE_CNT);
  690. rx_ev_pkt_ok = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_PKT_OK);
  691. rx_ev_hdr_type = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_HDR_TYPE);
  692. WARN_ON(EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_JUMBO_CONT));
  693. WARN_ON(EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_SOP) != 1);
  694. WARN_ON(EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_Q_LABEL) !=
  695. channel->channel);
  696. rx_queue = &efx->rx_queue[channel->channel];
  697. rx_ev_desc_ptr = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_DESC_PTR);
  698. expected_ptr = rx_queue->removed_count & EFX_RXQ_MASK;
  699. if (unlikely(rx_ev_desc_ptr != expected_ptr))
  700. efx_handle_rx_bad_index(rx_queue, rx_ev_desc_ptr);
  701. if (likely(rx_ev_pkt_ok)) {
  702. /* If packet is marked as OK and packet type is TCP/IP or
  703. * UDP/IP, then we can rely on the hardware checksum.
  704. */
  705. checksummed =
  706. likely(efx->rx_checksum_enabled) &&
  707. (rx_ev_hdr_type == FSE_CZ_RX_EV_HDR_TYPE_IPV4V6_TCP ||
  708. rx_ev_hdr_type == FSE_CZ_RX_EV_HDR_TYPE_IPV4V6_UDP);
  709. } else {
  710. efx_handle_rx_not_ok(rx_queue, event, &rx_ev_pkt_ok, &discard);
  711. checksummed = false;
  712. }
  713. /* Detect multicast packets that didn't match the filter */
  714. rx_ev_mcast_pkt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_PKT);
  715. if (rx_ev_mcast_pkt) {
  716. unsigned int rx_ev_mcast_hash_match =
  717. EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_HASH_MATCH);
  718. if (unlikely(!rx_ev_mcast_hash_match)) {
  719. ++channel->n_rx_mcast_mismatch;
  720. discard = true;
  721. }
  722. }
  723. channel->irq_mod_score += 2;
  724. /* Handle received packet */
  725. efx_rx_packet(rx_queue, rx_ev_desc_ptr, rx_ev_byte_cnt,
  726. checksummed, discard);
  727. }
  728. /* Global events are basically PHY events */
  729. static void
  730. efx_handle_global_event(struct efx_channel *channel, efx_qword_t *event)
  731. {
  732. struct efx_nic *efx = channel->efx;
  733. bool handled = false;
  734. if (EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_G_PHY0_INTR) ||
  735. EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XG_PHY0_INTR) ||
  736. EFX_QWORD_FIELD(*event, FSF_AB_GLB_EV_XFP_PHY0_INTR)) {
  737. /* Ignored */
  738. handled = true;
  739. }
  740. if ((efx_nic_rev(efx) >= EFX_REV_FALCON_B0) &&
  741. EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_XG_MGT_INTR)) {
  742. efx->xmac_poll_required = true;
  743. handled = true;
  744. }
  745. if (efx_nic_rev(efx) <= EFX_REV_FALCON_A1 ?
  746. EFX_QWORD_FIELD(*event, FSF_AA_GLB_EV_RX_RECOVERY) :
  747. EFX_QWORD_FIELD(*event, FSF_BB_GLB_EV_RX_RECOVERY)) {
  748. EFX_ERR(efx, "channel %d seen global RX_RESET "
  749. "event. Resetting.\n", channel->channel);
  750. atomic_inc(&efx->rx_reset);
  751. efx_schedule_reset(efx, EFX_WORKAROUND_6555(efx) ?
  752. RESET_TYPE_RX_RECOVERY : RESET_TYPE_DISABLE);
  753. handled = true;
  754. }
  755. if (!handled)
  756. EFX_ERR(efx, "channel %d unknown global event "
  757. EFX_QWORD_FMT "\n", channel->channel,
  758. EFX_QWORD_VAL(*event));
  759. }
  760. static void
  761. efx_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
  762. {
  763. struct efx_nic *efx = channel->efx;
  764. unsigned int ev_sub_code;
  765. unsigned int ev_sub_data;
  766. ev_sub_code = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBCODE);
  767. ev_sub_data = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBDATA);
  768. switch (ev_sub_code) {
  769. case FSE_AZ_TX_DESCQ_FLS_DONE_EV:
  770. EFX_TRACE(efx, "channel %d TXQ %d flushed\n",
  771. channel->channel, ev_sub_data);
  772. break;
  773. case FSE_AZ_RX_DESCQ_FLS_DONE_EV:
  774. EFX_TRACE(efx, "channel %d RXQ %d flushed\n",
  775. channel->channel, ev_sub_data);
  776. break;
  777. case FSE_AZ_EVQ_INIT_DONE_EV:
  778. EFX_LOG(efx, "channel %d EVQ %d initialised\n",
  779. channel->channel, ev_sub_data);
  780. break;
  781. case FSE_AZ_SRM_UPD_DONE_EV:
  782. EFX_TRACE(efx, "channel %d SRAM update done\n",
  783. channel->channel);
  784. break;
  785. case FSE_AZ_WAKE_UP_EV:
  786. EFX_TRACE(efx, "channel %d RXQ %d wakeup event\n",
  787. channel->channel, ev_sub_data);
  788. break;
  789. case FSE_AZ_TIMER_EV:
  790. EFX_TRACE(efx, "channel %d RX queue %d timer expired\n",
  791. channel->channel, ev_sub_data);
  792. break;
  793. case FSE_AA_RX_RECOVER_EV:
  794. EFX_ERR(efx, "channel %d seen DRIVER RX_RESET event. "
  795. "Resetting.\n", channel->channel);
  796. atomic_inc(&efx->rx_reset);
  797. efx_schedule_reset(efx,
  798. EFX_WORKAROUND_6555(efx) ?
  799. RESET_TYPE_RX_RECOVERY :
  800. RESET_TYPE_DISABLE);
  801. break;
  802. case FSE_BZ_RX_DSC_ERROR_EV:
  803. EFX_ERR(efx, "RX DMA Q %d reports descriptor fetch error."
  804. " RX Q %d is disabled.\n", ev_sub_data, ev_sub_data);
  805. efx_schedule_reset(efx, RESET_TYPE_RX_DESC_FETCH);
  806. break;
  807. case FSE_BZ_TX_DSC_ERROR_EV:
  808. EFX_ERR(efx, "TX DMA Q %d reports descriptor fetch error."
  809. " TX Q %d is disabled.\n", ev_sub_data, ev_sub_data);
  810. efx_schedule_reset(efx, RESET_TYPE_TX_DESC_FETCH);
  811. break;
  812. default:
  813. EFX_TRACE(efx, "channel %d unknown driver event code %d "
  814. "data %04x\n", channel->channel, ev_sub_code,
  815. ev_sub_data);
  816. break;
  817. }
  818. }
  819. int efx_nic_process_eventq(struct efx_channel *channel, int rx_quota)
  820. {
  821. unsigned int read_ptr;
  822. efx_qword_t event, *p_event;
  823. int ev_code;
  824. int rx_packets = 0;
  825. read_ptr = channel->eventq_read_ptr;
  826. do {
  827. p_event = efx_event(channel, read_ptr);
  828. event = *p_event;
  829. if (!efx_event_present(&event))
  830. /* End of events */
  831. break;
  832. EFX_TRACE(channel->efx, "channel %d event is "EFX_QWORD_FMT"\n",
  833. channel->channel, EFX_QWORD_VAL(event));
  834. /* Clear this event by marking it all ones */
  835. EFX_SET_QWORD(*p_event);
  836. ev_code = EFX_QWORD_FIELD(event, FSF_AZ_EV_CODE);
  837. switch (ev_code) {
  838. case FSE_AZ_EV_CODE_RX_EV:
  839. efx_handle_rx_event(channel, &event);
  840. ++rx_packets;
  841. break;
  842. case FSE_AZ_EV_CODE_TX_EV:
  843. efx_handle_tx_event(channel, &event);
  844. break;
  845. case FSE_AZ_EV_CODE_DRV_GEN_EV:
  846. channel->eventq_magic = EFX_QWORD_FIELD(
  847. event, FSF_AZ_DRV_GEN_EV_MAGIC);
  848. EFX_LOG(channel->efx, "channel %d received generated "
  849. "event "EFX_QWORD_FMT"\n", channel->channel,
  850. EFX_QWORD_VAL(event));
  851. break;
  852. case FSE_AZ_EV_CODE_GLOBAL_EV:
  853. efx_handle_global_event(channel, &event);
  854. break;
  855. case FSE_AZ_EV_CODE_DRIVER_EV:
  856. efx_handle_driver_event(channel, &event);
  857. break;
  858. case FSE_CZ_EV_CODE_MCDI_EV:
  859. efx_mcdi_process_event(channel, &event);
  860. break;
  861. default:
  862. EFX_ERR(channel->efx, "channel %d unknown event type %d"
  863. " (data " EFX_QWORD_FMT ")\n", channel->channel,
  864. ev_code, EFX_QWORD_VAL(event));
  865. }
  866. /* Increment read pointer */
  867. read_ptr = (read_ptr + 1) & EFX_EVQ_MASK;
  868. } while (rx_packets < rx_quota);
  869. channel->eventq_read_ptr = read_ptr;
  870. return rx_packets;
  871. }
  872. /* Allocate buffer table entries for event queue */
  873. int efx_nic_probe_eventq(struct efx_channel *channel)
  874. {
  875. struct efx_nic *efx = channel->efx;
  876. BUILD_BUG_ON(EFX_EVQ_SIZE < 512 || EFX_EVQ_SIZE > 32768 ||
  877. EFX_EVQ_SIZE & EFX_EVQ_MASK);
  878. return efx_alloc_special_buffer(efx, &channel->eventq,
  879. EFX_EVQ_SIZE * sizeof(efx_qword_t));
  880. }
  881. void efx_nic_init_eventq(struct efx_channel *channel)
  882. {
  883. efx_oword_t reg;
  884. struct efx_nic *efx = channel->efx;
  885. EFX_LOG(efx, "channel %d event queue in special buffers %d-%d\n",
  886. channel->channel, channel->eventq.index,
  887. channel->eventq.index + channel->eventq.entries - 1);
  888. if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0) {
  889. EFX_POPULATE_OWORD_3(reg,
  890. FRF_CZ_TIMER_Q_EN, 1,
  891. FRF_CZ_HOST_NOTIFY_MODE, 0,
  892. FRF_CZ_TIMER_MODE, FFE_CZ_TIMER_MODE_DIS);
  893. efx_writeo_table(efx, &reg, FR_BZ_TIMER_TBL, channel->channel);
  894. }
  895. /* Pin event queue buffer */
  896. efx_init_special_buffer(efx, &channel->eventq);
  897. /* Fill event queue with all ones (i.e. empty events) */
  898. memset(channel->eventq.addr, 0xff, channel->eventq.len);
  899. /* Push event queue to card */
  900. EFX_POPULATE_OWORD_3(reg,
  901. FRF_AZ_EVQ_EN, 1,
  902. FRF_AZ_EVQ_SIZE, __ffs(channel->eventq.entries),
  903. FRF_AZ_EVQ_BUF_BASE_ID, channel->eventq.index);
  904. efx_writeo_table(efx, &reg, efx->type->evq_ptr_tbl_base,
  905. channel->channel);
  906. efx->type->push_irq_moderation(channel);
  907. }
  908. void efx_nic_fini_eventq(struct efx_channel *channel)
  909. {
  910. efx_oword_t reg;
  911. struct efx_nic *efx = channel->efx;
  912. /* Remove event queue from card */
  913. EFX_ZERO_OWORD(reg);
  914. efx_writeo_table(efx, &reg, efx->type->evq_ptr_tbl_base,
  915. channel->channel);
  916. if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0)
  917. efx_writeo_table(efx, &reg, FR_BZ_TIMER_TBL, channel->channel);
  918. /* Unpin event queue */
  919. efx_fini_special_buffer(efx, &channel->eventq);
  920. }
  921. /* Free buffers backing event queue */
  922. void efx_nic_remove_eventq(struct efx_channel *channel)
  923. {
  924. efx_free_special_buffer(channel->efx, &channel->eventq);
  925. }
  926. /* Generates a test event on the event queue. A subsequent call to
  927. * process_eventq() should pick up the event and place the value of
  928. * "magic" into channel->eventq_magic;
  929. */
  930. void efx_nic_generate_test_event(struct efx_channel *channel, unsigned int magic)
  931. {
  932. efx_qword_t test_event;
  933. EFX_POPULATE_QWORD_2(test_event, FSF_AZ_EV_CODE,
  934. FSE_AZ_EV_CODE_DRV_GEN_EV,
  935. FSF_AZ_DRV_GEN_EV_MAGIC, magic);
  936. efx_generate_event(channel, &test_event);
  937. }
  938. /**************************************************************************
  939. *
  940. * Flush handling
  941. *
  942. **************************************************************************/
  943. static void efx_poll_flush_events(struct efx_nic *efx)
  944. {
  945. struct efx_channel *channel = &efx->channel[0];
  946. struct efx_tx_queue *tx_queue;
  947. struct efx_rx_queue *rx_queue;
  948. unsigned int read_ptr = channel->eventq_read_ptr;
  949. unsigned int end_ptr = (read_ptr - 1) & EFX_EVQ_MASK;
  950. do {
  951. efx_qword_t *event = efx_event(channel, read_ptr);
  952. int ev_code, ev_sub_code, ev_queue;
  953. bool ev_failed;
  954. if (!efx_event_present(event))
  955. break;
  956. ev_code = EFX_QWORD_FIELD(*event, FSF_AZ_EV_CODE);
  957. ev_sub_code = EFX_QWORD_FIELD(*event,
  958. FSF_AZ_DRIVER_EV_SUBCODE);
  959. if (ev_code == FSE_AZ_EV_CODE_DRIVER_EV &&
  960. ev_sub_code == FSE_AZ_TX_DESCQ_FLS_DONE_EV) {
  961. ev_queue = EFX_QWORD_FIELD(*event,
  962. FSF_AZ_DRIVER_EV_SUBDATA);
  963. if (ev_queue < EFX_TX_QUEUE_COUNT) {
  964. tx_queue = efx->tx_queue + ev_queue;
  965. tx_queue->flushed = FLUSH_DONE;
  966. }
  967. } else if (ev_code == FSE_AZ_EV_CODE_DRIVER_EV &&
  968. ev_sub_code == FSE_AZ_RX_DESCQ_FLS_DONE_EV) {
  969. ev_queue = EFX_QWORD_FIELD(
  970. *event, FSF_AZ_DRIVER_EV_RX_DESCQ_ID);
  971. ev_failed = EFX_QWORD_FIELD(
  972. *event, FSF_AZ_DRIVER_EV_RX_FLUSH_FAIL);
  973. if (ev_queue < efx->n_rx_queues) {
  974. rx_queue = efx->rx_queue + ev_queue;
  975. rx_queue->flushed =
  976. ev_failed ? FLUSH_FAILED : FLUSH_DONE;
  977. }
  978. }
  979. /* We're about to destroy the queue anyway, so
  980. * it's ok to throw away every non-flush event */
  981. EFX_SET_QWORD(*event);
  982. read_ptr = (read_ptr + 1) & EFX_EVQ_MASK;
  983. } while (read_ptr != end_ptr);
  984. channel->eventq_read_ptr = read_ptr;
  985. }
  986. /* Handle tx and rx flushes at the same time, since they run in
  987. * parallel in the hardware and there's no reason for us to
  988. * serialise them */
  989. int efx_nic_flush_queues(struct efx_nic *efx)
  990. {
  991. struct efx_rx_queue *rx_queue;
  992. struct efx_tx_queue *tx_queue;
  993. int i, tx_pending, rx_pending;
  994. /* If necessary prepare the hardware for flushing */
  995. efx->type->prepare_flush(efx);
  996. /* Flush all tx queues in parallel */
  997. efx_for_each_tx_queue(tx_queue, efx)
  998. efx_flush_tx_queue(tx_queue);
  999. /* The hardware supports four concurrent rx flushes, each of which may
  1000. * need to be retried if there is an outstanding descriptor fetch */
  1001. for (i = 0; i < EFX_FLUSH_POLL_COUNT; ++i) {
  1002. rx_pending = tx_pending = 0;
  1003. efx_for_each_rx_queue(rx_queue, efx) {
  1004. if (rx_queue->flushed == FLUSH_PENDING)
  1005. ++rx_pending;
  1006. }
  1007. efx_for_each_rx_queue(rx_queue, efx) {
  1008. if (rx_pending == EFX_RX_FLUSH_COUNT)
  1009. break;
  1010. if (rx_queue->flushed == FLUSH_FAILED ||
  1011. rx_queue->flushed == FLUSH_NONE) {
  1012. efx_flush_rx_queue(rx_queue);
  1013. ++rx_pending;
  1014. }
  1015. }
  1016. efx_for_each_tx_queue(tx_queue, efx) {
  1017. if (tx_queue->flushed != FLUSH_DONE)
  1018. ++tx_pending;
  1019. }
  1020. if (rx_pending == 0 && tx_pending == 0)
  1021. return 0;
  1022. msleep(EFX_FLUSH_INTERVAL);
  1023. efx_poll_flush_events(efx);
  1024. }
  1025. /* Mark the queues as all flushed. We're going to return failure
  1026. * leading to a reset, or fake up success anyway */
  1027. efx_for_each_tx_queue(tx_queue, efx) {
  1028. if (tx_queue->flushed != FLUSH_DONE)
  1029. EFX_ERR(efx, "tx queue %d flush command timed out\n",
  1030. tx_queue->queue);
  1031. tx_queue->flushed = FLUSH_DONE;
  1032. }
  1033. efx_for_each_rx_queue(rx_queue, efx) {
  1034. if (rx_queue->flushed != FLUSH_DONE)
  1035. EFX_ERR(efx, "rx queue %d flush command timed out\n",
  1036. rx_queue->queue);
  1037. rx_queue->flushed = FLUSH_DONE;
  1038. }
  1039. if (EFX_WORKAROUND_7803(efx))
  1040. return 0;
  1041. return -ETIMEDOUT;
  1042. }
  1043. /**************************************************************************
  1044. *
  1045. * Hardware interrupts
  1046. * The hardware interrupt handler does very little work; all the event
  1047. * queue processing is carried out by per-channel tasklets.
  1048. *
  1049. **************************************************************************/
  1050. /* Enable/disable/generate interrupts */
  1051. static inline void efx_nic_interrupts(struct efx_nic *efx,
  1052. bool enabled, bool force)
  1053. {
  1054. efx_oword_t int_en_reg_ker;
  1055. unsigned int level = 0;
  1056. if (EFX_WORKAROUND_17213(efx) && !EFX_INT_MODE_USE_MSI(efx))
  1057. /* Set the level always even if we're generating a test
  1058. * interrupt, because our legacy interrupt handler is safe */
  1059. level = 0x1f;
  1060. EFX_POPULATE_OWORD_3(int_en_reg_ker,
  1061. FRF_AZ_KER_INT_LEVE_SEL, 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 (error == 0)
  1107. goto out;
  1108. /* If this is a memory parity error dump which blocks are offending */
  1109. mem_perr = EFX_OWORD_FIELD(fatal_intr, FRF_AZ_MEM_PERR_INT_KER);
  1110. if (mem_perr) {
  1111. efx_oword_t reg;
  1112. efx_reado(efx, &reg, FR_AZ_MEM_STAT);
  1113. EFX_ERR(efx, "SYSTEM ERROR: memory parity error "
  1114. EFX_OWORD_FMT "\n", EFX_OWORD_VAL(reg));
  1115. }
  1116. /* Disable both devices */
  1117. pci_clear_master(efx->pci_dev);
  1118. if (efx_nic_is_dual_func(efx))
  1119. pci_clear_master(nic_data->pci_dev2);
  1120. efx_nic_disable_interrupts(efx);
  1121. /* Count errors and reset or disable the NIC accordingly */
  1122. if (efx->int_error_count == 0 ||
  1123. time_after(jiffies, efx->int_error_expire)) {
  1124. efx->int_error_count = 0;
  1125. efx->int_error_expire =
  1126. jiffies + EFX_INT_ERROR_EXPIRE * HZ;
  1127. }
  1128. if (++efx->int_error_count < EFX_MAX_INT_ERRORS) {
  1129. EFX_ERR(efx, "SYSTEM ERROR - reset scheduled\n");
  1130. efx_schedule_reset(efx, RESET_TYPE_INT_ERROR);
  1131. } else {
  1132. EFX_ERR(efx, "SYSTEM ERROR - max number of errors seen."
  1133. "NIC will be disabled\n");
  1134. efx_schedule_reset(efx, RESET_TYPE_DISABLE);
  1135. }
  1136. out:
  1137. return IRQ_HANDLED;
  1138. }
  1139. /* Handle a legacy interrupt
  1140. * Acknowledges the interrupt and schedule event queue processing.
  1141. */
  1142. static irqreturn_t efx_legacy_interrupt(int irq, void *dev_id)
  1143. {
  1144. struct efx_nic *efx = dev_id;
  1145. efx_oword_t *int_ker = efx->irq_status.addr;
  1146. irqreturn_t result = IRQ_NONE;
  1147. struct efx_channel *channel;
  1148. efx_dword_t reg;
  1149. u32 queues;
  1150. int syserr;
  1151. /* Read the ISR which also ACKs the interrupts */
  1152. efx_readd(efx, &reg, FR_BZ_INT_ISR0);
  1153. queues = EFX_EXTRACT_DWORD(reg, 0, 31);
  1154. /* Check to see if we have a serious error condition */
  1155. syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT);
  1156. if (unlikely(syserr))
  1157. return efx_nic_fatal_interrupt(efx);
  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->irq_zero_count++ == 0) {
  1170. efx_qword_t *event;
  1171. /* Ensure we rearm all event queues */
  1172. efx_for_each_channel(channel, efx) {
  1173. event = efx_event(channel, channel->eventq_read_ptr);
  1174. if (efx_event_present(event))
  1175. efx_schedule_channel(channel);
  1176. }
  1177. result = IRQ_HANDLED;
  1178. }
  1179. if (result == IRQ_HANDLED) {
  1180. efx->last_irq_cpu = raw_smp_processor_id();
  1181. EFX_TRACE(efx, "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
  1182. irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
  1183. }
  1184. return result;
  1185. }
  1186. /* Handle an MSI interrupt
  1187. *
  1188. * Handle an MSI hardware interrupt. This routine schedules event
  1189. * queue processing. No interrupt acknowledgement cycle is necessary.
  1190. * Also, we never need to check that the interrupt is for us, since
  1191. * MSI interrupts cannot be shared.
  1192. */
  1193. static irqreturn_t efx_msi_interrupt(int irq, void *dev_id)
  1194. {
  1195. struct efx_channel *channel = dev_id;
  1196. struct efx_nic *efx = channel->efx;
  1197. efx_oword_t *int_ker = efx->irq_status.addr;
  1198. int syserr;
  1199. efx->last_irq_cpu = raw_smp_processor_id();
  1200. EFX_TRACE(efx, "IRQ %d on CPU %d status " EFX_OWORD_FMT "\n",
  1201. irq, raw_smp_processor_id(), EFX_OWORD_VAL(*int_ker));
  1202. /* Check to see if we have a serious error condition */
  1203. syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT);
  1204. if (unlikely(syserr))
  1205. return efx_nic_fatal_interrupt(efx);
  1206. /* Schedule processing of the channel */
  1207. efx_schedule_channel(channel);
  1208. return IRQ_HANDLED;
  1209. }
  1210. /* Setup RSS indirection table.
  1211. * This maps from the hash value of the packet to RXQ
  1212. */
  1213. static void efx_setup_rss_indir_table(struct efx_nic *efx)
  1214. {
  1215. int i = 0;
  1216. unsigned long offset;
  1217. efx_dword_t dword;
  1218. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0)
  1219. return;
  1220. for (offset = FR_BZ_RX_INDIRECTION_TBL;
  1221. offset < FR_BZ_RX_INDIRECTION_TBL + 0x800;
  1222. offset += 0x10) {
  1223. EFX_POPULATE_DWORD_1(dword, FRF_BZ_IT_QUEUE,
  1224. i % efx->n_rx_queues);
  1225. efx_writed(efx, &dword, offset);
  1226. i++;
  1227. }
  1228. }
  1229. /* Hook interrupt handler(s)
  1230. * Try MSI and then legacy interrupts.
  1231. */
  1232. int efx_nic_init_interrupt(struct efx_nic *efx)
  1233. {
  1234. struct efx_channel *channel;
  1235. int rc;
  1236. if (!EFX_INT_MODE_USE_MSI(efx)) {
  1237. irq_handler_t handler;
  1238. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
  1239. handler = efx_legacy_interrupt;
  1240. else
  1241. handler = falcon_legacy_interrupt_a1;
  1242. rc = request_irq(efx->legacy_irq, handler, IRQF_SHARED,
  1243. efx->name, efx);
  1244. if (rc) {
  1245. EFX_ERR(efx, "failed to hook legacy IRQ %d\n",
  1246. efx->pci_dev->irq);
  1247. goto fail1;
  1248. }
  1249. return 0;
  1250. }
  1251. /* Hook MSI or MSI-X interrupt */
  1252. efx_for_each_channel(channel, efx) {
  1253. rc = request_irq(channel->irq, efx_msi_interrupt,
  1254. IRQF_PROBE_SHARED, /* Not shared */
  1255. channel->name, channel);
  1256. if (rc) {
  1257. EFX_ERR(efx, "failed to hook IRQ %d\n", channel->irq);
  1258. goto fail2;
  1259. }
  1260. }
  1261. return 0;
  1262. fail2:
  1263. efx_for_each_channel(channel, efx)
  1264. free_irq(channel->irq, channel);
  1265. fail1:
  1266. return rc;
  1267. }
  1268. void efx_nic_fini_interrupt(struct efx_nic *efx)
  1269. {
  1270. struct efx_channel *channel;
  1271. efx_oword_t reg;
  1272. /* Disable MSI/MSI-X interrupts */
  1273. efx_for_each_channel(channel, efx) {
  1274. if (channel->irq)
  1275. free_irq(channel->irq, channel);
  1276. }
  1277. /* ACK legacy interrupt */
  1278. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
  1279. efx_reado(efx, &reg, FR_BZ_INT_ISR0);
  1280. else
  1281. falcon_irq_ack_a1(efx);
  1282. /* Disable legacy interrupt */
  1283. if (efx->legacy_irq)
  1284. free_irq(efx->legacy_irq, efx);
  1285. }
  1286. u32 efx_nic_fpga_ver(struct efx_nic *efx)
  1287. {
  1288. efx_oword_t altera_build;
  1289. efx_reado(efx, &altera_build, FR_AZ_ALTERA_BUILD);
  1290. return EFX_OWORD_FIELD(altera_build, FRF_AZ_ALTERA_BUILD_VER);
  1291. }
  1292. void efx_nic_init_common(struct efx_nic *efx)
  1293. {
  1294. efx_oword_t temp;
  1295. /* Set positions of descriptor caches in SRAM. */
  1296. EFX_POPULATE_OWORD_1(temp, FRF_AZ_SRM_TX_DC_BASE_ADR,
  1297. efx->type->tx_dc_base / 8);
  1298. efx_writeo(efx, &temp, FR_AZ_SRM_TX_DC_CFG);
  1299. EFX_POPULATE_OWORD_1(temp, FRF_AZ_SRM_RX_DC_BASE_ADR,
  1300. efx->type->rx_dc_base / 8);
  1301. efx_writeo(efx, &temp, FR_AZ_SRM_RX_DC_CFG);
  1302. /* Set TX descriptor cache size. */
  1303. BUILD_BUG_ON(TX_DC_ENTRIES != (8 << TX_DC_ENTRIES_ORDER));
  1304. EFX_POPULATE_OWORD_1(temp, FRF_AZ_TX_DC_SIZE, TX_DC_ENTRIES_ORDER);
  1305. efx_writeo(efx, &temp, FR_AZ_TX_DC_CFG);
  1306. /* Set RX descriptor cache size. Set low watermark to size-8, as
  1307. * this allows most efficient prefetching.
  1308. */
  1309. BUILD_BUG_ON(RX_DC_ENTRIES != (8 << RX_DC_ENTRIES_ORDER));
  1310. EFX_POPULATE_OWORD_1(temp, FRF_AZ_RX_DC_SIZE, RX_DC_ENTRIES_ORDER);
  1311. efx_writeo(efx, &temp, FR_AZ_RX_DC_CFG);
  1312. EFX_POPULATE_OWORD_1(temp, FRF_AZ_RX_DC_PF_LWM, RX_DC_ENTRIES - 8);
  1313. efx_writeo(efx, &temp, FR_AZ_RX_DC_PF_WM);
  1314. /* Program INT_KER address */
  1315. EFX_POPULATE_OWORD_2(temp,
  1316. FRF_AZ_NORM_INT_VEC_DIS_KER,
  1317. EFX_INT_MODE_USE_MSI(efx),
  1318. FRF_AZ_INT_ADR_KER, efx->irq_status.dma_addr);
  1319. efx_writeo(efx, &temp, FR_AZ_INT_ADR_KER);
  1320. /* Enable all the genuinely fatal interrupts. (They are still
  1321. * masked by the overall interrupt mask, controlled by
  1322. * falcon_interrupts()).
  1323. *
  1324. * Note: All other fatal interrupts are enabled
  1325. */
  1326. EFX_POPULATE_OWORD_3(temp,
  1327. FRF_AZ_ILL_ADR_INT_KER_EN, 1,
  1328. FRF_AZ_RBUF_OWN_INT_KER_EN, 1,
  1329. FRF_AZ_TBUF_OWN_INT_KER_EN, 1);
  1330. EFX_INVERT_OWORD(temp);
  1331. efx_writeo(efx, &temp, FR_AZ_FATAL_INTR_KER);
  1332. efx_setup_rss_indir_table(efx);
  1333. /* Disable the ugly timer-based TX DMA backoff and allow TX DMA to be
  1334. * controlled by the RX FIFO fill level. Set arbitration to one pkt/Q.
  1335. */
  1336. efx_reado(efx, &temp, FR_AZ_TX_RESERVED);
  1337. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_RX_SPACER, 0xfe);
  1338. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_RX_SPACER_EN, 1);
  1339. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_ONE_PKT_PER_Q, 1);
  1340. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PUSH_EN, 0);
  1341. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_DIS_NON_IP_EV, 1);
  1342. /* Enable SW_EV to inherit in char driver - assume harmless here */
  1343. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_SOFT_EVT_EN, 1);
  1344. /* Prefetch threshold 2 => fetch when descriptor cache half empty */
  1345. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PREF_THRESHOLD, 2);
  1346. /* Disable hardware watchdog which can misfire */
  1347. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PREF_WD_TMR, 0x3fffff);
  1348. /* Squash TX of packets of 16 bytes or less */
  1349. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
  1350. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TX_FLUSH_MIN_LEN_EN, 1);
  1351. efx_writeo(efx, &temp, FR_AZ_TX_RESERVED);
  1352. }