nic.c 48 KB

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