nic.c 57 KB

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