nic.c 58 KB

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