nic.c 58 KB

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