nic.c 61 KB

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