nic.c 57 KB

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