nic.c 61 KB

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