farch.c 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781
  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 "farch_regs.h"
  21. #include "io.h"
  22. #include "workarounds.h"
  23. /* Falcon-architecture (SFC4000 and SFC9000-family) support */
  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_farch_magic_event(struct efx_channel *channel, u32 magic);
  68. /**************************************************************************
  69. *
  70. * 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. static bool efx_masked_compare_oword(const efx_oword_t *a, const efx_oword_t *b,
  80. const efx_oword_t *mask)
  81. {
  82. return ((a->u64[0] ^ b->u64[0]) & mask->u64[0]) ||
  83. ((a->u64[1] ^ b->u64[1]) & mask->u64[1]);
  84. }
  85. int efx_farch_test_registers(struct efx_nic *efx,
  86. const struct efx_farch_register_test *regs,
  87. size_t n_regs)
  88. {
  89. unsigned address = 0, i, j;
  90. efx_oword_t mask, imask, original, reg, buf;
  91. for (i = 0; i < n_regs; ++i) {
  92. address = regs[i].address;
  93. mask = imask = regs[i].mask;
  94. EFX_INVERT_OWORD(imask);
  95. efx_reado(efx, &original, address);
  96. /* bit sweep on and off */
  97. for (j = 0; j < 128; j++) {
  98. if (!EFX_EXTRACT_OWORD32(mask, j, j))
  99. continue;
  100. /* Test this testable bit can be set in isolation */
  101. EFX_AND_OWORD(reg, original, mask);
  102. EFX_SET_OWORD32(reg, j, j, 1);
  103. efx_writeo(efx, &reg, address);
  104. efx_reado(efx, &buf, address);
  105. if (efx_masked_compare_oword(&reg, &buf, &mask))
  106. goto fail;
  107. /* Test this testable bit can be cleared in isolation */
  108. EFX_OR_OWORD(reg, original, mask);
  109. EFX_SET_OWORD32(reg, j, j, 0);
  110. efx_writeo(efx, &reg, address);
  111. efx_reado(efx, &buf, address);
  112. if (efx_masked_compare_oword(&reg, &buf, &mask))
  113. goto fail;
  114. }
  115. efx_writeo(efx, &original, address);
  116. }
  117. return 0;
  118. fail:
  119. netif_err(efx, hw, efx->net_dev,
  120. "wrote "EFX_OWORD_FMT" read "EFX_OWORD_FMT
  121. " at address 0x%x mask "EFX_OWORD_FMT"\n", EFX_OWORD_VAL(reg),
  122. EFX_OWORD_VAL(buf), address, EFX_OWORD_VAL(mask));
  123. return -EIO;
  124. }
  125. /**************************************************************************
  126. *
  127. * Special buffer handling
  128. * Special buffers are used for event queues and the TX and RX
  129. * descriptor rings.
  130. *
  131. *************************************************************************/
  132. /*
  133. * Initialise a special buffer
  134. *
  135. * This will define a buffer (previously allocated via
  136. * efx_alloc_special_buffer()) in the buffer table, allowing
  137. * it to be used for event queues, descriptor rings etc.
  138. */
  139. static void
  140. efx_init_special_buffer(struct efx_nic *efx, struct efx_special_buffer *buffer)
  141. {
  142. efx_qword_t buf_desc;
  143. unsigned int index;
  144. dma_addr_t dma_addr;
  145. int i;
  146. EFX_BUG_ON_PARANOID(!buffer->buf.addr);
  147. /* Write buffer descriptors to NIC */
  148. for (i = 0; i < buffer->entries; i++) {
  149. index = buffer->index + i;
  150. dma_addr = buffer->buf.dma_addr + (i * EFX_BUF_SIZE);
  151. netif_dbg(efx, probe, efx->net_dev,
  152. "mapping special buffer %d at %llx\n",
  153. index, (unsigned long long)dma_addr);
  154. EFX_POPULATE_QWORD_3(buf_desc,
  155. FRF_AZ_BUF_ADR_REGION, 0,
  156. FRF_AZ_BUF_ADR_FBUF, dma_addr >> 12,
  157. FRF_AZ_BUF_OWNER_ID_FBUF, 0);
  158. efx_write_buf_tbl(efx, &buf_desc, index);
  159. }
  160. }
  161. /* Unmaps a buffer and clears the buffer table entries */
  162. static void
  163. efx_fini_special_buffer(struct efx_nic *efx, struct efx_special_buffer *buffer)
  164. {
  165. efx_oword_t buf_tbl_upd;
  166. unsigned int start = buffer->index;
  167. unsigned int end = (buffer->index + buffer->entries - 1);
  168. if (!buffer->entries)
  169. return;
  170. netif_dbg(efx, hw, efx->net_dev, "unmapping special buffers %d-%d\n",
  171. buffer->index, buffer->index + buffer->entries - 1);
  172. EFX_POPULATE_OWORD_4(buf_tbl_upd,
  173. FRF_AZ_BUF_UPD_CMD, 0,
  174. FRF_AZ_BUF_CLR_CMD, 1,
  175. FRF_AZ_BUF_CLR_END_ID, end,
  176. FRF_AZ_BUF_CLR_START_ID, start);
  177. efx_writeo(efx, &buf_tbl_upd, FR_AZ_BUF_TBL_UPD);
  178. }
  179. /*
  180. * Allocate a new special buffer
  181. *
  182. * This allocates memory for a new buffer, clears it and allocates a
  183. * new buffer ID range. It does not write into the buffer table.
  184. *
  185. * This call will allocate 4KB buffers, since 8KB buffers can't be
  186. * used for event queues and descriptor rings.
  187. */
  188. static int efx_alloc_special_buffer(struct efx_nic *efx,
  189. struct efx_special_buffer *buffer,
  190. unsigned int len)
  191. {
  192. len = ALIGN(len, EFX_BUF_SIZE);
  193. if (efx_nic_alloc_buffer(efx, &buffer->buf, len, GFP_KERNEL))
  194. return -ENOMEM;
  195. buffer->entries = len / EFX_BUF_SIZE;
  196. BUG_ON(buffer->buf.dma_addr & (EFX_BUF_SIZE - 1));
  197. /* Select new buffer ID */
  198. buffer->index = efx->next_buffer_table;
  199. efx->next_buffer_table += buffer->entries;
  200. #ifdef CONFIG_SFC_SRIOV
  201. BUG_ON(efx_sriov_enabled(efx) &&
  202. efx->vf_buftbl_base < efx->next_buffer_table);
  203. #endif
  204. netif_dbg(efx, probe, efx->net_dev,
  205. "allocating special buffers %d-%d at %llx+%x "
  206. "(virt %p phys %llx)\n", buffer->index,
  207. buffer->index + buffer->entries - 1,
  208. (u64)buffer->buf.dma_addr, len,
  209. buffer->buf.addr, (u64)virt_to_phys(buffer->buf.addr));
  210. return 0;
  211. }
  212. static void
  213. efx_free_special_buffer(struct efx_nic *efx, struct efx_special_buffer *buffer)
  214. {
  215. if (!buffer->buf.addr)
  216. return;
  217. netif_dbg(efx, hw, efx->net_dev,
  218. "deallocating special buffers %d-%d at %llx+%x "
  219. "(virt %p phys %llx)\n", buffer->index,
  220. buffer->index + buffer->entries - 1,
  221. (u64)buffer->buf.dma_addr, buffer->buf.len,
  222. buffer->buf.addr, (u64)virt_to_phys(buffer->buf.addr));
  223. efx_nic_free_buffer(efx, &buffer->buf);
  224. buffer->entries = 0;
  225. }
  226. /**************************************************************************
  227. *
  228. * TX path
  229. *
  230. **************************************************************************/
  231. /* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
  232. static inline void efx_farch_notify_tx_desc(struct efx_tx_queue *tx_queue)
  233. {
  234. unsigned write_ptr;
  235. efx_dword_t reg;
  236. write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
  237. EFX_POPULATE_DWORD_1(reg, FRF_AZ_TX_DESC_WPTR_DWORD, write_ptr);
  238. efx_writed_page(tx_queue->efx, &reg,
  239. FR_AZ_TX_DESC_UPD_DWORD_P0, tx_queue->queue);
  240. }
  241. /* Write pointer and first descriptor for TX descriptor ring */
  242. static inline void efx_farch_push_tx_desc(struct efx_tx_queue *tx_queue,
  243. const efx_qword_t *txd)
  244. {
  245. unsigned write_ptr;
  246. efx_oword_t reg;
  247. BUILD_BUG_ON(FRF_AZ_TX_DESC_LBN != 0);
  248. BUILD_BUG_ON(FR_AA_TX_DESC_UPD_KER != FR_BZ_TX_DESC_UPD_P0);
  249. write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
  250. EFX_POPULATE_OWORD_2(reg, FRF_AZ_TX_DESC_PUSH_CMD, true,
  251. FRF_AZ_TX_DESC_WPTR, write_ptr);
  252. reg.qword[0] = *txd;
  253. efx_writeo_page(tx_queue->efx, &reg,
  254. FR_BZ_TX_DESC_UPD_P0, tx_queue->queue);
  255. }
  256. /* For each entry inserted into the software descriptor ring, create a
  257. * descriptor in the hardware TX descriptor ring (in host memory), and
  258. * write a doorbell.
  259. */
  260. void efx_farch_tx_write(struct efx_tx_queue *tx_queue)
  261. {
  262. struct efx_tx_buffer *buffer;
  263. efx_qword_t *txd;
  264. unsigned write_ptr;
  265. unsigned old_write_count = tx_queue->write_count;
  266. BUG_ON(tx_queue->write_count == tx_queue->insert_count);
  267. do {
  268. write_ptr = tx_queue->write_count & tx_queue->ptr_mask;
  269. buffer = &tx_queue->buffer[write_ptr];
  270. txd = efx_tx_desc(tx_queue, write_ptr);
  271. ++tx_queue->write_count;
  272. /* Create TX descriptor ring entry */
  273. BUILD_BUG_ON(EFX_TX_BUF_CONT != 1);
  274. EFX_POPULATE_QWORD_4(*txd,
  275. FSF_AZ_TX_KER_CONT,
  276. buffer->flags & EFX_TX_BUF_CONT,
  277. FSF_AZ_TX_KER_BYTE_COUNT, buffer->len,
  278. FSF_AZ_TX_KER_BUF_REGION, 0,
  279. FSF_AZ_TX_KER_BUF_ADDR, buffer->dma_addr);
  280. } while (tx_queue->write_count != tx_queue->insert_count);
  281. wmb(); /* Ensure descriptors are written before they are fetched */
  282. if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) {
  283. txd = efx_tx_desc(tx_queue,
  284. old_write_count & tx_queue->ptr_mask);
  285. efx_farch_push_tx_desc(tx_queue, txd);
  286. ++tx_queue->pushes;
  287. } else {
  288. efx_farch_notify_tx_desc(tx_queue);
  289. }
  290. }
  291. /* Allocate hardware resources for a TX queue */
  292. int efx_farch_tx_probe(struct efx_tx_queue *tx_queue)
  293. {
  294. struct efx_nic *efx = tx_queue->efx;
  295. unsigned entries;
  296. entries = tx_queue->ptr_mask + 1;
  297. return efx_alloc_special_buffer(efx, &tx_queue->txd,
  298. entries * sizeof(efx_qword_t));
  299. }
  300. void efx_farch_tx_init(struct efx_tx_queue *tx_queue)
  301. {
  302. struct efx_nic *efx = tx_queue->efx;
  303. efx_oword_t reg;
  304. /* Pin TX descriptor ring */
  305. efx_init_special_buffer(efx, &tx_queue->txd);
  306. /* Push TX descriptor ring to card */
  307. EFX_POPULATE_OWORD_10(reg,
  308. FRF_AZ_TX_DESCQ_EN, 1,
  309. FRF_AZ_TX_ISCSI_DDIG_EN, 0,
  310. FRF_AZ_TX_ISCSI_HDIG_EN, 0,
  311. FRF_AZ_TX_DESCQ_BUF_BASE_ID, tx_queue->txd.index,
  312. FRF_AZ_TX_DESCQ_EVQ_ID,
  313. tx_queue->channel->channel,
  314. FRF_AZ_TX_DESCQ_OWNER_ID, 0,
  315. FRF_AZ_TX_DESCQ_LABEL, tx_queue->queue,
  316. FRF_AZ_TX_DESCQ_SIZE,
  317. __ffs(tx_queue->txd.entries),
  318. FRF_AZ_TX_DESCQ_TYPE, 0,
  319. FRF_BZ_TX_NON_IP_DROP_DIS, 1);
  320. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) {
  321. int csum = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD;
  322. EFX_SET_OWORD_FIELD(reg, FRF_BZ_TX_IP_CHKSM_DIS, !csum);
  323. EFX_SET_OWORD_FIELD(reg, FRF_BZ_TX_TCP_CHKSM_DIS,
  324. !csum);
  325. }
  326. efx_writeo_table(efx, &reg, efx->type->txd_ptr_tbl_base,
  327. tx_queue->queue);
  328. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0) {
  329. /* Only 128 bits in this register */
  330. BUILD_BUG_ON(EFX_MAX_TX_QUEUES > 128);
  331. efx_reado(efx, &reg, FR_AA_TX_CHKSM_CFG);
  332. if (tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD)
  333. __clear_bit_le(tx_queue->queue, &reg);
  334. else
  335. __set_bit_le(tx_queue->queue, &reg);
  336. efx_writeo(efx, &reg, FR_AA_TX_CHKSM_CFG);
  337. }
  338. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) {
  339. EFX_POPULATE_OWORD_1(reg,
  340. FRF_BZ_TX_PACE,
  341. (tx_queue->queue & EFX_TXQ_TYPE_HIGHPRI) ?
  342. FFE_BZ_TX_PACE_OFF :
  343. FFE_BZ_TX_PACE_RESERVED);
  344. efx_writeo_table(efx, &reg, FR_BZ_TX_PACE_TBL,
  345. tx_queue->queue);
  346. }
  347. }
  348. static void efx_farch_flush_tx_queue(struct efx_tx_queue *tx_queue)
  349. {
  350. struct efx_nic *efx = tx_queue->efx;
  351. efx_oword_t tx_flush_descq;
  352. WARN_ON(atomic_read(&tx_queue->flush_outstanding));
  353. atomic_set(&tx_queue->flush_outstanding, 1);
  354. EFX_POPULATE_OWORD_2(tx_flush_descq,
  355. FRF_AZ_TX_FLUSH_DESCQ_CMD, 1,
  356. FRF_AZ_TX_FLUSH_DESCQ, tx_queue->queue);
  357. efx_writeo(efx, &tx_flush_descq, FR_AZ_TX_FLUSH_DESCQ);
  358. }
  359. void efx_farch_tx_fini(struct efx_tx_queue *tx_queue)
  360. {
  361. struct efx_nic *efx = tx_queue->efx;
  362. efx_oword_t tx_desc_ptr;
  363. /* Remove TX descriptor ring from card */
  364. EFX_ZERO_OWORD(tx_desc_ptr);
  365. efx_writeo_table(efx, &tx_desc_ptr, efx->type->txd_ptr_tbl_base,
  366. tx_queue->queue);
  367. /* Unpin TX descriptor ring */
  368. efx_fini_special_buffer(efx, &tx_queue->txd);
  369. }
  370. /* Free buffers backing TX queue */
  371. void efx_farch_tx_remove(struct efx_tx_queue *tx_queue)
  372. {
  373. efx_free_special_buffer(tx_queue->efx, &tx_queue->txd);
  374. }
  375. /**************************************************************************
  376. *
  377. * RX path
  378. *
  379. **************************************************************************/
  380. /* This creates an entry in the RX descriptor queue */
  381. static inline void
  382. efx_farch_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned index)
  383. {
  384. struct efx_rx_buffer *rx_buf;
  385. efx_qword_t *rxd;
  386. rxd = efx_rx_desc(rx_queue, index);
  387. rx_buf = efx_rx_buffer(rx_queue, index);
  388. EFX_POPULATE_QWORD_3(*rxd,
  389. FSF_AZ_RX_KER_BUF_SIZE,
  390. rx_buf->len -
  391. rx_queue->efx->type->rx_buffer_padding,
  392. FSF_AZ_RX_KER_BUF_REGION, 0,
  393. FSF_AZ_RX_KER_BUF_ADDR, rx_buf->dma_addr);
  394. }
  395. /* This writes to the RX_DESC_WPTR register for the specified receive
  396. * descriptor ring.
  397. */
  398. void efx_farch_rx_write(struct efx_rx_queue *rx_queue)
  399. {
  400. struct efx_nic *efx = rx_queue->efx;
  401. efx_dword_t reg;
  402. unsigned write_ptr;
  403. while (rx_queue->notified_count != rx_queue->added_count) {
  404. efx_farch_build_rx_desc(
  405. rx_queue,
  406. rx_queue->notified_count & rx_queue->ptr_mask);
  407. ++rx_queue->notified_count;
  408. }
  409. wmb();
  410. write_ptr = rx_queue->added_count & rx_queue->ptr_mask;
  411. EFX_POPULATE_DWORD_1(reg, FRF_AZ_RX_DESC_WPTR_DWORD, write_ptr);
  412. efx_writed_page(efx, &reg, FR_AZ_RX_DESC_UPD_DWORD_P0,
  413. efx_rx_queue_index(rx_queue));
  414. }
  415. int efx_farch_rx_probe(struct efx_rx_queue *rx_queue)
  416. {
  417. struct efx_nic *efx = rx_queue->efx;
  418. unsigned entries;
  419. entries = rx_queue->ptr_mask + 1;
  420. return efx_alloc_special_buffer(efx, &rx_queue->rxd,
  421. entries * sizeof(efx_qword_t));
  422. }
  423. void efx_farch_rx_init(struct efx_rx_queue *rx_queue)
  424. {
  425. efx_oword_t rx_desc_ptr;
  426. struct efx_nic *efx = rx_queue->efx;
  427. bool is_b0 = efx_nic_rev(efx) >= EFX_REV_FALCON_B0;
  428. bool iscsi_digest_en = is_b0;
  429. bool jumbo_en;
  430. /* For kernel-mode queues in Falcon A1, the JUMBO flag enables
  431. * DMA to continue after a PCIe page boundary (and scattering
  432. * is not possible). In Falcon B0 and Siena, it enables
  433. * scatter.
  434. */
  435. jumbo_en = !is_b0 || efx->rx_scatter;
  436. netif_dbg(efx, hw, efx->net_dev,
  437. "RX queue %d ring in special buffers %d-%d\n",
  438. efx_rx_queue_index(rx_queue), rx_queue->rxd.index,
  439. rx_queue->rxd.index + rx_queue->rxd.entries - 1);
  440. rx_queue->scatter_n = 0;
  441. /* Pin RX descriptor ring */
  442. efx_init_special_buffer(efx, &rx_queue->rxd);
  443. /* Push RX descriptor ring to card */
  444. EFX_POPULATE_OWORD_10(rx_desc_ptr,
  445. FRF_AZ_RX_ISCSI_DDIG_EN, iscsi_digest_en,
  446. FRF_AZ_RX_ISCSI_HDIG_EN, iscsi_digest_en,
  447. FRF_AZ_RX_DESCQ_BUF_BASE_ID, rx_queue->rxd.index,
  448. FRF_AZ_RX_DESCQ_EVQ_ID,
  449. efx_rx_queue_channel(rx_queue)->channel,
  450. FRF_AZ_RX_DESCQ_OWNER_ID, 0,
  451. FRF_AZ_RX_DESCQ_LABEL,
  452. efx_rx_queue_index(rx_queue),
  453. FRF_AZ_RX_DESCQ_SIZE,
  454. __ffs(rx_queue->rxd.entries),
  455. FRF_AZ_RX_DESCQ_TYPE, 0 /* kernel queue */ ,
  456. FRF_AZ_RX_DESCQ_JUMBO, jumbo_en,
  457. FRF_AZ_RX_DESCQ_EN, 1);
  458. efx_writeo_table(efx, &rx_desc_ptr, efx->type->rxd_ptr_tbl_base,
  459. efx_rx_queue_index(rx_queue));
  460. }
  461. static void efx_farch_flush_rx_queue(struct efx_rx_queue *rx_queue)
  462. {
  463. struct efx_nic *efx = rx_queue->efx;
  464. efx_oword_t rx_flush_descq;
  465. EFX_POPULATE_OWORD_2(rx_flush_descq,
  466. FRF_AZ_RX_FLUSH_DESCQ_CMD, 1,
  467. FRF_AZ_RX_FLUSH_DESCQ,
  468. efx_rx_queue_index(rx_queue));
  469. efx_writeo(efx, &rx_flush_descq, FR_AZ_RX_FLUSH_DESCQ);
  470. }
  471. void efx_farch_rx_fini(struct efx_rx_queue *rx_queue)
  472. {
  473. efx_oword_t rx_desc_ptr;
  474. struct efx_nic *efx = rx_queue->efx;
  475. /* Remove RX descriptor ring from card */
  476. EFX_ZERO_OWORD(rx_desc_ptr);
  477. efx_writeo_table(efx, &rx_desc_ptr, efx->type->rxd_ptr_tbl_base,
  478. efx_rx_queue_index(rx_queue));
  479. /* Unpin RX descriptor ring */
  480. efx_fini_special_buffer(efx, &rx_queue->rxd);
  481. }
  482. /* Free buffers backing RX queue */
  483. void efx_farch_rx_remove(struct efx_rx_queue *rx_queue)
  484. {
  485. efx_free_special_buffer(rx_queue->efx, &rx_queue->rxd);
  486. }
  487. /**************************************************************************
  488. *
  489. * Flush handling
  490. *
  491. **************************************************************************/
  492. /* efx_farch_flush_queues() must be woken up when all flushes are completed,
  493. * or more RX flushes can be kicked off.
  494. */
  495. static bool efx_farch_flush_wake(struct efx_nic *efx)
  496. {
  497. /* Ensure that all updates are visible to efx_farch_flush_queues() */
  498. smp_mb();
  499. return (atomic_read(&efx->drain_pending) == 0 ||
  500. (atomic_read(&efx->rxq_flush_outstanding) < EFX_RX_FLUSH_COUNT
  501. && atomic_read(&efx->rxq_flush_pending) > 0));
  502. }
  503. static bool efx_check_tx_flush_complete(struct efx_nic *efx)
  504. {
  505. bool i = true;
  506. efx_oword_t txd_ptr_tbl;
  507. struct efx_channel *channel;
  508. struct efx_tx_queue *tx_queue;
  509. efx_for_each_channel(channel, efx) {
  510. efx_for_each_channel_tx_queue(tx_queue, channel) {
  511. efx_reado_table(efx, &txd_ptr_tbl,
  512. FR_BZ_TX_DESC_PTR_TBL, tx_queue->queue);
  513. if (EFX_OWORD_FIELD(txd_ptr_tbl,
  514. FRF_AZ_TX_DESCQ_FLUSH) ||
  515. EFX_OWORD_FIELD(txd_ptr_tbl,
  516. FRF_AZ_TX_DESCQ_EN)) {
  517. netif_dbg(efx, hw, efx->net_dev,
  518. "flush did not complete on TXQ %d\n",
  519. tx_queue->queue);
  520. i = false;
  521. } else if (atomic_cmpxchg(&tx_queue->flush_outstanding,
  522. 1, 0)) {
  523. /* The flush is complete, but we didn't
  524. * receive a flush completion event
  525. */
  526. netif_dbg(efx, hw, efx->net_dev,
  527. "flush complete on TXQ %d, so drain "
  528. "the queue\n", tx_queue->queue);
  529. /* Don't need to increment drain_pending as it
  530. * has already been incremented for the queues
  531. * which did not drain
  532. */
  533. efx_farch_magic_event(channel,
  534. EFX_CHANNEL_MAGIC_TX_DRAIN(
  535. tx_queue));
  536. }
  537. }
  538. }
  539. return i;
  540. }
  541. /* Flush all the transmit queues, and continue flushing receive queues until
  542. * they're all flushed. Wait for the DRAIN events to be recieved so that there
  543. * are no more RX and TX events left on any channel. */
  544. static int efx_farch_do_flush(struct efx_nic *efx)
  545. {
  546. unsigned timeout = msecs_to_jiffies(5000); /* 5s for all flushes and drains */
  547. struct efx_channel *channel;
  548. struct efx_rx_queue *rx_queue;
  549. struct efx_tx_queue *tx_queue;
  550. int rc = 0;
  551. efx_for_each_channel(channel, efx) {
  552. efx_for_each_channel_tx_queue(tx_queue, channel) {
  553. atomic_inc(&efx->drain_pending);
  554. efx_farch_flush_tx_queue(tx_queue);
  555. }
  556. efx_for_each_channel_rx_queue(rx_queue, channel) {
  557. atomic_inc(&efx->drain_pending);
  558. rx_queue->flush_pending = true;
  559. atomic_inc(&efx->rxq_flush_pending);
  560. }
  561. }
  562. while (timeout && atomic_read(&efx->drain_pending) > 0) {
  563. /* If SRIOV is enabled, then offload receive queue flushing to
  564. * the firmware (though we will still have to poll for
  565. * completion). If that fails, fall back to the old scheme.
  566. */
  567. if (efx_sriov_enabled(efx)) {
  568. rc = efx_mcdi_flush_rxqs(efx);
  569. if (!rc)
  570. goto wait;
  571. }
  572. /* The hardware supports four concurrent rx flushes, each of
  573. * which may need to be retried if there is an outstanding
  574. * descriptor fetch
  575. */
  576. efx_for_each_channel(channel, efx) {
  577. efx_for_each_channel_rx_queue(rx_queue, channel) {
  578. if (atomic_read(&efx->rxq_flush_outstanding) >=
  579. EFX_RX_FLUSH_COUNT)
  580. break;
  581. if (rx_queue->flush_pending) {
  582. rx_queue->flush_pending = false;
  583. atomic_dec(&efx->rxq_flush_pending);
  584. atomic_inc(&efx->rxq_flush_outstanding);
  585. efx_farch_flush_rx_queue(rx_queue);
  586. }
  587. }
  588. }
  589. wait:
  590. timeout = wait_event_timeout(efx->flush_wq,
  591. efx_farch_flush_wake(efx),
  592. timeout);
  593. }
  594. if (atomic_read(&efx->drain_pending) &&
  595. !efx_check_tx_flush_complete(efx)) {
  596. netif_err(efx, hw, efx->net_dev, "failed to flush %d queues "
  597. "(rx %d+%d)\n", atomic_read(&efx->drain_pending),
  598. atomic_read(&efx->rxq_flush_outstanding),
  599. atomic_read(&efx->rxq_flush_pending));
  600. rc = -ETIMEDOUT;
  601. atomic_set(&efx->drain_pending, 0);
  602. atomic_set(&efx->rxq_flush_pending, 0);
  603. atomic_set(&efx->rxq_flush_outstanding, 0);
  604. }
  605. return rc;
  606. }
  607. int efx_farch_fini_dmaq(struct efx_nic *efx)
  608. {
  609. struct efx_channel *channel;
  610. struct efx_tx_queue *tx_queue;
  611. struct efx_rx_queue *rx_queue;
  612. int rc = 0;
  613. /* Do not attempt to write to the NIC during EEH recovery */
  614. if (efx->state != STATE_RECOVERY) {
  615. /* Only perform flush if DMA is enabled */
  616. if (efx->pci_dev->is_busmaster) {
  617. efx->type->prepare_flush(efx);
  618. rc = efx_farch_do_flush(efx);
  619. efx->type->finish_flush(efx);
  620. }
  621. efx_for_each_channel(channel, efx) {
  622. efx_for_each_channel_rx_queue(rx_queue, channel)
  623. efx_farch_rx_fini(rx_queue);
  624. efx_for_each_channel_tx_queue(tx_queue, channel)
  625. efx_farch_tx_fini(tx_queue);
  626. }
  627. }
  628. return rc;
  629. }
  630. /**************************************************************************
  631. *
  632. * Event queue processing
  633. * Event queues are processed by per-channel tasklets.
  634. *
  635. **************************************************************************/
  636. /* Update a channel's event queue's read pointer (RPTR) register
  637. *
  638. * This writes the EVQ_RPTR_REG register for the specified channel's
  639. * event queue.
  640. */
  641. void efx_farch_ev_read_ack(struct efx_channel *channel)
  642. {
  643. efx_dword_t reg;
  644. struct efx_nic *efx = channel->efx;
  645. EFX_POPULATE_DWORD_1(reg, FRF_AZ_EVQ_RPTR,
  646. channel->eventq_read_ptr & channel->eventq_mask);
  647. /* For Falcon A1, EVQ_RPTR_KER is documented as having a step size
  648. * of 4 bytes, but it is really 16 bytes just like later revisions.
  649. */
  650. efx_writed(efx, &reg,
  651. efx->type->evq_rptr_tbl_base +
  652. FR_BZ_EVQ_RPTR_STEP * channel->channel);
  653. }
  654. /* Use HW to insert a SW defined event */
  655. void efx_farch_generate_event(struct efx_nic *efx, unsigned int evq,
  656. efx_qword_t *event)
  657. {
  658. efx_oword_t drv_ev_reg;
  659. BUILD_BUG_ON(FRF_AZ_DRV_EV_DATA_LBN != 0 ||
  660. FRF_AZ_DRV_EV_DATA_WIDTH != 64);
  661. drv_ev_reg.u32[0] = event->u32[0];
  662. drv_ev_reg.u32[1] = event->u32[1];
  663. drv_ev_reg.u32[2] = 0;
  664. drv_ev_reg.u32[3] = 0;
  665. EFX_SET_OWORD_FIELD(drv_ev_reg, FRF_AZ_DRV_EV_QID, evq);
  666. efx_writeo(efx, &drv_ev_reg, FR_AZ_DRV_EV);
  667. }
  668. static void efx_farch_magic_event(struct efx_channel *channel, u32 magic)
  669. {
  670. efx_qword_t event;
  671. EFX_POPULATE_QWORD_2(event, FSF_AZ_EV_CODE,
  672. FSE_AZ_EV_CODE_DRV_GEN_EV,
  673. FSF_AZ_DRV_GEN_EV_MAGIC, magic);
  674. efx_farch_generate_event(channel->efx, channel->channel, &event);
  675. }
  676. /* Handle a transmit completion event
  677. *
  678. * The NIC batches TX completion events; the message we receive is of
  679. * the form "complete all TX events up to this index".
  680. */
  681. static int
  682. efx_farch_handle_tx_event(struct efx_channel *channel, efx_qword_t *event)
  683. {
  684. unsigned int tx_ev_desc_ptr;
  685. unsigned int tx_ev_q_label;
  686. struct efx_tx_queue *tx_queue;
  687. struct efx_nic *efx = channel->efx;
  688. int tx_packets = 0;
  689. if (unlikely(ACCESS_ONCE(efx->reset_pending)))
  690. return 0;
  691. if (likely(EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_COMP))) {
  692. /* Transmit completion */
  693. tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_DESC_PTR);
  694. tx_ev_q_label = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_Q_LABEL);
  695. tx_queue = efx_channel_get_tx_queue(
  696. channel, tx_ev_q_label % EFX_TXQ_TYPES);
  697. tx_packets = ((tx_ev_desc_ptr - tx_queue->read_count) &
  698. tx_queue->ptr_mask);
  699. efx_xmit_done(tx_queue, tx_ev_desc_ptr);
  700. } else if (EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_WQ_FF_FULL)) {
  701. /* Rewrite the FIFO write pointer */
  702. tx_ev_q_label = EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_Q_LABEL);
  703. tx_queue = efx_channel_get_tx_queue(
  704. channel, tx_ev_q_label % EFX_TXQ_TYPES);
  705. netif_tx_lock(efx->net_dev);
  706. efx_farch_notify_tx_desc(tx_queue);
  707. netif_tx_unlock(efx->net_dev);
  708. } else if (EFX_QWORD_FIELD(*event, FSF_AZ_TX_EV_PKT_ERR)) {
  709. efx_schedule_reset(efx, RESET_TYPE_TX_DESC_FETCH);
  710. } else {
  711. netif_err(efx, tx_err, efx->net_dev,
  712. "channel %d unexpected TX event "
  713. EFX_QWORD_FMT"\n", channel->channel,
  714. EFX_QWORD_VAL(*event));
  715. }
  716. return tx_packets;
  717. }
  718. /* Detect errors included in the rx_evt_pkt_ok bit. */
  719. static u16 efx_farch_handle_rx_not_ok(struct efx_rx_queue *rx_queue,
  720. const efx_qword_t *event)
  721. {
  722. struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
  723. struct efx_nic *efx = rx_queue->efx;
  724. bool rx_ev_buf_owner_id_err, rx_ev_ip_hdr_chksum_err;
  725. bool rx_ev_tcp_udp_chksum_err, rx_ev_eth_crc_err;
  726. bool rx_ev_frm_trunc, rx_ev_drib_nib, rx_ev_tobe_disc;
  727. bool rx_ev_other_err, rx_ev_pause_frm;
  728. bool rx_ev_hdr_type, rx_ev_mcast_pkt;
  729. unsigned rx_ev_pkt_type;
  730. rx_ev_hdr_type = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_HDR_TYPE);
  731. rx_ev_mcast_pkt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_PKT);
  732. rx_ev_tobe_disc = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_TOBE_DISC);
  733. rx_ev_pkt_type = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_PKT_TYPE);
  734. rx_ev_buf_owner_id_err = EFX_QWORD_FIELD(*event,
  735. FSF_AZ_RX_EV_BUF_OWNER_ID_ERR);
  736. rx_ev_ip_hdr_chksum_err = EFX_QWORD_FIELD(*event,
  737. FSF_AZ_RX_EV_IP_HDR_CHKSUM_ERR);
  738. rx_ev_tcp_udp_chksum_err = EFX_QWORD_FIELD(*event,
  739. FSF_AZ_RX_EV_TCP_UDP_CHKSUM_ERR);
  740. rx_ev_eth_crc_err = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_ETH_CRC_ERR);
  741. rx_ev_frm_trunc = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_FRM_TRUNC);
  742. rx_ev_drib_nib = ((efx_nic_rev(efx) >= EFX_REV_FALCON_B0) ?
  743. 0 : EFX_QWORD_FIELD(*event, FSF_AA_RX_EV_DRIB_NIB));
  744. rx_ev_pause_frm = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_PAUSE_FRM_ERR);
  745. /* Every error apart from tobe_disc and pause_frm */
  746. rx_ev_other_err = (rx_ev_drib_nib | rx_ev_tcp_udp_chksum_err |
  747. rx_ev_buf_owner_id_err | rx_ev_eth_crc_err |
  748. rx_ev_frm_trunc | rx_ev_ip_hdr_chksum_err);
  749. /* Count errors that are not in MAC stats. Ignore expected
  750. * checksum errors during self-test. */
  751. if (rx_ev_frm_trunc)
  752. ++channel->n_rx_frm_trunc;
  753. else if (rx_ev_tobe_disc)
  754. ++channel->n_rx_tobe_disc;
  755. else if (!efx->loopback_selftest) {
  756. if (rx_ev_ip_hdr_chksum_err)
  757. ++channel->n_rx_ip_hdr_chksum_err;
  758. else if (rx_ev_tcp_udp_chksum_err)
  759. ++channel->n_rx_tcp_udp_chksum_err;
  760. }
  761. /* TOBE_DISC is expected on unicast mismatches; don't print out an
  762. * error message. FRM_TRUNC indicates RXDP dropped the packet due
  763. * to a FIFO overflow.
  764. */
  765. #ifdef DEBUG
  766. if (rx_ev_other_err && net_ratelimit()) {
  767. netif_dbg(efx, rx_err, efx->net_dev,
  768. " RX queue %d unexpected RX event "
  769. EFX_QWORD_FMT "%s%s%s%s%s%s%s%s\n",
  770. efx_rx_queue_index(rx_queue), EFX_QWORD_VAL(*event),
  771. rx_ev_buf_owner_id_err ? " [OWNER_ID_ERR]" : "",
  772. rx_ev_ip_hdr_chksum_err ?
  773. " [IP_HDR_CHKSUM_ERR]" : "",
  774. rx_ev_tcp_udp_chksum_err ?
  775. " [TCP_UDP_CHKSUM_ERR]" : "",
  776. rx_ev_eth_crc_err ? " [ETH_CRC_ERR]" : "",
  777. rx_ev_frm_trunc ? " [FRM_TRUNC]" : "",
  778. rx_ev_drib_nib ? " [DRIB_NIB]" : "",
  779. rx_ev_tobe_disc ? " [TOBE_DISC]" : "",
  780. rx_ev_pause_frm ? " [PAUSE]" : "");
  781. }
  782. #endif
  783. /* The frame must be discarded if any of these are true. */
  784. return (rx_ev_eth_crc_err | rx_ev_frm_trunc | rx_ev_drib_nib |
  785. rx_ev_tobe_disc | rx_ev_pause_frm) ?
  786. EFX_RX_PKT_DISCARD : 0;
  787. }
  788. /* Handle receive events that are not in-order. Return true if this
  789. * can be handled as a partial packet discard, false if it's more
  790. * serious.
  791. */
  792. static bool
  793. efx_farch_handle_rx_bad_index(struct efx_rx_queue *rx_queue, unsigned index)
  794. {
  795. struct efx_channel *channel = efx_rx_queue_channel(rx_queue);
  796. struct efx_nic *efx = rx_queue->efx;
  797. unsigned expected, dropped;
  798. if (rx_queue->scatter_n &&
  799. index == ((rx_queue->removed_count + rx_queue->scatter_n - 1) &
  800. rx_queue->ptr_mask)) {
  801. ++channel->n_rx_nodesc_trunc;
  802. return true;
  803. }
  804. expected = rx_queue->removed_count & rx_queue->ptr_mask;
  805. dropped = (index - expected) & rx_queue->ptr_mask;
  806. netif_info(efx, rx_err, efx->net_dev,
  807. "dropped %d events (index=%d expected=%d)\n",
  808. dropped, index, expected);
  809. efx_schedule_reset(efx, EFX_WORKAROUND_5676(efx) ?
  810. RESET_TYPE_RX_RECOVERY : RESET_TYPE_DISABLE);
  811. return false;
  812. }
  813. /* Handle a packet received event
  814. *
  815. * The NIC gives a "discard" flag if it's a unicast packet with the
  816. * wrong destination address
  817. * Also "is multicast" and "matches multicast filter" flags can be used to
  818. * discard non-matching multicast packets.
  819. */
  820. static void
  821. efx_farch_handle_rx_event(struct efx_channel *channel, const efx_qword_t *event)
  822. {
  823. unsigned int rx_ev_desc_ptr, rx_ev_byte_cnt;
  824. unsigned int rx_ev_hdr_type, rx_ev_mcast_pkt;
  825. unsigned expected_ptr;
  826. bool rx_ev_pkt_ok, rx_ev_sop, rx_ev_cont;
  827. u16 flags;
  828. struct efx_rx_queue *rx_queue;
  829. struct efx_nic *efx = channel->efx;
  830. if (unlikely(ACCESS_ONCE(efx->reset_pending)))
  831. return;
  832. rx_ev_cont = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_JUMBO_CONT);
  833. rx_ev_sop = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_SOP);
  834. WARN_ON(EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_Q_LABEL) !=
  835. channel->channel);
  836. rx_queue = efx_channel_get_rx_queue(channel);
  837. rx_ev_desc_ptr = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_DESC_PTR);
  838. expected_ptr = ((rx_queue->removed_count + rx_queue->scatter_n) &
  839. rx_queue->ptr_mask);
  840. /* Check for partial drops and other errors */
  841. if (unlikely(rx_ev_desc_ptr != expected_ptr) ||
  842. unlikely(rx_ev_sop != (rx_queue->scatter_n == 0))) {
  843. if (rx_ev_desc_ptr != expected_ptr &&
  844. !efx_farch_handle_rx_bad_index(rx_queue, rx_ev_desc_ptr))
  845. return;
  846. /* Discard all pending fragments */
  847. if (rx_queue->scatter_n) {
  848. efx_rx_packet(
  849. rx_queue,
  850. rx_queue->removed_count & rx_queue->ptr_mask,
  851. rx_queue->scatter_n, 0, EFX_RX_PKT_DISCARD);
  852. rx_queue->removed_count += rx_queue->scatter_n;
  853. rx_queue->scatter_n = 0;
  854. }
  855. /* Return if there is no new fragment */
  856. if (rx_ev_desc_ptr != expected_ptr)
  857. return;
  858. /* Discard new fragment if not SOP */
  859. if (!rx_ev_sop) {
  860. efx_rx_packet(
  861. rx_queue,
  862. rx_queue->removed_count & rx_queue->ptr_mask,
  863. 1, 0, EFX_RX_PKT_DISCARD);
  864. ++rx_queue->removed_count;
  865. return;
  866. }
  867. }
  868. ++rx_queue->scatter_n;
  869. if (rx_ev_cont)
  870. return;
  871. rx_ev_byte_cnt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_BYTE_CNT);
  872. rx_ev_pkt_ok = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_PKT_OK);
  873. rx_ev_hdr_type = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_HDR_TYPE);
  874. if (likely(rx_ev_pkt_ok)) {
  875. /* If packet is marked as OK then we can rely on the
  876. * hardware checksum and classification.
  877. */
  878. flags = 0;
  879. switch (rx_ev_hdr_type) {
  880. case FSE_CZ_RX_EV_HDR_TYPE_IPV4V6_TCP:
  881. flags |= EFX_RX_PKT_TCP;
  882. /* fall through */
  883. case FSE_CZ_RX_EV_HDR_TYPE_IPV4V6_UDP:
  884. flags |= EFX_RX_PKT_CSUMMED;
  885. /* fall through */
  886. case FSE_CZ_RX_EV_HDR_TYPE_IPV4V6_OTHER:
  887. case FSE_AZ_RX_EV_HDR_TYPE_OTHER:
  888. break;
  889. }
  890. } else {
  891. flags = efx_farch_handle_rx_not_ok(rx_queue, event);
  892. }
  893. /* Detect multicast packets that didn't match the filter */
  894. rx_ev_mcast_pkt = EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_PKT);
  895. if (rx_ev_mcast_pkt) {
  896. unsigned int rx_ev_mcast_hash_match =
  897. EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_MCAST_HASH_MATCH);
  898. if (unlikely(!rx_ev_mcast_hash_match)) {
  899. ++channel->n_rx_mcast_mismatch;
  900. flags |= EFX_RX_PKT_DISCARD;
  901. }
  902. }
  903. channel->irq_mod_score += 2;
  904. /* Handle received packet */
  905. efx_rx_packet(rx_queue,
  906. rx_queue->removed_count & rx_queue->ptr_mask,
  907. rx_queue->scatter_n, rx_ev_byte_cnt, flags);
  908. rx_queue->removed_count += rx_queue->scatter_n;
  909. rx_queue->scatter_n = 0;
  910. }
  911. /* If this flush done event corresponds to a &struct efx_tx_queue, then
  912. * send an %EFX_CHANNEL_MAGIC_TX_DRAIN event to drain the event queue
  913. * of all transmit completions.
  914. */
  915. static void
  916. efx_farch_handle_tx_flush_done(struct efx_nic *efx, efx_qword_t *event)
  917. {
  918. struct efx_tx_queue *tx_queue;
  919. int qid;
  920. qid = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBDATA);
  921. if (qid < EFX_TXQ_TYPES * efx->n_tx_channels) {
  922. tx_queue = efx_get_tx_queue(efx, qid / EFX_TXQ_TYPES,
  923. qid % EFX_TXQ_TYPES);
  924. if (atomic_cmpxchg(&tx_queue->flush_outstanding, 1, 0)) {
  925. efx_farch_magic_event(tx_queue->channel,
  926. EFX_CHANNEL_MAGIC_TX_DRAIN(tx_queue));
  927. }
  928. }
  929. }
  930. /* If this flush done event corresponds to a &struct efx_rx_queue: If the flush
  931. * was succesful then send an %EFX_CHANNEL_MAGIC_RX_DRAIN, otherwise add
  932. * the RX queue back to the mask of RX queues in need of flushing.
  933. */
  934. static void
  935. efx_farch_handle_rx_flush_done(struct efx_nic *efx, efx_qword_t *event)
  936. {
  937. struct efx_channel *channel;
  938. struct efx_rx_queue *rx_queue;
  939. int qid;
  940. bool failed;
  941. qid = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_RX_DESCQ_ID);
  942. failed = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_RX_FLUSH_FAIL);
  943. if (qid >= efx->n_channels)
  944. return;
  945. channel = efx_get_channel(efx, qid);
  946. if (!efx_channel_has_rx_queue(channel))
  947. return;
  948. rx_queue = efx_channel_get_rx_queue(channel);
  949. if (failed) {
  950. netif_info(efx, hw, efx->net_dev,
  951. "RXQ %d flush retry\n", qid);
  952. rx_queue->flush_pending = true;
  953. atomic_inc(&efx->rxq_flush_pending);
  954. } else {
  955. efx_farch_magic_event(efx_rx_queue_channel(rx_queue),
  956. EFX_CHANNEL_MAGIC_RX_DRAIN(rx_queue));
  957. }
  958. atomic_dec(&efx->rxq_flush_outstanding);
  959. if (efx_farch_flush_wake(efx))
  960. wake_up(&efx->flush_wq);
  961. }
  962. static void
  963. efx_farch_handle_drain_event(struct efx_channel *channel)
  964. {
  965. struct efx_nic *efx = channel->efx;
  966. WARN_ON(atomic_read(&efx->drain_pending) == 0);
  967. atomic_dec(&efx->drain_pending);
  968. if (efx_farch_flush_wake(efx))
  969. wake_up(&efx->flush_wq);
  970. }
  971. static void efx_farch_handle_generated_event(struct efx_channel *channel,
  972. efx_qword_t *event)
  973. {
  974. struct efx_nic *efx = channel->efx;
  975. struct efx_rx_queue *rx_queue =
  976. efx_channel_has_rx_queue(channel) ?
  977. efx_channel_get_rx_queue(channel) : NULL;
  978. unsigned magic, code;
  979. magic = EFX_QWORD_FIELD(*event, FSF_AZ_DRV_GEN_EV_MAGIC);
  980. code = _EFX_CHANNEL_MAGIC_CODE(magic);
  981. if (magic == EFX_CHANNEL_MAGIC_TEST(channel)) {
  982. channel->event_test_cpu = raw_smp_processor_id();
  983. } else if (rx_queue && magic == EFX_CHANNEL_MAGIC_FILL(rx_queue)) {
  984. /* The queue must be empty, so we won't receive any rx
  985. * events, so efx_process_channel() won't refill the
  986. * queue. Refill it here */
  987. efx_fast_push_rx_descriptors(rx_queue);
  988. } else if (rx_queue && magic == EFX_CHANNEL_MAGIC_RX_DRAIN(rx_queue)) {
  989. efx_farch_handle_drain_event(channel);
  990. } else if (code == _EFX_CHANNEL_MAGIC_TX_DRAIN) {
  991. efx_farch_handle_drain_event(channel);
  992. } else {
  993. netif_dbg(efx, hw, efx->net_dev, "channel %d received "
  994. "generated event "EFX_QWORD_FMT"\n",
  995. channel->channel, EFX_QWORD_VAL(*event));
  996. }
  997. }
  998. static void
  999. efx_farch_handle_driver_event(struct efx_channel *channel, efx_qword_t *event)
  1000. {
  1001. struct efx_nic *efx = channel->efx;
  1002. unsigned int ev_sub_code;
  1003. unsigned int ev_sub_data;
  1004. ev_sub_code = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBCODE);
  1005. ev_sub_data = EFX_QWORD_FIELD(*event, FSF_AZ_DRIVER_EV_SUBDATA);
  1006. switch (ev_sub_code) {
  1007. case FSE_AZ_TX_DESCQ_FLS_DONE_EV:
  1008. netif_vdbg(efx, hw, efx->net_dev, "channel %d TXQ %d flushed\n",
  1009. channel->channel, ev_sub_data);
  1010. efx_farch_handle_tx_flush_done(efx, event);
  1011. efx_sriov_tx_flush_done(efx, event);
  1012. break;
  1013. case FSE_AZ_RX_DESCQ_FLS_DONE_EV:
  1014. netif_vdbg(efx, hw, efx->net_dev, "channel %d RXQ %d flushed\n",
  1015. channel->channel, ev_sub_data);
  1016. efx_farch_handle_rx_flush_done(efx, event);
  1017. efx_sriov_rx_flush_done(efx, event);
  1018. break;
  1019. case FSE_AZ_EVQ_INIT_DONE_EV:
  1020. netif_dbg(efx, hw, efx->net_dev,
  1021. "channel %d EVQ %d initialised\n",
  1022. channel->channel, ev_sub_data);
  1023. break;
  1024. case FSE_AZ_SRM_UPD_DONE_EV:
  1025. netif_vdbg(efx, hw, efx->net_dev,
  1026. "channel %d SRAM update done\n", channel->channel);
  1027. break;
  1028. case FSE_AZ_WAKE_UP_EV:
  1029. netif_vdbg(efx, hw, efx->net_dev,
  1030. "channel %d RXQ %d wakeup event\n",
  1031. channel->channel, ev_sub_data);
  1032. break;
  1033. case FSE_AZ_TIMER_EV:
  1034. netif_vdbg(efx, hw, efx->net_dev,
  1035. "channel %d RX queue %d timer expired\n",
  1036. channel->channel, ev_sub_data);
  1037. break;
  1038. case FSE_AA_RX_RECOVER_EV:
  1039. netif_err(efx, rx_err, efx->net_dev,
  1040. "channel %d seen DRIVER RX_RESET event. "
  1041. "Resetting.\n", channel->channel);
  1042. atomic_inc(&efx->rx_reset);
  1043. efx_schedule_reset(efx,
  1044. EFX_WORKAROUND_6555(efx) ?
  1045. RESET_TYPE_RX_RECOVERY :
  1046. RESET_TYPE_DISABLE);
  1047. break;
  1048. case FSE_BZ_RX_DSC_ERROR_EV:
  1049. if (ev_sub_data < EFX_VI_BASE) {
  1050. netif_err(efx, rx_err, efx->net_dev,
  1051. "RX DMA Q %d reports descriptor fetch error."
  1052. " RX Q %d is disabled.\n", ev_sub_data,
  1053. ev_sub_data);
  1054. efx_schedule_reset(efx, RESET_TYPE_RX_DESC_FETCH);
  1055. } else
  1056. efx_sriov_desc_fetch_err(efx, ev_sub_data);
  1057. break;
  1058. case FSE_BZ_TX_DSC_ERROR_EV:
  1059. if (ev_sub_data < EFX_VI_BASE) {
  1060. netif_err(efx, tx_err, efx->net_dev,
  1061. "TX DMA Q %d reports descriptor fetch error."
  1062. " TX Q %d is disabled.\n", ev_sub_data,
  1063. ev_sub_data);
  1064. efx_schedule_reset(efx, RESET_TYPE_TX_DESC_FETCH);
  1065. } else
  1066. efx_sriov_desc_fetch_err(efx, ev_sub_data);
  1067. break;
  1068. default:
  1069. netif_vdbg(efx, hw, efx->net_dev,
  1070. "channel %d unknown driver event code %d "
  1071. "data %04x\n", channel->channel, ev_sub_code,
  1072. ev_sub_data);
  1073. break;
  1074. }
  1075. }
  1076. int efx_farch_ev_process(struct efx_channel *channel, int budget)
  1077. {
  1078. struct efx_nic *efx = channel->efx;
  1079. unsigned int read_ptr;
  1080. efx_qword_t event, *p_event;
  1081. int ev_code;
  1082. int tx_packets = 0;
  1083. int spent = 0;
  1084. read_ptr = channel->eventq_read_ptr;
  1085. for (;;) {
  1086. p_event = efx_event(channel, read_ptr);
  1087. event = *p_event;
  1088. if (!efx_event_present(&event))
  1089. /* End of events */
  1090. break;
  1091. netif_vdbg(channel->efx, intr, channel->efx->net_dev,
  1092. "channel %d event is "EFX_QWORD_FMT"\n",
  1093. channel->channel, EFX_QWORD_VAL(event));
  1094. /* Clear this event by marking it all ones */
  1095. EFX_SET_QWORD(*p_event);
  1096. ++read_ptr;
  1097. ev_code = EFX_QWORD_FIELD(event, FSF_AZ_EV_CODE);
  1098. switch (ev_code) {
  1099. case FSE_AZ_EV_CODE_RX_EV:
  1100. efx_farch_handle_rx_event(channel, &event);
  1101. if (++spent == budget)
  1102. goto out;
  1103. break;
  1104. case FSE_AZ_EV_CODE_TX_EV:
  1105. tx_packets += efx_farch_handle_tx_event(channel,
  1106. &event);
  1107. if (tx_packets > efx->txq_entries) {
  1108. spent = budget;
  1109. goto out;
  1110. }
  1111. break;
  1112. case FSE_AZ_EV_CODE_DRV_GEN_EV:
  1113. efx_farch_handle_generated_event(channel, &event);
  1114. break;
  1115. case FSE_AZ_EV_CODE_DRIVER_EV:
  1116. efx_farch_handle_driver_event(channel, &event);
  1117. break;
  1118. case FSE_CZ_EV_CODE_USER_EV:
  1119. efx_sriov_event(channel, &event);
  1120. break;
  1121. case FSE_CZ_EV_CODE_MCDI_EV:
  1122. efx_mcdi_process_event(channel, &event);
  1123. break;
  1124. case FSE_AZ_EV_CODE_GLOBAL_EV:
  1125. if (efx->type->handle_global_event &&
  1126. efx->type->handle_global_event(channel, &event))
  1127. break;
  1128. /* else fall through */
  1129. default:
  1130. netif_err(channel->efx, hw, channel->efx->net_dev,
  1131. "channel %d unknown event type %d (data "
  1132. EFX_QWORD_FMT ")\n", channel->channel,
  1133. ev_code, EFX_QWORD_VAL(event));
  1134. }
  1135. }
  1136. out:
  1137. channel->eventq_read_ptr = read_ptr;
  1138. return spent;
  1139. }
  1140. /* Allocate buffer table entries for event queue */
  1141. int efx_farch_ev_probe(struct efx_channel *channel)
  1142. {
  1143. struct efx_nic *efx = channel->efx;
  1144. unsigned entries;
  1145. entries = channel->eventq_mask + 1;
  1146. return efx_alloc_special_buffer(efx, &channel->eventq,
  1147. entries * sizeof(efx_qword_t));
  1148. }
  1149. void efx_farch_ev_init(struct efx_channel *channel)
  1150. {
  1151. efx_oword_t reg;
  1152. struct efx_nic *efx = channel->efx;
  1153. netif_dbg(efx, hw, efx->net_dev,
  1154. "channel %d event queue in special buffers %d-%d\n",
  1155. channel->channel, channel->eventq.index,
  1156. channel->eventq.index + channel->eventq.entries - 1);
  1157. if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0) {
  1158. EFX_POPULATE_OWORD_3(reg,
  1159. FRF_CZ_TIMER_Q_EN, 1,
  1160. FRF_CZ_HOST_NOTIFY_MODE, 0,
  1161. FRF_CZ_TIMER_MODE, FFE_CZ_TIMER_MODE_DIS);
  1162. efx_writeo_table(efx, &reg, FR_BZ_TIMER_TBL, channel->channel);
  1163. }
  1164. /* Pin event queue buffer */
  1165. efx_init_special_buffer(efx, &channel->eventq);
  1166. /* Fill event queue with all ones (i.e. empty events) */
  1167. memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len);
  1168. /* Push event queue to card */
  1169. EFX_POPULATE_OWORD_3(reg,
  1170. FRF_AZ_EVQ_EN, 1,
  1171. FRF_AZ_EVQ_SIZE, __ffs(channel->eventq.entries),
  1172. FRF_AZ_EVQ_BUF_BASE_ID, channel->eventq.index);
  1173. efx_writeo_table(efx, &reg, efx->type->evq_ptr_tbl_base,
  1174. channel->channel);
  1175. efx->type->push_irq_moderation(channel);
  1176. }
  1177. void efx_farch_ev_fini(struct efx_channel *channel)
  1178. {
  1179. efx_oword_t reg;
  1180. struct efx_nic *efx = channel->efx;
  1181. /* Remove event queue from card */
  1182. EFX_ZERO_OWORD(reg);
  1183. efx_writeo_table(efx, &reg, efx->type->evq_ptr_tbl_base,
  1184. channel->channel);
  1185. if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0)
  1186. efx_writeo_table(efx, &reg, FR_BZ_TIMER_TBL, channel->channel);
  1187. /* Unpin event queue */
  1188. efx_fini_special_buffer(efx, &channel->eventq);
  1189. }
  1190. /* Free buffers backing event queue */
  1191. void efx_farch_ev_remove(struct efx_channel *channel)
  1192. {
  1193. efx_free_special_buffer(channel->efx, &channel->eventq);
  1194. }
  1195. void efx_farch_ev_test_generate(struct efx_channel *channel)
  1196. {
  1197. efx_farch_magic_event(channel, EFX_CHANNEL_MAGIC_TEST(channel));
  1198. }
  1199. void efx_farch_rx_defer_refill(struct efx_rx_queue *rx_queue)
  1200. {
  1201. efx_farch_magic_event(efx_rx_queue_channel(rx_queue),
  1202. EFX_CHANNEL_MAGIC_FILL(rx_queue));
  1203. }
  1204. /**************************************************************************
  1205. *
  1206. * Hardware interrupts
  1207. * The hardware interrupt handler does very little work; all the event
  1208. * queue processing is carried out by per-channel tasklets.
  1209. *
  1210. **************************************************************************/
  1211. /* Enable/disable/generate interrupts */
  1212. static inline void efx_farch_interrupts(struct efx_nic *efx,
  1213. bool enabled, bool force)
  1214. {
  1215. efx_oword_t int_en_reg_ker;
  1216. EFX_POPULATE_OWORD_3(int_en_reg_ker,
  1217. FRF_AZ_KER_INT_LEVE_SEL, efx->irq_level,
  1218. FRF_AZ_KER_INT_KER, force,
  1219. FRF_AZ_DRV_INT_EN_KER, enabled);
  1220. efx_writeo(efx, &int_en_reg_ker, FR_AZ_INT_EN_KER);
  1221. }
  1222. void efx_farch_irq_enable_master(struct efx_nic *efx)
  1223. {
  1224. EFX_ZERO_OWORD(*((efx_oword_t *) efx->irq_status.addr));
  1225. wmb(); /* Ensure interrupt vector is clear before interrupts enabled */
  1226. efx_farch_interrupts(efx, true, false);
  1227. }
  1228. void efx_farch_irq_disable_master(struct efx_nic *efx)
  1229. {
  1230. /* Disable interrupts */
  1231. efx_farch_interrupts(efx, false, false);
  1232. }
  1233. /* Generate a test interrupt
  1234. * Interrupt must already have been enabled, otherwise nasty things
  1235. * may happen.
  1236. */
  1237. void efx_farch_irq_test_generate(struct efx_nic *efx)
  1238. {
  1239. efx_farch_interrupts(efx, true, true);
  1240. }
  1241. /* Process a fatal interrupt
  1242. * Disable bus mastering ASAP and schedule a reset
  1243. */
  1244. irqreturn_t efx_farch_fatal_interrupt(struct efx_nic *efx)
  1245. {
  1246. struct falcon_nic_data *nic_data = efx->nic_data;
  1247. efx_oword_t *int_ker = efx->irq_status.addr;
  1248. efx_oword_t fatal_intr;
  1249. int error, mem_perr;
  1250. efx_reado(efx, &fatal_intr, FR_AZ_FATAL_INTR_KER);
  1251. error = EFX_OWORD_FIELD(fatal_intr, FRF_AZ_FATAL_INTR);
  1252. netif_err(efx, hw, efx->net_dev, "SYSTEM ERROR "EFX_OWORD_FMT" status "
  1253. EFX_OWORD_FMT ": %s\n", EFX_OWORD_VAL(*int_ker),
  1254. EFX_OWORD_VAL(fatal_intr),
  1255. error ? "disabling bus mastering" : "no recognised error");
  1256. /* If this is a memory parity error dump which blocks are offending */
  1257. mem_perr = (EFX_OWORD_FIELD(fatal_intr, FRF_AZ_MEM_PERR_INT_KER) ||
  1258. EFX_OWORD_FIELD(fatal_intr, FRF_AZ_SRM_PERR_INT_KER));
  1259. if (mem_perr) {
  1260. efx_oword_t reg;
  1261. efx_reado(efx, &reg, FR_AZ_MEM_STAT);
  1262. netif_err(efx, hw, efx->net_dev,
  1263. "SYSTEM ERROR: memory parity error "EFX_OWORD_FMT"\n",
  1264. EFX_OWORD_VAL(reg));
  1265. }
  1266. /* Disable both devices */
  1267. pci_clear_master(efx->pci_dev);
  1268. if (efx_nic_is_dual_func(efx))
  1269. pci_clear_master(nic_data->pci_dev2);
  1270. efx_farch_irq_disable_master(efx);
  1271. /* Count errors and reset or disable the NIC accordingly */
  1272. if (efx->int_error_count == 0 ||
  1273. time_after(jiffies, efx->int_error_expire)) {
  1274. efx->int_error_count = 0;
  1275. efx->int_error_expire =
  1276. jiffies + EFX_INT_ERROR_EXPIRE * HZ;
  1277. }
  1278. if (++efx->int_error_count < EFX_MAX_INT_ERRORS) {
  1279. netif_err(efx, hw, efx->net_dev,
  1280. "SYSTEM ERROR - reset scheduled\n");
  1281. efx_schedule_reset(efx, RESET_TYPE_INT_ERROR);
  1282. } else {
  1283. netif_err(efx, hw, efx->net_dev,
  1284. "SYSTEM ERROR - max number of errors seen."
  1285. "NIC will be disabled\n");
  1286. efx_schedule_reset(efx, RESET_TYPE_DISABLE);
  1287. }
  1288. return IRQ_HANDLED;
  1289. }
  1290. /* Handle a legacy interrupt
  1291. * Acknowledges the interrupt and schedule event queue processing.
  1292. */
  1293. irqreturn_t efx_farch_legacy_interrupt(int irq, void *dev_id)
  1294. {
  1295. struct efx_nic *efx = dev_id;
  1296. bool soft_enabled = ACCESS_ONCE(efx->irq_soft_enabled);
  1297. efx_oword_t *int_ker = efx->irq_status.addr;
  1298. irqreturn_t result = IRQ_NONE;
  1299. struct efx_channel *channel;
  1300. efx_dword_t reg;
  1301. u32 queues;
  1302. int syserr;
  1303. /* Read the ISR which also ACKs the interrupts */
  1304. efx_readd(efx, &reg, FR_BZ_INT_ISR0);
  1305. queues = EFX_EXTRACT_DWORD(reg, 0, 31);
  1306. /* Legacy interrupts are disabled too late by the EEH kernel
  1307. * code. Disable them earlier.
  1308. * If an EEH error occurred, the read will have returned all ones.
  1309. */
  1310. if (EFX_DWORD_IS_ALL_ONES(reg) && efx_try_recovery(efx) &&
  1311. !efx->eeh_disabled_legacy_irq) {
  1312. disable_irq_nosync(efx->legacy_irq);
  1313. efx->eeh_disabled_legacy_irq = true;
  1314. }
  1315. /* Handle non-event-queue sources */
  1316. if (queues & (1U << efx->irq_level) && soft_enabled) {
  1317. syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT);
  1318. if (unlikely(syserr))
  1319. return efx_farch_fatal_interrupt(efx);
  1320. efx->last_irq_cpu = raw_smp_processor_id();
  1321. }
  1322. if (queues != 0) {
  1323. efx->irq_zero_count = 0;
  1324. /* Schedule processing of any interrupting queues */
  1325. if (likely(soft_enabled)) {
  1326. efx_for_each_channel(channel, efx) {
  1327. if (queues & 1)
  1328. efx_schedule_channel_irq(channel);
  1329. queues >>= 1;
  1330. }
  1331. }
  1332. result = IRQ_HANDLED;
  1333. } else {
  1334. efx_qword_t *event;
  1335. /* Legacy ISR read can return zero once (SF bug 15783) */
  1336. /* We can't return IRQ_HANDLED more than once on seeing ISR=0
  1337. * because this might be a shared interrupt. */
  1338. if (efx->irq_zero_count++ == 0)
  1339. result = IRQ_HANDLED;
  1340. /* Ensure we schedule or rearm all event queues */
  1341. if (likely(soft_enabled)) {
  1342. efx_for_each_channel(channel, efx) {
  1343. event = efx_event(channel,
  1344. channel->eventq_read_ptr);
  1345. if (efx_event_present(event))
  1346. efx_schedule_channel_irq(channel);
  1347. else
  1348. efx_farch_ev_read_ack(channel);
  1349. }
  1350. }
  1351. }
  1352. if (result == IRQ_HANDLED)
  1353. netif_vdbg(efx, intr, efx->net_dev,
  1354. "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
  1355. irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
  1356. return result;
  1357. }
  1358. /* Handle an MSI interrupt
  1359. *
  1360. * Handle an MSI hardware interrupt. This routine schedules event
  1361. * queue processing. No interrupt acknowledgement cycle is necessary.
  1362. * Also, we never need to check that the interrupt is for us, since
  1363. * MSI interrupts cannot be shared.
  1364. */
  1365. irqreturn_t efx_farch_msi_interrupt(int irq, void *dev_id)
  1366. {
  1367. struct efx_msi_context *context = dev_id;
  1368. struct efx_nic *efx = context->efx;
  1369. efx_oword_t *int_ker = efx->irq_status.addr;
  1370. int syserr;
  1371. netif_vdbg(efx, intr, efx->net_dev,
  1372. "IRQ %d on CPU %d status " EFX_OWORD_FMT "\n",
  1373. irq, raw_smp_processor_id(), EFX_OWORD_VAL(*int_ker));
  1374. if (!likely(ACCESS_ONCE(efx->irq_soft_enabled)))
  1375. return IRQ_HANDLED;
  1376. /* Handle non-event-queue sources */
  1377. if (context->index == efx->irq_level) {
  1378. syserr = EFX_OWORD_FIELD(*int_ker, FSF_AZ_NET_IVEC_FATAL_INT);
  1379. if (unlikely(syserr))
  1380. return efx_farch_fatal_interrupt(efx);
  1381. efx->last_irq_cpu = raw_smp_processor_id();
  1382. }
  1383. /* Schedule processing of the channel */
  1384. efx_schedule_channel_irq(efx->channel[context->index]);
  1385. return IRQ_HANDLED;
  1386. }
  1387. /* Setup RSS indirection table.
  1388. * This maps from the hash value of the packet to RXQ
  1389. */
  1390. void efx_farch_rx_push_indir_table(struct efx_nic *efx)
  1391. {
  1392. size_t i = 0;
  1393. efx_dword_t dword;
  1394. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0)
  1395. return;
  1396. BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) !=
  1397. FR_BZ_RX_INDIRECTION_TBL_ROWS);
  1398. for (i = 0; i < FR_BZ_RX_INDIRECTION_TBL_ROWS; i++) {
  1399. EFX_POPULATE_DWORD_1(dword, FRF_BZ_IT_QUEUE,
  1400. efx->rx_indir_table[i]);
  1401. efx_writed(efx, &dword,
  1402. FR_BZ_RX_INDIRECTION_TBL +
  1403. FR_BZ_RX_INDIRECTION_TBL_STEP * i);
  1404. }
  1405. }
  1406. /* Looks at available SRAM resources and works out how many queues we
  1407. * can support, and where things like descriptor caches should live.
  1408. *
  1409. * SRAM is split up as follows:
  1410. * 0 buftbl entries for channels
  1411. * efx->vf_buftbl_base buftbl entries for SR-IOV
  1412. * efx->rx_dc_base RX descriptor caches
  1413. * efx->tx_dc_base TX descriptor caches
  1414. */
  1415. void efx_farch_dimension_resources(struct efx_nic *efx, unsigned sram_lim_qw)
  1416. {
  1417. unsigned vi_count, buftbl_min;
  1418. /* Account for the buffer table entries backing the datapath channels
  1419. * and the descriptor caches for those channels.
  1420. */
  1421. buftbl_min = ((efx->n_rx_channels * EFX_MAX_DMAQ_SIZE +
  1422. efx->n_tx_channels * EFX_TXQ_TYPES * EFX_MAX_DMAQ_SIZE +
  1423. efx->n_channels * EFX_MAX_EVQ_SIZE)
  1424. * sizeof(efx_qword_t) / EFX_BUF_SIZE);
  1425. vi_count = max(efx->n_channels, efx->n_tx_channels * EFX_TXQ_TYPES);
  1426. #ifdef CONFIG_SFC_SRIOV
  1427. if (efx_sriov_wanted(efx)) {
  1428. unsigned vi_dc_entries, buftbl_free, entries_per_vf, vf_limit;
  1429. efx->vf_buftbl_base = buftbl_min;
  1430. vi_dc_entries = RX_DC_ENTRIES + TX_DC_ENTRIES;
  1431. vi_count = max(vi_count, EFX_VI_BASE);
  1432. buftbl_free = (sram_lim_qw - buftbl_min -
  1433. vi_count * vi_dc_entries);
  1434. entries_per_vf = ((vi_dc_entries + EFX_VF_BUFTBL_PER_VI) *
  1435. efx_vf_size(efx));
  1436. vf_limit = min(buftbl_free / entries_per_vf,
  1437. (1024U - EFX_VI_BASE) >> efx->vi_scale);
  1438. if (efx->vf_count > vf_limit) {
  1439. netif_err(efx, probe, efx->net_dev,
  1440. "Reducing VF count from from %d to %d\n",
  1441. efx->vf_count, vf_limit);
  1442. efx->vf_count = vf_limit;
  1443. }
  1444. vi_count += efx->vf_count * efx_vf_size(efx);
  1445. }
  1446. #endif
  1447. efx->tx_dc_base = sram_lim_qw - vi_count * TX_DC_ENTRIES;
  1448. efx->rx_dc_base = efx->tx_dc_base - vi_count * RX_DC_ENTRIES;
  1449. }
  1450. u32 efx_farch_fpga_ver(struct efx_nic *efx)
  1451. {
  1452. efx_oword_t altera_build;
  1453. efx_reado(efx, &altera_build, FR_AZ_ALTERA_BUILD);
  1454. return EFX_OWORD_FIELD(altera_build, FRF_AZ_ALTERA_BUILD_VER);
  1455. }
  1456. void efx_farch_init_common(struct efx_nic *efx)
  1457. {
  1458. efx_oword_t temp;
  1459. /* Set positions of descriptor caches in SRAM. */
  1460. EFX_POPULATE_OWORD_1(temp, FRF_AZ_SRM_TX_DC_BASE_ADR, efx->tx_dc_base);
  1461. efx_writeo(efx, &temp, FR_AZ_SRM_TX_DC_CFG);
  1462. EFX_POPULATE_OWORD_1(temp, FRF_AZ_SRM_RX_DC_BASE_ADR, efx->rx_dc_base);
  1463. efx_writeo(efx, &temp, FR_AZ_SRM_RX_DC_CFG);
  1464. /* Set TX descriptor cache size. */
  1465. BUILD_BUG_ON(TX_DC_ENTRIES != (8 << TX_DC_ENTRIES_ORDER));
  1466. EFX_POPULATE_OWORD_1(temp, FRF_AZ_TX_DC_SIZE, TX_DC_ENTRIES_ORDER);
  1467. efx_writeo(efx, &temp, FR_AZ_TX_DC_CFG);
  1468. /* Set RX descriptor cache size. Set low watermark to size-8, as
  1469. * this allows most efficient prefetching.
  1470. */
  1471. BUILD_BUG_ON(RX_DC_ENTRIES != (8 << RX_DC_ENTRIES_ORDER));
  1472. EFX_POPULATE_OWORD_1(temp, FRF_AZ_RX_DC_SIZE, RX_DC_ENTRIES_ORDER);
  1473. efx_writeo(efx, &temp, FR_AZ_RX_DC_CFG);
  1474. EFX_POPULATE_OWORD_1(temp, FRF_AZ_RX_DC_PF_LWM, RX_DC_ENTRIES - 8);
  1475. efx_writeo(efx, &temp, FR_AZ_RX_DC_PF_WM);
  1476. /* Program INT_KER address */
  1477. EFX_POPULATE_OWORD_2(temp,
  1478. FRF_AZ_NORM_INT_VEC_DIS_KER,
  1479. EFX_INT_MODE_USE_MSI(efx),
  1480. FRF_AZ_INT_ADR_KER, efx->irq_status.dma_addr);
  1481. efx_writeo(efx, &temp, FR_AZ_INT_ADR_KER);
  1482. if (EFX_WORKAROUND_17213(efx) && !EFX_INT_MODE_USE_MSI(efx))
  1483. /* Use an interrupt level unused by event queues */
  1484. efx->irq_level = 0x1f;
  1485. else
  1486. /* Use a valid MSI-X vector */
  1487. efx->irq_level = 0;
  1488. /* Enable all the genuinely fatal interrupts. (They are still
  1489. * masked by the overall interrupt mask, controlled by
  1490. * falcon_interrupts()).
  1491. *
  1492. * Note: All other fatal interrupts are enabled
  1493. */
  1494. EFX_POPULATE_OWORD_3(temp,
  1495. FRF_AZ_ILL_ADR_INT_KER_EN, 1,
  1496. FRF_AZ_RBUF_OWN_INT_KER_EN, 1,
  1497. FRF_AZ_TBUF_OWN_INT_KER_EN, 1);
  1498. if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0)
  1499. EFX_SET_OWORD_FIELD(temp, FRF_CZ_SRAM_PERR_INT_P_KER_EN, 1);
  1500. EFX_INVERT_OWORD(temp);
  1501. efx_writeo(efx, &temp, FR_AZ_FATAL_INTR_KER);
  1502. efx_farch_rx_push_indir_table(efx);
  1503. /* Disable the ugly timer-based TX DMA backoff and allow TX DMA to be
  1504. * controlled by the RX FIFO fill level. Set arbitration to one pkt/Q.
  1505. */
  1506. efx_reado(efx, &temp, FR_AZ_TX_RESERVED);
  1507. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_RX_SPACER, 0xfe);
  1508. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_RX_SPACER_EN, 1);
  1509. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_ONE_PKT_PER_Q, 1);
  1510. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PUSH_EN, 1);
  1511. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_DIS_NON_IP_EV, 1);
  1512. /* Enable SW_EV to inherit in char driver - assume harmless here */
  1513. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_SOFT_EVT_EN, 1);
  1514. /* Prefetch threshold 2 => fetch when descriptor cache half empty */
  1515. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PREF_THRESHOLD, 2);
  1516. /* Disable hardware watchdog which can misfire */
  1517. EFX_SET_OWORD_FIELD(temp, FRF_AZ_TX_PREF_WD_TMR, 0x3fffff);
  1518. /* Squash TX of packets of 16 bytes or less */
  1519. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0)
  1520. EFX_SET_OWORD_FIELD(temp, FRF_BZ_TX_FLUSH_MIN_LEN_EN, 1);
  1521. efx_writeo(efx, &temp, FR_AZ_TX_RESERVED);
  1522. if (efx_nic_rev(efx) >= EFX_REV_FALCON_B0) {
  1523. EFX_POPULATE_OWORD_4(temp,
  1524. /* Default values */
  1525. FRF_BZ_TX_PACE_SB_NOT_AF, 0x15,
  1526. FRF_BZ_TX_PACE_SB_AF, 0xb,
  1527. FRF_BZ_TX_PACE_FB_BASE, 0,
  1528. /* Allow large pace values in the
  1529. * fast bin. */
  1530. FRF_BZ_TX_PACE_BIN_TH,
  1531. FFE_BZ_TX_PACE_RESERVED);
  1532. efx_writeo(efx, &temp, FR_BZ_TX_PACE);
  1533. }
  1534. }