nic.c 64 KB

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