nic.c 65 KB

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