nic.c 57 KB

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