nic.c 47 KB

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