nic.c 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2006-2011 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/interrupt.h>
  13. #include <linux/pci.h>
  14. #include <linux/module.h>
  15. #include <linux/seq_file.h>
  16. #include "net_driver.h"
  17. #include "bitfield.h"
  18. #include "efx.h"
  19. #include "nic.h"
  20. #include "regs.h"
  21. #include "io.h"
  22. #include "workarounds.h"
  23. /**************************************************************************
  24. *
  25. * Configurable values
  26. *
  27. **************************************************************************
  28. */
  29. /* This is set to 16 for a good reason. In summary, if larger than
  30. * 16, the descriptor cache holds more than a default socket
  31. * buffer's worth of packets (for UDP we can only have at most one
  32. * socket buffer's worth outstanding). This combined with the fact
  33. * that we only get 1 TX event per descriptor cache means the NIC
  34. * goes idle.
  35. */
  36. #define TX_DC_ENTRIES 16
  37. #define TX_DC_ENTRIES_ORDER 1
  38. #define RX_DC_ENTRIES 64
  39. #define RX_DC_ENTRIES_ORDER 3
  40. /* If EFX_MAX_INT_ERRORS internal errors occur within
  41. * EFX_INT_ERROR_EXPIRE seconds, we consider the NIC broken and
  42. * disable it.
  43. */
  44. #define EFX_INT_ERROR_EXPIRE 3600
  45. #define EFX_MAX_INT_ERRORS 5
  46. /* We poll for events every FLUSH_INTERVAL ms, and check FLUSH_POLL_COUNT times
  47. */
  48. #define EFX_FLUSH_INTERVAL 10
  49. #define EFX_FLUSH_POLL_COUNT 100
  50. /* Depth of RX flush request fifo */
  51. #define EFX_RX_FLUSH_COUNT 4
  52. /* Driver generated events */
  53. #define _EFX_CHANNEL_MAGIC_TEST 0x000101
  54. #define _EFX_CHANNEL_MAGIC_FILL 0x000102
  55. #define _EFX_CHANNEL_MAGIC(_code, _data) ((_code) << 8 | (_data))
  56. #define _EFX_CHANNEL_MAGIC_CODE(_magic) ((_magic) >> 8)
  57. #define EFX_CHANNEL_MAGIC_TEST(_channel) \
  58. _EFX_CHANNEL_MAGIC(_EFX_CHANNEL_MAGIC_TEST, (_channel)->channel)
  59. #define EFX_CHANNEL_MAGIC_FILL(_rx_queue) \
  60. _EFX_CHANNEL_MAGIC(_EFX_CHANNEL_MAGIC_FILL, \
  61. efx_rx_queue_index(_rx_queue))
  62. /**************************************************************************
  63. *
  64. * Solarstorm hardware access
  65. *
  66. **************************************************************************/
  67. static inline void efx_write_buf_tbl(struct efx_nic *efx, efx_qword_t *value,
  68. unsigned int index)
  69. {
  70. efx_sram_writeq(efx, efx->membase + efx->type->buf_tbl_base,
  71. value, index);
  72. }
  73. /* Read the current event from the event queue */
  74. static inline efx_qword_t *efx_event(struct efx_channel *channel,
  75. unsigned int index)
  76. {
  77. return ((efx_qword_t *) (channel->eventq.addr)) +
  78. (index & channel->eventq_mask);
  79. }
  80. /* See if an event is present
  81. *
  82. * We check both the high and low dword of the event for all ones. We
  83. * wrote all ones when we cleared the event, and no valid event can
  84. * have all ones in either its high or low dwords. This approach is
  85. * robust against reordering.
  86. *
  87. * Note that using a single 64-bit comparison is incorrect; even
  88. * though the CPU read will be atomic, the DMA write may not be.
  89. */
  90. static inline int efx_event_present(efx_qword_t *event)
  91. {
  92. return !(EFX_DWORD_IS_ALL_ONES(event->dword[0]) |
  93. EFX_DWORD_IS_ALL_ONES(event->dword[1]));
  94. }
  95. static bool efx_masked_compare_oword(const efx_oword_t *a, const efx_oword_t *b,
  96. const efx_oword_t *mask)
  97. {
  98. return ((a->u64[0] ^ b->u64[0]) & mask->u64[0]) ||
  99. ((a->u64[1] ^ b->u64[1]) & mask->u64[1]);
  100. }
  101. int efx_nic_test_registers(struct efx_nic *efx,
  102. const struct efx_nic_register_test *regs,
  103. size_t n_regs)
  104. {
  105. unsigned address = 0, i, j;
  106. efx_oword_t mask, imask, original, reg, buf;
  107. /* Falcon should be in loopback to isolate the XMAC from the PHY */
  108. WARN_ON(!LOOPBACK_INTERNAL(efx));
  109. for (i = 0; i < n_regs; ++i) {
  110. address = regs[i].address;
  111. mask = imask = regs[i].mask;
  112. EFX_INVERT_OWORD(imask);
  113. efx_reado(efx, &original, address);
  114. /* bit sweep on and off */
  115. for (j = 0; j < 128; j++) {
  116. if (!EFX_EXTRACT_OWORD32(mask, j, j))
  117. continue;
  118. /* Test this testable bit can be set in isolation */
  119. EFX_AND_OWORD(reg, original, mask);
  120. EFX_SET_OWORD32(reg, j, j, 1);
  121. efx_writeo(efx, &reg, address);
  122. efx_reado(efx, &buf, address);
  123. if (efx_masked_compare_oword(&reg, &buf, &mask))
  124. goto fail;
  125. /* Test this testable bit can be cleared in isolation */
  126. EFX_OR_OWORD(reg, original, mask);
  127. EFX_SET_OWORD32(reg, j, j, 0);
  128. efx_writeo(efx, &reg, address);
  129. efx_reado(efx, &buf, address);
  130. if (efx_masked_compare_oword(&reg, &buf, &mask))
  131. goto fail;
  132. }
  133. efx_writeo(efx, &original, address);
  134. }
  135. return 0;
  136. fail:
  137. netif_err(efx, hw, efx->net_dev,
  138. "wrote "EFX_OWORD_FMT" read "EFX_OWORD_FMT
  139. " at address 0x%x mask "EFX_OWORD_FMT"\n", EFX_OWORD_VAL(reg),
  140. EFX_OWORD_VAL(buf), address, EFX_OWORD_VAL(mask));
  141. return -EIO;
  142. }
  143. /**************************************************************************
  144. *
  145. * Special buffer handling
  146. * Special buffers are used for event queues and the TX and RX
  147. * descriptor rings.
  148. *
  149. *************************************************************************/
  150. /*
  151. * Initialise a special buffer
  152. *
  153. * This will define a buffer (previously allocated via
  154. * efx_alloc_special_buffer()) in the buffer table, allowing
  155. * it to be used for event queues, descriptor rings etc.
  156. */
  157. static void
  158. efx_init_special_buffer(struct efx_nic *efx, struct efx_special_buffer *buffer)
  159. {
  160. efx_qword_t buf_desc;
  161. int index;
  162. dma_addr_t dma_addr;
  163. int i;
  164. EFX_BUG_ON_PARANOID(!buffer->addr);
  165. /* Write buffer descriptors to NIC */
  166. for (i = 0; i < buffer->entries; i++) {
  167. index = buffer->index + i;
  168. dma_addr = buffer->dma_addr + (i * EFX_BUF_SIZE);
  169. netif_dbg(efx, probe, efx->net_dev,
  170. "mapping special buffer %d at %llx\n",
  171. index, (unsigned long long)dma_addr);
  172. EFX_POPULATE_QWORD_3(buf_desc,
  173. FRF_AZ_BUF_ADR_REGION, 0,
  174. FRF_AZ_BUF_ADR_FBUF, dma_addr >> 12,
  175. FRF_AZ_BUF_OWNER_ID_FBUF, 0);
  176. efx_write_buf_tbl(efx, &buf_desc, index);
  177. }
  178. }
  179. /* Unmaps a buffer and clears the buffer table entries */
  180. static void
  181. efx_fini_special_buffer(struct efx_nic *efx, struct efx_special_buffer *buffer)
  182. {
  183. efx_oword_t buf_tbl_upd;
  184. unsigned int start = buffer->index;
  185. unsigned int end = (buffer->index + buffer->entries - 1);
  186. if (!buffer->entries)
  187. return;
  188. netif_dbg(efx, hw, efx->net_dev, "unmapping special buffers %d-%d\n",
  189. buffer->index, buffer->index + buffer->entries - 1);
  190. EFX_POPULATE_OWORD_4(buf_tbl_upd,
  191. FRF_AZ_BUF_UPD_CMD, 0,
  192. FRF_AZ_BUF_CLR_CMD, 1,
  193. FRF_AZ_BUF_CLR_END_ID, end,
  194. FRF_AZ_BUF_CLR_START_ID, start);
  195. efx_writeo(efx, &buf_tbl_upd, FR_AZ_BUF_TBL_UPD);
  196. }
  197. /*
  198. * Allocate a new special buffer
  199. *
  200. * This allocates memory for a new buffer, clears it and allocates a
  201. * new buffer ID range. It does not write into the buffer table.
  202. *
  203. * This call will allocate 4KB buffers, since 8KB buffers can't be
  204. * used for event queues and descriptor rings.
  205. */
  206. static int efx_alloc_special_buffer(struct efx_nic *efx,
  207. struct efx_special_buffer *buffer,
  208. unsigned int len)
  209. {
  210. len = ALIGN(len, EFX_BUF_SIZE);
  211. buffer->addr = dma_alloc_coherent(&efx->pci_dev->dev, len,
  212. &buffer->dma_addr, GFP_KERNEL);
  213. if (!buffer->addr)
  214. return -ENOMEM;
  215. buffer->len = len;
  216. buffer->entries = len / EFX_BUF_SIZE;
  217. BUG_ON(buffer->dma_addr & (EFX_BUF_SIZE - 1));
  218. /* All zeros is a potentially valid event so memset to 0xff */
  219. memset(buffer->addr, 0xff, len);
  220. /* Select new buffer ID */
  221. buffer->index = efx->next_buffer_table;
  222. efx->next_buffer_table += buffer->entries;
  223. netif_dbg(efx, probe, efx->net_dev,
  224. "allocating special buffers %d-%d at %llx+%x "
  225. "(virt %p phys %llx)\n", buffer->index,
  226. buffer->index + buffer->entries - 1,
  227. (u64)buffer->dma_addr, len,
  228. buffer->addr, (u64)virt_to_phys(buffer->addr));
  229. return 0;
  230. }
  231. static void
  232. efx_free_special_buffer(struct efx_nic *efx, struct efx_special_buffer *buffer)
  233. {
  234. if (!buffer->addr)
  235. return;
  236. netif_dbg(efx, hw, efx->net_dev,
  237. "deallocating special buffers %d-%d at %llx+%x "
  238. "(virt %p phys %llx)\n", buffer->index,
  239. buffer->index + buffer->entries - 1,
  240. (u64)buffer->dma_addr, buffer->len,
  241. buffer->addr, (u64)virt_to_phys(buffer->addr));
  242. dma_free_coherent(&efx->pci_dev->dev, buffer->len, buffer->addr,
  243. buffer->dma_addr);
  244. buffer->addr = NULL;
  245. buffer->entries = 0;
  246. }
  247. /**************************************************************************
  248. *
  249. * Generic buffer handling
  250. * These buffers are used for interrupt status and MAC stats
  251. *
  252. **************************************************************************/
  253. int efx_nic_alloc_buffer(struct efx_nic *efx, struct efx_buffer *buffer,
  254. unsigned int len)
  255. {
  256. buffer->addr = pci_alloc_consistent(efx->pci_dev, len,
  257. &buffer->dma_addr);
  258. if (!buffer->addr)
  259. return -ENOMEM;
  260. buffer->len = len;
  261. memset(buffer->addr, 0, len);
  262. return 0;
  263. }
  264. void efx_nic_free_buffer(struct efx_nic *efx, struct efx_buffer *buffer)
  265. {
  266. if (buffer->addr) {
  267. pci_free_consistent(efx->pci_dev, buffer->len,
  268. buffer->addr, buffer->dma_addr);
  269. buffer->addr = NULL;
  270. }
  271. }
  272. /**************************************************************************
  273. *
  274. * TX path
  275. *
  276. **************************************************************************/
  277. /* Returns a pointer to the specified transmit descriptor in the TX
  278. * descriptor queue belonging to the specified channel.
  279. */
  280. static inline efx_qword_t *
  281. efx_tx_desc(struct efx_tx_queue *tx_queue, unsigned int index)
  282. {
  283. return ((efx_qword_t *) (tx_queue->txd.addr)) + index;
  284. }
  285. /* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
  286. static inline void efx_notify_tx_desc(struct efx_tx_queue *tx_queue)
  287. {
  288. unsigned write_ptr;
  289. efx_dword_t reg;
  290. write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
  291. EFX_POPULATE_DWORD_1(reg, FRF_AZ_TX_DESC_WPTR_DWORD, write_ptr);
  292. efx_writed_page(tx_queue->efx, &reg,
  293. FR_AZ_TX_DESC_UPD_DWORD_P0, tx_queue->queue);
  294. }
  295. /* Write pointer and first descriptor for TX descriptor ring */
  296. static inline void efx_push_tx_desc(struct efx_tx_queue *tx_queue,
  297. const efx_qword_t *txd)
  298. {
  299. unsigned write_ptr;
  300. efx_oword_t reg;
  301. BUILD_BUG_ON(FRF_AZ_TX_DESC_LBN != 0);
  302. BUILD_BUG_ON(FR_AA_TX_DESC_UPD_KER != FR_BZ_TX_DESC_UPD_P0);
  303. write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
  304. EFX_POPULATE_OWORD_2(reg, FRF_AZ_TX_DESC_PUSH_CMD, true,
  305. FRF_AZ_TX_DESC_WPTR, write_ptr);
  306. reg.qword[0] = *txd;
  307. efx_writeo_page(tx_queue->efx, &reg,
  308. FR_BZ_TX_DESC_UPD_P0, tx_queue->queue);
  309. }
  310. static inline bool
  311. efx_may_push_tx_desc(struct efx_tx_queue *tx_queue, unsigned int write_count)
  312. {
  313. unsigned empty_read_count = ACCESS_ONCE(tx_queue->empty_read_count);
  314. if (empty_read_count == 0)
  315. return false;
  316. tx_queue->empty_read_count = 0;
  317. return ((empty_read_count ^ write_count) & ~EFX_EMPTY_COUNT_VALID) == 0;
  318. }
  319. /* For each entry inserted into the software descriptor ring, create a
  320. * descriptor in the hardware TX descriptor ring (in host memory), and
  321. * write a doorbell.
  322. */
  323. void efx_nic_push_buffers(struct efx_tx_queue *tx_queue)
  324. {
  325. struct efx_tx_buffer *buffer;
  326. efx_qword_t *txd;
  327. unsigned write_ptr;
  328. unsigned old_write_count = tx_queue->write_count;
  329. BUG_ON(tx_queue->write_count == tx_queue->insert_count);
  330. do {
  331. write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
  332. buffer = &tx_queue->buffer[write_ptr];
  333. txd = efx_tx_desc(tx_queue, write_ptr);
  334. ++tx_queue->write_count;
  335. /* Create TX descriptor ring entry */
  336. EFX_POPULATE_QWORD_4(*txd,
  337. FSF_AZ_TX_KER_CONT, buffer->continuation,
  338. FSF_AZ_TX_KER_BYTE_COUNT, buffer->len,
  339. FSF_AZ_TX_KER_BUF_REGION, 0,
  340. FSF_AZ_TX_KER_BUF_ADDR, buffer->dma_addr);
  341. } while (tx_queue->write_count != tx_queue->insert_count);
  342. wmb(); /* Ensure descriptors are written before they are fetched */
  343. if (efx_may_push_tx_desc(tx_queue, old_write_count)) {
  344. txd = efx_tx_desc(tx_queue,
  345. old_write_count & tx_queue->ptr_mask);
  346. efx_push_tx_desc(tx_queue, txd);
  347. ++tx_queue->pushes;
  348. } else {
  349. efx_notify_tx_desc(tx_queue);
  350. }
  351. }
  352. /* Allocate hardware resources for a TX queue */
  353. int efx_nic_probe_tx(struct efx_tx_queue *tx_queue)
  354. {
  355. struct efx_nic *efx = tx_queue->efx;
  356. unsigned entries;
  357. entries = tx_queue->ptr_mask + 1;
  358. return efx_alloc_special_buffer(efx, &tx_queue->txd,
  359. entries * sizeof(efx_qword_t));
  360. }
  361. void efx_nic_init_tx(struct efx_tx_queue *tx_queue)
  362. {
  363. struct efx_nic *efx = tx_queue->efx;
  364. efx_oword_t reg;
  365. tx_queue->flushed = FLUSH_NONE;
  366. /* Pin TX descriptor ring */
  367. efx_init_special_buffer(efx, &tx_queue->txd);
  368. /* Push TX descriptor ring to card */
  369. EFX_POPULATE_OWORD_10(reg,
  370. FRF_AZ_TX_DESCQ_EN, 1,
  371. FRF_AZ_TX_ISCSI_DDIG_EN, 0,
  372. FRF_AZ_TX_ISCSI_HDIG_EN, 0,
  373. FRF_AZ_TX_DESCQ_BUF_BASE_ID, tx_queue->txd.index,
  374. FRF_AZ_TX_DESCQ_EVQ_ID,
  375. tx_queue->channel->channel,
  376. FRF_AZ_TX_DESCQ_OWNER_ID, 0,
  377. FRF_AZ_TX_DESCQ_LABEL, tx_queue->queue,
  378. FRF_AZ_TX_DESCQ_SIZE,
  379. __ffs(tx_queue->txd.entries),
  380. FRF_AZ_TX_DESCQ_TYPE, 0,
  381. FRF_BZ_TX_NON_IP_DROP_DIS, 1);
  382. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) {
  383. int csum = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD;
  384. EFX_SET_OWORD_FIELD(reg, FRF_BZ_TX_IP_CHKSM_DIS, !csum);
  385. EFX_SET_OWORD_FIELD(reg, FRF_BZ_TX_TCP_CHKSM_DIS,
  386. !csum);
  387. }
  388. efx_writeo_table(efx, &reg, efx->type->txd_ptr_tbl_base,
  389. tx_queue->queue);
  390. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0) {
  391. /* Only 128 bits in this register */
  392. BUILD_BUG_ON(EFX_MAX_TX_QUEUES > 128);
  393. efx_reado(efx, &reg, FR_AA_TX_CHKSM_CFG);
  394. if (tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD)
  395. clear_bit_le(tx_queue->queue, (void *)&reg);
  396. else
  397. set_bit_le(tx_queue->queue, (void *)&reg);
  398. efx_writeo(efx, &reg, FR_AA_TX_CHKSM_CFG);
  399. }
  400. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) {
  401. EFX_POPULATE_OWORD_1(reg,
  402. FRF_BZ_TX_PACE,
  403. (tx_queue->queue & EFX_TXQ_TYPE_HIGHPRI) ?
  404. FFE_BZ_TX_PACE_OFF :
  405. FFE_BZ_TX_PACE_RESERVED);
  406. efx_writeo_table(efx, &reg, FR_BZ_TX_PACE_TBL,
  407. tx_queue->queue);
  408. }
  409. }
  410. static void efx_flush_tx_queue(struct efx_tx_queue *tx_queue)
  411. {
  412. struct efx_nic *efx = tx_queue->efx;
  413. efx_oword_t tx_flush_descq;
  414. tx_queue->flushed = FLUSH_PENDING;
  415. /* Post a flush command */
  416. EFX_POPULATE_OWORD_2(tx_flush_descq,
  417. FRF_AZ_TX_FLUSH_DESCQ_CMD, 1,
  418. FRF_AZ_TX_FLUSH_DESCQ, tx_queue->queue);
  419. efx_writeo(efx, &tx_flush_descq, FR_AZ_TX_FLUSH_DESCQ);
  420. }
  421. void efx_nic_fini_tx(struct efx_tx_queue *tx_queue)
  422. {
  423. struct efx_nic *efx = tx_queue->efx;
  424. efx_oword_t tx_desc_ptr;
  425. /* The queue should have been flushed */
  426. WARN_ON(tx_queue->flushed != FLUSH_DONE);
  427. /* Remove TX descriptor ring from card */
  428. EFX_ZERO_OWORD(tx_desc_ptr);
  429. efx_writeo_table(efx, &tx_desc_ptr, efx->type->txd_ptr_tbl_base,
  430. tx_queue->queue);
  431. /* Unpin TX descriptor ring */
  432. efx_fini_special_buffer(efx, &tx_queue->txd);
  433. }
  434. /* Free buffers backing TX queue */
  435. void efx_nic_remove_tx(struct efx_tx_queue *tx_queue)
  436. {
  437. efx_free_special_buffer(tx_queue->efx, &tx_queue->txd);
  438. }
  439. /**************************************************************************
  440. *
  441. * RX path
  442. *
  443. **************************************************************************/
  444. /* Returns a pointer to the specified descriptor in the RX descriptor queue */
  445. static inline efx_qword_t *
  446. efx_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index)
  447. {
  448. return ((efx_qword_t *) (rx_queue->rxd.addr)) + index;
  449. }
  450. /* This creates an entry in the RX descriptor queue */
  451. static inline void
  452. efx_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned index)
  453. {
  454. struct efx_rx_buffer *rx_buf;
  455. efx_qword_t *rxd;
  456. rxd = efx_rx_desc(rx_queue, index);
  457. rx_buf = efx_rx_buffer(rx_queue, index);
  458. EFX_POPULATE_QWORD_3(*rxd,
  459. FSF_AZ_RX_KER_BUF_SIZE,
  460. rx_buf->len -
  461. rx_queue->efx->type->rx_buffer_padding,
  462. FSF_AZ_RX_KER_BUF_REGION, 0,
  463. FSF_AZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
  464. }
  465. /* This writes to the RX_DESC_WPTR register for the specified receive
  466. * descriptor ring.
  467. */
  468. void efx_nic_notify_rx_desc(struct efx_rx_queue *rx_queue)
  469. {
  470. struct efx_nic *efx = rx_queue->efx;
  471. efx_dword_t reg;
  472. unsigned write_ptr;
  473. while (rx_queue->notified_count != rx_queue->added_count) {
  474. efx_build_rx_desc(
  475. rx_queue,
  476. rx_queue->notified_count & rx_queue->ptr_mask);
  477. ++rx_queue->notified_count;
  478. }
  479. wmb();
  480. write_ptr = rx_queue->added_count & rx_queue->ptr_mask;
  481. EFX_POPULATE_DWORD_1(reg, FRF_AZ_RX_DESC_WPTR_DWORD, write_ptr);
  482. efx_writed_page(efx, &reg, FR_AZ_RX_DESC_UPD_DWORD_P0,
  483. efx_rx_queue_index(rx_queue));
  484. }
  485. int efx_nic_probe_rx(struct efx_rx_queue *rx_queue)
  486. {
  487. struct efx_nic *efx = rx_queue->efx;
  488. unsigned entries;
  489. entries = rx_queue->ptr_mask + 1;
  490. return efx_alloc_special_buffer(efx, &rx_queue->rxd,
  491. entries * sizeof(efx_qword_t));
  492. }
  493. void efx_nic_init_rx(struct efx_rx_queue *rx_queue)
  494. {
  495. efx_oword_t rx_desc_ptr;
  496. struct efx_nic *efx = rx_queue->efx;
  497. bool is_b0 = efx_nic_rev(efx) >= EFX_REV_FALCON_B0;
  498. bool iscsi_digest_en = is_b0;
  499. netif_dbg(efx, hw, efx->net_dev,
  500. "RX queue %d ring in special buffers %d-%d\n",
  501. efx_rx_queue_index(rx_queue), rx_queue->rxd.index,
  502. rx_queue->rxd.index + rx_queue->rxd.entries - 1);
  503. rx_queue->flushed = FLUSH_NONE;
  504. /* Pin RX descriptor ring */
  505. efx_init_special_buffer(efx, &rx_queue->rxd);
  506. /* Push RX descriptor ring to card */
  507. EFX_POPULATE_OWORD_10(rx_desc_ptr,
  508. FRF_AZ_RX_ISCSI_DDIG_EN, iscsi_digest_en,
  509. FRF_AZ_RX_ISCSI_HDIG_EN, iscsi_digest_en,
  510. FRF_AZ_RX_DESCQ_BUF_BASE_ID, rx_queue->rxd.index,
  511. FRF_AZ_RX_DESCQ_EVQ_ID,
  512. efx_rx_queue_channel(rx_queue)->channel,
  513. FRF_AZ_RX_DESCQ_OWNER_ID, 0,
  514. FRF_AZ_RX_DESCQ_LABEL,
  515. efx_rx_queue_index(rx_queue),
  516. FRF_AZ_RX_DESCQ_SIZE,
  517. __ffs(rx_queue->rxd.entries),
  518. FRF_AZ_RX_DESCQ_TYPE, 0 /* kernel queue */ ,
  519. /* For >=B0 this is scatter so disable */
  520. FRF_AZ_RX_DESCQ_JUMBO, !is_b0,
  521. FRF_AZ_RX_DESCQ_EN, 1);
  522. efx_writeo_table(efx, &rx_desc_ptr, efx->type->rxd_ptr_tbl_base,
  523. efx_rx_queue_index(rx_queue));
  524. }
  525. static void efx_flush_rx_queue(struct efx_rx_queue *rx_queue)
  526. {
  527. struct efx_nic *efx = rx_queue->efx;
  528. efx_oword_t rx_flush_descq;
  529. rx_queue->flushed = FLUSH_PENDING;
  530. /* Post a flush command */
  531. EFX_POPULATE_OWORD_2(rx_flush_descq,
  532. FRF_AZ_RX_FLUSH_DESCQ_CMD, 1,
  533. FRF_AZ_RX_FLUSH_DESCQ,
  534. efx_rx_queue_index(rx_queue));
  535. efx_writeo(efx, &rx_flush_descq, FR_AZ_RX_FLUSH_DESCQ);
  536. }
  537. void efx_nic_fini_rx(struct efx_rx_queue *rx_queue)
  538. {
  539. efx_oword_t rx_desc_ptr;
  540. struct efx_nic *efx = rx_queue->efx;
  541. /* The queue should already have been flushed */
  542. WARN_ON(rx_queue->flushed != FLUSH_DONE);
  543. /* Remove RX descriptor ring from card */
  544. EFX_ZERO_OWORD(rx_desc_ptr);
  545. efx_writeo_table(efx, &rx_desc_ptr, efx->type->rxd_ptr_tbl_base,
  546. efx_rx_queue_index(rx_queue));
  547. /* Unpin RX descriptor ring */
  548. efx_fini_special_buffer(efx, &rx_queue->rxd);
  549. }
  550. /* Free buffers backing RX queue */
  551. void efx_nic_remove_rx(struct efx_rx_queue *rx_queue)
  552. {
  553. efx_free_special_buffer(rx_queue->efx, &rx_queue->rxd);
  554. }
  555. /**************************************************************************
  556. *
  557. * Event queue processing
  558. * Event queues are processed by per-channel tasklets.
  559. *
  560. **************************************************************************/
  561. /* Update a channel's event queue's read pointer (RPTR) register
  562. *
  563. * This writes the EVQ_RPTR_REG register for the specified channel's
  564. * event queue.
  565. */
  566. void efx_nic_eventq_read_ack(struct efx_channel *channel)
  567. {
  568. efx_dword_t reg;
  569. struct efx_nic *efx = channel->efx;
  570. EFX_POPULATE_DWORD_1(reg, FRF_AZ_EVQ_RPTR,
  571. channel->eventq_read_ptr & channel->eventq_mask);
  572. efx_writed_table(efx, &reg, efx->type->evq_rptr_tbl_base,
  573. channel->channel);
  574. }
  575. /* Use HW to insert a SW defined event */
  576. static void efx_generate_event(struct efx_channel *channel, efx_qword_t *event)
  577. {
  578. efx_oword_t drv_ev_reg;
  579. BUILD_BUG_ON(FRF_AZ_DRV_EV_DATA_LBN != 0 ||
  580. FRF_AZ_DRV_EV_DATA_WIDTH != 64);
  581. drv_ev_reg.u32[0] = event->u32[0];
  582. drv_ev_reg.u32[1] = event->u32[1];
  583. drv_ev_reg.u32[2] = 0;
  584. drv_ev_reg.u32[3] = 0;
  585. EFX_SET_OWORD_FIELD(drv_ev_reg, FRF_AZ_DRV_EV_QID, channel->channel);
  586. efx_writeo(channel->efx, &drv_ev_reg, FR_AZ_DRV_EV);
  587. }
  588. static void efx_magic_event(struct efx_channel *channel, u32 magic)
  589. {
  590. efx_qword_t event;
  591. EFX_POPULATE_QWORD_2(event, FSF_AZ_EV_CODE,
  592. FSE_AZ_EV_CODE_DRV_GEN_EV,
  593. FSF_AZ_DRV_GEN_EV_MAGIC, magic);
  594. efx_generate_event(channel, &event);
  595. }
  596. /* Handle a transmit completion event
  597. *
  598. * The NIC batches TX completion events; the message we receive is of
  599. * the form "complete all TX events up to this index".
  600. */
  601. static int
  602. efx_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
  603. {
  604. unsigned int tx_ev_desc_ptr;
  605. unsigned int tx_ev_q_label;
  606. struct efx_tx_queue *tx_queue;
  607. struct efx_nic *efx = channel->efx;
  608. int tx_packets = 0;
  609. if (likely(EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_COMP))) {
  610. /* Transmit completion */
  611. tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_DESC_PTR);
  612. tx_ev_q_label = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_Q_LABEL);
  613. tx_queue = efx_channel_get_tx_queue(
  614. channel, tx_ev_q_label % EFX_TXQ_TYPES);
  615. tx_packets = ((tx_ev_desc_ptr - tx_queue->read_count) &
  616. tx_queue->ptr_mask);
  617. channel->irq_mod_score += tx_packets;
  618. efx_xmit_done(tx_queue, tx_ev_desc_ptr);
  619. } else if (EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_WQ_FF_FULL)) {
  620. /* Rewrite the FIFO write pointer */
  621. tx_ev_q_label = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_Q_LABEL);
  622. tx_queue = efx_channel_get_tx_queue(
  623. channel, tx_ev_q_label % EFX_TXQ_TYPES);
  624. netif_tx_lock(efx->net_dev);
  625. efx_notify_tx_desc(tx_queue);
  626. netif_tx_unlock(efx->net_dev);
  627. } else if (EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_PKT_ERR) &&
  628. EFX_WORKAROUND_10727(efx)) {
  629. efx_schedule_reset(efx, RESET_TYPE_TX_DESC_FETCH);
  630. } else {
  631. netif_err(efx, tx_err, efx->net_dev,
  632. "channel %d unexpected TX event "
  633. EFX_QWORD_FMT"\n", channel->channel,
  634. EFX_QWORD_VAL(*event));
  635. }
  636. return tx_packets;
  637. }
  638. /* Detect errors included in the rx_evt_pkt_ok bit. */
  639. static u16 efx_handle_rx_not_ok(struct efx_rx_queue *rx_queue,
  640. const efx_qword_t *event)
  641. {
  642. struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
  643. struct efx_nic *efx = rx_queue->efx;
  644. bool rx_ev_buf_owner_id_err, rx_ev_ip_hdr_chksum_err;
  645. bool rx_ev_tcp_udp_chksum_err, rx_ev_eth_crc_err;
  646. bool rx_ev_frm_trunc, rx_ev_drib_nib, rx_ev_tobe_disc;
  647. bool rx_ev_other_err, rx_ev_pause_frm;
  648. bool rx_ev_hdr_type, rx_ev_mcast_pkt;
  649. unsigned rx_ev_pkt_type;
  650. rx_ev_hdr_type = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_HDR_TYPE);
  651. rx_ev_mcast_pkt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_PKT);
  652. rx_ev_tobe_disc = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_TOBE_DISC);
  653. rx_ev_pkt_type = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_PKT_TYPE);
  654. rx_ev_buf_owner_id_err = EFX_QWORD_FIELD(*event,
  655. FSF_AZ_RX_EV_BUF_OWNER_ID_ERR);
  656. rx_ev_ip_hdr_chksum_err = EFX_QWORD_FIELD(*event,
  657. FSF_AZ_RX_EV_IP_HDR_CHKSUM_ERR);
  658. rx_ev_tcp_udp_chksum_err = EFX_QWORD_FIELD(*event,
  659. FSF_AZ_RX_EV_TCP_UDP_CHKSUM_ERR);
  660. rx_ev_eth_crc_err = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_ETH_CRC_ERR);
  661. rx_ev_frm_trunc = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_FRM_TRUNC);
  662. rx_ev_drib_nib = ((efx_nic_rev(efx) >= EFX_REV_FALCON_B0) ?
  663. 0 : EFX_QWORD_FIELD(*event, FSF_AA_RX_EV_DRIB_NIB));
  664. rx_ev_pause_frm = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_PAUSE_FRM_ERR);
  665. /* Every error apart from tobe_disc and pause_frm */
  666. rx_ev_other_err = (rx_ev_drib_nib | rx_ev_tcp_udp_chksum_err |
  667. rx_ev_buf_owner_id_err | rx_ev_eth_crc_err |
  668. rx_ev_frm_trunc | rx_ev_ip_hdr_chksum_err);
  669. /* Count errors that are not in MAC stats. Ignore expected
  670. * checksum errors during self-test. */
  671. if (rx_ev_frm_trunc)
  672. ++channel->n_rx_frm_trunc;
  673. else if (rx_ev_tobe_disc)
  674. ++channel->n_rx_tobe_disc;
  675. else if (!efx->loopback_selftest) {
  676. if (rx_ev_ip_hdr_chksum_err)
  677. ++channel->n_rx_ip_hdr_chksum_err;
  678. else if (rx_ev_tcp_udp_chksum_err)
  679. ++channel->n_rx_tcp_udp_chksum_err;
  680. }
  681. /* TOBE_DISC is expected on unicast mismatches; don't print out an
  682. * error message. FRM_TRUNC indicates RXDP dropped the packet due
  683. * to a FIFO overflow.
  684. */
  685. #ifdef DEBUG
  686. if (rx_ev_other_err && net_ratelimit()) {
  687. netif_dbg(efx, rx_err, efx->net_dev,
  688. " RX queue %d unexpected RX event "
  689. EFX_QWORD_FMT "%s%s%s%s%s%s%s%s\n",
  690. efx_rx_queue_index(rx_queue), EFX_QWORD_VAL(*event),
  691. rx_ev_buf_owner_id_err ? " [OWNER_ID_ERR]" : "",
  692. rx_ev_ip_hdr_chksum_err ?
  693. " [IP_HDR_CHKSUM_ERR]" : "",
  694. rx_ev_tcp_udp_chksum_err ?
  695. " [TCP_UDP_CHKSUM_ERR]" : "",
  696. rx_ev_eth_crc_err ? " [ETH_CRC_ERR]" : "",
  697. rx_ev_frm_trunc ? " [FRM_TRUNC]" : "",
  698. rx_ev_drib_nib ? " [DRIB_NIB]" : "",
  699. rx_ev_tobe_disc ? " [TOBE_DISC]" : "",
  700. rx_ev_pause_frm ? " [PAUSE]" : "");
  701. }
  702. #endif
  703. /* The frame must be discarded if any of these are true. */
  704. return (rx_ev_eth_crc_err | rx_ev_frm_trunc | rx_ev_drib_nib |
  705. rx_ev_tobe_disc | rx_ev_pause_frm) ?
  706. EFX_RX_PKT_DISCARD : 0;
  707. }
  708. /* Handle receive events that are not in-order. */
  709. static void
  710. efx_handle_rx_bad_index(struct efx_rx_queue *rx_queue, unsigned index)
  711. {
  712. struct efx_nic *efx = rx_queue->efx;
  713. unsigned expected, dropped;
  714. expected = rx_queue->removed_count & rx_queue->ptr_mask;
  715. dropped = (index - expected) & rx_queue->ptr_mask;
  716. netif_info(efx, rx_err, efx->net_dev,
  717. "dropped %d events (index=%d expected=%d)\n",
  718. dropped, index, expected);
  719. efx_schedule_reset(efx, EFX_WORKAROUND_5676(efx) ?
  720. RESET_TYPE_RX_RECOVERY : RESET_TYPE_DISABLE);
  721. }
  722. /* Handle a packet received event
  723. *
  724. * The NIC gives a "discard" flag if it's a unicast packet with the
  725. * wrong destination address
  726. * Also "is multicast" and "matches multicast filter" flags can be used to
  727. * discard non-matching multicast packets.
  728. */
  729. static void
  730. efx_handle_rx_event(struct efx_channel *channel, const efx_qword_t *event)
  731. {
  732. unsigned int rx_ev_desc_ptr, rx_ev_byte_cnt;
  733. unsigned int rx_ev_hdr_type, rx_ev_mcast_pkt;
  734. unsigned expected_ptr;
  735. bool rx_ev_pkt_ok;
  736. u16 flags;
  737. struct efx_rx_queue *rx_queue;
  738. /* Basic packet information */
  739. rx_ev_byte_cnt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_BYTE_CNT);
  740. rx_ev_pkt_ok = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_PKT_OK);
  741. rx_ev_hdr_type = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_HDR_TYPE);
  742. WARN_ON(EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_JUMBO_CONT));
  743. WARN_ON(EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_SOP) != 1);
  744. WARN_ON(EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_Q_LABEL) !=
  745. channel->channel);
  746. rx_queue = efx_channel_get_rx_queue(channel);
  747. rx_ev_desc_ptr = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_DESC_PTR);
  748. expected_ptr = rx_queue->removed_count & rx_queue->ptr_mask;
  749. if (unlikely(rx_ev_desc_ptr != expected_ptr))
  750. efx_handle_rx_bad_index(rx_queue, rx_ev_desc_ptr);
  751. if (likely(rx_ev_pkt_ok)) {
  752. /* If packet is marked as OK and packet type is TCP/IP or
  753. * UDP/IP, then we can rely on the hardware checksum.
  754. */
  755. flags = (rx_ev_hdr_type == FSE_CZ_RX_EV_HDR_TYPE_IPV4V6_TCP ||
  756. rx_ev_hdr_type == FSE_CZ_RX_EV_HDR_TYPE_IPV4V6_UDP) ?
  757. EFX_RX_PKT_CSUMMED : 0;
  758. } else {
  759. flags = efx_handle_rx_not_ok(rx_queue, event);
  760. }
  761. /* Detect multicast packets that didn't match the filter */
  762. rx_ev_mcast_pkt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_PKT);
  763. if (rx_ev_mcast_pkt) {
  764. unsigned int rx_ev_mcast_hash_match =
  765. EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_HASH_MATCH);
  766. if (unlikely(!rx_ev_mcast_hash_match)) {
  767. ++channel->n_rx_mcast_mismatch;
  768. flags |= EFX_RX_PKT_DISCARD;
  769. }
  770. }
  771. channel->irq_mod_score += 2;
  772. /* Handle received packet */
  773. efx_rx_packet(rx_queue, rx_ev_desc_ptr, rx_ev_byte_cnt, flags);
  774. }
  775. static void
  776. efx_handle_generated_event(struct efx_channel *channel, efx_qword_t *event)
  777. {
  778. struct efx_nic *efx = channel->efx;
  779. struct efx_rx_queue *rx_queue =
  780. efx_channel_has_rx_queue(channel) ?
  781. efx_channel_get_rx_queue(channel) : NULL;
  782. unsigned magic;
  783. magic = EFX_QWORD_FIELD(*event, FSF_AZ_DRV_GEN_EV_MAGIC);
  784. if (magic == EFX_CHANNEL_MAGIC_TEST(channel))
  785. ; /* ignore */
  786. else if (rx_queue && magic == EFX_CHANNEL_MAGIC_FILL(rx_queue))
  787. /* The queue must be empty, so we won't receive any rx
  788. * events, so efx_process_channel() won't refill the
  789. * queue. Refill it here */
  790. efx_fast_push_rx_descriptors(rx_queue);
  791. else
  792. netif_dbg(efx, hw, efx->net_dev, "channel %d received "
  793. "generated event "EFX_QWORD_FMT"\n",
  794. channel->channel, EFX_QWORD_VAL(*event));
  795. }
  796. static void
  797. efx_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
  798. {
  799. struct efx_nic *efx = channel->efx;
  800. unsigned int ev_sub_code;
  801. unsigned int ev_sub_data;
  802. ev_sub_code = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBCODE);
  803. ev_sub_data = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBDATA);
  804. switch (ev_sub_code) {
  805. case FSE_AZ_TX_DESCQ_FLS_DONE_EV:
  806. netif_vdbg(efx, hw, efx->net_dev, "channel %d TXQ %d flushed\n",
  807. channel->channel, ev_sub_data);
  808. break;
  809. case FSE_AZ_RX_DESCQ_FLS_DONE_EV:
  810. netif_vdbg(efx, hw, efx->net_dev, "channel %d RXQ %d flushed\n",
  811. channel->channel, ev_sub_data);
  812. break;
  813. case FSE_AZ_EVQ_INIT_DONE_EV:
  814. netif_dbg(efx, hw, efx->net_dev,
  815. "channel %d EVQ %d initialised\n",
  816. channel->channel, ev_sub_data);
  817. break;
  818. case FSE_AZ_SRM_UPD_DONE_EV:
  819. netif_vdbg(efx, hw, efx->net_dev,
  820. "channel %d SRAM update done\n", channel->channel);
  821. break;
  822. case FSE_AZ_WAKE_UP_EV:
  823. netif_vdbg(efx, hw, efx->net_dev,
  824. "channel %d RXQ %d wakeup event\n",
  825. channel->channel, ev_sub_data);
  826. break;
  827. case FSE_AZ_TIMER_EV:
  828. netif_vdbg(efx, hw, efx->net_dev,
  829. "channel %d RX queue %d timer expired\n",
  830. channel->channel, ev_sub_data);
  831. break;
  832. case FSE_AA_RX_RECOVER_EV:
  833. netif_err(efx, rx_err, efx->net_dev,
  834. "channel %d seen DRIVER RX_RESET event. "
  835. "Resetting.\n", channel->channel);
  836. atomic_inc(&efx->rx_reset);
  837. efx_schedule_reset(efx,
  838. EFX_WORKAROUND_6555(efx) ?
  839. RESET_TYPE_RX_RECOVERY :
  840. RESET_TYPE_DISABLE);
  841. break;
  842. case FSE_BZ_RX_DSC_ERROR_EV:
  843. netif_err(efx, rx_err, efx->net_dev,
  844. "RX DMA Q %d reports descriptor fetch error."
  845. " RX Q %d is disabled.\n", ev_sub_data, ev_sub_data);
  846. efx_schedule_reset(efx, RESET_TYPE_RX_DESC_FETCH);
  847. break;
  848. case FSE_BZ_TX_DSC_ERROR_EV:
  849. netif_err(efx, tx_err, efx->net_dev,
  850. "TX DMA Q %d reports descriptor fetch error."
  851. " TX Q %d is disabled.\n", ev_sub_data, ev_sub_data);
  852. efx_schedule_reset(efx, RESET_TYPE_TX_DESC_FETCH);
  853. break;
  854. default:
  855. netif_vdbg(efx, hw, efx->net_dev,
  856. "channel %d unknown driver event code %d "
  857. "data %04x\n", channel->channel, ev_sub_code,
  858. ev_sub_data);
  859. break;
  860. }
  861. }
  862. int efx_nic_process_eventq(struct efx_channel *channel, int budget)
  863. {
  864. struct efx_nic *efx = channel->efx;
  865. unsigned int read_ptr;
  866. efx_qword_t event, *p_event;
  867. int ev_code;
  868. int tx_packets = 0;
  869. int spent = 0;
  870. read_ptr = channel->eventq_read_ptr;
  871. for (;;) {
  872. p_event = efx_event(channel, read_ptr);
  873. event = *p_event;
  874. if (!efx_event_present(&event))
  875. /* End of events */
  876. break;
  877. netif_vdbg(channel->efx, intr, channel->efx->net_dev,
  878. "channel %d event is "EFX_QWORD_FMT"\n",
  879. channel->channel, EFX_QWORD_VAL(event));
  880. /* Clear this event by marking it all ones */
  881. EFX_SET_QWORD(*p_event);
  882. ++read_ptr;
  883. ev_code = EFX_QWORD_FIELD(event, FSF_AZ_EV_CODE);
  884. switch (ev_code) {
  885. case FSE_AZ_EV_CODE_RX_EV:
  886. efx_handle_rx_event(channel, &event);
  887. if (++spent == budget)
  888. goto out;
  889. break;
  890. case FSE_AZ_EV_CODE_TX_EV:
  891. tx_packets += efx_handle_tx_event(channel, &event);
  892. if (tx_packets > efx->txq_entries) {
  893. spent = budget;
  894. goto out;
  895. }
  896. break;
  897. case FSE_AZ_EV_CODE_DRV_GEN_EV:
  898. efx_handle_generated_event(channel, &event);
  899. break;
  900. case FSE_AZ_EV_CODE_DRIVER_EV:
  901. efx_handle_driver_event(channel, &event);
  902. break;
  903. case FSE_CZ_EV_CODE_MCDI_EV:
  904. efx_mcdi_process_event(channel, &event);
  905. break;
  906. case FSE_AZ_EV_CODE_GLOBAL_EV:
  907. if (efx->type->handle_global_event &&
  908. efx->type->handle_global_event(channel, &event))
  909. break;
  910. /* else fall through */
  911. default:
  912. netif_err(channel->efx, hw, channel->efx->net_dev,
  913. "channel %d unknown event type %d (data "
  914. EFX_QWORD_FMT ")\n", channel->channel,
  915. ev_code, EFX_QWORD_VAL(event));
  916. }
  917. }
  918. out:
  919. channel->eventq_read_ptr = read_ptr;
  920. return spent;
  921. }
  922. /* Check whether an event is present in the eventq at the current
  923. * read pointer. Only useful for self-test.
  924. */
  925. bool efx_nic_event_present(struct efx_channel *channel)
  926. {
  927. return efx_event_present(efx_event(channel, channel->eventq_read_ptr));
  928. }
  929. /* Allocate buffer table entries for event queue */
  930. int efx_nic_probe_eventq(struct efx_channel *channel)
  931. {
  932. struct efx_nic *efx = channel->efx;
  933. unsigned entries;
  934. entries = channel->eventq_mask + 1;
  935. return efx_alloc_special_buffer(efx, &channel->eventq,
  936. entries * sizeof(efx_qword_t));
  937. }
  938. void efx_nic_init_eventq(struct efx_channel *channel)
  939. {
  940. efx_oword_t reg;
  941. struct efx_nic *efx = channel->efx;
  942. netif_dbg(efx, hw, efx->net_dev,
  943. "channel %d event queue in special buffers %d-%d\n",
  944. channel->channel, channel->eventq.index,
  945. channel->eventq.index + channel->eventq.entries - 1);
  946. if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0) {
  947. EFX_POPULATE_OWORD_3(reg,
  948. FRF_CZ_TIMER_Q_EN, 1,
  949. FRF_CZ_HOST_NOTIFY_MODE, 0,
  950. FRF_CZ_TIMER_MODE, FFE_CZ_TIMER_MODE_DIS);
  951. efx_writeo_table(efx, &reg, FR_BZ_TIMER_TBL, channel->channel);
  952. }
  953. /* Pin event queue buffer */
  954. efx_init_special_buffer(efx, &channel->eventq);
  955. /* Fill event queue with all ones (i.e. empty events) */
  956. memset(channel->eventq.addr, 0xff, channel->eventq.len);
  957. /* Push event queue to card */
  958. EFX_POPULATE_OWORD_3(reg,
  959. FRF_AZ_EVQ_EN, 1,
  960. FRF_AZ_EVQ_SIZE, __ffs(channel->eventq.entries),
  961. FRF_AZ_EVQ_BUF_BASE_ID, channel->eventq.index);
  962. efx_writeo_table(efx, &reg, efx->type->evq_ptr_tbl_base,
  963. channel->channel);
  964. efx->type->push_irq_moderation(channel);
  965. }
  966. void efx_nic_fini_eventq(struct efx_channel *channel)
  967. {
  968. efx_oword_t reg;
  969. struct efx_nic *efx = channel->efx;
  970. /* Remove event queue from card */
  971. EFX_ZERO_OWORD(reg);
  972. efx_writeo_table(efx, &reg, efx->type->evq_ptr_tbl_base,
  973. channel->channel);
  974. if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0)
  975. efx_writeo_table(efx, &reg, FR_BZ_TIMER_TBL, channel->channel);
  976. /* Unpin event queue */
  977. efx_fini_special_buffer(efx, &channel->eventq);
  978. }
  979. /* Free buffers backing event queue */
  980. void efx_nic_remove_eventq(struct efx_channel *channel)
  981. {
  982. efx_free_special_buffer(channel->efx, &channel->eventq);
  983. }
  984. void efx_nic_generate_test_event(struct efx_channel *channel)
  985. {
  986. efx_magic_event(channel, EFX_CHANNEL_MAGIC_TEST(channel));
  987. }
  988. void efx_nic_generate_fill_event(struct efx_rx_queue *rx_queue)
  989. {
  990. efx_magic_event(efx_rx_queue_channel(rx_queue),
  991. EFX_CHANNEL_MAGIC_FILL(rx_queue));
  992. }
  993. /**************************************************************************
  994. *
  995. * Flush handling
  996. *
  997. **************************************************************************/
  998. static void efx_poll_flush_events(struct efx_nic *efx)
  999. {
  1000. struct efx_channel *channel = efx_get_channel(efx, 0);
  1001. struct efx_tx_queue *tx_queue;
  1002. struct efx_rx_queue *rx_queue;
  1003. unsigned int read_ptr = channel->eventq_read_ptr;
  1004. unsigned int end_ptr = read_ptr + channel->eventq_mask - 1;
  1005. do {
  1006. efx_qword_t *event = efx_event(channel, read_ptr);
  1007. int ev_code, ev_sub_code, ev_queue;
  1008. bool ev_failed;
  1009. if (!efx_event_present(event))
  1010. break;
  1011. ev_code = EFX_QWORD_FIELD(*event, FSF_AZ_EV_CODE);
  1012. ev_sub_code = EFX_QWORD_FIELD(*event,
  1013. FSF_AZ_DRIVER_EV_SUBCODE);
  1014. if (ev_code == FSE_AZ_EV_CODE_DRIVER_EV &&
  1015. ev_sub_code == FSE_AZ_TX_DESCQ_FLS_DONE_EV) {
  1016. ev_queue = EFX_QWORD_FIELD(*event,
  1017. FSF_AZ_DRIVER_EV_SUBDATA);
  1018. if (ev_queue < EFX_TXQ_TYPES * efx->n_tx_channels) {
  1019. tx_queue = efx_get_tx_queue(
  1020. efx, ev_queue / EFX_TXQ_TYPES,
  1021. ev_queue % EFX_TXQ_TYPES);
  1022. tx_queue->flushed = FLUSH_DONE;
  1023. }
  1024. } else if (ev_code == FSE_AZ_EV_CODE_DRIVER_EV &&
  1025. ev_sub_code == FSE_AZ_RX_DESCQ_FLS_DONE_EV) {
  1026. ev_queue = EFX_QWORD_FIELD(
  1027. *event, FSF_AZ_DRIVER_EV_RX_DESCQ_ID);
  1028. ev_failed = EFX_QWORD_FIELD(
  1029. *event, FSF_AZ_DRIVER_EV_RX_FLUSH_FAIL);
  1030. if (ev_queue < efx->n_rx_channels) {
  1031. rx_queue = efx_get_rx_queue(efx, ev_queue);
  1032. rx_queue->flushed =
  1033. ev_failed ? FLUSH_FAILED : FLUSH_DONE;
  1034. }
  1035. }
  1036. /* We're about to destroy the queue anyway, so
  1037. * it's ok to throw away every non-flush event */
  1038. EFX_SET_QWORD(*event);
  1039. ++read_ptr;
  1040. } while (read_ptr != end_ptr);
  1041. channel->eventq_read_ptr = read_ptr;
  1042. }
  1043. /* Handle tx and rx flushes at the same time, since they run in
  1044. * parallel in the hardware and there's no reason for us to
  1045. * serialise them */
  1046. int efx_nic_flush_queues(struct efx_nic *efx)
  1047. {
  1048. struct efx_channel *channel;
  1049. struct efx_rx_queue *rx_queue;
  1050. struct efx_tx_queue *tx_queue;
  1051. int i, tx_pending, rx_pending;
  1052. /* If necessary prepare the hardware for flushing */
  1053. efx->type->prepare_flush(efx);
  1054. /* Flush all tx queues in parallel */
  1055. efx_for_each_channel(channel, efx) {
  1056. efx_for_each_possible_channel_tx_queue(tx_queue, channel) {
  1057. if (tx_queue->initialised)
  1058. efx_flush_tx_queue(tx_queue);
  1059. }
  1060. }
  1061. /* The hardware supports four concurrent rx flushes, each of which may
  1062. * need to be retried if there is an outstanding descriptor fetch */
  1063. for (i = 0; i < EFX_FLUSH_POLL_COUNT; ++i) {
  1064. rx_pending = tx_pending = 0;
  1065. efx_for_each_channel(channel, efx) {
  1066. efx_for_each_channel_rx_queue(rx_queue, channel) {
  1067. if (rx_queue->flushed == FLUSH_PENDING)
  1068. ++rx_pending;
  1069. }
  1070. }
  1071. efx_for_each_channel(channel, efx) {
  1072. efx_for_each_channel_rx_queue(rx_queue, channel) {
  1073. if (rx_pending == EFX_RX_FLUSH_COUNT)
  1074. break;
  1075. if (rx_queue->flushed == FLUSH_FAILED ||
  1076. rx_queue->flushed == FLUSH_NONE) {
  1077. efx_flush_rx_queue(rx_queue);
  1078. ++rx_pending;
  1079. }
  1080. }
  1081. efx_for_each_possible_channel_tx_queue(tx_queue, channel) {
  1082. if (tx_queue->initialised &&
  1083. tx_queue->flushed != FLUSH_DONE)
  1084. ++tx_pending;
  1085. }
  1086. }
  1087. if (rx_pending == 0 && tx_pending == 0)
  1088. return 0;
  1089. msleep(EFX_FLUSH_INTERVAL);
  1090. efx_poll_flush_events(efx);
  1091. }
  1092. /* Mark the queues as all flushed. We're going to return failure
  1093. * leading to a reset, or fake up success anyway */
  1094. efx_for_each_channel(channel, efx) {
  1095. efx_for_each_possible_channel_tx_queue(tx_queue, channel) {
  1096. if (tx_queue->initialised &&
  1097. tx_queue->flushed != FLUSH_DONE)
  1098. netif_err(efx, hw, efx->net_dev,
  1099. "tx queue %d flush command timed out\n",
  1100. tx_queue->queue);
  1101. tx_queue->flushed = FLUSH_DONE;
  1102. }
  1103. efx_for_each_channel_rx_queue(rx_queue, channel) {
  1104. if (rx_queue->flushed != FLUSH_DONE)
  1105. netif_err(efx, hw, efx->net_dev,
  1106. "rx queue %d flush command timed out\n",
  1107. efx_rx_queue_index(rx_queue));
  1108. rx_queue->flushed = FLUSH_DONE;
  1109. }
  1110. }
  1111. return -ETIMEDOUT;
  1112. }
  1113. /**************************************************************************
  1114. *
  1115. * Hardware interrupts
  1116. * The hardware interrupt handler does very little work; all the event
  1117. * queue processing is carried out by per-channel tasklets.
  1118. *
  1119. **************************************************************************/
  1120. /* Enable/disable/generate interrupts */
  1121. static inline void efx_nic_interrupts(struct efx_nic *efx,
  1122. bool enabled, bool force)
  1123. {
  1124. efx_oword_t int_en_reg_ker;
  1125. EFX_POPULATE_OWORD_3(int_en_reg_ker,
  1126. FRF_AZ_KER_INT_LEVE_SEL, efx->irq_level,
  1127. FRF_AZ_KER_INT_KER, force,
  1128. FRF_AZ_DRV_INT_EN_KER, enabled);
  1129. efx_writeo(efx, &int_en_reg_ker, FR_AZ_INT_EN_KER);
  1130. }
  1131. void efx_nic_enable_interrupts(struct efx_nic *efx)
  1132. {
  1133. struct efx_channel *channel;
  1134. EFX_ZERO_OWORD(*((efx_oword_t *) efx->irq_status.addr));
  1135. wmb(); /* Ensure interrupt vector is clear before interrupts enabled */
  1136. /* Enable interrupts */
  1137. efx_nic_interrupts(efx, true, false);
  1138. /* Force processing of all the channels to get the EVQ RPTRs up to
  1139. date */
  1140. efx_for_each_channel(channel, efx)
  1141. efx_schedule_channel(channel);
  1142. }
  1143. void efx_nic_disable_interrupts(struct efx_nic *efx)
  1144. {
  1145. /* Disable interrupts */
  1146. efx_nic_interrupts(efx, false, false);
  1147. }
  1148. /* Generate a test interrupt
  1149. * Interrupt must already have been enabled, otherwise nasty things
  1150. * may happen.
  1151. */
  1152. void efx_nic_generate_interrupt(struct efx_nic *efx)
  1153. {
  1154. efx_nic_interrupts(efx, true, true);
  1155. }
  1156. /* Process a fatal interrupt
  1157. * Disable bus mastering ASAP and schedule a reset
  1158. */
  1159. irqreturn_t efx_nic_fatal_interrupt(struct efx_nic *efx)
  1160. {
  1161. struct falcon_nic_data *nic_data = efx->nic_data;
  1162. efx_oword_t *int_ker = efx->irq_status.addr;
  1163. efx_oword_t fatal_intr;
  1164. int error, mem_perr;
  1165. efx_reado(efx, &fatal_intr, FR_AZ_FATAL_INTR_KER);
  1166. error = EFX_OWORD_FIELD(fatal_intr, FRF_AZ_FATAL_INTR);
  1167. netif_err(efx, hw, efx->net_dev, "SYSTEM ERROR "EFX_OWORD_FMT" status "
  1168. EFX_OWORD_FMT ": %s\n", EFX_OWORD_VAL(*int_ker),
  1169. EFX_OWORD_VAL(fatal_intr),
  1170. error ? "disabling bus mastering" : "no recognised error");
  1171. /* If this is a memory parity error dump which blocks are offending */
  1172. mem_perr = (EFX_OWORD_FIELD(fatal_intr, FRF_AZ_MEM_PERR_INT_KER) ||
  1173. EFX_OWORD_FIELD(fatal_intr, FRF_AZ_SRM_PERR_INT_KER));
  1174. if (mem_perr) {
  1175. efx_oword_t reg;
  1176. efx_reado(efx, &reg, FR_AZ_MEM_STAT);
  1177. netif_err(efx, hw, efx->net_dev,
  1178. "SYSTEM ERROR: memory parity error "EFX_OWORD_FMT"\n",
  1179. EFX_OWORD_VAL(reg));
  1180. }
  1181. /* Disable both devices */
  1182. pci_clear_master(efx->pci_dev);
  1183. if (efx_nic_is_dual_func(efx))
  1184. pci_clear_master(nic_data->pci_dev2);
  1185. efx_nic_disable_interrupts(efx);
  1186. /* Count errors and reset or disable the NIC accordingly */
  1187. if (efx->int_error_count == 0 ||
  1188. time_after(jiffies, efx->int_error_expire)) {
  1189. efx->int_error_count = 0;
  1190. efx->int_error_expire =
  1191. jiffies + EFX_INT_ERROR_EXPIRE * HZ;
  1192. }
  1193. if (++efx->int_error_count < EFX_MAX_INT_ERRORS) {
  1194. netif_err(efx, hw, efx->net_dev,
  1195. "SYSTEM ERROR - reset scheduled\n");
  1196. efx_schedule_reset(efx, RESET_TYPE_INT_ERROR);
  1197. } else {
  1198. netif_err(efx, hw, efx->net_dev,
  1199. "SYSTEM ERROR - max number of errors seen."
  1200. "NIC will be disabled\n");
  1201. efx_schedule_reset(efx, RESET_TYPE_DISABLE);
  1202. }
  1203. return IRQ_HANDLED;
  1204. }
  1205. /* Handle a legacy interrupt
  1206. * Acknowledges the interrupt and schedule event queue processing.
  1207. */
  1208. static irqreturn_t efx_legacy_interrupt(int irq, void *dev_id)
  1209. {
  1210. struct efx_nic *efx = dev_id;
  1211. efx_oword_t *int_ker = efx->irq_status.addr;
  1212. irqreturn_t result = IRQ_NONE;
  1213. struct efx_channel *channel;
  1214. efx_dword_t reg;
  1215. u32 queues;
  1216. int syserr;
  1217. /* Could this be ours? If interrupts are disabled then the
  1218. * channel state may not be valid.
  1219. */
  1220. if (!efx->legacy_irq_enabled)
  1221. return result;
  1222. /* Read the ISR which also ACKs the interrupts */
  1223. efx_readd(efx, &reg, FR_BZ_INT_ISR0);
  1224. queues = EFX_EXTRACT_DWORD(reg, 0, 31);
  1225. /* Handle non-event-queue sources */
  1226. if (queues & (1U << efx->irq_level)) {
  1227. syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT);
  1228. if (unlikely(syserr))
  1229. return efx_nic_fatal_interrupt(efx);
  1230. efx->last_irq_cpu = raw_smp_processor_id();
  1231. }
  1232. if (queues != 0) {
  1233. if (EFX_WORKAROUND_15783(efx))
  1234. efx->irq_zero_count = 0;
  1235. /* Schedule processing of any interrupting queues */
  1236. efx_for_each_channel(channel, efx) {
  1237. if (queues & 1)
  1238. efx_schedule_channel_irq(channel);
  1239. queues >>= 1;
  1240. }
  1241. result = IRQ_HANDLED;
  1242. } else if (EFX_WORKAROUND_15783(efx)) {
  1243. efx_qword_t *event;
  1244. /* We can't return IRQ_HANDLED more than once on seeing ISR=0
  1245. * because this might be a shared interrupt. */
  1246. if (efx->irq_zero_count++ == 0)
  1247. result = IRQ_HANDLED;
  1248. /* Ensure we schedule or rearm all event queues */
  1249. efx_for_each_channel(channel, efx) {
  1250. event = efx_event(channel, channel->eventq_read_ptr);
  1251. if (efx_event_present(event))
  1252. efx_schedule_channel_irq(channel);
  1253. else
  1254. efx_nic_eventq_read_ack(channel);
  1255. }
  1256. }
  1257. if (result == IRQ_HANDLED)
  1258. netif_vdbg(efx, intr, efx->net_dev,
  1259. "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
  1260. irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
  1261. return result;
  1262. }
  1263. /* Handle an MSI interrupt
  1264. *
  1265. * Handle an MSI hardware interrupt. This routine schedules event
  1266. * queue processing. No interrupt acknowledgement cycle is necessary.
  1267. * Also, we never need to check that the interrupt is for us, since
  1268. * MSI interrupts cannot be shared.
  1269. */
  1270. static irqreturn_t efx_msi_interrupt(int irq, void *dev_id)
  1271. {
  1272. struct efx_channel *channel = *(struct efx_channel **)dev_id;
  1273. struct efx_nic *efx = channel->efx;
  1274. efx_oword_t *int_ker = efx->irq_status.addr;
  1275. int syserr;
  1276. netif_vdbg(efx, intr, efx->net_dev,
  1277. "IRQ %d on CPU %d status " EFX_OWORD_FMT "\n",
  1278. irq, raw_smp_processor_id(), EFX_OWORD_VAL(*int_ker));
  1279. /* Handle non-event-queue sources */
  1280. if (channel->channel == efx->irq_level) {
  1281. syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT);
  1282. if (unlikely(syserr))
  1283. return efx_nic_fatal_interrupt(efx);
  1284. efx->last_irq_cpu = raw_smp_processor_id();
  1285. }
  1286. /* Schedule processing of the channel */
  1287. efx_schedule_channel_irq(channel);
  1288. return IRQ_HANDLED;
  1289. }
  1290. /* Setup RSS indirection table.
  1291. * This maps from the hash value of the packet to RXQ
  1292. */
  1293. void efx_nic_push_rx_indir_table(struct efx_nic *efx)
  1294. {
  1295. size_t i = 0;
  1296. efx_dword_t dword;
  1297. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0)
  1298. return;
  1299. BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
  1300. FR_BZ_RX_INDIRECTION_TBL_ROWS);
  1301. for (i = 0; i < FR_BZ_RX_INDIRECTION_TBL_ROWS; i++) {
  1302. EFX_POPULATE_DWORD_1(dword, FRF_BZ_IT_QUEUE,
  1303. efx->rx_indir_table[i]);
  1304. efx_writed_table(efx, &dword, FR_BZ_RX_INDIRECTION_TBL, i);
  1305. }
  1306. }
  1307. /* Hook interrupt handler(s)
  1308. * Try MSI and then legacy interrupts.
  1309. */
  1310. int efx_nic_init_interrupt(struct efx_nic *efx)
  1311. {
  1312. struct efx_channel *channel;
  1313. int rc;
  1314. if (!EFX_INT_MODE_USE_MSI(efx)) {
  1315. irq_handler_t handler;
  1316. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
  1317. handler = efx_legacy_interrupt;
  1318. else
  1319. handler = falcon_legacy_interrupt_a1;
  1320. rc = request_irq(efx->legacy_irq, handler, IRQF_SHARED,
  1321. efx->name, efx);
  1322. if (rc) {
  1323. netif_err(efx, drv, efx->net_dev,
  1324. "failed to hook legacy IRQ %d\n",
  1325. efx->pci_dev->irq);
  1326. goto fail1;
  1327. }
  1328. return 0;
  1329. }
  1330. /* Hook MSI or MSI-X interrupt */
  1331. efx_for_each_channel(channel, efx) {
  1332. rc = request_irq(channel->irq, efx_msi_interrupt,
  1333. IRQF_PROBE_SHARED, /* Not shared */
  1334. efx->channel_name[channel->channel],
  1335. &efx->channel[channel->channel]);
  1336. if (rc) {
  1337. netif_err(efx, drv, efx->net_dev,
  1338. "failed to hook IRQ %d\n", channel->irq);
  1339. goto fail2;
  1340. }
  1341. }
  1342. return 0;
  1343. fail2:
  1344. efx_for_each_channel(channel, efx)
  1345. free_irq(channel->irq, &efx->channel[channel->channel]);
  1346. fail1:
  1347. return rc;
  1348. }
  1349. void efx_nic_fini_interrupt(struct efx_nic *efx)
  1350. {
  1351. struct efx_channel *channel;
  1352. efx_oword_t reg;
  1353. /* Disable MSI/MSI-X interrupts */
  1354. efx_for_each_channel(channel, efx) {
  1355. if (channel->irq)
  1356. free_irq(channel->irq, &efx->channel[channel->channel]);
  1357. }
  1358. /* ACK legacy interrupt */
  1359. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
  1360. efx_reado(efx, &reg, FR_BZ_INT_ISR0);
  1361. else
  1362. falcon_irq_ack_a1(efx);
  1363. /* Disable legacy interrupt */
  1364. if (efx->legacy_irq)
  1365. free_irq(efx->legacy_irq, efx);
  1366. }
  1367. u32 efx_nic_fpga_ver(struct efx_nic *efx)
  1368. {
  1369. efx_oword_t altera_build;
  1370. efx_reado(efx, &altera_build, FR_AZ_ALTERA_BUILD);
  1371. return EFX_OWORD_FIELD(altera_build, FRF_AZ_ALTERA_BUILD_VER);
  1372. }
  1373. void efx_nic_init_common(struct efx_nic *efx)
  1374. {
  1375. efx_oword_t temp;
  1376. /* Set positions of descriptor caches in SRAM. */
  1377. EFX_POPULATE_OWORD_1(temp, FRF_AZ_SRM_TX_DC_BASE_ADR,
  1378. efx->type->tx_dc_base / 8);
  1379. efx_writeo(efx, &temp, FR_AZ_SRM_TX_DC_CFG);
  1380. EFX_POPULATE_OWORD_1(temp, FRF_AZ_SRM_RX_DC_BASE_ADR,
  1381. efx->type->rx_dc_base / 8);
  1382. efx_writeo(efx, &temp, FR_AZ_SRM_RX_DC_CFG);
  1383. /* Set TX descriptor cache size. */
  1384. BUILD_BUG_ON(TX_DC_ENTRIES != (8 << TX_DC_ENTRIES_ORDER));
  1385. EFX_POPULATE_OWORD_1(temp, FRF_AZ_TX_DC_SIZE, TX_DC_ENTRIES_ORDER);
  1386. efx_writeo(efx, &temp, FR_AZ_TX_DC_CFG);
  1387. /* Set RX descriptor cache size. Set low watermark to size-8, as
  1388. * this allows most efficient prefetching.
  1389. */
  1390. BUILD_BUG_ON(RX_DC_ENTRIES != (8 << RX_DC_ENTRIES_ORDER));
  1391. EFX_POPULATE_OWORD_1(temp, FRF_AZ_RX_DC_SIZE, RX_DC_ENTRIES_ORDER);
  1392. efx_writeo(efx, &temp, FR_AZ_RX_DC_CFG);
  1393. EFX_POPULATE_OWORD_1(temp, FRF_AZ_RX_DC_PF_LWM, RX_DC_ENTRIES - 8);
  1394. efx_writeo(efx, &temp, FR_AZ_RX_DC_PF_WM);
  1395. /* Program INT_KER address */
  1396. EFX_POPULATE_OWORD_2(temp,
  1397. FRF_AZ_NORM_INT_VEC_DIS_KER,
  1398. EFX_INT_MODE_USE_MSI(efx),
  1399. FRF_AZ_INT_ADR_KER, efx->irq_status.dma_addr);
  1400. efx_writeo(efx, &temp, FR_AZ_INT_ADR_KER);
  1401. if (EFX_WORKAROUND_17213(efx) && !EFX_INT_MODE_USE_MSI(efx))
  1402. /* Use an interrupt level unused by event queues */
  1403. efx->irq_level = 0x1f;
  1404. else
  1405. /* Use a valid MSI-X vector */
  1406. efx->irq_level = 0;
  1407. /* Enable all the genuinely fatal interrupts. (They are still
  1408. * masked by the overall interrupt mask, controlled by
  1409. * falcon_interrupts()).
  1410. *
  1411. * Note: All other fatal interrupts are enabled
  1412. */
  1413. EFX_POPULATE_OWORD_3(temp,
  1414. FRF_AZ_ILL_ADR_INT_KER_EN, 1,
  1415. FRF_AZ_RBUF_OWN_INT_KER_EN, 1,
  1416. FRF_AZ_TBUF_OWN_INT_KER_EN, 1);
  1417. if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0)
  1418. EFX_SET_OWORD_FIELD(temp, FRF_CZ_SRAM_PERR_INT_P_KER_EN, 1);
  1419. EFX_INVERT_OWORD(temp);
  1420. efx_writeo(efx, &temp, FR_AZ_FATAL_INTR_KER);
  1421. efx_nic_push_rx_indir_table(efx);
  1422. /* Disable the ugly timer-based TX DMA backoff and allow TX DMA to be
  1423. * controlled by the RX FIFO fill level. Set arbitration to one pkt/Q.
  1424. */
  1425. efx_reado(efx, &temp, FR_AZ_TX_RESERVED);
  1426. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_RX_SPACER, 0xfe);
  1427. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_RX_SPACER_EN, 1);
  1428. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_ONE_PKT_PER_Q, 1);
  1429. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PUSH_EN, 1);
  1430. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_DIS_NON_IP_EV, 1);
  1431. /* Enable SW_EV to inherit in char driver - assume harmless here */
  1432. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_SOFT_EVT_EN, 1);
  1433. /* Prefetch threshold 2 => fetch when descriptor cache half empty */
  1434. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PREF_THRESHOLD, 2);
  1435. /* Disable hardware watchdog which can misfire */
  1436. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PREF_WD_TMR, 0x3fffff);
  1437. /* Squash TX of packets of 16 bytes or less */
  1438. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
  1439. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TX_FLUSH_MIN_LEN_EN, 1);
  1440. efx_writeo(efx, &temp, FR_AZ_TX_RESERVED);
  1441. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) {
  1442. EFX_POPULATE_OWORD_4(temp,
  1443. /* Default values */
  1444. FRF_BZ_TX_PACE_SB_NOT_AF, 0x15,
  1445. FRF_BZ_TX_PACE_SB_AF, 0xb,
  1446. FRF_BZ_TX_PACE_FB_BASE, 0,
  1447. /* Allow large pace values in the
  1448. * fast bin. */
  1449. FRF_BZ_TX_PACE_BIN_TH,
  1450. FFE_BZ_TX_PACE_RESERVED);
  1451. efx_writeo(efx, &temp, FR_BZ_TX_PACE);
  1452. }
  1453. }
  1454. /* Register dump */
  1455. #define REGISTER_REVISION_A 1
  1456. #define REGISTER_REVISION_B 2
  1457. #define REGISTER_REVISION_C 3
  1458. #define REGISTER_REVISION_Z 3 /* latest revision */
  1459. struct efx_nic_reg {
  1460. u32 offset:24;
  1461. u32 min_revision:2, max_revision:2;
  1462. };
  1463. #define REGISTER(name, min_rev, max_rev) { \
  1464. FR_ ## min_rev ## max_rev ## _ ## name, \
  1465. REGISTER_REVISION_ ## min_rev, REGISTER_REVISION_ ## max_rev \
  1466. }
  1467. #define REGISTER_AA(name) REGISTER(name, A, A)
  1468. #define REGISTER_AB(name) REGISTER(name, A, B)
  1469. #define REGISTER_AZ(name) REGISTER(name, A, Z)
  1470. #define REGISTER_BB(name) REGISTER(name, B, B)
  1471. #define REGISTER_BZ(name) REGISTER(name, B, Z)
  1472. #define REGISTER_CZ(name) REGISTER(name, C, Z)
  1473. static const struct efx_nic_reg efx_nic_regs[] = {
  1474. REGISTER_AZ(ADR_REGION),
  1475. REGISTER_AZ(INT_EN_KER),
  1476. REGISTER_BZ(INT_EN_CHAR),
  1477. REGISTER_AZ(INT_ADR_KER),
  1478. REGISTER_BZ(INT_ADR_CHAR),
  1479. /* INT_ACK_KER is WO */
  1480. /* INT_ISR0 is RC */
  1481. REGISTER_AZ(HW_INIT),
  1482. REGISTER_CZ(USR_EV_CFG),
  1483. REGISTER_AB(EE_SPI_HCMD),
  1484. REGISTER_AB(EE_SPI_HADR),
  1485. REGISTER_AB(EE_SPI_HDATA),
  1486. REGISTER_AB(EE_BASE_PAGE),
  1487. REGISTER_AB(EE_VPD_CFG0),
  1488. /* EE_VPD_SW_CNTL and EE_VPD_SW_DATA are not used */
  1489. /* PMBX_DBG_IADDR and PBMX_DBG_IDATA are indirect */
  1490. /* PCIE_CORE_INDIRECT is indirect */
  1491. REGISTER_AB(NIC_STAT),
  1492. REGISTER_AB(GPIO_CTL),
  1493. REGISTER_AB(GLB_CTL),
  1494. /* FATAL_INTR_KER and FATAL_INTR_CHAR are partly RC */
  1495. REGISTER_BZ(DP_CTRL),
  1496. REGISTER_AZ(MEM_STAT),
  1497. REGISTER_AZ(CS_DEBUG),
  1498. REGISTER_AZ(ALTERA_BUILD),
  1499. REGISTER_AZ(CSR_SPARE),
  1500. REGISTER_AB(PCIE_SD_CTL0123),
  1501. REGISTER_AB(PCIE_SD_CTL45),
  1502. REGISTER_AB(PCIE_PCS_CTL_STAT),
  1503. /* DEBUG_DATA_OUT is not used */
  1504. /* DRV_EV is WO */
  1505. REGISTER_AZ(EVQ_CTL),
  1506. REGISTER_AZ(EVQ_CNT1),
  1507. REGISTER_AZ(EVQ_CNT2),
  1508. REGISTER_AZ(BUF_TBL_CFG),
  1509. REGISTER_AZ(SRM_RX_DC_CFG),
  1510. REGISTER_AZ(SRM_TX_DC_CFG),
  1511. REGISTER_AZ(SRM_CFG),
  1512. /* BUF_TBL_UPD is WO */
  1513. REGISTER_AZ(SRM_UPD_EVQ),
  1514. REGISTER_AZ(SRAM_PARITY),
  1515. REGISTER_AZ(RX_CFG),
  1516. REGISTER_BZ(RX_FILTER_CTL),
  1517. /* RX_FLUSH_DESCQ is WO */
  1518. REGISTER_AZ(RX_DC_CFG),
  1519. REGISTER_AZ(RX_DC_PF_WM),
  1520. REGISTER_BZ(RX_RSS_TKEY),
  1521. /* RX_NODESC_DROP is RC */
  1522. REGISTER_AA(RX_SELF_RST),
  1523. /* RX_DEBUG, RX_PUSH_DROP are not used */
  1524. REGISTER_CZ(RX_RSS_IPV6_REG1),
  1525. REGISTER_CZ(RX_RSS_IPV6_REG2),
  1526. REGISTER_CZ(RX_RSS_IPV6_REG3),
  1527. /* TX_FLUSH_DESCQ is WO */
  1528. REGISTER_AZ(TX_DC_CFG),
  1529. REGISTER_AA(TX_CHKSM_CFG),
  1530. REGISTER_AZ(TX_CFG),
  1531. /* TX_PUSH_DROP is not used */
  1532. REGISTER_AZ(TX_RESERVED),
  1533. REGISTER_BZ(TX_PACE),
  1534. /* TX_PACE_DROP_QID is RC */
  1535. REGISTER_BB(TX_VLAN),
  1536. REGISTER_BZ(TX_IPFIL_PORTEN),
  1537. REGISTER_AB(MD_TXD),
  1538. REGISTER_AB(MD_RXD),
  1539. REGISTER_AB(MD_CS),
  1540. REGISTER_AB(MD_PHY_ADR),
  1541. REGISTER_AB(MD_ID),
  1542. /* MD_STAT is RC */
  1543. REGISTER_AB(MAC_STAT_DMA),
  1544. REGISTER_AB(MAC_CTRL),
  1545. REGISTER_BB(GEN_MODE),
  1546. REGISTER_AB(MAC_MC_HASH_REG0),
  1547. REGISTER_AB(MAC_MC_HASH_REG1),
  1548. REGISTER_AB(GM_CFG1),
  1549. REGISTER_AB(GM_CFG2),
  1550. /* GM_IPG and GM_HD are not used */
  1551. REGISTER_AB(GM_MAX_FLEN),
  1552. /* GM_TEST is not used */
  1553. REGISTER_AB(GM_ADR1),
  1554. REGISTER_AB(GM_ADR2),
  1555. REGISTER_AB(GMF_CFG0),
  1556. REGISTER_AB(GMF_CFG1),
  1557. REGISTER_AB(GMF_CFG2),
  1558. REGISTER_AB(GMF_CFG3),
  1559. REGISTER_AB(GMF_CFG4),
  1560. REGISTER_AB(GMF_CFG5),
  1561. REGISTER_BB(TX_SRC_MAC_CTL),
  1562. REGISTER_AB(XM_ADR_LO),
  1563. REGISTER_AB(XM_ADR_HI),
  1564. REGISTER_AB(XM_GLB_CFG),
  1565. REGISTER_AB(XM_TX_CFG),
  1566. REGISTER_AB(XM_RX_CFG),
  1567. REGISTER_AB(XM_MGT_INT_MASK),
  1568. REGISTER_AB(XM_FC),
  1569. REGISTER_AB(XM_PAUSE_TIME),
  1570. REGISTER_AB(XM_TX_PARAM),
  1571. REGISTER_AB(XM_RX_PARAM),
  1572. /* XM_MGT_INT_MSK (note no 'A') is RC */
  1573. REGISTER_AB(XX_PWR_RST),
  1574. REGISTER_AB(XX_SD_CTL),
  1575. REGISTER_AB(XX_TXDRV_CTL),
  1576. /* XX_PRBS_CTL, XX_PRBS_CHK and XX_PRBS_ERR are not used */
  1577. /* XX_CORE_STAT is partly RC */
  1578. };
  1579. struct efx_nic_reg_table {
  1580. u32 offset:24;
  1581. u32 min_revision:2, max_revision:2;
  1582. u32 step:6, rows:21;
  1583. };
  1584. #define REGISTER_TABLE_DIMENSIONS(_, offset, min_rev, max_rev, step, rows) { \
  1585. offset, \
  1586. REGISTER_REVISION_ ## min_rev, REGISTER_REVISION_ ## max_rev, \
  1587. step, rows \
  1588. }
  1589. #define REGISTER_TABLE(name, min_rev, max_rev) \
  1590. REGISTER_TABLE_DIMENSIONS( \
  1591. name, FR_ ## min_rev ## max_rev ## _ ## name, \
  1592. min_rev, max_rev, \
  1593. FR_ ## min_rev ## max_rev ## _ ## name ## _STEP, \
  1594. FR_ ## min_rev ## max_rev ## _ ## name ## _ROWS)
  1595. #define REGISTER_TABLE_AA(name) REGISTER_TABLE(name, A, A)
  1596. #define REGISTER_TABLE_AZ(name) REGISTER_TABLE(name, A, Z)
  1597. #define REGISTER_TABLE_BB(name) REGISTER_TABLE(name, B, B)
  1598. #define REGISTER_TABLE_BZ(name) REGISTER_TABLE(name, B, Z)
  1599. #define REGISTER_TABLE_BB_CZ(name) \
  1600. REGISTER_TABLE_DIMENSIONS(name, FR_BZ_ ## name, B, B, \
  1601. FR_BZ_ ## name ## _STEP, \
  1602. FR_BB_ ## name ## _ROWS), \
  1603. REGISTER_TABLE_DIMENSIONS(name, FR_BZ_ ## name, C, Z, \
  1604. FR_BZ_ ## name ## _STEP, \
  1605. FR_CZ_ ## name ## _ROWS)
  1606. #define REGISTER_TABLE_CZ(name) REGISTER_TABLE(name, C, Z)
  1607. static const struct efx_nic_reg_table efx_nic_reg_tables[] = {
  1608. /* DRIVER is not used */
  1609. /* EVQ_RPTR, TIMER_COMMAND, USR_EV and {RX,TX}_DESC_UPD are WO */
  1610. REGISTER_TABLE_BB(TX_IPFIL_TBL),
  1611. REGISTER_TABLE_BB(TX_SRC_MAC_TBL),
  1612. REGISTER_TABLE_AA(RX_DESC_PTR_TBL_KER),
  1613. REGISTER_TABLE_BB_CZ(RX_DESC_PTR_TBL),
  1614. REGISTER_TABLE_AA(TX_DESC_PTR_TBL_KER),
  1615. REGISTER_TABLE_BB_CZ(TX_DESC_PTR_TBL),
  1616. REGISTER_TABLE_AA(EVQ_PTR_TBL_KER),
  1617. REGISTER_TABLE_BB_CZ(EVQ_PTR_TBL),
  1618. /* We can't reasonably read all of the buffer table (up to 8MB!).
  1619. * However this driver will only use a few entries. Reading
  1620. * 1K entries allows for some expansion of queue count and
  1621. * size before we need to change the version. */
  1622. REGISTER_TABLE_DIMENSIONS(BUF_FULL_TBL_KER, FR_AA_BUF_FULL_TBL_KER,
  1623. A, A, 8, 1024),
  1624. REGISTER_TABLE_DIMENSIONS(BUF_FULL_TBL, FR_BZ_BUF_FULL_TBL,
  1625. B, Z, 8, 1024),
  1626. REGISTER_TABLE_CZ(RX_MAC_FILTER_TBL0),
  1627. REGISTER_TABLE_BB_CZ(TIMER_TBL),
  1628. REGISTER_TABLE_BB_CZ(TX_PACE_TBL),
  1629. REGISTER_TABLE_BZ(RX_INDIRECTION_TBL),
  1630. /* TX_FILTER_TBL0 is huge and not used by this driver */
  1631. REGISTER_TABLE_CZ(TX_MAC_FILTER_TBL0),
  1632. REGISTER_TABLE_CZ(MC_TREG_SMEM),
  1633. /* MSIX_PBA_TABLE is not mapped */
  1634. /* SRM_DBG is not mapped (and is redundant with BUF_FLL_TBL) */
  1635. REGISTER_TABLE_BZ(RX_FILTER_TBL0),
  1636. };
  1637. size_t efx_nic_get_regs_len(struct efx_nic *efx)
  1638. {
  1639. const struct efx_nic_reg *reg;
  1640. const struct efx_nic_reg_table *table;
  1641. size_t len = 0;
  1642. for (reg = efx_nic_regs;
  1643. reg < efx_nic_regs + ARRAY_SIZE(efx_nic_regs);
  1644. reg++)
  1645. if (efx->type->revision >= reg->min_revision &&
  1646. efx->type->revision <= reg->max_revision)
  1647. len += sizeof(efx_oword_t);
  1648. for (table = efx_nic_reg_tables;
  1649. table < efx_nic_reg_tables + ARRAY_SIZE(efx_nic_reg_tables);
  1650. table++)
  1651. if (efx->type->revision >= table->min_revision &&
  1652. efx->type->revision <= table->max_revision)
  1653. len += table->rows * min_t(size_t, table->step, 16);
  1654. return len;
  1655. }
  1656. void efx_nic_get_regs(struct efx_nic *efx, void *buf)
  1657. {
  1658. const struct efx_nic_reg *reg;
  1659. const struct efx_nic_reg_table *table;
  1660. for (reg = efx_nic_regs;
  1661. reg < efx_nic_regs + ARRAY_SIZE(efx_nic_regs);
  1662. reg++) {
  1663. if (efx->type->revision >= reg->min_revision &&
  1664. efx->type->revision <= reg->max_revision) {
  1665. efx_reado(efx, (efx_oword_t *)buf, reg->offset);
  1666. buf += sizeof(efx_oword_t);
  1667. }
  1668. }
  1669. for (table = efx_nic_reg_tables;
  1670. table < efx_nic_reg_tables + ARRAY_SIZE(efx_nic_reg_tables);
  1671. table++) {
  1672. size_t size, i;
  1673. if (!(efx->type->revision >= table->min_revision &&
  1674. efx->type->revision <= table->max_revision))
  1675. continue;
  1676. size = min_t(size_t, table->step, 16);
  1677. for (i = 0; i < table->rows; i++) {
  1678. switch (table->step) {
  1679. case 4: /* 32-bit register or SRAM */
  1680. efx_readd_table(efx, buf, table->offset, i);
  1681. break;
  1682. case 8: /* 64-bit SRAM */
  1683. efx_sram_readq(efx,
  1684. efx->membase + table->offset,
  1685. buf, i);
  1686. break;
  1687. case 16: /* 128-bit register */
  1688. efx_reado_table(efx, buf, table->offset, i);
  1689. break;
  1690. case 32: /* 128-bit register, interleaved */
  1691. efx_reado_table(efx, buf, table->offset, 2 * i);
  1692. break;
  1693. default:
  1694. WARN_ON(1);
  1695. return;
  1696. }
  1697. buf += size;
  1698. }
  1699. }
  1700. }