nic.c 64 KB

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