nic.c 58 KB

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